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