blob: 75f2e7a78d16c1c23dab5cf5f7d70250e0bc9752 [file] [log] [blame]
Chris Lattner24943d22010-06-08 16:52:24 +00001//===-- SBTarget.cpp --------------------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
Eli Friedman7a62c8b2010-06-09 07:44:37 +000010#include "lldb/API/SBTarget.h"
Chris Lattner24943d22010-06-08 16:52:24 +000011
Greg Claytonb3448432011-03-24 21:19:54 +000012#include "lldb/lldb-public.h"
Chris Lattner24943d22010-06-08 16:52:24 +000013
Greg Clayton917c0002011-06-29 22:09:02 +000014#include "lldb/API/SBDebugger.h"
15#include "lldb/API/SBBreakpoint.h"
Chris Lattner24943d22010-06-08 16:52:24 +000016#include "lldb/API/SBFileSpec.h"
Greg Clayton917c0002011-06-29 22:09:02 +000017#include "lldb/API/SBListener.h"
Chris Lattner24943d22010-06-08 16:52:24 +000018#include "lldb/API/SBModule.h"
Jim Inghamcc637462011-09-13 00:29:56 +000019#include "lldb/API/SBSourceManager.h"
Greg Clayton917c0002011-06-29 22:09:02 +000020#include "lldb/API/SBProcess.h"
Caroline Tice98f930f2010-09-20 05:20:02 +000021#include "lldb/API/SBStream.h"
Greg Clayton4ed315f2011-06-21 01:34:41 +000022#include "lldb/API/SBSymbolContextList.h"
Chris Lattner24943d22010-06-08 16:52:24 +000023#include "lldb/Breakpoint/BreakpointID.h"
24#include "lldb/Breakpoint/BreakpointIDList.h"
25#include "lldb/Breakpoint/BreakpointList.h"
26#include "lldb/Breakpoint/BreakpointLocation.h"
27#include "lldb/Core/Address.h"
28#include "lldb/Core/AddressResolver.h"
29#include "lldb/Core/AddressResolverName.h"
Chris Lattner24943d22010-06-08 16:52:24 +000030#include "lldb/Core/ArchSpec.h"
31#include "lldb/Core/Debugger.h"
32#include "lldb/Core/Disassembler.h"
Caroline Tice7826c882010-10-26 03:11:13 +000033#include "lldb/Core/Log.h"
Chris Lattner24943d22010-06-08 16:52:24 +000034#include "lldb/Core/RegularExpression.h"
35#include "lldb/Core/SearchFilter.h"
36#include "lldb/Core/STLUtils.h"
Greg Clayton917c0002011-06-29 22:09:02 +000037#include "lldb/Core/ValueObjectList.h"
38#include "lldb/Core/ValueObjectVariable.h"
39#include "lldb/Host/FileSpec.h"
Greg Claytoncd548032011-02-01 01:31:41 +000040#include "lldb/Host/Host.h"
Greg Clayton917c0002011-06-29 22:09:02 +000041#include "lldb/Interpreter/Args.h"
Enrico Granata979e20d2011-07-29 19:53:35 +000042#include "lldb/Symbol/SymbolVendor.h"
Greg Clayton917c0002011-06-29 22:09:02 +000043#include "lldb/Symbol/VariableList.h"
Chris Lattner24943d22010-06-08 16:52:24 +000044#include "lldb/Target/Process.h"
45#include "lldb/Target/Target.h"
46#include "lldb/Target/TargetList.h"
47
48#include "lldb/Interpreter/CommandReturnObject.h"
49#include "../source/Commands/CommandObjectBreakpoint.h"
50
Chris Lattner24943d22010-06-08 16:52:24 +000051
52using namespace lldb;
53using namespace lldb_private;
54
55#define DEFAULT_DISASM_BYTE_SIZE 32
56
57//----------------------------------------------------------------------
58// SBTarget constructor
59//----------------------------------------------------------------------
Greg Claytonc3b61d22010-12-15 05:08:08 +000060SBTarget::SBTarget () :
61 m_opaque_sp ()
Chris Lattner24943d22010-06-08 16:52:24 +000062{
63}
64
65SBTarget::SBTarget (const SBTarget& rhs) :
Greg Clayton63094e02010-06-23 01:19:29 +000066 m_opaque_sp (rhs.m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +000067{
68}
69
70SBTarget::SBTarget(const TargetSP& target_sp) :
Greg Clayton63094e02010-06-23 01:19:29 +000071 m_opaque_sp (target_sp)
Chris Lattner24943d22010-06-08 16:52:24 +000072{
73}
74
Greg Clayton538eb822010-11-05 23:17:00 +000075const SBTarget&
76SBTarget::operator = (const SBTarget& rhs)
77{
78 if (this != &rhs)
79 m_opaque_sp = rhs.m_opaque_sp;
80 return *this;
81}
82
Chris Lattner24943d22010-06-08 16:52:24 +000083//----------------------------------------------------------------------
84// Destructor
85//----------------------------------------------------------------------
86SBTarget::~SBTarget()
87{
88}
89
90bool
91SBTarget::IsValid () const
92{
Greg Clayton63094e02010-06-23 01:19:29 +000093 return m_opaque_sp.get() != NULL;
Chris Lattner24943d22010-06-08 16:52:24 +000094}
95
96SBProcess
97SBTarget::GetProcess ()
98{
99 SBProcess sb_process;
Greg Clayton334d33a2012-01-30 07:41:31 +0000100 ProcessSP process_sp;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000101 TargetSP target_sp(GetSP());
102 if (target_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000103 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000104 process_sp = target_sp->GetProcessSP();
Greg Clayton334d33a2012-01-30 07:41:31 +0000105 sb_process.SetSP (process_sp);
Greg Claytonbdcda462010-12-20 20:49:23 +0000106 }
Caroline Tice7826c882010-10-26 03:11:13 +0000107
Greg Claytone005f2c2010-11-06 01:53:30 +0000108 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000109 if (log)
110 {
Greg Clayton49ce6822010-10-31 03:01:06 +0000111 log->Printf ("SBTarget(%p)::GetProcess () => SBProcess(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +0000112 target_sp.get(), process_sp.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000113 }
114
Chris Lattner24943d22010-06-08 16:52:24 +0000115 return sb_process;
116}
117
Greg Clayton63094e02010-06-23 01:19:29 +0000118SBDebugger
119SBTarget::GetDebugger () const
120{
121 SBDebugger debugger;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000122 TargetSP target_sp(GetSP());
123 if (target_sp)
124 debugger.reset (target_sp->GetDebugger().shared_from_this());
Greg Clayton63094e02010-06-23 01:19:29 +0000125 return debugger;
126}
127
Jim Inghamb5871fe2011-03-31 00:01:24 +0000128SBProcess
129SBTarget::LaunchSimple
130(
131 char const **argv,
132 char const **envp,
133 const char *working_directory
134)
135{
136 char *stdin_path = NULL;
137 char *stdout_path = NULL;
138 char *stderr_path = NULL;
139 uint32_t launch_flags = 0;
140 bool stop_at_entry = false;
141 SBError error;
142 SBListener listener = GetDebugger().GetListener();
143 return Launch (listener,
144 argv,
145 envp,
146 stdin_path,
147 stdout_path,
148 stderr_path,
149 working_directory,
150 launch_flags,
151 stop_at_entry,
152 error);
153}
Greg Claytonde915be2011-01-23 05:56:20 +0000154
155SBProcess
156SBTarget::Launch
157(
Greg Clayton271a5db2011-02-03 21:28:34 +0000158 SBListener &listener,
Greg Claytonde915be2011-01-23 05:56:20 +0000159 char const **argv,
160 char const **envp,
161 const char *stdin_path,
162 const char *stdout_path,
163 const char *stderr_path,
164 const char *working_directory,
165 uint32_t launch_flags, // See LaunchFlags
166 bool stop_at_entry,
167 lldb::SBError& error
168)
169{
Greg Claytone005f2c2010-11-06 01:53:30 +0000170 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000171
Greg Clayton0416bdf2012-01-30 09:04:36 +0000172 SBProcess sb_process;
173 ProcessSP process_sp;
174 TargetSP target_sp(GetSP());
175
Caroline Tice7826c882010-10-26 03:11:13 +0000176 if (log)
Greg Clayton3f5ee7f2010-10-29 04:59:35 +0000177 {
Greg Claytonde915be2011-01-23 05:56:20 +0000178 log->Printf ("SBTarget(%p)::Launch (argv=%p, envp=%p, stdin=%s, stdout=%s, stderr=%s, working-dir=%s, launch_flags=0x%x, stop_at_entry=%i, &error (%p))...",
Greg Clayton0416bdf2012-01-30 09:04:36 +0000179 target_sp.get(),
Greg Claytonde915be2011-01-23 05:56:20 +0000180 argv,
181 envp,
182 stdin_path ? stdin_path : "NULL",
183 stdout_path ? stdout_path : "NULL",
184 stderr_path ? stderr_path : "NULL",
185 working_directory ? working_directory : "NULL",
186 launch_flags,
187 stop_at_entry,
188 error.get());
Greg Clayton3f5ee7f2010-10-29 04:59:35 +0000189 }
Greg Clayton0416bdf2012-01-30 09:04:36 +0000190
191 if (target_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000192 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000193 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton1a3083a2010-10-06 03:53:16 +0000194
Greg Clayton7c330d62011-01-27 01:01:10 +0000195 if (getenv("LLDB_LAUNCH_FLAG_DISABLE_ASLR"))
196 launch_flags |= eLaunchFlagDisableASLR;
197
Greg Clayton180546b2011-04-30 01:09:13 +0000198 StateType state = eStateInvalid;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000199 process_sp = target_sp->GetProcessSP();
Greg Clayton334d33a2012-01-30 07:41:31 +0000200 if (process_sp)
Greg Clayton28d5fcc2011-01-27 06:44:37 +0000201 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000202 state = process_sp->GetState();
Greg Clayton180546b2011-04-30 01:09:13 +0000203
Greg Clayton334d33a2012-01-30 07:41:31 +0000204 if (process_sp->IsAlive() && state != eStateConnected)
Greg Clayton180546b2011-04-30 01:09:13 +0000205 {
206 if (state == eStateAttaching)
207 error.SetErrorString ("process attach is in progress");
208 else
209 error.SetErrorString ("a process is already being debugged");
Greg Clayton180546b2011-04-30 01:09:13 +0000210 return sb_process;
211 }
Greg Clayton28d5fcc2011-01-27 06:44:37 +0000212 }
213
Greg Clayton180546b2011-04-30 01:09:13 +0000214 if (state == eStateConnected)
215 {
216 // If we are already connected, then we have already specified the
217 // listener, so if a valid listener is supplied, we need to error out
218 // to let the client know.
219 if (listener.IsValid())
220 {
221 error.SetErrorString ("process is connected and already has a listener, pass empty listener");
Greg Clayton180546b2011-04-30 01:09:13 +0000222 return sb_process;
223 }
224 }
225 else
Greg Claytonc5f728c2010-10-06 22:10:17 +0000226 {
Greg Clayton271a5db2011-02-03 21:28:34 +0000227 if (listener.IsValid())
Greg Clayton46c9a352012-02-09 06:16:32 +0000228 process_sp = target_sp->CreateProcess (listener.ref(), NULL, NULL);
Greg Clayton271a5db2011-02-03 21:28:34 +0000229 else
Greg Clayton46c9a352012-02-09 06:16:32 +0000230 process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener(), NULL, NULL);
Greg Clayton180546b2011-04-30 01:09:13 +0000231 }
Greg Clayton7c330d62011-01-27 01:01:10 +0000232
Greg Clayton334d33a2012-01-30 07:41:31 +0000233 if (process_sp)
Greg Clayton180546b2011-04-30 01:09:13 +0000234 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000235 sb_process.SetSP (process_sp);
Greg Clayton180546b2011-04-30 01:09:13 +0000236 if (getenv("LLDB_LAUNCH_FLAG_DISABLE_STDIO"))
237 launch_flags |= eLaunchFlagDisableSTDIO;
238
Greg Clayton36bc5ea2011-11-03 21:22:33 +0000239 ProcessLaunchInfo launch_info (stdin_path, stdout_path, stderr_path, working_directory, launch_flags);
240
Greg Clayton0416bdf2012-01-30 09:04:36 +0000241 Module *exe_module = target_sp->GetExecutableModulePointer();
Greg Clayton36bc5ea2011-11-03 21:22:33 +0000242 if (exe_module)
Greg Clayton1d1f39e2011-11-29 04:03:30 +0000243 launch_info.SetExecutableFile(exe_module->GetPlatformFileSpec(), true);
Greg Clayton36bc5ea2011-11-03 21:22:33 +0000244 if (argv)
245 launch_info.GetArguments().AppendArguments (argv);
246 if (envp)
247 launch_info.GetEnvironmentEntries ().SetArguments (envp);
248
Greg Clayton334d33a2012-01-30 07:41:31 +0000249 error.SetError (process_sp->Launch (launch_info));
Greg Clayton180546b2011-04-30 01:09:13 +0000250 if (error.Success())
Greg Clayton7c330d62011-01-27 01:01:10 +0000251 {
Greg Clayton180546b2011-04-30 01:09:13 +0000252 // We we are stopping at the entry point, we can return now!
253 if (stop_at_entry)
254 return sb_process;
Greg Clayton7c330d62011-01-27 01:01:10 +0000255
Greg Clayton180546b2011-04-30 01:09:13 +0000256 // Make sure we are stopped at the entry
Greg Clayton334d33a2012-01-30 07:41:31 +0000257 StateType state = process_sp->WaitForProcessToStop (NULL);
Greg Clayton180546b2011-04-30 01:09:13 +0000258 if (state == eStateStopped)
Greg Clayton7c330d62011-01-27 01:01:10 +0000259 {
Greg Clayton180546b2011-04-30 01:09:13 +0000260 // resume the process to skip the entry point
Greg Clayton334d33a2012-01-30 07:41:31 +0000261 error.SetError (process_sp->Resume());
Greg Clayton180546b2011-04-30 01:09:13 +0000262 if (error.Success())
Greg Clayton7c330d62011-01-27 01:01:10 +0000263 {
Greg Clayton180546b2011-04-30 01:09:13 +0000264 // If we are doing synchronous mode, then wait for the
265 // process to stop yet again!
Greg Clayton0416bdf2012-01-30 09:04:36 +0000266 if (target_sp->GetDebugger().GetAsyncExecution () == false)
Greg Clayton334d33a2012-01-30 07:41:31 +0000267 process_sp->WaitForProcessToStop (NULL);
Greg Clayton7c330d62011-01-27 01:01:10 +0000268 }
269 }
270 }
Greg Clayton180546b2011-04-30 01:09:13 +0000271 }
272 else
273 {
274 error.SetErrorString ("unable to create lldb_private::Process");
Greg Claytonc5f728c2010-10-06 22:10:17 +0000275 }
276 }
277 else
278 {
279 error.SetErrorString ("SBTarget is invalid");
Chris Lattner24943d22010-06-08 16:52:24 +0000280 }
Caroline Tice7826c882010-10-26 03:11:13 +0000281
Caroline Tice926060e2010-10-29 21:48:37 +0000282 log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
Caroline Tice7826c882010-10-26 03:11:13 +0000283 if (log)
284 {
Greg Clayton49ce6822010-10-31 03:01:06 +0000285 log->Printf ("SBTarget(%p)::Launch (...) => SBProceess(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +0000286 target_sp.get(), process_sp.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000287 }
288
Greg Clayton1a3083a2010-10-06 03:53:16 +0000289 return sb_process;
Chris Lattner24943d22010-06-08 16:52:24 +0000290}
291
Greg Claytond5b0b442011-12-02 02:10:57 +0000292#if defined(__APPLE__)
293
294lldb::SBProcess
295SBTarget::AttachToProcessWithID (SBListener &listener,
296 ::pid_t pid,
297 lldb::SBError& error)
298{
299 return AttachToProcessWithID (listener, (lldb::pid_t)pid, error);
300}
301
302#endif // #if defined(__APPLE__)
Greg Claytonc5f728c2010-10-06 22:10:17 +0000303
304lldb::SBProcess
Greg Claytond8c62532010-10-07 04:19:01 +0000305SBTarget::AttachToProcessWithID
Greg Claytonc5f728c2010-10-06 22:10:17 +0000306(
Greg Clayton271a5db2011-02-03 21:28:34 +0000307 SBListener &listener,
Greg Claytonc5f728c2010-10-06 22:10:17 +0000308 lldb::pid_t pid,// The process ID to attach to
309 SBError& error // An error explaining what went wrong if attach fails
310)
311{
312 SBProcess sb_process;
Greg Clayton334d33a2012-01-30 07:41:31 +0000313 ProcessSP process_sp;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000314 TargetSP target_sp(GetSP());
315 if (target_sp)
Greg Claytonc5f728c2010-10-06 22:10:17 +0000316 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000317 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytonde1dd812011-06-24 03:21:43 +0000318
319 StateType state = eStateInvalid;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000320 process_sp = target_sp->GetProcessSP();
Greg Clayton334d33a2012-01-30 07:41:31 +0000321 if (process_sp)
Greg Claytonde1dd812011-06-24 03:21:43 +0000322 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000323 state = process_sp->GetState();
Greg Claytonde1dd812011-06-24 03:21:43 +0000324
Greg Clayton334d33a2012-01-30 07:41:31 +0000325 if (process_sp->IsAlive() && state != eStateConnected)
Greg Claytonde1dd812011-06-24 03:21:43 +0000326 {
327 if (state == eStateAttaching)
328 error.SetErrorString ("process attach is in progress");
329 else
330 error.SetErrorString ("a process is already being debugged");
Greg Claytonde1dd812011-06-24 03:21:43 +0000331 return sb_process;
332 }
333 }
334
335 if (state == eStateConnected)
336 {
337 // If we are already connected, then we have already specified the
338 // listener, so if a valid listener is supplied, we need to error out
339 // to let the client know.
340 if (listener.IsValid())
341 {
342 error.SetErrorString ("process is connected and already has a listener, pass empty listener");
Greg Claytonde1dd812011-06-24 03:21:43 +0000343 return sb_process;
344 }
345 }
Greg Clayton271a5db2011-02-03 21:28:34 +0000346 else
Greg Claytonde1dd812011-06-24 03:21:43 +0000347 {
348 if (listener.IsValid())
Greg Clayton46c9a352012-02-09 06:16:32 +0000349 process_sp = target_sp->CreateProcess (listener.ref(), NULL, NULL);
Greg Claytonde1dd812011-06-24 03:21:43 +0000350 else
Greg Clayton46c9a352012-02-09 06:16:32 +0000351 process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener(), NULL, NULL);
Greg Claytonde1dd812011-06-24 03:21:43 +0000352 }
Greg Clayton334d33a2012-01-30 07:41:31 +0000353 if (process_sp)
Greg Claytonc5f728c2010-10-06 22:10:17 +0000354 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000355 sb_process.SetSP (process_sp);
356
Greg Clayton527154d2011-11-15 03:53:30 +0000357 ProcessAttachInfo attach_info;
358 attach_info.SetProcessID (pid);
Greg Clayton334d33a2012-01-30 07:41:31 +0000359 error.SetError (process_sp->Attach (attach_info));
Johnny Chen535960e2011-06-17 00:51:15 +0000360 // If we are doing synchronous mode, then wait for the
361 // process to stop!
Greg Clayton0416bdf2012-01-30 09:04:36 +0000362 if (target_sp->GetDebugger().GetAsyncExecution () == false)
Greg Clayton334d33a2012-01-30 07:41:31 +0000363 process_sp->WaitForProcessToStop (NULL);
Greg Claytonc5f728c2010-10-06 22:10:17 +0000364 }
365 else
366 {
367 error.SetErrorString ("unable to create lldb_private::Process");
368 }
369 }
370 else
371 {
372 error.SetErrorString ("SBTarget is invalid");
373 }
374 return sb_process;
375
376}
377
378lldb::SBProcess
Greg Claytond8c62532010-10-07 04:19:01 +0000379SBTarget::AttachToProcessWithName
Greg Claytonc5f728c2010-10-06 22:10:17 +0000380(
Greg Clayton271a5db2011-02-03 21:28:34 +0000381 SBListener &listener,
Greg Claytonc5f728c2010-10-06 22:10:17 +0000382 const char *name, // basename of process to attach to
383 bool wait_for, // if true wait for a new instance of "name" to be launched
384 SBError& error // An error explaining what went wrong if attach fails
385)
386{
387 SBProcess sb_process;
Greg Clayton334d33a2012-01-30 07:41:31 +0000388 ProcessSP process_sp;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000389 TargetSP target_sp(GetSP());
390 if (name && target_sp)
Greg Claytonc5f728c2010-10-06 22:10:17 +0000391 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000392 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytonbdcda462010-12-20 20:49:23 +0000393
Greg Claytonde1dd812011-06-24 03:21:43 +0000394 StateType state = eStateInvalid;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000395 process_sp = target_sp->GetProcessSP();
Greg Clayton334d33a2012-01-30 07:41:31 +0000396 if (process_sp)
Greg Claytonde1dd812011-06-24 03:21:43 +0000397 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000398 state = process_sp->GetState();
Greg Claytonde1dd812011-06-24 03:21:43 +0000399
Greg Clayton334d33a2012-01-30 07:41:31 +0000400 if (process_sp->IsAlive() && state != eStateConnected)
Greg Claytonde1dd812011-06-24 03:21:43 +0000401 {
402 if (state == eStateAttaching)
403 error.SetErrorString ("process attach is in progress");
404 else
405 error.SetErrorString ("a process is already being debugged");
Greg Claytonde1dd812011-06-24 03:21:43 +0000406 return sb_process;
407 }
408 }
409
410 if (state == eStateConnected)
411 {
412 // If we are already connected, then we have already specified the
413 // listener, so if a valid listener is supplied, we need to error out
414 // to let the client know.
415 if (listener.IsValid())
416 {
417 error.SetErrorString ("process is connected and already has a listener, pass empty listener");
Greg Claytonde1dd812011-06-24 03:21:43 +0000418 return sb_process;
419 }
420 }
Greg Clayton271a5db2011-02-03 21:28:34 +0000421 else
Greg Claytonde1dd812011-06-24 03:21:43 +0000422 {
423 if (listener.IsValid())
Greg Clayton46c9a352012-02-09 06:16:32 +0000424 process_sp = target_sp->CreateProcess (listener.ref(), NULL, NULL);
Greg Claytonde1dd812011-06-24 03:21:43 +0000425 else
Greg Clayton46c9a352012-02-09 06:16:32 +0000426 process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener(), NULL, NULL);
Greg Claytonde1dd812011-06-24 03:21:43 +0000427 }
Greg Claytonc5f728c2010-10-06 22:10:17 +0000428
Greg Clayton334d33a2012-01-30 07:41:31 +0000429 if (process_sp)
Greg Claytonc5f728c2010-10-06 22:10:17 +0000430 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000431 sb_process.SetSP (process_sp);
Greg Clayton527154d2011-11-15 03:53:30 +0000432 ProcessAttachInfo attach_info;
433 attach_info.GetExecutableFile().SetFile(name, false);
434 attach_info.SetWaitForLaunch(wait_for);
Greg Clayton334d33a2012-01-30 07:41:31 +0000435 error.SetError (process_sp->Attach (attach_info));
Johnny Chen58d02ff2011-06-17 19:21:30 +0000436 // If we are doing synchronous mode, then wait for the
437 // process to stop!
Greg Clayton0416bdf2012-01-30 09:04:36 +0000438 if (target_sp->GetDebugger().GetAsyncExecution () == false)
Greg Clayton334d33a2012-01-30 07:41:31 +0000439 process_sp->WaitForProcessToStop (NULL);
Greg Claytonc5f728c2010-10-06 22:10:17 +0000440 }
441 else
442 {
443 error.SetErrorString ("unable to create lldb_private::Process");
444 }
445 }
446 else
447 {
448 error.SetErrorString ("SBTarget is invalid");
449 }
450 return sb_process;
451
452}
453
James McIlree38093402011-03-04 00:31:13 +0000454lldb::SBProcess
455SBTarget::ConnectRemote
456(
457 SBListener &listener,
458 const char *url,
459 const char *plugin_name,
460 SBError& error
461)
462{
463 SBProcess sb_process;
Greg Clayton334d33a2012-01-30 07:41:31 +0000464 ProcessSP process_sp;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000465 TargetSP target_sp(GetSP());
466 if (target_sp)
James McIlree38093402011-03-04 00:31:13 +0000467 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000468 Mutex::Locker api_locker (target_sp->GetAPIMutex());
James McIlree38093402011-03-04 00:31:13 +0000469 if (listener.IsValid())
Greg Clayton46c9a352012-02-09 06:16:32 +0000470 process_sp = target_sp->CreateProcess (listener.ref(), plugin_name, NULL);
James McIlree38093402011-03-04 00:31:13 +0000471 else
Greg Clayton46c9a352012-02-09 06:16:32 +0000472 process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener(), plugin_name, NULL);
James McIlree38093402011-03-04 00:31:13 +0000473
474
Greg Clayton334d33a2012-01-30 07:41:31 +0000475 if (process_sp)
James McIlree38093402011-03-04 00:31:13 +0000476 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000477 sb_process.SetSP (process_sp);
478 error.SetError (process_sp->ConnectRemote (url));
James McIlree38093402011-03-04 00:31:13 +0000479 }
480 else
481 {
482 error.SetErrorString ("unable to create lldb_private::Process");
483 }
484 }
485 else
486 {
487 error.SetErrorString ("SBTarget is invalid");
488 }
489 return sb_process;
490}
491
Chris Lattner24943d22010-06-08 16:52:24 +0000492SBFileSpec
493SBTarget::GetExecutable ()
494{
Caroline Tice7826c882010-10-26 03:11:13 +0000495
Chris Lattner24943d22010-06-08 16:52:24 +0000496 SBFileSpec exe_file_spec;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000497 TargetSP target_sp(GetSP());
498 if (target_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000499 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000500 Module *exe_module = target_sp->GetExecutableModulePointer();
Greg Clayton5beb99d2011-08-11 02:48:45 +0000501 if (exe_module)
502 exe_file_spec.SetFileSpec (exe_module->GetFileSpec());
Chris Lattner24943d22010-06-08 16:52:24 +0000503 }
Caroline Tice7826c882010-10-26 03:11:13 +0000504
Greg Claytone005f2c2010-11-06 01:53:30 +0000505 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000506 if (log)
507 {
Greg Clayton49ce6822010-10-31 03:01:06 +0000508 log->Printf ("SBTarget(%p)::GetExecutable () => SBFileSpec(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +0000509 target_sp.get(), exe_file_spec.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000510 }
511
Chris Lattner24943d22010-06-08 16:52:24 +0000512 return exe_file_spec;
513}
514
Chris Lattner24943d22010-06-08 16:52:24 +0000515bool
Chris Lattner24943d22010-06-08 16:52:24 +0000516SBTarget::operator == (const SBTarget &rhs) const
517{
Greg Clayton63094e02010-06-23 01:19:29 +0000518 return m_opaque_sp.get() == rhs.m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000519}
520
521bool
522SBTarget::operator != (const SBTarget &rhs) const
523{
Greg Clayton63094e02010-06-23 01:19:29 +0000524 return m_opaque_sp.get() != rhs.m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000525}
526
Greg Clayton334d33a2012-01-30 07:41:31 +0000527lldb::TargetSP
528SBTarget::GetSP () const
Greg Clayton15afa9f2011-10-01 02:59:24 +0000529{
530 return m_opaque_sp;
531}
532
Greg Clayton63094e02010-06-23 01:19:29 +0000533void
Greg Clayton334d33a2012-01-30 07:41:31 +0000534SBTarget::SetSP (const lldb::TargetSP& target_sp)
Greg Clayton63094e02010-06-23 01:19:29 +0000535{
536 m_opaque_sp = target_sp;
Chris Lattner24943d22010-06-08 16:52:24 +0000537}
538
Greg Claytona3955062011-07-22 16:46:35 +0000539lldb::SBAddress
540SBTarget::ResolveLoadAddress (lldb::addr_t vm_addr)
Greg Claytonea49cc72010-12-12 19:25:26 +0000541{
Greg Claytona3955062011-07-22 16:46:35 +0000542 lldb::SBAddress sb_addr;
543 Address &addr = sb_addr.ref();
Greg Clayton0416bdf2012-01-30 09:04:36 +0000544 TargetSP target_sp(GetSP());
545 if (target_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000546 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000547 Mutex::Locker api_locker (target_sp->GetAPIMutex());
548 if (target_sp->GetSectionLoadList().ResolveLoadAddress (vm_addr, addr))
Greg Claytona3955062011-07-22 16:46:35 +0000549 return sb_addr;
Greg Claytonbdcda462010-12-20 20:49:23 +0000550 }
Greg Claytonea49cc72010-12-12 19:25:26 +0000551
Greg Claytona3955062011-07-22 16:46:35 +0000552 // We have a load address that isn't in a section, just return an address
553 // with the offset filled in (the address) and the section set to NULL
554 addr.SetSection(NULL);
555 addr.SetOffset(vm_addr);
556 return sb_addr;
Greg Claytonea49cc72010-12-12 19:25:26 +0000557}
558
Greg Claytonafb81862011-03-02 21:34:46 +0000559SBSymbolContext
560SBTarget::ResolveSymbolContextForAddress (const SBAddress& addr, uint32_t resolve_scope)
561{
562 SBSymbolContext sc;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000563 if (addr.IsValid())
564 {
565 TargetSP target_sp(GetSP());
566 if (target_sp)
567 target_sp->GetImages().ResolveSymbolContextForAddress (addr.ref(), resolve_scope, sc.ref());
568 }
Greg Claytonafb81862011-03-02 21:34:46 +0000569 return sc;
570}
571
572
Chris Lattner24943d22010-06-08 16:52:24 +0000573SBBreakpoint
574SBTarget::BreakpointCreateByLocation (const char *file, uint32_t line)
575{
Greg Claytond6d806c2010-11-08 00:28:40 +0000576 return SBBreakpoint(BreakpointCreateByLocation (SBFileSpec (file, false), line));
Chris Lattner24943d22010-06-08 16:52:24 +0000577}
578
579SBBreakpoint
580SBTarget::BreakpointCreateByLocation (const SBFileSpec &sb_file_spec, uint32_t line)
581{
Greg Claytone005f2c2010-11-06 01:53:30 +0000582 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000583
Chris Lattner24943d22010-06-08 16:52:24 +0000584 SBBreakpoint sb_bp;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000585 TargetSP target_sp(GetSP());
586 if (target_sp && line != 0)
Greg Claytonbdcda462010-12-20 20:49:23 +0000587 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000588 Mutex::Locker api_locker (target_sp->GetAPIMutex());
589 *sb_bp = target_sp->CreateBreakpoint (NULL, *sb_file_spec, line, true, false);
Greg Claytonbdcda462010-12-20 20:49:23 +0000590 }
Caroline Tice7826c882010-10-26 03:11:13 +0000591
592 if (log)
593 {
594 SBStream sstr;
595 sb_bp.GetDescription (sstr);
Greg Clayton49ce6822010-10-31 03:01:06 +0000596 char path[PATH_MAX];
597 sb_file_spec->GetPath (path, sizeof(path));
598 log->Printf ("SBTarget(%p)::BreakpointCreateByLocation ( %s:%u ) => SBBreakpoint(%p): %s",
Greg Clayton0416bdf2012-01-30 09:04:36 +0000599 target_sp.get(),
Greg Clayton49ce6822010-10-31 03:01:06 +0000600 path,
Greg Claytona66ba462010-10-30 04:51:46 +0000601 line,
Greg Clayton49ce6822010-10-31 03:01:06 +0000602 sb_bp.get(),
Caroline Tice7826c882010-10-26 03:11:13 +0000603 sstr.GetData());
604 }
605
Chris Lattner24943d22010-06-08 16:52:24 +0000606 return sb_bp;
607}
608
609SBBreakpoint
610SBTarget::BreakpointCreateByName (const char *symbol_name, const char *module_name)
611{
Greg Claytone005f2c2010-11-06 01:53:30 +0000612 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000613
Chris Lattner24943d22010-06-08 16:52:24 +0000614 SBBreakpoint sb_bp;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000615 TargetSP target_sp(GetSP());
616 if (target_sp.get())
Chris Lattner24943d22010-06-08 16:52:24 +0000617 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000618 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Chris Lattner24943d22010-06-08 16:52:24 +0000619 if (module_name && module_name[0])
620 {
Jim Ingham03c8ee52011-09-21 01:17:13 +0000621 FileSpecList module_spec_list;
622 module_spec_list.Append (FileSpec (module_name, false));
Greg Clayton0416bdf2012-01-30 09:04:36 +0000623 *sb_bp = target_sp->CreateBreakpoint (&module_spec_list, NULL, symbol_name, eFunctionNameTypeAuto, false);
Chris Lattner24943d22010-06-08 16:52:24 +0000624 }
625 else
626 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000627 *sb_bp = target_sp->CreateBreakpoint (NULL, NULL, symbol_name, eFunctionNameTypeAuto, false);
Chris Lattner24943d22010-06-08 16:52:24 +0000628 }
629 }
Caroline Tice7826c882010-10-26 03:11:13 +0000630
631 if (log)
632 {
Greg Clayton49ce6822010-10-31 03:01:06 +0000633 log->Printf ("SBTarget(%p)::BreakpointCreateByName (symbol=\"%s\", module=\"%s\") => SBBreakpoint(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +0000634 target_sp.get(), symbol_name, module_name, sb_bp.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000635 }
636
Chris Lattner24943d22010-06-08 16:52:24 +0000637 return sb_bp;
638}
639
Jim Inghamd6d47972011-09-23 00:54:11 +0000640lldb::SBBreakpoint
641SBTarget::BreakpointCreateByName (const char *symbol_name,
642 const SBFileSpecList &module_list,
643 const SBFileSpecList &comp_unit_list)
644{
Jim Ingham1fb8a2d2011-10-11 01:18:55 +0000645 uint32_t name_type_mask = eFunctionNameTypeAuto;
646 return BreakpointCreateByName (symbol_name, name_type_mask, module_list, comp_unit_list);
647}
648
649lldb::SBBreakpoint
650SBTarget::BreakpointCreateByName (const char *symbol_name,
651 uint32_t name_type_mask,
652 const SBFileSpecList &module_list,
653 const SBFileSpecList &comp_unit_list)
654{
Jim Inghamd6d47972011-09-23 00:54:11 +0000655 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
656
657 SBBreakpoint sb_bp;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000658 TargetSP target_sp(GetSP());
659 if (target_sp && symbol_name && symbol_name[0])
Jim Inghamd6d47972011-09-23 00:54:11 +0000660 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000661 Mutex::Locker api_locker (target_sp->GetAPIMutex());
662 *sb_bp = target_sp->CreateBreakpoint (module_list.get(),
Jim Inghamd6d47972011-09-23 00:54:11 +0000663 comp_unit_list.get(),
664 symbol_name,
Jim Ingham1fb8a2d2011-10-11 01:18:55 +0000665 name_type_mask,
Jim Inghamd6d47972011-09-23 00:54:11 +0000666 false);
667 }
668
669 if (log)
670 {
Jim Ingham1fb8a2d2011-10-11 01:18:55 +0000671 log->Printf ("SBTarget(%p)::BreakpointCreateByName (symbol=\"%s\", name_type: %d) => SBBreakpoint(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +0000672 target_sp.get(), symbol_name, name_type_mask, sb_bp.get());
Jim Inghamd6d47972011-09-23 00:54:11 +0000673 }
674
675 return sb_bp;
676}
677
678
Chris Lattner24943d22010-06-08 16:52:24 +0000679SBBreakpoint
680SBTarget::BreakpointCreateByRegex (const char *symbol_name_regex, const char *module_name)
681{
Greg Claytone005f2c2010-11-06 01:53:30 +0000682 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000683
Chris Lattner24943d22010-06-08 16:52:24 +0000684 SBBreakpoint sb_bp;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000685 TargetSP target_sp(GetSP());
686 if (target_sp && symbol_name_regex && symbol_name_regex[0])
Chris Lattner24943d22010-06-08 16:52:24 +0000687 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000688 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Chris Lattner24943d22010-06-08 16:52:24 +0000689 RegularExpression regexp(symbol_name_regex);
690
691 if (module_name && module_name[0])
692 {
Jim Ingham03c8ee52011-09-21 01:17:13 +0000693 FileSpecList module_spec_list;
694 module_spec_list.Append (FileSpec (module_name, false));
Chris Lattner24943d22010-06-08 16:52:24 +0000695
Greg Clayton0416bdf2012-01-30 09:04:36 +0000696 *sb_bp = target_sp->CreateFuncRegexBreakpoint (&module_spec_list, NULL, regexp, false);
Chris Lattner24943d22010-06-08 16:52:24 +0000697 }
698 else
699 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000700 *sb_bp = target_sp->CreateFuncRegexBreakpoint (NULL, NULL, regexp, false);
Chris Lattner24943d22010-06-08 16:52:24 +0000701 }
702 }
Caroline Tice7826c882010-10-26 03:11:13 +0000703
704 if (log)
705 {
Greg Clayton49ce6822010-10-31 03:01:06 +0000706 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (symbol_regex=\"%s\", module_name=\"%s\") => SBBreakpoint(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +0000707 target_sp.get(), symbol_name_regex, module_name, sb_bp.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000708 }
709
Chris Lattner24943d22010-06-08 16:52:24 +0000710 return sb_bp;
711}
712
Jim Inghamd6d47972011-09-23 00:54:11 +0000713lldb::SBBreakpoint
714SBTarget::BreakpointCreateByRegex (const char *symbol_name_regex,
715 const SBFileSpecList &module_list,
716 const SBFileSpecList &comp_unit_list)
717{
718 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Chris Lattner24943d22010-06-08 16:52:24 +0000719
Jim Inghamd6d47972011-09-23 00:54:11 +0000720 SBBreakpoint sb_bp;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000721 TargetSP target_sp(GetSP());
722 if (target_sp && symbol_name_regex && symbol_name_regex[0])
Jim Inghamd6d47972011-09-23 00:54:11 +0000723 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000724 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Jim Inghamd6d47972011-09-23 00:54:11 +0000725 RegularExpression regexp(symbol_name_regex);
726
Greg Clayton0416bdf2012-01-30 09:04:36 +0000727 *sb_bp = target_sp->CreateFuncRegexBreakpoint (module_list.get(), comp_unit_list.get(), regexp, false);
Jim Inghamd6d47972011-09-23 00:54:11 +0000728 }
729
730 if (log)
731 {
732 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (symbol_regex=\"%s\") => SBBreakpoint(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +0000733 target_sp.get(), symbol_name_regex, sb_bp.get());
Jim Inghamd6d47972011-09-23 00:54:11 +0000734 }
735
736 return sb_bp;
737}
Chris Lattner24943d22010-06-08 16:52:24 +0000738
739SBBreakpoint
740SBTarget::BreakpointCreateByAddress (addr_t address)
741{
Greg Claytone005f2c2010-11-06 01:53:30 +0000742 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000743
Chris Lattner24943d22010-06-08 16:52:24 +0000744 SBBreakpoint sb_bp;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000745 TargetSP target_sp(GetSP());
746 if (target_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000747 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000748 Mutex::Locker api_locker (target_sp->GetAPIMutex());
749 *sb_bp = target_sp->CreateBreakpoint (address, false);
Greg Claytonbdcda462010-12-20 20:49:23 +0000750 }
Caroline Tice7826c882010-10-26 03:11:13 +0000751
752 if (log)
753 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000754 log->Printf ("SBTarget(%p)::BreakpointCreateByAddress (address=%llu) => SBBreakpoint(%p)", target_sp.get(), (uint64_t) address, sb_bp.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000755 }
756
Chris Lattner24943d22010-06-08 16:52:24 +0000757 return sb_bp;
758}
759
Jim Ingham03c8ee52011-09-21 01:17:13 +0000760lldb::SBBreakpoint
761SBTarget::BreakpointCreateBySourceRegex (const char *source_regex, const lldb::SBFileSpec &source_file, const char *module_name)
762{
763 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
764
765 SBBreakpoint sb_bp;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000766 TargetSP target_sp(GetSP());
767 if (target_sp && source_regex && source_regex[0])
Jim Ingham03c8ee52011-09-21 01:17:13 +0000768 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000769 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Jim Ingham03c8ee52011-09-21 01:17:13 +0000770 RegularExpression regexp(source_regex);
Jim Inghamd6d47972011-09-23 00:54:11 +0000771 FileSpecList source_file_spec_list;
772 source_file_spec_list.Append (source_file.ref());
Jim Ingham03c8ee52011-09-21 01:17:13 +0000773
774 if (module_name && module_name[0])
775 {
776 FileSpecList module_spec_list;
777 module_spec_list.Append (FileSpec (module_name, false));
778
Greg Clayton0416bdf2012-01-30 09:04:36 +0000779 *sb_bp = target_sp->CreateSourceRegexBreakpoint (&module_spec_list, &source_file_spec_list, regexp, false);
Jim Ingham03c8ee52011-09-21 01:17:13 +0000780 }
781 else
782 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000783 *sb_bp = target_sp->CreateSourceRegexBreakpoint (NULL, &source_file_spec_list, regexp, false);
Jim Ingham03c8ee52011-09-21 01:17:13 +0000784 }
785 }
786
787 if (log)
788 {
789 char path[PATH_MAX];
790 source_file->GetPath (path, sizeof(path));
791 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (source_regex=\"%s\", file=\"%s\", module_name=\"%s\") => SBBreakpoint(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +0000792 target_sp.get(), source_regex, path, module_name, sb_bp.get());
Jim Ingham03c8ee52011-09-21 01:17:13 +0000793 }
794
795 return sb_bp;
796}
797
Jim Inghamd6d47972011-09-23 00:54:11 +0000798lldb::SBBreakpoint
799SBTarget::BreakpointCreateBySourceRegex (const char *source_regex,
800 const SBFileSpecList &module_list,
801 const lldb::SBFileSpecList &source_file_list)
802{
803 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
804
805 SBBreakpoint sb_bp;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000806 TargetSP target_sp(GetSP());
807 if (target_sp && source_regex && source_regex[0])
Jim Inghamd6d47972011-09-23 00:54:11 +0000808 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000809 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Jim Inghamd6d47972011-09-23 00:54:11 +0000810 RegularExpression regexp(source_regex);
Greg Clayton0416bdf2012-01-30 09:04:36 +0000811 *sb_bp = target_sp->CreateSourceRegexBreakpoint (module_list.get(), source_file_list.get(), regexp, false);
Jim Inghamd6d47972011-09-23 00:54:11 +0000812 }
813
814 if (log)
815 {
816 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (source_regex=\"%s\") => SBBreakpoint(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +0000817 target_sp.get(), source_regex, sb_bp.get());
Jim Inghamd6d47972011-09-23 00:54:11 +0000818 }
819
820 return sb_bp;
821}
Jim Ingham03c8ee52011-09-21 01:17:13 +0000822
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000823uint32_t
824SBTarget::GetNumBreakpoints () const
825{
Greg Clayton0416bdf2012-01-30 09:04:36 +0000826 TargetSP target_sp(GetSP());
827 if (target_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000828 {
829 // The breakpoint list is thread safe, no need to lock
Greg Clayton0416bdf2012-01-30 09:04:36 +0000830 return target_sp->GetBreakpointList().GetSize();
Greg Claytonbdcda462010-12-20 20:49:23 +0000831 }
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000832 return 0;
833}
834
835SBBreakpoint
836SBTarget::GetBreakpointAtIndex (uint32_t idx) const
837{
838 SBBreakpoint sb_breakpoint;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000839 TargetSP target_sp(GetSP());
840 if (target_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000841 {
842 // The breakpoint list is thread safe, no need to lock
Greg Clayton0416bdf2012-01-30 09:04:36 +0000843 *sb_breakpoint = target_sp->GetBreakpointList().GetBreakpointAtIndex(idx);
Greg Claytonbdcda462010-12-20 20:49:23 +0000844 }
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000845 return sb_breakpoint;
846}
Chris Lattner24943d22010-06-08 16:52:24 +0000847
848bool
849SBTarget::BreakpointDelete (break_id_t bp_id)
850{
Greg Claytone005f2c2010-11-06 01:53:30 +0000851 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000852
Caroline Tice7826c882010-10-26 03:11:13 +0000853 bool result = false;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000854 TargetSP target_sp(GetSP());
855 if (target_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000856 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000857 Mutex::Locker api_locker (target_sp->GetAPIMutex());
858 result = target_sp->RemoveBreakpointByID (bp_id);
Greg Claytonbdcda462010-12-20 20:49:23 +0000859 }
Caroline Tice7826c882010-10-26 03:11:13 +0000860
861 if (log)
862 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000863 log->Printf ("SBTarget(%p)::BreakpointDelete (bp_id=%d) => %i", target_sp.get(), (uint32_t) bp_id, result);
Caroline Tice7826c882010-10-26 03:11:13 +0000864 }
865
866 return result;
Chris Lattner24943d22010-06-08 16:52:24 +0000867}
868
Johnny Chen096c2932011-09-26 22:40:50 +0000869SBBreakpoint
870SBTarget::FindBreakpointByID (break_id_t bp_id)
871{
872 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
873
874 SBBreakpoint sb_breakpoint;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000875 TargetSP target_sp(GetSP());
876 if (target_sp && bp_id != LLDB_INVALID_BREAK_ID)
Johnny Chen096c2932011-09-26 22:40:50 +0000877 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000878 Mutex::Locker api_locker (target_sp->GetAPIMutex());
879 *sb_breakpoint = target_sp->GetBreakpointByID (bp_id);
Johnny Chen096c2932011-09-26 22:40:50 +0000880 }
881
882 if (log)
883 {
884 log->Printf ("SBTarget(%p)::FindBreakpointByID (bp_id=%d) => SBBreakpoint(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +0000885 target_sp.get(), (uint32_t) bp_id, sb_breakpoint.get());
Johnny Chen096c2932011-09-26 22:40:50 +0000886 }
887
888 return sb_breakpoint;
889}
890
Chris Lattner24943d22010-06-08 16:52:24 +0000891bool
892SBTarget::EnableAllBreakpoints ()
893{
Greg Clayton0416bdf2012-01-30 09:04:36 +0000894 TargetSP target_sp(GetSP());
895 if (target_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000896 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000897 Mutex::Locker api_locker (target_sp->GetAPIMutex());
898 target_sp->EnableAllBreakpoints ();
Chris Lattner24943d22010-06-08 16:52:24 +0000899 return true;
900 }
901 return false;
902}
903
904bool
905SBTarget::DisableAllBreakpoints ()
906{
Greg Clayton0416bdf2012-01-30 09:04:36 +0000907 TargetSP target_sp(GetSP());
908 if (target_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000909 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000910 Mutex::Locker api_locker (target_sp->GetAPIMutex());
911 target_sp->DisableAllBreakpoints ();
Chris Lattner24943d22010-06-08 16:52:24 +0000912 return true;
913 }
914 return false;
915}
916
917bool
918SBTarget::DeleteAllBreakpoints ()
919{
Greg Clayton0416bdf2012-01-30 09:04:36 +0000920 TargetSP target_sp(GetSP());
921 if (target_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000922 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000923 Mutex::Locker api_locker (target_sp->GetAPIMutex());
924 target_sp->RemoveAllBreakpoints ();
Chris Lattner24943d22010-06-08 16:52:24 +0000925 return true;
926 }
927 return false;
928}
929
Johnny Chen096c2932011-09-26 22:40:50 +0000930uint32_t
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000931SBTarget::GetNumWatchpoints () const
Johnny Chen096c2932011-09-26 22:40:50 +0000932{
Greg Clayton0416bdf2012-01-30 09:04:36 +0000933 TargetSP target_sp(GetSP());
934 if (target_sp)
Johnny Chen096c2932011-09-26 22:40:50 +0000935 {
Johnny Chenecd4feb2011-10-14 00:42:25 +0000936 // The watchpoint list is thread safe, no need to lock
Greg Clayton0416bdf2012-01-30 09:04:36 +0000937 return target_sp->GetWatchpointList().GetSize();
Johnny Chen096c2932011-09-26 22:40:50 +0000938 }
939 return 0;
940}
941
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000942SBWatchpoint
943SBTarget::GetWatchpointAtIndex (uint32_t idx) const
Johnny Chen5eb54bb2011-09-27 20:29:45 +0000944{
Johnny Chenecd4feb2011-10-14 00:42:25 +0000945 SBWatchpoint sb_watchpoint;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000946 TargetSP target_sp(GetSP());
947 if (target_sp)
Johnny Chen096c2932011-09-26 22:40:50 +0000948 {
Johnny Chenecd4feb2011-10-14 00:42:25 +0000949 // The watchpoint list is thread safe, no need to lock
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000950 sb_watchpoint.SetSP (target_sp->GetWatchpointList().GetByIndex(idx));
Johnny Chen096c2932011-09-26 22:40:50 +0000951 }
Johnny Chenecd4feb2011-10-14 00:42:25 +0000952 return sb_watchpoint;
Johnny Chen096c2932011-09-26 22:40:50 +0000953}
954
955bool
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000956SBTarget::DeleteWatchpoint (watch_id_t wp_id)
Johnny Chen096c2932011-09-26 22:40:50 +0000957{
958 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
959
960 bool result = false;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000961 TargetSP target_sp(GetSP());
962 if (target_sp)
Johnny Chen096c2932011-09-26 22:40:50 +0000963 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000964 Mutex::Locker api_locker (target_sp->GetAPIMutex());
965 result = target_sp->RemoveWatchpointByID (wp_id);
Johnny Chen096c2932011-09-26 22:40:50 +0000966 }
967
968 if (log)
969 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000970 log->Printf ("SBTarget(%p)::WatchpointDelete (wp_id=%d) => %i", target_sp.get(), (uint32_t) wp_id, result);
Johnny Chen096c2932011-09-26 22:40:50 +0000971 }
972
973 return result;
974}
975
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000976SBWatchpoint
977SBTarget::FindWatchpointByID (lldb::watch_id_t wp_id)
Johnny Chen096c2932011-09-26 22:40:50 +0000978{
979 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
980
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000981 SBWatchpoint sb_watchpoint;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000982 lldb::WatchpointSP watchpoint_sp;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000983 TargetSP target_sp(GetSP());
984 if (target_sp && wp_id != LLDB_INVALID_WATCH_ID)
Johnny Chen096c2932011-09-26 22:40:50 +0000985 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000986 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000987 watchpoint_sp = target_sp->GetWatchpointList().FindByID(wp_id);
988 sb_watchpoint.SetSP (watchpoint_sp);
Johnny Chen096c2932011-09-26 22:40:50 +0000989 }
990
991 if (log)
992 {
Johnny Chenecd4feb2011-10-14 00:42:25 +0000993 log->Printf ("SBTarget(%p)::FindWatchpointByID (bp_id=%d) => SBWatchpoint(%p)",
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000994 target_sp.get(), (uint32_t) wp_id, watchpoint_sp.get());
Johnny Chen096c2932011-09-26 22:40:50 +0000995 }
996
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000997 return sb_watchpoint;
998}
999
1000lldb::SBWatchpoint
1001SBTarget::WatchAddress (lldb::addr_t addr, size_t size, bool read, bool write)
1002{
1003 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1004
1005 SBWatchpoint sb_watchpoint;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001006 lldb::WatchpointSP watchpoint_sp;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001007 TargetSP target_sp(GetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001008 if (target_sp && (read || write) && addr != LLDB_INVALID_ADDRESS && size > 0)
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001009 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001010 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001011 uint32_t watch_type = 0;
1012 if (read)
1013 watch_type |= LLDB_WATCH_TYPE_READ;
1014 if (write)
1015 watch_type |= LLDB_WATCH_TYPE_WRITE;
1016 watchpoint_sp = target_sp->CreateWatchpoint(addr, size, watch_type);
1017 sb_watchpoint.SetSP (watchpoint_sp);
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001018 }
1019
1020 if (log)
1021 {
1022 log->Printf ("SBTarget(%p)::WatchAddress (addr=0x%llx, 0x%u) => SBWatchpoint(%p)",
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001023 target_sp.get(), addr, (uint32_t) size, watchpoint_sp.get());
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001024 }
1025
1026 return sb_watchpoint;
Johnny Chen096c2932011-09-26 22:40:50 +00001027}
1028
1029bool
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001030SBTarget::EnableAllWatchpoints ()
Johnny Chen096c2932011-09-26 22:40:50 +00001031{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001032 TargetSP target_sp(GetSP());
1033 if (target_sp)
Johnny Chen096c2932011-09-26 22:40:50 +00001034 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001035 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1036 target_sp->EnableAllWatchpoints ();
Johnny Chen096c2932011-09-26 22:40:50 +00001037 return true;
1038 }
1039 return false;
1040}
1041
1042bool
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001043SBTarget::DisableAllWatchpoints ()
Johnny Chen096c2932011-09-26 22:40:50 +00001044{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001045 TargetSP target_sp(GetSP());
1046 if (target_sp)
Johnny Chen096c2932011-09-26 22:40:50 +00001047 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001048 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1049 target_sp->DisableAllWatchpoints ();
Johnny Chen096c2932011-09-26 22:40:50 +00001050 return true;
1051 }
1052 return false;
1053}
1054
1055bool
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001056SBTarget::DeleteAllWatchpoints ()
Johnny Chen096c2932011-09-26 22:40:50 +00001057{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001058 TargetSP target_sp(GetSP());
1059 if (target_sp)
Johnny Chen096c2932011-09-26 22:40:50 +00001060 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001061 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1062 target_sp->RemoveAllWatchpoints ();
Johnny Chen096c2932011-09-26 22:40:50 +00001063 return true;
1064 }
1065 return false;
1066}
1067
Chris Lattner24943d22010-06-08 16:52:24 +00001068
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001069lldb::SBModule
1070SBTarget::AddModule (const char *path,
1071 const char *triple,
1072 const char *uuid_cstr)
1073{
1074 lldb::SBModule sb_module;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001075 TargetSP target_sp(GetSP());
1076 if (target_sp)
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001077 {
1078 FileSpec module_file_spec;
1079 UUID module_uuid;
1080 ArchSpec module_arch;
1081
1082 if (path)
1083 module_file_spec.SetFile(path, false);
1084
1085 if (uuid_cstr)
1086 module_uuid.SetfromCString(uuid_cstr);
1087
1088 if (triple)
Greg Clayton0416bdf2012-01-30 09:04:36 +00001089 module_arch.SetTriple (triple, target_sp->GetPlatform ().get());
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001090
Greg Clayton0416bdf2012-01-30 09:04:36 +00001091 sb_module.SetSP(target_sp->GetSharedModule (module_file_spec,
1092 module_arch,
1093 uuid_cstr ? &module_uuid : NULL));
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001094 }
1095 return sb_module;
1096}
1097
1098bool
1099SBTarget::AddModule (lldb::SBModule &module)
1100{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001101 TargetSP target_sp(GetSP());
1102 if (target_sp)
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001103 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001104 target_sp->GetImages().AppendIfNeeded (module.GetSP());
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001105 return true;
1106 }
1107 return false;
1108}
1109
Chris Lattner24943d22010-06-08 16:52:24 +00001110uint32_t
1111SBTarget::GetNumModules () const
1112{
Greg Claytone005f2c2010-11-06 01:53:30 +00001113 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001114
Caroline Tice7826c882010-10-26 03:11:13 +00001115 uint32_t num = 0;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001116 TargetSP target_sp(GetSP());
1117 if (target_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +00001118 {
1119 // The module list is thread safe, no need to lock
Greg Clayton0416bdf2012-01-30 09:04:36 +00001120 num = target_sp->GetImages().GetSize();
Greg Claytonbdcda462010-12-20 20:49:23 +00001121 }
Caroline Tice7826c882010-10-26 03:11:13 +00001122
1123 if (log)
Greg Clayton0416bdf2012-01-30 09:04:36 +00001124 log->Printf ("SBTarget(%p)::GetNumModules () => %d", target_sp.get(), num);
Caroline Tice7826c882010-10-26 03:11:13 +00001125
1126 return num;
Chris Lattner24943d22010-06-08 16:52:24 +00001127}
1128
Greg Clayton43490d12010-07-30 20:12:55 +00001129void
1130SBTarget::Clear ()
1131{
Greg Claytone005f2c2010-11-06 01:53:30 +00001132 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001133
1134 if (log)
Greg Clayton3f5ee7f2010-10-29 04:59:35 +00001135 log->Printf ("SBTarget(%p)::Clear ()", m_opaque_sp.get());
Caroline Tice7826c882010-10-26 03:11:13 +00001136
Greg Clayton43490d12010-07-30 20:12:55 +00001137 m_opaque_sp.reset();
1138}
1139
1140
Chris Lattner24943d22010-06-08 16:52:24 +00001141SBModule
1142SBTarget::FindModule (const SBFileSpec &sb_file_spec)
1143{
1144 SBModule sb_module;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001145 TargetSP target_sp(GetSP());
1146 if (target_sp && sb_file_spec.IsValid())
Greg Claytonbdcda462010-12-20 20:49:23 +00001147 {
1148 // The module list is thread safe, no need to lock
Greg Clayton0416bdf2012-01-30 09:04:36 +00001149 sb_module.SetSP (target_sp->GetImages().FindFirstModuleForFileSpec (*sb_file_spec, NULL, NULL));
Greg Claytonbdcda462010-12-20 20:49:23 +00001150 }
Chris Lattner24943d22010-06-08 16:52:24 +00001151 return sb_module;
1152}
1153
Greg Clayton1b925202012-01-29 06:07:39 +00001154lldb::ByteOrder
1155SBTarget::GetByteOrder ()
1156{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001157 TargetSP target_sp(GetSP());
1158 if (target_sp)
1159 return target_sp->GetArchitecture().GetByteOrder();
Greg Clayton1b925202012-01-29 06:07:39 +00001160 return eByteOrderInvalid;
1161}
1162
1163const char *
1164SBTarget::GetTriple ()
1165{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001166 TargetSP target_sp(GetSP());
1167 if (target_sp)
Greg Clayton1b925202012-01-29 06:07:39 +00001168 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001169 std::string triple (target_sp->GetArchitecture().GetTriple().str());
Greg Clayton1b925202012-01-29 06:07:39 +00001170 // Unique the string so we don't run into ownership issues since
1171 // the const strings put the string into the string pool once and
1172 // the strings never comes out
1173 ConstString const_triple (triple.c_str());
1174 return const_triple.GetCString();
1175 }
1176 return NULL;
1177}
1178
1179uint32_t
1180SBTarget::GetAddressByteSize()
1181{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001182 TargetSP target_sp(GetSP());
1183 if (target_sp)
1184 return target_sp->GetArchitecture().GetAddressByteSize();
Greg Clayton1b925202012-01-29 06:07:39 +00001185 return sizeof(void*);
1186}
1187
1188
Chris Lattner24943d22010-06-08 16:52:24 +00001189SBModule
1190SBTarget::GetModuleAtIndex (uint32_t idx)
1191{
Greg Claytone005f2c2010-11-06 01:53:30 +00001192 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001193
Chris Lattner24943d22010-06-08 16:52:24 +00001194 SBModule sb_module;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001195 ModuleSP module_sp;
1196 TargetSP target_sp(GetSP());
1197 if (target_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +00001198 {
1199 // The module list is thread safe, no need to lock
Greg Clayton0416bdf2012-01-30 09:04:36 +00001200 module_sp = target_sp->GetImages().GetModuleAtIndex(idx);
1201 sb_module.SetSP (module_sp);
Greg Claytonbdcda462010-12-20 20:49:23 +00001202 }
Caroline Tice7826c882010-10-26 03:11:13 +00001203
1204 if (log)
1205 {
Greg Clayton49ce6822010-10-31 03:01:06 +00001206 log->Printf ("SBTarget(%p)::GetModuleAtIndex (idx=%d) => SBModule(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +00001207 target_sp.get(), idx, module_sp.get());
Caroline Tice7826c882010-10-26 03:11:13 +00001208 }
1209
Chris Lattner24943d22010-06-08 16:52:24 +00001210 return sb_module;
1211}
1212
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001213bool
1214SBTarget::RemoveModule (lldb::SBModule module)
1215{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001216 TargetSP target_sp(GetSP());
1217 if (target_sp)
1218 return target_sp->GetImages().Remove(module.GetSP());
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001219 return false;
1220}
1221
Chris Lattner24943d22010-06-08 16:52:24 +00001222
1223SBBroadcaster
1224SBTarget::GetBroadcaster () const
1225{
Greg Claytone005f2c2010-11-06 01:53:30 +00001226 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001227
Greg Clayton0416bdf2012-01-30 09:04:36 +00001228 TargetSP target_sp(GetSP());
1229 SBBroadcaster broadcaster(target_sp.get(), false);
Caroline Tice7826c882010-10-26 03:11:13 +00001230
1231 if (log)
Greg Clayton3f5ee7f2010-10-29 04:59:35 +00001232 log->Printf ("SBTarget(%p)::GetBroadcaster () => SBBroadcaster(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +00001233 target_sp.get(), broadcaster.get());
Caroline Tice7826c882010-10-26 03:11:13 +00001234
Chris Lattner24943d22010-06-08 16:52:24 +00001235 return broadcaster;
1236}
1237
Caroline Tice98f930f2010-09-20 05:20:02 +00001238
1239bool
Caroline Tice7826c882010-10-26 03:11:13 +00001240SBTarget::GetDescription (SBStream &description, lldb::DescriptionLevel description_level)
Caroline Tice98f930f2010-09-20 05:20:02 +00001241{
Greg Clayton96154be2011-11-13 06:57:31 +00001242 Stream &strm = description.ref();
1243
Greg Clayton0416bdf2012-01-30 09:04:36 +00001244 TargetSP target_sp(GetSP());
1245 if (target_sp)
Caroline Ticee7a566e2010-09-20 16:21:41 +00001246 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001247 target_sp->Dump (&strm, description_level);
Caroline Tice7826c882010-10-26 03:11:13 +00001248 }
1249 else
Greg Clayton96154be2011-11-13 06:57:31 +00001250 strm.PutCString ("No value");
Caroline Tice7826c882010-10-26 03:11:13 +00001251
1252 return true;
1253}
1254
Greg Clayton7dd5c512012-02-06 01:44:54 +00001255lldb::SBSymbolContextList
1256SBTarget::FindFunctions (const char *name, uint32_t name_type_mask)
Greg Clayton4ed315f2011-06-21 01:34:41 +00001257{
Greg Clayton7dd5c512012-02-06 01:44:54 +00001258 lldb::SBSymbolContextList sb_sc_list;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001259 if (name && name[0])
Greg Clayton4ed315f2011-06-21 01:34:41 +00001260 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001261 TargetSP target_sp(GetSP());
1262 if (target_sp)
1263 {
1264 const bool symbols_ok = true;
Greg Clayton7dd5c512012-02-06 01:44:54 +00001265 const bool append = true;
1266 target_sp->GetImages().FindFunctions (ConstString(name),
1267 name_type_mask,
1268 symbols_ok,
1269 append,
1270 *sb_sc_list);
Greg Clayton0416bdf2012-01-30 09:04:36 +00001271 }
Greg Clayton4ed315f2011-06-21 01:34:41 +00001272 }
Greg Clayton7dd5c512012-02-06 01:44:54 +00001273 return sb_sc_list;
Greg Clayton4ed315f2011-06-21 01:34:41 +00001274}
1275
Enrico Granata979e20d2011-07-29 19:53:35 +00001276lldb::SBType
1277SBTarget::FindFirstType (const char* type)
1278{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001279 TargetSP target_sp(GetSP());
1280 if (type && target_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +00001281 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001282 size_t count = target_sp->GetImages().GetSize();
Enrico Granata979e20d2011-07-29 19:53:35 +00001283 for (size_t idx = 0; idx < count; idx++)
1284 {
1285 SBType found_at_idx = GetModuleAtIndex(idx).FindFirstType(type);
1286
1287 if (found_at_idx.IsValid())
1288 return found_at_idx;
1289 }
1290 }
1291 return SBType();
1292}
1293
1294lldb::SBTypeList
1295SBTarget::FindTypes (const char* type)
1296{
1297
1298 SBTypeList retval;
1299
Greg Clayton0416bdf2012-01-30 09:04:36 +00001300 TargetSP target_sp(GetSP());
1301 if (type && target_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +00001302 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001303 ModuleList& images = target_sp->GetImages();
Enrico Granata979e20d2011-07-29 19:53:35 +00001304 ConstString name_const(type);
1305 SymbolContext sc;
1306 TypeList type_list;
1307
1308 uint32_t num_matches = images.FindTypes(sc,
1309 name_const,
1310 true,
1311 UINT32_MAX,
1312 type_list);
1313
1314 for (size_t idx = 0; idx < num_matches; idx++)
1315 {
Greg Clayton0fb0bcc2011-08-03 22:57:10 +00001316 TypeSP type_sp (type_list.GetTypeAtIndex(idx));
1317 if (type_sp)
1318 retval.Append(SBType(type_sp));
Enrico Granata979e20d2011-07-29 19:53:35 +00001319 }
1320 }
1321 return retval;
1322}
1323
Greg Clayton917c0002011-06-29 22:09:02 +00001324SBValueList
1325SBTarget::FindGlobalVariables (const char *name, uint32_t max_matches)
1326{
1327 SBValueList sb_value_list;
1328
Greg Clayton0416bdf2012-01-30 09:04:36 +00001329 TargetSP target_sp(GetSP());
1330 if (name && target_sp)
Greg Clayton917c0002011-06-29 22:09:02 +00001331 {
1332 VariableList variable_list;
1333 const bool append = true;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001334 const uint32_t match_count = target_sp->GetImages().FindGlobalVariables (ConstString (name),
1335 append,
1336 max_matches,
1337 variable_list);
Greg Clayton917c0002011-06-29 22:09:02 +00001338
1339 if (match_count > 0)
1340 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001341 ExecutionContextScope *exe_scope = target_sp->GetProcessSP().get();
Greg Clayton917c0002011-06-29 22:09:02 +00001342 if (exe_scope == NULL)
Greg Clayton0416bdf2012-01-30 09:04:36 +00001343 exe_scope = target_sp.get();
Greg Clayton917c0002011-06-29 22:09:02 +00001344 ValueObjectList &value_object_list = sb_value_list.ref();
1345 for (uint32_t i=0; i<match_count; ++i)
1346 {
1347 lldb::ValueObjectSP valobj_sp (ValueObjectVariable::Create (exe_scope, variable_list.GetVariableAtIndex(i)));
1348 if (valobj_sp)
1349 value_object_list.Append(valobj_sp);
1350 }
1351 }
1352 }
1353
1354 return sb_value_list;
1355}
1356
Jim Inghamcc637462011-09-13 00:29:56 +00001357SBSourceManager
1358SBTarget::GetSourceManager()
1359{
1360 SBSourceManager source_manager (*this);
1361 return source_manager;
1362}
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001363
Sean Callananef1f6902011-12-14 23:49:37 +00001364lldb::SBInstructionList
1365SBTarget::GetInstructions (lldb::SBAddress base_addr, const void *buf, size_t size)
1366{
1367 SBInstructionList sb_instructions;
1368
Greg Clayton0416bdf2012-01-30 09:04:36 +00001369 TargetSP target_sp(GetSP());
1370 if (target_sp)
Sean Callananef1f6902011-12-14 23:49:37 +00001371 {
1372 Address addr;
1373
1374 if (base_addr.get())
1375 addr = *base_addr.get();
1376
Greg Clayton0416bdf2012-01-30 09:04:36 +00001377 sb_instructions.SetDisassembler (Disassembler::DisassembleBytes (target_sp->GetArchitecture(),
Sean Callananef1f6902011-12-14 23:49:37 +00001378 NULL,
1379 addr,
1380 buf,
1381 size));
1382 }
1383
1384 return sb_instructions;
1385}
1386
1387lldb::SBInstructionList
1388SBTarget::GetInstructions (lldb::addr_t base_addr, const void *buf, size_t size)
1389{
1390 return GetInstructions (ResolveLoadAddress(base_addr), buf, size);
1391}
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001392
1393SBError
1394SBTarget::SetSectionLoadAddress (lldb::SBSection section,
1395 lldb::addr_t section_base_addr)
1396{
1397 SBError sb_error;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001398 TargetSP target_sp(GetSP());
1399 if (target_sp)
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001400 {
1401 if (!section.IsValid())
1402 {
1403 sb_error.SetErrorStringWithFormat ("invalid section");
1404 }
1405 else
1406 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001407 target_sp->GetSectionLoadList().SetSectionLoadAddress (section.GetSection(), section_base_addr);
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001408 }
1409 }
1410 else
1411 {
1412 sb_error.SetErrorStringWithFormat ("invalid target");
1413 }
1414 return sb_error;
1415}
1416
1417SBError
1418SBTarget::ClearSectionLoadAddress (lldb::SBSection section)
1419{
1420 SBError sb_error;
1421
Greg Clayton0416bdf2012-01-30 09:04:36 +00001422 TargetSP target_sp(GetSP());
1423 if (target_sp)
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001424 {
1425 if (!section.IsValid())
1426 {
1427 sb_error.SetErrorStringWithFormat ("invalid section");
1428 }
1429 else
1430 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001431 target_sp->GetSectionLoadList().SetSectionUnloaded (section.GetSection());
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001432 }
1433 }
1434 else
1435 {
1436 sb_error.SetErrorStringWithFormat ("invalid target");
1437 }
1438 return sb_error;
1439}
1440
1441SBError
1442SBTarget::SetModuleLoadAddress (lldb::SBModule module, int64_t slide_offset)
1443{
1444 SBError sb_error;
1445
1446 char path[PATH_MAX];
Greg Clayton0416bdf2012-01-30 09:04:36 +00001447 TargetSP target_sp(GetSP());
1448 if (target_sp)
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001449 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001450 ModuleSP module_sp (module.GetSP());
1451 if (module_sp)
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001452 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001453 ObjectFile *objfile = module_sp->GetObjectFile();
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001454 if (objfile)
1455 {
1456 SectionList *section_list = objfile->GetSectionList();
1457 if (section_list)
1458 {
1459 const size_t num_sections = section_list->GetSize();
1460 for (size_t sect_idx = 0; sect_idx < num_sections; ++sect_idx)
1461 {
1462 SectionSP section_sp (section_list->GetSectionAtIndex(sect_idx));
1463 if (section_sp)
Greg Clayton0416bdf2012-01-30 09:04:36 +00001464 target_sp->GetSectionLoadList().SetSectionLoadAddress (section_sp.get(), section_sp->GetFileAddress() + slide_offset);
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001465 }
1466 }
1467 else
1468 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001469 module_sp->GetFileSpec().GetPath (path, sizeof(path));
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001470 sb_error.SetErrorStringWithFormat ("no sections in object file '%s'", path);
1471 }
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 object file for module '%s'", path);
1477 }
1478 }
Greg Clayton0416bdf2012-01-30 09:04:36 +00001479 else
1480 {
1481 sb_error.SetErrorStringWithFormat ("invalid module");
1482 }
1483
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001484 }
1485 else
1486 {
1487 sb_error.SetErrorStringWithFormat ("invalid target");
1488 }
1489 return sb_error;
1490}
1491
1492SBError
1493SBTarget::ClearModuleLoadAddress (lldb::SBModule module)
1494{
1495 SBError sb_error;
1496
1497 char path[PATH_MAX];
Greg Clayton0416bdf2012-01-30 09:04:36 +00001498 TargetSP target_sp(GetSP());
1499 if (target_sp)
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001500 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001501 ModuleSP module_sp (module.GetSP());
1502 if (module_sp)
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001503 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001504 ObjectFile *objfile = module_sp->GetObjectFile();
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001505 if (objfile)
1506 {
1507 SectionList *section_list = objfile->GetSectionList();
1508 if (section_list)
1509 {
1510 const size_t num_sections = section_list->GetSize();
1511 for (size_t sect_idx = 0; sect_idx < num_sections; ++sect_idx)
1512 {
1513 SectionSP section_sp (section_list->GetSectionAtIndex(sect_idx));
1514 if (section_sp)
Greg Clayton0416bdf2012-01-30 09:04:36 +00001515 target_sp->GetSectionLoadList().SetSectionUnloaded (section_sp.get());
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001516 }
1517 }
1518 else
1519 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001520 module_sp->GetFileSpec().GetPath (path, sizeof(path));
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001521 sb_error.SetErrorStringWithFormat ("no sections in object file '%s'", path);
1522 }
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 object file for module '%s'", path);
1528 }
1529 }
Greg Clayton0416bdf2012-01-30 09:04:36 +00001530 else
1531 {
1532 sb_error.SetErrorStringWithFormat ("invalid module");
1533 }
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001534 }
1535 else
1536 {
1537 sb_error.SetErrorStringWithFormat ("invalid target");
1538 }
1539 return sb_error;
1540}
1541
1542