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