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