blob: 66d375aa4578cb5e66de6ef43c8e097275555f3a [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001//===-- SBTarget.cpp --------------------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
Eli Friedman4c5de692010-06-09 07:44:37 +000010#include "lldb/API/SBTarget.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"
Greg Claytonfe356d32011-06-21 01:34:41 +000026#include "lldb/API/SBSymbolContextList.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000027#include "lldb/Breakpoint/BreakpointID.h"
28#include "lldb/Breakpoint/BreakpointIDList.h"
29#include "lldb/Breakpoint/BreakpointList.h"
30#include "lldb/Breakpoint/BreakpointLocation.h"
31#include "lldb/Core/Address.h"
32#include "lldb/Core/AddressResolver.h"
33#include "lldb/Core/AddressResolverName.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000034#include "lldb/Core/ArchSpec.h"
35#include "lldb/Core/Debugger.h"
36#include "lldb/Core/Disassembler.h"
Caroline Ticeceb6b132010-10-26 03:11:13 +000037#include "lldb/Core/Log.h"
Greg Clayton1f746072012-08-29 21:13:06 +000038#include "lldb/Core/Module.h"
39#include "lldb/Core/ModuleSpec.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000040#include "lldb/Core/RegularExpression.h"
Kate Stoneb9c1b512016-09-06 20:57:50 +000041#include "lldb/Core/STLUtils.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000042#include "lldb/Core/SearchFilter.h"
Greg Clayton1f746072012-08-29 21:13:06 +000043#include "lldb/Core/Section.h"
Enrico Granata347c2aa2013-10-08 21:49:02 +000044#include "lldb/Core/ValueObjectConstResult.h"
Greg Claytondea8cb42011-06-29 22:09:02 +000045#include "lldb/Core/ValueObjectList.h"
46#include "lldb/Core/ValueObjectVariable.h"
47#include "lldb/Host/FileSpec.h"
Greg Clayton7fb56d02011-02-01 01:31:41 +000048#include "lldb/Host/Host.h"
Greg Claytondea8cb42011-06-29 22:09:02 +000049#include "lldb/Interpreter/Args.h"
Zachary Turnera78bd7f2015-03-03 23:11:11 +000050#include "lldb/Symbol/ClangASTContext.h"
51#include "lldb/Symbol/DeclVendor.h"
Greg Clayton1f746072012-08-29 21:13:06 +000052#include "lldb/Symbol/ObjectFile.h"
Greg Claytonae088e52016-02-10 21:28:13 +000053#include "lldb/Symbol/SymbolFile.h"
Enrico Granata6f3533f2011-07-29 19:53:35 +000054#include "lldb/Symbol/SymbolVendor.h"
Greg Claytondea8cb42011-06-29 22:09:02 +000055#include "lldb/Symbol/VariableList.h"
Zachary Turner32abc6e2015-03-03 19:23:09 +000056#include "lldb/Target/ABI.h"
Jim Ingham0e0984e2015-09-02 01:06:46 +000057#include "lldb/Target/Language.h"
Jim Inghamfab10e82012-03-06 00:37:27 +000058#include "lldb/Target/LanguageRuntime.h"
Zachary Turnera78bd7f2015-03-03 23:11:11 +000059#include "lldb/Target/ObjCLanguageRuntime.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000060#include "lldb/Target/Process.h"
Enrico Granatab10e0032015-03-04 21:33:45 +000061#include "lldb/Target/StackFrame.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000062#include "lldb/Target/Target.h"
63#include "lldb/Target/TargetList.h"
64
Chris Lattner30fdc8d2010-06-08 16:52:24 +000065#include "../source/Commands/CommandObjectBreakpoint.h"
Kate Stoneb9c1b512016-09-06 20:57:50 +000066#include "lldb/Interpreter/CommandReturnObject.h"
Carlo Kok0fd6fd42014-09-19 19:38:19 +000067#include "llvm/Support/Regex.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000068
Chris Lattner30fdc8d2010-06-08 16:52:24 +000069using namespace lldb;
70using namespace lldb_private;
71
72#define DEFAULT_DISASM_BYTE_SIZE 32
73
Oleksiy Vyalov37386142015-02-10 22:49:57 +000074namespace {
75
Kate Stoneb9c1b512016-09-06 20:57:50 +000076Error AttachToProcess(ProcessAttachInfo &attach_info, Target &target) {
77 std::lock_guard<std::recursive_mutex> guard(target.GetAPIMutex());
Oleksiy Vyalov37386142015-02-10 22:49:57 +000078
Kate Stoneb9c1b512016-09-06 20:57:50 +000079 auto process_sp = target.GetProcessSP();
80 if (process_sp) {
81 const auto state = process_sp->GetState();
82 if (process_sp->IsAlive() && state == eStateConnected) {
83 // If we are already connected, then we have already specified the
84 // listener, so if a valid listener is supplied, we need to error out
85 // to let the client know.
86 if (attach_info.GetListener())
87 return Error("process is connected and already has a listener, pass "
88 "empty listener");
Oleksiy Vyalov37386142015-02-10 22:49:57 +000089 }
Kate Stoneb9c1b512016-09-06 20:57:50 +000090 }
Oleksiy Vyalov37386142015-02-10 22:49:57 +000091
Kate Stoneb9c1b512016-09-06 20:57:50 +000092 return target.Attach(attach_info, nullptr);
Oleksiy Vyalov37386142015-02-10 22:49:57 +000093}
94
Kate Stoneb9c1b512016-09-06 20:57:50 +000095} // namespace
Oleksiy Vyalov37386142015-02-10 22:49:57 +000096
Chris Lattner30fdc8d2010-06-08 16:52:24 +000097//----------------------------------------------------------------------
98// SBTarget constructor
99//----------------------------------------------------------------------
Kate Stoneb9c1b512016-09-06 20:57:50 +0000100SBTarget::SBTarget() : m_opaque_sp() {}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000101
Kate Stoneb9c1b512016-09-06 20:57:50 +0000102SBTarget::SBTarget(const SBTarget &rhs) : m_opaque_sp(rhs.m_opaque_sp) {}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000103
Kate Stoneb9c1b512016-09-06 20:57:50 +0000104SBTarget::SBTarget(const TargetSP &target_sp) : m_opaque_sp(target_sp) {}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000105
Kate Stoneb9c1b512016-09-06 20:57:50 +0000106const SBTarget &SBTarget::operator=(const SBTarget &rhs) {
107 if (this != &rhs)
108 m_opaque_sp = rhs.m_opaque_sp;
109 return *this;
Greg Claytonefabb122010-11-05 23:17:00 +0000110}
111
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000112//----------------------------------------------------------------------
113// Destructor
114//----------------------------------------------------------------------
Kate Stoneb9c1b512016-09-06 20:57:50 +0000115SBTarget::~SBTarget() {}
116
117bool SBTarget::EventIsTargetEvent(const SBEvent &event) {
118 return Target::TargetEventData::GetEventDataFromEvent(event.get()) != NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000119}
120
Kate Stoneb9c1b512016-09-06 20:57:50 +0000121SBTarget SBTarget::GetTargetFromEvent(const SBEvent &event) {
122 return Target::TargetEventData::GetTargetFromEvent(event.get());
Ilia Keb2c19a2015-03-10 21:59:55 +0000123}
124
Kate Stoneb9c1b512016-09-06 20:57:50 +0000125uint32_t SBTarget::GetNumModulesFromEvent(const SBEvent &event) {
126 const ModuleList module_list =
127 Target::TargetEventData::GetModuleListFromEvent(event.get());
128 return module_list.GetSize();
Ilia Keb2c19a2015-03-10 21:59:55 +0000129}
130
Kate Stoneb9c1b512016-09-06 20:57:50 +0000131SBModule SBTarget::GetModuleAtIndexFromEvent(const uint32_t idx,
132 const SBEvent &event) {
133 const ModuleList module_list =
134 Target::TargetEventData::GetModuleListFromEvent(event.get());
135 return SBModule(module_list.GetModuleAtIndex(idx));
Ilia Keb2c19a2015-03-10 21:59:55 +0000136}
137
Kate Stoneb9c1b512016-09-06 20:57:50 +0000138const char *SBTarget::GetBroadcasterClassName() {
139 return Target::GetStaticBroadcasterClass().AsCString();
Ilia Keb2c19a2015-03-10 21:59:55 +0000140}
141
Kate Stoneb9c1b512016-09-06 20:57:50 +0000142bool SBTarget::IsValid() const {
143 return m_opaque_sp.get() != NULL && m_opaque_sp->IsValid();
Jim Ingham4bddaeb2012-02-16 06:50:00 +0000144}
145
Kate Stoneb9c1b512016-09-06 20:57:50 +0000146SBProcess SBTarget::GetProcess() {
147 SBProcess sb_process;
148 ProcessSP process_sp;
149 TargetSP target_sp(GetSP());
150 if (target_sp) {
151 process_sp = target_sp->GetProcessSP();
152 sb_process.SetSP(process_sp);
153 }
154
155 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
156 if (log)
157 log->Printf("SBTarget(%p)::GetProcess () => SBProcess(%p)",
158 static_cast<void *>(target_sp.get()),
159 static_cast<void *>(process_sp.get()));
160
161 return sb_process;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000162}
163
Kate Stoneb9c1b512016-09-06 20:57:50 +0000164SBPlatform SBTarget::GetPlatform() {
165 TargetSP target_sp(GetSP());
166 if (!target_sp)
167 return SBPlatform();
168
169 SBPlatform platform;
170 platform.m_opaque_sp = target_sp->GetPlatform();
171
172 return platform;
173}
174
175SBDebugger SBTarget::GetDebugger() const {
176 SBDebugger debugger;
177 TargetSP target_sp(GetSP());
178 if (target_sp)
179 debugger.reset(target_sp->GetDebugger().shared_from_this());
180 return debugger;
181}
182
183SBProcess SBTarget::LoadCore(const char *core_file) {
184 SBProcess sb_process;
185 TargetSP target_sp(GetSP());
186 if (target_sp) {
187 FileSpec filespec(core_file, true);
188 ProcessSP process_sp(target_sp->CreateProcess(
189 target_sp->GetDebugger().GetListener(), NULL, &filespec));
190 if (process_sp) {
191 process_sp->LoadCore();
192 sb_process.SetSP(process_sp);
193 }
194 }
195 return sb_process;
196}
197
198SBProcess SBTarget::LaunchSimple(char const **argv, char const **envp,
199 const char *working_directory) {
200 char *stdin_path = NULL;
201 char *stdout_path = NULL;
202 char *stderr_path = NULL;
203 uint32_t launch_flags = 0;
204 bool stop_at_entry = false;
205 SBError error;
206 SBListener listener = GetDebugger().GetListener();
207 return Launch(listener, argv, envp, stdin_path, stdout_path, stderr_path,
208 working_directory, launch_flags, stop_at_entry, error);
209}
210
211SBError SBTarget::Install() {
212 SBError sb_error;
213 TargetSP target_sp(GetSP());
214 if (target_sp) {
215 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
216 sb_error.ref() = target_sp->Install(NULL);
217 }
218 return sb_error;
219}
220
221SBProcess SBTarget::Launch(SBListener &listener, char const **argv,
222 char const **envp, const char *stdin_path,
223 const char *stdout_path, const char *stderr_path,
224 const char *working_directory,
225 uint32_t launch_flags, // See LaunchFlags
226 bool stop_at_entry, lldb::SBError &error) {
227 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
228
229 SBProcess sb_process;
230 ProcessSP process_sp;
231 TargetSP target_sp(GetSP());
232
233 if (log)
234 log->Printf("SBTarget(%p)::Launch (argv=%p, envp=%p, stdin=%s, stdout=%s, "
235 "stderr=%s, working-dir=%s, launch_flags=0x%x, "
236 "stop_at_entry=%i, &error (%p))...",
237 static_cast<void *>(target_sp.get()), static_cast<void *>(argv),
238 static_cast<void *>(envp), stdin_path ? stdin_path : "NULL",
239 stdout_path ? stdout_path : "NULL",
240 stderr_path ? stderr_path : "NULL",
241 working_directory ? working_directory : "NULL", launch_flags,
242 stop_at_entry, static_cast<void *>(error.get()));
243
244 if (target_sp) {
245 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
246
247 if (stop_at_entry)
248 launch_flags |= eLaunchFlagStopAtEntry;
249
250 if (getenv("LLDB_LAUNCH_FLAG_DISABLE_ASLR"))
251 launch_flags |= eLaunchFlagDisableASLR;
252
253 StateType state = eStateInvalid;
254 process_sp = target_sp->GetProcessSP();
255 if (process_sp) {
256 state = process_sp->GetState();
257
258 if (process_sp->IsAlive() && state != eStateConnected) {
259 if (state == eStateAttaching)
260 error.SetErrorString("process attach is in progress");
261 else
262 error.SetErrorString("a process is already being debugged");
263 return sb_process;
264 }
Greg Claytonaf67cec2010-12-20 20:49:23 +0000265 }
Caroline Ticeceb6b132010-10-26 03:11:13 +0000266
Kate Stoneb9c1b512016-09-06 20:57:50 +0000267 if (state == eStateConnected) {
268 // If we are already connected, then we have already specified the
269 // listener, so if a valid listener is supplied, we need to error out
270 // to let the client know.
271 if (listener.IsValid()) {
272 error.SetErrorString("process is connected and already has a listener, "
273 "pass empty listener");
274 return sb_process;
275 }
276 }
Caroline Ticeceb6b132010-10-26 03:11:13 +0000277
Kate Stoneb9c1b512016-09-06 20:57:50 +0000278 if (getenv("LLDB_LAUNCH_FLAG_DISABLE_STDIO"))
279 launch_flags |= eLaunchFlagDisableSTDIO;
280
281 ProcessLaunchInfo launch_info(
282 FileSpec{stdin_path, false}, FileSpec{stdout_path, false},
283 FileSpec{stderr_path, false}, FileSpec{working_directory, false},
284 launch_flags);
285
286 Module *exe_module = target_sp->GetExecutableModulePointer();
287 if (exe_module)
288 launch_info.SetExecutableFile(exe_module->GetPlatformFileSpec(), true);
289 if (argv)
290 launch_info.GetArguments().AppendArguments(argv);
291 if (envp)
292 launch_info.GetEnvironmentEntries().SetArguments(envp);
293
294 if (listener.IsValid())
295 launch_info.SetListener(listener.GetSP());
296
297 error.SetError(target_sp->Launch(launch_info, NULL));
298
299 sb_process.SetSP(target_sp->GetProcessSP());
300 } else {
301 error.SetErrorString("SBTarget is invalid");
302 }
303
304 log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API);
305 if (log)
306 log->Printf("SBTarget(%p)::Launch (...) => SBProcess(%p), SBError(%s)",
307 static_cast<void *>(target_sp.get()),
308 static_cast<void *>(sb_process.GetSP().get()),
309 error.GetCString());
310
311 return sb_process;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000312}
313
Kate Stoneb9c1b512016-09-06 20:57:50 +0000314SBProcess SBTarget::Launch(SBLaunchInfo &sb_launch_info, SBError &error) {
315 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
Matthew Gardinerc928de32014-10-22 07:22:56 +0000316
Kate Stoneb9c1b512016-09-06 20:57:50 +0000317 SBProcess sb_process;
318 TargetSP target_sp(GetSP());
Matthew Gardinerc928de32014-10-22 07:22:56 +0000319
Kate Stoneb9c1b512016-09-06 20:57:50 +0000320 if (log)
321 log->Printf("SBTarget(%p)::Launch (launch_info, error)...",
322 static_cast<void *>(target_sp.get()));
Matthew Gardinerc928de32014-10-22 07:22:56 +0000323
Kate Stoneb9c1b512016-09-06 20:57:50 +0000324 if (target_sp) {
325 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
326 StateType state = eStateInvalid;
Greg Clayton4d8ad552013-03-25 22:40:51 +0000327 {
Kate Stoneb9c1b512016-09-06 20:57:50 +0000328 ProcessSP process_sp = target_sp->GetProcessSP();
329 if (process_sp) {
330 state = process_sp->GetState();
331
332 if (process_sp->IsAlive() && state != eStateConnected) {
333 if (state == eStateAttaching)
334 error.SetErrorString("process attach is in progress");
335 else
336 error.SetErrorString("a process is already being debugged");
337 return sb_process;
Greg Clayton4d8ad552013-03-25 22:40:51 +0000338 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000339 }
Greg Clayton4d8ad552013-03-25 22:40:51 +0000340 }
Greg Clayton4d8ad552013-03-25 22:40:51 +0000341
Kate Stoneb9c1b512016-09-06 20:57:50 +0000342 lldb_private::ProcessLaunchInfo &launch_info = sb_launch_info.ref();
Greg Claytonbd82a5d2011-01-23 05:56:20 +0000343
Kate Stoneb9c1b512016-09-06 20:57:50 +0000344 if (!launch_info.GetExecutableFile()) {
345 Module *exe_module = target_sp->GetExecutableModulePointer();
346 if (exe_module)
347 launch_info.SetExecutableFile(exe_module->GetPlatformFileSpec(), true);
Greg Claytonfbb76342013-11-20 21:07:01 +0000348 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000349
350 const ArchSpec &arch_spec = target_sp->GetArchitecture();
351 if (arch_spec.IsValid())
352 launch_info.GetArchitecture() = arch_spec;
353
354 error.SetError(target_sp->Launch(launch_info, NULL));
355 sb_process.SetSP(target_sp->GetProcessSP());
356 } else {
357 error.SetErrorString("SBTarget is invalid");
358 }
359
360 log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API);
361 if (log)
362 log->Printf("SBTarget(%p)::Launch (...) => SBProcess(%p)",
363 static_cast<void *>(target_sp.get()),
364 static_cast<void *>(sb_process.GetSP().get()));
365
366 return sb_process;
Greg Claytonfbb76342013-11-20 21:07:01 +0000367}
368
Kate Stoneb9c1b512016-09-06 20:57:50 +0000369lldb::SBProcess SBTarget::Attach(SBAttachInfo &sb_attach_info, SBError &error) {
370 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000371
Kate Stoneb9c1b512016-09-06 20:57:50 +0000372 SBProcess sb_process;
373 TargetSP target_sp(GetSP());
Greg Claytonacdbe812012-01-30 09:04:36 +0000374
Kate Stoneb9c1b512016-09-06 20:57:50 +0000375 if (log)
376 log->Printf("SBTarget(%p)::Attach (sb_attach_info, error)...",
377 static_cast<void *>(target_sp.get()));
Greg Claytonacdbe812012-01-30 09:04:36 +0000378
Kate Stoneb9c1b512016-09-06 20:57:50 +0000379 if (target_sp) {
380 ProcessAttachInfo &attach_info = sb_attach_info.ref();
381 if (attach_info.ProcessIDIsValid() && !attach_info.UserIDIsValid()) {
382 PlatformSP platform_sp = target_sp->GetPlatform();
383 // See if we can pre-verify if a process exists or not
384 if (platform_sp && platform_sp->IsConnected()) {
385 lldb::pid_t attach_pid = attach_info.GetProcessID();
386 ProcessInstanceInfo instance_info;
387 if (platform_sp->GetProcessInfo(attach_pid, instance_info)) {
388 attach_info.SetUserID(instance_info.GetEffectiveUserID());
389 } else {
390 error.ref().SetErrorStringWithFormat(
391 "no process found with process ID %" PRIu64, attach_pid);
392 if (log) {
393 log->Printf("SBTarget(%p)::Attach (...) => error %s",
394 static_cast<void *>(target_sp.get()),
395 error.GetCString());
396 }
397 return sb_process;
Greg Clayton931180e2011-01-27 06:44:37 +0000398 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000399 }
Greg Clayton524e60b2010-10-06 22:10:17 +0000400 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000401 error.SetError(AttachToProcess(attach_info, *target_sp));
402 if (error.Success())
403 sb_process.SetSP(target_sp->GetProcessSP());
404 } else {
405 error.SetErrorString("SBTarget is invalid");
406 }
Caroline Ticeceb6b132010-10-26 03:11:13 +0000407
Kate Stoneb9c1b512016-09-06 20:57:50 +0000408 if (log)
409 log->Printf("SBTarget(%p)::Attach (...) => SBProcess(%p)",
410 static_cast<void *>(target_sp.get()),
411 static_cast<void *>(sb_process.GetSP().get()));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000412
Kate Stoneb9c1b512016-09-06 20:57:50 +0000413 return sb_process;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000414}
415
Greg Clayton1ba6cfd2011-12-02 02:10:57 +0000416#if defined(__APPLE__)
417
Kate Stoneb9c1b512016-09-06 20:57:50 +0000418lldb::SBProcess SBTarget::AttachToProcessWithID(SBListener &listener,
419 ::pid_t pid,
420 lldb::SBError &error) {
421 return AttachToProcessWithID(listener, (lldb::pid_t)pid, error);
Greg Clayton1ba6cfd2011-12-02 02:10:57 +0000422}
423
424#endif // #if defined(__APPLE__)
Greg Clayton524e60b2010-10-06 22:10:17 +0000425
Kate Stoneb9c1b512016-09-06 20:57:50 +0000426lldb::SBProcess SBTarget::AttachToProcessWithID(
James McIlree9631aae2011-03-04 00:31:13 +0000427 SBListener &listener,
Kate Stoneb9c1b512016-09-06 20:57:50 +0000428 lldb::pid_t pid, // The process ID to attach to
429 SBError &error // An error explaining what went wrong if attach fails
430 ) {
431 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
Sean Callanan575a4542012-10-20 00:21:31 +0000432
Kate Stoneb9c1b512016-09-06 20:57:50 +0000433 SBProcess sb_process;
434 TargetSP target_sp(GetSP());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000435
Kate Stoneb9c1b512016-09-06 20:57:50 +0000436 if (log)
437 log->Printf("SBTarget(%p)::%s (listener, pid=%" PRId64 ", error)...",
438 static_cast<void *>(target_sp.get()), __FUNCTION__, pid);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000439
Kate Stoneb9c1b512016-09-06 20:57:50 +0000440 if (target_sp) {
441 ProcessAttachInfo attach_info;
442 attach_info.SetProcessID(pid);
443 if (listener.IsValid())
444 attach_info.SetListener(listener.GetSP());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000445
Kate Stoneb9c1b512016-09-06 20:57:50 +0000446 ProcessInstanceInfo instance_info;
447 if (target_sp->GetPlatform()->GetProcessInfo(pid, instance_info))
448 attach_info.SetUserID(instance_info.GetEffectiveUserID());
449
450 error.SetError(AttachToProcess(attach_info, *target_sp));
451 if (error.Success())
452 sb_process.SetSP(target_sp->GetProcessSP());
453 } else
454 error.SetErrorString("SBTarget is invalid");
455
456 if (log)
457 log->Printf("SBTarget(%p)::%s (...) => SBProcess(%p)",
458 static_cast<void *>(target_sp.get()), __FUNCTION__,
459 static_cast<void *>(sb_process.GetSP().get()));
460 return sb_process;
461}
462
463lldb::SBProcess SBTarget::AttachToProcessWithName(
464 SBListener &listener,
465 const char *name, // basename of process to attach to
466 bool wait_for, // if true wait for a new instance of "name" to be launched
467 SBError &error // An error explaining what went wrong if attach fails
468 ) {
469 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
470
471 SBProcess sb_process;
472 TargetSP target_sp(GetSP());
473
474 if (log)
475 log->Printf("SBTarget(%p)::%s (listener, name=%s, wait_for=%s, error)...",
476 static_cast<void *>(target_sp.get()), __FUNCTION__, name,
477 wait_for ? "true" : "false");
478
479 if (name && target_sp) {
480 ProcessAttachInfo attach_info;
481 attach_info.GetExecutableFile().SetFile(name, false);
482 attach_info.SetWaitForLaunch(wait_for);
483 if (listener.IsValid())
484 attach_info.SetListener(listener.GetSP());
485
486 error.SetError(AttachToProcess(attach_info, *target_sp));
487 if (error.Success())
488 sb_process.SetSP(target_sp->GetProcessSP());
489 } else
490 error.SetErrorString("SBTarget is invalid");
491
492 if (log)
493 log->Printf("SBTarget(%p)::%s (...) => SBProcess(%p)",
494 static_cast<void *>(target_sp.get()), __FUNCTION__,
495 static_cast<void *>(sb_process.GetSP().get()));
496 return sb_process;
497}
498
499lldb::SBProcess SBTarget::ConnectRemote(SBListener &listener, const char *url,
500 const char *plugin_name,
501 SBError &error) {
502 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
503
504 SBProcess sb_process;
505 ProcessSP process_sp;
506 TargetSP target_sp(GetSP());
507
508 if (log)
509 log->Printf("SBTarget(%p)::ConnectRemote (listener, url=%s, "
510 "plugin_name=%s, error)...",
511 static_cast<void *>(target_sp.get()), url, plugin_name);
512
513 if (target_sp) {
514 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
515 if (listener.IsValid())
516 process_sp =
517 target_sp->CreateProcess(listener.m_opaque_sp, plugin_name, NULL);
James McIlree9631aae2011-03-04 00:31:13 +0000518 else
Kate Stoneb9c1b512016-09-06 20:57:50 +0000519 process_sp = target_sp->CreateProcess(
520 target_sp->GetDebugger().GetListener(), plugin_name, NULL);
521
522 if (process_sp) {
523 sb_process.SetSP(process_sp);
524 error.SetError(process_sp->ConnectRemote(NULL, url));
525 } else {
526 error.SetErrorString("unable to create lldb_private::Process");
James McIlree9631aae2011-03-04 00:31:13 +0000527 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000528 } else {
529 error.SetErrorString("SBTarget is invalid");
530 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000531
Kate Stoneb9c1b512016-09-06 20:57:50 +0000532 if (log)
533 log->Printf("SBTarget(%p)::ConnectRemote (...) => SBProcess(%p)",
534 static_cast<void *>(target_sp.get()),
535 static_cast<void *>(process_sp.get()));
536 return sb_process;
James McIlree9631aae2011-03-04 00:31:13 +0000537}
538
Kate Stoneb9c1b512016-09-06 20:57:50 +0000539SBFileSpec SBTarget::GetExecutable() {
Caroline Ticeceb6b132010-10-26 03:11:13 +0000540
Kate Stoneb9c1b512016-09-06 20:57:50 +0000541 SBFileSpec exe_file_spec;
542 TargetSP target_sp(GetSP());
543 if (target_sp) {
544 Module *exe_module = target_sp->GetExecutableModulePointer();
545 if (exe_module)
546 exe_file_spec.SetFileSpec(exe_module->GetFileSpec());
547 }
Caroline Ticeceb6b132010-10-26 03:11:13 +0000548
Kate Stoneb9c1b512016-09-06 20:57:50 +0000549 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
550 if (log) {
551 log->Printf("SBTarget(%p)::GetExecutable () => SBFileSpec(%p)",
552 static_cast<void *>(target_sp.get()),
553 static_cast<const void *>(exe_file_spec.get()));
554 }
Caroline Ticeceb6b132010-10-26 03:11:13 +0000555
Kate Stoneb9c1b512016-09-06 20:57:50 +0000556 return exe_file_spec;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000557}
558
Kate Stoneb9c1b512016-09-06 20:57:50 +0000559bool SBTarget::operator==(const SBTarget &rhs) const {
560 return m_opaque_sp.get() == rhs.m_opaque_sp.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000561}
562
Kate Stoneb9c1b512016-09-06 20:57:50 +0000563bool SBTarget::operator!=(const SBTarget &rhs) const {
564 return m_opaque_sp.get() != rhs.m_opaque_sp.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000565}
566
Kate Stoneb9c1b512016-09-06 20:57:50 +0000567lldb::TargetSP SBTarget::GetSP() const { return m_opaque_sp; }
568
569void SBTarget::SetSP(const lldb::TargetSP &target_sp) {
570 m_opaque_sp = target_sp;
Greg Clayton9a377662011-10-01 02:59:24 +0000571}
572
Kate Stoneb9c1b512016-09-06 20:57:50 +0000573lldb::SBAddress SBTarget::ResolveLoadAddress(lldb::addr_t vm_addr) {
574 lldb::SBAddress sb_addr;
575 Address &addr = sb_addr.ref();
576 TargetSP target_sp(GetSP());
577 if (target_sp) {
578 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
579 if (target_sp->ResolveLoadAddress(vm_addr, addr))
580 return sb_addr;
581 }
582
583 // We have a load address that isn't in a section, just return an address
584 // with the offset filled in (the address) and the section set to NULL
585 addr.SetRawAddress(vm_addr);
586 return sb_addr;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000587}
588
Kate Stoneb9c1b512016-09-06 20:57:50 +0000589lldb::SBAddress SBTarget::ResolveFileAddress(lldb::addr_t file_addr) {
590 lldb::SBAddress sb_addr;
591 Address &addr = sb_addr.ref();
592 TargetSP target_sp(GetSP());
593 if (target_sp) {
594 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
595 if (target_sp->ResolveFileAddress(file_addr, addr))
596 return sb_addr;
597 }
Greg Claytonac2eb9b2010-12-12 19:25:26 +0000598
Kate Stoneb9c1b512016-09-06 20:57:50 +0000599 addr.SetRawAddress(file_addr);
600 return sb_addr;
Greg Claytonac2eb9b2010-12-12 19:25:26 +0000601}
602
Kate Stoneb9c1b512016-09-06 20:57:50 +0000603lldb::SBAddress SBTarget::ResolvePastLoadAddress(uint32_t stop_id,
604 lldb::addr_t vm_addr) {
605 lldb::SBAddress sb_addr;
606 Address &addr = sb_addr.ref();
607 TargetSP target_sp(GetSP());
608 if (target_sp) {
609 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
610 if (target_sp->ResolveLoadAddress(vm_addr, addr))
611 return sb_addr;
612 }
Matthew Gardinerc928de32014-10-22 07:22:56 +0000613
Kate Stoneb9c1b512016-09-06 20:57:50 +0000614 // We have a load address that isn't in a section, just return an address
615 // with the offset filled in (the address) and the section set to NULL
616 addr.SetRawAddress(vm_addr);
617 return sb_addr;
Greg Claytond5944cd2013-12-06 01:12:00 +0000618}
619
Greg Clayton5f2a4f92011-03-02 21:34:46 +0000620SBSymbolContext
Kate Stoneb9c1b512016-09-06 20:57:50 +0000621SBTarget::ResolveSymbolContextForAddress(const SBAddress &addr,
622 uint32_t resolve_scope) {
623 SBSymbolContext sc;
624 if (addr.IsValid()) {
Matthew Gardinerc928de32014-10-22 07:22:56 +0000625 TargetSP target_sp(GetSP());
626 if (target_sp)
Kate Stoneb9c1b512016-09-06 20:57:50 +0000627 target_sp->GetImages().ResolveSymbolContextForAddress(
628 addr.ref(), resolve_scope, sc.ref());
629 }
630 return sc;
631}
Matthew Gardinerc928de32014-10-22 07:22:56 +0000632
Kate Stoneb9c1b512016-09-06 20:57:50 +0000633size_t SBTarget::ReadMemory(const SBAddress addr, void *buf, size_t size,
634 lldb::SBError &error) {
635 SBError sb_error;
636 size_t bytes_read = 0;
637 TargetSP target_sp(GetSP());
638 if (target_sp) {
639 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
640 bytes_read =
641 target_sp->ReadMemory(addr.ref(), false, buf, size, sb_error.ref());
642 } else {
643 sb_error.SetErrorString("invalid target");
644 }
645
646 return bytes_read;
647}
648
649SBBreakpoint SBTarget::BreakpointCreateByLocation(const char *file,
650 uint32_t line) {
651 return SBBreakpoint(
652 BreakpointCreateByLocation(SBFileSpec(file, false), line));
Matthew Gardinerc928de32014-10-22 07:22:56 +0000653}
Greg Clayton5f2a4f92011-03-02 21:34:46 +0000654
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000655SBBreakpoint
Kate Stoneb9c1b512016-09-06 20:57:50 +0000656SBTarget::BreakpointCreateByLocation(const SBFileSpec &sb_file_spec,
657 uint32_t line) {
658 return BreakpointCreateByLocation(sb_file_spec, line, 0);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000659}
660
661SBBreakpoint
Kate Stoneb9c1b512016-09-06 20:57:50 +0000662SBTarget::BreakpointCreateByLocation(const SBFileSpec &sb_file_spec,
663 uint32_t line, lldb::addr_t offset) {
664 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
Jim Ingham24111672016-03-09 18:59:13 +0000665
Kate Stoneb9c1b512016-09-06 20:57:50 +0000666 SBBreakpoint sb_bp;
667 TargetSP target_sp(GetSP());
668 if (target_sp && line != 0) {
669 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
Caroline Ticeceb6b132010-10-26 03:11:13 +0000670
Kate Stoneb9c1b512016-09-06 20:57:50 +0000671 const LazyBool check_inlines = eLazyBoolCalculate;
672 const LazyBool skip_prologue = eLazyBoolCalculate;
673 const bool internal = false;
674 const bool hardware = false;
675 const LazyBool move_to_nearest_code = eLazyBoolCalculate;
676 *sb_bp = target_sp->CreateBreakpoint(NULL, *sb_file_spec, line, offset,
677 check_inlines, skip_prologue, internal,
678 hardware, move_to_nearest_code);
679 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000680
Kate Stoneb9c1b512016-09-06 20:57:50 +0000681 if (log) {
682 SBStream sstr;
683 sb_bp.GetDescription(sstr);
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000684 char path[PATH_MAX];
Kate Stoneb9c1b512016-09-06 20:57:50 +0000685 sb_file_spec->GetPath(path, sizeof(path));
686 log->Printf("SBTarget(%p)::BreakpointCreateByLocation ( %s:%u ) => "
687 "SBBreakpoint(%p): %s",
688 static_cast<void *>(target_sp.get()), path, line,
689 static_cast<void *>(sb_bp.get()), sstr.GetData());
690 }
Greg Claytond5944cd2013-12-06 01:12:00 +0000691
Kate Stoneb9c1b512016-09-06 20:57:50 +0000692 return sb_bp;
693}
694
695SBBreakpoint SBTarget::BreakpointCreateByName(const char *symbol_name,
696 const char *module_name) {
697 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
698
699 SBBreakpoint sb_bp;
700 TargetSP target_sp(GetSP());
701 if (target_sp.get()) {
702 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
703
704 const bool internal = false;
705 const bool hardware = false;
706 const LazyBool skip_prologue = eLazyBoolCalculate;
707 const lldb::addr_t offset = 0;
708 if (module_name && module_name[0]) {
709 FileSpecList module_spec_list;
710 module_spec_list.Append(FileSpec(module_name, false));
711 *sb_bp = target_sp->CreateBreakpoint(
712 &module_spec_list, NULL, symbol_name, eFunctionNameTypeAuto,
713 eLanguageTypeUnknown, offset, skip_prologue, internal, hardware);
714 } else {
715 *sb_bp = target_sp->CreateBreakpoint(
716 NULL, NULL, symbol_name, eFunctionNameTypeAuto, eLanguageTypeUnknown,
717 offset, skip_prologue, internal, hardware);
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000718 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000719 }
720
721 if (log)
722 log->Printf("SBTarget(%p)::BreakpointCreateByName (symbol=\"%s\", "
723 "module=\"%s\") => SBBreakpoint(%p)",
724 static_cast<void *>(target_sp.get()), symbol_name, module_name,
725 static_cast<void *>(sb_bp.get()));
726
727 return sb_bp;
728}
729
730lldb::SBBreakpoint
731SBTarget::BreakpointCreateByName(const char *symbol_name,
732 const SBFileSpecList &module_list,
733 const SBFileSpecList &comp_unit_list) {
734 uint32_t name_type_mask = eFunctionNameTypeAuto;
735 return BreakpointCreateByName(symbol_name, name_type_mask,
736 eLanguageTypeUnknown, module_list,
737 comp_unit_list);
738}
739
740lldb::SBBreakpoint SBTarget::BreakpointCreateByName(
741 const char *symbol_name, uint32_t name_type_mask,
742 const SBFileSpecList &module_list, const SBFileSpecList &comp_unit_list) {
743 return BreakpointCreateByName(symbol_name, name_type_mask,
744 eLanguageTypeUnknown, module_list,
745 comp_unit_list);
746}
747
748lldb::SBBreakpoint SBTarget::BreakpointCreateByName(
749 const char *symbol_name, uint32_t name_type_mask,
750 LanguageType symbol_language, const SBFileSpecList &module_list,
751 const SBFileSpecList &comp_unit_list) {
752 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
753
754 SBBreakpoint sb_bp;
755 TargetSP target_sp(GetSP());
756 if (target_sp && symbol_name && symbol_name[0]) {
757 const bool internal = false;
758 const bool hardware = false;
759 const LazyBool skip_prologue = eLazyBoolCalculate;
760 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
761 *sb_bp = target_sp->CreateBreakpoint(
762 module_list.get(), comp_unit_list.get(), symbol_name, name_type_mask,
763 symbol_language, 0, skip_prologue, internal, hardware);
764 }
765
766 if (log)
767 log->Printf("SBTarget(%p)::BreakpointCreateByName (symbol=\"%s\", "
768 "name_type: %d) => SBBreakpoint(%p)",
769 static_cast<void *>(target_sp.get()), symbol_name,
770 name_type_mask, static_cast<void *>(sb_bp.get()));
771
772 return sb_bp;
773}
774
775lldb::SBBreakpoint SBTarget::BreakpointCreateByNames(
776 const char *symbol_names[], uint32_t num_names, uint32_t name_type_mask,
777 const SBFileSpecList &module_list, const SBFileSpecList &comp_unit_list) {
778 return BreakpointCreateByNames(symbol_names, num_names, name_type_mask,
779 eLanguageTypeUnknown, module_list,
780 comp_unit_list);
781}
782
783lldb::SBBreakpoint SBTarget::BreakpointCreateByNames(
784 const char *symbol_names[], uint32_t num_names, uint32_t name_type_mask,
785 LanguageType symbol_language, const SBFileSpecList &module_list,
786 const SBFileSpecList &comp_unit_list) {
787 return BreakpointCreateByNames(symbol_names, num_names, name_type_mask,
788 eLanguageTypeUnknown, 0, module_list,
789 comp_unit_list);
790}
791
792lldb::SBBreakpoint SBTarget::BreakpointCreateByNames(
793 const char *symbol_names[], uint32_t num_names, uint32_t name_type_mask,
794 LanguageType symbol_language, lldb::addr_t offset,
795 const SBFileSpecList &module_list, const SBFileSpecList &comp_unit_list) {
796 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
797
798 SBBreakpoint sb_bp;
799 TargetSP target_sp(GetSP());
800 if (target_sp && num_names > 0) {
801 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
802 const bool internal = false;
803 const bool hardware = false;
804 const LazyBool skip_prologue = eLazyBoolCalculate;
805 *sb_bp = target_sp->CreateBreakpoint(
806 module_list.get(), comp_unit_list.get(), symbol_names, num_names,
807 name_type_mask, symbol_language, offset, skip_prologue, internal,
808 hardware);
809 }
810
811 if (log) {
812 log->Printf("SBTarget(%p)::BreakpointCreateByName (symbols={",
813 static_cast<void *>(target_sp.get()));
814 for (uint32_t i = 0; i < num_names; i++) {
815 char sep;
816 if (i < num_names - 1)
817 sep = ',';
818 else
819 sep = '}';
820 if (symbol_names[i] != NULL)
821 log->Printf("\"%s\"%c ", symbol_names[i], sep);
822 else
823 log->Printf("\"<NULL>\"%c ", sep);
824 }
825 log->Printf("name_type: %d) => SBBreakpoint(%p)", name_type_mask,
826 static_cast<void *>(sb_bp.get()));
827 }
828
829 return sb_bp;
830}
831
832SBBreakpoint SBTarget::BreakpointCreateByRegex(const char *symbol_name_regex,
833 const char *module_name) {
834 SBFileSpecList module_spec_list;
835 SBFileSpecList comp_unit_list;
836 if (module_name && module_name[0]) {
837 module_spec_list.Append(FileSpec(module_name, false));
838 }
839 return BreakpointCreateByRegex(symbol_name_regex, eLanguageTypeUnknown,
840 module_spec_list, comp_unit_list);
841}
842
843lldb::SBBreakpoint
844SBTarget::BreakpointCreateByRegex(const char *symbol_name_regex,
845 const SBFileSpecList &module_list,
846 const SBFileSpecList &comp_unit_list) {
847 return BreakpointCreateByRegex(symbol_name_regex, eLanguageTypeUnknown,
848 module_list, comp_unit_list);
849}
850
851lldb::SBBreakpoint SBTarget::BreakpointCreateByRegex(
852 const char *symbol_name_regex, LanguageType symbol_language,
853 const SBFileSpecList &module_list, const SBFileSpecList &comp_unit_list) {
854 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
855
856 SBBreakpoint sb_bp;
857 TargetSP target_sp(GetSP());
858 if (target_sp && symbol_name_regex && symbol_name_regex[0]) {
859 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
860 RegularExpression regexp(symbol_name_regex);
861 const bool internal = false;
862 const bool hardware = false;
863 const LazyBool skip_prologue = eLazyBoolCalculate;
864
865 *sb_bp = target_sp->CreateFuncRegexBreakpoint(
866 module_list.get(), comp_unit_list.get(), regexp, symbol_language,
867 skip_prologue, internal, hardware);
868 }
869
870 if (log)
871 log->Printf("SBTarget(%p)::BreakpointCreateByRegex (symbol_regex=\"%s\") "
872 "=> SBBreakpoint(%p)",
873 static_cast<void *>(target_sp.get()), symbol_name_regex,
874 static_cast<void *>(sb_bp.get()));
875
876 return sb_bp;
877}
878
879SBBreakpoint SBTarget::BreakpointCreateByAddress(addr_t address) {
880 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
881
882 SBBreakpoint sb_bp;
883 TargetSP target_sp(GetSP());
884 if (target_sp) {
885 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
886 const bool hardware = false;
887 *sb_bp = target_sp->CreateBreakpoint(address, false, hardware);
888 }
889
890 if (log)
891 log->Printf("SBTarget(%p)::BreakpointCreateByAddress (address=%" PRIu64
892 ") => SBBreakpoint(%p)",
893 static_cast<void *>(target_sp.get()),
894 static_cast<uint64_t>(address),
895 static_cast<void *>(sb_bp.get()));
896
897 return sb_bp;
898}
899
900SBBreakpoint SBTarget::BreakpointCreateBySBAddress(SBAddress &sb_address) {
901 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
902
903 SBBreakpoint sb_bp;
904 TargetSP target_sp(GetSP());
905 if (!sb_address.IsValid()) {
906 if (log)
907 log->Printf("SBTarget(%p)::BreakpointCreateBySBAddress called with "
908 "invalid address",
909 static_cast<void *>(target_sp.get()));
910 return sb_bp;
911 }
912
913 if (target_sp) {
914 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
915 const bool hardware = false;
916 *sb_bp = target_sp->CreateBreakpoint(sb_address.ref(), false, hardware);
917 }
918
919 if (log) {
920 SBStream s;
921 sb_address.GetDescription(s);
922 log->Printf("SBTarget(%p)::BreakpointCreateBySBAddress (address=%s) => "
923 "SBBreakpoint(%p)",
924 static_cast<void *>(target_sp.get()), s.GetData(),
925 static_cast<void *>(sb_bp.get()));
926 }
927
928 return sb_bp;
929}
930
931lldb::SBBreakpoint
932SBTarget::BreakpointCreateBySourceRegex(const char *source_regex,
933 const lldb::SBFileSpec &source_file,
934 const char *module_name) {
935 SBFileSpecList module_spec_list;
936
937 if (module_name && module_name[0]) {
938 module_spec_list.Append(FileSpec(module_name, false));
939 }
940
941 SBFileSpecList source_file_list;
942 if (source_file.IsValid()) {
943 source_file_list.Append(source_file);
944 }
945
946 return BreakpointCreateBySourceRegex(source_regex, module_spec_list,
947 source_file_list);
948}
949
950lldb::SBBreakpoint SBTarget::BreakpointCreateBySourceRegex(
951 const char *source_regex, const SBFileSpecList &module_list,
952 const lldb::SBFileSpecList &source_file_list) {
953 return BreakpointCreateBySourceRegex(source_regex, module_list,
954 source_file_list, SBStringList());
955}
956
957lldb::SBBreakpoint SBTarget::BreakpointCreateBySourceRegex(
958 const char *source_regex, const SBFileSpecList &module_list,
959 const lldb::SBFileSpecList &source_file_list,
960 const SBStringList &func_names) {
961 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
962
963 SBBreakpoint sb_bp;
964 TargetSP target_sp(GetSP());
965 if (target_sp && source_regex && source_regex[0]) {
966 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
967 const bool hardware = false;
968 const LazyBool move_to_nearest_code = eLazyBoolCalculate;
969 RegularExpression regexp(source_regex);
970 std::unordered_set<std::string> func_names_set;
971 for (size_t i = 0; i < func_names.GetSize(); i++) {
972 func_names_set.insert(func_names.GetStringAtIndex(i));
973 }
974
975 *sb_bp = target_sp->CreateSourceRegexBreakpoint(
976 module_list.get(), source_file_list.get(), func_names_set, regexp,
977 false, hardware, move_to_nearest_code);
978 }
979
980 if (log)
981 log->Printf("SBTarget(%p)::BreakpointCreateByRegex (source_regex=\"%s\") "
982 "=> SBBreakpoint(%p)",
983 static_cast<void *>(target_sp.get()), source_regex,
984 static_cast<void *>(sb_bp.get()));
985
986 return sb_bp;
987}
988
989lldb::SBBreakpoint
990SBTarget::BreakpointCreateForException(lldb::LanguageType language,
991 bool catch_bp, bool throw_bp) {
992 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
993
994 SBBreakpoint sb_bp;
995 TargetSP target_sp(GetSP());
996 if (target_sp) {
997 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
998 const bool hardware = false;
999 *sb_bp = target_sp->CreateExceptionBreakpoint(language, catch_bp, throw_bp,
1000 hardware);
1001 }
1002
1003 if (log)
1004 log->Printf("SBTarget(%p)::BreakpointCreateByRegex (Language: %s, catch: "
1005 "%s throw: %s) => SBBreakpoint(%p)",
1006 static_cast<void *>(target_sp.get()),
1007 Language::GetNameForLanguageType(language),
1008 catch_bp ? "on" : "off", throw_bp ? "on" : "off",
1009 static_cast<void *>(sb_bp.get()));
1010
1011 return sb_bp;
1012}
1013
1014uint32_t SBTarget::GetNumBreakpoints() const {
1015 TargetSP target_sp(GetSP());
1016 if (target_sp) {
1017 // The breakpoint list is thread safe, no need to lock
1018 return target_sp->GetBreakpointList().GetSize();
1019 }
1020 return 0;
1021}
1022
1023SBBreakpoint SBTarget::GetBreakpointAtIndex(uint32_t idx) const {
1024 SBBreakpoint sb_breakpoint;
1025 TargetSP target_sp(GetSP());
1026 if (target_sp) {
1027 // The breakpoint list is thread safe, no need to lock
1028 *sb_breakpoint = target_sp->GetBreakpointList().GetBreakpointAtIndex(idx);
1029 }
1030 return sb_breakpoint;
1031}
1032
1033bool SBTarget::BreakpointDelete(break_id_t bp_id) {
1034 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1035
1036 bool result = false;
1037 TargetSP target_sp(GetSP());
1038 if (target_sp) {
1039 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1040 result = target_sp->RemoveBreakpointByID(bp_id);
1041 }
1042
1043 if (log)
1044 log->Printf("SBTarget(%p)::BreakpointDelete (bp_id=%d) => %i",
1045 static_cast<void *>(target_sp.get()),
1046 static_cast<uint32_t>(bp_id), result);
1047
1048 return result;
1049}
1050
1051SBBreakpoint SBTarget::FindBreakpointByID(break_id_t bp_id) {
1052 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1053
1054 SBBreakpoint sb_breakpoint;
1055 TargetSP target_sp(GetSP());
1056 if (target_sp && bp_id != LLDB_INVALID_BREAK_ID) {
1057 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1058 *sb_breakpoint = target_sp->GetBreakpointByID(bp_id);
1059 }
1060
1061 if (log)
1062 log->Printf(
1063 "SBTarget(%p)::FindBreakpointByID (bp_id=%d) => SBBreakpoint(%p)",
1064 static_cast<void *>(target_sp.get()), static_cast<uint32_t>(bp_id),
1065 static_cast<void *>(sb_breakpoint.get()));
1066
1067 return sb_breakpoint;
1068}
1069
1070bool SBTarget::EnableAllBreakpoints() {
1071 TargetSP target_sp(GetSP());
1072 if (target_sp) {
1073 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1074 target_sp->EnableAllBreakpoints();
1075 return true;
1076 }
1077 return false;
1078}
1079
1080bool SBTarget::DisableAllBreakpoints() {
1081 TargetSP target_sp(GetSP());
1082 if (target_sp) {
1083 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1084 target_sp->DisableAllBreakpoints();
1085 return true;
1086 }
1087 return false;
1088}
1089
1090bool SBTarget::DeleteAllBreakpoints() {
1091 TargetSP target_sp(GetSP());
1092 if (target_sp) {
1093 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1094 target_sp->RemoveAllBreakpoints();
1095 return true;
1096 }
1097 return false;
1098}
1099
Jim Ingham01f16662016-09-14 19:07:35 +00001100lldb::SBError SBTarget::BreakpointsCreateFromFile(SBFileSpec &source_file,
1101 SBBreakpointList &new_bps) {
1102 SBError sberr;
1103 TargetSP target_sp(GetSP());
1104 if (!target_sp) {
1105 sberr.SetErrorString(
1106 "BreakpointCreateFromFile called with invalid target.");
1107 return sberr;
1108 }
1109 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1110
1111 BreakpointIDList bp_ids;
1112 sberr.ref() = target_sp->CreateBreakpointsFromFile(source_file.ref(), bp_ids);
1113 if (sberr.Fail())
1114 return sberr;
1115
1116 size_t num_bkpts = bp_ids.GetSize();
1117 for (size_t i = 0; i < num_bkpts; i++) {
1118 BreakpointID bp_id = bp_ids.GetBreakpointIDAtIndex(i);
1119 new_bps.AppendByID(bp_id.GetBreakpointID());
1120 }
1121 return sberr;
1122}
1123
1124lldb::SBError SBTarget::BreakpointsWriteToFile(SBFileSpec &dest_file) {
1125 SBError sberr;
1126 TargetSP target_sp(GetSP());
1127 if (!target_sp) {
1128 sberr.SetErrorString("BreakpointWriteToFile called with invalid target.");
1129 return sberr;
1130 }
1131 SBBreakpointList bkpt_list(*this);
1132 return BreakpointsWriteToFile(dest_file, bkpt_list);
1133}
1134
1135lldb::SBError SBTarget::BreakpointsWriteToFile(SBFileSpec &dest_file,
1136 SBBreakpointList &bkpt_list) {
1137 SBError sberr;
1138 TargetSP target_sp(GetSP());
1139 if (!target_sp) {
1140 sberr.SetErrorString("BreakpointWriteToFile called with invalid target.");
1141 return sberr;
1142 }
1143
1144 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1145 BreakpointIDList bp_id_list;
1146 bkpt_list.CopyToBreakpointIDList(bp_id_list);
1147 sberr.ref() =
1148 target_sp->SerializeBreakpointsToFile(dest_file.ref(), bp_id_list);
1149 return sberr;
1150}
1151
Kate Stoneb9c1b512016-09-06 20:57:50 +00001152uint32_t SBTarget::GetNumWatchpoints() const {
1153 TargetSP target_sp(GetSP());
1154 if (target_sp) {
1155 // The watchpoint list is thread safe, no need to lock
1156 return target_sp->GetWatchpointList().GetSize();
1157 }
1158 return 0;
1159}
1160
1161SBWatchpoint SBTarget::GetWatchpointAtIndex(uint32_t idx) const {
1162 SBWatchpoint sb_watchpoint;
1163 TargetSP target_sp(GetSP());
1164 if (target_sp) {
1165 // The watchpoint list is thread safe, no need to lock
1166 sb_watchpoint.SetSP(target_sp->GetWatchpointList().GetByIndex(idx));
1167 }
1168 return sb_watchpoint;
1169}
1170
1171bool SBTarget::DeleteWatchpoint(watch_id_t wp_id) {
1172 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1173
1174 bool result = false;
1175 TargetSP target_sp(GetSP());
1176 if (target_sp) {
1177 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1178 std::unique_lock<std::recursive_mutex> lock;
1179 target_sp->GetWatchpointList().GetListMutex(lock);
1180 result = target_sp->RemoveWatchpointByID(wp_id);
1181 }
1182
1183 if (log)
1184 log->Printf("SBTarget(%p)::WatchpointDelete (wp_id=%d) => %i",
1185 static_cast<void *>(target_sp.get()),
1186 static_cast<uint32_t>(wp_id), result);
1187
1188 return result;
1189}
1190
1191SBWatchpoint SBTarget::FindWatchpointByID(lldb::watch_id_t wp_id) {
1192 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1193
1194 SBWatchpoint sb_watchpoint;
1195 lldb::WatchpointSP watchpoint_sp;
1196 TargetSP target_sp(GetSP());
1197 if (target_sp && wp_id != LLDB_INVALID_WATCH_ID) {
1198 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1199 std::unique_lock<std::recursive_mutex> lock;
1200 target_sp->GetWatchpointList().GetListMutex(lock);
1201 watchpoint_sp = target_sp->GetWatchpointList().FindByID(wp_id);
1202 sb_watchpoint.SetSP(watchpoint_sp);
1203 }
1204
1205 if (log)
1206 log->Printf(
1207 "SBTarget(%p)::FindWatchpointByID (bp_id=%d) => SBWatchpoint(%p)",
1208 static_cast<void *>(target_sp.get()), static_cast<uint32_t>(wp_id),
1209 static_cast<void *>(watchpoint_sp.get()));
1210
1211 return sb_watchpoint;
1212}
1213
1214lldb::SBWatchpoint SBTarget::WatchAddress(lldb::addr_t addr, size_t size,
1215 bool read, bool write,
1216 SBError &error) {
1217 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1218
1219 SBWatchpoint sb_watchpoint;
1220 lldb::WatchpointSP watchpoint_sp;
1221 TargetSP target_sp(GetSP());
1222 if (target_sp && (read || write) && addr != LLDB_INVALID_ADDRESS &&
1223 size > 0) {
1224 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1225 uint32_t watch_type = 0;
1226 if (read)
1227 watch_type |= LLDB_WATCH_TYPE_READ;
1228 if (write)
1229 watch_type |= LLDB_WATCH_TYPE_WRITE;
1230 if (watch_type == 0) {
1231 error.SetErrorString(
1232 "Can't create a watchpoint that is neither read nor write.");
1233 return sb_watchpoint;
1234 }
1235
1236 // Target::CreateWatchpoint() is thread safe.
1237 Error cw_error;
1238 // This API doesn't take in a type, so we can't figure out what it is.
1239 CompilerType *type = NULL;
1240 watchpoint_sp =
1241 target_sp->CreateWatchpoint(addr, size, type, watch_type, cw_error);
1242 error.SetError(cw_error);
1243 sb_watchpoint.SetSP(watchpoint_sp);
1244 }
1245
1246 if (log)
1247 log->Printf("SBTarget(%p)::WatchAddress (addr=0x%" PRIx64
1248 ", 0x%u) => SBWatchpoint(%p)",
1249 static_cast<void *>(target_sp.get()), addr,
1250 static_cast<uint32_t>(size),
1251 static_cast<void *>(watchpoint_sp.get()));
1252
1253 return sb_watchpoint;
1254}
1255
1256bool SBTarget::EnableAllWatchpoints() {
1257 TargetSP target_sp(GetSP());
1258 if (target_sp) {
1259 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1260 std::unique_lock<std::recursive_mutex> lock;
1261 target_sp->GetWatchpointList().GetListMutex(lock);
1262 target_sp->EnableAllWatchpoints();
1263 return true;
1264 }
1265 return false;
1266}
1267
1268bool SBTarget::DisableAllWatchpoints() {
1269 TargetSP target_sp(GetSP());
1270 if (target_sp) {
1271 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1272 std::unique_lock<std::recursive_mutex> lock;
1273 target_sp->GetWatchpointList().GetListMutex(lock);
1274 target_sp->DisableAllWatchpoints();
1275 return true;
1276 }
1277 return false;
1278}
1279
1280SBValue SBTarget::CreateValueFromAddress(const char *name, SBAddress addr,
1281 SBType type) {
1282 SBValue sb_value;
1283 lldb::ValueObjectSP new_value_sp;
1284 if (IsValid() && name && *name && addr.IsValid() && type.IsValid()) {
1285 lldb::addr_t load_addr(addr.GetLoadAddress(*this));
1286 ExecutionContext exe_ctx(
1287 ExecutionContextRef(ExecutionContext(m_opaque_sp.get(), false)));
1288 CompilerType ast_type(type.GetSP()->GetCompilerType(true));
1289 new_value_sp = ValueObject::CreateValueObjectFromAddress(name, load_addr,
1290 exe_ctx, ast_type);
1291 }
1292 sb_value.SetSP(new_value_sp);
1293 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1294 if (log) {
1295 if (new_value_sp)
1296 log->Printf("SBTarget(%p)::CreateValueFromAddress => \"%s\"",
1297 static_cast<void *>(m_opaque_sp.get()),
1298 new_value_sp->GetName().AsCString());
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001299 else
Kate Stoneb9c1b512016-09-06 20:57:50 +00001300 log->Printf("SBTarget(%p)::CreateValueFromAddress => NULL",
1301 static_cast<void *>(m_opaque_sp.get()));
1302 }
1303 return sb_value;
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001304}
1305
Kate Stoneb9c1b512016-09-06 20:57:50 +00001306lldb::SBValue SBTarget::CreateValueFromData(const char *name, lldb::SBData data,
1307 lldb::SBType type) {
1308 SBValue sb_value;
1309 lldb::ValueObjectSP new_value_sp;
1310 if (IsValid() && name && *name && data.IsValid() && type.IsValid()) {
1311 DataExtractorSP extractor(*data);
1312 ExecutionContext exe_ctx(
1313 ExecutionContextRef(ExecutionContext(m_opaque_sp.get(), false)));
1314 CompilerType ast_type(type.GetSP()->GetCompilerType(true));
1315 new_value_sp = ValueObject::CreateValueObjectFromData(name, *extractor,
1316 exe_ctx, ast_type);
1317 }
1318 sb_value.SetSP(new_value_sp);
1319 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1320 if (log) {
1321 if (new_value_sp)
1322 log->Printf("SBTarget(%p)::CreateValueFromData => \"%s\"",
1323 static_cast<void *>(m_opaque_sp.get()),
1324 new_value_sp->GetName().AsCString());
1325 else
1326 log->Printf("SBTarget(%p)::CreateValueFromData => NULL",
1327 static_cast<void *>(m_opaque_sp.get()));
1328 }
1329 return sb_value;
Greg Claytone14e1922012-12-04 02:22:16 +00001330}
1331
Kate Stoneb9c1b512016-09-06 20:57:50 +00001332lldb::SBValue SBTarget::CreateValueFromExpression(const char *name,
1333 const char *expr) {
1334 SBValue sb_value;
1335 lldb::ValueObjectSP new_value_sp;
1336 if (IsValid() && name && *name && expr && *expr) {
1337 ExecutionContext exe_ctx(
1338 ExecutionContextRef(ExecutionContext(m_opaque_sp.get(), false)));
1339 new_value_sp =
1340 ValueObject::CreateValueObjectFromExpression(name, expr, exe_ctx);
1341 }
1342 sb_value.SetSP(new_value_sp);
1343 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1344 if (log) {
1345 if (new_value_sp)
1346 log->Printf("SBTarget(%p)::CreateValueFromExpression => \"%s\"",
1347 static_cast<void *>(m_opaque_sp.get()),
1348 new_value_sp->GetName().AsCString());
1349 else
1350 log->Printf("SBTarget(%p)::CreateValueFromExpression => NULL",
1351 static_cast<void *>(m_opaque_sp.get()));
1352 }
1353 return sb_value;
1354}
1355
1356bool SBTarget::DeleteAllWatchpoints() {
1357 TargetSP target_sp(GetSP());
1358 if (target_sp) {
1359 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1360 std::unique_lock<std::recursive_mutex> lock;
1361 target_sp->GetWatchpointList().GetListMutex(lock);
1362 target_sp->RemoveAllWatchpoints();
1363 return true;
1364 }
1365 return false;
1366}
1367
1368lldb::SBModule SBTarget::AddModule(const char *path, const char *triple,
1369 const char *uuid_cstr) {
1370 return AddModule(path, triple, uuid_cstr, NULL);
1371}
1372
1373lldb::SBModule SBTarget::AddModule(const char *path, const char *triple,
1374 const char *uuid_cstr, const char *symfile) {
1375 lldb::SBModule sb_module;
1376 TargetSP target_sp(GetSP());
1377 if (target_sp) {
1378 ModuleSpec module_spec;
1379 if (path)
1380 module_spec.GetFileSpec().SetFile(path, false);
1381
1382 if (uuid_cstr)
1383 module_spec.GetUUID().SetFromCString(uuid_cstr);
1384
1385 if (triple)
1386 module_spec.GetArchitecture().SetTriple(triple,
1387 target_sp->GetPlatform().get());
1388 else
1389 module_spec.GetArchitecture() = target_sp->GetArchitecture();
1390
1391 if (symfile)
1392 module_spec.GetSymbolFileSpec().SetFile(symfile, false);
1393
1394 sb_module.SetSP(target_sp->GetSharedModule(module_spec));
1395 }
1396 return sb_module;
1397}
1398
1399lldb::SBModule SBTarget::AddModule(const SBModuleSpec &module_spec) {
1400 lldb::SBModule sb_module;
1401 TargetSP target_sp(GetSP());
1402 if (target_sp)
1403 sb_module.SetSP(target_sp->GetSharedModule(*module_spec.m_opaque_ap));
1404 return sb_module;
1405}
1406
1407bool SBTarget::AddModule(lldb::SBModule &module) {
1408 TargetSP target_sp(GetSP());
1409 if (target_sp) {
1410 target_sp->GetImages().AppendIfNeeded(module.GetSP());
1411 return true;
1412 }
1413 return false;
1414}
1415
1416uint32_t SBTarget::GetNumModules() const {
1417 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1418
1419 uint32_t num = 0;
1420 TargetSP target_sp(GetSP());
1421 if (target_sp) {
1422 // The module list is thread safe, no need to lock
1423 num = target_sp->GetImages().GetSize();
1424 }
1425
1426 if (log)
1427 log->Printf("SBTarget(%p)::GetNumModules () => %d",
1428 static_cast<void *>(target_sp.get()), num);
1429
1430 return num;
1431}
1432
1433void SBTarget::Clear() {
1434 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1435
1436 if (log)
1437 log->Printf("SBTarget(%p)::Clear ()",
1438 static_cast<void *>(m_opaque_sp.get()));
1439
1440 m_opaque_sp.reset();
1441}
1442
1443SBModule SBTarget::FindModule(const SBFileSpec &sb_file_spec) {
1444 SBModule sb_module;
1445 TargetSP target_sp(GetSP());
1446 if (target_sp && sb_file_spec.IsValid()) {
1447 ModuleSpec module_spec(*sb_file_spec);
1448 // The module list is thread safe, no need to lock
1449 sb_module.SetSP(target_sp->GetImages().FindFirstModule(module_spec));
1450 }
1451 return sb_module;
1452}
1453
1454lldb::ByteOrder SBTarget::GetByteOrder() {
1455 TargetSP target_sp(GetSP());
1456 if (target_sp)
1457 return target_sp->GetArchitecture().GetByteOrder();
1458 return eByteOrderInvalid;
1459}
1460
1461const char *SBTarget::GetTriple() {
1462 TargetSP target_sp(GetSP());
1463 if (target_sp) {
1464 std::string triple(target_sp->GetArchitecture().GetTriple().str());
1465 // Unique the string so we don't run into ownership issues since
1466 // the const strings put the string into the string pool once and
1467 // the strings never comes out
1468 ConstString const_triple(triple.c_str());
1469 return const_triple.GetCString();
1470 }
1471 return NULL;
1472}
1473
1474uint32_t SBTarget::GetDataByteSize() {
1475 TargetSP target_sp(GetSP());
1476 if (target_sp) {
1477 return target_sp->GetArchitecture().GetDataByteSize();
1478 }
1479 return 0;
1480}
1481
1482uint32_t SBTarget::GetCodeByteSize() {
1483 TargetSP target_sp(GetSP());
1484 if (target_sp) {
1485 return target_sp->GetArchitecture().GetCodeByteSize();
1486 }
1487 return 0;
1488}
1489
1490uint32_t SBTarget::GetAddressByteSize() {
1491 TargetSP target_sp(GetSP());
1492 if (target_sp)
1493 return target_sp->GetArchitecture().GetAddressByteSize();
1494 return sizeof(void *);
1495}
1496
1497SBModule SBTarget::GetModuleAtIndex(uint32_t idx) {
1498 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1499
1500 SBModule sb_module;
1501 ModuleSP module_sp;
1502 TargetSP target_sp(GetSP());
1503 if (target_sp) {
1504 // The module list is thread safe, no need to lock
1505 module_sp = target_sp->GetImages().GetModuleAtIndex(idx);
1506 sb_module.SetSP(module_sp);
1507 }
1508
1509 if (log)
1510 log->Printf("SBTarget(%p)::GetModuleAtIndex (idx=%d) => SBModule(%p)",
1511 static_cast<void *>(target_sp.get()), idx,
1512 static_cast<void *>(module_sp.get()));
1513
1514 return sb_module;
1515}
1516
1517bool SBTarget::RemoveModule(lldb::SBModule module) {
1518 TargetSP target_sp(GetSP());
1519 if (target_sp)
1520 return target_sp->GetImages().Remove(module.GetSP());
1521 return false;
1522}
1523
1524SBBroadcaster SBTarget::GetBroadcaster() const {
1525 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1526
1527 TargetSP target_sp(GetSP());
1528 SBBroadcaster broadcaster(target_sp.get(), false);
1529
1530 if (log)
1531 log->Printf("SBTarget(%p)::GetBroadcaster () => SBBroadcaster(%p)",
1532 static_cast<void *>(target_sp.get()),
1533 static_cast<void *>(broadcaster.get()));
1534
1535 return broadcaster;
1536}
1537
1538bool SBTarget::GetDescription(SBStream &description,
1539 lldb::DescriptionLevel description_level) {
1540 Stream &strm = description.ref();
1541
1542 TargetSP target_sp(GetSP());
1543 if (target_sp) {
1544 target_sp->Dump(&strm, description_level);
1545 } else
1546 strm.PutCString("No value");
1547
1548 return true;
1549}
1550
1551lldb::SBSymbolContextList SBTarget::FindFunctions(const char *name,
1552 uint32_t name_type_mask) {
1553 lldb::SBSymbolContextList sb_sc_list;
1554 if (name && name[0]) {
Jim Ingham763b2b22015-07-07 22:12:17 +00001555 TargetSP target_sp(GetSP());
Kate Stoneb9c1b512016-09-06 20:57:50 +00001556 if (target_sp) {
1557 const bool symbols_ok = true;
1558 const bool inlines_ok = true;
1559 const bool append = true;
1560 target_sp->GetImages().FindFunctions(ConstString(name), name_type_mask,
1561 symbols_ok, inlines_ok, append,
1562 *sb_sc_list);
1563 }
1564 }
1565 return sb_sc_list;
Jim Ingham763b2b22015-07-07 22:12:17 +00001566}
Greg Claytone14e1922012-12-04 02:22:16 +00001567
Kate Stoneb9c1b512016-09-06 20:57:50 +00001568lldb::SBSymbolContextList SBTarget::FindGlobalFunctions(const char *name,
1569 uint32_t max_matches,
1570 MatchType matchtype) {
1571 lldb::SBSymbolContextList sb_sc_list;
1572 if (name && name[0]) {
1573 TargetSP target_sp(GetSP());
1574 if (target_sp) {
1575 std::string regexstr;
1576 switch (matchtype) {
1577 case eMatchTypeRegex:
1578 target_sp->GetImages().FindFunctions(RegularExpression(name), true,
1579 true, true, *sb_sc_list);
1580 break;
1581 case eMatchTypeStartsWith:
1582 regexstr = llvm::Regex::escape(name) + ".*";
1583 target_sp->GetImages().FindFunctions(
1584 RegularExpression(regexstr.c_str()), true, true, true, *sb_sc_list);
1585 break;
1586 default:
1587 target_sp->GetImages().FindFunctions(ConstString(name),
1588 eFunctionNameTypeAny, true, true,
1589 true, *sb_sc_list);
1590 break;
1591 }
1592 }
1593 }
1594 return sb_sc_list;
1595}
1596
1597lldb::SBType SBTarget::FindFirstType(const char *typename_cstr) {
1598 TargetSP target_sp(GetSP());
1599 if (typename_cstr && typename_cstr[0] && target_sp) {
1600 ConstString const_typename(typename_cstr);
1601 SymbolContext sc;
1602 const bool exact_match = false;
1603
1604 const ModuleList &module_list = target_sp->GetImages();
1605 size_t count = module_list.GetSize();
1606 for (size_t idx = 0; idx < count; idx++) {
1607 ModuleSP module_sp(module_list.GetModuleAtIndex(idx));
1608 if (module_sp) {
1609 TypeSP type_sp(
1610 module_sp->FindFirstType(sc, const_typename, exact_match));
1611 if (type_sp)
1612 return SBType(type_sp);
1613 }
1614 }
1615
1616 // Didn't find the type in the symbols; try the Objective-C runtime
1617 // if one is installed
1618
1619 ProcessSP process_sp(target_sp->GetProcessSP());
1620
1621 if (process_sp) {
1622 ObjCLanguageRuntime *objc_language_runtime =
1623 process_sp->GetObjCLanguageRuntime();
1624
1625 if (objc_language_runtime) {
1626 DeclVendor *objc_decl_vendor = objc_language_runtime->GetDeclVendor();
1627
1628 if (objc_decl_vendor) {
1629 std::vector<clang::NamedDecl *> decls;
1630
1631 if (objc_decl_vendor->FindDecls(const_typename, true, 1, decls) > 0) {
1632 if (CompilerType type = ClangASTContext::GetTypeForDecl(decls[0])) {
1633 return SBType(type);
1634 }
1635 }
1636 }
1637 }
1638 }
1639
1640 // No matches, search for basic typename matches
1641 ClangASTContext *clang_ast = target_sp->GetScratchClangASTContext();
1642 if (clang_ast)
1643 return SBType(ClangASTContext::GetBasicType(clang_ast->getASTContext(),
1644 const_typename));
1645 }
1646 return SBType();
1647}
1648
1649SBType SBTarget::GetBasicType(lldb::BasicType type) {
1650 TargetSP target_sp(GetSP());
1651 if (target_sp) {
1652 ClangASTContext *clang_ast = target_sp->GetScratchClangASTContext();
1653 if (clang_ast)
1654 return SBType(
1655 ClangASTContext::GetBasicType(clang_ast->getASTContext(), type));
1656 }
1657 return SBType();
1658}
1659
1660lldb::SBTypeList SBTarget::FindTypes(const char *typename_cstr) {
1661 SBTypeList sb_type_list;
1662 TargetSP target_sp(GetSP());
1663 if (typename_cstr && typename_cstr[0] && target_sp) {
1664 ModuleList &images = target_sp->GetImages();
1665 ConstString const_typename(typename_cstr);
1666 bool exact_match = false;
1667 SymbolContext sc;
1668 TypeList type_list;
1669 llvm::DenseSet<SymbolFile *> searched_symbol_files;
1670 uint32_t num_matches =
1671 images.FindTypes(sc, const_typename, exact_match, UINT32_MAX,
1672 searched_symbol_files, type_list);
1673
1674 if (num_matches > 0) {
1675 for (size_t idx = 0; idx < num_matches; idx++) {
1676 TypeSP type_sp(type_list.GetTypeAtIndex(idx));
1677 if (type_sp)
1678 sb_type_list.Append(SBType(type_sp));
1679 }
1680 }
1681
1682 // Try the Objective-C runtime if one is installed
1683
1684 ProcessSP process_sp(target_sp->GetProcessSP());
1685
1686 if (process_sp) {
1687 ObjCLanguageRuntime *objc_language_runtime =
1688 process_sp->GetObjCLanguageRuntime();
1689
1690 if (objc_language_runtime) {
1691 DeclVendor *objc_decl_vendor = objc_language_runtime->GetDeclVendor();
1692
1693 if (objc_decl_vendor) {
1694 std::vector<clang::NamedDecl *> decls;
1695
1696 if (objc_decl_vendor->FindDecls(const_typename, true, 1, decls) > 0) {
1697 for (clang::NamedDecl *decl : decls) {
1698 if (CompilerType type = ClangASTContext::GetTypeForDecl(decl)) {
1699 sb_type_list.Append(SBType(type));
1700 }
1701 }
1702 }
1703 }
1704 }
1705 }
1706
1707 if (sb_type_list.GetSize() == 0) {
1708 // No matches, search for basic typename matches
1709 ClangASTContext *clang_ast = target_sp->GetScratchClangASTContext();
1710 if (clang_ast)
1711 sb_type_list.Append(SBType(ClangASTContext::GetBasicType(
1712 clang_ast->getASTContext(), const_typename)));
1713 }
1714 }
1715 return sb_type_list;
1716}
1717
1718SBValueList SBTarget::FindGlobalVariables(const char *name,
1719 uint32_t max_matches) {
1720 SBValueList sb_value_list;
1721
1722 TargetSP target_sp(GetSP());
1723 if (name && target_sp) {
1724 VariableList variable_list;
1725 const bool append = true;
1726 const uint32_t match_count = target_sp->GetImages().FindGlobalVariables(
1727 ConstString(name), append, max_matches, variable_list);
1728
1729 if (match_count > 0) {
1730 ExecutionContextScope *exe_scope = target_sp->GetProcessSP().get();
1731 if (exe_scope == NULL)
1732 exe_scope = target_sp.get();
1733 for (uint32_t i = 0; i < match_count; ++i) {
1734 lldb::ValueObjectSP valobj_sp(ValueObjectVariable::Create(
1735 exe_scope, variable_list.GetVariableAtIndex(i)));
1736 if (valobj_sp)
1737 sb_value_list.Append(SBValue(valobj_sp));
1738 }
1739 }
1740 }
1741
1742 return sb_value_list;
1743}
1744
1745SBValueList SBTarget::FindGlobalVariables(const char *name,
1746 uint32_t max_matches,
1747 MatchType matchtype) {
1748 SBValueList sb_value_list;
1749
1750 TargetSP target_sp(GetSP());
1751 if (name && target_sp) {
1752 VariableList variable_list;
1753 const bool append = true;
1754
1755 std::string regexstr;
1756 uint32_t match_count;
1757 switch (matchtype) {
1758 case eMatchTypeNormal:
1759 match_count = target_sp->GetImages().FindGlobalVariables(
1760 ConstString(name), append, max_matches, variable_list);
1761 break;
1762 case eMatchTypeRegex:
1763 match_count = target_sp->GetImages().FindGlobalVariables(
1764 RegularExpression(name), append, max_matches, variable_list);
1765 break;
1766 case eMatchTypeStartsWith:
1767 regexstr = llvm::Regex::escape(name) + ".*";
1768 match_count = target_sp->GetImages().FindGlobalVariables(
1769 RegularExpression(regexstr.c_str()), append, max_matches,
1770 variable_list);
1771 break;
1772 }
1773
1774 if (match_count > 0) {
1775 ExecutionContextScope *exe_scope = target_sp->GetProcessSP().get();
1776 if (exe_scope == NULL)
1777 exe_scope = target_sp.get();
1778 for (uint32_t i = 0; i < match_count; ++i) {
1779 lldb::ValueObjectSP valobj_sp(ValueObjectVariable::Create(
1780 exe_scope, variable_list.GetVariableAtIndex(i)));
1781 if (valobj_sp)
1782 sb_value_list.Append(SBValue(valobj_sp));
1783 }
1784 }
1785 }
1786
1787 return sb_value_list;
1788}
1789
1790lldb::SBValue SBTarget::FindFirstGlobalVariable(const char *name) {
1791 SBValueList sb_value_list(FindGlobalVariables(name, 1));
1792 if (sb_value_list.IsValid() && sb_value_list.GetSize() > 0)
1793 return sb_value_list.GetValueAtIndex(0);
1794 return SBValue();
1795}
1796
1797SBSourceManager SBTarget::GetSourceManager() {
1798 SBSourceManager source_manager(*this);
1799 return source_manager;
1800}
1801
1802lldb::SBInstructionList SBTarget::ReadInstructions(lldb::SBAddress base_addr,
1803 uint32_t count) {
1804 return ReadInstructions(base_addr, count, NULL);
1805}
1806
1807lldb::SBInstructionList SBTarget::ReadInstructions(lldb::SBAddress base_addr,
1808 uint32_t count,
1809 const char *flavor_string) {
1810 SBInstructionList sb_instructions;
1811
1812 TargetSP target_sp(GetSP());
1813 if (target_sp) {
1814 Address *addr_ptr = base_addr.get();
1815
1816 if (addr_ptr) {
1817 DataBufferHeap data(
1818 target_sp->GetArchitecture().GetMaximumOpcodeByteSize() * count, 0);
1819 bool prefer_file_cache = false;
1820 lldb_private::Error error;
1821 lldb::addr_t load_addr = LLDB_INVALID_ADDRESS;
1822 const size_t bytes_read =
1823 target_sp->ReadMemory(*addr_ptr, prefer_file_cache, data.GetBytes(),
1824 data.GetByteSize(), error, &load_addr);
1825 const bool data_from_file = load_addr == LLDB_INVALID_ADDRESS;
1826 sb_instructions.SetDisassembler(Disassembler::DisassembleBytes(
1827 target_sp->GetArchitecture(), NULL, flavor_string, *addr_ptr,
1828 data.GetBytes(), bytes_read, count, data_from_file));
1829 }
1830 }
1831
1832 return sb_instructions;
1833}
1834
1835lldb::SBInstructionList SBTarget::GetInstructions(lldb::SBAddress base_addr,
1836 const void *buf,
1837 size_t size) {
1838 return GetInstructionsWithFlavor(base_addr, NULL, buf, size);
1839}
1840
1841lldb::SBInstructionList
1842SBTarget::GetInstructionsWithFlavor(lldb::SBAddress base_addr,
1843 const char *flavor_string, const void *buf,
1844 size_t size) {
1845 SBInstructionList sb_instructions;
1846
1847 TargetSP target_sp(GetSP());
1848 if (target_sp) {
1849 Address addr;
1850
1851 if (base_addr.get())
1852 addr = *base_addr.get();
1853
1854 const bool data_from_file = true;
1855
1856 sb_instructions.SetDisassembler(Disassembler::DisassembleBytes(
1857 target_sp->GetArchitecture(), NULL, flavor_string, addr, buf, size,
1858 UINT32_MAX, data_from_file));
1859 }
1860
1861 return sb_instructions;
1862}
1863
1864lldb::SBInstructionList SBTarget::GetInstructions(lldb::addr_t base_addr,
1865 const void *buf,
1866 size_t size) {
1867 return GetInstructionsWithFlavor(ResolveLoadAddress(base_addr), NULL, buf,
1868 size);
1869}
1870
1871lldb::SBInstructionList
1872SBTarget::GetInstructionsWithFlavor(lldb::addr_t base_addr,
1873 const char *flavor_string, const void *buf,
1874 size_t size) {
1875 return GetInstructionsWithFlavor(ResolveLoadAddress(base_addr), flavor_string,
1876 buf, size);
1877}
1878
1879SBError SBTarget::SetSectionLoadAddress(lldb::SBSection section,
1880 lldb::addr_t section_base_addr) {
1881 SBError sb_error;
1882 TargetSP target_sp(GetSP());
1883 if (target_sp) {
1884 if (!section.IsValid()) {
1885 sb_error.SetErrorStringWithFormat("invalid section");
1886 } else {
1887 SectionSP section_sp(section.GetSP());
1888 if (section_sp) {
1889 if (section_sp->IsThreadSpecific()) {
1890 sb_error.SetErrorString(
1891 "thread specific sections are not yet supported");
1892 } else {
1893 ProcessSP process_sp(target_sp->GetProcessSP());
1894 if (target_sp->SetSectionLoadAddress(section_sp, section_base_addr)) {
1895 ModuleSP module_sp(section_sp->GetModule());
1896 if (module_sp) {
1897 ModuleList module_list;
1898 module_list.Append(module_sp);
1899 target_sp->ModulesDidLoad(module_list);
1900 }
1901 // Flush info in the process (stack frames, etc)
1902 if (process_sp)
1903 process_sp->Flush();
1904 }
1905 }
1906 }
1907 }
1908 } else {
1909 sb_error.SetErrorString("invalid target");
1910 }
1911 return sb_error;
1912}
1913
1914SBError SBTarget::ClearSectionLoadAddress(lldb::SBSection section) {
1915 SBError sb_error;
1916
1917 TargetSP target_sp(GetSP());
1918 if (target_sp) {
1919 if (!section.IsValid()) {
1920 sb_error.SetErrorStringWithFormat("invalid section");
1921 } else {
1922 SectionSP section_sp(section.GetSP());
1923 if (section_sp) {
1924 ProcessSP process_sp(target_sp->GetProcessSP());
1925 if (target_sp->SetSectionUnloaded(section_sp)) {
1926 ModuleSP module_sp(section_sp->GetModule());
1927 if (module_sp) {
1928 ModuleList module_list;
1929 module_list.Append(module_sp);
1930 target_sp->ModulesDidUnload(module_list, false);
1931 }
1932 // Flush info in the process (stack frames, etc)
1933 if (process_sp)
1934 process_sp->Flush();
1935 }
1936 } else {
1937 sb_error.SetErrorStringWithFormat("invalid section");
1938 }
1939 }
1940 } else {
1941 sb_error.SetErrorStringWithFormat("invalid target");
1942 }
1943 return sb_error;
1944}
1945
1946SBError SBTarget::SetModuleLoadAddress(lldb::SBModule module,
1947 int64_t slide_offset) {
1948 SBError sb_error;
1949
1950 TargetSP target_sp(GetSP());
1951 if (target_sp) {
1952 ModuleSP module_sp(module.GetSP());
1953 if (module_sp) {
1954 bool changed = false;
1955 if (module_sp->SetLoadAddress(*target_sp, slide_offset, true, changed)) {
1956 // The load was successful, make sure that at least some sections
1957 // changed before we notify that our module was loaded.
1958 if (changed) {
1959 ModuleList module_list;
1960 module_list.Append(module_sp);
1961 target_sp->ModulesDidLoad(module_list);
1962 // Flush info in the process (stack frames, etc)
1963 ProcessSP process_sp(target_sp->GetProcessSP());
1964 if (process_sp)
1965 process_sp->Flush();
1966 }
1967 }
1968 } else {
1969 sb_error.SetErrorStringWithFormat("invalid module");
1970 }
1971
1972 } else {
1973 sb_error.SetErrorStringWithFormat("invalid target");
1974 }
1975 return sb_error;
1976}
1977
1978SBError SBTarget::ClearModuleLoadAddress(lldb::SBModule module) {
1979 SBError sb_error;
1980
1981 char path[PATH_MAX];
1982 TargetSP target_sp(GetSP());
1983 if (target_sp) {
1984 ModuleSP module_sp(module.GetSP());
1985 if (module_sp) {
1986 ObjectFile *objfile = module_sp->GetObjectFile();
1987 if (objfile) {
1988 SectionList *section_list = objfile->GetSectionList();
1989 if (section_list) {
1990 ProcessSP process_sp(target_sp->GetProcessSP());
1991
1992 bool changed = false;
1993 const size_t num_sections = section_list->GetSize();
1994 for (size_t sect_idx = 0; sect_idx < num_sections; ++sect_idx) {
1995 SectionSP section_sp(section_list->GetSectionAtIndex(sect_idx));
1996 if (section_sp)
1997 changed |= target_sp->SetSectionUnloaded(section_sp);
1998 }
1999 if (changed) {
2000 ModuleList module_list;
2001 module_list.Append(module_sp);
2002 target_sp->ModulesDidUnload(module_list, false);
2003 // Flush info in the process (stack frames, etc)
2004 ProcessSP process_sp(target_sp->GetProcessSP());
2005 if (process_sp)
2006 process_sp->Flush();
2007 }
2008 } else {
2009 module_sp->GetFileSpec().GetPath(path, sizeof(path));
2010 sb_error.SetErrorStringWithFormat("no sections in object file '%s'",
2011 path);
2012 }
2013 } else {
2014 module_sp->GetFileSpec().GetPath(path, sizeof(path));
2015 sb_error.SetErrorStringWithFormat("no object file for module '%s'",
2016 path);
2017 }
2018 } else {
2019 sb_error.SetErrorStringWithFormat("invalid module");
2020 }
2021 } else {
2022 sb_error.SetErrorStringWithFormat("invalid target");
2023 }
2024 return sb_error;
2025}
2026
2027lldb::SBSymbolContextList SBTarget::FindSymbols(const char *name,
2028 lldb::SymbolType symbol_type) {
2029 SBSymbolContextList sb_sc_list;
2030 if (name && name[0]) {
2031 TargetSP target_sp(GetSP());
2032 if (target_sp) {
2033 bool append = true;
2034 target_sp->GetImages().FindSymbolsWithNameAndType(
2035 ConstString(name), symbol_type, *sb_sc_list, append);
2036 }
2037 }
2038 return sb_sc_list;
2039}
2040
2041lldb::SBValue SBTarget::EvaluateExpression(const char *expr) {
2042 TargetSP target_sp(GetSP());
2043 if (!target_sp)
2044 return SBValue();
2045
2046 SBExpressionOptions options;
2047 lldb::DynamicValueType fetch_dynamic_value =
2048 target_sp->GetPreferDynamicValue();
2049 options.SetFetchDynamicValue(fetch_dynamic_value);
2050 options.SetUnwindOnError(true);
2051 return EvaluateExpression(expr, options);
2052}
2053
2054lldb::SBValue SBTarget::EvaluateExpression(const char *expr,
2055 const SBExpressionOptions &options) {
2056 Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
Saleem Abdulrasool6010f972016-04-22 23:08:34 +00002057#if !defined(LLDB_DISABLE_PYTHON)
Kate Stoneb9c1b512016-09-06 20:57:50 +00002058 Log *expr_log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS));
Saleem Abdulrasool6010f972016-04-22 23:08:34 +00002059#endif
Kate Stoneb9c1b512016-09-06 20:57:50 +00002060 SBValue expr_result;
2061 ExpressionResults exe_results = eExpressionSetupError;
2062 ValueObjectSP expr_value_sp;
2063 TargetSP target_sp(GetSP());
2064 StackFrame *frame = NULL;
2065 if (target_sp) {
2066 if (expr == NULL || expr[0] == '\0') {
2067 if (log)
2068 log->Printf(
2069 "SBTarget::EvaluateExpression called with an empty expression");
2070 return expr_result;
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002071 }
Kate Stoneb9c1b512016-09-06 20:57:50 +00002072
2073 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
2074 ExecutionContext exe_ctx(m_opaque_sp.get());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002075
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002076 if (log)
Kate Stoneb9c1b512016-09-06 20:57:50 +00002077 log->Printf("SBTarget()::EvaluateExpression (expr=\"%s\")...", expr);
2078
2079 frame = exe_ctx.GetFramePtr();
2080 Target *target = exe_ctx.GetTargetPtr();
2081
2082 if (target) {
2083#ifdef LLDB_CONFIGURATION_DEBUG
2084 StreamString frame_description;
2085 if (frame)
2086 frame->DumpUsingSettingsFormat(&frame_description);
2087 Host::SetCrashDescriptionWithFormat(
2088 "SBTarget::EvaluateExpression (expr = \"%s\", fetch_dynamic_value = "
2089 "%u) %s",
2090 expr, options.GetFetchDynamicValue(),
2091 frame_description.GetString().c_str());
2092#endif
2093 exe_results =
2094 target->EvaluateExpression(expr, frame, expr_value_sp, options.ref());
2095
2096 expr_result.SetSP(expr_value_sp, options.GetFetchDynamicValue());
2097#ifdef LLDB_CONFIGURATION_DEBUG
2098 Host::SetCrashDescription(NULL);
2099#endif
2100 } else {
2101 if (log)
2102 log->Printf("SBTarget::EvaluateExpression () => error: could not "
2103 "reconstruct frame object for this SBTarget.");
2104 }
2105 }
2106#ifndef LLDB_DISABLE_PYTHON
2107 if (expr_log)
2108 expr_log->Printf("** [SBTarget::EvaluateExpression] Expression result is "
2109 "%s, summary %s **",
2110 expr_result.GetValue(), expr_result.GetSummary());
2111
2112 if (log)
2113 log->Printf("SBTarget(%p)::EvaluateExpression (expr=\"%s\") => SBValue(%p) "
2114 "(execution result=%d)",
2115 static_cast<void *>(frame), expr,
2116 static_cast<void *>(expr_value_sp.get()), exe_results);
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002117#endif
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002118
Kate Stoneb9c1b512016-09-06 20:57:50 +00002119 return expr_result;
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002120}
2121
Kate Stoneb9c1b512016-09-06 20:57:50 +00002122lldb::addr_t SBTarget::GetStackRedZoneSize() {
2123 TargetSP target_sp(GetSP());
2124 if (target_sp) {
2125 ABISP abi_sp;
2126 ProcessSP process_sp(target_sp->GetProcessSP());
2127 if (process_sp)
2128 abi_sp = process_sp->GetABI();
2129 else
2130 abi_sp = ABI::FindPlugin(target_sp->GetArchitecture());
2131 if (abi_sp)
2132 return abi_sp->GetRedZoneSize();
2133 }
2134 return 0;
Greg Clayton13fbb992013-02-01 00:47:49 +00002135}
Ilia K8f37ca52015-02-13 14:31:06 +00002136
Kate Stoneb9c1b512016-09-06 20:57:50 +00002137lldb::SBLaunchInfo SBTarget::GetLaunchInfo() const {
2138 lldb::SBLaunchInfo launch_info(NULL);
2139 TargetSP target_sp(GetSP());
2140 if (target_sp)
2141 launch_info.ref() = m_opaque_sp->GetProcessLaunchInfo();
2142 return launch_info;
Ilia K8f37ca52015-02-13 14:31:06 +00002143}
2144
Kate Stoneb9c1b512016-09-06 20:57:50 +00002145void SBTarget::SetLaunchInfo(const lldb::SBLaunchInfo &launch_info) {
2146 TargetSP target_sp(GetSP());
2147 if (target_sp)
2148 m_opaque_sp->SetProcessLaunchInfo(launch_info.ref());
Ilia K8f37ca52015-02-13 14:31:06 +00002149}