]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - source/API/SBThread.cpp
Vendor import of lldb release_39 branch r276489:
[FreeBSD/FreeBSD.git] / source / API / SBThread.cpp
1 //===-- SBThread.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/API/SBThread.h"
11
12 #include "lldb/API/SBSymbolContext.h"
13 #include "lldb/API/SBFileSpec.h"
14 #include "lldb/API/SBStream.h"
15 #include "lldb/Breakpoint/BreakpointLocation.h"
16 #include "lldb/Core/Debugger.h"
17 #include "lldb/Core/State.h"
18 #include "lldb/Core/Stream.h"
19 #include "lldb/Core/StreamFile.h"
20 #include "lldb/Core/StructuredData.h"
21 #include "lldb/Core/ValueObject.h"
22 #include "lldb/Interpreter/CommandInterpreter.h"
23 #include "lldb/Symbol/SymbolContext.h"
24 #include "lldb/Symbol/CompileUnit.h"
25 #include "lldb/Target/SystemRuntime.h"
26 #include "lldb/Target/Thread.h"
27 #include "lldb/Target/Process.h"
28 #include "lldb/Target/Queue.h"
29 #include "lldb/Target/UnixSignals.h"
30 #include "lldb/Target/StopInfo.h"
31 #include "lldb/Target/Target.h"
32 #include "lldb/Target/ThreadPlan.h"
33 #include "lldb/Target/ThreadPlanStepInstruction.h"
34 #include "lldb/Target/ThreadPlanStepOut.h"
35 #include "lldb/Target/ThreadPlanStepRange.h"
36 #include "lldb/Target/ThreadPlanStepInRange.h"
37
38 #include "lldb/API/SBAddress.h"
39 #include "lldb/API/SBDebugger.h"
40 #include "lldb/API/SBEvent.h"
41 #include "lldb/API/SBFrame.h"
42 #include "lldb/API/SBProcess.h"
43 #include "lldb/API/SBThreadCollection.h"
44 #include "lldb/API/SBThreadPlan.h"
45 #include "lldb/API/SBValue.h"
46
47 using namespace lldb;
48 using namespace lldb_private;
49
50 const char *
51 SBThread::GetBroadcasterClassName ()
52 {
53     return Thread::GetStaticBroadcasterClass().AsCString();
54 }
55
56 //----------------------------------------------------------------------
57 // Constructors
58 //----------------------------------------------------------------------
59 SBThread::SBThread () :
60     m_opaque_sp (new ExecutionContextRef())
61 {
62 }
63
64 SBThread::SBThread (const ThreadSP& lldb_object_sp) :
65     m_opaque_sp (new ExecutionContextRef(lldb_object_sp))
66 {
67 }
68
69 SBThread::SBThread (const SBThread &rhs) :
70     m_opaque_sp (new ExecutionContextRef(*rhs.m_opaque_sp))
71 {
72     
73 }
74
75 //----------------------------------------------------------------------
76 // Assignment operator
77 //----------------------------------------------------------------------
78
79 const lldb::SBThread &
80 SBThread::operator = (const SBThread &rhs)
81 {
82     if (this != &rhs)
83         *m_opaque_sp = *rhs.m_opaque_sp;
84     return *this;
85 }
86
87 //----------------------------------------------------------------------
88 // Destructor
89 //----------------------------------------------------------------------
90 SBThread::~SBThread()
91 {
92 }
93
94 lldb::SBQueue
95 SBThread::GetQueue () const
96 {
97     SBQueue sb_queue;
98     QueueSP queue_sp;
99     std::unique_lock<std::recursive_mutex> lock;
100     ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
101
102     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
103     if (exe_ctx.HasThreadScope())
104     {
105         Process::StopLocker stop_locker;
106         if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
107         {
108             queue_sp = exe_ctx.GetThreadPtr()->GetQueue();
109             if (queue_sp)
110             {
111                 sb_queue.SetQueue (queue_sp);
112             }
113         }
114         else
115         {
116             if (log)
117                 log->Printf ("SBThread(%p)::GetQueue() => error: process is running",
118                              static_cast<void*>(exe_ctx.GetThreadPtr()));
119         }
120     }
121
122     if (log)
123         log->Printf ("SBThread(%p)::GetQueue () => SBQueue(%p)",
124                      static_cast<void*>(exe_ctx.GetThreadPtr()), static_cast<void*>(queue_sp.get()));
125
126     return sb_queue;
127 }
128
129
130 bool
131 SBThread::IsValid() const
132 {
133     std::unique_lock<std::recursive_mutex> lock;
134     ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
135
136     Target *target = exe_ctx.GetTargetPtr();
137     Process *process = exe_ctx.GetProcessPtr();
138     if (target && process)
139     {
140         Process::StopLocker stop_locker;
141         if (stop_locker.TryLock(&process->GetRunLock()))
142         return m_opaque_sp->GetThreadSP().get() != NULL;
143     }
144     // Without a valid target & process, this thread can't be valid.
145     return false;
146 }
147
148 void
149 SBThread::Clear ()
150 {
151     m_opaque_sp->Clear();
152 }
153
154
155 StopReason
156 SBThread::GetStopReason()
157 {
158     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
159
160     StopReason reason = eStopReasonInvalid;
161     std::unique_lock<std::recursive_mutex> lock;
162     ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
163
164     if (exe_ctx.HasThreadScope())
165     {
166         Process::StopLocker stop_locker;
167         if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
168         {
169             return exe_ctx.GetThreadPtr()->GetStopReason();
170         }
171         else
172         {
173             if (log)
174                 log->Printf ("SBThread(%p)::GetStopReason() => error: process is running",
175                              static_cast<void*>(exe_ctx.GetThreadPtr()));
176         }
177     }
178
179     if (log)
180         log->Printf ("SBThread(%p)::GetStopReason () => %s",
181                      static_cast<void*>(exe_ctx.GetThreadPtr()),
182                      Thread::StopReasonAsCString (reason));
183
184     return reason;
185 }
186
187 size_t
188 SBThread::GetStopReasonDataCount ()
189 {
190     std::unique_lock<std::recursive_mutex> lock;
191     ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
192
193     if (exe_ctx.HasThreadScope())
194     {
195         Process::StopLocker stop_locker;
196         if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
197         {
198             StopInfoSP stop_info_sp = exe_ctx.GetThreadPtr()->GetStopInfo ();
199             if (stop_info_sp)
200             {
201                 StopReason reason = stop_info_sp->GetStopReason();
202                 switch (reason)
203                 {
204                 case eStopReasonInvalid:
205                 case eStopReasonNone:
206                 case eStopReasonTrace:
207                 case eStopReasonExec:
208                 case eStopReasonPlanComplete:
209                 case eStopReasonThreadExiting:
210                 case eStopReasonInstrumentation:
211                     // There is no data for these stop reasons.
212                     return 0;
213
214                 case eStopReasonBreakpoint:
215                     {
216                         break_id_t site_id = stop_info_sp->GetValue();
217                         lldb::BreakpointSiteSP bp_site_sp (exe_ctx.GetProcessPtr()->GetBreakpointSiteList().FindByID (site_id));
218                         if (bp_site_sp)
219                             return bp_site_sp->GetNumberOfOwners () * 2;
220                         else
221                             return 0; // Breakpoint must have cleared itself...
222                     }
223                     break;
224
225                 case eStopReasonWatchpoint:
226                     return 1;
227
228                 case eStopReasonSignal:
229                     return 1;
230
231                 case eStopReasonException:
232                     return 1;
233                 }
234             }
235         }
236         else
237         {
238             Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
239             if (log)
240                 log->Printf ("SBThread(%p)::GetStopReasonDataCount() => error: process is running",
241                              static_cast<void*>(exe_ctx.GetThreadPtr()));
242         }
243     }
244     return 0;
245 }
246
247 uint64_t
248 SBThread::GetStopReasonDataAtIndex (uint32_t idx)
249 {
250     std::unique_lock<std::recursive_mutex> lock;
251     ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
252
253     if (exe_ctx.HasThreadScope())
254     {
255         Process::StopLocker stop_locker;
256         if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
257         {
258             Thread *thread = exe_ctx.GetThreadPtr();
259             StopInfoSP stop_info_sp = thread->GetStopInfo ();
260             if (stop_info_sp)
261             {
262                 StopReason reason = stop_info_sp->GetStopReason();
263                 switch (reason)
264                 {
265                 case eStopReasonInvalid:
266                 case eStopReasonNone:
267                 case eStopReasonTrace:
268                 case eStopReasonExec:
269                 case eStopReasonPlanComplete:
270                 case eStopReasonThreadExiting:
271                 case eStopReasonInstrumentation:
272                     // There is no data for these stop reasons.
273                     return 0;
274
275                 case eStopReasonBreakpoint:
276                     {
277                         break_id_t site_id = stop_info_sp->GetValue();
278                         lldb::BreakpointSiteSP bp_site_sp (exe_ctx.GetProcessPtr()->GetBreakpointSiteList().FindByID (site_id));
279                         if (bp_site_sp)
280                         {
281                             uint32_t bp_index = idx / 2;
282                             BreakpointLocationSP bp_loc_sp (bp_site_sp->GetOwnerAtIndex (bp_index));
283                             if (bp_loc_sp)
284                             {
285                                 if (idx & 1)
286                                 {
287                                     // Odd idx, return the breakpoint location ID
288                                     return bp_loc_sp->GetID();
289                                 }
290                                 else
291                                 {
292                                     // Even idx, return the breakpoint ID
293                                     return bp_loc_sp->GetBreakpoint().GetID();
294                                 }
295                             }
296                         }
297                         return LLDB_INVALID_BREAK_ID;
298                     }
299                     break;
300
301                 case eStopReasonWatchpoint:
302                     return stop_info_sp->GetValue();
303
304                 case eStopReasonSignal:
305                     return stop_info_sp->GetValue();
306
307                 case eStopReasonException:
308                     return stop_info_sp->GetValue();
309                 }
310             }
311         }
312         else
313         {
314             Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
315             if (log)
316                 log->Printf ("SBThread(%p)::GetStopReasonDataAtIndex() => error: process is running",
317                              static_cast<void*>(exe_ctx.GetThreadPtr()));
318         }
319     }
320     return 0;
321 }
322
323 bool
324 SBThread::GetStopReasonExtendedInfoAsJSON (lldb::SBStream &stream)
325 {
326     Stream &strm = stream.ref();
327     
328     std::unique_lock<std::recursive_mutex> lock;
329     ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
330
331     if (! exe_ctx.HasThreadScope())
332         return false;
333
334     
335     StopInfoSP stop_info = exe_ctx.GetThreadPtr()->GetStopInfo();
336     StructuredData::ObjectSP info = stop_info->GetExtendedInfo();
337     if (! info)
338         return false;
339
340     info->Dump(strm);
341     
342     return true;
343 }
344
345 SBThreadCollection
346 SBThread::GetStopReasonExtendedBacktraces (InstrumentationRuntimeType type)
347 {
348     ThreadCollectionSP threads;
349     threads.reset(new ThreadCollection());
350     
351     // We currently only support ThreadSanitizer.
352     if (type != eInstrumentationRuntimeTypeThreadSanitizer)
353         return threads;
354     
355     std::unique_lock<std::recursive_mutex> lock;
356     ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
357
358     if (! exe_ctx.HasThreadScope())
359         return threads;
360     
361     ProcessSP process_sp = exe_ctx.GetProcessSP();
362     
363     StopInfoSP stop_info = exe_ctx.GetThreadPtr()->GetStopInfo();
364     StructuredData::ObjectSP info = stop_info->GetExtendedInfo();
365     if (! info)
366         return threads;
367     
368     return process_sp->GetInstrumentationRuntime(type)->GetBacktracesFromExtendedStopInfo(info);
369 }
370
371 size_t
372 SBThread::GetStopDescription (char *dst, size_t dst_len)
373 {
374     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
375
376     std::unique_lock<std::recursive_mutex> lock;
377     ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
378
379     if (exe_ctx.HasThreadScope())
380     {
381         Process::StopLocker stop_locker;
382         if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
383         {
384
385             StopInfoSP stop_info_sp = exe_ctx.GetThreadPtr()->GetStopInfo ();
386             if (stop_info_sp)
387             {
388                 const char *stop_desc = stop_info_sp->GetDescription();
389                 if (stop_desc)
390                 {
391                     if (log)
392                         log->Printf ("SBThread(%p)::GetStopDescription (dst, dst_len) => \"%s\"",
393                                      static_cast<void*>(exe_ctx.GetThreadPtr()),
394                                      stop_desc);
395                     if (dst)
396                         return ::snprintf (dst, dst_len, "%s", stop_desc);
397                     else
398                     {
399                         // NULL dst passed in, return the length needed to contain the description
400                         return ::strlen (stop_desc) + 1; // Include the NULL byte for size
401                     }
402                 }
403                 else
404                 {
405                     size_t stop_desc_len = 0;
406                     switch (stop_info_sp->GetStopReason())
407                     {
408                     case eStopReasonTrace:
409                     case eStopReasonPlanComplete:
410                         {
411                             static char trace_desc[] = "step";
412                             stop_desc = trace_desc;
413                             stop_desc_len = sizeof(trace_desc); // Include the NULL byte for size
414                         }
415                         break;
416
417                     case eStopReasonBreakpoint:
418                         {
419                             static char bp_desc[] = "breakpoint hit";
420                             stop_desc = bp_desc;
421                             stop_desc_len = sizeof(bp_desc); // Include the NULL byte for size
422                         }
423                         break;
424
425                     case eStopReasonWatchpoint:
426                         {
427                             static char wp_desc[] = "watchpoint hit";
428                             stop_desc = wp_desc;
429                             stop_desc_len = sizeof(wp_desc); // Include the NULL byte for size
430                         }
431                         break;
432
433                     case eStopReasonSignal:
434                         {
435                             stop_desc = exe_ctx.GetProcessPtr()->GetUnixSignals()->GetSignalAsCString(stop_info_sp->GetValue());
436                             if (stop_desc == NULL || stop_desc[0] == '\0')
437                             {
438                                 static char signal_desc[] = "signal";
439                                 stop_desc = signal_desc;
440                                 stop_desc_len = sizeof(signal_desc); // Include the NULL byte for size
441                             }
442                         }
443                         break;
444
445                     case eStopReasonException:
446                         {
447                             char exc_desc[] = "exception";
448                             stop_desc = exc_desc;
449                             stop_desc_len = sizeof(exc_desc); // Include the NULL byte for size
450                         }
451                         break;          
452
453                     case eStopReasonExec:
454                         {
455                             char exc_desc[] = "exec";
456                             stop_desc = exc_desc;
457                             stop_desc_len = sizeof(exc_desc); // Include the NULL byte for size
458                         }
459                         break;
460
461                     case eStopReasonThreadExiting:
462                         {
463                             char limbo_desc[] = "thread exiting";
464                             stop_desc = limbo_desc;
465                             stop_desc_len = sizeof(limbo_desc);
466                         }
467                         break;
468                     default:
469                         break;
470                     }
471
472                     if (stop_desc && stop_desc[0])
473                     {
474                         if (log)
475                             log->Printf ("SBThread(%p)::GetStopDescription (dst, dst_len) => '%s'",
476                                          static_cast<void*>(exe_ctx.GetThreadPtr()),
477                                          stop_desc);
478
479                         if (dst)
480                             return ::snprintf (dst, dst_len, "%s", stop_desc) + 1; // Include the NULL byte
481
482                         if (stop_desc_len == 0)
483                             stop_desc_len = ::strlen (stop_desc) + 1; // Include the NULL byte
484
485                         return stop_desc_len;
486                     }
487                 }
488             }
489         }
490         else
491         {
492             Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
493             if (log)
494                 log->Printf ("SBThread(%p)::GetStopDescription() => error: process is running",
495                              static_cast<void*>(exe_ctx.GetThreadPtr()));
496         }
497     }
498     if (dst)
499         *dst = 0;
500     return 0;
501 }
502
503 SBValue
504 SBThread::GetStopReturnValue ()
505 {
506     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
507     ValueObjectSP return_valobj_sp;
508     std::unique_lock<std::recursive_mutex> lock;
509     ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
510
511     if (exe_ctx.HasThreadScope())
512     {
513         Process::StopLocker stop_locker;
514         if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
515         {
516             StopInfoSP stop_info_sp = exe_ctx.GetThreadPtr()->GetStopInfo ();
517             if (stop_info_sp)
518             {
519                 return_valobj_sp = StopInfo::GetReturnValueObject (stop_info_sp);
520             }
521         }
522         else
523         {
524             if (log)
525                 log->Printf ("SBThread(%p)::GetStopReturnValue() => error: process is running",
526                              static_cast<void*>(exe_ctx.GetThreadPtr()));
527         }
528     }
529
530     if (log)
531         log->Printf ("SBThread(%p)::GetStopReturnValue () => %s",
532                      static_cast<void*>(exe_ctx.GetThreadPtr()),
533                      return_valobj_sp.get()
534                         ? return_valobj_sp->GetValueAsCString()
535                         : "<no return value>");
536
537     return SBValue (return_valobj_sp);
538 }
539
540 void
541 SBThread::SetThread (const ThreadSP& lldb_object_sp)
542 {
543     m_opaque_sp->SetThreadSP (lldb_object_sp);
544 }
545
546 lldb::tid_t
547 SBThread::GetThreadID () const
548 {
549     ThreadSP thread_sp(m_opaque_sp->GetThreadSP());
550     if (thread_sp)
551         return thread_sp->GetID();
552     return LLDB_INVALID_THREAD_ID;
553 }
554
555 uint32_t
556 SBThread::GetIndexID () const
557 {
558     ThreadSP thread_sp(m_opaque_sp->GetThreadSP());
559     if (thread_sp)
560         return thread_sp->GetIndexID();
561     return LLDB_INVALID_INDEX32;
562 }
563
564 const char *
565 SBThread::GetName () const
566 {
567     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
568     const char *name = NULL;
569     std::unique_lock<std::recursive_mutex> lock;
570     ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
571
572     if (exe_ctx.HasThreadScope())
573     {
574         Process::StopLocker stop_locker;
575         if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
576         {
577             name = exe_ctx.GetThreadPtr()->GetName();
578         }
579         else
580         {
581             if (log)
582                 log->Printf ("SBThread(%p)::GetName() => error: process is running",
583                              static_cast<void*>(exe_ctx.GetThreadPtr()));
584         }
585     }
586
587     if (log)
588         log->Printf ("SBThread(%p)::GetName () => %s",
589                      static_cast<void*>(exe_ctx.GetThreadPtr()),
590                      name ? name : "NULL");
591
592     return name;
593 }
594
595 const char *
596 SBThread::GetQueueName () const
597 {
598     const char *name = NULL;
599     std::unique_lock<std::recursive_mutex> lock;
600     ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
601
602     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
603     if (exe_ctx.HasThreadScope())
604     {
605         Process::StopLocker stop_locker;
606         if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
607         {
608             name = exe_ctx.GetThreadPtr()->GetQueueName();
609         }
610         else
611         {
612             if (log)
613                 log->Printf ("SBThread(%p)::GetQueueName() => error: process is running",
614                              static_cast<void*>(exe_ctx.GetThreadPtr()));
615         }
616     }
617
618     if (log)
619         log->Printf ("SBThread(%p)::GetQueueName () => %s",
620                      static_cast<void*>(exe_ctx.GetThreadPtr()),
621                      name ? name : "NULL");
622
623     return name;
624 }
625
626 lldb::queue_id_t
627 SBThread::GetQueueID () const
628 {
629     queue_id_t id = LLDB_INVALID_QUEUE_ID;
630     std::unique_lock<std::recursive_mutex> lock;
631     ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
632
633     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
634     if (exe_ctx.HasThreadScope())
635     {
636         Process::StopLocker stop_locker;
637         if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
638         {
639             id = exe_ctx.GetThreadPtr()->GetQueueID();
640         }
641         else
642         {
643             if (log)
644                 log->Printf ("SBThread(%p)::GetQueueID() => error: process is running",
645                              static_cast<void*>(exe_ctx.GetThreadPtr()));
646         }
647     }
648
649     if (log)
650         log->Printf ("SBThread(%p)::GetQueueID () => 0x%" PRIx64,
651                      static_cast<void*>(exe_ctx.GetThreadPtr()), id);
652
653     return id;
654 }
655
656 bool
657 SBThread::GetInfoItemByPathAsString (const char *path, SBStream &strm)
658 {
659     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
660     bool success = false;
661     std::unique_lock<std::recursive_mutex> lock;
662     ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
663
664     if (exe_ctx.HasThreadScope())
665     {
666         Process::StopLocker stop_locker;
667         if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
668         {
669             Thread *thread = exe_ctx.GetThreadPtr();
670             StructuredData::ObjectSP info_root_sp = thread->GetExtendedInfo();
671             if (info_root_sp)
672             {
673                 StructuredData::ObjectSP node = info_root_sp->GetObjectForDotSeparatedPath (path);
674                 if (node)
675                 {
676                     if (node->GetType() == StructuredData::Type::eTypeString)
677                     {
678                         strm.Printf ("%s", node->GetAsString()->GetValue().c_str());
679                         success = true;
680                     }
681                     if (node->GetType() == StructuredData::Type::eTypeInteger)
682                     {
683                         strm.Printf ("0x%" PRIx64, node->GetAsInteger()->GetValue());
684                         success = true;
685                     }
686                     if (node->GetType() == StructuredData::Type::eTypeFloat)
687                     {
688                         strm.Printf ("0x%f", node->GetAsFloat()->GetValue());
689                         success = true;
690                     }
691                     if (node->GetType() == StructuredData::Type::eTypeBoolean)
692                     {
693                         if (node->GetAsBoolean()->GetValue() == true)
694                             strm.Printf ("true");
695                         else
696                             strm.Printf ("false");
697                         success = true;
698                     }
699                     if (node->GetType() == StructuredData::Type::eTypeNull)
700                     {
701                         strm.Printf ("null");
702                         success = true;
703                     }
704                 }
705             }
706         }
707         else
708         {
709             if (log)
710                 log->Printf ("SBThread(%p)::GetInfoItemByPathAsString() => error: process is running",
711                              static_cast<void*>(exe_ctx.GetThreadPtr()));
712         }
713     }
714
715     if (log)
716         log->Printf ("SBThread(%p)::GetInfoItemByPathAsString () => %s",
717                      static_cast<void*>(exe_ctx.GetThreadPtr()),
718                      strm.GetData());
719
720     return success;
721 }
722
723
724 SBError
725 SBThread::ResumeNewPlan (ExecutionContext &exe_ctx, ThreadPlan *new_plan)
726 {
727     SBError sb_error;
728     
729     Process *process = exe_ctx.GetProcessPtr();
730     if (!process)
731     {
732         sb_error.SetErrorString("No process in SBThread::ResumeNewPlan");
733         return sb_error;
734     }
735
736     Thread *thread = exe_ctx.GetThreadPtr();
737     if (!thread)
738     {
739         sb_error.SetErrorString("No thread in SBThread::ResumeNewPlan");
740         return sb_error;
741     }
742     
743     // User level plans should be Master Plans so they can be interrupted, other plans executed, and
744     // then a "continue" will resume the plan.
745     if (new_plan != NULL)
746     {
747         new_plan->SetIsMasterPlan(true);
748         new_plan->SetOkayToDiscard(false);
749     }
750     
751     // Why do we need to set the current thread by ID here???
752     process->GetThreadList().SetSelectedThreadByID (thread->GetID());
753
754     if (process->GetTarget().GetDebugger().GetAsyncExecution ())
755         sb_error.ref() = process->Resume ();
756     else
757         sb_error.ref() = process->ResumeSynchronous (NULL);
758     
759     return sb_error;
760 }
761
762 void
763 SBThread::StepOver (lldb::RunMode stop_other_threads)
764 {
765     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
766
767     std::unique_lock<std::recursive_mutex> lock;
768     ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
769
770     if (log)
771         log->Printf ("SBThread(%p)::StepOver (stop_other_threads='%s')",
772                      static_cast<void*>(exe_ctx.GetThreadPtr()),
773                      Thread::RunModeAsCString (stop_other_threads));
774
775     if (exe_ctx.HasThreadScope())
776     {
777         Thread *thread = exe_ctx.GetThreadPtr();
778         bool abort_other_plans = false;
779         StackFrameSP frame_sp(thread->GetStackFrameAtIndex (0));
780
781         ThreadPlanSP new_plan_sp;
782         if (frame_sp)
783         {
784             if (frame_sp->HasDebugInformation ())
785             {
786                 const LazyBool avoid_no_debug = eLazyBoolCalculate;
787                 SymbolContext sc(frame_sp->GetSymbolContext(eSymbolContextEverything));
788                 new_plan_sp = thread->QueueThreadPlanForStepOverRange (abort_other_plans,
789                                                                     sc.line_entry,
790                                                                     sc,
791                                                                     stop_other_threads,
792                                                                     avoid_no_debug);
793             }
794             else
795             {
796                 new_plan_sp = thread->QueueThreadPlanForStepSingleInstruction (true,
797                                                                                abort_other_plans,
798                                                                                stop_other_threads);
799             }
800         }
801
802         // This returns an error, we should use it!
803         ResumeNewPlan (exe_ctx, new_plan_sp.get());
804     }
805 }
806
807 void
808 SBThread::StepInto (lldb::RunMode stop_other_threads)
809 {
810     StepInto (NULL, stop_other_threads);
811 }
812
813 void
814 SBThread::StepInto (const char *target_name, lldb::RunMode stop_other_threads)
815 {
816     SBError error;
817     StepInto(target_name, LLDB_INVALID_LINE_NUMBER, error, stop_other_threads);
818 }
819
820 void
821 SBThread::StepInto (const char *target_name, uint32_t end_line, SBError &error, lldb::RunMode stop_other_threads)
822 {
823     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
824
825     std::unique_lock<std::recursive_mutex> lock;
826     ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
827
828     if (log)
829         log->Printf ("SBThread(%p)::StepInto (target_name='%s', stop_other_threads='%s')",
830                      static_cast<void*>(exe_ctx.GetThreadPtr()),
831                      target_name? target_name: "<NULL>",
832                      Thread::RunModeAsCString (stop_other_threads));
833
834     if (exe_ctx.HasThreadScope())
835     {
836         bool abort_other_plans = false;
837
838         Thread *thread = exe_ctx.GetThreadPtr();
839         StackFrameSP frame_sp(thread->GetStackFrameAtIndex (0));
840         ThreadPlanSP new_plan_sp;
841
842         if (frame_sp && frame_sp->HasDebugInformation ())
843         {
844             SymbolContext sc(frame_sp->GetSymbolContext(eSymbolContextEverything));
845             AddressRange range;
846             if (end_line == LLDB_INVALID_LINE_NUMBER)
847                 range = sc.line_entry.range;
848             else
849             {
850                 if (!sc.GetAddressRangeFromHereToEndLine(end_line, range, error.ref()))
851                     return;
852             }
853             
854             const LazyBool step_out_avoids_code_without_debug_info = eLazyBoolCalculate;
855             const LazyBool step_in_avoids_code_without_debug_info = eLazyBoolCalculate;
856             new_plan_sp = thread->QueueThreadPlanForStepInRange (abort_other_plans,
857                                                               range,
858                                                               sc,
859                                                               target_name,
860                                                               stop_other_threads,
861                                                               step_in_avoids_code_without_debug_info,
862                                                               step_out_avoids_code_without_debug_info);
863         }
864         else
865         {
866             new_plan_sp = thread->QueueThreadPlanForStepSingleInstruction (false,
867                                                                            abort_other_plans,
868                                                                            stop_other_threads);
869         }
870
871         error = ResumeNewPlan (exe_ctx, new_plan_sp.get());
872     }
873 }
874
875 void
876 SBThread::StepOut ()
877 {
878     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
879
880     std::unique_lock<std::recursive_mutex> lock;
881     ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
882
883     if (log)
884         log->Printf ("SBThread(%p)::StepOut ()",
885                      static_cast<void*>(exe_ctx.GetThreadPtr()));
886
887     if (exe_ctx.HasThreadScope())
888     {
889         bool abort_other_plans = false;
890         bool stop_other_threads = false;
891
892         Thread *thread = exe_ctx.GetThreadPtr();
893
894         const LazyBool avoid_no_debug = eLazyBoolCalculate;
895         ThreadPlanSP new_plan_sp(thread->QueueThreadPlanForStepOut (abort_other_plans,
896                                                                     NULL,
897                                                                     false,
898                                                                     stop_other_threads,
899                                                                     eVoteYes,
900                                                                     eVoteNoOpinion,
901                                                                     0,
902                                                                     avoid_no_debug));
903
904         // This returns an error, we should use it!
905         ResumeNewPlan (exe_ctx, new_plan_sp.get());
906     }
907 }
908
909 void
910 SBThread::StepOutOfFrame (lldb::SBFrame &sb_frame)
911 {
912     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
913
914     std::unique_lock<std::recursive_mutex> lock;
915     ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
916
917     if (!sb_frame.IsValid())
918     {
919         if (log)
920             log->Printf("SBThread(%p)::StepOutOfFrame passed an invalid frame, returning.",
921                         static_cast<void*>(exe_ctx.GetThreadPtr()));
922         return;
923     }
924     
925     StackFrameSP frame_sp (sb_frame.GetFrameSP());
926     if (log)
927     {
928         SBStream frame_desc_strm;
929         sb_frame.GetDescription (frame_desc_strm);
930         log->Printf ("SBThread(%p)::StepOutOfFrame (frame = SBFrame(%p): %s)",
931                      static_cast<void*>(exe_ctx.GetThreadPtr()),
932                      static_cast<void*>(frame_sp.get()),
933                      frame_desc_strm.GetData());
934     }
935
936     if (exe_ctx.HasThreadScope())
937     {
938         bool abort_other_plans = false;
939         bool stop_other_threads = false;
940         Thread *thread = exe_ctx.GetThreadPtr();
941         if (sb_frame.GetThread().GetThreadID() != thread->GetID())
942         {
943             log->Printf("SBThread(%p)::StepOutOfFrame passed a frame from another thread (0x%" PRIx64 " vrs. 0x%" PRIx64 ", returning.",
944                         static_cast<void*>(exe_ctx.GetThreadPtr()),
945                         sb_frame.GetThread().GetThreadID(),
946                         thread->GetID());
947         }
948
949         ThreadPlanSP new_plan_sp(thread->QueueThreadPlanForStepOut (abort_other_plans,
950                                                                     NULL,
951                                                                     false,
952                                                                     stop_other_threads,
953                                                                     eVoteYes,
954                                                                     eVoteNoOpinion,
955                                                                     frame_sp->GetFrameIndex()));
956
957         // This returns an error, we should use it!
958         ResumeNewPlan (exe_ctx, new_plan_sp.get());
959     }
960 }
961
962 void
963 SBThread::StepInstruction (bool step_over)
964 {
965     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
966
967     std::unique_lock<std::recursive_mutex> lock;
968     ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
969
970     if (log)
971         log->Printf ("SBThread(%p)::StepInstruction (step_over=%i)",
972                      static_cast<void*>(exe_ctx.GetThreadPtr()), step_over);
973
974     if (exe_ctx.HasThreadScope())
975     {
976         Thread *thread = exe_ctx.GetThreadPtr();
977         ThreadPlanSP new_plan_sp(thread->QueueThreadPlanForStepSingleInstruction (step_over, true, true));
978
979         // This returns an error, we should use it!
980         ResumeNewPlan (exe_ctx, new_plan_sp.get());
981     }
982 }
983
984 void
985 SBThread::RunToAddress (lldb::addr_t addr)
986 {
987     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
988
989     std::unique_lock<std::recursive_mutex> lock;
990     ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
991
992     if (log)
993         log->Printf ("SBThread(%p)::RunToAddress (addr=0x%" PRIx64 ")",
994                      static_cast<void*>(exe_ctx.GetThreadPtr()), addr);
995
996     if (exe_ctx.HasThreadScope())
997     {
998         bool abort_other_plans = false;
999         bool stop_other_threads = true;
1000
1001         Address target_addr (addr);
1002
1003         Thread *thread = exe_ctx.GetThreadPtr();
1004
1005         ThreadPlanSP new_plan_sp(thread->QueueThreadPlanForRunToAddress (abort_other_plans,
1006                                                                          target_addr,
1007                                                                          stop_other_threads));
1008
1009         // This returns an error, we should use it!
1010         ResumeNewPlan (exe_ctx, new_plan_sp.get());
1011     }
1012 }
1013
1014 SBError
1015 SBThread::StepOverUntil (lldb::SBFrame &sb_frame, 
1016                          lldb::SBFileSpec &sb_file_spec, 
1017                          uint32_t line)
1018 {
1019     SBError sb_error;
1020     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1021     char path[PATH_MAX];
1022
1023     std::unique_lock<std::recursive_mutex> lock;
1024     ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
1025
1026     StackFrameSP frame_sp (sb_frame.GetFrameSP());
1027
1028     if (log)
1029     {
1030         SBStream frame_desc_strm;
1031         sb_frame.GetDescription (frame_desc_strm);
1032         sb_file_spec->GetPath (path, sizeof(path));
1033         log->Printf ("SBThread(%p)::StepOverUntil (frame = SBFrame(%p): %s, file+line = %s:%u)",
1034                      static_cast<void*>(exe_ctx.GetThreadPtr()),
1035                      static_cast<void*>(frame_sp.get()),
1036                      frame_desc_strm.GetData(), path, line);
1037     }
1038
1039     if (exe_ctx.HasThreadScope())
1040     {
1041         Target *target = exe_ctx.GetTargetPtr();
1042         Thread *thread = exe_ctx.GetThreadPtr();
1043
1044         if (line == 0)
1045         {
1046             sb_error.SetErrorString("invalid line argument");
1047             return sb_error;
1048         }
1049
1050         if (!frame_sp)
1051         {
1052             frame_sp = thread->GetSelectedFrame ();
1053             if (!frame_sp)
1054                 frame_sp = thread->GetStackFrameAtIndex (0);
1055         }
1056
1057         SymbolContext frame_sc;
1058         if (!frame_sp)        
1059         {
1060             sb_error.SetErrorString("no valid frames in thread to step");
1061             return sb_error;
1062         }
1063
1064         // If we have a frame, get its line
1065         frame_sc = frame_sp->GetSymbolContext (eSymbolContextCompUnit  |
1066                                                eSymbolContextFunction  | 
1067                                                eSymbolContextLineEntry | 
1068                                                eSymbolContextSymbol    );
1069
1070         if (frame_sc.comp_unit == NULL)
1071         {
1072             sb_error.SetErrorStringWithFormat("frame %u doesn't have debug information", frame_sp->GetFrameIndex());
1073             return sb_error;
1074         }
1075
1076         FileSpec step_file_spec;
1077         if (sb_file_spec.IsValid())
1078         {
1079             // The file spec passed in was valid, so use it
1080             step_file_spec = sb_file_spec.ref();
1081         }
1082         else
1083         {
1084             if (frame_sc.line_entry.IsValid())
1085                 step_file_spec = frame_sc.line_entry.file;
1086             else
1087             {
1088                 sb_error.SetErrorString("invalid file argument or no file for frame");
1089                 return sb_error;
1090             }
1091         }
1092
1093         // Grab the current function, then we will make sure the "until" address is
1094         // within the function.  We discard addresses that are out of the current
1095         // function, and then if there are no addresses remaining, give an appropriate
1096         // error message.
1097
1098         bool all_in_function = true;
1099         AddressRange fun_range = frame_sc.function->GetAddressRange();
1100
1101         std::vector<addr_t> step_over_until_addrs;
1102         const bool abort_other_plans = false;
1103         const bool stop_other_threads = false;
1104         const bool check_inlines = true;
1105         const bool exact = false;
1106
1107         SymbolContextList sc_list;
1108         const uint32_t num_matches = frame_sc.comp_unit->ResolveSymbolContext (step_file_spec, 
1109                                                                                line, 
1110                                                                                check_inlines, 
1111                                                                                exact, 
1112                                                                                eSymbolContextLineEntry, 
1113                                                                                sc_list);
1114         if (num_matches > 0)
1115         {
1116             SymbolContext sc;
1117             for (uint32_t i=0; i<num_matches; ++i)
1118             {
1119                 if (sc_list.GetContextAtIndex(i, sc))
1120                 {
1121                     addr_t step_addr = sc.line_entry.range.GetBaseAddress().GetLoadAddress(target);
1122                     if (step_addr != LLDB_INVALID_ADDRESS)
1123                     {
1124                         if (fun_range.ContainsLoadAddress(step_addr, target))
1125                             step_over_until_addrs.push_back(step_addr);
1126                         else
1127                             all_in_function = false;
1128                     }
1129                 }
1130             }
1131         }
1132
1133         if (step_over_until_addrs.empty())
1134         {
1135             if (all_in_function)
1136             {
1137                 step_file_spec.GetPath (path, sizeof(path));
1138                 sb_error.SetErrorStringWithFormat("No line entries for %s:%u", path, line);
1139             }
1140             else
1141                 sb_error.SetErrorString ("step until target not in current function");
1142         }
1143         else
1144         {
1145             ThreadPlanSP new_plan_sp(thread->QueueThreadPlanForStepUntil (abort_other_plans,
1146                                                                         &step_over_until_addrs[0],
1147                                                                         step_over_until_addrs.size(),
1148                                                                         stop_other_threads,
1149                                                                         frame_sp->GetFrameIndex()));
1150
1151             sb_error = ResumeNewPlan (exe_ctx, new_plan_sp.get());
1152         }
1153     }
1154     else
1155     {
1156         sb_error.SetErrorString("this SBThread object is invalid");
1157     }
1158     return sb_error;
1159 }
1160
1161 SBError
1162 SBThread::StepUsingScriptedThreadPlan (const char *script_class_name)
1163 {
1164     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1165     SBError sb_error;
1166
1167     std::unique_lock<std::recursive_mutex> lock;
1168     ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
1169
1170     if (log)
1171     {
1172         log->Printf ("SBThread(%p)::StepUsingScriptedThreadPlan: class name: %s",
1173                      static_cast<void*>(exe_ctx.GetThreadPtr()),
1174                      script_class_name);
1175     }
1176
1177
1178     if (!exe_ctx.HasThreadScope())
1179     {
1180         sb_error.SetErrorString("this SBThread object is invalid");
1181         return sb_error;
1182     }
1183
1184     Thread *thread = exe_ctx.GetThreadPtr();
1185     ThreadPlanSP thread_plan_sp = thread->QueueThreadPlanForStepScripted(false, script_class_name, false);
1186
1187     if (thread_plan_sp)
1188         sb_error = ResumeNewPlan(exe_ctx, thread_plan_sp.get());
1189     else
1190     {
1191         sb_error.SetErrorStringWithFormat("Error queuing thread plan for class: %s.", script_class_name);
1192         if (log)
1193         log->Printf ("SBThread(%p)::StepUsingScriptedThreadPlan: Error queuing thread plan for class: %s",
1194                      static_cast<void*>(exe_ctx.GetThreadPtr()),
1195                      script_class_name);
1196     }
1197
1198     return sb_error;
1199 }
1200
1201 SBError
1202 SBThread::JumpToLine (lldb::SBFileSpec &file_spec, uint32_t line)
1203 {
1204     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1205     SBError sb_error;
1206
1207     std::unique_lock<std::recursive_mutex> lock;
1208     ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
1209
1210     if (log)
1211         log->Printf ("SBThread(%p)::JumpToLine (file+line = %s:%u)",
1212                      static_cast<void*>(exe_ctx.GetThreadPtr()),
1213                      file_spec->GetPath().c_str(), line);
1214
1215     if (!exe_ctx.HasThreadScope())
1216     {
1217         sb_error.SetErrorString("this SBThread object is invalid");
1218         return sb_error;
1219     }
1220
1221     Thread *thread = exe_ctx.GetThreadPtr();
1222
1223     Error err = thread->JumpToLine (file_spec.get(), line, true);
1224     sb_error.SetError (err);
1225     return sb_error;
1226 }
1227
1228 SBError
1229 SBThread::ReturnFromFrame (SBFrame &frame, SBValue &return_value)
1230 {
1231     SBError sb_error;
1232
1233     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1234
1235     std::unique_lock<std::recursive_mutex> lock;
1236     ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
1237
1238     if (log)
1239         log->Printf ("SBThread(%p)::ReturnFromFrame (frame=%d)",
1240                      static_cast<void*>(exe_ctx.GetThreadPtr()),
1241                      frame.GetFrameID());
1242
1243     if (exe_ctx.HasThreadScope())
1244     {
1245         Thread *thread = exe_ctx.GetThreadPtr();
1246         sb_error.SetError (thread->ReturnFromFrame(frame.GetFrameSP(), return_value.GetSP()));
1247     }
1248
1249     return sb_error;
1250 }
1251
1252 SBError
1253 SBThread::UnwindInnermostExpression()
1254 {
1255     SBError sb_error;
1256
1257     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1258
1259     std::unique_lock<std::recursive_mutex> lock;
1260     ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
1261
1262     if (log)
1263         log->Printf ("SBThread(%p)::UnwindExpressionEvaluation",
1264                      static_cast<void*>(exe_ctx.GetThreadPtr()));
1265
1266     if (exe_ctx.HasThreadScope())
1267     {
1268         Thread *thread = exe_ctx.GetThreadPtr();
1269         sb_error.SetError (thread->UnwindInnermostExpression());
1270         if (sb_error.Success())
1271             thread->SetSelectedFrameByIndex(0, false);
1272     }
1273
1274     return sb_error;
1275
1276 }
1277
1278 bool
1279 SBThread::Suspend()
1280 {
1281     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1282     std::unique_lock<std::recursive_mutex> lock;
1283     ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
1284
1285     bool result = false;
1286     if (exe_ctx.HasThreadScope())
1287     {
1288         Process::StopLocker stop_locker;
1289         if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
1290         {
1291             exe_ctx.GetThreadPtr()->SetResumeState (eStateSuspended);
1292             result = true;
1293         }
1294         else
1295         {
1296             if (log)
1297                 log->Printf ("SBThread(%p)::Suspend() => error: process is running",
1298                              static_cast<void*>(exe_ctx.GetThreadPtr()));
1299         }
1300     }
1301     if (log)
1302         log->Printf ("SBThread(%p)::Suspend() => %i",
1303                      static_cast<void*>(exe_ctx.GetThreadPtr()), result);
1304     return result;
1305 }
1306
1307 bool
1308 SBThread::Resume ()
1309 {
1310     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1311     std::unique_lock<std::recursive_mutex> lock;
1312     ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
1313
1314     bool result = false;
1315     if (exe_ctx.HasThreadScope())
1316     {
1317         Process::StopLocker stop_locker;
1318         if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
1319         {
1320             const bool override_suspend = true;
1321             exe_ctx.GetThreadPtr()->SetResumeState (eStateRunning, override_suspend);
1322             result = true;
1323         }
1324         else
1325         {
1326             if (log)
1327                 log->Printf ("SBThread(%p)::Resume() => error: process is running",
1328                              static_cast<void*>(exe_ctx.GetThreadPtr()));
1329         }
1330     }
1331     if (log)
1332         log->Printf ("SBThread(%p)::Resume() => %i",
1333                      static_cast<void*>(exe_ctx.GetThreadPtr()), result);
1334     return result;
1335 }
1336
1337 bool
1338 SBThread::IsSuspended()
1339 {
1340     std::unique_lock<std::recursive_mutex> lock;
1341     ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
1342
1343     if (exe_ctx.HasThreadScope())
1344         return exe_ctx.GetThreadPtr()->GetResumeState () == eStateSuspended;
1345     return false;
1346 }
1347
1348 bool
1349 SBThread::IsStopped()
1350 {
1351     std::unique_lock<std::recursive_mutex> lock;
1352     ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
1353
1354     if (exe_ctx.HasThreadScope())
1355         return StateIsStoppedState(exe_ctx.GetThreadPtr()->GetState(), true);
1356     return false;
1357 }
1358
1359 SBProcess
1360 SBThread::GetProcess ()
1361 {
1362     SBProcess sb_process;
1363     std::unique_lock<std::recursive_mutex> lock;
1364     ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
1365
1366     if (exe_ctx.HasThreadScope())
1367     {
1368         // Have to go up to the target so we can get a shared pointer to our process...
1369         sb_process.SetSP (exe_ctx.GetProcessSP());
1370     }
1371
1372     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1373     if (log)
1374     {
1375         SBStream frame_desc_strm;
1376         sb_process.GetDescription (frame_desc_strm);
1377         log->Printf ("SBThread(%p)::GetProcess () => SBProcess(%p): %s",
1378                      static_cast<void*>(exe_ctx.GetThreadPtr()),
1379                      static_cast<void*>(sb_process.GetSP().get()),
1380                      frame_desc_strm.GetData());
1381     }
1382
1383     return sb_process;
1384 }
1385
1386 uint32_t
1387 SBThread::GetNumFrames ()
1388 {
1389     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1390
1391     uint32_t num_frames = 0;
1392     std::unique_lock<std::recursive_mutex> lock;
1393     ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
1394
1395     if (exe_ctx.HasThreadScope())
1396     {
1397         Process::StopLocker stop_locker;
1398         if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
1399         {
1400             num_frames = exe_ctx.GetThreadPtr()->GetStackFrameCount();
1401         }
1402         else
1403         {
1404             if (log)
1405                 log->Printf ("SBThread(%p)::GetNumFrames() => error: process is running",
1406                              static_cast<void*>(exe_ctx.GetThreadPtr()));
1407         }
1408     }
1409
1410     if (log)
1411         log->Printf ("SBThread(%p)::GetNumFrames () => %u",
1412                      static_cast<void*>(exe_ctx.GetThreadPtr()), num_frames);
1413
1414     return num_frames;
1415 }
1416
1417 SBFrame
1418 SBThread::GetFrameAtIndex (uint32_t idx)
1419 {
1420     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1421
1422     SBFrame sb_frame;
1423     StackFrameSP frame_sp;
1424     std::unique_lock<std::recursive_mutex> lock;
1425     ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
1426
1427     if (exe_ctx.HasThreadScope())
1428     {
1429         Process::StopLocker stop_locker;
1430         if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
1431         {
1432             frame_sp = exe_ctx.GetThreadPtr()->GetStackFrameAtIndex (idx);
1433             sb_frame.SetFrameSP (frame_sp);
1434         }
1435         else
1436         {
1437             if (log)
1438                 log->Printf ("SBThread(%p)::GetFrameAtIndex() => error: process is running",
1439                              static_cast<void*>(exe_ctx.GetThreadPtr()));
1440         }
1441     }
1442
1443     if (log)
1444     {
1445         SBStream frame_desc_strm;
1446         sb_frame.GetDescription (frame_desc_strm);
1447         log->Printf ("SBThread(%p)::GetFrameAtIndex (idx=%d) => SBFrame(%p): %s",
1448                      static_cast<void*>(exe_ctx.GetThreadPtr()), idx,
1449                      static_cast<void*>(frame_sp.get()),
1450                      frame_desc_strm.GetData());
1451     }
1452
1453     return sb_frame;
1454 }
1455
1456 lldb::SBFrame
1457 SBThread::GetSelectedFrame ()
1458 {
1459     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1460
1461     SBFrame sb_frame;
1462     StackFrameSP frame_sp;
1463     std::unique_lock<std::recursive_mutex> lock;
1464     ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
1465
1466     if (exe_ctx.HasThreadScope())
1467     {
1468         Process::StopLocker stop_locker;
1469         if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
1470         {
1471             frame_sp = exe_ctx.GetThreadPtr()->GetSelectedFrame ();
1472             sb_frame.SetFrameSP (frame_sp);
1473         }
1474         else
1475         {
1476             if (log)
1477                 log->Printf ("SBThread(%p)::GetSelectedFrame() => error: process is running",
1478                              static_cast<void*>(exe_ctx.GetThreadPtr()));
1479         }
1480     }
1481
1482     if (log)
1483     {
1484         SBStream frame_desc_strm;
1485         sb_frame.GetDescription (frame_desc_strm);
1486         log->Printf ("SBThread(%p)::GetSelectedFrame () => SBFrame(%p): %s",
1487                      static_cast<void*>(exe_ctx.GetThreadPtr()),
1488                      static_cast<void*>(frame_sp.get()),
1489                      frame_desc_strm.GetData());
1490     }
1491
1492     return sb_frame;
1493 }
1494
1495 lldb::SBFrame
1496 SBThread::SetSelectedFrame (uint32_t idx)
1497 {
1498     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1499
1500     SBFrame sb_frame;
1501     StackFrameSP frame_sp;
1502     std::unique_lock<std::recursive_mutex> lock;
1503     ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
1504
1505     if (exe_ctx.HasThreadScope())
1506     {
1507         Process::StopLocker stop_locker;
1508         if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
1509         {
1510             Thread *thread = exe_ctx.GetThreadPtr();
1511             frame_sp = thread->GetStackFrameAtIndex (idx);
1512             if (frame_sp)
1513             {
1514                 thread->SetSelectedFrame (frame_sp.get());
1515                 sb_frame.SetFrameSP (frame_sp);
1516             }
1517         }
1518         else
1519         {
1520             if (log)
1521                 log->Printf ("SBThread(%p)::SetSelectedFrame() => error: process is running",
1522                              static_cast<void*>(exe_ctx.GetThreadPtr()));
1523         }
1524     }
1525
1526     if (log)
1527     {
1528         SBStream frame_desc_strm;
1529         sb_frame.GetDescription (frame_desc_strm);
1530         log->Printf ("SBThread(%p)::SetSelectedFrame (idx=%u) => SBFrame(%p): %s",
1531                      static_cast<void*>(exe_ctx.GetThreadPtr()), idx,
1532                      static_cast<void*>(frame_sp.get()),
1533                      frame_desc_strm.GetData());
1534     }
1535     return sb_frame;
1536 }
1537
1538 bool
1539 SBThread::EventIsThreadEvent (const SBEvent &event)
1540 {
1541     return Thread::ThreadEventData::GetEventDataFromEvent(event.get()) != NULL;
1542 }
1543
1544 SBFrame
1545 SBThread::GetStackFrameFromEvent (const SBEvent &event)
1546 {
1547     return Thread::ThreadEventData::GetStackFrameFromEvent (event.get());
1548
1549 }
1550
1551 SBThread
1552 SBThread::GetThreadFromEvent (const SBEvent &event)
1553 {
1554     return Thread::ThreadEventData::GetThreadFromEvent (event.get());
1555 }
1556
1557 bool
1558 SBThread::operator == (const SBThread &rhs) const
1559 {
1560     return m_opaque_sp->GetThreadSP().get() == rhs.m_opaque_sp->GetThreadSP().get();
1561 }
1562
1563 bool
1564 SBThread::operator != (const SBThread &rhs) const
1565 {
1566     return m_opaque_sp->GetThreadSP().get() != rhs.m_opaque_sp->GetThreadSP().get();
1567 }
1568
1569 bool
1570 SBThread::GetStatus (SBStream &status) const
1571 {
1572     Stream &strm = status.ref();
1573
1574     std::unique_lock<std::recursive_mutex> lock;
1575     ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
1576
1577     if (exe_ctx.HasThreadScope())
1578     {
1579         exe_ctx.GetThreadPtr()->GetStatus(strm, 0, 1, 1);
1580     }
1581     else
1582         strm.PutCString ("No status");
1583     
1584     return true;
1585 }
1586
1587 bool
1588 SBThread::GetDescription (SBStream &description) const
1589 {
1590     Stream &strm = description.ref();
1591
1592     std::unique_lock<std::recursive_mutex> lock;
1593     ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
1594
1595     if (exe_ctx.HasThreadScope())
1596     {
1597         exe_ctx.GetThreadPtr()->DumpUsingSettingsFormat(strm, LLDB_INVALID_THREAD_ID);
1598         //strm.Printf("SBThread: tid = 0x%4.4" PRIx64, exe_ctx.GetThreadPtr()->GetID());
1599     }
1600     else
1601         strm.PutCString ("No value");
1602     
1603     return true;
1604 }
1605
1606 SBThread
1607 SBThread::GetExtendedBacktraceThread (const char *type)
1608 {
1609     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1610     std::unique_lock<std::recursive_mutex> lock;
1611     ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
1612     SBThread sb_origin_thread;
1613
1614     if (exe_ctx.HasThreadScope())
1615     {
1616         Process::StopLocker stop_locker;
1617         if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
1618         {
1619             ThreadSP real_thread(exe_ctx.GetThreadSP());
1620             if (real_thread)
1621             {
1622                 ConstString type_const (type);
1623                 Process *process = exe_ctx.GetProcessPtr();
1624                 if (process)
1625                 {
1626                     SystemRuntime *runtime = process->GetSystemRuntime();
1627                     if (runtime)
1628                     {
1629                         ThreadSP new_thread_sp (runtime->GetExtendedBacktraceThread (real_thread, type_const));
1630                         if (new_thread_sp)
1631                         {
1632                             // Save this in the Process' ExtendedThreadList so a strong pointer retains the
1633                             // object.
1634                             process->GetExtendedThreadList().AddThread (new_thread_sp);
1635                             sb_origin_thread.SetThread (new_thread_sp);
1636                             if (log)
1637                             {
1638                                 const char *queue_name = new_thread_sp->GetQueueName();
1639                                 if (queue_name == NULL)
1640                                     queue_name = "";
1641                                 log->Printf ("SBThread(%p)::GetExtendedBacktraceThread() => new extended Thread "
1642                                              "created (%p) with queue_id 0x%" PRIx64 " queue name '%s'",
1643                                              static_cast<void*>(exe_ctx.GetThreadPtr()),
1644                                              static_cast<void*>(new_thread_sp.get()),
1645                                              new_thread_sp->GetQueueID(),
1646                                              queue_name);
1647                             }
1648                         }
1649                     }
1650                 }
1651             }
1652         }
1653         else
1654         {
1655             if (log)
1656                 log->Printf ("SBThread(%p)::GetExtendedBacktraceThread() => error: process is running",
1657                              static_cast<void*>(exe_ctx.GetThreadPtr()));
1658         }
1659     }
1660
1661     if (log && sb_origin_thread.IsValid() == false)
1662         log->Printf("SBThread(%p)::GetExtendedBacktraceThread() is not returning a Valid thread",
1663                     static_cast<void*>(exe_ctx.GetThreadPtr()));
1664     return sb_origin_thread;
1665 }
1666
1667 uint32_t
1668 SBThread::GetExtendedBacktraceOriginatingIndexID ()
1669 {
1670     ThreadSP thread_sp(m_opaque_sp->GetThreadSP());
1671     if (thread_sp)
1672         return thread_sp->GetExtendedBacktraceOriginatingIndexID();
1673     return LLDB_INVALID_INDEX32;
1674 }
1675
1676 bool
1677 SBThread::SafeToCallFunctions ()
1678 {
1679     ThreadSP thread_sp(m_opaque_sp->GetThreadSP());
1680     if (thread_sp)
1681         return thread_sp->SafeToCallFunctions();
1682     return true;
1683 }
1684
1685 lldb_private::Thread *
1686 SBThread::operator->()
1687 {
1688     ThreadSP thread_sp(m_opaque_sp->GetThreadSP());
1689     if (thread_sp)
1690         return thread_sp.get();
1691     else
1692         return NULL;
1693 }
1694
1695 lldb_private::Thread *
1696 SBThread::get()
1697 {
1698     ThreadSP thread_sp(m_opaque_sp->GetThreadSP());
1699     if (thread_sp)
1700         return thread_sp.get();
1701     else
1702         return NULL;
1703 }
1704