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