blob: fa9c43ef77f1cf917b16eae0c3fbfe712ef5b9ed [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
Greg Clayton98ca1e62012-02-24 20:59:25 +000057SBLaunchInfo::SBLaunchInfo (const char **argv) :
58 m_opaque_sp(new ProcessLaunchInfo())
Greg Clayton0a8dcac2012-02-24 05:03:03 +000059{
Greg Clayton98ca1e62012-02-24 20:59:25 +000060 m_opaque_sp->GetFlags().Reset (eLaunchFlagDebug | eLaunchFlagDisableASLR);
61 if (argv && argv[0])
62 m_opaque_sp->GetArguments().SetArguments(argv);
Greg Clayton0a8dcac2012-02-24 05:03:03 +000063}
64
65uint32_t
66SBLaunchInfo::GetUserID()
67{
68 return m_opaque_sp->GetUserID();
69}
70
71uint32_t
72SBLaunchInfo::GetGroupID()
73{
74 return m_opaque_sp->GetGroupID();
75}
76
77bool
78SBLaunchInfo::UserIDIsValid ()
79{
80 return m_opaque_sp->UserIDIsValid();
81}
82
83bool
84SBLaunchInfo::GroupIDIsValid ()
85{
86 return m_opaque_sp->GroupIDIsValid();
87}
88
89void
90SBLaunchInfo::SetUserID (uint32_t uid)
91{
92 m_opaque_sp->SetUserID (uid);
93}
94
95void
96SBLaunchInfo::SetGroupID (uint32_t gid)
97{
98 m_opaque_sp->SetGroupID (gid);
99}
100
Greg Clayton0a8dcac2012-02-24 05:03:03 +0000101uint32_t
102SBLaunchInfo::GetNumArguments ()
103{
104 return m_opaque_sp->GetArguments().GetArgumentCount();
105}
106
107const char *
108SBLaunchInfo::GetArgumentAtIndex (uint32_t idx)
109{
110 return m_opaque_sp->GetArguments().GetArgumentAtIndex(idx);
111}
112
113void
114SBLaunchInfo::SetArguments (const char **argv, bool append)
115{
116 if (append)
117 {
118 if (argv)
119 m_opaque_sp->GetArguments().AppendArguments(argv);
120 }
121 else
122 {
123 if (argv)
124 m_opaque_sp->GetArguments().SetArguments(argv);
125 else
126 m_opaque_sp->GetArguments().Clear();
127 }
128}
129
130uint32_t
131SBLaunchInfo::GetNumEnvironmentEntries ()
132{
133 return m_opaque_sp->GetEnvironmentEntries().GetArgumentCount();
134}
135
136const char *
137SBLaunchInfo::GetEnvironmentEntryAtIndex (uint32_t idx)
138{
139 return m_opaque_sp->GetEnvironmentEntries().GetArgumentAtIndex(idx);
140}
141
142void
143SBLaunchInfo::SetEnvironmentEntries (const char **envp, bool append)
144{
145 if (append)
146 {
147 if (envp)
148 m_opaque_sp->GetEnvironmentEntries().AppendArguments(envp);
149 }
150 else
151 {
152 if (envp)
153 m_opaque_sp->GetEnvironmentEntries().SetArguments(envp);
154 else
155 m_opaque_sp->GetEnvironmentEntries().Clear();
156 }
157}
158
159void
160SBLaunchInfo::Clear ()
161{
162 m_opaque_sp->Clear();
163}
164
165const char *
166SBLaunchInfo::GetWorkingDirectory () const
167{
168 return m_opaque_sp->GetWorkingDirectory();
169}
170
171void
172SBLaunchInfo::SetWorkingDirectory (const char *working_dir)
173{
174 m_opaque_sp->SetWorkingDirectory(working_dir);
175}
176
177uint32_t
178SBLaunchInfo::GetLaunchFlags ()
179{
180 return m_opaque_sp->GetFlags().Get();
181}
182
183void
184SBLaunchInfo::SetLaunchFlags (uint32_t flags)
185{
186 m_opaque_sp->GetFlags().Reset(flags);
187}
188
189const char *
190SBLaunchInfo::GetProcessPluginName ()
191{
192 return m_opaque_sp->GetProcessPluginName();
193}
194
195void
196SBLaunchInfo::SetProcessPluginName (const char *plugin_name)
197{
198 return m_opaque_sp->SetProcessPluginName (plugin_name);
199}
200
201const char *
202SBLaunchInfo::GetShell ()
203{
204 return m_opaque_sp->GetShell();
205}
206
207void
208SBLaunchInfo::SetShell (const char * path)
209{
210 m_opaque_sp->SetShell (path);
211}
212
213uint32_t
214SBLaunchInfo::GetResumeCount ()
215{
216 return m_opaque_sp->GetResumeCount();
217}
218
219void
220SBLaunchInfo::SetResumeCount (uint32_t c)
221{
222 m_opaque_sp->SetResumeCount (c);
223}
224
225bool
226SBLaunchInfo::AddCloseFileAction (int fd)
227{
228 return m_opaque_sp->AppendCloseFileAction(fd);
229}
230
231bool
232SBLaunchInfo::AddDuplicateFileAction (int fd, int dup_fd)
233{
234 return m_opaque_sp->AppendDuplicateFileAction(fd, dup_fd);
235}
236
237bool
238SBLaunchInfo::AddOpenFileAction (int fd, const char *path, bool read, bool write)
239{
240 return m_opaque_sp->AppendOpenFileAction(fd, path, read, write);
241}
242
243bool
244SBLaunchInfo::AddSuppressFileAction (int fd, bool read, bool write)
245{
246 return m_opaque_sp->AppendSuppressFileAction(fd, read, write);
247}
248
249
250SBAttachInfo::SBAttachInfo () :
251m_opaque_sp (new ProcessAttachInfo())
252{
253}
254
255SBAttachInfo::SBAttachInfo (lldb::pid_t pid) :
256m_opaque_sp (new ProcessAttachInfo())
257{
258 m_opaque_sp->SetProcessID (pid);
259}
260
261SBAttachInfo::SBAttachInfo (const char *path, bool wait_for) :
262m_opaque_sp (new ProcessAttachInfo())
263{
264 if (path && path[0])
265 m_opaque_sp->GetExecutableFile().SetFile(path, false);
266 m_opaque_sp->SetWaitForLaunch (wait_for);
267}
268
269SBAttachInfo::SBAttachInfo (const SBAttachInfo &rhs) :
270m_opaque_sp (new ProcessAttachInfo())
271{
272 *m_opaque_sp = *rhs.m_opaque_sp;
273}
274
275SBAttachInfo &
276SBAttachInfo::operator = (const SBAttachInfo &rhs)
277{
278 if (this != &rhs)
279 *m_opaque_sp = *rhs.m_opaque_sp;
280 return *this;
281}
282
283lldb::pid_t
284SBAttachInfo::GetProcessID ()
285{
286 return m_opaque_sp->GetProcessID();
287}
288
289void
290SBAttachInfo::SetProcessID (lldb::pid_t pid)
291{
292 m_opaque_sp->SetProcessID (pid);
293}
294
295
296uint32_t
297SBAttachInfo::GetResumeCount ()
298{
299 return m_opaque_sp->GetResumeCount();
300}
301
302void
303SBAttachInfo::SetResumeCount (uint32_t c)
304{
305 m_opaque_sp->SetResumeCount (c);
306}
307
308const char *
309SBAttachInfo::GetProcessPluginName ()
310{
311 return m_opaque_sp->GetProcessPluginName();
312}
313
314void
315SBAttachInfo::SetProcessPluginName (const char *plugin_name)
316{
317 return m_opaque_sp->SetProcessPluginName (plugin_name);
318}
319
320void
321SBAttachInfo::SetExecutable (const char *path)
322{
323 if (path && path[0])
324 m_opaque_sp->GetExecutableFile().SetFile(path, false);
325 else
326 m_opaque_sp->GetExecutableFile().Clear();
327}
328
329void
330SBAttachInfo::SetExecutable (SBFileSpec exe_file)
331{
332 if (exe_file.IsValid())
333 m_opaque_sp->GetExecutableFile() = exe_file.ref();
334 else
335 m_opaque_sp->GetExecutableFile().Clear();
336}
337
338bool
339SBAttachInfo::GetWaitForLaunch ()
340{
341 return m_opaque_sp->GetWaitForLaunch();
342}
343
344void
345SBAttachInfo::SetWaitForLaunch (bool b)
346{
347 m_opaque_sp->SetWaitForLaunch (b);
348}
349
350uint32_t
351SBAttachInfo::GetEffectiveUserID()
352{
353 return m_opaque_sp->GetEffectiveUserID();
354}
355
356uint32_t
357SBAttachInfo::GetEffectiveGroupID()
358{
359 return m_opaque_sp->GetEffectiveGroupID();
360}
361
362bool
363SBAttachInfo::EffectiveUserIDIsValid ()
364{
365 return m_opaque_sp->EffectiveUserIDIsValid();
366}
367
368bool
369SBAttachInfo::EffectiveGroupIDIsValid ()
370{
371 return m_opaque_sp->EffectiveGroupIDIsValid ();
372}
373
374void
375SBAttachInfo::SetEffectiveUserID (uint32_t uid)
376{
377 m_opaque_sp->SetEffectiveUserID(uid);
378}
379
380void
381SBAttachInfo::SetEffectiveGroupID (uint32_t gid)
382{
383 m_opaque_sp->SetEffectiveGroupID(gid);
384}
385
386lldb::pid_t
387SBAttachInfo::GetParentProcessID ()
388{
389 return m_opaque_sp->GetParentProcessID();
390}
391
392void
393SBAttachInfo::SetParentProcessID (lldb::pid_t pid)
394{
395 m_opaque_sp->SetParentProcessID (pid);
396}
397
398bool
399SBAttachInfo::ParentProcessIDIsValid()
400{
401 return m_opaque_sp->ParentProcessIDIsValid();
402}
403
404
Chris Lattner24943d22010-06-08 16:52:24 +0000405//----------------------------------------------------------------------
406// SBTarget constructor
407//----------------------------------------------------------------------
Greg Claytonc3b61d22010-12-15 05:08:08 +0000408SBTarget::SBTarget () :
409 m_opaque_sp ()
Chris Lattner24943d22010-06-08 16:52:24 +0000410{
411}
412
413SBTarget::SBTarget (const SBTarget& rhs) :
Greg Clayton63094e02010-06-23 01:19:29 +0000414 m_opaque_sp (rhs.m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000415{
416}
417
418SBTarget::SBTarget(const TargetSP& target_sp) :
Greg Clayton63094e02010-06-23 01:19:29 +0000419 m_opaque_sp (target_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000420{
421}
422
Greg Clayton538eb822010-11-05 23:17:00 +0000423const SBTarget&
424SBTarget::operator = (const SBTarget& rhs)
425{
426 if (this != &rhs)
427 m_opaque_sp = rhs.m_opaque_sp;
428 return *this;
429}
430
Chris Lattner24943d22010-06-08 16:52:24 +0000431//----------------------------------------------------------------------
432// Destructor
433//----------------------------------------------------------------------
434SBTarget::~SBTarget()
435{
436}
437
Jim Ingham5a15e692012-02-16 06:50:00 +0000438const char *
439SBTarget::GetBroadcasterClassName ()
440{
441 return Target::GetStaticBroadcasterClass().AsCString();
442}
443
Chris Lattner24943d22010-06-08 16:52:24 +0000444bool
445SBTarget::IsValid () const
446{
Greg Clayton63094e02010-06-23 01:19:29 +0000447 return m_opaque_sp.get() != NULL;
Chris Lattner24943d22010-06-08 16:52:24 +0000448}
449
450SBProcess
451SBTarget::GetProcess ()
452{
453 SBProcess sb_process;
Greg Clayton334d33a2012-01-30 07:41:31 +0000454 ProcessSP process_sp;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000455 TargetSP target_sp(GetSP());
456 if (target_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000457 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000458 process_sp = target_sp->GetProcessSP();
Greg Clayton334d33a2012-01-30 07:41:31 +0000459 sb_process.SetSP (process_sp);
Greg Claytonbdcda462010-12-20 20:49:23 +0000460 }
Caroline Tice7826c882010-10-26 03:11:13 +0000461
Greg Claytone005f2c2010-11-06 01:53:30 +0000462 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000463 if (log)
464 {
Greg Clayton49ce6822010-10-31 03:01:06 +0000465 log->Printf ("SBTarget(%p)::GetProcess () => SBProcess(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +0000466 target_sp.get(), process_sp.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000467 }
468
Chris Lattner24943d22010-06-08 16:52:24 +0000469 return sb_process;
470}
471
Greg Clayton63094e02010-06-23 01:19:29 +0000472SBDebugger
473SBTarget::GetDebugger () const
474{
475 SBDebugger debugger;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000476 TargetSP target_sp(GetSP());
477 if (target_sp)
478 debugger.reset (target_sp->GetDebugger().shared_from_this());
Greg Clayton63094e02010-06-23 01:19:29 +0000479 return debugger;
480}
481
Jim Inghamb5871fe2011-03-31 00:01:24 +0000482SBProcess
483SBTarget::LaunchSimple
484(
485 char const **argv,
486 char const **envp,
487 const char *working_directory
488)
489{
490 char *stdin_path = NULL;
491 char *stdout_path = NULL;
492 char *stderr_path = NULL;
493 uint32_t launch_flags = 0;
494 bool stop_at_entry = false;
495 SBError error;
496 SBListener listener = GetDebugger().GetListener();
497 return Launch (listener,
498 argv,
499 envp,
500 stdin_path,
501 stdout_path,
502 stderr_path,
503 working_directory,
504 launch_flags,
505 stop_at_entry,
506 error);
507}
Greg Claytonde915be2011-01-23 05:56:20 +0000508
509SBProcess
510SBTarget::Launch
511(
Greg Clayton271a5db2011-02-03 21:28:34 +0000512 SBListener &listener,
Greg Claytonde915be2011-01-23 05:56:20 +0000513 char const **argv,
514 char const **envp,
515 const char *stdin_path,
516 const char *stdout_path,
517 const char *stderr_path,
518 const char *working_directory,
519 uint32_t launch_flags, // See LaunchFlags
520 bool stop_at_entry,
521 lldb::SBError& error
522)
523{
Greg Claytone005f2c2010-11-06 01:53:30 +0000524 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000525
Greg Clayton0416bdf2012-01-30 09:04:36 +0000526 SBProcess sb_process;
527 ProcessSP process_sp;
528 TargetSP target_sp(GetSP());
529
Caroline Tice7826c882010-10-26 03:11:13 +0000530 if (log)
Greg Clayton3f5ee7f2010-10-29 04:59:35 +0000531 {
Greg Claytonde915be2011-01-23 05:56:20 +0000532 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))...",
Greg Clayton0416bdf2012-01-30 09:04:36 +0000533 target_sp.get(),
Greg Claytonde915be2011-01-23 05:56:20 +0000534 argv,
535 envp,
536 stdin_path ? stdin_path : "NULL",
537 stdout_path ? stdout_path : "NULL",
538 stderr_path ? stderr_path : "NULL",
539 working_directory ? working_directory : "NULL",
540 launch_flags,
541 stop_at_entry,
542 error.get());
Greg Clayton3f5ee7f2010-10-29 04:59:35 +0000543 }
Greg Clayton0416bdf2012-01-30 09:04:36 +0000544
545 if (target_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000546 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000547 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton1a3083a2010-10-06 03:53:16 +0000548
Greg Clayton7c330d62011-01-27 01:01:10 +0000549 if (getenv("LLDB_LAUNCH_FLAG_DISABLE_ASLR"))
550 launch_flags |= eLaunchFlagDisableASLR;
551
Greg Clayton180546b2011-04-30 01:09:13 +0000552 StateType state = eStateInvalid;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000553 process_sp = target_sp->GetProcessSP();
Greg Clayton334d33a2012-01-30 07:41:31 +0000554 if (process_sp)
Greg Clayton28d5fcc2011-01-27 06:44:37 +0000555 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000556 state = process_sp->GetState();
Greg Clayton180546b2011-04-30 01:09:13 +0000557
Greg Clayton334d33a2012-01-30 07:41:31 +0000558 if (process_sp->IsAlive() && state != eStateConnected)
Greg Clayton180546b2011-04-30 01:09:13 +0000559 {
560 if (state == eStateAttaching)
561 error.SetErrorString ("process attach is in progress");
562 else
563 error.SetErrorString ("a process is already being debugged");
Greg Clayton180546b2011-04-30 01:09:13 +0000564 return sb_process;
565 }
Greg Clayton28d5fcc2011-01-27 06:44:37 +0000566 }
567
Greg Clayton180546b2011-04-30 01:09:13 +0000568 if (state == eStateConnected)
569 {
570 // If we are already connected, then we have already specified the
571 // listener, so if a valid listener is supplied, we need to error out
572 // to let the client know.
573 if (listener.IsValid())
574 {
575 error.SetErrorString ("process is connected and already has a listener, pass empty listener");
Greg Clayton180546b2011-04-30 01:09:13 +0000576 return sb_process;
577 }
578 }
579 else
Greg Claytonc5f728c2010-10-06 22:10:17 +0000580 {
Greg Clayton271a5db2011-02-03 21:28:34 +0000581 if (listener.IsValid())
Greg Clayton46c9a352012-02-09 06:16:32 +0000582 process_sp = target_sp->CreateProcess (listener.ref(), NULL, NULL);
Greg Clayton271a5db2011-02-03 21:28:34 +0000583 else
Greg Clayton46c9a352012-02-09 06:16:32 +0000584 process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener(), NULL, NULL);
Greg Clayton180546b2011-04-30 01:09:13 +0000585 }
Greg Clayton7c330d62011-01-27 01:01:10 +0000586
Greg Clayton334d33a2012-01-30 07:41:31 +0000587 if (process_sp)
Greg Clayton180546b2011-04-30 01:09:13 +0000588 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000589 sb_process.SetSP (process_sp);
Greg Clayton180546b2011-04-30 01:09:13 +0000590 if (getenv("LLDB_LAUNCH_FLAG_DISABLE_STDIO"))
591 launch_flags |= eLaunchFlagDisableSTDIO;
592
Greg Clayton36bc5ea2011-11-03 21:22:33 +0000593 ProcessLaunchInfo launch_info (stdin_path, stdout_path, stderr_path, working_directory, launch_flags);
594
Greg Clayton0416bdf2012-01-30 09:04:36 +0000595 Module *exe_module = target_sp->GetExecutableModulePointer();
Greg Clayton36bc5ea2011-11-03 21:22:33 +0000596 if (exe_module)
Greg Clayton1d1f39e2011-11-29 04:03:30 +0000597 launch_info.SetExecutableFile(exe_module->GetPlatformFileSpec(), true);
Greg Clayton36bc5ea2011-11-03 21:22:33 +0000598 if (argv)
599 launch_info.GetArguments().AppendArguments (argv);
600 if (envp)
601 launch_info.GetEnvironmentEntries ().SetArguments (envp);
602
Greg Clayton334d33a2012-01-30 07:41:31 +0000603 error.SetError (process_sp->Launch (launch_info));
Greg Clayton180546b2011-04-30 01:09:13 +0000604 if (error.Success())
Greg Clayton7c330d62011-01-27 01:01:10 +0000605 {
Greg Clayton180546b2011-04-30 01:09:13 +0000606 // We we are stopping at the entry point, we can return now!
607 if (stop_at_entry)
608 return sb_process;
Greg Clayton7c330d62011-01-27 01:01:10 +0000609
Greg Clayton180546b2011-04-30 01:09:13 +0000610 // Make sure we are stopped at the entry
Greg Clayton334d33a2012-01-30 07:41:31 +0000611 StateType state = process_sp->WaitForProcessToStop (NULL);
Greg Clayton180546b2011-04-30 01:09:13 +0000612 if (state == eStateStopped)
Greg Clayton7c330d62011-01-27 01:01:10 +0000613 {
Greg Clayton180546b2011-04-30 01:09:13 +0000614 // resume the process to skip the entry point
Greg Clayton334d33a2012-01-30 07:41:31 +0000615 error.SetError (process_sp->Resume());
Greg Clayton180546b2011-04-30 01:09:13 +0000616 if (error.Success())
Greg Clayton7c330d62011-01-27 01:01:10 +0000617 {
Greg Clayton180546b2011-04-30 01:09:13 +0000618 // If we are doing synchronous mode, then wait for the
619 // process to stop yet again!
Greg Clayton0416bdf2012-01-30 09:04:36 +0000620 if (target_sp->GetDebugger().GetAsyncExecution () == false)
Greg Clayton334d33a2012-01-30 07:41:31 +0000621 process_sp->WaitForProcessToStop (NULL);
Greg Clayton7c330d62011-01-27 01:01:10 +0000622 }
623 }
624 }
Greg Clayton180546b2011-04-30 01:09:13 +0000625 }
626 else
627 {
628 error.SetErrorString ("unable to create lldb_private::Process");
Greg Claytonc5f728c2010-10-06 22:10:17 +0000629 }
630 }
631 else
632 {
633 error.SetErrorString ("SBTarget is invalid");
Chris Lattner24943d22010-06-08 16:52:24 +0000634 }
Caroline Tice7826c882010-10-26 03:11:13 +0000635
Caroline Tice926060e2010-10-29 21:48:37 +0000636 log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
Caroline Tice7826c882010-10-26 03:11:13 +0000637 if (log)
638 {
Greg Clayton49ce6822010-10-31 03:01:06 +0000639 log->Printf ("SBTarget(%p)::Launch (...) => SBProceess(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +0000640 target_sp.get(), process_sp.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000641 }
642
Greg Clayton1a3083a2010-10-06 03:53:16 +0000643 return sb_process;
Chris Lattner24943d22010-06-08 16:52:24 +0000644}
645
Greg Clayton0a8dcac2012-02-24 05:03:03 +0000646SBProcess
647SBTarget::Launch (SBLaunchInfo &sb_launch_info, SBError& error)
648{
649 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
650
651 SBProcess sb_process;
652 ProcessSP process_sp;
653 TargetSP target_sp(GetSP());
654
655 if (log)
656 {
657 log->Printf ("SBTarget(%p)::Launch (launch_info, error)...", target_sp.get());
658 }
659
660 if (target_sp)
661 {
662 Mutex::Locker api_locker (target_sp->GetAPIMutex());
663 StateType state = eStateInvalid;
664 process_sp = target_sp->GetProcessSP();
665 if (process_sp)
666 {
667 state = process_sp->GetState();
668
669 if (process_sp->IsAlive() && state != eStateConnected)
670 {
671 if (state == eStateAttaching)
672 error.SetErrorString ("process attach is in progress");
673 else
674 error.SetErrorString ("a process is already being debugged");
675 return sb_process;
676 }
677 }
678
679 if (state != eStateConnected)
680 process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener(), NULL, NULL);
681
682 if (process_sp)
683 {
684 sb_process.SetSP (process_sp);
685 lldb_private::ProcessLaunchInfo &launch_info = sb_launch_info.ref();
Greg Clayton98ca1e62012-02-24 20:59:25 +0000686
687 bool add_exe_as_first_argv = true; //launch_info.GetArguments().GetArgumentCount() == 0;
688 Module *exe_module = target_sp->GetExecutableModulePointer();
689 if (exe_module)
690 launch_info.SetExecutableFile(exe_module->GetPlatformFileSpec(), add_exe_as_first_argv);
691
692 const ArchSpec &arch_spec = target_sp->GetArchitecture();
693 if (arch_spec.IsValid())
694 launch_info.GetArchitecture () = arch_spec;
695
Greg Clayton0a8dcac2012-02-24 05:03:03 +0000696 error.SetError (process_sp->Launch (launch_info));
Greg Clayton98ca1e62012-02-24 20:59:25 +0000697 const bool synchronous_execution = target_sp->GetDebugger().GetAsyncExecution () == false;
Greg Clayton0a8dcac2012-02-24 05:03:03 +0000698 if (error.Success())
699 {
Greg Clayton98ca1e62012-02-24 20:59:25 +0000700 StateType state = eStateInvalid;
Greg Clayton0a8dcac2012-02-24 05:03:03 +0000701 if (launch_info.GetFlags().Test(eLaunchFlagStopAtEntry))
Greg Clayton98ca1e62012-02-24 20:59:25 +0000702 {
703 // If we are doing synchronous mode, then wait for the initial
704 // stop to happen, else, return and let the caller watch for
705 // the stop
706 if (synchronous_execution)
707 state = process_sp->WaitForProcessToStop (NULL);
708 // We we are stopping at the entry point, we can return now!
Greg Clayton0a8dcac2012-02-24 05:03:03 +0000709 return sb_process;
Greg Clayton98ca1e62012-02-24 20:59:25 +0000710 }
Greg Clayton0a8dcac2012-02-24 05:03:03 +0000711
712 // Make sure we are stopped at the entry
Greg Clayton98ca1e62012-02-24 20:59:25 +0000713 state = process_sp->WaitForProcessToStop (NULL);
Greg Clayton0a8dcac2012-02-24 05:03:03 +0000714 if (state == eStateStopped)
715 {
716 // resume the process to skip the entry point
717 error.SetError (process_sp->Resume());
718 if (error.Success())
719 {
720 // If we are doing synchronous mode, then wait for the
721 // process to stop yet again!
Greg Clayton98ca1e62012-02-24 20:59:25 +0000722 if (synchronous_execution)
Greg Clayton0a8dcac2012-02-24 05:03:03 +0000723 process_sp->WaitForProcessToStop (NULL);
724 }
725 }
726 }
727 }
728 else
729 {
730 error.SetErrorString ("unable to create lldb_private::Process");
731 }
732 }
733 else
734 {
735 error.SetErrorString ("SBTarget is invalid");
736 }
737
738 log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
739 if (log)
740 {
741 log->Printf ("SBTarget(%p)::Launch (...) => SBProceess(%p)",
742 target_sp.get(), process_sp.get());
743 }
744
745 return sb_process;
746}
747
748lldb::SBProcess
749SBTarget::Attach (SBAttachInfo &sb_attach_info, SBError& error)
750{
751 SBProcess sb_process;
752 ProcessSP process_sp;
753 TargetSP target_sp(GetSP());
754 if (target_sp)
755 {
756 Mutex::Locker api_locker (target_sp->GetAPIMutex());
757
758 StateType state = eStateInvalid;
759 process_sp = target_sp->GetProcessSP();
760 if (process_sp)
761 {
762 state = process_sp->GetState();
763
764 if (process_sp->IsAlive() && state != eStateConnected)
765 {
766 if (state == eStateAttaching)
767 error.SetErrorString ("process attach is in progress");
768 else
769 error.SetErrorString ("a process is already being debugged");
770 return sb_process;
771 }
772 }
773
774 if (state != eStateConnected)
775 process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener(), NULL, NULL);
776
777 if (process_sp)
778 {
779 sb_process.SetSP (process_sp);
780
781 ProcessAttachInfo &attach_info = sb_attach_info.ref();
782 error.SetError (process_sp->Attach (attach_info));
783 // If we are doing synchronous mode, then wait for the
784 // process to stop!
785 if (target_sp->GetDebugger().GetAsyncExecution () == false)
786 process_sp->WaitForProcessToStop (NULL);
787 }
788 else
789 {
790 error.SetErrorString ("unable to create lldb_private::Process");
791 }
792 }
793 else
794 {
795 error.SetErrorString ("SBTarget is invalid");
796 }
797 return sb_process;
798}
799
800
Greg Claytond5b0b442011-12-02 02:10:57 +0000801#if defined(__APPLE__)
802
803lldb::SBProcess
804SBTarget::AttachToProcessWithID (SBListener &listener,
805 ::pid_t pid,
806 lldb::SBError& error)
807{
808 return AttachToProcessWithID (listener, (lldb::pid_t)pid, error);
809}
810
811#endif // #if defined(__APPLE__)
Greg Claytonc5f728c2010-10-06 22:10:17 +0000812
813lldb::SBProcess
Greg Claytond8c62532010-10-07 04:19:01 +0000814SBTarget::AttachToProcessWithID
Greg Claytonc5f728c2010-10-06 22:10:17 +0000815(
Greg Clayton271a5db2011-02-03 21:28:34 +0000816 SBListener &listener,
Greg Claytonc5f728c2010-10-06 22:10:17 +0000817 lldb::pid_t pid,// The process ID to attach to
818 SBError& error // An error explaining what went wrong if attach fails
819)
820{
821 SBProcess sb_process;
Greg Clayton334d33a2012-01-30 07:41:31 +0000822 ProcessSP process_sp;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000823 TargetSP target_sp(GetSP());
824 if (target_sp)
Greg Claytonc5f728c2010-10-06 22:10:17 +0000825 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000826 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytonde1dd812011-06-24 03:21:43 +0000827
828 StateType state = eStateInvalid;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000829 process_sp = target_sp->GetProcessSP();
Greg Clayton334d33a2012-01-30 07:41:31 +0000830 if (process_sp)
Greg Claytonde1dd812011-06-24 03:21:43 +0000831 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000832 state = process_sp->GetState();
Greg Claytonde1dd812011-06-24 03:21:43 +0000833
Greg Clayton334d33a2012-01-30 07:41:31 +0000834 if (process_sp->IsAlive() && state != eStateConnected)
Greg Claytonde1dd812011-06-24 03:21:43 +0000835 {
836 if (state == eStateAttaching)
837 error.SetErrorString ("process attach is in progress");
838 else
839 error.SetErrorString ("a process is already being debugged");
Greg Claytonde1dd812011-06-24 03:21:43 +0000840 return sb_process;
841 }
842 }
843
844 if (state == eStateConnected)
845 {
846 // If we are already connected, then we have already specified the
847 // listener, so if a valid listener is supplied, we need to error out
848 // to let the client know.
849 if (listener.IsValid())
850 {
851 error.SetErrorString ("process is connected and already has a listener, pass empty listener");
Greg Claytonde1dd812011-06-24 03:21:43 +0000852 return sb_process;
853 }
854 }
Greg Clayton271a5db2011-02-03 21:28:34 +0000855 else
Greg Claytonde1dd812011-06-24 03:21:43 +0000856 {
857 if (listener.IsValid())
Greg Clayton46c9a352012-02-09 06:16:32 +0000858 process_sp = target_sp->CreateProcess (listener.ref(), NULL, NULL);
Greg Claytonde1dd812011-06-24 03:21:43 +0000859 else
Greg Clayton46c9a352012-02-09 06:16:32 +0000860 process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener(), NULL, NULL);
Greg Claytonde1dd812011-06-24 03:21:43 +0000861 }
Greg Clayton334d33a2012-01-30 07:41:31 +0000862 if (process_sp)
Greg Claytonc5f728c2010-10-06 22:10:17 +0000863 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000864 sb_process.SetSP (process_sp);
865
Greg Clayton527154d2011-11-15 03:53:30 +0000866 ProcessAttachInfo attach_info;
867 attach_info.SetProcessID (pid);
Greg Clayton334d33a2012-01-30 07:41:31 +0000868 error.SetError (process_sp->Attach (attach_info));
Johnny Chen535960e2011-06-17 00:51:15 +0000869 // If we are doing synchronous mode, then wait for the
870 // process to stop!
Greg Clayton0416bdf2012-01-30 09:04:36 +0000871 if (target_sp->GetDebugger().GetAsyncExecution () == false)
Greg Clayton334d33a2012-01-30 07:41:31 +0000872 process_sp->WaitForProcessToStop (NULL);
Greg Claytonc5f728c2010-10-06 22:10:17 +0000873 }
874 else
875 {
876 error.SetErrorString ("unable to create lldb_private::Process");
877 }
878 }
879 else
880 {
881 error.SetErrorString ("SBTarget is invalid");
882 }
883 return sb_process;
884
885}
886
887lldb::SBProcess
Greg Claytond8c62532010-10-07 04:19:01 +0000888SBTarget::AttachToProcessWithName
Greg Claytonc5f728c2010-10-06 22:10:17 +0000889(
Greg Clayton271a5db2011-02-03 21:28:34 +0000890 SBListener &listener,
Greg Claytonc5f728c2010-10-06 22:10:17 +0000891 const char *name, // basename of process to attach to
892 bool wait_for, // if true wait for a new instance of "name" to be launched
893 SBError& error // An error explaining what went wrong if attach fails
894)
895{
896 SBProcess sb_process;
Greg Clayton334d33a2012-01-30 07:41:31 +0000897 ProcessSP process_sp;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000898 TargetSP target_sp(GetSP());
899 if (name && target_sp)
Greg Claytonc5f728c2010-10-06 22:10:17 +0000900 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000901 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytonbdcda462010-12-20 20:49:23 +0000902
Greg Claytonde1dd812011-06-24 03:21:43 +0000903 StateType state = eStateInvalid;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000904 process_sp = target_sp->GetProcessSP();
Greg Clayton334d33a2012-01-30 07:41:31 +0000905 if (process_sp)
Greg Claytonde1dd812011-06-24 03:21:43 +0000906 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000907 state = process_sp->GetState();
Greg Claytonde1dd812011-06-24 03:21:43 +0000908
Greg Clayton334d33a2012-01-30 07:41:31 +0000909 if (process_sp->IsAlive() && state != eStateConnected)
Greg Claytonde1dd812011-06-24 03:21:43 +0000910 {
911 if (state == eStateAttaching)
912 error.SetErrorString ("process attach is in progress");
913 else
914 error.SetErrorString ("a process is already being debugged");
Greg Claytonde1dd812011-06-24 03:21:43 +0000915 return sb_process;
916 }
917 }
918
919 if (state == eStateConnected)
920 {
921 // If we are already connected, then we have already specified the
922 // listener, so if a valid listener is supplied, we need to error out
923 // to let the client know.
924 if (listener.IsValid())
925 {
926 error.SetErrorString ("process is connected and already has a listener, pass empty listener");
Greg Claytonde1dd812011-06-24 03:21:43 +0000927 return sb_process;
928 }
929 }
Greg Clayton271a5db2011-02-03 21:28:34 +0000930 else
Greg Claytonde1dd812011-06-24 03:21:43 +0000931 {
932 if (listener.IsValid())
Greg Clayton46c9a352012-02-09 06:16:32 +0000933 process_sp = target_sp->CreateProcess (listener.ref(), NULL, NULL);
Greg Claytonde1dd812011-06-24 03:21:43 +0000934 else
Greg Clayton46c9a352012-02-09 06:16:32 +0000935 process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener(), NULL, NULL);
Greg Claytonde1dd812011-06-24 03:21:43 +0000936 }
Greg Claytonc5f728c2010-10-06 22:10:17 +0000937
Greg Clayton334d33a2012-01-30 07:41:31 +0000938 if (process_sp)
Greg Claytonc5f728c2010-10-06 22:10:17 +0000939 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000940 sb_process.SetSP (process_sp);
Greg Clayton527154d2011-11-15 03:53:30 +0000941 ProcessAttachInfo attach_info;
942 attach_info.GetExecutableFile().SetFile(name, false);
943 attach_info.SetWaitForLaunch(wait_for);
Greg Clayton334d33a2012-01-30 07:41:31 +0000944 error.SetError (process_sp->Attach (attach_info));
Johnny Chen58d02ff2011-06-17 19:21:30 +0000945 // If we are doing synchronous mode, then wait for the
946 // process to stop!
Greg Clayton0416bdf2012-01-30 09:04:36 +0000947 if (target_sp->GetDebugger().GetAsyncExecution () == false)
Greg Clayton334d33a2012-01-30 07:41:31 +0000948 process_sp->WaitForProcessToStop (NULL);
Greg Claytonc5f728c2010-10-06 22:10:17 +0000949 }
950 else
951 {
952 error.SetErrorString ("unable to create lldb_private::Process");
953 }
954 }
955 else
956 {
957 error.SetErrorString ("SBTarget is invalid");
958 }
959 return sb_process;
960
961}
962
James McIlree38093402011-03-04 00:31:13 +0000963lldb::SBProcess
964SBTarget::ConnectRemote
965(
966 SBListener &listener,
967 const char *url,
968 const char *plugin_name,
969 SBError& error
970)
971{
972 SBProcess sb_process;
Greg Clayton334d33a2012-01-30 07:41:31 +0000973 ProcessSP process_sp;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000974 TargetSP target_sp(GetSP());
975 if (target_sp)
James McIlree38093402011-03-04 00:31:13 +0000976 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000977 Mutex::Locker api_locker (target_sp->GetAPIMutex());
James McIlree38093402011-03-04 00:31:13 +0000978 if (listener.IsValid())
Greg Clayton46c9a352012-02-09 06:16:32 +0000979 process_sp = target_sp->CreateProcess (listener.ref(), plugin_name, NULL);
James McIlree38093402011-03-04 00:31:13 +0000980 else
Greg Clayton46c9a352012-02-09 06:16:32 +0000981 process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener(), plugin_name, NULL);
James McIlree38093402011-03-04 00:31:13 +0000982
983
Greg Clayton334d33a2012-01-30 07:41:31 +0000984 if (process_sp)
James McIlree38093402011-03-04 00:31:13 +0000985 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000986 sb_process.SetSP (process_sp);
987 error.SetError (process_sp->ConnectRemote (url));
James McIlree38093402011-03-04 00:31:13 +0000988 }
989 else
990 {
991 error.SetErrorString ("unable to create lldb_private::Process");
992 }
993 }
994 else
995 {
996 error.SetErrorString ("SBTarget is invalid");
997 }
998 return sb_process;
999}
1000
Chris Lattner24943d22010-06-08 16:52:24 +00001001SBFileSpec
1002SBTarget::GetExecutable ()
1003{
Caroline Tice7826c882010-10-26 03:11:13 +00001004
Chris Lattner24943d22010-06-08 16:52:24 +00001005 SBFileSpec exe_file_spec;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001006 TargetSP target_sp(GetSP());
1007 if (target_sp)
Chris Lattner24943d22010-06-08 16:52:24 +00001008 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001009 Module *exe_module = target_sp->GetExecutableModulePointer();
Greg Clayton5beb99d2011-08-11 02:48:45 +00001010 if (exe_module)
1011 exe_file_spec.SetFileSpec (exe_module->GetFileSpec());
Chris Lattner24943d22010-06-08 16:52:24 +00001012 }
Caroline Tice7826c882010-10-26 03:11:13 +00001013
Greg Claytone005f2c2010-11-06 01:53:30 +00001014 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001015 if (log)
1016 {
Greg Clayton49ce6822010-10-31 03:01:06 +00001017 log->Printf ("SBTarget(%p)::GetExecutable () => SBFileSpec(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +00001018 target_sp.get(), exe_file_spec.get());
Caroline Tice7826c882010-10-26 03:11:13 +00001019 }
1020
Chris Lattner24943d22010-06-08 16:52:24 +00001021 return exe_file_spec;
1022}
1023
Chris Lattner24943d22010-06-08 16:52:24 +00001024bool
Chris Lattner24943d22010-06-08 16:52:24 +00001025SBTarget::operator == (const SBTarget &rhs) const
1026{
Greg Clayton63094e02010-06-23 01:19:29 +00001027 return m_opaque_sp.get() == rhs.m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +00001028}
1029
1030bool
1031SBTarget::operator != (const SBTarget &rhs) const
1032{
Greg Clayton63094e02010-06-23 01:19:29 +00001033 return m_opaque_sp.get() != rhs.m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +00001034}
1035
Greg Clayton334d33a2012-01-30 07:41:31 +00001036lldb::TargetSP
1037SBTarget::GetSP () const
Greg Clayton15afa9f2011-10-01 02:59:24 +00001038{
1039 return m_opaque_sp;
1040}
1041
Greg Clayton63094e02010-06-23 01:19:29 +00001042void
Greg Clayton334d33a2012-01-30 07:41:31 +00001043SBTarget::SetSP (const lldb::TargetSP& target_sp)
Greg Clayton63094e02010-06-23 01:19:29 +00001044{
1045 m_opaque_sp = target_sp;
Chris Lattner24943d22010-06-08 16:52:24 +00001046}
1047
Greg Claytona3955062011-07-22 16:46:35 +00001048lldb::SBAddress
1049SBTarget::ResolveLoadAddress (lldb::addr_t vm_addr)
Greg Claytonea49cc72010-12-12 19:25:26 +00001050{
Greg Claytona3955062011-07-22 16:46:35 +00001051 lldb::SBAddress sb_addr;
1052 Address &addr = sb_addr.ref();
Greg Clayton0416bdf2012-01-30 09:04:36 +00001053 TargetSP target_sp(GetSP());
1054 if (target_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +00001055 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001056 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1057 if (target_sp->GetSectionLoadList().ResolveLoadAddress (vm_addr, addr))
Greg Claytona3955062011-07-22 16:46:35 +00001058 return sb_addr;
Greg Claytonbdcda462010-12-20 20:49:23 +00001059 }
Greg Claytonea49cc72010-12-12 19:25:26 +00001060
Greg Claytona3955062011-07-22 16:46:35 +00001061 // We have a load address that isn't in a section, just return an address
1062 // with the offset filled in (the address) and the section set to NULL
Greg Clayton3508c382012-02-24 01:59:29 +00001063 addr.SetRawAddress(vm_addr);
Greg Claytona3955062011-07-22 16:46:35 +00001064 return sb_addr;
Greg Claytonea49cc72010-12-12 19:25:26 +00001065}
1066
Greg Claytonafb81862011-03-02 21:34:46 +00001067SBSymbolContext
1068SBTarget::ResolveSymbolContextForAddress (const SBAddress& addr, uint32_t resolve_scope)
1069{
1070 SBSymbolContext sc;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001071 if (addr.IsValid())
1072 {
1073 TargetSP target_sp(GetSP());
1074 if (target_sp)
1075 target_sp->GetImages().ResolveSymbolContextForAddress (addr.ref(), resolve_scope, sc.ref());
1076 }
Greg Claytonafb81862011-03-02 21:34:46 +00001077 return sc;
1078}
1079
1080
Chris Lattner24943d22010-06-08 16:52:24 +00001081SBBreakpoint
1082SBTarget::BreakpointCreateByLocation (const char *file, uint32_t line)
1083{
Greg Claytond6d806c2010-11-08 00:28:40 +00001084 return SBBreakpoint(BreakpointCreateByLocation (SBFileSpec (file, false), line));
Chris Lattner24943d22010-06-08 16:52:24 +00001085}
1086
1087SBBreakpoint
1088SBTarget::BreakpointCreateByLocation (const SBFileSpec &sb_file_spec, uint32_t line)
1089{
Greg Claytone005f2c2010-11-06 01:53:30 +00001090 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001091
Chris Lattner24943d22010-06-08 16:52:24 +00001092 SBBreakpoint sb_bp;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001093 TargetSP target_sp(GetSP());
1094 if (target_sp && line != 0)
Greg Claytonbdcda462010-12-20 20:49:23 +00001095 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001096 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1097 *sb_bp = target_sp->CreateBreakpoint (NULL, *sb_file_spec, line, true, false);
Greg Claytonbdcda462010-12-20 20:49:23 +00001098 }
Caroline Tice7826c882010-10-26 03:11:13 +00001099
1100 if (log)
1101 {
1102 SBStream sstr;
1103 sb_bp.GetDescription (sstr);
Greg Clayton49ce6822010-10-31 03:01:06 +00001104 char path[PATH_MAX];
1105 sb_file_spec->GetPath (path, sizeof(path));
1106 log->Printf ("SBTarget(%p)::BreakpointCreateByLocation ( %s:%u ) => SBBreakpoint(%p): %s",
Greg Clayton0416bdf2012-01-30 09:04:36 +00001107 target_sp.get(),
Greg Clayton49ce6822010-10-31 03:01:06 +00001108 path,
Greg Claytona66ba462010-10-30 04:51:46 +00001109 line,
Greg Clayton49ce6822010-10-31 03:01:06 +00001110 sb_bp.get(),
Caroline Tice7826c882010-10-26 03:11:13 +00001111 sstr.GetData());
1112 }
1113
Chris Lattner24943d22010-06-08 16:52:24 +00001114 return sb_bp;
1115}
1116
1117SBBreakpoint
1118SBTarget::BreakpointCreateByName (const char *symbol_name, const char *module_name)
1119{
Greg Claytone005f2c2010-11-06 01:53:30 +00001120 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001121
Chris Lattner24943d22010-06-08 16:52:24 +00001122 SBBreakpoint sb_bp;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001123 TargetSP target_sp(GetSP());
1124 if (target_sp.get())
Chris Lattner24943d22010-06-08 16:52:24 +00001125 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001126 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Chris Lattner24943d22010-06-08 16:52:24 +00001127 if (module_name && module_name[0])
1128 {
Jim Ingham03c8ee52011-09-21 01:17:13 +00001129 FileSpecList module_spec_list;
1130 module_spec_list.Append (FileSpec (module_name, false));
Greg Clayton0416bdf2012-01-30 09:04:36 +00001131 *sb_bp = target_sp->CreateBreakpoint (&module_spec_list, NULL, symbol_name, eFunctionNameTypeAuto, false);
Chris Lattner24943d22010-06-08 16:52:24 +00001132 }
1133 else
1134 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001135 *sb_bp = target_sp->CreateBreakpoint (NULL, NULL, symbol_name, eFunctionNameTypeAuto, false);
Chris Lattner24943d22010-06-08 16:52:24 +00001136 }
1137 }
Caroline Tice7826c882010-10-26 03:11:13 +00001138
1139 if (log)
1140 {
Greg Clayton49ce6822010-10-31 03:01:06 +00001141 log->Printf ("SBTarget(%p)::BreakpointCreateByName (symbol=\"%s\", module=\"%s\") => SBBreakpoint(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +00001142 target_sp.get(), symbol_name, module_name, sb_bp.get());
Caroline Tice7826c882010-10-26 03:11:13 +00001143 }
1144
Chris Lattner24943d22010-06-08 16:52:24 +00001145 return sb_bp;
1146}
1147
Jim Inghamd6d47972011-09-23 00:54:11 +00001148lldb::SBBreakpoint
1149SBTarget::BreakpointCreateByName (const char *symbol_name,
1150 const SBFileSpecList &module_list,
1151 const SBFileSpecList &comp_unit_list)
1152{
Jim Ingham1fb8a2d2011-10-11 01:18:55 +00001153 uint32_t name_type_mask = eFunctionNameTypeAuto;
1154 return BreakpointCreateByName (symbol_name, name_type_mask, module_list, comp_unit_list);
1155}
1156
1157lldb::SBBreakpoint
1158SBTarget::BreakpointCreateByName (const char *symbol_name,
1159 uint32_t name_type_mask,
1160 const SBFileSpecList &module_list,
1161 const SBFileSpecList &comp_unit_list)
1162{
Jim Inghamd6d47972011-09-23 00:54:11 +00001163 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1164
1165 SBBreakpoint sb_bp;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001166 TargetSP target_sp(GetSP());
1167 if (target_sp && symbol_name && symbol_name[0])
Jim Inghamd6d47972011-09-23 00:54:11 +00001168 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001169 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1170 *sb_bp = target_sp->CreateBreakpoint (module_list.get(),
Jim Inghamd6d47972011-09-23 00:54:11 +00001171 comp_unit_list.get(),
1172 symbol_name,
Jim Ingham1fb8a2d2011-10-11 01:18:55 +00001173 name_type_mask,
Jim Inghamd6d47972011-09-23 00:54:11 +00001174 false);
1175 }
1176
1177 if (log)
1178 {
Jim Ingham1fb8a2d2011-10-11 01:18:55 +00001179 log->Printf ("SBTarget(%p)::BreakpointCreateByName (symbol=\"%s\", name_type: %d) => SBBreakpoint(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +00001180 target_sp.get(), symbol_name, name_type_mask, sb_bp.get());
Jim Inghamd6d47972011-09-23 00:54:11 +00001181 }
1182
1183 return sb_bp;
1184}
1185
1186
Chris Lattner24943d22010-06-08 16:52:24 +00001187SBBreakpoint
1188SBTarget::BreakpointCreateByRegex (const char *symbol_name_regex, const char *module_name)
1189{
Greg Claytone005f2c2010-11-06 01:53:30 +00001190 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001191
Chris Lattner24943d22010-06-08 16:52:24 +00001192 SBBreakpoint sb_bp;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001193 TargetSP target_sp(GetSP());
1194 if (target_sp && symbol_name_regex && symbol_name_regex[0])
Chris Lattner24943d22010-06-08 16:52:24 +00001195 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001196 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Chris Lattner24943d22010-06-08 16:52:24 +00001197 RegularExpression regexp(symbol_name_regex);
1198
1199 if (module_name && module_name[0])
1200 {
Jim Ingham03c8ee52011-09-21 01:17:13 +00001201 FileSpecList module_spec_list;
1202 module_spec_list.Append (FileSpec (module_name, false));
Chris Lattner24943d22010-06-08 16:52:24 +00001203
Greg Clayton0416bdf2012-01-30 09:04:36 +00001204 *sb_bp = target_sp->CreateFuncRegexBreakpoint (&module_spec_list, NULL, regexp, false);
Chris Lattner24943d22010-06-08 16:52:24 +00001205 }
1206 else
1207 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001208 *sb_bp = target_sp->CreateFuncRegexBreakpoint (NULL, NULL, regexp, false);
Chris Lattner24943d22010-06-08 16:52:24 +00001209 }
1210 }
Caroline Tice7826c882010-10-26 03:11:13 +00001211
1212 if (log)
1213 {
Greg Clayton49ce6822010-10-31 03:01:06 +00001214 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (symbol_regex=\"%s\", module_name=\"%s\") => SBBreakpoint(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +00001215 target_sp.get(), symbol_name_regex, module_name, sb_bp.get());
Caroline Tice7826c882010-10-26 03:11:13 +00001216 }
1217
Chris Lattner24943d22010-06-08 16:52:24 +00001218 return sb_bp;
1219}
1220
Jim Inghamd6d47972011-09-23 00:54:11 +00001221lldb::SBBreakpoint
1222SBTarget::BreakpointCreateByRegex (const char *symbol_name_regex,
1223 const SBFileSpecList &module_list,
1224 const SBFileSpecList &comp_unit_list)
1225{
1226 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Chris Lattner24943d22010-06-08 16:52:24 +00001227
Jim Inghamd6d47972011-09-23 00:54:11 +00001228 SBBreakpoint sb_bp;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001229 TargetSP target_sp(GetSP());
1230 if (target_sp && symbol_name_regex && symbol_name_regex[0])
Jim Inghamd6d47972011-09-23 00:54:11 +00001231 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001232 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Jim Inghamd6d47972011-09-23 00:54:11 +00001233 RegularExpression regexp(symbol_name_regex);
1234
Greg Clayton0416bdf2012-01-30 09:04:36 +00001235 *sb_bp = target_sp->CreateFuncRegexBreakpoint (module_list.get(), comp_unit_list.get(), regexp, false);
Jim Inghamd6d47972011-09-23 00:54:11 +00001236 }
1237
1238 if (log)
1239 {
1240 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (symbol_regex=\"%s\") => SBBreakpoint(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +00001241 target_sp.get(), symbol_name_regex, sb_bp.get());
Jim Inghamd6d47972011-09-23 00:54:11 +00001242 }
1243
1244 return sb_bp;
1245}
Chris Lattner24943d22010-06-08 16:52:24 +00001246
1247SBBreakpoint
1248SBTarget::BreakpointCreateByAddress (addr_t address)
1249{
Greg Claytone005f2c2010-11-06 01:53:30 +00001250 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001251
Chris Lattner24943d22010-06-08 16:52:24 +00001252 SBBreakpoint sb_bp;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001253 TargetSP target_sp(GetSP());
1254 if (target_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +00001255 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001256 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1257 *sb_bp = target_sp->CreateBreakpoint (address, false);
Greg Claytonbdcda462010-12-20 20:49:23 +00001258 }
Caroline Tice7826c882010-10-26 03:11:13 +00001259
1260 if (log)
1261 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001262 log->Printf ("SBTarget(%p)::BreakpointCreateByAddress (address=%llu) => SBBreakpoint(%p)", target_sp.get(), (uint64_t) address, sb_bp.get());
Caroline Tice7826c882010-10-26 03:11:13 +00001263 }
1264
Chris Lattner24943d22010-06-08 16:52:24 +00001265 return sb_bp;
1266}
1267
Jim Ingham03c8ee52011-09-21 01:17:13 +00001268lldb::SBBreakpoint
1269SBTarget::BreakpointCreateBySourceRegex (const char *source_regex, const lldb::SBFileSpec &source_file, const char *module_name)
1270{
1271 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1272
1273 SBBreakpoint sb_bp;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001274 TargetSP target_sp(GetSP());
1275 if (target_sp && source_regex && source_regex[0])
Jim Ingham03c8ee52011-09-21 01:17:13 +00001276 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001277 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Jim Ingham03c8ee52011-09-21 01:17:13 +00001278 RegularExpression regexp(source_regex);
Jim Inghamd6d47972011-09-23 00:54:11 +00001279 FileSpecList source_file_spec_list;
1280 source_file_spec_list.Append (source_file.ref());
Jim Ingham03c8ee52011-09-21 01:17:13 +00001281
1282 if (module_name && module_name[0])
1283 {
1284 FileSpecList module_spec_list;
1285 module_spec_list.Append (FileSpec (module_name, false));
1286
Greg Clayton0416bdf2012-01-30 09:04:36 +00001287 *sb_bp = target_sp->CreateSourceRegexBreakpoint (&module_spec_list, &source_file_spec_list, regexp, false);
Jim Ingham03c8ee52011-09-21 01:17:13 +00001288 }
1289 else
1290 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001291 *sb_bp = target_sp->CreateSourceRegexBreakpoint (NULL, &source_file_spec_list, regexp, false);
Jim Ingham03c8ee52011-09-21 01:17:13 +00001292 }
1293 }
1294
1295 if (log)
1296 {
1297 char path[PATH_MAX];
1298 source_file->GetPath (path, sizeof(path));
1299 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (source_regex=\"%s\", file=\"%s\", module_name=\"%s\") => SBBreakpoint(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +00001300 target_sp.get(), source_regex, path, module_name, sb_bp.get());
Jim Ingham03c8ee52011-09-21 01:17:13 +00001301 }
1302
1303 return sb_bp;
1304}
1305
Jim Inghamd6d47972011-09-23 00:54:11 +00001306lldb::SBBreakpoint
1307SBTarget::BreakpointCreateBySourceRegex (const char *source_regex,
1308 const SBFileSpecList &module_list,
1309 const lldb::SBFileSpecList &source_file_list)
1310{
1311 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1312
1313 SBBreakpoint sb_bp;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001314 TargetSP target_sp(GetSP());
1315 if (target_sp && source_regex && source_regex[0])
Jim Inghamd6d47972011-09-23 00:54:11 +00001316 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001317 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Jim Inghamd6d47972011-09-23 00:54:11 +00001318 RegularExpression regexp(source_regex);
Greg Clayton0416bdf2012-01-30 09:04:36 +00001319 *sb_bp = target_sp->CreateSourceRegexBreakpoint (module_list.get(), source_file_list.get(), regexp, false);
Jim Inghamd6d47972011-09-23 00:54:11 +00001320 }
1321
1322 if (log)
1323 {
1324 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (source_regex=\"%s\") => SBBreakpoint(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +00001325 target_sp.get(), source_regex, sb_bp.get());
Jim Inghamd6d47972011-09-23 00:54:11 +00001326 }
1327
1328 return sb_bp;
1329}
Jim Ingham03c8ee52011-09-21 01:17:13 +00001330
Greg Claytonc7f5d5c2010-07-23 23:33:17 +00001331uint32_t
1332SBTarget::GetNumBreakpoints () const
1333{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001334 TargetSP target_sp(GetSP());
1335 if (target_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +00001336 {
1337 // The breakpoint list is thread safe, no need to lock
Greg Clayton0416bdf2012-01-30 09:04:36 +00001338 return target_sp->GetBreakpointList().GetSize();
Greg Claytonbdcda462010-12-20 20:49:23 +00001339 }
Greg Claytonc7f5d5c2010-07-23 23:33:17 +00001340 return 0;
1341}
1342
1343SBBreakpoint
1344SBTarget::GetBreakpointAtIndex (uint32_t idx) const
1345{
1346 SBBreakpoint sb_breakpoint;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001347 TargetSP target_sp(GetSP());
1348 if (target_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +00001349 {
1350 // The breakpoint list is thread safe, no need to lock
Greg Clayton0416bdf2012-01-30 09:04:36 +00001351 *sb_breakpoint = target_sp->GetBreakpointList().GetBreakpointAtIndex(idx);
Greg Claytonbdcda462010-12-20 20:49:23 +00001352 }
Greg Claytonc7f5d5c2010-07-23 23:33:17 +00001353 return sb_breakpoint;
1354}
Chris Lattner24943d22010-06-08 16:52:24 +00001355
1356bool
1357SBTarget::BreakpointDelete (break_id_t bp_id)
1358{
Greg Claytone005f2c2010-11-06 01:53:30 +00001359 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001360
Caroline Tice7826c882010-10-26 03:11:13 +00001361 bool result = false;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001362 TargetSP target_sp(GetSP());
1363 if (target_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +00001364 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001365 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1366 result = target_sp->RemoveBreakpointByID (bp_id);
Greg Claytonbdcda462010-12-20 20:49:23 +00001367 }
Caroline Tice7826c882010-10-26 03:11:13 +00001368
1369 if (log)
1370 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001371 log->Printf ("SBTarget(%p)::BreakpointDelete (bp_id=%d) => %i", target_sp.get(), (uint32_t) bp_id, result);
Caroline Tice7826c882010-10-26 03:11:13 +00001372 }
1373
1374 return result;
Chris Lattner24943d22010-06-08 16:52:24 +00001375}
1376
Johnny Chen096c2932011-09-26 22:40:50 +00001377SBBreakpoint
1378SBTarget::FindBreakpointByID (break_id_t bp_id)
1379{
1380 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1381
1382 SBBreakpoint sb_breakpoint;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001383 TargetSP target_sp(GetSP());
1384 if (target_sp && bp_id != LLDB_INVALID_BREAK_ID)
Johnny Chen096c2932011-09-26 22:40:50 +00001385 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001386 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1387 *sb_breakpoint = target_sp->GetBreakpointByID (bp_id);
Johnny Chen096c2932011-09-26 22:40:50 +00001388 }
1389
1390 if (log)
1391 {
1392 log->Printf ("SBTarget(%p)::FindBreakpointByID (bp_id=%d) => SBBreakpoint(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +00001393 target_sp.get(), (uint32_t) bp_id, sb_breakpoint.get());
Johnny Chen096c2932011-09-26 22:40:50 +00001394 }
1395
1396 return sb_breakpoint;
1397}
1398
Chris Lattner24943d22010-06-08 16:52:24 +00001399bool
1400SBTarget::EnableAllBreakpoints ()
1401{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001402 TargetSP target_sp(GetSP());
1403 if (target_sp)
Chris Lattner24943d22010-06-08 16:52:24 +00001404 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001405 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1406 target_sp->EnableAllBreakpoints ();
Chris Lattner24943d22010-06-08 16:52:24 +00001407 return true;
1408 }
1409 return false;
1410}
1411
1412bool
1413SBTarget::DisableAllBreakpoints ()
1414{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001415 TargetSP target_sp(GetSP());
1416 if (target_sp)
Chris Lattner24943d22010-06-08 16:52:24 +00001417 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001418 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1419 target_sp->DisableAllBreakpoints ();
Chris Lattner24943d22010-06-08 16:52:24 +00001420 return true;
1421 }
1422 return false;
1423}
1424
1425bool
1426SBTarget::DeleteAllBreakpoints ()
1427{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001428 TargetSP target_sp(GetSP());
1429 if (target_sp)
Chris Lattner24943d22010-06-08 16:52:24 +00001430 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001431 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1432 target_sp->RemoveAllBreakpoints ();
Chris Lattner24943d22010-06-08 16:52:24 +00001433 return true;
1434 }
1435 return false;
1436}
1437
Johnny Chen096c2932011-09-26 22:40:50 +00001438uint32_t
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001439SBTarget::GetNumWatchpoints () const
Johnny Chen096c2932011-09-26 22:40:50 +00001440{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001441 TargetSP target_sp(GetSP());
1442 if (target_sp)
Johnny Chen096c2932011-09-26 22:40:50 +00001443 {
Johnny Chenecd4feb2011-10-14 00:42:25 +00001444 // The watchpoint list is thread safe, no need to lock
Greg Clayton0416bdf2012-01-30 09:04:36 +00001445 return target_sp->GetWatchpointList().GetSize();
Johnny Chen096c2932011-09-26 22:40:50 +00001446 }
1447 return 0;
1448}
1449
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001450SBWatchpoint
1451SBTarget::GetWatchpointAtIndex (uint32_t idx) const
Johnny Chen5eb54bb2011-09-27 20:29:45 +00001452{
Johnny Chenecd4feb2011-10-14 00:42:25 +00001453 SBWatchpoint sb_watchpoint;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001454 TargetSP target_sp(GetSP());
1455 if (target_sp)
Johnny Chen096c2932011-09-26 22:40:50 +00001456 {
Johnny Chenecd4feb2011-10-14 00:42:25 +00001457 // The watchpoint list is thread safe, no need to lock
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001458 sb_watchpoint.SetSP (target_sp->GetWatchpointList().GetByIndex(idx));
Johnny Chen096c2932011-09-26 22:40:50 +00001459 }
Johnny Chenecd4feb2011-10-14 00:42:25 +00001460 return sb_watchpoint;
Johnny Chen096c2932011-09-26 22:40:50 +00001461}
1462
1463bool
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001464SBTarget::DeleteWatchpoint (watch_id_t wp_id)
Johnny Chen096c2932011-09-26 22:40:50 +00001465{
1466 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1467
1468 bool result = false;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001469 TargetSP target_sp(GetSP());
1470 if (target_sp)
Johnny Chen096c2932011-09-26 22:40:50 +00001471 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001472 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1473 result = target_sp->RemoveWatchpointByID (wp_id);
Johnny Chen096c2932011-09-26 22:40:50 +00001474 }
1475
1476 if (log)
1477 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001478 log->Printf ("SBTarget(%p)::WatchpointDelete (wp_id=%d) => %i", target_sp.get(), (uint32_t) wp_id, result);
Johnny Chen096c2932011-09-26 22:40:50 +00001479 }
1480
1481 return result;
1482}
1483
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001484SBWatchpoint
1485SBTarget::FindWatchpointByID (lldb::watch_id_t wp_id)
Johnny Chen096c2932011-09-26 22:40:50 +00001486{
1487 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1488
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001489 SBWatchpoint sb_watchpoint;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001490 lldb::WatchpointSP watchpoint_sp;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001491 TargetSP target_sp(GetSP());
1492 if (target_sp && wp_id != LLDB_INVALID_WATCH_ID)
Johnny Chen096c2932011-09-26 22:40:50 +00001493 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001494 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001495 watchpoint_sp = target_sp->GetWatchpointList().FindByID(wp_id);
1496 sb_watchpoint.SetSP (watchpoint_sp);
Johnny Chen096c2932011-09-26 22:40:50 +00001497 }
1498
1499 if (log)
1500 {
Johnny Chenecd4feb2011-10-14 00:42:25 +00001501 log->Printf ("SBTarget(%p)::FindWatchpointByID (bp_id=%d) => SBWatchpoint(%p)",
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001502 target_sp.get(), (uint32_t) wp_id, watchpoint_sp.get());
Johnny Chen096c2932011-09-26 22:40:50 +00001503 }
1504
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001505 return sb_watchpoint;
1506}
1507
1508lldb::SBWatchpoint
1509SBTarget::WatchAddress (lldb::addr_t addr, size_t size, bool read, bool write)
1510{
1511 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1512
1513 SBWatchpoint sb_watchpoint;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001514 lldb::WatchpointSP watchpoint_sp;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001515 TargetSP target_sp(GetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001516 if (target_sp && (read || write) && addr != LLDB_INVALID_ADDRESS && size > 0)
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001517 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001518 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001519 uint32_t watch_type = 0;
1520 if (read)
1521 watch_type |= LLDB_WATCH_TYPE_READ;
1522 if (write)
1523 watch_type |= LLDB_WATCH_TYPE_WRITE;
1524 watchpoint_sp = target_sp->CreateWatchpoint(addr, size, watch_type);
1525 sb_watchpoint.SetSP (watchpoint_sp);
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001526 }
1527
1528 if (log)
1529 {
1530 log->Printf ("SBTarget(%p)::WatchAddress (addr=0x%llx, 0x%u) => SBWatchpoint(%p)",
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001531 target_sp.get(), addr, (uint32_t) size, watchpoint_sp.get());
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001532 }
1533
1534 return sb_watchpoint;
Johnny Chen096c2932011-09-26 22:40:50 +00001535}
1536
1537bool
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001538SBTarget::EnableAllWatchpoints ()
Johnny Chen096c2932011-09-26 22:40:50 +00001539{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001540 TargetSP target_sp(GetSP());
1541 if (target_sp)
Johnny Chen096c2932011-09-26 22:40:50 +00001542 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001543 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1544 target_sp->EnableAllWatchpoints ();
Johnny Chen096c2932011-09-26 22:40:50 +00001545 return true;
1546 }
1547 return false;
1548}
1549
1550bool
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001551SBTarget::DisableAllWatchpoints ()
Johnny Chen096c2932011-09-26 22:40:50 +00001552{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001553 TargetSP target_sp(GetSP());
1554 if (target_sp)
Johnny Chen096c2932011-09-26 22:40:50 +00001555 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001556 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1557 target_sp->DisableAllWatchpoints ();
Johnny Chen096c2932011-09-26 22:40:50 +00001558 return true;
1559 }
1560 return false;
1561}
1562
1563bool
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001564SBTarget::DeleteAllWatchpoints ()
Johnny Chen096c2932011-09-26 22:40:50 +00001565{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001566 TargetSP target_sp(GetSP());
1567 if (target_sp)
Johnny Chen096c2932011-09-26 22:40:50 +00001568 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001569 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1570 target_sp->RemoveAllWatchpoints ();
Johnny Chen096c2932011-09-26 22:40:50 +00001571 return true;
1572 }
1573 return false;
1574}
1575
Chris Lattner24943d22010-06-08 16:52:24 +00001576
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001577lldb::SBModule
1578SBTarget::AddModule (const char *path,
1579 const char *triple,
1580 const char *uuid_cstr)
1581{
1582 lldb::SBModule sb_module;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001583 TargetSP target_sp(GetSP());
1584 if (target_sp)
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001585 {
1586 FileSpec module_file_spec;
1587 UUID module_uuid;
1588 ArchSpec module_arch;
1589
1590 if (path)
1591 module_file_spec.SetFile(path, false);
1592
1593 if (uuid_cstr)
1594 module_uuid.SetfromCString(uuid_cstr);
1595
1596 if (triple)
Greg Clayton0416bdf2012-01-30 09:04:36 +00001597 module_arch.SetTriple (triple, target_sp->GetPlatform ().get());
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001598
Greg Clayton0416bdf2012-01-30 09:04:36 +00001599 sb_module.SetSP(target_sp->GetSharedModule (module_file_spec,
1600 module_arch,
1601 uuid_cstr ? &module_uuid : NULL));
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001602 }
1603 return sb_module;
1604}
1605
1606bool
1607SBTarget::AddModule (lldb::SBModule &module)
1608{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001609 TargetSP target_sp(GetSP());
1610 if (target_sp)
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001611 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001612 target_sp->GetImages().AppendIfNeeded (module.GetSP());
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001613 return true;
1614 }
1615 return false;
1616}
1617
Chris Lattner24943d22010-06-08 16:52:24 +00001618uint32_t
1619SBTarget::GetNumModules () const
1620{
Greg Claytone005f2c2010-11-06 01:53:30 +00001621 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001622
Caroline Tice7826c882010-10-26 03:11:13 +00001623 uint32_t num = 0;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001624 TargetSP target_sp(GetSP());
1625 if (target_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +00001626 {
1627 // The module list is thread safe, no need to lock
Greg Clayton0416bdf2012-01-30 09:04:36 +00001628 num = target_sp->GetImages().GetSize();
Greg Claytonbdcda462010-12-20 20:49:23 +00001629 }
Caroline Tice7826c882010-10-26 03:11:13 +00001630
1631 if (log)
Greg Clayton0416bdf2012-01-30 09:04:36 +00001632 log->Printf ("SBTarget(%p)::GetNumModules () => %d", target_sp.get(), num);
Caroline Tice7826c882010-10-26 03:11:13 +00001633
1634 return num;
Chris Lattner24943d22010-06-08 16:52:24 +00001635}
1636
Greg Clayton43490d12010-07-30 20:12:55 +00001637void
1638SBTarget::Clear ()
1639{
Greg Claytone005f2c2010-11-06 01:53:30 +00001640 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001641
1642 if (log)
Greg Clayton3f5ee7f2010-10-29 04:59:35 +00001643 log->Printf ("SBTarget(%p)::Clear ()", m_opaque_sp.get());
Caroline Tice7826c882010-10-26 03:11:13 +00001644
Greg Clayton43490d12010-07-30 20:12:55 +00001645 m_opaque_sp.reset();
1646}
1647
1648
Chris Lattner24943d22010-06-08 16:52:24 +00001649SBModule
1650SBTarget::FindModule (const SBFileSpec &sb_file_spec)
1651{
1652 SBModule sb_module;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001653 TargetSP target_sp(GetSP());
1654 if (target_sp && sb_file_spec.IsValid())
Greg Claytonbdcda462010-12-20 20:49:23 +00001655 {
1656 // The module list is thread safe, no need to lock
Greg Clayton0416bdf2012-01-30 09:04:36 +00001657 sb_module.SetSP (target_sp->GetImages().FindFirstModuleForFileSpec (*sb_file_spec, NULL, NULL));
Greg Claytonbdcda462010-12-20 20:49:23 +00001658 }
Chris Lattner24943d22010-06-08 16:52:24 +00001659 return sb_module;
1660}
1661
Greg Clayton1b925202012-01-29 06:07:39 +00001662lldb::ByteOrder
1663SBTarget::GetByteOrder ()
1664{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001665 TargetSP target_sp(GetSP());
1666 if (target_sp)
1667 return target_sp->GetArchitecture().GetByteOrder();
Greg Clayton1b925202012-01-29 06:07:39 +00001668 return eByteOrderInvalid;
1669}
1670
1671const char *
1672SBTarget::GetTriple ()
1673{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001674 TargetSP target_sp(GetSP());
1675 if (target_sp)
Greg Clayton1b925202012-01-29 06:07:39 +00001676 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001677 std::string triple (target_sp->GetArchitecture().GetTriple().str());
Greg Clayton1b925202012-01-29 06:07:39 +00001678 // Unique the string so we don't run into ownership issues since
1679 // the const strings put the string into the string pool once and
1680 // the strings never comes out
1681 ConstString const_triple (triple.c_str());
1682 return const_triple.GetCString();
1683 }
1684 return NULL;
1685}
1686
1687uint32_t
1688SBTarget::GetAddressByteSize()
1689{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001690 TargetSP target_sp(GetSP());
1691 if (target_sp)
1692 return target_sp->GetArchitecture().GetAddressByteSize();
Greg Clayton1b925202012-01-29 06:07:39 +00001693 return sizeof(void*);
1694}
1695
1696
Chris Lattner24943d22010-06-08 16:52:24 +00001697SBModule
1698SBTarget::GetModuleAtIndex (uint32_t idx)
1699{
Greg Claytone005f2c2010-11-06 01:53:30 +00001700 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001701
Chris Lattner24943d22010-06-08 16:52:24 +00001702 SBModule sb_module;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001703 ModuleSP module_sp;
1704 TargetSP target_sp(GetSP());
1705 if (target_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +00001706 {
1707 // The module list is thread safe, no need to lock
Greg Clayton0416bdf2012-01-30 09:04:36 +00001708 module_sp = target_sp->GetImages().GetModuleAtIndex(idx);
1709 sb_module.SetSP (module_sp);
Greg Claytonbdcda462010-12-20 20:49:23 +00001710 }
Caroline Tice7826c882010-10-26 03:11:13 +00001711
1712 if (log)
1713 {
Greg Clayton49ce6822010-10-31 03:01:06 +00001714 log->Printf ("SBTarget(%p)::GetModuleAtIndex (idx=%d) => SBModule(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +00001715 target_sp.get(), idx, module_sp.get());
Caroline Tice7826c882010-10-26 03:11:13 +00001716 }
1717
Chris Lattner24943d22010-06-08 16:52:24 +00001718 return sb_module;
1719}
1720
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001721bool
1722SBTarget::RemoveModule (lldb::SBModule module)
1723{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001724 TargetSP target_sp(GetSP());
1725 if (target_sp)
1726 return target_sp->GetImages().Remove(module.GetSP());
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001727 return false;
1728}
1729
Chris Lattner24943d22010-06-08 16:52:24 +00001730
1731SBBroadcaster
1732SBTarget::GetBroadcaster () const
1733{
Greg Claytone005f2c2010-11-06 01:53:30 +00001734 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001735
Greg Clayton0416bdf2012-01-30 09:04:36 +00001736 TargetSP target_sp(GetSP());
1737 SBBroadcaster broadcaster(target_sp.get(), false);
Caroline Tice7826c882010-10-26 03:11:13 +00001738
1739 if (log)
Greg Clayton3f5ee7f2010-10-29 04:59:35 +00001740 log->Printf ("SBTarget(%p)::GetBroadcaster () => SBBroadcaster(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +00001741 target_sp.get(), broadcaster.get());
Caroline Tice7826c882010-10-26 03:11:13 +00001742
Chris Lattner24943d22010-06-08 16:52:24 +00001743 return broadcaster;
1744}
1745
Caroline Tice98f930f2010-09-20 05:20:02 +00001746bool
Caroline Tice7826c882010-10-26 03:11:13 +00001747SBTarget::GetDescription (SBStream &description, lldb::DescriptionLevel description_level)
Caroline Tice98f930f2010-09-20 05:20:02 +00001748{
Greg Clayton96154be2011-11-13 06:57:31 +00001749 Stream &strm = description.ref();
1750
Greg Clayton0416bdf2012-01-30 09:04:36 +00001751 TargetSP target_sp(GetSP());
1752 if (target_sp)
Caroline Ticee7a566e2010-09-20 16:21:41 +00001753 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001754 target_sp->Dump (&strm, description_level);
Caroline Tice7826c882010-10-26 03:11:13 +00001755 }
1756 else
Greg Clayton96154be2011-11-13 06:57:31 +00001757 strm.PutCString ("No value");
Caroline Tice7826c882010-10-26 03:11:13 +00001758
1759 return true;
1760}
1761
Greg Clayton7dd5c512012-02-06 01:44:54 +00001762lldb::SBSymbolContextList
1763SBTarget::FindFunctions (const char *name, uint32_t name_type_mask)
Greg Clayton4ed315f2011-06-21 01:34:41 +00001764{
Greg Clayton7dd5c512012-02-06 01:44:54 +00001765 lldb::SBSymbolContextList sb_sc_list;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001766 if (name && name[0])
Greg Clayton4ed315f2011-06-21 01:34:41 +00001767 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001768 TargetSP target_sp(GetSP());
1769 if (target_sp)
1770 {
1771 const bool symbols_ok = true;
Sean Callanan302d78c2012-02-10 22:52:19 +00001772 const bool inlines_ok = true;
Greg Clayton7dd5c512012-02-06 01:44:54 +00001773 const bool append = true;
1774 target_sp->GetImages().FindFunctions (ConstString(name),
1775 name_type_mask,
Sean Callanan302d78c2012-02-10 22:52:19 +00001776 symbols_ok,
1777 inlines_ok,
Greg Clayton7dd5c512012-02-06 01:44:54 +00001778 append,
1779 *sb_sc_list);
Greg Clayton0416bdf2012-01-30 09:04:36 +00001780 }
Greg Clayton4ed315f2011-06-21 01:34:41 +00001781 }
Greg Clayton7dd5c512012-02-06 01:44:54 +00001782 return sb_sc_list;
Greg Clayton4ed315f2011-06-21 01:34:41 +00001783}
1784
Enrico Granata979e20d2011-07-29 19:53:35 +00001785lldb::SBType
1786SBTarget::FindFirstType (const char* type)
1787{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001788 TargetSP target_sp(GetSP());
1789 if (type && target_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +00001790 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001791 size_t count = target_sp->GetImages().GetSize();
Enrico Granata979e20d2011-07-29 19:53:35 +00001792 for (size_t idx = 0; idx < count; idx++)
1793 {
1794 SBType found_at_idx = GetModuleAtIndex(idx).FindFirstType(type);
1795
1796 if (found_at_idx.IsValid())
1797 return found_at_idx;
1798 }
1799 }
1800 return SBType();
1801}
1802
1803lldb::SBTypeList
1804SBTarget::FindTypes (const char* type)
1805{
1806
1807 SBTypeList retval;
1808
Greg Clayton0416bdf2012-01-30 09:04:36 +00001809 TargetSP target_sp(GetSP());
1810 if (type && target_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +00001811 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001812 ModuleList& images = target_sp->GetImages();
Enrico Granata979e20d2011-07-29 19:53:35 +00001813 ConstString name_const(type);
1814 SymbolContext sc;
1815 TypeList type_list;
1816
1817 uint32_t num_matches = images.FindTypes(sc,
1818 name_const,
1819 true,
1820 UINT32_MAX,
1821 type_list);
1822
1823 for (size_t idx = 0; idx < num_matches; idx++)
1824 {
Greg Clayton0fb0bcc2011-08-03 22:57:10 +00001825 TypeSP type_sp (type_list.GetTypeAtIndex(idx));
1826 if (type_sp)
1827 retval.Append(SBType(type_sp));
Enrico Granata979e20d2011-07-29 19:53:35 +00001828 }
1829 }
1830 return retval;
1831}
1832
Greg Clayton917c0002011-06-29 22:09:02 +00001833SBValueList
1834SBTarget::FindGlobalVariables (const char *name, uint32_t max_matches)
1835{
1836 SBValueList sb_value_list;
1837
Greg Clayton0416bdf2012-01-30 09:04:36 +00001838 TargetSP target_sp(GetSP());
1839 if (name && target_sp)
Greg Clayton917c0002011-06-29 22:09:02 +00001840 {
1841 VariableList variable_list;
1842 const bool append = true;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001843 const uint32_t match_count = target_sp->GetImages().FindGlobalVariables (ConstString (name),
1844 append,
1845 max_matches,
1846 variable_list);
Greg Clayton917c0002011-06-29 22:09:02 +00001847
1848 if (match_count > 0)
1849 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001850 ExecutionContextScope *exe_scope = target_sp->GetProcessSP().get();
Greg Clayton917c0002011-06-29 22:09:02 +00001851 if (exe_scope == NULL)
Greg Clayton0416bdf2012-01-30 09:04:36 +00001852 exe_scope = target_sp.get();
Greg Clayton917c0002011-06-29 22:09:02 +00001853 ValueObjectList &value_object_list = sb_value_list.ref();
1854 for (uint32_t i=0; i<match_count; ++i)
1855 {
1856 lldb::ValueObjectSP valobj_sp (ValueObjectVariable::Create (exe_scope, variable_list.GetVariableAtIndex(i)));
1857 if (valobj_sp)
1858 value_object_list.Append(valobj_sp);
1859 }
1860 }
1861 }
1862
1863 return sb_value_list;
1864}
1865
Jim Inghamcc637462011-09-13 00:29:56 +00001866SBSourceManager
1867SBTarget::GetSourceManager()
1868{
1869 SBSourceManager source_manager (*this);
1870 return source_manager;
1871}
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001872
Sean Callananef1f6902011-12-14 23:49:37 +00001873lldb::SBInstructionList
1874SBTarget::GetInstructions (lldb::SBAddress base_addr, const void *buf, size_t size)
1875{
1876 SBInstructionList sb_instructions;
1877
Greg Clayton0416bdf2012-01-30 09:04:36 +00001878 TargetSP target_sp(GetSP());
1879 if (target_sp)
Sean Callananef1f6902011-12-14 23:49:37 +00001880 {
1881 Address addr;
1882
1883 if (base_addr.get())
1884 addr = *base_addr.get();
1885
Greg Clayton0416bdf2012-01-30 09:04:36 +00001886 sb_instructions.SetDisassembler (Disassembler::DisassembleBytes (target_sp->GetArchitecture(),
Sean Callananef1f6902011-12-14 23:49:37 +00001887 NULL,
1888 addr,
1889 buf,
1890 size));
1891 }
1892
1893 return sb_instructions;
1894}
1895
1896lldb::SBInstructionList
1897SBTarget::GetInstructions (lldb::addr_t base_addr, const void *buf, size_t size)
1898{
1899 return GetInstructions (ResolveLoadAddress(base_addr), buf, size);
1900}
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001901
1902SBError
1903SBTarget::SetSectionLoadAddress (lldb::SBSection section,
1904 lldb::addr_t section_base_addr)
1905{
1906 SBError sb_error;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001907 TargetSP target_sp(GetSP());
1908 if (target_sp)
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001909 {
1910 if (!section.IsValid())
1911 {
1912 sb_error.SetErrorStringWithFormat ("invalid section");
1913 }
1914 else
1915 {
Greg Clayton3508c382012-02-24 01:59:29 +00001916 target_sp->GetSectionLoadList().SetSectionLoadAddress (section.GetSP().get(), section_base_addr);
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001917 }
1918 }
1919 else
1920 {
1921 sb_error.SetErrorStringWithFormat ("invalid target");
1922 }
1923 return sb_error;
1924}
1925
1926SBError
1927SBTarget::ClearSectionLoadAddress (lldb::SBSection section)
1928{
1929 SBError sb_error;
1930
Greg Clayton0416bdf2012-01-30 09:04:36 +00001931 TargetSP target_sp(GetSP());
1932 if (target_sp)
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001933 {
1934 if (!section.IsValid())
1935 {
1936 sb_error.SetErrorStringWithFormat ("invalid section");
1937 }
1938 else
1939 {
Greg Clayton3508c382012-02-24 01:59:29 +00001940 target_sp->GetSectionLoadList().SetSectionUnloaded (section.GetSP().get());
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001941 }
1942 }
1943 else
1944 {
1945 sb_error.SetErrorStringWithFormat ("invalid target");
1946 }
1947 return sb_error;
1948}
1949
1950SBError
1951SBTarget::SetModuleLoadAddress (lldb::SBModule module, int64_t slide_offset)
1952{
1953 SBError sb_error;
1954
1955 char path[PATH_MAX];
Greg Clayton0416bdf2012-01-30 09:04:36 +00001956 TargetSP target_sp(GetSP());
1957 if (target_sp)
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001958 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001959 ModuleSP module_sp (module.GetSP());
1960 if (module_sp)
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001961 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001962 ObjectFile *objfile = module_sp->GetObjectFile();
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001963 if (objfile)
1964 {
1965 SectionList *section_list = objfile->GetSectionList();
1966 if (section_list)
1967 {
1968 const size_t num_sections = section_list->GetSize();
1969 for (size_t sect_idx = 0; sect_idx < num_sections; ++sect_idx)
1970 {
1971 SectionSP section_sp (section_list->GetSectionAtIndex(sect_idx));
1972 if (section_sp)
Greg Clayton0416bdf2012-01-30 09:04:36 +00001973 target_sp->GetSectionLoadList().SetSectionLoadAddress (section_sp.get(), section_sp->GetFileAddress() + slide_offset);
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001974 }
1975 }
1976 else
1977 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001978 module_sp->GetFileSpec().GetPath (path, sizeof(path));
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001979 sb_error.SetErrorStringWithFormat ("no sections in object file '%s'", path);
1980 }
1981 }
1982 else
1983 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001984 module_sp->GetFileSpec().GetPath (path, sizeof(path));
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001985 sb_error.SetErrorStringWithFormat ("no object file for module '%s'", path);
1986 }
1987 }
Greg Clayton0416bdf2012-01-30 09:04:36 +00001988 else
1989 {
1990 sb_error.SetErrorStringWithFormat ("invalid module");
1991 }
1992
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001993 }
1994 else
1995 {
1996 sb_error.SetErrorStringWithFormat ("invalid target");
1997 }
1998 return sb_error;
1999}
2000
2001SBError
2002SBTarget::ClearModuleLoadAddress (lldb::SBModule module)
2003{
2004 SBError sb_error;
2005
2006 char path[PATH_MAX];
Greg Clayton0416bdf2012-01-30 09:04:36 +00002007 TargetSP target_sp(GetSP());
2008 if (target_sp)
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002009 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00002010 ModuleSP module_sp (module.GetSP());
2011 if (module_sp)
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002012 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00002013 ObjectFile *objfile = module_sp->GetObjectFile();
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002014 if (objfile)
2015 {
2016 SectionList *section_list = objfile->GetSectionList();
2017 if (section_list)
2018 {
2019 const size_t num_sections = section_list->GetSize();
2020 for (size_t sect_idx = 0; sect_idx < num_sections; ++sect_idx)
2021 {
2022 SectionSP section_sp (section_list->GetSectionAtIndex(sect_idx));
2023 if (section_sp)
Greg Clayton0416bdf2012-01-30 09:04:36 +00002024 target_sp->GetSectionLoadList().SetSectionUnloaded (section_sp.get());
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002025 }
2026 }
2027 else
2028 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00002029 module_sp->GetFileSpec().GetPath (path, sizeof(path));
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002030 sb_error.SetErrorStringWithFormat ("no sections in object file '%s'", path);
2031 }
2032 }
2033 else
2034 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00002035 module_sp->GetFileSpec().GetPath (path, sizeof(path));
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002036 sb_error.SetErrorStringWithFormat ("no object file for module '%s'", path);
2037 }
2038 }
Greg Clayton0416bdf2012-01-30 09:04:36 +00002039 else
2040 {
2041 sb_error.SetErrorStringWithFormat ("invalid module");
2042 }
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002043 }
2044 else
2045 {
2046 sb_error.SetErrorStringWithFormat ("invalid target");
2047 }
2048 return sb_error;
2049}
2050
2051