blob: d32215e274c3d367ee80df6c4ff737c9f52c652a [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
234 error.SetError (sb_process->Launch (argv, envp, launch_flags, stdin_path, stdout_path, stderr_path, working_directory));
235 if (error.Success())
Greg Clayton7c330d62011-01-27 01:01:10 +0000236 {
Greg Clayton180546b2011-04-30 01:09:13 +0000237 // We we are stopping at the entry point, we can return now!
238 if (stop_at_entry)
239 return sb_process;
Greg Clayton7c330d62011-01-27 01:01:10 +0000240
Greg Clayton180546b2011-04-30 01:09:13 +0000241 // Make sure we are stopped at the entry
242 StateType state = sb_process->WaitForProcessToStop (NULL);
243 if (state == eStateStopped)
Greg Clayton7c330d62011-01-27 01:01:10 +0000244 {
Greg Clayton180546b2011-04-30 01:09:13 +0000245 // resume the process to skip the entry point
246 error.SetError (sb_process->Resume());
247 if (error.Success())
Greg Clayton7c330d62011-01-27 01:01:10 +0000248 {
Greg Clayton180546b2011-04-30 01:09:13 +0000249 // If we are doing synchronous mode, then wait for the
250 // process to stop yet again!
251 if (m_opaque_sp->GetDebugger().GetAsyncExecution () == false)
252 sb_process->WaitForProcessToStop (NULL);
Greg Clayton7c330d62011-01-27 01:01:10 +0000253 }
254 }
255 }
Greg Clayton180546b2011-04-30 01:09:13 +0000256 }
257 else
258 {
259 error.SetErrorString ("unable to create lldb_private::Process");
Greg Claytonc5f728c2010-10-06 22:10:17 +0000260 }
261 }
262 else
263 {
264 error.SetErrorString ("SBTarget is invalid");
Chris Lattner24943d22010-06-08 16:52:24 +0000265 }
Caroline Tice7826c882010-10-26 03:11:13 +0000266
Caroline Tice926060e2010-10-29 21:48:37 +0000267 log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
Caroline Tice7826c882010-10-26 03:11:13 +0000268 if (log)
269 {
Greg Clayton49ce6822010-10-31 03:01:06 +0000270 log->Printf ("SBTarget(%p)::Launch (...) => SBProceess(%p)",
271 m_opaque_sp.get(), sb_process.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000272 }
273
Greg Clayton1a3083a2010-10-06 03:53:16 +0000274 return sb_process;
Chris Lattner24943d22010-06-08 16:52:24 +0000275}
276
Greg Claytonc5f728c2010-10-06 22:10:17 +0000277
278lldb::SBProcess
Greg Claytond8c62532010-10-07 04:19:01 +0000279SBTarget::AttachToProcessWithID
Greg Claytonc5f728c2010-10-06 22:10:17 +0000280(
Greg Clayton271a5db2011-02-03 21:28:34 +0000281 SBListener &listener,
Greg Claytonc5f728c2010-10-06 22:10:17 +0000282 lldb::pid_t pid,// The process ID to attach to
283 SBError& error // An error explaining what went wrong if attach fails
284)
285{
286 SBProcess sb_process;
287 if (m_opaque_sp)
288 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000289 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
Greg Claytonde1dd812011-06-24 03:21:43 +0000290
291 StateType state = eStateInvalid;
292 sb_process.SetProcess (m_opaque_sp->GetProcessSP());
293 if (sb_process.IsValid())
294 {
295 state = sb_process->GetState();
296
297 if (sb_process->IsAlive() && state != eStateConnected)
298 {
299 if (state == eStateAttaching)
300 error.SetErrorString ("process attach is in progress");
301 else
302 error.SetErrorString ("a process is already being debugged");
303 sb_process.Clear();
304 return sb_process;
305 }
306 }
307
308 if (state == eStateConnected)
309 {
310 // If we are already connected, then we have already specified the
311 // listener, so if a valid listener is supplied, we need to error out
312 // to let the client know.
313 if (listener.IsValid())
314 {
315 error.SetErrorString ("process is connected and already has a listener, pass empty listener");
316 sb_process.Clear();
317 return sb_process;
318 }
319 }
Greg Clayton271a5db2011-02-03 21:28:34 +0000320 else
Greg Claytonde1dd812011-06-24 03:21:43 +0000321 {
322 if (listener.IsValid())
323 sb_process.SetProcess (m_opaque_sp->CreateProcess (listener.ref()));
324 else
325 sb_process.SetProcess (m_opaque_sp->CreateProcess (m_opaque_sp->GetDebugger().GetListener()));
326 }
Greg Claytonc5f728c2010-10-06 22:10:17 +0000327
328 if (sb_process.IsValid())
329 {
330 error.SetError (sb_process->Attach (pid));
Johnny Chen535960e2011-06-17 00:51:15 +0000331 // If we are doing synchronous mode, then wait for the
332 // process to stop!
333 if (m_opaque_sp->GetDebugger().GetAsyncExecution () == false)
334 sb_process->WaitForProcessToStop (NULL);
Greg Claytonc5f728c2010-10-06 22:10:17 +0000335 }
336 else
337 {
338 error.SetErrorString ("unable to create lldb_private::Process");
339 }
340 }
341 else
342 {
343 error.SetErrorString ("SBTarget is invalid");
344 }
345 return sb_process;
346
347}
348
349lldb::SBProcess
Greg Claytond8c62532010-10-07 04:19:01 +0000350SBTarget::AttachToProcessWithName
Greg Claytonc5f728c2010-10-06 22:10:17 +0000351(
Greg Clayton271a5db2011-02-03 21:28:34 +0000352 SBListener &listener,
Greg Claytonc5f728c2010-10-06 22:10:17 +0000353 const char *name, // basename of process to attach to
354 bool wait_for, // if true wait for a new instance of "name" to be launched
355 SBError& error // An error explaining what went wrong if attach fails
356)
357{
358 SBProcess sb_process;
359 if (m_opaque_sp)
360 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000361 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
362
Greg Claytonde1dd812011-06-24 03:21:43 +0000363 StateType state = eStateInvalid;
364 sb_process.SetProcess (m_opaque_sp->GetProcessSP());
365 if (sb_process.IsValid())
366 {
367 state = sb_process->GetState();
368
369 if (sb_process->IsAlive() && state != eStateConnected)
370 {
371 if (state == eStateAttaching)
372 error.SetErrorString ("process attach is in progress");
373 else
374 error.SetErrorString ("a process is already being debugged");
375 sb_process.Clear();
376 return sb_process;
377 }
378 }
379
380 if (state == eStateConnected)
381 {
382 // If we are already connected, then we have already specified the
383 // listener, so if a valid listener is supplied, we need to error out
384 // to let the client know.
385 if (listener.IsValid())
386 {
387 error.SetErrorString ("process is connected and already has a listener, pass empty listener");
388 sb_process.Clear();
389 return sb_process;
390 }
391 }
Greg Clayton271a5db2011-02-03 21:28:34 +0000392 else
Greg Claytonde1dd812011-06-24 03:21:43 +0000393 {
394 if (listener.IsValid())
395 sb_process.SetProcess (m_opaque_sp->CreateProcess (listener.ref()));
396 else
397 sb_process.SetProcess (m_opaque_sp->CreateProcess (m_opaque_sp->GetDebugger().GetListener()));
398 }
Greg Claytonc5f728c2010-10-06 22:10:17 +0000399
400 if (sb_process.IsValid())
401 {
402 error.SetError (sb_process->Attach (name, wait_for));
Johnny Chen58d02ff2011-06-17 19:21:30 +0000403 // If we are doing synchronous mode, then wait for the
404 // process to stop!
405 if (m_opaque_sp->GetDebugger().GetAsyncExecution () == false)
406 sb_process->WaitForProcessToStop (NULL);
Greg Claytonc5f728c2010-10-06 22:10:17 +0000407 }
408 else
409 {
410 error.SetErrorString ("unable to create lldb_private::Process");
411 }
412 }
413 else
414 {
415 error.SetErrorString ("SBTarget is invalid");
416 }
417 return sb_process;
418
419}
420
James McIlree38093402011-03-04 00:31:13 +0000421lldb::SBProcess
422SBTarget::ConnectRemote
423(
424 SBListener &listener,
425 const char *url,
426 const char *plugin_name,
427 SBError& error
428)
429{
430 SBProcess sb_process;
431 if (m_opaque_sp)
432 {
433 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
434 if (listener.IsValid())
435 sb_process.SetProcess (m_opaque_sp->CreateProcess (listener.ref(), plugin_name));
436 else
437 sb_process.SetProcess (m_opaque_sp->CreateProcess (m_opaque_sp->GetDebugger().GetListener(), plugin_name));
438
439
440 if (sb_process.IsValid())
441 {
442 error.SetError (sb_process->ConnectRemote (url));
443 }
444 else
445 {
446 error.SetErrorString ("unable to create lldb_private::Process");
447 }
448 }
449 else
450 {
451 error.SetErrorString ("SBTarget is invalid");
452 }
453 return sb_process;
454}
455
Chris Lattner24943d22010-06-08 16:52:24 +0000456SBFileSpec
457SBTarget::GetExecutable ()
458{
Caroline Tice7826c882010-10-26 03:11:13 +0000459
Chris Lattner24943d22010-06-08 16:52:24 +0000460 SBFileSpec exe_file_spec;
Greg Clayton63094e02010-06-23 01:19:29 +0000461 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000462 {
Greg Clayton5beb99d2011-08-11 02:48:45 +0000463 Module *exe_module = m_opaque_sp->GetExecutableModulePointer();
464 if (exe_module)
465 exe_file_spec.SetFileSpec (exe_module->GetFileSpec());
Chris Lattner24943d22010-06-08 16:52:24 +0000466 }
Caroline Tice7826c882010-10-26 03:11:13 +0000467
Greg Claytone005f2c2010-11-06 01:53:30 +0000468 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000469 if (log)
470 {
Greg Clayton49ce6822010-10-31 03:01:06 +0000471 log->Printf ("SBTarget(%p)::GetExecutable () => SBFileSpec(%p)",
472 m_opaque_sp.get(), exe_file_spec.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000473 }
474
Chris Lattner24943d22010-06-08 16:52:24 +0000475 return exe_file_spec;
476}
477
Chris Lattner24943d22010-06-08 16:52:24 +0000478bool
Chris Lattner24943d22010-06-08 16:52:24 +0000479SBTarget::operator == (const SBTarget &rhs) const
480{
Greg Clayton63094e02010-06-23 01:19:29 +0000481 return m_opaque_sp.get() == rhs.m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000482}
483
484bool
485SBTarget::operator != (const SBTarget &rhs) const
486{
Greg Clayton63094e02010-06-23 01:19:29 +0000487 return m_opaque_sp.get() != rhs.m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000488}
489
490lldb_private::Target *
Greg Clayton63094e02010-06-23 01:19:29 +0000491SBTarget::operator ->() const
Chris Lattner24943d22010-06-08 16:52:24 +0000492{
Greg Clayton63094e02010-06-23 01:19:29 +0000493 return m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000494}
Greg Clayton63094e02010-06-23 01:19:29 +0000495
496lldb_private::Target *
497SBTarget::get() const
Chris Lattner24943d22010-06-08 16:52:24 +0000498{
Greg Clayton63094e02010-06-23 01:19:29 +0000499 return m_opaque_sp.get();
500}
501
Greg Clayton15afa9f2011-10-01 02:59:24 +0000502const lldb::TargetSP &
503SBTarget::get_sp () const
504{
505 return m_opaque_sp;
506}
507
Greg Clayton63094e02010-06-23 01:19:29 +0000508void
509SBTarget::reset (const lldb::TargetSP& target_sp)
510{
511 m_opaque_sp = target_sp;
Chris Lattner24943d22010-06-08 16:52:24 +0000512}
513
Greg Claytona3955062011-07-22 16:46:35 +0000514lldb::SBAddress
515SBTarget::ResolveLoadAddress (lldb::addr_t vm_addr)
Greg Claytonea49cc72010-12-12 19:25:26 +0000516{
Greg Claytona3955062011-07-22 16:46:35 +0000517 lldb::SBAddress sb_addr;
518 Address &addr = sb_addr.ref();
519 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000520 {
521 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
Greg Claytona3955062011-07-22 16:46:35 +0000522 if (m_opaque_sp->GetSectionLoadList().ResolveLoadAddress (vm_addr, addr))
523 return sb_addr;
Greg Claytonbdcda462010-12-20 20:49:23 +0000524 }
Greg Claytonea49cc72010-12-12 19:25:26 +0000525
Greg Claytona3955062011-07-22 16:46:35 +0000526 // We have a load address that isn't in a section, just return an address
527 // with the offset filled in (the address) and the section set to NULL
528 addr.SetSection(NULL);
529 addr.SetOffset(vm_addr);
530 return sb_addr;
Greg Claytonea49cc72010-12-12 19:25:26 +0000531}
532
Greg Claytonafb81862011-03-02 21:34:46 +0000533SBSymbolContext
534SBTarget::ResolveSymbolContextForAddress (const SBAddress& addr, uint32_t resolve_scope)
535{
536 SBSymbolContext sc;
Johnny Chene657fbc2011-06-29 00:05:40 +0000537 if (m_opaque_sp && addr.IsValid())
Greg Claytona3955062011-07-22 16:46:35 +0000538 m_opaque_sp->GetImages().ResolveSymbolContextForAddress (addr.ref(), resolve_scope, sc.ref());
Greg Claytonafb81862011-03-02 21:34:46 +0000539 return sc;
540}
541
542
Chris Lattner24943d22010-06-08 16:52:24 +0000543SBBreakpoint
544SBTarget::BreakpointCreateByLocation (const char *file, uint32_t line)
545{
Greg Claytond6d806c2010-11-08 00:28:40 +0000546 return SBBreakpoint(BreakpointCreateByLocation (SBFileSpec (file, false), line));
Chris Lattner24943d22010-06-08 16:52:24 +0000547}
548
549SBBreakpoint
550SBTarget::BreakpointCreateByLocation (const SBFileSpec &sb_file_spec, uint32_t line)
551{
Greg Claytone005f2c2010-11-06 01:53:30 +0000552 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000553
Chris Lattner24943d22010-06-08 16:52:24 +0000554 SBBreakpoint sb_bp;
Greg Clayton63094e02010-06-23 01:19:29 +0000555 if (m_opaque_sp.get() && line != 0)
Greg Claytonbdcda462010-12-20 20:49:23 +0000556 {
557 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
Greg Clayton63094e02010-06-23 01:19:29 +0000558 *sb_bp = m_opaque_sp->CreateBreakpoint (NULL, *sb_file_spec, line, true, false);
Greg Claytonbdcda462010-12-20 20:49:23 +0000559 }
Caroline Tice7826c882010-10-26 03:11:13 +0000560
561 if (log)
562 {
563 SBStream sstr;
564 sb_bp.GetDescription (sstr);
Greg Clayton49ce6822010-10-31 03:01:06 +0000565 char path[PATH_MAX];
566 sb_file_spec->GetPath (path, sizeof(path));
567 log->Printf ("SBTarget(%p)::BreakpointCreateByLocation ( %s:%u ) => SBBreakpoint(%p): %s",
Greg Claytona66ba462010-10-30 04:51:46 +0000568 m_opaque_sp.get(),
Greg Clayton49ce6822010-10-31 03:01:06 +0000569 path,
Greg Claytona66ba462010-10-30 04:51:46 +0000570 line,
Greg Clayton49ce6822010-10-31 03:01:06 +0000571 sb_bp.get(),
Caroline Tice7826c882010-10-26 03:11:13 +0000572 sstr.GetData());
573 }
574
Chris Lattner24943d22010-06-08 16:52:24 +0000575 return sb_bp;
576}
577
578SBBreakpoint
579SBTarget::BreakpointCreateByName (const char *symbol_name, const char *module_name)
580{
Greg Claytone005f2c2010-11-06 01:53:30 +0000581 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000582
Chris Lattner24943d22010-06-08 16:52:24 +0000583 SBBreakpoint sb_bp;
Jim Inghamd6d47972011-09-23 00:54:11 +0000584 if (m_opaque_sp.get())
Chris Lattner24943d22010-06-08 16:52:24 +0000585 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000586 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
Chris Lattner24943d22010-06-08 16:52:24 +0000587 if (module_name && module_name[0])
588 {
Jim Ingham03c8ee52011-09-21 01:17:13 +0000589 FileSpecList module_spec_list;
590 module_spec_list.Append (FileSpec (module_name, false));
Jim Ingham8b7b2272011-10-07 22:23:45 +0000591 *sb_bp = m_opaque_sp->CreateBreakpoint (&module_spec_list, NULL, symbol_name, eFunctionNameTypeAuto, false);
Chris Lattner24943d22010-06-08 16:52:24 +0000592 }
593 else
594 {
Jim Ingham8b7b2272011-10-07 22:23:45 +0000595 *sb_bp = m_opaque_sp->CreateBreakpoint (NULL, NULL, symbol_name, eFunctionNameTypeAuto, false);
Chris Lattner24943d22010-06-08 16:52:24 +0000596 }
597 }
Caroline Tice7826c882010-10-26 03:11:13 +0000598
599 if (log)
600 {
Greg Clayton49ce6822010-10-31 03:01:06 +0000601 log->Printf ("SBTarget(%p)::BreakpointCreateByName (symbol=\"%s\", module=\"%s\") => SBBreakpoint(%p)",
602 m_opaque_sp.get(), symbol_name, module_name, sb_bp.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000603 }
604
Chris Lattner24943d22010-06-08 16:52:24 +0000605 return sb_bp;
606}
607
Jim Inghamd6d47972011-09-23 00:54:11 +0000608lldb::SBBreakpoint
609SBTarget::BreakpointCreateByName (const char *symbol_name,
610 const SBFileSpecList &module_list,
611 const SBFileSpecList &comp_unit_list)
612{
Jim Ingham1fb8a2d2011-10-11 01:18:55 +0000613 uint32_t name_type_mask = eFunctionNameTypeAuto;
614 return BreakpointCreateByName (symbol_name, name_type_mask, module_list, comp_unit_list);
615}
616
617lldb::SBBreakpoint
618SBTarget::BreakpointCreateByName (const char *symbol_name,
619 uint32_t name_type_mask,
620 const SBFileSpecList &module_list,
621 const SBFileSpecList &comp_unit_list)
622{
Jim Inghamd6d47972011-09-23 00:54:11 +0000623 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
624
625 SBBreakpoint sb_bp;
626 if (m_opaque_sp.get() && symbol_name && symbol_name[0])
627 {
628 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
629 *sb_bp = m_opaque_sp->CreateBreakpoint (module_list.get(),
630 comp_unit_list.get(),
631 symbol_name,
Jim Ingham1fb8a2d2011-10-11 01:18:55 +0000632 name_type_mask,
Jim Inghamd6d47972011-09-23 00:54:11 +0000633 false);
634 }
635
636 if (log)
637 {
Jim Ingham1fb8a2d2011-10-11 01:18:55 +0000638 log->Printf ("SBTarget(%p)::BreakpointCreateByName (symbol=\"%s\", name_type: %d) => SBBreakpoint(%p)",
639 m_opaque_sp.get(), symbol_name, name_type_mask, sb_bp.get());
Jim Inghamd6d47972011-09-23 00:54:11 +0000640 }
641
642 return sb_bp;
643}
644
645
Chris Lattner24943d22010-06-08 16:52:24 +0000646SBBreakpoint
647SBTarget::BreakpointCreateByRegex (const char *symbol_name_regex, const char *module_name)
648{
Greg Claytone005f2c2010-11-06 01:53:30 +0000649 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000650
Chris Lattner24943d22010-06-08 16:52:24 +0000651 SBBreakpoint sb_bp;
Greg Clayton63094e02010-06-23 01:19:29 +0000652 if (m_opaque_sp.get() && symbol_name_regex && symbol_name_regex[0])
Chris Lattner24943d22010-06-08 16:52:24 +0000653 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000654 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
Chris Lattner24943d22010-06-08 16:52:24 +0000655 RegularExpression regexp(symbol_name_regex);
656
657 if (module_name && module_name[0])
658 {
Jim Ingham03c8ee52011-09-21 01:17:13 +0000659 FileSpecList module_spec_list;
660 module_spec_list.Append (FileSpec (module_name, false));
Chris Lattner24943d22010-06-08 16:52:24 +0000661
Jim Inghamd6d47972011-09-23 00:54:11 +0000662 *sb_bp = m_opaque_sp->CreateFuncRegexBreakpoint (&module_spec_list, NULL, regexp, false);
Chris Lattner24943d22010-06-08 16:52:24 +0000663 }
664 else
665 {
Jim Inghamd6d47972011-09-23 00:54:11 +0000666 *sb_bp = m_opaque_sp->CreateFuncRegexBreakpoint (NULL, NULL, regexp, false);
Chris Lattner24943d22010-06-08 16:52:24 +0000667 }
668 }
Caroline Tice7826c882010-10-26 03:11:13 +0000669
670 if (log)
671 {
Greg Clayton49ce6822010-10-31 03:01:06 +0000672 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (symbol_regex=\"%s\", module_name=\"%s\") => SBBreakpoint(%p)",
673 m_opaque_sp.get(), symbol_name_regex, module_name, sb_bp.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000674 }
675
Chris Lattner24943d22010-06-08 16:52:24 +0000676 return sb_bp;
677}
678
Jim Inghamd6d47972011-09-23 00:54:11 +0000679lldb::SBBreakpoint
680SBTarget::BreakpointCreateByRegex (const char *symbol_name_regex,
681 const SBFileSpecList &module_list,
682 const SBFileSpecList &comp_unit_list)
683{
684 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Chris Lattner24943d22010-06-08 16:52:24 +0000685
Jim Inghamd6d47972011-09-23 00:54:11 +0000686 SBBreakpoint sb_bp;
687 if (m_opaque_sp.get() && symbol_name_regex && symbol_name_regex[0])
688 {
689 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
690 RegularExpression regexp(symbol_name_regex);
691
692 *sb_bp = m_opaque_sp->CreateFuncRegexBreakpoint (module_list.get(), comp_unit_list.get(), regexp, false);
693 }
694
695 if (log)
696 {
697 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (symbol_regex=\"%s\") => SBBreakpoint(%p)",
698 m_opaque_sp.get(), symbol_name_regex, sb_bp.get());
699 }
700
701 return sb_bp;
702}
Chris Lattner24943d22010-06-08 16:52:24 +0000703
704SBBreakpoint
705SBTarget::BreakpointCreateByAddress (addr_t address)
706{
Greg Claytone005f2c2010-11-06 01:53:30 +0000707 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000708
Chris Lattner24943d22010-06-08 16:52:24 +0000709 SBBreakpoint sb_bp;
Greg Clayton63094e02010-06-23 01:19:29 +0000710 if (m_opaque_sp.get())
Greg Claytonbdcda462010-12-20 20:49:23 +0000711 {
712 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
Greg Clayton63094e02010-06-23 01:19:29 +0000713 *sb_bp = m_opaque_sp->CreateBreakpoint (address, false);
Greg Claytonbdcda462010-12-20 20:49:23 +0000714 }
Caroline Tice7826c882010-10-26 03:11:13 +0000715
716 if (log)
717 {
Jason Molenda7e5fa7f2011-09-20 21:44:10 +0000718 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 +0000719 }
720
Chris Lattner24943d22010-06-08 16:52:24 +0000721 return sb_bp;
722}
723
Jim Ingham03c8ee52011-09-21 01:17:13 +0000724lldb::SBBreakpoint
725SBTarget::BreakpointCreateBySourceRegex (const char *source_regex, const lldb::SBFileSpec &source_file, const char *module_name)
726{
727 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
728
729 SBBreakpoint sb_bp;
730 if (m_opaque_sp.get() && source_regex && source_regex[0])
731 {
732 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
733 RegularExpression regexp(source_regex);
Jim Inghamd6d47972011-09-23 00:54:11 +0000734 FileSpecList source_file_spec_list;
735 source_file_spec_list.Append (source_file.ref());
Jim Ingham03c8ee52011-09-21 01:17:13 +0000736
737 if (module_name && module_name[0])
738 {
739 FileSpecList module_spec_list;
740 module_spec_list.Append (FileSpec (module_name, false));
741
Jim Inghamd6d47972011-09-23 00:54:11 +0000742 *sb_bp = m_opaque_sp->CreateSourceRegexBreakpoint (&module_spec_list, &source_file_spec_list, regexp, false);
Jim Ingham03c8ee52011-09-21 01:17:13 +0000743 }
744 else
745 {
Jim Inghamd6d47972011-09-23 00:54:11 +0000746 *sb_bp = m_opaque_sp->CreateSourceRegexBreakpoint (NULL, &source_file_spec_list, regexp, false);
Jim Ingham03c8ee52011-09-21 01:17:13 +0000747 }
748 }
749
750 if (log)
751 {
752 char path[PATH_MAX];
753 source_file->GetPath (path, sizeof(path));
754 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (source_regex=\"%s\", file=\"%s\", module_name=\"%s\") => SBBreakpoint(%p)",
Greg Claytona253c932011-09-21 06:45:51 +0000755 m_opaque_sp.get(), source_regex, path, module_name, sb_bp.get());
Jim Ingham03c8ee52011-09-21 01:17:13 +0000756 }
757
758 return sb_bp;
759}
760
Jim Inghamd6d47972011-09-23 00:54:11 +0000761lldb::SBBreakpoint
762SBTarget::BreakpointCreateBySourceRegex (const char *source_regex,
763 const SBFileSpecList &module_list,
764 const lldb::SBFileSpecList &source_file_list)
765{
766 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
767
768 SBBreakpoint sb_bp;
769 if (m_opaque_sp.get() && source_regex && source_regex[0])
770 {
771 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
772 RegularExpression regexp(source_regex);
773 *sb_bp = m_opaque_sp->CreateSourceRegexBreakpoint (module_list.get(), source_file_list.get(), regexp, false);
774 }
775
776 if (log)
777 {
778 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (source_regex=\"%s\") => SBBreakpoint(%p)",
779 m_opaque_sp.get(), source_regex, sb_bp.get());
780 }
781
782 return sb_bp;
783}
Jim Ingham03c8ee52011-09-21 01:17:13 +0000784
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000785uint32_t
786SBTarget::GetNumBreakpoints () const
787{
788 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000789 {
790 // The breakpoint list is thread safe, no need to lock
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000791 return m_opaque_sp->GetBreakpointList().GetSize();
Greg Claytonbdcda462010-12-20 20:49:23 +0000792 }
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000793 return 0;
794}
795
796SBBreakpoint
797SBTarget::GetBreakpointAtIndex (uint32_t idx) const
798{
799 SBBreakpoint sb_breakpoint;
800 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000801 {
802 // The breakpoint list is thread safe, no need to lock
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000803 *sb_breakpoint = m_opaque_sp->GetBreakpointList().GetBreakpointAtIndex(idx);
Greg Claytonbdcda462010-12-20 20:49:23 +0000804 }
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000805 return sb_breakpoint;
806}
Chris Lattner24943d22010-06-08 16:52:24 +0000807
808bool
809SBTarget::BreakpointDelete (break_id_t bp_id)
810{
Greg Claytone005f2c2010-11-06 01:53:30 +0000811 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000812
Caroline Tice7826c882010-10-26 03:11:13 +0000813 bool result = false;
Greg Clayton63094e02010-06-23 01:19:29 +0000814 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000815 {
816 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
Caroline Tice7826c882010-10-26 03:11:13 +0000817 result = m_opaque_sp->RemoveBreakpointByID (bp_id);
Greg Claytonbdcda462010-12-20 20:49:23 +0000818 }
Caroline Tice7826c882010-10-26 03:11:13 +0000819
820 if (log)
821 {
Greg Clayton3f5ee7f2010-10-29 04:59:35 +0000822 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 +0000823 }
824
825 return result;
Chris Lattner24943d22010-06-08 16:52:24 +0000826}
827
Johnny Chen096c2932011-09-26 22:40:50 +0000828SBBreakpoint
829SBTarget::FindBreakpointByID (break_id_t bp_id)
830{
831 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
832
833 SBBreakpoint sb_breakpoint;
834 if (m_opaque_sp && bp_id != LLDB_INVALID_BREAK_ID)
835 {
836 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
837 *sb_breakpoint = m_opaque_sp->GetBreakpointByID (bp_id);
838 }
839
840 if (log)
841 {
842 log->Printf ("SBTarget(%p)::FindBreakpointByID (bp_id=%d) => SBBreakpoint(%p)",
843 m_opaque_sp.get(), (uint32_t) bp_id, sb_breakpoint.get());
844 }
845
846 return sb_breakpoint;
847}
848
Chris Lattner24943d22010-06-08 16:52:24 +0000849bool
850SBTarget::EnableAllBreakpoints ()
851{
Greg Clayton63094e02010-06-23 01:19:29 +0000852 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000853 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000854 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
Greg Clayton63094e02010-06-23 01:19:29 +0000855 m_opaque_sp->EnableAllBreakpoints ();
Chris Lattner24943d22010-06-08 16:52:24 +0000856 return true;
857 }
858 return false;
859}
860
861bool
862SBTarget::DisableAllBreakpoints ()
863{
Greg Clayton63094e02010-06-23 01:19:29 +0000864 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000865 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000866 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
Greg Clayton63094e02010-06-23 01:19:29 +0000867 m_opaque_sp->DisableAllBreakpoints ();
Chris Lattner24943d22010-06-08 16:52:24 +0000868 return true;
869 }
870 return false;
871}
872
873bool
874SBTarget::DeleteAllBreakpoints ()
875{
Greg Clayton63094e02010-06-23 01:19:29 +0000876 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000877 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000878 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
Greg Clayton63094e02010-06-23 01:19:29 +0000879 m_opaque_sp->RemoveAllBreakpoints ();
Chris Lattner24943d22010-06-08 16:52:24 +0000880 return true;
881 }
882 return false;
883}
884
Johnny Chen096c2932011-09-26 22:40:50 +0000885uint32_t
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000886SBTarget::GetNumWatchpoints () const
Johnny Chen096c2932011-09-26 22:40:50 +0000887{
888 if (m_opaque_sp)
889 {
Johnny Chenecd4feb2011-10-14 00:42:25 +0000890 // The watchpoint list is thread safe, no need to lock
891 return m_opaque_sp->GetWatchpointList().GetSize();
Johnny Chen096c2932011-09-26 22:40:50 +0000892 }
893 return 0;
894}
895
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000896SBWatchpoint
897SBTarget::GetWatchpointAtIndex (uint32_t idx) const
Johnny Chen5eb54bb2011-09-27 20:29:45 +0000898{
Johnny Chenecd4feb2011-10-14 00:42:25 +0000899 SBWatchpoint sb_watchpoint;
Johnny Chen096c2932011-09-26 22:40:50 +0000900 if (m_opaque_sp)
901 {
Johnny Chenecd4feb2011-10-14 00:42:25 +0000902 // The watchpoint list is thread safe, no need to lock
903 *sb_watchpoint = m_opaque_sp->GetWatchpointList().GetByIndex(idx);
Johnny Chen096c2932011-09-26 22:40:50 +0000904 }
Johnny Chenecd4feb2011-10-14 00:42:25 +0000905 return sb_watchpoint;
Johnny Chen096c2932011-09-26 22:40:50 +0000906}
907
908bool
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000909SBTarget::DeleteWatchpoint (watch_id_t wp_id)
Johnny Chen096c2932011-09-26 22:40:50 +0000910{
911 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
912
913 bool result = false;
914 if (m_opaque_sp)
915 {
916 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
Johnny Chenecd4feb2011-10-14 00:42:25 +0000917 result = m_opaque_sp->RemoveWatchpointByID (wp_id);
Johnny Chen096c2932011-09-26 22:40:50 +0000918 }
919
920 if (log)
921 {
Johnny Chenecd4feb2011-10-14 00:42:25 +0000922 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 +0000923 }
924
925 return result;
926}
927
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000928SBWatchpoint
929SBTarget::FindWatchpointByID (lldb::watch_id_t wp_id)
Johnny Chen096c2932011-09-26 22:40:50 +0000930{
931 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
932
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000933 SBWatchpoint sb_watchpoint;
Johnny Chen096c2932011-09-26 22:40:50 +0000934 if (m_opaque_sp && wp_id != LLDB_INVALID_WATCH_ID)
935 {
936 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
Johnny Chenecd4feb2011-10-14 00:42:25 +0000937 *sb_watchpoint = m_opaque_sp->GetWatchpointList().FindByID(wp_id);
Johnny Chen096c2932011-09-26 22:40:50 +0000938 }
939
940 if (log)
941 {
Johnny Chenecd4feb2011-10-14 00:42:25 +0000942 log->Printf ("SBTarget(%p)::FindWatchpointByID (bp_id=%d) => SBWatchpoint(%p)",
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000943 m_opaque_sp.get(), (uint32_t) wp_id, sb_watchpoint.get());
Johnny Chen096c2932011-09-26 22:40:50 +0000944 }
945
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000946 return sb_watchpoint;
947}
948
949lldb::SBWatchpoint
950SBTarget::WatchAddress (lldb::addr_t addr, size_t size, bool read, bool write)
951{
952 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
953
954 SBWatchpoint sb_watchpoint;
955 if (m_opaque_sp)
956 {
957 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
Johnny Chenecd4feb2011-10-14 00:42:25 +0000958 uint32_t watch_type = (read ? LLDB_WATCH_TYPE_READ : 0) |
959 (write ? LLDB_WATCH_TYPE_WRITE : 0);
Johnny Chen50e05342011-10-14 01:16:39 +0000960 sb_watchpoint = m_opaque_sp->CreateWatchpoint(addr, size, watch_type);
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000961 }
962
963 if (log)
964 {
965 log->Printf ("SBTarget(%p)::WatchAddress (addr=0x%llx, 0x%u) => SBWatchpoint(%p)",
966 m_opaque_sp.get(), addr, (uint32_t) size, sb_watchpoint.get());
967 }
968
969 return sb_watchpoint;
Johnny Chen096c2932011-09-26 22:40:50 +0000970}
971
972bool
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000973SBTarget::EnableAllWatchpoints ()
Johnny Chen096c2932011-09-26 22:40:50 +0000974{
975 if (m_opaque_sp)
976 {
977 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
Johnny Chenecd4feb2011-10-14 00:42:25 +0000978 m_opaque_sp->EnableAllWatchpoints ();
Johnny Chen096c2932011-09-26 22:40:50 +0000979 return true;
980 }
981 return false;
982}
983
984bool
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000985SBTarget::DisableAllWatchpoints ()
Johnny Chen096c2932011-09-26 22:40:50 +0000986{
987 if (m_opaque_sp)
988 {
989 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
Johnny Chenecd4feb2011-10-14 00:42:25 +0000990 m_opaque_sp->DisableAllWatchpoints ();
Johnny Chen096c2932011-09-26 22:40:50 +0000991 return true;
992 }
993 return false;
994}
995
996bool
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000997SBTarget::DeleteAllWatchpoints ()
Johnny Chen096c2932011-09-26 22:40:50 +0000998{
999 if (m_opaque_sp)
1000 {
1001 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
Johnny Chenecd4feb2011-10-14 00:42:25 +00001002 m_opaque_sp->RemoveAllWatchpoints ();
Johnny Chen096c2932011-09-26 22:40:50 +00001003 return true;
1004 }
1005 return false;
1006}
1007
Chris Lattner24943d22010-06-08 16:52:24 +00001008
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001009lldb::SBModule
1010SBTarget::AddModule (const char *path,
1011 const char *triple,
1012 const char *uuid_cstr)
1013{
1014 lldb::SBModule sb_module;
1015 if (m_opaque_sp)
1016 {
1017 FileSpec module_file_spec;
1018 UUID module_uuid;
1019 ArchSpec module_arch;
1020
1021 if (path)
1022 module_file_spec.SetFile(path, false);
1023
1024 if (uuid_cstr)
1025 module_uuid.SetfromCString(uuid_cstr);
1026
1027 if (triple)
1028 module_arch.SetTriple (triple, m_opaque_sp->GetPlatform ().get());
1029
1030 sb_module.SetModule(m_opaque_sp->GetSharedModule (module_file_spec,
1031 module_arch,
1032 uuid_cstr ? &module_uuid : NULL));
1033 }
1034 return sb_module;
1035}
1036
1037bool
1038SBTarget::AddModule (lldb::SBModule &module)
1039{
1040 if (m_opaque_sp)
1041 {
1042 m_opaque_sp->GetImages().AppendIfNeeded (module.get_sp());
1043 return true;
1044 }
1045 return false;
1046}
1047
1048lldb::SBModule
1049AddModule (const char *path,
1050 const char *triple,
1051 const char *uuid);
1052
1053
1054
Chris Lattner24943d22010-06-08 16:52:24 +00001055uint32_t
1056SBTarget::GetNumModules () const
1057{
Greg Claytone005f2c2010-11-06 01:53:30 +00001058 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001059
Caroline Tice7826c882010-10-26 03:11:13 +00001060 uint32_t num = 0;
Greg Clayton63094e02010-06-23 01:19:29 +00001061 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +00001062 {
1063 // The module list is thread safe, no need to lock
1064 num = m_opaque_sp->GetImages().GetSize();
1065 }
Caroline Tice7826c882010-10-26 03:11:13 +00001066
1067 if (log)
Greg Clayton3f5ee7f2010-10-29 04:59:35 +00001068 log->Printf ("SBTarget(%p)::GetNumModules () => %d", m_opaque_sp.get(), num);
Caroline Tice7826c882010-10-26 03:11:13 +00001069
1070 return num;
Chris Lattner24943d22010-06-08 16:52:24 +00001071}
1072
Greg Clayton43490d12010-07-30 20:12:55 +00001073void
1074SBTarget::Clear ()
1075{
Greg Claytone005f2c2010-11-06 01:53:30 +00001076 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001077
1078 if (log)
Greg Clayton3f5ee7f2010-10-29 04:59:35 +00001079 log->Printf ("SBTarget(%p)::Clear ()", m_opaque_sp.get());
Caroline Tice7826c882010-10-26 03:11:13 +00001080
Greg Clayton43490d12010-07-30 20:12:55 +00001081 m_opaque_sp.reset();
1082}
1083
1084
Chris Lattner24943d22010-06-08 16:52:24 +00001085SBModule
1086SBTarget::FindModule (const SBFileSpec &sb_file_spec)
1087{
1088 SBModule sb_module;
Greg Clayton63094e02010-06-23 01:19:29 +00001089 if (m_opaque_sp && sb_file_spec.IsValid())
Greg Claytonbdcda462010-12-20 20:49:23 +00001090 {
1091 // The module list is thread safe, no need to lock
Greg Clayton24bc5d92011-03-30 18:16:51 +00001092 sb_module.SetModule (m_opaque_sp->GetImages().FindFirstModuleForFileSpec (*sb_file_spec, NULL, NULL));
Greg Claytonbdcda462010-12-20 20:49:23 +00001093 }
Chris Lattner24943d22010-06-08 16:52:24 +00001094 return sb_module;
1095}
1096
1097SBModule
1098SBTarget::GetModuleAtIndex (uint32_t idx)
1099{
Greg Claytone005f2c2010-11-06 01:53:30 +00001100 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001101
Chris Lattner24943d22010-06-08 16:52:24 +00001102 SBModule sb_module;
Greg Clayton63094e02010-06-23 01:19:29 +00001103 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +00001104 {
1105 // The module list is thread safe, no need to lock
Greg Clayton63094e02010-06-23 01:19:29 +00001106 sb_module.SetModule(m_opaque_sp->GetImages().GetModuleAtIndex(idx));
Greg Claytonbdcda462010-12-20 20:49:23 +00001107 }
Caroline Tice7826c882010-10-26 03:11:13 +00001108
1109 if (log)
1110 {
Greg Clayton49ce6822010-10-31 03:01:06 +00001111 log->Printf ("SBTarget(%p)::GetModuleAtIndex (idx=%d) => SBModule(%p)",
1112 m_opaque_sp.get(), idx, sb_module.get());
Caroline Tice7826c882010-10-26 03:11:13 +00001113 }
1114
Chris Lattner24943d22010-06-08 16:52:24 +00001115 return sb_module;
1116}
1117
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001118bool
1119SBTarget::RemoveModule (lldb::SBModule module)
1120{
1121 if (m_opaque_sp)
1122 return m_opaque_sp->GetImages().Remove(module.get_sp());
1123 return false;
1124}
1125
Chris Lattner24943d22010-06-08 16:52:24 +00001126
1127SBBroadcaster
1128SBTarget::GetBroadcaster () const
1129{
Greg Claytone005f2c2010-11-06 01:53:30 +00001130 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001131
Greg Clayton63094e02010-06-23 01:19:29 +00001132 SBBroadcaster broadcaster(m_opaque_sp.get(), false);
Caroline Tice7826c882010-10-26 03:11:13 +00001133
1134 if (log)
Greg Clayton3f5ee7f2010-10-29 04:59:35 +00001135 log->Printf ("SBTarget(%p)::GetBroadcaster () => SBBroadcaster(%p)",
Caroline Tice61ba7ec2010-10-26 23:49:36 +00001136 m_opaque_sp.get(), broadcaster.get());
Caroline Tice7826c882010-10-26 03:11:13 +00001137
Chris Lattner24943d22010-06-08 16:52:24 +00001138 return broadcaster;
1139}
1140
Caroline Tice98f930f2010-09-20 05:20:02 +00001141
1142bool
Caroline Tice7826c882010-10-26 03:11:13 +00001143SBTarget::GetDescription (SBStream &description, lldb::DescriptionLevel description_level)
Caroline Tice98f930f2010-09-20 05:20:02 +00001144{
1145 if (m_opaque_sp)
Caroline Ticee7a566e2010-09-20 16:21:41 +00001146 {
Caroline Ticee49ec182010-09-22 23:01:29 +00001147 description.ref();
Caroline Tice7826c882010-10-26 03:11:13 +00001148 m_opaque_sp->Dump (description.get(), description_level);
1149 }
1150 else
1151 description.Printf ("No value");
1152
1153 return true;
1154}
1155
1156bool
1157SBTarget::GetDescription (SBStream &description, lldb::DescriptionLevel description_level) const
1158{
1159 if (m_opaque_sp)
1160 {
1161 description.ref();
1162 m_opaque_sp->Dump (description.get(), description_level);
Caroline Ticee7a566e2010-09-20 16:21:41 +00001163 }
Caroline Tice98f930f2010-09-20 05:20:02 +00001164 else
1165 description.Printf ("No value");
1166
1167 return true;
1168}
Greg Clayton4ed315f2011-06-21 01:34:41 +00001169
1170
1171uint32_t
1172SBTarget::FindFunctions (const char *name,
1173 uint32_t name_type_mask,
1174 bool append,
1175 lldb::SBSymbolContextList& sc_list)
1176{
1177 if (!append)
1178 sc_list.Clear();
1179 if (m_opaque_sp)
1180 {
1181 const bool symbols_ok = true;
1182 return m_opaque_sp->GetImages().FindFunctions (ConstString(name),
1183 name_type_mask,
1184 symbols_ok,
1185 append,
1186 *sc_list);
1187 }
1188 return 0;
1189}
1190
Enrico Granata979e20d2011-07-29 19:53:35 +00001191lldb::SBType
1192SBTarget::FindFirstType (const char* type)
1193{
1194 if (m_opaque_sp)
1195 {
1196 size_t count = m_opaque_sp->GetImages().GetSize();
1197 for (size_t idx = 0; idx < count; idx++)
1198 {
1199 SBType found_at_idx = GetModuleAtIndex(idx).FindFirstType(type);
1200
1201 if (found_at_idx.IsValid())
1202 return found_at_idx;
1203 }
1204 }
1205 return SBType();
1206}
1207
1208lldb::SBTypeList
1209SBTarget::FindTypes (const char* type)
1210{
1211
1212 SBTypeList retval;
1213
1214 if (m_opaque_sp)
1215 {
1216 ModuleList& images = m_opaque_sp->GetImages();
1217 ConstString name_const(type);
1218 SymbolContext sc;
1219 TypeList type_list;
1220
1221 uint32_t num_matches = images.FindTypes(sc,
1222 name_const,
1223 true,
1224 UINT32_MAX,
1225 type_list);
1226
1227 for (size_t idx = 0; idx < num_matches; idx++)
1228 {
Greg Clayton0fb0bcc2011-08-03 22:57:10 +00001229 TypeSP type_sp (type_list.GetTypeAtIndex(idx));
1230 if (type_sp)
1231 retval.Append(SBType(type_sp));
Enrico Granata979e20d2011-07-29 19:53:35 +00001232 }
1233 }
1234 return retval;
1235}
1236
Greg Clayton917c0002011-06-29 22:09:02 +00001237SBValueList
1238SBTarget::FindGlobalVariables (const char *name, uint32_t max_matches)
1239{
1240 SBValueList sb_value_list;
1241
1242 if (m_opaque_sp)
1243 {
1244 VariableList variable_list;
1245 const bool append = true;
1246 const uint32_t match_count = m_opaque_sp->GetImages().FindGlobalVariables (ConstString (name),
1247 append,
1248 max_matches,
1249 variable_list);
1250
1251 if (match_count > 0)
1252 {
1253 ExecutionContextScope *exe_scope = m_opaque_sp->GetProcessSP().get();
1254 if (exe_scope == NULL)
1255 exe_scope = m_opaque_sp.get();
1256 ValueObjectList &value_object_list = sb_value_list.ref();
1257 for (uint32_t i=0; i<match_count; ++i)
1258 {
1259 lldb::ValueObjectSP valobj_sp (ValueObjectVariable::Create (exe_scope, variable_list.GetVariableAtIndex(i)));
1260 if (valobj_sp)
1261 value_object_list.Append(valobj_sp);
1262 }
1263 }
1264 }
1265
1266 return sb_value_list;
1267}
1268
Jim Inghamcc637462011-09-13 00:29:56 +00001269SBSourceManager
1270SBTarget::GetSourceManager()
1271{
1272 SBSourceManager source_manager (*this);
1273 return source_manager;
1274}
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001275
1276
1277SBError
1278SBTarget::SetSectionLoadAddress (lldb::SBSection section,
1279 lldb::addr_t section_base_addr)
1280{
1281 SBError sb_error;
1282
1283 if (IsValid())
1284 {
1285 if (!section.IsValid())
1286 {
1287 sb_error.SetErrorStringWithFormat ("invalid section");
1288 }
1289 else
1290 {
1291 m_opaque_sp->GetSectionLoadList().SetSectionLoadAddress (section.GetSection(), section_base_addr);
1292 }
1293 }
1294 else
1295 {
1296 sb_error.SetErrorStringWithFormat ("invalid target");
1297 }
1298 return sb_error;
1299}
1300
1301SBError
1302SBTarget::ClearSectionLoadAddress (lldb::SBSection section)
1303{
1304 SBError sb_error;
1305
1306 if (IsValid())
1307 {
1308 if (!section.IsValid())
1309 {
1310 sb_error.SetErrorStringWithFormat ("invalid section");
1311 }
1312 else
1313 {
1314 m_opaque_sp->GetSectionLoadList().SetSectionUnloaded (section.GetSection());
1315 }
1316 }
1317 else
1318 {
1319 sb_error.SetErrorStringWithFormat ("invalid target");
1320 }
1321 return sb_error;
1322}
1323
1324SBError
1325SBTarget::SetModuleLoadAddress (lldb::SBModule module, int64_t slide_offset)
1326{
1327 SBError sb_error;
1328
1329 char path[PATH_MAX];
1330 if (IsValid())
1331 {
1332 if (!module.IsValid())
1333 {
1334 sb_error.SetErrorStringWithFormat ("invalid module");
1335 }
1336 else
1337 {
1338 ObjectFile *objfile = module->GetObjectFile();
1339 if (objfile)
1340 {
1341 SectionList *section_list = objfile->GetSectionList();
1342 if (section_list)
1343 {
1344 const size_t num_sections = section_list->GetSize();
1345 for (size_t sect_idx = 0; sect_idx < num_sections; ++sect_idx)
1346 {
1347 SectionSP section_sp (section_list->GetSectionAtIndex(sect_idx));
1348 if (section_sp)
1349 m_opaque_sp->GetSectionLoadList().SetSectionLoadAddress (section_sp.get(), section_sp->GetFileAddress() + slide_offset);
1350 }
1351 }
1352 else
1353 {
1354 module->GetFileSpec().GetPath (path, sizeof(path));
1355 sb_error.SetErrorStringWithFormat ("no sections in object file '%s'", path);
1356 }
1357 }
1358 else
1359 {
1360 module->GetFileSpec().GetPath (path, sizeof(path));
1361 sb_error.SetErrorStringWithFormat ("no object file for module '%s'", path);
1362 }
1363 }
1364 }
1365 else
1366 {
1367 sb_error.SetErrorStringWithFormat ("invalid target");
1368 }
1369 return sb_error;
1370}
1371
1372SBError
1373SBTarget::ClearModuleLoadAddress (lldb::SBModule module)
1374{
1375 SBError sb_error;
1376
1377 char path[PATH_MAX];
1378 if (IsValid())
1379 {
1380 if (!module.IsValid())
1381 {
1382 sb_error.SetErrorStringWithFormat ("invalid module");
1383 }
1384 else
1385 {
1386 ObjectFile *objfile = module->GetObjectFile();
1387 if (objfile)
1388 {
1389 SectionList *section_list = objfile->GetSectionList();
1390 if (section_list)
1391 {
1392 const size_t num_sections = section_list->GetSize();
1393 for (size_t sect_idx = 0; sect_idx < num_sections; ++sect_idx)
1394 {
1395 SectionSP section_sp (section_list->GetSectionAtIndex(sect_idx));
1396 if (section_sp)
1397 m_opaque_sp->GetSectionLoadList().SetSectionUnloaded (section_sp.get());
1398 }
1399 }
1400 else
1401 {
1402 module->GetFileSpec().GetPath (path, sizeof(path));
1403 sb_error.SetErrorStringWithFormat ("no sections in object file '%s'", path);
1404 }
1405 }
1406 else
1407 {
1408 module->GetFileSpec().GetPath (path, sizeof(path));
1409 sb_error.SetErrorStringWithFormat ("no object file for module '%s'", path);
1410 }
1411 }
1412 }
1413 else
1414 {
1415 sb_error.SetErrorStringWithFormat ("invalid target");
1416 }
1417 return sb_error;
1418}
1419
1420