blob: d87d156c1c92ea924c03ead587bb980ef14e37ba [file] [log] [blame]
Chris Lattner30fdc8d2010-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 Malea93a64302012-12-05 00:20:57 +000010#include "lldb/lldb-python.h"
11
Eli Friedman4c5de692010-06-09 07:44:37 +000012#include "lldb/API/SBTarget.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000013
Greg Claytone0d378b2011-03-24 21:19:54 +000014#include "lldb/lldb-public.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000015
Greg Claytondea8cb42011-06-29 22:09:02 +000016#include "lldb/API/SBDebugger.h"
17#include "lldb/API/SBBreakpoint.h"
Greg Clayton4b63a5c2013-01-04 18:10:18 +000018#include "lldb/API/SBExpressionOptions.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000019#include "lldb/API/SBFileSpec.h"
Greg Claytondea8cb42011-06-29 22:09:02 +000020#include "lldb/API/SBListener.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000021#include "lldb/API/SBModule.h"
Greg Clayton226cce22013-07-08 22:22:41 +000022#include "lldb/API/SBModuleSpec.h"
Jim Inghame37d6052011-09-13 00:29:56 +000023#include "lldb/API/SBSourceManager.h"
Greg Claytondea8cb42011-06-29 22:09:02 +000024#include "lldb/API/SBProcess.h"
Caroline Ticedde9cff2010-09-20 05:20:02 +000025#include "lldb/API/SBStream.h"
Greg Claytonfe356d32011-06-21 01:34:41 +000026#include "lldb/API/SBSymbolContextList.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000027#include "lldb/Breakpoint/BreakpointID.h"
28#include "lldb/Breakpoint/BreakpointIDList.h"
29#include "lldb/Breakpoint/BreakpointList.h"
30#include "lldb/Breakpoint/BreakpointLocation.h"
31#include "lldb/Core/Address.h"
32#include "lldb/Core/AddressResolver.h"
33#include "lldb/Core/AddressResolverName.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000034#include "lldb/Core/ArchSpec.h"
35#include "lldb/Core/Debugger.h"
36#include "lldb/Core/Disassembler.h"
Caroline Ticeceb6b132010-10-26 03:11:13 +000037#include "lldb/Core/Log.h"
Greg Clayton1f746072012-08-29 21:13:06 +000038#include "lldb/Core/Module.h"
39#include "lldb/Core/ModuleSpec.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000040#include "lldb/Core/RegularExpression.h"
41#include "lldb/Core/SearchFilter.h"
Greg Clayton1f746072012-08-29 21:13:06 +000042#include "lldb/Core/Section.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000043#include "lldb/Core/STLUtils.h"
Enrico Granata347c2aa2013-10-08 21:49:02 +000044#include "lldb/Core/ValueObjectConstResult.h"
Greg Claytondea8cb42011-06-29 22:09:02 +000045#include "lldb/Core/ValueObjectList.h"
46#include "lldb/Core/ValueObjectVariable.h"
47#include "lldb/Host/FileSpec.h"
Greg Clayton7fb56d02011-02-01 01:31:41 +000048#include "lldb/Host/Host.h"
Greg Claytondea8cb42011-06-29 22:09:02 +000049#include "lldb/Interpreter/Args.h"
Greg Clayton1f746072012-08-29 21:13:06 +000050#include "lldb/Symbol/ObjectFile.h"
Enrico Granata6f3533f2011-07-29 19:53:35 +000051#include "lldb/Symbol/SymbolVendor.h"
Greg Claytondea8cb42011-06-29 22:09:02 +000052#include "lldb/Symbol/VariableList.h"
Jim Inghamfab10e82012-03-06 00:37:27 +000053#include "lldb/Target/LanguageRuntime.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000054#include "lldb/Target/Process.h"
Greg Claytond5944cd2013-12-06 01:12:00 +000055
Chris Lattner30fdc8d2010-06-08 16:52:24 +000056#include "lldb/Target/Target.h"
57#include "lldb/Target/TargetList.h"
58
59#include "lldb/Interpreter/CommandReturnObject.h"
60#include "../source/Commands/CommandObjectBreakpoint.h"
Carlo Kok0fd6fd42014-09-19 19:38:19 +000061#include "llvm/Support/Regex.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000062
Chris Lattner30fdc8d2010-06-08 16:52:24 +000063
64using namespace lldb;
65using namespace lldb_private;
66
67#define DEFAULT_DISASM_BYTE_SIZE 32
68
Greg Clayton38d1f052012-02-24 20:59:25 +000069SBLaunchInfo::SBLaunchInfo (const char **argv) :
70 m_opaque_sp(new ProcessLaunchInfo())
Greg Clayton0e615682012-02-24 05:03:03 +000071{
Greg Clayton38d1f052012-02-24 20:59:25 +000072 m_opaque_sp->GetFlags().Reset (eLaunchFlagDebug | eLaunchFlagDisableASLR);
73 if (argv && argv[0])
74 m_opaque_sp->GetArguments().SetArguments(argv);
Greg Clayton0e615682012-02-24 05:03:03 +000075}
76
Greg Claytonecc7c0d2012-03-07 23:52:51 +000077SBLaunchInfo::~SBLaunchInfo()
78{
79}
80
81lldb_private::ProcessLaunchInfo &
82SBLaunchInfo::ref ()
83{
84 return *m_opaque_sp;
85}
86
87
Greg Clayton0e615682012-02-24 05:03:03 +000088uint32_t
89SBLaunchInfo::GetUserID()
90{
91 return m_opaque_sp->GetUserID();
92}
93
94uint32_t
95SBLaunchInfo::GetGroupID()
96{
97 return m_opaque_sp->GetGroupID();
98}
99
100bool
101SBLaunchInfo::UserIDIsValid ()
102{
103 return m_opaque_sp->UserIDIsValid();
104}
105
106bool
107SBLaunchInfo::GroupIDIsValid ()
108{
109 return m_opaque_sp->GroupIDIsValid();
110}
111
112void
113SBLaunchInfo::SetUserID (uint32_t uid)
114{
115 m_opaque_sp->SetUserID (uid);
116}
117
118void
119SBLaunchInfo::SetGroupID (uint32_t gid)
120{
121 m_opaque_sp->SetGroupID (gid);
122}
123
Greg Clayton3e32ad62014-05-07 20:16:06 +0000124SBFileSpec
125SBLaunchInfo::GetExecutableFile ()
126{
127 return SBFileSpec (m_opaque_sp->GetExecutableFile());
128}
129
130void
131SBLaunchInfo::SetExecutableFile (SBFileSpec exe_file, bool add_as_first_arg)
132{
133 m_opaque_sp->SetExecutableFile(exe_file.ref(), add_as_first_arg);
134}
135
Greg Clayton8012cad2014-11-17 19:39:20 +0000136SBListener
137SBLaunchInfo::GetListener ()
138{
139 return SBListener(m_opaque_sp->GetListener());
140}
141
142void
143SBLaunchInfo::SetListener (SBListener &listener)
144{
145 m_opaque_sp->SetListener(listener.GetSP());
146}
147
Greg Clayton0e615682012-02-24 05:03:03 +0000148uint32_t
149SBLaunchInfo::GetNumArguments ()
150{
151 return m_opaque_sp->GetArguments().GetArgumentCount();
152}
153
154const char *
155SBLaunchInfo::GetArgumentAtIndex (uint32_t idx)
156{
157 return m_opaque_sp->GetArguments().GetArgumentAtIndex(idx);
158}
159
160void
161SBLaunchInfo::SetArguments (const char **argv, bool append)
162{
163 if (append)
164 {
165 if (argv)
166 m_opaque_sp->GetArguments().AppendArguments(argv);
167 }
168 else
169 {
170 if (argv)
171 m_opaque_sp->GetArguments().SetArguments(argv);
172 else
173 m_opaque_sp->GetArguments().Clear();
174 }
175}
176
177uint32_t
178SBLaunchInfo::GetNumEnvironmentEntries ()
179{
180 return m_opaque_sp->GetEnvironmentEntries().GetArgumentCount();
181}
182
183const char *
184SBLaunchInfo::GetEnvironmentEntryAtIndex (uint32_t idx)
185{
186 return m_opaque_sp->GetEnvironmentEntries().GetArgumentAtIndex(idx);
187}
188
189void
190SBLaunchInfo::SetEnvironmentEntries (const char **envp, bool append)
191{
192 if (append)
193 {
194 if (envp)
195 m_opaque_sp->GetEnvironmentEntries().AppendArguments(envp);
196 }
197 else
198 {
199 if (envp)
200 m_opaque_sp->GetEnvironmentEntries().SetArguments(envp);
201 else
202 m_opaque_sp->GetEnvironmentEntries().Clear();
203 }
204}
205
206void
207SBLaunchInfo::Clear ()
208{
209 m_opaque_sp->Clear();
210}
211
212const char *
213SBLaunchInfo::GetWorkingDirectory () const
214{
215 return m_opaque_sp->GetWorkingDirectory();
216}
217
218void
219SBLaunchInfo::SetWorkingDirectory (const char *working_dir)
220{
221 m_opaque_sp->SetWorkingDirectory(working_dir);
222}
223
224uint32_t
225SBLaunchInfo::GetLaunchFlags ()
226{
227 return m_opaque_sp->GetFlags().Get();
228}
229
230void
231SBLaunchInfo::SetLaunchFlags (uint32_t flags)
232{
233 m_opaque_sp->GetFlags().Reset(flags);
234}
235
236const char *
237SBLaunchInfo::GetProcessPluginName ()
238{
239 return m_opaque_sp->GetProcessPluginName();
240}
241
242void
243SBLaunchInfo::SetProcessPluginName (const char *plugin_name)
244{
245 return m_opaque_sp->SetProcessPluginName (plugin_name);
246}
247
248const char *
249SBLaunchInfo::GetShell ()
250{
Zachary Turner10687b02014-10-20 17:46:43 +0000251 // Constify this string so that it is saved in the string pool. Otherwise
252 // it would be freed when this function goes out of scope.
253 ConstString shell(m_opaque_sp->GetShell().GetPath().c_str());
254 return shell.AsCString();
Greg Clayton0e615682012-02-24 05:03:03 +0000255}
256
257void
258SBLaunchInfo::SetShell (const char * path)
259{
Zachary Turner10687b02014-10-20 17:46:43 +0000260 m_opaque_sp->SetShell (FileSpec(path, false));
Greg Clayton0e615682012-02-24 05:03:03 +0000261}
262
263uint32_t
264SBLaunchInfo::GetResumeCount ()
265{
266 return m_opaque_sp->GetResumeCount();
267}
268
269void
270SBLaunchInfo::SetResumeCount (uint32_t c)
271{
272 m_opaque_sp->SetResumeCount (c);
273}
274
275bool
276SBLaunchInfo::AddCloseFileAction (int fd)
277{
278 return m_opaque_sp->AppendCloseFileAction(fd);
279}
280
281bool
282SBLaunchInfo::AddDuplicateFileAction (int fd, int dup_fd)
283{
284 return m_opaque_sp->AppendDuplicateFileAction(fd, dup_fd);
285}
286
287bool
288SBLaunchInfo::AddOpenFileAction (int fd, const char *path, bool read, bool write)
289{
290 return m_opaque_sp->AppendOpenFileAction(fd, path, read, write);
291}
292
293bool
294SBLaunchInfo::AddSuppressFileAction (int fd, bool read, bool write)
295{
296 return m_opaque_sp->AppendSuppressFileAction(fd, read, write);
297}
298
Jason Molendaa3329782014-03-29 18:54:20 +0000299void
300SBLaunchInfo::SetLaunchEventData (const char *data)
301{
302 m_opaque_sp->SetLaunchEventData (data);
303}
304
305const char *
306SBLaunchInfo::GetLaunchEventData () const
307{
308 return m_opaque_sp->GetLaunchEventData ();
309}
Greg Clayton0e615682012-02-24 05:03:03 +0000310
Jim Ingham106d0282014-06-25 02:32:56 +0000311void
312SBLaunchInfo::SetDetachOnError (bool enable)
313{
314 m_opaque_sp->SetDetachOnError (enable);
315}
316
317bool
318SBLaunchInfo::GetDetachOnError () const
319{
320 return m_opaque_sp->GetDetachOnError ();
321}
322
Greg Clayton0e615682012-02-24 05:03:03 +0000323SBAttachInfo::SBAttachInfo () :
Greg Claytonecc7c0d2012-03-07 23:52:51 +0000324 m_opaque_sp (new ProcessAttachInfo())
Greg Clayton0e615682012-02-24 05:03:03 +0000325{
326}
327
328SBAttachInfo::SBAttachInfo (lldb::pid_t pid) :
Greg Claytonecc7c0d2012-03-07 23:52:51 +0000329 m_opaque_sp (new ProcessAttachInfo())
Greg Clayton0e615682012-02-24 05:03:03 +0000330{
331 m_opaque_sp->SetProcessID (pid);
332}
333
334SBAttachInfo::SBAttachInfo (const char *path, bool wait_for) :
Greg Claytonecc7c0d2012-03-07 23:52:51 +0000335 m_opaque_sp (new ProcessAttachInfo())
Greg Clayton0e615682012-02-24 05:03:03 +0000336{
337 if (path && path[0])
338 m_opaque_sp->GetExecutableFile().SetFile(path, false);
339 m_opaque_sp->SetWaitForLaunch (wait_for);
340}
341
342SBAttachInfo::SBAttachInfo (const SBAttachInfo &rhs) :
Greg Claytonecc7c0d2012-03-07 23:52:51 +0000343 m_opaque_sp (new ProcessAttachInfo())
Greg Clayton0e615682012-02-24 05:03:03 +0000344{
345 *m_opaque_sp = *rhs.m_opaque_sp;
346}
347
Greg Claytonecc7c0d2012-03-07 23:52:51 +0000348SBAttachInfo::~SBAttachInfo()
349{
350}
351
352lldb_private::ProcessAttachInfo &
353SBAttachInfo::ref ()
354{
355 return *m_opaque_sp;
356}
357
Greg Clayton0e615682012-02-24 05:03:03 +0000358SBAttachInfo &
359SBAttachInfo::operator = (const SBAttachInfo &rhs)
360{
361 if (this != &rhs)
362 *m_opaque_sp = *rhs.m_opaque_sp;
363 return *this;
364}
365
366lldb::pid_t
367SBAttachInfo::GetProcessID ()
368{
369 return m_opaque_sp->GetProcessID();
370}
371
372void
373SBAttachInfo::SetProcessID (lldb::pid_t pid)
374{
375 m_opaque_sp->SetProcessID (pid);
376}
377
378
379uint32_t
380SBAttachInfo::GetResumeCount ()
381{
382 return m_opaque_sp->GetResumeCount();
383}
384
385void
386SBAttachInfo::SetResumeCount (uint32_t c)
387{
388 m_opaque_sp->SetResumeCount (c);
389}
390
391const char *
392SBAttachInfo::GetProcessPluginName ()
393{
394 return m_opaque_sp->GetProcessPluginName();
395}
396
397void
398SBAttachInfo::SetProcessPluginName (const char *plugin_name)
399{
400 return m_opaque_sp->SetProcessPluginName (plugin_name);
401}
402
403void
404SBAttachInfo::SetExecutable (const char *path)
405{
406 if (path && path[0])
407 m_opaque_sp->GetExecutableFile().SetFile(path, false);
408 else
409 m_opaque_sp->GetExecutableFile().Clear();
410}
411
412void
413SBAttachInfo::SetExecutable (SBFileSpec exe_file)
414{
415 if (exe_file.IsValid())
416 m_opaque_sp->GetExecutableFile() = exe_file.ref();
417 else
418 m_opaque_sp->GetExecutableFile().Clear();
419}
420
421bool
422SBAttachInfo::GetWaitForLaunch ()
423{
424 return m_opaque_sp->GetWaitForLaunch();
425}
426
427void
428SBAttachInfo::SetWaitForLaunch (bool b)
429{
430 m_opaque_sp->SetWaitForLaunch (b);
431}
432
Jim Inghamcd16df92012-07-20 21:37:13 +0000433bool
434SBAttachInfo::GetIgnoreExisting ()
435{
436 return m_opaque_sp->GetIgnoreExisting();
437}
438
439void
440SBAttachInfo::SetIgnoreExisting (bool b)
441{
442 m_opaque_sp->SetIgnoreExisting (b);
443}
444
Greg Clayton0e615682012-02-24 05:03:03 +0000445uint32_t
Greg Clayton41bd8ac2012-02-24 23:56:06 +0000446SBAttachInfo::GetUserID()
447{
448 return m_opaque_sp->GetUserID();
449}
450
451uint32_t
452SBAttachInfo::GetGroupID()
453{
454 return m_opaque_sp->GetGroupID();
455}
456
457bool
458SBAttachInfo::UserIDIsValid ()
459{
460 return m_opaque_sp->UserIDIsValid();
461}
462
463bool
464SBAttachInfo::GroupIDIsValid ()
465{
466 return m_opaque_sp->GroupIDIsValid();
467}
468
469void
470SBAttachInfo::SetUserID (uint32_t uid)
471{
472 m_opaque_sp->SetUserID (uid);
473}
474
475void
476SBAttachInfo::SetGroupID (uint32_t gid)
477{
478 m_opaque_sp->SetGroupID (gid);
479}
480
481uint32_t
Greg Clayton0e615682012-02-24 05:03:03 +0000482SBAttachInfo::GetEffectiveUserID()
483{
484 return m_opaque_sp->GetEffectiveUserID();
485}
486
487uint32_t
488SBAttachInfo::GetEffectiveGroupID()
489{
490 return m_opaque_sp->GetEffectiveGroupID();
491}
492
493bool
494SBAttachInfo::EffectiveUserIDIsValid ()
495{
496 return m_opaque_sp->EffectiveUserIDIsValid();
497}
498
499bool
500SBAttachInfo::EffectiveGroupIDIsValid ()
501{
502 return m_opaque_sp->EffectiveGroupIDIsValid ();
503}
504
505void
506SBAttachInfo::SetEffectiveUserID (uint32_t uid)
507{
508 m_opaque_sp->SetEffectiveUserID(uid);
509}
510
511void
512SBAttachInfo::SetEffectiveGroupID (uint32_t gid)
513{
514 m_opaque_sp->SetEffectiveGroupID(gid);
515}
516
517lldb::pid_t
518SBAttachInfo::GetParentProcessID ()
519{
520 return m_opaque_sp->GetParentProcessID();
521}
522
523void
524SBAttachInfo::SetParentProcessID (lldb::pid_t pid)
525{
526 m_opaque_sp->SetParentProcessID (pid);
527}
528
529bool
530SBAttachInfo::ParentProcessIDIsValid()
531{
532 return m_opaque_sp->ParentProcessIDIsValid();
533}
534
Greg Clayton8012cad2014-11-17 19:39:20 +0000535SBListener
536SBAttachInfo::GetListener ()
537{
538 return SBListener(m_opaque_sp->GetListener());
539}
540
541void
542SBAttachInfo::SetListener (SBListener &listener)
543{
544 m_opaque_sp->SetListener(listener.GetSP());
545}
Greg Clayton0e615682012-02-24 05:03:03 +0000546
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000547//----------------------------------------------------------------------
548// SBTarget constructor
549//----------------------------------------------------------------------
Greg Clayton54979cd2010-12-15 05:08:08 +0000550SBTarget::SBTarget () :
551 m_opaque_sp ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000552{
553}
554
555SBTarget::SBTarget (const SBTarget& rhs) :
Greg Clayton66111032010-06-23 01:19:29 +0000556 m_opaque_sp (rhs.m_opaque_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000557{
558}
559
560SBTarget::SBTarget(const TargetSP& target_sp) :
Greg Clayton66111032010-06-23 01:19:29 +0000561 m_opaque_sp (target_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000562{
563}
564
Greg Claytonefabb122010-11-05 23:17:00 +0000565const SBTarget&
566SBTarget::operator = (const SBTarget& rhs)
567{
568 if (this != &rhs)
569 m_opaque_sp = rhs.m_opaque_sp;
570 return *this;
571}
572
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000573//----------------------------------------------------------------------
574// Destructor
575//----------------------------------------------------------------------
576SBTarget::~SBTarget()
577{
578}
579
Jim Ingham4bddaeb2012-02-16 06:50:00 +0000580const char *
581SBTarget::GetBroadcasterClassName ()
582{
583 return Target::GetStaticBroadcasterClass().AsCString();
584}
585
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000586bool
587SBTarget::IsValid () const
588{
Filipe Cabecinhas721ba3f2012-05-19 09:59:08 +0000589 return m_opaque_sp.get() != NULL && m_opaque_sp->IsValid();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000590}
591
592SBProcess
593SBTarget::GetProcess ()
594{
595 SBProcess sb_process;
Greg Claytonb9556ac2012-01-30 07:41:31 +0000596 ProcessSP process_sp;
Greg Claytonacdbe812012-01-30 09:04:36 +0000597 TargetSP target_sp(GetSP());
598 if (target_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000599 {
Greg Claytonacdbe812012-01-30 09:04:36 +0000600 process_sp = target_sp->GetProcessSP();
Greg Claytonb9556ac2012-01-30 07:41:31 +0000601 sb_process.SetSP (process_sp);
Greg Claytonaf67cec2010-12-20 20:49:23 +0000602 }
Caroline Ticeceb6b132010-10-26 03:11:13 +0000603
Greg Clayton5160ce52013-03-27 23:08:40 +0000604 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000605 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000606 log->Printf ("SBTarget(%p)::GetProcess () => SBProcess(%p)",
607 static_cast<void*>(target_sp.get()),
608 static_cast<void*>(process_sp.get()));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000609
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000610 return sb_process;
611}
612
Matthew Gardinerc928de32014-10-22 07:22:56 +0000613SBPlatform
614SBTarget::GetPlatform ()
615{
616 TargetSP target_sp(GetSP());
617 if (!target_sp)
618 return SBPlatform();
619
620 SBPlatform platform;
621 platform.m_opaque_sp = target_sp->GetPlatform();
622
623 return platform;
624}
625
Greg Clayton66111032010-06-23 01:19:29 +0000626SBDebugger
627SBTarget::GetDebugger () const
628{
629 SBDebugger debugger;
Greg Claytonacdbe812012-01-30 09:04:36 +0000630 TargetSP target_sp(GetSP());
631 if (target_sp)
632 debugger.reset (target_sp->GetDebugger().shared_from_this());
Greg Clayton66111032010-06-23 01:19:29 +0000633 return debugger;
634}
635
Jim Ingham270684d2011-03-31 00:01:24 +0000636SBProcess
Greg Clayton4d8ad552013-03-25 22:40:51 +0000637SBTarget::LoadCore (const char *core_file)
638{
639 SBProcess sb_process;
640 TargetSP target_sp(GetSP());
641 if (target_sp)
642 {
643 FileSpec filespec(core_file, true);
644 ProcessSP process_sp (target_sp->CreateProcess(target_sp->GetDebugger().GetListener(),
645 NULL,
646 &filespec));
647 if (process_sp)
648 {
649 process_sp->LoadCore();
650 sb_process.SetSP (process_sp);
651 }
652 }
653 return sb_process;
654}
655
656SBProcess
Jim Ingham270684d2011-03-31 00:01:24 +0000657SBTarget::LaunchSimple
658(
659 char const **argv,
660 char const **envp,
661 const char *working_directory
662)
663{
664 char *stdin_path = NULL;
665 char *stdout_path = NULL;
666 char *stderr_path = NULL;
667 uint32_t launch_flags = 0;
668 bool stop_at_entry = false;
669 SBError error;
670 SBListener listener = GetDebugger().GetListener();
671 return Launch (listener,
672 argv,
673 envp,
674 stdin_path,
675 stdout_path,
676 stderr_path,
677 working_directory,
678 launch_flags,
679 stop_at_entry,
680 error);
681}
Greg Claytonbd82a5d2011-01-23 05:56:20 +0000682
Greg Claytonfbb76342013-11-20 21:07:01 +0000683SBError
684SBTarget::Install()
685{
686 SBError sb_error;
687 TargetSP target_sp(GetSP());
688 if (target_sp)
689 {
690 Mutex::Locker api_locker (target_sp->GetAPIMutex());
691 sb_error.ref() = target_sp->Install(NULL);
692 }
693 return sb_error;
694}
695
Greg Claytonbd82a5d2011-01-23 05:56:20 +0000696SBProcess
697SBTarget::Launch
698(
Greg Clayton4b045622011-02-03 21:28:34 +0000699 SBListener &listener,
Greg Claytonbd82a5d2011-01-23 05:56:20 +0000700 char const **argv,
701 char const **envp,
702 const char *stdin_path,
703 const char *stdout_path,
704 const char *stderr_path,
705 const char *working_directory,
706 uint32_t launch_flags, // See LaunchFlags
707 bool stop_at_entry,
708 lldb::SBError& error
709)
710{
Greg Clayton5160ce52013-03-27 23:08:40 +0000711 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000712
Greg Claytonacdbe812012-01-30 09:04:36 +0000713 SBProcess sb_process;
714 ProcessSP process_sp;
715 TargetSP target_sp(GetSP());
716
Caroline Ticeceb6b132010-10-26 03:11:13 +0000717 if (log)
Greg Claytonbd82a5d2011-01-23 05:56:20 +0000718 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))...",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000719 static_cast<void*>(target_sp.get()),
720 static_cast<void*>(argv), static_cast<void*>(envp),
721 stdin_path ? stdin_path : "NULL",
722 stdout_path ? stdout_path : "NULL",
723 stderr_path ? stderr_path : "NULL",
Greg Claytonbd82a5d2011-01-23 05:56:20 +0000724 working_directory ? working_directory : "NULL",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000725 launch_flags, stop_at_entry,
726 static_cast<void*>(error.get()));
Greg Claytonacdbe812012-01-30 09:04:36 +0000727
728 if (target_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000729 {
Greg Claytonacdbe812012-01-30 09:04:36 +0000730 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton5d5028b2010-10-06 03:53:16 +0000731
Zachary Turner6fd3f342015-02-02 18:50:01 +0000732 if (stop_at_entry)
733 launch_flags |= eLaunchFlagStopAtEntry;
734
Greg Clayton645bf542011-01-27 01:01:10 +0000735 if (getenv("LLDB_LAUNCH_FLAG_DISABLE_ASLR"))
736 launch_flags |= eLaunchFlagDisableASLR;
737
Greg Clayton2289fa42011-04-30 01:09:13 +0000738 StateType state = eStateInvalid;
Greg Claytonacdbe812012-01-30 09:04:36 +0000739 process_sp = target_sp->GetProcessSP();
Greg Claytonb9556ac2012-01-30 07:41:31 +0000740 if (process_sp)
Greg Clayton931180e2011-01-27 06:44:37 +0000741 {
Greg Claytonb9556ac2012-01-30 07:41:31 +0000742 state = process_sp->GetState();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000743
Greg Claytonb9556ac2012-01-30 07:41:31 +0000744 if (process_sp->IsAlive() && state != eStateConnected)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000745 {
Greg Clayton2289fa42011-04-30 01:09:13 +0000746 if (state == eStateAttaching)
747 error.SetErrorString ("process attach is in progress");
748 else
749 error.SetErrorString ("a process is already being debugged");
Greg Clayton2289fa42011-04-30 01:09:13 +0000750 return sb_process;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000751 }
Greg Clayton931180e2011-01-27 06:44:37 +0000752 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000753
Greg Clayton2289fa42011-04-30 01:09:13 +0000754 if (state == eStateConnected)
755 {
756 // If we are already connected, then we have already specified the
757 // listener, so if a valid listener is supplied, we need to error out
758 // to let the client know.
759 if (listener.IsValid())
760 {
761 error.SetErrorString ("process is connected and already has a listener, pass empty listener");
Greg Clayton2289fa42011-04-30 01:09:13 +0000762 return sb_process;
763 }
764 }
Greg Claytonb09c5382013-12-13 17:20:18 +0000765
766 if (getenv("LLDB_LAUNCH_FLAG_DISABLE_STDIO"))
767 launch_flags |= eLaunchFlagDisableSTDIO;
768
769 ProcessLaunchInfo launch_info (stdin_path, stdout_path, stderr_path, working_directory, launch_flags);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000770
Greg Claytonb09c5382013-12-13 17:20:18 +0000771 Module *exe_module = target_sp->GetExecutableModulePointer();
772 if (exe_module)
773 launch_info.SetExecutableFile(exe_module->GetPlatformFileSpec(), true);
774 if (argv)
775 launch_info.GetArguments().AppendArguments (argv);
776 if (envp)
777 launch_info.GetEnvironmentEntries ().SetArguments (envp);
778
779 if (listener.IsValid())
Greg Clayton8012cad2014-11-17 19:39:20 +0000780 launch_info.SetListener(listener.GetSP());
781
782 error.SetError (target_sp->Launch(launch_info, NULL));
Greg Clayton645bf542011-01-27 01:01:10 +0000783
Greg Claytonb09c5382013-12-13 17:20:18 +0000784 sb_process.SetSP(target_sp->GetProcessSP());
Greg Clayton524e60b2010-10-06 22:10:17 +0000785 }
786 else
787 {
788 error.SetErrorString ("SBTarget is invalid");
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000789 }
Caroline Ticeceb6b132010-10-26 03:11:13 +0000790
Caroline Tice20ad3c42010-10-29 21:48:37 +0000791 log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
Caroline Ticeceb6b132010-10-26 03:11:13 +0000792 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000793 log->Printf ("SBTarget(%p)::Launch (...) => SBProcess(%p)",
794 static_cast<void*>(target_sp.get()),
795 static_cast<void*>(sb_process.GetSP().get()));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000796
Greg Clayton5d5028b2010-10-06 03:53:16 +0000797 return sb_process;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000798}
799
Greg Clayton0e615682012-02-24 05:03:03 +0000800SBProcess
801SBTarget::Launch (SBLaunchInfo &sb_launch_info, SBError& error)
802{
Greg Clayton5160ce52013-03-27 23:08:40 +0000803 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000804
Greg Clayton0e615682012-02-24 05:03:03 +0000805 SBProcess sb_process;
Greg Clayton0e615682012-02-24 05:03:03 +0000806 TargetSP target_sp(GetSP());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000807
Greg Clayton0e615682012-02-24 05:03:03 +0000808 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000809 log->Printf ("SBTarget(%p)::Launch (launch_info, error)...",
810 static_cast<void*>(target_sp.get()));
811
Greg Clayton0e615682012-02-24 05:03:03 +0000812 if (target_sp)
813 {
814 Mutex::Locker api_locker (target_sp->GetAPIMutex());
815 StateType state = eStateInvalid;
Greg Claytonb09c5382013-12-13 17:20:18 +0000816 {
Greg Clayton3e32ad62014-05-07 20:16:06 +0000817 ProcessSP process_sp = target_sp->GetProcessSP();
818 if (process_sp)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000819 {
Greg Clayton3e32ad62014-05-07 20:16:06 +0000820 state = process_sp->GetState();
821
822 if (process_sp->IsAlive() && state != eStateConnected)
823 {
824 if (state == eStateAttaching)
825 error.SetErrorString ("process attach is in progress");
826 else
827 error.SetErrorString ("a process is already being debugged");
828 return sb_process;
829 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000830 }
Greg Clayton0e615682012-02-24 05:03:03 +0000831 }
Greg Claytonb09c5382013-12-13 17:20:18 +0000832
833 lldb_private::ProcessLaunchInfo &launch_info = sb_launch_info.ref();
834
Greg Clayton3e32ad62014-05-07 20:16:06 +0000835 if (!launch_info.GetExecutableFile())
836 {
837 Module *exe_module = target_sp->GetExecutableModulePointer();
838 if (exe_module)
839 launch_info.SetExecutableFile(exe_module->GetPlatformFileSpec(), true);
840 }
Greg Claytonb09c5382013-12-13 17:20:18 +0000841
842 const ArchSpec &arch_spec = target_sp->GetArchitecture();
843 if (arch_spec.IsValid())
844 launch_info.GetArchitecture () = arch_spec;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000845
Greg Clayton8012cad2014-11-17 19:39:20 +0000846 error.SetError (target_sp->Launch (launch_info, NULL));
Greg Claytonb09c5382013-12-13 17:20:18 +0000847 sb_process.SetSP(target_sp->GetProcessSP());
Greg Clayton0e615682012-02-24 05:03:03 +0000848 }
849 else
850 {
851 error.SetErrorString ("SBTarget is invalid");
852 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000853
Greg Clayton0e615682012-02-24 05:03:03 +0000854 log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
855 if (log)
Greg Claytonb09c5382013-12-13 17:20:18 +0000856 log->Printf ("SBTarget(%p)::Launch (...) => SBProcess(%p)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000857 static_cast<void*>(target_sp.get()),
858 static_cast<void*>(sb_process.GetSP().get()));
859
Greg Clayton0e615682012-02-24 05:03:03 +0000860 return sb_process;
861}
862
863lldb::SBProcess
864SBTarget::Attach (SBAttachInfo &sb_attach_info, SBError& error)
865{
Greg Clayton5160ce52013-03-27 23:08:40 +0000866 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000867
Greg Clayton0e615682012-02-24 05:03:03 +0000868 SBProcess sb_process;
869 ProcessSP process_sp;
870 TargetSP target_sp(GetSP());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000871
Sean Callanan575a4542012-10-20 00:21:31 +0000872 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000873 log->Printf ("SBTarget(%p)::Attach (sb_attach_info, error)...",
874 static_cast<void*>(target_sp.get()));
875
Greg Clayton0e615682012-02-24 05:03:03 +0000876 if (target_sp)
877 {
878 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000879
Greg Clayton0e615682012-02-24 05:03:03 +0000880 StateType state = eStateInvalid;
881 process_sp = target_sp->GetProcessSP();
882 if (process_sp)
883 {
884 state = process_sp->GetState();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000885
Greg Clayton0e615682012-02-24 05:03:03 +0000886 if (process_sp->IsAlive() && state != eStateConnected)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000887 {
Greg Clayton0e615682012-02-24 05:03:03 +0000888 if (state == eStateAttaching)
889 error.SetErrorString ("process attach is in progress");
890 else
891 error.SetErrorString ("a process is already being debugged");
Sean Callanan575a4542012-10-20 00:21:31 +0000892 if (log)
Sean Callanan575a4542012-10-20 00:21:31 +0000893 log->Printf ("SBTarget(%p)::Attach (...) => error %s",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000894 static_cast<void*>(target_sp.get()),
895 error.GetCString());
Greg Clayton0e615682012-02-24 05:03:03 +0000896 return sb_process;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000897 }
Greg Clayton0e615682012-02-24 05:03:03 +0000898 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000899
Greg Clayton0e615682012-02-24 05:03:03 +0000900 if (state != eStateConnected)
901 process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener(), NULL, NULL);
902
903 if (process_sp)
904 {
Greg Clayton0e615682012-02-24 05:03:03 +0000905 ProcessAttachInfo &attach_info = sb_attach_info.ref();
Han Ming Ongfbd8de82013-03-25 20:11:18 +0000906 if (attach_info.ProcessIDIsValid() && !attach_info.UserIDIsValid())
Han Ming Ongcec8c902012-02-29 00:12:56 +0000907 {
908 PlatformSP platform_sp = target_sp->GetPlatform();
Greg Clayton91e407e2012-09-27 00:03:39 +0000909 // See if we can pre-verify if a process exists or not
910 if (platform_sp && platform_sp->IsConnected())
Han Ming Ongcec8c902012-02-29 00:12:56 +0000911 {
Han Ming Ongfbd8de82013-03-25 20:11:18 +0000912 lldb::pid_t attach_pid = attach_info.GetProcessID();
Greg Clayton91e407e2012-09-27 00:03:39 +0000913 ProcessInstanceInfo instance_info;
914 if (platform_sp->GetProcessInfo(attach_pid, instance_info))
915 {
916 attach_info.SetUserID(instance_info.GetEffectiveUserID());
917 }
918 else
919 {
Daniel Malead01b2952012-11-29 21:49:15 +0000920 error.ref().SetErrorStringWithFormat("no process found with process ID %" PRIu64, attach_pid);
Sean Callanan575a4542012-10-20 00:21:31 +0000921 if (log)
922 {
923 log->Printf ("SBTarget(%p)::Attach (...) => error %s",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000924 static_cast<void*>(target_sp.get()), error.GetCString());
Sean Callanan575a4542012-10-20 00:21:31 +0000925 }
Greg Clayton91e407e2012-09-27 00:03:39 +0000926 return sb_process;
927 }
Han Ming Ongcec8c902012-02-29 00:12:56 +0000928 }
929 }
Han Ming Ongbee98392012-02-29 19:16:40 +0000930 error.SetError (process_sp->Attach (attach_info));
931 if (error.Success())
932 {
933 sb_process.SetSP (process_sp);
934 // If we are doing synchronous mode, then wait for the
935 // process to stop!
936 if (target_sp->GetDebugger().GetAsyncExecution () == false)
937 process_sp->WaitForProcessToStop (NULL);
938 }
Greg Clayton0e615682012-02-24 05:03:03 +0000939 }
940 else
941 {
942 error.SetErrorString ("unable to create lldb_private::Process");
943 }
944 }
945 else
946 {
947 error.SetErrorString ("SBTarget is invalid");
948 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000949
Sean Callanan575a4542012-10-20 00:21:31 +0000950 if (log)
Sean Callanan575a4542012-10-20 00:21:31 +0000951 log->Printf ("SBTarget(%p)::Attach (...) => SBProcess(%p)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000952 static_cast<void*>(target_sp.get()),
953 static_cast<void*>(process_sp.get()));
954
Greg Clayton0e615682012-02-24 05:03:03 +0000955 return sb_process;
956}
957
958
Greg Clayton1ba6cfd2011-12-02 02:10:57 +0000959#if defined(__APPLE__)
960
961lldb::SBProcess
962SBTarget::AttachToProcessWithID (SBListener &listener,
963 ::pid_t pid,
964 lldb::SBError& error)
965{
966 return AttachToProcessWithID (listener, (lldb::pid_t)pid, error);
967}
968
969#endif // #if defined(__APPLE__)
Greg Clayton524e60b2010-10-06 22:10:17 +0000970
971lldb::SBProcess
Greg Clayton05faeb72010-10-07 04:19:01 +0000972SBTarget::AttachToProcessWithID
Greg Clayton524e60b2010-10-06 22:10:17 +0000973(
Greg Clayton4b045622011-02-03 21:28:34 +0000974 SBListener &listener,
Greg Clayton524e60b2010-10-06 22:10:17 +0000975 lldb::pid_t pid,// The process ID to attach to
976 SBError& error // An error explaining what went wrong if attach fails
977)
978{
Greg Clayton5160ce52013-03-27 23:08:40 +0000979 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Sean Callanan575a4542012-10-20 00:21:31 +0000980
Greg Clayton524e60b2010-10-06 22:10:17 +0000981 SBProcess sb_process;
Greg Claytonb9556ac2012-01-30 07:41:31 +0000982 ProcessSP process_sp;
Greg Claytonacdbe812012-01-30 09:04:36 +0000983 TargetSP target_sp(GetSP());
Sean Callanan575a4542012-10-20 00:21:31 +0000984
985 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000986 log->Printf ("SBTarget(%p)::AttachToProcessWithID (listener, pid=%" PRId64 ", error)...",
987 static_cast<void*>(target_sp.get()), pid);
988
Greg Claytonacdbe812012-01-30 09:04:36 +0000989 if (target_sp)
Greg Clayton524e60b2010-10-06 22:10:17 +0000990 {
Greg Claytonacdbe812012-01-30 09:04:36 +0000991 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton0c74e782011-06-24 03:21:43 +0000992
993 StateType state = eStateInvalid;
Greg Claytonacdbe812012-01-30 09:04:36 +0000994 process_sp = target_sp->GetProcessSP();
Greg Claytonb9556ac2012-01-30 07:41:31 +0000995 if (process_sp)
Greg Clayton0c74e782011-06-24 03:21:43 +0000996 {
Greg Claytonb9556ac2012-01-30 07:41:31 +0000997 state = process_sp->GetState();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000998
Greg Claytonb9556ac2012-01-30 07:41:31 +0000999 if (process_sp->IsAlive() && state != eStateConnected)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001000 {
Greg Clayton0c74e782011-06-24 03:21:43 +00001001 if (state == eStateAttaching)
1002 error.SetErrorString ("process attach is in progress");
1003 else
1004 error.SetErrorString ("a process is already being debugged");
Greg Clayton0c74e782011-06-24 03:21:43 +00001005 return sb_process;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001006 }
Greg Clayton0c74e782011-06-24 03:21:43 +00001007 }
1008
1009 if (state == eStateConnected)
1010 {
1011 // If we are already connected, then we have already specified the
1012 // listener, so if a valid listener is supplied, we need to error out
1013 // to let the client know.
1014 if (listener.IsValid())
1015 {
1016 error.SetErrorString ("process is connected and already has a listener, pass empty listener");
Greg Clayton0c74e782011-06-24 03:21:43 +00001017 return sb_process;
1018 }
1019 }
Greg Clayton4b045622011-02-03 21:28:34 +00001020 else
Greg Clayton0c74e782011-06-24 03:21:43 +00001021 {
1022 if (listener.IsValid())
Greg Claytonc3776bf2012-02-09 06:16:32 +00001023 process_sp = target_sp->CreateProcess (listener.ref(), NULL, NULL);
Greg Clayton0c74e782011-06-24 03:21:43 +00001024 else
Greg Claytonc3776bf2012-02-09 06:16:32 +00001025 process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener(), NULL, NULL);
Greg Clayton0c74e782011-06-24 03:21:43 +00001026 }
Greg Claytonb9556ac2012-01-30 07:41:31 +00001027 if (process_sp)
Greg Clayton524e60b2010-10-06 22:10:17 +00001028 {
Greg Claytonb9556ac2012-01-30 07:41:31 +00001029 sb_process.SetSP (process_sp);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001030
Greg Clayton144f3a92011-11-15 03:53:30 +00001031 ProcessAttachInfo attach_info;
1032 attach_info.SetProcessID (pid);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001033
Han Ming Ong84647042012-02-25 01:07:38 +00001034 PlatformSP platform_sp = target_sp->GetPlatform();
1035 ProcessInstanceInfo instance_info;
1036 if (platform_sp->GetProcessInfo(pid, instance_info))
1037 {
1038 attach_info.SetUserID(instance_info.GetEffectiveUserID());
Han Ming Ong84647042012-02-25 01:07:38 +00001039 }
Greg Claytonb9556ac2012-01-30 07:41:31 +00001040 error.SetError (process_sp->Attach (attach_info));
Greg Claytone2186ed2012-09-07 17:51:47 +00001041 if (error.Success())
1042 {
1043 // If we are doing synchronous mode, then wait for the
1044 // process to stop!
1045 if (target_sp->GetDebugger().GetAsyncExecution () == false)
Greg Claytondc6224e2014-10-21 01:00:42 +00001046 process_sp->WaitForProcessToStop (NULL);
Greg Claytone2186ed2012-09-07 17:51:47 +00001047 }
Greg Clayton524e60b2010-10-06 22:10:17 +00001048 }
1049 else
1050 {
1051 error.SetErrorString ("unable to create lldb_private::Process");
1052 }
1053 }
1054 else
1055 {
1056 error.SetErrorString ("SBTarget is invalid");
1057 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001058
Sean Callanan575a4542012-10-20 00:21:31 +00001059 if (log)
Sean Callanan575a4542012-10-20 00:21:31 +00001060 log->Printf ("SBTarget(%p)::AttachToProcessWithID (...) => SBProcess(%p)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001061 static_cast<void*>(target_sp.get()),
1062 static_cast<void*>(process_sp.get()));
Greg Clayton524e60b2010-10-06 22:10:17 +00001063 return sb_process;
Greg Clayton524e60b2010-10-06 22:10:17 +00001064}
1065
1066lldb::SBProcess
Greg Clayton05faeb72010-10-07 04:19:01 +00001067SBTarget::AttachToProcessWithName
Greg Clayton524e60b2010-10-06 22:10:17 +00001068(
Greg Clayton4b045622011-02-03 21:28:34 +00001069 SBListener &listener,
Greg Clayton524e60b2010-10-06 22:10:17 +00001070 const char *name, // basename of process to attach to
1071 bool wait_for, // if true wait for a new instance of "name" to be launched
1072 SBError& error // An error explaining what went wrong if attach fails
1073)
1074{
Greg Clayton5160ce52013-03-27 23:08:40 +00001075 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001076
Greg Clayton524e60b2010-10-06 22:10:17 +00001077 SBProcess sb_process;
Greg Claytonb9556ac2012-01-30 07:41:31 +00001078 ProcessSP process_sp;
Greg Claytonacdbe812012-01-30 09:04:36 +00001079 TargetSP target_sp(GetSP());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001080
Sean Callanan575a4542012-10-20 00:21:31 +00001081 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001082 log->Printf ("SBTarget(%p)::AttachToProcessWithName (listener, name=%s, wait_for=%s, error)...",
1083 static_cast<void*>(target_sp.get()), name,
1084 wait_for ? "true" : "false");
1085
Greg Claytonacdbe812012-01-30 09:04:36 +00001086 if (name && target_sp)
Greg Clayton524e60b2010-10-06 22:10:17 +00001087 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001088 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytonaf67cec2010-12-20 20:49:23 +00001089
Greg Clayton0c74e782011-06-24 03:21:43 +00001090 StateType state = eStateInvalid;
Greg Claytonacdbe812012-01-30 09:04:36 +00001091 process_sp = target_sp->GetProcessSP();
Greg Claytonb9556ac2012-01-30 07:41:31 +00001092 if (process_sp)
Greg Clayton0c74e782011-06-24 03:21:43 +00001093 {
Greg Claytonb9556ac2012-01-30 07:41:31 +00001094 state = process_sp->GetState();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001095
Greg Claytonb9556ac2012-01-30 07:41:31 +00001096 if (process_sp->IsAlive() && state != eStateConnected)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001097 {
Greg Clayton0c74e782011-06-24 03:21:43 +00001098 if (state == eStateAttaching)
1099 error.SetErrorString ("process attach is in progress");
1100 else
1101 error.SetErrorString ("a process is already being debugged");
Greg Clayton0c74e782011-06-24 03:21:43 +00001102 return sb_process;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001103 }
Greg Clayton0c74e782011-06-24 03:21:43 +00001104 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001105
Greg Clayton0c74e782011-06-24 03:21:43 +00001106 if (state == eStateConnected)
1107 {
1108 // If we are already connected, then we have already specified the
1109 // listener, so if a valid listener is supplied, we need to error out
1110 // to let the client know.
1111 if (listener.IsValid())
1112 {
1113 error.SetErrorString ("process is connected and already has a listener, pass empty listener");
Greg Clayton0c74e782011-06-24 03:21:43 +00001114 return sb_process;
1115 }
1116 }
Greg Clayton4b045622011-02-03 21:28:34 +00001117 else
Greg Clayton0c74e782011-06-24 03:21:43 +00001118 {
1119 if (listener.IsValid())
Greg Claytonc3776bf2012-02-09 06:16:32 +00001120 process_sp = target_sp->CreateProcess (listener.ref(), NULL, NULL);
Greg Clayton0c74e782011-06-24 03:21:43 +00001121 else
Greg Claytonc3776bf2012-02-09 06:16:32 +00001122 process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener(), NULL, NULL);
Greg Clayton0c74e782011-06-24 03:21:43 +00001123 }
Greg Clayton524e60b2010-10-06 22:10:17 +00001124
Greg Claytonb9556ac2012-01-30 07:41:31 +00001125 if (process_sp)
Greg Clayton524e60b2010-10-06 22:10:17 +00001126 {
Greg Claytonb9556ac2012-01-30 07:41:31 +00001127 sb_process.SetSP (process_sp);
Greg Clayton144f3a92011-11-15 03:53:30 +00001128 ProcessAttachInfo attach_info;
1129 attach_info.GetExecutableFile().SetFile(name, false);
1130 attach_info.SetWaitForLaunch(wait_for);
Greg Claytonb9556ac2012-01-30 07:41:31 +00001131 error.SetError (process_sp->Attach (attach_info));
Daniel Malead659dc12013-04-01 19:47:00 +00001132 if (error.Success())
1133 {
1134 // If we are doing synchronous mode, then wait for the
1135 // process to stop!
1136 if (target_sp->GetDebugger().GetAsyncExecution () == false)
1137 process_sp->WaitForProcessToStop (NULL);
1138 }
Greg Clayton524e60b2010-10-06 22:10:17 +00001139 }
1140 else
1141 {
1142 error.SetErrorString ("unable to create lldb_private::Process");
1143 }
1144 }
1145 else
1146 {
1147 error.SetErrorString ("SBTarget is invalid");
1148 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001149
Sean Callanan575a4542012-10-20 00:21:31 +00001150 if (log)
Sean Callanan575a4542012-10-20 00:21:31 +00001151 log->Printf ("SBTarget(%p)::AttachToPorcessWithName (...) => SBProcess(%p)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001152 static_cast<void*>(target_sp.get()),
1153 static_cast<void*>(process_sp.get()));
Greg Clayton524e60b2010-10-06 22:10:17 +00001154 return sb_process;
Greg Clayton524e60b2010-10-06 22:10:17 +00001155}
1156
James McIlree9631aae2011-03-04 00:31:13 +00001157lldb::SBProcess
1158SBTarget::ConnectRemote
1159(
1160 SBListener &listener,
1161 const char *url,
1162 const char *plugin_name,
1163 SBError& error
1164)
1165{
Greg Clayton5160ce52013-03-27 23:08:40 +00001166 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Sean Callanan575a4542012-10-20 00:21:31 +00001167
James McIlree9631aae2011-03-04 00:31:13 +00001168 SBProcess sb_process;
Greg Claytonb9556ac2012-01-30 07:41:31 +00001169 ProcessSP process_sp;
Greg Claytonacdbe812012-01-30 09:04:36 +00001170 TargetSP target_sp(GetSP());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001171
Sean Callanan575a4542012-10-20 00:21:31 +00001172 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001173 log->Printf ("SBTarget(%p)::ConnectRemote (listener, url=%s, plugin_name=%s, error)...",
1174 static_cast<void*>(target_sp.get()), url, plugin_name);
1175
Greg Claytonacdbe812012-01-30 09:04:36 +00001176 if (target_sp)
James McIlree9631aae2011-03-04 00:31:13 +00001177 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001178 Mutex::Locker api_locker (target_sp->GetAPIMutex());
James McIlree9631aae2011-03-04 00:31:13 +00001179 if (listener.IsValid())
Greg Claytonc3776bf2012-02-09 06:16:32 +00001180 process_sp = target_sp->CreateProcess (listener.ref(), plugin_name, NULL);
James McIlree9631aae2011-03-04 00:31:13 +00001181 else
Greg Claytonc3776bf2012-02-09 06:16:32 +00001182 process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener(), plugin_name, NULL);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001183
Greg Claytonb9556ac2012-01-30 07:41:31 +00001184 if (process_sp)
James McIlree9631aae2011-03-04 00:31:13 +00001185 {
Greg Claytonb9556ac2012-01-30 07:41:31 +00001186 sb_process.SetSP (process_sp);
Jason Molenda4bd4e7e2012-09-29 04:02:01 +00001187 error.SetError (process_sp->ConnectRemote (NULL, url));
James McIlree9631aae2011-03-04 00:31:13 +00001188 }
1189 else
1190 {
1191 error.SetErrorString ("unable to create lldb_private::Process");
1192 }
1193 }
1194 else
1195 {
1196 error.SetErrorString ("SBTarget is invalid");
1197 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001198
Sean Callanan575a4542012-10-20 00:21:31 +00001199 if (log)
Sean Callanan575a4542012-10-20 00:21:31 +00001200 log->Printf ("SBTarget(%p)::ConnectRemote (...) => SBProcess(%p)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001201 static_cast<void*>(target_sp.get()),
1202 static_cast<void*>(process_sp.get()));
James McIlree9631aae2011-03-04 00:31:13 +00001203 return sb_process;
1204}
1205
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001206SBFileSpec
1207SBTarget::GetExecutable ()
1208{
Caroline Ticeceb6b132010-10-26 03:11:13 +00001209
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001210 SBFileSpec exe_file_spec;
Greg Claytonacdbe812012-01-30 09:04:36 +00001211 TargetSP target_sp(GetSP());
1212 if (target_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001213 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001214 Module *exe_module = target_sp->GetExecutableModulePointer();
Greg Claytonaa149cb2011-08-11 02:48:45 +00001215 if (exe_module)
1216 exe_file_spec.SetFileSpec (exe_module->GetFileSpec());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001217 }
Caroline Ticeceb6b132010-10-26 03:11:13 +00001218
Greg Clayton5160ce52013-03-27 23:08:40 +00001219 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001220 if (log)
1221 {
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001222 log->Printf ("SBTarget(%p)::GetExecutable () => SBFileSpec(%p)",
1223 static_cast<void*>(target_sp.get()),
1224 static_cast<const void*>(exe_file_spec.get()));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001225 }
1226
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001227 return exe_file_spec;
1228}
1229
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001230bool
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001231SBTarget::operator == (const SBTarget &rhs) const
1232{
Greg Clayton66111032010-06-23 01:19:29 +00001233 return m_opaque_sp.get() == rhs.m_opaque_sp.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001234}
1235
1236bool
1237SBTarget::operator != (const SBTarget &rhs) const
1238{
Greg Clayton66111032010-06-23 01:19:29 +00001239 return m_opaque_sp.get() != rhs.m_opaque_sp.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001240}
1241
Greg Claytonb9556ac2012-01-30 07:41:31 +00001242lldb::TargetSP
1243SBTarget::GetSP () const
Greg Clayton9a377662011-10-01 02:59:24 +00001244{
1245 return m_opaque_sp;
1246}
1247
Greg Clayton66111032010-06-23 01:19:29 +00001248void
Greg Claytonb9556ac2012-01-30 07:41:31 +00001249SBTarget::SetSP (const lldb::TargetSP& target_sp)
Greg Clayton66111032010-06-23 01:19:29 +00001250{
1251 m_opaque_sp = target_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001252}
1253
Greg Clayton00e6fbf2011-07-22 16:46:35 +00001254lldb::SBAddress
1255SBTarget::ResolveLoadAddress (lldb::addr_t vm_addr)
Greg Claytonac2eb9b2010-12-12 19:25:26 +00001256{
Greg Clayton00e6fbf2011-07-22 16:46:35 +00001257 lldb::SBAddress sb_addr;
1258 Address &addr = sb_addr.ref();
Greg Claytonacdbe812012-01-30 09:04:36 +00001259 TargetSP target_sp(GetSP());
1260 if (target_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +00001261 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001262 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytond5944cd2013-12-06 01:12:00 +00001263 if (target_sp->ResolveLoadAddress (vm_addr, addr))
Greg Clayton00e6fbf2011-07-22 16:46:35 +00001264 return sb_addr;
Greg Claytonaf67cec2010-12-20 20:49:23 +00001265 }
Greg Claytonac2eb9b2010-12-12 19:25:26 +00001266
Greg Clayton00e6fbf2011-07-22 16:46:35 +00001267 // We have a load address that isn't in a section, just return an address
1268 // with the offset filled in (the address) and the section set to NULL
Greg Claytone72dfb32012-02-24 01:59:29 +00001269 addr.SetRawAddress(vm_addr);
Greg Clayton00e6fbf2011-07-22 16:46:35 +00001270 return sb_addr;
Greg Claytonac2eb9b2010-12-12 19:25:26 +00001271}
1272
Matthew Gardinerc928de32014-10-22 07:22:56 +00001273lldb::SBAddress
1274SBTarget::ResolveFileAddress (lldb::addr_t file_addr)
1275{
1276 lldb::SBAddress sb_addr;
1277 Address &addr = sb_addr.ref();
1278 TargetSP target_sp(GetSP());
1279 if (target_sp)
1280 {
1281 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1282 if (target_sp->ResolveFileAddress (file_addr, addr))
1283 return sb_addr;
1284 }
1285
1286 addr.SetRawAddress(file_addr);
1287 return sb_addr;
1288}
Greg Claytond5944cd2013-12-06 01:12:00 +00001289
1290lldb::SBAddress
1291SBTarget::ResolvePastLoadAddress (uint32_t stop_id, lldb::addr_t vm_addr)
1292{
1293 lldb::SBAddress sb_addr;
1294 Address &addr = sb_addr.ref();
1295 TargetSP target_sp(GetSP());
1296 if (target_sp)
1297 {
1298 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1299 if (target_sp->ResolveLoadAddress (vm_addr, addr))
1300 return sb_addr;
1301 }
1302
1303 // We have a load address that isn't in a section, just return an address
1304 // with the offset filled in (the address) and the section set to NULL
1305 addr.SetRawAddress(vm_addr);
1306 return sb_addr;
1307}
1308
Greg Clayton5f2a4f92011-03-02 21:34:46 +00001309SBSymbolContext
Greg Claytoneb023e72013-10-11 19:48:25 +00001310SBTarget::ResolveSymbolContextForAddress (const SBAddress& addr,
1311 uint32_t resolve_scope)
Greg Clayton5f2a4f92011-03-02 21:34:46 +00001312{
1313 SBSymbolContext sc;
Greg Claytonacdbe812012-01-30 09:04:36 +00001314 if (addr.IsValid())
1315 {
1316 TargetSP target_sp(GetSP());
1317 if (target_sp)
1318 target_sp->GetImages().ResolveSymbolContextForAddress (addr.ref(), resolve_scope, sc.ref());
1319 }
Greg Clayton5f2a4f92011-03-02 21:34:46 +00001320 return sc;
1321}
1322
Matthew Gardinerc928de32014-10-22 07:22:56 +00001323size_t
1324SBTarget::ReadMemory (const SBAddress addr,
1325 void *buf,
1326 size_t size,
1327 lldb::SBError &error)
1328{
1329 SBError sb_error;
1330 size_t bytes_read = 0;
1331 TargetSP target_sp(GetSP());
1332 if (target_sp)
1333 {
1334 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton8691dc52014-11-04 00:56:30 +00001335 bytes_read = target_sp->ReadMemory(addr.ref(), false, buf, size, sb_error.ref());
1336 }
1337 else
1338 {
1339 sb_error.SetErrorString("invalid target");
Matthew Gardinerc928de32014-10-22 07:22:56 +00001340 }
1341
1342 return bytes_read;
1343}
Greg Clayton5f2a4f92011-03-02 21:34:46 +00001344
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001345SBBreakpoint
Greg Claytoneb023e72013-10-11 19:48:25 +00001346SBTarget::BreakpointCreateByLocation (const char *file,
1347 uint32_t line)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001348{
Greg Clayton7481c202010-11-08 00:28:40 +00001349 return SBBreakpoint(BreakpointCreateByLocation (SBFileSpec (file, false), line));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001350}
1351
1352SBBreakpoint
Greg Claytoneb023e72013-10-11 19:48:25 +00001353SBTarget::BreakpointCreateByLocation (const SBFileSpec &sb_file_spec,
1354 uint32_t line)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001355{
Greg Clayton5160ce52013-03-27 23:08:40 +00001356 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001357
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001358 SBBreakpoint sb_bp;
Greg Claytonacdbe812012-01-30 09:04:36 +00001359 TargetSP target_sp(GetSP());
1360 if (target_sp && line != 0)
Greg Claytonaf67cec2010-12-20 20:49:23 +00001361 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001362 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001363
Greg Clayton1f746072012-08-29 21:13:06 +00001364 const LazyBool check_inlines = eLazyBoolCalculate;
Jim Inghama8558b62012-05-22 00:12:20 +00001365 const LazyBool skip_prologue = eLazyBoolCalculate;
Greg Clayton1f746072012-08-29 21:13:06 +00001366 const bool internal = false;
Greg Claytoneb023e72013-10-11 19:48:25 +00001367 const bool hardware = false;
1368 *sb_bp = target_sp->CreateBreakpoint (NULL, *sb_file_spec, line, check_inlines, skip_prologue, internal, hardware);
Greg Claytonaf67cec2010-12-20 20:49:23 +00001369 }
Caroline Ticeceb6b132010-10-26 03:11:13 +00001370
1371 if (log)
1372 {
1373 SBStream sstr;
1374 sb_bp.GetDescription (sstr);
Greg Claytoncfd1ace2010-10-31 03:01:06 +00001375 char path[PATH_MAX];
1376 sb_file_spec->GetPath (path, sizeof(path));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001377 log->Printf ("SBTarget(%p)::BreakpointCreateByLocation ( %s:%u ) => SBBreakpoint(%p): %s",
1378 static_cast<void*>(target_sp.get()), path, line,
1379 static_cast<void*>(sb_bp.get()), sstr.GetData());
Caroline Ticeceb6b132010-10-26 03:11:13 +00001380 }
1381
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001382 return sb_bp;
1383}
1384
1385SBBreakpoint
Greg Claytoneb023e72013-10-11 19:48:25 +00001386SBTarget::BreakpointCreateByName (const char *symbol_name,
1387 const char *module_name)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001388{
Greg Clayton5160ce52013-03-27 23:08:40 +00001389 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001390
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001391 SBBreakpoint sb_bp;
Greg Claytonacdbe812012-01-30 09:04:36 +00001392 TargetSP target_sp(GetSP());
1393 if (target_sp.get())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001394 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001395 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001396
Jim Inghama8558b62012-05-22 00:12:20 +00001397 const bool internal = false;
Greg Claytoneb023e72013-10-11 19:48:25 +00001398 const bool hardware = false;
Jim Inghama8558b62012-05-22 00:12:20 +00001399 const LazyBool skip_prologue = eLazyBoolCalculate;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001400 if (module_name && module_name[0])
1401 {
Jim Ingham969795f2011-09-21 01:17:13 +00001402 FileSpecList module_spec_list;
1403 module_spec_list.Append (FileSpec (module_name, false));
Greg Claytoneb023e72013-10-11 19:48:25 +00001404 *sb_bp = target_sp->CreateBreakpoint (&module_spec_list, NULL, symbol_name, eFunctionNameTypeAuto, skip_prologue, internal, hardware);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001405 }
1406 else
1407 {
Greg Claytoneb023e72013-10-11 19:48:25 +00001408 *sb_bp = target_sp->CreateBreakpoint (NULL, NULL, symbol_name, eFunctionNameTypeAuto, skip_prologue, internal, hardware);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001409 }
1410 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001411
Caroline Ticeceb6b132010-10-26 03:11:13 +00001412 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001413 log->Printf ("SBTarget(%p)::BreakpointCreateByName (symbol=\"%s\", module=\"%s\") => SBBreakpoint(%p)",
1414 static_cast<void*>(target_sp.get()), symbol_name,
1415 module_name, static_cast<void*>(sb_bp.get()));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001416
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001417 return sb_bp;
1418}
1419
Jim Ingham87df91b2011-09-23 00:54:11 +00001420lldb::SBBreakpoint
1421SBTarget::BreakpointCreateByName (const char *symbol_name,
Greg Claytoneb023e72013-10-11 19:48:25 +00001422 const SBFileSpecList &module_list,
1423 const SBFileSpecList &comp_unit_list)
Jim Ingham87df91b2011-09-23 00:54:11 +00001424{
Jim Ingham2dd7f7f2011-10-11 01:18:55 +00001425 uint32_t name_type_mask = eFunctionNameTypeAuto;
1426 return BreakpointCreateByName (symbol_name, name_type_mask, module_list, comp_unit_list);
1427}
1428
1429lldb::SBBreakpoint
1430SBTarget::BreakpointCreateByName (const char *symbol_name,
Greg Claytoneb023e72013-10-11 19:48:25 +00001431 uint32_t name_type_mask,
1432 const SBFileSpecList &module_list,
1433 const SBFileSpecList &comp_unit_list)
Jim Ingham2dd7f7f2011-10-11 01:18:55 +00001434{
Greg Clayton5160ce52013-03-27 23:08:40 +00001435 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Jim Ingham87df91b2011-09-23 00:54:11 +00001436
1437 SBBreakpoint sb_bp;
Greg Claytonacdbe812012-01-30 09:04:36 +00001438 TargetSP target_sp(GetSP());
1439 if (target_sp && symbol_name && symbol_name[0])
Jim Ingham87df91b2011-09-23 00:54:11 +00001440 {
Jim Inghama8558b62012-05-22 00:12:20 +00001441 const bool internal = false;
Greg Claytoneb023e72013-10-11 19:48:25 +00001442 const bool hardware = false;
Jim Inghama8558b62012-05-22 00:12:20 +00001443 const LazyBool skip_prologue = eLazyBoolCalculate;
Greg Claytonacdbe812012-01-30 09:04:36 +00001444 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1445 *sb_bp = target_sp->CreateBreakpoint (module_list.get(),
Greg Claytoneb023e72013-10-11 19:48:25 +00001446 comp_unit_list.get(),
1447 symbol_name,
1448 name_type_mask,
1449 skip_prologue,
1450 internal,
1451 hardware);
Jim Ingham87df91b2011-09-23 00:54:11 +00001452 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001453
Jim Ingham87df91b2011-09-23 00:54:11 +00001454 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001455 log->Printf ("SBTarget(%p)::BreakpointCreateByName (symbol=\"%s\", name_type: %d) => SBBreakpoint(%p)",
1456 static_cast<void*>(target_sp.get()), symbol_name,
1457 name_type_mask, static_cast<void*>(sb_bp.get()));
Jim Ingham87df91b2011-09-23 00:54:11 +00001458
1459 return sb_bp;
1460}
1461
Jim Inghamfab10e82012-03-06 00:37:27 +00001462lldb::SBBreakpoint
1463SBTarget::BreakpointCreateByNames (const char *symbol_names[],
1464 uint32_t num_names,
1465 uint32_t name_type_mask,
1466 const SBFileSpecList &module_list,
1467 const SBFileSpecList &comp_unit_list)
1468{
Greg Clayton5160ce52013-03-27 23:08:40 +00001469 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Jim Inghamfab10e82012-03-06 00:37:27 +00001470
1471 SBBreakpoint sb_bp;
1472 TargetSP target_sp(GetSP());
1473 if (target_sp && num_names > 0)
1474 {
1475 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Jim Inghama8558b62012-05-22 00:12:20 +00001476 const bool internal = false;
Greg Claytoneb023e72013-10-11 19:48:25 +00001477 const bool hardware = false;
Jim Inghama8558b62012-05-22 00:12:20 +00001478 const LazyBool skip_prologue = eLazyBoolCalculate;
Jim Inghamfab10e82012-03-06 00:37:27 +00001479 *sb_bp = target_sp->CreateBreakpoint (module_list.get(),
1480 comp_unit_list.get(),
1481 symbol_names,
1482 num_names,
1483 name_type_mask,
Jim Inghama8558b62012-05-22 00:12:20 +00001484 skip_prologue,
Greg Claytoneb023e72013-10-11 19:48:25 +00001485 internal,
1486 hardware);
Jim Inghamfab10e82012-03-06 00:37:27 +00001487 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001488
Jim Inghamfab10e82012-03-06 00:37:27 +00001489 if (log)
1490 {
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001491 log->Printf ("SBTarget(%p)::BreakpointCreateByName (symbols={",
1492 static_cast<void*>(target_sp.get()));
Jim Inghamfab10e82012-03-06 00:37:27 +00001493 for (uint32_t i = 0 ; i < num_names; i++)
1494 {
1495 char sep;
1496 if (i < num_names - 1)
1497 sep = ',';
1498 else
1499 sep = '}';
1500 if (symbol_names[i] != NULL)
1501 log->Printf ("\"%s\"%c ", symbol_names[i], sep);
1502 else
1503 log->Printf ("\"<NULL>\"%c ", sep);
Jim Inghamfab10e82012-03-06 00:37:27 +00001504 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001505 log->Printf ("name_type: %d) => SBBreakpoint(%p)", name_type_mask,
1506 static_cast<void*>(sb_bp.get()));
Jim Inghamfab10e82012-03-06 00:37:27 +00001507 }
1508
1509 return sb_bp;
1510}
Jim Ingham87df91b2011-09-23 00:54:11 +00001511
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001512SBBreakpoint
Greg Claytoneb023e72013-10-11 19:48:25 +00001513SBTarget::BreakpointCreateByRegex (const char *symbol_name_regex,
1514 const char *module_name)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001515{
Greg Clayton5160ce52013-03-27 23:08:40 +00001516 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001517
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001518 SBBreakpoint sb_bp;
Greg Claytonacdbe812012-01-30 09:04:36 +00001519 TargetSP target_sp(GetSP());
1520 if (target_sp && symbol_name_regex && symbol_name_regex[0])
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001521 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001522 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001523 RegularExpression regexp(symbol_name_regex);
Jim Inghama8558b62012-05-22 00:12:20 +00001524 const bool internal = false;
Greg Claytoneb023e72013-10-11 19:48:25 +00001525 const bool hardware = false;
Jim Inghama8558b62012-05-22 00:12:20 +00001526 const LazyBool skip_prologue = eLazyBoolCalculate;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001527
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001528 if (module_name && module_name[0])
1529 {
Jim Ingham969795f2011-09-21 01:17:13 +00001530 FileSpecList module_spec_list;
1531 module_spec_list.Append (FileSpec (module_name, false));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001532
Greg Claytoneb023e72013-10-11 19:48:25 +00001533 *sb_bp = target_sp->CreateFuncRegexBreakpoint (&module_spec_list, NULL, regexp, skip_prologue, internal, hardware);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001534 }
1535 else
1536 {
Greg Claytoneb023e72013-10-11 19:48:25 +00001537 *sb_bp = target_sp->CreateFuncRegexBreakpoint (NULL, NULL, regexp, skip_prologue, internal, hardware);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001538 }
1539 }
Caroline Ticeceb6b132010-10-26 03:11:13 +00001540
1541 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001542 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (symbol_regex=\"%s\", module_name=\"%s\") => SBBreakpoint(%p)",
1543 static_cast<void*>(target_sp.get()), symbol_name_regex,
1544 module_name, static_cast<void*>(sb_bp.get()));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001545
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001546 return sb_bp;
1547}
1548
Jim Ingham87df91b2011-09-23 00:54:11 +00001549lldb::SBBreakpoint
1550SBTarget::BreakpointCreateByRegex (const char *symbol_name_regex,
Greg Claytoneb023e72013-10-11 19:48:25 +00001551 const SBFileSpecList &module_list,
1552 const SBFileSpecList &comp_unit_list)
Jim Ingham87df91b2011-09-23 00:54:11 +00001553{
Greg Clayton5160ce52013-03-27 23:08:40 +00001554 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001555
Jim Ingham87df91b2011-09-23 00:54:11 +00001556 SBBreakpoint sb_bp;
Greg Claytonacdbe812012-01-30 09:04:36 +00001557 TargetSP target_sp(GetSP());
1558 if (target_sp && symbol_name_regex && symbol_name_regex[0])
Jim Ingham87df91b2011-09-23 00:54:11 +00001559 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001560 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Jim Ingham87df91b2011-09-23 00:54:11 +00001561 RegularExpression regexp(symbol_name_regex);
Jim Inghama8558b62012-05-22 00:12:20 +00001562 const bool internal = false;
Greg Claytoneb023e72013-10-11 19:48:25 +00001563 const bool hardware = false;
Jim Inghama8558b62012-05-22 00:12:20 +00001564 const LazyBool skip_prologue = eLazyBoolCalculate;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001565
Greg Claytoneb023e72013-10-11 19:48:25 +00001566 *sb_bp = target_sp->CreateFuncRegexBreakpoint (module_list.get(), comp_unit_list.get(), regexp, skip_prologue, internal, hardware);
Jim Ingham87df91b2011-09-23 00:54:11 +00001567 }
1568
1569 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001570 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (symbol_regex=\"%s\") => SBBreakpoint(%p)",
1571 static_cast<void*>(target_sp.get()), symbol_name_regex,
1572 static_cast<void*>(sb_bp.get()));
Jim Ingham87df91b2011-09-23 00:54:11 +00001573
1574 return sb_bp;
1575}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001576
1577SBBreakpoint
1578SBTarget::BreakpointCreateByAddress (addr_t address)
1579{
Greg Clayton5160ce52013-03-27 23:08:40 +00001580 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001581
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001582 SBBreakpoint sb_bp;
Greg Claytonacdbe812012-01-30 09:04:36 +00001583 TargetSP target_sp(GetSP());
1584 if (target_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +00001585 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001586 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytoneb023e72013-10-11 19:48:25 +00001587 const bool hardware = false;
1588 *sb_bp = target_sp->CreateBreakpoint (address, false, hardware);
Greg Claytonaf67cec2010-12-20 20:49:23 +00001589 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001590
Caroline Ticeceb6b132010-10-26 03:11:13 +00001591 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001592 log->Printf ("SBTarget(%p)::BreakpointCreateByAddress (address=%" PRIu64 ") => SBBreakpoint(%p)",
1593 static_cast<void*>(target_sp.get()),
1594 static_cast<uint64_t>(address),
1595 static_cast<void*>(sb_bp.get()));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001596
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001597 return sb_bp;
1598}
1599
Jim Ingham969795f2011-09-21 01:17:13 +00001600lldb::SBBreakpoint
Greg Claytoneb023e72013-10-11 19:48:25 +00001601SBTarget::BreakpointCreateBySourceRegex (const char *source_regex,
1602 const lldb::SBFileSpec &source_file,
1603 const char *module_name)
Jim Ingham969795f2011-09-21 01:17:13 +00001604{
Greg Clayton5160ce52013-03-27 23:08:40 +00001605 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Jim Ingham969795f2011-09-21 01:17:13 +00001606
1607 SBBreakpoint sb_bp;
Greg Claytonacdbe812012-01-30 09:04:36 +00001608 TargetSP target_sp(GetSP());
1609 if (target_sp && source_regex && source_regex[0])
Jim Ingham969795f2011-09-21 01:17:13 +00001610 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001611 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Jim Ingham969795f2011-09-21 01:17:13 +00001612 RegularExpression regexp(source_regex);
Jim Ingham87df91b2011-09-23 00:54:11 +00001613 FileSpecList source_file_spec_list;
Greg Claytoneb023e72013-10-11 19:48:25 +00001614 const bool hardware = false;
Jim Ingham87df91b2011-09-23 00:54:11 +00001615 source_file_spec_list.Append (source_file.ref());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001616
Jim Ingham969795f2011-09-21 01:17:13 +00001617 if (module_name && module_name[0])
1618 {
1619 FileSpecList module_spec_list;
1620 module_spec_list.Append (FileSpec (module_name, false));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001621
Greg Claytoneb023e72013-10-11 19:48:25 +00001622 *sb_bp = target_sp->CreateSourceRegexBreakpoint (&module_spec_list, &source_file_spec_list, regexp, false, hardware);
Jim Ingham969795f2011-09-21 01:17:13 +00001623 }
1624 else
1625 {
Greg Claytoneb023e72013-10-11 19:48:25 +00001626 *sb_bp = target_sp->CreateSourceRegexBreakpoint (NULL, &source_file_spec_list, regexp, false, hardware);
Jim Ingham969795f2011-09-21 01:17:13 +00001627 }
1628 }
1629
1630 if (log)
1631 {
1632 char path[PATH_MAX];
1633 source_file->GetPath (path, sizeof(path));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001634 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (source_regex=\"%s\", file=\"%s\", module_name=\"%s\") => SBBreakpoint(%p)",
1635 static_cast<void*>(target_sp.get()), source_regex, path,
1636 module_name, static_cast<void*>(sb_bp.get()));
Jim Ingham969795f2011-09-21 01:17:13 +00001637 }
1638
1639 return sb_bp;
1640}
1641
Jim Ingham87df91b2011-09-23 00:54:11 +00001642lldb::SBBreakpoint
1643SBTarget::BreakpointCreateBySourceRegex (const char *source_regex,
Greg Claytoneb023e72013-10-11 19:48:25 +00001644 const SBFileSpecList &module_list,
1645 const lldb::SBFileSpecList &source_file_list)
Jim Ingham87df91b2011-09-23 00:54:11 +00001646{
Greg Clayton5160ce52013-03-27 23:08:40 +00001647 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Jim Ingham87df91b2011-09-23 00:54:11 +00001648
1649 SBBreakpoint sb_bp;
Greg Claytonacdbe812012-01-30 09:04:36 +00001650 TargetSP target_sp(GetSP());
1651 if (target_sp && source_regex && source_regex[0])
Jim Ingham87df91b2011-09-23 00:54:11 +00001652 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001653 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytoneb023e72013-10-11 19:48:25 +00001654 const bool hardware = false;
Jim Ingham87df91b2011-09-23 00:54:11 +00001655 RegularExpression regexp(source_regex);
Greg Claytoneb023e72013-10-11 19:48:25 +00001656 *sb_bp = target_sp->CreateSourceRegexBreakpoint (module_list.get(), source_file_list.get(), regexp, false, hardware);
Jim Ingham87df91b2011-09-23 00:54:11 +00001657 }
1658
1659 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001660 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (source_regex=\"%s\") => SBBreakpoint(%p)",
1661 static_cast<void*>(target_sp.get()), source_regex,
1662 static_cast<void*>(sb_bp.get()));
Jim Ingham87df91b2011-09-23 00:54:11 +00001663
1664 return sb_bp;
1665}
Jim Ingham969795f2011-09-21 01:17:13 +00001666
Jim Inghamfab10e82012-03-06 00:37:27 +00001667lldb::SBBreakpoint
1668SBTarget::BreakpointCreateForException (lldb::LanguageType language,
Greg Claytoneb023e72013-10-11 19:48:25 +00001669 bool catch_bp,
1670 bool throw_bp)
Jim Inghamfab10e82012-03-06 00:37:27 +00001671{
Greg Clayton5160ce52013-03-27 23:08:40 +00001672 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Jim Inghamfab10e82012-03-06 00:37:27 +00001673
1674 SBBreakpoint sb_bp;
1675 TargetSP target_sp(GetSP());
1676 if (target_sp)
1677 {
1678 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytoneb023e72013-10-11 19:48:25 +00001679 const bool hardware = false;
1680 *sb_bp = target_sp->CreateExceptionBreakpoint (language, catch_bp, throw_bp, hardware);
Jim Inghamfab10e82012-03-06 00:37:27 +00001681 }
1682
1683 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001684 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (Language: %s, catch: %s throw: %s) => SBBreakpoint(%p)",
1685 static_cast<void*>(target_sp.get()),
Jim Inghamfab10e82012-03-06 00:37:27 +00001686 LanguageRuntime::GetNameForLanguageType(language),
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001687 catch_bp ? "on" : "off", throw_bp ? "on" : "off",
1688 static_cast<void*>(sb_bp.get()));
Jim Inghamfab10e82012-03-06 00:37:27 +00001689
1690 return sb_bp;
1691}
1692
Greg Clayton9fed0d82010-07-23 23:33:17 +00001693uint32_t
1694SBTarget::GetNumBreakpoints () const
1695{
Greg Claytonacdbe812012-01-30 09:04:36 +00001696 TargetSP target_sp(GetSP());
1697 if (target_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +00001698 {
1699 // The breakpoint list is thread safe, no need to lock
Greg Claytonacdbe812012-01-30 09:04:36 +00001700 return target_sp->GetBreakpointList().GetSize();
Greg Claytonaf67cec2010-12-20 20:49:23 +00001701 }
Greg Clayton9fed0d82010-07-23 23:33:17 +00001702 return 0;
1703}
1704
1705SBBreakpoint
1706SBTarget::GetBreakpointAtIndex (uint32_t idx) const
1707{
1708 SBBreakpoint sb_breakpoint;
Greg Claytonacdbe812012-01-30 09:04:36 +00001709 TargetSP target_sp(GetSP());
1710 if (target_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +00001711 {
1712 // The breakpoint list is thread safe, no need to lock
Greg Claytonacdbe812012-01-30 09:04:36 +00001713 *sb_breakpoint = target_sp->GetBreakpointList().GetBreakpointAtIndex(idx);
Greg Claytonaf67cec2010-12-20 20:49:23 +00001714 }
Greg Clayton9fed0d82010-07-23 23:33:17 +00001715 return sb_breakpoint;
1716}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001717
1718bool
1719SBTarget::BreakpointDelete (break_id_t bp_id)
1720{
Greg Clayton5160ce52013-03-27 23:08:40 +00001721 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001722
Caroline Ticeceb6b132010-10-26 03:11:13 +00001723 bool result = false;
Greg Claytonacdbe812012-01-30 09:04:36 +00001724 TargetSP target_sp(GetSP());
1725 if (target_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +00001726 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001727 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1728 result = target_sp->RemoveBreakpointByID (bp_id);
Greg Claytonaf67cec2010-12-20 20:49:23 +00001729 }
Caroline Ticeceb6b132010-10-26 03:11:13 +00001730
1731 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001732 log->Printf ("SBTarget(%p)::BreakpointDelete (bp_id=%d) => %i",
1733 static_cast<void*>(target_sp.get()),
1734 static_cast<uint32_t>(bp_id), result);
Caroline Ticeceb6b132010-10-26 03:11:13 +00001735
1736 return result;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001737}
1738
Johnny Chen5d043462011-09-26 22:40:50 +00001739SBBreakpoint
1740SBTarget::FindBreakpointByID (break_id_t bp_id)
1741{
Greg Clayton5160ce52013-03-27 23:08:40 +00001742 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Johnny Chen5d043462011-09-26 22:40:50 +00001743
1744 SBBreakpoint sb_breakpoint;
Greg Claytonacdbe812012-01-30 09:04:36 +00001745 TargetSP target_sp(GetSP());
1746 if (target_sp && bp_id != LLDB_INVALID_BREAK_ID)
Johnny Chen5d043462011-09-26 22:40:50 +00001747 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001748 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1749 *sb_breakpoint = target_sp->GetBreakpointByID (bp_id);
Johnny Chen5d043462011-09-26 22:40:50 +00001750 }
1751
1752 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001753 log->Printf ("SBTarget(%p)::FindBreakpointByID (bp_id=%d) => SBBreakpoint(%p)",
1754 static_cast<void*>(target_sp.get()),
1755 static_cast<uint32_t>(bp_id),
1756 static_cast<void*>(sb_breakpoint.get()));
Johnny Chen5d043462011-09-26 22:40:50 +00001757
1758 return sb_breakpoint;
1759}
1760
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001761bool
1762SBTarget::EnableAllBreakpoints ()
1763{
Greg Claytonacdbe812012-01-30 09:04:36 +00001764 TargetSP target_sp(GetSP());
1765 if (target_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001766 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001767 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1768 target_sp->EnableAllBreakpoints ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001769 return true;
1770 }
1771 return false;
1772}
1773
1774bool
1775SBTarget::DisableAllBreakpoints ()
1776{
Greg Claytonacdbe812012-01-30 09:04:36 +00001777 TargetSP target_sp(GetSP());
1778 if (target_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001779 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001780 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1781 target_sp->DisableAllBreakpoints ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001782 return true;
1783 }
1784 return false;
1785}
1786
1787bool
1788SBTarget::DeleteAllBreakpoints ()
1789{
Greg Claytonacdbe812012-01-30 09:04:36 +00001790 TargetSP target_sp(GetSP());
1791 if (target_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001792 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001793 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1794 target_sp->RemoveAllBreakpoints ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001795 return true;
1796 }
1797 return false;
1798}
1799
Johnny Chen5d043462011-09-26 22:40:50 +00001800uint32_t
Greg Clayton1b282f92011-10-13 18:08:26 +00001801SBTarget::GetNumWatchpoints () const
Johnny Chen5d043462011-09-26 22:40:50 +00001802{
Greg Claytonacdbe812012-01-30 09:04:36 +00001803 TargetSP target_sp(GetSP());
1804 if (target_sp)
Johnny Chen5d043462011-09-26 22:40:50 +00001805 {
Johnny Chen01a67862011-10-14 00:42:25 +00001806 // The watchpoint list is thread safe, no need to lock
Greg Claytonacdbe812012-01-30 09:04:36 +00001807 return target_sp->GetWatchpointList().GetSize();
Johnny Chen5d043462011-09-26 22:40:50 +00001808 }
1809 return 0;
1810}
1811
Greg Clayton1b282f92011-10-13 18:08:26 +00001812SBWatchpoint
1813SBTarget::GetWatchpointAtIndex (uint32_t idx) const
Johnny Chen9d954d82011-09-27 20:29:45 +00001814{
Johnny Chen01a67862011-10-14 00:42:25 +00001815 SBWatchpoint sb_watchpoint;
Greg Claytonacdbe812012-01-30 09:04:36 +00001816 TargetSP target_sp(GetSP());
1817 if (target_sp)
Johnny Chen5d043462011-09-26 22:40:50 +00001818 {
Johnny Chen01a67862011-10-14 00:42:25 +00001819 // The watchpoint list is thread safe, no need to lock
Greg Clayton81e871e2012-02-04 02:27:34 +00001820 sb_watchpoint.SetSP (target_sp->GetWatchpointList().GetByIndex(idx));
Johnny Chen5d043462011-09-26 22:40:50 +00001821 }
Johnny Chen01a67862011-10-14 00:42:25 +00001822 return sb_watchpoint;
Johnny Chen5d043462011-09-26 22:40:50 +00001823}
1824
1825bool
Greg Clayton1b282f92011-10-13 18:08:26 +00001826SBTarget::DeleteWatchpoint (watch_id_t wp_id)
Johnny Chen5d043462011-09-26 22:40:50 +00001827{
Greg Clayton5160ce52013-03-27 23:08:40 +00001828 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Johnny Chen5d043462011-09-26 22:40:50 +00001829
1830 bool result = false;
Greg Claytonacdbe812012-01-30 09:04:36 +00001831 TargetSP target_sp(GetSP());
1832 if (target_sp)
Johnny Chen5d043462011-09-26 22:40:50 +00001833 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001834 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Johnny Chen7385a5a2012-05-31 22:56:36 +00001835 Mutex::Locker locker;
1836 target_sp->GetWatchpointList().GetListMutex(locker);
Greg Claytonacdbe812012-01-30 09:04:36 +00001837 result = target_sp->RemoveWatchpointByID (wp_id);
Johnny Chen5d043462011-09-26 22:40:50 +00001838 }
1839
1840 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001841 log->Printf ("SBTarget(%p)::WatchpointDelete (wp_id=%d) => %i",
1842 static_cast<void*>(target_sp.get()),
1843 static_cast<uint32_t>(wp_id), result);
Johnny Chen5d043462011-09-26 22:40:50 +00001844
1845 return result;
1846}
1847
Greg Clayton1b282f92011-10-13 18:08:26 +00001848SBWatchpoint
1849SBTarget::FindWatchpointByID (lldb::watch_id_t wp_id)
Johnny Chen5d043462011-09-26 22:40:50 +00001850{
Greg Clayton5160ce52013-03-27 23:08:40 +00001851 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Johnny Chen5d043462011-09-26 22:40:50 +00001852
Greg Clayton1b282f92011-10-13 18:08:26 +00001853 SBWatchpoint sb_watchpoint;
Greg Clayton81e871e2012-02-04 02:27:34 +00001854 lldb::WatchpointSP watchpoint_sp;
Greg Claytonacdbe812012-01-30 09:04:36 +00001855 TargetSP target_sp(GetSP());
1856 if (target_sp && wp_id != LLDB_INVALID_WATCH_ID)
Johnny Chen5d043462011-09-26 22:40:50 +00001857 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001858 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Johnny Chen7385a5a2012-05-31 22:56:36 +00001859 Mutex::Locker locker;
1860 target_sp->GetWatchpointList().GetListMutex(locker);
Greg Clayton81e871e2012-02-04 02:27:34 +00001861 watchpoint_sp = target_sp->GetWatchpointList().FindByID(wp_id);
1862 sb_watchpoint.SetSP (watchpoint_sp);
Johnny Chen5d043462011-09-26 22:40:50 +00001863 }
1864
1865 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001866 log->Printf ("SBTarget(%p)::FindWatchpointByID (bp_id=%d) => SBWatchpoint(%p)",
1867 static_cast<void*>(target_sp.get()),
1868 static_cast<uint32_t>(wp_id),
1869 static_cast<void*>(watchpoint_sp.get()));
Johnny Chen5d043462011-09-26 22:40:50 +00001870
Greg Clayton1b282f92011-10-13 18:08:26 +00001871 return sb_watchpoint;
1872}
1873
1874lldb::SBWatchpoint
Johnny Chenb90827e2012-06-04 23:19:54 +00001875SBTarget::WatchAddress (lldb::addr_t addr, size_t size, bool read, bool write, SBError &error)
Greg Clayton1b282f92011-10-13 18:08:26 +00001876{
Greg Clayton5160ce52013-03-27 23:08:40 +00001877 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001878
Greg Clayton1b282f92011-10-13 18:08:26 +00001879 SBWatchpoint sb_watchpoint;
Greg Clayton81e871e2012-02-04 02:27:34 +00001880 lldb::WatchpointSP watchpoint_sp;
Greg Claytonacdbe812012-01-30 09:04:36 +00001881 TargetSP target_sp(GetSP());
Greg Clayton81e871e2012-02-04 02:27:34 +00001882 if (target_sp && (read || write) && addr != LLDB_INVALID_ADDRESS && size > 0)
Greg Clayton1b282f92011-10-13 18:08:26 +00001883 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001884 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton81e871e2012-02-04 02:27:34 +00001885 uint32_t watch_type = 0;
1886 if (read)
1887 watch_type |= LLDB_WATCH_TYPE_READ;
1888 if (write)
1889 watch_type |= LLDB_WATCH_TYPE_WRITE;
Jim Inghamc6462312013-06-18 21:52:48 +00001890 if (watch_type == 0)
1891 {
1892 error.SetErrorString("Can't create a watchpoint that is neither read nor write.");
1893 return sb_watchpoint;
1894 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001895
Johnny Chen7385a5a2012-05-31 22:56:36 +00001896 // Target::CreateWatchpoint() is thread safe.
Johnny Chenb90827e2012-06-04 23:19:54 +00001897 Error cw_error;
Jim Inghama7dfb662012-10-23 07:20:06 +00001898 // This API doesn't take in a type, so we can't figure out what it is.
1899 ClangASTType *type = NULL;
1900 watchpoint_sp = target_sp->CreateWatchpoint(addr, size, type, watch_type, cw_error);
Johnny Chenb90827e2012-06-04 23:19:54 +00001901 error.SetError(cw_error);
Greg Clayton81e871e2012-02-04 02:27:34 +00001902 sb_watchpoint.SetSP (watchpoint_sp);
Greg Clayton1b282f92011-10-13 18:08:26 +00001903 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001904
Greg Clayton1b282f92011-10-13 18:08:26 +00001905 if (log)
Daniel Malead01b2952012-11-29 21:49:15 +00001906 log->Printf ("SBTarget(%p)::WatchAddress (addr=0x%" PRIx64 ", 0x%u) => SBWatchpoint(%p)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001907 static_cast<void*>(target_sp.get()), addr,
1908 static_cast<uint32_t>(size),
1909 static_cast<void*>(watchpoint_sp.get()));
1910
Greg Clayton1b282f92011-10-13 18:08:26 +00001911 return sb_watchpoint;
Johnny Chen5d043462011-09-26 22:40:50 +00001912}
1913
1914bool
Greg Clayton1b282f92011-10-13 18:08:26 +00001915SBTarget::EnableAllWatchpoints ()
Johnny Chen5d043462011-09-26 22:40:50 +00001916{
Greg Claytonacdbe812012-01-30 09:04:36 +00001917 TargetSP target_sp(GetSP());
1918 if (target_sp)
Johnny Chen5d043462011-09-26 22:40:50 +00001919 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001920 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Johnny Chen7385a5a2012-05-31 22:56:36 +00001921 Mutex::Locker locker;
1922 target_sp->GetWatchpointList().GetListMutex(locker);
Greg Claytonacdbe812012-01-30 09:04:36 +00001923 target_sp->EnableAllWatchpoints ();
Johnny Chen5d043462011-09-26 22:40:50 +00001924 return true;
1925 }
1926 return false;
1927}
1928
1929bool
Greg Clayton1b282f92011-10-13 18:08:26 +00001930SBTarget::DisableAllWatchpoints ()
Johnny Chen5d043462011-09-26 22:40:50 +00001931{
Greg Claytonacdbe812012-01-30 09:04:36 +00001932 TargetSP target_sp(GetSP());
1933 if (target_sp)
Johnny Chen5d043462011-09-26 22:40:50 +00001934 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001935 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Johnny Chen7385a5a2012-05-31 22:56:36 +00001936 Mutex::Locker locker;
1937 target_sp->GetWatchpointList().GetListMutex(locker);
Greg Claytonacdbe812012-01-30 09:04:36 +00001938 target_sp->DisableAllWatchpoints ();
Johnny Chen5d043462011-09-26 22:40:50 +00001939 return true;
1940 }
1941 return false;
1942}
1943
Enrico Granata347c2aa2013-10-08 21:49:02 +00001944SBValue
1945SBTarget::CreateValueFromAddress (const char *name, SBAddress addr, SBType type)
1946{
1947 SBValue sb_value;
1948 lldb::ValueObjectSP new_value_sp;
1949 if (IsValid() && name && *name && addr.IsValid() && type.IsValid())
1950 {
Enrico Granata972be532014-12-17 21:18:43 +00001951 lldb::addr_t load_addr(addr.GetLoadAddress(*this));
1952 ExecutionContext exe_ctx (ExecutionContextRef(ExecutionContext(m_opaque_sp.get(),false)));
1953 ClangASTType ast_type(type.GetSP()->GetClangASTType(true));
1954 new_value_sp = ValueObject::CreateValueObjectFromAddress(name, load_addr, exe_ctx, ast_type);
Enrico Granata347c2aa2013-10-08 21:49:02 +00001955 }
1956 sb_value.SetSP(new_value_sp);
1957 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1958 if (log)
1959 {
1960 if (new_value_sp)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001961 log->Printf ("SBTarget(%p)::CreateValueFromAddress => \"%s\"",
1962 static_cast<void*>(m_opaque_sp.get()),
1963 new_value_sp->GetName().AsCString());
Enrico Granata347c2aa2013-10-08 21:49:02 +00001964 else
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001965 log->Printf ("SBTarget(%p)::CreateValueFromAddress => NULL",
1966 static_cast<void*>(m_opaque_sp.get()));
Enrico Granata347c2aa2013-10-08 21:49:02 +00001967 }
1968 return sb_value;
1969}
1970
Enrico Granata972be532014-12-17 21:18:43 +00001971lldb::SBValue
1972SBTarget::CreateValueFromData (const char *name, lldb::SBData data, lldb::SBType type)
1973{
1974 SBValue sb_value;
1975 lldb::ValueObjectSP new_value_sp;
1976 if (IsValid() && name && *name && data.IsValid() && type.IsValid())
1977 {
1978 DataExtractorSP extractor(*data);
1979 ExecutionContext exe_ctx (ExecutionContextRef(ExecutionContext(m_opaque_sp.get(),false)));
1980 ClangASTType ast_type(type.GetSP()->GetClangASTType(true));
1981 new_value_sp = ValueObject::CreateValueObjectFromData(name, *extractor, exe_ctx, ast_type);
1982 }
1983 sb_value.SetSP(new_value_sp);
1984 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1985 if (log)
1986 {
1987 if (new_value_sp)
1988 log->Printf ("SBTarget(%p)::CreateValueFromData => \"%s\"",
1989 static_cast<void*>(m_opaque_sp.get()),
1990 new_value_sp->GetName().AsCString());
1991 else
1992 log->Printf ("SBTarget(%p)::CreateValueFromData => NULL",
1993 static_cast<void*>(m_opaque_sp.get()));
1994 }
1995 return sb_value;
1996}
1997
1998lldb::SBValue
1999SBTarget::CreateValueFromExpression (const char *name, const char* expr)
2000{
2001 SBValue sb_value;
2002 lldb::ValueObjectSP new_value_sp;
2003 if (IsValid() && name && *name && expr && *expr)
2004 {
2005 ExecutionContext exe_ctx (ExecutionContextRef(ExecutionContext(m_opaque_sp.get(),false)));
2006 new_value_sp = ValueObject::CreateValueObjectFromExpression(name, expr, exe_ctx);
2007 }
2008 sb_value.SetSP(new_value_sp);
2009 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
2010 if (log)
2011 {
2012 if (new_value_sp)
2013 log->Printf ("SBTarget(%p)::CreateValueFromExpression => \"%s\"",
2014 static_cast<void*>(m_opaque_sp.get()),
2015 new_value_sp->GetName().AsCString());
2016 else
2017 log->Printf ("SBTarget(%p)::CreateValueFromExpression => NULL",
2018 static_cast<void*>(m_opaque_sp.get()));
2019 }
2020 return sb_value;
2021}
2022
Johnny Chen5d043462011-09-26 22:40:50 +00002023bool
Greg Clayton1b282f92011-10-13 18:08:26 +00002024SBTarget::DeleteAllWatchpoints ()
Johnny Chen5d043462011-09-26 22:40:50 +00002025{
Greg Claytonacdbe812012-01-30 09:04:36 +00002026 TargetSP target_sp(GetSP());
2027 if (target_sp)
Johnny Chen5d043462011-09-26 22:40:50 +00002028 {
Greg Claytonacdbe812012-01-30 09:04:36 +00002029 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Johnny Chen7385a5a2012-05-31 22:56:36 +00002030 Mutex::Locker locker;
2031 target_sp->GetWatchpointList().GetListMutex(locker);
Greg Claytonacdbe812012-01-30 09:04:36 +00002032 target_sp->RemoveAllWatchpoints ();
Johnny Chen5d043462011-09-26 22:40:50 +00002033 return true;
2034 }
2035 return false;
2036}
2037
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002038
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002039lldb::SBModule
2040SBTarget::AddModule (const char *path,
2041 const char *triple,
2042 const char *uuid_cstr)
2043{
Greg Claytonb210aec2012-04-23 20:23:39 +00002044 return AddModule (path, triple, uuid_cstr, NULL);
2045}
2046
2047lldb::SBModule
2048SBTarget::AddModule (const char *path,
2049 const char *triple,
2050 const char *uuid_cstr,
2051 const char *symfile)
2052{
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002053 lldb::SBModule sb_module;
Greg Claytonacdbe812012-01-30 09:04:36 +00002054 TargetSP target_sp(GetSP());
2055 if (target_sp)
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002056 {
Greg Claytonb9a01b32012-02-26 05:51:37 +00002057 ModuleSpec module_spec;
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002058 if (path)
Greg Claytonb9a01b32012-02-26 05:51:37 +00002059 module_spec.GetFileSpec().SetFile(path, false);
Greg Claytonb210aec2012-04-23 20:23:39 +00002060
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002061 if (uuid_cstr)
Greg Claytonb5f0fea2012-09-27 22:26:11 +00002062 module_spec.GetUUID().SetFromCString(uuid_cstr);
Greg Claytonb210aec2012-04-23 20:23:39 +00002063
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002064 if (triple)
Greg Claytonb9a01b32012-02-26 05:51:37 +00002065 module_spec.GetArchitecture().SetTriple (triple, target_sp->GetPlatform ().get());
Jason Molendab019cd92013-09-11 21:25:46 +00002066 else
2067 module_spec.GetArchitecture() = target_sp->GetArchitecture();
Greg Claytonb210aec2012-04-23 20:23:39 +00002068
2069 if (symfile)
2070 module_spec.GetSymbolFileSpec ().SetFile(symfile, false);
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002071
Greg Claytonb9a01b32012-02-26 05:51:37 +00002072 sb_module.SetSP(target_sp->GetSharedModule (module_spec));
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002073 }
2074 return sb_module;
2075}
2076
Greg Clayton226cce22013-07-08 22:22:41 +00002077lldb::SBModule
2078SBTarget::AddModule (const SBModuleSpec &module_spec)
2079{
2080 lldb::SBModule sb_module;
2081 TargetSP target_sp(GetSP());
2082 if (target_sp)
2083 sb_module.SetSP(target_sp->GetSharedModule (*module_spec.m_opaque_ap));
2084 return sb_module;
2085}
2086
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002087bool
2088SBTarget::AddModule (lldb::SBModule &module)
2089{
Greg Claytonacdbe812012-01-30 09:04:36 +00002090 TargetSP target_sp(GetSP());
2091 if (target_sp)
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002092 {
Greg Claytonacdbe812012-01-30 09:04:36 +00002093 target_sp->GetImages().AppendIfNeeded (module.GetSP());
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002094 return true;
2095 }
2096 return false;
2097}
2098
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002099uint32_t
2100SBTarget::GetNumModules () const
2101{
Greg Clayton5160ce52013-03-27 23:08:40 +00002102 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +00002103
Caroline Ticeceb6b132010-10-26 03:11:13 +00002104 uint32_t num = 0;
Greg Claytonacdbe812012-01-30 09:04:36 +00002105 TargetSP target_sp(GetSP());
2106 if (target_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +00002107 {
2108 // The module list is thread safe, no need to lock
Greg Claytonacdbe812012-01-30 09:04:36 +00002109 num = target_sp->GetImages().GetSize();
Greg Claytonaf67cec2010-12-20 20:49:23 +00002110 }
Caroline Ticeceb6b132010-10-26 03:11:13 +00002111
2112 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002113 log->Printf ("SBTarget(%p)::GetNumModules () => %d",
2114 static_cast<void*>(target_sp.get()), num);
Caroline Ticeceb6b132010-10-26 03:11:13 +00002115
2116 return num;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002117}
2118
Greg Clayton48e42542010-07-30 20:12:55 +00002119void
2120SBTarget::Clear ()
2121{
Greg Clayton5160ce52013-03-27 23:08:40 +00002122 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +00002123
2124 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002125 log->Printf ("SBTarget(%p)::Clear ()",
2126 static_cast<void*>(m_opaque_sp.get()));
Caroline Ticeceb6b132010-10-26 03:11:13 +00002127
Greg Clayton48e42542010-07-30 20:12:55 +00002128 m_opaque_sp.reset();
2129}
2130
2131
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002132SBModule
2133SBTarget::FindModule (const SBFileSpec &sb_file_spec)
2134{
2135 SBModule sb_module;
Greg Claytonacdbe812012-01-30 09:04:36 +00002136 TargetSP target_sp(GetSP());
2137 if (target_sp && sb_file_spec.IsValid())
Greg Claytonaf67cec2010-12-20 20:49:23 +00002138 {
Greg Claytonb9a01b32012-02-26 05:51:37 +00002139 ModuleSpec module_spec(*sb_file_spec);
Greg Claytonaf67cec2010-12-20 20:49:23 +00002140 // The module list is thread safe, no need to lock
Greg Claytonb9a01b32012-02-26 05:51:37 +00002141 sb_module.SetSP (target_sp->GetImages().FindFirstModule (module_spec));
Greg Claytonaf67cec2010-12-20 20:49:23 +00002142 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002143 return sb_module;
2144}
2145
Greg Clayton13d19502012-01-29 06:07:39 +00002146lldb::ByteOrder
2147SBTarget::GetByteOrder ()
2148{
Greg Claytonacdbe812012-01-30 09:04:36 +00002149 TargetSP target_sp(GetSP());
2150 if (target_sp)
2151 return target_sp->GetArchitecture().GetByteOrder();
Greg Clayton13d19502012-01-29 06:07:39 +00002152 return eByteOrderInvalid;
2153}
2154
2155const char *
2156SBTarget::GetTriple ()
2157{
Greg Claytonacdbe812012-01-30 09:04:36 +00002158 TargetSP target_sp(GetSP());
2159 if (target_sp)
Greg Clayton13d19502012-01-29 06:07:39 +00002160 {
Greg Claytonacdbe812012-01-30 09:04:36 +00002161 std::string triple (target_sp->GetArchitecture().GetTriple().str());
Greg Clayton13d19502012-01-29 06:07:39 +00002162 // Unique the string so we don't run into ownership issues since
2163 // the const strings put the string into the string pool once and
2164 // the strings never comes out
2165 ConstString const_triple (triple.c_str());
2166 return const_triple.GetCString();
2167 }
2168 return NULL;
2169}
2170
2171uint32_t
Matthew Gardinerc928de32014-10-22 07:22:56 +00002172SBTarget::GetDataByteSize ()
2173{
2174 TargetSP target_sp(GetSP());
2175 if (target_sp)
2176 {
2177 return target_sp->GetArchitecture().GetDataByteSize() ;
2178 }
2179 return 0;
2180}
2181
2182uint32_t
2183SBTarget::GetCodeByteSize ()
2184{
2185 TargetSP target_sp(GetSP());
2186 if (target_sp)
2187 {
2188 return target_sp->GetArchitecture().GetCodeByteSize() ;
2189 }
2190 return 0;
2191}
2192
2193uint32_t
Greg Clayton13d19502012-01-29 06:07:39 +00002194SBTarget::GetAddressByteSize()
2195{
Greg Claytonacdbe812012-01-30 09:04:36 +00002196 TargetSP target_sp(GetSP());
2197 if (target_sp)
2198 return target_sp->GetArchitecture().GetAddressByteSize();
Greg Clayton13d19502012-01-29 06:07:39 +00002199 return sizeof(void*);
2200}
2201
2202
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002203SBModule
2204SBTarget::GetModuleAtIndex (uint32_t idx)
2205{
Greg Clayton5160ce52013-03-27 23:08:40 +00002206 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +00002207
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002208 SBModule sb_module;
Greg Claytonacdbe812012-01-30 09:04:36 +00002209 ModuleSP module_sp;
2210 TargetSP target_sp(GetSP());
2211 if (target_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +00002212 {
2213 // The module list is thread safe, no need to lock
Greg Claytonacdbe812012-01-30 09:04:36 +00002214 module_sp = target_sp->GetImages().GetModuleAtIndex(idx);
2215 sb_module.SetSP (module_sp);
Greg Claytonaf67cec2010-12-20 20:49:23 +00002216 }
Caroline Ticeceb6b132010-10-26 03:11:13 +00002217
2218 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002219 log->Printf ("SBTarget(%p)::GetModuleAtIndex (idx=%d) => SBModule(%p)",
2220 static_cast<void*>(target_sp.get()), idx,
2221 static_cast<void*>(module_sp.get()));
Caroline Ticeceb6b132010-10-26 03:11:13 +00002222
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002223 return sb_module;
2224}
2225
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002226bool
2227SBTarget::RemoveModule (lldb::SBModule module)
2228{
Greg Claytonacdbe812012-01-30 09:04:36 +00002229 TargetSP target_sp(GetSP());
2230 if (target_sp)
2231 return target_sp->GetImages().Remove(module.GetSP());
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002232 return false;
2233}
2234
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002235
2236SBBroadcaster
2237SBTarget::GetBroadcaster () const
2238{
Greg Clayton5160ce52013-03-27 23:08:40 +00002239 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +00002240
Greg Claytonacdbe812012-01-30 09:04:36 +00002241 TargetSP target_sp(GetSP());
2242 SBBroadcaster broadcaster(target_sp.get(), false);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002243
Caroline Ticeceb6b132010-10-26 03:11:13 +00002244 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002245 log->Printf ("SBTarget(%p)::GetBroadcaster () => SBBroadcaster(%p)",
2246 static_cast<void*>(target_sp.get()),
2247 static_cast<void*>(broadcaster.get()));
Caroline Ticeceb6b132010-10-26 03:11:13 +00002248
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002249 return broadcaster;
2250}
2251
Caroline Ticedde9cff2010-09-20 05:20:02 +00002252bool
Caroline Ticeceb6b132010-10-26 03:11:13 +00002253SBTarget::GetDescription (SBStream &description, lldb::DescriptionLevel description_level)
Caroline Ticedde9cff2010-09-20 05:20:02 +00002254{
Greg Claytonda7bc7d2011-11-13 06:57:31 +00002255 Stream &strm = description.ref();
2256
Greg Claytonacdbe812012-01-30 09:04:36 +00002257 TargetSP target_sp(GetSP());
2258 if (target_sp)
Caroline Tice201a8852010-09-20 16:21:41 +00002259 {
Greg Claytonacdbe812012-01-30 09:04:36 +00002260 target_sp->Dump (&strm, description_level);
Caroline Ticeceb6b132010-10-26 03:11:13 +00002261 }
2262 else
Greg Claytonda7bc7d2011-11-13 06:57:31 +00002263 strm.PutCString ("No value");
Caroline Ticeceb6b132010-10-26 03:11:13 +00002264
2265 return true;
2266}
2267
Greg Clayton5569e642012-02-06 01:44:54 +00002268lldb::SBSymbolContextList
2269SBTarget::FindFunctions (const char *name, uint32_t name_type_mask)
Greg Claytonfe356d32011-06-21 01:34:41 +00002270{
Greg Clayton5569e642012-02-06 01:44:54 +00002271 lldb::SBSymbolContextList sb_sc_list;
Greg Claytonacdbe812012-01-30 09:04:36 +00002272 if (name && name[0])
Greg Claytonfe356d32011-06-21 01:34:41 +00002273 {
Greg Claytonacdbe812012-01-30 09:04:36 +00002274 TargetSP target_sp(GetSP());
2275 if (target_sp)
2276 {
2277 const bool symbols_ok = true;
Sean Callanan9df05fb2012-02-10 22:52:19 +00002278 const bool inlines_ok = true;
Greg Clayton5569e642012-02-06 01:44:54 +00002279 const bool append = true;
2280 target_sp->GetImages().FindFunctions (ConstString(name),
2281 name_type_mask,
Sean Callanan9df05fb2012-02-10 22:52:19 +00002282 symbols_ok,
2283 inlines_ok,
Greg Clayton5569e642012-02-06 01:44:54 +00002284 append,
2285 *sb_sc_list);
Greg Claytonacdbe812012-01-30 09:04:36 +00002286 }
Greg Claytonfe356d32011-06-21 01:34:41 +00002287 }
Greg Clayton5569e642012-02-06 01:44:54 +00002288 return sb_sc_list;
Greg Claytonfe356d32011-06-21 01:34:41 +00002289}
2290
Carlo Kok0fd6fd42014-09-19 19:38:19 +00002291lldb::SBSymbolContextList
2292SBTarget::FindGlobalFunctions(const char *name, uint32_t max_matches, MatchType matchtype)
2293{
2294 lldb::SBSymbolContextList sb_sc_list;
2295 if (name && name[0])
2296 {
2297 TargetSP target_sp(GetSP());
2298 if (target_sp)
2299 {
2300 std::string regexstr;
2301 switch (matchtype)
2302 {
2303 case eMatchTypeRegex:
2304 target_sp->GetImages().FindFunctions(RegularExpression(name), true, true, true, *sb_sc_list);
2305 break;
2306 case eMatchTypeStartsWith:
2307 regexstr = llvm::Regex::escape(name) + ".*";
2308 target_sp->GetImages().FindFunctions(RegularExpression(regexstr.c_str()), true, true, true, *sb_sc_list);
2309 break;
2310 default:
2311 target_sp->GetImages().FindFunctions(ConstString(name), eFunctionNameTypeAny, true, true, true, *sb_sc_list);
2312 break;
2313 }
2314 }
2315 }
2316 return sb_sc_list;
2317}
2318
Enrico Granata6f3533f2011-07-29 19:53:35 +00002319lldb::SBType
Greg Claytonb43165b2012-12-05 21:24:42 +00002320SBTarget::FindFirstType (const char* typename_cstr)
Enrico Granata6f3533f2011-07-29 19:53:35 +00002321{
Greg Claytonacdbe812012-01-30 09:04:36 +00002322 TargetSP target_sp(GetSP());
Greg Claytonb43165b2012-12-05 21:24:42 +00002323 if (typename_cstr && typename_cstr[0] && target_sp)
Enrico Granata6f3533f2011-07-29 19:53:35 +00002324 {
Greg Claytonb43165b2012-12-05 21:24:42 +00002325 ConstString const_typename(typename_cstr);
2326 SymbolContext sc;
2327 const bool exact_match = false;
2328
2329 const ModuleList &module_list = target_sp->GetImages();
2330 size_t count = module_list.GetSize();
Enrico Granata6f3533f2011-07-29 19:53:35 +00002331 for (size_t idx = 0; idx < count; idx++)
2332 {
Greg Claytonb43165b2012-12-05 21:24:42 +00002333 ModuleSP module_sp (module_list.GetModuleAtIndex(idx));
2334 if (module_sp)
2335 {
2336 TypeSP type_sp (module_sp->FindFirstType(sc, const_typename, exact_match));
2337 if (type_sp)
2338 return SBType(type_sp);
2339 }
Enrico Granata6f3533f2011-07-29 19:53:35 +00002340 }
Sean Callanan7be70e82012-12-19 23:05:01 +00002341
2342 // Didn't find the type in the symbols; try the Objective-C runtime
2343 // if one is installed
2344
2345 ProcessSP process_sp(target_sp->GetProcessSP());
2346
2347 if (process_sp)
2348 {
2349 ObjCLanguageRuntime *objc_language_runtime = process_sp->GetObjCLanguageRuntime();
2350
2351 if (objc_language_runtime)
2352 {
Sean Callanan9998acd2014-12-05 01:21:59 +00002353 DeclVendor *objc_decl_vendor = objc_language_runtime->GetDeclVendor();
Sean Callanan7be70e82012-12-19 23:05:01 +00002354
Sean Callanan9998acd2014-12-05 01:21:59 +00002355 if (objc_decl_vendor)
Sean Callanan7be70e82012-12-19 23:05:01 +00002356 {
Sean Callanan9998acd2014-12-05 01:21:59 +00002357 std::vector <clang::NamedDecl *> decls;
Sean Callanan7be70e82012-12-19 23:05:01 +00002358
Sean Callanan9998acd2014-12-05 01:21:59 +00002359 if (objc_decl_vendor->FindDecls(const_typename, true, 1, decls) > 0)
2360 {
2361 if (ClangASTType type = ClangASTContext::GetTypeForDecl(decls[0]))
2362 {
2363 return SBType(type);
2364 }
2365 }
Sean Callanan7be70e82012-12-19 23:05:01 +00002366 }
2367 }
2368 }
Greg Claytonb43165b2012-12-05 21:24:42 +00002369
2370 // No matches, search for basic typename matches
2371 ClangASTContext *clang_ast = target_sp->GetScratchClangASTContext();
2372 if (clang_ast)
Greg Clayton57ee3062013-07-11 22:46:58 +00002373 return SBType (ClangASTContext::GetBasicType (clang_ast->getASTContext(), const_typename));
Enrico Granata6f3533f2011-07-29 19:53:35 +00002374 }
2375 return SBType();
2376}
2377
Greg Claytonb43165b2012-12-05 21:24:42 +00002378SBType
2379SBTarget::GetBasicType(lldb::BasicType type)
Enrico Granata6f3533f2011-07-29 19:53:35 +00002380{
Greg Claytonacdbe812012-01-30 09:04:36 +00002381 TargetSP target_sp(GetSP());
Greg Claytonb43165b2012-12-05 21:24:42 +00002382 if (target_sp)
2383 {
2384 ClangASTContext *clang_ast = target_sp->GetScratchClangASTContext();
2385 if (clang_ast)
Greg Clayton57ee3062013-07-11 22:46:58 +00002386 return SBType (ClangASTContext::GetBasicType (clang_ast->getASTContext(), type));
Greg Claytonb43165b2012-12-05 21:24:42 +00002387 }
2388 return SBType();
2389}
2390
2391
2392lldb::SBTypeList
2393SBTarget::FindTypes (const char* typename_cstr)
2394{
2395 SBTypeList sb_type_list;
2396 TargetSP target_sp(GetSP());
2397 if (typename_cstr && typename_cstr[0] && target_sp)
Enrico Granata6f3533f2011-07-29 19:53:35 +00002398 {
Greg Claytonacdbe812012-01-30 09:04:36 +00002399 ModuleList& images = target_sp->GetImages();
Greg Claytonb43165b2012-12-05 21:24:42 +00002400 ConstString const_typename(typename_cstr);
Greg Clayton84db9102012-03-26 23:03:23 +00002401 bool exact_match = false;
Enrico Granata6f3533f2011-07-29 19:53:35 +00002402 SymbolContext sc;
2403 TypeList type_list;
2404
Greg Clayton29399a22012-04-06 17:41:13 +00002405 uint32_t num_matches = images.FindTypes (sc,
Greg Claytonb43165b2012-12-05 21:24:42 +00002406 const_typename,
Greg Clayton84db9102012-03-26 23:03:23 +00002407 exact_match,
2408 UINT32_MAX,
2409 type_list);
Enrico Granata6f3533f2011-07-29 19:53:35 +00002410
Greg Claytonb43165b2012-12-05 21:24:42 +00002411 if (num_matches > 0)
Enrico Granata6f3533f2011-07-29 19:53:35 +00002412 {
Greg Claytonb43165b2012-12-05 21:24:42 +00002413 for (size_t idx = 0; idx < num_matches; idx++)
2414 {
2415 TypeSP type_sp (type_list.GetTypeAtIndex(idx));
2416 if (type_sp)
2417 sb_type_list.Append(SBType(type_sp));
2418 }
2419 }
Sean Callanan7be70e82012-12-19 23:05:01 +00002420
2421 // Try the Objective-C runtime if one is installed
2422
2423 ProcessSP process_sp(target_sp->GetProcessSP());
2424
2425 if (process_sp)
2426 {
2427 ObjCLanguageRuntime *objc_language_runtime = process_sp->GetObjCLanguageRuntime();
2428
2429 if (objc_language_runtime)
2430 {
Sean Callanan9998acd2014-12-05 01:21:59 +00002431 DeclVendor *objc_decl_vendor = objc_language_runtime->GetDeclVendor();
Sean Callanan7be70e82012-12-19 23:05:01 +00002432
Sean Callanan9998acd2014-12-05 01:21:59 +00002433 if (objc_decl_vendor)
Sean Callanan7be70e82012-12-19 23:05:01 +00002434 {
Sean Callanan9998acd2014-12-05 01:21:59 +00002435 std::vector <clang::NamedDecl *> decls;
Sean Callanan7be70e82012-12-19 23:05:01 +00002436
Sean Callanan9998acd2014-12-05 01:21:59 +00002437 if (objc_decl_vendor->FindDecls(const_typename, true, 1, decls) > 0)
Sean Callanan7be70e82012-12-19 23:05:01 +00002438 {
Sean Callanan9998acd2014-12-05 01:21:59 +00002439 for (clang::NamedDecl *decl : decls)
Sean Callanan7be70e82012-12-19 23:05:01 +00002440 {
Sean Callanan9998acd2014-12-05 01:21:59 +00002441 if (ClangASTType type = ClangASTContext::GetTypeForDecl(decl))
2442 {
2443 sb_type_list.Append(SBType(type));
2444 }
Sean Callanan7be70e82012-12-19 23:05:01 +00002445 }
2446 }
2447 }
2448 }
2449 }
2450
2451 if (sb_type_list.GetSize() == 0)
Greg Claytonb43165b2012-12-05 21:24:42 +00002452 {
2453 // No matches, search for basic typename matches
2454 ClangASTContext *clang_ast = target_sp->GetScratchClangASTContext();
2455 if (clang_ast)
Greg Clayton57ee3062013-07-11 22:46:58 +00002456 sb_type_list.Append (SBType (ClangASTContext::GetBasicType (clang_ast->getASTContext(), const_typename)));
Enrico Granata6f3533f2011-07-29 19:53:35 +00002457 }
2458 }
Greg Claytonb43165b2012-12-05 21:24:42 +00002459 return sb_type_list;
Enrico Granata6f3533f2011-07-29 19:53:35 +00002460}
2461
Greg Claytondea8cb42011-06-29 22:09:02 +00002462SBValueList
2463SBTarget::FindGlobalVariables (const char *name, uint32_t max_matches)
2464{
2465 SBValueList sb_value_list;
2466
Greg Claytonacdbe812012-01-30 09:04:36 +00002467 TargetSP target_sp(GetSP());
2468 if (name && target_sp)
Greg Claytondea8cb42011-06-29 22:09:02 +00002469 {
2470 VariableList variable_list;
2471 const bool append = true;
Greg Claytonacdbe812012-01-30 09:04:36 +00002472 const uint32_t match_count = target_sp->GetImages().FindGlobalVariables (ConstString (name),
2473 append,
2474 max_matches,
2475 variable_list);
Greg Claytondea8cb42011-06-29 22:09:02 +00002476
2477 if (match_count > 0)
2478 {
Greg Claytonacdbe812012-01-30 09:04:36 +00002479 ExecutionContextScope *exe_scope = target_sp->GetProcessSP().get();
Greg Claytondea8cb42011-06-29 22:09:02 +00002480 if (exe_scope == NULL)
Greg Claytonacdbe812012-01-30 09:04:36 +00002481 exe_scope = target_sp.get();
Greg Claytondea8cb42011-06-29 22:09:02 +00002482 for (uint32_t i=0; i<match_count; ++i)
2483 {
2484 lldb::ValueObjectSP valobj_sp (ValueObjectVariable::Create (exe_scope, variable_list.GetVariableAtIndex(i)));
2485 if (valobj_sp)
Enrico Granata85425d72013-02-07 18:23:56 +00002486 sb_value_list.Append(SBValue(valobj_sp));
Greg Claytondea8cb42011-06-29 22:09:02 +00002487 }
2488 }
2489 }
2490
2491 return sb_value_list;
2492}
2493
Carlo Kok0fd6fd42014-09-19 19:38:19 +00002494SBValueList
2495SBTarget::FindGlobalVariables(const char *name, uint32_t max_matches, MatchType matchtype)
2496{
2497 SBValueList sb_value_list;
2498
2499 TargetSP target_sp(GetSP());
2500 if (name && target_sp)
2501 {
2502 VariableList variable_list;
2503 const bool append = true;
2504
2505 std::string regexstr;
2506 uint32_t match_count;
2507 switch (matchtype)
2508 {
2509 case eMatchTypeNormal:
2510 match_count = target_sp->GetImages().FindGlobalVariables(ConstString(name),
2511 append,
2512 max_matches,
2513 variable_list);
2514 break;
2515 case eMatchTypeRegex:
2516 match_count = target_sp->GetImages().FindGlobalVariables(RegularExpression(name),
2517 append,
2518 max_matches,
2519 variable_list);
2520 break;
2521 case eMatchTypeStartsWith:
2522 regexstr = llvm::Regex::escape(name) + ".*";
2523 match_count = target_sp->GetImages().FindGlobalVariables(RegularExpression(regexstr.c_str()),
2524 append,
2525 max_matches,
2526 variable_list);
2527 break;
2528 }
2529
2530
2531 if (match_count > 0)
2532 {
2533 ExecutionContextScope *exe_scope = target_sp->GetProcessSP().get();
2534 if (exe_scope == NULL)
2535 exe_scope = target_sp.get();
2536 for (uint32_t i = 0; i<match_count; ++i)
2537 {
2538 lldb::ValueObjectSP valobj_sp(ValueObjectVariable::Create(exe_scope, variable_list.GetVariableAtIndex(i)));
2539 if (valobj_sp)
2540 sb_value_list.Append(SBValue(valobj_sp));
2541 }
2542 }
2543 }
2544
2545 return sb_value_list;
2546}
2547
2548
Enrico Granatabcd80b42013-01-16 18:53:52 +00002549lldb::SBValue
2550SBTarget::FindFirstGlobalVariable (const char* name)
2551{
2552 SBValueList sb_value_list(FindGlobalVariables(name, 1));
2553 if (sb_value_list.IsValid() && sb_value_list.GetSize() > 0)
2554 return sb_value_list.GetValueAtIndex(0);
2555 return SBValue();
2556}
2557
Jim Inghame37d6052011-09-13 00:29:56 +00002558SBSourceManager
2559SBTarget::GetSourceManager()
2560{
2561 SBSourceManager source_manager (*this);
2562 return source_manager;
2563}
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002564
Sean Callanan50952e92011-12-14 23:49:37 +00002565lldb::SBInstructionList
Greg Clayton9c766112012-03-06 22:24:44 +00002566SBTarget::ReadInstructions (lldb::SBAddress base_addr, uint32_t count)
2567{
Jim Ingham0f063ba2013-03-02 00:26:47 +00002568 return ReadInstructions (base_addr, count, NULL);
2569}
2570
2571lldb::SBInstructionList
2572SBTarget::ReadInstructions (lldb::SBAddress base_addr, uint32_t count, const char *flavor_string)
2573{
Greg Clayton9c766112012-03-06 22:24:44 +00002574 SBInstructionList sb_instructions;
2575
2576 TargetSP target_sp(GetSP());
2577 if (target_sp)
2578 {
2579 Address *addr_ptr = base_addr.get();
2580
2581 if (addr_ptr)
2582 {
2583 DataBufferHeap data (target_sp->GetArchitecture().GetMaximumOpcodeByteSize() * count, 0);
2584 bool prefer_file_cache = false;
2585 lldb_private::Error error;
Greg Clayton3faf47c2013-03-28 23:42:53 +00002586 lldb::addr_t load_addr = LLDB_INVALID_ADDRESS;
2587 const size_t bytes_read = target_sp->ReadMemory(*addr_ptr,
2588 prefer_file_cache,
2589 data.GetBytes(),
2590 data.GetByteSize(),
2591 error,
2592 &load_addr);
2593 const bool data_from_file = load_addr == LLDB_INVALID_ADDRESS;
Greg Clayton9c766112012-03-06 22:24:44 +00002594 sb_instructions.SetDisassembler (Disassembler::DisassembleBytes (target_sp->GetArchitecture(),
2595 NULL,
Jim Ingham0f063ba2013-03-02 00:26:47 +00002596 flavor_string,
Greg Clayton9c766112012-03-06 22:24:44 +00002597 *addr_ptr,
2598 data.GetBytes(),
2599 bytes_read,
Greg Clayton3faf47c2013-03-28 23:42:53 +00002600 count,
2601 data_from_file));
Greg Clayton9c766112012-03-06 22:24:44 +00002602 }
2603 }
2604
2605 return sb_instructions;
2606
2607}
2608
2609lldb::SBInstructionList
Sean Callanan50952e92011-12-14 23:49:37 +00002610SBTarget::GetInstructions (lldb::SBAddress base_addr, const void *buf, size_t size)
2611{
Jim Ingham0f063ba2013-03-02 00:26:47 +00002612 return GetInstructionsWithFlavor (base_addr, NULL, buf, size);
2613}
2614
2615lldb::SBInstructionList
2616SBTarget::GetInstructionsWithFlavor (lldb::SBAddress base_addr, const char *flavor_string, const void *buf, size_t size)
2617{
Sean Callanan50952e92011-12-14 23:49:37 +00002618 SBInstructionList sb_instructions;
2619
Greg Claytonacdbe812012-01-30 09:04:36 +00002620 TargetSP target_sp(GetSP());
2621 if (target_sp)
Sean Callanan50952e92011-12-14 23:49:37 +00002622 {
2623 Address addr;
2624
2625 if (base_addr.get())
2626 addr = *base_addr.get();
2627
Greg Clayton3faf47c2013-03-28 23:42:53 +00002628 const bool data_from_file = true;
2629
Greg Claytonacdbe812012-01-30 09:04:36 +00002630 sb_instructions.SetDisassembler (Disassembler::DisassembleBytes (target_sp->GetArchitecture(),
Sean Callanan50952e92011-12-14 23:49:37 +00002631 NULL,
Jim Ingham0f063ba2013-03-02 00:26:47 +00002632 flavor_string,
Sean Callanan50952e92011-12-14 23:49:37 +00002633 addr,
2634 buf,
Greg Clayton3faf47c2013-03-28 23:42:53 +00002635 size,
2636 UINT32_MAX,
2637 data_from_file));
Sean Callanan50952e92011-12-14 23:49:37 +00002638 }
2639
2640 return sb_instructions;
2641}
2642
2643lldb::SBInstructionList
2644SBTarget::GetInstructions (lldb::addr_t base_addr, const void *buf, size_t size)
2645{
Jim Ingham0f063ba2013-03-02 00:26:47 +00002646 return GetInstructionsWithFlavor (ResolveLoadAddress(base_addr), NULL, buf, size);
2647}
2648
2649lldb::SBInstructionList
2650SBTarget::GetInstructionsWithFlavor (lldb::addr_t base_addr, const char *flavor_string, const void *buf, size_t size)
2651{
2652 return GetInstructionsWithFlavor (ResolveLoadAddress(base_addr), flavor_string, buf, size);
Sean Callanan50952e92011-12-14 23:49:37 +00002653}
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002654
2655SBError
2656SBTarget::SetSectionLoadAddress (lldb::SBSection section,
2657 lldb::addr_t section_base_addr)
2658{
2659 SBError sb_error;
Greg Claytonacdbe812012-01-30 09:04:36 +00002660 TargetSP target_sp(GetSP());
2661 if (target_sp)
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002662 {
2663 if (!section.IsValid())
2664 {
2665 sb_error.SetErrorStringWithFormat ("invalid section");
2666 }
2667 else
2668 {
Greg Clayton741f3f92012-03-27 21:10:07 +00002669 SectionSP section_sp (section.GetSP());
2670 if (section_sp)
2671 {
2672 if (section_sp->IsThreadSpecific())
2673 {
2674 sb_error.SetErrorString ("thread specific sections are not yet supported");
2675 }
2676 else
2677 {
Greg Claytond5944cd2013-12-06 01:12:00 +00002678 ProcessSP process_sp (target_sp->GetProcessSP());
Greg Claytond5944cd2013-12-06 01:12:00 +00002679 if (target_sp->SetSectionLoadAddress (section_sp, section_base_addr))
Greg Clayton3c947372013-01-29 01:17:09 +00002680 {
2681 // Flush info in the process (stack frames, etc)
Greg Clayton3c947372013-01-29 01:17:09 +00002682 if (process_sp)
2683 process_sp->Flush();
2684 }
Greg Clayton741f3f92012-03-27 21:10:07 +00002685 }
2686 }
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002687 }
2688 }
2689 else
2690 {
Greg Clayton741f3f92012-03-27 21:10:07 +00002691 sb_error.SetErrorString ("invalid target");
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002692 }
2693 return sb_error;
2694}
2695
2696SBError
2697SBTarget::ClearSectionLoadAddress (lldb::SBSection section)
2698{
2699 SBError sb_error;
2700
Greg Claytonacdbe812012-01-30 09:04:36 +00002701 TargetSP target_sp(GetSP());
2702 if (target_sp)
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002703 {
2704 if (!section.IsValid())
2705 {
2706 sb_error.SetErrorStringWithFormat ("invalid section");
2707 }
2708 else
2709 {
Greg Claytond5944cd2013-12-06 01:12:00 +00002710 ProcessSP process_sp (target_sp->GetProcessSP());
Greg Claytond5944cd2013-12-06 01:12:00 +00002711 if (target_sp->SetSectionUnloaded (section.GetSP()))
Greg Clayton3c947372013-01-29 01:17:09 +00002712 {
2713 // Flush info in the process (stack frames, etc)
Greg Clayton3c947372013-01-29 01:17:09 +00002714 if (process_sp)
2715 process_sp->Flush();
2716 }
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002717 }
2718 }
2719 else
2720 {
2721 sb_error.SetErrorStringWithFormat ("invalid target");
2722 }
2723 return sb_error;
2724}
2725
2726SBError
2727SBTarget::SetModuleLoadAddress (lldb::SBModule module, int64_t slide_offset)
2728{
2729 SBError sb_error;
2730
Greg Claytonacdbe812012-01-30 09:04:36 +00002731 TargetSP target_sp(GetSP());
2732 if (target_sp)
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002733 {
Greg Claytonacdbe812012-01-30 09:04:36 +00002734 ModuleSP module_sp (module.GetSP());
2735 if (module_sp)
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002736 {
Greg Clayton741f3f92012-03-27 21:10:07 +00002737 bool changed = false;
Greg Clayton751caf62014-02-07 22:54:47 +00002738 if (module_sp->SetLoadAddress (*target_sp, slide_offset, true, changed))
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002739 {
Greg Clayton741f3f92012-03-27 21:10:07 +00002740 // The load was successful, make sure that at least some sections
2741 // changed before we notify that our module was loaded.
2742 if (changed)
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002743 {
Greg Clayton741f3f92012-03-27 21:10:07 +00002744 ModuleList module_list;
2745 module_list.Append(module_sp);
2746 target_sp->ModulesDidLoad (module_list);
Greg Clayton3c947372013-01-29 01:17:09 +00002747 // Flush info in the process (stack frames, etc)
2748 ProcessSP process_sp (target_sp->GetProcessSP());
2749 if (process_sp)
2750 process_sp->Flush();
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002751 }
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002752 }
2753 }
Greg Claytonacdbe812012-01-30 09:04:36 +00002754 else
2755 {
2756 sb_error.SetErrorStringWithFormat ("invalid module");
2757 }
2758
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002759 }
2760 else
2761 {
2762 sb_error.SetErrorStringWithFormat ("invalid target");
2763 }
2764 return sb_error;
2765}
2766
2767SBError
2768SBTarget::ClearModuleLoadAddress (lldb::SBModule module)
2769{
2770 SBError sb_error;
2771
2772 char path[PATH_MAX];
Greg Claytonacdbe812012-01-30 09:04:36 +00002773 TargetSP target_sp(GetSP());
2774 if (target_sp)
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002775 {
Greg Claytonacdbe812012-01-30 09:04:36 +00002776 ModuleSP module_sp (module.GetSP());
2777 if (module_sp)
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002778 {
Greg Claytonacdbe812012-01-30 09:04:36 +00002779 ObjectFile *objfile = module_sp->GetObjectFile();
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002780 if (objfile)
2781 {
2782 SectionList *section_list = objfile->GetSectionList();
2783 if (section_list)
2784 {
Greg Claytond5944cd2013-12-06 01:12:00 +00002785 ProcessSP process_sp (target_sp->GetProcessSP());
Greg Claytond5944cd2013-12-06 01:12:00 +00002786
Greg Clayton3c947372013-01-29 01:17:09 +00002787 bool changed = false;
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002788 const size_t num_sections = section_list->GetSize();
2789 for (size_t sect_idx = 0; sect_idx < num_sections; ++sect_idx)
2790 {
2791 SectionSP section_sp (section_list->GetSectionAtIndex(sect_idx));
2792 if (section_sp)
Zachary Turner40411162014-07-16 20:28:24 +00002793 changed |= target_sp->SetSectionUnloaded (section_sp);
Greg Clayton3c947372013-01-29 01:17:09 +00002794 }
2795 if (changed)
2796 {
2797 // Flush info in the process (stack frames, etc)
2798 ProcessSP process_sp (target_sp->GetProcessSP());
2799 if (process_sp)
2800 process_sp->Flush();
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002801 }
2802 }
2803 else
2804 {
Greg Claytonacdbe812012-01-30 09:04:36 +00002805 module_sp->GetFileSpec().GetPath (path, sizeof(path));
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002806 sb_error.SetErrorStringWithFormat ("no sections in object file '%s'", path);
2807 }
2808 }
2809 else
2810 {
Greg Claytonacdbe812012-01-30 09:04:36 +00002811 module_sp->GetFileSpec().GetPath (path, sizeof(path));
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002812 sb_error.SetErrorStringWithFormat ("no object file for module '%s'", path);
2813 }
2814 }
Greg Claytonacdbe812012-01-30 09:04:36 +00002815 else
2816 {
2817 sb_error.SetErrorStringWithFormat ("invalid module");
2818 }
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002819 }
2820 else
2821 {
2822 sb_error.SetErrorStringWithFormat ("invalid target");
2823 }
2824 return sb_error;
2825}
2826
2827
Greg Claytone14e1922012-12-04 02:22:16 +00002828lldb::SBSymbolContextList
2829SBTarget::FindSymbols (const char *name, lldb::SymbolType symbol_type)
2830{
2831 SBSymbolContextList sb_sc_list;
2832 if (name && name[0])
2833 {
2834 TargetSP target_sp(GetSP());
2835 if (target_sp)
2836 {
2837 bool append = true;
2838 target_sp->GetImages().FindSymbolsWithNameAndType (ConstString(name),
2839 symbol_type,
2840 *sb_sc_list,
2841 append);
2842 }
2843 }
2844 return sb_sc_list;
2845
2846}
2847
2848
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002849lldb::SBValue
2850SBTarget::EvaluateExpression (const char *expr, const SBExpressionOptions &options)
2851{
Greg Clayton5160ce52013-03-27 23:08:40 +00002852 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
2853 Log * expr_log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002854 SBValue expr_result;
Jim Ingham8646d3c2014-05-05 02:47:44 +00002855 ExpressionResults exe_results = eExpressionSetupError;
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002856 ValueObjectSP expr_value_sp;
2857 TargetSP target_sp(GetSP());
Jason Molendab57e4a12013-11-04 09:33:30 +00002858 StackFrame *frame = NULL;
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002859 if (target_sp)
2860 {
2861 if (expr == NULL || expr[0] == '\0')
2862 {
2863 if (log)
2864 log->Printf ("SBTarget::EvaluateExpression called with an empty expression");
2865 return expr_result;
2866 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002867
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002868 Mutex::Locker api_locker (target_sp->GetAPIMutex());
2869 ExecutionContext exe_ctx (m_opaque_sp.get());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002870
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002871 if (log)
2872 log->Printf ("SBTarget()::EvaluateExpression (expr=\"%s\")...", expr);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002873
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002874 frame = exe_ctx.GetFramePtr();
2875 Target *target = exe_ctx.GetTargetPtr();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002876
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002877 if (target)
2878 {
2879#ifdef LLDB_CONFIGURATION_DEBUG
2880 StreamString frame_description;
2881 if (frame)
2882 frame->DumpUsingSettingsFormat (&frame_description);
2883 Host::SetCrashDescriptionWithFormat ("SBTarget::EvaluateExpression (expr = \"%s\", fetch_dynamic_value = %u) %s",
2884 expr, options.GetFetchDynamicValue(), frame_description.GetString().c_str());
2885#endif
2886 exe_results = target->EvaluateExpression (expr,
2887 frame,
2888 expr_value_sp,
2889 options.ref());
2890
2891 expr_result.SetSP(expr_value_sp, options.GetFetchDynamicValue());
2892#ifdef LLDB_CONFIGURATION_DEBUG
2893 Host::SetCrashDescription (NULL);
2894#endif
2895 }
2896 else
2897 {
2898 if (log)
2899 log->Printf ("SBTarget::EvaluateExpression () => error: could not reconstruct frame object for this SBTarget.");
2900 }
2901 }
2902#ifndef LLDB_DISABLE_PYTHON
2903 if (expr_log)
2904 expr_log->Printf("** [SBTarget::EvaluateExpression] Expression result is %s, summary %s **",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002905 expr_result.GetValue(), expr_result.GetSummary());
2906
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002907 if (log)
2908 log->Printf ("SBTarget(%p)::EvaluateExpression (expr=\"%s\") => SBValue(%p) (execution result=%d)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002909 static_cast<void*>(frame), expr,
2910 static_cast<void*>(expr_value_sp.get()), exe_results);
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002911#endif
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002912
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002913 return expr_result;
2914}
2915
Greg Clayton13fbb992013-02-01 00:47:49 +00002916
2917lldb::addr_t
2918SBTarget::GetStackRedZoneSize()
2919{
2920 TargetSP target_sp(GetSP());
2921 if (target_sp)
2922 {
2923 ABISP abi_sp;
2924 ProcessSP process_sp (target_sp->GetProcessSP());
2925 if (process_sp)
2926 abi_sp = process_sp->GetABI();
2927 else
2928 abi_sp = ABI::FindPlugin(target_sp->GetArchitecture());
2929 if (abi_sp)
2930 return abi_sp->GetRedZoneSize();
2931 }
2932 return 0;
2933}
2934