1 //===-- 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 
10 #include "lldb/lldb-python.h"
11 
12 #include "lldb/API/SBTarget.h"
13 
14 #include "lldb/lldb-public.h"
15 
16 #include "lldb/API/SBDebugger.h"
17 #include "lldb/API/SBBreakpoint.h"
18 #include "lldb/API/SBExpressionOptions.h"
19 #include "lldb/API/SBFileSpec.h"
20 #include "lldb/API/SBListener.h"
21 #include "lldb/API/SBModule.h"
22 #include "lldb/API/SBModuleSpec.h"
23 #include "lldb/API/SBSourceManager.h"
24 #include "lldb/API/SBProcess.h"
25 #include "lldb/API/SBStream.h"
26 #include "lldb/API/SBSymbolContextList.h"
27 #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"
34 #include "lldb/Core/ArchSpec.h"
35 #include "lldb/Core/Debugger.h"
36 #include "lldb/Core/Disassembler.h"
37 #include "lldb/Core/Log.h"
38 #include "lldb/Core/Module.h"
39 #include "lldb/Core/ModuleSpec.h"
40 #include "lldb/Core/RegularExpression.h"
41 #include "lldb/Core/SearchFilter.h"
42 #include "lldb/Core/Section.h"
43 #include "lldb/Core/STLUtils.h"
44 #include "lldb/Core/ValueObjectConstResult.h"
45 #include "lldb/Core/ValueObjectList.h"
46 #include "lldb/Core/ValueObjectVariable.h"
47 #include "lldb/Host/FileSpec.h"
48 #include "lldb/Host/Host.h"
49 #include "lldb/Interpreter/Args.h"
50 #include "lldb/Symbol/ObjectFile.h"
51 #include "lldb/Symbol/SymbolVendor.h"
52 #include "lldb/Symbol/VariableList.h"
53 #include "lldb/Target/LanguageRuntime.h"
54 #include "lldb/Target/Process.h"
55 
56 #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 #include "llvm/Support/Regex.h"
62 
63 
64 using namespace lldb;
65 using namespace lldb_private;
66 
67 #define DEFAULT_DISASM_BYTE_SIZE 32
68 
69 SBLaunchInfo::SBLaunchInfo (const char **argv) :
70     m_opaque_sp(new ProcessLaunchInfo())
71 {
72     m_opaque_sp->GetFlags().Reset (eLaunchFlagDebug | eLaunchFlagDisableASLR);
73     if (argv && argv[0])
74         m_opaque_sp->GetArguments().SetArguments(argv);
75 }
76 
77 SBLaunchInfo::~SBLaunchInfo()
78 {
79 }
80 
81 lldb_private::ProcessLaunchInfo &
82 SBLaunchInfo::ref ()
83 {
84     return *m_opaque_sp;
85 }
86 
87 
88 uint32_t
89 SBLaunchInfo::GetUserID()
90 {
91     return m_opaque_sp->GetUserID();
92 }
93 
94 uint32_t
95 SBLaunchInfo::GetGroupID()
96 {
97     return m_opaque_sp->GetGroupID();
98 }
99 
100 bool
101 SBLaunchInfo::UserIDIsValid ()
102 {
103     return m_opaque_sp->UserIDIsValid();
104 }
105 
106 bool
107 SBLaunchInfo::GroupIDIsValid ()
108 {
109     return m_opaque_sp->GroupIDIsValid();
110 }
111 
112 void
113 SBLaunchInfo::SetUserID (uint32_t uid)
114 {
115     m_opaque_sp->SetUserID (uid);
116 }
117 
118 void
119 SBLaunchInfo::SetGroupID (uint32_t gid)
120 {
121     m_opaque_sp->SetGroupID (gid);
122 }
123 
124 SBFileSpec
125 SBLaunchInfo::GetExecutableFile ()
126 {
127     return SBFileSpec (m_opaque_sp->GetExecutableFile());
128 }
129 
130 void
131 SBLaunchInfo::SetExecutableFile (SBFileSpec exe_file, bool add_as_first_arg)
132 {
133     m_opaque_sp->SetExecutableFile(exe_file.ref(), add_as_first_arg);
134 }
135 
136 uint32_t
137 SBLaunchInfo::GetNumArguments ()
138 {
139     return m_opaque_sp->GetArguments().GetArgumentCount();
140 }
141 
142 const char *
143 SBLaunchInfo::GetArgumentAtIndex (uint32_t idx)
144 {
145     return m_opaque_sp->GetArguments().GetArgumentAtIndex(idx);
146 }
147 
148 void
149 SBLaunchInfo::SetArguments (const char **argv, bool append)
150 {
151     if (append)
152     {
153         if (argv)
154             m_opaque_sp->GetArguments().AppendArguments(argv);
155     }
156     else
157     {
158         if (argv)
159             m_opaque_sp->GetArguments().SetArguments(argv);
160         else
161             m_opaque_sp->GetArguments().Clear();
162     }
163 }
164 
165 uint32_t
166 SBLaunchInfo::GetNumEnvironmentEntries ()
167 {
168     return m_opaque_sp->GetEnvironmentEntries().GetArgumentCount();
169 }
170 
171 const char *
172 SBLaunchInfo::GetEnvironmentEntryAtIndex (uint32_t idx)
173 {
174     return m_opaque_sp->GetEnvironmentEntries().GetArgumentAtIndex(idx);
175 }
176 
177 void
178 SBLaunchInfo::SetEnvironmentEntries (const char **envp, bool append)
179 {
180     if (append)
181     {
182         if (envp)
183             m_opaque_sp->GetEnvironmentEntries().AppendArguments(envp);
184     }
185     else
186     {
187         if (envp)
188             m_opaque_sp->GetEnvironmentEntries().SetArguments(envp);
189         else
190             m_opaque_sp->GetEnvironmentEntries().Clear();
191     }
192 }
193 
194 void
195 SBLaunchInfo::Clear ()
196 {
197     m_opaque_sp->Clear();
198 }
199 
200 const char *
201 SBLaunchInfo::GetWorkingDirectory () const
202 {
203     return m_opaque_sp->GetWorkingDirectory();
204 }
205 
206 void
207 SBLaunchInfo::SetWorkingDirectory (const char *working_dir)
208 {
209     m_opaque_sp->SetWorkingDirectory(working_dir);
210 }
211 
212 uint32_t
213 SBLaunchInfo::GetLaunchFlags ()
214 {
215     return m_opaque_sp->GetFlags().Get();
216 }
217 
218 void
219 SBLaunchInfo::SetLaunchFlags (uint32_t flags)
220 {
221     m_opaque_sp->GetFlags().Reset(flags);
222 }
223 
224 const char *
225 SBLaunchInfo::GetProcessPluginName ()
226 {
227     return m_opaque_sp->GetProcessPluginName();
228 }
229 
230 void
231 SBLaunchInfo::SetProcessPluginName (const char *plugin_name)
232 {
233     return m_opaque_sp->SetProcessPluginName (plugin_name);
234 }
235 
236 const char *
237 SBLaunchInfo::GetShell ()
238 {
239     // Constify this string so that it is saved in the string pool.  Otherwise
240     // it would be freed when this function goes out of scope.
241     ConstString shell(m_opaque_sp->GetShell().GetPath().c_str());
242     return shell.AsCString();
243 }
244 
245 void
246 SBLaunchInfo::SetShell (const char * path)
247 {
248     m_opaque_sp->SetShell (FileSpec(path, false));
249 }
250 
251 uint32_t
252 SBLaunchInfo::GetResumeCount ()
253 {
254     return m_opaque_sp->GetResumeCount();
255 }
256 
257 void
258 SBLaunchInfo::SetResumeCount (uint32_t c)
259 {
260     m_opaque_sp->SetResumeCount (c);
261 }
262 
263 bool
264 SBLaunchInfo::AddCloseFileAction (int fd)
265 {
266     return m_opaque_sp->AppendCloseFileAction(fd);
267 }
268 
269 bool
270 SBLaunchInfo::AddDuplicateFileAction (int fd, int dup_fd)
271 {
272     return m_opaque_sp->AppendDuplicateFileAction(fd, dup_fd);
273 }
274 
275 bool
276 SBLaunchInfo::AddOpenFileAction (int fd, const char *path, bool read, bool write)
277 {
278     return m_opaque_sp->AppendOpenFileAction(fd, path, read, write);
279 }
280 
281 bool
282 SBLaunchInfo::AddSuppressFileAction (int fd, bool read, bool write)
283 {
284     return m_opaque_sp->AppendSuppressFileAction(fd, read, write);
285 }
286 
287 void
288 SBLaunchInfo::SetLaunchEventData (const char *data)
289 {
290     m_opaque_sp->SetLaunchEventData (data);
291 }
292 
293 const char *
294 SBLaunchInfo::GetLaunchEventData () const
295 {
296     return m_opaque_sp->GetLaunchEventData ();
297 }
298 
299 void
300 SBLaunchInfo::SetDetachOnError (bool enable)
301 {
302     m_opaque_sp->SetDetachOnError (enable);
303 }
304 
305 bool
306 SBLaunchInfo::GetDetachOnError () const
307 {
308     return m_opaque_sp->GetDetachOnError ();
309 }
310 
311 SBAttachInfo::SBAttachInfo () :
312     m_opaque_sp (new ProcessAttachInfo())
313 {
314 }
315 
316 SBAttachInfo::SBAttachInfo (lldb::pid_t pid) :
317     m_opaque_sp (new ProcessAttachInfo())
318 {
319     m_opaque_sp->SetProcessID (pid);
320 }
321 
322 SBAttachInfo::SBAttachInfo (const char *path, bool wait_for) :
323     m_opaque_sp (new ProcessAttachInfo())
324 {
325     if (path && path[0])
326         m_opaque_sp->GetExecutableFile().SetFile(path, false);
327     m_opaque_sp->SetWaitForLaunch (wait_for);
328 }
329 
330 SBAttachInfo::SBAttachInfo (const SBAttachInfo &rhs) :
331     m_opaque_sp (new ProcessAttachInfo())
332 {
333     *m_opaque_sp = *rhs.m_opaque_sp;
334 }
335 
336 SBAttachInfo::~SBAttachInfo()
337 {
338 }
339 
340 lldb_private::ProcessAttachInfo &
341 SBAttachInfo::ref ()
342 {
343     return *m_opaque_sp;
344 }
345 
346 SBAttachInfo &
347 SBAttachInfo::operator = (const SBAttachInfo &rhs)
348 {
349     if (this != &rhs)
350         *m_opaque_sp = *rhs.m_opaque_sp;
351     return *this;
352 }
353 
354 lldb::pid_t
355 SBAttachInfo::GetProcessID ()
356 {
357     return m_opaque_sp->GetProcessID();
358 }
359 
360 void
361 SBAttachInfo::SetProcessID (lldb::pid_t pid)
362 {
363     m_opaque_sp->SetProcessID (pid);
364 }
365 
366 
367 uint32_t
368 SBAttachInfo::GetResumeCount ()
369 {
370     return m_opaque_sp->GetResumeCount();
371 }
372 
373 void
374 SBAttachInfo::SetResumeCount (uint32_t c)
375 {
376     m_opaque_sp->SetResumeCount (c);
377 }
378 
379 const char *
380 SBAttachInfo::GetProcessPluginName ()
381 {
382     return m_opaque_sp->GetProcessPluginName();
383 }
384 
385 void
386 SBAttachInfo::SetProcessPluginName (const char *plugin_name)
387 {
388     return m_opaque_sp->SetProcessPluginName (plugin_name);
389 }
390 
391 void
392 SBAttachInfo::SetExecutable (const char *path)
393 {
394     if (path && path[0])
395         m_opaque_sp->GetExecutableFile().SetFile(path, false);
396     else
397         m_opaque_sp->GetExecutableFile().Clear();
398 }
399 
400 void
401 SBAttachInfo::SetExecutable (SBFileSpec exe_file)
402 {
403     if (exe_file.IsValid())
404         m_opaque_sp->GetExecutableFile() = exe_file.ref();
405     else
406         m_opaque_sp->GetExecutableFile().Clear();
407 }
408 
409 bool
410 SBAttachInfo::GetWaitForLaunch ()
411 {
412     return m_opaque_sp->GetWaitForLaunch();
413 }
414 
415 void
416 SBAttachInfo::SetWaitForLaunch (bool b)
417 {
418     m_opaque_sp->SetWaitForLaunch (b);
419 }
420 
421 bool
422 SBAttachInfo::GetIgnoreExisting ()
423 {
424     return m_opaque_sp->GetIgnoreExisting();
425 }
426 
427 void
428 SBAttachInfo::SetIgnoreExisting (bool b)
429 {
430     m_opaque_sp->SetIgnoreExisting (b);
431 }
432 
433 uint32_t
434 SBAttachInfo::GetUserID()
435 {
436     return m_opaque_sp->GetUserID();
437 }
438 
439 uint32_t
440 SBAttachInfo::GetGroupID()
441 {
442     return m_opaque_sp->GetGroupID();
443 }
444 
445 bool
446 SBAttachInfo::UserIDIsValid ()
447 {
448     return m_opaque_sp->UserIDIsValid();
449 }
450 
451 bool
452 SBAttachInfo::GroupIDIsValid ()
453 {
454     return m_opaque_sp->GroupIDIsValid();
455 }
456 
457 void
458 SBAttachInfo::SetUserID (uint32_t uid)
459 {
460     m_opaque_sp->SetUserID (uid);
461 }
462 
463 void
464 SBAttachInfo::SetGroupID (uint32_t gid)
465 {
466     m_opaque_sp->SetGroupID (gid);
467 }
468 
469 uint32_t
470 SBAttachInfo::GetEffectiveUserID()
471 {
472     return m_opaque_sp->GetEffectiveUserID();
473 }
474 
475 uint32_t
476 SBAttachInfo::GetEffectiveGroupID()
477 {
478     return m_opaque_sp->GetEffectiveGroupID();
479 }
480 
481 bool
482 SBAttachInfo::EffectiveUserIDIsValid ()
483 {
484     return m_opaque_sp->EffectiveUserIDIsValid();
485 }
486 
487 bool
488 SBAttachInfo::EffectiveGroupIDIsValid ()
489 {
490     return m_opaque_sp->EffectiveGroupIDIsValid ();
491 }
492 
493 void
494 SBAttachInfo::SetEffectiveUserID (uint32_t uid)
495 {
496     m_opaque_sp->SetEffectiveUserID(uid);
497 }
498 
499 void
500 SBAttachInfo::SetEffectiveGroupID (uint32_t gid)
501 {
502     m_opaque_sp->SetEffectiveGroupID(gid);
503 }
504 
505 lldb::pid_t
506 SBAttachInfo::GetParentProcessID ()
507 {
508     return m_opaque_sp->GetParentProcessID();
509 }
510 
511 void
512 SBAttachInfo::SetParentProcessID (lldb::pid_t pid)
513 {
514     m_opaque_sp->SetParentProcessID (pid);
515 }
516 
517 bool
518 SBAttachInfo::ParentProcessIDIsValid()
519 {
520     return m_opaque_sp->ParentProcessIDIsValid();
521 }
522 
523 
524 //----------------------------------------------------------------------
525 // SBTarget constructor
526 //----------------------------------------------------------------------
527 SBTarget::SBTarget () :
528     m_opaque_sp ()
529 {
530 }
531 
532 SBTarget::SBTarget (const SBTarget& rhs) :
533     m_opaque_sp (rhs.m_opaque_sp)
534 {
535 }
536 
537 SBTarget::SBTarget(const TargetSP& target_sp) :
538     m_opaque_sp (target_sp)
539 {
540 }
541 
542 const SBTarget&
543 SBTarget::operator = (const SBTarget& rhs)
544 {
545     if (this != &rhs)
546         m_opaque_sp = rhs.m_opaque_sp;
547     return *this;
548 }
549 
550 //----------------------------------------------------------------------
551 // Destructor
552 //----------------------------------------------------------------------
553 SBTarget::~SBTarget()
554 {
555 }
556 
557 const char *
558 SBTarget::GetBroadcasterClassName ()
559 {
560     return Target::GetStaticBroadcasterClass().AsCString();
561 }
562 
563 bool
564 SBTarget::IsValid () const
565 {
566     return m_opaque_sp.get() != NULL && m_opaque_sp->IsValid();
567 }
568 
569 SBProcess
570 SBTarget::GetProcess ()
571 {
572     SBProcess sb_process;
573     ProcessSP process_sp;
574     TargetSP target_sp(GetSP());
575     if (target_sp)
576     {
577         process_sp = target_sp->GetProcessSP();
578         sb_process.SetSP (process_sp);
579     }
580 
581     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
582     if (log)
583         log->Printf ("SBTarget(%p)::GetProcess () => SBProcess(%p)",
584                      static_cast<void*>(target_sp.get()),
585                      static_cast<void*>(process_sp.get()));
586 
587     return sb_process;
588 }
589 
590 SBPlatform
591 SBTarget::GetPlatform ()
592 {
593     TargetSP target_sp(GetSP());
594     if (!target_sp)
595         return SBPlatform();
596 
597     SBPlatform platform;
598     platform.m_opaque_sp = target_sp->GetPlatform();
599 
600     return platform;
601 }
602 
603 SBDebugger
604 SBTarget::GetDebugger () const
605 {
606     SBDebugger debugger;
607     TargetSP target_sp(GetSP());
608     if (target_sp)
609         debugger.reset (target_sp->GetDebugger().shared_from_this());
610     return debugger;
611 }
612 
613 SBProcess
614 SBTarget::LoadCore (const char *core_file)
615 {
616     SBProcess sb_process;
617     TargetSP target_sp(GetSP());
618     if (target_sp)
619     {
620         FileSpec filespec(core_file, true);
621         ProcessSP process_sp (target_sp->CreateProcess(target_sp->GetDebugger().GetListener(),
622                                                        NULL,
623                                                        &filespec));
624         if (process_sp)
625         {
626             process_sp->LoadCore();
627             sb_process.SetSP (process_sp);
628         }
629     }
630     return sb_process;
631 }
632 
633 SBProcess
634 SBTarget::LaunchSimple
635 (
636     char const **argv,
637     char const **envp,
638     const char *working_directory
639 )
640 {
641     char *stdin_path = NULL;
642     char *stdout_path = NULL;
643     char *stderr_path = NULL;
644     uint32_t launch_flags = 0;
645     bool stop_at_entry = false;
646     SBError error;
647     SBListener listener = GetDebugger().GetListener();
648     return Launch (listener,
649                    argv,
650                    envp,
651                    stdin_path,
652                    stdout_path,
653                    stderr_path,
654                    working_directory,
655                    launch_flags,
656                    stop_at_entry,
657                    error);
658 }
659 
660 SBError
661 SBTarget::Install()
662 {
663     SBError sb_error;
664     TargetSP target_sp(GetSP());
665     if (target_sp)
666     {
667         Mutex::Locker api_locker (target_sp->GetAPIMutex());
668         sb_error.ref() = target_sp->Install(NULL);
669     }
670     return sb_error;
671 }
672 
673 SBProcess
674 SBTarget::Launch
675 (
676     SBListener &listener,
677     char const **argv,
678     char const **envp,
679     const char *stdin_path,
680     const char *stdout_path,
681     const char *stderr_path,
682     const char *working_directory,
683     uint32_t launch_flags,   // See LaunchFlags
684     bool stop_at_entry,
685     lldb::SBError& error
686 )
687 {
688     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
689 
690     SBProcess sb_process;
691     ProcessSP process_sp;
692     TargetSP target_sp(GetSP());
693 
694     if (log)
695         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))...",
696                      static_cast<void*>(target_sp.get()),
697                      static_cast<void*>(argv), static_cast<void*>(envp),
698                      stdin_path ? stdin_path : "NULL",
699                      stdout_path ? stdout_path : "NULL",
700                      stderr_path ? stderr_path : "NULL",
701                      working_directory ? working_directory : "NULL",
702                      launch_flags, stop_at_entry,
703                      static_cast<void*>(error.get()));
704 
705     if (target_sp)
706     {
707         Mutex::Locker api_locker (target_sp->GetAPIMutex());
708 
709         if (getenv("LLDB_LAUNCH_FLAG_DISABLE_ASLR"))
710             launch_flags |= eLaunchFlagDisableASLR;
711 
712         StateType state = eStateInvalid;
713         process_sp = target_sp->GetProcessSP();
714         if (process_sp)
715         {
716             state = process_sp->GetState();
717 
718             if (process_sp->IsAlive() && state != eStateConnected)
719             {
720                 if (state == eStateAttaching)
721                     error.SetErrorString ("process attach is in progress");
722                 else
723                     error.SetErrorString ("a process is already being debugged");
724                 return sb_process;
725             }
726         }
727 
728         if (state == eStateConnected)
729         {
730             // If we are already connected, then we have already specified the
731             // listener, so if a valid listener is supplied, we need to error out
732             // to let the client know.
733             if (listener.IsValid())
734             {
735                 error.SetErrorString ("process is connected and already has a listener, pass empty listener");
736                 return sb_process;
737             }
738         }
739 
740         if (getenv("LLDB_LAUNCH_FLAG_DISABLE_STDIO"))
741             launch_flags |= eLaunchFlagDisableSTDIO;
742 
743         ProcessLaunchInfo launch_info (stdin_path, stdout_path, stderr_path, working_directory, launch_flags);
744 
745         Module *exe_module = target_sp->GetExecutableModulePointer();
746         if (exe_module)
747             launch_info.SetExecutableFile(exe_module->GetPlatformFileSpec(), true);
748         if (argv)
749             launch_info.GetArguments().AppendArguments (argv);
750         if (envp)
751             launch_info.GetEnvironmentEntries ().SetArguments (envp);
752 
753         if (listener.IsValid())
754             error.SetError (target_sp->Launch(listener.ref(), launch_info, NULL));
755         else
756             error.SetError (target_sp->Launch(target_sp->GetDebugger().GetListener(), launch_info, NULL));
757 
758         sb_process.SetSP(target_sp->GetProcessSP());
759     }
760     else
761     {
762         error.SetErrorString ("SBTarget is invalid");
763     }
764 
765     log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
766     if (log)
767         log->Printf ("SBTarget(%p)::Launch (...) => SBProcess(%p)",
768                      static_cast<void*>(target_sp.get()),
769                      static_cast<void*>(sb_process.GetSP().get()));
770 
771     return sb_process;
772 }
773 
774 SBProcess
775 SBTarget::Launch (SBLaunchInfo &sb_launch_info, SBError& error)
776 {
777     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
778 
779     SBProcess sb_process;
780     TargetSP target_sp(GetSP());
781 
782     if (log)
783         log->Printf ("SBTarget(%p)::Launch (launch_info, error)...",
784                      static_cast<void*>(target_sp.get()));
785 
786     if (target_sp)
787     {
788         Mutex::Locker api_locker (target_sp->GetAPIMutex());
789         StateType state = eStateInvalid;
790         {
791             ProcessSP process_sp = target_sp->GetProcessSP();
792             if (process_sp)
793             {
794                 state = process_sp->GetState();
795 
796                 if (process_sp->IsAlive() && state != eStateConnected)
797                 {
798                     if (state == eStateAttaching)
799                         error.SetErrorString ("process attach is in progress");
800                     else
801                         error.SetErrorString ("a process is already being debugged");
802                     return sb_process;
803                 }
804             }
805         }
806 
807         lldb_private::ProcessLaunchInfo &launch_info = sb_launch_info.ref();
808 
809         if (!launch_info.GetExecutableFile())
810         {
811             Module *exe_module = target_sp->GetExecutableModulePointer();
812             if (exe_module)
813                 launch_info.SetExecutableFile(exe_module->GetPlatformFileSpec(), true);
814         }
815 
816         const ArchSpec &arch_spec = target_sp->GetArchitecture();
817         if (arch_spec.IsValid())
818             launch_info.GetArchitecture () = arch_spec;
819 
820         error.SetError (target_sp->Launch (target_sp->GetDebugger().GetListener(), launch_info, NULL));
821         sb_process.SetSP(target_sp->GetProcessSP());
822     }
823     else
824     {
825         error.SetErrorString ("SBTarget is invalid");
826     }
827 
828     log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
829     if (log)
830         log->Printf ("SBTarget(%p)::Launch (...) => SBProcess(%p)",
831                      static_cast<void*>(target_sp.get()),
832                      static_cast<void*>(sb_process.GetSP().get()));
833 
834     return sb_process;
835 }
836 
837 lldb::SBProcess
838 SBTarget::Attach (SBAttachInfo &sb_attach_info, SBError& error)
839 {
840     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
841 
842     SBProcess sb_process;
843     ProcessSP process_sp;
844     TargetSP target_sp(GetSP());
845 
846     if (log)
847         log->Printf ("SBTarget(%p)::Attach (sb_attach_info, error)...",
848                      static_cast<void*>(target_sp.get()));
849 
850     if (target_sp)
851     {
852         Mutex::Locker api_locker (target_sp->GetAPIMutex());
853 
854         StateType state = eStateInvalid;
855         process_sp = target_sp->GetProcessSP();
856         if (process_sp)
857         {
858             state = process_sp->GetState();
859 
860             if (process_sp->IsAlive() && state != eStateConnected)
861             {
862                 if (state == eStateAttaching)
863                     error.SetErrorString ("process attach is in progress");
864                 else
865                     error.SetErrorString ("a process is already being debugged");
866                 if (log)
867                     log->Printf ("SBTarget(%p)::Attach (...) => error %s",
868                                  static_cast<void*>(target_sp.get()),
869                                  error.GetCString());
870                 return sb_process;
871             }
872         }
873 
874         if (state != eStateConnected)
875             process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener(), NULL, NULL);
876 
877         if (process_sp)
878         {
879             ProcessAttachInfo &attach_info = sb_attach_info.ref();
880             if (attach_info.ProcessIDIsValid() && !attach_info.UserIDIsValid())
881             {
882                 PlatformSP platform_sp = target_sp->GetPlatform();
883                 // See if we can pre-verify if a process exists or not
884                 if (platform_sp && platform_sp->IsConnected())
885                 {
886                     lldb::pid_t attach_pid = attach_info.GetProcessID();
887                     ProcessInstanceInfo instance_info;
888                     if (platform_sp->GetProcessInfo(attach_pid, instance_info))
889                     {
890                         attach_info.SetUserID(instance_info.GetEffectiveUserID());
891                     }
892                     else
893                     {
894                         error.ref().SetErrorStringWithFormat("no process found with process ID %" PRIu64, attach_pid);
895                         if (log)
896                         {
897                             log->Printf ("SBTarget(%p)::Attach (...) => error %s",
898                                          static_cast<void*>(target_sp.get()), error.GetCString());
899                         }
900                         return sb_process;
901                     }
902                 }
903             }
904             error.SetError (process_sp->Attach (attach_info));
905             if (error.Success())
906             {
907                 sb_process.SetSP (process_sp);
908                 // If we are doing synchronous mode, then wait for the
909                 // process to stop!
910                 if (target_sp->GetDebugger().GetAsyncExecution () == false)
911                     process_sp->WaitForProcessToStop (NULL);
912             }
913         }
914         else
915         {
916             error.SetErrorString ("unable to create lldb_private::Process");
917         }
918     }
919     else
920     {
921         error.SetErrorString ("SBTarget is invalid");
922     }
923 
924     if (log)
925         log->Printf ("SBTarget(%p)::Attach (...) => SBProcess(%p)",
926                      static_cast<void*>(target_sp.get()),
927                      static_cast<void*>(process_sp.get()));
928 
929     return sb_process;
930 }
931 
932 
933 #if defined(__APPLE__)
934 
935 lldb::SBProcess
936 SBTarget::AttachToProcessWithID (SBListener &listener,
937                                 ::pid_t pid,
938                                  lldb::SBError& error)
939 {
940     return AttachToProcessWithID (listener, (lldb::pid_t)pid, error);
941 }
942 
943 #endif // #if defined(__APPLE__)
944 
945 lldb::SBProcess
946 SBTarget::AttachToProcessWithID
947 (
948     SBListener &listener,
949     lldb::pid_t pid,// The process ID to attach to
950     SBError& error  // An error explaining what went wrong if attach fails
951 )
952 {
953     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
954 
955     SBProcess sb_process;
956     ProcessSP process_sp;
957     TargetSP target_sp(GetSP());
958 
959     if (log)
960         log->Printf ("SBTarget(%p)::AttachToProcessWithID (listener, pid=%" PRId64 ", error)...",
961                      static_cast<void*>(target_sp.get()), pid);
962 
963     if (target_sp)
964     {
965         Mutex::Locker api_locker (target_sp->GetAPIMutex());
966 
967         StateType state = eStateInvalid;
968         process_sp = target_sp->GetProcessSP();
969         if (process_sp)
970         {
971             state = process_sp->GetState();
972 
973             if (process_sp->IsAlive() && state != eStateConnected)
974             {
975                 if (state == eStateAttaching)
976                     error.SetErrorString ("process attach is in progress");
977                 else
978                     error.SetErrorString ("a process is already being debugged");
979                 return sb_process;
980             }
981         }
982 
983         if (state == eStateConnected)
984         {
985             // If we are already connected, then we have already specified the
986             // listener, so if a valid listener is supplied, we need to error out
987             // to let the client know.
988             if (listener.IsValid())
989             {
990                 error.SetErrorString ("process is connected and already has a listener, pass empty listener");
991                 return sb_process;
992             }
993         }
994         else
995         {
996             if (listener.IsValid())
997                 process_sp = target_sp->CreateProcess (listener.ref(), NULL, NULL);
998             else
999                 process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener(), NULL, NULL);
1000         }
1001         if (process_sp)
1002         {
1003             sb_process.SetSP (process_sp);
1004 
1005             ProcessAttachInfo attach_info;
1006             attach_info.SetProcessID (pid);
1007 
1008             PlatformSP platform_sp = target_sp->GetPlatform();
1009             ProcessInstanceInfo instance_info;
1010             if (platform_sp->GetProcessInfo(pid, instance_info))
1011             {
1012                 attach_info.SetUserID(instance_info.GetEffectiveUserID());
1013             }
1014             error.SetError (process_sp->Attach (attach_info));
1015             if (error.Success())
1016             {
1017                 // If we are doing synchronous mode, then wait for the
1018                 // process to stop!
1019                 if (target_sp->GetDebugger().GetAsyncExecution () == false)
1020                     process_sp->WaitForProcessToStop (NULL);
1021             }
1022         }
1023         else
1024         {
1025             error.SetErrorString ("unable to create lldb_private::Process");
1026         }
1027     }
1028     else
1029     {
1030         error.SetErrorString ("SBTarget is invalid");
1031     }
1032 
1033     if (log)
1034         log->Printf ("SBTarget(%p)::AttachToProcessWithID (...) => SBProcess(%p)",
1035                      static_cast<void*>(target_sp.get()),
1036                      static_cast<void*>(process_sp.get()));
1037     return sb_process;
1038 }
1039 
1040 lldb::SBProcess
1041 SBTarget::AttachToProcessWithName
1042 (
1043     SBListener &listener,
1044     const char *name,   // basename of process to attach to
1045     bool wait_for,      // if true wait for a new instance of "name" to be launched
1046     SBError& error      // An error explaining what went wrong if attach fails
1047 )
1048 {
1049     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1050 
1051     SBProcess sb_process;
1052     ProcessSP process_sp;
1053     TargetSP target_sp(GetSP());
1054 
1055     if (log)
1056         log->Printf ("SBTarget(%p)::AttachToProcessWithName (listener, name=%s, wait_for=%s, error)...",
1057                      static_cast<void*>(target_sp.get()), name,
1058                      wait_for ? "true" : "false");
1059 
1060     if (name && target_sp)
1061     {
1062         Mutex::Locker api_locker (target_sp->GetAPIMutex());
1063 
1064         StateType state = eStateInvalid;
1065         process_sp = target_sp->GetProcessSP();
1066         if (process_sp)
1067         {
1068             state = process_sp->GetState();
1069 
1070             if (process_sp->IsAlive() && state != eStateConnected)
1071             {
1072                 if (state == eStateAttaching)
1073                     error.SetErrorString ("process attach is in progress");
1074                 else
1075                     error.SetErrorString ("a process is already being debugged");
1076                 return sb_process;
1077             }
1078         }
1079 
1080         if (state == eStateConnected)
1081         {
1082             // If we are already connected, then we have already specified the
1083             // listener, so if a valid listener is supplied, we need to error out
1084             // to let the client know.
1085             if (listener.IsValid())
1086             {
1087                 error.SetErrorString ("process is connected and already has a listener, pass empty listener");
1088                 return sb_process;
1089             }
1090         }
1091         else
1092         {
1093             if (listener.IsValid())
1094                 process_sp = target_sp->CreateProcess (listener.ref(), NULL, NULL);
1095             else
1096                 process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener(), NULL, NULL);
1097         }
1098 
1099         if (process_sp)
1100         {
1101             sb_process.SetSP (process_sp);
1102             ProcessAttachInfo attach_info;
1103             attach_info.GetExecutableFile().SetFile(name, false);
1104             attach_info.SetWaitForLaunch(wait_for);
1105             error.SetError (process_sp->Attach (attach_info));
1106             if (error.Success())
1107             {
1108                 // If we are doing synchronous mode, then wait for the
1109                 // process to stop!
1110                 if (target_sp->GetDebugger().GetAsyncExecution () == false)
1111                     process_sp->WaitForProcessToStop (NULL);
1112             }
1113         }
1114         else
1115         {
1116             error.SetErrorString ("unable to create lldb_private::Process");
1117         }
1118     }
1119     else
1120     {
1121         error.SetErrorString ("SBTarget is invalid");
1122     }
1123 
1124     if (log)
1125         log->Printf ("SBTarget(%p)::AttachToPorcessWithName (...) => SBProcess(%p)",
1126                      static_cast<void*>(target_sp.get()),
1127                      static_cast<void*>(process_sp.get()));
1128     return sb_process;
1129 }
1130 
1131 lldb::SBProcess
1132 SBTarget::ConnectRemote
1133 (
1134     SBListener &listener,
1135     const char *url,
1136     const char *plugin_name,
1137     SBError& error
1138 )
1139 {
1140     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1141 
1142     SBProcess sb_process;
1143     ProcessSP process_sp;
1144     TargetSP target_sp(GetSP());
1145 
1146     if (log)
1147         log->Printf ("SBTarget(%p)::ConnectRemote (listener, url=%s, plugin_name=%s, error)...",
1148                      static_cast<void*>(target_sp.get()), url, plugin_name);
1149 
1150     if (target_sp)
1151     {
1152         Mutex::Locker api_locker (target_sp->GetAPIMutex());
1153         if (listener.IsValid())
1154             process_sp = target_sp->CreateProcess (listener.ref(), plugin_name, NULL);
1155         else
1156             process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener(), plugin_name, NULL);
1157 
1158         if (process_sp)
1159         {
1160             sb_process.SetSP (process_sp);
1161             error.SetError (process_sp->ConnectRemote (NULL, url));
1162         }
1163         else
1164         {
1165             error.SetErrorString ("unable to create lldb_private::Process");
1166         }
1167     }
1168     else
1169     {
1170         error.SetErrorString ("SBTarget is invalid");
1171     }
1172 
1173     if (log)
1174         log->Printf ("SBTarget(%p)::ConnectRemote (...) => SBProcess(%p)",
1175                      static_cast<void*>(target_sp.get()),
1176                      static_cast<void*>(process_sp.get()));
1177     return sb_process;
1178 }
1179 
1180 SBFileSpec
1181 SBTarget::GetExecutable ()
1182 {
1183 
1184     SBFileSpec exe_file_spec;
1185     TargetSP target_sp(GetSP());
1186     if (target_sp)
1187     {
1188         Module *exe_module = target_sp->GetExecutableModulePointer();
1189         if (exe_module)
1190             exe_file_spec.SetFileSpec (exe_module->GetFileSpec());
1191     }
1192 
1193     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1194     if (log)
1195     {
1196         log->Printf ("SBTarget(%p)::GetExecutable () => SBFileSpec(%p)",
1197                      static_cast<void*>(target_sp.get()),
1198                      static_cast<const void*>(exe_file_spec.get()));
1199     }
1200 
1201     return exe_file_spec;
1202 }
1203 
1204 bool
1205 SBTarget::operator == (const SBTarget &rhs) const
1206 {
1207     return m_opaque_sp.get() == rhs.m_opaque_sp.get();
1208 }
1209 
1210 bool
1211 SBTarget::operator != (const SBTarget &rhs) const
1212 {
1213     return m_opaque_sp.get() != rhs.m_opaque_sp.get();
1214 }
1215 
1216 lldb::TargetSP
1217 SBTarget::GetSP () const
1218 {
1219     return m_opaque_sp;
1220 }
1221 
1222 void
1223 SBTarget::SetSP (const lldb::TargetSP& target_sp)
1224 {
1225     m_opaque_sp = target_sp;
1226 }
1227 
1228 lldb::SBAddress
1229 SBTarget::ResolveLoadAddress (lldb::addr_t vm_addr)
1230 {
1231     lldb::SBAddress sb_addr;
1232     Address &addr = sb_addr.ref();
1233     TargetSP target_sp(GetSP());
1234     if (target_sp)
1235     {
1236         Mutex::Locker api_locker (target_sp->GetAPIMutex());
1237         if (target_sp->ResolveLoadAddress (vm_addr, addr))
1238             return sb_addr;
1239     }
1240 
1241     // We have a load address that isn't in a section, just return an address
1242     // with the offset filled in (the address) and the section set to NULL
1243     addr.SetRawAddress(vm_addr);
1244     return sb_addr;
1245 }
1246 
1247 lldb::SBAddress
1248 SBTarget::ResolveFileAddress (lldb::addr_t file_addr)
1249 {
1250     lldb::SBAddress sb_addr;
1251     Address &addr = sb_addr.ref();
1252     TargetSP target_sp(GetSP());
1253     if (target_sp)
1254     {
1255         Mutex::Locker api_locker (target_sp->GetAPIMutex());
1256         if (target_sp->ResolveFileAddress (file_addr, addr))
1257             return sb_addr;
1258     }
1259 
1260     addr.SetRawAddress(file_addr);
1261     return sb_addr;
1262 }
1263 
1264 lldb::SBAddress
1265 SBTarget::ResolvePastLoadAddress (uint32_t stop_id, lldb::addr_t vm_addr)
1266 {
1267     lldb::SBAddress sb_addr;
1268     Address &addr = sb_addr.ref();
1269     TargetSP target_sp(GetSP());
1270     if (target_sp)
1271     {
1272         Mutex::Locker api_locker (target_sp->GetAPIMutex());
1273         if (target_sp->ResolveLoadAddress (vm_addr, addr))
1274             return sb_addr;
1275     }
1276 
1277     // We have a load address that isn't in a section, just return an address
1278     // with the offset filled in (the address) and the section set to NULL
1279     addr.SetRawAddress(vm_addr);
1280     return sb_addr;
1281 }
1282 
1283 SBSymbolContext
1284 SBTarget::ResolveSymbolContextForAddress (const SBAddress& addr,
1285                                           uint32_t resolve_scope)
1286 {
1287     SBSymbolContext sc;
1288     if (addr.IsValid())
1289     {
1290         TargetSP target_sp(GetSP());
1291         if (target_sp)
1292             target_sp->GetImages().ResolveSymbolContextForAddress (addr.ref(), resolve_scope, sc.ref());
1293     }
1294     return sc;
1295 }
1296 
1297 size_t
1298 SBTarget::ReadMemory (const SBAddress addr,
1299                       void *buf,
1300                       size_t size,
1301                       lldb::SBError &error)
1302 {
1303     SBError sb_error;
1304     size_t bytes_read = 0;
1305     TargetSP target_sp(GetSP());
1306     if (target_sp)
1307     {
1308         Mutex::Locker api_locker (target_sp->GetAPIMutex());
1309         lldb_private::Address addr_priv(addr.GetFileAddress(), NULL);
1310         lldb_private::Error err_priv;
1311         bytes_read = target_sp->ReadMemory(addr_priv, false, buf, size, err_priv);
1312         if(err_priv.Fail())
1313         {
1314             sb_error.SetError(err_priv.GetError(), err_priv.GetType());
1315         }
1316     }
1317 
1318     return bytes_read;
1319 }
1320 
1321 SBBreakpoint
1322 SBTarget::BreakpointCreateByLocation (const char *file,
1323                                       uint32_t line)
1324 {
1325     return SBBreakpoint(BreakpointCreateByLocation (SBFileSpec (file, false), line));
1326 }
1327 
1328 SBBreakpoint
1329 SBTarget::BreakpointCreateByLocation (const SBFileSpec &sb_file_spec,
1330                                       uint32_t line)
1331 {
1332     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1333 
1334     SBBreakpoint sb_bp;
1335     TargetSP target_sp(GetSP());
1336     if (target_sp && line != 0)
1337     {
1338         Mutex::Locker api_locker (target_sp->GetAPIMutex());
1339 
1340         const LazyBool check_inlines = eLazyBoolCalculate;
1341         const LazyBool skip_prologue = eLazyBoolCalculate;
1342         const bool internal = false;
1343         const bool hardware = false;
1344         *sb_bp = target_sp->CreateBreakpoint (NULL, *sb_file_spec, line, check_inlines, skip_prologue, internal, hardware);
1345     }
1346 
1347     if (log)
1348     {
1349         SBStream sstr;
1350         sb_bp.GetDescription (sstr);
1351         char path[PATH_MAX];
1352         sb_file_spec->GetPath (path, sizeof(path));
1353         log->Printf ("SBTarget(%p)::BreakpointCreateByLocation ( %s:%u ) => SBBreakpoint(%p): %s",
1354                      static_cast<void*>(target_sp.get()), path, line,
1355                      static_cast<void*>(sb_bp.get()), sstr.GetData());
1356     }
1357 
1358     return sb_bp;
1359 }
1360 
1361 SBBreakpoint
1362 SBTarget::BreakpointCreateByName (const char *symbol_name,
1363                                   const char *module_name)
1364 {
1365     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1366 
1367     SBBreakpoint sb_bp;
1368     TargetSP target_sp(GetSP());
1369     if (target_sp.get())
1370     {
1371         Mutex::Locker api_locker (target_sp->GetAPIMutex());
1372 
1373         const bool internal = false;
1374         const bool hardware = false;
1375         const LazyBool skip_prologue = eLazyBoolCalculate;
1376         if (module_name && module_name[0])
1377         {
1378             FileSpecList module_spec_list;
1379             module_spec_list.Append (FileSpec (module_name, false));
1380             *sb_bp = target_sp->CreateBreakpoint (&module_spec_list, NULL, symbol_name, eFunctionNameTypeAuto, skip_prologue, internal, hardware);
1381         }
1382         else
1383         {
1384             *sb_bp = target_sp->CreateBreakpoint (NULL, NULL, symbol_name, eFunctionNameTypeAuto, skip_prologue, internal, hardware);
1385         }
1386     }
1387 
1388     if (log)
1389         log->Printf ("SBTarget(%p)::BreakpointCreateByName (symbol=\"%s\", module=\"%s\") => SBBreakpoint(%p)",
1390                      static_cast<void*>(target_sp.get()), symbol_name,
1391                      module_name, static_cast<void*>(sb_bp.get()));
1392 
1393     return sb_bp;
1394 }
1395 
1396 lldb::SBBreakpoint
1397 SBTarget::BreakpointCreateByName (const char *symbol_name,
1398                                   const SBFileSpecList &module_list,
1399                                   const SBFileSpecList &comp_unit_list)
1400 {
1401     uint32_t name_type_mask = eFunctionNameTypeAuto;
1402     return BreakpointCreateByName (symbol_name, name_type_mask, module_list, comp_unit_list);
1403 }
1404 
1405 lldb::SBBreakpoint
1406 SBTarget::BreakpointCreateByName (const char *symbol_name,
1407                                   uint32_t name_type_mask,
1408                                   const SBFileSpecList &module_list,
1409                                   const SBFileSpecList &comp_unit_list)
1410 {
1411     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1412 
1413     SBBreakpoint sb_bp;
1414     TargetSP target_sp(GetSP());
1415     if (target_sp && symbol_name && symbol_name[0])
1416     {
1417         const bool internal = false;
1418         const bool hardware = false;
1419         const LazyBool skip_prologue = eLazyBoolCalculate;
1420         Mutex::Locker api_locker (target_sp->GetAPIMutex());
1421         *sb_bp = target_sp->CreateBreakpoint (module_list.get(),
1422                                               comp_unit_list.get(),
1423                                               symbol_name,
1424                                               name_type_mask,
1425                                               skip_prologue,
1426                                               internal,
1427                                               hardware);
1428     }
1429 
1430     if (log)
1431         log->Printf ("SBTarget(%p)::BreakpointCreateByName (symbol=\"%s\", name_type: %d) => SBBreakpoint(%p)",
1432                      static_cast<void*>(target_sp.get()), symbol_name,
1433                      name_type_mask, static_cast<void*>(sb_bp.get()));
1434 
1435     return sb_bp;
1436 }
1437 
1438 lldb::SBBreakpoint
1439 SBTarget::BreakpointCreateByNames (const char *symbol_names[],
1440                                    uint32_t num_names,
1441                                    uint32_t name_type_mask,
1442                                    const SBFileSpecList &module_list,
1443                                    const SBFileSpecList &comp_unit_list)
1444 {
1445     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1446 
1447     SBBreakpoint sb_bp;
1448     TargetSP target_sp(GetSP());
1449     if (target_sp && num_names > 0)
1450     {
1451         Mutex::Locker api_locker (target_sp->GetAPIMutex());
1452         const bool internal = false;
1453         const bool hardware = false;
1454         const LazyBool skip_prologue = eLazyBoolCalculate;
1455         *sb_bp = target_sp->CreateBreakpoint (module_list.get(),
1456                                                 comp_unit_list.get(),
1457                                                 symbol_names,
1458                                                 num_names,
1459                                                 name_type_mask,
1460                                                 skip_prologue,
1461                                                 internal,
1462                                                 hardware);
1463     }
1464 
1465     if (log)
1466     {
1467         log->Printf ("SBTarget(%p)::BreakpointCreateByName (symbols={",
1468                      static_cast<void*>(target_sp.get()));
1469         for (uint32_t i = 0 ; i < num_names; i++)
1470         {
1471             char sep;
1472             if (i < num_names - 1)
1473                 sep = ',';
1474             else
1475                 sep = '}';
1476             if (symbol_names[i] != NULL)
1477                 log->Printf ("\"%s\"%c ", symbol_names[i], sep);
1478             else
1479                 log->Printf ("\"<NULL>\"%c ", sep);
1480         }
1481         log->Printf ("name_type: %d) => SBBreakpoint(%p)", name_type_mask,
1482                      static_cast<void*>(sb_bp.get()));
1483     }
1484 
1485     return sb_bp;
1486 }
1487 
1488 SBBreakpoint
1489 SBTarget::BreakpointCreateByRegex (const char *symbol_name_regex,
1490                                    const char *module_name)
1491 {
1492     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1493 
1494     SBBreakpoint sb_bp;
1495     TargetSP target_sp(GetSP());
1496     if (target_sp && symbol_name_regex && symbol_name_regex[0])
1497     {
1498         Mutex::Locker api_locker (target_sp->GetAPIMutex());
1499         RegularExpression regexp(symbol_name_regex);
1500         const bool internal = false;
1501         const bool hardware = false;
1502         const LazyBool skip_prologue = eLazyBoolCalculate;
1503 
1504         if (module_name && module_name[0])
1505         {
1506             FileSpecList module_spec_list;
1507             module_spec_list.Append (FileSpec (module_name, false));
1508 
1509             *sb_bp = target_sp->CreateFuncRegexBreakpoint (&module_spec_list, NULL, regexp, skip_prologue, internal, hardware);
1510         }
1511         else
1512         {
1513             *sb_bp = target_sp->CreateFuncRegexBreakpoint (NULL, NULL, regexp, skip_prologue, internal, hardware);
1514         }
1515     }
1516 
1517     if (log)
1518         log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (symbol_regex=\"%s\", module_name=\"%s\") => SBBreakpoint(%p)",
1519                      static_cast<void*>(target_sp.get()), symbol_name_regex,
1520                      module_name, static_cast<void*>(sb_bp.get()));
1521 
1522     return sb_bp;
1523 }
1524 
1525 lldb::SBBreakpoint
1526 SBTarget::BreakpointCreateByRegex (const char *symbol_name_regex,
1527                                    const SBFileSpecList &module_list,
1528                                    const SBFileSpecList &comp_unit_list)
1529 {
1530     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1531 
1532     SBBreakpoint sb_bp;
1533     TargetSP target_sp(GetSP());
1534     if (target_sp && symbol_name_regex && symbol_name_regex[0])
1535     {
1536         Mutex::Locker api_locker (target_sp->GetAPIMutex());
1537         RegularExpression regexp(symbol_name_regex);
1538         const bool internal = false;
1539         const bool hardware = false;
1540         const LazyBool skip_prologue = eLazyBoolCalculate;
1541 
1542         *sb_bp = target_sp->CreateFuncRegexBreakpoint (module_list.get(), comp_unit_list.get(), regexp, skip_prologue, internal, hardware);
1543     }
1544 
1545     if (log)
1546         log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (symbol_regex=\"%s\") => SBBreakpoint(%p)",
1547                      static_cast<void*>(target_sp.get()), symbol_name_regex,
1548                      static_cast<void*>(sb_bp.get()));
1549 
1550     return sb_bp;
1551 }
1552 
1553 SBBreakpoint
1554 SBTarget::BreakpointCreateByAddress (addr_t address)
1555 {
1556     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1557 
1558     SBBreakpoint sb_bp;
1559     TargetSP target_sp(GetSP());
1560     if (target_sp)
1561     {
1562         Mutex::Locker api_locker (target_sp->GetAPIMutex());
1563         const bool hardware = false;
1564         *sb_bp = target_sp->CreateBreakpoint (address, false, hardware);
1565     }
1566 
1567     if (log)
1568         log->Printf ("SBTarget(%p)::BreakpointCreateByAddress (address=%" PRIu64 ") => SBBreakpoint(%p)",
1569                      static_cast<void*>(target_sp.get()),
1570                      static_cast<uint64_t>(address),
1571                      static_cast<void*>(sb_bp.get()));
1572 
1573     return sb_bp;
1574 }
1575 
1576 lldb::SBBreakpoint
1577 SBTarget::BreakpointCreateBySourceRegex (const char *source_regex,
1578                                          const lldb::SBFileSpec &source_file,
1579                                          const char *module_name)
1580 {
1581     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1582 
1583     SBBreakpoint sb_bp;
1584     TargetSP target_sp(GetSP());
1585     if (target_sp && source_regex && source_regex[0])
1586     {
1587         Mutex::Locker api_locker (target_sp->GetAPIMutex());
1588         RegularExpression regexp(source_regex);
1589         FileSpecList source_file_spec_list;
1590         const bool hardware = false;
1591         source_file_spec_list.Append (source_file.ref());
1592 
1593         if (module_name && module_name[0])
1594         {
1595             FileSpecList module_spec_list;
1596             module_spec_list.Append (FileSpec (module_name, false));
1597 
1598             *sb_bp = target_sp->CreateSourceRegexBreakpoint (&module_spec_list, &source_file_spec_list, regexp, false, hardware);
1599         }
1600         else
1601         {
1602             *sb_bp = target_sp->CreateSourceRegexBreakpoint (NULL, &source_file_spec_list, regexp, false, hardware);
1603         }
1604     }
1605 
1606     if (log)
1607     {
1608         char path[PATH_MAX];
1609         source_file->GetPath (path, sizeof(path));
1610         log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (source_regex=\"%s\", file=\"%s\", module_name=\"%s\") => SBBreakpoint(%p)",
1611                      static_cast<void*>(target_sp.get()), source_regex, path,
1612                      module_name, static_cast<void*>(sb_bp.get()));
1613     }
1614 
1615     return sb_bp;
1616 }
1617 
1618 lldb::SBBreakpoint
1619 SBTarget::BreakpointCreateBySourceRegex (const char *source_regex,
1620                                          const SBFileSpecList &module_list,
1621                                          const lldb::SBFileSpecList &source_file_list)
1622 {
1623     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1624 
1625     SBBreakpoint sb_bp;
1626     TargetSP target_sp(GetSP());
1627     if (target_sp && source_regex && source_regex[0])
1628     {
1629         Mutex::Locker api_locker (target_sp->GetAPIMutex());
1630         const bool hardware = false;
1631         RegularExpression regexp(source_regex);
1632         *sb_bp = target_sp->CreateSourceRegexBreakpoint (module_list.get(), source_file_list.get(), regexp, false, hardware);
1633     }
1634 
1635     if (log)
1636         log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (source_regex=\"%s\") => SBBreakpoint(%p)",
1637                      static_cast<void*>(target_sp.get()), source_regex,
1638                      static_cast<void*>(sb_bp.get()));
1639 
1640     return sb_bp;
1641 }
1642 
1643 lldb::SBBreakpoint
1644 SBTarget::BreakpointCreateForException  (lldb::LanguageType language,
1645                                          bool catch_bp,
1646                                          bool throw_bp)
1647 {
1648     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1649 
1650     SBBreakpoint sb_bp;
1651     TargetSP target_sp(GetSP());
1652     if (target_sp)
1653     {
1654         Mutex::Locker api_locker (target_sp->GetAPIMutex());
1655         const bool hardware = false;
1656         *sb_bp = target_sp->CreateExceptionBreakpoint (language, catch_bp, throw_bp, hardware);
1657     }
1658 
1659     if (log)
1660         log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (Language: %s, catch: %s throw: %s) => SBBreakpoint(%p)",
1661                      static_cast<void*>(target_sp.get()),
1662                      LanguageRuntime::GetNameForLanguageType(language),
1663                      catch_bp ? "on" : "off", throw_bp ? "on" : "off",
1664                      static_cast<void*>(sb_bp.get()));
1665 
1666     return sb_bp;
1667 }
1668 
1669 uint32_t
1670 SBTarget::GetNumBreakpoints () const
1671 {
1672     TargetSP target_sp(GetSP());
1673     if (target_sp)
1674     {
1675         // The breakpoint list is thread safe, no need to lock
1676         return target_sp->GetBreakpointList().GetSize();
1677     }
1678     return 0;
1679 }
1680 
1681 SBBreakpoint
1682 SBTarget::GetBreakpointAtIndex (uint32_t idx) const
1683 {
1684     SBBreakpoint sb_breakpoint;
1685     TargetSP target_sp(GetSP());
1686     if (target_sp)
1687     {
1688         // The breakpoint list is thread safe, no need to lock
1689         *sb_breakpoint = target_sp->GetBreakpointList().GetBreakpointAtIndex(idx);
1690     }
1691     return sb_breakpoint;
1692 }
1693 
1694 bool
1695 SBTarget::BreakpointDelete (break_id_t bp_id)
1696 {
1697     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1698 
1699     bool result = false;
1700     TargetSP target_sp(GetSP());
1701     if (target_sp)
1702     {
1703         Mutex::Locker api_locker (target_sp->GetAPIMutex());
1704         result = target_sp->RemoveBreakpointByID (bp_id);
1705     }
1706 
1707     if (log)
1708         log->Printf ("SBTarget(%p)::BreakpointDelete (bp_id=%d) => %i",
1709                      static_cast<void*>(target_sp.get()),
1710                      static_cast<uint32_t>(bp_id), result);
1711 
1712     return result;
1713 }
1714 
1715 SBBreakpoint
1716 SBTarget::FindBreakpointByID (break_id_t bp_id)
1717 {
1718     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1719 
1720     SBBreakpoint sb_breakpoint;
1721     TargetSP target_sp(GetSP());
1722     if (target_sp && bp_id != LLDB_INVALID_BREAK_ID)
1723     {
1724         Mutex::Locker api_locker (target_sp->GetAPIMutex());
1725         *sb_breakpoint = target_sp->GetBreakpointByID (bp_id);
1726     }
1727 
1728     if (log)
1729         log->Printf ("SBTarget(%p)::FindBreakpointByID (bp_id=%d) => SBBreakpoint(%p)",
1730                      static_cast<void*>(target_sp.get()),
1731                      static_cast<uint32_t>(bp_id),
1732                      static_cast<void*>(sb_breakpoint.get()));
1733 
1734     return sb_breakpoint;
1735 }
1736 
1737 bool
1738 SBTarget::EnableAllBreakpoints ()
1739 {
1740     TargetSP target_sp(GetSP());
1741     if (target_sp)
1742     {
1743         Mutex::Locker api_locker (target_sp->GetAPIMutex());
1744         target_sp->EnableAllBreakpoints ();
1745         return true;
1746     }
1747     return false;
1748 }
1749 
1750 bool
1751 SBTarget::DisableAllBreakpoints ()
1752 {
1753     TargetSP target_sp(GetSP());
1754     if (target_sp)
1755     {
1756         Mutex::Locker api_locker (target_sp->GetAPIMutex());
1757         target_sp->DisableAllBreakpoints ();
1758         return true;
1759     }
1760     return false;
1761 }
1762 
1763 bool
1764 SBTarget::DeleteAllBreakpoints ()
1765 {
1766     TargetSP target_sp(GetSP());
1767     if (target_sp)
1768     {
1769         Mutex::Locker api_locker (target_sp->GetAPIMutex());
1770         target_sp->RemoveAllBreakpoints ();
1771         return true;
1772     }
1773     return false;
1774 }
1775 
1776 uint32_t
1777 SBTarget::GetNumWatchpoints () const
1778 {
1779     TargetSP target_sp(GetSP());
1780     if (target_sp)
1781     {
1782         // The watchpoint list is thread safe, no need to lock
1783         return target_sp->GetWatchpointList().GetSize();
1784     }
1785     return 0;
1786 }
1787 
1788 SBWatchpoint
1789 SBTarget::GetWatchpointAtIndex (uint32_t idx) const
1790 {
1791     SBWatchpoint sb_watchpoint;
1792     TargetSP target_sp(GetSP());
1793     if (target_sp)
1794     {
1795         // The watchpoint list is thread safe, no need to lock
1796         sb_watchpoint.SetSP (target_sp->GetWatchpointList().GetByIndex(idx));
1797     }
1798     return sb_watchpoint;
1799 }
1800 
1801 bool
1802 SBTarget::DeleteWatchpoint (watch_id_t wp_id)
1803 {
1804     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1805 
1806     bool result = false;
1807     TargetSP target_sp(GetSP());
1808     if (target_sp)
1809     {
1810         Mutex::Locker api_locker (target_sp->GetAPIMutex());
1811         Mutex::Locker locker;
1812         target_sp->GetWatchpointList().GetListMutex(locker);
1813         result = target_sp->RemoveWatchpointByID (wp_id);
1814     }
1815 
1816     if (log)
1817         log->Printf ("SBTarget(%p)::WatchpointDelete (wp_id=%d) => %i",
1818                      static_cast<void*>(target_sp.get()),
1819                      static_cast<uint32_t>(wp_id), result);
1820 
1821     return result;
1822 }
1823 
1824 SBWatchpoint
1825 SBTarget::FindWatchpointByID (lldb::watch_id_t wp_id)
1826 {
1827     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1828 
1829     SBWatchpoint sb_watchpoint;
1830     lldb::WatchpointSP watchpoint_sp;
1831     TargetSP target_sp(GetSP());
1832     if (target_sp && wp_id != LLDB_INVALID_WATCH_ID)
1833     {
1834         Mutex::Locker api_locker (target_sp->GetAPIMutex());
1835         Mutex::Locker locker;
1836         target_sp->GetWatchpointList().GetListMutex(locker);
1837         watchpoint_sp = target_sp->GetWatchpointList().FindByID(wp_id);
1838         sb_watchpoint.SetSP (watchpoint_sp);
1839     }
1840 
1841     if (log)
1842         log->Printf ("SBTarget(%p)::FindWatchpointByID (bp_id=%d) => SBWatchpoint(%p)",
1843                      static_cast<void*>(target_sp.get()),
1844                      static_cast<uint32_t>(wp_id),
1845                      static_cast<void*>(watchpoint_sp.get()));
1846 
1847     return sb_watchpoint;
1848 }
1849 
1850 lldb::SBWatchpoint
1851 SBTarget::WatchAddress (lldb::addr_t addr, size_t size, bool read, bool write, SBError &error)
1852 {
1853     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1854 
1855     SBWatchpoint sb_watchpoint;
1856     lldb::WatchpointSP watchpoint_sp;
1857     TargetSP target_sp(GetSP());
1858     if (target_sp && (read || write) && addr != LLDB_INVALID_ADDRESS && size > 0)
1859     {
1860         Mutex::Locker api_locker (target_sp->GetAPIMutex());
1861         uint32_t watch_type = 0;
1862         if (read)
1863             watch_type |= LLDB_WATCH_TYPE_READ;
1864         if (write)
1865             watch_type |= LLDB_WATCH_TYPE_WRITE;
1866         if (watch_type == 0)
1867         {
1868             error.SetErrorString("Can't create a watchpoint that is neither read nor write.");
1869             return sb_watchpoint;
1870         }
1871 
1872         // Target::CreateWatchpoint() is thread safe.
1873         Error cw_error;
1874         // This API doesn't take in a type, so we can't figure out what it is.
1875         ClangASTType *type = NULL;
1876         watchpoint_sp = target_sp->CreateWatchpoint(addr, size, type, watch_type, cw_error);
1877         error.SetError(cw_error);
1878         sb_watchpoint.SetSP (watchpoint_sp);
1879     }
1880 
1881     if (log)
1882         log->Printf ("SBTarget(%p)::WatchAddress (addr=0x%" PRIx64 ", 0x%u) => SBWatchpoint(%p)",
1883                      static_cast<void*>(target_sp.get()), addr,
1884                      static_cast<uint32_t>(size),
1885                      static_cast<void*>(watchpoint_sp.get()));
1886 
1887     return sb_watchpoint;
1888 }
1889 
1890 bool
1891 SBTarget::EnableAllWatchpoints ()
1892 {
1893     TargetSP target_sp(GetSP());
1894     if (target_sp)
1895     {
1896         Mutex::Locker api_locker (target_sp->GetAPIMutex());
1897         Mutex::Locker locker;
1898         target_sp->GetWatchpointList().GetListMutex(locker);
1899         target_sp->EnableAllWatchpoints ();
1900         return true;
1901     }
1902     return false;
1903 }
1904 
1905 bool
1906 SBTarget::DisableAllWatchpoints ()
1907 {
1908     TargetSP target_sp(GetSP());
1909     if (target_sp)
1910     {
1911         Mutex::Locker api_locker (target_sp->GetAPIMutex());
1912         Mutex::Locker locker;
1913         target_sp->GetWatchpointList().GetListMutex(locker);
1914         target_sp->DisableAllWatchpoints ();
1915         return true;
1916     }
1917     return false;
1918 }
1919 
1920 SBValue
1921 SBTarget::CreateValueFromAddress (const char *name, SBAddress addr, SBType type)
1922 {
1923     SBValue sb_value;
1924     lldb::ValueObjectSP new_value_sp;
1925     if (IsValid() && name && *name && addr.IsValid() && type.IsValid())
1926     {
1927         lldb::addr_t address(addr.GetLoadAddress(*this));
1928         lldb::TypeImplSP type_impl_sp (type.GetSP());
1929         ClangASTType pointer_ast_type(type_impl_sp->GetClangASTType(true).GetPointerType ());
1930         if (pointer_ast_type)
1931         {
1932             lldb::DataBufferSP buffer(new lldb_private::DataBufferHeap(&address,sizeof(lldb::addr_t)));
1933 
1934             ExecutionContext exe_ctx (ExecutionContextRef(ExecutionContext(m_opaque_sp.get(),false)));
1935             ValueObjectSP ptr_result_valobj_sp(ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
1936                                                                                pointer_ast_type,
1937                                                                                ConstString(name),
1938                                                                                buffer,
1939                                                                                exe_ctx.GetByteOrder(),
1940                                                                                exe_ctx.GetAddressByteSize()));
1941 
1942             if (ptr_result_valobj_sp)
1943             {
1944                 ptr_result_valobj_sp->GetValue().SetValueType(Value::eValueTypeLoadAddress);
1945                 Error err;
1946                 new_value_sp = ptr_result_valobj_sp->Dereference(err);
1947                 if (new_value_sp)
1948                     new_value_sp->SetName(ConstString(name));
1949             }
1950         }
1951     }
1952     sb_value.SetSP(new_value_sp);
1953     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1954     if (log)
1955     {
1956         if (new_value_sp)
1957             log->Printf ("SBTarget(%p)::CreateValueFromAddress => \"%s\"",
1958                          static_cast<void*>(m_opaque_sp.get()),
1959                          new_value_sp->GetName().AsCString());
1960         else
1961             log->Printf ("SBTarget(%p)::CreateValueFromAddress => NULL",
1962                          static_cast<void*>(m_opaque_sp.get()));
1963     }
1964     return sb_value;
1965 }
1966 
1967 bool
1968 SBTarget::DeleteAllWatchpoints ()
1969 {
1970     TargetSP target_sp(GetSP());
1971     if (target_sp)
1972     {
1973         Mutex::Locker api_locker (target_sp->GetAPIMutex());
1974         Mutex::Locker locker;
1975         target_sp->GetWatchpointList().GetListMutex(locker);
1976         target_sp->RemoveAllWatchpoints ();
1977         return true;
1978     }
1979     return false;
1980 }
1981 
1982 
1983 lldb::SBModule
1984 SBTarget::AddModule (const char *path,
1985                      const char *triple,
1986                      const char *uuid_cstr)
1987 {
1988     return AddModule (path, triple, uuid_cstr, NULL);
1989 }
1990 
1991 lldb::SBModule
1992 SBTarget::AddModule (const char *path,
1993                      const char *triple,
1994                      const char *uuid_cstr,
1995                      const char *symfile)
1996 {
1997     lldb::SBModule sb_module;
1998     TargetSP target_sp(GetSP());
1999     if (target_sp)
2000     {
2001         ModuleSpec module_spec;
2002         if (path)
2003             module_spec.GetFileSpec().SetFile(path, false);
2004 
2005         if (uuid_cstr)
2006             module_spec.GetUUID().SetFromCString(uuid_cstr);
2007 
2008         if (triple)
2009             module_spec.GetArchitecture().SetTriple (triple, target_sp->GetPlatform ().get());
2010         else
2011             module_spec.GetArchitecture() = target_sp->GetArchitecture();
2012 
2013         if (symfile)
2014             module_spec.GetSymbolFileSpec ().SetFile(symfile, false);
2015 
2016         sb_module.SetSP(target_sp->GetSharedModule (module_spec));
2017     }
2018     return sb_module;
2019 }
2020 
2021 lldb::SBModule
2022 SBTarget::AddModule (const SBModuleSpec &module_spec)
2023 {
2024     lldb::SBModule sb_module;
2025     TargetSP target_sp(GetSP());
2026     if (target_sp)
2027         sb_module.SetSP(target_sp->GetSharedModule (*module_spec.m_opaque_ap));
2028     return sb_module;
2029 }
2030 
2031 bool
2032 SBTarget::AddModule (lldb::SBModule &module)
2033 {
2034     TargetSP target_sp(GetSP());
2035     if (target_sp)
2036     {
2037         target_sp->GetImages().AppendIfNeeded (module.GetSP());
2038         return true;
2039     }
2040     return false;
2041 }
2042 
2043 uint32_t
2044 SBTarget::GetNumModules () const
2045 {
2046     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
2047 
2048     uint32_t num = 0;
2049     TargetSP target_sp(GetSP());
2050     if (target_sp)
2051     {
2052         // The module list is thread safe, no need to lock
2053         num = target_sp->GetImages().GetSize();
2054     }
2055 
2056     if (log)
2057         log->Printf ("SBTarget(%p)::GetNumModules () => %d",
2058                      static_cast<void*>(target_sp.get()), num);
2059 
2060     return num;
2061 }
2062 
2063 void
2064 SBTarget::Clear ()
2065 {
2066     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
2067 
2068     if (log)
2069         log->Printf ("SBTarget(%p)::Clear ()",
2070                      static_cast<void*>(m_opaque_sp.get()));
2071 
2072     m_opaque_sp.reset();
2073 }
2074 
2075 
2076 SBModule
2077 SBTarget::FindModule (const SBFileSpec &sb_file_spec)
2078 {
2079     SBModule sb_module;
2080     TargetSP target_sp(GetSP());
2081     if (target_sp && sb_file_spec.IsValid())
2082     {
2083         ModuleSpec module_spec(*sb_file_spec);
2084         // The module list is thread safe, no need to lock
2085         sb_module.SetSP (target_sp->GetImages().FindFirstModule (module_spec));
2086     }
2087     return sb_module;
2088 }
2089 
2090 lldb::ByteOrder
2091 SBTarget::GetByteOrder ()
2092 {
2093     TargetSP target_sp(GetSP());
2094     if (target_sp)
2095         return target_sp->GetArchitecture().GetByteOrder();
2096     return eByteOrderInvalid;
2097 }
2098 
2099 const char *
2100 SBTarget::GetTriple ()
2101 {
2102     TargetSP target_sp(GetSP());
2103     if (target_sp)
2104     {
2105         std::string triple (target_sp->GetArchitecture().GetTriple().str());
2106         // Unique the string so we don't run into ownership issues since
2107         // the const strings put the string into the string pool once and
2108         // the strings never comes out
2109         ConstString const_triple (triple.c_str());
2110         return const_triple.GetCString();
2111     }
2112     return NULL;
2113 }
2114 
2115 uint32_t
2116 SBTarget::GetDataByteSize ()
2117 {
2118     TargetSP target_sp(GetSP());
2119     if (target_sp)
2120     {
2121         return target_sp->GetArchitecture().GetDataByteSize() ;
2122     }
2123     return 0;
2124 }
2125 
2126 uint32_t
2127 SBTarget::GetCodeByteSize ()
2128 {
2129     TargetSP target_sp(GetSP());
2130     if (target_sp)
2131     {
2132         return target_sp->GetArchitecture().GetCodeByteSize() ;
2133     }
2134     return 0;
2135 }
2136 
2137 uint32_t
2138 SBTarget::GetAddressByteSize()
2139 {
2140     TargetSP target_sp(GetSP());
2141     if (target_sp)
2142         return target_sp->GetArchitecture().GetAddressByteSize();
2143     return sizeof(void*);
2144 }
2145 
2146 
2147 SBModule
2148 SBTarget::GetModuleAtIndex (uint32_t idx)
2149 {
2150     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
2151 
2152     SBModule sb_module;
2153     ModuleSP module_sp;
2154     TargetSP target_sp(GetSP());
2155     if (target_sp)
2156     {
2157         // The module list is thread safe, no need to lock
2158         module_sp = target_sp->GetImages().GetModuleAtIndex(idx);
2159         sb_module.SetSP (module_sp);
2160     }
2161 
2162     if (log)
2163         log->Printf ("SBTarget(%p)::GetModuleAtIndex (idx=%d) => SBModule(%p)",
2164                      static_cast<void*>(target_sp.get()), idx,
2165                      static_cast<void*>(module_sp.get()));
2166 
2167     return sb_module;
2168 }
2169 
2170 bool
2171 SBTarget::RemoveModule (lldb::SBModule module)
2172 {
2173     TargetSP target_sp(GetSP());
2174     if (target_sp)
2175         return target_sp->GetImages().Remove(module.GetSP());
2176     return false;
2177 }
2178 
2179 
2180 SBBroadcaster
2181 SBTarget::GetBroadcaster () const
2182 {
2183     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
2184 
2185     TargetSP target_sp(GetSP());
2186     SBBroadcaster broadcaster(target_sp.get(), false);
2187 
2188     if (log)
2189         log->Printf ("SBTarget(%p)::GetBroadcaster () => SBBroadcaster(%p)",
2190                      static_cast<void*>(target_sp.get()),
2191                      static_cast<void*>(broadcaster.get()));
2192 
2193     return broadcaster;
2194 }
2195 
2196 bool
2197 SBTarget::GetDescription (SBStream &description, lldb::DescriptionLevel description_level)
2198 {
2199     Stream &strm = description.ref();
2200 
2201     TargetSP target_sp(GetSP());
2202     if (target_sp)
2203     {
2204         target_sp->Dump (&strm, description_level);
2205     }
2206     else
2207         strm.PutCString ("No value");
2208 
2209     return true;
2210 }
2211 
2212 lldb::SBSymbolContextList
2213 SBTarget::FindFunctions (const char *name, uint32_t name_type_mask)
2214 {
2215     lldb::SBSymbolContextList sb_sc_list;
2216     if (name && name[0])
2217     {
2218         TargetSP target_sp(GetSP());
2219         if (target_sp)
2220         {
2221             const bool symbols_ok = true;
2222             const bool inlines_ok = true;
2223             const bool append = true;
2224             target_sp->GetImages().FindFunctions (ConstString(name),
2225                                                   name_type_mask,
2226                                                   symbols_ok,
2227                                                   inlines_ok,
2228                                                   append,
2229                                                   *sb_sc_list);
2230         }
2231     }
2232     return sb_sc_list;
2233 }
2234 
2235 lldb::SBSymbolContextList
2236 SBTarget::FindGlobalFunctions(const char *name, uint32_t max_matches, MatchType matchtype)
2237 {
2238     lldb::SBSymbolContextList sb_sc_list;
2239     if (name && name[0])
2240     {
2241         TargetSP target_sp(GetSP());
2242         if (target_sp)
2243         {
2244             std::string regexstr;
2245             switch (matchtype)
2246             {
2247             case eMatchTypeRegex:
2248                 target_sp->GetImages().FindFunctions(RegularExpression(name), true, true, true, *sb_sc_list);
2249                 break;
2250             case eMatchTypeStartsWith:
2251                 regexstr = llvm::Regex::escape(name) + ".*";
2252                 target_sp->GetImages().FindFunctions(RegularExpression(regexstr.c_str()), true, true, true, *sb_sc_list);
2253                 break;
2254             default:
2255                 target_sp->GetImages().FindFunctions(ConstString(name), eFunctionNameTypeAny, true, true, true, *sb_sc_list);
2256                 break;
2257             }
2258         }
2259     }
2260     return sb_sc_list;
2261 }
2262 
2263 lldb::SBType
2264 SBTarget::FindFirstType (const char* typename_cstr)
2265 {
2266     TargetSP target_sp(GetSP());
2267     if (typename_cstr && typename_cstr[0] && target_sp)
2268     {
2269         ConstString const_typename(typename_cstr);
2270         SymbolContext sc;
2271         const bool exact_match = false;
2272 
2273         const ModuleList &module_list = target_sp->GetImages();
2274         size_t count = module_list.GetSize();
2275         for (size_t idx = 0; idx < count; idx++)
2276         {
2277             ModuleSP module_sp (module_list.GetModuleAtIndex(idx));
2278             if (module_sp)
2279             {
2280                 TypeSP type_sp (module_sp->FindFirstType(sc, const_typename, exact_match));
2281                 if (type_sp)
2282                     return SBType(type_sp);
2283             }
2284         }
2285 
2286         // Didn't find the type in the symbols; try the Objective-C runtime
2287         // if one is installed
2288 
2289         ProcessSP process_sp(target_sp->GetProcessSP());
2290 
2291         if (process_sp)
2292         {
2293             ObjCLanguageRuntime *objc_language_runtime = process_sp->GetObjCLanguageRuntime();
2294 
2295             if (objc_language_runtime)
2296             {
2297                 TypeVendor *objc_type_vendor = objc_language_runtime->GetTypeVendor();
2298 
2299                 if (objc_type_vendor)
2300                 {
2301                     std::vector <ClangASTType> types;
2302 
2303                     if (objc_type_vendor->FindTypes(const_typename, true, 1, types) > 0)
2304                         return SBType(types[0]);
2305                 }
2306             }
2307         }
2308 
2309         // No matches, search for basic typename matches
2310         ClangASTContext *clang_ast = target_sp->GetScratchClangASTContext();
2311         if (clang_ast)
2312             return SBType (ClangASTContext::GetBasicType (clang_ast->getASTContext(), const_typename));
2313     }
2314     return SBType();
2315 }
2316 
2317 SBType
2318 SBTarget::GetBasicType(lldb::BasicType type)
2319 {
2320     TargetSP target_sp(GetSP());
2321     if (target_sp)
2322     {
2323         ClangASTContext *clang_ast = target_sp->GetScratchClangASTContext();
2324         if (clang_ast)
2325             return SBType (ClangASTContext::GetBasicType (clang_ast->getASTContext(), type));
2326     }
2327     return SBType();
2328 }
2329 
2330 
2331 lldb::SBTypeList
2332 SBTarget::FindTypes (const char* typename_cstr)
2333 {
2334     SBTypeList sb_type_list;
2335     TargetSP target_sp(GetSP());
2336     if (typename_cstr && typename_cstr[0] && target_sp)
2337     {
2338         ModuleList& images = target_sp->GetImages();
2339         ConstString const_typename(typename_cstr);
2340         bool exact_match = false;
2341         SymbolContext sc;
2342         TypeList type_list;
2343 
2344         uint32_t num_matches = images.FindTypes (sc,
2345                                                  const_typename,
2346                                                  exact_match,
2347                                                  UINT32_MAX,
2348                                                  type_list);
2349 
2350         if (num_matches > 0)
2351         {
2352             for (size_t idx = 0; idx < num_matches; idx++)
2353             {
2354                 TypeSP type_sp (type_list.GetTypeAtIndex(idx));
2355                 if (type_sp)
2356                     sb_type_list.Append(SBType(type_sp));
2357             }
2358         }
2359 
2360         // Try the Objective-C runtime if one is installed
2361 
2362         ProcessSP process_sp(target_sp->GetProcessSP());
2363 
2364         if (process_sp)
2365         {
2366             ObjCLanguageRuntime *objc_language_runtime = process_sp->GetObjCLanguageRuntime();
2367 
2368             if (objc_language_runtime)
2369             {
2370                 TypeVendor *objc_type_vendor = objc_language_runtime->GetTypeVendor();
2371 
2372                 if (objc_type_vendor)
2373                 {
2374                     std::vector <ClangASTType> types;
2375 
2376                     if (objc_type_vendor->FindTypes(const_typename, true, UINT32_MAX, types))
2377                     {
2378                         for (ClangASTType &type : types)
2379                         {
2380                             sb_type_list.Append(SBType(type));
2381                         }
2382                     }
2383                 }
2384             }
2385         }
2386 
2387         if (sb_type_list.GetSize() == 0)
2388         {
2389             // No matches, search for basic typename matches
2390             ClangASTContext *clang_ast = target_sp->GetScratchClangASTContext();
2391             if (clang_ast)
2392                 sb_type_list.Append (SBType (ClangASTContext::GetBasicType (clang_ast->getASTContext(), const_typename)));
2393         }
2394     }
2395     return sb_type_list;
2396 }
2397 
2398 SBValueList
2399 SBTarget::FindGlobalVariables (const char *name, uint32_t max_matches)
2400 {
2401     SBValueList sb_value_list;
2402 
2403     TargetSP target_sp(GetSP());
2404     if (name && target_sp)
2405     {
2406         VariableList variable_list;
2407         const bool append = true;
2408         const uint32_t match_count = target_sp->GetImages().FindGlobalVariables (ConstString (name),
2409                                                                                  append,
2410                                                                                  max_matches,
2411                                                                                  variable_list);
2412 
2413         if (match_count > 0)
2414         {
2415             ExecutionContextScope *exe_scope = target_sp->GetProcessSP().get();
2416             if (exe_scope == NULL)
2417                 exe_scope = target_sp.get();
2418             for (uint32_t i=0; i<match_count; ++i)
2419             {
2420                 lldb::ValueObjectSP valobj_sp (ValueObjectVariable::Create (exe_scope, variable_list.GetVariableAtIndex(i)));
2421                 if (valobj_sp)
2422                     sb_value_list.Append(SBValue(valobj_sp));
2423             }
2424         }
2425     }
2426 
2427     return sb_value_list;
2428 }
2429 
2430 SBValueList
2431 SBTarget::FindGlobalVariables(const char *name, uint32_t max_matches, MatchType matchtype)
2432 {
2433     SBValueList sb_value_list;
2434 
2435     TargetSP target_sp(GetSP());
2436     if (name && target_sp)
2437     {
2438         VariableList variable_list;
2439         const bool append = true;
2440 
2441         std::string regexstr;
2442         uint32_t match_count;
2443         switch (matchtype)
2444         {
2445         case eMatchTypeNormal:
2446             match_count = target_sp->GetImages().FindGlobalVariables(ConstString(name),
2447                 append,
2448                 max_matches,
2449                 variable_list);
2450             break;
2451         case eMatchTypeRegex:
2452             match_count = target_sp->GetImages().FindGlobalVariables(RegularExpression(name),
2453                 append,
2454                 max_matches,
2455                 variable_list);
2456             break;
2457         case eMatchTypeStartsWith:
2458             regexstr = llvm::Regex::escape(name) + ".*";
2459             match_count = target_sp->GetImages().FindGlobalVariables(RegularExpression(regexstr.c_str()),
2460                 append,
2461                 max_matches,
2462                 variable_list);
2463             break;
2464         }
2465 
2466 
2467         if (match_count > 0)
2468         {
2469             ExecutionContextScope *exe_scope = target_sp->GetProcessSP().get();
2470             if (exe_scope == NULL)
2471                 exe_scope = target_sp.get();
2472             for (uint32_t i = 0; i<match_count; ++i)
2473             {
2474                 lldb::ValueObjectSP valobj_sp(ValueObjectVariable::Create(exe_scope, variable_list.GetVariableAtIndex(i)));
2475                 if (valobj_sp)
2476                     sb_value_list.Append(SBValue(valobj_sp));
2477             }
2478         }
2479     }
2480 
2481     return sb_value_list;
2482 }
2483 
2484 
2485 lldb::SBValue
2486 SBTarget::FindFirstGlobalVariable (const char* name)
2487 {
2488     SBValueList sb_value_list(FindGlobalVariables(name, 1));
2489     if (sb_value_list.IsValid() && sb_value_list.GetSize() > 0)
2490         return sb_value_list.GetValueAtIndex(0);
2491     return SBValue();
2492 }
2493 
2494 SBSourceManager
2495 SBTarget::GetSourceManager()
2496 {
2497     SBSourceManager source_manager (*this);
2498     return source_manager;
2499 }
2500 
2501 lldb::SBInstructionList
2502 SBTarget::ReadInstructions (lldb::SBAddress base_addr, uint32_t count)
2503 {
2504     return ReadInstructions (base_addr, count, NULL);
2505 }
2506 
2507 lldb::SBInstructionList
2508 SBTarget::ReadInstructions (lldb::SBAddress base_addr, uint32_t count, const char *flavor_string)
2509 {
2510     SBInstructionList sb_instructions;
2511 
2512     TargetSP target_sp(GetSP());
2513     if (target_sp)
2514     {
2515         Address *addr_ptr = base_addr.get();
2516 
2517         if (addr_ptr)
2518         {
2519             DataBufferHeap data (target_sp->GetArchitecture().GetMaximumOpcodeByteSize() * count, 0);
2520             bool prefer_file_cache = false;
2521             lldb_private::Error error;
2522             lldb::addr_t load_addr = LLDB_INVALID_ADDRESS;
2523             const size_t bytes_read = target_sp->ReadMemory(*addr_ptr,
2524                                                             prefer_file_cache,
2525                                                             data.GetBytes(),
2526                                                             data.GetByteSize(),
2527                                                             error,
2528                                                             &load_addr);
2529             const bool data_from_file = load_addr == LLDB_INVALID_ADDRESS;
2530             sb_instructions.SetDisassembler (Disassembler::DisassembleBytes (target_sp->GetArchitecture(),
2531                                                                              NULL,
2532                                                                              flavor_string,
2533                                                                              *addr_ptr,
2534                                                                              data.GetBytes(),
2535                                                                              bytes_read,
2536                                                                              count,
2537                                                                              data_from_file));
2538         }
2539     }
2540 
2541     return sb_instructions;
2542 
2543 }
2544 
2545 lldb::SBInstructionList
2546 SBTarget::GetInstructions (lldb::SBAddress base_addr, const void *buf, size_t size)
2547 {
2548     return GetInstructionsWithFlavor (base_addr, NULL, buf, size);
2549 }
2550 
2551 lldb::SBInstructionList
2552 SBTarget::GetInstructionsWithFlavor (lldb::SBAddress base_addr, const char *flavor_string, const void *buf, size_t size)
2553 {
2554     SBInstructionList sb_instructions;
2555 
2556     TargetSP target_sp(GetSP());
2557     if (target_sp)
2558     {
2559         Address addr;
2560 
2561         if (base_addr.get())
2562             addr = *base_addr.get();
2563 
2564         const bool data_from_file = true;
2565 
2566         sb_instructions.SetDisassembler (Disassembler::DisassembleBytes (target_sp->GetArchitecture(),
2567                                                                          NULL,
2568                                                                          flavor_string,
2569                                                                          addr,
2570                                                                          buf,
2571                                                                          size,
2572                                                                          UINT32_MAX,
2573                                                                          data_from_file));
2574     }
2575 
2576     return sb_instructions;
2577 }
2578 
2579 lldb::SBInstructionList
2580 SBTarget::GetInstructions (lldb::addr_t base_addr, const void *buf, size_t size)
2581 {
2582     return GetInstructionsWithFlavor (ResolveLoadAddress(base_addr), NULL, buf, size);
2583 }
2584 
2585 lldb::SBInstructionList
2586 SBTarget::GetInstructionsWithFlavor (lldb::addr_t base_addr, const char *flavor_string, const void *buf, size_t size)
2587 {
2588     return GetInstructionsWithFlavor (ResolveLoadAddress(base_addr), flavor_string, buf, size);
2589 }
2590 
2591 SBError
2592 SBTarget::SetSectionLoadAddress (lldb::SBSection section,
2593                                  lldb::addr_t section_base_addr)
2594 {
2595     SBError sb_error;
2596     TargetSP target_sp(GetSP());
2597     if (target_sp)
2598     {
2599         if (!section.IsValid())
2600         {
2601             sb_error.SetErrorStringWithFormat ("invalid section");
2602         }
2603         else
2604         {
2605             SectionSP section_sp (section.GetSP());
2606             if (section_sp)
2607             {
2608                 if (section_sp->IsThreadSpecific())
2609                 {
2610                     sb_error.SetErrorString ("thread specific sections are not yet supported");
2611                 }
2612                 else
2613                 {
2614                     ProcessSP process_sp (target_sp->GetProcessSP());
2615                     if (target_sp->SetSectionLoadAddress (section_sp, section_base_addr))
2616                     {
2617                         // Flush info in the process (stack frames, etc)
2618                         if (process_sp)
2619                             process_sp->Flush();
2620                     }
2621                 }
2622             }
2623         }
2624     }
2625     else
2626     {
2627         sb_error.SetErrorString ("invalid target");
2628     }
2629     return sb_error;
2630 }
2631 
2632 SBError
2633 SBTarget::ClearSectionLoadAddress (lldb::SBSection section)
2634 {
2635     SBError sb_error;
2636 
2637     TargetSP target_sp(GetSP());
2638     if (target_sp)
2639     {
2640         if (!section.IsValid())
2641         {
2642             sb_error.SetErrorStringWithFormat ("invalid section");
2643         }
2644         else
2645         {
2646             ProcessSP process_sp (target_sp->GetProcessSP());
2647             if (target_sp->SetSectionUnloaded (section.GetSP()))
2648             {
2649                 // Flush info in the process (stack frames, etc)
2650                 if (process_sp)
2651                     process_sp->Flush();
2652             }
2653         }
2654     }
2655     else
2656     {
2657         sb_error.SetErrorStringWithFormat ("invalid target");
2658     }
2659     return sb_error;
2660 }
2661 
2662 SBError
2663 SBTarget::SetModuleLoadAddress (lldb::SBModule module, int64_t slide_offset)
2664 {
2665     SBError sb_error;
2666 
2667     TargetSP target_sp(GetSP());
2668     if (target_sp)
2669     {
2670         ModuleSP module_sp (module.GetSP());
2671         if (module_sp)
2672         {
2673             bool changed = false;
2674             if (module_sp->SetLoadAddress (*target_sp, slide_offset, true, changed))
2675             {
2676                 // The load was successful, make sure that at least some sections
2677                 // changed before we notify that our module was loaded.
2678                 if (changed)
2679                 {
2680                     ModuleList module_list;
2681                     module_list.Append(module_sp);
2682                     target_sp->ModulesDidLoad (module_list);
2683                     // Flush info in the process (stack frames, etc)
2684                     ProcessSP process_sp (target_sp->GetProcessSP());
2685                     if (process_sp)
2686                         process_sp->Flush();
2687                 }
2688             }
2689         }
2690         else
2691         {
2692             sb_error.SetErrorStringWithFormat ("invalid module");
2693         }
2694 
2695     }
2696     else
2697     {
2698         sb_error.SetErrorStringWithFormat ("invalid target");
2699     }
2700     return sb_error;
2701 }
2702 
2703 SBError
2704 SBTarget::ClearModuleLoadAddress (lldb::SBModule module)
2705 {
2706     SBError sb_error;
2707 
2708     char path[PATH_MAX];
2709     TargetSP target_sp(GetSP());
2710     if (target_sp)
2711     {
2712         ModuleSP module_sp (module.GetSP());
2713         if (module_sp)
2714         {
2715             ObjectFile *objfile = module_sp->GetObjectFile();
2716             if (objfile)
2717             {
2718                 SectionList *section_list = objfile->GetSectionList();
2719                 if (section_list)
2720                 {
2721                     ProcessSP process_sp (target_sp->GetProcessSP());
2722 
2723                     bool changed = false;
2724                     const size_t num_sections = section_list->GetSize();
2725                     for (size_t sect_idx = 0; sect_idx < num_sections; ++sect_idx)
2726                     {
2727                         SectionSP section_sp (section_list->GetSectionAtIndex(sect_idx));
2728                         if (section_sp)
2729                             changed |= target_sp->SetSectionUnloaded (section_sp);
2730                     }
2731                     if (changed)
2732                     {
2733                         // Flush info in the process (stack frames, etc)
2734                         ProcessSP process_sp (target_sp->GetProcessSP());
2735                         if (process_sp)
2736                             process_sp->Flush();
2737                     }
2738                 }
2739                 else
2740                 {
2741                     module_sp->GetFileSpec().GetPath (path, sizeof(path));
2742                     sb_error.SetErrorStringWithFormat ("no sections in object file '%s'", path);
2743                 }
2744             }
2745             else
2746             {
2747                 module_sp->GetFileSpec().GetPath (path, sizeof(path));
2748                 sb_error.SetErrorStringWithFormat ("no object file for module '%s'", path);
2749             }
2750         }
2751         else
2752         {
2753             sb_error.SetErrorStringWithFormat ("invalid module");
2754         }
2755     }
2756     else
2757     {
2758         sb_error.SetErrorStringWithFormat ("invalid target");
2759     }
2760     return sb_error;
2761 }
2762 
2763 
2764 lldb::SBSymbolContextList
2765 SBTarget::FindSymbols (const char *name, lldb::SymbolType symbol_type)
2766 {
2767     SBSymbolContextList sb_sc_list;
2768     if (name && name[0])
2769     {
2770         TargetSP target_sp(GetSP());
2771         if (target_sp)
2772         {
2773             bool append = true;
2774             target_sp->GetImages().FindSymbolsWithNameAndType (ConstString(name),
2775                                                                symbol_type,
2776                                                                *sb_sc_list,
2777                                                                append);
2778         }
2779     }
2780     return sb_sc_list;
2781 
2782 }
2783 
2784 
2785 lldb::SBValue
2786 SBTarget::EvaluateExpression (const char *expr, const SBExpressionOptions &options)
2787 {
2788     Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
2789     Log * expr_log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
2790     SBValue expr_result;
2791     ExpressionResults exe_results = eExpressionSetupError;
2792     ValueObjectSP expr_value_sp;
2793     TargetSP target_sp(GetSP());
2794     StackFrame *frame = NULL;
2795     if (target_sp)
2796     {
2797         if (expr == NULL || expr[0] == '\0')
2798         {
2799             if (log)
2800                 log->Printf ("SBTarget::EvaluateExpression called with an empty expression");
2801             return expr_result;
2802         }
2803 
2804         Mutex::Locker api_locker (target_sp->GetAPIMutex());
2805         ExecutionContext exe_ctx (m_opaque_sp.get());
2806 
2807         if (log)
2808             log->Printf ("SBTarget()::EvaluateExpression (expr=\"%s\")...", expr);
2809 
2810         frame = exe_ctx.GetFramePtr();
2811         Target *target = exe_ctx.GetTargetPtr();
2812 
2813         if (target)
2814         {
2815 #ifdef LLDB_CONFIGURATION_DEBUG
2816             StreamString frame_description;
2817             if (frame)
2818                 frame->DumpUsingSettingsFormat (&frame_description);
2819             Host::SetCrashDescriptionWithFormat ("SBTarget::EvaluateExpression (expr = \"%s\", fetch_dynamic_value = %u) %s",
2820                                                  expr, options.GetFetchDynamicValue(), frame_description.GetString().c_str());
2821 #endif
2822             exe_results = target->EvaluateExpression (expr,
2823                                                       frame,
2824                                                       expr_value_sp,
2825                                                       options.ref());
2826 
2827             expr_result.SetSP(expr_value_sp, options.GetFetchDynamicValue());
2828 #ifdef LLDB_CONFIGURATION_DEBUG
2829             Host::SetCrashDescription (NULL);
2830 #endif
2831         }
2832         else
2833         {
2834             if (log)
2835                 log->Printf ("SBTarget::EvaluateExpression () => error: could not reconstruct frame object for this SBTarget.");
2836         }
2837     }
2838 #ifndef LLDB_DISABLE_PYTHON
2839     if (expr_log)
2840         expr_log->Printf("** [SBTarget::EvaluateExpression] Expression result is %s, summary %s **",
2841                          expr_result.GetValue(), expr_result.GetSummary());
2842 
2843     if (log)
2844         log->Printf ("SBTarget(%p)::EvaluateExpression (expr=\"%s\") => SBValue(%p) (execution result=%d)",
2845                      static_cast<void*>(frame), expr,
2846                      static_cast<void*>(expr_value_sp.get()), exe_results);
2847 #endif
2848 
2849     return expr_result;
2850 }
2851 
2852 
2853 lldb::addr_t
2854 SBTarget::GetStackRedZoneSize()
2855 {
2856     TargetSP target_sp(GetSP());
2857     if (target_sp)
2858     {
2859         ABISP abi_sp;
2860         ProcessSP process_sp (target_sp->GetProcessSP());
2861         if (process_sp)
2862             abi_sp = process_sp->GetABI();
2863         else
2864             abi_sp = ABI::FindPlugin(target_sp->GetArchitecture());
2865         if (abi_sp)
2866             return abi_sp->GetRedZoneSize();
2867     }
2868     return 0;
2869 }
2870 
2871