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