blob: d4810f580db1bca52440817ca3d5cb297fa70b7a [file] [log] [blame]
Chris Lattner24943d22010-06-08 16:52:24 +00001//===-- SBTarget.cpp --------------------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
Eli Friedman7a62c8b2010-06-09 07:44:37 +000010#include "lldb/API/SBTarget.h"
Chris Lattner24943d22010-06-08 16:52:24 +000011
Greg Claytonb3448432011-03-24 21:19:54 +000012#include "lldb/lldb-public.h"
Chris Lattner24943d22010-06-08 16:52:24 +000013
Greg Clayton917c0002011-06-29 22:09:02 +000014#include "lldb/API/SBDebugger.h"
15#include "lldb/API/SBBreakpoint.h"
Chris Lattner24943d22010-06-08 16:52:24 +000016#include "lldb/API/SBFileSpec.h"
Greg Clayton917c0002011-06-29 22:09:02 +000017#include "lldb/API/SBListener.h"
Chris Lattner24943d22010-06-08 16:52:24 +000018#include "lldb/API/SBModule.h"
Jim Inghamcc637462011-09-13 00:29:56 +000019#include "lldb/API/SBSourceManager.h"
Greg Clayton917c0002011-06-29 22:09:02 +000020#include "lldb/API/SBProcess.h"
Caroline Tice98f930f2010-09-20 05:20:02 +000021#include "lldb/API/SBStream.h"
Greg Clayton4ed315f2011-06-21 01:34:41 +000022#include "lldb/API/SBSymbolContextList.h"
Chris Lattner24943d22010-06-08 16:52:24 +000023#include "lldb/Breakpoint/BreakpointID.h"
24#include "lldb/Breakpoint/BreakpointIDList.h"
25#include "lldb/Breakpoint/BreakpointList.h"
26#include "lldb/Breakpoint/BreakpointLocation.h"
27#include "lldb/Core/Address.h"
28#include "lldb/Core/AddressResolver.h"
29#include "lldb/Core/AddressResolverName.h"
Chris Lattner24943d22010-06-08 16:52:24 +000030#include "lldb/Core/ArchSpec.h"
31#include "lldb/Core/Debugger.h"
32#include "lldb/Core/Disassembler.h"
Caroline Tice7826c882010-10-26 03:11:13 +000033#include "lldb/Core/Log.h"
Chris Lattner24943d22010-06-08 16:52:24 +000034#include "lldb/Core/RegularExpression.h"
35#include "lldb/Core/SearchFilter.h"
36#include "lldb/Core/STLUtils.h"
Greg Clayton917c0002011-06-29 22:09:02 +000037#include "lldb/Core/ValueObjectList.h"
38#include "lldb/Core/ValueObjectVariable.h"
39#include "lldb/Host/FileSpec.h"
Greg Claytoncd548032011-02-01 01:31:41 +000040#include "lldb/Host/Host.h"
Greg Clayton917c0002011-06-29 22:09:02 +000041#include "lldb/Interpreter/Args.h"
Enrico Granata979e20d2011-07-29 19:53:35 +000042#include "lldb/Symbol/SymbolVendor.h"
Greg Clayton917c0002011-06-29 22:09:02 +000043#include "lldb/Symbol/VariableList.h"
Chris Lattner24943d22010-06-08 16:52:24 +000044#include "lldb/Target/Process.h"
45#include "lldb/Target/Target.h"
46#include "lldb/Target/TargetList.h"
47
48#include "lldb/Interpreter/CommandReturnObject.h"
49#include "../source/Commands/CommandObjectBreakpoint.h"
50
Chris Lattner24943d22010-06-08 16:52:24 +000051
52using namespace lldb;
53using namespace lldb_private;
54
55#define DEFAULT_DISASM_BYTE_SIZE 32
56
Greg Clayton98ca1e62012-02-24 20:59:25 +000057SBLaunchInfo::SBLaunchInfo (const char **argv) :
58 m_opaque_sp(new ProcessLaunchInfo())
Greg Clayton0a8dcac2012-02-24 05:03:03 +000059{
Greg Clayton98ca1e62012-02-24 20:59:25 +000060 m_opaque_sp->GetFlags().Reset (eLaunchFlagDebug | eLaunchFlagDisableASLR);
61 if (argv && argv[0])
62 m_opaque_sp->GetArguments().SetArguments(argv);
Greg Clayton0a8dcac2012-02-24 05:03:03 +000063}
64
65uint32_t
66SBLaunchInfo::GetUserID()
67{
68 return m_opaque_sp->GetUserID();
69}
70
71uint32_t
72SBLaunchInfo::GetGroupID()
73{
74 return m_opaque_sp->GetGroupID();
75}
76
77bool
78SBLaunchInfo::UserIDIsValid ()
79{
80 return m_opaque_sp->UserIDIsValid();
81}
82
83bool
84SBLaunchInfo::GroupIDIsValid ()
85{
86 return m_opaque_sp->GroupIDIsValid();
87}
88
89void
90SBLaunchInfo::SetUserID (uint32_t uid)
91{
92 m_opaque_sp->SetUserID (uid);
93}
94
95void
96SBLaunchInfo::SetGroupID (uint32_t gid)
97{
98 m_opaque_sp->SetGroupID (gid);
99}
100
Greg Clayton0a8dcac2012-02-24 05:03:03 +0000101uint32_t
102SBLaunchInfo::GetNumArguments ()
103{
104 return m_opaque_sp->GetArguments().GetArgumentCount();
105}
106
107const char *
108SBLaunchInfo::GetArgumentAtIndex (uint32_t idx)
109{
110 return m_opaque_sp->GetArguments().GetArgumentAtIndex(idx);
111}
112
113void
114SBLaunchInfo::SetArguments (const char **argv, bool append)
115{
116 if (append)
117 {
118 if (argv)
119 m_opaque_sp->GetArguments().AppendArguments(argv);
120 }
121 else
122 {
123 if (argv)
124 m_opaque_sp->GetArguments().SetArguments(argv);
125 else
126 m_opaque_sp->GetArguments().Clear();
127 }
128}
129
130uint32_t
131SBLaunchInfo::GetNumEnvironmentEntries ()
132{
133 return m_opaque_sp->GetEnvironmentEntries().GetArgumentCount();
134}
135
136const char *
137SBLaunchInfo::GetEnvironmentEntryAtIndex (uint32_t idx)
138{
139 return m_opaque_sp->GetEnvironmentEntries().GetArgumentAtIndex(idx);
140}
141
142void
143SBLaunchInfo::SetEnvironmentEntries (const char **envp, bool append)
144{
145 if (append)
146 {
147 if (envp)
148 m_opaque_sp->GetEnvironmentEntries().AppendArguments(envp);
149 }
150 else
151 {
152 if (envp)
153 m_opaque_sp->GetEnvironmentEntries().SetArguments(envp);
154 else
155 m_opaque_sp->GetEnvironmentEntries().Clear();
156 }
157}
158
159void
160SBLaunchInfo::Clear ()
161{
162 m_opaque_sp->Clear();
163}
164
165const char *
166SBLaunchInfo::GetWorkingDirectory () const
167{
168 return m_opaque_sp->GetWorkingDirectory();
169}
170
171void
172SBLaunchInfo::SetWorkingDirectory (const char *working_dir)
173{
174 m_opaque_sp->SetWorkingDirectory(working_dir);
175}
176
177uint32_t
178SBLaunchInfo::GetLaunchFlags ()
179{
180 return m_opaque_sp->GetFlags().Get();
181}
182
183void
184SBLaunchInfo::SetLaunchFlags (uint32_t flags)
185{
186 m_opaque_sp->GetFlags().Reset(flags);
187}
188
189const char *
190SBLaunchInfo::GetProcessPluginName ()
191{
192 return m_opaque_sp->GetProcessPluginName();
193}
194
195void
196SBLaunchInfo::SetProcessPluginName (const char *plugin_name)
197{
198 return m_opaque_sp->SetProcessPluginName (plugin_name);
199}
200
201const char *
202SBLaunchInfo::GetShell ()
203{
204 return m_opaque_sp->GetShell();
205}
206
207void
208SBLaunchInfo::SetShell (const char * path)
209{
210 m_opaque_sp->SetShell (path);
211}
212
213uint32_t
214SBLaunchInfo::GetResumeCount ()
215{
216 return m_opaque_sp->GetResumeCount();
217}
218
219void
220SBLaunchInfo::SetResumeCount (uint32_t c)
221{
222 m_opaque_sp->SetResumeCount (c);
223}
224
225bool
226SBLaunchInfo::AddCloseFileAction (int fd)
227{
228 return m_opaque_sp->AppendCloseFileAction(fd);
229}
230
231bool
232SBLaunchInfo::AddDuplicateFileAction (int fd, int dup_fd)
233{
234 return m_opaque_sp->AppendDuplicateFileAction(fd, dup_fd);
235}
236
237bool
238SBLaunchInfo::AddOpenFileAction (int fd, const char *path, bool read, bool write)
239{
240 return m_opaque_sp->AppendOpenFileAction(fd, path, read, write);
241}
242
243bool
244SBLaunchInfo::AddSuppressFileAction (int fd, bool read, bool write)
245{
246 return m_opaque_sp->AppendSuppressFileAction(fd, read, write);
247}
248
249
250SBAttachInfo::SBAttachInfo () :
251m_opaque_sp (new ProcessAttachInfo())
252{
253}
254
255SBAttachInfo::SBAttachInfo (lldb::pid_t pid) :
256m_opaque_sp (new ProcessAttachInfo())
257{
258 m_opaque_sp->SetProcessID (pid);
259}
260
261SBAttachInfo::SBAttachInfo (const char *path, bool wait_for) :
262m_opaque_sp (new ProcessAttachInfo())
263{
264 if (path && path[0])
265 m_opaque_sp->GetExecutableFile().SetFile(path, false);
266 m_opaque_sp->SetWaitForLaunch (wait_for);
267}
268
269SBAttachInfo::SBAttachInfo (const SBAttachInfo &rhs) :
270m_opaque_sp (new ProcessAttachInfo())
271{
272 *m_opaque_sp = *rhs.m_opaque_sp;
273}
274
275SBAttachInfo &
276SBAttachInfo::operator = (const SBAttachInfo &rhs)
277{
278 if (this != &rhs)
279 *m_opaque_sp = *rhs.m_opaque_sp;
280 return *this;
281}
282
283lldb::pid_t
284SBAttachInfo::GetProcessID ()
285{
286 return m_opaque_sp->GetProcessID();
287}
288
289void
290SBAttachInfo::SetProcessID (lldb::pid_t pid)
291{
292 m_opaque_sp->SetProcessID (pid);
293}
294
295
296uint32_t
297SBAttachInfo::GetResumeCount ()
298{
299 return m_opaque_sp->GetResumeCount();
300}
301
302void
303SBAttachInfo::SetResumeCount (uint32_t c)
304{
305 m_opaque_sp->SetResumeCount (c);
306}
307
308const char *
309SBAttachInfo::GetProcessPluginName ()
310{
311 return m_opaque_sp->GetProcessPluginName();
312}
313
314void
315SBAttachInfo::SetProcessPluginName (const char *plugin_name)
316{
317 return m_opaque_sp->SetProcessPluginName (plugin_name);
318}
319
320void
321SBAttachInfo::SetExecutable (const char *path)
322{
323 if (path && path[0])
324 m_opaque_sp->GetExecutableFile().SetFile(path, false);
325 else
326 m_opaque_sp->GetExecutableFile().Clear();
327}
328
329void
330SBAttachInfo::SetExecutable (SBFileSpec exe_file)
331{
332 if (exe_file.IsValid())
333 m_opaque_sp->GetExecutableFile() = exe_file.ref();
334 else
335 m_opaque_sp->GetExecutableFile().Clear();
336}
337
338bool
339SBAttachInfo::GetWaitForLaunch ()
340{
341 return m_opaque_sp->GetWaitForLaunch();
342}
343
344void
345SBAttachInfo::SetWaitForLaunch (bool b)
346{
347 m_opaque_sp->SetWaitForLaunch (b);
348}
349
350uint32_t
Greg Clayton80efa5e2012-02-24 23:56:06 +0000351SBAttachInfo::GetUserID()
352{
353 return m_opaque_sp->GetUserID();
354}
355
356uint32_t
357SBAttachInfo::GetGroupID()
358{
359 return m_opaque_sp->GetGroupID();
360}
361
362bool
363SBAttachInfo::UserIDIsValid ()
364{
365 return m_opaque_sp->UserIDIsValid();
366}
367
368bool
369SBAttachInfo::GroupIDIsValid ()
370{
371 return m_opaque_sp->GroupIDIsValid();
372}
373
374void
375SBAttachInfo::SetUserID (uint32_t uid)
376{
377 m_opaque_sp->SetUserID (uid);
378}
379
380void
381SBAttachInfo::SetGroupID (uint32_t gid)
382{
383 m_opaque_sp->SetGroupID (gid);
384}
385
386uint32_t
Greg Clayton0a8dcac2012-02-24 05:03:03 +0000387SBAttachInfo::GetEffectiveUserID()
388{
389 return m_opaque_sp->GetEffectiveUserID();
390}
391
392uint32_t
393SBAttachInfo::GetEffectiveGroupID()
394{
395 return m_opaque_sp->GetEffectiveGroupID();
396}
397
398bool
399SBAttachInfo::EffectiveUserIDIsValid ()
400{
401 return m_opaque_sp->EffectiveUserIDIsValid();
402}
403
404bool
405SBAttachInfo::EffectiveGroupIDIsValid ()
406{
407 return m_opaque_sp->EffectiveGroupIDIsValid ();
408}
409
410void
411SBAttachInfo::SetEffectiveUserID (uint32_t uid)
412{
413 m_opaque_sp->SetEffectiveUserID(uid);
414}
415
416void
417SBAttachInfo::SetEffectiveGroupID (uint32_t gid)
418{
419 m_opaque_sp->SetEffectiveGroupID(gid);
420}
421
422lldb::pid_t
423SBAttachInfo::GetParentProcessID ()
424{
425 return m_opaque_sp->GetParentProcessID();
426}
427
428void
429SBAttachInfo::SetParentProcessID (lldb::pid_t pid)
430{
431 m_opaque_sp->SetParentProcessID (pid);
432}
433
434bool
435SBAttachInfo::ParentProcessIDIsValid()
436{
437 return m_opaque_sp->ParentProcessIDIsValid();
438}
439
440
Chris Lattner24943d22010-06-08 16:52:24 +0000441//----------------------------------------------------------------------
442// SBTarget constructor
443//----------------------------------------------------------------------
Greg Claytonc3b61d22010-12-15 05:08:08 +0000444SBTarget::SBTarget () :
445 m_opaque_sp ()
Chris Lattner24943d22010-06-08 16:52:24 +0000446{
447}
448
449SBTarget::SBTarget (const SBTarget& rhs) :
Greg Clayton63094e02010-06-23 01:19:29 +0000450 m_opaque_sp (rhs.m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000451{
452}
453
454SBTarget::SBTarget(const TargetSP& target_sp) :
Greg Clayton63094e02010-06-23 01:19:29 +0000455 m_opaque_sp (target_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000456{
457}
458
Greg Clayton538eb822010-11-05 23:17:00 +0000459const SBTarget&
460SBTarget::operator = (const SBTarget& rhs)
461{
462 if (this != &rhs)
463 m_opaque_sp = rhs.m_opaque_sp;
464 return *this;
465}
466
Chris Lattner24943d22010-06-08 16:52:24 +0000467//----------------------------------------------------------------------
468// Destructor
469//----------------------------------------------------------------------
470SBTarget::~SBTarget()
471{
472}
473
Jim Ingham5a15e692012-02-16 06:50:00 +0000474const char *
475SBTarget::GetBroadcasterClassName ()
476{
477 return Target::GetStaticBroadcasterClass().AsCString();
478}
479
Chris Lattner24943d22010-06-08 16:52:24 +0000480bool
481SBTarget::IsValid () const
482{
Greg Clayton63094e02010-06-23 01:19:29 +0000483 return m_opaque_sp.get() != NULL;
Chris Lattner24943d22010-06-08 16:52:24 +0000484}
485
486SBProcess
487SBTarget::GetProcess ()
488{
489 SBProcess sb_process;
Greg Clayton334d33a2012-01-30 07:41:31 +0000490 ProcessSP process_sp;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000491 TargetSP target_sp(GetSP());
492 if (target_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000493 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000494 process_sp = target_sp->GetProcessSP();
Greg Clayton334d33a2012-01-30 07:41:31 +0000495 sb_process.SetSP (process_sp);
Greg Claytonbdcda462010-12-20 20:49:23 +0000496 }
Caroline Tice7826c882010-10-26 03:11:13 +0000497
Greg Claytone005f2c2010-11-06 01:53:30 +0000498 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000499 if (log)
500 {
Greg Clayton49ce6822010-10-31 03:01:06 +0000501 log->Printf ("SBTarget(%p)::GetProcess () => SBProcess(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +0000502 target_sp.get(), process_sp.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000503 }
504
Chris Lattner24943d22010-06-08 16:52:24 +0000505 return sb_process;
506}
507
Greg Clayton63094e02010-06-23 01:19:29 +0000508SBDebugger
509SBTarget::GetDebugger () const
510{
511 SBDebugger debugger;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000512 TargetSP target_sp(GetSP());
513 if (target_sp)
514 debugger.reset (target_sp->GetDebugger().shared_from_this());
Greg Clayton63094e02010-06-23 01:19:29 +0000515 return debugger;
516}
517
Jim Inghamb5871fe2011-03-31 00:01:24 +0000518SBProcess
519SBTarget::LaunchSimple
520(
521 char const **argv,
522 char const **envp,
523 const char *working_directory
524)
525{
526 char *stdin_path = NULL;
527 char *stdout_path = NULL;
528 char *stderr_path = NULL;
529 uint32_t launch_flags = 0;
530 bool stop_at_entry = false;
531 SBError error;
532 SBListener listener = GetDebugger().GetListener();
533 return Launch (listener,
534 argv,
535 envp,
536 stdin_path,
537 stdout_path,
538 stderr_path,
539 working_directory,
540 launch_flags,
541 stop_at_entry,
542 error);
543}
Greg Claytonde915be2011-01-23 05:56:20 +0000544
545SBProcess
546SBTarget::Launch
547(
Greg Clayton271a5db2011-02-03 21:28:34 +0000548 SBListener &listener,
Greg Claytonde915be2011-01-23 05:56:20 +0000549 char const **argv,
550 char const **envp,
551 const char *stdin_path,
552 const char *stdout_path,
553 const char *stderr_path,
554 const char *working_directory,
555 uint32_t launch_flags, // See LaunchFlags
556 bool stop_at_entry,
557 lldb::SBError& error
558)
559{
Greg Claytone005f2c2010-11-06 01:53:30 +0000560 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000561
Greg Clayton0416bdf2012-01-30 09:04:36 +0000562 SBProcess sb_process;
563 ProcessSP process_sp;
564 TargetSP target_sp(GetSP());
565
Caroline Tice7826c882010-10-26 03:11:13 +0000566 if (log)
Greg Clayton3f5ee7f2010-10-29 04:59:35 +0000567 {
Greg Claytonde915be2011-01-23 05:56:20 +0000568 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 +0000569 target_sp.get(),
Greg Claytonde915be2011-01-23 05:56:20 +0000570 argv,
571 envp,
572 stdin_path ? stdin_path : "NULL",
573 stdout_path ? stdout_path : "NULL",
574 stderr_path ? stderr_path : "NULL",
575 working_directory ? working_directory : "NULL",
576 launch_flags,
577 stop_at_entry,
578 error.get());
Greg Clayton3f5ee7f2010-10-29 04:59:35 +0000579 }
Greg Clayton0416bdf2012-01-30 09:04:36 +0000580
581 if (target_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000582 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000583 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton1a3083a2010-10-06 03:53:16 +0000584
Greg Clayton7c330d62011-01-27 01:01:10 +0000585 if (getenv("LLDB_LAUNCH_FLAG_DISABLE_ASLR"))
586 launch_flags |= eLaunchFlagDisableASLR;
587
Greg Clayton180546b2011-04-30 01:09:13 +0000588 StateType state = eStateInvalid;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000589 process_sp = target_sp->GetProcessSP();
Greg Clayton334d33a2012-01-30 07:41:31 +0000590 if (process_sp)
Greg Clayton28d5fcc2011-01-27 06:44:37 +0000591 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000592 state = process_sp->GetState();
Greg Clayton180546b2011-04-30 01:09:13 +0000593
Greg Clayton334d33a2012-01-30 07:41:31 +0000594 if (process_sp->IsAlive() && state != eStateConnected)
Greg Clayton180546b2011-04-30 01:09:13 +0000595 {
596 if (state == eStateAttaching)
597 error.SetErrorString ("process attach is in progress");
598 else
599 error.SetErrorString ("a process is already being debugged");
Greg Clayton180546b2011-04-30 01:09:13 +0000600 return sb_process;
601 }
Greg Clayton28d5fcc2011-01-27 06:44:37 +0000602 }
603
Greg Clayton180546b2011-04-30 01:09:13 +0000604 if (state == eStateConnected)
605 {
606 // If we are already connected, then we have already specified the
607 // listener, so if a valid listener is supplied, we need to error out
608 // to let the client know.
609 if (listener.IsValid())
610 {
611 error.SetErrorString ("process is connected and already has a listener, pass empty listener");
Greg Clayton180546b2011-04-30 01:09:13 +0000612 return sb_process;
613 }
614 }
615 else
Greg Claytonc5f728c2010-10-06 22:10:17 +0000616 {
Greg Clayton271a5db2011-02-03 21:28:34 +0000617 if (listener.IsValid())
Greg Clayton46c9a352012-02-09 06:16:32 +0000618 process_sp = target_sp->CreateProcess (listener.ref(), NULL, NULL);
Greg Clayton271a5db2011-02-03 21:28:34 +0000619 else
Greg Clayton46c9a352012-02-09 06:16:32 +0000620 process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener(), NULL, NULL);
Greg Clayton180546b2011-04-30 01:09:13 +0000621 }
Greg Clayton7c330d62011-01-27 01:01:10 +0000622
Greg Clayton334d33a2012-01-30 07:41:31 +0000623 if (process_sp)
Greg Clayton180546b2011-04-30 01:09:13 +0000624 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000625 sb_process.SetSP (process_sp);
Greg Clayton180546b2011-04-30 01:09:13 +0000626 if (getenv("LLDB_LAUNCH_FLAG_DISABLE_STDIO"))
627 launch_flags |= eLaunchFlagDisableSTDIO;
628
Greg Clayton36bc5ea2011-11-03 21:22:33 +0000629 ProcessLaunchInfo launch_info (stdin_path, stdout_path, stderr_path, working_directory, launch_flags);
630
Greg Clayton0416bdf2012-01-30 09:04:36 +0000631 Module *exe_module = target_sp->GetExecutableModulePointer();
Greg Clayton36bc5ea2011-11-03 21:22:33 +0000632 if (exe_module)
Greg Clayton1d1f39e2011-11-29 04:03:30 +0000633 launch_info.SetExecutableFile(exe_module->GetPlatformFileSpec(), true);
Greg Clayton36bc5ea2011-11-03 21:22:33 +0000634 if (argv)
635 launch_info.GetArguments().AppendArguments (argv);
636 if (envp)
637 launch_info.GetEnvironmentEntries ().SetArguments (envp);
638
Greg Clayton334d33a2012-01-30 07:41:31 +0000639 error.SetError (process_sp->Launch (launch_info));
Greg Clayton180546b2011-04-30 01:09:13 +0000640 if (error.Success())
Greg Clayton7c330d62011-01-27 01:01:10 +0000641 {
Greg Clayton180546b2011-04-30 01:09:13 +0000642 // We we are stopping at the entry point, we can return now!
643 if (stop_at_entry)
644 return sb_process;
Greg Clayton7c330d62011-01-27 01:01:10 +0000645
Greg Clayton180546b2011-04-30 01:09:13 +0000646 // Make sure we are stopped at the entry
Greg Clayton334d33a2012-01-30 07:41:31 +0000647 StateType state = process_sp->WaitForProcessToStop (NULL);
Greg Clayton180546b2011-04-30 01:09:13 +0000648 if (state == eStateStopped)
Greg Clayton7c330d62011-01-27 01:01:10 +0000649 {
Greg Clayton180546b2011-04-30 01:09:13 +0000650 // resume the process to skip the entry point
Greg Clayton334d33a2012-01-30 07:41:31 +0000651 error.SetError (process_sp->Resume());
Greg Clayton180546b2011-04-30 01:09:13 +0000652 if (error.Success())
Greg Clayton7c330d62011-01-27 01:01:10 +0000653 {
Greg Clayton180546b2011-04-30 01:09:13 +0000654 // If we are doing synchronous mode, then wait for the
655 // process to stop yet again!
Greg Clayton0416bdf2012-01-30 09:04:36 +0000656 if (target_sp->GetDebugger().GetAsyncExecution () == false)
Greg Clayton334d33a2012-01-30 07:41:31 +0000657 process_sp->WaitForProcessToStop (NULL);
Greg Clayton7c330d62011-01-27 01:01:10 +0000658 }
659 }
660 }
Greg Clayton180546b2011-04-30 01:09:13 +0000661 }
662 else
663 {
664 error.SetErrorString ("unable to create lldb_private::Process");
Greg Claytonc5f728c2010-10-06 22:10:17 +0000665 }
666 }
667 else
668 {
669 error.SetErrorString ("SBTarget is invalid");
Chris Lattner24943d22010-06-08 16:52:24 +0000670 }
Caroline Tice7826c882010-10-26 03:11:13 +0000671
Caroline Tice926060e2010-10-29 21:48:37 +0000672 log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
Caroline Tice7826c882010-10-26 03:11:13 +0000673 if (log)
674 {
Greg Clayton49ce6822010-10-31 03:01:06 +0000675 log->Printf ("SBTarget(%p)::Launch (...) => SBProceess(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +0000676 target_sp.get(), process_sp.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000677 }
678
Greg Clayton1a3083a2010-10-06 03:53:16 +0000679 return sb_process;
Chris Lattner24943d22010-06-08 16:52:24 +0000680}
681
Greg Clayton0a8dcac2012-02-24 05:03:03 +0000682SBProcess
683SBTarget::Launch (SBLaunchInfo &sb_launch_info, SBError& error)
684{
685 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
686
687 SBProcess sb_process;
688 ProcessSP process_sp;
689 TargetSP target_sp(GetSP());
690
691 if (log)
692 {
693 log->Printf ("SBTarget(%p)::Launch (launch_info, error)...", target_sp.get());
694 }
695
696 if (target_sp)
697 {
698 Mutex::Locker api_locker (target_sp->GetAPIMutex());
699 StateType state = eStateInvalid;
700 process_sp = target_sp->GetProcessSP();
701 if (process_sp)
702 {
703 state = process_sp->GetState();
704
705 if (process_sp->IsAlive() && state != eStateConnected)
706 {
707 if (state == eStateAttaching)
708 error.SetErrorString ("process attach is in progress");
709 else
710 error.SetErrorString ("a process is already being debugged");
711 return sb_process;
712 }
713 }
714
715 if (state != eStateConnected)
716 process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener(), NULL, NULL);
717
718 if (process_sp)
719 {
720 sb_process.SetSP (process_sp);
721 lldb_private::ProcessLaunchInfo &launch_info = sb_launch_info.ref();
Greg Clayton98ca1e62012-02-24 20:59:25 +0000722
Greg Clayton98ca1e62012-02-24 20:59:25 +0000723 Module *exe_module = target_sp->GetExecutableModulePointer();
724 if (exe_module)
Han Ming Ongc86723f2012-03-02 01:02:04 +0000725 launch_info.SetExecutableFile(exe_module->GetPlatformFileSpec(), true);
Greg Clayton98ca1e62012-02-24 20:59:25 +0000726
727 const ArchSpec &arch_spec = target_sp->GetArchitecture();
728 if (arch_spec.IsValid())
729 launch_info.GetArchitecture () = arch_spec;
730
Greg Clayton0a8dcac2012-02-24 05:03:03 +0000731 error.SetError (process_sp->Launch (launch_info));
Greg Clayton98ca1e62012-02-24 20:59:25 +0000732 const bool synchronous_execution = target_sp->GetDebugger().GetAsyncExecution () == false;
Greg Clayton0a8dcac2012-02-24 05:03:03 +0000733 if (error.Success())
734 {
Greg Clayton98ca1e62012-02-24 20:59:25 +0000735 StateType state = eStateInvalid;
Greg Clayton0a8dcac2012-02-24 05:03:03 +0000736 if (launch_info.GetFlags().Test(eLaunchFlagStopAtEntry))
Greg Clayton98ca1e62012-02-24 20:59:25 +0000737 {
738 // If we are doing synchronous mode, then wait for the initial
739 // stop to happen, else, return and let the caller watch for
740 // the stop
741 if (synchronous_execution)
742 state = process_sp->WaitForProcessToStop (NULL);
743 // We we are stopping at the entry point, we can return now!
Greg Clayton0a8dcac2012-02-24 05:03:03 +0000744 return sb_process;
Greg Clayton98ca1e62012-02-24 20:59:25 +0000745 }
Greg Clayton0a8dcac2012-02-24 05:03:03 +0000746
747 // Make sure we are stopped at the entry
Greg Clayton98ca1e62012-02-24 20:59:25 +0000748 state = process_sp->WaitForProcessToStop (NULL);
Greg Clayton0a8dcac2012-02-24 05:03:03 +0000749 if (state == eStateStopped)
750 {
751 // resume the process to skip the entry point
752 error.SetError (process_sp->Resume());
753 if (error.Success())
754 {
755 // If we are doing synchronous mode, then wait for the
756 // process to stop yet again!
Greg Clayton98ca1e62012-02-24 20:59:25 +0000757 if (synchronous_execution)
Greg Clayton0a8dcac2012-02-24 05:03:03 +0000758 process_sp->WaitForProcessToStop (NULL);
759 }
760 }
761 }
762 }
763 else
764 {
765 error.SetErrorString ("unable to create lldb_private::Process");
766 }
767 }
768 else
769 {
770 error.SetErrorString ("SBTarget is invalid");
771 }
772
773 log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
774 if (log)
775 {
776 log->Printf ("SBTarget(%p)::Launch (...) => SBProceess(%p)",
777 target_sp.get(), process_sp.get());
778 }
779
780 return sb_process;
781}
782
783lldb::SBProcess
784SBTarget::Attach (SBAttachInfo &sb_attach_info, SBError& error)
785{
786 SBProcess sb_process;
787 ProcessSP process_sp;
788 TargetSP target_sp(GetSP());
789 if (target_sp)
790 {
791 Mutex::Locker api_locker (target_sp->GetAPIMutex());
792
793 StateType state = eStateInvalid;
794 process_sp = target_sp->GetProcessSP();
795 if (process_sp)
796 {
797 state = process_sp->GetState();
798
799 if (process_sp->IsAlive() && state != eStateConnected)
800 {
801 if (state == eStateAttaching)
802 error.SetErrorString ("process attach is in progress");
803 else
804 error.SetErrorString ("a process is already being debugged");
805 return sb_process;
806 }
807 }
808
809 if (state != eStateConnected)
810 process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener(), NULL, NULL);
811
812 if (process_sp)
813 {
Greg Clayton0a8dcac2012-02-24 05:03:03 +0000814 ProcessAttachInfo &attach_info = sb_attach_info.ref();
Han Ming Ong435c5ef2012-02-29 00:12:56 +0000815 lldb::pid_t attach_pid = attach_info.GetProcessID();
816 if (attach_pid != LLDB_INVALID_PROCESS_ID)
817 {
818 PlatformSP platform_sp = target_sp->GetPlatform();
819 ProcessInstanceInfo instance_info;
820 if (platform_sp->GetProcessInfo(attach_pid, instance_info))
821 {
822 attach_info.SetUserID(instance_info.GetEffectiveUserID());
823 }
824 }
Han Ming Ong94b4e9a2012-02-29 19:16:40 +0000825 error.SetError (process_sp->Attach (attach_info));
826 if (error.Success())
827 {
828 sb_process.SetSP (process_sp);
829 // If we are doing synchronous mode, then wait for the
830 // process to stop!
831 if (target_sp->GetDebugger().GetAsyncExecution () == false)
832 process_sp->WaitForProcessToStop (NULL);
833 }
Greg Clayton0a8dcac2012-02-24 05:03:03 +0000834 }
835 else
836 {
837 error.SetErrorString ("unable to create lldb_private::Process");
838 }
839 }
840 else
841 {
842 error.SetErrorString ("SBTarget is invalid");
843 }
844 return sb_process;
845}
846
847
Greg Claytond5b0b442011-12-02 02:10:57 +0000848#if defined(__APPLE__)
849
850lldb::SBProcess
851SBTarget::AttachToProcessWithID (SBListener &listener,
852 ::pid_t pid,
853 lldb::SBError& error)
854{
855 return AttachToProcessWithID (listener, (lldb::pid_t)pid, error);
856}
857
858#endif // #if defined(__APPLE__)
Greg Claytonc5f728c2010-10-06 22:10:17 +0000859
860lldb::SBProcess
Greg Claytond8c62532010-10-07 04:19:01 +0000861SBTarget::AttachToProcessWithID
Greg Claytonc5f728c2010-10-06 22:10:17 +0000862(
Greg Clayton271a5db2011-02-03 21:28:34 +0000863 SBListener &listener,
Greg Claytonc5f728c2010-10-06 22:10:17 +0000864 lldb::pid_t pid,// The process ID to attach to
865 SBError& error // An error explaining what went wrong if attach fails
866)
867{
868 SBProcess sb_process;
Greg Clayton334d33a2012-01-30 07:41:31 +0000869 ProcessSP process_sp;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000870 TargetSP target_sp(GetSP());
871 if (target_sp)
Greg Claytonc5f728c2010-10-06 22:10:17 +0000872 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000873 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytonde1dd812011-06-24 03:21:43 +0000874
875 StateType state = eStateInvalid;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000876 process_sp = target_sp->GetProcessSP();
Greg Clayton334d33a2012-01-30 07:41:31 +0000877 if (process_sp)
Greg Claytonde1dd812011-06-24 03:21:43 +0000878 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000879 state = process_sp->GetState();
Greg Claytonde1dd812011-06-24 03:21:43 +0000880
Greg Clayton334d33a2012-01-30 07:41:31 +0000881 if (process_sp->IsAlive() && state != eStateConnected)
Greg Claytonde1dd812011-06-24 03:21:43 +0000882 {
883 if (state == eStateAttaching)
884 error.SetErrorString ("process attach is in progress");
885 else
886 error.SetErrorString ("a process is already being debugged");
Greg Claytonde1dd812011-06-24 03:21:43 +0000887 return sb_process;
888 }
889 }
890
891 if (state == eStateConnected)
892 {
893 // If we are already connected, then we have already specified the
894 // listener, so if a valid listener is supplied, we need to error out
895 // to let the client know.
896 if (listener.IsValid())
897 {
898 error.SetErrorString ("process is connected and already has a listener, pass empty listener");
Greg Claytonde1dd812011-06-24 03:21:43 +0000899 return sb_process;
900 }
901 }
Greg Clayton271a5db2011-02-03 21:28:34 +0000902 else
Greg Claytonde1dd812011-06-24 03:21:43 +0000903 {
904 if (listener.IsValid())
Greg Clayton46c9a352012-02-09 06:16:32 +0000905 process_sp = target_sp->CreateProcess (listener.ref(), NULL, NULL);
Greg Claytonde1dd812011-06-24 03:21:43 +0000906 else
Greg Clayton46c9a352012-02-09 06:16:32 +0000907 process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener(), NULL, NULL);
Greg Claytonde1dd812011-06-24 03:21:43 +0000908 }
Greg Clayton334d33a2012-01-30 07:41:31 +0000909 if (process_sp)
Greg Claytonc5f728c2010-10-06 22:10:17 +0000910 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000911 sb_process.SetSP (process_sp);
912
Greg Clayton527154d2011-11-15 03:53:30 +0000913 ProcessAttachInfo attach_info;
914 attach_info.SetProcessID (pid);
Han Ming Ongd1040dd2012-02-25 01:07:38 +0000915
916 PlatformSP platform_sp = target_sp->GetPlatform();
917 ProcessInstanceInfo instance_info;
918 if (platform_sp->GetProcessInfo(pid, instance_info))
919 {
920 attach_info.SetUserID(instance_info.GetEffectiveUserID());
Han Ming Ongd1040dd2012-02-25 01:07:38 +0000921 }
Greg Clayton334d33a2012-01-30 07:41:31 +0000922 error.SetError (process_sp->Attach (attach_info));
Johnny Chen535960e2011-06-17 00:51:15 +0000923 // If we are doing synchronous mode, then wait for the
924 // process to stop!
Greg Clayton0416bdf2012-01-30 09:04:36 +0000925 if (target_sp->GetDebugger().GetAsyncExecution () == false)
Greg Clayton334d33a2012-01-30 07:41:31 +0000926 process_sp->WaitForProcessToStop (NULL);
Greg Claytonc5f728c2010-10-06 22:10:17 +0000927 }
928 else
929 {
930 error.SetErrorString ("unable to create lldb_private::Process");
931 }
932 }
933 else
934 {
935 error.SetErrorString ("SBTarget is invalid");
936 }
937 return sb_process;
938
939}
940
941lldb::SBProcess
Greg Claytond8c62532010-10-07 04:19:01 +0000942SBTarget::AttachToProcessWithName
Greg Claytonc5f728c2010-10-06 22:10:17 +0000943(
Greg Clayton271a5db2011-02-03 21:28:34 +0000944 SBListener &listener,
Greg Claytonc5f728c2010-10-06 22:10:17 +0000945 const char *name, // basename of process to attach to
946 bool wait_for, // if true wait for a new instance of "name" to be launched
947 SBError& error // An error explaining what went wrong if attach fails
948)
949{
950 SBProcess sb_process;
Greg Clayton334d33a2012-01-30 07:41:31 +0000951 ProcessSP process_sp;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000952 TargetSP target_sp(GetSP());
953 if (name && target_sp)
Greg Claytonc5f728c2010-10-06 22:10:17 +0000954 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000955 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytonbdcda462010-12-20 20:49:23 +0000956
Greg Claytonde1dd812011-06-24 03:21:43 +0000957 StateType state = eStateInvalid;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000958 process_sp = target_sp->GetProcessSP();
Greg Clayton334d33a2012-01-30 07:41:31 +0000959 if (process_sp)
Greg Claytonde1dd812011-06-24 03:21:43 +0000960 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000961 state = process_sp->GetState();
Greg Claytonde1dd812011-06-24 03:21:43 +0000962
Greg Clayton334d33a2012-01-30 07:41:31 +0000963 if (process_sp->IsAlive() && state != eStateConnected)
Greg Claytonde1dd812011-06-24 03:21:43 +0000964 {
965 if (state == eStateAttaching)
966 error.SetErrorString ("process attach is in progress");
967 else
968 error.SetErrorString ("a process is already being debugged");
Greg Claytonde1dd812011-06-24 03:21:43 +0000969 return sb_process;
970 }
971 }
972
973 if (state == eStateConnected)
974 {
975 // If we are already connected, then we have already specified the
976 // listener, so if a valid listener is supplied, we need to error out
977 // to let the client know.
978 if (listener.IsValid())
979 {
980 error.SetErrorString ("process is connected and already has a listener, pass empty listener");
Greg Claytonde1dd812011-06-24 03:21:43 +0000981 return sb_process;
982 }
983 }
Greg Clayton271a5db2011-02-03 21:28:34 +0000984 else
Greg Claytonde1dd812011-06-24 03:21:43 +0000985 {
986 if (listener.IsValid())
Greg Clayton46c9a352012-02-09 06:16:32 +0000987 process_sp = target_sp->CreateProcess (listener.ref(), NULL, NULL);
Greg Claytonde1dd812011-06-24 03:21:43 +0000988 else
Greg Clayton46c9a352012-02-09 06:16:32 +0000989 process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener(), NULL, NULL);
Greg Claytonde1dd812011-06-24 03:21:43 +0000990 }
Greg Claytonc5f728c2010-10-06 22:10:17 +0000991
Greg Clayton334d33a2012-01-30 07:41:31 +0000992 if (process_sp)
Greg Claytonc5f728c2010-10-06 22:10:17 +0000993 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000994 sb_process.SetSP (process_sp);
Greg Clayton527154d2011-11-15 03:53:30 +0000995 ProcessAttachInfo attach_info;
996 attach_info.GetExecutableFile().SetFile(name, false);
997 attach_info.SetWaitForLaunch(wait_for);
Greg Clayton334d33a2012-01-30 07:41:31 +0000998 error.SetError (process_sp->Attach (attach_info));
Johnny Chen58d02ff2011-06-17 19:21:30 +0000999 // If we are doing synchronous mode, then wait for the
1000 // process to stop!
Greg Clayton0416bdf2012-01-30 09:04:36 +00001001 if (target_sp->GetDebugger().GetAsyncExecution () == false)
Greg Clayton334d33a2012-01-30 07:41:31 +00001002 process_sp->WaitForProcessToStop (NULL);
Greg Claytonc5f728c2010-10-06 22:10:17 +00001003 }
1004 else
1005 {
1006 error.SetErrorString ("unable to create lldb_private::Process");
1007 }
1008 }
1009 else
1010 {
1011 error.SetErrorString ("SBTarget is invalid");
1012 }
1013 return sb_process;
1014
1015}
1016
James McIlree38093402011-03-04 00:31:13 +00001017lldb::SBProcess
1018SBTarget::ConnectRemote
1019(
1020 SBListener &listener,
1021 const char *url,
1022 const char *plugin_name,
1023 SBError& error
1024)
1025{
1026 SBProcess sb_process;
Greg Clayton334d33a2012-01-30 07:41:31 +00001027 ProcessSP process_sp;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001028 TargetSP target_sp(GetSP());
1029 if (target_sp)
James McIlree38093402011-03-04 00:31:13 +00001030 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001031 Mutex::Locker api_locker (target_sp->GetAPIMutex());
James McIlree38093402011-03-04 00:31:13 +00001032 if (listener.IsValid())
Greg Clayton46c9a352012-02-09 06:16:32 +00001033 process_sp = target_sp->CreateProcess (listener.ref(), plugin_name, NULL);
James McIlree38093402011-03-04 00:31:13 +00001034 else
Greg Clayton46c9a352012-02-09 06:16:32 +00001035 process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener(), plugin_name, NULL);
James McIlree38093402011-03-04 00:31:13 +00001036
1037
Greg Clayton334d33a2012-01-30 07:41:31 +00001038 if (process_sp)
James McIlree38093402011-03-04 00:31:13 +00001039 {
Greg Clayton334d33a2012-01-30 07:41:31 +00001040 sb_process.SetSP (process_sp);
1041 error.SetError (process_sp->ConnectRemote (url));
James McIlree38093402011-03-04 00:31:13 +00001042 }
1043 else
1044 {
1045 error.SetErrorString ("unable to create lldb_private::Process");
1046 }
1047 }
1048 else
1049 {
1050 error.SetErrorString ("SBTarget is invalid");
1051 }
1052 return sb_process;
1053}
1054
Chris Lattner24943d22010-06-08 16:52:24 +00001055SBFileSpec
1056SBTarget::GetExecutable ()
1057{
Caroline Tice7826c882010-10-26 03:11:13 +00001058
Chris Lattner24943d22010-06-08 16:52:24 +00001059 SBFileSpec exe_file_spec;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001060 TargetSP target_sp(GetSP());
1061 if (target_sp)
Chris Lattner24943d22010-06-08 16:52:24 +00001062 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001063 Module *exe_module = target_sp->GetExecutableModulePointer();
Greg Clayton5beb99d2011-08-11 02:48:45 +00001064 if (exe_module)
1065 exe_file_spec.SetFileSpec (exe_module->GetFileSpec());
Chris Lattner24943d22010-06-08 16:52:24 +00001066 }
Caroline Tice7826c882010-10-26 03:11:13 +00001067
Greg Claytone005f2c2010-11-06 01:53:30 +00001068 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001069 if (log)
1070 {
Greg Clayton49ce6822010-10-31 03:01:06 +00001071 log->Printf ("SBTarget(%p)::GetExecutable () => SBFileSpec(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +00001072 target_sp.get(), exe_file_spec.get());
Caroline Tice7826c882010-10-26 03:11:13 +00001073 }
1074
Chris Lattner24943d22010-06-08 16:52:24 +00001075 return exe_file_spec;
1076}
1077
Chris Lattner24943d22010-06-08 16:52:24 +00001078bool
Chris Lattner24943d22010-06-08 16:52:24 +00001079SBTarget::operator == (const SBTarget &rhs) const
1080{
Greg Clayton63094e02010-06-23 01:19:29 +00001081 return m_opaque_sp.get() == rhs.m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +00001082}
1083
1084bool
1085SBTarget::operator != (const SBTarget &rhs) const
1086{
Greg Clayton63094e02010-06-23 01:19:29 +00001087 return m_opaque_sp.get() != rhs.m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +00001088}
1089
Greg Clayton334d33a2012-01-30 07:41:31 +00001090lldb::TargetSP
1091SBTarget::GetSP () const
Greg Clayton15afa9f2011-10-01 02:59:24 +00001092{
1093 return m_opaque_sp;
1094}
1095
Greg Clayton63094e02010-06-23 01:19:29 +00001096void
Greg Clayton334d33a2012-01-30 07:41:31 +00001097SBTarget::SetSP (const lldb::TargetSP& target_sp)
Greg Clayton63094e02010-06-23 01:19:29 +00001098{
1099 m_opaque_sp = target_sp;
Chris Lattner24943d22010-06-08 16:52:24 +00001100}
1101
Greg Claytona3955062011-07-22 16:46:35 +00001102lldb::SBAddress
1103SBTarget::ResolveLoadAddress (lldb::addr_t vm_addr)
Greg Claytonea49cc72010-12-12 19:25:26 +00001104{
Greg Claytona3955062011-07-22 16:46:35 +00001105 lldb::SBAddress sb_addr;
1106 Address &addr = sb_addr.ref();
Greg Clayton0416bdf2012-01-30 09:04:36 +00001107 TargetSP target_sp(GetSP());
1108 if (target_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +00001109 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001110 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1111 if (target_sp->GetSectionLoadList().ResolveLoadAddress (vm_addr, addr))
Greg Claytona3955062011-07-22 16:46:35 +00001112 return sb_addr;
Greg Claytonbdcda462010-12-20 20:49:23 +00001113 }
Greg Claytonea49cc72010-12-12 19:25:26 +00001114
Greg Claytona3955062011-07-22 16:46:35 +00001115 // We have a load address that isn't in a section, just return an address
1116 // with the offset filled in (the address) and the section set to NULL
Greg Clayton3508c382012-02-24 01:59:29 +00001117 addr.SetRawAddress(vm_addr);
Greg Claytona3955062011-07-22 16:46:35 +00001118 return sb_addr;
Greg Claytonea49cc72010-12-12 19:25:26 +00001119}
1120
Greg Claytonafb81862011-03-02 21:34:46 +00001121SBSymbolContext
1122SBTarget::ResolveSymbolContextForAddress (const SBAddress& addr, uint32_t resolve_scope)
1123{
1124 SBSymbolContext sc;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001125 if (addr.IsValid())
1126 {
1127 TargetSP target_sp(GetSP());
1128 if (target_sp)
1129 target_sp->GetImages().ResolveSymbolContextForAddress (addr.ref(), resolve_scope, sc.ref());
1130 }
Greg Claytonafb81862011-03-02 21:34:46 +00001131 return sc;
1132}
1133
1134
Chris Lattner24943d22010-06-08 16:52:24 +00001135SBBreakpoint
1136SBTarget::BreakpointCreateByLocation (const char *file, uint32_t line)
1137{
Greg Claytond6d806c2010-11-08 00:28:40 +00001138 return SBBreakpoint(BreakpointCreateByLocation (SBFileSpec (file, false), line));
Chris Lattner24943d22010-06-08 16:52:24 +00001139}
1140
1141SBBreakpoint
1142SBTarget::BreakpointCreateByLocation (const SBFileSpec &sb_file_spec, uint32_t line)
1143{
Greg Claytone005f2c2010-11-06 01:53:30 +00001144 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001145
Chris Lattner24943d22010-06-08 16:52:24 +00001146 SBBreakpoint sb_bp;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001147 TargetSP target_sp(GetSP());
1148 if (target_sp && line != 0)
Greg Claytonbdcda462010-12-20 20:49:23 +00001149 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001150 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1151 *sb_bp = target_sp->CreateBreakpoint (NULL, *sb_file_spec, line, true, false);
Greg Claytonbdcda462010-12-20 20:49:23 +00001152 }
Caroline Tice7826c882010-10-26 03:11:13 +00001153
1154 if (log)
1155 {
1156 SBStream sstr;
1157 sb_bp.GetDescription (sstr);
Greg Clayton49ce6822010-10-31 03:01:06 +00001158 char path[PATH_MAX];
1159 sb_file_spec->GetPath (path, sizeof(path));
1160 log->Printf ("SBTarget(%p)::BreakpointCreateByLocation ( %s:%u ) => SBBreakpoint(%p): %s",
Greg Clayton0416bdf2012-01-30 09:04:36 +00001161 target_sp.get(),
Greg Clayton49ce6822010-10-31 03:01:06 +00001162 path,
Greg Claytona66ba462010-10-30 04:51:46 +00001163 line,
Greg Clayton49ce6822010-10-31 03:01:06 +00001164 sb_bp.get(),
Caroline Tice7826c882010-10-26 03:11:13 +00001165 sstr.GetData());
1166 }
1167
Chris Lattner24943d22010-06-08 16:52:24 +00001168 return sb_bp;
1169}
1170
1171SBBreakpoint
1172SBTarget::BreakpointCreateByName (const char *symbol_name, const char *module_name)
1173{
Greg Claytone005f2c2010-11-06 01:53:30 +00001174 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001175
Chris Lattner24943d22010-06-08 16:52:24 +00001176 SBBreakpoint sb_bp;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001177 TargetSP target_sp(GetSP());
1178 if (target_sp.get())
Chris Lattner24943d22010-06-08 16:52:24 +00001179 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001180 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Chris Lattner24943d22010-06-08 16:52:24 +00001181 if (module_name && module_name[0])
1182 {
Jim Ingham03c8ee52011-09-21 01:17:13 +00001183 FileSpecList module_spec_list;
1184 module_spec_list.Append (FileSpec (module_name, false));
Greg Clayton0416bdf2012-01-30 09:04:36 +00001185 *sb_bp = target_sp->CreateBreakpoint (&module_spec_list, NULL, symbol_name, eFunctionNameTypeAuto, false);
Chris Lattner24943d22010-06-08 16:52:24 +00001186 }
1187 else
1188 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001189 *sb_bp = target_sp->CreateBreakpoint (NULL, NULL, symbol_name, eFunctionNameTypeAuto, false);
Chris Lattner24943d22010-06-08 16:52:24 +00001190 }
1191 }
Caroline Tice7826c882010-10-26 03:11:13 +00001192
1193 if (log)
1194 {
Greg Clayton49ce6822010-10-31 03:01:06 +00001195 log->Printf ("SBTarget(%p)::BreakpointCreateByName (symbol=\"%s\", module=\"%s\") => SBBreakpoint(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +00001196 target_sp.get(), symbol_name, module_name, sb_bp.get());
Caroline Tice7826c882010-10-26 03:11:13 +00001197 }
1198
Chris Lattner24943d22010-06-08 16:52:24 +00001199 return sb_bp;
1200}
1201
Jim Inghamd6d47972011-09-23 00:54:11 +00001202lldb::SBBreakpoint
1203SBTarget::BreakpointCreateByName (const char *symbol_name,
1204 const SBFileSpecList &module_list,
1205 const SBFileSpecList &comp_unit_list)
1206{
Jim Ingham1fb8a2d2011-10-11 01:18:55 +00001207 uint32_t name_type_mask = eFunctionNameTypeAuto;
1208 return BreakpointCreateByName (symbol_name, name_type_mask, module_list, comp_unit_list);
1209}
1210
1211lldb::SBBreakpoint
1212SBTarget::BreakpointCreateByName (const char *symbol_name,
1213 uint32_t name_type_mask,
1214 const SBFileSpecList &module_list,
1215 const SBFileSpecList &comp_unit_list)
1216{
Jim Inghamd6d47972011-09-23 00:54:11 +00001217 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1218
1219 SBBreakpoint sb_bp;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001220 TargetSP target_sp(GetSP());
1221 if (target_sp && symbol_name && symbol_name[0])
Jim Inghamd6d47972011-09-23 00:54:11 +00001222 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001223 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1224 *sb_bp = target_sp->CreateBreakpoint (module_list.get(),
Jim Inghamd6d47972011-09-23 00:54:11 +00001225 comp_unit_list.get(),
1226 symbol_name,
Jim Ingham1fb8a2d2011-10-11 01:18:55 +00001227 name_type_mask,
Jim Inghamd6d47972011-09-23 00:54:11 +00001228 false);
1229 }
1230
1231 if (log)
1232 {
Jim Ingham1fb8a2d2011-10-11 01:18:55 +00001233 log->Printf ("SBTarget(%p)::BreakpointCreateByName (symbol=\"%s\", name_type: %d) => SBBreakpoint(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +00001234 target_sp.get(), symbol_name, name_type_mask, sb_bp.get());
Jim Inghamd6d47972011-09-23 00:54:11 +00001235 }
1236
1237 return sb_bp;
1238}
1239
1240
Chris Lattner24943d22010-06-08 16:52:24 +00001241SBBreakpoint
1242SBTarget::BreakpointCreateByRegex (const char *symbol_name_regex, const char *module_name)
1243{
Greg Claytone005f2c2010-11-06 01:53:30 +00001244 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001245
Chris Lattner24943d22010-06-08 16:52:24 +00001246 SBBreakpoint sb_bp;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001247 TargetSP target_sp(GetSP());
1248 if (target_sp && symbol_name_regex && symbol_name_regex[0])
Chris Lattner24943d22010-06-08 16:52:24 +00001249 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001250 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Chris Lattner24943d22010-06-08 16:52:24 +00001251 RegularExpression regexp(symbol_name_regex);
1252
1253 if (module_name && module_name[0])
1254 {
Jim Ingham03c8ee52011-09-21 01:17:13 +00001255 FileSpecList module_spec_list;
1256 module_spec_list.Append (FileSpec (module_name, false));
Chris Lattner24943d22010-06-08 16:52:24 +00001257
Greg Clayton0416bdf2012-01-30 09:04:36 +00001258 *sb_bp = target_sp->CreateFuncRegexBreakpoint (&module_spec_list, NULL, regexp, false);
Chris Lattner24943d22010-06-08 16:52:24 +00001259 }
1260 else
1261 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001262 *sb_bp = target_sp->CreateFuncRegexBreakpoint (NULL, NULL, regexp, false);
Chris Lattner24943d22010-06-08 16:52:24 +00001263 }
1264 }
Caroline Tice7826c882010-10-26 03:11:13 +00001265
1266 if (log)
1267 {
Greg Clayton49ce6822010-10-31 03:01:06 +00001268 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (symbol_regex=\"%s\", module_name=\"%s\") => SBBreakpoint(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +00001269 target_sp.get(), symbol_name_regex, module_name, sb_bp.get());
Caroline Tice7826c882010-10-26 03:11:13 +00001270 }
1271
Chris Lattner24943d22010-06-08 16:52:24 +00001272 return sb_bp;
1273}
1274
Jim Inghamd6d47972011-09-23 00:54:11 +00001275lldb::SBBreakpoint
1276SBTarget::BreakpointCreateByRegex (const char *symbol_name_regex,
1277 const SBFileSpecList &module_list,
1278 const SBFileSpecList &comp_unit_list)
1279{
1280 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Chris Lattner24943d22010-06-08 16:52:24 +00001281
Jim Inghamd6d47972011-09-23 00:54:11 +00001282 SBBreakpoint sb_bp;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001283 TargetSP target_sp(GetSP());
1284 if (target_sp && symbol_name_regex && symbol_name_regex[0])
Jim Inghamd6d47972011-09-23 00:54:11 +00001285 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001286 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Jim Inghamd6d47972011-09-23 00:54:11 +00001287 RegularExpression regexp(symbol_name_regex);
1288
Greg Clayton0416bdf2012-01-30 09:04:36 +00001289 *sb_bp = target_sp->CreateFuncRegexBreakpoint (module_list.get(), comp_unit_list.get(), regexp, false);
Jim Inghamd6d47972011-09-23 00:54:11 +00001290 }
1291
1292 if (log)
1293 {
1294 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (symbol_regex=\"%s\") => SBBreakpoint(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +00001295 target_sp.get(), symbol_name_regex, sb_bp.get());
Jim Inghamd6d47972011-09-23 00:54:11 +00001296 }
1297
1298 return sb_bp;
1299}
Chris Lattner24943d22010-06-08 16:52:24 +00001300
1301SBBreakpoint
1302SBTarget::BreakpointCreateByAddress (addr_t address)
1303{
Greg Claytone005f2c2010-11-06 01:53:30 +00001304 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001305
Chris Lattner24943d22010-06-08 16:52:24 +00001306 SBBreakpoint sb_bp;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001307 TargetSP target_sp(GetSP());
1308 if (target_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +00001309 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001310 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1311 *sb_bp = target_sp->CreateBreakpoint (address, false);
Greg Claytonbdcda462010-12-20 20:49:23 +00001312 }
Caroline Tice7826c882010-10-26 03:11:13 +00001313
1314 if (log)
1315 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001316 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 +00001317 }
1318
Chris Lattner24943d22010-06-08 16:52:24 +00001319 return sb_bp;
1320}
1321
Jim Ingham03c8ee52011-09-21 01:17:13 +00001322lldb::SBBreakpoint
1323SBTarget::BreakpointCreateBySourceRegex (const char *source_regex, const lldb::SBFileSpec &source_file, const char *module_name)
1324{
1325 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1326
1327 SBBreakpoint sb_bp;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001328 TargetSP target_sp(GetSP());
1329 if (target_sp && source_regex && source_regex[0])
Jim Ingham03c8ee52011-09-21 01:17:13 +00001330 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001331 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Jim Ingham03c8ee52011-09-21 01:17:13 +00001332 RegularExpression regexp(source_regex);
Jim Inghamd6d47972011-09-23 00:54:11 +00001333 FileSpecList source_file_spec_list;
1334 source_file_spec_list.Append (source_file.ref());
Jim Ingham03c8ee52011-09-21 01:17:13 +00001335
1336 if (module_name && module_name[0])
1337 {
1338 FileSpecList module_spec_list;
1339 module_spec_list.Append (FileSpec (module_name, false));
1340
Greg Clayton0416bdf2012-01-30 09:04:36 +00001341 *sb_bp = target_sp->CreateSourceRegexBreakpoint (&module_spec_list, &source_file_spec_list, regexp, false);
Jim Ingham03c8ee52011-09-21 01:17:13 +00001342 }
1343 else
1344 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001345 *sb_bp = target_sp->CreateSourceRegexBreakpoint (NULL, &source_file_spec_list, regexp, false);
Jim Ingham03c8ee52011-09-21 01:17:13 +00001346 }
1347 }
1348
1349 if (log)
1350 {
1351 char path[PATH_MAX];
1352 source_file->GetPath (path, sizeof(path));
1353 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (source_regex=\"%s\", file=\"%s\", module_name=\"%s\") => SBBreakpoint(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +00001354 target_sp.get(), source_regex, path, module_name, sb_bp.get());
Jim Ingham03c8ee52011-09-21 01:17:13 +00001355 }
1356
1357 return sb_bp;
1358}
1359
Jim Inghamd6d47972011-09-23 00:54:11 +00001360lldb::SBBreakpoint
1361SBTarget::BreakpointCreateBySourceRegex (const char *source_regex,
1362 const SBFileSpecList &module_list,
1363 const lldb::SBFileSpecList &source_file_list)
1364{
1365 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1366
1367 SBBreakpoint sb_bp;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001368 TargetSP target_sp(GetSP());
1369 if (target_sp && source_regex && source_regex[0])
Jim Inghamd6d47972011-09-23 00:54:11 +00001370 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001371 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Jim Inghamd6d47972011-09-23 00:54:11 +00001372 RegularExpression regexp(source_regex);
Greg Clayton0416bdf2012-01-30 09:04:36 +00001373 *sb_bp = target_sp->CreateSourceRegexBreakpoint (module_list.get(), source_file_list.get(), regexp, false);
Jim Inghamd6d47972011-09-23 00:54:11 +00001374 }
1375
1376 if (log)
1377 {
1378 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (source_regex=\"%s\") => SBBreakpoint(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +00001379 target_sp.get(), source_regex, sb_bp.get());
Jim Inghamd6d47972011-09-23 00:54:11 +00001380 }
1381
1382 return sb_bp;
1383}
Jim Ingham03c8ee52011-09-21 01:17:13 +00001384
Greg Claytonc7f5d5c2010-07-23 23:33:17 +00001385uint32_t
1386SBTarget::GetNumBreakpoints () const
1387{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001388 TargetSP target_sp(GetSP());
1389 if (target_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +00001390 {
1391 // The breakpoint list is thread safe, no need to lock
Greg Clayton0416bdf2012-01-30 09:04:36 +00001392 return target_sp->GetBreakpointList().GetSize();
Greg Claytonbdcda462010-12-20 20:49:23 +00001393 }
Greg Claytonc7f5d5c2010-07-23 23:33:17 +00001394 return 0;
1395}
1396
1397SBBreakpoint
1398SBTarget::GetBreakpointAtIndex (uint32_t idx) const
1399{
1400 SBBreakpoint sb_breakpoint;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001401 TargetSP target_sp(GetSP());
1402 if (target_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +00001403 {
1404 // The breakpoint list is thread safe, no need to lock
Greg Clayton0416bdf2012-01-30 09:04:36 +00001405 *sb_breakpoint = target_sp->GetBreakpointList().GetBreakpointAtIndex(idx);
Greg Claytonbdcda462010-12-20 20:49:23 +00001406 }
Greg Claytonc7f5d5c2010-07-23 23:33:17 +00001407 return sb_breakpoint;
1408}
Chris Lattner24943d22010-06-08 16:52:24 +00001409
1410bool
1411SBTarget::BreakpointDelete (break_id_t bp_id)
1412{
Greg Claytone005f2c2010-11-06 01:53:30 +00001413 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001414
Caroline Tice7826c882010-10-26 03:11:13 +00001415 bool result = false;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001416 TargetSP target_sp(GetSP());
1417 if (target_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +00001418 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001419 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1420 result = target_sp->RemoveBreakpointByID (bp_id);
Greg Claytonbdcda462010-12-20 20:49:23 +00001421 }
Caroline Tice7826c882010-10-26 03:11:13 +00001422
1423 if (log)
1424 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001425 log->Printf ("SBTarget(%p)::BreakpointDelete (bp_id=%d) => %i", target_sp.get(), (uint32_t) bp_id, result);
Caroline Tice7826c882010-10-26 03:11:13 +00001426 }
1427
1428 return result;
Chris Lattner24943d22010-06-08 16:52:24 +00001429}
1430
Johnny Chen096c2932011-09-26 22:40:50 +00001431SBBreakpoint
1432SBTarget::FindBreakpointByID (break_id_t bp_id)
1433{
1434 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1435
1436 SBBreakpoint sb_breakpoint;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001437 TargetSP target_sp(GetSP());
1438 if (target_sp && bp_id != LLDB_INVALID_BREAK_ID)
Johnny Chen096c2932011-09-26 22:40:50 +00001439 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001440 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1441 *sb_breakpoint = target_sp->GetBreakpointByID (bp_id);
Johnny Chen096c2932011-09-26 22:40:50 +00001442 }
1443
1444 if (log)
1445 {
1446 log->Printf ("SBTarget(%p)::FindBreakpointByID (bp_id=%d) => SBBreakpoint(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +00001447 target_sp.get(), (uint32_t) bp_id, sb_breakpoint.get());
Johnny Chen096c2932011-09-26 22:40:50 +00001448 }
1449
1450 return sb_breakpoint;
1451}
1452
Chris Lattner24943d22010-06-08 16:52:24 +00001453bool
1454SBTarget::EnableAllBreakpoints ()
1455{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001456 TargetSP target_sp(GetSP());
1457 if (target_sp)
Chris Lattner24943d22010-06-08 16:52:24 +00001458 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001459 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1460 target_sp->EnableAllBreakpoints ();
Chris Lattner24943d22010-06-08 16:52:24 +00001461 return true;
1462 }
1463 return false;
1464}
1465
1466bool
1467SBTarget::DisableAllBreakpoints ()
1468{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001469 TargetSP target_sp(GetSP());
1470 if (target_sp)
Chris Lattner24943d22010-06-08 16:52:24 +00001471 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001472 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1473 target_sp->DisableAllBreakpoints ();
Chris Lattner24943d22010-06-08 16:52:24 +00001474 return true;
1475 }
1476 return false;
1477}
1478
1479bool
1480SBTarget::DeleteAllBreakpoints ()
1481{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001482 TargetSP target_sp(GetSP());
1483 if (target_sp)
Chris Lattner24943d22010-06-08 16:52:24 +00001484 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001485 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1486 target_sp->RemoveAllBreakpoints ();
Chris Lattner24943d22010-06-08 16:52:24 +00001487 return true;
1488 }
1489 return false;
1490}
1491
Johnny Chen096c2932011-09-26 22:40:50 +00001492uint32_t
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001493SBTarget::GetNumWatchpoints () const
Johnny Chen096c2932011-09-26 22:40:50 +00001494{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001495 TargetSP target_sp(GetSP());
1496 if (target_sp)
Johnny Chen096c2932011-09-26 22:40:50 +00001497 {
Johnny Chenecd4feb2011-10-14 00:42:25 +00001498 // The watchpoint list is thread safe, no need to lock
Greg Clayton0416bdf2012-01-30 09:04:36 +00001499 return target_sp->GetWatchpointList().GetSize();
Johnny Chen096c2932011-09-26 22:40:50 +00001500 }
1501 return 0;
1502}
1503
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001504SBWatchpoint
1505SBTarget::GetWatchpointAtIndex (uint32_t idx) const
Johnny Chen5eb54bb2011-09-27 20:29:45 +00001506{
Johnny Chenecd4feb2011-10-14 00:42:25 +00001507 SBWatchpoint sb_watchpoint;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001508 TargetSP target_sp(GetSP());
1509 if (target_sp)
Johnny Chen096c2932011-09-26 22:40:50 +00001510 {
Johnny Chenecd4feb2011-10-14 00:42:25 +00001511 // The watchpoint list is thread safe, no need to lock
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001512 sb_watchpoint.SetSP (target_sp->GetWatchpointList().GetByIndex(idx));
Johnny Chen096c2932011-09-26 22:40:50 +00001513 }
Johnny Chenecd4feb2011-10-14 00:42:25 +00001514 return sb_watchpoint;
Johnny Chen096c2932011-09-26 22:40:50 +00001515}
1516
1517bool
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001518SBTarget::DeleteWatchpoint (watch_id_t wp_id)
Johnny Chen096c2932011-09-26 22:40:50 +00001519{
1520 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1521
1522 bool result = false;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001523 TargetSP target_sp(GetSP());
1524 if (target_sp)
Johnny Chen096c2932011-09-26 22:40:50 +00001525 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001526 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1527 result = target_sp->RemoveWatchpointByID (wp_id);
Johnny Chen096c2932011-09-26 22:40:50 +00001528 }
1529
1530 if (log)
1531 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001532 log->Printf ("SBTarget(%p)::WatchpointDelete (wp_id=%d) => %i", target_sp.get(), (uint32_t) wp_id, result);
Johnny Chen096c2932011-09-26 22:40:50 +00001533 }
1534
1535 return result;
1536}
1537
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001538SBWatchpoint
1539SBTarget::FindWatchpointByID (lldb::watch_id_t wp_id)
Johnny Chen096c2932011-09-26 22:40:50 +00001540{
1541 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1542
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001543 SBWatchpoint sb_watchpoint;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001544 lldb::WatchpointSP watchpoint_sp;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001545 TargetSP target_sp(GetSP());
1546 if (target_sp && wp_id != LLDB_INVALID_WATCH_ID)
Johnny Chen096c2932011-09-26 22:40:50 +00001547 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001548 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001549 watchpoint_sp = target_sp->GetWatchpointList().FindByID(wp_id);
1550 sb_watchpoint.SetSP (watchpoint_sp);
Johnny Chen096c2932011-09-26 22:40:50 +00001551 }
1552
1553 if (log)
1554 {
Johnny Chenecd4feb2011-10-14 00:42:25 +00001555 log->Printf ("SBTarget(%p)::FindWatchpointByID (bp_id=%d) => SBWatchpoint(%p)",
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001556 target_sp.get(), (uint32_t) wp_id, watchpoint_sp.get());
Johnny Chen096c2932011-09-26 22:40:50 +00001557 }
1558
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001559 return sb_watchpoint;
1560}
1561
1562lldb::SBWatchpoint
1563SBTarget::WatchAddress (lldb::addr_t addr, size_t size, bool read, bool write)
1564{
1565 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1566
1567 SBWatchpoint sb_watchpoint;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001568 lldb::WatchpointSP watchpoint_sp;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001569 TargetSP target_sp(GetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001570 if (target_sp && (read || write) && addr != LLDB_INVALID_ADDRESS && size > 0)
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001571 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001572 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001573 uint32_t watch_type = 0;
1574 if (read)
1575 watch_type |= LLDB_WATCH_TYPE_READ;
1576 if (write)
1577 watch_type |= LLDB_WATCH_TYPE_WRITE;
1578 watchpoint_sp = target_sp->CreateWatchpoint(addr, size, watch_type);
1579 sb_watchpoint.SetSP (watchpoint_sp);
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001580 }
1581
1582 if (log)
1583 {
1584 log->Printf ("SBTarget(%p)::WatchAddress (addr=0x%llx, 0x%u) => SBWatchpoint(%p)",
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001585 target_sp.get(), addr, (uint32_t) size, watchpoint_sp.get());
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001586 }
1587
1588 return sb_watchpoint;
Johnny Chen096c2932011-09-26 22:40:50 +00001589}
1590
1591bool
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001592SBTarget::EnableAllWatchpoints ()
Johnny Chen096c2932011-09-26 22:40:50 +00001593{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001594 TargetSP target_sp(GetSP());
1595 if (target_sp)
Johnny Chen096c2932011-09-26 22:40:50 +00001596 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001597 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1598 target_sp->EnableAllWatchpoints ();
Johnny Chen096c2932011-09-26 22:40:50 +00001599 return true;
1600 }
1601 return false;
1602}
1603
1604bool
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001605SBTarget::DisableAllWatchpoints ()
Johnny Chen096c2932011-09-26 22:40:50 +00001606{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001607 TargetSP target_sp(GetSP());
1608 if (target_sp)
Johnny Chen096c2932011-09-26 22:40:50 +00001609 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001610 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1611 target_sp->DisableAllWatchpoints ();
Johnny Chen096c2932011-09-26 22:40:50 +00001612 return true;
1613 }
1614 return false;
1615}
1616
1617bool
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001618SBTarget::DeleteAllWatchpoints ()
Johnny Chen096c2932011-09-26 22:40:50 +00001619{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001620 TargetSP target_sp(GetSP());
1621 if (target_sp)
Johnny Chen096c2932011-09-26 22:40:50 +00001622 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001623 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1624 target_sp->RemoveAllWatchpoints ();
Johnny Chen096c2932011-09-26 22:40:50 +00001625 return true;
1626 }
1627 return false;
1628}
1629
Chris Lattner24943d22010-06-08 16:52:24 +00001630
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001631lldb::SBModule
1632SBTarget::AddModule (const char *path,
1633 const char *triple,
1634 const char *uuid_cstr)
1635{
1636 lldb::SBModule sb_module;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001637 TargetSP target_sp(GetSP());
1638 if (target_sp)
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001639 {
Greg Clayton444fe992012-02-26 05:51:37 +00001640 ModuleSpec module_spec;
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001641 if (path)
Greg Clayton444fe992012-02-26 05:51:37 +00001642 module_spec.GetFileSpec().SetFile(path, false);
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001643
1644 if (uuid_cstr)
Greg Clayton444fe992012-02-26 05:51:37 +00001645 module_spec.GetUUID().SetfromCString(uuid_cstr);
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001646
1647 if (triple)
Greg Clayton444fe992012-02-26 05:51:37 +00001648 module_spec.GetArchitecture().SetTriple (triple, target_sp->GetPlatform ().get());
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001649
Greg Clayton444fe992012-02-26 05:51:37 +00001650 sb_module.SetSP(target_sp->GetSharedModule (module_spec));
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001651 }
1652 return sb_module;
1653}
1654
1655bool
1656SBTarget::AddModule (lldb::SBModule &module)
1657{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001658 TargetSP target_sp(GetSP());
1659 if (target_sp)
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001660 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001661 target_sp->GetImages().AppendIfNeeded (module.GetSP());
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001662 return true;
1663 }
1664 return false;
1665}
1666
Chris Lattner24943d22010-06-08 16:52:24 +00001667uint32_t
1668SBTarget::GetNumModules () const
1669{
Greg Claytone005f2c2010-11-06 01:53:30 +00001670 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001671
Caroline Tice7826c882010-10-26 03:11:13 +00001672 uint32_t num = 0;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001673 TargetSP target_sp(GetSP());
1674 if (target_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +00001675 {
1676 // The module list is thread safe, no need to lock
Greg Clayton0416bdf2012-01-30 09:04:36 +00001677 num = target_sp->GetImages().GetSize();
Greg Claytonbdcda462010-12-20 20:49:23 +00001678 }
Caroline Tice7826c882010-10-26 03:11:13 +00001679
1680 if (log)
Greg Clayton0416bdf2012-01-30 09:04:36 +00001681 log->Printf ("SBTarget(%p)::GetNumModules () => %d", target_sp.get(), num);
Caroline Tice7826c882010-10-26 03:11:13 +00001682
1683 return num;
Chris Lattner24943d22010-06-08 16:52:24 +00001684}
1685
Greg Clayton43490d12010-07-30 20:12:55 +00001686void
1687SBTarget::Clear ()
1688{
Greg Claytone005f2c2010-11-06 01:53:30 +00001689 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001690
1691 if (log)
Greg Clayton3f5ee7f2010-10-29 04:59:35 +00001692 log->Printf ("SBTarget(%p)::Clear ()", m_opaque_sp.get());
Caroline Tice7826c882010-10-26 03:11:13 +00001693
Greg Clayton43490d12010-07-30 20:12:55 +00001694 m_opaque_sp.reset();
1695}
1696
1697
Chris Lattner24943d22010-06-08 16:52:24 +00001698SBModule
1699SBTarget::FindModule (const SBFileSpec &sb_file_spec)
1700{
1701 SBModule sb_module;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001702 TargetSP target_sp(GetSP());
1703 if (target_sp && sb_file_spec.IsValid())
Greg Claytonbdcda462010-12-20 20:49:23 +00001704 {
Greg Clayton444fe992012-02-26 05:51:37 +00001705 ModuleSpec module_spec(*sb_file_spec);
Greg Claytonbdcda462010-12-20 20:49:23 +00001706 // The module list is thread safe, no need to lock
Greg Clayton444fe992012-02-26 05:51:37 +00001707 sb_module.SetSP (target_sp->GetImages().FindFirstModule (module_spec));
Greg Claytonbdcda462010-12-20 20:49:23 +00001708 }
Chris Lattner24943d22010-06-08 16:52:24 +00001709 return sb_module;
1710}
1711
Greg Clayton1b925202012-01-29 06:07:39 +00001712lldb::ByteOrder
1713SBTarget::GetByteOrder ()
1714{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001715 TargetSP target_sp(GetSP());
1716 if (target_sp)
1717 return target_sp->GetArchitecture().GetByteOrder();
Greg Clayton1b925202012-01-29 06:07:39 +00001718 return eByteOrderInvalid;
1719}
1720
1721const char *
1722SBTarget::GetTriple ()
1723{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001724 TargetSP target_sp(GetSP());
1725 if (target_sp)
Greg Clayton1b925202012-01-29 06:07:39 +00001726 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001727 std::string triple (target_sp->GetArchitecture().GetTriple().str());
Greg Clayton1b925202012-01-29 06:07:39 +00001728 // Unique the string so we don't run into ownership issues since
1729 // the const strings put the string into the string pool once and
1730 // the strings never comes out
1731 ConstString const_triple (triple.c_str());
1732 return const_triple.GetCString();
1733 }
1734 return NULL;
1735}
1736
1737uint32_t
1738SBTarget::GetAddressByteSize()
1739{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001740 TargetSP target_sp(GetSP());
1741 if (target_sp)
1742 return target_sp->GetArchitecture().GetAddressByteSize();
Greg Clayton1b925202012-01-29 06:07:39 +00001743 return sizeof(void*);
1744}
1745
1746
Chris Lattner24943d22010-06-08 16:52:24 +00001747SBModule
1748SBTarget::GetModuleAtIndex (uint32_t idx)
1749{
Greg Claytone005f2c2010-11-06 01:53:30 +00001750 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001751
Chris Lattner24943d22010-06-08 16:52:24 +00001752 SBModule sb_module;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001753 ModuleSP module_sp;
1754 TargetSP target_sp(GetSP());
1755 if (target_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +00001756 {
1757 // The module list is thread safe, no need to lock
Greg Clayton0416bdf2012-01-30 09:04:36 +00001758 module_sp = target_sp->GetImages().GetModuleAtIndex(idx);
1759 sb_module.SetSP (module_sp);
Greg Claytonbdcda462010-12-20 20:49:23 +00001760 }
Caroline Tice7826c882010-10-26 03:11:13 +00001761
1762 if (log)
1763 {
Greg Clayton49ce6822010-10-31 03:01:06 +00001764 log->Printf ("SBTarget(%p)::GetModuleAtIndex (idx=%d) => SBModule(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +00001765 target_sp.get(), idx, module_sp.get());
Caroline Tice7826c882010-10-26 03:11:13 +00001766 }
1767
Chris Lattner24943d22010-06-08 16:52:24 +00001768 return sb_module;
1769}
1770
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001771bool
1772SBTarget::RemoveModule (lldb::SBModule module)
1773{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001774 TargetSP target_sp(GetSP());
1775 if (target_sp)
1776 return target_sp->GetImages().Remove(module.GetSP());
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001777 return false;
1778}
1779
Chris Lattner24943d22010-06-08 16:52:24 +00001780
1781SBBroadcaster
1782SBTarget::GetBroadcaster () const
1783{
Greg Claytone005f2c2010-11-06 01:53:30 +00001784 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001785
Greg Clayton0416bdf2012-01-30 09:04:36 +00001786 TargetSP target_sp(GetSP());
1787 SBBroadcaster broadcaster(target_sp.get(), false);
Caroline Tice7826c882010-10-26 03:11:13 +00001788
1789 if (log)
Greg Clayton3f5ee7f2010-10-29 04:59:35 +00001790 log->Printf ("SBTarget(%p)::GetBroadcaster () => SBBroadcaster(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +00001791 target_sp.get(), broadcaster.get());
Caroline Tice7826c882010-10-26 03:11:13 +00001792
Chris Lattner24943d22010-06-08 16:52:24 +00001793 return broadcaster;
1794}
1795
Caroline Tice98f930f2010-09-20 05:20:02 +00001796bool
Caroline Tice7826c882010-10-26 03:11:13 +00001797SBTarget::GetDescription (SBStream &description, lldb::DescriptionLevel description_level)
Caroline Tice98f930f2010-09-20 05:20:02 +00001798{
Greg Clayton96154be2011-11-13 06:57:31 +00001799 Stream &strm = description.ref();
1800
Greg Clayton0416bdf2012-01-30 09:04:36 +00001801 TargetSP target_sp(GetSP());
1802 if (target_sp)
Caroline Ticee7a566e2010-09-20 16:21:41 +00001803 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001804 target_sp->Dump (&strm, description_level);
Caroline Tice7826c882010-10-26 03:11:13 +00001805 }
1806 else
Greg Clayton96154be2011-11-13 06:57:31 +00001807 strm.PutCString ("No value");
Caroline Tice7826c882010-10-26 03:11:13 +00001808
1809 return true;
1810}
1811
Greg Clayton7dd5c512012-02-06 01:44:54 +00001812lldb::SBSymbolContextList
1813SBTarget::FindFunctions (const char *name, uint32_t name_type_mask)
Greg Clayton4ed315f2011-06-21 01:34:41 +00001814{
Greg Clayton7dd5c512012-02-06 01:44:54 +00001815 lldb::SBSymbolContextList sb_sc_list;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001816 if (name && name[0])
Greg Clayton4ed315f2011-06-21 01:34:41 +00001817 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001818 TargetSP target_sp(GetSP());
1819 if (target_sp)
1820 {
1821 const bool symbols_ok = true;
Sean Callanan302d78c2012-02-10 22:52:19 +00001822 const bool inlines_ok = true;
Greg Clayton7dd5c512012-02-06 01:44:54 +00001823 const bool append = true;
1824 target_sp->GetImages().FindFunctions (ConstString(name),
1825 name_type_mask,
Sean Callanan302d78c2012-02-10 22:52:19 +00001826 symbols_ok,
1827 inlines_ok,
Greg Clayton7dd5c512012-02-06 01:44:54 +00001828 append,
1829 *sb_sc_list);
Greg Clayton0416bdf2012-01-30 09:04:36 +00001830 }
Greg Clayton4ed315f2011-06-21 01:34:41 +00001831 }
Greg Clayton7dd5c512012-02-06 01:44:54 +00001832 return sb_sc_list;
Greg Clayton4ed315f2011-06-21 01:34:41 +00001833}
1834
Enrico Granata979e20d2011-07-29 19:53:35 +00001835lldb::SBType
1836SBTarget::FindFirstType (const char* type)
1837{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001838 TargetSP target_sp(GetSP());
1839 if (type && target_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +00001840 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001841 size_t count = target_sp->GetImages().GetSize();
Enrico Granata979e20d2011-07-29 19:53:35 +00001842 for (size_t idx = 0; idx < count; idx++)
1843 {
1844 SBType found_at_idx = GetModuleAtIndex(idx).FindFirstType(type);
1845
1846 if (found_at_idx.IsValid())
1847 return found_at_idx;
1848 }
1849 }
1850 return SBType();
1851}
1852
1853lldb::SBTypeList
1854SBTarget::FindTypes (const char* type)
1855{
1856
1857 SBTypeList retval;
1858
Greg Clayton0416bdf2012-01-30 09:04:36 +00001859 TargetSP target_sp(GetSP());
1860 if (type && target_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +00001861 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001862 ModuleList& images = target_sp->GetImages();
Enrico Granata979e20d2011-07-29 19:53:35 +00001863 ConstString name_const(type);
1864 SymbolContext sc;
1865 TypeList type_list;
1866
1867 uint32_t num_matches = images.FindTypes(sc,
1868 name_const,
1869 true,
1870 UINT32_MAX,
1871 type_list);
1872
1873 for (size_t idx = 0; idx < num_matches; idx++)
1874 {
Greg Clayton0fb0bcc2011-08-03 22:57:10 +00001875 TypeSP type_sp (type_list.GetTypeAtIndex(idx));
1876 if (type_sp)
1877 retval.Append(SBType(type_sp));
Enrico Granata979e20d2011-07-29 19:53:35 +00001878 }
1879 }
1880 return retval;
1881}
1882
Greg Clayton917c0002011-06-29 22:09:02 +00001883SBValueList
1884SBTarget::FindGlobalVariables (const char *name, uint32_t max_matches)
1885{
1886 SBValueList sb_value_list;
1887
Greg Clayton0416bdf2012-01-30 09:04:36 +00001888 TargetSP target_sp(GetSP());
1889 if (name && target_sp)
Greg Clayton917c0002011-06-29 22:09:02 +00001890 {
1891 VariableList variable_list;
1892 const bool append = true;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001893 const uint32_t match_count = target_sp->GetImages().FindGlobalVariables (ConstString (name),
1894 append,
1895 max_matches,
1896 variable_list);
Greg Clayton917c0002011-06-29 22:09:02 +00001897
1898 if (match_count > 0)
1899 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001900 ExecutionContextScope *exe_scope = target_sp->GetProcessSP().get();
Greg Clayton917c0002011-06-29 22:09:02 +00001901 if (exe_scope == NULL)
Greg Clayton0416bdf2012-01-30 09:04:36 +00001902 exe_scope = target_sp.get();
Greg Clayton917c0002011-06-29 22:09:02 +00001903 ValueObjectList &value_object_list = sb_value_list.ref();
1904 for (uint32_t i=0; i<match_count; ++i)
1905 {
1906 lldb::ValueObjectSP valobj_sp (ValueObjectVariable::Create (exe_scope, variable_list.GetVariableAtIndex(i)));
1907 if (valobj_sp)
1908 value_object_list.Append(valobj_sp);
1909 }
1910 }
1911 }
1912
1913 return sb_value_list;
1914}
1915
Jim Inghamcc637462011-09-13 00:29:56 +00001916SBSourceManager
1917SBTarget::GetSourceManager()
1918{
1919 SBSourceManager source_manager (*this);
1920 return source_manager;
1921}
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001922
Sean Callananef1f6902011-12-14 23:49:37 +00001923lldb::SBInstructionList
1924SBTarget::GetInstructions (lldb::SBAddress base_addr, const void *buf, size_t size)
1925{
1926 SBInstructionList sb_instructions;
1927
Greg Clayton0416bdf2012-01-30 09:04:36 +00001928 TargetSP target_sp(GetSP());
1929 if (target_sp)
Sean Callananef1f6902011-12-14 23:49:37 +00001930 {
1931 Address addr;
1932
1933 if (base_addr.get())
1934 addr = *base_addr.get();
1935
Greg Clayton0416bdf2012-01-30 09:04:36 +00001936 sb_instructions.SetDisassembler (Disassembler::DisassembleBytes (target_sp->GetArchitecture(),
Sean Callananef1f6902011-12-14 23:49:37 +00001937 NULL,
1938 addr,
1939 buf,
1940 size));
1941 }
1942
1943 return sb_instructions;
1944}
1945
1946lldb::SBInstructionList
1947SBTarget::GetInstructions (lldb::addr_t base_addr, const void *buf, size_t size)
1948{
1949 return GetInstructions (ResolveLoadAddress(base_addr), buf, size);
1950}
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001951
1952SBError
1953SBTarget::SetSectionLoadAddress (lldb::SBSection section,
1954 lldb::addr_t section_base_addr)
1955{
1956 SBError sb_error;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001957 TargetSP target_sp(GetSP());
1958 if (target_sp)
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001959 {
1960 if (!section.IsValid())
1961 {
1962 sb_error.SetErrorStringWithFormat ("invalid section");
1963 }
1964 else
1965 {
Greg Clayton3508c382012-02-24 01:59:29 +00001966 target_sp->GetSectionLoadList().SetSectionLoadAddress (section.GetSP().get(), section_base_addr);
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001967 }
1968 }
1969 else
1970 {
1971 sb_error.SetErrorStringWithFormat ("invalid target");
1972 }
1973 return sb_error;
1974}
1975
1976SBError
1977SBTarget::ClearSectionLoadAddress (lldb::SBSection section)
1978{
1979 SBError sb_error;
1980
Greg Clayton0416bdf2012-01-30 09:04:36 +00001981 TargetSP target_sp(GetSP());
1982 if (target_sp)
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001983 {
1984 if (!section.IsValid())
1985 {
1986 sb_error.SetErrorStringWithFormat ("invalid section");
1987 }
1988 else
1989 {
Greg Clayton3508c382012-02-24 01:59:29 +00001990 target_sp->GetSectionLoadList().SetSectionUnloaded (section.GetSP().get());
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001991 }
1992 }
1993 else
1994 {
1995 sb_error.SetErrorStringWithFormat ("invalid target");
1996 }
1997 return sb_error;
1998}
1999
2000SBError
2001SBTarget::SetModuleLoadAddress (lldb::SBModule module, int64_t slide_offset)
2002{
2003 SBError sb_error;
2004
2005 char path[PATH_MAX];
Greg Clayton0416bdf2012-01-30 09:04:36 +00002006 TargetSP target_sp(GetSP());
2007 if (target_sp)
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002008 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00002009 ModuleSP module_sp (module.GetSP());
2010 if (module_sp)
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002011 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00002012 ObjectFile *objfile = module_sp->GetObjectFile();
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002013 if (objfile)
2014 {
2015 SectionList *section_list = objfile->GetSectionList();
2016 if (section_list)
2017 {
2018 const size_t num_sections = section_list->GetSize();
2019 for (size_t sect_idx = 0; sect_idx < num_sections; ++sect_idx)
2020 {
2021 SectionSP section_sp (section_list->GetSectionAtIndex(sect_idx));
2022 if (section_sp)
Greg Clayton0416bdf2012-01-30 09:04:36 +00002023 target_sp->GetSectionLoadList().SetSectionLoadAddress (section_sp.get(), section_sp->GetFileAddress() + slide_offset);
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002024 }
2025 }
2026 else
2027 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00002028 module_sp->GetFileSpec().GetPath (path, sizeof(path));
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002029 sb_error.SetErrorStringWithFormat ("no sections in object file '%s'", path);
2030 }
2031 }
2032 else
2033 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00002034 module_sp->GetFileSpec().GetPath (path, sizeof(path));
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002035 sb_error.SetErrorStringWithFormat ("no object file for module '%s'", path);
2036 }
2037 }
Greg Clayton0416bdf2012-01-30 09:04:36 +00002038 else
2039 {
2040 sb_error.SetErrorStringWithFormat ("invalid module");
2041 }
2042
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002043 }
2044 else
2045 {
2046 sb_error.SetErrorStringWithFormat ("invalid target");
2047 }
2048 return sb_error;
2049}
2050
2051SBError
2052SBTarget::ClearModuleLoadAddress (lldb::SBModule module)
2053{
2054 SBError sb_error;
2055
2056 char path[PATH_MAX];
Greg Clayton0416bdf2012-01-30 09:04:36 +00002057 TargetSP target_sp(GetSP());
2058 if (target_sp)
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002059 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00002060 ModuleSP module_sp (module.GetSP());
2061 if (module_sp)
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002062 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00002063 ObjectFile *objfile = module_sp->GetObjectFile();
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002064 if (objfile)
2065 {
2066 SectionList *section_list = objfile->GetSectionList();
2067 if (section_list)
2068 {
2069 const size_t num_sections = section_list->GetSize();
2070 for (size_t sect_idx = 0; sect_idx < num_sections; ++sect_idx)
2071 {
2072 SectionSP section_sp (section_list->GetSectionAtIndex(sect_idx));
2073 if (section_sp)
Greg Clayton0416bdf2012-01-30 09:04:36 +00002074 target_sp->GetSectionLoadList().SetSectionUnloaded (section_sp.get());
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002075 }
2076 }
2077 else
2078 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00002079 module_sp->GetFileSpec().GetPath (path, sizeof(path));
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002080 sb_error.SetErrorStringWithFormat ("no sections in object file '%s'", path);
2081 }
2082 }
2083 else
2084 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00002085 module_sp->GetFileSpec().GetPath (path, sizeof(path));
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002086 sb_error.SetErrorStringWithFormat ("no object file for module '%s'", path);
2087 }
2088 }
Greg Clayton0416bdf2012-01-30 09:04:36 +00002089 else
2090 {
2091 sb_error.SetErrorStringWithFormat ("invalid module");
2092 }
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002093 }
2094 else
2095 {
2096 sb_error.SetErrorStringWithFormat ("invalid target");
2097 }
2098 return sb_error;
2099}
2100
2101