blob: 1fc0fdc5075ea9dc68977e9f0cf90af0c9bad1bb [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001//===-- 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
Eli Friedman4c5de692010-06-09 07:44:37 +000010#include "lldb/API/SBThread.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000011
12#include "lldb/API/SBSymbolContext.h"
13#include "lldb/API/SBFileSpec.h"
Caroline Ticedde9cff2010-09-20 05:20:02 +000014#include "lldb/API/SBStream.h"
Greg Clayton4e78f602010-11-18 18:52:36 +000015#include "lldb/Breakpoint/BreakpointLocation.h"
Greg Clayton66111032010-06-23 01:19:29 +000016#include "lldb/Core/Debugger.h"
Andrew Kaylora75418d2013-04-15 23:33:53 +000017#include "lldb/Core/State.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000018#include "lldb/Core/Stream.h"
19#include "lldb/Core/StreamFile.h"
Jason Molenda705b1802014-06-13 02:37:02 +000020#include "lldb/Core/StructuredData.h"
Zachary Turnera78bd7f2015-03-03 23:11:11 +000021#include "lldb/Core/ValueObject.h"
Greg Clayton66111032010-06-23 01:19:29 +000022#include "lldb/Interpreter/CommandInterpreter.h"
Zachary Turner93749ab2015-03-03 21:51:25 +000023#include "lldb/Symbol/SymbolContext.h"
24#include "lldb/Symbol/CompileUnit.h"
Jason Molenda5dd49162013-11-06 00:04:44 +000025#include "lldb/Target/SystemRuntime.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000026#include "lldb/Target/Thread.h"
27#include "lldb/Target/Process.h"
Jason Molendab9ffa982014-04-25 00:01:15 +000028#include "lldb/Target/Queue.h"
Zachary Turner93749ab2015-03-03 21:51:25 +000029#include "lldb/Target/UnixSignals.h"
Greg Claytonf4b47e12010-08-04 01:40:35 +000030#include "lldb/Target/StopInfo.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000031#include "lldb/Target/Target.h"
32#include "lldb/Target/ThreadPlan.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000033#include "lldb/Target/ThreadPlanStepInstruction.h"
34#include "lldb/Target/ThreadPlanStepOut.h"
35#include "lldb/Target/ThreadPlanStepRange.h"
36#include "lldb/Target/ThreadPlanStepInRange.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000037
Eli Friedman4c5de692010-06-09 07:44:37 +000038#include "lldb/API/SBAddress.h"
Eli Friedman4c5de692010-06-09 07:44:37 +000039#include "lldb/API/SBDebugger.h"
Jim Ingham4f465cf2012-10-10 18:32:14 +000040#include "lldb/API/SBEvent.h"
Jim Ingham73ca05a2011-12-17 01:35:57 +000041#include "lldb/API/SBFrame.h"
Eli Friedman4c5de692010-06-09 07:44:37 +000042#include "lldb/API/SBProcess.h"
Kuba Brecka6a831432016-03-23 15:36:22 +000043#include "lldb/API/SBThreadCollection.h"
Jim Ingham2bdbfd52014-09-29 23:17:18 +000044#include "lldb/API/SBThreadPlan.h"
Jim Ingham73ca05a2011-12-17 01:35:57 +000045#include "lldb/API/SBValue.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000046
47using namespace lldb;
48using namespace lldb_private;
49
Jim Ingham4f465cf2012-10-10 18:32:14 +000050const char *
51SBThread::GetBroadcasterClassName ()
52{
53 return Thread::GetStaticBroadcasterClass().AsCString();
54}
55
Greg Claytoncfd1ace2010-10-31 03:01:06 +000056//----------------------------------------------------------------------
57// Constructors
58//----------------------------------------------------------------------
Chris Lattner30fdc8d2010-06-08 16:52:24 +000059SBThread::SBThread () :
Greg Clayton7fdf9ef2012-04-05 16:12:35 +000060 m_opaque_sp (new ExecutionContextRef())
Chris Lattner30fdc8d2010-06-08 16:52:24 +000061{
62}
63
Chris Lattner30fdc8d2010-06-08 16:52:24 +000064SBThread::SBThread (const ThreadSP& lldb_object_sp) :
Greg Clayton7fdf9ef2012-04-05 16:12:35 +000065 m_opaque_sp (new ExecutionContextRef(lldb_object_sp))
Chris Lattner30fdc8d2010-06-08 16:52:24 +000066{
67}
68
Greg Clayton92ef5732010-10-30 18:26:59 +000069SBThread::SBThread (const SBThread &rhs) :
Greg Clayton7fdf9ef2012-04-05 16:12:35 +000070 m_opaque_sp (new ExecutionContextRef(*rhs.m_opaque_sp))
Chris Lattner30fdc8d2010-06-08 16:52:24 +000071{
Greg Clayton7fdf9ef2012-04-05 16:12:35 +000072
Chris Lattner30fdc8d2010-06-08 16:52:24 +000073}
74
75//----------------------------------------------------------------------
Greg Claytoncfd1ace2010-10-31 03:01:06 +000076// Assignment operator
77//----------------------------------------------------------------------
78
79const lldb::SBThread &
80SBThread::operator = (const SBThread &rhs)
81{
82 if (this != &rhs)
Greg Clayton7fdf9ef2012-04-05 16:12:35 +000083 *m_opaque_sp = *rhs.m_opaque_sp;
Greg Claytoncfd1ace2010-10-31 03:01:06 +000084 return *this;
85}
86
87//----------------------------------------------------------------------
Chris Lattner30fdc8d2010-06-08 16:52:24 +000088// Destructor
89//----------------------------------------------------------------------
90SBThread::~SBThread()
91{
92}
93
Jason Molendab9ffa982014-04-25 00:01:15 +000094lldb::SBQueue
95SBThread::GetQueue () const
96{
97 SBQueue sb_queue;
98 QueueSP queue_sp;
99 Mutex::Locker api_locker;
100 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
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)
Greg Clayton358cf1e2015-06-25 21:46:34 +0000117 log->Printf ("SBThread(%p)::GetQueue() => error: process is running",
Jason Molendab9ffa982014-04-25 00:01:15 +0000118 static_cast<void*>(exe_ctx.GetThreadPtr()));
119 }
120 }
121
122 if (log)
Greg Clayton358cf1e2015-06-25 21:46:34 +0000123 log->Printf ("SBThread(%p)::GetQueue () => SBQueue(%p)",
Jason Molendab9ffa982014-04-25 00:01:15 +0000124 static_cast<void*>(exe_ctx.GetThreadPtr()), static_cast<void*>(queue_sp.get()));
125
126 return sb_queue;
127}
128
129
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000130bool
131SBThread::IsValid() const
132{
Jim Ingham7fa7dc32016-05-07 00:54:56 +0000133 Mutex::Locker api_locker;
134 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
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;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000146}
147
Greg Clayton48e42542010-07-30 20:12:55 +0000148void
149SBThread::Clear ()
150{
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000151 m_opaque_sp->Clear();
Greg Clayton48e42542010-07-30 20:12:55 +0000152}
153
154
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000155StopReason
156SBThread::GetStopReason()
157{
Greg Clayton5160ce52013-03-27 23:08:40 +0000158 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000159
Caroline Ticeceb6b132010-10-26 03:11:13 +0000160 StopReason reason = eStopReasonInvalid;
Jim Ingham4fc6cb92012-08-22 21:34:33 +0000161 Mutex::Locker api_locker;
162 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
163
Greg Clayton1ac04c32012-02-21 00:09:25 +0000164 if (exe_ctx.HasThreadScope())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000165 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000166 Process::StopLocker stop_locker;
167 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
168 {
Greg Clayton97d5cf02012-09-25 02:40:06 +0000169 return exe_ctx.GetThreadPtr()->GetStopReason();
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000170 }
Greg Claytonc9858e42012-04-06 02:17:47 +0000171 else
172 {
173 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000174 log->Printf ("SBThread(%p)::GetStopReason() => error: process is running",
175 static_cast<void*>(exe_ctx.GetThreadPtr()));
Greg Claytonc9858e42012-04-06 02:17:47 +0000176 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000177 }
Caroline Ticeceb6b132010-10-26 03:11:13 +0000178
179 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000180 log->Printf ("SBThread(%p)::GetStopReason () => %s",
181 static_cast<void*>(exe_ctx.GetThreadPtr()),
Caroline Tice750cd172010-10-26 23:49:36 +0000182 Thread::StopReasonAsCString (reason));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000183
184 return reason;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000185}
186
187size_t
Greg Clayton4e78f602010-11-18 18:52:36 +0000188SBThread::GetStopReasonDataCount ()
189{
Jim Ingham4fc6cb92012-08-22 21:34:33 +0000190 Mutex::Locker api_locker;
191 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
192
Greg Clayton1ac04c32012-02-21 00:09:25 +0000193 if (exe_ctx.HasThreadScope())
Greg Clayton4e78f602010-11-18 18:52:36 +0000194 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000195 Process::StopLocker stop_locker;
196 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
Greg Clayton4e78f602010-11-18 18:52:36 +0000197 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000198 StopInfoSP stop_info_sp = exe_ctx.GetThreadPtr()->GetStopInfo ();
199 if (stop_info_sp)
Greg Clayton4e78f602010-11-18 18:52:36 +0000200 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000201 StopReason reason = stop_info_sp->GetStopReason();
202 switch (reason)
Greg Clayton4e78f602010-11-18 18:52:36 +0000203 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000204 case eStopReasonInvalid:
205 case eStopReasonNone:
206 case eStopReasonTrace:
Greg Clayton90ba8112012-12-05 00:16:59 +0000207 case eStopReasonExec:
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000208 case eStopReasonPlanComplete:
Andrew Kaylorf85defa2012-12-20 23:08:03 +0000209 case eStopReasonThreadExiting:
Kuba Breckaafdf8422014-10-10 23:43:03 +0000210 case eStopReasonInstrumentation:
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000211 // 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;
Greg Clayton4e78f602010-11-18 18:52:36 +0000233 }
Greg Clayton4e78f602010-11-18 18:52:36 +0000234 }
235 }
Greg Claytonc9858e42012-04-06 02:17:47 +0000236 else
237 {
Greg Clayton5160ce52013-03-27 23:08:40 +0000238 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytonc9858e42012-04-06 02:17:47 +0000239 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000240 log->Printf ("SBThread(%p)::GetStopReasonDataCount() => error: process is running",
241 static_cast<void*>(exe_ctx.GetThreadPtr()));
Greg Claytonc9858e42012-04-06 02:17:47 +0000242 }
Greg Clayton4e78f602010-11-18 18:52:36 +0000243 }
244 return 0;
245}
246
247uint64_t
248SBThread::GetStopReasonDataAtIndex (uint32_t idx)
249{
Jim Ingham4fc6cb92012-08-22 21:34:33 +0000250 Mutex::Locker api_locker;
251 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
252
Greg Clayton1ac04c32012-02-21 00:09:25 +0000253 if (exe_ctx.HasThreadScope())
Greg Clayton4e78f602010-11-18 18:52:36 +0000254 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000255 Process::StopLocker stop_locker;
256 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
Greg Clayton4e78f602010-11-18 18:52:36 +0000257 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000258 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)
Greg Clayton4e78f602010-11-18 18:52:36 +0000264 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000265 case eStopReasonInvalid:
266 case eStopReasonNone:
267 case eStopReasonTrace:
Greg Clayton90ba8112012-12-05 00:16:59 +0000268 case eStopReasonExec:
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000269 case eStopReasonPlanComplete:
Andrew Kaylorf85defa2012-12-20 23:08:03 +0000270 case eStopReasonThreadExiting:
Kuba Breckaafdf8422014-10-10 23:43:03 +0000271 case eStopReasonInstrumentation:
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000272 // There is no data for these stop reasons.
273 return 0;
274
275 case eStopReasonBreakpoint:
Greg Clayton4e78f602010-11-18 18:52:36 +0000276 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000277 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)
Greg Clayton4e78f602010-11-18 18:52:36 +0000280 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000281 uint32_t bp_index = idx / 2;
282 BreakpointLocationSP bp_loc_sp (bp_site_sp->GetOwnerAtIndex (bp_index));
283 if (bp_loc_sp)
Greg Clayton4e78f602010-11-18 18:52:36 +0000284 {
Greg Clayton8334e142014-04-11 17:27:02 +0000285 if (idx & 1)
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000286 {
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 }
Greg Clayton4e78f602010-11-18 18:52:36 +0000295 }
296 }
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000297 return LLDB_INVALID_BREAK_ID;
Greg Clayton4e78f602010-11-18 18:52:36 +0000298 }
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000299 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();
Greg Clayton4e78f602010-11-18 18:52:36 +0000309 }
Greg Clayton4e78f602010-11-18 18:52:36 +0000310 }
311 }
Greg Claytonc9858e42012-04-06 02:17:47 +0000312 else
313 {
Greg Clayton5160ce52013-03-27 23:08:40 +0000314 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytonc9858e42012-04-06 02:17:47 +0000315 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000316 log->Printf ("SBThread(%p)::GetStopReasonDataAtIndex() => error: process is running",
317 static_cast<void*>(exe_ctx.GetThreadPtr()));
Greg Claytonc9858e42012-04-06 02:17:47 +0000318 }
Greg Clayton4e78f602010-11-18 18:52:36 +0000319 }
320 return 0;
321}
322
Kuba Breckaafdf8422014-10-10 23:43:03 +0000323bool
324SBThread::GetStopReasonExtendedInfoAsJSON (lldb::SBStream &stream)
325{
326 Stream &strm = stream.ref();
327
328 ExecutionContext exe_ctx (m_opaque_sp.get());
329 if (! exe_ctx.HasThreadScope())
330 return false;
331
332
333 StopInfoSP stop_info = exe_ctx.GetThreadPtr()->GetStopInfo();
334 StructuredData::ObjectSP info = stop_info->GetExtendedInfo();
335 if (! info)
336 return false;
337
338 info->Dump(strm);
339
340 return true;
341}
342
Kuba Brecka6a831432016-03-23 15:36:22 +0000343SBThreadCollection
344SBThread::GetStopReasonExtendedBacktraces (InstrumentationRuntimeType type)
345{
346 ThreadCollectionSP threads;
347 threads.reset(new ThreadCollection());
348
349 // We currently only support ThreadSanitizer.
350 if (type != eInstrumentationRuntimeTypeThreadSanitizer)
351 return threads;
Kuba Brecka1aad8fb2016-04-10 18:57:38 +0000352
Kuba Brecka6a831432016-03-23 15:36:22 +0000353 ExecutionContext exe_ctx (m_opaque_sp.get());
354 if (! exe_ctx.HasThreadScope())
Kuba Brecka1aad8fb2016-04-10 18:57:38 +0000355 return threads;
Kuba Brecka6a831432016-03-23 15:36:22 +0000356
357 ProcessSP process_sp = exe_ctx.GetProcessSP();
358
359 StopInfoSP stop_info = exe_ctx.GetThreadPtr()->GetStopInfo();
360 StructuredData::ObjectSP info = stop_info->GetExtendedInfo();
361 if (! info)
362 return threads;
363
Kuba Brecka1aad8fb2016-04-10 18:57:38 +0000364 return process_sp->GetInstrumentationRuntime(type)->GetBacktracesFromExtendedStopInfo(info);
Kuba Brecka6a831432016-03-23 15:36:22 +0000365}
366
Greg Clayton4e78f602010-11-18 18:52:36 +0000367size_t
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000368SBThread::GetStopDescription (char *dst, size_t dst_len)
369{
Greg Clayton5160ce52013-03-27 23:08:40 +0000370 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000371
Jim Ingham4fc6cb92012-08-22 21:34:33 +0000372 Mutex::Locker api_locker;
373 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
374
Greg Clayton1ac04c32012-02-21 00:09:25 +0000375 if (exe_ctx.HasThreadScope())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000376 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000377 Process::StopLocker stop_locker;
378 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000379 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000380
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000381 StopInfoSP stop_info_sp = exe_ctx.GetThreadPtr()->GetStopInfo ();
382 if (stop_info_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000383 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000384 const char *stop_desc = stop_info_sp->GetDescription();
385 if (stop_desc)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000386 {
Caroline Ticeceb6b132010-10-26 03:11:13 +0000387 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000388 log->Printf ("SBThread(%p)::GetStopDescription (dst, dst_len) => \"%s\"",
389 static_cast<void*>(exe_ctx.GetThreadPtr()),
390 stop_desc);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000391 if (dst)
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000392 return ::snprintf (dst, dst_len, "%s", stop_desc);
393 else
394 {
395 // NULL dst passed in, return the length needed to contain the description
396 return ::strlen (stop_desc) + 1; // Include the NULL byte for size
397 }
398 }
399 else
400 {
401 size_t stop_desc_len = 0;
402 switch (stop_info_sp->GetStopReason())
403 {
404 case eStopReasonTrace:
405 case eStopReasonPlanComplete:
406 {
407 static char trace_desc[] = "step";
408 stop_desc = trace_desc;
409 stop_desc_len = sizeof(trace_desc); // Include the NULL byte for size
410 }
411 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000412
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000413 case eStopReasonBreakpoint:
414 {
415 static char bp_desc[] = "breakpoint hit";
416 stop_desc = bp_desc;
417 stop_desc_len = sizeof(bp_desc); // Include the NULL byte for size
418 }
419 break;
420
421 case eStopReasonWatchpoint:
422 {
423 static char wp_desc[] = "watchpoint hit";
424 stop_desc = wp_desc;
425 stop_desc_len = sizeof(wp_desc); // Include the NULL byte for size
426 }
427 break;
428
429 case eStopReasonSignal:
430 {
Chaoren Lin98d0a4b2015-07-14 01:09:28 +0000431 stop_desc = exe_ctx.GetProcessPtr()->GetUnixSignals()->GetSignalAsCString(stop_info_sp->GetValue());
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000432 if (stop_desc == NULL || stop_desc[0] == '\0')
433 {
434 static char signal_desc[] = "signal";
435 stop_desc = signal_desc;
436 stop_desc_len = sizeof(signal_desc); // Include the NULL byte for size
437 }
438 }
439 break;
440
441 case eStopReasonException:
442 {
443 char exc_desc[] = "exception";
444 stop_desc = exc_desc;
445 stop_desc_len = sizeof(exc_desc); // Include the NULL byte for size
446 }
447 break;
448
Greg Clayton90ba8112012-12-05 00:16:59 +0000449 case eStopReasonExec:
450 {
451 char exc_desc[] = "exec";
452 stop_desc = exc_desc;
453 stop_desc_len = sizeof(exc_desc); // Include the NULL byte for size
454 }
455 break;
456
Andrew Kaylorf85defa2012-12-20 23:08:03 +0000457 case eStopReasonThreadExiting:
458 {
459 char limbo_desc[] = "thread exiting";
460 stop_desc = limbo_desc;
461 stop_desc_len = sizeof(limbo_desc);
462 }
463 break;
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000464 default:
465 break;
466 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000467
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000468 if (stop_desc && stop_desc[0])
469 {
470 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000471 log->Printf ("SBThread(%p)::GetStopDescription (dst, dst_len) => '%s'",
472 static_cast<void*>(exe_ctx.GetThreadPtr()),
473 stop_desc);
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000474
475 if (dst)
476 return ::snprintf (dst, dst_len, "%s", stop_desc) + 1; // Include the NULL byte
477
478 if (stop_desc_len == 0)
479 stop_desc_len = ::strlen (stop_desc) + 1; // Include the NULL byte
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000480
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000481 return stop_desc_len;
482 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000483 }
484 }
485 }
Greg Claytonc9858e42012-04-06 02:17:47 +0000486 else
487 {
Greg Clayton5160ce52013-03-27 23:08:40 +0000488 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytonc9858e42012-04-06 02:17:47 +0000489 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000490 log->Printf ("SBThread(%p)::GetStopDescription() => error: process is running",
491 static_cast<void*>(exe_ctx.GetThreadPtr()));
Greg Claytonc9858e42012-04-06 02:17:47 +0000492 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000493 }
494 if (dst)
495 *dst = 0;
496 return 0;
497}
498
Jim Ingham73ca05a2011-12-17 01:35:57 +0000499SBValue
500SBThread::GetStopReturnValue ()
501{
Greg Clayton5160ce52013-03-27 23:08:40 +0000502 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Jim Ingham73ca05a2011-12-17 01:35:57 +0000503 ValueObjectSP return_valobj_sp;
Jim Ingham4fc6cb92012-08-22 21:34:33 +0000504 Mutex::Locker api_locker;
505 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
506
Greg Clayton1ac04c32012-02-21 00:09:25 +0000507 if (exe_ctx.HasThreadScope())
Jim Ingham73ca05a2011-12-17 01:35:57 +0000508 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000509 Process::StopLocker stop_locker;
510 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
Jim Ingham73ca05a2011-12-17 01:35:57 +0000511 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000512 StopInfoSP stop_info_sp = exe_ctx.GetThreadPtr()->GetStopInfo ();
513 if (stop_info_sp)
514 {
515 return_valobj_sp = StopInfo::GetReturnValueObject (stop_info_sp);
516 }
Jim Ingham73ca05a2011-12-17 01:35:57 +0000517 }
Greg Claytonc9858e42012-04-06 02:17:47 +0000518 else
519 {
520 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000521 log->Printf ("SBThread(%p)::GetStopReturnValue() => error: process is running",
522 static_cast<void*>(exe_ctx.GetThreadPtr()));
Greg Claytonc9858e42012-04-06 02:17:47 +0000523 }
Jim Ingham73ca05a2011-12-17 01:35:57 +0000524 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000525
Jim Ingham73ca05a2011-12-17 01:35:57 +0000526 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000527 log->Printf ("SBThread(%p)::GetStopReturnValue () => %s",
528 static_cast<void*>(exe_ctx.GetThreadPtr()),
529 return_valobj_sp.get()
530 ? return_valobj_sp->GetValueAsCString()
531 : "<no return value>");
532
Jim Ingham73ca05a2011-12-17 01:35:57 +0000533 return SBValue (return_valobj_sp);
534}
535
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000536void
537SBThread::SetThread (const ThreadSP& lldb_object_sp)
538{
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000539 m_opaque_sp->SetThreadSP (lldb_object_sp);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000540}
541
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000542lldb::tid_t
543SBThread::GetThreadID () const
544{
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000545 ThreadSP thread_sp(m_opaque_sp->GetThreadSP());
Greg Clayton17a6ad02012-01-30 02:53:15 +0000546 if (thread_sp)
Greg Clayton1ac04c32012-02-21 00:09:25 +0000547 return thread_sp->GetID();
548 return LLDB_INVALID_THREAD_ID;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000549}
550
551uint32_t
552SBThread::GetIndexID () const
553{
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000554 ThreadSP thread_sp(m_opaque_sp->GetThreadSP());
Greg Clayton17a6ad02012-01-30 02:53:15 +0000555 if (thread_sp)
556 return thread_sp->GetIndexID();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000557 return LLDB_INVALID_INDEX32;
558}
Greg Clayton1ac04c32012-02-21 00:09:25 +0000559
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000560const char *
561SBThread::GetName () const
562{
Greg Clayton5160ce52013-03-27 23:08:40 +0000563 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton48381312010-10-30 04:51:46 +0000564 const char *name = NULL;
Jim Ingham4fc6cb92012-08-22 21:34:33 +0000565 Mutex::Locker api_locker;
566 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
567
Greg Clayton1ac04c32012-02-21 00:09:25 +0000568 if (exe_ctx.HasThreadScope())
Greg Claytonaf67cec2010-12-20 20:49:23 +0000569 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000570 Process::StopLocker stop_locker;
571 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
572 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000573 name = exe_ctx.GetThreadPtr()->GetName();
574 }
Greg Claytonc9858e42012-04-06 02:17:47 +0000575 else
576 {
577 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000578 log->Printf ("SBThread(%p)::GetName() => error: process is running",
579 static_cast<void*>(exe_ctx.GetThreadPtr()));
Greg Claytonc9858e42012-04-06 02:17:47 +0000580 }
Greg Claytonaf67cec2010-12-20 20:49:23 +0000581 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000582
Caroline Ticeceb6b132010-10-26 03:11:13 +0000583 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000584 log->Printf ("SBThread(%p)::GetName () => %s",
585 static_cast<void*>(exe_ctx.GetThreadPtr()),
586 name ? name : "NULL");
Caroline Ticeceb6b132010-10-26 03:11:13 +0000587
Greg Clayton48381312010-10-30 04:51:46 +0000588 return name;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000589}
590
591const char *
592SBThread::GetQueueName () const
593{
Greg Clayton48381312010-10-30 04:51:46 +0000594 const char *name = NULL;
Jim Ingham4fc6cb92012-08-22 21:34:33 +0000595 Mutex::Locker api_locker;
596 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
597
Greg Clayton5160ce52013-03-27 23:08:40 +0000598 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton1ac04c32012-02-21 00:09:25 +0000599 if (exe_ctx.HasThreadScope())
Greg Claytonaf67cec2010-12-20 20:49:23 +0000600 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000601 Process::StopLocker stop_locker;
602 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
603 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000604 name = exe_ctx.GetThreadPtr()->GetQueueName();
605 }
Greg Claytonc9858e42012-04-06 02:17:47 +0000606 else
607 {
608 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000609 log->Printf ("SBThread(%p)::GetQueueName() => error: process is running",
610 static_cast<void*>(exe_ctx.GetThreadPtr()));
Greg Claytonc9858e42012-04-06 02:17:47 +0000611 }
Greg Claytonaf67cec2010-12-20 20:49:23 +0000612 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000613
Caroline Ticeceb6b132010-10-26 03:11:13 +0000614 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000615 log->Printf ("SBThread(%p)::GetQueueName () => %s",
616 static_cast<void*>(exe_ctx.GetThreadPtr()),
617 name ? name : "NULL");
Caroline Ticeceb6b132010-10-26 03:11:13 +0000618
Greg Clayton48381312010-10-30 04:51:46 +0000619 return name;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000620}
621
Jason Molenda4fdb5862013-10-21 23:52:54 +0000622lldb::queue_id_t
623SBThread::GetQueueID () const
624{
625 queue_id_t id = LLDB_INVALID_QUEUE_ID;
626 Mutex::Locker api_locker;
627 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
628
629 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
630 if (exe_ctx.HasThreadScope())
631 {
632 Process::StopLocker stop_locker;
633 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
634 {
635 id = exe_ctx.GetThreadPtr()->GetQueueID();
636 }
637 else
638 {
639 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000640 log->Printf ("SBThread(%p)::GetQueueID() => error: process is running",
641 static_cast<void*>(exe_ctx.GetThreadPtr()));
Jason Molenda4fdb5862013-10-21 23:52:54 +0000642 }
643 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000644
Jason Molenda4fdb5862013-10-21 23:52:54 +0000645 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000646 log->Printf ("SBThread(%p)::GetQueueID () => 0x%" PRIx64,
647 static_cast<void*>(exe_ctx.GetThreadPtr()), id);
Jason Molenda4fdb5862013-10-21 23:52:54 +0000648
649 return id;
650}
651
Jason Molenda705b1802014-06-13 02:37:02 +0000652bool
653SBThread::GetInfoItemByPathAsString (const char *path, SBStream &strm)
654{
655 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
656 bool success = false;
657 Mutex::Locker api_locker;
658 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
659
660 if (exe_ctx.HasThreadScope())
661 {
662 Process::StopLocker stop_locker;
663 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
664 {
665 Thread *thread = exe_ctx.GetThreadPtr();
666 StructuredData::ObjectSP info_root_sp = thread->GetExtendedInfo();
667 if (info_root_sp)
668 {
669 StructuredData::ObjectSP node = info_root_sp->GetObjectForDotSeparatedPath (path);
670 if (node)
671 {
672 if (node->GetType() == StructuredData::Type::eTypeString)
673 {
674 strm.Printf ("%s", node->GetAsString()->GetValue().c_str());
675 success = true;
676 }
677 if (node->GetType() == StructuredData::Type::eTypeInteger)
678 {
679 strm.Printf ("0x%" PRIx64, node->GetAsInteger()->GetValue());
680 success = true;
681 }
682 if (node->GetType() == StructuredData::Type::eTypeFloat)
683 {
684 strm.Printf ("0x%f", node->GetAsFloat()->GetValue());
685 success = true;
686 }
687 if (node->GetType() == StructuredData::Type::eTypeBoolean)
688 {
689 if (node->GetAsBoolean()->GetValue() == true)
690 strm.Printf ("true");
691 else
692 strm.Printf ("false");
693 success = true;
694 }
695 if (node->GetType() == StructuredData::Type::eTypeNull)
696 {
697 strm.Printf ("null");
698 success = true;
699 }
700 }
701 }
702 }
703 else
704 {
705 if (log)
706 log->Printf ("SBThread(%p)::GetInfoItemByPathAsString() => error: process is running",
707 static_cast<void*>(exe_ctx.GetThreadPtr()));
708 }
709 }
710
711 if (log)
712 log->Printf ("SBThread(%p)::GetInfoItemByPathAsString () => %s",
713 static_cast<void*>(exe_ctx.GetThreadPtr()),
714 strm.GetData());
715
716 return success;
717}
718
719
Jim Ingham64e7ead2012-05-03 21:19:36 +0000720SBError
721SBThread::ResumeNewPlan (ExecutionContext &exe_ctx, ThreadPlan *new_plan)
722{
723 SBError sb_error;
724
725 Process *process = exe_ctx.GetProcessPtr();
726 if (!process)
727 {
728 sb_error.SetErrorString("No process in SBThread::ResumeNewPlan");
729 return sb_error;
730 }
731
732 Thread *thread = exe_ctx.GetThreadPtr();
733 if (!thread)
734 {
735 sb_error.SetErrorString("No thread in SBThread::ResumeNewPlan");
736 return sb_error;
737 }
738
739 // User level plans should be Master Plans so they can be interrupted, other plans executed, and
740 // then a "continue" will resume the plan.
741 if (new_plan != NULL)
742 {
743 new_plan->SetIsMasterPlan(true);
744 new_plan->SetOkayToDiscard(false);
745 }
746
747 // Why do we need to set the current thread by ID here???
748 process->GetThreadList().SetSelectedThreadByID (thread->GetID());
Greg Claytondc6224e2014-10-21 01:00:42 +0000749
750 if (process->GetTarget().GetDebugger().GetAsyncExecution ())
751 sb_error.ref() = process->Resume ();
752 else
753 sb_error.ref() = process->ResumeSynchronous (NULL);
Jim Ingham64e7ead2012-05-03 21:19:36 +0000754
755 return sb_error;
756}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000757
758void
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000759SBThread::StepOver (lldb::RunMode stop_other_threads)
760{
Greg Clayton5160ce52013-03-27 23:08:40 +0000761 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000762
Jim Ingham4fc6cb92012-08-22 21:34:33 +0000763 Mutex::Locker api_locker;
764 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
765
Caroline Ticeceb6b132010-10-26 03:11:13 +0000766
Greg Clayton17a6ad02012-01-30 02:53:15 +0000767 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000768 log->Printf ("SBThread(%p)::StepOver (stop_other_threads='%s')",
769 static_cast<void*>(exe_ctx.GetThreadPtr()),
Greg Clayton17a6ad02012-01-30 02:53:15 +0000770 Thread::RunModeAsCString (stop_other_threads));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000771
Greg Clayton1ac04c32012-02-21 00:09:25 +0000772 if (exe_ctx.HasThreadScope())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000773 {
Greg Clayton1ac04c32012-02-21 00:09:25 +0000774 Thread *thread = exe_ctx.GetThreadPtr();
Jim Ingham7ba6e992012-05-11 23:47:32 +0000775 bool abort_other_plans = false;
Jason Molendab57e4a12013-11-04 09:33:30 +0000776 StackFrameSP frame_sp(thread->GetStackFrameAtIndex (0));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000777
Jim Ingham4d56e9c2013-07-18 21:48:26 +0000778 ThreadPlanSP new_plan_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000779 if (frame_sp)
780 {
781 if (frame_sp->HasDebugInformation ())
782 {
Jim Ingham4b4b2472014-03-13 02:47:14 +0000783 const LazyBool avoid_no_debug = eLazyBoolCalculate;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000784 SymbolContext sc(frame_sp->GetSymbolContext(eSymbolContextEverything));
Jim Ingham4d56e9c2013-07-18 21:48:26 +0000785 new_plan_sp = thread->QueueThreadPlanForStepOverRange (abort_other_plans,
Jason Molenda25d5b102015-12-15 00:40:30 +0000786 sc.line_entry,
Jim Inghamc6276822012-12-12 19:58:40 +0000787 sc,
Jim Ingham4b4b2472014-03-13 02:47:14 +0000788 stop_other_threads,
789 avoid_no_debug);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000790 }
791 else
792 {
Jim Ingham4d56e9c2013-07-18 21:48:26 +0000793 new_plan_sp = thread->QueueThreadPlanForStepSingleInstruction (true,
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000794 abort_other_plans,
795 stop_other_threads);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000796 }
797 }
798
Jim Ingham64e7ead2012-05-03 21:19:36 +0000799 // This returns an error, we should use it!
Jim Ingham4d56e9c2013-07-18 21:48:26 +0000800 ResumeNewPlan (exe_ctx, new_plan_sp.get());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000801 }
802}
803
804void
805SBThread::StepInto (lldb::RunMode stop_other_threads)
806{
Jim Inghamc6276822012-12-12 19:58:40 +0000807 StepInto (NULL, stop_other_threads);
808}
809
810void
811SBThread::StepInto (const char *target_name, lldb::RunMode stop_other_threads)
812{
Jim Inghamcbf6f9b2016-02-13 00:31:47 +0000813 SBError error;
814 StepInto(target_name, LLDB_INVALID_LINE_NUMBER, error, stop_other_threads);
815}
816
817void
818SBThread::StepInto (const char *target_name, uint32_t end_line, SBError &error, lldb::RunMode stop_other_threads)
819{
Greg Clayton5160ce52013-03-27 23:08:40 +0000820 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000821
Jim Ingham4fc6cb92012-08-22 21:34:33 +0000822 Mutex::Locker api_locker;
823 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
Greg Clayton17a6ad02012-01-30 02:53:15 +0000824
825 if (log)
Jim Inghamc6276822012-12-12 19:58:40 +0000826 log->Printf ("SBThread(%p)::StepInto (target_name='%s', stop_other_threads='%s')",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000827 static_cast<void*>(exe_ctx.GetThreadPtr()),
Jim Inghamc6276822012-12-12 19:58:40 +0000828 target_name? target_name: "<NULL>",
Greg Clayton17a6ad02012-01-30 02:53:15 +0000829 Thread::RunModeAsCString (stop_other_threads));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000830
Greg Clayton1ac04c32012-02-21 00:09:25 +0000831 if (exe_ctx.HasThreadScope())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000832 {
Jim Ingham7ba6e992012-05-11 23:47:32 +0000833 bool abort_other_plans = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000834
Greg Clayton1ac04c32012-02-21 00:09:25 +0000835 Thread *thread = exe_ctx.GetThreadPtr();
Jason Molendab57e4a12013-11-04 09:33:30 +0000836 StackFrameSP frame_sp(thread->GetStackFrameAtIndex (0));
Jim Ingham4d56e9c2013-07-18 21:48:26 +0000837 ThreadPlanSP new_plan_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000838
839 if (frame_sp && frame_sp->HasDebugInformation ())
840 {
Jim Inghamcbf6f9b2016-02-13 00:31:47 +0000841 SymbolContext sc(frame_sp->GetSymbolContext(eSymbolContextEverything));
842 AddressRange range;
843 if (end_line == LLDB_INVALID_LINE_NUMBER)
844 range = sc.line_entry.range;
845 else
846 {
847 if (!sc.GetAddressRangeFromHereToEndLine(end_line, range, error.ref()))
848 return;
849 }
850
Jim Ingham4b4b2472014-03-13 02:47:14 +0000851 const LazyBool step_out_avoids_code_without_debug_info = eLazyBoolCalculate;
852 const LazyBool step_in_avoids_code_without_debug_info = eLazyBoolCalculate;
Jim Ingham4d56e9c2013-07-18 21:48:26 +0000853 new_plan_sp = thread->QueueThreadPlanForStepInRange (abort_other_plans,
Jim Inghamcbf6f9b2016-02-13 00:31:47 +0000854 range,
Jim Inghamc6276822012-12-12 19:58:40 +0000855 sc,
856 target_name,
857 stop_other_threads,
Jim Ingham4b4b2472014-03-13 02:47:14 +0000858 step_in_avoids_code_without_debug_info,
859 step_out_avoids_code_without_debug_info);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000860 }
861 else
862 {
Jim Ingham4d56e9c2013-07-18 21:48:26 +0000863 new_plan_sp = thread->QueueThreadPlanForStepSingleInstruction (false,
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000864 abort_other_plans,
865 stop_other_threads);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000866 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000867
Jim Inghamcbf6f9b2016-02-13 00:31:47 +0000868 error = ResumeNewPlan (exe_ctx, new_plan_sp.get());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000869 }
870}
871
872void
873SBThread::StepOut ()
874{
Greg Clayton5160ce52013-03-27 23:08:40 +0000875 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000876
Jim Ingham4fc6cb92012-08-22 21:34:33 +0000877 Mutex::Locker api_locker;
878 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
879
Greg Clayton17a6ad02012-01-30 02:53:15 +0000880 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000881 log->Printf ("SBThread(%p)::StepOut ()",
882 static_cast<void*>(exe_ctx.GetThreadPtr()));
883
Greg Clayton1ac04c32012-02-21 00:09:25 +0000884 if (exe_ctx.HasThreadScope())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000885 {
Jim Ingham7ba6e992012-05-11 23:47:32 +0000886 bool abort_other_plans = false;
Jim Ingham94b09242012-09-14 21:07:14 +0000887 bool stop_other_threads = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000888
Greg Clayton1ac04c32012-02-21 00:09:25 +0000889 Thread *thread = exe_ctx.GetThreadPtr();
890
Jim Ingham4b4b2472014-03-13 02:47:14 +0000891 const LazyBool avoid_no_debug = eLazyBoolCalculate;
Jim Ingham4d56e9c2013-07-18 21:48:26 +0000892 ThreadPlanSP new_plan_sp(thread->QueueThreadPlanForStepOut (abort_other_plans,
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000893 NULL,
894 false,
895 stop_other_threads,
896 eVoteYes,
897 eVoteNoOpinion,
898 0,
899 avoid_no_debug));
900
Jim Ingham64e7ead2012-05-03 21:19:36 +0000901 // This returns an error, we should use it!
Jim Ingham4d56e9c2013-07-18 21:48:26 +0000902 ResumeNewPlan (exe_ctx, new_plan_sp.get());
Greg Clayton481cef22011-01-21 06:11:58 +0000903 }
904}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000905
Greg Clayton481cef22011-01-21 06:11:58 +0000906void
907SBThread::StepOutOfFrame (lldb::SBFrame &sb_frame)
908{
Greg Clayton5160ce52013-03-27 23:08:40 +0000909 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton481cef22011-01-21 06:11:58 +0000910
Jim Ingham4fc6cb92012-08-22 21:34:33 +0000911 Mutex::Locker api_locker;
912 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
913
Jim Ingham989a7552015-09-08 18:40:59 +0000914 if (!sb_frame.IsValid())
915 {
916 if (log)
917 log->Printf("SBThread(%p)::StepOutOfFrame passed an invalid frame, returning.",
918 static_cast<void*>(exe_ctx.GetThreadPtr()));
919 return;
920 }
921
Jason Molendab57e4a12013-11-04 09:33:30 +0000922 StackFrameSP frame_sp (sb_frame.GetFrameSP());
Greg Clayton481cef22011-01-21 06:11:58 +0000923 if (log)
924 {
925 SBStream frame_desc_strm;
926 sb_frame.GetDescription (frame_desc_strm);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000927 log->Printf ("SBThread(%p)::StepOutOfFrame (frame = SBFrame(%p): %s)",
928 static_cast<void*>(exe_ctx.GetThreadPtr()),
929 static_cast<void*>(frame_sp.get()),
930 frame_desc_strm.GetData());
Greg Clayton481cef22011-01-21 06:11:58 +0000931 }
932
Greg Clayton1ac04c32012-02-21 00:09:25 +0000933 if (exe_ctx.HasThreadScope())
Greg Clayton481cef22011-01-21 06:11:58 +0000934 {
Jim Ingham7ba6e992012-05-11 23:47:32 +0000935 bool abort_other_plans = false;
Jim Ingham94b09242012-09-14 21:07:14 +0000936 bool stop_other_threads = false;
Greg Clayton1ac04c32012-02-21 00:09:25 +0000937 Thread *thread = exe_ctx.GetThreadPtr();
Jim Ingham989a7552015-09-08 18:40:59 +0000938 if (sb_frame.GetThread().GetThreadID() != thread->GetID())
939 {
Bruce Mitchener1ef6e4c2015-09-09 00:56:25 +0000940 log->Printf("SBThread(%p)::StepOutOfFrame passed a frame from another thread (0x%" PRIx64 " vrs. 0x%" PRIx64 ", returning.",
Jim Ingham989a7552015-09-08 18:40:59 +0000941 static_cast<void*>(exe_ctx.GetThreadPtr()),
942 sb_frame.GetThread().GetThreadID(),
943 thread->GetID());
944 }
Greg Clayton481cef22011-01-21 06:11:58 +0000945
Jim Ingham4d56e9c2013-07-18 21:48:26 +0000946 ThreadPlanSP new_plan_sp(thread->QueueThreadPlanForStepOut (abort_other_plans,
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000947 NULL,
948 false,
949 stop_other_threads,
950 eVoteYes,
Jim Ingham64e7ead2012-05-03 21:19:36 +0000951 eVoteNoOpinion,
Jim Ingham4d56e9c2013-07-18 21:48:26 +0000952 frame_sp->GetFrameIndex()));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000953
Jim Ingham64e7ead2012-05-03 21:19:36 +0000954 // This returns an error, we should use it!
Jim Ingham4d56e9c2013-07-18 21:48:26 +0000955 ResumeNewPlan (exe_ctx, new_plan_sp.get());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000956 }
957}
958
959void
960SBThread::StepInstruction (bool step_over)
961{
Greg Clayton5160ce52013-03-27 23:08:40 +0000962 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000963
Jim Ingham4fc6cb92012-08-22 21:34:33 +0000964 Mutex::Locker api_locker;
965 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
966
Greg Clayton1ac04c32012-02-21 00:09:25 +0000967
Caroline Ticeceb6b132010-10-26 03:11:13 +0000968
Greg Clayton17a6ad02012-01-30 02:53:15 +0000969 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000970 log->Printf ("SBThread(%p)::StepInstruction (step_over=%i)",
971 static_cast<void*>(exe_ctx.GetThreadPtr()), step_over);
972
Greg Clayton1ac04c32012-02-21 00:09:25 +0000973 if (exe_ctx.HasThreadScope())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000974 {
Greg Clayton1ac04c32012-02-21 00:09:25 +0000975 Thread *thread = exe_ctx.GetThreadPtr();
Jim Ingham4d56e9c2013-07-18 21:48:26 +0000976 ThreadPlanSP new_plan_sp(thread->QueueThreadPlanForStepSingleInstruction (step_over, true, true));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000977
Jim Ingham64e7ead2012-05-03 21:19:36 +0000978 // This returns an error, we should use it!
Jim Ingham4d56e9c2013-07-18 21:48:26 +0000979 ResumeNewPlan (exe_ctx, new_plan_sp.get());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000980 }
981}
982
983void
984SBThread::RunToAddress (lldb::addr_t addr)
985{
Greg Clayton5160ce52013-03-27 23:08:40 +0000986 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000987
Jim Ingham4fc6cb92012-08-22 21:34:33 +0000988 Mutex::Locker api_locker;
989 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
990
Caroline Ticeceb6b132010-10-26 03:11:13 +0000991
Greg Clayton17a6ad02012-01-30 02:53:15 +0000992 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000993 log->Printf ("SBThread(%p)::RunToAddress (addr=0x%" PRIx64 ")",
994 static_cast<void*>(exe_ctx.GetThreadPtr()), addr);
995
Greg Clayton1ac04c32012-02-21 00:09:25 +0000996 if (exe_ctx.HasThreadScope())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000997 {
Jim Ingham7ba6e992012-05-11 23:47:32 +0000998 bool abort_other_plans = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000999 bool stop_other_threads = true;
1000
Greg Claytone72dfb32012-02-24 01:59:29 +00001001 Address target_addr (addr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001002
Greg Clayton1ac04c32012-02-21 00:09:25 +00001003 Thread *thread = exe_ctx.GetThreadPtr();
Greg Clayton1ac04c32012-02-21 00:09:25 +00001004
Jim Ingham2bdbfd52014-09-29 23:17:18 +00001005 ThreadPlanSP new_plan_sp(thread->QueueThreadPlanForRunToAddress (abort_other_plans,
1006 target_addr,
1007 stop_other_threads));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001008
Jim Ingham64e7ead2012-05-03 21:19:36 +00001009 // This returns an error, we should use it!
Jim Ingham4d56e9c2013-07-18 21:48:26 +00001010 ResumeNewPlan (exe_ctx, new_plan_sp.get());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001011 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001012}
1013
Greg Clayton481cef22011-01-21 06:11:58 +00001014SBError
1015SBThread::StepOverUntil (lldb::SBFrame &sb_frame,
1016 lldb::SBFileSpec &sb_file_spec,
1017 uint32_t line)
1018{
1019 SBError sb_error;
Greg Clayton5160ce52013-03-27 23:08:40 +00001020 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton481cef22011-01-21 06:11:58 +00001021 char path[PATH_MAX];
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001022
Jim Ingham4fc6cb92012-08-22 21:34:33 +00001023 Mutex::Locker api_locker;
1024 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
1025
Jason Molendab57e4a12013-11-04 09:33:30 +00001026 StackFrameSP frame_sp (sb_frame.GetFrameSP());
Greg Claytonb9556ac2012-01-30 07:41:31 +00001027
Greg Clayton481cef22011-01-21 06:11:58 +00001028 if (log)
1029 {
1030 SBStream frame_desc_strm;
1031 sb_frame.GetDescription (frame_desc_strm);
1032 sb_file_spec->GetPath (path, sizeof(path));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001033 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);
Greg Clayton481cef22011-01-21 06:11:58 +00001037 }
Greg Clayton17a6ad02012-01-30 02:53:15 +00001038
Greg Clayton1ac04c32012-02-21 00:09:25 +00001039 if (exe_ctx.HasThreadScope())
Greg Clayton481cef22011-01-21 06:11:58 +00001040 {
Greg Clayton1ac04c32012-02-21 00:09:25 +00001041 Target *target = exe_ctx.GetTargetPtr();
Greg Clayton1ac04c32012-02-21 00:09:25 +00001042 Thread *thread = exe_ctx.GetThreadPtr();
Greg Clayton481cef22011-01-21 06:11:58 +00001043
1044 if (line == 0)
1045 {
1046 sb_error.SetErrorString("invalid line argument");
1047 return sb_error;
1048 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001049
Greg Claytonb9556ac2012-01-30 07:41:31 +00001050 if (!frame_sp)
Greg Clayton481cef22011-01-21 06:11:58 +00001051 {
Greg Clayton1ac04c32012-02-21 00:09:25 +00001052 frame_sp = thread->GetSelectedFrame ();
Greg Clayton481cef22011-01-21 06:11:58 +00001053 if (!frame_sp)
Greg Clayton1ac04c32012-02-21 00:09:25 +00001054 frame_sp = thread->GetStackFrameAtIndex (0);
Greg Clayton481cef22011-01-21 06:11:58 +00001055 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001056
Greg Clayton481cef22011-01-21 06:11:58 +00001057 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 );
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001069
Greg Clayton481cef22011-01-21 06:11:58 +00001070 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 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001075
Greg Clayton481cef22011-01-21 06:11:58 +00001076 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 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001092
Jim Ingham9b70ddb2011-05-08 00:56:32 +00001093 // 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.
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001097
Jim Ingham9b70ddb2011-05-08 00:56:32 +00001098 bool all_in_function = true;
1099 AddressRange fun_range = frame_sc.function->GetAddressRange();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001100
Greg Clayton481cef22011-01-21 06:11:58 +00001101 std::vector<addr_t> step_over_until_addrs;
Jim Ingham7ba6e992012-05-11 23:47:32 +00001102 const bool abort_other_plans = false;
Jim Inghamc02e3342012-09-14 18:57:14 +00001103 const bool stop_other_threads = false;
Greg Clayton481cef22011-01-21 06:11:58 +00001104 const bool check_inlines = true;
1105 const bool exact = false;
1106
1107 SymbolContextList sc_list;
Jim Ingham9b70ddb2011-05-08 00:56:32 +00001108 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);
Greg Clayton481cef22011-01-21 06:11:58 +00001114 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 {
Jim Ingham9b70ddb2011-05-08 00:56:32 +00001121 addr_t step_addr = sc.line_entry.range.GetBaseAddress().GetLoadAddress(target);
Greg Clayton481cef22011-01-21 06:11:58 +00001122 if (step_addr != LLDB_INVALID_ADDRESS)
1123 {
Jim Ingham9b70ddb2011-05-08 00:56:32 +00001124 if (fun_range.ContainsLoadAddress(step_addr, target))
1125 step_over_until_addrs.push_back(step_addr);
1126 else
1127 all_in_function = false;
Greg Clayton481cef22011-01-21 06:11:58 +00001128 }
1129 }
1130 }
1131 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001132
Greg Clayton481cef22011-01-21 06:11:58 +00001133 if (step_over_until_addrs.empty())
1134 {
Jim Ingham9b70ddb2011-05-08 00:56:32 +00001135 if (all_in_function)
1136 {
1137 step_file_spec.GetPath (path, sizeof(path));
Jason Molendafd54b362011-09-20 21:44:10 +00001138 sb_error.SetErrorStringWithFormat("No line entries for %s:%u", path, line);
Jim Ingham9b70ddb2011-05-08 00:56:32 +00001139 }
1140 else
Greg Clayton86edbf42011-10-26 00:56:27 +00001141 sb_error.SetErrorString ("step until target not in current function");
Greg Clayton481cef22011-01-21 06:11:58 +00001142 }
1143 else
1144 {
Jim Ingham4d56e9c2013-07-18 21:48:26 +00001145 ThreadPlanSP new_plan_sp(thread->QueueThreadPlanForStepUntil (abort_other_plans,
Jim Ingham64e7ead2012-05-03 21:19:36 +00001146 &step_over_until_addrs[0],
1147 step_over_until_addrs.size(),
1148 stop_other_threads,
Jim Ingham4d56e9c2013-07-18 21:48:26 +00001149 frame_sp->GetFrameIndex()));
Greg Clayton481cef22011-01-21 06:11:58 +00001150
Jim Ingham4d56e9c2013-07-18 21:48:26 +00001151 sb_error = ResumeNewPlan (exe_ctx, new_plan_sp.get());
Greg Clayton481cef22011-01-21 06:11:58 +00001152 }
1153 }
1154 else
1155 {
1156 sb_error.SetErrorString("this SBThread object is invalid");
1157 }
1158 return sb_error;
1159}
1160
Jim Ingham44137582012-09-12 00:40:39 +00001161SBError
Jim Ingham2bdbfd52014-09-29 23:17:18 +00001162SBThread::StepUsingScriptedThreadPlan (const char *script_class_name)
1163{
1164 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1165 SBError sb_error;
1166
1167 Mutex::Locker api_locker;
1168 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
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
1201SBError
Richard Mittonf86248d2013-09-12 02:20:34 +00001202SBThread::JumpToLine (lldb::SBFileSpec &file_spec, uint32_t line)
1203{
1204 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1205 SBError sb_error;
1206
1207 Mutex::Locker api_locker;
1208 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
1209
1210 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001211 log->Printf ("SBThread(%p)::JumpToLine (file+line = %s:%u)",
1212 static_cast<void*>(exe_ctx.GetThreadPtr()),
1213 file_spec->GetPath().c_str(), line);
Richard Mittonf86248d2013-09-12 02:20:34 +00001214
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
1228SBError
Jim Inghamcb640dd2012-09-14 02:14:15 +00001229SBThread::ReturnFromFrame (SBFrame &frame, SBValue &return_value)
Jim Ingham44137582012-09-12 00:40:39 +00001230{
1231 SBError sb_error;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001232
Greg Clayton5160ce52013-03-27 23:08:40 +00001233 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Jim Ingham44137582012-09-12 00:40:39 +00001234
1235 Mutex::Locker api_locker;
1236 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
1237
1238
1239 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001240 log->Printf ("SBThread(%p)::ReturnFromFrame (frame=%d)",
1241 static_cast<void*>(exe_ctx.GetThreadPtr()),
1242 frame.GetFrameID());
1243
Jim Ingham44137582012-09-12 00:40:39 +00001244 if (exe_ctx.HasThreadScope())
1245 {
1246 Thread *thread = exe_ctx.GetThreadPtr();
Jim Inghamcb640dd2012-09-14 02:14:15 +00001247 sb_error.SetError (thread->ReturnFromFrame(frame.GetFrameSP(), return_value.GetSP()));
Jim Ingham44137582012-09-12 00:40:39 +00001248 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001249
Jim Ingham44137582012-09-12 00:40:39 +00001250 return sb_error;
1251}
1252
Greg Clayton481cef22011-01-21 06:11:58 +00001253
Greg Clayton722a0cd2011-01-12 02:25:42 +00001254bool
1255SBThread::Suspend()
1256{
Greg Clayton5160ce52013-03-27 23:08:40 +00001257 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001258 ExecutionContext exe_ctx (m_opaque_sp.get());
Greg Claytonc9858e42012-04-06 02:17:47 +00001259 bool result = false;
Greg Clayton1ac04c32012-02-21 00:09:25 +00001260 if (exe_ctx.HasThreadScope())
Greg Clayton722a0cd2011-01-12 02:25:42 +00001261 {
Greg Claytonc9858e42012-04-06 02:17:47 +00001262 Process::StopLocker stop_locker;
1263 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
1264 {
1265 exe_ctx.GetThreadPtr()->SetResumeState (eStateSuspended);
1266 result = true;
1267 }
1268 else
1269 {
1270 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001271 log->Printf ("SBThread(%p)::Suspend() => error: process is running",
1272 static_cast<void*>(exe_ctx.GetThreadPtr()));
Greg Claytonc9858e42012-04-06 02:17:47 +00001273 }
Greg Clayton722a0cd2011-01-12 02:25:42 +00001274 }
Greg Claytonc9858e42012-04-06 02:17:47 +00001275 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001276 log->Printf ("SBThread(%p)::Suspend() => %i",
1277 static_cast<void*>(exe_ctx.GetThreadPtr()), result);
Greg Claytonc9858e42012-04-06 02:17:47 +00001278 return result;
Greg Clayton722a0cd2011-01-12 02:25:42 +00001279}
1280
1281bool
1282SBThread::Resume ()
1283{
Greg Clayton5160ce52013-03-27 23:08:40 +00001284 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001285 ExecutionContext exe_ctx (m_opaque_sp.get());
Greg Claytonc9858e42012-04-06 02:17:47 +00001286 bool result = false;
Greg Clayton1ac04c32012-02-21 00:09:25 +00001287 if (exe_ctx.HasThreadScope())
Greg Clayton722a0cd2011-01-12 02:25:42 +00001288 {
Greg Claytonc9858e42012-04-06 02:17:47 +00001289 Process::StopLocker stop_locker;
1290 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
1291 {
Jim Ingham6c9ed912014-04-03 01:26:14 +00001292 const bool override_suspend = true;
1293 exe_ctx.GetThreadPtr()->SetResumeState (eStateRunning, override_suspend);
Greg Claytonc9858e42012-04-06 02:17:47 +00001294 result = true;
1295 }
1296 else
1297 {
1298 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001299 log->Printf ("SBThread(%p)::Resume() => error: process is running",
1300 static_cast<void*>(exe_ctx.GetThreadPtr()));
Greg Claytonc9858e42012-04-06 02:17:47 +00001301 }
Greg Clayton722a0cd2011-01-12 02:25:42 +00001302 }
Greg Claytonc9858e42012-04-06 02:17:47 +00001303 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001304 log->Printf ("SBThread(%p)::Resume() => %i",
1305 static_cast<void*>(exe_ctx.GetThreadPtr()), result);
Greg Claytonc9858e42012-04-06 02:17:47 +00001306 return result;
Greg Clayton722a0cd2011-01-12 02:25:42 +00001307}
1308
1309bool
1310SBThread::IsSuspended()
1311{
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001312 ExecutionContext exe_ctx (m_opaque_sp.get());
Greg Clayton1ac04c32012-02-21 00:09:25 +00001313 if (exe_ctx.HasThreadScope())
1314 return exe_ctx.GetThreadPtr()->GetResumeState () == eStateSuspended;
Greg Clayton722a0cd2011-01-12 02:25:42 +00001315 return false;
1316}
1317
Andrew Kaylora75418d2013-04-15 23:33:53 +00001318bool
1319SBThread::IsStopped()
1320{
1321 ExecutionContext exe_ctx (m_opaque_sp.get());
1322 if (exe_ctx.HasThreadScope())
1323 return StateIsStoppedState(exe_ctx.GetThreadPtr()->GetState(), true);
1324 return false;
1325}
1326
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001327SBProcess
1328SBThread::GetProcess ()
1329{
Greg Claytonb9556ac2012-01-30 07:41:31 +00001330 SBProcess sb_process;
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001331 ExecutionContext exe_ctx (m_opaque_sp.get());
Greg Clayton1ac04c32012-02-21 00:09:25 +00001332 if (exe_ctx.HasThreadScope())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001333 {
1334 // Have to go up to the target so we can get a shared pointer to our process...
Greg Clayton1ac04c32012-02-21 00:09:25 +00001335 sb_process.SetSP (exe_ctx.GetProcessSP());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001336 }
Caroline Ticeceb6b132010-10-26 03:11:13 +00001337
Greg Clayton5160ce52013-03-27 23:08:40 +00001338 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001339 if (log)
1340 {
Greg Clayton481cef22011-01-21 06:11:58 +00001341 SBStream frame_desc_strm;
Greg Claytonb9556ac2012-01-30 07:41:31 +00001342 sb_process.GetDescription (frame_desc_strm);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001343 log->Printf ("SBThread(%p)::GetProcess () => SBProcess(%p): %s",
1344 static_cast<void*>(exe_ctx.GetThreadPtr()),
1345 static_cast<void*>(sb_process.GetSP().get()),
1346 frame_desc_strm.GetData());
Caroline Ticeceb6b132010-10-26 03:11:13 +00001347 }
1348
Greg Claytonb9556ac2012-01-30 07:41:31 +00001349 return sb_process;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001350}
1351
1352uint32_t
1353SBThread::GetNumFrames ()
1354{
Greg Clayton5160ce52013-03-27 23:08:40 +00001355 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001356
Caroline Ticeceb6b132010-10-26 03:11:13 +00001357 uint32_t num_frames = 0;
Jim Ingham4fc6cb92012-08-22 21:34:33 +00001358 Mutex::Locker api_locker;
1359 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
1360
Greg Clayton1ac04c32012-02-21 00:09:25 +00001361 if (exe_ctx.HasThreadScope())
Greg Claytonaf67cec2010-12-20 20:49:23 +00001362 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001363 Process::StopLocker stop_locker;
1364 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
1365 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001366 num_frames = exe_ctx.GetThreadPtr()->GetStackFrameCount();
1367 }
Greg Claytonc9858e42012-04-06 02:17:47 +00001368 else
1369 {
1370 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001371 log->Printf ("SBThread(%p)::GetNumFrames() => error: process is running",
1372 static_cast<void*>(exe_ctx.GetThreadPtr()));
Greg Claytonc9858e42012-04-06 02:17:47 +00001373 }
Greg Claytonaf67cec2010-12-20 20:49:23 +00001374 }
Caroline Ticeceb6b132010-10-26 03:11:13 +00001375
1376 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001377 log->Printf ("SBThread(%p)::GetNumFrames () => %u",
1378 static_cast<void*>(exe_ctx.GetThreadPtr()), num_frames);
Caroline Ticeceb6b132010-10-26 03:11:13 +00001379
1380 return num_frames;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001381}
1382
1383SBFrame
1384SBThread::GetFrameAtIndex (uint32_t idx)
1385{
Greg Clayton5160ce52013-03-27 23:08:40 +00001386 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001387
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001388 SBFrame sb_frame;
Jason Molendab57e4a12013-11-04 09:33:30 +00001389 StackFrameSP frame_sp;
Jim Ingham4fc6cb92012-08-22 21:34:33 +00001390 Mutex::Locker api_locker;
1391 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
1392
Greg Clayton1ac04c32012-02-21 00:09:25 +00001393 if (exe_ctx.HasThreadScope())
Greg Claytonaf67cec2010-12-20 20:49:23 +00001394 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001395 Process::StopLocker stop_locker;
1396 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
1397 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001398 frame_sp = exe_ctx.GetThreadPtr()->GetStackFrameAtIndex (idx);
1399 sb_frame.SetFrameSP (frame_sp);
1400 }
Greg Claytonc9858e42012-04-06 02:17:47 +00001401 else
1402 {
1403 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001404 log->Printf ("SBThread(%p)::GetFrameAtIndex() => error: process is running",
1405 static_cast<void*>(exe_ctx.GetThreadPtr()));
Greg Claytonc9858e42012-04-06 02:17:47 +00001406 }
Greg Claytonaf67cec2010-12-20 20:49:23 +00001407 }
Caroline Ticeceb6b132010-10-26 03:11:13 +00001408
1409 if (log)
1410 {
Greg Clayton481cef22011-01-21 06:11:58 +00001411 SBStream frame_desc_strm;
1412 sb_frame.GetDescription (frame_desc_strm);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001413 log->Printf ("SBThread(%p)::GetFrameAtIndex (idx=%d) => SBFrame(%p): %s",
1414 static_cast<void*>(exe_ctx.GetThreadPtr()), idx,
1415 static_cast<void*>(frame_sp.get()),
1416 frame_desc_strm.GetData());
Caroline Ticeceb6b132010-10-26 03:11:13 +00001417 }
1418
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001419 return sb_frame;
1420}
1421
Greg Claytonf028a1f2010-12-17 02:26:24 +00001422lldb::SBFrame
1423SBThread::GetSelectedFrame ()
1424{
Greg Clayton5160ce52013-03-27 23:08:40 +00001425 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytonf028a1f2010-12-17 02:26:24 +00001426
1427 SBFrame sb_frame;
Jason Molendab57e4a12013-11-04 09:33:30 +00001428 StackFrameSP frame_sp;
Jim Ingham4fc6cb92012-08-22 21:34:33 +00001429 Mutex::Locker api_locker;
1430 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
1431
Greg Clayton1ac04c32012-02-21 00:09:25 +00001432 if (exe_ctx.HasThreadScope())
Greg Claytonaf67cec2010-12-20 20:49:23 +00001433 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001434 Process::StopLocker stop_locker;
1435 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
1436 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001437 frame_sp = exe_ctx.GetThreadPtr()->GetSelectedFrame ();
1438 sb_frame.SetFrameSP (frame_sp);
1439 }
Greg Claytonc9858e42012-04-06 02:17:47 +00001440 else
1441 {
1442 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001443 log->Printf ("SBThread(%p)::GetSelectedFrame() => error: process is running",
1444 static_cast<void*>(exe_ctx.GetThreadPtr()));
Greg Claytonc9858e42012-04-06 02:17:47 +00001445 }
Greg Claytonaf67cec2010-12-20 20:49:23 +00001446 }
Greg Claytonf028a1f2010-12-17 02:26:24 +00001447
1448 if (log)
1449 {
Greg Clayton481cef22011-01-21 06:11:58 +00001450 SBStream frame_desc_strm;
1451 sb_frame.GetDescription (frame_desc_strm);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001452 log->Printf ("SBThread(%p)::GetSelectedFrame () => SBFrame(%p): %s",
1453 static_cast<void*>(exe_ctx.GetThreadPtr()),
1454 static_cast<void*>(frame_sp.get()),
1455 frame_desc_strm.GetData());
Greg Claytonf028a1f2010-12-17 02:26:24 +00001456 }
1457
1458 return sb_frame;
1459}
1460
1461lldb::SBFrame
1462SBThread::SetSelectedFrame (uint32_t idx)
1463{
Greg Clayton5160ce52013-03-27 23:08:40 +00001464 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytonf028a1f2010-12-17 02:26:24 +00001465
1466 SBFrame sb_frame;
Jason Molendab57e4a12013-11-04 09:33:30 +00001467 StackFrameSP frame_sp;
Jim Ingham4fc6cb92012-08-22 21:34:33 +00001468 Mutex::Locker api_locker;
1469 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
1470
Greg Clayton1ac04c32012-02-21 00:09:25 +00001471 if (exe_ctx.HasThreadScope())
Greg Claytonf028a1f2010-12-17 02:26:24 +00001472 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001473 Process::StopLocker stop_locker;
1474 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
Greg Claytonf028a1f2010-12-17 02:26:24 +00001475 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001476 Thread *thread = exe_ctx.GetThreadPtr();
1477 frame_sp = thread->GetStackFrameAtIndex (idx);
1478 if (frame_sp)
1479 {
1480 thread->SetSelectedFrame (frame_sp.get());
1481 sb_frame.SetFrameSP (frame_sp);
1482 }
Greg Claytonf028a1f2010-12-17 02:26:24 +00001483 }
Greg Claytonc9858e42012-04-06 02:17:47 +00001484 else
1485 {
1486 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001487 log->Printf ("SBThread(%p)::SetSelectedFrame() => error: process is running",
1488 static_cast<void*>(exe_ctx.GetThreadPtr()));
Greg Claytonc9858e42012-04-06 02:17:47 +00001489 }
Greg Claytonf028a1f2010-12-17 02:26:24 +00001490 }
1491
1492 if (log)
1493 {
Greg Clayton481cef22011-01-21 06:11:58 +00001494 SBStream frame_desc_strm;
1495 sb_frame.GetDescription (frame_desc_strm);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001496 log->Printf ("SBThread(%p)::SetSelectedFrame (idx=%u) => SBFrame(%p): %s",
1497 static_cast<void*>(exe_ctx.GetThreadPtr()), idx,
1498 static_cast<void*>(frame_sp.get()),
1499 frame_desc_strm.GetData());
Greg Claytonf028a1f2010-12-17 02:26:24 +00001500 }
1501 return sb_frame;
1502}
1503
Jim Ingham4f465cf2012-10-10 18:32:14 +00001504bool
1505SBThread::EventIsThreadEvent (const SBEvent &event)
1506{
1507 return Thread::ThreadEventData::GetEventDataFromEvent(event.get()) != NULL;
1508}
1509
1510SBFrame
1511SBThread::GetStackFrameFromEvent (const SBEvent &event)
1512{
1513 return Thread::ThreadEventData::GetStackFrameFromEvent (event.get());
1514
1515}
1516
1517SBThread
1518SBThread::GetThreadFromEvent (const SBEvent &event)
1519{
1520 return Thread::ThreadEventData::GetThreadFromEvent (event.get());
1521}
Greg Claytonf028a1f2010-12-17 02:26:24 +00001522
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001523bool
1524SBThread::operator == (const SBThread &rhs) const
1525{
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001526 return m_opaque_sp->GetThreadSP().get() == rhs.m_opaque_sp->GetThreadSP().get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001527}
1528
1529bool
1530SBThread::operator != (const SBThread &rhs) const
1531{
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001532 return m_opaque_sp->GetThreadSP().get() != rhs.m_opaque_sp->GetThreadSP().get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001533}
Caroline Ticedde9cff2010-09-20 05:20:02 +00001534
1535bool
Jim Ingham4f465cf2012-10-10 18:32:14 +00001536SBThread::GetStatus (SBStream &status) const
1537{
1538 Stream &strm = status.ref();
1539
1540 ExecutionContext exe_ctx (m_opaque_sp.get());
1541 if (exe_ctx.HasThreadScope())
1542 {
1543 exe_ctx.GetThreadPtr()->GetStatus(strm, 0, 1, 1);
1544 }
1545 else
1546 strm.PutCString ("No status");
1547
1548 return true;
1549}
1550
1551bool
Caroline Ticeceb6b132010-10-26 03:11:13 +00001552SBThread::GetDescription (SBStream &description) const
1553{
Greg Claytonda7bc7d2011-11-13 06:57:31 +00001554 Stream &strm = description.ref();
1555
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001556 ExecutionContext exe_ctx (m_opaque_sp.get());
Greg Clayton1ac04c32012-02-21 00:09:25 +00001557 if (exe_ctx.HasThreadScope())
Caroline Ticeceb6b132010-10-26 03:11:13 +00001558 {
Jim Ingham603985f2015-01-28 01:18:01 +00001559 exe_ctx.GetThreadPtr()->DumpUsingSettingsFormat(strm, LLDB_INVALID_THREAD_ID);
1560 //strm.Printf("SBThread: tid = 0x%4.4" PRIx64, exe_ctx.GetThreadPtr()->GetID());
Caroline Ticeceb6b132010-10-26 03:11:13 +00001561 }
1562 else
Greg Claytonda7bc7d2011-11-13 06:57:31 +00001563 strm.PutCString ("No value");
Caroline Ticeceb6b132010-10-26 03:11:13 +00001564
1565 return true;
1566}
Jason Molenda5dd49162013-11-06 00:04:44 +00001567
1568SBThread
Jason Molenda008c45f2013-11-12 23:33:32 +00001569SBThread::GetExtendedBacktraceThread (const char *type)
Jason Molenda5dd49162013-11-06 00:04:44 +00001570{
1571 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1572 Mutex::Locker api_locker;
1573 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
1574 SBThread sb_origin_thread;
1575
1576 if (exe_ctx.HasThreadScope())
1577 {
1578 Process::StopLocker stop_locker;
1579 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
1580 {
Jason Molenda7a2f7902013-11-11 05:19:34 +00001581 ThreadSP real_thread(exe_ctx.GetThreadSP());
Jason Molenda5dd49162013-11-06 00:04:44 +00001582 if (real_thread)
1583 {
1584 ConstString type_const (type);
Jason Molenda7a2f7902013-11-11 05:19:34 +00001585 Process *process = exe_ctx.GetProcessPtr();
1586 if (process)
Jason Molenda5dd49162013-11-06 00:04:44 +00001587 {
Jason Molenda7a2f7902013-11-11 05:19:34 +00001588 SystemRuntime *runtime = process->GetSystemRuntime();
1589 if (runtime)
1590 {
Jason Molenda008c45f2013-11-12 23:33:32 +00001591 ThreadSP new_thread_sp (runtime->GetExtendedBacktraceThread (real_thread, type_const));
Jason Molendaa6e91302013-11-19 05:44:41 +00001592 if (new_thread_sp)
1593 {
1594 // Save this in the Process' ExtendedThreadList so a strong pointer retains the
1595 // object.
1596 process->GetExtendedThreadList().AddThread (new_thread_sp);
1597 sb_origin_thread.SetThread (new_thread_sp);
1598 if (log)
1599 {
1600 const char *queue_name = new_thread_sp->GetQueueName();
1601 if (queue_name == NULL)
1602 queue_name = "";
Jim Ingham2bdbfd52014-09-29 23:17:18 +00001603 log->Printf ("SBThread(%p)::GetExtendedBacktraceThread() => new extended Thread "
1604 "created (%p) with queue_id 0x%" PRIx64 " queue name '%s'",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001605 static_cast<void*>(exe_ctx.GetThreadPtr()),
1606 static_cast<void*>(new_thread_sp.get()),
1607 new_thread_sp->GetQueueID(),
1608 queue_name);
Jason Molendaa6e91302013-11-19 05:44:41 +00001609 }
1610 }
Jason Molenda7a2f7902013-11-11 05:19:34 +00001611 }
Jason Molenda5dd49162013-11-06 00:04:44 +00001612 }
1613 }
1614 }
1615 else
1616 {
1617 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001618 log->Printf ("SBThread(%p)::GetExtendedBacktraceThread() => error: process is running",
1619 static_cast<void*>(exe_ctx.GetThreadPtr()));
Jason Molenda5dd49162013-11-06 00:04:44 +00001620 }
1621 }
1622
Jason Molendaac605f42014-03-08 01:34:55 +00001623 if (log && sb_origin_thread.IsValid() == false)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001624 log->Printf("SBThread(%p)::GetExtendedBacktraceThread() is not returning a Valid thread",
1625 static_cast<void*>(exe_ctx.GetThreadPtr()));
Jason Molenda5dd49162013-11-06 00:04:44 +00001626 return sb_origin_thread;
1627}
Jason Molenda8ee9cb52013-11-16 01:24:22 +00001628
1629uint32_t
1630SBThread::GetExtendedBacktraceOriginatingIndexID ()
1631{
1632 ThreadSP thread_sp(m_opaque_sp->GetThreadSP());
1633 if (thread_sp)
1634 return thread_sp->GetExtendedBacktraceOriginatingIndexID();
1635 return LLDB_INVALID_INDEX32;
1636}
Jason Molendab4892cd2014-05-13 22:02:48 +00001637
1638bool
1639SBThread::SafeToCallFunctions ()
1640{
1641 ThreadSP thread_sp(m_opaque_sp->GetThreadSP());
1642 if (thread_sp)
1643 return thread_sp->SafeToCallFunctions();
1644 return true;
1645}
Jim Ingham2bdbfd52014-09-29 23:17:18 +00001646
1647lldb_private::Thread *
1648SBThread::operator->()
1649{
1650 ThreadSP thread_sp(m_opaque_sp->GetThreadSP());
1651 if (thread_sp)
1652 return thread_sp.get();
1653 else
1654 return NULL;
1655}
1656
1657lldb_private::Thread *
1658SBThread::get()
1659{
1660 ThreadSP thread_sp(m_opaque_sp->GetThreadSP());
1661 if (thread_sp)
1662 return thread_sp.get();
1663 else
1664 return NULL;
1665}
1666