LLDB mainline
SBTarget.cpp
Go to the documentation of this file.
1//===-- SBTarget.cpp ------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#include "lldb/API/SBTarget.h"
12#include "lldb/lldb-public.h"
13
15#include "lldb/API/SBDebugger.h"
17#include "lldb/API/SBEvent.h"
19#include "lldb/API/SBFileSpec.h"
20#include "lldb/API/SBListener.h"
21#include "lldb/API/SBModule.h"
23#include "lldb/API/SBProcess.h"
25#include "lldb/API/SBStream.h"
29#include "lldb/API/SBTrace.h"
34#include "lldb/Core/Address.h"
36#include "lldb/Core/Debugger.h"
38#include "lldb/Core/Module.h"
41#include "lldb/Core/Section.h"
46#include "lldb/Host/Host.h"
53#include "lldb/Target/ABI.h"
56#include "lldb/Target/Process.h"
58#include "lldb/Target/Target.h"
61#include "lldb/Utility/Args.h"
65
68#include "llvm/Support/PrettyStackTrace.h"
69#include "llvm/Support/Regex.h"
70
71using namespace lldb;
72using namespace lldb_private;
73
74#define DEFAULT_DISASM_BYTE_SIZE 32
75
76static Status AttachToProcess(ProcessAttachInfo &attach_info, Target &target) {
77 std::lock_guard<std::recursive_mutex> guard(target.GetAPIMutex());
78
79 auto process_sp = target.GetProcessSP();
80 if (process_sp) {
81 const auto state = process_sp->GetState();
82 if (process_sp->IsAlive() && state == eStateConnected) {
83 // If we are already connected, then we have already specified the
84 // listener, so if a valid listener is supplied, we need to error out to
85 // let the client know.
86 if (attach_info.GetListener())
87 return Status("process is connected and already has a listener, pass "
88 "empty listener");
89 }
90 }
91
92 return target.Attach(attach_info, nullptr);
93}
94
95// SBTarget constructor
97
98SBTarget::SBTarget(const SBTarget &rhs) : m_opaque_sp(rhs.m_opaque_sp) {
99 LLDB_INSTRUMENT_VA(this, rhs);
100}
101
102SBTarget::SBTarget(const TargetSP &target_sp) : m_opaque_sp(target_sp) {
103 LLDB_INSTRUMENT_VA(this, target_sp);
104}
105
107 LLDB_INSTRUMENT_VA(this, rhs);
108
109 if (this != &rhs)
111 return *this;
112}
113
114// Destructor
115SBTarget::~SBTarget() = default;
116
118 LLDB_INSTRUMENT_VA(event);
119
120 return Target::TargetEventData::GetEventDataFromEvent(event.get()) != nullptr;
121}
122
124 LLDB_INSTRUMENT_VA(event);
125
127}
128
130 LLDB_INSTRUMENT_VA(event);
131
132 const ModuleList module_list =
134 return module_list.GetSize();
135}
136
138 const SBEvent &event) {
139 LLDB_INSTRUMENT_VA(idx, event);
140
141 const ModuleList module_list =
143 return SBModule(module_list.GetModuleAtIndex(idx));
144}
145
148
150}
151
152bool SBTarget::IsValid() const {
153 LLDB_INSTRUMENT_VA(this);
154 return this->operator bool();
155}
156SBTarget::operator bool() const {
157 LLDB_INSTRUMENT_VA(this);
158
159 return m_opaque_sp.get() != nullptr && m_opaque_sp->IsValid();
160}
161
163 LLDB_INSTRUMENT_VA(this);
164
165 SBProcess sb_process;
166 ProcessSP process_sp;
167 TargetSP target_sp(GetSP());
168 if (target_sp) {
169 process_sp = target_sp->GetProcessSP();
170 sb_process.SetSP(process_sp);
171 }
172
173 return sb_process;
174}
175
177 LLDB_INSTRUMENT_VA(this);
178
179 TargetSP target_sp(GetSP());
180 if (!target_sp)
181 return SBPlatform();
182
183 SBPlatform platform;
184 platform.m_opaque_sp = target_sp->GetPlatform();
185
186 return platform;
187}
188
190 LLDB_INSTRUMENT_VA(this);
191
192 SBDebugger debugger;
193 TargetSP target_sp(GetSP());
194 if (target_sp)
195 debugger.reset(target_sp->GetDebugger().shared_from_this());
196 return debugger;
197}
198
200 LLDB_INSTRUMENT_VA(this);
201
202 SBStructuredData data;
203 TargetSP target_sp(GetSP());
204 if (!target_sp)
205 return data;
206 std::string json_str =
207 llvm::formatv("{0:2}",
208 DebuggerStats::ReportStatistics(target_sp->GetDebugger(),
209 target_sp.get())).str();
210 data.m_impl_up->SetObjectSP(StructuredData::ParseJSON(json_str));
211 return data;
212}
213
215 LLDB_INSTRUMENT_VA(this, v);
216
217 TargetSP target_sp(GetSP());
218 if (!target_sp)
219 return;
221}
222
224 LLDB_INSTRUMENT_VA(this);
225
226 TargetSP target_sp(GetSP());
227 if (!target_sp)
228 return false;
230}
231
232SBProcess SBTarget::LoadCore(const char *core_file) {
233 LLDB_INSTRUMENT_VA(this, core_file);
234
235 lldb::SBError error; // Ignored
236 return LoadCore(core_file, error);
237}
238
240 LLDB_INSTRUMENT_VA(this, core_file, error);
241
242 SBProcess sb_process;
243 TargetSP target_sp(GetSP());
244 if (target_sp) {
245 FileSpec filespec(core_file);
246 FileSystem::Instance().Resolve(filespec);
247 ProcessSP process_sp(target_sp->CreateProcess(
248 target_sp->GetDebugger().GetListener(), "", &filespec, false));
249 if (process_sp) {
250 error.SetError(process_sp->LoadCore());
251 if (error.Success())
252 sb_process.SetSP(process_sp);
253 } else {
254 error.SetErrorString("Failed to create the process");
255 }
256 } else {
257 error.SetErrorString("SBTarget is invalid");
258 }
259 return sb_process;
260}
261
262SBProcess SBTarget::LaunchSimple(char const **argv, char const **envp,
263 const char *working_directory) {
264 LLDB_INSTRUMENT_VA(this, argv, envp, working_directory);
265
266 TargetSP target_sp = GetSP();
267 if (!target_sp)
268 return SBProcess();
269
270 SBLaunchInfo launch_info = GetLaunchInfo();
271
272 if (Module *exe_module = target_sp->GetExecutableModulePointer())
273 launch_info.SetExecutableFile(exe_module->GetPlatformFileSpec(),
274 /*add_as_first_arg*/ true);
275 if (argv)
276 launch_info.SetArguments(argv, /*append*/ true);
277 if (envp)
278 launch_info.SetEnvironmentEntries(envp, /*append*/ false);
279 if (working_directory)
280 launch_info.SetWorkingDirectory(working_directory);
281
283 return Launch(launch_info, error);
284}
285
287 LLDB_INSTRUMENT_VA(this);
288
289 SBError sb_error;
290 TargetSP target_sp(GetSP());
291 if (target_sp) {
292 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
293 sb_error.ref() = target_sp->Install(nullptr);
294 }
295 return sb_error;
296}
297
298SBProcess SBTarget::Launch(SBListener &listener, char const **argv,
299 char const **envp, const char *stdin_path,
300 const char *stdout_path, const char *stderr_path,
301 const char *working_directory,
302 uint32_t launch_flags, // See LaunchFlags
303 bool stop_at_entry, lldb::SBError &error) {
304 LLDB_INSTRUMENT_VA(this, listener, argv, envp, stdin_path, stdout_path,
305 stderr_path, working_directory, launch_flags,
306 stop_at_entry, error);
307
308 SBProcess sb_process;
309 ProcessSP process_sp;
310 TargetSP target_sp(GetSP());
311
312 if (target_sp) {
313 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
314
315 if (stop_at_entry)
316 launch_flags |= eLaunchFlagStopAtEntry;
317
318 if (getenv("LLDB_LAUNCH_FLAG_DISABLE_ASLR"))
319 launch_flags |= eLaunchFlagDisableASLR;
320
321 StateType state = eStateInvalid;
322 process_sp = target_sp->GetProcessSP();
323 if (process_sp) {
324 state = process_sp->GetState();
325
326 if (process_sp->IsAlive() && state != eStateConnected) {
327 if (state == eStateAttaching)
328 error.SetErrorString("process attach is in progress");
329 else
330 error.SetErrorString("a process is already being debugged");
331 return sb_process;
332 }
333 }
334
335 if (state == eStateConnected) {
336 // If we are already connected, then we have already specified the
337 // listener, so if a valid listener is supplied, we need to error out to
338 // let the client know.
339 if (listener.IsValid()) {
340 error.SetErrorString("process is connected and already has a listener, "
341 "pass empty listener");
342 return sb_process;
343 }
344 }
345
346 if (getenv("LLDB_LAUNCH_FLAG_DISABLE_STDIO"))
347 launch_flags |= eLaunchFlagDisableSTDIO;
348
349 ProcessLaunchInfo launch_info(FileSpec(stdin_path), FileSpec(stdout_path),
350 FileSpec(stderr_path),
351 FileSpec(working_directory), launch_flags);
352
353 Module *exe_module = target_sp->GetExecutableModulePointer();
354 if (exe_module)
355 launch_info.SetExecutableFile(exe_module->GetPlatformFileSpec(), true);
356 if (argv) {
357 launch_info.GetArguments().AppendArguments(argv);
358 } else {
359 auto default_launch_info = target_sp->GetProcessLaunchInfo();
360 launch_info.GetArguments().AppendArguments(
361 default_launch_info.GetArguments());
362 }
363 if (envp) {
364 launch_info.GetEnvironment() = Environment(envp);
365 } else {
366 auto default_launch_info = target_sp->GetProcessLaunchInfo();
367 launch_info.GetEnvironment() = default_launch_info.GetEnvironment();
368 }
369
370 if (listener.IsValid())
371 launch_info.SetListener(listener.GetSP());
372
373 error.SetError(target_sp->Launch(launch_info, nullptr));
374
375 sb_process.SetSP(target_sp->GetProcessSP());
376 } else {
377 error.SetErrorString("SBTarget is invalid");
378 }
379
380 return sb_process;
381}
382
384 LLDB_INSTRUMENT_VA(this, sb_launch_info, error);
385
386 SBProcess sb_process;
387 TargetSP target_sp(GetSP());
388
389 if (target_sp) {
390 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
391 StateType state = eStateInvalid;
392 {
393 ProcessSP process_sp = target_sp->GetProcessSP();
394 if (process_sp) {
395 state = process_sp->GetState();
396
397 if (process_sp->IsAlive() && state != eStateConnected) {
398 if (state == eStateAttaching)
399 error.SetErrorString("process attach is in progress");
400 else
401 error.SetErrorString("a process is already being debugged");
402 return sb_process;
403 }
404 }
405 }
406
407 lldb_private::ProcessLaunchInfo launch_info = sb_launch_info.ref();
408
409 if (!launch_info.GetExecutableFile()) {
410 Module *exe_module = target_sp->GetExecutableModulePointer();
411 if (exe_module)
412 launch_info.SetExecutableFile(exe_module->GetPlatformFileSpec(), true);
413 }
414
415 const ArchSpec &arch_spec = target_sp->GetArchitecture();
416 if (arch_spec.IsValid())
417 launch_info.GetArchitecture() = arch_spec;
418
419 error.SetError(target_sp->Launch(launch_info, nullptr));
420 sb_launch_info.set_ref(launch_info);
421 sb_process.SetSP(target_sp->GetProcessSP());
422 } else {
423 error.SetErrorString("SBTarget is invalid");
424 }
425
426 return sb_process;
427}
428
430 LLDB_INSTRUMENT_VA(this, sb_attach_info, error);
431
432 SBProcess sb_process;
433 TargetSP target_sp(GetSP());
434
435 if (target_sp) {
436 ProcessAttachInfo &attach_info = sb_attach_info.ref();
437 if (attach_info.ProcessIDIsValid() && !attach_info.UserIDIsValid() &&
438 !attach_info.IsScriptedProcess()) {
439 PlatformSP platform_sp = target_sp->GetPlatform();
440 // See if we can pre-verify if a process exists or not
441 if (platform_sp && platform_sp->IsConnected()) {
442 lldb::pid_t attach_pid = attach_info.GetProcessID();
443 ProcessInstanceInfo instance_info;
444 if (platform_sp->GetProcessInfo(attach_pid, instance_info)) {
445 attach_info.SetUserID(instance_info.GetEffectiveUserID());
446 } else {
447 error.ref().SetErrorStringWithFormat(
448 "no process found with process ID %" PRIu64, attach_pid);
449 return sb_process;
450 }
451 }
452 }
453 error.SetError(AttachToProcess(attach_info, *target_sp));
454 if (error.Success())
455 sb_process.SetSP(target_sp->GetProcessSP());
456 } else {
457 error.SetErrorString("SBTarget is invalid");
458 }
459
460 return sb_process;
461}
462
464 SBListener &listener,
465 lldb::pid_t pid, // The process ID to attach to
466 SBError &error // An error explaining what went wrong if attach fails
467) {
468 LLDB_INSTRUMENT_VA(this, listener, pid, error);
469
470 SBProcess sb_process;
471 TargetSP target_sp(GetSP());
472
473 if (target_sp) {
474 ProcessAttachInfo attach_info;
475 attach_info.SetProcessID(pid);
476 if (listener.IsValid())
477 attach_info.SetListener(listener.GetSP());
478
479 ProcessInstanceInfo instance_info;
480 if (target_sp->GetPlatform()->GetProcessInfo(pid, instance_info))
481 attach_info.SetUserID(instance_info.GetEffectiveUserID());
482
483 error.SetError(AttachToProcess(attach_info, *target_sp));
484 if (error.Success())
485 sb_process.SetSP(target_sp->GetProcessSP());
486 } else
487 error.SetErrorString("SBTarget is invalid");
488
489 return sb_process;
490}
491
493 SBListener &listener,
494 const char *name, // basename of process to attach to
495 bool wait_for, // if true wait for a new instance of "name" to be launched
496 SBError &error // An error explaining what went wrong if attach fails
497) {
498 LLDB_INSTRUMENT_VA(this, listener, name, wait_for, error);
499
500 SBProcess sb_process;
501 TargetSP target_sp(GetSP());
502
503 if (name && target_sp) {
504 ProcessAttachInfo attach_info;
505 attach_info.GetExecutableFile().SetFile(name, FileSpec::Style::native);
506 attach_info.SetWaitForLaunch(wait_for);
507 if (listener.IsValid())
508 attach_info.SetListener(listener.GetSP());
509
510 error.SetError(AttachToProcess(attach_info, *target_sp));
511 if (error.Success())
512 sb_process.SetSP(target_sp->GetProcessSP());
513 } else
514 error.SetErrorString("SBTarget is invalid");
515
516 return sb_process;
517}
518
520 const char *plugin_name,
521 SBError &error) {
522 LLDB_INSTRUMENT_VA(this, listener, url, plugin_name, error);
523
524 SBProcess sb_process;
525 ProcessSP process_sp;
526 TargetSP target_sp(GetSP());
527
528 if (target_sp) {
529 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
530 if (listener.IsValid())
531 process_sp =
532 target_sp->CreateProcess(listener.m_opaque_sp, plugin_name, nullptr,
533 true);
534 else
535 process_sp = target_sp->CreateProcess(
536 target_sp->GetDebugger().GetListener(), plugin_name, nullptr, true);
537
538 if (process_sp) {
539 sb_process.SetSP(process_sp);
540 error.SetError(process_sp->ConnectRemote(url));
541 } else {
542 error.SetErrorString("unable to create lldb_private::Process");
543 }
544 } else {
545 error.SetErrorString("SBTarget is invalid");
546 }
547
548 return sb_process;
549}
550
552 LLDB_INSTRUMENT_VA(this);
553
554 SBFileSpec exe_file_spec;
555 TargetSP target_sp(GetSP());
556 if (target_sp) {
557 Module *exe_module = target_sp->GetExecutableModulePointer();
558 if (exe_module)
559 exe_file_spec.SetFileSpec(exe_module->GetFileSpec());
560 }
561
562 return exe_file_spec;
563}
564
565bool SBTarget::operator==(const SBTarget &rhs) const {
566 LLDB_INSTRUMENT_VA(this, rhs);
567
568 return m_opaque_sp.get() == rhs.m_opaque_sp.get();
569}
570
571bool SBTarget::operator!=(const SBTarget &rhs) const {
572 LLDB_INSTRUMENT_VA(this, rhs);
573
574 return m_opaque_sp.get() != rhs.m_opaque_sp.get();
575}
576
577lldb::TargetSP SBTarget::GetSP() const { return m_opaque_sp; }
578
579void SBTarget::SetSP(const lldb::TargetSP &target_sp) {
580 m_opaque_sp = target_sp;
581}
582
584 LLDB_INSTRUMENT_VA(this, vm_addr);
585
586 lldb::SBAddress sb_addr;
587 Address &addr = sb_addr.ref();
588 TargetSP target_sp(GetSP());
589 if (target_sp) {
590 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
591 if (target_sp->ResolveLoadAddress(vm_addr, addr))
592 return sb_addr;
593 }
594
595 // We have a load address that isn't in a section, just return an address
596 // with the offset filled in (the address) and the section set to NULL
597 addr.SetRawAddress(vm_addr);
598 return sb_addr;
599}
600
602 LLDB_INSTRUMENT_VA(this, file_addr);
603
604 lldb::SBAddress sb_addr;
605 Address &addr = sb_addr.ref();
606 TargetSP target_sp(GetSP());
607 if (target_sp) {
608 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
609 if (target_sp->ResolveFileAddress(file_addr, addr))
610 return sb_addr;
611 }
612
613 addr.SetRawAddress(file_addr);
614 return sb_addr;
615}
616
618 lldb::addr_t vm_addr) {
619 LLDB_INSTRUMENT_VA(this, stop_id, vm_addr);
620
621 lldb::SBAddress sb_addr;
622 Address &addr = sb_addr.ref();
623 TargetSP target_sp(GetSP());
624 if (target_sp) {
625 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
626 if (target_sp->ResolveLoadAddress(vm_addr, addr))
627 return sb_addr;
628 }
629
630 // We have a load address that isn't in a section, just return an address
631 // with the offset filled in (the address) and the section set to NULL
632 addr.SetRawAddress(vm_addr);
633 return sb_addr;
634}
635
638 uint32_t resolve_scope) {
639 LLDB_INSTRUMENT_VA(this, addr, resolve_scope);
640
642 SymbolContextItem scope = static_cast<SymbolContextItem>(resolve_scope);
643 if (addr.IsValid()) {
644 TargetSP target_sp(GetSP());
645 if (target_sp)
646 target_sp->GetImages().ResolveSymbolContextForAddress(addr.ref(), scope,
647 sc.ref());
648 }
649 return sc;
650}
651
652size_t SBTarget::ReadMemory(const SBAddress addr, void *buf, size_t size,
654 LLDB_INSTRUMENT_VA(this, addr, buf, size, error);
655
656 SBError sb_error;
657 size_t bytes_read = 0;
658 TargetSP target_sp(GetSP());
659 if (target_sp) {
660 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
661 bytes_read =
662 target_sp->ReadMemory(addr.ref(), buf, size, sb_error.ref(), true);
663 } else {
664 sb_error.SetErrorString("invalid target");
665 }
666
667 return bytes_read;
668}
669
671 uint32_t line) {
672 LLDB_INSTRUMENT_VA(this, file, line);
673
674 return SBBreakpoint(
675 BreakpointCreateByLocation(SBFileSpec(file, false), line));
676}
677
680 uint32_t line) {
681 LLDB_INSTRUMENT_VA(this, sb_file_spec, line);
682
683 return BreakpointCreateByLocation(sb_file_spec, line, 0);
684}
685
688 uint32_t line, lldb::addr_t offset) {
689 LLDB_INSTRUMENT_VA(this, sb_file_spec, line, offset);
690
691 SBFileSpecList empty_list;
692 return BreakpointCreateByLocation(sb_file_spec, line, offset, empty_list);
693}
694
697 uint32_t line, lldb::addr_t offset,
698 SBFileSpecList &sb_module_list) {
699 LLDB_INSTRUMENT_VA(this, sb_file_spec, line, offset, sb_module_list);
700
701 return BreakpointCreateByLocation(sb_file_spec, line, 0, offset,
702 sb_module_list);
703}
704
706 const SBFileSpec &sb_file_spec, uint32_t line, uint32_t column,
707 lldb::addr_t offset, SBFileSpecList &sb_module_list) {
708 LLDB_INSTRUMENT_VA(this, sb_file_spec, line, column, offset, sb_module_list);
709
710 SBBreakpoint sb_bp;
711 TargetSP target_sp(GetSP());
712 if (target_sp && line != 0) {
713 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
714
715 const LazyBool check_inlines = eLazyBoolCalculate;
716 const LazyBool skip_prologue = eLazyBoolCalculate;
717 const bool internal = false;
718 const bool hardware = false;
719 const LazyBool move_to_nearest_code = eLazyBoolCalculate;
720 const FileSpecList *module_list = nullptr;
721 if (sb_module_list.GetSize() > 0) {
722 module_list = sb_module_list.get();
723 }
724 sb_bp = target_sp->CreateBreakpoint(
725 module_list, *sb_file_spec, line, column, offset, check_inlines,
726 skip_prologue, internal, hardware, move_to_nearest_code);
727 }
728
729 return sb_bp;
730}
731
733 const SBFileSpec &sb_file_spec, uint32_t line, uint32_t column,
734 lldb::addr_t offset, SBFileSpecList &sb_module_list,
735 bool move_to_nearest_code) {
736 LLDB_INSTRUMENT_VA(this, sb_file_spec, line, column, offset, sb_module_list,
737 move_to_nearest_code);
738
739 SBBreakpoint sb_bp;
740 TargetSP target_sp(GetSP());
741 if (target_sp && line != 0) {
742 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
743
744 const LazyBool check_inlines = eLazyBoolCalculate;
745 const LazyBool skip_prologue = eLazyBoolCalculate;
746 const bool internal = false;
747 const bool hardware = false;
748 const FileSpecList *module_list = nullptr;
749 if (sb_module_list.GetSize() > 0) {
750 module_list = sb_module_list.get();
751 }
752 sb_bp = target_sp->CreateBreakpoint(
753 module_list, *sb_file_spec, line, column, offset, check_inlines,
754 skip_prologue, internal, hardware,
755 move_to_nearest_code ? eLazyBoolYes : eLazyBoolNo);
756 }
757
758 return sb_bp;
759}
760
762 const char *module_name) {
763 LLDB_INSTRUMENT_VA(this, symbol_name, module_name);
764
765 SBBreakpoint sb_bp;
766 TargetSP target_sp(GetSP());
767 if (target_sp.get()) {
768 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
769
770 const bool internal = false;
771 const bool hardware = false;
772 const LazyBool skip_prologue = eLazyBoolCalculate;
773 const lldb::addr_t offset = 0;
774 if (module_name && module_name[0]) {
775 FileSpecList module_spec_list;
776 module_spec_list.Append(FileSpec(module_name));
777 sb_bp = target_sp->CreateBreakpoint(
778 &module_spec_list, nullptr, symbol_name, eFunctionNameTypeAuto,
779 eLanguageTypeUnknown, offset, skip_prologue, internal, hardware);
780 } else {
781 sb_bp = target_sp->CreateBreakpoint(
782 nullptr, nullptr, symbol_name, eFunctionNameTypeAuto,
783 eLanguageTypeUnknown, offset, skip_prologue, internal, hardware);
784 }
785 }
786
787 return sb_bp;
788}
789
791SBTarget::BreakpointCreateByName(const char *symbol_name,
792 const SBFileSpecList &module_list,
793 const SBFileSpecList &comp_unit_list) {
794 LLDB_INSTRUMENT_VA(this, symbol_name, module_list, comp_unit_list);
795
796 lldb::FunctionNameType name_type_mask = eFunctionNameTypeAuto;
797 return BreakpointCreateByName(symbol_name, name_type_mask,
798 eLanguageTypeUnknown, module_list,
799 comp_unit_list);
800}
801
803 const char *symbol_name, uint32_t name_type_mask,
804 const SBFileSpecList &module_list, const SBFileSpecList &comp_unit_list) {
805 LLDB_INSTRUMENT_VA(this, symbol_name, name_type_mask, module_list,
806 comp_unit_list);
807
808 return BreakpointCreateByName(symbol_name, name_type_mask,
809 eLanguageTypeUnknown, module_list,
810 comp_unit_list);
811}
812
814 const char *symbol_name, uint32_t name_type_mask,
815 LanguageType symbol_language, const SBFileSpecList &module_list,
816 const SBFileSpecList &comp_unit_list) {
817 LLDB_INSTRUMENT_VA(this, symbol_name, name_type_mask, symbol_language,
818 module_list, comp_unit_list);
819
820 SBBreakpoint sb_bp;
821 TargetSP target_sp(GetSP());
822 if (target_sp && symbol_name && symbol_name[0]) {
823 const bool internal = false;
824 const bool hardware = false;
825 const LazyBool skip_prologue = eLazyBoolCalculate;
826 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
827 FunctionNameType mask = static_cast<FunctionNameType>(name_type_mask);
828 sb_bp = target_sp->CreateBreakpoint(module_list.get(), comp_unit_list.get(),
829 symbol_name, mask, symbol_language, 0,
830 skip_prologue, internal, hardware);
831 }
832
833 return sb_bp;
834}
835
837 const char *symbol_names[], uint32_t num_names, uint32_t name_type_mask,
838 const SBFileSpecList &module_list, const SBFileSpecList &comp_unit_list) {
839 LLDB_INSTRUMENT_VA(this, symbol_names, num_names, name_type_mask, module_list,
840 comp_unit_list);
841
842 return BreakpointCreateByNames(symbol_names, num_names, name_type_mask,
843 eLanguageTypeUnknown, module_list,
844 comp_unit_list);
845}
846
848 const char *symbol_names[], uint32_t num_names, uint32_t name_type_mask,
849 LanguageType symbol_language, const SBFileSpecList &module_list,
850 const SBFileSpecList &comp_unit_list) {
851 LLDB_INSTRUMENT_VA(this, symbol_names, num_names, name_type_mask,
852 symbol_language, module_list, comp_unit_list);
853
854 return BreakpointCreateByNames(symbol_names, num_names, name_type_mask,
855 eLanguageTypeUnknown, 0, module_list,
856 comp_unit_list);
857}
858
860 const char *symbol_names[], uint32_t num_names, uint32_t name_type_mask,
861 LanguageType symbol_language, lldb::addr_t offset,
862 const SBFileSpecList &module_list, const SBFileSpecList &comp_unit_list) {
863 LLDB_INSTRUMENT_VA(this, symbol_names, num_names, name_type_mask,
864 symbol_language, offset, module_list, comp_unit_list);
865
866 SBBreakpoint sb_bp;
867 TargetSP target_sp(GetSP());
868 if (target_sp && num_names > 0) {
869 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
870 const bool internal = false;
871 const bool hardware = false;
872 FunctionNameType mask = static_cast<FunctionNameType>(name_type_mask);
873 const LazyBool skip_prologue = eLazyBoolCalculate;
874 sb_bp = target_sp->CreateBreakpoint(
875 module_list.get(), comp_unit_list.get(), symbol_names, num_names, mask,
876 symbol_language, offset, skip_prologue, internal, hardware);
877 }
878
879 return sb_bp;
880}
881
883 const char *module_name) {
884 LLDB_INSTRUMENT_VA(this, symbol_name_regex, module_name);
885
886 SBFileSpecList module_spec_list;
887 SBFileSpecList comp_unit_list;
888 if (module_name && module_name[0]) {
889 module_spec_list.Append(FileSpec(module_name));
890 }
891 return BreakpointCreateByRegex(symbol_name_regex, eLanguageTypeUnknown,
892 module_spec_list, comp_unit_list);
893}
894
896SBTarget::BreakpointCreateByRegex(const char *symbol_name_regex,
897 const SBFileSpecList &module_list,
898 const SBFileSpecList &comp_unit_list) {
899 LLDB_INSTRUMENT_VA(this, symbol_name_regex, module_list, comp_unit_list);
900
901 return BreakpointCreateByRegex(symbol_name_regex, eLanguageTypeUnknown,
902 module_list, comp_unit_list);
903}
904
906 const char *symbol_name_regex, LanguageType symbol_language,
907 const SBFileSpecList &module_list, const SBFileSpecList &comp_unit_list) {
908 LLDB_INSTRUMENT_VA(this, symbol_name_regex, symbol_language, module_list,
909 comp_unit_list);
910
911 SBBreakpoint sb_bp;
912 TargetSP target_sp(GetSP());
913 if (target_sp && symbol_name_regex && symbol_name_regex[0]) {
914 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
915 RegularExpression regexp((llvm::StringRef(symbol_name_regex)));
916 const bool internal = false;
917 const bool hardware = false;
918 const LazyBool skip_prologue = eLazyBoolCalculate;
919
920 sb_bp = target_sp->CreateFuncRegexBreakpoint(
921 module_list.get(), comp_unit_list.get(), std::move(regexp),
922 symbol_language, skip_prologue, internal, hardware);
923 }
924
925 return sb_bp;
926}
927
929 LLDB_INSTRUMENT_VA(this, address);
930
931 SBBreakpoint sb_bp;
932 TargetSP target_sp(GetSP());
933 if (target_sp) {
934 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
935 const bool hardware = false;
936 sb_bp = target_sp->CreateBreakpoint(address, false, hardware);
937 }
938
939 return sb_bp;
940}
941
943 LLDB_INSTRUMENT_VA(this, sb_address);
944
945 SBBreakpoint sb_bp;
946 TargetSP target_sp(GetSP());
947 if (!sb_address.IsValid()) {
948 return sb_bp;
949 }
950
951 if (target_sp) {
952 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
953 const bool hardware = false;
954 sb_bp = target_sp->CreateBreakpoint(sb_address.ref(), false, hardware);
955 }
956
957 return sb_bp;
958}
959
962 const lldb::SBFileSpec &source_file,
963 const char *module_name) {
964 LLDB_INSTRUMENT_VA(this, source_regex, source_file, module_name);
965
966 SBFileSpecList module_spec_list;
967
968 if (module_name && module_name[0]) {
969 module_spec_list.Append(FileSpec(module_name));
970 }
971
972 SBFileSpecList source_file_list;
973 if (source_file.IsValid()) {
974 source_file_list.Append(source_file);
975 }
976
977 return BreakpointCreateBySourceRegex(source_regex, module_spec_list,
978 source_file_list);
979}
980
982 const char *source_regex, const SBFileSpecList &module_list,
983 const lldb::SBFileSpecList &source_file_list) {
984 LLDB_INSTRUMENT_VA(this, source_regex, module_list, source_file_list);
985
986 return BreakpointCreateBySourceRegex(source_regex, module_list,
987 source_file_list, SBStringList());
988}
989
991 const char *source_regex, const SBFileSpecList &module_list,
992 const lldb::SBFileSpecList &source_file_list,
993 const SBStringList &func_names) {
994 LLDB_INSTRUMENT_VA(this, source_regex, module_list, source_file_list,
995 func_names);
996
997 SBBreakpoint sb_bp;
998 TargetSP target_sp(GetSP());
999 if (target_sp && source_regex && source_regex[0]) {
1000 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1001 const bool hardware = false;
1002 const LazyBool move_to_nearest_code = eLazyBoolCalculate;
1003 RegularExpression regexp((llvm::StringRef(source_regex)));
1004 std::unordered_set<std::string> func_names_set;
1005 for (size_t i = 0; i < func_names.GetSize(); i++) {
1006 func_names_set.insert(func_names.GetStringAtIndex(i));
1007 }
1008
1009 sb_bp = target_sp->CreateSourceRegexBreakpoint(
1010 module_list.get(), source_file_list.get(), func_names_set,
1011 std::move(regexp), false, hardware, move_to_nearest_code);
1012 }
1013
1014 return sb_bp;
1015}
1016
1019 bool catch_bp, bool throw_bp) {
1020 LLDB_INSTRUMENT_VA(this, language, catch_bp, throw_bp);
1021
1022 SBBreakpoint sb_bp;
1023 TargetSP target_sp(GetSP());
1024 if (target_sp) {
1025 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1026 const bool hardware = false;
1027 sb_bp = target_sp->CreateExceptionBreakpoint(language, catch_bp, throw_bp,
1028 hardware);
1029 }
1030
1031 return sb_bp;
1032}
1033
1035 const char *class_name, SBStructuredData &extra_args,
1036 const SBFileSpecList &module_list, const SBFileSpecList &file_list,
1037 bool request_hardware) {
1038 LLDB_INSTRUMENT_VA(this, class_name, extra_args, module_list, file_list,
1039 request_hardware);
1040
1041 SBBreakpoint sb_bp;
1042 TargetSP target_sp(GetSP());
1043 if (target_sp) {
1044 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1045 Status error;
1046
1047 StructuredData::ObjectSP obj_sp = extra_args.m_impl_up->GetObjectSP();
1048 sb_bp =
1049 target_sp->CreateScriptedBreakpoint(class_name,
1050 module_list.get(),
1051 file_list.get(),
1052 false, /* internal */
1053 request_hardware,
1054 obj_sp,
1055 &error);
1056 }
1057
1058 return sb_bp;
1059}
1060
1062 LLDB_INSTRUMENT_VA(this);
1063
1064 TargetSP target_sp(GetSP());
1065 if (target_sp) {
1066 // The breakpoint list is thread safe, no need to lock
1067 return target_sp->GetBreakpointList().GetSize();
1068 }
1069 return 0;
1070}
1071
1073 LLDB_INSTRUMENT_VA(this, idx);
1074
1075 SBBreakpoint sb_breakpoint;
1076 TargetSP target_sp(GetSP());
1077 if (target_sp) {
1078 // The breakpoint list is thread safe, no need to lock
1079 sb_breakpoint = target_sp->GetBreakpointList().GetBreakpointAtIndex(idx);
1080 }
1081 return sb_breakpoint;
1082}
1083
1085 LLDB_INSTRUMENT_VA(this, bp_id);
1086
1087 bool result = false;
1088 TargetSP target_sp(GetSP());
1089 if (target_sp) {
1090 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1091 result = target_sp->RemoveBreakpointByID(bp_id);
1092 }
1093
1094 return result;
1095}
1096
1098 LLDB_INSTRUMENT_VA(this, bp_id);
1099
1100 SBBreakpoint sb_breakpoint;
1101 TargetSP target_sp(GetSP());
1102 if (target_sp && bp_id != LLDB_INVALID_BREAK_ID) {
1103 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1104 sb_breakpoint = target_sp->GetBreakpointByID(bp_id);
1105 }
1106
1107 return sb_breakpoint;
1108}
1109
1111 SBBreakpointList &bkpts) {
1112 LLDB_INSTRUMENT_VA(this, name, bkpts);
1113
1114 TargetSP target_sp(GetSP());
1115 if (target_sp) {
1116 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1117 llvm::Expected<std::vector<BreakpointSP>> expected_vector =
1118 target_sp->GetBreakpointList().FindBreakpointsByName(name);
1119 if (!expected_vector) {
1120 LLDB_LOG(GetLog(LLDBLog::Breakpoints), "invalid breakpoint name: {}",
1121 llvm::toString(expected_vector.takeError()));
1122 return false;
1123 }
1124 for (BreakpointSP bkpt_sp : *expected_vector) {
1125 bkpts.AppendByID(bkpt_sp->GetID());
1126 }
1127 }
1128 return true;
1129}
1130
1132 LLDB_INSTRUMENT_VA(this, names);
1133
1134 names.Clear();
1135
1136 TargetSP target_sp(GetSP());
1137 if (target_sp) {
1138 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1139
1140 std::vector<std::string> name_vec;
1141 target_sp->GetBreakpointNames(name_vec);
1142 for (auto name : name_vec)
1143 names.AppendString(name.c_str());
1144 }
1145}
1146
1147void SBTarget::DeleteBreakpointName(const char *name) {
1148 LLDB_INSTRUMENT_VA(this, name);
1149
1150 TargetSP target_sp(GetSP());
1151 if (target_sp) {
1152 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1153 target_sp->DeleteBreakpointName(ConstString(name));
1154 }
1155}
1156
1158 LLDB_INSTRUMENT_VA(this);
1159
1160 TargetSP target_sp(GetSP());
1161 if (target_sp) {
1162 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1163 target_sp->EnableAllowedBreakpoints();
1164 return true;
1165 }
1166 return false;
1167}
1168
1170 LLDB_INSTRUMENT_VA(this);
1171
1172 TargetSP target_sp(GetSP());
1173 if (target_sp) {
1174 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1175 target_sp->DisableAllowedBreakpoints();
1176 return true;
1177 }
1178 return false;
1179}
1180
1182 LLDB_INSTRUMENT_VA(this);
1183
1184 TargetSP target_sp(GetSP());
1185 if (target_sp) {
1186 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1187 target_sp->RemoveAllowedBreakpoints();
1188 return true;
1189 }
1190 return false;
1191}
1192
1194 SBBreakpointList &new_bps) {
1195 LLDB_INSTRUMENT_VA(this, source_file, new_bps);
1196
1197 SBStringList empty_name_list;
1198 return BreakpointsCreateFromFile(source_file, empty_name_list, new_bps);
1199}
1200
1202 SBStringList &matching_names,
1203 SBBreakpointList &new_bps) {
1204 LLDB_INSTRUMENT_VA(this, source_file, matching_names, new_bps);
1205
1206 SBError sberr;
1207 TargetSP target_sp(GetSP());
1208 if (!target_sp) {
1209 sberr.SetErrorString(
1210 "BreakpointCreateFromFile called with invalid target.");
1211 return sberr;
1212 }
1213 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1214
1215 BreakpointIDList bp_ids;
1216
1217 std::vector<std::string> name_vector;
1218 size_t num_names = matching_names.GetSize();
1219 for (size_t i = 0; i < num_names; i++)
1220 name_vector.push_back(matching_names.GetStringAtIndex(i));
1221
1222 sberr.ref() = target_sp->CreateBreakpointsFromFile(source_file.ref(),
1223 name_vector, bp_ids);
1224 if (sberr.Fail())
1225 return sberr;
1226
1227 size_t num_bkpts = bp_ids.GetSize();
1228 for (size_t i = 0; i < num_bkpts; i++) {
1229 BreakpointID bp_id = bp_ids.GetBreakpointIDAtIndex(i);
1230 new_bps.AppendByID(bp_id.GetBreakpointID());
1231 }
1232 return sberr;
1233}
1234
1236 LLDB_INSTRUMENT_VA(this, dest_file);
1237
1238 SBError sberr;
1239 TargetSP target_sp(GetSP());
1240 if (!target_sp) {
1241 sberr.SetErrorString("BreakpointWriteToFile called with invalid target.");
1242 return sberr;
1243 }
1244 SBBreakpointList bkpt_list(*this);
1245 return BreakpointsWriteToFile(dest_file, bkpt_list);
1246}
1247
1249 SBBreakpointList &bkpt_list,
1250 bool append) {
1251 LLDB_INSTRUMENT_VA(this, dest_file, bkpt_list, append);
1252
1253 SBError sberr;
1254 TargetSP target_sp(GetSP());
1255 if (!target_sp) {
1256 sberr.SetErrorString("BreakpointWriteToFile called with invalid target.");
1257 return sberr;
1258 }
1259
1260 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1261 BreakpointIDList bp_id_list;
1262 bkpt_list.CopyToBreakpointIDList(bp_id_list);
1263 sberr.ref() = target_sp->SerializeBreakpointsToFile(dest_file.ref(),
1264 bp_id_list, append);
1265 return sberr;
1266}
1267
1269 LLDB_INSTRUMENT_VA(this);
1270
1271 TargetSP target_sp(GetSP());
1272 if (target_sp) {
1273 // The watchpoint list is thread safe, no need to lock
1274 return target_sp->GetWatchpointList().GetSize();
1275 }
1276 return 0;
1277}
1278
1280 LLDB_INSTRUMENT_VA(this, idx);
1281
1282 SBWatchpoint sb_watchpoint;
1283 TargetSP target_sp(GetSP());
1284 if (target_sp) {
1285 // The watchpoint list is thread safe, no need to lock
1286 sb_watchpoint.SetSP(target_sp->GetWatchpointList().GetByIndex(idx));
1287 }
1288 return sb_watchpoint;
1289}
1290
1292 LLDB_INSTRUMENT_VA(this, wp_id);
1293
1294 bool result = false;
1295 TargetSP target_sp(GetSP());
1296 if (target_sp) {
1297 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1298 std::unique_lock<std::recursive_mutex> lock;
1299 target_sp->GetWatchpointList().GetListMutex(lock);
1300 result = target_sp->RemoveWatchpointByID(wp_id);
1301 }
1302
1303 return result;
1304}
1305
1307 LLDB_INSTRUMENT_VA(this, wp_id);
1308
1309 SBWatchpoint sb_watchpoint;
1310 lldb::WatchpointSP watchpoint_sp;
1311 TargetSP target_sp(GetSP());
1312 if (target_sp && wp_id != LLDB_INVALID_WATCH_ID) {
1313 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1314 std::unique_lock<std::recursive_mutex> lock;
1315 target_sp->GetWatchpointList().GetListMutex(lock);
1316 watchpoint_sp = target_sp->GetWatchpointList().FindByID(wp_id);
1317 sb_watchpoint.SetSP(watchpoint_sp);
1318 }
1319
1320 return sb_watchpoint;
1321}
1322
1324 bool read, bool write,
1325 SBError &error) {
1326 LLDB_INSTRUMENT_VA(this, addr, size, read, write, error);
1327
1328 SBWatchpoint sb_watchpoint;
1329 lldb::WatchpointSP watchpoint_sp;
1330 TargetSP target_sp(GetSP());
1331 if (target_sp && (read || write) && addr != LLDB_INVALID_ADDRESS &&
1332 size > 0) {
1333 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1334 uint32_t watch_type = 0;
1335 if (read)
1336 watch_type |= LLDB_WATCH_TYPE_READ;
1337 if (write)
1338 watch_type |= LLDB_WATCH_TYPE_WRITE;
1339 if (watch_type == 0) {
1340 error.SetErrorString(
1341 "Can't create a watchpoint that is neither read nor write.");
1342 return sb_watchpoint;
1343 }
1344
1345 // Target::CreateWatchpoint() is thread safe.
1346 Status cw_error;
1347 // This API doesn't take in a type, so we can't figure out what it is.
1348 CompilerType *type = nullptr;
1349 watchpoint_sp =
1350 target_sp->CreateWatchpoint(addr, size, type, watch_type, cw_error);
1351 error.SetError(cw_error);
1352 sb_watchpoint.SetSP(watchpoint_sp);
1353 }
1354
1355 return sb_watchpoint;
1356}
1357
1359 LLDB_INSTRUMENT_VA(this);
1360
1361 TargetSP target_sp(GetSP());
1362 if (target_sp) {
1363 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1364 std::unique_lock<std::recursive_mutex> lock;
1365 target_sp->GetWatchpointList().GetListMutex(lock);
1366 target_sp->EnableAllWatchpoints();
1367 return true;
1368 }
1369 return false;
1370}
1371
1373 LLDB_INSTRUMENT_VA(this);
1374
1375 TargetSP target_sp(GetSP());
1376 if (target_sp) {
1377 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1378 std::unique_lock<std::recursive_mutex> lock;
1379 target_sp->GetWatchpointList().GetListMutex(lock);
1380 target_sp->DisableAllWatchpoints();
1381 return true;
1382 }
1383 return false;
1384}
1385
1387 SBType type) {
1388 LLDB_INSTRUMENT_VA(this, name, addr, type);
1389
1390 SBValue sb_value;
1391 lldb::ValueObjectSP new_value_sp;
1392 if (IsValid() && name && *name && addr.IsValid() && type.IsValid()) {
1393 lldb::addr_t load_addr(addr.GetLoadAddress(*this));
1394 ExecutionContext exe_ctx(
1396 CompilerType ast_type(type.GetSP()->GetCompilerType(true));
1397 new_value_sp = ValueObject::CreateValueObjectFromAddress(name, load_addr,
1398 exe_ctx, ast_type);
1399 }
1400 sb_value.SetSP(new_value_sp);
1401 return sb_value;
1402}
1403
1405 lldb::SBType type) {
1406 LLDB_INSTRUMENT_VA(this, name, data, type);
1407
1408 SBValue sb_value;
1409 lldb::ValueObjectSP new_value_sp;
1410 if (IsValid() && name && *name && data.IsValid() && type.IsValid()) {
1411 DataExtractorSP extractor(*data);
1412 ExecutionContext exe_ctx(
1414 CompilerType ast_type(type.GetSP()->GetCompilerType(true));
1415 new_value_sp = ValueObject::CreateValueObjectFromData(name, *extractor,
1416 exe_ctx, ast_type);
1417 }
1418 sb_value.SetSP(new_value_sp);
1419 return sb_value;
1420}
1421
1423 const char *expr) {
1424 LLDB_INSTRUMENT_VA(this, name, expr);
1425
1426 SBValue sb_value;
1427 lldb::ValueObjectSP new_value_sp;
1428 if (IsValid() && name && *name && expr && *expr) {
1429 ExecutionContext exe_ctx(
1431 new_value_sp =
1433 }
1434 sb_value.SetSP(new_value_sp);
1435 return sb_value;
1436}
1437
1439 LLDB_INSTRUMENT_VA(this);
1440
1441 TargetSP target_sp(GetSP());
1442 if (target_sp) {
1443 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1444 std::unique_lock<std::recursive_mutex> lock;
1445 target_sp->GetWatchpointList().GetListMutex(lock);
1446 target_sp->RemoveAllWatchpoints();
1447 return true;
1448 }
1449 return false;
1450}
1451
1452void SBTarget::AppendImageSearchPath(const char *from, const char *to,
1454 LLDB_INSTRUMENT_VA(this, from, to, error);
1455
1456 TargetSP target_sp(GetSP());
1457 if (!target_sp)
1458 return error.SetErrorString("invalid target");
1459
1460 llvm::StringRef srFrom = from, srTo = to;
1461 if (srFrom.empty())
1462 return error.SetErrorString("<from> path can't be empty");
1463 if (srTo.empty())
1464 return error.SetErrorString("<to> path can't be empty");
1465
1466 target_sp->GetImageSearchPathList().Append(srFrom, srTo, true);
1467}
1468
1469lldb::SBModule SBTarget::AddModule(const char *path, const char *triple,
1470 const char *uuid_cstr) {
1471 LLDB_INSTRUMENT_VA(this, path, triple, uuid_cstr);
1472
1473 return AddModule(path, triple, uuid_cstr, nullptr);
1474}
1475
1476lldb::SBModule SBTarget::AddModule(const char *path, const char *triple,
1477 const char *uuid_cstr, const char *symfile) {
1478 LLDB_INSTRUMENT_VA(this, path, triple, uuid_cstr, symfile);
1479
1480 lldb::SBModule sb_module;
1481 TargetSP target_sp(GetSP());
1482 if (target_sp) {
1483 ModuleSpec module_spec;
1484 if (path)
1485 module_spec.GetFileSpec().SetFile(path, FileSpec::Style::native);
1486
1487 if (uuid_cstr)
1488 module_spec.GetUUID().SetFromStringRef(uuid_cstr);
1489
1490 if (triple)
1492 target_sp->GetPlatform().get(), triple);
1493 else
1494 module_spec.GetArchitecture() = target_sp->GetArchitecture();
1495
1496 if (symfile)
1497 module_spec.GetSymbolFileSpec().SetFile(symfile, FileSpec::Style::native);
1498
1499 sb_module.SetSP(target_sp->GetOrCreateModule(module_spec, true /* notify */));
1500 }
1501 return sb_module;
1502}
1503
1505 LLDB_INSTRUMENT_VA(this, module_spec);
1506
1507 lldb::SBModule sb_module;
1508 TargetSP target_sp(GetSP());
1509 if (target_sp)
1510 sb_module.SetSP(target_sp->GetOrCreateModule(*module_spec.m_opaque_up,
1511 true /* notify */));
1512 return sb_module;
1513}
1514
1516 LLDB_INSTRUMENT_VA(this, module);
1517
1518 TargetSP target_sp(GetSP());
1519 if (target_sp) {
1520 target_sp->GetImages().AppendIfNeeded(module.GetSP());
1521 return true;
1522 }
1523 return false;
1524}
1525
1527 LLDB_INSTRUMENT_VA(this);
1528
1529 uint32_t num = 0;
1530 TargetSP target_sp(GetSP());
1531 if (target_sp) {
1532 // The module list is thread safe, no need to lock
1533 num = target_sp->GetImages().GetSize();
1534 }
1535
1536 return num;
1537}
1538
1540 LLDB_INSTRUMENT_VA(this);
1541
1542 m_opaque_sp.reset();
1543}
1544
1546 LLDB_INSTRUMENT_VA(this, sb_file_spec);
1547
1548 SBModule sb_module;
1549 TargetSP target_sp(GetSP());
1550 if (target_sp && sb_file_spec.IsValid()) {
1551 ModuleSpec module_spec(*sb_file_spec);
1552 // The module list is thread safe, no need to lock
1553 sb_module.SetSP(target_sp->GetImages().FindFirstModule(module_spec));
1554 }
1555 return sb_module;
1556}
1557
1559 LLDB_INSTRUMENT_VA(this, sb_file_spec);
1560
1561 SBSymbolContextList sb_sc_list;
1562 const TargetSP target_sp(GetSP());
1563 if (target_sp && sb_file_spec.IsValid())
1564 target_sp->GetImages().FindCompileUnits(*sb_file_spec, *sb_sc_list);
1565 return sb_sc_list;
1566}
1567
1569 LLDB_INSTRUMENT_VA(this);
1570
1571 TargetSP target_sp(GetSP());
1572 if (target_sp)
1573 return target_sp->GetArchitecture().GetByteOrder();
1574 return eByteOrderInvalid;
1575}
1576
1577const char *SBTarget::GetTriple() {
1578 LLDB_INSTRUMENT_VA(this);
1579
1580 TargetSP target_sp(GetSP());
1581 if (!target_sp)
1582 return nullptr;
1583
1584 std::string triple(target_sp->GetArchitecture().GetTriple().str());
1585 // Unique the string so we don't run into ownership issues since the const
1586 // strings put the string into the string pool once and the strings never
1587 // comes out
1588 ConstString const_triple(triple.c_str());
1589 return const_triple.GetCString();
1590}
1591
1593 LLDB_INSTRUMENT_VA(this);
1594
1595 TargetSP target_sp(GetSP());
1596 if (!target_sp)
1597 return nullptr;
1598
1599 std::string abi_name(target_sp->GetABIName().str());
1600 ConstString const_name(abi_name.c_str());
1601 return const_name.GetCString();
1602}
1603
1605 LLDB_INSTRUMENT_VA(this);
1606
1607 TargetSP target_sp(GetSP());
1608 if (target_sp) {
1609 return target_sp->GetArchitecture().GetDataByteSize();
1610 }
1611 return 0;
1612}
1613
1615 LLDB_INSTRUMENT_VA(this);
1616
1617 TargetSP target_sp(GetSP());
1618 if (target_sp) {
1619 return target_sp->GetArchitecture().GetCodeByteSize();
1620 }
1621 return 0;
1622}
1623
1625 LLDB_INSTRUMENT_VA(this);
1626
1627 TargetSP target_sp(GetSP());
1628 if(target_sp){
1629 return target_sp->GetMaximumNumberOfChildrenToDisplay();
1630 }
1631 return 0;
1632}
1633
1635 LLDB_INSTRUMENT_VA(this);
1636
1637 TargetSP target_sp(GetSP());
1638 if (target_sp)
1639 return target_sp->GetArchitecture().GetAddressByteSize();
1640 return sizeof(void *);
1641}
1642
1644 LLDB_INSTRUMENT_VA(this, idx);
1645
1646 SBModule sb_module;
1647 ModuleSP module_sp;
1648 TargetSP target_sp(GetSP());
1649 if (target_sp) {
1650 // The module list is thread safe, no need to lock
1651 module_sp = target_sp->GetImages().GetModuleAtIndex(idx);
1652 sb_module.SetSP(module_sp);
1653 }
1654
1655 return sb_module;
1656}
1657
1659 LLDB_INSTRUMENT_VA(this, module);
1660
1661 TargetSP target_sp(GetSP());
1662 if (target_sp)
1663 return target_sp->GetImages().Remove(module.GetSP());
1664 return false;
1665}
1666
1668 LLDB_INSTRUMENT_VA(this);
1669
1670 TargetSP target_sp(GetSP());
1671 SBBroadcaster broadcaster(target_sp.get(), false);
1672
1673 return broadcaster;
1674}
1675
1677 lldb::DescriptionLevel description_level) {
1678 LLDB_INSTRUMENT_VA(this, description, description_level);
1679
1680 Stream &strm = description.ref();
1681
1682 TargetSP target_sp(GetSP());
1683 if (target_sp) {
1684 target_sp->Dump(&strm, description_level);
1685 } else
1686 strm.PutCString("No value");
1687
1688 return true;
1689}
1690
1692 uint32_t name_type_mask) {
1693 LLDB_INSTRUMENT_VA(this, name, name_type_mask);
1694
1695 lldb::SBSymbolContextList sb_sc_list;
1696 if (!name || !name[0])
1697 return sb_sc_list;
1698
1699 TargetSP target_sp(GetSP());
1700 if (!target_sp)
1701 return sb_sc_list;
1702
1703 ModuleFunctionSearchOptions function_options;
1704 function_options.include_symbols = true;
1705 function_options.include_inlines = true;
1706
1707 FunctionNameType mask = static_cast<FunctionNameType>(name_type_mask);
1708 target_sp->GetImages().FindFunctions(ConstString(name), mask,
1709 function_options, *sb_sc_list);
1710 return sb_sc_list;
1711}
1712
1714 uint32_t max_matches,
1715 MatchType matchtype) {
1716 LLDB_INSTRUMENT_VA(this, name, max_matches, matchtype);
1717
1718 lldb::SBSymbolContextList sb_sc_list;
1719 if (name && name[0]) {
1720 llvm::StringRef name_ref(name);
1721 TargetSP target_sp(GetSP());
1722 if (target_sp) {
1723 ModuleFunctionSearchOptions function_options;
1724 function_options.include_symbols = true;
1725 function_options.include_inlines = true;
1726
1727 std::string regexstr;
1728 switch (matchtype) {
1729 case eMatchTypeRegex:
1730 target_sp->GetImages().FindFunctions(RegularExpression(name_ref),
1731 function_options, *sb_sc_list);
1732 break;
1734 regexstr = llvm::Regex::escape(name) + ".*";
1735 target_sp->GetImages().FindFunctions(RegularExpression(regexstr),
1736 function_options, *sb_sc_list);
1737 break;
1738 default:
1739 target_sp->GetImages().FindFunctions(ConstString(name),
1740 eFunctionNameTypeAny,
1741 function_options, *sb_sc_list);
1742 break;
1743 }
1744 }
1745 }
1746 return sb_sc_list;
1747}
1748
1749lldb::SBType SBTarget::FindFirstType(const char *typename_cstr) {
1750 LLDB_INSTRUMENT_VA(this, typename_cstr);
1751
1752 TargetSP target_sp(GetSP());
1753 if (typename_cstr && typename_cstr[0] && target_sp) {
1754 ConstString const_typename(typename_cstr);
1755 SymbolContext sc;
1756 const bool exact_match = false;
1757
1758 const ModuleList &module_list = target_sp->GetImages();
1759 size_t count = module_list.GetSize();
1760 for (size_t idx = 0; idx < count; idx++) {
1761 ModuleSP module_sp(module_list.GetModuleAtIndex(idx));
1762 if (module_sp) {
1763 TypeSP type_sp(
1764 module_sp->FindFirstType(sc, const_typename, exact_match));
1765 if (type_sp)
1766 return SBType(type_sp);
1767 }
1768 }
1769
1770 // Didn't find the type in the symbols; Try the loaded language runtimes.
1771 if (auto process_sp = target_sp->GetProcessSP()) {
1772 for (auto *runtime : process_sp->GetLanguageRuntimes()) {
1773 if (auto vendor = runtime->GetDeclVendor()) {
1774 auto types = vendor->FindTypes(const_typename, /*max_matches*/ 1);
1775 if (!types.empty())
1776 return SBType(types.front());
1777 }
1778 }
1779 }
1780
1781 // No matches, search for basic typename matches.
1782 for (auto type_system_sp : target_sp->GetScratchTypeSystems())
1783 if (auto type = type_system_sp->GetBuiltinTypeByName(const_typename))
1784 return SBType(type);
1785 }
1786
1787 return SBType();
1788}
1789
1791 LLDB_INSTRUMENT_VA(this, type);
1792
1793 TargetSP target_sp(GetSP());
1794 if (target_sp) {
1795 for (auto type_system_sp : target_sp->GetScratchTypeSystems())
1796 if (auto compiler_type = type_system_sp->GetBasicTypeFromAST(type))
1797 return SBType(compiler_type);
1798 }
1799 return SBType();
1800}
1801
1802lldb::SBTypeList SBTarget::FindTypes(const char *typename_cstr) {
1803 LLDB_INSTRUMENT_VA(this, typename_cstr);
1804
1805 SBTypeList sb_type_list;
1806 TargetSP target_sp(GetSP());
1807 if (typename_cstr && typename_cstr[0] && target_sp) {
1808 ModuleList &images = target_sp->GetImages();
1809 ConstString const_typename(typename_cstr);
1810 bool exact_match = false;
1811 TypeList type_list;
1812 llvm::DenseSet<SymbolFile *> searched_symbol_files;
1813 images.FindTypes(nullptr, const_typename, exact_match, UINT32_MAX,
1814 searched_symbol_files, type_list);
1815
1816 for (size_t idx = 0; idx < type_list.GetSize(); idx++) {
1817 TypeSP type_sp(type_list.GetTypeAtIndex(idx));
1818 if (type_sp)
1819 sb_type_list.Append(SBType(type_sp));
1820 }
1821
1822 // Try the loaded language runtimes
1823 if (auto process_sp = target_sp->GetProcessSP()) {
1824 for (auto *runtime : process_sp->GetLanguageRuntimes()) {
1825 if (auto *vendor = runtime->GetDeclVendor()) {
1826 auto types =
1827 vendor->FindTypes(const_typename, /*max_matches*/ UINT32_MAX);
1828 for (auto type : types)
1829 sb_type_list.Append(SBType(type));
1830 }
1831 }
1832 }
1833
1834 if (sb_type_list.GetSize() == 0) {
1835 // No matches, search for basic typename matches
1836 for (auto type_system_sp : target_sp->GetScratchTypeSystems())
1837 if (auto compiler_type =
1838 type_system_sp->GetBuiltinTypeByName(const_typename))
1839 sb_type_list.Append(SBType(compiler_type));
1840 }
1841 }
1842 return sb_type_list;
1843}
1844
1846 uint32_t max_matches) {
1847 LLDB_INSTRUMENT_VA(this, name, max_matches);
1848
1849 SBValueList sb_value_list;
1850
1851 TargetSP target_sp(GetSP());
1852 if (name && target_sp) {
1853 VariableList variable_list;
1854 target_sp->GetImages().FindGlobalVariables(ConstString(name), max_matches,
1855 variable_list);
1856 if (!variable_list.Empty()) {
1857 ExecutionContextScope *exe_scope = target_sp->GetProcessSP().get();
1858 if (exe_scope == nullptr)
1859 exe_scope = target_sp.get();
1860 for (const VariableSP &var_sp : variable_list) {
1861 lldb::ValueObjectSP valobj_sp(
1862 ValueObjectVariable::Create(exe_scope, var_sp));
1863 if (valobj_sp)
1864 sb_value_list.Append(SBValue(valobj_sp));
1865 }
1866 }
1867 }
1868
1869 return sb_value_list;
1870}
1871
1873 uint32_t max_matches,
1874 MatchType matchtype) {
1875 LLDB_INSTRUMENT_VA(this, name, max_matches, matchtype);
1876
1877 SBValueList sb_value_list;
1878
1879 TargetSP target_sp(GetSP());
1880 if (name && target_sp) {
1881 llvm::StringRef name_ref(name);
1882 VariableList variable_list;
1883
1884 std::string regexstr;
1885 switch (matchtype) {
1886 case eMatchTypeNormal:
1887 target_sp->GetImages().FindGlobalVariables(ConstString(name), max_matches,
1888 variable_list);
1889 break;
1890 case eMatchTypeRegex:
1891 target_sp->GetImages().FindGlobalVariables(RegularExpression(name_ref),
1892 max_matches, variable_list);
1893 break;
1895 regexstr = llvm::Regex::escape(name) + ".*";
1896 target_sp->GetImages().FindGlobalVariables(RegularExpression(regexstr),
1897 max_matches, variable_list);
1898 break;
1899 }
1900 if (!variable_list.Empty()) {
1901 ExecutionContextScope *exe_scope = target_sp->GetProcessSP().get();
1902 if (exe_scope == nullptr)
1903 exe_scope = target_sp.get();
1904 for (const VariableSP &var_sp : variable_list) {
1905 lldb::ValueObjectSP valobj_sp(
1906 ValueObjectVariable::Create(exe_scope, var_sp));
1907 if (valobj_sp)
1908 sb_value_list.Append(SBValue(valobj_sp));
1909 }
1910 }
1911 }
1912
1913 return sb_value_list;
1914}
1915
1917 LLDB_INSTRUMENT_VA(this, name);
1918
1919 SBValueList sb_value_list(FindGlobalVariables(name, 1));
1920 if (sb_value_list.IsValid() && sb_value_list.GetSize() > 0)
1921 return sb_value_list.GetValueAtIndex(0);
1922 return SBValue();
1923}
1924
1926 LLDB_INSTRUMENT_VA(this);
1927
1928 SBSourceManager source_manager(*this);
1929 return source_manager;
1930}
1931
1933 uint32_t count) {
1934 LLDB_INSTRUMENT_VA(this, base_addr, count);
1935
1936 return ReadInstructions(base_addr, count, nullptr);
1937}
1938
1940 uint32_t count,
1941 const char *flavor_string) {
1942 LLDB_INSTRUMENT_VA(this, base_addr, count, flavor_string);
1943
1944 SBInstructionList sb_instructions;
1945
1946 TargetSP target_sp(GetSP());
1947 if (target_sp) {
1948 Address *addr_ptr = base_addr.get();
1949
1950 if (addr_ptr) {
1951 DataBufferHeap data(
1952 target_sp->GetArchitecture().GetMaximumOpcodeByteSize() * count, 0);
1953 bool force_live_memory = true;
1956 const size_t bytes_read =
1957 target_sp->ReadMemory(*addr_ptr, data.GetBytes(), data.GetByteSize(),
1958 error, force_live_memory, &load_addr);
1959 const bool data_from_file = load_addr == LLDB_INVALID_ADDRESS;
1961 target_sp->GetArchitecture(), nullptr, flavor_string, *addr_ptr,
1962 data.GetBytes(), bytes_read, count, data_from_file));
1963 }
1964 }
1965
1966 return sb_instructions;
1967}
1968
1970 const void *buf,
1971 size_t size) {
1972 LLDB_INSTRUMENT_VA(this, base_addr, buf, size);
1973
1974 return GetInstructionsWithFlavor(base_addr, nullptr, buf, size);
1975}
1976
1979 const char *flavor_string, const void *buf,
1980 size_t size) {
1981 LLDB_INSTRUMENT_VA(this, base_addr, flavor_string, buf, size);
1982
1983 SBInstructionList sb_instructions;
1984
1985 TargetSP target_sp(GetSP());
1986 if (target_sp) {
1987 Address addr;
1988
1989 if (base_addr.get())
1990 addr = *base_addr.get();
1991
1992 const bool data_from_file = true;
1993
1995 target_sp->GetArchitecture(), nullptr, flavor_string, addr, buf, size,
1996 UINT32_MAX, data_from_file));
1997 }
1998
1999 return sb_instructions;
2000}
2001
2003 const void *buf,
2004 size_t size) {
2005 LLDB_INSTRUMENT_VA(this, base_addr, buf, size);
2006
2007 return GetInstructionsWithFlavor(ResolveLoadAddress(base_addr), nullptr, buf,
2008 size);
2009}
2010
2013 const char *flavor_string, const void *buf,
2014 size_t size) {
2015 LLDB_INSTRUMENT_VA(this, base_addr, flavor_string, buf, size);
2016
2017 return GetInstructionsWithFlavor(ResolveLoadAddress(base_addr), flavor_string,
2018 buf, size);
2019}
2020
2022 lldb::addr_t section_base_addr) {
2023 LLDB_INSTRUMENT_VA(this, section, section_base_addr);
2024
2025 SBError sb_error;
2026 TargetSP target_sp(GetSP());
2027 if (target_sp) {
2028 if (!section.IsValid()) {
2029 sb_error.SetErrorStringWithFormat("invalid section");
2030 } else {
2031 SectionSP section_sp(section.GetSP());
2032 if (section_sp) {
2033 if (section_sp->IsThreadSpecific()) {
2034 sb_error.SetErrorString(
2035 "thread specific sections are not yet supported");
2036 } else {
2037 ProcessSP process_sp(target_sp->GetProcessSP());
2038 if (target_sp->SetSectionLoadAddress(section_sp, section_base_addr)) {
2039 ModuleSP module_sp(section_sp->GetModule());
2040 if (module_sp) {
2041 ModuleList module_list;
2042 module_list.Append(module_sp);
2043 target_sp->ModulesDidLoad(module_list);
2044 }
2045 // Flush info in the process (stack frames, etc)
2046 if (process_sp)
2047 process_sp->Flush();
2048 }
2049 }
2050 }
2051 }
2052 } else {
2053 sb_error.SetErrorString("invalid target");
2054 }
2055 return sb_error;
2056}
2057
2059 LLDB_INSTRUMENT_VA(this, section);
2060
2061 SBError sb_error;
2062
2063 TargetSP target_sp(GetSP());
2064 if (target_sp) {
2065 if (!section.IsValid()) {
2066 sb_error.SetErrorStringWithFormat("invalid section");
2067 } else {
2068 SectionSP section_sp(section.GetSP());
2069 if (section_sp) {
2070 ProcessSP process_sp(target_sp->GetProcessSP());
2071 if (target_sp->SetSectionUnloaded(section_sp)) {
2072 ModuleSP module_sp(section_sp->GetModule());
2073 if (module_sp) {
2074 ModuleList module_list;
2075 module_list.Append(module_sp);
2076 target_sp->ModulesDidUnload(module_list, false);
2077 }
2078 // Flush info in the process (stack frames, etc)
2079 if (process_sp)
2080 process_sp->Flush();
2081 }
2082 } else {
2083 sb_error.SetErrorStringWithFormat("invalid section");
2084 }
2085 }
2086 } else {
2087 sb_error.SetErrorStringWithFormat("invalid target");
2088 }
2089 return sb_error;
2090}
2091
2093 int64_t slide_offset) {
2094 LLDB_INSTRUMENT_VA(this, module, slide_offset);
2095
2096 if (slide_offset < 0) {
2097 SBError sb_error;
2098 sb_error.SetErrorStringWithFormat("slide must be positive");
2099 return sb_error;
2100 }
2101
2102 return SetModuleLoadAddress(module, static_cast<uint64_t>(slide_offset));
2103}
2104
2106 uint64_t slide_offset) {
2107
2108 SBError sb_error;
2109
2110 TargetSP target_sp(GetSP());
2111 if (target_sp) {
2112 ModuleSP module_sp(module.GetSP());
2113 if (module_sp) {
2114 bool changed = false;
2115 if (module_sp->SetLoadAddress(*target_sp, slide_offset, true, changed)) {
2116 // The load was successful, make sure that at least some sections
2117 // changed before we notify that our module was loaded.
2118 if (changed) {
2119 ModuleList module_list;
2120 module_list.Append(module_sp);
2121 target_sp->ModulesDidLoad(module_list);
2122 // Flush info in the process (stack frames, etc)
2123 ProcessSP process_sp(target_sp->GetProcessSP());
2124 if (process_sp)
2125 process_sp->Flush();
2126 }
2127 }
2128 } else {
2129 sb_error.SetErrorStringWithFormat("invalid module");
2130 }
2131
2132 } else {
2133 sb_error.SetErrorStringWithFormat("invalid target");
2134 }
2135 return sb_error;
2136}
2137
2139 LLDB_INSTRUMENT_VA(this, module);
2140
2141 SBError sb_error;
2142
2143 char path[PATH_MAX];
2144 TargetSP target_sp(GetSP());
2145 if (target_sp) {
2146 ModuleSP module_sp(module.GetSP());
2147 if (module_sp) {
2148 ObjectFile *objfile = module_sp->GetObjectFile();
2149 if (objfile) {
2150 SectionList *section_list = objfile->GetSectionList();
2151 if (section_list) {
2152 ProcessSP process_sp(target_sp->GetProcessSP());
2153
2154 bool changed = false;
2155 const size_t num_sections = section_list->GetSize();
2156 for (size_t sect_idx = 0; sect_idx < num_sections; ++sect_idx) {
2157 SectionSP section_sp(section_list->GetSectionAtIndex(sect_idx));
2158 if (section_sp)
2159 changed |= target_sp->SetSectionUnloaded(section_sp);
2160 }
2161 if (changed) {
2162 ModuleList module_list;
2163 module_list.Append(module_sp);
2164 target_sp->ModulesDidUnload(module_list, false);
2165 // Flush info in the process (stack frames, etc)
2166 ProcessSP process_sp(target_sp->GetProcessSP());
2167 if (process_sp)
2168 process_sp->Flush();
2169 }
2170 } else {
2171 module_sp->GetFileSpec().GetPath(path, sizeof(path));
2172 sb_error.SetErrorStringWithFormat("no sections in object file '%s'",
2173 path);
2174 }
2175 } else {
2176 module_sp->GetFileSpec().GetPath(path, sizeof(path));
2177 sb_error.SetErrorStringWithFormat("no object file for module '%s'",
2178 path);
2179 }
2180 } else {
2181 sb_error.SetErrorStringWithFormat("invalid module");
2182 }
2183 } else {
2184 sb_error.SetErrorStringWithFormat("invalid target");
2185 }
2186 return sb_error;
2187}
2188
2190 lldb::SymbolType symbol_type) {
2191 LLDB_INSTRUMENT_VA(this, name, symbol_type);
2192
2193 SBSymbolContextList sb_sc_list;
2194 if (name && name[0]) {
2195 TargetSP target_sp(GetSP());
2196 if (target_sp)
2197 target_sp->GetImages().FindSymbolsWithNameAndType(
2198 ConstString(name), symbol_type, *sb_sc_list);
2199 }
2200 return sb_sc_list;
2201}
2202
2204 LLDB_INSTRUMENT_VA(this, expr);
2205
2206 TargetSP target_sp(GetSP());
2207 if (!target_sp)
2208 return SBValue();
2209
2210 SBExpressionOptions options;
2211 lldb::DynamicValueType fetch_dynamic_value =
2212 target_sp->GetPreferDynamicValue();
2213 options.SetFetchDynamicValue(fetch_dynamic_value);
2214 options.SetUnwindOnError(true);
2215 return EvaluateExpression(expr, options);
2216}
2217
2219 const SBExpressionOptions &options) {
2220 LLDB_INSTRUMENT_VA(this, expr, options);
2221
2222 Log *expr_log = GetLog(LLDBLog::Expressions);
2223 SBValue expr_result;
2224 ValueObjectSP expr_value_sp;
2225 TargetSP target_sp(GetSP());
2226 StackFrame *frame = nullptr;
2227 if (target_sp) {
2228 if (expr == nullptr || expr[0] == '\0') {
2229 return expr_result;
2230 }
2231
2232 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
2233 ExecutionContext exe_ctx(m_opaque_sp.get());
2234
2235 frame = exe_ctx.GetFramePtr();
2236 Target *target = exe_ctx.GetTargetPtr();
2237 Process *process = exe_ctx.GetProcessPtr();
2238
2239 if (target) {
2240 // If we have a process, make sure to lock the runlock:
2241 if (process) {
2242 Process::StopLocker stop_locker;
2243 if (stop_locker.TryLock(&process->GetRunLock())) {
2244 target->EvaluateExpression(expr, frame, expr_value_sp, options.ref());
2245 } else {
2246 Status error;
2247 error.SetErrorString("can't evaluate expressions when the "
2248 "process is running.");
2249 expr_value_sp = ValueObjectConstResult::Create(nullptr, error);
2250 }
2251 } else {
2252 target->EvaluateExpression(expr, frame, expr_value_sp, options.ref());
2253 }
2254
2255 expr_result.SetSP(expr_value_sp, options.GetFetchDynamicValue());
2256 }
2257 }
2258 LLDB_LOGF(expr_log,
2259 "** [SBTarget::EvaluateExpression] Expression result is "
2260 "%s, summary %s **",
2261 expr_result.GetValue(), expr_result.GetSummary());
2262 return expr_result;
2263}
2264
2266 LLDB_INSTRUMENT_VA(this);
2267
2268 TargetSP target_sp(GetSP());
2269 if (target_sp) {
2270 ABISP abi_sp;
2271 ProcessSP process_sp(target_sp->GetProcessSP());
2272 if (process_sp)
2273 abi_sp = process_sp->GetABI();
2274 else
2275 abi_sp = ABI::FindPlugin(ProcessSP(), target_sp->GetArchitecture());
2276 if (abi_sp)
2277 return abi_sp->GetRedZoneSize();
2278 }
2279 return 0;
2280}
2281
2282bool SBTarget::IsLoaded(const SBModule &module) const {
2283 LLDB_INSTRUMENT_VA(this, module);
2284
2285 TargetSP target_sp(GetSP());
2286 if (!target_sp)
2287 return false;
2288
2289 ModuleSP module_sp(module.GetSP());
2290 if (!module_sp)
2291 return false;
2292
2293 return module_sp->IsLoadedInTarget(target_sp.get());
2294}
2295
2297 LLDB_INSTRUMENT_VA(this);
2298
2299 lldb::SBLaunchInfo launch_info(nullptr);
2300 TargetSP target_sp(GetSP());
2301 if (target_sp)
2302 launch_info.set_ref(m_opaque_sp->GetProcessLaunchInfo());
2303 return launch_info;
2304}
2305
2307 LLDB_INSTRUMENT_VA(this, launch_info);
2308
2309 TargetSP target_sp(GetSP());
2310 if (target_sp)
2311 m_opaque_sp->SetProcessLaunchInfo(launch_info.ref());
2312}
2313
2315 LLDB_INSTRUMENT_VA(this);
2316 TargetSP target_sp(GetSP());
2317
2318 if (target_sp) {
2319 return SBEnvironment(target_sp->GetEnvironment());
2320 }
2321
2322 return SBEnvironment();
2323}
2324
2326 LLDB_INSTRUMENT_VA(this);
2327 TargetSP target_sp(GetSP());
2328
2329 if (target_sp)
2330 return SBTrace(target_sp->GetTrace());
2331
2332 return SBTrace();
2333}
2334
2337 TargetSP target_sp(GetSP());
2338 error.Clear();
2339
2340 if (target_sp) {
2341 if (llvm::Expected<lldb::TraceSP> trace_sp = target_sp->CreateTrace()) {
2342 return SBTrace(*trace_sp);
2343 } else {
2344 error.SetErrorString(llvm::toString(trace_sp.takeError()).c_str());
2345 }
2346 } else {
2347 error.SetErrorString("missing target");
2348 }
2349 return SBTrace();
2350}
static llvm::raw_ostream & error(Stream &strm)
#define LLDB_INSTRUMENT()
#define LLDB_INSTRUMENT_VA(...)
#define LLDB_LOG(log,...)
The LLDB_LOG* macros defined below are the way to emit log messages.
Definition: Log.h:337
#define LLDB_LOGF(log,...)
Definition: Log.h:344
static Status AttachToProcess(ProcessAttachInfo &attach_info, Target &target)
Definition: SBTarget.cpp:76
lldb_private::Address * get()
Definition: SBAddress.cpp:186
addr_t GetLoadAddress(const lldb::SBTarget &target) const
Definition: SBAddress.cpp:107
lldb_private::Address & ref()
Definition: SBAddress.cpp:173
bool IsValid() const
Definition: SBAddress.cpp:72
lldb_private::ProcessAttachInfo & ref()
void CopyToBreakpointIDList(lldb_private::BreakpointIDList &bp_id_list)
void AppendByID(lldb::break_id_t id)
bool IsValid()
Definition: SBData.cpp:59
void reset(const lldb::DebuggerSP &debugger_sp)
void SetErrorString(const char *err_str)
Definition: SBError.cpp:132
bool Fail() const
Definition: SBError.cpp:64
lldb_private::Status & ref()
Definition: SBError.cpp:167
lldb_private::Event * get() const
Definition: SBEvent.cpp:133
void SetFetchDynamicValue(lldb::DynamicValueType dynamic=lldb::eDynamicCanRunTarget)
lldb_private::EvaluateExpressionOptions & ref() const
void SetUnwindOnError(bool unwind=true)
lldb::DynamicValueType GetFetchDynamicValue() const
const lldb_private::FileSpecList * get() const
void Append(const SBFileSpec &sb_file)
uint32_t GetSize() const
void SetFileSpec(const lldb_private::FileSpec &fspec)
Definition: SBFileSpec.cpp:164
bool IsValid() const
Definition: SBFileSpec.cpp:76
const lldb_private::FileSpec & ref() const
Definition: SBFileSpec.cpp:162
void SetDisassembler(const lldb::DisassemblerSP &opaque_sp)
void SetWorkingDirectory(const char *working_dir)
void SetExecutableFile(SBFileSpec exe_file, bool add_as_first_arg)
Set the executable file that will be used to launch the process and optionally set it as the first ar...
void set_ref(const lldb_private::ProcessLaunchInfo &info)
void SetEnvironmentEntries(const char **envp, bool append)
Update this object with the given environment variables.
const lldb_private::ProcessLaunchInfo & ref() const
void SetArguments(const char **argv, bool append)
lldb::ListenerSP GetSP()
Definition: SBListener.cpp:286
lldb::ListenerSP m_opaque_sp
Definition: SBListener.h:102
bool IsValid() const
Definition: SBListener.cpp:49
std::unique_ptr< lldb_private::ModuleSpec > m_opaque_up
Definition: SBModuleSpec.h:87
void SetSP(const ModuleSP &module_sp)
Definition: SBModule.cpp:211
ModuleSP GetSP() const
Definition: SBModule.cpp:209
lldb::PlatformSP m_opaque_sp
Definition: SBPlatform.h:184
void SetSP(const lldb::ProcessSP &process_sp)
Definition: SBProcess.cpp:104
lldb::SectionSP GetSP() const
Definition: SBSection.cpp:112
bool IsValid() const
Definition: SBSection.cpp:45
lldb_private::Stream & ref()
Definition: SBStream.cpp:177
uint32_t GetSize() const
void AppendString(const char *str)
const char * GetStringAtIndex(size_t idx)
StructuredDataImplUP m_impl_up
lldb_private::SymbolContext & ref()
SBSourceManager GetSourceManager()
Definition: SBTarget.cpp:1925
bool AddModule(lldb::SBModule &module)
Definition: SBTarget.cpp:1515
bool DisableAllBreakpoints()
Definition: SBTarget.cpp:1169
uint32_t GetNumWatchpoints() const
Definition: SBTarget.cpp:1268
bool GetDescription(lldb::SBStream &description, lldb::DescriptionLevel description_level)
Definition: SBTarget.cpp:1676
lldb::SBError ClearSectionLoadAddress(lldb::SBSection section)
Clear the base load address for a module section.
Definition: SBTarget.cpp:2058
bool DeleteWatchpoint(lldb::watch_id_t watch_id)
Definition: SBTarget.cpp:1291
lldb::ByteOrder GetByteOrder()
Definition: SBTarget.cpp:1568
uint32_t GetNumBreakpoints() const
Definition: SBTarget.cpp:1061
lldb::SBInstructionList GetInstructionsWithFlavor(lldb::SBAddress base_addr, const char *flavor_string, const void *buf, size_t size)
Definition: SBTarget.cpp:1978
void SetCollectingStats(bool v)
Sets whether we should collect statistics on lldb or not.
Definition: SBTarget.cpp:214
bool BreakpointDelete(break_id_t break_id)
Definition: SBTarget.cpp:1084
void SetSP(const lldb::TargetSP &target_sp)
Definition: SBTarget.cpp:579
bool IsLoaded(const lldb::SBModule &module) const
Definition: SBTarget.cpp:2282
const char * GetTriple()
Definition: SBTarget.cpp:1577
static lldb::SBModule GetModuleAtIndexFromEvent(const uint32_t idx, const lldb::SBEvent &event)
Definition: SBTarget.cpp:137
bool GetCollectingStats()
Returns whether statistics collection are enabled.
Definition: SBTarget.cpp:223
lldb::SBBreakpoint BreakpointCreateByAddress(addr_t address)
Definition: SBTarget.cpp:928
lldb::SBValue CreateValueFromExpression(const char *name, const char *expr)
Definition: SBTarget.cpp:1422
lldb::SBSymbolContextList FindGlobalFunctions(const char *name, uint32_t max_matches, MatchType matchtype)
Find global functions by their name with pattern matching.
Definition: SBTarget.cpp:1713
lldb::SBBreakpoint BreakpointCreateByRegex(const char *symbol_name_regex, const char *module_name=nullptr)
Definition: SBTarget.cpp:882
lldb::SBTrace GetTrace()
Get a SBTrace object the can manage the processor trace information of this target.
Definition: SBTarget.cpp:2325
const lldb::SBTarget & operator=(const lldb::SBTarget &rhs)
Definition: SBTarget.cpp:106
friend class SBProcess
Definition: SBTarget.h:932
static bool EventIsTargetEvent(const lldb::SBEvent &event)
Definition: SBTarget.cpp:117
lldb::SBAddress ResolvePastLoadAddress(uint32_t stop_id, lldb::addr_t vm_addr)
Resolve a current load address into a section offset address using the process stop ID to identify a ...
Definition: SBTarget.cpp:617
bool DisableAllWatchpoints()
Definition: SBTarget.cpp:1372
lldb::addr_t GetStackRedZoneSize()
Definition: SBTarget.cpp:2265
lldb::SBBreakpoint GetBreakpointAtIndex(uint32_t idx) const
Definition: SBTarget.cpp:1072
SBError Install()
Install any binaries that need to be installed.
Definition: SBTarget.cpp:286
lldb::SBSymbolContextList FindCompileUnits(const lldb::SBFileSpec &sb_file_spec)
Find compile units related to *this target and passed source file.
Definition: SBTarget.cpp:1558
lldb::SBAddress ResolveLoadAddress(lldb::addr_t vm_addr)
Resolve a current load address into a section offset address.
Definition: SBTarget.cpp:583
lldb::SBStructuredData GetStatistics()
Returns a dump of the collected statistics.
Definition: SBTarget.cpp:199
lldb::SBModule GetModuleAtIndex(uint32_t idx)
Definition: SBTarget.cpp:1643
lldb::SBValueList FindGlobalVariables(const char *name, uint32_t max_matches)
Find global and static variables by name.
Definition: SBTarget.cpp:1845
lldb::SBType GetBasicType(lldb::BasicType type)
Definition: SBTarget.cpp:1790
lldb::SBFileSpec GetExecutable()
Definition: SBTarget.cpp:551
const char * GetABIName()
Definition: SBTarget.cpp:1592
lldb::SBError SetSectionLoadAddress(lldb::SBSection section, lldb::addr_t section_base_addr)
Set the base load address for a module section.
Definition: SBTarget.cpp:2021
friend class SBModule
Definition: SBTarget.h:930
lldb::SBProcess ConnectRemote(SBListener &listener, const char *url, const char *plugin_name, SBError &error)
Connect to a remote debug server with url.
Definition: SBTarget.cpp:519
friend class SBBreakpoint
Definition: SBTarget.h:922
lldb::SBBreakpoint BreakpointCreateByName(const char *symbol_name, const char *module_name=nullptr)
Definition: SBTarget.cpp:761
void DeleteBreakpointName(const char *name)
Definition: SBTarget.cpp:1147
SBProcess Attach(SBAttachInfo &attach_info, SBError &error)
Definition: SBTarget.cpp:429
bool EnableAllWatchpoints()
Definition: SBTarget.cpp:1358
lldb::SBBreakpoint BreakpointCreateBySBAddress(SBAddress &address)
Definition: SBTarget.cpp:942
friend class SBValue
Definition: SBTarget.h:936
bool IsValid() const
Definition: SBTarget.cpp:152
LLDB_DEPRECATED("Use SetModuleLoadAddress(lldb::SBModule, uint64_t)", "SetModuleLoadAddress(lldb::SBModule, uint64_t)") lldb lldb::SBError SetModuleLoadAddress(lldb::SBModule module, uint64_t sections_offset)
Slide all file addresses for all module sections so that module appears to loaded at these slide addr...
Definition: SBTarget.cpp:2092
lldb::SBProcess GetProcess()
Definition: SBTarget.cpp:162
SBSymbolContext ResolveSymbolContextForAddress(const SBAddress &addr, uint32_t resolve_scope)
Definition: SBTarget.cpp:637
lldb::SBProcess AttachToProcessWithID(SBListener &listener, lldb::pid_t pid, lldb::SBError &error)
Attach to process with pid.
Definition: SBTarget.cpp:463
lldb::SBPlatform GetPlatform()
Return the platform object associated with the target.
Definition: SBTarget.cpp:176
lldb::SBBreakpoint BreakpointCreateByLocation(const char *file, uint32_t line)
Definition: SBTarget.cpp:670
lldb::SBBreakpoint BreakpointCreateForException(lldb::LanguageType language, bool catch_bp, bool throw_bp)
Definition: SBTarget.cpp:1018
uint32_t GetNumModules() const
Definition: SBTarget.cpp:1526
lldb::TargetSP GetSP() const
Definition: SBTarget.cpp:577
uint32_t GetDataByteSize()
Architecture data byte width accessor.
Definition: SBTarget.cpp:1604
uint32_t GetMaximumNumberOfChildrenToDisplay() const
Gets the target.max-children-count value It should be used to limit the number of children of large d...
Definition: SBTarget.cpp:1624
bool DeleteAllWatchpoints()
Definition: SBTarget.cpp:1438
lldb::SBInstructionList GetInstructions(lldb::SBAddress base_addr, const void *buf, size_t size)
Definition: SBTarget.cpp:1969
lldb::SBProcess Launch(SBListener &listener, char const **argv, char const **envp, const char *stdin_path, const char *stdout_path, const char *stderr_path, const char *working_directory, uint32_t launch_flags, bool stop_at_entry, lldb::SBError &error)
Launch a new process.
Definition: SBTarget.cpp:298
bool RemoveModule(lldb::SBModule module)
Definition: SBTarget.cpp:1658
lldb::SBWatchpoint WatchAddress(lldb::addr_t addr, size_t size, bool read, bool write, SBError &error)
Definition: SBTarget.cpp:1323
lldb::SBSymbolContextList FindFunctions(const char *name, uint32_t name_type_mask=lldb::eFunctionNameTypeAny)
Find functions by name.
Definition: SBTarget.cpp:1691
lldb::SBValue FindFirstGlobalVariable(const char *name)
Find the first global (or static) variable by name.
Definition: SBTarget.cpp:1916
lldb::SBValue EvaluateExpression(const char *expr)
Definition: SBTarget.cpp:2203
lldb::SBBreakpoint BreakpointCreateFromScript(const char *class_name, SBStructuredData &extra_args, const SBFileSpecList &module_list, const SBFileSpecList &file_list, bool request_hardware=false)
Create a breakpoint using a scripted resolver.
Definition: SBTarget.cpp:1034
static const char * GetBroadcasterClassName()
Definition: SBTarget.cpp:146
SBEnvironment GetEnvironment()
Return the environment variables that would be used to launch a new process.
Definition: SBTarget.cpp:2314
lldb::SBTypeList FindTypes(const char *type)
Definition: SBTarget.cpp:1802
lldb::SBValue CreateValueFromAddress(const char *name, lldb::SBAddress addr, lldb::SBType type)
Definition: SBTarget.cpp:1386
static lldb::SBTarget GetTargetFromEvent(const lldb::SBEvent &event)
Definition: SBTarget.cpp:123
lldb::SBError BreakpointsCreateFromFile(SBFileSpec &source_file, SBBreakpointList &new_bps)
Read breakpoints from source_file and return the newly created breakpoints in bkpt_list.
Definition: SBTarget.cpp:1193
uint32_t GetAddressByteSize()
Definition: SBTarget.cpp:1634
bool operator==(const lldb::SBTarget &rhs) const
Definition: SBTarget.cpp:565
bool operator!=(const lldb::SBTarget &rhs) const
Definition: SBTarget.cpp:571
lldb::TargetSP m_opaque_sp
Definition: SBTarget.h:951
lldb::SBWatchpoint GetWatchpointAtIndex(uint32_t idx) const
Definition: SBTarget.cpp:1279
lldb::SBLaunchInfo GetLaunchInfo() const
Definition: SBTarget.cpp:2296
lldb::SBSymbolContextList FindSymbols(const char *name, lldb::SymbolType type=eSymbolTypeAny)
Definition: SBTarget.cpp:2189
void AppendImageSearchPath(const char *from, const char *to, lldb::SBError &error)
Definition: SBTarget.cpp:1452
lldb::SBTrace CreateTrace(SBError &error)
Create a Trace object for the current target using the using the default supported tracing technology...
Definition: SBTarget.cpp:2335
lldb::SBBreakpoint BreakpointCreateBySourceRegex(const char *source_regex, const SBFileSpec &source_file, const char *module_name=nullptr)
Definition: SBTarget.cpp:961
bool DeleteAllBreakpoints()
Definition: SBTarget.cpp:1181
lldb::SBValue CreateValueFromData(const char *name, lldb::SBData data, lldb::SBType type)
Definition: SBTarget.cpp:1404
lldb::SBBroadcaster GetBroadcaster() const
Definition: SBTarget.cpp:1667
bool FindBreakpointsByName(const char *name, SBBreakpointList &bkpt_list)
Definition: SBTarget.cpp:1110
size_t ReadMemory(const SBAddress addr, void *buf, size_t size, lldb::SBError &error)
Read target memory.
Definition: SBTarget.cpp:652
lldb::SBBreakpoint BreakpointCreateByNames(const char *symbol_name[], uint32_t num_names, uint32_t name_type_mask, const SBFileSpecList &module_list, const SBFileSpecList &comp_unit_list)
Definition: SBTarget.cpp:836
SBProcess LaunchSimple(const char **argv, const char **envp, const char *working_directory)
Launch a new process with sensible defaults.
Definition: SBTarget.cpp:262
lldb::SBModule FindModule(const lldb::SBFileSpec &file_spec)
Definition: SBTarget.cpp:1545
lldb::SBBreakpoint FindBreakpointByID(break_id_t break_id)
Definition: SBTarget.cpp:1097
lldb::SBInstructionList ReadInstructions(lldb::SBAddress base_addr, uint32_t count)
Definition: SBTarget.cpp:1932
void GetBreakpointNames(SBStringList &names)
Definition: SBTarget.cpp:1131
lldb::SBDebugger GetDebugger() const
Definition: SBTarget.cpp:189
friend class SBPlatform
Definition: SBTarget.h:931
lldb::SBError BreakpointsWriteToFile(SBFileSpec &dest_file)
Write breakpoints to dest_file.
Definition: SBTarget.cpp:1235
lldb::SBWatchpoint FindWatchpointByID(lldb::watch_id_t watch_id)
Definition: SBTarget.cpp:1306
lldb::SBAddress ResolveFileAddress(lldb::addr_t file_addr)
Resolve a current file address into a section offset address.
Definition: SBTarget.cpp:601
void SetLaunchInfo(const lldb::SBLaunchInfo &launch_info)
Definition: SBTarget.cpp:2306
lldb::SBError ClearModuleLoadAddress(lldb::SBModule module)
Clear the section base load addresses for all sections in a module.
Definition: SBTarget.cpp:2138
lldb::SBType FindFirstType(const char *type)
Definition: SBTarget.cpp:1749
uint32_t GetCodeByteSize()
Architecture code byte width accessor.
Definition: SBTarget.cpp:1614
lldb::SBProcess AttachToProcessWithName(SBListener &listener, const char *name, bool wait_for, lldb::SBError &error)
Attach to process with name.
Definition: SBTarget.cpp:492
SBProcess LoadCore(const char *core_file)
Definition: SBTarget.cpp:232
static uint32_t GetNumModulesFromEvent(const lldb::SBEvent &event)
Definition: SBTarget.cpp:129
bool EnableAllBreakpoints()
Definition: SBTarget.cpp:1157
uint32_t GetSize()
Definition: SBType.cpp:639
void Append(lldb::SBType type)
Definition: SBType.cpp:624
lldb::TypeImplSP GetSP()
Definition: SBType.cpp:76
bool IsValid() const
Definition: SBType.cpp:107
bool IsValid() const
Definition: SBValueList.cpp:93
void Append(const lldb::SBValue &val_obj)
lldb::SBValue GetValueAtIndex(uint32_t idx) const
uint32_t GetSize() const
void SetSP(const lldb::ValueObjectSP &sp)
Definition: SBValue.cpp:1060
const char * GetValue()
Definition: SBValue.cpp:352
const char * GetSummary()
Definition: SBValue.cpp:414
void SetSP(const lldb::WatchpointSP &sp)
static lldb::ABISP FindPlugin(lldb::ProcessSP process_sp, const ArchSpec &arch)
Definition: ABI.cpp:27
A section + offset based address class.
Definition: Address.h:59
void SetRawAddress(lldb::addr_t addr)
Definition: Address.h:444
An architecture specification class.
Definition: ArchSpec.h:31
bool IsValid() const
Tests if this ArchSpec is valid.
Definition: ArchSpec.h:348
void AppendArguments(const Args &rhs)
Definition: Args.cpp:297
const BreakpointID & GetBreakpointIDAtIndex(size_t index) const
lldb::break_id_t GetBreakpointID() const
Definition: BreakpointID.h:29
Generic representation of a type in a programming language.
Definition: CompilerType.h:36
A uniqued constant string class.
Definition: ConstString.h:39
const char * AsCString(const char *value_if_empty=nullptr) const
Get the string value as a C string.
Definition: ConstString.h:195
const char * GetCString() const
Get the string value as a C string.
Definition: ConstString.h:218
A subclass of DataBuffer that stores a data buffer on the heap.
lldb::offset_t GetByteSize() const override
static void SetCollectingStats(bool enable)
Definition: Statistics.h:161
static bool GetCollectingStats()
Definition: Statistics.h:162
static llvm::json::Value ReportStatistics(Debugger &debugger, Target *target)
Get metrics associated with one or all targets in a debugger in JSON format.
Definition: Statistics.cpp:186
static lldb::DisassemblerSP DisassembleBytes(const ArchSpec &arch, const char *plugin_name, const char *flavor, const Address &start, const void *bytes, size_t length, uint32_t max_num_instructions, bool data_from_file)
Execution context objects refer to objects in the execution of the program that is being debugged.
"lldb/Target/ExecutionContextScope.h" Inherit from this if your object can reconstruct its execution ...
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
StackFrame * GetFramePtr() const
Returns a pointer to the frame object.
Target * GetTargetPtr() const
Returns a pointer to the target object.
Process * GetProcessPtr() const
Returns a pointer to the process object.
A file collection class.
Definition: FileSpecList.h:24
void Append(const FileSpec &file)
Append a FileSpec object to the list.
A file utility class.
Definition: FileSpec.h:56
void SetFile(llvm::StringRef path, Style style)
Change the file specified with a new path.
Definition: FileSpec.cpp:173
void Resolve(llvm::SmallVectorImpl< char > &path)
Resolve path to make it canonical.
static FileSystem & Instance()
A collection class for Module objects.
Definition: ModuleList.h:82
void FindTypes(Module *search_first, ConstString name, bool name_is_fully_qualified, size_t max_matches, llvm::DenseSet< SymbolFile * > &searched_symbol_files, TypeList &types) const
Find types by name.
Definition: ModuleList.cpp:561
void Append(const lldb::ModuleSP &module_sp, bool notify=true)
Append a module to the module list.
lldb::ModuleSP GetModuleAtIndex(size_t idx) const
Get the module shared pointer for the module at index idx.
Definition: ModuleList.cpp:403
size_t GetSize() const
Gets the size of the module list.
Definition: ModuleList.cpp:627
FileSpec & GetFileSpec()
Definition: ModuleSpec.h:53
ArchSpec & GetArchitecture()
Definition: ModuleSpec.h:89
FileSpec & GetSymbolFileSpec()
Definition: ModuleSpec.h:77
A class that describes an executable image and its associated object and symbol files.
Definition: Module.h:88
const FileSpec & GetPlatformFileSpec() const
Get accessor for the module platform file specification.
Definition: Module.h:512
const FileSpec & GetFileSpec() const
Get const accessor for the module file specification.
Definition: Module.h:498
A plug-in interface definition class for object file parsers.
Definition: ObjectFile.h:43
virtual SectionList * GetSectionList(bool update_module_section_list=true)
Gets the section list for the currently selected architecture (and object for archives).
Definition: ObjectFile.cpp:588
static ArchSpec GetAugmentedArchSpec(Platform *platform, llvm::StringRef triple)
Augments the triple either with information from platform or the host system (if platform is null).
Definition: Platform.cpp:263
void SetExecutableFile(const FileSpec &exe_file, bool add_exe_file_as_first_arg)
Definition: ProcessInfo.cpp:65
bool ProcessIDIsValid() const
Definition: ProcessInfo.h:71
lldb::pid_t GetProcessID() const
Definition: ProcessInfo.h:67
void SetProcessID(lldb::pid_t pid)
Definition: ProcessInfo.h:69
FileSpec & GetExecutableFile()
Definition: ProcessInfo.h:42
void SetListener(const lldb::ListenerSP &listener_sp)
Definition: ProcessInfo.h:103
lldb::ListenerSP GetListener() const
Definition: ProcessInfo.h:101
bool UserIDIsValid() const
Definition: ProcessInfo.h:53
Environment & GetEnvironment()
Definition: ProcessInfo.h:87
bool IsScriptedProcess() const
void SetUserID(uint32_t uid)
Definition: ProcessInfo.h:57
ArchSpec & GetArchitecture()
Definition: ProcessInfo.h:61
uint32_t GetEffectiveUserID() const
Definition: ProcessInfo.h:155
A plug-in interface definition class for debugging a process.
Definition: Process.h:335
ProcessRunLock & GetRunLock()
Definition: Process.cpp:5644
size_t GetSize() const
Definition: Section.h:75
lldb::SectionSP GetSectionAtIndex(size_t idx) const
Definition: Section.cpp:538
This base class provides an interface to stack frames.
Definition: StackFrame.h:41
An error handling class.
Definition: Status.h:44
A stream class that can stream formatted output to a file.
Definition: Stream.h:28
size_t PutCString(llvm::StringRef cstr)
Output a C string to the stream.
Definition: Stream.cpp:63
std::shared_ptr< Object > ObjectSP
static ObjectSP ParseJSON(llvm::StringRef json_text)
Defines a symbol context baton that can be handed other debug core functions.
Definition: SymbolContext.h:33
static ModuleList GetModuleListFromEvent(const Event *event_ptr)
Definition: Target.cpp:4834
static const TargetEventData * GetEventDataFromEvent(const Event *event_ptr)
Definition: Target.cpp:4815
static lldb::TargetSP GetTargetFromEvent(const Event *event_ptr)
Definition: Target.cpp:4825
static ConstString & GetStaticBroadcasterClass()
Definition: Target.cpp:88
const lldb::ProcessSP & GetProcessSP() const
Definition: Target.cpp:219
std::recursive_mutex & GetAPIMutex()
Definition: Target.cpp:4842
Status Attach(ProcessAttachInfo &attach_info, Stream *stream)
Definition: Target.cpp:3306
lldb::ExpressionResults EvaluateExpression(llvm::StringRef expression, ExecutionContextScope *exe_scope, lldb::ValueObjectSP &result_valobj_sp, const EvaluateExpressionOptions &options=EvaluateExpressionOptions(), std::string *fixed_expression=nullptr, ValueObject *ctx_obj=nullptr)
Definition: Target.cpp:2553
uint32_t GetSize() const
Definition: TypeList.cpp:60
lldb::TypeSP GetTypeAtIndex(uint32_t idx)
Definition: TypeList.cpp:66
bool SetFromStringRef(llvm::StringRef str)
Definition: UUID.cpp:97
static lldb::ValueObjectSP Create(ExecutionContextScope *exe_scope, lldb::ByteOrder byte_order, uint32_t addr_byte_size, lldb::addr_t address=LLDB_INVALID_ADDRESS)
static lldb::ValueObjectSP Create(ExecutionContextScope *exe_scope, const lldb::VariableSP &var_sp)
static lldb::ValueObjectSP CreateValueObjectFromExpression(llvm::StringRef name, llvm::StringRef expression, const ExecutionContext &exe_ctx)
static lldb::ValueObjectSP CreateValueObjectFromData(llvm::StringRef name, const DataExtractor &data, const ExecutionContext &exe_ctx, CompilerType type)
static lldb::ValueObjectSP CreateValueObjectFromAddress(llvm::StringRef name, uint64_t address, const ExecutionContext &exe_ctx, CompilerType type)
#define LLDB_WATCH_TYPE_WRITE
Definition: lldb-defines.h:46
#define LLDB_INVALID_BREAK_ID
Definition: lldb-defines.h:37
#define LLDB_INVALID_WATCH_ID
Definition: lldb-defines.h:43
#define LLDB_WATCH_TYPE_READ
Definition: lldb-defines.h:45
#define LLDB_INVALID_ADDRESS
Definition: lldb-defines.h:74
#define UINT32_MAX
Definition: lldb-defines.h:19
A class that represents a running process on the host machine.
Definition: SBAttachInfo.h:14
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
Definition: Log.h:309
Definition: SBAddress.h:15
MatchType
String matching algorithm used by SBTarget.
@ eMatchTypeStartsWith
DescriptionLevel
Description levels for "void GetDescription(Stream *, DescriptionLevel)" calls.
BasicType
Basic types enumeration for the public API SBType::GetBasicType().
StateType
Process and Thread States.
@ eStateConnected
Process is connected to remote debug services, but not launched or attached to anything yet.
@ eStateAttaching
Process is currently trying to attach.
LanguageType
Programming language type.
@ eLanguageTypeUnknown
Unknown or invalid language value.
int32_t break_id_t
Definition: lldb-types.h:84
SymbolType
Symbol types.
uint64_t pid_t
Definition: lldb-types.h:81
ByteOrder
Byte ordering definitions.
@ eByteOrderInvalid
int32_t watch_id_t
Definition: lldb-types.h:85
uint64_t addr_t
Definition: lldb-types.h:79
Options used by Module::FindFunctions.
Definition: Module.h:65
bool include_inlines
Include inlined functions.
Definition: Module.h:69
bool include_symbols
Include the symbol table.
Definition: Module.h:67
#define PATH_MAX