blob: cc5535691e45befea7284115a4fd3f8a75a27fe7 [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{
Caroline Tice7826c882010-10-26 03:11:13 +000099
Chris Lattner24943d22010-06-08 16:52:24 +0000100 SBProcess sb_process;
Greg Clayton63094e02010-06-23 01:19:29 +0000101 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000102 {
103 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
Greg Clayton63094e02010-06-23 01:19:29 +0000104 sb_process.SetProcess (m_opaque_sp->GetProcessSP());
Greg Claytonbdcda462010-12-20 20:49:23 +0000105 }
Caroline Tice7826c882010-10-26 03:11:13 +0000106
Greg Claytone005f2c2010-11-06 01:53:30 +0000107 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000108 if (log)
109 {
Greg Clayton49ce6822010-10-31 03:01:06 +0000110 log->Printf ("SBTarget(%p)::GetProcess () => SBProcess(%p)",
111 m_opaque_sp.get(), sb_process.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000112 }
113
Chris Lattner24943d22010-06-08 16:52:24 +0000114 return sb_process;
115}
116
Greg Clayton63094e02010-06-23 01:19:29 +0000117SBDebugger
118SBTarget::GetDebugger () const
119{
120 SBDebugger debugger;
121 if (m_opaque_sp)
122 debugger.reset (m_opaque_sp->GetDebugger().GetSP());
123 return debugger;
124}
125
Jim Inghamb5871fe2011-03-31 00:01:24 +0000126SBProcess
127SBTarget::LaunchSimple
128(
129 char const **argv,
130 char const **envp,
131 const char *working_directory
132)
133{
134 char *stdin_path = NULL;
135 char *stdout_path = NULL;
136 char *stderr_path = NULL;
137 uint32_t launch_flags = 0;
138 bool stop_at_entry = false;
139 SBError error;
140 SBListener listener = GetDebugger().GetListener();
141 return Launch (listener,
142 argv,
143 envp,
144 stdin_path,
145 stdout_path,
146 stderr_path,
147 working_directory,
148 launch_flags,
149 stop_at_entry,
150 error);
151}
Greg Claytonde915be2011-01-23 05:56:20 +0000152
153SBProcess
154SBTarget::Launch
155(
Greg Clayton271a5db2011-02-03 21:28:34 +0000156 SBListener &listener,
Greg Claytonde915be2011-01-23 05:56:20 +0000157 char const **argv,
158 char const **envp,
159 const char *stdin_path,
160 const char *stdout_path,
161 const char *stderr_path,
162 const char *working_directory,
163 uint32_t launch_flags, // See LaunchFlags
164 bool stop_at_entry,
165 lldb::SBError& error
166)
167{
Greg Claytone005f2c2010-11-06 01:53:30 +0000168 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000169
170 if (log)
Greg Clayton3f5ee7f2010-10-29 04:59:35 +0000171 {
Greg Claytonde915be2011-01-23 05:56:20 +0000172 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))...",
173 m_opaque_sp.get(),
174 argv,
175 envp,
176 stdin_path ? stdin_path : "NULL",
177 stdout_path ? stdout_path : "NULL",
178 stderr_path ? stderr_path : "NULL",
179 working_directory ? working_directory : "NULL",
180 launch_flags,
181 stop_at_entry,
182 error.get());
Greg Clayton3f5ee7f2010-10-29 04:59:35 +0000183 }
Greg Clayton1a3083a2010-10-06 03:53:16 +0000184 SBProcess sb_process;
185 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000186 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000187 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
Greg Clayton1a3083a2010-10-06 03:53:16 +0000188
Greg Clayton7c330d62011-01-27 01:01:10 +0000189 if (getenv("LLDB_LAUNCH_FLAG_DISABLE_ASLR"))
190 launch_flags |= eLaunchFlagDisableASLR;
191
Greg Clayton180546b2011-04-30 01:09:13 +0000192 StateType state = eStateInvalid;
193 sb_process.SetProcess (m_opaque_sp->GetProcessSP());
194 if (sb_process.IsValid())
Greg Clayton28d5fcc2011-01-27 06:44:37 +0000195 {
Greg Clayton180546b2011-04-30 01:09:13 +0000196 state = sb_process->GetState();
197
198 if (sb_process->IsAlive() && state != eStateConnected)
199 {
200 if (state == eStateAttaching)
201 error.SetErrorString ("process attach is in progress");
202 else
203 error.SetErrorString ("a process is already being debugged");
204 sb_process.Clear();
205 return sb_process;
206 }
Greg Clayton28d5fcc2011-01-27 06:44:37 +0000207 }
208
Greg Clayton180546b2011-04-30 01:09:13 +0000209 if (state == eStateConnected)
210 {
211 // If we are already connected, then we have already specified the
212 // listener, so if a valid listener is supplied, we need to error out
213 // to let the client know.
214 if (listener.IsValid())
215 {
216 error.SetErrorString ("process is connected and already has a listener, pass empty listener");
217 sb_process.Clear();
218 return sb_process;
219 }
220 }
221 else
Greg Claytonc5f728c2010-10-06 22:10:17 +0000222 {
Greg Clayton271a5db2011-02-03 21:28:34 +0000223 if (listener.IsValid())
224 sb_process.SetProcess (m_opaque_sp->CreateProcess (listener.ref()));
225 else
226 sb_process.SetProcess (m_opaque_sp->CreateProcess (m_opaque_sp->GetDebugger().GetListener()));
Greg Clayton180546b2011-04-30 01:09:13 +0000227 }
Greg Clayton7c330d62011-01-27 01:01:10 +0000228
Greg Clayton180546b2011-04-30 01:09:13 +0000229 if (sb_process.IsValid())
230 {
231 if (getenv("LLDB_LAUNCH_FLAG_DISABLE_STDIO"))
232 launch_flags |= eLaunchFlagDisableSTDIO;
233
Greg Clayton36bc5ea2011-11-03 21:22:33 +0000234 ProcessLaunchInfo launch_info (stdin_path, stdout_path, stderr_path, working_directory, launch_flags);
235
236 Module *exe_module = m_opaque_sp->GetExecutableModulePointer();
237 if (exe_module)
Greg Clayton1d1f39e2011-11-29 04:03:30 +0000238 launch_info.SetExecutableFile(exe_module->GetPlatformFileSpec(), true);
Greg Clayton36bc5ea2011-11-03 21:22:33 +0000239 if (argv)
240 launch_info.GetArguments().AppendArguments (argv);
241 if (envp)
242 launch_info.GetEnvironmentEntries ().SetArguments (envp);
243
244 error.SetError (sb_process->Launch (launch_info));
Greg Clayton180546b2011-04-30 01:09:13 +0000245 if (error.Success())
Greg Clayton7c330d62011-01-27 01:01:10 +0000246 {
Greg Clayton180546b2011-04-30 01:09:13 +0000247 // We we are stopping at the entry point, we can return now!
248 if (stop_at_entry)
249 return sb_process;
Greg Clayton7c330d62011-01-27 01:01:10 +0000250
Greg Clayton180546b2011-04-30 01:09:13 +0000251 // Make sure we are stopped at the entry
252 StateType state = sb_process->WaitForProcessToStop (NULL);
253 if (state == eStateStopped)
Greg Clayton7c330d62011-01-27 01:01:10 +0000254 {
Greg Clayton180546b2011-04-30 01:09:13 +0000255 // resume the process to skip the entry point
256 error.SetError (sb_process->Resume());
257 if (error.Success())
Greg Clayton7c330d62011-01-27 01:01:10 +0000258 {
Greg Clayton180546b2011-04-30 01:09:13 +0000259 // If we are doing synchronous mode, then wait for the
260 // process to stop yet again!
261 if (m_opaque_sp->GetDebugger().GetAsyncExecution () == false)
262 sb_process->WaitForProcessToStop (NULL);
Greg Clayton7c330d62011-01-27 01:01:10 +0000263 }
264 }
265 }
Greg Clayton180546b2011-04-30 01:09:13 +0000266 }
267 else
268 {
269 error.SetErrorString ("unable to create lldb_private::Process");
Greg Claytonc5f728c2010-10-06 22:10:17 +0000270 }
271 }
272 else
273 {
274 error.SetErrorString ("SBTarget is invalid");
Chris Lattner24943d22010-06-08 16:52:24 +0000275 }
Caroline Tice7826c882010-10-26 03:11:13 +0000276
Caroline Tice926060e2010-10-29 21:48:37 +0000277 log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
Caroline Tice7826c882010-10-26 03:11:13 +0000278 if (log)
279 {
Greg Clayton49ce6822010-10-31 03:01:06 +0000280 log->Printf ("SBTarget(%p)::Launch (...) => SBProceess(%p)",
281 m_opaque_sp.get(), sb_process.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000282 }
283
Greg Clayton1a3083a2010-10-06 03:53:16 +0000284 return sb_process;
Chris Lattner24943d22010-06-08 16:52:24 +0000285}
286
Greg Claytonc5f728c2010-10-06 22:10:17 +0000287
288lldb::SBProcess
Greg Claytond8c62532010-10-07 04:19:01 +0000289SBTarget::AttachToProcessWithID
Greg Claytonc5f728c2010-10-06 22:10:17 +0000290(
Greg Clayton271a5db2011-02-03 21:28:34 +0000291 SBListener &listener,
Greg Claytonc5f728c2010-10-06 22:10:17 +0000292 lldb::pid_t pid,// The process ID to attach to
293 SBError& error // An error explaining what went wrong if attach fails
294)
295{
296 SBProcess sb_process;
297 if (m_opaque_sp)
298 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000299 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
Greg Claytonde1dd812011-06-24 03:21:43 +0000300
301 StateType state = eStateInvalid;
302 sb_process.SetProcess (m_opaque_sp->GetProcessSP());
303 if (sb_process.IsValid())
304 {
305 state = sb_process->GetState();
306
307 if (sb_process->IsAlive() && state != eStateConnected)
308 {
309 if (state == eStateAttaching)
310 error.SetErrorString ("process attach is in progress");
311 else
312 error.SetErrorString ("a process is already being debugged");
313 sb_process.Clear();
314 return sb_process;
315 }
316 }
317
318 if (state == eStateConnected)
319 {
320 // If we are already connected, then we have already specified the
321 // listener, so if a valid listener is supplied, we need to error out
322 // to let the client know.
323 if (listener.IsValid())
324 {
325 error.SetErrorString ("process is connected and already has a listener, pass empty listener");
326 sb_process.Clear();
327 return sb_process;
328 }
329 }
Greg Clayton271a5db2011-02-03 21:28:34 +0000330 else
Greg Claytonde1dd812011-06-24 03:21:43 +0000331 {
332 if (listener.IsValid())
333 sb_process.SetProcess (m_opaque_sp->CreateProcess (listener.ref()));
334 else
335 sb_process.SetProcess (m_opaque_sp->CreateProcess (m_opaque_sp->GetDebugger().GetListener()));
336 }
Greg Claytonc5f728c2010-10-06 22:10:17 +0000337
338 if (sb_process.IsValid())
339 {
Greg Clayton527154d2011-11-15 03:53:30 +0000340 ProcessAttachInfo attach_info;
341 attach_info.SetProcessID (pid);
342 error.SetError (sb_process->Attach (attach_info));
Johnny Chen535960e2011-06-17 00:51:15 +0000343 // If we are doing synchronous mode, then wait for the
344 // process to stop!
345 if (m_opaque_sp->GetDebugger().GetAsyncExecution () == false)
346 sb_process->WaitForProcessToStop (NULL);
Greg Claytonc5f728c2010-10-06 22:10:17 +0000347 }
348 else
349 {
350 error.SetErrorString ("unable to create lldb_private::Process");
351 }
352 }
353 else
354 {
355 error.SetErrorString ("SBTarget is invalid");
356 }
357 return sb_process;
358
359}
360
361lldb::SBProcess
Greg Claytond8c62532010-10-07 04:19:01 +0000362SBTarget::AttachToProcessWithName
Greg Claytonc5f728c2010-10-06 22:10:17 +0000363(
Greg Clayton271a5db2011-02-03 21:28:34 +0000364 SBListener &listener,
Greg Claytonc5f728c2010-10-06 22:10:17 +0000365 const char *name, // basename of process to attach to
366 bool wait_for, // if true wait for a new instance of "name" to be launched
367 SBError& error // An error explaining what went wrong if attach fails
368)
369{
370 SBProcess sb_process;
371 if (m_opaque_sp)
372 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000373 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
374
Greg Claytonde1dd812011-06-24 03:21:43 +0000375 StateType state = eStateInvalid;
376 sb_process.SetProcess (m_opaque_sp->GetProcessSP());
377 if (sb_process.IsValid())
378 {
379 state = sb_process->GetState();
380
381 if (sb_process->IsAlive() && state != eStateConnected)
382 {
383 if (state == eStateAttaching)
384 error.SetErrorString ("process attach is in progress");
385 else
386 error.SetErrorString ("a process is already being debugged");
387 sb_process.Clear();
388 return sb_process;
389 }
390 }
391
392 if (state == eStateConnected)
393 {
394 // If we are already connected, then we have already specified the
395 // listener, so if a valid listener is supplied, we need to error out
396 // to let the client know.
397 if (listener.IsValid())
398 {
399 error.SetErrorString ("process is connected and already has a listener, pass empty listener");
400 sb_process.Clear();
401 return sb_process;
402 }
403 }
Greg Clayton271a5db2011-02-03 21:28:34 +0000404 else
Greg Claytonde1dd812011-06-24 03:21:43 +0000405 {
406 if (listener.IsValid())
407 sb_process.SetProcess (m_opaque_sp->CreateProcess (listener.ref()));
408 else
409 sb_process.SetProcess (m_opaque_sp->CreateProcess (m_opaque_sp->GetDebugger().GetListener()));
410 }
Greg Claytonc5f728c2010-10-06 22:10:17 +0000411
412 if (sb_process.IsValid())
413 {
Greg Clayton527154d2011-11-15 03:53:30 +0000414 ProcessAttachInfo attach_info;
415 attach_info.GetExecutableFile().SetFile(name, false);
416 attach_info.SetWaitForLaunch(wait_for);
417 error.SetError (sb_process->Attach (attach_info));
Johnny Chen58d02ff2011-06-17 19:21:30 +0000418 // If we are doing synchronous mode, then wait for the
419 // process to stop!
420 if (m_opaque_sp->GetDebugger().GetAsyncExecution () == false)
421 sb_process->WaitForProcessToStop (NULL);
Greg Claytonc5f728c2010-10-06 22:10:17 +0000422 }
423 else
424 {
425 error.SetErrorString ("unable to create lldb_private::Process");
426 }
427 }
428 else
429 {
430 error.SetErrorString ("SBTarget is invalid");
431 }
432 return sb_process;
433
434}
435
James McIlree38093402011-03-04 00:31:13 +0000436lldb::SBProcess
437SBTarget::ConnectRemote
438(
439 SBListener &listener,
440 const char *url,
441 const char *plugin_name,
442 SBError& error
443)
444{
445 SBProcess sb_process;
446 if (m_opaque_sp)
447 {
448 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
449 if (listener.IsValid())
450 sb_process.SetProcess (m_opaque_sp->CreateProcess (listener.ref(), plugin_name));
451 else
452 sb_process.SetProcess (m_opaque_sp->CreateProcess (m_opaque_sp->GetDebugger().GetListener(), plugin_name));
453
454
455 if (sb_process.IsValid())
456 {
457 error.SetError (sb_process->ConnectRemote (url));
458 }
459 else
460 {
461 error.SetErrorString ("unable to create lldb_private::Process");
462 }
463 }
464 else
465 {
466 error.SetErrorString ("SBTarget is invalid");
467 }
468 return sb_process;
469}
470
Chris Lattner24943d22010-06-08 16:52:24 +0000471SBFileSpec
472SBTarget::GetExecutable ()
473{
Caroline Tice7826c882010-10-26 03:11:13 +0000474
Chris Lattner24943d22010-06-08 16:52:24 +0000475 SBFileSpec exe_file_spec;
Greg Clayton63094e02010-06-23 01:19:29 +0000476 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000477 {
Greg Clayton5beb99d2011-08-11 02:48:45 +0000478 Module *exe_module = m_opaque_sp->GetExecutableModulePointer();
479 if (exe_module)
480 exe_file_spec.SetFileSpec (exe_module->GetFileSpec());
Chris Lattner24943d22010-06-08 16:52:24 +0000481 }
Caroline Tice7826c882010-10-26 03:11:13 +0000482
Greg Claytone005f2c2010-11-06 01:53:30 +0000483 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000484 if (log)
485 {
Greg Clayton49ce6822010-10-31 03:01:06 +0000486 log->Printf ("SBTarget(%p)::GetExecutable () => SBFileSpec(%p)",
487 m_opaque_sp.get(), exe_file_spec.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000488 }
489
Chris Lattner24943d22010-06-08 16:52:24 +0000490 return exe_file_spec;
491}
492
Chris Lattner24943d22010-06-08 16:52:24 +0000493bool
Chris Lattner24943d22010-06-08 16:52:24 +0000494SBTarget::operator == (const SBTarget &rhs) const
495{
Greg Clayton63094e02010-06-23 01:19:29 +0000496 return m_opaque_sp.get() == rhs.m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000497}
498
499bool
500SBTarget::operator != (const SBTarget &rhs) const
501{
Greg Clayton63094e02010-06-23 01:19:29 +0000502 return m_opaque_sp.get() != rhs.m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000503}
504
505lldb_private::Target *
Greg Clayton63094e02010-06-23 01:19:29 +0000506SBTarget::operator ->() const
Chris Lattner24943d22010-06-08 16:52:24 +0000507{
Greg Clayton63094e02010-06-23 01:19:29 +0000508 return m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000509}
Greg Clayton63094e02010-06-23 01:19:29 +0000510
511lldb_private::Target *
512SBTarget::get() const
Chris Lattner24943d22010-06-08 16:52:24 +0000513{
Greg Clayton63094e02010-06-23 01:19:29 +0000514 return m_opaque_sp.get();
515}
516
Greg Clayton15afa9f2011-10-01 02:59:24 +0000517const lldb::TargetSP &
518SBTarget::get_sp () const
519{
520 return m_opaque_sp;
521}
522
Greg Clayton63094e02010-06-23 01:19:29 +0000523void
524SBTarget::reset (const lldb::TargetSP& target_sp)
525{
526 m_opaque_sp = target_sp;
Chris Lattner24943d22010-06-08 16:52:24 +0000527}
528
Greg Claytona3955062011-07-22 16:46:35 +0000529lldb::SBAddress
530SBTarget::ResolveLoadAddress (lldb::addr_t vm_addr)
Greg Claytonea49cc72010-12-12 19:25:26 +0000531{
Greg Claytona3955062011-07-22 16:46:35 +0000532 lldb::SBAddress sb_addr;
533 Address &addr = sb_addr.ref();
534 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000535 {
536 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
Greg Claytona3955062011-07-22 16:46:35 +0000537 if (m_opaque_sp->GetSectionLoadList().ResolveLoadAddress (vm_addr, addr))
538 return sb_addr;
Greg Claytonbdcda462010-12-20 20:49:23 +0000539 }
Greg Claytonea49cc72010-12-12 19:25:26 +0000540
Greg Claytona3955062011-07-22 16:46:35 +0000541 // We have a load address that isn't in a section, just return an address
542 // with the offset filled in (the address) and the section set to NULL
543 addr.SetSection(NULL);
544 addr.SetOffset(vm_addr);
545 return sb_addr;
Greg Claytonea49cc72010-12-12 19:25:26 +0000546}
547
Greg Claytonafb81862011-03-02 21:34:46 +0000548SBSymbolContext
549SBTarget::ResolveSymbolContextForAddress (const SBAddress& addr, uint32_t resolve_scope)
550{
551 SBSymbolContext sc;
Johnny Chene657fbc2011-06-29 00:05:40 +0000552 if (m_opaque_sp && addr.IsValid())
Greg Claytona3955062011-07-22 16:46:35 +0000553 m_opaque_sp->GetImages().ResolveSymbolContextForAddress (addr.ref(), resolve_scope, sc.ref());
Greg Claytonafb81862011-03-02 21:34:46 +0000554 return sc;
555}
556
557
Chris Lattner24943d22010-06-08 16:52:24 +0000558SBBreakpoint
559SBTarget::BreakpointCreateByLocation (const char *file, uint32_t line)
560{
Greg Claytond6d806c2010-11-08 00:28:40 +0000561 return SBBreakpoint(BreakpointCreateByLocation (SBFileSpec (file, false), line));
Chris Lattner24943d22010-06-08 16:52:24 +0000562}
563
564SBBreakpoint
565SBTarget::BreakpointCreateByLocation (const SBFileSpec &sb_file_spec, uint32_t line)
566{
Greg Claytone005f2c2010-11-06 01:53:30 +0000567 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000568
Chris Lattner24943d22010-06-08 16:52:24 +0000569 SBBreakpoint sb_bp;
Greg Clayton63094e02010-06-23 01:19:29 +0000570 if (m_opaque_sp.get() && line != 0)
Greg Claytonbdcda462010-12-20 20:49:23 +0000571 {
572 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
Greg Clayton63094e02010-06-23 01:19:29 +0000573 *sb_bp = m_opaque_sp->CreateBreakpoint (NULL, *sb_file_spec, line, true, false);
Greg Claytonbdcda462010-12-20 20:49:23 +0000574 }
Caroline Tice7826c882010-10-26 03:11:13 +0000575
576 if (log)
577 {
578 SBStream sstr;
579 sb_bp.GetDescription (sstr);
Greg Clayton49ce6822010-10-31 03:01:06 +0000580 char path[PATH_MAX];
581 sb_file_spec->GetPath (path, sizeof(path));
582 log->Printf ("SBTarget(%p)::BreakpointCreateByLocation ( %s:%u ) => SBBreakpoint(%p): %s",
Greg Claytona66ba462010-10-30 04:51:46 +0000583 m_opaque_sp.get(),
Greg Clayton49ce6822010-10-31 03:01:06 +0000584 path,
Greg Claytona66ba462010-10-30 04:51:46 +0000585 line,
Greg Clayton49ce6822010-10-31 03:01:06 +0000586 sb_bp.get(),
Caroline Tice7826c882010-10-26 03:11:13 +0000587 sstr.GetData());
588 }
589
Chris Lattner24943d22010-06-08 16:52:24 +0000590 return sb_bp;
591}
592
593SBBreakpoint
594SBTarget::BreakpointCreateByName (const char *symbol_name, const char *module_name)
595{
Greg Claytone005f2c2010-11-06 01:53:30 +0000596 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000597
Chris Lattner24943d22010-06-08 16:52:24 +0000598 SBBreakpoint sb_bp;
Jim Inghamd6d47972011-09-23 00:54:11 +0000599 if (m_opaque_sp.get())
Chris Lattner24943d22010-06-08 16:52:24 +0000600 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000601 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
Chris Lattner24943d22010-06-08 16:52:24 +0000602 if (module_name && module_name[0])
603 {
Jim Ingham03c8ee52011-09-21 01:17:13 +0000604 FileSpecList module_spec_list;
605 module_spec_list.Append (FileSpec (module_name, false));
Jim Ingham8b7b2272011-10-07 22:23:45 +0000606 *sb_bp = m_opaque_sp->CreateBreakpoint (&module_spec_list, NULL, symbol_name, eFunctionNameTypeAuto, false);
Chris Lattner24943d22010-06-08 16:52:24 +0000607 }
608 else
609 {
Jim Ingham8b7b2272011-10-07 22:23:45 +0000610 *sb_bp = m_opaque_sp->CreateBreakpoint (NULL, NULL, symbol_name, eFunctionNameTypeAuto, false);
Chris Lattner24943d22010-06-08 16:52:24 +0000611 }
612 }
Caroline Tice7826c882010-10-26 03:11:13 +0000613
614 if (log)
615 {
Greg Clayton49ce6822010-10-31 03:01:06 +0000616 log->Printf ("SBTarget(%p)::BreakpointCreateByName (symbol=\"%s\", module=\"%s\") => SBBreakpoint(%p)",
617 m_opaque_sp.get(), symbol_name, module_name, sb_bp.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000618 }
619
Chris Lattner24943d22010-06-08 16:52:24 +0000620 return sb_bp;
621}
622
Jim Inghamd6d47972011-09-23 00:54:11 +0000623lldb::SBBreakpoint
624SBTarget::BreakpointCreateByName (const char *symbol_name,
625 const SBFileSpecList &module_list,
626 const SBFileSpecList &comp_unit_list)
627{
Jim Ingham1fb8a2d2011-10-11 01:18:55 +0000628 uint32_t name_type_mask = eFunctionNameTypeAuto;
629 return BreakpointCreateByName (symbol_name, name_type_mask, module_list, comp_unit_list);
630}
631
632lldb::SBBreakpoint
633SBTarget::BreakpointCreateByName (const char *symbol_name,
634 uint32_t name_type_mask,
635 const SBFileSpecList &module_list,
636 const SBFileSpecList &comp_unit_list)
637{
Jim Inghamd6d47972011-09-23 00:54:11 +0000638 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
639
640 SBBreakpoint sb_bp;
641 if (m_opaque_sp.get() && symbol_name && symbol_name[0])
642 {
643 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
644 *sb_bp = m_opaque_sp->CreateBreakpoint (module_list.get(),
645 comp_unit_list.get(),
646 symbol_name,
Jim Ingham1fb8a2d2011-10-11 01:18:55 +0000647 name_type_mask,
Jim Inghamd6d47972011-09-23 00:54:11 +0000648 false);
649 }
650
651 if (log)
652 {
Jim Ingham1fb8a2d2011-10-11 01:18:55 +0000653 log->Printf ("SBTarget(%p)::BreakpointCreateByName (symbol=\"%s\", name_type: %d) => SBBreakpoint(%p)",
654 m_opaque_sp.get(), symbol_name, name_type_mask, sb_bp.get());
Jim Inghamd6d47972011-09-23 00:54:11 +0000655 }
656
657 return sb_bp;
658}
659
660
Chris Lattner24943d22010-06-08 16:52:24 +0000661SBBreakpoint
662SBTarget::BreakpointCreateByRegex (const char *symbol_name_regex, const char *module_name)
663{
Greg Claytone005f2c2010-11-06 01:53:30 +0000664 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000665
Chris Lattner24943d22010-06-08 16:52:24 +0000666 SBBreakpoint sb_bp;
Greg Clayton63094e02010-06-23 01:19:29 +0000667 if (m_opaque_sp.get() && symbol_name_regex && symbol_name_regex[0])
Chris Lattner24943d22010-06-08 16:52:24 +0000668 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000669 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
Chris Lattner24943d22010-06-08 16:52:24 +0000670 RegularExpression regexp(symbol_name_regex);
671
672 if (module_name && module_name[0])
673 {
Jim Ingham03c8ee52011-09-21 01:17:13 +0000674 FileSpecList module_spec_list;
675 module_spec_list.Append (FileSpec (module_name, false));
Chris Lattner24943d22010-06-08 16:52:24 +0000676
Jim Inghamd6d47972011-09-23 00:54:11 +0000677 *sb_bp = m_opaque_sp->CreateFuncRegexBreakpoint (&module_spec_list, NULL, regexp, false);
Chris Lattner24943d22010-06-08 16:52:24 +0000678 }
679 else
680 {
Jim Inghamd6d47972011-09-23 00:54:11 +0000681 *sb_bp = m_opaque_sp->CreateFuncRegexBreakpoint (NULL, NULL, regexp, false);
Chris Lattner24943d22010-06-08 16:52:24 +0000682 }
683 }
Caroline Tice7826c882010-10-26 03:11:13 +0000684
685 if (log)
686 {
Greg Clayton49ce6822010-10-31 03:01:06 +0000687 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (symbol_regex=\"%s\", module_name=\"%s\") => SBBreakpoint(%p)",
688 m_opaque_sp.get(), symbol_name_regex, module_name, sb_bp.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000689 }
690
Chris Lattner24943d22010-06-08 16:52:24 +0000691 return sb_bp;
692}
693
Jim Inghamd6d47972011-09-23 00:54:11 +0000694lldb::SBBreakpoint
695SBTarget::BreakpointCreateByRegex (const char *symbol_name_regex,
696 const SBFileSpecList &module_list,
697 const SBFileSpecList &comp_unit_list)
698{
699 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Chris Lattner24943d22010-06-08 16:52:24 +0000700
Jim Inghamd6d47972011-09-23 00:54:11 +0000701 SBBreakpoint sb_bp;
702 if (m_opaque_sp.get() && symbol_name_regex && symbol_name_regex[0])
703 {
704 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
705 RegularExpression regexp(symbol_name_regex);
706
707 *sb_bp = m_opaque_sp->CreateFuncRegexBreakpoint (module_list.get(), comp_unit_list.get(), regexp, false);
708 }
709
710 if (log)
711 {
712 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (symbol_regex=\"%s\") => SBBreakpoint(%p)",
713 m_opaque_sp.get(), symbol_name_regex, sb_bp.get());
714 }
715
716 return sb_bp;
717}
Chris Lattner24943d22010-06-08 16:52:24 +0000718
719SBBreakpoint
720SBTarget::BreakpointCreateByAddress (addr_t address)
721{
Greg Claytone005f2c2010-11-06 01:53:30 +0000722 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000723
Chris Lattner24943d22010-06-08 16:52:24 +0000724 SBBreakpoint sb_bp;
Greg Clayton63094e02010-06-23 01:19:29 +0000725 if (m_opaque_sp.get())
Greg Claytonbdcda462010-12-20 20:49:23 +0000726 {
727 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
Greg Clayton63094e02010-06-23 01:19:29 +0000728 *sb_bp = m_opaque_sp->CreateBreakpoint (address, false);
Greg Claytonbdcda462010-12-20 20:49:23 +0000729 }
Caroline Tice7826c882010-10-26 03:11:13 +0000730
731 if (log)
732 {
Jason Molenda7e5fa7f2011-09-20 21:44:10 +0000733 log->Printf ("SBTarget(%p)::BreakpointCreateByAddress (address=%llu) => SBBreakpoint(%p)", m_opaque_sp.get(), (uint64_t) address, sb_bp.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000734 }
735
Chris Lattner24943d22010-06-08 16:52:24 +0000736 return sb_bp;
737}
738
Jim Ingham03c8ee52011-09-21 01:17:13 +0000739lldb::SBBreakpoint
740SBTarget::BreakpointCreateBySourceRegex (const char *source_regex, const lldb::SBFileSpec &source_file, const char *module_name)
741{
742 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
743
744 SBBreakpoint sb_bp;
745 if (m_opaque_sp.get() && source_regex && source_regex[0])
746 {
747 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
748 RegularExpression regexp(source_regex);
Jim Inghamd6d47972011-09-23 00:54:11 +0000749 FileSpecList source_file_spec_list;
750 source_file_spec_list.Append (source_file.ref());
Jim Ingham03c8ee52011-09-21 01:17:13 +0000751
752 if (module_name && module_name[0])
753 {
754 FileSpecList module_spec_list;
755 module_spec_list.Append (FileSpec (module_name, false));
756
Jim Inghamd6d47972011-09-23 00:54:11 +0000757 *sb_bp = m_opaque_sp->CreateSourceRegexBreakpoint (&module_spec_list, &source_file_spec_list, regexp, false);
Jim Ingham03c8ee52011-09-21 01:17:13 +0000758 }
759 else
760 {
Jim Inghamd6d47972011-09-23 00:54:11 +0000761 *sb_bp = m_opaque_sp->CreateSourceRegexBreakpoint (NULL, &source_file_spec_list, regexp, false);
Jim Ingham03c8ee52011-09-21 01:17:13 +0000762 }
763 }
764
765 if (log)
766 {
767 char path[PATH_MAX];
768 source_file->GetPath (path, sizeof(path));
769 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (source_regex=\"%s\", file=\"%s\", module_name=\"%s\") => SBBreakpoint(%p)",
Greg Claytona253c932011-09-21 06:45:51 +0000770 m_opaque_sp.get(), source_regex, path, module_name, sb_bp.get());
Jim Ingham03c8ee52011-09-21 01:17:13 +0000771 }
772
773 return sb_bp;
774}
775
Jim Inghamd6d47972011-09-23 00:54:11 +0000776lldb::SBBreakpoint
777SBTarget::BreakpointCreateBySourceRegex (const char *source_regex,
778 const SBFileSpecList &module_list,
779 const lldb::SBFileSpecList &source_file_list)
780{
781 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
782
783 SBBreakpoint sb_bp;
784 if (m_opaque_sp.get() && source_regex && source_regex[0])
785 {
786 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
787 RegularExpression regexp(source_regex);
788 *sb_bp = m_opaque_sp->CreateSourceRegexBreakpoint (module_list.get(), source_file_list.get(), regexp, false);
789 }
790
791 if (log)
792 {
793 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (source_regex=\"%s\") => SBBreakpoint(%p)",
794 m_opaque_sp.get(), source_regex, sb_bp.get());
795 }
796
797 return sb_bp;
798}
Jim Ingham03c8ee52011-09-21 01:17:13 +0000799
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000800uint32_t
801SBTarget::GetNumBreakpoints () const
802{
803 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000804 {
805 // The breakpoint list is thread safe, no need to lock
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000806 return m_opaque_sp->GetBreakpointList().GetSize();
Greg Claytonbdcda462010-12-20 20:49:23 +0000807 }
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000808 return 0;
809}
810
811SBBreakpoint
812SBTarget::GetBreakpointAtIndex (uint32_t idx) const
813{
814 SBBreakpoint sb_breakpoint;
815 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000816 {
817 // The breakpoint list is thread safe, no need to lock
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000818 *sb_breakpoint = m_opaque_sp->GetBreakpointList().GetBreakpointAtIndex(idx);
Greg Claytonbdcda462010-12-20 20:49:23 +0000819 }
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000820 return sb_breakpoint;
821}
Chris Lattner24943d22010-06-08 16:52:24 +0000822
823bool
824SBTarget::BreakpointDelete (break_id_t bp_id)
825{
Greg Claytone005f2c2010-11-06 01:53:30 +0000826 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000827
Caroline Tice7826c882010-10-26 03:11:13 +0000828 bool result = false;
Greg Clayton63094e02010-06-23 01:19:29 +0000829 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000830 {
831 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
Caroline Tice7826c882010-10-26 03:11:13 +0000832 result = m_opaque_sp->RemoveBreakpointByID (bp_id);
Greg Claytonbdcda462010-12-20 20:49:23 +0000833 }
Caroline Tice7826c882010-10-26 03:11:13 +0000834
835 if (log)
836 {
Greg Clayton3f5ee7f2010-10-29 04:59:35 +0000837 log->Printf ("SBTarget(%p)::BreakpointDelete (bp_id=%d) => %i", m_opaque_sp.get(), (uint32_t) bp_id, result);
Caroline Tice7826c882010-10-26 03:11:13 +0000838 }
839
840 return result;
Chris Lattner24943d22010-06-08 16:52:24 +0000841}
842
Johnny Chen096c2932011-09-26 22:40:50 +0000843SBBreakpoint
844SBTarget::FindBreakpointByID (break_id_t bp_id)
845{
846 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
847
848 SBBreakpoint sb_breakpoint;
849 if (m_opaque_sp && bp_id != LLDB_INVALID_BREAK_ID)
850 {
851 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
852 *sb_breakpoint = m_opaque_sp->GetBreakpointByID (bp_id);
853 }
854
855 if (log)
856 {
857 log->Printf ("SBTarget(%p)::FindBreakpointByID (bp_id=%d) => SBBreakpoint(%p)",
858 m_opaque_sp.get(), (uint32_t) bp_id, sb_breakpoint.get());
859 }
860
861 return sb_breakpoint;
862}
863
Chris Lattner24943d22010-06-08 16:52:24 +0000864bool
865SBTarget::EnableAllBreakpoints ()
866{
Greg Clayton63094e02010-06-23 01:19:29 +0000867 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000868 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000869 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
Greg Clayton63094e02010-06-23 01:19:29 +0000870 m_opaque_sp->EnableAllBreakpoints ();
Chris Lattner24943d22010-06-08 16:52:24 +0000871 return true;
872 }
873 return false;
874}
875
876bool
877SBTarget::DisableAllBreakpoints ()
878{
Greg Clayton63094e02010-06-23 01:19:29 +0000879 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000880 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000881 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
Greg Clayton63094e02010-06-23 01:19:29 +0000882 m_opaque_sp->DisableAllBreakpoints ();
Chris Lattner24943d22010-06-08 16:52:24 +0000883 return true;
884 }
885 return false;
886}
887
888bool
889SBTarget::DeleteAllBreakpoints ()
890{
Greg Clayton63094e02010-06-23 01:19:29 +0000891 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000892 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000893 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
Greg Clayton63094e02010-06-23 01:19:29 +0000894 m_opaque_sp->RemoveAllBreakpoints ();
Chris Lattner24943d22010-06-08 16:52:24 +0000895 return true;
896 }
897 return false;
898}
899
Johnny Chen096c2932011-09-26 22:40:50 +0000900uint32_t
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000901SBTarget::GetNumWatchpoints () const
Johnny Chen096c2932011-09-26 22:40:50 +0000902{
903 if (m_opaque_sp)
904 {
Johnny Chenecd4feb2011-10-14 00:42:25 +0000905 // The watchpoint list is thread safe, no need to lock
906 return m_opaque_sp->GetWatchpointList().GetSize();
Johnny Chen096c2932011-09-26 22:40:50 +0000907 }
908 return 0;
909}
910
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000911SBWatchpoint
912SBTarget::GetWatchpointAtIndex (uint32_t idx) const
Johnny Chen5eb54bb2011-09-27 20:29:45 +0000913{
Johnny Chenecd4feb2011-10-14 00:42:25 +0000914 SBWatchpoint sb_watchpoint;
Johnny Chen096c2932011-09-26 22:40:50 +0000915 if (m_opaque_sp)
916 {
Johnny Chenecd4feb2011-10-14 00:42:25 +0000917 // The watchpoint list is thread safe, no need to lock
918 *sb_watchpoint = m_opaque_sp->GetWatchpointList().GetByIndex(idx);
Johnny Chen096c2932011-09-26 22:40:50 +0000919 }
Johnny Chenecd4feb2011-10-14 00:42:25 +0000920 return sb_watchpoint;
Johnny Chen096c2932011-09-26 22:40:50 +0000921}
922
923bool
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000924SBTarget::DeleteWatchpoint (watch_id_t wp_id)
Johnny Chen096c2932011-09-26 22:40:50 +0000925{
926 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
927
928 bool result = false;
929 if (m_opaque_sp)
930 {
931 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
Johnny Chenecd4feb2011-10-14 00:42:25 +0000932 result = m_opaque_sp->RemoveWatchpointByID (wp_id);
Johnny Chen096c2932011-09-26 22:40:50 +0000933 }
934
935 if (log)
936 {
Johnny Chenecd4feb2011-10-14 00:42:25 +0000937 log->Printf ("SBTarget(%p)::WatchpointDelete (wp_id=%d) => %i", m_opaque_sp.get(), (uint32_t) wp_id, result);
Johnny Chen096c2932011-09-26 22:40:50 +0000938 }
939
940 return result;
941}
942
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000943SBWatchpoint
944SBTarget::FindWatchpointByID (lldb::watch_id_t wp_id)
Johnny Chen096c2932011-09-26 22:40:50 +0000945{
946 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
947
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000948 SBWatchpoint sb_watchpoint;
Johnny Chen096c2932011-09-26 22:40:50 +0000949 if (m_opaque_sp && wp_id != LLDB_INVALID_WATCH_ID)
950 {
951 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
Johnny Chenecd4feb2011-10-14 00:42:25 +0000952 *sb_watchpoint = m_opaque_sp->GetWatchpointList().FindByID(wp_id);
Johnny Chen096c2932011-09-26 22:40:50 +0000953 }
954
955 if (log)
956 {
Johnny Chenecd4feb2011-10-14 00:42:25 +0000957 log->Printf ("SBTarget(%p)::FindWatchpointByID (bp_id=%d) => SBWatchpoint(%p)",
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000958 m_opaque_sp.get(), (uint32_t) wp_id, sb_watchpoint.get());
Johnny Chen096c2932011-09-26 22:40:50 +0000959 }
960
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000961 return sb_watchpoint;
962}
963
964lldb::SBWatchpoint
965SBTarget::WatchAddress (lldb::addr_t addr, size_t size, bool read, bool write)
966{
967 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
968
969 SBWatchpoint sb_watchpoint;
970 if (m_opaque_sp)
971 {
972 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
Johnny Chenecd4feb2011-10-14 00:42:25 +0000973 uint32_t watch_type = (read ? LLDB_WATCH_TYPE_READ : 0) |
974 (write ? LLDB_WATCH_TYPE_WRITE : 0);
Johnny Chen50e05342011-10-14 01:16:39 +0000975 sb_watchpoint = m_opaque_sp->CreateWatchpoint(addr, size, watch_type);
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000976 }
977
978 if (log)
979 {
980 log->Printf ("SBTarget(%p)::WatchAddress (addr=0x%llx, 0x%u) => SBWatchpoint(%p)",
981 m_opaque_sp.get(), addr, (uint32_t) size, sb_watchpoint.get());
982 }
983
984 return sb_watchpoint;
Johnny Chen096c2932011-09-26 22:40:50 +0000985}
986
987bool
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000988SBTarget::EnableAllWatchpoints ()
Johnny Chen096c2932011-09-26 22:40:50 +0000989{
990 if (m_opaque_sp)
991 {
992 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
Johnny Chenecd4feb2011-10-14 00:42:25 +0000993 m_opaque_sp->EnableAllWatchpoints ();
Johnny Chen096c2932011-09-26 22:40:50 +0000994 return true;
995 }
996 return false;
997}
998
999bool
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001000SBTarget::DisableAllWatchpoints ()
Johnny Chen096c2932011-09-26 22:40:50 +00001001{
1002 if (m_opaque_sp)
1003 {
1004 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
Johnny Chenecd4feb2011-10-14 00:42:25 +00001005 m_opaque_sp->DisableAllWatchpoints ();
Johnny Chen096c2932011-09-26 22:40:50 +00001006 return true;
1007 }
1008 return false;
1009}
1010
1011bool
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001012SBTarget::DeleteAllWatchpoints ()
Johnny Chen096c2932011-09-26 22:40:50 +00001013{
1014 if (m_opaque_sp)
1015 {
1016 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
Johnny Chenecd4feb2011-10-14 00:42:25 +00001017 m_opaque_sp->RemoveAllWatchpoints ();
Johnny Chen096c2932011-09-26 22:40:50 +00001018 return true;
1019 }
1020 return false;
1021}
1022
Chris Lattner24943d22010-06-08 16:52:24 +00001023
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001024lldb::SBModule
1025SBTarget::AddModule (const char *path,
1026 const char *triple,
1027 const char *uuid_cstr)
1028{
1029 lldb::SBModule sb_module;
1030 if (m_opaque_sp)
1031 {
1032 FileSpec module_file_spec;
1033 UUID module_uuid;
1034 ArchSpec module_arch;
1035
1036 if (path)
1037 module_file_spec.SetFile(path, false);
1038
1039 if (uuid_cstr)
1040 module_uuid.SetfromCString(uuid_cstr);
1041
1042 if (triple)
1043 module_arch.SetTriple (triple, m_opaque_sp->GetPlatform ().get());
1044
1045 sb_module.SetModule(m_opaque_sp->GetSharedModule (module_file_spec,
1046 module_arch,
1047 uuid_cstr ? &module_uuid : NULL));
1048 }
1049 return sb_module;
1050}
1051
1052bool
1053SBTarget::AddModule (lldb::SBModule &module)
1054{
1055 if (m_opaque_sp)
1056 {
1057 m_opaque_sp->GetImages().AppendIfNeeded (module.get_sp());
1058 return true;
1059 }
1060 return false;
1061}
1062
1063lldb::SBModule
1064AddModule (const char *path,
1065 const char *triple,
1066 const char *uuid);
1067
1068
1069
Chris Lattner24943d22010-06-08 16:52:24 +00001070uint32_t
1071SBTarget::GetNumModules () const
1072{
Greg Claytone005f2c2010-11-06 01:53:30 +00001073 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001074
Caroline Tice7826c882010-10-26 03:11:13 +00001075 uint32_t num = 0;
Greg Clayton63094e02010-06-23 01:19:29 +00001076 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +00001077 {
1078 // The module list is thread safe, no need to lock
1079 num = m_opaque_sp->GetImages().GetSize();
1080 }
Caroline Tice7826c882010-10-26 03:11:13 +00001081
1082 if (log)
Greg Clayton3f5ee7f2010-10-29 04:59:35 +00001083 log->Printf ("SBTarget(%p)::GetNumModules () => %d", m_opaque_sp.get(), num);
Caroline Tice7826c882010-10-26 03:11:13 +00001084
1085 return num;
Chris Lattner24943d22010-06-08 16:52:24 +00001086}
1087
Greg Clayton43490d12010-07-30 20:12:55 +00001088void
1089SBTarget::Clear ()
1090{
Greg Claytone005f2c2010-11-06 01:53:30 +00001091 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001092
1093 if (log)
Greg Clayton3f5ee7f2010-10-29 04:59:35 +00001094 log->Printf ("SBTarget(%p)::Clear ()", m_opaque_sp.get());
Caroline Tice7826c882010-10-26 03:11:13 +00001095
Greg Clayton43490d12010-07-30 20:12:55 +00001096 m_opaque_sp.reset();
1097}
1098
1099
Chris Lattner24943d22010-06-08 16:52:24 +00001100SBModule
1101SBTarget::FindModule (const SBFileSpec &sb_file_spec)
1102{
1103 SBModule sb_module;
Greg Clayton63094e02010-06-23 01:19:29 +00001104 if (m_opaque_sp && sb_file_spec.IsValid())
Greg Claytonbdcda462010-12-20 20:49:23 +00001105 {
1106 // The module list is thread safe, no need to lock
Greg Clayton24bc5d92011-03-30 18:16:51 +00001107 sb_module.SetModule (m_opaque_sp->GetImages().FindFirstModuleForFileSpec (*sb_file_spec, NULL, NULL));
Greg Claytonbdcda462010-12-20 20:49:23 +00001108 }
Chris Lattner24943d22010-06-08 16:52:24 +00001109 return sb_module;
1110}
1111
1112SBModule
1113SBTarget::GetModuleAtIndex (uint32_t idx)
1114{
Greg Claytone005f2c2010-11-06 01:53:30 +00001115 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001116
Chris Lattner24943d22010-06-08 16:52:24 +00001117 SBModule sb_module;
Greg Clayton63094e02010-06-23 01:19:29 +00001118 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +00001119 {
1120 // The module list is thread safe, no need to lock
Greg Clayton63094e02010-06-23 01:19:29 +00001121 sb_module.SetModule(m_opaque_sp->GetImages().GetModuleAtIndex(idx));
Greg Claytonbdcda462010-12-20 20:49:23 +00001122 }
Caroline Tice7826c882010-10-26 03:11:13 +00001123
1124 if (log)
1125 {
Greg Clayton49ce6822010-10-31 03:01:06 +00001126 log->Printf ("SBTarget(%p)::GetModuleAtIndex (idx=%d) => SBModule(%p)",
1127 m_opaque_sp.get(), idx, sb_module.get());
Caroline Tice7826c882010-10-26 03:11:13 +00001128 }
1129
Chris Lattner24943d22010-06-08 16:52:24 +00001130 return sb_module;
1131}
1132
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001133bool
1134SBTarget::RemoveModule (lldb::SBModule module)
1135{
1136 if (m_opaque_sp)
1137 return m_opaque_sp->GetImages().Remove(module.get_sp());
1138 return false;
1139}
1140
Chris Lattner24943d22010-06-08 16:52:24 +00001141
1142SBBroadcaster
1143SBTarget::GetBroadcaster () const
1144{
Greg Claytone005f2c2010-11-06 01:53:30 +00001145 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001146
Greg Clayton63094e02010-06-23 01:19:29 +00001147 SBBroadcaster broadcaster(m_opaque_sp.get(), false);
Caroline Tice7826c882010-10-26 03:11:13 +00001148
1149 if (log)
Greg Clayton3f5ee7f2010-10-29 04:59:35 +00001150 log->Printf ("SBTarget(%p)::GetBroadcaster () => SBBroadcaster(%p)",
Caroline Tice61ba7ec2010-10-26 23:49:36 +00001151 m_opaque_sp.get(), broadcaster.get());
Caroline Tice7826c882010-10-26 03:11:13 +00001152
Chris Lattner24943d22010-06-08 16:52:24 +00001153 return broadcaster;
1154}
1155
Caroline Tice98f930f2010-09-20 05:20:02 +00001156
1157bool
Caroline Tice7826c882010-10-26 03:11:13 +00001158SBTarget::GetDescription (SBStream &description, lldb::DescriptionLevel description_level)
Caroline Tice98f930f2010-09-20 05:20:02 +00001159{
Greg Clayton96154be2011-11-13 06:57:31 +00001160 Stream &strm = description.ref();
1161
Caroline Tice98f930f2010-09-20 05:20:02 +00001162 if (m_opaque_sp)
Caroline Ticee7a566e2010-09-20 16:21:41 +00001163 {
Greg Clayton96154be2011-11-13 06:57:31 +00001164 m_opaque_sp->Dump (&strm, description_level);
Caroline Tice7826c882010-10-26 03:11:13 +00001165 }
1166 else
Greg Clayton96154be2011-11-13 06:57:31 +00001167 strm.PutCString ("No value");
Caroline Tice7826c882010-10-26 03:11:13 +00001168
1169 return true;
1170}
1171
Greg Clayton4ed315f2011-06-21 01:34:41 +00001172uint32_t
1173SBTarget::FindFunctions (const char *name,
1174 uint32_t name_type_mask,
1175 bool append,
1176 lldb::SBSymbolContextList& sc_list)
1177{
1178 if (!append)
1179 sc_list.Clear();
1180 if (m_opaque_sp)
1181 {
1182 const bool symbols_ok = true;
1183 return m_opaque_sp->GetImages().FindFunctions (ConstString(name),
1184 name_type_mask,
1185 symbols_ok,
1186 append,
1187 *sc_list);
1188 }
1189 return 0;
1190}
1191
Enrico Granata979e20d2011-07-29 19:53:35 +00001192lldb::SBType
1193SBTarget::FindFirstType (const char* type)
1194{
1195 if (m_opaque_sp)
1196 {
1197 size_t count = m_opaque_sp->GetImages().GetSize();
1198 for (size_t idx = 0; idx < count; idx++)
1199 {
1200 SBType found_at_idx = GetModuleAtIndex(idx).FindFirstType(type);
1201
1202 if (found_at_idx.IsValid())
1203 return found_at_idx;
1204 }
1205 }
1206 return SBType();
1207}
1208
1209lldb::SBTypeList
1210SBTarget::FindTypes (const char* type)
1211{
1212
1213 SBTypeList retval;
1214
1215 if (m_opaque_sp)
1216 {
1217 ModuleList& images = m_opaque_sp->GetImages();
1218 ConstString name_const(type);
1219 SymbolContext sc;
1220 TypeList type_list;
1221
1222 uint32_t num_matches = images.FindTypes(sc,
1223 name_const,
1224 true,
1225 UINT32_MAX,
1226 type_list);
1227
1228 for (size_t idx = 0; idx < num_matches; idx++)
1229 {
Greg Clayton0fb0bcc2011-08-03 22:57:10 +00001230 TypeSP type_sp (type_list.GetTypeAtIndex(idx));
1231 if (type_sp)
1232 retval.Append(SBType(type_sp));
Enrico Granata979e20d2011-07-29 19:53:35 +00001233 }
1234 }
1235 return retval;
1236}
1237
Greg Clayton917c0002011-06-29 22:09:02 +00001238SBValueList
1239SBTarget::FindGlobalVariables (const char *name, uint32_t max_matches)
1240{
1241 SBValueList sb_value_list;
1242
1243 if (m_opaque_sp)
1244 {
1245 VariableList variable_list;
1246 const bool append = true;
1247 const uint32_t match_count = m_opaque_sp->GetImages().FindGlobalVariables (ConstString (name),
1248 append,
1249 max_matches,
1250 variable_list);
1251
1252 if (match_count > 0)
1253 {
1254 ExecutionContextScope *exe_scope = m_opaque_sp->GetProcessSP().get();
1255 if (exe_scope == NULL)
1256 exe_scope = m_opaque_sp.get();
1257 ValueObjectList &value_object_list = sb_value_list.ref();
1258 for (uint32_t i=0; i<match_count; ++i)
1259 {
1260 lldb::ValueObjectSP valobj_sp (ValueObjectVariable::Create (exe_scope, variable_list.GetVariableAtIndex(i)));
1261 if (valobj_sp)
1262 value_object_list.Append(valobj_sp);
1263 }
1264 }
1265 }
1266
1267 return sb_value_list;
1268}
1269
Jim Inghamcc637462011-09-13 00:29:56 +00001270SBSourceManager
1271SBTarget::GetSourceManager()
1272{
1273 SBSourceManager source_manager (*this);
1274 return source_manager;
1275}
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001276
1277
1278SBError
1279SBTarget::SetSectionLoadAddress (lldb::SBSection section,
1280 lldb::addr_t section_base_addr)
1281{
1282 SBError sb_error;
1283
1284 if (IsValid())
1285 {
1286 if (!section.IsValid())
1287 {
1288 sb_error.SetErrorStringWithFormat ("invalid section");
1289 }
1290 else
1291 {
1292 m_opaque_sp->GetSectionLoadList().SetSectionLoadAddress (section.GetSection(), section_base_addr);
1293 }
1294 }
1295 else
1296 {
1297 sb_error.SetErrorStringWithFormat ("invalid target");
1298 }
1299 return sb_error;
1300}
1301
1302SBError
1303SBTarget::ClearSectionLoadAddress (lldb::SBSection section)
1304{
1305 SBError sb_error;
1306
1307 if (IsValid())
1308 {
1309 if (!section.IsValid())
1310 {
1311 sb_error.SetErrorStringWithFormat ("invalid section");
1312 }
1313 else
1314 {
1315 m_opaque_sp->GetSectionLoadList().SetSectionUnloaded (section.GetSection());
1316 }
1317 }
1318 else
1319 {
1320 sb_error.SetErrorStringWithFormat ("invalid target");
1321 }
1322 return sb_error;
1323}
1324
1325SBError
1326SBTarget::SetModuleLoadAddress (lldb::SBModule module, int64_t slide_offset)
1327{
1328 SBError sb_error;
1329
1330 char path[PATH_MAX];
1331 if (IsValid())
1332 {
1333 if (!module.IsValid())
1334 {
1335 sb_error.SetErrorStringWithFormat ("invalid module");
1336 }
1337 else
1338 {
1339 ObjectFile *objfile = module->GetObjectFile();
1340 if (objfile)
1341 {
1342 SectionList *section_list = objfile->GetSectionList();
1343 if (section_list)
1344 {
1345 const size_t num_sections = section_list->GetSize();
1346 for (size_t sect_idx = 0; sect_idx < num_sections; ++sect_idx)
1347 {
1348 SectionSP section_sp (section_list->GetSectionAtIndex(sect_idx));
1349 if (section_sp)
1350 m_opaque_sp->GetSectionLoadList().SetSectionLoadAddress (section_sp.get(), section_sp->GetFileAddress() + slide_offset);
1351 }
1352 }
1353 else
1354 {
1355 module->GetFileSpec().GetPath (path, sizeof(path));
1356 sb_error.SetErrorStringWithFormat ("no sections in object file '%s'", path);
1357 }
1358 }
1359 else
1360 {
1361 module->GetFileSpec().GetPath (path, sizeof(path));
1362 sb_error.SetErrorStringWithFormat ("no object file for module '%s'", path);
1363 }
1364 }
1365 }
1366 else
1367 {
1368 sb_error.SetErrorStringWithFormat ("invalid target");
1369 }
1370 return sb_error;
1371}
1372
1373SBError
1374SBTarget::ClearModuleLoadAddress (lldb::SBModule module)
1375{
1376 SBError sb_error;
1377
1378 char path[PATH_MAX];
1379 if (IsValid())
1380 {
1381 if (!module.IsValid())
1382 {
1383 sb_error.SetErrorStringWithFormat ("invalid module");
1384 }
1385 else
1386 {
1387 ObjectFile *objfile = module->GetObjectFile();
1388 if (objfile)
1389 {
1390 SectionList *section_list = objfile->GetSectionList();
1391 if (section_list)
1392 {
1393 const size_t num_sections = section_list->GetSize();
1394 for (size_t sect_idx = 0; sect_idx < num_sections; ++sect_idx)
1395 {
1396 SectionSP section_sp (section_list->GetSectionAtIndex(sect_idx));
1397 if (section_sp)
1398 m_opaque_sp->GetSectionLoadList().SetSectionUnloaded (section_sp.get());
1399 }
1400 }
1401 else
1402 {
1403 module->GetFileSpec().GetPath (path, sizeof(path));
1404 sb_error.SetErrorStringWithFormat ("no sections in object file '%s'", path);
1405 }
1406 }
1407 else
1408 {
1409 module->GetFileSpec().GetPath (path, sizeof(path));
1410 sb_error.SetErrorStringWithFormat ("no object file for module '%s'", path);
1411 }
1412 }
1413 }
1414 else
1415 {
1416 sb_error.SetErrorStringWithFormat ("invalid target");
1417 }
1418 return sb_error;
1419}
1420
1421