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