blob: b922d2ae4f2cd2749be44e3d7c013b0aaaa8118b [file] [log] [blame]
Chris Lattner24943d22010-06-08 16:52:24 +00001//===-- SBTarget.cpp --------------------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
Eli Friedman7a62c8b2010-06-09 07:44:37 +000010#include "lldb/API/SBTarget.h"
Chris Lattner24943d22010-06-08 16:52:24 +000011
Greg Claytonb3448432011-03-24 21:19:54 +000012#include "lldb/lldb-public.h"
Chris Lattner24943d22010-06-08 16:52:24 +000013
Greg Clayton917c0002011-06-29 22:09:02 +000014#include "lldb/API/SBDebugger.h"
15#include "lldb/API/SBBreakpoint.h"
Chris Lattner24943d22010-06-08 16:52:24 +000016#include "lldb/API/SBFileSpec.h"
Greg Clayton917c0002011-06-29 22:09:02 +000017#include "lldb/API/SBListener.h"
Chris Lattner24943d22010-06-08 16:52:24 +000018#include "lldb/API/SBModule.h"
Jim Inghamcc637462011-09-13 00:29:56 +000019#include "lldb/API/SBSourceManager.h"
Greg Clayton917c0002011-06-29 22:09:02 +000020#include "lldb/API/SBProcess.h"
Caroline Tice98f930f2010-09-20 05:20:02 +000021#include "lldb/API/SBStream.h"
Greg Clayton4ed315f2011-06-21 01:34:41 +000022#include "lldb/API/SBSymbolContextList.h"
Chris Lattner24943d22010-06-08 16:52:24 +000023#include "lldb/Breakpoint/BreakpointID.h"
24#include "lldb/Breakpoint/BreakpointIDList.h"
25#include "lldb/Breakpoint/BreakpointList.h"
26#include "lldb/Breakpoint/BreakpointLocation.h"
27#include "lldb/Core/Address.h"
28#include "lldb/Core/AddressResolver.h"
29#include "lldb/Core/AddressResolverName.h"
Chris Lattner24943d22010-06-08 16:52:24 +000030#include "lldb/Core/ArchSpec.h"
31#include "lldb/Core/Debugger.h"
32#include "lldb/Core/Disassembler.h"
Caroline Tice7826c882010-10-26 03:11:13 +000033#include "lldb/Core/Log.h"
Chris Lattner24943d22010-06-08 16:52:24 +000034#include "lldb/Core/RegularExpression.h"
35#include "lldb/Core/SearchFilter.h"
36#include "lldb/Core/STLUtils.h"
Greg Clayton917c0002011-06-29 22:09:02 +000037#include "lldb/Core/ValueObjectList.h"
38#include "lldb/Core/ValueObjectVariable.h"
39#include "lldb/Host/FileSpec.h"
Greg Claytoncd548032011-02-01 01:31:41 +000040#include "lldb/Host/Host.h"
Greg Clayton917c0002011-06-29 22:09:02 +000041#include "lldb/Interpreter/Args.h"
Enrico Granata979e20d2011-07-29 19:53:35 +000042#include "lldb/Symbol/SymbolVendor.h"
Greg Clayton917c0002011-06-29 22:09:02 +000043#include "lldb/Symbol/VariableList.h"
Chris Lattner24943d22010-06-08 16:52:24 +000044#include "lldb/Target/Process.h"
45#include "lldb/Target/Target.h"
46#include "lldb/Target/TargetList.h"
47
48#include "lldb/Interpreter/CommandReturnObject.h"
49#include "../source/Commands/CommandObjectBreakpoint.h"
50
Chris Lattner24943d22010-06-08 16:52:24 +000051
52using namespace lldb;
53using namespace lldb_private;
54
55#define DEFAULT_DISASM_BYTE_SIZE 32
56
57//----------------------------------------------------------------------
58// SBTarget constructor
59//----------------------------------------------------------------------
Greg Claytonc3b61d22010-12-15 05:08:08 +000060SBTarget::SBTarget () :
61 m_opaque_sp ()
Chris Lattner24943d22010-06-08 16:52:24 +000062{
63}
64
65SBTarget::SBTarget (const SBTarget& rhs) :
Greg Clayton63094e02010-06-23 01:19:29 +000066 m_opaque_sp (rhs.m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +000067{
68}
69
70SBTarget::SBTarget(const TargetSP& target_sp) :
Greg Clayton63094e02010-06-23 01:19:29 +000071 m_opaque_sp (target_sp)
Chris Lattner24943d22010-06-08 16:52:24 +000072{
73}
74
Greg Clayton538eb822010-11-05 23:17:00 +000075const SBTarget&
76SBTarget::operator = (const SBTarget& rhs)
77{
78 if (this != &rhs)
79 m_opaque_sp = rhs.m_opaque_sp;
80 return *this;
81}
82
Chris Lattner24943d22010-06-08 16:52:24 +000083//----------------------------------------------------------------------
84// Destructor
85//----------------------------------------------------------------------
86SBTarget::~SBTarget()
87{
88}
89
90bool
91SBTarget::IsValid () const
92{
Greg Clayton63094e02010-06-23 01:19:29 +000093 return m_opaque_sp.get() != NULL;
Chris Lattner24943d22010-06-08 16:52:24 +000094}
95
96SBProcess
97SBTarget::GetProcess ()
98{
Caroline Tice7826c882010-10-26 03:11:13 +000099
Chris Lattner24943d22010-06-08 16:52:24 +0000100 SBProcess sb_process;
Greg Clayton63094e02010-06-23 01:19:29 +0000101 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000102 {
103 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
Greg Clayton63094e02010-06-23 01:19:29 +0000104 sb_process.SetProcess (m_opaque_sp->GetProcessSP());
Greg Claytonbdcda462010-12-20 20:49:23 +0000105 }
Caroline Tice7826c882010-10-26 03:11:13 +0000106
Greg Claytone005f2c2010-11-06 01:53:30 +0000107 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000108 if (log)
109 {
Greg Clayton49ce6822010-10-31 03:01:06 +0000110 log->Printf ("SBTarget(%p)::GetProcess () => SBProcess(%p)",
111 m_opaque_sp.get(), sb_process.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000112 }
113
Chris Lattner24943d22010-06-08 16:52:24 +0000114 return sb_process;
115}
116
Greg Clayton63094e02010-06-23 01:19:29 +0000117SBDebugger
118SBTarget::GetDebugger () const
119{
120 SBDebugger debugger;
121 if (m_opaque_sp)
122 debugger.reset (m_opaque_sp->GetDebugger().GetSP());
123 return debugger;
124}
125
Jim Inghamb5871fe2011-03-31 00:01:24 +0000126SBProcess
127SBTarget::LaunchSimple
128(
129 char const **argv,
130 char const **envp,
131 const char *working_directory
132)
133{
134 char *stdin_path = NULL;
135 char *stdout_path = NULL;
136 char *stderr_path = NULL;
137 uint32_t launch_flags = 0;
138 bool stop_at_entry = false;
139 SBError error;
140 SBListener listener = GetDebugger().GetListener();
141 return Launch (listener,
142 argv,
143 envp,
144 stdin_path,
145 stdout_path,
146 stderr_path,
147 working_directory,
148 launch_flags,
149 stop_at_entry,
150 error);
151}
Greg Claytonde915be2011-01-23 05:56:20 +0000152
153SBProcess
154SBTarget::Launch
155(
Greg Clayton271a5db2011-02-03 21:28:34 +0000156 SBListener &listener,
Greg Claytonde915be2011-01-23 05:56:20 +0000157 char const **argv,
158 char const **envp,
159 const char *stdin_path,
160 const char *stdout_path,
161 const char *stderr_path,
162 const char *working_directory,
163 uint32_t launch_flags, // See LaunchFlags
164 bool stop_at_entry,
165 lldb::SBError& error
166)
167{
Greg Claytone005f2c2010-11-06 01:53:30 +0000168 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000169
170 if (log)
Greg Clayton3f5ee7f2010-10-29 04:59:35 +0000171 {
Greg Claytonde915be2011-01-23 05:56:20 +0000172 log->Printf ("SBTarget(%p)::Launch (argv=%p, envp=%p, stdin=%s, stdout=%s, stderr=%s, working-dir=%s, launch_flags=0x%x, stop_at_entry=%i, &error (%p))...",
173 m_opaque_sp.get(),
174 argv,
175 envp,
176 stdin_path ? stdin_path : "NULL",
177 stdout_path ? stdout_path : "NULL",
178 stderr_path ? stderr_path : "NULL",
179 working_directory ? working_directory : "NULL",
180 launch_flags,
181 stop_at_entry,
182 error.get());
Greg Clayton3f5ee7f2010-10-29 04:59:35 +0000183 }
Greg Clayton1a3083a2010-10-06 03:53:16 +0000184 SBProcess sb_process;
185 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000186 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000187 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
Greg Clayton1a3083a2010-10-06 03:53:16 +0000188
Greg Clayton7c330d62011-01-27 01:01:10 +0000189 if (getenv("LLDB_LAUNCH_FLAG_DISABLE_ASLR"))
190 launch_flags |= eLaunchFlagDisableASLR;
191
Greg Clayton180546b2011-04-30 01:09:13 +0000192 StateType state = eStateInvalid;
193 sb_process.SetProcess (m_opaque_sp->GetProcessSP());
194 if (sb_process.IsValid())
Greg Clayton28d5fcc2011-01-27 06:44:37 +0000195 {
Greg Clayton180546b2011-04-30 01:09:13 +0000196 state = sb_process->GetState();
197
198 if (sb_process->IsAlive() && state != eStateConnected)
199 {
200 if (state == eStateAttaching)
201 error.SetErrorString ("process attach is in progress");
202 else
203 error.SetErrorString ("a process is already being debugged");
204 sb_process.Clear();
205 return sb_process;
206 }
Greg Clayton28d5fcc2011-01-27 06:44:37 +0000207 }
208
Greg Clayton180546b2011-04-30 01:09:13 +0000209 if (state == eStateConnected)
210 {
211 // If we are already connected, then we have already specified the
212 // listener, so if a valid listener is supplied, we need to error out
213 // to let the client know.
214 if (listener.IsValid())
215 {
216 error.SetErrorString ("process is connected and already has a listener, pass empty listener");
217 sb_process.Clear();
218 return sb_process;
219 }
220 }
221 else
Greg Claytonc5f728c2010-10-06 22:10:17 +0000222 {
Greg Clayton271a5db2011-02-03 21:28:34 +0000223 if (listener.IsValid())
224 sb_process.SetProcess (m_opaque_sp->CreateProcess (listener.ref()));
225 else
226 sb_process.SetProcess (m_opaque_sp->CreateProcess (m_opaque_sp->GetDebugger().GetListener()));
Greg Clayton180546b2011-04-30 01:09:13 +0000227 }
Greg Clayton7c330d62011-01-27 01:01:10 +0000228
Greg Clayton180546b2011-04-30 01:09:13 +0000229 if (sb_process.IsValid())
230 {
231 if (getenv("LLDB_LAUNCH_FLAG_DISABLE_STDIO"))
232 launch_flags |= eLaunchFlagDisableSTDIO;
233
Greg Clayton36bc5ea2011-11-03 21:22:33 +0000234 ProcessLaunchInfo launch_info (stdin_path, stdout_path, stderr_path, working_directory, launch_flags);
235
236 Module *exe_module = m_opaque_sp->GetExecutableModulePointer();
237 if (exe_module)
Greg Clayton1d1f39e2011-11-29 04:03:30 +0000238 launch_info.SetExecutableFile(exe_module->GetPlatformFileSpec(), true);
Greg Clayton36bc5ea2011-11-03 21:22:33 +0000239 if (argv)
240 launch_info.GetArguments().AppendArguments (argv);
241 if (envp)
242 launch_info.GetEnvironmentEntries ().SetArguments (envp);
243
244 error.SetError (sb_process->Launch (launch_info));
Greg Clayton180546b2011-04-30 01:09:13 +0000245 if (error.Success())
Greg Clayton7c330d62011-01-27 01:01:10 +0000246 {
Greg Clayton180546b2011-04-30 01:09:13 +0000247 // We we are stopping at the entry point, we can return now!
248 if (stop_at_entry)
249 return sb_process;
Greg Clayton7c330d62011-01-27 01:01:10 +0000250
Greg Clayton180546b2011-04-30 01:09:13 +0000251 // Make sure we are stopped at the entry
252 StateType state = sb_process->WaitForProcessToStop (NULL);
253 if (state == eStateStopped)
Greg Clayton7c330d62011-01-27 01:01:10 +0000254 {
Greg Clayton180546b2011-04-30 01:09:13 +0000255 // resume the process to skip the entry point
256 error.SetError (sb_process->Resume());
257 if (error.Success())
Greg Clayton7c330d62011-01-27 01:01:10 +0000258 {
Greg Clayton180546b2011-04-30 01:09:13 +0000259 // If we are doing synchronous mode, then wait for the
260 // process to stop yet again!
261 if (m_opaque_sp->GetDebugger().GetAsyncExecution () == false)
262 sb_process->WaitForProcessToStop (NULL);
Greg Clayton7c330d62011-01-27 01:01:10 +0000263 }
264 }
265 }
Greg Clayton180546b2011-04-30 01:09:13 +0000266 }
267 else
268 {
269 error.SetErrorString ("unable to create lldb_private::Process");
Greg Claytonc5f728c2010-10-06 22:10:17 +0000270 }
271 }
272 else
273 {
274 error.SetErrorString ("SBTarget is invalid");
Chris Lattner24943d22010-06-08 16:52:24 +0000275 }
Caroline Tice7826c882010-10-26 03:11:13 +0000276
Caroline Tice926060e2010-10-29 21:48:37 +0000277 log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
Caroline Tice7826c882010-10-26 03:11:13 +0000278 if (log)
279 {
Greg Clayton49ce6822010-10-31 03:01:06 +0000280 log->Printf ("SBTarget(%p)::Launch (...) => SBProceess(%p)",
281 m_opaque_sp.get(), sb_process.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000282 }
283
Greg Clayton1a3083a2010-10-06 03:53:16 +0000284 return sb_process;
Chris Lattner24943d22010-06-08 16:52:24 +0000285}
286
Greg Claytond5b0b442011-12-02 02:10:57 +0000287#if defined(__APPLE__)
288
289lldb::SBProcess
290SBTarget::AttachToProcessWithID (SBListener &listener,
291 ::pid_t pid,
292 lldb::SBError& error)
293{
294 return AttachToProcessWithID (listener, (lldb::pid_t)pid, error);
295}
296
297#endif // #if defined(__APPLE__)
Greg Claytonc5f728c2010-10-06 22:10:17 +0000298
299lldb::SBProcess
Greg Claytond8c62532010-10-07 04:19:01 +0000300SBTarget::AttachToProcessWithID
Greg Claytonc5f728c2010-10-06 22:10:17 +0000301(
Greg Clayton271a5db2011-02-03 21:28:34 +0000302 SBListener &listener,
Greg Claytonc5f728c2010-10-06 22:10:17 +0000303 lldb::pid_t pid,// The process ID to attach to
304 SBError& error // An error explaining what went wrong if attach fails
305)
306{
307 SBProcess sb_process;
308 if (m_opaque_sp)
309 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000310 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
Greg Claytonde1dd812011-06-24 03:21:43 +0000311
312 StateType state = eStateInvalid;
313 sb_process.SetProcess (m_opaque_sp->GetProcessSP());
314 if (sb_process.IsValid())
315 {
316 state = sb_process->GetState();
317
318 if (sb_process->IsAlive() && state != eStateConnected)
319 {
320 if (state == eStateAttaching)
321 error.SetErrorString ("process attach is in progress");
322 else
323 error.SetErrorString ("a process is already being debugged");
324 sb_process.Clear();
325 return sb_process;
326 }
327 }
328
329 if (state == eStateConnected)
330 {
331 // If we are already connected, then we have already specified the
332 // listener, so if a valid listener is supplied, we need to error out
333 // to let the client know.
334 if (listener.IsValid())
335 {
336 error.SetErrorString ("process is connected and already has a listener, pass empty listener");
337 sb_process.Clear();
338 return sb_process;
339 }
340 }
Greg Clayton271a5db2011-02-03 21:28:34 +0000341 else
Greg Claytonde1dd812011-06-24 03:21:43 +0000342 {
343 if (listener.IsValid())
344 sb_process.SetProcess (m_opaque_sp->CreateProcess (listener.ref()));
345 else
346 sb_process.SetProcess (m_opaque_sp->CreateProcess (m_opaque_sp->GetDebugger().GetListener()));
347 }
Greg Claytonc5f728c2010-10-06 22:10:17 +0000348
349 if (sb_process.IsValid())
350 {
Greg Clayton527154d2011-11-15 03:53:30 +0000351 ProcessAttachInfo attach_info;
352 attach_info.SetProcessID (pid);
353 error.SetError (sb_process->Attach (attach_info));
Johnny Chen535960e2011-06-17 00:51:15 +0000354 // If we are doing synchronous mode, then wait for the
355 // process to stop!
356 if (m_opaque_sp->GetDebugger().GetAsyncExecution () == false)
357 sb_process->WaitForProcessToStop (NULL);
Greg Claytonc5f728c2010-10-06 22:10:17 +0000358 }
359 else
360 {
361 error.SetErrorString ("unable to create lldb_private::Process");
362 }
363 }
364 else
365 {
366 error.SetErrorString ("SBTarget is invalid");
367 }
368 return sb_process;
369
370}
371
372lldb::SBProcess
Greg Claytond8c62532010-10-07 04:19:01 +0000373SBTarget::AttachToProcessWithName
Greg Claytonc5f728c2010-10-06 22:10:17 +0000374(
Greg Clayton271a5db2011-02-03 21:28:34 +0000375 SBListener &listener,
Greg Claytonc5f728c2010-10-06 22:10:17 +0000376 const char *name, // basename of process to attach to
377 bool wait_for, // if true wait for a new instance of "name" to be launched
378 SBError& error // An error explaining what went wrong if attach fails
379)
380{
381 SBProcess sb_process;
382 if (m_opaque_sp)
383 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000384 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
385
Greg Claytonde1dd812011-06-24 03:21:43 +0000386 StateType state = eStateInvalid;
387 sb_process.SetProcess (m_opaque_sp->GetProcessSP());
388 if (sb_process.IsValid())
389 {
390 state = sb_process->GetState();
391
392 if (sb_process->IsAlive() && state != eStateConnected)
393 {
394 if (state == eStateAttaching)
395 error.SetErrorString ("process attach is in progress");
396 else
397 error.SetErrorString ("a process is already being debugged");
398 sb_process.Clear();
399 return sb_process;
400 }
401 }
402
403 if (state == eStateConnected)
404 {
405 // If we are already connected, then we have already specified the
406 // listener, so if a valid listener is supplied, we need to error out
407 // to let the client know.
408 if (listener.IsValid())
409 {
410 error.SetErrorString ("process is connected and already has a listener, pass empty listener");
411 sb_process.Clear();
412 return sb_process;
413 }
414 }
Greg Clayton271a5db2011-02-03 21:28:34 +0000415 else
Greg Claytonde1dd812011-06-24 03:21:43 +0000416 {
417 if (listener.IsValid())
418 sb_process.SetProcess (m_opaque_sp->CreateProcess (listener.ref()));
419 else
420 sb_process.SetProcess (m_opaque_sp->CreateProcess (m_opaque_sp->GetDebugger().GetListener()));
421 }
Greg Claytonc5f728c2010-10-06 22:10:17 +0000422
423 if (sb_process.IsValid())
424 {
Greg Clayton527154d2011-11-15 03:53:30 +0000425 ProcessAttachInfo attach_info;
426 attach_info.GetExecutableFile().SetFile(name, false);
427 attach_info.SetWaitForLaunch(wait_for);
428 error.SetError (sb_process->Attach (attach_info));
Johnny Chen58d02ff2011-06-17 19:21:30 +0000429 // If we are doing synchronous mode, then wait for the
430 // process to stop!
431 if (m_opaque_sp->GetDebugger().GetAsyncExecution () == false)
432 sb_process->WaitForProcessToStop (NULL);
Greg Claytonc5f728c2010-10-06 22:10:17 +0000433 }
434 else
435 {
436 error.SetErrorString ("unable to create lldb_private::Process");
437 }
438 }
439 else
440 {
441 error.SetErrorString ("SBTarget is invalid");
442 }
443 return sb_process;
444
445}
446
James McIlree38093402011-03-04 00:31:13 +0000447lldb::SBProcess
448SBTarget::ConnectRemote
449(
450 SBListener &listener,
451 const char *url,
452 const char *plugin_name,
453 SBError& error
454)
455{
456 SBProcess sb_process;
457 if (m_opaque_sp)
458 {
459 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
460 if (listener.IsValid())
461 sb_process.SetProcess (m_opaque_sp->CreateProcess (listener.ref(), plugin_name));
462 else
463 sb_process.SetProcess (m_opaque_sp->CreateProcess (m_opaque_sp->GetDebugger().GetListener(), plugin_name));
464
465
466 if (sb_process.IsValid())
467 {
468 error.SetError (sb_process->ConnectRemote (url));
469 }
470 else
471 {
472 error.SetErrorString ("unable to create lldb_private::Process");
473 }
474 }
475 else
476 {
477 error.SetErrorString ("SBTarget is invalid");
478 }
479 return sb_process;
480}
481
Chris Lattner24943d22010-06-08 16:52:24 +0000482SBFileSpec
483SBTarget::GetExecutable ()
484{
Caroline Tice7826c882010-10-26 03:11:13 +0000485
Chris Lattner24943d22010-06-08 16:52:24 +0000486 SBFileSpec exe_file_spec;
Greg Clayton63094e02010-06-23 01:19:29 +0000487 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000488 {
Greg Clayton5beb99d2011-08-11 02:48:45 +0000489 Module *exe_module = m_opaque_sp->GetExecutableModulePointer();
490 if (exe_module)
491 exe_file_spec.SetFileSpec (exe_module->GetFileSpec());
Chris Lattner24943d22010-06-08 16:52:24 +0000492 }
Caroline Tice7826c882010-10-26 03:11:13 +0000493
Greg Claytone005f2c2010-11-06 01:53:30 +0000494 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000495 if (log)
496 {
Greg Clayton49ce6822010-10-31 03:01:06 +0000497 log->Printf ("SBTarget(%p)::GetExecutable () => SBFileSpec(%p)",
498 m_opaque_sp.get(), exe_file_spec.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000499 }
500
Chris Lattner24943d22010-06-08 16:52:24 +0000501 return exe_file_spec;
502}
503
Chris Lattner24943d22010-06-08 16:52:24 +0000504bool
Chris Lattner24943d22010-06-08 16:52:24 +0000505SBTarget::operator == (const SBTarget &rhs) const
506{
Greg Clayton63094e02010-06-23 01:19:29 +0000507 return m_opaque_sp.get() == rhs.m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000508}
509
510bool
511SBTarget::operator != (const SBTarget &rhs) const
512{
Greg Clayton63094e02010-06-23 01:19:29 +0000513 return m_opaque_sp.get() != rhs.m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000514}
515
516lldb_private::Target *
Greg Clayton63094e02010-06-23 01:19:29 +0000517SBTarget::operator ->() const
Chris Lattner24943d22010-06-08 16:52:24 +0000518{
Greg Clayton63094e02010-06-23 01:19:29 +0000519 return m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000520}
Greg Clayton63094e02010-06-23 01:19:29 +0000521
522lldb_private::Target *
523SBTarget::get() const
Chris Lattner24943d22010-06-08 16:52:24 +0000524{
Greg Clayton63094e02010-06-23 01:19:29 +0000525 return m_opaque_sp.get();
526}
527
Greg Clayton15afa9f2011-10-01 02:59:24 +0000528const lldb::TargetSP &
529SBTarget::get_sp () const
530{
531 return m_opaque_sp;
532}
533
Greg Clayton63094e02010-06-23 01:19:29 +0000534void
535SBTarget::reset (const lldb::TargetSP& target_sp)
536{
537 m_opaque_sp = target_sp;
Chris Lattner24943d22010-06-08 16:52:24 +0000538}
539
Greg Claytona3955062011-07-22 16:46:35 +0000540lldb::SBAddress
541SBTarget::ResolveLoadAddress (lldb::addr_t vm_addr)
Greg Claytonea49cc72010-12-12 19:25:26 +0000542{
Greg Claytona3955062011-07-22 16:46:35 +0000543 lldb::SBAddress sb_addr;
544 Address &addr = sb_addr.ref();
545 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000546 {
547 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
Greg Claytona3955062011-07-22 16:46:35 +0000548 if (m_opaque_sp->GetSectionLoadList().ResolveLoadAddress (vm_addr, addr))
549 return sb_addr;
Greg Claytonbdcda462010-12-20 20:49:23 +0000550 }
Greg Claytonea49cc72010-12-12 19:25:26 +0000551
Greg Claytona3955062011-07-22 16:46:35 +0000552 // We have a load address that isn't in a section, just return an address
553 // with the offset filled in (the address) and the section set to NULL
554 addr.SetSection(NULL);
555 addr.SetOffset(vm_addr);
556 return sb_addr;
Greg Claytonea49cc72010-12-12 19:25:26 +0000557}
558
Greg Claytonafb81862011-03-02 21:34:46 +0000559SBSymbolContext
560SBTarget::ResolveSymbolContextForAddress (const SBAddress& addr, uint32_t resolve_scope)
561{
562 SBSymbolContext sc;
Johnny Chene657fbc2011-06-29 00:05:40 +0000563 if (m_opaque_sp && addr.IsValid())
Greg Claytona3955062011-07-22 16:46:35 +0000564 m_opaque_sp->GetImages().ResolveSymbolContextForAddress (addr.ref(), resolve_scope, sc.ref());
Greg Claytonafb81862011-03-02 21:34:46 +0000565 return sc;
566}
567
568
Chris Lattner24943d22010-06-08 16:52:24 +0000569SBBreakpoint
570SBTarget::BreakpointCreateByLocation (const char *file, uint32_t line)
571{
Greg Claytond6d806c2010-11-08 00:28:40 +0000572 return SBBreakpoint(BreakpointCreateByLocation (SBFileSpec (file, false), line));
Chris Lattner24943d22010-06-08 16:52:24 +0000573}
574
575SBBreakpoint
576SBTarget::BreakpointCreateByLocation (const SBFileSpec &sb_file_spec, uint32_t line)
577{
Greg Claytone005f2c2010-11-06 01:53:30 +0000578 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000579
Chris Lattner24943d22010-06-08 16:52:24 +0000580 SBBreakpoint sb_bp;
Greg Clayton63094e02010-06-23 01:19:29 +0000581 if (m_opaque_sp.get() && line != 0)
Greg Claytonbdcda462010-12-20 20:49:23 +0000582 {
583 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
Greg Clayton63094e02010-06-23 01:19:29 +0000584 *sb_bp = m_opaque_sp->CreateBreakpoint (NULL, *sb_file_spec, line, true, false);
Greg Claytonbdcda462010-12-20 20:49:23 +0000585 }
Caroline Tice7826c882010-10-26 03:11:13 +0000586
587 if (log)
588 {
589 SBStream sstr;
590 sb_bp.GetDescription (sstr);
Greg Clayton49ce6822010-10-31 03:01:06 +0000591 char path[PATH_MAX];
592 sb_file_spec->GetPath (path, sizeof(path));
593 log->Printf ("SBTarget(%p)::BreakpointCreateByLocation ( %s:%u ) => SBBreakpoint(%p): %s",
Greg Claytona66ba462010-10-30 04:51:46 +0000594 m_opaque_sp.get(),
Greg Clayton49ce6822010-10-31 03:01:06 +0000595 path,
Greg Claytona66ba462010-10-30 04:51:46 +0000596 line,
Greg Clayton49ce6822010-10-31 03:01:06 +0000597 sb_bp.get(),
Caroline Tice7826c882010-10-26 03:11:13 +0000598 sstr.GetData());
599 }
600
Chris Lattner24943d22010-06-08 16:52:24 +0000601 return sb_bp;
602}
603
604SBBreakpoint
605SBTarget::BreakpointCreateByName (const char *symbol_name, const char *module_name)
606{
Greg Claytone005f2c2010-11-06 01:53:30 +0000607 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000608
Chris Lattner24943d22010-06-08 16:52:24 +0000609 SBBreakpoint sb_bp;
Jim Inghamd6d47972011-09-23 00:54:11 +0000610 if (m_opaque_sp.get())
Chris Lattner24943d22010-06-08 16:52:24 +0000611 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000612 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
Chris Lattner24943d22010-06-08 16:52:24 +0000613 if (module_name && module_name[0])
614 {
Jim Ingham03c8ee52011-09-21 01:17:13 +0000615 FileSpecList module_spec_list;
616 module_spec_list.Append (FileSpec (module_name, false));
Jim Ingham8b7b2272011-10-07 22:23:45 +0000617 *sb_bp = m_opaque_sp->CreateBreakpoint (&module_spec_list, NULL, symbol_name, eFunctionNameTypeAuto, false);
Chris Lattner24943d22010-06-08 16:52:24 +0000618 }
619 else
620 {
Jim Ingham8b7b2272011-10-07 22:23:45 +0000621 *sb_bp = m_opaque_sp->CreateBreakpoint (NULL, NULL, symbol_name, eFunctionNameTypeAuto, false);
Chris Lattner24943d22010-06-08 16:52:24 +0000622 }
623 }
Caroline Tice7826c882010-10-26 03:11:13 +0000624
625 if (log)
626 {
Greg Clayton49ce6822010-10-31 03:01:06 +0000627 log->Printf ("SBTarget(%p)::BreakpointCreateByName (symbol=\"%s\", module=\"%s\") => SBBreakpoint(%p)",
628 m_opaque_sp.get(), symbol_name, module_name, sb_bp.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000629 }
630
Chris Lattner24943d22010-06-08 16:52:24 +0000631 return sb_bp;
632}
633
Jim Inghamd6d47972011-09-23 00:54:11 +0000634lldb::SBBreakpoint
635SBTarget::BreakpointCreateByName (const char *symbol_name,
636 const SBFileSpecList &module_list,
637 const SBFileSpecList &comp_unit_list)
638{
Jim Ingham1fb8a2d2011-10-11 01:18:55 +0000639 uint32_t name_type_mask = eFunctionNameTypeAuto;
640 return BreakpointCreateByName (symbol_name, name_type_mask, module_list, comp_unit_list);
641}
642
643lldb::SBBreakpoint
644SBTarget::BreakpointCreateByName (const char *symbol_name,
645 uint32_t name_type_mask,
646 const SBFileSpecList &module_list,
647 const SBFileSpecList &comp_unit_list)
648{
Jim Inghamd6d47972011-09-23 00:54:11 +0000649 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
650
651 SBBreakpoint sb_bp;
652 if (m_opaque_sp.get() && symbol_name && symbol_name[0])
653 {
654 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
655 *sb_bp = m_opaque_sp->CreateBreakpoint (module_list.get(),
656 comp_unit_list.get(),
657 symbol_name,
Jim Ingham1fb8a2d2011-10-11 01:18:55 +0000658 name_type_mask,
Jim Inghamd6d47972011-09-23 00:54:11 +0000659 false);
660 }
661
662 if (log)
663 {
Jim Ingham1fb8a2d2011-10-11 01:18:55 +0000664 log->Printf ("SBTarget(%p)::BreakpointCreateByName (symbol=\"%s\", name_type: %d) => SBBreakpoint(%p)",
665 m_opaque_sp.get(), symbol_name, name_type_mask, sb_bp.get());
Jim Inghamd6d47972011-09-23 00:54:11 +0000666 }
667
668 return sb_bp;
669}
670
671
Chris Lattner24943d22010-06-08 16:52:24 +0000672SBBreakpoint
673SBTarget::BreakpointCreateByRegex (const char *symbol_name_regex, const char *module_name)
674{
Greg Claytone005f2c2010-11-06 01:53:30 +0000675 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000676
Chris Lattner24943d22010-06-08 16:52:24 +0000677 SBBreakpoint sb_bp;
Greg Clayton63094e02010-06-23 01:19:29 +0000678 if (m_opaque_sp.get() && symbol_name_regex && symbol_name_regex[0])
Chris Lattner24943d22010-06-08 16:52:24 +0000679 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000680 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
Chris Lattner24943d22010-06-08 16:52:24 +0000681 RegularExpression regexp(symbol_name_regex);
682
683 if (module_name && module_name[0])
684 {
Jim Ingham03c8ee52011-09-21 01:17:13 +0000685 FileSpecList module_spec_list;
686 module_spec_list.Append (FileSpec (module_name, false));
Chris Lattner24943d22010-06-08 16:52:24 +0000687
Jim Inghamd6d47972011-09-23 00:54:11 +0000688 *sb_bp = m_opaque_sp->CreateFuncRegexBreakpoint (&module_spec_list, NULL, regexp, false);
Chris Lattner24943d22010-06-08 16:52:24 +0000689 }
690 else
691 {
Jim Inghamd6d47972011-09-23 00:54:11 +0000692 *sb_bp = m_opaque_sp->CreateFuncRegexBreakpoint (NULL, NULL, regexp, false);
Chris Lattner24943d22010-06-08 16:52:24 +0000693 }
694 }
Caroline Tice7826c882010-10-26 03:11:13 +0000695
696 if (log)
697 {
Greg Clayton49ce6822010-10-31 03:01:06 +0000698 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (symbol_regex=\"%s\", module_name=\"%s\") => SBBreakpoint(%p)",
699 m_opaque_sp.get(), symbol_name_regex, module_name, sb_bp.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000700 }
701
Chris Lattner24943d22010-06-08 16:52:24 +0000702 return sb_bp;
703}
704
Jim Inghamd6d47972011-09-23 00:54:11 +0000705lldb::SBBreakpoint
706SBTarget::BreakpointCreateByRegex (const char *symbol_name_regex,
707 const SBFileSpecList &module_list,
708 const SBFileSpecList &comp_unit_list)
709{
710 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Chris Lattner24943d22010-06-08 16:52:24 +0000711
Jim Inghamd6d47972011-09-23 00:54:11 +0000712 SBBreakpoint sb_bp;
713 if (m_opaque_sp.get() && symbol_name_regex && symbol_name_regex[0])
714 {
715 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
716 RegularExpression regexp(symbol_name_regex);
717
718 *sb_bp = m_opaque_sp->CreateFuncRegexBreakpoint (module_list.get(), comp_unit_list.get(), regexp, false);
719 }
720
721 if (log)
722 {
723 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (symbol_regex=\"%s\") => SBBreakpoint(%p)",
724 m_opaque_sp.get(), symbol_name_regex, sb_bp.get());
725 }
726
727 return sb_bp;
728}
Chris Lattner24943d22010-06-08 16:52:24 +0000729
730SBBreakpoint
731SBTarget::BreakpointCreateByAddress (addr_t address)
732{
Greg Claytone005f2c2010-11-06 01:53:30 +0000733 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000734
Chris Lattner24943d22010-06-08 16:52:24 +0000735 SBBreakpoint sb_bp;
Greg Clayton63094e02010-06-23 01:19:29 +0000736 if (m_opaque_sp.get())
Greg Claytonbdcda462010-12-20 20:49:23 +0000737 {
738 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
Greg Clayton63094e02010-06-23 01:19:29 +0000739 *sb_bp = m_opaque_sp->CreateBreakpoint (address, false);
Greg Claytonbdcda462010-12-20 20:49:23 +0000740 }
Caroline Tice7826c882010-10-26 03:11:13 +0000741
742 if (log)
743 {
Jason Molenda7e5fa7f2011-09-20 21:44:10 +0000744 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 +0000745 }
746
Chris Lattner24943d22010-06-08 16:52:24 +0000747 return sb_bp;
748}
749
Jim Ingham03c8ee52011-09-21 01:17:13 +0000750lldb::SBBreakpoint
751SBTarget::BreakpointCreateBySourceRegex (const char *source_regex, const lldb::SBFileSpec &source_file, const char *module_name)
752{
753 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
754
755 SBBreakpoint sb_bp;
756 if (m_opaque_sp.get() && source_regex && source_regex[0])
757 {
758 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
759 RegularExpression regexp(source_regex);
Jim Inghamd6d47972011-09-23 00:54:11 +0000760 FileSpecList source_file_spec_list;
761 source_file_spec_list.Append (source_file.ref());
Jim Ingham03c8ee52011-09-21 01:17:13 +0000762
763 if (module_name && module_name[0])
764 {
765 FileSpecList module_spec_list;
766 module_spec_list.Append (FileSpec (module_name, false));
767
Jim Inghamd6d47972011-09-23 00:54:11 +0000768 *sb_bp = m_opaque_sp->CreateSourceRegexBreakpoint (&module_spec_list, &source_file_spec_list, regexp, false);
Jim Ingham03c8ee52011-09-21 01:17:13 +0000769 }
770 else
771 {
Jim Inghamd6d47972011-09-23 00:54:11 +0000772 *sb_bp = m_opaque_sp->CreateSourceRegexBreakpoint (NULL, &source_file_spec_list, regexp, false);
Jim Ingham03c8ee52011-09-21 01:17:13 +0000773 }
774 }
775
776 if (log)
777 {
778 char path[PATH_MAX];
779 source_file->GetPath (path, sizeof(path));
780 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (source_regex=\"%s\", file=\"%s\", module_name=\"%s\") => SBBreakpoint(%p)",
Greg Claytona253c932011-09-21 06:45:51 +0000781 m_opaque_sp.get(), source_regex, path, module_name, sb_bp.get());
Jim Ingham03c8ee52011-09-21 01:17:13 +0000782 }
783
784 return sb_bp;
785}
786
Jim Inghamd6d47972011-09-23 00:54:11 +0000787lldb::SBBreakpoint
788SBTarget::BreakpointCreateBySourceRegex (const char *source_regex,
789 const SBFileSpecList &module_list,
790 const lldb::SBFileSpecList &source_file_list)
791{
792 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
793
794 SBBreakpoint sb_bp;
795 if (m_opaque_sp.get() && source_regex && source_regex[0])
796 {
797 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
798 RegularExpression regexp(source_regex);
799 *sb_bp = m_opaque_sp->CreateSourceRegexBreakpoint (module_list.get(), source_file_list.get(), regexp, false);
800 }
801
802 if (log)
803 {
804 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (source_regex=\"%s\") => SBBreakpoint(%p)",
805 m_opaque_sp.get(), source_regex, sb_bp.get());
806 }
807
808 return sb_bp;
809}
Jim Ingham03c8ee52011-09-21 01:17:13 +0000810
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000811uint32_t
812SBTarget::GetNumBreakpoints () const
813{
814 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000815 {
816 // The breakpoint list is thread safe, no need to lock
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000817 return m_opaque_sp->GetBreakpointList().GetSize();
Greg Claytonbdcda462010-12-20 20:49:23 +0000818 }
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000819 return 0;
820}
821
822SBBreakpoint
823SBTarget::GetBreakpointAtIndex (uint32_t idx) const
824{
825 SBBreakpoint sb_breakpoint;
826 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000827 {
828 // The breakpoint list is thread safe, no need to lock
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000829 *sb_breakpoint = m_opaque_sp->GetBreakpointList().GetBreakpointAtIndex(idx);
Greg Claytonbdcda462010-12-20 20:49:23 +0000830 }
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000831 return sb_breakpoint;
832}
Chris Lattner24943d22010-06-08 16:52:24 +0000833
834bool
835SBTarget::BreakpointDelete (break_id_t bp_id)
836{
Greg Claytone005f2c2010-11-06 01:53:30 +0000837 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000838
Caroline Tice7826c882010-10-26 03:11:13 +0000839 bool result = false;
Greg Clayton63094e02010-06-23 01:19:29 +0000840 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000841 {
842 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
Caroline Tice7826c882010-10-26 03:11:13 +0000843 result = m_opaque_sp->RemoveBreakpointByID (bp_id);
Greg Claytonbdcda462010-12-20 20:49:23 +0000844 }
Caroline Tice7826c882010-10-26 03:11:13 +0000845
846 if (log)
847 {
Greg Clayton3f5ee7f2010-10-29 04:59:35 +0000848 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 +0000849 }
850
851 return result;
Chris Lattner24943d22010-06-08 16:52:24 +0000852}
853
Johnny Chen096c2932011-09-26 22:40:50 +0000854SBBreakpoint
855SBTarget::FindBreakpointByID (break_id_t bp_id)
856{
857 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
858
859 SBBreakpoint sb_breakpoint;
860 if (m_opaque_sp && bp_id != LLDB_INVALID_BREAK_ID)
861 {
862 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
863 *sb_breakpoint = m_opaque_sp->GetBreakpointByID (bp_id);
864 }
865
866 if (log)
867 {
868 log->Printf ("SBTarget(%p)::FindBreakpointByID (bp_id=%d) => SBBreakpoint(%p)",
869 m_opaque_sp.get(), (uint32_t) bp_id, sb_breakpoint.get());
870 }
871
872 return sb_breakpoint;
873}
874
Chris Lattner24943d22010-06-08 16:52:24 +0000875bool
876SBTarget::EnableAllBreakpoints ()
877{
Greg Clayton63094e02010-06-23 01:19:29 +0000878 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000879 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000880 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
Greg Clayton63094e02010-06-23 01:19:29 +0000881 m_opaque_sp->EnableAllBreakpoints ();
Chris Lattner24943d22010-06-08 16:52:24 +0000882 return true;
883 }
884 return false;
885}
886
887bool
888SBTarget::DisableAllBreakpoints ()
889{
Greg Clayton63094e02010-06-23 01:19:29 +0000890 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000891 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000892 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
Greg Clayton63094e02010-06-23 01:19:29 +0000893 m_opaque_sp->DisableAllBreakpoints ();
Chris Lattner24943d22010-06-08 16:52:24 +0000894 return true;
895 }
896 return false;
897}
898
899bool
900SBTarget::DeleteAllBreakpoints ()
901{
Greg Clayton63094e02010-06-23 01:19:29 +0000902 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000903 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000904 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
Greg Clayton63094e02010-06-23 01:19:29 +0000905 m_opaque_sp->RemoveAllBreakpoints ();
Chris Lattner24943d22010-06-08 16:52:24 +0000906 return true;
907 }
908 return false;
909}
910
Johnny Chen096c2932011-09-26 22:40:50 +0000911uint32_t
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000912SBTarget::GetNumWatchpoints () const
Johnny Chen096c2932011-09-26 22:40:50 +0000913{
914 if (m_opaque_sp)
915 {
Johnny Chenecd4feb2011-10-14 00:42:25 +0000916 // The watchpoint list is thread safe, no need to lock
917 return m_opaque_sp->GetWatchpointList().GetSize();
Johnny Chen096c2932011-09-26 22:40:50 +0000918 }
919 return 0;
920}
921
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000922SBWatchpoint
923SBTarget::GetWatchpointAtIndex (uint32_t idx) const
Johnny Chen5eb54bb2011-09-27 20:29:45 +0000924{
Johnny Chenecd4feb2011-10-14 00:42:25 +0000925 SBWatchpoint sb_watchpoint;
Johnny Chen096c2932011-09-26 22:40:50 +0000926 if (m_opaque_sp)
927 {
Johnny Chenecd4feb2011-10-14 00:42:25 +0000928 // The watchpoint list is thread safe, no need to lock
929 *sb_watchpoint = m_opaque_sp->GetWatchpointList().GetByIndex(idx);
Johnny Chen096c2932011-09-26 22:40:50 +0000930 }
Johnny Chenecd4feb2011-10-14 00:42:25 +0000931 return sb_watchpoint;
Johnny Chen096c2932011-09-26 22:40:50 +0000932}
933
934bool
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000935SBTarget::DeleteWatchpoint (watch_id_t wp_id)
Johnny Chen096c2932011-09-26 22:40:50 +0000936{
937 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
938
939 bool result = false;
940 if (m_opaque_sp)
941 {
942 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
Johnny Chenecd4feb2011-10-14 00:42:25 +0000943 result = m_opaque_sp->RemoveWatchpointByID (wp_id);
Johnny Chen096c2932011-09-26 22:40:50 +0000944 }
945
946 if (log)
947 {
Johnny Chenecd4feb2011-10-14 00:42:25 +0000948 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 +0000949 }
950
951 return result;
952}
953
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000954SBWatchpoint
955SBTarget::FindWatchpointByID (lldb::watch_id_t wp_id)
Johnny Chen096c2932011-09-26 22:40:50 +0000956{
957 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
958
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000959 SBWatchpoint sb_watchpoint;
Johnny Chen096c2932011-09-26 22:40:50 +0000960 if (m_opaque_sp && wp_id != LLDB_INVALID_WATCH_ID)
961 {
962 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
Johnny Chenecd4feb2011-10-14 00:42:25 +0000963 *sb_watchpoint = m_opaque_sp->GetWatchpointList().FindByID(wp_id);
Johnny Chen096c2932011-09-26 22:40:50 +0000964 }
965
966 if (log)
967 {
Johnny Chenecd4feb2011-10-14 00:42:25 +0000968 log->Printf ("SBTarget(%p)::FindWatchpointByID (bp_id=%d) => SBWatchpoint(%p)",
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000969 m_opaque_sp.get(), (uint32_t) wp_id, sb_watchpoint.get());
Johnny Chen096c2932011-09-26 22:40:50 +0000970 }
971
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000972 return sb_watchpoint;
973}
974
975lldb::SBWatchpoint
976SBTarget::WatchAddress (lldb::addr_t addr, size_t size, bool read, bool write)
977{
978 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
979
980 SBWatchpoint sb_watchpoint;
981 if (m_opaque_sp)
982 {
983 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
Johnny Chenecd4feb2011-10-14 00:42:25 +0000984 uint32_t watch_type = (read ? LLDB_WATCH_TYPE_READ : 0) |
985 (write ? LLDB_WATCH_TYPE_WRITE : 0);
Johnny Chen50e05342011-10-14 01:16:39 +0000986 sb_watchpoint = m_opaque_sp->CreateWatchpoint(addr, size, watch_type);
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000987 }
988
989 if (log)
990 {
991 log->Printf ("SBTarget(%p)::WatchAddress (addr=0x%llx, 0x%u) => SBWatchpoint(%p)",
992 m_opaque_sp.get(), addr, (uint32_t) size, sb_watchpoint.get());
993 }
994
995 return sb_watchpoint;
Johnny Chen096c2932011-09-26 22:40:50 +0000996}
997
998bool
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000999SBTarget::EnableAllWatchpoints ()
Johnny Chen096c2932011-09-26 22:40:50 +00001000{
1001 if (m_opaque_sp)
1002 {
1003 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
Johnny Chenecd4feb2011-10-14 00:42:25 +00001004 m_opaque_sp->EnableAllWatchpoints ();
Johnny Chen096c2932011-09-26 22:40:50 +00001005 return true;
1006 }
1007 return false;
1008}
1009
1010bool
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001011SBTarget::DisableAllWatchpoints ()
Johnny Chen096c2932011-09-26 22:40:50 +00001012{
1013 if (m_opaque_sp)
1014 {
1015 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
Johnny Chenecd4feb2011-10-14 00:42:25 +00001016 m_opaque_sp->DisableAllWatchpoints ();
Johnny Chen096c2932011-09-26 22:40:50 +00001017 return true;
1018 }
1019 return false;
1020}
1021
1022bool
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001023SBTarget::DeleteAllWatchpoints ()
Johnny Chen096c2932011-09-26 22:40:50 +00001024{
1025 if (m_opaque_sp)
1026 {
1027 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
Johnny Chenecd4feb2011-10-14 00:42:25 +00001028 m_opaque_sp->RemoveAllWatchpoints ();
Johnny Chen096c2932011-09-26 22:40:50 +00001029 return true;
1030 }
1031 return false;
1032}
1033
Chris Lattner24943d22010-06-08 16:52:24 +00001034
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001035lldb::SBModule
1036SBTarget::AddModule (const char *path,
1037 const char *triple,
1038 const char *uuid_cstr)
1039{
1040 lldb::SBModule sb_module;
1041 if (m_opaque_sp)
1042 {
1043 FileSpec module_file_spec;
1044 UUID module_uuid;
1045 ArchSpec module_arch;
1046
1047 if (path)
1048 module_file_spec.SetFile(path, false);
1049
1050 if (uuid_cstr)
1051 module_uuid.SetfromCString(uuid_cstr);
1052
1053 if (triple)
1054 module_arch.SetTriple (triple, m_opaque_sp->GetPlatform ().get());
1055
1056 sb_module.SetModule(m_opaque_sp->GetSharedModule (module_file_spec,
1057 module_arch,
1058 uuid_cstr ? &module_uuid : NULL));
1059 }
1060 return sb_module;
1061}
1062
1063bool
1064SBTarget::AddModule (lldb::SBModule &module)
1065{
1066 if (m_opaque_sp)
1067 {
1068 m_opaque_sp->GetImages().AppendIfNeeded (module.get_sp());
1069 return true;
1070 }
1071 return false;
1072}
1073
1074lldb::SBModule
1075AddModule (const char *path,
1076 const char *triple,
1077 const char *uuid);
1078
1079
1080
Chris Lattner24943d22010-06-08 16:52:24 +00001081uint32_t
1082SBTarget::GetNumModules () const
1083{
Greg Claytone005f2c2010-11-06 01:53:30 +00001084 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001085
Caroline Tice7826c882010-10-26 03:11:13 +00001086 uint32_t num = 0;
Greg Clayton63094e02010-06-23 01:19:29 +00001087 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +00001088 {
1089 // The module list is thread safe, no need to lock
1090 num = m_opaque_sp->GetImages().GetSize();
1091 }
Caroline Tice7826c882010-10-26 03:11:13 +00001092
1093 if (log)
Greg Clayton3f5ee7f2010-10-29 04:59:35 +00001094 log->Printf ("SBTarget(%p)::GetNumModules () => %d", m_opaque_sp.get(), num);
Caroline Tice7826c882010-10-26 03:11:13 +00001095
1096 return num;
Chris Lattner24943d22010-06-08 16:52:24 +00001097}
1098
Greg Clayton43490d12010-07-30 20:12:55 +00001099void
1100SBTarget::Clear ()
1101{
Greg Claytone005f2c2010-11-06 01:53:30 +00001102 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001103
1104 if (log)
Greg Clayton3f5ee7f2010-10-29 04:59:35 +00001105 log->Printf ("SBTarget(%p)::Clear ()", m_opaque_sp.get());
Caroline Tice7826c882010-10-26 03:11:13 +00001106
Greg Clayton43490d12010-07-30 20:12:55 +00001107 m_opaque_sp.reset();
1108}
1109
1110
Chris Lattner24943d22010-06-08 16:52:24 +00001111SBModule
1112SBTarget::FindModule (const SBFileSpec &sb_file_spec)
1113{
1114 SBModule sb_module;
Greg Clayton63094e02010-06-23 01:19:29 +00001115 if (m_opaque_sp && sb_file_spec.IsValid())
Greg Claytonbdcda462010-12-20 20:49:23 +00001116 {
1117 // The module list is thread safe, no need to lock
Greg Clayton24bc5d92011-03-30 18:16:51 +00001118 sb_module.SetModule (m_opaque_sp->GetImages().FindFirstModuleForFileSpec (*sb_file_spec, NULL, NULL));
Greg Claytonbdcda462010-12-20 20:49:23 +00001119 }
Chris Lattner24943d22010-06-08 16:52:24 +00001120 return sb_module;
1121}
1122
1123SBModule
1124SBTarget::GetModuleAtIndex (uint32_t idx)
1125{
Greg Claytone005f2c2010-11-06 01:53:30 +00001126 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001127
Chris Lattner24943d22010-06-08 16:52:24 +00001128 SBModule sb_module;
Greg Clayton63094e02010-06-23 01:19:29 +00001129 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +00001130 {
1131 // The module list is thread safe, no need to lock
Greg Clayton63094e02010-06-23 01:19:29 +00001132 sb_module.SetModule(m_opaque_sp->GetImages().GetModuleAtIndex(idx));
Greg Claytonbdcda462010-12-20 20:49:23 +00001133 }
Caroline Tice7826c882010-10-26 03:11:13 +00001134
1135 if (log)
1136 {
Greg Clayton49ce6822010-10-31 03:01:06 +00001137 log->Printf ("SBTarget(%p)::GetModuleAtIndex (idx=%d) => SBModule(%p)",
1138 m_opaque_sp.get(), idx, sb_module.get());
Caroline Tice7826c882010-10-26 03:11:13 +00001139 }
1140
Chris Lattner24943d22010-06-08 16:52:24 +00001141 return sb_module;
1142}
1143
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001144bool
1145SBTarget::RemoveModule (lldb::SBModule module)
1146{
1147 if (m_opaque_sp)
1148 return m_opaque_sp->GetImages().Remove(module.get_sp());
1149 return false;
1150}
1151
Chris Lattner24943d22010-06-08 16:52:24 +00001152
1153SBBroadcaster
1154SBTarget::GetBroadcaster () const
1155{
Greg Claytone005f2c2010-11-06 01:53:30 +00001156 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001157
Greg Clayton63094e02010-06-23 01:19:29 +00001158 SBBroadcaster broadcaster(m_opaque_sp.get(), false);
Caroline Tice7826c882010-10-26 03:11:13 +00001159
1160 if (log)
Greg Clayton3f5ee7f2010-10-29 04:59:35 +00001161 log->Printf ("SBTarget(%p)::GetBroadcaster () => SBBroadcaster(%p)",
Caroline Tice61ba7ec2010-10-26 23:49:36 +00001162 m_opaque_sp.get(), broadcaster.get());
Caroline Tice7826c882010-10-26 03:11:13 +00001163
Chris Lattner24943d22010-06-08 16:52:24 +00001164 return broadcaster;
1165}
1166
Caroline Tice98f930f2010-09-20 05:20:02 +00001167
1168bool
Caroline Tice7826c882010-10-26 03:11:13 +00001169SBTarget::GetDescription (SBStream &description, lldb::DescriptionLevel description_level)
Caroline Tice98f930f2010-09-20 05:20:02 +00001170{
Greg Clayton96154be2011-11-13 06:57:31 +00001171 Stream &strm = description.ref();
1172
Caroline Tice98f930f2010-09-20 05:20:02 +00001173 if (m_opaque_sp)
Caroline Ticee7a566e2010-09-20 16:21:41 +00001174 {
Greg Clayton96154be2011-11-13 06:57:31 +00001175 m_opaque_sp->Dump (&strm, description_level);
Caroline Tice7826c882010-10-26 03:11:13 +00001176 }
1177 else
Greg Clayton96154be2011-11-13 06:57:31 +00001178 strm.PutCString ("No value");
Caroline Tice7826c882010-10-26 03:11:13 +00001179
1180 return true;
1181}
1182
Greg Clayton4ed315f2011-06-21 01:34:41 +00001183uint32_t
1184SBTarget::FindFunctions (const char *name,
1185 uint32_t name_type_mask,
1186 bool append,
1187 lldb::SBSymbolContextList& sc_list)
1188{
1189 if (!append)
1190 sc_list.Clear();
Johnny Chencd186e52011-12-14 01:43:31 +00001191 if (name && m_opaque_sp)
Greg Clayton4ed315f2011-06-21 01:34:41 +00001192 {
1193 const bool symbols_ok = true;
1194 return m_opaque_sp->GetImages().FindFunctions (ConstString(name),
1195 name_type_mask,
1196 symbols_ok,
1197 append,
1198 *sc_list);
1199 }
1200 return 0;
1201}
1202
Enrico Granata979e20d2011-07-29 19:53:35 +00001203lldb::SBType
1204SBTarget::FindFirstType (const char* type)
1205{
Johnny Chencd186e52011-12-14 01:43:31 +00001206 if (type && m_opaque_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +00001207 {
1208 size_t count = m_opaque_sp->GetImages().GetSize();
1209 for (size_t idx = 0; idx < count; idx++)
1210 {
1211 SBType found_at_idx = GetModuleAtIndex(idx).FindFirstType(type);
1212
1213 if (found_at_idx.IsValid())
1214 return found_at_idx;
1215 }
1216 }
1217 return SBType();
1218}
1219
1220lldb::SBTypeList
1221SBTarget::FindTypes (const char* type)
1222{
1223
1224 SBTypeList retval;
1225
Johnny Chencd186e52011-12-14 01:43:31 +00001226 if (type && m_opaque_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +00001227 {
1228 ModuleList& images = m_opaque_sp->GetImages();
1229 ConstString name_const(type);
1230 SymbolContext sc;
1231 TypeList type_list;
1232
1233 uint32_t num_matches = images.FindTypes(sc,
1234 name_const,
1235 true,
1236 UINT32_MAX,
1237 type_list);
1238
1239 for (size_t idx = 0; idx < num_matches; idx++)
1240 {
Greg Clayton0fb0bcc2011-08-03 22:57:10 +00001241 TypeSP type_sp (type_list.GetTypeAtIndex(idx));
1242 if (type_sp)
1243 retval.Append(SBType(type_sp));
Enrico Granata979e20d2011-07-29 19:53:35 +00001244 }
1245 }
1246 return retval;
1247}
1248
Greg Clayton917c0002011-06-29 22:09:02 +00001249SBValueList
1250SBTarget::FindGlobalVariables (const char *name, uint32_t max_matches)
1251{
1252 SBValueList sb_value_list;
1253
Johnny Chencd186e52011-12-14 01:43:31 +00001254 if (name && m_opaque_sp)
Greg Clayton917c0002011-06-29 22:09:02 +00001255 {
1256 VariableList variable_list;
1257 const bool append = true;
1258 const uint32_t match_count = m_opaque_sp->GetImages().FindGlobalVariables (ConstString (name),
1259 append,
1260 max_matches,
1261 variable_list);
1262
1263 if (match_count > 0)
1264 {
1265 ExecutionContextScope *exe_scope = m_opaque_sp->GetProcessSP().get();
1266 if (exe_scope == NULL)
1267 exe_scope = m_opaque_sp.get();
1268 ValueObjectList &value_object_list = sb_value_list.ref();
1269 for (uint32_t i=0; i<match_count; ++i)
1270 {
1271 lldb::ValueObjectSP valobj_sp (ValueObjectVariable::Create (exe_scope, variable_list.GetVariableAtIndex(i)));
1272 if (valobj_sp)
1273 value_object_list.Append(valobj_sp);
1274 }
1275 }
1276 }
1277
1278 return sb_value_list;
1279}
1280
Jim Inghamcc637462011-09-13 00:29:56 +00001281SBSourceManager
1282SBTarget::GetSourceManager()
1283{
1284 SBSourceManager source_manager (*this);
1285 return source_manager;
1286}
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001287
Sean Callananef1f6902011-12-14 23:49:37 +00001288lldb::SBInstructionList
1289SBTarget::GetInstructions (lldb::SBAddress base_addr, const void *buf, size_t size)
1290{
1291 SBInstructionList sb_instructions;
1292
1293 if (m_opaque_sp)
1294 {
1295 Address addr;
1296
1297 if (base_addr.get())
1298 addr = *base_addr.get();
1299
1300 sb_instructions.SetDisassembler (Disassembler::DisassembleBytes (m_opaque_sp->GetArchitecture(),
1301 NULL,
1302 addr,
1303 buf,
1304 size));
1305 }
1306
1307 return sb_instructions;
1308}
1309
1310lldb::SBInstructionList
1311SBTarget::GetInstructions (lldb::addr_t base_addr, const void *buf, size_t size)
1312{
1313 return GetInstructions (ResolveLoadAddress(base_addr), buf, size);
1314}
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001315
1316SBError
1317SBTarget::SetSectionLoadAddress (lldb::SBSection section,
1318 lldb::addr_t section_base_addr)
1319{
1320 SBError sb_error;
1321
1322 if (IsValid())
1323 {
1324 if (!section.IsValid())
1325 {
1326 sb_error.SetErrorStringWithFormat ("invalid section");
1327 }
1328 else
1329 {
1330 m_opaque_sp->GetSectionLoadList().SetSectionLoadAddress (section.GetSection(), section_base_addr);
1331 }
1332 }
1333 else
1334 {
1335 sb_error.SetErrorStringWithFormat ("invalid target");
1336 }
1337 return sb_error;
1338}
1339
1340SBError
1341SBTarget::ClearSectionLoadAddress (lldb::SBSection section)
1342{
1343 SBError sb_error;
1344
1345 if (IsValid())
1346 {
1347 if (!section.IsValid())
1348 {
1349 sb_error.SetErrorStringWithFormat ("invalid section");
1350 }
1351 else
1352 {
1353 m_opaque_sp->GetSectionLoadList().SetSectionUnloaded (section.GetSection());
1354 }
1355 }
1356 else
1357 {
1358 sb_error.SetErrorStringWithFormat ("invalid target");
1359 }
1360 return sb_error;
1361}
1362
1363SBError
1364SBTarget::SetModuleLoadAddress (lldb::SBModule module, int64_t slide_offset)
1365{
1366 SBError sb_error;
1367
1368 char path[PATH_MAX];
1369 if (IsValid())
1370 {
1371 if (!module.IsValid())
1372 {
1373 sb_error.SetErrorStringWithFormat ("invalid module");
1374 }
1375 else
1376 {
1377 ObjectFile *objfile = module->GetObjectFile();
1378 if (objfile)
1379 {
1380 SectionList *section_list = objfile->GetSectionList();
1381 if (section_list)
1382 {
1383 const size_t num_sections = section_list->GetSize();
1384 for (size_t sect_idx = 0; sect_idx < num_sections; ++sect_idx)
1385 {
1386 SectionSP section_sp (section_list->GetSectionAtIndex(sect_idx));
1387 if (section_sp)
1388 m_opaque_sp->GetSectionLoadList().SetSectionLoadAddress (section_sp.get(), section_sp->GetFileAddress() + slide_offset);
1389 }
1390 }
1391 else
1392 {
1393 module->GetFileSpec().GetPath (path, sizeof(path));
1394 sb_error.SetErrorStringWithFormat ("no sections in object file '%s'", path);
1395 }
1396 }
1397 else
1398 {
1399 module->GetFileSpec().GetPath (path, sizeof(path));
1400 sb_error.SetErrorStringWithFormat ("no object file for module '%s'", path);
1401 }
1402 }
1403 }
1404 else
1405 {
1406 sb_error.SetErrorStringWithFormat ("invalid target");
1407 }
1408 return sb_error;
1409}
1410
1411SBError
1412SBTarget::ClearModuleLoadAddress (lldb::SBModule module)
1413{
1414 SBError sb_error;
1415
1416 char path[PATH_MAX];
1417 if (IsValid())
1418 {
1419 if (!module.IsValid())
1420 {
1421 sb_error.SetErrorStringWithFormat ("invalid module");
1422 }
1423 else
1424 {
1425 ObjectFile *objfile = module->GetObjectFile();
1426 if (objfile)
1427 {
1428 SectionList *section_list = objfile->GetSectionList();
1429 if (section_list)
1430 {
1431 const size_t num_sections = section_list->GetSize();
1432 for (size_t sect_idx = 0; sect_idx < num_sections; ++sect_idx)
1433 {
1434 SectionSP section_sp (section_list->GetSectionAtIndex(sect_idx));
1435 if (section_sp)
1436 m_opaque_sp->GetSectionLoadList().SetSectionUnloaded (section_sp.get());
1437 }
1438 }
1439 else
1440 {
1441 module->GetFileSpec().GetPath (path, sizeof(path));
1442 sb_error.SetErrorStringWithFormat ("no sections in object file '%s'", path);
1443 }
1444 }
1445 else
1446 {
1447 module->GetFileSpec().GetPath (path, sizeof(path));
1448 sb_error.SetErrorStringWithFormat ("no object file for module '%s'", path);
1449 }
1450 }
1451 }
1452 else
1453 {
1454 sb_error.SetErrorStringWithFormat ("invalid target");
1455 }
1456 return sb_error;
1457}
1458
1459