blob: 115703e81f8e6118907e0328910ab9275f402362 [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
Daniel Malead891f9b2012-12-05 00:20:57 +000010#include "lldb/lldb-python.h"
11
Eli Friedman7a62c8b2010-06-09 07:44:37 +000012#include "lldb/API/SBTarget.h"
Chris Lattner24943d22010-06-08 16:52:24 +000013
Greg Claytonb3448432011-03-24 21:19:54 +000014#include "lldb/lldb-public.h"
Chris Lattner24943d22010-06-08 16:52:24 +000015
Greg Clayton917c0002011-06-29 22:09:02 +000016#include "lldb/API/SBDebugger.h"
17#include "lldb/API/SBBreakpoint.h"
Greg Clayton19b64672013-01-04 18:10:18 +000018#include "lldb/API/SBExpressionOptions.h"
Chris Lattner24943d22010-06-08 16:52:24 +000019#include "lldb/API/SBFileSpec.h"
Greg Clayton917c0002011-06-29 22:09:02 +000020#include "lldb/API/SBListener.h"
Chris Lattner24943d22010-06-08 16:52:24 +000021#include "lldb/API/SBModule.h"
Jim Inghamcc637462011-09-13 00:29:56 +000022#include "lldb/API/SBSourceManager.h"
Greg Clayton917c0002011-06-29 22:09:02 +000023#include "lldb/API/SBProcess.h"
Caroline Tice98f930f2010-09-20 05:20:02 +000024#include "lldb/API/SBStream.h"
Greg Clayton4ed315f2011-06-21 01:34:41 +000025#include "lldb/API/SBSymbolContextList.h"
Chris Lattner24943d22010-06-08 16:52:24 +000026#include "lldb/Breakpoint/BreakpointID.h"
27#include "lldb/Breakpoint/BreakpointIDList.h"
28#include "lldb/Breakpoint/BreakpointList.h"
29#include "lldb/Breakpoint/BreakpointLocation.h"
30#include "lldb/Core/Address.h"
31#include "lldb/Core/AddressResolver.h"
32#include "lldb/Core/AddressResolverName.h"
Chris Lattner24943d22010-06-08 16:52:24 +000033#include "lldb/Core/ArchSpec.h"
34#include "lldb/Core/Debugger.h"
35#include "lldb/Core/Disassembler.h"
Caroline Tice7826c882010-10-26 03:11:13 +000036#include "lldb/Core/Log.h"
Greg Clayton49ce8962012-08-29 21:13:06 +000037#include "lldb/Core/Module.h"
38#include "lldb/Core/ModuleSpec.h"
Chris Lattner24943d22010-06-08 16:52:24 +000039#include "lldb/Core/RegularExpression.h"
40#include "lldb/Core/SearchFilter.h"
Greg Clayton49ce8962012-08-29 21:13:06 +000041#include "lldb/Core/Section.h"
Chris Lattner24943d22010-06-08 16:52:24 +000042#include "lldb/Core/STLUtils.h"
Greg Clayton917c0002011-06-29 22:09:02 +000043#include "lldb/Core/ValueObjectList.h"
44#include "lldb/Core/ValueObjectVariable.h"
45#include "lldb/Host/FileSpec.h"
Greg Claytoncd548032011-02-01 01:31:41 +000046#include "lldb/Host/Host.h"
Greg Clayton917c0002011-06-29 22:09:02 +000047#include "lldb/Interpreter/Args.h"
Greg Clayton49ce8962012-08-29 21:13:06 +000048#include "lldb/Symbol/ObjectFile.h"
Enrico Granata979e20d2011-07-29 19:53:35 +000049#include "lldb/Symbol/SymbolVendor.h"
Greg Clayton917c0002011-06-29 22:09:02 +000050#include "lldb/Symbol/VariableList.h"
Jim Ingham4722b102012-03-06 00:37:27 +000051#include "lldb/Target/LanguageRuntime.h"
Chris Lattner24943d22010-06-08 16:52:24 +000052#include "lldb/Target/Process.h"
53#include "lldb/Target/Target.h"
54#include "lldb/Target/TargetList.h"
55
56#include "lldb/Interpreter/CommandReturnObject.h"
57#include "../source/Commands/CommandObjectBreakpoint.h"
58
Chris Lattner24943d22010-06-08 16:52:24 +000059
60using namespace lldb;
61using namespace lldb_private;
62
63#define DEFAULT_DISASM_BYTE_SIZE 32
64
Greg Clayton98ca1e62012-02-24 20:59:25 +000065SBLaunchInfo::SBLaunchInfo (const char **argv) :
66 m_opaque_sp(new ProcessLaunchInfo())
Greg Clayton0a8dcac2012-02-24 05:03:03 +000067{
Greg Clayton98ca1e62012-02-24 20:59:25 +000068 m_opaque_sp->GetFlags().Reset (eLaunchFlagDebug | eLaunchFlagDisableASLR);
69 if (argv && argv[0])
70 m_opaque_sp->GetArguments().SetArguments(argv);
Greg Clayton0a8dcac2012-02-24 05:03:03 +000071}
72
Greg Clayton66c2e192012-03-07 23:52:51 +000073SBLaunchInfo::~SBLaunchInfo()
74{
75}
76
77lldb_private::ProcessLaunchInfo &
78SBLaunchInfo::ref ()
79{
80 return *m_opaque_sp;
81}
82
83
Greg Clayton0a8dcac2012-02-24 05:03:03 +000084uint32_t
85SBLaunchInfo::GetUserID()
86{
87 return m_opaque_sp->GetUserID();
88}
89
90uint32_t
91SBLaunchInfo::GetGroupID()
92{
93 return m_opaque_sp->GetGroupID();
94}
95
96bool
97SBLaunchInfo::UserIDIsValid ()
98{
99 return m_opaque_sp->UserIDIsValid();
100}
101
102bool
103SBLaunchInfo::GroupIDIsValid ()
104{
105 return m_opaque_sp->GroupIDIsValid();
106}
107
108void
109SBLaunchInfo::SetUserID (uint32_t uid)
110{
111 m_opaque_sp->SetUserID (uid);
112}
113
114void
115SBLaunchInfo::SetGroupID (uint32_t gid)
116{
117 m_opaque_sp->SetGroupID (gid);
118}
119
Greg Clayton0a8dcac2012-02-24 05:03:03 +0000120uint32_t
121SBLaunchInfo::GetNumArguments ()
122{
123 return m_opaque_sp->GetArguments().GetArgumentCount();
124}
125
126const char *
127SBLaunchInfo::GetArgumentAtIndex (uint32_t idx)
128{
129 return m_opaque_sp->GetArguments().GetArgumentAtIndex(idx);
130}
131
132void
133SBLaunchInfo::SetArguments (const char **argv, bool append)
134{
135 if (append)
136 {
137 if (argv)
138 m_opaque_sp->GetArguments().AppendArguments(argv);
139 }
140 else
141 {
142 if (argv)
143 m_opaque_sp->GetArguments().SetArguments(argv);
144 else
145 m_opaque_sp->GetArguments().Clear();
146 }
147}
148
149uint32_t
150SBLaunchInfo::GetNumEnvironmentEntries ()
151{
152 return m_opaque_sp->GetEnvironmentEntries().GetArgumentCount();
153}
154
155const char *
156SBLaunchInfo::GetEnvironmentEntryAtIndex (uint32_t idx)
157{
158 return m_opaque_sp->GetEnvironmentEntries().GetArgumentAtIndex(idx);
159}
160
161void
162SBLaunchInfo::SetEnvironmentEntries (const char **envp, bool append)
163{
164 if (append)
165 {
166 if (envp)
167 m_opaque_sp->GetEnvironmentEntries().AppendArguments(envp);
168 }
169 else
170 {
171 if (envp)
172 m_opaque_sp->GetEnvironmentEntries().SetArguments(envp);
173 else
174 m_opaque_sp->GetEnvironmentEntries().Clear();
175 }
176}
177
178void
179SBLaunchInfo::Clear ()
180{
181 m_opaque_sp->Clear();
182}
183
184const char *
185SBLaunchInfo::GetWorkingDirectory () const
186{
187 return m_opaque_sp->GetWorkingDirectory();
188}
189
190void
191SBLaunchInfo::SetWorkingDirectory (const char *working_dir)
192{
193 m_opaque_sp->SetWorkingDirectory(working_dir);
194}
195
196uint32_t
197SBLaunchInfo::GetLaunchFlags ()
198{
199 return m_opaque_sp->GetFlags().Get();
200}
201
202void
203SBLaunchInfo::SetLaunchFlags (uint32_t flags)
204{
205 m_opaque_sp->GetFlags().Reset(flags);
206}
207
208const char *
209SBLaunchInfo::GetProcessPluginName ()
210{
211 return m_opaque_sp->GetProcessPluginName();
212}
213
214void
215SBLaunchInfo::SetProcessPluginName (const char *plugin_name)
216{
217 return m_opaque_sp->SetProcessPluginName (plugin_name);
218}
219
220const char *
221SBLaunchInfo::GetShell ()
222{
223 return m_opaque_sp->GetShell();
224}
225
226void
227SBLaunchInfo::SetShell (const char * path)
228{
229 m_opaque_sp->SetShell (path);
230}
231
232uint32_t
233SBLaunchInfo::GetResumeCount ()
234{
235 return m_opaque_sp->GetResumeCount();
236}
237
238void
239SBLaunchInfo::SetResumeCount (uint32_t c)
240{
241 m_opaque_sp->SetResumeCount (c);
242}
243
244bool
245SBLaunchInfo::AddCloseFileAction (int fd)
246{
247 return m_opaque_sp->AppendCloseFileAction(fd);
248}
249
250bool
251SBLaunchInfo::AddDuplicateFileAction (int fd, int dup_fd)
252{
253 return m_opaque_sp->AppendDuplicateFileAction(fd, dup_fd);
254}
255
256bool
257SBLaunchInfo::AddOpenFileAction (int fd, const char *path, bool read, bool write)
258{
259 return m_opaque_sp->AppendOpenFileAction(fd, path, read, write);
260}
261
262bool
263SBLaunchInfo::AddSuppressFileAction (int fd, bool read, bool write)
264{
265 return m_opaque_sp->AppendSuppressFileAction(fd, read, write);
266}
267
268
269SBAttachInfo::SBAttachInfo () :
Greg Clayton66c2e192012-03-07 23:52:51 +0000270 m_opaque_sp (new ProcessAttachInfo())
Greg Clayton0a8dcac2012-02-24 05:03:03 +0000271{
272}
273
274SBAttachInfo::SBAttachInfo (lldb::pid_t pid) :
Greg Clayton66c2e192012-03-07 23:52:51 +0000275 m_opaque_sp (new ProcessAttachInfo())
Greg Clayton0a8dcac2012-02-24 05:03:03 +0000276{
277 m_opaque_sp->SetProcessID (pid);
278}
279
280SBAttachInfo::SBAttachInfo (const char *path, bool wait_for) :
Greg Clayton66c2e192012-03-07 23:52:51 +0000281 m_opaque_sp (new ProcessAttachInfo())
Greg Clayton0a8dcac2012-02-24 05:03:03 +0000282{
283 if (path && path[0])
284 m_opaque_sp->GetExecutableFile().SetFile(path, false);
285 m_opaque_sp->SetWaitForLaunch (wait_for);
286}
287
288SBAttachInfo::SBAttachInfo (const SBAttachInfo &rhs) :
Greg Clayton66c2e192012-03-07 23:52:51 +0000289 m_opaque_sp (new ProcessAttachInfo())
Greg Clayton0a8dcac2012-02-24 05:03:03 +0000290{
291 *m_opaque_sp = *rhs.m_opaque_sp;
292}
293
Greg Clayton66c2e192012-03-07 23:52:51 +0000294SBAttachInfo::~SBAttachInfo()
295{
296}
297
298lldb_private::ProcessAttachInfo &
299SBAttachInfo::ref ()
300{
301 return *m_opaque_sp;
302}
303
Greg Clayton0a8dcac2012-02-24 05:03:03 +0000304SBAttachInfo &
305SBAttachInfo::operator = (const SBAttachInfo &rhs)
306{
307 if (this != &rhs)
308 *m_opaque_sp = *rhs.m_opaque_sp;
309 return *this;
310}
311
312lldb::pid_t
313SBAttachInfo::GetProcessID ()
314{
315 return m_opaque_sp->GetProcessID();
316}
317
318void
319SBAttachInfo::SetProcessID (lldb::pid_t pid)
320{
321 m_opaque_sp->SetProcessID (pid);
322}
323
324
325uint32_t
326SBAttachInfo::GetResumeCount ()
327{
328 return m_opaque_sp->GetResumeCount();
329}
330
331void
332SBAttachInfo::SetResumeCount (uint32_t c)
333{
334 m_opaque_sp->SetResumeCount (c);
335}
336
337const char *
338SBAttachInfo::GetProcessPluginName ()
339{
340 return m_opaque_sp->GetProcessPluginName();
341}
342
343void
344SBAttachInfo::SetProcessPluginName (const char *plugin_name)
345{
346 return m_opaque_sp->SetProcessPluginName (plugin_name);
347}
348
349void
350SBAttachInfo::SetExecutable (const char *path)
351{
352 if (path && path[0])
353 m_opaque_sp->GetExecutableFile().SetFile(path, false);
354 else
355 m_opaque_sp->GetExecutableFile().Clear();
356}
357
358void
359SBAttachInfo::SetExecutable (SBFileSpec exe_file)
360{
361 if (exe_file.IsValid())
362 m_opaque_sp->GetExecutableFile() = exe_file.ref();
363 else
364 m_opaque_sp->GetExecutableFile().Clear();
365}
366
367bool
368SBAttachInfo::GetWaitForLaunch ()
369{
370 return m_opaque_sp->GetWaitForLaunch();
371}
372
373void
374SBAttachInfo::SetWaitForLaunch (bool b)
375{
376 m_opaque_sp->SetWaitForLaunch (b);
377}
378
Jim Ingham3a458eb2012-07-20 21:37:13 +0000379bool
380SBAttachInfo::GetIgnoreExisting ()
381{
382 return m_opaque_sp->GetIgnoreExisting();
383}
384
385void
386SBAttachInfo::SetIgnoreExisting (bool b)
387{
388 m_opaque_sp->SetIgnoreExisting (b);
389}
390
Greg Clayton0a8dcac2012-02-24 05:03:03 +0000391uint32_t
Greg Clayton80efa5e2012-02-24 23:56:06 +0000392SBAttachInfo::GetUserID()
393{
394 return m_opaque_sp->GetUserID();
395}
396
397uint32_t
398SBAttachInfo::GetGroupID()
399{
400 return m_opaque_sp->GetGroupID();
401}
402
403bool
404SBAttachInfo::UserIDIsValid ()
405{
406 return m_opaque_sp->UserIDIsValid();
407}
408
409bool
410SBAttachInfo::GroupIDIsValid ()
411{
412 return m_opaque_sp->GroupIDIsValid();
413}
414
415void
416SBAttachInfo::SetUserID (uint32_t uid)
417{
418 m_opaque_sp->SetUserID (uid);
419}
420
421void
422SBAttachInfo::SetGroupID (uint32_t gid)
423{
424 m_opaque_sp->SetGroupID (gid);
425}
426
427uint32_t
Greg Clayton0a8dcac2012-02-24 05:03:03 +0000428SBAttachInfo::GetEffectiveUserID()
429{
430 return m_opaque_sp->GetEffectiveUserID();
431}
432
433uint32_t
434SBAttachInfo::GetEffectiveGroupID()
435{
436 return m_opaque_sp->GetEffectiveGroupID();
437}
438
439bool
440SBAttachInfo::EffectiveUserIDIsValid ()
441{
442 return m_opaque_sp->EffectiveUserIDIsValid();
443}
444
445bool
446SBAttachInfo::EffectiveGroupIDIsValid ()
447{
448 return m_opaque_sp->EffectiveGroupIDIsValid ();
449}
450
451void
452SBAttachInfo::SetEffectiveUserID (uint32_t uid)
453{
454 m_opaque_sp->SetEffectiveUserID(uid);
455}
456
457void
458SBAttachInfo::SetEffectiveGroupID (uint32_t gid)
459{
460 m_opaque_sp->SetEffectiveGroupID(gid);
461}
462
463lldb::pid_t
464SBAttachInfo::GetParentProcessID ()
465{
466 return m_opaque_sp->GetParentProcessID();
467}
468
469void
470SBAttachInfo::SetParentProcessID (lldb::pid_t pid)
471{
472 m_opaque_sp->SetParentProcessID (pid);
473}
474
475bool
476SBAttachInfo::ParentProcessIDIsValid()
477{
478 return m_opaque_sp->ParentProcessIDIsValid();
479}
480
481
Chris Lattner24943d22010-06-08 16:52:24 +0000482//----------------------------------------------------------------------
483// SBTarget constructor
484//----------------------------------------------------------------------
Greg Claytonc3b61d22010-12-15 05:08:08 +0000485SBTarget::SBTarget () :
486 m_opaque_sp ()
Chris Lattner24943d22010-06-08 16:52:24 +0000487{
488}
489
490SBTarget::SBTarget (const SBTarget& rhs) :
Greg Clayton63094e02010-06-23 01:19:29 +0000491 m_opaque_sp (rhs.m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000492{
493}
494
495SBTarget::SBTarget(const TargetSP& target_sp) :
Greg Clayton63094e02010-06-23 01:19:29 +0000496 m_opaque_sp (target_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000497{
498}
499
Greg Clayton538eb822010-11-05 23:17:00 +0000500const SBTarget&
501SBTarget::operator = (const SBTarget& rhs)
502{
503 if (this != &rhs)
504 m_opaque_sp = rhs.m_opaque_sp;
505 return *this;
506}
507
Chris Lattner24943d22010-06-08 16:52:24 +0000508//----------------------------------------------------------------------
509// Destructor
510//----------------------------------------------------------------------
511SBTarget::~SBTarget()
512{
513}
514
Jim Ingham5a15e692012-02-16 06:50:00 +0000515const char *
516SBTarget::GetBroadcasterClassName ()
517{
518 return Target::GetStaticBroadcasterClass().AsCString();
519}
520
Chris Lattner24943d22010-06-08 16:52:24 +0000521bool
522SBTarget::IsValid () const
523{
Filipe Cabecinhasf7d782b2012-05-19 09:59:08 +0000524 return m_opaque_sp.get() != NULL && m_opaque_sp->IsValid();
Chris Lattner24943d22010-06-08 16:52:24 +0000525}
526
527SBProcess
528SBTarget::GetProcess ()
529{
530 SBProcess sb_process;
Greg Clayton334d33a2012-01-30 07:41:31 +0000531 ProcessSP process_sp;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000532 TargetSP target_sp(GetSP());
533 if (target_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000534 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000535 process_sp = target_sp->GetProcessSP();
Greg Clayton334d33a2012-01-30 07:41:31 +0000536 sb_process.SetSP (process_sp);
Greg Claytonbdcda462010-12-20 20:49:23 +0000537 }
Caroline Tice7826c882010-10-26 03:11:13 +0000538
Greg Claytone005f2c2010-11-06 01:53:30 +0000539 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000540 if (log)
541 {
Greg Clayton49ce6822010-10-31 03:01:06 +0000542 log->Printf ("SBTarget(%p)::GetProcess () => SBProcess(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +0000543 target_sp.get(), process_sp.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000544 }
545
Chris Lattner24943d22010-06-08 16:52:24 +0000546 return sb_process;
547}
548
Greg Clayton63094e02010-06-23 01:19:29 +0000549SBDebugger
550SBTarget::GetDebugger () const
551{
552 SBDebugger debugger;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000553 TargetSP target_sp(GetSP());
554 if (target_sp)
555 debugger.reset (target_sp->GetDebugger().shared_from_this());
Greg Clayton63094e02010-06-23 01:19:29 +0000556 return debugger;
557}
558
Jim Inghamb5871fe2011-03-31 00:01:24 +0000559SBProcess
560SBTarget::LaunchSimple
561(
562 char const **argv,
563 char const **envp,
564 const char *working_directory
565)
566{
567 char *stdin_path = NULL;
568 char *stdout_path = NULL;
569 char *stderr_path = NULL;
570 uint32_t launch_flags = 0;
571 bool stop_at_entry = false;
572 SBError error;
573 SBListener listener = GetDebugger().GetListener();
574 return Launch (listener,
575 argv,
576 envp,
577 stdin_path,
578 stdout_path,
579 stderr_path,
580 working_directory,
581 launch_flags,
582 stop_at_entry,
583 error);
584}
Greg Claytonde915be2011-01-23 05:56:20 +0000585
586SBProcess
587SBTarget::Launch
588(
Greg Clayton271a5db2011-02-03 21:28:34 +0000589 SBListener &listener,
Greg Claytonde915be2011-01-23 05:56:20 +0000590 char const **argv,
591 char const **envp,
592 const char *stdin_path,
593 const char *stdout_path,
594 const char *stderr_path,
595 const char *working_directory,
596 uint32_t launch_flags, // See LaunchFlags
597 bool stop_at_entry,
598 lldb::SBError& error
599)
600{
Greg Claytone005f2c2010-11-06 01:53:30 +0000601 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000602
Greg Clayton0416bdf2012-01-30 09:04:36 +0000603 SBProcess sb_process;
604 ProcessSP process_sp;
605 TargetSP target_sp(GetSP());
606
Caroline Tice7826c882010-10-26 03:11:13 +0000607 if (log)
Greg Clayton3f5ee7f2010-10-29 04:59:35 +0000608 {
Greg Claytonde915be2011-01-23 05:56:20 +0000609 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 +0000610 target_sp.get(),
Greg Claytonde915be2011-01-23 05:56:20 +0000611 argv,
612 envp,
613 stdin_path ? stdin_path : "NULL",
614 stdout_path ? stdout_path : "NULL",
615 stderr_path ? stderr_path : "NULL",
616 working_directory ? working_directory : "NULL",
617 launch_flags,
618 stop_at_entry,
619 error.get());
Greg Clayton3f5ee7f2010-10-29 04:59:35 +0000620 }
Greg Clayton0416bdf2012-01-30 09:04:36 +0000621
622 if (target_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000623 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000624 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton1a3083a2010-10-06 03:53:16 +0000625
Greg Clayton7c330d62011-01-27 01:01:10 +0000626 if (getenv("LLDB_LAUNCH_FLAG_DISABLE_ASLR"))
627 launch_flags |= eLaunchFlagDisableASLR;
628
Greg Clayton180546b2011-04-30 01:09:13 +0000629 StateType state = eStateInvalid;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000630 process_sp = target_sp->GetProcessSP();
Greg Clayton334d33a2012-01-30 07:41:31 +0000631 if (process_sp)
Greg Clayton28d5fcc2011-01-27 06:44:37 +0000632 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000633 state = process_sp->GetState();
Greg Clayton180546b2011-04-30 01:09:13 +0000634
Greg Clayton334d33a2012-01-30 07:41:31 +0000635 if (process_sp->IsAlive() && state != eStateConnected)
Greg Clayton180546b2011-04-30 01:09:13 +0000636 {
637 if (state == eStateAttaching)
638 error.SetErrorString ("process attach is in progress");
639 else
640 error.SetErrorString ("a process is already being debugged");
Greg Clayton180546b2011-04-30 01:09:13 +0000641 return sb_process;
642 }
Greg Clayton28d5fcc2011-01-27 06:44:37 +0000643 }
644
Greg Clayton180546b2011-04-30 01:09:13 +0000645 if (state == eStateConnected)
646 {
647 // If we are already connected, then we have already specified the
648 // listener, so if a valid listener is supplied, we need to error out
649 // to let the client know.
650 if (listener.IsValid())
651 {
652 error.SetErrorString ("process is connected and already has a listener, pass empty listener");
Greg Clayton180546b2011-04-30 01:09:13 +0000653 return sb_process;
654 }
655 }
656 else
Greg Claytonc5f728c2010-10-06 22:10:17 +0000657 {
Greg Clayton271a5db2011-02-03 21:28:34 +0000658 if (listener.IsValid())
Greg Clayton46c9a352012-02-09 06:16:32 +0000659 process_sp = target_sp->CreateProcess (listener.ref(), NULL, NULL);
Greg Clayton271a5db2011-02-03 21:28:34 +0000660 else
Greg Clayton46c9a352012-02-09 06:16:32 +0000661 process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener(), NULL, NULL);
Greg Clayton180546b2011-04-30 01:09:13 +0000662 }
Greg Clayton7c330d62011-01-27 01:01:10 +0000663
Greg Clayton334d33a2012-01-30 07:41:31 +0000664 if (process_sp)
Greg Clayton180546b2011-04-30 01:09:13 +0000665 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000666 sb_process.SetSP (process_sp);
Greg Clayton180546b2011-04-30 01:09:13 +0000667 if (getenv("LLDB_LAUNCH_FLAG_DISABLE_STDIO"))
668 launch_flags |= eLaunchFlagDisableSTDIO;
669
Greg Clayton36bc5ea2011-11-03 21:22:33 +0000670 ProcessLaunchInfo launch_info (stdin_path, stdout_path, stderr_path, working_directory, launch_flags);
671
Greg Clayton0416bdf2012-01-30 09:04:36 +0000672 Module *exe_module = target_sp->GetExecutableModulePointer();
Greg Clayton36bc5ea2011-11-03 21:22:33 +0000673 if (exe_module)
Greg Clayton1d1f39e2011-11-29 04:03:30 +0000674 launch_info.SetExecutableFile(exe_module->GetPlatformFileSpec(), true);
Greg Clayton36bc5ea2011-11-03 21:22:33 +0000675 if (argv)
676 launch_info.GetArguments().AppendArguments (argv);
677 if (envp)
678 launch_info.GetEnvironmentEntries ().SetArguments (envp);
679
Greg Clayton334d33a2012-01-30 07:41:31 +0000680 error.SetError (process_sp->Launch (launch_info));
Greg Clayton180546b2011-04-30 01:09:13 +0000681 if (error.Success())
Greg Clayton7c330d62011-01-27 01:01:10 +0000682 {
Greg Clayton180546b2011-04-30 01:09:13 +0000683 // We we are stopping at the entry point, we can return now!
684 if (stop_at_entry)
685 return sb_process;
Greg Clayton7c330d62011-01-27 01:01:10 +0000686
Greg Clayton180546b2011-04-30 01:09:13 +0000687 // Make sure we are stopped at the entry
Greg Clayton334d33a2012-01-30 07:41:31 +0000688 StateType state = process_sp->WaitForProcessToStop (NULL);
Greg Clayton180546b2011-04-30 01:09:13 +0000689 if (state == eStateStopped)
Greg Clayton7c330d62011-01-27 01:01:10 +0000690 {
Greg Clayton180546b2011-04-30 01:09:13 +0000691 // resume the process to skip the entry point
Greg Clayton334d33a2012-01-30 07:41:31 +0000692 error.SetError (process_sp->Resume());
Greg Clayton180546b2011-04-30 01:09:13 +0000693 if (error.Success())
Greg Clayton7c330d62011-01-27 01:01:10 +0000694 {
Greg Clayton180546b2011-04-30 01:09:13 +0000695 // If we are doing synchronous mode, then wait for the
696 // process to stop yet again!
Greg Clayton0416bdf2012-01-30 09:04:36 +0000697 if (target_sp->GetDebugger().GetAsyncExecution () == false)
Greg Clayton334d33a2012-01-30 07:41:31 +0000698 process_sp->WaitForProcessToStop (NULL);
Greg Clayton7c330d62011-01-27 01:01:10 +0000699 }
700 }
701 }
Greg Clayton180546b2011-04-30 01:09:13 +0000702 }
703 else
704 {
705 error.SetErrorString ("unable to create lldb_private::Process");
Greg Claytonc5f728c2010-10-06 22:10:17 +0000706 }
707 }
708 else
709 {
710 error.SetErrorString ("SBTarget is invalid");
Chris Lattner24943d22010-06-08 16:52:24 +0000711 }
Caroline Tice7826c882010-10-26 03:11:13 +0000712
Caroline Tice926060e2010-10-29 21:48:37 +0000713 log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
Caroline Tice7826c882010-10-26 03:11:13 +0000714 if (log)
715 {
Sean Callanan4e846742012-10-20 00:21:31 +0000716 log->Printf ("SBTarget(%p)::Launch (...) => SBProcess(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +0000717 target_sp.get(), process_sp.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000718 }
719
Greg Clayton1a3083a2010-10-06 03:53:16 +0000720 return sb_process;
Chris Lattner24943d22010-06-08 16:52:24 +0000721}
722
Greg Clayton0a8dcac2012-02-24 05:03:03 +0000723SBProcess
724SBTarget::Launch (SBLaunchInfo &sb_launch_info, SBError& error)
725{
726 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
727
728 SBProcess sb_process;
729 ProcessSP process_sp;
730 TargetSP target_sp(GetSP());
731
732 if (log)
733 {
734 log->Printf ("SBTarget(%p)::Launch (launch_info, error)...", target_sp.get());
735 }
736
737 if (target_sp)
738 {
739 Mutex::Locker api_locker (target_sp->GetAPIMutex());
740 StateType state = eStateInvalid;
741 process_sp = target_sp->GetProcessSP();
742 if (process_sp)
743 {
744 state = process_sp->GetState();
745
746 if (process_sp->IsAlive() && state != eStateConnected)
747 {
748 if (state == eStateAttaching)
749 error.SetErrorString ("process attach is in progress");
750 else
751 error.SetErrorString ("a process is already being debugged");
752 return sb_process;
753 }
754 }
755
756 if (state != eStateConnected)
757 process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener(), NULL, NULL);
758
759 if (process_sp)
760 {
761 sb_process.SetSP (process_sp);
762 lldb_private::ProcessLaunchInfo &launch_info = sb_launch_info.ref();
Greg Clayton98ca1e62012-02-24 20:59:25 +0000763
Greg Clayton98ca1e62012-02-24 20:59:25 +0000764 Module *exe_module = target_sp->GetExecutableModulePointer();
765 if (exe_module)
Han Ming Ongc86723f2012-03-02 01:02:04 +0000766 launch_info.SetExecutableFile(exe_module->GetPlatformFileSpec(), true);
Greg Clayton98ca1e62012-02-24 20:59:25 +0000767
768 const ArchSpec &arch_spec = target_sp->GetArchitecture();
769 if (arch_spec.IsValid())
770 launch_info.GetArchitecture () = arch_spec;
771
Greg Clayton0a8dcac2012-02-24 05:03:03 +0000772 error.SetError (process_sp->Launch (launch_info));
Greg Clayton98ca1e62012-02-24 20:59:25 +0000773 const bool synchronous_execution = target_sp->GetDebugger().GetAsyncExecution () == false;
Greg Clayton0a8dcac2012-02-24 05:03:03 +0000774 if (error.Success())
775 {
Greg Clayton0a8dcac2012-02-24 05:03:03 +0000776 if (launch_info.GetFlags().Test(eLaunchFlagStopAtEntry))
Greg Clayton98ca1e62012-02-24 20:59:25 +0000777 {
778 // If we are doing synchronous mode, then wait for the initial
779 // stop to happen, else, return and let the caller watch for
780 // the stop
781 if (synchronous_execution)
Greg Clayton4a379b12012-07-17 03:23:13 +0000782 process_sp->WaitForProcessToStop (NULL);
Greg Clayton98ca1e62012-02-24 20:59:25 +0000783 // We we are stopping at the entry point, we can return now!
Greg Clayton0a8dcac2012-02-24 05:03:03 +0000784 return sb_process;
Greg Clayton98ca1e62012-02-24 20:59:25 +0000785 }
Greg Clayton0a8dcac2012-02-24 05:03:03 +0000786
787 // Make sure we are stopped at the entry
Greg Clayton4a379b12012-07-17 03:23:13 +0000788 StateType state = process_sp->WaitForProcessToStop (NULL);
Greg Clayton0a8dcac2012-02-24 05:03:03 +0000789 if (state == eStateStopped)
790 {
791 // resume the process to skip the entry point
792 error.SetError (process_sp->Resume());
793 if (error.Success())
794 {
795 // If we are doing synchronous mode, then wait for the
796 // process to stop yet again!
Greg Clayton98ca1e62012-02-24 20:59:25 +0000797 if (synchronous_execution)
Greg Clayton0a8dcac2012-02-24 05:03:03 +0000798 process_sp->WaitForProcessToStop (NULL);
799 }
800 }
801 }
802 }
803 else
804 {
805 error.SetErrorString ("unable to create lldb_private::Process");
806 }
807 }
808 else
809 {
810 error.SetErrorString ("SBTarget is invalid");
811 }
812
813 log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
814 if (log)
815 {
Sean Callanan4e846742012-10-20 00:21:31 +0000816 log->Printf ("SBTarget(%p)::Launch (...) => SBProcess(%p)",
Greg Clayton0a8dcac2012-02-24 05:03:03 +0000817 target_sp.get(), process_sp.get());
818 }
819
820 return sb_process;
821}
822
823lldb::SBProcess
824SBTarget::Attach (SBAttachInfo &sb_attach_info, SBError& error)
825{
Sean Callanan4e846742012-10-20 00:21:31 +0000826 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
827
Greg Clayton0a8dcac2012-02-24 05:03:03 +0000828 SBProcess sb_process;
829 ProcessSP process_sp;
830 TargetSP target_sp(GetSP());
Sean Callanan4e846742012-10-20 00:21:31 +0000831
832 if (log)
833 {
834 log->Printf ("SBTarget(%p)::Attach (sb_attach_info, error)...", target_sp.get());
835 }
836
Greg Clayton0a8dcac2012-02-24 05:03:03 +0000837 if (target_sp)
838 {
839 Mutex::Locker api_locker (target_sp->GetAPIMutex());
840
841 StateType state = eStateInvalid;
842 process_sp = target_sp->GetProcessSP();
843 if (process_sp)
844 {
845 state = process_sp->GetState();
846
847 if (process_sp->IsAlive() && state != eStateConnected)
848 {
849 if (state == eStateAttaching)
850 error.SetErrorString ("process attach is in progress");
851 else
852 error.SetErrorString ("a process is already being debugged");
Sean Callanan4e846742012-10-20 00:21:31 +0000853 if (log)
854 {
855 log->Printf ("SBTarget(%p)::Attach (...) => error %s",
856 target_sp.get(), error.GetCString());
857 }
Greg Clayton0a8dcac2012-02-24 05:03:03 +0000858 return sb_process;
859 }
860 }
861
862 if (state != eStateConnected)
863 process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener(), NULL, NULL);
864
865 if (process_sp)
866 {
Greg Clayton0a8dcac2012-02-24 05:03:03 +0000867 ProcessAttachInfo &attach_info = sb_attach_info.ref();
Han Ming Ong435c5ef2012-02-29 00:12:56 +0000868 lldb::pid_t attach_pid = attach_info.GetProcessID();
869 if (attach_pid != LLDB_INVALID_PROCESS_ID)
870 {
871 PlatformSP platform_sp = target_sp->GetPlatform();
Greg Clayton02fac1c2012-09-27 00:03:39 +0000872 // See if we can pre-verify if a process exists or not
873 if (platform_sp && platform_sp->IsConnected())
Han Ming Ong435c5ef2012-02-29 00:12:56 +0000874 {
Greg Clayton02fac1c2012-09-27 00:03:39 +0000875 ProcessInstanceInfo instance_info;
876 if (platform_sp->GetProcessInfo(attach_pid, instance_info))
877 {
878 attach_info.SetUserID(instance_info.GetEffectiveUserID());
879 }
880 else
881 {
Daniel Malea5f35a4b2012-11-29 21:49:15 +0000882 error.ref().SetErrorStringWithFormat("no process found with process ID %" PRIu64, attach_pid);
Sean Callanan4e846742012-10-20 00:21:31 +0000883 if (log)
884 {
885 log->Printf ("SBTarget(%p)::Attach (...) => error %s",
886 target_sp.get(), error.GetCString());
887 }
Greg Clayton02fac1c2012-09-27 00:03:39 +0000888 return sb_process;
889 }
Han Ming Ong435c5ef2012-02-29 00:12:56 +0000890 }
891 }
Han Ming Ong94b4e9a2012-02-29 19:16:40 +0000892 error.SetError (process_sp->Attach (attach_info));
893 if (error.Success())
894 {
895 sb_process.SetSP (process_sp);
896 // If we are doing synchronous mode, then wait for the
897 // process to stop!
898 if (target_sp->GetDebugger().GetAsyncExecution () == false)
899 process_sp->WaitForProcessToStop (NULL);
900 }
Greg Clayton0a8dcac2012-02-24 05:03:03 +0000901 }
902 else
903 {
904 error.SetErrorString ("unable to create lldb_private::Process");
905 }
906 }
907 else
908 {
909 error.SetErrorString ("SBTarget is invalid");
910 }
Sean Callanan4e846742012-10-20 00:21:31 +0000911
912 if (log)
913 {
914 log->Printf ("SBTarget(%p)::Attach (...) => SBProcess(%p)",
915 target_sp.get(), process_sp.get());
916 }
917
Greg Clayton0a8dcac2012-02-24 05:03:03 +0000918 return sb_process;
919}
920
921
Greg Claytond5b0b442011-12-02 02:10:57 +0000922#if defined(__APPLE__)
923
924lldb::SBProcess
925SBTarget::AttachToProcessWithID (SBListener &listener,
926 ::pid_t pid,
927 lldb::SBError& error)
928{
929 return AttachToProcessWithID (listener, (lldb::pid_t)pid, error);
930}
931
932#endif // #if defined(__APPLE__)
Greg Claytonc5f728c2010-10-06 22:10:17 +0000933
934lldb::SBProcess
Greg Claytond8c62532010-10-07 04:19:01 +0000935SBTarget::AttachToProcessWithID
Greg Claytonc5f728c2010-10-06 22:10:17 +0000936(
Greg Clayton271a5db2011-02-03 21:28:34 +0000937 SBListener &listener,
Greg Claytonc5f728c2010-10-06 22:10:17 +0000938 lldb::pid_t pid,// The process ID to attach to
939 SBError& error // An error explaining what went wrong if attach fails
940)
941{
Sean Callanan4e846742012-10-20 00:21:31 +0000942 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
943
Greg Claytonc5f728c2010-10-06 22:10:17 +0000944 SBProcess sb_process;
Greg Clayton334d33a2012-01-30 07:41:31 +0000945 ProcessSP process_sp;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000946 TargetSP target_sp(GetSP());
Sean Callanan4e846742012-10-20 00:21:31 +0000947
948 if (log)
949 {
Daniel Malea5f35a4b2012-11-29 21:49:15 +0000950 log->Printf ("SBTarget(%p)::AttachToProcessWithID (listener, pid=%" PRId64 ", error)...", target_sp.get(), pid);
Sean Callanan4e846742012-10-20 00:21:31 +0000951 }
952
Greg Clayton0416bdf2012-01-30 09:04:36 +0000953 if (target_sp)
Greg Claytonc5f728c2010-10-06 22:10:17 +0000954 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000955 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytonde1dd812011-06-24 03:21:43 +0000956
957 StateType state = eStateInvalid;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000958 process_sp = target_sp->GetProcessSP();
Greg Clayton334d33a2012-01-30 07:41:31 +0000959 if (process_sp)
Greg Claytonde1dd812011-06-24 03:21:43 +0000960 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000961 state = process_sp->GetState();
Greg Claytonde1dd812011-06-24 03:21:43 +0000962
Greg Clayton334d33a2012-01-30 07:41:31 +0000963 if (process_sp->IsAlive() && state != eStateConnected)
Greg Claytonde1dd812011-06-24 03:21:43 +0000964 {
965 if (state == eStateAttaching)
966 error.SetErrorString ("process attach is in progress");
967 else
968 error.SetErrorString ("a process is already being debugged");
Greg Claytonde1dd812011-06-24 03:21:43 +0000969 return sb_process;
970 }
971 }
972
973 if (state == eStateConnected)
974 {
975 // If we are already connected, then we have already specified the
976 // listener, so if a valid listener is supplied, we need to error out
977 // to let the client know.
978 if (listener.IsValid())
979 {
980 error.SetErrorString ("process is connected and already has a listener, pass empty listener");
Greg Claytonde1dd812011-06-24 03:21:43 +0000981 return sb_process;
982 }
983 }
Greg Clayton271a5db2011-02-03 21:28:34 +0000984 else
Greg Claytonde1dd812011-06-24 03:21:43 +0000985 {
986 if (listener.IsValid())
Greg Clayton46c9a352012-02-09 06:16:32 +0000987 process_sp = target_sp->CreateProcess (listener.ref(), NULL, NULL);
Greg Claytonde1dd812011-06-24 03:21:43 +0000988 else
Greg Clayton46c9a352012-02-09 06:16:32 +0000989 process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener(), NULL, NULL);
Greg Claytonde1dd812011-06-24 03:21:43 +0000990 }
Greg Clayton334d33a2012-01-30 07:41:31 +0000991 if (process_sp)
Greg Claytonc5f728c2010-10-06 22:10:17 +0000992 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000993 sb_process.SetSP (process_sp);
994
Greg Clayton527154d2011-11-15 03:53:30 +0000995 ProcessAttachInfo attach_info;
996 attach_info.SetProcessID (pid);
Han Ming Ongd1040dd2012-02-25 01:07:38 +0000997
998 PlatformSP platform_sp = target_sp->GetPlatform();
999 ProcessInstanceInfo instance_info;
1000 if (platform_sp->GetProcessInfo(pid, instance_info))
1001 {
1002 attach_info.SetUserID(instance_info.GetEffectiveUserID());
Han Ming Ongd1040dd2012-02-25 01:07:38 +00001003 }
Greg Clayton334d33a2012-01-30 07:41:31 +00001004 error.SetError (process_sp->Attach (attach_info));
Greg Claytonc6430772012-09-07 17:51:47 +00001005 if (error.Success())
1006 {
1007 // If we are doing synchronous mode, then wait for the
1008 // process to stop!
1009 if (target_sp->GetDebugger().GetAsyncExecution () == false)
Greg Clayton334d33a2012-01-30 07:41:31 +00001010 process_sp->WaitForProcessToStop (NULL);
Greg Claytonc6430772012-09-07 17:51:47 +00001011 }
Greg Claytonc5f728c2010-10-06 22:10:17 +00001012 }
1013 else
1014 {
1015 error.SetErrorString ("unable to create lldb_private::Process");
1016 }
1017 }
1018 else
1019 {
1020 error.SetErrorString ("SBTarget is invalid");
1021 }
Sean Callanan4e846742012-10-20 00:21:31 +00001022
1023 if (log)
1024 {
1025 log->Printf ("SBTarget(%p)::AttachToProcessWithID (...) => SBProcess(%p)",
1026 target_sp.get(), process_sp.get());
1027 }
Greg Claytonc5f728c2010-10-06 22:10:17 +00001028 return sb_process;
Greg Claytonc5f728c2010-10-06 22:10:17 +00001029}
1030
1031lldb::SBProcess
Greg Claytond8c62532010-10-07 04:19:01 +00001032SBTarget::AttachToProcessWithName
Greg Claytonc5f728c2010-10-06 22:10:17 +00001033(
Greg Clayton271a5db2011-02-03 21:28:34 +00001034 SBListener &listener,
Greg Claytonc5f728c2010-10-06 22:10:17 +00001035 const char *name, // basename of process to attach to
1036 bool wait_for, // if true wait for a new instance of "name" to be launched
1037 SBError& error // An error explaining what went wrong if attach fails
1038)
1039{
Sean Callanan4e846742012-10-20 00:21:31 +00001040 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1041
Greg Claytonc5f728c2010-10-06 22:10:17 +00001042 SBProcess sb_process;
Greg Clayton334d33a2012-01-30 07:41:31 +00001043 ProcessSP process_sp;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001044 TargetSP target_sp(GetSP());
Sean Callanan4e846742012-10-20 00:21:31 +00001045
1046 if (log)
1047 {
1048 log->Printf ("SBTarget(%p)::AttachToProcessWithName (listener, name=%s, wait_for=%s, error)...", target_sp.get(), name, wait_for ? "true" : "false");
1049 }
1050
Greg Clayton0416bdf2012-01-30 09:04:36 +00001051 if (name && target_sp)
Greg Claytonc5f728c2010-10-06 22:10:17 +00001052 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001053 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytonbdcda462010-12-20 20:49:23 +00001054
Greg Claytonde1dd812011-06-24 03:21:43 +00001055 StateType state = eStateInvalid;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001056 process_sp = target_sp->GetProcessSP();
Greg Clayton334d33a2012-01-30 07:41:31 +00001057 if (process_sp)
Greg Claytonde1dd812011-06-24 03:21:43 +00001058 {
Greg Clayton334d33a2012-01-30 07:41:31 +00001059 state = process_sp->GetState();
Greg Claytonde1dd812011-06-24 03:21:43 +00001060
Greg Clayton334d33a2012-01-30 07:41:31 +00001061 if (process_sp->IsAlive() && state != eStateConnected)
Greg Claytonde1dd812011-06-24 03:21:43 +00001062 {
1063 if (state == eStateAttaching)
1064 error.SetErrorString ("process attach is in progress");
1065 else
1066 error.SetErrorString ("a process is already being debugged");
Greg Claytonde1dd812011-06-24 03:21:43 +00001067 return sb_process;
1068 }
1069 }
1070
1071 if (state == eStateConnected)
1072 {
1073 // If we are already connected, then we have already specified the
1074 // listener, so if a valid listener is supplied, we need to error out
1075 // to let the client know.
1076 if (listener.IsValid())
1077 {
1078 error.SetErrorString ("process is connected and already has a listener, pass empty listener");
Greg Claytonde1dd812011-06-24 03:21:43 +00001079 return sb_process;
1080 }
1081 }
Greg Clayton271a5db2011-02-03 21:28:34 +00001082 else
Greg Claytonde1dd812011-06-24 03:21:43 +00001083 {
1084 if (listener.IsValid())
Greg Clayton46c9a352012-02-09 06:16:32 +00001085 process_sp = target_sp->CreateProcess (listener.ref(), NULL, NULL);
Greg Claytonde1dd812011-06-24 03:21:43 +00001086 else
Greg Clayton46c9a352012-02-09 06:16:32 +00001087 process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener(), NULL, NULL);
Greg Claytonde1dd812011-06-24 03:21:43 +00001088 }
Greg Claytonc5f728c2010-10-06 22:10:17 +00001089
Greg Clayton334d33a2012-01-30 07:41:31 +00001090 if (process_sp)
Greg Claytonc5f728c2010-10-06 22:10:17 +00001091 {
Greg Clayton334d33a2012-01-30 07:41:31 +00001092 sb_process.SetSP (process_sp);
Greg Clayton527154d2011-11-15 03:53:30 +00001093 ProcessAttachInfo attach_info;
1094 attach_info.GetExecutableFile().SetFile(name, false);
1095 attach_info.SetWaitForLaunch(wait_for);
Greg Clayton334d33a2012-01-30 07:41:31 +00001096 error.SetError (process_sp->Attach (attach_info));
Johnny Chen58d02ff2011-06-17 19:21:30 +00001097 // If we are doing synchronous mode, then wait for the
1098 // process to stop!
Greg Clayton0416bdf2012-01-30 09:04:36 +00001099 if (target_sp->GetDebugger().GetAsyncExecution () == false)
Greg Clayton334d33a2012-01-30 07:41:31 +00001100 process_sp->WaitForProcessToStop (NULL);
Greg Claytonc5f728c2010-10-06 22:10:17 +00001101 }
1102 else
1103 {
1104 error.SetErrorString ("unable to create lldb_private::Process");
1105 }
1106 }
1107 else
1108 {
1109 error.SetErrorString ("SBTarget is invalid");
1110 }
Sean Callanan4e846742012-10-20 00:21:31 +00001111
1112 if (log)
1113 {
1114 log->Printf ("SBTarget(%p)::AttachToPorcessWithName (...) => SBProcess(%p)",
1115 target_sp.get(), process_sp.get());
1116 }
Greg Claytonc5f728c2010-10-06 22:10:17 +00001117 return sb_process;
Greg Claytonc5f728c2010-10-06 22:10:17 +00001118}
1119
James McIlree38093402011-03-04 00:31:13 +00001120lldb::SBProcess
1121SBTarget::ConnectRemote
1122(
1123 SBListener &listener,
1124 const char *url,
1125 const char *plugin_name,
1126 SBError& error
1127)
1128{
Sean Callanan4e846742012-10-20 00:21:31 +00001129 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1130
James McIlree38093402011-03-04 00:31:13 +00001131 SBProcess sb_process;
Greg Clayton334d33a2012-01-30 07:41:31 +00001132 ProcessSP process_sp;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001133 TargetSP target_sp(GetSP());
Sean Callanan4e846742012-10-20 00:21:31 +00001134
1135 if (log)
1136 {
1137 log->Printf ("SBTarget(%p)::ConnectRemote (listener, url=%s, plugin_name=%s, error)...", target_sp.get(), url, plugin_name);
1138 }
1139
Greg Clayton0416bdf2012-01-30 09:04:36 +00001140 if (target_sp)
James McIlree38093402011-03-04 00:31:13 +00001141 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001142 Mutex::Locker api_locker (target_sp->GetAPIMutex());
James McIlree38093402011-03-04 00:31:13 +00001143 if (listener.IsValid())
Greg Clayton46c9a352012-02-09 06:16:32 +00001144 process_sp = target_sp->CreateProcess (listener.ref(), plugin_name, NULL);
James McIlree38093402011-03-04 00:31:13 +00001145 else
Greg Clayton46c9a352012-02-09 06:16:32 +00001146 process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener(), plugin_name, NULL);
James McIlree38093402011-03-04 00:31:13 +00001147
1148
Greg Clayton334d33a2012-01-30 07:41:31 +00001149 if (process_sp)
James McIlree38093402011-03-04 00:31:13 +00001150 {
Greg Clayton334d33a2012-01-30 07:41:31 +00001151 sb_process.SetSP (process_sp);
Jason Molendafac2e622012-09-29 04:02:01 +00001152 error.SetError (process_sp->ConnectRemote (NULL, url));
James McIlree38093402011-03-04 00:31:13 +00001153 }
1154 else
1155 {
1156 error.SetErrorString ("unable to create lldb_private::Process");
1157 }
1158 }
1159 else
1160 {
1161 error.SetErrorString ("SBTarget is invalid");
1162 }
Sean Callanan4e846742012-10-20 00:21:31 +00001163
1164 if (log)
1165 {
1166 log->Printf ("SBTarget(%p)::ConnectRemote (...) => SBProcess(%p)",
1167 target_sp.get(), process_sp.get());
1168 }
James McIlree38093402011-03-04 00:31:13 +00001169 return sb_process;
1170}
1171
Chris Lattner24943d22010-06-08 16:52:24 +00001172SBFileSpec
1173SBTarget::GetExecutable ()
1174{
Caroline Tice7826c882010-10-26 03:11:13 +00001175
Chris Lattner24943d22010-06-08 16:52:24 +00001176 SBFileSpec exe_file_spec;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001177 TargetSP target_sp(GetSP());
1178 if (target_sp)
Chris Lattner24943d22010-06-08 16:52:24 +00001179 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001180 Module *exe_module = target_sp->GetExecutableModulePointer();
Greg Clayton5beb99d2011-08-11 02:48:45 +00001181 if (exe_module)
1182 exe_file_spec.SetFileSpec (exe_module->GetFileSpec());
Chris Lattner24943d22010-06-08 16:52:24 +00001183 }
Caroline Tice7826c882010-10-26 03:11:13 +00001184
Greg Claytone005f2c2010-11-06 01:53:30 +00001185 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001186 if (log)
1187 {
Greg Clayton49ce6822010-10-31 03:01:06 +00001188 log->Printf ("SBTarget(%p)::GetExecutable () => SBFileSpec(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +00001189 target_sp.get(), exe_file_spec.get());
Caroline Tice7826c882010-10-26 03:11:13 +00001190 }
1191
Chris Lattner24943d22010-06-08 16:52:24 +00001192 return exe_file_spec;
1193}
1194
Chris Lattner24943d22010-06-08 16:52:24 +00001195bool
Chris Lattner24943d22010-06-08 16:52:24 +00001196SBTarget::operator == (const SBTarget &rhs) const
1197{
Greg Clayton63094e02010-06-23 01:19:29 +00001198 return m_opaque_sp.get() == rhs.m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +00001199}
1200
1201bool
1202SBTarget::operator != (const SBTarget &rhs) const
1203{
Greg Clayton63094e02010-06-23 01:19:29 +00001204 return m_opaque_sp.get() != rhs.m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +00001205}
1206
Greg Clayton334d33a2012-01-30 07:41:31 +00001207lldb::TargetSP
1208SBTarget::GetSP () const
Greg Clayton15afa9f2011-10-01 02:59:24 +00001209{
1210 return m_opaque_sp;
1211}
1212
Greg Clayton63094e02010-06-23 01:19:29 +00001213void
Greg Clayton334d33a2012-01-30 07:41:31 +00001214SBTarget::SetSP (const lldb::TargetSP& target_sp)
Greg Clayton63094e02010-06-23 01:19:29 +00001215{
1216 m_opaque_sp = target_sp;
Chris Lattner24943d22010-06-08 16:52:24 +00001217}
1218
Greg Claytona3955062011-07-22 16:46:35 +00001219lldb::SBAddress
1220SBTarget::ResolveLoadAddress (lldb::addr_t vm_addr)
Greg Claytonea49cc72010-12-12 19:25:26 +00001221{
Greg Claytona3955062011-07-22 16:46:35 +00001222 lldb::SBAddress sb_addr;
1223 Address &addr = sb_addr.ref();
Greg Clayton0416bdf2012-01-30 09:04:36 +00001224 TargetSP target_sp(GetSP());
1225 if (target_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +00001226 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001227 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1228 if (target_sp->GetSectionLoadList().ResolveLoadAddress (vm_addr, addr))
Greg Claytona3955062011-07-22 16:46:35 +00001229 return sb_addr;
Greg Claytonbdcda462010-12-20 20:49:23 +00001230 }
Greg Claytonea49cc72010-12-12 19:25:26 +00001231
Greg Claytona3955062011-07-22 16:46:35 +00001232 // We have a load address that isn't in a section, just return an address
1233 // with the offset filled in (the address) and the section set to NULL
Greg Clayton3508c382012-02-24 01:59:29 +00001234 addr.SetRawAddress(vm_addr);
Greg Claytona3955062011-07-22 16:46:35 +00001235 return sb_addr;
Greg Claytonea49cc72010-12-12 19:25:26 +00001236}
1237
Greg Claytonafb81862011-03-02 21:34:46 +00001238SBSymbolContext
1239SBTarget::ResolveSymbolContextForAddress (const SBAddress& addr, uint32_t resolve_scope)
1240{
1241 SBSymbolContext sc;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001242 if (addr.IsValid())
1243 {
1244 TargetSP target_sp(GetSP());
1245 if (target_sp)
1246 target_sp->GetImages().ResolveSymbolContextForAddress (addr.ref(), resolve_scope, sc.ref());
1247 }
Greg Claytonafb81862011-03-02 21:34:46 +00001248 return sc;
1249}
1250
1251
Chris Lattner24943d22010-06-08 16:52:24 +00001252SBBreakpoint
1253SBTarget::BreakpointCreateByLocation (const char *file, uint32_t line)
1254{
Greg Claytond6d806c2010-11-08 00:28:40 +00001255 return SBBreakpoint(BreakpointCreateByLocation (SBFileSpec (file, false), line));
Chris Lattner24943d22010-06-08 16:52:24 +00001256}
1257
1258SBBreakpoint
1259SBTarget::BreakpointCreateByLocation (const SBFileSpec &sb_file_spec, uint32_t line)
1260{
Greg Claytone005f2c2010-11-06 01:53:30 +00001261 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001262
Chris Lattner24943d22010-06-08 16:52:24 +00001263 SBBreakpoint sb_bp;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001264 TargetSP target_sp(GetSP());
1265 if (target_sp && line != 0)
Greg Claytonbdcda462010-12-20 20:49:23 +00001266 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001267 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Jim Ingham2cf5ccb2012-05-22 00:12:20 +00001268
Greg Clayton49ce8962012-08-29 21:13:06 +00001269 const LazyBool check_inlines = eLazyBoolCalculate;
Jim Ingham2cf5ccb2012-05-22 00:12:20 +00001270 const LazyBool skip_prologue = eLazyBoolCalculate;
Greg Clayton49ce8962012-08-29 21:13:06 +00001271 const bool internal = false;
Jim Ingham2cf5ccb2012-05-22 00:12:20 +00001272 *sb_bp = target_sp->CreateBreakpoint (NULL, *sb_file_spec, line, check_inlines, skip_prologue, internal);
Greg Claytonbdcda462010-12-20 20:49:23 +00001273 }
Caroline Tice7826c882010-10-26 03:11:13 +00001274
1275 if (log)
1276 {
1277 SBStream sstr;
1278 sb_bp.GetDescription (sstr);
Greg Clayton49ce6822010-10-31 03:01:06 +00001279 char path[PATH_MAX];
1280 sb_file_spec->GetPath (path, sizeof(path));
1281 log->Printf ("SBTarget(%p)::BreakpointCreateByLocation ( %s:%u ) => SBBreakpoint(%p): %s",
Greg Clayton0416bdf2012-01-30 09:04:36 +00001282 target_sp.get(),
Greg Clayton49ce6822010-10-31 03:01:06 +00001283 path,
Greg Claytona66ba462010-10-30 04:51:46 +00001284 line,
Greg Clayton49ce6822010-10-31 03:01:06 +00001285 sb_bp.get(),
Caroline Tice7826c882010-10-26 03:11:13 +00001286 sstr.GetData());
1287 }
1288
Chris Lattner24943d22010-06-08 16:52:24 +00001289 return sb_bp;
1290}
1291
1292SBBreakpoint
1293SBTarget::BreakpointCreateByName (const char *symbol_name, const char *module_name)
1294{
Greg Claytone005f2c2010-11-06 01:53:30 +00001295 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001296
Chris Lattner24943d22010-06-08 16:52:24 +00001297 SBBreakpoint sb_bp;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001298 TargetSP target_sp(GetSP());
1299 if (target_sp.get())
Chris Lattner24943d22010-06-08 16:52:24 +00001300 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001301 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Jim Ingham2cf5ccb2012-05-22 00:12:20 +00001302
1303 const bool internal = false;
1304 const LazyBool skip_prologue = eLazyBoolCalculate;
Chris Lattner24943d22010-06-08 16:52:24 +00001305 if (module_name && module_name[0])
1306 {
Jim Ingham03c8ee52011-09-21 01:17:13 +00001307 FileSpecList module_spec_list;
1308 module_spec_list.Append (FileSpec (module_name, false));
Jim Ingham2cf5ccb2012-05-22 00:12:20 +00001309 *sb_bp = target_sp->CreateBreakpoint (&module_spec_list, NULL, symbol_name, eFunctionNameTypeAuto, skip_prologue, internal);
Chris Lattner24943d22010-06-08 16:52:24 +00001310 }
1311 else
1312 {
Jim Ingham2cf5ccb2012-05-22 00:12:20 +00001313 *sb_bp = target_sp->CreateBreakpoint (NULL, NULL, symbol_name, eFunctionNameTypeAuto, skip_prologue, internal);
Chris Lattner24943d22010-06-08 16:52:24 +00001314 }
1315 }
Caroline Tice7826c882010-10-26 03:11:13 +00001316
1317 if (log)
1318 {
Greg Clayton49ce6822010-10-31 03:01:06 +00001319 log->Printf ("SBTarget(%p)::BreakpointCreateByName (symbol=\"%s\", module=\"%s\") => SBBreakpoint(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +00001320 target_sp.get(), symbol_name, module_name, sb_bp.get());
Caroline Tice7826c882010-10-26 03:11:13 +00001321 }
1322
Chris Lattner24943d22010-06-08 16:52:24 +00001323 return sb_bp;
1324}
1325
Jim Inghamd6d47972011-09-23 00:54:11 +00001326lldb::SBBreakpoint
1327SBTarget::BreakpointCreateByName (const char *symbol_name,
1328 const SBFileSpecList &module_list,
1329 const SBFileSpecList &comp_unit_list)
1330{
Jim Ingham1fb8a2d2011-10-11 01:18:55 +00001331 uint32_t name_type_mask = eFunctionNameTypeAuto;
1332 return BreakpointCreateByName (symbol_name, name_type_mask, module_list, comp_unit_list);
1333}
1334
1335lldb::SBBreakpoint
1336SBTarget::BreakpointCreateByName (const char *symbol_name,
1337 uint32_t name_type_mask,
1338 const SBFileSpecList &module_list,
1339 const SBFileSpecList &comp_unit_list)
1340{
Jim Inghamd6d47972011-09-23 00:54:11 +00001341 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1342
1343 SBBreakpoint sb_bp;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001344 TargetSP target_sp(GetSP());
1345 if (target_sp && symbol_name && symbol_name[0])
Jim Inghamd6d47972011-09-23 00:54:11 +00001346 {
Jim Ingham2cf5ccb2012-05-22 00:12:20 +00001347 const bool internal = false;
1348 const LazyBool skip_prologue = eLazyBoolCalculate;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001349 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1350 *sb_bp = target_sp->CreateBreakpoint (module_list.get(),
Jim Inghamd6d47972011-09-23 00:54:11 +00001351 comp_unit_list.get(),
1352 symbol_name,
Jim Ingham1fb8a2d2011-10-11 01:18:55 +00001353 name_type_mask,
Jim Ingham2cf5ccb2012-05-22 00:12:20 +00001354 skip_prologue,
1355 internal);
Jim Inghamd6d47972011-09-23 00:54:11 +00001356 }
1357
1358 if (log)
1359 {
Jim Ingham1fb8a2d2011-10-11 01:18:55 +00001360 log->Printf ("SBTarget(%p)::BreakpointCreateByName (symbol=\"%s\", name_type: %d) => SBBreakpoint(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +00001361 target_sp.get(), symbol_name, name_type_mask, sb_bp.get());
Jim Inghamd6d47972011-09-23 00:54:11 +00001362 }
1363
1364 return sb_bp;
1365}
1366
Jim Ingham4722b102012-03-06 00:37:27 +00001367lldb::SBBreakpoint
1368SBTarget::BreakpointCreateByNames (const char *symbol_names[],
1369 uint32_t num_names,
1370 uint32_t name_type_mask,
1371 const SBFileSpecList &module_list,
1372 const SBFileSpecList &comp_unit_list)
1373{
1374 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1375
1376 SBBreakpoint sb_bp;
1377 TargetSP target_sp(GetSP());
1378 if (target_sp && num_names > 0)
1379 {
1380 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Jim Ingham2cf5ccb2012-05-22 00:12:20 +00001381 const bool internal = false;
1382 const LazyBool skip_prologue = eLazyBoolCalculate;
Jim Ingham4722b102012-03-06 00:37:27 +00001383 *sb_bp = target_sp->CreateBreakpoint (module_list.get(),
1384 comp_unit_list.get(),
1385 symbol_names,
1386 num_names,
1387 name_type_mask,
Jim Ingham2cf5ccb2012-05-22 00:12:20 +00001388 skip_prologue,
1389 internal);
Jim Ingham4722b102012-03-06 00:37:27 +00001390 }
1391
1392 if (log)
1393 {
1394 log->Printf ("SBTarget(%p)::BreakpointCreateByName (symbols={", target_sp.get());
1395 for (uint32_t i = 0 ; i < num_names; i++)
1396 {
1397 char sep;
1398 if (i < num_names - 1)
1399 sep = ',';
1400 else
1401 sep = '}';
1402 if (symbol_names[i] != NULL)
1403 log->Printf ("\"%s\"%c ", symbol_names[i], sep);
1404 else
1405 log->Printf ("\"<NULL>\"%c ", sep);
1406
1407 }
1408 log->Printf ("name_type: %d) => SBBreakpoint(%p)", name_type_mask, sb_bp.get());
1409 }
1410
1411 return sb_bp;
1412}
Jim Inghamd6d47972011-09-23 00:54:11 +00001413
Chris Lattner24943d22010-06-08 16:52:24 +00001414SBBreakpoint
1415SBTarget::BreakpointCreateByRegex (const char *symbol_name_regex, const char *module_name)
1416{
Greg Claytone005f2c2010-11-06 01:53:30 +00001417 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001418
Chris Lattner24943d22010-06-08 16:52:24 +00001419 SBBreakpoint sb_bp;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001420 TargetSP target_sp(GetSP());
1421 if (target_sp && symbol_name_regex && symbol_name_regex[0])
Chris Lattner24943d22010-06-08 16:52:24 +00001422 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001423 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Chris Lattner24943d22010-06-08 16:52:24 +00001424 RegularExpression regexp(symbol_name_regex);
Jim Ingham2cf5ccb2012-05-22 00:12:20 +00001425 const bool internal = false;
1426 const LazyBool skip_prologue = eLazyBoolCalculate;
Chris Lattner24943d22010-06-08 16:52:24 +00001427
1428 if (module_name && module_name[0])
1429 {
Jim Ingham03c8ee52011-09-21 01:17:13 +00001430 FileSpecList module_spec_list;
1431 module_spec_list.Append (FileSpec (module_name, false));
Chris Lattner24943d22010-06-08 16:52:24 +00001432
Jim Ingham2cf5ccb2012-05-22 00:12:20 +00001433 *sb_bp = target_sp->CreateFuncRegexBreakpoint (&module_spec_list, NULL, regexp, skip_prologue, internal);
Chris Lattner24943d22010-06-08 16:52:24 +00001434 }
1435 else
1436 {
Jim Ingham2cf5ccb2012-05-22 00:12:20 +00001437 *sb_bp = target_sp->CreateFuncRegexBreakpoint (NULL, NULL, regexp, skip_prologue, internal);
Chris Lattner24943d22010-06-08 16:52:24 +00001438 }
1439 }
Caroline Tice7826c882010-10-26 03:11:13 +00001440
1441 if (log)
1442 {
Greg Clayton49ce6822010-10-31 03:01:06 +00001443 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (symbol_regex=\"%s\", module_name=\"%s\") => SBBreakpoint(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +00001444 target_sp.get(), symbol_name_regex, module_name, sb_bp.get());
Caroline Tice7826c882010-10-26 03:11:13 +00001445 }
1446
Chris Lattner24943d22010-06-08 16:52:24 +00001447 return sb_bp;
1448}
1449
Jim Inghamd6d47972011-09-23 00:54:11 +00001450lldb::SBBreakpoint
1451SBTarget::BreakpointCreateByRegex (const char *symbol_name_regex,
1452 const SBFileSpecList &module_list,
1453 const SBFileSpecList &comp_unit_list)
1454{
1455 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Chris Lattner24943d22010-06-08 16:52:24 +00001456
Jim Inghamd6d47972011-09-23 00:54:11 +00001457 SBBreakpoint sb_bp;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001458 TargetSP target_sp(GetSP());
1459 if (target_sp && symbol_name_regex && symbol_name_regex[0])
Jim Inghamd6d47972011-09-23 00:54:11 +00001460 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001461 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Jim Inghamd6d47972011-09-23 00:54:11 +00001462 RegularExpression regexp(symbol_name_regex);
Jim Ingham2cf5ccb2012-05-22 00:12:20 +00001463 const bool internal = false;
1464 const LazyBool skip_prologue = eLazyBoolCalculate;
Jim Inghamd6d47972011-09-23 00:54:11 +00001465
Jim Ingham2cf5ccb2012-05-22 00:12:20 +00001466 *sb_bp = target_sp->CreateFuncRegexBreakpoint (module_list.get(), comp_unit_list.get(), regexp, skip_prologue, internal);
Jim Inghamd6d47972011-09-23 00:54:11 +00001467 }
1468
1469 if (log)
1470 {
1471 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (symbol_regex=\"%s\") => SBBreakpoint(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +00001472 target_sp.get(), symbol_name_regex, sb_bp.get());
Jim Inghamd6d47972011-09-23 00:54:11 +00001473 }
1474
1475 return sb_bp;
1476}
Chris Lattner24943d22010-06-08 16:52:24 +00001477
1478SBBreakpoint
1479SBTarget::BreakpointCreateByAddress (addr_t address)
1480{
Greg Claytone005f2c2010-11-06 01:53:30 +00001481 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001482
Chris Lattner24943d22010-06-08 16:52:24 +00001483 SBBreakpoint sb_bp;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001484 TargetSP target_sp(GetSP());
1485 if (target_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +00001486 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001487 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1488 *sb_bp = target_sp->CreateBreakpoint (address, false);
Greg Claytonbdcda462010-12-20 20:49:23 +00001489 }
Caroline Tice7826c882010-10-26 03:11:13 +00001490
1491 if (log)
1492 {
Daniel Malea5f35a4b2012-11-29 21:49:15 +00001493 log->Printf ("SBTarget(%p)::BreakpointCreateByAddress (address=%" PRIu64 ") => SBBreakpoint(%p)", target_sp.get(), (uint64_t) address, sb_bp.get());
Caroline Tice7826c882010-10-26 03:11:13 +00001494 }
1495
Chris Lattner24943d22010-06-08 16:52:24 +00001496 return sb_bp;
1497}
1498
Jim Ingham03c8ee52011-09-21 01:17:13 +00001499lldb::SBBreakpoint
1500SBTarget::BreakpointCreateBySourceRegex (const char *source_regex, const lldb::SBFileSpec &source_file, const char *module_name)
1501{
1502 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1503
1504 SBBreakpoint sb_bp;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001505 TargetSP target_sp(GetSP());
1506 if (target_sp && source_regex && source_regex[0])
Jim Ingham03c8ee52011-09-21 01:17:13 +00001507 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001508 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Jim Ingham03c8ee52011-09-21 01:17:13 +00001509 RegularExpression regexp(source_regex);
Jim Inghamd6d47972011-09-23 00:54:11 +00001510 FileSpecList source_file_spec_list;
1511 source_file_spec_list.Append (source_file.ref());
Jim Ingham03c8ee52011-09-21 01:17:13 +00001512
1513 if (module_name && module_name[0])
1514 {
1515 FileSpecList module_spec_list;
1516 module_spec_list.Append (FileSpec (module_name, false));
1517
Greg Clayton0416bdf2012-01-30 09:04:36 +00001518 *sb_bp = target_sp->CreateSourceRegexBreakpoint (&module_spec_list, &source_file_spec_list, regexp, false);
Jim Ingham03c8ee52011-09-21 01:17:13 +00001519 }
1520 else
1521 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001522 *sb_bp = target_sp->CreateSourceRegexBreakpoint (NULL, &source_file_spec_list, regexp, false);
Jim Ingham03c8ee52011-09-21 01:17:13 +00001523 }
1524 }
1525
1526 if (log)
1527 {
1528 char path[PATH_MAX];
1529 source_file->GetPath (path, sizeof(path));
1530 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (source_regex=\"%s\", file=\"%s\", module_name=\"%s\") => SBBreakpoint(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +00001531 target_sp.get(), source_regex, path, module_name, sb_bp.get());
Jim Ingham03c8ee52011-09-21 01:17:13 +00001532 }
1533
1534 return sb_bp;
1535}
1536
Jim Inghamd6d47972011-09-23 00:54:11 +00001537lldb::SBBreakpoint
1538SBTarget::BreakpointCreateBySourceRegex (const char *source_regex,
1539 const SBFileSpecList &module_list,
1540 const lldb::SBFileSpecList &source_file_list)
1541{
1542 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1543
1544 SBBreakpoint sb_bp;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001545 TargetSP target_sp(GetSP());
1546 if (target_sp && source_regex && source_regex[0])
Jim Inghamd6d47972011-09-23 00:54:11 +00001547 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001548 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Jim Inghamd6d47972011-09-23 00:54:11 +00001549 RegularExpression regexp(source_regex);
Greg Clayton0416bdf2012-01-30 09:04:36 +00001550 *sb_bp = target_sp->CreateSourceRegexBreakpoint (module_list.get(), source_file_list.get(), regexp, false);
Jim Inghamd6d47972011-09-23 00:54:11 +00001551 }
1552
1553 if (log)
1554 {
1555 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (source_regex=\"%s\") => SBBreakpoint(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +00001556 target_sp.get(), source_regex, sb_bp.get());
Jim Inghamd6d47972011-09-23 00:54:11 +00001557 }
1558
1559 return sb_bp;
1560}
Jim Ingham03c8ee52011-09-21 01:17:13 +00001561
Jim Ingham4722b102012-03-06 00:37:27 +00001562lldb::SBBreakpoint
1563SBTarget::BreakpointCreateForException (lldb::LanguageType language,
1564 bool catch_bp,
1565 bool throw_bp)
1566{
1567 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1568
1569 SBBreakpoint sb_bp;
1570 TargetSP target_sp(GetSP());
1571 if (target_sp)
1572 {
1573 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1574 *sb_bp = target_sp->CreateExceptionBreakpoint (language, catch_bp, throw_bp);
1575 }
1576
1577 if (log)
1578 {
1579 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (Language: %s, catch: %s throw: %s) => SBBreakpoint(%p)",
1580 target_sp.get(),
1581 LanguageRuntime::GetNameForLanguageType(language),
1582 catch_bp ? "on" : "off",
1583 throw_bp ? "on" : "off",
1584 sb_bp.get());
1585 }
1586
1587 return sb_bp;
1588}
1589
Greg Claytonc7f5d5c2010-07-23 23:33:17 +00001590uint32_t
1591SBTarget::GetNumBreakpoints () const
1592{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001593 TargetSP target_sp(GetSP());
1594 if (target_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +00001595 {
1596 // The breakpoint list is thread safe, no need to lock
Greg Clayton0416bdf2012-01-30 09:04:36 +00001597 return target_sp->GetBreakpointList().GetSize();
Greg Claytonbdcda462010-12-20 20:49:23 +00001598 }
Greg Claytonc7f5d5c2010-07-23 23:33:17 +00001599 return 0;
1600}
1601
1602SBBreakpoint
1603SBTarget::GetBreakpointAtIndex (uint32_t idx) const
1604{
1605 SBBreakpoint sb_breakpoint;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001606 TargetSP target_sp(GetSP());
1607 if (target_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +00001608 {
1609 // The breakpoint list is thread safe, no need to lock
Greg Clayton0416bdf2012-01-30 09:04:36 +00001610 *sb_breakpoint = target_sp->GetBreakpointList().GetBreakpointAtIndex(idx);
Greg Claytonbdcda462010-12-20 20:49:23 +00001611 }
Greg Claytonc7f5d5c2010-07-23 23:33:17 +00001612 return sb_breakpoint;
1613}
Chris Lattner24943d22010-06-08 16:52:24 +00001614
1615bool
1616SBTarget::BreakpointDelete (break_id_t bp_id)
1617{
Greg Claytone005f2c2010-11-06 01:53:30 +00001618 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001619
Caroline Tice7826c882010-10-26 03:11:13 +00001620 bool result = false;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001621 TargetSP target_sp(GetSP());
1622 if (target_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +00001623 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001624 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1625 result = target_sp->RemoveBreakpointByID (bp_id);
Greg Claytonbdcda462010-12-20 20:49:23 +00001626 }
Caroline Tice7826c882010-10-26 03:11:13 +00001627
1628 if (log)
1629 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001630 log->Printf ("SBTarget(%p)::BreakpointDelete (bp_id=%d) => %i", target_sp.get(), (uint32_t) bp_id, result);
Caroline Tice7826c882010-10-26 03:11:13 +00001631 }
1632
1633 return result;
Chris Lattner24943d22010-06-08 16:52:24 +00001634}
1635
Johnny Chen096c2932011-09-26 22:40:50 +00001636SBBreakpoint
1637SBTarget::FindBreakpointByID (break_id_t bp_id)
1638{
1639 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1640
1641 SBBreakpoint sb_breakpoint;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001642 TargetSP target_sp(GetSP());
1643 if (target_sp && bp_id != LLDB_INVALID_BREAK_ID)
Johnny Chen096c2932011-09-26 22:40:50 +00001644 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001645 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1646 *sb_breakpoint = target_sp->GetBreakpointByID (bp_id);
Johnny Chen096c2932011-09-26 22:40:50 +00001647 }
1648
1649 if (log)
1650 {
1651 log->Printf ("SBTarget(%p)::FindBreakpointByID (bp_id=%d) => SBBreakpoint(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +00001652 target_sp.get(), (uint32_t) bp_id, sb_breakpoint.get());
Johnny Chen096c2932011-09-26 22:40:50 +00001653 }
1654
1655 return sb_breakpoint;
1656}
1657
Chris Lattner24943d22010-06-08 16:52:24 +00001658bool
1659SBTarget::EnableAllBreakpoints ()
1660{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001661 TargetSP target_sp(GetSP());
1662 if (target_sp)
Chris Lattner24943d22010-06-08 16:52:24 +00001663 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001664 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1665 target_sp->EnableAllBreakpoints ();
Chris Lattner24943d22010-06-08 16:52:24 +00001666 return true;
1667 }
1668 return false;
1669}
1670
1671bool
1672SBTarget::DisableAllBreakpoints ()
1673{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001674 TargetSP target_sp(GetSP());
1675 if (target_sp)
Chris Lattner24943d22010-06-08 16:52:24 +00001676 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001677 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1678 target_sp->DisableAllBreakpoints ();
Chris Lattner24943d22010-06-08 16:52:24 +00001679 return true;
1680 }
1681 return false;
1682}
1683
1684bool
1685SBTarget::DeleteAllBreakpoints ()
1686{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001687 TargetSP target_sp(GetSP());
1688 if (target_sp)
Chris Lattner24943d22010-06-08 16:52:24 +00001689 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001690 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1691 target_sp->RemoveAllBreakpoints ();
Chris Lattner24943d22010-06-08 16:52:24 +00001692 return true;
1693 }
1694 return false;
1695}
1696
Johnny Chen096c2932011-09-26 22:40:50 +00001697uint32_t
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001698SBTarget::GetNumWatchpoints () const
Johnny Chen096c2932011-09-26 22:40:50 +00001699{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001700 TargetSP target_sp(GetSP());
1701 if (target_sp)
Johnny Chen096c2932011-09-26 22:40:50 +00001702 {
Johnny Chenecd4feb2011-10-14 00:42:25 +00001703 // The watchpoint list is thread safe, no need to lock
Greg Clayton0416bdf2012-01-30 09:04:36 +00001704 return target_sp->GetWatchpointList().GetSize();
Johnny Chen096c2932011-09-26 22:40:50 +00001705 }
1706 return 0;
1707}
1708
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001709SBWatchpoint
1710SBTarget::GetWatchpointAtIndex (uint32_t idx) const
Johnny Chen5eb54bb2011-09-27 20:29:45 +00001711{
Johnny Chenecd4feb2011-10-14 00:42:25 +00001712 SBWatchpoint sb_watchpoint;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001713 TargetSP target_sp(GetSP());
1714 if (target_sp)
Johnny Chen096c2932011-09-26 22:40:50 +00001715 {
Johnny Chenecd4feb2011-10-14 00:42:25 +00001716 // The watchpoint list is thread safe, no need to lock
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001717 sb_watchpoint.SetSP (target_sp->GetWatchpointList().GetByIndex(idx));
Johnny Chen096c2932011-09-26 22:40:50 +00001718 }
Johnny Chenecd4feb2011-10-14 00:42:25 +00001719 return sb_watchpoint;
Johnny Chen096c2932011-09-26 22:40:50 +00001720}
1721
1722bool
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001723SBTarget::DeleteWatchpoint (watch_id_t wp_id)
Johnny Chen096c2932011-09-26 22:40:50 +00001724{
1725 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1726
1727 bool result = false;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001728 TargetSP target_sp(GetSP());
1729 if (target_sp)
Johnny Chen096c2932011-09-26 22:40:50 +00001730 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001731 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Johnny Chenbbf6aa52012-05-31 22:56:36 +00001732 Mutex::Locker locker;
1733 target_sp->GetWatchpointList().GetListMutex(locker);
Greg Clayton0416bdf2012-01-30 09:04:36 +00001734 result = target_sp->RemoveWatchpointByID (wp_id);
Johnny Chen096c2932011-09-26 22:40:50 +00001735 }
1736
1737 if (log)
1738 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001739 log->Printf ("SBTarget(%p)::WatchpointDelete (wp_id=%d) => %i", target_sp.get(), (uint32_t) wp_id, result);
Johnny Chen096c2932011-09-26 22:40:50 +00001740 }
1741
1742 return result;
1743}
1744
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001745SBWatchpoint
1746SBTarget::FindWatchpointByID (lldb::watch_id_t wp_id)
Johnny Chen096c2932011-09-26 22:40:50 +00001747{
1748 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1749
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001750 SBWatchpoint sb_watchpoint;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001751 lldb::WatchpointSP watchpoint_sp;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001752 TargetSP target_sp(GetSP());
1753 if (target_sp && wp_id != LLDB_INVALID_WATCH_ID)
Johnny Chen096c2932011-09-26 22:40:50 +00001754 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001755 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Johnny Chenbbf6aa52012-05-31 22:56:36 +00001756 Mutex::Locker locker;
1757 target_sp->GetWatchpointList().GetListMutex(locker);
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001758 watchpoint_sp = target_sp->GetWatchpointList().FindByID(wp_id);
1759 sb_watchpoint.SetSP (watchpoint_sp);
Johnny Chen096c2932011-09-26 22:40:50 +00001760 }
1761
1762 if (log)
1763 {
Johnny Chenecd4feb2011-10-14 00:42:25 +00001764 log->Printf ("SBTarget(%p)::FindWatchpointByID (bp_id=%d) => SBWatchpoint(%p)",
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001765 target_sp.get(), (uint32_t) wp_id, watchpoint_sp.get());
Johnny Chen096c2932011-09-26 22:40:50 +00001766 }
1767
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001768 return sb_watchpoint;
1769}
1770
1771lldb::SBWatchpoint
Johnny Chen3f883492012-06-04 23:19:54 +00001772SBTarget::WatchAddress (lldb::addr_t addr, size_t size, bool read, bool write, SBError &error)
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001773{
1774 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1775
1776 SBWatchpoint sb_watchpoint;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001777 lldb::WatchpointSP watchpoint_sp;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001778 TargetSP target_sp(GetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001779 if (target_sp && (read || write) && addr != LLDB_INVALID_ADDRESS && size > 0)
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001780 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001781 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001782 uint32_t watch_type = 0;
1783 if (read)
1784 watch_type |= LLDB_WATCH_TYPE_READ;
1785 if (write)
1786 watch_type |= LLDB_WATCH_TYPE_WRITE;
Johnny Chenbbf6aa52012-05-31 22:56:36 +00001787 // Target::CreateWatchpoint() is thread safe.
Johnny Chen3f883492012-06-04 23:19:54 +00001788 Error cw_error;
Jim Ingham9e376622012-10-23 07:20:06 +00001789 // This API doesn't take in a type, so we can't figure out what it is.
1790 ClangASTType *type = NULL;
1791 watchpoint_sp = target_sp->CreateWatchpoint(addr, size, type, watch_type, cw_error);
Johnny Chen3f883492012-06-04 23:19:54 +00001792 error.SetError(cw_error);
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001793 sb_watchpoint.SetSP (watchpoint_sp);
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001794 }
1795
1796 if (log)
1797 {
Daniel Malea5f35a4b2012-11-29 21:49:15 +00001798 log->Printf ("SBTarget(%p)::WatchAddress (addr=0x%" PRIx64 ", 0x%u) => SBWatchpoint(%p)",
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001799 target_sp.get(), addr, (uint32_t) size, watchpoint_sp.get());
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001800 }
1801
1802 return sb_watchpoint;
Johnny Chen096c2932011-09-26 22:40:50 +00001803}
1804
1805bool
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001806SBTarget::EnableAllWatchpoints ()
Johnny Chen096c2932011-09-26 22:40:50 +00001807{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001808 TargetSP target_sp(GetSP());
1809 if (target_sp)
Johnny Chen096c2932011-09-26 22:40:50 +00001810 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001811 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Johnny Chenbbf6aa52012-05-31 22:56:36 +00001812 Mutex::Locker locker;
1813 target_sp->GetWatchpointList().GetListMutex(locker);
Greg Clayton0416bdf2012-01-30 09:04:36 +00001814 target_sp->EnableAllWatchpoints ();
Johnny Chen096c2932011-09-26 22:40:50 +00001815 return true;
1816 }
1817 return false;
1818}
1819
1820bool
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001821SBTarget::DisableAllWatchpoints ()
Johnny Chen096c2932011-09-26 22:40:50 +00001822{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001823 TargetSP target_sp(GetSP());
1824 if (target_sp)
Johnny Chen096c2932011-09-26 22:40:50 +00001825 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001826 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Johnny Chenbbf6aa52012-05-31 22:56:36 +00001827 Mutex::Locker locker;
1828 target_sp->GetWatchpointList().GetListMutex(locker);
Greg Clayton0416bdf2012-01-30 09:04:36 +00001829 target_sp->DisableAllWatchpoints ();
Johnny Chen096c2932011-09-26 22:40:50 +00001830 return true;
1831 }
1832 return false;
1833}
1834
1835bool
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001836SBTarget::DeleteAllWatchpoints ()
Johnny Chen096c2932011-09-26 22:40:50 +00001837{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001838 TargetSP target_sp(GetSP());
1839 if (target_sp)
Johnny Chen096c2932011-09-26 22:40:50 +00001840 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001841 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Johnny Chenbbf6aa52012-05-31 22:56:36 +00001842 Mutex::Locker locker;
1843 target_sp->GetWatchpointList().GetListMutex(locker);
Greg Clayton0416bdf2012-01-30 09:04:36 +00001844 target_sp->RemoveAllWatchpoints ();
Johnny Chen096c2932011-09-26 22:40:50 +00001845 return true;
1846 }
1847 return false;
1848}
1849
Chris Lattner24943d22010-06-08 16:52:24 +00001850
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001851lldb::SBModule
1852SBTarget::AddModule (const char *path,
1853 const char *triple,
1854 const char *uuid_cstr)
1855{
Greg Claytonf0bc8152012-04-23 20:23:39 +00001856 return AddModule (path, triple, uuid_cstr, NULL);
1857}
1858
1859lldb::SBModule
1860SBTarget::AddModule (const char *path,
1861 const char *triple,
1862 const char *uuid_cstr,
1863 const char *symfile)
1864{
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001865 lldb::SBModule sb_module;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001866 TargetSP target_sp(GetSP());
1867 if (target_sp)
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001868 {
Greg Clayton444fe992012-02-26 05:51:37 +00001869 ModuleSpec module_spec;
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001870 if (path)
Greg Clayton444fe992012-02-26 05:51:37 +00001871 module_spec.GetFileSpec().SetFile(path, false);
Greg Claytonf0bc8152012-04-23 20:23:39 +00001872
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001873 if (uuid_cstr)
Greg Clayton437b5bc2012-09-27 22:26:11 +00001874 module_spec.GetUUID().SetFromCString(uuid_cstr);
Greg Claytonf0bc8152012-04-23 20:23:39 +00001875
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001876 if (triple)
Greg Clayton444fe992012-02-26 05:51:37 +00001877 module_spec.GetArchitecture().SetTriple (triple, target_sp->GetPlatform ().get());
Greg Claytonf0bc8152012-04-23 20:23:39 +00001878
1879 if (symfile)
1880 module_spec.GetSymbolFileSpec ().SetFile(symfile, false);
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001881
Greg Clayton444fe992012-02-26 05:51:37 +00001882 sb_module.SetSP(target_sp->GetSharedModule (module_spec));
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001883 }
1884 return sb_module;
1885}
1886
1887bool
1888SBTarget::AddModule (lldb::SBModule &module)
1889{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001890 TargetSP target_sp(GetSP());
1891 if (target_sp)
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001892 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001893 target_sp->GetImages().AppendIfNeeded (module.GetSP());
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001894 return true;
1895 }
1896 return false;
1897}
1898
Chris Lattner24943d22010-06-08 16:52:24 +00001899uint32_t
1900SBTarget::GetNumModules () const
1901{
Greg Claytone005f2c2010-11-06 01:53:30 +00001902 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001903
Caroline Tice7826c882010-10-26 03:11:13 +00001904 uint32_t num = 0;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001905 TargetSP target_sp(GetSP());
1906 if (target_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +00001907 {
1908 // The module list is thread safe, no need to lock
Greg Clayton0416bdf2012-01-30 09:04:36 +00001909 num = target_sp->GetImages().GetSize();
Greg Claytonbdcda462010-12-20 20:49:23 +00001910 }
Caroline Tice7826c882010-10-26 03:11:13 +00001911
1912 if (log)
Greg Clayton0416bdf2012-01-30 09:04:36 +00001913 log->Printf ("SBTarget(%p)::GetNumModules () => %d", target_sp.get(), num);
Caroline Tice7826c882010-10-26 03:11:13 +00001914
1915 return num;
Chris Lattner24943d22010-06-08 16:52:24 +00001916}
1917
Greg Clayton43490d12010-07-30 20:12:55 +00001918void
1919SBTarget::Clear ()
1920{
Greg Claytone005f2c2010-11-06 01:53:30 +00001921 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001922
1923 if (log)
Greg Clayton3f5ee7f2010-10-29 04:59:35 +00001924 log->Printf ("SBTarget(%p)::Clear ()", m_opaque_sp.get());
Caroline Tice7826c882010-10-26 03:11:13 +00001925
Greg Clayton43490d12010-07-30 20:12:55 +00001926 m_opaque_sp.reset();
1927}
1928
1929
Chris Lattner24943d22010-06-08 16:52:24 +00001930SBModule
1931SBTarget::FindModule (const SBFileSpec &sb_file_spec)
1932{
1933 SBModule sb_module;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001934 TargetSP target_sp(GetSP());
1935 if (target_sp && sb_file_spec.IsValid())
Greg Claytonbdcda462010-12-20 20:49:23 +00001936 {
Greg Clayton444fe992012-02-26 05:51:37 +00001937 ModuleSpec module_spec(*sb_file_spec);
Greg Claytonbdcda462010-12-20 20:49:23 +00001938 // The module list is thread safe, no need to lock
Greg Clayton444fe992012-02-26 05:51:37 +00001939 sb_module.SetSP (target_sp->GetImages().FindFirstModule (module_spec));
Greg Claytonbdcda462010-12-20 20:49:23 +00001940 }
Chris Lattner24943d22010-06-08 16:52:24 +00001941 return sb_module;
1942}
1943
Greg Clayton1b925202012-01-29 06:07:39 +00001944lldb::ByteOrder
1945SBTarget::GetByteOrder ()
1946{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001947 TargetSP target_sp(GetSP());
1948 if (target_sp)
1949 return target_sp->GetArchitecture().GetByteOrder();
Greg Clayton1b925202012-01-29 06:07:39 +00001950 return eByteOrderInvalid;
1951}
1952
1953const char *
1954SBTarget::GetTriple ()
1955{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001956 TargetSP target_sp(GetSP());
1957 if (target_sp)
Greg Clayton1b925202012-01-29 06:07:39 +00001958 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001959 std::string triple (target_sp->GetArchitecture().GetTriple().str());
Greg Clayton1b925202012-01-29 06:07:39 +00001960 // Unique the string so we don't run into ownership issues since
1961 // the const strings put the string into the string pool once and
1962 // the strings never comes out
1963 ConstString const_triple (triple.c_str());
1964 return const_triple.GetCString();
1965 }
1966 return NULL;
1967}
1968
1969uint32_t
1970SBTarget::GetAddressByteSize()
1971{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001972 TargetSP target_sp(GetSP());
1973 if (target_sp)
1974 return target_sp->GetArchitecture().GetAddressByteSize();
Greg Clayton1b925202012-01-29 06:07:39 +00001975 return sizeof(void*);
1976}
1977
1978
Chris Lattner24943d22010-06-08 16:52:24 +00001979SBModule
1980SBTarget::GetModuleAtIndex (uint32_t idx)
1981{
Greg Claytone005f2c2010-11-06 01:53:30 +00001982 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001983
Chris Lattner24943d22010-06-08 16:52:24 +00001984 SBModule sb_module;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001985 ModuleSP module_sp;
1986 TargetSP target_sp(GetSP());
1987 if (target_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +00001988 {
1989 // The module list is thread safe, no need to lock
Greg Clayton0416bdf2012-01-30 09:04:36 +00001990 module_sp = target_sp->GetImages().GetModuleAtIndex(idx);
1991 sb_module.SetSP (module_sp);
Greg Claytonbdcda462010-12-20 20:49:23 +00001992 }
Caroline Tice7826c882010-10-26 03:11:13 +00001993
1994 if (log)
1995 {
Greg Clayton49ce6822010-10-31 03:01:06 +00001996 log->Printf ("SBTarget(%p)::GetModuleAtIndex (idx=%d) => SBModule(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +00001997 target_sp.get(), idx, module_sp.get());
Caroline Tice7826c882010-10-26 03:11:13 +00001998 }
1999
Chris Lattner24943d22010-06-08 16:52:24 +00002000 return sb_module;
2001}
2002
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002003bool
2004SBTarget::RemoveModule (lldb::SBModule module)
2005{
Greg Clayton0416bdf2012-01-30 09:04:36 +00002006 TargetSP target_sp(GetSP());
2007 if (target_sp)
2008 return target_sp->GetImages().Remove(module.GetSP());
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002009 return false;
2010}
2011
Chris Lattner24943d22010-06-08 16:52:24 +00002012
2013SBBroadcaster
2014SBTarget::GetBroadcaster () const
2015{
Greg Claytone005f2c2010-11-06 01:53:30 +00002016 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00002017
Greg Clayton0416bdf2012-01-30 09:04:36 +00002018 TargetSP target_sp(GetSP());
2019 SBBroadcaster broadcaster(target_sp.get(), false);
Caroline Tice7826c882010-10-26 03:11:13 +00002020
2021 if (log)
Greg Clayton3f5ee7f2010-10-29 04:59:35 +00002022 log->Printf ("SBTarget(%p)::GetBroadcaster () => SBBroadcaster(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +00002023 target_sp.get(), broadcaster.get());
Caroline Tice7826c882010-10-26 03:11:13 +00002024
Chris Lattner24943d22010-06-08 16:52:24 +00002025 return broadcaster;
2026}
2027
Caroline Tice98f930f2010-09-20 05:20:02 +00002028bool
Caroline Tice7826c882010-10-26 03:11:13 +00002029SBTarget::GetDescription (SBStream &description, lldb::DescriptionLevel description_level)
Caroline Tice98f930f2010-09-20 05:20:02 +00002030{
Greg Clayton96154be2011-11-13 06:57:31 +00002031 Stream &strm = description.ref();
2032
Greg Clayton0416bdf2012-01-30 09:04:36 +00002033 TargetSP target_sp(GetSP());
2034 if (target_sp)
Caroline Ticee7a566e2010-09-20 16:21:41 +00002035 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00002036 target_sp->Dump (&strm, description_level);
Caroline Tice7826c882010-10-26 03:11:13 +00002037 }
2038 else
Greg Clayton96154be2011-11-13 06:57:31 +00002039 strm.PutCString ("No value");
Caroline Tice7826c882010-10-26 03:11:13 +00002040
2041 return true;
2042}
2043
Greg Clayton7dd5c512012-02-06 01:44:54 +00002044lldb::SBSymbolContextList
2045SBTarget::FindFunctions (const char *name, uint32_t name_type_mask)
Greg Clayton4ed315f2011-06-21 01:34:41 +00002046{
Greg Clayton7dd5c512012-02-06 01:44:54 +00002047 lldb::SBSymbolContextList sb_sc_list;
Greg Clayton0416bdf2012-01-30 09:04:36 +00002048 if (name && name[0])
Greg Clayton4ed315f2011-06-21 01:34:41 +00002049 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00002050 TargetSP target_sp(GetSP());
2051 if (target_sp)
2052 {
2053 const bool symbols_ok = true;
Sean Callanan302d78c2012-02-10 22:52:19 +00002054 const bool inlines_ok = true;
Greg Clayton7dd5c512012-02-06 01:44:54 +00002055 const bool append = true;
2056 target_sp->GetImages().FindFunctions (ConstString(name),
2057 name_type_mask,
Sean Callanan302d78c2012-02-10 22:52:19 +00002058 symbols_ok,
2059 inlines_ok,
Greg Clayton7dd5c512012-02-06 01:44:54 +00002060 append,
2061 *sb_sc_list);
Greg Clayton0416bdf2012-01-30 09:04:36 +00002062 }
Greg Clayton4ed315f2011-06-21 01:34:41 +00002063 }
Greg Clayton7dd5c512012-02-06 01:44:54 +00002064 return sb_sc_list;
Greg Clayton4ed315f2011-06-21 01:34:41 +00002065}
2066
Enrico Granata979e20d2011-07-29 19:53:35 +00002067lldb::SBType
Greg Clayton0b93a752012-12-05 21:24:42 +00002068SBTarget::FindFirstType (const char* typename_cstr)
Enrico Granata979e20d2011-07-29 19:53:35 +00002069{
Greg Clayton0416bdf2012-01-30 09:04:36 +00002070 TargetSP target_sp(GetSP());
Greg Clayton0b93a752012-12-05 21:24:42 +00002071 if (typename_cstr && typename_cstr[0] && target_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +00002072 {
Greg Clayton0b93a752012-12-05 21:24:42 +00002073 ConstString const_typename(typename_cstr);
2074 SymbolContext sc;
2075 const bool exact_match = false;
2076
2077 const ModuleList &module_list = target_sp->GetImages();
2078 size_t count = module_list.GetSize();
Enrico Granata979e20d2011-07-29 19:53:35 +00002079 for (size_t idx = 0; idx < count; idx++)
2080 {
Greg Clayton0b93a752012-12-05 21:24:42 +00002081 ModuleSP module_sp (module_list.GetModuleAtIndex(idx));
2082 if (module_sp)
2083 {
2084 TypeSP type_sp (module_sp->FindFirstType(sc, const_typename, exact_match));
2085 if (type_sp)
2086 return SBType(type_sp);
2087 }
Enrico Granata979e20d2011-07-29 19:53:35 +00002088 }
Sean Callanan282c22c2012-12-19 23:05:01 +00002089
2090 // Didn't find the type in the symbols; try the Objective-C runtime
2091 // if one is installed
2092
2093 ProcessSP process_sp(target_sp->GetProcessSP());
2094
2095 if (process_sp)
2096 {
2097 ObjCLanguageRuntime *objc_language_runtime = process_sp->GetObjCLanguageRuntime();
2098
2099 if (objc_language_runtime)
2100 {
2101 TypeVendor *objc_type_vendor = objc_language_runtime->GetTypeVendor();
2102
2103 if (objc_type_vendor)
2104 {
2105 std::vector <ClangASTType> types;
2106
2107 if (objc_type_vendor->FindTypes(const_typename, true, 1, types) > 0)
2108 return SBType(types[0]);
2109 }
2110 }
2111 }
Greg Clayton0b93a752012-12-05 21:24:42 +00002112
2113 // No matches, search for basic typename matches
2114 ClangASTContext *clang_ast = target_sp->GetScratchClangASTContext();
2115 if (clang_ast)
2116 return SBType (ClangASTType::GetBasicType (clang_ast->getASTContext(), const_typename));
Enrico Granata979e20d2011-07-29 19:53:35 +00002117 }
2118 return SBType();
2119}
2120
Greg Clayton0b93a752012-12-05 21:24:42 +00002121SBType
2122SBTarget::GetBasicType(lldb::BasicType type)
Enrico Granata979e20d2011-07-29 19:53:35 +00002123{
Greg Clayton0416bdf2012-01-30 09:04:36 +00002124 TargetSP target_sp(GetSP());
Greg Clayton0b93a752012-12-05 21:24:42 +00002125 if (target_sp)
2126 {
2127 ClangASTContext *clang_ast = target_sp->GetScratchClangASTContext();
2128 if (clang_ast)
2129 return SBType (ClangASTType::GetBasicType (clang_ast->getASTContext(), type));
2130 }
2131 return SBType();
2132}
2133
2134
2135lldb::SBTypeList
2136SBTarget::FindTypes (const char* typename_cstr)
2137{
2138 SBTypeList sb_type_list;
2139 TargetSP target_sp(GetSP());
2140 if (typename_cstr && typename_cstr[0] && target_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +00002141 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00002142 ModuleList& images = target_sp->GetImages();
Greg Clayton0b93a752012-12-05 21:24:42 +00002143 ConstString const_typename(typename_cstr);
Greg Claytondc0a38c2012-03-26 23:03:23 +00002144 bool exact_match = false;
Enrico Granata979e20d2011-07-29 19:53:35 +00002145 SymbolContext sc;
2146 TypeList type_list;
2147
Greg Clayton9f95fb62012-04-06 17:41:13 +00002148 uint32_t num_matches = images.FindTypes (sc,
Greg Clayton0b93a752012-12-05 21:24:42 +00002149 const_typename,
Greg Claytondc0a38c2012-03-26 23:03:23 +00002150 exact_match,
2151 UINT32_MAX,
2152 type_list);
Enrico Granata979e20d2011-07-29 19:53:35 +00002153
Greg Clayton0b93a752012-12-05 21:24:42 +00002154 if (num_matches > 0)
Enrico Granata979e20d2011-07-29 19:53:35 +00002155 {
Greg Clayton0b93a752012-12-05 21:24:42 +00002156 for (size_t idx = 0; idx < num_matches; idx++)
2157 {
2158 TypeSP type_sp (type_list.GetTypeAtIndex(idx));
2159 if (type_sp)
2160 sb_type_list.Append(SBType(type_sp));
2161 }
2162 }
Sean Callanan282c22c2012-12-19 23:05:01 +00002163
2164 // Try the Objective-C runtime if one is installed
2165
2166 ProcessSP process_sp(target_sp->GetProcessSP());
2167
2168 if (process_sp)
2169 {
2170 ObjCLanguageRuntime *objc_language_runtime = process_sp->GetObjCLanguageRuntime();
2171
2172 if (objc_language_runtime)
2173 {
2174 TypeVendor *objc_type_vendor = objc_language_runtime->GetTypeVendor();
2175
2176 if (objc_type_vendor)
2177 {
2178 std::vector <ClangASTType> types;
2179
2180 if (objc_type_vendor->FindTypes(const_typename, true, UINT32_MAX, types))
2181 {
2182 for (ClangASTType &type : types)
2183 {
2184 sb_type_list.Append(SBType(type));
2185 }
2186 }
2187 }
2188 }
2189 }
2190
2191 if (sb_type_list.GetSize() == 0)
Greg Clayton0b93a752012-12-05 21:24:42 +00002192 {
2193 // No matches, search for basic typename matches
2194 ClangASTContext *clang_ast = target_sp->GetScratchClangASTContext();
2195 if (clang_ast)
2196 sb_type_list.Append (SBType (ClangASTType::GetBasicType (clang_ast->getASTContext(), const_typename)));
Enrico Granata979e20d2011-07-29 19:53:35 +00002197 }
2198 }
Greg Clayton0b93a752012-12-05 21:24:42 +00002199 return sb_type_list;
Enrico Granata979e20d2011-07-29 19:53:35 +00002200}
2201
Greg Clayton917c0002011-06-29 22:09:02 +00002202SBValueList
2203SBTarget::FindGlobalVariables (const char *name, uint32_t max_matches)
2204{
2205 SBValueList sb_value_list;
2206
Greg Clayton0416bdf2012-01-30 09:04:36 +00002207 TargetSP target_sp(GetSP());
2208 if (name && target_sp)
Greg Clayton917c0002011-06-29 22:09:02 +00002209 {
2210 VariableList variable_list;
2211 const bool append = true;
Greg Clayton0416bdf2012-01-30 09:04:36 +00002212 const uint32_t match_count = target_sp->GetImages().FindGlobalVariables (ConstString (name),
2213 append,
2214 max_matches,
2215 variable_list);
Greg Clayton917c0002011-06-29 22:09:02 +00002216
2217 if (match_count > 0)
2218 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00002219 ExecutionContextScope *exe_scope = target_sp->GetProcessSP().get();
Greg Clayton917c0002011-06-29 22:09:02 +00002220 if (exe_scope == NULL)
Greg Clayton0416bdf2012-01-30 09:04:36 +00002221 exe_scope = target_sp.get();
Greg Clayton917c0002011-06-29 22:09:02 +00002222 ValueObjectList &value_object_list = sb_value_list.ref();
2223 for (uint32_t i=0; i<match_count; ++i)
2224 {
2225 lldb::ValueObjectSP valobj_sp (ValueObjectVariable::Create (exe_scope, variable_list.GetVariableAtIndex(i)));
2226 if (valobj_sp)
2227 value_object_list.Append(valobj_sp);
2228 }
2229 }
2230 }
2231
2232 return sb_value_list;
2233}
2234
Enrico Granata392bd8d2013-01-16 18:53:52 +00002235lldb::SBValue
2236SBTarget::FindFirstGlobalVariable (const char* name)
2237{
2238 SBValueList sb_value_list(FindGlobalVariables(name, 1));
2239 if (sb_value_list.IsValid() && sb_value_list.GetSize() > 0)
2240 return sb_value_list.GetValueAtIndex(0);
2241 return SBValue();
2242}
2243
Jim Inghamcc637462011-09-13 00:29:56 +00002244SBSourceManager
2245SBTarget::GetSourceManager()
2246{
2247 SBSourceManager source_manager (*this);
2248 return source_manager;
2249}
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002250
Sean Callananef1f6902011-12-14 23:49:37 +00002251lldb::SBInstructionList
Greg Claytona9893072012-03-06 22:24:44 +00002252SBTarget::ReadInstructions (lldb::SBAddress base_addr, uint32_t count)
2253{
2254 SBInstructionList sb_instructions;
2255
2256 TargetSP target_sp(GetSP());
2257 if (target_sp)
2258 {
2259 Address *addr_ptr = base_addr.get();
2260
2261 if (addr_ptr)
2262 {
2263 DataBufferHeap data (target_sp->GetArchitecture().GetMaximumOpcodeByteSize() * count, 0);
2264 bool prefer_file_cache = false;
2265 lldb_private::Error error;
2266 const size_t bytes_read = target_sp->ReadMemory(*addr_ptr, prefer_file_cache, data.GetBytes(), data.GetByteSize(), error);
2267 sb_instructions.SetDisassembler (Disassembler::DisassembleBytes (target_sp->GetArchitecture(),
2268 NULL,
2269 *addr_ptr,
2270 data.GetBytes(),
2271 bytes_read,
2272 count));
2273 }
2274 }
2275
2276 return sb_instructions;
2277
2278}
2279
2280lldb::SBInstructionList
Sean Callananef1f6902011-12-14 23:49:37 +00002281SBTarget::GetInstructions (lldb::SBAddress base_addr, const void *buf, size_t size)
2282{
2283 SBInstructionList sb_instructions;
2284
Greg Clayton0416bdf2012-01-30 09:04:36 +00002285 TargetSP target_sp(GetSP());
2286 if (target_sp)
Sean Callananef1f6902011-12-14 23:49:37 +00002287 {
2288 Address addr;
2289
2290 if (base_addr.get())
2291 addr = *base_addr.get();
2292
Greg Clayton0416bdf2012-01-30 09:04:36 +00002293 sb_instructions.SetDisassembler (Disassembler::DisassembleBytes (target_sp->GetArchitecture(),
Sean Callananef1f6902011-12-14 23:49:37 +00002294 NULL,
2295 addr,
2296 buf,
2297 size));
2298 }
2299
2300 return sb_instructions;
2301}
2302
2303lldb::SBInstructionList
2304SBTarget::GetInstructions (lldb::addr_t base_addr, const void *buf, size_t size)
2305{
2306 return GetInstructions (ResolveLoadAddress(base_addr), buf, size);
2307}
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002308
2309SBError
2310SBTarget::SetSectionLoadAddress (lldb::SBSection section,
2311 lldb::addr_t section_base_addr)
2312{
2313 SBError sb_error;
Greg Clayton0416bdf2012-01-30 09:04:36 +00002314 TargetSP target_sp(GetSP());
2315 if (target_sp)
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002316 {
2317 if (!section.IsValid())
2318 {
2319 sb_error.SetErrorStringWithFormat ("invalid section");
2320 }
2321 else
2322 {
Greg Clayton9ab696e2012-03-27 21:10:07 +00002323 SectionSP section_sp (section.GetSP());
2324 if (section_sp)
2325 {
2326 if (section_sp->IsThreadSpecific())
2327 {
2328 sb_error.SetErrorString ("thread specific sections are not yet supported");
2329 }
2330 else
2331 {
Greg Clayton1f71bcf2013-01-29 01:17:09 +00002332 if (target_sp->GetSectionLoadList().SetSectionLoadAddress (section_sp, section_base_addr))
2333 {
2334 // Flush info in the process (stack frames, etc)
2335 ProcessSP process_sp (target_sp->GetProcessSP());
2336 if (process_sp)
2337 process_sp->Flush();
2338 }
Greg Clayton9ab696e2012-03-27 21:10:07 +00002339 }
2340 }
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002341 }
2342 }
2343 else
2344 {
Greg Clayton9ab696e2012-03-27 21:10:07 +00002345 sb_error.SetErrorString ("invalid target");
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002346 }
2347 return sb_error;
2348}
2349
2350SBError
2351SBTarget::ClearSectionLoadAddress (lldb::SBSection section)
2352{
2353 SBError sb_error;
2354
Greg Clayton0416bdf2012-01-30 09:04:36 +00002355 TargetSP target_sp(GetSP());
2356 if (target_sp)
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002357 {
2358 if (!section.IsValid())
2359 {
2360 sb_error.SetErrorStringWithFormat ("invalid section");
2361 }
2362 else
2363 {
Greg Clayton1f71bcf2013-01-29 01:17:09 +00002364 if (target_sp->GetSectionLoadList().SetSectionUnloaded (section.GetSP()))
2365 {
2366 // Flush info in the process (stack frames, etc)
2367 ProcessSP process_sp (target_sp->GetProcessSP());
2368 if (process_sp)
2369 process_sp->Flush();
2370 }
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002371 }
2372 }
2373 else
2374 {
2375 sb_error.SetErrorStringWithFormat ("invalid target");
2376 }
2377 return sb_error;
2378}
2379
2380SBError
2381SBTarget::SetModuleLoadAddress (lldb::SBModule module, int64_t slide_offset)
2382{
2383 SBError sb_error;
2384
Greg Clayton0416bdf2012-01-30 09:04:36 +00002385 TargetSP target_sp(GetSP());
2386 if (target_sp)
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002387 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00002388 ModuleSP module_sp (module.GetSP());
2389 if (module_sp)
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002390 {
Greg Clayton9ab696e2012-03-27 21:10:07 +00002391 bool changed = false;
2392 if (module_sp->SetLoadAddress (*target_sp, slide_offset, changed))
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002393 {
Greg Clayton9ab696e2012-03-27 21:10:07 +00002394 // The load was successful, make sure that at least some sections
2395 // changed before we notify that our module was loaded.
2396 if (changed)
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002397 {
Greg Clayton9ab696e2012-03-27 21:10:07 +00002398 ModuleList module_list;
2399 module_list.Append(module_sp);
2400 target_sp->ModulesDidLoad (module_list);
Greg Clayton1f71bcf2013-01-29 01:17:09 +00002401 // Flush info in the process (stack frames, etc)
2402 ProcessSP process_sp (target_sp->GetProcessSP());
2403 if (process_sp)
2404 process_sp->Flush();
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002405 }
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002406 }
2407 }
Greg Clayton0416bdf2012-01-30 09:04:36 +00002408 else
2409 {
2410 sb_error.SetErrorStringWithFormat ("invalid module");
2411 }
2412
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002413 }
2414 else
2415 {
2416 sb_error.SetErrorStringWithFormat ("invalid target");
2417 }
2418 return sb_error;
2419}
2420
2421SBError
2422SBTarget::ClearModuleLoadAddress (lldb::SBModule module)
2423{
2424 SBError sb_error;
2425
2426 char path[PATH_MAX];
Greg Clayton0416bdf2012-01-30 09:04:36 +00002427 TargetSP target_sp(GetSP());
2428 if (target_sp)
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002429 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00002430 ModuleSP module_sp (module.GetSP());
2431 if (module_sp)
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002432 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00002433 ObjectFile *objfile = module_sp->GetObjectFile();
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002434 if (objfile)
2435 {
2436 SectionList *section_list = objfile->GetSectionList();
2437 if (section_list)
2438 {
Greg Clayton1f71bcf2013-01-29 01:17:09 +00002439 bool changed = false;
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002440 const size_t num_sections = section_list->GetSize();
2441 for (size_t sect_idx = 0; sect_idx < num_sections; ++sect_idx)
2442 {
2443 SectionSP section_sp (section_list->GetSectionAtIndex(sect_idx));
2444 if (section_sp)
Greg Clayton1f71bcf2013-01-29 01:17:09 +00002445 changed |= target_sp->GetSectionLoadList().SetSectionUnloaded (section_sp) > 0;
2446 }
2447 if (changed)
2448 {
2449 // Flush info in the process (stack frames, etc)
2450 ProcessSP process_sp (target_sp->GetProcessSP());
2451 if (process_sp)
2452 process_sp->Flush();
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002453 }
2454 }
2455 else
2456 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00002457 module_sp->GetFileSpec().GetPath (path, sizeof(path));
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002458 sb_error.SetErrorStringWithFormat ("no sections in object file '%s'", path);
2459 }
2460 }
2461 else
2462 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00002463 module_sp->GetFileSpec().GetPath (path, sizeof(path));
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002464 sb_error.SetErrorStringWithFormat ("no object file for module '%s'", path);
2465 }
2466 }
Greg Clayton0416bdf2012-01-30 09:04:36 +00002467 else
2468 {
2469 sb_error.SetErrorStringWithFormat ("invalid module");
2470 }
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002471 }
2472 else
2473 {
2474 sb_error.SetErrorStringWithFormat ("invalid target");
2475 }
2476 return sb_error;
2477}
2478
2479
Greg Claytonb3dafc62012-12-04 02:22:16 +00002480lldb::SBSymbolContextList
2481SBTarget::FindSymbols (const char *name, lldb::SymbolType symbol_type)
2482{
2483 SBSymbolContextList sb_sc_list;
2484 if (name && name[0])
2485 {
2486 TargetSP target_sp(GetSP());
2487 if (target_sp)
2488 {
2489 bool append = true;
2490 target_sp->GetImages().FindSymbolsWithNameAndType (ConstString(name),
2491 symbol_type,
2492 *sb_sc_list,
2493 append);
2494 }
2495 }
2496 return sb_sc_list;
2497
2498}
2499
2500
Greg Clayton19b64672013-01-04 18:10:18 +00002501lldb::SBValue
2502SBTarget::EvaluateExpression (const char *expr, const SBExpressionOptions &options)
2503{
2504 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
2505 LogSP expr_log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
2506 SBValue expr_result;
2507 ExecutionResults exe_results = eExecutionSetupError;
2508 ValueObjectSP expr_value_sp;
2509 TargetSP target_sp(GetSP());
2510 StackFrame *frame = NULL;
2511 if (target_sp)
2512 {
2513 if (expr == NULL || expr[0] == '\0')
2514 {
2515 if (log)
2516 log->Printf ("SBTarget::EvaluateExpression called with an empty expression");
2517 return expr_result;
2518 }
2519
2520 Mutex::Locker api_locker (target_sp->GetAPIMutex());
2521 ExecutionContext exe_ctx (m_opaque_sp.get());
2522
2523 if (log)
2524 log->Printf ("SBTarget()::EvaluateExpression (expr=\"%s\")...", expr);
2525
2526 frame = exe_ctx.GetFramePtr();
2527 Target *target = exe_ctx.GetTargetPtr();
2528
2529 if (target)
2530 {
2531#ifdef LLDB_CONFIGURATION_DEBUG
2532 StreamString frame_description;
2533 if (frame)
2534 frame->DumpUsingSettingsFormat (&frame_description);
2535 Host::SetCrashDescriptionWithFormat ("SBTarget::EvaluateExpression (expr = \"%s\", fetch_dynamic_value = %u) %s",
2536 expr, options.GetFetchDynamicValue(), frame_description.GetString().c_str());
2537#endif
2538 exe_results = target->EvaluateExpression (expr,
2539 frame,
2540 expr_value_sp,
2541 options.ref());
2542
2543 expr_result.SetSP(expr_value_sp, options.GetFetchDynamicValue());
2544#ifdef LLDB_CONFIGURATION_DEBUG
2545 Host::SetCrashDescription (NULL);
2546#endif
2547 }
2548 else
2549 {
2550 if (log)
2551 log->Printf ("SBTarget::EvaluateExpression () => error: could not reconstruct frame object for this SBTarget.");
2552 }
2553 }
2554#ifndef LLDB_DISABLE_PYTHON
2555 if (expr_log)
2556 expr_log->Printf("** [SBTarget::EvaluateExpression] Expression result is %s, summary %s **",
2557 expr_result.GetValue(),
2558 expr_result.GetSummary());
2559
2560 if (log)
2561 log->Printf ("SBTarget(%p)::EvaluateExpression (expr=\"%s\") => SBValue(%p) (execution result=%d)",
2562 frame,
2563 expr,
2564 expr_value_sp.get(),
2565 exe_results);
2566#endif
2567
2568 return expr_result;
2569}
2570
Greg Claytonad72e522013-02-01 00:47:49 +00002571
2572lldb::addr_t
2573SBTarget::GetStackRedZoneSize()
2574{
2575 TargetSP target_sp(GetSP());
2576 if (target_sp)
2577 {
2578 ABISP abi_sp;
2579 ProcessSP process_sp (target_sp->GetProcessSP());
2580 if (process_sp)
2581 abi_sp = process_sp->GetABI();
2582 else
2583 abi_sp = ABI::FindPlugin(target_sp->GetArchitecture());
2584 if (abi_sp)
2585 return abi_sp->GetRedZoneSize();
2586 }
2587 return 0;
2588}
2589