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