blob: dc06e7c9e5e2150a47c8690645195c1a0528c960 [file] [log] [blame]
Chris Lattner24943d22010-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 Friedman7a62c8b2010-06-09 07:44:37 +000010#include "lldb/API/SBTarget.h"
Chris Lattner24943d22010-06-08 16:52:24 +000011
Greg Claytonb3448432011-03-24 21:19:54 +000012#include "lldb/lldb-public.h"
Chris Lattner24943d22010-06-08 16:52:24 +000013
Greg Clayton917c0002011-06-29 22:09:02 +000014#include "lldb/API/SBDebugger.h"
15#include "lldb/API/SBBreakpoint.h"
Chris Lattner24943d22010-06-08 16:52:24 +000016#include "lldb/API/SBFileSpec.h"
Greg Clayton917c0002011-06-29 22:09:02 +000017#include "lldb/API/SBListener.h"
Chris Lattner24943d22010-06-08 16:52:24 +000018#include "lldb/API/SBModule.h"
Jim Inghamcc637462011-09-13 00:29:56 +000019#include "lldb/API/SBSourceManager.h"
Greg Clayton917c0002011-06-29 22:09:02 +000020#include "lldb/API/SBProcess.h"
Caroline Tice98f930f2010-09-20 05:20:02 +000021#include "lldb/API/SBStream.h"
Greg Clayton4ed315f2011-06-21 01:34:41 +000022#include "lldb/API/SBSymbolContextList.h"
Chris Lattner24943d22010-06-08 16:52:24 +000023#include "lldb/Breakpoint/BreakpointID.h"
24#include "lldb/Breakpoint/BreakpointIDList.h"
25#include "lldb/Breakpoint/BreakpointList.h"
26#include "lldb/Breakpoint/BreakpointLocation.h"
27#include "lldb/Core/Address.h"
28#include "lldb/Core/AddressResolver.h"
29#include "lldb/Core/AddressResolverName.h"
Chris Lattner24943d22010-06-08 16:52:24 +000030#include "lldb/Core/ArchSpec.h"
31#include "lldb/Core/Debugger.h"
32#include "lldb/Core/Disassembler.h"
Caroline Tice7826c882010-10-26 03:11:13 +000033#include "lldb/Core/Log.h"
Chris Lattner24943d22010-06-08 16:52:24 +000034#include "lldb/Core/RegularExpression.h"
35#include "lldb/Core/SearchFilter.h"
36#include "lldb/Core/STLUtils.h"
Greg Clayton917c0002011-06-29 22:09:02 +000037#include "lldb/Core/ValueObjectList.h"
38#include "lldb/Core/ValueObjectVariable.h"
39#include "lldb/Host/FileSpec.h"
Greg Claytoncd548032011-02-01 01:31:41 +000040#include "lldb/Host/Host.h"
Greg Clayton917c0002011-06-29 22:09:02 +000041#include "lldb/Interpreter/Args.h"
Enrico Granata979e20d2011-07-29 19:53:35 +000042#include "lldb/Symbol/SymbolVendor.h"
Greg Clayton917c0002011-06-29 22:09:02 +000043#include "lldb/Symbol/VariableList.h"
Chris Lattner24943d22010-06-08 16:52:24 +000044#include "lldb/Target/Process.h"
45#include "lldb/Target/Target.h"
46#include "lldb/Target/TargetList.h"
47
48#include "lldb/Interpreter/CommandReturnObject.h"
49#include "../source/Commands/CommandObjectBreakpoint.h"
50
Chris Lattner24943d22010-06-08 16:52:24 +000051
52using namespace lldb;
53using namespace lldb_private;
54
55#define DEFAULT_DISASM_BYTE_SIZE 32
56
57//----------------------------------------------------------------------
58// SBTarget constructor
59//----------------------------------------------------------------------
Greg Claytonc3b61d22010-12-15 05:08:08 +000060SBTarget::SBTarget () :
61 m_opaque_sp ()
Chris Lattner24943d22010-06-08 16:52:24 +000062{
63}
64
65SBTarget::SBTarget (const SBTarget& rhs) :
Greg Clayton63094e02010-06-23 01:19:29 +000066 m_opaque_sp (rhs.m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +000067{
68}
69
70SBTarget::SBTarget(const TargetSP& target_sp) :
Greg Clayton63094e02010-06-23 01:19:29 +000071 m_opaque_sp (target_sp)
Chris Lattner24943d22010-06-08 16:52:24 +000072{
73}
74
Greg Clayton538eb822010-11-05 23:17:00 +000075const SBTarget&
76SBTarget::operator = (const SBTarget& rhs)
77{
78 if (this != &rhs)
79 m_opaque_sp = rhs.m_opaque_sp;
80 return *this;
81}
82
Chris Lattner24943d22010-06-08 16:52:24 +000083//----------------------------------------------------------------------
84// Destructor
85//----------------------------------------------------------------------
86SBTarget::~SBTarget()
87{
88}
89
90bool
91SBTarget::IsValid () const
92{
Greg Clayton63094e02010-06-23 01:19:29 +000093 return m_opaque_sp.get() != NULL;
Chris Lattner24943d22010-06-08 16:52:24 +000094}
95
96SBProcess
97SBTarget::GetProcess ()
98{
99 SBProcess sb_process;
Greg Clayton334d33a2012-01-30 07:41:31 +0000100 ProcessSP process_sp;
Greg Clayton63094e02010-06-23 01:19:29 +0000101 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000102 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000103 process_sp = m_opaque_sp->GetProcessSP();
104 sb_process.SetSP (process_sp);
Greg Claytonbdcda462010-12-20 20:49:23 +0000105 }
Caroline Tice7826c882010-10-26 03:11:13 +0000106
Greg Claytone005f2c2010-11-06 01:53:30 +0000107 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000108 if (log)
109 {
Greg Clayton49ce6822010-10-31 03:01:06 +0000110 log->Printf ("SBTarget(%p)::GetProcess () => SBProcess(%p)",
Greg Clayton334d33a2012-01-30 07:41:31 +0000111 m_opaque_sp.get(), process_sp.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000112 }
113
Chris Lattner24943d22010-06-08 16:52:24 +0000114 return sb_process;
115}
116
Greg Clayton63094e02010-06-23 01:19:29 +0000117SBDebugger
118SBTarget::GetDebugger () const
119{
120 SBDebugger debugger;
121 if (m_opaque_sp)
Greg Clayton13d24fb2012-01-29 20:56:30 +0000122 debugger.reset (m_opaque_sp->GetDebugger().shared_from_this());
Greg Clayton63094e02010-06-23 01:19:29 +0000123 return debugger;
124}
125
Jim Inghamb5871fe2011-03-31 00:01:24 +0000126SBProcess
127SBTarget::LaunchSimple
128(
129 char const **argv,
130 char const **envp,
131 const char *working_directory
132)
133{
134 char *stdin_path = NULL;
135 char *stdout_path = NULL;
136 char *stderr_path = NULL;
137 uint32_t launch_flags = 0;
138 bool stop_at_entry = false;
139 SBError error;
140 SBListener listener = GetDebugger().GetListener();
141 return Launch (listener,
142 argv,
143 envp,
144 stdin_path,
145 stdout_path,
146 stderr_path,
147 working_directory,
148 launch_flags,
149 stop_at_entry,
150 error);
151}
Greg Claytonde915be2011-01-23 05:56:20 +0000152
153SBProcess
154SBTarget::Launch
155(
Greg Clayton271a5db2011-02-03 21:28:34 +0000156 SBListener &listener,
Greg Claytonde915be2011-01-23 05:56:20 +0000157 char const **argv,
158 char const **envp,
159 const char *stdin_path,
160 const char *stdout_path,
161 const char *stderr_path,
162 const char *working_directory,
163 uint32_t launch_flags, // See LaunchFlags
164 bool stop_at_entry,
165 lldb::SBError& error
166)
167{
Greg Claytone005f2c2010-11-06 01:53:30 +0000168 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000169
170 if (log)
Greg Clayton3f5ee7f2010-10-29 04:59:35 +0000171 {
Greg Claytonde915be2011-01-23 05:56:20 +0000172 log->Printf ("SBTarget(%p)::Launch (argv=%p, envp=%p, stdin=%s, stdout=%s, stderr=%s, working-dir=%s, launch_flags=0x%x, stop_at_entry=%i, &error (%p))...",
173 m_opaque_sp.get(),
174 argv,
175 envp,
176 stdin_path ? stdin_path : "NULL",
177 stdout_path ? stdout_path : "NULL",
178 stderr_path ? stderr_path : "NULL",
179 working_directory ? working_directory : "NULL",
180 launch_flags,
181 stop_at_entry,
182 error.get());
Greg Clayton3f5ee7f2010-10-29 04:59:35 +0000183 }
Greg Clayton1a3083a2010-10-06 03:53:16 +0000184 SBProcess sb_process;
Greg Clayton334d33a2012-01-30 07:41:31 +0000185 ProcessSP process_sp;
Greg Clayton1a3083a2010-10-06 03:53:16 +0000186 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000187 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000188 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
Greg Clayton1a3083a2010-10-06 03:53:16 +0000189
Greg Clayton7c330d62011-01-27 01:01:10 +0000190 if (getenv("LLDB_LAUNCH_FLAG_DISABLE_ASLR"))
191 launch_flags |= eLaunchFlagDisableASLR;
192
Greg Clayton180546b2011-04-30 01:09:13 +0000193 StateType state = eStateInvalid;
Greg Clayton334d33a2012-01-30 07:41:31 +0000194 process_sp = m_opaque_sp->GetProcessSP();
195 if (process_sp)
Greg Clayton28d5fcc2011-01-27 06:44:37 +0000196 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000197 state = process_sp->GetState();
Greg Clayton180546b2011-04-30 01:09:13 +0000198
Greg Clayton334d33a2012-01-30 07:41:31 +0000199 if (process_sp->IsAlive() && state != eStateConnected)
Greg Clayton180546b2011-04-30 01:09:13 +0000200 {
201 if (state == eStateAttaching)
202 error.SetErrorString ("process attach is in progress");
203 else
204 error.SetErrorString ("a process is already being debugged");
Greg Clayton180546b2011-04-30 01:09:13 +0000205 return sb_process;
206 }
Greg Clayton28d5fcc2011-01-27 06:44:37 +0000207 }
208
Greg Clayton180546b2011-04-30 01:09:13 +0000209 if (state == eStateConnected)
210 {
211 // If we are already connected, then we have already specified the
212 // listener, so if a valid listener is supplied, we need to error out
213 // to let the client know.
214 if (listener.IsValid())
215 {
216 error.SetErrorString ("process is connected and already has a listener, pass empty listener");
Greg Clayton180546b2011-04-30 01:09:13 +0000217 return sb_process;
218 }
219 }
220 else
Greg Claytonc5f728c2010-10-06 22:10:17 +0000221 {
Greg Clayton271a5db2011-02-03 21:28:34 +0000222 if (listener.IsValid())
Greg Clayton334d33a2012-01-30 07:41:31 +0000223 process_sp = m_opaque_sp->CreateProcess (listener.ref());
Greg Clayton271a5db2011-02-03 21:28:34 +0000224 else
Greg Clayton334d33a2012-01-30 07:41:31 +0000225 process_sp = m_opaque_sp->CreateProcess (m_opaque_sp->GetDebugger().GetListener());
Greg Clayton180546b2011-04-30 01:09:13 +0000226 }
Greg Clayton7c330d62011-01-27 01:01:10 +0000227
Greg Clayton334d33a2012-01-30 07:41:31 +0000228 if (process_sp)
Greg Clayton180546b2011-04-30 01:09:13 +0000229 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000230 sb_process.SetSP (process_sp);
Greg Clayton180546b2011-04-30 01:09:13 +0000231 if (getenv("LLDB_LAUNCH_FLAG_DISABLE_STDIO"))
232 launch_flags |= eLaunchFlagDisableSTDIO;
233
Greg Clayton36bc5ea2011-11-03 21:22:33 +0000234 ProcessLaunchInfo launch_info (stdin_path, stdout_path, stderr_path, working_directory, launch_flags);
235
236 Module *exe_module = m_opaque_sp->GetExecutableModulePointer();
237 if (exe_module)
Greg Clayton1d1f39e2011-11-29 04:03:30 +0000238 launch_info.SetExecutableFile(exe_module->GetPlatformFileSpec(), true);
Greg Clayton36bc5ea2011-11-03 21:22:33 +0000239 if (argv)
240 launch_info.GetArguments().AppendArguments (argv);
241 if (envp)
242 launch_info.GetEnvironmentEntries ().SetArguments (envp);
243
Greg Clayton334d33a2012-01-30 07:41:31 +0000244 error.SetError (process_sp->Launch (launch_info));
Greg Clayton180546b2011-04-30 01:09:13 +0000245 if (error.Success())
Greg Clayton7c330d62011-01-27 01:01:10 +0000246 {
Greg Clayton180546b2011-04-30 01:09:13 +0000247 // We we are stopping at the entry point, we can return now!
248 if (stop_at_entry)
249 return sb_process;
Greg Clayton7c330d62011-01-27 01:01:10 +0000250
Greg Clayton180546b2011-04-30 01:09:13 +0000251 // Make sure we are stopped at the entry
Greg Clayton334d33a2012-01-30 07:41:31 +0000252 StateType state = process_sp->WaitForProcessToStop (NULL);
Greg Clayton180546b2011-04-30 01:09:13 +0000253 if (state == eStateStopped)
Greg Clayton7c330d62011-01-27 01:01:10 +0000254 {
Greg Clayton180546b2011-04-30 01:09:13 +0000255 // resume the process to skip the entry point
Greg Clayton334d33a2012-01-30 07:41:31 +0000256 error.SetError (process_sp->Resume());
Greg Clayton180546b2011-04-30 01:09:13 +0000257 if (error.Success())
Greg Clayton7c330d62011-01-27 01:01:10 +0000258 {
Greg Clayton180546b2011-04-30 01:09:13 +0000259 // If we are doing synchronous mode, then wait for the
260 // process to stop yet again!
261 if (m_opaque_sp->GetDebugger().GetAsyncExecution () == false)
Greg Clayton334d33a2012-01-30 07:41:31 +0000262 process_sp->WaitForProcessToStop (NULL);
Greg Clayton7c330d62011-01-27 01:01:10 +0000263 }
264 }
265 }
Greg Clayton180546b2011-04-30 01:09:13 +0000266 }
267 else
268 {
269 error.SetErrorString ("unable to create lldb_private::Process");
Greg Claytonc5f728c2010-10-06 22:10:17 +0000270 }
271 }
272 else
273 {
274 error.SetErrorString ("SBTarget is invalid");
Chris Lattner24943d22010-06-08 16:52:24 +0000275 }
Caroline Tice7826c882010-10-26 03:11:13 +0000276
Caroline Tice926060e2010-10-29 21:48:37 +0000277 log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
Caroline Tice7826c882010-10-26 03:11:13 +0000278 if (log)
279 {
Greg Clayton49ce6822010-10-31 03:01:06 +0000280 log->Printf ("SBTarget(%p)::Launch (...) => SBProceess(%p)",
Greg Clayton334d33a2012-01-30 07:41:31 +0000281 m_opaque_sp.get(), process_sp.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000282 }
283
Greg Clayton1a3083a2010-10-06 03:53:16 +0000284 return sb_process;
Chris Lattner24943d22010-06-08 16:52:24 +0000285}
286
Greg Claytond5b0b442011-12-02 02:10:57 +0000287#if defined(__APPLE__)
288
289lldb::SBProcess
290SBTarget::AttachToProcessWithID (SBListener &listener,
291 ::pid_t pid,
292 lldb::SBError& error)
293{
294 return AttachToProcessWithID (listener, (lldb::pid_t)pid, error);
295}
296
297#endif // #if defined(__APPLE__)
Greg Claytonc5f728c2010-10-06 22:10:17 +0000298
299lldb::SBProcess
Greg Claytond8c62532010-10-07 04:19:01 +0000300SBTarget::AttachToProcessWithID
Greg Claytonc5f728c2010-10-06 22:10:17 +0000301(
Greg Clayton271a5db2011-02-03 21:28:34 +0000302 SBListener &listener,
Greg Claytonc5f728c2010-10-06 22:10:17 +0000303 lldb::pid_t pid,// The process ID to attach to
304 SBError& error // An error explaining what went wrong if attach fails
305)
306{
307 SBProcess sb_process;
Greg Clayton334d33a2012-01-30 07:41:31 +0000308 ProcessSP process_sp;
Greg Claytonc5f728c2010-10-06 22:10:17 +0000309 if (m_opaque_sp)
310 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000311 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
Greg Claytonde1dd812011-06-24 03:21:43 +0000312
313 StateType state = eStateInvalid;
Greg Clayton334d33a2012-01-30 07:41:31 +0000314 process_sp = m_opaque_sp->GetProcessSP();
315 if (process_sp)
Greg Claytonde1dd812011-06-24 03:21:43 +0000316 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000317 state = process_sp->GetState();
Greg Claytonde1dd812011-06-24 03:21:43 +0000318
Greg Clayton334d33a2012-01-30 07:41:31 +0000319 if (process_sp->IsAlive() && state != eStateConnected)
Greg Claytonde1dd812011-06-24 03:21:43 +0000320 {
321 if (state == eStateAttaching)
322 error.SetErrorString ("process attach is in progress");
323 else
324 error.SetErrorString ("a process is already being debugged");
Greg Claytonde1dd812011-06-24 03:21:43 +0000325 return sb_process;
326 }
327 }
328
329 if (state == eStateConnected)
330 {
331 // If we are already connected, then we have already specified the
332 // listener, so if a valid listener is supplied, we need to error out
333 // to let the client know.
334 if (listener.IsValid())
335 {
336 error.SetErrorString ("process is connected and already has a listener, pass empty listener");
Greg Claytonde1dd812011-06-24 03:21:43 +0000337 return sb_process;
338 }
339 }
Greg Clayton271a5db2011-02-03 21:28:34 +0000340 else
Greg Claytonde1dd812011-06-24 03:21:43 +0000341 {
342 if (listener.IsValid())
Greg Clayton334d33a2012-01-30 07:41:31 +0000343 process_sp = m_opaque_sp->CreateProcess (listener.ref());
Greg Claytonde1dd812011-06-24 03:21:43 +0000344 else
Greg Clayton334d33a2012-01-30 07:41:31 +0000345 process_sp = m_opaque_sp->CreateProcess (m_opaque_sp->GetDebugger().GetListener());
Greg Claytonde1dd812011-06-24 03:21:43 +0000346 }
Greg Clayton334d33a2012-01-30 07:41:31 +0000347 if (process_sp)
Greg Claytonc5f728c2010-10-06 22:10:17 +0000348 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000349 sb_process.SetSP (process_sp);
350
Greg Clayton527154d2011-11-15 03:53:30 +0000351 ProcessAttachInfo attach_info;
352 attach_info.SetProcessID (pid);
Greg Clayton334d33a2012-01-30 07:41:31 +0000353 error.SetError (process_sp->Attach (attach_info));
Johnny Chen535960e2011-06-17 00:51:15 +0000354 // If we are doing synchronous mode, then wait for the
355 // process to stop!
356 if (m_opaque_sp->GetDebugger().GetAsyncExecution () == false)
Greg Clayton334d33a2012-01-30 07:41:31 +0000357 process_sp->WaitForProcessToStop (NULL);
Greg Claytonc5f728c2010-10-06 22:10:17 +0000358 }
359 else
360 {
361 error.SetErrorString ("unable to create lldb_private::Process");
362 }
363 }
364 else
365 {
366 error.SetErrorString ("SBTarget is invalid");
367 }
368 return sb_process;
369
370}
371
372lldb::SBProcess
Greg Claytond8c62532010-10-07 04:19:01 +0000373SBTarget::AttachToProcessWithName
Greg Claytonc5f728c2010-10-06 22:10:17 +0000374(
Greg Clayton271a5db2011-02-03 21:28:34 +0000375 SBListener &listener,
Greg Claytonc5f728c2010-10-06 22:10:17 +0000376 const char *name, // basename of process to attach to
377 bool wait_for, // if true wait for a new instance of "name" to be launched
378 SBError& error // An error explaining what went wrong if attach fails
379)
380{
381 SBProcess sb_process;
Greg Clayton334d33a2012-01-30 07:41:31 +0000382 ProcessSP process_sp;
Johnny Chen5a4bbce2011-12-20 01:22:03 +0000383 if (name && m_opaque_sp)
Greg Claytonc5f728c2010-10-06 22:10:17 +0000384 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000385 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
386
Greg Claytonde1dd812011-06-24 03:21:43 +0000387 StateType state = eStateInvalid;
Greg Clayton334d33a2012-01-30 07:41:31 +0000388 process_sp = m_opaque_sp->GetProcessSP();
389 if (process_sp)
Greg Claytonde1dd812011-06-24 03:21:43 +0000390 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000391 state = process_sp->GetState();
Greg Claytonde1dd812011-06-24 03:21:43 +0000392
Greg Clayton334d33a2012-01-30 07:41:31 +0000393 if (process_sp->IsAlive() && state != eStateConnected)
Greg Claytonde1dd812011-06-24 03:21:43 +0000394 {
395 if (state == eStateAttaching)
396 error.SetErrorString ("process attach is in progress");
397 else
398 error.SetErrorString ("a process is already being debugged");
Greg Claytonde1dd812011-06-24 03:21:43 +0000399 return sb_process;
400 }
401 }
402
403 if (state == eStateConnected)
404 {
405 // If we are already connected, then we have already specified the
406 // listener, so if a valid listener is supplied, we need to error out
407 // to let the client know.
408 if (listener.IsValid())
409 {
410 error.SetErrorString ("process is connected and already has a listener, pass empty listener");
Greg Claytonde1dd812011-06-24 03:21:43 +0000411 return sb_process;
412 }
413 }
Greg Clayton271a5db2011-02-03 21:28:34 +0000414 else
Greg Claytonde1dd812011-06-24 03:21:43 +0000415 {
416 if (listener.IsValid())
Greg Clayton334d33a2012-01-30 07:41:31 +0000417 process_sp = m_opaque_sp->CreateProcess (listener.ref());
Greg Claytonde1dd812011-06-24 03:21:43 +0000418 else
Greg Clayton334d33a2012-01-30 07:41:31 +0000419 process_sp = m_opaque_sp->CreateProcess (m_opaque_sp->GetDebugger().GetListener());
Greg Claytonde1dd812011-06-24 03:21:43 +0000420 }
Greg Claytonc5f728c2010-10-06 22:10:17 +0000421
Greg Clayton334d33a2012-01-30 07:41:31 +0000422 if (process_sp)
Greg Claytonc5f728c2010-10-06 22:10:17 +0000423 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000424 sb_process.SetSP (process_sp);
Greg Clayton527154d2011-11-15 03:53:30 +0000425 ProcessAttachInfo attach_info;
426 attach_info.GetExecutableFile().SetFile(name, false);
427 attach_info.SetWaitForLaunch(wait_for);
Greg Clayton334d33a2012-01-30 07:41:31 +0000428 error.SetError (process_sp->Attach (attach_info));
Johnny Chen58d02ff2011-06-17 19:21:30 +0000429 // If we are doing synchronous mode, then wait for the
430 // process to stop!
431 if (m_opaque_sp->GetDebugger().GetAsyncExecution () == false)
Greg Clayton334d33a2012-01-30 07:41:31 +0000432 process_sp->WaitForProcessToStop (NULL);
Greg Claytonc5f728c2010-10-06 22:10:17 +0000433 }
434 else
435 {
436 error.SetErrorString ("unable to create lldb_private::Process");
437 }
438 }
439 else
440 {
441 error.SetErrorString ("SBTarget is invalid");
442 }
443 return sb_process;
444
445}
446
James McIlree38093402011-03-04 00:31:13 +0000447lldb::SBProcess
448SBTarget::ConnectRemote
449(
450 SBListener &listener,
451 const char *url,
452 const char *plugin_name,
453 SBError& error
454)
455{
456 SBProcess sb_process;
Greg Clayton334d33a2012-01-30 07:41:31 +0000457 ProcessSP process_sp;
James McIlree38093402011-03-04 00:31:13 +0000458 if (m_opaque_sp)
459 {
460 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
461 if (listener.IsValid())
Greg Clayton334d33a2012-01-30 07:41:31 +0000462 process_sp = m_opaque_sp->CreateProcess (listener.ref(), plugin_name);
James McIlree38093402011-03-04 00:31:13 +0000463 else
Greg Clayton334d33a2012-01-30 07:41:31 +0000464 process_sp = m_opaque_sp->CreateProcess (m_opaque_sp->GetDebugger().GetListener(), plugin_name);
James McIlree38093402011-03-04 00:31:13 +0000465
466
Greg Clayton334d33a2012-01-30 07:41:31 +0000467 if (process_sp)
James McIlree38093402011-03-04 00:31:13 +0000468 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000469 sb_process.SetSP (process_sp);
470 error.SetError (process_sp->ConnectRemote (url));
James McIlree38093402011-03-04 00:31:13 +0000471 }
472 else
473 {
474 error.SetErrorString ("unable to create lldb_private::Process");
475 }
476 }
477 else
478 {
479 error.SetErrorString ("SBTarget is invalid");
480 }
481 return sb_process;
482}
483
Chris Lattner24943d22010-06-08 16:52:24 +0000484SBFileSpec
485SBTarget::GetExecutable ()
486{
Caroline Tice7826c882010-10-26 03:11:13 +0000487
Chris Lattner24943d22010-06-08 16:52:24 +0000488 SBFileSpec exe_file_spec;
Greg Clayton63094e02010-06-23 01:19:29 +0000489 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000490 {
Greg Clayton5beb99d2011-08-11 02:48:45 +0000491 Module *exe_module = m_opaque_sp->GetExecutableModulePointer();
492 if (exe_module)
493 exe_file_spec.SetFileSpec (exe_module->GetFileSpec());
Chris Lattner24943d22010-06-08 16:52:24 +0000494 }
Caroline Tice7826c882010-10-26 03:11:13 +0000495
Greg Claytone005f2c2010-11-06 01:53:30 +0000496 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000497 if (log)
498 {
Greg Clayton49ce6822010-10-31 03:01:06 +0000499 log->Printf ("SBTarget(%p)::GetExecutable () => SBFileSpec(%p)",
500 m_opaque_sp.get(), exe_file_spec.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000501 }
502
Chris Lattner24943d22010-06-08 16:52:24 +0000503 return exe_file_spec;
504}
505
Chris Lattner24943d22010-06-08 16:52:24 +0000506bool
Chris Lattner24943d22010-06-08 16:52:24 +0000507SBTarget::operator == (const SBTarget &rhs) const
508{
Greg Clayton63094e02010-06-23 01:19:29 +0000509 return m_opaque_sp.get() == rhs.m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000510}
511
512bool
513SBTarget::operator != (const SBTarget &rhs) const
514{
Greg Clayton63094e02010-06-23 01:19:29 +0000515 return m_opaque_sp.get() != rhs.m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000516}
517
Greg Clayton334d33a2012-01-30 07:41:31 +0000518lldb::TargetSP
519SBTarget::GetSP () const
Greg Clayton15afa9f2011-10-01 02:59:24 +0000520{
521 return m_opaque_sp;
522}
523
Greg Clayton63094e02010-06-23 01:19:29 +0000524void
Greg Clayton334d33a2012-01-30 07:41:31 +0000525SBTarget::SetSP (const lldb::TargetSP& target_sp)
Greg Clayton63094e02010-06-23 01:19:29 +0000526{
527 m_opaque_sp = target_sp;
Chris Lattner24943d22010-06-08 16:52:24 +0000528}
529
Greg Claytona3955062011-07-22 16:46:35 +0000530lldb::SBAddress
531SBTarget::ResolveLoadAddress (lldb::addr_t vm_addr)
Greg Claytonea49cc72010-12-12 19:25:26 +0000532{
Greg Claytona3955062011-07-22 16:46:35 +0000533 lldb::SBAddress sb_addr;
534 Address &addr = sb_addr.ref();
535 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000536 {
537 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
Greg Claytona3955062011-07-22 16:46:35 +0000538 if (m_opaque_sp->GetSectionLoadList().ResolveLoadAddress (vm_addr, addr))
539 return sb_addr;
Greg Claytonbdcda462010-12-20 20:49:23 +0000540 }
Greg Claytonea49cc72010-12-12 19:25:26 +0000541
Greg Claytona3955062011-07-22 16:46:35 +0000542 // We have a load address that isn't in a section, just return an address
543 // with the offset filled in (the address) and the section set to NULL
544 addr.SetSection(NULL);
545 addr.SetOffset(vm_addr);
546 return sb_addr;
Greg Claytonea49cc72010-12-12 19:25:26 +0000547}
548
Greg Claytonafb81862011-03-02 21:34:46 +0000549SBSymbolContext
550SBTarget::ResolveSymbolContextForAddress (const SBAddress& addr, uint32_t resolve_scope)
551{
552 SBSymbolContext sc;
Johnny Chene657fbc2011-06-29 00:05:40 +0000553 if (m_opaque_sp && addr.IsValid())
Greg Claytona3955062011-07-22 16:46:35 +0000554 m_opaque_sp->GetImages().ResolveSymbolContextForAddress (addr.ref(), resolve_scope, sc.ref());
Greg Claytonafb81862011-03-02 21:34:46 +0000555 return sc;
556}
557
558
Chris Lattner24943d22010-06-08 16:52:24 +0000559SBBreakpoint
560SBTarget::BreakpointCreateByLocation (const char *file, uint32_t line)
561{
Greg Claytond6d806c2010-11-08 00:28:40 +0000562 return SBBreakpoint(BreakpointCreateByLocation (SBFileSpec (file, false), line));
Chris Lattner24943d22010-06-08 16:52:24 +0000563}
564
565SBBreakpoint
566SBTarget::BreakpointCreateByLocation (const SBFileSpec &sb_file_spec, uint32_t line)
567{
Greg Claytone005f2c2010-11-06 01:53:30 +0000568 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000569
Chris Lattner24943d22010-06-08 16:52:24 +0000570 SBBreakpoint sb_bp;
Greg Clayton63094e02010-06-23 01:19:29 +0000571 if (m_opaque_sp.get() && line != 0)
Greg Claytonbdcda462010-12-20 20:49:23 +0000572 {
573 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
Greg Clayton63094e02010-06-23 01:19:29 +0000574 *sb_bp = m_opaque_sp->CreateBreakpoint (NULL, *sb_file_spec, line, true, false);
Greg Claytonbdcda462010-12-20 20:49:23 +0000575 }
Caroline Tice7826c882010-10-26 03:11:13 +0000576
577 if (log)
578 {
579 SBStream sstr;
580 sb_bp.GetDescription (sstr);
Greg Clayton49ce6822010-10-31 03:01:06 +0000581 char path[PATH_MAX];
582 sb_file_spec->GetPath (path, sizeof(path));
583 log->Printf ("SBTarget(%p)::BreakpointCreateByLocation ( %s:%u ) => SBBreakpoint(%p): %s",
Greg Claytona66ba462010-10-30 04:51:46 +0000584 m_opaque_sp.get(),
Greg Clayton49ce6822010-10-31 03:01:06 +0000585 path,
Greg Claytona66ba462010-10-30 04:51:46 +0000586 line,
Greg Clayton49ce6822010-10-31 03:01:06 +0000587 sb_bp.get(),
Caroline Tice7826c882010-10-26 03:11:13 +0000588 sstr.GetData());
589 }
590
Chris Lattner24943d22010-06-08 16:52:24 +0000591 return sb_bp;
592}
593
594SBBreakpoint
595SBTarget::BreakpointCreateByName (const char *symbol_name, const char *module_name)
596{
Greg Claytone005f2c2010-11-06 01:53:30 +0000597 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000598
Chris Lattner24943d22010-06-08 16:52:24 +0000599 SBBreakpoint sb_bp;
Jim Inghamd6d47972011-09-23 00:54:11 +0000600 if (m_opaque_sp.get())
Chris Lattner24943d22010-06-08 16:52:24 +0000601 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000602 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
Chris Lattner24943d22010-06-08 16:52:24 +0000603 if (module_name && module_name[0])
604 {
Jim Ingham03c8ee52011-09-21 01:17:13 +0000605 FileSpecList module_spec_list;
606 module_spec_list.Append (FileSpec (module_name, false));
Jim Ingham8b7b2272011-10-07 22:23:45 +0000607 *sb_bp = m_opaque_sp->CreateBreakpoint (&module_spec_list, NULL, symbol_name, eFunctionNameTypeAuto, false);
Chris Lattner24943d22010-06-08 16:52:24 +0000608 }
609 else
610 {
Jim Ingham8b7b2272011-10-07 22:23:45 +0000611 *sb_bp = m_opaque_sp->CreateBreakpoint (NULL, NULL, symbol_name, eFunctionNameTypeAuto, false);
Chris Lattner24943d22010-06-08 16:52:24 +0000612 }
613 }
Caroline Tice7826c882010-10-26 03:11:13 +0000614
615 if (log)
616 {
Greg Clayton49ce6822010-10-31 03:01:06 +0000617 log->Printf ("SBTarget(%p)::BreakpointCreateByName (symbol=\"%s\", module=\"%s\") => SBBreakpoint(%p)",
618 m_opaque_sp.get(), symbol_name, module_name, sb_bp.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000619 }
620
Chris Lattner24943d22010-06-08 16:52:24 +0000621 return sb_bp;
622}
623
Jim Inghamd6d47972011-09-23 00:54:11 +0000624lldb::SBBreakpoint
625SBTarget::BreakpointCreateByName (const char *symbol_name,
626 const SBFileSpecList &module_list,
627 const SBFileSpecList &comp_unit_list)
628{
Jim Ingham1fb8a2d2011-10-11 01:18:55 +0000629 uint32_t name_type_mask = eFunctionNameTypeAuto;
630 return BreakpointCreateByName (symbol_name, name_type_mask, module_list, comp_unit_list);
631}
632
633lldb::SBBreakpoint
634SBTarget::BreakpointCreateByName (const char *symbol_name,
635 uint32_t name_type_mask,
636 const SBFileSpecList &module_list,
637 const SBFileSpecList &comp_unit_list)
638{
Jim Inghamd6d47972011-09-23 00:54:11 +0000639 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
640
641 SBBreakpoint sb_bp;
642 if (m_opaque_sp.get() && symbol_name && symbol_name[0])
643 {
644 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
645 *sb_bp = m_opaque_sp->CreateBreakpoint (module_list.get(),
646 comp_unit_list.get(),
647 symbol_name,
Jim Ingham1fb8a2d2011-10-11 01:18:55 +0000648 name_type_mask,
Jim Inghamd6d47972011-09-23 00:54:11 +0000649 false);
650 }
651
652 if (log)
653 {
Jim Ingham1fb8a2d2011-10-11 01:18:55 +0000654 log->Printf ("SBTarget(%p)::BreakpointCreateByName (symbol=\"%s\", name_type: %d) => SBBreakpoint(%p)",
655 m_opaque_sp.get(), symbol_name, name_type_mask, sb_bp.get());
Jim Inghamd6d47972011-09-23 00:54:11 +0000656 }
657
658 return sb_bp;
659}
660
661
Chris Lattner24943d22010-06-08 16:52:24 +0000662SBBreakpoint
663SBTarget::BreakpointCreateByRegex (const char *symbol_name_regex, const char *module_name)
664{
Greg Claytone005f2c2010-11-06 01:53:30 +0000665 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000666
Chris Lattner24943d22010-06-08 16:52:24 +0000667 SBBreakpoint sb_bp;
Greg Clayton63094e02010-06-23 01:19:29 +0000668 if (m_opaque_sp.get() && symbol_name_regex && symbol_name_regex[0])
Chris Lattner24943d22010-06-08 16:52:24 +0000669 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000670 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
Chris Lattner24943d22010-06-08 16:52:24 +0000671 RegularExpression regexp(symbol_name_regex);
672
673 if (module_name && module_name[0])
674 {
Jim Ingham03c8ee52011-09-21 01:17:13 +0000675 FileSpecList module_spec_list;
676 module_spec_list.Append (FileSpec (module_name, false));
Chris Lattner24943d22010-06-08 16:52:24 +0000677
Jim Inghamd6d47972011-09-23 00:54:11 +0000678 *sb_bp = m_opaque_sp->CreateFuncRegexBreakpoint (&module_spec_list, NULL, regexp, false);
Chris Lattner24943d22010-06-08 16:52:24 +0000679 }
680 else
681 {
Jim Inghamd6d47972011-09-23 00:54:11 +0000682 *sb_bp = m_opaque_sp->CreateFuncRegexBreakpoint (NULL, NULL, regexp, false);
Chris Lattner24943d22010-06-08 16:52:24 +0000683 }
684 }
Caroline Tice7826c882010-10-26 03:11:13 +0000685
686 if (log)
687 {
Greg Clayton49ce6822010-10-31 03:01:06 +0000688 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (symbol_regex=\"%s\", module_name=\"%s\") => SBBreakpoint(%p)",
689 m_opaque_sp.get(), symbol_name_regex, module_name, sb_bp.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000690 }
691
Chris Lattner24943d22010-06-08 16:52:24 +0000692 return sb_bp;
693}
694
Jim Inghamd6d47972011-09-23 00:54:11 +0000695lldb::SBBreakpoint
696SBTarget::BreakpointCreateByRegex (const char *symbol_name_regex,
697 const SBFileSpecList &module_list,
698 const SBFileSpecList &comp_unit_list)
699{
700 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Chris Lattner24943d22010-06-08 16:52:24 +0000701
Jim Inghamd6d47972011-09-23 00:54:11 +0000702 SBBreakpoint sb_bp;
703 if (m_opaque_sp.get() && symbol_name_regex && symbol_name_regex[0])
704 {
705 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
706 RegularExpression regexp(symbol_name_regex);
707
708 *sb_bp = m_opaque_sp->CreateFuncRegexBreakpoint (module_list.get(), comp_unit_list.get(), regexp, false);
709 }
710
711 if (log)
712 {
713 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (symbol_regex=\"%s\") => SBBreakpoint(%p)",
714 m_opaque_sp.get(), symbol_name_regex, sb_bp.get());
715 }
716
717 return sb_bp;
718}
Chris Lattner24943d22010-06-08 16:52:24 +0000719
720SBBreakpoint
721SBTarget::BreakpointCreateByAddress (addr_t address)
722{
Greg Claytone005f2c2010-11-06 01:53:30 +0000723 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000724
Chris Lattner24943d22010-06-08 16:52:24 +0000725 SBBreakpoint sb_bp;
Greg Clayton63094e02010-06-23 01:19:29 +0000726 if (m_opaque_sp.get())
Greg Claytonbdcda462010-12-20 20:49:23 +0000727 {
728 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
Greg Clayton63094e02010-06-23 01:19:29 +0000729 *sb_bp = m_opaque_sp->CreateBreakpoint (address, false);
Greg Claytonbdcda462010-12-20 20:49:23 +0000730 }
Caroline Tice7826c882010-10-26 03:11:13 +0000731
732 if (log)
733 {
Jason Molenda7e5fa7f2011-09-20 21:44:10 +0000734 log->Printf ("SBTarget(%p)::BreakpointCreateByAddress (address=%llu) => SBBreakpoint(%p)", m_opaque_sp.get(), (uint64_t) address, sb_bp.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000735 }
736
Chris Lattner24943d22010-06-08 16:52:24 +0000737 return sb_bp;
738}
739
Jim Ingham03c8ee52011-09-21 01:17:13 +0000740lldb::SBBreakpoint
741SBTarget::BreakpointCreateBySourceRegex (const char *source_regex, const lldb::SBFileSpec &source_file, const char *module_name)
742{
743 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
744
745 SBBreakpoint sb_bp;
746 if (m_opaque_sp.get() && source_regex && source_regex[0])
747 {
748 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
749 RegularExpression regexp(source_regex);
Jim Inghamd6d47972011-09-23 00:54:11 +0000750 FileSpecList source_file_spec_list;
751 source_file_spec_list.Append (source_file.ref());
Jim Ingham03c8ee52011-09-21 01:17:13 +0000752
753 if (module_name && module_name[0])
754 {
755 FileSpecList module_spec_list;
756 module_spec_list.Append (FileSpec (module_name, false));
757
Jim Inghamd6d47972011-09-23 00:54:11 +0000758 *sb_bp = m_opaque_sp->CreateSourceRegexBreakpoint (&module_spec_list, &source_file_spec_list, regexp, false);
Jim Ingham03c8ee52011-09-21 01:17:13 +0000759 }
760 else
761 {
Jim Inghamd6d47972011-09-23 00:54:11 +0000762 *sb_bp = m_opaque_sp->CreateSourceRegexBreakpoint (NULL, &source_file_spec_list, regexp, false);
Jim Ingham03c8ee52011-09-21 01:17:13 +0000763 }
764 }
765
766 if (log)
767 {
768 char path[PATH_MAX];
769 source_file->GetPath (path, sizeof(path));
770 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (source_regex=\"%s\", file=\"%s\", module_name=\"%s\") => SBBreakpoint(%p)",
Greg Claytona253c932011-09-21 06:45:51 +0000771 m_opaque_sp.get(), source_regex, path, module_name, sb_bp.get());
Jim Ingham03c8ee52011-09-21 01:17:13 +0000772 }
773
774 return sb_bp;
775}
776
Jim Inghamd6d47972011-09-23 00:54:11 +0000777lldb::SBBreakpoint
778SBTarget::BreakpointCreateBySourceRegex (const char *source_regex,
779 const SBFileSpecList &module_list,
780 const lldb::SBFileSpecList &source_file_list)
781{
782 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
783
784 SBBreakpoint sb_bp;
785 if (m_opaque_sp.get() && source_regex && source_regex[0])
786 {
787 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
788 RegularExpression regexp(source_regex);
789 *sb_bp = m_opaque_sp->CreateSourceRegexBreakpoint (module_list.get(), source_file_list.get(), regexp, false);
790 }
791
792 if (log)
793 {
794 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (source_regex=\"%s\") => SBBreakpoint(%p)",
795 m_opaque_sp.get(), source_regex, sb_bp.get());
796 }
797
798 return sb_bp;
799}
Jim Ingham03c8ee52011-09-21 01:17:13 +0000800
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000801uint32_t
802SBTarget::GetNumBreakpoints () const
803{
804 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000805 {
806 // The breakpoint list is thread safe, no need to lock
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000807 return m_opaque_sp->GetBreakpointList().GetSize();
Greg Claytonbdcda462010-12-20 20:49:23 +0000808 }
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000809 return 0;
810}
811
812SBBreakpoint
813SBTarget::GetBreakpointAtIndex (uint32_t idx) const
814{
815 SBBreakpoint sb_breakpoint;
816 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000817 {
818 // The breakpoint list is thread safe, no need to lock
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000819 *sb_breakpoint = m_opaque_sp->GetBreakpointList().GetBreakpointAtIndex(idx);
Greg Claytonbdcda462010-12-20 20:49:23 +0000820 }
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000821 return sb_breakpoint;
822}
Chris Lattner24943d22010-06-08 16:52:24 +0000823
824bool
825SBTarget::BreakpointDelete (break_id_t bp_id)
826{
Greg Claytone005f2c2010-11-06 01:53:30 +0000827 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000828
Caroline Tice7826c882010-10-26 03:11:13 +0000829 bool result = false;
Greg Clayton63094e02010-06-23 01:19:29 +0000830 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000831 {
832 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
Caroline Tice7826c882010-10-26 03:11:13 +0000833 result = m_opaque_sp->RemoveBreakpointByID (bp_id);
Greg Claytonbdcda462010-12-20 20:49:23 +0000834 }
Caroline Tice7826c882010-10-26 03:11:13 +0000835
836 if (log)
837 {
Greg Clayton3f5ee7f2010-10-29 04:59:35 +0000838 log->Printf ("SBTarget(%p)::BreakpointDelete (bp_id=%d) => %i", m_opaque_sp.get(), (uint32_t) bp_id, result);
Caroline Tice7826c882010-10-26 03:11:13 +0000839 }
840
841 return result;
Chris Lattner24943d22010-06-08 16:52:24 +0000842}
843
Johnny Chen096c2932011-09-26 22:40:50 +0000844SBBreakpoint
845SBTarget::FindBreakpointByID (break_id_t bp_id)
846{
847 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
848
849 SBBreakpoint sb_breakpoint;
850 if (m_opaque_sp && bp_id != LLDB_INVALID_BREAK_ID)
851 {
852 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
853 *sb_breakpoint = m_opaque_sp->GetBreakpointByID (bp_id);
854 }
855
856 if (log)
857 {
858 log->Printf ("SBTarget(%p)::FindBreakpointByID (bp_id=%d) => SBBreakpoint(%p)",
859 m_opaque_sp.get(), (uint32_t) bp_id, sb_breakpoint.get());
860 }
861
862 return sb_breakpoint;
863}
864
Chris Lattner24943d22010-06-08 16:52:24 +0000865bool
866SBTarget::EnableAllBreakpoints ()
867{
Greg Clayton63094e02010-06-23 01:19:29 +0000868 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000869 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000870 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
Greg Clayton63094e02010-06-23 01:19:29 +0000871 m_opaque_sp->EnableAllBreakpoints ();
Chris Lattner24943d22010-06-08 16:52:24 +0000872 return true;
873 }
874 return false;
875}
876
877bool
878SBTarget::DisableAllBreakpoints ()
879{
Greg Clayton63094e02010-06-23 01:19:29 +0000880 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000881 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000882 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
Greg Clayton63094e02010-06-23 01:19:29 +0000883 m_opaque_sp->DisableAllBreakpoints ();
Chris Lattner24943d22010-06-08 16:52:24 +0000884 return true;
885 }
886 return false;
887}
888
889bool
890SBTarget::DeleteAllBreakpoints ()
891{
Greg Clayton63094e02010-06-23 01:19:29 +0000892 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000893 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000894 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
Greg Clayton63094e02010-06-23 01:19:29 +0000895 m_opaque_sp->RemoveAllBreakpoints ();
Chris Lattner24943d22010-06-08 16:52:24 +0000896 return true;
897 }
898 return false;
899}
900
Johnny Chen096c2932011-09-26 22:40:50 +0000901uint32_t
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000902SBTarget::GetNumWatchpoints () const
Johnny Chen096c2932011-09-26 22:40:50 +0000903{
904 if (m_opaque_sp)
905 {
Johnny Chenecd4feb2011-10-14 00:42:25 +0000906 // The watchpoint list is thread safe, no need to lock
907 return m_opaque_sp->GetWatchpointList().GetSize();
Johnny Chen096c2932011-09-26 22:40:50 +0000908 }
909 return 0;
910}
911
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000912SBWatchpoint
913SBTarget::GetWatchpointAtIndex (uint32_t idx) const
Johnny Chen5eb54bb2011-09-27 20:29:45 +0000914{
Johnny Chenecd4feb2011-10-14 00:42:25 +0000915 SBWatchpoint sb_watchpoint;
Johnny Chen096c2932011-09-26 22:40:50 +0000916 if (m_opaque_sp)
917 {
Johnny Chenecd4feb2011-10-14 00:42:25 +0000918 // The watchpoint list is thread safe, no need to lock
919 *sb_watchpoint = m_opaque_sp->GetWatchpointList().GetByIndex(idx);
Johnny Chen096c2932011-09-26 22:40:50 +0000920 }
Johnny Chenecd4feb2011-10-14 00:42:25 +0000921 return sb_watchpoint;
Johnny Chen096c2932011-09-26 22:40:50 +0000922}
923
924bool
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000925SBTarget::DeleteWatchpoint (watch_id_t wp_id)
Johnny Chen096c2932011-09-26 22:40:50 +0000926{
927 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
928
929 bool result = false;
930 if (m_opaque_sp)
931 {
932 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
Johnny Chenecd4feb2011-10-14 00:42:25 +0000933 result = m_opaque_sp->RemoveWatchpointByID (wp_id);
Johnny Chen096c2932011-09-26 22:40:50 +0000934 }
935
936 if (log)
937 {
Johnny Chenecd4feb2011-10-14 00:42:25 +0000938 log->Printf ("SBTarget(%p)::WatchpointDelete (wp_id=%d) => %i", m_opaque_sp.get(), (uint32_t) wp_id, result);
Johnny Chen096c2932011-09-26 22:40:50 +0000939 }
940
941 return result;
942}
943
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000944SBWatchpoint
945SBTarget::FindWatchpointByID (lldb::watch_id_t wp_id)
Johnny Chen096c2932011-09-26 22:40:50 +0000946{
947 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
948
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000949 SBWatchpoint sb_watchpoint;
Johnny Chen096c2932011-09-26 22:40:50 +0000950 if (m_opaque_sp && wp_id != LLDB_INVALID_WATCH_ID)
951 {
952 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
Johnny Chenecd4feb2011-10-14 00:42:25 +0000953 *sb_watchpoint = m_opaque_sp->GetWatchpointList().FindByID(wp_id);
Johnny Chen096c2932011-09-26 22:40:50 +0000954 }
955
956 if (log)
957 {
Johnny Chenecd4feb2011-10-14 00:42:25 +0000958 log->Printf ("SBTarget(%p)::FindWatchpointByID (bp_id=%d) => SBWatchpoint(%p)",
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000959 m_opaque_sp.get(), (uint32_t) wp_id, sb_watchpoint.get());
Johnny Chen096c2932011-09-26 22:40:50 +0000960 }
961
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000962 return sb_watchpoint;
963}
964
965lldb::SBWatchpoint
966SBTarget::WatchAddress (lldb::addr_t addr, size_t size, bool read, bool write)
967{
968 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
969
970 SBWatchpoint sb_watchpoint;
971 if (m_opaque_sp)
972 {
973 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
Johnny Chenecd4feb2011-10-14 00:42:25 +0000974 uint32_t watch_type = (read ? LLDB_WATCH_TYPE_READ : 0) |
975 (write ? LLDB_WATCH_TYPE_WRITE : 0);
Johnny Chen50e05342011-10-14 01:16:39 +0000976 sb_watchpoint = m_opaque_sp->CreateWatchpoint(addr, size, watch_type);
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000977 }
978
979 if (log)
980 {
981 log->Printf ("SBTarget(%p)::WatchAddress (addr=0x%llx, 0x%u) => SBWatchpoint(%p)",
982 m_opaque_sp.get(), addr, (uint32_t) size, sb_watchpoint.get());
983 }
984
985 return sb_watchpoint;
Johnny Chen096c2932011-09-26 22:40:50 +0000986}
987
988bool
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000989SBTarget::EnableAllWatchpoints ()
Johnny Chen096c2932011-09-26 22:40:50 +0000990{
991 if (m_opaque_sp)
992 {
993 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
Johnny Chenecd4feb2011-10-14 00:42:25 +0000994 m_opaque_sp->EnableAllWatchpoints ();
Johnny Chen096c2932011-09-26 22:40:50 +0000995 return true;
996 }
997 return false;
998}
999
1000bool
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001001SBTarget::DisableAllWatchpoints ()
Johnny Chen096c2932011-09-26 22:40:50 +00001002{
1003 if (m_opaque_sp)
1004 {
1005 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
Johnny Chenecd4feb2011-10-14 00:42:25 +00001006 m_opaque_sp->DisableAllWatchpoints ();
Johnny Chen096c2932011-09-26 22:40:50 +00001007 return true;
1008 }
1009 return false;
1010}
1011
1012bool
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001013SBTarget::DeleteAllWatchpoints ()
Johnny Chen096c2932011-09-26 22:40:50 +00001014{
1015 if (m_opaque_sp)
1016 {
1017 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
Johnny Chenecd4feb2011-10-14 00:42:25 +00001018 m_opaque_sp->RemoveAllWatchpoints ();
Johnny Chen096c2932011-09-26 22:40:50 +00001019 return true;
1020 }
1021 return false;
1022}
1023
Chris Lattner24943d22010-06-08 16:52:24 +00001024
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001025lldb::SBModule
1026SBTarget::AddModule (const char *path,
1027 const char *triple,
1028 const char *uuid_cstr)
1029{
1030 lldb::SBModule sb_module;
1031 if (m_opaque_sp)
1032 {
1033 FileSpec module_file_spec;
1034 UUID module_uuid;
1035 ArchSpec module_arch;
1036
1037 if (path)
1038 module_file_spec.SetFile(path, false);
1039
1040 if (uuid_cstr)
1041 module_uuid.SetfromCString(uuid_cstr);
1042
1043 if (triple)
1044 module_arch.SetTriple (triple, m_opaque_sp->GetPlatform ().get());
1045
1046 sb_module.SetModule(m_opaque_sp->GetSharedModule (module_file_spec,
1047 module_arch,
1048 uuid_cstr ? &module_uuid : NULL));
1049 }
1050 return sb_module;
1051}
1052
1053bool
1054SBTarget::AddModule (lldb::SBModule &module)
1055{
1056 if (m_opaque_sp)
1057 {
1058 m_opaque_sp->GetImages().AppendIfNeeded (module.get_sp());
1059 return true;
1060 }
1061 return false;
1062}
1063
Chris Lattner24943d22010-06-08 16:52:24 +00001064uint32_t
1065SBTarget::GetNumModules () const
1066{
Greg Claytone005f2c2010-11-06 01:53:30 +00001067 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001068
Caroline Tice7826c882010-10-26 03:11:13 +00001069 uint32_t num = 0;
Greg Clayton63094e02010-06-23 01:19:29 +00001070 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +00001071 {
1072 // The module list is thread safe, no need to lock
1073 num = m_opaque_sp->GetImages().GetSize();
1074 }
Caroline Tice7826c882010-10-26 03:11:13 +00001075
1076 if (log)
Greg Clayton3f5ee7f2010-10-29 04:59:35 +00001077 log->Printf ("SBTarget(%p)::GetNumModules () => %d", m_opaque_sp.get(), num);
Caroline Tice7826c882010-10-26 03:11:13 +00001078
1079 return num;
Chris Lattner24943d22010-06-08 16:52:24 +00001080}
1081
Greg Clayton43490d12010-07-30 20:12:55 +00001082void
1083SBTarget::Clear ()
1084{
Greg Claytone005f2c2010-11-06 01:53:30 +00001085 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001086
1087 if (log)
Greg Clayton3f5ee7f2010-10-29 04:59:35 +00001088 log->Printf ("SBTarget(%p)::Clear ()", m_opaque_sp.get());
Caroline Tice7826c882010-10-26 03:11:13 +00001089
Greg Clayton43490d12010-07-30 20:12:55 +00001090 m_opaque_sp.reset();
1091}
1092
1093
Chris Lattner24943d22010-06-08 16:52:24 +00001094SBModule
1095SBTarget::FindModule (const SBFileSpec &sb_file_spec)
1096{
1097 SBModule sb_module;
Greg Clayton63094e02010-06-23 01:19:29 +00001098 if (m_opaque_sp && sb_file_spec.IsValid())
Greg Claytonbdcda462010-12-20 20:49:23 +00001099 {
1100 // The module list is thread safe, no need to lock
Greg Clayton24bc5d92011-03-30 18:16:51 +00001101 sb_module.SetModule (m_opaque_sp->GetImages().FindFirstModuleForFileSpec (*sb_file_spec, NULL, NULL));
Greg Claytonbdcda462010-12-20 20:49:23 +00001102 }
Chris Lattner24943d22010-06-08 16:52:24 +00001103 return sb_module;
1104}
1105
Greg Clayton1b925202012-01-29 06:07:39 +00001106lldb::ByteOrder
1107SBTarget::GetByteOrder ()
1108{
1109 if (m_opaque_sp)
1110 return m_opaque_sp->GetArchitecture().GetByteOrder();
1111 return eByteOrderInvalid;
1112}
1113
1114const char *
1115SBTarget::GetTriple ()
1116{
1117 if (m_opaque_sp)
1118 {
1119 std::string triple (m_opaque_sp->GetArchitecture().GetTriple().str());
1120 // Unique the string so we don't run into ownership issues since
1121 // the const strings put the string into the string pool once and
1122 // the strings never comes out
1123 ConstString const_triple (triple.c_str());
1124 return const_triple.GetCString();
1125 }
1126 return NULL;
1127}
1128
1129uint32_t
1130SBTarget::GetAddressByteSize()
1131{
1132 if (m_opaque_sp)
1133 return m_opaque_sp->GetArchitecture().GetAddressByteSize();
1134 return sizeof(void*);
1135}
1136
1137
Chris Lattner24943d22010-06-08 16:52:24 +00001138SBModule
1139SBTarget::GetModuleAtIndex (uint32_t idx)
1140{
Greg Claytone005f2c2010-11-06 01:53:30 +00001141 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001142
Chris Lattner24943d22010-06-08 16:52:24 +00001143 SBModule sb_module;
Greg Clayton63094e02010-06-23 01:19:29 +00001144 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +00001145 {
1146 // The module list is thread safe, no need to lock
Greg Clayton63094e02010-06-23 01:19:29 +00001147 sb_module.SetModule(m_opaque_sp->GetImages().GetModuleAtIndex(idx));
Greg Claytonbdcda462010-12-20 20:49:23 +00001148 }
Caroline Tice7826c882010-10-26 03:11:13 +00001149
1150 if (log)
1151 {
Greg Clayton49ce6822010-10-31 03:01:06 +00001152 log->Printf ("SBTarget(%p)::GetModuleAtIndex (idx=%d) => SBModule(%p)",
1153 m_opaque_sp.get(), idx, sb_module.get());
Caroline Tice7826c882010-10-26 03:11:13 +00001154 }
1155
Chris Lattner24943d22010-06-08 16:52:24 +00001156 return sb_module;
1157}
1158
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001159bool
1160SBTarget::RemoveModule (lldb::SBModule module)
1161{
1162 if (m_opaque_sp)
1163 return m_opaque_sp->GetImages().Remove(module.get_sp());
1164 return false;
1165}
1166
Chris Lattner24943d22010-06-08 16:52:24 +00001167
1168SBBroadcaster
1169SBTarget::GetBroadcaster () const
1170{
Greg Claytone005f2c2010-11-06 01:53:30 +00001171 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001172
Greg Clayton63094e02010-06-23 01:19:29 +00001173 SBBroadcaster broadcaster(m_opaque_sp.get(), false);
Caroline Tice7826c882010-10-26 03:11:13 +00001174
1175 if (log)
Greg Clayton3f5ee7f2010-10-29 04:59:35 +00001176 log->Printf ("SBTarget(%p)::GetBroadcaster () => SBBroadcaster(%p)",
Caroline Tice61ba7ec2010-10-26 23:49:36 +00001177 m_opaque_sp.get(), broadcaster.get());
Caroline Tice7826c882010-10-26 03:11:13 +00001178
Chris Lattner24943d22010-06-08 16:52:24 +00001179 return broadcaster;
1180}
1181
Caroline Tice98f930f2010-09-20 05:20:02 +00001182
1183bool
Caroline Tice7826c882010-10-26 03:11:13 +00001184SBTarget::GetDescription (SBStream &description, lldb::DescriptionLevel description_level)
Caroline Tice98f930f2010-09-20 05:20:02 +00001185{
Greg Clayton96154be2011-11-13 06:57:31 +00001186 Stream &strm = description.ref();
1187
Caroline Tice98f930f2010-09-20 05:20:02 +00001188 if (m_opaque_sp)
Caroline Ticee7a566e2010-09-20 16:21:41 +00001189 {
Greg Clayton96154be2011-11-13 06:57:31 +00001190 m_opaque_sp->Dump (&strm, description_level);
Caroline Tice7826c882010-10-26 03:11:13 +00001191 }
1192 else
Greg Clayton96154be2011-11-13 06:57:31 +00001193 strm.PutCString ("No value");
Caroline Tice7826c882010-10-26 03:11:13 +00001194
1195 return true;
1196}
1197
Greg Clayton4ed315f2011-06-21 01:34:41 +00001198uint32_t
1199SBTarget::FindFunctions (const char *name,
1200 uint32_t name_type_mask,
1201 bool append,
1202 lldb::SBSymbolContextList& sc_list)
1203{
1204 if (!append)
1205 sc_list.Clear();
Johnny Chencd186e52011-12-14 01:43:31 +00001206 if (name && m_opaque_sp)
Greg Clayton4ed315f2011-06-21 01:34:41 +00001207 {
1208 const bool symbols_ok = true;
1209 return m_opaque_sp->GetImages().FindFunctions (ConstString(name),
1210 name_type_mask,
1211 symbols_ok,
1212 append,
1213 *sc_list);
1214 }
1215 return 0;
1216}
1217
Enrico Granata979e20d2011-07-29 19:53:35 +00001218lldb::SBType
1219SBTarget::FindFirstType (const char* type)
1220{
Johnny Chencd186e52011-12-14 01:43:31 +00001221 if (type && m_opaque_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +00001222 {
1223 size_t count = m_opaque_sp->GetImages().GetSize();
1224 for (size_t idx = 0; idx < count; idx++)
1225 {
1226 SBType found_at_idx = GetModuleAtIndex(idx).FindFirstType(type);
1227
1228 if (found_at_idx.IsValid())
1229 return found_at_idx;
1230 }
1231 }
1232 return SBType();
1233}
1234
1235lldb::SBTypeList
1236SBTarget::FindTypes (const char* type)
1237{
1238
1239 SBTypeList retval;
1240
Johnny Chencd186e52011-12-14 01:43:31 +00001241 if (type && m_opaque_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +00001242 {
1243 ModuleList& images = m_opaque_sp->GetImages();
1244 ConstString name_const(type);
1245 SymbolContext sc;
1246 TypeList type_list;
1247
1248 uint32_t num_matches = images.FindTypes(sc,
1249 name_const,
1250 true,
1251 UINT32_MAX,
1252 type_list);
1253
1254 for (size_t idx = 0; idx < num_matches; idx++)
1255 {
Greg Clayton0fb0bcc2011-08-03 22:57:10 +00001256 TypeSP type_sp (type_list.GetTypeAtIndex(idx));
1257 if (type_sp)
1258 retval.Append(SBType(type_sp));
Enrico Granata979e20d2011-07-29 19:53:35 +00001259 }
1260 }
1261 return retval;
1262}
1263
Greg Clayton917c0002011-06-29 22:09:02 +00001264SBValueList
1265SBTarget::FindGlobalVariables (const char *name, uint32_t max_matches)
1266{
1267 SBValueList sb_value_list;
1268
Johnny Chencd186e52011-12-14 01:43:31 +00001269 if (name && m_opaque_sp)
Greg Clayton917c0002011-06-29 22:09:02 +00001270 {
1271 VariableList variable_list;
1272 const bool append = true;
1273 const uint32_t match_count = m_opaque_sp->GetImages().FindGlobalVariables (ConstString (name),
1274 append,
1275 max_matches,
1276 variable_list);
1277
1278 if (match_count > 0)
1279 {
1280 ExecutionContextScope *exe_scope = m_opaque_sp->GetProcessSP().get();
1281 if (exe_scope == NULL)
1282 exe_scope = m_opaque_sp.get();
1283 ValueObjectList &value_object_list = sb_value_list.ref();
1284 for (uint32_t i=0; i<match_count; ++i)
1285 {
1286 lldb::ValueObjectSP valobj_sp (ValueObjectVariable::Create (exe_scope, variable_list.GetVariableAtIndex(i)));
1287 if (valobj_sp)
1288 value_object_list.Append(valobj_sp);
1289 }
1290 }
1291 }
1292
1293 return sb_value_list;
1294}
1295
Jim Inghamcc637462011-09-13 00:29:56 +00001296SBSourceManager
1297SBTarget::GetSourceManager()
1298{
1299 SBSourceManager source_manager (*this);
1300 return source_manager;
1301}
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001302
Sean Callananef1f6902011-12-14 23:49:37 +00001303lldb::SBInstructionList
1304SBTarget::GetInstructions (lldb::SBAddress base_addr, const void *buf, size_t size)
1305{
1306 SBInstructionList sb_instructions;
1307
1308 if (m_opaque_sp)
1309 {
1310 Address addr;
1311
1312 if (base_addr.get())
1313 addr = *base_addr.get();
1314
1315 sb_instructions.SetDisassembler (Disassembler::DisassembleBytes (m_opaque_sp->GetArchitecture(),
1316 NULL,
1317 addr,
1318 buf,
1319 size));
1320 }
1321
1322 return sb_instructions;
1323}
1324
1325lldb::SBInstructionList
1326SBTarget::GetInstructions (lldb::addr_t base_addr, const void *buf, size_t size)
1327{
1328 return GetInstructions (ResolveLoadAddress(base_addr), buf, size);
1329}
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001330
1331SBError
1332SBTarget::SetSectionLoadAddress (lldb::SBSection section,
1333 lldb::addr_t section_base_addr)
1334{
1335 SBError sb_error;
1336
1337 if (IsValid())
1338 {
1339 if (!section.IsValid())
1340 {
1341 sb_error.SetErrorStringWithFormat ("invalid section");
1342 }
1343 else
1344 {
1345 m_opaque_sp->GetSectionLoadList().SetSectionLoadAddress (section.GetSection(), section_base_addr);
1346 }
1347 }
1348 else
1349 {
1350 sb_error.SetErrorStringWithFormat ("invalid target");
1351 }
1352 return sb_error;
1353}
1354
1355SBError
1356SBTarget::ClearSectionLoadAddress (lldb::SBSection section)
1357{
1358 SBError sb_error;
1359
1360 if (IsValid())
1361 {
1362 if (!section.IsValid())
1363 {
1364 sb_error.SetErrorStringWithFormat ("invalid section");
1365 }
1366 else
1367 {
1368 m_opaque_sp->GetSectionLoadList().SetSectionUnloaded (section.GetSection());
1369 }
1370 }
1371 else
1372 {
1373 sb_error.SetErrorStringWithFormat ("invalid target");
1374 }
1375 return sb_error;
1376}
1377
1378SBError
1379SBTarget::SetModuleLoadAddress (lldb::SBModule module, int64_t slide_offset)
1380{
1381 SBError sb_error;
1382
1383 char path[PATH_MAX];
1384 if (IsValid())
1385 {
1386 if (!module.IsValid())
1387 {
1388 sb_error.SetErrorStringWithFormat ("invalid module");
1389 }
1390 else
1391 {
1392 ObjectFile *objfile = module->GetObjectFile();
1393 if (objfile)
1394 {
1395 SectionList *section_list = objfile->GetSectionList();
1396 if (section_list)
1397 {
1398 const size_t num_sections = section_list->GetSize();
1399 for (size_t sect_idx = 0; sect_idx < num_sections; ++sect_idx)
1400 {
1401 SectionSP section_sp (section_list->GetSectionAtIndex(sect_idx));
1402 if (section_sp)
1403 m_opaque_sp->GetSectionLoadList().SetSectionLoadAddress (section_sp.get(), section_sp->GetFileAddress() + slide_offset);
1404 }
1405 }
1406 else
1407 {
1408 module->GetFileSpec().GetPath (path, sizeof(path));
1409 sb_error.SetErrorStringWithFormat ("no sections in object file '%s'", path);
1410 }
1411 }
1412 else
1413 {
1414 module->GetFileSpec().GetPath (path, sizeof(path));
1415 sb_error.SetErrorStringWithFormat ("no object file for module '%s'", path);
1416 }
1417 }
1418 }
1419 else
1420 {
1421 sb_error.SetErrorStringWithFormat ("invalid target");
1422 }
1423 return sb_error;
1424}
1425
1426SBError
1427SBTarget::ClearModuleLoadAddress (lldb::SBModule module)
1428{
1429 SBError sb_error;
1430
1431 char path[PATH_MAX];
1432 if (IsValid())
1433 {
1434 if (!module.IsValid())
1435 {
1436 sb_error.SetErrorStringWithFormat ("invalid module");
1437 }
1438 else
1439 {
1440 ObjectFile *objfile = module->GetObjectFile();
1441 if (objfile)
1442 {
1443 SectionList *section_list = objfile->GetSectionList();
1444 if (section_list)
1445 {
1446 const size_t num_sections = section_list->GetSize();
1447 for (size_t sect_idx = 0; sect_idx < num_sections; ++sect_idx)
1448 {
1449 SectionSP section_sp (section_list->GetSectionAtIndex(sect_idx));
1450 if (section_sp)
1451 m_opaque_sp->GetSectionLoadList().SetSectionUnloaded (section_sp.get());
1452 }
1453 }
1454 else
1455 {
1456 module->GetFileSpec().GetPath (path, sizeof(path));
1457 sb_error.SetErrorStringWithFormat ("no sections in object file '%s'", path);
1458 }
1459 }
1460 else
1461 {
1462 module->GetFileSpec().GetPath (path, sizeof(path));
1463 sb_error.SetErrorStringWithFormat ("no object file for module '%s'", path);
1464 }
1465 }
1466 }
1467 else
1468 {
1469 sb_error.SetErrorStringWithFormat ("invalid target");
1470 }
1471 return sb_error;
1472}
1473
1474