blob: 52203f6b31b1067a9bc2a42bf0edc978cabded51 [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
271
272SBAttachInfo::SBAttachInfo () :
Greg Claytonecc7c0d2012-03-07 23:52:51 +0000273 m_opaque_sp (new ProcessAttachInfo())
Greg Clayton0e615682012-02-24 05:03:03 +0000274{
275}
276
277SBAttachInfo::SBAttachInfo (lldb::pid_t pid) :
Greg Claytonecc7c0d2012-03-07 23:52:51 +0000278 m_opaque_sp (new ProcessAttachInfo())
Greg Clayton0e615682012-02-24 05:03:03 +0000279{
280 m_opaque_sp->SetProcessID (pid);
281}
282
283SBAttachInfo::SBAttachInfo (const char *path, bool wait_for) :
Greg Claytonecc7c0d2012-03-07 23:52:51 +0000284 m_opaque_sp (new ProcessAttachInfo())
Greg Clayton0e615682012-02-24 05:03:03 +0000285{
286 if (path && path[0])
287 m_opaque_sp->GetExecutableFile().SetFile(path, false);
288 m_opaque_sp->SetWaitForLaunch (wait_for);
289}
290
291SBAttachInfo::SBAttachInfo (const SBAttachInfo &rhs) :
Greg Claytonecc7c0d2012-03-07 23:52:51 +0000292 m_opaque_sp (new ProcessAttachInfo())
Greg Clayton0e615682012-02-24 05:03:03 +0000293{
294 *m_opaque_sp = *rhs.m_opaque_sp;
295}
296
Greg Claytonecc7c0d2012-03-07 23:52:51 +0000297SBAttachInfo::~SBAttachInfo()
298{
299}
300
301lldb_private::ProcessAttachInfo &
302SBAttachInfo::ref ()
303{
304 return *m_opaque_sp;
305}
306
Greg Clayton0e615682012-02-24 05:03:03 +0000307SBAttachInfo &
308SBAttachInfo::operator = (const SBAttachInfo &rhs)
309{
310 if (this != &rhs)
311 *m_opaque_sp = *rhs.m_opaque_sp;
312 return *this;
313}
314
315lldb::pid_t
316SBAttachInfo::GetProcessID ()
317{
318 return m_opaque_sp->GetProcessID();
319}
320
321void
322SBAttachInfo::SetProcessID (lldb::pid_t pid)
323{
324 m_opaque_sp->SetProcessID (pid);
325}
326
327
328uint32_t
329SBAttachInfo::GetResumeCount ()
330{
331 return m_opaque_sp->GetResumeCount();
332}
333
334void
335SBAttachInfo::SetResumeCount (uint32_t c)
336{
337 m_opaque_sp->SetResumeCount (c);
338}
339
340const char *
341SBAttachInfo::GetProcessPluginName ()
342{
343 return m_opaque_sp->GetProcessPluginName();
344}
345
346void
347SBAttachInfo::SetProcessPluginName (const char *plugin_name)
348{
349 return m_opaque_sp->SetProcessPluginName (plugin_name);
350}
351
352void
353SBAttachInfo::SetExecutable (const char *path)
354{
355 if (path && path[0])
356 m_opaque_sp->GetExecutableFile().SetFile(path, false);
357 else
358 m_opaque_sp->GetExecutableFile().Clear();
359}
360
361void
362SBAttachInfo::SetExecutable (SBFileSpec exe_file)
363{
364 if (exe_file.IsValid())
365 m_opaque_sp->GetExecutableFile() = exe_file.ref();
366 else
367 m_opaque_sp->GetExecutableFile().Clear();
368}
369
370bool
371SBAttachInfo::GetWaitForLaunch ()
372{
373 return m_opaque_sp->GetWaitForLaunch();
374}
375
376void
377SBAttachInfo::SetWaitForLaunch (bool b)
378{
379 m_opaque_sp->SetWaitForLaunch (b);
380}
381
Jim Inghamcd16df92012-07-20 21:37:13 +0000382bool
383SBAttachInfo::GetIgnoreExisting ()
384{
385 return m_opaque_sp->GetIgnoreExisting();
386}
387
388void
389SBAttachInfo::SetIgnoreExisting (bool b)
390{
391 m_opaque_sp->SetIgnoreExisting (b);
392}
393
Greg Clayton0e615682012-02-24 05:03:03 +0000394uint32_t
Greg Clayton41bd8ac2012-02-24 23:56:06 +0000395SBAttachInfo::GetUserID()
396{
397 return m_opaque_sp->GetUserID();
398}
399
400uint32_t
401SBAttachInfo::GetGroupID()
402{
403 return m_opaque_sp->GetGroupID();
404}
405
406bool
407SBAttachInfo::UserIDIsValid ()
408{
409 return m_opaque_sp->UserIDIsValid();
410}
411
412bool
413SBAttachInfo::GroupIDIsValid ()
414{
415 return m_opaque_sp->GroupIDIsValid();
416}
417
418void
419SBAttachInfo::SetUserID (uint32_t uid)
420{
421 m_opaque_sp->SetUserID (uid);
422}
423
424void
425SBAttachInfo::SetGroupID (uint32_t gid)
426{
427 m_opaque_sp->SetGroupID (gid);
428}
429
430uint32_t
Greg Clayton0e615682012-02-24 05:03:03 +0000431SBAttachInfo::GetEffectiveUserID()
432{
433 return m_opaque_sp->GetEffectiveUserID();
434}
435
436uint32_t
437SBAttachInfo::GetEffectiveGroupID()
438{
439 return m_opaque_sp->GetEffectiveGroupID();
440}
441
442bool
443SBAttachInfo::EffectiveUserIDIsValid ()
444{
445 return m_opaque_sp->EffectiveUserIDIsValid();
446}
447
448bool
449SBAttachInfo::EffectiveGroupIDIsValid ()
450{
451 return m_opaque_sp->EffectiveGroupIDIsValid ();
452}
453
454void
455SBAttachInfo::SetEffectiveUserID (uint32_t uid)
456{
457 m_opaque_sp->SetEffectiveUserID(uid);
458}
459
460void
461SBAttachInfo::SetEffectiveGroupID (uint32_t gid)
462{
463 m_opaque_sp->SetEffectiveGroupID(gid);
464}
465
466lldb::pid_t
467SBAttachInfo::GetParentProcessID ()
468{
469 return m_opaque_sp->GetParentProcessID();
470}
471
472void
473SBAttachInfo::SetParentProcessID (lldb::pid_t pid)
474{
475 m_opaque_sp->SetParentProcessID (pid);
476}
477
478bool
479SBAttachInfo::ParentProcessIDIsValid()
480{
481 return m_opaque_sp->ParentProcessIDIsValid();
482}
483
484
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000485//----------------------------------------------------------------------
486// SBTarget constructor
487//----------------------------------------------------------------------
Greg Clayton54979cd2010-12-15 05:08:08 +0000488SBTarget::SBTarget () :
489 m_opaque_sp ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000490{
491}
492
493SBTarget::SBTarget (const SBTarget& rhs) :
Greg Clayton66111032010-06-23 01:19:29 +0000494 m_opaque_sp (rhs.m_opaque_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000495{
496}
497
498SBTarget::SBTarget(const TargetSP& target_sp) :
Greg Clayton66111032010-06-23 01:19:29 +0000499 m_opaque_sp (target_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000500{
501}
502
Greg Claytonefabb122010-11-05 23:17:00 +0000503const SBTarget&
504SBTarget::operator = (const SBTarget& rhs)
505{
506 if (this != &rhs)
507 m_opaque_sp = rhs.m_opaque_sp;
508 return *this;
509}
510
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000511//----------------------------------------------------------------------
512// Destructor
513//----------------------------------------------------------------------
514SBTarget::~SBTarget()
515{
516}
517
Jim Ingham4bddaeb2012-02-16 06:50:00 +0000518const char *
519SBTarget::GetBroadcasterClassName ()
520{
521 return Target::GetStaticBroadcasterClass().AsCString();
522}
523
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000524bool
525SBTarget::IsValid () const
526{
Filipe Cabecinhas721ba3f2012-05-19 09:59:08 +0000527 return m_opaque_sp.get() != NULL && m_opaque_sp->IsValid();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000528}
529
530SBProcess
531SBTarget::GetProcess ()
532{
533 SBProcess sb_process;
Greg Claytonb9556ac2012-01-30 07:41:31 +0000534 ProcessSP process_sp;
Greg Claytonacdbe812012-01-30 09:04:36 +0000535 TargetSP target_sp(GetSP());
536 if (target_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000537 {
Greg Claytonacdbe812012-01-30 09:04:36 +0000538 process_sp = target_sp->GetProcessSP();
Greg Claytonb9556ac2012-01-30 07:41:31 +0000539 sb_process.SetSP (process_sp);
Greg Claytonaf67cec2010-12-20 20:49:23 +0000540 }
Caroline Ticeceb6b132010-10-26 03:11:13 +0000541
Greg Clayton5160ce52013-03-27 23:08:40 +0000542 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000543 if (log)
544 {
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000545 log->Printf ("SBTarget(%p)::GetProcess () => SBProcess(%p)",
Greg Claytonacdbe812012-01-30 09:04:36 +0000546 target_sp.get(), process_sp.get());
Caroline Ticeceb6b132010-10-26 03:11:13 +0000547 }
548
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000549 return sb_process;
550}
551
Greg Clayton66111032010-06-23 01:19:29 +0000552SBDebugger
553SBTarget::GetDebugger () const
554{
555 SBDebugger debugger;
Greg Claytonacdbe812012-01-30 09:04:36 +0000556 TargetSP target_sp(GetSP());
557 if (target_sp)
558 debugger.reset (target_sp->GetDebugger().shared_from_this());
Greg Clayton66111032010-06-23 01:19:29 +0000559 return debugger;
560}
561
Jim Ingham270684d2011-03-31 00:01:24 +0000562SBProcess
Greg Clayton4d8ad552013-03-25 22:40:51 +0000563SBTarget::LoadCore (const char *core_file)
564{
565 SBProcess sb_process;
566 TargetSP target_sp(GetSP());
567 if (target_sp)
568 {
569 FileSpec filespec(core_file, true);
570 ProcessSP process_sp (target_sp->CreateProcess(target_sp->GetDebugger().GetListener(),
571 NULL,
572 &filespec));
573 if (process_sp)
574 {
575 process_sp->LoadCore();
576 sb_process.SetSP (process_sp);
577 }
578 }
579 return sb_process;
580}
581
582SBProcess
Jim Ingham270684d2011-03-31 00:01:24 +0000583SBTarget::LaunchSimple
584(
585 char const **argv,
586 char const **envp,
587 const char *working_directory
588)
589{
590 char *stdin_path = NULL;
591 char *stdout_path = NULL;
592 char *stderr_path = NULL;
593 uint32_t launch_flags = 0;
594 bool stop_at_entry = false;
595 SBError error;
596 SBListener listener = GetDebugger().GetListener();
597 return Launch (listener,
598 argv,
599 envp,
600 stdin_path,
601 stdout_path,
602 stderr_path,
603 working_directory,
604 launch_flags,
605 stop_at_entry,
606 error);
607}
Greg Claytonbd82a5d2011-01-23 05:56:20 +0000608
Greg Claytonfbb76342013-11-20 21:07:01 +0000609SBError
610SBTarget::Install()
611{
612 SBError sb_error;
613 TargetSP target_sp(GetSP());
614 if (target_sp)
615 {
616 Mutex::Locker api_locker (target_sp->GetAPIMutex());
617 sb_error.ref() = target_sp->Install(NULL);
618 }
619 return sb_error;
620}
621
Greg Claytonbd82a5d2011-01-23 05:56:20 +0000622SBProcess
623SBTarget::Launch
624(
Greg Clayton4b045622011-02-03 21:28:34 +0000625 SBListener &listener,
Greg Claytonbd82a5d2011-01-23 05:56:20 +0000626 char const **argv,
627 char const **envp,
628 const char *stdin_path,
629 const char *stdout_path,
630 const char *stderr_path,
631 const char *working_directory,
632 uint32_t launch_flags, // See LaunchFlags
633 bool stop_at_entry,
634 lldb::SBError& error
635)
636{
Greg Clayton5160ce52013-03-27 23:08:40 +0000637 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000638
Greg Claytonacdbe812012-01-30 09:04:36 +0000639 SBProcess sb_process;
640 ProcessSP process_sp;
641 TargetSP target_sp(GetSP());
642
Caroline Ticeceb6b132010-10-26 03:11:13 +0000643 if (log)
Greg Clayton93aa84e2010-10-29 04:59:35 +0000644 {
Greg Claytonbd82a5d2011-01-23 05:56:20 +0000645 log->Printf ("SBTarget(%p)::Launch (argv=%p, envp=%p, stdin=%s, stdout=%s, stderr=%s, working-dir=%s, launch_flags=0x%x, stop_at_entry=%i, &error (%p))...",
Greg Claytonacdbe812012-01-30 09:04:36 +0000646 target_sp.get(),
Greg Claytonbd82a5d2011-01-23 05:56:20 +0000647 argv,
648 envp,
649 stdin_path ? stdin_path : "NULL",
650 stdout_path ? stdout_path : "NULL",
651 stderr_path ? stderr_path : "NULL",
652 working_directory ? working_directory : "NULL",
653 launch_flags,
654 stop_at_entry,
655 error.get());
Greg Clayton93aa84e2010-10-29 04:59:35 +0000656 }
Greg Claytonacdbe812012-01-30 09:04:36 +0000657
658 if (target_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000659 {
Greg Claytonacdbe812012-01-30 09:04:36 +0000660 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton5d5028b2010-10-06 03:53:16 +0000661
Greg Clayton645bf542011-01-27 01:01:10 +0000662 if (getenv("LLDB_LAUNCH_FLAG_DISABLE_ASLR"))
663 launch_flags |= eLaunchFlagDisableASLR;
664
Greg Clayton2289fa42011-04-30 01:09:13 +0000665 StateType state = eStateInvalid;
Greg Claytonacdbe812012-01-30 09:04:36 +0000666 process_sp = target_sp->GetProcessSP();
Greg Claytonb9556ac2012-01-30 07:41:31 +0000667 if (process_sp)
Greg Clayton931180e2011-01-27 06:44:37 +0000668 {
Greg Claytonb9556ac2012-01-30 07:41:31 +0000669 state = process_sp->GetState();
Greg Clayton2289fa42011-04-30 01:09:13 +0000670
Greg Claytonb9556ac2012-01-30 07:41:31 +0000671 if (process_sp->IsAlive() && state != eStateConnected)
Greg Clayton2289fa42011-04-30 01:09:13 +0000672 {
673 if (state == eStateAttaching)
674 error.SetErrorString ("process attach is in progress");
675 else
676 error.SetErrorString ("a process is already being debugged");
Greg Clayton2289fa42011-04-30 01:09:13 +0000677 return sb_process;
678 }
Greg Clayton931180e2011-01-27 06:44:37 +0000679 }
680
Greg Clayton2289fa42011-04-30 01:09:13 +0000681 if (state == eStateConnected)
682 {
683 // If we are already connected, then we have already specified the
684 // listener, so if a valid listener is supplied, we need to error out
685 // to let the client know.
686 if (listener.IsValid())
687 {
688 error.SetErrorString ("process is connected and already has a listener, pass empty listener");
Greg Clayton2289fa42011-04-30 01:09:13 +0000689 return sb_process;
690 }
691 }
Greg Claytonb09c5382013-12-13 17:20:18 +0000692
693 if (getenv("LLDB_LAUNCH_FLAG_DISABLE_STDIO"))
694 launch_flags |= eLaunchFlagDisableSTDIO;
695
696 ProcessLaunchInfo launch_info (stdin_path, stdout_path, stderr_path, working_directory, launch_flags);
697
698 Module *exe_module = target_sp->GetExecutableModulePointer();
699 if (exe_module)
700 launch_info.SetExecutableFile(exe_module->GetPlatformFileSpec(), true);
701 if (argv)
702 launch_info.GetArguments().AppendArguments (argv);
703 if (envp)
704 launch_info.GetEnvironmentEntries ().SetArguments (envp);
705
706 if (listener.IsValid())
707 error.SetError (target_sp->Launch(listener.ref(), launch_info));
Greg Clayton2289fa42011-04-30 01:09:13 +0000708 else
Greg Claytonb09c5382013-12-13 17:20:18 +0000709 error.SetError (target_sp->Launch(target_sp->GetDebugger().GetListener(), launch_info));
Greg Clayton645bf542011-01-27 01:01:10 +0000710
Greg Claytonb09c5382013-12-13 17:20:18 +0000711 sb_process.SetSP(target_sp->GetProcessSP());
Greg Clayton524e60b2010-10-06 22:10:17 +0000712 }
713 else
714 {
715 error.SetErrorString ("SBTarget is invalid");
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000716 }
Caroline Ticeceb6b132010-10-26 03:11:13 +0000717
Caroline Tice20ad3c42010-10-29 21:48:37 +0000718 log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
Caroline Ticeceb6b132010-10-26 03:11:13 +0000719 if (log)
720 {
Sean Callanan575a4542012-10-20 00:21:31 +0000721 log->Printf ("SBTarget(%p)::Launch (...) => SBProcess(%p)",
Greg Claytonb09c5382013-12-13 17:20:18 +0000722 target_sp.get(), sb_process.GetSP().get());
Caroline Ticeceb6b132010-10-26 03:11:13 +0000723 }
724
Greg Clayton5d5028b2010-10-06 03:53:16 +0000725 return sb_process;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000726}
727
Greg Clayton0e615682012-02-24 05:03:03 +0000728SBProcess
729SBTarget::Launch (SBLaunchInfo &sb_launch_info, SBError& error)
730{
Greg Clayton5160ce52013-03-27 23:08:40 +0000731 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton0e615682012-02-24 05:03:03 +0000732
733 SBProcess sb_process;
Greg Clayton0e615682012-02-24 05:03:03 +0000734 TargetSP target_sp(GetSP());
735
736 if (log)
737 {
738 log->Printf ("SBTarget(%p)::Launch (launch_info, error)...", target_sp.get());
739 }
740
741 if (target_sp)
742 {
743 Mutex::Locker api_locker (target_sp->GetAPIMutex());
744 StateType state = eStateInvalid;
Greg Claytonb09c5382013-12-13 17:20:18 +0000745 {
746 ProcessSP process_sp = target_sp->GetProcessSP();
Greg Clayton0e615682012-02-24 05:03:03 +0000747 if (process_sp)
748 {
749 state = process_sp->GetState();
750
751 if (process_sp->IsAlive() && state != eStateConnected)
752 {
753 if (state == eStateAttaching)
754 error.SetErrorString ("process attach is in progress");
755 else
756 error.SetErrorString ("a process is already being debugged");
757 return sb_process;
758 }
759 }
Greg Clayton0e615682012-02-24 05:03:03 +0000760 }
Greg Claytonb09c5382013-12-13 17:20:18 +0000761
762 lldb_private::ProcessLaunchInfo &launch_info = sb_launch_info.ref();
763
764 Module *exe_module = target_sp->GetExecutableModulePointer();
765 if (exe_module)
766 launch_info.SetExecutableFile(exe_module->GetPlatformFileSpec(), true);
767
768 const ArchSpec &arch_spec = target_sp->GetArchitecture();
769 if (arch_spec.IsValid())
770 launch_info.GetArchitecture () = arch_spec;
771
772 error.SetError (target_sp->Launch (target_sp->GetDebugger().GetListener(), launch_info));
773 sb_process.SetSP(target_sp->GetProcessSP());
Greg Clayton0e615682012-02-24 05:03:03 +0000774 }
775 else
776 {
777 error.SetErrorString ("SBTarget is invalid");
778 }
779
780 log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
781 if (log)
782 {
Greg Claytonb09c5382013-12-13 17:20:18 +0000783 log->Printf ("SBTarget(%p)::Launch (...) => SBProcess(%p)",
784 target_sp.get(), sb_process.GetSP().get());
Greg Clayton0e615682012-02-24 05:03:03 +0000785 }
786
787 return sb_process;
788}
789
790lldb::SBProcess
791SBTarget::Attach (SBAttachInfo &sb_attach_info, SBError& error)
792{
Greg Clayton5160ce52013-03-27 23:08:40 +0000793 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Sean Callanan575a4542012-10-20 00:21:31 +0000794
Greg Clayton0e615682012-02-24 05:03:03 +0000795 SBProcess sb_process;
796 ProcessSP process_sp;
797 TargetSP target_sp(GetSP());
Sean Callanan575a4542012-10-20 00:21:31 +0000798
799 if (log)
800 {
801 log->Printf ("SBTarget(%p)::Attach (sb_attach_info, error)...", target_sp.get());
802 }
803
Greg Clayton0e615682012-02-24 05:03:03 +0000804 if (target_sp)
805 {
806 Mutex::Locker api_locker (target_sp->GetAPIMutex());
807
808 StateType state = eStateInvalid;
809 process_sp = target_sp->GetProcessSP();
810 if (process_sp)
811 {
812 state = process_sp->GetState();
813
814 if (process_sp->IsAlive() && state != eStateConnected)
815 {
816 if (state == eStateAttaching)
817 error.SetErrorString ("process attach is in progress");
818 else
819 error.SetErrorString ("a process is already being debugged");
Sean Callanan575a4542012-10-20 00:21:31 +0000820 if (log)
821 {
822 log->Printf ("SBTarget(%p)::Attach (...) => error %s",
823 target_sp.get(), error.GetCString());
824 }
Greg Clayton0e615682012-02-24 05:03:03 +0000825 return sb_process;
826 }
827 }
828
829 if (state != eStateConnected)
830 process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener(), NULL, NULL);
831
832 if (process_sp)
833 {
Greg Clayton0e615682012-02-24 05:03:03 +0000834 ProcessAttachInfo &attach_info = sb_attach_info.ref();
Han Ming Ongfbd8de82013-03-25 20:11:18 +0000835 if (attach_info.ProcessIDIsValid() && !attach_info.UserIDIsValid())
Han Ming Ongcec8c902012-02-29 00:12:56 +0000836 {
837 PlatformSP platform_sp = target_sp->GetPlatform();
Greg Clayton91e407e2012-09-27 00:03:39 +0000838 // See if we can pre-verify if a process exists or not
839 if (platform_sp && platform_sp->IsConnected())
Han Ming Ongcec8c902012-02-29 00:12:56 +0000840 {
Han Ming Ongfbd8de82013-03-25 20:11:18 +0000841 lldb::pid_t attach_pid = attach_info.GetProcessID();
Greg Clayton91e407e2012-09-27 00:03:39 +0000842 ProcessInstanceInfo instance_info;
843 if (platform_sp->GetProcessInfo(attach_pid, instance_info))
844 {
845 attach_info.SetUserID(instance_info.GetEffectiveUserID());
846 }
847 else
848 {
Daniel Malead01b2952012-11-29 21:49:15 +0000849 error.ref().SetErrorStringWithFormat("no process found with process ID %" PRIu64, attach_pid);
Sean Callanan575a4542012-10-20 00:21:31 +0000850 if (log)
851 {
852 log->Printf ("SBTarget(%p)::Attach (...) => error %s",
853 target_sp.get(), error.GetCString());
854 }
Greg Clayton91e407e2012-09-27 00:03:39 +0000855 return sb_process;
856 }
Han Ming Ongcec8c902012-02-29 00:12:56 +0000857 }
858 }
Han Ming Ongbee98392012-02-29 19:16:40 +0000859 error.SetError (process_sp->Attach (attach_info));
860 if (error.Success())
861 {
862 sb_process.SetSP (process_sp);
863 // If we are doing synchronous mode, then wait for the
864 // process to stop!
865 if (target_sp->GetDebugger().GetAsyncExecution () == false)
866 process_sp->WaitForProcessToStop (NULL);
867 }
Greg Clayton0e615682012-02-24 05:03:03 +0000868 }
869 else
870 {
871 error.SetErrorString ("unable to create lldb_private::Process");
872 }
873 }
874 else
875 {
876 error.SetErrorString ("SBTarget is invalid");
877 }
Sean Callanan575a4542012-10-20 00:21:31 +0000878
879 if (log)
880 {
881 log->Printf ("SBTarget(%p)::Attach (...) => SBProcess(%p)",
882 target_sp.get(), process_sp.get());
883 }
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)
916 {
Daniel Malead01b2952012-11-29 21:49:15 +0000917 log->Printf ("SBTarget(%p)::AttachToProcessWithID (listener, pid=%" PRId64 ", error)...", target_sp.get(), pid);
Sean Callanan575a4542012-10-20 00:21:31 +0000918 }
919
Greg Claytonacdbe812012-01-30 09:04:36 +0000920 if (target_sp)
Greg Clayton524e60b2010-10-06 22:10:17 +0000921 {
Greg Claytonacdbe812012-01-30 09:04:36 +0000922 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton0c74e782011-06-24 03:21:43 +0000923
924 StateType state = eStateInvalid;
Greg Claytonacdbe812012-01-30 09:04:36 +0000925 process_sp = target_sp->GetProcessSP();
Greg Claytonb9556ac2012-01-30 07:41:31 +0000926 if (process_sp)
Greg Clayton0c74e782011-06-24 03:21:43 +0000927 {
Greg Claytonb9556ac2012-01-30 07:41:31 +0000928 state = process_sp->GetState();
Greg Clayton0c74e782011-06-24 03:21:43 +0000929
Greg Claytonb9556ac2012-01-30 07:41:31 +0000930 if (process_sp->IsAlive() && state != eStateConnected)
Greg Clayton0c74e782011-06-24 03:21:43 +0000931 {
932 if (state == eStateAttaching)
933 error.SetErrorString ("process attach is in progress");
934 else
935 error.SetErrorString ("a process is already being debugged");
Greg Clayton0c74e782011-06-24 03:21:43 +0000936 return sb_process;
937 }
938 }
939
940 if (state == eStateConnected)
941 {
942 // If we are already connected, then we have already specified the
943 // listener, so if a valid listener is supplied, we need to error out
944 // to let the client know.
945 if (listener.IsValid())
946 {
947 error.SetErrorString ("process is connected and already has a listener, pass empty listener");
Greg Clayton0c74e782011-06-24 03:21:43 +0000948 return sb_process;
949 }
950 }
Greg Clayton4b045622011-02-03 21:28:34 +0000951 else
Greg Clayton0c74e782011-06-24 03:21:43 +0000952 {
953 if (listener.IsValid())
Greg Claytonc3776bf2012-02-09 06:16:32 +0000954 process_sp = target_sp->CreateProcess (listener.ref(), NULL, NULL);
Greg Clayton0c74e782011-06-24 03:21:43 +0000955 else
Greg Claytonc3776bf2012-02-09 06:16:32 +0000956 process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener(), NULL, NULL);
Greg Clayton0c74e782011-06-24 03:21:43 +0000957 }
Greg Claytonb9556ac2012-01-30 07:41:31 +0000958 if (process_sp)
Greg Clayton524e60b2010-10-06 22:10:17 +0000959 {
Greg Claytonb9556ac2012-01-30 07:41:31 +0000960 sb_process.SetSP (process_sp);
961
Greg Clayton144f3a92011-11-15 03:53:30 +0000962 ProcessAttachInfo attach_info;
963 attach_info.SetProcessID (pid);
Han Ming Ong84647042012-02-25 01:07:38 +0000964
965 PlatformSP platform_sp = target_sp->GetPlatform();
966 ProcessInstanceInfo instance_info;
967 if (platform_sp->GetProcessInfo(pid, instance_info))
968 {
969 attach_info.SetUserID(instance_info.GetEffectiveUserID());
Han Ming Ong84647042012-02-25 01:07:38 +0000970 }
Greg Claytonb9556ac2012-01-30 07:41:31 +0000971 error.SetError (process_sp->Attach (attach_info));
Greg Claytone2186ed2012-09-07 17:51:47 +0000972 if (error.Success())
973 {
974 // If we are doing synchronous mode, then wait for the
975 // process to stop!
976 if (target_sp->GetDebugger().GetAsyncExecution () == false)
Greg Claytonb9556ac2012-01-30 07:41:31 +0000977 process_sp->WaitForProcessToStop (NULL);
Greg Claytone2186ed2012-09-07 17:51:47 +0000978 }
Greg Clayton524e60b2010-10-06 22:10:17 +0000979 }
980 else
981 {
982 error.SetErrorString ("unable to create lldb_private::Process");
983 }
984 }
985 else
986 {
987 error.SetErrorString ("SBTarget is invalid");
988 }
Sean Callanan575a4542012-10-20 00:21:31 +0000989
990 if (log)
991 {
992 log->Printf ("SBTarget(%p)::AttachToProcessWithID (...) => SBProcess(%p)",
993 target_sp.get(), process_sp.get());
994 }
Greg Clayton524e60b2010-10-06 22:10:17 +0000995 return sb_process;
Greg Clayton524e60b2010-10-06 22:10:17 +0000996}
997
998lldb::SBProcess
Greg Clayton05faeb72010-10-07 04:19:01 +0000999SBTarget::AttachToProcessWithName
Greg Clayton524e60b2010-10-06 22:10:17 +00001000(
Greg Clayton4b045622011-02-03 21:28:34 +00001001 SBListener &listener,
Greg Clayton524e60b2010-10-06 22:10:17 +00001002 const char *name, // basename of process to attach to
1003 bool wait_for, // if true wait for a new instance of "name" to be launched
1004 SBError& error // An error explaining what went wrong if attach fails
1005)
1006{
Greg Clayton5160ce52013-03-27 23:08:40 +00001007 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Sean Callanan575a4542012-10-20 00:21:31 +00001008
Greg Clayton524e60b2010-10-06 22:10:17 +00001009 SBProcess sb_process;
Greg Claytonb9556ac2012-01-30 07:41:31 +00001010 ProcessSP process_sp;
Greg Claytonacdbe812012-01-30 09:04:36 +00001011 TargetSP target_sp(GetSP());
Sean Callanan575a4542012-10-20 00:21:31 +00001012
1013 if (log)
1014 {
1015 log->Printf ("SBTarget(%p)::AttachToProcessWithName (listener, name=%s, wait_for=%s, error)...", target_sp.get(), name, wait_for ? "true" : "false");
1016 }
1017
Greg Claytonacdbe812012-01-30 09:04:36 +00001018 if (name && target_sp)
Greg Clayton524e60b2010-10-06 22:10:17 +00001019 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001020 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytonaf67cec2010-12-20 20:49:23 +00001021
Greg Clayton0c74e782011-06-24 03:21:43 +00001022 StateType state = eStateInvalid;
Greg Claytonacdbe812012-01-30 09:04:36 +00001023 process_sp = target_sp->GetProcessSP();
Greg Claytonb9556ac2012-01-30 07:41:31 +00001024 if (process_sp)
Greg Clayton0c74e782011-06-24 03:21:43 +00001025 {
Greg Claytonb9556ac2012-01-30 07:41:31 +00001026 state = process_sp->GetState();
Greg Clayton0c74e782011-06-24 03:21:43 +00001027
Greg Claytonb9556ac2012-01-30 07:41:31 +00001028 if (process_sp->IsAlive() && state != eStateConnected)
Greg Clayton0c74e782011-06-24 03:21:43 +00001029 {
1030 if (state == eStateAttaching)
1031 error.SetErrorString ("process attach is in progress");
1032 else
1033 error.SetErrorString ("a process is already being debugged");
Greg Clayton0c74e782011-06-24 03:21:43 +00001034 return sb_process;
1035 }
1036 }
1037
1038 if (state == eStateConnected)
1039 {
1040 // If we are already connected, then we have already specified the
1041 // listener, so if a valid listener is supplied, we need to error out
1042 // to let the client know.
1043 if (listener.IsValid())
1044 {
1045 error.SetErrorString ("process is connected and already has a listener, pass empty listener");
Greg Clayton0c74e782011-06-24 03:21:43 +00001046 return sb_process;
1047 }
1048 }
Greg Clayton4b045622011-02-03 21:28:34 +00001049 else
Greg Clayton0c74e782011-06-24 03:21:43 +00001050 {
1051 if (listener.IsValid())
Greg Claytonc3776bf2012-02-09 06:16:32 +00001052 process_sp = target_sp->CreateProcess (listener.ref(), NULL, NULL);
Greg Clayton0c74e782011-06-24 03:21:43 +00001053 else
Greg Claytonc3776bf2012-02-09 06:16:32 +00001054 process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener(), NULL, NULL);
Greg Clayton0c74e782011-06-24 03:21:43 +00001055 }
Greg Clayton524e60b2010-10-06 22:10:17 +00001056
Greg Claytonb9556ac2012-01-30 07:41:31 +00001057 if (process_sp)
Greg Clayton524e60b2010-10-06 22:10:17 +00001058 {
Greg Claytonb9556ac2012-01-30 07:41:31 +00001059 sb_process.SetSP (process_sp);
Greg Clayton144f3a92011-11-15 03:53:30 +00001060 ProcessAttachInfo attach_info;
1061 attach_info.GetExecutableFile().SetFile(name, false);
1062 attach_info.SetWaitForLaunch(wait_for);
Greg Claytonb9556ac2012-01-30 07:41:31 +00001063 error.SetError (process_sp->Attach (attach_info));
Daniel Malead659dc12013-04-01 19:47:00 +00001064 if (error.Success())
1065 {
1066 // If we are doing synchronous mode, then wait for the
1067 // process to stop!
1068 if (target_sp->GetDebugger().GetAsyncExecution () == false)
1069 process_sp->WaitForProcessToStop (NULL);
1070 }
Greg Clayton524e60b2010-10-06 22:10:17 +00001071 }
1072 else
1073 {
1074 error.SetErrorString ("unable to create lldb_private::Process");
1075 }
1076 }
1077 else
1078 {
1079 error.SetErrorString ("SBTarget is invalid");
1080 }
Sean Callanan575a4542012-10-20 00:21:31 +00001081
1082 if (log)
1083 {
1084 log->Printf ("SBTarget(%p)::AttachToPorcessWithName (...) => SBProcess(%p)",
1085 target_sp.get(), process_sp.get());
1086 }
Greg Clayton524e60b2010-10-06 22:10:17 +00001087 return sb_process;
Greg Clayton524e60b2010-10-06 22:10:17 +00001088}
1089
James McIlree9631aae2011-03-04 00:31:13 +00001090lldb::SBProcess
1091SBTarget::ConnectRemote
1092(
1093 SBListener &listener,
1094 const char *url,
1095 const char *plugin_name,
1096 SBError& error
1097)
1098{
Greg Clayton5160ce52013-03-27 23:08:40 +00001099 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Sean Callanan575a4542012-10-20 00:21:31 +00001100
James McIlree9631aae2011-03-04 00:31:13 +00001101 SBProcess sb_process;
Greg Claytonb9556ac2012-01-30 07:41:31 +00001102 ProcessSP process_sp;
Greg Claytonacdbe812012-01-30 09:04:36 +00001103 TargetSP target_sp(GetSP());
Sean Callanan575a4542012-10-20 00:21:31 +00001104
1105 if (log)
1106 {
1107 log->Printf ("SBTarget(%p)::ConnectRemote (listener, url=%s, plugin_name=%s, error)...", target_sp.get(), url, plugin_name);
1108 }
1109
Greg Claytonacdbe812012-01-30 09:04:36 +00001110 if (target_sp)
James McIlree9631aae2011-03-04 00:31:13 +00001111 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001112 Mutex::Locker api_locker (target_sp->GetAPIMutex());
James McIlree9631aae2011-03-04 00:31:13 +00001113 if (listener.IsValid())
Greg Claytonc3776bf2012-02-09 06:16:32 +00001114 process_sp = target_sp->CreateProcess (listener.ref(), plugin_name, NULL);
James McIlree9631aae2011-03-04 00:31:13 +00001115 else
Greg Claytonc3776bf2012-02-09 06:16:32 +00001116 process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener(), plugin_name, NULL);
James McIlree9631aae2011-03-04 00:31:13 +00001117
1118
Greg Claytonb9556ac2012-01-30 07:41:31 +00001119 if (process_sp)
James McIlree9631aae2011-03-04 00:31:13 +00001120 {
Greg Claytonb9556ac2012-01-30 07:41:31 +00001121 sb_process.SetSP (process_sp);
Jason Molenda4bd4e7e2012-09-29 04:02:01 +00001122 error.SetError (process_sp->ConnectRemote (NULL, url));
James McIlree9631aae2011-03-04 00:31:13 +00001123 }
1124 else
1125 {
1126 error.SetErrorString ("unable to create lldb_private::Process");
1127 }
1128 }
1129 else
1130 {
1131 error.SetErrorString ("SBTarget is invalid");
1132 }
Sean Callanan575a4542012-10-20 00:21:31 +00001133
1134 if (log)
1135 {
1136 log->Printf ("SBTarget(%p)::ConnectRemote (...) => SBProcess(%p)",
1137 target_sp.get(), process_sp.get());
1138 }
James McIlree9631aae2011-03-04 00:31:13 +00001139 return sb_process;
1140}
1141
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001142SBFileSpec
1143SBTarget::GetExecutable ()
1144{
Caroline Ticeceb6b132010-10-26 03:11:13 +00001145
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001146 SBFileSpec exe_file_spec;
Greg Claytonacdbe812012-01-30 09:04:36 +00001147 TargetSP target_sp(GetSP());
1148 if (target_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001149 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001150 Module *exe_module = target_sp->GetExecutableModulePointer();
Greg Claytonaa149cb2011-08-11 02:48:45 +00001151 if (exe_module)
1152 exe_file_spec.SetFileSpec (exe_module->GetFileSpec());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001153 }
Caroline Ticeceb6b132010-10-26 03:11:13 +00001154
Greg Clayton5160ce52013-03-27 23:08:40 +00001155 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001156 if (log)
1157 {
Greg Claytoncfd1ace2010-10-31 03:01:06 +00001158 log->Printf ("SBTarget(%p)::GetExecutable () => SBFileSpec(%p)",
Greg Claytonacdbe812012-01-30 09:04:36 +00001159 target_sp.get(), exe_file_spec.get());
Caroline Ticeceb6b132010-10-26 03:11:13 +00001160 }
1161
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001162 return exe_file_spec;
1163}
1164
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001165bool
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001166SBTarget::operator == (const SBTarget &rhs) const
1167{
Greg Clayton66111032010-06-23 01:19:29 +00001168 return m_opaque_sp.get() == rhs.m_opaque_sp.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001169}
1170
1171bool
1172SBTarget::operator != (const SBTarget &rhs) const
1173{
Greg Clayton66111032010-06-23 01:19:29 +00001174 return m_opaque_sp.get() != rhs.m_opaque_sp.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001175}
1176
Greg Claytonb9556ac2012-01-30 07:41:31 +00001177lldb::TargetSP
1178SBTarget::GetSP () const
Greg Clayton9a377662011-10-01 02:59:24 +00001179{
1180 return m_opaque_sp;
1181}
1182
Greg Clayton66111032010-06-23 01:19:29 +00001183void
Greg Claytonb9556ac2012-01-30 07:41:31 +00001184SBTarget::SetSP (const lldb::TargetSP& target_sp)
Greg Clayton66111032010-06-23 01:19:29 +00001185{
1186 m_opaque_sp = target_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001187}
1188
Greg Clayton00e6fbf2011-07-22 16:46:35 +00001189lldb::SBAddress
1190SBTarget::ResolveLoadAddress (lldb::addr_t vm_addr)
Greg Claytonac2eb9b2010-12-12 19:25:26 +00001191{
Greg Clayton00e6fbf2011-07-22 16:46:35 +00001192 lldb::SBAddress sb_addr;
1193 Address &addr = sb_addr.ref();
Greg Claytonacdbe812012-01-30 09:04:36 +00001194 TargetSP target_sp(GetSP());
1195 if (target_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +00001196 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001197 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytond5944cd2013-12-06 01:12:00 +00001198 if (target_sp->ResolveLoadAddress (vm_addr, addr))
Greg Clayton00e6fbf2011-07-22 16:46:35 +00001199 return sb_addr;
Greg Claytonaf67cec2010-12-20 20:49:23 +00001200 }
Greg Claytonac2eb9b2010-12-12 19:25:26 +00001201
Greg Clayton00e6fbf2011-07-22 16:46:35 +00001202 // We have a load address that isn't in a section, just return an address
1203 // with the offset filled in (the address) and the section set to NULL
Greg Claytone72dfb32012-02-24 01:59:29 +00001204 addr.SetRawAddress(vm_addr);
Greg Clayton00e6fbf2011-07-22 16:46:35 +00001205 return sb_addr;
Greg Claytonac2eb9b2010-12-12 19:25:26 +00001206}
1207
Greg Claytond5944cd2013-12-06 01:12:00 +00001208
1209lldb::SBAddress
1210SBTarget::ResolvePastLoadAddress (uint32_t stop_id, lldb::addr_t vm_addr)
1211{
1212 lldb::SBAddress sb_addr;
1213 Address &addr = sb_addr.ref();
1214 TargetSP target_sp(GetSP());
1215 if (target_sp)
1216 {
1217 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1218 if (target_sp->ResolveLoadAddress (vm_addr, addr))
1219 return sb_addr;
1220 }
1221
1222 // We have a load address that isn't in a section, just return an address
1223 // with the offset filled in (the address) and the section set to NULL
1224 addr.SetRawAddress(vm_addr);
1225 return sb_addr;
1226}
1227
Greg Clayton5f2a4f92011-03-02 21:34:46 +00001228SBSymbolContext
Greg Claytoneb023e72013-10-11 19:48:25 +00001229SBTarget::ResolveSymbolContextForAddress (const SBAddress& addr,
1230 uint32_t resolve_scope)
Greg Clayton5f2a4f92011-03-02 21:34:46 +00001231{
1232 SBSymbolContext sc;
Greg Claytonacdbe812012-01-30 09:04:36 +00001233 if (addr.IsValid())
1234 {
1235 TargetSP target_sp(GetSP());
1236 if (target_sp)
1237 target_sp->GetImages().ResolveSymbolContextForAddress (addr.ref(), resolve_scope, sc.ref());
1238 }
Greg Clayton5f2a4f92011-03-02 21:34:46 +00001239 return sc;
1240}
1241
1242
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001243SBBreakpoint
Greg Claytoneb023e72013-10-11 19:48:25 +00001244SBTarget::BreakpointCreateByLocation (const char *file,
1245 uint32_t line)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001246{
Greg Clayton7481c202010-11-08 00:28:40 +00001247 return SBBreakpoint(BreakpointCreateByLocation (SBFileSpec (file, false), line));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001248}
1249
1250SBBreakpoint
Greg Claytoneb023e72013-10-11 19:48:25 +00001251SBTarget::BreakpointCreateByLocation (const SBFileSpec &sb_file_spec,
1252 uint32_t line)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001253{
Greg Clayton5160ce52013-03-27 23:08:40 +00001254 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001255
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001256 SBBreakpoint sb_bp;
Greg Claytonacdbe812012-01-30 09:04:36 +00001257 TargetSP target_sp(GetSP());
1258 if (target_sp && line != 0)
Greg Claytonaf67cec2010-12-20 20:49:23 +00001259 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001260 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Jim Inghama8558b62012-05-22 00:12:20 +00001261
Greg Clayton1f746072012-08-29 21:13:06 +00001262 const LazyBool check_inlines = eLazyBoolCalculate;
Jim Inghama8558b62012-05-22 00:12:20 +00001263 const LazyBool skip_prologue = eLazyBoolCalculate;
Greg Clayton1f746072012-08-29 21:13:06 +00001264 const bool internal = false;
Greg Claytoneb023e72013-10-11 19:48:25 +00001265 const bool hardware = false;
1266 *sb_bp = target_sp->CreateBreakpoint (NULL, *sb_file_spec, line, check_inlines, skip_prologue, internal, hardware);
Greg Claytonaf67cec2010-12-20 20:49:23 +00001267 }
Caroline Ticeceb6b132010-10-26 03:11:13 +00001268
1269 if (log)
1270 {
1271 SBStream sstr;
1272 sb_bp.GetDescription (sstr);
Greg Claytoncfd1ace2010-10-31 03:01:06 +00001273 char path[PATH_MAX];
1274 sb_file_spec->GetPath (path, sizeof(path));
1275 log->Printf ("SBTarget(%p)::BreakpointCreateByLocation ( %s:%u ) => SBBreakpoint(%p): %s",
Greg Claytonacdbe812012-01-30 09:04:36 +00001276 target_sp.get(),
Greg Claytoncfd1ace2010-10-31 03:01:06 +00001277 path,
Greg Clayton48381312010-10-30 04:51:46 +00001278 line,
Greg Claytoncfd1ace2010-10-31 03:01:06 +00001279 sb_bp.get(),
Caroline Ticeceb6b132010-10-26 03:11:13 +00001280 sstr.GetData());
1281 }
1282
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001283 return sb_bp;
1284}
1285
1286SBBreakpoint
Greg Claytoneb023e72013-10-11 19:48:25 +00001287SBTarget::BreakpointCreateByName (const char *symbol_name,
1288 const char *module_name)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001289{
Greg Clayton5160ce52013-03-27 23:08:40 +00001290 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001291
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001292 SBBreakpoint sb_bp;
Greg Claytonacdbe812012-01-30 09:04:36 +00001293 TargetSP target_sp(GetSP());
1294 if (target_sp.get())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001295 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001296 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Jim Inghama8558b62012-05-22 00:12:20 +00001297
1298 const bool internal = false;
Greg Claytoneb023e72013-10-11 19:48:25 +00001299 const bool hardware = false;
Jim Inghama8558b62012-05-22 00:12:20 +00001300 const LazyBool skip_prologue = eLazyBoolCalculate;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001301 if (module_name && module_name[0])
1302 {
Jim Ingham969795f2011-09-21 01:17:13 +00001303 FileSpecList module_spec_list;
1304 module_spec_list.Append (FileSpec (module_name, false));
Greg Claytoneb023e72013-10-11 19:48:25 +00001305 *sb_bp = target_sp->CreateBreakpoint (&module_spec_list, NULL, symbol_name, eFunctionNameTypeAuto, skip_prologue, internal, hardware);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001306 }
1307 else
1308 {
Greg Claytoneb023e72013-10-11 19:48:25 +00001309 *sb_bp = target_sp->CreateBreakpoint (NULL, NULL, symbol_name, eFunctionNameTypeAuto, skip_prologue, internal, hardware);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001310 }
1311 }
Caroline Ticeceb6b132010-10-26 03:11:13 +00001312
1313 if (log)
1314 {
Greg Claytoncfd1ace2010-10-31 03:01:06 +00001315 log->Printf ("SBTarget(%p)::BreakpointCreateByName (symbol=\"%s\", module=\"%s\") => SBBreakpoint(%p)",
Greg Claytonacdbe812012-01-30 09:04:36 +00001316 target_sp.get(), symbol_name, module_name, sb_bp.get());
Caroline Ticeceb6b132010-10-26 03:11:13 +00001317 }
1318
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001319 return sb_bp;
1320}
1321
Jim Ingham87df91b2011-09-23 00:54:11 +00001322lldb::SBBreakpoint
1323SBTarget::BreakpointCreateByName (const char *symbol_name,
Greg Claytoneb023e72013-10-11 19:48:25 +00001324 const SBFileSpecList &module_list,
1325 const SBFileSpecList &comp_unit_list)
Jim Ingham87df91b2011-09-23 00:54:11 +00001326{
Jim Ingham2dd7f7f2011-10-11 01:18:55 +00001327 uint32_t name_type_mask = eFunctionNameTypeAuto;
1328 return BreakpointCreateByName (symbol_name, name_type_mask, module_list, comp_unit_list);
1329}
1330
1331lldb::SBBreakpoint
1332SBTarget::BreakpointCreateByName (const char *symbol_name,
Greg Claytoneb023e72013-10-11 19:48:25 +00001333 uint32_t name_type_mask,
1334 const SBFileSpecList &module_list,
1335 const SBFileSpecList &comp_unit_list)
Jim Ingham2dd7f7f2011-10-11 01:18:55 +00001336{
Greg Clayton5160ce52013-03-27 23:08:40 +00001337 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Jim Ingham87df91b2011-09-23 00:54:11 +00001338
1339 SBBreakpoint sb_bp;
Greg Claytonacdbe812012-01-30 09:04:36 +00001340 TargetSP target_sp(GetSP());
1341 if (target_sp && symbol_name && symbol_name[0])
Jim Ingham87df91b2011-09-23 00:54:11 +00001342 {
Jim Inghama8558b62012-05-22 00:12:20 +00001343 const bool internal = false;
Greg Claytoneb023e72013-10-11 19:48:25 +00001344 const bool hardware = false;
Jim Inghama8558b62012-05-22 00:12:20 +00001345 const LazyBool skip_prologue = eLazyBoolCalculate;
Greg Claytonacdbe812012-01-30 09:04:36 +00001346 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1347 *sb_bp = target_sp->CreateBreakpoint (module_list.get(),
Greg Claytoneb023e72013-10-11 19:48:25 +00001348 comp_unit_list.get(),
1349 symbol_name,
1350 name_type_mask,
1351 skip_prologue,
1352 internal,
1353 hardware);
Jim Ingham87df91b2011-09-23 00:54:11 +00001354 }
1355
1356 if (log)
1357 {
Jim Ingham2dd7f7f2011-10-11 01:18:55 +00001358 log->Printf ("SBTarget(%p)::BreakpointCreateByName (symbol=\"%s\", name_type: %d) => SBBreakpoint(%p)",
Greg Claytonacdbe812012-01-30 09:04:36 +00001359 target_sp.get(), symbol_name, name_type_mask, sb_bp.get());
Jim Ingham87df91b2011-09-23 00:54:11 +00001360 }
1361
1362 return sb_bp;
1363}
1364
Jim Inghamfab10e82012-03-06 00:37:27 +00001365lldb::SBBreakpoint
1366SBTarget::BreakpointCreateByNames (const char *symbol_names[],
1367 uint32_t num_names,
1368 uint32_t name_type_mask,
1369 const SBFileSpecList &module_list,
1370 const SBFileSpecList &comp_unit_list)
1371{
Greg Clayton5160ce52013-03-27 23:08:40 +00001372 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Jim Inghamfab10e82012-03-06 00:37:27 +00001373
1374 SBBreakpoint sb_bp;
1375 TargetSP target_sp(GetSP());
1376 if (target_sp && num_names > 0)
1377 {
1378 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Jim Inghama8558b62012-05-22 00:12:20 +00001379 const bool internal = false;
Greg Claytoneb023e72013-10-11 19:48:25 +00001380 const bool hardware = false;
Jim Inghama8558b62012-05-22 00:12:20 +00001381 const LazyBool skip_prologue = eLazyBoolCalculate;
Jim Inghamfab10e82012-03-06 00:37:27 +00001382 *sb_bp = target_sp->CreateBreakpoint (module_list.get(),
1383 comp_unit_list.get(),
1384 symbol_names,
1385 num_names,
1386 name_type_mask,
Jim Inghama8558b62012-05-22 00:12:20 +00001387 skip_prologue,
Greg Claytoneb023e72013-10-11 19:48:25 +00001388 internal,
1389 hardware);
Jim Inghamfab10e82012-03-06 00:37:27 +00001390 }
1391
1392 if (log)
1393 {
1394 log->Printf ("SBTarget(%p)::BreakpointCreateByName (symbols={", target_sp.get());
1395 for (uint32_t i = 0 ; i < num_names; i++)
1396 {
1397 char sep;
1398 if (i < num_names - 1)
1399 sep = ',';
1400 else
1401 sep = '}';
1402 if (symbol_names[i] != NULL)
1403 log->Printf ("\"%s\"%c ", symbol_names[i], sep);
1404 else
1405 log->Printf ("\"<NULL>\"%c ", sep);
1406
1407 }
1408 log->Printf ("name_type: %d) => SBBreakpoint(%p)", name_type_mask, sb_bp.get());
1409 }
1410
1411 return sb_bp;
1412}
Jim Ingham87df91b2011-09-23 00:54:11 +00001413
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001414SBBreakpoint
Greg Claytoneb023e72013-10-11 19:48:25 +00001415SBTarget::BreakpointCreateByRegex (const char *symbol_name_regex,
1416 const char *module_name)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001417{
Greg Clayton5160ce52013-03-27 23:08:40 +00001418 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001419
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001420 SBBreakpoint sb_bp;
Greg Claytonacdbe812012-01-30 09:04:36 +00001421 TargetSP target_sp(GetSP());
1422 if (target_sp && symbol_name_regex && symbol_name_regex[0])
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001423 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001424 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001425 RegularExpression regexp(symbol_name_regex);
Jim Inghama8558b62012-05-22 00:12:20 +00001426 const bool internal = false;
Greg Claytoneb023e72013-10-11 19:48:25 +00001427 const bool hardware = false;
Jim Inghama8558b62012-05-22 00:12:20 +00001428 const LazyBool skip_prologue = eLazyBoolCalculate;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001429
1430 if (module_name && module_name[0])
1431 {
Jim Ingham969795f2011-09-21 01:17:13 +00001432 FileSpecList module_spec_list;
1433 module_spec_list.Append (FileSpec (module_name, false));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001434
Greg Claytoneb023e72013-10-11 19:48:25 +00001435 *sb_bp = target_sp->CreateFuncRegexBreakpoint (&module_spec_list, NULL, regexp, skip_prologue, internal, hardware);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001436 }
1437 else
1438 {
Greg Claytoneb023e72013-10-11 19:48:25 +00001439 *sb_bp = target_sp->CreateFuncRegexBreakpoint (NULL, NULL, regexp, skip_prologue, internal, hardware);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001440 }
1441 }
Caroline Ticeceb6b132010-10-26 03:11:13 +00001442
1443 if (log)
1444 {
Greg Claytoncfd1ace2010-10-31 03:01:06 +00001445 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (symbol_regex=\"%s\", module_name=\"%s\") => SBBreakpoint(%p)",
Greg Claytonacdbe812012-01-30 09:04:36 +00001446 target_sp.get(), symbol_name_regex, module_name, sb_bp.get());
Caroline Ticeceb6b132010-10-26 03:11:13 +00001447 }
1448
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001449 return sb_bp;
1450}
1451
Jim Ingham87df91b2011-09-23 00:54:11 +00001452lldb::SBBreakpoint
1453SBTarget::BreakpointCreateByRegex (const char *symbol_name_regex,
Greg Claytoneb023e72013-10-11 19:48:25 +00001454 const SBFileSpecList &module_list,
1455 const SBFileSpecList &comp_unit_list)
Jim Ingham87df91b2011-09-23 00:54:11 +00001456{
Greg Clayton5160ce52013-03-27 23:08:40 +00001457 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001458
Jim Ingham87df91b2011-09-23 00:54:11 +00001459 SBBreakpoint sb_bp;
Greg Claytonacdbe812012-01-30 09:04:36 +00001460 TargetSP target_sp(GetSP());
1461 if (target_sp && symbol_name_regex && symbol_name_regex[0])
Jim Ingham87df91b2011-09-23 00:54:11 +00001462 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001463 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Jim Ingham87df91b2011-09-23 00:54:11 +00001464 RegularExpression regexp(symbol_name_regex);
Jim Inghama8558b62012-05-22 00:12:20 +00001465 const bool internal = false;
Greg Claytoneb023e72013-10-11 19:48:25 +00001466 const bool hardware = false;
Jim Inghama8558b62012-05-22 00:12:20 +00001467 const LazyBool skip_prologue = eLazyBoolCalculate;
Jim Ingham87df91b2011-09-23 00:54:11 +00001468
Greg Claytoneb023e72013-10-11 19:48:25 +00001469 *sb_bp = target_sp->CreateFuncRegexBreakpoint (module_list.get(), comp_unit_list.get(), regexp, skip_prologue, internal, hardware);
Jim Ingham87df91b2011-09-23 00:54:11 +00001470 }
1471
1472 if (log)
1473 {
1474 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (symbol_regex=\"%s\") => SBBreakpoint(%p)",
Greg Claytonacdbe812012-01-30 09:04:36 +00001475 target_sp.get(), symbol_name_regex, sb_bp.get());
Jim Ingham87df91b2011-09-23 00:54:11 +00001476 }
1477
1478 return sb_bp;
1479}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001480
1481SBBreakpoint
1482SBTarget::BreakpointCreateByAddress (addr_t address)
1483{
Greg Clayton5160ce52013-03-27 23:08:40 +00001484 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001485
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001486 SBBreakpoint sb_bp;
Greg Claytonacdbe812012-01-30 09:04:36 +00001487 TargetSP target_sp(GetSP());
1488 if (target_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +00001489 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001490 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytoneb023e72013-10-11 19:48:25 +00001491 const bool hardware = false;
1492 *sb_bp = target_sp->CreateBreakpoint (address, false, hardware);
Greg Claytonaf67cec2010-12-20 20:49:23 +00001493 }
Caroline Ticeceb6b132010-10-26 03:11:13 +00001494
1495 if (log)
1496 {
Daniel Malead01b2952012-11-29 21:49:15 +00001497 log->Printf ("SBTarget(%p)::BreakpointCreateByAddress (address=%" PRIu64 ") => SBBreakpoint(%p)", target_sp.get(), (uint64_t) address, sb_bp.get());
Caroline Ticeceb6b132010-10-26 03:11:13 +00001498 }
1499
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001500 return sb_bp;
1501}
1502
Jim Ingham969795f2011-09-21 01:17:13 +00001503lldb::SBBreakpoint
Greg Claytoneb023e72013-10-11 19:48:25 +00001504SBTarget::BreakpointCreateBySourceRegex (const char *source_regex,
1505 const lldb::SBFileSpec &source_file,
1506 const char *module_name)
Jim Ingham969795f2011-09-21 01:17:13 +00001507{
Greg Clayton5160ce52013-03-27 23:08:40 +00001508 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Jim Ingham969795f2011-09-21 01:17:13 +00001509
1510 SBBreakpoint sb_bp;
Greg Claytonacdbe812012-01-30 09:04:36 +00001511 TargetSP target_sp(GetSP());
1512 if (target_sp && source_regex && source_regex[0])
Jim Ingham969795f2011-09-21 01:17:13 +00001513 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001514 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Jim Ingham969795f2011-09-21 01:17:13 +00001515 RegularExpression regexp(source_regex);
Jim Ingham87df91b2011-09-23 00:54:11 +00001516 FileSpecList source_file_spec_list;
Greg Claytoneb023e72013-10-11 19:48:25 +00001517 const bool hardware = false;
Jim Ingham87df91b2011-09-23 00:54:11 +00001518 source_file_spec_list.Append (source_file.ref());
Jim Ingham969795f2011-09-21 01:17:13 +00001519
1520 if (module_name && module_name[0])
1521 {
1522 FileSpecList module_spec_list;
1523 module_spec_list.Append (FileSpec (module_name, false));
1524
Greg Claytoneb023e72013-10-11 19:48:25 +00001525 *sb_bp = target_sp->CreateSourceRegexBreakpoint (&module_spec_list, &source_file_spec_list, regexp, false, hardware);
Jim Ingham969795f2011-09-21 01:17:13 +00001526 }
1527 else
1528 {
Greg Claytoneb023e72013-10-11 19:48:25 +00001529 *sb_bp = target_sp->CreateSourceRegexBreakpoint (NULL, &source_file_spec_list, regexp, false, hardware);
Jim Ingham969795f2011-09-21 01:17:13 +00001530 }
1531 }
1532
1533 if (log)
1534 {
1535 char path[PATH_MAX];
1536 source_file->GetPath (path, sizeof(path));
1537 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (source_regex=\"%s\", file=\"%s\", module_name=\"%s\") => SBBreakpoint(%p)",
Greg Claytonacdbe812012-01-30 09:04:36 +00001538 target_sp.get(), source_regex, path, module_name, sb_bp.get());
Jim Ingham969795f2011-09-21 01:17:13 +00001539 }
1540
1541 return sb_bp;
1542}
1543
Jim Ingham87df91b2011-09-23 00:54:11 +00001544lldb::SBBreakpoint
1545SBTarget::BreakpointCreateBySourceRegex (const char *source_regex,
Greg Claytoneb023e72013-10-11 19:48:25 +00001546 const SBFileSpecList &module_list,
1547 const lldb::SBFileSpecList &source_file_list)
Jim Ingham87df91b2011-09-23 00:54:11 +00001548{
Greg Clayton5160ce52013-03-27 23:08:40 +00001549 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Jim Ingham87df91b2011-09-23 00:54:11 +00001550
1551 SBBreakpoint sb_bp;
Greg Claytonacdbe812012-01-30 09:04:36 +00001552 TargetSP target_sp(GetSP());
1553 if (target_sp && source_regex && source_regex[0])
Jim Ingham87df91b2011-09-23 00:54:11 +00001554 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001555 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytoneb023e72013-10-11 19:48:25 +00001556 const bool hardware = false;
Jim Ingham87df91b2011-09-23 00:54:11 +00001557 RegularExpression regexp(source_regex);
Greg Claytoneb023e72013-10-11 19:48:25 +00001558 *sb_bp = target_sp->CreateSourceRegexBreakpoint (module_list.get(), source_file_list.get(), regexp, false, hardware);
Jim Ingham87df91b2011-09-23 00:54:11 +00001559 }
1560
1561 if (log)
1562 {
1563 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (source_regex=\"%s\") => SBBreakpoint(%p)",
Greg Claytonacdbe812012-01-30 09:04:36 +00001564 target_sp.get(), source_regex, sb_bp.get());
Jim Ingham87df91b2011-09-23 00:54:11 +00001565 }
1566
1567 return sb_bp;
1568}
Jim Ingham969795f2011-09-21 01:17:13 +00001569
Jim Inghamfab10e82012-03-06 00:37:27 +00001570lldb::SBBreakpoint
1571SBTarget::BreakpointCreateForException (lldb::LanguageType language,
Greg Claytoneb023e72013-10-11 19:48:25 +00001572 bool catch_bp,
1573 bool throw_bp)
Jim Inghamfab10e82012-03-06 00:37:27 +00001574{
Greg Clayton5160ce52013-03-27 23:08:40 +00001575 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Jim Inghamfab10e82012-03-06 00:37:27 +00001576
1577 SBBreakpoint sb_bp;
1578 TargetSP target_sp(GetSP());
1579 if (target_sp)
1580 {
1581 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytoneb023e72013-10-11 19:48:25 +00001582 const bool hardware = false;
1583 *sb_bp = target_sp->CreateExceptionBreakpoint (language, catch_bp, throw_bp, hardware);
Jim Inghamfab10e82012-03-06 00:37:27 +00001584 }
1585
1586 if (log)
1587 {
1588 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (Language: %s, catch: %s throw: %s) => SBBreakpoint(%p)",
1589 target_sp.get(),
1590 LanguageRuntime::GetNameForLanguageType(language),
1591 catch_bp ? "on" : "off",
1592 throw_bp ? "on" : "off",
1593 sb_bp.get());
1594 }
1595
1596 return sb_bp;
1597}
1598
Greg Clayton9fed0d82010-07-23 23:33:17 +00001599uint32_t
1600SBTarget::GetNumBreakpoints () const
1601{
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 return target_sp->GetBreakpointList().GetSize();
Greg Claytonaf67cec2010-12-20 20:49:23 +00001607 }
Greg Clayton9fed0d82010-07-23 23:33:17 +00001608 return 0;
1609}
1610
1611SBBreakpoint
1612SBTarget::GetBreakpointAtIndex (uint32_t idx) const
1613{
1614 SBBreakpoint sb_breakpoint;
Greg Claytonacdbe812012-01-30 09:04:36 +00001615 TargetSP target_sp(GetSP());
1616 if (target_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +00001617 {
1618 // The breakpoint list is thread safe, no need to lock
Greg Claytonacdbe812012-01-30 09:04:36 +00001619 *sb_breakpoint = target_sp->GetBreakpointList().GetBreakpointAtIndex(idx);
Greg Claytonaf67cec2010-12-20 20:49:23 +00001620 }
Greg Clayton9fed0d82010-07-23 23:33:17 +00001621 return sb_breakpoint;
1622}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001623
1624bool
1625SBTarget::BreakpointDelete (break_id_t bp_id)
1626{
Greg Clayton5160ce52013-03-27 23:08:40 +00001627 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001628
Caroline Ticeceb6b132010-10-26 03:11:13 +00001629 bool result = false;
Greg Claytonacdbe812012-01-30 09:04:36 +00001630 TargetSP target_sp(GetSP());
1631 if (target_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +00001632 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001633 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1634 result = target_sp->RemoveBreakpointByID (bp_id);
Greg Claytonaf67cec2010-12-20 20:49:23 +00001635 }
Caroline Ticeceb6b132010-10-26 03:11:13 +00001636
1637 if (log)
1638 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001639 log->Printf ("SBTarget(%p)::BreakpointDelete (bp_id=%d) => %i", target_sp.get(), (uint32_t) bp_id, result);
Caroline Ticeceb6b132010-10-26 03:11:13 +00001640 }
1641
1642 return result;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001643}
1644
Johnny Chen5d043462011-09-26 22:40:50 +00001645SBBreakpoint
1646SBTarget::FindBreakpointByID (break_id_t bp_id)
1647{
Greg Clayton5160ce52013-03-27 23:08:40 +00001648 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Johnny Chen5d043462011-09-26 22:40:50 +00001649
1650 SBBreakpoint sb_breakpoint;
Greg Claytonacdbe812012-01-30 09:04:36 +00001651 TargetSP target_sp(GetSP());
1652 if (target_sp && bp_id != LLDB_INVALID_BREAK_ID)
Johnny Chen5d043462011-09-26 22:40:50 +00001653 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001654 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1655 *sb_breakpoint = target_sp->GetBreakpointByID (bp_id);
Johnny Chen5d043462011-09-26 22:40:50 +00001656 }
1657
1658 if (log)
1659 {
1660 log->Printf ("SBTarget(%p)::FindBreakpointByID (bp_id=%d) => SBBreakpoint(%p)",
Greg Claytonacdbe812012-01-30 09:04:36 +00001661 target_sp.get(), (uint32_t) bp_id, sb_breakpoint.get());
Johnny Chen5d043462011-09-26 22:40:50 +00001662 }
1663
1664 return sb_breakpoint;
1665}
1666
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001667bool
1668SBTarget::EnableAllBreakpoints ()
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->EnableAllBreakpoints ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001675 return true;
1676 }
1677 return false;
1678}
1679
1680bool
1681SBTarget::DisableAllBreakpoints ()
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->DisableAllBreakpoints ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001688 return true;
1689 }
1690 return false;
1691}
1692
1693bool
1694SBTarget::DeleteAllBreakpoints ()
1695{
Greg Claytonacdbe812012-01-30 09:04:36 +00001696 TargetSP target_sp(GetSP());
1697 if (target_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001698 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001699 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1700 target_sp->RemoveAllBreakpoints ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001701 return true;
1702 }
1703 return false;
1704}
1705
Johnny Chen5d043462011-09-26 22:40:50 +00001706uint32_t
Greg Clayton1b282f92011-10-13 18:08:26 +00001707SBTarget::GetNumWatchpoints () const
Johnny Chen5d043462011-09-26 22:40:50 +00001708{
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 Claytonacdbe812012-01-30 09:04:36 +00001713 return target_sp->GetWatchpointList().GetSize();
Johnny Chen5d043462011-09-26 22:40:50 +00001714 }
1715 return 0;
1716}
1717
Greg Clayton1b282f92011-10-13 18:08:26 +00001718SBWatchpoint
1719SBTarget::GetWatchpointAtIndex (uint32_t idx) const
Johnny Chen9d954d82011-09-27 20:29:45 +00001720{
Johnny Chen01a67862011-10-14 00:42:25 +00001721 SBWatchpoint sb_watchpoint;
Greg Claytonacdbe812012-01-30 09:04:36 +00001722 TargetSP target_sp(GetSP());
1723 if (target_sp)
Johnny Chen5d043462011-09-26 22:40:50 +00001724 {
Johnny Chen01a67862011-10-14 00:42:25 +00001725 // The watchpoint list is thread safe, no need to lock
Greg Clayton81e871e2012-02-04 02:27:34 +00001726 sb_watchpoint.SetSP (target_sp->GetWatchpointList().GetByIndex(idx));
Johnny Chen5d043462011-09-26 22:40:50 +00001727 }
Johnny Chen01a67862011-10-14 00:42:25 +00001728 return sb_watchpoint;
Johnny Chen5d043462011-09-26 22:40:50 +00001729}
1730
1731bool
Greg Clayton1b282f92011-10-13 18:08:26 +00001732SBTarget::DeleteWatchpoint (watch_id_t wp_id)
Johnny Chen5d043462011-09-26 22:40:50 +00001733{
Greg Clayton5160ce52013-03-27 23:08:40 +00001734 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Johnny Chen5d043462011-09-26 22:40:50 +00001735
1736 bool result = false;
Greg Claytonacdbe812012-01-30 09:04:36 +00001737 TargetSP target_sp(GetSP());
1738 if (target_sp)
Johnny Chen5d043462011-09-26 22:40:50 +00001739 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001740 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Johnny Chen7385a5a2012-05-31 22:56:36 +00001741 Mutex::Locker locker;
1742 target_sp->GetWatchpointList().GetListMutex(locker);
Greg Claytonacdbe812012-01-30 09:04:36 +00001743 result = target_sp->RemoveWatchpointByID (wp_id);
Johnny Chen5d043462011-09-26 22:40:50 +00001744 }
1745
1746 if (log)
1747 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001748 log->Printf ("SBTarget(%p)::WatchpointDelete (wp_id=%d) => %i", target_sp.get(), (uint32_t) wp_id, result);
Johnny Chen5d043462011-09-26 22:40:50 +00001749 }
1750
1751 return result;
1752}
1753
Greg Clayton1b282f92011-10-13 18:08:26 +00001754SBWatchpoint
1755SBTarget::FindWatchpointByID (lldb::watch_id_t wp_id)
Johnny Chen5d043462011-09-26 22:40:50 +00001756{
Greg Clayton5160ce52013-03-27 23:08:40 +00001757 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Johnny Chen5d043462011-09-26 22:40:50 +00001758
Greg Clayton1b282f92011-10-13 18:08:26 +00001759 SBWatchpoint sb_watchpoint;
Greg Clayton81e871e2012-02-04 02:27:34 +00001760 lldb::WatchpointSP watchpoint_sp;
Greg Claytonacdbe812012-01-30 09:04:36 +00001761 TargetSP target_sp(GetSP());
1762 if (target_sp && wp_id != LLDB_INVALID_WATCH_ID)
Johnny Chen5d043462011-09-26 22:40:50 +00001763 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001764 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Johnny Chen7385a5a2012-05-31 22:56:36 +00001765 Mutex::Locker locker;
1766 target_sp->GetWatchpointList().GetListMutex(locker);
Greg Clayton81e871e2012-02-04 02:27:34 +00001767 watchpoint_sp = target_sp->GetWatchpointList().FindByID(wp_id);
1768 sb_watchpoint.SetSP (watchpoint_sp);
Johnny Chen5d043462011-09-26 22:40:50 +00001769 }
1770
1771 if (log)
1772 {
Johnny Chen01a67862011-10-14 00:42:25 +00001773 log->Printf ("SBTarget(%p)::FindWatchpointByID (bp_id=%d) => SBWatchpoint(%p)",
Greg Clayton81e871e2012-02-04 02:27:34 +00001774 target_sp.get(), (uint32_t) wp_id, watchpoint_sp.get());
Johnny Chen5d043462011-09-26 22:40:50 +00001775 }
1776
Greg Clayton1b282f92011-10-13 18:08:26 +00001777 return sb_watchpoint;
1778}
1779
1780lldb::SBWatchpoint
Johnny Chenb90827e2012-06-04 23:19:54 +00001781SBTarget::WatchAddress (lldb::addr_t addr, size_t size, bool read, bool write, SBError &error)
Greg Clayton1b282f92011-10-13 18:08:26 +00001782{
Greg Clayton5160ce52013-03-27 23:08:40 +00001783 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton1b282f92011-10-13 18:08:26 +00001784
1785 SBWatchpoint sb_watchpoint;
Greg Clayton81e871e2012-02-04 02:27:34 +00001786 lldb::WatchpointSP watchpoint_sp;
Greg Claytonacdbe812012-01-30 09:04:36 +00001787 TargetSP target_sp(GetSP());
Greg Clayton81e871e2012-02-04 02:27:34 +00001788 if (target_sp && (read || write) && addr != LLDB_INVALID_ADDRESS && size > 0)
Greg Clayton1b282f92011-10-13 18:08:26 +00001789 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001790 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton81e871e2012-02-04 02:27:34 +00001791 uint32_t watch_type = 0;
1792 if (read)
1793 watch_type |= LLDB_WATCH_TYPE_READ;
1794 if (write)
1795 watch_type |= LLDB_WATCH_TYPE_WRITE;
Jim Inghamc6462312013-06-18 21:52:48 +00001796 if (watch_type == 0)
1797 {
1798 error.SetErrorString("Can't create a watchpoint that is neither read nor write.");
1799 return sb_watchpoint;
1800 }
1801
Johnny Chen7385a5a2012-05-31 22:56:36 +00001802 // Target::CreateWatchpoint() is thread safe.
Johnny Chenb90827e2012-06-04 23:19:54 +00001803 Error cw_error;
Jim Inghama7dfb662012-10-23 07:20:06 +00001804 // This API doesn't take in a type, so we can't figure out what it is.
1805 ClangASTType *type = NULL;
1806 watchpoint_sp = target_sp->CreateWatchpoint(addr, size, type, watch_type, cw_error);
Johnny Chenb90827e2012-06-04 23:19:54 +00001807 error.SetError(cw_error);
Greg Clayton81e871e2012-02-04 02:27:34 +00001808 sb_watchpoint.SetSP (watchpoint_sp);
Greg Clayton1b282f92011-10-13 18:08:26 +00001809 }
1810
1811 if (log)
1812 {
Daniel Malead01b2952012-11-29 21:49:15 +00001813 log->Printf ("SBTarget(%p)::WatchAddress (addr=0x%" PRIx64 ", 0x%u) => SBWatchpoint(%p)",
Greg Clayton81e871e2012-02-04 02:27:34 +00001814 target_sp.get(), addr, (uint32_t) size, watchpoint_sp.get());
Greg Clayton1b282f92011-10-13 18:08:26 +00001815 }
1816
1817 return sb_watchpoint;
Johnny Chen5d043462011-09-26 22:40:50 +00001818}
1819
1820bool
Greg Clayton1b282f92011-10-13 18:08:26 +00001821SBTarget::EnableAllWatchpoints ()
Johnny Chen5d043462011-09-26 22:40:50 +00001822{
Greg Claytonacdbe812012-01-30 09:04:36 +00001823 TargetSP target_sp(GetSP());
1824 if (target_sp)
Johnny Chen5d043462011-09-26 22:40:50 +00001825 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001826 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Johnny Chen7385a5a2012-05-31 22:56:36 +00001827 Mutex::Locker locker;
1828 target_sp->GetWatchpointList().GetListMutex(locker);
Greg Claytonacdbe812012-01-30 09:04:36 +00001829 target_sp->EnableAllWatchpoints ();
Johnny Chen5d043462011-09-26 22:40:50 +00001830 return true;
1831 }
1832 return false;
1833}
1834
1835bool
Greg Clayton1b282f92011-10-13 18:08:26 +00001836SBTarget::DisableAllWatchpoints ()
Johnny Chen5d043462011-09-26 22:40:50 +00001837{
Greg Claytonacdbe812012-01-30 09:04:36 +00001838 TargetSP target_sp(GetSP());
1839 if (target_sp)
Johnny Chen5d043462011-09-26 22:40:50 +00001840 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001841 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Johnny Chen7385a5a2012-05-31 22:56:36 +00001842 Mutex::Locker locker;
1843 target_sp->GetWatchpointList().GetListMutex(locker);
Greg Claytonacdbe812012-01-30 09:04:36 +00001844 target_sp->DisableAllWatchpoints ();
Johnny Chen5d043462011-09-26 22:40:50 +00001845 return true;
1846 }
1847 return false;
1848}
1849
Enrico Granata347c2aa2013-10-08 21:49:02 +00001850SBValue
1851SBTarget::CreateValueFromAddress (const char *name, SBAddress addr, SBType type)
1852{
1853 SBValue sb_value;
1854 lldb::ValueObjectSP new_value_sp;
1855 if (IsValid() && name && *name && addr.IsValid() && type.IsValid())
1856 {
1857 lldb::addr_t address(addr.GetLoadAddress(*this));
1858 lldb::TypeImplSP type_impl_sp (type.GetSP());
Enrico Granatadc4db5a2013-10-29 00:28:35 +00001859 ClangASTType pointer_ast_type(type_impl_sp->GetClangASTType(true).GetPointerType ());
Enrico Granata347c2aa2013-10-08 21:49:02 +00001860 if (pointer_ast_type)
1861 {
1862 lldb::DataBufferSP buffer(new lldb_private::DataBufferHeap(&address,sizeof(lldb::addr_t)));
1863
1864 ExecutionContext exe_ctx (ExecutionContextRef(ExecutionContext(m_opaque_sp.get(),false)));
1865 ValueObjectSP ptr_result_valobj_sp(ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
1866 pointer_ast_type,
1867 ConstString(name),
1868 buffer,
1869 exe_ctx.GetByteOrder(),
1870 exe_ctx.GetAddressByteSize()));
1871
1872 if (ptr_result_valobj_sp)
1873 {
1874 ptr_result_valobj_sp->GetValue().SetValueType(Value::eValueTypeLoadAddress);
1875 Error err;
1876 new_value_sp = ptr_result_valobj_sp->Dereference(err);
1877 if (new_value_sp)
1878 new_value_sp->SetName(ConstString(name));
1879 }
1880 }
1881 }
1882 sb_value.SetSP(new_value_sp);
1883 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1884 if (log)
1885 {
1886 if (new_value_sp)
1887 log->Printf ("SBTarget(%p)::CreateValueFromAddress => \"%s\"", m_opaque_sp.get(), new_value_sp->GetName().AsCString());
1888 else
1889 log->Printf ("SBTarget(%p)::CreateValueFromAddress => NULL", m_opaque_sp.get());
1890 }
1891 return sb_value;
1892}
1893
Johnny Chen5d043462011-09-26 22:40:50 +00001894bool
Greg Clayton1b282f92011-10-13 18:08:26 +00001895SBTarget::DeleteAllWatchpoints ()
Johnny Chen5d043462011-09-26 22:40:50 +00001896{
Greg Claytonacdbe812012-01-30 09:04:36 +00001897 TargetSP target_sp(GetSP());
1898 if (target_sp)
Johnny Chen5d043462011-09-26 22:40:50 +00001899 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001900 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Johnny Chen7385a5a2012-05-31 22:56:36 +00001901 Mutex::Locker locker;
1902 target_sp->GetWatchpointList().GetListMutex(locker);
Greg Claytonacdbe812012-01-30 09:04:36 +00001903 target_sp->RemoveAllWatchpoints ();
Johnny Chen5d043462011-09-26 22:40:50 +00001904 return true;
1905 }
1906 return false;
1907}
1908
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001909
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001910lldb::SBModule
1911SBTarget::AddModule (const char *path,
1912 const char *triple,
1913 const char *uuid_cstr)
1914{
Greg Claytonb210aec2012-04-23 20:23:39 +00001915 return AddModule (path, triple, uuid_cstr, NULL);
1916}
1917
1918lldb::SBModule
1919SBTarget::AddModule (const char *path,
1920 const char *triple,
1921 const char *uuid_cstr,
1922 const char *symfile)
1923{
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001924 lldb::SBModule sb_module;
Greg Claytonacdbe812012-01-30 09:04:36 +00001925 TargetSP target_sp(GetSP());
1926 if (target_sp)
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001927 {
Greg Claytonb9a01b32012-02-26 05:51:37 +00001928 ModuleSpec module_spec;
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001929 if (path)
Greg Claytonb9a01b32012-02-26 05:51:37 +00001930 module_spec.GetFileSpec().SetFile(path, false);
Greg Claytonb210aec2012-04-23 20:23:39 +00001931
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001932 if (uuid_cstr)
Greg Claytonb5f0fea2012-09-27 22:26:11 +00001933 module_spec.GetUUID().SetFromCString(uuid_cstr);
Greg Claytonb210aec2012-04-23 20:23:39 +00001934
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001935 if (triple)
Greg Claytonb9a01b32012-02-26 05:51:37 +00001936 module_spec.GetArchitecture().SetTriple (triple, target_sp->GetPlatform ().get());
Jason Molendab019cd92013-09-11 21:25:46 +00001937 else
1938 module_spec.GetArchitecture() = target_sp->GetArchitecture();
Greg Claytonb210aec2012-04-23 20:23:39 +00001939
1940 if (symfile)
1941 module_spec.GetSymbolFileSpec ().SetFile(symfile, false);
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001942
Greg Claytonb9a01b32012-02-26 05:51:37 +00001943 sb_module.SetSP(target_sp->GetSharedModule (module_spec));
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001944 }
1945 return sb_module;
1946}
1947
Greg Clayton226cce22013-07-08 22:22:41 +00001948lldb::SBModule
1949SBTarget::AddModule (const SBModuleSpec &module_spec)
1950{
1951 lldb::SBModule sb_module;
1952 TargetSP target_sp(GetSP());
1953 if (target_sp)
1954 sb_module.SetSP(target_sp->GetSharedModule (*module_spec.m_opaque_ap));
1955 return sb_module;
1956}
1957
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001958bool
1959SBTarget::AddModule (lldb::SBModule &module)
1960{
Greg Claytonacdbe812012-01-30 09:04:36 +00001961 TargetSP target_sp(GetSP());
1962 if (target_sp)
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001963 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001964 target_sp->GetImages().AppendIfNeeded (module.GetSP());
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001965 return true;
1966 }
1967 return false;
1968}
1969
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001970uint32_t
1971SBTarget::GetNumModules () const
1972{
Greg Clayton5160ce52013-03-27 23:08:40 +00001973 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001974
Caroline Ticeceb6b132010-10-26 03:11:13 +00001975 uint32_t num = 0;
Greg Claytonacdbe812012-01-30 09:04:36 +00001976 TargetSP target_sp(GetSP());
1977 if (target_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +00001978 {
1979 // The module list is thread safe, no need to lock
Greg Claytonacdbe812012-01-30 09:04:36 +00001980 num = target_sp->GetImages().GetSize();
Greg Claytonaf67cec2010-12-20 20:49:23 +00001981 }
Caroline Ticeceb6b132010-10-26 03:11:13 +00001982
1983 if (log)
Greg Claytonacdbe812012-01-30 09:04:36 +00001984 log->Printf ("SBTarget(%p)::GetNumModules () => %d", target_sp.get(), num);
Caroline Ticeceb6b132010-10-26 03:11:13 +00001985
1986 return num;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001987}
1988
Greg Clayton48e42542010-07-30 20:12:55 +00001989void
1990SBTarget::Clear ()
1991{
Greg Clayton5160ce52013-03-27 23:08:40 +00001992 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001993
1994 if (log)
Greg Clayton93aa84e2010-10-29 04:59:35 +00001995 log->Printf ("SBTarget(%p)::Clear ()", m_opaque_sp.get());
Caroline Ticeceb6b132010-10-26 03:11:13 +00001996
Greg Clayton48e42542010-07-30 20:12:55 +00001997 m_opaque_sp.reset();
1998}
1999
2000
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002001SBModule
2002SBTarget::FindModule (const SBFileSpec &sb_file_spec)
2003{
2004 SBModule sb_module;
Greg Claytonacdbe812012-01-30 09:04:36 +00002005 TargetSP target_sp(GetSP());
2006 if (target_sp && sb_file_spec.IsValid())
Greg Claytonaf67cec2010-12-20 20:49:23 +00002007 {
Greg Claytonb9a01b32012-02-26 05:51:37 +00002008 ModuleSpec module_spec(*sb_file_spec);
Greg Claytonaf67cec2010-12-20 20:49:23 +00002009 // The module list is thread safe, no need to lock
Greg Claytonb9a01b32012-02-26 05:51:37 +00002010 sb_module.SetSP (target_sp->GetImages().FindFirstModule (module_spec));
Greg Claytonaf67cec2010-12-20 20:49:23 +00002011 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002012 return sb_module;
2013}
2014
Greg Clayton13d19502012-01-29 06:07:39 +00002015lldb::ByteOrder
2016SBTarget::GetByteOrder ()
2017{
Greg Claytonacdbe812012-01-30 09:04:36 +00002018 TargetSP target_sp(GetSP());
2019 if (target_sp)
2020 return target_sp->GetArchitecture().GetByteOrder();
Greg Clayton13d19502012-01-29 06:07:39 +00002021 return eByteOrderInvalid;
2022}
2023
2024const char *
2025SBTarget::GetTriple ()
2026{
Greg Claytonacdbe812012-01-30 09:04:36 +00002027 TargetSP target_sp(GetSP());
2028 if (target_sp)
Greg Clayton13d19502012-01-29 06:07:39 +00002029 {
Greg Claytonacdbe812012-01-30 09:04:36 +00002030 std::string triple (target_sp->GetArchitecture().GetTriple().str());
Greg Clayton13d19502012-01-29 06:07:39 +00002031 // Unique the string so we don't run into ownership issues since
2032 // the const strings put the string into the string pool once and
2033 // the strings never comes out
2034 ConstString const_triple (triple.c_str());
2035 return const_triple.GetCString();
2036 }
2037 return NULL;
2038}
2039
2040uint32_t
2041SBTarget::GetAddressByteSize()
2042{
Greg Claytonacdbe812012-01-30 09:04:36 +00002043 TargetSP target_sp(GetSP());
2044 if (target_sp)
2045 return target_sp->GetArchitecture().GetAddressByteSize();
Greg Clayton13d19502012-01-29 06:07:39 +00002046 return sizeof(void*);
2047}
2048
2049
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002050SBModule
2051SBTarget::GetModuleAtIndex (uint32_t idx)
2052{
Greg Clayton5160ce52013-03-27 23:08:40 +00002053 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +00002054
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002055 SBModule sb_module;
Greg Claytonacdbe812012-01-30 09:04:36 +00002056 ModuleSP module_sp;
2057 TargetSP target_sp(GetSP());
2058 if (target_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +00002059 {
2060 // The module list is thread safe, no need to lock
Greg Claytonacdbe812012-01-30 09:04:36 +00002061 module_sp = target_sp->GetImages().GetModuleAtIndex(idx);
2062 sb_module.SetSP (module_sp);
Greg Claytonaf67cec2010-12-20 20:49:23 +00002063 }
Caroline Ticeceb6b132010-10-26 03:11:13 +00002064
2065 if (log)
2066 {
Greg Claytoncfd1ace2010-10-31 03:01:06 +00002067 log->Printf ("SBTarget(%p)::GetModuleAtIndex (idx=%d) => SBModule(%p)",
Greg Claytonacdbe812012-01-30 09:04:36 +00002068 target_sp.get(), idx, module_sp.get());
Caroline Ticeceb6b132010-10-26 03:11:13 +00002069 }
2070
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002071 return sb_module;
2072}
2073
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002074bool
2075SBTarget::RemoveModule (lldb::SBModule module)
2076{
Greg Claytonacdbe812012-01-30 09:04:36 +00002077 TargetSP target_sp(GetSP());
2078 if (target_sp)
2079 return target_sp->GetImages().Remove(module.GetSP());
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002080 return false;
2081}
2082
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002083
2084SBBroadcaster
2085SBTarget::GetBroadcaster () const
2086{
Greg Clayton5160ce52013-03-27 23:08:40 +00002087 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +00002088
Greg Claytonacdbe812012-01-30 09:04:36 +00002089 TargetSP target_sp(GetSP());
2090 SBBroadcaster broadcaster(target_sp.get(), false);
Caroline Ticeceb6b132010-10-26 03:11:13 +00002091
2092 if (log)
Greg Clayton93aa84e2010-10-29 04:59:35 +00002093 log->Printf ("SBTarget(%p)::GetBroadcaster () => SBBroadcaster(%p)",
Greg Claytonacdbe812012-01-30 09:04:36 +00002094 target_sp.get(), broadcaster.get());
Caroline Ticeceb6b132010-10-26 03:11:13 +00002095
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002096 return broadcaster;
2097}
2098
Caroline Ticedde9cff2010-09-20 05:20:02 +00002099bool
Caroline Ticeceb6b132010-10-26 03:11:13 +00002100SBTarget::GetDescription (SBStream &description, lldb::DescriptionLevel description_level)
Caroline Ticedde9cff2010-09-20 05:20:02 +00002101{
Greg Claytonda7bc7d2011-11-13 06:57:31 +00002102 Stream &strm = description.ref();
2103
Greg Claytonacdbe812012-01-30 09:04:36 +00002104 TargetSP target_sp(GetSP());
2105 if (target_sp)
Caroline Tice201a8852010-09-20 16:21:41 +00002106 {
Greg Claytonacdbe812012-01-30 09:04:36 +00002107 target_sp->Dump (&strm, description_level);
Caroline Ticeceb6b132010-10-26 03:11:13 +00002108 }
2109 else
Greg Claytonda7bc7d2011-11-13 06:57:31 +00002110 strm.PutCString ("No value");
Caroline Ticeceb6b132010-10-26 03:11:13 +00002111
2112 return true;
2113}
2114
Greg Clayton5569e642012-02-06 01:44:54 +00002115lldb::SBSymbolContextList
2116SBTarget::FindFunctions (const char *name, uint32_t name_type_mask)
Greg Claytonfe356d32011-06-21 01:34:41 +00002117{
Greg Clayton5569e642012-02-06 01:44:54 +00002118 lldb::SBSymbolContextList sb_sc_list;
Greg Claytonacdbe812012-01-30 09:04:36 +00002119 if (name && name[0])
Greg Claytonfe356d32011-06-21 01:34:41 +00002120 {
Greg Claytonacdbe812012-01-30 09:04:36 +00002121 TargetSP target_sp(GetSP());
2122 if (target_sp)
2123 {
2124 const bool symbols_ok = true;
Sean Callanan9df05fb2012-02-10 22:52:19 +00002125 const bool inlines_ok = true;
Greg Clayton5569e642012-02-06 01:44:54 +00002126 const bool append = true;
2127 target_sp->GetImages().FindFunctions (ConstString(name),
2128 name_type_mask,
Sean Callanan9df05fb2012-02-10 22:52:19 +00002129 symbols_ok,
2130 inlines_ok,
Greg Clayton5569e642012-02-06 01:44:54 +00002131 append,
2132 *sb_sc_list);
Greg Claytonacdbe812012-01-30 09:04:36 +00002133 }
Greg Claytonfe356d32011-06-21 01:34:41 +00002134 }
Greg Clayton5569e642012-02-06 01:44:54 +00002135 return sb_sc_list;
Greg Claytonfe356d32011-06-21 01:34:41 +00002136}
2137
Enrico Granata6f3533f2011-07-29 19:53:35 +00002138lldb::SBType
Greg Claytonb43165b2012-12-05 21:24:42 +00002139SBTarget::FindFirstType (const char* typename_cstr)
Enrico Granata6f3533f2011-07-29 19:53:35 +00002140{
Greg Claytonacdbe812012-01-30 09:04:36 +00002141 TargetSP target_sp(GetSP());
Greg Claytonb43165b2012-12-05 21:24:42 +00002142 if (typename_cstr && typename_cstr[0] && target_sp)
Enrico Granata6f3533f2011-07-29 19:53:35 +00002143 {
Greg Claytonb43165b2012-12-05 21:24:42 +00002144 ConstString const_typename(typename_cstr);
2145 SymbolContext sc;
2146 const bool exact_match = false;
2147
2148 const ModuleList &module_list = target_sp->GetImages();
2149 size_t count = module_list.GetSize();
Enrico Granata6f3533f2011-07-29 19:53:35 +00002150 for (size_t idx = 0; idx < count; idx++)
2151 {
Greg Claytonb43165b2012-12-05 21:24:42 +00002152 ModuleSP module_sp (module_list.GetModuleAtIndex(idx));
2153 if (module_sp)
2154 {
2155 TypeSP type_sp (module_sp->FindFirstType(sc, const_typename, exact_match));
2156 if (type_sp)
2157 return SBType(type_sp);
2158 }
Enrico Granata6f3533f2011-07-29 19:53:35 +00002159 }
Sean Callanan7be70e82012-12-19 23:05:01 +00002160
2161 // Didn't find the type in the symbols; try the Objective-C runtime
2162 // if one is installed
2163
2164 ProcessSP process_sp(target_sp->GetProcessSP());
2165
2166 if (process_sp)
2167 {
2168 ObjCLanguageRuntime *objc_language_runtime = process_sp->GetObjCLanguageRuntime();
2169
2170 if (objc_language_runtime)
2171 {
2172 TypeVendor *objc_type_vendor = objc_language_runtime->GetTypeVendor();
2173
2174 if (objc_type_vendor)
2175 {
2176 std::vector <ClangASTType> types;
2177
2178 if (objc_type_vendor->FindTypes(const_typename, true, 1, types) > 0)
2179 return SBType(types[0]);
2180 }
2181 }
2182 }
Greg Claytonb43165b2012-12-05 21:24:42 +00002183
2184 // No matches, search for basic typename matches
2185 ClangASTContext *clang_ast = target_sp->GetScratchClangASTContext();
2186 if (clang_ast)
Greg Clayton57ee3062013-07-11 22:46:58 +00002187 return SBType (ClangASTContext::GetBasicType (clang_ast->getASTContext(), const_typename));
Enrico Granata6f3533f2011-07-29 19:53:35 +00002188 }
2189 return SBType();
2190}
2191
Greg Claytonb43165b2012-12-05 21:24:42 +00002192SBType
2193SBTarget::GetBasicType(lldb::BasicType type)
Enrico Granata6f3533f2011-07-29 19:53:35 +00002194{
Greg Claytonacdbe812012-01-30 09:04:36 +00002195 TargetSP target_sp(GetSP());
Greg Claytonb43165b2012-12-05 21:24:42 +00002196 if (target_sp)
2197 {
2198 ClangASTContext *clang_ast = target_sp->GetScratchClangASTContext();
2199 if (clang_ast)
Greg Clayton57ee3062013-07-11 22:46:58 +00002200 return SBType (ClangASTContext::GetBasicType (clang_ast->getASTContext(), type));
Greg Claytonb43165b2012-12-05 21:24:42 +00002201 }
2202 return SBType();
2203}
2204
2205
2206lldb::SBTypeList
2207SBTarget::FindTypes (const char* typename_cstr)
2208{
2209 SBTypeList sb_type_list;
2210 TargetSP target_sp(GetSP());
2211 if (typename_cstr && typename_cstr[0] && target_sp)
Enrico Granata6f3533f2011-07-29 19:53:35 +00002212 {
Greg Claytonacdbe812012-01-30 09:04:36 +00002213 ModuleList& images = target_sp->GetImages();
Greg Claytonb43165b2012-12-05 21:24:42 +00002214 ConstString const_typename(typename_cstr);
Greg Clayton84db9102012-03-26 23:03:23 +00002215 bool exact_match = false;
Enrico Granata6f3533f2011-07-29 19:53:35 +00002216 SymbolContext sc;
2217 TypeList type_list;
2218
Greg Clayton29399a22012-04-06 17:41:13 +00002219 uint32_t num_matches = images.FindTypes (sc,
Greg Claytonb43165b2012-12-05 21:24:42 +00002220 const_typename,
Greg Clayton84db9102012-03-26 23:03:23 +00002221 exact_match,
2222 UINT32_MAX,
2223 type_list);
Enrico Granata6f3533f2011-07-29 19:53:35 +00002224
Greg Claytonb43165b2012-12-05 21:24:42 +00002225 if (num_matches > 0)
Enrico Granata6f3533f2011-07-29 19:53:35 +00002226 {
Greg Claytonb43165b2012-12-05 21:24:42 +00002227 for (size_t idx = 0; idx < num_matches; idx++)
2228 {
2229 TypeSP type_sp (type_list.GetTypeAtIndex(idx));
2230 if (type_sp)
2231 sb_type_list.Append(SBType(type_sp));
2232 }
2233 }
Sean Callanan7be70e82012-12-19 23:05:01 +00002234
2235 // Try the Objective-C runtime if one is installed
2236
2237 ProcessSP process_sp(target_sp->GetProcessSP());
2238
2239 if (process_sp)
2240 {
2241 ObjCLanguageRuntime *objc_language_runtime = process_sp->GetObjCLanguageRuntime();
2242
2243 if (objc_language_runtime)
2244 {
2245 TypeVendor *objc_type_vendor = objc_language_runtime->GetTypeVendor();
2246
2247 if (objc_type_vendor)
2248 {
2249 std::vector <ClangASTType> types;
2250
2251 if (objc_type_vendor->FindTypes(const_typename, true, UINT32_MAX, types))
2252 {
2253 for (ClangASTType &type : types)
2254 {
2255 sb_type_list.Append(SBType(type));
2256 }
2257 }
2258 }
2259 }
2260 }
2261
2262 if (sb_type_list.GetSize() == 0)
Greg Claytonb43165b2012-12-05 21:24:42 +00002263 {
2264 // No matches, search for basic typename matches
2265 ClangASTContext *clang_ast = target_sp->GetScratchClangASTContext();
2266 if (clang_ast)
Greg Clayton57ee3062013-07-11 22:46:58 +00002267 sb_type_list.Append (SBType (ClangASTContext::GetBasicType (clang_ast->getASTContext(), const_typename)));
Enrico Granata6f3533f2011-07-29 19:53:35 +00002268 }
2269 }
Greg Claytonb43165b2012-12-05 21:24:42 +00002270 return sb_type_list;
Enrico Granata6f3533f2011-07-29 19:53:35 +00002271}
2272
Greg Claytondea8cb42011-06-29 22:09:02 +00002273SBValueList
2274SBTarget::FindGlobalVariables (const char *name, uint32_t max_matches)
2275{
2276 SBValueList sb_value_list;
2277
Greg Claytonacdbe812012-01-30 09:04:36 +00002278 TargetSP target_sp(GetSP());
2279 if (name && target_sp)
Greg Claytondea8cb42011-06-29 22:09:02 +00002280 {
2281 VariableList variable_list;
2282 const bool append = true;
Greg Claytonacdbe812012-01-30 09:04:36 +00002283 const uint32_t match_count = target_sp->GetImages().FindGlobalVariables (ConstString (name),
2284 append,
2285 max_matches,
2286 variable_list);
Greg Claytondea8cb42011-06-29 22:09:02 +00002287
2288 if (match_count > 0)
2289 {
Greg Claytonacdbe812012-01-30 09:04:36 +00002290 ExecutionContextScope *exe_scope = target_sp->GetProcessSP().get();
Greg Claytondea8cb42011-06-29 22:09:02 +00002291 if (exe_scope == NULL)
Greg Claytonacdbe812012-01-30 09:04:36 +00002292 exe_scope = target_sp.get();
Greg Claytondea8cb42011-06-29 22:09:02 +00002293 for (uint32_t i=0; i<match_count; ++i)
2294 {
2295 lldb::ValueObjectSP valobj_sp (ValueObjectVariable::Create (exe_scope, variable_list.GetVariableAtIndex(i)));
2296 if (valobj_sp)
Enrico Granata85425d72013-02-07 18:23:56 +00002297 sb_value_list.Append(SBValue(valobj_sp));
Greg Claytondea8cb42011-06-29 22:09:02 +00002298 }
2299 }
2300 }
2301
2302 return sb_value_list;
2303}
2304
Enrico Granatabcd80b42013-01-16 18:53:52 +00002305lldb::SBValue
2306SBTarget::FindFirstGlobalVariable (const char* name)
2307{
2308 SBValueList sb_value_list(FindGlobalVariables(name, 1));
2309 if (sb_value_list.IsValid() && sb_value_list.GetSize() > 0)
2310 return sb_value_list.GetValueAtIndex(0);
2311 return SBValue();
2312}
2313
Jim Inghame37d6052011-09-13 00:29:56 +00002314SBSourceManager
2315SBTarget::GetSourceManager()
2316{
2317 SBSourceManager source_manager (*this);
2318 return source_manager;
2319}
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002320
Sean Callanan50952e92011-12-14 23:49:37 +00002321lldb::SBInstructionList
Greg Clayton9c766112012-03-06 22:24:44 +00002322SBTarget::ReadInstructions (lldb::SBAddress base_addr, uint32_t count)
2323{
Jim Ingham0f063ba2013-03-02 00:26:47 +00002324 return ReadInstructions (base_addr, count, NULL);
2325}
2326
2327lldb::SBInstructionList
2328SBTarget::ReadInstructions (lldb::SBAddress base_addr, uint32_t count, const char *flavor_string)
2329{
Greg Clayton9c766112012-03-06 22:24:44 +00002330 SBInstructionList sb_instructions;
2331
2332 TargetSP target_sp(GetSP());
2333 if (target_sp)
2334 {
2335 Address *addr_ptr = base_addr.get();
2336
2337 if (addr_ptr)
2338 {
2339 DataBufferHeap data (target_sp->GetArchitecture().GetMaximumOpcodeByteSize() * count, 0);
2340 bool prefer_file_cache = false;
2341 lldb_private::Error error;
Greg Clayton3faf47c2013-03-28 23:42:53 +00002342 lldb::addr_t load_addr = LLDB_INVALID_ADDRESS;
2343 const size_t bytes_read = target_sp->ReadMemory(*addr_ptr,
2344 prefer_file_cache,
2345 data.GetBytes(),
2346 data.GetByteSize(),
2347 error,
2348 &load_addr);
2349 const bool data_from_file = load_addr == LLDB_INVALID_ADDRESS;
Greg Clayton9c766112012-03-06 22:24:44 +00002350 sb_instructions.SetDisassembler (Disassembler::DisassembleBytes (target_sp->GetArchitecture(),
2351 NULL,
Jim Ingham0f063ba2013-03-02 00:26:47 +00002352 flavor_string,
Greg Clayton9c766112012-03-06 22:24:44 +00002353 *addr_ptr,
2354 data.GetBytes(),
2355 bytes_read,
Greg Clayton3faf47c2013-03-28 23:42:53 +00002356 count,
2357 data_from_file));
Greg Clayton9c766112012-03-06 22:24:44 +00002358 }
2359 }
2360
2361 return sb_instructions;
2362
2363}
2364
2365lldb::SBInstructionList
Sean Callanan50952e92011-12-14 23:49:37 +00002366SBTarget::GetInstructions (lldb::SBAddress base_addr, const void *buf, size_t size)
2367{
Jim Ingham0f063ba2013-03-02 00:26:47 +00002368 return GetInstructionsWithFlavor (base_addr, NULL, buf, size);
2369}
2370
2371lldb::SBInstructionList
2372SBTarget::GetInstructionsWithFlavor (lldb::SBAddress base_addr, const char *flavor_string, const void *buf, size_t size)
2373{
Sean Callanan50952e92011-12-14 23:49:37 +00002374 SBInstructionList sb_instructions;
2375
Greg Claytonacdbe812012-01-30 09:04:36 +00002376 TargetSP target_sp(GetSP());
2377 if (target_sp)
Sean Callanan50952e92011-12-14 23:49:37 +00002378 {
2379 Address addr;
2380
2381 if (base_addr.get())
2382 addr = *base_addr.get();
2383
Greg Clayton3faf47c2013-03-28 23:42:53 +00002384 const bool data_from_file = true;
2385
Greg Claytonacdbe812012-01-30 09:04:36 +00002386 sb_instructions.SetDisassembler (Disassembler::DisassembleBytes (target_sp->GetArchitecture(),
Sean Callanan50952e92011-12-14 23:49:37 +00002387 NULL,
Jim Ingham0f063ba2013-03-02 00:26:47 +00002388 flavor_string,
Sean Callanan50952e92011-12-14 23:49:37 +00002389 addr,
2390 buf,
Greg Clayton3faf47c2013-03-28 23:42:53 +00002391 size,
2392 UINT32_MAX,
2393 data_from_file));
Sean Callanan50952e92011-12-14 23:49:37 +00002394 }
2395
2396 return sb_instructions;
2397}
2398
2399lldb::SBInstructionList
2400SBTarget::GetInstructions (lldb::addr_t base_addr, const void *buf, size_t size)
2401{
Jim Ingham0f063ba2013-03-02 00:26:47 +00002402 return GetInstructionsWithFlavor (ResolveLoadAddress(base_addr), NULL, buf, size);
2403}
2404
2405lldb::SBInstructionList
2406SBTarget::GetInstructionsWithFlavor (lldb::addr_t base_addr, const char *flavor_string, const void *buf, size_t size)
2407{
2408 return GetInstructionsWithFlavor (ResolveLoadAddress(base_addr), flavor_string, buf, size);
Sean Callanan50952e92011-12-14 23:49:37 +00002409}
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002410
2411SBError
2412SBTarget::SetSectionLoadAddress (lldb::SBSection section,
2413 lldb::addr_t section_base_addr)
2414{
2415 SBError sb_error;
Greg Claytonacdbe812012-01-30 09:04:36 +00002416 TargetSP target_sp(GetSP());
2417 if (target_sp)
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002418 {
2419 if (!section.IsValid())
2420 {
2421 sb_error.SetErrorStringWithFormat ("invalid section");
2422 }
2423 else
2424 {
Greg Clayton741f3f92012-03-27 21:10:07 +00002425 SectionSP section_sp (section.GetSP());
2426 if (section_sp)
2427 {
2428 if (section_sp->IsThreadSpecific())
2429 {
2430 sb_error.SetErrorString ("thread specific sections are not yet supported");
2431 }
2432 else
2433 {
Greg Claytond5944cd2013-12-06 01:12:00 +00002434 ProcessSP process_sp (target_sp->GetProcessSP());
2435 uint32_t stop_id = 0;
2436 if (process_sp)
2437 stop_id = process_sp->GetStopID();
2438
2439 if (target_sp->SetSectionLoadAddress (section_sp, section_base_addr))
Greg Clayton3c947372013-01-29 01:17:09 +00002440 {
2441 // Flush info in the process (stack frames, etc)
Greg Clayton3c947372013-01-29 01:17:09 +00002442 if (process_sp)
2443 process_sp->Flush();
2444 }
Greg Clayton741f3f92012-03-27 21:10:07 +00002445 }
2446 }
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002447 }
2448 }
2449 else
2450 {
Greg Clayton741f3f92012-03-27 21:10:07 +00002451 sb_error.SetErrorString ("invalid target");
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002452 }
2453 return sb_error;
2454}
2455
2456SBError
2457SBTarget::ClearSectionLoadAddress (lldb::SBSection section)
2458{
2459 SBError sb_error;
2460
Greg Claytonacdbe812012-01-30 09:04:36 +00002461 TargetSP target_sp(GetSP());
2462 if (target_sp)
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002463 {
2464 if (!section.IsValid())
2465 {
2466 sb_error.SetErrorStringWithFormat ("invalid section");
2467 }
2468 else
2469 {
Greg Claytond5944cd2013-12-06 01:12:00 +00002470 ProcessSP process_sp (target_sp->GetProcessSP());
2471 uint32_t stop_id = 0;
2472 if (process_sp)
2473 stop_id = process_sp->GetStopID();
2474
2475 if (target_sp->SetSectionUnloaded (section.GetSP()))
Greg Clayton3c947372013-01-29 01:17:09 +00002476 {
2477 // Flush info in the process (stack frames, etc)
Greg Clayton3c947372013-01-29 01:17:09 +00002478 if (process_sp)
2479 process_sp->Flush();
2480 }
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002481 }
2482 }
2483 else
2484 {
2485 sb_error.SetErrorStringWithFormat ("invalid target");
2486 }
2487 return sb_error;
2488}
2489
2490SBError
2491SBTarget::SetModuleLoadAddress (lldb::SBModule module, int64_t slide_offset)
2492{
2493 SBError sb_error;
2494
Greg Claytonacdbe812012-01-30 09:04:36 +00002495 TargetSP target_sp(GetSP());
2496 if (target_sp)
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002497 {
Greg Claytonacdbe812012-01-30 09:04:36 +00002498 ModuleSP module_sp (module.GetSP());
2499 if (module_sp)
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002500 {
Greg Clayton741f3f92012-03-27 21:10:07 +00002501 bool changed = false;
2502 if (module_sp->SetLoadAddress (*target_sp, slide_offset, changed))
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002503 {
Greg Clayton741f3f92012-03-27 21:10:07 +00002504 // The load was successful, make sure that at least some sections
2505 // changed before we notify that our module was loaded.
2506 if (changed)
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002507 {
Greg Clayton741f3f92012-03-27 21:10:07 +00002508 ModuleList module_list;
2509 module_list.Append(module_sp);
2510 target_sp->ModulesDidLoad (module_list);
Greg Clayton3c947372013-01-29 01:17:09 +00002511 // Flush info in the process (stack frames, etc)
2512 ProcessSP process_sp (target_sp->GetProcessSP());
2513 if (process_sp)
2514 process_sp->Flush();
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002515 }
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002516 }
2517 }
Greg Claytonacdbe812012-01-30 09:04:36 +00002518 else
2519 {
2520 sb_error.SetErrorStringWithFormat ("invalid module");
2521 }
2522
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002523 }
2524 else
2525 {
2526 sb_error.SetErrorStringWithFormat ("invalid target");
2527 }
2528 return sb_error;
2529}
2530
2531SBError
2532SBTarget::ClearModuleLoadAddress (lldb::SBModule module)
2533{
2534 SBError sb_error;
2535
2536 char path[PATH_MAX];
Greg Claytonacdbe812012-01-30 09:04:36 +00002537 TargetSP target_sp(GetSP());
2538 if (target_sp)
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002539 {
Greg Claytonacdbe812012-01-30 09:04:36 +00002540 ModuleSP module_sp (module.GetSP());
2541 if (module_sp)
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002542 {
Greg Claytonacdbe812012-01-30 09:04:36 +00002543 ObjectFile *objfile = module_sp->GetObjectFile();
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002544 if (objfile)
2545 {
2546 SectionList *section_list = objfile->GetSectionList();
2547 if (section_list)
2548 {
Greg Claytond5944cd2013-12-06 01:12:00 +00002549 ProcessSP process_sp (target_sp->GetProcessSP());
2550 uint32_t stop_id = 0;
2551 if (process_sp)
2552 stop_id = process_sp->GetStopID();
2553
Greg Clayton3c947372013-01-29 01:17:09 +00002554 bool changed = false;
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002555 const size_t num_sections = section_list->GetSize();
2556 for (size_t sect_idx = 0; sect_idx < num_sections; ++sect_idx)
2557 {
2558 SectionSP section_sp (section_list->GetSectionAtIndex(sect_idx));
2559 if (section_sp)
Greg Claytond5944cd2013-12-06 01:12:00 +00002560 changed |= target_sp->SetSectionUnloaded (section_sp) > 0;
Greg Clayton3c947372013-01-29 01:17:09 +00002561 }
2562 if (changed)
2563 {
2564 // Flush info in the process (stack frames, etc)
2565 ProcessSP process_sp (target_sp->GetProcessSP());
2566 if (process_sp)
2567 process_sp->Flush();
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002568 }
2569 }
2570 else
2571 {
Greg Claytonacdbe812012-01-30 09:04:36 +00002572 module_sp->GetFileSpec().GetPath (path, sizeof(path));
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002573 sb_error.SetErrorStringWithFormat ("no sections in object file '%s'", path);
2574 }
2575 }
2576 else
2577 {
Greg Claytonacdbe812012-01-30 09:04:36 +00002578 module_sp->GetFileSpec().GetPath (path, sizeof(path));
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002579 sb_error.SetErrorStringWithFormat ("no object file for module '%s'", path);
2580 }
2581 }
Greg Claytonacdbe812012-01-30 09:04:36 +00002582 else
2583 {
2584 sb_error.SetErrorStringWithFormat ("invalid module");
2585 }
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002586 }
2587 else
2588 {
2589 sb_error.SetErrorStringWithFormat ("invalid target");
2590 }
2591 return sb_error;
2592}
2593
2594
Greg Claytone14e1922012-12-04 02:22:16 +00002595lldb::SBSymbolContextList
2596SBTarget::FindSymbols (const char *name, lldb::SymbolType symbol_type)
2597{
2598 SBSymbolContextList sb_sc_list;
2599 if (name && name[0])
2600 {
2601 TargetSP target_sp(GetSP());
2602 if (target_sp)
2603 {
2604 bool append = true;
2605 target_sp->GetImages().FindSymbolsWithNameAndType (ConstString(name),
2606 symbol_type,
2607 *sb_sc_list,
2608 append);
2609 }
2610 }
2611 return sb_sc_list;
2612
2613}
2614
2615
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002616lldb::SBValue
2617SBTarget::EvaluateExpression (const char *expr, const SBExpressionOptions &options)
2618{
Greg Clayton5160ce52013-03-27 23:08:40 +00002619 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
2620 Log * expr_log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002621 SBValue expr_result;
2622 ExecutionResults exe_results = eExecutionSetupError;
2623 ValueObjectSP expr_value_sp;
2624 TargetSP target_sp(GetSP());
Jason Molendab57e4a12013-11-04 09:33:30 +00002625 StackFrame *frame = NULL;
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002626 if (target_sp)
2627 {
2628 if (expr == NULL || expr[0] == '\0')
2629 {
2630 if (log)
2631 log->Printf ("SBTarget::EvaluateExpression called with an empty expression");
2632 return expr_result;
2633 }
2634
2635 Mutex::Locker api_locker (target_sp->GetAPIMutex());
2636 ExecutionContext exe_ctx (m_opaque_sp.get());
2637
2638 if (log)
2639 log->Printf ("SBTarget()::EvaluateExpression (expr=\"%s\")...", expr);
2640
2641 frame = exe_ctx.GetFramePtr();
2642 Target *target = exe_ctx.GetTargetPtr();
2643
2644 if (target)
2645 {
2646#ifdef LLDB_CONFIGURATION_DEBUG
2647 StreamString frame_description;
2648 if (frame)
2649 frame->DumpUsingSettingsFormat (&frame_description);
2650 Host::SetCrashDescriptionWithFormat ("SBTarget::EvaluateExpression (expr = \"%s\", fetch_dynamic_value = %u) %s",
2651 expr, options.GetFetchDynamicValue(), frame_description.GetString().c_str());
2652#endif
2653 exe_results = target->EvaluateExpression (expr,
2654 frame,
2655 expr_value_sp,
2656 options.ref());
2657
2658 expr_result.SetSP(expr_value_sp, options.GetFetchDynamicValue());
2659#ifdef LLDB_CONFIGURATION_DEBUG
2660 Host::SetCrashDescription (NULL);
2661#endif
2662 }
2663 else
2664 {
2665 if (log)
2666 log->Printf ("SBTarget::EvaluateExpression () => error: could not reconstruct frame object for this SBTarget.");
2667 }
2668 }
2669#ifndef LLDB_DISABLE_PYTHON
2670 if (expr_log)
2671 expr_log->Printf("** [SBTarget::EvaluateExpression] Expression result is %s, summary %s **",
2672 expr_result.GetValue(),
2673 expr_result.GetSummary());
2674
2675 if (log)
2676 log->Printf ("SBTarget(%p)::EvaluateExpression (expr=\"%s\") => SBValue(%p) (execution result=%d)",
2677 frame,
2678 expr,
2679 expr_value_sp.get(),
2680 exe_results);
2681#endif
2682
2683 return expr_result;
2684}
2685
Greg Clayton13fbb992013-02-01 00:47:49 +00002686
2687lldb::addr_t
2688SBTarget::GetStackRedZoneSize()
2689{
2690 TargetSP target_sp(GetSP());
2691 if (target_sp)
2692 {
2693 ABISP abi_sp;
2694 ProcessSP process_sp (target_sp->GetProcessSP());
2695 if (process_sp)
2696 abi_sp = process_sp->GetABI();
2697 else
2698 abi_sp = ABI::FindPlugin(target_sp->GetArchitecture());
2699 if (abi_sp)
2700 return abi_sp->GetRedZoneSize();
2701 }
2702 return 0;
2703}
2704