blob: 2bb70afcbdd3e420a6e7e58e4ba925733ed9808c [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
12#include "lldb/lldb-include.h"
13
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"
28#include "lldb/Core/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"
33#include "lldb/Target/Process.h"
34#include "lldb/Target/Target.h"
35#include "lldb/Target/TargetList.h"
36
37#include "lldb/Interpreter/CommandReturnObject.h"
38#include "../source/Commands/CommandObjectBreakpoint.h"
39
Eli Friedman7a62c8b2010-06-09 07:44:37 +000040#include "lldb/API/SBDebugger.h"
41#include "lldb/API/SBProcess.h"
42#include "lldb/API/SBListener.h"
43#include "lldb/API/SBBreakpoint.h"
Chris Lattner24943d22010-06-08 16:52:24 +000044
45using namespace lldb;
46using namespace lldb_private;
47
48#define DEFAULT_DISASM_BYTE_SIZE 32
49
50//----------------------------------------------------------------------
51// SBTarget constructor
52//----------------------------------------------------------------------
Greg Claytonc3b61d22010-12-15 05:08:08 +000053SBTarget::SBTarget () :
54 m_opaque_sp ()
Chris Lattner24943d22010-06-08 16:52:24 +000055{
56}
57
58SBTarget::SBTarget (const SBTarget& rhs) :
Greg Clayton63094e02010-06-23 01:19:29 +000059 m_opaque_sp (rhs.m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +000060{
61}
62
63SBTarget::SBTarget(const TargetSP& target_sp) :
Greg Clayton63094e02010-06-23 01:19:29 +000064 m_opaque_sp (target_sp)
Chris Lattner24943d22010-06-08 16:52:24 +000065{
66}
67
Greg Clayton538eb822010-11-05 23:17:00 +000068const SBTarget&
69SBTarget::operator = (const SBTarget& rhs)
70{
71 if (this != &rhs)
72 m_opaque_sp = rhs.m_opaque_sp;
73 return *this;
74}
75
Chris Lattner24943d22010-06-08 16:52:24 +000076//----------------------------------------------------------------------
77// Destructor
78//----------------------------------------------------------------------
79SBTarget::~SBTarget()
80{
81}
82
83bool
84SBTarget::IsValid () const
85{
Greg Clayton63094e02010-06-23 01:19:29 +000086 return m_opaque_sp.get() != NULL;
Chris Lattner24943d22010-06-08 16:52:24 +000087}
88
89SBProcess
90SBTarget::GetProcess ()
91{
Caroline Tice7826c882010-10-26 03:11:13 +000092
Chris Lattner24943d22010-06-08 16:52:24 +000093 SBProcess sb_process;
Greg Clayton63094e02010-06-23 01:19:29 +000094 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +000095 {
96 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
Greg Clayton63094e02010-06-23 01:19:29 +000097 sb_process.SetProcess (m_opaque_sp->GetProcessSP());
Greg Claytonbdcda462010-12-20 20:49:23 +000098 }
Caroline Tice7826c882010-10-26 03:11:13 +000099
Greg Claytone005f2c2010-11-06 01:53:30 +0000100 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000101 if (log)
102 {
Greg Clayton49ce6822010-10-31 03:01:06 +0000103 log->Printf ("SBTarget(%p)::GetProcess () => SBProcess(%p)",
104 m_opaque_sp.get(), sb_process.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000105 }
106
Chris Lattner24943d22010-06-08 16:52:24 +0000107 return sb_process;
108}
109
Greg Clayton63094e02010-06-23 01:19:29 +0000110SBDebugger
111SBTarget::GetDebugger () const
112{
113 SBDebugger debugger;
114 if (m_opaque_sp)
115 debugger.reset (m_opaque_sp->GetDebugger().GetSP());
116 return debugger;
117}
118
Greg Claytonde915be2011-01-23 05:56:20 +0000119
120SBProcess
121SBTarget::Launch
122(
123 char const **argv,
124 char const **envp,
125 const char *stdin_path,
126 const char *stdout_path,
127 const char *stderr_path,
128 const char *working_directory,
129 uint32_t launch_flags, // See LaunchFlags
130 bool stop_at_entry,
131 lldb::SBError& error
132)
133{
Greg Claytone005f2c2010-11-06 01:53:30 +0000134 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000135
136 if (log)
Greg Clayton3f5ee7f2010-10-29 04:59:35 +0000137 {
Greg Claytonde915be2011-01-23 05:56:20 +0000138 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))...",
139 m_opaque_sp.get(),
140 argv,
141 envp,
142 stdin_path ? stdin_path : "NULL",
143 stdout_path ? stdout_path : "NULL",
144 stderr_path ? stderr_path : "NULL",
145 working_directory ? working_directory : "NULL",
146 launch_flags,
147 stop_at_entry,
148 error.get());
Greg Clayton3f5ee7f2010-10-29 04:59:35 +0000149 }
Greg Clayton1a3083a2010-10-06 03:53:16 +0000150 SBProcess sb_process;
151 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000152 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000153 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
Greg Clayton1a3083a2010-10-06 03:53:16 +0000154
Greg Clayton7c330d62011-01-27 01:01:10 +0000155 if (getenv("LLDB_LAUNCH_FLAG_DISABLE_ASLR"))
156 launch_flags |= eLaunchFlagDisableASLR;
157
Greg Clayton28d5fcc2011-01-27 06:44:37 +0000158 static const char *g_launch_tty = NULL;
159 static bool g_got_launch_tty = false;
160 if (!g_got_launch_tty)
161 {
162 // Get the LLDB_LAUNCH_FLAG_LAUNCH_IN_TTY only once
163 g_got_launch_tty = true;
164 g_launch_tty = ::getenv ("LLDB_LAUNCH_FLAG_LAUNCH_IN_TTY");
165 if (g_launch_tty)
166 {
167 // LLDB_LAUNCH_FLAG_LAUNCH_IN_TTY is a path to a terminal to reuse
168 // if the first character is '/', else it is a boolean value.
169 if (g_launch_tty[0] != '/')
170 {
171 if (Args::StringToBoolean(g_launch_tty, false, NULL))
172 g_launch_tty = "";
173 else
174 g_launch_tty = NULL;
175 }
176 }
177 }
178
179 if ((launch_flags & eLaunchFlagLaunchInTTY) || g_launch_tty)
Chris Lattner24943d22010-06-08 16:52:24 +0000180 {
Greg Clayton7c330d62011-01-27 01:01:10 +0000181 ArchSpec arch (m_opaque_sp->GetArchitecture ());
182
183 Module *exe_module = m_opaque_sp->GetExecutableModule().get();
184 if (exe_module)
Chris Lattner24943d22010-06-08 16:52:24 +0000185 {
Greg Clayton7c330d62011-01-27 01:01:10 +0000186 char exec_file_path[PATH_MAX];
187 exe_module->GetFileSpec().GetPath(exec_file_path, sizeof(exec_file_path));
188 if (exe_module->GetFileSpec().Exists())
Greg Clayton1a3083a2010-10-06 03:53:16 +0000189 {
Greg Clayton7c330d62011-01-27 01:01:10 +0000190 // Make a new argument vector
191 std::vector<const char *> exec_path_plus_argv;
192 // Append the resolved executable path
193 exec_path_plus_argv.push_back (exec_file_path);
194
195 // Push all args if there are any
196 if (argv)
Greg Clayton1a3083a2010-10-06 03:53:16 +0000197 {
Greg Clayton7c330d62011-01-27 01:01:10 +0000198 for (int i = 0; argv[i]; ++i)
199 exec_path_plus_argv.push_back(argv[i]);
200 }
201
202 // Push a NULL to terminate the args.
203 exec_path_plus_argv.push_back(NULL);
204
205
Greg Clayton28d5fcc2011-01-27 06:44:37 +0000206 const char *tty_name = NULL;
207 if (g_launch_tty && g_launch_tty[0] == '/')
208 tty_name = g_launch_tty;
209
210 lldb::pid_t pid = Host::LaunchInNewTerminal (tty_name,
211 &exec_path_plus_argv[0],
212 envp,
213 working_directory,
214 &arch,
215 true,
216 launch_flags & eLaunchFlagDisableASLR);
217
Greg Clayton7c330d62011-01-27 01:01:10 +0000218 if (pid != LLDB_INVALID_PROCESS_ID)
219 {
220 sb_process = AttachToProcessWithID(pid, error);
221 }
222 else
223 {
224 error.SetErrorStringWithFormat("failed to launch process in terminal");
Greg Clayton1a3083a2010-10-06 03:53:16 +0000225 }
226 }
Greg Clayton7c330d62011-01-27 01:01:10 +0000227 else
228 {
229 error.SetErrorStringWithFormat("executable doesn't exist: \"%s\"", exec_file_path);
230 }
231 }
232 else
233 {
234 error.SetErrorStringWithFormat("invalid executable");
Chris Lattner24943d22010-06-08 16:52:24 +0000235 }
236 }
Greg Claytonc5f728c2010-10-06 22:10:17 +0000237 else
238 {
Greg Clayton7c330d62011-01-27 01:01:10 +0000239 sb_process.SetProcess (m_opaque_sp->CreateProcess (m_opaque_sp->GetDebugger().GetListener()));
240
241 if (sb_process.IsValid())
242 {
243
244 if (getenv("LLDB_LAUNCH_FLAG_DISABLE_STDIO"))
245 launch_flags |= eLaunchFlagDisableSTDIO;
246
247
248 error.SetError (sb_process->Launch (argv, envp, launch_flags, stdin_path, stdout_path, stderr_path, working_directory));
249 if (error.Success())
250 {
251 // We we are stopping at the entry point, we can return now!
252 if (stop_at_entry)
253 return sb_process;
254
255 // Make sure we are stopped at the entry
256 StateType state = sb_process->WaitForProcessToStop (NULL);
257 if (state == eStateStopped)
258 {
259 // resume the process to skip the entry point
260 error.SetError (sb_process->Resume());
261 if (error.Success())
262 {
263 // If we are doing synchronous mode, then wait for the
264 // process to stop yet again!
265 if (m_opaque_sp->GetDebugger().GetAsyncExecution () == false)
266 sb_process->WaitForProcessToStop (NULL);
267 }
268 }
269 }
270 }
271 else
272 {
273 error.SetErrorString ("unable to create lldb_private::Process");
274 }
Greg Claytonc5f728c2010-10-06 22:10:17 +0000275 }
276 }
277 else
278 {
279 error.SetErrorString ("SBTarget is invalid");
Chris Lattner24943d22010-06-08 16:52:24 +0000280 }
Caroline Tice7826c882010-10-26 03:11:13 +0000281
Caroline Tice926060e2010-10-29 21:48:37 +0000282 log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
Caroline Tice7826c882010-10-26 03:11:13 +0000283 if (log)
284 {
Greg Clayton49ce6822010-10-31 03:01:06 +0000285 log->Printf ("SBTarget(%p)::Launch (...) => SBProceess(%p)",
286 m_opaque_sp.get(), sb_process.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000287 }
288
Greg Clayton1a3083a2010-10-06 03:53:16 +0000289 return sb_process;
Chris Lattner24943d22010-06-08 16:52:24 +0000290}
291
Greg Claytonc5f728c2010-10-06 22:10:17 +0000292
293lldb::SBProcess
Greg Claytond8c62532010-10-07 04:19:01 +0000294SBTarget::AttachToProcessWithID
Greg Claytonc5f728c2010-10-06 22:10:17 +0000295(
296 lldb::pid_t pid,// The process ID to attach to
297 SBError& error // An error explaining what went wrong if attach fails
298)
299{
300 SBProcess sb_process;
301 if (m_opaque_sp)
302 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000303 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
304 sb_process.SetProcess (m_opaque_sp->CreateProcess (m_opaque_sp->GetDebugger().GetListener()));
Greg Claytonc5f728c2010-10-06 22:10:17 +0000305
306 if (sb_process.IsValid())
307 {
308 error.SetError (sb_process->Attach (pid));
309 }
310 else
311 {
312 error.SetErrorString ("unable to create lldb_private::Process");
313 }
314 }
315 else
316 {
317 error.SetErrorString ("SBTarget is invalid");
318 }
319 return sb_process;
320
321}
322
323lldb::SBProcess
Greg Claytond8c62532010-10-07 04:19:01 +0000324SBTarget::AttachToProcessWithName
Greg Claytonc5f728c2010-10-06 22:10:17 +0000325(
326 const char *name, // basename of process to attach to
327 bool wait_for, // if true wait for a new instance of "name" to be launched
328 SBError& error // An error explaining what went wrong if attach fails
329)
330{
331 SBProcess sb_process;
332 if (m_opaque_sp)
333 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000334 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
335
336 sb_process.SetProcess (m_opaque_sp->CreateProcess (m_opaque_sp->GetDebugger().GetListener()));
Greg Claytonc5f728c2010-10-06 22:10:17 +0000337
338 if (sb_process.IsValid())
339 {
340 error.SetError (sb_process->Attach (name, wait_for));
341 }
342 else
343 {
344 error.SetErrorString ("unable to create lldb_private::Process");
345 }
346 }
347 else
348 {
349 error.SetErrorString ("SBTarget is invalid");
350 }
351 return sb_process;
352
353}
354
Chris Lattner24943d22010-06-08 16:52:24 +0000355SBFileSpec
356SBTarget::GetExecutable ()
357{
Caroline Tice7826c882010-10-26 03:11:13 +0000358
Chris Lattner24943d22010-06-08 16:52:24 +0000359 SBFileSpec exe_file_spec;
Greg Clayton63094e02010-06-23 01:19:29 +0000360 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000361 {
Greg Clayton63094e02010-06-23 01:19:29 +0000362 ModuleSP exe_module_sp (m_opaque_sp->GetExecutableModule ());
Chris Lattner24943d22010-06-08 16:52:24 +0000363 if (exe_module_sp)
364 exe_file_spec.SetFileSpec (exe_module_sp->GetFileSpec());
365 }
Caroline Tice7826c882010-10-26 03:11:13 +0000366
Greg Claytone005f2c2010-11-06 01:53:30 +0000367 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000368 if (log)
369 {
Greg Clayton49ce6822010-10-31 03:01:06 +0000370 log->Printf ("SBTarget(%p)::GetExecutable () => SBFileSpec(%p)",
371 m_opaque_sp.get(), exe_file_spec.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000372 }
373
Chris Lattner24943d22010-06-08 16:52:24 +0000374 return exe_file_spec;
375}
376
377
378bool
379SBTarget::DeleteTargetFromList (TargetList *list)
380{
Greg Clayton63094e02010-06-23 01:19:29 +0000381 if (m_opaque_sp)
382 return list->DeleteTarget (m_opaque_sp);
Chris Lattner24943d22010-06-08 16:52:24 +0000383 else
384 return false;
385}
386
387bool
Chris Lattner24943d22010-06-08 16:52:24 +0000388SBTarget::operator == (const SBTarget &rhs) const
389{
Greg Clayton63094e02010-06-23 01:19:29 +0000390 return m_opaque_sp.get() == rhs.m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000391}
392
393bool
394SBTarget::operator != (const SBTarget &rhs) const
395{
Greg Clayton63094e02010-06-23 01:19:29 +0000396 return m_opaque_sp.get() != rhs.m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000397}
398
399lldb_private::Target *
Greg Clayton63094e02010-06-23 01:19:29 +0000400SBTarget::operator ->() const
Chris Lattner24943d22010-06-08 16:52:24 +0000401{
Greg Clayton63094e02010-06-23 01:19:29 +0000402 return m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000403}
Greg Clayton63094e02010-06-23 01:19:29 +0000404
405lldb_private::Target *
406SBTarget::get() const
Chris Lattner24943d22010-06-08 16:52:24 +0000407{
Greg Clayton63094e02010-06-23 01:19:29 +0000408 return m_opaque_sp.get();
409}
410
411void
412SBTarget::reset (const lldb::TargetSP& target_sp)
413{
414 m_opaque_sp = target_sp;
Chris Lattner24943d22010-06-08 16:52:24 +0000415}
416
Greg Claytonea49cc72010-12-12 19:25:26 +0000417bool
418SBTarget::ResolveLoadAddress (lldb::addr_t vm_addr,
419 lldb::SBAddress& addr)
420{
421 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000422 {
423 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
Greg Claytonea49cc72010-12-12 19:25:26 +0000424 return m_opaque_sp->GetSectionLoadList().ResolveLoadAddress (vm_addr, *addr);
Greg Claytonbdcda462010-12-20 20:49:23 +0000425 }
Greg Claytonea49cc72010-12-12 19:25:26 +0000426
427 addr->Clear();
428 return false;
429}
430
Chris Lattner24943d22010-06-08 16:52:24 +0000431SBBreakpoint
432SBTarget::BreakpointCreateByLocation (const char *file, uint32_t line)
433{
Greg Claytond6d806c2010-11-08 00:28:40 +0000434 return SBBreakpoint(BreakpointCreateByLocation (SBFileSpec (file, false), line));
Chris Lattner24943d22010-06-08 16:52:24 +0000435}
436
437SBBreakpoint
438SBTarget::BreakpointCreateByLocation (const SBFileSpec &sb_file_spec, uint32_t line)
439{
Greg Claytone005f2c2010-11-06 01:53:30 +0000440 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000441
Chris Lattner24943d22010-06-08 16:52:24 +0000442 SBBreakpoint sb_bp;
Greg Clayton63094e02010-06-23 01:19:29 +0000443 if (m_opaque_sp.get() && line != 0)
Greg Claytonbdcda462010-12-20 20:49:23 +0000444 {
445 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
Greg Clayton63094e02010-06-23 01:19:29 +0000446 *sb_bp = m_opaque_sp->CreateBreakpoint (NULL, *sb_file_spec, line, true, false);
Greg Claytonbdcda462010-12-20 20:49:23 +0000447 }
Caroline Tice7826c882010-10-26 03:11:13 +0000448
449 if (log)
450 {
451 SBStream sstr;
452 sb_bp.GetDescription (sstr);
Greg Clayton49ce6822010-10-31 03:01:06 +0000453 char path[PATH_MAX];
454 sb_file_spec->GetPath (path, sizeof(path));
455 log->Printf ("SBTarget(%p)::BreakpointCreateByLocation ( %s:%u ) => SBBreakpoint(%p): %s",
Greg Claytona66ba462010-10-30 04:51:46 +0000456 m_opaque_sp.get(),
Greg Clayton49ce6822010-10-31 03:01:06 +0000457 path,
Greg Claytona66ba462010-10-30 04:51:46 +0000458 line,
Greg Clayton49ce6822010-10-31 03:01:06 +0000459 sb_bp.get(),
Caroline Tice7826c882010-10-26 03:11:13 +0000460 sstr.GetData());
461 }
462
Chris Lattner24943d22010-06-08 16:52:24 +0000463 return sb_bp;
464}
465
466SBBreakpoint
467SBTarget::BreakpointCreateByName (const char *symbol_name, const char *module_name)
468{
Greg Claytone005f2c2010-11-06 01:53:30 +0000469 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000470
Chris Lattner24943d22010-06-08 16:52:24 +0000471 SBBreakpoint sb_bp;
Greg Clayton63094e02010-06-23 01:19:29 +0000472 if (m_opaque_sp.get() && symbol_name && symbol_name[0])
Chris Lattner24943d22010-06-08 16:52:24 +0000473 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000474 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
Chris Lattner24943d22010-06-08 16:52:24 +0000475 if (module_name && module_name[0])
476 {
Greg Clayton537a7a82010-10-20 20:54:39 +0000477 FileSpec module_file_spec(module_name, false);
Jim Ingham7ec03bd2010-09-30 21:21:43 +0000478 *sb_bp = m_opaque_sp->CreateBreakpoint (&module_file_spec, symbol_name, eFunctionNameTypeFull | eFunctionNameTypeBase, false);
Chris Lattner24943d22010-06-08 16:52:24 +0000479 }
480 else
481 {
Jim Ingham7ec03bd2010-09-30 21:21:43 +0000482 *sb_bp = m_opaque_sp->CreateBreakpoint (NULL, symbol_name, eFunctionNameTypeFull | eFunctionNameTypeBase, false);
Chris Lattner24943d22010-06-08 16:52:24 +0000483 }
484 }
Caroline Tice7826c882010-10-26 03:11:13 +0000485
486 if (log)
487 {
Greg Clayton49ce6822010-10-31 03:01:06 +0000488 log->Printf ("SBTarget(%p)::BreakpointCreateByName (symbol=\"%s\", module=\"%s\") => SBBreakpoint(%p)",
489 m_opaque_sp.get(), symbol_name, module_name, sb_bp.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000490 }
491
Chris Lattner24943d22010-06-08 16:52:24 +0000492 return sb_bp;
493}
494
495SBBreakpoint
496SBTarget::BreakpointCreateByRegex (const char *symbol_name_regex, const char *module_name)
497{
Greg Claytone005f2c2010-11-06 01:53:30 +0000498 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000499
Chris Lattner24943d22010-06-08 16:52:24 +0000500 SBBreakpoint sb_bp;
Greg Clayton63094e02010-06-23 01:19:29 +0000501 if (m_opaque_sp.get() && symbol_name_regex && symbol_name_regex[0])
Chris Lattner24943d22010-06-08 16:52:24 +0000502 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000503 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
Chris Lattner24943d22010-06-08 16:52:24 +0000504 RegularExpression regexp(symbol_name_regex);
505
506 if (module_name && module_name[0])
507 {
Greg Clayton537a7a82010-10-20 20:54:39 +0000508 FileSpec module_file_spec(module_name, false);
Chris Lattner24943d22010-06-08 16:52:24 +0000509
Greg Clayton63094e02010-06-23 01:19:29 +0000510 *sb_bp = m_opaque_sp->CreateBreakpoint (&module_file_spec, regexp, false);
Chris Lattner24943d22010-06-08 16:52:24 +0000511 }
512 else
513 {
Greg Clayton63094e02010-06-23 01:19:29 +0000514 *sb_bp = m_opaque_sp->CreateBreakpoint (NULL, regexp, false);
Chris Lattner24943d22010-06-08 16:52:24 +0000515 }
516 }
Caroline Tice7826c882010-10-26 03:11:13 +0000517
518 if (log)
519 {
Greg Clayton49ce6822010-10-31 03:01:06 +0000520 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (symbol_regex=\"%s\", module_name=\"%s\") => SBBreakpoint(%p)",
521 m_opaque_sp.get(), symbol_name_regex, module_name, sb_bp.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000522 }
523
Chris Lattner24943d22010-06-08 16:52:24 +0000524 return sb_bp;
525}
526
527
528
529SBBreakpoint
530SBTarget::BreakpointCreateByAddress (addr_t address)
531{
Greg Claytone005f2c2010-11-06 01:53:30 +0000532 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000533
Chris Lattner24943d22010-06-08 16:52:24 +0000534 SBBreakpoint sb_bp;
Greg Clayton63094e02010-06-23 01:19:29 +0000535 if (m_opaque_sp.get())
Greg Claytonbdcda462010-12-20 20:49:23 +0000536 {
537 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
Greg Clayton63094e02010-06-23 01:19:29 +0000538 *sb_bp = m_opaque_sp->CreateBreakpoint (address, false);
Greg Claytonbdcda462010-12-20 20:49:23 +0000539 }
Caroline Tice7826c882010-10-26 03:11:13 +0000540
541 if (log)
542 {
Greg Clayton49ce6822010-10-31 03:01:06 +0000543 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 +0000544 }
545
Chris Lattner24943d22010-06-08 16:52:24 +0000546 return sb_bp;
547}
548
Chris Lattner24943d22010-06-08 16:52:24 +0000549SBBreakpoint
550SBTarget::FindBreakpointByID (break_id_t bp_id)
551{
Greg Claytone005f2c2010-11-06 01:53:30 +0000552 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000553
Chris Lattner24943d22010-06-08 16:52:24 +0000554 SBBreakpoint sb_breakpoint;
Greg Clayton63094e02010-06-23 01:19:29 +0000555 if (m_opaque_sp && bp_id != LLDB_INVALID_BREAK_ID)
Greg Claytonbdcda462010-12-20 20:49:23 +0000556 {
557 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
Greg Clayton63094e02010-06-23 01:19:29 +0000558 *sb_breakpoint = m_opaque_sp->GetBreakpointByID (bp_id);
Greg Claytonbdcda462010-12-20 20:49:23 +0000559 }
Caroline Tice7826c882010-10-26 03:11:13 +0000560
561 if (log)
562 {
Greg Clayton49ce6822010-10-31 03:01:06 +0000563 log->Printf ("SBTarget(%p)::FindBreakpointByID (bp_id=%d) => SBBreakpoint(%p)",
564 m_opaque_sp.get(), (uint32_t) bp_id, sb_breakpoint.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000565 }
566
Chris Lattner24943d22010-06-08 16:52:24 +0000567 return sb_breakpoint;
568}
569
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000570uint32_t
571SBTarget::GetNumBreakpoints () const
572{
573 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000574 {
575 // The breakpoint list is thread safe, no need to lock
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000576 return m_opaque_sp->GetBreakpointList().GetSize();
Greg Claytonbdcda462010-12-20 20:49:23 +0000577 }
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000578 return 0;
579}
580
581SBBreakpoint
582SBTarget::GetBreakpointAtIndex (uint32_t idx) const
583{
584 SBBreakpoint sb_breakpoint;
585 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000586 {
587 // The breakpoint list is thread safe, no need to lock
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000588 *sb_breakpoint = m_opaque_sp->GetBreakpointList().GetBreakpointAtIndex(idx);
Greg Claytonbdcda462010-12-20 20:49:23 +0000589 }
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000590 return sb_breakpoint;
591}
Chris Lattner24943d22010-06-08 16:52:24 +0000592
593bool
594SBTarget::BreakpointDelete (break_id_t bp_id)
595{
Greg Claytone005f2c2010-11-06 01:53:30 +0000596 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000597
Caroline Tice7826c882010-10-26 03:11:13 +0000598 bool result = false;
Greg Clayton63094e02010-06-23 01:19:29 +0000599 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000600 {
601 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
Caroline Tice7826c882010-10-26 03:11:13 +0000602 result = m_opaque_sp->RemoveBreakpointByID (bp_id);
Greg Claytonbdcda462010-12-20 20:49:23 +0000603 }
Caroline Tice7826c882010-10-26 03:11:13 +0000604
605 if (log)
606 {
Greg Clayton3f5ee7f2010-10-29 04:59:35 +0000607 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 +0000608 }
609
610 return result;
Chris Lattner24943d22010-06-08 16:52:24 +0000611}
612
613bool
614SBTarget::EnableAllBreakpoints ()
615{
Greg Clayton63094e02010-06-23 01:19:29 +0000616 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000617 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000618 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
Greg Clayton63094e02010-06-23 01:19:29 +0000619 m_opaque_sp->EnableAllBreakpoints ();
Chris Lattner24943d22010-06-08 16:52:24 +0000620 return true;
621 }
622 return false;
623}
624
625bool
626SBTarget::DisableAllBreakpoints ()
627{
Greg Clayton63094e02010-06-23 01:19:29 +0000628 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000629 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000630 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
Greg Clayton63094e02010-06-23 01:19:29 +0000631 m_opaque_sp->DisableAllBreakpoints ();
Chris Lattner24943d22010-06-08 16:52:24 +0000632 return true;
633 }
634 return false;
635}
636
637bool
638SBTarget::DeleteAllBreakpoints ()
639{
Greg Clayton63094e02010-06-23 01:19:29 +0000640 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000641 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000642 Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
Greg Clayton63094e02010-06-23 01:19:29 +0000643 m_opaque_sp->RemoveAllBreakpoints ();
Chris Lattner24943d22010-06-08 16:52:24 +0000644 return true;
645 }
646 return false;
647}
648
649
650uint32_t
651SBTarget::GetNumModules () const
652{
Greg Claytone005f2c2010-11-06 01:53:30 +0000653 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000654
Caroline Tice7826c882010-10-26 03:11:13 +0000655 uint32_t num = 0;
Greg Clayton63094e02010-06-23 01:19:29 +0000656 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000657 {
658 // The module list is thread safe, no need to lock
659 num = m_opaque_sp->GetImages().GetSize();
660 }
Caroline Tice7826c882010-10-26 03:11:13 +0000661
662 if (log)
Greg Clayton3f5ee7f2010-10-29 04:59:35 +0000663 log->Printf ("SBTarget(%p)::GetNumModules () => %d", m_opaque_sp.get(), num);
Caroline Tice7826c882010-10-26 03:11:13 +0000664
665 return num;
Chris Lattner24943d22010-06-08 16:52:24 +0000666}
667
Greg Clayton43490d12010-07-30 20:12:55 +0000668void
669SBTarget::Clear ()
670{
Greg Claytone005f2c2010-11-06 01:53:30 +0000671 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000672
673 if (log)
Greg Clayton3f5ee7f2010-10-29 04:59:35 +0000674 log->Printf ("SBTarget(%p)::Clear ()", m_opaque_sp.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000675
Greg Clayton43490d12010-07-30 20:12:55 +0000676 m_opaque_sp.reset();
677}
678
679
Chris Lattner24943d22010-06-08 16:52:24 +0000680SBModule
681SBTarget::FindModule (const SBFileSpec &sb_file_spec)
682{
683 SBModule sb_module;
Greg Clayton63094e02010-06-23 01:19:29 +0000684 if (m_opaque_sp && sb_file_spec.IsValid())
Greg Claytonbdcda462010-12-20 20:49:23 +0000685 {
686 // The module list is thread safe, no need to lock
Greg Clayton63094e02010-06-23 01:19:29 +0000687 sb_module.SetModule (m_opaque_sp->GetImages().FindFirstModuleForFileSpec (*sb_file_spec, NULL));
Greg Claytonbdcda462010-12-20 20:49:23 +0000688 }
Chris Lattner24943d22010-06-08 16:52:24 +0000689 return sb_module;
690}
691
692SBModule
693SBTarget::GetModuleAtIndex (uint32_t idx)
694{
Greg Claytone005f2c2010-11-06 01:53:30 +0000695 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000696
Chris Lattner24943d22010-06-08 16:52:24 +0000697 SBModule sb_module;
Greg Clayton63094e02010-06-23 01:19:29 +0000698 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000699 {
700 // The module list is thread safe, no need to lock
Greg Clayton63094e02010-06-23 01:19:29 +0000701 sb_module.SetModule(m_opaque_sp->GetImages().GetModuleAtIndex(idx));
Greg Claytonbdcda462010-12-20 20:49:23 +0000702 }
Caroline Tice7826c882010-10-26 03:11:13 +0000703
704 if (log)
705 {
Greg Clayton49ce6822010-10-31 03:01:06 +0000706 log->Printf ("SBTarget(%p)::GetModuleAtIndex (idx=%d) => SBModule(%p)",
707 m_opaque_sp.get(), idx, sb_module.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000708 }
709
Chris Lattner24943d22010-06-08 16:52:24 +0000710 return sb_module;
711}
712
713
714SBBroadcaster
715SBTarget::GetBroadcaster () const
716{
Greg Claytone005f2c2010-11-06 01:53:30 +0000717 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000718
Greg Clayton63094e02010-06-23 01:19:29 +0000719 SBBroadcaster broadcaster(m_opaque_sp.get(), false);
Caroline Tice7826c882010-10-26 03:11:13 +0000720
721 if (log)
Greg Clayton3f5ee7f2010-10-29 04:59:35 +0000722 log->Printf ("SBTarget(%p)::GetBroadcaster () => SBBroadcaster(%p)",
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000723 m_opaque_sp.get(), broadcaster.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000724
Chris Lattner24943d22010-06-08 16:52:24 +0000725 return broadcaster;
726}
727
Caroline Tice98f930f2010-09-20 05:20:02 +0000728
729bool
Caroline Tice7826c882010-10-26 03:11:13 +0000730SBTarget::GetDescription (SBStream &description, lldb::DescriptionLevel description_level)
Caroline Tice98f930f2010-09-20 05:20:02 +0000731{
732 if (m_opaque_sp)
Caroline Ticee7a566e2010-09-20 16:21:41 +0000733 {
Caroline Ticee49ec182010-09-22 23:01:29 +0000734 description.ref();
Caroline Tice7826c882010-10-26 03:11:13 +0000735 m_opaque_sp->Dump (description.get(), description_level);
736 }
737 else
738 description.Printf ("No value");
739
740 return true;
741}
742
743bool
744SBTarget::GetDescription (SBStream &description, lldb::DescriptionLevel description_level) const
745{
746 if (m_opaque_sp)
747 {
748 description.ref();
749 m_opaque_sp->Dump (description.get(), description_level);
Caroline Ticee7a566e2010-09-20 16:21:41 +0000750 }
Caroline Tice98f930f2010-09-20 05:20:02 +0000751 else
752 description.Printf ("No value");
753
754 return true;
755}