blob: f79d4f3c01c1f5e13cea0d7d4833a9e44fc4c34c [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)
238 launch_info.SetExecutableFile(exe_module->GetFileSpec(), true);
239 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 Clayton2d9adb72011-11-12 02:10:56 +0000340 error.SetError (sb_process->Attach (pid, 0));
Johnny Chen535960e2011-06-17 00:51:15 +0000341 // If we are doing synchronous mode, then wait for the
342 // process to stop!
343 if (m_opaque_sp->GetDebugger().GetAsyncExecution () == false)
344 sb_process->WaitForProcessToStop (NULL);
Greg Claytonc5f728c2010-10-06 22:10:17 +0000345 }
346 else
347 {
348 error.SetErrorString ("unable to create lldb_private::Process");
349 }
350 }
351 else
352 {
353 error.SetErrorString ("SBTarget is invalid");
354 }
355 return sb_process;
356
357}
358
359lldb::SBProcess
Greg Claytond8c62532010-10-07 04:19:01 +0000360SBTarget::AttachToProcessWithName
Greg Claytonc5f728c2010-10-06 22:10:17 +0000361(
Greg Clayton271a5db2011-02-03 21:28:34 +0000362 SBListener &listener,
Greg Claytonc5f728c2010-10-06 22:10:17 +0000363 const char *name, // basename of process to attach to
364 bool wait_for, // if true wait for a new instance of "name" to be launched
365 SBError& error // An error explaining what went wrong if attach fails
366)
367{
368 SBProcess sb_process;
369 if (m_opaque_sp)
370 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000371 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
372
Greg Claytonde1dd812011-06-24 03:21:43 +0000373 StateType state = eStateInvalid;
374 sb_process.SetProcess (m_opaque_sp->GetProcessSP());
375 if (sb_process.IsValid())
376 {
377 state = sb_process->GetState();
378
379 if (sb_process->IsAlive() && state != eStateConnected)
380 {
381 if (state == eStateAttaching)
382 error.SetErrorString ("process attach is in progress");
383 else
384 error.SetErrorString ("a process is already being debugged");
385 sb_process.Clear();
386 return sb_process;
387 }
388 }
389
390 if (state == eStateConnected)
391 {
392 // If we are already connected, then we have already specified the
393 // listener, so if a valid listener is supplied, we need to error out
394 // to let the client know.
395 if (listener.IsValid())
396 {
397 error.SetErrorString ("process is connected and already has a listener, pass empty listener");
398 sb_process.Clear();
399 return sb_process;
400 }
401 }
Greg Clayton271a5db2011-02-03 21:28:34 +0000402 else
Greg Claytonde1dd812011-06-24 03:21:43 +0000403 {
404 if (listener.IsValid())
405 sb_process.SetProcess (m_opaque_sp->CreateProcess (listener.ref()));
406 else
407 sb_process.SetProcess (m_opaque_sp->CreateProcess (m_opaque_sp->GetDebugger().GetListener()));
408 }
Greg Claytonc5f728c2010-10-06 22:10:17 +0000409
410 if (sb_process.IsValid())
411 {
412 error.SetError (sb_process->Attach (name, wait_for));
Johnny Chen58d02ff2011-06-17 19:21:30 +0000413 // If we are doing synchronous mode, then wait for the
414 // process to stop!
415 if (m_opaque_sp->GetDebugger().GetAsyncExecution () == false)
416 sb_process->WaitForProcessToStop (NULL);
Greg Claytonc5f728c2010-10-06 22:10:17 +0000417 }
418 else
419 {
420 error.SetErrorString ("unable to create lldb_private::Process");
421 }
422 }
423 else
424 {
425 error.SetErrorString ("SBTarget is invalid");
426 }
427 return sb_process;
428
429}
430
James McIlree38093402011-03-04 00:31:13 +0000431lldb::SBProcess
432SBTarget::ConnectRemote
433(
434 SBListener &listener,
435 const char *url,
436 const char *plugin_name,
437 SBError& error
438)
439{
440 SBProcess sb_process;
441 if (m_opaque_sp)
442 {
443 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
444 if (listener.IsValid())
445 sb_process.SetProcess (m_opaque_sp->CreateProcess (listener.ref(), plugin_name));
446 else
447 sb_process.SetProcess (m_opaque_sp->CreateProcess (m_opaque_sp->GetDebugger().GetListener(), plugin_name));
448
449
450 if (sb_process.IsValid())
451 {
452 error.SetError (sb_process->ConnectRemote (url));
453 }
454 else
455 {
456 error.SetErrorString ("unable to create lldb_private::Process");
457 }
458 }
459 else
460 {
461 error.SetErrorString ("SBTarget is invalid");
462 }
463 return sb_process;
464}
465
Chris Lattner24943d22010-06-08 16:52:24 +0000466SBFileSpec
467SBTarget::GetExecutable ()
468{
Caroline Tice7826c882010-10-26 03:11:13 +0000469
Chris Lattner24943d22010-06-08 16:52:24 +0000470 SBFileSpec exe_file_spec;
Greg Clayton63094e02010-06-23 01:19:29 +0000471 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000472 {
Greg Clayton5beb99d2011-08-11 02:48:45 +0000473 Module *exe_module = m_opaque_sp->GetExecutableModulePointer();
474 if (exe_module)
475 exe_file_spec.SetFileSpec (exe_module->GetFileSpec());
Chris Lattner24943d22010-06-08 16:52:24 +0000476 }
Caroline Tice7826c882010-10-26 03:11:13 +0000477
Greg Claytone005f2c2010-11-06 01:53:30 +0000478 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000479 if (log)
480 {
Greg Clayton49ce6822010-10-31 03:01:06 +0000481 log->Printf ("SBTarget(%p)::GetExecutable () => SBFileSpec(%p)",
482 m_opaque_sp.get(), exe_file_spec.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000483 }
484
Chris Lattner24943d22010-06-08 16:52:24 +0000485 return exe_file_spec;
486}
487
Chris Lattner24943d22010-06-08 16:52:24 +0000488bool
Chris Lattner24943d22010-06-08 16:52:24 +0000489SBTarget::operator == (const SBTarget &rhs) const
490{
Greg Clayton63094e02010-06-23 01:19:29 +0000491 return m_opaque_sp.get() == rhs.m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000492}
493
494bool
495SBTarget::operator != (const SBTarget &rhs) const
496{
Greg Clayton63094e02010-06-23 01:19:29 +0000497 return m_opaque_sp.get() != rhs.m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000498}
499
500lldb_private::Target *
Greg Clayton63094e02010-06-23 01:19:29 +0000501SBTarget::operator ->() const
Chris Lattner24943d22010-06-08 16:52:24 +0000502{
Greg Clayton63094e02010-06-23 01:19:29 +0000503 return m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000504}
Greg Clayton63094e02010-06-23 01:19:29 +0000505
506lldb_private::Target *
507SBTarget::get() const
Chris Lattner24943d22010-06-08 16:52:24 +0000508{
Greg Clayton63094e02010-06-23 01:19:29 +0000509 return m_opaque_sp.get();
510}
511
Greg Clayton15afa9f2011-10-01 02:59:24 +0000512const lldb::TargetSP &
513SBTarget::get_sp () const
514{
515 return m_opaque_sp;
516}
517
Greg Clayton63094e02010-06-23 01:19:29 +0000518void
519SBTarget::reset (const lldb::TargetSP& target_sp)
520{
521 m_opaque_sp = target_sp;
Chris Lattner24943d22010-06-08 16:52:24 +0000522}
523
Greg Claytona3955062011-07-22 16:46:35 +0000524lldb::SBAddress
525SBTarget::ResolveLoadAddress (lldb::addr_t vm_addr)
Greg Claytonea49cc72010-12-12 19:25:26 +0000526{
Greg Claytona3955062011-07-22 16:46:35 +0000527 lldb::SBAddress sb_addr;
528 Address &addr = sb_addr.ref();
529 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000530 {
531 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
Greg Claytona3955062011-07-22 16:46:35 +0000532 if (m_opaque_sp->GetSectionLoadList().ResolveLoadAddress (vm_addr, addr))
533 return sb_addr;
Greg Claytonbdcda462010-12-20 20:49:23 +0000534 }
Greg Claytonea49cc72010-12-12 19:25:26 +0000535
Greg Claytona3955062011-07-22 16:46:35 +0000536 // We have a load address that isn't in a section, just return an address
537 // with the offset filled in (the address) and the section set to NULL
538 addr.SetSection(NULL);
539 addr.SetOffset(vm_addr);
540 return sb_addr;
Greg Claytonea49cc72010-12-12 19:25:26 +0000541}
542
Greg Claytonafb81862011-03-02 21:34:46 +0000543SBSymbolContext
544SBTarget::ResolveSymbolContextForAddress (const SBAddress& addr, uint32_t resolve_scope)
545{
546 SBSymbolContext sc;
Johnny Chene657fbc2011-06-29 00:05:40 +0000547 if (m_opaque_sp && addr.IsValid())
Greg Claytona3955062011-07-22 16:46:35 +0000548 m_opaque_sp->GetImages().ResolveSymbolContextForAddress (addr.ref(), resolve_scope, sc.ref());
Greg Claytonafb81862011-03-02 21:34:46 +0000549 return sc;
550}
551
552
Chris Lattner24943d22010-06-08 16:52:24 +0000553SBBreakpoint
554SBTarget::BreakpointCreateByLocation (const char *file, uint32_t line)
555{
Greg Claytond6d806c2010-11-08 00:28:40 +0000556 return SBBreakpoint(BreakpointCreateByLocation (SBFileSpec (file, false), line));
Chris Lattner24943d22010-06-08 16:52:24 +0000557}
558
559SBBreakpoint
560SBTarget::BreakpointCreateByLocation (const SBFileSpec &sb_file_spec, uint32_t line)
561{
Greg Claytone005f2c2010-11-06 01:53:30 +0000562 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000563
Chris Lattner24943d22010-06-08 16:52:24 +0000564 SBBreakpoint sb_bp;
Greg Clayton63094e02010-06-23 01:19:29 +0000565 if (m_opaque_sp.get() && line != 0)
Greg Claytonbdcda462010-12-20 20:49:23 +0000566 {
567 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
Greg Clayton63094e02010-06-23 01:19:29 +0000568 *sb_bp = m_opaque_sp->CreateBreakpoint (NULL, *sb_file_spec, line, true, false);
Greg Claytonbdcda462010-12-20 20:49:23 +0000569 }
Caroline Tice7826c882010-10-26 03:11:13 +0000570
571 if (log)
572 {
573 SBStream sstr;
574 sb_bp.GetDescription (sstr);
Greg Clayton49ce6822010-10-31 03:01:06 +0000575 char path[PATH_MAX];
576 sb_file_spec->GetPath (path, sizeof(path));
577 log->Printf ("SBTarget(%p)::BreakpointCreateByLocation ( %s:%u ) => SBBreakpoint(%p): %s",
Greg Claytona66ba462010-10-30 04:51:46 +0000578 m_opaque_sp.get(),
Greg Clayton49ce6822010-10-31 03:01:06 +0000579 path,
Greg Claytona66ba462010-10-30 04:51:46 +0000580 line,
Greg Clayton49ce6822010-10-31 03:01:06 +0000581 sb_bp.get(),
Caroline Tice7826c882010-10-26 03:11:13 +0000582 sstr.GetData());
583 }
584
Chris Lattner24943d22010-06-08 16:52:24 +0000585 return sb_bp;
586}
587
588SBBreakpoint
589SBTarget::BreakpointCreateByName (const char *symbol_name, const char *module_name)
590{
Greg Claytone005f2c2010-11-06 01:53:30 +0000591 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000592
Chris Lattner24943d22010-06-08 16:52:24 +0000593 SBBreakpoint sb_bp;
Jim Inghamd6d47972011-09-23 00:54:11 +0000594 if (m_opaque_sp.get())
Chris Lattner24943d22010-06-08 16:52:24 +0000595 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000596 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
Chris Lattner24943d22010-06-08 16:52:24 +0000597 if (module_name && module_name[0])
598 {
Jim Ingham03c8ee52011-09-21 01:17:13 +0000599 FileSpecList module_spec_list;
600 module_spec_list.Append (FileSpec (module_name, false));
Jim Ingham8b7b2272011-10-07 22:23:45 +0000601 *sb_bp = m_opaque_sp->CreateBreakpoint (&module_spec_list, NULL, symbol_name, eFunctionNameTypeAuto, false);
Chris Lattner24943d22010-06-08 16:52:24 +0000602 }
603 else
604 {
Jim Ingham8b7b2272011-10-07 22:23:45 +0000605 *sb_bp = m_opaque_sp->CreateBreakpoint (NULL, NULL, symbol_name, eFunctionNameTypeAuto, false);
Chris Lattner24943d22010-06-08 16:52:24 +0000606 }
607 }
Caroline Tice7826c882010-10-26 03:11:13 +0000608
609 if (log)
610 {
Greg Clayton49ce6822010-10-31 03:01:06 +0000611 log->Printf ("SBTarget(%p)::BreakpointCreateByName (symbol=\"%s\", module=\"%s\") => SBBreakpoint(%p)",
612 m_opaque_sp.get(), symbol_name, module_name, sb_bp.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000613 }
614
Chris Lattner24943d22010-06-08 16:52:24 +0000615 return sb_bp;
616}
617
Jim Inghamd6d47972011-09-23 00:54:11 +0000618lldb::SBBreakpoint
619SBTarget::BreakpointCreateByName (const char *symbol_name,
620 const SBFileSpecList &module_list,
621 const SBFileSpecList &comp_unit_list)
622{
Jim Ingham1fb8a2d2011-10-11 01:18:55 +0000623 uint32_t name_type_mask = eFunctionNameTypeAuto;
624 return BreakpointCreateByName (symbol_name, name_type_mask, module_list, comp_unit_list);
625}
626
627lldb::SBBreakpoint
628SBTarget::BreakpointCreateByName (const char *symbol_name,
629 uint32_t name_type_mask,
630 const SBFileSpecList &module_list,
631 const SBFileSpecList &comp_unit_list)
632{
Jim Inghamd6d47972011-09-23 00:54:11 +0000633 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
634
635 SBBreakpoint sb_bp;
636 if (m_opaque_sp.get() && symbol_name && symbol_name[0])
637 {
638 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
639 *sb_bp = m_opaque_sp->CreateBreakpoint (module_list.get(),
640 comp_unit_list.get(),
641 symbol_name,
Jim Ingham1fb8a2d2011-10-11 01:18:55 +0000642 name_type_mask,
Jim Inghamd6d47972011-09-23 00:54:11 +0000643 false);
644 }
645
646 if (log)
647 {
Jim Ingham1fb8a2d2011-10-11 01:18:55 +0000648 log->Printf ("SBTarget(%p)::BreakpointCreateByName (symbol=\"%s\", name_type: %d) => SBBreakpoint(%p)",
649 m_opaque_sp.get(), symbol_name, name_type_mask, sb_bp.get());
Jim Inghamd6d47972011-09-23 00:54:11 +0000650 }
651
652 return sb_bp;
653}
654
655
Chris Lattner24943d22010-06-08 16:52:24 +0000656SBBreakpoint
657SBTarget::BreakpointCreateByRegex (const char *symbol_name_regex, const char *module_name)
658{
Greg Claytone005f2c2010-11-06 01:53:30 +0000659 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000660
Chris Lattner24943d22010-06-08 16:52:24 +0000661 SBBreakpoint sb_bp;
Greg Clayton63094e02010-06-23 01:19:29 +0000662 if (m_opaque_sp.get() && symbol_name_regex && symbol_name_regex[0])
Chris Lattner24943d22010-06-08 16:52:24 +0000663 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000664 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
Chris Lattner24943d22010-06-08 16:52:24 +0000665 RegularExpression regexp(symbol_name_regex);
666
667 if (module_name && module_name[0])
668 {
Jim Ingham03c8ee52011-09-21 01:17:13 +0000669 FileSpecList module_spec_list;
670 module_spec_list.Append (FileSpec (module_name, false));
Chris Lattner24943d22010-06-08 16:52:24 +0000671
Jim Inghamd6d47972011-09-23 00:54:11 +0000672 *sb_bp = m_opaque_sp->CreateFuncRegexBreakpoint (&module_spec_list, NULL, regexp, false);
Chris Lattner24943d22010-06-08 16:52:24 +0000673 }
674 else
675 {
Jim Inghamd6d47972011-09-23 00:54:11 +0000676 *sb_bp = m_opaque_sp->CreateFuncRegexBreakpoint (NULL, NULL, regexp, false);
Chris Lattner24943d22010-06-08 16:52:24 +0000677 }
678 }
Caroline Tice7826c882010-10-26 03:11:13 +0000679
680 if (log)
681 {
Greg Clayton49ce6822010-10-31 03:01:06 +0000682 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (symbol_regex=\"%s\", module_name=\"%s\") => SBBreakpoint(%p)",
683 m_opaque_sp.get(), symbol_name_regex, module_name, sb_bp.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000684 }
685
Chris Lattner24943d22010-06-08 16:52:24 +0000686 return sb_bp;
687}
688
Jim Inghamd6d47972011-09-23 00:54:11 +0000689lldb::SBBreakpoint
690SBTarget::BreakpointCreateByRegex (const char *symbol_name_regex,
691 const SBFileSpecList &module_list,
692 const SBFileSpecList &comp_unit_list)
693{
694 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Chris Lattner24943d22010-06-08 16:52:24 +0000695
Jim Inghamd6d47972011-09-23 00:54:11 +0000696 SBBreakpoint sb_bp;
697 if (m_opaque_sp.get() && symbol_name_regex && symbol_name_regex[0])
698 {
699 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
700 RegularExpression regexp(symbol_name_regex);
701
702 *sb_bp = m_opaque_sp->CreateFuncRegexBreakpoint (module_list.get(), comp_unit_list.get(), regexp, false);
703 }
704
705 if (log)
706 {
707 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (symbol_regex=\"%s\") => SBBreakpoint(%p)",
708 m_opaque_sp.get(), symbol_name_regex, sb_bp.get());
709 }
710
711 return sb_bp;
712}
Chris Lattner24943d22010-06-08 16:52:24 +0000713
714SBBreakpoint
715SBTarget::BreakpointCreateByAddress (addr_t address)
716{
Greg Claytone005f2c2010-11-06 01:53:30 +0000717 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000718
Chris Lattner24943d22010-06-08 16:52:24 +0000719 SBBreakpoint sb_bp;
Greg Clayton63094e02010-06-23 01:19:29 +0000720 if (m_opaque_sp.get())
Greg Claytonbdcda462010-12-20 20:49:23 +0000721 {
722 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
Greg Clayton63094e02010-06-23 01:19:29 +0000723 *sb_bp = m_opaque_sp->CreateBreakpoint (address, false);
Greg Claytonbdcda462010-12-20 20:49:23 +0000724 }
Caroline Tice7826c882010-10-26 03:11:13 +0000725
726 if (log)
727 {
Jason Molenda7e5fa7f2011-09-20 21:44:10 +0000728 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 +0000729 }
730
Chris Lattner24943d22010-06-08 16:52:24 +0000731 return sb_bp;
732}
733
Jim Ingham03c8ee52011-09-21 01:17:13 +0000734lldb::SBBreakpoint
735SBTarget::BreakpointCreateBySourceRegex (const char *source_regex, const lldb::SBFileSpec &source_file, const char *module_name)
736{
737 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
738
739 SBBreakpoint sb_bp;
740 if (m_opaque_sp.get() && source_regex && source_regex[0])
741 {
742 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
743 RegularExpression regexp(source_regex);
Jim Inghamd6d47972011-09-23 00:54:11 +0000744 FileSpecList source_file_spec_list;
745 source_file_spec_list.Append (source_file.ref());
Jim Ingham03c8ee52011-09-21 01:17:13 +0000746
747 if (module_name && module_name[0])
748 {
749 FileSpecList module_spec_list;
750 module_spec_list.Append (FileSpec (module_name, false));
751
Jim Inghamd6d47972011-09-23 00:54:11 +0000752 *sb_bp = m_opaque_sp->CreateSourceRegexBreakpoint (&module_spec_list, &source_file_spec_list, regexp, false);
Jim Ingham03c8ee52011-09-21 01:17:13 +0000753 }
754 else
755 {
Jim Inghamd6d47972011-09-23 00:54:11 +0000756 *sb_bp = m_opaque_sp->CreateSourceRegexBreakpoint (NULL, &source_file_spec_list, regexp, false);
Jim Ingham03c8ee52011-09-21 01:17:13 +0000757 }
758 }
759
760 if (log)
761 {
762 char path[PATH_MAX];
763 source_file->GetPath (path, sizeof(path));
764 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (source_regex=\"%s\", file=\"%s\", module_name=\"%s\") => SBBreakpoint(%p)",
Greg Claytona253c932011-09-21 06:45:51 +0000765 m_opaque_sp.get(), source_regex, path, module_name, sb_bp.get());
Jim Ingham03c8ee52011-09-21 01:17:13 +0000766 }
767
768 return sb_bp;
769}
770
Jim Inghamd6d47972011-09-23 00:54:11 +0000771lldb::SBBreakpoint
772SBTarget::BreakpointCreateBySourceRegex (const char *source_regex,
773 const SBFileSpecList &module_list,
774 const lldb::SBFileSpecList &source_file_list)
775{
776 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
777
778 SBBreakpoint sb_bp;
779 if (m_opaque_sp.get() && source_regex && source_regex[0])
780 {
781 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
782 RegularExpression regexp(source_regex);
783 *sb_bp = m_opaque_sp->CreateSourceRegexBreakpoint (module_list.get(), source_file_list.get(), regexp, false);
784 }
785
786 if (log)
787 {
788 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (source_regex=\"%s\") => SBBreakpoint(%p)",
789 m_opaque_sp.get(), source_regex, sb_bp.get());
790 }
791
792 return sb_bp;
793}
Jim Ingham03c8ee52011-09-21 01:17:13 +0000794
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000795uint32_t
796SBTarget::GetNumBreakpoints () const
797{
798 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000799 {
800 // The breakpoint list is thread safe, no need to lock
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000801 return m_opaque_sp->GetBreakpointList().GetSize();
Greg Claytonbdcda462010-12-20 20:49:23 +0000802 }
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000803 return 0;
804}
805
806SBBreakpoint
807SBTarget::GetBreakpointAtIndex (uint32_t idx) const
808{
809 SBBreakpoint sb_breakpoint;
810 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000811 {
812 // The breakpoint list is thread safe, no need to lock
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000813 *sb_breakpoint = m_opaque_sp->GetBreakpointList().GetBreakpointAtIndex(idx);
Greg Claytonbdcda462010-12-20 20:49:23 +0000814 }
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000815 return sb_breakpoint;
816}
Chris Lattner24943d22010-06-08 16:52:24 +0000817
818bool
819SBTarget::BreakpointDelete (break_id_t bp_id)
820{
Greg Claytone005f2c2010-11-06 01:53:30 +0000821 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000822
Caroline Tice7826c882010-10-26 03:11:13 +0000823 bool result = false;
Greg Clayton63094e02010-06-23 01:19:29 +0000824 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000825 {
826 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
Caroline Tice7826c882010-10-26 03:11:13 +0000827 result = m_opaque_sp->RemoveBreakpointByID (bp_id);
Greg Claytonbdcda462010-12-20 20:49:23 +0000828 }
Caroline Tice7826c882010-10-26 03:11:13 +0000829
830 if (log)
831 {
Greg Clayton3f5ee7f2010-10-29 04:59:35 +0000832 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 +0000833 }
834
835 return result;
Chris Lattner24943d22010-06-08 16:52:24 +0000836}
837
Johnny Chen096c2932011-09-26 22:40:50 +0000838SBBreakpoint
839SBTarget::FindBreakpointByID (break_id_t bp_id)
840{
841 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
842
843 SBBreakpoint sb_breakpoint;
844 if (m_opaque_sp && bp_id != LLDB_INVALID_BREAK_ID)
845 {
846 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
847 *sb_breakpoint = m_opaque_sp->GetBreakpointByID (bp_id);
848 }
849
850 if (log)
851 {
852 log->Printf ("SBTarget(%p)::FindBreakpointByID (bp_id=%d) => SBBreakpoint(%p)",
853 m_opaque_sp.get(), (uint32_t) bp_id, sb_breakpoint.get());
854 }
855
856 return sb_breakpoint;
857}
858
Chris Lattner24943d22010-06-08 16:52:24 +0000859bool
860SBTarget::EnableAllBreakpoints ()
861{
Greg Clayton63094e02010-06-23 01:19:29 +0000862 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000863 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000864 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
Greg Clayton63094e02010-06-23 01:19:29 +0000865 m_opaque_sp->EnableAllBreakpoints ();
Chris Lattner24943d22010-06-08 16:52:24 +0000866 return true;
867 }
868 return false;
869}
870
871bool
872SBTarget::DisableAllBreakpoints ()
873{
Greg Clayton63094e02010-06-23 01:19:29 +0000874 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000875 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000876 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
Greg Clayton63094e02010-06-23 01:19:29 +0000877 m_opaque_sp->DisableAllBreakpoints ();
Chris Lattner24943d22010-06-08 16:52:24 +0000878 return true;
879 }
880 return false;
881}
882
883bool
884SBTarget::DeleteAllBreakpoints ()
885{
Greg Clayton63094e02010-06-23 01:19:29 +0000886 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000887 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000888 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
Greg Clayton63094e02010-06-23 01:19:29 +0000889 m_opaque_sp->RemoveAllBreakpoints ();
Chris Lattner24943d22010-06-08 16:52:24 +0000890 return true;
891 }
892 return false;
893}
894
Johnny Chen096c2932011-09-26 22:40:50 +0000895uint32_t
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000896SBTarget::GetNumWatchpoints () const
Johnny Chen096c2932011-09-26 22:40:50 +0000897{
898 if (m_opaque_sp)
899 {
Johnny Chenecd4feb2011-10-14 00:42:25 +0000900 // The watchpoint list is thread safe, no need to lock
901 return m_opaque_sp->GetWatchpointList().GetSize();
Johnny Chen096c2932011-09-26 22:40:50 +0000902 }
903 return 0;
904}
905
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000906SBWatchpoint
907SBTarget::GetWatchpointAtIndex (uint32_t idx) const
Johnny Chen5eb54bb2011-09-27 20:29:45 +0000908{
Johnny Chenecd4feb2011-10-14 00:42:25 +0000909 SBWatchpoint sb_watchpoint;
Johnny Chen096c2932011-09-26 22:40:50 +0000910 if (m_opaque_sp)
911 {
Johnny Chenecd4feb2011-10-14 00:42:25 +0000912 // The watchpoint list is thread safe, no need to lock
913 *sb_watchpoint = m_opaque_sp->GetWatchpointList().GetByIndex(idx);
Johnny Chen096c2932011-09-26 22:40:50 +0000914 }
Johnny Chenecd4feb2011-10-14 00:42:25 +0000915 return sb_watchpoint;
Johnny Chen096c2932011-09-26 22:40:50 +0000916}
917
918bool
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000919SBTarget::DeleteWatchpoint (watch_id_t wp_id)
Johnny Chen096c2932011-09-26 22:40:50 +0000920{
921 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
922
923 bool result = false;
924 if (m_opaque_sp)
925 {
926 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
Johnny Chenecd4feb2011-10-14 00:42:25 +0000927 result = m_opaque_sp->RemoveWatchpointByID (wp_id);
Johnny Chen096c2932011-09-26 22:40:50 +0000928 }
929
930 if (log)
931 {
Johnny Chenecd4feb2011-10-14 00:42:25 +0000932 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 +0000933 }
934
935 return result;
936}
937
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000938SBWatchpoint
939SBTarget::FindWatchpointByID (lldb::watch_id_t wp_id)
Johnny Chen096c2932011-09-26 22:40:50 +0000940{
941 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
942
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000943 SBWatchpoint sb_watchpoint;
Johnny Chen096c2932011-09-26 22:40:50 +0000944 if (m_opaque_sp && wp_id != LLDB_INVALID_WATCH_ID)
945 {
946 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
Johnny Chenecd4feb2011-10-14 00:42:25 +0000947 *sb_watchpoint = m_opaque_sp->GetWatchpointList().FindByID(wp_id);
Johnny Chen096c2932011-09-26 22:40:50 +0000948 }
949
950 if (log)
951 {
Johnny Chenecd4feb2011-10-14 00:42:25 +0000952 log->Printf ("SBTarget(%p)::FindWatchpointByID (bp_id=%d) => SBWatchpoint(%p)",
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000953 m_opaque_sp.get(), (uint32_t) wp_id, sb_watchpoint.get());
Johnny Chen096c2932011-09-26 22:40:50 +0000954 }
955
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000956 return sb_watchpoint;
957}
958
959lldb::SBWatchpoint
960SBTarget::WatchAddress (lldb::addr_t addr, size_t size, bool read, bool write)
961{
962 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
963
964 SBWatchpoint sb_watchpoint;
965 if (m_opaque_sp)
966 {
967 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
Johnny Chenecd4feb2011-10-14 00:42:25 +0000968 uint32_t watch_type = (read ? LLDB_WATCH_TYPE_READ : 0) |
969 (write ? LLDB_WATCH_TYPE_WRITE : 0);
Johnny Chen50e05342011-10-14 01:16:39 +0000970 sb_watchpoint = m_opaque_sp->CreateWatchpoint(addr, size, watch_type);
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000971 }
972
973 if (log)
974 {
975 log->Printf ("SBTarget(%p)::WatchAddress (addr=0x%llx, 0x%u) => SBWatchpoint(%p)",
976 m_opaque_sp.get(), addr, (uint32_t) size, sb_watchpoint.get());
977 }
978
979 return sb_watchpoint;
Johnny Chen096c2932011-09-26 22:40:50 +0000980}
981
982bool
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000983SBTarget::EnableAllWatchpoints ()
Johnny Chen096c2932011-09-26 22:40:50 +0000984{
985 if (m_opaque_sp)
986 {
987 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
Johnny Chenecd4feb2011-10-14 00:42:25 +0000988 m_opaque_sp->EnableAllWatchpoints ();
Johnny Chen096c2932011-09-26 22:40:50 +0000989 return true;
990 }
991 return false;
992}
993
994bool
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000995SBTarget::DisableAllWatchpoints ()
Johnny Chen096c2932011-09-26 22:40:50 +0000996{
997 if (m_opaque_sp)
998 {
999 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
Johnny Chenecd4feb2011-10-14 00:42:25 +00001000 m_opaque_sp->DisableAllWatchpoints ();
Johnny Chen096c2932011-09-26 22:40:50 +00001001 return true;
1002 }
1003 return false;
1004}
1005
1006bool
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001007SBTarget::DeleteAllWatchpoints ()
Johnny Chen096c2932011-09-26 22:40:50 +00001008{
1009 if (m_opaque_sp)
1010 {
1011 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
Johnny Chenecd4feb2011-10-14 00:42:25 +00001012 m_opaque_sp->RemoveAllWatchpoints ();
Johnny Chen096c2932011-09-26 22:40:50 +00001013 return true;
1014 }
1015 return false;
1016}
1017
Chris Lattner24943d22010-06-08 16:52:24 +00001018
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001019lldb::SBModule
1020SBTarget::AddModule (const char *path,
1021 const char *triple,
1022 const char *uuid_cstr)
1023{
1024 lldb::SBModule sb_module;
1025 if (m_opaque_sp)
1026 {
1027 FileSpec module_file_spec;
1028 UUID module_uuid;
1029 ArchSpec module_arch;
1030
1031 if (path)
1032 module_file_spec.SetFile(path, false);
1033
1034 if (uuid_cstr)
1035 module_uuid.SetfromCString(uuid_cstr);
1036
1037 if (triple)
1038 module_arch.SetTriple (triple, m_opaque_sp->GetPlatform ().get());
1039
1040 sb_module.SetModule(m_opaque_sp->GetSharedModule (module_file_spec,
1041 module_arch,
1042 uuid_cstr ? &module_uuid : NULL));
1043 }
1044 return sb_module;
1045}
1046
1047bool
1048SBTarget::AddModule (lldb::SBModule &module)
1049{
1050 if (m_opaque_sp)
1051 {
1052 m_opaque_sp->GetImages().AppendIfNeeded (module.get_sp());
1053 return true;
1054 }
1055 return false;
1056}
1057
1058lldb::SBModule
1059AddModule (const char *path,
1060 const char *triple,
1061 const char *uuid);
1062
1063
1064
Chris Lattner24943d22010-06-08 16:52:24 +00001065uint32_t
1066SBTarget::GetNumModules () const
1067{
Greg Claytone005f2c2010-11-06 01:53:30 +00001068 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001069
Caroline Tice7826c882010-10-26 03:11:13 +00001070 uint32_t num = 0;
Greg Clayton63094e02010-06-23 01:19:29 +00001071 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +00001072 {
1073 // The module list is thread safe, no need to lock
1074 num = m_opaque_sp->GetImages().GetSize();
1075 }
Caroline Tice7826c882010-10-26 03:11:13 +00001076
1077 if (log)
Greg Clayton3f5ee7f2010-10-29 04:59:35 +00001078 log->Printf ("SBTarget(%p)::GetNumModules () => %d", m_opaque_sp.get(), num);
Caroline Tice7826c882010-10-26 03:11:13 +00001079
1080 return num;
Chris Lattner24943d22010-06-08 16:52:24 +00001081}
1082
Greg Clayton43490d12010-07-30 20:12:55 +00001083void
1084SBTarget::Clear ()
1085{
Greg Claytone005f2c2010-11-06 01:53:30 +00001086 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001087
1088 if (log)
Greg Clayton3f5ee7f2010-10-29 04:59:35 +00001089 log->Printf ("SBTarget(%p)::Clear ()", m_opaque_sp.get());
Caroline Tice7826c882010-10-26 03:11:13 +00001090
Greg Clayton43490d12010-07-30 20:12:55 +00001091 m_opaque_sp.reset();
1092}
1093
1094
Chris Lattner24943d22010-06-08 16:52:24 +00001095SBModule
1096SBTarget::FindModule (const SBFileSpec &sb_file_spec)
1097{
1098 SBModule sb_module;
Greg Clayton63094e02010-06-23 01:19:29 +00001099 if (m_opaque_sp && sb_file_spec.IsValid())
Greg Claytonbdcda462010-12-20 20:49:23 +00001100 {
1101 // The module list is thread safe, no need to lock
Greg Clayton24bc5d92011-03-30 18:16:51 +00001102 sb_module.SetModule (m_opaque_sp->GetImages().FindFirstModuleForFileSpec (*sb_file_spec, NULL, NULL));
Greg Claytonbdcda462010-12-20 20:49:23 +00001103 }
Chris Lattner24943d22010-06-08 16:52:24 +00001104 return sb_module;
1105}
1106
1107SBModule
1108SBTarget::GetModuleAtIndex (uint32_t idx)
1109{
Greg Claytone005f2c2010-11-06 01:53:30 +00001110 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001111
Chris Lattner24943d22010-06-08 16:52:24 +00001112 SBModule sb_module;
Greg Clayton63094e02010-06-23 01:19:29 +00001113 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +00001114 {
1115 // The module list is thread safe, no need to lock
Greg Clayton63094e02010-06-23 01:19:29 +00001116 sb_module.SetModule(m_opaque_sp->GetImages().GetModuleAtIndex(idx));
Greg Claytonbdcda462010-12-20 20:49:23 +00001117 }
Caroline Tice7826c882010-10-26 03:11:13 +00001118
1119 if (log)
1120 {
Greg Clayton49ce6822010-10-31 03:01:06 +00001121 log->Printf ("SBTarget(%p)::GetModuleAtIndex (idx=%d) => SBModule(%p)",
1122 m_opaque_sp.get(), idx, sb_module.get());
Caroline Tice7826c882010-10-26 03:11:13 +00001123 }
1124
Chris Lattner24943d22010-06-08 16:52:24 +00001125 return sb_module;
1126}
1127
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001128bool
1129SBTarget::RemoveModule (lldb::SBModule module)
1130{
1131 if (m_opaque_sp)
1132 return m_opaque_sp->GetImages().Remove(module.get_sp());
1133 return false;
1134}
1135
Chris Lattner24943d22010-06-08 16:52:24 +00001136
1137SBBroadcaster
1138SBTarget::GetBroadcaster () const
1139{
Greg Claytone005f2c2010-11-06 01:53:30 +00001140 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001141
Greg Clayton63094e02010-06-23 01:19:29 +00001142 SBBroadcaster broadcaster(m_opaque_sp.get(), false);
Caroline Tice7826c882010-10-26 03:11:13 +00001143
1144 if (log)
Greg Clayton3f5ee7f2010-10-29 04:59:35 +00001145 log->Printf ("SBTarget(%p)::GetBroadcaster () => SBBroadcaster(%p)",
Caroline Tice61ba7ec2010-10-26 23:49:36 +00001146 m_opaque_sp.get(), broadcaster.get());
Caroline Tice7826c882010-10-26 03:11:13 +00001147
Chris Lattner24943d22010-06-08 16:52:24 +00001148 return broadcaster;
1149}
1150
Caroline Tice98f930f2010-09-20 05:20:02 +00001151
1152bool
Caroline Tice7826c882010-10-26 03:11:13 +00001153SBTarget::GetDescription (SBStream &description, lldb::DescriptionLevel description_level)
Caroline Tice98f930f2010-09-20 05:20:02 +00001154{
1155 if (m_opaque_sp)
Caroline Ticee7a566e2010-09-20 16:21:41 +00001156 {
Caroline Ticee49ec182010-09-22 23:01:29 +00001157 description.ref();
Caroline Tice7826c882010-10-26 03:11:13 +00001158 m_opaque_sp->Dump (description.get(), description_level);
1159 }
1160 else
1161 description.Printf ("No value");
1162
1163 return true;
1164}
1165
1166bool
1167SBTarget::GetDescription (SBStream &description, lldb::DescriptionLevel description_level) const
1168{
1169 if (m_opaque_sp)
1170 {
1171 description.ref();
1172 m_opaque_sp->Dump (description.get(), description_level);
Caroline Ticee7a566e2010-09-20 16:21:41 +00001173 }
Caroline Tice98f930f2010-09-20 05:20:02 +00001174 else
1175 description.Printf ("No value");
1176
1177 return true;
1178}
Greg Clayton4ed315f2011-06-21 01:34:41 +00001179
1180
1181uint32_t
1182SBTarget::FindFunctions (const char *name,
1183 uint32_t name_type_mask,
1184 bool append,
1185 lldb::SBSymbolContextList& sc_list)
1186{
1187 if (!append)
1188 sc_list.Clear();
1189 if (m_opaque_sp)
1190 {
1191 const bool symbols_ok = true;
1192 return m_opaque_sp->GetImages().FindFunctions (ConstString(name),
1193 name_type_mask,
1194 symbols_ok,
1195 append,
1196 *sc_list);
1197 }
1198 return 0;
1199}
1200
Enrico Granata979e20d2011-07-29 19:53:35 +00001201lldb::SBType
1202SBTarget::FindFirstType (const char* type)
1203{
1204 if (m_opaque_sp)
1205 {
1206 size_t count = m_opaque_sp->GetImages().GetSize();
1207 for (size_t idx = 0; idx < count; idx++)
1208 {
1209 SBType found_at_idx = GetModuleAtIndex(idx).FindFirstType(type);
1210
1211 if (found_at_idx.IsValid())
1212 return found_at_idx;
1213 }
1214 }
1215 return SBType();
1216}
1217
1218lldb::SBTypeList
1219SBTarget::FindTypes (const char* type)
1220{
1221
1222 SBTypeList retval;
1223
1224 if (m_opaque_sp)
1225 {
1226 ModuleList& images = m_opaque_sp->GetImages();
1227 ConstString name_const(type);
1228 SymbolContext sc;
1229 TypeList type_list;
1230
1231 uint32_t num_matches = images.FindTypes(sc,
1232 name_const,
1233 true,
1234 UINT32_MAX,
1235 type_list);
1236
1237 for (size_t idx = 0; idx < num_matches; idx++)
1238 {
Greg Clayton0fb0bcc2011-08-03 22:57:10 +00001239 TypeSP type_sp (type_list.GetTypeAtIndex(idx));
1240 if (type_sp)
1241 retval.Append(SBType(type_sp));
Enrico Granata979e20d2011-07-29 19:53:35 +00001242 }
1243 }
1244 return retval;
1245}
1246
Greg Clayton917c0002011-06-29 22:09:02 +00001247SBValueList
1248SBTarget::FindGlobalVariables (const char *name, uint32_t max_matches)
1249{
1250 SBValueList sb_value_list;
1251
1252 if (m_opaque_sp)
1253 {
1254 VariableList variable_list;
1255 const bool append = true;
1256 const uint32_t match_count = m_opaque_sp->GetImages().FindGlobalVariables (ConstString (name),
1257 append,
1258 max_matches,
1259 variable_list);
1260
1261 if (match_count > 0)
1262 {
1263 ExecutionContextScope *exe_scope = m_opaque_sp->GetProcessSP().get();
1264 if (exe_scope == NULL)
1265 exe_scope = m_opaque_sp.get();
1266 ValueObjectList &value_object_list = sb_value_list.ref();
1267 for (uint32_t i=0; i<match_count; ++i)
1268 {
1269 lldb::ValueObjectSP valobj_sp (ValueObjectVariable::Create (exe_scope, variable_list.GetVariableAtIndex(i)));
1270 if (valobj_sp)
1271 value_object_list.Append(valobj_sp);
1272 }
1273 }
1274 }
1275
1276 return sb_value_list;
1277}
1278
Jim Inghamcc637462011-09-13 00:29:56 +00001279SBSourceManager
1280SBTarget::GetSourceManager()
1281{
1282 SBSourceManager source_manager (*this);
1283 return source_manager;
1284}
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001285
1286
1287SBError
1288SBTarget::SetSectionLoadAddress (lldb::SBSection section,
1289 lldb::addr_t section_base_addr)
1290{
1291 SBError sb_error;
1292
1293 if (IsValid())
1294 {
1295 if (!section.IsValid())
1296 {
1297 sb_error.SetErrorStringWithFormat ("invalid section");
1298 }
1299 else
1300 {
1301 m_opaque_sp->GetSectionLoadList().SetSectionLoadAddress (section.GetSection(), section_base_addr);
1302 }
1303 }
1304 else
1305 {
1306 sb_error.SetErrorStringWithFormat ("invalid target");
1307 }
1308 return sb_error;
1309}
1310
1311SBError
1312SBTarget::ClearSectionLoadAddress (lldb::SBSection section)
1313{
1314 SBError sb_error;
1315
1316 if (IsValid())
1317 {
1318 if (!section.IsValid())
1319 {
1320 sb_error.SetErrorStringWithFormat ("invalid section");
1321 }
1322 else
1323 {
1324 m_opaque_sp->GetSectionLoadList().SetSectionUnloaded (section.GetSection());
1325 }
1326 }
1327 else
1328 {
1329 sb_error.SetErrorStringWithFormat ("invalid target");
1330 }
1331 return sb_error;
1332}
1333
1334SBError
1335SBTarget::SetModuleLoadAddress (lldb::SBModule module, int64_t slide_offset)
1336{
1337 SBError sb_error;
1338
1339 char path[PATH_MAX];
1340 if (IsValid())
1341 {
1342 if (!module.IsValid())
1343 {
1344 sb_error.SetErrorStringWithFormat ("invalid module");
1345 }
1346 else
1347 {
1348 ObjectFile *objfile = module->GetObjectFile();
1349 if (objfile)
1350 {
1351 SectionList *section_list = objfile->GetSectionList();
1352 if (section_list)
1353 {
1354 const size_t num_sections = section_list->GetSize();
1355 for (size_t sect_idx = 0; sect_idx < num_sections; ++sect_idx)
1356 {
1357 SectionSP section_sp (section_list->GetSectionAtIndex(sect_idx));
1358 if (section_sp)
1359 m_opaque_sp->GetSectionLoadList().SetSectionLoadAddress (section_sp.get(), section_sp->GetFileAddress() + slide_offset);
1360 }
1361 }
1362 else
1363 {
1364 module->GetFileSpec().GetPath (path, sizeof(path));
1365 sb_error.SetErrorStringWithFormat ("no sections in object file '%s'", path);
1366 }
1367 }
1368 else
1369 {
1370 module->GetFileSpec().GetPath (path, sizeof(path));
1371 sb_error.SetErrorStringWithFormat ("no object file for module '%s'", path);
1372 }
1373 }
1374 }
1375 else
1376 {
1377 sb_error.SetErrorStringWithFormat ("invalid target");
1378 }
1379 return sb_error;
1380}
1381
1382SBError
1383SBTarget::ClearModuleLoadAddress (lldb::SBModule module)
1384{
1385 SBError sb_error;
1386
1387 char path[PATH_MAX];
1388 if (IsValid())
1389 {
1390 if (!module.IsValid())
1391 {
1392 sb_error.SetErrorStringWithFormat ("invalid module");
1393 }
1394 else
1395 {
1396 ObjectFile *objfile = module->GetObjectFile();
1397 if (objfile)
1398 {
1399 SectionList *section_list = objfile->GetSectionList();
1400 if (section_list)
1401 {
1402 const size_t num_sections = section_list->GetSize();
1403 for (size_t sect_idx = 0; sect_idx < num_sections; ++sect_idx)
1404 {
1405 SectionSP section_sp (section_list->GetSectionAtIndex(sect_idx));
1406 if (section_sp)
1407 m_opaque_sp->GetSectionLoadList().SetSectionUnloaded (section_sp.get());
1408 }
1409 }
1410 else
1411 {
1412 module->GetFileSpec().GetPath (path, sizeof(path));
1413 sb_error.SetErrorStringWithFormat ("no sections in object file '%s'", path);
1414 }
1415 }
1416 else
1417 {
1418 module->GetFileSpec().GetPath (path, sizeof(path));
1419 sb_error.SetErrorStringWithFormat ("no object file for module '%s'", path);
1420 }
1421 }
1422 }
1423 else
1424 {
1425 sb_error.SetErrorStringWithFormat ("invalid target");
1426 }
1427 return sb_error;
1428}
1429
1430