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