15ffd83dbSDimitry Andric //===-- SBTarget.cpp ------------------------------------------------------===//
20b57cec5SDimitry Andric //
30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric //
70b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric 
90b57cec5SDimitry Andric #include "lldb/API/SBTarget.h"
100b57cec5SDimitry Andric #include "SBReproducerPrivate.h"
110b57cec5SDimitry Andric 
120b57cec5SDimitry Andric #include "lldb/lldb-public.h"
130b57cec5SDimitry Andric 
140b57cec5SDimitry Andric #include "lldb/API/SBBreakpoint.h"
150b57cec5SDimitry Andric #include "lldb/API/SBDebugger.h"
165ffd83dbSDimitry Andric #include "lldb/API/SBEnvironment.h"
170b57cec5SDimitry Andric #include "lldb/API/SBEvent.h"
180b57cec5SDimitry Andric #include "lldb/API/SBExpressionOptions.h"
190b57cec5SDimitry Andric #include "lldb/API/SBFileSpec.h"
200b57cec5SDimitry Andric #include "lldb/API/SBListener.h"
210b57cec5SDimitry Andric #include "lldb/API/SBModule.h"
220b57cec5SDimitry Andric #include "lldb/API/SBModuleSpec.h"
230b57cec5SDimitry Andric #include "lldb/API/SBProcess.h"
240b57cec5SDimitry Andric #include "lldb/API/SBSourceManager.h"
250b57cec5SDimitry Andric #include "lldb/API/SBStream.h"
260b57cec5SDimitry Andric #include "lldb/API/SBStringList.h"
270b57cec5SDimitry Andric #include "lldb/API/SBStructuredData.h"
280b57cec5SDimitry Andric #include "lldb/API/SBSymbolContextList.h"
29*5f7ddb14SDimitry Andric #include "lldb/API/SBTrace.h"
300b57cec5SDimitry Andric #include "lldb/Breakpoint/BreakpointID.h"
310b57cec5SDimitry Andric #include "lldb/Breakpoint/BreakpointIDList.h"
320b57cec5SDimitry Andric #include "lldb/Breakpoint/BreakpointList.h"
330b57cec5SDimitry Andric #include "lldb/Breakpoint/BreakpointLocation.h"
340b57cec5SDimitry Andric #include "lldb/Core/Address.h"
350b57cec5SDimitry Andric #include "lldb/Core/AddressResolver.h"
360b57cec5SDimitry Andric #include "lldb/Core/Debugger.h"
370b57cec5SDimitry Andric #include "lldb/Core/Disassembler.h"
380b57cec5SDimitry Andric #include "lldb/Core/Module.h"
390b57cec5SDimitry Andric #include "lldb/Core/ModuleSpec.h"
400b57cec5SDimitry Andric #include "lldb/Core/SearchFilter.h"
410b57cec5SDimitry Andric #include "lldb/Core/Section.h"
420b57cec5SDimitry Andric #include "lldb/Core/StructuredDataImpl.h"
430b57cec5SDimitry Andric #include "lldb/Core/ValueObjectConstResult.h"
440b57cec5SDimitry Andric #include "lldb/Core/ValueObjectList.h"
450b57cec5SDimitry Andric #include "lldb/Core/ValueObjectVariable.h"
460b57cec5SDimitry Andric #include "lldb/Host/Host.h"
470b57cec5SDimitry Andric #include "lldb/Symbol/DeclVendor.h"
480b57cec5SDimitry Andric #include "lldb/Symbol/ObjectFile.h"
490b57cec5SDimitry Andric #include "lldb/Symbol/SymbolFile.h"
500b57cec5SDimitry Andric #include "lldb/Symbol/SymbolVendor.h"
519dba64beSDimitry Andric #include "lldb/Symbol/TypeSystem.h"
520b57cec5SDimitry Andric #include "lldb/Symbol/VariableList.h"
530b57cec5SDimitry Andric #include "lldb/Target/ABI.h"
540b57cec5SDimitry Andric #include "lldb/Target/Language.h"
550b57cec5SDimitry Andric #include "lldb/Target/LanguageRuntime.h"
560b57cec5SDimitry Andric #include "lldb/Target/Process.h"
570b57cec5SDimitry Andric #include "lldb/Target/StackFrame.h"
580b57cec5SDimitry Andric #include "lldb/Target/Target.h"
590b57cec5SDimitry Andric #include "lldb/Target/TargetList.h"
600b57cec5SDimitry Andric #include "lldb/Utility/ArchSpec.h"
610b57cec5SDimitry Andric #include "lldb/Utility/Args.h"
620b57cec5SDimitry Andric #include "lldb/Utility/FileSpec.h"
630b57cec5SDimitry Andric #include "lldb/Utility/ProcessInfo.h"
640b57cec5SDimitry Andric #include "lldb/Utility/RegularExpression.h"
650b57cec5SDimitry Andric 
660b57cec5SDimitry Andric #include "Commands/CommandObjectBreakpoint.h"
670b57cec5SDimitry Andric #include "lldb/Interpreter/CommandReturnObject.h"
680b57cec5SDimitry Andric #include "llvm/Support/PrettyStackTrace.h"
690b57cec5SDimitry Andric #include "llvm/Support/Regex.h"
700b57cec5SDimitry Andric 
710b57cec5SDimitry Andric using namespace lldb;
720b57cec5SDimitry Andric using namespace lldb_private;
730b57cec5SDimitry Andric 
740b57cec5SDimitry Andric #define DEFAULT_DISASM_BYTE_SIZE 32
750b57cec5SDimitry Andric 
760b57cec5SDimitry Andric namespace {
770b57cec5SDimitry Andric 
AttachToProcess(ProcessAttachInfo & attach_info,Target & target)780b57cec5SDimitry Andric Status AttachToProcess(ProcessAttachInfo &attach_info, Target &target) {
790b57cec5SDimitry Andric   std::lock_guard<std::recursive_mutex> guard(target.GetAPIMutex());
800b57cec5SDimitry Andric 
810b57cec5SDimitry Andric   auto process_sp = target.GetProcessSP();
820b57cec5SDimitry Andric   if (process_sp) {
830b57cec5SDimitry Andric     const auto state = process_sp->GetState();
840b57cec5SDimitry Andric     if (process_sp->IsAlive() && state == eStateConnected) {
850b57cec5SDimitry Andric       // If we are already connected, then we have already specified the
860b57cec5SDimitry Andric       // listener, so if a valid listener is supplied, we need to error out to
870b57cec5SDimitry Andric       // let the client know.
880b57cec5SDimitry Andric       if (attach_info.GetListener())
890b57cec5SDimitry Andric         return Status("process is connected and already has a listener, pass "
900b57cec5SDimitry Andric                       "empty listener");
910b57cec5SDimitry Andric     }
920b57cec5SDimitry Andric   }
930b57cec5SDimitry Andric 
940b57cec5SDimitry Andric   return target.Attach(attach_info, nullptr);
950b57cec5SDimitry Andric }
960b57cec5SDimitry Andric 
970b57cec5SDimitry Andric } // namespace
980b57cec5SDimitry Andric 
990b57cec5SDimitry Andric // SBTarget constructor
SBTarget()1000b57cec5SDimitry Andric SBTarget::SBTarget() : m_opaque_sp() {
1010b57cec5SDimitry Andric   LLDB_RECORD_CONSTRUCTOR_NO_ARGS(SBTarget);
1020b57cec5SDimitry Andric }
1030b57cec5SDimitry Andric 
SBTarget(const SBTarget & rhs)1040b57cec5SDimitry Andric SBTarget::SBTarget(const SBTarget &rhs) : m_opaque_sp(rhs.m_opaque_sp) {
1050b57cec5SDimitry Andric   LLDB_RECORD_CONSTRUCTOR(SBTarget, (const lldb::SBTarget &), rhs);
1060b57cec5SDimitry Andric }
1070b57cec5SDimitry Andric 
SBTarget(const TargetSP & target_sp)1080b57cec5SDimitry Andric SBTarget::SBTarget(const TargetSP &target_sp) : m_opaque_sp(target_sp) {
1090b57cec5SDimitry Andric   LLDB_RECORD_CONSTRUCTOR(SBTarget, (const lldb::TargetSP &), target_sp);
1100b57cec5SDimitry Andric }
1110b57cec5SDimitry Andric 
operator =(const SBTarget & rhs)1120b57cec5SDimitry Andric const SBTarget &SBTarget::operator=(const SBTarget &rhs) {
1130b57cec5SDimitry Andric   LLDB_RECORD_METHOD(const lldb::SBTarget &,
1140b57cec5SDimitry Andric                      SBTarget, operator=,(const lldb::SBTarget &), rhs);
1150b57cec5SDimitry Andric 
1160b57cec5SDimitry Andric   if (this != &rhs)
1170b57cec5SDimitry Andric     m_opaque_sp = rhs.m_opaque_sp;
1180b57cec5SDimitry Andric   return LLDB_RECORD_RESULT(*this);
1190b57cec5SDimitry Andric }
1200b57cec5SDimitry Andric 
1210b57cec5SDimitry Andric // Destructor
1225ffd83dbSDimitry Andric SBTarget::~SBTarget() = default;
1230b57cec5SDimitry Andric 
EventIsTargetEvent(const SBEvent & event)1240b57cec5SDimitry Andric bool SBTarget::EventIsTargetEvent(const SBEvent &event) {
1250b57cec5SDimitry Andric   LLDB_RECORD_STATIC_METHOD(bool, SBTarget, EventIsTargetEvent,
1260b57cec5SDimitry Andric                             (const lldb::SBEvent &), event);
1270b57cec5SDimitry Andric 
1280b57cec5SDimitry Andric   return Target::TargetEventData::GetEventDataFromEvent(event.get()) != nullptr;
1290b57cec5SDimitry Andric }
1300b57cec5SDimitry Andric 
GetTargetFromEvent(const SBEvent & event)1310b57cec5SDimitry Andric SBTarget SBTarget::GetTargetFromEvent(const SBEvent &event) {
1320b57cec5SDimitry Andric   LLDB_RECORD_STATIC_METHOD(lldb::SBTarget, SBTarget, GetTargetFromEvent,
1330b57cec5SDimitry Andric                             (const lldb::SBEvent &), event);
1340b57cec5SDimitry Andric 
1350b57cec5SDimitry Andric   return LLDB_RECORD_RESULT(
1360b57cec5SDimitry Andric       Target::TargetEventData::GetTargetFromEvent(event.get()));
1370b57cec5SDimitry Andric }
1380b57cec5SDimitry Andric 
GetNumModulesFromEvent(const SBEvent & event)1390b57cec5SDimitry Andric uint32_t SBTarget::GetNumModulesFromEvent(const SBEvent &event) {
1400b57cec5SDimitry Andric   LLDB_RECORD_STATIC_METHOD(uint32_t, SBTarget, GetNumModulesFromEvent,
1410b57cec5SDimitry Andric                             (const lldb::SBEvent &), event);
1420b57cec5SDimitry Andric 
1430b57cec5SDimitry Andric   const ModuleList module_list =
1440b57cec5SDimitry Andric       Target::TargetEventData::GetModuleListFromEvent(event.get());
1450b57cec5SDimitry Andric   return module_list.GetSize();
1460b57cec5SDimitry Andric }
1470b57cec5SDimitry Andric 
GetModuleAtIndexFromEvent(const uint32_t idx,const SBEvent & event)1480b57cec5SDimitry Andric SBModule SBTarget::GetModuleAtIndexFromEvent(const uint32_t idx,
1490b57cec5SDimitry Andric                                              const SBEvent &event) {
1500b57cec5SDimitry Andric   LLDB_RECORD_STATIC_METHOD(lldb::SBModule, SBTarget, GetModuleAtIndexFromEvent,
1510b57cec5SDimitry Andric                             (const uint32_t, const lldb::SBEvent &), idx,
1520b57cec5SDimitry Andric                             event);
1530b57cec5SDimitry Andric 
1540b57cec5SDimitry Andric   const ModuleList module_list =
1550b57cec5SDimitry Andric       Target::TargetEventData::GetModuleListFromEvent(event.get());
1560b57cec5SDimitry Andric   return LLDB_RECORD_RESULT(SBModule(module_list.GetModuleAtIndex(idx)));
1570b57cec5SDimitry Andric }
1580b57cec5SDimitry Andric 
GetBroadcasterClassName()1590b57cec5SDimitry Andric const char *SBTarget::GetBroadcasterClassName() {
1600b57cec5SDimitry Andric   LLDB_RECORD_STATIC_METHOD_NO_ARGS(const char *, SBTarget,
1610b57cec5SDimitry Andric                                     GetBroadcasterClassName);
1620b57cec5SDimitry Andric 
1630b57cec5SDimitry Andric   return Target::GetStaticBroadcasterClass().AsCString();
1640b57cec5SDimitry Andric }
1650b57cec5SDimitry Andric 
IsValid() const1660b57cec5SDimitry Andric bool SBTarget::IsValid() const {
1670b57cec5SDimitry Andric   LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBTarget, IsValid);
1680b57cec5SDimitry Andric   return this->operator bool();
1690b57cec5SDimitry Andric }
operator bool() const1700b57cec5SDimitry Andric SBTarget::operator bool() const {
1710b57cec5SDimitry Andric   LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBTarget, operator bool);
1720b57cec5SDimitry Andric 
1730b57cec5SDimitry Andric   return m_opaque_sp.get() != nullptr && m_opaque_sp->IsValid();
1740b57cec5SDimitry Andric }
1750b57cec5SDimitry Andric 
GetProcess()1760b57cec5SDimitry Andric SBProcess SBTarget::GetProcess() {
1770b57cec5SDimitry Andric   LLDB_RECORD_METHOD_NO_ARGS(lldb::SBProcess, SBTarget, GetProcess);
1780b57cec5SDimitry Andric 
1790b57cec5SDimitry Andric   SBProcess sb_process;
1800b57cec5SDimitry Andric   ProcessSP process_sp;
1810b57cec5SDimitry Andric   TargetSP target_sp(GetSP());
1820b57cec5SDimitry Andric   if (target_sp) {
1830b57cec5SDimitry Andric     process_sp = target_sp->GetProcessSP();
1840b57cec5SDimitry Andric     sb_process.SetSP(process_sp);
1850b57cec5SDimitry Andric   }
1860b57cec5SDimitry Andric 
1870b57cec5SDimitry Andric   return LLDB_RECORD_RESULT(sb_process);
1880b57cec5SDimitry Andric }
1890b57cec5SDimitry Andric 
GetPlatform()1900b57cec5SDimitry Andric SBPlatform SBTarget::GetPlatform() {
1910b57cec5SDimitry Andric   LLDB_RECORD_METHOD_NO_ARGS(lldb::SBPlatform, SBTarget, GetPlatform);
1920b57cec5SDimitry Andric 
1930b57cec5SDimitry Andric   TargetSP target_sp(GetSP());
1940b57cec5SDimitry Andric   if (!target_sp)
1950b57cec5SDimitry Andric     return LLDB_RECORD_RESULT(SBPlatform());
1960b57cec5SDimitry Andric 
1970b57cec5SDimitry Andric   SBPlatform platform;
1980b57cec5SDimitry Andric   platform.m_opaque_sp = target_sp->GetPlatform();
1990b57cec5SDimitry Andric 
2000b57cec5SDimitry Andric   return LLDB_RECORD_RESULT(platform);
2010b57cec5SDimitry Andric }
2020b57cec5SDimitry Andric 
GetDebugger() const2030b57cec5SDimitry Andric SBDebugger SBTarget::GetDebugger() const {
2040b57cec5SDimitry Andric   LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::SBDebugger, SBTarget, GetDebugger);
2050b57cec5SDimitry Andric 
2060b57cec5SDimitry Andric   SBDebugger debugger;
2070b57cec5SDimitry Andric   TargetSP target_sp(GetSP());
2080b57cec5SDimitry Andric   if (target_sp)
2090b57cec5SDimitry Andric     debugger.reset(target_sp->GetDebugger().shared_from_this());
2100b57cec5SDimitry Andric   return LLDB_RECORD_RESULT(debugger);
2110b57cec5SDimitry Andric }
2120b57cec5SDimitry Andric 
GetStatistics()2130b57cec5SDimitry Andric SBStructuredData SBTarget::GetStatistics() {
2140b57cec5SDimitry Andric   LLDB_RECORD_METHOD_NO_ARGS(lldb::SBStructuredData, SBTarget, GetStatistics);
2150b57cec5SDimitry Andric 
2160b57cec5SDimitry Andric   SBStructuredData data;
2170b57cec5SDimitry Andric   TargetSP target_sp(GetSP());
2180b57cec5SDimitry Andric   if (!target_sp)
2190b57cec5SDimitry Andric     return LLDB_RECORD_RESULT(data);
2200b57cec5SDimitry Andric 
2219dba64beSDimitry Andric   auto stats_up = std::make_unique<StructuredData::Dictionary>();
2220b57cec5SDimitry Andric   int i = 0;
2230b57cec5SDimitry Andric   for (auto &Entry : target_sp->GetStatistics()) {
2240b57cec5SDimitry Andric     std::string Desc = lldb_private::GetStatDescription(
2250b57cec5SDimitry Andric         static_cast<lldb_private::StatisticKind>(i));
2260b57cec5SDimitry Andric     stats_up->AddIntegerItem(Desc, Entry);
2270b57cec5SDimitry Andric     i += 1;
2280b57cec5SDimitry Andric   }
2290b57cec5SDimitry Andric 
2300b57cec5SDimitry Andric   data.m_impl_up->SetObjectSP(std::move(stats_up));
2310b57cec5SDimitry Andric   return LLDB_RECORD_RESULT(data);
2320b57cec5SDimitry Andric }
2330b57cec5SDimitry Andric 
SetCollectingStats(bool v)2340b57cec5SDimitry Andric void SBTarget::SetCollectingStats(bool v) {
2350b57cec5SDimitry Andric   LLDB_RECORD_METHOD(void, SBTarget, SetCollectingStats, (bool), v);
2360b57cec5SDimitry Andric 
2370b57cec5SDimitry Andric   TargetSP target_sp(GetSP());
2380b57cec5SDimitry Andric   if (!target_sp)
2390b57cec5SDimitry Andric     return;
2400b57cec5SDimitry Andric   return target_sp->SetCollectingStats(v);
2410b57cec5SDimitry Andric }
2420b57cec5SDimitry Andric 
GetCollectingStats()2430b57cec5SDimitry Andric bool SBTarget::GetCollectingStats() {
2440b57cec5SDimitry Andric   LLDB_RECORD_METHOD_NO_ARGS(bool, SBTarget, GetCollectingStats);
2450b57cec5SDimitry Andric 
2460b57cec5SDimitry Andric   TargetSP target_sp(GetSP());
2470b57cec5SDimitry Andric   if (!target_sp)
2480b57cec5SDimitry Andric     return false;
2490b57cec5SDimitry Andric   return target_sp->GetCollectingStats();
2500b57cec5SDimitry Andric }
2510b57cec5SDimitry Andric 
LoadCore(const char * core_file)2520b57cec5SDimitry Andric SBProcess SBTarget::LoadCore(const char *core_file) {
2530b57cec5SDimitry Andric   LLDB_RECORD_METHOD(lldb::SBProcess, SBTarget, LoadCore, (const char *),
2540b57cec5SDimitry Andric                      core_file);
2550b57cec5SDimitry Andric 
2560b57cec5SDimitry Andric   lldb::SBError error; // Ignored
2570b57cec5SDimitry Andric   return LLDB_RECORD_RESULT(LoadCore(core_file, error));
2580b57cec5SDimitry Andric }
2590b57cec5SDimitry Andric 
LoadCore(const char * core_file,lldb::SBError & error)2600b57cec5SDimitry Andric SBProcess SBTarget::LoadCore(const char *core_file, lldb::SBError &error) {
2610b57cec5SDimitry Andric   LLDB_RECORD_METHOD(lldb::SBProcess, SBTarget, LoadCore,
2620b57cec5SDimitry Andric                      (const char *, lldb::SBError &), core_file, error);
2630b57cec5SDimitry Andric 
2640b57cec5SDimitry Andric   SBProcess sb_process;
2650b57cec5SDimitry Andric   TargetSP target_sp(GetSP());
2660b57cec5SDimitry Andric   if (target_sp) {
2670b57cec5SDimitry Andric     FileSpec filespec(core_file);
2680b57cec5SDimitry Andric     FileSystem::Instance().Resolve(filespec);
2690b57cec5SDimitry Andric     ProcessSP process_sp(target_sp->CreateProcess(
270af732203SDimitry Andric         target_sp->GetDebugger().GetListener(), "", &filespec, false));
2710b57cec5SDimitry Andric     if (process_sp) {
2720b57cec5SDimitry Andric       error.SetError(process_sp->LoadCore());
2730b57cec5SDimitry Andric       if (error.Success())
2740b57cec5SDimitry Andric         sb_process.SetSP(process_sp);
2750b57cec5SDimitry Andric     } else {
2760b57cec5SDimitry Andric       error.SetErrorString("Failed to create the process");
2770b57cec5SDimitry Andric     }
2780b57cec5SDimitry Andric   } else {
2790b57cec5SDimitry Andric     error.SetErrorString("SBTarget is invalid");
2800b57cec5SDimitry Andric   }
2810b57cec5SDimitry Andric   return LLDB_RECORD_RESULT(sb_process);
2820b57cec5SDimitry Andric }
2830b57cec5SDimitry Andric 
LaunchSimple(char const ** argv,char const ** envp,const char * working_directory)2840b57cec5SDimitry Andric SBProcess SBTarget::LaunchSimple(char const **argv, char const **envp,
2850b57cec5SDimitry Andric                                  const char *working_directory) {
2860b57cec5SDimitry Andric   LLDB_RECORD_METHOD(lldb::SBProcess, SBTarget, LaunchSimple,
2870b57cec5SDimitry Andric                      (const char **, const char **, const char *), argv, envp,
2880b57cec5SDimitry Andric                      working_directory);
2890b57cec5SDimitry Andric 
290af732203SDimitry Andric   TargetSP target_sp = GetSP();
291af732203SDimitry Andric   if (!target_sp)
292af732203SDimitry Andric     return LLDB_RECORD_RESULT(SBProcess());
293af732203SDimitry Andric 
294af732203SDimitry Andric   SBLaunchInfo launch_info = GetLaunchInfo();
295af732203SDimitry Andric 
296af732203SDimitry Andric   if (Module *exe_module = target_sp->GetExecutableModulePointer())
297af732203SDimitry Andric     launch_info.SetExecutableFile(exe_module->GetPlatformFileSpec(),
298af732203SDimitry Andric                                   /*add_as_first_arg*/ true);
299af732203SDimitry Andric   if (argv)
300af732203SDimitry Andric     launch_info.SetArguments(argv, /*append*/ true);
301af732203SDimitry Andric   if (envp)
302af732203SDimitry Andric     launch_info.SetEnvironmentEntries(envp, /*append*/ false);
303af732203SDimitry Andric   if (working_directory)
304af732203SDimitry Andric     launch_info.SetWorkingDirectory(working_directory);
305af732203SDimitry Andric 
3060b57cec5SDimitry Andric   SBError error;
307af732203SDimitry Andric   return LLDB_RECORD_RESULT(Launch(launch_info, error));
3080b57cec5SDimitry Andric }
3090b57cec5SDimitry Andric 
Install()3100b57cec5SDimitry Andric SBError SBTarget::Install() {
3110b57cec5SDimitry Andric   LLDB_RECORD_METHOD_NO_ARGS(lldb::SBError, SBTarget, Install);
3120b57cec5SDimitry Andric 
3130b57cec5SDimitry Andric   SBError sb_error;
3140b57cec5SDimitry Andric   TargetSP target_sp(GetSP());
3150b57cec5SDimitry Andric   if (target_sp) {
3160b57cec5SDimitry Andric     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
3170b57cec5SDimitry Andric     sb_error.ref() = target_sp->Install(nullptr);
3180b57cec5SDimitry Andric   }
3190b57cec5SDimitry Andric   return LLDB_RECORD_RESULT(sb_error);
3200b57cec5SDimitry Andric }
3210b57cec5SDimitry Andric 
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)3220b57cec5SDimitry Andric SBProcess SBTarget::Launch(SBListener &listener, char const **argv,
3230b57cec5SDimitry Andric                            char const **envp, const char *stdin_path,
3240b57cec5SDimitry Andric                            const char *stdout_path, const char *stderr_path,
3250b57cec5SDimitry Andric                            const char *working_directory,
3260b57cec5SDimitry Andric                            uint32_t launch_flags, // See LaunchFlags
3270b57cec5SDimitry Andric                            bool stop_at_entry, lldb::SBError &error) {
3280b57cec5SDimitry Andric   LLDB_RECORD_METHOD(lldb::SBProcess, SBTarget, Launch,
3290b57cec5SDimitry Andric                      (lldb::SBListener &, const char **, const char **,
3300b57cec5SDimitry Andric                       const char *, const char *, const char *, const char *,
3310b57cec5SDimitry Andric                       uint32_t, bool, lldb::SBError &),
3320b57cec5SDimitry Andric                      listener, argv, envp, stdin_path, stdout_path, stderr_path,
3330b57cec5SDimitry Andric                      working_directory, launch_flags, stop_at_entry, error);
3340b57cec5SDimitry Andric 
3350b57cec5SDimitry Andric   SBProcess sb_process;
3360b57cec5SDimitry Andric   ProcessSP process_sp;
3370b57cec5SDimitry Andric   TargetSP target_sp(GetSP());
3380b57cec5SDimitry Andric 
3390b57cec5SDimitry Andric   if (target_sp) {
3400b57cec5SDimitry Andric     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
3410b57cec5SDimitry Andric 
3420b57cec5SDimitry Andric     if (stop_at_entry)
3430b57cec5SDimitry Andric       launch_flags |= eLaunchFlagStopAtEntry;
3440b57cec5SDimitry Andric 
3450b57cec5SDimitry Andric     if (getenv("LLDB_LAUNCH_FLAG_DISABLE_ASLR"))
3460b57cec5SDimitry Andric       launch_flags |= eLaunchFlagDisableASLR;
3470b57cec5SDimitry Andric 
3480b57cec5SDimitry Andric     StateType state = eStateInvalid;
3490b57cec5SDimitry Andric     process_sp = target_sp->GetProcessSP();
3500b57cec5SDimitry Andric     if (process_sp) {
3510b57cec5SDimitry Andric       state = process_sp->GetState();
3520b57cec5SDimitry Andric 
3530b57cec5SDimitry Andric       if (process_sp->IsAlive() && state != eStateConnected) {
3540b57cec5SDimitry Andric         if (state == eStateAttaching)
3550b57cec5SDimitry Andric           error.SetErrorString("process attach is in progress");
3560b57cec5SDimitry Andric         else
3570b57cec5SDimitry Andric           error.SetErrorString("a process is already being debugged");
3580b57cec5SDimitry Andric         return LLDB_RECORD_RESULT(sb_process);
3590b57cec5SDimitry Andric       }
3600b57cec5SDimitry Andric     }
3610b57cec5SDimitry Andric 
3620b57cec5SDimitry Andric     if (state == eStateConnected) {
3630b57cec5SDimitry Andric       // If we are already connected, then we have already specified the
3640b57cec5SDimitry Andric       // listener, so if a valid listener is supplied, we need to error out to
3650b57cec5SDimitry Andric       // let the client know.
3660b57cec5SDimitry Andric       if (listener.IsValid()) {
3670b57cec5SDimitry Andric         error.SetErrorString("process is connected and already has a listener, "
3680b57cec5SDimitry Andric                              "pass empty listener");
3690b57cec5SDimitry Andric         return LLDB_RECORD_RESULT(sb_process);
3700b57cec5SDimitry Andric       }
3710b57cec5SDimitry Andric     }
3720b57cec5SDimitry Andric 
3730b57cec5SDimitry Andric     if (getenv("LLDB_LAUNCH_FLAG_DISABLE_STDIO"))
3740b57cec5SDimitry Andric       launch_flags |= eLaunchFlagDisableSTDIO;
3750b57cec5SDimitry Andric 
3760b57cec5SDimitry Andric     ProcessLaunchInfo launch_info(FileSpec(stdin_path), FileSpec(stdout_path),
3770b57cec5SDimitry Andric                                   FileSpec(stderr_path),
3780b57cec5SDimitry Andric                                   FileSpec(working_directory), launch_flags);
3790b57cec5SDimitry Andric 
3800b57cec5SDimitry Andric     Module *exe_module = target_sp->GetExecutableModulePointer();
3810b57cec5SDimitry Andric     if (exe_module)
3820b57cec5SDimitry Andric       launch_info.SetExecutableFile(exe_module->GetPlatformFileSpec(), true);
3835ffd83dbSDimitry Andric     if (argv) {
3840b57cec5SDimitry Andric       launch_info.GetArguments().AppendArguments(argv);
3855ffd83dbSDimitry Andric     } else {
3865ffd83dbSDimitry Andric       auto default_launch_info = target_sp->GetProcessLaunchInfo();
3875ffd83dbSDimitry Andric       launch_info.GetArguments().AppendArguments(
3885ffd83dbSDimitry Andric           default_launch_info.GetArguments());
3895ffd83dbSDimitry Andric     }
3905ffd83dbSDimitry Andric     if (envp) {
3910b57cec5SDimitry Andric       launch_info.GetEnvironment() = Environment(envp);
3925ffd83dbSDimitry Andric     } else {
3935ffd83dbSDimitry Andric       auto default_launch_info = target_sp->GetProcessLaunchInfo();
3945ffd83dbSDimitry Andric       launch_info.GetEnvironment() = default_launch_info.GetEnvironment();
3955ffd83dbSDimitry Andric     }
3960b57cec5SDimitry Andric 
3970b57cec5SDimitry Andric     if (listener.IsValid())
3980b57cec5SDimitry Andric       launch_info.SetListener(listener.GetSP());
3990b57cec5SDimitry Andric 
4000b57cec5SDimitry Andric     error.SetError(target_sp->Launch(launch_info, nullptr));
4010b57cec5SDimitry Andric 
4020b57cec5SDimitry Andric     sb_process.SetSP(target_sp->GetProcessSP());
4030b57cec5SDimitry Andric   } else {
4040b57cec5SDimitry Andric     error.SetErrorString("SBTarget is invalid");
4050b57cec5SDimitry Andric   }
4060b57cec5SDimitry Andric 
4070b57cec5SDimitry Andric   return LLDB_RECORD_RESULT(sb_process);
4080b57cec5SDimitry Andric }
4090b57cec5SDimitry Andric 
Launch(SBLaunchInfo & sb_launch_info,SBError & error)4100b57cec5SDimitry Andric SBProcess SBTarget::Launch(SBLaunchInfo &sb_launch_info, SBError &error) {
4110b57cec5SDimitry Andric   LLDB_RECORD_METHOD(lldb::SBProcess, SBTarget, Launch,
4120b57cec5SDimitry Andric                      (lldb::SBLaunchInfo &, lldb::SBError &), sb_launch_info,
4130b57cec5SDimitry Andric                      error);
4140b57cec5SDimitry Andric 
4150b57cec5SDimitry Andric 
4160b57cec5SDimitry Andric   SBProcess sb_process;
4170b57cec5SDimitry Andric   TargetSP target_sp(GetSP());
4180b57cec5SDimitry Andric 
4190b57cec5SDimitry Andric   if (target_sp) {
4200b57cec5SDimitry Andric     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
4210b57cec5SDimitry Andric     StateType state = eStateInvalid;
4220b57cec5SDimitry Andric     {
4230b57cec5SDimitry Andric       ProcessSP process_sp = target_sp->GetProcessSP();
4240b57cec5SDimitry Andric       if (process_sp) {
4250b57cec5SDimitry Andric         state = process_sp->GetState();
4260b57cec5SDimitry Andric 
4270b57cec5SDimitry Andric         if (process_sp->IsAlive() && state != eStateConnected) {
4280b57cec5SDimitry Andric           if (state == eStateAttaching)
4290b57cec5SDimitry Andric             error.SetErrorString("process attach is in progress");
4300b57cec5SDimitry Andric           else
4310b57cec5SDimitry Andric             error.SetErrorString("a process is already being debugged");
4320b57cec5SDimitry Andric           return LLDB_RECORD_RESULT(sb_process);
4330b57cec5SDimitry Andric         }
4340b57cec5SDimitry Andric       }
4350b57cec5SDimitry Andric     }
4360b57cec5SDimitry Andric 
4370b57cec5SDimitry Andric     lldb_private::ProcessLaunchInfo launch_info = sb_launch_info.ref();
4380b57cec5SDimitry Andric 
4390b57cec5SDimitry Andric     if (!launch_info.GetExecutableFile()) {
4400b57cec5SDimitry Andric       Module *exe_module = target_sp->GetExecutableModulePointer();
4410b57cec5SDimitry Andric       if (exe_module)
4420b57cec5SDimitry Andric         launch_info.SetExecutableFile(exe_module->GetPlatformFileSpec(), true);
4430b57cec5SDimitry Andric     }
4440b57cec5SDimitry Andric 
4450b57cec5SDimitry Andric     const ArchSpec &arch_spec = target_sp->GetArchitecture();
4460b57cec5SDimitry Andric     if (arch_spec.IsValid())
4470b57cec5SDimitry Andric       launch_info.GetArchitecture() = arch_spec;
4480b57cec5SDimitry Andric 
4490b57cec5SDimitry Andric     error.SetError(target_sp->Launch(launch_info, nullptr));
4500b57cec5SDimitry Andric     sb_launch_info.set_ref(launch_info);
4510b57cec5SDimitry Andric     sb_process.SetSP(target_sp->GetProcessSP());
4520b57cec5SDimitry Andric   } else {
4530b57cec5SDimitry Andric     error.SetErrorString("SBTarget is invalid");
4540b57cec5SDimitry Andric   }
4550b57cec5SDimitry Andric 
4560b57cec5SDimitry Andric   return LLDB_RECORD_RESULT(sb_process);
4570b57cec5SDimitry Andric }
4580b57cec5SDimitry Andric 
Attach(SBAttachInfo & sb_attach_info,SBError & error)4590b57cec5SDimitry Andric lldb::SBProcess SBTarget::Attach(SBAttachInfo &sb_attach_info, SBError &error) {
4600b57cec5SDimitry Andric   LLDB_RECORD_METHOD(lldb::SBProcess, SBTarget, Attach,
4610b57cec5SDimitry Andric                      (lldb::SBAttachInfo &, lldb::SBError &), sb_attach_info,
4620b57cec5SDimitry Andric                      error);
4630b57cec5SDimitry Andric 
4640b57cec5SDimitry Andric   SBProcess sb_process;
4650b57cec5SDimitry Andric   TargetSP target_sp(GetSP());
4660b57cec5SDimitry Andric 
4670b57cec5SDimitry Andric   if (target_sp) {
4680b57cec5SDimitry Andric     ProcessAttachInfo &attach_info = sb_attach_info.ref();
4690b57cec5SDimitry Andric     if (attach_info.ProcessIDIsValid() && !attach_info.UserIDIsValid()) {
4700b57cec5SDimitry Andric       PlatformSP platform_sp = target_sp->GetPlatform();
4710b57cec5SDimitry Andric       // See if we can pre-verify if a process exists or not
4720b57cec5SDimitry Andric       if (platform_sp && platform_sp->IsConnected()) {
4730b57cec5SDimitry Andric         lldb::pid_t attach_pid = attach_info.GetProcessID();
4740b57cec5SDimitry Andric         ProcessInstanceInfo instance_info;
4750b57cec5SDimitry Andric         if (platform_sp->GetProcessInfo(attach_pid, instance_info)) {
4760b57cec5SDimitry Andric           attach_info.SetUserID(instance_info.GetEffectiveUserID());
4770b57cec5SDimitry Andric         } else {
4780b57cec5SDimitry Andric           error.ref().SetErrorStringWithFormat(
4790b57cec5SDimitry Andric               "no process found with process ID %" PRIu64, attach_pid);
4800b57cec5SDimitry Andric           return LLDB_RECORD_RESULT(sb_process);
4810b57cec5SDimitry Andric         }
4820b57cec5SDimitry Andric       }
4830b57cec5SDimitry Andric     }
4840b57cec5SDimitry Andric     error.SetError(AttachToProcess(attach_info, *target_sp));
4850b57cec5SDimitry Andric     if (error.Success())
4860b57cec5SDimitry Andric       sb_process.SetSP(target_sp->GetProcessSP());
4870b57cec5SDimitry Andric   } else {
4880b57cec5SDimitry Andric     error.SetErrorString("SBTarget is invalid");
4890b57cec5SDimitry Andric   }
4900b57cec5SDimitry Andric 
4910b57cec5SDimitry Andric   return LLDB_RECORD_RESULT(sb_process);
4920b57cec5SDimitry Andric }
4930b57cec5SDimitry Andric 
AttachToProcessWithID(SBListener & listener,lldb::pid_t pid,SBError & error)4940b57cec5SDimitry Andric lldb::SBProcess SBTarget::AttachToProcessWithID(
4950b57cec5SDimitry Andric     SBListener &listener,
4960b57cec5SDimitry Andric     lldb::pid_t pid, // The process ID to attach to
4970b57cec5SDimitry Andric     SBError &error   // An error explaining what went wrong if attach fails
4980b57cec5SDimitry Andric ) {
4990b57cec5SDimitry Andric   LLDB_RECORD_METHOD(lldb::SBProcess, SBTarget, AttachToProcessWithID,
5000b57cec5SDimitry Andric                      (lldb::SBListener &, lldb::pid_t, lldb::SBError &),
5010b57cec5SDimitry Andric                      listener, pid, error);
5020b57cec5SDimitry Andric 
5030b57cec5SDimitry Andric   SBProcess sb_process;
5040b57cec5SDimitry Andric   TargetSP target_sp(GetSP());
5050b57cec5SDimitry Andric 
5060b57cec5SDimitry Andric   if (target_sp) {
5070b57cec5SDimitry Andric     ProcessAttachInfo attach_info;
5080b57cec5SDimitry Andric     attach_info.SetProcessID(pid);
5090b57cec5SDimitry Andric     if (listener.IsValid())
5100b57cec5SDimitry Andric       attach_info.SetListener(listener.GetSP());
5110b57cec5SDimitry Andric 
5120b57cec5SDimitry Andric     ProcessInstanceInfo instance_info;
5130b57cec5SDimitry Andric     if (target_sp->GetPlatform()->GetProcessInfo(pid, instance_info))
5140b57cec5SDimitry Andric       attach_info.SetUserID(instance_info.GetEffectiveUserID());
5150b57cec5SDimitry Andric 
5160b57cec5SDimitry Andric     error.SetError(AttachToProcess(attach_info, *target_sp));
5170b57cec5SDimitry Andric     if (error.Success())
5180b57cec5SDimitry Andric       sb_process.SetSP(target_sp->GetProcessSP());
5190b57cec5SDimitry Andric   } else
5200b57cec5SDimitry Andric     error.SetErrorString("SBTarget is invalid");
5210b57cec5SDimitry Andric 
5220b57cec5SDimitry Andric   return LLDB_RECORD_RESULT(sb_process);
5230b57cec5SDimitry Andric }
5240b57cec5SDimitry Andric 
AttachToProcessWithName(SBListener & listener,const char * name,bool wait_for,SBError & error)5250b57cec5SDimitry Andric lldb::SBProcess SBTarget::AttachToProcessWithName(
5260b57cec5SDimitry Andric     SBListener &listener,
5270b57cec5SDimitry Andric     const char *name, // basename of process to attach to
5280b57cec5SDimitry Andric     bool wait_for, // if true wait for a new instance of "name" to be launched
5290b57cec5SDimitry Andric     SBError &error // An error explaining what went wrong if attach fails
5300b57cec5SDimitry Andric ) {
5310b57cec5SDimitry Andric   LLDB_RECORD_METHOD(lldb::SBProcess, SBTarget, AttachToProcessWithName,
5320b57cec5SDimitry Andric                      (lldb::SBListener &, const char *, bool, lldb::SBError &),
5330b57cec5SDimitry Andric                      listener, name, wait_for, error);
5340b57cec5SDimitry Andric 
5350b57cec5SDimitry Andric   SBProcess sb_process;
5360b57cec5SDimitry Andric   TargetSP target_sp(GetSP());
5370b57cec5SDimitry Andric 
5380b57cec5SDimitry Andric   if (name && target_sp) {
5390b57cec5SDimitry Andric     ProcessAttachInfo attach_info;
5400b57cec5SDimitry Andric     attach_info.GetExecutableFile().SetFile(name, FileSpec::Style::native);
5410b57cec5SDimitry Andric     attach_info.SetWaitForLaunch(wait_for);
5420b57cec5SDimitry Andric     if (listener.IsValid())
5430b57cec5SDimitry Andric       attach_info.SetListener(listener.GetSP());
5440b57cec5SDimitry Andric 
5450b57cec5SDimitry Andric     error.SetError(AttachToProcess(attach_info, *target_sp));
5460b57cec5SDimitry Andric     if (error.Success())
5470b57cec5SDimitry Andric       sb_process.SetSP(target_sp->GetProcessSP());
5480b57cec5SDimitry Andric   } else
5490b57cec5SDimitry Andric     error.SetErrorString("SBTarget is invalid");
5500b57cec5SDimitry Andric 
5510b57cec5SDimitry Andric   return LLDB_RECORD_RESULT(sb_process);
5520b57cec5SDimitry Andric }
5530b57cec5SDimitry Andric 
ConnectRemote(SBListener & listener,const char * url,const char * plugin_name,SBError & error)5540b57cec5SDimitry Andric lldb::SBProcess SBTarget::ConnectRemote(SBListener &listener, const char *url,
5550b57cec5SDimitry Andric                                         const char *plugin_name,
5560b57cec5SDimitry Andric                                         SBError &error) {
5570b57cec5SDimitry Andric   LLDB_RECORD_METHOD(
5580b57cec5SDimitry Andric       lldb::SBProcess, SBTarget, ConnectRemote,
5590b57cec5SDimitry Andric       (lldb::SBListener &, const char *, const char *, lldb::SBError &),
5600b57cec5SDimitry Andric       listener, url, plugin_name, error);
5610b57cec5SDimitry Andric 
5620b57cec5SDimitry Andric   SBProcess sb_process;
5630b57cec5SDimitry Andric   ProcessSP process_sp;
5640b57cec5SDimitry Andric   TargetSP target_sp(GetSP());
5650b57cec5SDimitry Andric 
5660b57cec5SDimitry Andric   if (target_sp) {
5670b57cec5SDimitry Andric     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
5680b57cec5SDimitry Andric     if (listener.IsValid())
5690b57cec5SDimitry Andric       process_sp =
570af732203SDimitry Andric           target_sp->CreateProcess(listener.m_opaque_sp, plugin_name, nullptr,
571af732203SDimitry Andric                                    true);
5720b57cec5SDimitry Andric     else
5730b57cec5SDimitry Andric       process_sp = target_sp->CreateProcess(
574af732203SDimitry Andric           target_sp->GetDebugger().GetListener(), plugin_name, nullptr, true);
5750b57cec5SDimitry Andric 
5760b57cec5SDimitry Andric     if (process_sp) {
5770b57cec5SDimitry Andric       sb_process.SetSP(process_sp);
5785ffd83dbSDimitry Andric       error.SetError(process_sp->ConnectRemote(url));
5790b57cec5SDimitry Andric     } else {
5800b57cec5SDimitry Andric       error.SetErrorString("unable to create lldb_private::Process");
5810b57cec5SDimitry Andric     }
5820b57cec5SDimitry Andric   } else {
5830b57cec5SDimitry Andric     error.SetErrorString("SBTarget is invalid");
5840b57cec5SDimitry Andric   }
5850b57cec5SDimitry Andric 
5860b57cec5SDimitry Andric   return LLDB_RECORD_RESULT(sb_process);
5870b57cec5SDimitry Andric }
5880b57cec5SDimitry Andric 
GetExecutable()5890b57cec5SDimitry Andric SBFileSpec SBTarget::GetExecutable() {
5900b57cec5SDimitry Andric   LLDB_RECORD_METHOD_NO_ARGS(lldb::SBFileSpec, SBTarget, GetExecutable);
5910b57cec5SDimitry Andric 
5920b57cec5SDimitry Andric   SBFileSpec exe_file_spec;
5930b57cec5SDimitry Andric   TargetSP target_sp(GetSP());
5940b57cec5SDimitry Andric   if (target_sp) {
5950b57cec5SDimitry Andric     Module *exe_module = target_sp->GetExecutableModulePointer();
5960b57cec5SDimitry Andric     if (exe_module)
5970b57cec5SDimitry Andric       exe_file_spec.SetFileSpec(exe_module->GetFileSpec());
5980b57cec5SDimitry Andric   }
5990b57cec5SDimitry Andric 
6000b57cec5SDimitry Andric   return LLDB_RECORD_RESULT(exe_file_spec);
6010b57cec5SDimitry Andric }
6020b57cec5SDimitry Andric 
operator ==(const SBTarget & rhs) const6030b57cec5SDimitry Andric bool SBTarget::operator==(const SBTarget &rhs) const {
6040b57cec5SDimitry Andric   LLDB_RECORD_METHOD_CONST(bool, SBTarget, operator==,(const lldb::SBTarget &),
6050b57cec5SDimitry Andric                            rhs);
6060b57cec5SDimitry Andric 
6070b57cec5SDimitry Andric   return m_opaque_sp.get() == rhs.m_opaque_sp.get();
6080b57cec5SDimitry Andric }
6090b57cec5SDimitry Andric 
operator !=(const SBTarget & rhs) const6100b57cec5SDimitry Andric bool SBTarget::operator!=(const SBTarget &rhs) const {
6110b57cec5SDimitry Andric   LLDB_RECORD_METHOD_CONST(bool, SBTarget, operator!=,(const lldb::SBTarget &),
6120b57cec5SDimitry Andric                            rhs);
6130b57cec5SDimitry Andric 
6140b57cec5SDimitry Andric   return m_opaque_sp.get() != rhs.m_opaque_sp.get();
6150b57cec5SDimitry Andric }
6160b57cec5SDimitry Andric 
GetSP() const6170b57cec5SDimitry Andric lldb::TargetSP SBTarget::GetSP() const { return m_opaque_sp; }
6180b57cec5SDimitry Andric 
SetSP(const lldb::TargetSP & target_sp)6190b57cec5SDimitry Andric void SBTarget::SetSP(const lldb::TargetSP &target_sp) {
6200b57cec5SDimitry Andric   m_opaque_sp = target_sp;
6210b57cec5SDimitry Andric }
6220b57cec5SDimitry Andric 
ResolveLoadAddress(lldb::addr_t vm_addr)6230b57cec5SDimitry Andric lldb::SBAddress SBTarget::ResolveLoadAddress(lldb::addr_t vm_addr) {
6240b57cec5SDimitry Andric   LLDB_RECORD_METHOD(lldb::SBAddress, SBTarget, ResolveLoadAddress,
6250b57cec5SDimitry Andric                      (lldb::addr_t), vm_addr);
6260b57cec5SDimitry Andric 
6270b57cec5SDimitry Andric   lldb::SBAddress sb_addr;
6280b57cec5SDimitry Andric   Address &addr = sb_addr.ref();
6290b57cec5SDimitry Andric   TargetSP target_sp(GetSP());
6300b57cec5SDimitry Andric   if (target_sp) {
6310b57cec5SDimitry Andric     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
6320b57cec5SDimitry Andric     if (target_sp->ResolveLoadAddress(vm_addr, addr))
6330b57cec5SDimitry Andric       return LLDB_RECORD_RESULT(sb_addr);
6340b57cec5SDimitry Andric   }
6350b57cec5SDimitry Andric 
6360b57cec5SDimitry Andric   // We have a load address that isn't in a section, just return an address
6370b57cec5SDimitry Andric   // with the offset filled in (the address) and the section set to NULL
6380b57cec5SDimitry Andric   addr.SetRawAddress(vm_addr);
6390b57cec5SDimitry Andric   return LLDB_RECORD_RESULT(sb_addr);
6400b57cec5SDimitry Andric }
6410b57cec5SDimitry Andric 
ResolveFileAddress(lldb::addr_t file_addr)6420b57cec5SDimitry Andric lldb::SBAddress SBTarget::ResolveFileAddress(lldb::addr_t file_addr) {
6430b57cec5SDimitry Andric   LLDB_RECORD_METHOD(lldb::SBAddress, SBTarget, ResolveFileAddress,
6440b57cec5SDimitry Andric                      (lldb::addr_t), file_addr);
6450b57cec5SDimitry Andric 
6460b57cec5SDimitry Andric   lldb::SBAddress sb_addr;
6470b57cec5SDimitry Andric   Address &addr = sb_addr.ref();
6480b57cec5SDimitry Andric   TargetSP target_sp(GetSP());
6490b57cec5SDimitry Andric   if (target_sp) {
6500b57cec5SDimitry Andric     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
6510b57cec5SDimitry Andric     if (target_sp->ResolveFileAddress(file_addr, addr))
6520b57cec5SDimitry Andric       return LLDB_RECORD_RESULT(sb_addr);
6530b57cec5SDimitry Andric   }
6540b57cec5SDimitry Andric 
6550b57cec5SDimitry Andric   addr.SetRawAddress(file_addr);
6560b57cec5SDimitry Andric   return LLDB_RECORD_RESULT(sb_addr);
6570b57cec5SDimitry Andric }
6580b57cec5SDimitry Andric 
ResolvePastLoadAddress(uint32_t stop_id,lldb::addr_t vm_addr)6590b57cec5SDimitry Andric lldb::SBAddress SBTarget::ResolvePastLoadAddress(uint32_t stop_id,
6600b57cec5SDimitry Andric                                                  lldb::addr_t vm_addr) {
6610b57cec5SDimitry Andric   LLDB_RECORD_METHOD(lldb::SBAddress, SBTarget, ResolvePastLoadAddress,
6620b57cec5SDimitry Andric                      (uint32_t, lldb::addr_t), stop_id, vm_addr);
6630b57cec5SDimitry Andric 
6640b57cec5SDimitry Andric   lldb::SBAddress sb_addr;
6650b57cec5SDimitry Andric   Address &addr = sb_addr.ref();
6660b57cec5SDimitry Andric   TargetSP target_sp(GetSP());
6670b57cec5SDimitry Andric   if (target_sp) {
6680b57cec5SDimitry Andric     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
6690b57cec5SDimitry Andric     if (target_sp->ResolveLoadAddress(vm_addr, addr))
6700b57cec5SDimitry Andric       return LLDB_RECORD_RESULT(sb_addr);
6710b57cec5SDimitry Andric   }
6720b57cec5SDimitry Andric 
6730b57cec5SDimitry Andric   // We have a load address that isn't in a section, just return an address
6740b57cec5SDimitry Andric   // with the offset filled in (the address) and the section set to NULL
6750b57cec5SDimitry Andric   addr.SetRawAddress(vm_addr);
6760b57cec5SDimitry Andric   return LLDB_RECORD_RESULT(sb_addr);
6770b57cec5SDimitry Andric }
6780b57cec5SDimitry Andric 
6790b57cec5SDimitry Andric SBSymbolContext
ResolveSymbolContextForAddress(const SBAddress & addr,uint32_t resolve_scope)6800b57cec5SDimitry Andric SBTarget::ResolveSymbolContextForAddress(const SBAddress &addr,
6810b57cec5SDimitry Andric                                          uint32_t resolve_scope) {
6820b57cec5SDimitry Andric   LLDB_RECORD_METHOD(lldb::SBSymbolContext, SBTarget,
6830b57cec5SDimitry Andric                      ResolveSymbolContextForAddress,
6840b57cec5SDimitry Andric                      (const lldb::SBAddress &, uint32_t), addr, resolve_scope);
6850b57cec5SDimitry Andric 
6860b57cec5SDimitry Andric   SBSymbolContext sc;
6870b57cec5SDimitry Andric   SymbolContextItem scope = static_cast<SymbolContextItem>(resolve_scope);
6880b57cec5SDimitry Andric   if (addr.IsValid()) {
6890b57cec5SDimitry Andric     TargetSP target_sp(GetSP());
6900b57cec5SDimitry Andric     if (target_sp)
6910b57cec5SDimitry Andric       target_sp->GetImages().ResolveSymbolContextForAddress(addr.ref(), scope,
6920b57cec5SDimitry Andric                                                             sc.ref());
6930b57cec5SDimitry Andric   }
6940b57cec5SDimitry Andric   return LLDB_RECORD_RESULT(sc);
6950b57cec5SDimitry Andric }
6960b57cec5SDimitry Andric 
ReadMemory(const SBAddress addr,void * buf,size_t size,lldb::SBError & error)6970b57cec5SDimitry Andric size_t SBTarget::ReadMemory(const SBAddress addr, void *buf, size_t size,
6980b57cec5SDimitry Andric                             lldb::SBError &error) {
6995ffd83dbSDimitry Andric   LLDB_RECORD_METHOD(size_t, SBTarget, ReadMemory,
7000b57cec5SDimitry Andric                      (const lldb::SBAddress, void *, size_t, lldb::SBError &),
7010b57cec5SDimitry Andric                      addr, buf, size, error);
7020b57cec5SDimitry Andric 
7030b57cec5SDimitry Andric   SBError sb_error;
7040b57cec5SDimitry Andric   size_t bytes_read = 0;
7050b57cec5SDimitry Andric   TargetSP target_sp(GetSP());
7060b57cec5SDimitry Andric   if (target_sp) {
7070b57cec5SDimitry Andric     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
7080b57cec5SDimitry Andric     bytes_read =
709*5f7ddb14SDimitry Andric         target_sp->ReadMemory(addr.ref(), buf, size, sb_error.ref(), true);
7100b57cec5SDimitry Andric   } else {
7110b57cec5SDimitry Andric     sb_error.SetErrorString("invalid target");
7120b57cec5SDimitry Andric   }
7130b57cec5SDimitry Andric 
7140b57cec5SDimitry Andric   return bytes_read;
7150b57cec5SDimitry Andric }
7160b57cec5SDimitry Andric 
BreakpointCreateByLocation(const char * file,uint32_t line)7170b57cec5SDimitry Andric SBBreakpoint SBTarget::BreakpointCreateByLocation(const char *file,
7180b57cec5SDimitry Andric                                                   uint32_t line) {
7190b57cec5SDimitry Andric   LLDB_RECORD_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateByLocation,
7200b57cec5SDimitry Andric                      (const char *, uint32_t), file, line);
7210b57cec5SDimitry Andric 
7220b57cec5SDimitry Andric   return LLDB_RECORD_RESULT(
7230b57cec5SDimitry Andric       SBBreakpoint(BreakpointCreateByLocation(SBFileSpec(file, false), line)));
7240b57cec5SDimitry Andric }
7250b57cec5SDimitry Andric 
7260b57cec5SDimitry Andric SBBreakpoint
BreakpointCreateByLocation(const SBFileSpec & sb_file_spec,uint32_t line)7270b57cec5SDimitry Andric SBTarget::BreakpointCreateByLocation(const SBFileSpec &sb_file_spec,
7280b57cec5SDimitry Andric                                      uint32_t line) {
7290b57cec5SDimitry Andric   LLDB_RECORD_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateByLocation,
7300b57cec5SDimitry Andric                      (const lldb::SBFileSpec &, uint32_t), sb_file_spec, line);
7310b57cec5SDimitry Andric 
7320b57cec5SDimitry Andric   return LLDB_RECORD_RESULT(BreakpointCreateByLocation(sb_file_spec, line, 0));
7330b57cec5SDimitry Andric }
7340b57cec5SDimitry Andric 
7350b57cec5SDimitry Andric SBBreakpoint
BreakpointCreateByLocation(const SBFileSpec & sb_file_spec,uint32_t line,lldb::addr_t offset)7360b57cec5SDimitry Andric SBTarget::BreakpointCreateByLocation(const SBFileSpec &sb_file_spec,
7370b57cec5SDimitry Andric                                      uint32_t line, lldb::addr_t offset) {
7380b57cec5SDimitry Andric   LLDB_RECORD_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateByLocation,
7390b57cec5SDimitry Andric                      (const lldb::SBFileSpec &, uint32_t, lldb::addr_t),
7400b57cec5SDimitry Andric                      sb_file_spec, line, offset);
7410b57cec5SDimitry Andric 
7420b57cec5SDimitry Andric   SBFileSpecList empty_list;
7430b57cec5SDimitry Andric   return LLDB_RECORD_RESULT(
7440b57cec5SDimitry Andric       BreakpointCreateByLocation(sb_file_spec, line, offset, empty_list));
7450b57cec5SDimitry Andric }
7460b57cec5SDimitry Andric 
7470b57cec5SDimitry Andric SBBreakpoint
BreakpointCreateByLocation(const SBFileSpec & sb_file_spec,uint32_t line,lldb::addr_t offset,SBFileSpecList & sb_module_list)7480b57cec5SDimitry Andric SBTarget::BreakpointCreateByLocation(const SBFileSpec &sb_file_spec,
7490b57cec5SDimitry Andric                                      uint32_t line, lldb::addr_t offset,
7500b57cec5SDimitry Andric                                      SBFileSpecList &sb_module_list) {
7510b57cec5SDimitry Andric   LLDB_RECORD_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateByLocation,
7520b57cec5SDimitry Andric                      (const lldb::SBFileSpec &, uint32_t, lldb::addr_t,
7530b57cec5SDimitry Andric                       lldb::SBFileSpecList &),
7540b57cec5SDimitry Andric                      sb_file_spec, line, offset, sb_module_list);
7550b57cec5SDimitry Andric 
7560b57cec5SDimitry Andric   return LLDB_RECORD_RESULT(BreakpointCreateByLocation(sb_file_spec, line, 0,
7570b57cec5SDimitry Andric                                                        offset, sb_module_list));
7580b57cec5SDimitry Andric }
7590b57cec5SDimitry Andric 
BreakpointCreateByLocation(const SBFileSpec & sb_file_spec,uint32_t line,uint32_t column,lldb::addr_t offset,SBFileSpecList & sb_module_list)7600b57cec5SDimitry Andric SBBreakpoint SBTarget::BreakpointCreateByLocation(
7610b57cec5SDimitry Andric     const SBFileSpec &sb_file_spec, uint32_t line, uint32_t column,
7620b57cec5SDimitry Andric     lldb::addr_t offset, SBFileSpecList &sb_module_list) {
7630b57cec5SDimitry Andric   LLDB_RECORD_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateByLocation,
7640b57cec5SDimitry Andric                      (const lldb::SBFileSpec &, uint32_t, uint32_t,
7650b57cec5SDimitry Andric                       lldb::addr_t, lldb::SBFileSpecList &),
7660b57cec5SDimitry Andric                      sb_file_spec, line, column, offset, sb_module_list);
7670b57cec5SDimitry Andric 
7680b57cec5SDimitry Andric   SBBreakpoint sb_bp;
7690b57cec5SDimitry Andric   TargetSP target_sp(GetSP());
7700b57cec5SDimitry Andric   if (target_sp && line != 0) {
7710b57cec5SDimitry Andric     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
7720b57cec5SDimitry Andric 
7730b57cec5SDimitry Andric     const LazyBool check_inlines = eLazyBoolCalculate;
7740b57cec5SDimitry Andric     const LazyBool skip_prologue = eLazyBoolCalculate;
7750b57cec5SDimitry Andric     const bool internal = false;
7760b57cec5SDimitry Andric     const bool hardware = false;
7770b57cec5SDimitry Andric     const LazyBool move_to_nearest_code = eLazyBoolCalculate;
7780b57cec5SDimitry Andric     const FileSpecList *module_list = nullptr;
7790b57cec5SDimitry Andric     if (sb_module_list.GetSize() > 0) {
7800b57cec5SDimitry Andric       module_list = sb_module_list.get();
7810b57cec5SDimitry Andric     }
7820b57cec5SDimitry Andric     sb_bp = target_sp->CreateBreakpoint(
7830b57cec5SDimitry Andric         module_list, *sb_file_spec, line, column, offset, check_inlines,
7840b57cec5SDimitry Andric         skip_prologue, internal, hardware, move_to_nearest_code);
7850b57cec5SDimitry Andric   }
7860b57cec5SDimitry Andric 
7870b57cec5SDimitry Andric   return LLDB_RECORD_RESULT(sb_bp);
7880b57cec5SDimitry Andric }
7890b57cec5SDimitry Andric 
BreakpointCreateByLocation(const SBFileSpec & sb_file_spec,uint32_t line,uint32_t column,lldb::addr_t offset,SBFileSpecList & sb_module_list,bool move_to_nearest_code)790af732203SDimitry Andric SBBreakpoint SBTarget::BreakpointCreateByLocation(
791af732203SDimitry Andric     const SBFileSpec &sb_file_spec, uint32_t line, uint32_t column,
792af732203SDimitry Andric     lldb::addr_t offset, SBFileSpecList &sb_module_list,
793af732203SDimitry Andric     bool move_to_nearest_code) {
794af732203SDimitry Andric   LLDB_RECORD_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateByLocation,
795af732203SDimitry Andric                      (const lldb::SBFileSpec &, uint32_t, uint32_t,
796af732203SDimitry Andric                       lldb::addr_t, lldb::SBFileSpecList &, bool),
797af732203SDimitry Andric                      sb_file_spec, line, column, offset, sb_module_list,
798af732203SDimitry Andric                      move_to_nearest_code);
799af732203SDimitry Andric 
800af732203SDimitry Andric   SBBreakpoint sb_bp;
801af732203SDimitry Andric   TargetSP target_sp(GetSP());
802af732203SDimitry Andric   if (target_sp && line != 0) {
803af732203SDimitry Andric     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
804af732203SDimitry Andric 
805af732203SDimitry Andric     const LazyBool check_inlines = eLazyBoolCalculate;
806af732203SDimitry Andric     const LazyBool skip_prologue = eLazyBoolCalculate;
807af732203SDimitry Andric     const bool internal = false;
808af732203SDimitry Andric     const bool hardware = false;
809af732203SDimitry Andric     const FileSpecList *module_list = nullptr;
810af732203SDimitry Andric     if (sb_module_list.GetSize() > 0) {
811af732203SDimitry Andric       module_list = sb_module_list.get();
812af732203SDimitry Andric     }
813af732203SDimitry Andric     sb_bp = target_sp->CreateBreakpoint(
814af732203SDimitry Andric         module_list, *sb_file_spec, line, column, offset, check_inlines,
815af732203SDimitry Andric         skip_prologue, internal, hardware,
816af732203SDimitry Andric         move_to_nearest_code ? eLazyBoolYes : eLazyBoolNo);
817af732203SDimitry Andric   }
818af732203SDimitry Andric 
819af732203SDimitry Andric   return LLDB_RECORD_RESULT(sb_bp);
820af732203SDimitry Andric }
821af732203SDimitry Andric 
BreakpointCreateByName(const char * symbol_name,const char * module_name)8220b57cec5SDimitry Andric SBBreakpoint SBTarget::BreakpointCreateByName(const char *symbol_name,
8230b57cec5SDimitry Andric                                               const char *module_name) {
8240b57cec5SDimitry Andric   LLDB_RECORD_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateByName,
8250b57cec5SDimitry Andric                      (const char *, const char *), symbol_name, module_name);
8260b57cec5SDimitry Andric 
8270b57cec5SDimitry Andric   SBBreakpoint sb_bp;
8280b57cec5SDimitry Andric   TargetSP target_sp(GetSP());
8290b57cec5SDimitry Andric   if (target_sp.get()) {
8300b57cec5SDimitry Andric     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
8310b57cec5SDimitry Andric 
8320b57cec5SDimitry Andric     const bool internal = false;
8330b57cec5SDimitry Andric     const bool hardware = false;
8340b57cec5SDimitry Andric     const LazyBool skip_prologue = eLazyBoolCalculate;
8350b57cec5SDimitry Andric     const lldb::addr_t offset = 0;
8360b57cec5SDimitry Andric     if (module_name && module_name[0]) {
8370b57cec5SDimitry Andric       FileSpecList module_spec_list;
8380b57cec5SDimitry Andric       module_spec_list.Append(FileSpec(module_name));
8390b57cec5SDimitry Andric       sb_bp = target_sp->CreateBreakpoint(
8400b57cec5SDimitry Andric           &module_spec_list, nullptr, symbol_name, eFunctionNameTypeAuto,
8410b57cec5SDimitry Andric           eLanguageTypeUnknown, offset, skip_prologue, internal, hardware);
8420b57cec5SDimitry Andric     } else {
8430b57cec5SDimitry Andric       sb_bp = target_sp->CreateBreakpoint(
8440b57cec5SDimitry Andric           nullptr, nullptr, symbol_name, eFunctionNameTypeAuto,
8450b57cec5SDimitry Andric           eLanguageTypeUnknown, offset, skip_prologue, internal, hardware);
8460b57cec5SDimitry Andric     }
8470b57cec5SDimitry Andric   }
8480b57cec5SDimitry Andric 
8490b57cec5SDimitry Andric   return LLDB_RECORD_RESULT(sb_bp);
8500b57cec5SDimitry Andric }
8510b57cec5SDimitry Andric 
8520b57cec5SDimitry Andric lldb::SBBreakpoint
BreakpointCreateByName(const char * symbol_name,const SBFileSpecList & module_list,const SBFileSpecList & comp_unit_list)8530b57cec5SDimitry Andric SBTarget::BreakpointCreateByName(const char *symbol_name,
8540b57cec5SDimitry Andric                                  const SBFileSpecList &module_list,
8550b57cec5SDimitry Andric                                  const SBFileSpecList &comp_unit_list) {
8560b57cec5SDimitry Andric   LLDB_RECORD_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateByName,
8570b57cec5SDimitry Andric                      (const char *, const lldb::SBFileSpecList &,
8580b57cec5SDimitry Andric                       const lldb::SBFileSpecList &),
8590b57cec5SDimitry Andric                      symbol_name, module_list, comp_unit_list);
8600b57cec5SDimitry Andric 
8610b57cec5SDimitry Andric   lldb::FunctionNameType name_type_mask = eFunctionNameTypeAuto;
8620b57cec5SDimitry Andric   return LLDB_RECORD_RESULT(
8630b57cec5SDimitry Andric       BreakpointCreateByName(symbol_name, name_type_mask, eLanguageTypeUnknown,
8640b57cec5SDimitry Andric                              module_list, comp_unit_list));
8650b57cec5SDimitry Andric }
8660b57cec5SDimitry Andric 
BreakpointCreateByName(const char * symbol_name,uint32_t name_type_mask,const SBFileSpecList & module_list,const SBFileSpecList & comp_unit_list)8670b57cec5SDimitry Andric lldb::SBBreakpoint SBTarget::BreakpointCreateByName(
8680b57cec5SDimitry Andric     const char *symbol_name, uint32_t name_type_mask,
8690b57cec5SDimitry Andric     const SBFileSpecList &module_list, const SBFileSpecList &comp_unit_list) {
8700b57cec5SDimitry Andric   LLDB_RECORD_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateByName,
8710b57cec5SDimitry Andric                      (const char *, uint32_t, const lldb::SBFileSpecList &,
8720b57cec5SDimitry Andric                       const lldb::SBFileSpecList &),
8730b57cec5SDimitry Andric                      symbol_name, name_type_mask, module_list, comp_unit_list);
8740b57cec5SDimitry Andric 
8750b57cec5SDimitry Andric   return LLDB_RECORD_RESULT(
8760b57cec5SDimitry Andric       BreakpointCreateByName(symbol_name, name_type_mask, eLanguageTypeUnknown,
8770b57cec5SDimitry Andric                              module_list, comp_unit_list));
8780b57cec5SDimitry Andric }
8790b57cec5SDimitry Andric 
BreakpointCreateByName(const char * symbol_name,uint32_t name_type_mask,LanguageType symbol_language,const SBFileSpecList & module_list,const SBFileSpecList & comp_unit_list)8800b57cec5SDimitry Andric lldb::SBBreakpoint SBTarget::BreakpointCreateByName(
8810b57cec5SDimitry Andric     const char *symbol_name, uint32_t name_type_mask,
8820b57cec5SDimitry Andric     LanguageType symbol_language, const SBFileSpecList &module_list,
8830b57cec5SDimitry Andric     const SBFileSpecList &comp_unit_list) {
8840b57cec5SDimitry Andric   LLDB_RECORD_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateByName,
8850b57cec5SDimitry Andric                      (const char *, uint32_t, lldb::LanguageType,
8860b57cec5SDimitry Andric                       const lldb::SBFileSpecList &,
8870b57cec5SDimitry Andric                       const lldb::SBFileSpecList &),
8880b57cec5SDimitry Andric                      symbol_name, name_type_mask, symbol_language, module_list,
8890b57cec5SDimitry Andric                      comp_unit_list);
8900b57cec5SDimitry Andric 
8910b57cec5SDimitry Andric   SBBreakpoint sb_bp;
8920b57cec5SDimitry Andric   TargetSP target_sp(GetSP());
8930b57cec5SDimitry Andric   if (target_sp && symbol_name && symbol_name[0]) {
8940b57cec5SDimitry Andric     const bool internal = false;
8950b57cec5SDimitry Andric     const bool hardware = false;
8960b57cec5SDimitry Andric     const LazyBool skip_prologue = eLazyBoolCalculate;
8970b57cec5SDimitry Andric     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
8980b57cec5SDimitry Andric     FunctionNameType mask = static_cast<FunctionNameType>(name_type_mask);
8990b57cec5SDimitry Andric     sb_bp = target_sp->CreateBreakpoint(module_list.get(), comp_unit_list.get(),
9000b57cec5SDimitry Andric                                         symbol_name, mask, symbol_language, 0,
9010b57cec5SDimitry Andric                                         skip_prologue, internal, hardware);
9020b57cec5SDimitry Andric   }
9030b57cec5SDimitry Andric 
9040b57cec5SDimitry Andric   return LLDB_RECORD_RESULT(sb_bp);
9050b57cec5SDimitry Andric }
9060b57cec5SDimitry Andric 
BreakpointCreateByNames(const char * symbol_names[],uint32_t num_names,uint32_t name_type_mask,const SBFileSpecList & module_list,const SBFileSpecList & comp_unit_list)9070b57cec5SDimitry Andric lldb::SBBreakpoint SBTarget::BreakpointCreateByNames(
9080b57cec5SDimitry Andric     const char *symbol_names[], uint32_t num_names, uint32_t name_type_mask,
9090b57cec5SDimitry Andric     const SBFileSpecList &module_list, const SBFileSpecList &comp_unit_list) {
9100b57cec5SDimitry Andric   LLDB_RECORD_METHOD(
9110b57cec5SDimitry Andric       lldb::SBBreakpoint, SBTarget, BreakpointCreateByNames,
9120b57cec5SDimitry Andric       (const char **, uint32_t, uint32_t, const lldb::SBFileSpecList &,
9130b57cec5SDimitry Andric        const lldb::SBFileSpecList &),
9140b57cec5SDimitry Andric       symbol_names, num_names, name_type_mask, module_list, comp_unit_list);
9150b57cec5SDimitry Andric 
9160b57cec5SDimitry Andric   return LLDB_RECORD_RESULT(BreakpointCreateByNames(
9170b57cec5SDimitry Andric       symbol_names, num_names, name_type_mask, eLanguageTypeUnknown,
9180b57cec5SDimitry Andric       module_list, comp_unit_list));
9190b57cec5SDimitry Andric }
9200b57cec5SDimitry Andric 
BreakpointCreateByNames(const char * symbol_names[],uint32_t num_names,uint32_t name_type_mask,LanguageType symbol_language,const SBFileSpecList & module_list,const SBFileSpecList & comp_unit_list)9210b57cec5SDimitry Andric lldb::SBBreakpoint SBTarget::BreakpointCreateByNames(
9220b57cec5SDimitry Andric     const char *symbol_names[], uint32_t num_names, uint32_t name_type_mask,
9230b57cec5SDimitry Andric     LanguageType symbol_language, const SBFileSpecList &module_list,
9240b57cec5SDimitry Andric     const SBFileSpecList &comp_unit_list) {
9250b57cec5SDimitry Andric   LLDB_RECORD_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateByNames,
9260b57cec5SDimitry Andric                      (const char **, uint32_t, uint32_t, lldb::LanguageType,
9270b57cec5SDimitry Andric                       const lldb::SBFileSpecList &,
9280b57cec5SDimitry Andric                       const lldb::SBFileSpecList &),
9290b57cec5SDimitry Andric                      symbol_names, num_names, name_type_mask, symbol_language,
9300b57cec5SDimitry Andric                      module_list, comp_unit_list);
9310b57cec5SDimitry Andric 
9320b57cec5SDimitry Andric   return LLDB_RECORD_RESULT(BreakpointCreateByNames(
9330b57cec5SDimitry Andric       symbol_names, num_names, name_type_mask, eLanguageTypeUnknown, 0,
9340b57cec5SDimitry Andric       module_list, comp_unit_list));
9350b57cec5SDimitry Andric }
9360b57cec5SDimitry Andric 
BreakpointCreateByNames(const char * symbol_names[],uint32_t num_names,uint32_t name_type_mask,LanguageType symbol_language,lldb::addr_t offset,const SBFileSpecList & module_list,const SBFileSpecList & comp_unit_list)9370b57cec5SDimitry Andric lldb::SBBreakpoint SBTarget::BreakpointCreateByNames(
9380b57cec5SDimitry Andric     const char *symbol_names[], uint32_t num_names, uint32_t name_type_mask,
9390b57cec5SDimitry Andric     LanguageType symbol_language, lldb::addr_t offset,
9400b57cec5SDimitry Andric     const SBFileSpecList &module_list, const SBFileSpecList &comp_unit_list) {
9410b57cec5SDimitry Andric   LLDB_RECORD_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateByNames,
9420b57cec5SDimitry Andric                      (const char **, uint32_t, uint32_t, lldb::LanguageType,
9430b57cec5SDimitry Andric                       lldb::addr_t, const lldb::SBFileSpecList &,
9440b57cec5SDimitry Andric                       const lldb::SBFileSpecList &),
9450b57cec5SDimitry Andric                      symbol_names, num_names, name_type_mask, symbol_language,
9460b57cec5SDimitry Andric                      offset, module_list, comp_unit_list);
9470b57cec5SDimitry Andric 
9480b57cec5SDimitry Andric   SBBreakpoint sb_bp;
9490b57cec5SDimitry Andric   TargetSP target_sp(GetSP());
9500b57cec5SDimitry Andric   if (target_sp && num_names > 0) {
9510b57cec5SDimitry Andric     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
9520b57cec5SDimitry Andric     const bool internal = false;
9530b57cec5SDimitry Andric     const bool hardware = false;
9540b57cec5SDimitry Andric     FunctionNameType mask = static_cast<FunctionNameType>(name_type_mask);
9550b57cec5SDimitry Andric     const LazyBool skip_prologue = eLazyBoolCalculate;
9560b57cec5SDimitry Andric     sb_bp = target_sp->CreateBreakpoint(
9570b57cec5SDimitry Andric         module_list.get(), comp_unit_list.get(), symbol_names, num_names, mask,
9580b57cec5SDimitry Andric         symbol_language, offset, skip_prologue, internal, hardware);
9590b57cec5SDimitry Andric   }
9600b57cec5SDimitry Andric 
9610b57cec5SDimitry Andric   return LLDB_RECORD_RESULT(sb_bp);
9620b57cec5SDimitry Andric }
9630b57cec5SDimitry Andric 
BreakpointCreateByRegex(const char * symbol_name_regex,const char * module_name)9640b57cec5SDimitry Andric SBBreakpoint SBTarget::BreakpointCreateByRegex(const char *symbol_name_regex,
9650b57cec5SDimitry Andric                                                const char *module_name) {
9660b57cec5SDimitry Andric   LLDB_RECORD_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateByRegex,
9670b57cec5SDimitry Andric                      (const char *, const char *), symbol_name_regex,
9680b57cec5SDimitry Andric                      module_name);
9690b57cec5SDimitry Andric 
9700b57cec5SDimitry Andric   SBFileSpecList module_spec_list;
9710b57cec5SDimitry Andric   SBFileSpecList comp_unit_list;
9720b57cec5SDimitry Andric   if (module_name && module_name[0]) {
9730b57cec5SDimitry Andric     module_spec_list.Append(FileSpec(module_name));
9740b57cec5SDimitry Andric   }
9750b57cec5SDimitry Andric   return LLDB_RECORD_RESULT(
9760b57cec5SDimitry Andric       BreakpointCreateByRegex(symbol_name_regex, eLanguageTypeUnknown,
9770b57cec5SDimitry Andric                               module_spec_list, comp_unit_list));
9780b57cec5SDimitry Andric }
9790b57cec5SDimitry Andric 
9800b57cec5SDimitry Andric lldb::SBBreakpoint
BreakpointCreateByRegex(const char * symbol_name_regex,const SBFileSpecList & module_list,const SBFileSpecList & comp_unit_list)9810b57cec5SDimitry Andric SBTarget::BreakpointCreateByRegex(const char *symbol_name_regex,
9820b57cec5SDimitry Andric                                   const SBFileSpecList &module_list,
9830b57cec5SDimitry Andric                                   const SBFileSpecList &comp_unit_list) {
9840b57cec5SDimitry Andric   LLDB_RECORD_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateByRegex,
9850b57cec5SDimitry Andric                      (const char *, const lldb::SBFileSpecList &,
9860b57cec5SDimitry Andric                       const lldb::SBFileSpecList &),
9870b57cec5SDimitry Andric                      symbol_name_regex, module_list, comp_unit_list);
9880b57cec5SDimitry Andric 
9890b57cec5SDimitry Andric   return LLDB_RECORD_RESULT(BreakpointCreateByRegex(
9900b57cec5SDimitry Andric       symbol_name_regex, eLanguageTypeUnknown, module_list, comp_unit_list));
9910b57cec5SDimitry Andric }
9920b57cec5SDimitry Andric 
BreakpointCreateByRegex(const char * symbol_name_regex,LanguageType symbol_language,const SBFileSpecList & module_list,const SBFileSpecList & comp_unit_list)9930b57cec5SDimitry Andric lldb::SBBreakpoint SBTarget::BreakpointCreateByRegex(
9940b57cec5SDimitry Andric     const char *symbol_name_regex, LanguageType symbol_language,
9950b57cec5SDimitry Andric     const SBFileSpecList &module_list, const SBFileSpecList &comp_unit_list) {
9960b57cec5SDimitry Andric   LLDB_RECORD_METHOD(
9970b57cec5SDimitry Andric       lldb::SBBreakpoint, SBTarget, BreakpointCreateByRegex,
9980b57cec5SDimitry Andric       (const char *, lldb::LanguageType, const lldb::SBFileSpecList &,
9990b57cec5SDimitry Andric        const lldb::SBFileSpecList &),
10000b57cec5SDimitry Andric       symbol_name_regex, symbol_language, module_list, comp_unit_list);
10010b57cec5SDimitry Andric 
10020b57cec5SDimitry Andric 
10030b57cec5SDimitry Andric   SBBreakpoint sb_bp;
10040b57cec5SDimitry Andric   TargetSP target_sp(GetSP());
10050b57cec5SDimitry Andric   if (target_sp && symbol_name_regex && symbol_name_regex[0]) {
10060b57cec5SDimitry Andric     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
10070b57cec5SDimitry Andric     RegularExpression regexp((llvm::StringRef(symbol_name_regex)));
10080b57cec5SDimitry Andric     const bool internal = false;
10090b57cec5SDimitry Andric     const bool hardware = false;
10100b57cec5SDimitry Andric     const LazyBool skip_prologue = eLazyBoolCalculate;
10110b57cec5SDimitry Andric 
10120b57cec5SDimitry Andric     sb_bp = target_sp->CreateFuncRegexBreakpoint(
10139dba64beSDimitry Andric         module_list.get(), comp_unit_list.get(), std::move(regexp),
10149dba64beSDimitry Andric         symbol_language, skip_prologue, internal, hardware);
10150b57cec5SDimitry Andric   }
10160b57cec5SDimitry Andric 
10170b57cec5SDimitry Andric   return LLDB_RECORD_RESULT(sb_bp);
10180b57cec5SDimitry Andric }
10190b57cec5SDimitry Andric 
BreakpointCreateByAddress(addr_t address)10200b57cec5SDimitry Andric SBBreakpoint SBTarget::BreakpointCreateByAddress(addr_t address) {
10210b57cec5SDimitry Andric   LLDB_RECORD_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateByAddress,
10220b57cec5SDimitry Andric                      (lldb::addr_t), address);
10230b57cec5SDimitry Andric 
10240b57cec5SDimitry Andric   SBBreakpoint sb_bp;
10250b57cec5SDimitry Andric   TargetSP target_sp(GetSP());
10260b57cec5SDimitry Andric   if (target_sp) {
10270b57cec5SDimitry Andric     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
10280b57cec5SDimitry Andric     const bool hardware = false;
10290b57cec5SDimitry Andric     sb_bp = target_sp->CreateBreakpoint(address, false, hardware);
10300b57cec5SDimitry Andric   }
10310b57cec5SDimitry Andric 
10320b57cec5SDimitry Andric   return LLDB_RECORD_RESULT(sb_bp);
10330b57cec5SDimitry Andric }
10340b57cec5SDimitry Andric 
BreakpointCreateBySBAddress(SBAddress & sb_address)10350b57cec5SDimitry Andric SBBreakpoint SBTarget::BreakpointCreateBySBAddress(SBAddress &sb_address) {
10360b57cec5SDimitry Andric   LLDB_RECORD_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateBySBAddress,
10370b57cec5SDimitry Andric                      (lldb::SBAddress &), sb_address);
10380b57cec5SDimitry Andric 
10390b57cec5SDimitry Andric   SBBreakpoint sb_bp;
10400b57cec5SDimitry Andric   TargetSP target_sp(GetSP());
10410b57cec5SDimitry Andric   if (!sb_address.IsValid()) {
10420b57cec5SDimitry Andric     return LLDB_RECORD_RESULT(sb_bp);
10430b57cec5SDimitry Andric   }
10440b57cec5SDimitry Andric 
10450b57cec5SDimitry Andric   if (target_sp) {
10460b57cec5SDimitry Andric     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
10470b57cec5SDimitry Andric     const bool hardware = false;
10480b57cec5SDimitry Andric     sb_bp = target_sp->CreateBreakpoint(sb_address.ref(), false, hardware);
10490b57cec5SDimitry Andric   }
10500b57cec5SDimitry Andric 
10510b57cec5SDimitry Andric   return LLDB_RECORD_RESULT(sb_bp);
10520b57cec5SDimitry Andric }
10530b57cec5SDimitry Andric 
10540b57cec5SDimitry Andric lldb::SBBreakpoint
BreakpointCreateBySourceRegex(const char * source_regex,const lldb::SBFileSpec & source_file,const char * module_name)10550b57cec5SDimitry Andric SBTarget::BreakpointCreateBySourceRegex(const char *source_regex,
10560b57cec5SDimitry Andric                                         const lldb::SBFileSpec &source_file,
10570b57cec5SDimitry Andric                                         const char *module_name) {
10580b57cec5SDimitry Andric   LLDB_RECORD_METHOD(lldb::SBBreakpoint, SBTarget,
10590b57cec5SDimitry Andric                      BreakpointCreateBySourceRegex,
10600b57cec5SDimitry Andric                      (const char *, const lldb::SBFileSpec &, const char *),
10610b57cec5SDimitry Andric                      source_regex, source_file, module_name);
10620b57cec5SDimitry Andric 
10630b57cec5SDimitry Andric   SBFileSpecList module_spec_list;
10640b57cec5SDimitry Andric 
10650b57cec5SDimitry Andric   if (module_name && module_name[0]) {
10660b57cec5SDimitry Andric     module_spec_list.Append(FileSpec(module_name));
10670b57cec5SDimitry Andric   }
10680b57cec5SDimitry Andric 
10690b57cec5SDimitry Andric   SBFileSpecList source_file_list;
10700b57cec5SDimitry Andric   if (source_file.IsValid()) {
10710b57cec5SDimitry Andric     source_file_list.Append(source_file);
10720b57cec5SDimitry Andric   }
10730b57cec5SDimitry Andric 
10740b57cec5SDimitry Andric   return LLDB_RECORD_RESULT(BreakpointCreateBySourceRegex(
10750b57cec5SDimitry Andric       source_regex, module_spec_list, source_file_list));
10760b57cec5SDimitry Andric }
10770b57cec5SDimitry Andric 
BreakpointCreateBySourceRegex(const char * source_regex,const SBFileSpecList & module_list,const lldb::SBFileSpecList & source_file_list)10780b57cec5SDimitry Andric lldb::SBBreakpoint SBTarget::BreakpointCreateBySourceRegex(
10790b57cec5SDimitry Andric     const char *source_regex, const SBFileSpecList &module_list,
10800b57cec5SDimitry Andric     const lldb::SBFileSpecList &source_file_list) {
10810b57cec5SDimitry Andric   LLDB_RECORD_METHOD(lldb::SBBreakpoint, SBTarget,
10820b57cec5SDimitry Andric                      BreakpointCreateBySourceRegex,
10830b57cec5SDimitry Andric                      (const char *, const lldb::SBFileSpecList &,
10840b57cec5SDimitry Andric                       const lldb::SBFileSpecList &),
10850b57cec5SDimitry Andric                      source_regex, module_list, source_file_list);
10860b57cec5SDimitry Andric 
10870b57cec5SDimitry Andric   return LLDB_RECORD_RESULT(BreakpointCreateBySourceRegex(
10880b57cec5SDimitry Andric       source_regex, module_list, source_file_list, SBStringList()));
10890b57cec5SDimitry Andric }
10900b57cec5SDimitry Andric 
BreakpointCreateBySourceRegex(const char * source_regex,const SBFileSpecList & module_list,const lldb::SBFileSpecList & source_file_list,const SBStringList & func_names)10910b57cec5SDimitry Andric lldb::SBBreakpoint SBTarget::BreakpointCreateBySourceRegex(
10920b57cec5SDimitry Andric     const char *source_regex, const SBFileSpecList &module_list,
10930b57cec5SDimitry Andric     const lldb::SBFileSpecList &source_file_list,
10940b57cec5SDimitry Andric     const SBStringList &func_names) {
10950b57cec5SDimitry Andric   LLDB_RECORD_METHOD(lldb::SBBreakpoint, SBTarget,
10960b57cec5SDimitry Andric                      BreakpointCreateBySourceRegex,
10970b57cec5SDimitry Andric                      (const char *, const lldb::SBFileSpecList &,
10980b57cec5SDimitry Andric                       const lldb::SBFileSpecList &, const lldb::SBStringList &),
10990b57cec5SDimitry Andric                      source_regex, module_list, source_file_list, func_names);
11000b57cec5SDimitry Andric 
11010b57cec5SDimitry Andric   SBBreakpoint sb_bp;
11020b57cec5SDimitry Andric   TargetSP target_sp(GetSP());
11030b57cec5SDimitry Andric   if (target_sp && source_regex && source_regex[0]) {
11040b57cec5SDimitry Andric     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
11050b57cec5SDimitry Andric     const bool hardware = false;
11060b57cec5SDimitry Andric     const LazyBool move_to_nearest_code = eLazyBoolCalculate;
11070b57cec5SDimitry Andric     RegularExpression regexp((llvm::StringRef(source_regex)));
11080b57cec5SDimitry Andric     std::unordered_set<std::string> func_names_set;
11090b57cec5SDimitry Andric     for (size_t i = 0; i < func_names.GetSize(); i++) {
11100b57cec5SDimitry Andric       func_names_set.insert(func_names.GetStringAtIndex(i));
11110b57cec5SDimitry Andric     }
11120b57cec5SDimitry Andric 
11130b57cec5SDimitry Andric     sb_bp = target_sp->CreateSourceRegexBreakpoint(
11149dba64beSDimitry Andric         module_list.get(), source_file_list.get(), func_names_set,
11159dba64beSDimitry Andric         std::move(regexp), false, hardware, move_to_nearest_code);
11160b57cec5SDimitry Andric   }
11170b57cec5SDimitry Andric 
11180b57cec5SDimitry Andric   return LLDB_RECORD_RESULT(sb_bp);
11190b57cec5SDimitry Andric }
11200b57cec5SDimitry Andric 
11210b57cec5SDimitry Andric lldb::SBBreakpoint
BreakpointCreateForException(lldb::LanguageType language,bool catch_bp,bool throw_bp)11220b57cec5SDimitry Andric SBTarget::BreakpointCreateForException(lldb::LanguageType language,
11230b57cec5SDimitry Andric                                        bool catch_bp, bool throw_bp) {
11240b57cec5SDimitry Andric   LLDB_RECORD_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateForException,
11250b57cec5SDimitry Andric                      (lldb::LanguageType, bool, bool), language, catch_bp,
11260b57cec5SDimitry Andric                      throw_bp);
11270b57cec5SDimitry Andric 
11280b57cec5SDimitry Andric   SBBreakpoint sb_bp;
11290b57cec5SDimitry Andric   TargetSP target_sp(GetSP());
11300b57cec5SDimitry Andric   if (target_sp) {
11310b57cec5SDimitry Andric     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
11320b57cec5SDimitry Andric     const bool hardware = false;
11330b57cec5SDimitry Andric     sb_bp = target_sp->CreateExceptionBreakpoint(language, catch_bp, throw_bp,
11340b57cec5SDimitry Andric                                                   hardware);
11350b57cec5SDimitry Andric   }
11360b57cec5SDimitry Andric 
11370b57cec5SDimitry Andric   return LLDB_RECORD_RESULT(sb_bp);
11380b57cec5SDimitry Andric }
11390b57cec5SDimitry Andric 
BreakpointCreateFromScript(const char * class_name,SBStructuredData & extra_args,const SBFileSpecList & module_list,const SBFileSpecList & file_list,bool request_hardware)11400b57cec5SDimitry Andric lldb::SBBreakpoint SBTarget::BreakpointCreateFromScript(
11410b57cec5SDimitry Andric     const char *class_name, SBStructuredData &extra_args,
11420b57cec5SDimitry Andric     const SBFileSpecList &module_list, const SBFileSpecList &file_list,
11430b57cec5SDimitry Andric     bool request_hardware) {
11440b57cec5SDimitry Andric   LLDB_RECORD_METHOD(
11450b57cec5SDimitry Andric       lldb::SBBreakpoint, SBTarget, BreakpointCreateFromScript,
11460b57cec5SDimitry Andric       (const char *, lldb::SBStructuredData &, const lldb::SBFileSpecList &,
11470b57cec5SDimitry Andric        const lldb::SBFileSpecList &, bool),
11480b57cec5SDimitry Andric       class_name, extra_args, module_list, file_list, request_hardware);
11490b57cec5SDimitry Andric 
11500b57cec5SDimitry Andric   SBBreakpoint sb_bp;
11510b57cec5SDimitry Andric   TargetSP target_sp(GetSP());
11520b57cec5SDimitry Andric   if (target_sp) {
11530b57cec5SDimitry Andric     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
11540b57cec5SDimitry Andric     Status error;
11550b57cec5SDimitry Andric 
11560b57cec5SDimitry Andric     StructuredData::ObjectSP obj_sp = extra_args.m_impl_up->GetObjectSP();
11570b57cec5SDimitry Andric     sb_bp =
11580b57cec5SDimitry Andric         target_sp->CreateScriptedBreakpoint(class_name,
11590b57cec5SDimitry Andric                                             module_list.get(),
11600b57cec5SDimitry Andric                                             file_list.get(),
11610b57cec5SDimitry Andric                                             false, /* internal */
11620b57cec5SDimitry Andric                                             request_hardware,
11630b57cec5SDimitry Andric                                             obj_sp,
11640b57cec5SDimitry Andric                                             &error);
11650b57cec5SDimitry Andric   }
11660b57cec5SDimitry Andric 
11670b57cec5SDimitry Andric   return LLDB_RECORD_RESULT(sb_bp);
11680b57cec5SDimitry Andric }
11690b57cec5SDimitry Andric 
GetNumBreakpoints() const11700b57cec5SDimitry Andric uint32_t SBTarget::GetNumBreakpoints() const {
11710b57cec5SDimitry Andric   LLDB_RECORD_METHOD_CONST_NO_ARGS(uint32_t, SBTarget, GetNumBreakpoints);
11720b57cec5SDimitry Andric 
11730b57cec5SDimitry Andric   TargetSP target_sp(GetSP());
11740b57cec5SDimitry Andric   if (target_sp) {
11750b57cec5SDimitry Andric     // The breakpoint list is thread safe, no need to lock
11760b57cec5SDimitry Andric     return target_sp->GetBreakpointList().GetSize();
11770b57cec5SDimitry Andric   }
11780b57cec5SDimitry Andric   return 0;
11790b57cec5SDimitry Andric }
11800b57cec5SDimitry Andric 
GetBreakpointAtIndex(uint32_t idx) const11810b57cec5SDimitry Andric SBBreakpoint SBTarget::GetBreakpointAtIndex(uint32_t idx) const {
11820b57cec5SDimitry Andric   LLDB_RECORD_METHOD_CONST(lldb::SBBreakpoint, SBTarget, GetBreakpointAtIndex,
11830b57cec5SDimitry Andric                            (uint32_t), idx);
11840b57cec5SDimitry Andric 
11850b57cec5SDimitry Andric   SBBreakpoint sb_breakpoint;
11860b57cec5SDimitry Andric   TargetSP target_sp(GetSP());
11870b57cec5SDimitry Andric   if (target_sp) {
11880b57cec5SDimitry Andric     // The breakpoint list is thread safe, no need to lock
11890b57cec5SDimitry Andric     sb_breakpoint = target_sp->GetBreakpointList().GetBreakpointAtIndex(idx);
11900b57cec5SDimitry Andric   }
11910b57cec5SDimitry Andric   return LLDB_RECORD_RESULT(sb_breakpoint);
11920b57cec5SDimitry Andric }
11930b57cec5SDimitry Andric 
BreakpointDelete(break_id_t bp_id)11940b57cec5SDimitry Andric bool SBTarget::BreakpointDelete(break_id_t bp_id) {
11950b57cec5SDimitry Andric   LLDB_RECORD_METHOD(bool, SBTarget, BreakpointDelete, (lldb::break_id_t),
11960b57cec5SDimitry Andric                      bp_id);
11970b57cec5SDimitry Andric 
11980b57cec5SDimitry Andric   bool result = false;
11990b57cec5SDimitry Andric   TargetSP target_sp(GetSP());
12000b57cec5SDimitry Andric   if (target_sp) {
12010b57cec5SDimitry Andric     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
12020b57cec5SDimitry Andric     result = target_sp->RemoveBreakpointByID(bp_id);
12030b57cec5SDimitry Andric   }
12040b57cec5SDimitry Andric 
12050b57cec5SDimitry Andric   return result;
12060b57cec5SDimitry Andric }
12070b57cec5SDimitry Andric 
FindBreakpointByID(break_id_t bp_id)12080b57cec5SDimitry Andric SBBreakpoint SBTarget::FindBreakpointByID(break_id_t bp_id) {
12090b57cec5SDimitry Andric   LLDB_RECORD_METHOD(lldb::SBBreakpoint, SBTarget, FindBreakpointByID,
12100b57cec5SDimitry Andric                      (lldb::break_id_t), bp_id);
12110b57cec5SDimitry Andric 
12120b57cec5SDimitry Andric   SBBreakpoint sb_breakpoint;
12130b57cec5SDimitry Andric   TargetSP target_sp(GetSP());
12140b57cec5SDimitry Andric   if (target_sp && bp_id != LLDB_INVALID_BREAK_ID) {
12150b57cec5SDimitry Andric     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
12160b57cec5SDimitry Andric     sb_breakpoint = target_sp->GetBreakpointByID(bp_id);
12170b57cec5SDimitry Andric   }
12180b57cec5SDimitry Andric 
12190b57cec5SDimitry Andric   return LLDB_RECORD_RESULT(sb_breakpoint);
12200b57cec5SDimitry Andric }
12210b57cec5SDimitry Andric 
FindBreakpointsByName(const char * name,SBBreakpointList & bkpts)12220b57cec5SDimitry Andric bool SBTarget::FindBreakpointsByName(const char *name,
12230b57cec5SDimitry Andric                                      SBBreakpointList &bkpts) {
12240b57cec5SDimitry Andric   LLDB_RECORD_METHOD(bool, SBTarget, FindBreakpointsByName,
12250b57cec5SDimitry Andric                      (const char *, lldb::SBBreakpointList &), name, bkpts);
12260b57cec5SDimitry Andric 
12270b57cec5SDimitry Andric   TargetSP target_sp(GetSP());
12280b57cec5SDimitry Andric   if (target_sp) {
12290b57cec5SDimitry Andric     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1230480093f4SDimitry Andric     llvm::Expected<std::vector<BreakpointSP>> expected_vector =
1231480093f4SDimitry Andric         target_sp->GetBreakpointList().FindBreakpointsByName(name);
1232480093f4SDimitry Andric     if (!expected_vector) {
1233480093f4SDimitry Andric       LLDB_LOG(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_BREAKPOINTS),
1234480093f4SDimitry Andric                "invalid breakpoint name: {}",
1235480093f4SDimitry Andric                llvm::toString(expected_vector.takeError()));
12360b57cec5SDimitry Andric       return false;
1237480093f4SDimitry Andric     }
1238480093f4SDimitry Andric     for (BreakpointSP bkpt_sp : *expected_vector) {
12390b57cec5SDimitry Andric       bkpts.AppendByID(bkpt_sp->GetID());
12400b57cec5SDimitry Andric     }
12410b57cec5SDimitry Andric   }
12420b57cec5SDimitry Andric   return true;
12430b57cec5SDimitry Andric }
12440b57cec5SDimitry Andric 
GetBreakpointNames(SBStringList & names)12450b57cec5SDimitry Andric void SBTarget::GetBreakpointNames(SBStringList &names) {
12460b57cec5SDimitry Andric   LLDB_RECORD_METHOD(void, SBTarget, GetBreakpointNames, (lldb::SBStringList &),
12470b57cec5SDimitry Andric                      names);
12480b57cec5SDimitry Andric 
12490b57cec5SDimitry Andric   names.Clear();
12500b57cec5SDimitry Andric 
12510b57cec5SDimitry Andric   TargetSP target_sp(GetSP());
12520b57cec5SDimitry Andric   if (target_sp) {
12530b57cec5SDimitry Andric     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
12540b57cec5SDimitry Andric 
12550b57cec5SDimitry Andric     std::vector<std::string> name_vec;
12560b57cec5SDimitry Andric     target_sp->GetBreakpointNames(name_vec);
12570b57cec5SDimitry Andric     for (auto name : name_vec)
12580b57cec5SDimitry Andric       names.AppendString(name.c_str());
12590b57cec5SDimitry Andric   }
12600b57cec5SDimitry Andric }
12610b57cec5SDimitry Andric 
DeleteBreakpointName(const char * name)12620b57cec5SDimitry Andric void SBTarget::DeleteBreakpointName(const char *name) {
12630b57cec5SDimitry Andric   LLDB_RECORD_METHOD(void, SBTarget, DeleteBreakpointName, (const char *),
12640b57cec5SDimitry Andric                      name);
12650b57cec5SDimitry Andric 
12660b57cec5SDimitry Andric   TargetSP target_sp(GetSP());
12670b57cec5SDimitry Andric   if (target_sp) {
12680b57cec5SDimitry Andric     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
12690b57cec5SDimitry Andric     target_sp->DeleteBreakpointName(ConstString(name));
12700b57cec5SDimitry Andric   }
12710b57cec5SDimitry Andric }
12720b57cec5SDimitry Andric 
EnableAllBreakpoints()12730b57cec5SDimitry Andric bool SBTarget::EnableAllBreakpoints() {
12740b57cec5SDimitry Andric   LLDB_RECORD_METHOD_NO_ARGS(bool, SBTarget, EnableAllBreakpoints);
12750b57cec5SDimitry Andric 
12760b57cec5SDimitry Andric   TargetSP target_sp(GetSP());
12770b57cec5SDimitry Andric   if (target_sp) {
12780b57cec5SDimitry Andric     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
12790b57cec5SDimitry Andric     target_sp->EnableAllowedBreakpoints();
12800b57cec5SDimitry Andric     return true;
12810b57cec5SDimitry Andric   }
12820b57cec5SDimitry Andric   return false;
12830b57cec5SDimitry Andric }
12840b57cec5SDimitry Andric 
DisableAllBreakpoints()12850b57cec5SDimitry Andric bool SBTarget::DisableAllBreakpoints() {
12860b57cec5SDimitry Andric   LLDB_RECORD_METHOD_NO_ARGS(bool, SBTarget, DisableAllBreakpoints);
12870b57cec5SDimitry Andric 
12880b57cec5SDimitry Andric   TargetSP target_sp(GetSP());
12890b57cec5SDimitry Andric   if (target_sp) {
12900b57cec5SDimitry Andric     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
12910b57cec5SDimitry Andric     target_sp->DisableAllowedBreakpoints();
12920b57cec5SDimitry Andric     return true;
12930b57cec5SDimitry Andric   }
12940b57cec5SDimitry Andric   return false;
12950b57cec5SDimitry Andric }
12960b57cec5SDimitry Andric 
DeleteAllBreakpoints()12970b57cec5SDimitry Andric bool SBTarget::DeleteAllBreakpoints() {
12980b57cec5SDimitry Andric   LLDB_RECORD_METHOD_NO_ARGS(bool, SBTarget, DeleteAllBreakpoints);
12990b57cec5SDimitry Andric 
13000b57cec5SDimitry Andric   TargetSP target_sp(GetSP());
13010b57cec5SDimitry Andric   if (target_sp) {
13020b57cec5SDimitry Andric     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
13030b57cec5SDimitry Andric     target_sp->RemoveAllowedBreakpoints();
13040b57cec5SDimitry Andric     return true;
13050b57cec5SDimitry Andric   }
13060b57cec5SDimitry Andric   return false;
13070b57cec5SDimitry Andric }
13080b57cec5SDimitry Andric 
BreakpointsCreateFromFile(SBFileSpec & source_file,SBBreakpointList & new_bps)13090b57cec5SDimitry Andric lldb::SBError SBTarget::BreakpointsCreateFromFile(SBFileSpec &source_file,
13100b57cec5SDimitry Andric                                                   SBBreakpointList &new_bps) {
13110b57cec5SDimitry Andric   LLDB_RECORD_METHOD(lldb::SBError, SBTarget, BreakpointsCreateFromFile,
13120b57cec5SDimitry Andric                      (lldb::SBFileSpec &, lldb::SBBreakpointList &),
13130b57cec5SDimitry Andric                      source_file, new_bps);
13140b57cec5SDimitry Andric 
13150b57cec5SDimitry Andric   SBStringList empty_name_list;
13160b57cec5SDimitry Andric   return LLDB_RECORD_RESULT(
13170b57cec5SDimitry Andric       BreakpointsCreateFromFile(source_file, empty_name_list, new_bps));
13180b57cec5SDimitry Andric }
13190b57cec5SDimitry Andric 
BreakpointsCreateFromFile(SBFileSpec & source_file,SBStringList & matching_names,SBBreakpointList & new_bps)13200b57cec5SDimitry Andric lldb::SBError SBTarget::BreakpointsCreateFromFile(SBFileSpec &source_file,
13210b57cec5SDimitry Andric                                                   SBStringList &matching_names,
13220b57cec5SDimitry Andric                                                   SBBreakpointList &new_bps) {
13230b57cec5SDimitry Andric   LLDB_RECORD_METHOD(
13240b57cec5SDimitry Andric       lldb::SBError, SBTarget, BreakpointsCreateFromFile,
13250b57cec5SDimitry Andric       (lldb::SBFileSpec &, lldb::SBStringList &, lldb::SBBreakpointList &),
13260b57cec5SDimitry Andric       source_file, matching_names, new_bps);
13270b57cec5SDimitry Andric 
13280b57cec5SDimitry Andric   SBError sberr;
13290b57cec5SDimitry Andric   TargetSP target_sp(GetSP());
13300b57cec5SDimitry Andric   if (!target_sp) {
13310b57cec5SDimitry Andric     sberr.SetErrorString(
13320b57cec5SDimitry Andric         "BreakpointCreateFromFile called with invalid target.");
13330b57cec5SDimitry Andric     return LLDB_RECORD_RESULT(sberr);
13340b57cec5SDimitry Andric   }
13350b57cec5SDimitry Andric   std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
13360b57cec5SDimitry Andric 
13370b57cec5SDimitry Andric   BreakpointIDList bp_ids;
13380b57cec5SDimitry Andric 
13390b57cec5SDimitry Andric   std::vector<std::string> name_vector;
13400b57cec5SDimitry Andric   size_t num_names = matching_names.GetSize();
13410b57cec5SDimitry Andric   for (size_t i = 0; i < num_names; i++)
13420b57cec5SDimitry Andric     name_vector.push_back(matching_names.GetStringAtIndex(i));
13430b57cec5SDimitry Andric 
13440b57cec5SDimitry Andric   sberr.ref() = target_sp->CreateBreakpointsFromFile(source_file.ref(),
13450b57cec5SDimitry Andric                                                      name_vector, bp_ids);
13460b57cec5SDimitry Andric   if (sberr.Fail())
13470b57cec5SDimitry Andric     return LLDB_RECORD_RESULT(sberr);
13480b57cec5SDimitry Andric 
13490b57cec5SDimitry Andric   size_t num_bkpts = bp_ids.GetSize();
13500b57cec5SDimitry Andric   for (size_t i = 0; i < num_bkpts; i++) {
13510b57cec5SDimitry Andric     BreakpointID bp_id = bp_ids.GetBreakpointIDAtIndex(i);
13520b57cec5SDimitry Andric     new_bps.AppendByID(bp_id.GetBreakpointID());
13530b57cec5SDimitry Andric   }
13540b57cec5SDimitry Andric   return LLDB_RECORD_RESULT(sberr);
13550b57cec5SDimitry Andric }
13560b57cec5SDimitry Andric 
BreakpointsWriteToFile(SBFileSpec & dest_file)13570b57cec5SDimitry Andric lldb::SBError SBTarget::BreakpointsWriteToFile(SBFileSpec &dest_file) {
13580b57cec5SDimitry Andric   LLDB_RECORD_METHOD(lldb::SBError, SBTarget, BreakpointsWriteToFile,
13590b57cec5SDimitry Andric                      (lldb::SBFileSpec &), dest_file);
13600b57cec5SDimitry Andric 
13610b57cec5SDimitry Andric   SBError sberr;
13620b57cec5SDimitry Andric   TargetSP target_sp(GetSP());
13630b57cec5SDimitry Andric   if (!target_sp) {
13640b57cec5SDimitry Andric     sberr.SetErrorString("BreakpointWriteToFile called with invalid target.");
13650b57cec5SDimitry Andric     return LLDB_RECORD_RESULT(sberr);
13660b57cec5SDimitry Andric   }
13670b57cec5SDimitry Andric   SBBreakpointList bkpt_list(*this);
13680b57cec5SDimitry Andric   return LLDB_RECORD_RESULT(BreakpointsWriteToFile(dest_file, bkpt_list));
13690b57cec5SDimitry Andric }
13700b57cec5SDimitry Andric 
BreakpointsWriteToFile(SBFileSpec & dest_file,SBBreakpointList & bkpt_list,bool append)13710b57cec5SDimitry Andric lldb::SBError SBTarget::BreakpointsWriteToFile(SBFileSpec &dest_file,
13720b57cec5SDimitry Andric                                                SBBreakpointList &bkpt_list,
13730b57cec5SDimitry Andric                                                bool append) {
13740b57cec5SDimitry Andric   LLDB_RECORD_METHOD(lldb::SBError, SBTarget, BreakpointsWriteToFile,
13750b57cec5SDimitry Andric                      (lldb::SBFileSpec &, lldb::SBBreakpointList &, bool),
13760b57cec5SDimitry Andric                      dest_file, bkpt_list, append);
13770b57cec5SDimitry Andric 
13780b57cec5SDimitry Andric   SBError sberr;
13790b57cec5SDimitry Andric   TargetSP target_sp(GetSP());
13800b57cec5SDimitry Andric   if (!target_sp) {
13810b57cec5SDimitry Andric     sberr.SetErrorString("BreakpointWriteToFile called with invalid target.");
13820b57cec5SDimitry Andric     return LLDB_RECORD_RESULT(sberr);
13830b57cec5SDimitry Andric   }
13840b57cec5SDimitry Andric 
13850b57cec5SDimitry Andric   std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
13860b57cec5SDimitry Andric   BreakpointIDList bp_id_list;
13870b57cec5SDimitry Andric   bkpt_list.CopyToBreakpointIDList(bp_id_list);
13880b57cec5SDimitry Andric   sberr.ref() = target_sp->SerializeBreakpointsToFile(dest_file.ref(),
13890b57cec5SDimitry Andric                                                       bp_id_list, append);
13900b57cec5SDimitry Andric   return LLDB_RECORD_RESULT(sberr);
13910b57cec5SDimitry Andric }
13920b57cec5SDimitry Andric 
GetNumWatchpoints() const13930b57cec5SDimitry Andric uint32_t SBTarget::GetNumWatchpoints() const {
13940b57cec5SDimitry Andric   LLDB_RECORD_METHOD_CONST_NO_ARGS(uint32_t, SBTarget, GetNumWatchpoints);
13950b57cec5SDimitry Andric 
13960b57cec5SDimitry Andric   TargetSP target_sp(GetSP());
13970b57cec5SDimitry Andric   if (target_sp) {
13980b57cec5SDimitry Andric     // The watchpoint list is thread safe, no need to lock
13990b57cec5SDimitry Andric     return target_sp->GetWatchpointList().GetSize();
14000b57cec5SDimitry Andric   }
14010b57cec5SDimitry Andric   return 0;
14020b57cec5SDimitry Andric }
14030b57cec5SDimitry Andric 
GetWatchpointAtIndex(uint32_t idx) const14040b57cec5SDimitry Andric SBWatchpoint SBTarget::GetWatchpointAtIndex(uint32_t idx) const {
14050b57cec5SDimitry Andric   LLDB_RECORD_METHOD_CONST(lldb::SBWatchpoint, SBTarget, GetWatchpointAtIndex,
14060b57cec5SDimitry Andric                            (uint32_t), idx);
14070b57cec5SDimitry Andric 
14080b57cec5SDimitry Andric   SBWatchpoint sb_watchpoint;
14090b57cec5SDimitry Andric   TargetSP target_sp(GetSP());
14100b57cec5SDimitry Andric   if (target_sp) {
14110b57cec5SDimitry Andric     // The watchpoint list is thread safe, no need to lock
14120b57cec5SDimitry Andric     sb_watchpoint.SetSP(target_sp->GetWatchpointList().GetByIndex(idx));
14130b57cec5SDimitry Andric   }
14140b57cec5SDimitry Andric   return LLDB_RECORD_RESULT(sb_watchpoint);
14150b57cec5SDimitry Andric }
14160b57cec5SDimitry Andric 
DeleteWatchpoint(watch_id_t wp_id)14170b57cec5SDimitry Andric bool SBTarget::DeleteWatchpoint(watch_id_t wp_id) {
14180b57cec5SDimitry Andric   LLDB_RECORD_METHOD(bool, SBTarget, DeleteWatchpoint, (lldb::watch_id_t),
14190b57cec5SDimitry Andric                      wp_id);
14200b57cec5SDimitry Andric 
14210b57cec5SDimitry Andric 
14220b57cec5SDimitry Andric   bool result = false;
14230b57cec5SDimitry Andric   TargetSP target_sp(GetSP());
14240b57cec5SDimitry Andric   if (target_sp) {
14250b57cec5SDimitry Andric     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
14260b57cec5SDimitry Andric     std::unique_lock<std::recursive_mutex> lock;
14270b57cec5SDimitry Andric     target_sp->GetWatchpointList().GetListMutex(lock);
14280b57cec5SDimitry Andric     result = target_sp->RemoveWatchpointByID(wp_id);
14290b57cec5SDimitry Andric   }
14300b57cec5SDimitry Andric 
14310b57cec5SDimitry Andric   return result;
14320b57cec5SDimitry Andric }
14330b57cec5SDimitry Andric 
FindWatchpointByID(lldb::watch_id_t wp_id)14340b57cec5SDimitry Andric SBWatchpoint SBTarget::FindWatchpointByID(lldb::watch_id_t wp_id) {
14350b57cec5SDimitry Andric   LLDB_RECORD_METHOD(lldb::SBWatchpoint, SBTarget, FindWatchpointByID,
14360b57cec5SDimitry Andric                      (lldb::watch_id_t), wp_id);
14370b57cec5SDimitry Andric 
14380b57cec5SDimitry Andric 
14390b57cec5SDimitry Andric   SBWatchpoint sb_watchpoint;
14400b57cec5SDimitry Andric   lldb::WatchpointSP watchpoint_sp;
14410b57cec5SDimitry Andric   TargetSP target_sp(GetSP());
14420b57cec5SDimitry Andric   if (target_sp && wp_id != LLDB_INVALID_WATCH_ID) {
14430b57cec5SDimitry Andric     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
14440b57cec5SDimitry Andric     std::unique_lock<std::recursive_mutex> lock;
14450b57cec5SDimitry Andric     target_sp->GetWatchpointList().GetListMutex(lock);
14460b57cec5SDimitry Andric     watchpoint_sp = target_sp->GetWatchpointList().FindByID(wp_id);
14470b57cec5SDimitry Andric     sb_watchpoint.SetSP(watchpoint_sp);
14480b57cec5SDimitry Andric   }
14490b57cec5SDimitry Andric 
14500b57cec5SDimitry Andric   return LLDB_RECORD_RESULT(sb_watchpoint);
14510b57cec5SDimitry Andric }
14520b57cec5SDimitry Andric 
WatchAddress(lldb::addr_t addr,size_t size,bool read,bool write,SBError & error)14530b57cec5SDimitry Andric lldb::SBWatchpoint SBTarget::WatchAddress(lldb::addr_t addr, size_t size,
14540b57cec5SDimitry Andric                                           bool read, bool write,
14550b57cec5SDimitry Andric                                           SBError &error) {
14560b57cec5SDimitry Andric   LLDB_RECORD_METHOD(lldb::SBWatchpoint, SBTarget, WatchAddress,
14570b57cec5SDimitry Andric                      (lldb::addr_t, size_t, bool, bool, lldb::SBError &), addr,
14580b57cec5SDimitry Andric                      size, read, write, error);
14590b57cec5SDimitry Andric 
14600b57cec5SDimitry Andric   SBWatchpoint sb_watchpoint;
14610b57cec5SDimitry Andric   lldb::WatchpointSP watchpoint_sp;
14620b57cec5SDimitry Andric   TargetSP target_sp(GetSP());
14630b57cec5SDimitry Andric   if (target_sp && (read || write) && addr != LLDB_INVALID_ADDRESS &&
14640b57cec5SDimitry Andric       size > 0) {
14650b57cec5SDimitry Andric     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
14660b57cec5SDimitry Andric     uint32_t watch_type = 0;
14670b57cec5SDimitry Andric     if (read)
14680b57cec5SDimitry Andric       watch_type |= LLDB_WATCH_TYPE_READ;
14690b57cec5SDimitry Andric     if (write)
14700b57cec5SDimitry Andric       watch_type |= LLDB_WATCH_TYPE_WRITE;
14710b57cec5SDimitry Andric     if (watch_type == 0) {
14720b57cec5SDimitry Andric       error.SetErrorString(
14730b57cec5SDimitry Andric           "Can't create a watchpoint that is neither read nor write.");
14740b57cec5SDimitry Andric       return LLDB_RECORD_RESULT(sb_watchpoint);
14750b57cec5SDimitry Andric     }
14760b57cec5SDimitry Andric 
14770b57cec5SDimitry Andric     // Target::CreateWatchpoint() is thread safe.
14780b57cec5SDimitry Andric     Status cw_error;
14790b57cec5SDimitry Andric     // This API doesn't take in a type, so we can't figure out what it is.
14800b57cec5SDimitry Andric     CompilerType *type = nullptr;
14810b57cec5SDimitry Andric     watchpoint_sp =
14820b57cec5SDimitry Andric         target_sp->CreateWatchpoint(addr, size, type, watch_type, cw_error);
14830b57cec5SDimitry Andric     error.SetError(cw_error);
14840b57cec5SDimitry Andric     sb_watchpoint.SetSP(watchpoint_sp);
14850b57cec5SDimitry Andric   }
14860b57cec5SDimitry Andric 
14870b57cec5SDimitry Andric   return LLDB_RECORD_RESULT(sb_watchpoint);
14880b57cec5SDimitry Andric }
14890b57cec5SDimitry Andric 
EnableAllWatchpoints()14900b57cec5SDimitry Andric bool SBTarget::EnableAllWatchpoints() {
14910b57cec5SDimitry Andric   LLDB_RECORD_METHOD_NO_ARGS(bool, SBTarget, EnableAllWatchpoints);
14920b57cec5SDimitry Andric 
14930b57cec5SDimitry Andric   TargetSP target_sp(GetSP());
14940b57cec5SDimitry Andric   if (target_sp) {
14950b57cec5SDimitry Andric     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
14960b57cec5SDimitry Andric     std::unique_lock<std::recursive_mutex> lock;
14970b57cec5SDimitry Andric     target_sp->GetWatchpointList().GetListMutex(lock);
14980b57cec5SDimitry Andric     target_sp->EnableAllWatchpoints();
14990b57cec5SDimitry Andric     return true;
15000b57cec5SDimitry Andric   }
15010b57cec5SDimitry Andric   return false;
15020b57cec5SDimitry Andric }
15030b57cec5SDimitry Andric 
DisableAllWatchpoints()15040b57cec5SDimitry Andric bool SBTarget::DisableAllWatchpoints() {
15050b57cec5SDimitry Andric   LLDB_RECORD_METHOD_NO_ARGS(bool, SBTarget, DisableAllWatchpoints);
15060b57cec5SDimitry Andric 
15070b57cec5SDimitry Andric   TargetSP target_sp(GetSP());
15080b57cec5SDimitry Andric   if (target_sp) {
15090b57cec5SDimitry Andric     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
15100b57cec5SDimitry Andric     std::unique_lock<std::recursive_mutex> lock;
15110b57cec5SDimitry Andric     target_sp->GetWatchpointList().GetListMutex(lock);
15120b57cec5SDimitry Andric     target_sp->DisableAllWatchpoints();
15130b57cec5SDimitry Andric     return true;
15140b57cec5SDimitry Andric   }
15150b57cec5SDimitry Andric   return false;
15160b57cec5SDimitry Andric }
15170b57cec5SDimitry Andric 
CreateValueFromAddress(const char * name,SBAddress addr,SBType type)15180b57cec5SDimitry Andric SBValue SBTarget::CreateValueFromAddress(const char *name, SBAddress addr,
15190b57cec5SDimitry Andric                                          SBType type) {
15200b57cec5SDimitry Andric   LLDB_RECORD_METHOD(lldb::SBValue, SBTarget, CreateValueFromAddress,
15210b57cec5SDimitry Andric                      (const char *, lldb::SBAddress, lldb::SBType), name, addr,
15220b57cec5SDimitry Andric                      type);
15230b57cec5SDimitry Andric 
15240b57cec5SDimitry Andric   SBValue sb_value;
15250b57cec5SDimitry Andric   lldb::ValueObjectSP new_value_sp;
15260b57cec5SDimitry Andric   if (IsValid() && name && *name && addr.IsValid() && type.IsValid()) {
15270b57cec5SDimitry Andric     lldb::addr_t load_addr(addr.GetLoadAddress(*this));
15280b57cec5SDimitry Andric     ExecutionContext exe_ctx(
15290b57cec5SDimitry Andric         ExecutionContextRef(ExecutionContext(m_opaque_sp.get(), false)));
15300b57cec5SDimitry Andric     CompilerType ast_type(type.GetSP()->GetCompilerType(true));
15310b57cec5SDimitry Andric     new_value_sp = ValueObject::CreateValueObjectFromAddress(name, load_addr,
15320b57cec5SDimitry Andric                                                              exe_ctx, ast_type);
15330b57cec5SDimitry Andric   }
15340b57cec5SDimitry Andric   sb_value.SetSP(new_value_sp);
15350b57cec5SDimitry Andric   return LLDB_RECORD_RESULT(sb_value);
15360b57cec5SDimitry Andric }
15370b57cec5SDimitry Andric 
CreateValueFromData(const char * name,lldb::SBData data,lldb::SBType type)15380b57cec5SDimitry Andric lldb::SBValue SBTarget::CreateValueFromData(const char *name, lldb::SBData data,
15390b57cec5SDimitry Andric                                             lldb::SBType type) {
15400b57cec5SDimitry Andric   LLDB_RECORD_METHOD(lldb::SBValue, SBTarget, CreateValueFromData,
15410b57cec5SDimitry Andric                      (const char *, lldb::SBData, lldb::SBType), name, data,
15420b57cec5SDimitry Andric                      type);
15430b57cec5SDimitry Andric 
15440b57cec5SDimitry Andric   SBValue sb_value;
15450b57cec5SDimitry Andric   lldb::ValueObjectSP new_value_sp;
15460b57cec5SDimitry Andric   if (IsValid() && name && *name && data.IsValid() && type.IsValid()) {
15470b57cec5SDimitry Andric     DataExtractorSP extractor(*data);
15480b57cec5SDimitry Andric     ExecutionContext exe_ctx(
15490b57cec5SDimitry Andric         ExecutionContextRef(ExecutionContext(m_opaque_sp.get(), false)));
15500b57cec5SDimitry Andric     CompilerType ast_type(type.GetSP()->GetCompilerType(true));
15510b57cec5SDimitry Andric     new_value_sp = ValueObject::CreateValueObjectFromData(name, *extractor,
15520b57cec5SDimitry Andric                                                           exe_ctx, ast_type);
15530b57cec5SDimitry Andric   }
15540b57cec5SDimitry Andric   sb_value.SetSP(new_value_sp);
15550b57cec5SDimitry Andric   return LLDB_RECORD_RESULT(sb_value);
15560b57cec5SDimitry Andric }
15570b57cec5SDimitry Andric 
CreateValueFromExpression(const char * name,const char * expr)15580b57cec5SDimitry Andric lldb::SBValue SBTarget::CreateValueFromExpression(const char *name,
15590b57cec5SDimitry Andric                                                   const char *expr) {
15600b57cec5SDimitry Andric   LLDB_RECORD_METHOD(lldb::SBValue, SBTarget, CreateValueFromExpression,
15610b57cec5SDimitry Andric                      (const char *, const char *), name, expr);
15620b57cec5SDimitry Andric 
15630b57cec5SDimitry Andric   SBValue sb_value;
15640b57cec5SDimitry Andric   lldb::ValueObjectSP new_value_sp;
15650b57cec5SDimitry Andric   if (IsValid() && name && *name && expr && *expr) {
15660b57cec5SDimitry Andric     ExecutionContext exe_ctx(
15670b57cec5SDimitry Andric         ExecutionContextRef(ExecutionContext(m_opaque_sp.get(), false)));
15680b57cec5SDimitry Andric     new_value_sp =
15690b57cec5SDimitry Andric         ValueObject::CreateValueObjectFromExpression(name, expr, exe_ctx);
15700b57cec5SDimitry Andric   }
15710b57cec5SDimitry Andric   sb_value.SetSP(new_value_sp);
15720b57cec5SDimitry Andric   return LLDB_RECORD_RESULT(sb_value);
15730b57cec5SDimitry Andric }
15740b57cec5SDimitry Andric 
DeleteAllWatchpoints()15750b57cec5SDimitry Andric bool SBTarget::DeleteAllWatchpoints() {
15760b57cec5SDimitry Andric   LLDB_RECORD_METHOD_NO_ARGS(bool, SBTarget, DeleteAllWatchpoints);
15770b57cec5SDimitry Andric 
15780b57cec5SDimitry Andric   TargetSP target_sp(GetSP());
15790b57cec5SDimitry Andric   if (target_sp) {
15800b57cec5SDimitry Andric     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
15810b57cec5SDimitry Andric     std::unique_lock<std::recursive_mutex> lock;
15820b57cec5SDimitry Andric     target_sp->GetWatchpointList().GetListMutex(lock);
15830b57cec5SDimitry Andric     target_sp->RemoveAllWatchpoints();
15840b57cec5SDimitry Andric     return true;
15850b57cec5SDimitry Andric   }
15860b57cec5SDimitry Andric   return false;
15870b57cec5SDimitry Andric }
15880b57cec5SDimitry Andric 
AppendImageSearchPath(const char * from,const char * to,lldb::SBError & error)15890b57cec5SDimitry Andric void SBTarget::AppendImageSearchPath(const char *from, const char *to,
15900b57cec5SDimitry Andric                                      lldb::SBError &error) {
15910b57cec5SDimitry Andric   LLDB_RECORD_METHOD(void, SBTarget, AppendImageSearchPath,
15920b57cec5SDimitry Andric                      (const char *, const char *, lldb::SBError &), from, to,
15930b57cec5SDimitry Andric                      error);
15940b57cec5SDimitry Andric 
15950b57cec5SDimitry Andric   TargetSP target_sp(GetSP());
15960b57cec5SDimitry Andric   if (!target_sp)
15970b57cec5SDimitry Andric     return error.SetErrorString("invalid target");
15980b57cec5SDimitry Andric 
15990b57cec5SDimitry Andric   const ConstString csFrom(from), csTo(to);
16000b57cec5SDimitry Andric   if (!csFrom)
16010b57cec5SDimitry Andric     return error.SetErrorString("<from> path can't be empty");
16020b57cec5SDimitry Andric   if (!csTo)
16030b57cec5SDimitry Andric     return error.SetErrorString("<to> path can't be empty");
16040b57cec5SDimitry Andric 
16050b57cec5SDimitry Andric   target_sp->GetImageSearchPathList().Append(csFrom, csTo, true);
16060b57cec5SDimitry Andric }
16070b57cec5SDimitry Andric 
AddModule(const char * path,const char * triple,const char * uuid_cstr)16080b57cec5SDimitry Andric lldb::SBModule SBTarget::AddModule(const char *path, const char *triple,
16090b57cec5SDimitry Andric                                    const char *uuid_cstr) {
16100b57cec5SDimitry Andric   LLDB_RECORD_METHOD(lldb::SBModule, SBTarget, AddModule,
16110b57cec5SDimitry Andric                      (const char *, const char *, const char *), path, triple,
16120b57cec5SDimitry Andric                      uuid_cstr);
16130b57cec5SDimitry Andric 
16140b57cec5SDimitry Andric   return LLDB_RECORD_RESULT(AddModule(path, triple, uuid_cstr, nullptr));
16150b57cec5SDimitry Andric }
16160b57cec5SDimitry Andric 
AddModule(const char * path,const char * triple,const char * uuid_cstr,const char * symfile)16170b57cec5SDimitry Andric lldb::SBModule SBTarget::AddModule(const char *path, const char *triple,
16180b57cec5SDimitry Andric                                    const char *uuid_cstr, const char *symfile) {
16190b57cec5SDimitry Andric   LLDB_RECORD_METHOD(lldb::SBModule, SBTarget, AddModule,
16200b57cec5SDimitry Andric                      (const char *, const char *, const char *, const char *),
16210b57cec5SDimitry Andric                      path, triple, uuid_cstr, symfile);
16220b57cec5SDimitry Andric 
16230b57cec5SDimitry Andric   lldb::SBModule sb_module;
16240b57cec5SDimitry Andric   TargetSP target_sp(GetSP());
16250b57cec5SDimitry Andric   if (target_sp) {
16260b57cec5SDimitry Andric     ModuleSpec module_spec;
16270b57cec5SDimitry Andric     if (path)
16280b57cec5SDimitry Andric       module_spec.GetFileSpec().SetFile(path, FileSpec::Style::native);
16290b57cec5SDimitry Andric 
16300b57cec5SDimitry Andric     if (uuid_cstr)
16310b57cec5SDimitry Andric       module_spec.GetUUID().SetFromStringRef(uuid_cstr);
16320b57cec5SDimitry Andric 
16330b57cec5SDimitry Andric     if (triple)
16340b57cec5SDimitry Andric       module_spec.GetArchitecture() = Platform::GetAugmentedArchSpec(
16350b57cec5SDimitry Andric           target_sp->GetPlatform().get(), triple);
16360b57cec5SDimitry Andric     else
16370b57cec5SDimitry Andric       module_spec.GetArchitecture() = target_sp->GetArchitecture();
16380b57cec5SDimitry Andric 
16390b57cec5SDimitry Andric     if (symfile)
16400b57cec5SDimitry Andric       module_spec.GetSymbolFileSpec().SetFile(symfile, FileSpec::Style::native);
16410b57cec5SDimitry Andric 
16420b57cec5SDimitry Andric     sb_module.SetSP(target_sp->GetOrCreateModule(module_spec, true /* notify */));
16430b57cec5SDimitry Andric   }
16440b57cec5SDimitry Andric   return LLDB_RECORD_RESULT(sb_module);
16450b57cec5SDimitry Andric }
16460b57cec5SDimitry Andric 
AddModule(const SBModuleSpec & module_spec)16470b57cec5SDimitry Andric lldb::SBModule SBTarget::AddModule(const SBModuleSpec &module_spec) {
16480b57cec5SDimitry Andric   LLDB_RECORD_METHOD(lldb::SBModule, SBTarget, AddModule,
16490b57cec5SDimitry Andric                      (const lldb::SBModuleSpec &), module_spec);
16500b57cec5SDimitry Andric 
16510b57cec5SDimitry Andric   lldb::SBModule sb_module;
16520b57cec5SDimitry Andric   TargetSP target_sp(GetSP());
16530b57cec5SDimitry Andric   if (target_sp)
16540b57cec5SDimitry Andric     sb_module.SetSP(target_sp->GetOrCreateModule(*module_spec.m_opaque_up,
16550b57cec5SDimitry Andric                                                  true /* notify */));
16560b57cec5SDimitry Andric   return LLDB_RECORD_RESULT(sb_module);
16570b57cec5SDimitry Andric }
16580b57cec5SDimitry Andric 
AddModule(lldb::SBModule & module)16590b57cec5SDimitry Andric bool SBTarget::AddModule(lldb::SBModule &module) {
16600b57cec5SDimitry Andric   LLDB_RECORD_METHOD(bool, SBTarget, AddModule, (lldb::SBModule &), module);
16610b57cec5SDimitry Andric 
16620b57cec5SDimitry Andric   TargetSP target_sp(GetSP());
16630b57cec5SDimitry Andric   if (target_sp) {
16640b57cec5SDimitry Andric     target_sp->GetImages().AppendIfNeeded(module.GetSP());
16650b57cec5SDimitry Andric     return true;
16660b57cec5SDimitry Andric   }
16670b57cec5SDimitry Andric   return false;
16680b57cec5SDimitry Andric }
16690b57cec5SDimitry Andric 
GetNumModules() const16700b57cec5SDimitry Andric uint32_t SBTarget::GetNumModules() const {
16710b57cec5SDimitry Andric   LLDB_RECORD_METHOD_CONST_NO_ARGS(uint32_t, SBTarget, GetNumModules);
16720b57cec5SDimitry Andric 
16730b57cec5SDimitry Andric   uint32_t num = 0;
16740b57cec5SDimitry Andric   TargetSP target_sp(GetSP());
16750b57cec5SDimitry Andric   if (target_sp) {
16760b57cec5SDimitry Andric     // The module list is thread safe, no need to lock
16770b57cec5SDimitry Andric     num = target_sp->GetImages().GetSize();
16780b57cec5SDimitry Andric   }
16790b57cec5SDimitry Andric 
16800b57cec5SDimitry Andric   return num;
16810b57cec5SDimitry Andric }
16820b57cec5SDimitry Andric 
Clear()16830b57cec5SDimitry Andric void SBTarget::Clear() {
16840b57cec5SDimitry Andric   LLDB_RECORD_METHOD_NO_ARGS(void, SBTarget, Clear);
16850b57cec5SDimitry Andric 
16860b57cec5SDimitry Andric   m_opaque_sp.reset();
16870b57cec5SDimitry Andric }
16880b57cec5SDimitry Andric 
FindModule(const SBFileSpec & sb_file_spec)16890b57cec5SDimitry Andric SBModule SBTarget::FindModule(const SBFileSpec &sb_file_spec) {
16900b57cec5SDimitry Andric   LLDB_RECORD_METHOD(lldb::SBModule, SBTarget, FindModule,
16910b57cec5SDimitry Andric                      (const lldb::SBFileSpec &), sb_file_spec);
16920b57cec5SDimitry Andric 
16930b57cec5SDimitry Andric   SBModule sb_module;
16940b57cec5SDimitry Andric   TargetSP target_sp(GetSP());
16950b57cec5SDimitry Andric   if (target_sp && sb_file_spec.IsValid()) {
16960b57cec5SDimitry Andric     ModuleSpec module_spec(*sb_file_spec);
16970b57cec5SDimitry Andric     // The module list is thread safe, no need to lock
16980b57cec5SDimitry Andric     sb_module.SetSP(target_sp->GetImages().FindFirstModule(module_spec));
16990b57cec5SDimitry Andric   }
17000b57cec5SDimitry Andric   return LLDB_RECORD_RESULT(sb_module);
17010b57cec5SDimitry Andric }
17020b57cec5SDimitry Andric 
FindCompileUnits(const SBFileSpec & sb_file_spec)17030b57cec5SDimitry Andric SBSymbolContextList SBTarget::FindCompileUnits(const SBFileSpec &sb_file_spec) {
17040b57cec5SDimitry Andric   LLDB_RECORD_METHOD(lldb::SBSymbolContextList, SBTarget, FindCompileUnits,
17050b57cec5SDimitry Andric                      (const lldb::SBFileSpec &), sb_file_spec);
17060b57cec5SDimitry Andric 
17070b57cec5SDimitry Andric   SBSymbolContextList sb_sc_list;
17080b57cec5SDimitry Andric   const TargetSP target_sp(GetSP());
17099dba64beSDimitry Andric   if (target_sp && sb_file_spec.IsValid())
17109dba64beSDimitry Andric     target_sp->GetImages().FindCompileUnits(*sb_file_spec, *sb_sc_list);
17110b57cec5SDimitry Andric   return LLDB_RECORD_RESULT(sb_sc_list);
17120b57cec5SDimitry Andric }
17130b57cec5SDimitry Andric 
GetByteOrder()17140b57cec5SDimitry Andric lldb::ByteOrder SBTarget::GetByteOrder() {
17150b57cec5SDimitry Andric   LLDB_RECORD_METHOD_NO_ARGS(lldb::ByteOrder, SBTarget, GetByteOrder);
17160b57cec5SDimitry Andric 
17170b57cec5SDimitry Andric   TargetSP target_sp(GetSP());
17180b57cec5SDimitry Andric   if (target_sp)
17190b57cec5SDimitry Andric     return target_sp->GetArchitecture().GetByteOrder();
17200b57cec5SDimitry Andric   return eByteOrderInvalid;
17210b57cec5SDimitry Andric }
17220b57cec5SDimitry Andric 
GetTriple()17230b57cec5SDimitry Andric const char *SBTarget::GetTriple() {
17240b57cec5SDimitry Andric   LLDB_RECORD_METHOD_NO_ARGS(const char *, SBTarget, GetTriple);
17250b57cec5SDimitry Andric 
17260b57cec5SDimitry Andric   TargetSP target_sp(GetSP());
17270b57cec5SDimitry Andric   if (target_sp) {
17280b57cec5SDimitry Andric     std::string triple(target_sp->GetArchitecture().GetTriple().str());
17290b57cec5SDimitry Andric     // Unique the string so we don't run into ownership issues since the const
17300b57cec5SDimitry Andric     // strings put the string into the string pool once and the strings never
17310b57cec5SDimitry Andric     // comes out
17320b57cec5SDimitry Andric     ConstString const_triple(triple.c_str());
17330b57cec5SDimitry Andric     return const_triple.GetCString();
17340b57cec5SDimitry Andric   }
17350b57cec5SDimitry Andric   return nullptr;
17360b57cec5SDimitry Andric }
17370b57cec5SDimitry Andric 
GetDataByteSize()17380b57cec5SDimitry Andric uint32_t SBTarget::GetDataByteSize() {
17390b57cec5SDimitry Andric   LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBTarget, GetDataByteSize);
17400b57cec5SDimitry Andric 
17410b57cec5SDimitry Andric   TargetSP target_sp(GetSP());
17420b57cec5SDimitry Andric   if (target_sp) {
17430b57cec5SDimitry Andric     return target_sp->GetArchitecture().GetDataByteSize();
17440b57cec5SDimitry Andric   }
17450b57cec5SDimitry Andric   return 0;
17460b57cec5SDimitry Andric }
17470b57cec5SDimitry Andric 
GetCodeByteSize()17480b57cec5SDimitry Andric uint32_t SBTarget::GetCodeByteSize() {
17490b57cec5SDimitry Andric   LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBTarget, GetCodeByteSize);
17500b57cec5SDimitry Andric 
17510b57cec5SDimitry Andric   TargetSP target_sp(GetSP());
17520b57cec5SDimitry Andric   if (target_sp) {
17530b57cec5SDimitry Andric     return target_sp->GetArchitecture().GetCodeByteSize();
17540b57cec5SDimitry Andric   }
17550b57cec5SDimitry Andric   return 0;
17560b57cec5SDimitry Andric }
17570b57cec5SDimitry Andric 
GetAddressByteSize()17580b57cec5SDimitry Andric uint32_t SBTarget::GetAddressByteSize() {
17590b57cec5SDimitry Andric   LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBTarget, GetAddressByteSize);
17600b57cec5SDimitry Andric 
17610b57cec5SDimitry Andric   TargetSP target_sp(GetSP());
17620b57cec5SDimitry Andric   if (target_sp)
17630b57cec5SDimitry Andric     return target_sp->GetArchitecture().GetAddressByteSize();
17640b57cec5SDimitry Andric   return sizeof(void *);
17650b57cec5SDimitry Andric }
17660b57cec5SDimitry Andric 
GetModuleAtIndex(uint32_t idx)17670b57cec5SDimitry Andric SBModule SBTarget::GetModuleAtIndex(uint32_t idx) {
17680b57cec5SDimitry Andric   LLDB_RECORD_METHOD(lldb::SBModule, SBTarget, GetModuleAtIndex, (uint32_t),
17690b57cec5SDimitry Andric                      idx);
17700b57cec5SDimitry Andric 
17710b57cec5SDimitry Andric   SBModule sb_module;
17720b57cec5SDimitry Andric   ModuleSP module_sp;
17730b57cec5SDimitry Andric   TargetSP target_sp(GetSP());
17740b57cec5SDimitry Andric   if (target_sp) {
17750b57cec5SDimitry Andric     // The module list is thread safe, no need to lock
17760b57cec5SDimitry Andric     module_sp = target_sp->GetImages().GetModuleAtIndex(idx);
17770b57cec5SDimitry Andric     sb_module.SetSP(module_sp);
17780b57cec5SDimitry Andric   }
17790b57cec5SDimitry Andric 
17800b57cec5SDimitry Andric   return LLDB_RECORD_RESULT(sb_module);
17810b57cec5SDimitry Andric }
17820b57cec5SDimitry Andric 
RemoveModule(lldb::SBModule module)17830b57cec5SDimitry Andric bool SBTarget::RemoveModule(lldb::SBModule module) {
17840b57cec5SDimitry Andric   LLDB_RECORD_METHOD(bool, SBTarget, RemoveModule, (lldb::SBModule), module);
17850b57cec5SDimitry Andric 
17860b57cec5SDimitry Andric   TargetSP target_sp(GetSP());
17870b57cec5SDimitry Andric   if (target_sp)
17880b57cec5SDimitry Andric     return target_sp->GetImages().Remove(module.GetSP());
17890b57cec5SDimitry Andric   return false;
17900b57cec5SDimitry Andric }
17910b57cec5SDimitry Andric 
GetBroadcaster() const17920b57cec5SDimitry Andric SBBroadcaster SBTarget::GetBroadcaster() const {
17930b57cec5SDimitry Andric   LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::SBBroadcaster, SBTarget,
17940b57cec5SDimitry Andric                                    GetBroadcaster);
17950b57cec5SDimitry Andric 
17960b57cec5SDimitry Andric 
17970b57cec5SDimitry Andric   TargetSP target_sp(GetSP());
17980b57cec5SDimitry Andric   SBBroadcaster broadcaster(target_sp.get(), false);
17990b57cec5SDimitry Andric 
18000b57cec5SDimitry Andric 
18010b57cec5SDimitry Andric   return LLDB_RECORD_RESULT(broadcaster);
18020b57cec5SDimitry Andric }
18030b57cec5SDimitry Andric 
GetDescription(SBStream & description,lldb::DescriptionLevel description_level)18040b57cec5SDimitry Andric bool SBTarget::GetDescription(SBStream &description,
18050b57cec5SDimitry Andric                               lldb::DescriptionLevel description_level) {
18060b57cec5SDimitry Andric   LLDB_RECORD_METHOD(bool, SBTarget, GetDescription,
18070b57cec5SDimitry Andric                      (lldb::SBStream &, lldb::DescriptionLevel), description,
18080b57cec5SDimitry Andric                      description_level);
18090b57cec5SDimitry Andric 
18100b57cec5SDimitry Andric   Stream &strm = description.ref();
18110b57cec5SDimitry Andric 
18120b57cec5SDimitry Andric   TargetSP target_sp(GetSP());
18130b57cec5SDimitry Andric   if (target_sp) {
18140b57cec5SDimitry Andric     target_sp->Dump(&strm, description_level);
18150b57cec5SDimitry Andric   } else
18160b57cec5SDimitry Andric     strm.PutCString("No value");
18170b57cec5SDimitry Andric 
18180b57cec5SDimitry Andric   return true;
18190b57cec5SDimitry Andric }
18200b57cec5SDimitry Andric 
FindFunctions(const char * name,uint32_t name_type_mask)18210b57cec5SDimitry Andric lldb::SBSymbolContextList SBTarget::FindFunctions(const char *name,
18220b57cec5SDimitry Andric                                                   uint32_t name_type_mask) {
18230b57cec5SDimitry Andric   LLDB_RECORD_METHOD(lldb::SBSymbolContextList, SBTarget, FindFunctions,
18240b57cec5SDimitry Andric                      (const char *, uint32_t), name, name_type_mask);
18250b57cec5SDimitry Andric 
18260b57cec5SDimitry Andric   lldb::SBSymbolContextList sb_sc_list;
1827af732203SDimitry Andric   if (!name || !name[0])
18280b57cec5SDimitry Andric     return LLDB_RECORD_RESULT(sb_sc_list);
18290b57cec5SDimitry Andric 
18300b57cec5SDimitry Andric   TargetSP target_sp(GetSP());
18310b57cec5SDimitry Andric   if (!target_sp)
18320b57cec5SDimitry Andric     return LLDB_RECORD_RESULT(sb_sc_list);
18330b57cec5SDimitry Andric 
18340b57cec5SDimitry Andric   const bool symbols_ok = true;
18350b57cec5SDimitry Andric   const bool inlines_ok = true;
18360b57cec5SDimitry Andric   FunctionNameType mask = static_cast<FunctionNameType>(name_type_mask);
18370b57cec5SDimitry Andric   target_sp->GetImages().FindFunctions(ConstString(name), mask, symbols_ok,
18389dba64beSDimitry Andric                                        inlines_ok, *sb_sc_list);
18390b57cec5SDimitry Andric   return LLDB_RECORD_RESULT(sb_sc_list);
18400b57cec5SDimitry Andric }
18410b57cec5SDimitry Andric 
FindGlobalFunctions(const char * name,uint32_t max_matches,MatchType matchtype)18420b57cec5SDimitry Andric lldb::SBSymbolContextList SBTarget::FindGlobalFunctions(const char *name,
18430b57cec5SDimitry Andric                                                         uint32_t max_matches,
18440b57cec5SDimitry Andric                                                         MatchType matchtype) {
18450b57cec5SDimitry Andric   LLDB_RECORD_METHOD(lldb::SBSymbolContextList, SBTarget, FindGlobalFunctions,
18460b57cec5SDimitry Andric                      (const char *, uint32_t, lldb::MatchType), name,
18470b57cec5SDimitry Andric                      max_matches, matchtype);
18480b57cec5SDimitry Andric 
18490b57cec5SDimitry Andric   lldb::SBSymbolContextList sb_sc_list;
18500b57cec5SDimitry Andric   if (name && name[0]) {
18510b57cec5SDimitry Andric     llvm::StringRef name_ref(name);
18520b57cec5SDimitry Andric     TargetSP target_sp(GetSP());
18530b57cec5SDimitry Andric     if (target_sp) {
18540b57cec5SDimitry Andric       std::string regexstr;
18550b57cec5SDimitry Andric       switch (matchtype) {
18560b57cec5SDimitry Andric       case eMatchTypeRegex:
18570b57cec5SDimitry Andric         target_sp->GetImages().FindFunctions(RegularExpression(name_ref), true,
18589dba64beSDimitry Andric                                              true, *sb_sc_list);
18590b57cec5SDimitry Andric         break;
18600b57cec5SDimitry Andric       case eMatchTypeStartsWith:
18610b57cec5SDimitry Andric         regexstr = llvm::Regex::escape(name) + ".*";
18620b57cec5SDimitry Andric         target_sp->GetImages().FindFunctions(RegularExpression(regexstr), true,
18639dba64beSDimitry Andric                                              true, *sb_sc_list);
18640b57cec5SDimitry Andric         break;
18650b57cec5SDimitry Andric       default:
18669dba64beSDimitry Andric         target_sp->GetImages().FindFunctions(
18679dba64beSDimitry Andric             ConstString(name), eFunctionNameTypeAny, true, true, *sb_sc_list);
18680b57cec5SDimitry Andric         break;
18690b57cec5SDimitry Andric       }
18700b57cec5SDimitry Andric     }
18710b57cec5SDimitry Andric   }
18720b57cec5SDimitry Andric   return LLDB_RECORD_RESULT(sb_sc_list);
18730b57cec5SDimitry Andric }
18740b57cec5SDimitry Andric 
FindFirstType(const char * typename_cstr)18750b57cec5SDimitry Andric lldb::SBType SBTarget::FindFirstType(const char *typename_cstr) {
18760b57cec5SDimitry Andric   LLDB_RECORD_METHOD(lldb::SBType, SBTarget, FindFirstType, (const char *),
18770b57cec5SDimitry Andric                      typename_cstr);
18780b57cec5SDimitry Andric 
18790b57cec5SDimitry Andric   TargetSP target_sp(GetSP());
18800b57cec5SDimitry Andric   if (typename_cstr && typename_cstr[0] && target_sp) {
18810b57cec5SDimitry Andric     ConstString const_typename(typename_cstr);
18820b57cec5SDimitry Andric     SymbolContext sc;
18830b57cec5SDimitry Andric     const bool exact_match = false;
18840b57cec5SDimitry Andric 
18850b57cec5SDimitry Andric     const ModuleList &module_list = target_sp->GetImages();
18860b57cec5SDimitry Andric     size_t count = module_list.GetSize();
18870b57cec5SDimitry Andric     for (size_t idx = 0; idx < count; idx++) {
18880b57cec5SDimitry Andric       ModuleSP module_sp(module_list.GetModuleAtIndex(idx));
18890b57cec5SDimitry Andric       if (module_sp) {
18900b57cec5SDimitry Andric         TypeSP type_sp(
18910b57cec5SDimitry Andric             module_sp->FindFirstType(sc, const_typename, exact_match));
18920b57cec5SDimitry Andric         if (type_sp)
18930b57cec5SDimitry Andric           return LLDB_RECORD_RESULT(SBType(type_sp));
18940b57cec5SDimitry Andric       }
18950b57cec5SDimitry Andric     }
18960b57cec5SDimitry Andric 
18970b57cec5SDimitry Andric     // Didn't find the type in the symbols; Try the loaded language runtimes
18980b57cec5SDimitry Andric     if (auto process_sp = target_sp->GetProcessSP()) {
18990b57cec5SDimitry Andric       for (auto *runtime : process_sp->GetLanguageRuntimes()) {
19000b57cec5SDimitry Andric         if (auto vendor = runtime->GetDeclVendor()) {
19010b57cec5SDimitry Andric           auto types = vendor->FindTypes(const_typename, /*max_matches*/ 1);
19020b57cec5SDimitry Andric           if (!types.empty())
19030b57cec5SDimitry Andric             return LLDB_RECORD_RESULT(SBType(types.front()));
19040b57cec5SDimitry Andric         }
19050b57cec5SDimitry Andric       }
19060b57cec5SDimitry Andric     }
19070b57cec5SDimitry Andric 
19080b57cec5SDimitry Andric     // No matches, search for basic typename matches
19099dba64beSDimitry Andric     for (auto *type_system : target_sp->GetScratchTypeSystems())
19109dba64beSDimitry Andric       if (auto type = type_system->GetBuiltinTypeByName(const_typename))
19119dba64beSDimitry Andric         return LLDB_RECORD_RESULT(SBType(type));
19120b57cec5SDimitry Andric   }
19139dba64beSDimitry Andric 
19140b57cec5SDimitry Andric   return LLDB_RECORD_RESULT(SBType());
19150b57cec5SDimitry Andric }
19160b57cec5SDimitry Andric 
GetBasicType(lldb::BasicType type)19170b57cec5SDimitry Andric SBType SBTarget::GetBasicType(lldb::BasicType type) {
19180b57cec5SDimitry Andric   LLDB_RECORD_METHOD(lldb::SBType, SBTarget, GetBasicType, (lldb::BasicType),
19190b57cec5SDimitry Andric                      type);
19200b57cec5SDimitry Andric 
19210b57cec5SDimitry Andric   TargetSP target_sp(GetSP());
19220b57cec5SDimitry Andric   if (target_sp) {
19239dba64beSDimitry Andric     for (auto *type_system : target_sp->GetScratchTypeSystems())
19249dba64beSDimitry Andric       if (auto compiler_type = type_system->GetBasicTypeFromAST(type))
19259dba64beSDimitry Andric         return LLDB_RECORD_RESULT(SBType(compiler_type));
19260b57cec5SDimitry Andric   }
19270b57cec5SDimitry Andric   return LLDB_RECORD_RESULT(SBType());
19280b57cec5SDimitry Andric }
19290b57cec5SDimitry Andric 
FindTypes(const char * typename_cstr)19300b57cec5SDimitry Andric lldb::SBTypeList SBTarget::FindTypes(const char *typename_cstr) {
19310b57cec5SDimitry Andric   LLDB_RECORD_METHOD(lldb::SBTypeList, SBTarget, FindTypes, (const char *),
19320b57cec5SDimitry Andric                      typename_cstr);
19330b57cec5SDimitry Andric 
19340b57cec5SDimitry Andric   SBTypeList sb_type_list;
19350b57cec5SDimitry Andric   TargetSP target_sp(GetSP());
19360b57cec5SDimitry Andric   if (typename_cstr && typename_cstr[0] && target_sp) {
19370b57cec5SDimitry Andric     ModuleList &images = target_sp->GetImages();
19380b57cec5SDimitry Andric     ConstString const_typename(typename_cstr);
19390b57cec5SDimitry Andric     bool exact_match = false;
19400b57cec5SDimitry Andric     TypeList type_list;
19410b57cec5SDimitry Andric     llvm::DenseSet<SymbolFile *> searched_symbol_files;
19420b57cec5SDimitry Andric     images.FindTypes(nullptr, const_typename, exact_match, UINT32_MAX,
19430b57cec5SDimitry Andric                      searched_symbol_files, type_list);
19440b57cec5SDimitry Andric 
19459dba64beSDimitry Andric     for (size_t idx = 0; idx < type_list.GetSize(); idx++) {
19460b57cec5SDimitry Andric       TypeSP type_sp(type_list.GetTypeAtIndex(idx));
19470b57cec5SDimitry Andric       if (type_sp)
19480b57cec5SDimitry Andric         sb_type_list.Append(SBType(type_sp));
19490b57cec5SDimitry Andric     }
19500b57cec5SDimitry Andric 
19510b57cec5SDimitry Andric     // Try the loaded language runtimes
19520b57cec5SDimitry Andric     if (auto process_sp = target_sp->GetProcessSP()) {
19530b57cec5SDimitry Andric       for (auto *runtime : process_sp->GetLanguageRuntimes()) {
19540b57cec5SDimitry Andric         if (auto *vendor = runtime->GetDeclVendor()) {
19550b57cec5SDimitry Andric           auto types =
19560b57cec5SDimitry Andric               vendor->FindTypes(const_typename, /*max_matches*/ UINT32_MAX);
19570b57cec5SDimitry Andric           for (auto type : types)
19580b57cec5SDimitry Andric             sb_type_list.Append(SBType(type));
19590b57cec5SDimitry Andric         }
19600b57cec5SDimitry Andric       }
19610b57cec5SDimitry Andric     }
19620b57cec5SDimitry Andric 
19630b57cec5SDimitry Andric     if (sb_type_list.GetSize() == 0) {
19640b57cec5SDimitry Andric       // No matches, search for basic typename matches
19659dba64beSDimitry Andric       for (auto *type_system : target_sp->GetScratchTypeSystems())
19669dba64beSDimitry Andric         if (auto compiler_type =
19679dba64beSDimitry Andric                 type_system->GetBuiltinTypeByName(const_typename))
19689dba64beSDimitry Andric           sb_type_list.Append(SBType(compiler_type));
19690b57cec5SDimitry Andric     }
19700b57cec5SDimitry Andric   }
19710b57cec5SDimitry Andric   return LLDB_RECORD_RESULT(sb_type_list);
19720b57cec5SDimitry Andric }
19730b57cec5SDimitry Andric 
FindGlobalVariables(const char * name,uint32_t max_matches)19740b57cec5SDimitry Andric SBValueList SBTarget::FindGlobalVariables(const char *name,
19750b57cec5SDimitry Andric                                           uint32_t max_matches) {
19760b57cec5SDimitry Andric   LLDB_RECORD_METHOD(lldb::SBValueList, SBTarget, FindGlobalVariables,
19770b57cec5SDimitry Andric                      (const char *, uint32_t), name, max_matches);
19780b57cec5SDimitry Andric 
19790b57cec5SDimitry Andric   SBValueList sb_value_list;
19800b57cec5SDimitry Andric 
19810b57cec5SDimitry Andric   TargetSP target_sp(GetSP());
19820b57cec5SDimitry Andric   if (name && target_sp) {
19830b57cec5SDimitry Andric     VariableList variable_list;
19849dba64beSDimitry Andric     target_sp->GetImages().FindGlobalVariables(ConstString(name), max_matches,
19859dba64beSDimitry Andric                                                variable_list);
1986480093f4SDimitry Andric     if (!variable_list.Empty()) {
19870b57cec5SDimitry Andric       ExecutionContextScope *exe_scope = target_sp->GetProcessSP().get();
19880b57cec5SDimitry Andric       if (exe_scope == nullptr)
19890b57cec5SDimitry Andric         exe_scope = target_sp.get();
1990480093f4SDimitry Andric       for (const VariableSP &var_sp : variable_list) {
1991480093f4SDimitry Andric         lldb::ValueObjectSP valobj_sp(
1992480093f4SDimitry Andric             ValueObjectVariable::Create(exe_scope, var_sp));
19930b57cec5SDimitry Andric         if (valobj_sp)
19940b57cec5SDimitry Andric           sb_value_list.Append(SBValue(valobj_sp));
19950b57cec5SDimitry Andric       }
19960b57cec5SDimitry Andric     }
19970b57cec5SDimitry Andric   }
19980b57cec5SDimitry Andric 
19990b57cec5SDimitry Andric   return LLDB_RECORD_RESULT(sb_value_list);
20000b57cec5SDimitry Andric }
20010b57cec5SDimitry Andric 
FindGlobalVariables(const char * name,uint32_t max_matches,MatchType matchtype)20020b57cec5SDimitry Andric SBValueList SBTarget::FindGlobalVariables(const char *name,
20030b57cec5SDimitry Andric                                           uint32_t max_matches,
20040b57cec5SDimitry Andric                                           MatchType matchtype) {
20050b57cec5SDimitry Andric   LLDB_RECORD_METHOD(lldb::SBValueList, SBTarget, FindGlobalVariables,
20060b57cec5SDimitry Andric                      (const char *, uint32_t, lldb::MatchType), name,
20070b57cec5SDimitry Andric                      max_matches, matchtype);
20080b57cec5SDimitry Andric 
20090b57cec5SDimitry Andric   SBValueList sb_value_list;
20100b57cec5SDimitry Andric 
20110b57cec5SDimitry Andric   TargetSP target_sp(GetSP());
20120b57cec5SDimitry Andric   if (name && target_sp) {
20130b57cec5SDimitry Andric     llvm::StringRef name_ref(name);
20140b57cec5SDimitry Andric     VariableList variable_list;
20150b57cec5SDimitry Andric 
20160b57cec5SDimitry Andric     std::string regexstr;
20170b57cec5SDimitry Andric     switch (matchtype) {
20180b57cec5SDimitry Andric     case eMatchTypeNormal:
20199dba64beSDimitry Andric       target_sp->GetImages().FindGlobalVariables(ConstString(name), max_matches,
20209dba64beSDimitry Andric                                                  variable_list);
20210b57cec5SDimitry Andric       break;
20220b57cec5SDimitry Andric     case eMatchTypeRegex:
20239dba64beSDimitry Andric       target_sp->GetImages().FindGlobalVariables(RegularExpression(name_ref),
20249dba64beSDimitry Andric                                                  max_matches, variable_list);
20250b57cec5SDimitry Andric       break;
20260b57cec5SDimitry Andric     case eMatchTypeStartsWith:
20270b57cec5SDimitry Andric       regexstr = llvm::Regex::escape(name) + ".*";
20289dba64beSDimitry Andric       target_sp->GetImages().FindGlobalVariables(RegularExpression(regexstr),
20299dba64beSDimitry Andric                                                  max_matches, variable_list);
20300b57cec5SDimitry Andric       break;
20310b57cec5SDimitry Andric     }
2032480093f4SDimitry Andric     if (!variable_list.Empty()) {
20330b57cec5SDimitry Andric       ExecutionContextScope *exe_scope = target_sp->GetProcessSP().get();
20340b57cec5SDimitry Andric       if (exe_scope == nullptr)
20350b57cec5SDimitry Andric         exe_scope = target_sp.get();
2036480093f4SDimitry Andric       for (const VariableSP &var_sp : variable_list) {
2037480093f4SDimitry Andric         lldb::ValueObjectSP valobj_sp(
2038480093f4SDimitry Andric             ValueObjectVariable::Create(exe_scope, var_sp));
20390b57cec5SDimitry Andric         if (valobj_sp)
20400b57cec5SDimitry Andric           sb_value_list.Append(SBValue(valobj_sp));
20410b57cec5SDimitry Andric       }
20420b57cec5SDimitry Andric     }
20430b57cec5SDimitry Andric   }
20440b57cec5SDimitry Andric 
20450b57cec5SDimitry Andric   return LLDB_RECORD_RESULT(sb_value_list);
20460b57cec5SDimitry Andric }
20470b57cec5SDimitry Andric 
FindFirstGlobalVariable(const char * name)20480b57cec5SDimitry Andric lldb::SBValue SBTarget::FindFirstGlobalVariable(const char *name) {
20490b57cec5SDimitry Andric   LLDB_RECORD_METHOD(lldb::SBValue, SBTarget, FindFirstGlobalVariable,
20500b57cec5SDimitry Andric                      (const char *), name);
20510b57cec5SDimitry Andric 
20520b57cec5SDimitry Andric   SBValueList sb_value_list(FindGlobalVariables(name, 1));
20530b57cec5SDimitry Andric   if (sb_value_list.IsValid() && sb_value_list.GetSize() > 0)
20540b57cec5SDimitry Andric     return LLDB_RECORD_RESULT(sb_value_list.GetValueAtIndex(0));
20550b57cec5SDimitry Andric   return LLDB_RECORD_RESULT(SBValue());
20560b57cec5SDimitry Andric }
20570b57cec5SDimitry Andric 
GetSourceManager()20580b57cec5SDimitry Andric SBSourceManager SBTarget::GetSourceManager() {
20590b57cec5SDimitry Andric   LLDB_RECORD_METHOD_NO_ARGS(lldb::SBSourceManager, SBTarget, GetSourceManager);
20600b57cec5SDimitry Andric 
20610b57cec5SDimitry Andric   SBSourceManager source_manager(*this);
20620b57cec5SDimitry Andric   return LLDB_RECORD_RESULT(source_manager);
20630b57cec5SDimitry Andric }
20640b57cec5SDimitry Andric 
ReadInstructions(lldb::SBAddress base_addr,uint32_t count)20650b57cec5SDimitry Andric lldb::SBInstructionList SBTarget::ReadInstructions(lldb::SBAddress base_addr,
20660b57cec5SDimitry Andric                                                    uint32_t count) {
20670b57cec5SDimitry Andric   LLDB_RECORD_METHOD(lldb::SBInstructionList, SBTarget, ReadInstructions,
20680b57cec5SDimitry Andric                      (lldb::SBAddress, uint32_t), base_addr, count);
20690b57cec5SDimitry Andric 
20700b57cec5SDimitry Andric   return LLDB_RECORD_RESULT(ReadInstructions(base_addr, count, nullptr));
20710b57cec5SDimitry Andric }
20720b57cec5SDimitry Andric 
ReadInstructions(lldb::SBAddress base_addr,uint32_t count,const char * flavor_string)20730b57cec5SDimitry Andric lldb::SBInstructionList SBTarget::ReadInstructions(lldb::SBAddress base_addr,
20740b57cec5SDimitry Andric                                                    uint32_t count,
20750b57cec5SDimitry Andric                                                    const char *flavor_string) {
20760b57cec5SDimitry Andric   LLDB_RECORD_METHOD(lldb::SBInstructionList, SBTarget, ReadInstructions,
20770b57cec5SDimitry Andric                      (lldb::SBAddress, uint32_t, const char *), base_addr,
20780b57cec5SDimitry Andric                      count, flavor_string);
20790b57cec5SDimitry Andric 
20800b57cec5SDimitry Andric   SBInstructionList sb_instructions;
20810b57cec5SDimitry Andric 
20820b57cec5SDimitry Andric   TargetSP target_sp(GetSP());
20830b57cec5SDimitry Andric   if (target_sp) {
20840b57cec5SDimitry Andric     Address *addr_ptr = base_addr.get();
20850b57cec5SDimitry Andric 
20860b57cec5SDimitry Andric     if (addr_ptr) {
20870b57cec5SDimitry Andric       DataBufferHeap data(
20880b57cec5SDimitry Andric           target_sp->GetArchitecture().GetMaximumOpcodeByteSize() * count, 0);
2089*5f7ddb14SDimitry Andric       bool force_live_memory = true;
20900b57cec5SDimitry Andric       lldb_private::Status error;
20910b57cec5SDimitry Andric       lldb::addr_t load_addr = LLDB_INVALID_ADDRESS;
20920b57cec5SDimitry Andric       const size_t bytes_read =
2093*5f7ddb14SDimitry Andric           target_sp->ReadMemory(*addr_ptr, data.GetBytes(), data.GetByteSize(),
2094*5f7ddb14SDimitry Andric                                 error, force_live_memory, &load_addr);
20950b57cec5SDimitry Andric       const bool data_from_file = load_addr == LLDB_INVALID_ADDRESS;
20960b57cec5SDimitry Andric       sb_instructions.SetDisassembler(Disassembler::DisassembleBytes(
20970b57cec5SDimitry Andric           target_sp->GetArchitecture(), nullptr, flavor_string, *addr_ptr,
20980b57cec5SDimitry Andric           data.GetBytes(), bytes_read, count, data_from_file));
20990b57cec5SDimitry Andric     }
21000b57cec5SDimitry Andric   }
21010b57cec5SDimitry Andric 
21020b57cec5SDimitry Andric   return LLDB_RECORD_RESULT(sb_instructions);
21030b57cec5SDimitry Andric }
21040b57cec5SDimitry Andric 
GetInstructions(lldb::SBAddress base_addr,const void * buf,size_t size)21050b57cec5SDimitry Andric lldb::SBInstructionList SBTarget::GetInstructions(lldb::SBAddress base_addr,
21060b57cec5SDimitry Andric                                                   const void *buf,
21070b57cec5SDimitry Andric                                                   size_t size) {
21085ffd83dbSDimitry Andric   LLDB_RECORD_METHOD(lldb::SBInstructionList, SBTarget, GetInstructions,
21090b57cec5SDimitry Andric                      (lldb::SBAddress, const void *, size_t), base_addr, buf,
21100b57cec5SDimitry Andric                      size);
21110b57cec5SDimitry Andric 
21125ffd83dbSDimitry Andric   return LLDB_RECORD_RESULT(
21135ffd83dbSDimitry Andric       GetInstructionsWithFlavor(base_addr, nullptr, buf, size));
21140b57cec5SDimitry Andric }
21150b57cec5SDimitry Andric 
21160b57cec5SDimitry Andric lldb::SBInstructionList
GetInstructionsWithFlavor(lldb::SBAddress base_addr,const char * flavor_string,const void * buf,size_t size)21170b57cec5SDimitry Andric SBTarget::GetInstructionsWithFlavor(lldb::SBAddress base_addr,
21180b57cec5SDimitry Andric                                     const char *flavor_string, const void *buf,
21190b57cec5SDimitry Andric                                     size_t size) {
21205ffd83dbSDimitry Andric   LLDB_RECORD_METHOD(lldb::SBInstructionList, SBTarget,
21210b57cec5SDimitry Andric                      GetInstructionsWithFlavor,
21220b57cec5SDimitry Andric                      (lldb::SBAddress, const char *, const void *, size_t),
21230b57cec5SDimitry Andric                      base_addr, flavor_string, buf, size);
21240b57cec5SDimitry Andric 
21250b57cec5SDimitry Andric   SBInstructionList sb_instructions;
21260b57cec5SDimitry Andric 
21270b57cec5SDimitry Andric   TargetSP target_sp(GetSP());
21280b57cec5SDimitry Andric   if (target_sp) {
21290b57cec5SDimitry Andric     Address addr;
21300b57cec5SDimitry Andric 
21310b57cec5SDimitry Andric     if (base_addr.get())
21320b57cec5SDimitry Andric       addr = *base_addr.get();
21330b57cec5SDimitry Andric 
21340b57cec5SDimitry Andric     const bool data_from_file = true;
21350b57cec5SDimitry Andric 
21360b57cec5SDimitry Andric     sb_instructions.SetDisassembler(Disassembler::DisassembleBytes(
21370b57cec5SDimitry Andric         target_sp->GetArchitecture(), nullptr, flavor_string, addr, buf, size,
21380b57cec5SDimitry Andric         UINT32_MAX, data_from_file));
21390b57cec5SDimitry Andric   }
21400b57cec5SDimitry Andric 
21415ffd83dbSDimitry Andric   return LLDB_RECORD_RESULT(sb_instructions);
21420b57cec5SDimitry Andric }
21430b57cec5SDimitry Andric 
GetInstructions(lldb::addr_t base_addr,const void * buf,size_t size)21440b57cec5SDimitry Andric lldb::SBInstructionList SBTarget::GetInstructions(lldb::addr_t base_addr,
21450b57cec5SDimitry Andric                                                   const void *buf,
21460b57cec5SDimitry Andric                                                   size_t size) {
21475ffd83dbSDimitry Andric   LLDB_RECORD_METHOD(lldb::SBInstructionList, SBTarget, GetInstructions,
21485ffd83dbSDimitry Andric                      (lldb::addr_t, const void *, size_t), base_addr, buf,
21490b57cec5SDimitry Andric                      size);
21505ffd83dbSDimitry Andric 
21515ffd83dbSDimitry Andric   return LLDB_RECORD_RESULT(GetInstructionsWithFlavor(
21525ffd83dbSDimitry Andric       ResolveLoadAddress(base_addr), nullptr, buf, size));
21530b57cec5SDimitry Andric }
21540b57cec5SDimitry Andric 
21550b57cec5SDimitry Andric lldb::SBInstructionList
GetInstructionsWithFlavor(lldb::addr_t base_addr,const char * flavor_string,const void * buf,size_t size)21560b57cec5SDimitry Andric SBTarget::GetInstructionsWithFlavor(lldb::addr_t base_addr,
21570b57cec5SDimitry Andric                                     const char *flavor_string, const void *buf,
21580b57cec5SDimitry Andric                                     size_t size) {
21595ffd83dbSDimitry Andric   LLDB_RECORD_METHOD(lldb::SBInstructionList, SBTarget,
21600b57cec5SDimitry Andric                      GetInstructionsWithFlavor,
21610b57cec5SDimitry Andric                      (lldb::addr_t, const char *, const void *, size_t),
21620b57cec5SDimitry Andric                      base_addr, flavor_string, buf, size);
21630b57cec5SDimitry Andric 
21645ffd83dbSDimitry Andric   return LLDB_RECORD_RESULT(GetInstructionsWithFlavor(
21655ffd83dbSDimitry Andric       ResolveLoadAddress(base_addr), flavor_string, buf, size));
21660b57cec5SDimitry Andric }
21670b57cec5SDimitry Andric 
SetSectionLoadAddress(lldb::SBSection section,lldb::addr_t section_base_addr)21680b57cec5SDimitry Andric SBError SBTarget::SetSectionLoadAddress(lldb::SBSection section,
21690b57cec5SDimitry Andric                                         lldb::addr_t section_base_addr) {
21700b57cec5SDimitry Andric   LLDB_RECORD_METHOD(lldb::SBError, SBTarget, SetSectionLoadAddress,
21710b57cec5SDimitry Andric                      (lldb::SBSection, lldb::addr_t), section,
21720b57cec5SDimitry Andric                      section_base_addr);
21730b57cec5SDimitry Andric 
21740b57cec5SDimitry Andric   SBError sb_error;
21750b57cec5SDimitry Andric   TargetSP target_sp(GetSP());
21760b57cec5SDimitry Andric   if (target_sp) {
21770b57cec5SDimitry Andric     if (!section.IsValid()) {
21780b57cec5SDimitry Andric       sb_error.SetErrorStringWithFormat("invalid section");
21790b57cec5SDimitry Andric     } else {
21800b57cec5SDimitry Andric       SectionSP section_sp(section.GetSP());
21810b57cec5SDimitry Andric       if (section_sp) {
21820b57cec5SDimitry Andric         if (section_sp->IsThreadSpecific()) {
21830b57cec5SDimitry Andric           sb_error.SetErrorString(
21840b57cec5SDimitry Andric               "thread specific sections are not yet supported");
21850b57cec5SDimitry Andric         } else {
21860b57cec5SDimitry Andric           ProcessSP process_sp(target_sp->GetProcessSP());
21870b57cec5SDimitry Andric           if (target_sp->SetSectionLoadAddress(section_sp, section_base_addr)) {
21880b57cec5SDimitry Andric             ModuleSP module_sp(section_sp->GetModule());
21890b57cec5SDimitry Andric             if (module_sp) {
21900b57cec5SDimitry Andric               ModuleList module_list;
21910b57cec5SDimitry Andric               module_list.Append(module_sp);
21920b57cec5SDimitry Andric               target_sp->ModulesDidLoad(module_list);
21930b57cec5SDimitry Andric             }
21940b57cec5SDimitry Andric             // Flush info in the process (stack frames, etc)
21950b57cec5SDimitry Andric             if (process_sp)
21960b57cec5SDimitry Andric               process_sp->Flush();
21970b57cec5SDimitry Andric           }
21980b57cec5SDimitry Andric         }
21990b57cec5SDimitry Andric       }
22000b57cec5SDimitry Andric     }
22010b57cec5SDimitry Andric   } else {
22020b57cec5SDimitry Andric     sb_error.SetErrorString("invalid target");
22030b57cec5SDimitry Andric   }
22040b57cec5SDimitry Andric   return LLDB_RECORD_RESULT(sb_error);
22050b57cec5SDimitry Andric }
22060b57cec5SDimitry Andric 
ClearSectionLoadAddress(lldb::SBSection section)22070b57cec5SDimitry Andric SBError SBTarget::ClearSectionLoadAddress(lldb::SBSection section) {
22080b57cec5SDimitry Andric   LLDB_RECORD_METHOD(lldb::SBError, SBTarget, ClearSectionLoadAddress,
22090b57cec5SDimitry Andric                      (lldb::SBSection), section);
22100b57cec5SDimitry Andric 
22110b57cec5SDimitry Andric   SBError sb_error;
22120b57cec5SDimitry Andric 
22130b57cec5SDimitry Andric   TargetSP target_sp(GetSP());
22140b57cec5SDimitry Andric   if (target_sp) {
22150b57cec5SDimitry Andric     if (!section.IsValid()) {
22160b57cec5SDimitry Andric       sb_error.SetErrorStringWithFormat("invalid section");
22170b57cec5SDimitry Andric     } else {
22180b57cec5SDimitry Andric       SectionSP section_sp(section.GetSP());
22190b57cec5SDimitry Andric       if (section_sp) {
22200b57cec5SDimitry Andric         ProcessSP process_sp(target_sp->GetProcessSP());
22210b57cec5SDimitry Andric         if (target_sp->SetSectionUnloaded(section_sp)) {
22220b57cec5SDimitry Andric           ModuleSP module_sp(section_sp->GetModule());
22230b57cec5SDimitry Andric           if (module_sp) {
22240b57cec5SDimitry Andric             ModuleList module_list;
22250b57cec5SDimitry Andric             module_list.Append(module_sp);
22260b57cec5SDimitry Andric             target_sp->ModulesDidUnload(module_list, false);
22270b57cec5SDimitry Andric           }
22280b57cec5SDimitry Andric           // Flush info in the process (stack frames, etc)
22290b57cec5SDimitry Andric           if (process_sp)
22300b57cec5SDimitry Andric             process_sp->Flush();
22310b57cec5SDimitry Andric         }
22320b57cec5SDimitry Andric       } else {
22330b57cec5SDimitry Andric         sb_error.SetErrorStringWithFormat("invalid section");
22340b57cec5SDimitry Andric       }
22350b57cec5SDimitry Andric     }
22360b57cec5SDimitry Andric   } else {
22370b57cec5SDimitry Andric     sb_error.SetErrorStringWithFormat("invalid target");
22380b57cec5SDimitry Andric   }
22390b57cec5SDimitry Andric   return LLDB_RECORD_RESULT(sb_error);
22400b57cec5SDimitry Andric }
22410b57cec5SDimitry Andric 
SetModuleLoadAddress(lldb::SBModule module,int64_t slide_offset)22420b57cec5SDimitry Andric SBError SBTarget::SetModuleLoadAddress(lldb::SBModule module,
22430b57cec5SDimitry Andric                                        int64_t slide_offset) {
22440b57cec5SDimitry Andric   LLDB_RECORD_METHOD(lldb::SBError, SBTarget, SetModuleLoadAddress,
22450b57cec5SDimitry Andric                      (lldb::SBModule, int64_t), module, slide_offset);
22460b57cec5SDimitry Andric 
22470b57cec5SDimitry Andric   SBError sb_error;
22480b57cec5SDimitry Andric 
22490b57cec5SDimitry Andric   TargetSP target_sp(GetSP());
22500b57cec5SDimitry Andric   if (target_sp) {
22510b57cec5SDimitry Andric     ModuleSP module_sp(module.GetSP());
22520b57cec5SDimitry Andric     if (module_sp) {
22530b57cec5SDimitry Andric       bool changed = false;
22540b57cec5SDimitry Andric       if (module_sp->SetLoadAddress(*target_sp, slide_offset, true, changed)) {
22550b57cec5SDimitry Andric         // The load was successful, make sure that at least some sections
22560b57cec5SDimitry Andric         // changed before we notify that our module was loaded.
22570b57cec5SDimitry Andric         if (changed) {
22580b57cec5SDimitry Andric           ModuleList module_list;
22590b57cec5SDimitry Andric           module_list.Append(module_sp);
22600b57cec5SDimitry Andric           target_sp->ModulesDidLoad(module_list);
22610b57cec5SDimitry Andric           // Flush info in the process (stack frames, etc)
22620b57cec5SDimitry Andric           ProcessSP process_sp(target_sp->GetProcessSP());
22630b57cec5SDimitry Andric           if (process_sp)
22640b57cec5SDimitry Andric             process_sp->Flush();
22650b57cec5SDimitry Andric         }
22660b57cec5SDimitry Andric       }
22670b57cec5SDimitry Andric     } else {
22680b57cec5SDimitry Andric       sb_error.SetErrorStringWithFormat("invalid module");
22690b57cec5SDimitry Andric     }
22700b57cec5SDimitry Andric 
22710b57cec5SDimitry Andric   } else {
22720b57cec5SDimitry Andric     sb_error.SetErrorStringWithFormat("invalid target");
22730b57cec5SDimitry Andric   }
22740b57cec5SDimitry Andric   return LLDB_RECORD_RESULT(sb_error);
22750b57cec5SDimitry Andric }
22760b57cec5SDimitry Andric 
ClearModuleLoadAddress(lldb::SBModule module)22770b57cec5SDimitry Andric SBError SBTarget::ClearModuleLoadAddress(lldb::SBModule module) {
22780b57cec5SDimitry Andric   LLDB_RECORD_METHOD(lldb::SBError, SBTarget, ClearModuleLoadAddress,
22790b57cec5SDimitry Andric                      (lldb::SBModule), module);
22800b57cec5SDimitry Andric 
22810b57cec5SDimitry Andric   SBError sb_error;
22820b57cec5SDimitry Andric 
22830b57cec5SDimitry Andric   char path[PATH_MAX];
22840b57cec5SDimitry Andric   TargetSP target_sp(GetSP());
22850b57cec5SDimitry Andric   if (target_sp) {
22860b57cec5SDimitry Andric     ModuleSP module_sp(module.GetSP());
22870b57cec5SDimitry Andric     if (module_sp) {
22880b57cec5SDimitry Andric       ObjectFile *objfile = module_sp->GetObjectFile();
22890b57cec5SDimitry Andric       if (objfile) {
22900b57cec5SDimitry Andric         SectionList *section_list = objfile->GetSectionList();
22910b57cec5SDimitry Andric         if (section_list) {
22920b57cec5SDimitry Andric           ProcessSP process_sp(target_sp->GetProcessSP());
22930b57cec5SDimitry Andric 
22940b57cec5SDimitry Andric           bool changed = false;
22950b57cec5SDimitry Andric           const size_t num_sections = section_list->GetSize();
22960b57cec5SDimitry Andric           for (size_t sect_idx = 0; sect_idx < num_sections; ++sect_idx) {
22970b57cec5SDimitry Andric             SectionSP section_sp(section_list->GetSectionAtIndex(sect_idx));
22980b57cec5SDimitry Andric             if (section_sp)
22990b57cec5SDimitry Andric               changed |= target_sp->SetSectionUnloaded(section_sp);
23000b57cec5SDimitry Andric           }
23010b57cec5SDimitry Andric           if (changed) {
23020b57cec5SDimitry Andric             ModuleList module_list;
23030b57cec5SDimitry Andric             module_list.Append(module_sp);
23040b57cec5SDimitry Andric             target_sp->ModulesDidUnload(module_list, false);
23050b57cec5SDimitry Andric             // Flush info in the process (stack frames, etc)
23060b57cec5SDimitry Andric             ProcessSP process_sp(target_sp->GetProcessSP());
23070b57cec5SDimitry Andric             if (process_sp)
23080b57cec5SDimitry Andric               process_sp->Flush();
23090b57cec5SDimitry Andric           }
23100b57cec5SDimitry Andric         } else {
23110b57cec5SDimitry Andric           module_sp->GetFileSpec().GetPath(path, sizeof(path));
23120b57cec5SDimitry Andric           sb_error.SetErrorStringWithFormat("no sections in object file '%s'",
23130b57cec5SDimitry Andric                                             path);
23140b57cec5SDimitry Andric         }
23150b57cec5SDimitry Andric       } else {
23160b57cec5SDimitry Andric         module_sp->GetFileSpec().GetPath(path, sizeof(path));
23170b57cec5SDimitry Andric         sb_error.SetErrorStringWithFormat("no object file for module '%s'",
23180b57cec5SDimitry Andric                                           path);
23190b57cec5SDimitry Andric       }
23200b57cec5SDimitry Andric     } else {
23210b57cec5SDimitry Andric       sb_error.SetErrorStringWithFormat("invalid module");
23220b57cec5SDimitry Andric     }
23230b57cec5SDimitry Andric   } else {
23240b57cec5SDimitry Andric     sb_error.SetErrorStringWithFormat("invalid target");
23250b57cec5SDimitry Andric   }
23260b57cec5SDimitry Andric   return LLDB_RECORD_RESULT(sb_error);
23270b57cec5SDimitry Andric }
23280b57cec5SDimitry Andric 
FindSymbols(const char * name,lldb::SymbolType symbol_type)23290b57cec5SDimitry Andric lldb::SBSymbolContextList SBTarget::FindSymbols(const char *name,
23300b57cec5SDimitry Andric                                                 lldb::SymbolType symbol_type) {
23310b57cec5SDimitry Andric   LLDB_RECORD_METHOD(lldb::SBSymbolContextList, SBTarget, FindSymbols,
23320b57cec5SDimitry Andric                      (const char *, lldb::SymbolType), name, symbol_type);
23330b57cec5SDimitry Andric 
23340b57cec5SDimitry Andric   SBSymbolContextList sb_sc_list;
23350b57cec5SDimitry Andric   if (name && name[0]) {
23360b57cec5SDimitry Andric     TargetSP target_sp(GetSP());
23379dba64beSDimitry Andric     if (target_sp)
23380b57cec5SDimitry Andric       target_sp->GetImages().FindSymbolsWithNameAndType(
23399dba64beSDimitry Andric           ConstString(name), symbol_type, *sb_sc_list);
23400b57cec5SDimitry Andric   }
23410b57cec5SDimitry Andric   return LLDB_RECORD_RESULT(sb_sc_list);
23420b57cec5SDimitry Andric }
23430b57cec5SDimitry Andric 
EvaluateExpression(const char * expr)23440b57cec5SDimitry Andric lldb::SBValue SBTarget::EvaluateExpression(const char *expr) {
23450b57cec5SDimitry Andric   LLDB_RECORD_METHOD(lldb::SBValue, SBTarget, EvaluateExpression,
23460b57cec5SDimitry Andric                      (const char *), expr);
23470b57cec5SDimitry Andric 
23480b57cec5SDimitry Andric   TargetSP target_sp(GetSP());
23490b57cec5SDimitry Andric   if (!target_sp)
23500b57cec5SDimitry Andric     return LLDB_RECORD_RESULT(SBValue());
23510b57cec5SDimitry Andric 
23520b57cec5SDimitry Andric   SBExpressionOptions options;
23530b57cec5SDimitry Andric   lldb::DynamicValueType fetch_dynamic_value =
23540b57cec5SDimitry Andric       target_sp->GetPreferDynamicValue();
23550b57cec5SDimitry Andric   options.SetFetchDynamicValue(fetch_dynamic_value);
23560b57cec5SDimitry Andric   options.SetUnwindOnError(true);
23570b57cec5SDimitry Andric   return LLDB_RECORD_RESULT(EvaluateExpression(expr, options));
23580b57cec5SDimitry Andric }
23590b57cec5SDimitry Andric 
EvaluateExpression(const char * expr,const SBExpressionOptions & options)23600b57cec5SDimitry Andric lldb::SBValue SBTarget::EvaluateExpression(const char *expr,
23610b57cec5SDimitry Andric                                            const SBExpressionOptions &options) {
23620b57cec5SDimitry Andric   LLDB_RECORD_METHOD(lldb::SBValue, SBTarget, EvaluateExpression,
23630b57cec5SDimitry Andric                      (const char *, const lldb::SBExpressionOptions &), expr,
23640b57cec5SDimitry Andric                      options);
23650b57cec5SDimitry Andric 
23660b57cec5SDimitry Andric   Log *expr_log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS));
23670b57cec5SDimitry Andric   SBValue expr_result;
23680b57cec5SDimitry Andric   ValueObjectSP expr_value_sp;
23690b57cec5SDimitry Andric   TargetSP target_sp(GetSP());
23700b57cec5SDimitry Andric   StackFrame *frame = nullptr;
23710b57cec5SDimitry Andric   if (target_sp) {
23720b57cec5SDimitry Andric     if (expr == nullptr || expr[0] == '\0') {
23730b57cec5SDimitry Andric       return LLDB_RECORD_RESULT(expr_result);
23740b57cec5SDimitry Andric     }
23750b57cec5SDimitry Andric 
23760b57cec5SDimitry Andric     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
23770b57cec5SDimitry Andric     ExecutionContext exe_ctx(m_opaque_sp.get());
23780b57cec5SDimitry Andric 
23790b57cec5SDimitry Andric 
23800b57cec5SDimitry Andric     frame = exe_ctx.GetFramePtr();
23810b57cec5SDimitry Andric     Target *target = exe_ctx.GetTargetPtr();
23820b57cec5SDimitry Andric 
23830b57cec5SDimitry Andric     if (target) {
23840b57cec5SDimitry Andric       target->EvaluateExpression(expr, frame, expr_value_sp, options.ref());
23850b57cec5SDimitry Andric 
23860b57cec5SDimitry Andric       expr_result.SetSP(expr_value_sp, options.GetFetchDynamicValue());
23870b57cec5SDimitry Andric     }
23880b57cec5SDimitry Andric   }
23899dba64beSDimitry Andric   LLDB_LOGF(expr_log,
23909dba64beSDimitry Andric             "** [SBTarget::EvaluateExpression] Expression result is "
23910b57cec5SDimitry Andric             "%s, summary %s **",
23920b57cec5SDimitry Andric             expr_result.GetValue(), expr_result.GetSummary());
23930b57cec5SDimitry Andric   return LLDB_RECORD_RESULT(expr_result);
23940b57cec5SDimitry Andric }
23950b57cec5SDimitry Andric 
GetStackRedZoneSize()23960b57cec5SDimitry Andric lldb::addr_t SBTarget::GetStackRedZoneSize() {
23970b57cec5SDimitry Andric   LLDB_RECORD_METHOD_NO_ARGS(lldb::addr_t, SBTarget, GetStackRedZoneSize);
23980b57cec5SDimitry Andric 
23990b57cec5SDimitry Andric   TargetSP target_sp(GetSP());
24000b57cec5SDimitry Andric   if (target_sp) {
24010b57cec5SDimitry Andric     ABISP abi_sp;
24020b57cec5SDimitry Andric     ProcessSP process_sp(target_sp->GetProcessSP());
24030b57cec5SDimitry Andric     if (process_sp)
24040b57cec5SDimitry Andric       abi_sp = process_sp->GetABI();
24050b57cec5SDimitry Andric     else
24060b57cec5SDimitry Andric       abi_sp = ABI::FindPlugin(ProcessSP(), target_sp->GetArchitecture());
24070b57cec5SDimitry Andric     if (abi_sp)
24080b57cec5SDimitry Andric       return abi_sp->GetRedZoneSize();
24090b57cec5SDimitry Andric   }
24100b57cec5SDimitry Andric   return 0;
24110b57cec5SDimitry Andric }
24120b57cec5SDimitry Andric 
IsLoaded(const SBModule & module) const2413*5f7ddb14SDimitry Andric bool SBTarget::IsLoaded(const SBModule &module) const {
2414*5f7ddb14SDimitry Andric   LLDB_RECORD_METHOD_CONST(bool, SBTarget, IsLoaded, (const lldb::SBModule &),
2415*5f7ddb14SDimitry Andric                            module);
2416*5f7ddb14SDimitry Andric 
2417*5f7ddb14SDimitry Andric   TargetSP target_sp(GetSP());
2418*5f7ddb14SDimitry Andric   if (!target_sp)
2419*5f7ddb14SDimitry Andric     return false;
2420*5f7ddb14SDimitry Andric 
2421*5f7ddb14SDimitry Andric   ModuleSP module_sp(module.GetSP());
2422*5f7ddb14SDimitry Andric   if (!module_sp)
2423*5f7ddb14SDimitry Andric     return false;
2424*5f7ddb14SDimitry Andric 
2425*5f7ddb14SDimitry Andric   return module_sp->IsLoadedInTarget(target_sp.get());
2426*5f7ddb14SDimitry Andric }
2427*5f7ddb14SDimitry Andric 
GetLaunchInfo() const24280b57cec5SDimitry Andric lldb::SBLaunchInfo SBTarget::GetLaunchInfo() const {
24290b57cec5SDimitry Andric   LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::SBLaunchInfo, SBTarget, GetLaunchInfo);
24300b57cec5SDimitry Andric 
24310b57cec5SDimitry Andric   lldb::SBLaunchInfo launch_info(nullptr);
24320b57cec5SDimitry Andric   TargetSP target_sp(GetSP());
24330b57cec5SDimitry Andric   if (target_sp)
24340b57cec5SDimitry Andric     launch_info.set_ref(m_opaque_sp->GetProcessLaunchInfo());
24350b57cec5SDimitry Andric   return LLDB_RECORD_RESULT(launch_info);
24360b57cec5SDimitry Andric }
24370b57cec5SDimitry Andric 
SetLaunchInfo(const lldb::SBLaunchInfo & launch_info)24380b57cec5SDimitry Andric void SBTarget::SetLaunchInfo(const lldb::SBLaunchInfo &launch_info) {
24390b57cec5SDimitry Andric   LLDB_RECORD_METHOD(void, SBTarget, SetLaunchInfo,
24400b57cec5SDimitry Andric                      (const lldb::SBLaunchInfo &), launch_info);
24410b57cec5SDimitry Andric 
24420b57cec5SDimitry Andric   TargetSP target_sp(GetSP());
24430b57cec5SDimitry Andric   if (target_sp)
24440b57cec5SDimitry Andric     m_opaque_sp->SetProcessLaunchInfo(launch_info.ref());
24450b57cec5SDimitry Andric }
24460b57cec5SDimitry Andric 
GetEnvironment()24475ffd83dbSDimitry Andric SBEnvironment SBTarget::GetEnvironment() {
24485ffd83dbSDimitry Andric   LLDB_RECORD_METHOD_NO_ARGS(lldb::SBEnvironment, SBTarget, GetEnvironment);
24495ffd83dbSDimitry Andric   TargetSP target_sp(GetSP());
24505ffd83dbSDimitry Andric 
24515ffd83dbSDimitry Andric   if (target_sp) {
24525ffd83dbSDimitry Andric     return LLDB_RECORD_RESULT(SBEnvironment(target_sp->GetEnvironment()));
24535ffd83dbSDimitry Andric   }
24545ffd83dbSDimitry Andric 
24555ffd83dbSDimitry Andric   return LLDB_RECORD_RESULT(SBEnvironment());
24565ffd83dbSDimitry Andric }
24575ffd83dbSDimitry Andric 
GetTrace()2458*5f7ddb14SDimitry Andric lldb::SBTrace SBTarget::GetTrace() {
2459*5f7ddb14SDimitry Andric   LLDB_RECORD_METHOD_NO_ARGS(lldb::SBTrace, SBTarget, GetTrace);
2460*5f7ddb14SDimitry Andric   TargetSP target_sp(GetSP());
2461*5f7ddb14SDimitry Andric 
2462*5f7ddb14SDimitry Andric   if (target_sp)
2463*5f7ddb14SDimitry Andric     return LLDB_RECORD_RESULT(SBTrace(target_sp->GetTrace()));
2464*5f7ddb14SDimitry Andric 
2465*5f7ddb14SDimitry Andric   return LLDB_RECORD_RESULT(SBTrace());
2466*5f7ddb14SDimitry Andric }
2467*5f7ddb14SDimitry Andric 
CreateTrace(lldb::SBError & error)2468*5f7ddb14SDimitry Andric lldb::SBTrace SBTarget::CreateTrace(lldb::SBError &error) {
2469*5f7ddb14SDimitry Andric   LLDB_RECORD_METHOD(lldb::SBTrace, SBTarget, CreateTrace, (lldb::SBError &),
2470*5f7ddb14SDimitry Andric                      error);
2471*5f7ddb14SDimitry Andric   TargetSP target_sp(GetSP());
2472*5f7ddb14SDimitry Andric   error.Clear();
2473*5f7ddb14SDimitry Andric 
2474*5f7ddb14SDimitry Andric   if (target_sp) {
2475*5f7ddb14SDimitry Andric     if (llvm::Expected<lldb::TraceSP> trace_sp = target_sp->CreateTrace()) {
2476*5f7ddb14SDimitry Andric       return LLDB_RECORD_RESULT(SBTrace(*trace_sp));
2477*5f7ddb14SDimitry Andric     } else {
2478*5f7ddb14SDimitry Andric       error.SetErrorString(llvm::toString(trace_sp.takeError()).c_str());
2479*5f7ddb14SDimitry Andric     }
2480*5f7ddb14SDimitry Andric   } else {
2481*5f7ddb14SDimitry Andric     error.SetErrorString("missing target");
2482*5f7ddb14SDimitry Andric   }
2483*5f7ddb14SDimitry Andric   return LLDB_RECORD_RESULT(SBTrace());
2484*5f7ddb14SDimitry Andric }
2485*5f7ddb14SDimitry Andric 
24860b57cec5SDimitry Andric namespace lldb_private {
24870b57cec5SDimitry Andric namespace repro {
24880b57cec5SDimitry Andric 
24890b57cec5SDimitry Andric template <>
RegisterMethods(Registry & R)24900b57cec5SDimitry Andric void RegisterMethods<SBTarget>(Registry &R) {
24910b57cec5SDimitry Andric   LLDB_REGISTER_CONSTRUCTOR(SBTarget, ());
24920b57cec5SDimitry Andric   LLDB_REGISTER_CONSTRUCTOR(SBTarget, (const lldb::SBTarget &));
24930b57cec5SDimitry Andric   LLDB_REGISTER_CONSTRUCTOR(SBTarget, (const lldb::TargetSP &));
24940b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(const lldb::SBTarget &,
24950b57cec5SDimitry Andric                        SBTarget, operator=,(const lldb::SBTarget &));
24960b57cec5SDimitry Andric   LLDB_REGISTER_STATIC_METHOD(bool, SBTarget, EventIsTargetEvent,
24970b57cec5SDimitry Andric                               (const lldb::SBEvent &));
24980b57cec5SDimitry Andric   LLDB_REGISTER_STATIC_METHOD(lldb::SBTarget, SBTarget, GetTargetFromEvent,
24990b57cec5SDimitry Andric                               (const lldb::SBEvent &));
25000b57cec5SDimitry Andric   LLDB_REGISTER_STATIC_METHOD(uint32_t, SBTarget, GetNumModulesFromEvent,
25010b57cec5SDimitry Andric                               (const lldb::SBEvent &));
25020b57cec5SDimitry Andric   LLDB_REGISTER_STATIC_METHOD(lldb::SBModule, SBTarget,
25030b57cec5SDimitry Andric                               GetModuleAtIndexFromEvent,
25040b57cec5SDimitry Andric                               (const uint32_t, const lldb::SBEvent &));
25050b57cec5SDimitry Andric   LLDB_REGISTER_STATIC_METHOD(const char *, SBTarget, GetBroadcasterClassName,
25060b57cec5SDimitry Andric                               ());
25070b57cec5SDimitry Andric   LLDB_REGISTER_METHOD_CONST(bool, SBTarget, IsValid, ());
25080b57cec5SDimitry Andric   LLDB_REGISTER_METHOD_CONST(bool, SBTarget, operator bool, ());
25090b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(lldb::SBProcess, SBTarget, GetProcess, ());
25100b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(lldb::SBPlatform, SBTarget, GetPlatform, ());
25110b57cec5SDimitry Andric   LLDB_REGISTER_METHOD_CONST(lldb::SBDebugger, SBTarget, GetDebugger, ());
25120b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(lldb::SBStructuredData, SBTarget, GetStatistics, ());
25130b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(void, SBTarget, SetCollectingStats, (bool));
25140b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(bool, SBTarget, GetCollectingStats, ());
25150b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(lldb::SBProcess, SBTarget, LoadCore, (const char *));
25160b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(lldb::SBProcess, SBTarget, LoadCore,
25170b57cec5SDimitry Andric                        (const char *, lldb::SBError &));
25180b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(lldb::SBProcess, SBTarget, LaunchSimple,
25190b57cec5SDimitry Andric                        (const char **, const char **, const char *));
25200b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(lldb::SBError, SBTarget, Install, ());
25210b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(lldb::SBProcess, SBTarget, Launch,
25220b57cec5SDimitry Andric                        (lldb::SBListener &, const char **, const char **,
25230b57cec5SDimitry Andric                         const char *, const char *, const char *,
25240b57cec5SDimitry Andric                         const char *, uint32_t, bool, lldb::SBError &));
25250b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(lldb::SBProcess, SBTarget, Launch,
25260b57cec5SDimitry Andric                        (lldb::SBLaunchInfo &, lldb::SBError &));
25270b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(lldb::SBProcess, SBTarget, Attach,
25280b57cec5SDimitry Andric                        (lldb::SBAttachInfo &, lldb::SBError &));
25290b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(lldb::SBProcess, SBTarget, AttachToProcessWithID,
25300b57cec5SDimitry Andric                        (lldb::SBListener &, lldb::pid_t, lldb::SBError &));
25310b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(
25320b57cec5SDimitry Andric       lldb::SBProcess, SBTarget, AttachToProcessWithName,
25330b57cec5SDimitry Andric       (lldb::SBListener &, const char *, bool, lldb::SBError &));
25340b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(
25350b57cec5SDimitry Andric       lldb::SBProcess, SBTarget, ConnectRemote,
25360b57cec5SDimitry Andric       (lldb::SBListener &, const char *, const char *, lldb::SBError &));
25370b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(lldb::SBFileSpec, SBTarget, GetExecutable, ());
25380b57cec5SDimitry Andric   LLDB_REGISTER_METHOD_CONST(bool,
25390b57cec5SDimitry Andric                              SBTarget, operator==,(const lldb::SBTarget &));
25400b57cec5SDimitry Andric   LLDB_REGISTER_METHOD_CONST(bool,
25410b57cec5SDimitry Andric                              SBTarget, operator!=,(const lldb::SBTarget &));
25420b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(lldb::SBAddress, SBTarget, ResolveLoadAddress,
25430b57cec5SDimitry Andric                        (lldb::addr_t));
25440b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(lldb::SBAddress, SBTarget, ResolveFileAddress,
25450b57cec5SDimitry Andric                        (lldb::addr_t));
25460b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(lldb::SBAddress, SBTarget, ResolvePastLoadAddress,
25470b57cec5SDimitry Andric                        (uint32_t, lldb::addr_t));
25480b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(lldb::SBSymbolContext, SBTarget,
25490b57cec5SDimitry Andric                        ResolveSymbolContextForAddress,
25500b57cec5SDimitry Andric                        (const lldb::SBAddress &, uint32_t));
25510b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(lldb::SBBreakpoint, SBTarget,
25520b57cec5SDimitry Andric                        BreakpointCreateByLocation, (const char *, uint32_t));
25530b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(lldb::SBBreakpoint, SBTarget,
25540b57cec5SDimitry Andric                        BreakpointCreateByLocation,
25550b57cec5SDimitry Andric                        (const lldb::SBFileSpec &, uint32_t));
25560b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(lldb::SBBreakpoint, SBTarget,
25570b57cec5SDimitry Andric                        BreakpointCreateByLocation,
25580b57cec5SDimitry Andric                        (const lldb::SBFileSpec &, uint32_t, lldb::addr_t));
25590b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(lldb::SBBreakpoint, SBTarget,
25600b57cec5SDimitry Andric                        BreakpointCreateByLocation,
25610b57cec5SDimitry Andric                        (const lldb::SBFileSpec &, uint32_t, lldb::addr_t,
25620b57cec5SDimitry Andric                         lldb::SBFileSpecList &));
25630b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(lldb::SBBreakpoint, SBTarget,
25640b57cec5SDimitry Andric                        BreakpointCreateByLocation,
25650b57cec5SDimitry Andric                        (const lldb::SBFileSpec &, uint32_t, uint32_t,
25660b57cec5SDimitry Andric                         lldb::addr_t, lldb::SBFileSpecList &));
2567af732203SDimitry Andric   LLDB_REGISTER_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateByLocation,
2568af732203SDimitry Andric                        (const lldb::SBFileSpec &, uint32_t, uint32_t,
2569af732203SDimitry Andric                         lldb::addr_t, lldb::SBFileSpecList &, bool));
25700b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateByName,
25710b57cec5SDimitry Andric                        (const char *, const char *));
25720b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateByName,
25730b57cec5SDimitry Andric                        (const char *, const lldb::SBFileSpecList &,
25740b57cec5SDimitry Andric                         const lldb::SBFileSpecList &));
25750b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateByName,
25760b57cec5SDimitry Andric                        (const char *, uint32_t, const lldb::SBFileSpecList &,
25770b57cec5SDimitry Andric                         const lldb::SBFileSpecList &));
25780b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateByName,
25790b57cec5SDimitry Andric                        (const char *, uint32_t, lldb::LanguageType,
25800b57cec5SDimitry Andric                         const lldb::SBFileSpecList &,
25810b57cec5SDimitry Andric                         const lldb::SBFileSpecList &));
25820b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateByNames,
25830b57cec5SDimitry Andric                        (const char **, uint32_t, uint32_t,
25840b57cec5SDimitry Andric                         const lldb::SBFileSpecList &,
25850b57cec5SDimitry Andric                         const lldb::SBFileSpecList &));
25860b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateByNames,
25870b57cec5SDimitry Andric                        (const char **, uint32_t, uint32_t, lldb::LanguageType,
25880b57cec5SDimitry Andric                         const lldb::SBFileSpecList &,
25890b57cec5SDimitry Andric                         const lldb::SBFileSpecList &));
25900b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateByNames,
25910b57cec5SDimitry Andric                        (const char **, uint32_t, uint32_t, lldb::LanguageType,
25920b57cec5SDimitry Andric                         lldb::addr_t, const lldb::SBFileSpecList &,
25930b57cec5SDimitry Andric                         const lldb::SBFileSpecList &));
25940b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateByRegex,
25950b57cec5SDimitry Andric                        (const char *, const char *));
25960b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateByRegex,
25970b57cec5SDimitry Andric                        (const char *, const lldb::SBFileSpecList &,
25980b57cec5SDimitry Andric                         const lldb::SBFileSpecList &));
25990b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateByRegex,
26000b57cec5SDimitry Andric                        (const char *, lldb::LanguageType,
26010b57cec5SDimitry Andric                         const lldb::SBFileSpecList &,
26020b57cec5SDimitry Andric                         const lldb::SBFileSpecList &));
26030b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(lldb::SBBreakpoint, SBTarget,
26040b57cec5SDimitry Andric                        BreakpointCreateByAddress, (lldb::addr_t));
26050b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(lldb::SBBreakpoint, SBTarget,
26060b57cec5SDimitry Andric                        BreakpointCreateBySBAddress, (lldb::SBAddress &));
26070b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(
26080b57cec5SDimitry Andric       lldb::SBBreakpoint, SBTarget, BreakpointCreateBySourceRegex,
26090b57cec5SDimitry Andric       (const char *, const lldb::SBFileSpec &, const char *));
26100b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(lldb::SBBreakpoint, SBTarget,
26110b57cec5SDimitry Andric                        BreakpointCreateBySourceRegex,
26120b57cec5SDimitry Andric                        (const char *, const lldb::SBFileSpecList &,
26130b57cec5SDimitry Andric                         const lldb::SBFileSpecList &));
26140b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(
26150b57cec5SDimitry Andric       lldb::SBBreakpoint, SBTarget, BreakpointCreateBySourceRegex,
26160b57cec5SDimitry Andric       (const char *, const lldb::SBFileSpecList &,
26170b57cec5SDimitry Andric        const lldb::SBFileSpecList &, const lldb::SBStringList &));
26180b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(lldb::SBBreakpoint, SBTarget,
26190b57cec5SDimitry Andric                        BreakpointCreateForException,
26200b57cec5SDimitry Andric                        (lldb::LanguageType, bool, bool));
26210b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(
26220b57cec5SDimitry Andric       lldb::SBBreakpoint, SBTarget, BreakpointCreateFromScript,
26230b57cec5SDimitry Andric       (const char *, lldb::SBStructuredData &, const lldb::SBFileSpecList &,
26240b57cec5SDimitry Andric        const lldb::SBFileSpecList &, bool));
26250b57cec5SDimitry Andric   LLDB_REGISTER_METHOD_CONST(uint32_t, SBTarget, GetNumBreakpoints, ());
26260b57cec5SDimitry Andric   LLDB_REGISTER_METHOD_CONST(lldb::SBBreakpoint, SBTarget,
26270b57cec5SDimitry Andric                              GetBreakpointAtIndex, (uint32_t));
26280b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(bool, SBTarget, BreakpointDelete, (lldb::break_id_t));
26290b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(lldb::SBBreakpoint, SBTarget, FindBreakpointByID,
26300b57cec5SDimitry Andric                        (lldb::break_id_t));
26310b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(bool, SBTarget, FindBreakpointsByName,
26320b57cec5SDimitry Andric                        (const char *, lldb::SBBreakpointList &));
26330b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(void, SBTarget, GetBreakpointNames,
26340b57cec5SDimitry Andric                        (lldb::SBStringList &));
26350b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(void, SBTarget, DeleteBreakpointName, (const char *));
26360b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(bool, SBTarget, EnableAllBreakpoints, ());
26370b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(bool, SBTarget, DisableAllBreakpoints, ());
26380b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(bool, SBTarget, DeleteAllBreakpoints, ());
26390b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(lldb::SBError, SBTarget, BreakpointsCreateFromFile,
26400b57cec5SDimitry Andric                        (lldb::SBFileSpec &, lldb::SBBreakpointList &));
26410b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(
26420b57cec5SDimitry Andric       lldb::SBError, SBTarget, BreakpointsCreateFromFile,
26430b57cec5SDimitry Andric       (lldb::SBFileSpec &, lldb::SBStringList &, lldb::SBBreakpointList &));
26440b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(lldb::SBError, SBTarget, BreakpointsWriteToFile,
26450b57cec5SDimitry Andric                        (lldb::SBFileSpec &));
26460b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(lldb::SBError, SBTarget, BreakpointsWriteToFile,
26470b57cec5SDimitry Andric                        (lldb::SBFileSpec &, lldb::SBBreakpointList &, bool));
26480b57cec5SDimitry Andric   LLDB_REGISTER_METHOD_CONST(uint32_t, SBTarget, GetNumWatchpoints, ());
26490b57cec5SDimitry Andric   LLDB_REGISTER_METHOD_CONST(lldb::SBWatchpoint, SBTarget,
26500b57cec5SDimitry Andric                              GetWatchpointAtIndex, (uint32_t));
26510b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(bool, SBTarget, DeleteWatchpoint, (lldb::watch_id_t));
26520b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(lldb::SBWatchpoint, SBTarget, FindWatchpointByID,
26530b57cec5SDimitry Andric                        (lldb::watch_id_t));
26540b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(lldb::SBWatchpoint, SBTarget, WatchAddress,
26550b57cec5SDimitry Andric                        (lldb::addr_t, size_t, bool, bool, lldb::SBError &));
26560b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(bool, SBTarget, EnableAllWatchpoints, ());
26570b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(bool, SBTarget, DisableAllWatchpoints, ());
26580b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(lldb::SBValue, SBTarget, CreateValueFromAddress,
26590b57cec5SDimitry Andric                        (const char *, lldb::SBAddress, lldb::SBType));
26600b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(lldb::SBValue, SBTarget, CreateValueFromData,
26610b57cec5SDimitry Andric                        (const char *, lldb::SBData, lldb::SBType));
26620b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(lldb::SBValue, SBTarget, CreateValueFromExpression,
26630b57cec5SDimitry Andric                        (const char *, const char *));
26640b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(bool, SBTarget, DeleteAllWatchpoints, ());
26650b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(void, SBTarget, AppendImageSearchPath,
26660b57cec5SDimitry Andric                        (const char *, const char *, lldb::SBError &));
26670b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(lldb::SBModule, SBTarget, AddModule,
26680b57cec5SDimitry Andric                        (const char *, const char *, const char *));
26690b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(
26700b57cec5SDimitry Andric       lldb::SBModule, SBTarget, AddModule,
26710b57cec5SDimitry Andric       (const char *, const char *, const char *, const char *));
26720b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(lldb::SBModule, SBTarget, AddModule,
26730b57cec5SDimitry Andric                        (const lldb::SBModuleSpec &));
26740b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(bool, SBTarget, AddModule, (lldb::SBModule &));
26750b57cec5SDimitry Andric   LLDB_REGISTER_METHOD_CONST(uint32_t, SBTarget, GetNumModules, ());
26760b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(void, SBTarget, Clear, ());
26770b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(lldb::SBModule, SBTarget, FindModule,
26780b57cec5SDimitry Andric                        (const lldb::SBFileSpec &));
26790b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(lldb::SBSymbolContextList, SBTarget, FindCompileUnits,
26800b57cec5SDimitry Andric                        (const lldb::SBFileSpec &));
26810b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(lldb::ByteOrder, SBTarget, GetByteOrder, ());
26820b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(const char *, SBTarget, GetTriple, ());
26830b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(uint32_t, SBTarget, GetDataByteSize, ());
26840b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(uint32_t, SBTarget, GetCodeByteSize, ());
26850b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(uint32_t, SBTarget, GetAddressByteSize, ());
26860b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(lldb::SBModule, SBTarget, GetModuleAtIndex,
26870b57cec5SDimitry Andric                        (uint32_t));
26880b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(bool, SBTarget, RemoveModule, (lldb::SBModule));
26890b57cec5SDimitry Andric   LLDB_REGISTER_METHOD_CONST(lldb::SBBroadcaster, SBTarget, GetBroadcaster,
26900b57cec5SDimitry Andric                              ());
26910b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(bool, SBTarget, GetDescription,
26920b57cec5SDimitry Andric                        (lldb::SBStream &, lldb::DescriptionLevel));
26930b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(lldb::SBSymbolContextList, SBTarget, FindFunctions,
26940b57cec5SDimitry Andric                        (const char *, uint32_t));
26950b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(lldb::SBSymbolContextList, SBTarget,
26960b57cec5SDimitry Andric                        FindGlobalFunctions,
26970b57cec5SDimitry Andric                        (const char *, uint32_t, lldb::MatchType));
26980b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(lldb::SBType, SBTarget, FindFirstType, (const char *));
26990b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(lldb::SBType, SBTarget, GetBasicType,
27000b57cec5SDimitry Andric                        (lldb::BasicType));
27010b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(lldb::SBTypeList, SBTarget, FindTypes, (const char *));
27020b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(lldb::SBValueList, SBTarget, FindGlobalVariables,
27030b57cec5SDimitry Andric                        (const char *, uint32_t));
27040b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(lldb::SBValueList, SBTarget, FindGlobalVariables,
27050b57cec5SDimitry Andric                        (const char *, uint32_t, lldb::MatchType));
27060b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(lldb::SBValue, SBTarget, FindFirstGlobalVariable,
27070b57cec5SDimitry Andric                        (const char *));
27080b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(lldb::SBSourceManager, SBTarget, GetSourceManager, ());
27090b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(lldb::SBInstructionList, SBTarget, ReadInstructions,
27100b57cec5SDimitry Andric                        (lldb::SBAddress, uint32_t));
27110b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(lldb::SBInstructionList, SBTarget, ReadInstructions,
27120b57cec5SDimitry Andric                        (lldb::SBAddress, uint32_t, const char *));
27130b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(lldb::SBError, SBTarget, SetSectionLoadAddress,
27140b57cec5SDimitry Andric                        (lldb::SBSection, lldb::addr_t));
27150b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(lldb::SBError, SBTarget, ClearSectionLoadAddress,
27160b57cec5SDimitry Andric                        (lldb::SBSection));
27170b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(lldb::SBError, SBTarget, SetModuleLoadAddress,
27180b57cec5SDimitry Andric                        (lldb::SBModule, int64_t));
27190b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(lldb::SBError, SBTarget, ClearModuleLoadAddress,
27200b57cec5SDimitry Andric                        (lldb::SBModule));
27210b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(lldb::SBSymbolContextList, SBTarget, FindSymbols,
27220b57cec5SDimitry Andric                        (const char *, lldb::SymbolType));
27230b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(lldb::SBValue, SBTarget, EvaluateExpression,
27240b57cec5SDimitry Andric                        (const char *));
27250b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(lldb::SBValue, SBTarget, EvaluateExpression,
27260b57cec5SDimitry Andric                        (const char *, const lldb::SBExpressionOptions &));
27270b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(lldb::addr_t, SBTarget, GetStackRedZoneSize, ());
2728*5f7ddb14SDimitry Andric   LLDB_REGISTER_METHOD_CONST(bool, SBTarget, IsLoaded,
2729*5f7ddb14SDimitry Andric                              (const lldb::SBModule &));
27300b57cec5SDimitry Andric   LLDB_REGISTER_METHOD_CONST(lldb::SBLaunchInfo, SBTarget, GetLaunchInfo, ());
27310b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(void, SBTarget, SetLaunchInfo,
27320b57cec5SDimitry Andric                        (const lldb::SBLaunchInfo &));
27335ffd83dbSDimitry Andric   LLDB_REGISTER_METHOD(
27345ffd83dbSDimitry Andric       size_t, SBTarget, ReadMemory,
27355ffd83dbSDimitry Andric       (const lldb::SBAddress, void *, size_t, lldb::SBError &));
27365ffd83dbSDimitry Andric   LLDB_REGISTER_METHOD(lldb::SBInstructionList, SBTarget, GetInstructions,
27375ffd83dbSDimitry Andric                        (lldb::SBAddress, const void *, size_t));
27385ffd83dbSDimitry Andric   LLDB_REGISTER_METHOD(lldb::SBInstructionList, SBTarget,
27395ffd83dbSDimitry Andric                        GetInstructionsWithFlavor,
27405ffd83dbSDimitry Andric                        (lldb::SBAddress, const char *, const void *, size_t));
27415ffd83dbSDimitry Andric   LLDB_REGISTER_METHOD(lldb::SBInstructionList, SBTarget, GetInstructions,
27425ffd83dbSDimitry Andric                        (lldb::addr_t, const void *, size_t));
27435ffd83dbSDimitry Andric   LLDB_REGISTER_METHOD(lldb::SBInstructionList, SBTarget,
27445ffd83dbSDimitry Andric                        GetInstructionsWithFlavor,
27455ffd83dbSDimitry Andric                        (lldb::addr_t, const char *, const void *, size_t));
27465ffd83dbSDimitry Andric   LLDB_REGISTER_METHOD(lldb::SBEnvironment, SBTarget, GetEnvironment, ());
2747*5f7ddb14SDimitry Andric   LLDB_REGISTER_METHOD(lldb::SBTrace, SBTarget, GetTrace, ());
2748*5f7ddb14SDimitry Andric   LLDB_REGISTER_METHOD(lldb::SBTrace, SBTarget, CreateTrace, (lldb::SBError &));
27490b57cec5SDimitry Andric }
27500b57cec5SDimitry Andric 
27510b57cec5SDimitry Andric }
27520b57cec5SDimitry Andric }
2753