blob: 1dc30d1debca235797cfdebcf38c394ff273ca59 [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
Greg Clayton66c2e192012-03-07 23:52:51 +000066SBLaunchInfo::~SBLaunchInfo()
67{
68}
69
70lldb_private::ProcessLaunchInfo &
71SBLaunchInfo::ref ()
72{
73 return *m_opaque_sp;
74}
75
76
Greg Clayton0a8dcac2012-02-24 05:03:03 +000077uint32_t
78SBLaunchInfo::GetUserID()
79{
80 return m_opaque_sp->GetUserID();
81}
82
83uint32_t
84SBLaunchInfo::GetGroupID()
85{
86 return m_opaque_sp->GetGroupID();
87}
88
89bool
90SBLaunchInfo::UserIDIsValid ()
91{
92 return m_opaque_sp->UserIDIsValid();
93}
94
95bool
96SBLaunchInfo::GroupIDIsValid ()
97{
98 return m_opaque_sp->GroupIDIsValid();
99}
100
101void
102SBLaunchInfo::SetUserID (uint32_t uid)
103{
104 m_opaque_sp->SetUserID (uid);
105}
106
107void
108SBLaunchInfo::SetGroupID (uint32_t gid)
109{
110 m_opaque_sp->SetGroupID (gid);
111}
112
Greg Clayton0a8dcac2012-02-24 05:03:03 +0000113uint32_t
114SBLaunchInfo::GetNumArguments ()
115{
116 return m_opaque_sp->GetArguments().GetArgumentCount();
117}
118
119const char *
120SBLaunchInfo::GetArgumentAtIndex (uint32_t idx)
121{
122 return m_opaque_sp->GetArguments().GetArgumentAtIndex(idx);
123}
124
125void
126SBLaunchInfo::SetArguments (const char **argv, bool append)
127{
128 if (append)
129 {
130 if (argv)
131 m_opaque_sp->GetArguments().AppendArguments(argv);
132 }
133 else
134 {
135 if (argv)
136 m_opaque_sp->GetArguments().SetArguments(argv);
137 else
138 m_opaque_sp->GetArguments().Clear();
139 }
140}
141
142uint32_t
143SBLaunchInfo::GetNumEnvironmentEntries ()
144{
145 return m_opaque_sp->GetEnvironmentEntries().GetArgumentCount();
146}
147
148const char *
149SBLaunchInfo::GetEnvironmentEntryAtIndex (uint32_t idx)
150{
151 return m_opaque_sp->GetEnvironmentEntries().GetArgumentAtIndex(idx);
152}
153
154void
155SBLaunchInfo::SetEnvironmentEntries (const char **envp, bool append)
156{
157 if (append)
158 {
159 if (envp)
160 m_opaque_sp->GetEnvironmentEntries().AppendArguments(envp);
161 }
162 else
163 {
164 if (envp)
165 m_opaque_sp->GetEnvironmentEntries().SetArguments(envp);
166 else
167 m_opaque_sp->GetEnvironmentEntries().Clear();
168 }
169}
170
171void
172SBLaunchInfo::Clear ()
173{
174 m_opaque_sp->Clear();
175}
176
177const char *
178SBLaunchInfo::GetWorkingDirectory () const
179{
180 return m_opaque_sp->GetWorkingDirectory();
181}
182
183void
184SBLaunchInfo::SetWorkingDirectory (const char *working_dir)
185{
186 m_opaque_sp->SetWorkingDirectory(working_dir);
187}
188
189uint32_t
190SBLaunchInfo::GetLaunchFlags ()
191{
192 return m_opaque_sp->GetFlags().Get();
193}
194
195void
196SBLaunchInfo::SetLaunchFlags (uint32_t flags)
197{
198 m_opaque_sp->GetFlags().Reset(flags);
199}
200
201const char *
202SBLaunchInfo::GetProcessPluginName ()
203{
204 return m_opaque_sp->GetProcessPluginName();
205}
206
207void
208SBLaunchInfo::SetProcessPluginName (const char *plugin_name)
209{
210 return m_opaque_sp->SetProcessPluginName (plugin_name);
211}
212
213const char *
214SBLaunchInfo::GetShell ()
215{
216 return m_opaque_sp->GetShell();
217}
218
219void
220SBLaunchInfo::SetShell (const char * path)
221{
222 m_opaque_sp->SetShell (path);
223}
224
225uint32_t
226SBLaunchInfo::GetResumeCount ()
227{
228 return m_opaque_sp->GetResumeCount();
229}
230
231void
232SBLaunchInfo::SetResumeCount (uint32_t c)
233{
234 m_opaque_sp->SetResumeCount (c);
235}
236
237bool
238SBLaunchInfo::AddCloseFileAction (int fd)
239{
240 return m_opaque_sp->AppendCloseFileAction(fd);
241}
242
243bool
244SBLaunchInfo::AddDuplicateFileAction (int fd, int dup_fd)
245{
246 return m_opaque_sp->AppendDuplicateFileAction(fd, dup_fd);
247}
248
249bool
250SBLaunchInfo::AddOpenFileAction (int fd, const char *path, bool read, bool write)
251{
252 return m_opaque_sp->AppendOpenFileAction(fd, path, read, write);
253}
254
255bool
256SBLaunchInfo::AddSuppressFileAction (int fd, bool read, bool write)
257{
258 return m_opaque_sp->AppendSuppressFileAction(fd, read, write);
259}
260
261
262SBAttachInfo::SBAttachInfo () :
Greg Clayton66c2e192012-03-07 23:52:51 +0000263 m_opaque_sp (new ProcessAttachInfo())
Greg Clayton0a8dcac2012-02-24 05:03:03 +0000264{
265}
266
267SBAttachInfo::SBAttachInfo (lldb::pid_t pid) :
Greg Clayton66c2e192012-03-07 23:52:51 +0000268 m_opaque_sp (new ProcessAttachInfo())
Greg Clayton0a8dcac2012-02-24 05:03:03 +0000269{
270 m_opaque_sp->SetProcessID (pid);
271}
272
273SBAttachInfo::SBAttachInfo (const char *path, bool wait_for) :
Greg Clayton66c2e192012-03-07 23:52:51 +0000274 m_opaque_sp (new ProcessAttachInfo())
Greg Clayton0a8dcac2012-02-24 05:03:03 +0000275{
276 if (path && path[0])
277 m_opaque_sp->GetExecutableFile().SetFile(path, false);
278 m_opaque_sp->SetWaitForLaunch (wait_for);
279}
280
281SBAttachInfo::SBAttachInfo (const SBAttachInfo &rhs) :
Greg Clayton66c2e192012-03-07 23:52:51 +0000282 m_opaque_sp (new ProcessAttachInfo())
Greg Clayton0a8dcac2012-02-24 05:03:03 +0000283{
284 *m_opaque_sp = *rhs.m_opaque_sp;
285}
286
Greg Clayton66c2e192012-03-07 23:52:51 +0000287SBAttachInfo::~SBAttachInfo()
288{
289}
290
291lldb_private::ProcessAttachInfo &
292SBAttachInfo::ref ()
293{
294 return *m_opaque_sp;
295}
296
Greg Clayton0a8dcac2012-02-24 05:03:03 +0000297SBAttachInfo &
298SBAttachInfo::operator = (const SBAttachInfo &rhs)
299{
300 if (this != &rhs)
301 *m_opaque_sp = *rhs.m_opaque_sp;
302 return *this;
303}
304
305lldb::pid_t
306SBAttachInfo::GetProcessID ()
307{
308 return m_opaque_sp->GetProcessID();
309}
310
311void
312SBAttachInfo::SetProcessID (lldb::pid_t pid)
313{
314 m_opaque_sp->SetProcessID (pid);
315}
316
317
318uint32_t
319SBAttachInfo::GetResumeCount ()
320{
321 return m_opaque_sp->GetResumeCount();
322}
323
324void
325SBAttachInfo::SetResumeCount (uint32_t c)
326{
327 m_opaque_sp->SetResumeCount (c);
328}
329
330const char *
331SBAttachInfo::GetProcessPluginName ()
332{
333 return m_opaque_sp->GetProcessPluginName();
334}
335
336void
337SBAttachInfo::SetProcessPluginName (const char *plugin_name)
338{
339 return m_opaque_sp->SetProcessPluginName (plugin_name);
340}
341
342void
343SBAttachInfo::SetExecutable (const char *path)
344{
345 if (path && path[0])
346 m_opaque_sp->GetExecutableFile().SetFile(path, false);
347 else
348 m_opaque_sp->GetExecutableFile().Clear();
349}
350
351void
352SBAttachInfo::SetExecutable (SBFileSpec exe_file)
353{
354 if (exe_file.IsValid())
355 m_opaque_sp->GetExecutableFile() = exe_file.ref();
356 else
357 m_opaque_sp->GetExecutableFile().Clear();
358}
359
360bool
361SBAttachInfo::GetWaitForLaunch ()
362{
363 return m_opaque_sp->GetWaitForLaunch();
364}
365
366void
367SBAttachInfo::SetWaitForLaunch (bool b)
368{
369 m_opaque_sp->SetWaitForLaunch (b);
370}
371
372uint32_t
Greg Clayton80efa5e2012-02-24 23:56:06 +0000373SBAttachInfo::GetUserID()
374{
375 return m_opaque_sp->GetUserID();
376}
377
378uint32_t
379SBAttachInfo::GetGroupID()
380{
381 return m_opaque_sp->GetGroupID();
382}
383
384bool
385SBAttachInfo::UserIDIsValid ()
386{
387 return m_opaque_sp->UserIDIsValid();
388}
389
390bool
391SBAttachInfo::GroupIDIsValid ()
392{
393 return m_opaque_sp->GroupIDIsValid();
394}
395
396void
397SBAttachInfo::SetUserID (uint32_t uid)
398{
399 m_opaque_sp->SetUserID (uid);
400}
401
402void
403SBAttachInfo::SetGroupID (uint32_t gid)
404{
405 m_opaque_sp->SetGroupID (gid);
406}
407
408uint32_t
Greg Clayton0a8dcac2012-02-24 05:03:03 +0000409SBAttachInfo::GetEffectiveUserID()
410{
411 return m_opaque_sp->GetEffectiveUserID();
412}
413
414uint32_t
415SBAttachInfo::GetEffectiveGroupID()
416{
417 return m_opaque_sp->GetEffectiveGroupID();
418}
419
420bool
421SBAttachInfo::EffectiveUserIDIsValid ()
422{
423 return m_opaque_sp->EffectiveUserIDIsValid();
424}
425
426bool
427SBAttachInfo::EffectiveGroupIDIsValid ()
428{
429 return m_opaque_sp->EffectiveGroupIDIsValid ();
430}
431
432void
433SBAttachInfo::SetEffectiveUserID (uint32_t uid)
434{
435 m_opaque_sp->SetEffectiveUserID(uid);
436}
437
438void
439SBAttachInfo::SetEffectiveGroupID (uint32_t gid)
440{
441 m_opaque_sp->SetEffectiveGroupID(gid);
442}
443
444lldb::pid_t
445SBAttachInfo::GetParentProcessID ()
446{
447 return m_opaque_sp->GetParentProcessID();
448}
449
450void
451SBAttachInfo::SetParentProcessID (lldb::pid_t pid)
452{
453 m_opaque_sp->SetParentProcessID (pid);
454}
455
456bool
457SBAttachInfo::ParentProcessIDIsValid()
458{
459 return m_opaque_sp->ParentProcessIDIsValid();
460}
461
462
Chris Lattner24943d22010-06-08 16:52:24 +0000463//----------------------------------------------------------------------
464// SBTarget constructor
465//----------------------------------------------------------------------
Greg Claytonc3b61d22010-12-15 05:08:08 +0000466SBTarget::SBTarget () :
467 m_opaque_sp ()
Chris Lattner24943d22010-06-08 16:52:24 +0000468{
469}
470
471SBTarget::SBTarget (const SBTarget& rhs) :
Greg Clayton63094e02010-06-23 01:19:29 +0000472 m_opaque_sp (rhs.m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000473{
474}
475
476SBTarget::SBTarget(const TargetSP& target_sp) :
Greg Clayton63094e02010-06-23 01:19:29 +0000477 m_opaque_sp (target_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000478{
479}
480
Greg Clayton538eb822010-11-05 23:17:00 +0000481const SBTarget&
482SBTarget::operator = (const SBTarget& rhs)
483{
484 if (this != &rhs)
485 m_opaque_sp = rhs.m_opaque_sp;
486 return *this;
487}
488
Chris Lattner24943d22010-06-08 16:52:24 +0000489//----------------------------------------------------------------------
490// Destructor
491//----------------------------------------------------------------------
492SBTarget::~SBTarget()
493{
494}
495
Jim Ingham5a15e692012-02-16 06:50:00 +0000496const char *
497SBTarget::GetBroadcasterClassName ()
498{
499 return Target::GetStaticBroadcasterClass().AsCString();
500}
501
Chris Lattner24943d22010-06-08 16:52:24 +0000502bool
503SBTarget::IsValid () const
504{
Filipe Cabecinhasf7d782b2012-05-19 09:59:08 +0000505 return m_opaque_sp.get() != NULL && m_opaque_sp->IsValid();
Chris Lattner24943d22010-06-08 16:52:24 +0000506}
507
508SBProcess
509SBTarget::GetProcess ()
510{
511 SBProcess sb_process;
Greg Clayton334d33a2012-01-30 07:41:31 +0000512 ProcessSP process_sp;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000513 TargetSP target_sp(GetSP());
514 if (target_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000515 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000516 process_sp = target_sp->GetProcessSP();
Greg Clayton334d33a2012-01-30 07:41:31 +0000517 sb_process.SetSP (process_sp);
Greg Claytonbdcda462010-12-20 20:49:23 +0000518 }
Caroline Tice7826c882010-10-26 03:11:13 +0000519
Greg Claytone005f2c2010-11-06 01:53:30 +0000520 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000521 if (log)
522 {
Greg Clayton49ce6822010-10-31 03:01:06 +0000523 log->Printf ("SBTarget(%p)::GetProcess () => SBProcess(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +0000524 target_sp.get(), process_sp.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000525 }
526
Chris Lattner24943d22010-06-08 16:52:24 +0000527 return sb_process;
528}
529
Greg Clayton63094e02010-06-23 01:19:29 +0000530SBDebugger
531SBTarget::GetDebugger () const
532{
533 SBDebugger debugger;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000534 TargetSP target_sp(GetSP());
535 if (target_sp)
536 debugger.reset (target_sp->GetDebugger().shared_from_this());
Greg Clayton63094e02010-06-23 01:19:29 +0000537 return debugger;
538}
539
Jim Inghamb5871fe2011-03-31 00:01:24 +0000540SBProcess
541SBTarget::LaunchSimple
542(
543 char const **argv,
544 char const **envp,
545 const char *working_directory
546)
547{
548 char *stdin_path = NULL;
549 char *stdout_path = NULL;
550 char *stderr_path = NULL;
551 uint32_t launch_flags = 0;
552 bool stop_at_entry = false;
553 SBError error;
554 SBListener listener = GetDebugger().GetListener();
555 return Launch (listener,
556 argv,
557 envp,
558 stdin_path,
559 stdout_path,
560 stderr_path,
561 working_directory,
562 launch_flags,
563 stop_at_entry,
564 error);
565}
Greg Claytonde915be2011-01-23 05:56:20 +0000566
567SBProcess
568SBTarget::Launch
569(
Greg Clayton271a5db2011-02-03 21:28:34 +0000570 SBListener &listener,
Greg Claytonde915be2011-01-23 05:56:20 +0000571 char const **argv,
572 char const **envp,
573 const char *stdin_path,
574 const char *stdout_path,
575 const char *stderr_path,
576 const char *working_directory,
577 uint32_t launch_flags, // See LaunchFlags
578 bool stop_at_entry,
579 lldb::SBError& error
580)
581{
Greg Claytone005f2c2010-11-06 01:53:30 +0000582 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000583
Greg Clayton0416bdf2012-01-30 09:04:36 +0000584 SBProcess sb_process;
585 ProcessSP process_sp;
586 TargetSP target_sp(GetSP());
587
Caroline Tice7826c882010-10-26 03:11:13 +0000588 if (log)
Greg Clayton3f5ee7f2010-10-29 04:59:35 +0000589 {
Greg Claytonde915be2011-01-23 05:56:20 +0000590 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 +0000591 target_sp.get(),
Greg Claytonde915be2011-01-23 05:56:20 +0000592 argv,
593 envp,
594 stdin_path ? stdin_path : "NULL",
595 stdout_path ? stdout_path : "NULL",
596 stderr_path ? stderr_path : "NULL",
597 working_directory ? working_directory : "NULL",
598 launch_flags,
599 stop_at_entry,
600 error.get());
Greg Clayton3f5ee7f2010-10-29 04:59:35 +0000601 }
Greg Clayton0416bdf2012-01-30 09:04:36 +0000602
603 if (target_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000604 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000605 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton1a3083a2010-10-06 03:53:16 +0000606
Greg Clayton7c330d62011-01-27 01:01:10 +0000607 if (getenv("LLDB_LAUNCH_FLAG_DISABLE_ASLR"))
608 launch_flags |= eLaunchFlagDisableASLR;
609
Greg Clayton180546b2011-04-30 01:09:13 +0000610 StateType state = eStateInvalid;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000611 process_sp = target_sp->GetProcessSP();
Greg Clayton334d33a2012-01-30 07:41:31 +0000612 if (process_sp)
Greg Clayton28d5fcc2011-01-27 06:44:37 +0000613 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000614 state = process_sp->GetState();
Greg Clayton180546b2011-04-30 01:09:13 +0000615
Greg Clayton334d33a2012-01-30 07:41:31 +0000616 if (process_sp->IsAlive() && state != eStateConnected)
Greg Clayton180546b2011-04-30 01:09:13 +0000617 {
618 if (state == eStateAttaching)
619 error.SetErrorString ("process attach is in progress");
620 else
621 error.SetErrorString ("a process is already being debugged");
Greg Clayton180546b2011-04-30 01:09:13 +0000622 return sb_process;
623 }
Greg Clayton28d5fcc2011-01-27 06:44:37 +0000624 }
625
Greg Clayton180546b2011-04-30 01:09:13 +0000626 if (state == eStateConnected)
627 {
628 // If we are already connected, then we have already specified the
629 // listener, so if a valid listener is supplied, we need to error out
630 // to let the client know.
631 if (listener.IsValid())
632 {
633 error.SetErrorString ("process is connected and already has a listener, pass empty listener");
Greg Clayton180546b2011-04-30 01:09:13 +0000634 return sb_process;
635 }
636 }
637 else
Greg Claytonc5f728c2010-10-06 22:10:17 +0000638 {
Greg Clayton271a5db2011-02-03 21:28:34 +0000639 if (listener.IsValid())
Greg Clayton46c9a352012-02-09 06:16:32 +0000640 process_sp = target_sp->CreateProcess (listener.ref(), NULL, NULL);
Greg Clayton271a5db2011-02-03 21:28:34 +0000641 else
Greg Clayton46c9a352012-02-09 06:16:32 +0000642 process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener(), NULL, NULL);
Greg Clayton180546b2011-04-30 01:09:13 +0000643 }
Greg Clayton7c330d62011-01-27 01:01:10 +0000644
Greg Clayton334d33a2012-01-30 07:41:31 +0000645 if (process_sp)
Greg Clayton180546b2011-04-30 01:09:13 +0000646 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000647 sb_process.SetSP (process_sp);
Greg Clayton180546b2011-04-30 01:09:13 +0000648 if (getenv("LLDB_LAUNCH_FLAG_DISABLE_STDIO"))
649 launch_flags |= eLaunchFlagDisableSTDIO;
650
Greg Clayton36bc5ea2011-11-03 21:22:33 +0000651 ProcessLaunchInfo launch_info (stdin_path, stdout_path, stderr_path, working_directory, launch_flags);
652
Greg Clayton0416bdf2012-01-30 09:04:36 +0000653 Module *exe_module = target_sp->GetExecutableModulePointer();
Greg Clayton36bc5ea2011-11-03 21:22:33 +0000654 if (exe_module)
Greg Clayton1d1f39e2011-11-29 04:03:30 +0000655 launch_info.SetExecutableFile(exe_module->GetPlatformFileSpec(), true);
Greg Clayton36bc5ea2011-11-03 21:22:33 +0000656 if (argv)
657 launch_info.GetArguments().AppendArguments (argv);
658 if (envp)
659 launch_info.GetEnvironmentEntries ().SetArguments (envp);
660
Greg Clayton334d33a2012-01-30 07:41:31 +0000661 error.SetError (process_sp->Launch (launch_info));
Greg Clayton180546b2011-04-30 01:09:13 +0000662 if (error.Success())
Greg Clayton7c330d62011-01-27 01:01:10 +0000663 {
Greg Clayton180546b2011-04-30 01:09:13 +0000664 // We we are stopping at the entry point, we can return now!
665 if (stop_at_entry)
666 return sb_process;
Greg Clayton7c330d62011-01-27 01:01:10 +0000667
Greg Clayton180546b2011-04-30 01:09:13 +0000668 // Make sure we are stopped at the entry
Greg Clayton334d33a2012-01-30 07:41:31 +0000669 StateType state = process_sp->WaitForProcessToStop (NULL);
Greg Clayton180546b2011-04-30 01:09:13 +0000670 if (state == eStateStopped)
Greg Clayton7c330d62011-01-27 01:01:10 +0000671 {
Greg Clayton180546b2011-04-30 01:09:13 +0000672 // resume the process to skip the entry point
Greg Clayton334d33a2012-01-30 07:41:31 +0000673 error.SetError (process_sp->Resume());
Greg Clayton180546b2011-04-30 01:09:13 +0000674 if (error.Success())
Greg Clayton7c330d62011-01-27 01:01:10 +0000675 {
Greg Clayton180546b2011-04-30 01:09:13 +0000676 // If we are doing synchronous mode, then wait for the
677 // process to stop yet again!
Greg Clayton0416bdf2012-01-30 09:04:36 +0000678 if (target_sp->GetDebugger().GetAsyncExecution () == false)
Greg Clayton334d33a2012-01-30 07:41:31 +0000679 process_sp->WaitForProcessToStop (NULL);
Greg Clayton7c330d62011-01-27 01:01:10 +0000680 }
681 }
682 }
Greg Clayton180546b2011-04-30 01:09:13 +0000683 }
684 else
685 {
686 error.SetErrorString ("unable to create lldb_private::Process");
Greg Claytonc5f728c2010-10-06 22:10:17 +0000687 }
688 }
689 else
690 {
691 error.SetErrorString ("SBTarget is invalid");
Chris Lattner24943d22010-06-08 16:52:24 +0000692 }
Caroline Tice7826c882010-10-26 03:11:13 +0000693
Caroline Tice926060e2010-10-29 21:48:37 +0000694 log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
Caroline Tice7826c882010-10-26 03:11:13 +0000695 if (log)
696 {
Greg Clayton49ce6822010-10-31 03:01:06 +0000697 log->Printf ("SBTarget(%p)::Launch (...) => SBProceess(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +0000698 target_sp.get(), process_sp.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000699 }
700
Greg Clayton1a3083a2010-10-06 03:53:16 +0000701 return sb_process;
Chris Lattner24943d22010-06-08 16:52:24 +0000702}
703
Greg Clayton0a8dcac2012-02-24 05:03:03 +0000704SBProcess
705SBTarget::Launch (SBLaunchInfo &sb_launch_info, SBError& error)
706{
707 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
708
709 SBProcess sb_process;
710 ProcessSP process_sp;
711 TargetSP target_sp(GetSP());
712
713 if (log)
714 {
715 log->Printf ("SBTarget(%p)::Launch (launch_info, error)...", target_sp.get());
716 }
717
718 if (target_sp)
719 {
720 Mutex::Locker api_locker (target_sp->GetAPIMutex());
721 StateType state = eStateInvalid;
722 process_sp = target_sp->GetProcessSP();
723 if (process_sp)
724 {
725 state = process_sp->GetState();
726
727 if (process_sp->IsAlive() && state != eStateConnected)
728 {
729 if (state == eStateAttaching)
730 error.SetErrorString ("process attach is in progress");
731 else
732 error.SetErrorString ("a process is already being debugged");
733 return sb_process;
734 }
735 }
736
737 if (state != eStateConnected)
738 process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener(), NULL, NULL);
739
740 if (process_sp)
741 {
742 sb_process.SetSP (process_sp);
743 lldb_private::ProcessLaunchInfo &launch_info = sb_launch_info.ref();
Greg Clayton98ca1e62012-02-24 20:59:25 +0000744
Greg Clayton98ca1e62012-02-24 20:59:25 +0000745 Module *exe_module = target_sp->GetExecutableModulePointer();
746 if (exe_module)
Han Ming Ongc86723f2012-03-02 01:02:04 +0000747 launch_info.SetExecutableFile(exe_module->GetPlatformFileSpec(), true);
Greg Clayton98ca1e62012-02-24 20:59:25 +0000748
749 const ArchSpec &arch_spec = target_sp->GetArchitecture();
750 if (arch_spec.IsValid())
751 launch_info.GetArchitecture () = arch_spec;
752
Greg Clayton0a8dcac2012-02-24 05:03:03 +0000753 error.SetError (process_sp->Launch (launch_info));
Greg Clayton98ca1e62012-02-24 20:59:25 +0000754 const bool synchronous_execution = target_sp->GetDebugger().GetAsyncExecution () == false;
Greg Clayton0a8dcac2012-02-24 05:03:03 +0000755 if (error.Success())
756 {
Greg Clayton0a8dcac2012-02-24 05:03:03 +0000757 if (launch_info.GetFlags().Test(eLaunchFlagStopAtEntry))
Greg Clayton98ca1e62012-02-24 20:59:25 +0000758 {
759 // If we are doing synchronous mode, then wait for the initial
760 // stop to happen, else, return and let the caller watch for
761 // the stop
762 if (synchronous_execution)
Greg Clayton4a379b12012-07-17 03:23:13 +0000763 process_sp->WaitForProcessToStop (NULL);
Greg Clayton98ca1e62012-02-24 20:59:25 +0000764 // We we are stopping at the entry point, we can return now!
Greg Clayton0a8dcac2012-02-24 05:03:03 +0000765 return sb_process;
Greg Clayton98ca1e62012-02-24 20:59:25 +0000766 }
Greg Clayton0a8dcac2012-02-24 05:03:03 +0000767
768 // Make sure we are stopped at the entry
Greg Clayton4a379b12012-07-17 03:23:13 +0000769 StateType state = process_sp->WaitForProcessToStop (NULL);
Greg Clayton0a8dcac2012-02-24 05:03:03 +0000770 if (state == eStateStopped)
771 {
772 // resume the process to skip the entry point
773 error.SetError (process_sp->Resume());
774 if (error.Success())
775 {
776 // If we are doing synchronous mode, then wait for the
777 // process to stop yet again!
Greg Clayton98ca1e62012-02-24 20:59:25 +0000778 if (synchronous_execution)
Greg Clayton0a8dcac2012-02-24 05:03:03 +0000779 process_sp->WaitForProcessToStop (NULL);
780 }
781 }
782 }
783 }
784 else
785 {
786 error.SetErrorString ("unable to create lldb_private::Process");
787 }
788 }
789 else
790 {
791 error.SetErrorString ("SBTarget is invalid");
792 }
793
794 log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
795 if (log)
796 {
797 log->Printf ("SBTarget(%p)::Launch (...) => SBProceess(%p)",
798 target_sp.get(), process_sp.get());
799 }
800
801 return sb_process;
802}
803
804lldb::SBProcess
805SBTarget::Attach (SBAttachInfo &sb_attach_info, SBError& error)
806{
807 SBProcess sb_process;
808 ProcessSP process_sp;
809 TargetSP target_sp(GetSP());
810 if (target_sp)
811 {
812 Mutex::Locker api_locker (target_sp->GetAPIMutex());
813
814 StateType state = eStateInvalid;
815 process_sp = target_sp->GetProcessSP();
816 if (process_sp)
817 {
818 state = process_sp->GetState();
819
820 if (process_sp->IsAlive() && state != eStateConnected)
821 {
822 if (state == eStateAttaching)
823 error.SetErrorString ("process attach is in progress");
824 else
825 error.SetErrorString ("a process is already being debugged");
826 return sb_process;
827 }
828 }
829
830 if (state != eStateConnected)
831 process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener(), NULL, NULL);
832
833 if (process_sp)
834 {
Greg Clayton0a8dcac2012-02-24 05:03:03 +0000835 ProcessAttachInfo &attach_info = sb_attach_info.ref();
Han Ming Ong435c5ef2012-02-29 00:12:56 +0000836 lldb::pid_t attach_pid = attach_info.GetProcessID();
837 if (attach_pid != LLDB_INVALID_PROCESS_ID)
838 {
839 PlatformSP platform_sp = target_sp->GetPlatform();
840 ProcessInstanceInfo instance_info;
841 if (platform_sp->GetProcessInfo(attach_pid, instance_info))
842 {
843 attach_info.SetUserID(instance_info.GetEffectiveUserID());
844 }
845 }
Han Ming Ong94b4e9a2012-02-29 19:16:40 +0000846 error.SetError (process_sp->Attach (attach_info));
847 if (error.Success())
848 {
849 sb_process.SetSP (process_sp);
850 // If we are doing synchronous mode, then wait for the
851 // process to stop!
852 if (target_sp->GetDebugger().GetAsyncExecution () == false)
853 process_sp->WaitForProcessToStop (NULL);
854 }
Greg Clayton0a8dcac2012-02-24 05:03:03 +0000855 }
856 else
857 {
858 error.SetErrorString ("unable to create lldb_private::Process");
859 }
860 }
861 else
862 {
863 error.SetErrorString ("SBTarget is invalid");
864 }
865 return sb_process;
866}
867
868
Greg Claytond5b0b442011-12-02 02:10:57 +0000869#if defined(__APPLE__)
870
871lldb::SBProcess
872SBTarget::AttachToProcessWithID (SBListener &listener,
873 ::pid_t pid,
874 lldb::SBError& error)
875{
876 return AttachToProcessWithID (listener, (lldb::pid_t)pid, error);
877}
878
879#endif // #if defined(__APPLE__)
Greg Claytonc5f728c2010-10-06 22:10:17 +0000880
881lldb::SBProcess
Greg Claytond8c62532010-10-07 04:19:01 +0000882SBTarget::AttachToProcessWithID
Greg Claytonc5f728c2010-10-06 22:10:17 +0000883(
Greg Clayton271a5db2011-02-03 21:28:34 +0000884 SBListener &listener,
Greg Claytonc5f728c2010-10-06 22:10:17 +0000885 lldb::pid_t pid,// The process ID to attach to
886 SBError& error // An error explaining what went wrong if attach fails
887)
888{
889 SBProcess sb_process;
Greg Clayton334d33a2012-01-30 07:41:31 +0000890 ProcessSP process_sp;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000891 TargetSP target_sp(GetSP());
892 if (target_sp)
Greg Claytonc5f728c2010-10-06 22:10:17 +0000893 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000894 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytonde1dd812011-06-24 03:21:43 +0000895
896 StateType state = eStateInvalid;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000897 process_sp = target_sp->GetProcessSP();
Greg Clayton334d33a2012-01-30 07:41:31 +0000898 if (process_sp)
Greg Claytonde1dd812011-06-24 03:21:43 +0000899 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000900 state = process_sp->GetState();
Greg Claytonde1dd812011-06-24 03:21:43 +0000901
Greg Clayton334d33a2012-01-30 07:41:31 +0000902 if (process_sp->IsAlive() && state != eStateConnected)
Greg Claytonde1dd812011-06-24 03:21:43 +0000903 {
904 if (state == eStateAttaching)
905 error.SetErrorString ("process attach is in progress");
906 else
907 error.SetErrorString ("a process is already being debugged");
Greg Claytonde1dd812011-06-24 03:21:43 +0000908 return sb_process;
909 }
910 }
911
912 if (state == eStateConnected)
913 {
914 // If we are already connected, then we have already specified the
915 // listener, so if a valid listener is supplied, we need to error out
916 // to let the client know.
917 if (listener.IsValid())
918 {
919 error.SetErrorString ("process is connected and already has a listener, pass empty listener");
Greg Claytonde1dd812011-06-24 03:21:43 +0000920 return sb_process;
921 }
922 }
Greg Clayton271a5db2011-02-03 21:28:34 +0000923 else
Greg Claytonde1dd812011-06-24 03:21:43 +0000924 {
925 if (listener.IsValid())
Greg Clayton46c9a352012-02-09 06:16:32 +0000926 process_sp = target_sp->CreateProcess (listener.ref(), NULL, NULL);
Greg Claytonde1dd812011-06-24 03:21:43 +0000927 else
Greg Clayton46c9a352012-02-09 06:16:32 +0000928 process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener(), NULL, NULL);
Greg Claytonde1dd812011-06-24 03:21:43 +0000929 }
Greg Clayton334d33a2012-01-30 07:41:31 +0000930 if (process_sp)
Greg Claytonc5f728c2010-10-06 22:10:17 +0000931 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000932 sb_process.SetSP (process_sp);
933
Greg Clayton527154d2011-11-15 03:53:30 +0000934 ProcessAttachInfo attach_info;
935 attach_info.SetProcessID (pid);
Han Ming Ongd1040dd2012-02-25 01:07:38 +0000936
937 PlatformSP platform_sp = target_sp->GetPlatform();
938 ProcessInstanceInfo instance_info;
939 if (platform_sp->GetProcessInfo(pid, instance_info))
940 {
941 attach_info.SetUserID(instance_info.GetEffectiveUserID());
Han Ming Ongd1040dd2012-02-25 01:07:38 +0000942 }
Greg Clayton334d33a2012-01-30 07:41:31 +0000943 error.SetError (process_sp->Attach (attach_info));
Johnny Chen535960e2011-06-17 00:51:15 +0000944 // If we are doing synchronous mode, then wait for the
945 // process to stop!
Greg Clayton0416bdf2012-01-30 09:04:36 +0000946 if (target_sp->GetDebugger().GetAsyncExecution () == false)
Greg Clayton334d33a2012-01-30 07:41:31 +0000947 process_sp->WaitForProcessToStop (NULL);
Greg Claytonc5f728c2010-10-06 22:10:17 +0000948 }
949 else
950 {
951 error.SetErrorString ("unable to create lldb_private::Process");
952 }
953 }
954 else
955 {
956 error.SetErrorString ("SBTarget is invalid");
957 }
958 return sb_process;
959
960}
961
962lldb::SBProcess
Greg Claytond8c62532010-10-07 04:19:01 +0000963SBTarget::AttachToProcessWithName
Greg Claytonc5f728c2010-10-06 22:10:17 +0000964(
Greg Clayton271a5db2011-02-03 21:28:34 +0000965 SBListener &listener,
Greg Claytonc5f728c2010-10-06 22:10:17 +0000966 const char *name, // basename of process to attach to
967 bool wait_for, // if true wait for a new instance of "name" to be launched
968 SBError& error // An error explaining what went wrong if attach fails
969)
970{
971 SBProcess sb_process;
Greg Clayton334d33a2012-01-30 07:41:31 +0000972 ProcessSP process_sp;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000973 TargetSP target_sp(GetSP());
974 if (name && target_sp)
Greg Claytonc5f728c2010-10-06 22:10:17 +0000975 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000976 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytonbdcda462010-12-20 20:49:23 +0000977
Greg Claytonde1dd812011-06-24 03:21:43 +0000978 StateType state = eStateInvalid;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000979 process_sp = target_sp->GetProcessSP();
Greg Clayton334d33a2012-01-30 07:41:31 +0000980 if (process_sp)
Greg Claytonde1dd812011-06-24 03:21:43 +0000981 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000982 state = process_sp->GetState();
Greg Claytonde1dd812011-06-24 03:21:43 +0000983
Greg Clayton334d33a2012-01-30 07:41:31 +0000984 if (process_sp->IsAlive() && state != eStateConnected)
Greg Claytonde1dd812011-06-24 03:21:43 +0000985 {
986 if (state == eStateAttaching)
987 error.SetErrorString ("process attach is in progress");
988 else
989 error.SetErrorString ("a process is already being debugged");
Greg Claytonde1dd812011-06-24 03:21:43 +0000990 return sb_process;
991 }
992 }
993
994 if (state == eStateConnected)
995 {
996 // If we are already connected, then we have already specified the
997 // listener, so if a valid listener is supplied, we need to error out
998 // to let the client know.
999 if (listener.IsValid())
1000 {
1001 error.SetErrorString ("process is connected and already has a listener, pass empty listener");
Greg Claytonde1dd812011-06-24 03:21:43 +00001002 return sb_process;
1003 }
1004 }
Greg Clayton271a5db2011-02-03 21:28:34 +00001005 else
Greg Claytonde1dd812011-06-24 03:21:43 +00001006 {
1007 if (listener.IsValid())
Greg Clayton46c9a352012-02-09 06:16:32 +00001008 process_sp = target_sp->CreateProcess (listener.ref(), NULL, NULL);
Greg Claytonde1dd812011-06-24 03:21:43 +00001009 else
Greg Clayton46c9a352012-02-09 06:16:32 +00001010 process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener(), NULL, NULL);
Greg Claytonde1dd812011-06-24 03:21:43 +00001011 }
Greg Claytonc5f728c2010-10-06 22:10:17 +00001012
Greg Clayton334d33a2012-01-30 07:41:31 +00001013 if (process_sp)
Greg Claytonc5f728c2010-10-06 22:10:17 +00001014 {
Greg Clayton334d33a2012-01-30 07:41:31 +00001015 sb_process.SetSP (process_sp);
Greg Clayton527154d2011-11-15 03:53:30 +00001016 ProcessAttachInfo attach_info;
1017 attach_info.GetExecutableFile().SetFile(name, false);
1018 attach_info.SetWaitForLaunch(wait_for);
Greg Clayton334d33a2012-01-30 07:41:31 +00001019 error.SetError (process_sp->Attach (attach_info));
Johnny Chen58d02ff2011-06-17 19:21:30 +00001020 // If we are doing synchronous mode, then wait for the
1021 // process to stop!
Greg Clayton0416bdf2012-01-30 09:04:36 +00001022 if (target_sp->GetDebugger().GetAsyncExecution () == false)
Greg Clayton334d33a2012-01-30 07:41:31 +00001023 process_sp->WaitForProcessToStop (NULL);
Greg Claytonc5f728c2010-10-06 22:10:17 +00001024 }
1025 else
1026 {
1027 error.SetErrorString ("unable to create lldb_private::Process");
1028 }
1029 }
1030 else
1031 {
1032 error.SetErrorString ("SBTarget is invalid");
1033 }
1034 return sb_process;
1035
1036}
1037
James McIlree38093402011-03-04 00:31:13 +00001038lldb::SBProcess
1039SBTarget::ConnectRemote
1040(
1041 SBListener &listener,
1042 const char *url,
1043 const char *plugin_name,
1044 SBError& error
1045)
1046{
1047 SBProcess sb_process;
Greg Clayton334d33a2012-01-30 07:41:31 +00001048 ProcessSP process_sp;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001049 TargetSP target_sp(GetSP());
1050 if (target_sp)
James McIlree38093402011-03-04 00:31:13 +00001051 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001052 Mutex::Locker api_locker (target_sp->GetAPIMutex());
James McIlree38093402011-03-04 00:31:13 +00001053 if (listener.IsValid())
Greg Clayton46c9a352012-02-09 06:16:32 +00001054 process_sp = target_sp->CreateProcess (listener.ref(), plugin_name, NULL);
James McIlree38093402011-03-04 00:31:13 +00001055 else
Greg Clayton46c9a352012-02-09 06:16:32 +00001056 process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener(), plugin_name, NULL);
James McIlree38093402011-03-04 00:31:13 +00001057
1058
Greg Clayton334d33a2012-01-30 07:41:31 +00001059 if (process_sp)
James McIlree38093402011-03-04 00:31:13 +00001060 {
Greg Clayton334d33a2012-01-30 07:41:31 +00001061 sb_process.SetSP (process_sp);
1062 error.SetError (process_sp->ConnectRemote (url));
James McIlree38093402011-03-04 00:31:13 +00001063 }
1064 else
1065 {
1066 error.SetErrorString ("unable to create lldb_private::Process");
1067 }
1068 }
1069 else
1070 {
1071 error.SetErrorString ("SBTarget is invalid");
1072 }
1073 return sb_process;
1074}
1075
Chris Lattner24943d22010-06-08 16:52:24 +00001076SBFileSpec
1077SBTarget::GetExecutable ()
1078{
Caroline Tice7826c882010-10-26 03:11:13 +00001079
Chris Lattner24943d22010-06-08 16:52:24 +00001080 SBFileSpec exe_file_spec;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001081 TargetSP target_sp(GetSP());
1082 if (target_sp)
Chris Lattner24943d22010-06-08 16:52:24 +00001083 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001084 Module *exe_module = target_sp->GetExecutableModulePointer();
Greg Clayton5beb99d2011-08-11 02:48:45 +00001085 if (exe_module)
1086 exe_file_spec.SetFileSpec (exe_module->GetFileSpec());
Chris Lattner24943d22010-06-08 16:52:24 +00001087 }
Caroline Tice7826c882010-10-26 03:11:13 +00001088
Greg Claytone005f2c2010-11-06 01:53:30 +00001089 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001090 if (log)
1091 {
Greg Clayton49ce6822010-10-31 03:01:06 +00001092 log->Printf ("SBTarget(%p)::GetExecutable () => SBFileSpec(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +00001093 target_sp.get(), exe_file_spec.get());
Caroline Tice7826c882010-10-26 03:11:13 +00001094 }
1095
Chris Lattner24943d22010-06-08 16:52:24 +00001096 return exe_file_spec;
1097}
1098
Chris Lattner24943d22010-06-08 16:52:24 +00001099bool
Chris Lattner24943d22010-06-08 16:52:24 +00001100SBTarget::operator == (const SBTarget &rhs) const
1101{
Greg Clayton63094e02010-06-23 01:19:29 +00001102 return m_opaque_sp.get() == rhs.m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +00001103}
1104
1105bool
1106SBTarget::operator != (const SBTarget &rhs) const
1107{
Greg Clayton63094e02010-06-23 01:19:29 +00001108 return m_opaque_sp.get() != rhs.m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +00001109}
1110
Greg Clayton334d33a2012-01-30 07:41:31 +00001111lldb::TargetSP
1112SBTarget::GetSP () const
Greg Clayton15afa9f2011-10-01 02:59:24 +00001113{
1114 return m_opaque_sp;
1115}
1116
Greg Clayton63094e02010-06-23 01:19:29 +00001117void
Greg Clayton334d33a2012-01-30 07:41:31 +00001118SBTarget::SetSP (const lldb::TargetSP& target_sp)
Greg Clayton63094e02010-06-23 01:19:29 +00001119{
1120 m_opaque_sp = target_sp;
Chris Lattner24943d22010-06-08 16:52:24 +00001121}
1122
Greg Claytona3955062011-07-22 16:46:35 +00001123lldb::SBAddress
1124SBTarget::ResolveLoadAddress (lldb::addr_t vm_addr)
Greg Claytonea49cc72010-12-12 19:25:26 +00001125{
Greg Claytona3955062011-07-22 16:46:35 +00001126 lldb::SBAddress sb_addr;
1127 Address &addr = sb_addr.ref();
Greg Clayton0416bdf2012-01-30 09:04:36 +00001128 TargetSP target_sp(GetSP());
1129 if (target_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +00001130 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001131 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1132 if (target_sp->GetSectionLoadList().ResolveLoadAddress (vm_addr, addr))
Greg Claytona3955062011-07-22 16:46:35 +00001133 return sb_addr;
Greg Claytonbdcda462010-12-20 20:49:23 +00001134 }
Greg Claytonea49cc72010-12-12 19:25:26 +00001135
Greg Claytona3955062011-07-22 16:46:35 +00001136 // We have a load address that isn't in a section, just return an address
1137 // with the offset filled in (the address) and the section set to NULL
Greg Clayton3508c382012-02-24 01:59:29 +00001138 addr.SetRawAddress(vm_addr);
Greg Claytona3955062011-07-22 16:46:35 +00001139 return sb_addr;
Greg Claytonea49cc72010-12-12 19:25:26 +00001140}
1141
Greg Claytonafb81862011-03-02 21:34:46 +00001142SBSymbolContext
1143SBTarget::ResolveSymbolContextForAddress (const SBAddress& addr, uint32_t resolve_scope)
1144{
1145 SBSymbolContext sc;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001146 if (addr.IsValid())
1147 {
1148 TargetSP target_sp(GetSP());
1149 if (target_sp)
1150 target_sp->GetImages().ResolveSymbolContextForAddress (addr.ref(), resolve_scope, sc.ref());
1151 }
Greg Claytonafb81862011-03-02 21:34:46 +00001152 return sc;
1153}
1154
1155
Chris Lattner24943d22010-06-08 16:52:24 +00001156SBBreakpoint
1157SBTarget::BreakpointCreateByLocation (const char *file, uint32_t line)
1158{
Greg Claytond6d806c2010-11-08 00:28:40 +00001159 return SBBreakpoint(BreakpointCreateByLocation (SBFileSpec (file, false), line));
Chris Lattner24943d22010-06-08 16:52:24 +00001160}
1161
1162SBBreakpoint
1163SBTarget::BreakpointCreateByLocation (const SBFileSpec &sb_file_spec, uint32_t line)
1164{
Greg Claytone005f2c2010-11-06 01:53:30 +00001165 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001166
Chris Lattner24943d22010-06-08 16:52:24 +00001167 SBBreakpoint sb_bp;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001168 TargetSP target_sp(GetSP());
1169 if (target_sp && line != 0)
Greg Claytonbdcda462010-12-20 20:49:23 +00001170 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001171 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Jim Ingham2cf5ccb2012-05-22 00:12:20 +00001172
1173 const bool check_inlines = true;
1174 const bool internal = false;
1175 const LazyBool skip_prologue = eLazyBoolCalculate;
1176 *sb_bp = target_sp->CreateBreakpoint (NULL, *sb_file_spec, line, check_inlines, skip_prologue, internal);
Greg Claytonbdcda462010-12-20 20:49:23 +00001177 }
Caroline Tice7826c882010-10-26 03:11:13 +00001178
1179 if (log)
1180 {
1181 SBStream sstr;
1182 sb_bp.GetDescription (sstr);
Greg Clayton49ce6822010-10-31 03:01:06 +00001183 char path[PATH_MAX];
1184 sb_file_spec->GetPath (path, sizeof(path));
1185 log->Printf ("SBTarget(%p)::BreakpointCreateByLocation ( %s:%u ) => SBBreakpoint(%p): %s",
Greg Clayton0416bdf2012-01-30 09:04:36 +00001186 target_sp.get(),
Greg Clayton49ce6822010-10-31 03:01:06 +00001187 path,
Greg Claytona66ba462010-10-30 04:51:46 +00001188 line,
Greg Clayton49ce6822010-10-31 03:01:06 +00001189 sb_bp.get(),
Caroline Tice7826c882010-10-26 03:11:13 +00001190 sstr.GetData());
1191 }
1192
Chris Lattner24943d22010-06-08 16:52:24 +00001193 return sb_bp;
1194}
1195
1196SBBreakpoint
1197SBTarget::BreakpointCreateByName (const char *symbol_name, const char *module_name)
1198{
Greg Claytone005f2c2010-11-06 01:53:30 +00001199 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001200
Chris Lattner24943d22010-06-08 16:52:24 +00001201 SBBreakpoint sb_bp;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001202 TargetSP target_sp(GetSP());
1203 if (target_sp.get())
Chris Lattner24943d22010-06-08 16:52:24 +00001204 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001205 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Jim Ingham2cf5ccb2012-05-22 00:12:20 +00001206
1207 const bool internal = false;
1208 const LazyBool skip_prologue = eLazyBoolCalculate;
Chris Lattner24943d22010-06-08 16:52:24 +00001209 if (module_name && module_name[0])
1210 {
Jim Ingham03c8ee52011-09-21 01:17:13 +00001211 FileSpecList module_spec_list;
1212 module_spec_list.Append (FileSpec (module_name, false));
Jim Ingham2cf5ccb2012-05-22 00:12:20 +00001213 *sb_bp = target_sp->CreateBreakpoint (&module_spec_list, NULL, symbol_name, eFunctionNameTypeAuto, skip_prologue, internal);
Chris Lattner24943d22010-06-08 16:52:24 +00001214 }
1215 else
1216 {
Jim Ingham2cf5ccb2012-05-22 00:12:20 +00001217 *sb_bp = target_sp->CreateBreakpoint (NULL, NULL, symbol_name, eFunctionNameTypeAuto, skip_prologue, internal);
Chris Lattner24943d22010-06-08 16:52:24 +00001218 }
1219 }
Caroline Tice7826c882010-10-26 03:11:13 +00001220
1221 if (log)
1222 {
Greg Clayton49ce6822010-10-31 03:01:06 +00001223 log->Printf ("SBTarget(%p)::BreakpointCreateByName (symbol=\"%s\", module=\"%s\") => SBBreakpoint(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +00001224 target_sp.get(), symbol_name, module_name, sb_bp.get());
Caroline Tice7826c882010-10-26 03:11:13 +00001225 }
1226
Chris Lattner24943d22010-06-08 16:52:24 +00001227 return sb_bp;
1228}
1229
Jim Inghamd6d47972011-09-23 00:54:11 +00001230lldb::SBBreakpoint
1231SBTarget::BreakpointCreateByName (const char *symbol_name,
1232 const SBFileSpecList &module_list,
1233 const SBFileSpecList &comp_unit_list)
1234{
Jim Ingham1fb8a2d2011-10-11 01:18:55 +00001235 uint32_t name_type_mask = eFunctionNameTypeAuto;
1236 return BreakpointCreateByName (symbol_name, name_type_mask, module_list, comp_unit_list);
1237}
1238
1239lldb::SBBreakpoint
1240SBTarget::BreakpointCreateByName (const char *symbol_name,
1241 uint32_t name_type_mask,
1242 const SBFileSpecList &module_list,
1243 const SBFileSpecList &comp_unit_list)
1244{
Jim Inghamd6d47972011-09-23 00:54:11 +00001245 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1246
1247 SBBreakpoint sb_bp;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001248 TargetSP target_sp(GetSP());
1249 if (target_sp && symbol_name && symbol_name[0])
Jim Inghamd6d47972011-09-23 00:54:11 +00001250 {
Jim Ingham2cf5ccb2012-05-22 00:12:20 +00001251 const bool internal = false;
1252 const LazyBool skip_prologue = eLazyBoolCalculate;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001253 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1254 *sb_bp = target_sp->CreateBreakpoint (module_list.get(),
Jim Inghamd6d47972011-09-23 00:54:11 +00001255 comp_unit_list.get(),
1256 symbol_name,
Jim Ingham1fb8a2d2011-10-11 01:18:55 +00001257 name_type_mask,
Jim Ingham2cf5ccb2012-05-22 00:12:20 +00001258 skip_prologue,
1259 internal);
Jim Inghamd6d47972011-09-23 00:54:11 +00001260 }
1261
1262 if (log)
1263 {
Jim Ingham1fb8a2d2011-10-11 01:18:55 +00001264 log->Printf ("SBTarget(%p)::BreakpointCreateByName (symbol=\"%s\", name_type: %d) => SBBreakpoint(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +00001265 target_sp.get(), symbol_name, name_type_mask, sb_bp.get());
Jim Inghamd6d47972011-09-23 00:54:11 +00001266 }
1267
1268 return sb_bp;
1269}
1270
Jim Ingham4722b102012-03-06 00:37:27 +00001271lldb::SBBreakpoint
1272SBTarget::BreakpointCreateByNames (const char *symbol_names[],
1273 uint32_t num_names,
1274 uint32_t name_type_mask,
1275 const SBFileSpecList &module_list,
1276 const SBFileSpecList &comp_unit_list)
1277{
1278 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1279
1280 SBBreakpoint sb_bp;
1281 TargetSP target_sp(GetSP());
1282 if (target_sp && num_names > 0)
1283 {
1284 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Jim Ingham2cf5ccb2012-05-22 00:12:20 +00001285 const bool internal = false;
1286 const LazyBool skip_prologue = eLazyBoolCalculate;
Jim Ingham4722b102012-03-06 00:37:27 +00001287 *sb_bp = target_sp->CreateBreakpoint (module_list.get(),
1288 comp_unit_list.get(),
1289 symbol_names,
1290 num_names,
1291 name_type_mask,
Jim Ingham2cf5ccb2012-05-22 00:12:20 +00001292 skip_prologue,
1293 internal);
Jim Ingham4722b102012-03-06 00:37:27 +00001294 }
1295
1296 if (log)
1297 {
1298 log->Printf ("SBTarget(%p)::BreakpointCreateByName (symbols={", target_sp.get());
1299 for (uint32_t i = 0 ; i < num_names; i++)
1300 {
1301 char sep;
1302 if (i < num_names - 1)
1303 sep = ',';
1304 else
1305 sep = '}';
1306 if (symbol_names[i] != NULL)
1307 log->Printf ("\"%s\"%c ", symbol_names[i], sep);
1308 else
1309 log->Printf ("\"<NULL>\"%c ", sep);
1310
1311 }
1312 log->Printf ("name_type: %d) => SBBreakpoint(%p)", name_type_mask, sb_bp.get());
1313 }
1314
1315 return sb_bp;
1316}
Jim Inghamd6d47972011-09-23 00:54:11 +00001317
Chris Lattner24943d22010-06-08 16:52:24 +00001318SBBreakpoint
1319SBTarget::BreakpointCreateByRegex (const char *symbol_name_regex, const char *module_name)
1320{
Greg Claytone005f2c2010-11-06 01:53:30 +00001321 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001322
Chris Lattner24943d22010-06-08 16:52:24 +00001323 SBBreakpoint sb_bp;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001324 TargetSP target_sp(GetSP());
1325 if (target_sp && symbol_name_regex && symbol_name_regex[0])
Chris Lattner24943d22010-06-08 16:52:24 +00001326 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001327 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Chris Lattner24943d22010-06-08 16:52:24 +00001328 RegularExpression regexp(symbol_name_regex);
Jim Ingham2cf5ccb2012-05-22 00:12:20 +00001329 const bool internal = false;
1330 const LazyBool skip_prologue = eLazyBoolCalculate;
Chris Lattner24943d22010-06-08 16:52:24 +00001331
1332 if (module_name && module_name[0])
1333 {
Jim Ingham03c8ee52011-09-21 01:17:13 +00001334 FileSpecList module_spec_list;
1335 module_spec_list.Append (FileSpec (module_name, false));
Chris Lattner24943d22010-06-08 16:52:24 +00001336
Jim Ingham2cf5ccb2012-05-22 00:12:20 +00001337 *sb_bp = target_sp->CreateFuncRegexBreakpoint (&module_spec_list, NULL, regexp, skip_prologue, internal);
Chris Lattner24943d22010-06-08 16:52:24 +00001338 }
1339 else
1340 {
Jim Ingham2cf5ccb2012-05-22 00:12:20 +00001341 *sb_bp = target_sp->CreateFuncRegexBreakpoint (NULL, NULL, regexp, skip_prologue, internal);
Chris Lattner24943d22010-06-08 16:52:24 +00001342 }
1343 }
Caroline Tice7826c882010-10-26 03:11:13 +00001344
1345 if (log)
1346 {
Greg Clayton49ce6822010-10-31 03:01:06 +00001347 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (symbol_regex=\"%s\", module_name=\"%s\") => SBBreakpoint(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +00001348 target_sp.get(), symbol_name_regex, module_name, sb_bp.get());
Caroline Tice7826c882010-10-26 03:11:13 +00001349 }
1350
Chris Lattner24943d22010-06-08 16:52:24 +00001351 return sb_bp;
1352}
1353
Jim Inghamd6d47972011-09-23 00:54:11 +00001354lldb::SBBreakpoint
1355SBTarget::BreakpointCreateByRegex (const char *symbol_name_regex,
1356 const SBFileSpecList &module_list,
1357 const SBFileSpecList &comp_unit_list)
1358{
1359 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Chris Lattner24943d22010-06-08 16:52:24 +00001360
Jim Inghamd6d47972011-09-23 00:54:11 +00001361 SBBreakpoint sb_bp;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001362 TargetSP target_sp(GetSP());
1363 if (target_sp && symbol_name_regex && symbol_name_regex[0])
Jim Inghamd6d47972011-09-23 00:54:11 +00001364 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001365 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Jim Inghamd6d47972011-09-23 00:54:11 +00001366 RegularExpression regexp(symbol_name_regex);
Jim Ingham2cf5ccb2012-05-22 00:12:20 +00001367 const bool internal = false;
1368 const LazyBool skip_prologue = eLazyBoolCalculate;
Jim Inghamd6d47972011-09-23 00:54:11 +00001369
Jim Ingham2cf5ccb2012-05-22 00:12:20 +00001370 *sb_bp = target_sp->CreateFuncRegexBreakpoint (module_list.get(), comp_unit_list.get(), regexp, skip_prologue, internal);
Jim Inghamd6d47972011-09-23 00:54:11 +00001371 }
1372
1373 if (log)
1374 {
1375 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (symbol_regex=\"%s\") => SBBreakpoint(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +00001376 target_sp.get(), symbol_name_regex, sb_bp.get());
Jim Inghamd6d47972011-09-23 00:54:11 +00001377 }
1378
1379 return sb_bp;
1380}
Chris Lattner24943d22010-06-08 16:52:24 +00001381
1382SBBreakpoint
1383SBTarget::BreakpointCreateByAddress (addr_t address)
1384{
Greg Claytone005f2c2010-11-06 01:53:30 +00001385 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001386
Chris Lattner24943d22010-06-08 16:52:24 +00001387 SBBreakpoint sb_bp;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001388 TargetSP target_sp(GetSP());
1389 if (target_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +00001390 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001391 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1392 *sb_bp = target_sp->CreateBreakpoint (address, false);
Greg Claytonbdcda462010-12-20 20:49:23 +00001393 }
Caroline Tice7826c882010-10-26 03:11:13 +00001394
1395 if (log)
1396 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001397 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 +00001398 }
1399
Chris Lattner24943d22010-06-08 16:52:24 +00001400 return sb_bp;
1401}
1402
Jim Ingham03c8ee52011-09-21 01:17:13 +00001403lldb::SBBreakpoint
1404SBTarget::BreakpointCreateBySourceRegex (const char *source_regex, const lldb::SBFileSpec &source_file, const char *module_name)
1405{
1406 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1407
1408 SBBreakpoint sb_bp;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001409 TargetSP target_sp(GetSP());
1410 if (target_sp && source_regex && source_regex[0])
Jim Ingham03c8ee52011-09-21 01:17:13 +00001411 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001412 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Jim Ingham03c8ee52011-09-21 01:17:13 +00001413 RegularExpression regexp(source_regex);
Jim Inghamd6d47972011-09-23 00:54:11 +00001414 FileSpecList source_file_spec_list;
1415 source_file_spec_list.Append (source_file.ref());
Jim Ingham03c8ee52011-09-21 01:17:13 +00001416
1417 if (module_name && module_name[0])
1418 {
1419 FileSpecList module_spec_list;
1420 module_spec_list.Append (FileSpec (module_name, false));
1421
Greg Clayton0416bdf2012-01-30 09:04:36 +00001422 *sb_bp = target_sp->CreateSourceRegexBreakpoint (&module_spec_list, &source_file_spec_list, regexp, false);
Jim Ingham03c8ee52011-09-21 01:17:13 +00001423 }
1424 else
1425 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001426 *sb_bp = target_sp->CreateSourceRegexBreakpoint (NULL, &source_file_spec_list, regexp, false);
Jim Ingham03c8ee52011-09-21 01:17:13 +00001427 }
1428 }
1429
1430 if (log)
1431 {
1432 char path[PATH_MAX];
1433 source_file->GetPath (path, sizeof(path));
1434 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (source_regex=\"%s\", file=\"%s\", module_name=\"%s\") => SBBreakpoint(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +00001435 target_sp.get(), source_regex, path, module_name, sb_bp.get());
Jim Ingham03c8ee52011-09-21 01:17:13 +00001436 }
1437
1438 return sb_bp;
1439}
1440
Jim Inghamd6d47972011-09-23 00:54:11 +00001441lldb::SBBreakpoint
1442SBTarget::BreakpointCreateBySourceRegex (const char *source_regex,
1443 const SBFileSpecList &module_list,
1444 const lldb::SBFileSpecList &source_file_list)
1445{
1446 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1447
1448 SBBreakpoint sb_bp;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001449 TargetSP target_sp(GetSP());
1450 if (target_sp && source_regex && source_regex[0])
Jim Inghamd6d47972011-09-23 00:54:11 +00001451 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001452 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Jim Inghamd6d47972011-09-23 00:54:11 +00001453 RegularExpression regexp(source_regex);
Greg Clayton0416bdf2012-01-30 09:04:36 +00001454 *sb_bp = target_sp->CreateSourceRegexBreakpoint (module_list.get(), source_file_list.get(), regexp, false);
Jim Inghamd6d47972011-09-23 00:54:11 +00001455 }
1456
1457 if (log)
1458 {
1459 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (source_regex=\"%s\") => SBBreakpoint(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +00001460 target_sp.get(), source_regex, sb_bp.get());
Jim Inghamd6d47972011-09-23 00:54:11 +00001461 }
1462
1463 return sb_bp;
1464}
Jim Ingham03c8ee52011-09-21 01:17:13 +00001465
Jim Ingham4722b102012-03-06 00:37:27 +00001466lldb::SBBreakpoint
1467SBTarget::BreakpointCreateForException (lldb::LanguageType language,
1468 bool catch_bp,
1469 bool throw_bp)
1470{
1471 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1472
1473 SBBreakpoint sb_bp;
1474 TargetSP target_sp(GetSP());
1475 if (target_sp)
1476 {
1477 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1478 *sb_bp = target_sp->CreateExceptionBreakpoint (language, catch_bp, throw_bp);
1479 }
1480
1481 if (log)
1482 {
1483 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (Language: %s, catch: %s throw: %s) => SBBreakpoint(%p)",
1484 target_sp.get(),
1485 LanguageRuntime::GetNameForLanguageType(language),
1486 catch_bp ? "on" : "off",
1487 throw_bp ? "on" : "off",
1488 sb_bp.get());
1489 }
1490
1491 return sb_bp;
1492}
1493
Greg Claytonc7f5d5c2010-07-23 23:33:17 +00001494uint32_t
1495SBTarget::GetNumBreakpoints () const
1496{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001497 TargetSP target_sp(GetSP());
1498 if (target_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +00001499 {
1500 // The breakpoint list is thread safe, no need to lock
Greg Clayton0416bdf2012-01-30 09:04:36 +00001501 return target_sp->GetBreakpointList().GetSize();
Greg Claytonbdcda462010-12-20 20:49:23 +00001502 }
Greg Claytonc7f5d5c2010-07-23 23:33:17 +00001503 return 0;
1504}
1505
1506SBBreakpoint
1507SBTarget::GetBreakpointAtIndex (uint32_t idx) const
1508{
1509 SBBreakpoint sb_breakpoint;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001510 TargetSP target_sp(GetSP());
1511 if (target_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +00001512 {
1513 // The breakpoint list is thread safe, no need to lock
Greg Clayton0416bdf2012-01-30 09:04:36 +00001514 *sb_breakpoint = target_sp->GetBreakpointList().GetBreakpointAtIndex(idx);
Greg Claytonbdcda462010-12-20 20:49:23 +00001515 }
Greg Claytonc7f5d5c2010-07-23 23:33:17 +00001516 return sb_breakpoint;
1517}
Chris Lattner24943d22010-06-08 16:52:24 +00001518
1519bool
1520SBTarget::BreakpointDelete (break_id_t bp_id)
1521{
Greg Claytone005f2c2010-11-06 01:53:30 +00001522 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001523
Caroline Tice7826c882010-10-26 03:11:13 +00001524 bool result = false;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001525 TargetSP target_sp(GetSP());
1526 if (target_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +00001527 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001528 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1529 result = target_sp->RemoveBreakpointByID (bp_id);
Greg Claytonbdcda462010-12-20 20:49:23 +00001530 }
Caroline Tice7826c882010-10-26 03:11:13 +00001531
1532 if (log)
1533 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001534 log->Printf ("SBTarget(%p)::BreakpointDelete (bp_id=%d) => %i", target_sp.get(), (uint32_t) bp_id, result);
Caroline Tice7826c882010-10-26 03:11:13 +00001535 }
1536
1537 return result;
Chris Lattner24943d22010-06-08 16:52:24 +00001538}
1539
Johnny Chen096c2932011-09-26 22:40:50 +00001540SBBreakpoint
1541SBTarget::FindBreakpointByID (break_id_t bp_id)
1542{
1543 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1544
1545 SBBreakpoint sb_breakpoint;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001546 TargetSP target_sp(GetSP());
1547 if (target_sp && bp_id != LLDB_INVALID_BREAK_ID)
Johnny Chen096c2932011-09-26 22:40:50 +00001548 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001549 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1550 *sb_breakpoint = target_sp->GetBreakpointByID (bp_id);
Johnny Chen096c2932011-09-26 22:40:50 +00001551 }
1552
1553 if (log)
1554 {
1555 log->Printf ("SBTarget(%p)::FindBreakpointByID (bp_id=%d) => SBBreakpoint(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +00001556 target_sp.get(), (uint32_t) bp_id, sb_breakpoint.get());
Johnny Chen096c2932011-09-26 22:40:50 +00001557 }
1558
1559 return sb_breakpoint;
1560}
1561
Chris Lattner24943d22010-06-08 16:52:24 +00001562bool
1563SBTarget::EnableAllBreakpoints ()
1564{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001565 TargetSP target_sp(GetSP());
1566 if (target_sp)
Chris Lattner24943d22010-06-08 16:52:24 +00001567 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001568 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1569 target_sp->EnableAllBreakpoints ();
Chris Lattner24943d22010-06-08 16:52:24 +00001570 return true;
1571 }
1572 return false;
1573}
1574
1575bool
1576SBTarget::DisableAllBreakpoints ()
1577{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001578 TargetSP target_sp(GetSP());
1579 if (target_sp)
Chris Lattner24943d22010-06-08 16:52:24 +00001580 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001581 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1582 target_sp->DisableAllBreakpoints ();
Chris Lattner24943d22010-06-08 16:52:24 +00001583 return true;
1584 }
1585 return false;
1586}
1587
1588bool
1589SBTarget::DeleteAllBreakpoints ()
1590{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001591 TargetSP target_sp(GetSP());
1592 if (target_sp)
Chris Lattner24943d22010-06-08 16:52:24 +00001593 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001594 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1595 target_sp->RemoveAllBreakpoints ();
Chris Lattner24943d22010-06-08 16:52:24 +00001596 return true;
1597 }
1598 return false;
1599}
1600
Johnny Chen096c2932011-09-26 22:40:50 +00001601uint32_t
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001602SBTarget::GetNumWatchpoints () const
Johnny Chen096c2932011-09-26 22:40:50 +00001603{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001604 TargetSP target_sp(GetSP());
1605 if (target_sp)
Johnny Chen096c2932011-09-26 22:40:50 +00001606 {
Johnny Chenecd4feb2011-10-14 00:42:25 +00001607 // The watchpoint list is thread safe, no need to lock
Greg Clayton0416bdf2012-01-30 09:04:36 +00001608 return target_sp->GetWatchpointList().GetSize();
Johnny Chen096c2932011-09-26 22:40:50 +00001609 }
1610 return 0;
1611}
1612
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001613SBWatchpoint
1614SBTarget::GetWatchpointAtIndex (uint32_t idx) const
Johnny Chen5eb54bb2011-09-27 20:29:45 +00001615{
Johnny Chenecd4feb2011-10-14 00:42:25 +00001616 SBWatchpoint sb_watchpoint;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001617 TargetSP target_sp(GetSP());
1618 if (target_sp)
Johnny Chen096c2932011-09-26 22:40:50 +00001619 {
Johnny Chenecd4feb2011-10-14 00:42:25 +00001620 // The watchpoint list is thread safe, no need to lock
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001621 sb_watchpoint.SetSP (target_sp->GetWatchpointList().GetByIndex(idx));
Johnny Chen096c2932011-09-26 22:40:50 +00001622 }
Johnny Chenecd4feb2011-10-14 00:42:25 +00001623 return sb_watchpoint;
Johnny Chen096c2932011-09-26 22:40:50 +00001624}
1625
1626bool
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001627SBTarget::DeleteWatchpoint (watch_id_t wp_id)
Johnny Chen096c2932011-09-26 22:40:50 +00001628{
1629 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1630
1631 bool result = false;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001632 TargetSP target_sp(GetSP());
1633 if (target_sp)
Johnny Chen096c2932011-09-26 22:40:50 +00001634 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001635 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Johnny Chenbbf6aa52012-05-31 22:56:36 +00001636 Mutex::Locker locker;
1637 target_sp->GetWatchpointList().GetListMutex(locker);
Greg Clayton0416bdf2012-01-30 09:04:36 +00001638 result = target_sp->RemoveWatchpointByID (wp_id);
Johnny Chen096c2932011-09-26 22:40:50 +00001639 }
1640
1641 if (log)
1642 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001643 log->Printf ("SBTarget(%p)::WatchpointDelete (wp_id=%d) => %i", target_sp.get(), (uint32_t) wp_id, result);
Johnny Chen096c2932011-09-26 22:40:50 +00001644 }
1645
1646 return result;
1647}
1648
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001649SBWatchpoint
1650SBTarget::FindWatchpointByID (lldb::watch_id_t wp_id)
Johnny Chen096c2932011-09-26 22:40:50 +00001651{
1652 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1653
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001654 SBWatchpoint sb_watchpoint;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001655 lldb::WatchpointSP watchpoint_sp;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001656 TargetSP target_sp(GetSP());
1657 if (target_sp && wp_id != LLDB_INVALID_WATCH_ID)
Johnny Chen096c2932011-09-26 22:40:50 +00001658 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001659 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Johnny Chenbbf6aa52012-05-31 22:56:36 +00001660 Mutex::Locker locker;
1661 target_sp->GetWatchpointList().GetListMutex(locker);
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001662 watchpoint_sp = target_sp->GetWatchpointList().FindByID(wp_id);
1663 sb_watchpoint.SetSP (watchpoint_sp);
Johnny Chen096c2932011-09-26 22:40:50 +00001664 }
1665
1666 if (log)
1667 {
Johnny Chenecd4feb2011-10-14 00:42:25 +00001668 log->Printf ("SBTarget(%p)::FindWatchpointByID (bp_id=%d) => SBWatchpoint(%p)",
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001669 target_sp.get(), (uint32_t) wp_id, watchpoint_sp.get());
Johnny Chen096c2932011-09-26 22:40:50 +00001670 }
1671
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001672 return sb_watchpoint;
1673}
1674
1675lldb::SBWatchpoint
Johnny Chen3f883492012-06-04 23:19:54 +00001676SBTarget::WatchAddress (lldb::addr_t addr, size_t size, bool read, bool write, SBError &error)
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001677{
1678 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1679
1680 SBWatchpoint sb_watchpoint;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001681 lldb::WatchpointSP watchpoint_sp;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001682 TargetSP target_sp(GetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001683 if (target_sp && (read || write) && addr != LLDB_INVALID_ADDRESS && size > 0)
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001684 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001685 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001686 uint32_t watch_type = 0;
1687 if (read)
1688 watch_type |= LLDB_WATCH_TYPE_READ;
1689 if (write)
1690 watch_type |= LLDB_WATCH_TYPE_WRITE;
Johnny Chenbbf6aa52012-05-31 22:56:36 +00001691 // Target::CreateWatchpoint() is thread safe.
Johnny Chen3f883492012-06-04 23:19:54 +00001692 Error cw_error;
1693 watchpoint_sp = target_sp->CreateWatchpoint(addr, size, watch_type, cw_error);
1694 error.SetError(cw_error);
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001695 sb_watchpoint.SetSP (watchpoint_sp);
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001696 }
1697
1698 if (log)
1699 {
1700 log->Printf ("SBTarget(%p)::WatchAddress (addr=0x%llx, 0x%u) => SBWatchpoint(%p)",
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001701 target_sp.get(), addr, (uint32_t) size, watchpoint_sp.get());
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001702 }
1703
1704 return sb_watchpoint;
Johnny Chen096c2932011-09-26 22:40:50 +00001705}
1706
1707bool
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001708SBTarget::EnableAllWatchpoints ()
Johnny Chen096c2932011-09-26 22:40:50 +00001709{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001710 TargetSP target_sp(GetSP());
1711 if (target_sp)
Johnny Chen096c2932011-09-26 22:40:50 +00001712 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001713 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Johnny Chenbbf6aa52012-05-31 22:56:36 +00001714 Mutex::Locker locker;
1715 target_sp->GetWatchpointList().GetListMutex(locker);
Greg Clayton0416bdf2012-01-30 09:04:36 +00001716 target_sp->EnableAllWatchpoints ();
Johnny Chen096c2932011-09-26 22:40:50 +00001717 return true;
1718 }
1719 return false;
1720}
1721
1722bool
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001723SBTarget::DisableAllWatchpoints ()
Johnny Chen096c2932011-09-26 22:40:50 +00001724{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001725 TargetSP target_sp(GetSP());
1726 if (target_sp)
Johnny Chen096c2932011-09-26 22:40:50 +00001727 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001728 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Johnny Chenbbf6aa52012-05-31 22:56:36 +00001729 Mutex::Locker locker;
1730 target_sp->GetWatchpointList().GetListMutex(locker);
Greg Clayton0416bdf2012-01-30 09:04:36 +00001731 target_sp->DisableAllWatchpoints ();
Johnny Chen096c2932011-09-26 22:40:50 +00001732 return true;
1733 }
1734 return false;
1735}
1736
1737bool
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001738SBTarget::DeleteAllWatchpoints ()
Johnny Chen096c2932011-09-26 22:40:50 +00001739{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001740 TargetSP target_sp(GetSP());
1741 if (target_sp)
Johnny Chen096c2932011-09-26 22:40:50 +00001742 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001743 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Johnny Chenbbf6aa52012-05-31 22:56:36 +00001744 Mutex::Locker locker;
1745 target_sp->GetWatchpointList().GetListMutex(locker);
Greg Clayton0416bdf2012-01-30 09:04:36 +00001746 target_sp->RemoveAllWatchpoints ();
Johnny Chen096c2932011-09-26 22:40:50 +00001747 return true;
1748 }
1749 return false;
1750}
1751
Chris Lattner24943d22010-06-08 16:52:24 +00001752
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001753lldb::SBModule
1754SBTarget::AddModule (const char *path,
1755 const char *triple,
1756 const char *uuid_cstr)
1757{
Greg Claytonf0bc8152012-04-23 20:23:39 +00001758 return AddModule (path, triple, uuid_cstr, NULL);
1759}
1760
1761lldb::SBModule
1762SBTarget::AddModule (const char *path,
1763 const char *triple,
1764 const char *uuid_cstr,
1765 const char *symfile)
1766{
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001767 lldb::SBModule sb_module;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001768 TargetSP target_sp(GetSP());
1769 if (target_sp)
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001770 {
Greg Clayton444fe992012-02-26 05:51:37 +00001771 ModuleSpec module_spec;
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001772 if (path)
Greg Clayton444fe992012-02-26 05:51:37 +00001773 module_spec.GetFileSpec().SetFile(path, false);
Greg Claytonf0bc8152012-04-23 20:23:39 +00001774
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001775 if (uuid_cstr)
Greg Clayton444fe992012-02-26 05:51:37 +00001776 module_spec.GetUUID().SetfromCString(uuid_cstr);
Greg Claytonf0bc8152012-04-23 20:23:39 +00001777
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001778 if (triple)
Greg Clayton444fe992012-02-26 05:51:37 +00001779 module_spec.GetArchitecture().SetTriple (triple, target_sp->GetPlatform ().get());
Greg Claytonf0bc8152012-04-23 20:23:39 +00001780
1781 if (symfile)
1782 module_spec.GetSymbolFileSpec ().SetFile(symfile, false);
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001783
Greg Clayton444fe992012-02-26 05:51:37 +00001784 sb_module.SetSP(target_sp->GetSharedModule (module_spec));
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001785 }
1786 return sb_module;
1787}
1788
1789bool
1790SBTarget::AddModule (lldb::SBModule &module)
1791{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001792 TargetSP target_sp(GetSP());
1793 if (target_sp)
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001794 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001795 target_sp->GetImages().AppendIfNeeded (module.GetSP());
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001796 return true;
1797 }
1798 return false;
1799}
1800
Chris Lattner24943d22010-06-08 16:52:24 +00001801uint32_t
1802SBTarget::GetNumModules () const
1803{
Greg Claytone005f2c2010-11-06 01:53:30 +00001804 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001805
Caroline Tice7826c882010-10-26 03:11:13 +00001806 uint32_t num = 0;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001807 TargetSP target_sp(GetSP());
1808 if (target_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +00001809 {
1810 // The module list is thread safe, no need to lock
Greg Clayton0416bdf2012-01-30 09:04:36 +00001811 num = target_sp->GetImages().GetSize();
Greg Claytonbdcda462010-12-20 20:49:23 +00001812 }
Caroline Tice7826c882010-10-26 03:11:13 +00001813
1814 if (log)
Greg Clayton0416bdf2012-01-30 09:04:36 +00001815 log->Printf ("SBTarget(%p)::GetNumModules () => %d", target_sp.get(), num);
Caroline Tice7826c882010-10-26 03:11:13 +00001816
1817 return num;
Chris Lattner24943d22010-06-08 16:52:24 +00001818}
1819
Greg Clayton43490d12010-07-30 20:12:55 +00001820void
1821SBTarget::Clear ()
1822{
Greg Claytone005f2c2010-11-06 01:53:30 +00001823 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001824
1825 if (log)
Greg Clayton3f5ee7f2010-10-29 04:59:35 +00001826 log->Printf ("SBTarget(%p)::Clear ()", m_opaque_sp.get());
Caroline Tice7826c882010-10-26 03:11:13 +00001827
Greg Clayton43490d12010-07-30 20:12:55 +00001828 m_opaque_sp.reset();
1829}
1830
1831
Chris Lattner24943d22010-06-08 16:52:24 +00001832SBModule
1833SBTarget::FindModule (const SBFileSpec &sb_file_spec)
1834{
1835 SBModule sb_module;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001836 TargetSP target_sp(GetSP());
1837 if (target_sp && sb_file_spec.IsValid())
Greg Claytonbdcda462010-12-20 20:49:23 +00001838 {
Greg Clayton444fe992012-02-26 05:51:37 +00001839 ModuleSpec module_spec(*sb_file_spec);
Greg Claytonbdcda462010-12-20 20:49:23 +00001840 // The module list is thread safe, no need to lock
Greg Clayton444fe992012-02-26 05:51:37 +00001841 sb_module.SetSP (target_sp->GetImages().FindFirstModule (module_spec));
Greg Claytonbdcda462010-12-20 20:49:23 +00001842 }
Chris Lattner24943d22010-06-08 16:52:24 +00001843 return sb_module;
1844}
1845
Greg Clayton1b925202012-01-29 06:07:39 +00001846lldb::ByteOrder
1847SBTarget::GetByteOrder ()
1848{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001849 TargetSP target_sp(GetSP());
1850 if (target_sp)
1851 return target_sp->GetArchitecture().GetByteOrder();
Greg Clayton1b925202012-01-29 06:07:39 +00001852 return eByteOrderInvalid;
1853}
1854
1855const char *
1856SBTarget::GetTriple ()
1857{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001858 TargetSP target_sp(GetSP());
1859 if (target_sp)
Greg Clayton1b925202012-01-29 06:07:39 +00001860 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001861 std::string triple (target_sp->GetArchitecture().GetTriple().str());
Greg Clayton1b925202012-01-29 06:07:39 +00001862 // Unique the string so we don't run into ownership issues since
1863 // the const strings put the string into the string pool once and
1864 // the strings never comes out
1865 ConstString const_triple (triple.c_str());
1866 return const_triple.GetCString();
1867 }
1868 return NULL;
1869}
1870
1871uint32_t
1872SBTarget::GetAddressByteSize()
1873{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001874 TargetSP target_sp(GetSP());
1875 if (target_sp)
1876 return target_sp->GetArchitecture().GetAddressByteSize();
Greg Clayton1b925202012-01-29 06:07:39 +00001877 return sizeof(void*);
1878}
1879
1880
Chris Lattner24943d22010-06-08 16:52:24 +00001881SBModule
1882SBTarget::GetModuleAtIndex (uint32_t idx)
1883{
Greg Claytone005f2c2010-11-06 01:53:30 +00001884 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001885
Chris Lattner24943d22010-06-08 16:52:24 +00001886 SBModule sb_module;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001887 ModuleSP module_sp;
1888 TargetSP target_sp(GetSP());
1889 if (target_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +00001890 {
1891 // The module list is thread safe, no need to lock
Greg Clayton0416bdf2012-01-30 09:04:36 +00001892 module_sp = target_sp->GetImages().GetModuleAtIndex(idx);
1893 sb_module.SetSP (module_sp);
Greg Claytonbdcda462010-12-20 20:49:23 +00001894 }
Caroline Tice7826c882010-10-26 03:11:13 +00001895
1896 if (log)
1897 {
Greg Clayton49ce6822010-10-31 03:01:06 +00001898 log->Printf ("SBTarget(%p)::GetModuleAtIndex (idx=%d) => SBModule(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +00001899 target_sp.get(), idx, module_sp.get());
Caroline Tice7826c882010-10-26 03:11:13 +00001900 }
1901
Chris Lattner24943d22010-06-08 16:52:24 +00001902 return sb_module;
1903}
1904
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001905bool
1906SBTarget::RemoveModule (lldb::SBModule module)
1907{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001908 TargetSP target_sp(GetSP());
1909 if (target_sp)
1910 return target_sp->GetImages().Remove(module.GetSP());
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001911 return false;
1912}
1913
Chris Lattner24943d22010-06-08 16:52:24 +00001914
1915SBBroadcaster
1916SBTarget::GetBroadcaster () const
1917{
Greg Claytone005f2c2010-11-06 01:53:30 +00001918 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001919
Greg Clayton0416bdf2012-01-30 09:04:36 +00001920 TargetSP target_sp(GetSP());
1921 SBBroadcaster broadcaster(target_sp.get(), false);
Caroline Tice7826c882010-10-26 03:11:13 +00001922
1923 if (log)
Greg Clayton3f5ee7f2010-10-29 04:59:35 +00001924 log->Printf ("SBTarget(%p)::GetBroadcaster () => SBBroadcaster(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +00001925 target_sp.get(), broadcaster.get());
Caroline Tice7826c882010-10-26 03:11:13 +00001926
Chris Lattner24943d22010-06-08 16:52:24 +00001927 return broadcaster;
1928}
1929
Caroline Tice98f930f2010-09-20 05:20:02 +00001930bool
Caroline Tice7826c882010-10-26 03:11:13 +00001931SBTarget::GetDescription (SBStream &description, lldb::DescriptionLevel description_level)
Caroline Tice98f930f2010-09-20 05:20:02 +00001932{
Greg Clayton96154be2011-11-13 06:57:31 +00001933 Stream &strm = description.ref();
1934
Greg Clayton0416bdf2012-01-30 09:04:36 +00001935 TargetSP target_sp(GetSP());
1936 if (target_sp)
Caroline Ticee7a566e2010-09-20 16:21:41 +00001937 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001938 target_sp->Dump (&strm, description_level);
Caroline Tice7826c882010-10-26 03:11:13 +00001939 }
1940 else
Greg Clayton96154be2011-11-13 06:57:31 +00001941 strm.PutCString ("No value");
Caroline Tice7826c882010-10-26 03:11:13 +00001942
1943 return true;
1944}
1945
Greg Clayton7dd5c512012-02-06 01:44:54 +00001946lldb::SBSymbolContextList
1947SBTarget::FindFunctions (const char *name, uint32_t name_type_mask)
Greg Clayton4ed315f2011-06-21 01:34:41 +00001948{
Greg Clayton7dd5c512012-02-06 01:44:54 +00001949 lldb::SBSymbolContextList sb_sc_list;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001950 if (name && name[0])
Greg Clayton4ed315f2011-06-21 01:34:41 +00001951 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001952 TargetSP target_sp(GetSP());
1953 if (target_sp)
1954 {
1955 const bool symbols_ok = true;
Sean Callanan302d78c2012-02-10 22:52:19 +00001956 const bool inlines_ok = true;
Greg Clayton7dd5c512012-02-06 01:44:54 +00001957 const bool append = true;
1958 target_sp->GetImages().FindFunctions (ConstString(name),
1959 name_type_mask,
Sean Callanan302d78c2012-02-10 22:52:19 +00001960 symbols_ok,
1961 inlines_ok,
Greg Clayton7dd5c512012-02-06 01:44:54 +00001962 append,
1963 *sb_sc_list);
Greg Clayton0416bdf2012-01-30 09:04:36 +00001964 }
Greg Clayton4ed315f2011-06-21 01:34:41 +00001965 }
Greg Clayton7dd5c512012-02-06 01:44:54 +00001966 return sb_sc_list;
Greg Clayton4ed315f2011-06-21 01:34:41 +00001967}
1968
Enrico Granata979e20d2011-07-29 19:53:35 +00001969lldb::SBType
1970SBTarget::FindFirstType (const char* type)
1971{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001972 TargetSP target_sp(GetSP());
1973 if (type && target_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +00001974 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001975 size_t count = target_sp->GetImages().GetSize();
Enrico Granata979e20d2011-07-29 19:53:35 +00001976 for (size_t idx = 0; idx < count; idx++)
1977 {
1978 SBType found_at_idx = GetModuleAtIndex(idx).FindFirstType(type);
1979
1980 if (found_at_idx.IsValid())
1981 return found_at_idx;
1982 }
1983 }
1984 return SBType();
1985}
1986
1987lldb::SBTypeList
1988SBTarget::FindTypes (const char* type)
1989{
1990
1991 SBTypeList retval;
1992
Greg Clayton0416bdf2012-01-30 09:04:36 +00001993 TargetSP target_sp(GetSP());
1994 if (type && target_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +00001995 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001996 ModuleList& images = target_sp->GetImages();
Enrico Granata979e20d2011-07-29 19:53:35 +00001997 ConstString name_const(type);
Greg Claytondc0a38c2012-03-26 23:03:23 +00001998 bool exact_match = false;
Enrico Granata979e20d2011-07-29 19:53:35 +00001999 SymbolContext sc;
2000 TypeList type_list;
2001
Greg Clayton9f95fb62012-04-06 17:41:13 +00002002 uint32_t num_matches = images.FindTypes (sc,
Greg Claytondc0a38c2012-03-26 23:03:23 +00002003 name_const,
2004 exact_match,
2005 UINT32_MAX,
2006 type_list);
Enrico Granata979e20d2011-07-29 19:53:35 +00002007
2008 for (size_t idx = 0; idx < num_matches; idx++)
2009 {
Greg Clayton0fb0bcc2011-08-03 22:57:10 +00002010 TypeSP type_sp (type_list.GetTypeAtIndex(idx));
2011 if (type_sp)
2012 retval.Append(SBType(type_sp));
Enrico Granata979e20d2011-07-29 19:53:35 +00002013 }
2014 }
2015 return retval;
2016}
2017
Greg Clayton917c0002011-06-29 22:09:02 +00002018SBValueList
2019SBTarget::FindGlobalVariables (const char *name, uint32_t max_matches)
2020{
2021 SBValueList sb_value_list;
2022
Greg Clayton0416bdf2012-01-30 09:04:36 +00002023 TargetSP target_sp(GetSP());
2024 if (name && target_sp)
Greg Clayton917c0002011-06-29 22:09:02 +00002025 {
2026 VariableList variable_list;
2027 const bool append = true;
Greg Clayton0416bdf2012-01-30 09:04:36 +00002028 const uint32_t match_count = target_sp->GetImages().FindGlobalVariables (ConstString (name),
2029 append,
2030 max_matches,
2031 variable_list);
Greg Clayton917c0002011-06-29 22:09:02 +00002032
2033 if (match_count > 0)
2034 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00002035 ExecutionContextScope *exe_scope = target_sp->GetProcessSP().get();
Greg Clayton917c0002011-06-29 22:09:02 +00002036 if (exe_scope == NULL)
Greg Clayton0416bdf2012-01-30 09:04:36 +00002037 exe_scope = target_sp.get();
Greg Clayton917c0002011-06-29 22:09:02 +00002038 ValueObjectList &value_object_list = sb_value_list.ref();
2039 for (uint32_t i=0; i<match_count; ++i)
2040 {
2041 lldb::ValueObjectSP valobj_sp (ValueObjectVariable::Create (exe_scope, variable_list.GetVariableAtIndex(i)));
2042 if (valobj_sp)
2043 value_object_list.Append(valobj_sp);
2044 }
2045 }
2046 }
2047
2048 return sb_value_list;
2049}
2050
Jim Inghamcc637462011-09-13 00:29:56 +00002051SBSourceManager
2052SBTarget::GetSourceManager()
2053{
2054 SBSourceManager source_manager (*this);
2055 return source_manager;
2056}
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002057
Sean Callananef1f6902011-12-14 23:49:37 +00002058lldb::SBInstructionList
Greg Claytona9893072012-03-06 22:24:44 +00002059SBTarget::ReadInstructions (lldb::SBAddress base_addr, uint32_t count)
2060{
2061 SBInstructionList sb_instructions;
2062
2063 TargetSP target_sp(GetSP());
2064 if (target_sp)
2065 {
2066 Address *addr_ptr = base_addr.get();
2067
2068 if (addr_ptr)
2069 {
2070 DataBufferHeap data (target_sp->GetArchitecture().GetMaximumOpcodeByteSize() * count, 0);
2071 bool prefer_file_cache = false;
2072 lldb_private::Error error;
2073 const size_t bytes_read = target_sp->ReadMemory(*addr_ptr, prefer_file_cache, data.GetBytes(), data.GetByteSize(), error);
2074 sb_instructions.SetDisassembler (Disassembler::DisassembleBytes (target_sp->GetArchitecture(),
2075 NULL,
2076 *addr_ptr,
2077 data.GetBytes(),
2078 bytes_read,
2079 count));
2080 }
2081 }
2082
2083 return sb_instructions;
2084
2085}
2086
2087lldb::SBInstructionList
Sean Callananef1f6902011-12-14 23:49:37 +00002088SBTarget::GetInstructions (lldb::SBAddress base_addr, const void *buf, size_t size)
2089{
2090 SBInstructionList sb_instructions;
2091
Greg Clayton0416bdf2012-01-30 09:04:36 +00002092 TargetSP target_sp(GetSP());
2093 if (target_sp)
Sean Callananef1f6902011-12-14 23:49:37 +00002094 {
2095 Address addr;
2096
2097 if (base_addr.get())
2098 addr = *base_addr.get();
2099
Greg Clayton0416bdf2012-01-30 09:04:36 +00002100 sb_instructions.SetDisassembler (Disassembler::DisassembleBytes (target_sp->GetArchitecture(),
Sean Callananef1f6902011-12-14 23:49:37 +00002101 NULL,
2102 addr,
2103 buf,
2104 size));
2105 }
2106
2107 return sb_instructions;
2108}
2109
2110lldb::SBInstructionList
2111SBTarget::GetInstructions (lldb::addr_t base_addr, const void *buf, size_t size)
2112{
2113 return GetInstructions (ResolveLoadAddress(base_addr), buf, size);
2114}
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002115
2116SBError
2117SBTarget::SetSectionLoadAddress (lldb::SBSection section,
2118 lldb::addr_t section_base_addr)
2119{
2120 SBError sb_error;
Greg Clayton0416bdf2012-01-30 09:04:36 +00002121 TargetSP target_sp(GetSP());
2122 if (target_sp)
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002123 {
2124 if (!section.IsValid())
2125 {
2126 sb_error.SetErrorStringWithFormat ("invalid section");
2127 }
2128 else
2129 {
Greg Clayton9ab696e2012-03-27 21:10:07 +00002130 SectionSP section_sp (section.GetSP());
2131 if (section_sp)
2132 {
2133 if (section_sp->IsThreadSpecific())
2134 {
2135 sb_error.SetErrorString ("thread specific sections are not yet supported");
2136 }
2137 else
2138 {
Greg Clayton545762f2012-07-07 01:24:12 +00002139 target_sp->GetSectionLoadList().SetSectionLoadAddress (section_sp, section_base_addr);
Greg Clayton9ab696e2012-03-27 21:10:07 +00002140 }
2141 }
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002142 }
2143 }
2144 else
2145 {
Greg Clayton9ab696e2012-03-27 21:10:07 +00002146 sb_error.SetErrorString ("invalid target");
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002147 }
2148 return sb_error;
2149}
2150
2151SBError
2152SBTarget::ClearSectionLoadAddress (lldb::SBSection section)
2153{
2154 SBError sb_error;
2155
Greg Clayton0416bdf2012-01-30 09:04:36 +00002156 TargetSP target_sp(GetSP());
2157 if (target_sp)
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002158 {
2159 if (!section.IsValid())
2160 {
2161 sb_error.SetErrorStringWithFormat ("invalid section");
2162 }
2163 else
2164 {
Greg Clayton545762f2012-07-07 01:24:12 +00002165 target_sp->GetSectionLoadList().SetSectionUnloaded (section.GetSP());
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002166 }
2167 }
2168 else
2169 {
2170 sb_error.SetErrorStringWithFormat ("invalid target");
2171 }
2172 return sb_error;
2173}
2174
2175SBError
2176SBTarget::SetModuleLoadAddress (lldb::SBModule module, int64_t slide_offset)
2177{
2178 SBError sb_error;
2179
Greg Clayton0416bdf2012-01-30 09:04:36 +00002180 TargetSP target_sp(GetSP());
2181 if (target_sp)
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002182 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00002183 ModuleSP module_sp (module.GetSP());
2184 if (module_sp)
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002185 {
Greg Clayton9ab696e2012-03-27 21:10:07 +00002186 bool changed = false;
2187 if (module_sp->SetLoadAddress (*target_sp, slide_offset, changed))
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002188 {
Greg Clayton9ab696e2012-03-27 21:10:07 +00002189 // The load was successful, make sure that at least some sections
2190 // changed before we notify that our module was loaded.
2191 if (changed)
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002192 {
Greg Clayton9ab696e2012-03-27 21:10:07 +00002193 ModuleList module_list;
2194 module_list.Append(module_sp);
2195 target_sp->ModulesDidLoad (module_list);
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002196 }
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002197 }
2198 }
Greg Clayton0416bdf2012-01-30 09:04:36 +00002199 else
2200 {
2201 sb_error.SetErrorStringWithFormat ("invalid module");
2202 }
2203
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002204 }
2205 else
2206 {
2207 sb_error.SetErrorStringWithFormat ("invalid target");
2208 }
2209 return sb_error;
2210}
2211
2212SBError
2213SBTarget::ClearModuleLoadAddress (lldb::SBModule module)
2214{
2215 SBError sb_error;
2216
2217 char path[PATH_MAX];
Greg Clayton0416bdf2012-01-30 09:04:36 +00002218 TargetSP target_sp(GetSP());
2219 if (target_sp)
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002220 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00002221 ModuleSP module_sp (module.GetSP());
2222 if (module_sp)
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002223 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00002224 ObjectFile *objfile = module_sp->GetObjectFile();
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002225 if (objfile)
2226 {
2227 SectionList *section_list = objfile->GetSectionList();
2228 if (section_list)
2229 {
2230 const size_t num_sections = section_list->GetSize();
2231 for (size_t sect_idx = 0; sect_idx < num_sections; ++sect_idx)
2232 {
2233 SectionSP section_sp (section_list->GetSectionAtIndex(sect_idx));
2234 if (section_sp)
Greg Clayton545762f2012-07-07 01:24:12 +00002235 target_sp->GetSectionLoadList().SetSectionUnloaded (section_sp);
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002236 }
2237 }
2238 else
2239 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00002240 module_sp->GetFileSpec().GetPath (path, sizeof(path));
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002241 sb_error.SetErrorStringWithFormat ("no sections in object file '%s'", path);
2242 }
2243 }
2244 else
2245 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00002246 module_sp->GetFileSpec().GetPath (path, sizeof(path));
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002247 sb_error.SetErrorStringWithFormat ("no object file for module '%s'", path);
2248 }
2249 }
Greg Clayton0416bdf2012-01-30 09:04:36 +00002250 else
2251 {
2252 sb_error.SetErrorStringWithFormat ("invalid module");
2253 }
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002254 }
2255 else
2256 {
2257 sb_error.SetErrorStringWithFormat ("invalid target");
2258 }
2259 return sb_error;
2260}
2261
2262