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