blob: 376ed78d9a7b0fc6f650c3d8429ab7d1e84ca6ea [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 Clayton0416bdf2012-01-30 09:04:36 +0000101 TargetSP target_sp(GetSP());
102 if (target_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000103 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000104 process_sp = target_sp->GetProcessSP();
Greg Clayton334d33a2012-01-30 07:41:31 +0000105 sb_process.SetSP (process_sp);
Greg Claytonbdcda462010-12-20 20:49:23 +0000106 }
Caroline Tice7826c882010-10-26 03:11:13 +0000107
Greg Claytone005f2c2010-11-06 01:53:30 +0000108 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000109 if (log)
110 {
Greg Clayton49ce6822010-10-31 03:01:06 +0000111 log->Printf ("SBTarget(%p)::GetProcess () => SBProcess(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +0000112 target_sp.get(), process_sp.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000113 }
114
Chris Lattner24943d22010-06-08 16:52:24 +0000115 return sb_process;
116}
117
Greg Clayton63094e02010-06-23 01:19:29 +0000118SBDebugger
119SBTarget::GetDebugger () const
120{
121 SBDebugger debugger;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000122 TargetSP target_sp(GetSP());
123 if (target_sp)
124 debugger.reset (target_sp->GetDebugger().shared_from_this());
Greg Clayton63094e02010-06-23 01:19:29 +0000125 return debugger;
126}
127
Jim Inghamb5871fe2011-03-31 00:01:24 +0000128SBProcess
129SBTarget::LaunchSimple
130(
131 char const **argv,
132 char const **envp,
133 const char *working_directory
134)
135{
136 char *stdin_path = NULL;
137 char *stdout_path = NULL;
138 char *stderr_path = NULL;
139 uint32_t launch_flags = 0;
140 bool stop_at_entry = false;
141 SBError error;
142 SBListener listener = GetDebugger().GetListener();
143 return Launch (listener,
144 argv,
145 envp,
146 stdin_path,
147 stdout_path,
148 stderr_path,
149 working_directory,
150 launch_flags,
151 stop_at_entry,
152 error);
153}
Greg Claytonde915be2011-01-23 05:56:20 +0000154
155SBProcess
156SBTarget::Launch
157(
Greg Clayton271a5db2011-02-03 21:28:34 +0000158 SBListener &listener,
Greg Claytonde915be2011-01-23 05:56:20 +0000159 char const **argv,
160 char const **envp,
161 const char *stdin_path,
162 const char *stdout_path,
163 const char *stderr_path,
164 const char *working_directory,
165 uint32_t launch_flags, // See LaunchFlags
166 bool stop_at_entry,
167 lldb::SBError& error
168)
169{
Greg Claytone005f2c2010-11-06 01:53:30 +0000170 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000171
Greg Clayton0416bdf2012-01-30 09:04:36 +0000172 SBProcess sb_process;
173 ProcessSP process_sp;
174 TargetSP target_sp(GetSP());
175
Caroline Tice7826c882010-10-26 03:11:13 +0000176 if (log)
Greg Clayton3f5ee7f2010-10-29 04:59:35 +0000177 {
Greg Claytonde915be2011-01-23 05:56:20 +0000178 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))...",
Greg Clayton0416bdf2012-01-30 09:04:36 +0000179 target_sp.get(),
Greg Claytonde915be2011-01-23 05:56:20 +0000180 argv,
181 envp,
182 stdin_path ? stdin_path : "NULL",
183 stdout_path ? stdout_path : "NULL",
184 stderr_path ? stderr_path : "NULL",
185 working_directory ? working_directory : "NULL",
186 launch_flags,
187 stop_at_entry,
188 error.get());
Greg Clayton3f5ee7f2010-10-29 04:59:35 +0000189 }
Greg Clayton0416bdf2012-01-30 09:04:36 +0000190
191 if (target_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000192 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000193 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton1a3083a2010-10-06 03:53:16 +0000194
Greg Clayton7c330d62011-01-27 01:01:10 +0000195 if (getenv("LLDB_LAUNCH_FLAG_DISABLE_ASLR"))
196 launch_flags |= eLaunchFlagDisableASLR;
197
Greg Clayton180546b2011-04-30 01:09:13 +0000198 StateType state = eStateInvalid;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000199 process_sp = target_sp->GetProcessSP();
Greg Clayton334d33a2012-01-30 07:41:31 +0000200 if (process_sp)
Greg Clayton28d5fcc2011-01-27 06:44:37 +0000201 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000202 state = process_sp->GetState();
Greg Clayton180546b2011-04-30 01:09:13 +0000203
Greg Clayton334d33a2012-01-30 07:41:31 +0000204 if (process_sp->IsAlive() && state != eStateConnected)
Greg Clayton180546b2011-04-30 01:09:13 +0000205 {
206 if (state == eStateAttaching)
207 error.SetErrorString ("process attach is in progress");
208 else
209 error.SetErrorString ("a process is already being debugged");
Greg Clayton180546b2011-04-30 01:09:13 +0000210 return sb_process;
211 }
Greg Clayton28d5fcc2011-01-27 06:44:37 +0000212 }
213
Greg Clayton180546b2011-04-30 01:09:13 +0000214 if (state == eStateConnected)
215 {
216 // If we are already connected, then we have already specified the
217 // listener, so if a valid listener is supplied, we need to error out
218 // to let the client know.
219 if (listener.IsValid())
220 {
221 error.SetErrorString ("process is connected and already has a listener, pass empty listener");
Greg Clayton180546b2011-04-30 01:09:13 +0000222 return sb_process;
223 }
224 }
225 else
Greg Claytonc5f728c2010-10-06 22:10:17 +0000226 {
Greg Clayton271a5db2011-02-03 21:28:34 +0000227 if (listener.IsValid())
Greg Clayton0416bdf2012-01-30 09:04:36 +0000228 process_sp = target_sp->CreateProcess (listener.ref());
Greg Clayton271a5db2011-02-03 21:28:34 +0000229 else
Greg Clayton0416bdf2012-01-30 09:04:36 +0000230 process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener());
Greg Clayton180546b2011-04-30 01:09:13 +0000231 }
Greg Clayton7c330d62011-01-27 01:01:10 +0000232
Greg Clayton334d33a2012-01-30 07:41:31 +0000233 if (process_sp)
Greg Clayton180546b2011-04-30 01:09:13 +0000234 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000235 sb_process.SetSP (process_sp);
Greg Clayton180546b2011-04-30 01:09:13 +0000236 if (getenv("LLDB_LAUNCH_FLAG_DISABLE_STDIO"))
237 launch_flags |= eLaunchFlagDisableSTDIO;
238
Greg Clayton36bc5ea2011-11-03 21:22:33 +0000239 ProcessLaunchInfo launch_info (stdin_path, stdout_path, stderr_path, working_directory, launch_flags);
240
Greg Clayton0416bdf2012-01-30 09:04:36 +0000241 Module *exe_module = target_sp->GetExecutableModulePointer();
Greg Clayton36bc5ea2011-11-03 21:22:33 +0000242 if (exe_module)
Greg Clayton1d1f39e2011-11-29 04:03:30 +0000243 launch_info.SetExecutableFile(exe_module->GetPlatformFileSpec(), true);
Greg Clayton36bc5ea2011-11-03 21:22:33 +0000244 if (argv)
245 launch_info.GetArguments().AppendArguments (argv);
246 if (envp)
247 launch_info.GetEnvironmentEntries ().SetArguments (envp);
248
Greg Clayton334d33a2012-01-30 07:41:31 +0000249 error.SetError (process_sp->Launch (launch_info));
Greg Clayton180546b2011-04-30 01:09:13 +0000250 if (error.Success())
Greg Clayton7c330d62011-01-27 01:01:10 +0000251 {
Greg Clayton180546b2011-04-30 01:09:13 +0000252 // We we are stopping at the entry point, we can return now!
253 if (stop_at_entry)
254 return sb_process;
Greg Clayton7c330d62011-01-27 01:01:10 +0000255
Greg Clayton180546b2011-04-30 01:09:13 +0000256 // Make sure we are stopped at the entry
Greg Clayton334d33a2012-01-30 07:41:31 +0000257 StateType state = process_sp->WaitForProcessToStop (NULL);
Greg Clayton180546b2011-04-30 01:09:13 +0000258 if (state == eStateStopped)
Greg Clayton7c330d62011-01-27 01:01:10 +0000259 {
Greg Clayton180546b2011-04-30 01:09:13 +0000260 // resume the process to skip the entry point
Greg Clayton334d33a2012-01-30 07:41:31 +0000261 error.SetError (process_sp->Resume());
Greg Clayton180546b2011-04-30 01:09:13 +0000262 if (error.Success())
Greg Clayton7c330d62011-01-27 01:01:10 +0000263 {
Greg Clayton180546b2011-04-30 01:09:13 +0000264 // If we are doing synchronous mode, then wait for the
265 // process to stop yet again!
Greg Clayton0416bdf2012-01-30 09:04:36 +0000266 if (target_sp->GetDebugger().GetAsyncExecution () == false)
Greg Clayton334d33a2012-01-30 07:41:31 +0000267 process_sp->WaitForProcessToStop (NULL);
Greg Clayton7c330d62011-01-27 01:01:10 +0000268 }
269 }
270 }
Greg Clayton180546b2011-04-30 01:09:13 +0000271 }
272 else
273 {
274 error.SetErrorString ("unable to create lldb_private::Process");
Greg Claytonc5f728c2010-10-06 22:10:17 +0000275 }
276 }
277 else
278 {
279 error.SetErrorString ("SBTarget is invalid");
Chris Lattner24943d22010-06-08 16:52:24 +0000280 }
Caroline Tice7826c882010-10-26 03:11:13 +0000281
Caroline Tice926060e2010-10-29 21:48:37 +0000282 log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
Caroline Tice7826c882010-10-26 03:11:13 +0000283 if (log)
284 {
Greg Clayton49ce6822010-10-31 03:01:06 +0000285 log->Printf ("SBTarget(%p)::Launch (...) => SBProceess(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +0000286 target_sp.get(), process_sp.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000287 }
288
Greg Clayton1a3083a2010-10-06 03:53:16 +0000289 return sb_process;
Chris Lattner24943d22010-06-08 16:52:24 +0000290}
291
Greg Claytond5b0b442011-12-02 02:10:57 +0000292#if defined(__APPLE__)
293
294lldb::SBProcess
295SBTarget::AttachToProcessWithID (SBListener &listener,
296 ::pid_t pid,
297 lldb::SBError& error)
298{
299 return AttachToProcessWithID (listener, (lldb::pid_t)pid, error);
300}
301
302#endif // #if defined(__APPLE__)
Greg Claytonc5f728c2010-10-06 22:10:17 +0000303
304lldb::SBProcess
Greg Claytond8c62532010-10-07 04:19:01 +0000305SBTarget::AttachToProcessWithID
Greg Claytonc5f728c2010-10-06 22:10:17 +0000306(
Greg Clayton271a5db2011-02-03 21:28:34 +0000307 SBListener &listener,
Greg Claytonc5f728c2010-10-06 22:10:17 +0000308 lldb::pid_t pid,// The process ID to attach to
309 SBError& error // An error explaining what went wrong if attach fails
310)
311{
312 SBProcess sb_process;
Greg Clayton334d33a2012-01-30 07:41:31 +0000313 ProcessSP process_sp;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000314 TargetSP target_sp(GetSP());
315 if (target_sp)
Greg Claytonc5f728c2010-10-06 22:10:17 +0000316 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000317 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytonde1dd812011-06-24 03:21:43 +0000318
319 StateType state = eStateInvalid;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000320 process_sp = target_sp->GetProcessSP();
Greg Clayton334d33a2012-01-30 07:41:31 +0000321 if (process_sp)
Greg Claytonde1dd812011-06-24 03:21:43 +0000322 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000323 state = process_sp->GetState();
Greg Claytonde1dd812011-06-24 03:21:43 +0000324
Greg Clayton334d33a2012-01-30 07:41:31 +0000325 if (process_sp->IsAlive() && state != eStateConnected)
Greg Claytonde1dd812011-06-24 03:21:43 +0000326 {
327 if (state == eStateAttaching)
328 error.SetErrorString ("process attach is in progress");
329 else
330 error.SetErrorString ("a process is already being debugged");
Greg Claytonde1dd812011-06-24 03:21:43 +0000331 return sb_process;
332 }
333 }
334
335 if (state == eStateConnected)
336 {
337 // If we are already connected, then we have already specified the
338 // listener, so if a valid listener is supplied, we need to error out
339 // to let the client know.
340 if (listener.IsValid())
341 {
342 error.SetErrorString ("process is connected and already has a listener, pass empty listener");
Greg Claytonde1dd812011-06-24 03:21:43 +0000343 return sb_process;
344 }
345 }
Greg Clayton271a5db2011-02-03 21:28:34 +0000346 else
Greg Claytonde1dd812011-06-24 03:21:43 +0000347 {
348 if (listener.IsValid())
Greg Clayton0416bdf2012-01-30 09:04:36 +0000349 process_sp = target_sp->CreateProcess (listener.ref());
Greg Claytonde1dd812011-06-24 03:21:43 +0000350 else
Greg Clayton0416bdf2012-01-30 09:04:36 +0000351 process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener());
Greg Claytonde1dd812011-06-24 03:21:43 +0000352 }
Greg Clayton334d33a2012-01-30 07:41:31 +0000353 if (process_sp)
Greg Claytonc5f728c2010-10-06 22:10:17 +0000354 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000355 sb_process.SetSP (process_sp);
356
Greg Clayton527154d2011-11-15 03:53:30 +0000357 ProcessAttachInfo attach_info;
358 attach_info.SetProcessID (pid);
Greg Clayton334d33a2012-01-30 07:41:31 +0000359 error.SetError (process_sp->Attach (attach_info));
Johnny Chen535960e2011-06-17 00:51:15 +0000360 // If we are doing synchronous mode, then wait for the
361 // process to stop!
Greg Clayton0416bdf2012-01-30 09:04:36 +0000362 if (target_sp->GetDebugger().GetAsyncExecution () == false)
Greg Clayton334d33a2012-01-30 07:41:31 +0000363 process_sp->WaitForProcessToStop (NULL);
Greg Claytonc5f728c2010-10-06 22:10:17 +0000364 }
365 else
366 {
367 error.SetErrorString ("unable to create lldb_private::Process");
368 }
369 }
370 else
371 {
372 error.SetErrorString ("SBTarget is invalid");
373 }
374 return sb_process;
375
376}
377
378lldb::SBProcess
Greg Claytond8c62532010-10-07 04:19:01 +0000379SBTarget::AttachToProcessWithName
Greg Claytonc5f728c2010-10-06 22:10:17 +0000380(
Greg Clayton271a5db2011-02-03 21:28:34 +0000381 SBListener &listener,
Greg Claytonc5f728c2010-10-06 22:10:17 +0000382 const char *name, // basename of process to attach to
383 bool wait_for, // if true wait for a new instance of "name" to be launched
384 SBError& error // An error explaining what went wrong if attach fails
385)
386{
387 SBProcess sb_process;
Greg Clayton334d33a2012-01-30 07:41:31 +0000388 ProcessSP process_sp;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000389 TargetSP target_sp(GetSP());
390 if (name && target_sp)
Greg Claytonc5f728c2010-10-06 22:10:17 +0000391 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000392 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytonbdcda462010-12-20 20:49:23 +0000393
Greg Claytonde1dd812011-06-24 03:21:43 +0000394 StateType state = eStateInvalid;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000395 process_sp = target_sp->GetProcessSP();
Greg Clayton334d33a2012-01-30 07:41:31 +0000396 if (process_sp)
Greg Claytonde1dd812011-06-24 03:21:43 +0000397 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000398 state = process_sp->GetState();
Greg Claytonde1dd812011-06-24 03:21:43 +0000399
Greg Clayton334d33a2012-01-30 07:41:31 +0000400 if (process_sp->IsAlive() && state != eStateConnected)
Greg Claytonde1dd812011-06-24 03:21:43 +0000401 {
402 if (state == eStateAttaching)
403 error.SetErrorString ("process attach is in progress");
404 else
405 error.SetErrorString ("a process is already being debugged");
Greg Claytonde1dd812011-06-24 03:21:43 +0000406 return sb_process;
407 }
408 }
409
410 if (state == eStateConnected)
411 {
412 // If we are already connected, then we have already specified the
413 // listener, so if a valid listener is supplied, we need to error out
414 // to let the client know.
415 if (listener.IsValid())
416 {
417 error.SetErrorString ("process is connected and already has a listener, pass empty listener");
Greg Claytonde1dd812011-06-24 03:21:43 +0000418 return sb_process;
419 }
420 }
Greg Clayton271a5db2011-02-03 21:28:34 +0000421 else
Greg Claytonde1dd812011-06-24 03:21:43 +0000422 {
423 if (listener.IsValid())
Greg Clayton0416bdf2012-01-30 09:04:36 +0000424 process_sp = target_sp->CreateProcess (listener.ref());
Greg Claytonde1dd812011-06-24 03:21:43 +0000425 else
Greg Clayton0416bdf2012-01-30 09:04:36 +0000426 process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener());
Greg Claytonde1dd812011-06-24 03:21:43 +0000427 }
Greg Claytonc5f728c2010-10-06 22:10:17 +0000428
Greg Clayton334d33a2012-01-30 07:41:31 +0000429 if (process_sp)
Greg Claytonc5f728c2010-10-06 22:10:17 +0000430 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000431 sb_process.SetSP (process_sp);
Greg Clayton527154d2011-11-15 03:53:30 +0000432 ProcessAttachInfo attach_info;
433 attach_info.GetExecutableFile().SetFile(name, false);
434 attach_info.SetWaitForLaunch(wait_for);
Greg Clayton334d33a2012-01-30 07:41:31 +0000435 error.SetError (process_sp->Attach (attach_info));
Johnny Chen58d02ff2011-06-17 19:21:30 +0000436 // If we are doing synchronous mode, then wait for the
437 // process to stop!
Greg Clayton0416bdf2012-01-30 09:04:36 +0000438 if (target_sp->GetDebugger().GetAsyncExecution () == false)
Greg Clayton334d33a2012-01-30 07:41:31 +0000439 process_sp->WaitForProcessToStop (NULL);
Greg Claytonc5f728c2010-10-06 22:10:17 +0000440 }
441 else
442 {
443 error.SetErrorString ("unable to create lldb_private::Process");
444 }
445 }
446 else
447 {
448 error.SetErrorString ("SBTarget is invalid");
449 }
450 return sb_process;
451
452}
453
James McIlree38093402011-03-04 00:31:13 +0000454lldb::SBProcess
455SBTarget::ConnectRemote
456(
457 SBListener &listener,
458 const char *url,
459 const char *plugin_name,
460 SBError& error
461)
462{
463 SBProcess sb_process;
Greg Clayton334d33a2012-01-30 07:41:31 +0000464 ProcessSP process_sp;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000465 TargetSP target_sp(GetSP());
466 if (target_sp)
James McIlree38093402011-03-04 00:31:13 +0000467 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000468 Mutex::Locker api_locker (target_sp->GetAPIMutex());
James McIlree38093402011-03-04 00:31:13 +0000469 if (listener.IsValid())
Greg Clayton0416bdf2012-01-30 09:04:36 +0000470 process_sp = target_sp->CreateProcess (listener.ref(), plugin_name);
James McIlree38093402011-03-04 00:31:13 +0000471 else
Greg Clayton0416bdf2012-01-30 09:04:36 +0000472 process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener(), plugin_name);
James McIlree38093402011-03-04 00:31:13 +0000473
474
Greg Clayton334d33a2012-01-30 07:41:31 +0000475 if (process_sp)
James McIlree38093402011-03-04 00:31:13 +0000476 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000477 sb_process.SetSP (process_sp);
478 error.SetError (process_sp->ConnectRemote (url));
James McIlree38093402011-03-04 00:31:13 +0000479 }
480 else
481 {
482 error.SetErrorString ("unable to create lldb_private::Process");
483 }
484 }
485 else
486 {
487 error.SetErrorString ("SBTarget is invalid");
488 }
489 return sb_process;
490}
491
Chris Lattner24943d22010-06-08 16:52:24 +0000492SBFileSpec
493SBTarget::GetExecutable ()
494{
Caroline Tice7826c882010-10-26 03:11:13 +0000495
Chris Lattner24943d22010-06-08 16:52:24 +0000496 SBFileSpec exe_file_spec;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000497 TargetSP target_sp(GetSP());
498 if (target_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000499 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000500 Module *exe_module = target_sp->GetExecutableModulePointer();
Greg Clayton5beb99d2011-08-11 02:48:45 +0000501 if (exe_module)
502 exe_file_spec.SetFileSpec (exe_module->GetFileSpec());
Chris Lattner24943d22010-06-08 16:52:24 +0000503 }
Caroline Tice7826c882010-10-26 03:11:13 +0000504
Greg Claytone005f2c2010-11-06 01:53:30 +0000505 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000506 if (log)
507 {
Greg Clayton49ce6822010-10-31 03:01:06 +0000508 log->Printf ("SBTarget(%p)::GetExecutable () => SBFileSpec(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +0000509 target_sp.get(), exe_file_spec.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000510 }
511
Chris Lattner24943d22010-06-08 16:52:24 +0000512 return exe_file_spec;
513}
514
Chris Lattner24943d22010-06-08 16:52:24 +0000515bool
Chris Lattner24943d22010-06-08 16:52:24 +0000516SBTarget::operator == (const SBTarget &rhs) const
517{
Greg Clayton63094e02010-06-23 01:19:29 +0000518 return m_opaque_sp.get() == rhs.m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000519}
520
521bool
522SBTarget::operator != (const SBTarget &rhs) const
523{
Greg Clayton63094e02010-06-23 01:19:29 +0000524 return m_opaque_sp.get() != rhs.m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000525}
526
Greg Clayton334d33a2012-01-30 07:41:31 +0000527lldb::TargetSP
528SBTarget::GetSP () const
Greg Clayton15afa9f2011-10-01 02:59:24 +0000529{
530 return m_opaque_sp;
531}
532
Greg Clayton63094e02010-06-23 01:19:29 +0000533void
Greg Clayton334d33a2012-01-30 07:41:31 +0000534SBTarget::SetSP (const lldb::TargetSP& target_sp)
Greg Clayton63094e02010-06-23 01:19:29 +0000535{
536 m_opaque_sp = target_sp;
Chris Lattner24943d22010-06-08 16:52:24 +0000537}
538
Greg Claytona3955062011-07-22 16:46:35 +0000539lldb::SBAddress
540SBTarget::ResolveLoadAddress (lldb::addr_t vm_addr)
Greg Claytonea49cc72010-12-12 19:25:26 +0000541{
Greg Claytona3955062011-07-22 16:46:35 +0000542 lldb::SBAddress sb_addr;
543 Address &addr = sb_addr.ref();
Greg Clayton0416bdf2012-01-30 09:04:36 +0000544 TargetSP target_sp(GetSP());
545 if (target_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000546 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000547 Mutex::Locker api_locker (target_sp->GetAPIMutex());
548 if (target_sp->GetSectionLoadList().ResolveLoadAddress (vm_addr, addr))
Greg Claytona3955062011-07-22 16:46:35 +0000549 return sb_addr;
Greg Claytonbdcda462010-12-20 20:49:23 +0000550 }
Greg Claytonea49cc72010-12-12 19:25:26 +0000551
Greg Claytona3955062011-07-22 16:46:35 +0000552 // We have a load address that isn't in a section, just return an address
553 // with the offset filled in (the address) and the section set to NULL
554 addr.SetSection(NULL);
555 addr.SetOffset(vm_addr);
556 return sb_addr;
Greg Claytonea49cc72010-12-12 19:25:26 +0000557}
558
Greg Claytonafb81862011-03-02 21:34:46 +0000559SBSymbolContext
560SBTarget::ResolveSymbolContextForAddress (const SBAddress& addr, uint32_t resolve_scope)
561{
562 SBSymbolContext sc;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000563 if (addr.IsValid())
564 {
565 TargetSP target_sp(GetSP());
566 if (target_sp)
567 target_sp->GetImages().ResolveSymbolContextForAddress (addr.ref(), resolve_scope, sc.ref());
568 }
Greg Claytonafb81862011-03-02 21:34:46 +0000569 return sc;
570}
571
572
Chris Lattner24943d22010-06-08 16:52:24 +0000573SBBreakpoint
574SBTarget::BreakpointCreateByLocation (const char *file, uint32_t line)
575{
Greg Claytond6d806c2010-11-08 00:28:40 +0000576 return SBBreakpoint(BreakpointCreateByLocation (SBFileSpec (file, false), line));
Chris Lattner24943d22010-06-08 16:52:24 +0000577}
578
579SBBreakpoint
580SBTarget::BreakpointCreateByLocation (const SBFileSpec &sb_file_spec, uint32_t line)
581{
Greg Claytone005f2c2010-11-06 01:53:30 +0000582 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000583
Chris Lattner24943d22010-06-08 16:52:24 +0000584 SBBreakpoint sb_bp;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000585 TargetSP target_sp(GetSP());
586 if (target_sp && line != 0)
Greg Claytonbdcda462010-12-20 20:49:23 +0000587 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000588 Mutex::Locker api_locker (target_sp->GetAPIMutex());
589 *sb_bp = target_sp->CreateBreakpoint (NULL, *sb_file_spec, line, true, false);
Greg Claytonbdcda462010-12-20 20:49:23 +0000590 }
Caroline Tice7826c882010-10-26 03:11:13 +0000591
592 if (log)
593 {
594 SBStream sstr;
595 sb_bp.GetDescription (sstr);
Greg Clayton49ce6822010-10-31 03:01:06 +0000596 char path[PATH_MAX];
597 sb_file_spec->GetPath (path, sizeof(path));
598 log->Printf ("SBTarget(%p)::BreakpointCreateByLocation ( %s:%u ) => SBBreakpoint(%p): %s",
Greg Clayton0416bdf2012-01-30 09:04:36 +0000599 target_sp.get(),
Greg Clayton49ce6822010-10-31 03:01:06 +0000600 path,
Greg Claytona66ba462010-10-30 04:51:46 +0000601 line,
Greg Clayton49ce6822010-10-31 03:01:06 +0000602 sb_bp.get(),
Caroline Tice7826c882010-10-26 03:11:13 +0000603 sstr.GetData());
604 }
605
Chris Lattner24943d22010-06-08 16:52:24 +0000606 return sb_bp;
607}
608
609SBBreakpoint
610SBTarget::BreakpointCreateByName (const char *symbol_name, const char *module_name)
611{
Greg Claytone005f2c2010-11-06 01:53:30 +0000612 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000613
Chris Lattner24943d22010-06-08 16:52:24 +0000614 SBBreakpoint sb_bp;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000615 TargetSP target_sp(GetSP());
616 if (target_sp.get())
Chris Lattner24943d22010-06-08 16:52:24 +0000617 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000618 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Chris Lattner24943d22010-06-08 16:52:24 +0000619 if (module_name && module_name[0])
620 {
Jim Ingham03c8ee52011-09-21 01:17:13 +0000621 FileSpecList module_spec_list;
622 module_spec_list.Append (FileSpec (module_name, false));
Greg Clayton0416bdf2012-01-30 09:04:36 +0000623 *sb_bp = target_sp->CreateBreakpoint (&module_spec_list, NULL, symbol_name, eFunctionNameTypeAuto, false);
Chris Lattner24943d22010-06-08 16:52:24 +0000624 }
625 else
626 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000627 *sb_bp = target_sp->CreateBreakpoint (NULL, NULL, symbol_name, eFunctionNameTypeAuto, false);
Chris Lattner24943d22010-06-08 16:52:24 +0000628 }
629 }
Caroline Tice7826c882010-10-26 03:11:13 +0000630
631 if (log)
632 {
Greg Clayton49ce6822010-10-31 03:01:06 +0000633 log->Printf ("SBTarget(%p)::BreakpointCreateByName (symbol=\"%s\", module=\"%s\") => SBBreakpoint(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +0000634 target_sp.get(), symbol_name, module_name, sb_bp.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000635 }
636
Chris Lattner24943d22010-06-08 16:52:24 +0000637 return sb_bp;
638}
639
Jim Inghamd6d47972011-09-23 00:54:11 +0000640lldb::SBBreakpoint
641SBTarget::BreakpointCreateByName (const char *symbol_name,
642 const SBFileSpecList &module_list,
643 const SBFileSpecList &comp_unit_list)
644{
Jim Ingham1fb8a2d2011-10-11 01:18:55 +0000645 uint32_t name_type_mask = eFunctionNameTypeAuto;
646 return BreakpointCreateByName (symbol_name, name_type_mask, module_list, comp_unit_list);
647}
648
649lldb::SBBreakpoint
650SBTarget::BreakpointCreateByName (const char *symbol_name,
651 uint32_t name_type_mask,
652 const SBFileSpecList &module_list,
653 const SBFileSpecList &comp_unit_list)
654{
Jim Inghamd6d47972011-09-23 00:54:11 +0000655 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
656
657 SBBreakpoint sb_bp;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000658 TargetSP target_sp(GetSP());
659 if (target_sp && symbol_name && symbol_name[0])
Jim Inghamd6d47972011-09-23 00:54:11 +0000660 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000661 Mutex::Locker api_locker (target_sp->GetAPIMutex());
662 *sb_bp = target_sp->CreateBreakpoint (module_list.get(),
Jim Inghamd6d47972011-09-23 00:54:11 +0000663 comp_unit_list.get(),
664 symbol_name,
Jim Ingham1fb8a2d2011-10-11 01:18:55 +0000665 name_type_mask,
Jim Inghamd6d47972011-09-23 00:54:11 +0000666 false);
667 }
668
669 if (log)
670 {
Jim Ingham1fb8a2d2011-10-11 01:18:55 +0000671 log->Printf ("SBTarget(%p)::BreakpointCreateByName (symbol=\"%s\", name_type: %d) => SBBreakpoint(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +0000672 target_sp.get(), symbol_name, name_type_mask, sb_bp.get());
Jim Inghamd6d47972011-09-23 00:54:11 +0000673 }
674
675 return sb_bp;
676}
677
678
Chris Lattner24943d22010-06-08 16:52:24 +0000679SBBreakpoint
680SBTarget::BreakpointCreateByRegex (const char *symbol_name_regex, const char *module_name)
681{
Greg Claytone005f2c2010-11-06 01:53:30 +0000682 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000683
Chris Lattner24943d22010-06-08 16:52:24 +0000684 SBBreakpoint sb_bp;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000685 TargetSP target_sp(GetSP());
686 if (target_sp && symbol_name_regex && symbol_name_regex[0])
Chris Lattner24943d22010-06-08 16:52:24 +0000687 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000688 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Chris Lattner24943d22010-06-08 16:52:24 +0000689 RegularExpression regexp(symbol_name_regex);
690
691 if (module_name && module_name[0])
692 {
Jim Ingham03c8ee52011-09-21 01:17:13 +0000693 FileSpecList module_spec_list;
694 module_spec_list.Append (FileSpec (module_name, false));
Chris Lattner24943d22010-06-08 16:52:24 +0000695
Greg Clayton0416bdf2012-01-30 09:04:36 +0000696 *sb_bp = target_sp->CreateFuncRegexBreakpoint (&module_spec_list, NULL, regexp, false);
Chris Lattner24943d22010-06-08 16:52:24 +0000697 }
698 else
699 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000700 *sb_bp = target_sp->CreateFuncRegexBreakpoint (NULL, NULL, regexp, false);
Chris Lattner24943d22010-06-08 16:52:24 +0000701 }
702 }
Caroline Tice7826c882010-10-26 03:11:13 +0000703
704 if (log)
705 {
Greg Clayton49ce6822010-10-31 03:01:06 +0000706 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (symbol_regex=\"%s\", module_name=\"%s\") => SBBreakpoint(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +0000707 target_sp.get(), symbol_name_regex, module_name, sb_bp.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000708 }
709
Chris Lattner24943d22010-06-08 16:52:24 +0000710 return sb_bp;
711}
712
Jim Inghamd6d47972011-09-23 00:54:11 +0000713lldb::SBBreakpoint
714SBTarget::BreakpointCreateByRegex (const char *symbol_name_regex,
715 const SBFileSpecList &module_list,
716 const SBFileSpecList &comp_unit_list)
717{
718 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Chris Lattner24943d22010-06-08 16:52:24 +0000719
Jim Inghamd6d47972011-09-23 00:54:11 +0000720 SBBreakpoint sb_bp;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000721 TargetSP target_sp(GetSP());
722 if (target_sp && symbol_name_regex && symbol_name_regex[0])
Jim Inghamd6d47972011-09-23 00:54:11 +0000723 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000724 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Jim Inghamd6d47972011-09-23 00:54:11 +0000725 RegularExpression regexp(symbol_name_regex);
726
Greg Clayton0416bdf2012-01-30 09:04:36 +0000727 *sb_bp = target_sp->CreateFuncRegexBreakpoint (module_list.get(), comp_unit_list.get(), regexp, false);
Jim Inghamd6d47972011-09-23 00:54:11 +0000728 }
729
730 if (log)
731 {
732 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (symbol_regex=\"%s\") => SBBreakpoint(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +0000733 target_sp.get(), symbol_name_regex, sb_bp.get());
Jim Inghamd6d47972011-09-23 00:54:11 +0000734 }
735
736 return sb_bp;
737}
Chris Lattner24943d22010-06-08 16:52:24 +0000738
739SBBreakpoint
740SBTarget::BreakpointCreateByAddress (addr_t address)
741{
Greg Claytone005f2c2010-11-06 01:53:30 +0000742 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000743
Chris Lattner24943d22010-06-08 16:52:24 +0000744 SBBreakpoint sb_bp;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000745 TargetSP target_sp(GetSP());
746 if (target_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000747 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000748 Mutex::Locker api_locker (target_sp->GetAPIMutex());
749 *sb_bp = target_sp->CreateBreakpoint (address, false);
Greg Claytonbdcda462010-12-20 20:49:23 +0000750 }
Caroline Tice7826c882010-10-26 03:11:13 +0000751
752 if (log)
753 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000754 log->Printf ("SBTarget(%p)::BreakpointCreateByAddress (address=%llu) => SBBreakpoint(%p)", target_sp.get(), (uint64_t) address, sb_bp.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000755 }
756
Chris Lattner24943d22010-06-08 16:52:24 +0000757 return sb_bp;
758}
759
Jim Ingham03c8ee52011-09-21 01:17:13 +0000760lldb::SBBreakpoint
761SBTarget::BreakpointCreateBySourceRegex (const char *source_regex, const lldb::SBFileSpec &source_file, const char *module_name)
762{
763 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
764
765 SBBreakpoint sb_bp;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000766 TargetSP target_sp(GetSP());
767 if (target_sp && source_regex && source_regex[0])
Jim Ingham03c8ee52011-09-21 01:17:13 +0000768 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000769 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Jim Ingham03c8ee52011-09-21 01:17:13 +0000770 RegularExpression regexp(source_regex);
Jim Inghamd6d47972011-09-23 00:54:11 +0000771 FileSpecList source_file_spec_list;
772 source_file_spec_list.Append (source_file.ref());
Jim Ingham03c8ee52011-09-21 01:17:13 +0000773
774 if (module_name && module_name[0])
775 {
776 FileSpecList module_spec_list;
777 module_spec_list.Append (FileSpec (module_name, false));
778
Greg Clayton0416bdf2012-01-30 09:04:36 +0000779 *sb_bp = target_sp->CreateSourceRegexBreakpoint (&module_spec_list, &source_file_spec_list, regexp, false);
Jim Ingham03c8ee52011-09-21 01:17:13 +0000780 }
781 else
782 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000783 *sb_bp = target_sp->CreateSourceRegexBreakpoint (NULL, &source_file_spec_list, regexp, false);
Jim Ingham03c8ee52011-09-21 01:17:13 +0000784 }
785 }
786
787 if (log)
788 {
789 char path[PATH_MAX];
790 source_file->GetPath (path, sizeof(path));
791 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (source_regex=\"%s\", file=\"%s\", module_name=\"%s\") => SBBreakpoint(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +0000792 target_sp.get(), source_regex, path, module_name, sb_bp.get());
Jim Ingham03c8ee52011-09-21 01:17:13 +0000793 }
794
795 return sb_bp;
796}
797
Jim Inghamd6d47972011-09-23 00:54:11 +0000798lldb::SBBreakpoint
799SBTarget::BreakpointCreateBySourceRegex (const char *source_regex,
800 const SBFileSpecList &module_list,
801 const lldb::SBFileSpecList &source_file_list)
802{
803 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
804
805 SBBreakpoint sb_bp;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000806 TargetSP target_sp(GetSP());
807 if (target_sp && source_regex && source_regex[0])
Jim Inghamd6d47972011-09-23 00:54:11 +0000808 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000809 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Jim Inghamd6d47972011-09-23 00:54:11 +0000810 RegularExpression regexp(source_regex);
Greg Clayton0416bdf2012-01-30 09:04:36 +0000811 *sb_bp = target_sp->CreateSourceRegexBreakpoint (module_list.get(), source_file_list.get(), regexp, false);
Jim Inghamd6d47972011-09-23 00:54:11 +0000812 }
813
814 if (log)
815 {
816 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (source_regex=\"%s\") => SBBreakpoint(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +0000817 target_sp.get(), source_regex, sb_bp.get());
Jim Inghamd6d47972011-09-23 00:54:11 +0000818 }
819
820 return sb_bp;
821}
Jim Ingham03c8ee52011-09-21 01:17:13 +0000822
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000823uint32_t
824SBTarget::GetNumBreakpoints () const
825{
Greg Clayton0416bdf2012-01-30 09:04:36 +0000826 TargetSP target_sp(GetSP());
827 if (target_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000828 {
829 // The breakpoint list is thread safe, no need to lock
Greg Clayton0416bdf2012-01-30 09:04:36 +0000830 return target_sp->GetBreakpointList().GetSize();
Greg Claytonbdcda462010-12-20 20:49:23 +0000831 }
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000832 return 0;
833}
834
835SBBreakpoint
836SBTarget::GetBreakpointAtIndex (uint32_t idx) const
837{
838 SBBreakpoint sb_breakpoint;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000839 TargetSP target_sp(GetSP());
840 if (target_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000841 {
842 // The breakpoint list is thread safe, no need to lock
Greg Clayton0416bdf2012-01-30 09:04:36 +0000843 *sb_breakpoint = target_sp->GetBreakpointList().GetBreakpointAtIndex(idx);
Greg Claytonbdcda462010-12-20 20:49:23 +0000844 }
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000845 return sb_breakpoint;
846}
Chris Lattner24943d22010-06-08 16:52:24 +0000847
848bool
849SBTarget::BreakpointDelete (break_id_t bp_id)
850{
Greg Claytone005f2c2010-11-06 01:53:30 +0000851 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000852
Caroline Tice7826c882010-10-26 03:11:13 +0000853 bool result = false;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000854 TargetSP target_sp(GetSP());
855 if (target_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000856 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000857 Mutex::Locker api_locker (target_sp->GetAPIMutex());
858 result = target_sp->RemoveBreakpointByID (bp_id);
Greg Claytonbdcda462010-12-20 20:49:23 +0000859 }
Caroline Tice7826c882010-10-26 03:11:13 +0000860
861 if (log)
862 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000863 log->Printf ("SBTarget(%p)::BreakpointDelete (bp_id=%d) => %i", target_sp.get(), (uint32_t) bp_id, result);
Caroline Tice7826c882010-10-26 03:11:13 +0000864 }
865
866 return result;
Chris Lattner24943d22010-06-08 16:52:24 +0000867}
868
Johnny Chen096c2932011-09-26 22:40:50 +0000869SBBreakpoint
870SBTarget::FindBreakpointByID (break_id_t bp_id)
871{
872 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
873
874 SBBreakpoint sb_breakpoint;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000875 TargetSP target_sp(GetSP());
876 if (target_sp && bp_id != LLDB_INVALID_BREAK_ID)
Johnny Chen096c2932011-09-26 22:40:50 +0000877 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000878 Mutex::Locker api_locker (target_sp->GetAPIMutex());
879 *sb_breakpoint = target_sp->GetBreakpointByID (bp_id);
Johnny Chen096c2932011-09-26 22:40:50 +0000880 }
881
882 if (log)
883 {
884 log->Printf ("SBTarget(%p)::FindBreakpointByID (bp_id=%d) => SBBreakpoint(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +0000885 target_sp.get(), (uint32_t) bp_id, sb_breakpoint.get());
Johnny Chen096c2932011-09-26 22:40:50 +0000886 }
887
888 return sb_breakpoint;
889}
890
Chris Lattner24943d22010-06-08 16:52:24 +0000891bool
892SBTarget::EnableAllBreakpoints ()
893{
Greg Clayton0416bdf2012-01-30 09:04:36 +0000894 TargetSP target_sp(GetSP());
895 if (target_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000896 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000897 Mutex::Locker api_locker (target_sp->GetAPIMutex());
898 target_sp->EnableAllBreakpoints ();
Chris Lattner24943d22010-06-08 16:52:24 +0000899 return true;
900 }
901 return false;
902}
903
904bool
905SBTarget::DisableAllBreakpoints ()
906{
Greg Clayton0416bdf2012-01-30 09:04:36 +0000907 TargetSP target_sp(GetSP());
908 if (target_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000909 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000910 Mutex::Locker api_locker (target_sp->GetAPIMutex());
911 target_sp->DisableAllBreakpoints ();
Chris Lattner24943d22010-06-08 16:52:24 +0000912 return true;
913 }
914 return false;
915}
916
917bool
918SBTarget::DeleteAllBreakpoints ()
919{
Greg Clayton0416bdf2012-01-30 09:04:36 +0000920 TargetSP target_sp(GetSP());
921 if (target_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000922 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000923 Mutex::Locker api_locker (target_sp->GetAPIMutex());
924 target_sp->RemoveAllBreakpoints ();
Chris Lattner24943d22010-06-08 16:52:24 +0000925 return true;
926 }
927 return false;
928}
929
Johnny Chen096c2932011-09-26 22:40:50 +0000930uint32_t
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000931SBTarget::GetNumWatchpoints () const
Johnny Chen096c2932011-09-26 22:40:50 +0000932{
Greg Clayton0416bdf2012-01-30 09:04:36 +0000933 TargetSP target_sp(GetSP());
934 if (target_sp)
Johnny Chen096c2932011-09-26 22:40:50 +0000935 {
Johnny Chenecd4feb2011-10-14 00:42:25 +0000936 // The watchpoint list is thread safe, no need to lock
Greg Clayton0416bdf2012-01-30 09:04:36 +0000937 return target_sp->GetWatchpointList().GetSize();
Johnny Chen096c2932011-09-26 22:40:50 +0000938 }
939 return 0;
940}
941
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000942SBWatchpoint
943SBTarget::GetWatchpointAtIndex (uint32_t idx) const
Johnny Chen5eb54bb2011-09-27 20:29:45 +0000944{
Johnny Chenecd4feb2011-10-14 00:42:25 +0000945 SBWatchpoint sb_watchpoint;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000946 TargetSP target_sp(GetSP());
947 if (target_sp)
Johnny Chen096c2932011-09-26 22:40:50 +0000948 {
Johnny Chenecd4feb2011-10-14 00:42:25 +0000949 // The watchpoint list is thread safe, no need to lock
Greg Clayton0416bdf2012-01-30 09:04:36 +0000950 *sb_watchpoint = target_sp->GetWatchpointList().GetByIndex(idx);
Johnny Chen096c2932011-09-26 22:40:50 +0000951 }
Johnny Chenecd4feb2011-10-14 00:42:25 +0000952 return sb_watchpoint;
Johnny Chen096c2932011-09-26 22:40:50 +0000953}
954
955bool
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000956SBTarget::DeleteWatchpoint (watch_id_t wp_id)
Johnny Chen096c2932011-09-26 22:40:50 +0000957{
958 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
959
960 bool result = false;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000961 TargetSP target_sp(GetSP());
962 if (target_sp)
Johnny Chen096c2932011-09-26 22:40:50 +0000963 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000964 Mutex::Locker api_locker (target_sp->GetAPIMutex());
965 result = target_sp->RemoveWatchpointByID (wp_id);
Johnny Chen096c2932011-09-26 22:40:50 +0000966 }
967
968 if (log)
969 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000970 log->Printf ("SBTarget(%p)::WatchpointDelete (wp_id=%d) => %i", target_sp.get(), (uint32_t) wp_id, result);
Johnny Chen096c2932011-09-26 22:40:50 +0000971 }
972
973 return result;
974}
975
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000976SBWatchpoint
977SBTarget::FindWatchpointByID (lldb::watch_id_t wp_id)
Johnny Chen096c2932011-09-26 22:40:50 +0000978{
979 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
980
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000981 SBWatchpoint sb_watchpoint;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000982 TargetSP target_sp(GetSP());
983 if (target_sp && wp_id != LLDB_INVALID_WATCH_ID)
Johnny Chen096c2932011-09-26 22:40:50 +0000984 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000985 Mutex::Locker api_locker (target_sp->GetAPIMutex());
986 *sb_watchpoint = target_sp->GetWatchpointList().FindByID(wp_id);
Johnny Chen096c2932011-09-26 22:40:50 +0000987 }
988
989 if (log)
990 {
Johnny Chenecd4feb2011-10-14 00:42:25 +0000991 log->Printf ("SBTarget(%p)::FindWatchpointByID (bp_id=%d) => SBWatchpoint(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +0000992 target_sp.get(), (uint32_t) wp_id, sb_watchpoint.get());
Johnny Chen096c2932011-09-26 22:40:50 +0000993 }
994
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000995 return sb_watchpoint;
996}
997
998lldb::SBWatchpoint
999SBTarget::WatchAddress (lldb::addr_t addr, size_t size, bool read, bool write)
1000{
1001 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1002
1003 SBWatchpoint sb_watchpoint;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001004 TargetSP target_sp(GetSP());
1005 if (target_sp)
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001006 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001007 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Johnny Chenecd4feb2011-10-14 00:42:25 +00001008 uint32_t watch_type = (read ? LLDB_WATCH_TYPE_READ : 0) |
1009 (write ? LLDB_WATCH_TYPE_WRITE : 0);
Greg Clayton0416bdf2012-01-30 09:04:36 +00001010 sb_watchpoint = target_sp->CreateWatchpoint(addr, size, watch_type);
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001011 }
1012
1013 if (log)
1014 {
1015 log->Printf ("SBTarget(%p)::WatchAddress (addr=0x%llx, 0x%u) => SBWatchpoint(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +00001016 target_sp.get(), addr, (uint32_t) size, sb_watchpoint.get());
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001017 }
1018
1019 return sb_watchpoint;
Johnny Chen096c2932011-09-26 22:40:50 +00001020}
1021
1022bool
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001023SBTarget::EnableAllWatchpoints ()
Johnny Chen096c2932011-09-26 22:40:50 +00001024{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001025 TargetSP target_sp(GetSP());
1026 if (target_sp)
Johnny Chen096c2932011-09-26 22:40:50 +00001027 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001028 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1029 target_sp->EnableAllWatchpoints ();
Johnny Chen096c2932011-09-26 22:40:50 +00001030 return true;
1031 }
1032 return false;
1033}
1034
1035bool
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001036SBTarget::DisableAllWatchpoints ()
Johnny Chen096c2932011-09-26 22:40:50 +00001037{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001038 TargetSP target_sp(GetSP());
1039 if (target_sp)
Johnny Chen096c2932011-09-26 22:40:50 +00001040 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001041 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1042 target_sp->DisableAllWatchpoints ();
Johnny Chen096c2932011-09-26 22:40:50 +00001043 return true;
1044 }
1045 return false;
1046}
1047
1048bool
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001049SBTarget::DeleteAllWatchpoints ()
Johnny Chen096c2932011-09-26 22:40:50 +00001050{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001051 TargetSP target_sp(GetSP());
1052 if (target_sp)
Johnny Chen096c2932011-09-26 22:40:50 +00001053 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001054 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1055 target_sp->RemoveAllWatchpoints ();
Johnny Chen096c2932011-09-26 22:40:50 +00001056 return true;
1057 }
1058 return false;
1059}
1060
Chris Lattner24943d22010-06-08 16:52:24 +00001061
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001062lldb::SBModule
1063SBTarget::AddModule (const char *path,
1064 const char *triple,
1065 const char *uuid_cstr)
1066{
1067 lldb::SBModule sb_module;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001068 TargetSP target_sp(GetSP());
1069 if (target_sp)
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001070 {
1071 FileSpec module_file_spec;
1072 UUID module_uuid;
1073 ArchSpec module_arch;
1074
1075 if (path)
1076 module_file_spec.SetFile(path, false);
1077
1078 if (uuid_cstr)
1079 module_uuid.SetfromCString(uuid_cstr);
1080
1081 if (triple)
Greg Clayton0416bdf2012-01-30 09:04:36 +00001082 module_arch.SetTriple (triple, target_sp->GetPlatform ().get());
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001083
Greg Clayton0416bdf2012-01-30 09:04:36 +00001084 sb_module.SetSP(target_sp->GetSharedModule (module_file_spec,
1085 module_arch,
1086 uuid_cstr ? &module_uuid : NULL));
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001087 }
1088 return sb_module;
1089}
1090
1091bool
1092SBTarget::AddModule (lldb::SBModule &module)
1093{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001094 TargetSP target_sp(GetSP());
1095 if (target_sp)
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001096 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001097 target_sp->GetImages().AppendIfNeeded (module.GetSP());
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001098 return true;
1099 }
1100 return false;
1101}
1102
Chris Lattner24943d22010-06-08 16:52:24 +00001103uint32_t
1104SBTarget::GetNumModules () const
1105{
Greg Claytone005f2c2010-11-06 01:53:30 +00001106 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001107
Caroline Tice7826c882010-10-26 03:11:13 +00001108 uint32_t num = 0;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001109 TargetSP target_sp(GetSP());
1110 if (target_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +00001111 {
1112 // The module list is thread safe, no need to lock
Greg Clayton0416bdf2012-01-30 09:04:36 +00001113 num = target_sp->GetImages().GetSize();
Greg Claytonbdcda462010-12-20 20:49:23 +00001114 }
Caroline Tice7826c882010-10-26 03:11:13 +00001115
1116 if (log)
Greg Clayton0416bdf2012-01-30 09:04:36 +00001117 log->Printf ("SBTarget(%p)::GetNumModules () => %d", target_sp.get(), num);
Caroline Tice7826c882010-10-26 03:11:13 +00001118
1119 return num;
Chris Lattner24943d22010-06-08 16:52:24 +00001120}
1121
Greg Clayton43490d12010-07-30 20:12:55 +00001122void
1123SBTarget::Clear ()
1124{
Greg Claytone005f2c2010-11-06 01:53:30 +00001125 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001126
1127 if (log)
Greg Clayton3f5ee7f2010-10-29 04:59:35 +00001128 log->Printf ("SBTarget(%p)::Clear ()", m_opaque_sp.get());
Caroline Tice7826c882010-10-26 03:11:13 +00001129
Greg Clayton43490d12010-07-30 20:12:55 +00001130 m_opaque_sp.reset();
1131}
1132
1133
Chris Lattner24943d22010-06-08 16:52:24 +00001134SBModule
1135SBTarget::FindModule (const SBFileSpec &sb_file_spec)
1136{
1137 SBModule sb_module;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001138 TargetSP target_sp(GetSP());
1139 if (target_sp && sb_file_spec.IsValid())
Greg Claytonbdcda462010-12-20 20:49:23 +00001140 {
1141 // The module list is thread safe, no need to lock
Greg Clayton0416bdf2012-01-30 09:04:36 +00001142 sb_module.SetSP (target_sp->GetImages().FindFirstModuleForFileSpec (*sb_file_spec, NULL, NULL));
Greg Claytonbdcda462010-12-20 20:49:23 +00001143 }
Chris Lattner24943d22010-06-08 16:52:24 +00001144 return sb_module;
1145}
1146
Greg Clayton1b925202012-01-29 06:07:39 +00001147lldb::ByteOrder
1148SBTarget::GetByteOrder ()
1149{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001150 TargetSP target_sp(GetSP());
1151 if (target_sp)
1152 return target_sp->GetArchitecture().GetByteOrder();
Greg Clayton1b925202012-01-29 06:07:39 +00001153 return eByteOrderInvalid;
1154}
1155
1156const char *
1157SBTarget::GetTriple ()
1158{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001159 TargetSP target_sp(GetSP());
1160 if (target_sp)
Greg Clayton1b925202012-01-29 06:07:39 +00001161 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001162 std::string triple (target_sp->GetArchitecture().GetTriple().str());
Greg Clayton1b925202012-01-29 06:07:39 +00001163 // Unique the string so we don't run into ownership issues since
1164 // the const strings put the string into the string pool once and
1165 // the strings never comes out
1166 ConstString const_triple (triple.c_str());
1167 return const_triple.GetCString();
1168 }
1169 return NULL;
1170}
1171
1172uint32_t
1173SBTarget::GetAddressByteSize()
1174{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001175 TargetSP target_sp(GetSP());
1176 if (target_sp)
1177 return target_sp->GetArchitecture().GetAddressByteSize();
Greg Clayton1b925202012-01-29 06:07:39 +00001178 return sizeof(void*);
1179}
1180
1181
Chris Lattner24943d22010-06-08 16:52:24 +00001182SBModule
1183SBTarget::GetModuleAtIndex (uint32_t idx)
1184{
Greg Claytone005f2c2010-11-06 01:53:30 +00001185 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001186
Chris Lattner24943d22010-06-08 16:52:24 +00001187 SBModule sb_module;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001188 ModuleSP module_sp;
1189 TargetSP target_sp(GetSP());
1190 if (target_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +00001191 {
1192 // The module list is thread safe, no need to lock
Greg Clayton0416bdf2012-01-30 09:04:36 +00001193 module_sp = target_sp->GetImages().GetModuleAtIndex(idx);
1194 sb_module.SetSP (module_sp);
Greg Claytonbdcda462010-12-20 20:49:23 +00001195 }
Caroline Tice7826c882010-10-26 03:11:13 +00001196
1197 if (log)
1198 {
Greg Clayton49ce6822010-10-31 03:01:06 +00001199 log->Printf ("SBTarget(%p)::GetModuleAtIndex (idx=%d) => SBModule(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +00001200 target_sp.get(), idx, module_sp.get());
Caroline Tice7826c882010-10-26 03:11:13 +00001201 }
1202
Chris Lattner24943d22010-06-08 16:52:24 +00001203 return sb_module;
1204}
1205
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001206bool
1207SBTarget::RemoveModule (lldb::SBModule module)
1208{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001209 TargetSP target_sp(GetSP());
1210 if (target_sp)
1211 return target_sp->GetImages().Remove(module.GetSP());
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001212 return false;
1213}
1214
Chris Lattner24943d22010-06-08 16:52:24 +00001215
1216SBBroadcaster
1217SBTarget::GetBroadcaster () const
1218{
Greg Claytone005f2c2010-11-06 01:53:30 +00001219 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001220
Greg Clayton0416bdf2012-01-30 09:04:36 +00001221 TargetSP target_sp(GetSP());
1222 SBBroadcaster broadcaster(target_sp.get(), false);
Caroline Tice7826c882010-10-26 03:11:13 +00001223
1224 if (log)
Greg Clayton3f5ee7f2010-10-29 04:59:35 +00001225 log->Printf ("SBTarget(%p)::GetBroadcaster () => SBBroadcaster(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +00001226 target_sp.get(), broadcaster.get());
Caroline Tice7826c882010-10-26 03:11:13 +00001227
Chris Lattner24943d22010-06-08 16:52:24 +00001228 return broadcaster;
1229}
1230
Caroline Tice98f930f2010-09-20 05:20:02 +00001231
1232bool
Caroline Tice7826c882010-10-26 03:11:13 +00001233SBTarget::GetDescription (SBStream &description, lldb::DescriptionLevel description_level)
Caroline Tice98f930f2010-09-20 05:20:02 +00001234{
Greg Clayton96154be2011-11-13 06:57:31 +00001235 Stream &strm = description.ref();
1236
Greg Clayton0416bdf2012-01-30 09:04:36 +00001237 TargetSP target_sp(GetSP());
1238 if (target_sp)
Caroline Ticee7a566e2010-09-20 16:21:41 +00001239 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001240 target_sp->Dump (&strm, description_level);
Caroline Tice7826c882010-10-26 03:11:13 +00001241 }
1242 else
Greg Clayton96154be2011-11-13 06:57:31 +00001243 strm.PutCString ("No value");
Caroline Tice7826c882010-10-26 03:11:13 +00001244
1245 return true;
1246}
1247
Greg Clayton4ed315f2011-06-21 01:34:41 +00001248uint32_t
1249SBTarget::FindFunctions (const char *name,
1250 uint32_t name_type_mask,
1251 bool append,
1252 lldb::SBSymbolContextList& sc_list)
1253{
1254 if (!append)
1255 sc_list.Clear();
Greg Clayton0416bdf2012-01-30 09:04:36 +00001256 if (name && name[0])
Greg Clayton4ed315f2011-06-21 01:34:41 +00001257 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001258 TargetSP target_sp(GetSP());
1259 if (target_sp)
1260 {
1261 const bool symbols_ok = true;
1262 return target_sp->GetImages().FindFunctions (ConstString(name),
1263 name_type_mask,
1264 symbols_ok,
1265 append,
1266 *sc_list);
1267 }
Greg Clayton4ed315f2011-06-21 01:34:41 +00001268 }
1269 return 0;
1270}
1271
Enrico Granata979e20d2011-07-29 19:53:35 +00001272lldb::SBType
1273SBTarget::FindFirstType (const char* type)
1274{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001275 TargetSP target_sp(GetSP());
1276 if (type && target_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +00001277 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001278 size_t count = target_sp->GetImages().GetSize();
Enrico Granata979e20d2011-07-29 19:53:35 +00001279 for (size_t idx = 0; idx < count; idx++)
1280 {
1281 SBType found_at_idx = GetModuleAtIndex(idx).FindFirstType(type);
1282
1283 if (found_at_idx.IsValid())
1284 return found_at_idx;
1285 }
1286 }
1287 return SBType();
1288}
1289
1290lldb::SBTypeList
1291SBTarget::FindTypes (const char* type)
1292{
1293
1294 SBTypeList retval;
1295
Greg Clayton0416bdf2012-01-30 09:04:36 +00001296 TargetSP target_sp(GetSP());
1297 if (type && target_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +00001298 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001299 ModuleList& images = target_sp->GetImages();
Enrico Granata979e20d2011-07-29 19:53:35 +00001300 ConstString name_const(type);
1301 SymbolContext sc;
1302 TypeList type_list;
1303
1304 uint32_t num_matches = images.FindTypes(sc,
1305 name_const,
1306 true,
1307 UINT32_MAX,
1308 type_list);
1309
1310 for (size_t idx = 0; idx < num_matches; idx++)
1311 {
Greg Clayton0fb0bcc2011-08-03 22:57:10 +00001312 TypeSP type_sp (type_list.GetTypeAtIndex(idx));
1313 if (type_sp)
1314 retval.Append(SBType(type_sp));
Enrico Granata979e20d2011-07-29 19:53:35 +00001315 }
1316 }
1317 return retval;
1318}
1319
Greg Clayton917c0002011-06-29 22:09:02 +00001320SBValueList
1321SBTarget::FindGlobalVariables (const char *name, uint32_t max_matches)
1322{
1323 SBValueList sb_value_list;
1324
Greg Clayton0416bdf2012-01-30 09:04:36 +00001325 TargetSP target_sp(GetSP());
1326 if (name && target_sp)
Greg Clayton917c0002011-06-29 22:09:02 +00001327 {
1328 VariableList variable_list;
1329 const bool append = true;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001330 const uint32_t match_count = target_sp->GetImages().FindGlobalVariables (ConstString (name),
1331 append,
1332 max_matches,
1333 variable_list);
Greg Clayton917c0002011-06-29 22:09:02 +00001334
1335 if (match_count > 0)
1336 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001337 ExecutionContextScope *exe_scope = target_sp->GetProcessSP().get();
Greg Clayton917c0002011-06-29 22:09:02 +00001338 if (exe_scope == NULL)
Greg Clayton0416bdf2012-01-30 09:04:36 +00001339 exe_scope = target_sp.get();
Greg Clayton917c0002011-06-29 22:09:02 +00001340 ValueObjectList &value_object_list = sb_value_list.ref();
1341 for (uint32_t i=0; i<match_count; ++i)
1342 {
1343 lldb::ValueObjectSP valobj_sp (ValueObjectVariable::Create (exe_scope, variable_list.GetVariableAtIndex(i)));
1344 if (valobj_sp)
1345 value_object_list.Append(valobj_sp);
1346 }
1347 }
1348 }
1349
1350 return sb_value_list;
1351}
1352
Jim Inghamcc637462011-09-13 00:29:56 +00001353SBSourceManager
1354SBTarget::GetSourceManager()
1355{
1356 SBSourceManager source_manager (*this);
1357 return source_manager;
1358}
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001359
Sean Callananef1f6902011-12-14 23:49:37 +00001360lldb::SBInstructionList
1361SBTarget::GetInstructions (lldb::SBAddress base_addr, const void *buf, size_t size)
1362{
1363 SBInstructionList sb_instructions;
1364
Greg Clayton0416bdf2012-01-30 09:04:36 +00001365 TargetSP target_sp(GetSP());
1366 if (target_sp)
Sean Callananef1f6902011-12-14 23:49:37 +00001367 {
1368 Address addr;
1369
1370 if (base_addr.get())
1371 addr = *base_addr.get();
1372
Greg Clayton0416bdf2012-01-30 09:04:36 +00001373 sb_instructions.SetDisassembler (Disassembler::DisassembleBytes (target_sp->GetArchitecture(),
Sean Callananef1f6902011-12-14 23:49:37 +00001374 NULL,
1375 addr,
1376 buf,
1377 size));
1378 }
1379
1380 return sb_instructions;
1381}
1382
1383lldb::SBInstructionList
1384SBTarget::GetInstructions (lldb::addr_t base_addr, const void *buf, size_t size)
1385{
1386 return GetInstructions (ResolveLoadAddress(base_addr), buf, size);
1387}
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001388
1389SBError
1390SBTarget::SetSectionLoadAddress (lldb::SBSection section,
1391 lldb::addr_t section_base_addr)
1392{
1393 SBError sb_error;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001394 TargetSP target_sp(GetSP());
1395 if (target_sp)
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001396 {
1397 if (!section.IsValid())
1398 {
1399 sb_error.SetErrorStringWithFormat ("invalid section");
1400 }
1401 else
1402 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001403 target_sp->GetSectionLoadList().SetSectionLoadAddress (section.GetSection(), section_base_addr);
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001404 }
1405 }
1406 else
1407 {
1408 sb_error.SetErrorStringWithFormat ("invalid target");
1409 }
1410 return sb_error;
1411}
1412
1413SBError
1414SBTarget::ClearSectionLoadAddress (lldb::SBSection section)
1415{
1416 SBError sb_error;
1417
Greg Clayton0416bdf2012-01-30 09:04:36 +00001418 TargetSP target_sp(GetSP());
1419 if (target_sp)
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001420 {
1421 if (!section.IsValid())
1422 {
1423 sb_error.SetErrorStringWithFormat ("invalid section");
1424 }
1425 else
1426 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001427 target_sp->GetSectionLoadList().SetSectionUnloaded (section.GetSection());
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001428 }
1429 }
1430 else
1431 {
1432 sb_error.SetErrorStringWithFormat ("invalid target");
1433 }
1434 return sb_error;
1435}
1436
1437SBError
1438SBTarget::SetModuleLoadAddress (lldb::SBModule module, int64_t slide_offset)
1439{
1440 SBError sb_error;
1441
1442 char path[PATH_MAX];
Greg Clayton0416bdf2012-01-30 09:04:36 +00001443 TargetSP target_sp(GetSP());
1444 if (target_sp)
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001445 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001446 ModuleSP module_sp (module.GetSP());
1447 if (module_sp)
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001448 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001449 ObjectFile *objfile = module_sp->GetObjectFile();
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001450 if (objfile)
1451 {
1452 SectionList *section_list = objfile->GetSectionList();
1453 if (section_list)
1454 {
1455 const size_t num_sections = section_list->GetSize();
1456 for (size_t sect_idx = 0; sect_idx < num_sections; ++sect_idx)
1457 {
1458 SectionSP section_sp (section_list->GetSectionAtIndex(sect_idx));
1459 if (section_sp)
Greg Clayton0416bdf2012-01-30 09:04:36 +00001460 target_sp->GetSectionLoadList().SetSectionLoadAddress (section_sp.get(), section_sp->GetFileAddress() + slide_offset);
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001461 }
1462 }
1463 else
1464 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001465 module_sp->GetFileSpec().GetPath (path, sizeof(path));
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001466 sb_error.SetErrorStringWithFormat ("no sections in object file '%s'", path);
1467 }
1468 }
1469 else
1470 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001471 module_sp->GetFileSpec().GetPath (path, sizeof(path));
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001472 sb_error.SetErrorStringWithFormat ("no object file for module '%s'", path);
1473 }
1474 }
Greg Clayton0416bdf2012-01-30 09:04:36 +00001475 else
1476 {
1477 sb_error.SetErrorStringWithFormat ("invalid module");
1478 }
1479
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001480 }
1481 else
1482 {
1483 sb_error.SetErrorStringWithFormat ("invalid target");
1484 }
1485 return sb_error;
1486}
1487
1488SBError
1489SBTarget::ClearModuleLoadAddress (lldb::SBModule module)
1490{
1491 SBError sb_error;
1492
1493 char path[PATH_MAX];
Greg Clayton0416bdf2012-01-30 09:04:36 +00001494 TargetSP target_sp(GetSP());
1495 if (target_sp)
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001496 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001497 ModuleSP module_sp (module.GetSP());
1498 if (module_sp)
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001499 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001500 ObjectFile *objfile = module_sp->GetObjectFile();
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001501 if (objfile)
1502 {
1503 SectionList *section_list = objfile->GetSectionList();
1504 if (section_list)
1505 {
1506 const size_t num_sections = section_list->GetSize();
1507 for (size_t sect_idx = 0; sect_idx < num_sections; ++sect_idx)
1508 {
1509 SectionSP section_sp (section_list->GetSectionAtIndex(sect_idx));
1510 if (section_sp)
Greg Clayton0416bdf2012-01-30 09:04:36 +00001511 target_sp->GetSectionLoadList().SetSectionUnloaded (section_sp.get());
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001512 }
1513 }
1514 else
1515 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001516 module_sp->GetFileSpec().GetPath (path, sizeof(path));
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001517 sb_error.SetErrorStringWithFormat ("no sections in object file '%s'", path);
1518 }
1519 }
1520 else
1521 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001522 module_sp->GetFileSpec().GetPath (path, sizeof(path));
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001523 sb_error.SetErrorStringWithFormat ("no object file for module '%s'", path);
1524 }
1525 }
Greg Clayton0416bdf2012-01-30 09:04:36 +00001526 else
1527 {
1528 sb_error.SetErrorStringWithFormat ("invalid module");
1529 }
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001530 }
1531 else
1532 {
1533 sb_error.SetErrorStringWithFormat ("invalid target");
1534 }
1535 return sb_error;
1536}
1537
1538