blob: 2c9c44f19b4369a12029b01e90afab4ba8a77bff [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
Jim Ingham5a15e692012-02-16 06:50:00 +000090const char *
91SBTarget::GetBroadcasterClassName ()
92{
93 return Target::GetStaticBroadcasterClass().AsCString();
94}
95
Chris Lattner24943d22010-06-08 16:52:24 +000096bool
97SBTarget::IsValid () const
98{
Greg Clayton63094e02010-06-23 01:19:29 +000099 return m_opaque_sp.get() != NULL;
Chris Lattner24943d22010-06-08 16:52:24 +0000100}
101
102SBProcess
103SBTarget::GetProcess ()
104{
105 SBProcess sb_process;
Greg Clayton334d33a2012-01-30 07:41:31 +0000106 ProcessSP process_sp;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000107 TargetSP target_sp(GetSP());
108 if (target_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000109 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000110 process_sp = target_sp->GetProcessSP();
Greg Clayton334d33a2012-01-30 07:41:31 +0000111 sb_process.SetSP (process_sp);
Greg Claytonbdcda462010-12-20 20:49:23 +0000112 }
Caroline Tice7826c882010-10-26 03:11:13 +0000113
Greg Claytone005f2c2010-11-06 01:53:30 +0000114 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000115 if (log)
116 {
Greg Clayton49ce6822010-10-31 03:01:06 +0000117 log->Printf ("SBTarget(%p)::GetProcess () => SBProcess(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +0000118 target_sp.get(), process_sp.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000119 }
120
Chris Lattner24943d22010-06-08 16:52:24 +0000121 return sb_process;
122}
123
Greg Clayton63094e02010-06-23 01:19:29 +0000124SBDebugger
125SBTarget::GetDebugger () const
126{
127 SBDebugger debugger;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000128 TargetSP target_sp(GetSP());
129 if (target_sp)
130 debugger.reset (target_sp->GetDebugger().shared_from_this());
Greg Clayton63094e02010-06-23 01:19:29 +0000131 return debugger;
132}
133
Jim Inghamb5871fe2011-03-31 00:01:24 +0000134SBProcess
135SBTarget::LaunchSimple
136(
137 char const **argv,
138 char const **envp,
139 const char *working_directory
140)
141{
142 char *stdin_path = NULL;
143 char *stdout_path = NULL;
144 char *stderr_path = NULL;
145 uint32_t launch_flags = 0;
146 bool stop_at_entry = false;
147 SBError error;
148 SBListener listener = GetDebugger().GetListener();
149 return Launch (listener,
150 argv,
151 envp,
152 stdin_path,
153 stdout_path,
154 stderr_path,
155 working_directory,
156 launch_flags,
157 stop_at_entry,
158 error);
159}
Greg Claytonde915be2011-01-23 05:56:20 +0000160
161SBProcess
162SBTarget::Launch
163(
Greg Clayton271a5db2011-02-03 21:28:34 +0000164 SBListener &listener,
Greg Claytonde915be2011-01-23 05:56:20 +0000165 char const **argv,
166 char const **envp,
167 const char *stdin_path,
168 const char *stdout_path,
169 const char *stderr_path,
170 const char *working_directory,
171 uint32_t launch_flags, // See LaunchFlags
172 bool stop_at_entry,
173 lldb::SBError& error
174)
175{
Greg Claytone005f2c2010-11-06 01:53:30 +0000176 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000177
Greg Clayton0416bdf2012-01-30 09:04:36 +0000178 SBProcess sb_process;
179 ProcessSP process_sp;
180 TargetSP target_sp(GetSP());
181
Caroline Tice7826c882010-10-26 03:11:13 +0000182 if (log)
Greg Clayton3f5ee7f2010-10-29 04:59:35 +0000183 {
Greg Claytonde915be2011-01-23 05:56:20 +0000184 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 +0000185 target_sp.get(),
Greg Claytonde915be2011-01-23 05:56:20 +0000186 argv,
187 envp,
188 stdin_path ? stdin_path : "NULL",
189 stdout_path ? stdout_path : "NULL",
190 stderr_path ? stderr_path : "NULL",
191 working_directory ? working_directory : "NULL",
192 launch_flags,
193 stop_at_entry,
194 error.get());
Greg Clayton3f5ee7f2010-10-29 04:59:35 +0000195 }
Greg Clayton0416bdf2012-01-30 09:04:36 +0000196
197 if (target_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000198 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000199 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton1a3083a2010-10-06 03:53:16 +0000200
Greg Clayton7c330d62011-01-27 01:01:10 +0000201 if (getenv("LLDB_LAUNCH_FLAG_DISABLE_ASLR"))
202 launch_flags |= eLaunchFlagDisableASLR;
203
Greg Clayton180546b2011-04-30 01:09:13 +0000204 StateType state = eStateInvalid;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000205 process_sp = target_sp->GetProcessSP();
Greg Clayton334d33a2012-01-30 07:41:31 +0000206 if (process_sp)
Greg Clayton28d5fcc2011-01-27 06:44:37 +0000207 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000208 state = process_sp->GetState();
Greg Clayton180546b2011-04-30 01:09:13 +0000209
Greg Clayton334d33a2012-01-30 07:41:31 +0000210 if (process_sp->IsAlive() && state != eStateConnected)
Greg Clayton180546b2011-04-30 01:09:13 +0000211 {
212 if (state == eStateAttaching)
213 error.SetErrorString ("process attach is in progress");
214 else
215 error.SetErrorString ("a process is already being debugged");
Greg Clayton180546b2011-04-30 01:09:13 +0000216 return sb_process;
217 }
Greg Clayton28d5fcc2011-01-27 06:44:37 +0000218 }
219
Greg Clayton180546b2011-04-30 01:09:13 +0000220 if (state == eStateConnected)
221 {
222 // If we are already connected, then we have already specified the
223 // listener, so if a valid listener is supplied, we need to error out
224 // to let the client know.
225 if (listener.IsValid())
226 {
227 error.SetErrorString ("process is connected and already has a listener, pass empty listener");
Greg Clayton180546b2011-04-30 01:09:13 +0000228 return sb_process;
229 }
230 }
231 else
Greg Claytonc5f728c2010-10-06 22:10:17 +0000232 {
Greg Clayton271a5db2011-02-03 21:28:34 +0000233 if (listener.IsValid())
Greg Clayton46c9a352012-02-09 06:16:32 +0000234 process_sp = target_sp->CreateProcess (listener.ref(), NULL, NULL);
Greg Clayton271a5db2011-02-03 21:28:34 +0000235 else
Greg Clayton46c9a352012-02-09 06:16:32 +0000236 process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener(), NULL, NULL);
Greg Clayton180546b2011-04-30 01:09:13 +0000237 }
Greg Clayton7c330d62011-01-27 01:01:10 +0000238
Greg Clayton334d33a2012-01-30 07:41:31 +0000239 if (process_sp)
Greg Clayton180546b2011-04-30 01:09:13 +0000240 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000241 sb_process.SetSP (process_sp);
Greg Clayton180546b2011-04-30 01:09:13 +0000242 if (getenv("LLDB_LAUNCH_FLAG_DISABLE_STDIO"))
243 launch_flags |= eLaunchFlagDisableSTDIO;
244
Greg Clayton36bc5ea2011-11-03 21:22:33 +0000245 ProcessLaunchInfo launch_info (stdin_path, stdout_path, stderr_path, working_directory, launch_flags);
246
Greg Clayton0416bdf2012-01-30 09:04:36 +0000247 Module *exe_module = target_sp->GetExecutableModulePointer();
Greg Clayton36bc5ea2011-11-03 21:22:33 +0000248 if (exe_module)
Greg Clayton1d1f39e2011-11-29 04:03:30 +0000249 launch_info.SetExecutableFile(exe_module->GetPlatformFileSpec(), true);
Greg Clayton36bc5ea2011-11-03 21:22:33 +0000250 if (argv)
251 launch_info.GetArguments().AppendArguments (argv);
252 if (envp)
253 launch_info.GetEnvironmentEntries ().SetArguments (envp);
254
Greg Clayton334d33a2012-01-30 07:41:31 +0000255 error.SetError (process_sp->Launch (launch_info));
Greg Clayton180546b2011-04-30 01:09:13 +0000256 if (error.Success())
Greg Clayton7c330d62011-01-27 01:01:10 +0000257 {
Greg Clayton180546b2011-04-30 01:09:13 +0000258 // We we are stopping at the entry point, we can return now!
259 if (stop_at_entry)
260 return sb_process;
Greg Clayton7c330d62011-01-27 01:01:10 +0000261
Greg Clayton180546b2011-04-30 01:09:13 +0000262 // Make sure we are stopped at the entry
Greg Clayton334d33a2012-01-30 07:41:31 +0000263 StateType state = process_sp->WaitForProcessToStop (NULL);
Greg Clayton180546b2011-04-30 01:09:13 +0000264 if (state == eStateStopped)
Greg Clayton7c330d62011-01-27 01:01:10 +0000265 {
Greg Clayton180546b2011-04-30 01:09:13 +0000266 // resume the process to skip the entry point
Greg Clayton334d33a2012-01-30 07:41:31 +0000267 error.SetError (process_sp->Resume());
Greg Clayton180546b2011-04-30 01:09:13 +0000268 if (error.Success())
Greg Clayton7c330d62011-01-27 01:01:10 +0000269 {
Greg Clayton180546b2011-04-30 01:09:13 +0000270 // If we are doing synchronous mode, then wait for the
271 // process to stop yet again!
Greg Clayton0416bdf2012-01-30 09:04:36 +0000272 if (target_sp->GetDebugger().GetAsyncExecution () == false)
Greg Clayton334d33a2012-01-30 07:41:31 +0000273 process_sp->WaitForProcessToStop (NULL);
Greg Clayton7c330d62011-01-27 01:01:10 +0000274 }
275 }
276 }
Greg Clayton180546b2011-04-30 01:09:13 +0000277 }
278 else
279 {
280 error.SetErrorString ("unable to create lldb_private::Process");
Greg Claytonc5f728c2010-10-06 22:10:17 +0000281 }
282 }
283 else
284 {
285 error.SetErrorString ("SBTarget is invalid");
Chris Lattner24943d22010-06-08 16:52:24 +0000286 }
Caroline Tice7826c882010-10-26 03:11:13 +0000287
Caroline Tice926060e2010-10-29 21:48:37 +0000288 log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
Caroline Tice7826c882010-10-26 03:11:13 +0000289 if (log)
290 {
Greg Clayton49ce6822010-10-31 03:01:06 +0000291 log->Printf ("SBTarget(%p)::Launch (...) => SBProceess(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +0000292 target_sp.get(), process_sp.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000293 }
294
Greg Clayton1a3083a2010-10-06 03:53:16 +0000295 return sb_process;
Chris Lattner24943d22010-06-08 16:52:24 +0000296}
297
Greg Claytond5b0b442011-12-02 02:10:57 +0000298#if defined(__APPLE__)
299
300lldb::SBProcess
301SBTarget::AttachToProcessWithID (SBListener &listener,
302 ::pid_t pid,
303 lldb::SBError& error)
304{
305 return AttachToProcessWithID (listener, (lldb::pid_t)pid, error);
306}
307
308#endif // #if defined(__APPLE__)
Greg Claytonc5f728c2010-10-06 22:10:17 +0000309
310lldb::SBProcess
Greg Claytond8c62532010-10-07 04:19:01 +0000311SBTarget::AttachToProcessWithID
Greg Claytonc5f728c2010-10-06 22:10:17 +0000312(
Greg Clayton271a5db2011-02-03 21:28:34 +0000313 SBListener &listener,
Greg Claytonc5f728c2010-10-06 22:10:17 +0000314 lldb::pid_t pid,// The process ID to attach to
315 SBError& error // An error explaining what went wrong if attach fails
316)
317{
318 SBProcess sb_process;
Greg Clayton334d33a2012-01-30 07:41:31 +0000319 ProcessSP process_sp;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000320 TargetSP target_sp(GetSP());
321 if (target_sp)
Greg Claytonc5f728c2010-10-06 22:10:17 +0000322 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000323 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytonde1dd812011-06-24 03:21:43 +0000324
325 StateType state = eStateInvalid;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000326 process_sp = target_sp->GetProcessSP();
Greg Clayton334d33a2012-01-30 07:41:31 +0000327 if (process_sp)
Greg Claytonde1dd812011-06-24 03:21:43 +0000328 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000329 state = process_sp->GetState();
Greg Claytonde1dd812011-06-24 03:21:43 +0000330
Greg Clayton334d33a2012-01-30 07:41:31 +0000331 if (process_sp->IsAlive() && state != eStateConnected)
Greg Claytonde1dd812011-06-24 03:21:43 +0000332 {
333 if (state == eStateAttaching)
334 error.SetErrorString ("process attach is in progress");
335 else
336 error.SetErrorString ("a process is already being debugged");
Greg Claytonde1dd812011-06-24 03:21:43 +0000337 return sb_process;
338 }
339 }
340
341 if (state == eStateConnected)
342 {
343 // If we are already connected, then we have already specified the
344 // listener, so if a valid listener is supplied, we need to error out
345 // to let the client know.
346 if (listener.IsValid())
347 {
348 error.SetErrorString ("process is connected and already has a listener, pass empty listener");
Greg Claytonde1dd812011-06-24 03:21:43 +0000349 return sb_process;
350 }
351 }
Greg Clayton271a5db2011-02-03 21:28:34 +0000352 else
Greg Claytonde1dd812011-06-24 03:21:43 +0000353 {
354 if (listener.IsValid())
Greg Clayton46c9a352012-02-09 06:16:32 +0000355 process_sp = target_sp->CreateProcess (listener.ref(), NULL, NULL);
Greg Claytonde1dd812011-06-24 03:21:43 +0000356 else
Greg Clayton46c9a352012-02-09 06:16:32 +0000357 process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener(), NULL, NULL);
Greg Claytonde1dd812011-06-24 03:21:43 +0000358 }
Greg Clayton334d33a2012-01-30 07:41:31 +0000359 if (process_sp)
Greg Claytonc5f728c2010-10-06 22:10:17 +0000360 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000361 sb_process.SetSP (process_sp);
362
Greg Clayton527154d2011-11-15 03:53:30 +0000363 ProcessAttachInfo attach_info;
364 attach_info.SetProcessID (pid);
Greg Clayton334d33a2012-01-30 07:41:31 +0000365 error.SetError (process_sp->Attach (attach_info));
Johnny Chen535960e2011-06-17 00:51:15 +0000366 // If we are doing synchronous mode, then wait for the
367 // process to stop!
Greg Clayton0416bdf2012-01-30 09:04:36 +0000368 if (target_sp->GetDebugger().GetAsyncExecution () == false)
Greg Clayton334d33a2012-01-30 07:41:31 +0000369 process_sp->WaitForProcessToStop (NULL);
Greg Claytonc5f728c2010-10-06 22:10:17 +0000370 }
371 else
372 {
373 error.SetErrorString ("unable to create lldb_private::Process");
374 }
375 }
376 else
377 {
378 error.SetErrorString ("SBTarget is invalid");
379 }
380 return sb_process;
381
382}
383
384lldb::SBProcess
Greg Claytond8c62532010-10-07 04:19:01 +0000385SBTarget::AttachToProcessWithName
Greg Claytonc5f728c2010-10-06 22:10:17 +0000386(
Greg Clayton271a5db2011-02-03 21:28:34 +0000387 SBListener &listener,
Greg Claytonc5f728c2010-10-06 22:10:17 +0000388 const char *name, // basename of process to attach to
389 bool wait_for, // if true wait for a new instance of "name" to be launched
390 SBError& error // An error explaining what went wrong if attach fails
391)
392{
393 SBProcess sb_process;
Greg Clayton334d33a2012-01-30 07:41:31 +0000394 ProcessSP process_sp;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000395 TargetSP target_sp(GetSP());
396 if (name && target_sp)
Greg Claytonc5f728c2010-10-06 22:10:17 +0000397 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000398 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytonbdcda462010-12-20 20:49:23 +0000399
Greg Claytonde1dd812011-06-24 03:21:43 +0000400 StateType state = eStateInvalid;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000401 process_sp = target_sp->GetProcessSP();
Greg Clayton334d33a2012-01-30 07:41:31 +0000402 if (process_sp)
Greg Claytonde1dd812011-06-24 03:21:43 +0000403 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000404 state = process_sp->GetState();
Greg Claytonde1dd812011-06-24 03:21:43 +0000405
Greg Clayton334d33a2012-01-30 07:41:31 +0000406 if (process_sp->IsAlive() && state != eStateConnected)
Greg Claytonde1dd812011-06-24 03:21:43 +0000407 {
408 if (state == eStateAttaching)
409 error.SetErrorString ("process attach is in progress");
410 else
411 error.SetErrorString ("a process is already being debugged");
Greg Claytonde1dd812011-06-24 03:21:43 +0000412 return sb_process;
413 }
414 }
415
416 if (state == eStateConnected)
417 {
418 // If we are already connected, then we have already specified the
419 // listener, so if a valid listener is supplied, we need to error out
420 // to let the client know.
421 if (listener.IsValid())
422 {
423 error.SetErrorString ("process is connected and already has a listener, pass empty listener");
Greg Claytonde1dd812011-06-24 03:21:43 +0000424 return sb_process;
425 }
426 }
Greg Clayton271a5db2011-02-03 21:28:34 +0000427 else
Greg Claytonde1dd812011-06-24 03:21:43 +0000428 {
429 if (listener.IsValid())
Greg Clayton46c9a352012-02-09 06:16:32 +0000430 process_sp = target_sp->CreateProcess (listener.ref(), NULL, NULL);
Greg Claytonde1dd812011-06-24 03:21:43 +0000431 else
Greg Clayton46c9a352012-02-09 06:16:32 +0000432 process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener(), NULL, NULL);
Greg Claytonde1dd812011-06-24 03:21:43 +0000433 }
Greg Claytonc5f728c2010-10-06 22:10:17 +0000434
Greg Clayton334d33a2012-01-30 07:41:31 +0000435 if (process_sp)
Greg Claytonc5f728c2010-10-06 22:10:17 +0000436 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000437 sb_process.SetSP (process_sp);
Greg Clayton527154d2011-11-15 03:53:30 +0000438 ProcessAttachInfo attach_info;
439 attach_info.GetExecutableFile().SetFile(name, false);
440 attach_info.SetWaitForLaunch(wait_for);
Greg Clayton334d33a2012-01-30 07:41:31 +0000441 error.SetError (process_sp->Attach (attach_info));
Johnny Chen58d02ff2011-06-17 19:21:30 +0000442 // If we are doing synchronous mode, then wait for the
443 // process to stop!
Greg Clayton0416bdf2012-01-30 09:04:36 +0000444 if (target_sp->GetDebugger().GetAsyncExecution () == false)
Greg Clayton334d33a2012-01-30 07:41:31 +0000445 process_sp->WaitForProcessToStop (NULL);
Greg Claytonc5f728c2010-10-06 22:10:17 +0000446 }
447 else
448 {
449 error.SetErrorString ("unable to create lldb_private::Process");
450 }
451 }
452 else
453 {
454 error.SetErrorString ("SBTarget is invalid");
455 }
456 return sb_process;
457
458}
459
James McIlree38093402011-03-04 00:31:13 +0000460lldb::SBProcess
461SBTarget::ConnectRemote
462(
463 SBListener &listener,
464 const char *url,
465 const char *plugin_name,
466 SBError& error
467)
468{
469 SBProcess sb_process;
Greg Clayton334d33a2012-01-30 07:41:31 +0000470 ProcessSP process_sp;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000471 TargetSP target_sp(GetSP());
472 if (target_sp)
James McIlree38093402011-03-04 00:31:13 +0000473 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000474 Mutex::Locker api_locker (target_sp->GetAPIMutex());
James McIlree38093402011-03-04 00:31:13 +0000475 if (listener.IsValid())
Greg Clayton46c9a352012-02-09 06:16:32 +0000476 process_sp = target_sp->CreateProcess (listener.ref(), plugin_name, NULL);
James McIlree38093402011-03-04 00:31:13 +0000477 else
Greg Clayton46c9a352012-02-09 06:16:32 +0000478 process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener(), plugin_name, NULL);
James McIlree38093402011-03-04 00:31:13 +0000479
480
Greg Clayton334d33a2012-01-30 07:41:31 +0000481 if (process_sp)
James McIlree38093402011-03-04 00:31:13 +0000482 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000483 sb_process.SetSP (process_sp);
484 error.SetError (process_sp->ConnectRemote (url));
James McIlree38093402011-03-04 00:31:13 +0000485 }
486 else
487 {
488 error.SetErrorString ("unable to create lldb_private::Process");
489 }
490 }
491 else
492 {
493 error.SetErrorString ("SBTarget is invalid");
494 }
495 return sb_process;
496}
497
Chris Lattner24943d22010-06-08 16:52:24 +0000498SBFileSpec
499SBTarget::GetExecutable ()
500{
Caroline Tice7826c882010-10-26 03:11:13 +0000501
Chris Lattner24943d22010-06-08 16:52:24 +0000502 SBFileSpec exe_file_spec;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000503 TargetSP target_sp(GetSP());
504 if (target_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000505 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000506 Module *exe_module = target_sp->GetExecutableModulePointer();
Greg Clayton5beb99d2011-08-11 02:48:45 +0000507 if (exe_module)
508 exe_file_spec.SetFileSpec (exe_module->GetFileSpec());
Chris Lattner24943d22010-06-08 16:52:24 +0000509 }
Caroline Tice7826c882010-10-26 03:11:13 +0000510
Greg Claytone005f2c2010-11-06 01:53:30 +0000511 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000512 if (log)
513 {
Greg Clayton49ce6822010-10-31 03:01:06 +0000514 log->Printf ("SBTarget(%p)::GetExecutable () => SBFileSpec(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +0000515 target_sp.get(), exe_file_spec.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000516 }
517
Chris Lattner24943d22010-06-08 16:52:24 +0000518 return exe_file_spec;
519}
520
Chris Lattner24943d22010-06-08 16:52:24 +0000521bool
Chris Lattner24943d22010-06-08 16:52:24 +0000522SBTarget::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
527bool
528SBTarget::operator != (const SBTarget &rhs) const
529{
Greg Clayton63094e02010-06-23 01:19:29 +0000530 return m_opaque_sp.get() != rhs.m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000531}
532
Greg Clayton334d33a2012-01-30 07:41:31 +0000533lldb::TargetSP
534SBTarget::GetSP () const
Greg Clayton15afa9f2011-10-01 02:59:24 +0000535{
536 return m_opaque_sp;
537}
538
Greg Clayton63094e02010-06-23 01:19:29 +0000539void
Greg Clayton334d33a2012-01-30 07:41:31 +0000540SBTarget::SetSP (const lldb::TargetSP& target_sp)
Greg Clayton63094e02010-06-23 01:19:29 +0000541{
542 m_opaque_sp = target_sp;
Chris Lattner24943d22010-06-08 16:52:24 +0000543}
544
Greg Claytona3955062011-07-22 16:46:35 +0000545lldb::SBAddress
546SBTarget::ResolveLoadAddress (lldb::addr_t vm_addr)
Greg Claytonea49cc72010-12-12 19:25:26 +0000547{
Greg Claytona3955062011-07-22 16:46:35 +0000548 lldb::SBAddress sb_addr;
549 Address &addr = sb_addr.ref();
Greg Clayton0416bdf2012-01-30 09:04:36 +0000550 TargetSP target_sp(GetSP());
551 if (target_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000552 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000553 Mutex::Locker api_locker (target_sp->GetAPIMutex());
554 if (target_sp->GetSectionLoadList().ResolveLoadAddress (vm_addr, addr))
Greg Claytona3955062011-07-22 16:46:35 +0000555 return sb_addr;
Greg Claytonbdcda462010-12-20 20:49:23 +0000556 }
Greg Claytonea49cc72010-12-12 19:25:26 +0000557
Greg Claytona3955062011-07-22 16:46:35 +0000558 // We have a load address that isn't in a section, just return an address
559 // with the offset filled in (the address) and the section set to NULL
Greg Clayton3508c382012-02-24 01:59:29 +0000560 addr.SetRawAddress(vm_addr);
Greg Claytona3955062011-07-22 16:46:35 +0000561 return sb_addr;
Greg Claytonea49cc72010-12-12 19:25:26 +0000562}
563
Greg Claytonafb81862011-03-02 21:34:46 +0000564SBSymbolContext
565SBTarget::ResolveSymbolContextForAddress (const SBAddress& addr, uint32_t resolve_scope)
566{
567 SBSymbolContext sc;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000568 if (addr.IsValid())
569 {
570 TargetSP target_sp(GetSP());
571 if (target_sp)
572 target_sp->GetImages().ResolveSymbolContextForAddress (addr.ref(), resolve_scope, sc.ref());
573 }
Greg Claytonafb81862011-03-02 21:34:46 +0000574 return sc;
575}
576
577
Chris Lattner24943d22010-06-08 16:52:24 +0000578SBBreakpoint
579SBTarget::BreakpointCreateByLocation (const char *file, uint32_t line)
580{
Greg Claytond6d806c2010-11-08 00:28:40 +0000581 return SBBreakpoint(BreakpointCreateByLocation (SBFileSpec (file, false), line));
Chris Lattner24943d22010-06-08 16:52:24 +0000582}
583
584SBBreakpoint
585SBTarget::BreakpointCreateByLocation (const SBFileSpec &sb_file_spec, uint32_t line)
586{
Greg Claytone005f2c2010-11-06 01:53:30 +0000587 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000588
Chris Lattner24943d22010-06-08 16:52:24 +0000589 SBBreakpoint sb_bp;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000590 TargetSP target_sp(GetSP());
591 if (target_sp && line != 0)
Greg Claytonbdcda462010-12-20 20:49:23 +0000592 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000593 Mutex::Locker api_locker (target_sp->GetAPIMutex());
594 *sb_bp = target_sp->CreateBreakpoint (NULL, *sb_file_spec, line, true, false);
Greg Claytonbdcda462010-12-20 20:49:23 +0000595 }
Caroline Tice7826c882010-10-26 03:11:13 +0000596
597 if (log)
598 {
599 SBStream sstr;
600 sb_bp.GetDescription (sstr);
Greg Clayton49ce6822010-10-31 03:01:06 +0000601 char path[PATH_MAX];
602 sb_file_spec->GetPath (path, sizeof(path));
603 log->Printf ("SBTarget(%p)::BreakpointCreateByLocation ( %s:%u ) => SBBreakpoint(%p): %s",
Greg Clayton0416bdf2012-01-30 09:04:36 +0000604 target_sp.get(),
Greg Clayton49ce6822010-10-31 03:01:06 +0000605 path,
Greg Claytona66ba462010-10-30 04:51:46 +0000606 line,
Greg Clayton49ce6822010-10-31 03:01:06 +0000607 sb_bp.get(),
Caroline Tice7826c882010-10-26 03:11:13 +0000608 sstr.GetData());
609 }
610
Chris Lattner24943d22010-06-08 16:52:24 +0000611 return sb_bp;
612}
613
614SBBreakpoint
615SBTarget::BreakpointCreateByName (const char *symbol_name, const char *module_name)
616{
Greg Claytone005f2c2010-11-06 01:53:30 +0000617 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000618
Chris Lattner24943d22010-06-08 16:52:24 +0000619 SBBreakpoint sb_bp;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000620 TargetSP target_sp(GetSP());
621 if (target_sp.get())
Chris Lattner24943d22010-06-08 16:52:24 +0000622 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000623 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Chris Lattner24943d22010-06-08 16:52:24 +0000624 if (module_name && module_name[0])
625 {
Jim Ingham03c8ee52011-09-21 01:17:13 +0000626 FileSpecList module_spec_list;
627 module_spec_list.Append (FileSpec (module_name, false));
Greg Clayton0416bdf2012-01-30 09:04:36 +0000628 *sb_bp = target_sp->CreateBreakpoint (&module_spec_list, NULL, symbol_name, eFunctionNameTypeAuto, false);
Chris Lattner24943d22010-06-08 16:52:24 +0000629 }
630 else
631 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000632 *sb_bp = target_sp->CreateBreakpoint (NULL, NULL, symbol_name, eFunctionNameTypeAuto, false);
Chris Lattner24943d22010-06-08 16:52:24 +0000633 }
634 }
Caroline Tice7826c882010-10-26 03:11:13 +0000635
636 if (log)
637 {
Greg Clayton49ce6822010-10-31 03:01:06 +0000638 log->Printf ("SBTarget(%p)::BreakpointCreateByName (symbol=\"%s\", module=\"%s\") => SBBreakpoint(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +0000639 target_sp.get(), symbol_name, module_name, sb_bp.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000640 }
641
Chris Lattner24943d22010-06-08 16:52:24 +0000642 return sb_bp;
643}
644
Jim Inghamd6d47972011-09-23 00:54:11 +0000645lldb::SBBreakpoint
646SBTarget::BreakpointCreateByName (const char *symbol_name,
647 const SBFileSpecList &module_list,
648 const SBFileSpecList &comp_unit_list)
649{
Jim Ingham1fb8a2d2011-10-11 01:18:55 +0000650 uint32_t name_type_mask = eFunctionNameTypeAuto;
651 return BreakpointCreateByName (symbol_name, name_type_mask, module_list, comp_unit_list);
652}
653
654lldb::SBBreakpoint
655SBTarget::BreakpointCreateByName (const char *symbol_name,
656 uint32_t name_type_mask,
657 const SBFileSpecList &module_list,
658 const SBFileSpecList &comp_unit_list)
659{
Jim Inghamd6d47972011-09-23 00:54:11 +0000660 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
661
662 SBBreakpoint sb_bp;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000663 TargetSP target_sp(GetSP());
664 if (target_sp && symbol_name && symbol_name[0])
Jim Inghamd6d47972011-09-23 00:54:11 +0000665 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000666 Mutex::Locker api_locker (target_sp->GetAPIMutex());
667 *sb_bp = target_sp->CreateBreakpoint (module_list.get(),
Jim Inghamd6d47972011-09-23 00:54:11 +0000668 comp_unit_list.get(),
669 symbol_name,
Jim Ingham1fb8a2d2011-10-11 01:18:55 +0000670 name_type_mask,
Jim Inghamd6d47972011-09-23 00:54:11 +0000671 false);
672 }
673
674 if (log)
675 {
Jim Ingham1fb8a2d2011-10-11 01:18:55 +0000676 log->Printf ("SBTarget(%p)::BreakpointCreateByName (symbol=\"%s\", name_type: %d) => SBBreakpoint(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +0000677 target_sp.get(), symbol_name, name_type_mask, sb_bp.get());
Jim Inghamd6d47972011-09-23 00:54:11 +0000678 }
679
680 return sb_bp;
681}
682
683
Chris Lattner24943d22010-06-08 16:52:24 +0000684SBBreakpoint
685SBTarget::BreakpointCreateByRegex (const char *symbol_name_regex, const char *module_name)
686{
Greg Claytone005f2c2010-11-06 01:53:30 +0000687 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000688
Chris Lattner24943d22010-06-08 16:52:24 +0000689 SBBreakpoint sb_bp;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000690 TargetSP target_sp(GetSP());
691 if (target_sp && symbol_name_regex && symbol_name_regex[0])
Chris Lattner24943d22010-06-08 16:52:24 +0000692 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000693 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Chris Lattner24943d22010-06-08 16:52:24 +0000694 RegularExpression regexp(symbol_name_regex);
695
696 if (module_name && module_name[0])
697 {
Jim Ingham03c8ee52011-09-21 01:17:13 +0000698 FileSpecList module_spec_list;
699 module_spec_list.Append (FileSpec (module_name, false));
Chris Lattner24943d22010-06-08 16:52:24 +0000700
Greg Clayton0416bdf2012-01-30 09:04:36 +0000701 *sb_bp = target_sp->CreateFuncRegexBreakpoint (&module_spec_list, NULL, regexp, false);
Chris Lattner24943d22010-06-08 16:52:24 +0000702 }
703 else
704 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000705 *sb_bp = target_sp->CreateFuncRegexBreakpoint (NULL, NULL, regexp, false);
Chris Lattner24943d22010-06-08 16:52:24 +0000706 }
707 }
Caroline Tice7826c882010-10-26 03:11:13 +0000708
709 if (log)
710 {
Greg Clayton49ce6822010-10-31 03:01:06 +0000711 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (symbol_regex=\"%s\", module_name=\"%s\") => SBBreakpoint(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +0000712 target_sp.get(), symbol_name_regex, module_name, sb_bp.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000713 }
714
Chris Lattner24943d22010-06-08 16:52:24 +0000715 return sb_bp;
716}
717
Jim Inghamd6d47972011-09-23 00:54:11 +0000718lldb::SBBreakpoint
719SBTarget::BreakpointCreateByRegex (const char *symbol_name_regex,
720 const SBFileSpecList &module_list,
721 const SBFileSpecList &comp_unit_list)
722{
723 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Chris Lattner24943d22010-06-08 16:52:24 +0000724
Jim Inghamd6d47972011-09-23 00:54:11 +0000725 SBBreakpoint sb_bp;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000726 TargetSP target_sp(GetSP());
727 if (target_sp && symbol_name_regex && symbol_name_regex[0])
Jim Inghamd6d47972011-09-23 00:54:11 +0000728 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000729 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Jim Inghamd6d47972011-09-23 00:54:11 +0000730 RegularExpression regexp(symbol_name_regex);
731
Greg Clayton0416bdf2012-01-30 09:04:36 +0000732 *sb_bp = target_sp->CreateFuncRegexBreakpoint (module_list.get(), comp_unit_list.get(), regexp, false);
Jim Inghamd6d47972011-09-23 00:54:11 +0000733 }
734
735 if (log)
736 {
737 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (symbol_regex=\"%s\") => SBBreakpoint(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +0000738 target_sp.get(), symbol_name_regex, sb_bp.get());
Jim Inghamd6d47972011-09-23 00:54:11 +0000739 }
740
741 return sb_bp;
742}
Chris Lattner24943d22010-06-08 16:52:24 +0000743
744SBBreakpoint
745SBTarget::BreakpointCreateByAddress (addr_t address)
746{
Greg Claytone005f2c2010-11-06 01:53:30 +0000747 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000748
Chris Lattner24943d22010-06-08 16:52:24 +0000749 SBBreakpoint sb_bp;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000750 TargetSP target_sp(GetSP());
751 if (target_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000752 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000753 Mutex::Locker api_locker (target_sp->GetAPIMutex());
754 *sb_bp = target_sp->CreateBreakpoint (address, false);
Greg Claytonbdcda462010-12-20 20:49:23 +0000755 }
Caroline Tice7826c882010-10-26 03:11:13 +0000756
757 if (log)
758 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000759 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 +0000760 }
761
Chris Lattner24943d22010-06-08 16:52:24 +0000762 return sb_bp;
763}
764
Jim Ingham03c8ee52011-09-21 01:17:13 +0000765lldb::SBBreakpoint
766SBTarget::BreakpointCreateBySourceRegex (const char *source_regex, const lldb::SBFileSpec &source_file, const char *module_name)
767{
768 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
769
770 SBBreakpoint sb_bp;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000771 TargetSP target_sp(GetSP());
772 if (target_sp && source_regex && source_regex[0])
Jim Ingham03c8ee52011-09-21 01:17:13 +0000773 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000774 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Jim Ingham03c8ee52011-09-21 01:17:13 +0000775 RegularExpression regexp(source_regex);
Jim Inghamd6d47972011-09-23 00:54:11 +0000776 FileSpecList source_file_spec_list;
777 source_file_spec_list.Append (source_file.ref());
Jim Ingham03c8ee52011-09-21 01:17:13 +0000778
779 if (module_name && module_name[0])
780 {
781 FileSpecList module_spec_list;
782 module_spec_list.Append (FileSpec (module_name, false));
783
Greg Clayton0416bdf2012-01-30 09:04:36 +0000784 *sb_bp = target_sp->CreateSourceRegexBreakpoint (&module_spec_list, &source_file_spec_list, regexp, false);
Jim Ingham03c8ee52011-09-21 01:17:13 +0000785 }
786 else
787 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000788 *sb_bp = target_sp->CreateSourceRegexBreakpoint (NULL, &source_file_spec_list, regexp, false);
Jim Ingham03c8ee52011-09-21 01:17:13 +0000789 }
790 }
791
792 if (log)
793 {
794 char path[PATH_MAX];
795 source_file->GetPath (path, sizeof(path));
796 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (source_regex=\"%s\", file=\"%s\", module_name=\"%s\") => SBBreakpoint(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +0000797 target_sp.get(), source_regex, path, module_name, sb_bp.get());
Jim Ingham03c8ee52011-09-21 01:17:13 +0000798 }
799
800 return sb_bp;
801}
802
Jim Inghamd6d47972011-09-23 00:54:11 +0000803lldb::SBBreakpoint
804SBTarget::BreakpointCreateBySourceRegex (const char *source_regex,
805 const SBFileSpecList &module_list,
806 const lldb::SBFileSpecList &source_file_list)
807{
808 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
809
810 SBBreakpoint sb_bp;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000811 TargetSP target_sp(GetSP());
812 if (target_sp && source_regex && source_regex[0])
Jim Inghamd6d47972011-09-23 00:54:11 +0000813 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000814 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Jim Inghamd6d47972011-09-23 00:54:11 +0000815 RegularExpression regexp(source_regex);
Greg Clayton0416bdf2012-01-30 09:04:36 +0000816 *sb_bp = target_sp->CreateSourceRegexBreakpoint (module_list.get(), source_file_list.get(), regexp, false);
Jim Inghamd6d47972011-09-23 00:54:11 +0000817 }
818
819 if (log)
820 {
821 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (source_regex=\"%s\") => SBBreakpoint(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +0000822 target_sp.get(), source_regex, sb_bp.get());
Jim Inghamd6d47972011-09-23 00:54:11 +0000823 }
824
825 return sb_bp;
826}
Jim Ingham03c8ee52011-09-21 01:17:13 +0000827
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000828uint32_t
829SBTarget::GetNumBreakpoints () const
830{
Greg Clayton0416bdf2012-01-30 09:04:36 +0000831 TargetSP target_sp(GetSP());
832 if (target_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000833 {
834 // The breakpoint list is thread safe, no need to lock
Greg Clayton0416bdf2012-01-30 09:04:36 +0000835 return target_sp->GetBreakpointList().GetSize();
Greg Claytonbdcda462010-12-20 20:49:23 +0000836 }
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000837 return 0;
838}
839
840SBBreakpoint
841SBTarget::GetBreakpointAtIndex (uint32_t idx) const
842{
843 SBBreakpoint sb_breakpoint;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000844 TargetSP target_sp(GetSP());
845 if (target_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000846 {
847 // The breakpoint list is thread safe, no need to lock
Greg Clayton0416bdf2012-01-30 09:04:36 +0000848 *sb_breakpoint = target_sp->GetBreakpointList().GetBreakpointAtIndex(idx);
Greg Claytonbdcda462010-12-20 20:49:23 +0000849 }
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000850 return sb_breakpoint;
851}
Chris Lattner24943d22010-06-08 16:52:24 +0000852
853bool
854SBTarget::BreakpointDelete (break_id_t bp_id)
855{
Greg Claytone005f2c2010-11-06 01:53:30 +0000856 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000857
Caroline Tice7826c882010-10-26 03:11:13 +0000858 bool result = false;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000859 TargetSP target_sp(GetSP());
860 if (target_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000861 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000862 Mutex::Locker api_locker (target_sp->GetAPIMutex());
863 result = target_sp->RemoveBreakpointByID (bp_id);
Greg Claytonbdcda462010-12-20 20:49:23 +0000864 }
Caroline Tice7826c882010-10-26 03:11:13 +0000865
866 if (log)
867 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000868 log->Printf ("SBTarget(%p)::BreakpointDelete (bp_id=%d) => %i", target_sp.get(), (uint32_t) bp_id, result);
Caroline Tice7826c882010-10-26 03:11:13 +0000869 }
870
871 return result;
Chris Lattner24943d22010-06-08 16:52:24 +0000872}
873
Johnny Chen096c2932011-09-26 22:40:50 +0000874SBBreakpoint
875SBTarget::FindBreakpointByID (break_id_t bp_id)
876{
877 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
878
879 SBBreakpoint sb_breakpoint;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000880 TargetSP target_sp(GetSP());
881 if (target_sp && bp_id != LLDB_INVALID_BREAK_ID)
Johnny Chen096c2932011-09-26 22:40:50 +0000882 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000883 Mutex::Locker api_locker (target_sp->GetAPIMutex());
884 *sb_breakpoint = target_sp->GetBreakpointByID (bp_id);
Johnny Chen096c2932011-09-26 22:40:50 +0000885 }
886
887 if (log)
888 {
889 log->Printf ("SBTarget(%p)::FindBreakpointByID (bp_id=%d) => SBBreakpoint(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +0000890 target_sp.get(), (uint32_t) bp_id, sb_breakpoint.get());
Johnny Chen096c2932011-09-26 22:40:50 +0000891 }
892
893 return sb_breakpoint;
894}
895
Chris Lattner24943d22010-06-08 16:52:24 +0000896bool
897SBTarget::EnableAllBreakpoints ()
898{
Greg Clayton0416bdf2012-01-30 09:04:36 +0000899 TargetSP target_sp(GetSP());
900 if (target_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000901 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000902 Mutex::Locker api_locker (target_sp->GetAPIMutex());
903 target_sp->EnableAllBreakpoints ();
Chris Lattner24943d22010-06-08 16:52:24 +0000904 return true;
905 }
906 return false;
907}
908
909bool
910SBTarget::DisableAllBreakpoints ()
911{
Greg Clayton0416bdf2012-01-30 09:04:36 +0000912 TargetSP target_sp(GetSP());
913 if (target_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000914 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000915 Mutex::Locker api_locker (target_sp->GetAPIMutex());
916 target_sp->DisableAllBreakpoints ();
Chris Lattner24943d22010-06-08 16:52:24 +0000917 return true;
918 }
919 return false;
920}
921
922bool
923SBTarget::DeleteAllBreakpoints ()
924{
Greg Clayton0416bdf2012-01-30 09:04:36 +0000925 TargetSP target_sp(GetSP());
926 if (target_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000927 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000928 Mutex::Locker api_locker (target_sp->GetAPIMutex());
929 target_sp->RemoveAllBreakpoints ();
Chris Lattner24943d22010-06-08 16:52:24 +0000930 return true;
931 }
932 return false;
933}
934
Johnny Chen096c2932011-09-26 22:40:50 +0000935uint32_t
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000936SBTarget::GetNumWatchpoints () const
Johnny Chen096c2932011-09-26 22:40:50 +0000937{
Greg Clayton0416bdf2012-01-30 09:04:36 +0000938 TargetSP target_sp(GetSP());
939 if (target_sp)
Johnny Chen096c2932011-09-26 22:40:50 +0000940 {
Johnny Chenecd4feb2011-10-14 00:42:25 +0000941 // The watchpoint list is thread safe, no need to lock
Greg Clayton0416bdf2012-01-30 09:04:36 +0000942 return target_sp->GetWatchpointList().GetSize();
Johnny Chen096c2932011-09-26 22:40:50 +0000943 }
944 return 0;
945}
946
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000947SBWatchpoint
948SBTarget::GetWatchpointAtIndex (uint32_t idx) const
Johnny Chen5eb54bb2011-09-27 20:29:45 +0000949{
Johnny Chenecd4feb2011-10-14 00:42:25 +0000950 SBWatchpoint sb_watchpoint;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000951 TargetSP target_sp(GetSP());
952 if (target_sp)
Johnny Chen096c2932011-09-26 22:40:50 +0000953 {
Johnny Chenecd4feb2011-10-14 00:42:25 +0000954 // The watchpoint list is thread safe, no need to lock
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000955 sb_watchpoint.SetSP (target_sp->GetWatchpointList().GetByIndex(idx));
Johnny Chen096c2932011-09-26 22:40:50 +0000956 }
Johnny Chenecd4feb2011-10-14 00:42:25 +0000957 return sb_watchpoint;
Johnny Chen096c2932011-09-26 22:40:50 +0000958}
959
960bool
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000961SBTarget::DeleteWatchpoint (watch_id_t wp_id)
Johnny Chen096c2932011-09-26 22:40:50 +0000962{
963 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
964
965 bool result = false;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000966 TargetSP target_sp(GetSP());
967 if (target_sp)
Johnny Chen096c2932011-09-26 22:40:50 +0000968 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000969 Mutex::Locker api_locker (target_sp->GetAPIMutex());
970 result = target_sp->RemoveWatchpointByID (wp_id);
Johnny Chen096c2932011-09-26 22:40:50 +0000971 }
972
973 if (log)
974 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000975 log->Printf ("SBTarget(%p)::WatchpointDelete (wp_id=%d) => %i", target_sp.get(), (uint32_t) wp_id, result);
Johnny Chen096c2932011-09-26 22:40:50 +0000976 }
977
978 return result;
979}
980
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000981SBWatchpoint
982SBTarget::FindWatchpointByID (lldb::watch_id_t wp_id)
Johnny Chen096c2932011-09-26 22:40:50 +0000983{
984 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
985
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000986 SBWatchpoint sb_watchpoint;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000987 lldb::WatchpointSP watchpoint_sp;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000988 TargetSP target_sp(GetSP());
989 if (target_sp && wp_id != LLDB_INVALID_WATCH_ID)
Johnny Chen096c2932011-09-26 22:40:50 +0000990 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000991 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000992 watchpoint_sp = target_sp->GetWatchpointList().FindByID(wp_id);
993 sb_watchpoint.SetSP (watchpoint_sp);
Johnny Chen096c2932011-09-26 22:40:50 +0000994 }
995
996 if (log)
997 {
Johnny Chenecd4feb2011-10-14 00:42:25 +0000998 log->Printf ("SBTarget(%p)::FindWatchpointByID (bp_id=%d) => SBWatchpoint(%p)",
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000999 target_sp.get(), (uint32_t) wp_id, watchpoint_sp.get());
Johnny Chen096c2932011-09-26 22:40:50 +00001000 }
1001
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001002 return sb_watchpoint;
1003}
1004
1005lldb::SBWatchpoint
1006SBTarget::WatchAddress (lldb::addr_t addr, size_t size, bool read, bool write)
1007{
1008 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1009
1010 SBWatchpoint sb_watchpoint;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001011 lldb::WatchpointSP watchpoint_sp;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001012 TargetSP target_sp(GetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001013 if (target_sp && (read || write) && addr != LLDB_INVALID_ADDRESS && size > 0)
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001014 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001015 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001016 uint32_t watch_type = 0;
1017 if (read)
1018 watch_type |= LLDB_WATCH_TYPE_READ;
1019 if (write)
1020 watch_type |= LLDB_WATCH_TYPE_WRITE;
1021 watchpoint_sp = target_sp->CreateWatchpoint(addr, size, watch_type);
1022 sb_watchpoint.SetSP (watchpoint_sp);
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001023 }
1024
1025 if (log)
1026 {
1027 log->Printf ("SBTarget(%p)::WatchAddress (addr=0x%llx, 0x%u) => SBWatchpoint(%p)",
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001028 target_sp.get(), addr, (uint32_t) size, watchpoint_sp.get());
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001029 }
1030
1031 return sb_watchpoint;
Johnny Chen096c2932011-09-26 22:40:50 +00001032}
1033
1034bool
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001035SBTarget::EnableAllWatchpoints ()
Johnny Chen096c2932011-09-26 22:40:50 +00001036{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001037 TargetSP target_sp(GetSP());
1038 if (target_sp)
Johnny Chen096c2932011-09-26 22:40:50 +00001039 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001040 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1041 target_sp->EnableAllWatchpoints ();
Johnny Chen096c2932011-09-26 22:40:50 +00001042 return true;
1043 }
1044 return false;
1045}
1046
1047bool
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001048SBTarget::DisableAllWatchpoints ()
Johnny Chen096c2932011-09-26 22:40:50 +00001049{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001050 TargetSP target_sp(GetSP());
1051 if (target_sp)
Johnny Chen096c2932011-09-26 22:40:50 +00001052 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001053 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1054 target_sp->DisableAllWatchpoints ();
Johnny Chen096c2932011-09-26 22:40:50 +00001055 return true;
1056 }
1057 return false;
1058}
1059
1060bool
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001061SBTarget::DeleteAllWatchpoints ()
Johnny Chen096c2932011-09-26 22:40:50 +00001062{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001063 TargetSP target_sp(GetSP());
1064 if (target_sp)
Johnny Chen096c2932011-09-26 22:40:50 +00001065 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001066 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1067 target_sp->RemoveAllWatchpoints ();
Johnny Chen096c2932011-09-26 22:40:50 +00001068 return true;
1069 }
1070 return false;
1071}
1072
Chris Lattner24943d22010-06-08 16:52:24 +00001073
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001074lldb::SBModule
1075SBTarget::AddModule (const char *path,
1076 const char *triple,
1077 const char *uuid_cstr)
1078{
1079 lldb::SBModule sb_module;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001080 TargetSP target_sp(GetSP());
1081 if (target_sp)
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001082 {
1083 FileSpec module_file_spec;
1084 UUID module_uuid;
1085 ArchSpec module_arch;
1086
1087 if (path)
1088 module_file_spec.SetFile(path, false);
1089
1090 if (uuid_cstr)
1091 module_uuid.SetfromCString(uuid_cstr);
1092
1093 if (triple)
Greg Clayton0416bdf2012-01-30 09:04:36 +00001094 module_arch.SetTriple (triple, target_sp->GetPlatform ().get());
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001095
Greg Clayton0416bdf2012-01-30 09:04:36 +00001096 sb_module.SetSP(target_sp->GetSharedModule (module_file_spec,
1097 module_arch,
1098 uuid_cstr ? &module_uuid : NULL));
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001099 }
1100 return sb_module;
1101}
1102
1103bool
1104SBTarget::AddModule (lldb::SBModule &module)
1105{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001106 TargetSP target_sp(GetSP());
1107 if (target_sp)
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001108 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001109 target_sp->GetImages().AppendIfNeeded (module.GetSP());
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001110 return true;
1111 }
1112 return false;
1113}
1114
Chris Lattner24943d22010-06-08 16:52:24 +00001115uint32_t
1116SBTarget::GetNumModules () const
1117{
Greg Claytone005f2c2010-11-06 01:53:30 +00001118 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001119
Caroline Tice7826c882010-10-26 03:11:13 +00001120 uint32_t num = 0;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001121 TargetSP target_sp(GetSP());
1122 if (target_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +00001123 {
1124 // The module list is thread safe, no need to lock
Greg Clayton0416bdf2012-01-30 09:04:36 +00001125 num = target_sp->GetImages().GetSize();
Greg Claytonbdcda462010-12-20 20:49:23 +00001126 }
Caroline Tice7826c882010-10-26 03:11:13 +00001127
1128 if (log)
Greg Clayton0416bdf2012-01-30 09:04:36 +00001129 log->Printf ("SBTarget(%p)::GetNumModules () => %d", target_sp.get(), num);
Caroline Tice7826c882010-10-26 03:11:13 +00001130
1131 return num;
Chris Lattner24943d22010-06-08 16:52:24 +00001132}
1133
Greg Clayton43490d12010-07-30 20:12:55 +00001134void
1135SBTarget::Clear ()
1136{
Greg Claytone005f2c2010-11-06 01:53:30 +00001137 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001138
1139 if (log)
Greg Clayton3f5ee7f2010-10-29 04:59:35 +00001140 log->Printf ("SBTarget(%p)::Clear ()", m_opaque_sp.get());
Caroline Tice7826c882010-10-26 03:11:13 +00001141
Greg Clayton43490d12010-07-30 20:12:55 +00001142 m_opaque_sp.reset();
1143}
1144
1145
Chris Lattner24943d22010-06-08 16:52:24 +00001146SBModule
1147SBTarget::FindModule (const SBFileSpec &sb_file_spec)
1148{
1149 SBModule sb_module;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001150 TargetSP target_sp(GetSP());
1151 if (target_sp && sb_file_spec.IsValid())
Greg Claytonbdcda462010-12-20 20:49:23 +00001152 {
1153 // The module list is thread safe, no need to lock
Greg Clayton0416bdf2012-01-30 09:04:36 +00001154 sb_module.SetSP (target_sp->GetImages().FindFirstModuleForFileSpec (*sb_file_spec, NULL, NULL));
Greg Claytonbdcda462010-12-20 20:49:23 +00001155 }
Chris Lattner24943d22010-06-08 16:52:24 +00001156 return sb_module;
1157}
1158
Greg Clayton1b925202012-01-29 06:07:39 +00001159lldb::ByteOrder
1160SBTarget::GetByteOrder ()
1161{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001162 TargetSP target_sp(GetSP());
1163 if (target_sp)
1164 return target_sp->GetArchitecture().GetByteOrder();
Greg Clayton1b925202012-01-29 06:07:39 +00001165 return eByteOrderInvalid;
1166}
1167
1168const char *
1169SBTarget::GetTriple ()
1170{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001171 TargetSP target_sp(GetSP());
1172 if (target_sp)
Greg Clayton1b925202012-01-29 06:07:39 +00001173 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001174 std::string triple (target_sp->GetArchitecture().GetTriple().str());
Greg Clayton1b925202012-01-29 06:07:39 +00001175 // Unique the string so we don't run into ownership issues since
1176 // the const strings put the string into the string pool once and
1177 // the strings never comes out
1178 ConstString const_triple (triple.c_str());
1179 return const_triple.GetCString();
1180 }
1181 return NULL;
1182}
1183
1184uint32_t
1185SBTarget::GetAddressByteSize()
1186{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001187 TargetSP target_sp(GetSP());
1188 if (target_sp)
1189 return target_sp->GetArchitecture().GetAddressByteSize();
Greg Clayton1b925202012-01-29 06:07:39 +00001190 return sizeof(void*);
1191}
1192
1193
Chris Lattner24943d22010-06-08 16:52:24 +00001194SBModule
1195SBTarget::GetModuleAtIndex (uint32_t idx)
1196{
Greg Claytone005f2c2010-11-06 01:53:30 +00001197 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001198
Chris Lattner24943d22010-06-08 16:52:24 +00001199 SBModule sb_module;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001200 ModuleSP module_sp;
1201 TargetSP target_sp(GetSP());
1202 if (target_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +00001203 {
1204 // The module list is thread safe, no need to lock
Greg Clayton0416bdf2012-01-30 09:04:36 +00001205 module_sp = target_sp->GetImages().GetModuleAtIndex(idx);
1206 sb_module.SetSP (module_sp);
Greg Claytonbdcda462010-12-20 20:49:23 +00001207 }
Caroline Tice7826c882010-10-26 03:11:13 +00001208
1209 if (log)
1210 {
Greg Clayton49ce6822010-10-31 03:01:06 +00001211 log->Printf ("SBTarget(%p)::GetModuleAtIndex (idx=%d) => SBModule(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +00001212 target_sp.get(), idx, module_sp.get());
Caroline Tice7826c882010-10-26 03:11:13 +00001213 }
1214
Chris Lattner24943d22010-06-08 16:52:24 +00001215 return sb_module;
1216}
1217
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001218bool
1219SBTarget::RemoveModule (lldb::SBModule module)
1220{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001221 TargetSP target_sp(GetSP());
1222 if (target_sp)
1223 return target_sp->GetImages().Remove(module.GetSP());
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001224 return false;
1225}
1226
Chris Lattner24943d22010-06-08 16:52:24 +00001227
1228SBBroadcaster
1229SBTarget::GetBroadcaster () const
1230{
Greg Claytone005f2c2010-11-06 01:53:30 +00001231 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001232
Greg Clayton0416bdf2012-01-30 09:04:36 +00001233 TargetSP target_sp(GetSP());
1234 SBBroadcaster broadcaster(target_sp.get(), false);
Caroline Tice7826c882010-10-26 03:11:13 +00001235
1236 if (log)
Greg Clayton3f5ee7f2010-10-29 04:59:35 +00001237 log->Printf ("SBTarget(%p)::GetBroadcaster () => SBBroadcaster(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +00001238 target_sp.get(), broadcaster.get());
Caroline Tice7826c882010-10-26 03:11:13 +00001239
Chris Lattner24943d22010-06-08 16:52:24 +00001240 return broadcaster;
1241}
1242
Caroline Tice98f930f2010-09-20 05:20:02 +00001243bool
Caroline Tice7826c882010-10-26 03:11:13 +00001244SBTarget::GetDescription (SBStream &description, lldb::DescriptionLevel description_level)
Caroline Tice98f930f2010-09-20 05:20:02 +00001245{
Greg Clayton96154be2011-11-13 06:57:31 +00001246 Stream &strm = description.ref();
1247
Greg Clayton0416bdf2012-01-30 09:04:36 +00001248 TargetSP target_sp(GetSP());
1249 if (target_sp)
Caroline Ticee7a566e2010-09-20 16:21:41 +00001250 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001251 target_sp->Dump (&strm, description_level);
Caroline Tice7826c882010-10-26 03:11:13 +00001252 }
1253 else
Greg Clayton96154be2011-11-13 06:57:31 +00001254 strm.PutCString ("No value");
Caroline Tice7826c882010-10-26 03:11:13 +00001255
1256 return true;
1257}
1258
Greg Clayton7dd5c512012-02-06 01:44:54 +00001259lldb::SBSymbolContextList
1260SBTarget::FindFunctions (const char *name, uint32_t name_type_mask)
Greg Clayton4ed315f2011-06-21 01:34:41 +00001261{
Greg Clayton7dd5c512012-02-06 01:44:54 +00001262 lldb::SBSymbolContextList sb_sc_list;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001263 if (name && name[0])
Greg Clayton4ed315f2011-06-21 01:34:41 +00001264 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001265 TargetSP target_sp(GetSP());
1266 if (target_sp)
1267 {
1268 const bool symbols_ok = true;
Sean Callanan302d78c2012-02-10 22:52:19 +00001269 const bool inlines_ok = true;
Greg Clayton7dd5c512012-02-06 01:44:54 +00001270 const bool append = true;
1271 target_sp->GetImages().FindFunctions (ConstString(name),
1272 name_type_mask,
Sean Callanan302d78c2012-02-10 22:52:19 +00001273 symbols_ok,
1274 inlines_ok,
Greg Clayton7dd5c512012-02-06 01:44:54 +00001275 append,
1276 *sb_sc_list);
Greg Clayton0416bdf2012-01-30 09:04:36 +00001277 }
Greg Clayton4ed315f2011-06-21 01:34:41 +00001278 }
Greg Clayton7dd5c512012-02-06 01:44:54 +00001279 return sb_sc_list;
Greg Clayton4ed315f2011-06-21 01:34:41 +00001280}
1281
Enrico Granata979e20d2011-07-29 19:53:35 +00001282lldb::SBType
1283SBTarget::FindFirstType (const char* type)
1284{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001285 TargetSP target_sp(GetSP());
1286 if (type && target_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +00001287 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001288 size_t count = target_sp->GetImages().GetSize();
Enrico Granata979e20d2011-07-29 19:53:35 +00001289 for (size_t idx = 0; idx < count; idx++)
1290 {
1291 SBType found_at_idx = GetModuleAtIndex(idx).FindFirstType(type);
1292
1293 if (found_at_idx.IsValid())
1294 return found_at_idx;
1295 }
1296 }
1297 return SBType();
1298}
1299
1300lldb::SBTypeList
1301SBTarget::FindTypes (const char* type)
1302{
1303
1304 SBTypeList retval;
1305
Greg Clayton0416bdf2012-01-30 09:04:36 +00001306 TargetSP target_sp(GetSP());
1307 if (type && target_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +00001308 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001309 ModuleList& images = target_sp->GetImages();
Enrico Granata979e20d2011-07-29 19:53:35 +00001310 ConstString name_const(type);
1311 SymbolContext sc;
1312 TypeList type_list;
1313
1314 uint32_t num_matches = images.FindTypes(sc,
1315 name_const,
1316 true,
1317 UINT32_MAX,
1318 type_list);
1319
1320 for (size_t idx = 0; idx < num_matches; idx++)
1321 {
Greg Clayton0fb0bcc2011-08-03 22:57:10 +00001322 TypeSP type_sp (type_list.GetTypeAtIndex(idx));
1323 if (type_sp)
1324 retval.Append(SBType(type_sp));
Enrico Granata979e20d2011-07-29 19:53:35 +00001325 }
1326 }
1327 return retval;
1328}
1329
Greg Clayton917c0002011-06-29 22:09:02 +00001330SBValueList
1331SBTarget::FindGlobalVariables (const char *name, uint32_t max_matches)
1332{
1333 SBValueList sb_value_list;
1334
Greg Clayton0416bdf2012-01-30 09:04:36 +00001335 TargetSP target_sp(GetSP());
1336 if (name && target_sp)
Greg Clayton917c0002011-06-29 22:09:02 +00001337 {
1338 VariableList variable_list;
1339 const bool append = true;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001340 const uint32_t match_count = target_sp->GetImages().FindGlobalVariables (ConstString (name),
1341 append,
1342 max_matches,
1343 variable_list);
Greg Clayton917c0002011-06-29 22:09:02 +00001344
1345 if (match_count > 0)
1346 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001347 ExecutionContextScope *exe_scope = target_sp->GetProcessSP().get();
Greg Clayton917c0002011-06-29 22:09:02 +00001348 if (exe_scope == NULL)
Greg Clayton0416bdf2012-01-30 09:04:36 +00001349 exe_scope = target_sp.get();
Greg Clayton917c0002011-06-29 22:09:02 +00001350 ValueObjectList &value_object_list = sb_value_list.ref();
1351 for (uint32_t i=0; i<match_count; ++i)
1352 {
1353 lldb::ValueObjectSP valobj_sp (ValueObjectVariable::Create (exe_scope, variable_list.GetVariableAtIndex(i)));
1354 if (valobj_sp)
1355 value_object_list.Append(valobj_sp);
1356 }
1357 }
1358 }
1359
1360 return sb_value_list;
1361}
1362
Jim Inghamcc637462011-09-13 00:29:56 +00001363SBSourceManager
1364SBTarget::GetSourceManager()
1365{
1366 SBSourceManager source_manager (*this);
1367 return source_manager;
1368}
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001369
Sean Callananef1f6902011-12-14 23:49:37 +00001370lldb::SBInstructionList
1371SBTarget::GetInstructions (lldb::SBAddress base_addr, const void *buf, size_t size)
1372{
1373 SBInstructionList sb_instructions;
1374
Greg Clayton0416bdf2012-01-30 09:04:36 +00001375 TargetSP target_sp(GetSP());
1376 if (target_sp)
Sean Callananef1f6902011-12-14 23:49:37 +00001377 {
1378 Address addr;
1379
1380 if (base_addr.get())
1381 addr = *base_addr.get();
1382
Greg Clayton0416bdf2012-01-30 09:04:36 +00001383 sb_instructions.SetDisassembler (Disassembler::DisassembleBytes (target_sp->GetArchitecture(),
Sean Callananef1f6902011-12-14 23:49:37 +00001384 NULL,
1385 addr,
1386 buf,
1387 size));
1388 }
1389
1390 return sb_instructions;
1391}
1392
1393lldb::SBInstructionList
1394SBTarget::GetInstructions (lldb::addr_t base_addr, const void *buf, size_t size)
1395{
1396 return GetInstructions (ResolveLoadAddress(base_addr), buf, size);
1397}
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001398
1399SBError
1400SBTarget::SetSectionLoadAddress (lldb::SBSection section,
1401 lldb::addr_t section_base_addr)
1402{
1403 SBError sb_error;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001404 TargetSP target_sp(GetSP());
1405 if (target_sp)
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001406 {
1407 if (!section.IsValid())
1408 {
1409 sb_error.SetErrorStringWithFormat ("invalid section");
1410 }
1411 else
1412 {
Greg Clayton3508c382012-02-24 01:59:29 +00001413 target_sp->GetSectionLoadList().SetSectionLoadAddress (section.GetSP().get(), section_base_addr);
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001414 }
1415 }
1416 else
1417 {
1418 sb_error.SetErrorStringWithFormat ("invalid target");
1419 }
1420 return sb_error;
1421}
1422
1423SBError
1424SBTarget::ClearSectionLoadAddress (lldb::SBSection section)
1425{
1426 SBError sb_error;
1427
Greg Clayton0416bdf2012-01-30 09:04:36 +00001428 TargetSP target_sp(GetSP());
1429 if (target_sp)
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001430 {
1431 if (!section.IsValid())
1432 {
1433 sb_error.SetErrorStringWithFormat ("invalid section");
1434 }
1435 else
1436 {
Greg Clayton3508c382012-02-24 01:59:29 +00001437 target_sp->GetSectionLoadList().SetSectionUnloaded (section.GetSP().get());
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001438 }
1439 }
1440 else
1441 {
1442 sb_error.SetErrorStringWithFormat ("invalid target");
1443 }
1444 return sb_error;
1445}
1446
1447SBError
1448SBTarget::SetModuleLoadAddress (lldb::SBModule module, int64_t slide_offset)
1449{
1450 SBError sb_error;
1451
1452 char path[PATH_MAX];
Greg Clayton0416bdf2012-01-30 09:04:36 +00001453 TargetSP target_sp(GetSP());
1454 if (target_sp)
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001455 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001456 ModuleSP module_sp (module.GetSP());
1457 if (module_sp)
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001458 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001459 ObjectFile *objfile = module_sp->GetObjectFile();
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001460 if (objfile)
1461 {
1462 SectionList *section_list = objfile->GetSectionList();
1463 if (section_list)
1464 {
1465 const size_t num_sections = section_list->GetSize();
1466 for (size_t sect_idx = 0; sect_idx < num_sections; ++sect_idx)
1467 {
1468 SectionSP section_sp (section_list->GetSectionAtIndex(sect_idx));
1469 if (section_sp)
Greg Clayton0416bdf2012-01-30 09:04:36 +00001470 target_sp->GetSectionLoadList().SetSectionLoadAddress (section_sp.get(), section_sp->GetFileAddress() + slide_offset);
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001471 }
1472 }
1473 else
1474 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001475 module_sp->GetFileSpec().GetPath (path, sizeof(path));
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001476 sb_error.SetErrorStringWithFormat ("no sections in object file '%s'", path);
1477 }
1478 }
1479 else
1480 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001481 module_sp->GetFileSpec().GetPath (path, sizeof(path));
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001482 sb_error.SetErrorStringWithFormat ("no object file for module '%s'", path);
1483 }
1484 }
Greg Clayton0416bdf2012-01-30 09:04:36 +00001485 else
1486 {
1487 sb_error.SetErrorStringWithFormat ("invalid module");
1488 }
1489
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001490 }
1491 else
1492 {
1493 sb_error.SetErrorStringWithFormat ("invalid target");
1494 }
1495 return sb_error;
1496}
1497
1498SBError
1499SBTarget::ClearModuleLoadAddress (lldb::SBModule module)
1500{
1501 SBError sb_error;
1502
1503 char path[PATH_MAX];
Greg Clayton0416bdf2012-01-30 09:04:36 +00001504 TargetSP target_sp(GetSP());
1505 if (target_sp)
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001506 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001507 ModuleSP module_sp (module.GetSP());
1508 if (module_sp)
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001509 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001510 ObjectFile *objfile = module_sp->GetObjectFile();
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001511 if (objfile)
1512 {
1513 SectionList *section_list = objfile->GetSectionList();
1514 if (section_list)
1515 {
1516 const size_t num_sections = section_list->GetSize();
1517 for (size_t sect_idx = 0; sect_idx < num_sections; ++sect_idx)
1518 {
1519 SectionSP section_sp (section_list->GetSectionAtIndex(sect_idx));
1520 if (section_sp)
Greg Clayton0416bdf2012-01-30 09:04:36 +00001521 target_sp->GetSectionLoadList().SetSectionUnloaded (section_sp.get());
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001522 }
1523 }
1524 else
1525 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001526 module_sp->GetFileSpec().GetPath (path, sizeof(path));
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001527 sb_error.SetErrorStringWithFormat ("no sections in object file '%s'", path);
1528 }
1529 }
1530 else
1531 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001532 module_sp->GetFileSpec().GetPath (path, sizeof(path));
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001533 sb_error.SetErrorStringWithFormat ("no object file for module '%s'", path);
1534 }
1535 }
Greg Clayton0416bdf2012-01-30 09:04:36 +00001536 else
1537 {
1538 sb_error.SetErrorStringWithFormat ("invalid module");
1539 }
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001540 }
1541 else
1542 {
1543 sb_error.SetErrorStringWithFormat ("invalid target");
1544 }
1545 return sb_error;
1546}
1547
1548