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 uint64_t type_mask,
688 SBStructuredData &args_data,
689 SBError &error) {
690 if (!class_name || class_name[0] == '\0') {
691 error.SetErrorString("empty class name");
693 }
694
695 if (TargetSP target_sp = GetSP()) {
697 args_data.CopyImpl(impl);
698 StructuredData::ObjectSP object_sp = impl.GetObjectSP();
700 new StructuredData::Dictionary(object_sp));
701 if (!args_dict->IsValid()) {
702 error.SetErrorString("args data is not a dictionary");
704 }
705
706 llvm::Expected<lldb::user_id_t> id_or_err =
707 target_sp->AddBreakpointResolverOverride(
708 class_name, type_mask, args_dict,
709 description ? description : "<No Description>");
710 if (id_or_err)
711 return *id_or_err;
712 error.SetErrorString(llvm::toString(id_or_err.takeError()).c_str());
714
715 } else {
716 error.SetErrorString("invalid SBTarget.");
718 }
719}
720
722 if (TargetSP target_sp = GetSP()) {
723 return target_sp->RemoveBreakpointResolverOverride(id);
724 }
725 return false;
726}
727
729 uint32_t line) {
730 LLDB_INSTRUMENT_VA(this, file, line);
731
732 return SBBreakpoint(
733 BreakpointCreateByLocation(SBFileSpec(file, false), line));
734}
735
738 uint32_t line) {
739 LLDB_INSTRUMENT_VA(this, sb_file_spec, line);
740
741 return BreakpointCreateByLocation(sb_file_spec, line, 0);
742}
743
746 uint32_t line, lldb::addr_t offset) {
747 LLDB_INSTRUMENT_VA(this, sb_file_spec, line, offset);
748
749 SBFileSpecList empty_list;
750 return BreakpointCreateByLocation(sb_file_spec, line, offset, empty_list);
751}
752
755 uint32_t line, lldb::addr_t offset,
756 SBFileSpecList &sb_module_list) {
757 LLDB_INSTRUMENT_VA(this, sb_file_spec, line, offset, sb_module_list);
758
759 return BreakpointCreateByLocation(sb_file_spec, line, 0, offset,
760 sb_module_list);
761}
762
764 const SBFileSpec &sb_file_spec, uint32_t line, uint32_t column,
765 lldb::addr_t offset, SBFileSpecList &sb_module_list) {
766 LLDB_INSTRUMENT_VA(this, sb_file_spec, line, column, offset, sb_module_list);
767
768 SBBreakpoint sb_bp;
769 if (TargetSP target_sp = GetSP(); target_sp && line != 0) {
770 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
771
772 const LazyBool check_inlines = eLazyBoolCalculate;
773 const LazyBool skip_prologue = eLazyBoolCalculate;
774 const bool internal = false;
775 const bool hardware = false;
776 const LazyBool move_to_nearest_code = eLazyBoolCalculate;
777 const FileSpecList *module_list = nullptr;
778 if (sb_module_list.GetSize() > 0) {
779 module_list = sb_module_list.get();
780 }
781 sb_bp = target_sp->CreateBreakpoint(
782 module_list, *sb_file_spec, line, column, offset, check_inlines,
783 skip_prologue, internal, hardware, move_to_nearest_code);
784 }
785
786 return sb_bp;
787}
788
790 const SBFileSpec &sb_file_spec, uint32_t line, uint32_t column,
791 lldb::addr_t offset, SBFileSpecList &sb_module_list,
792 bool move_to_nearest_code) {
793 LLDB_INSTRUMENT_VA(this, sb_file_spec, line, column, offset, sb_module_list,
794 move_to_nearest_code);
795
796 SBBreakpoint sb_bp;
797 if (TargetSP target_sp = GetSP(); target_sp && line != 0) {
798 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
799
800 const LazyBool check_inlines = eLazyBoolCalculate;
801 const LazyBool skip_prologue = eLazyBoolCalculate;
802 const bool internal = false;
803 const bool hardware = false;
804 const FileSpecList *module_list = nullptr;
805 if (sb_module_list.GetSize() > 0) {
806 module_list = sb_module_list.get();
807 }
808 sb_bp = target_sp->CreateBreakpoint(
809 module_list, *sb_file_spec, line, column, offset, check_inlines,
810 skip_prologue, internal, hardware,
811 move_to_nearest_code ? eLazyBoolYes : eLazyBoolNo);
812 }
813
814 return sb_bp;
815}
816
818 const char *module_name) {
819 LLDB_INSTRUMENT_VA(this, symbol_name, module_name);
820
821 SBBreakpoint sb_bp;
822 if (TargetSP target_sp = GetSP()) {
823 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
824
825 const bool internal = false;
826 const bool hardware = false;
827 const LazyBool skip_prologue = eLazyBoolCalculate;
828 const lldb::addr_t offset = 0;
829 const bool offset_is_insn_count = false;
830 if (module_name && module_name[0]) {
831 FileSpecList module_spec_list;
832 module_spec_list.Append(FileSpec(module_name));
833 sb_bp = target_sp->CreateBreakpoint(
834 &module_spec_list, nullptr, symbol_name, eFunctionNameTypeAuto,
835 eLanguageTypeUnknown, offset, offset_is_insn_count, skip_prologue,
836 internal, hardware);
837 } else {
838 sb_bp = target_sp->CreateBreakpoint(
839 nullptr, nullptr, symbol_name, eFunctionNameTypeAuto,
840 eLanguageTypeUnknown, offset, offset_is_insn_count, skip_prologue,
841 internal, hardware);
842 }
843 }
844
845 return sb_bp;
846}
847
849SBTarget::BreakpointCreateByName(const char *symbol_name,
850 const SBFileSpecList &module_list,
851 const SBFileSpecList &comp_unit_list) {
852 LLDB_INSTRUMENT_VA(this, symbol_name, module_list, comp_unit_list);
853
854 lldb::FunctionNameType name_type_mask = eFunctionNameTypeAuto;
855 return BreakpointCreateByName(symbol_name, name_type_mask,
856 eLanguageTypeUnknown, module_list,
857 comp_unit_list);
858}
859
861 const char *symbol_name, uint32_t name_type_mask,
862 const SBFileSpecList &module_list, const SBFileSpecList &comp_unit_list) {
863 LLDB_INSTRUMENT_VA(this, symbol_name, name_type_mask, module_list,
864 comp_unit_list);
865
866 return BreakpointCreateByName(symbol_name, name_type_mask,
867 eLanguageTypeUnknown, module_list,
868 comp_unit_list);
869}
870
872 const char *symbol_name, uint32_t name_type_mask,
873 LanguageType symbol_language, const SBFileSpecList &module_list,
874 const SBFileSpecList &comp_unit_list) {
875 LLDB_INSTRUMENT_VA(this, symbol_name, name_type_mask, symbol_language,
876 module_list, comp_unit_list);
877 return BreakpointCreateByName(symbol_name, name_type_mask, symbol_language, 0,
878 false, module_list, comp_unit_list);
879}
880
882 const char *symbol_name, uint32_t name_type_mask,
883 LanguageType symbol_language, lldb::addr_t offset,
884 bool offset_is_insn_count, const SBFileSpecList &module_list,
885 const SBFileSpecList &comp_unit_list) {
886 LLDB_INSTRUMENT_VA(this, symbol_name, name_type_mask, symbol_language, offset,
887 offset_is_insn_count, module_list, comp_unit_list);
888
889 SBBreakpoint sb_bp;
890 if (TargetSP target_sp = GetSP();
891 target_sp && symbol_name && symbol_name[0]) {
892 const bool internal = false;
893 const bool hardware = false;
894 const LazyBool skip_prologue = eLazyBoolCalculate;
895 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
896 FunctionNameType mask = static_cast<FunctionNameType>(name_type_mask);
897 sb_bp = target_sp->CreateBreakpoint(module_list.get(), comp_unit_list.get(),
898 symbol_name, mask, symbol_language,
899 offset, offset_is_insn_count,
900 skip_prologue, internal, hardware);
901 }
902
903 return sb_bp;
904}
905
907 const char *symbol_names[], uint32_t num_names, uint32_t name_type_mask,
908 const SBFileSpecList &module_list, const SBFileSpecList &comp_unit_list) {
909 LLDB_INSTRUMENT_VA(this, symbol_names, num_names, name_type_mask, module_list,
910 comp_unit_list);
911
912 return BreakpointCreateByNames(symbol_names, num_names, name_type_mask,
913 eLanguageTypeUnknown, module_list,
914 comp_unit_list);
915}
916
918 const char *symbol_names[], uint32_t num_names, uint32_t name_type_mask,
919 LanguageType symbol_language, const SBFileSpecList &module_list,
920 const SBFileSpecList &comp_unit_list) {
921 LLDB_INSTRUMENT_VA(this, symbol_names, num_names, name_type_mask,
922 symbol_language, module_list, comp_unit_list);
923
924 return BreakpointCreateByNames(symbol_names, num_names, name_type_mask,
925 eLanguageTypeUnknown, 0, module_list,
926 comp_unit_list);
927}
928
930 const char *symbol_names[], uint32_t num_names, uint32_t name_type_mask,
931 LanguageType symbol_language, lldb::addr_t offset,
932 const SBFileSpecList &module_list, const SBFileSpecList &comp_unit_list) {
933 LLDB_INSTRUMENT_VA(this, symbol_names, num_names, name_type_mask,
934 symbol_language, offset, module_list, comp_unit_list);
935
936 SBBreakpoint sb_bp;
937 if (TargetSP target_sp = GetSP(); target_sp && num_names > 0) {
938 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
939 const bool internal = false;
940 const bool hardware = false;
941 FunctionNameType mask = static_cast<FunctionNameType>(name_type_mask);
942 const LazyBool skip_prologue = eLazyBoolCalculate;
943 sb_bp = target_sp->CreateBreakpoint(
944 module_list.get(), comp_unit_list.get(), symbol_names, num_names, mask,
945 symbol_language, offset, skip_prologue, internal, hardware);
946 }
947
948 return sb_bp;
949}
950
952 const char *module_name) {
953 LLDB_INSTRUMENT_VA(this, symbol_name_regex, module_name);
954
955 SBFileSpecList module_spec_list;
956 SBFileSpecList comp_unit_list;
957 if (module_name && module_name[0]) {
958 module_spec_list.Append(FileSpec(module_name));
959 }
960 return BreakpointCreateByRegex(symbol_name_regex, eLanguageTypeUnknown,
961 module_spec_list, comp_unit_list);
962}
963
965SBTarget::BreakpointCreateByRegex(const char *symbol_name_regex,
966 const SBFileSpecList &module_list,
967 const SBFileSpecList &comp_unit_list) {
968 LLDB_INSTRUMENT_VA(this, symbol_name_regex, module_list, comp_unit_list);
969
970 return BreakpointCreateByRegex(symbol_name_regex, eLanguageTypeUnknown,
971 module_list, comp_unit_list);
972}
973
975 const char *symbol_name_regex, LanguageType symbol_language,
976 const SBFileSpecList &module_list, const SBFileSpecList &comp_unit_list) {
977 LLDB_INSTRUMENT_VA(this, symbol_name_regex, symbol_language, module_list,
978 comp_unit_list);
979
980 SBBreakpoint sb_bp;
981 if (TargetSP target_sp = GetSP();
982 target_sp && symbol_name_regex && symbol_name_regex[0]) {
983 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
984 RegularExpression regexp((llvm::StringRef(symbol_name_regex)));
985 const bool internal = false;
986 const bool hardware = false;
987 const LazyBool skip_prologue = eLazyBoolCalculate;
988
989 sb_bp = target_sp->CreateFuncRegexBreakpoint(
990 module_list.get(), comp_unit_list.get(), std::move(regexp),
991 symbol_language, skip_prologue, internal, hardware);
992 }
993
994 return sb_bp;
995}
996
998 LLDB_INSTRUMENT_VA(this, address);
999
1000 SBBreakpoint sb_bp;
1001 if (TargetSP target_sp = GetSP()) {
1002 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1003 const bool hardware = false;
1004 sb_bp = target_sp->CreateBreakpoint(address, false, hardware);
1005 }
1006
1007 return sb_bp;
1008}
1009
1011 LLDB_INSTRUMENT_VA(this, sb_address);
1012
1013 SBBreakpoint sb_bp;
1014 if (!sb_address.IsValid()) {
1015 return sb_bp;
1016 }
1017
1018 if (TargetSP target_sp = GetSP()) {
1019 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1020 const bool hardware = false;
1021 sb_bp = target_sp->CreateBreakpoint(sb_address.ref(), false, hardware);
1022 }
1023
1024 return sb_bp;
1025}
1026
1029 const lldb::SBFileSpec &source_file,
1030 const char *module_name) {
1031 LLDB_INSTRUMENT_VA(this, source_regex, source_file, module_name);
1032
1033 SBFileSpecList module_spec_list;
1034
1035 if (module_name && module_name[0]) {
1036 module_spec_list.Append(FileSpec(module_name));
1037 }
1038
1039 SBFileSpecList source_file_list;
1040 if (source_file.IsValid()) {
1041 source_file_list.Append(source_file);
1042 }
1043
1044 return BreakpointCreateBySourceRegex(source_regex, module_spec_list,
1045 source_file_list);
1046}
1047
1049 const char *source_regex, const SBFileSpecList &module_list,
1050 const lldb::SBFileSpecList &source_file_list) {
1051 LLDB_INSTRUMENT_VA(this, source_regex, module_list, source_file_list);
1052
1053 return BreakpointCreateBySourceRegex(source_regex, module_list,
1054 source_file_list, SBStringList());
1055}
1056
1058 const char *source_regex, const SBFileSpecList &module_list,
1059 const lldb::SBFileSpecList &source_file_list,
1060 const SBStringList &func_names) {
1061 LLDB_INSTRUMENT_VA(this, source_regex, module_list, source_file_list,
1062 func_names);
1063
1064 SBBreakpoint sb_bp;
1065 if (TargetSP target_sp = GetSP();
1066 target_sp && source_regex && source_regex[0]) {
1067 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1068 const bool hardware = false;
1069 const LazyBool move_to_nearest_code = eLazyBoolCalculate;
1070 RegularExpression regexp((llvm::StringRef(source_regex)));
1071 std::unordered_set<std::string> func_names_set;
1072 for (size_t i = 0; i < func_names.GetSize(); i++) {
1073 func_names_set.insert(func_names.GetStringAtIndex(i));
1074 }
1075
1076 sb_bp = target_sp->CreateSourceRegexBreakpoint(
1077 module_list.get(), source_file_list.get(), func_names_set,
1078 std::move(regexp), false, hardware, move_to_nearest_code);
1079 }
1080
1081 return sb_bp;
1082}
1083
1086 bool catch_bp, bool throw_bp) {
1087 LLDB_INSTRUMENT_VA(this, language, catch_bp, throw_bp);
1088
1089 SBBreakpoint sb_bp;
1090 if (TargetSP target_sp = GetSP()) {
1091 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1092 const bool hardware = false;
1093 sb_bp = target_sp->CreateExceptionBreakpoint(language, catch_bp, throw_bp,
1094 hardware);
1095 }
1096
1097 return sb_bp;
1098}
1099
1101 const char *class_name, SBStructuredData &extra_args,
1102 const SBFileSpecList &module_list, const SBFileSpecList &file_list,
1103 bool request_hardware) {
1104 LLDB_INSTRUMENT_VA(this, class_name, extra_args, module_list, file_list,
1105 request_hardware);
1106
1107 SBBreakpoint sb_bp;
1108 if (TargetSP target_sp = GetSP()) {
1109 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1110 Status error;
1111
1112 StructuredData::ObjectSP obj_sp = extra_args.m_impl_up->GetObjectSP();
1113 sb_bp =
1114 target_sp->CreateScriptedBreakpoint(class_name,
1115 module_list.get(),
1116 file_list.get(),
1117 false, /* internal */
1118 request_hardware,
1119 obj_sp,
1120 &error);
1121 }
1122
1123 return sb_bp;
1124}
1125
1127 LLDB_INSTRUMENT_VA(this);
1128
1129 if (TargetSP target_sp = GetSP()) {
1130 // The breakpoint list is thread safe, no need to lock
1131 return target_sp->GetBreakpointList().GetSize();
1132 }
1133 return 0;
1134}
1135
1137 LLDB_INSTRUMENT_VA(this, idx);
1138
1139 SBBreakpoint sb_breakpoint;
1140 if (TargetSP target_sp = GetSP()) {
1141 // The breakpoint list is thread safe, no need to lock
1142 sb_breakpoint = target_sp->GetBreakpointList().GetBreakpointAtIndex(idx);
1143 }
1144 return sb_breakpoint;
1145}
1146
1148 LLDB_INSTRUMENT_VA(this, bp_id);
1149
1150 bool result = false;
1151 if (TargetSP target_sp = GetSP()) {
1152 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1153 result = target_sp->RemoveBreakpointByID(bp_id);
1154 }
1155
1156 return result;
1157}
1158
1160 LLDB_INSTRUMENT_VA(this, bp_id);
1161
1162 SBBreakpoint sb_breakpoint;
1163 if (TargetSP target_sp = GetSP();
1164 target_sp && bp_id != LLDB_INVALID_BREAK_ID) {
1165 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1166 sb_breakpoint = target_sp->GetBreakpointByID(bp_id);
1167 }
1168
1169 return sb_breakpoint;
1170}
1171
1173 SBBreakpointList &bkpts) {
1174 LLDB_INSTRUMENT_VA(this, name, bkpts);
1175
1176 if (TargetSP target_sp = GetSP()) {
1177 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1178 llvm::Expected<std::vector<BreakpointSP>> expected_vector =
1179 target_sp->GetBreakpointList().FindBreakpointsByName(name);
1180 if (!expected_vector) {
1181 LLDB_LOG_ERROR(GetLog(LLDBLog::Breakpoints), expected_vector.takeError(),
1182 "invalid breakpoint name: {0}");
1183 return false;
1184 }
1185 for (BreakpointSP bkpt_sp : *expected_vector) {
1186 bkpts.AppendByID(bkpt_sp->GetID());
1187 }
1188 }
1189 return true;
1190}
1191
1193 LLDB_INSTRUMENT_VA(this, names);
1194
1195 names.Clear();
1196
1197 if (TargetSP target_sp = GetSP()) {
1198 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1199
1200 std::vector<std::string> name_vec;
1201 target_sp->GetBreakpointNames(name_vec);
1202 for (const auto &name : name_vec)
1203 names.AppendString(name.c_str());
1204 }
1205}
1206
1207void SBTarget::DeleteBreakpointName(const char *name) {
1208 LLDB_INSTRUMENT_VA(this, name);
1209
1210 if (TargetSP target_sp = GetSP()) {
1211 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1212 target_sp->DeleteBreakpointName(llvm::StringRef(name));
1213 }
1214}
1215
1217 LLDB_INSTRUMENT_VA(this);
1218
1219 if (TargetSP target_sp = GetSP()) {
1220 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1221 target_sp->EnableAllowedBreakpoints();
1222 return true;
1223 }
1224 return false;
1225}
1226
1228 LLDB_INSTRUMENT_VA(this);
1229
1230 if (TargetSP target_sp = GetSP()) {
1231 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1232 target_sp->DisableAllowedBreakpoints();
1233 return true;
1234 }
1235 return false;
1236}
1237
1239 LLDB_INSTRUMENT_VA(this);
1240
1241 if (TargetSP target_sp = GetSP()) {
1242 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1243 target_sp->RemoveAllowedBreakpoints();
1244 return true;
1245 }
1246 return false;
1247}
1248
1250 SBBreakpointList &new_bps) {
1251 LLDB_INSTRUMENT_VA(this, source_file, new_bps);
1252
1253 SBStringList empty_name_list;
1254 return BreakpointsCreateFromFile(source_file, empty_name_list, new_bps);
1255}
1256
1258 SBStringList &matching_names,
1259 SBBreakpointList &new_bps) {
1260 LLDB_INSTRUMENT_VA(this, source_file, matching_names, new_bps);
1261
1262 SBError sberr;
1263 if (TargetSP target_sp = GetSP()) {
1264 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1265
1266 BreakpointIDList bp_ids;
1267
1268 std::vector<std::string> name_vector;
1269 size_t num_names = matching_names.GetSize();
1270 for (size_t i = 0; i < num_names; i++)
1271 name_vector.push_back(matching_names.GetStringAtIndex(i));
1272
1273 sberr.ref() = target_sp->CreateBreakpointsFromFile(source_file.ref(),
1274 name_vector, bp_ids);
1275 if (sberr.Fail())
1276 return sberr;
1277
1278 size_t num_bkpts = bp_ids.GetSize();
1279 for (size_t i = 0; i < num_bkpts; i++) {
1280 BreakpointID bp_id = bp_ids.GetBreakpointIDAtIndex(i);
1281 new_bps.AppendByID(bp_id.GetBreakpointID());
1282 }
1283 } else {
1284 sberr.SetErrorString(
1285 "BreakpointCreateFromFile called with invalid target.");
1286 }
1287 return sberr;
1288}
1289
1291 LLDB_INSTRUMENT_VA(this, dest_file);
1292
1293 SBError sberr;
1294 if (TargetSP target_sp = GetSP()) {
1295 SBBreakpointList bkpt_list(*this);
1296 return BreakpointsWriteToFile(dest_file, bkpt_list);
1297 }
1298 sberr.SetErrorString("BreakpointWriteToFile called with invalid target.");
1299 return sberr;
1300}
1301
1303 SBBreakpointList &bkpt_list,
1304 bool append) {
1305 LLDB_INSTRUMENT_VA(this, dest_file, bkpt_list, append);
1306
1307 SBError sberr;
1308 if (TargetSP target_sp = GetSP()) {
1309 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1310 BreakpointIDList bp_id_list;
1311 bkpt_list.CopyToBreakpointIDList(bp_id_list);
1312 sberr.ref() = target_sp->SerializeBreakpointsToFile(dest_file.ref(),
1313 bp_id_list, append);
1314 } else {
1315 sberr.SetErrorString("BreakpointWriteToFile called with invalid target.");
1316 }
1317 return sberr;
1318}
1319
1321 LLDB_INSTRUMENT_VA(this);
1322
1323 if (TargetSP target_sp = GetSP()) {
1324 // The watchpoint list is thread safe, no need to lock
1325 return target_sp->GetWatchpointList().GetSize();
1326 }
1327 return 0;
1328}
1329
1331 LLDB_INSTRUMENT_VA(this, idx);
1332
1333 SBWatchpoint sb_watchpoint;
1334 if (TargetSP target_sp = GetSP()) {
1335 // The watchpoint list is thread safe, no need to lock
1336 sb_watchpoint.SetSP(target_sp->GetWatchpointList().GetByIndex(idx));
1337 }
1338 return sb_watchpoint;
1339}
1340
1342 LLDB_INSTRUMENT_VA(this, wp_id);
1343
1344 bool result = false;
1345 if (TargetSP target_sp = GetSP()) {
1346 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1347 std::unique_lock<std::recursive_mutex> lock;
1348 target_sp->GetWatchpointList().GetListMutex(lock);
1349 result = target_sp->RemoveWatchpointByID(wp_id);
1350 }
1351
1352 return result;
1353}
1354
1356 LLDB_INSTRUMENT_VA(this, wp_id);
1357
1358 SBWatchpoint sb_watchpoint;
1359 lldb::WatchpointSP watchpoint_sp;
1360 if (TargetSP target_sp = GetSP();
1361 target_sp && wp_id != LLDB_INVALID_WATCH_ID) {
1362 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1363 std::unique_lock<std::recursive_mutex> lock;
1364 target_sp->GetWatchpointList().GetListMutex(lock);
1365 watchpoint_sp = target_sp->GetWatchpointList().FindByID(wp_id);
1366 sb_watchpoint.SetSP(watchpoint_sp);
1367 }
1368
1369 return sb_watchpoint;
1370}
1371
1373 bool read, bool modify,
1374 SBError &error) {
1375 LLDB_INSTRUMENT_VA(this, addr, size, read, write, error);
1376
1377 SBWatchpointOptions options;
1378 options.SetWatchpointTypeRead(read);
1379 if (modify)
1381 return WatchpointCreateByAddress(addr, size, options, error);
1382}
1383
1386 SBWatchpointOptions options,
1387 SBError &error) {
1388 LLDB_INSTRUMENT_VA(this, addr, size, options, error);
1389
1390 SBWatchpoint sb_watchpoint;
1391 lldb::WatchpointSP watchpoint_sp;
1392 uint32_t watch_type = 0;
1393 if (options.GetWatchpointTypeRead())
1394 watch_type |= LLDB_WATCH_TYPE_READ;
1396 watch_type |= LLDB_WATCH_TYPE_WRITE;
1398 watch_type |= LLDB_WATCH_TYPE_MODIFY;
1399 if (watch_type == 0) {
1400 error.SetErrorString("Can't create a watchpoint that is neither read nor "
1401 "write nor modify.");
1402 return sb_watchpoint;
1403 }
1404
1405 if (TargetSP target_sp = GetSP();
1406 target_sp && addr != LLDB_INVALID_ADDRESS && size > 0) {
1407 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1408 // Target::CreateWatchpoint() is thread safe.
1409 Status cw_error;
1410 // This API doesn't take in a type, so we can't figure out what it is.
1411 CompilerType *type = nullptr;
1412 watchpoint_sp =
1413 target_sp->CreateWatchpoint(addr, size, type, watch_type, cw_error);
1414 error.SetError(std::move(cw_error));
1415 sb_watchpoint.SetSP(watchpoint_sp);
1416 }
1417
1418 return sb_watchpoint;
1419}
1420
1422 LLDB_INSTRUMENT_VA(this);
1423
1424 if (TargetSP target_sp = GetSP()) {
1425 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1426 std::unique_lock<std::recursive_mutex> lock;
1427 target_sp->GetWatchpointList().GetListMutex(lock);
1428 target_sp->EnableAllWatchpoints();
1429 return true;
1430 }
1431 return false;
1432}
1433
1435 LLDB_INSTRUMENT_VA(this);
1436
1437 if (TargetSP target_sp = GetSP()) {
1438 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1439 std::unique_lock<std::recursive_mutex> lock;
1440 target_sp->GetWatchpointList().GetListMutex(lock);
1441 target_sp->DisableAllWatchpoints();
1442 return true;
1443 }
1444 return false;
1445}
1446
1448 SBType type) {
1449 LLDB_INSTRUMENT_VA(this, name, addr, type);
1450
1451 SBValue sb_value;
1452 lldb::ValueObjectSP new_value_sp;
1453 if (IsValid() && name && *name && addr.IsValid() && type.IsValid()) {
1454 lldb::addr_t load_addr(addr.GetLoadAddress(*this));
1455 ExecutionContext exe_ctx(
1457 CompilerType ast_type(type.GetSP()->GetCompilerType(true));
1458 new_value_sp = ValueObject::CreateValueObjectFromAddress(name, load_addr,
1459 exe_ctx, ast_type);
1460 }
1461 sb_value.SetSP(new_value_sp);
1462 return sb_value;
1463}
1464
1466 lldb::SBType type) {
1467 LLDB_INSTRUMENT_VA(this, name, data, type);
1468
1469 SBValue sb_value;
1470 lldb::ValueObjectSP new_value_sp;
1471 if (IsValid() && name && *name && data.IsValid() && type.IsValid()) {
1472 DataExtractorSP extractor(*data);
1473 ExecutionContext exe_ctx(
1475 CompilerType ast_type(type.GetSP()->GetCompilerType(true));
1476 new_value_sp = ValueObject::CreateValueObjectFromData(name, *extractor,
1477 exe_ctx, ast_type);
1478 }
1479 sb_value.SetSP(new_value_sp);
1480 return sb_value;
1481}
1482
1484 const char *expr) {
1485 LLDB_INSTRUMENT_VA(this, name, expr);
1486
1487 SBValue sb_value;
1488 lldb::ValueObjectSP new_value_sp;
1489 if (IsValid() && name && *name && expr && *expr) {
1490 ExecutionContext exe_ctx(
1492 new_value_sp =
1494 }
1495 sb_value.SetSP(new_value_sp);
1496 return sb_value;
1497}
1498
1500 LLDB_INSTRUMENT_VA(this);
1501
1502 if (TargetSP target_sp = GetSP()) {
1503 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1504 std::unique_lock<std::recursive_mutex> lock;
1505 target_sp->GetWatchpointList().GetListMutex(lock);
1506 target_sp->RemoveAllWatchpoints();
1507 return true;
1508 }
1509 return false;
1510}
1511
1512void SBTarget::AppendImageSearchPath(const char *from, const char *to,
1514 LLDB_INSTRUMENT_VA(this, from, to, error);
1515
1516 if (TargetSP target_sp = GetSP()) {
1517 llvm::StringRef srFrom = from, srTo = to;
1518 if (srFrom.empty())
1519 return error.SetErrorString("<from> path can't be empty");
1520 if (srTo.empty())
1521 return error.SetErrorString("<to> path can't be empty");
1522
1523 target_sp->GetImageSearchPathList().Append(srFrom, srTo, true);
1524 } else {
1525 error.SetErrorString("invalid target");
1526 }
1527}
1528
1529lldb::SBModule SBTarget::AddModule(const char *path, const char *triple,
1530 const char *uuid_cstr) {
1531 LLDB_INSTRUMENT_VA(this, path, triple, uuid_cstr);
1532
1533 return AddModule(path, triple, uuid_cstr, nullptr);
1534}
1535
1536lldb::SBModule SBTarget::AddModule(const char *path, const char *triple,
1537 const char *uuid_cstr, const char *symfile) {
1538 LLDB_INSTRUMENT_VA(this, path, triple, uuid_cstr, symfile);
1539
1540 if (TargetSP target_sp = GetSP()) {
1541 ModuleSpec module_spec;
1542 if (path)
1543 module_spec.GetFileSpec().SetFile(path, FileSpec::Style::native);
1544
1545 if (uuid_cstr)
1546 module_spec.GetUUID().SetFromStringRef(uuid_cstr);
1547
1548 if (triple)
1550 target_sp->GetPlatform().get(), triple);
1551 else
1552 module_spec.GetArchitecture() = target_sp->GetArchitecture();
1553
1554 if (symfile)
1555 module_spec.GetSymbolFileSpec().SetFile(symfile, FileSpec::Style::native);
1556
1557 SBModuleSpec sb_modulespec(module_spec);
1558
1559 return AddModule(sb_modulespec);
1560 }
1561 return SBModule();
1562}
1563
1565 LLDB_INSTRUMENT_VA(this, module_spec);
1566
1567 lldb::SBModule sb_module;
1568 if (TargetSP target_sp = GetSP()) {
1569 sb_module.SetSP(target_sp->GetOrCreateModule(*module_spec.m_opaque_up,
1570 true /* notify */));
1571 if (!sb_module.IsValid() && module_spec.m_opaque_up->GetUUID().IsValid()) {
1572 Status error;
1574 error,
1575 /* force_lookup */ true)) {
1576 if (FileSystem::Instance().Exists(
1577 module_spec.m_opaque_up->GetFileSpec())) {
1578 sb_module.SetSP(target_sp->GetOrCreateModule(*module_spec.m_opaque_up,
1579 true /* notify */));
1580 }
1581 }
1582 }
1583
1584 // If the target hasn't initialized any architecture yet, use the
1585 // binary's architecture.
1586 if (sb_module.IsValid() && !target_sp->GetArchitecture().IsValid() &&
1587 sb_module.GetSP()->GetArchitecture().IsValid())
1588 target_sp->SetArchitecture(sb_module.GetSP()->GetArchitecture());
1589 }
1590 return sb_module;
1591}
1592
1594 LLDB_INSTRUMENT_VA(this, module);
1595
1596 if (TargetSP target_sp = GetSP()) {
1597 target_sp->GetImages().AppendIfNeeded(module.GetSP());
1598 return true;
1599 }
1600 return false;
1601}
1602
1603uint32_t SBTarget::GetNumModules() const {
1604 LLDB_INSTRUMENT_VA(this);
1605
1606 uint32_t num = 0;
1607 if (TargetSP target_sp = GetSP()) {
1608 // The module list is thread safe, no need to lock
1609 num = target_sp->GetImages().GetSize();
1610 }
1611
1612 return num;
1613}
1614
1616 LLDB_INSTRUMENT_VA(this);
1617
1618 m_opaque_sp.reset();
1619}
1620
1622 LLDB_INSTRUMENT_VA(this, sb_file_spec);
1623
1624 SBModule sb_module;
1625 if (TargetSP target_sp = GetSP(); target_sp && sb_file_spec.IsValid()) {
1626 ModuleSpec module_spec(*sb_file_spec);
1627 // The module list is thread safe, no need to lock
1628 sb_module.SetSP(target_sp->GetImages().FindFirstModule(module_spec));
1629 }
1630 return sb_module;
1631}
1632
1633SBModule SBTarget::FindModule(const SBModuleSpec &sb_module_spec) const {
1634 LLDB_INSTRUMENT_VA(this, sb_module_spec);
1635
1636 SBModule sb_module;
1637 if (TargetSP target_sp = GetSP(); target_sp && sb_module_spec.IsValid()) {
1638 // The module list is thread safe, no need to lock.
1639 sb_module.SetSP(
1640 target_sp->GetImages().FindFirstModule(*sb_module_spec.m_opaque_up));
1641 }
1642 return sb_module;
1643}
1644
1646 LLDB_INSTRUMENT_VA(this, sb_file_spec);
1647
1648 SBSymbolContextList sb_sc_list;
1649 if (TargetSP target_sp = GetSP(); target_sp && sb_file_spec.IsValid())
1650 target_sp->GetImages().FindCompileUnits(*sb_file_spec, *sb_sc_list);
1651 return sb_sc_list;
1652}
1653
1655 LLDB_INSTRUMENT_VA(this);
1656
1657 if (TargetSP target_sp = GetSP())
1658 return target_sp->GetArchitecture().GetByteOrder();
1659 return eByteOrderInvalid;
1660}
1661
1662const char *SBTarget::GetTriple() {
1663 LLDB_INSTRUMENT_VA(this);
1664
1665 if (TargetSP target_sp = GetSP()) {
1666 const std::string &triple = target_sp->GetArchitecture().GetTriple().str();
1667 // Unique the string so we don't run into ownership issues since the const
1668 // strings put the string into the string pool once and the strings never
1669 // comes out
1670 ConstString const_triple(triple);
1671 return const_triple.GetCString();
1672 }
1673 return nullptr;
1674}
1675
1676const char *SBTarget::GetArchName() const {
1677 LLDB_INSTRUMENT_VA(this);
1678
1679 if (TargetSP target_sp = GetSP()) {
1680 llvm::StringRef arch_name =
1681 target_sp->GetArchitecture().GetTriple().getArchName();
1682 ConstString const_arch_name(arch_name);
1683
1684 return const_arch_name.GetCString();
1685 }
1686 return nullptr;
1687}
1688
1690 LLDB_INSTRUMENT_VA(this);
1691
1692 if (TargetSP target_sp = GetSP()) {
1693 ConstString const_name(target_sp->GetABIName());
1694 return const_name.GetCString();
1695 }
1696 return nullptr;
1697}
1698
1699const char *SBTarget::GetLabel() const {
1700 LLDB_INSTRUMENT_VA(this);
1701
1702 if (TargetSP target_sp = GetSP())
1703 return ConstString(target_sp->GetLabel()).AsCString(nullptr);
1704 return nullptr;
1705}
1706
1708 LLDB_INSTRUMENT_VA(this);
1709
1710 if (TargetSP target_sp = GetSP())
1711 return target_sp->GetGloballyUniqueID();
1713}
1714
1716 LLDB_INSTRUMENT_VA(this);
1717
1718 if (TargetSP target_sp = GetSP())
1719 return ConstString(target_sp->GetTargetSessionName()).AsCString(nullptr);
1720 return nullptr;
1721}
1722
1723SBError SBTarget::SetLabel(const char *label) {
1724 LLDB_INSTRUMENT_VA(this, label);
1725
1726 if (TargetSP target_sp = GetSP())
1727 return Status::FromError(target_sp->SetLabel(label));
1728 return Status::FromErrorString("Couldn't get internal target object.");
1729}
1730
1732 LLDB_INSTRUMENT_VA(this);
1733
1734 if (TargetSP target_sp = GetSP())
1735 return target_sp->GetArchitecture().GetMinimumOpcodeByteSize();
1736 return 0;
1737}
1738
1740 LLDB_INSTRUMENT_VA(this);
1741
1742 TargetSP target_sp(GetSP());
1743 if (target_sp)
1744 return target_sp->GetArchitecture().GetMaximumOpcodeByteSize();
1745
1746 return 0;
1747}
1748
1750 LLDB_INSTRUMENT_VA(this);
1751
1752 return 1;
1753}
1754
1756 LLDB_INSTRUMENT_VA(this);
1757
1758 return 1;
1759}
1760
1762 LLDB_INSTRUMENT_VA(this);
1763
1764 if (TargetSP target_sp = GetSP())
1765 return target_sp->GetMaximumNumberOfChildrenToDisplay();
1766 return 0;
1767}
1768
1770 LLDB_INSTRUMENT_VA(this);
1771
1772 if (TargetSP target_sp = GetSP())
1773 return target_sp->GetArchitecture().GetAddressByteSize();
1774 return sizeof(void *);
1775}
1776
1778 LLDB_INSTRUMENT_VA(this, idx);
1779
1780 SBModule sb_module;
1781 ModuleSP module_sp;
1782 if (TargetSP target_sp = GetSP()) {
1783 // The module list is thread safe, no need to lock
1784 module_sp = target_sp->GetImages().GetModuleAtIndex(idx);
1785 sb_module.SetSP(module_sp);
1786 }
1787
1788 return sb_module;
1789}
1790
1792 LLDB_INSTRUMENT_VA(this, module);
1793
1794 if (TargetSP target_sp = GetSP())
1795 return target_sp->GetImages().Remove(module.GetSP());
1796 return false;
1797}
1798
1800 LLDB_INSTRUMENT_VA(this);
1801
1802 if (TargetSP target_sp = GetSP()) {
1803 SBBroadcaster broadcaster(target_sp.get(), false);
1804 return broadcaster;
1805 }
1806 return SBBroadcaster();
1807}
1808
1810 lldb::DescriptionLevel description_level) {
1811 LLDB_INSTRUMENT_VA(this, description, description_level);
1812
1813 Stream &strm = description.ref();
1814
1815 if (TargetSP target_sp = GetSP()) {
1816 target_sp->Dump(&strm, description_level);
1817 } else
1818 strm.PutCString("No value");
1819
1820 return true;
1821}
1822
1824 uint32_t name_type_mask) {
1825 LLDB_INSTRUMENT_VA(this, name, name_type_mask);
1826
1827 lldb::SBSymbolContextList sb_sc_list;
1828 if (!name || !name[0])
1829 return sb_sc_list;
1830
1831 if (TargetSP target_sp = GetSP()) {
1832 ModuleFunctionSearchOptions function_options;
1833 function_options.include_symbols = true;
1834 function_options.include_inlines = true;
1835
1836 FunctionNameType mask = static_cast<FunctionNameType>(name_type_mask);
1837 target_sp->GetImages().FindFunctions(ConstString(name), mask,
1838 function_options, *sb_sc_list);
1839 }
1840 return sb_sc_list;
1841}
1842
1844 uint32_t max_matches,
1845 MatchType matchtype) {
1846 LLDB_INSTRUMENT_VA(this, name, max_matches, matchtype);
1847
1848 lldb::SBSymbolContextList sb_sc_list;
1849 if (name && name[0]) {
1850 llvm::StringRef name_ref(name);
1851 if (TargetSP target_sp = GetSP()) {
1852 ModuleFunctionSearchOptions function_options;
1853 function_options.include_symbols = true;
1854 function_options.include_inlines = true;
1855
1856 std::string regexstr;
1857 switch (matchtype) {
1858 case eMatchTypeRegex:
1859 target_sp->GetImages().FindFunctions(RegularExpression(name_ref),
1860 function_options, *sb_sc_list);
1861 break;
1863 target_sp->GetImages().FindFunctions(
1864 RegularExpression(name_ref, llvm::Regex::RegexFlags::IgnoreCase),
1865 function_options, *sb_sc_list);
1866 break;
1868 regexstr = llvm::Regex::escape(name) + ".*";
1869 target_sp->GetImages().FindFunctions(RegularExpression(regexstr),
1870 function_options, *sb_sc_list);
1871 break;
1872 default:
1873 target_sp->GetImages().FindFunctions(ConstString(name),
1874 eFunctionNameTypeAny,
1875 function_options, *sb_sc_list);
1876 break;
1877 }
1878 }
1879 }
1880 return sb_sc_list;
1881}
1882
1884 const char *typename_cstr, lldb::LanguageType language, SBError &sb_error) {
1885 LLDB_INSTRUMENT_VA(this, typename_cstr, language, sb_error);
1886 sb_error.Clear();
1887
1888 TargetSP target_sp = GetSP();
1889 if (!target_sp) {
1890 sb_error.SetErrorString("no target.");
1891 return {};
1892 }
1893
1894 if (!typename_cstr || !typename_cstr[0]) {
1895 sb_error.SetErrorString("empty type name for search.");
1896 return {};
1897 }
1898
1899 if (language == eLanguageTypeUnknown) {
1900 sb_error.SetErrorString("eLanguageTypeUnknown can't define expression "
1901 "types.");
1902 return {};
1903 }
1904
1905 PersistentExpressionState *persistent =
1906 target_sp->GetPersistentExpressionStateForLanguage(language);
1907
1908 if (!persistent) {
1909 sb_error.SetErrorString(
1910 llvm::formatv("language {0} does not support expression defined types",
1911 language)
1912 .str()
1913 .c_str());
1914 return {};
1915 }
1916
1917 ConstString const_typename(typename_cstr);
1918 std::optional<CompilerType> type_op =
1919 persistent->GetCompilerTypeFromPersistentDecl(const_typename);
1920 if (type_op && (*type_op)) {
1921 return SBType(*type_op);
1922 }
1923 sb_error.SetErrorString(
1924 llvm::formatv("no type {0} found in expression types for language {1}",
1925 typename_cstr, language)
1926 .str()
1927 .c_str());
1928 return {};
1929}
1930
1933 lldb::LanguageType language) {
1934 LLDB_INSTRUMENT_VA(this, varname_cstr, language);
1935 TargetSP target_sp = GetSP();
1936 if (!target_sp)
1938 nullptr,
1940 "no variable {0} found for language {1}", varname_cstr, language));
1941
1942 if (!varname_cstr || !varname_cstr[0])
1944 target_sp.get(),
1945 Status::FromErrorString("empty variable name for search."));
1946
1947 if (language == eLanguageTypeUnknown)
1949 nullptr, Status::FromErrorString("eLanguageTypeUnknown doesn't support "
1950 "expression variables."));
1951
1952 PersistentExpressionState *persistent =
1953 target_sp->GetPersistentExpressionStateForLanguage(language);
1954 if (!persistent) {
1956 target_sp.get(),
1958 "language: {0} doesn't support expression variables.", language));
1959 }
1960
1961 ConstString const_varname(varname_cstr);
1962 lldb::ExpressionVariableSP expr_var_sp =
1963 persistent->GetVariable(const_varname);
1964 if (expr_var_sp)
1965 return expr_var_sp->GetValueObject();
1966
1968 target_sp.get(),
1970 "no variable {0} found for language {1}", varname_cstr, language));
1971}
1972
1973lldb::SBType SBTarget::FindFirstType(const char *typename_cstr) {
1974 LLDB_INSTRUMENT_VA(this, typename_cstr);
1975
1976 if (TargetSP target_sp = GetSP();
1977 target_sp && typename_cstr && typename_cstr[0]) {
1978 ConstString const_typename(typename_cstr);
1979 TypeQuery query(const_typename.GetStringRef(),
1980 TypeQueryOptions::e_find_one);
1981 TypeResults results;
1982 target_sp->GetImages().FindTypes(/*search_first=*/nullptr, query, results);
1983 if (TypeSP type_sp = results.GetFirstType())
1984 return SBType(type_sp);
1985 // Didn't find the type in the symbols; Try the loaded language runtimes.
1986 if (auto process_sp = target_sp->GetProcessSP()) {
1987 for (auto *runtime : process_sp->GetLanguageRuntimes()) {
1988 if (auto vendor = runtime->GetDeclVendor()) {
1989 auto types = vendor->FindTypes(const_typename, /*max_matches*/ 1);
1990 if (!types.empty())
1991 return SBType(types.front());
1992 }
1993 }
1994 }
1995
1996 // No matches, search for basic typename matches.
1997 for (auto type_system_sp : target_sp->GetScratchTypeSystems())
1998 if (auto type = type_system_sp->GetBuiltinTypeByName(const_typename))
1999 return SBType(type);
2000 }
2001
2002 return SBType();
2003}
2004
2006 LLDB_INSTRUMENT_VA(this, type);
2007
2008 if (TargetSP target_sp = GetSP()) {
2009 for (auto type_system_sp : target_sp->GetScratchTypeSystems())
2010 if (auto compiler_type = type_system_sp->GetBasicTypeFromAST(type))
2011 return SBType(compiler_type);
2012 }
2013 return SBType();
2014}
2015
2016lldb::SBTypeList SBTarget::FindTypes(const char *typename_cstr) {
2017 LLDB_INSTRUMENT_VA(this, typename_cstr);
2018
2019 SBTypeList sb_type_list;
2020 if (TargetSP target_sp = GetSP();
2021 target_sp && typename_cstr && typename_cstr[0]) {
2022 ModuleList &images = target_sp->GetImages();
2023 ConstString const_typename(typename_cstr);
2024 TypeQuery query(typename_cstr);
2025 TypeResults results;
2026 images.FindTypes(nullptr, query, results);
2027 for (const TypeSP &type_sp : results.GetTypeMap().Types())
2028 sb_type_list.Append(SBType(type_sp));
2029
2030 // Try the loaded language runtimes
2031 if (ProcessSP process_sp = target_sp->GetProcessSP()) {
2032 for (auto *runtime : process_sp->GetLanguageRuntimes()) {
2033 if (auto *vendor = runtime->GetDeclVendor()) {
2034 auto types =
2035 vendor->FindTypes(const_typename, /*max_matches*/ UINT32_MAX);
2036 for (auto type : types)
2037 sb_type_list.Append(SBType(type));
2038 }
2039 }
2040 }
2041
2042 if (sb_type_list.GetSize() == 0) {
2043 // No matches, search for basic typename matches
2044 for (auto type_system_sp : target_sp->GetScratchTypeSystems())
2045 if (auto compiler_type =
2046 type_system_sp->GetBuiltinTypeByName(const_typename))
2047 sb_type_list.Append(SBType(compiler_type));
2048 }
2049 }
2050 return sb_type_list;
2051}
2052
2054 uint32_t max_matches) {
2055 LLDB_INSTRUMENT_VA(this, name, max_matches);
2056
2057 SBValueList sb_value_list;
2058
2059 if (TargetSP target_sp = GetSP(); target_sp && name) {
2060 VariableList variable_list;
2061 target_sp->GetImages().FindGlobalVariables(ConstString(name), max_matches,
2062 variable_list);
2063 if (!variable_list.Empty()) {
2064 ExecutionContextScope *exe_scope = target_sp->GetProcessSP().get();
2065 if (exe_scope == nullptr)
2066 exe_scope = target_sp.get();
2067 for (const VariableSP &var_sp : variable_list) {
2068 lldb::ValueObjectSP valobj_sp(
2069 ValueObjectVariable::Create(exe_scope, var_sp));
2070 if (valobj_sp)
2071 sb_value_list.Append(SBValue(valobj_sp));
2072 }
2073 }
2074 }
2075
2076 return sb_value_list;
2077}
2078
2080 uint32_t max_matches,
2081 MatchType matchtype) {
2082 LLDB_INSTRUMENT_VA(this, name, max_matches, matchtype);
2083
2084 SBValueList sb_value_list;
2085
2086 if (TargetSP target_sp = GetSP(); target_sp && name) {
2087 llvm::StringRef name_ref(name);
2088 VariableList variable_list;
2089
2090 std::string regexstr;
2091 switch (matchtype) {
2092 case eMatchTypeNormal:
2093 target_sp->GetImages().FindGlobalVariables(ConstString(name), max_matches,
2094 variable_list);
2095 break;
2096 case eMatchTypeRegex:
2097 target_sp->GetImages().FindGlobalVariables(RegularExpression(name_ref),
2098 max_matches, variable_list);
2099 break;
2101 target_sp->GetImages().FindGlobalVariables(
2102 RegularExpression(name_ref, llvm::Regex::IgnoreCase), max_matches,
2103 variable_list);
2104 break;
2106 regexstr = "^" + llvm::Regex::escape(name) + ".*";
2107 target_sp->GetImages().FindGlobalVariables(RegularExpression(regexstr),
2108 max_matches, variable_list);
2109 break;
2110 }
2111 if (!variable_list.Empty()) {
2112 ExecutionContextScope *exe_scope = target_sp->GetProcessSP().get();
2113 if (exe_scope == nullptr)
2114 exe_scope = target_sp.get();
2115 for (const VariableSP &var_sp : variable_list) {
2116 lldb::ValueObjectSP valobj_sp(
2117 ValueObjectVariable::Create(exe_scope, var_sp));
2118 if (valobj_sp)
2119 sb_value_list.Append(SBValue(valobj_sp));
2120 }
2121 }
2122 }
2123
2124 return sb_value_list;
2125}
2126
2128 LLDB_INSTRUMENT_VA(this, name);
2129
2130 SBValueList sb_value_list(FindGlobalVariables(name, 1));
2131 if (sb_value_list.IsValid() && sb_value_list.GetSize() > 0)
2132 return sb_value_list.GetValueAtIndex(0);
2133 return SBValue();
2134}
2135
2137 LLDB_INSTRUMENT_VA(this);
2138
2139 SBSourceManager source_manager(*this);
2140 return source_manager;
2141}
2142
2144 uint32_t count) {
2145 LLDB_INSTRUMENT_VA(this, base_addr, count);
2146
2147 return ReadInstructions(base_addr, count, nullptr);
2148}
2149
2151 uint32_t count,
2152 const char *flavor_string) {
2153 LLDB_INSTRUMENT_VA(this, base_addr, count, flavor_string);
2154
2155 SBInstructionList sb_instructions;
2156
2157 if (TargetSP target_sp = GetSP()) {
2158 if (Address *addr_ptr = base_addr.get()) {
2159 if (llvm::Expected<DisassemblerSP> disassembler =
2160 target_sp->ReadInstructions(*addr_ptr, count, flavor_string)) {
2161 sb_instructions.SetDisassembler(*disassembler);
2162 }
2163 }
2164 }
2165
2166 return sb_instructions;
2167}
2168
2170 lldb::SBAddress end_addr,
2171 const char *flavor_string) {
2172 LLDB_INSTRUMENT_VA(this, start_addr, end_addr, flavor_string);
2173
2174 SBInstructionList sb_instructions;
2175
2176 if (TargetSP target_sp = GetSP()) {
2177 lldb::addr_t start_load_addr = start_addr.GetLoadAddress(*this);
2178 lldb::addr_t end_load_addr = end_addr.GetLoadAddress(*this);
2179 if (end_load_addr > start_load_addr) {
2180 lldb::addr_t size = end_load_addr - start_load_addr;
2181
2182 AddressRange range(start_load_addr, size);
2183 const bool force_live_memory = true;
2185 target_sp->GetArchitecture(), nullptr, flavor_string,
2186 target_sp->GetDisassemblyCPU(), target_sp->GetDisassemblyFeatures(),
2187 *target_sp, range, force_live_memory));
2188 }
2189 }
2190 return sb_instructions;
2191}
2192
2194 const void *buf,
2195 size_t size) {
2196 LLDB_INSTRUMENT_VA(this, base_addr, buf, size);
2197
2198 return GetInstructionsWithFlavor(base_addr, nullptr, buf, size);
2199}
2200
2203 const char *flavor_string, const void *buf,
2204 size_t size) {
2205 LLDB_INSTRUMENT_VA(this, base_addr, flavor_string, buf, size);
2206
2207 SBInstructionList sb_instructions;
2208
2209 if (TargetSP target_sp = GetSP()) {
2210 Address addr;
2211
2212 if (base_addr.get())
2213 addr = *base_addr.get();
2214
2215 constexpr bool data_from_file = true;
2216 if (!flavor_string || flavor_string[0] == '\0') {
2217 // FIXME - we don't have the mechanism in place to do per-architecture
2218 // settings. But since we know that for now we only support flavors on
2219 // x86 & x86_64,
2220 const llvm::Triple::ArchType arch =
2221 target_sp->GetArchitecture().GetTriple().getArch();
2222 if (arch == llvm::Triple::x86 || arch == llvm::Triple::x86_64)
2223 flavor_string = target_sp->GetDisassemblyFlavor();
2224 }
2225
2227 target_sp->GetArchitecture(), nullptr, flavor_string,
2228 target_sp->GetDisassemblyCPU(), target_sp->GetDisassemblyFeatures(),
2229 addr, buf, size, UINT32_MAX, data_from_file));
2230 }
2231
2232 return sb_instructions;
2233}
2234
2236 const void *buf,
2237 size_t size) {
2238 LLDB_INSTRUMENT_VA(this, base_addr, buf, size);
2239
2240 return GetInstructionsWithFlavor(ResolveLoadAddress(base_addr), nullptr, buf,
2241 size);
2242}
2243
2246 const char *flavor_string, const void *buf,
2247 size_t size) {
2248 LLDB_INSTRUMENT_VA(this, base_addr, flavor_string, buf, size);
2249
2250 return GetInstructionsWithFlavor(ResolveLoadAddress(base_addr), flavor_string,
2251 buf, size);
2252}
2253
2255 lldb::addr_t section_base_addr) {
2256 LLDB_INSTRUMENT_VA(this, section, section_base_addr);
2257
2258 SBError sb_error;
2259 if (TargetSP target_sp = GetSP()) {
2260 if (!section.IsValid()) {
2261 sb_error.SetErrorStringWithFormat("invalid section");
2262 } else {
2263 SectionSP section_sp(section.GetSP());
2264 if (section_sp) {
2265 if (section_sp->IsThreadSpecific()) {
2266 sb_error.SetErrorString(
2267 "thread specific sections are not yet supported");
2268 } else {
2269 ProcessSP process_sp(target_sp->GetProcessSP());
2270 if (target_sp->SetSectionLoadAddress(section_sp, section_base_addr)) {
2271 ModuleSP module_sp(section_sp->GetModule());
2272 if (module_sp) {
2273 ModuleList module_list;
2274 module_list.Append(module_sp);
2275 target_sp->ModulesDidLoad(module_list);
2276 }
2277 // Flush info in the process (stack frames, etc)
2278 if (process_sp)
2279 process_sp->Flush();
2280 }
2281 }
2282 }
2283 }
2284 } else {
2285 sb_error.SetErrorString("invalid target");
2286 }
2287 return sb_error;
2288}
2289
2291 LLDB_INSTRUMENT_VA(this, section);
2292
2293 SBError sb_error;
2294
2295 if (TargetSP target_sp = GetSP()) {
2296 if (!section.IsValid()) {
2297 sb_error.SetErrorStringWithFormat("invalid section");
2298 } else {
2299 SectionSP section_sp(section.GetSP());
2300 if (section_sp) {
2301 ProcessSP process_sp(target_sp->GetProcessSP());
2302 if (target_sp->SetSectionUnloaded(section_sp)) {
2303 ModuleSP module_sp(section_sp->GetModule());
2304 if (module_sp) {
2305 ModuleList module_list;
2306 module_list.Append(module_sp);
2307 target_sp->ModulesDidUnload(module_list, false);
2308 }
2309 // Flush info in the process (stack frames, etc)
2310 if (process_sp)
2311 process_sp->Flush();
2312 }
2313 } else {
2314 sb_error.SetErrorStringWithFormat("invalid section");
2315 }
2316 }
2317 } else {
2318 sb_error.SetErrorStringWithFormat("invalid target");
2319 }
2320 return sb_error;
2321}
2322
2324 int64_t slide_offset) {
2325 LLDB_INSTRUMENT_VA(this, module, slide_offset);
2326
2327 if (slide_offset < 0) {
2328 SBError sb_error;
2329 sb_error.SetErrorStringWithFormat("slide must be positive");
2330 return sb_error;
2331 }
2332
2333 return SetModuleLoadAddress(module, static_cast<uint64_t>(slide_offset));
2334}
2335
2337 uint64_t slide_offset) {
2338
2339 SBError sb_error;
2340
2341 if (TargetSP target_sp = GetSP()) {
2342 ModuleSP module_sp(module.GetSP());
2343 if (module_sp) {
2344 bool changed = false;
2345 if (module_sp->SetLoadAddress(*target_sp, slide_offset, true, changed)) {
2346 // The load was successful, make sure that at least some sections
2347 // changed before we notify that our module was loaded.
2348 if (changed) {
2349 ModuleList module_list;
2350 module_list.Append(module_sp);
2351 target_sp->ModulesDidLoad(module_list);
2352 // Flush info in the process (stack frames, etc)
2353 ProcessSP process_sp(target_sp->GetProcessSP());
2354 if (process_sp)
2355 process_sp->Flush();
2356 }
2357 }
2358 } else {
2359 sb_error.SetErrorStringWithFormat("invalid module");
2360 }
2361
2362 } else {
2363 sb_error.SetErrorStringWithFormat("invalid target");
2364 }
2365 return sb_error;
2366}
2367
2369 LLDB_INSTRUMENT_VA(this, module);
2370
2371 SBError sb_error;
2372
2373 char path[PATH_MAX];
2374 if (TargetSP target_sp = GetSP()) {
2375 ModuleSP module_sp(module.GetSP());
2376 if (module_sp) {
2377 ObjectFile *objfile = module_sp->GetObjectFile();
2378 if (objfile) {
2379 SectionList *section_list = objfile->GetSectionList();
2380 if (section_list) {
2381 ProcessSP process_sp(target_sp->GetProcessSP());
2382
2383 bool changed = false;
2384 const size_t num_sections = section_list->GetSize();
2385 for (size_t sect_idx = 0; sect_idx < num_sections; ++sect_idx) {
2386 SectionSP section_sp(section_list->GetSectionAtIndex(sect_idx));
2387 if (section_sp)
2388 changed |= target_sp->SetSectionUnloaded(section_sp);
2389 }
2390 if (changed) {
2391 ModuleList module_list;
2392 module_list.Append(module_sp);
2393 target_sp->ModulesDidUnload(module_list, false);
2394 // Flush info in the process (stack frames, etc)
2395 ProcessSP process_sp(target_sp->GetProcessSP());
2396 if (process_sp)
2397 process_sp->Flush();
2398 }
2399 } else {
2400 module_sp->GetFileSpec().GetPath(path, sizeof(path));
2401 sb_error.SetErrorStringWithFormat("no sections in object file '%s'",
2402 path);
2403 }
2404 } else {
2405 module_sp->GetFileSpec().GetPath(path, sizeof(path));
2406 sb_error.SetErrorStringWithFormat("no object file for module '%s'",
2407 path);
2408 }
2409 } else {
2410 sb_error.SetErrorStringWithFormat("invalid module");
2411 }
2412 } else {
2413 sb_error.SetErrorStringWithFormat("invalid target");
2414 }
2415 return sb_error;
2416}
2417
2419 lldb::SymbolType symbol_type) {
2420 LLDB_INSTRUMENT_VA(this, name, symbol_type);
2421
2422 SBSymbolContextList sb_sc_list;
2423 if (name && name[0]) {
2424 if (TargetSP target_sp = GetSP()) {
2425 target_sp->GetImages().FindSymbolsWithNameAndType(
2426 ConstString(name), symbol_type, *sb_sc_list);
2427 }
2428 }
2429 return sb_sc_list;
2430}
2431
2433 LLDB_INSTRUMENT_VA(this, expr);
2434
2435 if (TargetSP target_sp = GetSP()) {
2436 SBExpressionOptions options;
2437 lldb::DynamicValueType fetch_dynamic_value =
2438 target_sp->GetPreferDynamicValue();
2439 options.SetFetchDynamicValue(fetch_dynamic_value);
2440 options.SetUnwindOnError(true);
2441 return EvaluateExpression(expr, options);
2442 }
2443 return SBValue();
2444}
2445
2447 const SBExpressionOptions &options) {
2448 LLDB_INSTRUMENT_VA(this, expr, options);
2449
2450 Log *expr_log = GetLog(LLDBLog::Expressions);
2451 SBValue expr_result;
2452 ValueObjectSP expr_value_sp;
2453 if (TargetSP target_sp = GetSP()) {
2454 StackFrame *frame = nullptr;
2455 if (expr == nullptr || expr[0] == '\0')
2456 return expr_result;
2457
2458 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
2459 ExecutionContext exe_ctx(m_opaque_sp.get());
2460
2461 frame = exe_ctx.GetFramePtr();
2462 Target *target = exe_ctx.GetTargetPtr();
2463 Process *process = exe_ctx.GetProcessPtr();
2464
2465 if (target) {
2466 // If we have a process, make sure to lock the runlock:
2467 if (process) {
2468 Process::StopLocker stop_locker;
2469 if (stop_locker.TryLock(&process->GetRunLock())) {
2470 target->EvaluateExpression(expr, frame, expr_value_sp, options.ref());
2471 } else {
2472 Status error;
2473 error = Status::FromErrorString("can't evaluate expressions when the "
2474 "process is running.");
2475 expr_value_sp =
2476 ValueObjectConstResult::Create(nullptr, std::move(error));
2477 }
2478 } else {
2479 target->EvaluateExpression(expr, frame, expr_value_sp, options.ref());
2480 }
2481
2482 expr_result.SetSP(expr_value_sp, options.GetFetchDynamicValue());
2483 }
2484 }
2485 LLDB_LOGF(expr_log,
2486 "** [SBTarget::EvaluateExpression] Expression result is "
2487 "%s, summary %s **",
2488 expr_result.GetValue(), expr_result.GetSummary());
2489 return expr_result;
2490}
2491
2493 LLDB_INSTRUMENT_VA(this);
2494
2495 if (TargetSP target_sp = GetSP()) {
2496 ABISP abi_sp;
2497 ProcessSP process_sp(target_sp->GetProcessSP());
2498 if (process_sp)
2499 abi_sp = process_sp->GetABI();
2500 else
2501 abi_sp = ABI::FindPlugin(ProcessSP(), target_sp->GetArchitecture());
2502 if (abi_sp)
2503 return abi_sp->GetRedZoneSize();
2504 }
2505 return 0;
2506}
2507
2508bool SBTarget::IsLoaded(const SBModule &module) const {
2509 LLDB_INSTRUMENT_VA(this, module);
2510
2511 if (TargetSP target_sp = GetSP()) {
2512 ModuleSP module_sp(module.GetSP());
2513 if (module_sp)
2514 return module_sp->IsLoadedInTarget(target_sp.get());
2515 }
2516 return false;
2517}
2518
2520 LLDB_INSTRUMENT_VA(this);
2521
2522 lldb::SBLaunchInfo launch_info(nullptr);
2523 if (TargetSP target_sp = GetSP())
2524 launch_info.set_ref(m_opaque_sp->GetProcessLaunchInfo());
2525 return launch_info;
2526}
2527
2529 LLDB_INSTRUMENT_VA(this, launch_info);
2530
2531 if (TargetSP target_sp = GetSP())
2532 m_opaque_sp->SetProcessLaunchInfo(launch_info.ref());
2533}
2534
2536 LLDB_INSTRUMENT_VA(this);
2537
2538 if (TargetSP target_sp = GetSP())
2539 return SBEnvironment(target_sp->GetEnvironment());
2540
2541 return SBEnvironment();
2542}
2543
2545 LLDB_INSTRUMENT_VA(this);
2546
2547 if (TargetSP target_sp = GetSP())
2548 return SBTrace(target_sp->GetTrace());
2549
2550 return SBTrace();
2551}
2552
2555
2556 error.Clear();
2557 if (TargetSP target_sp = GetSP()) {
2558 if (llvm::Expected<lldb::TraceSP> trace_sp = target_sp->CreateTrace()) {
2559 return SBTrace(*trace_sp);
2560 } else {
2561 error.SetErrorString(llvm::toString(trace_sp.takeError()).c_str());
2562 }
2563 } else {
2564 error.SetErrorString("missing target");
2565 }
2566 return SBTrace();
2567}
2568
2570 LLDB_INSTRUMENT_VA(this);
2571
2572 if (TargetSP target_sp = GetSP())
2573 return lldb::SBMutex(target_sp);
2574 return lldb::SBMutex();
2575}
2576
2577uint32_t
2579 lldb::SBStructuredData args_dict,
2581 LLDB_INSTRUMENT_VA(this, class_name, args_dict, error);
2582
2583 TargetSP target_sp = GetSP();
2584 if (!target_sp) {
2585 error.SetErrorString("invalid target");
2586 return 0;
2587 }
2588
2589 if (!class_name || !class_name[0]) {
2590 error.SetErrorString("invalid class name");
2591 return 0;
2592 }
2593
2594 // Extract the dictionary from SBStructuredData.
2596 if (args_dict.IsValid() && args_dict.m_impl_up) {
2597 StructuredData::ObjectSP obj_sp = args_dict.m_impl_up->GetObjectSP();
2598 if (obj_sp && obj_sp->GetType() != lldb::eStructuredDataTypeDictionary) {
2599 error.SetErrorString("SBStructuredData argument isn't a dictionary");
2600 return 0;
2601 }
2602 dict_sp = std::make_shared<StructuredData::Dictionary>(obj_sp);
2603 }
2604
2605 // Create the ScriptedMetadata.
2606 ScriptedMetadataSP metadata_sp =
2607 std::make_shared<ScriptedMetadata>(class_name, dict_sp);
2608
2609 // Create the interface for calling static methods.
2611 target_sp->GetDebugger()
2612 .GetScriptInterpreter()
2613 ->CreateScriptedFrameProviderInterface();
2614
2615 // Create a descriptor (applies to all threads by default).
2616 ScriptedFrameProviderDescriptor descriptor(metadata_sp);
2617 descriptor.interface_sp = interface_sp;
2618
2619 llvm::Expected<uint32_t> descriptor_id_or_err =
2620 target_sp->AddScriptedFrameProviderDescriptor(descriptor);
2621 if (!descriptor_id_or_err) {
2622 error.SetErrorString(
2623 llvm::toString(descriptor_id_or_err.takeError()).c_str());
2624 return 0;
2625 }
2626
2627 // Register the descriptor with the target.
2628 return *descriptor_id_or_err;
2629}
2630
2632 LLDB_INSTRUMENT_VA(this, provider_id);
2633
2634 SBError error;
2635 TargetSP target_sp = GetSP();
2636 if (!target_sp) {
2637 error.SetErrorString("invalid target");
2638 return error;
2639 }
2640
2641 if (!provider_id) {
2642 error.SetErrorString("invalid provider id");
2643 return error;
2644 }
2645
2646 if (!target_sp->RemoveScriptedFrameProviderDescriptor(provider_id)) {
2647 error.SetErrorStringWithFormat("no frame provider named '%u' found",
2648 provider_id);
2649 return error;
2650 }
2651
2652 return {};
2653}
static llvm::raw_ostream & error(Stream &strm)
#define LLDB_INSTRUMENT()
#define LLDB_INSTRUMENT_VA(...)
#define LLDB_LOGF(log,...)
Definition Log.h:390
#define LLDB_LOG_ERROR(log, error,...)
Definition Log.h:406
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:997
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:951
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:1059
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)
lldb::SBFileSpec GetExecutable()
Definition SBTarget.cpp:570
const char * GetABIName()
friend class SBDebugger
Definition SBTarget.h:1051
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:1056
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:1048
lldb::SBBreakpoint BreakpointCreateByName(const char *symbol_name, const char *module_name=nullptr)
Definition SBTarget.cpp:817
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:1065
friend class SBAddress
Definition SBTarget.h:1045
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:721
lldb::SBBreakpoint BreakpointCreateByLocation(const char *file, uint32_t line)
Definition SBTarget.cpp:728
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()
uint64_t AddBreakpointOverride(const char *class_name, const char *description, uint64_t type_mask, SBStructuredData &args_data, SBError &status)
Adds a breakpoint override implemented by class_name.
Definition SBTarget.cpp:685
lldb::SBInstructionList GetInstructions(lldb::SBAddress base_addr, const void *buf, size_t size)
friend class SBModuleSpec
Definition SBTarget.h:1057
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:1082
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:1049
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:906
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:1061
lldb::SBBreakpoint FindBreakpointByID(break_id_t break_id)
friend class SBType
Definition SBTarget.h:1063
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:1058
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:993
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:441
An architecture specification class.
Definition ArchSpec.h:32
bool IsValid() const
Tests if this ArchSpec is valid.
Definition ArchSpec.h:452
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:359
ProcessRunLock::ProcessRunLocker StopLocker
Definition Process.h:399
ProcessRunLock & GetRunLock()
Definition Process.cpp:6156
size_t GetSize() const
Definition Section.h:77
lldb::SectionSP GetSectionAtIndex(size_t idx) const
Definition Section.cpp:552
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:5978
static ModuleList GetModuleListFromEvent(const Event *event_ptr)
Definition Target.cpp:5987
static const TargetEventData * GetEventDataFromEvent(const Event *event_ptr)
Definition Target.cpp:5959
static lldb::TargetSP GetTargetFromEvent(const Event *event_ptr)
Definition Target.cpp:5969
const lldb::ProcessSP & GetProcessSP() const
Definition Target.cpp:329
std::recursive_mutex & GetAPIMutex()
Definition Target.cpp:5995
static llvm::StringRef GetStaticBroadcasterClass()
Definition Target.cpp:176
Status Attach(ProcessAttachInfo &attach_info, Stream *stream)
Definition Target.cpp:3792
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:2942
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:339
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