blob: a54a15ec936e917d9393f3b1d52b8f50e1a2b4f7 [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
14#include "lldb/API/SBFileSpec.h"
15#include "lldb/API/SBModule.h"
Caroline Tice98f930f2010-09-20 05:20:02 +000016#include "lldb/API/SBStream.h"
Chris Lattner24943d22010-06-08 16:52:24 +000017#include "lldb/Breakpoint/BreakpointID.h"
18#include "lldb/Breakpoint/BreakpointIDList.h"
19#include "lldb/Breakpoint/BreakpointList.h"
20#include "lldb/Breakpoint/BreakpointLocation.h"
21#include "lldb/Core/Address.h"
22#include "lldb/Core/AddressResolver.h"
23#include "lldb/Core/AddressResolverName.h"
Jim Ingham84cdc152010-06-15 19:49:27 +000024#include "lldb/Interpreter/Args.h"
Chris Lattner24943d22010-06-08 16:52:24 +000025#include "lldb/Core/ArchSpec.h"
26#include "lldb/Core/Debugger.h"
27#include "lldb/Core/Disassembler.h"
Greg Clayton5f54ac32011-02-08 05:05:52 +000028#include "lldb/Host/FileSpec.h"
Caroline Tice7826c882010-10-26 03:11:13 +000029#include "lldb/Core/Log.h"
Chris Lattner24943d22010-06-08 16:52:24 +000030#include "lldb/Core/RegularExpression.h"
31#include "lldb/Core/SearchFilter.h"
32#include "lldb/Core/STLUtils.h"
Greg Claytoncd548032011-02-01 01:31:41 +000033#include "lldb/Host/Host.h"
Chris Lattner24943d22010-06-08 16:52:24 +000034#include "lldb/Target/Process.h"
35#include "lldb/Target/Target.h"
36#include "lldb/Target/TargetList.h"
37
38#include "lldb/Interpreter/CommandReturnObject.h"
39#include "../source/Commands/CommandObjectBreakpoint.h"
40
Eli Friedman7a62c8b2010-06-09 07:44:37 +000041#include "lldb/API/SBDebugger.h"
42#include "lldb/API/SBProcess.h"
43#include "lldb/API/SBListener.h"
44#include "lldb/API/SBBreakpoint.h"
Chris Lattner24943d22010-06-08 16:52:24 +000045
46using namespace lldb;
47using namespace lldb_private;
48
49#define DEFAULT_DISASM_BYTE_SIZE 32
50
51//----------------------------------------------------------------------
52// SBTarget constructor
53//----------------------------------------------------------------------
Greg Claytonc3b61d22010-12-15 05:08:08 +000054SBTarget::SBTarget () :
55 m_opaque_sp ()
Chris Lattner24943d22010-06-08 16:52:24 +000056{
57}
58
59SBTarget::SBTarget (const SBTarget& rhs) :
Greg Clayton63094e02010-06-23 01:19:29 +000060 m_opaque_sp (rhs.m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +000061{
62}
63
64SBTarget::SBTarget(const TargetSP& target_sp) :
Greg Clayton63094e02010-06-23 01:19:29 +000065 m_opaque_sp (target_sp)
Chris Lattner24943d22010-06-08 16:52:24 +000066{
67}
68
Greg Clayton538eb822010-11-05 23:17:00 +000069const SBTarget&
70SBTarget::operator = (const SBTarget& rhs)
71{
72 if (this != &rhs)
73 m_opaque_sp = rhs.m_opaque_sp;
74 return *this;
75}
76
Chris Lattner24943d22010-06-08 16:52:24 +000077//----------------------------------------------------------------------
78// Destructor
79//----------------------------------------------------------------------
80SBTarget::~SBTarget()
81{
82}
83
84bool
85SBTarget::IsValid () const
86{
Greg Clayton63094e02010-06-23 01:19:29 +000087 return m_opaque_sp.get() != NULL;
Chris Lattner24943d22010-06-08 16:52:24 +000088}
89
90SBProcess
91SBTarget::GetProcess ()
92{
Caroline Tice7826c882010-10-26 03:11:13 +000093
Chris Lattner24943d22010-06-08 16:52:24 +000094 SBProcess sb_process;
Greg Clayton63094e02010-06-23 01:19:29 +000095 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +000096 {
97 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
Greg Clayton63094e02010-06-23 01:19:29 +000098 sb_process.SetProcess (m_opaque_sp->GetProcessSP());
Greg Claytonbdcda462010-12-20 20:49:23 +000099 }
Caroline Tice7826c882010-10-26 03:11:13 +0000100
Greg Claytone005f2c2010-11-06 01:53:30 +0000101 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000102 if (log)
103 {
Greg Clayton49ce6822010-10-31 03:01:06 +0000104 log->Printf ("SBTarget(%p)::GetProcess () => SBProcess(%p)",
105 m_opaque_sp.get(), sb_process.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000106 }
107
Chris Lattner24943d22010-06-08 16:52:24 +0000108 return sb_process;
109}
110
Greg Clayton63094e02010-06-23 01:19:29 +0000111SBDebugger
112SBTarget::GetDebugger () const
113{
114 SBDebugger debugger;
115 if (m_opaque_sp)
116 debugger.reset (m_opaque_sp->GetDebugger().GetSP());
117 return debugger;
118}
119
Jim Inghamb5871fe2011-03-31 00:01:24 +0000120SBProcess
121SBTarget::LaunchSimple
122(
123 char const **argv,
124 char const **envp,
125 const char *working_directory
126)
127{
128 char *stdin_path = NULL;
129 char *stdout_path = NULL;
130 char *stderr_path = NULL;
131 uint32_t launch_flags = 0;
132 bool stop_at_entry = false;
133 SBError error;
134 SBListener listener = GetDebugger().GetListener();
135 return Launch (listener,
136 argv,
137 envp,
138 stdin_path,
139 stdout_path,
140 stderr_path,
141 working_directory,
142 launch_flags,
143 stop_at_entry,
144 error);
145}
Greg Claytonde915be2011-01-23 05:56:20 +0000146
147SBProcess
148SBTarget::Launch
149(
Greg Clayton271a5db2011-02-03 21:28:34 +0000150 SBListener &listener,
Greg Claytonde915be2011-01-23 05:56:20 +0000151 char const **argv,
152 char const **envp,
153 const char *stdin_path,
154 const char *stdout_path,
155 const char *stderr_path,
156 const char *working_directory,
157 uint32_t launch_flags, // See LaunchFlags
158 bool stop_at_entry,
159 lldb::SBError& error
160)
161{
Greg Claytone005f2c2010-11-06 01:53:30 +0000162 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000163
164 if (log)
Greg Clayton3f5ee7f2010-10-29 04:59:35 +0000165 {
Greg Claytonde915be2011-01-23 05:56:20 +0000166 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))...",
167 m_opaque_sp.get(),
168 argv,
169 envp,
170 stdin_path ? stdin_path : "NULL",
171 stdout_path ? stdout_path : "NULL",
172 stderr_path ? stderr_path : "NULL",
173 working_directory ? working_directory : "NULL",
174 launch_flags,
175 stop_at_entry,
176 error.get());
Greg Clayton3f5ee7f2010-10-29 04:59:35 +0000177 }
Greg Clayton1a3083a2010-10-06 03:53:16 +0000178 SBProcess sb_process;
179 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000180 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000181 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
Greg Clayton1a3083a2010-10-06 03:53:16 +0000182
Greg Clayton7c330d62011-01-27 01:01:10 +0000183 if (getenv("LLDB_LAUNCH_FLAG_DISABLE_ASLR"))
184 launch_flags |= eLaunchFlagDisableASLR;
185
Greg Clayton28d5fcc2011-01-27 06:44:37 +0000186 static const char *g_launch_tty = NULL;
187 static bool g_got_launch_tty = false;
188 if (!g_got_launch_tty)
189 {
190 // Get the LLDB_LAUNCH_FLAG_LAUNCH_IN_TTY only once
191 g_got_launch_tty = true;
192 g_launch_tty = ::getenv ("LLDB_LAUNCH_FLAG_LAUNCH_IN_TTY");
193 if (g_launch_tty)
194 {
195 // LLDB_LAUNCH_FLAG_LAUNCH_IN_TTY is a path to a terminal to reuse
196 // if the first character is '/', else it is a boolean value.
197 if (g_launch_tty[0] != '/')
198 {
199 if (Args::StringToBoolean(g_launch_tty, false, NULL))
200 g_launch_tty = "";
201 else
202 g_launch_tty = NULL;
203 }
204 }
205 }
206
207 if ((launch_flags & eLaunchFlagLaunchInTTY) || g_launch_tty)
Chris Lattner24943d22010-06-08 16:52:24 +0000208 {
Greg Clayton7c330d62011-01-27 01:01:10 +0000209 ArchSpec arch (m_opaque_sp->GetArchitecture ());
210
211 Module *exe_module = m_opaque_sp->GetExecutableModule().get();
212 if (exe_module)
Chris Lattner24943d22010-06-08 16:52:24 +0000213 {
Greg Clayton7c330d62011-01-27 01:01:10 +0000214 char exec_file_path[PATH_MAX];
215 exe_module->GetFileSpec().GetPath(exec_file_path, sizeof(exec_file_path));
216 if (exe_module->GetFileSpec().Exists())
Greg Clayton1a3083a2010-10-06 03:53:16 +0000217 {
Greg Clayton7c330d62011-01-27 01:01:10 +0000218 // Make a new argument vector
219 std::vector<const char *> exec_path_plus_argv;
220 // Append the resolved executable path
221 exec_path_plus_argv.push_back (exec_file_path);
222
223 // Push all args if there are any
224 if (argv)
Greg Clayton1a3083a2010-10-06 03:53:16 +0000225 {
Greg Clayton7c330d62011-01-27 01:01:10 +0000226 for (int i = 0; argv[i]; ++i)
227 exec_path_plus_argv.push_back(argv[i]);
228 }
229
230 // Push a NULL to terminate the args.
231 exec_path_plus_argv.push_back(NULL);
232
233
Greg Clayton28d5fcc2011-01-27 06:44:37 +0000234 const char *tty_name = NULL;
235 if (g_launch_tty && g_launch_tty[0] == '/')
236 tty_name = g_launch_tty;
237
238 lldb::pid_t pid = Host::LaunchInNewTerminal (tty_name,
239 &exec_path_plus_argv[0],
240 envp,
241 working_directory,
242 &arch,
243 true,
244 launch_flags & eLaunchFlagDisableASLR);
245
Greg Clayton7c330d62011-01-27 01:01:10 +0000246 if (pid != LLDB_INVALID_PROCESS_ID)
247 {
Greg Clayton271a5db2011-02-03 21:28:34 +0000248 sb_process = AttachToProcessWithID(listener, pid, error);
Greg Clayton7c330d62011-01-27 01:01:10 +0000249 }
250 else
251 {
252 error.SetErrorStringWithFormat("failed to launch process in terminal");
Greg Clayton1a3083a2010-10-06 03:53:16 +0000253 }
254 }
Greg Clayton7c330d62011-01-27 01:01:10 +0000255 else
256 {
257 error.SetErrorStringWithFormat("executable doesn't exist: \"%s\"", exec_file_path);
258 }
259 }
260 else
261 {
262 error.SetErrorStringWithFormat("invalid executable");
Chris Lattner24943d22010-06-08 16:52:24 +0000263 }
264 }
Greg Claytonc5f728c2010-10-06 22:10:17 +0000265 else
266 {
Greg Clayton271a5db2011-02-03 21:28:34 +0000267 if (listener.IsValid())
268 sb_process.SetProcess (m_opaque_sp->CreateProcess (listener.ref()));
269 else
270 sb_process.SetProcess (m_opaque_sp->CreateProcess (m_opaque_sp->GetDebugger().GetListener()));
Greg Clayton7c330d62011-01-27 01:01:10 +0000271
272 if (sb_process.IsValid())
273 {
274
275 if (getenv("LLDB_LAUNCH_FLAG_DISABLE_STDIO"))
276 launch_flags |= eLaunchFlagDisableSTDIO;
277
278
279 error.SetError (sb_process->Launch (argv, envp, launch_flags, stdin_path, stdout_path, stderr_path, working_directory));
280 if (error.Success())
281 {
282 // We we are stopping at the entry point, we can return now!
283 if (stop_at_entry)
284 return sb_process;
285
286 // Make sure we are stopped at the entry
287 StateType state = sb_process->WaitForProcessToStop (NULL);
288 if (state == eStateStopped)
289 {
290 // resume the process to skip the entry point
291 error.SetError (sb_process->Resume());
292 if (error.Success())
293 {
294 // If we are doing synchronous mode, then wait for the
295 // process to stop yet again!
296 if (m_opaque_sp->GetDebugger().GetAsyncExecution () == false)
297 sb_process->WaitForProcessToStop (NULL);
298 }
299 }
300 }
301 }
302 else
303 {
304 error.SetErrorString ("unable to create lldb_private::Process");
305 }
Greg Claytonc5f728c2010-10-06 22:10:17 +0000306 }
307 }
308 else
309 {
310 error.SetErrorString ("SBTarget is invalid");
Chris Lattner24943d22010-06-08 16:52:24 +0000311 }
Caroline Tice7826c882010-10-26 03:11:13 +0000312
Caroline Tice926060e2010-10-29 21:48:37 +0000313 log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
Caroline Tice7826c882010-10-26 03:11:13 +0000314 if (log)
315 {
Greg Clayton49ce6822010-10-31 03:01:06 +0000316 log->Printf ("SBTarget(%p)::Launch (...) => SBProceess(%p)",
317 m_opaque_sp.get(), sb_process.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000318 }
319
Greg Clayton1a3083a2010-10-06 03:53:16 +0000320 return sb_process;
Chris Lattner24943d22010-06-08 16:52:24 +0000321}
322
Greg Claytonc5f728c2010-10-06 22:10:17 +0000323
324lldb::SBProcess
Greg Claytond8c62532010-10-07 04:19:01 +0000325SBTarget::AttachToProcessWithID
Greg Claytonc5f728c2010-10-06 22:10:17 +0000326(
Greg Clayton271a5db2011-02-03 21:28:34 +0000327 SBListener &listener,
Greg Claytonc5f728c2010-10-06 22:10:17 +0000328 lldb::pid_t pid,// The process ID to attach to
329 SBError& error // An error explaining what went wrong if attach fails
330)
331{
332 SBProcess sb_process;
333 if (m_opaque_sp)
334 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000335 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
Greg Clayton271a5db2011-02-03 21:28:34 +0000336 if (listener.IsValid())
337 sb_process.SetProcess (m_opaque_sp->CreateProcess (listener.ref()));
338 else
339 sb_process.SetProcess (m_opaque_sp->CreateProcess (m_opaque_sp->GetDebugger().GetListener()));
340
Greg Claytonc5f728c2010-10-06 22:10:17 +0000341
342 if (sb_process.IsValid())
343 {
344 error.SetError (sb_process->Attach (pid));
345 }
346 else
347 {
348 error.SetErrorString ("unable to create lldb_private::Process");
349 }
350 }
351 else
352 {
353 error.SetErrorString ("SBTarget is invalid");
354 }
355 return sb_process;
356
357}
358
359lldb::SBProcess
Greg Claytond8c62532010-10-07 04:19:01 +0000360SBTarget::AttachToProcessWithName
Greg Claytonc5f728c2010-10-06 22:10:17 +0000361(
Greg Clayton271a5db2011-02-03 21:28:34 +0000362 SBListener &listener,
Greg Claytonc5f728c2010-10-06 22:10:17 +0000363 const char *name, // basename of process to attach to
364 bool wait_for, // if true wait for a new instance of "name" to be launched
365 SBError& error // An error explaining what went wrong if attach fails
366)
367{
368 SBProcess sb_process;
369 if (m_opaque_sp)
370 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000371 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
372
Greg Clayton271a5db2011-02-03 21:28:34 +0000373 if (listener.IsValid())
374 sb_process.SetProcess (m_opaque_sp->CreateProcess (listener.ref()));
375 else
376 sb_process.SetProcess (m_opaque_sp->CreateProcess (m_opaque_sp->GetDebugger().GetListener()));
Greg Claytonc5f728c2010-10-06 22:10:17 +0000377
378 if (sb_process.IsValid())
379 {
380 error.SetError (sb_process->Attach (name, wait_for));
381 }
382 else
383 {
384 error.SetErrorString ("unable to create lldb_private::Process");
385 }
386 }
387 else
388 {
389 error.SetErrorString ("SBTarget is invalid");
390 }
391 return sb_process;
392
393}
394
James McIlree38093402011-03-04 00:31:13 +0000395lldb::SBProcess
396SBTarget::ConnectRemote
397(
398 SBListener &listener,
399 const char *url,
400 const char *plugin_name,
401 SBError& error
402)
403{
404 SBProcess sb_process;
405 if (m_opaque_sp)
406 {
407 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
408 if (listener.IsValid())
409 sb_process.SetProcess (m_opaque_sp->CreateProcess (listener.ref(), plugin_name));
410 else
411 sb_process.SetProcess (m_opaque_sp->CreateProcess (m_opaque_sp->GetDebugger().GetListener(), plugin_name));
412
413
414 if (sb_process.IsValid())
415 {
416 error.SetError (sb_process->ConnectRemote (url));
417 }
418 else
419 {
420 error.SetErrorString ("unable to create lldb_private::Process");
421 }
422 }
423 else
424 {
425 error.SetErrorString ("SBTarget is invalid");
426 }
427 return sb_process;
428}
429
Chris Lattner24943d22010-06-08 16:52:24 +0000430SBFileSpec
431SBTarget::GetExecutable ()
432{
Caroline Tice7826c882010-10-26 03:11:13 +0000433
Chris Lattner24943d22010-06-08 16:52:24 +0000434 SBFileSpec exe_file_spec;
Greg Clayton63094e02010-06-23 01:19:29 +0000435 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000436 {
Greg Clayton63094e02010-06-23 01:19:29 +0000437 ModuleSP exe_module_sp (m_opaque_sp->GetExecutableModule ());
Chris Lattner24943d22010-06-08 16:52:24 +0000438 if (exe_module_sp)
439 exe_file_spec.SetFileSpec (exe_module_sp->GetFileSpec());
440 }
Caroline Tice7826c882010-10-26 03:11:13 +0000441
Greg Claytone005f2c2010-11-06 01:53:30 +0000442 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000443 if (log)
444 {
Greg Clayton49ce6822010-10-31 03:01:06 +0000445 log->Printf ("SBTarget(%p)::GetExecutable () => SBFileSpec(%p)",
446 m_opaque_sp.get(), exe_file_spec.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000447 }
448
Chris Lattner24943d22010-06-08 16:52:24 +0000449 return exe_file_spec;
450}
451
452
453bool
454SBTarget::DeleteTargetFromList (TargetList *list)
455{
Greg Clayton63094e02010-06-23 01:19:29 +0000456 if (m_opaque_sp)
457 return list->DeleteTarget (m_opaque_sp);
Chris Lattner24943d22010-06-08 16:52:24 +0000458 else
459 return false;
460}
461
462bool
Chris Lattner24943d22010-06-08 16:52:24 +0000463SBTarget::operator == (const SBTarget &rhs) const
464{
Greg Clayton63094e02010-06-23 01:19:29 +0000465 return m_opaque_sp.get() == rhs.m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000466}
467
468bool
469SBTarget::operator != (const SBTarget &rhs) const
470{
Greg Clayton63094e02010-06-23 01:19:29 +0000471 return m_opaque_sp.get() != rhs.m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000472}
473
474lldb_private::Target *
Greg Clayton63094e02010-06-23 01:19:29 +0000475SBTarget::operator ->() const
Chris Lattner24943d22010-06-08 16:52:24 +0000476{
Greg Clayton63094e02010-06-23 01:19:29 +0000477 return m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000478}
Greg Clayton63094e02010-06-23 01:19:29 +0000479
480lldb_private::Target *
481SBTarget::get() const
Chris Lattner24943d22010-06-08 16:52:24 +0000482{
Greg Clayton63094e02010-06-23 01:19:29 +0000483 return m_opaque_sp.get();
484}
485
486void
487SBTarget::reset (const lldb::TargetSP& target_sp)
488{
489 m_opaque_sp = target_sp;
Chris Lattner24943d22010-06-08 16:52:24 +0000490}
491
Greg Claytonea49cc72010-12-12 19:25:26 +0000492bool
493SBTarget::ResolveLoadAddress (lldb::addr_t vm_addr,
494 lldb::SBAddress& addr)
495{
496 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000497 {
498 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
Greg Claytonea49cc72010-12-12 19:25:26 +0000499 return m_opaque_sp->GetSectionLoadList().ResolveLoadAddress (vm_addr, *addr);
Greg Claytonbdcda462010-12-20 20:49:23 +0000500 }
Greg Claytonea49cc72010-12-12 19:25:26 +0000501
502 addr->Clear();
503 return false;
504}
505
Greg Claytonafb81862011-03-02 21:34:46 +0000506SBSymbolContext
507SBTarget::ResolveSymbolContextForAddress (const SBAddress& addr, uint32_t resolve_scope)
508{
509 SBSymbolContext sc;
510 if (m_opaque_sp)
511 m_opaque_sp->GetImages().ResolveSymbolContextForAddress (*addr, resolve_scope, sc.ref());
512 return sc;
513}
514
515
Chris Lattner24943d22010-06-08 16:52:24 +0000516SBBreakpoint
517SBTarget::BreakpointCreateByLocation (const char *file, uint32_t line)
518{
Greg Claytond6d806c2010-11-08 00:28:40 +0000519 return SBBreakpoint(BreakpointCreateByLocation (SBFileSpec (file, false), line));
Chris Lattner24943d22010-06-08 16:52:24 +0000520}
521
522SBBreakpoint
523SBTarget::BreakpointCreateByLocation (const SBFileSpec &sb_file_spec, uint32_t line)
524{
Greg Claytone005f2c2010-11-06 01:53:30 +0000525 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000526
Chris Lattner24943d22010-06-08 16:52:24 +0000527 SBBreakpoint sb_bp;
Greg Clayton63094e02010-06-23 01:19:29 +0000528 if (m_opaque_sp.get() && line != 0)
Greg Claytonbdcda462010-12-20 20:49:23 +0000529 {
530 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
Greg Clayton63094e02010-06-23 01:19:29 +0000531 *sb_bp = m_opaque_sp->CreateBreakpoint (NULL, *sb_file_spec, line, true, false);
Greg Claytonbdcda462010-12-20 20:49:23 +0000532 }
Caroline Tice7826c882010-10-26 03:11:13 +0000533
534 if (log)
535 {
536 SBStream sstr;
537 sb_bp.GetDescription (sstr);
Greg Clayton49ce6822010-10-31 03:01:06 +0000538 char path[PATH_MAX];
539 sb_file_spec->GetPath (path, sizeof(path));
540 log->Printf ("SBTarget(%p)::BreakpointCreateByLocation ( %s:%u ) => SBBreakpoint(%p): %s",
Greg Claytona66ba462010-10-30 04:51:46 +0000541 m_opaque_sp.get(),
Greg Clayton49ce6822010-10-31 03:01:06 +0000542 path,
Greg Claytona66ba462010-10-30 04:51:46 +0000543 line,
Greg Clayton49ce6822010-10-31 03:01:06 +0000544 sb_bp.get(),
Caroline Tice7826c882010-10-26 03:11:13 +0000545 sstr.GetData());
546 }
547
Chris Lattner24943d22010-06-08 16:52:24 +0000548 return sb_bp;
549}
550
551SBBreakpoint
552SBTarget::BreakpointCreateByName (const char *symbol_name, const char *module_name)
553{
Greg Claytone005f2c2010-11-06 01:53:30 +0000554 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000555
Chris Lattner24943d22010-06-08 16:52:24 +0000556 SBBreakpoint sb_bp;
Greg Clayton63094e02010-06-23 01:19:29 +0000557 if (m_opaque_sp.get() && symbol_name && symbol_name[0])
Chris Lattner24943d22010-06-08 16:52:24 +0000558 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000559 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
Chris Lattner24943d22010-06-08 16:52:24 +0000560 if (module_name && module_name[0])
561 {
Greg Clayton537a7a82010-10-20 20:54:39 +0000562 FileSpec module_file_spec(module_name, false);
Jim Ingham7ec03bd2010-09-30 21:21:43 +0000563 *sb_bp = m_opaque_sp->CreateBreakpoint (&module_file_spec, symbol_name, eFunctionNameTypeFull | eFunctionNameTypeBase, false);
Chris Lattner24943d22010-06-08 16:52:24 +0000564 }
565 else
566 {
Jim Ingham7ec03bd2010-09-30 21:21:43 +0000567 *sb_bp = m_opaque_sp->CreateBreakpoint (NULL, symbol_name, eFunctionNameTypeFull | eFunctionNameTypeBase, false);
Chris Lattner24943d22010-06-08 16:52:24 +0000568 }
569 }
Caroline Tice7826c882010-10-26 03:11:13 +0000570
571 if (log)
572 {
Greg Clayton49ce6822010-10-31 03:01:06 +0000573 log->Printf ("SBTarget(%p)::BreakpointCreateByName (symbol=\"%s\", module=\"%s\") => SBBreakpoint(%p)",
574 m_opaque_sp.get(), symbol_name, module_name, sb_bp.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000575 }
576
Chris Lattner24943d22010-06-08 16:52:24 +0000577 return sb_bp;
578}
579
580SBBreakpoint
581SBTarget::BreakpointCreateByRegex (const char *symbol_name_regex, const char *module_name)
582{
Greg Claytone005f2c2010-11-06 01:53:30 +0000583 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000584
Chris Lattner24943d22010-06-08 16:52:24 +0000585 SBBreakpoint sb_bp;
Greg Clayton63094e02010-06-23 01:19:29 +0000586 if (m_opaque_sp.get() && symbol_name_regex && symbol_name_regex[0])
Chris Lattner24943d22010-06-08 16:52:24 +0000587 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000588 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
Chris Lattner24943d22010-06-08 16:52:24 +0000589 RegularExpression regexp(symbol_name_regex);
590
591 if (module_name && module_name[0])
592 {
Greg Clayton537a7a82010-10-20 20:54:39 +0000593 FileSpec module_file_spec(module_name, false);
Chris Lattner24943d22010-06-08 16:52:24 +0000594
Greg Clayton63094e02010-06-23 01:19:29 +0000595 *sb_bp = m_opaque_sp->CreateBreakpoint (&module_file_spec, regexp, false);
Chris Lattner24943d22010-06-08 16:52:24 +0000596 }
597 else
598 {
Greg Clayton63094e02010-06-23 01:19:29 +0000599 *sb_bp = m_opaque_sp->CreateBreakpoint (NULL, regexp, false);
Chris Lattner24943d22010-06-08 16:52:24 +0000600 }
601 }
Caroline Tice7826c882010-10-26 03:11:13 +0000602
603 if (log)
604 {
Greg Clayton49ce6822010-10-31 03:01:06 +0000605 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (symbol_regex=\"%s\", module_name=\"%s\") => SBBreakpoint(%p)",
606 m_opaque_sp.get(), symbol_name_regex, module_name, sb_bp.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000607 }
608
Chris Lattner24943d22010-06-08 16:52:24 +0000609 return sb_bp;
610}
611
612
613
614SBBreakpoint
615SBTarget::BreakpointCreateByAddress (addr_t address)
616{
Greg Claytone005f2c2010-11-06 01:53:30 +0000617 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000618
Chris Lattner24943d22010-06-08 16:52:24 +0000619 SBBreakpoint sb_bp;
Greg Clayton63094e02010-06-23 01:19:29 +0000620 if (m_opaque_sp.get())
Greg Claytonbdcda462010-12-20 20:49:23 +0000621 {
622 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
Greg Clayton63094e02010-06-23 01:19:29 +0000623 *sb_bp = m_opaque_sp->CreateBreakpoint (address, false);
Greg Claytonbdcda462010-12-20 20:49:23 +0000624 }
Caroline Tice7826c882010-10-26 03:11:13 +0000625
626 if (log)
627 {
Greg Clayton49ce6822010-10-31 03:01:06 +0000628 log->Printf ("SBTarget(%p)::BreakpointCreateByAddress (%p, address=%p) => SBBreakpoint(%p)", m_opaque_sp.get(), address, 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
Chris Lattner24943d22010-06-08 16:52:24 +0000634SBBreakpoint
635SBTarget::FindBreakpointByID (break_id_t bp_id)
636{
Greg Claytone005f2c2010-11-06 01:53:30 +0000637 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000638
Chris Lattner24943d22010-06-08 16:52:24 +0000639 SBBreakpoint sb_breakpoint;
Greg Clayton63094e02010-06-23 01:19:29 +0000640 if (m_opaque_sp && bp_id != LLDB_INVALID_BREAK_ID)
Greg Claytonbdcda462010-12-20 20:49:23 +0000641 {
642 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
Greg Clayton63094e02010-06-23 01:19:29 +0000643 *sb_breakpoint = m_opaque_sp->GetBreakpointByID (bp_id);
Greg Claytonbdcda462010-12-20 20:49:23 +0000644 }
Caroline Tice7826c882010-10-26 03:11:13 +0000645
646 if (log)
647 {
Greg Clayton49ce6822010-10-31 03:01:06 +0000648 log->Printf ("SBTarget(%p)::FindBreakpointByID (bp_id=%d) => SBBreakpoint(%p)",
649 m_opaque_sp.get(), (uint32_t) bp_id, sb_breakpoint.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000650 }
651
Chris Lattner24943d22010-06-08 16:52:24 +0000652 return sb_breakpoint;
653}
654
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000655uint32_t
656SBTarget::GetNumBreakpoints () const
657{
658 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000659 {
660 // The breakpoint list is thread safe, no need to lock
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000661 return m_opaque_sp->GetBreakpointList().GetSize();
Greg Claytonbdcda462010-12-20 20:49:23 +0000662 }
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000663 return 0;
664}
665
666SBBreakpoint
667SBTarget::GetBreakpointAtIndex (uint32_t idx) const
668{
669 SBBreakpoint sb_breakpoint;
670 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000671 {
672 // The breakpoint list is thread safe, no need to lock
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000673 *sb_breakpoint = m_opaque_sp->GetBreakpointList().GetBreakpointAtIndex(idx);
Greg Claytonbdcda462010-12-20 20:49:23 +0000674 }
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000675 return sb_breakpoint;
676}
Chris Lattner24943d22010-06-08 16:52:24 +0000677
678bool
679SBTarget::BreakpointDelete (break_id_t bp_id)
680{
Greg Claytone005f2c2010-11-06 01:53:30 +0000681 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000682
Caroline Tice7826c882010-10-26 03:11:13 +0000683 bool result = false;
Greg Clayton63094e02010-06-23 01:19:29 +0000684 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000685 {
686 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
Caroline Tice7826c882010-10-26 03:11:13 +0000687 result = m_opaque_sp->RemoveBreakpointByID (bp_id);
Greg Claytonbdcda462010-12-20 20:49:23 +0000688 }
Caroline Tice7826c882010-10-26 03:11:13 +0000689
690 if (log)
691 {
Greg Clayton3f5ee7f2010-10-29 04:59:35 +0000692 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 +0000693 }
694
695 return result;
Chris Lattner24943d22010-06-08 16:52:24 +0000696}
697
698bool
699SBTarget::EnableAllBreakpoints ()
700{
Greg Clayton63094e02010-06-23 01:19:29 +0000701 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000702 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000703 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
Greg Clayton63094e02010-06-23 01:19:29 +0000704 m_opaque_sp->EnableAllBreakpoints ();
Chris Lattner24943d22010-06-08 16:52:24 +0000705 return true;
706 }
707 return false;
708}
709
710bool
711SBTarget::DisableAllBreakpoints ()
712{
Greg Clayton63094e02010-06-23 01:19:29 +0000713 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000714 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000715 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
Greg Clayton63094e02010-06-23 01:19:29 +0000716 m_opaque_sp->DisableAllBreakpoints ();
Chris Lattner24943d22010-06-08 16:52:24 +0000717 return true;
718 }
719 return false;
720}
721
722bool
723SBTarget::DeleteAllBreakpoints ()
724{
Greg Clayton63094e02010-06-23 01:19:29 +0000725 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000726 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000727 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
Greg Clayton63094e02010-06-23 01:19:29 +0000728 m_opaque_sp->RemoveAllBreakpoints ();
Chris Lattner24943d22010-06-08 16:52:24 +0000729 return true;
730 }
731 return false;
732}
733
734
735uint32_t
736SBTarget::GetNumModules () const
737{
Greg Claytone005f2c2010-11-06 01:53:30 +0000738 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000739
Caroline Tice7826c882010-10-26 03:11:13 +0000740 uint32_t num = 0;
Greg Clayton63094e02010-06-23 01:19:29 +0000741 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000742 {
743 // The module list is thread safe, no need to lock
744 num = m_opaque_sp->GetImages().GetSize();
745 }
Caroline Tice7826c882010-10-26 03:11:13 +0000746
747 if (log)
Greg Clayton3f5ee7f2010-10-29 04:59:35 +0000748 log->Printf ("SBTarget(%p)::GetNumModules () => %d", m_opaque_sp.get(), num);
Caroline Tice7826c882010-10-26 03:11:13 +0000749
750 return num;
Chris Lattner24943d22010-06-08 16:52:24 +0000751}
752
Greg Clayton43490d12010-07-30 20:12:55 +0000753void
754SBTarget::Clear ()
755{
Greg Claytone005f2c2010-11-06 01:53:30 +0000756 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000757
758 if (log)
Greg Clayton3f5ee7f2010-10-29 04:59:35 +0000759 log->Printf ("SBTarget(%p)::Clear ()", m_opaque_sp.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000760
Greg Clayton43490d12010-07-30 20:12:55 +0000761 m_opaque_sp.reset();
762}
763
764
Chris Lattner24943d22010-06-08 16:52:24 +0000765SBModule
766SBTarget::FindModule (const SBFileSpec &sb_file_spec)
767{
768 SBModule sb_module;
Greg Clayton63094e02010-06-23 01:19:29 +0000769 if (m_opaque_sp && sb_file_spec.IsValid())
Greg Claytonbdcda462010-12-20 20:49:23 +0000770 {
771 // The module list is thread safe, no need to lock
Greg Clayton24bc5d92011-03-30 18:16:51 +0000772 sb_module.SetModule (m_opaque_sp->GetImages().FindFirstModuleForFileSpec (*sb_file_spec, NULL, NULL));
Greg Claytonbdcda462010-12-20 20:49:23 +0000773 }
Chris Lattner24943d22010-06-08 16:52:24 +0000774 return sb_module;
775}
776
777SBModule
778SBTarget::GetModuleAtIndex (uint32_t idx)
779{
Greg Claytone005f2c2010-11-06 01:53:30 +0000780 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000781
Chris Lattner24943d22010-06-08 16:52:24 +0000782 SBModule sb_module;
Greg Clayton63094e02010-06-23 01:19:29 +0000783 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000784 {
785 // The module list is thread safe, no need to lock
Greg Clayton63094e02010-06-23 01:19:29 +0000786 sb_module.SetModule(m_opaque_sp->GetImages().GetModuleAtIndex(idx));
Greg Claytonbdcda462010-12-20 20:49:23 +0000787 }
Caroline Tice7826c882010-10-26 03:11:13 +0000788
789 if (log)
790 {
Greg Clayton49ce6822010-10-31 03:01:06 +0000791 log->Printf ("SBTarget(%p)::GetModuleAtIndex (idx=%d) => SBModule(%p)",
792 m_opaque_sp.get(), idx, sb_module.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000793 }
794
Chris Lattner24943d22010-06-08 16:52:24 +0000795 return sb_module;
796}
797
798
799SBBroadcaster
800SBTarget::GetBroadcaster () const
801{
Greg Claytone005f2c2010-11-06 01:53:30 +0000802 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000803
Greg Clayton63094e02010-06-23 01:19:29 +0000804 SBBroadcaster broadcaster(m_opaque_sp.get(), false);
Caroline Tice7826c882010-10-26 03:11:13 +0000805
806 if (log)
Greg Clayton3f5ee7f2010-10-29 04:59:35 +0000807 log->Printf ("SBTarget(%p)::GetBroadcaster () => SBBroadcaster(%p)",
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000808 m_opaque_sp.get(), broadcaster.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000809
Chris Lattner24943d22010-06-08 16:52:24 +0000810 return broadcaster;
811}
812
Caroline Tice98f930f2010-09-20 05:20:02 +0000813
814bool
Caroline Tice7826c882010-10-26 03:11:13 +0000815SBTarget::GetDescription (SBStream &description, lldb::DescriptionLevel description_level)
Caroline Tice98f930f2010-09-20 05:20:02 +0000816{
817 if (m_opaque_sp)
Caroline Ticee7a566e2010-09-20 16:21:41 +0000818 {
Caroline Ticee49ec182010-09-22 23:01:29 +0000819 description.ref();
Caroline Tice7826c882010-10-26 03:11:13 +0000820 m_opaque_sp->Dump (description.get(), description_level);
821 }
822 else
823 description.Printf ("No value");
824
825 return true;
826}
827
828bool
829SBTarget::GetDescription (SBStream &description, lldb::DescriptionLevel description_level) const
830{
831 if (m_opaque_sp)
832 {
833 description.ref();
834 m_opaque_sp->Dump (description.get(), description_level);
Caroline Ticee7a566e2010-09-20 16:21:41 +0000835 }
Caroline Tice98f930f2010-09-20 05:20:02 +0000836 else
837 description.Printf ("No value");
838
839 return true;
840}