blob: 8f8d75ec6db05c1f1e7ef2726adcdba939bcfbdf [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"
Jim Ingham4722b102012-03-06 00:37:27 +000044#include "lldb/Target/LanguageRuntime.h"
Chris Lattner24943d22010-06-08 16:52:24 +000045#include "lldb/Target/Process.h"
46#include "lldb/Target/Target.h"
47#include "lldb/Target/TargetList.h"
48
49#include "lldb/Interpreter/CommandReturnObject.h"
50#include "../source/Commands/CommandObjectBreakpoint.h"
51
Chris Lattner24943d22010-06-08 16:52:24 +000052
53using namespace lldb;
54using namespace lldb_private;
55
56#define DEFAULT_DISASM_BYTE_SIZE 32
57
Greg Clayton98ca1e62012-02-24 20:59:25 +000058SBLaunchInfo::SBLaunchInfo (const char **argv) :
59 m_opaque_sp(new ProcessLaunchInfo())
Greg Clayton0a8dcac2012-02-24 05:03:03 +000060{
Greg Clayton98ca1e62012-02-24 20:59:25 +000061 m_opaque_sp->GetFlags().Reset (eLaunchFlagDebug | eLaunchFlagDisableASLR);
62 if (argv && argv[0])
63 m_opaque_sp->GetArguments().SetArguments(argv);
Greg Clayton0a8dcac2012-02-24 05:03:03 +000064}
65
66uint32_t
67SBLaunchInfo::GetUserID()
68{
69 return m_opaque_sp->GetUserID();
70}
71
72uint32_t
73SBLaunchInfo::GetGroupID()
74{
75 return m_opaque_sp->GetGroupID();
76}
77
78bool
79SBLaunchInfo::UserIDIsValid ()
80{
81 return m_opaque_sp->UserIDIsValid();
82}
83
84bool
85SBLaunchInfo::GroupIDIsValid ()
86{
87 return m_opaque_sp->GroupIDIsValid();
88}
89
90void
91SBLaunchInfo::SetUserID (uint32_t uid)
92{
93 m_opaque_sp->SetUserID (uid);
94}
95
96void
97SBLaunchInfo::SetGroupID (uint32_t gid)
98{
99 m_opaque_sp->SetGroupID (gid);
100}
101
Greg Clayton0a8dcac2012-02-24 05:03:03 +0000102uint32_t
103SBLaunchInfo::GetNumArguments ()
104{
105 return m_opaque_sp->GetArguments().GetArgumentCount();
106}
107
108const char *
109SBLaunchInfo::GetArgumentAtIndex (uint32_t idx)
110{
111 return m_opaque_sp->GetArguments().GetArgumentAtIndex(idx);
112}
113
114void
115SBLaunchInfo::SetArguments (const char **argv, bool append)
116{
117 if (append)
118 {
119 if (argv)
120 m_opaque_sp->GetArguments().AppendArguments(argv);
121 }
122 else
123 {
124 if (argv)
125 m_opaque_sp->GetArguments().SetArguments(argv);
126 else
127 m_opaque_sp->GetArguments().Clear();
128 }
129}
130
131uint32_t
132SBLaunchInfo::GetNumEnvironmentEntries ()
133{
134 return m_opaque_sp->GetEnvironmentEntries().GetArgumentCount();
135}
136
137const char *
138SBLaunchInfo::GetEnvironmentEntryAtIndex (uint32_t idx)
139{
140 return m_opaque_sp->GetEnvironmentEntries().GetArgumentAtIndex(idx);
141}
142
143void
144SBLaunchInfo::SetEnvironmentEntries (const char **envp, bool append)
145{
146 if (append)
147 {
148 if (envp)
149 m_opaque_sp->GetEnvironmentEntries().AppendArguments(envp);
150 }
151 else
152 {
153 if (envp)
154 m_opaque_sp->GetEnvironmentEntries().SetArguments(envp);
155 else
156 m_opaque_sp->GetEnvironmentEntries().Clear();
157 }
158}
159
160void
161SBLaunchInfo::Clear ()
162{
163 m_opaque_sp->Clear();
164}
165
166const char *
167SBLaunchInfo::GetWorkingDirectory () const
168{
169 return m_opaque_sp->GetWorkingDirectory();
170}
171
172void
173SBLaunchInfo::SetWorkingDirectory (const char *working_dir)
174{
175 m_opaque_sp->SetWorkingDirectory(working_dir);
176}
177
178uint32_t
179SBLaunchInfo::GetLaunchFlags ()
180{
181 return m_opaque_sp->GetFlags().Get();
182}
183
184void
185SBLaunchInfo::SetLaunchFlags (uint32_t flags)
186{
187 m_opaque_sp->GetFlags().Reset(flags);
188}
189
190const char *
191SBLaunchInfo::GetProcessPluginName ()
192{
193 return m_opaque_sp->GetProcessPluginName();
194}
195
196void
197SBLaunchInfo::SetProcessPluginName (const char *plugin_name)
198{
199 return m_opaque_sp->SetProcessPluginName (plugin_name);
200}
201
202const char *
203SBLaunchInfo::GetShell ()
204{
205 return m_opaque_sp->GetShell();
206}
207
208void
209SBLaunchInfo::SetShell (const char * path)
210{
211 m_opaque_sp->SetShell (path);
212}
213
214uint32_t
215SBLaunchInfo::GetResumeCount ()
216{
217 return m_opaque_sp->GetResumeCount();
218}
219
220void
221SBLaunchInfo::SetResumeCount (uint32_t c)
222{
223 m_opaque_sp->SetResumeCount (c);
224}
225
226bool
227SBLaunchInfo::AddCloseFileAction (int fd)
228{
229 return m_opaque_sp->AppendCloseFileAction(fd);
230}
231
232bool
233SBLaunchInfo::AddDuplicateFileAction (int fd, int dup_fd)
234{
235 return m_opaque_sp->AppendDuplicateFileAction(fd, dup_fd);
236}
237
238bool
239SBLaunchInfo::AddOpenFileAction (int fd, const char *path, bool read, bool write)
240{
241 return m_opaque_sp->AppendOpenFileAction(fd, path, read, write);
242}
243
244bool
245SBLaunchInfo::AddSuppressFileAction (int fd, bool read, bool write)
246{
247 return m_opaque_sp->AppendSuppressFileAction(fd, read, write);
248}
249
250
251SBAttachInfo::SBAttachInfo () :
252m_opaque_sp (new ProcessAttachInfo())
253{
254}
255
256SBAttachInfo::SBAttachInfo (lldb::pid_t pid) :
257m_opaque_sp (new ProcessAttachInfo())
258{
259 m_opaque_sp->SetProcessID (pid);
260}
261
262SBAttachInfo::SBAttachInfo (const char *path, bool wait_for) :
263m_opaque_sp (new ProcessAttachInfo())
264{
265 if (path && path[0])
266 m_opaque_sp->GetExecutableFile().SetFile(path, false);
267 m_opaque_sp->SetWaitForLaunch (wait_for);
268}
269
270SBAttachInfo::SBAttachInfo (const SBAttachInfo &rhs) :
271m_opaque_sp (new ProcessAttachInfo())
272{
273 *m_opaque_sp = *rhs.m_opaque_sp;
274}
275
276SBAttachInfo &
277SBAttachInfo::operator = (const SBAttachInfo &rhs)
278{
279 if (this != &rhs)
280 *m_opaque_sp = *rhs.m_opaque_sp;
281 return *this;
282}
283
284lldb::pid_t
285SBAttachInfo::GetProcessID ()
286{
287 return m_opaque_sp->GetProcessID();
288}
289
290void
291SBAttachInfo::SetProcessID (lldb::pid_t pid)
292{
293 m_opaque_sp->SetProcessID (pid);
294}
295
296
297uint32_t
298SBAttachInfo::GetResumeCount ()
299{
300 return m_opaque_sp->GetResumeCount();
301}
302
303void
304SBAttachInfo::SetResumeCount (uint32_t c)
305{
306 m_opaque_sp->SetResumeCount (c);
307}
308
309const char *
310SBAttachInfo::GetProcessPluginName ()
311{
312 return m_opaque_sp->GetProcessPluginName();
313}
314
315void
316SBAttachInfo::SetProcessPluginName (const char *plugin_name)
317{
318 return m_opaque_sp->SetProcessPluginName (plugin_name);
319}
320
321void
322SBAttachInfo::SetExecutable (const char *path)
323{
324 if (path && path[0])
325 m_opaque_sp->GetExecutableFile().SetFile(path, false);
326 else
327 m_opaque_sp->GetExecutableFile().Clear();
328}
329
330void
331SBAttachInfo::SetExecutable (SBFileSpec exe_file)
332{
333 if (exe_file.IsValid())
334 m_opaque_sp->GetExecutableFile() = exe_file.ref();
335 else
336 m_opaque_sp->GetExecutableFile().Clear();
337}
338
339bool
340SBAttachInfo::GetWaitForLaunch ()
341{
342 return m_opaque_sp->GetWaitForLaunch();
343}
344
345void
346SBAttachInfo::SetWaitForLaunch (bool b)
347{
348 m_opaque_sp->SetWaitForLaunch (b);
349}
350
351uint32_t
Greg Clayton80efa5e2012-02-24 23:56:06 +0000352SBAttachInfo::GetUserID()
353{
354 return m_opaque_sp->GetUserID();
355}
356
357uint32_t
358SBAttachInfo::GetGroupID()
359{
360 return m_opaque_sp->GetGroupID();
361}
362
363bool
364SBAttachInfo::UserIDIsValid ()
365{
366 return m_opaque_sp->UserIDIsValid();
367}
368
369bool
370SBAttachInfo::GroupIDIsValid ()
371{
372 return m_opaque_sp->GroupIDIsValid();
373}
374
375void
376SBAttachInfo::SetUserID (uint32_t uid)
377{
378 m_opaque_sp->SetUserID (uid);
379}
380
381void
382SBAttachInfo::SetGroupID (uint32_t gid)
383{
384 m_opaque_sp->SetGroupID (gid);
385}
386
387uint32_t
Greg Clayton0a8dcac2012-02-24 05:03:03 +0000388SBAttachInfo::GetEffectiveUserID()
389{
390 return m_opaque_sp->GetEffectiveUserID();
391}
392
393uint32_t
394SBAttachInfo::GetEffectiveGroupID()
395{
396 return m_opaque_sp->GetEffectiveGroupID();
397}
398
399bool
400SBAttachInfo::EffectiveUserIDIsValid ()
401{
402 return m_opaque_sp->EffectiveUserIDIsValid();
403}
404
405bool
406SBAttachInfo::EffectiveGroupIDIsValid ()
407{
408 return m_opaque_sp->EffectiveGroupIDIsValid ();
409}
410
411void
412SBAttachInfo::SetEffectiveUserID (uint32_t uid)
413{
414 m_opaque_sp->SetEffectiveUserID(uid);
415}
416
417void
418SBAttachInfo::SetEffectiveGroupID (uint32_t gid)
419{
420 m_opaque_sp->SetEffectiveGroupID(gid);
421}
422
423lldb::pid_t
424SBAttachInfo::GetParentProcessID ()
425{
426 return m_opaque_sp->GetParentProcessID();
427}
428
429void
430SBAttachInfo::SetParentProcessID (lldb::pid_t pid)
431{
432 m_opaque_sp->SetParentProcessID (pid);
433}
434
435bool
436SBAttachInfo::ParentProcessIDIsValid()
437{
438 return m_opaque_sp->ParentProcessIDIsValid();
439}
440
441
Chris Lattner24943d22010-06-08 16:52:24 +0000442//----------------------------------------------------------------------
443// SBTarget constructor
444//----------------------------------------------------------------------
Greg Claytonc3b61d22010-12-15 05:08:08 +0000445SBTarget::SBTarget () :
446 m_opaque_sp ()
Chris Lattner24943d22010-06-08 16:52:24 +0000447{
448}
449
450SBTarget::SBTarget (const SBTarget& rhs) :
Greg Clayton63094e02010-06-23 01:19:29 +0000451 m_opaque_sp (rhs.m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000452{
453}
454
455SBTarget::SBTarget(const TargetSP& target_sp) :
Greg Clayton63094e02010-06-23 01:19:29 +0000456 m_opaque_sp (target_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000457{
458}
459
Greg Clayton538eb822010-11-05 23:17:00 +0000460const SBTarget&
461SBTarget::operator = (const SBTarget& rhs)
462{
463 if (this != &rhs)
464 m_opaque_sp = rhs.m_opaque_sp;
465 return *this;
466}
467
Chris Lattner24943d22010-06-08 16:52:24 +0000468//----------------------------------------------------------------------
469// Destructor
470//----------------------------------------------------------------------
471SBTarget::~SBTarget()
472{
473}
474
Jim Ingham5a15e692012-02-16 06:50:00 +0000475const char *
476SBTarget::GetBroadcasterClassName ()
477{
478 return Target::GetStaticBroadcasterClass().AsCString();
479}
480
Chris Lattner24943d22010-06-08 16:52:24 +0000481bool
482SBTarget::IsValid () const
483{
Greg Clayton63094e02010-06-23 01:19:29 +0000484 return m_opaque_sp.get() != NULL;
Chris Lattner24943d22010-06-08 16:52:24 +0000485}
486
487SBProcess
488SBTarget::GetProcess ()
489{
490 SBProcess sb_process;
Greg Clayton334d33a2012-01-30 07:41:31 +0000491 ProcessSP process_sp;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000492 TargetSP target_sp(GetSP());
493 if (target_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000494 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000495 process_sp = target_sp->GetProcessSP();
Greg Clayton334d33a2012-01-30 07:41:31 +0000496 sb_process.SetSP (process_sp);
Greg Claytonbdcda462010-12-20 20:49:23 +0000497 }
Caroline Tice7826c882010-10-26 03:11:13 +0000498
Greg Claytone005f2c2010-11-06 01:53:30 +0000499 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000500 if (log)
501 {
Greg Clayton49ce6822010-10-31 03:01:06 +0000502 log->Printf ("SBTarget(%p)::GetProcess () => SBProcess(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +0000503 target_sp.get(), process_sp.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000504 }
505
Chris Lattner24943d22010-06-08 16:52:24 +0000506 return sb_process;
507}
508
Greg Clayton63094e02010-06-23 01:19:29 +0000509SBDebugger
510SBTarget::GetDebugger () const
511{
512 SBDebugger debugger;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000513 TargetSP target_sp(GetSP());
514 if (target_sp)
515 debugger.reset (target_sp->GetDebugger().shared_from_this());
Greg Clayton63094e02010-06-23 01:19:29 +0000516 return debugger;
517}
518
Jim Inghamb5871fe2011-03-31 00:01:24 +0000519SBProcess
520SBTarget::LaunchSimple
521(
522 char const **argv,
523 char const **envp,
524 const char *working_directory
525)
526{
527 char *stdin_path = NULL;
528 char *stdout_path = NULL;
529 char *stderr_path = NULL;
530 uint32_t launch_flags = 0;
531 bool stop_at_entry = false;
532 SBError error;
533 SBListener listener = GetDebugger().GetListener();
534 return Launch (listener,
535 argv,
536 envp,
537 stdin_path,
538 stdout_path,
539 stderr_path,
540 working_directory,
541 launch_flags,
542 stop_at_entry,
543 error);
544}
Greg Claytonde915be2011-01-23 05:56:20 +0000545
546SBProcess
547SBTarget::Launch
548(
Greg Clayton271a5db2011-02-03 21:28:34 +0000549 SBListener &listener,
Greg Claytonde915be2011-01-23 05:56:20 +0000550 char const **argv,
551 char const **envp,
552 const char *stdin_path,
553 const char *stdout_path,
554 const char *stderr_path,
555 const char *working_directory,
556 uint32_t launch_flags, // See LaunchFlags
557 bool stop_at_entry,
558 lldb::SBError& error
559)
560{
Greg Claytone005f2c2010-11-06 01:53:30 +0000561 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000562
Greg Clayton0416bdf2012-01-30 09:04:36 +0000563 SBProcess sb_process;
564 ProcessSP process_sp;
565 TargetSP target_sp(GetSP());
566
Caroline Tice7826c882010-10-26 03:11:13 +0000567 if (log)
Greg Clayton3f5ee7f2010-10-29 04:59:35 +0000568 {
Greg Claytonde915be2011-01-23 05:56:20 +0000569 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 +0000570 target_sp.get(),
Greg Claytonde915be2011-01-23 05:56:20 +0000571 argv,
572 envp,
573 stdin_path ? stdin_path : "NULL",
574 stdout_path ? stdout_path : "NULL",
575 stderr_path ? stderr_path : "NULL",
576 working_directory ? working_directory : "NULL",
577 launch_flags,
578 stop_at_entry,
579 error.get());
Greg Clayton3f5ee7f2010-10-29 04:59:35 +0000580 }
Greg Clayton0416bdf2012-01-30 09:04:36 +0000581
582 if (target_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000583 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000584 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton1a3083a2010-10-06 03:53:16 +0000585
Greg Clayton7c330d62011-01-27 01:01:10 +0000586 if (getenv("LLDB_LAUNCH_FLAG_DISABLE_ASLR"))
587 launch_flags |= eLaunchFlagDisableASLR;
588
Greg Clayton180546b2011-04-30 01:09:13 +0000589 StateType state = eStateInvalid;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000590 process_sp = target_sp->GetProcessSP();
Greg Clayton334d33a2012-01-30 07:41:31 +0000591 if (process_sp)
Greg Clayton28d5fcc2011-01-27 06:44:37 +0000592 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000593 state = process_sp->GetState();
Greg Clayton180546b2011-04-30 01:09:13 +0000594
Greg Clayton334d33a2012-01-30 07:41:31 +0000595 if (process_sp->IsAlive() && state != eStateConnected)
Greg Clayton180546b2011-04-30 01:09:13 +0000596 {
597 if (state == eStateAttaching)
598 error.SetErrorString ("process attach is in progress");
599 else
600 error.SetErrorString ("a process is already being debugged");
Greg Clayton180546b2011-04-30 01:09:13 +0000601 return sb_process;
602 }
Greg Clayton28d5fcc2011-01-27 06:44:37 +0000603 }
604
Greg Clayton180546b2011-04-30 01:09:13 +0000605 if (state == eStateConnected)
606 {
607 // If we are already connected, then we have already specified the
608 // listener, so if a valid listener is supplied, we need to error out
609 // to let the client know.
610 if (listener.IsValid())
611 {
612 error.SetErrorString ("process is connected and already has a listener, pass empty listener");
Greg Clayton180546b2011-04-30 01:09:13 +0000613 return sb_process;
614 }
615 }
616 else
Greg Claytonc5f728c2010-10-06 22:10:17 +0000617 {
Greg Clayton271a5db2011-02-03 21:28:34 +0000618 if (listener.IsValid())
Greg Clayton46c9a352012-02-09 06:16:32 +0000619 process_sp = target_sp->CreateProcess (listener.ref(), NULL, NULL);
Greg Clayton271a5db2011-02-03 21:28:34 +0000620 else
Greg Clayton46c9a352012-02-09 06:16:32 +0000621 process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener(), NULL, NULL);
Greg Clayton180546b2011-04-30 01:09:13 +0000622 }
Greg Clayton7c330d62011-01-27 01:01:10 +0000623
Greg Clayton334d33a2012-01-30 07:41:31 +0000624 if (process_sp)
Greg Clayton180546b2011-04-30 01:09:13 +0000625 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000626 sb_process.SetSP (process_sp);
Greg Clayton180546b2011-04-30 01:09:13 +0000627 if (getenv("LLDB_LAUNCH_FLAG_DISABLE_STDIO"))
628 launch_flags |= eLaunchFlagDisableSTDIO;
629
Greg Clayton36bc5ea2011-11-03 21:22:33 +0000630 ProcessLaunchInfo launch_info (stdin_path, stdout_path, stderr_path, working_directory, launch_flags);
631
Greg Clayton0416bdf2012-01-30 09:04:36 +0000632 Module *exe_module = target_sp->GetExecutableModulePointer();
Greg Clayton36bc5ea2011-11-03 21:22:33 +0000633 if (exe_module)
Greg Clayton1d1f39e2011-11-29 04:03:30 +0000634 launch_info.SetExecutableFile(exe_module->GetPlatformFileSpec(), true);
Greg Clayton36bc5ea2011-11-03 21:22:33 +0000635 if (argv)
636 launch_info.GetArguments().AppendArguments (argv);
637 if (envp)
638 launch_info.GetEnvironmentEntries ().SetArguments (envp);
639
Greg Clayton334d33a2012-01-30 07:41:31 +0000640 error.SetError (process_sp->Launch (launch_info));
Greg Clayton180546b2011-04-30 01:09:13 +0000641 if (error.Success())
Greg Clayton7c330d62011-01-27 01:01:10 +0000642 {
Greg Clayton180546b2011-04-30 01:09:13 +0000643 // We we are stopping at the entry point, we can return now!
644 if (stop_at_entry)
645 return sb_process;
Greg Clayton7c330d62011-01-27 01:01:10 +0000646
Greg Clayton180546b2011-04-30 01:09:13 +0000647 // Make sure we are stopped at the entry
Greg Clayton334d33a2012-01-30 07:41:31 +0000648 StateType state = process_sp->WaitForProcessToStop (NULL);
Greg Clayton180546b2011-04-30 01:09:13 +0000649 if (state == eStateStopped)
Greg Clayton7c330d62011-01-27 01:01:10 +0000650 {
Greg Clayton180546b2011-04-30 01:09:13 +0000651 // resume the process to skip the entry point
Greg Clayton334d33a2012-01-30 07:41:31 +0000652 error.SetError (process_sp->Resume());
Greg Clayton180546b2011-04-30 01:09:13 +0000653 if (error.Success())
Greg Clayton7c330d62011-01-27 01:01:10 +0000654 {
Greg Clayton180546b2011-04-30 01:09:13 +0000655 // If we are doing synchronous mode, then wait for the
656 // process to stop yet again!
Greg Clayton0416bdf2012-01-30 09:04:36 +0000657 if (target_sp->GetDebugger().GetAsyncExecution () == false)
Greg Clayton334d33a2012-01-30 07:41:31 +0000658 process_sp->WaitForProcessToStop (NULL);
Greg Clayton7c330d62011-01-27 01:01:10 +0000659 }
660 }
661 }
Greg Clayton180546b2011-04-30 01:09:13 +0000662 }
663 else
664 {
665 error.SetErrorString ("unable to create lldb_private::Process");
Greg Claytonc5f728c2010-10-06 22:10:17 +0000666 }
667 }
668 else
669 {
670 error.SetErrorString ("SBTarget is invalid");
Chris Lattner24943d22010-06-08 16:52:24 +0000671 }
Caroline Tice7826c882010-10-26 03:11:13 +0000672
Caroline Tice926060e2010-10-29 21:48:37 +0000673 log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
Caroline Tice7826c882010-10-26 03:11:13 +0000674 if (log)
675 {
Greg Clayton49ce6822010-10-31 03:01:06 +0000676 log->Printf ("SBTarget(%p)::Launch (...) => SBProceess(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +0000677 target_sp.get(), process_sp.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000678 }
679
Greg Clayton1a3083a2010-10-06 03:53:16 +0000680 return sb_process;
Chris Lattner24943d22010-06-08 16:52:24 +0000681}
682
Greg Clayton0a8dcac2012-02-24 05:03:03 +0000683SBProcess
684SBTarget::Launch (SBLaunchInfo &sb_launch_info, SBError& error)
685{
686 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
687
688 SBProcess sb_process;
689 ProcessSP process_sp;
690 TargetSP target_sp(GetSP());
691
692 if (log)
693 {
694 log->Printf ("SBTarget(%p)::Launch (launch_info, error)...", target_sp.get());
695 }
696
697 if (target_sp)
698 {
699 Mutex::Locker api_locker (target_sp->GetAPIMutex());
700 StateType state = eStateInvalid;
701 process_sp = target_sp->GetProcessSP();
702 if (process_sp)
703 {
704 state = process_sp->GetState();
705
706 if (process_sp->IsAlive() && state != eStateConnected)
707 {
708 if (state == eStateAttaching)
709 error.SetErrorString ("process attach is in progress");
710 else
711 error.SetErrorString ("a process is already being debugged");
712 return sb_process;
713 }
714 }
715
716 if (state != eStateConnected)
717 process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener(), NULL, NULL);
718
719 if (process_sp)
720 {
721 sb_process.SetSP (process_sp);
722 lldb_private::ProcessLaunchInfo &launch_info = sb_launch_info.ref();
Greg Clayton98ca1e62012-02-24 20:59:25 +0000723
Greg Clayton98ca1e62012-02-24 20:59:25 +0000724 Module *exe_module = target_sp->GetExecutableModulePointer();
725 if (exe_module)
Han Ming Ongc86723f2012-03-02 01:02:04 +0000726 launch_info.SetExecutableFile(exe_module->GetPlatformFileSpec(), true);
Greg Clayton98ca1e62012-02-24 20:59:25 +0000727
728 const ArchSpec &arch_spec = target_sp->GetArchitecture();
729 if (arch_spec.IsValid())
730 launch_info.GetArchitecture () = arch_spec;
731
Greg Clayton0a8dcac2012-02-24 05:03:03 +0000732 error.SetError (process_sp->Launch (launch_info));
Greg Clayton98ca1e62012-02-24 20:59:25 +0000733 const bool synchronous_execution = target_sp->GetDebugger().GetAsyncExecution () == false;
Greg Clayton0a8dcac2012-02-24 05:03:03 +0000734 if (error.Success())
735 {
Greg Clayton98ca1e62012-02-24 20:59:25 +0000736 StateType state = eStateInvalid;
Greg Clayton0a8dcac2012-02-24 05:03:03 +0000737 if (launch_info.GetFlags().Test(eLaunchFlagStopAtEntry))
Greg Clayton98ca1e62012-02-24 20:59:25 +0000738 {
739 // If we are doing synchronous mode, then wait for the initial
740 // stop to happen, else, return and let the caller watch for
741 // the stop
742 if (synchronous_execution)
743 state = process_sp->WaitForProcessToStop (NULL);
744 // We we are stopping at the entry point, we can return now!
Greg Clayton0a8dcac2012-02-24 05:03:03 +0000745 return sb_process;
Greg Clayton98ca1e62012-02-24 20:59:25 +0000746 }
Greg Clayton0a8dcac2012-02-24 05:03:03 +0000747
748 // Make sure we are stopped at the entry
Greg Clayton98ca1e62012-02-24 20:59:25 +0000749 state = process_sp->WaitForProcessToStop (NULL);
Greg Clayton0a8dcac2012-02-24 05:03:03 +0000750 if (state == eStateStopped)
751 {
752 // resume the process to skip the entry point
753 error.SetError (process_sp->Resume());
754 if (error.Success())
755 {
756 // If we are doing synchronous mode, then wait for the
757 // process to stop yet again!
Greg Clayton98ca1e62012-02-24 20:59:25 +0000758 if (synchronous_execution)
Greg Clayton0a8dcac2012-02-24 05:03:03 +0000759 process_sp->WaitForProcessToStop (NULL);
760 }
761 }
762 }
763 }
764 else
765 {
766 error.SetErrorString ("unable to create lldb_private::Process");
767 }
768 }
769 else
770 {
771 error.SetErrorString ("SBTarget is invalid");
772 }
773
774 log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
775 if (log)
776 {
777 log->Printf ("SBTarget(%p)::Launch (...) => SBProceess(%p)",
778 target_sp.get(), process_sp.get());
779 }
780
781 return sb_process;
782}
783
784lldb::SBProcess
785SBTarget::Attach (SBAttachInfo &sb_attach_info, SBError& error)
786{
787 SBProcess sb_process;
788 ProcessSP process_sp;
789 TargetSP target_sp(GetSP());
790 if (target_sp)
791 {
792 Mutex::Locker api_locker (target_sp->GetAPIMutex());
793
794 StateType state = eStateInvalid;
795 process_sp = target_sp->GetProcessSP();
796 if (process_sp)
797 {
798 state = process_sp->GetState();
799
800 if (process_sp->IsAlive() && state != eStateConnected)
801 {
802 if (state == eStateAttaching)
803 error.SetErrorString ("process attach is in progress");
804 else
805 error.SetErrorString ("a process is already being debugged");
806 return sb_process;
807 }
808 }
809
810 if (state != eStateConnected)
811 process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener(), NULL, NULL);
812
813 if (process_sp)
814 {
Greg Clayton0a8dcac2012-02-24 05:03:03 +0000815 ProcessAttachInfo &attach_info = sb_attach_info.ref();
Han Ming Ong435c5ef2012-02-29 00:12:56 +0000816 lldb::pid_t attach_pid = attach_info.GetProcessID();
817 if (attach_pid != LLDB_INVALID_PROCESS_ID)
818 {
819 PlatformSP platform_sp = target_sp->GetPlatform();
820 ProcessInstanceInfo instance_info;
821 if (platform_sp->GetProcessInfo(attach_pid, instance_info))
822 {
823 attach_info.SetUserID(instance_info.GetEffectiveUserID());
824 }
825 }
Han Ming Ong94b4e9a2012-02-29 19:16:40 +0000826 error.SetError (process_sp->Attach (attach_info));
827 if (error.Success())
828 {
829 sb_process.SetSP (process_sp);
830 // If we are doing synchronous mode, then wait for the
831 // process to stop!
832 if (target_sp->GetDebugger().GetAsyncExecution () == false)
833 process_sp->WaitForProcessToStop (NULL);
834 }
Greg Clayton0a8dcac2012-02-24 05:03:03 +0000835 }
836 else
837 {
838 error.SetErrorString ("unable to create lldb_private::Process");
839 }
840 }
841 else
842 {
843 error.SetErrorString ("SBTarget is invalid");
844 }
845 return sb_process;
846}
847
848
Greg Claytond5b0b442011-12-02 02:10:57 +0000849#if defined(__APPLE__)
850
851lldb::SBProcess
852SBTarget::AttachToProcessWithID (SBListener &listener,
853 ::pid_t pid,
854 lldb::SBError& error)
855{
856 return AttachToProcessWithID (listener, (lldb::pid_t)pid, error);
857}
858
859#endif // #if defined(__APPLE__)
Greg Claytonc5f728c2010-10-06 22:10:17 +0000860
861lldb::SBProcess
Greg Claytond8c62532010-10-07 04:19:01 +0000862SBTarget::AttachToProcessWithID
Greg Claytonc5f728c2010-10-06 22:10:17 +0000863(
Greg Clayton271a5db2011-02-03 21:28:34 +0000864 SBListener &listener,
Greg Claytonc5f728c2010-10-06 22:10:17 +0000865 lldb::pid_t pid,// The process ID to attach to
866 SBError& error // An error explaining what went wrong if attach fails
867)
868{
869 SBProcess sb_process;
Greg Clayton334d33a2012-01-30 07:41:31 +0000870 ProcessSP process_sp;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000871 TargetSP target_sp(GetSP());
872 if (target_sp)
Greg Claytonc5f728c2010-10-06 22:10:17 +0000873 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000874 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytonde1dd812011-06-24 03:21:43 +0000875
876 StateType state = eStateInvalid;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000877 process_sp = target_sp->GetProcessSP();
Greg Clayton334d33a2012-01-30 07:41:31 +0000878 if (process_sp)
Greg Claytonde1dd812011-06-24 03:21:43 +0000879 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000880 state = process_sp->GetState();
Greg Claytonde1dd812011-06-24 03:21:43 +0000881
Greg Clayton334d33a2012-01-30 07:41:31 +0000882 if (process_sp->IsAlive() && state != eStateConnected)
Greg Claytonde1dd812011-06-24 03:21:43 +0000883 {
884 if (state == eStateAttaching)
885 error.SetErrorString ("process attach is in progress");
886 else
887 error.SetErrorString ("a process is already being debugged");
Greg Claytonde1dd812011-06-24 03:21:43 +0000888 return sb_process;
889 }
890 }
891
892 if (state == eStateConnected)
893 {
894 // If we are already connected, then we have already specified the
895 // listener, so if a valid listener is supplied, we need to error out
896 // to let the client know.
897 if (listener.IsValid())
898 {
899 error.SetErrorString ("process is connected and already has a listener, pass empty listener");
Greg Claytonde1dd812011-06-24 03:21:43 +0000900 return sb_process;
901 }
902 }
Greg Clayton271a5db2011-02-03 21:28:34 +0000903 else
Greg Claytonde1dd812011-06-24 03:21:43 +0000904 {
905 if (listener.IsValid())
Greg Clayton46c9a352012-02-09 06:16:32 +0000906 process_sp = target_sp->CreateProcess (listener.ref(), NULL, NULL);
Greg Claytonde1dd812011-06-24 03:21:43 +0000907 else
Greg Clayton46c9a352012-02-09 06:16:32 +0000908 process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener(), NULL, NULL);
Greg Claytonde1dd812011-06-24 03:21:43 +0000909 }
Greg Clayton334d33a2012-01-30 07:41:31 +0000910 if (process_sp)
Greg Claytonc5f728c2010-10-06 22:10:17 +0000911 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000912 sb_process.SetSP (process_sp);
913
Greg Clayton527154d2011-11-15 03:53:30 +0000914 ProcessAttachInfo attach_info;
915 attach_info.SetProcessID (pid);
Han Ming Ongd1040dd2012-02-25 01:07:38 +0000916
917 PlatformSP platform_sp = target_sp->GetPlatform();
918 ProcessInstanceInfo instance_info;
919 if (platform_sp->GetProcessInfo(pid, instance_info))
920 {
921 attach_info.SetUserID(instance_info.GetEffectiveUserID());
Han Ming Ongd1040dd2012-02-25 01:07:38 +0000922 }
Greg Clayton334d33a2012-01-30 07:41:31 +0000923 error.SetError (process_sp->Attach (attach_info));
Johnny Chen535960e2011-06-17 00:51:15 +0000924 // If we are doing synchronous mode, then wait for the
925 // process to stop!
Greg Clayton0416bdf2012-01-30 09:04:36 +0000926 if (target_sp->GetDebugger().GetAsyncExecution () == false)
Greg Clayton334d33a2012-01-30 07:41:31 +0000927 process_sp->WaitForProcessToStop (NULL);
Greg Claytonc5f728c2010-10-06 22:10:17 +0000928 }
929 else
930 {
931 error.SetErrorString ("unable to create lldb_private::Process");
932 }
933 }
934 else
935 {
936 error.SetErrorString ("SBTarget is invalid");
937 }
938 return sb_process;
939
940}
941
942lldb::SBProcess
Greg Claytond8c62532010-10-07 04:19:01 +0000943SBTarget::AttachToProcessWithName
Greg Claytonc5f728c2010-10-06 22:10:17 +0000944(
Greg Clayton271a5db2011-02-03 21:28:34 +0000945 SBListener &listener,
Greg Claytonc5f728c2010-10-06 22:10:17 +0000946 const char *name, // basename of process to attach to
947 bool wait_for, // if true wait for a new instance of "name" to be launched
948 SBError& error // An error explaining what went wrong if attach fails
949)
950{
951 SBProcess sb_process;
Greg Clayton334d33a2012-01-30 07:41:31 +0000952 ProcessSP process_sp;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000953 TargetSP target_sp(GetSP());
954 if (name && target_sp)
Greg Claytonc5f728c2010-10-06 22:10:17 +0000955 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000956 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytonbdcda462010-12-20 20:49:23 +0000957
Greg Claytonde1dd812011-06-24 03:21:43 +0000958 StateType state = eStateInvalid;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000959 process_sp = target_sp->GetProcessSP();
Greg Clayton334d33a2012-01-30 07:41:31 +0000960 if (process_sp)
Greg Claytonde1dd812011-06-24 03:21:43 +0000961 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000962 state = process_sp->GetState();
Greg Claytonde1dd812011-06-24 03:21:43 +0000963
Greg Clayton334d33a2012-01-30 07:41:31 +0000964 if (process_sp->IsAlive() && state != eStateConnected)
Greg Claytonde1dd812011-06-24 03:21:43 +0000965 {
966 if (state == eStateAttaching)
967 error.SetErrorString ("process attach is in progress");
968 else
969 error.SetErrorString ("a process is already being debugged");
Greg Claytonde1dd812011-06-24 03:21:43 +0000970 return sb_process;
971 }
972 }
973
974 if (state == eStateConnected)
975 {
976 // If we are already connected, then we have already specified the
977 // listener, so if a valid listener is supplied, we need to error out
978 // to let the client know.
979 if (listener.IsValid())
980 {
981 error.SetErrorString ("process is connected and already has a listener, pass empty listener");
Greg Claytonde1dd812011-06-24 03:21:43 +0000982 return sb_process;
983 }
984 }
Greg Clayton271a5db2011-02-03 21:28:34 +0000985 else
Greg Claytonde1dd812011-06-24 03:21:43 +0000986 {
987 if (listener.IsValid())
Greg Clayton46c9a352012-02-09 06:16:32 +0000988 process_sp = target_sp->CreateProcess (listener.ref(), NULL, NULL);
Greg Claytonde1dd812011-06-24 03:21:43 +0000989 else
Greg Clayton46c9a352012-02-09 06:16:32 +0000990 process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener(), NULL, NULL);
Greg Claytonde1dd812011-06-24 03:21:43 +0000991 }
Greg Claytonc5f728c2010-10-06 22:10:17 +0000992
Greg Clayton334d33a2012-01-30 07:41:31 +0000993 if (process_sp)
Greg Claytonc5f728c2010-10-06 22:10:17 +0000994 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000995 sb_process.SetSP (process_sp);
Greg Clayton527154d2011-11-15 03:53:30 +0000996 ProcessAttachInfo attach_info;
997 attach_info.GetExecutableFile().SetFile(name, false);
998 attach_info.SetWaitForLaunch(wait_for);
Greg Clayton334d33a2012-01-30 07:41:31 +0000999 error.SetError (process_sp->Attach (attach_info));
Johnny Chen58d02ff2011-06-17 19:21:30 +00001000 // If we are doing synchronous mode, then wait for the
1001 // process to stop!
Greg Clayton0416bdf2012-01-30 09:04:36 +00001002 if (target_sp->GetDebugger().GetAsyncExecution () == false)
Greg Clayton334d33a2012-01-30 07:41:31 +00001003 process_sp->WaitForProcessToStop (NULL);
Greg Claytonc5f728c2010-10-06 22:10:17 +00001004 }
1005 else
1006 {
1007 error.SetErrorString ("unable to create lldb_private::Process");
1008 }
1009 }
1010 else
1011 {
1012 error.SetErrorString ("SBTarget is invalid");
1013 }
1014 return sb_process;
1015
1016}
1017
James McIlree38093402011-03-04 00:31:13 +00001018lldb::SBProcess
1019SBTarget::ConnectRemote
1020(
1021 SBListener &listener,
1022 const char *url,
1023 const char *plugin_name,
1024 SBError& error
1025)
1026{
1027 SBProcess sb_process;
Greg Clayton334d33a2012-01-30 07:41:31 +00001028 ProcessSP process_sp;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001029 TargetSP target_sp(GetSP());
1030 if (target_sp)
James McIlree38093402011-03-04 00:31:13 +00001031 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001032 Mutex::Locker api_locker (target_sp->GetAPIMutex());
James McIlree38093402011-03-04 00:31:13 +00001033 if (listener.IsValid())
Greg Clayton46c9a352012-02-09 06:16:32 +00001034 process_sp = target_sp->CreateProcess (listener.ref(), plugin_name, NULL);
James McIlree38093402011-03-04 00:31:13 +00001035 else
Greg Clayton46c9a352012-02-09 06:16:32 +00001036 process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener(), plugin_name, NULL);
James McIlree38093402011-03-04 00:31:13 +00001037
1038
Greg Clayton334d33a2012-01-30 07:41:31 +00001039 if (process_sp)
James McIlree38093402011-03-04 00:31:13 +00001040 {
Greg Clayton334d33a2012-01-30 07:41:31 +00001041 sb_process.SetSP (process_sp);
1042 error.SetError (process_sp->ConnectRemote (url));
James McIlree38093402011-03-04 00:31:13 +00001043 }
1044 else
1045 {
1046 error.SetErrorString ("unable to create lldb_private::Process");
1047 }
1048 }
1049 else
1050 {
1051 error.SetErrorString ("SBTarget is invalid");
1052 }
1053 return sb_process;
1054}
1055
Chris Lattner24943d22010-06-08 16:52:24 +00001056SBFileSpec
1057SBTarget::GetExecutable ()
1058{
Caroline Tice7826c882010-10-26 03:11:13 +00001059
Chris Lattner24943d22010-06-08 16:52:24 +00001060 SBFileSpec exe_file_spec;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001061 TargetSP target_sp(GetSP());
1062 if (target_sp)
Chris Lattner24943d22010-06-08 16:52:24 +00001063 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001064 Module *exe_module = target_sp->GetExecutableModulePointer();
Greg Clayton5beb99d2011-08-11 02:48:45 +00001065 if (exe_module)
1066 exe_file_spec.SetFileSpec (exe_module->GetFileSpec());
Chris Lattner24943d22010-06-08 16:52:24 +00001067 }
Caroline Tice7826c882010-10-26 03:11:13 +00001068
Greg Claytone005f2c2010-11-06 01:53:30 +00001069 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001070 if (log)
1071 {
Greg Clayton49ce6822010-10-31 03:01:06 +00001072 log->Printf ("SBTarget(%p)::GetExecutable () => SBFileSpec(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +00001073 target_sp.get(), exe_file_spec.get());
Caroline Tice7826c882010-10-26 03:11:13 +00001074 }
1075
Chris Lattner24943d22010-06-08 16:52:24 +00001076 return exe_file_spec;
1077}
1078
Chris Lattner24943d22010-06-08 16:52:24 +00001079bool
Chris Lattner24943d22010-06-08 16:52:24 +00001080SBTarget::operator == (const SBTarget &rhs) const
1081{
Greg Clayton63094e02010-06-23 01:19:29 +00001082 return m_opaque_sp.get() == rhs.m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +00001083}
1084
1085bool
1086SBTarget::operator != (const SBTarget &rhs) const
1087{
Greg Clayton63094e02010-06-23 01:19:29 +00001088 return m_opaque_sp.get() != rhs.m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +00001089}
1090
Greg Clayton334d33a2012-01-30 07:41:31 +00001091lldb::TargetSP
1092SBTarget::GetSP () const
Greg Clayton15afa9f2011-10-01 02:59:24 +00001093{
1094 return m_opaque_sp;
1095}
1096
Greg Clayton63094e02010-06-23 01:19:29 +00001097void
Greg Clayton334d33a2012-01-30 07:41:31 +00001098SBTarget::SetSP (const lldb::TargetSP& target_sp)
Greg Clayton63094e02010-06-23 01:19:29 +00001099{
1100 m_opaque_sp = target_sp;
Chris Lattner24943d22010-06-08 16:52:24 +00001101}
1102
Greg Claytona3955062011-07-22 16:46:35 +00001103lldb::SBAddress
1104SBTarget::ResolveLoadAddress (lldb::addr_t vm_addr)
Greg Claytonea49cc72010-12-12 19:25:26 +00001105{
Greg Claytona3955062011-07-22 16:46:35 +00001106 lldb::SBAddress sb_addr;
1107 Address &addr = sb_addr.ref();
Greg Clayton0416bdf2012-01-30 09:04:36 +00001108 TargetSP target_sp(GetSP());
1109 if (target_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +00001110 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001111 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1112 if (target_sp->GetSectionLoadList().ResolveLoadAddress (vm_addr, addr))
Greg Claytona3955062011-07-22 16:46:35 +00001113 return sb_addr;
Greg Claytonbdcda462010-12-20 20:49:23 +00001114 }
Greg Claytonea49cc72010-12-12 19:25:26 +00001115
Greg Claytona3955062011-07-22 16:46:35 +00001116 // We have a load address that isn't in a section, just return an address
1117 // with the offset filled in (the address) and the section set to NULL
Greg Clayton3508c382012-02-24 01:59:29 +00001118 addr.SetRawAddress(vm_addr);
Greg Claytona3955062011-07-22 16:46:35 +00001119 return sb_addr;
Greg Claytonea49cc72010-12-12 19:25:26 +00001120}
1121
Greg Claytonafb81862011-03-02 21:34:46 +00001122SBSymbolContext
1123SBTarget::ResolveSymbolContextForAddress (const SBAddress& addr, uint32_t resolve_scope)
1124{
1125 SBSymbolContext sc;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001126 if (addr.IsValid())
1127 {
1128 TargetSP target_sp(GetSP());
1129 if (target_sp)
1130 target_sp->GetImages().ResolveSymbolContextForAddress (addr.ref(), resolve_scope, sc.ref());
1131 }
Greg Claytonafb81862011-03-02 21:34:46 +00001132 return sc;
1133}
1134
1135
Chris Lattner24943d22010-06-08 16:52:24 +00001136SBBreakpoint
1137SBTarget::BreakpointCreateByLocation (const char *file, uint32_t line)
1138{
Greg Claytond6d806c2010-11-08 00:28:40 +00001139 return SBBreakpoint(BreakpointCreateByLocation (SBFileSpec (file, false), line));
Chris Lattner24943d22010-06-08 16:52:24 +00001140}
1141
1142SBBreakpoint
1143SBTarget::BreakpointCreateByLocation (const SBFileSpec &sb_file_spec, uint32_t line)
1144{
Greg Claytone005f2c2010-11-06 01:53:30 +00001145 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001146
Chris Lattner24943d22010-06-08 16:52:24 +00001147 SBBreakpoint sb_bp;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001148 TargetSP target_sp(GetSP());
1149 if (target_sp && line != 0)
Greg Claytonbdcda462010-12-20 20:49:23 +00001150 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001151 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1152 *sb_bp = target_sp->CreateBreakpoint (NULL, *sb_file_spec, line, true, false);
Greg Claytonbdcda462010-12-20 20:49:23 +00001153 }
Caroline Tice7826c882010-10-26 03:11:13 +00001154
1155 if (log)
1156 {
1157 SBStream sstr;
1158 sb_bp.GetDescription (sstr);
Greg Clayton49ce6822010-10-31 03:01:06 +00001159 char path[PATH_MAX];
1160 sb_file_spec->GetPath (path, sizeof(path));
1161 log->Printf ("SBTarget(%p)::BreakpointCreateByLocation ( %s:%u ) => SBBreakpoint(%p): %s",
Greg Clayton0416bdf2012-01-30 09:04:36 +00001162 target_sp.get(),
Greg Clayton49ce6822010-10-31 03:01:06 +00001163 path,
Greg Claytona66ba462010-10-30 04:51:46 +00001164 line,
Greg Clayton49ce6822010-10-31 03:01:06 +00001165 sb_bp.get(),
Caroline Tice7826c882010-10-26 03:11:13 +00001166 sstr.GetData());
1167 }
1168
Chris Lattner24943d22010-06-08 16:52:24 +00001169 return sb_bp;
1170}
1171
1172SBBreakpoint
1173SBTarget::BreakpointCreateByName (const char *symbol_name, const char *module_name)
1174{
Greg Claytone005f2c2010-11-06 01:53:30 +00001175 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001176
Chris Lattner24943d22010-06-08 16:52:24 +00001177 SBBreakpoint sb_bp;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001178 TargetSP target_sp(GetSP());
1179 if (target_sp.get())
Chris Lattner24943d22010-06-08 16:52:24 +00001180 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001181 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Chris Lattner24943d22010-06-08 16:52:24 +00001182 if (module_name && module_name[0])
1183 {
Jim Ingham03c8ee52011-09-21 01:17:13 +00001184 FileSpecList module_spec_list;
1185 module_spec_list.Append (FileSpec (module_name, false));
Greg Clayton0416bdf2012-01-30 09:04:36 +00001186 *sb_bp = target_sp->CreateBreakpoint (&module_spec_list, NULL, symbol_name, eFunctionNameTypeAuto, false);
Chris Lattner24943d22010-06-08 16:52:24 +00001187 }
1188 else
1189 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001190 *sb_bp = target_sp->CreateBreakpoint (NULL, NULL, symbol_name, eFunctionNameTypeAuto, false);
Chris Lattner24943d22010-06-08 16:52:24 +00001191 }
1192 }
Caroline Tice7826c882010-10-26 03:11:13 +00001193
1194 if (log)
1195 {
Greg Clayton49ce6822010-10-31 03:01:06 +00001196 log->Printf ("SBTarget(%p)::BreakpointCreateByName (symbol=\"%s\", module=\"%s\") => SBBreakpoint(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +00001197 target_sp.get(), symbol_name, module_name, sb_bp.get());
Caroline Tice7826c882010-10-26 03:11:13 +00001198 }
1199
Chris Lattner24943d22010-06-08 16:52:24 +00001200 return sb_bp;
1201}
1202
Jim Inghamd6d47972011-09-23 00:54:11 +00001203lldb::SBBreakpoint
1204SBTarget::BreakpointCreateByName (const char *symbol_name,
1205 const SBFileSpecList &module_list,
1206 const SBFileSpecList &comp_unit_list)
1207{
Jim Ingham1fb8a2d2011-10-11 01:18:55 +00001208 uint32_t name_type_mask = eFunctionNameTypeAuto;
1209 return BreakpointCreateByName (symbol_name, name_type_mask, module_list, comp_unit_list);
1210}
1211
1212lldb::SBBreakpoint
1213SBTarget::BreakpointCreateByName (const char *symbol_name,
1214 uint32_t name_type_mask,
1215 const SBFileSpecList &module_list,
1216 const SBFileSpecList &comp_unit_list)
1217{
Jim Inghamd6d47972011-09-23 00:54:11 +00001218 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1219
1220 SBBreakpoint sb_bp;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001221 TargetSP target_sp(GetSP());
1222 if (target_sp && symbol_name && symbol_name[0])
Jim Inghamd6d47972011-09-23 00:54:11 +00001223 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001224 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1225 *sb_bp = target_sp->CreateBreakpoint (module_list.get(),
Jim Inghamd6d47972011-09-23 00:54:11 +00001226 comp_unit_list.get(),
1227 symbol_name,
Jim Ingham1fb8a2d2011-10-11 01:18:55 +00001228 name_type_mask,
Jim Inghamd6d47972011-09-23 00:54:11 +00001229 false);
1230 }
1231
1232 if (log)
1233 {
Jim Ingham1fb8a2d2011-10-11 01:18:55 +00001234 log->Printf ("SBTarget(%p)::BreakpointCreateByName (symbol=\"%s\", name_type: %d) => SBBreakpoint(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +00001235 target_sp.get(), symbol_name, name_type_mask, sb_bp.get());
Jim Inghamd6d47972011-09-23 00:54:11 +00001236 }
1237
1238 return sb_bp;
1239}
1240
Jim Ingham4722b102012-03-06 00:37:27 +00001241lldb::SBBreakpoint
1242SBTarget::BreakpointCreateByNames (const char *symbol_names[],
1243 uint32_t num_names,
1244 uint32_t name_type_mask,
1245 const SBFileSpecList &module_list,
1246 const SBFileSpecList &comp_unit_list)
1247{
1248 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1249
1250 SBBreakpoint sb_bp;
1251 TargetSP target_sp(GetSP());
1252 if (target_sp && num_names > 0)
1253 {
1254 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1255 *sb_bp = target_sp->CreateBreakpoint (module_list.get(),
1256 comp_unit_list.get(),
1257 symbol_names,
1258 num_names,
1259 name_type_mask,
1260 false);
1261 }
1262
1263 if (log)
1264 {
1265 log->Printf ("SBTarget(%p)::BreakpointCreateByName (symbols={", target_sp.get());
1266 for (uint32_t i = 0 ; i < num_names; i++)
1267 {
1268 char sep;
1269 if (i < num_names - 1)
1270 sep = ',';
1271 else
1272 sep = '}';
1273 if (symbol_names[i] != NULL)
1274 log->Printf ("\"%s\"%c ", symbol_names[i], sep);
1275 else
1276 log->Printf ("\"<NULL>\"%c ", sep);
1277
1278 }
1279 log->Printf ("name_type: %d) => SBBreakpoint(%p)", name_type_mask, sb_bp.get());
1280 }
1281
1282 return sb_bp;
1283}
Jim Inghamd6d47972011-09-23 00:54:11 +00001284
Chris Lattner24943d22010-06-08 16:52:24 +00001285SBBreakpoint
1286SBTarget::BreakpointCreateByRegex (const char *symbol_name_regex, const char *module_name)
1287{
Greg Claytone005f2c2010-11-06 01:53:30 +00001288 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001289
Chris Lattner24943d22010-06-08 16:52:24 +00001290 SBBreakpoint sb_bp;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001291 TargetSP target_sp(GetSP());
1292 if (target_sp && symbol_name_regex && symbol_name_regex[0])
Chris Lattner24943d22010-06-08 16:52:24 +00001293 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001294 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Chris Lattner24943d22010-06-08 16:52:24 +00001295 RegularExpression regexp(symbol_name_regex);
1296
1297 if (module_name && module_name[0])
1298 {
Jim Ingham03c8ee52011-09-21 01:17:13 +00001299 FileSpecList module_spec_list;
1300 module_spec_list.Append (FileSpec (module_name, false));
Chris Lattner24943d22010-06-08 16:52:24 +00001301
Greg Clayton0416bdf2012-01-30 09:04:36 +00001302 *sb_bp = target_sp->CreateFuncRegexBreakpoint (&module_spec_list, NULL, regexp, false);
Chris Lattner24943d22010-06-08 16:52:24 +00001303 }
1304 else
1305 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001306 *sb_bp = target_sp->CreateFuncRegexBreakpoint (NULL, NULL, regexp, false);
Chris Lattner24943d22010-06-08 16:52:24 +00001307 }
1308 }
Caroline Tice7826c882010-10-26 03:11:13 +00001309
1310 if (log)
1311 {
Greg Clayton49ce6822010-10-31 03:01:06 +00001312 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (symbol_regex=\"%s\", module_name=\"%s\") => SBBreakpoint(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +00001313 target_sp.get(), symbol_name_regex, module_name, sb_bp.get());
Caroline Tice7826c882010-10-26 03:11:13 +00001314 }
1315
Chris Lattner24943d22010-06-08 16:52:24 +00001316 return sb_bp;
1317}
1318
Jim Inghamd6d47972011-09-23 00:54:11 +00001319lldb::SBBreakpoint
1320SBTarget::BreakpointCreateByRegex (const char *symbol_name_regex,
1321 const SBFileSpecList &module_list,
1322 const SBFileSpecList &comp_unit_list)
1323{
1324 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Chris Lattner24943d22010-06-08 16:52:24 +00001325
Jim Inghamd6d47972011-09-23 00:54:11 +00001326 SBBreakpoint sb_bp;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001327 TargetSP target_sp(GetSP());
1328 if (target_sp && symbol_name_regex && symbol_name_regex[0])
Jim Inghamd6d47972011-09-23 00:54:11 +00001329 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001330 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Jim Inghamd6d47972011-09-23 00:54:11 +00001331 RegularExpression regexp(symbol_name_regex);
1332
Greg Clayton0416bdf2012-01-30 09:04:36 +00001333 *sb_bp = target_sp->CreateFuncRegexBreakpoint (module_list.get(), comp_unit_list.get(), regexp, false);
Jim Inghamd6d47972011-09-23 00:54:11 +00001334 }
1335
1336 if (log)
1337 {
1338 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (symbol_regex=\"%s\") => SBBreakpoint(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +00001339 target_sp.get(), symbol_name_regex, sb_bp.get());
Jim Inghamd6d47972011-09-23 00:54:11 +00001340 }
1341
1342 return sb_bp;
1343}
Chris Lattner24943d22010-06-08 16:52:24 +00001344
1345SBBreakpoint
1346SBTarget::BreakpointCreateByAddress (addr_t address)
1347{
Greg Claytone005f2c2010-11-06 01:53:30 +00001348 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001349
Chris Lattner24943d22010-06-08 16:52:24 +00001350 SBBreakpoint sb_bp;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001351 TargetSP target_sp(GetSP());
1352 if (target_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +00001353 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001354 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1355 *sb_bp = target_sp->CreateBreakpoint (address, false);
Greg Claytonbdcda462010-12-20 20:49:23 +00001356 }
Caroline Tice7826c882010-10-26 03:11:13 +00001357
1358 if (log)
1359 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001360 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 +00001361 }
1362
Chris Lattner24943d22010-06-08 16:52:24 +00001363 return sb_bp;
1364}
1365
Jim Ingham03c8ee52011-09-21 01:17:13 +00001366lldb::SBBreakpoint
1367SBTarget::BreakpointCreateBySourceRegex (const char *source_regex, const lldb::SBFileSpec &source_file, const char *module_name)
1368{
1369 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1370
1371 SBBreakpoint sb_bp;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001372 TargetSP target_sp(GetSP());
1373 if (target_sp && source_regex && source_regex[0])
Jim Ingham03c8ee52011-09-21 01:17:13 +00001374 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001375 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Jim Ingham03c8ee52011-09-21 01:17:13 +00001376 RegularExpression regexp(source_regex);
Jim Inghamd6d47972011-09-23 00:54:11 +00001377 FileSpecList source_file_spec_list;
1378 source_file_spec_list.Append (source_file.ref());
Jim Ingham03c8ee52011-09-21 01:17:13 +00001379
1380 if (module_name && module_name[0])
1381 {
1382 FileSpecList module_spec_list;
1383 module_spec_list.Append (FileSpec (module_name, false));
1384
Greg Clayton0416bdf2012-01-30 09:04:36 +00001385 *sb_bp = target_sp->CreateSourceRegexBreakpoint (&module_spec_list, &source_file_spec_list, regexp, false);
Jim Ingham03c8ee52011-09-21 01:17:13 +00001386 }
1387 else
1388 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001389 *sb_bp = target_sp->CreateSourceRegexBreakpoint (NULL, &source_file_spec_list, regexp, false);
Jim Ingham03c8ee52011-09-21 01:17:13 +00001390 }
1391 }
1392
1393 if (log)
1394 {
1395 char path[PATH_MAX];
1396 source_file->GetPath (path, sizeof(path));
1397 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (source_regex=\"%s\", file=\"%s\", module_name=\"%s\") => SBBreakpoint(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +00001398 target_sp.get(), source_regex, path, module_name, sb_bp.get());
Jim Ingham03c8ee52011-09-21 01:17:13 +00001399 }
1400
1401 return sb_bp;
1402}
1403
Jim Inghamd6d47972011-09-23 00:54:11 +00001404lldb::SBBreakpoint
1405SBTarget::BreakpointCreateBySourceRegex (const char *source_regex,
1406 const SBFileSpecList &module_list,
1407 const lldb::SBFileSpecList &source_file_list)
1408{
1409 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1410
1411 SBBreakpoint sb_bp;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001412 TargetSP target_sp(GetSP());
1413 if (target_sp && source_regex && source_regex[0])
Jim Inghamd6d47972011-09-23 00:54:11 +00001414 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001415 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Jim Inghamd6d47972011-09-23 00:54:11 +00001416 RegularExpression regexp(source_regex);
Greg Clayton0416bdf2012-01-30 09:04:36 +00001417 *sb_bp = target_sp->CreateSourceRegexBreakpoint (module_list.get(), source_file_list.get(), regexp, false);
Jim Inghamd6d47972011-09-23 00:54:11 +00001418 }
1419
1420 if (log)
1421 {
1422 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (source_regex=\"%s\") => SBBreakpoint(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +00001423 target_sp.get(), source_regex, sb_bp.get());
Jim Inghamd6d47972011-09-23 00:54:11 +00001424 }
1425
1426 return sb_bp;
1427}
Jim Ingham03c8ee52011-09-21 01:17:13 +00001428
Jim Ingham4722b102012-03-06 00:37:27 +00001429lldb::SBBreakpoint
1430SBTarget::BreakpointCreateForException (lldb::LanguageType language,
1431 bool catch_bp,
1432 bool throw_bp)
1433{
1434 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1435
1436 SBBreakpoint sb_bp;
1437 TargetSP target_sp(GetSP());
1438 if (target_sp)
1439 {
1440 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1441 *sb_bp = target_sp->CreateExceptionBreakpoint (language, catch_bp, throw_bp);
1442 }
1443
1444 if (log)
1445 {
1446 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (Language: %s, catch: %s throw: %s) => SBBreakpoint(%p)",
1447 target_sp.get(),
1448 LanguageRuntime::GetNameForLanguageType(language),
1449 catch_bp ? "on" : "off",
1450 throw_bp ? "on" : "off",
1451 sb_bp.get());
1452 }
1453
1454 return sb_bp;
1455}
1456
Greg Claytonc7f5d5c2010-07-23 23:33:17 +00001457uint32_t
1458SBTarget::GetNumBreakpoints () const
1459{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001460 TargetSP target_sp(GetSP());
1461 if (target_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +00001462 {
1463 // The breakpoint list is thread safe, no need to lock
Greg Clayton0416bdf2012-01-30 09:04:36 +00001464 return target_sp->GetBreakpointList().GetSize();
Greg Claytonbdcda462010-12-20 20:49:23 +00001465 }
Greg Claytonc7f5d5c2010-07-23 23:33:17 +00001466 return 0;
1467}
1468
1469SBBreakpoint
1470SBTarget::GetBreakpointAtIndex (uint32_t idx) const
1471{
1472 SBBreakpoint sb_breakpoint;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001473 TargetSP target_sp(GetSP());
1474 if (target_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +00001475 {
1476 // The breakpoint list is thread safe, no need to lock
Greg Clayton0416bdf2012-01-30 09:04:36 +00001477 *sb_breakpoint = target_sp->GetBreakpointList().GetBreakpointAtIndex(idx);
Greg Claytonbdcda462010-12-20 20:49:23 +00001478 }
Greg Claytonc7f5d5c2010-07-23 23:33:17 +00001479 return sb_breakpoint;
1480}
Chris Lattner24943d22010-06-08 16:52:24 +00001481
1482bool
1483SBTarget::BreakpointDelete (break_id_t bp_id)
1484{
Greg Claytone005f2c2010-11-06 01:53:30 +00001485 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001486
Caroline Tice7826c882010-10-26 03:11:13 +00001487 bool result = false;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001488 TargetSP target_sp(GetSP());
1489 if (target_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +00001490 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001491 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1492 result = target_sp->RemoveBreakpointByID (bp_id);
Greg Claytonbdcda462010-12-20 20:49:23 +00001493 }
Caroline Tice7826c882010-10-26 03:11:13 +00001494
1495 if (log)
1496 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001497 log->Printf ("SBTarget(%p)::BreakpointDelete (bp_id=%d) => %i", target_sp.get(), (uint32_t) bp_id, result);
Caroline Tice7826c882010-10-26 03:11:13 +00001498 }
1499
1500 return result;
Chris Lattner24943d22010-06-08 16:52:24 +00001501}
1502
Johnny Chen096c2932011-09-26 22:40:50 +00001503SBBreakpoint
1504SBTarget::FindBreakpointByID (break_id_t bp_id)
1505{
1506 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1507
1508 SBBreakpoint sb_breakpoint;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001509 TargetSP target_sp(GetSP());
1510 if (target_sp && bp_id != LLDB_INVALID_BREAK_ID)
Johnny Chen096c2932011-09-26 22:40:50 +00001511 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001512 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1513 *sb_breakpoint = target_sp->GetBreakpointByID (bp_id);
Johnny Chen096c2932011-09-26 22:40:50 +00001514 }
1515
1516 if (log)
1517 {
1518 log->Printf ("SBTarget(%p)::FindBreakpointByID (bp_id=%d) => SBBreakpoint(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +00001519 target_sp.get(), (uint32_t) bp_id, sb_breakpoint.get());
Johnny Chen096c2932011-09-26 22:40:50 +00001520 }
1521
1522 return sb_breakpoint;
1523}
1524
Chris Lattner24943d22010-06-08 16:52:24 +00001525bool
1526SBTarget::EnableAllBreakpoints ()
1527{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001528 TargetSP target_sp(GetSP());
1529 if (target_sp)
Chris Lattner24943d22010-06-08 16:52:24 +00001530 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001531 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1532 target_sp->EnableAllBreakpoints ();
Chris Lattner24943d22010-06-08 16:52:24 +00001533 return true;
1534 }
1535 return false;
1536}
1537
1538bool
1539SBTarget::DisableAllBreakpoints ()
1540{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001541 TargetSP target_sp(GetSP());
1542 if (target_sp)
Chris Lattner24943d22010-06-08 16:52:24 +00001543 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001544 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1545 target_sp->DisableAllBreakpoints ();
Chris Lattner24943d22010-06-08 16:52:24 +00001546 return true;
1547 }
1548 return false;
1549}
1550
1551bool
1552SBTarget::DeleteAllBreakpoints ()
1553{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001554 TargetSP target_sp(GetSP());
1555 if (target_sp)
Chris Lattner24943d22010-06-08 16:52:24 +00001556 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001557 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1558 target_sp->RemoveAllBreakpoints ();
Chris Lattner24943d22010-06-08 16:52:24 +00001559 return true;
1560 }
1561 return false;
1562}
1563
Johnny Chen096c2932011-09-26 22:40:50 +00001564uint32_t
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001565SBTarget::GetNumWatchpoints () const
Johnny Chen096c2932011-09-26 22:40:50 +00001566{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001567 TargetSP target_sp(GetSP());
1568 if (target_sp)
Johnny Chen096c2932011-09-26 22:40:50 +00001569 {
Johnny Chenecd4feb2011-10-14 00:42:25 +00001570 // The watchpoint list is thread safe, no need to lock
Greg Clayton0416bdf2012-01-30 09:04:36 +00001571 return target_sp->GetWatchpointList().GetSize();
Johnny Chen096c2932011-09-26 22:40:50 +00001572 }
1573 return 0;
1574}
1575
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001576SBWatchpoint
1577SBTarget::GetWatchpointAtIndex (uint32_t idx) const
Johnny Chen5eb54bb2011-09-27 20:29:45 +00001578{
Johnny Chenecd4feb2011-10-14 00:42:25 +00001579 SBWatchpoint sb_watchpoint;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001580 TargetSP target_sp(GetSP());
1581 if (target_sp)
Johnny Chen096c2932011-09-26 22:40:50 +00001582 {
Johnny Chenecd4feb2011-10-14 00:42:25 +00001583 // The watchpoint list is thread safe, no need to lock
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001584 sb_watchpoint.SetSP (target_sp->GetWatchpointList().GetByIndex(idx));
Johnny Chen096c2932011-09-26 22:40:50 +00001585 }
Johnny Chenecd4feb2011-10-14 00:42:25 +00001586 return sb_watchpoint;
Johnny Chen096c2932011-09-26 22:40:50 +00001587}
1588
1589bool
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001590SBTarget::DeleteWatchpoint (watch_id_t wp_id)
Johnny Chen096c2932011-09-26 22:40:50 +00001591{
1592 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1593
1594 bool result = false;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001595 TargetSP target_sp(GetSP());
1596 if (target_sp)
Johnny Chen096c2932011-09-26 22:40:50 +00001597 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001598 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1599 result = target_sp->RemoveWatchpointByID (wp_id);
Johnny Chen096c2932011-09-26 22:40:50 +00001600 }
1601
1602 if (log)
1603 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001604 log->Printf ("SBTarget(%p)::WatchpointDelete (wp_id=%d) => %i", target_sp.get(), (uint32_t) wp_id, result);
Johnny Chen096c2932011-09-26 22:40:50 +00001605 }
1606
1607 return result;
1608}
1609
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001610SBWatchpoint
1611SBTarget::FindWatchpointByID (lldb::watch_id_t wp_id)
Johnny Chen096c2932011-09-26 22:40:50 +00001612{
1613 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1614
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001615 SBWatchpoint sb_watchpoint;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001616 lldb::WatchpointSP watchpoint_sp;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001617 TargetSP target_sp(GetSP());
1618 if (target_sp && wp_id != LLDB_INVALID_WATCH_ID)
Johnny Chen096c2932011-09-26 22:40:50 +00001619 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001620 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001621 watchpoint_sp = target_sp->GetWatchpointList().FindByID(wp_id);
1622 sb_watchpoint.SetSP (watchpoint_sp);
Johnny Chen096c2932011-09-26 22:40:50 +00001623 }
1624
1625 if (log)
1626 {
Johnny Chenecd4feb2011-10-14 00:42:25 +00001627 log->Printf ("SBTarget(%p)::FindWatchpointByID (bp_id=%d) => SBWatchpoint(%p)",
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001628 target_sp.get(), (uint32_t) wp_id, watchpoint_sp.get());
Johnny Chen096c2932011-09-26 22:40:50 +00001629 }
1630
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001631 return sb_watchpoint;
1632}
1633
1634lldb::SBWatchpoint
1635SBTarget::WatchAddress (lldb::addr_t addr, size_t size, bool read, bool write)
1636{
1637 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1638
1639 SBWatchpoint sb_watchpoint;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001640 lldb::WatchpointSP watchpoint_sp;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001641 TargetSP target_sp(GetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001642 if (target_sp && (read || write) && addr != LLDB_INVALID_ADDRESS && size > 0)
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001643 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001644 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001645 uint32_t watch_type = 0;
1646 if (read)
1647 watch_type |= LLDB_WATCH_TYPE_READ;
1648 if (write)
1649 watch_type |= LLDB_WATCH_TYPE_WRITE;
1650 watchpoint_sp = target_sp->CreateWatchpoint(addr, size, watch_type);
1651 sb_watchpoint.SetSP (watchpoint_sp);
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001652 }
1653
1654 if (log)
1655 {
1656 log->Printf ("SBTarget(%p)::WatchAddress (addr=0x%llx, 0x%u) => SBWatchpoint(%p)",
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001657 target_sp.get(), addr, (uint32_t) size, watchpoint_sp.get());
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001658 }
1659
1660 return sb_watchpoint;
Johnny Chen096c2932011-09-26 22:40:50 +00001661}
1662
1663bool
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001664SBTarget::EnableAllWatchpoints ()
Johnny Chen096c2932011-09-26 22:40:50 +00001665{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001666 TargetSP target_sp(GetSP());
1667 if (target_sp)
Johnny Chen096c2932011-09-26 22:40:50 +00001668 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001669 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1670 target_sp->EnableAllWatchpoints ();
Johnny Chen096c2932011-09-26 22:40:50 +00001671 return true;
1672 }
1673 return false;
1674}
1675
1676bool
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001677SBTarget::DisableAllWatchpoints ()
Johnny Chen096c2932011-09-26 22:40:50 +00001678{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001679 TargetSP target_sp(GetSP());
1680 if (target_sp)
Johnny Chen096c2932011-09-26 22:40:50 +00001681 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001682 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1683 target_sp->DisableAllWatchpoints ();
Johnny Chen096c2932011-09-26 22:40:50 +00001684 return true;
1685 }
1686 return false;
1687}
1688
1689bool
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001690SBTarget::DeleteAllWatchpoints ()
Johnny Chen096c2932011-09-26 22:40:50 +00001691{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001692 TargetSP target_sp(GetSP());
1693 if (target_sp)
Johnny Chen096c2932011-09-26 22:40:50 +00001694 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001695 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1696 target_sp->RemoveAllWatchpoints ();
Johnny Chen096c2932011-09-26 22:40:50 +00001697 return true;
1698 }
1699 return false;
1700}
1701
Chris Lattner24943d22010-06-08 16:52:24 +00001702
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001703lldb::SBModule
1704SBTarget::AddModule (const char *path,
1705 const char *triple,
1706 const char *uuid_cstr)
1707{
1708 lldb::SBModule sb_module;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001709 TargetSP target_sp(GetSP());
1710 if (target_sp)
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001711 {
Greg Clayton444fe992012-02-26 05:51:37 +00001712 ModuleSpec module_spec;
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001713 if (path)
Greg Clayton444fe992012-02-26 05:51:37 +00001714 module_spec.GetFileSpec().SetFile(path, false);
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001715
1716 if (uuid_cstr)
Greg Clayton444fe992012-02-26 05:51:37 +00001717 module_spec.GetUUID().SetfromCString(uuid_cstr);
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001718
1719 if (triple)
Greg Clayton444fe992012-02-26 05:51:37 +00001720 module_spec.GetArchitecture().SetTriple (triple, target_sp->GetPlatform ().get());
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001721
Greg Clayton444fe992012-02-26 05:51:37 +00001722 sb_module.SetSP(target_sp->GetSharedModule (module_spec));
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001723 }
1724 return sb_module;
1725}
1726
1727bool
1728SBTarget::AddModule (lldb::SBModule &module)
1729{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001730 TargetSP target_sp(GetSP());
1731 if (target_sp)
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001732 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001733 target_sp->GetImages().AppendIfNeeded (module.GetSP());
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001734 return true;
1735 }
1736 return false;
1737}
1738
Chris Lattner24943d22010-06-08 16:52:24 +00001739uint32_t
1740SBTarget::GetNumModules () const
1741{
Greg Claytone005f2c2010-11-06 01:53:30 +00001742 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001743
Caroline Tice7826c882010-10-26 03:11:13 +00001744 uint32_t num = 0;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001745 TargetSP target_sp(GetSP());
1746 if (target_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +00001747 {
1748 // The module list is thread safe, no need to lock
Greg Clayton0416bdf2012-01-30 09:04:36 +00001749 num = target_sp->GetImages().GetSize();
Greg Claytonbdcda462010-12-20 20:49:23 +00001750 }
Caroline Tice7826c882010-10-26 03:11:13 +00001751
1752 if (log)
Greg Clayton0416bdf2012-01-30 09:04:36 +00001753 log->Printf ("SBTarget(%p)::GetNumModules () => %d", target_sp.get(), num);
Caroline Tice7826c882010-10-26 03:11:13 +00001754
1755 return num;
Chris Lattner24943d22010-06-08 16:52:24 +00001756}
1757
Greg Clayton43490d12010-07-30 20:12:55 +00001758void
1759SBTarget::Clear ()
1760{
Greg Claytone005f2c2010-11-06 01:53:30 +00001761 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001762
1763 if (log)
Greg Clayton3f5ee7f2010-10-29 04:59:35 +00001764 log->Printf ("SBTarget(%p)::Clear ()", m_opaque_sp.get());
Caroline Tice7826c882010-10-26 03:11:13 +00001765
Greg Clayton43490d12010-07-30 20:12:55 +00001766 m_opaque_sp.reset();
1767}
1768
1769
Chris Lattner24943d22010-06-08 16:52:24 +00001770SBModule
1771SBTarget::FindModule (const SBFileSpec &sb_file_spec)
1772{
1773 SBModule sb_module;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001774 TargetSP target_sp(GetSP());
1775 if (target_sp && sb_file_spec.IsValid())
Greg Claytonbdcda462010-12-20 20:49:23 +00001776 {
Greg Clayton444fe992012-02-26 05:51:37 +00001777 ModuleSpec module_spec(*sb_file_spec);
Greg Claytonbdcda462010-12-20 20:49:23 +00001778 // The module list is thread safe, no need to lock
Greg Clayton444fe992012-02-26 05:51:37 +00001779 sb_module.SetSP (target_sp->GetImages().FindFirstModule (module_spec));
Greg Claytonbdcda462010-12-20 20:49:23 +00001780 }
Chris Lattner24943d22010-06-08 16:52:24 +00001781 return sb_module;
1782}
1783
Greg Clayton1b925202012-01-29 06:07:39 +00001784lldb::ByteOrder
1785SBTarget::GetByteOrder ()
1786{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001787 TargetSP target_sp(GetSP());
1788 if (target_sp)
1789 return target_sp->GetArchitecture().GetByteOrder();
Greg Clayton1b925202012-01-29 06:07:39 +00001790 return eByteOrderInvalid;
1791}
1792
1793const char *
1794SBTarget::GetTriple ()
1795{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001796 TargetSP target_sp(GetSP());
1797 if (target_sp)
Greg Clayton1b925202012-01-29 06:07:39 +00001798 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001799 std::string triple (target_sp->GetArchitecture().GetTriple().str());
Greg Clayton1b925202012-01-29 06:07:39 +00001800 // Unique the string so we don't run into ownership issues since
1801 // the const strings put the string into the string pool once and
1802 // the strings never comes out
1803 ConstString const_triple (triple.c_str());
1804 return const_triple.GetCString();
1805 }
1806 return NULL;
1807}
1808
1809uint32_t
1810SBTarget::GetAddressByteSize()
1811{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001812 TargetSP target_sp(GetSP());
1813 if (target_sp)
1814 return target_sp->GetArchitecture().GetAddressByteSize();
Greg Clayton1b925202012-01-29 06:07:39 +00001815 return sizeof(void*);
1816}
1817
1818
Chris Lattner24943d22010-06-08 16:52:24 +00001819SBModule
1820SBTarget::GetModuleAtIndex (uint32_t idx)
1821{
Greg Claytone005f2c2010-11-06 01:53:30 +00001822 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001823
Chris Lattner24943d22010-06-08 16:52:24 +00001824 SBModule sb_module;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001825 ModuleSP module_sp;
1826 TargetSP target_sp(GetSP());
1827 if (target_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +00001828 {
1829 // The module list is thread safe, no need to lock
Greg Clayton0416bdf2012-01-30 09:04:36 +00001830 module_sp = target_sp->GetImages().GetModuleAtIndex(idx);
1831 sb_module.SetSP (module_sp);
Greg Claytonbdcda462010-12-20 20:49:23 +00001832 }
Caroline Tice7826c882010-10-26 03:11:13 +00001833
1834 if (log)
1835 {
Greg Clayton49ce6822010-10-31 03:01:06 +00001836 log->Printf ("SBTarget(%p)::GetModuleAtIndex (idx=%d) => SBModule(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +00001837 target_sp.get(), idx, module_sp.get());
Caroline Tice7826c882010-10-26 03:11:13 +00001838 }
1839
Chris Lattner24943d22010-06-08 16:52:24 +00001840 return sb_module;
1841}
1842
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001843bool
1844SBTarget::RemoveModule (lldb::SBModule module)
1845{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001846 TargetSP target_sp(GetSP());
1847 if (target_sp)
1848 return target_sp->GetImages().Remove(module.GetSP());
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001849 return false;
1850}
1851
Chris Lattner24943d22010-06-08 16:52:24 +00001852
1853SBBroadcaster
1854SBTarget::GetBroadcaster () const
1855{
Greg Claytone005f2c2010-11-06 01:53:30 +00001856 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001857
Greg Clayton0416bdf2012-01-30 09:04:36 +00001858 TargetSP target_sp(GetSP());
1859 SBBroadcaster broadcaster(target_sp.get(), false);
Caroline Tice7826c882010-10-26 03:11:13 +00001860
1861 if (log)
Greg Clayton3f5ee7f2010-10-29 04:59:35 +00001862 log->Printf ("SBTarget(%p)::GetBroadcaster () => SBBroadcaster(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +00001863 target_sp.get(), broadcaster.get());
Caroline Tice7826c882010-10-26 03:11:13 +00001864
Chris Lattner24943d22010-06-08 16:52:24 +00001865 return broadcaster;
1866}
1867
Caroline Tice98f930f2010-09-20 05:20:02 +00001868bool
Caroline Tice7826c882010-10-26 03:11:13 +00001869SBTarget::GetDescription (SBStream &description, lldb::DescriptionLevel description_level)
Caroline Tice98f930f2010-09-20 05:20:02 +00001870{
Greg Clayton96154be2011-11-13 06:57:31 +00001871 Stream &strm = description.ref();
1872
Greg Clayton0416bdf2012-01-30 09:04:36 +00001873 TargetSP target_sp(GetSP());
1874 if (target_sp)
Caroline Ticee7a566e2010-09-20 16:21:41 +00001875 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001876 target_sp->Dump (&strm, description_level);
Caroline Tice7826c882010-10-26 03:11:13 +00001877 }
1878 else
Greg Clayton96154be2011-11-13 06:57:31 +00001879 strm.PutCString ("No value");
Caroline Tice7826c882010-10-26 03:11:13 +00001880
1881 return true;
1882}
1883
Greg Clayton7dd5c512012-02-06 01:44:54 +00001884lldb::SBSymbolContextList
1885SBTarget::FindFunctions (const char *name, uint32_t name_type_mask)
Greg Clayton4ed315f2011-06-21 01:34:41 +00001886{
Greg Clayton7dd5c512012-02-06 01:44:54 +00001887 lldb::SBSymbolContextList sb_sc_list;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001888 if (name && name[0])
Greg Clayton4ed315f2011-06-21 01:34:41 +00001889 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001890 TargetSP target_sp(GetSP());
1891 if (target_sp)
1892 {
1893 const bool symbols_ok = true;
Sean Callanan302d78c2012-02-10 22:52:19 +00001894 const bool inlines_ok = true;
Greg Clayton7dd5c512012-02-06 01:44:54 +00001895 const bool append = true;
1896 target_sp->GetImages().FindFunctions (ConstString(name),
1897 name_type_mask,
Sean Callanan302d78c2012-02-10 22:52:19 +00001898 symbols_ok,
1899 inlines_ok,
Greg Clayton7dd5c512012-02-06 01:44:54 +00001900 append,
1901 *sb_sc_list);
Greg Clayton0416bdf2012-01-30 09:04:36 +00001902 }
Greg Clayton4ed315f2011-06-21 01:34:41 +00001903 }
Greg Clayton7dd5c512012-02-06 01:44:54 +00001904 return sb_sc_list;
Greg Clayton4ed315f2011-06-21 01:34:41 +00001905}
1906
Enrico Granata979e20d2011-07-29 19:53:35 +00001907lldb::SBType
1908SBTarget::FindFirstType (const char* type)
1909{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001910 TargetSP target_sp(GetSP());
1911 if (type && target_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +00001912 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001913 size_t count = target_sp->GetImages().GetSize();
Enrico Granata979e20d2011-07-29 19:53:35 +00001914 for (size_t idx = 0; idx < count; idx++)
1915 {
1916 SBType found_at_idx = GetModuleAtIndex(idx).FindFirstType(type);
1917
1918 if (found_at_idx.IsValid())
1919 return found_at_idx;
1920 }
1921 }
1922 return SBType();
1923}
1924
1925lldb::SBTypeList
1926SBTarget::FindTypes (const char* type)
1927{
1928
1929 SBTypeList retval;
1930
Greg Clayton0416bdf2012-01-30 09:04:36 +00001931 TargetSP target_sp(GetSP());
1932 if (type && target_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +00001933 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001934 ModuleList& images = target_sp->GetImages();
Enrico Granata979e20d2011-07-29 19:53:35 +00001935 ConstString name_const(type);
1936 SymbolContext sc;
1937 TypeList type_list;
1938
1939 uint32_t num_matches = images.FindTypes(sc,
1940 name_const,
1941 true,
1942 UINT32_MAX,
1943 type_list);
1944
1945 for (size_t idx = 0; idx < num_matches; idx++)
1946 {
Greg Clayton0fb0bcc2011-08-03 22:57:10 +00001947 TypeSP type_sp (type_list.GetTypeAtIndex(idx));
1948 if (type_sp)
1949 retval.Append(SBType(type_sp));
Enrico Granata979e20d2011-07-29 19:53:35 +00001950 }
1951 }
1952 return retval;
1953}
1954
Greg Clayton917c0002011-06-29 22:09:02 +00001955SBValueList
1956SBTarget::FindGlobalVariables (const char *name, uint32_t max_matches)
1957{
1958 SBValueList sb_value_list;
1959
Greg Clayton0416bdf2012-01-30 09:04:36 +00001960 TargetSP target_sp(GetSP());
1961 if (name && target_sp)
Greg Clayton917c0002011-06-29 22:09:02 +00001962 {
1963 VariableList variable_list;
1964 const bool append = true;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001965 const uint32_t match_count = target_sp->GetImages().FindGlobalVariables (ConstString (name),
1966 append,
1967 max_matches,
1968 variable_list);
Greg Clayton917c0002011-06-29 22:09:02 +00001969
1970 if (match_count > 0)
1971 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001972 ExecutionContextScope *exe_scope = target_sp->GetProcessSP().get();
Greg Clayton917c0002011-06-29 22:09:02 +00001973 if (exe_scope == NULL)
Greg Clayton0416bdf2012-01-30 09:04:36 +00001974 exe_scope = target_sp.get();
Greg Clayton917c0002011-06-29 22:09:02 +00001975 ValueObjectList &value_object_list = sb_value_list.ref();
1976 for (uint32_t i=0; i<match_count; ++i)
1977 {
1978 lldb::ValueObjectSP valobj_sp (ValueObjectVariable::Create (exe_scope, variable_list.GetVariableAtIndex(i)));
1979 if (valobj_sp)
1980 value_object_list.Append(valobj_sp);
1981 }
1982 }
1983 }
1984
1985 return sb_value_list;
1986}
1987
Jim Inghamcc637462011-09-13 00:29:56 +00001988SBSourceManager
1989SBTarget::GetSourceManager()
1990{
1991 SBSourceManager source_manager (*this);
1992 return source_manager;
1993}
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001994
Sean Callananef1f6902011-12-14 23:49:37 +00001995lldb::SBInstructionList
1996SBTarget::GetInstructions (lldb::SBAddress base_addr, const void *buf, size_t size)
1997{
1998 SBInstructionList sb_instructions;
1999
Greg Clayton0416bdf2012-01-30 09:04:36 +00002000 TargetSP target_sp(GetSP());
2001 if (target_sp)
Sean Callananef1f6902011-12-14 23:49:37 +00002002 {
2003 Address addr;
2004
2005 if (base_addr.get())
2006 addr = *base_addr.get();
2007
Greg Clayton0416bdf2012-01-30 09:04:36 +00002008 sb_instructions.SetDisassembler (Disassembler::DisassembleBytes (target_sp->GetArchitecture(),
Sean Callananef1f6902011-12-14 23:49:37 +00002009 NULL,
2010 addr,
2011 buf,
2012 size));
2013 }
2014
2015 return sb_instructions;
2016}
2017
2018lldb::SBInstructionList
2019SBTarget::GetInstructions (lldb::addr_t base_addr, const void *buf, size_t size)
2020{
2021 return GetInstructions (ResolveLoadAddress(base_addr), buf, size);
2022}
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002023
2024SBError
2025SBTarget::SetSectionLoadAddress (lldb::SBSection section,
2026 lldb::addr_t section_base_addr)
2027{
2028 SBError sb_error;
Greg Clayton0416bdf2012-01-30 09:04:36 +00002029 TargetSP target_sp(GetSP());
2030 if (target_sp)
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002031 {
2032 if (!section.IsValid())
2033 {
2034 sb_error.SetErrorStringWithFormat ("invalid section");
2035 }
2036 else
2037 {
Greg Clayton3508c382012-02-24 01:59:29 +00002038 target_sp->GetSectionLoadList().SetSectionLoadAddress (section.GetSP().get(), section_base_addr);
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002039 }
2040 }
2041 else
2042 {
2043 sb_error.SetErrorStringWithFormat ("invalid target");
2044 }
2045 return sb_error;
2046}
2047
2048SBError
2049SBTarget::ClearSectionLoadAddress (lldb::SBSection section)
2050{
2051 SBError sb_error;
2052
Greg Clayton0416bdf2012-01-30 09:04:36 +00002053 TargetSP target_sp(GetSP());
2054 if (target_sp)
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002055 {
2056 if (!section.IsValid())
2057 {
2058 sb_error.SetErrorStringWithFormat ("invalid section");
2059 }
2060 else
2061 {
Greg Clayton3508c382012-02-24 01:59:29 +00002062 target_sp->GetSectionLoadList().SetSectionUnloaded (section.GetSP().get());
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002063 }
2064 }
2065 else
2066 {
2067 sb_error.SetErrorStringWithFormat ("invalid target");
2068 }
2069 return sb_error;
2070}
2071
2072SBError
2073SBTarget::SetModuleLoadAddress (lldb::SBModule module, int64_t slide_offset)
2074{
2075 SBError sb_error;
2076
2077 char path[PATH_MAX];
Greg Clayton0416bdf2012-01-30 09:04:36 +00002078 TargetSP target_sp(GetSP());
2079 if (target_sp)
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002080 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00002081 ModuleSP module_sp (module.GetSP());
2082 if (module_sp)
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002083 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00002084 ObjectFile *objfile = module_sp->GetObjectFile();
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002085 if (objfile)
2086 {
2087 SectionList *section_list = objfile->GetSectionList();
2088 if (section_list)
2089 {
2090 const size_t num_sections = section_list->GetSize();
2091 for (size_t sect_idx = 0; sect_idx < num_sections; ++sect_idx)
2092 {
2093 SectionSP section_sp (section_list->GetSectionAtIndex(sect_idx));
2094 if (section_sp)
Greg Clayton0416bdf2012-01-30 09:04:36 +00002095 target_sp->GetSectionLoadList().SetSectionLoadAddress (section_sp.get(), section_sp->GetFileAddress() + slide_offset);
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002096 }
2097 }
2098 else
2099 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00002100 module_sp->GetFileSpec().GetPath (path, sizeof(path));
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002101 sb_error.SetErrorStringWithFormat ("no sections in object file '%s'", path);
2102 }
2103 }
2104 else
2105 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00002106 module_sp->GetFileSpec().GetPath (path, sizeof(path));
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002107 sb_error.SetErrorStringWithFormat ("no object file for module '%s'", path);
2108 }
2109 }
Greg Clayton0416bdf2012-01-30 09:04:36 +00002110 else
2111 {
2112 sb_error.SetErrorStringWithFormat ("invalid module");
2113 }
2114
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002115 }
2116 else
2117 {
2118 sb_error.SetErrorStringWithFormat ("invalid target");
2119 }
2120 return sb_error;
2121}
2122
2123SBError
2124SBTarget::ClearModuleLoadAddress (lldb::SBModule module)
2125{
2126 SBError sb_error;
2127
2128 char path[PATH_MAX];
Greg Clayton0416bdf2012-01-30 09:04:36 +00002129 TargetSP target_sp(GetSP());
2130 if (target_sp)
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002131 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00002132 ModuleSP module_sp (module.GetSP());
2133 if (module_sp)
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002134 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00002135 ObjectFile *objfile = module_sp->GetObjectFile();
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002136 if (objfile)
2137 {
2138 SectionList *section_list = objfile->GetSectionList();
2139 if (section_list)
2140 {
2141 const size_t num_sections = section_list->GetSize();
2142 for (size_t sect_idx = 0; sect_idx < num_sections; ++sect_idx)
2143 {
2144 SectionSP section_sp (section_list->GetSectionAtIndex(sect_idx));
2145 if (section_sp)
Greg Clayton0416bdf2012-01-30 09:04:36 +00002146 target_sp->GetSectionLoadList().SetSectionUnloaded (section_sp.get());
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002147 }
2148 }
2149 else
2150 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00002151 module_sp->GetFileSpec().GetPath (path, sizeof(path));
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002152 sb_error.SetErrorStringWithFormat ("no sections in object file '%s'", path);
2153 }
2154 }
2155 else
2156 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00002157 module_sp->GetFileSpec().GetPath (path, sizeof(path));
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002158 sb_error.SetErrorStringWithFormat ("no object file for module '%s'", path);
2159 }
2160 }
Greg Clayton0416bdf2012-01-30 09:04:36 +00002161 else
2162 {
2163 sb_error.SetErrorStringWithFormat ("invalid module");
2164 }
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002165 }
2166 else
2167 {
2168 sb_error.SetErrorStringWithFormat ("invalid target");
2169 }
2170 return sb_error;
2171}
2172
2173