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         bytes_read = target_sp->ReadMemory(addr.ref(), false, buf, size, sb_error.ref());
1310     }
1311     else
1312     {
1313         sb_error.SetErrorString("invalid target");
1314     }
1315 
1316     return bytes_read;
1317 }
1318 
1319 SBBreakpoint
1320 SBTarget::BreakpointCreateByLocation (const char *file,
1321                                       uint32_t line)
1322 {
1323     return SBBreakpoint(BreakpointCreateByLocation (SBFileSpec (file, false), line));
1324 }
1325 
1326 SBBreakpoint
1327 SBTarget::BreakpointCreateByLocation (const SBFileSpec &sb_file_spec,
1328                                       uint32_t line)
1329 {
1330     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1331 
1332     SBBreakpoint sb_bp;
1333     TargetSP target_sp(GetSP());
1334     if (target_sp && line != 0)
1335     {
1336         Mutex::Locker api_locker (target_sp->GetAPIMutex());
1337 
1338         const LazyBool check_inlines = eLazyBoolCalculate;
1339         const LazyBool skip_prologue = eLazyBoolCalculate;
1340         const bool internal = false;
1341         const bool hardware = false;
1342         *sb_bp = target_sp->CreateBreakpoint (NULL, *sb_file_spec, line, check_inlines, skip_prologue, internal, hardware);
1343     }
1344 
1345     if (log)
1346     {
1347         SBStream sstr;
1348         sb_bp.GetDescription (sstr);
1349         char path[PATH_MAX];
1350         sb_file_spec->GetPath (path, sizeof(path));
1351         log->Printf ("SBTarget(%p)::BreakpointCreateByLocation ( %s:%u ) => SBBreakpoint(%p): %s",
1352                      static_cast<void*>(target_sp.get()), path, line,
1353                      static_cast<void*>(sb_bp.get()), sstr.GetData());
1354     }
1355 
1356     return sb_bp;
1357 }
1358 
1359 SBBreakpoint
1360 SBTarget::BreakpointCreateByName (const char *symbol_name,
1361                                   const char *module_name)
1362 {
1363     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1364 
1365     SBBreakpoint sb_bp;
1366     TargetSP target_sp(GetSP());
1367     if (target_sp.get())
1368     {
1369         Mutex::Locker api_locker (target_sp->GetAPIMutex());
1370 
1371         const bool internal = false;
1372         const bool hardware = false;
1373         const LazyBool skip_prologue = eLazyBoolCalculate;
1374         if (module_name && module_name[0])
1375         {
1376             FileSpecList module_spec_list;
1377             module_spec_list.Append (FileSpec (module_name, false));
1378             *sb_bp = target_sp->CreateBreakpoint (&module_spec_list, NULL, symbol_name, eFunctionNameTypeAuto, skip_prologue, internal, hardware);
1379         }
1380         else
1381         {
1382             *sb_bp = target_sp->CreateBreakpoint (NULL, NULL, symbol_name, eFunctionNameTypeAuto, skip_prologue, internal, hardware);
1383         }
1384     }
1385 
1386     if (log)
1387         log->Printf ("SBTarget(%p)::BreakpointCreateByName (symbol=\"%s\", module=\"%s\") => SBBreakpoint(%p)",
1388                      static_cast<void*>(target_sp.get()), symbol_name,
1389                      module_name, static_cast<void*>(sb_bp.get()));
1390 
1391     return sb_bp;
1392 }
1393 
1394 lldb::SBBreakpoint
1395 SBTarget::BreakpointCreateByName (const char *symbol_name,
1396                                   const SBFileSpecList &module_list,
1397                                   const SBFileSpecList &comp_unit_list)
1398 {
1399     uint32_t name_type_mask = eFunctionNameTypeAuto;
1400     return BreakpointCreateByName (symbol_name, name_type_mask, module_list, comp_unit_list);
1401 }
1402 
1403 lldb::SBBreakpoint
1404 SBTarget::BreakpointCreateByName (const char *symbol_name,
1405                                   uint32_t name_type_mask,
1406                                   const SBFileSpecList &module_list,
1407                                   const SBFileSpecList &comp_unit_list)
1408 {
1409     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1410 
1411     SBBreakpoint sb_bp;
1412     TargetSP target_sp(GetSP());
1413     if (target_sp && symbol_name && symbol_name[0])
1414     {
1415         const bool internal = false;
1416         const bool hardware = false;
1417         const LazyBool skip_prologue = eLazyBoolCalculate;
1418         Mutex::Locker api_locker (target_sp->GetAPIMutex());
1419         *sb_bp = target_sp->CreateBreakpoint (module_list.get(),
1420                                               comp_unit_list.get(),
1421                                               symbol_name,
1422                                               name_type_mask,
1423                                               skip_prologue,
1424                                               internal,
1425                                               hardware);
1426     }
1427 
1428     if (log)
1429         log->Printf ("SBTarget(%p)::BreakpointCreateByName (symbol=\"%s\", name_type: %d) => SBBreakpoint(%p)",
1430                      static_cast<void*>(target_sp.get()), symbol_name,
1431                      name_type_mask, static_cast<void*>(sb_bp.get()));
1432 
1433     return sb_bp;
1434 }
1435 
1436 lldb::SBBreakpoint
1437 SBTarget::BreakpointCreateByNames (const char *symbol_names[],
1438                                    uint32_t num_names,
1439                                    uint32_t name_type_mask,
1440                                    const SBFileSpecList &module_list,
1441                                    const SBFileSpecList &comp_unit_list)
1442 {
1443     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1444 
1445     SBBreakpoint sb_bp;
1446     TargetSP target_sp(GetSP());
1447     if (target_sp && num_names > 0)
1448     {
1449         Mutex::Locker api_locker (target_sp->GetAPIMutex());
1450         const bool internal = false;
1451         const bool hardware = false;
1452         const LazyBool skip_prologue = eLazyBoolCalculate;
1453         *sb_bp = target_sp->CreateBreakpoint (module_list.get(),
1454                                                 comp_unit_list.get(),
1455                                                 symbol_names,
1456                                                 num_names,
1457                                                 name_type_mask,
1458                                                 skip_prologue,
1459                                                 internal,
1460                                                 hardware);
1461     }
1462 
1463     if (log)
1464     {
1465         log->Printf ("SBTarget(%p)::BreakpointCreateByName (symbols={",
1466                      static_cast<void*>(target_sp.get()));
1467         for (uint32_t i = 0 ; i < num_names; i++)
1468         {
1469             char sep;
1470             if (i < num_names - 1)
1471                 sep = ',';
1472             else
1473                 sep = '}';
1474             if (symbol_names[i] != NULL)
1475                 log->Printf ("\"%s\"%c ", symbol_names[i], sep);
1476             else
1477                 log->Printf ("\"<NULL>\"%c ", sep);
1478         }
1479         log->Printf ("name_type: %d) => SBBreakpoint(%p)", name_type_mask,
1480                      static_cast<void*>(sb_bp.get()));
1481     }
1482 
1483     return sb_bp;
1484 }
1485 
1486 SBBreakpoint
1487 SBTarget::BreakpointCreateByRegex (const char *symbol_name_regex,
1488                                    const char *module_name)
1489 {
1490     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1491 
1492     SBBreakpoint sb_bp;
1493     TargetSP target_sp(GetSP());
1494     if (target_sp && symbol_name_regex && symbol_name_regex[0])
1495     {
1496         Mutex::Locker api_locker (target_sp->GetAPIMutex());
1497         RegularExpression regexp(symbol_name_regex);
1498         const bool internal = false;
1499         const bool hardware = false;
1500         const LazyBool skip_prologue = eLazyBoolCalculate;
1501 
1502         if (module_name && module_name[0])
1503         {
1504             FileSpecList module_spec_list;
1505             module_spec_list.Append (FileSpec (module_name, false));
1506 
1507             *sb_bp = target_sp->CreateFuncRegexBreakpoint (&module_spec_list, NULL, regexp, skip_prologue, internal, hardware);
1508         }
1509         else
1510         {
1511             *sb_bp = target_sp->CreateFuncRegexBreakpoint (NULL, NULL, regexp, skip_prologue, internal, hardware);
1512         }
1513     }
1514 
1515     if (log)
1516         log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (symbol_regex=\"%s\", module_name=\"%s\") => SBBreakpoint(%p)",
1517                      static_cast<void*>(target_sp.get()), symbol_name_regex,
1518                      module_name, static_cast<void*>(sb_bp.get()));
1519 
1520     return sb_bp;
1521 }
1522 
1523 lldb::SBBreakpoint
1524 SBTarget::BreakpointCreateByRegex (const char *symbol_name_regex,
1525                                    const SBFileSpecList &module_list,
1526                                    const SBFileSpecList &comp_unit_list)
1527 {
1528     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1529 
1530     SBBreakpoint sb_bp;
1531     TargetSP target_sp(GetSP());
1532     if (target_sp && symbol_name_regex && symbol_name_regex[0])
1533     {
1534         Mutex::Locker api_locker (target_sp->GetAPIMutex());
1535         RegularExpression regexp(symbol_name_regex);
1536         const bool internal = false;
1537         const bool hardware = false;
1538         const LazyBool skip_prologue = eLazyBoolCalculate;
1539 
1540         *sb_bp = target_sp->CreateFuncRegexBreakpoint (module_list.get(), comp_unit_list.get(), regexp, skip_prologue, internal, hardware);
1541     }
1542 
1543     if (log)
1544         log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (symbol_regex=\"%s\") => SBBreakpoint(%p)",
1545                      static_cast<void*>(target_sp.get()), symbol_name_regex,
1546                      static_cast<void*>(sb_bp.get()));
1547 
1548     return sb_bp;
1549 }
1550 
1551 SBBreakpoint
1552 SBTarget::BreakpointCreateByAddress (addr_t address)
1553 {
1554     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1555 
1556     SBBreakpoint sb_bp;
1557     TargetSP target_sp(GetSP());
1558     if (target_sp)
1559     {
1560         Mutex::Locker api_locker (target_sp->GetAPIMutex());
1561         const bool hardware = false;
1562         *sb_bp = target_sp->CreateBreakpoint (address, false, hardware);
1563     }
1564 
1565     if (log)
1566         log->Printf ("SBTarget(%p)::BreakpointCreateByAddress (address=%" PRIu64 ") => SBBreakpoint(%p)",
1567                      static_cast<void*>(target_sp.get()),
1568                      static_cast<uint64_t>(address),
1569                      static_cast<void*>(sb_bp.get()));
1570 
1571     return sb_bp;
1572 }
1573 
1574 lldb::SBBreakpoint
1575 SBTarget::BreakpointCreateBySourceRegex (const char *source_regex,
1576                                          const lldb::SBFileSpec &source_file,
1577                                          const char *module_name)
1578 {
1579     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1580 
1581     SBBreakpoint sb_bp;
1582     TargetSP target_sp(GetSP());
1583     if (target_sp && source_regex && source_regex[0])
1584     {
1585         Mutex::Locker api_locker (target_sp->GetAPIMutex());
1586         RegularExpression regexp(source_regex);
1587         FileSpecList source_file_spec_list;
1588         const bool hardware = false;
1589         source_file_spec_list.Append (source_file.ref());
1590 
1591         if (module_name && module_name[0])
1592         {
1593             FileSpecList module_spec_list;
1594             module_spec_list.Append (FileSpec (module_name, false));
1595 
1596             *sb_bp = target_sp->CreateSourceRegexBreakpoint (&module_spec_list, &source_file_spec_list, regexp, false, hardware);
1597         }
1598         else
1599         {
1600             *sb_bp = target_sp->CreateSourceRegexBreakpoint (NULL, &source_file_spec_list, regexp, false, hardware);
1601         }
1602     }
1603 
1604     if (log)
1605     {
1606         char path[PATH_MAX];
1607         source_file->GetPath (path, sizeof(path));
1608         log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (source_regex=\"%s\", file=\"%s\", module_name=\"%s\") => SBBreakpoint(%p)",
1609                      static_cast<void*>(target_sp.get()), source_regex, path,
1610                      module_name, static_cast<void*>(sb_bp.get()));
1611     }
1612 
1613     return sb_bp;
1614 }
1615 
1616 lldb::SBBreakpoint
1617 SBTarget::BreakpointCreateBySourceRegex (const char *source_regex,
1618                                          const SBFileSpecList &module_list,
1619                                          const lldb::SBFileSpecList &source_file_list)
1620 {
1621     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1622 
1623     SBBreakpoint sb_bp;
1624     TargetSP target_sp(GetSP());
1625     if (target_sp && source_regex && source_regex[0])
1626     {
1627         Mutex::Locker api_locker (target_sp->GetAPIMutex());
1628         const bool hardware = false;
1629         RegularExpression regexp(source_regex);
1630         *sb_bp = target_sp->CreateSourceRegexBreakpoint (module_list.get(), source_file_list.get(), regexp, false, hardware);
1631     }
1632 
1633     if (log)
1634         log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (source_regex=\"%s\") => SBBreakpoint(%p)",
1635                      static_cast<void*>(target_sp.get()), source_regex,
1636                      static_cast<void*>(sb_bp.get()));
1637 
1638     return sb_bp;
1639 }
1640 
1641 lldb::SBBreakpoint
1642 SBTarget::BreakpointCreateForException  (lldb::LanguageType language,
1643                                          bool catch_bp,
1644                                          bool throw_bp)
1645 {
1646     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1647 
1648     SBBreakpoint sb_bp;
1649     TargetSP target_sp(GetSP());
1650     if (target_sp)
1651     {
1652         Mutex::Locker api_locker (target_sp->GetAPIMutex());
1653         const bool hardware = false;
1654         *sb_bp = target_sp->CreateExceptionBreakpoint (language, catch_bp, throw_bp, hardware);
1655     }
1656 
1657     if (log)
1658         log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (Language: %s, catch: %s throw: %s) => SBBreakpoint(%p)",
1659                      static_cast<void*>(target_sp.get()),
1660                      LanguageRuntime::GetNameForLanguageType(language),
1661                      catch_bp ? "on" : "off", throw_bp ? "on" : "off",
1662                      static_cast<void*>(sb_bp.get()));
1663 
1664     return sb_bp;
1665 }
1666 
1667 uint32_t
1668 SBTarget::GetNumBreakpoints () const
1669 {
1670     TargetSP target_sp(GetSP());
1671     if (target_sp)
1672     {
1673         // The breakpoint list is thread safe, no need to lock
1674         return target_sp->GetBreakpointList().GetSize();
1675     }
1676     return 0;
1677 }
1678 
1679 SBBreakpoint
1680 SBTarget::GetBreakpointAtIndex (uint32_t idx) const
1681 {
1682     SBBreakpoint sb_breakpoint;
1683     TargetSP target_sp(GetSP());
1684     if (target_sp)
1685     {
1686         // The breakpoint list is thread safe, no need to lock
1687         *sb_breakpoint = target_sp->GetBreakpointList().GetBreakpointAtIndex(idx);
1688     }
1689     return sb_breakpoint;
1690 }
1691 
1692 bool
1693 SBTarget::BreakpointDelete (break_id_t bp_id)
1694 {
1695     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1696 
1697     bool result = false;
1698     TargetSP target_sp(GetSP());
1699     if (target_sp)
1700     {
1701         Mutex::Locker api_locker (target_sp->GetAPIMutex());
1702         result = target_sp->RemoveBreakpointByID (bp_id);
1703     }
1704 
1705     if (log)
1706         log->Printf ("SBTarget(%p)::BreakpointDelete (bp_id=%d) => %i",
1707                      static_cast<void*>(target_sp.get()),
1708                      static_cast<uint32_t>(bp_id), result);
1709 
1710     return result;
1711 }
1712 
1713 SBBreakpoint
1714 SBTarget::FindBreakpointByID (break_id_t bp_id)
1715 {
1716     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1717 
1718     SBBreakpoint sb_breakpoint;
1719     TargetSP target_sp(GetSP());
1720     if (target_sp && bp_id != LLDB_INVALID_BREAK_ID)
1721     {
1722         Mutex::Locker api_locker (target_sp->GetAPIMutex());
1723         *sb_breakpoint = target_sp->GetBreakpointByID (bp_id);
1724     }
1725 
1726     if (log)
1727         log->Printf ("SBTarget(%p)::FindBreakpointByID (bp_id=%d) => SBBreakpoint(%p)",
1728                      static_cast<void*>(target_sp.get()),
1729                      static_cast<uint32_t>(bp_id),
1730                      static_cast<void*>(sb_breakpoint.get()));
1731 
1732     return sb_breakpoint;
1733 }
1734 
1735 bool
1736 SBTarget::EnableAllBreakpoints ()
1737 {
1738     TargetSP target_sp(GetSP());
1739     if (target_sp)
1740     {
1741         Mutex::Locker api_locker (target_sp->GetAPIMutex());
1742         target_sp->EnableAllBreakpoints ();
1743         return true;
1744     }
1745     return false;
1746 }
1747 
1748 bool
1749 SBTarget::DisableAllBreakpoints ()
1750 {
1751     TargetSP target_sp(GetSP());
1752     if (target_sp)
1753     {
1754         Mutex::Locker api_locker (target_sp->GetAPIMutex());
1755         target_sp->DisableAllBreakpoints ();
1756         return true;
1757     }
1758     return false;
1759 }
1760 
1761 bool
1762 SBTarget::DeleteAllBreakpoints ()
1763 {
1764     TargetSP target_sp(GetSP());
1765     if (target_sp)
1766     {
1767         Mutex::Locker api_locker (target_sp->GetAPIMutex());
1768         target_sp->RemoveAllBreakpoints ();
1769         return true;
1770     }
1771     return false;
1772 }
1773 
1774 uint32_t
1775 SBTarget::GetNumWatchpoints () const
1776 {
1777     TargetSP target_sp(GetSP());
1778     if (target_sp)
1779     {
1780         // The watchpoint list is thread safe, no need to lock
1781         return target_sp->GetWatchpointList().GetSize();
1782     }
1783     return 0;
1784 }
1785 
1786 SBWatchpoint
1787 SBTarget::GetWatchpointAtIndex (uint32_t idx) const
1788 {
1789     SBWatchpoint sb_watchpoint;
1790     TargetSP target_sp(GetSP());
1791     if (target_sp)
1792     {
1793         // The watchpoint list is thread safe, no need to lock
1794         sb_watchpoint.SetSP (target_sp->GetWatchpointList().GetByIndex(idx));
1795     }
1796     return sb_watchpoint;
1797 }
1798 
1799 bool
1800 SBTarget::DeleteWatchpoint (watch_id_t wp_id)
1801 {
1802     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1803 
1804     bool result = false;
1805     TargetSP target_sp(GetSP());
1806     if (target_sp)
1807     {
1808         Mutex::Locker api_locker (target_sp->GetAPIMutex());
1809         Mutex::Locker locker;
1810         target_sp->GetWatchpointList().GetListMutex(locker);
1811         result = target_sp->RemoveWatchpointByID (wp_id);
1812     }
1813 
1814     if (log)
1815         log->Printf ("SBTarget(%p)::WatchpointDelete (wp_id=%d) => %i",
1816                      static_cast<void*>(target_sp.get()),
1817                      static_cast<uint32_t>(wp_id), result);
1818 
1819     return result;
1820 }
1821 
1822 SBWatchpoint
1823 SBTarget::FindWatchpointByID (lldb::watch_id_t wp_id)
1824 {
1825     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1826 
1827     SBWatchpoint sb_watchpoint;
1828     lldb::WatchpointSP watchpoint_sp;
1829     TargetSP target_sp(GetSP());
1830     if (target_sp && wp_id != LLDB_INVALID_WATCH_ID)
1831     {
1832         Mutex::Locker api_locker (target_sp->GetAPIMutex());
1833         Mutex::Locker locker;
1834         target_sp->GetWatchpointList().GetListMutex(locker);
1835         watchpoint_sp = target_sp->GetWatchpointList().FindByID(wp_id);
1836         sb_watchpoint.SetSP (watchpoint_sp);
1837     }
1838 
1839     if (log)
1840         log->Printf ("SBTarget(%p)::FindWatchpointByID (bp_id=%d) => SBWatchpoint(%p)",
1841                      static_cast<void*>(target_sp.get()),
1842                      static_cast<uint32_t>(wp_id),
1843                      static_cast<void*>(watchpoint_sp.get()));
1844 
1845     return sb_watchpoint;
1846 }
1847 
1848 lldb::SBWatchpoint
1849 SBTarget::WatchAddress (lldb::addr_t addr, size_t size, bool read, bool write, SBError &error)
1850 {
1851     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1852 
1853     SBWatchpoint sb_watchpoint;
1854     lldb::WatchpointSP watchpoint_sp;
1855     TargetSP target_sp(GetSP());
1856     if (target_sp && (read || write) && addr != LLDB_INVALID_ADDRESS && size > 0)
1857     {
1858         Mutex::Locker api_locker (target_sp->GetAPIMutex());
1859         uint32_t watch_type = 0;
1860         if (read)
1861             watch_type |= LLDB_WATCH_TYPE_READ;
1862         if (write)
1863             watch_type |= LLDB_WATCH_TYPE_WRITE;
1864         if (watch_type == 0)
1865         {
1866             error.SetErrorString("Can't create a watchpoint that is neither read nor write.");
1867             return sb_watchpoint;
1868         }
1869 
1870         // Target::CreateWatchpoint() is thread safe.
1871         Error cw_error;
1872         // This API doesn't take in a type, so we can't figure out what it is.
1873         ClangASTType *type = NULL;
1874         watchpoint_sp = target_sp->CreateWatchpoint(addr, size, type, watch_type, cw_error);
1875         error.SetError(cw_error);
1876         sb_watchpoint.SetSP (watchpoint_sp);
1877     }
1878 
1879     if (log)
1880         log->Printf ("SBTarget(%p)::WatchAddress (addr=0x%" PRIx64 ", 0x%u) => SBWatchpoint(%p)",
1881                      static_cast<void*>(target_sp.get()), addr,
1882                      static_cast<uint32_t>(size),
1883                      static_cast<void*>(watchpoint_sp.get()));
1884 
1885     return sb_watchpoint;
1886 }
1887 
1888 bool
1889 SBTarget::EnableAllWatchpoints ()
1890 {
1891     TargetSP target_sp(GetSP());
1892     if (target_sp)
1893     {
1894         Mutex::Locker api_locker (target_sp->GetAPIMutex());
1895         Mutex::Locker locker;
1896         target_sp->GetWatchpointList().GetListMutex(locker);
1897         target_sp->EnableAllWatchpoints ();
1898         return true;
1899     }
1900     return false;
1901 }
1902 
1903 bool
1904 SBTarget::DisableAllWatchpoints ()
1905 {
1906     TargetSP target_sp(GetSP());
1907     if (target_sp)
1908     {
1909         Mutex::Locker api_locker (target_sp->GetAPIMutex());
1910         Mutex::Locker locker;
1911         target_sp->GetWatchpointList().GetListMutex(locker);
1912         target_sp->DisableAllWatchpoints ();
1913         return true;
1914     }
1915     return false;
1916 }
1917 
1918 SBValue
1919 SBTarget::CreateValueFromAddress (const char *name, SBAddress addr, SBType type)
1920 {
1921     SBValue sb_value;
1922     lldb::ValueObjectSP new_value_sp;
1923     if (IsValid() && name && *name && addr.IsValid() && type.IsValid())
1924     {
1925         lldb::addr_t address(addr.GetLoadAddress(*this));
1926         lldb::TypeImplSP type_impl_sp (type.GetSP());
1927         ClangASTType pointer_ast_type(type_impl_sp->GetClangASTType(true).GetPointerType ());
1928         if (pointer_ast_type)
1929         {
1930             lldb::DataBufferSP buffer(new lldb_private::DataBufferHeap(&address,sizeof(lldb::addr_t)));
1931 
1932             ExecutionContext exe_ctx (ExecutionContextRef(ExecutionContext(m_opaque_sp.get(),false)));
1933             ValueObjectSP ptr_result_valobj_sp(ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
1934                                                                                pointer_ast_type,
1935                                                                                ConstString(name),
1936                                                                                buffer,
1937                                                                                exe_ctx.GetByteOrder(),
1938                                                                                exe_ctx.GetAddressByteSize()));
1939 
1940             if (ptr_result_valobj_sp)
1941             {
1942                 ptr_result_valobj_sp->GetValue().SetValueType(Value::eValueTypeLoadAddress);
1943                 Error err;
1944                 new_value_sp = ptr_result_valobj_sp->Dereference(err);
1945                 if (new_value_sp)
1946                     new_value_sp->SetName(ConstString(name));
1947             }
1948         }
1949     }
1950     sb_value.SetSP(new_value_sp);
1951     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1952     if (log)
1953     {
1954         if (new_value_sp)
1955             log->Printf ("SBTarget(%p)::CreateValueFromAddress => \"%s\"",
1956                          static_cast<void*>(m_opaque_sp.get()),
1957                          new_value_sp->GetName().AsCString());
1958         else
1959             log->Printf ("SBTarget(%p)::CreateValueFromAddress => NULL",
1960                          static_cast<void*>(m_opaque_sp.get()));
1961     }
1962     return sb_value;
1963 }
1964 
1965 bool
1966 SBTarget::DeleteAllWatchpoints ()
1967 {
1968     TargetSP target_sp(GetSP());
1969     if (target_sp)
1970     {
1971         Mutex::Locker api_locker (target_sp->GetAPIMutex());
1972         Mutex::Locker locker;
1973         target_sp->GetWatchpointList().GetListMutex(locker);
1974         target_sp->RemoveAllWatchpoints ();
1975         return true;
1976     }
1977     return false;
1978 }
1979 
1980 
1981 lldb::SBModule
1982 SBTarget::AddModule (const char *path,
1983                      const char *triple,
1984                      const char *uuid_cstr)
1985 {
1986     return AddModule (path, triple, uuid_cstr, NULL);
1987 }
1988 
1989 lldb::SBModule
1990 SBTarget::AddModule (const char *path,
1991                      const char *triple,
1992                      const char *uuid_cstr,
1993                      const char *symfile)
1994 {
1995     lldb::SBModule sb_module;
1996     TargetSP target_sp(GetSP());
1997     if (target_sp)
1998     {
1999         ModuleSpec module_spec;
2000         if (path)
2001             module_spec.GetFileSpec().SetFile(path, false);
2002 
2003         if (uuid_cstr)
2004             module_spec.GetUUID().SetFromCString(uuid_cstr);
2005 
2006         if (triple)
2007             module_spec.GetArchitecture().SetTriple (triple, target_sp->GetPlatform ().get());
2008         else
2009             module_spec.GetArchitecture() = target_sp->GetArchitecture();
2010 
2011         if (symfile)
2012             module_spec.GetSymbolFileSpec ().SetFile(symfile, false);
2013 
2014         sb_module.SetSP(target_sp->GetSharedModule (module_spec));
2015     }
2016     return sb_module;
2017 }
2018 
2019 lldb::SBModule
2020 SBTarget::AddModule (const SBModuleSpec &module_spec)
2021 {
2022     lldb::SBModule sb_module;
2023     TargetSP target_sp(GetSP());
2024     if (target_sp)
2025         sb_module.SetSP(target_sp->GetSharedModule (*module_spec.m_opaque_ap));
2026     return sb_module;
2027 }
2028 
2029 bool
2030 SBTarget::AddModule (lldb::SBModule &module)
2031 {
2032     TargetSP target_sp(GetSP());
2033     if (target_sp)
2034     {
2035         target_sp->GetImages().AppendIfNeeded (module.GetSP());
2036         return true;
2037     }
2038     return false;
2039 }
2040 
2041 uint32_t
2042 SBTarget::GetNumModules () const
2043 {
2044     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
2045 
2046     uint32_t num = 0;
2047     TargetSP target_sp(GetSP());
2048     if (target_sp)
2049     {
2050         // The module list is thread safe, no need to lock
2051         num = target_sp->GetImages().GetSize();
2052     }
2053 
2054     if (log)
2055         log->Printf ("SBTarget(%p)::GetNumModules () => %d",
2056                      static_cast<void*>(target_sp.get()), num);
2057 
2058     return num;
2059 }
2060 
2061 void
2062 SBTarget::Clear ()
2063 {
2064     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
2065 
2066     if (log)
2067         log->Printf ("SBTarget(%p)::Clear ()",
2068                      static_cast<void*>(m_opaque_sp.get()));
2069 
2070     m_opaque_sp.reset();
2071 }
2072 
2073 
2074 SBModule
2075 SBTarget::FindModule (const SBFileSpec &sb_file_spec)
2076 {
2077     SBModule sb_module;
2078     TargetSP target_sp(GetSP());
2079     if (target_sp && sb_file_spec.IsValid())
2080     {
2081         ModuleSpec module_spec(*sb_file_spec);
2082         // The module list is thread safe, no need to lock
2083         sb_module.SetSP (target_sp->GetImages().FindFirstModule (module_spec));
2084     }
2085     return sb_module;
2086 }
2087 
2088 lldb::ByteOrder
2089 SBTarget::GetByteOrder ()
2090 {
2091     TargetSP target_sp(GetSP());
2092     if (target_sp)
2093         return target_sp->GetArchitecture().GetByteOrder();
2094     return eByteOrderInvalid;
2095 }
2096 
2097 const char *
2098 SBTarget::GetTriple ()
2099 {
2100     TargetSP target_sp(GetSP());
2101     if (target_sp)
2102     {
2103         std::string triple (target_sp->GetArchitecture().GetTriple().str());
2104         // Unique the string so we don't run into ownership issues since
2105         // the const strings put the string into the string pool once and
2106         // the strings never comes out
2107         ConstString const_triple (triple.c_str());
2108         return const_triple.GetCString();
2109     }
2110     return NULL;
2111 }
2112 
2113 uint32_t
2114 SBTarget::GetDataByteSize ()
2115 {
2116     TargetSP target_sp(GetSP());
2117     if (target_sp)
2118     {
2119         return target_sp->GetArchitecture().GetDataByteSize() ;
2120     }
2121     return 0;
2122 }
2123 
2124 uint32_t
2125 SBTarget::GetCodeByteSize ()
2126 {
2127     TargetSP target_sp(GetSP());
2128     if (target_sp)
2129     {
2130         return target_sp->GetArchitecture().GetCodeByteSize() ;
2131     }
2132     return 0;
2133 }
2134 
2135 uint32_t
2136 SBTarget::GetAddressByteSize()
2137 {
2138     TargetSP target_sp(GetSP());
2139     if (target_sp)
2140         return target_sp->GetArchitecture().GetAddressByteSize();
2141     return sizeof(void*);
2142 }
2143 
2144 
2145 SBModule
2146 SBTarget::GetModuleAtIndex (uint32_t idx)
2147 {
2148     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
2149 
2150     SBModule sb_module;
2151     ModuleSP module_sp;
2152     TargetSP target_sp(GetSP());
2153     if (target_sp)
2154     {
2155         // The module list is thread safe, no need to lock
2156         module_sp = target_sp->GetImages().GetModuleAtIndex(idx);
2157         sb_module.SetSP (module_sp);
2158     }
2159 
2160     if (log)
2161         log->Printf ("SBTarget(%p)::GetModuleAtIndex (idx=%d) => SBModule(%p)",
2162                      static_cast<void*>(target_sp.get()), idx,
2163                      static_cast<void*>(module_sp.get()));
2164 
2165     return sb_module;
2166 }
2167 
2168 bool
2169 SBTarget::RemoveModule (lldb::SBModule module)
2170 {
2171     TargetSP target_sp(GetSP());
2172     if (target_sp)
2173         return target_sp->GetImages().Remove(module.GetSP());
2174     return false;
2175 }
2176 
2177 
2178 SBBroadcaster
2179 SBTarget::GetBroadcaster () const
2180 {
2181     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
2182 
2183     TargetSP target_sp(GetSP());
2184     SBBroadcaster broadcaster(target_sp.get(), false);
2185 
2186     if (log)
2187         log->Printf ("SBTarget(%p)::GetBroadcaster () => SBBroadcaster(%p)",
2188                      static_cast<void*>(target_sp.get()),
2189                      static_cast<void*>(broadcaster.get()));
2190 
2191     return broadcaster;
2192 }
2193 
2194 bool
2195 SBTarget::GetDescription (SBStream &description, lldb::DescriptionLevel description_level)
2196 {
2197     Stream &strm = description.ref();
2198 
2199     TargetSP target_sp(GetSP());
2200     if (target_sp)
2201     {
2202         target_sp->Dump (&strm, description_level);
2203     }
2204     else
2205         strm.PutCString ("No value");
2206 
2207     return true;
2208 }
2209 
2210 lldb::SBSymbolContextList
2211 SBTarget::FindFunctions (const char *name, uint32_t name_type_mask)
2212 {
2213     lldb::SBSymbolContextList sb_sc_list;
2214     if (name && name[0])
2215     {
2216         TargetSP target_sp(GetSP());
2217         if (target_sp)
2218         {
2219             const bool symbols_ok = true;
2220             const bool inlines_ok = true;
2221             const bool append = true;
2222             target_sp->GetImages().FindFunctions (ConstString(name),
2223                                                   name_type_mask,
2224                                                   symbols_ok,
2225                                                   inlines_ok,
2226                                                   append,
2227                                                   *sb_sc_list);
2228         }
2229     }
2230     return sb_sc_list;
2231 }
2232 
2233 lldb::SBSymbolContextList
2234 SBTarget::FindGlobalFunctions(const char *name, uint32_t max_matches, MatchType matchtype)
2235 {
2236     lldb::SBSymbolContextList sb_sc_list;
2237     if (name && name[0])
2238     {
2239         TargetSP target_sp(GetSP());
2240         if (target_sp)
2241         {
2242             std::string regexstr;
2243             switch (matchtype)
2244             {
2245             case eMatchTypeRegex:
2246                 target_sp->GetImages().FindFunctions(RegularExpression(name), true, true, true, *sb_sc_list);
2247                 break;
2248             case eMatchTypeStartsWith:
2249                 regexstr = llvm::Regex::escape(name) + ".*";
2250                 target_sp->GetImages().FindFunctions(RegularExpression(regexstr.c_str()), true, true, true, *sb_sc_list);
2251                 break;
2252             default:
2253                 target_sp->GetImages().FindFunctions(ConstString(name), eFunctionNameTypeAny, true, true, true, *sb_sc_list);
2254                 break;
2255             }
2256         }
2257     }
2258     return sb_sc_list;
2259 }
2260 
2261 lldb::SBType
2262 SBTarget::FindFirstType (const char* typename_cstr)
2263 {
2264     TargetSP target_sp(GetSP());
2265     if (typename_cstr && typename_cstr[0] && target_sp)
2266     {
2267         ConstString const_typename(typename_cstr);
2268         SymbolContext sc;
2269         const bool exact_match = false;
2270 
2271         const ModuleList &module_list = target_sp->GetImages();
2272         size_t count = module_list.GetSize();
2273         for (size_t idx = 0; idx < count; idx++)
2274         {
2275             ModuleSP module_sp (module_list.GetModuleAtIndex(idx));
2276             if (module_sp)
2277             {
2278                 TypeSP type_sp (module_sp->FindFirstType(sc, const_typename, exact_match));
2279                 if (type_sp)
2280                     return SBType(type_sp);
2281             }
2282         }
2283 
2284         // Didn't find the type in the symbols; try the Objective-C runtime
2285         // if one is installed
2286 
2287         ProcessSP process_sp(target_sp->GetProcessSP());
2288 
2289         if (process_sp)
2290         {
2291             ObjCLanguageRuntime *objc_language_runtime = process_sp->GetObjCLanguageRuntime();
2292 
2293             if (objc_language_runtime)
2294             {
2295                 TypeVendor *objc_type_vendor = objc_language_runtime->GetTypeVendor();
2296 
2297                 if (objc_type_vendor)
2298                 {
2299                     std::vector <ClangASTType> types;
2300 
2301                     if (objc_type_vendor->FindTypes(const_typename, true, 1, types) > 0)
2302                         return SBType(types[0]);
2303                 }
2304             }
2305         }
2306 
2307         // No matches, search for basic typename matches
2308         ClangASTContext *clang_ast = target_sp->GetScratchClangASTContext();
2309         if (clang_ast)
2310             return SBType (ClangASTContext::GetBasicType (clang_ast->getASTContext(), const_typename));
2311     }
2312     return SBType();
2313 }
2314 
2315 SBType
2316 SBTarget::GetBasicType(lldb::BasicType type)
2317 {
2318     TargetSP target_sp(GetSP());
2319     if (target_sp)
2320     {
2321         ClangASTContext *clang_ast = target_sp->GetScratchClangASTContext();
2322         if (clang_ast)
2323             return SBType (ClangASTContext::GetBasicType (clang_ast->getASTContext(), type));
2324     }
2325     return SBType();
2326 }
2327 
2328 
2329 lldb::SBTypeList
2330 SBTarget::FindTypes (const char* typename_cstr)
2331 {
2332     SBTypeList sb_type_list;
2333     TargetSP target_sp(GetSP());
2334     if (typename_cstr && typename_cstr[0] && target_sp)
2335     {
2336         ModuleList& images = target_sp->GetImages();
2337         ConstString const_typename(typename_cstr);
2338         bool exact_match = false;
2339         SymbolContext sc;
2340         TypeList type_list;
2341 
2342         uint32_t num_matches = images.FindTypes (sc,
2343                                                  const_typename,
2344                                                  exact_match,
2345                                                  UINT32_MAX,
2346                                                  type_list);
2347 
2348         if (num_matches > 0)
2349         {
2350             for (size_t idx = 0; idx < num_matches; idx++)
2351             {
2352                 TypeSP type_sp (type_list.GetTypeAtIndex(idx));
2353                 if (type_sp)
2354                     sb_type_list.Append(SBType(type_sp));
2355             }
2356         }
2357 
2358         // Try the Objective-C runtime if one is installed
2359 
2360         ProcessSP process_sp(target_sp->GetProcessSP());
2361 
2362         if (process_sp)
2363         {
2364             ObjCLanguageRuntime *objc_language_runtime = process_sp->GetObjCLanguageRuntime();
2365 
2366             if (objc_language_runtime)
2367             {
2368                 TypeVendor *objc_type_vendor = objc_language_runtime->GetTypeVendor();
2369 
2370                 if (objc_type_vendor)
2371                 {
2372                     std::vector <ClangASTType> types;
2373 
2374                     if (objc_type_vendor->FindTypes(const_typename, true, UINT32_MAX, types))
2375                     {
2376                         for (ClangASTType &type : types)
2377                         {
2378                             sb_type_list.Append(SBType(type));
2379                         }
2380                     }
2381                 }
2382             }
2383         }
2384 
2385         if (sb_type_list.GetSize() == 0)
2386         {
2387             // No matches, search for basic typename matches
2388             ClangASTContext *clang_ast = target_sp->GetScratchClangASTContext();
2389             if (clang_ast)
2390                 sb_type_list.Append (SBType (ClangASTContext::GetBasicType (clang_ast->getASTContext(), const_typename)));
2391         }
2392     }
2393     return sb_type_list;
2394 }
2395 
2396 SBValueList
2397 SBTarget::FindGlobalVariables (const char *name, uint32_t max_matches)
2398 {
2399     SBValueList sb_value_list;
2400 
2401     TargetSP target_sp(GetSP());
2402     if (name && target_sp)
2403     {
2404         VariableList variable_list;
2405         const bool append = true;
2406         const uint32_t match_count = target_sp->GetImages().FindGlobalVariables (ConstString (name),
2407                                                                                  append,
2408                                                                                  max_matches,
2409                                                                                  variable_list);
2410 
2411         if (match_count > 0)
2412         {
2413             ExecutionContextScope *exe_scope = target_sp->GetProcessSP().get();
2414             if (exe_scope == NULL)
2415                 exe_scope = target_sp.get();
2416             for (uint32_t i=0; i<match_count; ++i)
2417             {
2418                 lldb::ValueObjectSP valobj_sp (ValueObjectVariable::Create (exe_scope, variable_list.GetVariableAtIndex(i)));
2419                 if (valobj_sp)
2420                     sb_value_list.Append(SBValue(valobj_sp));
2421             }
2422         }
2423     }
2424 
2425     return sb_value_list;
2426 }
2427 
2428 SBValueList
2429 SBTarget::FindGlobalVariables(const char *name, uint32_t max_matches, MatchType matchtype)
2430 {
2431     SBValueList sb_value_list;
2432 
2433     TargetSP target_sp(GetSP());
2434     if (name && target_sp)
2435     {
2436         VariableList variable_list;
2437         const bool append = true;
2438 
2439         std::string regexstr;
2440         uint32_t match_count;
2441         switch (matchtype)
2442         {
2443         case eMatchTypeNormal:
2444             match_count = target_sp->GetImages().FindGlobalVariables(ConstString(name),
2445                 append,
2446                 max_matches,
2447                 variable_list);
2448             break;
2449         case eMatchTypeRegex:
2450             match_count = target_sp->GetImages().FindGlobalVariables(RegularExpression(name),
2451                 append,
2452                 max_matches,
2453                 variable_list);
2454             break;
2455         case eMatchTypeStartsWith:
2456             regexstr = llvm::Regex::escape(name) + ".*";
2457             match_count = target_sp->GetImages().FindGlobalVariables(RegularExpression(regexstr.c_str()),
2458                 append,
2459                 max_matches,
2460                 variable_list);
2461             break;
2462         }
2463 
2464 
2465         if (match_count > 0)
2466         {
2467             ExecutionContextScope *exe_scope = target_sp->GetProcessSP().get();
2468             if (exe_scope == NULL)
2469                 exe_scope = target_sp.get();
2470             for (uint32_t i = 0; i<match_count; ++i)
2471             {
2472                 lldb::ValueObjectSP valobj_sp(ValueObjectVariable::Create(exe_scope, variable_list.GetVariableAtIndex(i)));
2473                 if (valobj_sp)
2474                     sb_value_list.Append(SBValue(valobj_sp));
2475             }
2476         }
2477     }
2478 
2479     return sb_value_list;
2480 }
2481 
2482 
2483 lldb::SBValue
2484 SBTarget::FindFirstGlobalVariable (const char* name)
2485 {
2486     SBValueList sb_value_list(FindGlobalVariables(name, 1));
2487     if (sb_value_list.IsValid() && sb_value_list.GetSize() > 0)
2488         return sb_value_list.GetValueAtIndex(0);
2489     return SBValue();
2490 }
2491 
2492 SBSourceManager
2493 SBTarget::GetSourceManager()
2494 {
2495     SBSourceManager source_manager (*this);
2496     return source_manager;
2497 }
2498 
2499 lldb::SBInstructionList
2500 SBTarget::ReadInstructions (lldb::SBAddress base_addr, uint32_t count)
2501 {
2502     return ReadInstructions (base_addr, count, NULL);
2503 }
2504 
2505 lldb::SBInstructionList
2506 SBTarget::ReadInstructions (lldb::SBAddress base_addr, uint32_t count, const char *flavor_string)
2507 {
2508     SBInstructionList sb_instructions;
2509 
2510     TargetSP target_sp(GetSP());
2511     if (target_sp)
2512     {
2513         Address *addr_ptr = base_addr.get();
2514 
2515         if (addr_ptr)
2516         {
2517             DataBufferHeap data (target_sp->GetArchitecture().GetMaximumOpcodeByteSize() * count, 0);
2518             bool prefer_file_cache = false;
2519             lldb_private::Error error;
2520             lldb::addr_t load_addr = LLDB_INVALID_ADDRESS;
2521             const size_t bytes_read = target_sp->ReadMemory(*addr_ptr,
2522                                                             prefer_file_cache,
2523                                                             data.GetBytes(),
2524                                                             data.GetByteSize(),
2525                                                             error,
2526                                                             &load_addr);
2527             const bool data_from_file = load_addr == LLDB_INVALID_ADDRESS;
2528             sb_instructions.SetDisassembler (Disassembler::DisassembleBytes (target_sp->GetArchitecture(),
2529                                                                              NULL,
2530                                                                              flavor_string,
2531                                                                              *addr_ptr,
2532                                                                              data.GetBytes(),
2533                                                                              bytes_read,
2534                                                                              count,
2535                                                                              data_from_file));
2536         }
2537     }
2538 
2539     return sb_instructions;
2540 
2541 }
2542 
2543 lldb::SBInstructionList
2544 SBTarget::GetInstructions (lldb::SBAddress base_addr, const void *buf, size_t size)
2545 {
2546     return GetInstructionsWithFlavor (base_addr, NULL, buf, size);
2547 }
2548 
2549 lldb::SBInstructionList
2550 SBTarget::GetInstructionsWithFlavor (lldb::SBAddress base_addr, const char *flavor_string, const void *buf, size_t size)
2551 {
2552     SBInstructionList sb_instructions;
2553 
2554     TargetSP target_sp(GetSP());
2555     if (target_sp)
2556     {
2557         Address addr;
2558 
2559         if (base_addr.get())
2560             addr = *base_addr.get();
2561 
2562         const bool data_from_file = true;
2563 
2564         sb_instructions.SetDisassembler (Disassembler::DisassembleBytes (target_sp->GetArchitecture(),
2565                                                                          NULL,
2566                                                                          flavor_string,
2567                                                                          addr,
2568                                                                          buf,
2569                                                                          size,
2570                                                                          UINT32_MAX,
2571                                                                          data_from_file));
2572     }
2573 
2574     return sb_instructions;
2575 }
2576 
2577 lldb::SBInstructionList
2578 SBTarget::GetInstructions (lldb::addr_t base_addr, const void *buf, size_t size)
2579 {
2580     return GetInstructionsWithFlavor (ResolveLoadAddress(base_addr), NULL, buf, size);
2581 }
2582 
2583 lldb::SBInstructionList
2584 SBTarget::GetInstructionsWithFlavor (lldb::addr_t base_addr, const char *flavor_string, const void *buf, size_t size)
2585 {
2586     return GetInstructionsWithFlavor (ResolveLoadAddress(base_addr), flavor_string, buf, size);
2587 }
2588 
2589 SBError
2590 SBTarget::SetSectionLoadAddress (lldb::SBSection section,
2591                                  lldb::addr_t section_base_addr)
2592 {
2593     SBError sb_error;
2594     TargetSP target_sp(GetSP());
2595     if (target_sp)
2596     {
2597         if (!section.IsValid())
2598         {
2599             sb_error.SetErrorStringWithFormat ("invalid section");
2600         }
2601         else
2602         {
2603             SectionSP section_sp (section.GetSP());
2604             if (section_sp)
2605             {
2606                 if (section_sp->IsThreadSpecific())
2607                 {
2608                     sb_error.SetErrorString ("thread specific sections are not yet supported");
2609                 }
2610                 else
2611                 {
2612                     ProcessSP process_sp (target_sp->GetProcessSP());
2613                     if (target_sp->SetSectionLoadAddress (section_sp, section_base_addr))
2614                     {
2615                         // Flush info in the process (stack frames, etc)
2616                         if (process_sp)
2617                             process_sp->Flush();
2618                     }
2619                 }
2620             }
2621         }
2622     }
2623     else
2624     {
2625         sb_error.SetErrorString ("invalid target");
2626     }
2627     return sb_error;
2628 }
2629 
2630 SBError
2631 SBTarget::ClearSectionLoadAddress (lldb::SBSection section)
2632 {
2633     SBError sb_error;
2634 
2635     TargetSP target_sp(GetSP());
2636     if (target_sp)
2637     {
2638         if (!section.IsValid())
2639         {
2640             sb_error.SetErrorStringWithFormat ("invalid section");
2641         }
2642         else
2643         {
2644             ProcessSP process_sp (target_sp->GetProcessSP());
2645             if (target_sp->SetSectionUnloaded (section.GetSP()))
2646             {
2647                 // Flush info in the process (stack frames, etc)
2648                 if (process_sp)
2649                     process_sp->Flush();
2650             }
2651         }
2652     }
2653     else
2654     {
2655         sb_error.SetErrorStringWithFormat ("invalid target");
2656     }
2657     return sb_error;
2658 }
2659 
2660 SBError
2661 SBTarget::SetModuleLoadAddress (lldb::SBModule module, int64_t slide_offset)
2662 {
2663     SBError sb_error;
2664 
2665     TargetSP target_sp(GetSP());
2666     if (target_sp)
2667     {
2668         ModuleSP module_sp (module.GetSP());
2669         if (module_sp)
2670         {
2671             bool changed = false;
2672             if (module_sp->SetLoadAddress (*target_sp, slide_offset, true, changed))
2673             {
2674                 // The load was successful, make sure that at least some sections
2675                 // changed before we notify that our module was loaded.
2676                 if (changed)
2677                 {
2678                     ModuleList module_list;
2679                     module_list.Append(module_sp);
2680                     target_sp->ModulesDidLoad (module_list);
2681                     // Flush info in the process (stack frames, etc)
2682                     ProcessSP process_sp (target_sp->GetProcessSP());
2683                     if (process_sp)
2684                         process_sp->Flush();
2685                 }
2686             }
2687         }
2688         else
2689         {
2690             sb_error.SetErrorStringWithFormat ("invalid module");
2691         }
2692 
2693     }
2694     else
2695     {
2696         sb_error.SetErrorStringWithFormat ("invalid target");
2697     }
2698     return sb_error;
2699 }
2700 
2701 SBError
2702 SBTarget::ClearModuleLoadAddress (lldb::SBModule module)
2703 {
2704     SBError sb_error;
2705 
2706     char path[PATH_MAX];
2707     TargetSP target_sp(GetSP());
2708     if (target_sp)
2709     {
2710         ModuleSP module_sp (module.GetSP());
2711         if (module_sp)
2712         {
2713             ObjectFile *objfile = module_sp->GetObjectFile();
2714             if (objfile)
2715             {
2716                 SectionList *section_list = objfile->GetSectionList();
2717                 if (section_list)
2718                 {
2719                     ProcessSP process_sp (target_sp->GetProcessSP());
2720 
2721                     bool changed = false;
2722                     const size_t num_sections = section_list->GetSize();
2723                     for (size_t sect_idx = 0; sect_idx < num_sections; ++sect_idx)
2724                     {
2725                         SectionSP section_sp (section_list->GetSectionAtIndex(sect_idx));
2726                         if (section_sp)
2727                             changed |= target_sp->SetSectionUnloaded (section_sp);
2728                     }
2729                     if (changed)
2730                     {
2731                         // Flush info in the process (stack frames, etc)
2732                         ProcessSP process_sp (target_sp->GetProcessSP());
2733                         if (process_sp)
2734                             process_sp->Flush();
2735                     }
2736                 }
2737                 else
2738                 {
2739                     module_sp->GetFileSpec().GetPath (path, sizeof(path));
2740                     sb_error.SetErrorStringWithFormat ("no sections in object file '%s'", path);
2741                 }
2742             }
2743             else
2744             {
2745                 module_sp->GetFileSpec().GetPath (path, sizeof(path));
2746                 sb_error.SetErrorStringWithFormat ("no object file for module '%s'", path);
2747             }
2748         }
2749         else
2750         {
2751             sb_error.SetErrorStringWithFormat ("invalid module");
2752         }
2753     }
2754     else
2755     {
2756         sb_error.SetErrorStringWithFormat ("invalid target");
2757     }
2758     return sb_error;
2759 }
2760 
2761 
2762 lldb::SBSymbolContextList
2763 SBTarget::FindSymbols (const char *name, lldb::SymbolType symbol_type)
2764 {
2765     SBSymbolContextList sb_sc_list;
2766     if (name && name[0])
2767     {
2768         TargetSP target_sp(GetSP());
2769         if (target_sp)
2770         {
2771             bool append = true;
2772             target_sp->GetImages().FindSymbolsWithNameAndType (ConstString(name),
2773                                                                symbol_type,
2774                                                                *sb_sc_list,
2775                                                                append);
2776         }
2777     }
2778     return sb_sc_list;
2779 
2780 }
2781 
2782 
2783 lldb::SBValue
2784 SBTarget::EvaluateExpression (const char *expr, const SBExpressionOptions &options)
2785 {
2786     Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
2787     Log * expr_log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
2788     SBValue expr_result;
2789     ExpressionResults exe_results = eExpressionSetupError;
2790     ValueObjectSP expr_value_sp;
2791     TargetSP target_sp(GetSP());
2792     StackFrame *frame = NULL;
2793     if (target_sp)
2794     {
2795         if (expr == NULL || expr[0] == '\0')
2796         {
2797             if (log)
2798                 log->Printf ("SBTarget::EvaluateExpression called with an empty expression");
2799             return expr_result;
2800         }
2801 
2802         Mutex::Locker api_locker (target_sp->GetAPIMutex());
2803         ExecutionContext exe_ctx (m_opaque_sp.get());
2804 
2805         if (log)
2806             log->Printf ("SBTarget()::EvaluateExpression (expr=\"%s\")...", expr);
2807 
2808         frame = exe_ctx.GetFramePtr();
2809         Target *target = exe_ctx.GetTargetPtr();
2810 
2811         if (target)
2812         {
2813 #ifdef LLDB_CONFIGURATION_DEBUG
2814             StreamString frame_description;
2815             if (frame)
2816                 frame->DumpUsingSettingsFormat (&frame_description);
2817             Host::SetCrashDescriptionWithFormat ("SBTarget::EvaluateExpression (expr = \"%s\", fetch_dynamic_value = %u) %s",
2818                                                  expr, options.GetFetchDynamicValue(), frame_description.GetString().c_str());
2819 #endif
2820             exe_results = target->EvaluateExpression (expr,
2821                                                       frame,
2822                                                       expr_value_sp,
2823                                                       options.ref());
2824 
2825             expr_result.SetSP(expr_value_sp, options.GetFetchDynamicValue());
2826 #ifdef LLDB_CONFIGURATION_DEBUG
2827             Host::SetCrashDescription (NULL);
2828 #endif
2829         }
2830         else
2831         {
2832             if (log)
2833                 log->Printf ("SBTarget::EvaluateExpression () => error: could not reconstruct frame object for this SBTarget.");
2834         }
2835     }
2836 #ifndef LLDB_DISABLE_PYTHON
2837     if (expr_log)
2838         expr_log->Printf("** [SBTarget::EvaluateExpression] Expression result is %s, summary %s **",
2839                          expr_result.GetValue(), expr_result.GetSummary());
2840 
2841     if (log)
2842         log->Printf ("SBTarget(%p)::EvaluateExpression (expr=\"%s\") => SBValue(%p) (execution result=%d)",
2843                      static_cast<void*>(frame), expr,
2844                      static_cast<void*>(expr_value_sp.get()), exe_results);
2845 #endif
2846 
2847     return expr_result;
2848 }
2849 
2850 
2851 lldb::addr_t
2852 SBTarget::GetStackRedZoneSize()
2853 {
2854     TargetSP target_sp(GetSP());
2855     if (target_sp)
2856     {
2857         ABISP abi_sp;
2858         ProcessSP process_sp (target_sp->GetProcessSP());
2859         if (process_sp)
2860             abi_sp = process_sp->GetABI();
2861         else
2862             abi_sp = ABI::FindPlugin(target_sp->GetArchitecture());
2863         if (abi_sp)
2864             return abi_sp->GetRedZoneSize();
2865     }
2866     return 0;
2867 }
2868 
2869