blob: 7cf9215aab81aeaf6c261a0d33437149d2065e8a [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) {
Jim Ingham92d19602016-09-20 22:54:49 +0000664 SBFileSpecList empty_list;
665 return BreakpointCreateByLocation(sb_file_spec, line, offset, empty_list);
666}
667
668SBBreakpoint
669SBTarget::BreakpointCreateByLocation(const SBFileSpec &sb_file_spec,
670 uint32_t line, lldb::addr_t offset,
671 SBFileSpecList &sb_module_list) {
Kate Stoneb9c1b512016-09-06 20:57:50 +0000672 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
Jim Ingham24111672016-03-09 18:59:13 +0000673
Kate Stoneb9c1b512016-09-06 20:57:50 +0000674 SBBreakpoint sb_bp;
675 TargetSP target_sp(GetSP());
676 if (target_sp && line != 0) {
677 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
Caroline Ticeceb6b132010-10-26 03:11:13 +0000678
Kate Stoneb9c1b512016-09-06 20:57:50 +0000679 const LazyBool check_inlines = eLazyBoolCalculate;
680 const LazyBool skip_prologue = eLazyBoolCalculate;
681 const bool internal = false;
682 const bool hardware = false;
683 const LazyBool move_to_nearest_code = eLazyBoolCalculate;
Jim Ingham92d19602016-09-20 22:54:49 +0000684 const FileSpecList *module_list = nullptr;
685 if (sb_module_list.GetSize() > 0) {
686 module_list = sb_module_list.get();
687 }
688 *sb_bp = target_sp->CreateBreakpoint(
689 module_list, *sb_file_spec, line, offset, check_inlines, skip_prologue,
690 internal, hardware, move_to_nearest_code);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000691 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000692
Kate Stoneb9c1b512016-09-06 20:57:50 +0000693 if (log) {
694 SBStream sstr;
695 sb_bp.GetDescription(sstr);
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000696 char path[PATH_MAX];
Kate Stoneb9c1b512016-09-06 20:57:50 +0000697 sb_file_spec->GetPath(path, sizeof(path));
698 log->Printf("SBTarget(%p)::BreakpointCreateByLocation ( %s:%u ) => "
699 "SBBreakpoint(%p): %s",
700 static_cast<void *>(target_sp.get()), path, line,
701 static_cast<void *>(sb_bp.get()), sstr.GetData());
702 }
Greg Claytond5944cd2013-12-06 01:12:00 +0000703
Kate Stoneb9c1b512016-09-06 20:57:50 +0000704 return sb_bp;
705}
706
707SBBreakpoint SBTarget::BreakpointCreateByName(const char *symbol_name,
708 const char *module_name) {
709 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
710
711 SBBreakpoint sb_bp;
712 TargetSP target_sp(GetSP());
713 if (target_sp.get()) {
714 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
715
716 const bool internal = false;
717 const bool hardware = false;
718 const LazyBool skip_prologue = eLazyBoolCalculate;
719 const lldb::addr_t offset = 0;
720 if (module_name && module_name[0]) {
721 FileSpecList module_spec_list;
722 module_spec_list.Append(FileSpec(module_name, false));
723 *sb_bp = target_sp->CreateBreakpoint(
724 &module_spec_list, NULL, symbol_name, eFunctionNameTypeAuto,
725 eLanguageTypeUnknown, offset, skip_prologue, internal, hardware);
726 } else {
727 *sb_bp = target_sp->CreateBreakpoint(
728 NULL, NULL, symbol_name, eFunctionNameTypeAuto, eLanguageTypeUnknown,
729 offset, skip_prologue, internal, hardware);
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000730 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000731 }
732
733 if (log)
734 log->Printf("SBTarget(%p)::BreakpointCreateByName (symbol=\"%s\", "
735 "module=\"%s\") => SBBreakpoint(%p)",
736 static_cast<void *>(target_sp.get()), symbol_name, module_name,
737 static_cast<void *>(sb_bp.get()));
738
739 return sb_bp;
740}
741
742lldb::SBBreakpoint
743SBTarget::BreakpointCreateByName(const char *symbol_name,
744 const SBFileSpecList &module_list,
745 const SBFileSpecList &comp_unit_list) {
746 uint32_t name_type_mask = eFunctionNameTypeAuto;
747 return BreakpointCreateByName(symbol_name, name_type_mask,
748 eLanguageTypeUnknown, module_list,
749 comp_unit_list);
750}
751
752lldb::SBBreakpoint SBTarget::BreakpointCreateByName(
753 const char *symbol_name, uint32_t name_type_mask,
754 const SBFileSpecList &module_list, const SBFileSpecList &comp_unit_list) {
755 return BreakpointCreateByName(symbol_name, name_type_mask,
756 eLanguageTypeUnknown, module_list,
757 comp_unit_list);
758}
759
760lldb::SBBreakpoint SBTarget::BreakpointCreateByName(
761 const char *symbol_name, uint32_t name_type_mask,
762 LanguageType symbol_language, const SBFileSpecList &module_list,
763 const SBFileSpecList &comp_unit_list) {
764 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
765
766 SBBreakpoint sb_bp;
767 TargetSP target_sp(GetSP());
768 if (target_sp && symbol_name && symbol_name[0]) {
769 const bool internal = false;
770 const bool hardware = false;
771 const LazyBool skip_prologue = eLazyBoolCalculate;
772 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
773 *sb_bp = target_sp->CreateBreakpoint(
774 module_list.get(), comp_unit_list.get(), symbol_name, name_type_mask,
775 symbol_language, 0, skip_prologue, internal, hardware);
776 }
777
778 if (log)
779 log->Printf("SBTarget(%p)::BreakpointCreateByName (symbol=\"%s\", "
780 "name_type: %d) => SBBreakpoint(%p)",
781 static_cast<void *>(target_sp.get()), symbol_name,
782 name_type_mask, static_cast<void *>(sb_bp.get()));
783
784 return sb_bp;
785}
786
787lldb::SBBreakpoint SBTarget::BreakpointCreateByNames(
788 const char *symbol_names[], uint32_t num_names, uint32_t name_type_mask,
789 const SBFileSpecList &module_list, const SBFileSpecList &comp_unit_list) {
790 return BreakpointCreateByNames(symbol_names, num_names, name_type_mask,
791 eLanguageTypeUnknown, module_list,
792 comp_unit_list);
793}
794
795lldb::SBBreakpoint SBTarget::BreakpointCreateByNames(
796 const char *symbol_names[], uint32_t num_names, uint32_t name_type_mask,
797 LanguageType symbol_language, const SBFileSpecList &module_list,
798 const SBFileSpecList &comp_unit_list) {
799 return BreakpointCreateByNames(symbol_names, num_names, name_type_mask,
800 eLanguageTypeUnknown, 0, module_list,
801 comp_unit_list);
802}
803
804lldb::SBBreakpoint SBTarget::BreakpointCreateByNames(
805 const char *symbol_names[], uint32_t num_names, uint32_t name_type_mask,
806 LanguageType symbol_language, lldb::addr_t offset,
807 const SBFileSpecList &module_list, const SBFileSpecList &comp_unit_list) {
808 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
809
810 SBBreakpoint sb_bp;
811 TargetSP target_sp(GetSP());
812 if (target_sp && num_names > 0) {
813 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
814 const bool internal = false;
815 const bool hardware = false;
816 const LazyBool skip_prologue = eLazyBoolCalculate;
817 *sb_bp = target_sp->CreateBreakpoint(
818 module_list.get(), comp_unit_list.get(), symbol_names, num_names,
819 name_type_mask, symbol_language, offset, skip_prologue, internal,
820 hardware);
821 }
822
823 if (log) {
824 log->Printf("SBTarget(%p)::BreakpointCreateByName (symbols={",
825 static_cast<void *>(target_sp.get()));
826 for (uint32_t i = 0; i < num_names; i++) {
827 char sep;
828 if (i < num_names - 1)
829 sep = ',';
830 else
831 sep = '}';
832 if (symbol_names[i] != NULL)
833 log->Printf("\"%s\"%c ", symbol_names[i], sep);
834 else
835 log->Printf("\"<NULL>\"%c ", sep);
836 }
837 log->Printf("name_type: %d) => SBBreakpoint(%p)", name_type_mask,
838 static_cast<void *>(sb_bp.get()));
839 }
840
841 return sb_bp;
842}
843
844SBBreakpoint SBTarget::BreakpointCreateByRegex(const char *symbol_name_regex,
845 const char *module_name) {
846 SBFileSpecList module_spec_list;
847 SBFileSpecList comp_unit_list;
848 if (module_name && module_name[0]) {
849 module_spec_list.Append(FileSpec(module_name, false));
850 }
851 return BreakpointCreateByRegex(symbol_name_regex, eLanguageTypeUnknown,
852 module_spec_list, comp_unit_list);
853}
854
855lldb::SBBreakpoint
856SBTarget::BreakpointCreateByRegex(const char *symbol_name_regex,
857 const SBFileSpecList &module_list,
858 const SBFileSpecList &comp_unit_list) {
859 return BreakpointCreateByRegex(symbol_name_regex, eLanguageTypeUnknown,
860 module_list, comp_unit_list);
861}
862
863lldb::SBBreakpoint SBTarget::BreakpointCreateByRegex(
864 const char *symbol_name_regex, LanguageType symbol_language,
865 const SBFileSpecList &module_list, const SBFileSpecList &comp_unit_list) {
866 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
867
868 SBBreakpoint sb_bp;
869 TargetSP target_sp(GetSP());
870 if (target_sp && symbol_name_regex && symbol_name_regex[0]) {
871 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
872 RegularExpression regexp(symbol_name_regex);
873 const bool internal = false;
874 const bool hardware = false;
875 const LazyBool skip_prologue = eLazyBoolCalculate;
876
877 *sb_bp = target_sp->CreateFuncRegexBreakpoint(
878 module_list.get(), comp_unit_list.get(), regexp, symbol_language,
879 skip_prologue, internal, hardware);
880 }
881
882 if (log)
883 log->Printf("SBTarget(%p)::BreakpointCreateByRegex (symbol_regex=\"%s\") "
884 "=> SBBreakpoint(%p)",
885 static_cast<void *>(target_sp.get()), symbol_name_regex,
886 static_cast<void *>(sb_bp.get()));
887
888 return sb_bp;
889}
890
891SBBreakpoint SBTarget::BreakpointCreateByAddress(addr_t address) {
892 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
893
894 SBBreakpoint sb_bp;
895 TargetSP target_sp(GetSP());
896 if (target_sp) {
897 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
898 const bool hardware = false;
899 *sb_bp = target_sp->CreateBreakpoint(address, false, hardware);
900 }
901
902 if (log)
903 log->Printf("SBTarget(%p)::BreakpointCreateByAddress (address=%" PRIu64
904 ") => SBBreakpoint(%p)",
905 static_cast<void *>(target_sp.get()),
906 static_cast<uint64_t>(address),
907 static_cast<void *>(sb_bp.get()));
908
909 return sb_bp;
910}
911
912SBBreakpoint SBTarget::BreakpointCreateBySBAddress(SBAddress &sb_address) {
913 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
914
915 SBBreakpoint sb_bp;
916 TargetSP target_sp(GetSP());
917 if (!sb_address.IsValid()) {
918 if (log)
919 log->Printf("SBTarget(%p)::BreakpointCreateBySBAddress called with "
920 "invalid address",
921 static_cast<void *>(target_sp.get()));
922 return sb_bp;
923 }
924
925 if (target_sp) {
926 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
927 const bool hardware = false;
928 *sb_bp = target_sp->CreateBreakpoint(sb_address.ref(), false, hardware);
929 }
930
931 if (log) {
932 SBStream s;
933 sb_address.GetDescription(s);
934 log->Printf("SBTarget(%p)::BreakpointCreateBySBAddress (address=%s) => "
935 "SBBreakpoint(%p)",
936 static_cast<void *>(target_sp.get()), s.GetData(),
937 static_cast<void *>(sb_bp.get()));
938 }
939
940 return sb_bp;
941}
942
943lldb::SBBreakpoint
944SBTarget::BreakpointCreateBySourceRegex(const char *source_regex,
945 const lldb::SBFileSpec &source_file,
946 const char *module_name) {
947 SBFileSpecList module_spec_list;
948
949 if (module_name && module_name[0]) {
950 module_spec_list.Append(FileSpec(module_name, false));
951 }
952
953 SBFileSpecList source_file_list;
954 if (source_file.IsValid()) {
955 source_file_list.Append(source_file);
956 }
957
958 return BreakpointCreateBySourceRegex(source_regex, module_spec_list,
959 source_file_list);
960}
961
962lldb::SBBreakpoint SBTarget::BreakpointCreateBySourceRegex(
963 const char *source_regex, const SBFileSpecList &module_list,
964 const lldb::SBFileSpecList &source_file_list) {
965 return BreakpointCreateBySourceRegex(source_regex, module_list,
966 source_file_list, SBStringList());
967}
968
969lldb::SBBreakpoint SBTarget::BreakpointCreateBySourceRegex(
970 const char *source_regex, const SBFileSpecList &module_list,
971 const lldb::SBFileSpecList &source_file_list,
972 const SBStringList &func_names) {
973 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
974
975 SBBreakpoint sb_bp;
976 TargetSP target_sp(GetSP());
977 if (target_sp && source_regex && source_regex[0]) {
978 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
979 const bool hardware = false;
980 const LazyBool move_to_nearest_code = eLazyBoolCalculate;
981 RegularExpression regexp(source_regex);
982 std::unordered_set<std::string> func_names_set;
983 for (size_t i = 0; i < func_names.GetSize(); i++) {
984 func_names_set.insert(func_names.GetStringAtIndex(i));
985 }
986
987 *sb_bp = target_sp->CreateSourceRegexBreakpoint(
988 module_list.get(), source_file_list.get(), func_names_set, regexp,
989 false, hardware, move_to_nearest_code);
990 }
991
992 if (log)
993 log->Printf("SBTarget(%p)::BreakpointCreateByRegex (source_regex=\"%s\") "
994 "=> SBBreakpoint(%p)",
995 static_cast<void *>(target_sp.get()), source_regex,
996 static_cast<void *>(sb_bp.get()));
997
998 return sb_bp;
999}
1000
1001lldb::SBBreakpoint
1002SBTarget::BreakpointCreateForException(lldb::LanguageType language,
1003 bool catch_bp, bool throw_bp) {
1004 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1005
1006 SBBreakpoint sb_bp;
1007 TargetSP target_sp(GetSP());
1008 if (target_sp) {
1009 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1010 const bool hardware = false;
1011 *sb_bp = target_sp->CreateExceptionBreakpoint(language, catch_bp, throw_bp,
1012 hardware);
1013 }
1014
1015 if (log)
1016 log->Printf("SBTarget(%p)::BreakpointCreateByRegex (Language: %s, catch: "
1017 "%s throw: %s) => SBBreakpoint(%p)",
1018 static_cast<void *>(target_sp.get()),
1019 Language::GetNameForLanguageType(language),
1020 catch_bp ? "on" : "off", throw_bp ? "on" : "off",
1021 static_cast<void *>(sb_bp.get()));
1022
1023 return sb_bp;
1024}
1025
1026uint32_t SBTarget::GetNumBreakpoints() const {
1027 TargetSP target_sp(GetSP());
1028 if (target_sp) {
1029 // The breakpoint list is thread safe, no need to lock
1030 return target_sp->GetBreakpointList().GetSize();
1031 }
1032 return 0;
1033}
1034
1035SBBreakpoint SBTarget::GetBreakpointAtIndex(uint32_t idx) const {
1036 SBBreakpoint sb_breakpoint;
1037 TargetSP target_sp(GetSP());
1038 if (target_sp) {
1039 // The breakpoint list is thread safe, no need to lock
1040 *sb_breakpoint = target_sp->GetBreakpointList().GetBreakpointAtIndex(idx);
1041 }
1042 return sb_breakpoint;
1043}
1044
1045bool SBTarget::BreakpointDelete(break_id_t bp_id) {
1046 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1047
1048 bool result = false;
1049 TargetSP target_sp(GetSP());
1050 if (target_sp) {
1051 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1052 result = target_sp->RemoveBreakpointByID(bp_id);
1053 }
1054
1055 if (log)
1056 log->Printf("SBTarget(%p)::BreakpointDelete (bp_id=%d) => %i",
1057 static_cast<void *>(target_sp.get()),
1058 static_cast<uint32_t>(bp_id), result);
1059
1060 return result;
1061}
1062
1063SBBreakpoint SBTarget::FindBreakpointByID(break_id_t bp_id) {
1064 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1065
1066 SBBreakpoint sb_breakpoint;
1067 TargetSP target_sp(GetSP());
1068 if (target_sp && bp_id != LLDB_INVALID_BREAK_ID) {
1069 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1070 *sb_breakpoint = target_sp->GetBreakpointByID(bp_id);
1071 }
1072
1073 if (log)
1074 log->Printf(
1075 "SBTarget(%p)::FindBreakpointByID (bp_id=%d) => SBBreakpoint(%p)",
1076 static_cast<void *>(target_sp.get()), static_cast<uint32_t>(bp_id),
1077 static_cast<void *>(sb_breakpoint.get()));
1078
1079 return sb_breakpoint;
1080}
1081
1082bool SBTarget::EnableAllBreakpoints() {
1083 TargetSP target_sp(GetSP());
1084 if (target_sp) {
1085 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1086 target_sp->EnableAllBreakpoints();
1087 return true;
1088 }
1089 return false;
1090}
1091
1092bool SBTarget::DisableAllBreakpoints() {
1093 TargetSP target_sp(GetSP());
1094 if (target_sp) {
1095 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1096 target_sp->DisableAllBreakpoints();
1097 return true;
1098 }
1099 return false;
1100}
1101
1102bool SBTarget::DeleteAllBreakpoints() {
1103 TargetSP target_sp(GetSP());
1104 if (target_sp) {
1105 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1106 target_sp->RemoveAllBreakpoints();
1107 return true;
1108 }
1109 return false;
1110}
1111
Jim Ingham01f16662016-09-14 19:07:35 +00001112lldb::SBError SBTarget::BreakpointsCreateFromFile(SBFileSpec &source_file,
1113 SBBreakpointList &new_bps) {
1114 SBError sberr;
1115 TargetSP target_sp(GetSP());
1116 if (!target_sp) {
1117 sberr.SetErrorString(
1118 "BreakpointCreateFromFile called with invalid target.");
1119 return sberr;
1120 }
1121 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1122
1123 BreakpointIDList bp_ids;
1124 sberr.ref() = target_sp->CreateBreakpointsFromFile(source_file.ref(), bp_ids);
1125 if (sberr.Fail())
1126 return sberr;
1127
1128 size_t num_bkpts = bp_ids.GetSize();
1129 for (size_t i = 0; i < num_bkpts; i++) {
1130 BreakpointID bp_id = bp_ids.GetBreakpointIDAtIndex(i);
1131 new_bps.AppendByID(bp_id.GetBreakpointID());
1132 }
1133 return sberr;
1134}
1135
1136lldb::SBError SBTarget::BreakpointsWriteToFile(SBFileSpec &dest_file) {
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 SBBreakpointList bkpt_list(*this);
1144 return BreakpointsWriteToFile(dest_file, bkpt_list);
1145}
1146
1147lldb::SBError SBTarget::BreakpointsWriteToFile(SBFileSpec &dest_file,
1148 SBBreakpointList &bkpt_list) {
1149 SBError sberr;
1150 TargetSP target_sp(GetSP());
1151 if (!target_sp) {
1152 sberr.SetErrorString("BreakpointWriteToFile called with invalid target.");
1153 return sberr;
1154 }
1155
1156 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1157 BreakpointIDList bp_id_list;
1158 bkpt_list.CopyToBreakpointIDList(bp_id_list);
1159 sberr.ref() =
1160 target_sp->SerializeBreakpointsToFile(dest_file.ref(), bp_id_list);
1161 return sberr;
1162}
1163
Kate Stoneb9c1b512016-09-06 20:57:50 +00001164uint32_t SBTarget::GetNumWatchpoints() const {
1165 TargetSP target_sp(GetSP());
1166 if (target_sp) {
1167 // The watchpoint list is thread safe, no need to lock
1168 return target_sp->GetWatchpointList().GetSize();
1169 }
1170 return 0;
1171}
1172
1173SBWatchpoint SBTarget::GetWatchpointAtIndex(uint32_t idx) const {
1174 SBWatchpoint sb_watchpoint;
1175 TargetSP target_sp(GetSP());
1176 if (target_sp) {
1177 // The watchpoint list is thread safe, no need to lock
1178 sb_watchpoint.SetSP(target_sp->GetWatchpointList().GetByIndex(idx));
1179 }
1180 return sb_watchpoint;
1181}
1182
1183bool SBTarget::DeleteWatchpoint(watch_id_t wp_id) {
1184 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1185
1186 bool result = false;
1187 TargetSP target_sp(GetSP());
1188 if (target_sp) {
1189 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1190 std::unique_lock<std::recursive_mutex> lock;
1191 target_sp->GetWatchpointList().GetListMutex(lock);
1192 result = target_sp->RemoveWatchpointByID(wp_id);
1193 }
1194
1195 if (log)
1196 log->Printf("SBTarget(%p)::WatchpointDelete (wp_id=%d) => %i",
1197 static_cast<void *>(target_sp.get()),
1198 static_cast<uint32_t>(wp_id), result);
1199
1200 return result;
1201}
1202
1203SBWatchpoint SBTarget::FindWatchpointByID(lldb::watch_id_t wp_id) {
1204 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1205
1206 SBWatchpoint sb_watchpoint;
1207 lldb::WatchpointSP watchpoint_sp;
1208 TargetSP target_sp(GetSP());
1209 if (target_sp && wp_id != LLDB_INVALID_WATCH_ID) {
1210 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1211 std::unique_lock<std::recursive_mutex> lock;
1212 target_sp->GetWatchpointList().GetListMutex(lock);
1213 watchpoint_sp = target_sp->GetWatchpointList().FindByID(wp_id);
1214 sb_watchpoint.SetSP(watchpoint_sp);
1215 }
1216
1217 if (log)
1218 log->Printf(
1219 "SBTarget(%p)::FindWatchpointByID (bp_id=%d) => SBWatchpoint(%p)",
1220 static_cast<void *>(target_sp.get()), static_cast<uint32_t>(wp_id),
1221 static_cast<void *>(watchpoint_sp.get()));
1222
1223 return sb_watchpoint;
1224}
1225
1226lldb::SBWatchpoint SBTarget::WatchAddress(lldb::addr_t addr, size_t size,
1227 bool read, bool write,
1228 SBError &error) {
1229 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1230
1231 SBWatchpoint sb_watchpoint;
1232 lldb::WatchpointSP watchpoint_sp;
1233 TargetSP target_sp(GetSP());
1234 if (target_sp && (read || write) && addr != LLDB_INVALID_ADDRESS &&
1235 size > 0) {
1236 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1237 uint32_t watch_type = 0;
1238 if (read)
1239 watch_type |= LLDB_WATCH_TYPE_READ;
1240 if (write)
1241 watch_type |= LLDB_WATCH_TYPE_WRITE;
1242 if (watch_type == 0) {
1243 error.SetErrorString(
1244 "Can't create a watchpoint that is neither read nor write.");
1245 return sb_watchpoint;
1246 }
1247
1248 // Target::CreateWatchpoint() is thread safe.
1249 Error cw_error;
1250 // This API doesn't take in a type, so we can't figure out what it is.
1251 CompilerType *type = NULL;
1252 watchpoint_sp =
1253 target_sp->CreateWatchpoint(addr, size, type, watch_type, cw_error);
1254 error.SetError(cw_error);
1255 sb_watchpoint.SetSP(watchpoint_sp);
1256 }
1257
1258 if (log)
1259 log->Printf("SBTarget(%p)::WatchAddress (addr=0x%" PRIx64
1260 ", 0x%u) => SBWatchpoint(%p)",
1261 static_cast<void *>(target_sp.get()), addr,
1262 static_cast<uint32_t>(size),
1263 static_cast<void *>(watchpoint_sp.get()));
1264
1265 return sb_watchpoint;
1266}
1267
1268bool SBTarget::EnableAllWatchpoints() {
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->EnableAllWatchpoints();
1275 return true;
1276 }
1277 return false;
1278}
1279
1280bool SBTarget::DisableAllWatchpoints() {
1281 TargetSP target_sp(GetSP());
1282 if (target_sp) {
1283 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1284 std::unique_lock<std::recursive_mutex> lock;
1285 target_sp->GetWatchpointList().GetListMutex(lock);
1286 target_sp->DisableAllWatchpoints();
1287 return true;
1288 }
1289 return false;
1290}
1291
1292SBValue SBTarget::CreateValueFromAddress(const char *name, SBAddress addr,
1293 SBType type) {
1294 SBValue sb_value;
1295 lldb::ValueObjectSP new_value_sp;
1296 if (IsValid() && name && *name && addr.IsValid() && type.IsValid()) {
1297 lldb::addr_t load_addr(addr.GetLoadAddress(*this));
1298 ExecutionContext exe_ctx(
1299 ExecutionContextRef(ExecutionContext(m_opaque_sp.get(), false)));
1300 CompilerType ast_type(type.GetSP()->GetCompilerType(true));
1301 new_value_sp = ValueObject::CreateValueObjectFromAddress(name, load_addr,
1302 exe_ctx, ast_type);
1303 }
1304 sb_value.SetSP(new_value_sp);
1305 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1306 if (log) {
1307 if (new_value_sp)
1308 log->Printf("SBTarget(%p)::CreateValueFromAddress => \"%s\"",
1309 static_cast<void *>(m_opaque_sp.get()),
1310 new_value_sp->GetName().AsCString());
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001311 else
Kate Stoneb9c1b512016-09-06 20:57:50 +00001312 log->Printf("SBTarget(%p)::CreateValueFromAddress => NULL",
1313 static_cast<void *>(m_opaque_sp.get()));
1314 }
1315 return sb_value;
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001316}
1317
Kate Stoneb9c1b512016-09-06 20:57:50 +00001318lldb::SBValue SBTarget::CreateValueFromData(const char *name, lldb::SBData data,
1319 lldb::SBType type) {
1320 SBValue sb_value;
1321 lldb::ValueObjectSP new_value_sp;
1322 if (IsValid() && name && *name && data.IsValid() && type.IsValid()) {
1323 DataExtractorSP extractor(*data);
1324 ExecutionContext exe_ctx(
1325 ExecutionContextRef(ExecutionContext(m_opaque_sp.get(), false)));
1326 CompilerType ast_type(type.GetSP()->GetCompilerType(true));
1327 new_value_sp = ValueObject::CreateValueObjectFromData(name, *extractor,
1328 exe_ctx, ast_type);
1329 }
1330 sb_value.SetSP(new_value_sp);
1331 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1332 if (log) {
1333 if (new_value_sp)
1334 log->Printf("SBTarget(%p)::CreateValueFromData => \"%s\"",
1335 static_cast<void *>(m_opaque_sp.get()),
1336 new_value_sp->GetName().AsCString());
1337 else
1338 log->Printf("SBTarget(%p)::CreateValueFromData => NULL",
1339 static_cast<void *>(m_opaque_sp.get()));
1340 }
1341 return sb_value;
Greg Claytone14e1922012-12-04 02:22:16 +00001342}
1343
Kate Stoneb9c1b512016-09-06 20:57:50 +00001344lldb::SBValue SBTarget::CreateValueFromExpression(const char *name,
1345 const char *expr) {
1346 SBValue sb_value;
1347 lldb::ValueObjectSP new_value_sp;
1348 if (IsValid() && name && *name && expr && *expr) {
1349 ExecutionContext exe_ctx(
1350 ExecutionContextRef(ExecutionContext(m_opaque_sp.get(), false)));
1351 new_value_sp =
1352 ValueObject::CreateValueObjectFromExpression(name, expr, exe_ctx);
1353 }
1354 sb_value.SetSP(new_value_sp);
1355 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1356 if (log) {
1357 if (new_value_sp)
1358 log->Printf("SBTarget(%p)::CreateValueFromExpression => \"%s\"",
1359 static_cast<void *>(m_opaque_sp.get()),
1360 new_value_sp->GetName().AsCString());
1361 else
1362 log->Printf("SBTarget(%p)::CreateValueFromExpression => NULL",
1363 static_cast<void *>(m_opaque_sp.get()));
1364 }
1365 return sb_value;
1366}
1367
1368bool SBTarget::DeleteAllWatchpoints() {
1369 TargetSP target_sp(GetSP());
1370 if (target_sp) {
1371 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1372 std::unique_lock<std::recursive_mutex> lock;
1373 target_sp->GetWatchpointList().GetListMutex(lock);
1374 target_sp->RemoveAllWatchpoints();
1375 return true;
1376 }
1377 return false;
1378}
1379
1380lldb::SBModule SBTarget::AddModule(const char *path, const char *triple,
1381 const char *uuid_cstr) {
1382 return AddModule(path, triple, uuid_cstr, NULL);
1383}
1384
1385lldb::SBModule SBTarget::AddModule(const char *path, const char *triple,
1386 const char *uuid_cstr, const char *symfile) {
1387 lldb::SBModule sb_module;
1388 TargetSP target_sp(GetSP());
1389 if (target_sp) {
1390 ModuleSpec module_spec;
1391 if (path)
1392 module_spec.GetFileSpec().SetFile(path, false);
1393
1394 if (uuid_cstr)
1395 module_spec.GetUUID().SetFromCString(uuid_cstr);
1396
1397 if (triple)
1398 module_spec.GetArchitecture().SetTriple(triple,
1399 target_sp->GetPlatform().get());
1400 else
1401 module_spec.GetArchitecture() = target_sp->GetArchitecture();
1402
1403 if (symfile)
1404 module_spec.GetSymbolFileSpec().SetFile(symfile, false);
1405
1406 sb_module.SetSP(target_sp->GetSharedModule(module_spec));
1407 }
1408 return sb_module;
1409}
1410
1411lldb::SBModule SBTarget::AddModule(const SBModuleSpec &module_spec) {
1412 lldb::SBModule sb_module;
1413 TargetSP target_sp(GetSP());
1414 if (target_sp)
1415 sb_module.SetSP(target_sp->GetSharedModule(*module_spec.m_opaque_ap));
1416 return sb_module;
1417}
1418
1419bool SBTarget::AddModule(lldb::SBModule &module) {
1420 TargetSP target_sp(GetSP());
1421 if (target_sp) {
1422 target_sp->GetImages().AppendIfNeeded(module.GetSP());
1423 return true;
1424 }
1425 return false;
1426}
1427
1428uint32_t SBTarget::GetNumModules() const {
1429 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1430
1431 uint32_t num = 0;
1432 TargetSP target_sp(GetSP());
1433 if (target_sp) {
1434 // The module list is thread safe, no need to lock
1435 num = target_sp->GetImages().GetSize();
1436 }
1437
1438 if (log)
1439 log->Printf("SBTarget(%p)::GetNumModules () => %d",
1440 static_cast<void *>(target_sp.get()), num);
1441
1442 return num;
1443}
1444
1445void SBTarget::Clear() {
1446 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1447
1448 if (log)
1449 log->Printf("SBTarget(%p)::Clear ()",
1450 static_cast<void *>(m_opaque_sp.get()));
1451
1452 m_opaque_sp.reset();
1453}
1454
1455SBModule SBTarget::FindModule(const SBFileSpec &sb_file_spec) {
1456 SBModule sb_module;
1457 TargetSP target_sp(GetSP());
1458 if (target_sp && sb_file_spec.IsValid()) {
1459 ModuleSpec module_spec(*sb_file_spec);
1460 // The module list is thread safe, no need to lock
1461 sb_module.SetSP(target_sp->GetImages().FindFirstModule(module_spec));
1462 }
1463 return sb_module;
1464}
1465
1466lldb::ByteOrder SBTarget::GetByteOrder() {
1467 TargetSP target_sp(GetSP());
1468 if (target_sp)
1469 return target_sp->GetArchitecture().GetByteOrder();
1470 return eByteOrderInvalid;
1471}
1472
1473const char *SBTarget::GetTriple() {
1474 TargetSP target_sp(GetSP());
1475 if (target_sp) {
1476 std::string triple(target_sp->GetArchitecture().GetTriple().str());
1477 // Unique the string so we don't run into ownership issues since
1478 // the const strings put the string into the string pool once and
1479 // the strings never comes out
1480 ConstString const_triple(triple.c_str());
1481 return const_triple.GetCString();
1482 }
1483 return NULL;
1484}
1485
1486uint32_t SBTarget::GetDataByteSize() {
1487 TargetSP target_sp(GetSP());
1488 if (target_sp) {
1489 return target_sp->GetArchitecture().GetDataByteSize();
1490 }
1491 return 0;
1492}
1493
1494uint32_t SBTarget::GetCodeByteSize() {
1495 TargetSP target_sp(GetSP());
1496 if (target_sp) {
1497 return target_sp->GetArchitecture().GetCodeByteSize();
1498 }
1499 return 0;
1500}
1501
1502uint32_t SBTarget::GetAddressByteSize() {
1503 TargetSP target_sp(GetSP());
1504 if (target_sp)
1505 return target_sp->GetArchitecture().GetAddressByteSize();
1506 return sizeof(void *);
1507}
1508
1509SBModule SBTarget::GetModuleAtIndex(uint32_t idx) {
1510 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1511
1512 SBModule sb_module;
1513 ModuleSP module_sp;
1514 TargetSP target_sp(GetSP());
1515 if (target_sp) {
1516 // The module list is thread safe, no need to lock
1517 module_sp = target_sp->GetImages().GetModuleAtIndex(idx);
1518 sb_module.SetSP(module_sp);
1519 }
1520
1521 if (log)
1522 log->Printf("SBTarget(%p)::GetModuleAtIndex (idx=%d) => SBModule(%p)",
1523 static_cast<void *>(target_sp.get()), idx,
1524 static_cast<void *>(module_sp.get()));
1525
1526 return sb_module;
1527}
1528
1529bool SBTarget::RemoveModule(lldb::SBModule module) {
1530 TargetSP target_sp(GetSP());
1531 if (target_sp)
1532 return target_sp->GetImages().Remove(module.GetSP());
1533 return false;
1534}
1535
1536SBBroadcaster SBTarget::GetBroadcaster() const {
1537 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1538
1539 TargetSP target_sp(GetSP());
1540 SBBroadcaster broadcaster(target_sp.get(), false);
1541
1542 if (log)
1543 log->Printf("SBTarget(%p)::GetBroadcaster () => SBBroadcaster(%p)",
1544 static_cast<void *>(target_sp.get()),
1545 static_cast<void *>(broadcaster.get()));
1546
1547 return broadcaster;
1548}
1549
1550bool SBTarget::GetDescription(SBStream &description,
1551 lldb::DescriptionLevel description_level) {
1552 Stream &strm = description.ref();
1553
1554 TargetSP target_sp(GetSP());
1555 if (target_sp) {
1556 target_sp->Dump(&strm, description_level);
1557 } else
1558 strm.PutCString("No value");
1559
1560 return true;
1561}
1562
1563lldb::SBSymbolContextList SBTarget::FindFunctions(const char *name,
1564 uint32_t name_type_mask) {
1565 lldb::SBSymbolContextList sb_sc_list;
1566 if (name && name[0]) {
Jim Ingham763b2b22015-07-07 22:12:17 +00001567 TargetSP target_sp(GetSP());
Kate Stoneb9c1b512016-09-06 20:57:50 +00001568 if (target_sp) {
1569 const bool symbols_ok = true;
1570 const bool inlines_ok = true;
1571 const bool append = true;
1572 target_sp->GetImages().FindFunctions(ConstString(name), name_type_mask,
1573 symbols_ok, inlines_ok, append,
1574 *sb_sc_list);
1575 }
1576 }
1577 return sb_sc_list;
Jim Ingham763b2b22015-07-07 22:12:17 +00001578}
Greg Claytone14e1922012-12-04 02:22:16 +00001579
Kate Stoneb9c1b512016-09-06 20:57:50 +00001580lldb::SBSymbolContextList SBTarget::FindGlobalFunctions(const char *name,
1581 uint32_t max_matches,
1582 MatchType matchtype) {
1583 lldb::SBSymbolContextList sb_sc_list;
1584 if (name && name[0]) {
1585 TargetSP target_sp(GetSP());
1586 if (target_sp) {
1587 std::string regexstr;
1588 switch (matchtype) {
1589 case eMatchTypeRegex:
1590 target_sp->GetImages().FindFunctions(RegularExpression(name), true,
1591 true, true, *sb_sc_list);
1592 break;
1593 case eMatchTypeStartsWith:
1594 regexstr = llvm::Regex::escape(name) + ".*";
1595 target_sp->GetImages().FindFunctions(
1596 RegularExpression(regexstr.c_str()), true, true, true, *sb_sc_list);
1597 break;
1598 default:
1599 target_sp->GetImages().FindFunctions(ConstString(name),
1600 eFunctionNameTypeAny, true, true,
1601 true, *sb_sc_list);
1602 break;
1603 }
1604 }
1605 }
1606 return sb_sc_list;
1607}
1608
1609lldb::SBType SBTarget::FindFirstType(const char *typename_cstr) {
1610 TargetSP target_sp(GetSP());
1611 if (typename_cstr && typename_cstr[0] && target_sp) {
1612 ConstString const_typename(typename_cstr);
1613 SymbolContext sc;
1614 const bool exact_match = false;
1615
1616 const ModuleList &module_list = target_sp->GetImages();
1617 size_t count = module_list.GetSize();
1618 for (size_t idx = 0; idx < count; idx++) {
1619 ModuleSP module_sp(module_list.GetModuleAtIndex(idx));
1620 if (module_sp) {
1621 TypeSP type_sp(
1622 module_sp->FindFirstType(sc, const_typename, exact_match));
1623 if (type_sp)
1624 return SBType(type_sp);
1625 }
1626 }
1627
1628 // Didn't find the type in the symbols; try the Objective-C runtime
1629 // if one is installed
1630
1631 ProcessSP process_sp(target_sp->GetProcessSP());
1632
1633 if (process_sp) {
1634 ObjCLanguageRuntime *objc_language_runtime =
1635 process_sp->GetObjCLanguageRuntime();
1636
1637 if (objc_language_runtime) {
1638 DeclVendor *objc_decl_vendor = objc_language_runtime->GetDeclVendor();
1639
1640 if (objc_decl_vendor) {
1641 std::vector<clang::NamedDecl *> decls;
1642
1643 if (objc_decl_vendor->FindDecls(const_typename, true, 1, decls) > 0) {
1644 if (CompilerType type = ClangASTContext::GetTypeForDecl(decls[0])) {
1645 return SBType(type);
1646 }
1647 }
1648 }
1649 }
1650 }
1651
1652 // No matches, search for basic typename matches
1653 ClangASTContext *clang_ast = target_sp->GetScratchClangASTContext();
1654 if (clang_ast)
1655 return SBType(ClangASTContext::GetBasicType(clang_ast->getASTContext(),
1656 const_typename));
1657 }
1658 return SBType();
1659}
1660
1661SBType SBTarget::GetBasicType(lldb::BasicType type) {
1662 TargetSP target_sp(GetSP());
1663 if (target_sp) {
1664 ClangASTContext *clang_ast = target_sp->GetScratchClangASTContext();
1665 if (clang_ast)
1666 return SBType(
1667 ClangASTContext::GetBasicType(clang_ast->getASTContext(), type));
1668 }
1669 return SBType();
1670}
1671
1672lldb::SBTypeList SBTarget::FindTypes(const char *typename_cstr) {
1673 SBTypeList sb_type_list;
1674 TargetSP target_sp(GetSP());
1675 if (typename_cstr && typename_cstr[0] && target_sp) {
1676 ModuleList &images = target_sp->GetImages();
1677 ConstString const_typename(typename_cstr);
1678 bool exact_match = false;
1679 SymbolContext sc;
1680 TypeList type_list;
1681 llvm::DenseSet<SymbolFile *> searched_symbol_files;
1682 uint32_t num_matches =
1683 images.FindTypes(sc, const_typename, exact_match, UINT32_MAX,
1684 searched_symbol_files, type_list);
1685
1686 if (num_matches > 0) {
1687 for (size_t idx = 0; idx < num_matches; idx++) {
1688 TypeSP type_sp(type_list.GetTypeAtIndex(idx));
1689 if (type_sp)
1690 sb_type_list.Append(SBType(type_sp));
1691 }
1692 }
1693
1694 // Try the Objective-C runtime if one is installed
1695
1696 ProcessSP process_sp(target_sp->GetProcessSP());
1697
1698 if (process_sp) {
1699 ObjCLanguageRuntime *objc_language_runtime =
1700 process_sp->GetObjCLanguageRuntime();
1701
1702 if (objc_language_runtime) {
1703 DeclVendor *objc_decl_vendor = objc_language_runtime->GetDeclVendor();
1704
1705 if (objc_decl_vendor) {
1706 std::vector<clang::NamedDecl *> decls;
1707
1708 if (objc_decl_vendor->FindDecls(const_typename, true, 1, decls) > 0) {
1709 for (clang::NamedDecl *decl : decls) {
1710 if (CompilerType type = ClangASTContext::GetTypeForDecl(decl)) {
1711 sb_type_list.Append(SBType(type));
1712 }
1713 }
1714 }
1715 }
1716 }
1717 }
1718
1719 if (sb_type_list.GetSize() == 0) {
1720 // No matches, search for basic typename matches
1721 ClangASTContext *clang_ast = target_sp->GetScratchClangASTContext();
1722 if (clang_ast)
1723 sb_type_list.Append(SBType(ClangASTContext::GetBasicType(
1724 clang_ast->getASTContext(), const_typename)));
1725 }
1726 }
1727 return sb_type_list;
1728}
1729
1730SBValueList SBTarget::FindGlobalVariables(const char *name,
1731 uint32_t max_matches) {
1732 SBValueList sb_value_list;
1733
1734 TargetSP target_sp(GetSP());
1735 if (name && target_sp) {
1736 VariableList variable_list;
1737 const bool append = true;
1738 const uint32_t match_count = target_sp->GetImages().FindGlobalVariables(
1739 ConstString(name), append, max_matches, variable_list);
1740
1741 if (match_count > 0) {
1742 ExecutionContextScope *exe_scope = target_sp->GetProcessSP().get();
1743 if (exe_scope == NULL)
1744 exe_scope = target_sp.get();
1745 for (uint32_t i = 0; i < match_count; ++i) {
1746 lldb::ValueObjectSP valobj_sp(ValueObjectVariable::Create(
1747 exe_scope, variable_list.GetVariableAtIndex(i)));
1748 if (valobj_sp)
1749 sb_value_list.Append(SBValue(valobj_sp));
1750 }
1751 }
1752 }
1753
1754 return sb_value_list;
1755}
1756
1757SBValueList SBTarget::FindGlobalVariables(const char *name,
1758 uint32_t max_matches,
1759 MatchType matchtype) {
1760 SBValueList sb_value_list;
1761
1762 TargetSP target_sp(GetSP());
1763 if (name && target_sp) {
1764 VariableList variable_list;
1765 const bool append = true;
1766
1767 std::string regexstr;
1768 uint32_t match_count;
1769 switch (matchtype) {
1770 case eMatchTypeNormal:
1771 match_count = target_sp->GetImages().FindGlobalVariables(
1772 ConstString(name), append, max_matches, variable_list);
1773 break;
1774 case eMatchTypeRegex:
1775 match_count = target_sp->GetImages().FindGlobalVariables(
1776 RegularExpression(name), append, max_matches, variable_list);
1777 break;
1778 case eMatchTypeStartsWith:
1779 regexstr = llvm::Regex::escape(name) + ".*";
1780 match_count = target_sp->GetImages().FindGlobalVariables(
1781 RegularExpression(regexstr.c_str()), append, max_matches,
1782 variable_list);
1783 break;
1784 }
1785
1786 if (match_count > 0) {
1787 ExecutionContextScope *exe_scope = target_sp->GetProcessSP().get();
1788 if (exe_scope == NULL)
1789 exe_scope = target_sp.get();
1790 for (uint32_t i = 0; i < match_count; ++i) {
1791 lldb::ValueObjectSP valobj_sp(ValueObjectVariable::Create(
1792 exe_scope, variable_list.GetVariableAtIndex(i)));
1793 if (valobj_sp)
1794 sb_value_list.Append(SBValue(valobj_sp));
1795 }
1796 }
1797 }
1798
1799 return sb_value_list;
1800}
1801
1802lldb::SBValue SBTarget::FindFirstGlobalVariable(const char *name) {
1803 SBValueList sb_value_list(FindGlobalVariables(name, 1));
1804 if (sb_value_list.IsValid() && sb_value_list.GetSize() > 0)
1805 return sb_value_list.GetValueAtIndex(0);
1806 return SBValue();
1807}
1808
1809SBSourceManager SBTarget::GetSourceManager() {
1810 SBSourceManager source_manager(*this);
1811 return source_manager;
1812}
1813
1814lldb::SBInstructionList SBTarget::ReadInstructions(lldb::SBAddress base_addr,
1815 uint32_t count) {
1816 return ReadInstructions(base_addr, count, NULL);
1817}
1818
1819lldb::SBInstructionList SBTarget::ReadInstructions(lldb::SBAddress base_addr,
1820 uint32_t count,
1821 const char *flavor_string) {
1822 SBInstructionList sb_instructions;
1823
1824 TargetSP target_sp(GetSP());
1825 if (target_sp) {
1826 Address *addr_ptr = base_addr.get();
1827
1828 if (addr_ptr) {
1829 DataBufferHeap data(
1830 target_sp->GetArchitecture().GetMaximumOpcodeByteSize() * count, 0);
1831 bool prefer_file_cache = false;
1832 lldb_private::Error error;
1833 lldb::addr_t load_addr = LLDB_INVALID_ADDRESS;
1834 const size_t bytes_read =
1835 target_sp->ReadMemory(*addr_ptr, prefer_file_cache, data.GetBytes(),
1836 data.GetByteSize(), error, &load_addr);
1837 const bool data_from_file = load_addr == LLDB_INVALID_ADDRESS;
1838 sb_instructions.SetDisassembler(Disassembler::DisassembleBytes(
1839 target_sp->GetArchitecture(), NULL, flavor_string, *addr_ptr,
1840 data.GetBytes(), bytes_read, count, data_from_file));
1841 }
1842 }
1843
1844 return sb_instructions;
1845}
1846
1847lldb::SBInstructionList SBTarget::GetInstructions(lldb::SBAddress base_addr,
1848 const void *buf,
1849 size_t size) {
1850 return GetInstructionsWithFlavor(base_addr, NULL, buf, size);
1851}
1852
1853lldb::SBInstructionList
1854SBTarget::GetInstructionsWithFlavor(lldb::SBAddress base_addr,
1855 const char *flavor_string, const void *buf,
1856 size_t size) {
1857 SBInstructionList sb_instructions;
1858
1859 TargetSP target_sp(GetSP());
1860 if (target_sp) {
1861 Address addr;
1862
1863 if (base_addr.get())
1864 addr = *base_addr.get();
1865
1866 const bool data_from_file = true;
1867
1868 sb_instructions.SetDisassembler(Disassembler::DisassembleBytes(
1869 target_sp->GetArchitecture(), NULL, flavor_string, addr, buf, size,
1870 UINT32_MAX, data_from_file));
1871 }
1872
1873 return sb_instructions;
1874}
1875
1876lldb::SBInstructionList SBTarget::GetInstructions(lldb::addr_t base_addr,
1877 const void *buf,
1878 size_t size) {
1879 return GetInstructionsWithFlavor(ResolveLoadAddress(base_addr), NULL, buf,
1880 size);
1881}
1882
1883lldb::SBInstructionList
1884SBTarget::GetInstructionsWithFlavor(lldb::addr_t base_addr,
1885 const char *flavor_string, const void *buf,
1886 size_t size) {
1887 return GetInstructionsWithFlavor(ResolveLoadAddress(base_addr), flavor_string,
1888 buf, size);
1889}
1890
1891SBError SBTarget::SetSectionLoadAddress(lldb::SBSection section,
1892 lldb::addr_t section_base_addr) {
1893 SBError sb_error;
1894 TargetSP target_sp(GetSP());
1895 if (target_sp) {
1896 if (!section.IsValid()) {
1897 sb_error.SetErrorStringWithFormat("invalid section");
1898 } else {
1899 SectionSP section_sp(section.GetSP());
1900 if (section_sp) {
1901 if (section_sp->IsThreadSpecific()) {
1902 sb_error.SetErrorString(
1903 "thread specific sections are not yet supported");
1904 } else {
1905 ProcessSP process_sp(target_sp->GetProcessSP());
1906 if (target_sp->SetSectionLoadAddress(section_sp, section_base_addr)) {
1907 ModuleSP module_sp(section_sp->GetModule());
1908 if (module_sp) {
1909 ModuleList module_list;
1910 module_list.Append(module_sp);
1911 target_sp->ModulesDidLoad(module_list);
1912 }
1913 // Flush info in the process (stack frames, etc)
1914 if (process_sp)
1915 process_sp->Flush();
1916 }
1917 }
1918 }
1919 }
1920 } else {
1921 sb_error.SetErrorString("invalid target");
1922 }
1923 return sb_error;
1924}
1925
1926SBError SBTarget::ClearSectionLoadAddress(lldb::SBSection section) {
1927 SBError sb_error;
1928
1929 TargetSP target_sp(GetSP());
1930 if (target_sp) {
1931 if (!section.IsValid()) {
1932 sb_error.SetErrorStringWithFormat("invalid section");
1933 } else {
1934 SectionSP section_sp(section.GetSP());
1935 if (section_sp) {
1936 ProcessSP process_sp(target_sp->GetProcessSP());
1937 if (target_sp->SetSectionUnloaded(section_sp)) {
1938 ModuleSP module_sp(section_sp->GetModule());
1939 if (module_sp) {
1940 ModuleList module_list;
1941 module_list.Append(module_sp);
1942 target_sp->ModulesDidUnload(module_list, false);
1943 }
1944 // Flush info in the process (stack frames, etc)
1945 if (process_sp)
1946 process_sp->Flush();
1947 }
1948 } else {
1949 sb_error.SetErrorStringWithFormat("invalid section");
1950 }
1951 }
1952 } else {
1953 sb_error.SetErrorStringWithFormat("invalid target");
1954 }
1955 return sb_error;
1956}
1957
1958SBError SBTarget::SetModuleLoadAddress(lldb::SBModule module,
1959 int64_t slide_offset) {
1960 SBError sb_error;
1961
1962 TargetSP target_sp(GetSP());
1963 if (target_sp) {
1964 ModuleSP module_sp(module.GetSP());
1965 if (module_sp) {
1966 bool changed = false;
1967 if (module_sp->SetLoadAddress(*target_sp, slide_offset, true, changed)) {
1968 // The load was successful, make sure that at least some sections
1969 // changed before we notify that our module was loaded.
1970 if (changed) {
1971 ModuleList module_list;
1972 module_list.Append(module_sp);
1973 target_sp->ModulesDidLoad(module_list);
1974 // Flush info in the process (stack frames, etc)
1975 ProcessSP process_sp(target_sp->GetProcessSP());
1976 if (process_sp)
1977 process_sp->Flush();
1978 }
1979 }
1980 } else {
1981 sb_error.SetErrorStringWithFormat("invalid module");
1982 }
1983
1984 } else {
1985 sb_error.SetErrorStringWithFormat("invalid target");
1986 }
1987 return sb_error;
1988}
1989
1990SBError SBTarget::ClearModuleLoadAddress(lldb::SBModule module) {
1991 SBError sb_error;
1992
1993 char path[PATH_MAX];
1994 TargetSP target_sp(GetSP());
1995 if (target_sp) {
1996 ModuleSP module_sp(module.GetSP());
1997 if (module_sp) {
1998 ObjectFile *objfile = module_sp->GetObjectFile();
1999 if (objfile) {
2000 SectionList *section_list = objfile->GetSectionList();
2001 if (section_list) {
2002 ProcessSP process_sp(target_sp->GetProcessSP());
2003
2004 bool changed = false;
2005 const size_t num_sections = section_list->GetSize();
2006 for (size_t sect_idx = 0; sect_idx < num_sections; ++sect_idx) {
2007 SectionSP section_sp(section_list->GetSectionAtIndex(sect_idx));
2008 if (section_sp)
2009 changed |= target_sp->SetSectionUnloaded(section_sp);
2010 }
2011 if (changed) {
2012 ModuleList module_list;
2013 module_list.Append(module_sp);
2014 target_sp->ModulesDidUnload(module_list, false);
2015 // Flush info in the process (stack frames, etc)
2016 ProcessSP process_sp(target_sp->GetProcessSP());
2017 if (process_sp)
2018 process_sp->Flush();
2019 }
2020 } else {
2021 module_sp->GetFileSpec().GetPath(path, sizeof(path));
2022 sb_error.SetErrorStringWithFormat("no sections in object file '%s'",
2023 path);
2024 }
2025 } else {
2026 module_sp->GetFileSpec().GetPath(path, sizeof(path));
2027 sb_error.SetErrorStringWithFormat("no object file for module '%s'",
2028 path);
2029 }
2030 } else {
2031 sb_error.SetErrorStringWithFormat("invalid module");
2032 }
2033 } else {
2034 sb_error.SetErrorStringWithFormat("invalid target");
2035 }
2036 return sb_error;
2037}
2038
2039lldb::SBSymbolContextList SBTarget::FindSymbols(const char *name,
2040 lldb::SymbolType symbol_type) {
2041 SBSymbolContextList sb_sc_list;
2042 if (name && name[0]) {
2043 TargetSP target_sp(GetSP());
2044 if (target_sp) {
2045 bool append = true;
2046 target_sp->GetImages().FindSymbolsWithNameAndType(
2047 ConstString(name), symbol_type, *sb_sc_list, append);
2048 }
2049 }
2050 return sb_sc_list;
2051}
2052
2053lldb::SBValue SBTarget::EvaluateExpression(const char *expr) {
2054 TargetSP target_sp(GetSP());
2055 if (!target_sp)
2056 return SBValue();
2057
2058 SBExpressionOptions options;
2059 lldb::DynamicValueType fetch_dynamic_value =
2060 target_sp->GetPreferDynamicValue();
2061 options.SetFetchDynamicValue(fetch_dynamic_value);
2062 options.SetUnwindOnError(true);
2063 return EvaluateExpression(expr, options);
2064}
2065
2066lldb::SBValue SBTarget::EvaluateExpression(const char *expr,
2067 const SBExpressionOptions &options) {
2068 Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
Saleem Abdulrasool6010f972016-04-22 23:08:34 +00002069#if !defined(LLDB_DISABLE_PYTHON)
Kate Stoneb9c1b512016-09-06 20:57:50 +00002070 Log *expr_log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS));
Saleem Abdulrasool6010f972016-04-22 23:08:34 +00002071#endif
Kate Stoneb9c1b512016-09-06 20:57:50 +00002072 SBValue expr_result;
2073 ExpressionResults exe_results = eExpressionSetupError;
2074 ValueObjectSP expr_value_sp;
2075 TargetSP target_sp(GetSP());
2076 StackFrame *frame = NULL;
2077 if (target_sp) {
2078 if (expr == NULL || expr[0] == '\0') {
2079 if (log)
2080 log->Printf(
2081 "SBTarget::EvaluateExpression called with an empty expression");
2082 return expr_result;
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002083 }
Kate Stoneb9c1b512016-09-06 20:57:50 +00002084
2085 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
2086 ExecutionContext exe_ctx(m_opaque_sp.get());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002087
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002088 if (log)
Kate Stoneb9c1b512016-09-06 20:57:50 +00002089 log->Printf("SBTarget()::EvaluateExpression (expr=\"%s\")...", expr);
2090
2091 frame = exe_ctx.GetFramePtr();
2092 Target *target = exe_ctx.GetTargetPtr();
2093
2094 if (target) {
2095#ifdef LLDB_CONFIGURATION_DEBUG
2096 StreamString frame_description;
2097 if (frame)
2098 frame->DumpUsingSettingsFormat(&frame_description);
2099 Host::SetCrashDescriptionWithFormat(
2100 "SBTarget::EvaluateExpression (expr = \"%s\", fetch_dynamic_value = "
2101 "%u) %s",
2102 expr, options.GetFetchDynamicValue(),
2103 frame_description.GetString().c_str());
2104#endif
2105 exe_results =
2106 target->EvaluateExpression(expr, frame, expr_value_sp, options.ref());
2107
2108 expr_result.SetSP(expr_value_sp, options.GetFetchDynamicValue());
2109#ifdef LLDB_CONFIGURATION_DEBUG
2110 Host::SetCrashDescription(NULL);
2111#endif
2112 } else {
2113 if (log)
2114 log->Printf("SBTarget::EvaluateExpression () => error: could not "
2115 "reconstruct frame object for this SBTarget.");
2116 }
2117 }
2118#ifndef LLDB_DISABLE_PYTHON
2119 if (expr_log)
2120 expr_log->Printf("** [SBTarget::EvaluateExpression] Expression result is "
2121 "%s, summary %s **",
2122 expr_result.GetValue(), expr_result.GetSummary());
2123
2124 if (log)
2125 log->Printf("SBTarget(%p)::EvaluateExpression (expr=\"%s\") => SBValue(%p) "
2126 "(execution result=%d)",
2127 static_cast<void *>(frame), expr,
2128 static_cast<void *>(expr_value_sp.get()), exe_results);
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002129#endif
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002130
Kate Stoneb9c1b512016-09-06 20:57:50 +00002131 return expr_result;
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002132}
2133
Kate Stoneb9c1b512016-09-06 20:57:50 +00002134lldb::addr_t SBTarget::GetStackRedZoneSize() {
2135 TargetSP target_sp(GetSP());
2136 if (target_sp) {
2137 ABISP abi_sp;
2138 ProcessSP process_sp(target_sp->GetProcessSP());
2139 if (process_sp)
2140 abi_sp = process_sp->GetABI();
2141 else
2142 abi_sp = ABI::FindPlugin(target_sp->GetArchitecture());
2143 if (abi_sp)
2144 return abi_sp->GetRedZoneSize();
2145 }
2146 return 0;
Greg Clayton13fbb992013-02-01 00:47:49 +00002147}
Ilia K8f37ca52015-02-13 14:31:06 +00002148
Kate Stoneb9c1b512016-09-06 20:57:50 +00002149lldb::SBLaunchInfo SBTarget::GetLaunchInfo() const {
2150 lldb::SBLaunchInfo launch_info(NULL);
2151 TargetSP target_sp(GetSP());
2152 if (target_sp)
2153 launch_info.ref() = m_opaque_sp->GetProcessLaunchInfo();
2154 return launch_info;
Ilia K8f37ca52015-02-13 14:31:06 +00002155}
2156
Kate Stoneb9c1b512016-09-06 20:57:50 +00002157void SBTarget::SetLaunchInfo(const lldb::SBLaunchInfo &launch_info) {
2158 TargetSP target_sp(GetSP());
2159 if (target_sp)
2160 m_opaque_sp->SetProcessLaunchInfo(launch_info.ref());
Ilia K8f37ca52015-02-13 14:31:06 +00002161}