blob: 74580c431e28a253498e52f8c2ad299906941271 [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
502void
503SBTarget::reset (const lldb::TargetSP& target_sp)
504{
505 m_opaque_sp = target_sp;
Chris Lattner24943d22010-06-08 16:52:24 +0000506}
507
Greg Claytona3955062011-07-22 16:46:35 +0000508lldb::SBAddress
509SBTarget::ResolveLoadAddress (lldb::addr_t vm_addr)
Greg Claytonea49cc72010-12-12 19:25:26 +0000510{
Greg Claytona3955062011-07-22 16:46:35 +0000511 lldb::SBAddress sb_addr;
512 Address &addr = sb_addr.ref();
513 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000514 {
515 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
Greg Claytona3955062011-07-22 16:46:35 +0000516 if (m_opaque_sp->GetSectionLoadList().ResolveLoadAddress (vm_addr, addr))
517 return sb_addr;
Greg Claytonbdcda462010-12-20 20:49:23 +0000518 }
Greg Claytonea49cc72010-12-12 19:25:26 +0000519
Greg Claytona3955062011-07-22 16:46:35 +0000520 // We have a load address that isn't in a section, just return an address
521 // with the offset filled in (the address) and the section set to NULL
522 addr.SetSection(NULL);
523 addr.SetOffset(vm_addr);
524 return sb_addr;
Greg Claytonea49cc72010-12-12 19:25:26 +0000525}
526
Greg Claytonafb81862011-03-02 21:34:46 +0000527SBSymbolContext
528SBTarget::ResolveSymbolContextForAddress (const SBAddress& addr, uint32_t resolve_scope)
529{
530 SBSymbolContext sc;
Johnny Chene657fbc2011-06-29 00:05:40 +0000531 if (m_opaque_sp && addr.IsValid())
Greg Claytona3955062011-07-22 16:46:35 +0000532 m_opaque_sp->GetImages().ResolveSymbolContextForAddress (addr.ref(), resolve_scope, sc.ref());
Greg Claytonafb81862011-03-02 21:34:46 +0000533 return sc;
534}
535
536
Chris Lattner24943d22010-06-08 16:52:24 +0000537SBBreakpoint
538SBTarget::BreakpointCreateByLocation (const char *file, uint32_t line)
539{
Greg Claytond6d806c2010-11-08 00:28:40 +0000540 return SBBreakpoint(BreakpointCreateByLocation (SBFileSpec (file, false), line));
Chris Lattner24943d22010-06-08 16:52:24 +0000541}
542
543SBBreakpoint
544SBTarget::BreakpointCreateByLocation (const SBFileSpec &sb_file_spec, uint32_t line)
545{
Greg Claytone005f2c2010-11-06 01:53:30 +0000546 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000547
Chris Lattner24943d22010-06-08 16:52:24 +0000548 SBBreakpoint sb_bp;
Greg Clayton63094e02010-06-23 01:19:29 +0000549 if (m_opaque_sp.get() && line != 0)
Greg Claytonbdcda462010-12-20 20:49:23 +0000550 {
551 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
Greg Clayton63094e02010-06-23 01:19:29 +0000552 *sb_bp = m_opaque_sp->CreateBreakpoint (NULL, *sb_file_spec, line, true, false);
Greg Claytonbdcda462010-12-20 20:49:23 +0000553 }
Caroline Tice7826c882010-10-26 03:11:13 +0000554
555 if (log)
556 {
557 SBStream sstr;
558 sb_bp.GetDescription (sstr);
Greg Clayton49ce6822010-10-31 03:01:06 +0000559 char path[PATH_MAX];
560 sb_file_spec->GetPath (path, sizeof(path));
561 log->Printf ("SBTarget(%p)::BreakpointCreateByLocation ( %s:%u ) => SBBreakpoint(%p): %s",
Greg Claytona66ba462010-10-30 04:51:46 +0000562 m_opaque_sp.get(),
Greg Clayton49ce6822010-10-31 03:01:06 +0000563 path,
Greg Claytona66ba462010-10-30 04:51:46 +0000564 line,
Greg Clayton49ce6822010-10-31 03:01:06 +0000565 sb_bp.get(),
Caroline Tice7826c882010-10-26 03:11:13 +0000566 sstr.GetData());
567 }
568
Chris Lattner24943d22010-06-08 16:52:24 +0000569 return sb_bp;
570}
571
572SBBreakpoint
573SBTarget::BreakpointCreateByName (const char *symbol_name, const char *module_name)
574{
Greg Claytone005f2c2010-11-06 01:53:30 +0000575 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000576
Chris Lattner24943d22010-06-08 16:52:24 +0000577 SBBreakpoint sb_bp;
Jim Inghamd6d47972011-09-23 00:54:11 +0000578 if (m_opaque_sp.get())
Chris Lattner24943d22010-06-08 16:52:24 +0000579 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000580 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
Chris Lattner24943d22010-06-08 16:52:24 +0000581 if (module_name && module_name[0])
582 {
Jim Ingham03c8ee52011-09-21 01:17:13 +0000583 FileSpecList module_spec_list;
584 module_spec_list.Append (FileSpec (module_name, false));
Jim Inghamd6d47972011-09-23 00:54:11 +0000585 *sb_bp = m_opaque_sp->CreateBreakpoint (&module_spec_list, NULL, symbol_name, eFunctionNameTypeFull | eFunctionNameTypeBase, false);
Chris Lattner24943d22010-06-08 16:52:24 +0000586 }
587 else
588 {
Jim Inghamd6d47972011-09-23 00:54:11 +0000589 *sb_bp = m_opaque_sp->CreateBreakpoint (NULL, NULL, symbol_name, eFunctionNameTypeFull | eFunctionNameTypeBase, false);
Chris Lattner24943d22010-06-08 16:52:24 +0000590 }
591 }
Caroline Tice7826c882010-10-26 03:11:13 +0000592
593 if (log)
594 {
Greg Clayton49ce6822010-10-31 03:01:06 +0000595 log->Printf ("SBTarget(%p)::BreakpointCreateByName (symbol=\"%s\", module=\"%s\") => SBBreakpoint(%p)",
596 m_opaque_sp.get(), symbol_name, module_name, sb_bp.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000597 }
598
Chris Lattner24943d22010-06-08 16:52:24 +0000599 return sb_bp;
600}
601
Jim Inghamd6d47972011-09-23 00:54:11 +0000602lldb::SBBreakpoint
603SBTarget::BreakpointCreateByName (const char *symbol_name,
604 const SBFileSpecList &module_list,
605 const SBFileSpecList &comp_unit_list)
606{
607 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
608
609 SBBreakpoint sb_bp;
610 if (m_opaque_sp.get() && symbol_name && symbol_name[0])
611 {
612 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
613 *sb_bp = m_opaque_sp->CreateBreakpoint (module_list.get(),
614 comp_unit_list.get(),
615 symbol_name,
616 eFunctionNameTypeFull | eFunctionNameTypeBase,
617 false);
618 }
619
620 if (log)
621 {
622 log->Printf ("SBTarget(%p)::BreakpointCreateByName (symbol=\"%s\") => SBBreakpoint(%p)",
623 m_opaque_sp.get(), symbol_name, sb_bp.get());
624 }
625
626 return sb_bp;
627}
628
629
Chris Lattner24943d22010-06-08 16:52:24 +0000630SBBreakpoint
631SBTarget::BreakpointCreateByRegex (const char *symbol_name_regex, const char *module_name)
632{
Greg Claytone005f2c2010-11-06 01:53:30 +0000633 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000634
Chris Lattner24943d22010-06-08 16:52:24 +0000635 SBBreakpoint sb_bp;
Greg Clayton63094e02010-06-23 01:19:29 +0000636 if (m_opaque_sp.get() && symbol_name_regex && symbol_name_regex[0])
Chris Lattner24943d22010-06-08 16:52:24 +0000637 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000638 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
Chris Lattner24943d22010-06-08 16:52:24 +0000639 RegularExpression regexp(symbol_name_regex);
640
641 if (module_name && module_name[0])
642 {
Jim Ingham03c8ee52011-09-21 01:17:13 +0000643 FileSpecList module_spec_list;
644 module_spec_list.Append (FileSpec (module_name, false));
Chris Lattner24943d22010-06-08 16:52:24 +0000645
Jim Inghamd6d47972011-09-23 00:54:11 +0000646 *sb_bp = m_opaque_sp->CreateFuncRegexBreakpoint (&module_spec_list, NULL, regexp, false);
Chris Lattner24943d22010-06-08 16:52:24 +0000647 }
648 else
649 {
Jim Inghamd6d47972011-09-23 00:54:11 +0000650 *sb_bp = m_opaque_sp->CreateFuncRegexBreakpoint (NULL, NULL, regexp, false);
Chris Lattner24943d22010-06-08 16:52:24 +0000651 }
652 }
Caroline Tice7826c882010-10-26 03:11:13 +0000653
654 if (log)
655 {
Greg Clayton49ce6822010-10-31 03:01:06 +0000656 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (symbol_regex=\"%s\", module_name=\"%s\") => SBBreakpoint(%p)",
657 m_opaque_sp.get(), symbol_name_regex, module_name, sb_bp.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000658 }
659
Chris Lattner24943d22010-06-08 16:52:24 +0000660 return sb_bp;
661}
662
Jim Inghamd6d47972011-09-23 00:54:11 +0000663lldb::SBBreakpoint
664SBTarget::BreakpointCreateByRegex (const char *symbol_name_regex,
665 const SBFileSpecList &module_list,
666 const SBFileSpecList &comp_unit_list)
667{
668 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Chris Lattner24943d22010-06-08 16:52:24 +0000669
Jim Inghamd6d47972011-09-23 00:54:11 +0000670 SBBreakpoint sb_bp;
671 if (m_opaque_sp.get() && symbol_name_regex && symbol_name_regex[0])
672 {
673 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
674 RegularExpression regexp(symbol_name_regex);
675
676 *sb_bp = m_opaque_sp->CreateFuncRegexBreakpoint (module_list.get(), comp_unit_list.get(), regexp, false);
677 }
678
679 if (log)
680 {
681 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (symbol_regex=\"%s\") => SBBreakpoint(%p)",
682 m_opaque_sp.get(), symbol_name_regex, sb_bp.get());
683 }
684
685 return sb_bp;
686}
Chris Lattner24943d22010-06-08 16:52:24 +0000687
688SBBreakpoint
689SBTarget::BreakpointCreateByAddress (addr_t address)
690{
Greg Claytone005f2c2010-11-06 01:53:30 +0000691 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000692
Chris Lattner24943d22010-06-08 16:52:24 +0000693 SBBreakpoint sb_bp;
Greg Clayton63094e02010-06-23 01:19:29 +0000694 if (m_opaque_sp.get())
Greg Claytonbdcda462010-12-20 20:49:23 +0000695 {
696 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
Greg Clayton63094e02010-06-23 01:19:29 +0000697 *sb_bp = m_opaque_sp->CreateBreakpoint (address, false);
Greg Claytonbdcda462010-12-20 20:49:23 +0000698 }
Caroline Tice7826c882010-10-26 03:11:13 +0000699
700 if (log)
701 {
Jason Molenda7e5fa7f2011-09-20 21:44:10 +0000702 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 +0000703 }
704
Chris Lattner24943d22010-06-08 16:52:24 +0000705 return sb_bp;
706}
707
Jim Ingham03c8ee52011-09-21 01:17:13 +0000708lldb::SBBreakpoint
709SBTarget::BreakpointCreateBySourceRegex (const char *source_regex, const lldb::SBFileSpec &source_file, const char *module_name)
710{
711 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
712
713 SBBreakpoint sb_bp;
714 if (m_opaque_sp.get() && source_regex && source_regex[0])
715 {
716 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
717 RegularExpression regexp(source_regex);
Jim Inghamd6d47972011-09-23 00:54:11 +0000718 FileSpecList source_file_spec_list;
719 source_file_spec_list.Append (source_file.ref());
Jim Ingham03c8ee52011-09-21 01:17:13 +0000720
721 if (module_name && module_name[0])
722 {
723 FileSpecList module_spec_list;
724 module_spec_list.Append (FileSpec (module_name, false));
725
Jim Inghamd6d47972011-09-23 00:54:11 +0000726 *sb_bp = m_opaque_sp->CreateSourceRegexBreakpoint (&module_spec_list, &source_file_spec_list, regexp, false);
Jim Ingham03c8ee52011-09-21 01:17:13 +0000727 }
728 else
729 {
Jim Inghamd6d47972011-09-23 00:54:11 +0000730 *sb_bp = m_opaque_sp->CreateSourceRegexBreakpoint (NULL, &source_file_spec_list, regexp, false);
Jim Ingham03c8ee52011-09-21 01:17:13 +0000731 }
732 }
733
734 if (log)
735 {
736 char path[PATH_MAX];
737 source_file->GetPath (path, sizeof(path));
738 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (source_regex=\"%s\", file=\"%s\", module_name=\"%s\") => SBBreakpoint(%p)",
Greg Claytona253c932011-09-21 06:45:51 +0000739 m_opaque_sp.get(), source_regex, path, module_name, sb_bp.get());
Jim Ingham03c8ee52011-09-21 01:17:13 +0000740 }
741
742 return sb_bp;
743}
744
Jim Inghamd6d47972011-09-23 00:54:11 +0000745lldb::SBBreakpoint
746SBTarget::BreakpointCreateBySourceRegex (const char *source_regex,
747 const SBFileSpecList &module_list,
748 const lldb::SBFileSpecList &source_file_list)
749{
750 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
751
752 SBBreakpoint sb_bp;
753 if (m_opaque_sp.get() && source_regex && source_regex[0])
754 {
755 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
756 RegularExpression regexp(source_regex);
757 *sb_bp = m_opaque_sp->CreateSourceRegexBreakpoint (module_list.get(), source_file_list.get(), regexp, false);
758 }
759
760 if (log)
761 {
762 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (source_regex=\"%s\") => SBBreakpoint(%p)",
763 m_opaque_sp.get(), source_regex, sb_bp.get());
764 }
765
766 return sb_bp;
767}
Jim Ingham03c8ee52011-09-21 01:17:13 +0000768
Chris Lattner24943d22010-06-08 16:52:24 +0000769SBBreakpoint
770SBTarget::FindBreakpointByID (break_id_t bp_id)
771{
Greg Claytone005f2c2010-11-06 01:53:30 +0000772 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000773
Chris Lattner24943d22010-06-08 16:52:24 +0000774 SBBreakpoint sb_breakpoint;
Greg Clayton63094e02010-06-23 01:19:29 +0000775 if (m_opaque_sp && bp_id != LLDB_INVALID_BREAK_ID)
Greg Claytonbdcda462010-12-20 20:49:23 +0000776 {
777 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
Greg Clayton63094e02010-06-23 01:19:29 +0000778 *sb_breakpoint = m_opaque_sp->GetBreakpointByID (bp_id);
Greg Claytonbdcda462010-12-20 20:49:23 +0000779 }
Caroline Tice7826c882010-10-26 03:11:13 +0000780
781 if (log)
782 {
Greg Clayton49ce6822010-10-31 03:01:06 +0000783 log->Printf ("SBTarget(%p)::FindBreakpointByID (bp_id=%d) => SBBreakpoint(%p)",
784 m_opaque_sp.get(), (uint32_t) bp_id, sb_breakpoint.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000785 }
786
Chris Lattner24943d22010-06-08 16:52:24 +0000787 return sb_breakpoint;
788}
789
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000790uint32_t
791SBTarget::GetNumBreakpoints () const
792{
793 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000794 {
795 // The breakpoint list is thread safe, no need to lock
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000796 return m_opaque_sp->GetBreakpointList().GetSize();
Greg Claytonbdcda462010-12-20 20:49:23 +0000797 }
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000798 return 0;
799}
800
801SBBreakpoint
802SBTarget::GetBreakpointAtIndex (uint32_t idx) const
803{
804 SBBreakpoint sb_breakpoint;
805 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000806 {
807 // The breakpoint list is thread safe, no need to lock
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000808 *sb_breakpoint = m_opaque_sp->GetBreakpointList().GetBreakpointAtIndex(idx);
Greg Claytonbdcda462010-12-20 20:49:23 +0000809 }
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000810 return sb_breakpoint;
811}
Chris Lattner24943d22010-06-08 16:52:24 +0000812
813bool
814SBTarget::BreakpointDelete (break_id_t bp_id)
815{
Greg Claytone005f2c2010-11-06 01:53:30 +0000816 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000817
Caroline Tice7826c882010-10-26 03:11:13 +0000818 bool result = false;
Greg Clayton63094e02010-06-23 01:19:29 +0000819 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000820 {
821 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
Caroline Tice7826c882010-10-26 03:11:13 +0000822 result = m_opaque_sp->RemoveBreakpointByID (bp_id);
Greg Claytonbdcda462010-12-20 20:49:23 +0000823 }
Caroline Tice7826c882010-10-26 03:11:13 +0000824
825 if (log)
826 {
Greg Clayton3f5ee7f2010-10-29 04:59:35 +0000827 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 +0000828 }
829
830 return result;
Chris Lattner24943d22010-06-08 16:52:24 +0000831}
832
833bool
834SBTarget::EnableAllBreakpoints ()
835{
Greg Clayton63094e02010-06-23 01:19:29 +0000836 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000837 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000838 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
Greg Clayton63094e02010-06-23 01:19:29 +0000839 m_opaque_sp->EnableAllBreakpoints ();
Chris Lattner24943d22010-06-08 16:52:24 +0000840 return true;
841 }
842 return false;
843}
844
845bool
846SBTarget::DisableAllBreakpoints ()
847{
Greg Clayton63094e02010-06-23 01:19:29 +0000848 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000849 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000850 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
Greg Clayton63094e02010-06-23 01:19:29 +0000851 m_opaque_sp->DisableAllBreakpoints ();
Chris Lattner24943d22010-06-08 16:52:24 +0000852 return true;
853 }
854 return false;
855}
856
857bool
858SBTarget::DeleteAllBreakpoints ()
859{
Greg Clayton63094e02010-06-23 01:19:29 +0000860 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000861 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000862 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
Greg Clayton63094e02010-06-23 01:19:29 +0000863 m_opaque_sp->RemoveAllBreakpoints ();
Chris Lattner24943d22010-06-08 16:52:24 +0000864 return true;
865 }
866 return false;
867}
868
869
Greg Clayton3e8c25f2011-09-24 00:52:29 +0000870lldb::SBModule
871SBTarget::AddModule (const char *path,
872 const char *triple,
873 const char *uuid_cstr)
874{
875 lldb::SBModule sb_module;
876 if (m_opaque_sp)
877 {
878 FileSpec module_file_spec;
879 UUID module_uuid;
880 ArchSpec module_arch;
881
882 if (path)
883 module_file_spec.SetFile(path, false);
884
885 if (uuid_cstr)
886 module_uuid.SetfromCString(uuid_cstr);
887
888 if (triple)
889 module_arch.SetTriple (triple, m_opaque_sp->GetPlatform ().get());
890
891 sb_module.SetModule(m_opaque_sp->GetSharedModule (module_file_spec,
892 module_arch,
893 uuid_cstr ? &module_uuid : NULL));
894 }
895 return sb_module;
896}
897
898bool
899SBTarget::AddModule (lldb::SBModule &module)
900{
901 if (m_opaque_sp)
902 {
903 m_opaque_sp->GetImages().AppendIfNeeded (module.get_sp());
904 return true;
905 }
906 return false;
907}
908
909lldb::SBModule
910AddModule (const char *path,
911 const char *triple,
912 const char *uuid);
913
914
915
Chris Lattner24943d22010-06-08 16:52:24 +0000916uint32_t
917SBTarget::GetNumModules () const
918{
Greg Claytone005f2c2010-11-06 01:53:30 +0000919 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000920
Caroline Tice7826c882010-10-26 03:11:13 +0000921 uint32_t num = 0;
Greg Clayton63094e02010-06-23 01:19:29 +0000922 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000923 {
924 // The module list is thread safe, no need to lock
925 num = m_opaque_sp->GetImages().GetSize();
926 }
Caroline Tice7826c882010-10-26 03:11:13 +0000927
928 if (log)
Greg Clayton3f5ee7f2010-10-29 04:59:35 +0000929 log->Printf ("SBTarget(%p)::GetNumModules () => %d", m_opaque_sp.get(), num);
Caroline Tice7826c882010-10-26 03:11:13 +0000930
931 return num;
Chris Lattner24943d22010-06-08 16:52:24 +0000932}
933
Greg Clayton43490d12010-07-30 20:12:55 +0000934void
935SBTarget::Clear ()
936{
Greg Claytone005f2c2010-11-06 01:53:30 +0000937 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000938
939 if (log)
Greg Clayton3f5ee7f2010-10-29 04:59:35 +0000940 log->Printf ("SBTarget(%p)::Clear ()", m_opaque_sp.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000941
Greg Clayton43490d12010-07-30 20:12:55 +0000942 m_opaque_sp.reset();
943}
944
945
Chris Lattner24943d22010-06-08 16:52:24 +0000946SBModule
947SBTarget::FindModule (const SBFileSpec &sb_file_spec)
948{
949 SBModule sb_module;
Greg Clayton63094e02010-06-23 01:19:29 +0000950 if (m_opaque_sp && sb_file_spec.IsValid())
Greg Claytonbdcda462010-12-20 20:49:23 +0000951 {
952 // The module list is thread safe, no need to lock
Greg Clayton24bc5d92011-03-30 18:16:51 +0000953 sb_module.SetModule (m_opaque_sp->GetImages().FindFirstModuleForFileSpec (*sb_file_spec, NULL, NULL));
Greg Claytonbdcda462010-12-20 20:49:23 +0000954 }
Chris Lattner24943d22010-06-08 16:52:24 +0000955 return sb_module;
956}
957
958SBModule
959SBTarget::GetModuleAtIndex (uint32_t idx)
960{
Greg Claytone005f2c2010-11-06 01:53:30 +0000961 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000962
Chris Lattner24943d22010-06-08 16:52:24 +0000963 SBModule sb_module;
Greg Clayton63094e02010-06-23 01:19:29 +0000964 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000965 {
966 // The module list is thread safe, no need to lock
Greg Clayton63094e02010-06-23 01:19:29 +0000967 sb_module.SetModule(m_opaque_sp->GetImages().GetModuleAtIndex(idx));
Greg Claytonbdcda462010-12-20 20:49:23 +0000968 }
Caroline Tice7826c882010-10-26 03:11:13 +0000969
970 if (log)
971 {
Greg Clayton49ce6822010-10-31 03:01:06 +0000972 log->Printf ("SBTarget(%p)::GetModuleAtIndex (idx=%d) => SBModule(%p)",
973 m_opaque_sp.get(), idx, sb_module.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000974 }
975
Chris Lattner24943d22010-06-08 16:52:24 +0000976 return sb_module;
977}
978
Greg Clayton3e8c25f2011-09-24 00:52:29 +0000979bool
980SBTarget::RemoveModule (lldb::SBModule module)
981{
982 if (m_opaque_sp)
983 return m_opaque_sp->GetImages().Remove(module.get_sp());
984 return false;
985}
986
Chris Lattner24943d22010-06-08 16:52:24 +0000987
988SBBroadcaster
989SBTarget::GetBroadcaster () const
990{
Greg Claytone005f2c2010-11-06 01:53:30 +0000991 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000992
Greg Clayton63094e02010-06-23 01:19:29 +0000993 SBBroadcaster broadcaster(m_opaque_sp.get(), false);
Caroline Tice7826c882010-10-26 03:11:13 +0000994
995 if (log)
Greg Clayton3f5ee7f2010-10-29 04:59:35 +0000996 log->Printf ("SBTarget(%p)::GetBroadcaster () => SBBroadcaster(%p)",
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000997 m_opaque_sp.get(), broadcaster.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000998
Chris Lattner24943d22010-06-08 16:52:24 +0000999 return broadcaster;
1000}
1001
Caroline Tice98f930f2010-09-20 05:20:02 +00001002
1003bool
Caroline Tice7826c882010-10-26 03:11:13 +00001004SBTarget::GetDescription (SBStream &description, lldb::DescriptionLevel description_level)
Caroline Tice98f930f2010-09-20 05:20:02 +00001005{
1006 if (m_opaque_sp)
Caroline Ticee7a566e2010-09-20 16:21:41 +00001007 {
Caroline Ticee49ec182010-09-22 23:01:29 +00001008 description.ref();
Caroline Tice7826c882010-10-26 03:11:13 +00001009 m_opaque_sp->Dump (description.get(), description_level);
1010 }
1011 else
1012 description.Printf ("No value");
1013
1014 return true;
1015}
1016
1017bool
1018SBTarget::GetDescription (SBStream &description, lldb::DescriptionLevel description_level) const
1019{
1020 if (m_opaque_sp)
1021 {
1022 description.ref();
1023 m_opaque_sp->Dump (description.get(), description_level);
Caroline Ticee7a566e2010-09-20 16:21:41 +00001024 }
Caroline Tice98f930f2010-09-20 05:20:02 +00001025 else
1026 description.Printf ("No value");
1027
1028 return true;
1029}
Greg Clayton4ed315f2011-06-21 01:34:41 +00001030
1031
1032uint32_t
1033SBTarget::FindFunctions (const char *name,
1034 uint32_t name_type_mask,
1035 bool append,
1036 lldb::SBSymbolContextList& sc_list)
1037{
1038 if (!append)
1039 sc_list.Clear();
1040 if (m_opaque_sp)
1041 {
1042 const bool symbols_ok = true;
1043 return m_opaque_sp->GetImages().FindFunctions (ConstString(name),
1044 name_type_mask,
1045 symbols_ok,
1046 append,
1047 *sc_list);
1048 }
1049 return 0;
1050}
1051
Enrico Granata979e20d2011-07-29 19:53:35 +00001052lldb::SBType
1053SBTarget::FindFirstType (const char* type)
1054{
1055 if (m_opaque_sp)
1056 {
1057 size_t count = m_opaque_sp->GetImages().GetSize();
1058 for (size_t idx = 0; idx < count; idx++)
1059 {
1060 SBType found_at_idx = GetModuleAtIndex(idx).FindFirstType(type);
1061
1062 if (found_at_idx.IsValid())
1063 return found_at_idx;
1064 }
1065 }
1066 return SBType();
1067}
1068
1069lldb::SBTypeList
1070SBTarget::FindTypes (const char* type)
1071{
1072
1073 SBTypeList retval;
1074
1075 if (m_opaque_sp)
1076 {
1077 ModuleList& images = m_opaque_sp->GetImages();
1078 ConstString name_const(type);
1079 SymbolContext sc;
1080 TypeList type_list;
1081
1082 uint32_t num_matches = images.FindTypes(sc,
1083 name_const,
1084 true,
1085 UINT32_MAX,
1086 type_list);
1087
1088 for (size_t idx = 0; idx < num_matches; idx++)
1089 {
Greg Clayton0fb0bcc2011-08-03 22:57:10 +00001090 TypeSP type_sp (type_list.GetTypeAtIndex(idx));
1091 if (type_sp)
1092 retval.Append(SBType(type_sp));
Enrico Granata979e20d2011-07-29 19:53:35 +00001093 }
1094 }
1095 return retval;
1096}
1097
Greg Clayton917c0002011-06-29 22:09:02 +00001098SBValueList
1099SBTarget::FindGlobalVariables (const char *name, uint32_t max_matches)
1100{
1101 SBValueList sb_value_list;
1102
1103 if (m_opaque_sp)
1104 {
1105 VariableList variable_list;
1106 const bool append = true;
1107 const uint32_t match_count = m_opaque_sp->GetImages().FindGlobalVariables (ConstString (name),
1108 append,
1109 max_matches,
1110 variable_list);
1111
1112 if (match_count > 0)
1113 {
1114 ExecutionContextScope *exe_scope = m_opaque_sp->GetProcessSP().get();
1115 if (exe_scope == NULL)
1116 exe_scope = m_opaque_sp.get();
1117 ValueObjectList &value_object_list = sb_value_list.ref();
1118 for (uint32_t i=0; i<match_count; ++i)
1119 {
1120 lldb::ValueObjectSP valobj_sp (ValueObjectVariable::Create (exe_scope, variable_list.GetVariableAtIndex(i)));
1121 if (valobj_sp)
1122 value_object_list.Append(valobj_sp);
1123 }
1124 }
1125 }
1126
1127 return sb_value_list;
1128}
1129
Jim Inghamcc637462011-09-13 00:29:56 +00001130SBSourceManager
1131SBTarget::GetSourceManager()
1132{
1133 SBSourceManager source_manager (*this);
1134 return source_manager;
1135}
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001136
1137
1138SBError
1139SBTarget::SetSectionLoadAddress (lldb::SBSection section,
1140 lldb::addr_t section_base_addr)
1141{
1142 SBError sb_error;
1143
1144 if (IsValid())
1145 {
1146 if (!section.IsValid())
1147 {
1148 sb_error.SetErrorStringWithFormat ("invalid section");
1149 }
1150 else
1151 {
1152 m_opaque_sp->GetSectionLoadList().SetSectionLoadAddress (section.GetSection(), section_base_addr);
1153 }
1154 }
1155 else
1156 {
1157 sb_error.SetErrorStringWithFormat ("invalid target");
1158 }
1159 return sb_error;
1160}
1161
1162SBError
1163SBTarget::ClearSectionLoadAddress (lldb::SBSection section)
1164{
1165 SBError sb_error;
1166
1167 if (IsValid())
1168 {
1169 if (!section.IsValid())
1170 {
1171 sb_error.SetErrorStringWithFormat ("invalid section");
1172 }
1173 else
1174 {
1175 m_opaque_sp->GetSectionLoadList().SetSectionUnloaded (section.GetSection());
1176 }
1177 }
1178 else
1179 {
1180 sb_error.SetErrorStringWithFormat ("invalid target");
1181 }
1182 return sb_error;
1183}
1184
1185SBError
1186SBTarget::SetModuleLoadAddress (lldb::SBModule module, int64_t slide_offset)
1187{
1188 SBError sb_error;
1189
1190 char path[PATH_MAX];
1191 if (IsValid())
1192 {
1193 if (!module.IsValid())
1194 {
1195 sb_error.SetErrorStringWithFormat ("invalid module");
1196 }
1197 else
1198 {
1199 ObjectFile *objfile = module->GetObjectFile();
1200 if (objfile)
1201 {
1202 SectionList *section_list = objfile->GetSectionList();
1203 if (section_list)
1204 {
1205 const size_t num_sections = section_list->GetSize();
1206 for (size_t sect_idx = 0; sect_idx < num_sections; ++sect_idx)
1207 {
1208 SectionSP section_sp (section_list->GetSectionAtIndex(sect_idx));
1209 if (section_sp)
1210 m_opaque_sp->GetSectionLoadList().SetSectionLoadAddress (section_sp.get(), section_sp->GetFileAddress() + slide_offset);
1211 }
1212 }
1213 else
1214 {
1215 module->GetFileSpec().GetPath (path, sizeof(path));
1216 sb_error.SetErrorStringWithFormat ("no sections in object file '%s'", path);
1217 }
1218 }
1219 else
1220 {
1221 module->GetFileSpec().GetPath (path, sizeof(path));
1222 sb_error.SetErrorStringWithFormat ("no object file for module '%s'", path);
1223 }
1224 }
1225 }
1226 else
1227 {
1228 sb_error.SetErrorStringWithFormat ("invalid target");
1229 }
1230 return sb_error;
1231}
1232
1233SBError
1234SBTarget::ClearModuleLoadAddress (lldb::SBModule module)
1235{
1236 SBError sb_error;
1237
1238 char path[PATH_MAX];
1239 if (IsValid())
1240 {
1241 if (!module.IsValid())
1242 {
1243 sb_error.SetErrorStringWithFormat ("invalid module");
1244 }
1245 else
1246 {
1247 ObjectFile *objfile = module->GetObjectFile();
1248 if (objfile)
1249 {
1250 SectionList *section_list = objfile->GetSectionList();
1251 if (section_list)
1252 {
1253 const size_t num_sections = section_list->GetSize();
1254 for (size_t sect_idx = 0; sect_idx < num_sections; ++sect_idx)
1255 {
1256 SectionSP section_sp (section_list->GetSectionAtIndex(sect_idx));
1257 if (section_sp)
1258 m_opaque_sp->GetSectionLoadList().SetSectionUnloaded (section_sp.get());
1259 }
1260 }
1261 else
1262 {
1263 module->GetFileSpec().GetPath (path, sizeof(path));
1264 sb_error.SetErrorStringWithFormat ("no sections in object file '%s'", path);
1265 }
1266 }
1267 else
1268 {
1269 module->GetFileSpec().GetPath (path, sizeof(path));
1270 sb_error.SetErrorStringWithFormat ("no object file for module '%s'", path);
1271 }
1272 }
1273 }
1274 else
1275 {
1276 sb_error.SetErrorStringWithFormat ("invalid target");
1277 }
1278 return sb_error;
1279}
1280
1281