blob: 8ed525e3d4df2761199cd215938f510d86a4706d [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
14#include "lldb/API/SBFileSpec.h"
15#include "lldb/API/SBModule.h"
Caroline Tice98f930f2010-09-20 05:20:02 +000016#include "lldb/API/SBStream.h"
Greg Clayton4ed315f2011-06-21 01:34:41 +000017#include "lldb/API/SBSymbolContextList.h"
Chris Lattner24943d22010-06-08 16:52:24 +000018#include "lldb/Breakpoint/BreakpointID.h"
19#include "lldb/Breakpoint/BreakpointIDList.h"
20#include "lldb/Breakpoint/BreakpointList.h"
21#include "lldb/Breakpoint/BreakpointLocation.h"
22#include "lldb/Core/Address.h"
23#include "lldb/Core/AddressResolver.h"
24#include "lldb/Core/AddressResolverName.h"
Jim Ingham84cdc152010-06-15 19:49:27 +000025#include "lldb/Interpreter/Args.h"
Chris Lattner24943d22010-06-08 16:52:24 +000026#include "lldb/Core/ArchSpec.h"
27#include "lldb/Core/Debugger.h"
28#include "lldb/Core/Disassembler.h"
Greg Clayton5f54ac32011-02-08 05:05:52 +000029#include "lldb/Host/FileSpec.h"
Caroline Tice7826c882010-10-26 03:11:13 +000030#include "lldb/Core/Log.h"
Chris Lattner24943d22010-06-08 16:52:24 +000031#include "lldb/Core/RegularExpression.h"
32#include "lldb/Core/SearchFilter.h"
33#include "lldb/Core/STLUtils.h"
Greg Claytoncd548032011-02-01 01:31:41 +000034#include "lldb/Host/Host.h"
Chris Lattner24943d22010-06-08 16:52:24 +000035#include "lldb/Target/Process.h"
36#include "lldb/Target/Target.h"
37#include "lldb/Target/TargetList.h"
38
39#include "lldb/Interpreter/CommandReturnObject.h"
40#include "../source/Commands/CommandObjectBreakpoint.h"
41
Eli Friedman7a62c8b2010-06-09 07:44:37 +000042#include "lldb/API/SBDebugger.h"
43#include "lldb/API/SBProcess.h"
44#include "lldb/API/SBListener.h"
45#include "lldb/API/SBBreakpoint.h"
Chris Lattner24943d22010-06-08 16:52:24 +000046
47using namespace lldb;
48using namespace lldb_private;
49
50#define DEFAULT_DISASM_BYTE_SIZE 32
51
52//----------------------------------------------------------------------
53// SBTarget constructor
54//----------------------------------------------------------------------
Greg Claytonc3b61d22010-12-15 05:08:08 +000055SBTarget::SBTarget () :
56 m_opaque_sp ()
Chris Lattner24943d22010-06-08 16:52:24 +000057{
58}
59
60SBTarget::SBTarget (const SBTarget& rhs) :
Greg Clayton63094e02010-06-23 01:19:29 +000061 m_opaque_sp (rhs.m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +000062{
63}
64
65SBTarget::SBTarget(const TargetSP& target_sp) :
Greg Clayton63094e02010-06-23 01:19:29 +000066 m_opaque_sp (target_sp)
Chris Lattner24943d22010-06-08 16:52:24 +000067{
68}
69
Greg Clayton538eb822010-11-05 23:17:00 +000070const SBTarget&
71SBTarget::operator = (const SBTarget& rhs)
72{
73 if (this != &rhs)
74 m_opaque_sp = rhs.m_opaque_sp;
75 return *this;
76}
77
Chris Lattner24943d22010-06-08 16:52:24 +000078//----------------------------------------------------------------------
79// Destructor
80//----------------------------------------------------------------------
81SBTarget::~SBTarget()
82{
83}
84
85bool
86SBTarget::IsValid () const
87{
Greg Clayton63094e02010-06-23 01:19:29 +000088 return m_opaque_sp.get() != NULL;
Chris Lattner24943d22010-06-08 16:52:24 +000089}
90
91SBProcess
92SBTarget::GetProcess ()
93{
Caroline Tice7826c882010-10-26 03:11:13 +000094
Chris Lattner24943d22010-06-08 16:52:24 +000095 SBProcess sb_process;
Greg Clayton63094e02010-06-23 01:19:29 +000096 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +000097 {
98 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
Greg Clayton63094e02010-06-23 01:19:29 +000099 sb_process.SetProcess (m_opaque_sp->GetProcessSP());
Greg Claytonbdcda462010-12-20 20:49:23 +0000100 }
Caroline Tice7826c882010-10-26 03:11:13 +0000101
Greg Claytone005f2c2010-11-06 01:53:30 +0000102 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000103 if (log)
104 {
Greg Clayton49ce6822010-10-31 03:01:06 +0000105 log->Printf ("SBTarget(%p)::GetProcess () => SBProcess(%p)",
106 m_opaque_sp.get(), sb_process.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000107 }
108
Chris Lattner24943d22010-06-08 16:52:24 +0000109 return sb_process;
110}
111
Greg Clayton63094e02010-06-23 01:19:29 +0000112SBDebugger
113SBTarget::GetDebugger () const
114{
115 SBDebugger debugger;
116 if (m_opaque_sp)
117 debugger.reset (m_opaque_sp->GetDebugger().GetSP());
118 return debugger;
119}
120
Jim Inghamb5871fe2011-03-31 00:01:24 +0000121SBProcess
122SBTarget::LaunchSimple
123(
124 char const **argv,
125 char const **envp,
126 const char *working_directory
127)
128{
129 char *stdin_path = NULL;
130 char *stdout_path = NULL;
131 char *stderr_path = NULL;
132 uint32_t launch_flags = 0;
133 bool stop_at_entry = false;
134 SBError error;
135 SBListener listener = GetDebugger().GetListener();
136 return Launch (listener,
137 argv,
138 envp,
139 stdin_path,
140 stdout_path,
141 stderr_path,
142 working_directory,
143 launch_flags,
144 stop_at_entry,
145 error);
146}
Greg Claytonde915be2011-01-23 05:56:20 +0000147
148SBProcess
149SBTarget::Launch
150(
Greg Clayton271a5db2011-02-03 21:28:34 +0000151 SBListener &listener,
Greg Claytonde915be2011-01-23 05:56:20 +0000152 char const **argv,
153 char const **envp,
154 const char *stdin_path,
155 const char *stdout_path,
156 const char *stderr_path,
157 const char *working_directory,
158 uint32_t launch_flags, // See LaunchFlags
159 bool stop_at_entry,
160 lldb::SBError& error
161)
162{
Greg Claytone005f2c2010-11-06 01:53:30 +0000163 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000164
165 if (log)
Greg Clayton3f5ee7f2010-10-29 04:59:35 +0000166 {
Greg Claytonde915be2011-01-23 05:56:20 +0000167 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))...",
168 m_opaque_sp.get(),
169 argv,
170 envp,
171 stdin_path ? stdin_path : "NULL",
172 stdout_path ? stdout_path : "NULL",
173 stderr_path ? stderr_path : "NULL",
174 working_directory ? working_directory : "NULL",
175 launch_flags,
176 stop_at_entry,
177 error.get());
Greg Clayton3f5ee7f2010-10-29 04:59:35 +0000178 }
Greg Clayton1a3083a2010-10-06 03:53:16 +0000179 SBProcess sb_process;
180 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000181 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000182 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
Greg Clayton1a3083a2010-10-06 03:53:16 +0000183
Greg Clayton7c330d62011-01-27 01:01:10 +0000184 if (getenv("LLDB_LAUNCH_FLAG_DISABLE_ASLR"))
185 launch_flags |= eLaunchFlagDisableASLR;
186
Greg Clayton180546b2011-04-30 01:09:13 +0000187 StateType state = eStateInvalid;
188 sb_process.SetProcess (m_opaque_sp->GetProcessSP());
189 if (sb_process.IsValid())
Greg Clayton28d5fcc2011-01-27 06:44:37 +0000190 {
Greg Clayton180546b2011-04-30 01:09:13 +0000191 state = sb_process->GetState();
192
193 if (sb_process->IsAlive() && state != eStateConnected)
194 {
195 if (state == eStateAttaching)
196 error.SetErrorString ("process attach is in progress");
197 else
198 error.SetErrorString ("a process is already being debugged");
199 sb_process.Clear();
200 return sb_process;
201 }
Greg Clayton28d5fcc2011-01-27 06:44:37 +0000202 }
203
Greg Clayton180546b2011-04-30 01:09:13 +0000204 if (state == eStateConnected)
205 {
206 // If we are already connected, then we have already specified the
207 // listener, so if a valid listener is supplied, we need to error out
208 // to let the client know.
209 if (listener.IsValid())
210 {
211 error.SetErrorString ("process is connected and already has a listener, pass empty listener");
212 sb_process.Clear();
213 return sb_process;
214 }
215 }
216 else
Greg Claytonc5f728c2010-10-06 22:10:17 +0000217 {
Greg Clayton271a5db2011-02-03 21:28:34 +0000218 if (listener.IsValid())
219 sb_process.SetProcess (m_opaque_sp->CreateProcess (listener.ref()));
220 else
221 sb_process.SetProcess (m_opaque_sp->CreateProcess (m_opaque_sp->GetDebugger().GetListener()));
Greg Clayton180546b2011-04-30 01:09:13 +0000222 }
Greg Clayton7c330d62011-01-27 01:01:10 +0000223
Greg Clayton180546b2011-04-30 01:09:13 +0000224 if (sb_process.IsValid())
225 {
226 if (getenv("LLDB_LAUNCH_FLAG_DISABLE_STDIO"))
227 launch_flags |= eLaunchFlagDisableSTDIO;
228
229 error.SetError (sb_process->Launch (argv, envp, launch_flags, stdin_path, stdout_path, stderr_path, working_directory));
230 if (error.Success())
Greg Clayton7c330d62011-01-27 01:01:10 +0000231 {
Greg Clayton180546b2011-04-30 01:09:13 +0000232 // We we are stopping at the entry point, we can return now!
233 if (stop_at_entry)
234 return sb_process;
Greg Clayton7c330d62011-01-27 01:01:10 +0000235
Greg Clayton180546b2011-04-30 01:09:13 +0000236 // Make sure we are stopped at the entry
237 StateType state = sb_process->WaitForProcessToStop (NULL);
238 if (state == eStateStopped)
Greg Clayton7c330d62011-01-27 01:01:10 +0000239 {
Greg Clayton180546b2011-04-30 01:09:13 +0000240 // resume the process to skip the entry point
241 error.SetError (sb_process->Resume());
242 if (error.Success())
Greg Clayton7c330d62011-01-27 01:01:10 +0000243 {
Greg Clayton180546b2011-04-30 01:09:13 +0000244 // If we are doing synchronous mode, then wait for the
245 // process to stop yet again!
246 if (m_opaque_sp->GetDebugger().GetAsyncExecution () == false)
247 sb_process->WaitForProcessToStop (NULL);
Greg Clayton7c330d62011-01-27 01:01:10 +0000248 }
249 }
250 }
Greg Clayton180546b2011-04-30 01:09:13 +0000251 }
252 else
253 {
254 error.SetErrorString ("unable to create lldb_private::Process");
Greg Claytonc5f728c2010-10-06 22:10:17 +0000255 }
256 }
257 else
258 {
259 error.SetErrorString ("SBTarget is invalid");
Chris Lattner24943d22010-06-08 16:52:24 +0000260 }
Caroline Tice7826c882010-10-26 03:11:13 +0000261
Caroline Tice926060e2010-10-29 21:48:37 +0000262 log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
Caroline Tice7826c882010-10-26 03:11:13 +0000263 if (log)
264 {
Greg Clayton49ce6822010-10-31 03:01:06 +0000265 log->Printf ("SBTarget(%p)::Launch (...) => SBProceess(%p)",
266 m_opaque_sp.get(), sb_process.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000267 }
268
Greg Clayton1a3083a2010-10-06 03:53:16 +0000269 return sb_process;
Chris Lattner24943d22010-06-08 16:52:24 +0000270}
271
Greg Claytonc5f728c2010-10-06 22:10:17 +0000272
273lldb::SBProcess
Greg Claytond8c62532010-10-07 04:19:01 +0000274SBTarget::AttachToProcessWithID
Greg Claytonc5f728c2010-10-06 22:10:17 +0000275(
Greg Clayton271a5db2011-02-03 21:28:34 +0000276 SBListener &listener,
Greg Claytonc5f728c2010-10-06 22:10:17 +0000277 lldb::pid_t pid,// The process ID to attach to
278 SBError& error // An error explaining what went wrong if attach fails
279)
280{
281 SBProcess sb_process;
282 if (m_opaque_sp)
283 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000284 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
Greg Clayton271a5db2011-02-03 21:28:34 +0000285 if (listener.IsValid())
286 sb_process.SetProcess (m_opaque_sp->CreateProcess (listener.ref()));
287 else
288 sb_process.SetProcess (m_opaque_sp->CreateProcess (m_opaque_sp->GetDebugger().GetListener()));
289
Greg Claytonc5f728c2010-10-06 22:10:17 +0000290
291 if (sb_process.IsValid())
292 {
293 error.SetError (sb_process->Attach (pid));
Johnny Chen535960e2011-06-17 00:51:15 +0000294 // If we are doing synchronous mode, then wait for the
295 // process to stop!
296 if (m_opaque_sp->GetDebugger().GetAsyncExecution () == false)
297 sb_process->WaitForProcessToStop (NULL);
Greg Claytonc5f728c2010-10-06 22:10:17 +0000298 }
299 else
300 {
301 error.SetErrorString ("unable to create lldb_private::Process");
302 }
303 }
304 else
305 {
306 error.SetErrorString ("SBTarget is invalid");
307 }
308 return sb_process;
309
310}
311
312lldb::SBProcess
Greg Claytond8c62532010-10-07 04:19:01 +0000313SBTarget::AttachToProcessWithName
Greg Claytonc5f728c2010-10-06 22:10:17 +0000314(
Greg Clayton271a5db2011-02-03 21:28:34 +0000315 SBListener &listener,
Greg Claytonc5f728c2010-10-06 22:10:17 +0000316 const char *name, // basename of process to attach to
317 bool wait_for, // if true wait for a new instance of "name" to be launched
318 SBError& error // An error explaining what went wrong if attach fails
319)
320{
321 SBProcess sb_process;
322 if (m_opaque_sp)
323 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000324 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
325
Greg Clayton271a5db2011-02-03 21:28:34 +0000326 if (listener.IsValid())
327 sb_process.SetProcess (m_opaque_sp->CreateProcess (listener.ref()));
328 else
329 sb_process.SetProcess (m_opaque_sp->CreateProcess (m_opaque_sp->GetDebugger().GetListener()));
Greg Claytonc5f728c2010-10-06 22:10:17 +0000330
331 if (sb_process.IsValid())
332 {
333 error.SetError (sb_process->Attach (name, wait_for));
Johnny Chen58d02ff2011-06-17 19:21:30 +0000334 // If we are doing synchronous mode, then wait for the
335 // process to stop!
336 if (m_opaque_sp->GetDebugger().GetAsyncExecution () == false)
337 sb_process->WaitForProcessToStop (NULL);
Greg Claytonc5f728c2010-10-06 22:10:17 +0000338 }
339 else
340 {
341 error.SetErrorString ("unable to create lldb_private::Process");
342 }
343 }
344 else
345 {
346 error.SetErrorString ("SBTarget is invalid");
347 }
348 return sb_process;
349
350}
351
James McIlree38093402011-03-04 00:31:13 +0000352lldb::SBProcess
353SBTarget::ConnectRemote
354(
355 SBListener &listener,
356 const char *url,
357 const char *plugin_name,
358 SBError& error
359)
360{
361 SBProcess sb_process;
362 if (m_opaque_sp)
363 {
364 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
365 if (listener.IsValid())
366 sb_process.SetProcess (m_opaque_sp->CreateProcess (listener.ref(), plugin_name));
367 else
368 sb_process.SetProcess (m_opaque_sp->CreateProcess (m_opaque_sp->GetDebugger().GetListener(), plugin_name));
369
370
371 if (sb_process.IsValid())
372 {
373 error.SetError (sb_process->ConnectRemote (url));
374 }
375 else
376 {
377 error.SetErrorString ("unable to create lldb_private::Process");
378 }
379 }
380 else
381 {
382 error.SetErrorString ("SBTarget is invalid");
383 }
384 return sb_process;
385}
386
Chris Lattner24943d22010-06-08 16:52:24 +0000387SBFileSpec
388SBTarget::GetExecutable ()
389{
Caroline Tice7826c882010-10-26 03:11:13 +0000390
Chris Lattner24943d22010-06-08 16:52:24 +0000391 SBFileSpec exe_file_spec;
Greg Clayton63094e02010-06-23 01:19:29 +0000392 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000393 {
Greg Clayton63094e02010-06-23 01:19:29 +0000394 ModuleSP exe_module_sp (m_opaque_sp->GetExecutableModule ());
Chris Lattner24943d22010-06-08 16:52:24 +0000395 if (exe_module_sp)
396 exe_file_spec.SetFileSpec (exe_module_sp->GetFileSpec());
397 }
Caroline Tice7826c882010-10-26 03:11:13 +0000398
Greg Claytone005f2c2010-11-06 01:53:30 +0000399 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000400 if (log)
401 {
Greg Clayton49ce6822010-10-31 03:01:06 +0000402 log->Printf ("SBTarget(%p)::GetExecutable () => SBFileSpec(%p)",
403 m_opaque_sp.get(), exe_file_spec.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000404 }
405
Chris Lattner24943d22010-06-08 16:52:24 +0000406 return exe_file_spec;
407}
408
Chris Lattner24943d22010-06-08 16:52:24 +0000409bool
Chris Lattner24943d22010-06-08 16:52:24 +0000410SBTarget::operator == (const SBTarget &rhs) const
411{
Greg Clayton63094e02010-06-23 01:19:29 +0000412 return m_opaque_sp.get() == rhs.m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000413}
414
415bool
416SBTarget::operator != (const SBTarget &rhs) const
417{
Greg Clayton63094e02010-06-23 01:19:29 +0000418 return m_opaque_sp.get() != rhs.m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000419}
420
421lldb_private::Target *
Greg Clayton63094e02010-06-23 01:19:29 +0000422SBTarget::operator ->() const
Chris Lattner24943d22010-06-08 16:52:24 +0000423{
Greg Clayton63094e02010-06-23 01:19:29 +0000424 return m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000425}
Greg Clayton63094e02010-06-23 01:19:29 +0000426
427lldb_private::Target *
428SBTarget::get() const
Chris Lattner24943d22010-06-08 16:52:24 +0000429{
Greg Clayton63094e02010-06-23 01:19:29 +0000430 return m_opaque_sp.get();
431}
432
433void
434SBTarget::reset (const lldb::TargetSP& target_sp)
435{
436 m_opaque_sp = target_sp;
Chris Lattner24943d22010-06-08 16:52:24 +0000437}
438
Greg Claytonea49cc72010-12-12 19:25:26 +0000439bool
440SBTarget::ResolveLoadAddress (lldb::addr_t vm_addr,
441 lldb::SBAddress& addr)
442{
443 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000444 {
445 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
Greg Claytonea49cc72010-12-12 19:25:26 +0000446 return m_opaque_sp->GetSectionLoadList().ResolveLoadAddress (vm_addr, *addr);
Greg Claytonbdcda462010-12-20 20:49:23 +0000447 }
Greg Claytonea49cc72010-12-12 19:25:26 +0000448
449 addr->Clear();
450 return false;
451}
452
Greg Claytonafb81862011-03-02 21:34:46 +0000453SBSymbolContext
454SBTarget::ResolveSymbolContextForAddress (const SBAddress& addr, uint32_t resolve_scope)
455{
456 SBSymbolContext sc;
457 if (m_opaque_sp)
458 m_opaque_sp->GetImages().ResolveSymbolContextForAddress (*addr, resolve_scope, sc.ref());
459 return sc;
460}
461
462
Chris Lattner24943d22010-06-08 16:52:24 +0000463SBBreakpoint
464SBTarget::BreakpointCreateByLocation (const char *file, uint32_t line)
465{
Greg Claytond6d806c2010-11-08 00:28:40 +0000466 return SBBreakpoint(BreakpointCreateByLocation (SBFileSpec (file, false), line));
Chris Lattner24943d22010-06-08 16:52:24 +0000467}
468
469SBBreakpoint
470SBTarget::BreakpointCreateByLocation (const SBFileSpec &sb_file_spec, uint32_t line)
471{
Greg Claytone005f2c2010-11-06 01:53:30 +0000472 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000473
Chris Lattner24943d22010-06-08 16:52:24 +0000474 SBBreakpoint sb_bp;
Greg Clayton63094e02010-06-23 01:19:29 +0000475 if (m_opaque_sp.get() && line != 0)
Greg Claytonbdcda462010-12-20 20:49:23 +0000476 {
477 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
Greg Clayton63094e02010-06-23 01:19:29 +0000478 *sb_bp = m_opaque_sp->CreateBreakpoint (NULL, *sb_file_spec, line, true, false);
Greg Claytonbdcda462010-12-20 20:49:23 +0000479 }
Caroline Tice7826c882010-10-26 03:11:13 +0000480
481 if (log)
482 {
483 SBStream sstr;
484 sb_bp.GetDescription (sstr);
Greg Clayton49ce6822010-10-31 03:01:06 +0000485 char path[PATH_MAX];
486 sb_file_spec->GetPath (path, sizeof(path));
487 log->Printf ("SBTarget(%p)::BreakpointCreateByLocation ( %s:%u ) => SBBreakpoint(%p): %s",
Greg Claytona66ba462010-10-30 04:51:46 +0000488 m_opaque_sp.get(),
Greg Clayton49ce6822010-10-31 03:01:06 +0000489 path,
Greg Claytona66ba462010-10-30 04:51:46 +0000490 line,
Greg Clayton49ce6822010-10-31 03:01:06 +0000491 sb_bp.get(),
Caroline Tice7826c882010-10-26 03:11:13 +0000492 sstr.GetData());
493 }
494
Chris Lattner24943d22010-06-08 16:52:24 +0000495 return sb_bp;
496}
497
498SBBreakpoint
499SBTarget::BreakpointCreateByName (const char *symbol_name, const char *module_name)
500{
Greg Claytone005f2c2010-11-06 01:53:30 +0000501 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000502
Chris Lattner24943d22010-06-08 16:52:24 +0000503 SBBreakpoint sb_bp;
Greg Clayton63094e02010-06-23 01:19:29 +0000504 if (m_opaque_sp.get() && symbol_name && symbol_name[0])
Chris Lattner24943d22010-06-08 16:52:24 +0000505 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000506 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
Chris Lattner24943d22010-06-08 16:52:24 +0000507 if (module_name && module_name[0])
508 {
Greg Clayton537a7a82010-10-20 20:54:39 +0000509 FileSpec module_file_spec(module_name, false);
Jim Ingham7ec03bd2010-09-30 21:21:43 +0000510 *sb_bp = m_opaque_sp->CreateBreakpoint (&module_file_spec, symbol_name, eFunctionNameTypeFull | eFunctionNameTypeBase, false);
Chris Lattner24943d22010-06-08 16:52:24 +0000511 }
512 else
513 {
Jim Ingham7ec03bd2010-09-30 21:21:43 +0000514 *sb_bp = m_opaque_sp->CreateBreakpoint (NULL, symbol_name, eFunctionNameTypeFull | eFunctionNameTypeBase, false);
Chris Lattner24943d22010-06-08 16:52:24 +0000515 }
516 }
Caroline Tice7826c882010-10-26 03:11:13 +0000517
518 if (log)
519 {
Greg Clayton49ce6822010-10-31 03:01:06 +0000520 log->Printf ("SBTarget(%p)::BreakpointCreateByName (symbol=\"%s\", module=\"%s\") => SBBreakpoint(%p)",
521 m_opaque_sp.get(), symbol_name, module_name, sb_bp.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000522 }
523
Chris Lattner24943d22010-06-08 16:52:24 +0000524 return sb_bp;
525}
526
527SBBreakpoint
528SBTarget::BreakpointCreateByRegex (const char *symbol_name_regex, const char *module_name)
529{
Greg Claytone005f2c2010-11-06 01:53:30 +0000530 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000531
Chris Lattner24943d22010-06-08 16:52:24 +0000532 SBBreakpoint sb_bp;
Greg Clayton63094e02010-06-23 01:19:29 +0000533 if (m_opaque_sp.get() && symbol_name_regex && symbol_name_regex[0])
Chris Lattner24943d22010-06-08 16:52:24 +0000534 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000535 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
Chris Lattner24943d22010-06-08 16:52:24 +0000536 RegularExpression regexp(symbol_name_regex);
537
538 if (module_name && module_name[0])
539 {
Greg Clayton537a7a82010-10-20 20:54:39 +0000540 FileSpec module_file_spec(module_name, false);
Chris Lattner24943d22010-06-08 16:52:24 +0000541
Greg Clayton63094e02010-06-23 01:19:29 +0000542 *sb_bp = m_opaque_sp->CreateBreakpoint (&module_file_spec, regexp, false);
Chris Lattner24943d22010-06-08 16:52:24 +0000543 }
544 else
545 {
Greg Clayton63094e02010-06-23 01:19:29 +0000546 *sb_bp = m_opaque_sp->CreateBreakpoint (NULL, regexp, false);
Chris Lattner24943d22010-06-08 16:52:24 +0000547 }
548 }
Caroline Tice7826c882010-10-26 03:11:13 +0000549
550 if (log)
551 {
Greg Clayton49ce6822010-10-31 03:01:06 +0000552 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (symbol_regex=\"%s\", module_name=\"%s\") => SBBreakpoint(%p)",
553 m_opaque_sp.get(), symbol_name_regex, module_name, sb_bp.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000554 }
555
Chris Lattner24943d22010-06-08 16:52:24 +0000556 return sb_bp;
557}
558
559
560
561SBBreakpoint
562SBTarget::BreakpointCreateByAddress (addr_t address)
563{
Greg Claytone005f2c2010-11-06 01:53:30 +0000564 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000565
Chris Lattner24943d22010-06-08 16:52:24 +0000566 SBBreakpoint sb_bp;
Greg Clayton63094e02010-06-23 01:19:29 +0000567 if (m_opaque_sp.get())
Greg Claytonbdcda462010-12-20 20:49:23 +0000568 {
569 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
Greg Clayton63094e02010-06-23 01:19:29 +0000570 *sb_bp = m_opaque_sp->CreateBreakpoint (address, false);
Greg Claytonbdcda462010-12-20 20:49:23 +0000571 }
Caroline Tice7826c882010-10-26 03:11:13 +0000572
573 if (log)
574 {
Greg Clayton49ce6822010-10-31 03:01:06 +0000575 log->Printf ("SBTarget(%p)::BreakpointCreateByAddress (%p, address=%p) => SBBreakpoint(%p)", m_opaque_sp.get(), address, sb_bp.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000576 }
577
Chris Lattner24943d22010-06-08 16:52:24 +0000578 return sb_bp;
579}
580
Chris Lattner24943d22010-06-08 16:52:24 +0000581SBBreakpoint
582SBTarget::FindBreakpointByID (break_id_t bp_id)
583{
Greg Claytone005f2c2010-11-06 01:53:30 +0000584 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000585
Chris Lattner24943d22010-06-08 16:52:24 +0000586 SBBreakpoint sb_breakpoint;
Greg Clayton63094e02010-06-23 01:19:29 +0000587 if (m_opaque_sp && bp_id != LLDB_INVALID_BREAK_ID)
Greg Claytonbdcda462010-12-20 20:49:23 +0000588 {
589 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
Greg Clayton63094e02010-06-23 01:19:29 +0000590 *sb_breakpoint = m_opaque_sp->GetBreakpointByID (bp_id);
Greg Claytonbdcda462010-12-20 20:49:23 +0000591 }
Caroline Tice7826c882010-10-26 03:11:13 +0000592
593 if (log)
594 {
Greg Clayton49ce6822010-10-31 03:01:06 +0000595 log->Printf ("SBTarget(%p)::FindBreakpointByID (bp_id=%d) => SBBreakpoint(%p)",
596 m_opaque_sp.get(), (uint32_t) bp_id, sb_breakpoint.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000597 }
598
Chris Lattner24943d22010-06-08 16:52:24 +0000599 return sb_breakpoint;
600}
601
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000602uint32_t
603SBTarget::GetNumBreakpoints () const
604{
605 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000606 {
607 // The breakpoint list is thread safe, no need to lock
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000608 return m_opaque_sp->GetBreakpointList().GetSize();
Greg Claytonbdcda462010-12-20 20:49:23 +0000609 }
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000610 return 0;
611}
612
613SBBreakpoint
614SBTarget::GetBreakpointAtIndex (uint32_t idx) const
615{
616 SBBreakpoint sb_breakpoint;
617 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000618 {
619 // The breakpoint list is thread safe, no need to lock
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000620 *sb_breakpoint = m_opaque_sp->GetBreakpointList().GetBreakpointAtIndex(idx);
Greg Claytonbdcda462010-12-20 20:49:23 +0000621 }
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000622 return sb_breakpoint;
623}
Chris Lattner24943d22010-06-08 16:52:24 +0000624
625bool
626SBTarget::BreakpointDelete (break_id_t bp_id)
627{
Greg Claytone005f2c2010-11-06 01:53:30 +0000628 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000629
Caroline Tice7826c882010-10-26 03:11:13 +0000630 bool result = false;
Greg Clayton63094e02010-06-23 01:19:29 +0000631 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000632 {
633 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
Caroline Tice7826c882010-10-26 03:11:13 +0000634 result = m_opaque_sp->RemoveBreakpointByID (bp_id);
Greg Claytonbdcda462010-12-20 20:49:23 +0000635 }
Caroline Tice7826c882010-10-26 03:11:13 +0000636
637 if (log)
638 {
Greg Clayton3f5ee7f2010-10-29 04:59:35 +0000639 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 +0000640 }
641
642 return result;
Chris Lattner24943d22010-06-08 16:52:24 +0000643}
644
645bool
646SBTarget::EnableAllBreakpoints ()
647{
Greg Clayton63094e02010-06-23 01:19:29 +0000648 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000649 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000650 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
Greg Clayton63094e02010-06-23 01:19:29 +0000651 m_opaque_sp->EnableAllBreakpoints ();
Chris Lattner24943d22010-06-08 16:52:24 +0000652 return true;
653 }
654 return false;
655}
656
657bool
658SBTarget::DisableAllBreakpoints ()
659{
Greg Clayton63094e02010-06-23 01:19:29 +0000660 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000661 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000662 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
Greg Clayton63094e02010-06-23 01:19:29 +0000663 m_opaque_sp->DisableAllBreakpoints ();
Chris Lattner24943d22010-06-08 16:52:24 +0000664 return true;
665 }
666 return false;
667}
668
669bool
670SBTarget::DeleteAllBreakpoints ()
671{
Greg Clayton63094e02010-06-23 01:19:29 +0000672 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000673 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000674 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
Greg Clayton63094e02010-06-23 01:19:29 +0000675 m_opaque_sp->RemoveAllBreakpoints ();
Chris Lattner24943d22010-06-08 16:52:24 +0000676 return true;
677 }
678 return false;
679}
680
681
682uint32_t
683SBTarget::GetNumModules () const
684{
Greg Claytone005f2c2010-11-06 01:53:30 +0000685 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000686
Caroline Tice7826c882010-10-26 03:11:13 +0000687 uint32_t num = 0;
Greg Clayton63094e02010-06-23 01:19:29 +0000688 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000689 {
690 // The module list is thread safe, no need to lock
691 num = m_opaque_sp->GetImages().GetSize();
692 }
Caroline Tice7826c882010-10-26 03:11:13 +0000693
694 if (log)
Greg Clayton3f5ee7f2010-10-29 04:59:35 +0000695 log->Printf ("SBTarget(%p)::GetNumModules () => %d", m_opaque_sp.get(), num);
Caroline Tice7826c882010-10-26 03:11:13 +0000696
697 return num;
Chris Lattner24943d22010-06-08 16:52:24 +0000698}
699
Greg Clayton43490d12010-07-30 20:12:55 +0000700void
701SBTarget::Clear ()
702{
Greg Claytone005f2c2010-11-06 01:53:30 +0000703 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000704
705 if (log)
Greg Clayton3f5ee7f2010-10-29 04:59:35 +0000706 log->Printf ("SBTarget(%p)::Clear ()", m_opaque_sp.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000707
Greg Clayton43490d12010-07-30 20:12:55 +0000708 m_opaque_sp.reset();
709}
710
711
Chris Lattner24943d22010-06-08 16:52:24 +0000712SBModule
713SBTarget::FindModule (const SBFileSpec &sb_file_spec)
714{
715 SBModule sb_module;
Greg Clayton63094e02010-06-23 01:19:29 +0000716 if (m_opaque_sp && sb_file_spec.IsValid())
Greg Claytonbdcda462010-12-20 20:49:23 +0000717 {
718 // The module list is thread safe, no need to lock
Greg Clayton24bc5d92011-03-30 18:16:51 +0000719 sb_module.SetModule (m_opaque_sp->GetImages().FindFirstModuleForFileSpec (*sb_file_spec, NULL, NULL));
Greg Claytonbdcda462010-12-20 20:49:23 +0000720 }
Chris Lattner24943d22010-06-08 16:52:24 +0000721 return sb_module;
722}
723
724SBModule
725SBTarget::GetModuleAtIndex (uint32_t idx)
726{
Greg Claytone005f2c2010-11-06 01:53:30 +0000727 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000728
Chris Lattner24943d22010-06-08 16:52:24 +0000729 SBModule sb_module;
Greg Clayton63094e02010-06-23 01:19:29 +0000730 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000731 {
732 // The module list is thread safe, no need to lock
Greg Clayton63094e02010-06-23 01:19:29 +0000733 sb_module.SetModule(m_opaque_sp->GetImages().GetModuleAtIndex(idx));
Greg Claytonbdcda462010-12-20 20:49:23 +0000734 }
Caroline Tice7826c882010-10-26 03:11:13 +0000735
736 if (log)
737 {
Greg Clayton49ce6822010-10-31 03:01:06 +0000738 log->Printf ("SBTarget(%p)::GetModuleAtIndex (idx=%d) => SBModule(%p)",
739 m_opaque_sp.get(), idx, sb_module.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000740 }
741
Chris Lattner24943d22010-06-08 16:52:24 +0000742 return sb_module;
743}
744
745
746SBBroadcaster
747SBTarget::GetBroadcaster () const
748{
Greg Claytone005f2c2010-11-06 01:53:30 +0000749 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000750
Greg Clayton63094e02010-06-23 01:19:29 +0000751 SBBroadcaster broadcaster(m_opaque_sp.get(), false);
Caroline Tice7826c882010-10-26 03:11:13 +0000752
753 if (log)
Greg Clayton3f5ee7f2010-10-29 04:59:35 +0000754 log->Printf ("SBTarget(%p)::GetBroadcaster () => SBBroadcaster(%p)",
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000755 m_opaque_sp.get(), broadcaster.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000756
Chris Lattner24943d22010-06-08 16:52:24 +0000757 return broadcaster;
758}
759
Caroline Tice98f930f2010-09-20 05:20:02 +0000760
761bool
Caroline Tice7826c882010-10-26 03:11:13 +0000762SBTarget::GetDescription (SBStream &description, lldb::DescriptionLevel description_level)
Caroline Tice98f930f2010-09-20 05:20:02 +0000763{
764 if (m_opaque_sp)
Caroline Ticee7a566e2010-09-20 16:21:41 +0000765 {
Caroline Ticee49ec182010-09-22 23:01:29 +0000766 description.ref();
Caroline Tice7826c882010-10-26 03:11:13 +0000767 m_opaque_sp->Dump (description.get(), description_level);
768 }
769 else
770 description.Printf ("No value");
771
772 return true;
773}
774
775bool
776SBTarget::GetDescription (SBStream &description, lldb::DescriptionLevel description_level) const
777{
778 if (m_opaque_sp)
779 {
780 description.ref();
781 m_opaque_sp->Dump (description.get(), description_level);
Caroline Ticee7a566e2010-09-20 16:21:41 +0000782 }
Caroline Tice98f930f2010-09-20 05:20:02 +0000783 else
784 description.Printf ("No value");
785
786 return true;
787}
Greg Clayton4ed315f2011-06-21 01:34:41 +0000788
789
790uint32_t
791SBTarget::FindFunctions (const char *name,
792 uint32_t name_type_mask,
793 bool append,
794 lldb::SBSymbolContextList& sc_list)
795{
796 if (!append)
797 sc_list.Clear();
798 if (m_opaque_sp)
799 {
800 const bool symbols_ok = true;
801 return m_opaque_sp->GetImages().FindFunctions (ConstString(name),
802 name_type_mask,
803 symbols_ok,
804 append,
805 *sc_list);
806 }
807 return 0;
808}
809