blob: 0a408e7037b2e12cafdf900e9307257042b871cf [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001//===-- SBTarget.cpp --------------------------------------------*- C++ -*-===//
2//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006//
7//===----------------------------------------------------------------------===//
8
Eli Friedman4c5de692010-06-09 07:44:37 +00009#include "lldb/API/SBTarget.h"
Jonas Devliegherebaf56642019-03-06 00:06:00 +000010#include "SBReproducerPrivate.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000011
Greg Claytone0d378b2011-03-24 21:19:54 +000012#include "lldb/lldb-public.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000013
Greg Claytondea8cb42011-06-29 22:09:02 +000014#include "lldb/API/SBBreakpoint.h"
Ilia Keb2c19a2015-03-10 21:59:55 +000015#include "lldb/API/SBDebugger.h"
16#include "lldb/API/SBEvent.h"
Greg Clayton4b63a5c2013-01-04 18:10:18 +000017#include "lldb/API/SBExpressionOptions.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000018#include "lldb/API/SBFileSpec.h"
Greg Claytondea8cb42011-06-29 22:09:02 +000019#include "lldb/API/SBListener.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000020#include "lldb/API/SBModule.h"
Greg Clayton226cce22013-07-08 22:22:41 +000021#include "lldb/API/SBModuleSpec.h"
Greg Claytondea8cb42011-06-29 22:09:02 +000022#include "lldb/API/SBProcess.h"
Kate Stoneb9c1b512016-09-06 20:57:50 +000023#include "lldb/API/SBSourceManager.h"
Caroline Ticedde9cff2010-09-20 05:20:02 +000024#include "lldb/API/SBStream.h"
Jim Ingham76bb8d62016-04-28 01:40:57 +000025#include "lldb/API/SBStringList.h"
Davide Italiano4a6a2b12018-04-16 22:55:34 +000026#include "lldb/API/SBStructuredData.h"
Greg Claytonfe356d32011-06-21 01:34:41 +000027#include "lldb/API/SBSymbolContextList.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000028#include "lldb/Breakpoint/BreakpointID.h"
29#include "lldb/Breakpoint/BreakpointIDList.h"
30#include "lldb/Breakpoint/BreakpointList.h"
31#include "lldb/Breakpoint/BreakpointLocation.h"
32#include "lldb/Core/Address.h"
33#include "lldb/Core/AddressResolver.h"
34#include "lldb/Core/AddressResolverName.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000035#include "lldb/Core/Debugger.h"
36#include "lldb/Core/Disassembler.h"
Greg Clayton1f746072012-08-29 21:13:06 +000037#include "lldb/Core/Module.h"
38#include "lldb/Core/ModuleSpec.h"
Kate Stoneb9c1b512016-09-06 20:57:50 +000039#include "lldb/Core/STLUtils.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000040#include "lldb/Core/SearchFilter.h"
Greg Clayton1f746072012-08-29 21:13:06 +000041#include "lldb/Core/Section.h"
Davide Italiano4a6a2b12018-04-16 22:55:34 +000042#include "lldb/Core/StructuredDataImpl.h"
Enrico Granata347c2aa2013-10-08 21:49:02 +000043#include "lldb/Core/ValueObjectConstResult.h"
Greg Claytondea8cb42011-06-29 22:09:02 +000044#include "lldb/Core/ValueObjectList.h"
45#include "lldb/Core/ValueObjectVariable.h"
Greg Clayton7fb56d02011-02-01 01:31:41 +000046#include "lldb/Host/Host.h"
Zachary Turnera78bd7f2015-03-03 23:11:11 +000047#include "lldb/Symbol/ClangASTContext.h"
48#include "lldb/Symbol/DeclVendor.h"
Greg Clayton1f746072012-08-29 21:13:06 +000049#include "lldb/Symbol/ObjectFile.h"
Greg Claytonae088e52016-02-10 21:28:13 +000050#include "lldb/Symbol/SymbolFile.h"
Enrico Granata6f3533f2011-07-29 19:53:35 +000051#include "lldb/Symbol/SymbolVendor.h"
Greg Claytondea8cb42011-06-29 22:09:02 +000052#include "lldb/Symbol/VariableList.h"
Zachary Turner32abc6e2015-03-03 19:23:09 +000053#include "lldb/Target/ABI.h"
Jim Ingham0e0984e2015-09-02 01:06:46 +000054#include "lldb/Target/Language.h"
Jim Inghamfab10e82012-03-06 00:37:27 +000055#include "lldb/Target/LanguageRuntime.h"
Zachary Turnera78bd7f2015-03-03 23:11:11 +000056#include "lldb/Target/ObjCLanguageRuntime.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000057#include "lldb/Target/Process.h"
Enrico Granatab10e0032015-03-04 21:33:45 +000058#include "lldb/Target/StackFrame.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000059#include "lldb/Target/Target.h"
60#include "lldb/Target/TargetList.h"
Pavel Labath5f19b902017-11-13 16:16:33 +000061#include "lldb/Utility/ArchSpec.h"
Pavel Labath145d95c2018-04-17 18:53:35 +000062#include "lldb/Utility/Args.h"
Zachary Turner5713a052017-03-22 18:40:07 +000063#include "lldb/Utility/FileSpec.h"
Zachary Turner805e7102019-03-04 21:51:03 +000064#include "lldb/Utility/ProcessInfo.h"
Zachary Turnerbf9a7732017-02-02 21:39:50 +000065#include "lldb/Utility/RegularExpression.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000066
James Y Knight2ad48212018-05-22 22:53:50 +000067#include "Commands/CommandObjectBreakpoint.h"
Kate Stoneb9c1b512016-09-06 20:57:50 +000068#include "lldb/Interpreter/CommandReturnObject.h"
Sean Callanan237c3ed2016-12-14 21:31:31 +000069#include "llvm/Support/PrettyStackTrace.h"
Carlo Kok0fd6fd42014-09-19 19:38:19 +000070#include "llvm/Support/Regex.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000071
Chris Lattner30fdc8d2010-06-08 16:52:24 +000072using namespace lldb;
73using namespace lldb_private;
74
75#define DEFAULT_DISASM_BYTE_SIZE 32
76
Oleksiy Vyalov37386142015-02-10 22:49:57 +000077namespace {
78
Zachary Turner97206d52017-05-12 04:51:55 +000079Status AttachToProcess(ProcessAttachInfo &attach_info, Target &target) {
Kate Stoneb9c1b512016-09-06 20:57:50 +000080 std::lock_guard<std::recursive_mutex> guard(target.GetAPIMutex());
Oleksiy Vyalov37386142015-02-10 22:49:57 +000081
Kate Stoneb9c1b512016-09-06 20:57:50 +000082 auto process_sp = target.GetProcessSP();
83 if (process_sp) {
84 const auto state = process_sp->GetState();
85 if (process_sp->IsAlive() && state == eStateConnected) {
86 // If we are already connected, then we have already specified the
Adrian Prantl05097242018-04-30 16:49:04 +000087 // listener, so if a valid listener is supplied, we need to error out to
88 // let the client know.
Kate Stoneb9c1b512016-09-06 20:57:50 +000089 if (attach_info.GetListener())
Zachary Turner97206d52017-05-12 04:51:55 +000090 return Status("process is connected and already has a listener, pass "
91 "empty listener");
Oleksiy Vyalov37386142015-02-10 22:49:57 +000092 }
Kate Stoneb9c1b512016-09-06 20:57:50 +000093 }
Oleksiy Vyalov37386142015-02-10 22:49:57 +000094
Kate Stoneb9c1b512016-09-06 20:57:50 +000095 return target.Attach(attach_info, nullptr);
Oleksiy Vyalov37386142015-02-10 22:49:57 +000096}
97
Kate Stoneb9c1b512016-09-06 20:57:50 +000098} // namespace
Oleksiy Vyalov37386142015-02-10 22:49:57 +000099
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000100// SBTarget constructor
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000101SBTarget::SBTarget() : m_opaque_sp() {
102 LLDB_RECORD_CONSTRUCTOR_NO_ARGS(SBTarget);
103}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000104
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000105SBTarget::SBTarget(const SBTarget &rhs) : m_opaque_sp(rhs.m_opaque_sp) {
106 LLDB_RECORD_CONSTRUCTOR(SBTarget, (const lldb::SBTarget &), rhs);
107}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000108
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000109SBTarget::SBTarget(const TargetSP &target_sp) : m_opaque_sp(target_sp) {
110 LLDB_RECORD_CONSTRUCTOR(SBTarget, (const lldb::TargetSP &), target_sp);
111}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000112
Kate Stoneb9c1b512016-09-06 20:57:50 +0000113const SBTarget &SBTarget::operator=(const SBTarget &rhs) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000114 LLDB_RECORD_METHOD(const lldb::SBTarget &,
115 SBTarget, operator=,(const lldb::SBTarget &), rhs);
116
Kate Stoneb9c1b512016-09-06 20:57:50 +0000117 if (this != &rhs)
118 m_opaque_sp = rhs.m_opaque_sp;
Jonas Devlieghere306809f2019-04-03 21:31:22 +0000119 return LLDB_RECORD_RESULT(*this);
Greg Claytonefabb122010-11-05 23:17:00 +0000120}
121
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000122// Destructor
Kate Stoneb9c1b512016-09-06 20:57:50 +0000123SBTarget::~SBTarget() {}
124
125bool SBTarget::EventIsTargetEvent(const SBEvent &event) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000126 LLDB_RECORD_STATIC_METHOD(bool, SBTarget, EventIsTargetEvent,
127 (const lldb::SBEvent &), event);
128
Konrad Kleine248a1302019-05-23 11:14:47 +0000129 return Target::TargetEventData::GetEventDataFromEvent(event.get()) != nullptr;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000130}
131
Kate Stoneb9c1b512016-09-06 20:57:50 +0000132SBTarget SBTarget::GetTargetFromEvent(const SBEvent &event) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000133 LLDB_RECORD_STATIC_METHOD(lldb::SBTarget, SBTarget, GetTargetFromEvent,
134 (const lldb::SBEvent &), event);
135
136 return LLDB_RECORD_RESULT(
137 Target::TargetEventData::GetTargetFromEvent(event.get()));
Ilia Keb2c19a2015-03-10 21:59:55 +0000138}
139
Kate Stoneb9c1b512016-09-06 20:57:50 +0000140uint32_t SBTarget::GetNumModulesFromEvent(const SBEvent &event) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000141 LLDB_RECORD_STATIC_METHOD(uint32_t, SBTarget, GetNumModulesFromEvent,
142 (const lldb::SBEvent &), event);
143
Kate Stoneb9c1b512016-09-06 20:57:50 +0000144 const ModuleList module_list =
145 Target::TargetEventData::GetModuleListFromEvent(event.get());
146 return module_list.GetSize();
Ilia Keb2c19a2015-03-10 21:59:55 +0000147}
148
Kate Stoneb9c1b512016-09-06 20:57:50 +0000149SBModule SBTarget::GetModuleAtIndexFromEvent(const uint32_t idx,
150 const SBEvent &event) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000151 LLDB_RECORD_STATIC_METHOD(lldb::SBModule, SBTarget, GetModuleAtIndexFromEvent,
152 (const uint32_t, const lldb::SBEvent &), idx,
153 event);
154
Kate Stoneb9c1b512016-09-06 20:57:50 +0000155 const ModuleList module_list =
156 Target::TargetEventData::GetModuleListFromEvent(event.get());
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000157 return LLDB_RECORD_RESULT(SBModule(module_list.GetModuleAtIndex(idx)));
Ilia Keb2c19a2015-03-10 21:59:55 +0000158}
159
Kate Stoneb9c1b512016-09-06 20:57:50 +0000160const char *SBTarget::GetBroadcasterClassName() {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000161 LLDB_RECORD_STATIC_METHOD_NO_ARGS(const char *, SBTarget,
162 GetBroadcasterClassName);
163
Kate Stoneb9c1b512016-09-06 20:57:50 +0000164 return Target::GetStaticBroadcasterClass().AsCString();
Ilia Keb2c19a2015-03-10 21:59:55 +0000165}
166
Kate Stoneb9c1b512016-09-06 20:57:50 +0000167bool SBTarget::IsValid() const {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000168 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBTarget, IsValid);
Pavel Labath7f5237b2019-03-11 13:58:46 +0000169 return this->operator bool();
170}
171SBTarget::operator bool() const {
172 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBTarget, operator bool);
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000173
Konrad Kleine248a1302019-05-23 11:14:47 +0000174 return m_opaque_sp.get() != nullptr && m_opaque_sp->IsValid();
Jim Ingham4bddaeb2012-02-16 06:50:00 +0000175}
176
Kate Stoneb9c1b512016-09-06 20:57:50 +0000177SBProcess SBTarget::GetProcess() {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000178 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBProcess, SBTarget, GetProcess);
179
Kate Stoneb9c1b512016-09-06 20:57:50 +0000180 SBProcess sb_process;
181 ProcessSP process_sp;
182 TargetSP target_sp(GetSP());
183 if (target_sp) {
184 process_sp = target_sp->GetProcessSP();
185 sb_process.SetSP(process_sp);
186 }
187
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000188 return LLDB_RECORD_RESULT(sb_process);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000189}
190
Kate Stoneb9c1b512016-09-06 20:57:50 +0000191SBPlatform SBTarget::GetPlatform() {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000192 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBPlatform, SBTarget, GetPlatform);
193
Kate Stoneb9c1b512016-09-06 20:57:50 +0000194 TargetSP target_sp(GetSP());
195 if (!target_sp)
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000196 return LLDB_RECORD_RESULT(SBPlatform());
Kate Stoneb9c1b512016-09-06 20:57:50 +0000197
198 SBPlatform platform;
199 platform.m_opaque_sp = target_sp->GetPlatform();
200
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000201 return LLDB_RECORD_RESULT(platform);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000202}
203
204SBDebugger SBTarget::GetDebugger() const {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000205 LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::SBDebugger, SBTarget, GetDebugger);
206
Kate Stoneb9c1b512016-09-06 20:57:50 +0000207 SBDebugger debugger;
208 TargetSP target_sp(GetSP());
209 if (target_sp)
210 debugger.reset(target_sp->GetDebugger().shared_from_this());
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000211 return LLDB_RECORD_RESULT(debugger);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000212}
213
Davide Italiano4a6a2b12018-04-16 22:55:34 +0000214SBStructuredData SBTarget::GetStatistics() {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000215 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBStructuredData, SBTarget, GetStatistics);
216
Davide Italiano4a6a2b12018-04-16 22:55:34 +0000217 SBStructuredData data;
218 TargetSP target_sp(GetSP());
219 if (!target_sp)
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000220 return LLDB_RECORD_RESULT(data);
Davide Italiano4a6a2b12018-04-16 22:55:34 +0000221
222 auto stats_up = llvm::make_unique<StructuredData::Dictionary>();
223 int i = 0;
224 for (auto &Entry : target_sp->GetStatistics()) {
225 std::string Desc = lldb_private::GetStatDescription(
226 static_cast<lldb_private::StatisticKind>(i));
227 stats_up->AddIntegerItem(Desc, Entry);
228 i += 1;
229 }
230
231 data.m_impl_up->SetObjectSP(std::move(stats_up));
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000232 return LLDB_RECORD_RESULT(data);
Davide Italiano4a6a2b12018-04-16 22:55:34 +0000233}
234
Davide Italianoe1747462018-09-28 23:27:54 +0000235void SBTarget::SetCollectingStats(bool v) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000236 LLDB_RECORD_METHOD(void, SBTarget, SetCollectingStats, (bool), v);
237
Davide Italianoe1747462018-09-28 23:27:54 +0000238 TargetSP target_sp(GetSP());
239 if (!target_sp)
240 return;
241 return target_sp->SetCollectingStats(v);
242}
243
244bool SBTarget::GetCollectingStats() {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000245 LLDB_RECORD_METHOD_NO_ARGS(bool, SBTarget, GetCollectingStats);
246
Davide Italianoe1747462018-09-28 23:27:54 +0000247 TargetSP target_sp(GetSP());
248 if (!target_sp)
249 return false;
250 return target_sp->GetCollectingStats();
251}
252
Kate Stoneb9c1b512016-09-06 20:57:50 +0000253SBProcess SBTarget::LoadCore(const char *core_file) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000254 LLDB_RECORD_METHOD(lldb::SBProcess, SBTarget, LoadCore, (const char *),
255 core_file);
256
Leonard Mosescue1bb5172018-06-11 21:19:26 +0000257 lldb::SBError error; // Ignored
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000258 return LLDB_RECORD_RESULT(LoadCore(core_file, error));
Leonard Mosescue1bb5172018-06-11 21:19:26 +0000259}
260
261SBProcess SBTarget::LoadCore(const char *core_file, lldb::SBError &error) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000262 LLDB_RECORD_METHOD(lldb::SBProcess, SBTarget, LoadCore,
263 (const char *, lldb::SBError &), core_file, error);
264
Kate Stoneb9c1b512016-09-06 20:57:50 +0000265 SBProcess sb_process;
266 TargetSP target_sp(GetSP());
267 if (target_sp) {
Jonas Devlieghere8f3be7a2018-11-01 21:05:36 +0000268 FileSpec filespec(core_file);
269 FileSystem::Instance().Resolve(filespec);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000270 ProcessSP process_sp(target_sp->CreateProcess(
Zachary Turner31659452016-11-17 21:15:14 +0000271 target_sp->GetDebugger().GetListener(), "", &filespec));
Kate Stoneb9c1b512016-09-06 20:57:50 +0000272 if (process_sp) {
Leonard Mosescue1bb5172018-06-11 21:19:26 +0000273 error.SetError(process_sp->LoadCore());
274 if (error.Success())
275 sb_process.SetSP(process_sp);
276 } else {
277 error.SetErrorString("Failed to create the process");
Kate Stoneb9c1b512016-09-06 20:57:50 +0000278 }
Leonard Mosescue1bb5172018-06-11 21:19:26 +0000279 } else {
280 error.SetErrorString("SBTarget is invalid");
Kate Stoneb9c1b512016-09-06 20:57:50 +0000281 }
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000282 return LLDB_RECORD_RESULT(sb_process);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000283}
284
285SBProcess SBTarget::LaunchSimple(char const **argv, char const **envp,
286 const char *working_directory) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000287 LLDB_RECORD_METHOD(lldb::SBProcess, SBTarget, LaunchSimple,
288 (const char **, const char **, const char *), argv, envp,
289 working_directory);
290
Konrad Kleine248a1302019-05-23 11:14:47 +0000291 char *stdin_path = nullptr;
292 char *stdout_path = nullptr;
293 char *stderr_path = nullptr;
Kate Stoneb9c1b512016-09-06 20:57:50 +0000294 uint32_t launch_flags = 0;
295 bool stop_at_entry = false;
296 SBError error;
297 SBListener listener = GetDebugger().GetListener();
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000298 return LLDB_RECORD_RESULT(Launch(listener, argv, envp, stdin_path,
299 stdout_path, stderr_path, working_directory,
300 launch_flags, stop_at_entry, error));
Kate Stoneb9c1b512016-09-06 20:57:50 +0000301}
302
303SBError SBTarget::Install() {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000304 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBError, SBTarget, Install);
305
Kate Stoneb9c1b512016-09-06 20:57:50 +0000306 SBError sb_error;
307 TargetSP target_sp(GetSP());
308 if (target_sp) {
309 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
Konrad Kleine248a1302019-05-23 11:14:47 +0000310 sb_error.ref() = target_sp->Install(nullptr);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000311 }
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000312 return LLDB_RECORD_RESULT(sb_error);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000313}
314
315SBProcess SBTarget::Launch(SBListener &listener, char const **argv,
316 char const **envp, const char *stdin_path,
317 const char *stdout_path, const char *stderr_path,
318 const char *working_directory,
319 uint32_t launch_flags, // See LaunchFlags
320 bool stop_at_entry, lldb::SBError &error) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000321 LLDB_RECORD_METHOD(lldb::SBProcess, SBTarget, Launch,
322 (lldb::SBListener &, const char **, const char **,
323 const char *, const char *, const char *, const char *,
324 uint32_t, bool, lldb::SBError &),
325 listener, argv, envp, stdin_path, stdout_path, stderr_path,
326 working_directory, launch_flags, stop_at_entry, error);
327
Kate Stoneb9c1b512016-09-06 20:57:50 +0000328 SBProcess sb_process;
329 ProcessSP process_sp;
330 TargetSP target_sp(GetSP());
331
Kate Stoneb9c1b512016-09-06 20:57:50 +0000332 if (target_sp) {
333 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
334
335 if (stop_at_entry)
336 launch_flags |= eLaunchFlagStopAtEntry;
337
338 if (getenv("LLDB_LAUNCH_FLAG_DISABLE_ASLR"))
339 launch_flags |= eLaunchFlagDisableASLR;
340
341 StateType state = eStateInvalid;
342 process_sp = target_sp->GetProcessSP();
343 if (process_sp) {
344 state = process_sp->GetState();
345
346 if (process_sp->IsAlive() && state != eStateConnected) {
347 if (state == eStateAttaching)
348 error.SetErrorString("process attach is in progress");
349 else
350 error.SetErrorString("a process is already being debugged");
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000351 return LLDB_RECORD_RESULT(sb_process);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000352 }
Greg Claytonaf67cec2010-12-20 20:49:23 +0000353 }
Caroline Ticeceb6b132010-10-26 03:11:13 +0000354
Kate Stoneb9c1b512016-09-06 20:57:50 +0000355 if (state == eStateConnected) {
356 // If we are already connected, then we have already specified the
Adrian Prantl05097242018-04-30 16:49:04 +0000357 // listener, so if a valid listener is supplied, we need to error out to
358 // let the client know.
Kate Stoneb9c1b512016-09-06 20:57:50 +0000359 if (listener.IsValid()) {
360 error.SetErrorString("process is connected and already has a listener, "
361 "pass empty listener");
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000362 return LLDB_RECORD_RESULT(sb_process);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000363 }
364 }
Caroline Ticeceb6b132010-10-26 03:11:13 +0000365
Kate Stoneb9c1b512016-09-06 20:57:50 +0000366 if (getenv("LLDB_LAUNCH_FLAG_DISABLE_STDIO"))
367 launch_flags |= eLaunchFlagDisableSTDIO;
368
Jonas Devlieghere8f3be7a2018-11-01 21:05:36 +0000369 ProcessLaunchInfo launch_info(FileSpec(stdin_path), FileSpec(stdout_path),
370 FileSpec(stderr_path),
371 FileSpec(working_directory), launch_flags);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000372
373 Module *exe_module = target_sp->GetExecutableModulePointer();
374 if (exe_module)
375 launch_info.SetExecutableFile(exe_module->GetPlatformFileSpec(), true);
376 if (argv)
377 launch_info.GetArguments().AppendArguments(argv);
378 if (envp)
Pavel Labath62930e52018-01-10 11:57:31 +0000379 launch_info.GetEnvironment() = Environment(envp);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000380
381 if (listener.IsValid())
382 launch_info.SetListener(listener.GetSP());
383
Konrad Kleine248a1302019-05-23 11:14:47 +0000384 error.SetError(target_sp->Launch(launch_info, nullptr));
Kate Stoneb9c1b512016-09-06 20:57:50 +0000385
386 sb_process.SetSP(target_sp->GetProcessSP());
387 } else {
388 error.SetErrorString("SBTarget is invalid");
389 }
390
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000391 return LLDB_RECORD_RESULT(sb_process);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000392}
393
Kate Stoneb9c1b512016-09-06 20:57:50 +0000394SBProcess SBTarget::Launch(SBLaunchInfo &sb_launch_info, SBError &error) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000395 LLDB_RECORD_METHOD(lldb::SBProcess, SBTarget, Launch,
396 (lldb::SBLaunchInfo &, lldb::SBError &), sb_launch_info,
397 error);
398
Matthew Gardinerc928de32014-10-22 07:22:56 +0000399
Kate Stoneb9c1b512016-09-06 20:57:50 +0000400 SBProcess sb_process;
401 TargetSP target_sp(GetSP());
Matthew Gardinerc928de32014-10-22 07:22:56 +0000402
Kate Stoneb9c1b512016-09-06 20:57:50 +0000403 if (target_sp) {
404 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
405 StateType state = eStateInvalid;
Greg Clayton4d8ad552013-03-25 22:40:51 +0000406 {
Kate Stoneb9c1b512016-09-06 20:57:50 +0000407 ProcessSP process_sp = target_sp->GetProcessSP();
408 if (process_sp) {
409 state = process_sp->GetState();
410
411 if (process_sp->IsAlive() && state != eStateConnected) {
412 if (state == eStateAttaching)
413 error.SetErrorString("process attach is in progress");
414 else
415 error.SetErrorString("a process is already being debugged");
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000416 return LLDB_RECORD_RESULT(sb_process);
Greg Clayton4d8ad552013-03-25 22:40:51 +0000417 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000418 }
Greg Clayton4d8ad552013-03-25 22:40:51 +0000419 }
Greg Clayton4d8ad552013-03-25 22:40:51 +0000420
Pavel Labath62930e52018-01-10 11:57:31 +0000421 lldb_private::ProcessLaunchInfo launch_info = sb_launch_info.ref();
Greg Claytonbd82a5d2011-01-23 05:56:20 +0000422
Kate Stoneb9c1b512016-09-06 20:57:50 +0000423 if (!launch_info.GetExecutableFile()) {
424 Module *exe_module = target_sp->GetExecutableModulePointer();
425 if (exe_module)
426 launch_info.SetExecutableFile(exe_module->GetPlatformFileSpec(), true);
Greg Claytonfbb76342013-11-20 21:07:01 +0000427 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000428
429 const ArchSpec &arch_spec = target_sp->GetArchitecture();
430 if (arch_spec.IsValid())
431 launch_info.GetArchitecture() = arch_spec;
432
Konrad Kleine248a1302019-05-23 11:14:47 +0000433 error.SetError(target_sp->Launch(launch_info, nullptr));
Pavel Labath62930e52018-01-10 11:57:31 +0000434 sb_launch_info.set_ref(launch_info);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000435 sb_process.SetSP(target_sp->GetProcessSP());
436 } else {
437 error.SetErrorString("SBTarget is invalid");
438 }
439
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000440 return LLDB_RECORD_RESULT(sb_process);
Greg Claytonfbb76342013-11-20 21:07:01 +0000441}
442
Kate Stoneb9c1b512016-09-06 20:57:50 +0000443lldb::SBProcess SBTarget::Attach(SBAttachInfo &sb_attach_info, SBError &error) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000444 LLDB_RECORD_METHOD(lldb::SBProcess, SBTarget, Attach,
445 (lldb::SBAttachInfo &, lldb::SBError &), sb_attach_info,
446 error);
447
Kate Stoneb9c1b512016-09-06 20:57:50 +0000448 SBProcess sb_process;
449 TargetSP target_sp(GetSP());
Greg Claytonacdbe812012-01-30 09:04:36 +0000450
Kate Stoneb9c1b512016-09-06 20:57:50 +0000451 if (target_sp) {
452 ProcessAttachInfo &attach_info = sb_attach_info.ref();
453 if (attach_info.ProcessIDIsValid() && !attach_info.UserIDIsValid()) {
454 PlatformSP platform_sp = target_sp->GetPlatform();
455 // See if we can pre-verify if a process exists or not
456 if (platform_sp && platform_sp->IsConnected()) {
457 lldb::pid_t attach_pid = attach_info.GetProcessID();
458 ProcessInstanceInfo instance_info;
459 if (platform_sp->GetProcessInfo(attach_pid, instance_info)) {
460 attach_info.SetUserID(instance_info.GetEffectiveUserID());
461 } else {
462 error.ref().SetErrorStringWithFormat(
463 "no process found with process ID %" PRIu64, attach_pid);
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000464 return LLDB_RECORD_RESULT(sb_process);
Greg Clayton931180e2011-01-27 06:44:37 +0000465 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000466 }
Greg Clayton524e60b2010-10-06 22:10:17 +0000467 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000468 error.SetError(AttachToProcess(attach_info, *target_sp));
469 if (error.Success())
470 sb_process.SetSP(target_sp->GetProcessSP());
471 } else {
472 error.SetErrorString("SBTarget is invalid");
473 }
Caroline Ticeceb6b132010-10-26 03:11:13 +0000474
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000475 return LLDB_RECORD_RESULT(sb_process);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000476}
477
Kate Stoneb9c1b512016-09-06 20:57:50 +0000478lldb::SBProcess SBTarget::AttachToProcessWithID(
James McIlree9631aae2011-03-04 00:31:13 +0000479 SBListener &listener,
Kate Stoneb9c1b512016-09-06 20:57:50 +0000480 lldb::pid_t pid, // The process ID to attach to
481 SBError &error // An error explaining what went wrong if attach fails
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000482) {
483 LLDB_RECORD_METHOD(lldb::SBProcess, SBTarget, AttachToProcessWithID,
484 (lldb::SBListener &, lldb::pid_t, lldb::SBError &),
485 listener, pid, error);
486
Kate Stoneb9c1b512016-09-06 20:57:50 +0000487 SBProcess sb_process;
488 TargetSP target_sp(GetSP());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000489
Kate Stoneb9c1b512016-09-06 20:57:50 +0000490 if (target_sp) {
491 ProcessAttachInfo attach_info;
492 attach_info.SetProcessID(pid);
493 if (listener.IsValid())
494 attach_info.SetListener(listener.GetSP());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000495
Kate Stoneb9c1b512016-09-06 20:57:50 +0000496 ProcessInstanceInfo instance_info;
497 if (target_sp->GetPlatform()->GetProcessInfo(pid, instance_info))
498 attach_info.SetUserID(instance_info.GetEffectiveUserID());
499
500 error.SetError(AttachToProcess(attach_info, *target_sp));
501 if (error.Success())
502 sb_process.SetSP(target_sp->GetProcessSP());
503 } else
504 error.SetErrorString("SBTarget is invalid");
505
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000506 return LLDB_RECORD_RESULT(sb_process);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000507}
508
509lldb::SBProcess SBTarget::AttachToProcessWithName(
510 SBListener &listener,
511 const char *name, // basename of process to attach to
512 bool wait_for, // if true wait for a new instance of "name" to be launched
513 SBError &error // An error explaining what went wrong if attach fails
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000514) {
515 LLDB_RECORD_METHOD(lldb::SBProcess, SBTarget, AttachToProcessWithName,
516 (lldb::SBListener &, const char *, bool, lldb::SBError &),
517 listener, name, wait_for, error);
518
Kate Stoneb9c1b512016-09-06 20:57:50 +0000519 SBProcess sb_process;
520 TargetSP target_sp(GetSP());
521
Kate Stoneb9c1b512016-09-06 20:57:50 +0000522 if (name && target_sp) {
523 ProcessAttachInfo attach_info;
Jonas Devlieghere8f3be7a2018-11-01 21:05:36 +0000524 attach_info.GetExecutableFile().SetFile(name, FileSpec::Style::native);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000525 attach_info.SetWaitForLaunch(wait_for);
526 if (listener.IsValid())
527 attach_info.SetListener(listener.GetSP());
528
529 error.SetError(AttachToProcess(attach_info, *target_sp));
530 if (error.Success())
531 sb_process.SetSP(target_sp->GetProcessSP());
532 } else
533 error.SetErrorString("SBTarget is invalid");
534
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000535 return LLDB_RECORD_RESULT(sb_process);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000536}
537
538lldb::SBProcess SBTarget::ConnectRemote(SBListener &listener, const char *url,
539 const char *plugin_name,
540 SBError &error) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000541 LLDB_RECORD_METHOD(
542 lldb::SBProcess, SBTarget, ConnectRemote,
543 (lldb::SBListener &, const char *, const char *, lldb::SBError &),
544 listener, url, plugin_name, error);
545
Kate Stoneb9c1b512016-09-06 20:57:50 +0000546 SBProcess sb_process;
547 ProcessSP process_sp;
548 TargetSP target_sp(GetSP());
549
Kate Stoneb9c1b512016-09-06 20:57:50 +0000550 if (target_sp) {
551 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
552 if (listener.IsValid())
553 process_sp =
Konrad Kleine248a1302019-05-23 11:14:47 +0000554 target_sp->CreateProcess(listener.m_opaque_sp, plugin_name, nullptr);
James McIlree9631aae2011-03-04 00:31:13 +0000555 else
Kate Stoneb9c1b512016-09-06 20:57:50 +0000556 process_sp = target_sp->CreateProcess(
Konrad Kleine248a1302019-05-23 11:14:47 +0000557 target_sp->GetDebugger().GetListener(), plugin_name, nullptr);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000558
559 if (process_sp) {
560 sb_process.SetSP(process_sp);
Konrad Kleine248a1302019-05-23 11:14:47 +0000561 error.SetError(process_sp->ConnectRemote(nullptr, url));
Kate Stoneb9c1b512016-09-06 20:57:50 +0000562 } else {
563 error.SetErrorString("unable to create lldb_private::Process");
James McIlree9631aae2011-03-04 00:31:13 +0000564 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000565 } else {
566 error.SetErrorString("SBTarget is invalid");
567 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000568
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000569 return LLDB_RECORD_RESULT(sb_process);
James McIlree9631aae2011-03-04 00:31:13 +0000570}
571
Kate Stoneb9c1b512016-09-06 20:57:50 +0000572SBFileSpec SBTarget::GetExecutable() {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000573 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBFileSpec, SBTarget, GetExecutable);
Caroline Ticeceb6b132010-10-26 03:11:13 +0000574
Kate Stoneb9c1b512016-09-06 20:57:50 +0000575 SBFileSpec exe_file_spec;
576 TargetSP target_sp(GetSP());
577 if (target_sp) {
578 Module *exe_module = target_sp->GetExecutableModulePointer();
579 if (exe_module)
580 exe_file_spec.SetFileSpec(exe_module->GetFileSpec());
581 }
Caroline Ticeceb6b132010-10-26 03:11:13 +0000582
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000583 return LLDB_RECORD_RESULT(exe_file_spec);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000584}
585
Kate Stoneb9c1b512016-09-06 20:57:50 +0000586bool SBTarget::operator==(const SBTarget &rhs) const {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000587 LLDB_RECORD_METHOD_CONST(bool, SBTarget, operator==,(const lldb::SBTarget &),
588 rhs);
589
Kate Stoneb9c1b512016-09-06 20:57:50 +0000590 return m_opaque_sp.get() == rhs.m_opaque_sp.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000591}
592
Kate Stoneb9c1b512016-09-06 20:57:50 +0000593bool SBTarget::operator!=(const SBTarget &rhs) const {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000594 LLDB_RECORD_METHOD_CONST(bool, SBTarget, operator!=,(const lldb::SBTarget &),
595 rhs);
596
Kate Stoneb9c1b512016-09-06 20:57:50 +0000597 return m_opaque_sp.get() != rhs.m_opaque_sp.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000598}
599
Kate Stoneb9c1b512016-09-06 20:57:50 +0000600lldb::TargetSP SBTarget::GetSP() const { return m_opaque_sp; }
601
602void SBTarget::SetSP(const lldb::TargetSP &target_sp) {
603 m_opaque_sp = target_sp;
Greg Clayton9a377662011-10-01 02:59:24 +0000604}
605
Kate Stoneb9c1b512016-09-06 20:57:50 +0000606lldb::SBAddress SBTarget::ResolveLoadAddress(lldb::addr_t vm_addr) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000607 LLDB_RECORD_METHOD(lldb::SBAddress, SBTarget, ResolveLoadAddress,
608 (lldb::addr_t), vm_addr);
609
Kate Stoneb9c1b512016-09-06 20:57:50 +0000610 lldb::SBAddress sb_addr;
611 Address &addr = sb_addr.ref();
612 TargetSP target_sp(GetSP());
613 if (target_sp) {
614 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
615 if (target_sp->ResolveLoadAddress(vm_addr, addr))
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000616 return LLDB_RECORD_RESULT(sb_addr);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000617 }
618
619 // We have a load address that isn't in a section, just return an address
620 // with the offset filled in (the address) and the section set to NULL
621 addr.SetRawAddress(vm_addr);
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000622 return LLDB_RECORD_RESULT(sb_addr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000623}
624
Kate Stoneb9c1b512016-09-06 20:57:50 +0000625lldb::SBAddress SBTarget::ResolveFileAddress(lldb::addr_t file_addr) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000626 LLDB_RECORD_METHOD(lldb::SBAddress, SBTarget, ResolveFileAddress,
627 (lldb::addr_t), file_addr);
628
Kate Stoneb9c1b512016-09-06 20:57:50 +0000629 lldb::SBAddress sb_addr;
630 Address &addr = sb_addr.ref();
631 TargetSP target_sp(GetSP());
632 if (target_sp) {
633 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
634 if (target_sp->ResolveFileAddress(file_addr, addr))
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000635 return LLDB_RECORD_RESULT(sb_addr);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000636 }
Greg Claytonac2eb9b2010-12-12 19:25:26 +0000637
Kate Stoneb9c1b512016-09-06 20:57:50 +0000638 addr.SetRawAddress(file_addr);
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000639 return LLDB_RECORD_RESULT(sb_addr);
Greg Claytonac2eb9b2010-12-12 19:25:26 +0000640}
641
Kate Stoneb9c1b512016-09-06 20:57:50 +0000642lldb::SBAddress SBTarget::ResolvePastLoadAddress(uint32_t stop_id,
643 lldb::addr_t vm_addr) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000644 LLDB_RECORD_METHOD(lldb::SBAddress, SBTarget, ResolvePastLoadAddress,
645 (uint32_t, lldb::addr_t), stop_id, vm_addr);
646
Kate Stoneb9c1b512016-09-06 20:57:50 +0000647 lldb::SBAddress sb_addr;
648 Address &addr = sb_addr.ref();
649 TargetSP target_sp(GetSP());
650 if (target_sp) {
651 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
652 if (target_sp->ResolveLoadAddress(vm_addr, addr))
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000653 return LLDB_RECORD_RESULT(sb_addr);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000654 }
Matthew Gardinerc928de32014-10-22 07:22:56 +0000655
Kate Stoneb9c1b512016-09-06 20:57:50 +0000656 // We have a load address that isn't in a section, just return an address
657 // with the offset filled in (the address) and the section set to NULL
658 addr.SetRawAddress(vm_addr);
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000659 return LLDB_RECORD_RESULT(sb_addr);
Greg Claytond5944cd2013-12-06 01:12:00 +0000660}
661
Greg Clayton5f2a4f92011-03-02 21:34:46 +0000662SBSymbolContext
Kate Stoneb9c1b512016-09-06 20:57:50 +0000663SBTarget::ResolveSymbolContextForAddress(const SBAddress &addr,
664 uint32_t resolve_scope) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000665 LLDB_RECORD_METHOD(lldb::SBSymbolContext, SBTarget,
666 ResolveSymbolContextForAddress,
667 (const lldb::SBAddress &, uint32_t), addr, resolve_scope);
668
Kate Stoneb9c1b512016-09-06 20:57:50 +0000669 SBSymbolContext sc;
Zachary Turner991e4452018-10-25 20:45:19 +0000670 SymbolContextItem scope = static_cast<SymbolContextItem>(resolve_scope);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000671 if (addr.IsValid()) {
Matthew Gardinerc928de32014-10-22 07:22:56 +0000672 TargetSP target_sp(GetSP());
673 if (target_sp)
Zachary Turner991e4452018-10-25 20:45:19 +0000674 target_sp->GetImages().ResolveSymbolContextForAddress(addr.ref(), scope,
675 sc.ref());
Kate Stoneb9c1b512016-09-06 20:57:50 +0000676 }
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000677 return LLDB_RECORD_RESULT(sc);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000678}
Matthew Gardinerc928de32014-10-22 07:22:56 +0000679
Kate Stoneb9c1b512016-09-06 20:57:50 +0000680size_t SBTarget::ReadMemory(const SBAddress addr, void *buf, size_t size,
681 lldb::SBError &error) {
Jonas Devlieghere0d7b0c92019-03-08 19:09:27 +0000682 LLDB_RECORD_DUMMY(size_t, SBTarget, ReadMemory,
683 (const lldb::SBAddress, void *, size_t, lldb::SBError &),
684 addr, buf, size, error);
685
Kate Stoneb9c1b512016-09-06 20:57:50 +0000686 SBError sb_error;
687 size_t bytes_read = 0;
688 TargetSP target_sp(GetSP());
689 if (target_sp) {
690 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
691 bytes_read =
692 target_sp->ReadMemory(addr.ref(), false, buf, size, sb_error.ref());
693 } else {
694 sb_error.SetErrorString("invalid target");
695 }
696
697 return bytes_read;
698}
699
700SBBreakpoint SBTarget::BreakpointCreateByLocation(const char *file,
701 uint32_t line) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000702 LLDB_RECORD_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateByLocation,
703 (const char *, uint32_t), file, line);
704
705 return LLDB_RECORD_RESULT(
706 SBBreakpoint(BreakpointCreateByLocation(SBFileSpec(file, false), line)));
Matthew Gardinerc928de32014-10-22 07:22:56 +0000707}
Greg Clayton5f2a4f92011-03-02 21:34:46 +0000708
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000709SBBreakpoint
Kate Stoneb9c1b512016-09-06 20:57:50 +0000710SBTarget::BreakpointCreateByLocation(const SBFileSpec &sb_file_spec,
711 uint32_t line) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000712 LLDB_RECORD_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateByLocation,
713 (const lldb::SBFileSpec &, uint32_t), sb_file_spec, line);
714
715 return LLDB_RECORD_RESULT(BreakpointCreateByLocation(sb_file_spec, line, 0));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000716}
717
718SBBreakpoint
Kate Stoneb9c1b512016-09-06 20:57:50 +0000719SBTarget::BreakpointCreateByLocation(const SBFileSpec &sb_file_spec,
720 uint32_t line, lldb::addr_t offset) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000721 LLDB_RECORD_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateByLocation,
722 (const lldb::SBFileSpec &, uint32_t, lldb::addr_t),
723 sb_file_spec, line, offset);
724
Jim Ingham92d19602016-09-20 22:54:49 +0000725 SBFileSpecList empty_list;
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000726 return LLDB_RECORD_RESULT(
727 BreakpointCreateByLocation(sb_file_spec, line, offset, empty_list));
Jim Ingham92d19602016-09-20 22:54:49 +0000728}
729
730SBBreakpoint
731SBTarget::BreakpointCreateByLocation(const SBFileSpec &sb_file_spec,
732 uint32_t line, lldb::addr_t offset,
733 SBFileSpecList &sb_module_list) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000734 LLDB_RECORD_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateByLocation,
735 (const lldb::SBFileSpec &, uint32_t, lldb::addr_t,
736 lldb::SBFileSpecList &),
737 sb_file_spec, line, offset, sb_module_list);
738
739 return LLDB_RECORD_RESULT(BreakpointCreateByLocation(sb_file_spec, line, 0,
740 offset, sb_module_list));
Adrian Prantl431b1582018-08-30 15:11:00 +0000741}
742
743SBBreakpoint SBTarget::BreakpointCreateByLocation(
744 const SBFileSpec &sb_file_spec, uint32_t line, uint32_t column,
745 lldb::addr_t offset, SBFileSpecList &sb_module_list) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000746 LLDB_RECORD_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateByLocation,
747 (const lldb::SBFileSpec &, uint32_t, uint32_t,
748 lldb::addr_t, lldb::SBFileSpecList &),
749 sb_file_spec, line, column, offset, sb_module_list);
750
Kate Stoneb9c1b512016-09-06 20:57:50 +0000751 SBBreakpoint sb_bp;
752 TargetSP target_sp(GetSP());
753 if (target_sp && line != 0) {
754 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
Caroline Ticeceb6b132010-10-26 03:11:13 +0000755
Kate Stoneb9c1b512016-09-06 20:57:50 +0000756 const LazyBool check_inlines = eLazyBoolCalculate;
757 const LazyBool skip_prologue = eLazyBoolCalculate;
758 const bool internal = false;
759 const bool hardware = false;
760 const LazyBool move_to_nearest_code = eLazyBoolCalculate;
Jim Ingham92d19602016-09-20 22:54:49 +0000761 const FileSpecList *module_list = nullptr;
762 if (sb_module_list.GetSize() > 0) {
763 module_list = sb_module_list.get();
764 }
Pavel Labath6ac84032017-02-27 11:05:34 +0000765 sb_bp = target_sp->CreateBreakpoint(
Adrian Prantl431b1582018-08-30 15:11:00 +0000766 module_list, *sb_file_spec, line, column, offset, check_inlines,
767 skip_prologue, internal, hardware, move_to_nearest_code);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000768 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000769
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000770 return LLDB_RECORD_RESULT(sb_bp);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000771}
772
773SBBreakpoint SBTarget::BreakpointCreateByName(const char *symbol_name,
774 const char *module_name) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000775 LLDB_RECORD_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateByName,
776 (const char *, const char *), symbol_name, module_name);
777
Kate Stoneb9c1b512016-09-06 20:57:50 +0000778 SBBreakpoint sb_bp;
779 TargetSP target_sp(GetSP());
780 if (target_sp.get()) {
781 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
782
783 const bool internal = false;
784 const bool hardware = false;
785 const LazyBool skip_prologue = eLazyBoolCalculate;
786 const lldb::addr_t offset = 0;
787 if (module_name && module_name[0]) {
788 FileSpecList module_spec_list;
Jonas Devlieghere8f3be7a2018-11-01 21:05:36 +0000789 module_spec_list.Append(FileSpec(module_name));
Pavel Labath6ac84032017-02-27 11:05:34 +0000790 sb_bp = target_sp->CreateBreakpoint(
Konrad Kleine248a1302019-05-23 11:14:47 +0000791 &module_spec_list, nullptr, symbol_name, eFunctionNameTypeAuto,
Kate Stoneb9c1b512016-09-06 20:57:50 +0000792 eLanguageTypeUnknown, offset, skip_prologue, internal, hardware);
793 } else {
Pavel Labath6ac84032017-02-27 11:05:34 +0000794 sb_bp = target_sp->CreateBreakpoint(
Konrad Kleine248a1302019-05-23 11:14:47 +0000795 nullptr, nullptr, symbol_name, eFunctionNameTypeAuto,
796 eLanguageTypeUnknown, offset, skip_prologue, internal, hardware);
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000797 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000798 }
799
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000800 return LLDB_RECORD_RESULT(sb_bp);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000801}
802
803lldb::SBBreakpoint
804SBTarget::BreakpointCreateByName(const char *symbol_name,
805 const SBFileSpecList &module_list,
806 const SBFileSpecList &comp_unit_list) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000807 LLDB_RECORD_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateByName,
808 (const char *, const lldb::SBFileSpecList &,
809 const lldb::SBFileSpecList &),
810 symbol_name, module_list, comp_unit_list);
811
Zachary Turner117b1fa2018-10-25 20:45:40 +0000812 lldb::FunctionNameType name_type_mask = eFunctionNameTypeAuto;
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000813 return LLDB_RECORD_RESULT(
814 BreakpointCreateByName(symbol_name, name_type_mask, eLanguageTypeUnknown,
815 module_list, comp_unit_list));
Kate Stoneb9c1b512016-09-06 20:57:50 +0000816}
817
818lldb::SBBreakpoint SBTarget::BreakpointCreateByName(
819 const char *symbol_name, uint32_t name_type_mask,
820 const SBFileSpecList &module_list, const SBFileSpecList &comp_unit_list) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000821 LLDB_RECORD_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateByName,
822 (const char *, uint32_t, const lldb::SBFileSpecList &,
823 const lldb::SBFileSpecList &),
824 symbol_name, name_type_mask, module_list, comp_unit_list);
825
826 return LLDB_RECORD_RESULT(
827 BreakpointCreateByName(symbol_name, name_type_mask, eLanguageTypeUnknown,
828 module_list, comp_unit_list));
Kate Stoneb9c1b512016-09-06 20:57:50 +0000829}
830
831lldb::SBBreakpoint SBTarget::BreakpointCreateByName(
832 const char *symbol_name, uint32_t name_type_mask,
833 LanguageType symbol_language, const SBFileSpecList &module_list,
834 const SBFileSpecList &comp_unit_list) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000835 LLDB_RECORD_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateByName,
836 (const char *, uint32_t, lldb::LanguageType,
837 const lldb::SBFileSpecList &,
838 const lldb::SBFileSpecList &),
839 symbol_name, name_type_mask, symbol_language, module_list,
840 comp_unit_list);
841
Kate Stoneb9c1b512016-09-06 20:57:50 +0000842 SBBreakpoint sb_bp;
843 TargetSP target_sp(GetSP());
844 if (target_sp && symbol_name && symbol_name[0]) {
845 const bool internal = false;
846 const bool hardware = false;
847 const LazyBool skip_prologue = eLazyBoolCalculate;
848 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
Zachary Turner117b1fa2018-10-25 20:45:40 +0000849 FunctionNameType mask = static_cast<FunctionNameType>(name_type_mask);
850 sb_bp = target_sp->CreateBreakpoint(module_list.get(), comp_unit_list.get(),
851 symbol_name, mask, symbol_language, 0,
852 skip_prologue, internal, hardware);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000853 }
854
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000855 return LLDB_RECORD_RESULT(sb_bp);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000856}
857
858lldb::SBBreakpoint SBTarget::BreakpointCreateByNames(
859 const char *symbol_names[], uint32_t num_names, uint32_t name_type_mask,
860 const SBFileSpecList &module_list, const SBFileSpecList &comp_unit_list) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000861 LLDB_RECORD_METHOD(
862 lldb::SBBreakpoint, SBTarget, BreakpointCreateByNames,
863 (const char **, uint32_t, uint32_t, const lldb::SBFileSpecList &,
864 const lldb::SBFileSpecList &),
865 symbol_names, num_names, name_type_mask, module_list, comp_unit_list);
866
867 return LLDB_RECORD_RESULT(BreakpointCreateByNames(
868 symbol_names, num_names, name_type_mask, eLanguageTypeUnknown,
869 module_list, comp_unit_list));
Kate Stoneb9c1b512016-09-06 20:57:50 +0000870}
871
872lldb::SBBreakpoint SBTarget::BreakpointCreateByNames(
873 const char *symbol_names[], uint32_t num_names, uint32_t name_type_mask,
874 LanguageType symbol_language, const SBFileSpecList &module_list,
875 const SBFileSpecList &comp_unit_list) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000876 LLDB_RECORD_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateByNames,
877 (const char **, uint32_t, uint32_t, lldb::LanguageType,
878 const lldb::SBFileSpecList &,
879 const lldb::SBFileSpecList &),
880 symbol_names, num_names, name_type_mask, symbol_language,
881 module_list, comp_unit_list);
882
883 return LLDB_RECORD_RESULT(BreakpointCreateByNames(
884 symbol_names, num_names, name_type_mask, eLanguageTypeUnknown, 0,
885 module_list, comp_unit_list));
Kate Stoneb9c1b512016-09-06 20:57:50 +0000886}
887
888lldb::SBBreakpoint SBTarget::BreakpointCreateByNames(
889 const char *symbol_names[], uint32_t num_names, uint32_t name_type_mask,
890 LanguageType symbol_language, lldb::addr_t offset,
891 const SBFileSpecList &module_list, const SBFileSpecList &comp_unit_list) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000892 LLDB_RECORD_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateByNames,
893 (const char **, uint32_t, uint32_t, lldb::LanguageType,
894 lldb::addr_t, const lldb::SBFileSpecList &,
895 const lldb::SBFileSpecList &),
896 symbol_names, num_names, name_type_mask, symbol_language,
897 offset, module_list, comp_unit_list);
898
Kate Stoneb9c1b512016-09-06 20:57:50 +0000899 SBBreakpoint sb_bp;
900 TargetSP target_sp(GetSP());
901 if (target_sp && num_names > 0) {
902 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
903 const bool internal = false;
904 const bool hardware = false;
Zachary Turner117b1fa2018-10-25 20:45:40 +0000905 FunctionNameType mask = static_cast<FunctionNameType>(name_type_mask);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000906 const LazyBool skip_prologue = eLazyBoolCalculate;
Pavel Labath6ac84032017-02-27 11:05:34 +0000907 sb_bp = target_sp->CreateBreakpoint(
Zachary Turner117b1fa2018-10-25 20:45:40 +0000908 module_list.get(), comp_unit_list.get(), symbol_names, num_names, mask,
909 symbol_language, offset, skip_prologue, internal, hardware);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000910 }
911
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000912 return LLDB_RECORD_RESULT(sb_bp);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000913}
914
915SBBreakpoint SBTarget::BreakpointCreateByRegex(const char *symbol_name_regex,
916 const char *module_name) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000917 LLDB_RECORD_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateByRegex,
918 (const char *, const char *), symbol_name_regex,
919 module_name);
920
Kate Stoneb9c1b512016-09-06 20:57:50 +0000921 SBFileSpecList module_spec_list;
922 SBFileSpecList comp_unit_list;
923 if (module_name && module_name[0]) {
Jonas Devlieghere8f3be7a2018-11-01 21:05:36 +0000924 module_spec_list.Append(FileSpec(module_name));
Kate Stoneb9c1b512016-09-06 20:57:50 +0000925 }
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000926 return LLDB_RECORD_RESULT(
927 BreakpointCreateByRegex(symbol_name_regex, eLanguageTypeUnknown,
928 module_spec_list, comp_unit_list));
Kate Stoneb9c1b512016-09-06 20:57:50 +0000929}
930
931lldb::SBBreakpoint
932SBTarget::BreakpointCreateByRegex(const char *symbol_name_regex,
933 const SBFileSpecList &module_list,
934 const SBFileSpecList &comp_unit_list) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000935 LLDB_RECORD_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateByRegex,
936 (const char *, const lldb::SBFileSpecList &,
937 const lldb::SBFileSpecList &),
938 symbol_name_regex, module_list, comp_unit_list);
939
940 return LLDB_RECORD_RESULT(BreakpointCreateByRegex(
941 symbol_name_regex, eLanguageTypeUnknown, module_list, comp_unit_list));
Kate Stoneb9c1b512016-09-06 20:57:50 +0000942}
943
944lldb::SBBreakpoint SBTarget::BreakpointCreateByRegex(
945 const char *symbol_name_regex, LanguageType symbol_language,
946 const SBFileSpecList &module_list, const SBFileSpecList &comp_unit_list) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000947 LLDB_RECORD_METHOD(
948 lldb::SBBreakpoint, SBTarget, BreakpointCreateByRegex,
949 (const char *, lldb::LanguageType, const lldb::SBFileSpecList &,
950 const lldb::SBFileSpecList &),
951 symbol_name_regex, symbol_language, module_list, comp_unit_list);
952
Kate Stoneb9c1b512016-09-06 20:57:50 +0000953
954 SBBreakpoint sb_bp;
955 TargetSP target_sp(GetSP());
956 if (target_sp && symbol_name_regex && symbol_name_regex[0]) {
957 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
Zachary Turner95eae422016-09-21 16:01:28 +0000958 RegularExpression regexp((llvm::StringRef(symbol_name_regex)));
Kate Stoneb9c1b512016-09-06 20:57:50 +0000959 const bool internal = false;
960 const bool hardware = false;
961 const LazyBool skip_prologue = eLazyBoolCalculate;
962
Pavel Labath6ac84032017-02-27 11:05:34 +0000963 sb_bp = target_sp->CreateFuncRegexBreakpoint(
Kate Stoneb9c1b512016-09-06 20:57:50 +0000964 module_list.get(), comp_unit_list.get(), regexp, symbol_language,
965 skip_prologue, internal, hardware);
966 }
967
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000968 return LLDB_RECORD_RESULT(sb_bp);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000969}
970
971SBBreakpoint SBTarget::BreakpointCreateByAddress(addr_t address) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000972 LLDB_RECORD_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateByAddress,
973 (lldb::addr_t), address);
974
Kate Stoneb9c1b512016-09-06 20:57:50 +0000975 SBBreakpoint sb_bp;
976 TargetSP target_sp(GetSP());
977 if (target_sp) {
978 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
979 const bool hardware = false;
Pavel Labath6ac84032017-02-27 11:05:34 +0000980 sb_bp = target_sp->CreateBreakpoint(address, false, hardware);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000981 }
982
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000983 return LLDB_RECORD_RESULT(sb_bp);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000984}
985
986SBBreakpoint SBTarget::BreakpointCreateBySBAddress(SBAddress &sb_address) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000987 LLDB_RECORD_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateBySBAddress,
988 (lldb::SBAddress &), sb_address);
989
Kate Stoneb9c1b512016-09-06 20:57:50 +0000990 SBBreakpoint sb_bp;
991 TargetSP target_sp(GetSP());
992 if (!sb_address.IsValid()) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000993 return LLDB_RECORD_RESULT(sb_bp);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000994 }
995
996 if (target_sp) {
997 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
998 const bool hardware = false;
Pavel Labath6ac84032017-02-27 11:05:34 +0000999 sb_bp = target_sp->CreateBreakpoint(sb_address.ref(), false, hardware);
Kate Stoneb9c1b512016-09-06 20:57:50 +00001000 }
1001
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001002 return LLDB_RECORD_RESULT(sb_bp);
Kate Stoneb9c1b512016-09-06 20:57:50 +00001003}
1004
1005lldb::SBBreakpoint
1006SBTarget::BreakpointCreateBySourceRegex(const char *source_regex,
1007 const lldb::SBFileSpec &source_file,
1008 const char *module_name) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001009 LLDB_RECORD_METHOD(lldb::SBBreakpoint, SBTarget,
1010 BreakpointCreateBySourceRegex,
1011 (const char *, const lldb::SBFileSpec &, const char *),
1012 source_regex, source_file, module_name);
1013
Kate Stoneb9c1b512016-09-06 20:57:50 +00001014 SBFileSpecList module_spec_list;
1015
1016 if (module_name && module_name[0]) {
Jonas Devlieghere8f3be7a2018-11-01 21:05:36 +00001017 module_spec_list.Append(FileSpec(module_name));
Kate Stoneb9c1b512016-09-06 20:57:50 +00001018 }
1019
1020 SBFileSpecList source_file_list;
1021 if (source_file.IsValid()) {
1022 source_file_list.Append(source_file);
1023 }
1024
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001025 return LLDB_RECORD_RESULT(BreakpointCreateBySourceRegex(
1026 source_regex, module_spec_list, source_file_list));
Kate Stoneb9c1b512016-09-06 20:57:50 +00001027}
1028
1029lldb::SBBreakpoint SBTarget::BreakpointCreateBySourceRegex(
1030 const char *source_regex, const SBFileSpecList &module_list,
1031 const lldb::SBFileSpecList &source_file_list) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001032 LLDB_RECORD_METHOD(lldb::SBBreakpoint, SBTarget,
1033 BreakpointCreateBySourceRegex,
1034 (const char *, const lldb::SBFileSpecList &,
1035 const lldb::SBFileSpecList &),
1036 source_regex, module_list, source_file_list);
1037
1038 return LLDB_RECORD_RESULT(BreakpointCreateBySourceRegex(
1039 source_regex, module_list, source_file_list, SBStringList()));
Kate Stoneb9c1b512016-09-06 20:57:50 +00001040}
1041
1042lldb::SBBreakpoint SBTarget::BreakpointCreateBySourceRegex(
1043 const char *source_regex, const SBFileSpecList &module_list,
1044 const lldb::SBFileSpecList &source_file_list,
1045 const SBStringList &func_names) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001046 LLDB_RECORD_METHOD(lldb::SBBreakpoint, SBTarget,
1047 BreakpointCreateBySourceRegex,
1048 (const char *, const lldb::SBFileSpecList &,
1049 const lldb::SBFileSpecList &, const lldb::SBStringList &),
1050 source_regex, module_list, source_file_list, func_names);
1051
Kate Stoneb9c1b512016-09-06 20:57:50 +00001052 SBBreakpoint sb_bp;
1053 TargetSP target_sp(GetSP());
1054 if (target_sp && source_regex && source_regex[0]) {
1055 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1056 const bool hardware = false;
1057 const LazyBool move_to_nearest_code = eLazyBoolCalculate;
Zachary Turner95eae422016-09-21 16:01:28 +00001058 RegularExpression regexp((llvm::StringRef(source_regex)));
Kate Stoneb9c1b512016-09-06 20:57:50 +00001059 std::unordered_set<std::string> func_names_set;
1060 for (size_t i = 0; i < func_names.GetSize(); i++) {
1061 func_names_set.insert(func_names.GetStringAtIndex(i));
1062 }
1063
Pavel Labath6ac84032017-02-27 11:05:34 +00001064 sb_bp = target_sp->CreateSourceRegexBreakpoint(
Kate Stoneb9c1b512016-09-06 20:57:50 +00001065 module_list.get(), source_file_list.get(), func_names_set, regexp,
1066 false, hardware, move_to_nearest_code);
1067 }
1068
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001069 return LLDB_RECORD_RESULT(sb_bp);
Kate Stoneb9c1b512016-09-06 20:57:50 +00001070}
1071
1072lldb::SBBreakpoint
1073SBTarget::BreakpointCreateForException(lldb::LanguageType language,
1074 bool catch_bp, bool throw_bp) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001075 LLDB_RECORD_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateForException,
1076 (lldb::LanguageType, bool, bool), language, catch_bp,
1077 throw_bp);
1078
Kate Stoneb9c1b512016-09-06 20:57:50 +00001079 SBBreakpoint sb_bp;
1080 TargetSP target_sp(GetSP());
1081 if (target_sp) {
1082 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1083 const bool hardware = false;
Pavel Labath6ac84032017-02-27 11:05:34 +00001084 sb_bp = target_sp->CreateExceptionBreakpoint(language, catch_bp, throw_bp,
Kate Stoneb9c1b512016-09-06 20:57:50 +00001085 hardware);
1086 }
1087
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001088 return LLDB_RECORD_RESULT(sb_bp);
Kate Stoneb9c1b512016-09-06 20:57:50 +00001089}
1090
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001091lldb::SBBreakpoint SBTarget::BreakpointCreateFromScript(
1092 const char *class_name, SBStructuredData &extra_args,
1093 const SBFileSpecList &module_list, const SBFileSpecList &file_list,
1094 bool request_hardware) {
1095 LLDB_RECORD_METHOD(
1096 lldb::SBBreakpoint, SBTarget, BreakpointCreateFromScript,
1097 (const char *, lldb::SBStructuredData &, const lldb::SBFileSpecList &,
1098 const lldb::SBFileSpecList &, bool),
1099 class_name, extra_args, module_list, file_list, request_hardware);
1100
Jim Ingham3815e702018-09-13 21:35:32 +00001101 SBBreakpoint sb_bp;
1102 TargetSP target_sp(GetSP());
1103 if (target_sp) {
1104 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1105 Status error;
Jonas Devlieghere581af8b2019-03-07 22:47:13 +00001106
Jim Ingham3815e702018-09-13 21:35:32 +00001107 StructuredData::ObjectSP obj_sp = extra_args.m_impl_up->GetObjectSP();
1108 sb_bp =
1109 target_sp->CreateScriptedBreakpoint(class_name,
1110 module_list.get(),
1111 file_list.get(),
1112 false, /* internal */
1113 request_hardware,
1114 obj_sp,
1115 &error);
1116 }
Jim Ingham3815e702018-09-13 21:35:32 +00001117
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001118 return LLDB_RECORD_RESULT(sb_bp);
Jim Ingham3815e702018-09-13 21:35:32 +00001119}
1120
Kate Stoneb9c1b512016-09-06 20:57:50 +00001121uint32_t SBTarget::GetNumBreakpoints() const {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001122 LLDB_RECORD_METHOD_CONST_NO_ARGS(uint32_t, SBTarget, GetNumBreakpoints);
1123
Kate Stoneb9c1b512016-09-06 20:57:50 +00001124 TargetSP target_sp(GetSP());
1125 if (target_sp) {
1126 // The breakpoint list is thread safe, no need to lock
1127 return target_sp->GetBreakpointList().GetSize();
1128 }
1129 return 0;
1130}
1131
1132SBBreakpoint SBTarget::GetBreakpointAtIndex(uint32_t idx) const {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001133 LLDB_RECORD_METHOD_CONST(lldb::SBBreakpoint, SBTarget, GetBreakpointAtIndex,
1134 (uint32_t), idx);
1135
Kate Stoneb9c1b512016-09-06 20:57:50 +00001136 SBBreakpoint sb_breakpoint;
1137 TargetSP target_sp(GetSP());
1138 if (target_sp) {
1139 // The breakpoint list is thread safe, no need to lock
Pavel Labath6ac84032017-02-27 11:05:34 +00001140 sb_breakpoint = target_sp->GetBreakpointList().GetBreakpointAtIndex(idx);
Kate Stoneb9c1b512016-09-06 20:57:50 +00001141 }
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001142 return LLDB_RECORD_RESULT(sb_breakpoint);
Kate Stoneb9c1b512016-09-06 20:57:50 +00001143}
1144
1145bool SBTarget::BreakpointDelete(break_id_t bp_id) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001146 LLDB_RECORD_METHOD(bool, SBTarget, BreakpointDelete, (lldb::break_id_t),
1147 bp_id);
1148
Kate Stoneb9c1b512016-09-06 20:57:50 +00001149 bool result = false;
1150 TargetSP target_sp(GetSP());
1151 if (target_sp) {
1152 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1153 result = target_sp->RemoveBreakpointByID(bp_id);
1154 }
1155
Kate Stoneb9c1b512016-09-06 20:57:50 +00001156 return result;
1157}
1158
1159SBBreakpoint SBTarget::FindBreakpointByID(break_id_t bp_id) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001160 LLDB_RECORD_METHOD(lldb::SBBreakpoint, SBTarget, FindBreakpointByID,
1161 (lldb::break_id_t), bp_id);
1162
Kate Stoneb9c1b512016-09-06 20:57:50 +00001163 SBBreakpoint sb_breakpoint;
1164 TargetSP target_sp(GetSP());
1165 if (target_sp && bp_id != LLDB_INVALID_BREAK_ID) {
1166 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
Pavel Labath6ac84032017-02-27 11:05:34 +00001167 sb_breakpoint = target_sp->GetBreakpointByID(bp_id);
Kate Stoneb9c1b512016-09-06 20:57:50 +00001168 }
1169
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001170 return LLDB_RECORD_RESULT(sb_breakpoint);
Kate Stoneb9c1b512016-09-06 20:57:50 +00001171}
1172
Jim Inghamff9a91e2016-09-21 01:21:19 +00001173bool SBTarget::FindBreakpointsByName(const char *name,
1174 SBBreakpointList &bkpts) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001175 LLDB_RECORD_METHOD(bool, SBTarget, FindBreakpointsByName,
1176 (const char *, lldb::SBBreakpointList &), name, bkpts);
1177
Jim Inghamff9a91e2016-09-21 01:21:19 +00001178 TargetSP target_sp(GetSP());
1179 if (target_sp) {
1180 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1181 BreakpointList bkpt_list(false);
1182 bool is_valid =
1183 target_sp->GetBreakpointList().FindBreakpointsByName(name, bkpt_list);
1184 if (!is_valid)
1185 return false;
1186 for (BreakpointSP bkpt_sp : bkpt_list.Breakpoints()) {
1187 bkpts.AppendByID(bkpt_sp->GetID());
1188 }
1189 }
1190 return true;
1191}
1192
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001193void SBTarget::GetBreakpointNames(SBStringList &names) {
1194 LLDB_RECORD_METHOD(void, SBTarget, GetBreakpointNames, (lldb::SBStringList &),
1195 names);
1196
Jim Inghamb842f2e2017-09-14 20:22:49 +00001197 names.Clear();
1198
1199 TargetSP target_sp(GetSP());
1200 if (target_sp) {
1201 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1202
1203 std::vector<std::string> name_vec;
1204 target_sp->GetBreakpointNames(name_vec);
1205 for (auto name : name_vec)
1206 names.AppendString(name.c_str());
1207 }
1208}
1209
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001210void SBTarget::DeleteBreakpointName(const char *name) {
1211 LLDB_RECORD_METHOD(void, SBTarget, DeleteBreakpointName, (const char *),
1212 name);
1213
Jim Inghamb842f2e2017-09-14 20:22:49 +00001214 TargetSP target_sp(GetSP());
1215 if (target_sp) {
1216 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
Jim Inghamb842f2e2017-09-14 20:22:49 +00001217 target_sp->DeleteBreakpointName(ConstString(name));
Jim Inghamb842f2e2017-09-14 20:22:49 +00001218 }
1219}
1220
Kate Stoneb9c1b512016-09-06 20:57:50 +00001221bool SBTarget::EnableAllBreakpoints() {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001222 LLDB_RECORD_METHOD_NO_ARGS(bool, SBTarget, EnableAllBreakpoints);
1223
Kate Stoneb9c1b512016-09-06 20:57:50 +00001224 TargetSP target_sp(GetSP());
1225 if (target_sp) {
1226 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
Jim Inghamb842f2e2017-09-14 20:22:49 +00001227 target_sp->EnableAllowedBreakpoints();
Kate Stoneb9c1b512016-09-06 20:57:50 +00001228 return true;
1229 }
1230 return false;
1231}
1232
1233bool SBTarget::DisableAllBreakpoints() {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001234 LLDB_RECORD_METHOD_NO_ARGS(bool, SBTarget, DisableAllBreakpoints);
1235
Kate Stoneb9c1b512016-09-06 20:57:50 +00001236 TargetSP target_sp(GetSP());
1237 if (target_sp) {
1238 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
Jim Inghamb842f2e2017-09-14 20:22:49 +00001239 target_sp->DisableAllowedBreakpoints();
Kate Stoneb9c1b512016-09-06 20:57:50 +00001240 return true;
1241 }
1242 return false;
1243}
1244
1245bool SBTarget::DeleteAllBreakpoints() {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001246 LLDB_RECORD_METHOD_NO_ARGS(bool, SBTarget, DeleteAllBreakpoints);
1247
Kate Stoneb9c1b512016-09-06 20:57:50 +00001248 TargetSP target_sp(GetSP());
1249 if (target_sp) {
1250 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
Jim Inghamb842f2e2017-09-14 20:22:49 +00001251 target_sp->RemoveAllowedBreakpoints();
Kate Stoneb9c1b512016-09-06 20:57:50 +00001252 return true;
1253 }
1254 return false;
1255}
1256
Jim Ingham01f16662016-09-14 19:07:35 +00001257lldb::SBError SBTarget::BreakpointsCreateFromFile(SBFileSpec &source_file,
1258 SBBreakpointList &new_bps) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001259 LLDB_RECORD_METHOD(lldb::SBError, SBTarget, BreakpointsCreateFromFile,
1260 (lldb::SBFileSpec &, lldb::SBBreakpointList &),
1261 source_file, new_bps);
1262
Jim Ingham3acdf382016-09-22 22:20:28 +00001263 SBStringList empty_name_list;
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001264 return LLDB_RECORD_RESULT(
1265 BreakpointsCreateFromFile(source_file, empty_name_list, new_bps));
Jim Ingham3acdf382016-09-22 22:20:28 +00001266}
1267
1268lldb::SBError SBTarget::BreakpointsCreateFromFile(SBFileSpec &source_file,
1269 SBStringList &matching_names,
1270 SBBreakpointList &new_bps) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001271 LLDB_RECORD_METHOD(
1272 lldb::SBError, SBTarget, BreakpointsCreateFromFile,
1273 (lldb::SBFileSpec &, lldb::SBStringList &, lldb::SBBreakpointList &),
1274 source_file, matching_names, new_bps);
1275
Jim Ingham01f16662016-09-14 19:07:35 +00001276 SBError sberr;
1277 TargetSP target_sp(GetSP());
1278 if (!target_sp) {
1279 sberr.SetErrorString(
1280 "BreakpointCreateFromFile called with invalid target.");
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001281 return LLDB_RECORD_RESULT(sberr);
Jim Ingham01f16662016-09-14 19:07:35 +00001282 }
1283 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1284
1285 BreakpointIDList bp_ids;
Jim Ingham3acdf382016-09-22 22:20:28 +00001286
1287 std::vector<std::string> name_vector;
1288 size_t num_names = matching_names.GetSize();
1289 for (size_t i = 0; i < num_names; i++)
1290 name_vector.push_back(matching_names.GetStringAtIndex(i));
1291
1292 sberr.ref() = target_sp->CreateBreakpointsFromFile(source_file.ref(),
1293 name_vector, bp_ids);
Jim Ingham01f16662016-09-14 19:07:35 +00001294 if (sberr.Fail())
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001295 return LLDB_RECORD_RESULT(sberr);
Jim Ingham01f16662016-09-14 19:07:35 +00001296
1297 size_t num_bkpts = bp_ids.GetSize();
1298 for (size_t i = 0; i < num_bkpts; i++) {
1299 BreakpointID bp_id = bp_ids.GetBreakpointIDAtIndex(i);
1300 new_bps.AppendByID(bp_id.GetBreakpointID());
1301 }
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001302 return LLDB_RECORD_RESULT(sberr);
Jim Ingham01f16662016-09-14 19:07:35 +00001303}
1304
1305lldb::SBError SBTarget::BreakpointsWriteToFile(SBFileSpec &dest_file) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001306 LLDB_RECORD_METHOD(lldb::SBError, SBTarget, BreakpointsWriteToFile,
1307 (lldb::SBFileSpec &), dest_file);
1308
Jim Ingham01f16662016-09-14 19:07:35 +00001309 SBError sberr;
1310 TargetSP target_sp(GetSP());
1311 if (!target_sp) {
1312 sberr.SetErrorString("BreakpointWriteToFile called with invalid target.");
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001313 return LLDB_RECORD_RESULT(sberr);
Jim Ingham01f16662016-09-14 19:07:35 +00001314 }
1315 SBBreakpointList bkpt_list(*this);
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001316 return LLDB_RECORD_RESULT(BreakpointsWriteToFile(dest_file, bkpt_list));
Jim Ingham01f16662016-09-14 19:07:35 +00001317}
1318
1319lldb::SBError SBTarget::BreakpointsWriteToFile(SBFileSpec &dest_file,
Jim Ingham2d3628e2016-09-22 23:42:42 +00001320 SBBreakpointList &bkpt_list,
1321 bool append) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001322 LLDB_RECORD_METHOD(lldb::SBError, SBTarget, BreakpointsWriteToFile,
1323 (lldb::SBFileSpec &, lldb::SBBreakpointList &, bool),
1324 dest_file, bkpt_list, append);
1325
Jim Ingham01f16662016-09-14 19:07:35 +00001326 SBError sberr;
1327 TargetSP target_sp(GetSP());
1328 if (!target_sp) {
1329 sberr.SetErrorString("BreakpointWriteToFile called with invalid target.");
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001330 return LLDB_RECORD_RESULT(sberr);
Jim Ingham01f16662016-09-14 19:07:35 +00001331 }
1332
1333 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1334 BreakpointIDList bp_id_list;
1335 bkpt_list.CopyToBreakpointIDList(bp_id_list);
Jim Ingham2d3628e2016-09-22 23:42:42 +00001336 sberr.ref() = target_sp->SerializeBreakpointsToFile(dest_file.ref(),
1337 bp_id_list, append);
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001338 return LLDB_RECORD_RESULT(sberr);
Jim Ingham01f16662016-09-14 19:07:35 +00001339}
1340
Kate Stoneb9c1b512016-09-06 20:57:50 +00001341uint32_t SBTarget::GetNumWatchpoints() const {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001342 LLDB_RECORD_METHOD_CONST_NO_ARGS(uint32_t, SBTarget, GetNumWatchpoints);
1343
Kate Stoneb9c1b512016-09-06 20:57:50 +00001344 TargetSP target_sp(GetSP());
1345 if (target_sp) {
1346 // The watchpoint list is thread safe, no need to lock
1347 return target_sp->GetWatchpointList().GetSize();
1348 }
1349 return 0;
1350}
1351
1352SBWatchpoint SBTarget::GetWatchpointAtIndex(uint32_t idx) const {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001353 LLDB_RECORD_METHOD_CONST(lldb::SBWatchpoint, SBTarget, GetWatchpointAtIndex,
1354 (uint32_t), idx);
1355
Kate Stoneb9c1b512016-09-06 20:57:50 +00001356 SBWatchpoint sb_watchpoint;
1357 TargetSP target_sp(GetSP());
1358 if (target_sp) {
1359 // The watchpoint list is thread safe, no need to lock
1360 sb_watchpoint.SetSP(target_sp->GetWatchpointList().GetByIndex(idx));
1361 }
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001362 return LLDB_RECORD_RESULT(sb_watchpoint);
Kate Stoneb9c1b512016-09-06 20:57:50 +00001363}
1364
1365bool SBTarget::DeleteWatchpoint(watch_id_t wp_id) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001366 LLDB_RECORD_METHOD(bool, SBTarget, DeleteWatchpoint, (lldb::watch_id_t),
1367 wp_id);
1368
Kate Stoneb9c1b512016-09-06 20:57:50 +00001369
1370 bool result = false;
1371 TargetSP target_sp(GetSP());
1372 if (target_sp) {
1373 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1374 std::unique_lock<std::recursive_mutex> lock;
1375 target_sp->GetWatchpointList().GetListMutex(lock);
1376 result = target_sp->RemoveWatchpointByID(wp_id);
1377 }
1378
Kate Stoneb9c1b512016-09-06 20:57:50 +00001379 return result;
1380}
1381
1382SBWatchpoint SBTarget::FindWatchpointByID(lldb::watch_id_t wp_id) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001383 LLDB_RECORD_METHOD(lldb::SBWatchpoint, SBTarget, FindWatchpointByID,
1384 (lldb::watch_id_t), wp_id);
1385
Kate Stoneb9c1b512016-09-06 20:57:50 +00001386
1387 SBWatchpoint sb_watchpoint;
1388 lldb::WatchpointSP watchpoint_sp;
1389 TargetSP target_sp(GetSP());
1390 if (target_sp && wp_id != LLDB_INVALID_WATCH_ID) {
1391 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1392 std::unique_lock<std::recursive_mutex> lock;
1393 target_sp->GetWatchpointList().GetListMutex(lock);
1394 watchpoint_sp = target_sp->GetWatchpointList().FindByID(wp_id);
1395 sb_watchpoint.SetSP(watchpoint_sp);
1396 }
1397
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001398 return LLDB_RECORD_RESULT(sb_watchpoint);
Kate Stoneb9c1b512016-09-06 20:57:50 +00001399}
1400
1401lldb::SBWatchpoint SBTarget::WatchAddress(lldb::addr_t addr, size_t size,
1402 bool read, bool write,
1403 SBError &error) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001404 LLDB_RECORD_METHOD(lldb::SBWatchpoint, SBTarget, WatchAddress,
1405 (lldb::addr_t, size_t, bool, bool, lldb::SBError &), addr,
1406 size, read, write, error);
1407
Kate Stoneb9c1b512016-09-06 20:57:50 +00001408 SBWatchpoint sb_watchpoint;
1409 lldb::WatchpointSP watchpoint_sp;
1410 TargetSP target_sp(GetSP());
1411 if (target_sp && (read || write) && addr != LLDB_INVALID_ADDRESS &&
1412 size > 0) {
1413 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1414 uint32_t watch_type = 0;
1415 if (read)
1416 watch_type |= LLDB_WATCH_TYPE_READ;
1417 if (write)
1418 watch_type |= LLDB_WATCH_TYPE_WRITE;
1419 if (watch_type == 0) {
1420 error.SetErrorString(
1421 "Can't create a watchpoint that is neither read nor write.");
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001422 return LLDB_RECORD_RESULT(sb_watchpoint);
Kate Stoneb9c1b512016-09-06 20:57:50 +00001423 }
1424
1425 // Target::CreateWatchpoint() is thread safe.
Zachary Turner97206d52017-05-12 04:51:55 +00001426 Status cw_error;
Kate Stoneb9c1b512016-09-06 20:57:50 +00001427 // This API doesn't take in a type, so we can't figure out what it is.
Konrad Kleine248a1302019-05-23 11:14:47 +00001428 CompilerType *type = nullptr;
Kate Stoneb9c1b512016-09-06 20:57:50 +00001429 watchpoint_sp =
1430 target_sp->CreateWatchpoint(addr, size, type, watch_type, cw_error);
1431 error.SetError(cw_error);
1432 sb_watchpoint.SetSP(watchpoint_sp);
1433 }
1434
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001435 return LLDB_RECORD_RESULT(sb_watchpoint);
Kate Stoneb9c1b512016-09-06 20:57:50 +00001436}
1437
1438bool SBTarget::EnableAllWatchpoints() {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001439 LLDB_RECORD_METHOD_NO_ARGS(bool, SBTarget, EnableAllWatchpoints);
1440
Kate Stoneb9c1b512016-09-06 20:57:50 +00001441 TargetSP target_sp(GetSP());
1442 if (target_sp) {
1443 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1444 std::unique_lock<std::recursive_mutex> lock;
1445 target_sp->GetWatchpointList().GetListMutex(lock);
1446 target_sp->EnableAllWatchpoints();
1447 return true;
1448 }
1449 return false;
1450}
1451
1452bool SBTarget::DisableAllWatchpoints() {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001453 LLDB_RECORD_METHOD_NO_ARGS(bool, SBTarget, DisableAllWatchpoints);
1454
Kate Stoneb9c1b512016-09-06 20:57:50 +00001455 TargetSP target_sp(GetSP());
1456 if (target_sp) {
1457 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1458 std::unique_lock<std::recursive_mutex> lock;
1459 target_sp->GetWatchpointList().GetListMutex(lock);
1460 target_sp->DisableAllWatchpoints();
1461 return true;
1462 }
1463 return false;
1464}
1465
1466SBValue SBTarget::CreateValueFromAddress(const char *name, SBAddress addr,
1467 SBType type) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001468 LLDB_RECORD_METHOD(lldb::SBValue, SBTarget, CreateValueFromAddress,
1469 (const char *, lldb::SBAddress, lldb::SBType), name, addr,
1470 type);
1471
Kate Stoneb9c1b512016-09-06 20:57:50 +00001472 SBValue sb_value;
1473 lldb::ValueObjectSP new_value_sp;
1474 if (IsValid() && name && *name && addr.IsValid() && type.IsValid()) {
1475 lldb::addr_t load_addr(addr.GetLoadAddress(*this));
1476 ExecutionContext exe_ctx(
1477 ExecutionContextRef(ExecutionContext(m_opaque_sp.get(), false)));
1478 CompilerType ast_type(type.GetSP()->GetCompilerType(true));
1479 new_value_sp = ValueObject::CreateValueObjectFromAddress(name, load_addr,
1480 exe_ctx, ast_type);
1481 }
1482 sb_value.SetSP(new_value_sp);
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001483 return LLDB_RECORD_RESULT(sb_value);
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001484}
1485
Kate Stoneb9c1b512016-09-06 20:57:50 +00001486lldb::SBValue SBTarget::CreateValueFromData(const char *name, lldb::SBData data,
1487 lldb::SBType type) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001488 LLDB_RECORD_METHOD(lldb::SBValue, SBTarget, CreateValueFromData,
1489 (const char *, lldb::SBData, lldb::SBType), name, data,
1490 type);
1491
Kate Stoneb9c1b512016-09-06 20:57:50 +00001492 SBValue sb_value;
1493 lldb::ValueObjectSP new_value_sp;
1494 if (IsValid() && name && *name && data.IsValid() && type.IsValid()) {
1495 DataExtractorSP extractor(*data);
1496 ExecutionContext exe_ctx(
1497 ExecutionContextRef(ExecutionContext(m_opaque_sp.get(), false)));
1498 CompilerType ast_type(type.GetSP()->GetCompilerType(true));
1499 new_value_sp = ValueObject::CreateValueObjectFromData(name, *extractor,
1500 exe_ctx, ast_type);
1501 }
1502 sb_value.SetSP(new_value_sp);
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001503 return LLDB_RECORD_RESULT(sb_value);
Greg Claytone14e1922012-12-04 02:22:16 +00001504}
1505
Kate Stoneb9c1b512016-09-06 20:57:50 +00001506lldb::SBValue SBTarget::CreateValueFromExpression(const char *name,
1507 const char *expr) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001508 LLDB_RECORD_METHOD(lldb::SBValue, SBTarget, CreateValueFromExpression,
1509 (const char *, const char *), name, expr);
1510
Kate Stoneb9c1b512016-09-06 20:57:50 +00001511 SBValue sb_value;
1512 lldb::ValueObjectSP new_value_sp;
1513 if (IsValid() && name && *name && expr && *expr) {
1514 ExecutionContext exe_ctx(
1515 ExecutionContextRef(ExecutionContext(m_opaque_sp.get(), false)));
1516 new_value_sp =
1517 ValueObject::CreateValueObjectFromExpression(name, expr, exe_ctx);
1518 }
1519 sb_value.SetSP(new_value_sp);
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001520 return LLDB_RECORD_RESULT(sb_value);
Kate Stoneb9c1b512016-09-06 20:57:50 +00001521}
1522
1523bool SBTarget::DeleteAllWatchpoints() {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001524 LLDB_RECORD_METHOD_NO_ARGS(bool, SBTarget, DeleteAllWatchpoints);
1525
Kate Stoneb9c1b512016-09-06 20:57:50 +00001526 TargetSP target_sp(GetSP());
1527 if (target_sp) {
1528 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1529 std::unique_lock<std::recursive_mutex> lock;
1530 target_sp->GetWatchpointList().GetListMutex(lock);
1531 target_sp->RemoveAllWatchpoints();
1532 return true;
1533 }
1534 return false;
1535}
1536
Alexander Polyakov3e7b9db2018-08-07 20:23:57 +00001537void SBTarget::AppendImageSearchPath(const char *from, const char *to,
1538 lldb::SBError &error) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001539 LLDB_RECORD_METHOD(void, SBTarget, AppendImageSearchPath,
1540 (const char *, const char *, lldb::SBError &), from, to,
1541 error);
1542
Alexander Polyakov3e7b9db2018-08-07 20:23:57 +00001543 TargetSP target_sp(GetSP());
1544 if (!target_sp)
1545 return error.SetErrorString("invalid target");
1546
1547 const ConstString csFrom(from), csTo(to);
1548 if (!csFrom)
1549 return error.SetErrorString("<from> path can't be empty");
1550 if (!csTo)
1551 return error.SetErrorString("<to> path can't be empty");
1552
Alexander Polyakov3e7b9db2018-08-07 20:23:57 +00001553 target_sp->GetImageSearchPathList().Append(csFrom, csTo, true);
1554}
1555
Kate Stoneb9c1b512016-09-06 20:57:50 +00001556lldb::SBModule SBTarget::AddModule(const char *path, const char *triple,
1557 const char *uuid_cstr) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001558 LLDB_RECORD_METHOD(lldb::SBModule, SBTarget, AddModule,
1559 (const char *, const char *, const char *), path, triple,
1560 uuid_cstr);
1561
Konrad Kleine248a1302019-05-23 11:14:47 +00001562 return LLDB_RECORD_RESULT(AddModule(path, triple, uuid_cstr, nullptr));
Kate Stoneb9c1b512016-09-06 20:57:50 +00001563}
1564
1565lldb::SBModule SBTarget::AddModule(const char *path, const char *triple,
1566 const char *uuid_cstr, const char *symfile) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001567 LLDB_RECORD_METHOD(lldb::SBModule, SBTarget, AddModule,
1568 (const char *, const char *, const char *, const char *),
1569 path, triple, uuid_cstr, symfile);
1570
Kate Stoneb9c1b512016-09-06 20:57:50 +00001571 lldb::SBModule sb_module;
1572 TargetSP target_sp(GetSP());
1573 if (target_sp) {
1574 ModuleSpec module_spec;
1575 if (path)
Jonas Devlieghere8f3be7a2018-11-01 21:05:36 +00001576 module_spec.GetFileSpec().SetFile(path, FileSpec::Style::native);
Kate Stoneb9c1b512016-09-06 20:57:50 +00001577
1578 if (uuid_cstr)
Pavel Labatha174bcb2018-06-21 15:24:39 +00001579 module_spec.GetUUID().SetFromStringRef(uuid_cstr);
Kate Stoneb9c1b512016-09-06 20:57:50 +00001580
1581 if (triple)
Pavel Labath7263f1b2017-10-31 10:56:03 +00001582 module_spec.GetArchitecture() = Platform::GetAugmentedArchSpec(
1583 target_sp->GetPlatform().get(), triple);
Kate Stoneb9c1b512016-09-06 20:57:50 +00001584 else
1585 module_spec.GetArchitecture() = target_sp->GetArchitecture();
1586
1587 if (symfile)
Jonas Devlieghere8f3be7a2018-11-01 21:05:36 +00001588 module_spec.GetSymbolFileSpec().SetFile(symfile, FileSpec::Style::native);
Kate Stoneb9c1b512016-09-06 20:57:50 +00001589
Jason Molenda1724a172019-04-08 23:03:02 +00001590 sb_module.SetSP(target_sp->GetOrCreateModule(module_spec, true /* notify */));
Kate Stoneb9c1b512016-09-06 20:57:50 +00001591 }
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001592 return LLDB_RECORD_RESULT(sb_module);
Kate Stoneb9c1b512016-09-06 20:57:50 +00001593}
1594
1595lldb::SBModule SBTarget::AddModule(const SBModuleSpec &module_spec) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001596 LLDB_RECORD_METHOD(lldb::SBModule, SBTarget, AddModule,
1597 (const lldb::SBModuleSpec &), module_spec);
1598
Kate Stoneb9c1b512016-09-06 20:57:50 +00001599 lldb::SBModule sb_module;
1600 TargetSP target_sp(GetSP());
1601 if (target_sp)
Jason Molenda1724a172019-04-08 23:03:02 +00001602 sb_module.SetSP(target_sp->GetOrCreateModule(*module_spec.m_opaque_up,
1603 true /* notify */));
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001604 return LLDB_RECORD_RESULT(sb_module);
Kate Stoneb9c1b512016-09-06 20:57:50 +00001605}
1606
1607bool SBTarget::AddModule(lldb::SBModule &module) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001608 LLDB_RECORD_METHOD(bool, SBTarget, AddModule, (lldb::SBModule &), module);
1609
Kate Stoneb9c1b512016-09-06 20:57:50 +00001610 TargetSP target_sp(GetSP());
1611 if (target_sp) {
1612 target_sp->GetImages().AppendIfNeeded(module.GetSP());
1613 return true;
1614 }
1615 return false;
1616}
1617
1618uint32_t SBTarget::GetNumModules() const {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001619 LLDB_RECORD_METHOD_CONST_NO_ARGS(uint32_t, SBTarget, GetNumModules);
1620
Kate Stoneb9c1b512016-09-06 20:57:50 +00001621 uint32_t num = 0;
1622 TargetSP target_sp(GetSP());
1623 if (target_sp) {
1624 // The module list is thread safe, no need to lock
1625 num = target_sp->GetImages().GetSize();
1626 }
1627
Kate Stoneb9c1b512016-09-06 20:57:50 +00001628 return num;
1629}
1630
1631void SBTarget::Clear() {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001632 LLDB_RECORD_METHOD_NO_ARGS(void, SBTarget, Clear);
1633
Kate Stoneb9c1b512016-09-06 20:57:50 +00001634 m_opaque_sp.reset();
1635}
1636
1637SBModule SBTarget::FindModule(const SBFileSpec &sb_file_spec) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001638 LLDB_RECORD_METHOD(lldb::SBModule, SBTarget, FindModule,
1639 (const lldb::SBFileSpec &), sb_file_spec);
1640
Kate Stoneb9c1b512016-09-06 20:57:50 +00001641 SBModule sb_module;
1642 TargetSP target_sp(GetSP());
1643 if (target_sp && sb_file_spec.IsValid()) {
1644 ModuleSpec module_spec(*sb_file_spec);
1645 // The module list is thread safe, no need to lock
1646 sb_module.SetSP(target_sp->GetImages().FindFirstModule(module_spec));
1647 }
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001648 return LLDB_RECORD_RESULT(sb_module);
Kate Stoneb9c1b512016-09-06 20:57:50 +00001649}
1650
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001651SBSymbolContextList SBTarget::FindCompileUnits(const SBFileSpec &sb_file_spec) {
1652 LLDB_RECORD_METHOD(lldb::SBSymbolContextList, SBTarget, FindCompileUnits,
1653 (const lldb::SBFileSpec &), sb_file_spec);
1654
Alexander Polyakovda0c0812018-07-03 14:22:44 +00001655 SBSymbolContextList sb_sc_list;
1656 const TargetSP target_sp(GetSP());
1657 if (target_sp && sb_file_spec.IsValid()) {
1658 const bool append = true;
1659 target_sp->GetImages().FindCompileUnits(*sb_file_spec,
1660 append, *sb_sc_list);
1661 }
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001662 return LLDB_RECORD_RESULT(sb_sc_list);
Alexander Polyakovda0c0812018-07-03 14:22:44 +00001663}
1664
Kate Stoneb9c1b512016-09-06 20:57:50 +00001665lldb::ByteOrder SBTarget::GetByteOrder() {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001666 LLDB_RECORD_METHOD_NO_ARGS(lldb::ByteOrder, SBTarget, GetByteOrder);
1667
Kate Stoneb9c1b512016-09-06 20:57:50 +00001668 TargetSP target_sp(GetSP());
1669 if (target_sp)
1670 return target_sp->GetArchitecture().GetByteOrder();
1671 return eByteOrderInvalid;
1672}
1673
1674const char *SBTarget::GetTriple() {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001675 LLDB_RECORD_METHOD_NO_ARGS(const char *, SBTarget, GetTriple);
1676
Kate Stoneb9c1b512016-09-06 20:57:50 +00001677 TargetSP target_sp(GetSP());
1678 if (target_sp) {
1679 std::string triple(target_sp->GetArchitecture().GetTriple().str());
Adrian Prantl05097242018-04-30 16:49:04 +00001680 // Unique the string so we don't run into ownership issues since the const
1681 // strings put the string into the string pool once and the strings never
1682 // comes out
Kate Stoneb9c1b512016-09-06 20:57:50 +00001683 ConstString const_triple(triple.c_str());
1684 return const_triple.GetCString();
1685 }
Konrad Kleine248a1302019-05-23 11:14:47 +00001686 return nullptr;
Kate Stoneb9c1b512016-09-06 20:57:50 +00001687}
1688
1689uint32_t SBTarget::GetDataByteSize() {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001690 LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBTarget, GetDataByteSize);
1691
Kate Stoneb9c1b512016-09-06 20:57:50 +00001692 TargetSP target_sp(GetSP());
1693 if (target_sp) {
1694 return target_sp->GetArchitecture().GetDataByteSize();
1695 }
1696 return 0;
1697}
1698
1699uint32_t SBTarget::GetCodeByteSize() {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001700 LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBTarget, GetCodeByteSize);
1701
Kate Stoneb9c1b512016-09-06 20:57:50 +00001702 TargetSP target_sp(GetSP());
1703 if (target_sp) {
1704 return target_sp->GetArchitecture().GetCodeByteSize();
1705 }
1706 return 0;
1707}
1708
1709uint32_t SBTarget::GetAddressByteSize() {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001710 LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBTarget, GetAddressByteSize);
1711
Kate Stoneb9c1b512016-09-06 20:57:50 +00001712 TargetSP target_sp(GetSP());
1713 if (target_sp)
1714 return target_sp->GetArchitecture().GetAddressByteSize();
1715 return sizeof(void *);
1716}
1717
1718SBModule SBTarget::GetModuleAtIndex(uint32_t idx) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001719 LLDB_RECORD_METHOD(lldb::SBModule, SBTarget, GetModuleAtIndex, (uint32_t),
1720 idx);
1721
Kate Stoneb9c1b512016-09-06 20:57:50 +00001722 SBModule sb_module;
1723 ModuleSP module_sp;
1724 TargetSP target_sp(GetSP());
1725 if (target_sp) {
1726 // The module list is thread safe, no need to lock
1727 module_sp = target_sp->GetImages().GetModuleAtIndex(idx);
1728 sb_module.SetSP(module_sp);
1729 }
1730
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001731 return LLDB_RECORD_RESULT(sb_module);
Kate Stoneb9c1b512016-09-06 20:57:50 +00001732}
1733
1734bool SBTarget::RemoveModule(lldb::SBModule module) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001735 LLDB_RECORD_METHOD(bool, SBTarget, RemoveModule, (lldb::SBModule), module);
1736
Kate Stoneb9c1b512016-09-06 20:57:50 +00001737 TargetSP target_sp(GetSP());
1738 if (target_sp)
1739 return target_sp->GetImages().Remove(module.GetSP());
1740 return false;
1741}
1742
1743SBBroadcaster SBTarget::GetBroadcaster() const {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001744 LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::SBBroadcaster, SBTarget,
1745 GetBroadcaster);
1746
Kate Stoneb9c1b512016-09-06 20:57:50 +00001747
1748 TargetSP target_sp(GetSP());
1749 SBBroadcaster broadcaster(target_sp.get(), false);
1750
Kate Stoneb9c1b512016-09-06 20:57:50 +00001751
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001752 return LLDB_RECORD_RESULT(broadcaster);
Kate Stoneb9c1b512016-09-06 20:57:50 +00001753}
1754
1755bool SBTarget::GetDescription(SBStream &description,
1756 lldb::DescriptionLevel description_level) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001757 LLDB_RECORD_METHOD(bool, SBTarget, GetDescription,
1758 (lldb::SBStream &, lldb::DescriptionLevel), description,
1759 description_level);
1760
Kate Stoneb9c1b512016-09-06 20:57:50 +00001761 Stream &strm = description.ref();
1762
1763 TargetSP target_sp(GetSP());
1764 if (target_sp) {
1765 target_sp->Dump(&strm, description_level);
1766 } else
1767 strm.PutCString("No value");
1768
1769 return true;
1770}
1771
1772lldb::SBSymbolContextList SBTarget::FindFunctions(const char *name,
1773 uint32_t name_type_mask) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001774 LLDB_RECORD_METHOD(lldb::SBSymbolContextList, SBTarget, FindFunctions,
1775 (const char *, uint32_t), name, name_type_mask);
1776
Kate Stoneb9c1b512016-09-06 20:57:50 +00001777 lldb::SBSymbolContextList sb_sc_list;
Zachary Turner117b1fa2018-10-25 20:45:40 +00001778 if (!name | !name[0])
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001779 return LLDB_RECORD_RESULT(sb_sc_list);
Zachary Turner117b1fa2018-10-25 20:45:40 +00001780
1781 TargetSP target_sp(GetSP());
1782 if (!target_sp)
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001783 return LLDB_RECORD_RESULT(sb_sc_list);
Zachary Turner117b1fa2018-10-25 20:45:40 +00001784
1785 const bool symbols_ok = true;
1786 const bool inlines_ok = true;
1787 const bool append = true;
1788 FunctionNameType mask = static_cast<FunctionNameType>(name_type_mask);
1789 target_sp->GetImages().FindFunctions(ConstString(name), mask, symbols_ok,
1790 inlines_ok, append, *sb_sc_list);
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001791 return LLDB_RECORD_RESULT(sb_sc_list);
Jim Ingham763b2b22015-07-07 22:12:17 +00001792}
Greg Claytone14e1922012-12-04 02:22:16 +00001793
Kate Stoneb9c1b512016-09-06 20:57:50 +00001794lldb::SBSymbolContextList SBTarget::FindGlobalFunctions(const char *name,
1795 uint32_t max_matches,
1796 MatchType matchtype) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001797 LLDB_RECORD_METHOD(lldb::SBSymbolContextList, SBTarget, FindGlobalFunctions,
1798 (const char *, uint32_t, lldb::MatchType), name,
1799 max_matches, matchtype);
1800
Kate Stoneb9c1b512016-09-06 20:57:50 +00001801 lldb::SBSymbolContextList sb_sc_list;
1802 if (name && name[0]) {
Zachary Turner95eae422016-09-21 16:01:28 +00001803 llvm::StringRef name_ref(name);
Kate Stoneb9c1b512016-09-06 20:57:50 +00001804 TargetSP target_sp(GetSP());
1805 if (target_sp) {
1806 std::string regexstr;
1807 switch (matchtype) {
1808 case eMatchTypeRegex:
Zachary Turner95eae422016-09-21 16:01:28 +00001809 target_sp->GetImages().FindFunctions(RegularExpression(name_ref), true,
Kate Stoneb9c1b512016-09-06 20:57:50 +00001810 true, true, *sb_sc_list);
1811 break;
1812 case eMatchTypeStartsWith:
1813 regexstr = llvm::Regex::escape(name) + ".*";
Zachary Turner95eae422016-09-21 16:01:28 +00001814 target_sp->GetImages().FindFunctions(RegularExpression(regexstr), true,
1815 true, true, *sb_sc_list);
Kate Stoneb9c1b512016-09-06 20:57:50 +00001816 break;
1817 default:
1818 target_sp->GetImages().FindFunctions(ConstString(name),
1819 eFunctionNameTypeAny, true, true,
1820 true, *sb_sc_list);
1821 break;
1822 }
1823 }
1824 }
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001825 return LLDB_RECORD_RESULT(sb_sc_list);
Kate Stoneb9c1b512016-09-06 20:57:50 +00001826}
1827
1828lldb::SBType SBTarget::FindFirstType(const char *typename_cstr) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001829 LLDB_RECORD_METHOD(lldb::SBType, SBTarget, FindFirstType, (const char *),
1830 typename_cstr);
1831
Kate Stoneb9c1b512016-09-06 20:57:50 +00001832 TargetSP target_sp(GetSP());
1833 if (typename_cstr && typename_cstr[0] && target_sp) {
1834 ConstString const_typename(typename_cstr);
1835 SymbolContext sc;
1836 const bool exact_match = false;
1837
1838 const ModuleList &module_list = target_sp->GetImages();
1839 size_t count = module_list.GetSize();
1840 for (size_t idx = 0; idx < count; idx++) {
1841 ModuleSP module_sp(module_list.GetModuleAtIndex(idx));
1842 if (module_sp) {
1843 TypeSP type_sp(
1844 module_sp->FindFirstType(sc, const_typename, exact_match));
1845 if (type_sp)
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001846 return LLDB_RECORD_RESULT(SBType(type_sp));
Kate Stoneb9c1b512016-09-06 20:57:50 +00001847 }
1848 }
1849
Adrian Prantl05097242018-04-30 16:49:04 +00001850 // Didn't find the type in the symbols; try the Objective-C runtime if one
1851 // is installed
Kate Stoneb9c1b512016-09-06 20:57:50 +00001852
1853 ProcessSP process_sp(target_sp->GetProcessSP());
1854
1855 if (process_sp) {
1856 ObjCLanguageRuntime *objc_language_runtime =
Alex Langforde823bbe2019-06-10 20:53:23 +00001857 ObjCLanguageRuntime::Get(*process_sp);
Kate Stoneb9c1b512016-09-06 20:57:50 +00001858
1859 if (objc_language_runtime) {
1860 DeclVendor *objc_decl_vendor = objc_language_runtime->GetDeclVendor();
1861
1862 if (objc_decl_vendor) {
1863 std::vector<clang::NamedDecl *> decls;
1864
1865 if (objc_decl_vendor->FindDecls(const_typename, true, 1, decls) > 0) {
1866 if (CompilerType type = ClangASTContext::GetTypeForDecl(decls[0])) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001867 return LLDB_RECORD_RESULT(SBType(type));
Kate Stoneb9c1b512016-09-06 20:57:50 +00001868 }
1869 }
1870 }
1871 }
1872 }
1873
1874 // No matches, search for basic typename matches
1875 ClangASTContext *clang_ast = target_sp->GetScratchClangASTContext();
1876 if (clang_ast)
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001877 return LLDB_RECORD_RESULT(SBType(ClangASTContext::GetBasicType(
1878 clang_ast->getASTContext(), const_typename)));
Kate Stoneb9c1b512016-09-06 20:57:50 +00001879 }
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001880 return LLDB_RECORD_RESULT(SBType());
Kate Stoneb9c1b512016-09-06 20:57:50 +00001881}
1882
1883SBType SBTarget::GetBasicType(lldb::BasicType type) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001884 LLDB_RECORD_METHOD(lldb::SBType, SBTarget, GetBasicType, (lldb::BasicType),
1885 type);
1886
Kate Stoneb9c1b512016-09-06 20:57:50 +00001887 TargetSP target_sp(GetSP());
1888 if (target_sp) {
1889 ClangASTContext *clang_ast = target_sp->GetScratchClangASTContext();
1890 if (clang_ast)
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001891 return LLDB_RECORD_RESULT(SBType(
1892 ClangASTContext::GetBasicType(clang_ast->getASTContext(), type)));
Kate Stoneb9c1b512016-09-06 20:57:50 +00001893 }
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001894 return LLDB_RECORD_RESULT(SBType());
Kate Stoneb9c1b512016-09-06 20:57:50 +00001895}
1896
1897lldb::SBTypeList SBTarget::FindTypes(const char *typename_cstr) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001898 LLDB_RECORD_METHOD(lldb::SBTypeList, SBTarget, FindTypes, (const char *),
1899 typename_cstr);
1900
Kate Stoneb9c1b512016-09-06 20:57:50 +00001901 SBTypeList sb_type_list;
1902 TargetSP target_sp(GetSP());
1903 if (typename_cstr && typename_cstr[0] && target_sp) {
1904 ModuleList &images = target_sp->GetImages();
1905 ConstString const_typename(typename_cstr);
1906 bool exact_match = false;
Kate Stoneb9c1b512016-09-06 20:57:50 +00001907 TypeList type_list;
1908 llvm::DenseSet<SymbolFile *> searched_symbol_files;
1909 uint32_t num_matches =
Zachary Turner576495e2019-01-14 22:41:21 +00001910 images.FindTypes(nullptr, const_typename, exact_match, UINT32_MAX,
Kate Stoneb9c1b512016-09-06 20:57:50 +00001911 searched_symbol_files, type_list);
1912
1913 if (num_matches > 0) {
1914 for (size_t idx = 0; idx < num_matches; idx++) {
1915 TypeSP type_sp(type_list.GetTypeAtIndex(idx));
1916 if (type_sp)
1917 sb_type_list.Append(SBType(type_sp));
1918 }
1919 }
1920
1921 // Try the Objective-C runtime if one is installed
1922
1923 ProcessSP process_sp(target_sp->GetProcessSP());
1924
1925 if (process_sp) {
1926 ObjCLanguageRuntime *objc_language_runtime =
Alex Langforde823bbe2019-06-10 20:53:23 +00001927 ObjCLanguageRuntime::Get(*process_sp);
Kate Stoneb9c1b512016-09-06 20:57:50 +00001928
1929 if (objc_language_runtime) {
1930 DeclVendor *objc_decl_vendor = objc_language_runtime->GetDeclVendor();
1931
1932 if (objc_decl_vendor) {
1933 std::vector<clang::NamedDecl *> decls;
1934
1935 if (objc_decl_vendor->FindDecls(const_typename, true, 1, decls) > 0) {
1936 for (clang::NamedDecl *decl : decls) {
1937 if (CompilerType type = ClangASTContext::GetTypeForDecl(decl)) {
1938 sb_type_list.Append(SBType(type));
1939 }
1940 }
1941 }
1942 }
1943 }
1944 }
1945
1946 if (sb_type_list.GetSize() == 0) {
1947 // No matches, search for basic typename matches
1948 ClangASTContext *clang_ast = target_sp->GetScratchClangASTContext();
1949 if (clang_ast)
1950 sb_type_list.Append(SBType(ClangASTContext::GetBasicType(
1951 clang_ast->getASTContext(), const_typename)));
1952 }
1953 }
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001954 return LLDB_RECORD_RESULT(sb_type_list);
Kate Stoneb9c1b512016-09-06 20:57:50 +00001955}
1956
1957SBValueList SBTarget::FindGlobalVariables(const char *name,
1958 uint32_t max_matches) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001959 LLDB_RECORD_METHOD(lldb::SBValueList, SBTarget, FindGlobalVariables,
1960 (const char *, uint32_t), name, max_matches);
1961
Kate Stoneb9c1b512016-09-06 20:57:50 +00001962 SBValueList sb_value_list;
1963
1964 TargetSP target_sp(GetSP());
1965 if (name && target_sp) {
1966 VariableList variable_list;
Kate Stoneb9c1b512016-09-06 20:57:50 +00001967 const uint32_t match_count = target_sp->GetImages().FindGlobalVariables(
Pavel Labath34cda142018-05-31 09:46:26 +00001968 ConstString(name), max_matches, variable_list);
Kate Stoneb9c1b512016-09-06 20:57:50 +00001969
1970 if (match_count > 0) {
1971 ExecutionContextScope *exe_scope = target_sp->GetProcessSP().get();
Konrad Kleine248a1302019-05-23 11:14:47 +00001972 if (exe_scope == nullptr)
Kate Stoneb9c1b512016-09-06 20:57:50 +00001973 exe_scope = target_sp.get();
1974 for (uint32_t i = 0; i < match_count; ++i) {
1975 lldb::ValueObjectSP valobj_sp(ValueObjectVariable::Create(
1976 exe_scope, variable_list.GetVariableAtIndex(i)));
1977 if (valobj_sp)
1978 sb_value_list.Append(SBValue(valobj_sp));
1979 }
1980 }
1981 }
1982
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001983 return LLDB_RECORD_RESULT(sb_value_list);
Kate Stoneb9c1b512016-09-06 20:57:50 +00001984}
1985
1986SBValueList SBTarget::FindGlobalVariables(const char *name,
1987 uint32_t max_matches,
1988 MatchType matchtype) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001989 LLDB_RECORD_METHOD(lldb::SBValueList, SBTarget, FindGlobalVariables,
1990 (const char *, uint32_t, lldb::MatchType), name,
1991 max_matches, matchtype);
1992
Kate Stoneb9c1b512016-09-06 20:57:50 +00001993 SBValueList sb_value_list;
1994
1995 TargetSP target_sp(GetSP());
1996 if (name && target_sp) {
Zachary Turner95eae422016-09-21 16:01:28 +00001997 llvm::StringRef name_ref(name);
Kate Stoneb9c1b512016-09-06 20:57:50 +00001998 VariableList variable_list;
Kate Stoneb9c1b512016-09-06 20:57:50 +00001999
2000 std::string regexstr;
2001 uint32_t match_count;
2002 switch (matchtype) {
2003 case eMatchTypeNormal:
2004 match_count = target_sp->GetImages().FindGlobalVariables(
Pavel Labath34cda142018-05-31 09:46:26 +00002005 ConstString(name), max_matches, variable_list);
Kate Stoneb9c1b512016-09-06 20:57:50 +00002006 break;
2007 case eMatchTypeRegex:
2008 match_count = target_sp->GetImages().FindGlobalVariables(
Pavel Labath34cda142018-05-31 09:46:26 +00002009 RegularExpression(name_ref), max_matches, variable_list);
Kate Stoneb9c1b512016-09-06 20:57:50 +00002010 break;
2011 case eMatchTypeStartsWith:
2012 regexstr = llvm::Regex::escape(name) + ".*";
2013 match_count = target_sp->GetImages().FindGlobalVariables(
Pavel Labath34cda142018-05-31 09:46:26 +00002014 RegularExpression(regexstr), max_matches, variable_list);
Kate Stoneb9c1b512016-09-06 20:57:50 +00002015 break;
2016 }
2017
2018 if (match_count > 0) {
2019 ExecutionContextScope *exe_scope = target_sp->GetProcessSP().get();
Konrad Kleine248a1302019-05-23 11:14:47 +00002020 if (exe_scope == nullptr)
Kate Stoneb9c1b512016-09-06 20:57:50 +00002021 exe_scope = target_sp.get();
2022 for (uint32_t i = 0; i < match_count; ++i) {
2023 lldb::ValueObjectSP valobj_sp(ValueObjectVariable::Create(
2024 exe_scope, variable_list.GetVariableAtIndex(i)));
2025 if (valobj_sp)
2026 sb_value_list.Append(SBValue(valobj_sp));
2027 }
2028 }
2029 }
2030
Jonas Devliegherebaf56642019-03-06 00:06:00 +00002031 return LLDB_RECORD_RESULT(sb_value_list);
Kate Stoneb9c1b512016-09-06 20:57:50 +00002032}
2033
2034lldb::SBValue SBTarget::FindFirstGlobalVariable(const char *name) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00002035 LLDB_RECORD_METHOD(lldb::SBValue, SBTarget, FindFirstGlobalVariable,
2036 (const char *), name);
2037
Kate Stoneb9c1b512016-09-06 20:57:50 +00002038 SBValueList sb_value_list(FindGlobalVariables(name, 1));
2039 if (sb_value_list.IsValid() && sb_value_list.GetSize() > 0)
Jonas Devliegherebaf56642019-03-06 00:06:00 +00002040 return LLDB_RECORD_RESULT(sb_value_list.GetValueAtIndex(0));
2041 return LLDB_RECORD_RESULT(SBValue());
Kate Stoneb9c1b512016-09-06 20:57:50 +00002042}
2043
2044SBSourceManager SBTarget::GetSourceManager() {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00002045 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBSourceManager, SBTarget, GetSourceManager);
2046
Kate Stoneb9c1b512016-09-06 20:57:50 +00002047 SBSourceManager source_manager(*this);
Jonas Devliegherebaf56642019-03-06 00:06:00 +00002048 return LLDB_RECORD_RESULT(source_manager);
Kate Stoneb9c1b512016-09-06 20:57:50 +00002049}
2050
2051lldb::SBInstructionList SBTarget::ReadInstructions(lldb::SBAddress base_addr,
2052 uint32_t count) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00002053 LLDB_RECORD_METHOD(lldb::SBInstructionList, SBTarget, ReadInstructions,
2054 (lldb::SBAddress, uint32_t), base_addr, count);
2055
Konrad Kleine248a1302019-05-23 11:14:47 +00002056 return LLDB_RECORD_RESULT(ReadInstructions(base_addr, count, nullptr));
Kate Stoneb9c1b512016-09-06 20:57:50 +00002057}
2058
2059lldb::SBInstructionList SBTarget::ReadInstructions(lldb::SBAddress base_addr,
2060 uint32_t count,
2061 const char *flavor_string) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00002062 LLDB_RECORD_METHOD(lldb::SBInstructionList, SBTarget, ReadInstructions,
2063 (lldb::SBAddress, uint32_t, const char *), base_addr,
2064 count, flavor_string);
2065
Kate Stoneb9c1b512016-09-06 20:57:50 +00002066 SBInstructionList sb_instructions;
2067
2068 TargetSP target_sp(GetSP());
2069 if (target_sp) {
2070 Address *addr_ptr = base_addr.get();
2071
2072 if (addr_ptr) {
2073 DataBufferHeap data(
2074 target_sp->GetArchitecture().GetMaximumOpcodeByteSize() * count, 0);
2075 bool prefer_file_cache = false;
Zachary Turner97206d52017-05-12 04:51:55 +00002076 lldb_private::Status error;
Kate Stoneb9c1b512016-09-06 20:57:50 +00002077 lldb::addr_t load_addr = LLDB_INVALID_ADDRESS;
2078 const size_t bytes_read =
2079 target_sp->ReadMemory(*addr_ptr, prefer_file_cache, data.GetBytes(),
2080 data.GetByteSize(), error, &load_addr);
2081 const bool data_from_file = load_addr == LLDB_INVALID_ADDRESS;
2082 sb_instructions.SetDisassembler(Disassembler::DisassembleBytes(
Konrad Kleine248a1302019-05-23 11:14:47 +00002083 target_sp->GetArchitecture(), nullptr, flavor_string, *addr_ptr,
Kate Stoneb9c1b512016-09-06 20:57:50 +00002084 data.GetBytes(), bytes_read, count, data_from_file));
2085 }
2086 }
2087
Jonas Devliegherebaf56642019-03-06 00:06:00 +00002088 return LLDB_RECORD_RESULT(sb_instructions);
Kate Stoneb9c1b512016-09-06 20:57:50 +00002089}
2090
2091lldb::SBInstructionList SBTarget::GetInstructions(lldb::SBAddress base_addr,
2092 const void *buf,
2093 size_t size) {
Jonas Devlieghere0d7b0c92019-03-08 19:09:27 +00002094 LLDB_RECORD_DUMMY(lldb::SBInstructionList, SBTarget, GetInstructions,
2095 (lldb::SBAddress, const void *, size_t), base_addr, buf,
2096 size);
2097
Konrad Kleine248a1302019-05-23 11:14:47 +00002098 return GetInstructionsWithFlavor(base_addr, nullptr, buf, size);
Kate Stoneb9c1b512016-09-06 20:57:50 +00002099}
2100
2101lldb::SBInstructionList
2102SBTarget::GetInstructionsWithFlavor(lldb::SBAddress base_addr,
2103 const char *flavor_string, const void *buf,
2104 size_t size) {
Jonas Devlieghere0d7b0c92019-03-08 19:09:27 +00002105 LLDB_RECORD_DUMMY(lldb::SBInstructionList, SBTarget,
2106 GetInstructionsWithFlavor,
2107 (lldb::SBAddress, const char *, const void *, size_t),
2108 base_addr, flavor_string, buf, size);
2109
Kate Stoneb9c1b512016-09-06 20:57:50 +00002110 SBInstructionList sb_instructions;
2111
2112 TargetSP target_sp(GetSP());
2113 if (target_sp) {
2114 Address addr;
2115
2116 if (base_addr.get())
2117 addr = *base_addr.get();
2118
2119 const bool data_from_file = true;
2120
2121 sb_instructions.SetDisassembler(Disassembler::DisassembleBytes(
Konrad Kleine248a1302019-05-23 11:14:47 +00002122 target_sp->GetArchitecture(), nullptr, flavor_string, addr, buf, size,
Kate Stoneb9c1b512016-09-06 20:57:50 +00002123 UINT32_MAX, data_from_file));
2124 }
2125
2126 return sb_instructions;
2127}
2128
2129lldb::SBInstructionList SBTarget::GetInstructions(lldb::addr_t base_addr,
2130 const void *buf,
2131 size_t size) {
Jonas Devlieghere0d7b0c92019-03-08 19:09:27 +00002132 LLDB_RECORD_DUMMY(lldb::SBInstructionList, SBTarget, GetInstructions,
2133 (lldb::addr_t, const void *, size_t), base_addr, buf, size);
2134
Konrad Kleine248a1302019-05-23 11:14:47 +00002135 return GetInstructionsWithFlavor(ResolveLoadAddress(base_addr), nullptr, buf,
Kate Stoneb9c1b512016-09-06 20:57:50 +00002136 size);
2137}
2138
2139lldb::SBInstructionList
2140SBTarget::GetInstructionsWithFlavor(lldb::addr_t base_addr,
2141 const char *flavor_string, const void *buf,
2142 size_t size) {
Jonas Devlieghere0d7b0c92019-03-08 19:09:27 +00002143 LLDB_RECORD_DUMMY(lldb::SBInstructionList, SBTarget,
2144 GetInstructionsWithFlavor,
2145 (lldb::addr_t, const char *, const void *, size_t),
2146 base_addr, flavor_string, buf, size);
2147
Kate Stoneb9c1b512016-09-06 20:57:50 +00002148 return GetInstructionsWithFlavor(ResolveLoadAddress(base_addr), flavor_string,
2149 buf, size);
2150}
2151
2152SBError SBTarget::SetSectionLoadAddress(lldb::SBSection section,
2153 lldb::addr_t section_base_addr) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00002154 LLDB_RECORD_METHOD(lldb::SBError, SBTarget, SetSectionLoadAddress,
2155 (lldb::SBSection, lldb::addr_t), section,
2156 section_base_addr);
2157
Kate Stoneb9c1b512016-09-06 20:57:50 +00002158 SBError sb_error;
2159 TargetSP target_sp(GetSP());
2160 if (target_sp) {
2161 if (!section.IsValid()) {
2162 sb_error.SetErrorStringWithFormat("invalid section");
2163 } else {
2164 SectionSP section_sp(section.GetSP());
2165 if (section_sp) {
2166 if (section_sp->IsThreadSpecific()) {
2167 sb_error.SetErrorString(
2168 "thread specific sections are not yet supported");
2169 } else {
2170 ProcessSP process_sp(target_sp->GetProcessSP());
2171 if (target_sp->SetSectionLoadAddress(section_sp, section_base_addr)) {
2172 ModuleSP module_sp(section_sp->GetModule());
2173 if (module_sp) {
2174 ModuleList module_list;
2175 module_list.Append(module_sp);
2176 target_sp->ModulesDidLoad(module_list);
2177 }
2178 // Flush info in the process (stack frames, etc)
2179 if (process_sp)
2180 process_sp->Flush();
2181 }
2182 }
2183 }
2184 }
2185 } else {
2186 sb_error.SetErrorString("invalid target");
2187 }
Jonas Devliegherebaf56642019-03-06 00:06:00 +00002188 return LLDB_RECORD_RESULT(sb_error);
Kate Stoneb9c1b512016-09-06 20:57:50 +00002189}
2190
2191SBError SBTarget::ClearSectionLoadAddress(lldb::SBSection section) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00002192 LLDB_RECORD_METHOD(lldb::SBError, SBTarget, ClearSectionLoadAddress,
2193 (lldb::SBSection), section);
2194
Kate Stoneb9c1b512016-09-06 20:57:50 +00002195 SBError sb_error;
2196
2197 TargetSP target_sp(GetSP());
2198 if (target_sp) {
2199 if (!section.IsValid()) {
2200 sb_error.SetErrorStringWithFormat("invalid section");
2201 } else {
2202 SectionSP section_sp(section.GetSP());
2203 if (section_sp) {
2204 ProcessSP process_sp(target_sp->GetProcessSP());
2205 if (target_sp->SetSectionUnloaded(section_sp)) {
2206 ModuleSP module_sp(section_sp->GetModule());
2207 if (module_sp) {
2208 ModuleList module_list;
2209 module_list.Append(module_sp);
2210 target_sp->ModulesDidUnload(module_list, false);
2211 }
2212 // Flush info in the process (stack frames, etc)
2213 if (process_sp)
2214 process_sp->Flush();
2215 }
2216 } else {
2217 sb_error.SetErrorStringWithFormat("invalid section");
2218 }
2219 }
2220 } else {
2221 sb_error.SetErrorStringWithFormat("invalid target");
2222 }
Jonas Devliegherebaf56642019-03-06 00:06:00 +00002223 return LLDB_RECORD_RESULT(sb_error);
Kate Stoneb9c1b512016-09-06 20:57:50 +00002224}
2225
2226SBError SBTarget::SetModuleLoadAddress(lldb::SBModule module,
2227 int64_t slide_offset) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00002228 LLDB_RECORD_METHOD(lldb::SBError, SBTarget, SetModuleLoadAddress,
2229 (lldb::SBModule, int64_t), module, slide_offset);
2230
Kate Stoneb9c1b512016-09-06 20:57:50 +00002231 SBError sb_error;
2232
2233 TargetSP target_sp(GetSP());
2234 if (target_sp) {
2235 ModuleSP module_sp(module.GetSP());
2236 if (module_sp) {
2237 bool changed = false;
2238 if (module_sp->SetLoadAddress(*target_sp, slide_offset, true, changed)) {
2239 // The load was successful, make sure that at least some sections
2240 // changed before we notify that our module was loaded.
2241 if (changed) {
2242 ModuleList module_list;
2243 module_list.Append(module_sp);
2244 target_sp->ModulesDidLoad(module_list);
2245 // Flush info in the process (stack frames, etc)
2246 ProcessSP process_sp(target_sp->GetProcessSP());
2247 if (process_sp)
2248 process_sp->Flush();
2249 }
2250 }
2251 } else {
2252 sb_error.SetErrorStringWithFormat("invalid module");
2253 }
2254
2255 } else {
2256 sb_error.SetErrorStringWithFormat("invalid target");
2257 }
Jonas Devliegherebaf56642019-03-06 00:06:00 +00002258 return LLDB_RECORD_RESULT(sb_error);
Kate Stoneb9c1b512016-09-06 20:57:50 +00002259}
2260
2261SBError SBTarget::ClearModuleLoadAddress(lldb::SBModule module) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00002262 LLDB_RECORD_METHOD(lldb::SBError, SBTarget, ClearModuleLoadAddress,
2263 (lldb::SBModule), module);
2264
Kate Stoneb9c1b512016-09-06 20:57:50 +00002265 SBError sb_error;
2266
2267 char path[PATH_MAX];
2268 TargetSP target_sp(GetSP());
2269 if (target_sp) {
2270 ModuleSP module_sp(module.GetSP());
2271 if (module_sp) {
2272 ObjectFile *objfile = module_sp->GetObjectFile();
2273 if (objfile) {
2274 SectionList *section_list = objfile->GetSectionList();
2275 if (section_list) {
2276 ProcessSP process_sp(target_sp->GetProcessSP());
2277
2278 bool changed = false;
2279 const size_t num_sections = section_list->GetSize();
2280 for (size_t sect_idx = 0; sect_idx < num_sections; ++sect_idx) {
2281 SectionSP section_sp(section_list->GetSectionAtIndex(sect_idx));
2282 if (section_sp)
2283 changed |= target_sp->SetSectionUnloaded(section_sp);
2284 }
2285 if (changed) {
2286 ModuleList module_list;
2287 module_list.Append(module_sp);
2288 target_sp->ModulesDidUnload(module_list, false);
2289 // Flush info in the process (stack frames, etc)
2290 ProcessSP process_sp(target_sp->GetProcessSP());
2291 if (process_sp)
2292 process_sp->Flush();
2293 }
2294 } else {
2295 module_sp->GetFileSpec().GetPath(path, sizeof(path));
2296 sb_error.SetErrorStringWithFormat("no sections in object file '%s'",
2297 path);
2298 }
2299 } else {
2300 module_sp->GetFileSpec().GetPath(path, sizeof(path));
2301 sb_error.SetErrorStringWithFormat("no object file for module '%s'",
2302 path);
2303 }
2304 } else {
2305 sb_error.SetErrorStringWithFormat("invalid module");
2306 }
2307 } else {
2308 sb_error.SetErrorStringWithFormat("invalid target");
2309 }
Jonas Devliegherebaf56642019-03-06 00:06:00 +00002310 return LLDB_RECORD_RESULT(sb_error);
Kate Stoneb9c1b512016-09-06 20:57:50 +00002311}
2312
2313lldb::SBSymbolContextList SBTarget::FindSymbols(const char *name,
2314 lldb::SymbolType symbol_type) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00002315 LLDB_RECORD_METHOD(lldb::SBSymbolContextList, SBTarget, FindSymbols,
2316 (const char *, lldb::SymbolType), name, symbol_type);
2317
Kate Stoneb9c1b512016-09-06 20:57:50 +00002318 SBSymbolContextList sb_sc_list;
2319 if (name && name[0]) {
2320 TargetSP target_sp(GetSP());
2321 if (target_sp) {
2322 bool append = true;
2323 target_sp->GetImages().FindSymbolsWithNameAndType(
2324 ConstString(name), symbol_type, *sb_sc_list, append);
2325 }
2326 }
Jonas Devliegherebaf56642019-03-06 00:06:00 +00002327 return LLDB_RECORD_RESULT(sb_sc_list);
Kate Stoneb9c1b512016-09-06 20:57:50 +00002328}
2329
2330lldb::SBValue SBTarget::EvaluateExpression(const char *expr) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00002331 LLDB_RECORD_METHOD(lldb::SBValue, SBTarget, EvaluateExpression,
2332 (const char *), expr);
2333
Kate Stoneb9c1b512016-09-06 20:57:50 +00002334 TargetSP target_sp(GetSP());
2335 if (!target_sp)
Jonas Devliegherebaf56642019-03-06 00:06:00 +00002336 return LLDB_RECORD_RESULT(SBValue());
Kate Stoneb9c1b512016-09-06 20:57:50 +00002337
2338 SBExpressionOptions options;
2339 lldb::DynamicValueType fetch_dynamic_value =
2340 target_sp->GetPreferDynamicValue();
2341 options.SetFetchDynamicValue(fetch_dynamic_value);
2342 options.SetUnwindOnError(true);
Jonas Devliegherebaf56642019-03-06 00:06:00 +00002343 return LLDB_RECORD_RESULT(EvaluateExpression(expr, options));
Kate Stoneb9c1b512016-09-06 20:57:50 +00002344}
2345
2346lldb::SBValue SBTarget::EvaluateExpression(const char *expr,
2347 const SBExpressionOptions &options) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00002348 LLDB_RECORD_METHOD(lldb::SBValue, SBTarget, EvaluateExpression,
2349 (const char *, const lldb::SBExpressionOptions &), expr,
2350 options);
2351
Kate Stoneb9c1b512016-09-06 20:57:50 +00002352 Log *expr_log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS));
Kate Stoneb9c1b512016-09-06 20:57:50 +00002353 SBValue expr_result;
Kate Stoneb9c1b512016-09-06 20:57:50 +00002354 ValueObjectSP expr_value_sp;
2355 TargetSP target_sp(GetSP());
Konrad Kleine248a1302019-05-23 11:14:47 +00002356 StackFrame *frame = nullptr;
Kate Stoneb9c1b512016-09-06 20:57:50 +00002357 if (target_sp) {
Konrad Kleine248a1302019-05-23 11:14:47 +00002358 if (expr == nullptr || expr[0] == '\0') {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00002359 return LLDB_RECORD_RESULT(expr_result);
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002360 }
Kate Stoneb9c1b512016-09-06 20:57:50 +00002361
2362 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
2363 ExecutionContext exe_ctx(m_opaque_sp.get());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002364
Kate Stoneb9c1b512016-09-06 20:57:50 +00002365
2366 frame = exe_ctx.GetFramePtr();
2367 Target *target = exe_ctx.GetTargetPtr();
2368
2369 if (target) {
2370#ifdef LLDB_CONFIGURATION_DEBUG
2371 StreamString frame_description;
2372 if (frame)
2373 frame->DumpUsingSettingsFormat(&frame_description);
Jim Ingham8f7db522016-12-15 00:30:30 +00002374 llvm::PrettyStackTraceFormat stack_trace(
Kate Stoneb9c1b512016-09-06 20:57:50 +00002375 "SBTarget::EvaluateExpression (expr = \"%s\", fetch_dynamic_value = "
2376 "%u) %s",
2377 expr, options.GetFetchDynamicValue(),
Zachary Turnerc1564272016-11-16 21:15:24 +00002378 frame_description.GetString().str().c_str());
Kate Stoneb9c1b512016-09-06 20:57:50 +00002379#endif
Pavel Labath370e5db2019-03-18 16:04:46 +00002380 target->EvaluateExpression(expr, frame, expr_value_sp, options.ref());
Kate Stoneb9c1b512016-09-06 20:57:50 +00002381
2382 expr_result.SetSP(expr_value_sp, options.GetFetchDynamicValue());
Kate Stoneb9c1b512016-09-06 20:57:50 +00002383 }
2384 }
Kate Stoneb9c1b512016-09-06 20:57:50 +00002385 if (expr_log)
2386 expr_log->Printf("** [SBTarget::EvaluateExpression] Expression result is "
2387 "%s, summary %s **",
2388 expr_result.GetValue(), expr_result.GetSummary());
Jonas Devliegherebaf56642019-03-06 00:06:00 +00002389 return LLDB_RECORD_RESULT(expr_result);
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002390}
2391
Kate Stoneb9c1b512016-09-06 20:57:50 +00002392lldb::addr_t SBTarget::GetStackRedZoneSize() {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00002393 LLDB_RECORD_METHOD_NO_ARGS(lldb::addr_t, SBTarget, GetStackRedZoneSize);
2394
Kate Stoneb9c1b512016-09-06 20:57:50 +00002395 TargetSP target_sp(GetSP());
2396 if (target_sp) {
2397 ABISP abi_sp;
2398 ProcessSP process_sp(target_sp->GetProcessSP());
2399 if (process_sp)
2400 abi_sp = process_sp->GetABI();
2401 else
Jason Molenda43294c92017-06-29 02:57:03 +00002402 abi_sp = ABI::FindPlugin(ProcessSP(), target_sp->GetArchitecture());
Kate Stoneb9c1b512016-09-06 20:57:50 +00002403 if (abi_sp)
2404 return abi_sp->GetRedZoneSize();
2405 }
2406 return 0;
Greg Clayton13fbb992013-02-01 00:47:49 +00002407}
Ilia K8f37ca52015-02-13 14:31:06 +00002408
Kate Stoneb9c1b512016-09-06 20:57:50 +00002409lldb::SBLaunchInfo SBTarget::GetLaunchInfo() const {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00002410 LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::SBLaunchInfo, SBTarget, GetLaunchInfo);
2411
Konrad Kleine248a1302019-05-23 11:14:47 +00002412 lldb::SBLaunchInfo launch_info(nullptr);
Kate Stoneb9c1b512016-09-06 20:57:50 +00002413 TargetSP target_sp(GetSP());
2414 if (target_sp)
Pavel Labath62930e52018-01-10 11:57:31 +00002415 launch_info.set_ref(m_opaque_sp->GetProcessLaunchInfo());
Jonas Devliegherebaf56642019-03-06 00:06:00 +00002416 return LLDB_RECORD_RESULT(launch_info);
Ilia K8f37ca52015-02-13 14:31:06 +00002417}
2418
Kate Stoneb9c1b512016-09-06 20:57:50 +00002419void SBTarget::SetLaunchInfo(const lldb::SBLaunchInfo &launch_info) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00002420 LLDB_RECORD_METHOD(void, SBTarget, SetLaunchInfo,
2421 (const lldb::SBLaunchInfo &), launch_info);
2422
Kate Stoneb9c1b512016-09-06 20:57:50 +00002423 TargetSP target_sp(GetSP());
2424 if (target_sp)
2425 m_opaque_sp->SetProcessLaunchInfo(launch_info.ref());
Ilia K8f37ca52015-02-13 14:31:06 +00002426}
Michal Gornyae211ec2019-03-19 17:13:13 +00002427
2428namespace lldb_private {
2429namespace repro {
2430
2431template <>
2432void RegisterMethods<SBTarget>(Registry &R) {
2433 LLDB_REGISTER_CONSTRUCTOR(SBTarget, ());
2434 LLDB_REGISTER_CONSTRUCTOR(SBTarget, (const lldb::SBTarget &));
2435 LLDB_REGISTER_CONSTRUCTOR(SBTarget, (const lldb::TargetSP &));
2436 LLDB_REGISTER_METHOD(const lldb::SBTarget &,
2437 SBTarget, operator=,(const lldb::SBTarget &));
2438 LLDB_REGISTER_STATIC_METHOD(bool, SBTarget, EventIsTargetEvent,
2439 (const lldb::SBEvent &));
2440 LLDB_REGISTER_STATIC_METHOD(lldb::SBTarget, SBTarget, GetTargetFromEvent,
2441 (const lldb::SBEvent &));
2442 LLDB_REGISTER_STATIC_METHOD(uint32_t, SBTarget, GetNumModulesFromEvent,
2443 (const lldb::SBEvent &));
2444 LLDB_REGISTER_STATIC_METHOD(lldb::SBModule, SBTarget,
2445 GetModuleAtIndexFromEvent,
2446 (const uint32_t, const lldb::SBEvent &));
2447 LLDB_REGISTER_STATIC_METHOD(const char *, SBTarget, GetBroadcasterClassName,
2448 ());
2449 LLDB_REGISTER_METHOD_CONST(bool, SBTarget, IsValid, ());
2450 LLDB_REGISTER_METHOD_CONST(bool, SBTarget, operator bool, ());
2451 LLDB_REGISTER_METHOD(lldb::SBProcess, SBTarget, GetProcess, ());
2452 LLDB_REGISTER_METHOD(lldb::SBPlatform, SBTarget, GetPlatform, ());
2453 LLDB_REGISTER_METHOD_CONST(lldb::SBDebugger, SBTarget, GetDebugger, ());
2454 LLDB_REGISTER_METHOD(lldb::SBStructuredData, SBTarget, GetStatistics, ());
2455 LLDB_REGISTER_METHOD(void, SBTarget, SetCollectingStats, (bool));
2456 LLDB_REGISTER_METHOD(bool, SBTarget, GetCollectingStats, ());
2457 LLDB_REGISTER_METHOD(lldb::SBProcess, SBTarget, LoadCore, (const char *));
2458 LLDB_REGISTER_METHOD(lldb::SBProcess, SBTarget, LoadCore,
2459 (const char *, lldb::SBError &));
2460 LLDB_REGISTER_METHOD(lldb::SBProcess, SBTarget, LaunchSimple,
2461 (const char **, const char **, const char *));
2462 LLDB_REGISTER_METHOD(lldb::SBError, SBTarget, Install, ());
2463 LLDB_REGISTER_METHOD(lldb::SBProcess, SBTarget, Launch,
2464 (lldb::SBListener &, const char **, const char **,
2465 const char *, const char *, const char *,
2466 const char *, uint32_t, bool, lldb::SBError &));
2467 LLDB_REGISTER_METHOD(lldb::SBProcess, SBTarget, Launch,
2468 (lldb::SBLaunchInfo &, lldb::SBError &));
2469 LLDB_REGISTER_METHOD(lldb::SBProcess, SBTarget, Attach,
2470 (lldb::SBAttachInfo &, lldb::SBError &));
2471 LLDB_REGISTER_METHOD(lldb::SBProcess, SBTarget, AttachToProcessWithID,
2472 (lldb::SBListener &, lldb::pid_t, lldb::SBError &));
2473 LLDB_REGISTER_METHOD(
2474 lldb::SBProcess, SBTarget, AttachToProcessWithName,
2475 (lldb::SBListener &, const char *, bool, lldb::SBError &));
2476 LLDB_REGISTER_METHOD(
2477 lldb::SBProcess, SBTarget, ConnectRemote,
2478 (lldb::SBListener &, const char *, const char *, lldb::SBError &));
2479 LLDB_REGISTER_METHOD(lldb::SBFileSpec, SBTarget, GetExecutable, ());
2480 LLDB_REGISTER_METHOD_CONST(bool,
2481 SBTarget, operator==,(const lldb::SBTarget &));
2482 LLDB_REGISTER_METHOD_CONST(bool,
2483 SBTarget, operator!=,(const lldb::SBTarget &));
2484 LLDB_REGISTER_METHOD(lldb::SBAddress, SBTarget, ResolveLoadAddress,
2485 (lldb::addr_t));
2486 LLDB_REGISTER_METHOD(lldb::SBAddress, SBTarget, ResolveFileAddress,
2487 (lldb::addr_t));
2488 LLDB_REGISTER_METHOD(lldb::SBAddress, SBTarget, ResolvePastLoadAddress,
2489 (uint32_t, lldb::addr_t));
2490 LLDB_REGISTER_METHOD(lldb::SBSymbolContext, SBTarget,
2491 ResolveSymbolContextForAddress,
2492 (const lldb::SBAddress &, uint32_t));
2493 LLDB_REGISTER_METHOD(lldb::SBBreakpoint, SBTarget,
2494 BreakpointCreateByLocation, (const char *, uint32_t));
2495 LLDB_REGISTER_METHOD(lldb::SBBreakpoint, SBTarget,
2496 BreakpointCreateByLocation,
2497 (const lldb::SBFileSpec &, uint32_t));
2498 LLDB_REGISTER_METHOD(lldb::SBBreakpoint, SBTarget,
2499 BreakpointCreateByLocation,
2500 (const lldb::SBFileSpec &, uint32_t, lldb::addr_t));
2501 LLDB_REGISTER_METHOD(lldb::SBBreakpoint, SBTarget,
2502 BreakpointCreateByLocation,
2503 (const lldb::SBFileSpec &, uint32_t, lldb::addr_t,
2504 lldb::SBFileSpecList &));
2505 LLDB_REGISTER_METHOD(lldb::SBBreakpoint, SBTarget,
2506 BreakpointCreateByLocation,
2507 (const lldb::SBFileSpec &, uint32_t, uint32_t,
2508 lldb::addr_t, lldb::SBFileSpecList &));
2509 LLDB_REGISTER_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateByName,
2510 (const char *, const char *));
2511 LLDB_REGISTER_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateByName,
2512 (const char *, const lldb::SBFileSpecList &,
2513 const lldb::SBFileSpecList &));
2514 LLDB_REGISTER_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateByName,
2515 (const char *, uint32_t, const lldb::SBFileSpecList &,
2516 const lldb::SBFileSpecList &));
2517 LLDB_REGISTER_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateByName,
2518 (const char *, uint32_t, lldb::LanguageType,
2519 const lldb::SBFileSpecList &,
2520 const lldb::SBFileSpecList &));
2521 LLDB_REGISTER_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateByNames,
2522 (const char **, uint32_t, uint32_t,
2523 const lldb::SBFileSpecList &,
2524 const lldb::SBFileSpecList &));
2525 LLDB_REGISTER_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateByNames,
2526 (const char **, uint32_t, uint32_t, lldb::LanguageType,
2527 const lldb::SBFileSpecList &,
2528 const lldb::SBFileSpecList &));
2529 LLDB_REGISTER_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateByNames,
2530 (const char **, uint32_t, uint32_t, lldb::LanguageType,
2531 lldb::addr_t, const lldb::SBFileSpecList &,
2532 const lldb::SBFileSpecList &));
2533 LLDB_REGISTER_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateByRegex,
2534 (const char *, const char *));
2535 LLDB_REGISTER_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateByRegex,
2536 (const char *, const lldb::SBFileSpecList &,
2537 const lldb::SBFileSpecList &));
2538 LLDB_REGISTER_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateByRegex,
2539 (const char *, lldb::LanguageType,
2540 const lldb::SBFileSpecList &,
2541 const lldb::SBFileSpecList &));
2542 LLDB_REGISTER_METHOD(lldb::SBBreakpoint, SBTarget,
2543 BreakpointCreateByAddress, (lldb::addr_t));
2544 LLDB_REGISTER_METHOD(lldb::SBBreakpoint, SBTarget,
2545 BreakpointCreateBySBAddress, (lldb::SBAddress &));
2546 LLDB_REGISTER_METHOD(
2547 lldb::SBBreakpoint, SBTarget, BreakpointCreateBySourceRegex,
2548 (const char *, const lldb::SBFileSpec &, const char *));
2549 LLDB_REGISTER_METHOD(lldb::SBBreakpoint, SBTarget,
2550 BreakpointCreateBySourceRegex,
2551 (const char *, const lldb::SBFileSpecList &,
2552 const lldb::SBFileSpecList &));
2553 LLDB_REGISTER_METHOD(
2554 lldb::SBBreakpoint, SBTarget, BreakpointCreateBySourceRegex,
2555 (const char *, const lldb::SBFileSpecList &,
2556 const lldb::SBFileSpecList &, const lldb::SBStringList &));
2557 LLDB_REGISTER_METHOD(lldb::SBBreakpoint, SBTarget,
2558 BreakpointCreateForException,
2559 (lldb::LanguageType, bool, bool));
2560 LLDB_REGISTER_METHOD(
2561 lldb::SBBreakpoint, SBTarget, BreakpointCreateFromScript,
2562 (const char *, lldb::SBStructuredData &, const lldb::SBFileSpecList &,
2563 const lldb::SBFileSpecList &, bool));
2564 LLDB_REGISTER_METHOD_CONST(uint32_t, SBTarget, GetNumBreakpoints, ());
2565 LLDB_REGISTER_METHOD_CONST(lldb::SBBreakpoint, SBTarget,
2566 GetBreakpointAtIndex, (uint32_t));
2567 LLDB_REGISTER_METHOD(bool, SBTarget, BreakpointDelete, (lldb::break_id_t));
2568 LLDB_REGISTER_METHOD(lldb::SBBreakpoint, SBTarget, FindBreakpointByID,
2569 (lldb::break_id_t));
2570 LLDB_REGISTER_METHOD(bool, SBTarget, FindBreakpointsByName,
2571 (const char *, lldb::SBBreakpointList &));
2572 LLDB_REGISTER_METHOD(void, SBTarget, GetBreakpointNames,
2573 (lldb::SBStringList &));
2574 LLDB_REGISTER_METHOD(void, SBTarget, DeleteBreakpointName, (const char *));
2575 LLDB_REGISTER_METHOD(bool, SBTarget, EnableAllBreakpoints, ());
2576 LLDB_REGISTER_METHOD(bool, SBTarget, DisableAllBreakpoints, ());
2577 LLDB_REGISTER_METHOD(bool, SBTarget, DeleteAllBreakpoints, ());
2578 LLDB_REGISTER_METHOD(lldb::SBError, SBTarget, BreakpointsCreateFromFile,
2579 (lldb::SBFileSpec &, lldb::SBBreakpointList &));
2580 LLDB_REGISTER_METHOD(
2581 lldb::SBError, SBTarget, BreakpointsCreateFromFile,
2582 (lldb::SBFileSpec &, lldb::SBStringList &, lldb::SBBreakpointList &));
2583 LLDB_REGISTER_METHOD(lldb::SBError, SBTarget, BreakpointsWriteToFile,
2584 (lldb::SBFileSpec &));
2585 LLDB_REGISTER_METHOD(lldb::SBError, SBTarget, BreakpointsWriteToFile,
2586 (lldb::SBFileSpec &, lldb::SBBreakpointList &, bool));
2587 LLDB_REGISTER_METHOD_CONST(uint32_t, SBTarget, GetNumWatchpoints, ());
2588 LLDB_REGISTER_METHOD_CONST(lldb::SBWatchpoint, SBTarget,
2589 GetWatchpointAtIndex, (uint32_t));
2590 LLDB_REGISTER_METHOD(bool, SBTarget, DeleteWatchpoint, (lldb::watch_id_t));
2591 LLDB_REGISTER_METHOD(lldb::SBWatchpoint, SBTarget, FindWatchpointByID,
2592 (lldb::watch_id_t));
2593 LLDB_REGISTER_METHOD(lldb::SBWatchpoint, SBTarget, WatchAddress,
2594 (lldb::addr_t, size_t, bool, bool, lldb::SBError &));
2595 LLDB_REGISTER_METHOD(bool, SBTarget, EnableAllWatchpoints, ());
2596 LLDB_REGISTER_METHOD(bool, SBTarget, DisableAllWatchpoints, ());
2597 LLDB_REGISTER_METHOD(lldb::SBValue, SBTarget, CreateValueFromAddress,
2598 (const char *, lldb::SBAddress, lldb::SBType));
2599 LLDB_REGISTER_METHOD(lldb::SBValue, SBTarget, CreateValueFromData,
2600 (const char *, lldb::SBData, lldb::SBType));
2601 LLDB_REGISTER_METHOD(lldb::SBValue, SBTarget, CreateValueFromExpression,
2602 (const char *, const char *));
2603 LLDB_REGISTER_METHOD(bool, SBTarget, DeleteAllWatchpoints, ());
2604 LLDB_REGISTER_METHOD(void, SBTarget, AppendImageSearchPath,
2605 (const char *, const char *, lldb::SBError &));
2606 LLDB_REGISTER_METHOD(lldb::SBModule, SBTarget, AddModule,
2607 (const char *, const char *, const char *));
2608 LLDB_REGISTER_METHOD(
2609 lldb::SBModule, SBTarget, AddModule,
2610 (const char *, const char *, const char *, const char *));
2611 LLDB_REGISTER_METHOD(lldb::SBModule, SBTarget, AddModule,
2612 (const lldb::SBModuleSpec &));
2613 LLDB_REGISTER_METHOD(bool, SBTarget, AddModule, (lldb::SBModule &));
2614 LLDB_REGISTER_METHOD_CONST(uint32_t, SBTarget, GetNumModules, ());
2615 LLDB_REGISTER_METHOD(void, SBTarget, Clear, ());
2616 LLDB_REGISTER_METHOD(lldb::SBModule, SBTarget, FindModule,
2617 (const lldb::SBFileSpec &));
2618 LLDB_REGISTER_METHOD(lldb::SBSymbolContextList, SBTarget, FindCompileUnits,
2619 (const lldb::SBFileSpec &));
2620 LLDB_REGISTER_METHOD(lldb::ByteOrder, SBTarget, GetByteOrder, ());
2621 LLDB_REGISTER_METHOD(const char *, SBTarget, GetTriple, ());
2622 LLDB_REGISTER_METHOD(uint32_t, SBTarget, GetDataByteSize, ());
2623 LLDB_REGISTER_METHOD(uint32_t, SBTarget, GetCodeByteSize, ());
2624 LLDB_REGISTER_METHOD(uint32_t, SBTarget, GetAddressByteSize, ());
2625 LLDB_REGISTER_METHOD(lldb::SBModule, SBTarget, GetModuleAtIndex,
2626 (uint32_t));
2627 LLDB_REGISTER_METHOD(bool, SBTarget, RemoveModule, (lldb::SBModule));
2628 LLDB_REGISTER_METHOD_CONST(lldb::SBBroadcaster, SBTarget, GetBroadcaster,
2629 ());
2630 LLDB_REGISTER_METHOD(bool, SBTarget, GetDescription,
2631 (lldb::SBStream &, lldb::DescriptionLevel));
2632 LLDB_REGISTER_METHOD(lldb::SBSymbolContextList, SBTarget, FindFunctions,
2633 (const char *, uint32_t));
2634 LLDB_REGISTER_METHOD(lldb::SBSymbolContextList, SBTarget,
2635 FindGlobalFunctions,
2636 (const char *, uint32_t, lldb::MatchType));
2637 LLDB_REGISTER_METHOD(lldb::SBType, SBTarget, FindFirstType, (const char *));
2638 LLDB_REGISTER_METHOD(lldb::SBType, SBTarget, GetBasicType,
2639 (lldb::BasicType));
2640 LLDB_REGISTER_METHOD(lldb::SBTypeList, SBTarget, FindTypes, (const char *));
2641 LLDB_REGISTER_METHOD(lldb::SBValueList, SBTarget, FindGlobalVariables,
2642 (const char *, uint32_t));
2643 LLDB_REGISTER_METHOD(lldb::SBValueList, SBTarget, FindGlobalVariables,
2644 (const char *, uint32_t, lldb::MatchType));
2645 LLDB_REGISTER_METHOD(lldb::SBValue, SBTarget, FindFirstGlobalVariable,
2646 (const char *));
2647 LLDB_REGISTER_METHOD(lldb::SBSourceManager, SBTarget, GetSourceManager, ());
2648 LLDB_REGISTER_METHOD(lldb::SBInstructionList, SBTarget, ReadInstructions,
2649 (lldb::SBAddress, uint32_t));
2650 LLDB_REGISTER_METHOD(lldb::SBInstructionList, SBTarget, ReadInstructions,
2651 (lldb::SBAddress, uint32_t, const char *));
2652 LLDB_REGISTER_METHOD(lldb::SBError, SBTarget, SetSectionLoadAddress,
2653 (lldb::SBSection, lldb::addr_t));
2654 LLDB_REGISTER_METHOD(lldb::SBError, SBTarget, ClearSectionLoadAddress,
2655 (lldb::SBSection));
2656 LLDB_REGISTER_METHOD(lldb::SBError, SBTarget, SetModuleLoadAddress,
2657 (lldb::SBModule, int64_t));
2658 LLDB_REGISTER_METHOD(lldb::SBError, SBTarget, ClearModuleLoadAddress,
2659 (lldb::SBModule));
2660 LLDB_REGISTER_METHOD(lldb::SBSymbolContextList, SBTarget, FindSymbols,
2661 (const char *, lldb::SymbolType));
2662 LLDB_REGISTER_METHOD(lldb::SBValue, SBTarget, EvaluateExpression,
2663 (const char *));
2664 LLDB_REGISTER_METHOD(lldb::SBValue, SBTarget, EvaluateExpression,
2665 (const char *, const lldb::SBExpressionOptions &));
2666 LLDB_REGISTER_METHOD(lldb::addr_t, SBTarget, GetStackRedZoneSize, ());
2667 LLDB_REGISTER_METHOD_CONST(lldb::SBLaunchInfo, SBTarget, GetLaunchInfo, ());
2668 LLDB_REGISTER_METHOD(void, SBTarget, SetLaunchInfo,
2669 (const lldb::SBLaunchInfo &));
2670}
2671
2672}
2673}