blob: 7fdfb3474298c683e54bbe789695d7707f789d8d [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
560 addr.SetSection(NULL);
561 addr.SetOffset(vm_addr);
562 return sb_addr;
Greg Claytonea49cc72010-12-12 19:25:26 +0000563}
564
Greg Claytonafb81862011-03-02 21:34:46 +0000565SBSymbolContext
566SBTarget::ResolveSymbolContextForAddress (const SBAddress& addr, uint32_t resolve_scope)
567{
568 SBSymbolContext sc;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000569 if (addr.IsValid())
570 {
571 TargetSP target_sp(GetSP());
572 if (target_sp)
573 target_sp->GetImages().ResolveSymbolContextForAddress (addr.ref(), resolve_scope, sc.ref());
574 }
Greg Claytonafb81862011-03-02 21:34:46 +0000575 return sc;
576}
577
578
Chris Lattner24943d22010-06-08 16:52:24 +0000579SBBreakpoint
580SBTarget::BreakpointCreateByLocation (const char *file, uint32_t line)
581{
Greg Claytond6d806c2010-11-08 00:28:40 +0000582 return SBBreakpoint(BreakpointCreateByLocation (SBFileSpec (file, false), line));
Chris Lattner24943d22010-06-08 16:52:24 +0000583}
584
585SBBreakpoint
586SBTarget::BreakpointCreateByLocation (const SBFileSpec &sb_file_spec, uint32_t line)
587{
Greg Claytone005f2c2010-11-06 01:53:30 +0000588 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000589
Chris Lattner24943d22010-06-08 16:52:24 +0000590 SBBreakpoint sb_bp;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000591 TargetSP target_sp(GetSP());
592 if (target_sp && line != 0)
Greg Claytonbdcda462010-12-20 20:49:23 +0000593 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000594 Mutex::Locker api_locker (target_sp->GetAPIMutex());
595 *sb_bp = target_sp->CreateBreakpoint (NULL, *sb_file_spec, line, true, false);
Greg Claytonbdcda462010-12-20 20:49:23 +0000596 }
Caroline Tice7826c882010-10-26 03:11:13 +0000597
598 if (log)
599 {
600 SBStream sstr;
601 sb_bp.GetDescription (sstr);
Greg Clayton49ce6822010-10-31 03:01:06 +0000602 char path[PATH_MAX];
603 sb_file_spec->GetPath (path, sizeof(path));
604 log->Printf ("SBTarget(%p)::BreakpointCreateByLocation ( %s:%u ) => SBBreakpoint(%p): %s",
Greg Clayton0416bdf2012-01-30 09:04:36 +0000605 target_sp.get(),
Greg Clayton49ce6822010-10-31 03:01:06 +0000606 path,
Greg Claytona66ba462010-10-30 04:51:46 +0000607 line,
Greg Clayton49ce6822010-10-31 03:01:06 +0000608 sb_bp.get(),
Caroline Tice7826c882010-10-26 03:11:13 +0000609 sstr.GetData());
610 }
611
Chris Lattner24943d22010-06-08 16:52:24 +0000612 return sb_bp;
613}
614
615SBBreakpoint
616SBTarget::BreakpointCreateByName (const char *symbol_name, const char *module_name)
617{
Greg Claytone005f2c2010-11-06 01:53:30 +0000618 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000619
Chris Lattner24943d22010-06-08 16:52:24 +0000620 SBBreakpoint sb_bp;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000621 TargetSP target_sp(GetSP());
622 if (target_sp.get())
Chris Lattner24943d22010-06-08 16:52:24 +0000623 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000624 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Chris Lattner24943d22010-06-08 16:52:24 +0000625 if (module_name && module_name[0])
626 {
Jim Ingham03c8ee52011-09-21 01:17:13 +0000627 FileSpecList module_spec_list;
628 module_spec_list.Append (FileSpec (module_name, false));
Greg Clayton0416bdf2012-01-30 09:04:36 +0000629 *sb_bp = target_sp->CreateBreakpoint (&module_spec_list, NULL, symbol_name, eFunctionNameTypeAuto, false);
Chris Lattner24943d22010-06-08 16:52:24 +0000630 }
631 else
632 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000633 *sb_bp = target_sp->CreateBreakpoint (NULL, NULL, symbol_name, eFunctionNameTypeAuto, false);
Chris Lattner24943d22010-06-08 16:52:24 +0000634 }
635 }
Caroline Tice7826c882010-10-26 03:11:13 +0000636
637 if (log)
638 {
Greg Clayton49ce6822010-10-31 03:01:06 +0000639 log->Printf ("SBTarget(%p)::BreakpointCreateByName (symbol=\"%s\", module=\"%s\") => SBBreakpoint(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +0000640 target_sp.get(), symbol_name, module_name, sb_bp.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000641 }
642
Chris Lattner24943d22010-06-08 16:52:24 +0000643 return sb_bp;
644}
645
Jim Inghamd6d47972011-09-23 00:54:11 +0000646lldb::SBBreakpoint
647SBTarget::BreakpointCreateByName (const char *symbol_name,
648 const SBFileSpecList &module_list,
649 const SBFileSpecList &comp_unit_list)
650{
Jim Ingham1fb8a2d2011-10-11 01:18:55 +0000651 uint32_t name_type_mask = eFunctionNameTypeAuto;
652 return BreakpointCreateByName (symbol_name, name_type_mask, module_list, comp_unit_list);
653}
654
655lldb::SBBreakpoint
656SBTarget::BreakpointCreateByName (const char *symbol_name,
657 uint32_t name_type_mask,
658 const SBFileSpecList &module_list,
659 const SBFileSpecList &comp_unit_list)
660{
Jim Inghamd6d47972011-09-23 00:54:11 +0000661 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
662
663 SBBreakpoint sb_bp;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000664 TargetSP target_sp(GetSP());
665 if (target_sp && symbol_name && symbol_name[0])
Jim Inghamd6d47972011-09-23 00:54:11 +0000666 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000667 Mutex::Locker api_locker (target_sp->GetAPIMutex());
668 *sb_bp = target_sp->CreateBreakpoint (module_list.get(),
Jim Inghamd6d47972011-09-23 00:54:11 +0000669 comp_unit_list.get(),
670 symbol_name,
Jim Ingham1fb8a2d2011-10-11 01:18:55 +0000671 name_type_mask,
Jim Inghamd6d47972011-09-23 00:54:11 +0000672 false);
673 }
674
675 if (log)
676 {
Jim Ingham1fb8a2d2011-10-11 01:18:55 +0000677 log->Printf ("SBTarget(%p)::BreakpointCreateByName (symbol=\"%s\", name_type: %d) => SBBreakpoint(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +0000678 target_sp.get(), symbol_name, name_type_mask, sb_bp.get());
Jim Inghamd6d47972011-09-23 00:54:11 +0000679 }
680
681 return sb_bp;
682}
683
684
Chris Lattner24943d22010-06-08 16:52:24 +0000685SBBreakpoint
686SBTarget::BreakpointCreateByRegex (const char *symbol_name_regex, const char *module_name)
687{
Greg Claytone005f2c2010-11-06 01:53:30 +0000688 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000689
Chris Lattner24943d22010-06-08 16:52:24 +0000690 SBBreakpoint sb_bp;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000691 TargetSP target_sp(GetSP());
692 if (target_sp && symbol_name_regex && symbol_name_regex[0])
Chris Lattner24943d22010-06-08 16:52:24 +0000693 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000694 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Chris Lattner24943d22010-06-08 16:52:24 +0000695 RegularExpression regexp(symbol_name_regex);
696
697 if (module_name && module_name[0])
698 {
Jim Ingham03c8ee52011-09-21 01:17:13 +0000699 FileSpecList module_spec_list;
700 module_spec_list.Append (FileSpec (module_name, false));
Chris Lattner24943d22010-06-08 16:52:24 +0000701
Greg Clayton0416bdf2012-01-30 09:04:36 +0000702 *sb_bp = target_sp->CreateFuncRegexBreakpoint (&module_spec_list, NULL, regexp, false);
Chris Lattner24943d22010-06-08 16:52:24 +0000703 }
704 else
705 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000706 *sb_bp = target_sp->CreateFuncRegexBreakpoint (NULL, NULL, regexp, false);
Chris Lattner24943d22010-06-08 16:52:24 +0000707 }
708 }
Caroline Tice7826c882010-10-26 03:11:13 +0000709
710 if (log)
711 {
Greg Clayton49ce6822010-10-31 03:01:06 +0000712 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (symbol_regex=\"%s\", module_name=\"%s\") => SBBreakpoint(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +0000713 target_sp.get(), symbol_name_regex, module_name, sb_bp.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000714 }
715
Chris Lattner24943d22010-06-08 16:52:24 +0000716 return sb_bp;
717}
718
Jim Inghamd6d47972011-09-23 00:54:11 +0000719lldb::SBBreakpoint
720SBTarget::BreakpointCreateByRegex (const char *symbol_name_regex,
721 const SBFileSpecList &module_list,
722 const SBFileSpecList &comp_unit_list)
723{
724 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Chris Lattner24943d22010-06-08 16:52:24 +0000725
Jim Inghamd6d47972011-09-23 00:54:11 +0000726 SBBreakpoint sb_bp;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000727 TargetSP target_sp(GetSP());
728 if (target_sp && symbol_name_regex && symbol_name_regex[0])
Jim Inghamd6d47972011-09-23 00:54:11 +0000729 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000730 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Jim Inghamd6d47972011-09-23 00:54:11 +0000731 RegularExpression regexp(symbol_name_regex);
732
Greg Clayton0416bdf2012-01-30 09:04:36 +0000733 *sb_bp = target_sp->CreateFuncRegexBreakpoint (module_list.get(), comp_unit_list.get(), regexp, false);
Jim Inghamd6d47972011-09-23 00:54:11 +0000734 }
735
736 if (log)
737 {
738 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (symbol_regex=\"%s\") => SBBreakpoint(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +0000739 target_sp.get(), symbol_name_regex, sb_bp.get());
Jim Inghamd6d47972011-09-23 00:54:11 +0000740 }
741
742 return sb_bp;
743}
Chris Lattner24943d22010-06-08 16:52:24 +0000744
745SBBreakpoint
746SBTarget::BreakpointCreateByAddress (addr_t address)
747{
Greg Claytone005f2c2010-11-06 01:53:30 +0000748 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000749
Chris Lattner24943d22010-06-08 16:52:24 +0000750 SBBreakpoint sb_bp;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000751 TargetSP target_sp(GetSP());
752 if (target_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000753 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000754 Mutex::Locker api_locker (target_sp->GetAPIMutex());
755 *sb_bp = target_sp->CreateBreakpoint (address, false);
Greg Claytonbdcda462010-12-20 20:49:23 +0000756 }
Caroline Tice7826c882010-10-26 03:11:13 +0000757
758 if (log)
759 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000760 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 +0000761 }
762
Chris Lattner24943d22010-06-08 16:52:24 +0000763 return sb_bp;
764}
765
Jim Ingham03c8ee52011-09-21 01:17:13 +0000766lldb::SBBreakpoint
767SBTarget::BreakpointCreateBySourceRegex (const char *source_regex, const lldb::SBFileSpec &source_file, const char *module_name)
768{
769 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
770
771 SBBreakpoint sb_bp;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000772 TargetSP target_sp(GetSP());
773 if (target_sp && source_regex && source_regex[0])
Jim Ingham03c8ee52011-09-21 01:17:13 +0000774 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000775 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Jim Ingham03c8ee52011-09-21 01:17:13 +0000776 RegularExpression regexp(source_regex);
Jim Inghamd6d47972011-09-23 00:54:11 +0000777 FileSpecList source_file_spec_list;
778 source_file_spec_list.Append (source_file.ref());
Jim Ingham03c8ee52011-09-21 01:17:13 +0000779
780 if (module_name && module_name[0])
781 {
782 FileSpecList module_spec_list;
783 module_spec_list.Append (FileSpec (module_name, false));
784
Greg Clayton0416bdf2012-01-30 09:04:36 +0000785 *sb_bp = target_sp->CreateSourceRegexBreakpoint (&module_spec_list, &source_file_spec_list, regexp, false);
Jim Ingham03c8ee52011-09-21 01:17:13 +0000786 }
787 else
788 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000789 *sb_bp = target_sp->CreateSourceRegexBreakpoint (NULL, &source_file_spec_list, regexp, false);
Jim Ingham03c8ee52011-09-21 01:17:13 +0000790 }
791 }
792
793 if (log)
794 {
795 char path[PATH_MAX];
796 source_file->GetPath (path, sizeof(path));
797 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (source_regex=\"%s\", file=\"%s\", module_name=\"%s\") => SBBreakpoint(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +0000798 target_sp.get(), source_regex, path, module_name, sb_bp.get());
Jim Ingham03c8ee52011-09-21 01:17:13 +0000799 }
800
801 return sb_bp;
802}
803
Jim Inghamd6d47972011-09-23 00:54:11 +0000804lldb::SBBreakpoint
805SBTarget::BreakpointCreateBySourceRegex (const char *source_regex,
806 const SBFileSpecList &module_list,
807 const lldb::SBFileSpecList &source_file_list)
808{
809 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
810
811 SBBreakpoint sb_bp;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000812 TargetSP target_sp(GetSP());
813 if (target_sp && source_regex && source_regex[0])
Jim Inghamd6d47972011-09-23 00:54:11 +0000814 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000815 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Jim Inghamd6d47972011-09-23 00:54:11 +0000816 RegularExpression regexp(source_regex);
Greg Clayton0416bdf2012-01-30 09:04:36 +0000817 *sb_bp = target_sp->CreateSourceRegexBreakpoint (module_list.get(), source_file_list.get(), regexp, false);
Jim Inghamd6d47972011-09-23 00:54:11 +0000818 }
819
820 if (log)
821 {
822 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (source_regex=\"%s\") => SBBreakpoint(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +0000823 target_sp.get(), source_regex, sb_bp.get());
Jim Inghamd6d47972011-09-23 00:54:11 +0000824 }
825
826 return sb_bp;
827}
Jim Ingham03c8ee52011-09-21 01:17:13 +0000828
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000829uint32_t
830SBTarget::GetNumBreakpoints () const
831{
Greg Clayton0416bdf2012-01-30 09:04:36 +0000832 TargetSP target_sp(GetSP());
833 if (target_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000834 {
835 // The breakpoint list is thread safe, no need to lock
Greg Clayton0416bdf2012-01-30 09:04:36 +0000836 return target_sp->GetBreakpointList().GetSize();
Greg Claytonbdcda462010-12-20 20:49:23 +0000837 }
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000838 return 0;
839}
840
841SBBreakpoint
842SBTarget::GetBreakpointAtIndex (uint32_t idx) const
843{
844 SBBreakpoint sb_breakpoint;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000845 TargetSP target_sp(GetSP());
846 if (target_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000847 {
848 // The breakpoint list is thread safe, no need to lock
Greg Clayton0416bdf2012-01-30 09:04:36 +0000849 *sb_breakpoint = target_sp->GetBreakpointList().GetBreakpointAtIndex(idx);
Greg Claytonbdcda462010-12-20 20:49:23 +0000850 }
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000851 return sb_breakpoint;
852}
Chris Lattner24943d22010-06-08 16:52:24 +0000853
854bool
855SBTarget::BreakpointDelete (break_id_t bp_id)
856{
Greg Claytone005f2c2010-11-06 01:53:30 +0000857 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000858
Caroline Tice7826c882010-10-26 03:11:13 +0000859 bool result = false;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000860 TargetSP target_sp(GetSP());
861 if (target_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000862 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000863 Mutex::Locker api_locker (target_sp->GetAPIMutex());
864 result = target_sp->RemoveBreakpointByID (bp_id);
Greg Claytonbdcda462010-12-20 20:49:23 +0000865 }
Caroline Tice7826c882010-10-26 03:11:13 +0000866
867 if (log)
868 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000869 log->Printf ("SBTarget(%p)::BreakpointDelete (bp_id=%d) => %i", target_sp.get(), (uint32_t) bp_id, result);
Caroline Tice7826c882010-10-26 03:11:13 +0000870 }
871
872 return result;
Chris Lattner24943d22010-06-08 16:52:24 +0000873}
874
Johnny Chen096c2932011-09-26 22:40:50 +0000875SBBreakpoint
876SBTarget::FindBreakpointByID (break_id_t bp_id)
877{
878 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
879
880 SBBreakpoint sb_breakpoint;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000881 TargetSP target_sp(GetSP());
882 if (target_sp && bp_id != LLDB_INVALID_BREAK_ID)
Johnny Chen096c2932011-09-26 22:40:50 +0000883 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000884 Mutex::Locker api_locker (target_sp->GetAPIMutex());
885 *sb_breakpoint = target_sp->GetBreakpointByID (bp_id);
Johnny Chen096c2932011-09-26 22:40:50 +0000886 }
887
888 if (log)
889 {
890 log->Printf ("SBTarget(%p)::FindBreakpointByID (bp_id=%d) => SBBreakpoint(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +0000891 target_sp.get(), (uint32_t) bp_id, sb_breakpoint.get());
Johnny Chen096c2932011-09-26 22:40:50 +0000892 }
893
894 return sb_breakpoint;
895}
896
Chris Lattner24943d22010-06-08 16:52:24 +0000897bool
898SBTarget::EnableAllBreakpoints ()
899{
Greg Clayton0416bdf2012-01-30 09:04:36 +0000900 TargetSP target_sp(GetSP());
901 if (target_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000902 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000903 Mutex::Locker api_locker (target_sp->GetAPIMutex());
904 target_sp->EnableAllBreakpoints ();
Chris Lattner24943d22010-06-08 16:52:24 +0000905 return true;
906 }
907 return false;
908}
909
910bool
911SBTarget::DisableAllBreakpoints ()
912{
Greg Clayton0416bdf2012-01-30 09:04:36 +0000913 TargetSP target_sp(GetSP());
914 if (target_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000915 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000916 Mutex::Locker api_locker (target_sp->GetAPIMutex());
917 target_sp->DisableAllBreakpoints ();
Chris Lattner24943d22010-06-08 16:52:24 +0000918 return true;
919 }
920 return false;
921}
922
923bool
924SBTarget::DeleteAllBreakpoints ()
925{
Greg Clayton0416bdf2012-01-30 09:04:36 +0000926 TargetSP target_sp(GetSP());
927 if (target_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000928 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000929 Mutex::Locker api_locker (target_sp->GetAPIMutex());
930 target_sp->RemoveAllBreakpoints ();
Chris Lattner24943d22010-06-08 16:52:24 +0000931 return true;
932 }
933 return false;
934}
935
Johnny Chen096c2932011-09-26 22:40:50 +0000936uint32_t
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000937SBTarget::GetNumWatchpoints () const
Johnny Chen096c2932011-09-26 22:40:50 +0000938{
Greg Clayton0416bdf2012-01-30 09:04:36 +0000939 TargetSP target_sp(GetSP());
940 if (target_sp)
Johnny Chen096c2932011-09-26 22:40:50 +0000941 {
Johnny Chenecd4feb2011-10-14 00:42:25 +0000942 // The watchpoint list is thread safe, no need to lock
Greg Clayton0416bdf2012-01-30 09:04:36 +0000943 return target_sp->GetWatchpointList().GetSize();
Johnny Chen096c2932011-09-26 22:40:50 +0000944 }
945 return 0;
946}
947
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000948SBWatchpoint
949SBTarget::GetWatchpointAtIndex (uint32_t idx) const
Johnny Chen5eb54bb2011-09-27 20:29:45 +0000950{
Johnny Chenecd4feb2011-10-14 00:42:25 +0000951 SBWatchpoint sb_watchpoint;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000952 TargetSP target_sp(GetSP());
953 if (target_sp)
Johnny Chen096c2932011-09-26 22:40:50 +0000954 {
Johnny Chenecd4feb2011-10-14 00:42:25 +0000955 // The watchpoint list is thread safe, no need to lock
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000956 sb_watchpoint.SetSP (target_sp->GetWatchpointList().GetByIndex(idx));
Johnny Chen096c2932011-09-26 22:40:50 +0000957 }
Johnny Chenecd4feb2011-10-14 00:42:25 +0000958 return sb_watchpoint;
Johnny Chen096c2932011-09-26 22:40:50 +0000959}
960
961bool
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000962SBTarget::DeleteWatchpoint (watch_id_t wp_id)
Johnny Chen096c2932011-09-26 22:40:50 +0000963{
964 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
965
966 bool result = false;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000967 TargetSP target_sp(GetSP());
968 if (target_sp)
Johnny Chen096c2932011-09-26 22:40:50 +0000969 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000970 Mutex::Locker api_locker (target_sp->GetAPIMutex());
971 result = target_sp->RemoveWatchpointByID (wp_id);
Johnny Chen096c2932011-09-26 22:40:50 +0000972 }
973
974 if (log)
975 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000976 log->Printf ("SBTarget(%p)::WatchpointDelete (wp_id=%d) => %i", target_sp.get(), (uint32_t) wp_id, result);
Johnny Chen096c2932011-09-26 22:40:50 +0000977 }
978
979 return result;
980}
981
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000982SBWatchpoint
983SBTarget::FindWatchpointByID (lldb::watch_id_t wp_id)
Johnny Chen096c2932011-09-26 22:40:50 +0000984{
985 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
986
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000987 SBWatchpoint sb_watchpoint;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000988 lldb::WatchpointSP watchpoint_sp;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000989 TargetSP target_sp(GetSP());
990 if (target_sp && wp_id != LLDB_INVALID_WATCH_ID)
Johnny Chen096c2932011-09-26 22:40:50 +0000991 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000992 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000993 watchpoint_sp = target_sp->GetWatchpointList().FindByID(wp_id);
994 sb_watchpoint.SetSP (watchpoint_sp);
Johnny Chen096c2932011-09-26 22:40:50 +0000995 }
996
997 if (log)
998 {
Johnny Chenecd4feb2011-10-14 00:42:25 +0000999 log->Printf ("SBTarget(%p)::FindWatchpointByID (bp_id=%d) => SBWatchpoint(%p)",
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001000 target_sp.get(), (uint32_t) wp_id, watchpoint_sp.get());
Johnny Chen096c2932011-09-26 22:40:50 +00001001 }
1002
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001003 return sb_watchpoint;
1004}
1005
1006lldb::SBWatchpoint
1007SBTarget::WatchAddress (lldb::addr_t addr, size_t size, bool read, bool write)
1008{
1009 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1010
1011 SBWatchpoint sb_watchpoint;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001012 lldb::WatchpointSP watchpoint_sp;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001013 TargetSP target_sp(GetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001014 if (target_sp && (read || write) && addr != LLDB_INVALID_ADDRESS && size > 0)
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001015 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001016 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001017 uint32_t watch_type = 0;
1018 if (read)
1019 watch_type |= LLDB_WATCH_TYPE_READ;
1020 if (write)
1021 watch_type |= LLDB_WATCH_TYPE_WRITE;
1022 watchpoint_sp = target_sp->CreateWatchpoint(addr, size, watch_type);
1023 sb_watchpoint.SetSP (watchpoint_sp);
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001024 }
1025
1026 if (log)
1027 {
1028 log->Printf ("SBTarget(%p)::WatchAddress (addr=0x%llx, 0x%u) => SBWatchpoint(%p)",
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001029 target_sp.get(), addr, (uint32_t) size, watchpoint_sp.get());
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001030 }
1031
1032 return sb_watchpoint;
Johnny Chen096c2932011-09-26 22:40:50 +00001033}
1034
1035bool
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001036SBTarget::EnableAllWatchpoints ()
Johnny Chen096c2932011-09-26 22:40:50 +00001037{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001038 TargetSP target_sp(GetSP());
1039 if (target_sp)
Johnny Chen096c2932011-09-26 22:40:50 +00001040 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001041 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1042 target_sp->EnableAllWatchpoints ();
Johnny Chen096c2932011-09-26 22:40:50 +00001043 return true;
1044 }
1045 return false;
1046}
1047
1048bool
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001049SBTarget::DisableAllWatchpoints ()
Johnny Chen096c2932011-09-26 22:40:50 +00001050{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001051 TargetSP target_sp(GetSP());
1052 if (target_sp)
Johnny Chen096c2932011-09-26 22:40:50 +00001053 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001054 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1055 target_sp->DisableAllWatchpoints ();
Johnny Chen096c2932011-09-26 22:40:50 +00001056 return true;
1057 }
1058 return false;
1059}
1060
1061bool
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001062SBTarget::DeleteAllWatchpoints ()
Johnny Chen096c2932011-09-26 22:40:50 +00001063{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001064 TargetSP target_sp(GetSP());
1065 if (target_sp)
Johnny Chen096c2932011-09-26 22:40:50 +00001066 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001067 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1068 target_sp->RemoveAllWatchpoints ();
Johnny Chen096c2932011-09-26 22:40:50 +00001069 return true;
1070 }
1071 return false;
1072}
1073
Chris Lattner24943d22010-06-08 16:52:24 +00001074
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001075lldb::SBModule
1076SBTarget::AddModule (const char *path,
1077 const char *triple,
1078 const char *uuid_cstr)
1079{
1080 lldb::SBModule sb_module;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001081 TargetSP target_sp(GetSP());
1082 if (target_sp)
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001083 {
1084 FileSpec module_file_spec;
1085 UUID module_uuid;
1086 ArchSpec module_arch;
1087
1088 if (path)
1089 module_file_spec.SetFile(path, false);
1090
1091 if (uuid_cstr)
1092 module_uuid.SetfromCString(uuid_cstr);
1093
1094 if (triple)
Greg Clayton0416bdf2012-01-30 09:04:36 +00001095 module_arch.SetTriple (triple, target_sp->GetPlatform ().get());
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001096
Greg Clayton0416bdf2012-01-30 09:04:36 +00001097 sb_module.SetSP(target_sp->GetSharedModule (module_file_spec,
1098 module_arch,
1099 uuid_cstr ? &module_uuid : NULL));
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001100 }
1101 return sb_module;
1102}
1103
1104bool
1105SBTarget::AddModule (lldb::SBModule &module)
1106{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001107 TargetSP target_sp(GetSP());
1108 if (target_sp)
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001109 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001110 target_sp->GetImages().AppendIfNeeded (module.GetSP());
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001111 return true;
1112 }
1113 return false;
1114}
1115
Chris Lattner24943d22010-06-08 16:52:24 +00001116uint32_t
1117SBTarget::GetNumModules () const
1118{
Greg Claytone005f2c2010-11-06 01:53:30 +00001119 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001120
Caroline Tice7826c882010-10-26 03:11:13 +00001121 uint32_t num = 0;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001122 TargetSP target_sp(GetSP());
1123 if (target_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +00001124 {
1125 // The module list is thread safe, no need to lock
Greg Clayton0416bdf2012-01-30 09:04:36 +00001126 num = target_sp->GetImages().GetSize();
Greg Claytonbdcda462010-12-20 20:49:23 +00001127 }
Caroline Tice7826c882010-10-26 03:11:13 +00001128
1129 if (log)
Greg Clayton0416bdf2012-01-30 09:04:36 +00001130 log->Printf ("SBTarget(%p)::GetNumModules () => %d", target_sp.get(), num);
Caroline Tice7826c882010-10-26 03:11:13 +00001131
1132 return num;
Chris Lattner24943d22010-06-08 16:52:24 +00001133}
1134
Greg Clayton43490d12010-07-30 20:12:55 +00001135void
1136SBTarget::Clear ()
1137{
Greg Claytone005f2c2010-11-06 01:53:30 +00001138 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001139
1140 if (log)
Greg Clayton3f5ee7f2010-10-29 04:59:35 +00001141 log->Printf ("SBTarget(%p)::Clear ()", m_opaque_sp.get());
Caroline Tice7826c882010-10-26 03:11:13 +00001142
Greg Clayton43490d12010-07-30 20:12:55 +00001143 m_opaque_sp.reset();
1144}
1145
1146
Chris Lattner24943d22010-06-08 16:52:24 +00001147SBModule
1148SBTarget::FindModule (const SBFileSpec &sb_file_spec)
1149{
1150 SBModule sb_module;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001151 TargetSP target_sp(GetSP());
1152 if (target_sp && sb_file_spec.IsValid())
Greg Claytonbdcda462010-12-20 20:49:23 +00001153 {
1154 // The module list is thread safe, no need to lock
Greg Clayton0416bdf2012-01-30 09:04:36 +00001155 sb_module.SetSP (target_sp->GetImages().FindFirstModuleForFileSpec (*sb_file_spec, NULL, NULL));
Greg Claytonbdcda462010-12-20 20:49:23 +00001156 }
Chris Lattner24943d22010-06-08 16:52:24 +00001157 return sb_module;
1158}
1159
Greg Clayton1b925202012-01-29 06:07:39 +00001160lldb::ByteOrder
1161SBTarget::GetByteOrder ()
1162{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001163 TargetSP target_sp(GetSP());
1164 if (target_sp)
1165 return target_sp->GetArchitecture().GetByteOrder();
Greg Clayton1b925202012-01-29 06:07:39 +00001166 return eByteOrderInvalid;
1167}
1168
1169const char *
1170SBTarget::GetTriple ()
1171{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001172 TargetSP target_sp(GetSP());
1173 if (target_sp)
Greg Clayton1b925202012-01-29 06:07:39 +00001174 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001175 std::string triple (target_sp->GetArchitecture().GetTriple().str());
Greg Clayton1b925202012-01-29 06:07:39 +00001176 // Unique the string so we don't run into ownership issues since
1177 // the const strings put the string into the string pool once and
1178 // the strings never comes out
1179 ConstString const_triple (triple.c_str());
1180 return const_triple.GetCString();
1181 }
1182 return NULL;
1183}
1184
1185uint32_t
1186SBTarget::GetAddressByteSize()
1187{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001188 TargetSP target_sp(GetSP());
1189 if (target_sp)
1190 return target_sp->GetArchitecture().GetAddressByteSize();
Greg Clayton1b925202012-01-29 06:07:39 +00001191 return sizeof(void*);
1192}
1193
1194
Chris Lattner24943d22010-06-08 16:52:24 +00001195SBModule
1196SBTarget::GetModuleAtIndex (uint32_t idx)
1197{
Greg Claytone005f2c2010-11-06 01:53:30 +00001198 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001199
Chris Lattner24943d22010-06-08 16:52:24 +00001200 SBModule sb_module;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001201 ModuleSP module_sp;
1202 TargetSP target_sp(GetSP());
1203 if (target_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +00001204 {
1205 // The module list is thread safe, no need to lock
Greg Clayton0416bdf2012-01-30 09:04:36 +00001206 module_sp = target_sp->GetImages().GetModuleAtIndex(idx);
1207 sb_module.SetSP (module_sp);
Greg Claytonbdcda462010-12-20 20:49:23 +00001208 }
Caroline Tice7826c882010-10-26 03:11:13 +00001209
1210 if (log)
1211 {
Greg Clayton49ce6822010-10-31 03:01:06 +00001212 log->Printf ("SBTarget(%p)::GetModuleAtIndex (idx=%d) => SBModule(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +00001213 target_sp.get(), idx, module_sp.get());
Caroline Tice7826c882010-10-26 03:11:13 +00001214 }
1215
Chris Lattner24943d22010-06-08 16:52:24 +00001216 return sb_module;
1217}
1218
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001219bool
1220SBTarget::RemoveModule (lldb::SBModule module)
1221{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001222 TargetSP target_sp(GetSP());
1223 if (target_sp)
1224 return target_sp->GetImages().Remove(module.GetSP());
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001225 return false;
1226}
1227
Chris Lattner24943d22010-06-08 16:52:24 +00001228
1229SBBroadcaster
1230SBTarget::GetBroadcaster () const
1231{
Greg Claytone005f2c2010-11-06 01:53:30 +00001232 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001233
Greg Clayton0416bdf2012-01-30 09:04:36 +00001234 TargetSP target_sp(GetSP());
1235 SBBroadcaster broadcaster(target_sp.get(), false);
Caroline Tice7826c882010-10-26 03:11:13 +00001236
1237 if (log)
Greg Clayton3f5ee7f2010-10-29 04:59:35 +00001238 log->Printf ("SBTarget(%p)::GetBroadcaster () => SBBroadcaster(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +00001239 target_sp.get(), broadcaster.get());
Caroline Tice7826c882010-10-26 03:11:13 +00001240
Chris Lattner24943d22010-06-08 16:52:24 +00001241 return broadcaster;
1242}
1243
Caroline Tice98f930f2010-09-20 05:20:02 +00001244bool
Caroline Tice7826c882010-10-26 03:11:13 +00001245SBTarget::GetDescription (SBStream &description, lldb::DescriptionLevel description_level)
Caroline Tice98f930f2010-09-20 05:20:02 +00001246{
Greg Clayton96154be2011-11-13 06:57:31 +00001247 Stream &strm = description.ref();
1248
Greg Clayton0416bdf2012-01-30 09:04:36 +00001249 TargetSP target_sp(GetSP());
1250 if (target_sp)
Caroline Ticee7a566e2010-09-20 16:21:41 +00001251 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001252 target_sp->Dump (&strm, description_level);
Caroline Tice7826c882010-10-26 03:11:13 +00001253 }
1254 else
Greg Clayton96154be2011-11-13 06:57:31 +00001255 strm.PutCString ("No value");
Caroline Tice7826c882010-10-26 03:11:13 +00001256
1257 return true;
1258}
1259
Greg Clayton7dd5c512012-02-06 01:44:54 +00001260lldb::SBSymbolContextList
1261SBTarget::FindFunctions (const char *name, uint32_t name_type_mask)
Greg Clayton4ed315f2011-06-21 01:34:41 +00001262{
Greg Clayton7dd5c512012-02-06 01:44:54 +00001263 lldb::SBSymbolContextList sb_sc_list;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001264 if (name && name[0])
Greg Clayton4ed315f2011-06-21 01:34:41 +00001265 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001266 TargetSP target_sp(GetSP());
1267 if (target_sp)
1268 {
1269 const bool symbols_ok = true;
Sean Callanan302d78c2012-02-10 22:52:19 +00001270 const bool inlines_ok = true;
Greg Clayton7dd5c512012-02-06 01:44:54 +00001271 const bool append = true;
1272 target_sp->GetImages().FindFunctions (ConstString(name),
1273 name_type_mask,
Sean Callanan302d78c2012-02-10 22:52:19 +00001274 symbols_ok,
1275 inlines_ok,
Greg Clayton7dd5c512012-02-06 01:44:54 +00001276 append,
1277 *sb_sc_list);
Greg Clayton0416bdf2012-01-30 09:04:36 +00001278 }
Greg Clayton4ed315f2011-06-21 01:34:41 +00001279 }
Greg Clayton7dd5c512012-02-06 01:44:54 +00001280 return sb_sc_list;
Greg Clayton4ed315f2011-06-21 01:34:41 +00001281}
1282
Enrico Granata979e20d2011-07-29 19:53:35 +00001283lldb::SBType
1284SBTarget::FindFirstType (const char* type)
1285{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001286 TargetSP target_sp(GetSP());
1287 if (type && target_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +00001288 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001289 size_t count = target_sp->GetImages().GetSize();
Enrico Granata979e20d2011-07-29 19:53:35 +00001290 for (size_t idx = 0; idx < count; idx++)
1291 {
1292 SBType found_at_idx = GetModuleAtIndex(idx).FindFirstType(type);
1293
1294 if (found_at_idx.IsValid())
1295 return found_at_idx;
1296 }
1297 }
1298 return SBType();
1299}
1300
1301lldb::SBTypeList
1302SBTarget::FindTypes (const char* type)
1303{
1304
1305 SBTypeList retval;
1306
Greg Clayton0416bdf2012-01-30 09:04:36 +00001307 TargetSP target_sp(GetSP());
1308 if (type && target_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +00001309 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001310 ModuleList& images = target_sp->GetImages();
Enrico Granata979e20d2011-07-29 19:53:35 +00001311 ConstString name_const(type);
1312 SymbolContext sc;
1313 TypeList type_list;
1314
1315 uint32_t num_matches = images.FindTypes(sc,
1316 name_const,
1317 true,
1318 UINT32_MAX,
1319 type_list);
1320
1321 for (size_t idx = 0; idx < num_matches; idx++)
1322 {
Greg Clayton0fb0bcc2011-08-03 22:57:10 +00001323 TypeSP type_sp (type_list.GetTypeAtIndex(idx));
1324 if (type_sp)
1325 retval.Append(SBType(type_sp));
Enrico Granata979e20d2011-07-29 19:53:35 +00001326 }
1327 }
1328 return retval;
1329}
1330
Greg Clayton917c0002011-06-29 22:09:02 +00001331SBValueList
1332SBTarget::FindGlobalVariables (const char *name, uint32_t max_matches)
1333{
1334 SBValueList sb_value_list;
1335
Greg Clayton0416bdf2012-01-30 09:04:36 +00001336 TargetSP target_sp(GetSP());
1337 if (name && target_sp)
Greg Clayton917c0002011-06-29 22:09:02 +00001338 {
1339 VariableList variable_list;
1340 const bool append = true;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001341 const uint32_t match_count = target_sp->GetImages().FindGlobalVariables (ConstString (name),
1342 append,
1343 max_matches,
1344 variable_list);
Greg Clayton917c0002011-06-29 22:09:02 +00001345
1346 if (match_count > 0)
1347 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001348 ExecutionContextScope *exe_scope = target_sp->GetProcessSP().get();
Greg Clayton917c0002011-06-29 22:09:02 +00001349 if (exe_scope == NULL)
Greg Clayton0416bdf2012-01-30 09:04:36 +00001350 exe_scope = target_sp.get();
Greg Clayton917c0002011-06-29 22:09:02 +00001351 ValueObjectList &value_object_list = sb_value_list.ref();
1352 for (uint32_t i=0; i<match_count; ++i)
1353 {
1354 lldb::ValueObjectSP valobj_sp (ValueObjectVariable::Create (exe_scope, variable_list.GetVariableAtIndex(i)));
1355 if (valobj_sp)
1356 value_object_list.Append(valobj_sp);
1357 }
1358 }
1359 }
1360
1361 return sb_value_list;
1362}
1363
Jim Inghamcc637462011-09-13 00:29:56 +00001364SBSourceManager
1365SBTarget::GetSourceManager()
1366{
1367 SBSourceManager source_manager (*this);
1368 return source_manager;
1369}
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001370
Sean Callananef1f6902011-12-14 23:49:37 +00001371lldb::SBInstructionList
1372SBTarget::GetInstructions (lldb::SBAddress base_addr, const void *buf, size_t size)
1373{
1374 SBInstructionList sb_instructions;
1375
Greg Clayton0416bdf2012-01-30 09:04:36 +00001376 TargetSP target_sp(GetSP());
1377 if (target_sp)
Sean Callananef1f6902011-12-14 23:49:37 +00001378 {
1379 Address addr;
1380
1381 if (base_addr.get())
1382 addr = *base_addr.get();
1383
Greg Clayton0416bdf2012-01-30 09:04:36 +00001384 sb_instructions.SetDisassembler (Disassembler::DisassembleBytes (target_sp->GetArchitecture(),
Sean Callananef1f6902011-12-14 23:49:37 +00001385 NULL,
1386 addr,
1387 buf,
1388 size));
1389 }
1390
1391 return sb_instructions;
1392}
1393
1394lldb::SBInstructionList
1395SBTarget::GetInstructions (lldb::addr_t base_addr, const void *buf, size_t size)
1396{
1397 return GetInstructions (ResolveLoadAddress(base_addr), buf, size);
1398}
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001399
1400SBError
1401SBTarget::SetSectionLoadAddress (lldb::SBSection section,
1402 lldb::addr_t section_base_addr)
1403{
1404 SBError sb_error;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001405 TargetSP target_sp(GetSP());
1406 if (target_sp)
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001407 {
1408 if (!section.IsValid())
1409 {
1410 sb_error.SetErrorStringWithFormat ("invalid section");
1411 }
1412 else
1413 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001414 target_sp->GetSectionLoadList().SetSectionLoadAddress (section.GetSection(), section_base_addr);
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001415 }
1416 }
1417 else
1418 {
1419 sb_error.SetErrorStringWithFormat ("invalid target");
1420 }
1421 return sb_error;
1422}
1423
1424SBError
1425SBTarget::ClearSectionLoadAddress (lldb::SBSection section)
1426{
1427 SBError sb_error;
1428
Greg Clayton0416bdf2012-01-30 09:04:36 +00001429 TargetSP target_sp(GetSP());
1430 if (target_sp)
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001431 {
1432 if (!section.IsValid())
1433 {
1434 sb_error.SetErrorStringWithFormat ("invalid section");
1435 }
1436 else
1437 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001438 target_sp->GetSectionLoadList().SetSectionUnloaded (section.GetSection());
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001439 }
1440 }
1441 else
1442 {
1443 sb_error.SetErrorStringWithFormat ("invalid target");
1444 }
1445 return sb_error;
1446}
1447
1448SBError
1449SBTarget::SetModuleLoadAddress (lldb::SBModule module, int64_t slide_offset)
1450{
1451 SBError sb_error;
1452
1453 char path[PATH_MAX];
Greg Clayton0416bdf2012-01-30 09:04:36 +00001454 TargetSP target_sp(GetSP());
1455 if (target_sp)
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001456 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001457 ModuleSP module_sp (module.GetSP());
1458 if (module_sp)
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001459 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001460 ObjectFile *objfile = module_sp->GetObjectFile();
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001461 if (objfile)
1462 {
1463 SectionList *section_list = objfile->GetSectionList();
1464 if (section_list)
1465 {
1466 const size_t num_sections = section_list->GetSize();
1467 for (size_t sect_idx = 0; sect_idx < num_sections; ++sect_idx)
1468 {
1469 SectionSP section_sp (section_list->GetSectionAtIndex(sect_idx));
1470 if (section_sp)
Greg Clayton0416bdf2012-01-30 09:04:36 +00001471 target_sp->GetSectionLoadList().SetSectionLoadAddress (section_sp.get(), section_sp->GetFileAddress() + slide_offset);
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001472 }
1473 }
1474 else
1475 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001476 module_sp->GetFileSpec().GetPath (path, sizeof(path));
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001477 sb_error.SetErrorStringWithFormat ("no sections in object file '%s'", path);
1478 }
1479 }
1480 else
1481 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001482 module_sp->GetFileSpec().GetPath (path, sizeof(path));
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001483 sb_error.SetErrorStringWithFormat ("no object file for module '%s'", path);
1484 }
1485 }
Greg Clayton0416bdf2012-01-30 09:04:36 +00001486 else
1487 {
1488 sb_error.SetErrorStringWithFormat ("invalid module");
1489 }
1490
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001491 }
1492 else
1493 {
1494 sb_error.SetErrorStringWithFormat ("invalid target");
1495 }
1496 return sb_error;
1497}
1498
1499SBError
1500SBTarget::ClearModuleLoadAddress (lldb::SBModule module)
1501{
1502 SBError sb_error;
1503
1504 char path[PATH_MAX];
Greg Clayton0416bdf2012-01-30 09:04:36 +00001505 TargetSP target_sp(GetSP());
1506 if (target_sp)
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001507 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001508 ModuleSP module_sp (module.GetSP());
1509 if (module_sp)
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001510 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001511 ObjectFile *objfile = module_sp->GetObjectFile();
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001512 if (objfile)
1513 {
1514 SectionList *section_list = objfile->GetSectionList();
1515 if (section_list)
1516 {
1517 const size_t num_sections = section_list->GetSize();
1518 for (size_t sect_idx = 0; sect_idx < num_sections; ++sect_idx)
1519 {
1520 SectionSP section_sp (section_list->GetSectionAtIndex(sect_idx));
1521 if (section_sp)
Greg Clayton0416bdf2012-01-30 09:04:36 +00001522 target_sp->GetSectionLoadList().SetSectionUnloaded (section_sp.get());
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001523 }
1524 }
1525 else
1526 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001527 module_sp->GetFileSpec().GetPath (path, sizeof(path));
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001528 sb_error.SetErrorStringWithFormat ("no sections in object file '%s'", path);
1529 }
1530 }
1531 else
1532 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001533 module_sp->GetFileSpec().GetPath (path, sizeof(path));
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001534 sb_error.SetErrorStringWithFormat ("no object file for module '%s'", path);
1535 }
1536 }
Greg Clayton0416bdf2012-01-30 09:04:36 +00001537 else
1538 {
1539 sb_error.SetErrorStringWithFormat ("invalid module");
1540 }
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001541 }
1542 else
1543 {
1544 sb_error.SetErrorStringWithFormat ("invalid target");
1545 }
1546 return sb_error;
1547}
1548
1549