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