blob: 7dbcf95e48e74003e719571f229b77c543a339f7 [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
723 bool add_exe_as_first_argv = true; //launch_info.GetArguments().GetArgumentCount() == 0;
724 Module *exe_module = target_sp->GetExecutableModulePointer();
725 if (exe_module)
726 launch_info.SetExecutableFile(exe_module->GetPlatformFileSpec(), add_exe_as_first_argv);
727
728 const ArchSpec &arch_spec = target_sp->GetArchitecture();
729 if (arch_spec.IsValid())
730 launch_info.GetArchitecture () = arch_spec;
731
Greg Clayton0a8dcac2012-02-24 05:03:03 +0000732 error.SetError (process_sp->Launch (launch_info));
Greg Clayton98ca1e62012-02-24 20:59:25 +0000733 const bool synchronous_execution = target_sp->GetDebugger().GetAsyncExecution () == false;
Greg Clayton0a8dcac2012-02-24 05:03:03 +0000734 if (error.Success())
735 {
Greg Clayton98ca1e62012-02-24 20:59:25 +0000736 StateType state = eStateInvalid;
Greg Clayton0a8dcac2012-02-24 05:03:03 +0000737 if (launch_info.GetFlags().Test(eLaunchFlagStopAtEntry))
Greg Clayton98ca1e62012-02-24 20:59:25 +0000738 {
739 // If we are doing synchronous mode, then wait for the initial
740 // stop to happen, else, return and let the caller watch for
741 // the stop
742 if (synchronous_execution)
743 state = process_sp->WaitForProcessToStop (NULL);
744 // We we are stopping at the entry point, we can return now!
Greg Clayton0a8dcac2012-02-24 05:03:03 +0000745 return sb_process;
Greg Clayton98ca1e62012-02-24 20:59:25 +0000746 }
Greg Clayton0a8dcac2012-02-24 05:03:03 +0000747
748 // Make sure we are stopped at the entry
Greg Clayton98ca1e62012-02-24 20:59:25 +0000749 state = process_sp->WaitForProcessToStop (NULL);
Greg Clayton0a8dcac2012-02-24 05:03:03 +0000750 if (state == eStateStopped)
751 {
752 // resume the process to skip the entry point
753 error.SetError (process_sp->Resume());
754 if (error.Success())
755 {
756 // If we are doing synchronous mode, then wait for the
757 // process to stop yet again!
Greg Clayton98ca1e62012-02-24 20:59:25 +0000758 if (synchronous_execution)
Greg Clayton0a8dcac2012-02-24 05:03:03 +0000759 process_sp->WaitForProcessToStop (NULL);
760 }
761 }
762 }
763 }
764 else
765 {
766 error.SetErrorString ("unable to create lldb_private::Process");
767 }
768 }
769 else
770 {
771 error.SetErrorString ("SBTarget is invalid");
772 }
773
774 log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
775 if (log)
776 {
777 log->Printf ("SBTarget(%p)::Launch (...) => SBProceess(%p)",
778 target_sp.get(), process_sp.get());
779 }
780
781 return sb_process;
782}
783
784lldb::SBProcess
785SBTarget::Attach (SBAttachInfo &sb_attach_info, SBError& error)
786{
787 SBProcess sb_process;
788 ProcessSP process_sp;
789 TargetSP target_sp(GetSP());
790 if (target_sp)
791 {
792 Mutex::Locker api_locker (target_sp->GetAPIMutex());
793
794 StateType state = eStateInvalid;
795 process_sp = target_sp->GetProcessSP();
796 if (process_sp)
797 {
798 state = process_sp->GetState();
799
800 if (process_sp->IsAlive() && state != eStateConnected)
801 {
802 if (state == eStateAttaching)
803 error.SetErrorString ("process attach is in progress");
804 else
805 error.SetErrorString ("a process is already being debugged");
806 return sb_process;
807 }
808 }
809
810 if (state != eStateConnected)
811 process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener(), NULL, NULL);
812
813 if (process_sp)
814 {
815 sb_process.SetSP (process_sp);
816
817 ProcessAttachInfo &attach_info = sb_attach_info.ref();
Han Ming Ong435c5ef2012-02-29 00:12:56 +0000818 lldb::pid_t attach_pid = attach_info.GetProcessID();
819 if (attach_pid != LLDB_INVALID_PROCESS_ID)
820 {
821 PlatformSP platform_sp = target_sp->GetPlatform();
822 ProcessInstanceInfo instance_info;
823 if (platform_sp->GetProcessInfo(attach_pid, instance_info))
824 {
825 attach_info.SetUserID(instance_info.GetEffectiveUserID());
826 }
827 }
Greg Clayton0a8dcac2012-02-24 05:03:03 +0000828 error.SetError (process_sp->Attach (attach_info));
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 }
834 else
835 {
836 error.SetErrorString ("unable to create lldb_private::Process");
837 }
838 }
839 else
840 {
841 error.SetErrorString ("SBTarget is invalid");
842 }
843 return sb_process;
844}
845
846
Greg Claytond5b0b442011-12-02 02:10:57 +0000847#if defined(__APPLE__)
848
849lldb::SBProcess
850SBTarget::AttachToProcessWithID (SBListener &listener,
851 ::pid_t pid,
852 lldb::SBError& error)
853{
854 return AttachToProcessWithID (listener, (lldb::pid_t)pid, error);
855}
856
857#endif // #if defined(__APPLE__)
Greg Claytonc5f728c2010-10-06 22:10:17 +0000858
859lldb::SBProcess
Greg Claytond8c62532010-10-07 04:19:01 +0000860SBTarget::AttachToProcessWithID
Greg Claytonc5f728c2010-10-06 22:10:17 +0000861(
Greg Clayton271a5db2011-02-03 21:28:34 +0000862 SBListener &listener,
Greg Claytonc5f728c2010-10-06 22:10:17 +0000863 lldb::pid_t pid,// The process ID to attach to
864 SBError& error // An error explaining what went wrong if attach fails
865)
866{
867 SBProcess sb_process;
Greg Clayton334d33a2012-01-30 07:41:31 +0000868 ProcessSP process_sp;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000869 TargetSP target_sp(GetSP());
870 if (target_sp)
Greg Claytonc5f728c2010-10-06 22:10:17 +0000871 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000872 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytonde1dd812011-06-24 03:21:43 +0000873
874 StateType state = eStateInvalid;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000875 process_sp = target_sp->GetProcessSP();
Greg Clayton334d33a2012-01-30 07:41:31 +0000876 if (process_sp)
Greg Claytonde1dd812011-06-24 03:21:43 +0000877 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000878 state = process_sp->GetState();
Greg Claytonde1dd812011-06-24 03:21:43 +0000879
Greg Clayton334d33a2012-01-30 07:41:31 +0000880 if (process_sp->IsAlive() && state != eStateConnected)
Greg Claytonde1dd812011-06-24 03:21:43 +0000881 {
882 if (state == eStateAttaching)
883 error.SetErrorString ("process attach is in progress");
884 else
885 error.SetErrorString ("a process is already being debugged");
Greg Claytonde1dd812011-06-24 03:21:43 +0000886 return sb_process;
887 }
888 }
889
890 if (state == eStateConnected)
891 {
892 // If we are already connected, then we have already specified the
893 // listener, so if a valid listener is supplied, we need to error out
894 // to let the client know.
895 if (listener.IsValid())
896 {
897 error.SetErrorString ("process is connected and already has a listener, pass empty listener");
Greg Claytonde1dd812011-06-24 03:21:43 +0000898 return sb_process;
899 }
900 }
Greg Clayton271a5db2011-02-03 21:28:34 +0000901 else
Greg Claytonde1dd812011-06-24 03:21:43 +0000902 {
903 if (listener.IsValid())
Greg Clayton46c9a352012-02-09 06:16:32 +0000904 process_sp = target_sp->CreateProcess (listener.ref(), NULL, NULL);
Greg Claytonde1dd812011-06-24 03:21:43 +0000905 else
Greg Clayton46c9a352012-02-09 06:16:32 +0000906 process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener(), NULL, NULL);
Greg Claytonde1dd812011-06-24 03:21:43 +0000907 }
Greg Clayton334d33a2012-01-30 07:41:31 +0000908 if (process_sp)
Greg Claytonc5f728c2010-10-06 22:10:17 +0000909 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000910 sb_process.SetSP (process_sp);
911
Greg Clayton527154d2011-11-15 03:53:30 +0000912 ProcessAttachInfo attach_info;
913 attach_info.SetProcessID (pid);
Han Ming Ongd1040dd2012-02-25 01:07:38 +0000914
915 PlatformSP platform_sp = target_sp->GetPlatform();
916 ProcessInstanceInfo instance_info;
917 if (platform_sp->GetProcessInfo(pid, instance_info))
918 {
919 attach_info.SetUserID(instance_info.GetEffectiveUserID());
Han Ming Ongd1040dd2012-02-25 01:07:38 +0000920 }
Greg Clayton334d33a2012-01-30 07:41:31 +0000921 error.SetError (process_sp->Attach (attach_info));
Johnny Chen535960e2011-06-17 00:51:15 +0000922 // If we are doing synchronous mode, then wait for the
923 // process to stop!
Greg Clayton0416bdf2012-01-30 09:04:36 +0000924 if (target_sp->GetDebugger().GetAsyncExecution () == false)
Greg Clayton334d33a2012-01-30 07:41:31 +0000925 process_sp->WaitForProcessToStop (NULL);
Greg Claytonc5f728c2010-10-06 22:10:17 +0000926 }
927 else
928 {
929 error.SetErrorString ("unable to create lldb_private::Process");
930 }
931 }
932 else
933 {
934 error.SetErrorString ("SBTarget is invalid");
935 }
936 return sb_process;
937
938}
939
940lldb::SBProcess
Greg Claytond8c62532010-10-07 04:19:01 +0000941SBTarget::AttachToProcessWithName
Greg Claytonc5f728c2010-10-06 22:10:17 +0000942(
Greg Clayton271a5db2011-02-03 21:28:34 +0000943 SBListener &listener,
Greg Claytonc5f728c2010-10-06 22:10:17 +0000944 const char *name, // basename of process to attach to
945 bool wait_for, // if true wait for a new instance of "name" to be launched
946 SBError& error // An error explaining what went wrong if attach fails
947)
948{
949 SBProcess sb_process;
Greg Clayton334d33a2012-01-30 07:41:31 +0000950 ProcessSP process_sp;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000951 TargetSP target_sp(GetSP());
952 if (name && target_sp)
Greg Claytonc5f728c2010-10-06 22:10:17 +0000953 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000954 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytonbdcda462010-12-20 20:49:23 +0000955
Greg Claytonde1dd812011-06-24 03:21:43 +0000956 StateType state = eStateInvalid;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000957 process_sp = target_sp->GetProcessSP();
Greg Clayton334d33a2012-01-30 07:41:31 +0000958 if (process_sp)
Greg Claytonde1dd812011-06-24 03:21:43 +0000959 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000960 state = process_sp->GetState();
Greg Claytonde1dd812011-06-24 03:21:43 +0000961
Greg Clayton334d33a2012-01-30 07:41:31 +0000962 if (process_sp->IsAlive() && state != eStateConnected)
Greg Claytonde1dd812011-06-24 03:21:43 +0000963 {
964 if (state == eStateAttaching)
965 error.SetErrorString ("process attach is in progress");
966 else
967 error.SetErrorString ("a process is already being debugged");
Greg Claytonde1dd812011-06-24 03:21:43 +0000968 return sb_process;
969 }
970 }
971
972 if (state == eStateConnected)
973 {
974 // If we are already connected, then we have already specified the
975 // listener, so if a valid listener is supplied, we need to error out
976 // to let the client know.
977 if (listener.IsValid())
978 {
979 error.SetErrorString ("process is connected and already has a listener, pass empty listener");
Greg Claytonde1dd812011-06-24 03:21:43 +0000980 return sb_process;
981 }
982 }
Greg Clayton271a5db2011-02-03 21:28:34 +0000983 else
Greg Claytonde1dd812011-06-24 03:21:43 +0000984 {
985 if (listener.IsValid())
Greg Clayton46c9a352012-02-09 06:16:32 +0000986 process_sp = target_sp->CreateProcess (listener.ref(), NULL, NULL);
Greg Claytonde1dd812011-06-24 03:21:43 +0000987 else
Greg Clayton46c9a352012-02-09 06:16:32 +0000988 process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener(), NULL, NULL);
Greg Claytonde1dd812011-06-24 03:21:43 +0000989 }
Greg Claytonc5f728c2010-10-06 22:10:17 +0000990
Greg Clayton334d33a2012-01-30 07:41:31 +0000991 if (process_sp)
Greg Claytonc5f728c2010-10-06 22:10:17 +0000992 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000993 sb_process.SetSP (process_sp);
Greg Clayton527154d2011-11-15 03:53:30 +0000994 ProcessAttachInfo attach_info;
995 attach_info.GetExecutableFile().SetFile(name, false);
996 attach_info.SetWaitForLaunch(wait_for);
Greg Clayton334d33a2012-01-30 07:41:31 +0000997 error.SetError (process_sp->Attach (attach_info));
Johnny Chen58d02ff2011-06-17 19:21:30 +0000998 // If we are doing synchronous mode, then wait for the
999 // process to stop!
Greg Clayton0416bdf2012-01-30 09:04:36 +00001000 if (target_sp->GetDebugger().GetAsyncExecution () == false)
Greg Clayton334d33a2012-01-30 07:41:31 +00001001 process_sp->WaitForProcessToStop (NULL);
Greg Claytonc5f728c2010-10-06 22:10:17 +00001002 }
1003 else
1004 {
1005 error.SetErrorString ("unable to create lldb_private::Process");
1006 }
1007 }
1008 else
1009 {
1010 error.SetErrorString ("SBTarget is invalid");
1011 }
1012 return sb_process;
1013
1014}
1015
James McIlree38093402011-03-04 00:31:13 +00001016lldb::SBProcess
1017SBTarget::ConnectRemote
1018(
1019 SBListener &listener,
1020 const char *url,
1021 const char *plugin_name,
1022 SBError& error
1023)
1024{
1025 SBProcess sb_process;
Greg Clayton334d33a2012-01-30 07:41:31 +00001026 ProcessSP process_sp;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001027 TargetSP target_sp(GetSP());
1028 if (target_sp)
James McIlree38093402011-03-04 00:31:13 +00001029 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001030 Mutex::Locker api_locker (target_sp->GetAPIMutex());
James McIlree38093402011-03-04 00:31:13 +00001031 if (listener.IsValid())
Greg Clayton46c9a352012-02-09 06:16:32 +00001032 process_sp = target_sp->CreateProcess (listener.ref(), plugin_name, NULL);
James McIlree38093402011-03-04 00:31:13 +00001033 else
Greg Clayton46c9a352012-02-09 06:16:32 +00001034 process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener(), plugin_name, NULL);
James McIlree38093402011-03-04 00:31:13 +00001035
1036
Greg Clayton334d33a2012-01-30 07:41:31 +00001037 if (process_sp)
James McIlree38093402011-03-04 00:31:13 +00001038 {
Greg Clayton334d33a2012-01-30 07:41:31 +00001039 sb_process.SetSP (process_sp);
1040 error.SetError (process_sp->ConnectRemote (url));
James McIlree38093402011-03-04 00:31:13 +00001041 }
1042 else
1043 {
1044 error.SetErrorString ("unable to create lldb_private::Process");
1045 }
1046 }
1047 else
1048 {
1049 error.SetErrorString ("SBTarget is invalid");
1050 }
1051 return sb_process;
1052}
1053
Chris Lattner24943d22010-06-08 16:52:24 +00001054SBFileSpec
1055SBTarget::GetExecutable ()
1056{
Caroline Tice7826c882010-10-26 03:11:13 +00001057
Chris Lattner24943d22010-06-08 16:52:24 +00001058 SBFileSpec exe_file_spec;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001059 TargetSP target_sp(GetSP());
1060 if (target_sp)
Chris Lattner24943d22010-06-08 16:52:24 +00001061 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001062 Module *exe_module = target_sp->GetExecutableModulePointer();
Greg Clayton5beb99d2011-08-11 02:48:45 +00001063 if (exe_module)
1064 exe_file_spec.SetFileSpec (exe_module->GetFileSpec());
Chris Lattner24943d22010-06-08 16:52:24 +00001065 }
Caroline Tice7826c882010-10-26 03:11:13 +00001066
Greg Claytone005f2c2010-11-06 01:53:30 +00001067 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001068 if (log)
1069 {
Greg Clayton49ce6822010-10-31 03:01:06 +00001070 log->Printf ("SBTarget(%p)::GetExecutable () => SBFileSpec(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +00001071 target_sp.get(), exe_file_spec.get());
Caroline Tice7826c882010-10-26 03:11:13 +00001072 }
1073
Chris Lattner24943d22010-06-08 16:52:24 +00001074 return exe_file_spec;
1075}
1076
Chris Lattner24943d22010-06-08 16:52:24 +00001077bool
Chris Lattner24943d22010-06-08 16:52:24 +00001078SBTarget::operator == (const SBTarget &rhs) const
1079{
Greg Clayton63094e02010-06-23 01:19:29 +00001080 return m_opaque_sp.get() == rhs.m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +00001081}
1082
1083bool
1084SBTarget::operator != (const SBTarget &rhs) const
1085{
Greg Clayton63094e02010-06-23 01:19:29 +00001086 return m_opaque_sp.get() != rhs.m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +00001087}
1088
Greg Clayton334d33a2012-01-30 07:41:31 +00001089lldb::TargetSP
1090SBTarget::GetSP () const
Greg Clayton15afa9f2011-10-01 02:59:24 +00001091{
1092 return m_opaque_sp;
1093}
1094
Greg Clayton63094e02010-06-23 01:19:29 +00001095void
Greg Clayton334d33a2012-01-30 07:41:31 +00001096SBTarget::SetSP (const lldb::TargetSP& target_sp)
Greg Clayton63094e02010-06-23 01:19:29 +00001097{
1098 m_opaque_sp = target_sp;
Chris Lattner24943d22010-06-08 16:52:24 +00001099}
1100
Greg Claytona3955062011-07-22 16:46:35 +00001101lldb::SBAddress
1102SBTarget::ResolveLoadAddress (lldb::addr_t vm_addr)
Greg Claytonea49cc72010-12-12 19:25:26 +00001103{
Greg Claytona3955062011-07-22 16:46:35 +00001104 lldb::SBAddress sb_addr;
1105 Address &addr = sb_addr.ref();
Greg Clayton0416bdf2012-01-30 09:04:36 +00001106 TargetSP target_sp(GetSP());
1107 if (target_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +00001108 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001109 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1110 if (target_sp->GetSectionLoadList().ResolveLoadAddress (vm_addr, addr))
Greg Claytona3955062011-07-22 16:46:35 +00001111 return sb_addr;
Greg Claytonbdcda462010-12-20 20:49:23 +00001112 }
Greg Claytonea49cc72010-12-12 19:25:26 +00001113
Greg Claytona3955062011-07-22 16:46:35 +00001114 // We have a load address that isn't in a section, just return an address
1115 // with the offset filled in (the address) and the section set to NULL
Greg Clayton3508c382012-02-24 01:59:29 +00001116 addr.SetRawAddress(vm_addr);
Greg Claytona3955062011-07-22 16:46:35 +00001117 return sb_addr;
Greg Claytonea49cc72010-12-12 19:25:26 +00001118}
1119
Greg Claytonafb81862011-03-02 21:34:46 +00001120SBSymbolContext
1121SBTarget::ResolveSymbolContextForAddress (const SBAddress& addr, uint32_t resolve_scope)
1122{
1123 SBSymbolContext sc;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001124 if (addr.IsValid())
1125 {
1126 TargetSP target_sp(GetSP());
1127 if (target_sp)
1128 target_sp->GetImages().ResolveSymbolContextForAddress (addr.ref(), resolve_scope, sc.ref());
1129 }
Greg Claytonafb81862011-03-02 21:34:46 +00001130 return sc;
1131}
1132
1133
Chris Lattner24943d22010-06-08 16:52:24 +00001134SBBreakpoint
1135SBTarget::BreakpointCreateByLocation (const char *file, uint32_t line)
1136{
Greg Claytond6d806c2010-11-08 00:28:40 +00001137 return SBBreakpoint(BreakpointCreateByLocation (SBFileSpec (file, false), line));
Chris Lattner24943d22010-06-08 16:52:24 +00001138}
1139
1140SBBreakpoint
1141SBTarget::BreakpointCreateByLocation (const SBFileSpec &sb_file_spec, uint32_t line)
1142{
Greg Claytone005f2c2010-11-06 01:53:30 +00001143 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001144
Chris Lattner24943d22010-06-08 16:52:24 +00001145 SBBreakpoint sb_bp;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001146 TargetSP target_sp(GetSP());
1147 if (target_sp && line != 0)
Greg Claytonbdcda462010-12-20 20:49:23 +00001148 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001149 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1150 *sb_bp = target_sp->CreateBreakpoint (NULL, *sb_file_spec, line, true, false);
Greg Claytonbdcda462010-12-20 20:49:23 +00001151 }
Caroline Tice7826c882010-10-26 03:11:13 +00001152
1153 if (log)
1154 {
1155 SBStream sstr;
1156 sb_bp.GetDescription (sstr);
Greg Clayton49ce6822010-10-31 03:01:06 +00001157 char path[PATH_MAX];
1158 sb_file_spec->GetPath (path, sizeof(path));
1159 log->Printf ("SBTarget(%p)::BreakpointCreateByLocation ( %s:%u ) => SBBreakpoint(%p): %s",
Greg Clayton0416bdf2012-01-30 09:04:36 +00001160 target_sp.get(),
Greg Clayton49ce6822010-10-31 03:01:06 +00001161 path,
Greg Claytona66ba462010-10-30 04:51:46 +00001162 line,
Greg Clayton49ce6822010-10-31 03:01:06 +00001163 sb_bp.get(),
Caroline Tice7826c882010-10-26 03:11:13 +00001164 sstr.GetData());
1165 }
1166
Chris Lattner24943d22010-06-08 16:52:24 +00001167 return sb_bp;
1168}
1169
1170SBBreakpoint
1171SBTarget::BreakpointCreateByName (const char *symbol_name, const char *module_name)
1172{
Greg Claytone005f2c2010-11-06 01:53:30 +00001173 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001174
Chris Lattner24943d22010-06-08 16:52:24 +00001175 SBBreakpoint sb_bp;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001176 TargetSP target_sp(GetSP());
1177 if (target_sp.get())
Chris Lattner24943d22010-06-08 16:52:24 +00001178 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001179 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Chris Lattner24943d22010-06-08 16:52:24 +00001180 if (module_name && module_name[0])
1181 {
Jim Ingham03c8ee52011-09-21 01:17:13 +00001182 FileSpecList module_spec_list;
1183 module_spec_list.Append (FileSpec (module_name, false));
Greg Clayton0416bdf2012-01-30 09:04:36 +00001184 *sb_bp = target_sp->CreateBreakpoint (&module_spec_list, NULL, symbol_name, eFunctionNameTypeAuto, false);
Chris Lattner24943d22010-06-08 16:52:24 +00001185 }
1186 else
1187 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001188 *sb_bp = target_sp->CreateBreakpoint (NULL, NULL, symbol_name, eFunctionNameTypeAuto, false);
Chris Lattner24943d22010-06-08 16:52:24 +00001189 }
1190 }
Caroline Tice7826c882010-10-26 03:11:13 +00001191
1192 if (log)
1193 {
Greg Clayton49ce6822010-10-31 03:01:06 +00001194 log->Printf ("SBTarget(%p)::BreakpointCreateByName (symbol=\"%s\", module=\"%s\") => SBBreakpoint(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +00001195 target_sp.get(), symbol_name, module_name, sb_bp.get());
Caroline Tice7826c882010-10-26 03:11:13 +00001196 }
1197
Chris Lattner24943d22010-06-08 16:52:24 +00001198 return sb_bp;
1199}
1200
Jim Inghamd6d47972011-09-23 00:54:11 +00001201lldb::SBBreakpoint
1202SBTarget::BreakpointCreateByName (const char *symbol_name,
1203 const SBFileSpecList &module_list,
1204 const SBFileSpecList &comp_unit_list)
1205{
Jim Ingham1fb8a2d2011-10-11 01:18:55 +00001206 uint32_t name_type_mask = eFunctionNameTypeAuto;
1207 return BreakpointCreateByName (symbol_name, name_type_mask, module_list, comp_unit_list);
1208}
1209
1210lldb::SBBreakpoint
1211SBTarget::BreakpointCreateByName (const char *symbol_name,
1212 uint32_t name_type_mask,
1213 const SBFileSpecList &module_list,
1214 const SBFileSpecList &comp_unit_list)
1215{
Jim Inghamd6d47972011-09-23 00:54:11 +00001216 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1217
1218 SBBreakpoint sb_bp;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001219 TargetSP target_sp(GetSP());
1220 if (target_sp && symbol_name && symbol_name[0])
Jim Inghamd6d47972011-09-23 00:54:11 +00001221 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001222 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1223 *sb_bp = target_sp->CreateBreakpoint (module_list.get(),
Jim Inghamd6d47972011-09-23 00:54:11 +00001224 comp_unit_list.get(),
1225 symbol_name,
Jim Ingham1fb8a2d2011-10-11 01:18:55 +00001226 name_type_mask,
Jim Inghamd6d47972011-09-23 00:54:11 +00001227 false);
1228 }
1229
1230 if (log)
1231 {
Jim Ingham1fb8a2d2011-10-11 01:18:55 +00001232 log->Printf ("SBTarget(%p)::BreakpointCreateByName (symbol=\"%s\", name_type: %d) => SBBreakpoint(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +00001233 target_sp.get(), symbol_name, name_type_mask, sb_bp.get());
Jim Inghamd6d47972011-09-23 00:54:11 +00001234 }
1235
1236 return sb_bp;
1237}
1238
1239
Chris Lattner24943d22010-06-08 16:52:24 +00001240SBBreakpoint
1241SBTarget::BreakpointCreateByRegex (const char *symbol_name_regex, const char *module_name)
1242{
Greg Claytone005f2c2010-11-06 01:53:30 +00001243 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001244
Chris Lattner24943d22010-06-08 16:52:24 +00001245 SBBreakpoint sb_bp;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001246 TargetSP target_sp(GetSP());
1247 if (target_sp && symbol_name_regex && symbol_name_regex[0])
Chris Lattner24943d22010-06-08 16:52:24 +00001248 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001249 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Chris Lattner24943d22010-06-08 16:52:24 +00001250 RegularExpression regexp(symbol_name_regex);
1251
1252 if (module_name && module_name[0])
1253 {
Jim Ingham03c8ee52011-09-21 01:17:13 +00001254 FileSpecList module_spec_list;
1255 module_spec_list.Append (FileSpec (module_name, false));
Chris Lattner24943d22010-06-08 16:52:24 +00001256
Greg Clayton0416bdf2012-01-30 09:04:36 +00001257 *sb_bp = target_sp->CreateFuncRegexBreakpoint (&module_spec_list, NULL, regexp, false);
Chris Lattner24943d22010-06-08 16:52:24 +00001258 }
1259 else
1260 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001261 *sb_bp = target_sp->CreateFuncRegexBreakpoint (NULL, NULL, regexp, false);
Chris Lattner24943d22010-06-08 16:52:24 +00001262 }
1263 }
Caroline Tice7826c882010-10-26 03:11:13 +00001264
1265 if (log)
1266 {
Greg Clayton49ce6822010-10-31 03:01:06 +00001267 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (symbol_regex=\"%s\", module_name=\"%s\") => SBBreakpoint(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +00001268 target_sp.get(), symbol_name_regex, module_name, sb_bp.get());
Caroline Tice7826c882010-10-26 03:11:13 +00001269 }
1270
Chris Lattner24943d22010-06-08 16:52:24 +00001271 return sb_bp;
1272}
1273
Jim Inghamd6d47972011-09-23 00:54:11 +00001274lldb::SBBreakpoint
1275SBTarget::BreakpointCreateByRegex (const char *symbol_name_regex,
1276 const SBFileSpecList &module_list,
1277 const SBFileSpecList &comp_unit_list)
1278{
1279 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Chris Lattner24943d22010-06-08 16:52:24 +00001280
Jim Inghamd6d47972011-09-23 00:54:11 +00001281 SBBreakpoint sb_bp;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001282 TargetSP target_sp(GetSP());
1283 if (target_sp && symbol_name_regex && symbol_name_regex[0])
Jim Inghamd6d47972011-09-23 00:54:11 +00001284 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001285 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Jim Inghamd6d47972011-09-23 00:54:11 +00001286 RegularExpression regexp(symbol_name_regex);
1287
Greg Clayton0416bdf2012-01-30 09:04:36 +00001288 *sb_bp = target_sp->CreateFuncRegexBreakpoint (module_list.get(), comp_unit_list.get(), regexp, false);
Jim Inghamd6d47972011-09-23 00:54:11 +00001289 }
1290
1291 if (log)
1292 {
1293 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (symbol_regex=\"%s\") => SBBreakpoint(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +00001294 target_sp.get(), symbol_name_regex, sb_bp.get());
Jim Inghamd6d47972011-09-23 00:54:11 +00001295 }
1296
1297 return sb_bp;
1298}
Chris Lattner24943d22010-06-08 16:52:24 +00001299
1300SBBreakpoint
1301SBTarget::BreakpointCreateByAddress (addr_t address)
1302{
Greg Claytone005f2c2010-11-06 01:53:30 +00001303 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001304
Chris Lattner24943d22010-06-08 16:52:24 +00001305 SBBreakpoint sb_bp;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001306 TargetSP target_sp(GetSP());
1307 if (target_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +00001308 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001309 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1310 *sb_bp = target_sp->CreateBreakpoint (address, false);
Greg Claytonbdcda462010-12-20 20:49:23 +00001311 }
Caroline Tice7826c882010-10-26 03:11:13 +00001312
1313 if (log)
1314 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001315 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 +00001316 }
1317
Chris Lattner24943d22010-06-08 16:52:24 +00001318 return sb_bp;
1319}
1320
Jim Ingham03c8ee52011-09-21 01:17:13 +00001321lldb::SBBreakpoint
1322SBTarget::BreakpointCreateBySourceRegex (const char *source_regex, const lldb::SBFileSpec &source_file, const char *module_name)
1323{
1324 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1325
1326 SBBreakpoint sb_bp;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001327 TargetSP target_sp(GetSP());
1328 if (target_sp && source_regex && source_regex[0])
Jim Ingham03c8ee52011-09-21 01:17:13 +00001329 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001330 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Jim Ingham03c8ee52011-09-21 01:17:13 +00001331 RegularExpression regexp(source_regex);
Jim Inghamd6d47972011-09-23 00:54:11 +00001332 FileSpecList source_file_spec_list;
1333 source_file_spec_list.Append (source_file.ref());
Jim Ingham03c8ee52011-09-21 01:17:13 +00001334
1335 if (module_name && module_name[0])
1336 {
1337 FileSpecList module_spec_list;
1338 module_spec_list.Append (FileSpec (module_name, false));
1339
Greg Clayton0416bdf2012-01-30 09:04:36 +00001340 *sb_bp = target_sp->CreateSourceRegexBreakpoint (&module_spec_list, &source_file_spec_list, regexp, false);
Jim Ingham03c8ee52011-09-21 01:17:13 +00001341 }
1342 else
1343 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001344 *sb_bp = target_sp->CreateSourceRegexBreakpoint (NULL, &source_file_spec_list, regexp, false);
Jim Ingham03c8ee52011-09-21 01:17:13 +00001345 }
1346 }
1347
1348 if (log)
1349 {
1350 char path[PATH_MAX];
1351 source_file->GetPath (path, sizeof(path));
1352 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (source_regex=\"%s\", file=\"%s\", module_name=\"%s\") => SBBreakpoint(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +00001353 target_sp.get(), source_regex, path, module_name, sb_bp.get());
Jim Ingham03c8ee52011-09-21 01:17:13 +00001354 }
1355
1356 return sb_bp;
1357}
1358
Jim Inghamd6d47972011-09-23 00:54:11 +00001359lldb::SBBreakpoint
1360SBTarget::BreakpointCreateBySourceRegex (const char *source_regex,
1361 const SBFileSpecList &module_list,
1362 const lldb::SBFileSpecList &source_file_list)
1363{
1364 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1365
1366 SBBreakpoint sb_bp;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001367 TargetSP target_sp(GetSP());
1368 if (target_sp && source_regex && source_regex[0])
Jim Inghamd6d47972011-09-23 00:54:11 +00001369 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001370 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Jim Inghamd6d47972011-09-23 00:54:11 +00001371 RegularExpression regexp(source_regex);
Greg Clayton0416bdf2012-01-30 09:04:36 +00001372 *sb_bp = target_sp->CreateSourceRegexBreakpoint (module_list.get(), source_file_list.get(), regexp, false);
Jim Inghamd6d47972011-09-23 00:54:11 +00001373 }
1374
1375 if (log)
1376 {
1377 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (source_regex=\"%s\") => SBBreakpoint(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +00001378 target_sp.get(), source_regex, sb_bp.get());
Jim Inghamd6d47972011-09-23 00:54:11 +00001379 }
1380
1381 return sb_bp;
1382}
Jim Ingham03c8ee52011-09-21 01:17:13 +00001383
Greg Claytonc7f5d5c2010-07-23 23:33:17 +00001384uint32_t
1385SBTarget::GetNumBreakpoints () const
1386{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001387 TargetSP target_sp(GetSP());
1388 if (target_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +00001389 {
1390 // The breakpoint list is thread safe, no need to lock
Greg Clayton0416bdf2012-01-30 09:04:36 +00001391 return target_sp->GetBreakpointList().GetSize();
Greg Claytonbdcda462010-12-20 20:49:23 +00001392 }
Greg Claytonc7f5d5c2010-07-23 23:33:17 +00001393 return 0;
1394}
1395
1396SBBreakpoint
1397SBTarget::GetBreakpointAtIndex (uint32_t idx) const
1398{
1399 SBBreakpoint sb_breakpoint;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001400 TargetSP target_sp(GetSP());
1401 if (target_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +00001402 {
1403 // The breakpoint list is thread safe, no need to lock
Greg Clayton0416bdf2012-01-30 09:04:36 +00001404 *sb_breakpoint = target_sp->GetBreakpointList().GetBreakpointAtIndex(idx);
Greg Claytonbdcda462010-12-20 20:49:23 +00001405 }
Greg Claytonc7f5d5c2010-07-23 23:33:17 +00001406 return sb_breakpoint;
1407}
Chris Lattner24943d22010-06-08 16:52:24 +00001408
1409bool
1410SBTarget::BreakpointDelete (break_id_t bp_id)
1411{
Greg Claytone005f2c2010-11-06 01:53:30 +00001412 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001413
Caroline Tice7826c882010-10-26 03:11:13 +00001414 bool result = false;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001415 TargetSP target_sp(GetSP());
1416 if (target_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +00001417 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001418 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1419 result = target_sp->RemoveBreakpointByID (bp_id);
Greg Claytonbdcda462010-12-20 20:49:23 +00001420 }
Caroline Tice7826c882010-10-26 03:11:13 +00001421
1422 if (log)
1423 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001424 log->Printf ("SBTarget(%p)::BreakpointDelete (bp_id=%d) => %i", target_sp.get(), (uint32_t) bp_id, result);
Caroline Tice7826c882010-10-26 03:11:13 +00001425 }
1426
1427 return result;
Chris Lattner24943d22010-06-08 16:52:24 +00001428}
1429
Johnny Chen096c2932011-09-26 22:40:50 +00001430SBBreakpoint
1431SBTarget::FindBreakpointByID (break_id_t bp_id)
1432{
1433 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1434
1435 SBBreakpoint sb_breakpoint;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001436 TargetSP target_sp(GetSP());
1437 if (target_sp && bp_id != LLDB_INVALID_BREAK_ID)
Johnny Chen096c2932011-09-26 22:40:50 +00001438 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001439 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1440 *sb_breakpoint = target_sp->GetBreakpointByID (bp_id);
Johnny Chen096c2932011-09-26 22:40:50 +00001441 }
1442
1443 if (log)
1444 {
1445 log->Printf ("SBTarget(%p)::FindBreakpointByID (bp_id=%d) => SBBreakpoint(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +00001446 target_sp.get(), (uint32_t) bp_id, sb_breakpoint.get());
Johnny Chen096c2932011-09-26 22:40:50 +00001447 }
1448
1449 return sb_breakpoint;
1450}
1451
Chris Lattner24943d22010-06-08 16:52:24 +00001452bool
1453SBTarget::EnableAllBreakpoints ()
1454{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001455 TargetSP target_sp(GetSP());
1456 if (target_sp)
Chris Lattner24943d22010-06-08 16:52:24 +00001457 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001458 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1459 target_sp->EnableAllBreakpoints ();
Chris Lattner24943d22010-06-08 16:52:24 +00001460 return true;
1461 }
1462 return false;
1463}
1464
1465bool
1466SBTarget::DisableAllBreakpoints ()
1467{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001468 TargetSP target_sp(GetSP());
1469 if (target_sp)
Chris Lattner24943d22010-06-08 16:52:24 +00001470 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001471 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1472 target_sp->DisableAllBreakpoints ();
Chris Lattner24943d22010-06-08 16:52:24 +00001473 return true;
1474 }
1475 return false;
1476}
1477
1478bool
1479SBTarget::DeleteAllBreakpoints ()
1480{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001481 TargetSP target_sp(GetSP());
1482 if (target_sp)
Chris Lattner24943d22010-06-08 16:52:24 +00001483 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001484 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1485 target_sp->RemoveAllBreakpoints ();
Chris Lattner24943d22010-06-08 16:52:24 +00001486 return true;
1487 }
1488 return false;
1489}
1490
Johnny Chen096c2932011-09-26 22:40:50 +00001491uint32_t
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001492SBTarget::GetNumWatchpoints () const
Johnny Chen096c2932011-09-26 22:40:50 +00001493{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001494 TargetSP target_sp(GetSP());
1495 if (target_sp)
Johnny Chen096c2932011-09-26 22:40:50 +00001496 {
Johnny Chenecd4feb2011-10-14 00:42:25 +00001497 // The watchpoint list is thread safe, no need to lock
Greg Clayton0416bdf2012-01-30 09:04:36 +00001498 return target_sp->GetWatchpointList().GetSize();
Johnny Chen096c2932011-09-26 22:40:50 +00001499 }
1500 return 0;
1501}
1502
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001503SBWatchpoint
1504SBTarget::GetWatchpointAtIndex (uint32_t idx) const
Johnny Chen5eb54bb2011-09-27 20:29:45 +00001505{
Johnny Chenecd4feb2011-10-14 00:42:25 +00001506 SBWatchpoint sb_watchpoint;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001507 TargetSP target_sp(GetSP());
1508 if (target_sp)
Johnny Chen096c2932011-09-26 22:40:50 +00001509 {
Johnny Chenecd4feb2011-10-14 00:42:25 +00001510 // The watchpoint list is thread safe, no need to lock
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001511 sb_watchpoint.SetSP (target_sp->GetWatchpointList().GetByIndex(idx));
Johnny Chen096c2932011-09-26 22:40:50 +00001512 }
Johnny Chenecd4feb2011-10-14 00:42:25 +00001513 return sb_watchpoint;
Johnny Chen096c2932011-09-26 22:40:50 +00001514}
1515
1516bool
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001517SBTarget::DeleteWatchpoint (watch_id_t wp_id)
Johnny Chen096c2932011-09-26 22:40:50 +00001518{
1519 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1520
1521 bool result = false;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001522 TargetSP target_sp(GetSP());
1523 if (target_sp)
Johnny Chen096c2932011-09-26 22:40:50 +00001524 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001525 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1526 result = target_sp->RemoveWatchpointByID (wp_id);
Johnny Chen096c2932011-09-26 22:40:50 +00001527 }
1528
1529 if (log)
1530 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001531 log->Printf ("SBTarget(%p)::WatchpointDelete (wp_id=%d) => %i", target_sp.get(), (uint32_t) wp_id, result);
Johnny Chen096c2932011-09-26 22:40:50 +00001532 }
1533
1534 return result;
1535}
1536
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001537SBWatchpoint
1538SBTarget::FindWatchpointByID (lldb::watch_id_t wp_id)
Johnny Chen096c2932011-09-26 22:40:50 +00001539{
1540 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1541
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001542 SBWatchpoint sb_watchpoint;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001543 lldb::WatchpointSP watchpoint_sp;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001544 TargetSP target_sp(GetSP());
1545 if (target_sp && wp_id != LLDB_INVALID_WATCH_ID)
Johnny Chen096c2932011-09-26 22:40:50 +00001546 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001547 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001548 watchpoint_sp = target_sp->GetWatchpointList().FindByID(wp_id);
1549 sb_watchpoint.SetSP (watchpoint_sp);
Johnny Chen096c2932011-09-26 22:40:50 +00001550 }
1551
1552 if (log)
1553 {
Johnny Chenecd4feb2011-10-14 00:42:25 +00001554 log->Printf ("SBTarget(%p)::FindWatchpointByID (bp_id=%d) => SBWatchpoint(%p)",
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001555 target_sp.get(), (uint32_t) wp_id, watchpoint_sp.get());
Johnny Chen096c2932011-09-26 22:40:50 +00001556 }
1557
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001558 return sb_watchpoint;
1559}
1560
1561lldb::SBWatchpoint
1562SBTarget::WatchAddress (lldb::addr_t addr, size_t size, bool read, bool write)
1563{
1564 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1565
1566 SBWatchpoint sb_watchpoint;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001567 lldb::WatchpointSP watchpoint_sp;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001568 TargetSP target_sp(GetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001569 if (target_sp && (read || write) && addr != LLDB_INVALID_ADDRESS && size > 0)
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001570 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001571 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001572 uint32_t watch_type = 0;
1573 if (read)
1574 watch_type |= LLDB_WATCH_TYPE_READ;
1575 if (write)
1576 watch_type |= LLDB_WATCH_TYPE_WRITE;
1577 watchpoint_sp = target_sp->CreateWatchpoint(addr, size, watch_type);
1578 sb_watchpoint.SetSP (watchpoint_sp);
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001579 }
1580
1581 if (log)
1582 {
1583 log->Printf ("SBTarget(%p)::WatchAddress (addr=0x%llx, 0x%u) => SBWatchpoint(%p)",
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001584 target_sp.get(), addr, (uint32_t) size, watchpoint_sp.get());
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001585 }
1586
1587 return sb_watchpoint;
Johnny Chen096c2932011-09-26 22:40:50 +00001588}
1589
1590bool
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001591SBTarget::EnableAllWatchpoints ()
Johnny Chen096c2932011-09-26 22:40:50 +00001592{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001593 TargetSP target_sp(GetSP());
1594 if (target_sp)
Johnny Chen096c2932011-09-26 22:40:50 +00001595 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001596 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1597 target_sp->EnableAllWatchpoints ();
Johnny Chen096c2932011-09-26 22:40:50 +00001598 return true;
1599 }
1600 return false;
1601}
1602
1603bool
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001604SBTarget::DisableAllWatchpoints ()
Johnny Chen096c2932011-09-26 22:40:50 +00001605{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001606 TargetSP target_sp(GetSP());
1607 if (target_sp)
Johnny Chen096c2932011-09-26 22:40:50 +00001608 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001609 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1610 target_sp->DisableAllWatchpoints ();
Johnny Chen096c2932011-09-26 22:40:50 +00001611 return true;
1612 }
1613 return false;
1614}
1615
1616bool
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001617SBTarget::DeleteAllWatchpoints ()
Johnny Chen096c2932011-09-26 22:40:50 +00001618{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001619 TargetSP target_sp(GetSP());
1620 if (target_sp)
Johnny Chen096c2932011-09-26 22:40:50 +00001621 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001622 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1623 target_sp->RemoveAllWatchpoints ();
Johnny Chen096c2932011-09-26 22:40:50 +00001624 return true;
1625 }
1626 return false;
1627}
1628
Chris Lattner24943d22010-06-08 16:52:24 +00001629
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001630lldb::SBModule
1631SBTarget::AddModule (const char *path,
1632 const char *triple,
1633 const char *uuid_cstr)
1634{
1635 lldb::SBModule sb_module;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001636 TargetSP target_sp(GetSP());
1637 if (target_sp)
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001638 {
Greg Clayton444fe992012-02-26 05:51:37 +00001639 ModuleSpec module_spec;
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001640 if (path)
Greg Clayton444fe992012-02-26 05:51:37 +00001641 module_spec.GetFileSpec().SetFile(path, false);
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001642
1643 if (uuid_cstr)
Greg Clayton444fe992012-02-26 05:51:37 +00001644 module_spec.GetUUID().SetfromCString(uuid_cstr);
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001645
1646 if (triple)
Greg Clayton444fe992012-02-26 05:51:37 +00001647 module_spec.GetArchitecture().SetTriple (triple, target_sp->GetPlatform ().get());
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001648
Greg Clayton444fe992012-02-26 05:51:37 +00001649 sb_module.SetSP(target_sp->GetSharedModule (module_spec));
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001650 }
1651 return sb_module;
1652}
1653
1654bool
1655SBTarget::AddModule (lldb::SBModule &module)
1656{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001657 TargetSP target_sp(GetSP());
1658 if (target_sp)
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001659 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001660 target_sp->GetImages().AppendIfNeeded (module.GetSP());
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001661 return true;
1662 }
1663 return false;
1664}
1665
Chris Lattner24943d22010-06-08 16:52:24 +00001666uint32_t
1667SBTarget::GetNumModules () const
1668{
Greg Claytone005f2c2010-11-06 01:53:30 +00001669 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001670
Caroline Tice7826c882010-10-26 03:11:13 +00001671 uint32_t num = 0;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001672 TargetSP target_sp(GetSP());
1673 if (target_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +00001674 {
1675 // The module list is thread safe, no need to lock
Greg Clayton0416bdf2012-01-30 09:04:36 +00001676 num = target_sp->GetImages().GetSize();
Greg Claytonbdcda462010-12-20 20:49:23 +00001677 }
Caroline Tice7826c882010-10-26 03:11:13 +00001678
1679 if (log)
Greg Clayton0416bdf2012-01-30 09:04:36 +00001680 log->Printf ("SBTarget(%p)::GetNumModules () => %d", target_sp.get(), num);
Caroline Tice7826c882010-10-26 03:11:13 +00001681
1682 return num;
Chris Lattner24943d22010-06-08 16:52:24 +00001683}
1684
Greg Clayton43490d12010-07-30 20:12:55 +00001685void
1686SBTarget::Clear ()
1687{
Greg Claytone005f2c2010-11-06 01:53:30 +00001688 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001689
1690 if (log)
Greg Clayton3f5ee7f2010-10-29 04:59:35 +00001691 log->Printf ("SBTarget(%p)::Clear ()", m_opaque_sp.get());
Caroline Tice7826c882010-10-26 03:11:13 +00001692
Greg Clayton43490d12010-07-30 20:12:55 +00001693 m_opaque_sp.reset();
1694}
1695
1696
Chris Lattner24943d22010-06-08 16:52:24 +00001697SBModule
1698SBTarget::FindModule (const SBFileSpec &sb_file_spec)
1699{
1700 SBModule sb_module;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001701 TargetSP target_sp(GetSP());
1702 if (target_sp && sb_file_spec.IsValid())
Greg Claytonbdcda462010-12-20 20:49:23 +00001703 {
Greg Clayton444fe992012-02-26 05:51:37 +00001704 ModuleSpec module_spec(*sb_file_spec);
Greg Claytonbdcda462010-12-20 20:49:23 +00001705 // The module list is thread safe, no need to lock
Greg Clayton444fe992012-02-26 05:51:37 +00001706 sb_module.SetSP (target_sp->GetImages().FindFirstModule (module_spec));
Greg Claytonbdcda462010-12-20 20:49:23 +00001707 }
Chris Lattner24943d22010-06-08 16:52:24 +00001708 return sb_module;
1709}
1710
Greg Clayton1b925202012-01-29 06:07:39 +00001711lldb::ByteOrder
1712SBTarget::GetByteOrder ()
1713{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001714 TargetSP target_sp(GetSP());
1715 if (target_sp)
1716 return target_sp->GetArchitecture().GetByteOrder();
Greg Clayton1b925202012-01-29 06:07:39 +00001717 return eByteOrderInvalid;
1718}
1719
1720const char *
1721SBTarget::GetTriple ()
1722{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001723 TargetSP target_sp(GetSP());
1724 if (target_sp)
Greg Clayton1b925202012-01-29 06:07:39 +00001725 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001726 std::string triple (target_sp->GetArchitecture().GetTriple().str());
Greg Clayton1b925202012-01-29 06:07:39 +00001727 // Unique the string so we don't run into ownership issues since
1728 // the const strings put the string into the string pool once and
1729 // the strings never comes out
1730 ConstString const_triple (triple.c_str());
1731 return const_triple.GetCString();
1732 }
1733 return NULL;
1734}
1735
1736uint32_t
1737SBTarget::GetAddressByteSize()
1738{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001739 TargetSP target_sp(GetSP());
1740 if (target_sp)
1741 return target_sp->GetArchitecture().GetAddressByteSize();
Greg Clayton1b925202012-01-29 06:07:39 +00001742 return sizeof(void*);
1743}
1744
1745
Chris Lattner24943d22010-06-08 16:52:24 +00001746SBModule
1747SBTarget::GetModuleAtIndex (uint32_t idx)
1748{
Greg Claytone005f2c2010-11-06 01:53:30 +00001749 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001750
Chris Lattner24943d22010-06-08 16:52:24 +00001751 SBModule sb_module;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001752 ModuleSP module_sp;
1753 TargetSP target_sp(GetSP());
1754 if (target_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +00001755 {
1756 // The module list is thread safe, no need to lock
Greg Clayton0416bdf2012-01-30 09:04:36 +00001757 module_sp = target_sp->GetImages().GetModuleAtIndex(idx);
1758 sb_module.SetSP (module_sp);
Greg Claytonbdcda462010-12-20 20:49:23 +00001759 }
Caroline Tice7826c882010-10-26 03:11:13 +00001760
1761 if (log)
1762 {
Greg Clayton49ce6822010-10-31 03:01:06 +00001763 log->Printf ("SBTarget(%p)::GetModuleAtIndex (idx=%d) => SBModule(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +00001764 target_sp.get(), idx, module_sp.get());
Caroline Tice7826c882010-10-26 03:11:13 +00001765 }
1766
Chris Lattner24943d22010-06-08 16:52:24 +00001767 return sb_module;
1768}
1769
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001770bool
1771SBTarget::RemoveModule (lldb::SBModule module)
1772{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001773 TargetSP target_sp(GetSP());
1774 if (target_sp)
1775 return target_sp->GetImages().Remove(module.GetSP());
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001776 return false;
1777}
1778
Chris Lattner24943d22010-06-08 16:52:24 +00001779
1780SBBroadcaster
1781SBTarget::GetBroadcaster () const
1782{
Greg Claytone005f2c2010-11-06 01:53:30 +00001783 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001784
Greg Clayton0416bdf2012-01-30 09:04:36 +00001785 TargetSP target_sp(GetSP());
1786 SBBroadcaster broadcaster(target_sp.get(), false);
Caroline Tice7826c882010-10-26 03:11:13 +00001787
1788 if (log)
Greg Clayton3f5ee7f2010-10-29 04:59:35 +00001789 log->Printf ("SBTarget(%p)::GetBroadcaster () => SBBroadcaster(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +00001790 target_sp.get(), broadcaster.get());
Caroline Tice7826c882010-10-26 03:11:13 +00001791
Chris Lattner24943d22010-06-08 16:52:24 +00001792 return broadcaster;
1793}
1794
Caroline Tice98f930f2010-09-20 05:20:02 +00001795bool
Caroline Tice7826c882010-10-26 03:11:13 +00001796SBTarget::GetDescription (SBStream &description, lldb::DescriptionLevel description_level)
Caroline Tice98f930f2010-09-20 05:20:02 +00001797{
Greg Clayton96154be2011-11-13 06:57:31 +00001798 Stream &strm = description.ref();
1799
Greg Clayton0416bdf2012-01-30 09:04:36 +00001800 TargetSP target_sp(GetSP());
1801 if (target_sp)
Caroline Ticee7a566e2010-09-20 16:21:41 +00001802 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001803 target_sp->Dump (&strm, description_level);
Caroline Tice7826c882010-10-26 03:11:13 +00001804 }
1805 else
Greg Clayton96154be2011-11-13 06:57:31 +00001806 strm.PutCString ("No value");
Caroline Tice7826c882010-10-26 03:11:13 +00001807
1808 return true;
1809}
1810
Greg Clayton7dd5c512012-02-06 01:44:54 +00001811lldb::SBSymbolContextList
1812SBTarget::FindFunctions (const char *name, uint32_t name_type_mask)
Greg Clayton4ed315f2011-06-21 01:34:41 +00001813{
Greg Clayton7dd5c512012-02-06 01:44:54 +00001814 lldb::SBSymbolContextList sb_sc_list;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001815 if (name && name[0])
Greg Clayton4ed315f2011-06-21 01:34:41 +00001816 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001817 TargetSP target_sp(GetSP());
1818 if (target_sp)
1819 {
1820 const bool symbols_ok = true;
Sean Callanan302d78c2012-02-10 22:52:19 +00001821 const bool inlines_ok = true;
Greg Clayton7dd5c512012-02-06 01:44:54 +00001822 const bool append = true;
1823 target_sp->GetImages().FindFunctions (ConstString(name),
1824 name_type_mask,
Sean Callanan302d78c2012-02-10 22:52:19 +00001825 symbols_ok,
1826 inlines_ok,
Greg Clayton7dd5c512012-02-06 01:44:54 +00001827 append,
1828 *sb_sc_list);
Greg Clayton0416bdf2012-01-30 09:04:36 +00001829 }
Greg Clayton4ed315f2011-06-21 01:34:41 +00001830 }
Greg Clayton7dd5c512012-02-06 01:44:54 +00001831 return sb_sc_list;
Greg Clayton4ed315f2011-06-21 01:34:41 +00001832}
1833
Enrico Granata979e20d2011-07-29 19:53:35 +00001834lldb::SBType
1835SBTarget::FindFirstType (const char* type)
1836{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001837 TargetSP target_sp(GetSP());
1838 if (type && target_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +00001839 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001840 size_t count = target_sp->GetImages().GetSize();
Enrico Granata979e20d2011-07-29 19:53:35 +00001841 for (size_t idx = 0; idx < count; idx++)
1842 {
1843 SBType found_at_idx = GetModuleAtIndex(idx).FindFirstType(type);
1844
1845 if (found_at_idx.IsValid())
1846 return found_at_idx;
1847 }
1848 }
1849 return SBType();
1850}
1851
1852lldb::SBTypeList
1853SBTarget::FindTypes (const char* type)
1854{
1855
1856 SBTypeList retval;
1857
Greg Clayton0416bdf2012-01-30 09:04:36 +00001858 TargetSP target_sp(GetSP());
1859 if (type && target_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +00001860 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001861 ModuleList& images = target_sp->GetImages();
Enrico Granata979e20d2011-07-29 19:53:35 +00001862 ConstString name_const(type);
1863 SymbolContext sc;
1864 TypeList type_list;
1865
1866 uint32_t num_matches = images.FindTypes(sc,
1867 name_const,
1868 true,
1869 UINT32_MAX,
1870 type_list);
1871
1872 for (size_t idx = 0; idx < num_matches; idx++)
1873 {
Greg Clayton0fb0bcc2011-08-03 22:57:10 +00001874 TypeSP type_sp (type_list.GetTypeAtIndex(idx));
1875 if (type_sp)
1876 retval.Append(SBType(type_sp));
Enrico Granata979e20d2011-07-29 19:53:35 +00001877 }
1878 }
1879 return retval;
1880}
1881
Greg Clayton917c0002011-06-29 22:09:02 +00001882SBValueList
1883SBTarget::FindGlobalVariables (const char *name, uint32_t max_matches)
1884{
1885 SBValueList sb_value_list;
1886
Greg Clayton0416bdf2012-01-30 09:04:36 +00001887 TargetSP target_sp(GetSP());
1888 if (name && target_sp)
Greg Clayton917c0002011-06-29 22:09:02 +00001889 {
1890 VariableList variable_list;
1891 const bool append = true;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001892 const uint32_t match_count = target_sp->GetImages().FindGlobalVariables (ConstString (name),
1893 append,
1894 max_matches,
1895 variable_list);
Greg Clayton917c0002011-06-29 22:09:02 +00001896
1897 if (match_count > 0)
1898 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001899 ExecutionContextScope *exe_scope = target_sp->GetProcessSP().get();
Greg Clayton917c0002011-06-29 22:09:02 +00001900 if (exe_scope == NULL)
Greg Clayton0416bdf2012-01-30 09:04:36 +00001901 exe_scope = target_sp.get();
Greg Clayton917c0002011-06-29 22:09:02 +00001902 ValueObjectList &value_object_list = sb_value_list.ref();
1903 for (uint32_t i=0; i<match_count; ++i)
1904 {
1905 lldb::ValueObjectSP valobj_sp (ValueObjectVariable::Create (exe_scope, variable_list.GetVariableAtIndex(i)));
1906 if (valobj_sp)
1907 value_object_list.Append(valobj_sp);
1908 }
1909 }
1910 }
1911
1912 return sb_value_list;
1913}
1914
Jim Inghamcc637462011-09-13 00:29:56 +00001915SBSourceManager
1916SBTarget::GetSourceManager()
1917{
1918 SBSourceManager source_manager (*this);
1919 return source_manager;
1920}
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001921
Sean Callananef1f6902011-12-14 23:49:37 +00001922lldb::SBInstructionList
1923SBTarget::GetInstructions (lldb::SBAddress base_addr, const void *buf, size_t size)
1924{
1925 SBInstructionList sb_instructions;
1926
Greg Clayton0416bdf2012-01-30 09:04:36 +00001927 TargetSP target_sp(GetSP());
1928 if (target_sp)
Sean Callananef1f6902011-12-14 23:49:37 +00001929 {
1930 Address addr;
1931
1932 if (base_addr.get())
1933 addr = *base_addr.get();
1934
Greg Clayton0416bdf2012-01-30 09:04:36 +00001935 sb_instructions.SetDisassembler (Disassembler::DisassembleBytes (target_sp->GetArchitecture(),
Sean Callananef1f6902011-12-14 23:49:37 +00001936 NULL,
1937 addr,
1938 buf,
1939 size));
1940 }
1941
1942 return sb_instructions;
1943}
1944
1945lldb::SBInstructionList
1946SBTarget::GetInstructions (lldb::addr_t base_addr, const void *buf, size_t size)
1947{
1948 return GetInstructions (ResolveLoadAddress(base_addr), buf, size);
1949}
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001950
1951SBError
1952SBTarget::SetSectionLoadAddress (lldb::SBSection section,
1953 lldb::addr_t section_base_addr)
1954{
1955 SBError sb_error;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001956 TargetSP target_sp(GetSP());
1957 if (target_sp)
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001958 {
1959 if (!section.IsValid())
1960 {
1961 sb_error.SetErrorStringWithFormat ("invalid section");
1962 }
1963 else
1964 {
Greg Clayton3508c382012-02-24 01:59:29 +00001965 target_sp->GetSectionLoadList().SetSectionLoadAddress (section.GetSP().get(), section_base_addr);
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001966 }
1967 }
1968 else
1969 {
1970 sb_error.SetErrorStringWithFormat ("invalid target");
1971 }
1972 return sb_error;
1973}
1974
1975SBError
1976SBTarget::ClearSectionLoadAddress (lldb::SBSection section)
1977{
1978 SBError sb_error;
1979
Greg Clayton0416bdf2012-01-30 09:04:36 +00001980 TargetSP target_sp(GetSP());
1981 if (target_sp)
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001982 {
1983 if (!section.IsValid())
1984 {
1985 sb_error.SetErrorStringWithFormat ("invalid section");
1986 }
1987 else
1988 {
Greg Clayton3508c382012-02-24 01:59:29 +00001989 target_sp->GetSectionLoadList().SetSectionUnloaded (section.GetSP().get());
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001990 }
1991 }
1992 else
1993 {
1994 sb_error.SetErrorStringWithFormat ("invalid target");
1995 }
1996 return sb_error;
1997}
1998
1999SBError
2000SBTarget::SetModuleLoadAddress (lldb::SBModule module, int64_t slide_offset)
2001{
2002 SBError sb_error;
2003
2004 char path[PATH_MAX];
Greg Clayton0416bdf2012-01-30 09:04:36 +00002005 TargetSP target_sp(GetSP());
2006 if (target_sp)
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002007 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00002008 ModuleSP module_sp (module.GetSP());
2009 if (module_sp)
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002010 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00002011 ObjectFile *objfile = module_sp->GetObjectFile();
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002012 if (objfile)
2013 {
2014 SectionList *section_list = objfile->GetSectionList();
2015 if (section_list)
2016 {
2017 const size_t num_sections = section_list->GetSize();
2018 for (size_t sect_idx = 0; sect_idx < num_sections; ++sect_idx)
2019 {
2020 SectionSP section_sp (section_list->GetSectionAtIndex(sect_idx));
2021 if (section_sp)
Greg Clayton0416bdf2012-01-30 09:04:36 +00002022 target_sp->GetSectionLoadList().SetSectionLoadAddress (section_sp.get(), section_sp->GetFileAddress() + slide_offset);
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002023 }
2024 }
2025 else
2026 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00002027 module_sp->GetFileSpec().GetPath (path, sizeof(path));
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002028 sb_error.SetErrorStringWithFormat ("no sections in object file '%s'", path);
2029 }
2030 }
2031 else
2032 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00002033 module_sp->GetFileSpec().GetPath (path, sizeof(path));
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002034 sb_error.SetErrorStringWithFormat ("no object file for module '%s'", path);
2035 }
2036 }
Greg Clayton0416bdf2012-01-30 09:04:36 +00002037 else
2038 {
2039 sb_error.SetErrorStringWithFormat ("invalid module");
2040 }
2041
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002042 }
2043 else
2044 {
2045 sb_error.SetErrorStringWithFormat ("invalid target");
2046 }
2047 return sb_error;
2048}
2049
2050SBError
2051SBTarget::ClearModuleLoadAddress (lldb::SBModule module)
2052{
2053 SBError sb_error;
2054
2055 char path[PATH_MAX];
Greg Clayton0416bdf2012-01-30 09:04:36 +00002056 TargetSP target_sp(GetSP());
2057 if (target_sp)
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002058 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00002059 ModuleSP module_sp (module.GetSP());
2060 if (module_sp)
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002061 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00002062 ObjectFile *objfile = module_sp->GetObjectFile();
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002063 if (objfile)
2064 {
2065 SectionList *section_list = objfile->GetSectionList();
2066 if (section_list)
2067 {
2068 const size_t num_sections = section_list->GetSize();
2069 for (size_t sect_idx = 0; sect_idx < num_sections; ++sect_idx)
2070 {
2071 SectionSP section_sp (section_list->GetSectionAtIndex(sect_idx));
2072 if (section_sp)
Greg Clayton0416bdf2012-01-30 09:04:36 +00002073 target_sp->GetSectionLoadList().SetSectionUnloaded (section_sp.get());
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002074 }
2075 }
2076 else
2077 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00002078 module_sp->GetFileSpec().GetPath (path, sizeof(path));
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002079 sb_error.SetErrorStringWithFormat ("no sections in object file '%s'", path);
2080 }
2081 }
2082 else
2083 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00002084 module_sp->GetFileSpec().GetPath (path, sizeof(path));
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002085 sb_error.SetErrorStringWithFormat ("no object file for module '%s'", path);
2086 }
2087 }
Greg Clayton0416bdf2012-01-30 09:04:36 +00002088 else
2089 {
2090 sb_error.SetErrorStringWithFormat ("invalid module");
2091 }
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002092 }
2093 else
2094 {
2095 sb_error.SetErrorStringWithFormat ("invalid target");
2096 }
2097 return sb_error;
2098}
2099
2100