blob: 9fcd2e51c565e5d8a5205eff160dcd004baa3b5c [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//----------------------------------------------------------------------
101// SBTarget constructor
102//----------------------------------------------------------------------
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000103SBTarget::SBTarget() : m_opaque_sp() {
104 LLDB_RECORD_CONSTRUCTOR_NO_ARGS(SBTarget);
105}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000106
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000107SBTarget::SBTarget(const SBTarget &rhs) : m_opaque_sp(rhs.m_opaque_sp) {
108 LLDB_RECORD_CONSTRUCTOR(SBTarget, (const lldb::SBTarget &), rhs);
109}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000110
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000111SBTarget::SBTarget(const TargetSP &target_sp) : m_opaque_sp(target_sp) {
112 LLDB_RECORD_CONSTRUCTOR(SBTarget, (const lldb::TargetSP &), target_sp);
113}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000114
Kate Stoneb9c1b512016-09-06 20:57:50 +0000115const SBTarget &SBTarget::operator=(const SBTarget &rhs) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000116 LLDB_RECORD_METHOD(const lldb::SBTarget &,
117 SBTarget, operator=,(const lldb::SBTarget &), rhs);
118
Kate Stoneb9c1b512016-09-06 20:57:50 +0000119 if (this != &rhs)
120 m_opaque_sp = rhs.m_opaque_sp;
121 return *this;
Greg Claytonefabb122010-11-05 23:17:00 +0000122}
123
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000124//----------------------------------------------------------------------
125// Destructor
126//----------------------------------------------------------------------
Kate Stoneb9c1b512016-09-06 20:57:50 +0000127SBTarget::~SBTarget() {}
128
129bool SBTarget::EventIsTargetEvent(const SBEvent &event) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000130 LLDB_RECORD_STATIC_METHOD(bool, SBTarget, EventIsTargetEvent,
131 (const lldb::SBEvent &), event);
132
Kate Stoneb9c1b512016-09-06 20:57:50 +0000133 return Target::TargetEventData::GetEventDataFromEvent(event.get()) != NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000134}
135
Kate Stoneb9c1b512016-09-06 20:57:50 +0000136SBTarget SBTarget::GetTargetFromEvent(const SBEvent &event) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000137 LLDB_RECORD_STATIC_METHOD(lldb::SBTarget, SBTarget, GetTargetFromEvent,
138 (const lldb::SBEvent &), event);
139
140 return LLDB_RECORD_RESULT(
141 Target::TargetEventData::GetTargetFromEvent(event.get()));
Ilia Keb2c19a2015-03-10 21:59:55 +0000142}
143
Kate Stoneb9c1b512016-09-06 20:57:50 +0000144uint32_t SBTarget::GetNumModulesFromEvent(const SBEvent &event) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000145 LLDB_RECORD_STATIC_METHOD(uint32_t, SBTarget, GetNumModulesFromEvent,
146 (const lldb::SBEvent &), event);
147
Kate Stoneb9c1b512016-09-06 20:57:50 +0000148 const ModuleList module_list =
149 Target::TargetEventData::GetModuleListFromEvent(event.get());
150 return module_list.GetSize();
Ilia Keb2c19a2015-03-10 21:59:55 +0000151}
152
Kate Stoneb9c1b512016-09-06 20:57:50 +0000153SBModule SBTarget::GetModuleAtIndexFromEvent(const uint32_t idx,
154 const SBEvent &event) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000155 LLDB_RECORD_STATIC_METHOD(lldb::SBModule, SBTarget, GetModuleAtIndexFromEvent,
156 (const uint32_t, const lldb::SBEvent &), idx,
157 event);
158
Kate Stoneb9c1b512016-09-06 20:57:50 +0000159 const ModuleList module_list =
160 Target::TargetEventData::GetModuleListFromEvent(event.get());
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000161 return LLDB_RECORD_RESULT(SBModule(module_list.GetModuleAtIndex(idx)));
Ilia Keb2c19a2015-03-10 21:59:55 +0000162}
163
Kate Stoneb9c1b512016-09-06 20:57:50 +0000164const char *SBTarget::GetBroadcasterClassName() {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000165 LLDB_RECORD_STATIC_METHOD_NO_ARGS(const char *, SBTarget,
166 GetBroadcasterClassName);
167
Kate Stoneb9c1b512016-09-06 20:57:50 +0000168 return Target::GetStaticBroadcasterClass().AsCString();
Ilia Keb2c19a2015-03-10 21:59:55 +0000169}
170
Kate Stoneb9c1b512016-09-06 20:57:50 +0000171bool SBTarget::IsValid() const {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000172 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBTarget, IsValid);
173
Kate Stoneb9c1b512016-09-06 20:57:50 +0000174 return m_opaque_sp.get() != NULL && 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
Kate Stoneb9c1b512016-09-06 20:57:50 +0000291 char *stdin_path = NULL;
292 char *stdout_path = NULL;
293 char *stderr_path = NULL;
294 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());
310 sb_error.ref() = target_sp->Install(NULL);
311 }
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
384 error.SetError(target_sp->Launch(launch_info, NULL));
385
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
433 error.SetError(target_sp->Launch(launch_info, NULL));
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 =
554 target_sp->CreateProcess(listener.m_opaque_sp, plugin_name, NULL);
James McIlree9631aae2011-03-04 00:31:13 +0000555 else
Kate Stoneb9c1b512016-09-06 20:57:50 +0000556 process_sp = target_sp->CreateProcess(
557 target_sp->GetDebugger().GetListener(), plugin_name, NULL);
558
559 if (process_sp) {
560 sb_process.SetSP(process_sp);
561 error.SetError(process_sp->ConnectRemote(NULL, url));
562 } 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) {
682 SBError sb_error;
683 size_t bytes_read = 0;
684 TargetSP target_sp(GetSP());
685 if (target_sp) {
686 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
687 bytes_read =
688 target_sp->ReadMemory(addr.ref(), false, buf, size, sb_error.ref());
689 } else {
690 sb_error.SetErrorString("invalid target");
691 }
692
693 return bytes_read;
694}
695
696SBBreakpoint SBTarget::BreakpointCreateByLocation(const char *file,
697 uint32_t line) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000698 LLDB_RECORD_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateByLocation,
699 (const char *, uint32_t), file, line);
700
701 return LLDB_RECORD_RESULT(
702 SBBreakpoint(BreakpointCreateByLocation(SBFileSpec(file, false), line)));
Matthew Gardinerc928de32014-10-22 07:22:56 +0000703}
Greg Clayton5f2a4f92011-03-02 21:34:46 +0000704
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000705SBBreakpoint
Kate Stoneb9c1b512016-09-06 20:57:50 +0000706SBTarget::BreakpointCreateByLocation(const SBFileSpec &sb_file_spec,
707 uint32_t line) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000708 LLDB_RECORD_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateByLocation,
709 (const lldb::SBFileSpec &, uint32_t), sb_file_spec, line);
710
711 return LLDB_RECORD_RESULT(BreakpointCreateByLocation(sb_file_spec, line, 0));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000712}
713
714SBBreakpoint
Kate Stoneb9c1b512016-09-06 20:57:50 +0000715SBTarget::BreakpointCreateByLocation(const SBFileSpec &sb_file_spec,
716 uint32_t line, lldb::addr_t offset) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000717 LLDB_RECORD_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateByLocation,
718 (const lldb::SBFileSpec &, uint32_t, lldb::addr_t),
719 sb_file_spec, line, offset);
720
Jim Ingham92d19602016-09-20 22:54:49 +0000721 SBFileSpecList empty_list;
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000722 return LLDB_RECORD_RESULT(
723 BreakpointCreateByLocation(sb_file_spec, line, offset, empty_list));
Jim Ingham92d19602016-09-20 22:54:49 +0000724}
725
726SBBreakpoint
727SBTarget::BreakpointCreateByLocation(const SBFileSpec &sb_file_spec,
728 uint32_t line, lldb::addr_t offset,
729 SBFileSpecList &sb_module_list) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000730 LLDB_RECORD_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateByLocation,
731 (const lldb::SBFileSpec &, uint32_t, lldb::addr_t,
732 lldb::SBFileSpecList &),
733 sb_file_spec, line, offset, sb_module_list);
734
735 return LLDB_RECORD_RESULT(BreakpointCreateByLocation(sb_file_spec, line, 0,
736 offset, sb_module_list));
Adrian Prantl431b1582018-08-30 15:11:00 +0000737}
738
739SBBreakpoint SBTarget::BreakpointCreateByLocation(
740 const SBFileSpec &sb_file_spec, uint32_t line, uint32_t column,
741 lldb::addr_t offset, SBFileSpecList &sb_module_list) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000742 LLDB_RECORD_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateByLocation,
743 (const lldb::SBFileSpec &, uint32_t, uint32_t,
744 lldb::addr_t, lldb::SBFileSpecList &),
745 sb_file_spec, line, column, offset, sb_module_list);
746
Kate Stoneb9c1b512016-09-06 20:57:50 +0000747 SBBreakpoint sb_bp;
748 TargetSP target_sp(GetSP());
749 if (target_sp && line != 0) {
750 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
Caroline Ticeceb6b132010-10-26 03:11:13 +0000751
Kate Stoneb9c1b512016-09-06 20:57:50 +0000752 const LazyBool check_inlines = eLazyBoolCalculate;
753 const LazyBool skip_prologue = eLazyBoolCalculate;
754 const bool internal = false;
755 const bool hardware = false;
756 const LazyBool move_to_nearest_code = eLazyBoolCalculate;
Jim Ingham92d19602016-09-20 22:54:49 +0000757 const FileSpecList *module_list = nullptr;
758 if (sb_module_list.GetSize() > 0) {
759 module_list = sb_module_list.get();
760 }
Pavel Labath6ac84032017-02-27 11:05:34 +0000761 sb_bp = target_sp->CreateBreakpoint(
Adrian Prantl431b1582018-08-30 15:11:00 +0000762 module_list, *sb_file_spec, line, column, offset, check_inlines,
763 skip_prologue, internal, hardware, move_to_nearest_code);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000764 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000765
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000766 return LLDB_RECORD_RESULT(sb_bp);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000767}
768
769SBBreakpoint SBTarget::BreakpointCreateByName(const char *symbol_name,
770 const char *module_name) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000771 LLDB_RECORD_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateByName,
772 (const char *, const char *), symbol_name, module_name);
773
Kate Stoneb9c1b512016-09-06 20:57:50 +0000774 SBBreakpoint sb_bp;
775 TargetSP target_sp(GetSP());
776 if (target_sp.get()) {
777 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
778
779 const bool internal = false;
780 const bool hardware = false;
781 const LazyBool skip_prologue = eLazyBoolCalculate;
782 const lldb::addr_t offset = 0;
783 if (module_name && module_name[0]) {
784 FileSpecList module_spec_list;
Jonas Devlieghere8f3be7a2018-11-01 21:05:36 +0000785 module_spec_list.Append(FileSpec(module_name));
Pavel Labath6ac84032017-02-27 11:05:34 +0000786 sb_bp = target_sp->CreateBreakpoint(
Kate Stoneb9c1b512016-09-06 20:57:50 +0000787 &module_spec_list, NULL, symbol_name, eFunctionNameTypeAuto,
788 eLanguageTypeUnknown, offset, skip_prologue, internal, hardware);
789 } else {
Pavel Labath6ac84032017-02-27 11:05:34 +0000790 sb_bp = target_sp->CreateBreakpoint(
Kate Stoneb9c1b512016-09-06 20:57:50 +0000791 NULL, NULL, symbol_name, eFunctionNameTypeAuto, eLanguageTypeUnknown,
792 offset, skip_prologue, internal, hardware);
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000793 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000794 }
795
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000796 return LLDB_RECORD_RESULT(sb_bp);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000797}
798
799lldb::SBBreakpoint
800SBTarget::BreakpointCreateByName(const char *symbol_name,
801 const SBFileSpecList &module_list,
802 const SBFileSpecList &comp_unit_list) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000803 LLDB_RECORD_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateByName,
804 (const char *, const lldb::SBFileSpecList &,
805 const lldb::SBFileSpecList &),
806 symbol_name, module_list, comp_unit_list);
807
Zachary Turner117b1fa2018-10-25 20:45:40 +0000808 lldb::FunctionNameType name_type_mask = eFunctionNameTypeAuto;
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000809 return LLDB_RECORD_RESULT(
810 BreakpointCreateByName(symbol_name, name_type_mask, eLanguageTypeUnknown,
811 module_list, comp_unit_list));
Kate Stoneb9c1b512016-09-06 20:57:50 +0000812}
813
814lldb::SBBreakpoint SBTarget::BreakpointCreateByName(
815 const char *symbol_name, uint32_t name_type_mask,
816 const SBFileSpecList &module_list, const SBFileSpecList &comp_unit_list) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000817 LLDB_RECORD_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateByName,
818 (const char *, uint32_t, const lldb::SBFileSpecList &,
819 const lldb::SBFileSpecList &),
820 symbol_name, name_type_mask, module_list, comp_unit_list);
821
822 return LLDB_RECORD_RESULT(
823 BreakpointCreateByName(symbol_name, name_type_mask, eLanguageTypeUnknown,
824 module_list, comp_unit_list));
Kate Stoneb9c1b512016-09-06 20:57:50 +0000825}
826
827lldb::SBBreakpoint SBTarget::BreakpointCreateByName(
828 const char *symbol_name, uint32_t name_type_mask,
829 LanguageType symbol_language, const SBFileSpecList &module_list,
830 const SBFileSpecList &comp_unit_list) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000831 LLDB_RECORD_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateByName,
832 (const char *, uint32_t, lldb::LanguageType,
833 const lldb::SBFileSpecList &,
834 const lldb::SBFileSpecList &),
835 symbol_name, name_type_mask, symbol_language, module_list,
836 comp_unit_list);
837
Kate Stoneb9c1b512016-09-06 20:57:50 +0000838 SBBreakpoint sb_bp;
839 TargetSP target_sp(GetSP());
840 if (target_sp && symbol_name && symbol_name[0]) {
841 const bool internal = false;
842 const bool hardware = false;
843 const LazyBool skip_prologue = eLazyBoolCalculate;
844 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
Zachary Turner117b1fa2018-10-25 20:45:40 +0000845 FunctionNameType mask = static_cast<FunctionNameType>(name_type_mask);
846 sb_bp = target_sp->CreateBreakpoint(module_list.get(), comp_unit_list.get(),
847 symbol_name, mask, symbol_language, 0,
848 skip_prologue, internal, hardware);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000849 }
850
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000851 return LLDB_RECORD_RESULT(sb_bp);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000852}
853
854lldb::SBBreakpoint SBTarget::BreakpointCreateByNames(
855 const char *symbol_names[], uint32_t num_names, uint32_t name_type_mask,
856 const SBFileSpecList &module_list, const SBFileSpecList &comp_unit_list) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000857 LLDB_RECORD_METHOD(
858 lldb::SBBreakpoint, SBTarget, BreakpointCreateByNames,
859 (const char **, uint32_t, uint32_t, const lldb::SBFileSpecList &,
860 const lldb::SBFileSpecList &),
861 symbol_names, num_names, name_type_mask, module_list, comp_unit_list);
862
863 return LLDB_RECORD_RESULT(BreakpointCreateByNames(
864 symbol_names, num_names, name_type_mask, eLanguageTypeUnknown,
865 module_list, comp_unit_list));
Kate Stoneb9c1b512016-09-06 20:57:50 +0000866}
867
868lldb::SBBreakpoint SBTarget::BreakpointCreateByNames(
869 const char *symbol_names[], uint32_t num_names, uint32_t name_type_mask,
870 LanguageType symbol_language, const SBFileSpecList &module_list,
871 const SBFileSpecList &comp_unit_list) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000872 LLDB_RECORD_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateByNames,
873 (const char **, uint32_t, uint32_t, lldb::LanguageType,
874 const lldb::SBFileSpecList &,
875 const lldb::SBFileSpecList &),
876 symbol_names, num_names, name_type_mask, symbol_language,
877 module_list, comp_unit_list);
878
879 return LLDB_RECORD_RESULT(BreakpointCreateByNames(
880 symbol_names, num_names, name_type_mask, eLanguageTypeUnknown, 0,
881 module_list, comp_unit_list));
Kate Stoneb9c1b512016-09-06 20:57:50 +0000882}
883
884lldb::SBBreakpoint SBTarget::BreakpointCreateByNames(
885 const char *symbol_names[], uint32_t num_names, uint32_t name_type_mask,
886 LanguageType symbol_language, lldb::addr_t offset,
887 const SBFileSpecList &module_list, const SBFileSpecList &comp_unit_list) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000888 LLDB_RECORD_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateByNames,
889 (const char **, uint32_t, uint32_t, lldb::LanguageType,
890 lldb::addr_t, const lldb::SBFileSpecList &,
891 const lldb::SBFileSpecList &),
892 symbol_names, num_names, name_type_mask, symbol_language,
893 offset, module_list, comp_unit_list);
894
Kate Stoneb9c1b512016-09-06 20:57:50 +0000895 SBBreakpoint sb_bp;
896 TargetSP target_sp(GetSP());
897 if (target_sp && num_names > 0) {
898 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
899 const bool internal = false;
900 const bool hardware = false;
Zachary Turner117b1fa2018-10-25 20:45:40 +0000901 FunctionNameType mask = static_cast<FunctionNameType>(name_type_mask);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000902 const LazyBool skip_prologue = eLazyBoolCalculate;
Pavel Labath6ac84032017-02-27 11:05:34 +0000903 sb_bp = target_sp->CreateBreakpoint(
Zachary Turner117b1fa2018-10-25 20:45:40 +0000904 module_list.get(), comp_unit_list.get(), symbol_names, num_names, mask,
905 symbol_language, offset, skip_prologue, internal, hardware);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000906 }
907
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000908 return LLDB_RECORD_RESULT(sb_bp);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000909}
910
911SBBreakpoint SBTarget::BreakpointCreateByRegex(const char *symbol_name_regex,
912 const char *module_name) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000913 LLDB_RECORD_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateByRegex,
914 (const char *, const char *), symbol_name_regex,
915 module_name);
916
Kate Stoneb9c1b512016-09-06 20:57:50 +0000917 SBFileSpecList module_spec_list;
918 SBFileSpecList comp_unit_list;
919 if (module_name && module_name[0]) {
Jonas Devlieghere8f3be7a2018-11-01 21:05:36 +0000920 module_spec_list.Append(FileSpec(module_name));
Kate Stoneb9c1b512016-09-06 20:57:50 +0000921 }
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000922 return LLDB_RECORD_RESULT(
923 BreakpointCreateByRegex(symbol_name_regex, eLanguageTypeUnknown,
924 module_spec_list, comp_unit_list));
Kate Stoneb9c1b512016-09-06 20:57:50 +0000925}
926
927lldb::SBBreakpoint
928SBTarget::BreakpointCreateByRegex(const char *symbol_name_regex,
929 const SBFileSpecList &module_list,
930 const SBFileSpecList &comp_unit_list) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000931 LLDB_RECORD_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateByRegex,
932 (const char *, const lldb::SBFileSpecList &,
933 const lldb::SBFileSpecList &),
934 symbol_name_regex, module_list, comp_unit_list);
935
936 return LLDB_RECORD_RESULT(BreakpointCreateByRegex(
937 symbol_name_regex, eLanguageTypeUnknown, module_list, comp_unit_list));
Kate Stoneb9c1b512016-09-06 20:57:50 +0000938}
939
940lldb::SBBreakpoint SBTarget::BreakpointCreateByRegex(
941 const char *symbol_name_regex, LanguageType symbol_language,
942 const SBFileSpecList &module_list, const SBFileSpecList &comp_unit_list) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000943 LLDB_RECORD_METHOD(
944 lldb::SBBreakpoint, SBTarget, BreakpointCreateByRegex,
945 (const char *, lldb::LanguageType, const lldb::SBFileSpecList &,
946 const lldb::SBFileSpecList &),
947 symbol_name_regex, symbol_language, module_list, comp_unit_list);
948
Kate Stoneb9c1b512016-09-06 20:57:50 +0000949
950 SBBreakpoint sb_bp;
951 TargetSP target_sp(GetSP());
952 if (target_sp && symbol_name_regex && symbol_name_regex[0]) {
953 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
Zachary Turner95eae422016-09-21 16:01:28 +0000954 RegularExpression regexp((llvm::StringRef(symbol_name_regex)));
Kate Stoneb9c1b512016-09-06 20:57:50 +0000955 const bool internal = false;
956 const bool hardware = false;
957 const LazyBool skip_prologue = eLazyBoolCalculate;
958
Pavel Labath6ac84032017-02-27 11:05:34 +0000959 sb_bp = target_sp->CreateFuncRegexBreakpoint(
Kate Stoneb9c1b512016-09-06 20:57:50 +0000960 module_list.get(), comp_unit_list.get(), regexp, symbol_language,
961 skip_prologue, internal, hardware);
962 }
963
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000964 return LLDB_RECORD_RESULT(sb_bp);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000965}
966
967SBBreakpoint SBTarget::BreakpointCreateByAddress(addr_t address) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000968 LLDB_RECORD_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateByAddress,
969 (lldb::addr_t), address);
970
Kate Stoneb9c1b512016-09-06 20:57:50 +0000971 SBBreakpoint sb_bp;
972 TargetSP target_sp(GetSP());
973 if (target_sp) {
974 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
975 const bool hardware = false;
Pavel Labath6ac84032017-02-27 11:05:34 +0000976 sb_bp = target_sp->CreateBreakpoint(address, false, hardware);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000977 }
978
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000979 return LLDB_RECORD_RESULT(sb_bp);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000980}
981
982SBBreakpoint SBTarget::BreakpointCreateBySBAddress(SBAddress &sb_address) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000983 LLDB_RECORD_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateBySBAddress,
984 (lldb::SBAddress &), sb_address);
985
Kate Stoneb9c1b512016-09-06 20:57:50 +0000986 SBBreakpoint sb_bp;
987 TargetSP target_sp(GetSP());
988 if (!sb_address.IsValid()) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000989 return LLDB_RECORD_RESULT(sb_bp);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000990 }
991
992 if (target_sp) {
993 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
994 const bool hardware = false;
Pavel Labath6ac84032017-02-27 11:05:34 +0000995 sb_bp = target_sp->CreateBreakpoint(sb_address.ref(), false, hardware);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000996 }
997
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000998 return LLDB_RECORD_RESULT(sb_bp);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000999}
1000
1001lldb::SBBreakpoint
1002SBTarget::BreakpointCreateBySourceRegex(const char *source_regex,
1003 const lldb::SBFileSpec &source_file,
1004 const char *module_name) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001005 LLDB_RECORD_METHOD(lldb::SBBreakpoint, SBTarget,
1006 BreakpointCreateBySourceRegex,
1007 (const char *, const lldb::SBFileSpec &, const char *),
1008 source_regex, source_file, module_name);
1009
Kate Stoneb9c1b512016-09-06 20:57:50 +00001010 SBFileSpecList module_spec_list;
1011
1012 if (module_name && module_name[0]) {
Jonas Devlieghere8f3be7a2018-11-01 21:05:36 +00001013 module_spec_list.Append(FileSpec(module_name));
Kate Stoneb9c1b512016-09-06 20:57:50 +00001014 }
1015
1016 SBFileSpecList source_file_list;
1017 if (source_file.IsValid()) {
1018 source_file_list.Append(source_file);
1019 }
1020
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001021 return LLDB_RECORD_RESULT(BreakpointCreateBySourceRegex(
1022 source_regex, module_spec_list, source_file_list));
Kate Stoneb9c1b512016-09-06 20:57:50 +00001023}
1024
1025lldb::SBBreakpoint SBTarget::BreakpointCreateBySourceRegex(
1026 const char *source_regex, const SBFileSpecList &module_list,
1027 const lldb::SBFileSpecList &source_file_list) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001028 LLDB_RECORD_METHOD(lldb::SBBreakpoint, SBTarget,
1029 BreakpointCreateBySourceRegex,
1030 (const char *, const lldb::SBFileSpecList &,
1031 const lldb::SBFileSpecList &),
1032 source_regex, module_list, source_file_list);
1033
1034 return LLDB_RECORD_RESULT(BreakpointCreateBySourceRegex(
1035 source_regex, module_list, source_file_list, SBStringList()));
Kate Stoneb9c1b512016-09-06 20:57:50 +00001036}
1037
1038lldb::SBBreakpoint SBTarget::BreakpointCreateBySourceRegex(
1039 const char *source_regex, const SBFileSpecList &module_list,
1040 const lldb::SBFileSpecList &source_file_list,
1041 const SBStringList &func_names) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001042 LLDB_RECORD_METHOD(lldb::SBBreakpoint, SBTarget,
1043 BreakpointCreateBySourceRegex,
1044 (const char *, const lldb::SBFileSpecList &,
1045 const lldb::SBFileSpecList &, const lldb::SBStringList &),
1046 source_regex, module_list, source_file_list, func_names);
1047
Kate Stoneb9c1b512016-09-06 20:57:50 +00001048 SBBreakpoint sb_bp;
1049 TargetSP target_sp(GetSP());
1050 if (target_sp && source_regex && source_regex[0]) {
1051 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1052 const bool hardware = false;
1053 const LazyBool move_to_nearest_code = eLazyBoolCalculate;
Zachary Turner95eae422016-09-21 16:01:28 +00001054 RegularExpression regexp((llvm::StringRef(source_regex)));
Kate Stoneb9c1b512016-09-06 20:57:50 +00001055 std::unordered_set<std::string> func_names_set;
1056 for (size_t i = 0; i < func_names.GetSize(); i++) {
1057 func_names_set.insert(func_names.GetStringAtIndex(i));
1058 }
1059
Pavel Labath6ac84032017-02-27 11:05:34 +00001060 sb_bp = target_sp->CreateSourceRegexBreakpoint(
Kate Stoneb9c1b512016-09-06 20:57:50 +00001061 module_list.get(), source_file_list.get(), func_names_set, regexp,
1062 false, hardware, move_to_nearest_code);
1063 }
1064
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001065 return LLDB_RECORD_RESULT(sb_bp);
Kate Stoneb9c1b512016-09-06 20:57:50 +00001066}
1067
1068lldb::SBBreakpoint
1069SBTarget::BreakpointCreateForException(lldb::LanguageType language,
1070 bool catch_bp, bool throw_bp) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001071 LLDB_RECORD_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateForException,
1072 (lldb::LanguageType, bool, bool), language, catch_bp,
1073 throw_bp);
1074
Kate Stoneb9c1b512016-09-06 20:57:50 +00001075 SBBreakpoint sb_bp;
1076 TargetSP target_sp(GetSP());
1077 if (target_sp) {
1078 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1079 const bool hardware = false;
Pavel Labath6ac84032017-02-27 11:05:34 +00001080 sb_bp = target_sp->CreateExceptionBreakpoint(language, catch_bp, throw_bp,
Kate Stoneb9c1b512016-09-06 20:57:50 +00001081 hardware);
1082 }
1083
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001084 return LLDB_RECORD_RESULT(sb_bp);
Kate Stoneb9c1b512016-09-06 20:57:50 +00001085}
1086
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001087lldb::SBBreakpoint SBTarget::BreakpointCreateFromScript(
1088 const char *class_name, SBStructuredData &extra_args,
1089 const SBFileSpecList &module_list, const SBFileSpecList &file_list,
1090 bool request_hardware) {
1091 LLDB_RECORD_METHOD(
1092 lldb::SBBreakpoint, SBTarget, BreakpointCreateFromScript,
1093 (const char *, lldb::SBStructuredData &, const lldb::SBFileSpecList &,
1094 const lldb::SBFileSpecList &, bool),
1095 class_name, extra_args, module_list, file_list, request_hardware);
1096
Jim Ingham3815e702018-09-13 21:35:32 +00001097 SBBreakpoint sb_bp;
1098 TargetSP target_sp(GetSP());
1099 if (target_sp) {
1100 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1101 Status error;
Jonas Devlieghere581af8b2019-03-07 22:47:13 +00001102
Jim Ingham3815e702018-09-13 21:35:32 +00001103 StructuredData::ObjectSP obj_sp = extra_args.m_impl_up->GetObjectSP();
1104 sb_bp =
1105 target_sp->CreateScriptedBreakpoint(class_name,
1106 module_list.get(),
1107 file_list.get(),
1108 false, /* internal */
1109 request_hardware,
1110 obj_sp,
1111 &error);
1112 }
Jim Ingham3815e702018-09-13 21:35:32 +00001113
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001114 return LLDB_RECORD_RESULT(sb_bp);
Jim Ingham3815e702018-09-13 21:35:32 +00001115}
1116
Kate Stoneb9c1b512016-09-06 20:57:50 +00001117uint32_t SBTarget::GetNumBreakpoints() const {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001118 LLDB_RECORD_METHOD_CONST_NO_ARGS(uint32_t, SBTarget, GetNumBreakpoints);
1119
Kate Stoneb9c1b512016-09-06 20:57:50 +00001120 TargetSP target_sp(GetSP());
1121 if (target_sp) {
1122 // The breakpoint list is thread safe, no need to lock
1123 return target_sp->GetBreakpointList().GetSize();
1124 }
1125 return 0;
1126}
1127
1128SBBreakpoint SBTarget::GetBreakpointAtIndex(uint32_t idx) const {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001129 LLDB_RECORD_METHOD_CONST(lldb::SBBreakpoint, SBTarget, GetBreakpointAtIndex,
1130 (uint32_t), idx);
1131
Kate Stoneb9c1b512016-09-06 20:57:50 +00001132 SBBreakpoint sb_breakpoint;
1133 TargetSP target_sp(GetSP());
1134 if (target_sp) {
1135 // The breakpoint list is thread safe, no need to lock
Pavel Labath6ac84032017-02-27 11:05:34 +00001136 sb_breakpoint = target_sp->GetBreakpointList().GetBreakpointAtIndex(idx);
Kate Stoneb9c1b512016-09-06 20:57:50 +00001137 }
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001138 return LLDB_RECORD_RESULT(sb_breakpoint);
Kate Stoneb9c1b512016-09-06 20:57:50 +00001139}
1140
1141bool SBTarget::BreakpointDelete(break_id_t bp_id) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001142 LLDB_RECORD_METHOD(bool, SBTarget, BreakpointDelete, (lldb::break_id_t),
1143 bp_id);
1144
Kate Stoneb9c1b512016-09-06 20:57:50 +00001145 bool result = false;
1146 TargetSP target_sp(GetSP());
1147 if (target_sp) {
1148 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1149 result = target_sp->RemoveBreakpointByID(bp_id);
1150 }
1151
Kate Stoneb9c1b512016-09-06 20:57:50 +00001152 return result;
1153}
1154
1155SBBreakpoint SBTarget::FindBreakpointByID(break_id_t bp_id) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001156 LLDB_RECORD_METHOD(lldb::SBBreakpoint, SBTarget, FindBreakpointByID,
1157 (lldb::break_id_t), bp_id);
1158
Kate Stoneb9c1b512016-09-06 20:57:50 +00001159 SBBreakpoint sb_breakpoint;
1160 TargetSP target_sp(GetSP());
1161 if (target_sp && bp_id != LLDB_INVALID_BREAK_ID) {
1162 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
Pavel Labath6ac84032017-02-27 11:05:34 +00001163 sb_breakpoint = target_sp->GetBreakpointByID(bp_id);
Kate Stoneb9c1b512016-09-06 20:57:50 +00001164 }
1165
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001166 return LLDB_RECORD_RESULT(sb_breakpoint);
Kate Stoneb9c1b512016-09-06 20:57:50 +00001167}
1168
Jim Inghamff9a91e2016-09-21 01:21:19 +00001169bool SBTarget::FindBreakpointsByName(const char *name,
1170 SBBreakpointList &bkpts) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001171 LLDB_RECORD_METHOD(bool, SBTarget, FindBreakpointsByName,
1172 (const char *, lldb::SBBreakpointList &), name, bkpts);
1173
Jim Inghamff9a91e2016-09-21 01:21:19 +00001174 TargetSP target_sp(GetSP());
1175 if (target_sp) {
1176 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1177 BreakpointList bkpt_list(false);
1178 bool is_valid =
1179 target_sp->GetBreakpointList().FindBreakpointsByName(name, bkpt_list);
1180 if (!is_valid)
1181 return false;
1182 for (BreakpointSP bkpt_sp : bkpt_list.Breakpoints()) {
1183 bkpts.AppendByID(bkpt_sp->GetID());
1184 }
1185 }
1186 return true;
1187}
1188
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001189void SBTarget::GetBreakpointNames(SBStringList &names) {
1190 LLDB_RECORD_METHOD(void, SBTarget, GetBreakpointNames, (lldb::SBStringList &),
1191 names);
1192
Jim Inghamb842f2e2017-09-14 20:22:49 +00001193 names.Clear();
1194
1195 TargetSP target_sp(GetSP());
1196 if (target_sp) {
1197 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1198
1199 std::vector<std::string> name_vec;
1200 target_sp->GetBreakpointNames(name_vec);
1201 for (auto name : name_vec)
1202 names.AppendString(name.c_str());
1203 }
1204}
1205
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001206void SBTarget::DeleteBreakpointName(const char *name) {
1207 LLDB_RECORD_METHOD(void, SBTarget, DeleteBreakpointName, (const char *),
1208 name);
1209
Jim Inghamb842f2e2017-09-14 20:22:49 +00001210 TargetSP target_sp(GetSP());
1211 if (target_sp) {
1212 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
Jim Inghamb842f2e2017-09-14 20:22:49 +00001213 target_sp->DeleteBreakpointName(ConstString(name));
Jim Inghamb842f2e2017-09-14 20:22:49 +00001214 }
1215}
1216
Kate Stoneb9c1b512016-09-06 20:57:50 +00001217bool SBTarget::EnableAllBreakpoints() {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001218 LLDB_RECORD_METHOD_NO_ARGS(bool, SBTarget, EnableAllBreakpoints);
1219
Kate Stoneb9c1b512016-09-06 20:57:50 +00001220 TargetSP target_sp(GetSP());
1221 if (target_sp) {
1222 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
Jim Inghamb842f2e2017-09-14 20:22:49 +00001223 target_sp->EnableAllowedBreakpoints();
Kate Stoneb9c1b512016-09-06 20:57:50 +00001224 return true;
1225 }
1226 return false;
1227}
1228
1229bool SBTarget::DisableAllBreakpoints() {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001230 LLDB_RECORD_METHOD_NO_ARGS(bool, SBTarget, DisableAllBreakpoints);
1231
Kate Stoneb9c1b512016-09-06 20:57:50 +00001232 TargetSP target_sp(GetSP());
1233 if (target_sp) {
1234 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
Jim Inghamb842f2e2017-09-14 20:22:49 +00001235 target_sp->DisableAllowedBreakpoints();
Kate Stoneb9c1b512016-09-06 20:57:50 +00001236 return true;
1237 }
1238 return false;
1239}
1240
1241bool SBTarget::DeleteAllBreakpoints() {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001242 LLDB_RECORD_METHOD_NO_ARGS(bool, SBTarget, DeleteAllBreakpoints);
1243
Kate Stoneb9c1b512016-09-06 20:57:50 +00001244 TargetSP target_sp(GetSP());
1245 if (target_sp) {
1246 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
Jim Inghamb842f2e2017-09-14 20:22:49 +00001247 target_sp->RemoveAllowedBreakpoints();
Kate Stoneb9c1b512016-09-06 20:57:50 +00001248 return true;
1249 }
1250 return false;
1251}
1252
Jim Ingham01f16662016-09-14 19:07:35 +00001253lldb::SBError SBTarget::BreakpointsCreateFromFile(SBFileSpec &source_file,
1254 SBBreakpointList &new_bps) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001255 LLDB_RECORD_METHOD(lldb::SBError, SBTarget, BreakpointsCreateFromFile,
1256 (lldb::SBFileSpec &, lldb::SBBreakpointList &),
1257 source_file, new_bps);
1258
Jim Ingham3acdf382016-09-22 22:20:28 +00001259 SBStringList empty_name_list;
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001260 return LLDB_RECORD_RESULT(
1261 BreakpointsCreateFromFile(source_file, empty_name_list, new_bps));
Jim Ingham3acdf382016-09-22 22:20:28 +00001262}
1263
1264lldb::SBError SBTarget::BreakpointsCreateFromFile(SBFileSpec &source_file,
1265 SBStringList &matching_names,
1266 SBBreakpointList &new_bps) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001267 LLDB_RECORD_METHOD(
1268 lldb::SBError, SBTarget, BreakpointsCreateFromFile,
1269 (lldb::SBFileSpec &, lldb::SBStringList &, lldb::SBBreakpointList &),
1270 source_file, matching_names, new_bps);
1271
Jim Ingham01f16662016-09-14 19:07:35 +00001272 SBError sberr;
1273 TargetSP target_sp(GetSP());
1274 if (!target_sp) {
1275 sberr.SetErrorString(
1276 "BreakpointCreateFromFile called with invalid target.");
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001277 return LLDB_RECORD_RESULT(sberr);
Jim Ingham01f16662016-09-14 19:07:35 +00001278 }
1279 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1280
1281 BreakpointIDList bp_ids;
Jim Ingham3acdf382016-09-22 22:20:28 +00001282
1283 std::vector<std::string> name_vector;
1284 size_t num_names = matching_names.GetSize();
1285 for (size_t i = 0; i < num_names; i++)
1286 name_vector.push_back(matching_names.GetStringAtIndex(i));
1287
1288 sberr.ref() = target_sp->CreateBreakpointsFromFile(source_file.ref(),
1289 name_vector, bp_ids);
Jim Ingham01f16662016-09-14 19:07:35 +00001290 if (sberr.Fail())
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001291 return LLDB_RECORD_RESULT(sberr);
Jim Ingham01f16662016-09-14 19:07:35 +00001292
1293 size_t num_bkpts = bp_ids.GetSize();
1294 for (size_t i = 0; i < num_bkpts; i++) {
1295 BreakpointID bp_id = bp_ids.GetBreakpointIDAtIndex(i);
1296 new_bps.AppendByID(bp_id.GetBreakpointID());
1297 }
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001298 return LLDB_RECORD_RESULT(sberr);
Jim Ingham01f16662016-09-14 19:07:35 +00001299}
1300
1301lldb::SBError SBTarget::BreakpointsWriteToFile(SBFileSpec &dest_file) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001302 LLDB_RECORD_METHOD(lldb::SBError, SBTarget, BreakpointsWriteToFile,
1303 (lldb::SBFileSpec &), dest_file);
1304
Jim Ingham01f16662016-09-14 19:07:35 +00001305 SBError sberr;
1306 TargetSP target_sp(GetSP());
1307 if (!target_sp) {
1308 sberr.SetErrorString("BreakpointWriteToFile called with invalid target.");
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001309 return LLDB_RECORD_RESULT(sberr);
Jim Ingham01f16662016-09-14 19:07:35 +00001310 }
1311 SBBreakpointList bkpt_list(*this);
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001312 return LLDB_RECORD_RESULT(BreakpointsWriteToFile(dest_file, bkpt_list));
Jim Ingham01f16662016-09-14 19:07:35 +00001313}
1314
1315lldb::SBError SBTarget::BreakpointsWriteToFile(SBFileSpec &dest_file,
Jim Ingham2d3628e2016-09-22 23:42:42 +00001316 SBBreakpointList &bkpt_list,
1317 bool append) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001318 LLDB_RECORD_METHOD(lldb::SBError, SBTarget, BreakpointsWriteToFile,
1319 (lldb::SBFileSpec &, lldb::SBBreakpointList &, bool),
1320 dest_file, bkpt_list, append);
1321
Jim Ingham01f16662016-09-14 19:07:35 +00001322 SBError sberr;
1323 TargetSP target_sp(GetSP());
1324 if (!target_sp) {
1325 sberr.SetErrorString("BreakpointWriteToFile called with invalid target.");
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001326 return LLDB_RECORD_RESULT(sberr);
Jim Ingham01f16662016-09-14 19:07:35 +00001327 }
1328
1329 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1330 BreakpointIDList bp_id_list;
1331 bkpt_list.CopyToBreakpointIDList(bp_id_list);
Jim Ingham2d3628e2016-09-22 23:42:42 +00001332 sberr.ref() = target_sp->SerializeBreakpointsToFile(dest_file.ref(),
1333 bp_id_list, append);
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001334 return LLDB_RECORD_RESULT(sberr);
Jim Ingham01f16662016-09-14 19:07:35 +00001335}
1336
Kate Stoneb9c1b512016-09-06 20:57:50 +00001337uint32_t SBTarget::GetNumWatchpoints() const {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001338 LLDB_RECORD_METHOD_CONST_NO_ARGS(uint32_t, SBTarget, GetNumWatchpoints);
1339
Kate Stoneb9c1b512016-09-06 20:57:50 +00001340 TargetSP target_sp(GetSP());
1341 if (target_sp) {
1342 // The watchpoint list is thread safe, no need to lock
1343 return target_sp->GetWatchpointList().GetSize();
1344 }
1345 return 0;
1346}
1347
1348SBWatchpoint SBTarget::GetWatchpointAtIndex(uint32_t idx) const {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001349 LLDB_RECORD_METHOD_CONST(lldb::SBWatchpoint, SBTarget, GetWatchpointAtIndex,
1350 (uint32_t), idx);
1351
Kate Stoneb9c1b512016-09-06 20:57:50 +00001352 SBWatchpoint sb_watchpoint;
1353 TargetSP target_sp(GetSP());
1354 if (target_sp) {
1355 // The watchpoint list is thread safe, no need to lock
1356 sb_watchpoint.SetSP(target_sp->GetWatchpointList().GetByIndex(idx));
1357 }
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001358 return LLDB_RECORD_RESULT(sb_watchpoint);
Kate Stoneb9c1b512016-09-06 20:57:50 +00001359}
1360
1361bool SBTarget::DeleteWatchpoint(watch_id_t wp_id) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001362 LLDB_RECORD_METHOD(bool, SBTarget, DeleteWatchpoint, (lldb::watch_id_t),
1363 wp_id);
1364
Kate Stoneb9c1b512016-09-06 20:57:50 +00001365
1366 bool result = false;
1367 TargetSP target_sp(GetSP());
1368 if (target_sp) {
1369 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1370 std::unique_lock<std::recursive_mutex> lock;
1371 target_sp->GetWatchpointList().GetListMutex(lock);
1372 result = target_sp->RemoveWatchpointByID(wp_id);
1373 }
1374
Kate Stoneb9c1b512016-09-06 20:57:50 +00001375 return result;
1376}
1377
1378SBWatchpoint SBTarget::FindWatchpointByID(lldb::watch_id_t wp_id) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001379 LLDB_RECORD_METHOD(lldb::SBWatchpoint, SBTarget, FindWatchpointByID,
1380 (lldb::watch_id_t), wp_id);
1381
Kate Stoneb9c1b512016-09-06 20:57:50 +00001382
1383 SBWatchpoint sb_watchpoint;
1384 lldb::WatchpointSP watchpoint_sp;
1385 TargetSP target_sp(GetSP());
1386 if (target_sp && wp_id != LLDB_INVALID_WATCH_ID) {
1387 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1388 std::unique_lock<std::recursive_mutex> lock;
1389 target_sp->GetWatchpointList().GetListMutex(lock);
1390 watchpoint_sp = target_sp->GetWatchpointList().FindByID(wp_id);
1391 sb_watchpoint.SetSP(watchpoint_sp);
1392 }
1393
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001394 return LLDB_RECORD_RESULT(sb_watchpoint);
Kate Stoneb9c1b512016-09-06 20:57:50 +00001395}
1396
1397lldb::SBWatchpoint SBTarget::WatchAddress(lldb::addr_t addr, size_t size,
1398 bool read, bool write,
1399 SBError &error) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001400 LLDB_RECORD_METHOD(lldb::SBWatchpoint, SBTarget, WatchAddress,
1401 (lldb::addr_t, size_t, bool, bool, lldb::SBError &), addr,
1402 size, read, write, error);
1403
Kate Stoneb9c1b512016-09-06 20:57:50 +00001404 SBWatchpoint sb_watchpoint;
1405 lldb::WatchpointSP watchpoint_sp;
1406 TargetSP target_sp(GetSP());
1407 if (target_sp && (read || write) && addr != LLDB_INVALID_ADDRESS &&
1408 size > 0) {
1409 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1410 uint32_t watch_type = 0;
1411 if (read)
1412 watch_type |= LLDB_WATCH_TYPE_READ;
1413 if (write)
1414 watch_type |= LLDB_WATCH_TYPE_WRITE;
1415 if (watch_type == 0) {
1416 error.SetErrorString(
1417 "Can't create a watchpoint that is neither read nor write.");
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001418 return LLDB_RECORD_RESULT(sb_watchpoint);
Kate Stoneb9c1b512016-09-06 20:57:50 +00001419 }
1420
1421 // Target::CreateWatchpoint() is thread safe.
Zachary Turner97206d52017-05-12 04:51:55 +00001422 Status cw_error;
Kate Stoneb9c1b512016-09-06 20:57:50 +00001423 // This API doesn't take in a type, so we can't figure out what it is.
1424 CompilerType *type = NULL;
1425 watchpoint_sp =
1426 target_sp->CreateWatchpoint(addr, size, type, watch_type, cw_error);
1427 error.SetError(cw_error);
1428 sb_watchpoint.SetSP(watchpoint_sp);
1429 }
1430
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001431 return LLDB_RECORD_RESULT(sb_watchpoint);
Kate Stoneb9c1b512016-09-06 20:57:50 +00001432}
1433
1434bool SBTarget::EnableAllWatchpoints() {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001435 LLDB_RECORD_METHOD_NO_ARGS(bool, SBTarget, EnableAllWatchpoints);
1436
Kate Stoneb9c1b512016-09-06 20:57:50 +00001437 TargetSP target_sp(GetSP());
1438 if (target_sp) {
1439 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1440 std::unique_lock<std::recursive_mutex> lock;
1441 target_sp->GetWatchpointList().GetListMutex(lock);
1442 target_sp->EnableAllWatchpoints();
1443 return true;
1444 }
1445 return false;
1446}
1447
1448bool SBTarget::DisableAllWatchpoints() {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001449 LLDB_RECORD_METHOD_NO_ARGS(bool, SBTarget, DisableAllWatchpoints);
1450
Kate Stoneb9c1b512016-09-06 20:57:50 +00001451 TargetSP target_sp(GetSP());
1452 if (target_sp) {
1453 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1454 std::unique_lock<std::recursive_mutex> lock;
1455 target_sp->GetWatchpointList().GetListMutex(lock);
1456 target_sp->DisableAllWatchpoints();
1457 return true;
1458 }
1459 return false;
1460}
1461
1462SBValue SBTarget::CreateValueFromAddress(const char *name, SBAddress addr,
1463 SBType type) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001464 LLDB_RECORD_METHOD(lldb::SBValue, SBTarget, CreateValueFromAddress,
1465 (const char *, lldb::SBAddress, lldb::SBType), name, addr,
1466 type);
1467
Kate Stoneb9c1b512016-09-06 20:57:50 +00001468 SBValue sb_value;
1469 lldb::ValueObjectSP new_value_sp;
1470 if (IsValid() && name && *name && addr.IsValid() && type.IsValid()) {
1471 lldb::addr_t load_addr(addr.GetLoadAddress(*this));
1472 ExecutionContext exe_ctx(
1473 ExecutionContextRef(ExecutionContext(m_opaque_sp.get(), false)));
1474 CompilerType ast_type(type.GetSP()->GetCompilerType(true));
1475 new_value_sp = ValueObject::CreateValueObjectFromAddress(name, load_addr,
1476 exe_ctx, ast_type);
1477 }
1478 sb_value.SetSP(new_value_sp);
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001479 return LLDB_RECORD_RESULT(sb_value);
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001480}
1481
Kate Stoneb9c1b512016-09-06 20:57:50 +00001482lldb::SBValue SBTarget::CreateValueFromData(const char *name, lldb::SBData data,
1483 lldb::SBType type) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001484 LLDB_RECORD_METHOD(lldb::SBValue, SBTarget, CreateValueFromData,
1485 (const char *, lldb::SBData, lldb::SBType), name, data,
1486 type);
1487
Kate Stoneb9c1b512016-09-06 20:57:50 +00001488 SBValue sb_value;
1489 lldb::ValueObjectSP new_value_sp;
1490 if (IsValid() && name && *name && data.IsValid() && type.IsValid()) {
1491 DataExtractorSP extractor(*data);
1492 ExecutionContext exe_ctx(
1493 ExecutionContextRef(ExecutionContext(m_opaque_sp.get(), false)));
1494 CompilerType ast_type(type.GetSP()->GetCompilerType(true));
1495 new_value_sp = ValueObject::CreateValueObjectFromData(name, *extractor,
1496 exe_ctx, ast_type);
1497 }
1498 sb_value.SetSP(new_value_sp);
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001499 return LLDB_RECORD_RESULT(sb_value);
Greg Claytone14e1922012-12-04 02:22:16 +00001500}
1501
Kate Stoneb9c1b512016-09-06 20:57:50 +00001502lldb::SBValue SBTarget::CreateValueFromExpression(const char *name,
1503 const char *expr) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001504 LLDB_RECORD_METHOD(lldb::SBValue, SBTarget, CreateValueFromExpression,
1505 (const char *, const char *), name, expr);
1506
Kate Stoneb9c1b512016-09-06 20:57:50 +00001507 SBValue sb_value;
1508 lldb::ValueObjectSP new_value_sp;
1509 if (IsValid() && name && *name && expr && *expr) {
1510 ExecutionContext exe_ctx(
1511 ExecutionContextRef(ExecutionContext(m_opaque_sp.get(), false)));
1512 new_value_sp =
1513 ValueObject::CreateValueObjectFromExpression(name, expr, exe_ctx);
1514 }
1515 sb_value.SetSP(new_value_sp);
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001516 return LLDB_RECORD_RESULT(sb_value);
Kate Stoneb9c1b512016-09-06 20:57:50 +00001517}
1518
1519bool SBTarget::DeleteAllWatchpoints() {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001520 LLDB_RECORD_METHOD_NO_ARGS(bool, SBTarget, DeleteAllWatchpoints);
1521
Kate Stoneb9c1b512016-09-06 20:57:50 +00001522 TargetSP target_sp(GetSP());
1523 if (target_sp) {
1524 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1525 std::unique_lock<std::recursive_mutex> lock;
1526 target_sp->GetWatchpointList().GetListMutex(lock);
1527 target_sp->RemoveAllWatchpoints();
1528 return true;
1529 }
1530 return false;
1531}
1532
Alexander Polyakov3e7b9db2018-08-07 20:23:57 +00001533void SBTarget::AppendImageSearchPath(const char *from, const char *to,
1534 lldb::SBError &error) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001535 LLDB_RECORD_METHOD(void, SBTarget, AppendImageSearchPath,
1536 (const char *, const char *, lldb::SBError &), from, to,
1537 error);
1538
Alexander Polyakov3e7b9db2018-08-07 20:23:57 +00001539 TargetSP target_sp(GetSP());
1540 if (!target_sp)
1541 return error.SetErrorString("invalid target");
1542
1543 const ConstString csFrom(from), csTo(to);
1544 if (!csFrom)
1545 return error.SetErrorString("<from> path can't be empty");
1546 if (!csTo)
1547 return error.SetErrorString("<to> path can't be empty");
1548
Alexander Polyakov3e7b9db2018-08-07 20:23:57 +00001549 target_sp->GetImageSearchPathList().Append(csFrom, csTo, true);
1550}
1551
Kate Stoneb9c1b512016-09-06 20:57:50 +00001552lldb::SBModule SBTarget::AddModule(const char *path, const char *triple,
1553 const char *uuid_cstr) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001554 LLDB_RECORD_METHOD(lldb::SBModule, SBTarget, AddModule,
1555 (const char *, const char *, const char *), path, triple,
1556 uuid_cstr);
1557
1558 return LLDB_RECORD_RESULT(AddModule(path, triple, uuid_cstr, NULL));
Kate Stoneb9c1b512016-09-06 20:57:50 +00001559}
1560
1561lldb::SBModule SBTarget::AddModule(const char *path, const char *triple,
1562 const char *uuid_cstr, const char *symfile) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001563 LLDB_RECORD_METHOD(lldb::SBModule, SBTarget, AddModule,
1564 (const char *, const char *, const char *, const char *),
1565 path, triple, uuid_cstr, symfile);
1566
Kate Stoneb9c1b512016-09-06 20:57:50 +00001567 lldb::SBModule sb_module;
1568 TargetSP target_sp(GetSP());
1569 if (target_sp) {
1570 ModuleSpec module_spec;
1571 if (path)
Jonas Devlieghere8f3be7a2018-11-01 21:05:36 +00001572 module_spec.GetFileSpec().SetFile(path, FileSpec::Style::native);
Kate Stoneb9c1b512016-09-06 20:57:50 +00001573
1574 if (uuid_cstr)
Pavel Labatha174bcb2018-06-21 15:24:39 +00001575 module_spec.GetUUID().SetFromStringRef(uuid_cstr);
Kate Stoneb9c1b512016-09-06 20:57:50 +00001576
1577 if (triple)
Pavel Labath7263f1b2017-10-31 10:56:03 +00001578 module_spec.GetArchitecture() = Platform::GetAugmentedArchSpec(
1579 target_sp->GetPlatform().get(), triple);
Kate Stoneb9c1b512016-09-06 20:57:50 +00001580 else
1581 module_spec.GetArchitecture() = target_sp->GetArchitecture();
1582
1583 if (symfile)
Jonas Devlieghere8f3be7a2018-11-01 21:05:36 +00001584 module_spec.GetSymbolFileSpec().SetFile(symfile, FileSpec::Style::native);
Kate Stoneb9c1b512016-09-06 20:57:50 +00001585
1586 sb_module.SetSP(target_sp->GetSharedModule(module_spec));
1587 }
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001588 return LLDB_RECORD_RESULT(sb_module);
Kate Stoneb9c1b512016-09-06 20:57:50 +00001589}
1590
1591lldb::SBModule SBTarget::AddModule(const SBModuleSpec &module_spec) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001592 LLDB_RECORD_METHOD(lldb::SBModule, SBTarget, AddModule,
1593 (const lldb::SBModuleSpec &), module_spec);
1594
Kate Stoneb9c1b512016-09-06 20:57:50 +00001595 lldb::SBModule sb_module;
1596 TargetSP target_sp(GetSP());
1597 if (target_sp)
Jonas Devlieghered5b44032019-02-13 06:25:41 +00001598 sb_module.SetSP(target_sp->GetSharedModule(*module_spec.m_opaque_up));
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001599 return LLDB_RECORD_RESULT(sb_module);
Kate Stoneb9c1b512016-09-06 20:57:50 +00001600}
1601
1602bool SBTarget::AddModule(lldb::SBModule &module) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001603 LLDB_RECORD_METHOD(bool, SBTarget, AddModule, (lldb::SBModule &), module);
1604
Kate Stoneb9c1b512016-09-06 20:57:50 +00001605 TargetSP target_sp(GetSP());
1606 if (target_sp) {
1607 target_sp->GetImages().AppendIfNeeded(module.GetSP());
1608 return true;
1609 }
1610 return false;
1611}
1612
1613uint32_t SBTarget::GetNumModules() const {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001614 LLDB_RECORD_METHOD_CONST_NO_ARGS(uint32_t, SBTarget, GetNumModules);
1615
Kate Stoneb9c1b512016-09-06 20:57:50 +00001616 uint32_t num = 0;
1617 TargetSP target_sp(GetSP());
1618 if (target_sp) {
1619 // The module list is thread safe, no need to lock
1620 num = target_sp->GetImages().GetSize();
1621 }
1622
Kate Stoneb9c1b512016-09-06 20:57:50 +00001623 return num;
1624}
1625
1626void SBTarget::Clear() {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001627 LLDB_RECORD_METHOD_NO_ARGS(void, SBTarget, Clear);
1628
Kate Stoneb9c1b512016-09-06 20:57:50 +00001629 m_opaque_sp.reset();
1630}
1631
1632SBModule SBTarget::FindModule(const SBFileSpec &sb_file_spec) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001633 LLDB_RECORD_METHOD(lldb::SBModule, SBTarget, FindModule,
1634 (const lldb::SBFileSpec &), sb_file_spec);
1635
Kate Stoneb9c1b512016-09-06 20:57:50 +00001636 SBModule sb_module;
1637 TargetSP target_sp(GetSP());
1638 if (target_sp && sb_file_spec.IsValid()) {
1639 ModuleSpec module_spec(*sb_file_spec);
1640 // The module list is thread safe, no need to lock
1641 sb_module.SetSP(target_sp->GetImages().FindFirstModule(module_spec));
1642 }
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001643 return LLDB_RECORD_RESULT(sb_module);
Kate Stoneb9c1b512016-09-06 20:57:50 +00001644}
1645
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001646SBSymbolContextList SBTarget::FindCompileUnits(const SBFileSpec &sb_file_spec) {
1647 LLDB_RECORD_METHOD(lldb::SBSymbolContextList, SBTarget, FindCompileUnits,
1648 (const lldb::SBFileSpec &), sb_file_spec);
1649
Alexander Polyakovda0c0812018-07-03 14:22:44 +00001650 SBSymbolContextList sb_sc_list;
1651 const TargetSP target_sp(GetSP());
1652 if (target_sp && sb_file_spec.IsValid()) {
1653 const bool append = true;
1654 target_sp->GetImages().FindCompileUnits(*sb_file_spec,
1655 append, *sb_sc_list);
1656 }
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001657 return LLDB_RECORD_RESULT(sb_sc_list);
Alexander Polyakovda0c0812018-07-03 14:22:44 +00001658}
1659
Kate Stoneb9c1b512016-09-06 20:57:50 +00001660lldb::ByteOrder SBTarget::GetByteOrder() {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001661 LLDB_RECORD_METHOD_NO_ARGS(lldb::ByteOrder, SBTarget, GetByteOrder);
1662
Kate Stoneb9c1b512016-09-06 20:57:50 +00001663 TargetSP target_sp(GetSP());
1664 if (target_sp)
1665 return target_sp->GetArchitecture().GetByteOrder();
1666 return eByteOrderInvalid;
1667}
1668
1669const char *SBTarget::GetTriple() {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001670 LLDB_RECORD_METHOD_NO_ARGS(const char *, SBTarget, GetTriple);
1671
Kate Stoneb9c1b512016-09-06 20:57:50 +00001672 TargetSP target_sp(GetSP());
1673 if (target_sp) {
1674 std::string triple(target_sp->GetArchitecture().GetTriple().str());
Adrian Prantl05097242018-04-30 16:49:04 +00001675 // Unique the string so we don't run into ownership issues since the const
1676 // strings put the string into the string pool once and the strings never
1677 // comes out
Kate Stoneb9c1b512016-09-06 20:57:50 +00001678 ConstString const_triple(triple.c_str());
1679 return const_triple.GetCString();
1680 }
1681 return NULL;
1682}
1683
1684uint32_t SBTarget::GetDataByteSize() {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001685 LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBTarget, GetDataByteSize);
1686
Kate Stoneb9c1b512016-09-06 20:57:50 +00001687 TargetSP target_sp(GetSP());
1688 if (target_sp) {
1689 return target_sp->GetArchitecture().GetDataByteSize();
1690 }
1691 return 0;
1692}
1693
1694uint32_t SBTarget::GetCodeByteSize() {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001695 LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBTarget, GetCodeByteSize);
1696
Kate Stoneb9c1b512016-09-06 20:57:50 +00001697 TargetSP target_sp(GetSP());
1698 if (target_sp) {
1699 return target_sp->GetArchitecture().GetCodeByteSize();
1700 }
1701 return 0;
1702}
1703
1704uint32_t SBTarget::GetAddressByteSize() {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001705 LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBTarget, GetAddressByteSize);
1706
Kate Stoneb9c1b512016-09-06 20:57:50 +00001707 TargetSP target_sp(GetSP());
1708 if (target_sp)
1709 return target_sp->GetArchitecture().GetAddressByteSize();
1710 return sizeof(void *);
1711}
1712
1713SBModule SBTarget::GetModuleAtIndex(uint32_t idx) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001714 LLDB_RECORD_METHOD(lldb::SBModule, SBTarget, GetModuleAtIndex, (uint32_t),
1715 idx);
1716
Kate Stoneb9c1b512016-09-06 20:57:50 +00001717 SBModule sb_module;
1718 ModuleSP module_sp;
1719 TargetSP target_sp(GetSP());
1720 if (target_sp) {
1721 // The module list is thread safe, no need to lock
1722 module_sp = target_sp->GetImages().GetModuleAtIndex(idx);
1723 sb_module.SetSP(module_sp);
1724 }
1725
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001726 return LLDB_RECORD_RESULT(sb_module);
Kate Stoneb9c1b512016-09-06 20:57:50 +00001727}
1728
1729bool SBTarget::RemoveModule(lldb::SBModule module) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001730 LLDB_RECORD_METHOD(bool, SBTarget, RemoveModule, (lldb::SBModule), module);
1731
Kate Stoneb9c1b512016-09-06 20:57:50 +00001732 TargetSP target_sp(GetSP());
1733 if (target_sp)
1734 return target_sp->GetImages().Remove(module.GetSP());
1735 return false;
1736}
1737
1738SBBroadcaster SBTarget::GetBroadcaster() const {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001739 LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::SBBroadcaster, SBTarget,
1740 GetBroadcaster);
1741
Kate Stoneb9c1b512016-09-06 20:57:50 +00001742
1743 TargetSP target_sp(GetSP());
1744 SBBroadcaster broadcaster(target_sp.get(), false);
1745
Kate Stoneb9c1b512016-09-06 20:57:50 +00001746
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001747 return LLDB_RECORD_RESULT(broadcaster);
Kate Stoneb9c1b512016-09-06 20:57:50 +00001748}
1749
1750bool SBTarget::GetDescription(SBStream &description,
1751 lldb::DescriptionLevel description_level) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001752 LLDB_RECORD_METHOD(bool, SBTarget, GetDescription,
1753 (lldb::SBStream &, lldb::DescriptionLevel), description,
1754 description_level);
1755
Kate Stoneb9c1b512016-09-06 20:57:50 +00001756 Stream &strm = description.ref();
1757
1758 TargetSP target_sp(GetSP());
1759 if (target_sp) {
1760 target_sp->Dump(&strm, description_level);
1761 } else
1762 strm.PutCString("No value");
1763
1764 return true;
1765}
1766
1767lldb::SBSymbolContextList SBTarget::FindFunctions(const char *name,
1768 uint32_t name_type_mask) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001769 LLDB_RECORD_METHOD(lldb::SBSymbolContextList, SBTarget, FindFunctions,
1770 (const char *, uint32_t), name, name_type_mask);
1771
Kate Stoneb9c1b512016-09-06 20:57:50 +00001772 lldb::SBSymbolContextList sb_sc_list;
Zachary Turner117b1fa2018-10-25 20:45:40 +00001773 if (!name | !name[0])
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001774 return LLDB_RECORD_RESULT(sb_sc_list);
Zachary Turner117b1fa2018-10-25 20:45:40 +00001775
1776 TargetSP target_sp(GetSP());
1777 if (!target_sp)
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001778 return LLDB_RECORD_RESULT(sb_sc_list);
Zachary Turner117b1fa2018-10-25 20:45:40 +00001779
1780 const bool symbols_ok = true;
1781 const bool inlines_ok = true;
1782 const bool append = true;
1783 FunctionNameType mask = static_cast<FunctionNameType>(name_type_mask);
1784 target_sp->GetImages().FindFunctions(ConstString(name), mask, symbols_ok,
1785 inlines_ok, append, *sb_sc_list);
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001786 return LLDB_RECORD_RESULT(sb_sc_list);
Jim Ingham763b2b22015-07-07 22:12:17 +00001787}
Greg Claytone14e1922012-12-04 02:22:16 +00001788
Kate Stoneb9c1b512016-09-06 20:57:50 +00001789lldb::SBSymbolContextList SBTarget::FindGlobalFunctions(const char *name,
1790 uint32_t max_matches,
1791 MatchType matchtype) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001792 LLDB_RECORD_METHOD(lldb::SBSymbolContextList, SBTarget, FindGlobalFunctions,
1793 (const char *, uint32_t, lldb::MatchType), name,
1794 max_matches, matchtype);
1795
Kate Stoneb9c1b512016-09-06 20:57:50 +00001796 lldb::SBSymbolContextList sb_sc_list;
1797 if (name && name[0]) {
Zachary Turner95eae422016-09-21 16:01:28 +00001798 llvm::StringRef name_ref(name);
Kate Stoneb9c1b512016-09-06 20:57:50 +00001799 TargetSP target_sp(GetSP());
1800 if (target_sp) {
1801 std::string regexstr;
1802 switch (matchtype) {
1803 case eMatchTypeRegex:
Zachary Turner95eae422016-09-21 16:01:28 +00001804 target_sp->GetImages().FindFunctions(RegularExpression(name_ref), true,
Kate Stoneb9c1b512016-09-06 20:57:50 +00001805 true, true, *sb_sc_list);
1806 break;
1807 case eMatchTypeStartsWith:
1808 regexstr = llvm::Regex::escape(name) + ".*";
Zachary Turner95eae422016-09-21 16:01:28 +00001809 target_sp->GetImages().FindFunctions(RegularExpression(regexstr), true,
1810 true, true, *sb_sc_list);
Kate Stoneb9c1b512016-09-06 20:57:50 +00001811 break;
1812 default:
1813 target_sp->GetImages().FindFunctions(ConstString(name),
1814 eFunctionNameTypeAny, true, true,
1815 true, *sb_sc_list);
1816 break;
1817 }
1818 }
1819 }
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001820 return LLDB_RECORD_RESULT(sb_sc_list);
Kate Stoneb9c1b512016-09-06 20:57:50 +00001821}
1822
1823lldb::SBType SBTarget::FindFirstType(const char *typename_cstr) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001824 LLDB_RECORD_METHOD(lldb::SBType, SBTarget, FindFirstType, (const char *),
1825 typename_cstr);
1826
Kate Stoneb9c1b512016-09-06 20:57:50 +00001827 TargetSP target_sp(GetSP());
1828 if (typename_cstr && typename_cstr[0] && target_sp) {
1829 ConstString const_typename(typename_cstr);
1830 SymbolContext sc;
1831 const bool exact_match = false;
1832
1833 const ModuleList &module_list = target_sp->GetImages();
1834 size_t count = module_list.GetSize();
1835 for (size_t idx = 0; idx < count; idx++) {
1836 ModuleSP module_sp(module_list.GetModuleAtIndex(idx));
1837 if (module_sp) {
1838 TypeSP type_sp(
1839 module_sp->FindFirstType(sc, const_typename, exact_match));
1840 if (type_sp)
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001841 return LLDB_RECORD_RESULT(SBType(type_sp));
Kate Stoneb9c1b512016-09-06 20:57:50 +00001842 }
1843 }
1844
Adrian Prantl05097242018-04-30 16:49:04 +00001845 // Didn't find the type in the symbols; try the Objective-C runtime if one
1846 // is installed
Kate Stoneb9c1b512016-09-06 20:57:50 +00001847
1848 ProcessSP process_sp(target_sp->GetProcessSP());
1849
1850 if (process_sp) {
1851 ObjCLanguageRuntime *objc_language_runtime =
1852 process_sp->GetObjCLanguageRuntime();
1853
1854 if (objc_language_runtime) {
1855 DeclVendor *objc_decl_vendor = objc_language_runtime->GetDeclVendor();
1856
1857 if (objc_decl_vendor) {
1858 std::vector<clang::NamedDecl *> decls;
1859
1860 if (objc_decl_vendor->FindDecls(const_typename, true, 1, decls) > 0) {
1861 if (CompilerType type = ClangASTContext::GetTypeForDecl(decls[0])) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001862 return LLDB_RECORD_RESULT(SBType(type));
Kate Stoneb9c1b512016-09-06 20:57:50 +00001863 }
1864 }
1865 }
1866 }
1867 }
1868
1869 // No matches, search for basic typename matches
1870 ClangASTContext *clang_ast = target_sp->GetScratchClangASTContext();
1871 if (clang_ast)
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001872 return LLDB_RECORD_RESULT(SBType(ClangASTContext::GetBasicType(
1873 clang_ast->getASTContext(), const_typename)));
Kate Stoneb9c1b512016-09-06 20:57:50 +00001874 }
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001875 return LLDB_RECORD_RESULT(SBType());
Kate Stoneb9c1b512016-09-06 20:57:50 +00001876}
1877
1878SBType SBTarget::GetBasicType(lldb::BasicType type) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001879 LLDB_RECORD_METHOD(lldb::SBType, SBTarget, GetBasicType, (lldb::BasicType),
1880 type);
1881
Kate Stoneb9c1b512016-09-06 20:57:50 +00001882 TargetSP target_sp(GetSP());
1883 if (target_sp) {
1884 ClangASTContext *clang_ast = target_sp->GetScratchClangASTContext();
1885 if (clang_ast)
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001886 return LLDB_RECORD_RESULT(SBType(
1887 ClangASTContext::GetBasicType(clang_ast->getASTContext(), type)));
Kate Stoneb9c1b512016-09-06 20:57:50 +00001888 }
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001889 return LLDB_RECORD_RESULT(SBType());
Kate Stoneb9c1b512016-09-06 20:57:50 +00001890}
1891
1892lldb::SBTypeList SBTarget::FindTypes(const char *typename_cstr) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001893 LLDB_RECORD_METHOD(lldb::SBTypeList, SBTarget, FindTypes, (const char *),
1894 typename_cstr);
1895
Kate Stoneb9c1b512016-09-06 20:57:50 +00001896 SBTypeList sb_type_list;
1897 TargetSP target_sp(GetSP());
1898 if (typename_cstr && typename_cstr[0] && target_sp) {
1899 ModuleList &images = target_sp->GetImages();
1900 ConstString const_typename(typename_cstr);
1901 bool exact_match = false;
Kate Stoneb9c1b512016-09-06 20:57:50 +00001902 TypeList type_list;
1903 llvm::DenseSet<SymbolFile *> searched_symbol_files;
1904 uint32_t num_matches =
Zachary Turner576495e2019-01-14 22:41:21 +00001905 images.FindTypes(nullptr, const_typename, exact_match, UINT32_MAX,
Kate Stoneb9c1b512016-09-06 20:57:50 +00001906 searched_symbol_files, type_list);
1907
1908 if (num_matches > 0) {
1909 for (size_t idx = 0; idx < num_matches; idx++) {
1910 TypeSP type_sp(type_list.GetTypeAtIndex(idx));
1911 if (type_sp)
1912 sb_type_list.Append(SBType(type_sp));
1913 }
1914 }
1915
1916 // Try the Objective-C runtime if one is installed
1917
1918 ProcessSP process_sp(target_sp->GetProcessSP());
1919
1920 if (process_sp) {
1921 ObjCLanguageRuntime *objc_language_runtime =
1922 process_sp->GetObjCLanguageRuntime();
1923
1924 if (objc_language_runtime) {
1925 DeclVendor *objc_decl_vendor = objc_language_runtime->GetDeclVendor();
1926
1927 if (objc_decl_vendor) {
1928 std::vector<clang::NamedDecl *> decls;
1929
1930 if (objc_decl_vendor->FindDecls(const_typename, true, 1, decls) > 0) {
1931 for (clang::NamedDecl *decl : decls) {
1932 if (CompilerType type = ClangASTContext::GetTypeForDecl(decl)) {
1933 sb_type_list.Append(SBType(type));
1934 }
1935 }
1936 }
1937 }
1938 }
1939 }
1940
1941 if (sb_type_list.GetSize() == 0) {
1942 // No matches, search for basic typename matches
1943 ClangASTContext *clang_ast = target_sp->GetScratchClangASTContext();
1944 if (clang_ast)
1945 sb_type_list.Append(SBType(ClangASTContext::GetBasicType(
1946 clang_ast->getASTContext(), const_typename)));
1947 }
1948 }
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001949 return LLDB_RECORD_RESULT(sb_type_list);
Kate Stoneb9c1b512016-09-06 20:57:50 +00001950}
1951
1952SBValueList SBTarget::FindGlobalVariables(const char *name,
1953 uint32_t max_matches) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001954 LLDB_RECORD_METHOD(lldb::SBValueList, SBTarget, FindGlobalVariables,
1955 (const char *, uint32_t), name, max_matches);
1956
Kate Stoneb9c1b512016-09-06 20:57:50 +00001957 SBValueList sb_value_list;
1958
1959 TargetSP target_sp(GetSP());
1960 if (name && target_sp) {
1961 VariableList variable_list;
Kate Stoneb9c1b512016-09-06 20:57:50 +00001962 const uint32_t match_count = target_sp->GetImages().FindGlobalVariables(
Pavel Labath34cda142018-05-31 09:46:26 +00001963 ConstString(name), max_matches, variable_list);
Kate Stoneb9c1b512016-09-06 20:57:50 +00001964
1965 if (match_count > 0) {
1966 ExecutionContextScope *exe_scope = target_sp->GetProcessSP().get();
1967 if (exe_scope == NULL)
1968 exe_scope = target_sp.get();
1969 for (uint32_t i = 0; i < match_count; ++i) {
1970 lldb::ValueObjectSP valobj_sp(ValueObjectVariable::Create(
1971 exe_scope, variable_list.GetVariableAtIndex(i)));
1972 if (valobj_sp)
1973 sb_value_list.Append(SBValue(valobj_sp));
1974 }
1975 }
1976 }
1977
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001978 return LLDB_RECORD_RESULT(sb_value_list);
Kate Stoneb9c1b512016-09-06 20:57:50 +00001979}
1980
1981SBValueList SBTarget::FindGlobalVariables(const char *name,
1982 uint32_t max_matches,
1983 MatchType matchtype) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00001984 LLDB_RECORD_METHOD(lldb::SBValueList, SBTarget, FindGlobalVariables,
1985 (const char *, uint32_t, lldb::MatchType), name,
1986 max_matches, matchtype);
1987
Kate Stoneb9c1b512016-09-06 20:57:50 +00001988 SBValueList sb_value_list;
1989
1990 TargetSP target_sp(GetSP());
1991 if (name && target_sp) {
Zachary Turner95eae422016-09-21 16:01:28 +00001992 llvm::StringRef name_ref(name);
Kate Stoneb9c1b512016-09-06 20:57:50 +00001993 VariableList variable_list;
Kate Stoneb9c1b512016-09-06 20:57:50 +00001994
1995 std::string regexstr;
1996 uint32_t match_count;
1997 switch (matchtype) {
1998 case eMatchTypeNormal:
1999 match_count = target_sp->GetImages().FindGlobalVariables(
Pavel Labath34cda142018-05-31 09:46:26 +00002000 ConstString(name), max_matches, variable_list);
Kate Stoneb9c1b512016-09-06 20:57:50 +00002001 break;
2002 case eMatchTypeRegex:
2003 match_count = target_sp->GetImages().FindGlobalVariables(
Pavel Labath34cda142018-05-31 09:46:26 +00002004 RegularExpression(name_ref), max_matches, variable_list);
Kate Stoneb9c1b512016-09-06 20:57:50 +00002005 break;
2006 case eMatchTypeStartsWith:
2007 regexstr = llvm::Regex::escape(name) + ".*";
2008 match_count = target_sp->GetImages().FindGlobalVariables(
Pavel Labath34cda142018-05-31 09:46:26 +00002009 RegularExpression(regexstr), max_matches, variable_list);
Kate Stoneb9c1b512016-09-06 20:57:50 +00002010 break;
2011 }
2012
2013 if (match_count > 0) {
2014 ExecutionContextScope *exe_scope = target_sp->GetProcessSP().get();
2015 if (exe_scope == NULL)
2016 exe_scope = target_sp.get();
2017 for (uint32_t i = 0; i < match_count; ++i) {
2018 lldb::ValueObjectSP valobj_sp(ValueObjectVariable::Create(
2019 exe_scope, variable_list.GetVariableAtIndex(i)));
2020 if (valobj_sp)
2021 sb_value_list.Append(SBValue(valobj_sp));
2022 }
2023 }
2024 }
2025
Jonas Devliegherebaf56642019-03-06 00:06:00 +00002026 return LLDB_RECORD_RESULT(sb_value_list);
Kate Stoneb9c1b512016-09-06 20:57:50 +00002027}
2028
2029lldb::SBValue SBTarget::FindFirstGlobalVariable(const char *name) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00002030 LLDB_RECORD_METHOD(lldb::SBValue, SBTarget, FindFirstGlobalVariable,
2031 (const char *), name);
2032
Kate Stoneb9c1b512016-09-06 20:57:50 +00002033 SBValueList sb_value_list(FindGlobalVariables(name, 1));
2034 if (sb_value_list.IsValid() && sb_value_list.GetSize() > 0)
Jonas Devliegherebaf56642019-03-06 00:06:00 +00002035 return LLDB_RECORD_RESULT(sb_value_list.GetValueAtIndex(0));
2036 return LLDB_RECORD_RESULT(SBValue());
Kate Stoneb9c1b512016-09-06 20:57:50 +00002037}
2038
2039SBSourceManager SBTarget::GetSourceManager() {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00002040 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBSourceManager, SBTarget, GetSourceManager);
2041
Kate Stoneb9c1b512016-09-06 20:57:50 +00002042 SBSourceManager source_manager(*this);
Jonas Devliegherebaf56642019-03-06 00:06:00 +00002043 return LLDB_RECORD_RESULT(source_manager);
Kate Stoneb9c1b512016-09-06 20:57:50 +00002044}
2045
2046lldb::SBInstructionList SBTarget::ReadInstructions(lldb::SBAddress base_addr,
2047 uint32_t count) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00002048 LLDB_RECORD_METHOD(lldb::SBInstructionList, SBTarget, ReadInstructions,
2049 (lldb::SBAddress, uint32_t), base_addr, count);
2050
2051 return LLDB_RECORD_RESULT(ReadInstructions(base_addr, count, NULL));
Kate Stoneb9c1b512016-09-06 20:57:50 +00002052}
2053
2054lldb::SBInstructionList SBTarget::ReadInstructions(lldb::SBAddress base_addr,
2055 uint32_t count,
2056 const char *flavor_string) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00002057 LLDB_RECORD_METHOD(lldb::SBInstructionList, SBTarget, ReadInstructions,
2058 (lldb::SBAddress, uint32_t, const char *), base_addr,
2059 count, flavor_string);
2060
Kate Stoneb9c1b512016-09-06 20:57:50 +00002061 SBInstructionList sb_instructions;
2062
2063 TargetSP target_sp(GetSP());
2064 if (target_sp) {
2065 Address *addr_ptr = base_addr.get();
2066
2067 if (addr_ptr) {
2068 DataBufferHeap data(
2069 target_sp->GetArchitecture().GetMaximumOpcodeByteSize() * count, 0);
2070 bool prefer_file_cache = false;
Zachary Turner97206d52017-05-12 04:51:55 +00002071 lldb_private::Status error;
Kate Stoneb9c1b512016-09-06 20:57:50 +00002072 lldb::addr_t load_addr = LLDB_INVALID_ADDRESS;
2073 const size_t bytes_read =
2074 target_sp->ReadMemory(*addr_ptr, prefer_file_cache, data.GetBytes(),
2075 data.GetByteSize(), error, &load_addr);
2076 const bool data_from_file = load_addr == LLDB_INVALID_ADDRESS;
2077 sb_instructions.SetDisassembler(Disassembler::DisassembleBytes(
2078 target_sp->GetArchitecture(), NULL, flavor_string, *addr_ptr,
2079 data.GetBytes(), bytes_read, count, data_from_file));
2080 }
2081 }
2082
Jonas Devliegherebaf56642019-03-06 00:06:00 +00002083 return LLDB_RECORD_RESULT(sb_instructions);
Kate Stoneb9c1b512016-09-06 20:57:50 +00002084}
2085
2086lldb::SBInstructionList SBTarget::GetInstructions(lldb::SBAddress base_addr,
2087 const void *buf,
2088 size_t size) {
2089 return GetInstructionsWithFlavor(base_addr, NULL, buf, size);
2090}
2091
2092lldb::SBInstructionList
2093SBTarget::GetInstructionsWithFlavor(lldb::SBAddress base_addr,
2094 const char *flavor_string, const void *buf,
2095 size_t size) {
2096 SBInstructionList sb_instructions;
2097
2098 TargetSP target_sp(GetSP());
2099 if (target_sp) {
2100 Address addr;
2101
2102 if (base_addr.get())
2103 addr = *base_addr.get();
2104
2105 const bool data_from_file = true;
2106
2107 sb_instructions.SetDisassembler(Disassembler::DisassembleBytes(
2108 target_sp->GetArchitecture(), NULL, flavor_string, addr, buf, size,
2109 UINT32_MAX, data_from_file));
2110 }
2111
2112 return sb_instructions;
2113}
2114
2115lldb::SBInstructionList SBTarget::GetInstructions(lldb::addr_t base_addr,
2116 const void *buf,
2117 size_t size) {
2118 return GetInstructionsWithFlavor(ResolveLoadAddress(base_addr), NULL, buf,
2119 size);
2120}
2121
2122lldb::SBInstructionList
2123SBTarget::GetInstructionsWithFlavor(lldb::addr_t base_addr,
2124 const char *flavor_string, const void *buf,
2125 size_t size) {
2126 return GetInstructionsWithFlavor(ResolveLoadAddress(base_addr), flavor_string,
2127 buf, size);
2128}
2129
2130SBError SBTarget::SetSectionLoadAddress(lldb::SBSection section,
2131 lldb::addr_t section_base_addr) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00002132 LLDB_RECORD_METHOD(lldb::SBError, SBTarget, SetSectionLoadAddress,
2133 (lldb::SBSection, lldb::addr_t), section,
2134 section_base_addr);
2135
Kate Stoneb9c1b512016-09-06 20:57:50 +00002136 SBError sb_error;
2137 TargetSP target_sp(GetSP());
2138 if (target_sp) {
2139 if (!section.IsValid()) {
2140 sb_error.SetErrorStringWithFormat("invalid section");
2141 } else {
2142 SectionSP section_sp(section.GetSP());
2143 if (section_sp) {
2144 if (section_sp->IsThreadSpecific()) {
2145 sb_error.SetErrorString(
2146 "thread specific sections are not yet supported");
2147 } else {
2148 ProcessSP process_sp(target_sp->GetProcessSP());
2149 if (target_sp->SetSectionLoadAddress(section_sp, section_base_addr)) {
2150 ModuleSP module_sp(section_sp->GetModule());
2151 if (module_sp) {
2152 ModuleList module_list;
2153 module_list.Append(module_sp);
2154 target_sp->ModulesDidLoad(module_list);
2155 }
2156 // Flush info in the process (stack frames, etc)
2157 if (process_sp)
2158 process_sp->Flush();
2159 }
2160 }
2161 }
2162 }
2163 } else {
2164 sb_error.SetErrorString("invalid target");
2165 }
Jonas Devliegherebaf56642019-03-06 00:06:00 +00002166 return LLDB_RECORD_RESULT(sb_error);
Kate Stoneb9c1b512016-09-06 20:57:50 +00002167}
2168
2169SBError SBTarget::ClearSectionLoadAddress(lldb::SBSection section) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00002170 LLDB_RECORD_METHOD(lldb::SBError, SBTarget, ClearSectionLoadAddress,
2171 (lldb::SBSection), section);
2172
Kate Stoneb9c1b512016-09-06 20:57:50 +00002173 SBError sb_error;
2174
2175 TargetSP target_sp(GetSP());
2176 if (target_sp) {
2177 if (!section.IsValid()) {
2178 sb_error.SetErrorStringWithFormat("invalid section");
2179 } else {
2180 SectionSP section_sp(section.GetSP());
2181 if (section_sp) {
2182 ProcessSP process_sp(target_sp->GetProcessSP());
2183 if (target_sp->SetSectionUnloaded(section_sp)) {
2184 ModuleSP module_sp(section_sp->GetModule());
2185 if (module_sp) {
2186 ModuleList module_list;
2187 module_list.Append(module_sp);
2188 target_sp->ModulesDidUnload(module_list, false);
2189 }
2190 // Flush info in the process (stack frames, etc)
2191 if (process_sp)
2192 process_sp->Flush();
2193 }
2194 } else {
2195 sb_error.SetErrorStringWithFormat("invalid section");
2196 }
2197 }
2198 } else {
2199 sb_error.SetErrorStringWithFormat("invalid target");
2200 }
Jonas Devliegherebaf56642019-03-06 00:06:00 +00002201 return LLDB_RECORD_RESULT(sb_error);
Kate Stoneb9c1b512016-09-06 20:57:50 +00002202}
2203
2204SBError SBTarget::SetModuleLoadAddress(lldb::SBModule module,
2205 int64_t slide_offset) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00002206 LLDB_RECORD_METHOD(lldb::SBError, SBTarget, SetModuleLoadAddress,
2207 (lldb::SBModule, int64_t), module, slide_offset);
2208
Kate Stoneb9c1b512016-09-06 20:57:50 +00002209 SBError sb_error;
2210
2211 TargetSP target_sp(GetSP());
2212 if (target_sp) {
2213 ModuleSP module_sp(module.GetSP());
2214 if (module_sp) {
2215 bool changed = false;
2216 if (module_sp->SetLoadAddress(*target_sp, slide_offset, true, changed)) {
2217 // The load was successful, make sure that at least some sections
2218 // changed before we notify that our module was loaded.
2219 if (changed) {
2220 ModuleList module_list;
2221 module_list.Append(module_sp);
2222 target_sp->ModulesDidLoad(module_list);
2223 // Flush info in the process (stack frames, etc)
2224 ProcessSP process_sp(target_sp->GetProcessSP());
2225 if (process_sp)
2226 process_sp->Flush();
2227 }
2228 }
2229 } else {
2230 sb_error.SetErrorStringWithFormat("invalid module");
2231 }
2232
2233 } else {
2234 sb_error.SetErrorStringWithFormat("invalid target");
2235 }
Jonas Devliegherebaf56642019-03-06 00:06:00 +00002236 return LLDB_RECORD_RESULT(sb_error);
Kate Stoneb9c1b512016-09-06 20:57:50 +00002237}
2238
2239SBError SBTarget::ClearModuleLoadAddress(lldb::SBModule module) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00002240 LLDB_RECORD_METHOD(lldb::SBError, SBTarget, ClearModuleLoadAddress,
2241 (lldb::SBModule), module);
2242
Kate Stoneb9c1b512016-09-06 20:57:50 +00002243 SBError sb_error;
2244
2245 char path[PATH_MAX];
2246 TargetSP target_sp(GetSP());
2247 if (target_sp) {
2248 ModuleSP module_sp(module.GetSP());
2249 if (module_sp) {
2250 ObjectFile *objfile = module_sp->GetObjectFile();
2251 if (objfile) {
2252 SectionList *section_list = objfile->GetSectionList();
2253 if (section_list) {
2254 ProcessSP process_sp(target_sp->GetProcessSP());
2255
2256 bool changed = false;
2257 const size_t num_sections = section_list->GetSize();
2258 for (size_t sect_idx = 0; sect_idx < num_sections; ++sect_idx) {
2259 SectionSP section_sp(section_list->GetSectionAtIndex(sect_idx));
2260 if (section_sp)
2261 changed |= target_sp->SetSectionUnloaded(section_sp);
2262 }
2263 if (changed) {
2264 ModuleList module_list;
2265 module_list.Append(module_sp);
2266 target_sp->ModulesDidUnload(module_list, false);
2267 // Flush info in the process (stack frames, etc)
2268 ProcessSP process_sp(target_sp->GetProcessSP());
2269 if (process_sp)
2270 process_sp->Flush();
2271 }
2272 } else {
2273 module_sp->GetFileSpec().GetPath(path, sizeof(path));
2274 sb_error.SetErrorStringWithFormat("no sections in object file '%s'",
2275 path);
2276 }
2277 } else {
2278 module_sp->GetFileSpec().GetPath(path, sizeof(path));
2279 sb_error.SetErrorStringWithFormat("no object file for module '%s'",
2280 path);
2281 }
2282 } else {
2283 sb_error.SetErrorStringWithFormat("invalid module");
2284 }
2285 } else {
2286 sb_error.SetErrorStringWithFormat("invalid target");
2287 }
Jonas Devliegherebaf56642019-03-06 00:06:00 +00002288 return LLDB_RECORD_RESULT(sb_error);
Kate Stoneb9c1b512016-09-06 20:57:50 +00002289}
2290
2291lldb::SBSymbolContextList SBTarget::FindSymbols(const char *name,
2292 lldb::SymbolType symbol_type) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00002293 LLDB_RECORD_METHOD(lldb::SBSymbolContextList, SBTarget, FindSymbols,
2294 (const char *, lldb::SymbolType), name, symbol_type);
2295
Kate Stoneb9c1b512016-09-06 20:57:50 +00002296 SBSymbolContextList sb_sc_list;
2297 if (name && name[0]) {
2298 TargetSP target_sp(GetSP());
2299 if (target_sp) {
2300 bool append = true;
2301 target_sp->GetImages().FindSymbolsWithNameAndType(
2302 ConstString(name), symbol_type, *sb_sc_list, append);
2303 }
2304 }
Jonas Devliegherebaf56642019-03-06 00:06:00 +00002305 return LLDB_RECORD_RESULT(sb_sc_list);
Kate Stoneb9c1b512016-09-06 20:57:50 +00002306}
2307
2308lldb::SBValue SBTarget::EvaluateExpression(const char *expr) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00002309 LLDB_RECORD_METHOD(lldb::SBValue, SBTarget, EvaluateExpression,
2310 (const char *), expr);
2311
Kate Stoneb9c1b512016-09-06 20:57:50 +00002312 TargetSP target_sp(GetSP());
2313 if (!target_sp)
Jonas Devliegherebaf56642019-03-06 00:06:00 +00002314 return LLDB_RECORD_RESULT(SBValue());
Kate Stoneb9c1b512016-09-06 20:57:50 +00002315
2316 SBExpressionOptions options;
2317 lldb::DynamicValueType fetch_dynamic_value =
2318 target_sp->GetPreferDynamicValue();
2319 options.SetFetchDynamicValue(fetch_dynamic_value);
2320 options.SetUnwindOnError(true);
Jonas Devliegherebaf56642019-03-06 00:06:00 +00002321 return LLDB_RECORD_RESULT(EvaluateExpression(expr, options));
Kate Stoneb9c1b512016-09-06 20:57:50 +00002322}
2323
2324lldb::SBValue SBTarget::EvaluateExpression(const char *expr,
2325 const SBExpressionOptions &options) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00002326 LLDB_RECORD_METHOD(lldb::SBValue, SBTarget, EvaluateExpression,
2327 (const char *, const lldb::SBExpressionOptions &), expr,
2328 options);
2329
Saleem Abdulrasool6010f972016-04-22 23:08:34 +00002330#if !defined(LLDB_DISABLE_PYTHON)
Kate Stoneb9c1b512016-09-06 20:57:50 +00002331 Log *expr_log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS));
Saleem Abdulrasool6010f972016-04-22 23:08:34 +00002332#endif
Kate Stoneb9c1b512016-09-06 20:57:50 +00002333 SBValue expr_result;
2334 ExpressionResults exe_results = eExpressionSetupError;
2335 ValueObjectSP expr_value_sp;
2336 TargetSP target_sp(GetSP());
2337 StackFrame *frame = NULL;
2338 if (target_sp) {
2339 if (expr == NULL || expr[0] == '\0') {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00002340 return LLDB_RECORD_RESULT(expr_result);
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002341 }
Kate Stoneb9c1b512016-09-06 20:57:50 +00002342
2343 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
2344 ExecutionContext exe_ctx(m_opaque_sp.get());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002345
Kate Stoneb9c1b512016-09-06 20:57:50 +00002346
2347 frame = exe_ctx.GetFramePtr();
2348 Target *target = exe_ctx.GetTargetPtr();
2349
2350 if (target) {
2351#ifdef LLDB_CONFIGURATION_DEBUG
2352 StreamString frame_description;
2353 if (frame)
2354 frame->DumpUsingSettingsFormat(&frame_description);
Jim Ingham8f7db522016-12-15 00:30:30 +00002355 llvm::PrettyStackTraceFormat stack_trace(
Kate Stoneb9c1b512016-09-06 20:57:50 +00002356 "SBTarget::EvaluateExpression (expr = \"%s\", fetch_dynamic_value = "
2357 "%u) %s",
2358 expr, options.GetFetchDynamicValue(),
Zachary Turnerc1564272016-11-16 21:15:24 +00002359 frame_description.GetString().str().c_str());
Kate Stoneb9c1b512016-09-06 20:57:50 +00002360#endif
2361 exe_results =
2362 target->EvaluateExpression(expr, frame, expr_value_sp, options.ref());
2363
2364 expr_result.SetSP(expr_value_sp, options.GetFetchDynamicValue());
Kate Stoneb9c1b512016-09-06 20:57:50 +00002365 }
2366 }
2367#ifndef LLDB_DISABLE_PYTHON
2368 if (expr_log)
2369 expr_log->Printf("** [SBTarget::EvaluateExpression] Expression result is "
2370 "%s, summary %s **",
2371 expr_result.GetValue(), expr_result.GetSummary());
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002372#endif
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002373
Jonas Devliegherebaf56642019-03-06 00:06:00 +00002374 return LLDB_RECORD_RESULT(expr_result);
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002375}
2376
Kate Stoneb9c1b512016-09-06 20:57:50 +00002377lldb::addr_t SBTarget::GetStackRedZoneSize() {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00002378 LLDB_RECORD_METHOD_NO_ARGS(lldb::addr_t, SBTarget, GetStackRedZoneSize);
2379
Kate Stoneb9c1b512016-09-06 20:57:50 +00002380 TargetSP target_sp(GetSP());
2381 if (target_sp) {
2382 ABISP abi_sp;
2383 ProcessSP process_sp(target_sp->GetProcessSP());
2384 if (process_sp)
2385 abi_sp = process_sp->GetABI();
2386 else
Jason Molenda43294c92017-06-29 02:57:03 +00002387 abi_sp = ABI::FindPlugin(ProcessSP(), target_sp->GetArchitecture());
Kate Stoneb9c1b512016-09-06 20:57:50 +00002388 if (abi_sp)
2389 return abi_sp->GetRedZoneSize();
2390 }
2391 return 0;
Greg Clayton13fbb992013-02-01 00:47:49 +00002392}
Ilia K8f37ca52015-02-13 14:31:06 +00002393
Kate Stoneb9c1b512016-09-06 20:57:50 +00002394lldb::SBLaunchInfo SBTarget::GetLaunchInfo() const {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00002395 LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::SBLaunchInfo, SBTarget, GetLaunchInfo);
2396
Kate Stoneb9c1b512016-09-06 20:57:50 +00002397 lldb::SBLaunchInfo launch_info(NULL);
2398 TargetSP target_sp(GetSP());
2399 if (target_sp)
Pavel Labath62930e52018-01-10 11:57:31 +00002400 launch_info.set_ref(m_opaque_sp->GetProcessLaunchInfo());
Jonas Devliegherebaf56642019-03-06 00:06:00 +00002401 return LLDB_RECORD_RESULT(launch_info);
Ilia K8f37ca52015-02-13 14:31:06 +00002402}
2403
Kate Stoneb9c1b512016-09-06 20:57:50 +00002404void SBTarget::SetLaunchInfo(const lldb::SBLaunchInfo &launch_info) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +00002405 LLDB_RECORD_METHOD(void, SBTarget, SetLaunchInfo,
2406 (const lldb::SBLaunchInfo &), launch_info);
2407
Kate Stoneb9c1b512016-09-06 20:57:50 +00002408 TargetSP target_sp(GetSP());
2409 if (target_sp)
2410 m_opaque_sp->SetProcessLaunchInfo(launch_info.ref());
Ilia K8f37ca52015-02-13 14:31:06 +00002411}