blob: 0ce361cb54db4ed0202c1bc4f0a2674ead7f615b [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"
Chris Lattner24943d22010-06-08 16:52:24 +000018#include "lldb/API/SBFileSpec.h"
Greg Clayton917c0002011-06-29 22:09:02 +000019#include "lldb/API/SBListener.h"
Chris Lattner24943d22010-06-08 16:52:24 +000020#include "lldb/API/SBModule.h"
Jim Inghamcc637462011-09-13 00:29:56 +000021#include "lldb/API/SBSourceManager.h"
Greg Clayton917c0002011-06-29 22:09:02 +000022#include "lldb/API/SBProcess.h"
Caroline Tice98f930f2010-09-20 05:20:02 +000023#include "lldb/API/SBStream.h"
Greg Clayton4ed315f2011-06-21 01:34:41 +000024#include "lldb/API/SBSymbolContextList.h"
Chris Lattner24943d22010-06-08 16:52:24 +000025#include "lldb/Breakpoint/BreakpointID.h"
26#include "lldb/Breakpoint/BreakpointIDList.h"
27#include "lldb/Breakpoint/BreakpointList.h"
28#include "lldb/Breakpoint/BreakpointLocation.h"
29#include "lldb/Core/Address.h"
30#include "lldb/Core/AddressResolver.h"
31#include "lldb/Core/AddressResolverName.h"
Chris Lattner24943d22010-06-08 16:52:24 +000032#include "lldb/Core/ArchSpec.h"
33#include "lldb/Core/Debugger.h"
34#include "lldb/Core/Disassembler.h"
Caroline Tice7826c882010-10-26 03:11:13 +000035#include "lldb/Core/Log.h"
Greg Clayton49ce8962012-08-29 21:13:06 +000036#include "lldb/Core/Module.h"
37#include "lldb/Core/ModuleSpec.h"
Chris Lattner24943d22010-06-08 16:52:24 +000038#include "lldb/Core/RegularExpression.h"
39#include "lldb/Core/SearchFilter.h"
Greg Clayton49ce8962012-08-29 21:13:06 +000040#include "lldb/Core/Section.h"
Chris Lattner24943d22010-06-08 16:52:24 +000041#include "lldb/Core/STLUtils.h"
Greg Clayton917c0002011-06-29 22:09:02 +000042#include "lldb/Core/ValueObjectList.h"
43#include "lldb/Core/ValueObjectVariable.h"
44#include "lldb/Host/FileSpec.h"
Greg Claytoncd548032011-02-01 01:31:41 +000045#include "lldb/Host/Host.h"
Greg Clayton917c0002011-06-29 22:09:02 +000046#include "lldb/Interpreter/Args.h"
Greg Clayton49ce8962012-08-29 21:13:06 +000047#include "lldb/Symbol/ObjectFile.h"
Enrico Granata979e20d2011-07-29 19:53:35 +000048#include "lldb/Symbol/SymbolVendor.h"
Greg Clayton917c0002011-06-29 22:09:02 +000049#include "lldb/Symbol/VariableList.h"
Jim Ingham4722b102012-03-06 00:37:27 +000050#include "lldb/Target/LanguageRuntime.h"
Chris Lattner24943d22010-06-08 16:52:24 +000051#include "lldb/Target/Process.h"
52#include "lldb/Target/Target.h"
53#include "lldb/Target/TargetList.h"
54
55#include "lldb/Interpreter/CommandReturnObject.h"
56#include "../source/Commands/CommandObjectBreakpoint.h"
57
Chris Lattner24943d22010-06-08 16:52:24 +000058
59using namespace lldb;
60using namespace lldb_private;
61
62#define DEFAULT_DISASM_BYTE_SIZE 32
63
Greg Clayton98ca1e62012-02-24 20:59:25 +000064SBLaunchInfo::SBLaunchInfo (const char **argv) :
65 m_opaque_sp(new ProcessLaunchInfo())
Greg Clayton0a8dcac2012-02-24 05:03:03 +000066{
Greg Clayton98ca1e62012-02-24 20:59:25 +000067 m_opaque_sp->GetFlags().Reset (eLaunchFlagDebug | eLaunchFlagDisableASLR);
68 if (argv && argv[0])
69 m_opaque_sp->GetArguments().SetArguments(argv);
Greg Clayton0a8dcac2012-02-24 05:03:03 +000070}
71
Greg Clayton66c2e192012-03-07 23:52:51 +000072SBLaunchInfo::~SBLaunchInfo()
73{
74}
75
76lldb_private::ProcessLaunchInfo &
77SBLaunchInfo::ref ()
78{
79 return *m_opaque_sp;
80}
81
82
Greg Clayton0a8dcac2012-02-24 05:03:03 +000083uint32_t
84SBLaunchInfo::GetUserID()
85{
86 return m_opaque_sp->GetUserID();
87}
88
89uint32_t
90SBLaunchInfo::GetGroupID()
91{
92 return m_opaque_sp->GetGroupID();
93}
94
95bool
96SBLaunchInfo::UserIDIsValid ()
97{
98 return m_opaque_sp->UserIDIsValid();
99}
100
101bool
102SBLaunchInfo::GroupIDIsValid ()
103{
104 return m_opaque_sp->GroupIDIsValid();
105}
106
107void
108SBLaunchInfo::SetUserID (uint32_t uid)
109{
110 m_opaque_sp->SetUserID (uid);
111}
112
113void
114SBLaunchInfo::SetGroupID (uint32_t gid)
115{
116 m_opaque_sp->SetGroupID (gid);
117}
118
Greg Clayton0a8dcac2012-02-24 05:03:03 +0000119uint32_t
120SBLaunchInfo::GetNumArguments ()
121{
122 return m_opaque_sp->GetArguments().GetArgumentCount();
123}
124
125const char *
126SBLaunchInfo::GetArgumentAtIndex (uint32_t idx)
127{
128 return m_opaque_sp->GetArguments().GetArgumentAtIndex(idx);
129}
130
131void
132SBLaunchInfo::SetArguments (const char **argv, bool append)
133{
134 if (append)
135 {
136 if (argv)
137 m_opaque_sp->GetArguments().AppendArguments(argv);
138 }
139 else
140 {
141 if (argv)
142 m_opaque_sp->GetArguments().SetArguments(argv);
143 else
144 m_opaque_sp->GetArguments().Clear();
145 }
146}
147
148uint32_t
149SBLaunchInfo::GetNumEnvironmentEntries ()
150{
151 return m_opaque_sp->GetEnvironmentEntries().GetArgumentCount();
152}
153
154const char *
155SBLaunchInfo::GetEnvironmentEntryAtIndex (uint32_t idx)
156{
157 return m_opaque_sp->GetEnvironmentEntries().GetArgumentAtIndex(idx);
158}
159
160void
161SBLaunchInfo::SetEnvironmentEntries (const char **envp, bool append)
162{
163 if (append)
164 {
165 if (envp)
166 m_opaque_sp->GetEnvironmentEntries().AppendArguments(envp);
167 }
168 else
169 {
170 if (envp)
171 m_opaque_sp->GetEnvironmentEntries().SetArguments(envp);
172 else
173 m_opaque_sp->GetEnvironmentEntries().Clear();
174 }
175}
176
177void
178SBLaunchInfo::Clear ()
179{
180 m_opaque_sp->Clear();
181}
182
183const char *
184SBLaunchInfo::GetWorkingDirectory () const
185{
186 return m_opaque_sp->GetWorkingDirectory();
187}
188
189void
190SBLaunchInfo::SetWorkingDirectory (const char *working_dir)
191{
192 m_opaque_sp->SetWorkingDirectory(working_dir);
193}
194
195uint32_t
196SBLaunchInfo::GetLaunchFlags ()
197{
198 return m_opaque_sp->GetFlags().Get();
199}
200
201void
202SBLaunchInfo::SetLaunchFlags (uint32_t flags)
203{
204 m_opaque_sp->GetFlags().Reset(flags);
205}
206
207const char *
208SBLaunchInfo::GetProcessPluginName ()
209{
210 return m_opaque_sp->GetProcessPluginName();
211}
212
213void
214SBLaunchInfo::SetProcessPluginName (const char *plugin_name)
215{
216 return m_opaque_sp->SetProcessPluginName (plugin_name);
217}
218
219const char *
220SBLaunchInfo::GetShell ()
221{
222 return m_opaque_sp->GetShell();
223}
224
225void
226SBLaunchInfo::SetShell (const char * path)
227{
228 m_opaque_sp->SetShell (path);
229}
230
231uint32_t
232SBLaunchInfo::GetResumeCount ()
233{
234 return m_opaque_sp->GetResumeCount();
235}
236
237void
238SBLaunchInfo::SetResumeCount (uint32_t c)
239{
240 m_opaque_sp->SetResumeCount (c);
241}
242
243bool
244SBLaunchInfo::AddCloseFileAction (int fd)
245{
246 return m_opaque_sp->AppendCloseFileAction(fd);
247}
248
249bool
250SBLaunchInfo::AddDuplicateFileAction (int fd, int dup_fd)
251{
252 return m_opaque_sp->AppendDuplicateFileAction(fd, dup_fd);
253}
254
255bool
256SBLaunchInfo::AddOpenFileAction (int fd, const char *path, bool read, bool write)
257{
258 return m_opaque_sp->AppendOpenFileAction(fd, path, read, write);
259}
260
261bool
262SBLaunchInfo::AddSuppressFileAction (int fd, bool read, bool write)
263{
264 return m_opaque_sp->AppendSuppressFileAction(fd, read, write);
265}
266
267
268SBAttachInfo::SBAttachInfo () :
Greg Clayton66c2e192012-03-07 23:52:51 +0000269 m_opaque_sp (new ProcessAttachInfo())
Greg Clayton0a8dcac2012-02-24 05:03:03 +0000270{
271}
272
273SBAttachInfo::SBAttachInfo (lldb::pid_t pid) :
Greg Clayton66c2e192012-03-07 23:52:51 +0000274 m_opaque_sp (new ProcessAttachInfo())
Greg Clayton0a8dcac2012-02-24 05:03:03 +0000275{
276 m_opaque_sp->SetProcessID (pid);
277}
278
279SBAttachInfo::SBAttachInfo (const char *path, bool wait_for) :
Greg Clayton66c2e192012-03-07 23:52:51 +0000280 m_opaque_sp (new ProcessAttachInfo())
Greg Clayton0a8dcac2012-02-24 05:03:03 +0000281{
282 if (path && path[0])
283 m_opaque_sp->GetExecutableFile().SetFile(path, false);
284 m_opaque_sp->SetWaitForLaunch (wait_for);
285}
286
287SBAttachInfo::SBAttachInfo (const SBAttachInfo &rhs) :
Greg Clayton66c2e192012-03-07 23:52:51 +0000288 m_opaque_sp (new ProcessAttachInfo())
Greg Clayton0a8dcac2012-02-24 05:03:03 +0000289{
290 *m_opaque_sp = *rhs.m_opaque_sp;
291}
292
Greg Clayton66c2e192012-03-07 23:52:51 +0000293SBAttachInfo::~SBAttachInfo()
294{
295}
296
297lldb_private::ProcessAttachInfo &
298SBAttachInfo::ref ()
299{
300 return *m_opaque_sp;
301}
302
Greg Clayton0a8dcac2012-02-24 05:03:03 +0000303SBAttachInfo &
304SBAttachInfo::operator = (const SBAttachInfo &rhs)
305{
306 if (this != &rhs)
307 *m_opaque_sp = *rhs.m_opaque_sp;
308 return *this;
309}
310
311lldb::pid_t
312SBAttachInfo::GetProcessID ()
313{
314 return m_opaque_sp->GetProcessID();
315}
316
317void
318SBAttachInfo::SetProcessID (lldb::pid_t pid)
319{
320 m_opaque_sp->SetProcessID (pid);
321}
322
323
324uint32_t
325SBAttachInfo::GetResumeCount ()
326{
327 return m_opaque_sp->GetResumeCount();
328}
329
330void
331SBAttachInfo::SetResumeCount (uint32_t c)
332{
333 m_opaque_sp->SetResumeCount (c);
334}
335
336const char *
337SBAttachInfo::GetProcessPluginName ()
338{
339 return m_opaque_sp->GetProcessPluginName();
340}
341
342void
343SBAttachInfo::SetProcessPluginName (const char *plugin_name)
344{
345 return m_opaque_sp->SetProcessPluginName (plugin_name);
346}
347
348void
349SBAttachInfo::SetExecutable (const char *path)
350{
351 if (path && path[0])
352 m_opaque_sp->GetExecutableFile().SetFile(path, false);
353 else
354 m_opaque_sp->GetExecutableFile().Clear();
355}
356
357void
358SBAttachInfo::SetExecutable (SBFileSpec exe_file)
359{
360 if (exe_file.IsValid())
361 m_opaque_sp->GetExecutableFile() = exe_file.ref();
362 else
363 m_opaque_sp->GetExecutableFile().Clear();
364}
365
366bool
367SBAttachInfo::GetWaitForLaunch ()
368{
369 return m_opaque_sp->GetWaitForLaunch();
370}
371
372void
373SBAttachInfo::SetWaitForLaunch (bool b)
374{
375 m_opaque_sp->SetWaitForLaunch (b);
376}
377
Jim Ingham3a458eb2012-07-20 21:37:13 +0000378bool
379SBAttachInfo::GetIgnoreExisting ()
380{
381 return m_opaque_sp->GetIgnoreExisting();
382}
383
384void
385SBAttachInfo::SetIgnoreExisting (bool b)
386{
387 m_opaque_sp->SetIgnoreExisting (b);
388}
389
Greg Clayton0a8dcac2012-02-24 05:03:03 +0000390uint32_t
Greg Clayton80efa5e2012-02-24 23:56:06 +0000391SBAttachInfo::GetUserID()
392{
393 return m_opaque_sp->GetUserID();
394}
395
396uint32_t
397SBAttachInfo::GetGroupID()
398{
399 return m_opaque_sp->GetGroupID();
400}
401
402bool
403SBAttachInfo::UserIDIsValid ()
404{
405 return m_opaque_sp->UserIDIsValid();
406}
407
408bool
409SBAttachInfo::GroupIDIsValid ()
410{
411 return m_opaque_sp->GroupIDIsValid();
412}
413
414void
415SBAttachInfo::SetUserID (uint32_t uid)
416{
417 m_opaque_sp->SetUserID (uid);
418}
419
420void
421SBAttachInfo::SetGroupID (uint32_t gid)
422{
423 m_opaque_sp->SetGroupID (gid);
424}
425
426uint32_t
Greg Clayton0a8dcac2012-02-24 05:03:03 +0000427SBAttachInfo::GetEffectiveUserID()
428{
429 return m_opaque_sp->GetEffectiveUserID();
430}
431
432uint32_t
433SBAttachInfo::GetEffectiveGroupID()
434{
435 return m_opaque_sp->GetEffectiveGroupID();
436}
437
438bool
439SBAttachInfo::EffectiveUserIDIsValid ()
440{
441 return m_opaque_sp->EffectiveUserIDIsValid();
442}
443
444bool
445SBAttachInfo::EffectiveGroupIDIsValid ()
446{
447 return m_opaque_sp->EffectiveGroupIDIsValid ();
448}
449
450void
451SBAttachInfo::SetEffectiveUserID (uint32_t uid)
452{
453 m_opaque_sp->SetEffectiveUserID(uid);
454}
455
456void
457SBAttachInfo::SetEffectiveGroupID (uint32_t gid)
458{
459 m_opaque_sp->SetEffectiveGroupID(gid);
460}
461
462lldb::pid_t
463SBAttachInfo::GetParentProcessID ()
464{
465 return m_opaque_sp->GetParentProcessID();
466}
467
468void
469SBAttachInfo::SetParentProcessID (lldb::pid_t pid)
470{
471 m_opaque_sp->SetParentProcessID (pid);
472}
473
474bool
475SBAttachInfo::ParentProcessIDIsValid()
476{
477 return m_opaque_sp->ParentProcessIDIsValid();
478}
479
480
Chris Lattner24943d22010-06-08 16:52:24 +0000481//----------------------------------------------------------------------
482// SBTarget constructor
483//----------------------------------------------------------------------
Greg Claytonc3b61d22010-12-15 05:08:08 +0000484SBTarget::SBTarget () :
485 m_opaque_sp ()
Chris Lattner24943d22010-06-08 16:52:24 +0000486{
487}
488
489SBTarget::SBTarget (const SBTarget& rhs) :
Greg Clayton63094e02010-06-23 01:19:29 +0000490 m_opaque_sp (rhs.m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000491{
492}
493
494SBTarget::SBTarget(const TargetSP& target_sp) :
Greg Clayton63094e02010-06-23 01:19:29 +0000495 m_opaque_sp (target_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000496{
497}
498
Greg Clayton538eb822010-11-05 23:17:00 +0000499const SBTarget&
500SBTarget::operator = (const SBTarget& rhs)
501{
502 if (this != &rhs)
503 m_opaque_sp = rhs.m_opaque_sp;
504 return *this;
505}
506
Chris Lattner24943d22010-06-08 16:52:24 +0000507//----------------------------------------------------------------------
508// Destructor
509//----------------------------------------------------------------------
510SBTarget::~SBTarget()
511{
512}
513
Jim Ingham5a15e692012-02-16 06:50:00 +0000514const char *
515SBTarget::GetBroadcasterClassName ()
516{
517 return Target::GetStaticBroadcasterClass().AsCString();
518}
519
Chris Lattner24943d22010-06-08 16:52:24 +0000520bool
521SBTarget::IsValid () const
522{
Filipe Cabecinhasf7d782b2012-05-19 09:59:08 +0000523 return m_opaque_sp.get() != NULL && m_opaque_sp->IsValid();
Chris Lattner24943d22010-06-08 16:52:24 +0000524}
525
526SBProcess
527SBTarget::GetProcess ()
528{
529 SBProcess sb_process;
Greg Clayton334d33a2012-01-30 07:41:31 +0000530 ProcessSP process_sp;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000531 TargetSP target_sp(GetSP());
532 if (target_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000533 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000534 process_sp = target_sp->GetProcessSP();
Greg Clayton334d33a2012-01-30 07:41:31 +0000535 sb_process.SetSP (process_sp);
Greg Claytonbdcda462010-12-20 20:49:23 +0000536 }
Caroline Tice7826c882010-10-26 03:11:13 +0000537
Greg Claytone005f2c2010-11-06 01:53:30 +0000538 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000539 if (log)
540 {
Greg Clayton49ce6822010-10-31 03:01:06 +0000541 log->Printf ("SBTarget(%p)::GetProcess () => SBProcess(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +0000542 target_sp.get(), process_sp.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000543 }
544
Chris Lattner24943d22010-06-08 16:52:24 +0000545 return sb_process;
546}
547
Greg Clayton63094e02010-06-23 01:19:29 +0000548SBDebugger
549SBTarget::GetDebugger () const
550{
551 SBDebugger debugger;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000552 TargetSP target_sp(GetSP());
553 if (target_sp)
554 debugger.reset (target_sp->GetDebugger().shared_from_this());
Greg Clayton63094e02010-06-23 01:19:29 +0000555 return debugger;
556}
557
Jim Inghamb5871fe2011-03-31 00:01:24 +0000558SBProcess
559SBTarget::LaunchSimple
560(
561 char const **argv,
562 char const **envp,
563 const char *working_directory
564)
565{
566 char *stdin_path = NULL;
567 char *stdout_path = NULL;
568 char *stderr_path = NULL;
569 uint32_t launch_flags = 0;
570 bool stop_at_entry = false;
571 SBError error;
572 SBListener listener = GetDebugger().GetListener();
573 return Launch (listener,
574 argv,
575 envp,
576 stdin_path,
577 stdout_path,
578 stderr_path,
579 working_directory,
580 launch_flags,
581 stop_at_entry,
582 error);
583}
Greg Claytonde915be2011-01-23 05:56:20 +0000584
585SBProcess
586SBTarget::Launch
587(
Greg Clayton271a5db2011-02-03 21:28:34 +0000588 SBListener &listener,
Greg Claytonde915be2011-01-23 05:56:20 +0000589 char const **argv,
590 char const **envp,
591 const char *stdin_path,
592 const char *stdout_path,
593 const char *stderr_path,
594 const char *working_directory,
595 uint32_t launch_flags, // See LaunchFlags
596 bool stop_at_entry,
597 lldb::SBError& error
598)
599{
Greg Claytone005f2c2010-11-06 01:53:30 +0000600 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000601
Greg Clayton0416bdf2012-01-30 09:04:36 +0000602 SBProcess sb_process;
603 ProcessSP process_sp;
604 TargetSP target_sp(GetSP());
605
Caroline Tice7826c882010-10-26 03:11:13 +0000606 if (log)
Greg Clayton3f5ee7f2010-10-29 04:59:35 +0000607 {
Greg Claytonde915be2011-01-23 05:56:20 +0000608 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 +0000609 target_sp.get(),
Greg Claytonde915be2011-01-23 05:56:20 +0000610 argv,
611 envp,
612 stdin_path ? stdin_path : "NULL",
613 stdout_path ? stdout_path : "NULL",
614 stderr_path ? stderr_path : "NULL",
615 working_directory ? working_directory : "NULL",
616 launch_flags,
617 stop_at_entry,
618 error.get());
Greg Clayton3f5ee7f2010-10-29 04:59:35 +0000619 }
Greg Clayton0416bdf2012-01-30 09:04:36 +0000620
621 if (target_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000622 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000623 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton1a3083a2010-10-06 03:53:16 +0000624
Greg Clayton7c330d62011-01-27 01:01:10 +0000625 if (getenv("LLDB_LAUNCH_FLAG_DISABLE_ASLR"))
626 launch_flags |= eLaunchFlagDisableASLR;
627
Greg Clayton180546b2011-04-30 01:09:13 +0000628 StateType state = eStateInvalid;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000629 process_sp = target_sp->GetProcessSP();
Greg Clayton334d33a2012-01-30 07:41:31 +0000630 if (process_sp)
Greg Clayton28d5fcc2011-01-27 06:44:37 +0000631 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000632 state = process_sp->GetState();
Greg Clayton180546b2011-04-30 01:09:13 +0000633
Greg Clayton334d33a2012-01-30 07:41:31 +0000634 if (process_sp->IsAlive() && state != eStateConnected)
Greg Clayton180546b2011-04-30 01:09:13 +0000635 {
636 if (state == eStateAttaching)
637 error.SetErrorString ("process attach is in progress");
638 else
639 error.SetErrorString ("a process is already being debugged");
Greg Clayton180546b2011-04-30 01:09:13 +0000640 return sb_process;
641 }
Greg Clayton28d5fcc2011-01-27 06:44:37 +0000642 }
643
Greg Clayton180546b2011-04-30 01:09:13 +0000644 if (state == eStateConnected)
645 {
646 // If we are already connected, then we have already specified the
647 // listener, so if a valid listener is supplied, we need to error out
648 // to let the client know.
649 if (listener.IsValid())
650 {
651 error.SetErrorString ("process is connected and already has a listener, pass empty listener");
Greg Clayton180546b2011-04-30 01:09:13 +0000652 return sb_process;
653 }
654 }
655 else
Greg Claytonc5f728c2010-10-06 22:10:17 +0000656 {
Greg Clayton271a5db2011-02-03 21:28:34 +0000657 if (listener.IsValid())
Greg Clayton46c9a352012-02-09 06:16:32 +0000658 process_sp = target_sp->CreateProcess (listener.ref(), NULL, NULL);
Greg Clayton271a5db2011-02-03 21:28:34 +0000659 else
Greg Clayton46c9a352012-02-09 06:16:32 +0000660 process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener(), NULL, NULL);
Greg Clayton180546b2011-04-30 01:09:13 +0000661 }
Greg Clayton7c330d62011-01-27 01:01:10 +0000662
Greg Clayton334d33a2012-01-30 07:41:31 +0000663 if (process_sp)
Greg Clayton180546b2011-04-30 01:09:13 +0000664 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000665 sb_process.SetSP (process_sp);
Greg Clayton180546b2011-04-30 01:09:13 +0000666 if (getenv("LLDB_LAUNCH_FLAG_DISABLE_STDIO"))
667 launch_flags |= eLaunchFlagDisableSTDIO;
668
Greg Clayton36bc5ea2011-11-03 21:22:33 +0000669 ProcessLaunchInfo launch_info (stdin_path, stdout_path, stderr_path, working_directory, launch_flags);
670
Greg Clayton0416bdf2012-01-30 09:04:36 +0000671 Module *exe_module = target_sp->GetExecutableModulePointer();
Greg Clayton36bc5ea2011-11-03 21:22:33 +0000672 if (exe_module)
Greg Clayton1d1f39e2011-11-29 04:03:30 +0000673 launch_info.SetExecutableFile(exe_module->GetPlatformFileSpec(), true);
Greg Clayton36bc5ea2011-11-03 21:22:33 +0000674 if (argv)
675 launch_info.GetArguments().AppendArguments (argv);
676 if (envp)
677 launch_info.GetEnvironmentEntries ().SetArguments (envp);
678
Greg Clayton334d33a2012-01-30 07:41:31 +0000679 error.SetError (process_sp->Launch (launch_info));
Greg Clayton180546b2011-04-30 01:09:13 +0000680 if (error.Success())
Greg Clayton7c330d62011-01-27 01:01:10 +0000681 {
Greg Clayton180546b2011-04-30 01:09:13 +0000682 // We we are stopping at the entry point, we can return now!
683 if (stop_at_entry)
684 return sb_process;
Greg Clayton7c330d62011-01-27 01:01:10 +0000685
Greg Clayton180546b2011-04-30 01:09:13 +0000686 // Make sure we are stopped at the entry
Greg Clayton334d33a2012-01-30 07:41:31 +0000687 StateType state = process_sp->WaitForProcessToStop (NULL);
Greg Clayton180546b2011-04-30 01:09:13 +0000688 if (state == eStateStopped)
Greg Clayton7c330d62011-01-27 01:01:10 +0000689 {
Greg Clayton180546b2011-04-30 01:09:13 +0000690 // resume the process to skip the entry point
Greg Clayton334d33a2012-01-30 07:41:31 +0000691 error.SetError (process_sp->Resume());
Greg Clayton180546b2011-04-30 01:09:13 +0000692 if (error.Success())
Greg Clayton7c330d62011-01-27 01:01:10 +0000693 {
Greg Clayton180546b2011-04-30 01:09:13 +0000694 // If we are doing synchronous mode, then wait for the
695 // process to stop yet again!
Greg Clayton0416bdf2012-01-30 09:04:36 +0000696 if (target_sp->GetDebugger().GetAsyncExecution () == false)
Greg Clayton334d33a2012-01-30 07:41:31 +0000697 process_sp->WaitForProcessToStop (NULL);
Greg Clayton7c330d62011-01-27 01:01:10 +0000698 }
699 }
700 }
Greg Clayton180546b2011-04-30 01:09:13 +0000701 }
702 else
703 {
704 error.SetErrorString ("unable to create lldb_private::Process");
Greg Claytonc5f728c2010-10-06 22:10:17 +0000705 }
706 }
707 else
708 {
709 error.SetErrorString ("SBTarget is invalid");
Chris Lattner24943d22010-06-08 16:52:24 +0000710 }
Caroline Tice7826c882010-10-26 03:11:13 +0000711
Caroline Tice926060e2010-10-29 21:48:37 +0000712 log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
Caroline Tice7826c882010-10-26 03:11:13 +0000713 if (log)
714 {
Sean Callanan4e846742012-10-20 00:21:31 +0000715 log->Printf ("SBTarget(%p)::Launch (...) => SBProcess(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +0000716 target_sp.get(), process_sp.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000717 }
718
Greg Clayton1a3083a2010-10-06 03:53:16 +0000719 return sb_process;
Chris Lattner24943d22010-06-08 16:52:24 +0000720}
721
Greg Clayton0a8dcac2012-02-24 05:03:03 +0000722SBProcess
723SBTarget::Launch (SBLaunchInfo &sb_launch_info, SBError& error)
724{
725 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
726
727 SBProcess sb_process;
728 ProcessSP process_sp;
729 TargetSP target_sp(GetSP());
730
731 if (log)
732 {
733 log->Printf ("SBTarget(%p)::Launch (launch_info, error)...", target_sp.get());
734 }
735
736 if (target_sp)
737 {
738 Mutex::Locker api_locker (target_sp->GetAPIMutex());
739 StateType state = eStateInvalid;
740 process_sp = target_sp->GetProcessSP();
741 if (process_sp)
742 {
743 state = process_sp->GetState();
744
745 if (process_sp->IsAlive() && state != eStateConnected)
746 {
747 if (state == eStateAttaching)
748 error.SetErrorString ("process attach is in progress");
749 else
750 error.SetErrorString ("a process is already being debugged");
751 return sb_process;
752 }
753 }
754
755 if (state != eStateConnected)
756 process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener(), NULL, NULL);
757
758 if (process_sp)
759 {
760 sb_process.SetSP (process_sp);
761 lldb_private::ProcessLaunchInfo &launch_info = sb_launch_info.ref();
Greg Clayton98ca1e62012-02-24 20:59:25 +0000762
Greg Clayton98ca1e62012-02-24 20:59:25 +0000763 Module *exe_module = target_sp->GetExecutableModulePointer();
764 if (exe_module)
Han Ming Ongc86723f2012-03-02 01:02:04 +0000765 launch_info.SetExecutableFile(exe_module->GetPlatformFileSpec(), true);
Greg Clayton98ca1e62012-02-24 20:59:25 +0000766
767 const ArchSpec &arch_spec = target_sp->GetArchitecture();
768 if (arch_spec.IsValid())
769 launch_info.GetArchitecture () = arch_spec;
770
Greg Clayton0a8dcac2012-02-24 05:03:03 +0000771 error.SetError (process_sp->Launch (launch_info));
Greg Clayton98ca1e62012-02-24 20:59:25 +0000772 const bool synchronous_execution = target_sp->GetDebugger().GetAsyncExecution () == false;
Greg Clayton0a8dcac2012-02-24 05:03:03 +0000773 if (error.Success())
774 {
Greg Clayton0a8dcac2012-02-24 05:03:03 +0000775 if (launch_info.GetFlags().Test(eLaunchFlagStopAtEntry))
Greg Clayton98ca1e62012-02-24 20:59:25 +0000776 {
777 // If we are doing synchronous mode, then wait for the initial
778 // stop to happen, else, return and let the caller watch for
779 // the stop
780 if (synchronous_execution)
Greg Clayton4a379b12012-07-17 03:23:13 +0000781 process_sp->WaitForProcessToStop (NULL);
Greg Clayton98ca1e62012-02-24 20:59:25 +0000782 // We we are stopping at the entry point, we can return now!
Greg Clayton0a8dcac2012-02-24 05:03:03 +0000783 return sb_process;
Greg Clayton98ca1e62012-02-24 20:59:25 +0000784 }
Greg Clayton0a8dcac2012-02-24 05:03:03 +0000785
786 // Make sure we are stopped at the entry
Greg Clayton4a379b12012-07-17 03:23:13 +0000787 StateType state = process_sp->WaitForProcessToStop (NULL);
Greg Clayton0a8dcac2012-02-24 05:03:03 +0000788 if (state == eStateStopped)
789 {
790 // resume the process to skip the entry point
791 error.SetError (process_sp->Resume());
792 if (error.Success())
793 {
794 // If we are doing synchronous mode, then wait for the
795 // process to stop yet again!
Greg Clayton98ca1e62012-02-24 20:59:25 +0000796 if (synchronous_execution)
Greg Clayton0a8dcac2012-02-24 05:03:03 +0000797 process_sp->WaitForProcessToStop (NULL);
798 }
799 }
800 }
801 }
802 else
803 {
804 error.SetErrorString ("unable to create lldb_private::Process");
805 }
806 }
807 else
808 {
809 error.SetErrorString ("SBTarget is invalid");
810 }
811
812 log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
813 if (log)
814 {
Sean Callanan4e846742012-10-20 00:21:31 +0000815 log->Printf ("SBTarget(%p)::Launch (...) => SBProcess(%p)",
Greg Clayton0a8dcac2012-02-24 05:03:03 +0000816 target_sp.get(), process_sp.get());
817 }
818
819 return sb_process;
820}
821
822lldb::SBProcess
823SBTarget::Attach (SBAttachInfo &sb_attach_info, SBError& error)
824{
Sean Callanan4e846742012-10-20 00:21:31 +0000825 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
826
Greg Clayton0a8dcac2012-02-24 05:03:03 +0000827 SBProcess sb_process;
828 ProcessSP process_sp;
829 TargetSP target_sp(GetSP());
Sean Callanan4e846742012-10-20 00:21:31 +0000830
831 if (log)
832 {
833 log->Printf ("SBTarget(%p)::Attach (sb_attach_info, error)...", target_sp.get());
834 }
835
Greg Clayton0a8dcac2012-02-24 05:03:03 +0000836 if (target_sp)
837 {
838 Mutex::Locker api_locker (target_sp->GetAPIMutex());
839
840 StateType state = eStateInvalid;
841 process_sp = target_sp->GetProcessSP();
842 if (process_sp)
843 {
844 state = process_sp->GetState();
845
846 if (process_sp->IsAlive() && state != eStateConnected)
847 {
848 if (state == eStateAttaching)
849 error.SetErrorString ("process attach is in progress");
850 else
851 error.SetErrorString ("a process is already being debugged");
Sean Callanan4e846742012-10-20 00:21:31 +0000852 if (log)
853 {
854 log->Printf ("SBTarget(%p)::Attach (...) => error %s",
855 target_sp.get(), error.GetCString());
856 }
Greg Clayton0a8dcac2012-02-24 05:03:03 +0000857 return sb_process;
858 }
859 }
860
861 if (state != eStateConnected)
862 process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener(), NULL, NULL);
863
864 if (process_sp)
865 {
Greg Clayton0a8dcac2012-02-24 05:03:03 +0000866 ProcessAttachInfo &attach_info = sb_attach_info.ref();
Han Ming Ong435c5ef2012-02-29 00:12:56 +0000867 lldb::pid_t attach_pid = attach_info.GetProcessID();
868 if (attach_pid != LLDB_INVALID_PROCESS_ID)
869 {
870 PlatformSP platform_sp = target_sp->GetPlatform();
Greg Clayton02fac1c2012-09-27 00:03:39 +0000871 // See if we can pre-verify if a process exists or not
872 if (platform_sp && platform_sp->IsConnected())
Han Ming Ong435c5ef2012-02-29 00:12:56 +0000873 {
Greg Clayton02fac1c2012-09-27 00:03:39 +0000874 ProcessInstanceInfo instance_info;
875 if (platform_sp->GetProcessInfo(attach_pid, instance_info))
876 {
877 attach_info.SetUserID(instance_info.GetEffectiveUserID());
878 }
879 else
880 {
Daniel Malea5f35a4b2012-11-29 21:49:15 +0000881 error.ref().SetErrorStringWithFormat("no process found with process ID %" PRIu64, attach_pid);
Sean Callanan4e846742012-10-20 00:21:31 +0000882 if (log)
883 {
884 log->Printf ("SBTarget(%p)::Attach (...) => error %s",
885 target_sp.get(), error.GetCString());
886 }
Greg Clayton02fac1c2012-09-27 00:03:39 +0000887 return sb_process;
888 }
Han Ming Ong435c5ef2012-02-29 00:12:56 +0000889 }
890 }
Han Ming Ong94b4e9a2012-02-29 19:16:40 +0000891 error.SetError (process_sp->Attach (attach_info));
892 if (error.Success())
893 {
894 sb_process.SetSP (process_sp);
895 // If we are doing synchronous mode, then wait for the
896 // process to stop!
897 if (target_sp->GetDebugger().GetAsyncExecution () == false)
898 process_sp->WaitForProcessToStop (NULL);
899 }
Greg Clayton0a8dcac2012-02-24 05:03:03 +0000900 }
901 else
902 {
903 error.SetErrorString ("unable to create lldb_private::Process");
904 }
905 }
906 else
907 {
908 error.SetErrorString ("SBTarget is invalid");
909 }
Sean Callanan4e846742012-10-20 00:21:31 +0000910
911 if (log)
912 {
913 log->Printf ("SBTarget(%p)::Attach (...) => SBProcess(%p)",
914 target_sp.get(), process_sp.get());
915 }
916
Greg Clayton0a8dcac2012-02-24 05:03:03 +0000917 return sb_process;
918}
919
920
Greg Claytond5b0b442011-12-02 02:10:57 +0000921#if defined(__APPLE__)
922
923lldb::SBProcess
924SBTarget::AttachToProcessWithID (SBListener &listener,
925 ::pid_t pid,
926 lldb::SBError& error)
927{
928 return AttachToProcessWithID (listener, (lldb::pid_t)pid, error);
929}
930
931#endif // #if defined(__APPLE__)
Greg Claytonc5f728c2010-10-06 22:10:17 +0000932
933lldb::SBProcess
Greg Claytond8c62532010-10-07 04:19:01 +0000934SBTarget::AttachToProcessWithID
Greg Claytonc5f728c2010-10-06 22:10:17 +0000935(
Greg Clayton271a5db2011-02-03 21:28:34 +0000936 SBListener &listener,
Greg Claytonc5f728c2010-10-06 22:10:17 +0000937 lldb::pid_t pid,// The process ID to attach to
938 SBError& error // An error explaining what went wrong if attach fails
939)
940{
Sean Callanan4e846742012-10-20 00:21:31 +0000941 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
942
Greg Claytonc5f728c2010-10-06 22:10:17 +0000943 SBProcess sb_process;
Greg Clayton334d33a2012-01-30 07:41:31 +0000944 ProcessSP process_sp;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000945 TargetSP target_sp(GetSP());
Sean Callanan4e846742012-10-20 00:21:31 +0000946
947 if (log)
948 {
Daniel Malea5f35a4b2012-11-29 21:49:15 +0000949 log->Printf ("SBTarget(%p)::AttachToProcessWithID (listener, pid=%" PRId64 ", error)...", target_sp.get(), pid);
Sean Callanan4e846742012-10-20 00:21:31 +0000950 }
951
Greg Clayton0416bdf2012-01-30 09:04:36 +0000952 if (target_sp)
Greg Claytonc5f728c2010-10-06 22:10:17 +0000953 {
Greg Clayton0416bdf2012-01-30 09:04:36 +0000954 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytonde1dd812011-06-24 03:21:43 +0000955
956 StateType state = eStateInvalid;
Greg Clayton0416bdf2012-01-30 09:04:36 +0000957 process_sp = target_sp->GetProcessSP();
Greg Clayton334d33a2012-01-30 07:41:31 +0000958 if (process_sp)
Greg Claytonde1dd812011-06-24 03:21:43 +0000959 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000960 state = process_sp->GetState();
Greg Claytonde1dd812011-06-24 03:21:43 +0000961
Greg Clayton334d33a2012-01-30 07:41:31 +0000962 if (process_sp->IsAlive() && state != eStateConnected)
Greg Claytonde1dd812011-06-24 03:21:43 +0000963 {
964 if (state == eStateAttaching)
965 error.SetErrorString ("process attach is in progress");
966 else
967 error.SetErrorString ("a process is already being debugged");
Greg Claytonde1dd812011-06-24 03:21:43 +0000968 return sb_process;
969 }
970 }
971
972 if (state == eStateConnected)
973 {
974 // If we are already connected, then we have already specified the
975 // listener, so if a valid listener is supplied, we need to error out
976 // to let the client know.
977 if (listener.IsValid())
978 {
979 error.SetErrorString ("process is connected and already has a listener, pass empty listener");
Greg Claytonde1dd812011-06-24 03:21:43 +0000980 return sb_process;
981 }
982 }
Greg Clayton271a5db2011-02-03 21:28:34 +0000983 else
Greg Claytonde1dd812011-06-24 03:21:43 +0000984 {
985 if (listener.IsValid())
Greg Clayton46c9a352012-02-09 06:16:32 +0000986 process_sp = target_sp->CreateProcess (listener.ref(), NULL, NULL);
Greg Claytonde1dd812011-06-24 03:21:43 +0000987 else
Greg Clayton46c9a352012-02-09 06:16:32 +0000988 process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener(), NULL, NULL);
Greg Claytonde1dd812011-06-24 03:21:43 +0000989 }
Greg Clayton334d33a2012-01-30 07:41:31 +0000990 if (process_sp)
Greg Claytonc5f728c2010-10-06 22:10:17 +0000991 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000992 sb_process.SetSP (process_sp);
993
Greg Clayton527154d2011-11-15 03:53:30 +0000994 ProcessAttachInfo attach_info;
995 attach_info.SetProcessID (pid);
Han Ming Ongd1040dd2012-02-25 01:07:38 +0000996
997 PlatformSP platform_sp = target_sp->GetPlatform();
998 ProcessInstanceInfo instance_info;
999 if (platform_sp->GetProcessInfo(pid, instance_info))
1000 {
1001 attach_info.SetUserID(instance_info.GetEffectiveUserID());
Han Ming Ongd1040dd2012-02-25 01:07:38 +00001002 }
Greg Clayton334d33a2012-01-30 07:41:31 +00001003 error.SetError (process_sp->Attach (attach_info));
Greg Claytonc6430772012-09-07 17:51:47 +00001004 if (error.Success())
1005 {
1006 // If we are doing synchronous mode, then wait for the
1007 // process to stop!
1008 if (target_sp->GetDebugger().GetAsyncExecution () == false)
Greg Clayton334d33a2012-01-30 07:41:31 +00001009 process_sp->WaitForProcessToStop (NULL);
Greg Claytonc6430772012-09-07 17:51:47 +00001010 }
Greg Claytonc5f728c2010-10-06 22:10:17 +00001011 }
1012 else
1013 {
1014 error.SetErrorString ("unable to create lldb_private::Process");
1015 }
1016 }
1017 else
1018 {
1019 error.SetErrorString ("SBTarget is invalid");
1020 }
Sean Callanan4e846742012-10-20 00:21:31 +00001021
1022 if (log)
1023 {
1024 log->Printf ("SBTarget(%p)::AttachToProcessWithID (...) => SBProcess(%p)",
1025 target_sp.get(), process_sp.get());
1026 }
Greg Claytonc5f728c2010-10-06 22:10:17 +00001027 return sb_process;
Greg Claytonc5f728c2010-10-06 22:10:17 +00001028}
1029
1030lldb::SBProcess
Greg Claytond8c62532010-10-07 04:19:01 +00001031SBTarget::AttachToProcessWithName
Greg Claytonc5f728c2010-10-06 22:10:17 +00001032(
Greg Clayton271a5db2011-02-03 21:28:34 +00001033 SBListener &listener,
Greg Claytonc5f728c2010-10-06 22:10:17 +00001034 const char *name, // basename of process to attach to
1035 bool wait_for, // if true wait for a new instance of "name" to be launched
1036 SBError& error // An error explaining what went wrong if attach fails
1037)
1038{
Sean Callanan4e846742012-10-20 00:21:31 +00001039 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1040
Greg Claytonc5f728c2010-10-06 22:10:17 +00001041 SBProcess sb_process;
Greg Clayton334d33a2012-01-30 07:41:31 +00001042 ProcessSP process_sp;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001043 TargetSP target_sp(GetSP());
Sean Callanan4e846742012-10-20 00:21:31 +00001044
1045 if (log)
1046 {
1047 log->Printf ("SBTarget(%p)::AttachToProcessWithName (listener, name=%s, wait_for=%s, error)...", target_sp.get(), name, wait_for ? "true" : "false");
1048 }
1049
Greg Clayton0416bdf2012-01-30 09:04:36 +00001050 if (name && target_sp)
Greg Claytonc5f728c2010-10-06 22:10:17 +00001051 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001052 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytonbdcda462010-12-20 20:49:23 +00001053
Greg Claytonde1dd812011-06-24 03:21:43 +00001054 StateType state = eStateInvalid;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001055 process_sp = target_sp->GetProcessSP();
Greg Clayton334d33a2012-01-30 07:41:31 +00001056 if (process_sp)
Greg Claytonde1dd812011-06-24 03:21:43 +00001057 {
Greg Clayton334d33a2012-01-30 07:41:31 +00001058 state = process_sp->GetState();
Greg Claytonde1dd812011-06-24 03:21:43 +00001059
Greg Clayton334d33a2012-01-30 07:41:31 +00001060 if (process_sp->IsAlive() && state != eStateConnected)
Greg Claytonde1dd812011-06-24 03:21:43 +00001061 {
1062 if (state == eStateAttaching)
1063 error.SetErrorString ("process attach is in progress");
1064 else
1065 error.SetErrorString ("a process is already being debugged");
Greg Claytonde1dd812011-06-24 03:21:43 +00001066 return sb_process;
1067 }
1068 }
1069
1070 if (state == eStateConnected)
1071 {
1072 // If we are already connected, then we have already specified the
1073 // listener, so if a valid listener is supplied, we need to error out
1074 // to let the client know.
1075 if (listener.IsValid())
1076 {
1077 error.SetErrorString ("process is connected and already has a listener, pass empty listener");
Greg Claytonde1dd812011-06-24 03:21:43 +00001078 return sb_process;
1079 }
1080 }
Greg Clayton271a5db2011-02-03 21:28:34 +00001081 else
Greg Claytonde1dd812011-06-24 03:21:43 +00001082 {
1083 if (listener.IsValid())
Greg Clayton46c9a352012-02-09 06:16:32 +00001084 process_sp = target_sp->CreateProcess (listener.ref(), NULL, NULL);
Greg Claytonde1dd812011-06-24 03:21:43 +00001085 else
Greg Clayton46c9a352012-02-09 06:16:32 +00001086 process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener(), NULL, NULL);
Greg Claytonde1dd812011-06-24 03:21:43 +00001087 }
Greg Claytonc5f728c2010-10-06 22:10:17 +00001088
Greg Clayton334d33a2012-01-30 07:41:31 +00001089 if (process_sp)
Greg Claytonc5f728c2010-10-06 22:10:17 +00001090 {
Greg Clayton334d33a2012-01-30 07:41:31 +00001091 sb_process.SetSP (process_sp);
Greg Clayton527154d2011-11-15 03:53:30 +00001092 ProcessAttachInfo attach_info;
1093 attach_info.GetExecutableFile().SetFile(name, false);
1094 attach_info.SetWaitForLaunch(wait_for);
Greg Clayton334d33a2012-01-30 07:41:31 +00001095 error.SetError (process_sp->Attach (attach_info));
Johnny Chen58d02ff2011-06-17 19:21:30 +00001096 // If we are doing synchronous mode, then wait for the
1097 // process to stop!
Greg Clayton0416bdf2012-01-30 09:04:36 +00001098 if (target_sp->GetDebugger().GetAsyncExecution () == false)
Greg Clayton334d33a2012-01-30 07:41:31 +00001099 process_sp->WaitForProcessToStop (NULL);
Greg Claytonc5f728c2010-10-06 22:10:17 +00001100 }
1101 else
1102 {
1103 error.SetErrorString ("unable to create lldb_private::Process");
1104 }
1105 }
1106 else
1107 {
1108 error.SetErrorString ("SBTarget is invalid");
1109 }
Sean Callanan4e846742012-10-20 00:21:31 +00001110
1111 if (log)
1112 {
1113 log->Printf ("SBTarget(%p)::AttachToPorcessWithName (...) => SBProcess(%p)",
1114 target_sp.get(), process_sp.get());
1115 }
Greg Claytonc5f728c2010-10-06 22:10:17 +00001116 return sb_process;
Greg Claytonc5f728c2010-10-06 22:10:17 +00001117}
1118
James McIlree38093402011-03-04 00:31:13 +00001119lldb::SBProcess
1120SBTarget::ConnectRemote
1121(
1122 SBListener &listener,
1123 const char *url,
1124 const char *plugin_name,
1125 SBError& error
1126)
1127{
Sean Callanan4e846742012-10-20 00:21:31 +00001128 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1129
James McIlree38093402011-03-04 00:31:13 +00001130 SBProcess sb_process;
Greg Clayton334d33a2012-01-30 07:41:31 +00001131 ProcessSP process_sp;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001132 TargetSP target_sp(GetSP());
Sean Callanan4e846742012-10-20 00:21:31 +00001133
1134 if (log)
1135 {
1136 log->Printf ("SBTarget(%p)::ConnectRemote (listener, url=%s, plugin_name=%s, error)...", target_sp.get(), url, plugin_name);
1137 }
1138
Greg Clayton0416bdf2012-01-30 09:04:36 +00001139 if (target_sp)
James McIlree38093402011-03-04 00:31:13 +00001140 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001141 Mutex::Locker api_locker (target_sp->GetAPIMutex());
James McIlree38093402011-03-04 00:31:13 +00001142 if (listener.IsValid())
Greg Clayton46c9a352012-02-09 06:16:32 +00001143 process_sp = target_sp->CreateProcess (listener.ref(), plugin_name, NULL);
James McIlree38093402011-03-04 00:31:13 +00001144 else
Greg Clayton46c9a352012-02-09 06:16:32 +00001145 process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener(), plugin_name, NULL);
James McIlree38093402011-03-04 00:31:13 +00001146
1147
Greg Clayton334d33a2012-01-30 07:41:31 +00001148 if (process_sp)
James McIlree38093402011-03-04 00:31:13 +00001149 {
Greg Clayton334d33a2012-01-30 07:41:31 +00001150 sb_process.SetSP (process_sp);
Jason Molendafac2e622012-09-29 04:02:01 +00001151 error.SetError (process_sp->ConnectRemote (NULL, url));
James McIlree38093402011-03-04 00:31:13 +00001152 }
1153 else
1154 {
1155 error.SetErrorString ("unable to create lldb_private::Process");
1156 }
1157 }
1158 else
1159 {
1160 error.SetErrorString ("SBTarget is invalid");
1161 }
Sean Callanan4e846742012-10-20 00:21:31 +00001162
1163 if (log)
1164 {
1165 log->Printf ("SBTarget(%p)::ConnectRemote (...) => SBProcess(%p)",
1166 target_sp.get(), process_sp.get());
1167 }
James McIlree38093402011-03-04 00:31:13 +00001168 return sb_process;
1169}
1170
Chris Lattner24943d22010-06-08 16:52:24 +00001171SBFileSpec
1172SBTarget::GetExecutable ()
1173{
Caroline Tice7826c882010-10-26 03:11:13 +00001174
Chris Lattner24943d22010-06-08 16:52:24 +00001175 SBFileSpec exe_file_spec;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001176 TargetSP target_sp(GetSP());
1177 if (target_sp)
Chris Lattner24943d22010-06-08 16:52:24 +00001178 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001179 Module *exe_module = target_sp->GetExecutableModulePointer();
Greg Clayton5beb99d2011-08-11 02:48:45 +00001180 if (exe_module)
1181 exe_file_spec.SetFileSpec (exe_module->GetFileSpec());
Chris Lattner24943d22010-06-08 16:52:24 +00001182 }
Caroline Tice7826c882010-10-26 03:11:13 +00001183
Greg Claytone005f2c2010-11-06 01:53:30 +00001184 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001185 if (log)
1186 {
Greg Clayton49ce6822010-10-31 03:01:06 +00001187 log->Printf ("SBTarget(%p)::GetExecutable () => SBFileSpec(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +00001188 target_sp.get(), exe_file_spec.get());
Caroline Tice7826c882010-10-26 03:11:13 +00001189 }
1190
Chris Lattner24943d22010-06-08 16:52:24 +00001191 return exe_file_spec;
1192}
1193
Chris Lattner24943d22010-06-08 16:52:24 +00001194bool
Chris Lattner24943d22010-06-08 16:52:24 +00001195SBTarget::operator == (const SBTarget &rhs) const
1196{
Greg Clayton63094e02010-06-23 01:19:29 +00001197 return m_opaque_sp.get() == rhs.m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +00001198}
1199
1200bool
1201SBTarget::operator != (const SBTarget &rhs) const
1202{
Greg Clayton63094e02010-06-23 01:19:29 +00001203 return m_opaque_sp.get() != rhs.m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +00001204}
1205
Greg Clayton334d33a2012-01-30 07:41:31 +00001206lldb::TargetSP
1207SBTarget::GetSP () const
Greg Clayton15afa9f2011-10-01 02:59:24 +00001208{
1209 return m_opaque_sp;
1210}
1211
Greg Clayton63094e02010-06-23 01:19:29 +00001212void
Greg Clayton334d33a2012-01-30 07:41:31 +00001213SBTarget::SetSP (const lldb::TargetSP& target_sp)
Greg Clayton63094e02010-06-23 01:19:29 +00001214{
1215 m_opaque_sp = target_sp;
Chris Lattner24943d22010-06-08 16:52:24 +00001216}
1217
Greg Claytona3955062011-07-22 16:46:35 +00001218lldb::SBAddress
1219SBTarget::ResolveLoadAddress (lldb::addr_t vm_addr)
Greg Claytonea49cc72010-12-12 19:25:26 +00001220{
Greg Claytona3955062011-07-22 16:46:35 +00001221 lldb::SBAddress sb_addr;
1222 Address &addr = sb_addr.ref();
Greg Clayton0416bdf2012-01-30 09:04:36 +00001223 TargetSP target_sp(GetSP());
1224 if (target_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +00001225 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001226 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1227 if (target_sp->GetSectionLoadList().ResolveLoadAddress (vm_addr, addr))
Greg Claytona3955062011-07-22 16:46:35 +00001228 return sb_addr;
Greg Claytonbdcda462010-12-20 20:49:23 +00001229 }
Greg Claytonea49cc72010-12-12 19:25:26 +00001230
Greg Claytona3955062011-07-22 16:46:35 +00001231 // We have a load address that isn't in a section, just return an address
1232 // with the offset filled in (the address) and the section set to NULL
Greg Clayton3508c382012-02-24 01:59:29 +00001233 addr.SetRawAddress(vm_addr);
Greg Claytona3955062011-07-22 16:46:35 +00001234 return sb_addr;
Greg Claytonea49cc72010-12-12 19:25:26 +00001235}
1236
Greg Claytonafb81862011-03-02 21:34:46 +00001237SBSymbolContext
1238SBTarget::ResolveSymbolContextForAddress (const SBAddress& addr, uint32_t resolve_scope)
1239{
1240 SBSymbolContext sc;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001241 if (addr.IsValid())
1242 {
1243 TargetSP target_sp(GetSP());
1244 if (target_sp)
1245 target_sp->GetImages().ResolveSymbolContextForAddress (addr.ref(), resolve_scope, sc.ref());
1246 }
Greg Claytonafb81862011-03-02 21:34:46 +00001247 return sc;
1248}
1249
1250
Chris Lattner24943d22010-06-08 16:52:24 +00001251SBBreakpoint
1252SBTarget::BreakpointCreateByLocation (const char *file, uint32_t line)
1253{
Greg Claytond6d806c2010-11-08 00:28:40 +00001254 return SBBreakpoint(BreakpointCreateByLocation (SBFileSpec (file, false), line));
Chris Lattner24943d22010-06-08 16:52:24 +00001255}
1256
1257SBBreakpoint
1258SBTarget::BreakpointCreateByLocation (const SBFileSpec &sb_file_spec, uint32_t line)
1259{
Greg Claytone005f2c2010-11-06 01:53:30 +00001260 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001261
Chris Lattner24943d22010-06-08 16:52:24 +00001262 SBBreakpoint sb_bp;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001263 TargetSP target_sp(GetSP());
1264 if (target_sp && line != 0)
Greg Claytonbdcda462010-12-20 20:49:23 +00001265 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001266 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Jim Ingham2cf5ccb2012-05-22 00:12:20 +00001267
Greg Clayton49ce8962012-08-29 21:13:06 +00001268 const LazyBool check_inlines = eLazyBoolCalculate;
Jim Ingham2cf5ccb2012-05-22 00:12:20 +00001269 const LazyBool skip_prologue = eLazyBoolCalculate;
Greg Clayton49ce8962012-08-29 21:13:06 +00001270 const bool internal = false;
Jim Ingham2cf5ccb2012-05-22 00:12:20 +00001271 *sb_bp = target_sp->CreateBreakpoint (NULL, *sb_file_spec, line, check_inlines, skip_prologue, internal);
Greg Claytonbdcda462010-12-20 20:49:23 +00001272 }
Caroline Tice7826c882010-10-26 03:11:13 +00001273
1274 if (log)
1275 {
1276 SBStream sstr;
1277 sb_bp.GetDescription (sstr);
Greg Clayton49ce6822010-10-31 03:01:06 +00001278 char path[PATH_MAX];
1279 sb_file_spec->GetPath (path, sizeof(path));
1280 log->Printf ("SBTarget(%p)::BreakpointCreateByLocation ( %s:%u ) => SBBreakpoint(%p): %s",
Greg Clayton0416bdf2012-01-30 09:04:36 +00001281 target_sp.get(),
Greg Clayton49ce6822010-10-31 03:01:06 +00001282 path,
Greg Claytona66ba462010-10-30 04:51:46 +00001283 line,
Greg Clayton49ce6822010-10-31 03:01:06 +00001284 sb_bp.get(),
Caroline Tice7826c882010-10-26 03:11:13 +00001285 sstr.GetData());
1286 }
1287
Chris Lattner24943d22010-06-08 16:52:24 +00001288 return sb_bp;
1289}
1290
1291SBBreakpoint
1292SBTarget::BreakpointCreateByName (const char *symbol_name, const char *module_name)
1293{
Greg Claytone005f2c2010-11-06 01:53:30 +00001294 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001295
Chris Lattner24943d22010-06-08 16:52:24 +00001296 SBBreakpoint sb_bp;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001297 TargetSP target_sp(GetSP());
1298 if (target_sp.get())
Chris Lattner24943d22010-06-08 16:52:24 +00001299 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001300 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Jim Ingham2cf5ccb2012-05-22 00:12:20 +00001301
1302 const bool internal = false;
1303 const LazyBool skip_prologue = eLazyBoolCalculate;
Chris Lattner24943d22010-06-08 16:52:24 +00001304 if (module_name && module_name[0])
1305 {
Jim Ingham03c8ee52011-09-21 01:17:13 +00001306 FileSpecList module_spec_list;
1307 module_spec_list.Append (FileSpec (module_name, false));
Jim Ingham2cf5ccb2012-05-22 00:12:20 +00001308 *sb_bp = target_sp->CreateBreakpoint (&module_spec_list, NULL, symbol_name, eFunctionNameTypeAuto, skip_prologue, internal);
Chris Lattner24943d22010-06-08 16:52:24 +00001309 }
1310 else
1311 {
Jim Ingham2cf5ccb2012-05-22 00:12:20 +00001312 *sb_bp = target_sp->CreateBreakpoint (NULL, NULL, symbol_name, eFunctionNameTypeAuto, skip_prologue, internal);
Chris Lattner24943d22010-06-08 16:52:24 +00001313 }
1314 }
Caroline Tice7826c882010-10-26 03:11:13 +00001315
1316 if (log)
1317 {
Greg Clayton49ce6822010-10-31 03:01:06 +00001318 log->Printf ("SBTarget(%p)::BreakpointCreateByName (symbol=\"%s\", module=\"%s\") => SBBreakpoint(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +00001319 target_sp.get(), symbol_name, module_name, sb_bp.get());
Caroline Tice7826c882010-10-26 03:11:13 +00001320 }
1321
Chris Lattner24943d22010-06-08 16:52:24 +00001322 return sb_bp;
1323}
1324
Jim Inghamd6d47972011-09-23 00:54:11 +00001325lldb::SBBreakpoint
1326SBTarget::BreakpointCreateByName (const char *symbol_name,
1327 const SBFileSpecList &module_list,
1328 const SBFileSpecList &comp_unit_list)
1329{
Jim Ingham1fb8a2d2011-10-11 01:18:55 +00001330 uint32_t name_type_mask = eFunctionNameTypeAuto;
1331 return BreakpointCreateByName (symbol_name, name_type_mask, module_list, comp_unit_list);
1332}
1333
1334lldb::SBBreakpoint
1335SBTarget::BreakpointCreateByName (const char *symbol_name,
1336 uint32_t name_type_mask,
1337 const SBFileSpecList &module_list,
1338 const SBFileSpecList &comp_unit_list)
1339{
Jim Inghamd6d47972011-09-23 00:54:11 +00001340 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1341
1342 SBBreakpoint sb_bp;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001343 TargetSP target_sp(GetSP());
1344 if (target_sp && symbol_name && symbol_name[0])
Jim Inghamd6d47972011-09-23 00:54:11 +00001345 {
Jim Ingham2cf5ccb2012-05-22 00:12:20 +00001346 const bool internal = false;
1347 const LazyBool skip_prologue = eLazyBoolCalculate;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001348 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1349 *sb_bp = target_sp->CreateBreakpoint (module_list.get(),
Jim Inghamd6d47972011-09-23 00:54:11 +00001350 comp_unit_list.get(),
1351 symbol_name,
Jim Ingham1fb8a2d2011-10-11 01:18:55 +00001352 name_type_mask,
Jim Ingham2cf5ccb2012-05-22 00:12:20 +00001353 skip_prologue,
1354 internal);
Jim Inghamd6d47972011-09-23 00:54:11 +00001355 }
1356
1357 if (log)
1358 {
Jim Ingham1fb8a2d2011-10-11 01:18:55 +00001359 log->Printf ("SBTarget(%p)::BreakpointCreateByName (symbol=\"%s\", name_type: %d) => SBBreakpoint(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +00001360 target_sp.get(), symbol_name, name_type_mask, sb_bp.get());
Jim Inghamd6d47972011-09-23 00:54:11 +00001361 }
1362
1363 return sb_bp;
1364}
1365
Jim Ingham4722b102012-03-06 00:37:27 +00001366lldb::SBBreakpoint
1367SBTarget::BreakpointCreateByNames (const char *symbol_names[],
1368 uint32_t num_names,
1369 uint32_t name_type_mask,
1370 const SBFileSpecList &module_list,
1371 const SBFileSpecList &comp_unit_list)
1372{
1373 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1374
1375 SBBreakpoint sb_bp;
1376 TargetSP target_sp(GetSP());
1377 if (target_sp && num_names > 0)
1378 {
1379 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Jim Ingham2cf5ccb2012-05-22 00:12:20 +00001380 const bool internal = false;
1381 const LazyBool skip_prologue = eLazyBoolCalculate;
Jim Ingham4722b102012-03-06 00:37:27 +00001382 *sb_bp = target_sp->CreateBreakpoint (module_list.get(),
1383 comp_unit_list.get(),
1384 symbol_names,
1385 num_names,
1386 name_type_mask,
Jim Ingham2cf5ccb2012-05-22 00:12:20 +00001387 skip_prologue,
1388 internal);
Jim Ingham4722b102012-03-06 00:37:27 +00001389 }
1390
1391 if (log)
1392 {
1393 log->Printf ("SBTarget(%p)::BreakpointCreateByName (symbols={", target_sp.get());
1394 for (uint32_t i = 0 ; i < num_names; i++)
1395 {
1396 char sep;
1397 if (i < num_names - 1)
1398 sep = ',';
1399 else
1400 sep = '}';
1401 if (symbol_names[i] != NULL)
1402 log->Printf ("\"%s\"%c ", symbol_names[i], sep);
1403 else
1404 log->Printf ("\"<NULL>\"%c ", sep);
1405
1406 }
1407 log->Printf ("name_type: %d) => SBBreakpoint(%p)", name_type_mask, sb_bp.get());
1408 }
1409
1410 return sb_bp;
1411}
Jim Inghamd6d47972011-09-23 00:54:11 +00001412
Chris Lattner24943d22010-06-08 16:52:24 +00001413SBBreakpoint
1414SBTarget::BreakpointCreateByRegex (const char *symbol_name_regex, const char *module_name)
1415{
Greg Claytone005f2c2010-11-06 01:53:30 +00001416 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001417
Chris Lattner24943d22010-06-08 16:52:24 +00001418 SBBreakpoint sb_bp;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001419 TargetSP target_sp(GetSP());
1420 if (target_sp && symbol_name_regex && symbol_name_regex[0])
Chris Lattner24943d22010-06-08 16:52:24 +00001421 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001422 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Chris Lattner24943d22010-06-08 16:52:24 +00001423 RegularExpression regexp(symbol_name_regex);
Jim Ingham2cf5ccb2012-05-22 00:12:20 +00001424 const bool internal = false;
1425 const LazyBool skip_prologue = eLazyBoolCalculate;
Chris Lattner24943d22010-06-08 16:52:24 +00001426
1427 if (module_name && module_name[0])
1428 {
Jim Ingham03c8ee52011-09-21 01:17:13 +00001429 FileSpecList module_spec_list;
1430 module_spec_list.Append (FileSpec (module_name, false));
Chris Lattner24943d22010-06-08 16:52:24 +00001431
Jim Ingham2cf5ccb2012-05-22 00:12:20 +00001432 *sb_bp = target_sp->CreateFuncRegexBreakpoint (&module_spec_list, NULL, regexp, skip_prologue, internal);
Chris Lattner24943d22010-06-08 16:52:24 +00001433 }
1434 else
1435 {
Jim Ingham2cf5ccb2012-05-22 00:12:20 +00001436 *sb_bp = target_sp->CreateFuncRegexBreakpoint (NULL, NULL, regexp, skip_prologue, internal);
Chris Lattner24943d22010-06-08 16:52:24 +00001437 }
1438 }
Caroline Tice7826c882010-10-26 03:11:13 +00001439
1440 if (log)
1441 {
Greg Clayton49ce6822010-10-31 03:01:06 +00001442 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (symbol_regex=\"%s\", module_name=\"%s\") => SBBreakpoint(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +00001443 target_sp.get(), symbol_name_regex, module_name, sb_bp.get());
Caroline Tice7826c882010-10-26 03:11:13 +00001444 }
1445
Chris Lattner24943d22010-06-08 16:52:24 +00001446 return sb_bp;
1447}
1448
Jim Inghamd6d47972011-09-23 00:54:11 +00001449lldb::SBBreakpoint
1450SBTarget::BreakpointCreateByRegex (const char *symbol_name_regex,
1451 const SBFileSpecList &module_list,
1452 const SBFileSpecList &comp_unit_list)
1453{
1454 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Chris Lattner24943d22010-06-08 16:52:24 +00001455
Jim Inghamd6d47972011-09-23 00:54:11 +00001456 SBBreakpoint sb_bp;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001457 TargetSP target_sp(GetSP());
1458 if (target_sp && symbol_name_regex && symbol_name_regex[0])
Jim Inghamd6d47972011-09-23 00:54:11 +00001459 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001460 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Jim Inghamd6d47972011-09-23 00:54:11 +00001461 RegularExpression regexp(symbol_name_regex);
Jim Ingham2cf5ccb2012-05-22 00:12:20 +00001462 const bool internal = false;
1463 const LazyBool skip_prologue = eLazyBoolCalculate;
Jim Inghamd6d47972011-09-23 00:54:11 +00001464
Jim Ingham2cf5ccb2012-05-22 00:12:20 +00001465 *sb_bp = target_sp->CreateFuncRegexBreakpoint (module_list.get(), comp_unit_list.get(), regexp, skip_prologue, internal);
Jim Inghamd6d47972011-09-23 00:54:11 +00001466 }
1467
1468 if (log)
1469 {
1470 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (symbol_regex=\"%s\") => SBBreakpoint(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +00001471 target_sp.get(), symbol_name_regex, sb_bp.get());
Jim Inghamd6d47972011-09-23 00:54:11 +00001472 }
1473
1474 return sb_bp;
1475}
Chris Lattner24943d22010-06-08 16:52:24 +00001476
1477SBBreakpoint
1478SBTarget::BreakpointCreateByAddress (addr_t address)
1479{
Greg Claytone005f2c2010-11-06 01:53:30 +00001480 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001481
Chris Lattner24943d22010-06-08 16:52:24 +00001482 SBBreakpoint sb_bp;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001483 TargetSP target_sp(GetSP());
1484 if (target_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +00001485 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001486 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1487 *sb_bp = target_sp->CreateBreakpoint (address, false);
Greg Claytonbdcda462010-12-20 20:49:23 +00001488 }
Caroline Tice7826c882010-10-26 03:11:13 +00001489
1490 if (log)
1491 {
Daniel Malea5f35a4b2012-11-29 21:49:15 +00001492 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 +00001493 }
1494
Chris Lattner24943d22010-06-08 16:52:24 +00001495 return sb_bp;
1496}
1497
Jim Ingham03c8ee52011-09-21 01:17:13 +00001498lldb::SBBreakpoint
1499SBTarget::BreakpointCreateBySourceRegex (const char *source_regex, const lldb::SBFileSpec &source_file, const char *module_name)
1500{
1501 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1502
1503 SBBreakpoint sb_bp;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001504 TargetSP target_sp(GetSP());
1505 if (target_sp && source_regex && source_regex[0])
Jim Ingham03c8ee52011-09-21 01:17:13 +00001506 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001507 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Jim Ingham03c8ee52011-09-21 01:17:13 +00001508 RegularExpression regexp(source_regex);
Jim Inghamd6d47972011-09-23 00:54:11 +00001509 FileSpecList source_file_spec_list;
1510 source_file_spec_list.Append (source_file.ref());
Jim Ingham03c8ee52011-09-21 01:17:13 +00001511
1512 if (module_name && module_name[0])
1513 {
1514 FileSpecList module_spec_list;
1515 module_spec_list.Append (FileSpec (module_name, false));
1516
Greg Clayton0416bdf2012-01-30 09:04:36 +00001517 *sb_bp = target_sp->CreateSourceRegexBreakpoint (&module_spec_list, &source_file_spec_list, regexp, false);
Jim Ingham03c8ee52011-09-21 01:17:13 +00001518 }
1519 else
1520 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001521 *sb_bp = target_sp->CreateSourceRegexBreakpoint (NULL, &source_file_spec_list, regexp, false);
Jim Ingham03c8ee52011-09-21 01:17:13 +00001522 }
1523 }
1524
1525 if (log)
1526 {
1527 char path[PATH_MAX];
1528 source_file->GetPath (path, sizeof(path));
1529 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (source_regex=\"%s\", file=\"%s\", module_name=\"%s\") => SBBreakpoint(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +00001530 target_sp.get(), source_regex, path, module_name, sb_bp.get());
Jim Ingham03c8ee52011-09-21 01:17:13 +00001531 }
1532
1533 return sb_bp;
1534}
1535
Jim Inghamd6d47972011-09-23 00:54:11 +00001536lldb::SBBreakpoint
1537SBTarget::BreakpointCreateBySourceRegex (const char *source_regex,
1538 const SBFileSpecList &module_list,
1539 const lldb::SBFileSpecList &source_file_list)
1540{
1541 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1542
1543 SBBreakpoint sb_bp;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001544 TargetSP target_sp(GetSP());
1545 if (target_sp && source_regex && source_regex[0])
Jim Inghamd6d47972011-09-23 00:54:11 +00001546 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001547 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Jim Inghamd6d47972011-09-23 00:54:11 +00001548 RegularExpression regexp(source_regex);
Greg Clayton0416bdf2012-01-30 09:04:36 +00001549 *sb_bp = target_sp->CreateSourceRegexBreakpoint (module_list.get(), source_file_list.get(), regexp, false);
Jim Inghamd6d47972011-09-23 00:54:11 +00001550 }
1551
1552 if (log)
1553 {
1554 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (source_regex=\"%s\") => SBBreakpoint(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +00001555 target_sp.get(), source_regex, sb_bp.get());
Jim Inghamd6d47972011-09-23 00:54:11 +00001556 }
1557
1558 return sb_bp;
1559}
Jim Ingham03c8ee52011-09-21 01:17:13 +00001560
Jim Ingham4722b102012-03-06 00:37:27 +00001561lldb::SBBreakpoint
1562SBTarget::BreakpointCreateForException (lldb::LanguageType language,
1563 bool catch_bp,
1564 bool throw_bp)
1565{
1566 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1567
1568 SBBreakpoint sb_bp;
1569 TargetSP target_sp(GetSP());
1570 if (target_sp)
1571 {
1572 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1573 *sb_bp = target_sp->CreateExceptionBreakpoint (language, catch_bp, throw_bp);
1574 }
1575
1576 if (log)
1577 {
1578 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (Language: %s, catch: %s throw: %s) => SBBreakpoint(%p)",
1579 target_sp.get(),
1580 LanguageRuntime::GetNameForLanguageType(language),
1581 catch_bp ? "on" : "off",
1582 throw_bp ? "on" : "off",
1583 sb_bp.get());
1584 }
1585
1586 return sb_bp;
1587}
1588
Greg Claytonc7f5d5c2010-07-23 23:33:17 +00001589uint32_t
1590SBTarget::GetNumBreakpoints () const
1591{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001592 TargetSP target_sp(GetSP());
1593 if (target_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +00001594 {
1595 // The breakpoint list is thread safe, no need to lock
Greg Clayton0416bdf2012-01-30 09:04:36 +00001596 return target_sp->GetBreakpointList().GetSize();
Greg Claytonbdcda462010-12-20 20:49:23 +00001597 }
Greg Claytonc7f5d5c2010-07-23 23:33:17 +00001598 return 0;
1599}
1600
1601SBBreakpoint
1602SBTarget::GetBreakpointAtIndex (uint32_t idx) const
1603{
1604 SBBreakpoint sb_breakpoint;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001605 TargetSP target_sp(GetSP());
1606 if (target_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +00001607 {
1608 // The breakpoint list is thread safe, no need to lock
Greg Clayton0416bdf2012-01-30 09:04:36 +00001609 *sb_breakpoint = target_sp->GetBreakpointList().GetBreakpointAtIndex(idx);
Greg Claytonbdcda462010-12-20 20:49:23 +00001610 }
Greg Claytonc7f5d5c2010-07-23 23:33:17 +00001611 return sb_breakpoint;
1612}
Chris Lattner24943d22010-06-08 16:52:24 +00001613
1614bool
1615SBTarget::BreakpointDelete (break_id_t bp_id)
1616{
Greg Claytone005f2c2010-11-06 01:53:30 +00001617 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001618
Caroline Tice7826c882010-10-26 03:11:13 +00001619 bool result = false;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001620 TargetSP target_sp(GetSP());
1621 if (target_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +00001622 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001623 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1624 result = target_sp->RemoveBreakpointByID (bp_id);
Greg Claytonbdcda462010-12-20 20:49:23 +00001625 }
Caroline Tice7826c882010-10-26 03:11:13 +00001626
1627 if (log)
1628 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001629 log->Printf ("SBTarget(%p)::BreakpointDelete (bp_id=%d) => %i", target_sp.get(), (uint32_t) bp_id, result);
Caroline Tice7826c882010-10-26 03:11:13 +00001630 }
1631
1632 return result;
Chris Lattner24943d22010-06-08 16:52:24 +00001633}
1634
Johnny Chen096c2932011-09-26 22:40:50 +00001635SBBreakpoint
1636SBTarget::FindBreakpointByID (break_id_t bp_id)
1637{
1638 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1639
1640 SBBreakpoint sb_breakpoint;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001641 TargetSP target_sp(GetSP());
1642 if (target_sp && bp_id != LLDB_INVALID_BREAK_ID)
Johnny Chen096c2932011-09-26 22:40:50 +00001643 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001644 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1645 *sb_breakpoint = target_sp->GetBreakpointByID (bp_id);
Johnny Chen096c2932011-09-26 22:40:50 +00001646 }
1647
1648 if (log)
1649 {
1650 log->Printf ("SBTarget(%p)::FindBreakpointByID (bp_id=%d) => SBBreakpoint(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +00001651 target_sp.get(), (uint32_t) bp_id, sb_breakpoint.get());
Johnny Chen096c2932011-09-26 22:40:50 +00001652 }
1653
1654 return sb_breakpoint;
1655}
1656
Chris Lattner24943d22010-06-08 16:52:24 +00001657bool
1658SBTarget::EnableAllBreakpoints ()
1659{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001660 TargetSP target_sp(GetSP());
1661 if (target_sp)
Chris Lattner24943d22010-06-08 16:52:24 +00001662 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001663 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1664 target_sp->EnableAllBreakpoints ();
Chris Lattner24943d22010-06-08 16:52:24 +00001665 return true;
1666 }
1667 return false;
1668}
1669
1670bool
1671SBTarget::DisableAllBreakpoints ()
1672{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001673 TargetSP target_sp(GetSP());
1674 if (target_sp)
Chris Lattner24943d22010-06-08 16:52:24 +00001675 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001676 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1677 target_sp->DisableAllBreakpoints ();
Chris Lattner24943d22010-06-08 16:52:24 +00001678 return true;
1679 }
1680 return false;
1681}
1682
1683bool
1684SBTarget::DeleteAllBreakpoints ()
1685{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001686 TargetSP target_sp(GetSP());
1687 if (target_sp)
Chris Lattner24943d22010-06-08 16:52:24 +00001688 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001689 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1690 target_sp->RemoveAllBreakpoints ();
Chris Lattner24943d22010-06-08 16:52:24 +00001691 return true;
1692 }
1693 return false;
1694}
1695
Johnny Chen096c2932011-09-26 22:40:50 +00001696uint32_t
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001697SBTarget::GetNumWatchpoints () const
Johnny Chen096c2932011-09-26 22:40:50 +00001698{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001699 TargetSP target_sp(GetSP());
1700 if (target_sp)
Johnny Chen096c2932011-09-26 22:40:50 +00001701 {
Johnny Chenecd4feb2011-10-14 00:42:25 +00001702 // The watchpoint list is thread safe, no need to lock
Greg Clayton0416bdf2012-01-30 09:04:36 +00001703 return target_sp->GetWatchpointList().GetSize();
Johnny Chen096c2932011-09-26 22:40:50 +00001704 }
1705 return 0;
1706}
1707
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001708SBWatchpoint
1709SBTarget::GetWatchpointAtIndex (uint32_t idx) const
Johnny Chen5eb54bb2011-09-27 20:29:45 +00001710{
Johnny Chenecd4feb2011-10-14 00:42:25 +00001711 SBWatchpoint sb_watchpoint;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001712 TargetSP target_sp(GetSP());
1713 if (target_sp)
Johnny Chen096c2932011-09-26 22:40:50 +00001714 {
Johnny Chenecd4feb2011-10-14 00:42:25 +00001715 // The watchpoint list is thread safe, no need to lock
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001716 sb_watchpoint.SetSP (target_sp->GetWatchpointList().GetByIndex(idx));
Johnny Chen096c2932011-09-26 22:40:50 +00001717 }
Johnny Chenecd4feb2011-10-14 00:42:25 +00001718 return sb_watchpoint;
Johnny Chen096c2932011-09-26 22:40:50 +00001719}
1720
1721bool
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001722SBTarget::DeleteWatchpoint (watch_id_t wp_id)
Johnny Chen096c2932011-09-26 22:40:50 +00001723{
1724 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1725
1726 bool result = false;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001727 TargetSP target_sp(GetSP());
1728 if (target_sp)
Johnny Chen096c2932011-09-26 22:40:50 +00001729 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001730 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Johnny Chenbbf6aa52012-05-31 22:56:36 +00001731 Mutex::Locker locker;
1732 target_sp->GetWatchpointList().GetListMutex(locker);
Greg Clayton0416bdf2012-01-30 09:04:36 +00001733 result = target_sp->RemoveWatchpointByID (wp_id);
Johnny Chen096c2932011-09-26 22:40:50 +00001734 }
1735
1736 if (log)
1737 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001738 log->Printf ("SBTarget(%p)::WatchpointDelete (wp_id=%d) => %i", target_sp.get(), (uint32_t) wp_id, result);
Johnny Chen096c2932011-09-26 22:40:50 +00001739 }
1740
1741 return result;
1742}
1743
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001744SBWatchpoint
1745SBTarget::FindWatchpointByID (lldb::watch_id_t wp_id)
Johnny Chen096c2932011-09-26 22:40:50 +00001746{
1747 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1748
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001749 SBWatchpoint sb_watchpoint;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001750 lldb::WatchpointSP watchpoint_sp;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001751 TargetSP target_sp(GetSP());
1752 if (target_sp && wp_id != LLDB_INVALID_WATCH_ID)
Johnny Chen096c2932011-09-26 22:40:50 +00001753 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001754 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Johnny Chenbbf6aa52012-05-31 22:56:36 +00001755 Mutex::Locker locker;
1756 target_sp->GetWatchpointList().GetListMutex(locker);
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001757 watchpoint_sp = target_sp->GetWatchpointList().FindByID(wp_id);
1758 sb_watchpoint.SetSP (watchpoint_sp);
Johnny Chen096c2932011-09-26 22:40:50 +00001759 }
1760
1761 if (log)
1762 {
Johnny Chenecd4feb2011-10-14 00:42:25 +00001763 log->Printf ("SBTarget(%p)::FindWatchpointByID (bp_id=%d) => SBWatchpoint(%p)",
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001764 target_sp.get(), (uint32_t) wp_id, watchpoint_sp.get());
Johnny Chen096c2932011-09-26 22:40:50 +00001765 }
1766
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001767 return sb_watchpoint;
1768}
1769
1770lldb::SBWatchpoint
Johnny Chen3f883492012-06-04 23:19:54 +00001771SBTarget::WatchAddress (lldb::addr_t addr, size_t size, bool read, bool write, SBError &error)
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001772{
1773 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1774
1775 SBWatchpoint sb_watchpoint;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001776 lldb::WatchpointSP watchpoint_sp;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001777 TargetSP target_sp(GetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001778 if (target_sp && (read || write) && addr != LLDB_INVALID_ADDRESS && size > 0)
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001779 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001780 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001781 uint32_t watch_type = 0;
1782 if (read)
1783 watch_type |= LLDB_WATCH_TYPE_READ;
1784 if (write)
1785 watch_type |= LLDB_WATCH_TYPE_WRITE;
Johnny Chenbbf6aa52012-05-31 22:56:36 +00001786 // Target::CreateWatchpoint() is thread safe.
Johnny Chen3f883492012-06-04 23:19:54 +00001787 Error cw_error;
Jim Ingham9e376622012-10-23 07:20:06 +00001788 // This API doesn't take in a type, so we can't figure out what it is.
1789 ClangASTType *type = NULL;
1790 watchpoint_sp = target_sp->CreateWatchpoint(addr, size, type, watch_type, cw_error);
Johnny Chen3f883492012-06-04 23:19:54 +00001791 error.SetError(cw_error);
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001792 sb_watchpoint.SetSP (watchpoint_sp);
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001793 }
1794
1795 if (log)
1796 {
Daniel Malea5f35a4b2012-11-29 21:49:15 +00001797 log->Printf ("SBTarget(%p)::WatchAddress (addr=0x%" PRIx64 ", 0x%u) => SBWatchpoint(%p)",
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001798 target_sp.get(), addr, (uint32_t) size, watchpoint_sp.get());
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001799 }
1800
1801 return sb_watchpoint;
Johnny Chen096c2932011-09-26 22:40:50 +00001802}
1803
1804bool
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001805SBTarget::EnableAllWatchpoints ()
Johnny Chen096c2932011-09-26 22:40:50 +00001806{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001807 TargetSP target_sp(GetSP());
1808 if (target_sp)
Johnny Chen096c2932011-09-26 22:40:50 +00001809 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001810 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Johnny Chenbbf6aa52012-05-31 22:56:36 +00001811 Mutex::Locker locker;
1812 target_sp->GetWatchpointList().GetListMutex(locker);
Greg Clayton0416bdf2012-01-30 09:04:36 +00001813 target_sp->EnableAllWatchpoints ();
Johnny Chen096c2932011-09-26 22:40:50 +00001814 return true;
1815 }
1816 return false;
1817}
1818
1819bool
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001820SBTarget::DisableAllWatchpoints ()
Johnny Chen096c2932011-09-26 22:40:50 +00001821{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001822 TargetSP target_sp(GetSP());
1823 if (target_sp)
Johnny Chen096c2932011-09-26 22:40:50 +00001824 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001825 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Johnny Chenbbf6aa52012-05-31 22:56:36 +00001826 Mutex::Locker locker;
1827 target_sp->GetWatchpointList().GetListMutex(locker);
Greg Clayton0416bdf2012-01-30 09:04:36 +00001828 target_sp->DisableAllWatchpoints ();
Johnny Chen096c2932011-09-26 22:40:50 +00001829 return true;
1830 }
1831 return false;
1832}
1833
1834bool
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001835SBTarget::DeleteAllWatchpoints ()
Johnny Chen096c2932011-09-26 22:40:50 +00001836{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001837 TargetSP target_sp(GetSP());
1838 if (target_sp)
Johnny Chen096c2932011-09-26 22:40:50 +00001839 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001840 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Johnny Chenbbf6aa52012-05-31 22:56:36 +00001841 Mutex::Locker locker;
1842 target_sp->GetWatchpointList().GetListMutex(locker);
Greg Clayton0416bdf2012-01-30 09:04:36 +00001843 target_sp->RemoveAllWatchpoints ();
Johnny Chen096c2932011-09-26 22:40:50 +00001844 return true;
1845 }
1846 return false;
1847}
1848
Chris Lattner24943d22010-06-08 16:52:24 +00001849
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001850lldb::SBModule
1851SBTarget::AddModule (const char *path,
1852 const char *triple,
1853 const char *uuid_cstr)
1854{
Greg Claytonf0bc8152012-04-23 20:23:39 +00001855 return AddModule (path, triple, uuid_cstr, NULL);
1856}
1857
1858lldb::SBModule
1859SBTarget::AddModule (const char *path,
1860 const char *triple,
1861 const char *uuid_cstr,
1862 const char *symfile)
1863{
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001864 lldb::SBModule sb_module;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001865 TargetSP target_sp(GetSP());
1866 if (target_sp)
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001867 {
Greg Clayton444fe992012-02-26 05:51:37 +00001868 ModuleSpec module_spec;
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001869 if (path)
Greg Clayton444fe992012-02-26 05:51:37 +00001870 module_spec.GetFileSpec().SetFile(path, false);
Greg Claytonf0bc8152012-04-23 20:23:39 +00001871
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001872 if (uuid_cstr)
Greg Clayton437b5bc2012-09-27 22:26:11 +00001873 module_spec.GetUUID().SetFromCString(uuid_cstr);
Greg Claytonf0bc8152012-04-23 20:23:39 +00001874
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001875 if (triple)
Greg Clayton444fe992012-02-26 05:51:37 +00001876 module_spec.GetArchitecture().SetTriple (triple, target_sp->GetPlatform ().get());
Greg Claytonf0bc8152012-04-23 20:23:39 +00001877
1878 if (symfile)
1879 module_spec.GetSymbolFileSpec ().SetFile(symfile, false);
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001880
Greg Clayton444fe992012-02-26 05:51:37 +00001881 sb_module.SetSP(target_sp->GetSharedModule (module_spec));
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001882 }
1883 return sb_module;
1884}
1885
1886bool
1887SBTarget::AddModule (lldb::SBModule &module)
1888{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001889 TargetSP target_sp(GetSP());
1890 if (target_sp)
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001891 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001892 target_sp->GetImages().AppendIfNeeded (module.GetSP());
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001893 return true;
1894 }
1895 return false;
1896}
1897
Chris Lattner24943d22010-06-08 16:52:24 +00001898uint32_t
1899SBTarget::GetNumModules () const
1900{
Greg Claytone005f2c2010-11-06 01:53:30 +00001901 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001902
Caroline Tice7826c882010-10-26 03:11:13 +00001903 uint32_t num = 0;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001904 TargetSP target_sp(GetSP());
1905 if (target_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +00001906 {
1907 // The module list is thread safe, no need to lock
Greg Clayton0416bdf2012-01-30 09:04:36 +00001908 num = target_sp->GetImages().GetSize();
Greg Claytonbdcda462010-12-20 20:49:23 +00001909 }
Caroline Tice7826c882010-10-26 03:11:13 +00001910
1911 if (log)
Greg Clayton0416bdf2012-01-30 09:04:36 +00001912 log->Printf ("SBTarget(%p)::GetNumModules () => %d", target_sp.get(), num);
Caroline Tice7826c882010-10-26 03:11:13 +00001913
1914 return num;
Chris Lattner24943d22010-06-08 16:52:24 +00001915}
1916
Greg Clayton43490d12010-07-30 20:12:55 +00001917void
1918SBTarget::Clear ()
1919{
Greg Claytone005f2c2010-11-06 01:53:30 +00001920 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001921
1922 if (log)
Greg Clayton3f5ee7f2010-10-29 04:59:35 +00001923 log->Printf ("SBTarget(%p)::Clear ()", m_opaque_sp.get());
Caroline Tice7826c882010-10-26 03:11:13 +00001924
Greg Clayton43490d12010-07-30 20:12:55 +00001925 m_opaque_sp.reset();
1926}
1927
1928
Chris Lattner24943d22010-06-08 16:52:24 +00001929SBModule
1930SBTarget::FindModule (const SBFileSpec &sb_file_spec)
1931{
1932 SBModule sb_module;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001933 TargetSP target_sp(GetSP());
1934 if (target_sp && sb_file_spec.IsValid())
Greg Claytonbdcda462010-12-20 20:49:23 +00001935 {
Greg Clayton444fe992012-02-26 05:51:37 +00001936 ModuleSpec module_spec(*sb_file_spec);
Greg Claytonbdcda462010-12-20 20:49:23 +00001937 // The module list is thread safe, no need to lock
Greg Clayton444fe992012-02-26 05:51:37 +00001938 sb_module.SetSP (target_sp->GetImages().FindFirstModule (module_spec));
Greg Claytonbdcda462010-12-20 20:49:23 +00001939 }
Chris Lattner24943d22010-06-08 16:52:24 +00001940 return sb_module;
1941}
1942
Greg Clayton1b925202012-01-29 06:07:39 +00001943lldb::ByteOrder
1944SBTarget::GetByteOrder ()
1945{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001946 TargetSP target_sp(GetSP());
1947 if (target_sp)
1948 return target_sp->GetArchitecture().GetByteOrder();
Greg Clayton1b925202012-01-29 06:07:39 +00001949 return eByteOrderInvalid;
1950}
1951
1952const char *
1953SBTarget::GetTriple ()
1954{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001955 TargetSP target_sp(GetSP());
1956 if (target_sp)
Greg Clayton1b925202012-01-29 06:07:39 +00001957 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00001958 std::string triple (target_sp->GetArchitecture().GetTriple().str());
Greg Clayton1b925202012-01-29 06:07:39 +00001959 // Unique the string so we don't run into ownership issues since
1960 // the const strings put the string into the string pool once and
1961 // the strings never comes out
1962 ConstString const_triple (triple.c_str());
1963 return const_triple.GetCString();
1964 }
1965 return NULL;
1966}
1967
1968uint32_t
1969SBTarget::GetAddressByteSize()
1970{
Greg Clayton0416bdf2012-01-30 09:04:36 +00001971 TargetSP target_sp(GetSP());
1972 if (target_sp)
1973 return target_sp->GetArchitecture().GetAddressByteSize();
Greg Clayton1b925202012-01-29 06:07:39 +00001974 return sizeof(void*);
1975}
1976
1977
Chris Lattner24943d22010-06-08 16:52:24 +00001978SBModule
1979SBTarget::GetModuleAtIndex (uint32_t idx)
1980{
Greg Claytone005f2c2010-11-06 01:53:30 +00001981 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001982
Chris Lattner24943d22010-06-08 16:52:24 +00001983 SBModule sb_module;
Greg Clayton0416bdf2012-01-30 09:04:36 +00001984 ModuleSP module_sp;
1985 TargetSP target_sp(GetSP());
1986 if (target_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +00001987 {
1988 // The module list is thread safe, no need to lock
Greg Clayton0416bdf2012-01-30 09:04:36 +00001989 module_sp = target_sp->GetImages().GetModuleAtIndex(idx);
1990 sb_module.SetSP (module_sp);
Greg Claytonbdcda462010-12-20 20:49:23 +00001991 }
Caroline Tice7826c882010-10-26 03:11:13 +00001992
1993 if (log)
1994 {
Greg Clayton49ce6822010-10-31 03:01:06 +00001995 log->Printf ("SBTarget(%p)::GetModuleAtIndex (idx=%d) => SBModule(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +00001996 target_sp.get(), idx, module_sp.get());
Caroline Tice7826c882010-10-26 03:11:13 +00001997 }
1998
Chris Lattner24943d22010-06-08 16:52:24 +00001999 return sb_module;
2000}
2001
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002002bool
2003SBTarget::RemoveModule (lldb::SBModule module)
2004{
Greg Clayton0416bdf2012-01-30 09:04:36 +00002005 TargetSP target_sp(GetSP());
2006 if (target_sp)
2007 return target_sp->GetImages().Remove(module.GetSP());
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002008 return false;
2009}
2010
Chris Lattner24943d22010-06-08 16:52:24 +00002011
2012SBBroadcaster
2013SBTarget::GetBroadcaster () const
2014{
Greg Claytone005f2c2010-11-06 01:53:30 +00002015 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00002016
Greg Clayton0416bdf2012-01-30 09:04:36 +00002017 TargetSP target_sp(GetSP());
2018 SBBroadcaster broadcaster(target_sp.get(), false);
Caroline Tice7826c882010-10-26 03:11:13 +00002019
2020 if (log)
Greg Clayton3f5ee7f2010-10-29 04:59:35 +00002021 log->Printf ("SBTarget(%p)::GetBroadcaster () => SBBroadcaster(%p)",
Greg Clayton0416bdf2012-01-30 09:04:36 +00002022 target_sp.get(), broadcaster.get());
Caroline Tice7826c882010-10-26 03:11:13 +00002023
Chris Lattner24943d22010-06-08 16:52:24 +00002024 return broadcaster;
2025}
2026
Caroline Tice98f930f2010-09-20 05:20:02 +00002027bool
Caroline Tice7826c882010-10-26 03:11:13 +00002028SBTarget::GetDescription (SBStream &description, lldb::DescriptionLevel description_level)
Caroline Tice98f930f2010-09-20 05:20:02 +00002029{
Greg Clayton96154be2011-11-13 06:57:31 +00002030 Stream &strm = description.ref();
2031
Greg Clayton0416bdf2012-01-30 09:04:36 +00002032 TargetSP target_sp(GetSP());
2033 if (target_sp)
Caroline Ticee7a566e2010-09-20 16:21:41 +00002034 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00002035 target_sp->Dump (&strm, description_level);
Caroline Tice7826c882010-10-26 03:11:13 +00002036 }
2037 else
Greg Clayton96154be2011-11-13 06:57:31 +00002038 strm.PutCString ("No value");
Caroline Tice7826c882010-10-26 03:11:13 +00002039
2040 return true;
2041}
2042
Greg Clayton7dd5c512012-02-06 01:44:54 +00002043lldb::SBSymbolContextList
2044SBTarget::FindFunctions (const char *name, uint32_t name_type_mask)
Greg Clayton4ed315f2011-06-21 01:34:41 +00002045{
Greg Clayton7dd5c512012-02-06 01:44:54 +00002046 lldb::SBSymbolContextList sb_sc_list;
Greg Clayton0416bdf2012-01-30 09:04:36 +00002047 if (name && name[0])
Greg Clayton4ed315f2011-06-21 01:34:41 +00002048 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00002049 TargetSP target_sp(GetSP());
2050 if (target_sp)
2051 {
2052 const bool symbols_ok = true;
Sean Callanan302d78c2012-02-10 22:52:19 +00002053 const bool inlines_ok = true;
Greg Clayton7dd5c512012-02-06 01:44:54 +00002054 const bool append = true;
2055 target_sp->GetImages().FindFunctions (ConstString(name),
2056 name_type_mask,
Sean Callanan302d78c2012-02-10 22:52:19 +00002057 symbols_ok,
2058 inlines_ok,
Greg Clayton7dd5c512012-02-06 01:44:54 +00002059 append,
2060 *sb_sc_list);
Greg Clayton0416bdf2012-01-30 09:04:36 +00002061 }
Greg Clayton4ed315f2011-06-21 01:34:41 +00002062 }
Greg Clayton7dd5c512012-02-06 01:44:54 +00002063 return sb_sc_list;
Greg Clayton4ed315f2011-06-21 01:34:41 +00002064}
2065
Enrico Granata979e20d2011-07-29 19:53:35 +00002066lldb::SBType
Greg Clayton0b93a752012-12-05 21:24:42 +00002067SBTarget::FindFirstType (const char* typename_cstr)
Enrico Granata979e20d2011-07-29 19:53:35 +00002068{
Greg Clayton0416bdf2012-01-30 09:04:36 +00002069 TargetSP target_sp(GetSP());
Greg Clayton0b93a752012-12-05 21:24:42 +00002070 if (typename_cstr && typename_cstr[0] && target_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +00002071 {
Greg Clayton0b93a752012-12-05 21:24:42 +00002072 ConstString const_typename(typename_cstr);
2073 SymbolContext sc;
2074 const bool exact_match = false;
2075
2076 const ModuleList &module_list = target_sp->GetImages();
2077 size_t count = module_list.GetSize();
Enrico Granata979e20d2011-07-29 19:53:35 +00002078 for (size_t idx = 0; idx < count; idx++)
2079 {
Greg Clayton0b93a752012-12-05 21:24:42 +00002080 ModuleSP module_sp (module_list.GetModuleAtIndex(idx));
2081 if (module_sp)
2082 {
2083 TypeSP type_sp (module_sp->FindFirstType(sc, const_typename, exact_match));
2084 if (type_sp)
2085 return SBType(type_sp);
2086 }
Enrico Granata979e20d2011-07-29 19:53:35 +00002087 }
Greg Clayton0b93a752012-12-05 21:24:42 +00002088
2089 // No matches, search for basic typename matches
2090 ClangASTContext *clang_ast = target_sp->GetScratchClangASTContext();
2091 if (clang_ast)
2092 return SBType (ClangASTType::GetBasicType (clang_ast->getASTContext(), const_typename));
Enrico Granata979e20d2011-07-29 19:53:35 +00002093 }
2094 return SBType();
2095}
2096
Greg Clayton0b93a752012-12-05 21:24:42 +00002097SBType
2098SBTarget::GetBasicType(lldb::BasicType type)
Enrico Granata979e20d2011-07-29 19:53:35 +00002099{
Greg Clayton0416bdf2012-01-30 09:04:36 +00002100 TargetSP target_sp(GetSP());
Greg Clayton0b93a752012-12-05 21:24:42 +00002101 if (target_sp)
2102 {
2103 ClangASTContext *clang_ast = target_sp->GetScratchClangASTContext();
2104 if (clang_ast)
2105 return SBType (ClangASTType::GetBasicType (clang_ast->getASTContext(), type));
2106 }
2107 return SBType();
2108}
2109
2110
2111lldb::SBTypeList
2112SBTarget::FindTypes (const char* typename_cstr)
2113{
2114 SBTypeList sb_type_list;
2115 TargetSP target_sp(GetSP());
2116 if (typename_cstr && typename_cstr[0] && target_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +00002117 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00002118 ModuleList& images = target_sp->GetImages();
Greg Clayton0b93a752012-12-05 21:24:42 +00002119 ConstString const_typename(typename_cstr);
Greg Claytondc0a38c2012-03-26 23:03:23 +00002120 bool exact_match = false;
Enrico Granata979e20d2011-07-29 19:53:35 +00002121 SymbolContext sc;
2122 TypeList type_list;
2123
Greg Clayton9f95fb62012-04-06 17:41:13 +00002124 uint32_t num_matches = images.FindTypes (sc,
Greg Clayton0b93a752012-12-05 21:24:42 +00002125 const_typename,
Greg Claytondc0a38c2012-03-26 23:03:23 +00002126 exact_match,
2127 UINT32_MAX,
2128 type_list);
Enrico Granata979e20d2011-07-29 19:53:35 +00002129
Greg Clayton0b93a752012-12-05 21:24:42 +00002130 if (num_matches > 0)
Enrico Granata979e20d2011-07-29 19:53:35 +00002131 {
Greg Clayton0b93a752012-12-05 21:24:42 +00002132 for (size_t idx = 0; idx < num_matches; idx++)
2133 {
2134 TypeSP type_sp (type_list.GetTypeAtIndex(idx));
2135 if (type_sp)
2136 sb_type_list.Append(SBType(type_sp));
2137 }
2138 }
2139 else
2140 {
2141 // No matches, search for basic typename matches
2142 ClangASTContext *clang_ast = target_sp->GetScratchClangASTContext();
2143 if (clang_ast)
2144 sb_type_list.Append (SBType (ClangASTType::GetBasicType (clang_ast->getASTContext(), const_typename)));
Enrico Granata979e20d2011-07-29 19:53:35 +00002145 }
2146 }
Greg Clayton0b93a752012-12-05 21:24:42 +00002147 return sb_type_list;
Enrico Granata979e20d2011-07-29 19:53:35 +00002148}
2149
Greg Clayton917c0002011-06-29 22:09:02 +00002150SBValueList
2151SBTarget::FindGlobalVariables (const char *name, uint32_t max_matches)
2152{
2153 SBValueList sb_value_list;
2154
Greg Clayton0416bdf2012-01-30 09:04:36 +00002155 TargetSP target_sp(GetSP());
2156 if (name && target_sp)
Greg Clayton917c0002011-06-29 22:09:02 +00002157 {
2158 VariableList variable_list;
2159 const bool append = true;
Greg Clayton0416bdf2012-01-30 09:04:36 +00002160 const uint32_t match_count = target_sp->GetImages().FindGlobalVariables (ConstString (name),
2161 append,
2162 max_matches,
2163 variable_list);
Greg Clayton917c0002011-06-29 22:09:02 +00002164
2165 if (match_count > 0)
2166 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00002167 ExecutionContextScope *exe_scope = target_sp->GetProcessSP().get();
Greg Clayton917c0002011-06-29 22:09:02 +00002168 if (exe_scope == NULL)
Greg Clayton0416bdf2012-01-30 09:04:36 +00002169 exe_scope = target_sp.get();
Greg Clayton917c0002011-06-29 22:09:02 +00002170 ValueObjectList &value_object_list = sb_value_list.ref();
2171 for (uint32_t i=0; i<match_count; ++i)
2172 {
2173 lldb::ValueObjectSP valobj_sp (ValueObjectVariable::Create (exe_scope, variable_list.GetVariableAtIndex(i)));
2174 if (valobj_sp)
2175 value_object_list.Append(valobj_sp);
2176 }
2177 }
2178 }
2179
2180 return sb_value_list;
2181}
2182
Jim Inghamcc637462011-09-13 00:29:56 +00002183SBSourceManager
2184SBTarget::GetSourceManager()
2185{
2186 SBSourceManager source_manager (*this);
2187 return source_manager;
2188}
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002189
Sean Callananef1f6902011-12-14 23:49:37 +00002190lldb::SBInstructionList
Greg Claytona9893072012-03-06 22:24:44 +00002191SBTarget::ReadInstructions (lldb::SBAddress base_addr, uint32_t count)
2192{
2193 SBInstructionList sb_instructions;
2194
2195 TargetSP target_sp(GetSP());
2196 if (target_sp)
2197 {
2198 Address *addr_ptr = base_addr.get();
2199
2200 if (addr_ptr)
2201 {
2202 DataBufferHeap data (target_sp->GetArchitecture().GetMaximumOpcodeByteSize() * count, 0);
2203 bool prefer_file_cache = false;
2204 lldb_private::Error error;
2205 const size_t bytes_read = target_sp->ReadMemory(*addr_ptr, prefer_file_cache, data.GetBytes(), data.GetByteSize(), error);
2206 sb_instructions.SetDisassembler (Disassembler::DisassembleBytes (target_sp->GetArchitecture(),
2207 NULL,
2208 *addr_ptr,
2209 data.GetBytes(),
2210 bytes_read,
2211 count));
2212 }
2213 }
2214
2215 return sb_instructions;
2216
2217}
2218
2219lldb::SBInstructionList
Sean Callananef1f6902011-12-14 23:49:37 +00002220SBTarget::GetInstructions (lldb::SBAddress base_addr, const void *buf, size_t size)
2221{
2222 SBInstructionList sb_instructions;
2223
Greg Clayton0416bdf2012-01-30 09:04:36 +00002224 TargetSP target_sp(GetSP());
2225 if (target_sp)
Sean Callananef1f6902011-12-14 23:49:37 +00002226 {
2227 Address addr;
2228
2229 if (base_addr.get())
2230 addr = *base_addr.get();
2231
Greg Clayton0416bdf2012-01-30 09:04:36 +00002232 sb_instructions.SetDisassembler (Disassembler::DisassembleBytes (target_sp->GetArchitecture(),
Sean Callananef1f6902011-12-14 23:49:37 +00002233 NULL,
2234 addr,
2235 buf,
2236 size));
2237 }
2238
2239 return sb_instructions;
2240}
2241
2242lldb::SBInstructionList
2243SBTarget::GetInstructions (lldb::addr_t base_addr, const void *buf, size_t size)
2244{
2245 return GetInstructions (ResolveLoadAddress(base_addr), buf, size);
2246}
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002247
2248SBError
2249SBTarget::SetSectionLoadAddress (lldb::SBSection section,
2250 lldb::addr_t section_base_addr)
2251{
2252 SBError sb_error;
Greg Clayton0416bdf2012-01-30 09:04:36 +00002253 TargetSP target_sp(GetSP());
2254 if (target_sp)
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002255 {
2256 if (!section.IsValid())
2257 {
2258 sb_error.SetErrorStringWithFormat ("invalid section");
2259 }
2260 else
2261 {
Greg Clayton9ab696e2012-03-27 21:10:07 +00002262 SectionSP section_sp (section.GetSP());
2263 if (section_sp)
2264 {
2265 if (section_sp->IsThreadSpecific())
2266 {
2267 sb_error.SetErrorString ("thread specific sections are not yet supported");
2268 }
2269 else
2270 {
Greg Clayton545762f2012-07-07 01:24:12 +00002271 target_sp->GetSectionLoadList().SetSectionLoadAddress (section_sp, section_base_addr);
Greg Clayton9ab696e2012-03-27 21:10:07 +00002272 }
2273 }
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002274 }
2275 }
2276 else
2277 {
Greg Clayton9ab696e2012-03-27 21:10:07 +00002278 sb_error.SetErrorString ("invalid target");
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002279 }
2280 return sb_error;
2281}
2282
2283SBError
2284SBTarget::ClearSectionLoadAddress (lldb::SBSection section)
2285{
2286 SBError sb_error;
2287
Greg Clayton0416bdf2012-01-30 09:04:36 +00002288 TargetSP target_sp(GetSP());
2289 if (target_sp)
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002290 {
2291 if (!section.IsValid())
2292 {
2293 sb_error.SetErrorStringWithFormat ("invalid section");
2294 }
2295 else
2296 {
Greg Clayton545762f2012-07-07 01:24:12 +00002297 target_sp->GetSectionLoadList().SetSectionUnloaded (section.GetSP());
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002298 }
2299 }
2300 else
2301 {
2302 sb_error.SetErrorStringWithFormat ("invalid target");
2303 }
2304 return sb_error;
2305}
2306
2307SBError
2308SBTarget::SetModuleLoadAddress (lldb::SBModule module, int64_t slide_offset)
2309{
2310 SBError sb_error;
2311
Greg Clayton0416bdf2012-01-30 09:04:36 +00002312 TargetSP target_sp(GetSP());
2313 if (target_sp)
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002314 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00002315 ModuleSP module_sp (module.GetSP());
2316 if (module_sp)
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002317 {
Greg Clayton9ab696e2012-03-27 21:10:07 +00002318 bool changed = false;
2319 if (module_sp->SetLoadAddress (*target_sp, slide_offset, changed))
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002320 {
Greg Clayton9ab696e2012-03-27 21:10:07 +00002321 // The load was successful, make sure that at least some sections
2322 // changed before we notify that our module was loaded.
2323 if (changed)
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002324 {
Greg Clayton9ab696e2012-03-27 21:10:07 +00002325 ModuleList module_list;
2326 module_list.Append(module_sp);
2327 target_sp->ModulesDidLoad (module_list);
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002328 }
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002329 }
2330 }
Greg Clayton0416bdf2012-01-30 09:04:36 +00002331 else
2332 {
2333 sb_error.SetErrorStringWithFormat ("invalid module");
2334 }
2335
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002336 }
2337 else
2338 {
2339 sb_error.SetErrorStringWithFormat ("invalid target");
2340 }
2341 return sb_error;
2342}
2343
2344SBError
2345SBTarget::ClearModuleLoadAddress (lldb::SBModule module)
2346{
2347 SBError sb_error;
2348
2349 char path[PATH_MAX];
Greg Clayton0416bdf2012-01-30 09:04:36 +00002350 TargetSP target_sp(GetSP());
2351 if (target_sp)
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002352 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00002353 ModuleSP module_sp (module.GetSP());
2354 if (module_sp)
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002355 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00002356 ObjectFile *objfile = module_sp->GetObjectFile();
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002357 if (objfile)
2358 {
2359 SectionList *section_list = objfile->GetSectionList();
2360 if (section_list)
2361 {
2362 const size_t num_sections = section_list->GetSize();
2363 for (size_t sect_idx = 0; sect_idx < num_sections; ++sect_idx)
2364 {
2365 SectionSP section_sp (section_list->GetSectionAtIndex(sect_idx));
2366 if (section_sp)
Greg Clayton545762f2012-07-07 01:24:12 +00002367 target_sp->GetSectionLoadList().SetSectionUnloaded (section_sp);
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002368 }
2369 }
2370 else
2371 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00002372 module_sp->GetFileSpec().GetPath (path, sizeof(path));
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002373 sb_error.SetErrorStringWithFormat ("no sections in object file '%s'", path);
2374 }
2375 }
2376 else
2377 {
Greg Clayton0416bdf2012-01-30 09:04:36 +00002378 module_sp->GetFileSpec().GetPath (path, sizeof(path));
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002379 sb_error.SetErrorStringWithFormat ("no object file for module '%s'", path);
2380 }
2381 }
Greg Clayton0416bdf2012-01-30 09:04:36 +00002382 else
2383 {
2384 sb_error.SetErrorStringWithFormat ("invalid module");
2385 }
Greg Clayton3e8c25f2011-09-24 00:52:29 +00002386 }
2387 else
2388 {
2389 sb_error.SetErrorStringWithFormat ("invalid target");
2390 }
2391 return sb_error;
2392}
2393
2394
Greg Claytonb3dafc62012-12-04 02:22:16 +00002395lldb::SBSymbolContextList
2396SBTarget::FindSymbols (const char *name, lldb::SymbolType symbol_type)
2397{
2398 SBSymbolContextList sb_sc_list;
2399 if (name && name[0])
2400 {
2401 TargetSP target_sp(GetSP());
2402 if (target_sp)
2403 {
2404 bool append = true;
2405 target_sp->GetImages().FindSymbolsWithNameAndType (ConstString(name),
2406 symbol_type,
2407 *sb_sc_list,
2408 append);
2409 }
2410 }
2411 return sb_sc_list;
2412
2413}
2414
2415