blob: 2b6489a80a0ae0aa478985b31728c2c9b8bcad1b [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();
818 error.SetError (process_sp->Attach (attach_info));
819 // If we are doing synchronous mode, then wait for the
820 // process to stop!
821 if (target_sp->GetDebugger().GetAsyncExecution () == false)
822 process_sp->WaitForProcessToStop (NULL);
823 }
824 else
825 {
826 error.SetErrorString ("unable to create lldb_private::Process");
827 }
828 }
829 else
830 {
831 error.SetErrorString ("SBTarget is invalid");
832 }
833 return sb_process;
834}
835
836
Greg Claytond5b0b442011-12-02 02:10:57 +0000837#if defined(__APPLE__)
838
839lldb::SBProcess
840SBTarget::AttachToProcessWithID (SBListener &listener,
841 ::pid_t pid,
842 lldb::SBError& error)
843{
844 return AttachToProcessWithID (listener, (lldb::pid_t)pid, error);
845}
846
847#endif // #if defined(__APPLE__)
Greg Claytonc5f728c2010-10-06 22:10:17 +0000848
849lldb::SBProcess
Greg Claytond8c62532010-10-07 04:19:01 +0000850SBTarget::AttachToProcessWithID
Greg Claytonc5f728c2010-10-06 22:10:17 +0000851(
Greg Clayton271a5db2011-02-03 21:28:34 +0000852 SBListener &listener,
Greg Claytonc5f728c2010-10-06 22:10:17 +0000853 lldb::pid_t pid,// The process ID to attach to
854 SBError& error // An error explaining what went wrong if attach fails
855)
856{
857 SBProcess sb_process;
Greg Clayton334d33a2012-01-30 07:41:31 +0000858 ProcessSP process_sp;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000859 TargetSP target_sp(GetSP());
860 if (target_sp)
Greg Claytonc5f728c2010-10-06 22:10:17 +0000861 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000862 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytonde1dd812011-06-24 03:21:43 +0000863
864 StateType state = eStateInvalid;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000865 process_sp = target_sp->GetProcessSP();
Greg Clayton334d33a2012-01-30 07:41:31 +0000866 if (process_sp)
Greg Claytonde1dd812011-06-24 03:21:43 +0000867 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000868 state = process_sp->GetState();
Greg Claytonde1dd812011-06-24 03:21:43 +0000869
Greg Clayton334d33a2012-01-30 07:41:31 +0000870 if (process_sp->IsAlive() && state != eStateConnected)
Greg Claytonde1dd812011-06-24 03:21:43 +0000871 {
872 if (state == eStateAttaching)
873 error.SetErrorString ("process attach is in progress");
874 else
875 error.SetErrorString ("a process is already being debugged");
Greg Claytonde1dd812011-06-24 03:21:43 +0000876 return sb_process;
877 }
878 }
879
880 if (state == eStateConnected)
881 {
882 // If we are already connected, then we have already specified the
883 // listener, so if a valid listener is supplied, we need to error out
884 // to let the client know.
885 if (listener.IsValid())
886 {
887 error.SetErrorString ("process is connected and already has a listener, pass empty listener");
Greg Claytonde1dd812011-06-24 03:21:43 +0000888 return sb_process;
889 }
890 }
Greg Clayton271a5db2011-02-03 21:28:34 +0000891 else
Greg Claytonde1dd812011-06-24 03:21:43 +0000892 {
893 if (listener.IsValid())
Greg Clayton46c9a352012-02-09 06:16:32 +0000894 process_sp = target_sp->CreateProcess (listener.ref(), NULL, NULL);
Greg Claytonde1dd812011-06-24 03:21:43 +0000895 else
Greg Clayton46c9a352012-02-09 06:16:32 +0000896 process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener(), NULL, NULL);
Greg Claytonde1dd812011-06-24 03:21:43 +0000897 }
Greg Clayton334d33a2012-01-30 07:41:31 +0000898 if (process_sp)
Greg Claytonc5f728c2010-10-06 22:10:17 +0000899 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000900 sb_process.SetSP (process_sp);
901
Greg Clayton527154d2011-11-15 03:53:30 +0000902 ProcessAttachInfo attach_info;
903 attach_info.SetProcessID (pid);
Greg Clayton334d33a2012-01-30 07:41:31 +0000904 error.SetError (process_sp->Attach (attach_info));
Johnny Chen535960e2011-06-17 00:51:15 +0000905 // If we are doing synchronous mode, then wait for the
906 // process to stop!
Greg Clayton0416bdf2012-01-30 09:04:36 +0000907 if (target_sp->GetDebugger().GetAsyncExecution () == false)
Greg Clayton334d33a2012-01-30 07:41:31 +0000908 process_sp->WaitForProcessToStop (NULL);
Greg Claytonc5f728c2010-10-06 22:10:17 +0000909 }
910 else
911 {
912 error.SetErrorString ("unable to create lldb_private::Process");
913 }
914 }
915 else
916 {
917 error.SetErrorString ("SBTarget is invalid");
918 }
919 return sb_process;
920
921}
922
923lldb::SBProcess
Greg Claytond8c62532010-10-07 04:19:01 +0000924SBTarget::AttachToProcessWithName
Greg Claytonc5f728c2010-10-06 22:10:17 +0000925(
Greg Clayton271a5db2011-02-03 21:28:34 +0000926 SBListener &listener,
Greg Claytonc5f728c2010-10-06 22:10:17 +0000927 const char *name, // basename of process to attach to
928 bool wait_for, // if true wait for a new instance of "name" to be launched
929 SBError& error // An error explaining what went wrong if attach fails
930)
931{
932 SBProcess sb_process;
Greg Clayton334d33a2012-01-30 07:41:31 +0000933 ProcessSP process_sp;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000934 TargetSP target_sp(GetSP());
935 if (name && target_sp)
Greg Claytonc5f728c2010-10-06 22:10:17 +0000936 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000937 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytonbdcda462010-12-20 20:49:23 +0000938
Greg Claytonde1dd812011-06-24 03:21:43 +0000939 StateType state = eStateInvalid;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000940 process_sp = target_sp->GetProcessSP();
Greg Clayton334d33a2012-01-30 07:41:31 +0000941 if (process_sp)
Greg Claytonde1dd812011-06-24 03:21:43 +0000942 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000943 state = process_sp->GetState();
Greg Claytonde1dd812011-06-24 03:21:43 +0000944
Greg Clayton334d33a2012-01-30 07:41:31 +0000945 if (process_sp->IsAlive() && state != eStateConnected)
Greg Claytonde1dd812011-06-24 03:21:43 +0000946 {
947 if (state == eStateAttaching)
948 error.SetErrorString ("process attach is in progress");
949 else
950 error.SetErrorString ("a process is already being debugged");
Greg Claytonde1dd812011-06-24 03:21:43 +0000951 return sb_process;
952 }
953 }
954
955 if (state == eStateConnected)
956 {
957 // If we are already connected, then we have already specified the
958 // listener, so if a valid listener is supplied, we need to error out
959 // to let the client know.
960 if (listener.IsValid())
961 {
962 error.SetErrorString ("process is connected and already has a listener, pass empty listener");
Greg Claytonde1dd812011-06-24 03:21:43 +0000963 return sb_process;
964 }
965 }
Greg Clayton271a5db2011-02-03 21:28:34 +0000966 else
Greg Claytonde1dd812011-06-24 03:21:43 +0000967 {
968 if (listener.IsValid())
Greg Clayton46c9a352012-02-09 06:16:32 +0000969 process_sp = target_sp->CreateProcess (listener.ref(), NULL, NULL);
Greg Claytonde1dd812011-06-24 03:21:43 +0000970 else
Greg Clayton46c9a352012-02-09 06:16:32 +0000971 process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener(), NULL, NULL);
Greg Claytonde1dd812011-06-24 03:21:43 +0000972 }
Greg Claytonc5f728c2010-10-06 22:10:17 +0000973
Greg Clayton334d33a2012-01-30 07:41:31 +0000974 if (process_sp)
Greg Claytonc5f728c2010-10-06 22:10:17 +0000975 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000976 sb_process.SetSP (process_sp);
Greg Clayton527154d2011-11-15 03:53:30 +0000977 ProcessAttachInfo attach_info;
978 attach_info.GetExecutableFile().SetFile(name, false);
979 attach_info.SetWaitForLaunch(wait_for);
Greg Clayton334d33a2012-01-30 07:41:31 +0000980 error.SetError (process_sp->Attach (attach_info));
Johnny Chen58d02ff2011-06-17 19:21:30 +0000981 // If we are doing synchronous mode, then wait for the
982 // process to stop!
Greg Clayton0416bdf2012-01-30 09:04:36 +0000983 if (target_sp->GetDebugger().GetAsyncExecution () == false)
Greg Clayton334d33a2012-01-30 07:41:31 +0000984 process_sp->WaitForProcessToStop (NULL);
Greg Claytonc5f728c2010-10-06 22:10:17 +0000985 }
986 else
987 {
988 error.SetErrorString ("unable to create lldb_private::Process");
989 }
990 }
991 else
992 {
993 error.SetErrorString ("SBTarget is invalid");
994 }
995 return sb_process;
996
997}
998
James McIlree38093402011-03-04 00:31:13 +0000999lldb::SBProcess
1000SBTarget::ConnectRemote
1001(
1002 SBListener &listener,
1003 const char *url,
1004 const char *plugin_name,
1005 SBError& error
1006)
1007{
1008 SBProcess sb_process;
Greg Clayton334d33a2012-01-30 07:41:31 +00001009 ProcessSP process_sp;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001010 TargetSP target_sp(GetSP());
1011 if (target_sp)
James McIlree38093402011-03-04 00:31:13 +00001012 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001013 Mutex::Locker api_locker (target_sp->GetAPIMutex());
James McIlree38093402011-03-04 00:31:13 +00001014 if (listener.IsValid())
Greg Clayton46c9a352012-02-09 06:16:32 +00001015 process_sp = target_sp->CreateProcess (listener.ref(), plugin_name, NULL);
James McIlree38093402011-03-04 00:31:13 +00001016 else
Greg Clayton46c9a352012-02-09 06:16:32 +00001017 process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener(), plugin_name, NULL);
James McIlree38093402011-03-04 00:31:13 +00001018
1019
Greg Clayton334d33a2012-01-30 07:41:31 +00001020 if (process_sp)
James McIlree38093402011-03-04 00:31:13 +00001021 {
Greg Clayton334d33a2012-01-30 07:41:31 +00001022 sb_process.SetSP (process_sp);
1023 error.SetError (process_sp->ConnectRemote (url));
James McIlree38093402011-03-04 00:31:13 +00001024 }
1025 else
1026 {
1027 error.SetErrorString ("unable to create lldb_private::Process");
1028 }
1029 }
1030 else
1031 {
1032 error.SetErrorString ("SBTarget is invalid");
1033 }
1034 return sb_process;
1035}
1036
Chris Lattner24943d22010-06-08 16:52:24 +00001037SBFileSpec
1038SBTarget::GetExecutable ()
1039{
Caroline Tice7826c882010-10-26 03:11:13 +00001040
Chris Lattner24943d22010-06-08 16:52:24 +00001041 SBFileSpec exe_file_spec;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001042 TargetSP target_sp(GetSP());
1043 if (target_sp)
Chris Lattner24943d22010-06-08 16:52:24 +00001044 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001045 Module *exe_module = target_sp->GetExecutableModulePointer();
Greg Clayton5beb99d2011-08-11 02:48:45 +00001046 if (exe_module)
1047 exe_file_spec.SetFileSpec (exe_module->GetFileSpec());
Chris Lattner24943d22010-06-08 16:52:24 +00001048 }
Caroline Tice7826c882010-10-26 03:11:13 +00001049
Greg Claytone005f2c2010-11-06 01:53:30 +00001050 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001051 if (log)
1052 {
Greg Clayton49ce6822010-10-31 03:01:06 +00001053 log->Printf ("SBTarget(%p)::GetExecutable () => SBFileSpec(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +00001054 target_sp.get(), exe_file_spec.get());
Caroline Tice7826c882010-10-26 03:11:13 +00001055 }
1056
Chris Lattner24943d22010-06-08 16:52:24 +00001057 return exe_file_spec;
1058}
1059
Chris Lattner24943d22010-06-08 16:52:24 +00001060bool
Chris Lattner24943d22010-06-08 16:52:24 +00001061SBTarget::operator == (const SBTarget &rhs) const
1062{
Greg Clayton63094e02010-06-23 01:19:29 +00001063 return m_opaque_sp.get() == rhs.m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +00001064}
1065
1066bool
1067SBTarget::operator != (const SBTarget &rhs) const
1068{
Greg Clayton63094e02010-06-23 01:19:29 +00001069 return m_opaque_sp.get() != rhs.m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +00001070}
1071
Greg Clayton334d33a2012-01-30 07:41:31 +00001072lldb::TargetSP
1073SBTarget::GetSP () const
Greg Clayton15afa9f2011-10-01 02:59:24 +00001074{
1075 return m_opaque_sp;
1076}
1077
Greg Clayton63094e02010-06-23 01:19:29 +00001078void
Greg Clayton334d33a2012-01-30 07:41:31 +00001079SBTarget::SetSP (const lldb::TargetSP& target_sp)
Greg Clayton63094e02010-06-23 01:19:29 +00001080{
1081 m_opaque_sp = target_sp;
Chris Lattner24943d22010-06-08 16:52:24 +00001082}
1083
Greg Claytona3955062011-07-22 16:46:35 +00001084lldb::SBAddress
1085SBTarget::ResolveLoadAddress (lldb::addr_t vm_addr)
Greg Claytonea49cc72010-12-12 19:25:26 +00001086{
Greg Claytona3955062011-07-22 16:46:35 +00001087 lldb::SBAddress sb_addr;
1088 Address &addr = sb_addr.ref();
Greg Clayton0416bdf2012-01-30 09:04:36 +00001089 TargetSP target_sp(GetSP());
1090 if (target_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +00001091 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001092 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1093 if (target_sp->GetSectionLoadList().ResolveLoadAddress (vm_addr, addr))
Greg Claytona3955062011-07-22 16:46:35 +00001094 return sb_addr;
Greg Claytonbdcda462010-12-20 20:49:23 +00001095 }
Greg Claytonea49cc72010-12-12 19:25:26 +00001096
Greg Claytona3955062011-07-22 16:46:35 +00001097 // We have a load address that isn't in a section, just return an address
1098 // with the offset filled in (the address) and the section set to NULL
Greg Clayton3508c382012-02-24 01:59:29 +00001099 addr.SetRawAddress(vm_addr);
Greg Claytona3955062011-07-22 16:46:35 +00001100 return sb_addr;
Greg Claytonea49cc72010-12-12 19:25:26 +00001101}
1102
Greg Claytonafb81862011-03-02 21:34:46 +00001103SBSymbolContext
1104SBTarget::ResolveSymbolContextForAddress (const SBAddress& addr, uint32_t resolve_scope)
1105{
1106 SBSymbolContext sc;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001107 if (addr.IsValid())
1108 {
1109 TargetSP target_sp(GetSP());
1110 if (target_sp)
1111 target_sp->GetImages().ResolveSymbolContextForAddress (addr.ref(), resolve_scope, sc.ref());
1112 }
Greg Claytonafb81862011-03-02 21:34:46 +00001113 return sc;
1114}
1115
1116
Chris Lattner24943d22010-06-08 16:52:24 +00001117SBBreakpoint
1118SBTarget::BreakpointCreateByLocation (const char *file, uint32_t line)
1119{
Greg Claytond6d806c2010-11-08 00:28:40 +00001120 return SBBreakpoint(BreakpointCreateByLocation (SBFileSpec (file, false), line));
Chris Lattner24943d22010-06-08 16:52:24 +00001121}
1122
1123SBBreakpoint
1124SBTarget::BreakpointCreateByLocation (const SBFileSpec &sb_file_spec, uint32_t line)
1125{
Greg Claytone005f2c2010-11-06 01:53:30 +00001126 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001127
Chris Lattner24943d22010-06-08 16:52:24 +00001128 SBBreakpoint sb_bp;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001129 TargetSP target_sp(GetSP());
1130 if (target_sp && line != 0)
Greg Claytonbdcda462010-12-20 20:49:23 +00001131 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001132 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1133 *sb_bp = target_sp->CreateBreakpoint (NULL, *sb_file_spec, line, true, false);
Greg Claytonbdcda462010-12-20 20:49:23 +00001134 }
Caroline Tice7826c882010-10-26 03:11:13 +00001135
1136 if (log)
1137 {
1138 SBStream sstr;
1139 sb_bp.GetDescription (sstr);
Greg Clayton49ce6822010-10-31 03:01:06 +00001140 char path[PATH_MAX];
1141 sb_file_spec->GetPath (path, sizeof(path));
1142 log->Printf ("SBTarget(%p)::BreakpointCreateByLocation ( %s:%u ) => SBBreakpoint(%p): %s",
Greg Clayton0416bdf2012-01-30 09:04:36 +00001143 target_sp.get(),
Greg Clayton49ce6822010-10-31 03:01:06 +00001144 path,
Greg Claytona66ba462010-10-30 04:51:46 +00001145 line,
Greg Clayton49ce6822010-10-31 03:01:06 +00001146 sb_bp.get(),
Caroline Tice7826c882010-10-26 03:11:13 +00001147 sstr.GetData());
1148 }
1149
Chris Lattner24943d22010-06-08 16:52:24 +00001150 return sb_bp;
1151}
1152
1153SBBreakpoint
1154SBTarget::BreakpointCreateByName (const char *symbol_name, const char *module_name)
1155{
Greg Claytone005f2c2010-11-06 01:53:30 +00001156 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001157
Chris Lattner24943d22010-06-08 16:52:24 +00001158 SBBreakpoint sb_bp;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001159 TargetSP target_sp(GetSP());
1160 if (target_sp.get())
Chris Lattner24943d22010-06-08 16:52:24 +00001161 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001162 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Chris Lattner24943d22010-06-08 16:52:24 +00001163 if (module_name && module_name[0])
1164 {
Jim Ingham03c8ee52011-09-21 01:17:13 +00001165 FileSpecList module_spec_list;
1166 module_spec_list.Append (FileSpec (module_name, false));
Greg Clayton0416bdf2012-01-30 09:04:36 +00001167 *sb_bp = target_sp->CreateBreakpoint (&module_spec_list, NULL, symbol_name, eFunctionNameTypeAuto, false);
Chris Lattner24943d22010-06-08 16:52:24 +00001168 }
1169 else
1170 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001171 *sb_bp = target_sp->CreateBreakpoint (NULL, NULL, symbol_name, eFunctionNameTypeAuto, false);
Chris Lattner24943d22010-06-08 16:52:24 +00001172 }
1173 }
Caroline Tice7826c882010-10-26 03:11:13 +00001174
1175 if (log)
1176 {
Greg Clayton49ce6822010-10-31 03:01:06 +00001177 log->Printf ("SBTarget(%p)::BreakpointCreateByName (symbol=\"%s\", module=\"%s\") => SBBreakpoint(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +00001178 target_sp.get(), symbol_name, module_name, sb_bp.get());
Caroline Tice7826c882010-10-26 03:11:13 +00001179 }
1180
Chris Lattner24943d22010-06-08 16:52:24 +00001181 return sb_bp;
1182}
1183
Jim Inghamd6d47972011-09-23 00:54:11 +00001184lldb::SBBreakpoint
1185SBTarget::BreakpointCreateByName (const char *symbol_name,
1186 const SBFileSpecList &module_list,
1187 const SBFileSpecList &comp_unit_list)
1188{
Jim Ingham1fb8a2d2011-10-11 01:18:55 +00001189 uint32_t name_type_mask = eFunctionNameTypeAuto;
1190 return BreakpointCreateByName (symbol_name, name_type_mask, module_list, comp_unit_list);
1191}
1192
1193lldb::SBBreakpoint
1194SBTarget::BreakpointCreateByName (const char *symbol_name,
1195 uint32_t name_type_mask,
1196 const SBFileSpecList &module_list,
1197 const SBFileSpecList &comp_unit_list)
1198{
Jim Inghamd6d47972011-09-23 00:54:11 +00001199 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1200
1201 SBBreakpoint sb_bp;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001202 TargetSP target_sp(GetSP());
1203 if (target_sp && symbol_name && symbol_name[0])
Jim Inghamd6d47972011-09-23 00:54:11 +00001204 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001205 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1206 *sb_bp = target_sp->CreateBreakpoint (module_list.get(),
Jim Inghamd6d47972011-09-23 00:54:11 +00001207 comp_unit_list.get(),
1208 symbol_name,
Jim Ingham1fb8a2d2011-10-11 01:18:55 +00001209 name_type_mask,
Jim Inghamd6d47972011-09-23 00:54:11 +00001210 false);
1211 }
1212
1213 if (log)
1214 {
Jim Ingham1fb8a2d2011-10-11 01:18:55 +00001215 log->Printf ("SBTarget(%p)::BreakpointCreateByName (symbol=\"%s\", name_type: %d) => SBBreakpoint(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +00001216 target_sp.get(), symbol_name, name_type_mask, sb_bp.get());
Jim Inghamd6d47972011-09-23 00:54:11 +00001217 }
1218
1219 return sb_bp;
1220}
1221
1222
Chris Lattner24943d22010-06-08 16:52:24 +00001223SBBreakpoint
1224SBTarget::BreakpointCreateByRegex (const char *symbol_name_regex, const char *module_name)
1225{
Greg Claytone005f2c2010-11-06 01:53:30 +00001226 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001227
Chris Lattner24943d22010-06-08 16:52:24 +00001228 SBBreakpoint sb_bp;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001229 TargetSP target_sp(GetSP());
1230 if (target_sp && symbol_name_regex && symbol_name_regex[0])
Chris Lattner24943d22010-06-08 16:52:24 +00001231 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001232 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Chris Lattner24943d22010-06-08 16:52:24 +00001233 RegularExpression regexp(symbol_name_regex);
1234
1235 if (module_name && module_name[0])
1236 {
Jim Ingham03c8ee52011-09-21 01:17:13 +00001237 FileSpecList module_spec_list;
1238 module_spec_list.Append (FileSpec (module_name, false));
Chris Lattner24943d22010-06-08 16:52:24 +00001239
Greg Clayton0416bdf2012-01-30 09:04:36 +00001240 *sb_bp = target_sp->CreateFuncRegexBreakpoint (&module_spec_list, NULL, regexp, false);
Chris Lattner24943d22010-06-08 16:52:24 +00001241 }
1242 else
1243 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001244 *sb_bp = target_sp->CreateFuncRegexBreakpoint (NULL, NULL, regexp, false);
Chris Lattner24943d22010-06-08 16:52:24 +00001245 }
1246 }
Caroline Tice7826c882010-10-26 03:11:13 +00001247
1248 if (log)
1249 {
Greg Clayton49ce6822010-10-31 03:01:06 +00001250 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (symbol_regex=\"%s\", module_name=\"%s\") => SBBreakpoint(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +00001251 target_sp.get(), symbol_name_regex, module_name, sb_bp.get());
Caroline Tice7826c882010-10-26 03:11:13 +00001252 }
1253
Chris Lattner24943d22010-06-08 16:52:24 +00001254 return sb_bp;
1255}
1256
Jim Inghamd6d47972011-09-23 00:54:11 +00001257lldb::SBBreakpoint
1258SBTarget::BreakpointCreateByRegex (const char *symbol_name_regex,
1259 const SBFileSpecList &module_list,
1260 const SBFileSpecList &comp_unit_list)
1261{
1262 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Chris Lattner24943d22010-06-08 16:52:24 +00001263
Jim Inghamd6d47972011-09-23 00:54:11 +00001264 SBBreakpoint sb_bp;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001265 TargetSP target_sp(GetSP());
1266 if (target_sp && symbol_name_regex && symbol_name_regex[0])
Jim Inghamd6d47972011-09-23 00:54:11 +00001267 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001268 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Jim Inghamd6d47972011-09-23 00:54:11 +00001269 RegularExpression regexp(symbol_name_regex);
1270
Greg Clayton0416bdf2012-01-30 09:04:36 +00001271 *sb_bp = target_sp->CreateFuncRegexBreakpoint (module_list.get(), comp_unit_list.get(), regexp, false);
Jim Inghamd6d47972011-09-23 00:54:11 +00001272 }
1273
1274 if (log)
1275 {
1276 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (symbol_regex=\"%s\") => SBBreakpoint(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +00001277 target_sp.get(), symbol_name_regex, sb_bp.get());
Jim Inghamd6d47972011-09-23 00:54:11 +00001278 }
1279
1280 return sb_bp;
1281}
Chris Lattner24943d22010-06-08 16:52:24 +00001282
1283SBBreakpoint
1284SBTarget::BreakpointCreateByAddress (addr_t address)
1285{
Greg Claytone005f2c2010-11-06 01:53:30 +00001286 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001287
Chris Lattner24943d22010-06-08 16:52:24 +00001288 SBBreakpoint sb_bp;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001289 TargetSP target_sp(GetSP());
1290 if (target_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +00001291 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001292 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1293 *sb_bp = target_sp->CreateBreakpoint (address, false);
Greg Claytonbdcda462010-12-20 20:49:23 +00001294 }
Caroline Tice7826c882010-10-26 03:11:13 +00001295
1296 if (log)
1297 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001298 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 +00001299 }
1300
Chris Lattner24943d22010-06-08 16:52:24 +00001301 return sb_bp;
1302}
1303
Jim Ingham03c8ee52011-09-21 01:17:13 +00001304lldb::SBBreakpoint
1305SBTarget::BreakpointCreateBySourceRegex (const char *source_regex, const lldb::SBFileSpec &source_file, const char *module_name)
1306{
1307 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1308
1309 SBBreakpoint sb_bp;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001310 TargetSP target_sp(GetSP());
1311 if (target_sp && source_regex && source_regex[0])
Jim Ingham03c8ee52011-09-21 01:17:13 +00001312 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001313 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Jim Ingham03c8ee52011-09-21 01:17:13 +00001314 RegularExpression regexp(source_regex);
Jim Inghamd6d47972011-09-23 00:54:11 +00001315 FileSpecList source_file_spec_list;
1316 source_file_spec_list.Append (source_file.ref());
Jim Ingham03c8ee52011-09-21 01:17:13 +00001317
1318 if (module_name && module_name[0])
1319 {
1320 FileSpecList module_spec_list;
1321 module_spec_list.Append (FileSpec (module_name, false));
1322
Greg Clayton0416bdf2012-01-30 09:04:36 +00001323 *sb_bp = target_sp->CreateSourceRegexBreakpoint (&module_spec_list, &source_file_spec_list, regexp, false);
Jim Ingham03c8ee52011-09-21 01:17:13 +00001324 }
1325 else
1326 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001327 *sb_bp = target_sp->CreateSourceRegexBreakpoint (NULL, &source_file_spec_list, regexp, false);
Jim Ingham03c8ee52011-09-21 01:17:13 +00001328 }
1329 }
1330
1331 if (log)
1332 {
1333 char path[PATH_MAX];
1334 source_file->GetPath (path, sizeof(path));
1335 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (source_regex=\"%s\", file=\"%s\", module_name=\"%s\") => SBBreakpoint(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +00001336 target_sp.get(), source_regex, path, module_name, sb_bp.get());
Jim Ingham03c8ee52011-09-21 01:17:13 +00001337 }
1338
1339 return sb_bp;
1340}
1341
Jim Inghamd6d47972011-09-23 00:54:11 +00001342lldb::SBBreakpoint
1343SBTarget::BreakpointCreateBySourceRegex (const char *source_regex,
1344 const SBFileSpecList &module_list,
1345 const lldb::SBFileSpecList &source_file_list)
1346{
1347 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1348
1349 SBBreakpoint sb_bp;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001350 TargetSP target_sp(GetSP());
1351 if (target_sp && source_regex && source_regex[0])
Jim Inghamd6d47972011-09-23 00:54:11 +00001352 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001353 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Jim Inghamd6d47972011-09-23 00:54:11 +00001354 RegularExpression regexp(source_regex);
Greg Clayton0416bdf2012-01-30 09:04:36 +00001355 *sb_bp = target_sp->CreateSourceRegexBreakpoint (module_list.get(), source_file_list.get(), regexp, false);
Jim Inghamd6d47972011-09-23 00:54:11 +00001356 }
1357
1358 if (log)
1359 {
1360 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (source_regex=\"%s\") => SBBreakpoint(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +00001361 target_sp.get(), source_regex, sb_bp.get());
Jim Inghamd6d47972011-09-23 00:54:11 +00001362 }
1363
1364 return sb_bp;
1365}
Jim Ingham03c8ee52011-09-21 01:17:13 +00001366
Greg Claytonc7f5d5c2010-07-23 23:33:17 +00001367uint32_t
1368SBTarget::GetNumBreakpoints () const
1369{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001370 TargetSP target_sp(GetSP());
1371 if (target_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +00001372 {
1373 // The breakpoint list is thread safe, no need to lock
Greg Clayton0416bdf2012-01-30 09:04:36 +00001374 return target_sp->GetBreakpointList().GetSize();
Greg Claytonbdcda462010-12-20 20:49:23 +00001375 }
Greg Claytonc7f5d5c2010-07-23 23:33:17 +00001376 return 0;
1377}
1378
1379SBBreakpoint
1380SBTarget::GetBreakpointAtIndex (uint32_t idx) const
1381{
1382 SBBreakpoint sb_breakpoint;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001383 TargetSP target_sp(GetSP());
1384 if (target_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +00001385 {
1386 // The breakpoint list is thread safe, no need to lock
Greg Clayton0416bdf2012-01-30 09:04:36 +00001387 *sb_breakpoint = target_sp->GetBreakpointList().GetBreakpointAtIndex(idx);
Greg Claytonbdcda462010-12-20 20:49:23 +00001388 }
Greg Claytonc7f5d5c2010-07-23 23:33:17 +00001389 return sb_breakpoint;
1390}
Chris Lattner24943d22010-06-08 16:52:24 +00001391
1392bool
1393SBTarget::BreakpointDelete (break_id_t bp_id)
1394{
Greg Claytone005f2c2010-11-06 01:53:30 +00001395 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001396
Caroline Tice7826c882010-10-26 03:11:13 +00001397 bool result = false;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001398 TargetSP target_sp(GetSP());
1399 if (target_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +00001400 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001401 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1402 result = target_sp->RemoveBreakpointByID (bp_id);
Greg Claytonbdcda462010-12-20 20:49:23 +00001403 }
Caroline Tice7826c882010-10-26 03:11:13 +00001404
1405 if (log)
1406 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001407 log->Printf ("SBTarget(%p)::BreakpointDelete (bp_id=%d) => %i", target_sp.get(), (uint32_t) bp_id, result);
Caroline Tice7826c882010-10-26 03:11:13 +00001408 }
1409
1410 return result;
Chris Lattner24943d22010-06-08 16:52:24 +00001411}
1412
Johnny Chen096c2932011-09-26 22:40:50 +00001413SBBreakpoint
1414SBTarget::FindBreakpointByID (break_id_t bp_id)
1415{
1416 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1417
1418 SBBreakpoint sb_breakpoint;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001419 TargetSP target_sp(GetSP());
1420 if (target_sp && bp_id != LLDB_INVALID_BREAK_ID)
Johnny Chen096c2932011-09-26 22:40:50 +00001421 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001422 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1423 *sb_breakpoint = target_sp->GetBreakpointByID (bp_id);
Johnny Chen096c2932011-09-26 22:40:50 +00001424 }
1425
1426 if (log)
1427 {
1428 log->Printf ("SBTarget(%p)::FindBreakpointByID (bp_id=%d) => SBBreakpoint(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +00001429 target_sp.get(), (uint32_t) bp_id, sb_breakpoint.get());
Johnny Chen096c2932011-09-26 22:40:50 +00001430 }
1431
1432 return sb_breakpoint;
1433}
1434
Chris Lattner24943d22010-06-08 16:52:24 +00001435bool
1436SBTarget::EnableAllBreakpoints ()
1437{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001438 TargetSP target_sp(GetSP());
1439 if (target_sp)
Chris Lattner24943d22010-06-08 16:52:24 +00001440 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001441 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1442 target_sp->EnableAllBreakpoints ();
Chris Lattner24943d22010-06-08 16:52:24 +00001443 return true;
1444 }
1445 return false;
1446}
1447
1448bool
1449SBTarget::DisableAllBreakpoints ()
1450{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001451 TargetSP target_sp(GetSP());
1452 if (target_sp)
Chris Lattner24943d22010-06-08 16:52:24 +00001453 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001454 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1455 target_sp->DisableAllBreakpoints ();
Chris Lattner24943d22010-06-08 16:52:24 +00001456 return true;
1457 }
1458 return false;
1459}
1460
1461bool
1462SBTarget::DeleteAllBreakpoints ()
1463{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001464 TargetSP target_sp(GetSP());
1465 if (target_sp)
Chris Lattner24943d22010-06-08 16:52:24 +00001466 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001467 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1468 target_sp->RemoveAllBreakpoints ();
Chris Lattner24943d22010-06-08 16:52:24 +00001469 return true;
1470 }
1471 return false;
1472}
1473
Johnny Chen096c2932011-09-26 22:40:50 +00001474uint32_t
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001475SBTarget::GetNumWatchpoints () const
Johnny Chen096c2932011-09-26 22:40:50 +00001476{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001477 TargetSP target_sp(GetSP());
1478 if (target_sp)
Johnny Chen096c2932011-09-26 22:40:50 +00001479 {
Johnny Chenecd4feb2011-10-14 00:42:25 +00001480 // The watchpoint list is thread safe, no need to lock
Greg Clayton0416bdf2012-01-30 09:04:36 +00001481 return target_sp->GetWatchpointList().GetSize();
Johnny Chen096c2932011-09-26 22:40:50 +00001482 }
1483 return 0;
1484}
1485
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001486SBWatchpoint
1487SBTarget::GetWatchpointAtIndex (uint32_t idx) const
Johnny Chen5eb54bb2011-09-27 20:29:45 +00001488{
Johnny Chenecd4feb2011-10-14 00:42:25 +00001489 SBWatchpoint sb_watchpoint;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001490 TargetSP target_sp(GetSP());
1491 if (target_sp)
Johnny Chen096c2932011-09-26 22:40:50 +00001492 {
Johnny Chenecd4feb2011-10-14 00:42:25 +00001493 // The watchpoint list is thread safe, no need to lock
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001494 sb_watchpoint.SetSP (target_sp->GetWatchpointList().GetByIndex(idx));
Johnny Chen096c2932011-09-26 22:40:50 +00001495 }
Johnny Chenecd4feb2011-10-14 00:42:25 +00001496 return sb_watchpoint;
Johnny Chen096c2932011-09-26 22:40:50 +00001497}
1498
1499bool
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001500SBTarget::DeleteWatchpoint (watch_id_t wp_id)
Johnny Chen096c2932011-09-26 22:40:50 +00001501{
1502 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1503
1504 bool result = false;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001505 TargetSP target_sp(GetSP());
1506 if (target_sp)
Johnny Chen096c2932011-09-26 22:40:50 +00001507 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001508 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1509 result = target_sp->RemoveWatchpointByID (wp_id);
Johnny Chen096c2932011-09-26 22:40:50 +00001510 }
1511
1512 if (log)
1513 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001514 log->Printf ("SBTarget(%p)::WatchpointDelete (wp_id=%d) => %i", target_sp.get(), (uint32_t) wp_id, result);
Johnny Chen096c2932011-09-26 22:40:50 +00001515 }
1516
1517 return result;
1518}
1519
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001520SBWatchpoint
1521SBTarget::FindWatchpointByID (lldb::watch_id_t wp_id)
Johnny Chen096c2932011-09-26 22:40:50 +00001522{
1523 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1524
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001525 SBWatchpoint sb_watchpoint;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001526 lldb::WatchpointSP watchpoint_sp;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001527 TargetSP target_sp(GetSP());
1528 if (target_sp && wp_id != LLDB_INVALID_WATCH_ID)
Johnny Chen096c2932011-09-26 22:40:50 +00001529 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001530 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001531 watchpoint_sp = target_sp->GetWatchpointList().FindByID(wp_id);
1532 sb_watchpoint.SetSP (watchpoint_sp);
Johnny Chen096c2932011-09-26 22:40:50 +00001533 }
1534
1535 if (log)
1536 {
Johnny Chenecd4feb2011-10-14 00:42:25 +00001537 log->Printf ("SBTarget(%p)::FindWatchpointByID (bp_id=%d) => SBWatchpoint(%p)",
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001538 target_sp.get(), (uint32_t) wp_id, watchpoint_sp.get());
Johnny Chen096c2932011-09-26 22:40:50 +00001539 }
1540
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001541 return sb_watchpoint;
1542}
1543
1544lldb::SBWatchpoint
1545SBTarget::WatchAddress (lldb::addr_t addr, size_t size, bool read, bool write)
1546{
1547 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1548
1549 SBWatchpoint sb_watchpoint;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001550 lldb::WatchpointSP watchpoint_sp;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001551 TargetSP target_sp(GetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001552 if (target_sp && (read || write) && addr != LLDB_INVALID_ADDRESS && size > 0)
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001553 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001554 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001555 uint32_t watch_type = 0;
1556 if (read)
1557 watch_type |= LLDB_WATCH_TYPE_READ;
1558 if (write)
1559 watch_type |= LLDB_WATCH_TYPE_WRITE;
1560 watchpoint_sp = target_sp->CreateWatchpoint(addr, size, watch_type);
1561 sb_watchpoint.SetSP (watchpoint_sp);
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001562 }
1563
1564 if (log)
1565 {
1566 log->Printf ("SBTarget(%p)::WatchAddress (addr=0x%llx, 0x%u) => SBWatchpoint(%p)",
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001567 target_sp.get(), addr, (uint32_t) size, watchpoint_sp.get());
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001568 }
1569
1570 return sb_watchpoint;
Johnny Chen096c2932011-09-26 22:40:50 +00001571}
1572
1573bool
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001574SBTarget::EnableAllWatchpoints ()
Johnny Chen096c2932011-09-26 22:40:50 +00001575{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001576 TargetSP target_sp(GetSP());
1577 if (target_sp)
Johnny Chen096c2932011-09-26 22:40:50 +00001578 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001579 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1580 target_sp->EnableAllWatchpoints ();
Johnny Chen096c2932011-09-26 22:40:50 +00001581 return true;
1582 }
1583 return false;
1584}
1585
1586bool
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001587SBTarget::DisableAllWatchpoints ()
Johnny Chen096c2932011-09-26 22:40:50 +00001588{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001589 TargetSP target_sp(GetSP());
1590 if (target_sp)
Johnny Chen096c2932011-09-26 22:40:50 +00001591 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001592 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1593 target_sp->DisableAllWatchpoints ();
Johnny Chen096c2932011-09-26 22:40:50 +00001594 return true;
1595 }
1596 return false;
1597}
1598
1599bool
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001600SBTarget::DeleteAllWatchpoints ()
Johnny Chen096c2932011-09-26 22:40:50 +00001601{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001602 TargetSP target_sp(GetSP());
1603 if (target_sp)
Johnny Chen096c2932011-09-26 22:40:50 +00001604 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001605 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1606 target_sp->RemoveAllWatchpoints ();
Johnny Chen096c2932011-09-26 22:40:50 +00001607 return true;
1608 }
1609 return false;
1610}
1611
Chris Lattner24943d22010-06-08 16:52:24 +00001612
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001613lldb::SBModule
1614SBTarget::AddModule (const char *path,
1615 const char *triple,
1616 const char *uuid_cstr)
1617{
1618 lldb::SBModule sb_module;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001619 TargetSP target_sp(GetSP());
1620 if (target_sp)
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001621 {
1622 FileSpec module_file_spec;
1623 UUID module_uuid;
1624 ArchSpec module_arch;
1625
1626 if (path)
1627 module_file_spec.SetFile(path, false);
1628
1629 if (uuid_cstr)
1630 module_uuid.SetfromCString(uuid_cstr);
1631
1632 if (triple)
Greg Clayton0416bdf2012-01-30 09:04:36 +00001633 module_arch.SetTriple (triple, target_sp->GetPlatform ().get());
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001634
Greg Clayton0416bdf2012-01-30 09:04:36 +00001635 sb_module.SetSP(target_sp->GetSharedModule (module_file_spec,
1636 module_arch,
1637 uuid_cstr ? &module_uuid : NULL));
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001638 }
1639 return sb_module;
1640}
1641
1642bool
1643SBTarget::AddModule (lldb::SBModule &module)
1644{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001645 TargetSP target_sp(GetSP());
1646 if (target_sp)
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001647 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001648 target_sp->GetImages().AppendIfNeeded (module.GetSP());
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001649 return true;
1650 }
1651 return false;
1652}
1653
Chris Lattner24943d22010-06-08 16:52:24 +00001654uint32_t
1655SBTarget::GetNumModules () const
1656{
Greg Claytone005f2c2010-11-06 01:53:30 +00001657 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001658
Caroline Tice7826c882010-10-26 03:11:13 +00001659 uint32_t num = 0;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001660 TargetSP target_sp(GetSP());
1661 if (target_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +00001662 {
1663 // The module list is thread safe, no need to lock
Greg Clayton0416bdf2012-01-30 09:04:36 +00001664 num = target_sp->GetImages().GetSize();
Greg Claytonbdcda462010-12-20 20:49:23 +00001665 }
Caroline Tice7826c882010-10-26 03:11:13 +00001666
1667 if (log)
Greg Clayton0416bdf2012-01-30 09:04:36 +00001668 log->Printf ("SBTarget(%p)::GetNumModules () => %d", target_sp.get(), num);
Caroline Tice7826c882010-10-26 03:11:13 +00001669
1670 return num;
Chris Lattner24943d22010-06-08 16:52:24 +00001671}
1672
Greg Clayton43490d12010-07-30 20:12:55 +00001673void
1674SBTarget::Clear ()
1675{
Greg Claytone005f2c2010-11-06 01:53:30 +00001676 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001677
1678 if (log)
Greg Clayton3f5ee7f2010-10-29 04:59:35 +00001679 log->Printf ("SBTarget(%p)::Clear ()", m_opaque_sp.get());
Caroline Tice7826c882010-10-26 03:11:13 +00001680
Greg Clayton43490d12010-07-30 20:12:55 +00001681 m_opaque_sp.reset();
1682}
1683
1684
Chris Lattner24943d22010-06-08 16:52:24 +00001685SBModule
1686SBTarget::FindModule (const SBFileSpec &sb_file_spec)
1687{
1688 SBModule sb_module;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001689 TargetSP target_sp(GetSP());
1690 if (target_sp && sb_file_spec.IsValid())
Greg Claytonbdcda462010-12-20 20:49:23 +00001691 {
1692 // The module list is thread safe, no need to lock
Greg Clayton0416bdf2012-01-30 09:04:36 +00001693 sb_module.SetSP (target_sp->GetImages().FindFirstModuleForFileSpec (*sb_file_spec, NULL, NULL));
Greg Claytonbdcda462010-12-20 20:49:23 +00001694 }
Chris Lattner24943d22010-06-08 16:52:24 +00001695 return sb_module;
1696}
1697
Greg Clayton1b925202012-01-29 06:07:39 +00001698lldb::ByteOrder
1699SBTarget::GetByteOrder ()
1700{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001701 TargetSP target_sp(GetSP());
1702 if (target_sp)
1703 return target_sp->GetArchitecture().GetByteOrder();
Greg Clayton1b925202012-01-29 06:07:39 +00001704 return eByteOrderInvalid;
1705}
1706
1707const char *
1708SBTarget::GetTriple ()
1709{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001710 TargetSP target_sp(GetSP());
1711 if (target_sp)
Greg Clayton1b925202012-01-29 06:07:39 +00001712 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001713 std::string triple (target_sp->GetArchitecture().GetTriple().str());
Greg Clayton1b925202012-01-29 06:07:39 +00001714 // Unique the string so we don't run into ownership issues since
1715 // the const strings put the string into the string pool once and
1716 // the strings never comes out
1717 ConstString const_triple (triple.c_str());
1718 return const_triple.GetCString();
1719 }
1720 return NULL;
1721}
1722
1723uint32_t
1724SBTarget::GetAddressByteSize()
1725{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001726 TargetSP target_sp(GetSP());
1727 if (target_sp)
1728 return target_sp->GetArchitecture().GetAddressByteSize();
Greg Clayton1b925202012-01-29 06:07:39 +00001729 return sizeof(void*);
1730}
1731
1732
Chris Lattner24943d22010-06-08 16:52:24 +00001733SBModule
1734SBTarget::GetModuleAtIndex (uint32_t idx)
1735{
Greg Claytone005f2c2010-11-06 01:53:30 +00001736 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001737
Chris Lattner24943d22010-06-08 16:52:24 +00001738 SBModule sb_module;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001739 ModuleSP module_sp;
1740 TargetSP target_sp(GetSP());
1741 if (target_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +00001742 {
1743 // The module list is thread safe, no need to lock
Greg Clayton0416bdf2012-01-30 09:04:36 +00001744 module_sp = target_sp->GetImages().GetModuleAtIndex(idx);
1745 sb_module.SetSP (module_sp);
Greg Claytonbdcda462010-12-20 20:49:23 +00001746 }
Caroline Tice7826c882010-10-26 03:11:13 +00001747
1748 if (log)
1749 {
Greg Clayton49ce6822010-10-31 03:01:06 +00001750 log->Printf ("SBTarget(%p)::GetModuleAtIndex (idx=%d) => SBModule(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +00001751 target_sp.get(), idx, module_sp.get());
Caroline Tice7826c882010-10-26 03:11:13 +00001752 }
1753
Chris Lattner24943d22010-06-08 16:52:24 +00001754 return sb_module;
1755}
1756
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001757bool
1758SBTarget::RemoveModule (lldb::SBModule module)
1759{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001760 TargetSP target_sp(GetSP());
1761 if (target_sp)
1762 return target_sp->GetImages().Remove(module.GetSP());
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001763 return false;
1764}
1765
Chris Lattner24943d22010-06-08 16:52:24 +00001766
1767SBBroadcaster
1768SBTarget::GetBroadcaster () const
1769{
Greg Claytone005f2c2010-11-06 01:53:30 +00001770 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001771
Greg Clayton0416bdf2012-01-30 09:04:36 +00001772 TargetSP target_sp(GetSP());
1773 SBBroadcaster broadcaster(target_sp.get(), false);
Caroline Tice7826c882010-10-26 03:11:13 +00001774
1775 if (log)
Greg Clayton3f5ee7f2010-10-29 04:59:35 +00001776 log->Printf ("SBTarget(%p)::GetBroadcaster () => SBBroadcaster(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +00001777 target_sp.get(), broadcaster.get());
Caroline Tice7826c882010-10-26 03:11:13 +00001778
Chris Lattner24943d22010-06-08 16:52:24 +00001779 return broadcaster;
1780}
1781
Caroline Tice98f930f2010-09-20 05:20:02 +00001782bool
Caroline Tice7826c882010-10-26 03:11:13 +00001783SBTarget::GetDescription (SBStream &description, lldb::DescriptionLevel description_level)
Caroline Tice98f930f2010-09-20 05:20:02 +00001784{
Greg Clayton96154be2011-11-13 06:57:31 +00001785 Stream &strm = description.ref();
1786
Greg Clayton0416bdf2012-01-30 09:04:36 +00001787 TargetSP target_sp(GetSP());
1788 if (target_sp)
Caroline Ticee7a566e2010-09-20 16:21:41 +00001789 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001790 target_sp->Dump (&strm, description_level);
Caroline Tice7826c882010-10-26 03:11:13 +00001791 }
1792 else
Greg Clayton96154be2011-11-13 06:57:31 +00001793 strm.PutCString ("No value");
Caroline Tice7826c882010-10-26 03:11:13 +00001794
1795 return true;
1796}
1797
Greg Clayton7dd5c512012-02-06 01:44:54 +00001798lldb::SBSymbolContextList
1799SBTarget::FindFunctions (const char *name, uint32_t name_type_mask)
Greg Clayton4ed315f2011-06-21 01:34:41 +00001800{
Greg Clayton7dd5c512012-02-06 01:44:54 +00001801 lldb::SBSymbolContextList sb_sc_list;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001802 if (name && name[0])
Greg Clayton4ed315f2011-06-21 01:34:41 +00001803 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001804 TargetSP target_sp(GetSP());
1805 if (target_sp)
1806 {
1807 const bool symbols_ok = true;
Sean Callanan302d78c2012-02-10 22:52:19 +00001808 const bool inlines_ok = true;
Greg Clayton7dd5c512012-02-06 01:44:54 +00001809 const bool append = true;
1810 target_sp->GetImages().FindFunctions (ConstString(name),
1811 name_type_mask,
Sean Callanan302d78c2012-02-10 22:52:19 +00001812 symbols_ok,
1813 inlines_ok,
Greg Clayton7dd5c512012-02-06 01:44:54 +00001814 append,
1815 *sb_sc_list);
Greg Clayton0416bdf2012-01-30 09:04:36 +00001816 }
Greg Clayton4ed315f2011-06-21 01:34:41 +00001817 }
Greg Clayton7dd5c512012-02-06 01:44:54 +00001818 return sb_sc_list;
Greg Clayton4ed315f2011-06-21 01:34:41 +00001819}
1820
Enrico Granata979e20d2011-07-29 19:53:35 +00001821lldb::SBType
1822SBTarget::FindFirstType (const char* type)
1823{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001824 TargetSP target_sp(GetSP());
1825 if (type && target_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +00001826 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001827 size_t count = target_sp->GetImages().GetSize();
Enrico Granata979e20d2011-07-29 19:53:35 +00001828 for (size_t idx = 0; idx < count; idx++)
1829 {
1830 SBType found_at_idx = GetModuleAtIndex(idx).FindFirstType(type);
1831
1832 if (found_at_idx.IsValid())
1833 return found_at_idx;
1834 }
1835 }
1836 return SBType();
1837}
1838
1839lldb::SBTypeList
1840SBTarget::FindTypes (const char* type)
1841{
1842
1843 SBTypeList retval;
1844
Greg Clayton0416bdf2012-01-30 09:04:36 +00001845 TargetSP target_sp(GetSP());
1846 if (type && target_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +00001847 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001848 ModuleList& images = target_sp->GetImages();
Enrico Granata979e20d2011-07-29 19:53:35 +00001849 ConstString name_const(type);
1850 SymbolContext sc;
1851 TypeList type_list;
1852
1853 uint32_t num_matches = images.FindTypes(sc,
1854 name_const,
1855 true,
1856 UINT32_MAX,
1857 type_list);
1858
1859 for (size_t idx = 0; idx < num_matches; idx++)
1860 {
Greg Clayton0fb0bcc2011-08-03 22:57:10 +00001861 TypeSP type_sp (type_list.GetTypeAtIndex(idx));
1862 if (type_sp)
1863 retval.Append(SBType(type_sp));
Enrico Granata979e20d2011-07-29 19:53:35 +00001864 }
1865 }
1866 return retval;
1867}
1868
Greg Clayton917c0002011-06-29 22:09:02 +00001869SBValueList
1870SBTarget::FindGlobalVariables (const char *name, uint32_t max_matches)
1871{
1872 SBValueList sb_value_list;
1873
Greg Clayton0416bdf2012-01-30 09:04:36 +00001874 TargetSP target_sp(GetSP());
1875 if (name && target_sp)
Greg Clayton917c0002011-06-29 22:09:02 +00001876 {
1877 VariableList variable_list;
1878 const bool append = true;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001879 const uint32_t match_count = target_sp->GetImages().FindGlobalVariables (ConstString (name),
1880 append,
1881 max_matches,
1882 variable_list);
Greg Clayton917c0002011-06-29 22:09:02 +00001883
1884 if (match_count > 0)
1885 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001886 ExecutionContextScope *exe_scope = target_sp->GetProcessSP().get();
Greg Clayton917c0002011-06-29 22:09:02 +00001887 if (exe_scope == NULL)
Greg Clayton0416bdf2012-01-30 09:04:36 +00001888 exe_scope = target_sp.get();
Greg Clayton917c0002011-06-29 22:09:02 +00001889 ValueObjectList &value_object_list = sb_value_list.ref();
1890 for (uint32_t i=0; i<match_count; ++i)
1891 {
1892 lldb::ValueObjectSP valobj_sp (ValueObjectVariable::Create (exe_scope, variable_list.GetVariableAtIndex(i)));
1893 if (valobj_sp)
1894 value_object_list.Append(valobj_sp);
1895 }
1896 }
1897 }
1898
1899 return sb_value_list;
1900}
1901
Jim Inghamcc637462011-09-13 00:29:56 +00001902SBSourceManager
1903SBTarget::GetSourceManager()
1904{
1905 SBSourceManager source_manager (*this);
1906 return source_manager;
1907}
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001908
Sean Callananef1f6902011-12-14 23:49:37 +00001909lldb::SBInstructionList
1910SBTarget::GetInstructions (lldb::SBAddress base_addr, const void *buf, size_t size)
1911{
1912 SBInstructionList sb_instructions;
1913
Greg Clayton0416bdf2012-01-30 09:04:36 +00001914 TargetSP target_sp(GetSP());
1915 if (target_sp)
Sean Callananef1f6902011-12-14 23:49:37 +00001916 {
1917 Address addr;
1918
1919 if (base_addr.get())
1920 addr = *base_addr.get();
1921
Greg Clayton0416bdf2012-01-30 09:04:36 +00001922 sb_instructions.SetDisassembler (Disassembler::DisassembleBytes (target_sp->GetArchitecture(),
Sean Callananef1f6902011-12-14 23:49:37 +00001923 NULL,
1924 addr,
1925 buf,
1926 size));
1927 }
1928
1929 return sb_instructions;
1930}
1931
1932lldb::SBInstructionList
1933SBTarget::GetInstructions (lldb::addr_t base_addr, const void *buf, size_t size)
1934{
1935 return GetInstructions (ResolveLoadAddress(base_addr), buf, size);
1936}
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001937
1938SBError
1939SBTarget::SetSectionLoadAddress (lldb::SBSection section,
1940 lldb::addr_t section_base_addr)
1941{
1942 SBError sb_error;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001943 TargetSP target_sp(GetSP());
1944 if (target_sp)
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001945 {
1946 if (!section.IsValid())
1947 {
1948 sb_error.SetErrorStringWithFormat ("invalid section");
1949 }
1950 else
1951 {
Greg Clayton3508c382012-02-24 01:59:29 +00001952 target_sp->GetSectionLoadList().SetSectionLoadAddress (section.GetSP().get(), section_base_addr);
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001953 }
1954 }
1955 else
1956 {
1957 sb_error.SetErrorStringWithFormat ("invalid target");
1958 }
1959 return sb_error;
1960}
1961
1962SBError
1963SBTarget::ClearSectionLoadAddress (lldb::SBSection section)
1964{
1965 SBError sb_error;
1966
Greg Clayton0416bdf2012-01-30 09:04:36 +00001967 TargetSP target_sp(GetSP());
1968 if (target_sp)
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001969 {
1970 if (!section.IsValid())
1971 {
1972 sb_error.SetErrorStringWithFormat ("invalid section");
1973 }
1974 else
1975 {
Greg Clayton3508c382012-02-24 01:59:29 +00001976 target_sp->GetSectionLoadList().SetSectionUnloaded (section.GetSP().get());
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001977 }
1978 }
1979 else
1980 {
1981 sb_error.SetErrorStringWithFormat ("invalid target");
1982 }
1983 return sb_error;
1984}
1985
1986SBError
1987SBTarget::SetModuleLoadAddress (lldb::SBModule module, int64_t slide_offset)
1988{
1989 SBError sb_error;
1990
1991 char path[PATH_MAX];
Greg Clayton0416bdf2012-01-30 09:04:36 +00001992 TargetSP target_sp(GetSP());
1993 if (target_sp)
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001994 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001995 ModuleSP module_sp (module.GetSP());
1996 if (module_sp)
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001997 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001998 ObjectFile *objfile = module_sp->GetObjectFile();
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001999 if (objfile)
2000 {
2001 SectionList *section_list = objfile->GetSectionList();
2002 if (section_list)
2003 {
2004 const size_t num_sections = section_list->GetSize();
2005 for (size_t sect_idx = 0; sect_idx < num_sections; ++sect_idx)
2006 {
2007 SectionSP section_sp (section_list->GetSectionAtIndex(sect_idx));
2008 if (section_sp)
Greg Clayton0416bdf2012-01-30 09:04:36 +00002009 target_sp->GetSectionLoadList().SetSectionLoadAddress (section_sp.get(), section_sp->GetFileAddress() + slide_offset);
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002010 }
2011 }
2012 else
2013 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00002014 module_sp->GetFileSpec().GetPath (path, sizeof(path));
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002015 sb_error.SetErrorStringWithFormat ("no sections in object file '%s'", path);
2016 }
2017 }
2018 else
2019 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00002020 module_sp->GetFileSpec().GetPath (path, sizeof(path));
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002021 sb_error.SetErrorStringWithFormat ("no object file for module '%s'", path);
2022 }
2023 }
Greg Clayton0416bdf2012-01-30 09:04:36 +00002024 else
2025 {
2026 sb_error.SetErrorStringWithFormat ("invalid module");
2027 }
2028
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002029 }
2030 else
2031 {
2032 sb_error.SetErrorStringWithFormat ("invalid target");
2033 }
2034 return sb_error;
2035}
2036
2037SBError
2038SBTarget::ClearModuleLoadAddress (lldb::SBModule module)
2039{
2040 SBError sb_error;
2041
2042 char path[PATH_MAX];
Greg Clayton0416bdf2012-01-30 09:04:36 +00002043 TargetSP target_sp(GetSP());
2044 if (target_sp)
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002045 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00002046 ModuleSP module_sp (module.GetSP());
2047 if (module_sp)
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002048 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00002049 ObjectFile *objfile = module_sp->GetObjectFile();
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002050 if (objfile)
2051 {
2052 SectionList *section_list = objfile->GetSectionList();
2053 if (section_list)
2054 {
2055 const size_t num_sections = section_list->GetSize();
2056 for (size_t sect_idx = 0; sect_idx < num_sections; ++sect_idx)
2057 {
2058 SectionSP section_sp (section_list->GetSectionAtIndex(sect_idx));
2059 if (section_sp)
Greg Clayton0416bdf2012-01-30 09:04:36 +00002060 target_sp->GetSectionLoadList().SetSectionUnloaded (section_sp.get());
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002061 }
2062 }
2063 else
2064 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00002065 module_sp->GetFileSpec().GetPath (path, sizeof(path));
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002066 sb_error.SetErrorStringWithFormat ("no sections in object file '%s'", path);
2067 }
2068 }
2069 else
2070 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00002071 module_sp->GetFileSpec().GetPath (path, sizeof(path));
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002072 sb_error.SetErrorStringWithFormat ("no object file for module '%s'", path);
2073 }
2074 }
Greg Clayton0416bdf2012-01-30 09:04:36 +00002075 else
2076 {
2077 sb_error.SetErrorStringWithFormat ("invalid module");
2078 }
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002079 }
2080 else
2081 {
2082 sb_error.SetErrorStringWithFormat ("invalid target");
2083 }
2084 return sb_error;
2085}
2086
2087