blob: 79b45485007e1ee83c04e7ca83a787cfba89dbc8 [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);
Han Ming Ongd1040dd2012-02-25 01:07:38 +0000904
905 PlatformSP platform_sp = target_sp->GetPlatform();
906 ProcessInstanceInfo instance_info;
907 if (platform_sp->GetProcessInfo(pid, instance_info))
908 {
909 attach_info.SetUserID(instance_info.GetEffectiveUserID());
910
911 }
Greg Clayton334d33a2012-01-30 07:41:31 +0000912 error.SetError (process_sp->Attach (attach_info));
Johnny Chen535960e2011-06-17 00:51:15 +0000913 // If we are doing synchronous mode, then wait for the
914 // process to stop!
Greg Clayton0416bdf2012-01-30 09:04:36 +0000915 if (target_sp->GetDebugger().GetAsyncExecution () == false)
Greg Clayton334d33a2012-01-30 07:41:31 +0000916 process_sp->WaitForProcessToStop (NULL);
Greg Claytonc5f728c2010-10-06 22:10:17 +0000917 }
918 else
919 {
920 error.SetErrorString ("unable to create lldb_private::Process");
921 }
922 }
923 else
924 {
925 error.SetErrorString ("SBTarget is invalid");
926 }
927 return sb_process;
928
929}
930
931lldb::SBProcess
Greg Claytond8c62532010-10-07 04:19:01 +0000932SBTarget::AttachToProcessWithName
Greg Claytonc5f728c2010-10-06 22:10:17 +0000933(
Greg Clayton271a5db2011-02-03 21:28:34 +0000934 SBListener &listener,
Greg Claytonc5f728c2010-10-06 22:10:17 +0000935 const char *name, // basename of process to attach to
936 bool wait_for, // if true wait for a new instance of "name" to be launched
937 SBError& error // An error explaining what went wrong if attach fails
938)
939{
940 SBProcess sb_process;
Greg Clayton334d33a2012-01-30 07:41:31 +0000941 ProcessSP process_sp;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000942 TargetSP target_sp(GetSP());
943 if (name && target_sp)
Greg Claytonc5f728c2010-10-06 22:10:17 +0000944 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000945 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytonbdcda462010-12-20 20:49:23 +0000946
Greg Claytonde1dd812011-06-24 03:21:43 +0000947 StateType state = eStateInvalid;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000948 process_sp = target_sp->GetProcessSP();
Greg Clayton334d33a2012-01-30 07:41:31 +0000949 if (process_sp)
Greg Claytonde1dd812011-06-24 03:21:43 +0000950 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000951 state = process_sp->GetState();
Greg Claytonde1dd812011-06-24 03:21:43 +0000952
Greg Clayton334d33a2012-01-30 07:41:31 +0000953 if (process_sp->IsAlive() && state != eStateConnected)
Greg Claytonde1dd812011-06-24 03:21:43 +0000954 {
955 if (state == eStateAttaching)
956 error.SetErrorString ("process attach is in progress");
957 else
958 error.SetErrorString ("a process is already being debugged");
Greg Claytonde1dd812011-06-24 03:21:43 +0000959 return sb_process;
960 }
961 }
962
963 if (state == eStateConnected)
964 {
965 // If we are already connected, then we have already specified the
966 // listener, so if a valid listener is supplied, we need to error out
967 // to let the client know.
968 if (listener.IsValid())
969 {
970 error.SetErrorString ("process is connected and already has a listener, pass empty listener");
Greg Claytonde1dd812011-06-24 03:21:43 +0000971 return sb_process;
972 }
973 }
Greg Clayton271a5db2011-02-03 21:28:34 +0000974 else
Greg Claytonde1dd812011-06-24 03:21:43 +0000975 {
976 if (listener.IsValid())
Greg Clayton46c9a352012-02-09 06:16:32 +0000977 process_sp = target_sp->CreateProcess (listener.ref(), NULL, NULL);
Greg Claytonde1dd812011-06-24 03:21:43 +0000978 else
Greg Clayton46c9a352012-02-09 06:16:32 +0000979 process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener(), NULL, NULL);
Greg Claytonde1dd812011-06-24 03:21:43 +0000980 }
Greg Claytonc5f728c2010-10-06 22:10:17 +0000981
Greg Clayton334d33a2012-01-30 07:41:31 +0000982 if (process_sp)
Greg Claytonc5f728c2010-10-06 22:10:17 +0000983 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000984 sb_process.SetSP (process_sp);
Greg Clayton527154d2011-11-15 03:53:30 +0000985 ProcessAttachInfo attach_info;
986 attach_info.GetExecutableFile().SetFile(name, false);
987 attach_info.SetWaitForLaunch(wait_for);
Greg Clayton334d33a2012-01-30 07:41:31 +0000988 error.SetError (process_sp->Attach (attach_info));
Johnny Chen58d02ff2011-06-17 19:21:30 +0000989 // If we are doing synchronous mode, then wait for the
990 // process to stop!
Greg Clayton0416bdf2012-01-30 09:04:36 +0000991 if (target_sp->GetDebugger().GetAsyncExecution () == false)
Greg Clayton334d33a2012-01-30 07:41:31 +0000992 process_sp->WaitForProcessToStop (NULL);
Greg Claytonc5f728c2010-10-06 22:10:17 +0000993 }
994 else
995 {
996 error.SetErrorString ("unable to create lldb_private::Process");
997 }
998 }
999 else
1000 {
1001 error.SetErrorString ("SBTarget is invalid");
1002 }
1003 return sb_process;
1004
1005}
1006
James McIlree38093402011-03-04 00:31:13 +00001007lldb::SBProcess
1008SBTarget::ConnectRemote
1009(
1010 SBListener &listener,
1011 const char *url,
1012 const char *plugin_name,
1013 SBError& error
1014)
1015{
1016 SBProcess sb_process;
Greg Clayton334d33a2012-01-30 07:41:31 +00001017 ProcessSP process_sp;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001018 TargetSP target_sp(GetSP());
1019 if (target_sp)
James McIlree38093402011-03-04 00:31:13 +00001020 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001021 Mutex::Locker api_locker (target_sp->GetAPIMutex());
James McIlree38093402011-03-04 00:31:13 +00001022 if (listener.IsValid())
Greg Clayton46c9a352012-02-09 06:16:32 +00001023 process_sp = target_sp->CreateProcess (listener.ref(), plugin_name, NULL);
James McIlree38093402011-03-04 00:31:13 +00001024 else
Greg Clayton46c9a352012-02-09 06:16:32 +00001025 process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener(), plugin_name, NULL);
James McIlree38093402011-03-04 00:31:13 +00001026
1027
Greg Clayton334d33a2012-01-30 07:41:31 +00001028 if (process_sp)
James McIlree38093402011-03-04 00:31:13 +00001029 {
Greg Clayton334d33a2012-01-30 07:41:31 +00001030 sb_process.SetSP (process_sp);
1031 error.SetError (process_sp->ConnectRemote (url));
James McIlree38093402011-03-04 00:31:13 +00001032 }
1033 else
1034 {
1035 error.SetErrorString ("unable to create lldb_private::Process");
1036 }
1037 }
1038 else
1039 {
1040 error.SetErrorString ("SBTarget is invalid");
1041 }
1042 return sb_process;
1043}
1044
Chris Lattner24943d22010-06-08 16:52:24 +00001045SBFileSpec
1046SBTarget::GetExecutable ()
1047{
Caroline Tice7826c882010-10-26 03:11:13 +00001048
Chris Lattner24943d22010-06-08 16:52:24 +00001049 SBFileSpec exe_file_spec;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001050 TargetSP target_sp(GetSP());
1051 if (target_sp)
Chris Lattner24943d22010-06-08 16:52:24 +00001052 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001053 Module *exe_module = target_sp->GetExecutableModulePointer();
Greg Clayton5beb99d2011-08-11 02:48:45 +00001054 if (exe_module)
1055 exe_file_spec.SetFileSpec (exe_module->GetFileSpec());
Chris Lattner24943d22010-06-08 16:52:24 +00001056 }
Caroline Tice7826c882010-10-26 03:11:13 +00001057
Greg Claytone005f2c2010-11-06 01:53:30 +00001058 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001059 if (log)
1060 {
Greg Clayton49ce6822010-10-31 03:01:06 +00001061 log->Printf ("SBTarget(%p)::GetExecutable () => SBFileSpec(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +00001062 target_sp.get(), exe_file_spec.get());
Caroline Tice7826c882010-10-26 03:11:13 +00001063 }
1064
Chris Lattner24943d22010-06-08 16:52:24 +00001065 return exe_file_spec;
1066}
1067
Chris Lattner24943d22010-06-08 16:52:24 +00001068bool
Chris Lattner24943d22010-06-08 16:52:24 +00001069SBTarget::operator == (const SBTarget &rhs) const
1070{
Greg Clayton63094e02010-06-23 01:19:29 +00001071 return m_opaque_sp.get() == rhs.m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +00001072}
1073
1074bool
1075SBTarget::operator != (const SBTarget &rhs) const
1076{
Greg Clayton63094e02010-06-23 01:19:29 +00001077 return m_opaque_sp.get() != rhs.m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +00001078}
1079
Greg Clayton334d33a2012-01-30 07:41:31 +00001080lldb::TargetSP
1081SBTarget::GetSP () const
Greg Clayton15afa9f2011-10-01 02:59:24 +00001082{
1083 return m_opaque_sp;
1084}
1085
Greg Clayton63094e02010-06-23 01:19:29 +00001086void
Greg Clayton334d33a2012-01-30 07:41:31 +00001087SBTarget::SetSP (const lldb::TargetSP& target_sp)
Greg Clayton63094e02010-06-23 01:19:29 +00001088{
1089 m_opaque_sp = target_sp;
Chris Lattner24943d22010-06-08 16:52:24 +00001090}
1091
Greg Claytona3955062011-07-22 16:46:35 +00001092lldb::SBAddress
1093SBTarget::ResolveLoadAddress (lldb::addr_t vm_addr)
Greg Claytonea49cc72010-12-12 19:25:26 +00001094{
Greg Claytona3955062011-07-22 16:46:35 +00001095 lldb::SBAddress sb_addr;
1096 Address &addr = sb_addr.ref();
Greg Clayton0416bdf2012-01-30 09:04:36 +00001097 TargetSP target_sp(GetSP());
1098 if (target_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +00001099 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001100 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1101 if (target_sp->GetSectionLoadList().ResolveLoadAddress (vm_addr, addr))
Greg Claytona3955062011-07-22 16:46:35 +00001102 return sb_addr;
Greg Claytonbdcda462010-12-20 20:49:23 +00001103 }
Greg Claytonea49cc72010-12-12 19:25:26 +00001104
Greg Claytona3955062011-07-22 16:46:35 +00001105 // We have a load address that isn't in a section, just return an address
1106 // with the offset filled in (the address) and the section set to NULL
Greg Clayton3508c382012-02-24 01:59:29 +00001107 addr.SetRawAddress(vm_addr);
Greg Claytona3955062011-07-22 16:46:35 +00001108 return sb_addr;
Greg Claytonea49cc72010-12-12 19:25:26 +00001109}
1110
Greg Claytonafb81862011-03-02 21:34:46 +00001111SBSymbolContext
1112SBTarget::ResolveSymbolContextForAddress (const SBAddress& addr, uint32_t resolve_scope)
1113{
1114 SBSymbolContext sc;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001115 if (addr.IsValid())
1116 {
1117 TargetSP target_sp(GetSP());
1118 if (target_sp)
1119 target_sp->GetImages().ResolveSymbolContextForAddress (addr.ref(), resolve_scope, sc.ref());
1120 }
Greg Claytonafb81862011-03-02 21:34:46 +00001121 return sc;
1122}
1123
1124
Chris Lattner24943d22010-06-08 16:52:24 +00001125SBBreakpoint
1126SBTarget::BreakpointCreateByLocation (const char *file, uint32_t line)
1127{
Greg Claytond6d806c2010-11-08 00:28:40 +00001128 return SBBreakpoint(BreakpointCreateByLocation (SBFileSpec (file, false), line));
Chris Lattner24943d22010-06-08 16:52:24 +00001129}
1130
1131SBBreakpoint
1132SBTarget::BreakpointCreateByLocation (const SBFileSpec &sb_file_spec, uint32_t line)
1133{
Greg Claytone005f2c2010-11-06 01:53:30 +00001134 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001135
Chris Lattner24943d22010-06-08 16:52:24 +00001136 SBBreakpoint sb_bp;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001137 TargetSP target_sp(GetSP());
1138 if (target_sp && line != 0)
Greg Claytonbdcda462010-12-20 20:49:23 +00001139 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001140 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1141 *sb_bp = target_sp->CreateBreakpoint (NULL, *sb_file_spec, line, true, false);
Greg Claytonbdcda462010-12-20 20:49:23 +00001142 }
Caroline Tice7826c882010-10-26 03:11:13 +00001143
1144 if (log)
1145 {
1146 SBStream sstr;
1147 sb_bp.GetDescription (sstr);
Greg Clayton49ce6822010-10-31 03:01:06 +00001148 char path[PATH_MAX];
1149 sb_file_spec->GetPath (path, sizeof(path));
1150 log->Printf ("SBTarget(%p)::BreakpointCreateByLocation ( %s:%u ) => SBBreakpoint(%p): %s",
Greg Clayton0416bdf2012-01-30 09:04:36 +00001151 target_sp.get(),
Greg Clayton49ce6822010-10-31 03:01:06 +00001152 path,
Greg Claytona66ba462010-10-30 04:51:46 +00001153 line,
Greg Clayton49ce6822010-10-31 03:01:06 +00001154 sb_bp.get(),
Caroline Tice7826c882010-10-26 03:11:13 +00001155 sstr.GetData());
1156 }
1157
Chris Lattner24943d22010-06-08 16:52:24 +00001158 return sb_bp;
1159}
1160
1161SBBreakpoint
1162SBTarget::BreakpointCreateByName (const char *symbol_name, const char *module_name)
1163{
Greg Claytone005f2c2010-11-06 01:53:30 +00001164 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001165
Chris Lattner24943d22010-06-08 16:52:24 +00001166 SBBreakpoint sb_bp;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001167 TargetSP target_sp(GetSP());
1168 if (target_sp.get())
Chris Lattner24943d22010-06-08 16:52:24 +00001169 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001170 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Chris Lattner24943d22010-06-08 16:52:24 +00001171 if (module_name && module_name[0])
1172 {
Jim Ingham03c8ee52011-09-21 01:17:13 +00001173 FileSpecList module_spec_list;
1174 module_spec_list.Append (FileSpec (module_name, false));
Greg Clayton0416bdf2012-01-30 09:04:36 +00001175 *sb_bp = target_sp->CreateBreakpoint (&module_spec_list, NULL, symbol_name, eFunctionNameTypeAuto, false);
Chris Lattner24943d22010-06-08 16:52:24 +00001176 }
1177 else
1178 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001179 *sb_bp = target_sp->CreateBreakpoint (NULL, NULL, symbol_name, eFunctionNameTypeAuto, false);
Chris Lattner24943d22010-06-08 16:52:24 +00001180 }
1181 }
Caroline Tice7826c882010-10-26 03:11:13 +00001182
1183 if (log)
1184 {
Greg Clayton49ce6822010-10-31 03:01:06 +00001185 log->Printf ("SBTarget(%p)::BreakpointCreateByName (symbol=\"%s\", module=\"%s\") => SBBreakpoint(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +00001186 target_sp.get(), symbol_name, module_name, sb_bp.get());
Caroline Tice7826c882010-10-26 03:11:13 +00001187 }
1188
Chris Lattner24943d22010-06-08 16:52:24 +00001189 return sb_bp;
1190}
1191
Jim Inghamd6d47972011-09-23 00:54:11 +00001192lldb::SBBreakpoint
1193SBTarget::BreakpointCreateByName (const char *symbol_name,
1194 const SBFileSpecList &module_list,
1195 const SBFileSpecList &comp_unit_list)
1196{
Jim Ingham1fb8a2d2011-10-11 01:18:55 +00001197 uint32_t name_type_mask = eFunctionNameTypeAuto;
1198 return BreakpointCreateByName (symbol_name, name_type_mask, module_list, comp_unit_list);
1199}
1200
1201lldb::SBBreakpoint
1202SBTarget::BreakpointCreateByName (const char *symbol_name,
1203 uint32_t name_type_mask,
1204 const SBFileSpecList &module_list,
1205 const SBFileSpecList &comp_unit_list)
1206{
Jim Inghamd6d47972011-09-23 00:54:11 +00001207 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1208
1209 SBBreakpoint sb_bp;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001210 TargetSP target_sp(GetSP());
1211 if (target_sp && symbol_name && symbol_name[0])
Jim Inghamd6d47972011-09-23 00:54:11 +00001212 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001213 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1214 *sb_bp = target_sp->CreateBreakpoint (module_list.get(),
Jim Inghamd6d47972011-09-23 00:54:11 +00001215 comp_unit_list.get(),
1216 symbol_name,
Jim Ingham1fb8a2d2011-10-11 01:18:55 +00001217 name_type_mask,
Jim Inghamd6d47972011-09-23 00:54:11 +00001218 false);
1219 }
1220
1221 if (log)
1222 {
Jim Ingham1fb8a2d2011-10-11 01:18:55 +00001223 log->Printf ("SBTarget(%p)::BreakpointCreateByName (symbol=\"%s\", name_type: %d) => SBBreakpoint(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +00001224 target_sp.get(), symbol_name, name_type_mask, sb_bp.get());
Jim Inghamd6d47972011-09-23 00:54:11 +00001225 }
1226
1227 return sb_bp;
1228}
1229
1230
Chris Lattner24943d22010-06-08 16:52:24 +00001231SBBreakpoint
1232SBTarget::BreakpointCreateByRegex (const char *symbol_name_regex, const char *module_name)
1233{
Greg Claytone005f2c2010-11-06 01:53:30 +00001234 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001235
Chris Lattner24943d22010-06-08 16:52:24 +00001236 SBBreakpoint sb_bp;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001237 TargetSP target_sp(GetSP());
1238 if (target_sp && symbol_name_regex && symbol_name_regex[0])
Chris Lattner24943d22010-06-08 16:52:24 +00001239 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001240 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Chris Lattner24943d22010-06-08 16:52:24 +00001241 RegularExpression regexp(symbol_name_regex);
1242
1243 if (module_name && module_name[0])
1244 {
Jim Ingham03c8ee52011-09-21 01:17:13 +00001245 FileSpecList module_spec_list;
1246 module_spec_list.Append (FileSpec (module_name, false));
Chris Lattner24943d22010-06-08 16:52:24 +00001247
Greg Clayton0416bdf2012-01-30 09:04:36 +00001248 *sb_bp = target_sp->CreateFuncRegexBreakpoint (&module_spec_list, NULL, regexp, false);
Chris Lattner24943d22010-06-08 16:52:24 +00001249 }
1250 else
1251 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001252 *sb_bp = target_sp->CreateFuncRegexBreakpoint (NULL, NULL, regexp, false);
Chris Lattner24943d22010-06-08 16:52:24 +00001253 }
1254 }
Caroline Tice7826c882010-10-26 03:11:13 +00001255
1256 if (log)
1257 {
Greg Clayton49ce6822010-10-31 03:01:06 +00001258 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (symbol_regex=\"%s\", module_name=\"%s\") => SBBreakpoint(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +00001259 target_sp.get(), symbol_name_regex, module_name, sb_bp.get());
Caroline Tice7826c882010-10-26 03:11:13 +00001260 }
1261
Chris Lattner24943d22010-06-08 16:52:24 +00001262 return sb_bp;
1263}
1264
Jim Inghamd6d47972011-09-23 00:54:11 +00001265lldb::SBBreakpoint
1266SBTarget::BreakpointCreateByRegex (const char *symbol_name_regex,
1267 const SBFileSpecList &module_list,
1268 const SBFileSpecList &comp_unit_list)
1269{
1270 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Chris Lattner24943d22010-06-08 16:52:24 +00001271
Jim Inghamd6d47972011-09-23 00:54:11 +00001272 SBBreakpoint sb_bp;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001273 TargetSP target_sp(GetSP());
1274 if (target_sp && symbol_name_regex && symbol_name_regex[0])
Jim Inghamd6d47972011-09-23 00:54:11 +00001275 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001276 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Jim Inghamd6d47972011-09-23 00:54:11 +00001277 RegularExpression regexp(symbol_name_regex);
1278
Greg Clayton0416bdf2012-01-30 09:04:36 +00001279 *sb_bp = target_sp->CreateFuncRegexBreakpoint (module_list.get(), comp_unit_list.get(), regexp, false);
Jim Inghamd6d47972011-09-23 00:54:11 +00001280 }
1281
1282 if (log)
1283 {
1284 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (symbol_regex=\"%s\") => SBBreakpoint(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +00001285 target_sp.get(), symbol_name_regex, sb_bp.get());
Jim Inghamd6d47972011-09-23 00:54:11 +00001286 }
1287
1288 return sb_bp;
1289}
Chris Lattner24943d22010-06-08 16:52:24 +00001290
1291SBBreakpoint
1292SBTarget::BreakpointCreateByAddress (addr_t address)
1293{
Greg Claytone005f2c2010-11-06 01:53:30 +00001294 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001295
Chris Lattner24943d22010-06-08 16:52:24 +00001296 SBBreakpoint sb_bp;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001297 TargetSP target_sp(GetSP());
1298 if (target_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +00001299 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001300 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1301 *sb_bp = target_sp->CreateBreakpoint (address, false);
Greg Claytonbdcda462010-12-20 20:49:23 +00001302 }
Caroline Tice7826c882010-10-26 03:11:13 +00001303
1304 if (log)
1305 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001306 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 +00001307 }
1308
Chris Lattner24943d22010-06-08 16:52:24 +00001309 return sb_bp;
1310}
1311
Jim Ingham03c8ee52011-09-21 01:17:13 +00001312lldb::SBBreakpoint
1313SBTarget::BreakpointCreateBySourceRegex (const char *source_regex, const lldb::SBFileSpec &source_file, const char *module_name)
1314{
1315 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1316
1317 SBBreakpoint sb_bp;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001318 TargetSP target_sp(GetSP());
1319 if (target_sp && source_regex && source_regex[0])
Jim Ingham03c8ee52011-09-21 01:17:13 +00001320 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001321 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Jim Ingham03c8ee52011-09-21 01:17:13 +00001322 RegularExpression regexp(source_regex);
Jim Inghamd6d47972011-09-23 00:54:11 +00001323 FileSpecList source_file_spec_list;
1324 source_file_spec_list.Append (source_file.ref());
Jim Ingham03c8ee52011-09-21 01:17:13 +00001325
1326 if (module_name && module_name[0])
1327 {
1328 FileSpecList module_spec_list;
1329 module_spec_list.Append (FileSpec (module_name, false));
1330
Greg Clayton0416bdf2012-01-30 09:04:36 +00001331 *sb_bp = target_sp->CreateSourceRegexBreakpoint (&module_spec_list, &source_file_spec_list, regexp, false);
Jim Ingham03c8ee52011-09-21 01:17:13 +00001332 }
1333 else
1334 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001335 *sb_bp = target_sp->CreateSourceRegexBreakpoint (NULL, &source_file_spec_list, regexp, false);
Jim Ingham03c8ee52011-09-21 01:17:13 +00001336 }
1337 }
1338
1339 if (log)
1340 {
1341 char path[PATH_MAX];
1342 source_file->GetPath (path, sizeof(path));
1343 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (source_regex=\"%s\", file=\"%s\", module_name=\"%s\") => SBBreakpoint(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +00001344 target_sp.get(), source_regex, path, module_name, sb_bp.get());
Jim Ingham03c8ee52011-09-21 01:17:13 +00001345 }
1346
1347 return sb_bp;
1348}
1349
Jim Inghamd6d47972011-09-23 00:54:11 +00001350lldb::SBBreakpoint
1351SBTarget::BreakpointCreateBySourceRegex (const char *source_regex,
1352 const SBFileSpecList &module_list,
1353 const lldb::SBFileSpecList &source_file_list)
1354{
1355 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1356
1357 SBBreakpoint sb_bp;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001358 TargetSP target_sp(GetSP());
1359 if (target_sp && source_regex && source_regex[0])
Jim Inghamd6d47972011-09-23 00:54:11 +00001360 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001361 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Jim Inghamd6d47972011-09-23 00:54:11 +00001362 RegularExpression regexp(source_regex);
Greg Clayton0416bdf2012-01-30 09:04:36 +00001363 *sb_bp = target_sp->CreateSourceRegexBreakpoint (module_list.get(), source_file_list.get(), regexp, false);
Jim Inghamd6d47972011-09-23 00:54:11 +00001364 }
1365
1366 if (log)
1367 {
1368 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (source_regex=\"%s\") => SBBreakpoint(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +00001369 target_sp.get(), source_regex, sb_bp.get());
Jim Inghamd6d47972011-09-23 00:54:11 +00001370 }
1371
1372 return sb_bp;
1373}
Jim Ingham03c8ee52011-09-21 01:17:13 +00001374
Greg Claytonc7f5d5c2010-07-23 23:33:17 +00001375uint32_t
1376SBTarget::GetNumBreakpoints () const
1377{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001378 TargetSP target_sp(GetSP());
1379 if (target_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +00001380 {
1381 // The breakpoint list is thread safe, no need to lock
Greg Clayton0416bdf2012-01-30 09:04:36 +00001382 return target_sp->GetBreakpointList().GetSize();
Greg Claytonbdcda462010-12-20 20:49:23 +00001383 }
Greg Claytonc7f5d5c2010-07-23 23:33:17 +00001384 return 0;
1385}
1386
1387SBBreakpoint
1388SBTarget::GetBreakpointAtIndex (uint32_t idx) const
1389{
1390 SBBreakpoint sb_breakpoint;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001391 TargetSP target_sp(GetSP());
1392 if (target_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +00001393 {
1394 // The breakpoint list is thread safe, no need to lock
Greg Clayton0416bdf2012-01-30 09:04:36 +00001395 *sb_breakpoint = target_sp->GetBreakpointList().GetBreakpointAtIndex(idx);
Greg Claytonbdcda462010-12-20 20:49:23 +00001396 }
Greg Claytonc7f5d5c2010-07-23 23:33:17 +00001397 return sb_breakpoint;
1398}
Chris Lattner24943d22010-06-08 16:52:24 +00001399
1400bool
1401SBTarget::BreakpointDelete (break_id_t bp_id)
1402{
Greg Claytone005f2c2010-11-06 01:53:30 +00001403 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001404
Caroline Tice7826c882010-10-26 03:11:13 +00001405 bool result = false;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001406 TargetSP target_sp(GetSP());
1407 if (target_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +00001408 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001409 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1410 result = target_sp->RemoveBreakpointByID (bp_id);
Greg Claytonbdcda462010-12-20 20:49:23 +00001411 }
Caroline Tice7826c882010-10-26 03:11:13 +00001412
1413 if (log)
1414 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001415 log->Printf ("SBTarget(%p)::BreakpointDelete (bp_id=%d) => %i", target_sp.get(), (uint32_t) bp_id, result);
Caroline Tice7826c882010-10-26 03:11:13 +00001416 }
1417
1418 return result;
Chris Lattner24943d22010-06-08 16:52:24 +00001419}
1420
Johnny Chen096c2932011-09-26 22:40:50 +00001421SBBreakpoint
1422SBTarget::FindBreakpointByID (break_id_t bp_id)
1423{
1424 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1425
1426 SBBreakpoint sb_breakpoint;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001427 TargetSP target_sp(GetSP());
1428 if (target_sp && bp_id != LLDB_INVALID_BREAK_ID)
Johnny Chen096c2932011-09-26 22:40:50 +00001429 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001430 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1431 *sb_breakpoint = target_sp->GetBreakpointByID (bp_id);
Johnny Chen096c2932011-09-26 22:40:50 +00001432 }
1433
1434 if (log)
1435 {
1436 log->Printf ("SBTarget(%p)::FindBreakpointByID (bp_id=%d) => SBBreakpoint(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +00001437 target_sp.get(), (uint32_t) bp_id, sb_breakpoint.get());
Johnny Chen096c2932011-09-26 22:40:50 +00001438 }
1439
1440 return sb_breakpoint;
1441}
1442
Chris Lattner24943d22010-06-08 16:52:24 +00001443bool
1444SBTarget::EnableAllBreakpoints ()
1445{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001446 TargetSP target_sp(GetSP());
1447 if (target_sp)
Chris Lattner24943d22010-06-08 16:52:24 +00001448 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001449 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1450 target_sp->EnableAllBreakpoints ();
Chris Lattner24943d22010-06-08 16:52:24 +00001451 return true;
1452 }
1453 return false;
1454}
1455
1456bool
1457SBTarget::DisableAllBreakpoints ()
1458{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001459 TargetSP target_sp(GetSP());
1460 if (target_sp)
Chris Lattner24943d22010-06-08 16:52:24 +00001461 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001462 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1463 target_sp->DisableAllBreakpoints ();
Chris Lattner24943d22010-06-08 16:52:24 +00001464 return true;
1465 }
1466 return false;
1467}
1468
1469bool
1470SBTarget::DeleteAllBreakpoints ()
1471{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001472 TargetSP target_sp(GetSP());
1473 if (target_sp)
Chris Lattner24943d22010-06-08 16:52:24 +00001474 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001475 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1476 target_sp->RemoveAllBreakpoints ();
Chris Lattner24943d22010-06-08 16:52:24 +00001477 return true;
1478 }
1479 return false;
1480}
1481
Johnny Chen096c2932011-09-26 22:40:50 +00001482uint32_t
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001483SBTarget::GetNumWatchpoints () const
Johnny Chen096c2932011-09-26 22:40:50 +00001484{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001485 TargetSP target_sp(GetSP());
1486 if (target_sp)
Johnny Chen096c2932011-09-26 22:40:50 +00001487 {
Johnny Chenecd4feb2011-10-14 00:42:25 +00001488 // The watchpoint list is thread safe, no need to lock
Greg Clayton0416bdf2012-01-30 09:04:36 +00001489 return target_sp->GetWatchpointList().GetSize();
Johnny Chen096c2932011-09-26 22:40:50 +00001490 }
1491 return 0;
1492}
1493
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001494SBWatchpoint
1495SBTarget::GetWatchpointAtIndex (uint32_t idx) const
Johnny Chen5eb54bb2011-09-27 20:29:45 +00001496{
Johnny Chenecd4feb2011-10-14 00:42:25 +00001497 SBWatchpoint sb_watchpoint;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001498 TargetSP target_sp(GetSP());
1499 if (target_sp)
Johnny Chen096c2932011-09-26 22:40:50 +00001500 {
Johnny Chenecd4feb2011-10-14 00:42:25 +00001501 // The watchpoint list is thread safe, no need to lock
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001502 sb_watchpoint.SetSP (target_sp->GetWatchpointList().GetByIndex(idx));
Johnny Chen096c2932011-09-26 22:40:50 +00001503 }
Johnny Chenecd4feb2011-10-14 00:42:25 +00001504 return sb_watchpoint;
Johnny Chen096c2932011-09-26 22:40:50 +00001505}
1506
1507bool
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001508SBTarget::DeleteWatchpoint (watch_id_t wp_id)
Johnny Chen096c2932011-09-26 22:40:50 +00001509{
1510 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1511
1512 bool result = false;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001513 TargetSP target_sp(GetSP());
1514 if (target_sp)
Johnny Chen096c2932011-09-26 22:40:50 +00001515 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001516 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1517 result = target_sp->RemoveWatchpointByID (wp_id);
Johnny Chen096c2932011-09-26 22:40:50 +00001518 }
1519
1520 if (log)
1521 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001522 log->Printf ("SBTarget(%p)::WatchpointDelete (wp_id=%d) => %i", target_sp.get(), (uint32_t) wp_id, result);
Johnny Chen096c2932011-09-26 22:40:50 +00001523 }
1524
1525 return result;
1526}
1527
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001528SBWatchpoint
1529SBTarget::FindWatchpointByID (lldb::watch_id_t wp_id)
Johnny Chen096c2932011-09-26 22:40:50 +00001530{
1531 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1532
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001533 SBWatchpoint sb_watchpoint;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001534 lldb::WatchpointSP watchpoint_sp;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001535 TargetSP target_sp(GetSP());
1536 if (target_sp && wp_id != LLDB_INVALID_WATCH_ID)
Johnny Chen096c2932011-09-26 22:40:50 +00001537 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001538 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001539 watchpoint_sp = target_sp->GetWatchpointList().FindByID(wp_id);
1540 sb_watchpoint.SetSP (watchpoint_sp);
Johnny Chen096c2932011-09-26 22:40:50 +00001541 }
1542
1543 if (log)
1544 {
Johnny Chenecd4feb2011-10-14 00:42:25 +00001545 log->Printf ("SBTarget(%p)::FindWatchpointByID (bp_id=%d) => SBWatchpoint(%p)",
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001546 target_sp.get(), (uint32_t) wp_id, watchpoint_sp.get());
Johnny Chen096c2932011-09-26 22:40:50 +00001547 }
1548
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001549 return sb_watchpoint;
1550}
1551
1552lldb::SBWatchpoint
1553SBTarget::WatchAddress (lldb::addr_t addr, size_t size, bool read, bool write)
1554{
1555 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1556
1557 SBWatchpoint sb_watchpoint;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001558 lldb::WatchpointSP watchpoint_sp;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001559 TargetSP target_sp(GetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001560 if (target_sp && (read || write) && addr != LLDB_INVALID_ADDRESS && size > 0)
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001561 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001562 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001563 uint32_t watch_type = 0;
1564 if (read)
1565 watch_type |= LLDB_WATCH_TYPE_READ;
1566 if (write)
1567 watch_type |= LLDB_WATCH_TYPE_WRITE;
1568 watchpoint_sp = target_sp->CreateWatchpoint(addr, size, watch_type);
1569 sb_watchpoint.SetSP (watchpoint_sp);
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001570 }
1571
1572 if (log)
1573 {
1574 log->Printf ("SBTarget(%p)::WatchAddress (addr=0x%llx, 0x%u) => SBWatchpoint(%p)",
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001575 target_sp.get(), addr, (uint32_t) size, watchpoint_sp.get());
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001576 }
1577
1578 return sb_watchpoint;
Johnny Chen096c2932011-09-26 22:40:50 +00001579}
1580
1581bool
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001582SBTarget::EnableAllWatchpoints ()
Johnny Chen096c2932011-09-26 22:40:50 +00001583{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001584 TargetSP target_sp(GetSP());
1585 if (target_sp)
Johnny Chen096c2932011-09-26 22:40:50 +00001586 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001587 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1588 target_sp->EnableAllWatchpoints ();
Johnny Chen096c2932011-09-26 22:40:50 +00001589 return true;
1590 }
1591 return false;
1592}
1593
1594bool
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001595SBTarget::DisableAllWatchpoints ()
Johnny Chen096c2932011-09-26 22:40:50 +00001596{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001597 TargetSP target_sp(GetSP());
1598 if (target_sp)
Johnny Chen096c2932011-09-26 22:40:50 +00001599 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001600 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1601 target_sp->DisableAllWatchpoints ();
Johnny Chen096c2932011-09-26 22:40:50 +00001602 return true;
1603 }
1604 return false;
1605}
1606
1607bool
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001608SBTarget::DeleteAllWatchpoints ()
Johnny Chen096c2932011-09-26 22:40:50 +00001609{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001610 TargetSP target_sp(GetSP());
1611 if (target_sp)
Johnny Chen096c2932011-09-26 22:40:50 +00001612 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001613 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1614 target_sp->RemoveAllWatchpoints ();
Johnny Chen096c2932011-09-26 22:40:50 +00001615 return true;
1616 }
1617 return false;
1618}
1619
Chris Lattner24943d22010-06-08 16:52:24 +00001620
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001621lldb::SBModule
1622SBTarget::AddModule (const char *path,
1623 const char *triple,
1624 const char *uuid_cstr)
1625{
1626 lldb::SBModule sb_module;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001627 TargetSP target_sp(GetSP());
1628 if (target_sp)
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001629 {
Greg Clayton444fe992012-02-26 05:51:37 +00001630 ModuleSpec module_spec;
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001631 if (path)
Greg Clayton444fe992012-02-26 05:51:37 +00001632 module_spec.GetFileSpec().SetFile(path, false);
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001633
1634 if (uuid_cstr)
Greg Clayton444fe992012-02-26 05:51:37 +00001635 module_spec.GetUUID().SetfromCString(uuid_cstr);
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001636
1637 if (triple)
Greg Clayton444fe992012-02-26 05:51:37 +00001638 module_spec.GetArchitecture().SetTriple (triple, target_sp->GetPlatform ().get());
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001639
Greg Clayton444fe992012-02-26 05:51:37 +00001640 sb_module.SetSP(target_sp->GetSharedModule (module_spec));
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001641 }
1642 return sb_module;
1643}
1644
1645bool
1646SBTarget::AddModule (lldb::SBModule &module)
1647{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001648 TargetSP target_sp(GetSP());
1649 if (target_sp)
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001650 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001651 target_sp->GetImages().AppendIfNeeded (module.GetSP());
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001652 return true;
1653 }
1654 return false;
1655}
1656
Chris Lattner24943d22010-06-08 16:52:24 +00001657uint32_t
1658SBTarget::GetNumModules () const
1659{
Greg Claytone005f2c2010-11-06 01:53:30 +00001660 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001661
Caroline Tice7826c882010-10-26 03:11:13 +00001662 uint32_t num = 0;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001663 TargetSP target_sp(GetSP());
1664 if (target_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +00001665 {
1666 // The module list is thread safe, no need to lock
Greg Clayton0416bdf2012-01-30 09:04:36 +00001667 num = target_sp->GetImages().GetSize();
Greg Claytonbdcda462010-12-20 20:49:23 +00001668 }
Caroline Tice7826c882010-10-26 03:11:13 +00001669
1670 if (log)
Greg Clayton0416bdf2012-01-30 09:04:36 +00001671 log->Printf ("SBTarget(%p)::GetNumModules () => %d", target_sp.get(), num);
Caroline Tice7826c882010-10-26 03:11:13 +00001672
1673 return num;
Chris Lattner24943d22010-06-08 16:52:24 +00001674}
1675
Greg Clayton43490d12010-07-30 20:12:55 +00001676void
1677SBTarget::Clear ()
1678{
Greg Claytone005f2c2010-11-06 01:53:30 +00001679 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001680
1681 if (log)
Greg Clayton3f5ee7f2010-10-29 04:59:35 +00001682 log->Printf ("SBTarget(%p)::Clear ()", m_opaque_sp.get());
Caroline Tice7826c882010-10-26 03:11:13 +00001683
Greg Clayton43490d12010-07-30 20:12:55 +00001684 m_opaque_sp.reset();
1685}
1686
1687
Chris Lattner24943d22010-06-08 16:52:24 +00001688SBModule
1689SBTarget::FindModule (const SBFileSpec &sb_file_spec)
1690{
1691 SBModule sb_module;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001692 TargetSP target_sp(GetSP());
1693 if (target_sp && sb_file_spec.IsValid())
Greg Claytonbdcda462010-12-20 20:49:23 +00001694 {
Greg Clayton444fe992012-02-26 05:51:37 +00001695 ModuleSpec module_spec(*sb_file_spec);
Greg Claytonbdcda462010-12-20 20:49:23 +00001696 // The module list is thread safe, no need to lock
Greg Clayton444fe992012-02-26 05:51:37 +00001697 sb_module.SetSP (target_sp->GetImages().FindFirstModule (module_spec));
Greg Claytonbdcda462010-12-20 20:49:23 +00001698 }
Chris Lattner24943d22010-06-08 16:52:24 +00001699 return sb_module;
1700}
1701
Greg Clayton1b925202012-01-29 06:07:39 +00001702lldb::ByteOrder
1703SBTarget::GetByteOrder ()
1704{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001705 TargetSP target_sp(GetSP());
1706 if (target_sp)
1707 return target_sp->GetArchitecture().GetByteOrder();
Greg Clayton1b925202012-01-29 06:07:39 +00001708 return eByteOrderInvalid;
1709}
1710
1711const char *
1712SBTarget::GetTriple ()
1713{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001714 TargetSP target_sp(GetSP());
1715 if (target_sp)
Greg Clayton1b925202012-01-29 06:07:39 +00001716 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001717 std::string triple (target_sp->GetArchitecture().GetTriple().str());
Greg Clayton1b925202012-01-29 06:07:39 +00001718 // Unique the string so we don't run into ownership issues since
1719 // the const strings put the string into the string pool once and
1720 // the strings never comes out
1721 ConstString const_triple (triple.c_str());
1722 return const_triple.GetCString();
1723 }
1724 return NULL;
1725}
1726
1727uint32_t
1728SBTarget::GetAddressByteSize()
1729{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001730 TargetSP target_sp(GetSP());
1731 if (target_sp)
1732 return target_sp->GetArchitecture().GetAddressByteSize();
Greg Clayton1b925202012-01-29 06:07:39 +00001733 return sizeof(void*);
1734}
1735
1736
Chris Lattner24943d22010-06-08 16:52:24 +00001737SBModule
1738SBTarget::GetModuleAtIndex (uint32_t idx)
1739{
Greg Claytone005f2c2010-11-06 01:53:30 +00001740 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001741
Chris Lattner24943d22010-06-08 16:52:24 +00001742 SBModule sb_module;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001743 ModuleSP module_sp;
1744 TargetSP target_sp(GetSP());
1745 if (target_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +00001746 {
1747 // The module list is thread safe, no need to lock
Greg Clayton0416bdf2012-01-30 09:04:36 +00001748 module_sp = target_sp->GetImages().GetModuleAtIndex(idx);
1749 sb_module.SetSP (module_sp);
Greg Claytonbdcda462010-12-20 20:49:23 +00001750 }
Caroline Tice7826c882010-10-26 03:11:13 +00001751
1752 if (log)
1753 {
Greg Clayton49ce6822010-10-31 03:01:06 +00001754 log->Printf ("SBTarget(%p)::GetModuleAtIndex (idx=%d) => SBModule(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +00001755 target_sp.get(), idx, module_sp.get());
Caroline Tice7826c882010-10-26 03:11:13 +00001756 }
1757
Chris Lattner24943d22010-06-08 16:52:24 +00001758 return sb_module;
1759}
1760
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001761bool
1762SBTarget::RemoveModule (lldb::SBModule module)
1763{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001764 TargetSP target_sp(GetSP());
1765 if (target_sp)
1766 return target_sp->GetImages().Remove(module.GetSP());
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001767 return false;
1768}
1769
Chris Lattner24943d22010-06-08 16:52:24 +00001770
1771SBBroadcaster
1772SBTarget::GetBroadcaster () const
1773{
Greg Claytone005f2c2010-11-06 01:53:30 +00001774 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001775
Greg Clayton0416bdf2012-01-30 09:04:36 +00001776 TargetSP target_sp(GetSP());
1777 SBBroadcaster broadcaster(target_sp.get(), false);
Caroline Tice7826c882010-10-26 03:11:13 +00001778
1779 if (log)
Greg Clayton3f5ee7f2010-10-29 04:59:35 +00001780 log->Printf ("SBTarget(%p)::GetBroadcaster () => SBBroadcaster(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +00001781 target_sp.get(), broadcaster.get());
Caroline Tice7826c882010-10-26 03:11:13 +00001782
Chris Lattner24943d22010-06-08 16:52:24 +00001783 return broadcaster;
1784}
1785
Caroline Tice98f930f2010-09-20 05:20:02 +00001786bool
Caroline Tice7826c882010-10-26 03:11:13 +00001787SBTarget::GetDescription (SBStream &description, lldb::DescriptionLevel description_level)
Caroline Tice98f930f2010-09-20 05:20:02 +00001788{
Greg Clayton96154be2011-11-13 06:57:31 +00001789 Stream &strm = description.ref();
1790
Greg Clayton0416bdf2012-01-30 09:04:36 +00001791 TargetSP target_sp(GetSP());
1792 if (target_sp)
Caroline Ticee7a566e2010-09-20 16:21:41 +00001793 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001794 target_sp->Dump (&strm, description_level);
Caroline Tice7826c882010-10-26 03:11:13 +00001795 }
1796 else
Greg Clayton96154be2011-11-13 06:57:31 +00001797 strm.PutCString ("No value");
Caroline Tice7826c882010-10-26 03:11:13 +00001798
1799 return true;
1800}
1801
Greg Clayton7dd5c512012-02-06 01:44:54 +00001802lldb::SBSymbolContextList
1803SBTarget::FindFunctions (const char *name, uint32_t name_type_mask)
Greg Clayton4ed315f2011-06-21 01:34:41 +00001804{
Greg Clayton7dd5c512012-02-06 01:44:54 +00001805 lldb::SBSymbolContextList sb_sc_list;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001806 if (name && name[0])
Greg Clayton4ed315f2011-06-21 01:34:41 +00001807 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001808 TargetSP target_sp(GetSP());
1809 if (target_sp)
1810 {
1811 const bool symbols_ok = true;
Sean Callanan302d78c2012-02-10 22:52:19 +00001812 const bool inlines_ok = true;
Greg Clayton7dd5c512012-02-06 01:44:54 +00001813 const bool append = true;
1814 target_sp->GetImages().FindFunctions (ConstString(name),
1815 name_type_mask,
Sean Callanan302d78c2012-02-10 22:52:19 +00001816 symbols_ok,
1817 inlines_ok,
Greg Clayton7dd5c512012-02-06 01:44:54 +00001818 append,
1819 *sb_sc_list);
Greg Clayton0416bdf2012-01-30 09:04:36 +00001820 }
Greg Clayton4ed315f2011-06-21 01:34:41 +00001821 }
Greg Clayton7dd5c512012-02-06 01:44:54 +00001822 return sb_sc_list;
Greg Clayton4ed315f2011-06-21 01:34:41 +00001823}
1824
Enrico Granata979e20d2011-07-29 19:53:35 +00001825lldb::SBType
1826SBTarget::FindFirstType (const char* type)
1827{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001828 TargetSP target_sp(GetSP());
1829 if (type && target_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +00001830 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001831 size_t count = target_sp->GetImages().GetSize();
Enrico Granata979e20d2011-07-29 19:53:35 +00001832 for (size_t idx = 0; idx < count; idx++)
1833 {
1834 SBType found_at_idx = GetModuleAtIndex(idx).FindFirstType(type);
1835
1836 if (found_at_idx.IsValid())
1837 return found_at_idx;
1838 }
1839 }
1840 return SBType();
1841}
1842
1843lldb::SBTypeList
1844SBTarget::FindTypes (const char* type)
1845{
1846
1847 SBTypeList retval;
1848
Greg Clayton0416bdf2012-01-30 09:04:36 +00001849 TargetSP target_sp(GetSP());
1850 if (type && target_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +00001851 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001852 ModuleList& images = target_sp->GetImages();
Enrico Granata979e20d2011-07-29 19:53:35 +00001853 ConstString name_const(type);
1854 SymbolContext sc;
1855 TypeList type_list;
1856
1857 uint32_t num_matches = images.FindTypes(sc,
1858 name_const,
1859 true,
1860 UINT32_MAX,
1861 type_list);
1862
1863 for (size_t idx = 0; idx < num_matches; idx++)
1864 {
Greg Clayton0fb0bcc2011-08-03 22:57:10 +00001865 TypeSP type_sp (type_list.GetTypeAtIndex(idx));
1866 if (type_sp)
1867 retval.Append(SBType(type_sp));
Enrico Granata979e20d2011-07-29 19:53:35 +00001868 }
1869 }
1870 return retval;
1871}
1872
Greg Clayton917c0002011-06-29 22:09:02 +00001873SBValueList
1874SBTarget::FindGlobalVariables (const char *name, uint32_t max_matches)
1875{
1876 SBValueList sb_value_list;
1877
Greg Clayton0416bdf2012-01-30 09:04:36 +00001878 TargetSP target_sp(GetSP());
1879 if (name && target_sp)
Greg Clayton917c0002011-06-29 22:09:02 +00001880 {
1881 VariableList variable_list;
1882 const bool append = true;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001883 const uint32_t match_count = target_sp->GetImages().FindGlobalVariables (ConstString (name),
1884 append,
1885 max_matches,
1886 variable_list);
Greg Clayton917c0002011-06-29 22:09:02 +00001887
1888 if (match_count > 0)
1889 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001890 ExecutionContextScope *exe_scope = target_sp->GetProcessSP().get();
Greg Clayton917c0002011-06-29 22:09:02 +00001891 if (exe_scope == NULL)
Greg Clayton0416bdf2012-01-30 09:04:36 +00001892 exe_scope = target_sp.get();
Greg Clayton917c0002011-06-29 22:09:02 +00001893 ValueObjectList &value_object_list = sb_value_list.ref();
1894 for (uint32_t i=0; i<match_count; ++i)
1895 {
1896 lldb::ValueObjectSP valobj_sp (ValueObjectVariable::Create (exe_scope, variable_list.GetVariableAtIndex(i)));
1897 if (valobj_sp)
1898 value_object_list.Append(valobj_sp);
1899 }
1900 }
1901 }
1902
1903 return sb_value_list;
1904}
1905
Jim Inghamcc637462011-09-13 00:29:56 +00001906SBSourceManager
1907SBTarget::GetSourceManager()
1908{
1909 SBSourceManager source_manager (*this);
1910 return source_manager;
1911}
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001912
Sean Callananef1f6902011-12-14 23:49:37 +00001913lldb::SBInstructionList
1914SBTarget::GetInstructions (lldb::SBAddress base_addr, const void *buf, size_t size)
1915{
1916 SBInstructionList sb_instructions;
1917
Greg Clayton0416bdf2012-01-30 09:04:36 +00001918 TargetSP target_sp(GetSP());
1919 if (target_sp)
Sean Callananef1f6902011-12-14 23:49:37 +00001920 {
1921 Address addr;
1922
1923 if (base_addr.get())
1924 addr = *base_addr.get();
1925
Greg Clayton0416bdf2012-01-30 09:04:36 +00001926 sb_instructions.SetDisassembler (Disassembler::DisassembleBytes (target_sp->GetArchitecture(),
Sean Callananef1f6902011-12-14 23:49:37 +00001927 NULL,
1928 addr,
1929 buf,
1930 size));
1931 }
1932
1933 return sb_instructions;
1934}
1935
1936lldb::SBInstructionList
1937SBTarget::GetInstructions (lldb::addr_t base_addr, const void *buf, size_t size)
1938{
1939 return GetInstructions (ResolveLoadAddress(base_addr), buf, size);
1940}
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001941
1942SBError
1943SBTarget::SetSectionLoadAddress (lldb::SBSection section,
1944 lldb::addr_t section_base_addr)
1945{
1946 SBError sb_error;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001947 TargetSP target_sp(GetSP());
1948 if (target_sp)
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001949 {
1950 if (!section.IsValid())
1951 {
1952 sb_error.SetErrorStringWithFormat ("invalid section");
1953 }
1954 else
1955 {
Greg Clayton3508c382012-02-24 01:59:29 +00001956 target_sp->GetSectionLoadList().SetSectionLoadAddress (section.GetSP().get(), section_base_addr);
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001957 }
1958 }
1959 else
1960 {
1961 sb_error.SetErrorStringWithFormat ("invalid target");
1962 }
1963 return sb_error;
1964}
1965
1966SBError
1967SBTarget::ClearSectionLoadAddress (lldb::SBSection section)
1968{
1969 SBError sb_error;
1970
Greg Clayton0416bdf2012-01-30 09:04:36 +00001971 TargetSP target_sp(GetSP());
1972 if (target_sp)
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001973 {
1974 if (!section.IsValid())
1975 {
1976 sb_error.SetErrorStringWithFormat ("invalid section");
1977 }
1978 else
1979 {
Greg Clayton3508c382012-02-24 01:59:29 +00001980 target_sp->GetSectionLoadList().SetSectionUnloaded (section.GetSP().get());
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001981 }
1982 }
1983 else
1984 {
1985 sb_error.SetErrorStringWithFormat ("invalid target");
1986 }
1987 return sb_error;
1988}
1989
1990SBError
1991SBTarget::SetModuleLoadAddress (lldb::SBModule module, int64_t slide_offset)
1992{
1993 SBError sb_error;
1994
1995 char path[PATH_MAX];
Greg Clayton0416bdf2012-01-30 09:04:36 +00001996 TargetSP target_sp(GetSP());
1997 if (target_sp)
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001998 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001999 ModuleSP module_sp (module.GetSP());
2000 if (module_sp)
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002001 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00002002 ObjectFile *objfile = module_sp->GetObjectFile();
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002003 if (objfile)
2004 {
2005 SectionList *section_list = objfile->GetSectionList();
2006 if (section_list)
2007 {
2008 const size_t num_sections = section_list->GetSize();
2009 for (size_t sect_idx = 0; sect_idx < num_sections; ++sect_idx)
2010 {
2011 SectionSP section_sp (section_list->GetSectionAtIndex(sect_idx));
2012 if (section_sp)
Greg Clayton0416bdf2012-01-30 09:04:36 +00002013 target_sp->GetSectionLoadList().SetSectionLoadAddress (section_sp.get(), section_sp->GetFileAddress() + slide_offset);
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002014 }
2015 }
2016 else
2017 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00002018 module_sp->GetFileSpec().GetPath (path, sizeof(path));
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002019 sb_error.SetErrorStringWithFormat ("no sections in object file '%s'", path);
2020 }
2021 }
2022 else
2023 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00002024 module_sp->GetFileSpec().GetPath (path, sizeof(path));
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002025 sb_error.SetErrorStringWithFormat ("no object file for module '%s'", path);
2026 }
2027 }
Greg Clayton0416bdf2012-01-30 09:04:36 +00002028 else
2029 {
2030 sb_error.SetErrorStringWithFormat ("invalid module");
2031 }
2032
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002033 }
2034 else
2035 {
2036 sb_error.SetErrorStringWithFormat ("invalid target");
2037 }
2038 return sb_error;
2039}
2040
2041SBError
2042SBTarget::ClearModuleLoadAddress (lldb::SBModule module)
2043{
2044 SBError sb_error;
2045
2046 char path[PATH_MAX];
Greg Clayton0416bdf2012-01-30 09:04:36 +00002047 TargetSP target_sp(GetSP());
2048 if (target_sp)
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002049 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00002050 ModuleSP module_sp (module.GetSP());
2051 if (module_sp)
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002052 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00002053 ObjectFile *objfile = module_sp->GetObjectFile();
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002054 if (objfile)
2055 {
2056 SectionList *section_list = objfile->GetSectionList();
2057 if (section_list)
2058 {
2059 const size_t num_sections = section_list->GetSize();
2060 for (size_t sect_idx = 0; sect_idx < num_sections; ++sect_idx)
2061 {
2062 SectionSP section_sp (section_list->GetSectionAtIndex(sect_idx));
2063 if (section_sp)
Greg Clayton0416bdf2012-01-30 09:04:36 +00002064 target_sp->GetSectionLoadList().SetSectionUnloaded (section_sp.get());
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002065 }
2066 }
2067 else
2068 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00002069 module_sp->GetFileSpec().GetPath (path, sizeof(path));
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002070 sb_error.SetErrorStringWithFormat ("no sections in object file '%s'", path);
2071 }
2072 }
2073 else
2074 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00002075 module_sp->GetFileSpec().GetPath (path, sizeof(path));
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002076 sb_error.SetErrorStringWithFormat ("no object file for module '%s'", path);
2077 }
2078 }
Greg Clayton0416bdf2012-01-30 09:04:36 +00002079 else
2080 {
2081 sb_error.SetErrorStringWithFormat ("invalid module");
2082 }
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002083 }
2084 else
2085 {
2086 sb_error.SetErrorStringWithFormat ("invalid target");
2087 }
2088 return sb_error;
2089}
2090
2091