blob: f8c259add9a7fb52415f39e6bdf0aa0cb5453438 [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 Clayton0a8dcac2012-02-24 05:03:03 +000057
58
59SBLaunchInfo::SBLaunchInfo () :
60m_opaque_sp(new ProcessLaunchInfo())
61{
62}
63
64SBLaunchInfo::SBLaunchInfo (const char *path, const char *triple, const char **argv) :
65m_opaque_sp(new ProcessLaunchInfo())
66{
67 SetExecutable(path);
68 if (triple && triple[0])
69 m_opaque_sp->GetArchitecture().SetTriple(triple, NULL);
70 if (argv)
71 SetArguments(argv, false);
72}
73
74SBFileSpec
75SBLaunchInfo::GetExecutable ()
76{
77 SBFileSpec exe_file;
78 exe_file.SetFileSpec (m_opaque_sp->GetExecutableFile());
79 return exe_file;
80}
81
82void
83SBLaunchInfo::SetExecutable (const char *path)
84{
85 if (path && path[0])
86 m_opaque_sp->GetExecutableFile().SetFile(path, false);
87 else
88 m_opaque_sp->GetExecutableFile().Clear();
89}
90
91void
92SBLaunchInfo::SetExecutable (SBFileSpec exe_file)
93{
94 if (exe_file.IsValid())
95 m_opaque_sp->GetExecutableFile() = exe_file.ref();
96 else
97 m_opaque_sp->GetExecutableFile().Clear();
98}
99
100uint32_t
101SBLaunchInfo::GetUserID()
102{
103 return m_opaque_sp->GetUserID();
104}
105
106uint32_t
107SBLaunchInfo::GetGroupID()
108{
109 return m_opaque_sp->GetGroupID();
110}
111
112bool
113SBLaunchInfo::UserIDIsValid ()
114{
115 return m_opaque_sp->UserIDIsValid();
116}
117
118bool
119SBLaunchInfo::GroupIDIsValid ()
120{
121 return m_opaque_sp->GroupIDIsValid();
122}
123
124void
125SBLaunchInfo::SetUserID (uint32_t uid)
126{
127 m_opaque_sp->SetUserID (uid);
128}
129
130void
131SBLaunchInfo::SetGroupID (uint32_t gid)
132{
133 m_opaque_sp->SetGroupID (gid);
134}
135
136const char *
137SBLaunchInfo::GetTriple ()
138{
139 const ArchSpec &arch = m_opaque_sp->GetArchitecture();
140 if (arch.IsValid())
141 {
142 std::string triple (arch.GetTriple().str());
143 if (!triple.empty())
144 {
145 // Unique the string so we don't run into ownership issues since
146 // the const strings put the string into the string pool once and
147 // the strings never comes out
148 ConstString const_triple (triple.c_str());
149 return const_triple.GetCString();
150 }
151 }
152 return NULL;
153}
154
155void
156SBLaunchInfo::SetTriple (const char *triple)
157{
158 m_opaque_sp->GetArchitecture().SetTriple(triple, NULL);
159}
160
161uint32_t
162SBLaunchInfo::GetNumArguments ()
163{
164 return m_opaque_sp->GetArguments().GetArgumentCount();
165}
166
167const char *
168SBLaunchInfo::GetArgumentAtIndex (uint32_t idx)
169{
170 return m_opaque_sp->GetArguments().GetArgumentAtIndex(idx);
171}
172
173void
174SBLaunchInfo::SetArguments (const char **argv, bool append)
175{
176 if (append)
177 {
178 if (argv)
179 m_opaque_sp->GetArguments().AppendArguments(argv);
180 }
181 else
182 {
183 if (argv)
184 m_opaque_sp->GetArguments().SetArguments(argv);
185 else
186 m_opaque_sp->GetArguments().Clear();
187 }
188}
189
190uint32_t
191SBLaunchInfo::GetNumEnvironmentEntries ()
192{
193 return m_opaque_sp->GetEnvironmentEntries().GetArgumentCount();
194}
195
196const char *
197SBLaunchInfo::GetEnvironmentEntryAtIndex (uint32_t idx)
198{
199 return m_opaque_sp->GetEnvironmentEntries().GetArgumentAtIndex(idx);
200}
201
202void
203SBLaunchInfo::SetEnvironmentEntries (const char **envp, bool append)
204{
205 if (append)
206 {
207 if (envp)
208 m_opaque_sp->GetEnvironmentEntries().AppendArguments(envp);
209 }
210 else
211 {
212 if (envp)
213 m_opaque_sp->GetEnvironmentEntries().SetArguments(envp);
214 else
215 m_opaque_sp->GetEnvironmentEntries().Clear();
216 }
217}
218
219void
220SBLaunchInfo::Clear ()
221{
222 m_opaque_sp->Clear();
223}
224
225const char *
226SBLaunchInfo::GetWorkingDirectory () const
227{
228 return m_opaque_sp->GetWorkingDirectory();
229}
230
231void
232SBLaunchInfo::SetWorkingDirectory (const char *working_dir)
233{
234 m_opaque_sp->SetWorkingDirectory(working_dir);
235}
236
237uint32_t
238SBLaunchInfo::GetLaunchFlags ()
239{
240 return m_opaque_sp->GetFlags().Get();
241}
242
243void
244SBLaunchInfo::SetLaunchFlags (uint32_t flags)
245{
246 m_opaque_sp->GetFlags().Reset(flags);
247}
248
249const char *
250SBLaunchInfo::GetProcessPluginName ()
251{
252 return m_opaque_sp->GetProcessPluginName();
253}
254
255void
256SBLaunchInfo::SetProcessPluginName (const char *plugin_name)
257{
258 return m_opaque_sp->SetProcessPluginName (plugin_name);
259}
260
261const char *
262SBLaunchInfo::GetShell ()
263{
264 return m_opaque_sp->GetShell();
265}
266
267void
268SBLaunchInfo::SetShell (const char * path)
269{
270 m_opaque_sp->SetShell (path);
271}
272
273uint32_t
274SBLaunchInfo::GetResumeCount ()
275{
276 return m_opaque_sp->GetResumeCount();
277}
278
279void
280SBLaunchInfo::SetResumeCount (uint32_t c)
281{
282 m_opaque_sp->SetResumeCount (c);
283}
284
285bool
286SBLaunchInfo::AddCloseFileAction (int fd)
287{
288 return m_opaque_sp->AppendCloseFileAction(fd);
289}
290
291bool
292SBLaunchInfo::AddDuplicateFileAction (int fd, int dup_fd)
293{
294 return m_opaque_sp->AppendDuplicateFileAction(fd, dup_fd);
295}
296
297bool
298SBLaunchInfo::AddOpenFileAction (int fd, const char *path, bool read, bool write)
299{
300 return m_opaque_sp->AppendOpenFileAction(fd, path, read, write);
301}
302
303bool
304SBLaunchInfo::AddSuppressFileAction (int fd, bool read, bool write)
305{
306 return m_opaque_sp->AppendSuppressFileAction(fd, read, write);
307}
308
309
310SBAttachInfo::SBAttachInfo () :
311m_opaque_sp (new ProcessAttachInfo())
312{
313}
314
315SBAttachInfo::SBAttachInfo (lldb::pid_t pid) :
316m_opaque_sp (new ProcessAttachInfo())
317{
318 m_opaque_sp->SetProcessID (pid);
319}
320
321SBAttachInfo::SBAttachInfo (const char *path, bool wait_for) :
322m_opaque_sp (new ProcessAttachInfo())
323{
324 if (path && path[0])
325 m_opaque_sp->GetExecutableFile().SetFile(path, false);
326 m_opaque_sp->SetWaitForLaunch (wait_for);
327}
328
329SBAttachInfo::SBAttachInfo (const SBAttachInfo &rhs) :
330m_opaque_sp (new ProcessAttachInfo())
331{
332 *m_opaque_sp = *rhs.m_opaque_sp;
333}
334
335SBAttachInfo &
336SBAttachInfo::operator = (const SBAttachInfo &rhs)
337{
338 if (this != &rhs)
339 *m_opaque_sp = *rhs.m_opaque_sp;
340 return *this;
341}
342
343lldb::pid_t
344SBAttachInfo::GetProcessID ()
345{
346 return m_opaque_sp->GetProcessID();
347}
348
349void
350SBAttachInfo::SetProcessID (lldb::pid_t pid)
351{
352 m_opaque_sp->SetProcessID (pid);
353}
354
355
356uint32_t
357SBAttachInfo::GetResumeCount ()
358{
359 return m_opaque_sp->GetResumeCount();
360}
361
362void
363SBAttachInfo::SetResumeCount (uint32_t c)
364{
365 m_opaque_sp->SetResumeCount (c);
366}
367
368const char *
369SBAttachInfo::GetProcessPluginName ()
370{
371 return m_opaque_sp->GetProcessPluginName();
372}
373
374void
375SBAttachInfo::SetProcessPluginName (const char *plugin_name)
376{
377 return m_opaque_sp->SetProcessPluginName (plugin_name);
378}
379
380void
381SBAttachInfo::SetExecutable (const char *path)
382{
383 if (path && path[0])
384 m_opaque_sp->GetExecutableFile().SetFile(path, false);
385 else
386 m_opaque_sp->GetExecutableFile().Clear();
387}
388
389void
390SBAttachInfo::SetExecutable (SBFileSpec exe_file)
391{
392 if (exe_file.IsValid())
393 m_opaque_sp->GetExecutableFile() = exe_file.ref();
394 else
395 m_opaque_sp->GetExecutableFile().Clear();
396}
397
398bool
399SBAttachInfo::GetWaitForLaunch ()
400{
401 return m_opaque_sp->GetWaitForLaunch();
402}
403
404void
405SBAttachInfo::SetWaitForLaunch (bool b)
406{
407 m_opaque_sp->SetWaitForLaunch (b);
408}
409
410uint32_t
411SBAttachInfo::GetEffectiveUserID()
412{
413 return m_opaque_sp->GetEffectiveUserID();
414}
415
416uint32_t
417SBAttachInfo::GetEffectiveGroupID()
418{
419 return m_opaque_sp->GetEffectiveGroupID();
420}
421
422bool
423SBAttachInfo::EffectiveUserIDIsValid ()
424{
425 return m_opaque_sp->EffectiveUserIDIsValid();
426}
427
428bool
429SBAttachInfo::EffectiveGroupIDIsValid ()
430{
431 return m_opaque_sp->EffectiveGroupIDIsValid ();
432}
433
434void
435SBAttachInfo::SetEffectiveUserID (uint32_t uid)
436{
437 m_opaque_sp->SetEffectiveUserID(uid);
438}
439
440void
441SBAttachInfo::SetEffectiveGroupID (uint32_t gid)
442{
443 m_opaque_sp->SetEffectiveGroupID(gid);
444}
445
446lldb::pid_t
447SBAttachInfo::GetParentProcessID ()
448{
449 return m_opaque_sp->GetParentProcessID();
450}
451
452void
453SBAttachInfo::SetParentProcessID (lldb::pid_t pid)
454{
455 m_opaque_sp->SetParentProcessID (pid);
456}
457
458bool
459SBAttachInfo::ParentProcessIDIsValid()
460{
461 return m_opaque_sp->ParentProcessIDIsValid();
462}
463
464
Chris Lattner24943d22010-06-08 16:52:24 +0000465//----------------------------------------------------------------------
466// SBTarget constructor
467//----------------------------------------------------------------------
Greg Claytonc3b61d22010-12-15 05:08:08 +0000468SBTarget::SBTarget () :
469 m_opaque_sp ()
Chris Lattner24943d22010-06-08 16:52:24 +0000470{
471}
472
473SBTarget::SBTarget (const SBTarget& rhs) :
Greg Clayton63094e02010-06-23 01:19:29 +0000474 m_opaque_sp (rhs.m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000475{
476}
477
478SBTarget::SBTarget(const TargetSP& target_sp) :
Greg Clayton63094e02010-06-23 01:19:29 +0000479 m_opaque_sp (target_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000480{
481}
482
Greg Clayton538eb822010-11-05 23:17:00 +0000483const SBTarget&
484SBTarget::operator = (const SBTarget& rhs)
485{
486 if (this != &rhs)
487 m_opaque_sp = rhs.m_opaque_sp;
488 return *this;
489}
490
Chris Lattner24943d22010-06-08 16:52:24 +0000491//----------------------------------------------------------------------
492// Destructor
493//----------------------------------------------------------------------
494SBTarget::~SBTarget()
495{
496}
497
Jim Ingham5a15e692012-02-16 06:50:00 +0000498const char *
499SBTarget::GetBroadcasterClassName ()
500{
501 return Target::GetStaticBroadcasterClass().AsCString();
502}
503
Chris Lattner24943d22010-06-08 16:52:24 +0000504bool
505SBTarget::IsValid () const
506{
Greg Clayton63094e02010-06-23 01:19:29 +0000507 return m_opaque_sp.get() != NULL;
Chris Lattner24943d22010-06-08 16:52:24 +0000508}
509
510SBProcess
511SBTarget::GetProcess ()
512{
513 SBProcess sb_process;
Greg Clayton334d33a2012-01-30 07:41:31 +0000514 ProcessSP process_sp;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000515 TargetSP target_sp(GetSP());
516 if (target_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000517 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000518 process_sp = target_sp->GetProcessSP();
Greg Clayton334d33a2012-01-30 07:41:31 +0000519 sb_process.SetSP (process_sp);
Greg Claytonbdcda462010-12-20 20:49:23 +0000520 }
Caroline Tice7826c882010-10-26 03:11:13 +0000521
Greg Claytone005f2c2010-11-06 01:53:30 +0000522 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000523 if (log)
524 {
Greg Clayton49ce6822010-10-31 03:01:06 +0000525 log->Printf ("SBTarget(%p)::GetProcess () => SBProcess(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +0000526 target_sp.get(), process_sp.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000527 }
528
Chris Lattner24943d22010-06-08 16:52:24 +0000529 return sb_process;
530}
531
Greg Clayton63094e02010-06-23 01:19:29 +0000532SBDebugger
533SBTarget::GetDebugger () const
534{
535 SBDebugger debugger;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000536 TargetSP target_sp(GetSP());
537 if (target_sp)
538 debugger.reset (target_sp->GetDebugger().shared_from_this());
Greg Clayton63094e02010-06-23 01:19:29 +0000539 return debugger;
540}
541
Jim Inghamb5871fe2011-03-31 00:01:24 +0000542SBProcess
543SBTarget::LaunchSimple
544(
545 char const **argv,
546 char const **envp,
547 const char *working_directory
548)
549{
550 char *stdin_path = NULL;
551 char *stdout_path = NULL;
552 char *stderr_path = NULL;
553 uint32_t launch_flags = 0;
554 bool stop_at_entry = false;
555 SBError error;
556 SBListener listener = GetDebugger().GetListener();
557 return Launch (listener,
558 argv,
559 envp,
560 stdin_path,
561 stdout_path,
562 stderr_path,
563 working_directory,
564 launch_flags,
565 stop_at_entry,
566 error);
567}
Greg Claytonde915be2011-01-23 05:56:20 +0000568
569SBProcess
570SBTarget::Launch
571(
Greg Clayton271a5db2011-02-03 21:28:34 +0000572 SBListener &listener,
Greg Claytonde915be2011-01-23 05:56:20 +0000573 char const **argv,
574 char const **envp,
575 const char *stdin_path,
576 const char *stdout_path,
577 const char *stderr_path,
578 const char *working_directory,
579 uint32_t launch_flags, // See LaunchFlags
580 bool stop_at_entry,
581 lldb::SBError& error
582)
583{
Greg Claytone005f2c2010-11-06 01:53:30 +0000584 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000585
Greg Clayton0416bdf2012-01-30 09:04:36 +0000586 SBProcess sb_process;
587 ProcessSP process_sp;
588 TargetSP target_sp(GetSP());
589
Caroline Tice7826c882010-10-26 03:11:13 +0000590 if (log)
Greg Clayton3f5ee7f2010-10-29 04:59:35 +0000591 {
Greg Claytonde915be2011-01-23 05:56:20 +0000592 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 +0000593 target_sp.get(),
Greg Claytonde915be2011-01-23 05:56:20 +0000594 argv,
595 envp,
596 stdin_path ? stdin_path : "NULL",
597 stdout_path ? stdout_path : "NULL",
598 stderr_path ? stderr_path : "NULL",
599 working_directory ? working_directory : "NULL",
600 launch_flags,
601 stop_at_entry,
602 error.get());
Greg Clayton3f5ee7f2010-10-29 04:59:35 +0000603 }
Greg Clayton0416bdf2012-01-30 09:04:36 +0000604
605 if (target_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000606 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000607 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton1a3083a2010-10-06 03:53:16 +0000608
Greg Clayton7c330d62011-01-27 01:01:10 +0000609 if (getenv("LLDB_LAUNCH_FLAG_DISABLE_ASLR"))
610 launch_flags |= eLaunchFlagDisableASLR;
611
Greg Clayton180546b2011-04-30 01:09:13 +0000612 StateType state = eStateInvalid;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000613 process_sp = target_sp->GetProcessSP();
Greg Clayton334d33a2012-01-30 07:41:31 +0000614 if (process_sp)
Greg Clayton28d5fcc2011-01-27 06:44:37 +0000615 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000616 state = process_sp->GetState();
Greg Clayton180546b2011-04-30 01:09:13 +0000617
Greg Clayton334d33a2012-01-30 07:41:31 +0000618 if (process_sp->IsAlive() && state != eStateConnected)
Greg Clayton180546b2011-04-30 01:09:13 +0000619 {
620 if (state == eStateAttaching)
621 error.SetErrorString ("process attach is in progress");
622 else
623 error.SetErrorString ("a process is already being debugged");
Greg Clayton180546b2011-04-30 01:09:13 +0000624 return sb_process;
625 }
Greg Clayton28d5fcc2011-01-27 06:44:37 +0000626 }
627
Greg Clayton180546b2011-04-30 01:09:13 +0000628 if (state == eStateConnected)
629 {
630 // If we are already connected, then we have already specified the
631 // listener, so if a valid listener is supplied, we need to error out
632 // to let the client know.
633 if (listener.IsValid())
634 {
635 error.SetErrorString ("process is connected and already has a listener, pass empty listener");
Greg Clayton180546b2011-04-30 01:09:13 +0000636 return sb_process;
637 }
638 }
639 else
Greg Claytonc5f728c2010-10-06 22:10:17 +0000640 {
Greg Clayton271a5db2011-02-03 21:28:34 +0000641 if (listener.IsValid())
Greg Clayton46c9a352012-02-09 06:16:32 +0000642 process_sp = target_sp->CreateProcess (listener.ref(), NULL, NULL);
Greg Clayton271a5db2011-02-03 21:28:34 +0000643 else
Greg Clayton46c9a352012-02-09 06:16:32 +0000644 process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener(), NULL, NULL);
Greg Clayton180546b2011-04-30 01:09:13 +0000645 }
Greg Clayton7c330d62011-01-27 01:01:10 +0000646
Greg Clayton334d33a2012-01-30 07:41:31 +0000647 if (process_sp)
Greg Clayton180546b2011-04-30 01:09:13 +0000648 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000649 sb_process.SetSP (process_sp);
Greg Clayton180546b2011-04-30 01:09:13 +0000650 if (getenv("LLDB_LAUNCH_FLAG_DISABLE_STDIO"))
651 launch_flags |= eLaunchFlagDisableSTDIO;
652
Greg Clayton36bc5ea2011-11-03 21:22:33 +0000653 ProcessLaunchInfo launch_info (stdin_path, stdout_path, stderr_path, working_directory, launch_flags);
654
Greg Clayton0416bdf2012-01-30 09:04:36 +0000655 Module *exe_module = target_sp->GetExecutableModulePointer();
Greg Clayton36bc5ea2011-11-03 21:22:33 +0000656 if (exe_module)
Greg Clayton1d1f39e2011-11-29 04:03:30 +0000657 launch_info.SetExecutableFile(exe_module->GetPlatformFileSpec(), true);
Greg Clayton36bc5ea2011-11-03 21:22:33 +0000658 if (argv)
659 launch_info.GetArguments().AppendArguments (argv);
660 if (envp)
661 launch_info.GetEnvironmentEntries ().SetArguments (envp);
662
Greg Clayton334d33a2012-01-30 07:41:31 +0000663 error.SetError (process_sp->Launch (launch_info));
Greg Clayton180546b2011-04-30 01:09:13 +0000664 if (error.Success())
Greg Clayton7c330d62011-01-27 01:01:10 +0000665 {
Greg Clayton180546b2011-04-30 01:09:13 +0000666 // We we are stopping at the entry point, we can return now!
667 if (stop_at_entry)
668 return sb_process;
Greg Clayton7c330d62011-01-27 01:01:10 +0000669
Greg Clayton180546b2011-04-30 01:09:13 +0000670 // Make sure we are stopped at the entry
Greg Clayton334d33a2012-01-30 07:41:31 +0000671 StateType state = process_sp->WaitForProcessToStop (NULL);
Greg Clayton180546b2011-04-30 01:09:13 +0000672 if (state == eStateStopped)
Greg Clayton7c330d62011-01-27 01:01:10 +0000673 {
Greg Clayton180546b2011-04-30 01:09:13 +0000674 // resume the process to skip the entry point
Greg Clayton334d33a2012-01-30 07:41:31 +0000675 error.SetError (process_sp->Resume());
Greg Clayton180546b2011-04-30 01:09:13 +0000676 if (error.Success())
Greg Clayton7c330d62011-01-27 01:01:10 +0000677 {
Greg Clayton180546b2011-04-30 01:09:13 +0000678 // If we are doing synchronous mode, then wait for the
679 // process to stop yet again!
Greg Clayton0416bdf2012-01-30 09:04:36 +0000680 if (target_sp->GetDebugger().GetAsyncExecution () == false)
Greg Clayton334d33a2012-01-30 07:41:31 +0000681 process_sp->WaitForProcessToStop (NULL);
Greg Clayton7c330d62011-01-27 01:01:10 +0000682 }
683 }
684 }
Greg Clayton180546b2011-04-30 01:09:13 +0000685 }
686 else
687 {
688 error.SetErrorString ("unable to create lldb_private::Process");
Greg Claytonc5f728c2010-10-06 22:10:17 +0000689 }
690 }
691 else
692 {
693 error.SetErrorString ("SBTarget is invalid");
Chris Lattner24943d22010-06-08 16:52:24 +0000694 }
Caroline Tice7826c882010-10-26 03:11:13 +0000695
Caroline Tice926060e2010-10-29 21:48:37 +0000696 log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
Caroline Tice7826c882010-10-26 03:11:13 +0000697 if (log)
698 {
Greg Clayton49ce6822010-10-31 03:01:06 +0000699 log->Printf ("SBTarget(%p)::Launch (...) => SBProceess(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +0000700 target_sp.get(), process_sp.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000701 }
702
Greg Clayton1a3083a2010-10-06 03:53:16 +0000703 return sb_process;
Chris Lattner24943d22010-06-08 16:52:24 +0000704}
705
Greg Clayton0a8dcac2012-02-24 05:03:03 +0000706SBProcess
707SBTarget::Launch (SBLaunchInfo &sb_launch_info, SBError& error)
708{
709 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
710
711 SBProcess sb_process;
712 ProcessSP process_sp;
713 TargetSP target_sp(GetSP());
714
715 if (log)
716 {
717 log->Printf ("SBTarget(%p)::Launch (launch_info, error)...", target_sp.get());
718 }
719
720 if (target_sp)
721 {
722 Mutex::Locker api_locker (target_sp->GetAPIMutex());
723 StateType state = eStateInvalid;
724 process_sp = target_sp->GetProcessSP();
725 if (process_sp)
726 {
727 state = process_sp->GetState();
728
729 if (process_sp->IsAlive() && state != eStateConnected)
730 {
731 if (state == eStateAttaching)
732 error.SetErrorString ("process attach is in progress");
733 else
734 error.SetErrorString ("a process is already being debugged");
735 return sb_process;
736 }
737 }
738
739 if (state != eStateConnected)
740 process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener(), NULL, NULL);
741
742 if (process_sp)
743 {
744 sb_process.SetSP (process_sp);
745 lldb_private::ProcessLaunchInfo &launch_info = sb_launch_info.ref();
746 error.SetError (process_sp->Launch (launch_info));
747 if (error.Success())
748 {
749 // We we are stopping at the entry point, we can return now!
750 if (launch_info.GetFlags().Test(eLaunchFlagStopAtEntry))
751 return sb_process;
752
753 // Make sure we are stopped at the entry
754 StateType state = process_sp->WaitForProcessToStop (NULL);
755 if (state == eStateStopped)
756 {
757 // resume the process to skip the entry point
758 error.SetError (process_sp->Resume());
759 if (error.Success())
760 {
761 // If we are doing synchronous mode, then wait for the
762 // process to stop yet again!
763 if (target_sp->GetDebugger().GetAsyncExecution () == false)
764 process_sp->WaitForProcessToStop (NULL);
765 }
766 }
767 }
768 }
769 else
770 {
771 error.SetErrorString ("unable to create lldb_private::Process");
772 }
773 }
774 else
775 {
776 error.SetErrorString ("SBTarget is invalid");
777 }
778
779 log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
780 if (log)
781 {
782 log->Printf ("SBTarget(%p)::Launch (...) => SBProceess(%p)",
783 target_sp.get(), process_sp.get());
784 }
785
786 return sb_process;
787}
788
789lldb::SBProcess
790SBTarget::Attach (SBAttachInfo &sb_attach_info, SBError& error)
791{
792 SBProcess sb_process;
793 ProcessSP process_sp;
794 TargetSP target_sp(GetSP());
795 if (target_sp)
796 {
797 Mutex::Locker api_locker (target_sp->GetAPIMutex());
798
799 StateType state = eStateInvalid;
800 process_sp = target_sp->GetProcessSP();
801 if (process_sp)
802 {
803 state = process_sp->GetState();
804
805 if (process_sp->IsAlive() && state != eStateConnected)
806 {
807 if (state == eStateAttaching)
808 error.SetErrorString ("process attach is in progress");
809 else
810 error.SetErrorString ("a process is already being debugged");
811 return sb_process;
812 }
813 }
814
815 if (state != eStateConnected)
816 process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener(), NULL, NULL);
817
818 if (process_sp)
819 {
820 sb_process.SetSP (process_sp);
821
822 ProcessAttachInfo &attach_info = sb_attach_info.ref();
823 error.SetError (process_sp->Attach (attach_info));
824 // If we are doing synchronous mode, then wait for the
825 // process to stop!
826 if (target_sp->GetDebugger().GetAsyncExecution () == false)
827 process_sp->WaitForProcessToStop (NULL);
828 }
829 else
830 {
831 error.SetErrorString ("unable to create lldb_private::Process");
832 }
833 }
834 else
835 {
836 error.SetErrorString ("SBTarget is invalid");
837 }
838 return sb_process;
839}
840
841
Greg Claytond5b0b442011-12-02 02:10:57 +0000842#if defined(__APPLE__)
843
844lldb::SBProcess
845SBTarget::AttachToProcessWithID (SBListener &listener,
846 ::pid_t pid,
847 lldb::SBError& error)
848{
849 return AttachToProcessWithID (listener, (lldb::pid_t)pid, error);
850}
851
852#endif // #if defined(__APPLE__)
Greg Claytonc5f728c2010-10-06 22:10:17 +0000853
854lldb::SBProcess
Greg Claytond8c62532010-10-07 04:19:01 +0000855SBTarget::AttachToProcessWithID
Greg Claytonc5f728c2010-10-06 22:10:17 +0000856(
Greg Clayton271a5db2011-02-03 21:28:34 +0000857 SBListener &listener,
Greg Claytonc5f728c2010-10-06 22:10:17 +0000858 lldb::pid_t pid,// The process ID to attach to
859 SBError& error // An error explaining what went wrong if attach fails
860)
861{
862 SBProcess sb_process;
Greg Clayton334d33a2012-01-30 07:41:31 +0000863 ProcessSP process_sp;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000864 TargetSP target_sp(GetSP());
865 if (target_sp)
Greg Claytonc5f728c2010-10-06 22:10:17 +0000866 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000867 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytonde1dd812011-06-24 03:21:43 +0000868
869 StateType state = eStateInvalid;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000870 process_sp = target_sp->GetProcessSP();
Greg Clayton334d33a2012-01-30 07:41:31 +0000871 if (process_sp)
Greg Claytonde1dd812011-06-24 03:21:43 +0000872 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000873 state = process_sp->GetState();
Greg Claytonde1dd812011-06-24 03:21:43 +0000874
Greg Clayton334d33a2012-01-30 07:41:31 +0000875 if (process_sp->IsAlive() && state != eStateConnected)
Greg Claytonde1dd812011-06-24 03:21:43 +0000876 {
877 if (state == eStateAttaching)
878 error.SetErrorString ("process attach is in progress");
879 else
880 error.SetErrorString ("a process is already being debugged");
Greg Claytonde1dd812011-06-24 03:21:43 +0000881 return sb_process;
882 }
883 }
884
885 if (state == eStateConnected)
886 {
887 // If we are already connected, then we have already specified the
888 // listener, so if a valid listener is supplied, we need to error out
889 // to let the client know.
890 if (listener.IsValid())
891 {
892 error.SetErrorString ("process is connected and already has a listener, pass empty listener");
Greg Claytonde1dd812011-06-24 03:21:43 +0000893 return sb_process;
894 }
895 }
Greg Clayton271a5db2011-02-03 21:28:34 +0000896 else
Greg Claytonde1dd812011-06-24 03:21:43 +0000897 {
898 if (listener.IsValid())
Greg Clayton46c9a352012-02-09 06:16:32 +0000899 process_sp = target_sp->CreateProcess (listener.ref(), NULL, NULL);
Greg Claytonde1dd812011-06-24 03:21:43 +0000900 else
Greg Clayton46c9a352012-02-09 06:16:32 +0000901 process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener(), NULL, NULL);
Greg Claytonde1dd812011-06-24 03:21:43 +0000902 }
Greg Clayton334d33a2012-01-30 07:41:31 +0000903 if (process_sp)
Greg Claytonc5f728c2010-10-06 22:10:17 +0000904 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000905 sb_process.SetSP (process_sp);
906
Greg Clayton527154d2011-11-15 03:53:30 +0000907 ProcessAttachInfo attach_info;
908 attach_info.SetProcessID (pid);
Greg Clayton334d33a2012-01-30 07:41:31 +0000909 error.SetError (process_sp->Attach (attach_info));
Johnny Chen535960e2011-06-17 00:51:15 +0000910 // If we are doing synchronous mode, then wait for the
911 // process to stop!
Greg Clayton0416bdf2012-01-30 09:04:36 +0000912 if (target_sp->GetDebugger().GetAsyncExecution () == false)
Greg Clayton334d33a2012-01-30 07:41:31 +0000913 process_sp->WaitForProcessToStop (NULL);
Greg Claytonc5f728c2010-10-06 22:10:17 +0000914 }
915 else
916 {
917 error.SetErrorString ("unable to create lldb_private::Process");
918 }
919 }
920 else
921 {
922 error.SetErrorString ("SBTarget is invalid");
923 }
924 return sb_process;
925
926}
927
928lldb::SBProcess
Greg Claytond8c62532010-10-07 04:19:01 +0000929SBTarget::AttachToProcessWithName
Greg Claytonc5f728c2010-10-06 22:10:17 +0000930(
Greg Clayton271a5db2011-02-03 21:28:34 +0000931 SBListener &listener,
Greg Claytonc5f728c2010-10-06 22:10:17 +0000932 const char *name, // basename of process to attach to
933 bool wait_for, // if true wait for a new instance of "name" to be launched
934 SBError& error // An error explaining what went wrong if attach fails
935)
936{
937 SBProcess sb_process;
Greg Clayton334d33a2012-01-30 07:41:31 +0000938 ProcessSP process_sp;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000939 TargetSP target_sp(GetSP());
940 if (name && target_sp)
Greg Claytonc5f728c2010-10-06 22:10:17 +0000941 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000942 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytonbdcda462010-12-20 20:49:23 +0000943
Greg Claytonde1dd812011-06-24 03:21:43 +0000944 StateType state = eStateInvalid;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000945 process_sp = target_sp->GetProcessSP();
Greg Clayton334d33a2012-01-30 07:41:31 +0000946 if (process_sp)
Greg Claytonde1dd812011-06-24 03:21:43 +0000947 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000948 state = process_sp->GetState();
Greg Claytonde1dd812011-06-24 03:21:43 +0000949
Greg Clayton334d33a2012-01-30 07:41:31 +0000950 if (process_sp->IsAlive() && state != eStateConnected)
Greg Claytonde1dd812011-06-24 03:21:43 +0000951 {
952 if (state == eStateAttaching)
953 error.SetErrorString ("process attach is in progress");
954 else
955 error.SetErrorString ("a process is already being debugged");
Greg Claytonde1dd812011-06-24 03:21:43 +0000956 return sb_process;
957 }
958 }
959
960 if (state == eStateConnected)
961 {
962 // If we are already connected, then we have already specified the
963 // listener, so if a valid listener is supplied, we need to error out
964 // to let the client know.
965 if (listener.IsValid())
966 {
967 error.SetErrorString ("process is connected and already has a listener, pass empty listener");
Greg Claytonde1dd812011-06-24 03:21:43 +0000968 return sb_process;
969 }
970 }
Greg Clayton271a5db2011-02-03 21:28:34 +0000971 else
Greg Claytonde1dd812011-06-24 03:21:43 +0000972 {
973 if (listener.IsValid())
Greg Clayton46c9a352012-02-09 06:16:32 +0000974 process_sp = target_sp->CreateProcess (listener.ref(), NULL, NULL);
Greg Claytonde1dd812011-06-24 03:21:43 +0000975 else
Greg Clayton46c9a352012-02-09 06:16:32 +0000976 process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener(), NULL, NULL);
Greg Claytonde1dd812011-06-24 03:21:43 +0000977 }
Greg Claytonc5f728c2010-10-06 22:10:17 +0000978
Greg Clayton334d33a2012-01-30 07:41:31 +0000979 if (process_sp)
Greg Claytonc5f728c2010-10-06 22:10:17 +0000980 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000981 sb_process.SetSP (process_sp);
Greg Clayton527154d2011-11-15 03:53:30 +0000982 ProcessAttachInfo attach_info;
983 attach_info.GetExecutableFile().SetFile(name, false);
984 attach_info.SetWaitForLaunch(wait_for);
Greg Clayton334d33a2012-01-30 07:41:31 +0000985 error.SetError (process_sp->Attach (attach_info));
Johnny Chen58d02ff2011-06-17 19:21:30 +0000986 // If we are doing synchronous mode, then wait for the
987 // process to stop!
Greg Clayton0416bdf2012-01-30 09:04:36 +0000988 if (target_sp->GetDebugger().GetAsyncExecution () == false)
Greg Clayton334d33a2012-01-30 07:41:31 +0000989 process_sp->WaitForProcessToStop (NULL);
Greg Claytonc5f728c2010-10-06 22:10:17 +0000990 }
991 else
992 {
993 error.SetErrorString ("unable to create lldb_private::Process");
994 }
995 }
996 else
997 {
998 error.SetErrorString ("SBTarget is invalid");
999 }
1000 return sb_process;
1001
1002}
1003
James McIlree38093402011-03-04 00:31:13 +00001004lldb::SBProcess
1005SBTarget::ConnectRemote
1006(
1007 SBListener &listener,
1008 const char *url,
1009 const char *plugin_name,
1010 SBError& error
1011)
1012{
1013 SBProcess sb_process;
Greg Clayton334d33a2012-01-30 07:41:31 +00001014 ProcessSP process_sp;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001015 TargetSP target_sp(GetSP());
1016 if (target_sp)
James McIlree38093402011-03-04 00:31:13 +00001017 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001018 Mutex::Locker api_locker (target_sp->GetAPIMutex());
James McIlree38093402011-03-04 00:31:13 +00001019 if (listener.IsValid())
Greg Clayton46c9a352012-02-09 06:16:32 +00001020 process_sp = target_sp->CreateProcess (listener.ref(), plugin_name, NULL);
James McIlree38093402011-03-04 00:31:13 +00001021 else
Greg Clayton46c9a352012-02-09 06:16:32 +00001022 process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener(), plugin_name, NULL);
James McIlree38093402011-03-04 00:31:13 +00001023
1024
Greg Clayton334d33a2012-01-30 07:41:31 +00001025 if (process_sp)
James McIlree38093402011-03-04 00:31:13 +00001026 {
Greg Clayton334d33a2012-01-30 07:41:31 +00001027 sb_process.SetSP (process_sp);
1028 error.SetError (process_sp->ConnectRemote (url));
James McIlree38093402011-03-04 00:31:13 +00001029 }
1030 else
1031 {
1032 error.SetErrorString ("unable to create lldb_private::Process");
1033 }
1034 }
1035 else
1036 {
1037 error.SetErrorString ("SBTarget is invalid");
1038 }
1039 return sb_process;
1040}
1041
Chris Lattner24943d22010-06-08 16:52:24 +00001042SBFileSpec
1043SBTarget::GetExecutable ()
1044{
Caroline Tice7826c882010-10-26 03:11:13 +00001045
Chris Lattner24943d22010-06-08 16:52:24 +00001046 SBFileSpec exe_file_spec;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001047 TargetSP target_sp(GetSP());
1048 if (target_sp)
Chris Lattner24943d22010-06-08 16:52:24 +00001049 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001050 Module *exe_module = target_sp->GetExecutableModulePointer();
Greg Clayton5beb99d2011-08-11 02:48:45 +00001051 if (exe_module)
1052 exe_file_spec.SetFileSpec (exe_module->GetFileSpec());
Chris Lattner24943d22010-06-08 16:52:24 +00001053 }
Caroline Tice7826c882010-10-26 03:11:13 +00001054
Greg Claytone005f2c2010-11-06 01:53:30 +00001055 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001056 if (log)
1057 {
Greg Clayton49ce6822010-10-31 03:01:06 +00001058 log->Printf ("SBTarget(%p)::GetExecutable () => SBFileSpec(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +00001059 target_sp.get(), exe_file_spec.get());
Caroline Tice7826c882010-10-26 03:11:13 +00001060 }
1061
Chris Lattner24943d22010-06-08 16:52:24 +00001062 return exe_file_spec;
1063}
1064
Chris Lattner24943d22010-06-08 16:52:24 +00001065bool
Chris Lattner24943d22010-06-08 16:52:24 +00001066SBTarget::operator == (const SBTarget &rhs) const
1067{
Greg Clayton63094e02010-06-23 01:19:29 +00001068 return m_opaque_sp.get() == rhs.m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +00001069}
1070
1071bool
1072SBTarget::operator != (const SBTarget &rhs) const
1073{
Greg Clayton63094e02010-06-23 01:19:29 +00001074 return m_opaque_sp.get() != rhs.m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +00001075}
1076
Greg Clayton334d33a2012-01-30 07:41:31 +00001077lldb::TargetSP
1078SBTarget::GetSP () const
Greg Clayton15afa9f2011-10-01 02:59:24 +00001079{
1080 return m_opaque_sp;
1081}
1082
Greg Clayton63094e02010-06-23 01:19:29 +00001083void
Greg Clayton334d33a2012-01-30 07:41:31 +00001084SBTarget::SetSP (const lldb::TargetSP& target_sp)
Greg Clayton63094e02010-06-23 01:19:29 +00001085{
1086 m_opaque_sp = target_sp;
Chris Lattner24943d22010-06-08 16:52:24 +00001087}
1088
Greg Claytona3955062011-07-22 16:46:35 +00001089lldb::SBAddress
1090SBTarget::ResolveLoadAddress (lldb::addr_t vm_addr)
Greg Claytonea49cc72010-12-12 19:25:26 +00001091{
Greg Claytona3955062011-07-22 16:46:35 +00001092 lldb::SBAddress sb_addr;
1093 Address &addr = sb_addr.ref();
Greg Clayton0416bdf2012-01-30 09:04:36 +00001094 TargetSP target_sp(GetSP());
1095 if (target_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +00001096 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001097 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1098 if (target_sp->GetSectionLoadList().ResolveLoadAddress (vm_addr, addr))
Greg Claytona3955062011-07-22 16:46:35 +00001099 return sb_addr;
Greg Claytonbdcda462010-12-20 20:49:23 +00001100 }
Greg Claytonea49cc72010-12-12 19:25:26 +00001101
Greg Claytona3955062011-07-22 16:46:35 +00001102 // We have a load address that isn't in a section, just return an address
1103 // with the offset filled in (the address) and the section set to NULL
Greg Clayton3508c382012-02-24 01:59:29 +00001104 addr.SetRawAddress(vm_addr);
Greg Claytona3955062011-07-22 16:46:35 +00001105 return sb_addr;
Greg Claytonea49cc72010-12-12 19:25:26 +00001106}
1107
Greg Claytonafb81862011-03-02 21:34:46 +00001108SBSymbolContext
1109SBTarget::ResolveSymbolContextForAddress (const SBAddress& addr, uint32_t resolve_scope)
1110{
1111 SBSymbolContext sc;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001112 if (addr.IsValid())
1113 {
1114 TargetSP target_sp(GetSP());
1115 if (target_sp)
1116 target_sp->GetImages().ResolveSymbolContextForAddress (addr.ref(), resolve_scope, sc.ref());
1117 }
Greg Claytonafb81862011-03-02 21:34:46 +00001118 return sc;
1119}
1120
1121
Chris Lattner24943d22010-06-08 16:52:24 +00001122SBBreakpoint
1123SBTarget::BreakpointCreateByLocation (const char *file, uint32_t line)
1124{
Greg Claytond6d806c2010-11-08 00:28:40 +00001125 return SBBreakpoint(BreakpointCreateByLocation (SBFileSpec (file, false), line));
Chris Lattner24943d22010-06-08 16:52:24 +00001126}
1127
1128SBBreakpoint
1129SBTarget::BreakpointCreateByLocation (const SBFileSpec &sb_file_spec, uint32_t line)
1130{
Greg Claytone005f2c2010-11-06 01:53:30 +00001131 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001132
Chris Lattner24943d22010-06-08 16:52:24 +00001133 SBBreakpoint sb_bp;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001134 TargetSP target_sp(GetSP());
1135 if (target_sp && line != 0)
Greg Claytonbdcda462010-12-20 20:49:23 +00001136 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001137 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1138 *sb_bp = target_sp->CreateBreakpoint (NULL, *sb_file_spec, line, true, false);
Greg Claytonbdcda462010-12-20 20:49:23 +00001139 }
Caroline Tice7826c882010-10-26 03:11:13 +00001140
1141 if (log)
1142 {
1143 SBStream sstr;
1144 sb_bp.GetDescription (sstr);
Greg Clayton49ce6822010-10-31 03:01:06 +00001145 char path[PATH_MAX];
1146 sb_file_spec->GetPath (path, sizeof(path));
1147 log->Printf ("SBTarget(%p)::BreakpointCreateByLocation ( %s:%u ) => SBBreakpoint(%p): %s",
Greg Clayton0416bdf2012-01-30 09:04:36 +00001148 target_sp.get(),
Greg Clayton49ce6822010-10-31 03:01:06 +00001149 path,
Greg Claytona66ba462010-10-30 04:51:46 +00001150 line,
Greg Clayton49ce6822010-10-31 03:01:06 +00001151 sb_bp.get(),
Caroline Tice7826c882010-10-26 03:11:13 +00001152 sstr.GetData());
1153 }
1154
Chris Lattner24943d22010-06-08 16:52:24 +00001155 return sb_bp;
1156}
1157
1158SBBreakpoint
1159SBTarget::BreakpointCreateByName (const char *symbol_name, const char *module_name)
1160{
Greg Claytone005f2c2010-11-06 01:53:30 +00001161 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001162
Chris Lattner24943d22010-06-08 16:52:24 +00001163 SBBreakpoint sb_bp;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001164 TargetSP target_sp(GetSP());
1165 if (target_sp.get())
Chris Lattner24943d22010-06-08 16:52:24 +00001166 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001167 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Chris Lattner24943d22010-06-08 16:52:24 +00001168 if (module_name && module_name[0])
1169 {
Jim Ingham03c8ee52011-09-21 01:17:13 +00001170 FileSpecList module_spec_list;
1171 module_spec_list.Append (FileSpec (module_name, false));
Greg Clayton0416bdf2012-01-30 09:04:36 +00001172 *sb_bp = target_sp->CreateBreakpoint (&module_spec_list, NULL, symbol_name, eFunctionNameTypeAuto, false);
Chris Lattner24943d22010-06-08 16:52:24 +00001173 }
1174 else
1175 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001176 *sb_bp = target_sp->CreateBreakpoint (NULL, NULL, symbol_name, eFunctionNameTypeAuto, false);
Chris Lattner24943d22010-06-08 16:52:24 +00001177 }
1178 }
Caroline Tice7826c882010-10-26 03:11:13 +00001179
1180 if (log)
1181 {
Greg Clayton49ce6822010-10-31 03:01:06 +00001182 log->Printf ("SBTarget(%p)::BreakpointCreateByName (symbol=\"%s\", module=\"%s\") => SBBreakpoint(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +00001183 target_sp.get(), symbol_name, module_name, sb_bp.get());
Caroline Tice7826c882010-10-26 03:11:13 +00001184 }
1185
Chris Lattner24943d22010-06-08 16:52:24 +00001186 return sb_bp;
1187}
1188
Jim Inghamd6d47972011-09-23 00:54:11 +00001189lldb::SBBreakpoint
1190SBTarget::BreakpointCreateByName (const char *symbol_name,
1191 const SBFileSpecList &module_list,
1192 const SBFileSpecList &comp_unit_list)
1193{
Jim Ingham1fb8a2d2011-10-11 01:18:55 +00001194 uint32_t name_type_mask = eFunctionNameTypeAuto;
1195 return BreakpointCreateByName (symbol_name, name_type_mask, module_list, comp_unit_list);
1196}
1197
1198lldb::SBBreakpoint
1199SBTarget::BreakpointCreateByName (const char *symbol_name,
1200 uint32_t name_type_mask,
1201 const SBFileSpecList &module_list,
1202 const SBFileSpecList &comp_unit_list)
1203{
Jim Inghamd6d47972011-09-23 00:54:11 +00001204 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1205
1206 SBBreakpoint sb_bp;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001207 TargetSP target_sp(GetSP());
1208 if (target_sp && symbol_name && symbol_name[0])
Jim Inghamd6d47972011-09-23 00:54:11 +00001209 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001210 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1211 *sb_bp = target_sp->CreateBreakpoint (module_list.get(),
Jim Inghamd6d47972011-09-23 00:54:11 +00001212 comp_unit_list.get(),
1213 symbol_name,
Jim Ingham1fb8a2d2011-10-11 01:18:55 +00001214 name_type_mask,
Jim Inghamd6d47972011-09-23 00:54:11 +00001215 false);
1216 }
1217
1218 if (log)
1219 {
Jim Ingham1fb8a2d2011-10-11 01:18:55 +00001220 log->Printf ("SBTarget(%p)::BreakpointCreateByName (symbol=\"%s\", name_type: %d) => SBBreakpoint(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +00001221 target_sp.get(), symbol_name, name_type_mask, sb_bp.get());
Jim Inghamd6d47972011-09-23 00:54:11 +00001222 }
1223
1224 return sb_bp;
1225}
1226
1227
Chris Lattner24943d22010-06-08 16:52:24 +00001228SBBreakpoint
1229SBTarget::BreakpointCreateByRegex (const char *symbol_name_regex, const char *module_name)
1230{
Greg Claytone005f2c2010-11-06 01:53:30 +00001231 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001232
Chris Lattner24943d22010-06-08 16:52:24 +00001233 SBBreakpoint sb_bp;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001234 TargetSP target_sp(GetSP());
1235 if (target_sp && symbol_name_regex && symbol_name_regex[0])
Chris Lattner24943d22010-06-08 16:52:24 +00001236 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001237 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Chris Lattner24943d22010-06-08 16:52:24 +00001238 RegularExpression regexp(symbol_name_regex);
1239
1240 if (module_name && module_name[0])
1241 {
Jim Ingham03c8ee52011-09-21 01:17:13 +00001242 FileSpecList module_spec_list;
1243 module_spec_list.Append (FileSpec (module_name, false));
Chris Lattner24943d22010-06-08 16:52:24 +00001244
Greg Clayton0416bdf2012-01-30 09:04:36 +00001245 *sb_bp = target_sp->CreateFuncRegexBreakpoint (&module_spec_list, NULL, regexp, false);
Chris Lattner24943d22010-06-08 16:52:24 +00001246 }
1247 else
1248 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001249 *sb_bp = target_sp->CreateFuncRegexBreakpoint (NULL, NULL, regexp, false);
Chris Lattner24943d22010-06-08 16:52:24 +00001250 }
1251 }
Caroline Tice7826c882010-10-26 03:11:13 +00001252
1253 if (log)
1254 {
Greg Clayton49ce6822010-10-31 03:01:06 +00001255 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (symbol_regex=\"%s\", module_name=\"%s\") => SBBreakpoint(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +00001256 target_sp.get(), symbol_name_regex, module_name, sb_bp.get());
Caroline Tice7826c882010-10-26 03:11:13 +00001257 }
1258
Chris Lattner24943d22010-06-08 16:52:24 +00001259 return sb_bp;
1260}
1261
Jim Inghamd6d47972011-09-23 00:54:11 +00001262lldb::SBBreakpoint
1263SBTarget::BreakpointCreateByRegex (const char *symbol_name_regex,
1264 const SBFileSpecList &module_list,
1265 const SBFileSpecList &comp_unit_list)
1266{
1267 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Chris Lattner24943d22010-06-08 16:52:24 +00001268
Jim Inghamd6d47972011-09-23 00:54:11 +00001269 SBBreakpoint sb_bp;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001270 TargetSP target_sp(GetSP());
1271 if (target_sp && symbol_name_regex && symbol_name_regex[0])
Jim Inghamd6d47972011-09-23 00:54:11 +00001272 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001273 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Jim Inghamd6d47972011-09-23 00:54:11 +00001274 RegularExpression regexp(symbol_name_regex);
1275
Greg Clayton0416bdf2012-01-30 09:04:36 +00001276 *sb_bp = target_sp->CreateFuncRegexBreakpoint (module_list.get(), comp_unit_list.get(), regexp, false);
Jim Inghamd6d47972011-09-23 00:54:11 +00001277 }
1278
1279 if (log)
1280 {
1281 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (symbol_regex=\"%s\") => SBBreakpoint(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +00001282 target_sp.get(), symbol_name_regex, sb_bp.get());
Jim Inghamd6d47972011-09-23 00:54:11 +00001283 }
1284
1285 return sb_bp;
1286}
Chris Lattner24943d22010-06-08 16:52:24 +00001287
1288SBBreakpoint
1289SBTarget::BreakpointCreateByAddress (addr_t address)
1290{
Greg Claytone005f2c2010-11-06 01:53:30 +00001291 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001292
Chris Lattner24943d22010-06-08 16:52:24 +00001293 SBBreakpoint sb_bp;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001294 TargetSP target_sp(GetSP());
1295 if (target_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +00001296 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001297 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1298 *sb_bp = target_sp->CreateBreakpoint (address, false);
Greg Claytonbdcda462010-12-20 20:49:23 +00001299 }
Caroline Tice7826c882010-10-26 03:11:13 +00001300
1301 if (log)
1302 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001303 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 +00001304 }
1305
Chris Lattner24943d22010-06-08 16:52:24 +00001306 return sb_bp;
1307}
1308
Jim Ingham03c8ee52011-09-21 01:17:13 +00001309lldb::SBBreakpoint
1310SBTarget::BreakpointCreateBySourceRegex (const char *source_regex, const lldb::SBFileSpec &source_file, const char *module_name)
1311{
1312 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1313
1314 SBBreakpoint sb_bp;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001315 TargetSP target_sp(GetSP());
1316 if (target_sp && source_regex && source_regex[0])
Jim Ingham03c8ee52011-09-21 01:17:13 +00001317 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001318 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Jim Ingham03c8ee52011-09-21 01:17:13 +00001319 RegularExpression regexp(source_regex);
Jim Inghamd6d47972011-09-23 00:54:11 +00001320 FileSpecList source_file_spec_list;
1321 source_file_spec_list.Append (source_file.ref());
Jim Ingham03c8ee52011-09-21 01:17:13 +00001322
1323 if (module_name && module_name[0])
1324 {
1325 FileSpecList module_spec_list;
1326 module_spec_list.Append (FileSpec (module_name, false));
1327
Greg Clayton0416bdf2012-01-30 09:04:36 +00001328 *sb_bp = target_sp->CreateSourceRegexBreakpoint (&module_spec_list, &source_file_spec_list, regexp, false);
Jim Ingham03c8ee52011-09-21 01:17:13 +00001329 }
1330 else
1331 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001332 *sb_bp = target_sp->CreateSourceRegexBreakpoint (NULL, &source_file_spec_list, regexp, false);
Jim Ingham03c8ee52011-09-21 01:17:13 +00001333 }
1334 }
1335
1336 if (log)
1337 {
1338 char path[PATH_MAX];
1339 source_file->GetPath (path, sizeof(path));
1340 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (source_regex=\"%s\", file=\"%s\", module_name=\"%s\") => SBBreakpoint(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +00001341 target_sp.get(), source_regex, path, module_name, sb_bp.get());
Jim Ingham03c8ee52011-09-21 01:17:13 +00001342 }
1343
1344 return sb_bp;
1345}
1346
Jim Inghamd6d47972011-09-23 00:54:11 +00001347lldb::SBBreakpoint
1348SBTarget::BreakpointCreateBySourceRegex (const char *source_regex,
1349 const SBFileSpecList &module_list,
1350 const lldb::SBFileSpecList &source_file_list)
1351{
1352 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1353
1354 SBBreakpoint sb_bp;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001355 TargetSP target_sp(GetSP());
1356 if (target_sp && source_regex && source_regex[0])
Jim Inghamd6d47972011-09-23 00:54:11 +00001357 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001358 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Jim Inghamd6d47972011-09-23 00:54:11 +00001359 RegularExpression regexp(source_regex);
Greg Clayton0416bdf2012-01-30 09:04:36 +00001360 *sb_bp = target_sp->CreateSourceRegexBreakpoint (module_list.get(), source_file_list.get(), regexp, false);
Jim Inghamd6d47972011-09-23 00:54:11 +00001361 }
1362
1363 if (log)
1364 {
1365 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (source_regex=\"%s\") => SBBreakpoint(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +00001366 target_sp.get(), source_regex, sb_bp.get());
Jim Inghamd6d47972011-09-23 00:54:11 +00001367 }
1368
1369 return sb_bp;
1370}
Jim Ingham03c8ee52011-09-21 01:17:13 +00001371
Greg Claytonc7f5d5c2010-07-23 23:33:17 +00001372uint32_t
1373SBTarget::GetNumBreakpoints () const
1374{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001375 TargetSP target_sp(GetSP());
1376 if (target_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +00001377 {
1378 // The breakpoint list is thread safe, no need to lock
Greg Clayton0416bdf2012-01-30 09:04:36 +00001379 return target_sp->GetBreakpointList().GetSize();
Greg Claytonbdcda462010-12-20 20:49:23 +00001380 }
Greg Claytonc7f5d5c2010-07-23 23:33:17 +00001381 return 0;
1382}
1383
1384SBBreakpoint
1385SBTarget::GetBreakpointAtIndex (uint32_t idx) const
1386{
1387 SBBreakpoint sb_breakpoint;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001388 TargetSP target_sp(GetSP());
1389 if (target_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +00001390 {
1391 // The breakpoint list is thread safe, no need to lock
Greg Clayton0416bdf2012-01-30 09:04:36 +00001392 *sb_breakpoint = target_sp->GetBreakpointList().GetBreakpointAtIndex(idx);
Greg Claytonbdcda462010-12-20 20:49:23 +00001393 }
Greg Claytonc7f5d5c2010-07-23 23:33:17 +00001394 return sb_breakpoint;
1395}
Chris Lattner24943d22010-06-08 16:52:24 +00001396
1397bool
1398SBTarget::BreakpointDelete (break_id_t bp_id)
1399{
Greg Claytone005f2c2010-11-06 01:53:30 +00001400 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001401
Caroline Tice7826c882010-10-26 03:11:13 +00001402 bool result = false;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001403 TargetSP target_sp(GetSP());
1404 if (target_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +00001405 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001406 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1407 result = target_sp->RemoveBreakpointByID (bp_id);
Greg Claytonbdcda462010-12-20 20:49:23 +00001408 }
Caroline Tice7826c882010-10-26 03:11:13 +00001409
1410 if (log)
1411 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001412 log->Printf ("SBTarget(%p)::BreakpointDelete (bp_id=%d) => %i", target_sp.get(), (uint32_t) bp_id, result);
Caroline Tice7826c882010-10-26 03:11:13 +00001413 }
1414
1415 return result;
Chris Lattner24943d22010-06-08 16:52:24 +00001416}
1417
Johnny Chen096c2932011-09-26 22:40:50 +00001418SBBreakpoint
1419SBTarget::FindBreakpointByID (break_id_t bp_id)
1420{
1421 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1422
1423 SBBreakpoint sb_breakpoint;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001424 TargetSP target_sp(GetSP());
1425 if (target_sp && bp_id != LLDB_INVALID_BREAK_ID)
Johnny Chen096c2932011-09-26 22:40:50 +00001426 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001427 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1428 *sb_breakpoint = target_sp->GetBreakpointByID (bp_id);
Johnny Chen096c2932011-09-26 22:40:50 +00001429 }
1430
1431 if (log)
1432 {
1433 log->Printf ("SBTarget(%p)::FindBreakpointByID (bp_id=%d) => SBBreakpoint(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +00001434 target_sp.get(), (uint32_t) bp_id, sb_breakpoint.get());
Johnny Chen096c2932011-09-26 22:40:50 +00001435 }
1436
1437 return sb_breakpoint;
1438}
1439
Chris Lattner24943d22010-06-08 16:52:24 +00001440bool
1441SBTarget::EnableAllBreakpoints ()
1442{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001443 TargetSP target_sp(GetSP());
1444 if (target_sp)
Chris Lattner24943d22010-06-08 16:52:24 +00001445 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001446 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1447 target_sp->EnableAllBreakpoints ();
Chris Lattner24943d22010-06-08 16:52:24 +00001448 return true;
1449 }
1450 return false;
1451}
1452
1453bool
1454SBTarget::DisableAllBreakpoints ()
1455{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001456 TargetSP target_sp(GetSP());
1457 if (target_sp)
Chris Lattner24943d22010-06-08 16:52:24 +00001458 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001459 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1460 target_sp->DisableAllBreakpoints ();
Chris Lattner24943d22010-06-08 16:52:24 +00001461 return true;
1462 }
1463 return false;
1464}
1465
1466bool
1467SBTarget::DeleteAllBreakpoints ()
1468{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001469 TargetSP target_sp(GetSP());
1470 if (target_sp)
Chris Lattner24943d22010-06-08 16:52:24 +00001471 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001472 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1473 target_sp->RemoveAllBreakpoints ();
Chris Lattner24943d22010-06-08 16:52:24 +00001474 return true;
1475 }
1476 return false;
1477}
1478
Johnny Chen096c2932011-09-26 22:40:50 +00001479uint32_t
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001480SBTarget::GetNumWatchpoints () const
Johnny Chen096c2932011-09-26 22:40:50 +00001481{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001482 TargetSP target_sp(GetSP());
1483 if (target_sp)
Johnny Chen096c2932011-09-26 22:40:50 +00001484 {
Johnny Chenecd4feb2011-10-14 00:42:25 +00001485 // The watchpoint list is thread safe, no need to lock
Greg Clayton0416bdf2012-01-30 09:04:36 +00001486 return target_sp->GetWatchpointList().GetSize();
Johnny Chen096c2932011-09-26 22:40:50 +00001487 }
1488 return 0;
1489}
1490
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001491SBWatchpoint
1492SBTarget::GetWatchpointAtIndex (uint32_t idx) const
Johnny Chen5eb54bb2011-09-27 20:29:45 +00001493{
Johnny Chenecd4feb2011-10-14 00:42:25 +00001494 SBWatchpoint sb_watchpoint;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001495 TargetSP target_sp(GetSP());
1496 if (target_sp)
Johnny Chen096c2932011-09-26 22:40:50 +00001497 {
Johnny Chenecd4feb2011-10-14 00:42:25 +00001498 // The watchpoint list is thread safe, no need to lock
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001499 sb_watchpoint.SetSP (target_sp->GetWatchpointList().GetByIndex(idx));
Johnny Chen096c2932011-09-26 22:40:50 +00001500 }
Johnny Chenecd4feb2011-10-14 00:42:25 +00001501 return sb_watchpoint;
Johnny Chen096c2932011-09-26 22:40:50 +00001502}
1503
1504bool
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001505SBTarget::DeleteWatchpoint (watch_id_t wp_id)
Johnny Chen096c2932011-09-26 22:40:50 +00001506{
1507 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1508
1509 bool result = false;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001510 TargetSP target_sp(GetSP());
1511 if (target_sp)
Johnny Chen096c2932011-09-26 22:40:50 +00001512 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001513 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1514 result = target_sp->RemoveWatchpointByID (wp_id);
Johnny Chen096c2932011-09-26 22:40:50 +00001515 }
1516
1517 if (log)
1518 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001519 log->Printf ("SBTarget(%p)::WatchpointDelete (wp_id=%d) => %i", target_sp.get(), (uint32_t) wp_id, result);
Johnny Chen096c2932011-09-26 22:40:50 +00001520 }
1521
1522 return result;
1523}
1524
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001525SBWatchpoint
1526SBTarget::FindWatchpointByID (lldb::watch_id_t wp_id)
Johnny Chen096c2932011-09-26 22:40:50 +00001527{
1528 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1529
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001530 SBWatchpoint sb_watchpoint;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001531 lldb::WatchpointSP watchpoint_sp;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001532 TargetSP target_sp(GetSP());
1533 if (target_sp && wp_id != LLDB_INVALID_WATCH_ID)
Johnny Chen096c2932011-09-26 22:40:50 +00001534 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001535 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001536 watchpoint_sp = target_sp->GetWatchpointList().FindByID(wp_id);
1537 sb_watchpoint.SetSP (watchpoint_sp);
Johnny Chen096c2932011-09-26 22:40:50 +00001538 }
1539
1540 if (log)
1541 {
Johnny Chenecd4feb2011-10-14 00:42:25 +00001542 log->Printf ("SBTarget(%p)::FindWatchpointByID (bp_id=%d) => SBWatchpoint(%p)",
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001543 target_sp.get(), (uint32_t) wp_id, watchpoint_sp.get());
Johnny Chen096c2932011-09-26 22:40:50 +00001544 }
1545
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001546 return sb_watchpoint;
1547}
1548
1549lldb::SBWatchpoint
1550SBTarget::WatchAddress (lldb::addr_t addr, size_t size, bool read, bool write)
1551{
1552 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1553
1554 SBWatchpoint sb_watchpoint;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001555 lldb::WatchpointSP watchpoint_sp;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001556 TargetSP target_sp(GetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001557 if (target_sp && (read || write) && addr != LLDB_INVALID_ADDRESS && size > 0)
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001558 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001559 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001560 uint32_t watch_type = 0;
1561 if (read)
1562 watch_type |= LLDB_WATCH_TYPE_READ;
1563 if (write)
1564 watch_type |= LLDB_WATCH_TYPE_WRITE;
1565 watchpoint_sp = target_sp->CreateWatchpoint(addr, size, watch_type);
1566 sb_watchpoint.SetSP (watchpoint_sp);
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001567 }
1568
1569 if (log)
1570 {
1571 log->Printf ("SBTarget(%p)::WatchAddress (addr=0x%llx, 0x%u) => SBWatchpoint(%p)",
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001572 target_sp.get(), addr, (uint32_t) size, watchpoint_sp.get());
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001573 }
1574
1575 return sb_watchpoint;
Johnny Chen096c2932011-09-26 22:40:50 +00001576}
1577
1578bool
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001579SBTarget::EnableAllWatchpoints ()
Johnny Chen096c2932011-09-26 22:40:50 +00001580{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001581 TargetSP target_sp(GetSP());
1582 if (target_sp)
Johnny Chen096c2932011-09-26 22:40:50 +00001583 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001584 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1585 target_sp->EnableAllWatchpoints ();
Johnny Chen096c2932011-09-26 22:40:50 +00001586 return true;
1587 }
1588 return false;
1589}
1590
1591bool
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001592SBTarget::DisableAllWatchpoints ()
Johnny Chen096c2932011-09-26 22:40:50 +00001593{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001594 TargetSP target_sp(GetSP());
1595 if (target_sp)
Johnny Chen096c2932011-09-26 22:40:50 +00001596 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001597 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1598 target_sp->DisableAllWatchpoints ();
Johnny Chen096c2932011-09-26 22:40:50 +00001599 return true;
1600 }
1601 return false;
1602}
1603
1604bool
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001605SBTarget::DeleteAllWatchpoints ()
Johnny Chen096c2932011-09-26 22:40:50 +00001606{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001607 TargetSP target_sp(GetSP());
1608 if (target_sp)
Johnny Chen096c2932011-09-26 22:40:50 +00001609 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001610 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1611 target_sp->RemoveAllWatchpoints ();
Johnny Chen096c2932011-09-26 22:40:50 +00001612 return true;
1613 }
1614 return false;
1615}
1616
Chris Lattner24943d22010-06-08 16:52:24 +00001617
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001618lldb::SBModule
1619SBTarget::AddModule (const char *path,
1620 const char *triple,
1621 const char *uuid_cstr)
1622{
1623 lldb::SBModule sb_module;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001624 TargetSP target_sp(GetSP());
1625 if (target_sp)
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001626 {
1627 FileSpec module_file_spec;
1628 UUID module_uuid;
1629 ArchSpec module_arch;
1630
1631 if (path)
1632 module_file_spec.SetFile(path, false);
1633
1634 if (uuid_cstr)
1635 module_uuid.SetfromCString(uuid_cstr);
1636
1637 if (triple)
Greg Clayton0416bdf2012-01-30 09:04:36 +00001638 module_arch.SetTriple (triple, target_sp->GetPlatform ().get());
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001639
Greg Clayton0416bdf2012-01-30 09:04:36 +00001640 sb_module.SetSP(target_sp->GetSharedModule (module_file_spec,
1641 module_arch,
1642 uuid_cstr ? &module_uuid : NULL));
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001643 }
1644 return sb_module;
1645}
1646
1647bool
1648SBTarget::AddModule (lldb::SBModule &module)
1649{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001650 TargetSP target_sp(GetSP());
1651 if (target_sp)
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001652 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001653 target_sp->GetImages().AppendIfNeeded (module.GetSP());
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001654 return true;
1655 }
1656 return false;
1657}
1658
Chris Lattner24943d22010-06-08 16:52:24 +00001659uint32_t
1660SBTarget::GetNumModules () const
1661{
Greg Claytone005f2c2010-11-06 01:53:30 +00001662 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001663
Caroline Tice7826c882010-10-26 03:11:13 +00001664 uint32_t num = 0;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001665 TargetSP target_sp(GetSP());
1666 if (target_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +00001667 {
1668 // The module list is thread safe, no need to lock
Greg Clayton0416bdf2012-01-30 09:04:36 +00001669 num = target_sp->GetImages().GetSize();
Greg Claytonbdcda462010-12-20 20:49:23 +00001670 }
Caroline Tice7826c882010-10-26 03:11:13 +00001671
1672 if (log)
Greg Clayton0416bdf2012-01-30 09:04:36 +00001673 log->Printf ("SBTarget(%p)::GetNumModules () => %d", target_sp.get(), num);
Caroline Tice7826c882010-10-26 03:11:13 +00001674
1675 return num;
Chris Lattner24943d22010-06-08 16:52:24 +00001676}
1677
Greg Clayton43490d12010-07-30 20:12:55 +00001678void
1679SBTarget::Clear ()
1680{
Greg Claytone005f2c2010-11-06 01:53:30 +00001681 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001682
1683 if (log)
Greg Clayton3f5ee7f2010-10-29 04:59:35 +00001684 log->Printf ("SBTarget(%p)::Clear ()", m_opaque_sp.get());
Caroline Tice7826c882010-10-26 03:11:13 +00001685
Greg Clayton43490d12010-07-30 20:12:55 +00001686 m_opaque_sp.reset();
1687}
1688
1689
Chris Lattner24943d22010-06-08 16:52:24 +00001690SBModule
1691SBTarget::FindModule (const SBFileSpec &sb_file_spec)
1692{
1693 SBModule sb_module;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001694 TargetSP target_sp(GetSP());
1695 if (target_sp && sb_file_spec.IsValid())
Greg Claytonbdcda462010-12-20 20:49:23 +00001696 {
1697 // The module list is thread safe, no need to lock
Greg Clayton0416bdf2012-01-30 09:04:36 +00001698 sb_module.SetSP (target_sp->GetImages().FindFirstModuleForFileSpec (*sb_file_spec, NULL, NULL));
Greg Claytonbdcda462010-12-20 20:49:23 +00001699 }
Chris Lattner24943d22010-06-08 16:52:24 +00001700 return sb_module;
1701}
1702
Greg Clayton1b925202012-01-29 06:07:39 +00001703lldb::ByteOrder
1704SBTarget::GetByteOrder ()
1705{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001706 TargetSP target_sp(GetSP());
1707 if (target_sp)
1708 return target_sp->GetArchitecture().GetByteOrder();
Greg Clayton1b925202012-01-29 06:07:39 +00001709 return eByteOrderInvalid;
1710}
1711
1712const char *
1713SBTarget::GetTriple ()
1714{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001715 TargetSP target_sp(GetSP());
1716 if (target_sp)
Greg Clayton1b925202012-01-29 06:07:39 +00001717 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001718 std::string triple (target_sp->GetArchitecture().GetTriple().str());
Greg Clayton1b925202012-01-29 06:07:39 +00001719 // Unique the string so we don't run into ownership issues since
1720 // the const strings put the string into the string pool once and
1721 // the strings never comes out
1722 ConstString const_triple (triple.c_str());
1723 return const_triple.GetCString();
1724 }
1725 return NULL;
1726}
1727
1728uint32_t
1729SBTarget::GetAddressByteSize()
1730{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001731 TargetSP target_sp(GetSP());
1732 if (target_sp)
1733 return target_sp->GetArchitecture().GetAddressByteSize();
Greg Clayton1b925202012-01-29 06:07:39 +00001734 return sizeof(void*);
1735}
1736
1737
Chris Lattner24943d22010-06-08 16:52:24 +00001738SBModule
1739SBTarget::GetModuleAtIndex (uint32_t idx)
1740{
Greg Claytone005f2c2010-11-06 01:53:30 +00001741 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001742
Chris Lattner24943d22010-06-08 16:52:24 +00001743 SBModule sb_module;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001744 ModuleSP module_sp;
1745 TargetSP target_sp(GetSP());
1746 if (target_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +00001747 {
1748 // The module list is thread safe, no need to lock
Greg Clayton0416bdf2012-01-30 09:04:36 +00001749 module_sp = target_sp->GetImages().GetModuleAtIndex(idx);
1750 sb_module.SetSP (module_sp);
Greg Claytonbdcda462010-12-20 20:49:23 +00001751 }
Caroline Tice7826c882010-10-26 03:11:13 +00001752
1753 if (log)
1754 {
Greg Clayton49ce6822010-10-31 03:01:06 +00001755 log->Printf ("SBTarget(%p)::GetModuleAtIndex (idx=%d) => SBModule(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +00001756 target_sp.get(), idx, module_sp.get());
Caroline Tice7826c882010-10-26 03:11:13 +00001757 }
1758
Chris Lattner24943d22010-06-08 16:52:24 +00001759 return sb_module;
1760}
1761
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001762bool
1763SBTarget::RemoveModule (lldb::SBModule module)
1764{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001765 TargetSP target_sp(GetSP());
1766 if (target_sp)
1767 return target_sp->GetImages().Remove(module.GetSP());
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001768 return false;
1769}
1770
Chris Lattner24943d22010-06-08 16:52:24 +00001771
1772SBBroadcaster
1773SBTarget::GetBroadcaster () const
1774{
Greg Claytone005f2c2010-11-06 01:53:30 +00001775 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001776
Greg Clayton0416bdf2012-01-30 09:04:36 +00001777 TargetSP target_sp(GetSP());
1778 SBBroadcaster broadcaster(target_sp.get(), false);
Caroline Tice7826c882010-10-26 03:11:13 +00001779
1780 if (log)
Greg Clayton3f5ee7f2010-10-29 04:59:35 +00001781 log->Printf ("SBTarget(%p)::GetBroadcaster () => SBBroadcaster(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +00001782 target_sp.get(), broadcaster.get());
Caroline Tice7826c882010-10-26 03:11:13 +00001783
Chris Lattner24943d22010-06-08 16:52:24 +00001784 return broadcaster;
1785}
1786
Caroline Tice98f930f2010-09-20 05:20:02 +00001787bool
Caroline Tice7826c882010-10-26 03:11:13 +00001788SBTarget::GetDescription (SBStream &description, lldb::DescriptionLevel description_level)
Caroline Tice98f930f2010-09-20 05:20:02 +00001789{
Greg Clayton96154be2011-11-13 06:57:31 +00001790 Stream &strm = description.ref();
1791
Greg Clayton0416bdf2012-01-30 09:04:36 +00001792 TargetSP target_sp(GetSP());
1793 if (target_sp)
Caroline Ticee7a566e2010-09-20 16:21:41 +00001794 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001795 target_sp->Dump (&strm, description_level);
Caroline Tice7826c882010-10-26 03:11:13 +00001796 }
1797 else
Greg Clayton96154be2011-11-13 06:57:31 +00001798 strm.PutCString ("No value");
Caroline Tice7826c882010-10-26 03:11:13 +00001799
1800 return true;
1801}
1802
Greg Clayton7dd5c512012-02-06 01:44:54 +00001803lldb::SBSymbolContextList
1804SBTarget::FindFunctions (const char *name, uint32_t name_type_mask)
Greg Clayton4ed315f2011-06-21 01:34:41 +00001805{
Greg Clayton7dd5c512012-02-06 01:44:54 +00001806 lldb::SBSymbolContextList sb_sc_list;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001807 if (name && name[0])
Greg Clayton4ed315f2011-06-21 01:34:41 +00001808 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001809 TargetSP target_sp(GetSP());
1810 if (target_sp)
1811 {
1812 const bool symbols_ok = true;
Sean Callanan302d78c2012-02-10 22:52:19 +00001813 const bool inlines_ok = true;
Greg Clayton7dd5c512012-02-06 01:44:54 +00001814 const bool append = true;
1815 target_sp->GetImages().FindFunctions (ConstString(name),
1816 name_type_mask,
Sean Callanan302d78c2012-02-10 22:52:19 +00001817 symbols_ok,
1818 inlines_ok,
Greg Clayton7dd5c512012-02-06 01:44:54 +00001819 append,
1820 *sb_sc_list);
Greg Clayton0416bdf2012-01-30 09:04:36 +00001821 }
Greg Clayton4ed315f2011-06-21 01:34:41 +00001822 }
Greg Clayton7dd5c512012-02-06 01:44:54 +00001823 return sb_sc_list;
Greg Clayton4ed315f2011-06-21 01:34:41 +00001824}
1825
Enrico Granata979e20d2011-07-29 19:53:35 +00001826lldb::SBType
1827SBTarget::FindFirstType (const char* type)
1828{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001829 TargetSP target_sp(GetSP());
1830 if (type && target_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +00001831 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001832 size_t count = target_sp->GetImages().GetSize();
Enrico Granata979e20d2011-07-29 19:53:35 +00001833 for (size_t idx = 0; idx < count; idx++)
1834 {
1835 SBType found_at_idx = GetModuleAtIndex(idx).FindFirstType(type);
1836
1837 if (found_at_idx.IsValid())
1838 return found_at_idx;
1839 }
1840 }
1841 return SBType();
1842}
1843
1844lldb::SBTypeList
1845SBTarget::FindTypes (const char* type)
1846{
1847
1848 SBTypeList retval;
1849
Greg Clayton0416bdf2012-01-30 09:04:36 +00001850 TargetSP target_sp(GetSP());
1851 if (type && target_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +00001852 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001853 ModuleList& images = target_sp->GetImages();
Enrico Granata979e20d2011-07-29 19:53:35 +00001854 ConstString name_const(type);
1855 SymbolContext sc;
1856 TypeList type_list;
1857
1858 uint32_t num_matches = images.FindTypes(sc,
1859 name_const,
1860 true,
1861 UINT32_MAX,
1862 type_list);
1863
1864 for (size_t idx = 0; idx < num_matches; idx++)
1865 {
Greg Clayton0fb0bcc2011-08-03 22:57:10 +00001866 TypeSP type_sp (type_list.GetTypeAtIndex(idx));
1867 if (type_sp)
1868 retval.Append(SBType(type_sp));
Enrico Granata979e20d2011-07-29 19:53:35 +00001869 }
1870 }
1871 return retval;
1872}
1873
Greg Clayton917c0002011-06-29 22:09:02 +00001874SBValueList
1875SBTarget::FindGlobalVariables (const char *name, uint32_t max_matches)
1876{
1877 SBValueList sb_value_list;
1878
Greg Clayton0416bdf2012-01-30 09:04:36 +00001879 TargetSP target_sp(GetSP());
1880 if (name && target_sp)
Greg Clayton917c0002011-06-29 22:09:02 +00001881 {
1882 VariableList variable_list;
1883 const bool append = true;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001884 const uint32_t match_count = target_sp->GetImages().FindGlobalVariables (ConstString (name),
1885 append,
1886 max_matches,
1887 variable_list);
Greg Clayton917c0002011-06-29 22:09:02 +00001888
1889 if (match_count > 0)
1890 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001891 ExecutionContextScope *exe_scope = target_sp->GetProcessSP().get();
Greg Clayton917c0002011-06-29 22:09:02 +00001892 if (exe_scope == NULL)
Greg Clayton0416bdf2012-01-30 09:04:36 +00001893 exe_scope = target_sp.get();
Greg Clayton917c0002011-06-29 22:09:02 +00001894 ValueObjectList &value_object_list = sb_value_list.ref();
1895 for (uint32_t i=0; i<match_count; ++i)
1896 {
1897 lldb::ValueObjectSP valobj_sp (ValueObjectVariable::Create (exe_scope, variable_list.GetVariableAtIndex(i)));
1898 if (valobj_sp)
1899 value_object_list.Append(valobj_sp);
1900 }
1901 }
1902 }
1903
1904 return sb_value_list;
1905}
1906
Jim Inghamcc637462011-09-13 00:29:56 +00001907SBSourceManager
1908SBTarget::GetSourceManager()
1909{
1910 SBSourceManager source_manager (*this);
1911 return source_manager;
1912}
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001913
Sean Callananef1f6902011-12-14 23:49:37 +00001914lldb::SBInstructionList
1915SBTarget::GetInstructions (lldb::SBAddress base_addr, const void *buf, size_t size)
1916{
1917 SBInstructionList sb_instructions;
1918
Greg Clayton0416bdf2012-01-30 09:04:36 +00001919 TargetSP target_sp(GetSP());
1920 if (target_sp)
Sean Callananef1f6902011-12-14 23:49:37 +00001921 {
1922 Address addr;
1923
1924 if (base_addr.get())
1925 addr = *base_addr.get();
1926
Greg Clayton0416bdf2012-01-30 09:04:36 +00001927 sb_instructions.SetDisassembler (Disassembler::DisassembleBytes (target_sp->GetArchitecture(),
Sean Callananef1f6902011-12-14 23:49:37 +00001928 NULL,
1929 addr,
1930 buf,
1931 size));
1932 }
1933
1934 return sb_instructions;
1935}
1936
1937lldb::SBInstructionList
1938SBTarget::GetInstructions (lldb::addr_t base_addr, const void *buf, size_t size)
1939{
1940 return GetInstructions (ResolveLoadAddress(base_addr), buf, size);
1941}
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001942
1943SBError
1944SBTarget::SetSectionLoadAddress (lldb::SBSection section,
1945 lldb::addr_t section_base_addr)
1946{
1947 SBError sb_error;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001948 TargetSP target_sp(GetSP());
1949 if (target_sp)
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001950 {
1951 if (!section.IsValid())
1952 {
1953 sb_error.SetErrorStringWithFormat ("invalid section");
1954 }
1955 else
1956 {
Greg Clayton3508c382012-02-24 01:59:29 +00001957 target_sp->GetSectionLoadList().SetSectionLoadAddress (section.GetSP().get(), section_base_addr);
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001958 }
1959 }
1960 else
1961 {
1962 sb_error.SetErrorStringWithFormat ("invalid target");
1963 }
1964 return sb_error;
1965}
1966
1967SBError
1968SBTarget::ClearSectionLoadAddress (lldb::SBSection section)
1969{
1970 SBError sb_error;
1971
Greg Clayton0416bdf2012-01-30 09:04:36 +00001972 TargetSP target_sp(GetSP());
1973 if (target_sp)
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001974 {
1975 if (!section.IsValid())
1976 {
1977 sb_error.SetErrorStringWithFormat ("invalid section");
1978 }
1979 else
1980 {
Greg Clayton3508c382012-02-24 01:59:29 +00001981 target_sp->GetSectionLoadList().SetSectionUnloaded (section.GetSP().get());
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001982 }
1983 }
1984 else
1985 {
1986 sb_error.SetErrorStringWithFormat ("invalid target");
1987 }
1988 return sb_error;
1989}
1990
1991SBError
1992SBTarget::SetModuleLoadAddress (lldb::SBModule module, int64_t slide_offset)
1993{
1994 SBError sb_error;
1995
1996 char path[PATH_MAX];
Greg Clayton0416bdf2012-01-30 09:04:36 +00001997 TargetSP target_sp(GetSP());
1998 if (target_sp)
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001999 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00002000 ModuleSP module_sp (module.GetSP());
2001 if (module_sp)
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002002 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00002003 ObjectFile *objfile = module_sp->GetObjectFile();
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002004 if (objfile)
2005 {
2006 SectionList *section_list = objfile->GetSectionList();
2007 if (section_list)
2008 {
2009 const size_t num_sections = section_list->GetSize();
2010 for (size_t sect_idx = 0; sect_idx < num_sections; ++sect_idx)
2011 {
2012 SectionSP section_sp (section_list->GetSectionAtIndex(sect_idx));
2013 if (section_sp)
Greg Clayton0416bdf2012-01-30 09:04:36 +00002014 target_sp->GetSectionLoadList().SetSectionLoadAddress (section_sp.get(), section_sp->GetFileAddress() + slide_offset);
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002015 }
2016 }
2017 else
2018 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00002019 module_sp->GetFileSpec().GetPath (path, sizeof(path));
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002020 sb_error.SetErrorStringWithFormat ("no sections in object file '%s'", path);
2021 }
2022 }
2023 else
2024 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00002025 module_sp->GetFileSpec().GetPath (path, sizeof(path));
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002026 sb_error.SetErrorStringWithFormat ("no object file for module '%s'", path);
2027 }
2028 }
Greg Clayton0416bdf2012-01-30 09:04:36 +00002029 else
2030 {
2031 sb_error.SetErrorStringWithFormat ("invalid module");
2032 }
2033
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002034 }
2035 else
2036 {
2037 sb_error.SetErrorStringWithFormat ("invalid target");
2038 }
2039 return sb_error;
2040}
2041
2042SBError
2043SBTarget::ClearModuleLoadAddress (lldb::SBModule module)
2044{
2045 SBError sb_error;
2046
2047 char path[PATH_MAX];
Greg Clayton0416bdf2012-01-30 09:04:36 +00002048 TargetSP target_sp(GetSP());
2049 if (target_sp)
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002050 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00002051 ModuleSP module_sp (module.GetSP());
2052 if (module_sp)
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002053 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00002054 ObjectFile *objfile = module_sp->GetObjectFile();
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002055 if (objfile)
2056 {
2057 SectionList *section_list = objfile->GetSectionList();
2058 if (section_list)
2059 {
2060 const size_t num_sections = section_list->GetSize();
2061 for (size_t sect_idx = 0; sect_idx < num_sections; ++sect_idx)
2062 {
2063 SectionSP section_sp (section_list->GetSectionAtIndex(sect_idx));
2064 if (section_sp)
Greg Clayton0416bdf2012-01-30 09:04:36 +00002065 target_sp->GetSectionLoadList().SetSectionUnloaded (section_sp.get());
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002066 }
2067 }
2068 else
2069 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00002070 module_sp->GetFileSpec().GetPath (path, sizeof(path));
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002071 sb_error.SetErrorStringWithFormat ("no sections in object file '%s'", path);
2072 }
2073 }
2074 else
2075 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00002076 module_sp->GetFileSpec().GetPath (path, sizeof(path));
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002077 sb_error.SetErrorStringWithFormat ("no object file for module '%s'", path);
2078 }
2079 }
Greg Clayton0416bdf2012-01-30 09:04:36 +00002080 else
2081 {
2082 sb_error.SetErrorStringWithFormat ("invalid module");
2083 }
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002084 }
2085 else
2086 {
2087 sb_error.SetErrorStringWithFormat ("invalid target");
2088 }
2089 return sb_error;
2090}
2091
2092