blob: 8faf50434f6ed0e56c6faacfc4c4edf0b8c3d279 [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"
61
Chris Lattner30fdc8d2010-06-08 16:52:24 +000062
63using namespace lldb;
64using namespace lldb_private;
65
66#define DEFAULT_DISASM_BYTE_SIZE 32
67
Greg Clayton38d1f052012-02-24 20:59:25 +000068SBLaunchInfo::SBLaunchInfo (const char **argv) :
69 m_opaque_sp(new ProcessLaunchInfo())
Greg Clayton0e615682012-02-24 05:03:03 +000070{
Greg Clayton38d1f052012-02-24 20:59:25 +000071 m_opaque_sp->GetFlags().Reset (eLaunchFlagDebug | eLaunchFlagDisableASLR);
72 if (argv && argv[0])
73 m_opaque_sp->GetArguments().SetArguments(argv);
Greg Clayton0e615682012-02-24 05:03:03 +000074}
75
Greg Claytonecc7c0d2012-03-07 23:52:51 +000076SBLaunchInfo::~SBLaunchInfo()
77{
78}
79
80lldb_private::ProcessLaunchInfo &
81SBLaunchInfo::ref ()
82{
83 return *m_opaque_sp;
84}
85
86
Greg Clayton0e615682012-02-24 05:03:03 +000087uint32_t
88SBLaunchInfo::GetUserID()
89{
90 return m_opaque_sp->GetUserID();
91}
92
93uint32_t
94SBLaunchInfo::GetGroupID()
95{
96 return m_opaque_sp->GetGroupID();
97}
98
99bool
100SBLaunchInfo::UserIDIsValid ()
101{
102 return m_opaque_sp->UserIDIsValid();
103}
104
105bool
106SBLaunchInfo::GroupIDIsValid ()
107{
108 return m_opaque_sp->GroupIDIsValid();
109}
110
111void
112SBLaunchInfo::SetUserID (uint32_t uid)
113{
114 m_opaque_sp->SetUserID (uid);
115}
116
117void
118SBLaunchInfo::SetGroupID (uint32_t gid)
119{
120 m_opaque_sp->SetGroupID (gid);
121}
122
Greg Clayton0e615682012-02-24 05:03:03 +0000123uint32_t
124SBLaunchInfo::GetNumArguments ()
125{
126 return m_opaque_sp->GetArguments().GetArgumentCount();
127}
128
129const char *
130SBLaunchInfo::GetArgumentAtIndex (uint32_t idx)
131{
132 return m_opaque_sp->GetArguments().GetArgumentAtIndex(idx);
133}
134
135void
136SBLaunchInfo::SetArguments (const char **argv, bool append)
137{
138 if (append)
139 {
140 if (argv)
141 m_opaque_sp->GetArguments().AppendArguments(argv);
142 }
143 else
144 {
145 if (argv)
146 m_opaque_sp->GetArguments().SetArguments(argv);
147 else
148 m_opaque_sp->GetArguments().Clear();
149 }
150}
151
152uint32_t
153SBLaunchInfo::GetNumEnvironmentEntries ()
154{
155 return m_opaque_sp->GetEnvironmentEntries().GetArgumentCount();
156}
157
158const char *
159SBLaunchInfo::GetEnvironmentEntryAtIndex (uint32_t idx)
160{
161 return m_opaque_sp->GetEnvironmentEntries().GetArgumentAtIndex(idx);
162}
163
164void
165SBLaunchInfo::SetEnvironmentEntries (const char **envp, bool append)
166{
167 if (append)
168 {
169 if (envp)
170 m_opaque_sp->GetEnvironmentEntries().AppendArguments(envp);
171 }
172 else
173 {
174 if (envp)
175 m_opaque_sp->GetEnvironmentEntries().SetArguments(envp);
176 else
177 m_opaque_sp->GetEnvironmentEntries().Clear();
178 }
179}
180
181void
182SBLaunchInfo::Clear ()
183{
184 m_opaque_sp->Clear();
185}
186
187const char *
188SBLaunchInfo::GetWorkingDirectory () const
189{
190 return m_opaque_sp->GetWorkingDirectory();
191}
192
193void
194SBLaunchInfo::SetWorkingDirectory (const char *working_dir)
195{
196 m_opaque_sp->SetWorkingDirectory(working_dir);
197}
198
199uint32_t
200SBLaunchInfo::GetLaunchFlags ()
201{
202 return m_opaque_sp->GetFlags().Get();
203}
204
205void
206SBLaunchInfo::SetLaunchFlags (uint32_t flags)
207{
208 m_opaque_sp->GetFlags().Reset(flags);
209}
210
211const char *
212SBLaunchInfo::GetProcessPluginName ()
213{
214 return m_opaque_sp->GetProcessPluginName();
215}
216
217void
218SBLaunchInfo::SetProcessPluginName (const char *plugin_name)
219{
220 return m_opaque_sp->SetProcessPluginName (plugin_name);
221}
222
223const char *
224SBLaunchInfo::GetShell ()
225{
226 return m_opaque_sp->GetShell();
227}
228
229void
230SBLaunchInfo::SetShell (const char * path)
231{
232 m_opaque_sp->SetShell (path);
233}
234
235uint32_t
236SBLaunchInfo::GetResumeCount ()
237{
238 return m_opaque_sp->GetResumeCount();
239}
240
241void
242SBLaunchInfo::SetResumeCount (uint32_t c)
243{
244 m_opaque_sp->SetResumeCount (c);
245}
246
247bool
248SBLaunchInfo::AddCloseFileAction (int fd)
249{
250 return m_opaque_sp->AppendCloseFileAction(fd);
251}
252
253bool
254SBLaunchInfo::AddDuplicateFileAction (int fd, int dup_fd)
255{
256 return m_opaque_sp->AppendDuplicateFileAction(fd, dup_fd);
257}
258
259bool
260SBLaunchInfo::AddOpenFileAction (int fd, const char *path, bool read, bool write)
261{
262 return m_opaque_sp->AppendOpenFileAction(fd, path, read, write);
263}
264
265bool
266SBLaunchInfo::AddSuppressFileAction (int fd, bool read, bool write)
267{
268 return m_opaque_sp->AppendSuppressFileAction(fd, read, write);
269}
270
Jason Molendaa3329782014-03-29 18:54:20 +0000271void
272SBLaunchInfo::SetLaunchEventData (const char *data)
273{
274 m_opaque_sp->SetLaunchEventData (data);
275}
276
277const char *
278SBLaunchInfo::GetLaunchEventData () const
279{
280 return m_opaque_sp->GetLaunchEventData ();
281}
Greg Clayton0e615682012-02-24 05:03:03 +0000282
283SBAttachInfo::SBAttachInfo () :
Greg Claytonecc7c0d2012-03-07 23:52:51 +0000284 m_opaque_sp (new ProcessAttachInfo())
Greg Clayton0e615682012-02-24 05:03:03 +0000285{
286}
287
288SBAttachInfo::SBAttachInfo (lldb::pid_t pid) :
Greg Claytonecc7c0d2012-03-07 23:52:51 +0000289 m_opaque_sp (new ProcessAttachInfo())
Greg Clayton0e615682012-02-24 05:03:03 +0000290{
291 m_opaque_sp->SetProcessID (pid);
292}
293
294SBAttachInfo::SBAttachInfo (const char *path, bool wait_for) :
Greg Claytonecc7c0d2012-03-07 23:52:51 +0000295 m_opaque_sp (new ProcessAttachInfo())
Greg Clayton0e615682012-02-24 05:03:03 +0000296{
297 if (path && path[0])
298 m_opaque_sp->GetExecutableFile().SetFile(path, false);
299 m_opaque_sp->SetWaitForLaunch (wait_for);
300}
301
302SBAttachInfo::SBAttachInfo (const SBAttachInfo &rhs) :
Greg Claytonecc7c0d2012-03-07 23:52:51 +0000303 m_opaque_sp (new ProcessAttachInfo())
Greg Clayton0e615682012-02-24 05:03:03 +0000304{
305 *m_opaque_sp = *rhs.m_opaque_sp;
306}
307
Greg Claytonecc7c0d2012-03-07 23:52:51 +0000308SBAttachInfo::~SBAttachInfo()
309{
310}
311
312lldb_private::ProcessAttachInfo &
313SBAttachInfo::ref ()
314{
315 return *m_opaque_sp;
316}
317
Greg Clayton0e615682012-02-24 05:03:03 +0000318SBAttachInfo &
319SBAttachInfo::operator = (const SBAttachInfo &rhs)
320{
321 if (this != &rhs)
322 *m_opaque_sp = *rhs.m_opaque_sp;
323 return *this;
324}
325
326lldb::pid_t
327SBAttachInfo::GetProcessID ()
328{
329 return m_opaque_sp->GetProcessID();
330}
331
332void
333SBAttachInfo::SetProcessID (lldb::pid_t pid)
334{
335 m_opaque_sp->SetProcessID (pid);
336}
337
338
339uint32_t
340SBAttachInfo::GetResumeCount ()
341{
342 return m_opaque_sp->GetResumeCount();
343}
344
345void
346SBAttachInfo::SetResumeCount (uint32_t c)
347{
348 m_opaque_sp->SetResumeCount (c);
349}
350
351const char *
352SBAttachInfo::GetProcessPluginName ()
353{
354 return m_opaque_sp->GetProcessPluginName();
355}
356
357void
358SBAttachInfo::SetProcessPluginName (const char *plugin_name)
359{
360 return m_opaque_sp->SetProcessPluginName (plugin_name);
361}
362
363void
364SBAttachInfo::SetExecutable (const char *path)
365{
366 if (path && path[0])
367 m_opaque_sp->GetExecutableFile().SetFile(path, false);
368 else
369 m_opaque_sp->GetExecutableFile().Clear();
370}
371
372void
373SBAttachInfo::SetExecutable (SBFileSpec exe_file)
374{
375 if (exe_file.IsValid())
376 m_opaque_sp->GetExecutableFile() = exe_file.ref();
377 else
378 m_opaque_sp->GetExecutableFile().Clear();
379}
380
381bool
382SBAttachInfo::GetWaitForLaunch ()
383{
384 return m_opaque_sp->GetWaitForLaunch();
385}
386
387void
388SBAttachInfo::SetWaitForLaunch (bool b)
389{
390 m_opaque_sp->SetWaitForLaunch (b);
391}
392
Jim Inghamcd16df92012-07-20 21:37:13 +0000393bool
394SBAttachInfo::GetIgnoreExisting ()
395{
396 return m_opaque_sp->GetIgnoreExisting();
397}
398
399void
400SBAttachInfo::SetIgnoreExisting (bool b)
401{
402 m_opaque_sp->SetIgnoreExisting (b);
403}
404
Greg Clayton0e615682012-02-24 05:03:03 +0000405uint32_t
Greg Clayton41bd8ac2012-02-24 23:56:06 +0000406SBAttachInfo::GetUserID()
407{
408 return m_opaque_sp->GetUserID();
409}
410
411uint32_t
412SBAttachInfo::GetGroupID()
413{
414 return m_opaque_sp->GetGroupID();
415}
416
417bool
418SBAttachInfo::UserIDIsValid ()
419{
420 return m_opaque_sp->UserIDIsValid();
421}
422
423bool
424SBAttachInfo::GroupIDIsValid ()
425{
426 return m_opaque_sp->GroupIDIsValid();
427}
428
429void
430SBAttachInfo::SetUserID (uint32_t uid)
431{
432 m_opaque_sp->SetUserID (uid);
433}
434
435void
436SBAttachInfo::SetGroupID (uint32_t gid)
437{
438 m_opaque_sp->SetGroupID (gid);
439}
440
441uint32_t
Greg Clayton0e615682012-02-24 05:03:03 +0000442SBAttachInfo::GetEffectiveUserID()
443{
444 return m_opaque_sp->GetEffectiveUserID();
445}
446
447uint32_t
448SBAttachInfo::GetEffectiveGroupID()
449{
450 return m_opaque_sp->GetEffectiveGroupID();
451}
452
453bool
454SBAttachInfo::EffectiveUserIDIsValid ()
455{
456 return m_opaque_sp->EffectiveUserIDIsValid();
457}
458
459bool
460SBAttachInfo::EffectiveGroupIDIsValid ()
461{
462 return m_opaque_sp->EffectiveGroupIDIsValid ();
463}
464
465void
466SBAttachInfo::SetEffectiveUserID (uint32_t uid)
467{
468 m_opaque_sp->SetEffectiveUserID(uid);
469}
470
471void
472SBAttachInfo::SetEffectiveGroupID (uint32_t gid)
473{
474 m_opaque_sp->SetEffectiveGroupID(gid);
475}
476
477lldb::pid_t
478SBAttachInfo::GetParentProcessID ()
479{
480 return m_opaque_sp->GetParentProcessID();
481}
482
483void
484SBAttachInfo::SetParentProcessID (lldb::pid_t pid)
485{
486 m_opaque_sp->SetParentProcessID (pid);
487}
488
489bool
490SBAttachInfo::ParentProcessIDIsValid()
491{
492 return m_opaque_sp->ParentProcessIDIsValid();
493}
494
495
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000496//----------------------------------------------------------------------
497// SBTarget constructor
498//----------------------------------------------------------------------
Greg Clayton54979cd2010-12-15 05:08:08 +0000499SBTarget::SBTarget () :
500 m_opaque_sp ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000501{
502}
503
504SBTarget::SBTarget (const SBTarget& rhs) :
Greg Clayton66111032010-06-23 01:19:29 +0000505 m_opaque_sp (rhs.m_opaque_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000506{
507}
508
509SBTarget::SBTarget(const TargetSP& target_sp) :
Greg Clayton66111032010-06-23 01:19:29 +0000510 m_opaque_sp (target_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000511{
512}
513
Greg Claytonefabb122010-11-05 23:17:00 +0000514const SBTarget&
515SBTarget::operator = (const SBTarget& rhs)
516{
517 if (this != &rhs)
518 m_opaque_sp = rhs.m_opaque_sp;
519 return *this;
520}
521
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000522//----------------------------------------------------------------------
523// Destructor
524//----------------------------------------------------------------------
525SBTarget::~SBTarget()
526{
527}
528
Jim Ingham4bddaeb2012-02-16 06:50:00 +0000529const char *
530SBTarget::GetBroadcasterClassName ()
531{
532 return Target::GetStaticBroadcasterClass().AsCString();
533}
534
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000535bool
536SBTarget::IsValid () const
537{
Filipe Cabecinhas721ba3f2012-05-19 09:59:08 +0000538 return m_opaque_sp.get() != NULL && m_opaque_sp->IsValid();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000539}
540
541SBProcess
542SBTarget::GetProcess ()
543{
544 SBProcess sb_process;
Greg Claytonb9556ac2012-01-30 07:41:31 +0000545 ProcessSP process_sp;
Greg Claytonacdbe812012-01-30 09:04:36 +0000546 TargetSP target_sp(GetSP());
547 if (target_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000548 {
Greg Claytonacdbe812012-01-30 09:04:36 +0000549 process_sp = target_sp->GetProcessSP();
Greg Claytonb9556ac2012-01-30 07:41:31 +0000550 sb_process.SetSP (process_sp);
Greg Claytonaf67cec2010-12-20 20:49:23 +0000551 }
Caroline Ticeceb6b132010-10-26 03:11:13 +0000552
Greg Clayton5160ce52013-03-27 23:08:40 +0000553 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000554 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000555 log->Printf ("SBTarget(%p)::GetProcess () => SBProcess(%p)",
556 static_cast<void*>(target_sp.get()),
557 static_cast<void*>(process_sp.get()));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000558
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000559 return sb_process;
560}
561
Greg Clayton66111032010-06-23 01:19:29 +0000562SBDebugger
563SBTarget::GetDebugger () const
564{
565 SBDebugger debugger;
Greg Claytonacdbe812012-01-30 09:04:36 +0000566 TargetSP target_sp(GetSP());
567 if (target_sp)
568 debugger.reset (target_sp->GetDebugger().shared_from_this());
Greg Clayton66111032010-06-23 01:19:29 +0000569 return debugger;
570}
571
Jim Ingham270684d2011-03-31 00:01:24 +0000572SBProcess
Greg Clayton4d8ad552013-03-25 22:40:51 +0000573SBTarget::LoadCore (const char *core_file)
574{
575 SBProcess sb_process;
576 TargetSP target_sp(GetSP());
577 if (target_sp)
578 {
579 FileSpec filespec(core_file, true);
580 ProcessSP process_sp (target_sp->CreateProcess(target_sp->GetDebugger().GetListener(),
581 NULL,
582 &filespec));
583 if (process_sp)
584 {
585 process_sp->LoadCore();
586 sb_process.SetSP (process_sp);
587 }
588 }
589 return sb_process;
590}
591
592SBProcess
Jim Ingham270684d2011-03-31 00:01:24 +0000593SBTarget::LaunchSimple
594(
595 char const **argv,
596 char const **envp,
597 const char *working_directory
598)
599{
600 char *stdin_path = NULL;
601 char *stdout_path = NULL;
602 char *stderr_path = NULL;
603 uint32_t launch_flags = 0;
604 bool stop_at_entry = false;
605 SBError error;
606 SBListener listener = GetDebugger().GetListener();
607 return Launch (listener,
608 argv,
609 envp,
610 stdin_path,
611 stdout_path,
612 stderr_path,
613 working_directory,
614 launch_flags,
615 stop_at_entry,
616 error);
617}
Greg Claytonbd82a5d2011-01-23 05:56:20 +0000618
Greg Claytonfbb76342013-11-20 21:07:01 +0000619SBError
620SBTarget::Install()
621{
622 SBError sb_error;
623 TargetSP target_sp(GetSP());
624 if (target_sp)
625 {
626 Mutex::Locker api_locker (target_sp->GetAPIMutex());
627 sb_error.ref() = target_sp->Install(NULL);
628 }
629 return sb_error;
630}
631
Greg Claytonbd82a5d2011-01-23 05:56:20 +0000632SBProcess
633SBTarget::Launch
634(
Greg Clayton4b045622011-02-03 21:28:34 +0000635 SBListener &listener,
Greg Claytonbd82a5d2011-01-23 05:56:20 +0000636 char const **argv,
637 char const **envp,
638 const char *stdin_path,
639 const char *stdout_path,
640 const char *stderr_path,
641 const char *working_directory,
642 uint32_t launch_flags, // See LaunchFlags
643 bool stop_at_entry,
644 lldb::SBError& error
645)
646{
Greg Clayton5160ce52013-03-27 23:08:40 +0000647 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000648
Greg Claytonacdbe812012-01-30 09:04:36 +0000649 SBProcess sb_process;
650 ProcessSP process_sp;
651 TargetSP target_sp(GetSP());
652
Caroline Ticeceb6b132010-10-26 03:11:13 +0000653 if (log)
Greg Claytonbd82a5d2011-01-23 05:56:20 +0000654 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 +0000655 static_cast<void*>(target_sp.get()),
656 static_cast<void*>(argv), static_cast<void*>(envp),
657 stdin_path ? stdin_path : "NULL",
658 stdout_path ? stdout_path : "NULL",
659 stderr_path ? stderr_path : "NULL",
Greg Claytonbd82a5d2011-01-23 05:56:20 +0000660 working_directory ? working_directory : "NULL",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000661 launch_flags, stop_at_entry,
662 static_cast<void*>(error.get()));
Greg Claytonacdbe812012-01-30 09:04:36 +0000663
664 if (target_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000665 {
Greg Claytonacdbe812012-01-30 09:04:36 +0000666 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton5d5028b2010-10-06 03:53:16 +0000667
Greg Clayton645bf542011-01-27 01:01:10 +0000668 if (getenv("LLDB_LAUNCH_FLAG_DISABLE_ASLR"))
669 launch_flags |= eLaunchFlagDisableASLR;
670
Greg Clayton2289fa42011-04-30 01:09:13 +0000671 StateType state = eStateInvalid;
Greg Claytonacdbe812012-01-30 09:04:36 +0000672 process_sp = target_sp->GetProcessSP();
Greg Claytonb9556ac2012-01-30 07:41:31 +0000673 if (process_sp)
Greg Clayton931180e2011-01-27 06:44:37 +0000674 {
Greg Claytonb9556ac2012-01-30 07:41:31 +0000675 state = process_sp->GetState();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000676
Greg Claytonb9556ac2012-01-30 07:41:31 +0000677 if (process_sp->IsAlive() && state != eStateConnected)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000678 {
Greg Clayton2289fa42011-04-30 01:09:13 +0000679 if (state == eStateAttaching)
680 error.SetErrorString ("process attach is in progress");
681 else
682 error.SetErrorString ("a process is already being debugged");
Greg Clayton2289fa42011-04-30 01:09:13 +0000683 return sb_process;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000684 }
Greg Clayton931180e2011-01-27 06:44:37 +0000685 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000686
Greg Clayton2289fa42011-04-30 01:09:13 +0000687 if (state == eStateConnected)
688 {
689 // If we are already connected, then we have already specified the
690 // listener, so if a valid listener is supplied, we need to error out
691 // to let the client know.
692 if (listener.IsValid())
693 {
694 error.SetErrorString ("process is connected and already has a listener, pass empty listener");
Greg Clayton2289fa42011-04-30 01:09:13 +0000695 return sb_process;
696 }
697 }
Greg Claytonb09c5382013-12-13 17:20:18 +0000698
699 if (getenv("LLDB_LAUNCH_FLAG_DISABLE_STDIO"))
700 launch_flags |= eLaunchFlagDisableSTDIO;
701
702 ProcessLaunchInfo launch_info (stdin_path, stdout_path, stderr_path, working_directory, launch_flags);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000703
Greg Claytonb09c5382013-12-13 17:20:18 +0000704 Module *exe_module = target_sp->GetExecutableModulePointer();
705 if (exe_module)
706 launch_info.SetExecutableFile(exe_module->GetPlatformFileSpec(), true);
707 if (argv)
708 launch_info.GetArguments().AppendArguments (argv);
709 if (envp)
710 launch_info.GetEnvironmentEntries ().SetArguments (envp);
711
712 if (listener.IsValid())
713 error.SetError (target_sp->Launch(listener.ref(), launch_info));
Greg Clayton2289fa42011-04-30 01:09:13 +0000714 else
Greg Claytonb09c5382013-12-13 17:20:18 +0000715 error.SetError (target_sp->Launch(target_sp->GetDebugger().GetListener(), launch_info));
Greg Clayton645bf542011-01-27 01:01:10 +0000716
Greg Claytonb09c5382013-12-13 17:20:18 +0000717 sb_process.SetSP(target_sp->GetProcessSP());
Greg Clayton524e60b2010-10-06 22:10:17 +0000718 }
719 else
720 {
721 error.SetErrorString ("SBTarget is invalid");
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000722 }
Caroline Ticeceb6b132010-10-26 03:11:13 +0000723
Caroline Tice20ad3c42010-10-29 21:48:37 +0000724 log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
Caroline Ticeceb6b132010-10-26 03:11:13 +0000725 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000726 log->Printf ("SBTarget(%p)::Launch (...) => SBProcess(%p)",
727 static_cast<void*>(target_sp.get()),
728 static_cast<void*>(sb_process.GetSP().get()));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000729
Greg Clayton5d5028b2010-10-06 03:53:16 +0000730 return sb_process;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000731}
732
Greg Clayton0e615682012-02-24 05:03:03 +0000733SBProcess
734SBTarget::Launch (SBLaunchInfo &sb_launch_info, SBError& error)
735{
Greg Clayton5160ce52013-03-27 23:08:40 +0000736 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000737
Greg Clayton0e615682012-02-24 05:03:03 +0000738 SBProcess sb_process;
Greg Clayton0e615682012-02-24 05:03:03 +0000739 TargetSP target_sp(GetSP());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000740
Greg Clayton0e615682012-02-24 05:03:03 +0000741 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000742 log->Printf ("SBTarget(%p)::Launch (launch_info, error)...",
743 static_cast<void*>(target_sp.get()));
744
Greg Clayton0e615682012-02-24 05:03:03 +0000745 if (target_sp)
746 {
747 Mutex::Locker api_locker (target_sp->GetAPIMutex());
748 StateType state = eStateInvalid;
Greg Claytonb09c5382013-12-13 17:20:18 +0000749 {
750 ProcessSP process_sp = target_sp->GetProcessSP();
Greg Clayton0e615682012-02-24 05:03:03 +0000751 if (process_sp)
752 {
753 state = process_sp->GetState();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000754
Greg Clayton0e615682012-02-24 05:03:03 +0000755 if (process_sp->IsAlive() && state != eStateConnected)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000756 {
Greg Clayton0e615682012-02-24 05:03:03 +0000757 if (state == eStateAttaching)
758 error.SetErrorString ("process attach is in progress");
759 else
760 error.SetErrorString ("a process is already being debugged");
761 return sb_process;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000762 }
Greg Clayton0e615682012-02-24 05:03:03 +0000763 }
Greg Clayton0e615682012-02-24 05:03:03 +0000764 }
Greg Claytonb09c5382013-12-13 17:20:18 +0000765
766 lldb_private::ProcessLaunchInfo &launch_info = sb_launch_info.ref();
767
768 Module *exe_module = target_sp->GetExecutableModulePointer();
769 if (exe_module)
770 launch_info.SetExecutableFile(exe_module->GetPlatformFileSpec(), true);
771
772 const ArchSpec &arch_spec = target_sp->GetArchitecture();
773 if (arch_spec.IsValid())
774 launch_info.GetArchitecture () = arch_spec;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000775
Greg Claytonb09c5382013-12-13 17:20:18 +0000776 error.SetError (target_sp->Launch (target_sp->GetDebugger().GetListener(), launch_info));
777 sb_process.SetSP(target_sp->GetProcessSP());
Greg Clayton0e615682012-02-24 05:03:03 +0000778 }
779 else
780 {
781 error.SetErrorString ("SBTarget is invalid");
782 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000783
Greg Clayton0e615682012-02-24 05:03:03 +0000784 log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
785 if (log)
Greg Claytonb09c5382013-12-13 17:20:18 +0000786 log->Printf ("SBTarget(%p)::Launch (...) => SBProcess(%p)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000787 static_cast<void*>(target_sp.get()),
788 static_cast<void*>(sb_process.GetSP().get()));
789
Greg Clayton0e615682012-02-24 05:03:03 +0000790 return sb_process;
791}
792
793lldb::SBProcess
794SBTarget::Attach (SBAttachInfo &sb_attach_info, SBError& error)
795{
Greg Clayton5160ce52013-03-27 23:08:40 +0000796 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000797
Greg Clayton0e615682012-02-24 05:03:03 +0000798 SBProcess sb_process;
799 ProcessSP process_sp;
800 TargetSP target_sp(GetSP());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000801
Sean Callanan575a4542012-10-20 00:21:31 +0000802 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000803 log->Printf ("SBTarget(%p)::Attach (sb_attach_info, error)...",
804 static_cast<void*>(target_sp.get()));
805
Greg Clayton0e615682012-02-24 05:03:03 +0000806 if (target_sp)
807 {
808 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000809
Greg Clayton0e615682012-02-24 05:03:03 +0000810 StateType state = eStateInvalid;
811 process_sp = target_sp->GetProcessSP();
812 if (process_sp)
813 {
814 state = process_sp->GetState();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000815
Greg Clayton0e615682012-02-24 05:03:03 +0000816 if (process_sp->IsAlive() && state != eStateConnected)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000817 {
Greg Clayton0e615682012-02-24 05:03:03 +0000818 if (state == eStateAttaching)
819 error.SetErrorString ("process attach is in progress");
820 else
821 error.SetErrorString ("a process is already being debugged");
Sean Callanan575a4542012-10-20 00:21:31 +0000822 if (log)
Sean Callanan575a4542012-10-20 00:21:31 +0000823 log->Printf ("SBTarget(%p)::Attach (...) => error %s",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000824 static_cast<void*>(target_sp.get()),
825 error.GetCString());
Greg Clayton0e615682012-02-24 05:03:03 +0000826 return sb_process;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000827 }
Greg Clayton0e615682012-02-24 05:03:03 +0000828 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000829
Greg Clayton0e615682012-02-24 05:03:03 +0000830 if (state != eStateConnected)
831 process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener(), NULL, NULL);
832
833 if (process_sp)
834 {
Greg Clayton0e615682012-02-24 05:03:03 +0000835 ProcessAttachInfo &attach_info = sb_attach_info.ref();
Han Ming Ongfbd8de82013-03-25 20:11:18 +0000836 if (attach_info.ProcessIDIsValid() && !attach_info.UserIDIsValid())
Han Ming Ongcec8c902012-02-29 00:12:56 +0000837 {
838 PlatformSP platform_sp = target_sp->GetPlatform();
Greg Clayton91e407e2012-09-27 00:03:39 +0000839 // See if we can pre-verify if a process exists or not
840 if (platform_sp && platform_sp->IsConnected())
Han Ming Ongcec8c902012-02-29 00:12:56 +0000841 {
Han Ming Ongfbd8de82013-03-25 20:11:18 +0000842 lldb::pid_t attach_pid = attach_info.GetProcessID();
Greg Clayton91e407e2012-09-27 00:03:39 +0000843 ProcessInstanceInfo instance_info;
844 if (platform_sp->GetProcessInfo(attach_pid, instance_info))
845 {
846 attach_info.SetUserID(instance_info.GetEffectiveUserID());
847 }
848 else
849 {
Daniel Malead01b2952012-11-29 21:49:15 +0000850 error.ref().SetErrorStringWithFormat("no process found with process ID %" PRIu64, attach_pid);
Sean Callanan575a4542012-10-20 00:21:31 +0000851 if (log)
852 {
853 log->Printf ("SBTarget(%p)::Attach (...) => error %s",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000854 static_cast<void*>(target_sp.get()), error.GetCString());
Sean Callanan575a4542012-10-20 00:21:31 +0000855 }
Greg Clayton91e407e2012-09-27 00:03:39 +0000856 return sb_process;
857 }
Han Ming Ongcec8c902012-02-29 00:12:56 +0000858 }
859 }
Han Ming Ongbee98392012-02-29 19:16:40 +0000860 error.SetError (process_sp->Attach (attach_info));
861 if (error.Success())
862 {
863 sb_process.SetSP (process_sp);
864 // If we are doing synchronous mode, then wait for the
865 // process to stop!
866 if (target_sp->GetDebugger().GetAsyncExecution () == false)
867 process_sp->WaitForProcessToStop (NULL);
868 }
Greg Clayton0e615682012-02-24 05:03:03 +0000869 }
870 else
871 {
872 error.SetErrorString ("unable to create lldb_private::Process");
873 }
874 }
875 else
876 {
877 error.SetErrorString ("SBTarget is invalid");
878 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000879
Sean Callanan575a4542012-10-20 00:21:31 +0000880 if (log)
Sean Callanan575a4542012-10-20 00:21:31 +0000881 log->Printf ("SBTarget(%p)::Attach (...) => SBProcess(%p)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000882 static_cast<void*>(target_sp.get()),
883 static_cast<void*>(process_sp.get()));
884
Greg Clayton0e615682012-02-24 05:03:03 +0000885 return sb_process;
886}
887
888
Greg Clayton1ba6cfd2011-12-02 02:10:57 +0000889#if defined(__APPLE__)
890
891lldb::SBProcess
892SBTarget::AttachToProcessWithID (SBListener &listener,
893 ::pid_t pid,
894 lldb::SBError& error)
895{
896 return AttachToProcessWithID (listener, (lldb::pid_t)pid, error);
897}
898
899#endif // #if defined(__APPLE__)
Greg Clayton524e60b2010-10-06 22:10:17 +0000900
901lldb::SBProcess
Greg Clayton05faeb72010-10-07 04:19:01 +0000902SBTarget::AttachToProcessWithID
Greg Clayton524e60b2010-10-06 22:10:17 +0000903(
Greg Clayton4b045622011-02-03 21:28:34 +0000904 SBListener &listener,
Greg Clayton524e60b2010-10-06 22:10:17 +0000905 lldb::pid_t pid,// The process ID to attach to
906 SBError& error // An error explaining what went wrong if attach fails
907)
908{
Greg Clayton5160ce52013-03-27 23:08:40 +0000909 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Sean Callanan575a4542012-10-20 00:21:31 +0000910
Greg Clayton524e60b2010-10-06 22:10:17 +0000911 SBProcess sb_process;
Greg Claytonb9556ac2012-01-30 07:41:31 +0000912 ProcessSP process_sp;
Greg Claytonacdbe812012-01-30 09:04:36 +0000913 TargetSP target_sp(GetSP());
Sean Callanan575a4542012-10-20 00:21:31 +0000914
915 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000916 log->Printf ("SBTarget(%p)::AttachToProcessWithID (listener, pid=%" PRId64 ", error)...",
917 static_cast<void*>(target_sp.get()), pid);
918
Greg Claytonacdbe812012-01-30 09:04:36 +0000919 if (target_sp)
Greg Clayton524e60b2010-10-06 22:10:17 +0000920 {
Greg Claytonacdbe812012-01-30 09:04:36 +0000921 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton0c74e782011-06-24 03:21:43 +0000922
923 StateType state = eStateInvalid;
Greg Claytonacdbe812012-01-30 09:04:36 +0000924 process_sp = target_sp->GetProcessSP();
Greg Claytonb9556ac2012-01-30 07:41:31 +0000925 if (process_sp)
Greg Clayton0c74e782011-06-24 03:21:43 +0000926 {
Greg Claytonb9556ac2012-01-30 07:41:31 +0000927 state = process_sp->GetState();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000928
Greg Claytonb9556ac2012-01-30 07:41:31 +0000929 if (process_sp->IsAlive() && state != eStateConnected)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000930 {
Greg Clayton0c74e782011-06-24 03:21:43 +0000931 if (state == eStateAttaching)
932 error.SetErrorString ("process attach is in progress");
933 else
934 error.SetErrorString ("a process is already being debugged");
Greg Clayton0c74e782011-06-24 03:21:43 +0000935 return sb_process;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000936 }
Greg Clayton0c74e782011-06-24 03:21:43 +0000937 }
938
939 if (state == eStateConnected)
940 {
941 // If we are already connected, then we have already specified the
942 // listener, so if a valid listener is supplied, we need to error out
943 // to let the client know.
944 if (listener.IsValid())
945 {
946 error.SetErrorString ("process is connected and already has a listener, pass empty listener");
Greg Clayton0c74e782011-06-24 03:21:43 +0000947 return sb_process;
948 }
949 }
Greg Clayton4b045622011-02-03 21:28:34 +0000950 else
Greg Clayton0c74e782011-06-24 03:21:43 +0000951 {
952 if (listener.IsValid())
Greg Claytonc3776bf2012-02-09 06:16:32 +0000953 process_sp = target_sp->CreateProcess (listener.ref(), NULL, NULL);
Greg Clayton0c74e782011-06-24 03:21:43 +0000954 else
Greg Claytonc3776bf2012-02-09 06:16:32 +0000955 process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener(), NULL, NULL);
Greg Clayton0c74e782011-06-24 03:21:43 +0000956 }
Greg Claytonb9556ac2012-01-30 07:41:31 +0000957 if (process_sp)
Greg Clayton524e60b2010-10-06 22:10:17 +0000958 {
Greg Claytonb9556ac2012-01-30 07:41:31 +0000959 sb_process.SetSP (process_sp);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000960
Greg Clayton144f3a92011-11-15 03:53:30 +0000961 ProcessAttachInfo attach_info;
962 attach_info.SetProcessID (pid);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000963
Han Ming Ong84647042012-02-25 01:07:38 +0000964 PlatformSP platform_sp = target_sp->GetPlatform();
965 ProcessInstanceInfo instance_info;
966 if (platform_sp->GetProcessInfo(pid, instance_info))
967 {
968 attach_info.SetUserID(instance_info.GetEffectiveUserID());
Han Ming Ong84647042012-02-25 01:07:38 +0000969 }
Greg Claytonb9556ac2012-01-30 07:41:31 +0000970 error.SetError (process_sp->Attach (attach_info));
Greg Claytone2186ed2012-09-07 17:51:47 +0000971 if (error.Success())
972 {
973 // If we are doing synchronous mode, then wait for the
974 // process to stop!
975 if (target_sp->GetDebugger().GetAsyncExecution () == false)
Greg Claytonb9556ac2012-01-30 07:41:31 +0000976 process_sp->WaitForProcessToStop (NULL);
Greg Claytone2186ed2012-09-07 17:51:47 +0000977 }
Greg Clayton524e60b2010-10-06 22:10:17 +0000978 }
979 else
980 {
981 error.SetErrorString ("unable to create lldb_private::Process");
982 }
983 }
984 else
985 {
986 error.SetErrorString ("SBTarget is invalid");
987 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000988
Sean Callanan575a4542012-10-20 00:21:31 +0000989 if (log)
Sean Callanan575a4542012-10-20 00:21:31 +0000990 log->Printf ("SBTarget(%p)::AttachToProcessWithID (...) => SBProcess(%p)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000991 static_cast<void*>(target_sp.get()),
992 static_cast<void*>(process_sp.get()));
Greg Clayton524e60b2010-10-06 22:10:17 +0000993 return sb_process;
Greg Clayton524e60b2010-10-06 22:10:17 +0000994}
995
996lldb::SBProcess
Greg Clayton05faeb72010-10-07 04:19:01 +0000997SBTarget::AttachToProcessWithName
Greg Clayton524e60b2010-10-06 22:10:17 +0000998(
Greg Clayton4b045622011-02-03 21:28:34 +0000999 SBListener &listener,
Greg Clayton524e60b2010-10-06 22:10:17 +00001000 const char *name, // basename of process to attach to
1001 bool wait_for, // if true wait for a new instance of "name" to be launched
1002 SBError& error // An error explaining what went wrong if attach fails
1003)
1004{
Greg Clayton5160ce52013-03-27 23:08:40 +00001005 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001006
Greg Clayton524e60b2010-10-06 22:10:17 +00001007 SBProcess sb_process;
Greg Claytonb9556ac2012-01-30 07:41:31 +00001008 ProcessSP process_sp;
Greg Claytonacdbe812012-01-30 09:04:36 +00001009 TargetSP target_sp(GetSP());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001010
Sean Callanan575a4542012-10-20 00:21:31 +00001011 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001012 log->Printf ("SBTarget(%p)::AttachToProcessWithName (listener, name=%s, wait_for=%s, error)...",
1013 static_cast<void*>(target_sp.get()), name,
1014 wait_for ? "true" : "false");
1015
Greg Claytonacdbe812012-01-30 09:04:36 +00001016 if (name && target_sp)
Greg Clayton524e60b2010-10-06 22:10:17 +00001017 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001018 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytonaf67cec2010-12-20 20:49:23 +00001019
Greg Clayton0c74e782011-06-24 03:21:43 +00001020 StateType state = eStateInvalid;
Greg Claytonacdbe812012-01-30 09:04:36 +00001021 process_sp = target_sp->GetProcessSP();
Greg Claytonb9556ac2012-01-30 07:41:31 +00001022 if (process_sp)
Greg Clayton0c74e782011-06-24 03:21:43 +00001023 {
Greg Claytonb9556ac2012-01-30 07:41:31 +00001024 state = process_sp->GetState();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001025
Greg Claytonb9556ac2012-01-30 07:41:31 +00001026 if (process_sp->IsAlive() && state != eStateConnected)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001027 {
Greg Clayton0c74e782011-06-24 03:21:43 +00001028 if (state == eStateAttaching)
1029 error.SetErrorString ("process attach is in progress");
1030 else
1031 error.SetErrorString ("a process is already being debugged");
Greg Clayton0c74e782011-06-24 03:21:43 +00001032 return sb_process;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001033 }
Greg Clayton0c74e782011-06-24 03:21:43 +00001034 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001035
Greg Clayton0c74e782011-06-24 03:21:43 +00001036 if (state == eStateConnected)
1037 {
1038 // If we are already connected, then we have already specified the
1039 // listener, so if a valid listener is supplied, we need to error out
1040 // to let the client know.
1041 if (listener.IsValid())
1042 {
1043 error.SetErrorString ("process is connected and already has a listener, pass empty listener");
Greg Clayton0c74e782011-06-24 03:21:43 +00001044 return sb_process;
1045 }
1046 }
Greg Clayton4b045622011-02-03 21:28:34 +00001047 else
Greg Clayton0c74e782011-06-24 03:21:43 +00001048 {
1049 if (listener.IsValid())
Greg Claytonc3776bf2012-02-09 06:16:32 +00001050 process_sp = target_sp->CreateProcess (listener.ref(), NULL, NULL);
Greg Clayton0c74e782011-06-24 03:21:43 +00001051 else
Greg Claytonc3776bf2012-02-09 06:16:32 +00001052 process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener(), NULL, NULL);
Greg Clayton0c74e782011-06-24 03:21:43 +00001053 }
Greg Clayton524e60b2010-10-06 22:10:17 +00001054
Greg Claytonb9556ac2012-01-30 07:41:31 +00001055 if (process_sp)
Greg Clayton524e60b2010-10-06 22:10:17 +00001056 {
Greg Claytonb9556ac2012-01-30 07:41:31 +00001057 sb_process.SetSP (process_sp);
Greg Clayton144f3a92011-11-15 03:53:30 +00001058 ProcessAttachInfo attach_info;
1059 attach_info.GetExecutableFile().SetFile(name, false);
1060 attach_info.SetWaitForLaunch(wait_for);
Greg Claytonb9556ac2012-01-30 07:41:31 +00001061 error.SetError (process_sp->Attach (attach_info));
Daniel Malead659dc12013-04-01 19:47:00 +00001062 if (error.Success())
1063 {
1064 // If we are doing synchronous mode, then wait for the
1065 // process to stop!
1066 if (target_sp->GetDebugger().GetAsyncExecution () == false)
1067 process_sp->WaitForProcessToStop (NULL);
1068 }
Greg Clayton524e60b2010-10-06 22:10:17 +00001069 }
1070 else
1071 {
1072 error.SetErrorString ("unable to create lldb_private::Process");
1073 }
1074 }
1075 else
1076 {
1077 error.SetErrorString ("SBTarget is invalid");
1078 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001079
Sean Callanan575a4542012-10-20 00:21:31 +00001080 if (log)
Sean Callanan575a4542012-10-20 00:21:31 +00001081 log->Printf ("SBTarget(%p)::AttachToPorcessWithName (...) => SBProcess(%p)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001082 static_cast<void*>(target_sp.get()),
1083 static_cast<void*>(process_sp.get()));
Greg Clayton524e60b2010-10-06 22:10:17 +00001084 return sb_process;
Greg Clayton524e60b2010-10-06 22:10:17 +00001085}
1086
James McIlree9631aae2011-03-04 00:31:13 +00001087lldb::SBProcess
1088SBTarget::ConnectRemote
1089(
1090 SBListener &listener,
1091 const char *url,
1092 const char *plugin_name,
1093 SBError& error
1094)
1095{
Greg Clayton5160ce52013-03-27 23:08:40 +00001096 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Sean Callanan575a4542012-10-20 00:21:31 +00001097
James McIlree9631aae2011-03-04 00:31:13 +00001098 SBProcess sb_process;
Greg Claytonb9556ac2012-01-30 07:41:31 +00001099 ProcessSP process_sp;
Greg Claytonacdbe812012-01-30 09:04:36 +00001100 TargetSP target_sp(GetSP());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001101
Sean Callanan575a4542012-10-20 00:21:31 +00001102 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001103 log->Printf ("SBTarget(%p)::ConnectRemote (listener, url=%s, plugin_name=%s, error)...",
1104 static_cast<void*>(target_sp.get()), url, plugin_name);
1105
Greg Claytonacdbe812012-01-30 09:04:36 +00001106 if (target_sp)
James McIlree9631aae2011-03-04 00:31:13 +00001107 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001108 Mutex::Locker api_locker (target_sp->GetAPIMutex());
James McIlree9631aae2011-03-04 00:31:13 +00001109 if (listener.IsValid())
Greg Claytonc3776bf2012-02-09 06:16:32 +00001110 process_sp = target_sp->CreateProcess (listener.ref(), plugin_name, NULL);
James McIlree9631aae2011-03-04 00:31:13 +00001111 else
Greg Claytonc3776bf2012-02-09 06:16:32 +00001112 process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener(), plugin_name, NULL);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001113
Greg Claytonb9556ac2012-01-30 07:41:31 +00001114 if (process_sp)
James McIlree9631aae2011-03-04 00:31:13 +00001115 {
Greg Claytonb9556ac2012-01-30 07:41:31 +00001116 sb_process.SetSP (process_sp);
Jason Molenda4bd4e7e2012-09-29 04:02:01 +00001117 error.SetError (process_sp->ConnectRemote (NULL, url));
James McIlree9631aae2011-03-04 00:31:13 +00001118 }
1119 else
1120 {
1121 error.SetErrorString ("unable to create lldb_private::Process");
1122 }
1123 }
1124 else
1125 {
1126 error.SetErrorString ("SBTarget is invalid");
1127 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001128
Sean Callanan575a4542012-10-20 00:21:31 +00001129 if (log)
Sean Callanan575a4542012-10-20 00:21:31 +00001130 log->Printf ("SBTarget(%p)::ConnectRemote (...) => SBProcess(%p)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001131 static_cast<void*>(target_sp.get()),
1132 static_cast<void*>(process_sp.get()));
James McIlree9631aae2011-03-04 00:31:13 +00001133 return sb_process;
1134}
1135
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001136SBFileSpec
1137SBTarget::GetExecutable ()
1138{
Caroline Ticeceb6b132010-10-26 03:11:13 +00001139
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001140 SBFileSpec exe_file_spec;
Greg Claytonacdbe812012-01-30 09:04:36 +00001141 TargetSP target_sp(GetSP());
1142 if (target_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001143 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001144 Module *exe_module = target_sp->GetExecutableModulePointer();
Greg Claytonaa149cb2011-08-11 02:48:45 +00001145 if (exe_module)
1146 exe_file_spec.SetFileSpec (exe_module->GetFileSpec());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001147 }
Caroline Ticeceb6b132010-10-26 03:11:13 +00001148
Greg Clayton5160ce52013-03-27 23:08:40 +00001149 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001150 if (log)
1151 {
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001152 log->Printf ("SBTarget(%p)::GetExecutable () => SBFileSpec(%p)",
1153 static_cast<void*>(target_sp.get()),
1154 static_cast<const void*>(exe_file_spec.get()));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001155 }
1156
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001157 return exe_file_spec;
1158}
1159
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001160bool
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001161SBTarget::operator == (const SBTarget &rhs) const
1162{
Greg Clayton66111032010-06-23 01:19:29 +00001163 return m_opaque_sp.get() == rhs.m_opaque_sp.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001164}
1165
1166bool
1167SBTarget::operator != (const SBTarget &rhs) const
1168{
Greg Clayton66111032010-06-23 01:19:29 +00001169 return m_opaque_sp.get() != rhs.m_opaque_sp.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001170}
1171
Greg Claytonb9556ac2012-01-30 07:41:31 +00001172lldb::TargetSP
1173SBTarget::GetSP () const
Greg Clayton9a377662011-10-01 02:59:24 +00001174{
1175 return m_opaque_sp;
1176}
1177
Greg Clayton66111032010-06-23 01:19:29 +00001178void
Greg Claytonb9556ac2012-01-30 07:41:31 +00001179SBTarget::SetSP (const lldb::TargetSP& target_sp)
Greg Clayton66111032010-06-23 01:19:29 +00001180{
1181 m_opaque_sp = target_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001182}
1183
Greg Clayton00e6fbf2011-07-22 16:46:35 +00001184lldb::SBAddress
1185SBTarget::ResolveLoadAddress (lldb::addr_t vm_addr)
Greg Claytonac2eb9b2010-12-12 19:25:26 +00001186{
Greg Clayton00e6fbf2011-07-22 16:46:35 +00001187 lldb::SBAddress sb_addr;
1188 Address &addr = sb_addr.ref();
Greg Claytonacdbe812012-01-30 09:04:36 +00001189 TargetSP target_sp(GetSP());
1190 if (target_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +00001191 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001192 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytond5944cd2013-12-06 01:12:00 +00001193 if (target_sp->ResolveLoadAddress (vm_addr, addr))
Greg Clayton00e6fbf2011-07-22 16:46:35 +00001194 return sb_addr;
Greg Claytonaf67cec2010-12-20 20:49:23 +00001195 }
Greg Claytonac2eb9b2010-12-12 19:25:26 +00001196
Greg Clayton00e6fbf2011-07-22 16:46:35 +00001197 // We have a load address that isn't in a section, just return an address
1198 // with the offset filled in (the address) and the section set to NULL
Greg Claytone72dfb32012-02-24 01:59:29 +00001199 addr.SetRawAddress(vm_addr);
Greg Clayton00e6fbf2011-07-22 16:46:35 +00001200 return sb_addr;
Greg Claytonac2eb9b2010-12-12 19:25:26 +00001201}
1202
Greg Claytond5944cd2013-12-06 01:12:00 +00001203
1204lldb::SBAddress
1205SBTarget::ResolvePastLoadAddress (uint32_t stop_id, lldb::addr_t vm_addr)
1206{
1207 lldb::SBAddress sb_addr;
1208 Address &addr = sb_addr.ref();
1209 TargetSP target_sp(GetSP());
1210 if (target_sp)
1211 {
1212 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1213 if (target_sp->ResolveLoadAddress (vm_addr, addr))
1214 return sb_addr;
1215 }
1216
1217 // We have a load address that isn't in a section, just return an address
1218 // with the offset filled in (the address) and the section set to NULL
1219 addr.SetRawAddress(vm_addr);
1220 return sb_addr;
1221}
1222
Greg Clayton5f2a4f92011-03-02 21:34:46 +00001223SBSymbolContext
Greg Claytoneb023e72013-10-11 19:48:25 +00001224SBTarget::ResolveSymbolContextForAddress (const SBAddress& addr,
1225 uint32_t resolve_scope)
Greg Clayton5f2a4f92011-03-02 21:34:46 +00001226{
1227 SBSymbolContext sc;
Greg Claytonacdbe812012-01-30 09:04:36 +00001228 if (addr.IsValid())
1229 {
1230 TargetSP target_sp(GetSP());
1231 if (target_sp)
1232 target_sp->GetImages().ResolveSymbolContextForAddress (addr.ref(), resolve_scope, sc.ref());
1233 }
Greg Clayton5f2a4f92011-03-02 21:34:46 +00001234 return sc;
1235}
1236
1237
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001238SBBreakpoint
Greg Claytoneb023e72013-10-11 19:48:25 +00001239SBTarget::BreakpointCreateByLocation (const char *file,
1240 uint32_t line)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001241{
Greg Clayton7481c202010-11-08 00:28:40 +00001242 return SBBreakpoint(BreakpointCreateByLocation (SBFileSpec (file, false), line));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001243}
1244
1245SBBreakpoint
Greg Claytoneb023e72013-10-11 19:48:25 +00001246SBTarget::BreakpointCreateByLocation (const SBFileSpec &sb_file_spec,
1247 uint32_t line)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001248{
Greg Clayton5160ce52013-03-27 23:08:40 +00001249 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001250
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001251 SBBreakpoint sb_bp;
Greg Claytonacdbe812012-01-30 09:04:36 +00001252 TargetSP target_sp(GetSP());
1253 if (target_sp && line != 0)
Greg Claytonaf67cec2010-12-20 20:49:23 +00001254 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001255 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001256
Greg Clayton1f746072012-08-29 21:13:06 +00001257 const LazyBool check_inlines = eLazyBoolCalculate;
Jim Inghama8558b62012-05-22 00:12:20 +00001258 const LazyBool skip_prologue = eLazyBoolCalculate;
Greg Clayton1f746072012-08-29 21:13:06 +00001259 const bool internal = false;
Greg Claytoneb023e72013-10-11 19:48:25 +00001260 const bool hardware = false;
1261 *sb_bp = target_sp->CreateBreakpoint (NULL, *sb_file_spec, line, check_inlines, skip_prologue, internal, hardware);
Greg Claytonaf67cec2010-12-20 20:49:23 +00001262 }
Caroline Ticeceb6b132010-10-26 03:11:13 +00001263
1264 if (log)
1265 {
1266 SBStream sstr;
1267 sb_bp.GetDescription (sstr);
Greg Claytoncfd1ace2010-10-31 03:01:06 +00001268 char path[PATH_MAX];
1269 sb_file_spec->GetPath (path, sizeof(path));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001270 log->Printf ("SBTarget(%p)::BreakpointCreateByLocation ( %s:%u ) => SBBreakpoint(%p): %s",
1271 static_cast<void*>(target_sp.get()), path, line,
1272 static_cast<void*>(sb_bp.get()), sstr.GetData());
Caroline Ticeceb6b132010-10-26 03:11:13 +00001273 }
1274
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001275 return sb_bp;
1276}
1277
1278SBBreakpoint
Greg Claytoneb023e72013-10-11 19:48:25 +00001279SBTarget::BreakpointCreateByName (const char *symbol_name,
1280 const char *module_name)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001281{
Greg Clayton5160ce52013-03-27 23:08:40 +00001282 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001283
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001284 SBBreakpoint sb_bp;
Greg Claytonacdbe812012-01-30 09:04:36 +00001285 TargetSP target_sp(GetSP());
1286 if (target_sp.get())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001287 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001288 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001289
Jim Inghama8558b62012-05-22 00:12:20 +00001290 const bool internal = false;
Greg Claytoneb023e72013-10-11 19:48:25 +00001291 const bool hardware = false;
Jim Inghama8558b62012-05-22 00:12:20 +00001292 const LazyBool skip_prologue = eLazyBoolCalculate;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001293 if (module_name && module_name[0])
1294 {
Jim Ingham969795f2011-09-21 01:17:13 +00001295 FileSpecList module_spec_list;
1296 module_spec_list.Append (FileSpec (module_name, false));
Greg Claytoneb023e72013-10-11 19:48:25 +00001297 *sb_bp = target_sp->CreateBreakpoint (&module_spec_list, NULL, symbol_name, eFunctionNameTypeAuto, skip_prologue, internal, hardware);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001298 }
1299 else
1300 {
Greg Claytoneb023e72013-10-11 19:48:25 +00001301 *sb_bp = target_sp->CreateBreakpoint (NULL, NULL, symbol_name, eFunctionNameTypeAuto, skip_prologue, internal, hardware);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001302 }
1303 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001304
Caroline Ticeceb6b132010-10-26 03:11:13 +00001305 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001306 log->Printf ("SBTarget(%p)::BreakpointCreateByName (symbol=\"%s\", module=\"%s\") => SBBreakpoint(%p)",
1307 static_cast<void*>(target_sp.get()), symbol_name,
1308 module_name, static_cast<void*>(sb_bp.get()));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001309
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001310 return sb_bp;
1311}
1312
Jim Ingham87df91b2011-09-23 00:54:11 +00001313lldb::SBBreakpoint
1314SBTarget::BreakpointCreateByName (const char *symbol_name,
Greg Claytoneb023e72013-10-11 19:48:25 +00001315 const SBFileSpecList &module_list,
1316 const SBFileSpecList &comp_unit_list)
Jim Ingham87df91b2011-09-23 00:54:11 +00001317{
Jim Ingham2dd7f7f2011-10-11 01:18:55 +00001318 uint32_t name_type_mask = eFunctionNameTypeAuto;
1319 return BreakpointCreateByName (symbol_name, name_type_mask, module_list, comp_unit_list);
1320}
1321
1322lldb::SBBreakpoint
1323SBTarget::BreakpointCreateByName (const char *symbol_name,
Greg Claytoneb023e72013-10-11 19:48:25 +00001324 uint32_t name_type_mask,
1325 const SBFileSpecList &module_list,
1326 const SBFileSpecList &comp_unit_list)
Jim Ingham2dd7f7f2011-10-11 01:18:55 +00001327{
Greg Clayton5160ce52013-03-27 23:08:40 +00001328 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Jim Ingham87df91b2011-09-23 00:54:11 +00001329
1330 SBBreakpoint sb_bp;
Greg Claytonacdbe812012-01-30 09:04:36 +00001331 TargetSP target_sp(GetSP());
1332 if (target_sp && symbol_name && symbol_name[0])
Jim Ingham87df91b2011-09-23 00:54:11 +00001333 {
Jim Inghama8558b62012-05-22 00:12:20 +00001334 const bool internal = false;
Greg Claytoneb023e72013-10-11 19:48:25 +00001335 const bool hardware = false;
Jim Inghama8558b62012-05-22 00:12:20 +00001336 const LazyBool skip_prologue = eLazyBoolCalculate;
Greg Claytonacdbe812012-01-30 09:04:36 +00001337 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1338 *sb_bp = target_sp->CreateBreakpoint (module_list.get(),
Greg Claytoneb023e72013-10-11 19:48:25 +00001339 comp_unit_list.get(),
1340 symbol_name,
1341 name_type_mask,
1342 skip_prologue,
1343 internal,
1344 hardware);
Jim Ingham87df91b2011-09-23 00:54:11 +00001345 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001346
Jim Ingham87df91b2011-09-23 00:54:11 +00001347 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001348 log->Printf ("SBTarget(%p)::BreakpointCreateByName (symbol=\"%s\", name_type: %d) => SBBreakpoint(%p)",
1349 static_cast<void*>(target_sp.get()), symbol_name,
1350 name_type_mask, static_cast<void*>(sb_bp.get()));
Jim Ingham87df91b2011-09-23 00:54:11 +00001351
1352 return sb_bp;
1353}
1354
Jim Inghamfab10e82012-03-06 00:37:27 +00001355lldb::SBBreakpoint
1356SBTarget::BreakpointCreateByNames (const char *symbol_names[],
1357 uint32_t num_names,
1358 uint32_t name_type_mask,
1359 const SBFileSpecList &module_list,
1360 const SBFileSpecList &comp_unit_list)
1361{
Greg Clayton5160ce52013-03-27 23:08:40 +00001362 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Jim Inghamfab10e82012-03-06 00:37:27 +00001363
1364 SBBreakpoint sb_bp;
1365 TargetSP target_sp(GetSP());
1366 if (target_sp && num_names > 0)
1367 {
1368 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Jim Inghama8558b62012-05-22 00:12:20 +00001369 const bool internal = false;
Greg Claytoneb023e72013-10-11 19:48:25 +00001370 const bool hardware = false;
Jim Inghama8558b62012-05-22 00:12:20 +00001371 const LazyBool skip_prologue = eLazyBoolCalculate;
Jim Inghamfab10e82012-03-06 00:37:27 +00001372 *sb_bp = target_sp->CreateBreakpoint (module_list.get(),
1373 comp_unit_list.get(),
1374 symbol_names,
1375 num_names,
1376 name_type_mask,
Jim Inghama8558b62012-05-22 00:12:20 +00001377 skip_prologue,
Greg Claytoneb023e72013-10-11 19:48:25 +00001378 internal,
1379 hardware);
Jim Inghamfab10e82012-03-06 00:37:27 +00001380 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001381
Jim Inghamfab10e82012-03-06 00:37:27 +00001382 if (log)
1383 {
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001384 log->Printf ("SBTarget(%p)::BreakpointCreateByName (symbols={",
1385 static_cast<void*>(target_sp.get()));
Jim Inghamfab10e82012-03-06 00:37:27 +00001386 for (uint32_t i = 0 ; i < num_names; i++)
1387 {
1388 char sep;
1389 if (i < num_names - 1)
1390 sep = ',';
1391 else
1392 sep = '}';
1393 if (symbol_names[i] != NULL)
1394 log->Printf ("\"%s\"%c ", symbol_names[i], sep);
1395 else
1396 log->Printf ("\"<NULL>\"%c ", sep);
Jim Inghamfab10e82012-03-06 00:37:27 +00001397 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001398 log->Printf ("name_type: %d) => SBBreakpoint(%p)", name_type_mask,
1399 static_cast<void*>(sb_bp.get()));
Jim Inghamfab10e82012-03-06 00:37:27 +00001400 }
1401
1402 return sb_bp;
1403}
Jim Ingham87df91b2011-09-23 00:54:11 +00001404
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001405SBBreakpoint
Greg Claytoneb023e72013-10-11 19:48:25 +00001406SBTarget::BreakpointCreateByRegex (const char *symbol_name_regex,
1407 const char *module_name)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001408{
Greg Clayton5160ce52013-03-27 23:08:40 +00001409 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001410
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001411 SBBreakpoint sb_bp;
Greg Claytonacdbe812012-01-30 09:04:36 +00001412 TargetSP target_sp(GetSP());
1413 if (target_sp && symbol_name_regex && symbol_name_regex[0])
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001414 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001415 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001416 RegularExpression regexp(symbol_name_regex);
Jim Inghama8558b62012-05-22 00:12:20 +00001417 const bool internal = false;
Greg Claytoneb023e72013-10-11 19:48:25 +00001418 const bool hardware = false;
Jim Inghama8558b62012-05-22 00:12:20 +00001419 const LazyBool skip_prologue = eLazyBoolCalculate;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001420
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001421 if (module_name && module_name[0])
1422 {
Jim Ingham969795f2011-09-21 01:17:13 +00001423 FileSpecList module_spec_list;
1424 module_spec_list.Append (FileSpec (module_name, false));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001425
Greg Claytoneb023e72013-10-11 19:48:25 +00001426 *sb_bp = target_sp->CreateFuncRegexBreakpoint (&module_spec_list, NULL, regexp, skip_prologue, internal, hardware);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001427 }
1428 else
1429 {
Greg Claytoneb023e72013-10-11 19:48:25 +00001430 *sb_bp = target_sp->CreateFuncRegexBreakpoint (NULL, NULL, regexp, skip_prologue, internal, hardware);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001431 }
1432 }
Caroline Ticeceb6b132010-10-26 03:11:13 +00001433
1434 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001435 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (symbol_regex=\"%s\", module_name=\"%s\") => SBBreakpoint(%p)",
1436 static_cast<void*>(target_sp.get()), symbol_name_regex,
1437 module_name, static_cast<void*>(sb_bp.get()));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001438
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001439 return sb_bp;
1440}
1441
Jim Ingham87df91b2011-09-23 00:54:11 +00001442lldb::SBBreakpoint
1443SBTarget::BreakpointCreateByRegex (const char *symbol_name_regex,
Greg Claytoneb023e72013-10-11 19:48:25 +00001444 const SBFileSpecList &module_list,
1445 const SBFileSpecList &comp_unit_list)
Jim Ingham87df91b2011-09-23 00:54:11 +00001446{
Greg Clayton5160ce52013-03-27 23:08:40 +00001447 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001448
Jim Ingham87df91b2011-09-23 00:54:11 +00001449 SBBreakpoint sb_bp;
Greg Claytonacdbe812012-01-30 09:04:36 +00001450 TargetSP target_sp(GetSP());
1451 if (target_sp && symbol_name_regex && symbol_name_regex[0])
Jim Ingham87df91b2011-09-23 00:54:11 +00001452 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001453 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Jim Ingham87df91b2011-09-23 00:54:11 +00001454 RegularExpression regexp(symbol_name_regex);
Jim Inghama8558b62012-05-22 00:12:20 +00001455 const bool internal = false;
Greg Claytoneb023e72013-10-11 19:48:25 +00001456 const bool hardware = false;
Jim Inghama8558b62012-05-22 00:12:20 +00001457 const LazyBool skip_prologue = eLazyBoolCalculate;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001458
Greg Claytoneb023e72013-10-11 19:48:25 +00001459 *sb_bp = target_sp->CreateFuncRegexBreakpoint (module_list.get(), comp_unit_list.get(), regexp, skip_prologue, internal, hardware);
Jim Ingham87df91b2011-09-23 00:54:11 +00001460 }
1461
1462 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001463 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (symbol_regex=\"%s\") => SBBreakpoint(%p)",
1464 static_cast<void*>(target_sp.get()), symbol_name_regex,
1465 static_cast<void*>(sb_bp.get()));
Jim Ingham87df91b2011-09-23 00:54:11 +00001466
1467 return sb_bp;
1468}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001469
1470SBBreakpoint
1471SBTarget::BreakpointCreateByAddress (addr_t address)
1472{
Greg Clayton5160ce52013-03-27 23:08:40 +00001473 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001474
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001475 SBBreakpoint sb_bp;
Greg Claytonacdbe812012-01-30 09:04:36 +00001476 TargetSP target_sp(GetSP());
1477 if (target_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +00001478 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001479 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytoneb023e72013-10-11 19:48:25 +00001480 const bool hardware = false;
1481 *sb_bp = target_sp->CreateBreakpoint (address, false, hardware);
Greg Claytonaf67cec2010-12-20 20:49:23 +00001482 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001483
Caroline Ticeceb6b132010-10-26 03:11:13 +00001484 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001485 log->Printf ("SBTarget(%p)::BreakpointCreateByAddress (address=%" PRIu64 ") => SBBreakpoint(%p)",
1486 static_cast<void*>(target_sp.get()),
1487 static_cast<uint64_t>(address),
1488 static_cast<void*>(sb_bp.get()));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001489
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001490 return sb_bp;
1491}
1492
Jim Ingham969795f2011-09-21 01:17:13 +00001493lldb::SBBreakpoint
Greg Claytoneb023e72013-10-11 19:48:25 +00001494SBTarget::BreakpointCreateBySourceRegex (const char *source_regex,
1495 const lldb::SBFileSpec &source_file,
1496 const char *module_name)
Jim Ingham969795f2011-09-21 01:17:13 +00001497{
Greg Clayton5160ce52013-03-27 23:08:40 +00001498 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Jim Ingham969795f2011-09-21 01:17:13 +00001499
1500 SBBreakpoint sb_bp;
Greg Claytonacdbe812012-01-30 09:04:36 +00001501 TargetSP target_sp(GetSP());
1502 if (target_sp && source_regex && source_regex[0])
Jim Ingham969795f2011-09-21 01:17:13 +00001503 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001504 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Jim Ingham969795f2011-09-21 01:17:13 +00001505 RegularExpression regexp(source_regex);
Jim Ingham87df91b2011-09-23 00:54:11 +00001506 FileSpecList source_file_spec_list;
Greg Claytoneb023e72013-10-11 19:48:25 +00001507 const bool hardware = false;
Jim Ingham87df91b2011-09-23 00:54:11 +00001508 source_file_spec_list.Append (source_file.ref());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001509
Jim Ingham969795f2011-09-21 01:17:13 +00001510 if (module_name && module_name[0])
1511 {
1512 FileSpecList module_spec_list;
1513 module_spec_list.Append (FileSpec (module_name, false));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001514
Greg Claytoneb023e72013-10-11 19:48:25 +00001515 *sb_bp = target_sp->CreateSourceRegexBreakpoint (&module_spec_list, &source_file_spec_list, regexp, false, hardware);
Jim Ingham969795f2011-09-21 01:17:13 +00001516 }
1517 else
1518 {
Greg Claytoneb023e72013-10-11 19:48:25 +00001519 *sb_bp = target_sp->CreateSourceRegexBreakpoint (NULL, &source_file_spec_list, regexp, false, hardware);
Jim Ingham969795f2011-09-21 01:17:13 +00001520 }
1521 }
1522
1523 if (log)
1524 {
1525 char path[PATH_MAX];
1526 source_file->GetPath (path, sizeof(path));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001527 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (source_regex=\"%s\", file=\"%s\", module_name=\"%s\") => SBBreakpoint(%p)",
1528 static_cast<void*>(target_sp.get()), source_regex, path,
1529 module_name, static_cast<void*>(sb_bp.get()));
Jim Ingham969795f2011-09-21 01:17:13 +00001530 }
1531
1532 return sb_bp;
1533}
1534
Jim Ingham87df91b2011-09-23 00:54:11 +00001535lldb::SBBreakpoint
1536SBTarget::BreakpointCreateBySourceRegex (const char *source_regex,
Greg Claytoneb023e72013-10-11 19:48:25 +00001537 const SBFileSpecList &module_list,
1538 const lldb::SBFileSpecList &source_file_list)
Jim Ingham87df91b2011-09-23 00:54:11 +00001539{
Greg Clayton5160ce52013-03-27 23:08:40 +00001540 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Jim Ingham87df91b2011-09-23 00:54:11 +00001541
1542 SBBreakpoint sb_bp;
Greg Claytonacdbe812012-01-30 09:04:36 +00001543 TargetSP target_sp(GetSP());
1544 if (target_sp && source_regex && source_regex[0])
Jim Ingham87df91b2011-09-23 00:54:11 +00001545 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001546 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytoneb023e72013-10-11 19:48:25 +00001547 const bool hardware = false;
Jim Ingham87df91b2011-09-23 00:54:11 +00001548 RegularExpression regexp(source_regex);
Greg Claytoneb023e72013-10-11 19:48:25 +00001549 *sb_bp = target_sp->CreateSourceRegexBreakpoint (module_list.get(), source_file_list.get(), regexp, false, hardware);
Jim Ingham87df91b2011-09-23 00:54:11 +00001550 }
1551
1552 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001553 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (source_regex=\"%s\") => SBBreakpoint(%p)",
1554 static_cast<void*>(target_sp.get()), source_regex,
1555 static_cast<void*>(sb_bp.get()));
Jim Ingham87df91b2011-09-23 00:54:11 +00001556
1557 return sb_bp;
1558}
Jim Ingham969795f2011-09-21 01:17:13 +00001559
Jim Inghamfab10e82012-03-06 00:37:27 +00001560lldb::SBBreakpoint
1561SBTarget::BreakpointCreateForException (lldb::LanguageType language,
Greg Claytoneb023e72013-10-11 19:48:25 +00001562 bool catch_bp,
1563 bool throw_bp)
Jim Inghamfab10e82012-03-06 00:37:27 +00001564{
Greg Clayton5160ce52013-03-27 23:08:40 +00001565 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Jim Inghamfab10e82012-03-06 00:37:27 +00001566
1567 SBBreakpoint sb_bp;
1568 TargetSP target_sp(GetSP());
1569 if (target_sp)
1570 {
1571 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytoneb023e72013-10-11 19:48:25 +00001572 const bool hardware = false;
1573 *sb_bp = target_sp->CreateExceptionBreakpoint (language, catch_bp, throw_bp, hardware);
Jim Inghamfab10e82012-03-06 00:37:27 +00001574 }
1575
1576 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001577 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (Language: %s, catch: %s throw: %s) => SBBreakpoint(%p)",
1578 static_cast<void*>(target_sp.get()),
Jim Inghamfab10e82012-03-06 00:37:27 +00001579 LanguageRuntime::GetNameForLanguageType(language),
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001580 catch_bp ? "on" : "off", throw_bp ? "on" : "off",
1581 static_cast<void*>(sb_bp.get()));
Jim Inghamfab10e82012-03-06 00:37:27 +00001582
1583 return sb_bp;
1584}
1585
Greg Clayton9fed0d82010-07-23 23:33:17 +00001586uint32_t
1587SBTarget::GetNumBreakpoints () const
1588{
Greg Claytonacdbe812012-01-30 09:04:36 +00001589 TargetSP target_sp(GetSP());
1590 if (target_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +00001591 {
1592 // The breakpoint list is thread safe, no need to lock
Greg Claytonacdbe812012-01-30 09:04:36 +00001593 return target_sp->GetBreakpointList().GetSize();
Greg Claytonaf67cec2010-12-20 20:49:23 +00001594 }
Greg Clayton9fed0d82010-07-23 23:33:17 +00001595 return 0;
1596}
1597
1598SBBreakpoint
1599SBTarget::GetBreakpointAtIndex (uint32_t idx) const
1600{
1601 SBBreakpoint sb_breakpoint;
Greg Claytonacdbe812012-01-30 09:04:36 +00001602 TargetSP target_sp(GetSP());
1603 if (target_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +00001604 {
1605 // The breakpoint list is thread safe, no need to lock
Greg Claytonacdbe812012-01-30 09:04:36 +00001606 *sb_breakpoint = target_sp->GetBreakpointList().GetBreakpointAtIndex(idx);
Greg Claytonaf67cec2010-12-20 20:49:23 +00001607 }
Greg Clayton9fed0d82010-07-23 23:33:17 +00001608 return sb_breakpoint;
1609}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001610
1611bool
1612SBTarget::BreakpointDelete (break_id_t bp_id)
1613{
Greg Clayton5160ce52013-03-27 23:08:40 +00001614 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001615
Caroline Ticeceb6b132010-10-26 03:11:13 +00001616 bool result = false;
Greg Claytonacdbe812012-01-30 09:04:36 +00001617 TargetSP target_sp(GetSP());
1618 if (target_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +00001619 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001620 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1621 result = target_sp->RemoveBreakpointByID (bp_id);
Greg Claytonaf67cec2010-12-20 20:49:23 +00001622 }
Caroline Ticeceb6b132010-10-26 03:11:13 +00001623
1624 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001625 log->Printf ("SBTarget(%p)::BreakpointDelete (bp_id=%d) => %i",
1626 static_cast<void*>(target_sp.get()),
1627 static_cast<uint32_t>(bp_id), result);
Caroline Ticeceb6b132010-10-26 03:11:13 +00001628
1629 return result;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001630}
1631
Johnny Chen5d043462011-09-26 22:40:50 +00001632SBBreakpoint
1633SBTarget::FindBreakpointByID (break_id_t bp_id)
1634{
Greg Clayton5160ce52013-03-27 23:08:40 +00001635 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Johnny Chen5d043462011-09-26 22:40:50 +00001636
1637 SBBreakpoint sb_breakpoint;
Greg Claytonacdbe812012-01-30 09:04:36 +00001638 TargetSP target_sp(GetSP());
1639 if (target_sp && bp_id != LLDB_INVALID_BREAK_ID)
Johnny Chen5d043462011-09-26 22:40:50 +00001640 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001641 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1642 *sb_breakpoint = target_sp->GetBreakpointByID (bp_id);
Johnny Chen5d043462011-09-26 22:40:50 +00001643 }
1644
1645 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001646 log->Printf ("SBTarget(%p)::FindBreakpointByID (bp_id=%d) => SBBreakpoint(%p)",
1647 static_cast<void*>(target_sp.get()),
1648 static_cast<uint32_t>(bp_id),
1649 static_cast<void*>(sb_breakpoint.get()));
Johnny Chen5d043462011-09-26 22:40:50 +00001650
1651 return sb_breakpoint;
1652}
1653
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001654bool
1655SBTarget::EnableAllBreakpoints ()
1656{
Greg Claytonacdbe812012-01-30 09:04:36 +00001657 TargetSP target_sp(GetSP());
1658 if (target_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001659 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001660 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1661 target_sp->EnableAllBreakpoints ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001662 return true;
1663 }
1664 return false;
1665}
1666
1667bool
1668SBTarget::DisableAllBreakpoints ()
1669{
Greg Claytonacdbe812012-01-30 09:04:36 +00001670 TargetSP target_sp(GetSP());
1671 if (target_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001672 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001673 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1674 target_sp->DisableAllBreakpoints ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001675 return true;
1676 }
1677 return false;
1678}
1679
1680bool
1681SBTarget::DeleteAllBreakpoints ()
1682{
Greg Claytonacdbe812012-01-30 09:04:36 +00001683 TargetSP target_sp(GetSP());
1684 if (target_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001685 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001686 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1687 target_sp->RemoveAllBreakpoints ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001688 return true;
1689 }
1690 return false;
1691}
1692
Johnny Chen5d043462011-09-26 22:40:50 +00001693uint32_t
Greg Clayton1b282f92011-10-13 18:08:26 +00001694SBTarget::GetNumWatchpoints () const
Johnny Chen5d043462011-09-26 22:40:50 +00001695{
Greg Claytonacdbe812012-01-30 09:04:36 +00001696 TargetSP target_sp(GetSP());
1697 if (target_sp)
Johnny Chen5d043462011-09-26 22:40:50 +00001698 {
Johnny Chen01a67862011-10-14 00:42:25 +00001699 // The watchpoint list is thread safe, no need to lock
Greg Claytonacdbe812012-01-30 09:04:36 +00001700 return target_sp->GetWatchpointList().GetSize();
Johnny Chen5d043462011-09-26 22:40:50 +00001701 }
1702 return 0;
1703}
1704
Greg Clayton1b282f92011-10-13 18:08:26 +00001705SBWatchpoint
1706SBTarget::GetWatchpointAtIndex (uint32_t idx) const
Johnny Chen9d954d82011-09-27 20:29:45 +00001707{
Johnny Chen01a67862011-10-14 00:42:25 +00001708 SBWatchpoint sb_watchpoint;
Greg Claytonacdbe812012-01-30 09:04:36 +00001709 TargetSP target_sp(GetSP());
1710 if (target_sp)
Johnny Chen5d043462011-09-26 22:40:50 +00001711 {
Johnny Chen01a67862011-10-14 00:42:25 +00001712 // The watchpoint list is thread safe, no need to lock
Greg Clayton81e871e2012-02-04 02:27:34 +00001713 sb_watchpoint.SetSP (target_sp->GetWatchpointList().GetByIndex(idx));
Johnny Chen5d043462011-09-26 22:40:50 +00001714 }
Johnny Chen01a67862011-10-14 00:42:25 +00001715 return sb_watchpoint;
Johnny Chen5d043462011-09-26 22:40:50 +00001716}
1717
1718bool
Greg Clayton1b282f92011-10-13 18:08:26 +00001719SBTarget::DeleteWatchpoint (watch_id_t wp_id)
Johnny Chen5d043462011-09-26 22:40:50 +00001720{
Greg Clayton5160ce52013-03-27 23:08:40 +00001721 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Johnny Chen5d043462011-09-26 22:40:50 +00001722
1723 bool result = false;
Greg Claytonacdbe812012-01-30 09:04:36 +00001724 TargetSP target_sp(GetSP());
1725 if (target_sp)
Johnny Chen5d043462011-09-26 22:40:50 +00001726 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001727 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Johnny Chen7385a5a2012-05-31 22:56:36 +00001728 Mutex::Locker locker;
1729 target_sp->GetWatchpointList().GetListMutex(locker);
Greg Claytonacdbe812012-01-30 09:04:36 +00001730 result = target_sp->RemoveWatchpointByID (wp_id);
Johnny Chen5d043462011-09-26 22:40:50 +00001731 }
1732
1733 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001734 log->Printf ("SBTarget(%p)::WatchpointDelete (wp_id=%d) => %i",
1735 static_cast<void*>(target_sp.get()),
1736 static_cast<uint32_t>(wp_id), result);
Johnny Chen5d043462011-09-26 22:40:50 +00001737
1738 return result;
1739}
1740
Greg Clayton1b282f92011-10-13 18:08:26 +00001741SBWatchpoint
1742SBTarget::FindWatchpointByID (lldb::watch_id_t wp_id)
Johnny Chen5d043462011-09-26 22:40:50 +00001743{
Greg Clayton5160ce52013-03-27 23:08:40 +00001744 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Johnny Chen5d043462011-09-26 22:40:50 +00001745
Greg Clayton1b282f92011-10-13 18:08:26 +00001746 SBWatchpoint sb_watchpoint;
Greg Clayton81e871e2012-02-04 02:27:34 +00001747 lldb::WatchpointSP watchpoint_sp;
Greg Claytonacdbe812012-01-30 09:04:36 +00001748 TargetSP target_sp(GetSP());
1749 if (target_sp && wp_id != LLDB_INVALID_WATCH_ID)
Johnny Chen5d043462011-09-26 22:40:50 +00001750 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001751 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Johnny Chen7385a5a2012-05-31 22:56:36 +00001752 Mutex::Locker locker;
1753 target_sp->GetWatchpointList().GetListMutex(locker);
Greg Clayton81e871e2012-02-04 02:27:34 +00001754 watchpoint_sp = target_sp->GetWatchpointList().FindByID(wp_id);
1755 sb_watchpoint.SetSP (watchpoint_sp);
Johnny Chen5d043462011-09-26 22:40:50 +00001756 }
1757
1758 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001759 log->Printf ("SBTarget(%p)::FindWatchpointByID (bp_id=%d) => SBWatchpoint(%p)",
1760 static_cast<void*>(target_sp.get()),
1761 static_cast<uint32_t>(wp_id),
1762 static_cast<void*>(watchpoint_sp.get()));
Johnny Chen5d043462011-09-26 22:40:50 +00001763
Greg Clayton1b282f92011-10-13 18:08:26 +00001764 return sb_watchpoint;
1765}
1766
1767lldb::SBWatchpoint
Johnny Chenb90827e2012-06-04 23:19:54 +00001768SBTarget::WatchAddress (lldb::addr_t addr, size_t size, bool read, bool write, SBError &error)
Greg Clayton1b282f92011-10-13 18:08:26 +00001769{
Greg Clayton5160ce52013-03-27 23:08:40 +00001770 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001771
Greg Clayton1b282f92011-10-13 18:08:26 +00001772 SBWatchpoint sb_watchpoint;
Greg Clayton81e871e2012-02-04 02:27:34 +00001773 lldb::WatchpointSP watchpoint_sp;
Greg Claytonacdbe812012-01-30 09:04:36 +00001774 TargetSP target_sp(GetSP());
Greg Clayton81e871e2012-02-04 02:27:34 +00001775 if (target_sp && (read || write) && addr != LLDB_INVALID_ADDRESS && size > 0)
Greg Clayton1b282f92011-10-13 18:08:26 +00001776 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001777 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton81e871e2012-02-04 02:27:34 +00001778 uint32_t watch_type = 0;
1779 if (read)
1780 watch_type |= LLDB_WATCH_TYPE_READ;
1781 if (write)
1782 watch_type |= LLDB_WATCH_TYPE_WRITE;
Jim Inghamc6462312013-06-18 21:52:48 +00001783 if (watch_type == 0)
1784 {
1785 error.SetErrorString("Can't create a watchpoint that is neither read nor write.");
1786 return sb_watchpoint;
1787 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001788
Johnny Chen7385a5a2012-05-31 22:56:36 +00001789 // Target::CreateWatchpoint() is thread safe.
Johnny Chenb90827e2012-06-04 23:19:54 +00001790 Error cw_error;
Jim Inghama7dfb662012-10-23 07:20:06 +00001791 // This API doesn't take in a type, so we can't figure out what it is.
1792 ClangASTType *type = NULL;
1793 watchpoint_sp = target_sp->CreateWatchpoint(addr, size, type, watch_type, cw_error);
Johnny Chenb90827e2012-06-04 23:19:54 +00001794 error.SetError(cw_error);
Greg Clayton81e871e2012-02-04 02:27:34 +00001795 sb_watchpoint.SetSP (watchpoint_sp);
Greg Clayton1b282f92011-10-13 18:08:26 +00001796 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001797
Greg Clayton1b282f92011-10-13 18:08:26 +00001798 if (log)
Daniel Malead01b2952012-11-29 21:49:15 +00001799 log->Printf ("SBTarget(%p)::WatchAddress (addr=0x%" PRIx64 ", 0x%u) => SBWatchpoint(%p)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001800 static_cast<void*>(target_sp.get()), addr,
1801 static_cast<uint32_t>(size),
1802 static_cast<void*>(watchpoint_sp.get()));
1803
Greg Clayton1b282f92011-10-13 18:08:26 +00001804 return sb_watchpoint;
Johnny Chen5d043462011-09-26 22:40:50 +00001805}
1806
1807bool
Greg Clayton1b282f92011-10-13 18:08:26 +00001808SBTarget::EnableAllWatchpoints ()
Johnny Chen5d043462011-09-26 22:40:50 +00001809{
Greg Claytonacdbe812012-01-30 09:04:36 +00001810 TargetSP target_sp(GetSP());
1811 if (target_sp)
Johnny Chen5d043462011-09-26 22:40:50 +00001812 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001813 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Johnny Chen7385a5a2012-05-31 22:56:36 +00001814 Mutex::Locker locker;
1815 target_sp->GetWatchpointList().GetListMutex(locker);
Greg Claytonacdbe812012-01-30 09:04:36 +00001816 target_sp->EnableAllWatchpoints ();
Johnny Chen5d043462011-09-26 22:40:50 +00001817 return true;
1818 }
1819 return false;
1820}
1821
1822bool
Greg Clayton1b282f92011-10-13 18:08:26 +00001823SBTarget::DisableAllWatchpoints ()
Johnny Chen5d043462011-09-26 22:40:50 +00001824{
Greg Claytonacdbe812012-01-30 09:04:36 +00001825 TargetSP target_sp(GetSP());
1826 if (target_sp)
Johnny Chen5d043462011-09-26 22:40:50 +00001827 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001828 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Johnny Chen7385a5a2012-05-31 22:56:36 +00001829 Mutex::Locker locker;
1830 target_sp->GetWatchpointList().GetListMutex(locker);
Greg Claytonacdbe812012-01-30 09:04:36 +00001831 target_sp->DisableAllWatchpoints ();
Johnny Chen5d043462011-09-26 22:40:50 +00001832 return true;
1833 }
1834 return false;
1835}
1836
Enrico Granata347c2aa2013-10-08 21:49:02 +00001837SBValue
1838SBTarget::CreateValueFromAddress (const char *name, SBAddress addr, SBType type)
1839{
1840 SBValue sb_value;
1841 lldb::ValueObjectSP new_value_sp;
1842 if (IsValid() && name && *name && addr.IsValid() && type.IsValid())
1843 {
1844 lldb::addr_t address(addr.GetLoadAddress(*this));
1845 lldb::TypeImplSP type_impl_sp (type.GetSP());
Enrico Granatadc4db5a2013-10-29 00:28:35 +00001846 ClangASTType pointer_ast_type(type_impl_sp->GetClangASTType(true).GetPointerType ());
Enrico Granata347c2aa2013-10-08 21:49:02 +00001847 if (pointer_ast_type)
1848 {
1849 lldb::DataBufferSP buffer(new lldb_private::DataBufferHeap(&address,sizeof(lldb::addr_t)));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001850
Enrico Granata347c2aa2013-10-08 21:49:02 +00001851 ExecutionContext exe_ctx (ExecutionContextRef(ExecutionContext(m_opaque_sp.get(),false)));
1852 ValueObjectSP ptr_result_valobj_sp(ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
1853 pointer_ast_type,
1854 ConstString(name),
1855 buffer,
1856 exe_ctx.GetByteOrder(),
1857 exe_ctx.GetAddressByteSize()));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001858
Enrico Granata347c2aa2013-10-08 21:49:02 +00001859 if (ptr_result_valobj_sp)
1860 {
1861 ptr_result_valobj_sp->GetValue().SetValueType(Value::eValueTypeLoadAddress);
1862 Error err;
1863 new_value_sp = ptr_result_valobj_sp->Dereference(err);
1864 if (new_value_sp)
1865 new_value_sp->SetName(ConstString(name));
1866 }
1867 }
1868 }
1869 sb_value.SetSP(new_value_sp);
1870 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1871 if (log)
1872 {
1873 if (new_value_sp)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001874 log->Printf ("SBTarget(%p)::CreateValueFromAddress => \"%s\"",
1875 static_cast<void*>(m_opaque_sp.get()),
1876 new_value_sp->GetName().AsCString());
Enrico Granata347c2aa2013-10-08 21:49:02 +00001877 else
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001878 log->Printf ("SBTarget(%p)::CreateValueFromAddress => NULL",
1879 static_cast<void*>(m_opaque_sp.get()));
Enrico Granata347c2aa2013-10-08 21:49:02 +00001880 }
1881 return sb_value;
1882}
1883
Johnny Chen5d043462011-09-26 22:40:50 +00001884bool
Greg Clayton1b282f92011-10-13 18:08:26 +00001885SBTarget::DeleteAllWatchpoints ()
Johnny Chen5d043462011-09-26 22:40:50 +00001886{
Greg Claytonacdbe812012-01-30 09:04:36 +00001887 TargetSP target_sp(GetSP());
1888 if (target_sp)
Johnny Chen5d043462011-09-26 22:40:50 +00001889 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001890 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Johnny Chen7385a5a2012-05-31 22:56:36 +00001891 Mutex::Locker locker;
1892 target_sp->GetWatchpointList().GetListMutex(locker);
Greg Claytonacdbe812012-01-30 09:04:36 +00001893 target_sp->RemoveAllWatchpoints ();
Johnny Chen5d043462011-09-26 22:40:50 +00001894 return true;
1895 }
1896 return false;
1897}
1898
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001899
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001900lldb::SBModule
1901SBTarget::AddModule (const char *path,
1902 const char *triple,
1903 const char *uuid_cstr)
1904{
Greg Claytonb210aec2012-04-23 20:23:39 +00001905 return AddModule (path, triple, uuid_cstr, NULL);
1906}
1907
1908lldb::SBModule
1909SBTarget::AddModule (const char *path,
1910 const char *triple,
1911 const char *uuid_cstr,
1912 const char *symfile)
1913{
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001914 lldb::SBModule sb_module;
Greg Claytonacdbe812012-01-30 09:04:36 +00001915 TargetSP target_sp(GetSP());
1916 if (target_sp)
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001917 {
Greg Claytonb9a01b32012-02-26 05:51:37 +00001918 ModuleSpec module_spec;
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001919 if (path)
Greg Claytonb9a01b32012-02-26 05:51:37 +00001920 module_spec.GetFileSpec().SetFile(path, false);
Greg Claytonb210aec2012-04-23 20:23:39 +00001921
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001922 if (uuid_cstr)
Greg Claytonb5f0fea2012-09-27 22:26:11 +00001923 module_spec.GetUUID().SetFromCString(uuid_cstr);
Greg Claytonb210aec2012-04-23 20:23:39 +00001924
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001925 if (triple)
Greg Claytonb9a01b32012-02-26 05:51:37 +00001926 module_spec.GetArchitecture().SetTriple (triple, target_sp->GetPlatform ().get());
Jason Molendab019cd92013-09-11 21:25:46 +00001927 else
1928 module_spec.GetArchitecture() = target_sp->GetArchitecture();
Greg Claytonb210aec2012-04-23 20:23:39 +00001929
1930 if (symfile)
1931 module_spec.GetSymbolFileSpec ().SetFile(symfile, false);
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001932
Greg Claytonb9a01b32012-02-26 05:51:37 +00001933 sb_module.SetSP(target_sp->GetSharedModule (module_spec));
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001934 }
1935 return sb_module;
1936}
1937
Greg Clayton226cce22013-07-08 22:22:41 +00001938lldb::SBModule
1939SBTarget::AddModule (const SBModuleSpec &module_spec)
1940{
1941 lldb::SBModule sb_module;
1942 TargetSP target_sp(GetSP());
1943 if (target_sp)
1944 sb_module.SetSP(target_sp->GetSharedModule (*module_spec.m_opaque_ap));
1945 return sb_module;
1946}
1947
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001948bool
1949SBTarget::AddModule (lldb::SBModule &module)
1950{
Greg Claytonacdbe812012-01-30 09:04:36 +00001951 TargetSP target_sp(GetSP());
1952 if (target_sp)
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001953 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001954 target_sp->GetImages().AppendIfNeeded (module.GetSP());
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001955 return true;
1956 }
1957 return false;
1958}
1959
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001960uint32_t
1961SBTarget::GetNumModules () const
1962{
Greg Clayton5160ce52013-03-27 23:08:40 +00001963 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001964
Caroline Ticeceb6b132010-10-26 03:11:13 +00001965 uint32_t num = 0;
Greg Claytonacdbe812012-01-30 09:04:36 +00001966 TargetSP target_sp(GetSP());
1967 if (target_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +00001968 {
1969 // The module list is thread safe, no need to lock
Greg Claytonacdbe812012-01-30 09:04:36 +00001970 num = target_sp->GetImages().GetSize();
Greg Claytonaf67cec2010-12-20 20:49:23 +00001971 }
Caroline Ticeceb6b132010-10-26 03:11:13 +00001972
1973 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001974 log->Printf ("SBTarget(%p)::GetNumModules () => %d",
1975 static_cast<void*>(target_sp.get()), num);
Caroline Ticeceb6b132010-10-26 03:11:13 +00001976
1977 return num;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001978}
1979
Greg Clayton48e42542010-07-30 20:12:55 +00001980void
1981SBTarget::Clear ()
1982{
Greg Clayton5160ce52013-03-27 23:08:40 +00001983 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001984
1985 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001986 log->Printf ("SBTarget(%p)::Clear ()",
1987 static_cast<void*>(m_opaque_sp.get()));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001988
Greg Clayton48e42542010-07-30 20:12:55 +00001989 m_opaque_sp.reset();
1990}
1991
1992
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001993SBModule
1994SBTarget::FindModule (const SBFileSpec &sb_file_spec)
1995{
1996 SBModule sb_module;
Greg Claytonacdbe812012-01-30 09:04:36 +00001997 TargetSP target_sp(GetSP());
1998 if (target_sp && sb_file_spec.IsValid())
Greg Claytonaf67cec2010-12-20 20:49:23 +00001999 {
Greg Claytonb9a01b32012-02-26 05:51:37 +00002000 ModuleSpec module_spec(*sb_file_spec);
Greg Claytonaf67cec2010-12-20 20:49:23 +00002001 // The module list is thread safe, no need to lock
Greg Claytonb9a01b32012-02-26 05:51:37 +00002002 sb_module.SetSP (target_sp->GetImages().FindFirstModule (module_spec));
Greg Claytonaf67cec2010-12-20 20:49:23 +00002003 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002004 return sb_module;
2005}
2006
Greg Clayton13d19502012-01-29 06:07:39 +00002007lldb::ByteOrder
2008SBTarget::GetByteOrder ()
2009{
Greg Claytonacdbe812012-01-30 09:04:36 +00002010 TargetSP target_sp(GetSP());
2011 if (target_sp)
2012 return target_sp->GetArchitecture().GetByteOrder();
Greg Clayton13d19502012-01-29 06:07:39 +00002013 return eByteOrderInvalid;
2014}
2015
2016const char *
2017SBTarget::GetTriple ()
2018{
Greg Claytonacdbe812012-01-30 09:04:36 +00002019 TargetSP target_sp(GetSP());
2020 if (target_sp)
Greg Clayton13d19502012-01-29 06:07:39 +00002021 {
Greg Claytonacdbe812012-01-30 09:04:36 +00002022 std::string triple (target_sp->GetArchitecture().GetTriple().str());
Greg Clayton13d19502012-01-29 06:07:39 +00002023 // Unique the string so we don't run into ownership issues since
2024 // the const strings put the string into the string pool once and
2025 // the strings never comes out
2026 ConstString const_triple (triple.c_str());
2027 return const_triple.GetCString();
2028 }
2029 return NULL;
2030}
2031
2032uint32_t
2033SBTarget::GetAddressByteSize()
2034{
Greg Claytonacdbe812012-01-30 09:04:36 +00002035 TargetSP target_sp(GetSP());
2036 if (target_sp)
2037 return target_sp->GetArchitecture().GetAddressByteSize();
Greg Clayton13d19502012-01-29 06:07:39 +00002038 return sizeof(void*);
2039}
2040
2041
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002042SBModule
2043SBTarget::GetModuleAtIndex (uint32_t idx)
2044{
Greg Clayton5160ce52013-03-27 23:08:40 +00002045 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +00002046
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002047 SBModule sb_module;
Greg Claytonacdbe812012-01-30 09:04:36 +00002048 ModuleSP module_sp;
2049 TargetSP target_sp(GetSP());
2050 if (target_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +00002051 {
2052 // The module list is thread safe, no need to lock
Greg Claytonacdbe812012-01-30 09:04:36 +00002053 module_sp = target_sp->GetImages().GetModuleAtIndex(idx);
2054 sb_module.SetSP (module_sp);
Greg Claytonaf67cec2010-12-20 20:49:23 +00002055 }
Caroline Ticeceb6b132010-10-26 03:11:13 +00002056
2057 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002058 log->Printf ("SBTarget(%p)::GetModuleAtIndex (idx=%d) => SBModule(%p)",
2059 static_cast<void*>(target_sp.get()), idx,
2060 static_cast<void*>(module_sp.get()));
Caroline Ticeceb6b132010-10-26 03:11:13 +00002061
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002062 return sb_module;
2063}
2064
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002065bool
2066SBTarget::RemoveModule (lldb::SBModule module)
2067{
Greg Claytonacdbe812012-01-30 09:04:36 +00002068 TargetSP target_sp(GetSP());
2069 if (target_sp)
2070 return target_sp->GetImages().Remove(module.GetSP());
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002071 return false;
2072}
2073
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002074
2075SBBroadcaster
2076SBTarget::GetBroadcaster () const
2077{
Greg Clayton5160ce52013-03-27 23:08:40 +00002078 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +00002079
Greg Claytonacdbe812012-01-30 09:04:36 +00002080 TargetSP target_sp(GetSP());
2081 SBBroadcaster broadcaster(target_sp.get(), false);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002082
Caroline Ticeceb6b132010-10-26 03:11:13 +00002083 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002084 log->Printf ("SBTarget(%p)::GetBroadcaster () => SBBroadcaster(%p)",
2085 static_cast<void*>(target_sp.get()),
2086 static_cast<void*>(broadcaster.get()));
Caroline Ticeceb6b132010-10-26 03:11:13 +00002087
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002088 return broadcaster;
2089}
2090
Caroline Ticedde9cff2010-09-20 05:20:02 +00002091bool
Caroline Ticeceb6b132010-10-26 03:11:13 +00002092SBTarget::GetDescription (SBStream &description, lldb::DescriptionLevel description_level)
Caroline Ticedde9cff2010-09-20 05:20:02 +00002093{
Greg Claytonda7bc7d2011-11-13 06:57:31 +00002094 Stream &strm = description.ref();
2095
Greg Claytonacdbe812012-01-30 09:04:36 +00002096 TargetSP target_sp(GetSP());
2097 if (target_sp)
Caroline Tice201a8852010-09-20 16:21:41 +00002098 {
Greg Claytonacdbe812012-01-30 09:04:36 +00002099 target_sp->Dump (&strm, description_level);
Caroline Ticeceb6b132010-10-26 03:11:13 +00002100 }
2101 else
Greg Claytonda7bc7d2011-11-13 06:57:31 +00002102 strm.PutCString ("No value");
Caroline Ticeceb6b132010-10-26 03:11:13 +00002103
2104 return true;
2105}
2106
Greg Clayton5569e642012-02-06 01:44:54 +00002107lldb::SBSymbolContextList
2108SBTarget::FindFunctions (const char *name, uint32_t name_type_mask)
Greg Claytonfe356d32011-06-21 01:34:41 +00002109{
Greg Clayton5569e642012-02-06 01:44:54 +00002110 lldb::SBSymbolContextList sb_sc_list;
Greg Claytonacdbe812012-01-30 09:04:36 +00002111 if (name && name[0])
Greg Claytonfe356d32011-06-21 01:34:41 +00002112 {
Greg Claytonacdbe812012-01-30 09:04:36 +00002113 TargetSP target_sp(GetSP());
2114 if (target_sp)
2115 {
2116 const bool symbols_ok = true;
Sean Callanan9df05fb2012-02-10 22:52:19 +00002117 const bool inlines_ok = true;
Greg Clayton5569e642012-02-06 01:44:54 +00002118 const bool append = true;
2119 target_sp->GetImages().FindFunctions (ConstString(name),
2120 name_type_mask,
Sean Callanan9df05fb2012-02-10 22:52:19 +00002121 symbols_ok,
2122 inlines_ok,
Greg Clayton5569e642012-02-06 01:44:54 +00002123 append,
2124 *sb_sc_list);
Greg Claytonacdbe812012-01-30 09:04:36 +00002125 }
Greg Claytonfe356d32011-06-21 01:34:41 +00002126 }
Greg Clayton5569e642012-02-06 01:44:54 +00002127 return sb_sc_list;
Greg Claytonfe356d32011-06-21 01:34:41 +00002128}
2129
Enrico Granata6f3533f2011-07-29 19:53:35 +00002130lldb::SBType
Greg Claytonb43165b2012-12-05 21:24:42 +00002131SBTarget::FindFirstType (const char* typename_cstr)
Enrico Granata6f3533f2011-07-29 19:53:35 +00002132{
Greg Claytonacdbe812012-01-30 09:04:36 +00002133 TargetSP target_sp(GetSP());
Greg Claytonb43165b2012-12-05 21:24:42 +00002134 if (typename_cstr && typename_cstr[0] && target_sp)
Enrico Granata6f3533f2011-07-29 19:53:35 +00002135 {
Greg Claytonb43165b2012-12-05 21:24:42 +00002136 ConstString const_typename(typename_cstr);
2137 SymbolContext sc;
2138 const bool exact_match = false;
2139
2140 const ModuleList &module_list = target_sp->GetImages();
2141 size_t count = module_list.GetSize();
Enrico Granata6f3533f2011-07-29 19:53:35 +00002142 for (size_t idx = 0; idx < count; idx++)
2143 {
Greg Claytonb43165b2012-12-05 21:24:42 +00002144 ModuleSP module_sp (module_list.GetModuleAtIndex(idx));
2145 if (module_sp)
2146 {
2147 TypeSP type_sp (module_sp->FindFirstType(sc, const_typename, exact_match));
2148 if (type_sp)
2149 return SBType(type_sp);
2150 }
Enrico Granata6f3533f2011-07-29 19:53:35 +00002151 }
Sean Callanan7be70e82012-12-19 23:05:01 +00002152
2153 // Didn't find the type in the symbols; try the Objective-C runtime
2154 // if one is installed
2155
2156 ProcessSP process_sp(target_sp->GetProcessSP());
2157
2158 if (process_sp)
2159 {
2160 ObjCLanguageRuntime *objc_language_runtime = process_sp->GetObjCLanguageRuntime();
2161
2162 if (objc_language_runtime)
2163 {
2164 TypeVendor *objc_type_vendor = objc_language_runtime->GetTypeVendor();
2165
2166 if (objc_type_vendor)
2167 {
2168 std::vector <ClangASTType> types;
2169
2170 if (objc_type_vendor->FindTypes(const_typename, true, 1, types) > 0)
2171 return SBType(types[0]);
2172 }
2173 }
2174 }
Greg Claytonb43165b2012-12-05 21:24:42 +00002175
2176 // No matches, search for basic typename matches
2177 ClangASTContext *clang_ast = target_sp->GetScratchClangASTContext();
2178 if (clang_ast)
Greg Clayton57ee3062013-07-11 22:46:58 +00002179 return SBType (ClangASTContext::GetBasicType (clang_ast->getASTContext(), const_typename));
Enrico Granata6f3533f2011-07-29 19:53:35 +00002180 }
2181 return SBType();
2182}
2183
Greg Claytonb43165b2012-12-05 21:24:42 +00002184SBType
2185SBTarget::GetBasicType(lldb::BasicType type)
Enrico Granata6f3533f2011-07-29 19:53:35 +00002186{
Greg Claytonacdbe812012-01-30 09:04:36 +00002187 TargetSP target_sp(GetSP());
Greg Claytonb43165b2012-12-05 21:24:42 +00002188 if (target_sp)
2189 {
2190 ClangASTContext *clang_ast = target_sp->GetScratchClangASTContext();
2191 if (clang_ast)
Greg Clayton57ee3062013-07-11 22:46:58 +00002192 return SBType (ClangASTContext::GetBasicType (clang_ast->getASTContext(), type));
Greg Claytonb43165b2012-12-05 21:24:42 +00002193 }
2194 return SBType();
2195}
2196
2197
2198lldb::SBTypeList
2199SBTarget::FindTypes (const char* typename_cstr)
2200{
2201 SBTypeList sb_type_list;
2202 TargetSP target_sp(GetSP());
2203 if (typename_cstr && typename_cstr[0] && target_sp)
Enrico Granata6f3533f2011-07-29 19:53:35 +00002204 {
Greg Claytonacdbe812012-01-30 09:04:36 +00002205 ModuleList& images = target_sp->GetImages();
Greg Claytonb43165b2012-12-05 21:24:42 +00002206 ConstString const_typename(typename_cstr);
Greg Clayton84db9102012-03-26 23:03:23 +00002207 bool exact_match = false;
Enrico Granata6f3533f2011-07-29 19:53:35 +00002208 SymbolContext sc;
2209 TypeList type_list;
2210
Greg Clayton29399a22012-04-06 17:41:13 +00002211 uint32_t num_matches = images.FindTypes (sc,
Greg Claytonb43165b2012-12-05 21:24:42 +00002212 const_typename,
Greg Clayton84db9102012-03-26 23:03:23 +00002213 exact_match,
2214 UINT32_MAX,
2215 type_list);
Enrico Granata6f3533f2011-07-29 19:53:35 +00002216
Greg Claytonb43165b2012-12-05 21:24:42 +00002217 if (num_matches > 0)
Enrico Granata6f3533f2011-07-29 19:53:35 +00002218 {
Greg Claytonb43165b2012-12-05 21:24:42 +00002219 for (size_t idx = 0; idx < num_matches; idx++)
2220 {
2221 TypeSP type_sp (type_list.GetTypeAtIndex(idx));
2222 if (type_sp)
2223 sb_type_list.Append(SBType(type_sp));
2224 }
2225 }
Sean Callanan7be70e82012-12-19 23:05:01 +00002226
2227 // Try the Objective-C runtime if one is installed
2228
2229 ProcessSP process_sp(target_sp->GetProcessSP());
2230
2231 if (process_sp)
2232 {
2233 ObjCLanguageRuntime *objc_language_runtime = process_sp->GetObjCLanguageRuntime();
2234
2235 if (objc_language_runtime)
2236 {
2237 TypeVendor *objc_type_vendor = objc_language_runtime->GetTypeVendor();
2238
2239 if (objc_type_vendor)
2240 {
2241 std::vector <ClangASTType> types;
2242
2243 if (objc_type_vendor->FindTypes(const_typename, true, UINT32_MAX, types))
2244 {
2245 for (ClangASTType &type : types)
2246 {
2247 sb_type_list.Append(SBType(type));
2248 }
2249 }
2250 }
2251 }
2252 }
2253
2254 if (sb_type_list.GetSize() == 0)
Greg Claytonb43165b2012-12-05 21:24:42 +00002255 {
2256 // No matches, search for basic typename matches
2257 ClangASTContext *clang_ast = target_sp->GetScratchClangASTContext();
2258 if (clang_ast)
Greg Clayton57ee3062013-07-11 22:46:58 +00002259 sb_type_list.Append (SBType (ClangASTContext::GetBasicType (clang_ast->getASTContext(), const_typename)));
Enrico Granata6f3533f2011-07-29 19:53:35 +00002260 }
2261 }
Greg Claytonb43165b2012-12-05 21:24:42 +00002262 return sb_type_list;
Enrico Granata6f3533f2011-07-29 19:53:35 +00002263}
2264
Greg Claytondea8cb42011-06-29 22:09:02 +00002265SBValueList
2266SBTarget::FindGlobalVariables (const char *name, uint32_t max_matches)
2267{
2268 SBValueList sb_value_list;
2269
Greg Claytonacdbe812012-01-30 09:04:36 +00002270 TargetSP target_sp(GetSP());
2271 if (name && target_sp)
Greg Claytondea8cb42011-06-29 22:09:02 +00002272 {
2273 VariableList variable_list;
2274 const bool append = true;
Greg Claytonacdbe812012-01-30 09:04:36 +00002275 const uint32_t match_count = target_sp->GetImages().FindGlobalVariables (ConstString (name),
2276 append,
2277 max_matches,
2278 variable_list);
Greg Claytondea8cb42011-06-29 22:09:02 +00002279
2280 if (match_count > 0)
2281 {
Greg Claytonacdbe812012-01-30 09:04:36 +00002282 ExecutionContextScope *exe_scope = target_sp->GetProcessSP().get();
Greg Claytondea8cb42011-06-29 22:09:02 +00002283 if (exe_scope == NULL)
Greg Claytonacdbe812012-01-30 09:04:36 +00002284 exe_scope = target_sp.get();
Greg Claytondea8cb42011-06-29 22:09:02 +00002285 for (uint32_t i=0; i<match_count; ++i)
2286 {
2287 lldb::ValueObjectSP valobj_sp (ValueObjectVariable::Create (exe_scope, variable_list.GetVariableAtIndex(i)));
2288 if (valobj_sp)
Enrico Granata85425d72013-02-07 18:23:56 +00002289 sb_value_list.Append(SBValue(valobj_sp));
Greg Claytondea8cb42011-06-29 22:09:02 +00002290 }
2291 }
2292 }
2293
2294 return sb_value_list;
2295}
2296
Enrico Granatabcd80b42013-01-16 18:53:52 +00002297lldb::SBValue
2298SBTarget::FindFirstGlobalVariable (const char* name)
2299{
2300 SBValueList sb_value_list(FindGlobalVariables(name, 1));
2301 if (sb_value_list.IsValid() && sb_value_list.GetSize() > 0)
2302 return sb_value_list.GetValueAtIndex(0);
2303 return SBValue();
2304}
2305
Jim Inghame37d6052011-09-13 00:29:56 +00002306SBSourceManager
2307SBTarget::GetSourceManager()
2308{
2309 SBSourceManager source_manager (*this);
2310 return source_manager;
2311}
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002312
Sean Callanan50952e92011-12-14 23:49:37 +00002313lldb::SBInstructionList
Greg Clayton9c766112012-03-06 22:24:44 +00002314SBTarget::ReadInstructions (lldb::SBAddress base_addr, uint32_t count)
2315{
Jim Ingham0f063ba2013-03-02 00:26:47 +00002316 return ReadInstructions (base_addr, count, NULL);
2317}
2318
2319lldb::SBInstructionList
2320SBTarget::ReadInstructions (lldb::SBAddress base_addr, uint32_t count, const char *flavor_string)
2321{
Greg Clayton9c766112012-03-06 22:24:44 +00002322 SBInstructionList sb_instructions;
2323
2324 TargetSP target_sp(GetSP());
2325 if (target_sp)
2326 {
2327 Address *addr_ptr = base_addr.get();
2328
2329 if (addr_ptr)
2330 {
2331 DataBufferHeap data (target_sp->GetArchitecture().GetMaximumOpcodeByteSize() * count, 0);
2332 bool prefer_file_cache = false;
2333 lldb_private::Error error;
Greg Clayton3faf47c2013-03-28 23:42:53 +00002334 lldb::addr_t load_addr = LLDB_INVALID_ADDRESS;
2335 const size_t bytes_read = target_sp->ReadMemory(*addr_ptr,
2336 prefer_file_cache,
2337 data.GetBytes(),
2338 data.GetByteSize(),
2339 error,
2340 &load_addr);
2341 const bool data_from_file = load_addr == LLDB_INVALID_ADDRESS;
Greg Clayton9c766112012-03-06 22:24:44 +00002342 sb_instructions.SetDisassembler (Disassembler::DisassembleBytes (target_sp->GetArchitecture(),
2343 NULL,
Jim Ingham0f063ba2013-03-02 00:26:47 +00002344 flavor_string,
Greg Clayton9c766112012-03-06 22:24:44 +00002345 *addr_ptr,
2346 data.GetBytes(),
2347 bytes_read,
Greg Clayton3faf47c2013-03-28 23:42:53 +00002348 count,
2349 data_from_file));
Greg Clayton9c766112012-03-06 22:24:44 +00002350 }
2351 }
2352
2353 return sb_instructions;
2354
2355}
2356
2357lldb::SBInstructionList
Sean Callanan50952e92011-12-14 23:49:37 +00002358SBTarget::GetInstructions (lldb::SBAddress base_addr, const void *buf, size_t size)
2359{
Jim Ingham0f063ba2013-03-02 00:26:47 +00002360 return GetInstructionsWithFlavor (base_addr, NULL, buf, size);
2361}
2362
2363lldb::SBInstructionList
2364SBTarget::GetInstructionsWithFlavor (lldb::SBAddress base_addr, const char *flavor_string, const void *buf, size_t size)
2365{
Sean Callanan50952e92011-12-14 23:49:37 +00002366 SBInstructionList sb_instructions;
2367
Greg Claytonacdbe812012-01-30 09:04:36 +00002368 TargetSP target_sp(GetSP());
2369 if (target_sp)
Sean Callanan50952e92011-12-14 23:49:37 +00002370 {
2371 Address addr;
2372
2373 if (base_addr.get())
2374 addr = *base_addr.get();
2375
Greg Clayton3faf47c2013-03-28 23:42:53 +00002376 const bool data_from_file = true;
2377
Greg Claytonacdbe812012-01-30 09:04:36 +00002378 sb_instructions.SetDisassembler (Disassembler::DisassembleBytes (target_sp->GetArchitecture(),
Sean Callanan50952e92011-12-14 23:49:37 +00002379 NULL,
Jim Ingham0f063ba2013-03-02 00:26:47 +00002380 flavor_string,
Sean Callanan50952e92011-12-14 23:49:37 +00002381 addr,
2382 buf,
Greg Clayton3faf47c2013-03-28 23:42:53 +00002383 size,
2384 UINT32_MAX,
2385 data_from_file));
Sean Callanan50952e92011-12-14 23:49:37 +00002386 }
2387
2388 return sb_instructions;
2389}
2390
2391lldb::SBInstructionList
2392SBTarget::GetInstructions (lldb::addr_t base_addr, const void *buf, size_t size)
2393{
Jim Ingham0f063ba2013-03-02 00:26:47 +00002394 return GetInstructionsWithFlavor (ResolveLoadAddress(base_addr), NULL, buf, size);
2395}
2396
2397lldb::SBInstructionList
2398SBTarget::GetInstructionsWithFlavor (lldb::addr_t base_addr, const char *flavor_string, const void *buf, size_t size)
2399{
2400 return GetInstructionsWithFlavor (ResolveLoadAddress(base_addr), flavor_string, buf, size);
Sean Callanan50952e92011-12-14 23:49:37 +00002401}
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002402
2403SBError
2404SBTarget::SetSectionLoadAddress (lldb::SBSection section,
2405 lldb::addr_t section_base_addr)
2406{
2407 SBError sb_error;
Greg Claytonacdbe812012-01-30 09:04:36 +00002408 TargetSP target_sp(GetSP());
2409 if (target_sp)
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002410 {
2411 if (!section.IsValid())
2412 {
2413 sb_error.SetErrorStringWithFormat ("invalid section");
2414 }
2415 else
2416 {
Greg Clayton741f3f92012-03-27 21:10:07 +00002417 SectionSP section_sp (section.GetSP());
2418 if (section_sp)
2419 {
2420 if (section_sp->IsThreadSpecific())
2421 {
2422 sb_error.SetErrorString ("thread specific sections are not yet supported");
2423 }
2424 else
2425 {
Greg Claytond5944cd2013-12-06 01:12:00 +00002426 ProcessSP process_sp (target_sp->GetProcessSP());
2427 uint32_t stop_id = 0;
2428 if (process_sp)
2429 stop_id = process_sp->GetStopID();
2430
2431 if (target_sp->SetSectionLoadAddress (section_sp, section_base_addr))
Greg Clayton3c947372013-01-29 01:17:09 +00002432 {
2433 // Flush info in the process (stack frames, etc)
Greg Clayton3c947372013-01-29 01:17:09 +00002434 if (process_sp)
2435 process_sp->Flush();
2436 }
Greg Clayton741f3f92012-03-27 21:10:07 +00002437 }
2438 }
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002439 }
2440 }
2441 else
2442 {
Greg Clayton741f3f92012-03-27 21:10:07 +00002443 sb_error.SetErrorString ("invalid target");
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002444 }
2445 return sb_error;
2446}
2447
2448SBError
2449SBTarget::ClearSectionLoadAddress (lldb::SBSection section)
2450{
2451 SBError sb_error;
2452
Greg Claytonacdbe812012-01-30 09:04:36 +00002453 TargetSP target_sp(GetSP());
2454 if (target_sp)
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002455 {
2456 if (!section.IsValid())
2457 {
2458 sb_error.SetErrorStringWithFormat ("invalid section");
2459 }
2460 else
2461 {
Greg Claytond5944cd2013-12-06 01:12:00 +00002462 ProcessSP process_sp (target_sp->GetProcessSP());
2463 uint32_t stop_id = 0;
2464 if (process_sp)
2465 stop_id = process_sp->GetStopID();
2466
2467 if (target_sp->SetSectionUnloaded (section.GetSP()))
Greg Clayton3c947372013-01-29 01:17:09 +00002468 {
2469 // Flush info in the process (stack frames, etc)
Greg Clayton3c947372013-01-29 01:17:09 +00002470 if (process_sp)
2471 process_sp->Flush();
2472 }
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002473 }
2474 }
2475 else
2476 {
2477 sb_error.SetErrorStringWithFormat ("invalid target");
2478 }
2479 return sb_error;
2480}
2481
2482SBError
2483SBTarget::SetModuleLoadAddress (lldb::SBModule module, int64_t slide_offset)
2484{
2485 SBError sb_error;
2486
Greg Claytonacdbe812012-01-30 09:04:36 +00002487 TargetSP target_sp(GetSP());
2488 if (target_sp)
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002489 {
Greg Claytonacdbe812012-01-30 09:04:36 +00002490 ModuleSP module_sp (module.GetSP());
2491 if (module_sp)
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002492 {
Greg Clayton741f3f92012-03-27 21:10:07 +00002493 bool changed = false;
Greg Clayton751caf62014-02-07 22:54:47 +00002494 if (module_sp->SetLoadAddress (*target_sp, slide_offset, true, changed))
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002495 {
Greg Clayton741f3f92012-03-27 21:10:07 +00002496 // The load was successful, make sure that at least some sections
2497 // changed before we notify that our module was loaded.
2498 if (changed)
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002499 {
Greg Clayton741f3f92012-03-27 21:10:07 +00002500 ModuleList module_list;
2501 module_list.Append(module_sp);
2502 target_sp->ModulesDidLoad (module_list);
Greg Clayton3c947372013-01-29 01:17:09 +00002503 // Flush info in the process (stack frames, etc)
2504 ProcessSP process_sp (target_sp->GetProcessSP());
2505 if (process_sp)
2506 process_sp->Flush();
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002507 }
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002508 }
2509 }
Greg Claytonacdbe812012-01-30 09:04:36 +00002510 else
2511 {
2512 sb_error.SetErrorStringWithFormat ("invalid module");
2513 }
2514
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002515 }
2516 else
2517 {
2518 sb_error.SetErrorStringWithFormat ("invalid target");
2519 }
2520 return sb_error;
2521}
2522
2523SBError
2524SBTarget::ClearModuleLoadAddress (lldb::SBModule module)
2525{
2526 SBError sb_error;
2527
2528 char path[PATH_MAX];
Greg Claytonacdbe812012-01-30 09:04:36 +00002529 TargetSP target_sp(GetSP());
2530 if (target_sp)
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002531 {
Greg Claytonacdbe812012-01-30 09:04:36 +00002532 ModuleSP module_sp (module.GetSP());
2533 if (module_sp)
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002534 {
Greg Claytonacdbe812012-01-30 09:04:36 +00002535 ObjectFile *objfile = module_sp->GetObjectFile();
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002536 if (objfile)
2537 {
2538 SectionList *section_list = objfile->GetSectionList();
2539 if (section_list)
2540 {
Greg Claytond5944cd2013-12-06 01:12:00 +00002541 ProcessSP process_sp (target_sp->GetProcessSP());
2542 uint32_t stop_id = 0;
2543 if (process_sp)
2544 stop_id = process_sp->GetStopID();
2545
Greg Clayton3c947372013-01-29 01:17:09 +00002546 bool changed = false;
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002547 const size_t num_sections = section_list->GetSize();
2548 for (size_t sect_idx = 0; sect_idx < num_sections; ++sect_idx)
2549 {
2550 SectionSP section_sp (section_list->GetSectionAtIndex(sect_idx));
2551 if (section_sp)
Greg Claytond5944cd2013-12-06 01:12:00 +00002552 changed |= target_sp->SetSectionUnloaded (section_sp) > 0;
Greg Clayton3c947372013-01-29 01:17:09 +00002553 }
2554 if (changed)
2555 {
2556 // Flush info in the process (stack frames, etc)
2557 ProcessSP process_sp (target_sp->GetProcessSP());
2558 if (process_sp)
2559 process_sp->Flush();
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002560 }
2561 }
2562 else
2563 {
Greg Claytonacdbe812012-01-30 09:04:36 +00002564 module_sp->GetFileSpec().GetPath (path, sizeof(path));
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002565 sb_error.SetErrorStringWithFormat ("no sections in object file '%s'", path);
2566 }
2567 }
2568 else
2569 {
Greg Claytonacdbe812012-01-30 09:04:36 +00002570 module_sp->GetFileSpec().GetPath (path, sizeof(path));
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002571 sb_error.SetErrorStringWithFormat ("no object file for module '%s'", path);
2572 }
2573 }
Greg Claytonacdbe812012-01-30 09:04:36 +00002574 else
2575 {
2576 sb_error.SetErrorStringWithFormat ("invalid module");
2577 }
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002578 }
2579 else
2580 {
2581 sb_error.SetErrorStringWithFormat ("invalid target");
2582 }
2583 return sb_error;
2584}
2585
2586
Greg Claytone14e1922012-12-04 02:22:16 +00002587lldb::SBSymbolContextList
2588SBTarget::FindSymbols (const char *name, lldb::SymbolType symbol_type)
2589{
2590 SBSymbolContextList sb_sc_list;
2591 if (name && name[0])
2592 {
2593 TargetSP target_sp(GetSP());
2594 if (target_sp)
2595 {
2596 bool append = true;
2597 target_sp->GetImages().FindSymbolsWithNameAndType (ConstString(name),
2598 symbol_type,
2599 *sb_sc_list,
2600 append);
2601 }
2602 }
2603 return sb_sc_list;
2604
2605}
2606
2607
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002608lldb::SBValue
2609SBTarget::EvaluateExpression (const char *expr, const SBExpressionOptions &options)
2610{
Greg Clayton5160ce52013-03-27 23:08:40 +00002611 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
2612 Log * expr_log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002613 SBValue expr_result;
Jim Ingham8646d3c2014-05-05 02:47:44 +00002614 ExpressionResults exe_results = eExpressionSetupError;
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002615 ValueObjectSP expr_value_sp;
2616 TargetSP target_sp(GetSP());
Jason Molendab57e4a12013-11-04 09:33:30 +00002617 StackFrame *frame = NULL;
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002618 if (target_sp)
2619 {
2620 if (expr == NULL || expr[0] == '\0')
2621 {
2622 if (log)
2623 log->Printf ("SBTarget::EvaluateExpression called with an empty expression");
2624 return expr_result;
2625 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002626
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002627 Mutex::Locker api_locker (target_sp->GetAPIMutex());
2628 ExecutionContext exe_ctx (m_opaque_sp.get());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002629
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002630 if (log)
2631 log->Printf ("SBTarget()::EvaluateExpression (expr=\"%s\")...", expr);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002632
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002633 frame = exe_ctx.GetFramePtr();
2634 Target *target = exe_ctx.GetTargetPtr();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002635
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002636 if (target)
2637 {
2638#ifdef LLDB_CONFIGURATION_DEBUG
2639 StreamString frame_description;
2640 if (frame)
2641 frame->DumpUsingSettingsFormat (&frame_description);
2642 Host::SetCrashDescriptionWithFormat ("SBTarget::EvaluateExpression (expr = \"%s\", fetch_dynamic_value = %u) %s",
2643 expr, options.GetFetchDynamicValue(), frame_description.GetString().c_str());
2644#endif
2645 exe_results = target->EvaluateExpression (expr,
2646 frame,
2647 expr_value_sp,
2648 options.ref());
2649
2650 expr_result.SetSP(expr_value_sp, options.GetFetchDynamicValue());
2651#ifdef LLDB_CONFIGURATION_DEBUG
2652 Host::SetCrashDescription (NULL);
2653#endif
2654 }
2655 else
2656 {
2657 if (log)
2658 log->Printf ("SBTarget::EvaluateExpression () => error: could not reconstruct frame object for this SBTarget.");
2659 }
2660 }
2661#ifndef LLDB_DISABLE_PYTHON
2662 if (expr_log)
2663 expr_log->Printf("** [SBTarget::EvaluateExpression] Expression result is %s, summary %s **",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002664 expr_result.GetValue(), expr_result.GetSummary());
2665
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002666 if (log)
2667 log->Printf ("SBTarget(%p)::EvaluateExpression (expr=\"%s\") => SBValue(%p) (execution result=%d)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002668 static_cast<void*>(frame), expr,
2669 static_cast<void*>(expr_value_sp.get()), exe_results);
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002670#endif
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002671
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002672 return expr_result;
2673}
2674
Greg Clayton13fbb992013-02-01 00:47:49 +00002675
2676lldb::addr_t
2677SBTarget::GetStackRedZoneSize()
2678{
2679 TargetSP target_sp(GetSP());
2680 if (target_sp)
2681 {
2682 ABISP abi_sp;
2683 ProcessSP process_sp (target_sp->GetProcessSP());
2684 if (process_sp)
2685 abi_sp = process_sp->GetABI();
2686 else
2687 abi_sp = ABI::FindPlugin(target_sp->GetArchitecture());
2688 if (abi_sp)
2689 return abi_sp->GetRedZoneSize();
2690 }
2691 return 0;
2692}
2693