blob: 4b54b1c0c1c67a5a2c126734147ef34cfab31eb8 [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
Daniel Malea93a64302012-12-05 00:20:57 +000010#include "lldb/lldb-python.h"
11
Eli Friedman4c5de692010-06-09 07:44:37 +000012#include "lldb/API/SBThread.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000013
14#include "lldb/API/SBSymbolContext.h"
15#include "lldb/API/SBFileSpec.h"
Caroline Ticedde9cff2010-09-20 05:20:02 +000016#include "lldb/API/SBStream.h"
Greg Clayton4e78f602010-11-18 18:52:36 +000017#include "lldb/Breakpoint/BreakpointLocation.h"
Greg Clayton66111032010-06-23 01:19:29 +000018#include "lldb/Core/Debugger.h"
Andrew Kaylora75418d2013-04-15 23:33:53 +000019#include "lldb/Core/State.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000020#include "lldb/Core/Stream.h"
21#include "lldb/Core/StreamFile.h"
Greg Clayton66111032010-06-23 01:19:29 +000022#include "lldb/Interpreter/CommandInterpreter.h"
Jason Molenda5dd49162013-11-06 00:04:44 +000023#include "lldb/Target/SystemRuntime.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000024#include "lldb/Target/Thread.h"
25#include "lldb/Target/Process.h"
26#include "lldb/Symbol/SymbolContext.h"
27#include "lldb/Symbol/CompileUnit.h"
Greg Claytonf4b47e12010-08-04 01:40:35 +000028#include "lldb/Target/StopInfo.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000029#include "lldb/Target/Target.h"
30#include "lldb/Target/ThreadPlan.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000031#include "lldb/Target/ThreadPlanStepInstruction.h"
32#include "lldb/Target/ThreadPlanStepOut.h"
33#include "lldb/Target/ThreadPlanStepRange.h"
34#include "lldb/Target/ThreadPlanStepInRange.h"
35
36
Eli Friedman4c5de692010-06-09 07:44:37 +000037#include "lldb/API/SBAddress.h"
Eli Friedman4c5de692010-06-09 07:44:37 +000038#include "lldb/API/SBDebugger.h"
Jim Ingham4f465cf2012-10-10 18:32:14 +000039#include "lldb/API/SBEvent.h"
Jim Ingham73ca05a2011-12-17 01:35:57 +000040#include "lldb/API/SBFrame.h"
Eli Friedman4c5de692010-06-09 07:44:37 +000041#include "lldb/API/SBProcess.h"
Jim Ingham73ca05a2011-12-17 01:35:57 +000042#include "lldb/API/SBValue.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000043
44using namespace lldb;
45using namespace lldb_private;
46
Jim Ingham4f465cf2012-10-10 18:32:14 +000047const char *
48SBThread::GetBroadcasterClassName ()
49{
50 return Thread::GetStaticBroadcasterClass().AsCString();
51}
52
Greg Claytoncfd1ace2010-10-31 03:01:06 +000053//----------------------------------------------------------------------
54// Constructors
55//----------------------------------------------------------------------
Chris Lattner30fdc8d2010-06-08 16:52:24 +000056SBThread::SBThread () :
Greg Clayton7fdf9ef2012-04-05 16:12:35 +000057 m_opaque_sp (new ExecutionContextRef())
Chris Lattner30fdc8d2010-06-08 16:52:24 +000058{
59}
60
Chris Lattner30fdc8d2010-06-08 16:52:24 +000061SBThread::SBThread (const ThreadSP& lldb_object_sp) :
Greg Clayton7fdf9ef2012-04-05 16:12:35 +000062 m_opaque_sp (new ExecutionContextRef(lldb_object_sp))
Chris Lattner30fdc8d2010-06-08 16:52:24 +000063{
64}
65
Greg Clayton92ef5732010-10-30 18:26:59 +000066SBThread::SBThread (const SBThread &rhs) :
Greg Clayton7fdf9ef2012-04-05 16:12:35 +000067 m_opaque_sp (new ExecutionContextRef(*rhs.m_opaque_sp))
Chris Lattner30fdc8d2010-06-08 16:52:24 +000068{
Greg Clayton7fdf9ef2012-04-05 16:12:35 +000069
Chris Lattner30fdc8d2010-06-08 16:52:24 +000070}
71
72//----------------------------------------------------------------------
Greg Claytoncfd1ace2010-10-31 03:01:06 +000073// Assignment operator
74//----------------------------------------------------------------------
75
76const lldb::SBThread &
77SBThread::operator = (const SBThread &rhs)
78{
79 if (this != &rhs)
Greg Clayton7fdf9ef2012-04-05 16:12:35 +000080 *m_opaque_sp = *rhs.m_opaque_sp;
Greg Claytoncfd1ace2010-10-31 03:01:06 +000081 return *this;
82}
83
84//----------------------------------------------------------------------
Chris Lattner30fdc8d2010-06-08 16:52:24 +000085// Destructor
86//----------------------------------------------------------------------
87SBThread::~SBThread()
88{
89}
90
91bool
92SBThread::IsValid() const
93{
Greg Clayton7fdf9ef2012-04-05 16:12:35 +000094 return m_opaque_sp->GetThreadSP().get() != NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000095}
96
Greg Clayton48e42542010-07-30 20:12:55 +000097void
98SBThread::Clear ()
99{
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000100 m_opaque_sp->Clear();
Greg Clayton48e42542010-07-30 20:12:55 +0000101}
102
103
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000104StopReason
105SBThread::GetStopReason()
106{
Greg Clayton5160ce52013-03-27 23:08:40 +0000107 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000108
Caroline Ticeceb6b132010-10-26 03:11:13 +0000109 StopReason reason = eStopReasonInvalid;
Jim Ingham4fc6cb92012-08-22 21:34:33 +0000110 Mutex::Locker api_locker;
111 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
112
Greg Clayton1ac04c32012-02-21 00:09:25 +0000113 if (exe_ctx.HasThreadScope())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000114 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000115 Process::StopLocker stop_locker;
116 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
117 {
Greg Clayton97d5cf02012-09-25 02:40:06 +0000118 return exe_ctx.GetThreadPtr()->GetStopReason();
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000119 }
Greg Claytonc9858e42012-04-06 02:17:47 +0000120 else
121 {
122 if (log)
123 log->Printf ("SBThread(%p)::GetStopReason() => error: process is running", exe_ctx.GetThreadPtr());
124 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000125 }
Caroline Ticeceb6b132010-10-26 03:11:13 +0000126
127 if (log)
Greg Clayton1ac04c32012-02-21 00:09:25 +0000128 log->Printf ("SBThread(%p)::GetStopReason () => %s", exe_ctx.GetThreadPtr(),
Caroline Tice750cd172010-10-26 23:49:36 +0000129 Thread::StopReasonAsCString (reason));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000130
131 return reason;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000132}
133
134size_t
Greg Clayton4e78f602010-11-18 18:52:36 +0000135SBThread::GetStopReasonDataCount ()
136{
Jim Ingham4fc6cb92012-08-22 21:34:33 +0000137 Mutex::Locker api_locker;
138 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
139
Greg Clayton1ac04c32012-02-21 00:09:25 +0000140 if (exe_ctx.HasThreadScope())
Greg Clayton4e78f602010-11-18 18:52:36 +0000141 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000142 Process::StopLocker stop_locker;
143 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
Greg Clayton4e78f602010-11-18 18:52:36 +0000144 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000145 StopInfoSP stop_info_sp = exe_ctx.GetThreadPtr()->GetStopInfo ();
146 if (stop_info_sp)
Greg Clayton4e78f602010-11-18 18:52:36 +0000147 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000148 StopReason reason = stop_info_sp->GetStopReason();
149 switch (reason)
Greg Clayton4e78f602010-11-18 18:52:36 +0000150 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000151 case eStopReasonInvalid:
152 case eStopReasonNone:
153 case eStopReasonTrace:
Greg Clayton90ba8112012-12-05 00:16:59 +0000154 case eStopReasonExec:
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000155 case eStopReasonPlanComplete:
Andrew Kaylorf85defa2012-12-20 23:08:03 +0000156 case eStopReasonThreadExiting:
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000157 // There is no data for these stop reasons.
158 return 0;
159
160 case eStopReasonBreakpoint:
161 {
162 break_id_t site_id = stop_info_sp->GetValue();
163 lldb::BreakpointSiteSP bp_site_sp (exe_ctx.GetProcessPtr()->GetBreakpointSiteList().FindByID (site_id));
164 if (bp_site_sp)
165 return bp_site_sp->GetNumberOfOwners () * 2;
166 else
167 return 0; // Breakpoint must have cleared itself...
168 }
169 break;
170
171 case eStopReasonWatchpoint:
172 return 1;
173
174 case eStopReasonSignal:
175 return 1;
176
177 case eStopReasonException:
178 return 1;
Greg Clayton4e78f602010-11-18 18:52:36 +0000179 }
Greg Clayton4e78f602010-11-18 18:52:36 +0000180 }
181 }
Greg Claytonc9858e42012-04-06 02:17:47 +0000182 else
183 {
Greg Clayton5160ce52013-03-27 23:08:40 +0000184 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytonc9858e42012-04-06 02:17:47 +0000185 if (log)
186 log->Printf ("SBThread(%p)::GetStopReasonDataCount() => error: process is running", exe_ctx.GetThreadPtr());
187 }
Greg Clayton4e78f602010-11-18 18:52:36 +0000188 }
189 return 0;
190}
191
192uint64_t
193SBThread::GetStopReasonDataAtIndex (uint32_t idx)
194{
Jim Ingham4fc6cb92012-08-22 21:34:33 +0000195 Mutex::Locker api_locker;
196 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
197
Greg Clayton1ac04c32012-02-21 00:09:25 +0000198 if (exe_ctx.HasThreadScope())
Greg Clayton4e78f602010-11-18 18:52:36 +0000199 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000200 Process::StopLocker stop_locker;
201 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
Greg Clayton4e78f602010-11-18 18:52:36 +0000202 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000203 Thread *thread = exe_ctx.GetThreadPtr();
204 StopInfoSP stop_info_sp = thread->GetStopInfo ();
205 if (stop_info_sp)
206 {
207 StopReason reason = stop_info_sp->GetStopReason();
208 switch (reason)
Greg Clayton4e78f602010-11-18 18:52:36 +0000209 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000210 case eStopReasonInvalid:
211 case eStopReasonNone:
212 case eStopReasonTrace:
Greg Clayton90ba8112012-12-05 00:16:59 +0000213 case eStopReasonExec:
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000214 case eStopReasonPlanComplete:
Andrew Kaylorf85defa2012-12-20 23:08:03 +0000215 case eStopReasonThreadExiting:
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000216 // There is no data for these stop reasons.
217 return 0;
218
219 case eStopReasonBreakpoint:
Greg Clayton4e78f602010-11-18 18:52:36 +0000220 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000221 break_id_t site_id = stop_info_sp->GetValue();
222 lldb::BreakpointSiteSP bp_site_sp (exe_ctx.GetProcessPtr()->GetBreakpointSiteList().FindByID (site_id));
223 if (bp_site_sp)
Greg Clayton4e78f602010-11-18 18:52:36 +0000224 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000225 uint32_t bp_index = idx / 2;
226 BreakpointLocationSP bp_loc_sp (bp_site_sp->GetOwnerAtIndex (bp_index));
227 if (bp_loc_sp)
Greg Clayton4e78f602010-11-18 18:52:36 +0000228 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000229 if (bp_index & 1)
230 {
231 // Odd idx, return the breakpoint location ID
232 return bp_loc_sp->GetID();
233 }
234 else
235 {
236 // Even idx, return the breakpoint ID
237 return bp_loc_sp->GetBreakpoint().GetID();
238 }
Greg Clayton4e78f602010-11-18 18:52:36 +0000239 }
240 }
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000241 return LLDB_INVALID_BREAK_ID;
Greg Clayton4e78f602010-11-18 18:52:36 +0000242 }
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000243 break;
244
245 case eStopReasonWatchpoint:
246 return stop_info_sp->GetValue();
247
248 case eStopReasonSignal:
249 return stop_info_sp->GetValue();
250
251 case eStopReasonException:
252 return stop_info_sp->GetValue();
Greg Clayton4e78f602010-11-18 18:52:36 +0000253 }
Greg Clayton4e78f602010-11-18 18:52:36 +0000254 }
255 }
Greg Claytonc9858e42012-04-06 02:17:47 +0000256 else
257 {
Greg Clayton5160ce52013-03-27 23:08:40 +0000258 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytonc9858e42012-04-06 02:17:47 +0000259 if (log)
260 log->Printf ("SBThread(%p)::GetStopReasonDataAtIndex() => error: process is running", exe_ctx.GetThreadPtr());
261 }
Greg Clayton4e78f602010-11-18 18:52:36 +0000262 }
263 return 0;
264}
265
266size_t
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000267SBThread::GetStopDescription (char *dst, size_t dst_len)
268{
Greg Clayton5160ce52013-03-27 23:08:40 +0000269 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000270
Jim Ingham4fc6cb92012-08-22 21:34:33 +0000271 Mutex::Locker api_locker;
272 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
273
Greg Clayton1ac04c32012-02-21 00:09:25 +0000274 if (exe_ctx.HasThreadScope())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000275 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000276 Process::StopLocker stop_locker;
277 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000278 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000279
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000280 StopInfoSP stop_info_sp = exe_ctx.GetThreadPtr()->GetStopInfo ();
281 if (stop_info_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000282 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000283 const char *stop_desc = stop_info_sp->GetDescription();
284 if (stop_desc)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000285 {
Caroline Ticeceb6b132010-10-26 03:11:13 +0000286 if (log)
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000287 log->Printf ("SBThread(%p)::GetStopDescription (dst, dst_len) => \"%s\"",
Greg Clayton1ac04c32012-02-21 00:09:25 +0000288 exe_ctx.GetThreadPtr(), stop_desc);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000289 if (dst)
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000290 return ::snprintf (dst, dst_len, "%s", stop_desc);
291 else
292 {
293 // NULL dst passed in, return the length needed to contain the description
294 return ::strlen (stop_desc) + 1; // Include the NULL byte for size
295 }
296 }
297 else
298 {
299 size_t stop_desc_len = 0;
300 switch (stop_info_sp->GetStopReason())
301 {
302 case eStopReasonTrace:
303 case eStopReasonPlanComplete:
304 {
305 static char trace_desc[] = "step";
306 stop_desc = trace_desc;
307 stop_desc_len = sizeof(trace_desc); // Include the NULL byte for size
308 }
309 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000310
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000311 case eStopReasonBreakpoint:
312 {
313 static char bp_desc[] = "breakpoint hit";
314 stop_desc = bp_desc;
315 stop_desc_len = sizeof(bp_desc); // Include the NULL byte for size
316 }
317 break;
318
319 case eStopReasonWatchpoint:
320 {
321 static char wp_desc[] = "watchpoint hit";
322 stop_desc = wp_desc;
323 stop_desc_len = sizeof(wp_desc); // Include the NULL byte for size
324 }
325 break;
326
327 case eStopReasonSignal:
328 {
329 stop_desc = exe_ctx.GetProcessPtr()->GetUnixSignals ().GetSignalAsCString (stop_info_sp->GetValue());
330 if (stop_desc == NULL || stop_desc[0] == '\0')
331 {
332 static char signal_desc[] = "signal";
333 stop_desc = signal_desc;
334 stop_desc_len = sizeof(signal_desc); // Include the NULL byte for size
335 }
336 }
337 break;
338
339 case eStopReasonException:
340 {
341 char exc_desc[] = "exception";
342 stop_desc = exc_desc;
343 stop_desc_len = sizeof(exc_desc); // Include the NULL byte for size
344 }
345 break;
346
Greg Clayton90ba8112012-12-05 00:16:59 +0000347 case eStopReasonExec:
348 {
349 char exc_desc[] = "exec";
350 stop_desc = exc_desc;
351 stop_desc_len = sizeof(exc_desc); // Include the NULL byte for size
352 }
353 break;
354
Andrew Kaylorf85defa2012-12-20 23:08:03 +0000355 case eStopReasonThreadExiting:
356 {
357 char limbo_desc[] = "thread exiting";
358 stop_desc = limbo_desc;
359 stop_desc_len = sizeof(limbo_desc);
360 }
361 break;
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000362 default:
363 break;
364 }
365
366 if (stop_desc && stop_desc[0])
367 {
368 if (log)
369 log->Printf ("SBThread(%p)::GetStopDescription (dst, dst_len) => '%s'",
370 exe_ctx.GetThreadPtr(), stop_desc);
371
372 if (dst)
373 return ::snprintf (dst, dst_len, "%s", stop_desc) + 1; // Include the NULL byte
374
375 if (stop_desc_len == 0)
376 stop_desc_len = ::strlen (stop_desc) + 1; // Include the NULL byte
377
378 return stop_desc_len;
379 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000380 }
381 }
382 }
Greg Claytonc9858e42012-04-06 02:17:47 +0000383 else
384 {
Greg Clayton5160ce52013-03-27 23:08:40 +0000385 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytonc9858e42012-04-06 02:17:47 +0000386 if (log)
387 log->Printf ("SBThread(%p)::GetStopDescription() => error: process is running", exe_ctx.GetThreadPtr());
388 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000389 }
390 if (dst)
391 *dst = 0;
392 return 0;
393}
394
Jim Ingham73ca05a2011-12-17 01:35:57 +0000395SBValue
396SBThread::GetStopReturnValue ()
397{
Greg Clayton5160ce52013-03-27 23:08:40 +0000398 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Jim Ingham73ca05a2011-12-17 01:35:57 +0000399 ValueObjectSP return_valobj_sp;
Jim Ingham4fc6cb92012-08-22 21:34:33 +0000400 Mutex::Locker api_locker;
401 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
402
Greg Clayton1ac04c32012-02-21 00:09:25 +0000403 if (exe_ctx.HasThreadScope())
Jim Ingham73ca05a2011-12-17 01:35:57 +0000404 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000405 Process::StopLocker stop_locker;
406 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
Jim Ingham73ca05a2011-12-17 01:35:57 +0000407 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000408 StopInfoSP stop_info_sp = exe_ctx.GetThreadPtr()->GetStopInfo ();
409 if (stop_info_sp)
410 {
411 return_valobj_sp = StopInfo::GetReturnValueObject (stop_info_sp);
412 }
Jim Ingham73ca05a2011-12-17 01:35:57 +0000413 }
Greg Claytonc9858e42012-04-06 02:17:47 +0000414 else
415 {
416 if (log)
417 log->Printf ("SBThread(%p)::GetStopReturnValue() => error: process is running", exe_ctx.GetThreadPtr());
418 }
Jim Ingham73ca05a2011-12-17 01:35:57 +0000419 }
420
Jim Ingham73ca05a2011-12-17 01:35:57 +0000421 if (log)
Greg Clayton1ac04c32012-02-21 00:09:25 +0000422 log->Printf ("SBThread(%p)::GetStopReturnValue () => %s", exe_ctx.GetThreadPtr(),
Jim Ingham73ca05a2011-12-17 01:35:57 +0000423 return_valobj_sp.get()
424 ? return_valobj_sp->GetValueAsCString()
425 : "<no return value>");
426
427 return SBValue (return_valobj_sp);
428}
429
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000430void
431SBThread::SetThread (const ThreadSP& lldb_object_sp)
432{
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000433 m_opaque_sp->SetThreadSP (lldb_object_sp);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000434}
435
436
437lldb::tid_t
438SBThread::GetThreadID () const
439{
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000440 ThreadSP thread_sp(m_opaque_sp->GetThreadSP());
Greg Clayton17a6ad02012-01-30 02:53:15 +0000441 if (thread_sp)
Greg Clayton1ac04c32012-02-21 00:09:25 +0000442 return thread_sp->GetID();
443 return LLDB_INVALID_THREAD_ID;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000444}
445
446uint32_t
447SBThread::GetIndexID () const
448{
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000449 ThreadSP thread_sp(m_opaque_sp->GetThreadSP());
Greg Clayton17a6ad02012-01-30 02:53:15 +0000450 if (thread_sp)
451 return thread_sp->GetIndexID();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000452 return LLDB_INVALID_INDEX32;
453}
Greg Clayton1ac04c32012-02-21 00:09:25 +0000454
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000455const char *
456SBThread::GetName () const
457{
Greg Clayton5160ce52013-03-27 23:08:40 +0000458 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton48381312010-10-30 04:51:46 +0000459 const char *name = NULL;
Jim Ingham4fc6cb92012-08-22 21:34:33 +0000460 Mutex::Locker api_locker;
461 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
462
Greg Clayton1ac04c32012-02-21 00:09:25 +0000463 if (exe_ctx.HasThreadScope())
Greg Claytonaf67cec2010-12-20 20:49:23 +0000464 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000465 Process::StopLocker stop_locker;
466 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
467 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000468 name = exe_ctx.GetThreadPtr()->GetName();
469 }
Greg Claytonc9858e42012-04-06 02:17:47 +0000470 else
471 {
472 if (log)
473 log->Printf ("SBThread(%p)::GetName() => error: process is running", exe_ctx.GetThreadPtr());
474 }
Greg Claytonaf67cec2010-12-20 20:49:23 +0000475 }
Greg Clayton48381312010-10-30 04:51:46 +0000476
Caroline Ticeceb6b132010-10-26 03:11:13 +0000477 if (log)
Greg Clayton1ac04c32012-02-21 00:09:25 +0000478 log->Printf ("SBThread(%p)::GetName () => %s", exe_ctx.GetThreadPtr(), name ? name : "NULL");
Caroline Ticeceb6b132010-10-26 03:11:13 +0000479
Greg Clayton48381312010-10-30 04:51:46 +0000480 return name;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000481}
482
483const char *
484SBThread::GetQueueName () const
485{
Greg Clayton48381312010-10-30 04:51:46 +0000486 const char *name = NULL;
Jim Ingham4fc6cb92012-08-22 21:34:33 +0000487 Mutex::Locker api_locker;
488 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
489
Greg Clayton5160ce52013-03-27 23:08:40 +0000490 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton1ac04c32012-02-21 00:09:25 +0000491 if (exe_ctx.HasThreadScope())
Greg Claytonaf67cec2010-12-20 20:49:23 +0000492 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000493 Process::StopLocker stop_locker;
494 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
495 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000496 name = exe_ctx.GetThreadPtr()->GetQueueName();
497 }
Greg Claytonc9858e42012-04-06 02:17:47 +0000498 else
499 {
500 if (log)
501 log->Printf ("SBThread(%p)::GetQueueName() => error: process is running", exe_ctx.GetThreadPtr());
502 }
Greg Claytonaf67cec2010-12-20 20:49:23 +0000503 }
Greg Clayton48381312010-10-30 04:51:46 +0000504
Caroline Ticeceb6b132010-10-26 03:11:13 +0000505 if (log)
Greg Clayton1ac04c32012-02-21 00:09:25 +0000506 log->Printf ("SBThread(%p)::GetQueueName () => %s", exe_ctx.GetThreadPtr(), name ? name : "NULL");
Caroline Ticeceb6b132010-10-26 03:11:13 +0000507
Greg Clayton48381312010-10-30 04:51:46 +0000508 return name;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000509}
510
Jason Molenda4fdb5862013-10-21 23:52:54 +0000511lldb::queue_id_t
512SBThread::GetQueueID () const
513{
514 queue_id_t id = LLDB_INVALID_QUEUE_ID;
515 Mutex::Locker api_locker;
516 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
517
518 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
519 if (exe_ctx.HasThreadScope())
520 {
521 Process::StopLocker stop_locker;
522 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
523 {
524 id = exe_ctx.GetThreadPtr()->GetQueueID();
525 }
526 else
527 {
528 if (log)
529 log->Printf ("SBThread(%p)::GetQueueID() => error: process is running", exe_ctx.GetThreadPtr());
530 }
531 }
532
533 if (log)
534 log->Printf ("SBThread(%p)::GetQueueID () => 0x%" PRIx64, exe_ctx.GetThreadPtr(), id);
535
536 return id;
537}
538
Jim Ingham64e7ead2012-05-03 21:19:36 +0000539SBError
540SBThread::ResumeNewPlan (ExecutionContext &exe_ctx, ThreadPlan *new_plan)
541{
542 SBError sb_error;
543
544 Process *process = exe_ctx.GetProcessPtr();
545 if (!process)
546 {
547 sb_error.SetErrorString("No process in SBThread::ResumeNewPlan");
548 return sb_error;
549 }
550
551 Thread *thread = exe_ctx.GetThreadPtr();
552 if (!thread)
553 {
554 sb_error.SetErrorString("No thread in SBThread::ResumeNewPlan");
555 return sb_error;
556 }
557
558 // User level plans should be Master Plans so they can be interrupted, other plans executed, and
559 // then a "continue" will resume the plan.
560 if (new_plan != NULL)
561 {
562 new_plan->SetIsMasterPlan(true);
563 new_plan->SetOkayToDiscard(false);
564 }
565
566 // Why do we need to set the current thread by ID here???
567 process->GetThreadList().SetSelectedThreadByID (thread->GetID());
568 sb_error.ref() = process->Resume();
569
570 if (sb_error.Success())
571 {
572 // If we are doing synchronous mode, then wait for the
573 // process to stop yet again!
574 if (process->GetTarget().GetDebugger().GetAsyncExecution () == false)
575 process->WaitForProcessToStop (NULL);
576 }
577
578 return sb_error;
579}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000580
581void
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000582SBThread::StepOver (lldb::RunMode stop_other_threads)
583{
Greg Clayton5160ce52013-03-27 23:08:40 +0000584 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000585
Jim Ingham4fc6cb92012-08-22 21:34:33 +0000586 Mutex::Locker api_locker;
587 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
588
Caroline Ticeceb6b132010-10-26 03:11:13 +0000589
Greg Clayton17a6ad02012-01-30 02:53:15 +0000590 if (log)
Greg Clayton1ac04c32012-02-21 00:09:25 +0000591 log->Printf ("SBThread(%p)::StepOver (stop_other_threads='%s')", exe_ctx.GetThreadPtr(),
Greg Clayton17a6ad02012-01-30 02:53:15 +0000592 Thread::RunModeAsCString (stop_other_threads));
593
Greg Clayton1ac04c32012-02-21 00:09:25 +0000594 if (exe_ctx.HasThreadScope())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000595 {
Greg Clayton1ac04c32012-02-21 00:09:25 +0000596 Thread *thread = exe_ctx.GetThreadPtr();
Jim Ingham7ba6e992012-05-11 23:47:32 +0000597 bool abort_other_plans = false;
Jason Molendab57e4a12013-11-04 09:33:30 +0000598 StackFrameSP frame_sp(thread->GetStackFrameAtIndex (0));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000599
Jim Ingham4d56e9c2013-07-18 21:48:26 +0000600 ThreadPlanSP new_plan_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000601 if (frame_sp)
602 {
603 if (frame_sp->HasDebugInformation ())
604 {
605 SymbolContext sc(frame_sp->GetSymbolContext(eSymbolContextEverything));
Jim Ingham4d56e9c2013-07-18 21:48:26 +0000606 new_plan_sp = thread->QueueThreadPlanForStepOverRange (abort_other_plans,
Jim Inghamc6276822012-12-12 19:58:40 +0000607 sc.line_entry.range,
608 sc,
609 stop_other_threads);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000610 }
611 else
612 {
Jim Ingham4d56e9c2013-07-18 21:48:26 +0000613 new_plan_sp = thread->QueueThreadPlanForStepSingleInstruction (true,
Jim Ingham64e7ead2012-05-03 21:19:36 +0000614 abort_other_plans,
615 stop_other_threads);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000616 }
617 }
618
Jim Ingham64e7ead2012-05-03 21:19:36 +0000619 // This returns an error, we should use it!
Jim Ingham4d56e9c2013-07-18 21:48:26 +0000620 ResumeNewPlan (exe_ctx, new_plan_sp.get());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000621 }
622}
623
624void
625SBThread::StepInto (lldb::RunMode stop_other_threads)
626{
Jim Inghamc6276822012-12-12 19:58:40 +0000627 StepInto (NULL, stop_other_threads);
628}
629
630void
631SBThread::StepInto (const char *target_name, lldb::RunMode stop_other_threads)
632{
Greg Clayton5160ce52013-03-27 23:08:40 +0000633 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000634
Jim Ingham4fc6cb92012-08-22 21:34:33 +0000635 Mutex::Locker api_locker;
636 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
Greg Clayton17a6ad02012-01-30 02:53:15 +0000637
638 if (log)
Jim Inghamc6276822012-12-12 19:58:40 +0000639 log->Printf ("SBThread(%p)::StepInto (target_name='%s', stop_other_threads='%s')",
640 exe_ctx.GetThreadPtr(),
641 target_name? target_name: "<NULL>",
Greg Clayton17a6ad02012-01-30 02:53:15 +0000642 Thread::RunModeAsCString (stop_other_threads));
Jim Inghamc6276822012-12-12 19:58:40 +0000643
Greg Clayton1ac04c32012-02-21 00:09:25 +0000644 if (exe_ctx.HasThreadScope())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000645 {
Jim Ingham7ba6e992012-05-11 23:47:32 +0000646 bool abort_other_plans = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000647
Greg Clayton1ac04c32012-02-21 00:09:25 +0000648 Thread *thread = exe_ctx.GetThreadPtr();
Jason Molendab57e4a12013-11-04 09:33:30 +0000649 StackFrameSP frame_sp(thread->GetStackFrameAtIndex (0));
Jim Ingham4d56e9c2013-07-18 21:48:26 +0000650 ThreadPlanSP new_plan_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000651
652 if (frame_sp && frame_sp->HasDebugInformation ())
653 {
Greg Clayton474966a2010-06-12 18:59:55 +0000654 bool avoid_code_without_debug_info = true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000655 SymbolContext sc(frame_sp->GetSymbolContext(eSymbolContextEverything));
Jim Ingham4d56e9c2013-07-18 21:48:26 +0000656 new_plan_sp = thread->QueueThreadPlanForStepInRange (abort_other_plans,
Jim Inghamc6276822012-12-12 19:58:40 +0000657 sc.line_entry.range,
658 sc,
659 target_name,
660 stop_other_threads,
661 avoid_code_without_debug_info);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000662 }
663 else
664 {
Jim Ingham4d56e9c2013-07-18 21:48:26 +0000665 new_plan_sp = thread->QueueThreadPlanForStepSingleInstruction (false,
Jim Ingham64e7ead2012-05-03 21:19:36 +0000666 abort_other_plans,
667 stop_other_threads);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000668 }
Jim Ingham64e7ead2012-05-03 21:19:36 +0000669
670 // This returns an error, we should use it!
Jim Ingham4d56e9c2013-07-18 21:48:26 +0000671 ResumeNewPlan (exe_ctx, new_plan_sp.get());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000672 }
673}
674
675void
676SBThread::StepOut ()
677{
Greg Clayton5160ce52013-03-27 23:08:40 +0000678 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000679
Jim Ingham4fc6cb92012-08-22 21:34:33 +0000680 Mutex::Locker api_locker;
681 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
682
Caroline Ticeceb6b132010-10-26 03:11:13 +0000683
Greg Clayton17a6ad02012-01-30 02:53:15 +0000684 if (log)
Greg Clayton1ac04c32012-02-21 00:09:25 +0000685 log->Printf ("SBThread(%p)::StepOut ()", exe_ctx.GetThreadPtr());
Greg Clayton17a6ad02012-01-30 02:53:15 +0000686
Greg Clayton1ac04c32012-02-21 00:09:25 +0000687 if (exe_ctx.HasThreadScope())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000688 {
Jim Ingham7ba6e992012-05-11 23:47:32 +0000689 bool abort_other_plans = false;
Jim Ingham94b09242012-09-14 21:07:14 +0000690 bool stop_other_threads = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000691
Greg Clayton1ac04c32012-02-21 00:09:25 +0000692 Thread *thread = exe_ctx.GetThreadPtr();
693
Jim Ingham4d56e9c2013-07-18 21:48:26 +0000694 ThreadPlanSP new_plan_sp(thread->QueueThreadPlanForStepOut (abort_other_plans,
Jim Ingham64e7ead2012-05-03 21:19:36 +0000695 NULL,
696 false,
697 stop_other_threads,
698 eVoteYes,
699 eVoteNoOpinion,
Jim Ingham4d56e9c2013-07-18 21:48:26 +0000700 0));
Jim Ingham64e7ead2012-05-03 21:19:36 +0000701
702 // This returns an error, we should use it!
Jim Ingham4d56e9c2013-07-18 21:48:26 +0000703 ResumeNewPlan (exe_ctx, new_plan_sp.get());
Greg Clayton481cef22011-01-21 06:11:58 +0000704 }
705}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000706
Greg Clayton481cef22011-01-21 06:11:58 +0000707void
708SBThread::StepOutOfFrame (lldb::SBFrame &sb_frame)
709{
Greg Clayton5160ce52013-03-27 23:08:40 +0000710 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton481cef22011-01-21 06:11:58 +0000711
Jim Ingham4fc6cb92012-08-22 21:34:33 +0000712 Mutex::Locker api_locker;
713 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
714
Jason Molendab57e4a12013-11-04 09:33:30 +0000715 StackFrameSP frame_sp (sb_frame.GetFrameSP());
Greg Clayton481cef22011-01-21 06:11:58 +0000716 if (log)
717 {
718 SBStream frame_desc_strm;
719 sb_frame.GetDescription (frame_desc_strm);
Greg Clayton1ac04c32012-02-21 00:09:25 +0000720 log->Printf ("SBThread(%p)::StepOutOfFrame (frame = SBFrame(%p): %s)", exe_ctx.GetThreadPtr(), frame_sp.get(), frame_desc_strm.GetData());
Greg Clayton481cef22011-01-21 06:11:58 +0000721 }
722
Greg Clayton1ac04c32012-02-21 00:09:25 +0000723 if (exe_ctx.HasThreadScope())
Greg Clayton481cef22011-01-21 06:11:58 +0000724 {
Jim Ingham7ba6e992012-05-11 23:47:32 +0000725 bool abort_other_plans = false;
Jim Ingham94b09242012-09-14 21:07:14 +0000726 bool stop_other_threads = false;
Greg Clayton1ac04c32012-02-21 00:09:25 +0000727 Thread *thread = exe_ctx.GetThreadPtr();
Greg Clayton481cef22011-01-21 06:11:58 +0000728
Jim Ingham4d56e9c2013-07-18 21:48:26 +0000729 ThreadPlanSP new_plan_sp(thread->QueueThreadPlanForStepOut (abort_other_plans,
Jim Ingham64e7ead2012-05-03 21:19:36 +0000730 NULL,
731 false,
732 stop_other_threads,
733 eVoteYes,
734 eVoteNoOpinion,
Jim Ingham4d56e9c2013-07-18 21:48:26 +0000735 frame_sp->GetFrameIndex()));
Jim Ingham64e7ead2012-05-03 21:19:36 +0000736
737 // This returns an error, we should use it!
Jim Ingham4d56e9c2013-07-18 21:48:26 +0000738 ResumeNewPlan (exe_ctx, new_plan_sp.get());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000739 }
740}
741
742void
743SBThread::StepInstruction (bool step_over)
744{
Greg Clayton5160ce52013-03-27 23:08:40 +0000745 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000746
Jim Ingham4fc6cb92012-08-22 21:34:33 +0000747 Mutex::Locker api_locker;
748 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
749
Greg Clayton1ac04c32012-02-21 00:09:25 +0000750
Caroline Ticeceb6b132010-10-26 03:11:13 +0000751
Greg Clayton17a6ad02012-01-30 02:53:15 +0000752 if (log)
Greg Clayton1ac04c32012-02-21 00:09:25 +0000753 log->Printf ("SBThread(%p)::StepInstruction (step_over=%i)", exe_ctx.GetThreadPtr(), step_over);
Greg Clayton17a6ad02012-01-30 02:53:15 +0000754
Greg Clayton1ac04c32012-02-21 00:09:25 +0000755 if (exe_ctx.HasThreadScope())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000756 {
Greg Clayton1ac04c32012-02-21 00:09:25 +0000757 Thread *thread = exe_ctx.GetThreadPtr();
Jim Ingham4d56e9c2013-07-18 21:48:26 +0000758 ThreadPlanSP new_plan_sp(thread->QueueThreadPlanForStepSingleInstruction (step_over, true, true));
Jim Ingham64e7ead2012-05-03 21:19:36 +0000759
760 // This returns an error, we should use it!
Jim Ingham4d56e9c2013-07-18 21:48:26 +0000761 ResumeNewPlan (exe_ctx, new_plan_sp.get());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000762 }
763}
764
765void
766SBThread::RunToAddress (lldb::addr_t addr)
767{
Greg Clayton5160ce52013-03-27 23:08:40 +0000768 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000769
Jim Ingham4fc6cb92012-08-22 21:34:33 +0000770 Mutex::Locker api_locker;
771 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
772
Caroline Ticeceb6b132010-10-26 03:11:13 +0000773
Greg Clayton17a6ad02012-01-30 02:53:15 +0000774 if (log)
Daniel Malead01b2952012-11-29 21:49:15 +0000775 log->Printf ("SBThread(%p)::RunToAddress (addr=0x%" PRIx64 ")", exe_ctx.GetThreadPtr(), addr);
Greg Clayton17a6ad02012-01-30 02:53:15 +0000776
Greg Clayton1ac04c32012-02-21 00:09:25 +0000777 if (exe_ctx.HasThreadScope())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000778 {
Jim Ingham7ba6e992012-05-11 23:47:32 +0000779 bool abort_other_plans = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000780 bool stop_other_threads = true;
781
Greg Claytone72dfb32012-02-24 01:59:29 +0000782 Address target_addr (addr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000783
Greg Clayton1ac04c32012-02-21 00:09:25 +0000784 Thread *thread = exe_ctx.GetThreadPtr();
Greg Clayton1ac04c32012-02-21 00:09:25 +0000785
Jim Ingham4d56e9c2013-07-18 21:48:26 +0000786 ThreadPlanSP new_plan_sp(thread->QueueThreadPlanForRunToAddress (abort_other_plans, target_addr, stop_other_threads));
Jim Ingham64e7ead2012-05-03 21:19:36 +0000787
788 // This returns an error, we should use it!
Jim Ingham4d56e9c2013-07-18 21:48:26 +0000789 ResumeNewPlan (exe_ctx, new_plan_sp.get());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000790 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000791}
792
Greg Clayton481cef22011-01-21 06:11:58 +0000793SBError
794SBThread::StepOverUntil (lldb::SBFrame &sb_frame,
795 lldb::SBFileSpec &sb_file_spec,
796 uint32_t line)
797{
798 SBError sb_error;
Greg Clayton5160ce52013-03-27 23:08:40 +0000799 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton481cef22011-01-21 06:11:58 +0000800 char path[PATH_MAX];
Greg Clayton17a6ad02012-01-30 02:53:15 +0000801
Jim Ingham4fc6cb92012-08-22 21:34:33 +0000802 Mutex::Locker api_locker;
803 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
804
Jason Molendab57e4a12013-11-04 09:33:30 +0000805 StackFrameSP frame_sp (sb_frame.GetFrameSP());
Greg Claytonb9556ac2012-01-30 07:41:31 +0000806
Greg Clayton481cef22011-01-21 06:11:58 +0000807 if (log)
808 {
809 SBStream frame_desc_strm;
810 sb_frame.GetDescription (frame_desc_strm);
811 sb_file_spec->GetPath (path, sizeof(path));
812 log->Printf ("SBThread(%p)::StepOverUntil (frame = SBFrame(%p): %s, file+line = %s:%u)",
Greg Clayton1ac04c32012-02-21 00:09:25 +0000813 exe_ctx.GetThreadPtr(),
Greg Claytonb9556ac2012-01-30 07:41:31 +0000814 frame_sp.get(),
Greg Clayton481cef22011-01-21 06:11:58 +0000815 frame_desc_strm.GetData(),
816 path, line);
817 }
Greg Clayton17a6ad02012-01-30 02:53:15 +0000818
Greg Clayton1ac04c32012-02-21 00:09:25 +0000819 if (exe_ctx.HasThreadScope())
Greg Clayton481cef22011-01-21 06:11:58 +0000820 {
Greg Clayton1ac04c32012-02-21 00:09:25 +0000821 Target *target = exe_ctx.GetTargetPtr();
Greg Clayton1ac04c32012-02-21 00:09:25 +0000822 Thread *thread = exe_ctx.GetThreadPtr();
Greg Clayton481cef22011-01-21 06:11:58 +0000823
824 if (line == 0)
825 {
826 sb_error.SetErrorString("invalid line argument");
827 return sb_error;
828 }
829
Greg Claytonb9556ac2012-01-30 07:41:31 +0000830 if (!frame_sp)
Greg Clayton481cef22011-01-21 06:11:58 +0000831 {
Greg Clayton1ac04c32012-02-21 00:09:25 +0000832 frame_sp = thread->GetSelectedFrame ();
Greg Clayton481cef22011-01-21 06:11:58 +0000833 if (!frame_sp)
Greg Clayton1ac04c32012-02-21 00:09:25 +0000834 frame_sp = thread->GetStackFrameAtIndex (0);
Greg Clayton481cef22011-01-21 06:11:58 +0000835 }
836
837 SymbolContext frame_sc;
838 if (!frame_sp)
839 {
840 sb_error.SetErrorString("no valid frames in thread to step");
841 return sb_error;
842 }
843
844 // If we have a frame, get its line
845 frame_sc = frame_sp->GetSymbolContext (eSymbolContextCompUnit |
846 eSymbolContextFunction |
847 eSymbolContextLineEntry |
848 eSymbolContextSymbol );
849
850 if (frame_sc.comp_unit == NULL)
851 {
852 sb_error.SetErrorStringWithFormat("frame %u doesn't have debug information", frame_sp->GetFrameIndex());
853 return sb_error;
854 }
855
856 FileSpec step_file_spec;
857 if (sb_file_spec.IsValid())
858 {
859 // The file spec passed in was valid, so use it
860 step_file_spec = sb_file_spec.ref();
861 }
862 else
863 {
864 if (frame_sc.line_entry.IsValid())
865 step_file_spec = frame_sc.line_entry.file;
866 else
867 {
868 sb_error.SetErrorString("invalid file argument or no file for frame");
869 return sb_error;
870 }
871 }
872
Jim Ingham9b70ddb2011-05-08 00:56:32 +0000873 // Grab the current function, then we will make sure the "until" address is
874 // within the function. We discard addresses that are out of the current
875 // function, and then if there are no addresses remaining, give an appropriate
876 // error message.
877
878 bool all_in_function = true;
879 AddressRange fun_range = frame_sc.function->GetAddressRange();
880
Greg Clayton481cef22011-01-21 06:11:58 +0000881 std::vector<addr_t> step_over_until_addrs;
Jim Ingham7ba6e992012-05-11 23:47:32 +0000882 const bool abort_other_plans = false;
Jim Inghamc02e3342012-09-14 18:57:14 +0000883 const bool stop_other_threads = false;
Greg Clayton481cef22011-01-21 06:11:58 +0000884 const bool check_inlines = true;
885 const bool exact = false;
886
887 SymbolContextList sc_list;
Jim Ingham9b70ddb2011-05-08 00:56:32 +0000888 const uint32_t num_matches = frame_sc.comp_unit->ResolveSymbolContext (step_file_spec,
889 line,
890 check_inlines,
891 exact,
892 eSymbolContextLineEntry,
893 sc_list);
Greg Clayton481cef22011-01-21 06:11:58 +0000894 if (num_matches > 0)
895 {
896 SymbolContext sc;
897 for (uint32_t i=0; i<num_matches; ++i)
898 {
899 if (sc_list.GetContextAtIndex(i, sc))
900 {
Jim Ingham9b70ddb2011-05-08 00:56:32 +0000901 addr_t step_addr = sc.line_entry.range.GetBaseAddress().GetLoadAddress(target);
Greg Clayton481cef22011-01-21 06:11:58 +0000902 if (step_addr != LLDB_INVALID_ADDRESS)
903 {
Jim Ingham9b70ddb2011-05-08 00:56:32 +0000904 if (fun_range.ContainsLoadAddress(step_addr, target))
905 step_over_until_addrs.push_back(step_addr);
906 else
907 all_in_function = false;
Greg Clayton481cef22011-01-21 06:11:58 +0000908 }
909 }
910 }
911 }
Jim Ingham9b70ddb2011-05-08 00:56:32 +0000912
Greg Clayton481cef22011-01-21 06:11:58 +0000913 if (step_over_until_addrs.empty())
914 {
Jim Ingham9b70ddb2011-05-08 00:56:32 +0000915 if (all_in_function)
916 {
917 step_file_spec.GetPath (path, sizeof(path));
Jason Molendafd54b362011-09-20 21:44:10 +0000918 sb_error.SetErrorStringWithFormat("No line entries for %s:%u", path, line);
Jim Ingham9b70ddb2011-05-08 00:56:32 +0000919 }
920 else
Greg Clayton86edbf42011-10-26 00:56:27 +0000921 sb_error.SetErrorString ("step until target not in current function");
Greg Clayton481cef22011-01-21 06:11:58 +0000922 }
923 else
924 {
Jim Ingham4d56e9c2013-07-18 21:48:26 +0000925 ThreadPlanSP new_plan_sp(thread->QueueThreadPlanForStepUntil (abort_other_plans,
Jim Ingham64e7ead2012-05-03 21:19:36 +0000926 &step_over_until_addrs[0],
927 step_over_until_addrs.size(),
928 stop_other_threads,
Jim Ingham4d56e9c2013-07-18 21:48:26 +0000929 frame_sp->GetFrameIndex()));
Greg Clayton481cef22011-01-21 06:11:58 +0000930
Jim Ingham4d56e9c2013-07-18 21:48:26 +0000931 sb_error = ResumeNewPlan (exe_ctx, new_plan_sp.get());
Greg Clayton481cef22011-01-21 06:11:58 +0000932 }
933 }
934 else
935 {
936 sb_error.SetErrorString("this SBThread object is invalid");
937 }
938 return sb_error;
939}
940
Jim Ingham44137582012-09-12 00:40:39 +0000941SBError
Richard Mittonf86248d2013-09-12 02:20:34 +0000942SBThread::JumpToLine (lldb::SBFileSpec &file_spec, uint32_t line)
943{
944 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
945 SBError sb_error;
946
947 Mutex::Locker api_locker;
948 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
949
950 if (log)
951 log->Printf ("SBThread(%p)::JumpToLine (file+line = %s:%u)", exe_ctx.GetThreadPtr(), file_spec->GetPath().c_str(), line);
952
953 if (!exe_ctx.HasThreadScope())
954 {
955 sb_error.SetErrorString("this SBThread object is invalid");
956 return sb_error;
957 }
958
959 Thread *thread = exe_ctx.GetThreadPtr();
960
961 Error err = thread->JumpToLine (file_spec.get(), line, true);
962 sb_error.SetError (err);
963 return sb_error;
964}
965
966SBError
Jim Inghamcb640dd2012-09-14 02:14:15 +0000967SBThread::ReturnFromFrame (SBFrame &frame, SBValue &return_value)
Jim Ingham44137582012-09-12 00:40:39 +0000968{
969 SBError sb_error;
970
Greg Clayton5160ce52013-03-27 23:08:40 +0000971 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Jim Ingham44137582012-09-12 00:40:39 +0000972
973 Mutex::Locker api_locker;
974 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
975
976
977 if (log)
Jim Inghamcb640dd2012-09-14 02:14:15 +0000978 log->Printf ("SBThread(%p)::ReturnFromFrame (frame=%d)", exe_ctx.GetThreadPtr(), frame.GetFrameID());
Jim Ingham44137582012-09-12 00:40:39 +0000979
980 if (exe_ctx.HasThreadScope())
981 {
982 Thread *thread = exe_ctx.GetThreadPtr();
Jim Inghamcb640dd2012-09-14 02:14:15 +0000983 sb_error.SetError (thread->ReturnFromFrame(frame.GetFrameSP(), return_value.GetSP()));
Jim Ingham44137582012-09-12 00:40:39 +0000984 }
985
986 return sb_error;
987}
988
Greg Clayton481cef22011-01-21 06:11:58 +0000989
Greg Clayton722a0cd2011-01-12 02:25:42 +0000990bool
991SBThread::Suspend()
992{
Greg Clayton5160ce52013-03-27 23:08:40 +0000993 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000994 ExecutionContext exe_ctx (m_opaque_sp.get());
Greg Claytonc9858e42012-04-06 02:17:47 +0000995 bool result = false;
Greg Clayton1ac04c32012-02-21 00:09:25 +0000996 if (exe_ctx.HasThreadScope())
Greg Clayton722a0cd2011-01-12 02:25:42 +0000997 {
Greg Claytonc9858e42012-04-06 02:17:47 +0000998 Process::StopLocker stop_locker;
999 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
1000 {
1001 exe_ctx.GetThreadPtr()->SetResumeState (eStateSuspended);
1002 result = true;
1003 }
1004 else
1005 {
1006 if (log)
1007 log->Printf ("SBThread(%p)::Suspend() => error: process is running", exe_ctx.GetThreadPtr());
1008 }
Greg Clayton722a0cd2011-01-12 02:25:42 +00001009 }
Greg Claytonc9858e42012-04-06 02:17:47 +00001010 if (log)
1011 log->Printf ("SBThread(%p)::Suspend() => %i", exe_ctx.GetThreadPtr(), result);
1012 return result;
Greg Clayton722a0cd2011-01-12 02:25:42 +00001013}
1014
1015bool
1016SBThread::Resume ()
1017{
Greg Clayton5160ce52013-03-27 23:08:40 +00001018 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001019 ExecutionContext exe_ctx (m_opaque_sp.get());
Greg Claytonc9858e42012-04-06 02:17:47 +00001020 bool result = false;
Greg Clayton1ac04c32012-02-21 00:09:25 +00001021 if (exe_ctx.HasThreadScope())
Greg Clayton722a0cd2011-01-12 02:25:42 +00001022 {
Greg Claytonc9858e42012-04-06 02:17:47 +00001023 Process::StopLocker stop_locker;
1024 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
1025 {
1026 exe_ctx.GetThreadPtr()->SetResumeState (eStateRunning);
1027 result = true;
1028 }
1029 else
1030 {
1031 if (log)
1032 log->Printf ("SBThread(%p)::Resume() => error: process is running", exe_ctx.GetThreadPtr());
1033 }
Greg Clayton722a0cd2011-01-12 02:25:42 +00001034 }
Greg Claytonc9858e42012-04-06 02:17:47 +00001035 if (log)
1036 log->Printf ("SBThread(%p)::Resume() => %i", exe_ctx.GetThreadPtr(), result);
1037 return result;
Greg Clayton722a0cd2011-01-12 02:25:42 +00001038}
1039
1040bool
1041SBThread::IsSuspended()
1042{
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001043 ExecutionContext exe_ctx (m_opaque_sp.get());
Greg Clayton1ac04c32012-02-21 00:09:25 +00001044 if (exe_ctx.HasThreadScope())
1045 return exe_ctx.GetThreadPtr()->GetResumeState () == eStateSuspended;
Greg Clayton722a0cd2011-01-12 02:25:42 +00001046 return false;
1047}
1048
Andrew Kaylora75418d2013-04-15 23:33:53 +00001049bool
1050SBThread::IsStopped()
1051{
1052 ExecutionContext exe_ctx (m_opaque_sp.get());
1053 if (exe_ctx.HasThreadScope())
1054 return StateIsStoppedState(exe_ctx.GetThreadPtr()->GetState(), true);
1055 return false;
1056}
1057
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001058SBProcess
1059SBThread::GetProcess ()
1060{
Greg Claytonb9556ac2012-01-30 07:41:31 +00001061 SBProcess sb_process;
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001062 ExecutionContext exe_ctx (m_opaque_sp.get());
Greg Clayton1ac04c32012-02-21 00:09:25 +00001063 if (exe_ctx.HasThreadScope())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001064 {
1065 // Have to go up to the target so we can get a shared pointer to our process...
Greg Clayton1ac04c32012-02-21 00:09:25 +00001066 sb_process.SetSP (exe_ctx.GetProcessSP());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001067 }
Caroline Ticeceb6b132010-10-26 03:11:13 +00001068
Greg Clayton5160ce52013-03-27 23:08:40 +00001069 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001070 if (log)
1071 {
Greg Clayton481cef22011-01-21 06:11:58 +00001072 SBStream frame_desc_strm;
Greg Claytonb9556ac2012-01-30 07:41:31 +00001073 sb_process.GetDescription (frame_desc_strm);
Greg Clayton1ac04c32012-02-21 00:09:25 +00001074 log->Printf ("SBThread(%p)::GetProcess () => SBProcess(%p): %s", exe_ctx.GetThreadPtr(),
Enrico Granata0a2df222013-02-28 02:18:49 +00001075 sb_process.GetSP().get(), frame_desc_strm.GetData());
Caroline Ticeceb6b132010-10-26 03:11:13 +00001076 }
1077
Greg Claytonb9556ac2012-01-30 07:41:31 +00001078 return sb_process;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001079}
1080
1081uint32_t
1082SBThread::GetNumFrames ()
1083{
Greg Clayton5160ce52013-03-27 23:08:40 +00001084 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001085
Caroline Ticeceb6b132010-10-26 03:11:13 +00001086 uint32_t num_frames = 0;
Jim Ingham4fc6cb92012-08-22 21:34:33 +00001087 Mutex::Locker api_locker;
1088 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
1089
Greg Clayton1ac04c32012-02-21 00:09:25 +00001090 if (exe_ctx.HasThreadScope())
Greg Claytonaf67cec2010-12-20 20:49:23 +00001091 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001092 Process::StopLocker stop_locker;
1093 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
1094 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001095 num_frames = exe_ctx.GetThreadPtr()->GetStackFrameCount();
1096 }
Greg Claytonc9858e42012-04-06 02:17:47 +00001097 else
1098 {
1099 if (log)
1100 log->Printf ("SBThread(%p)::GetNumFrames() => error: process is running", exe_ctx.GetThreadPtr());
1101 }
Greg Claytonaf67cec2010-12-20 20:49:23 +00001102 }
Caroline Ticeceb6b132010-10-26 03:11:13 +00001103
1104 if (log)
Greg Clayton1ac04c32012-02-21 00:09:25 +00001105 log->Printf ("SBThread(%p)::GetNumFrames () => %u", exe_ctx.GetThreadPtr(), num_frames);
Caroline Ticeceb6b132010-10-26 03:11:13 +00001106
1107 return num_frames;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001108}
1109
1110SBFrame
1111SBThread::GetFrameAtIndex (uint32_t idx)
1112{
Greg Clayton5160ce52013-03-27 23:08:40 +00001113 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001114
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001115 SBFrame sb_frame;
Jason Molendab57e4a12013-11-04 09:33:30 +00001116 StackFrameSP frame_sp;
Jim Ingham4fc6cb92012-08-22 21:34:33 +00001117 Mutex::Locker api_locker;
1118 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
1119
Greg Clayton1ac04c32012-02-21 00:09:25 +00001120 if (exe_ctx.HasThreadScope())
Greg Claytonaf67cec2010-12-20 20:49:23 +00001121 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001122 Process::StopLocker stop_locker;
1123 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
1124 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001125 frame_sp = exe_ctx.GetThreadPtr()->GetStackFrameAtIndex (idx);
1126 sb_frame.SetFrameSP (frame_sp);
1127 }
Greg Claytonc9858e42012-04-06 02:17:47 +00001128 else
1129 {
1130 if (log)
1131 log->Printf ("SBThread(%p)::GetFrameAtIndex() => error: process is running", exe_ctx.GetThreadPtr());
1132 }
Greg Claytonaf67cec2010-12-20 20:49:23 +00001133 }
Caroline Ticeceb6b132010-10-26 03:11:13 +00001134
1135 if (log)
1136 {
Greg Clayton481cef22011-01-21 06:11:58 +00001137 SBStream frame_desc_strm;
1138 sb_frame.GetDescription (frame_desc_strm);
Greg Clayton48381312010-10-30 04:51:46 +00001139 log->Printf ("SBThread(%p)::GetFrameAtIndex (idx=%d) => SBFrame(%p): %s",
Greg Clayton1ac04c32012-02-21 00:09:25 +00001140 exe_ctx.GetThreadPtr(), idx, frame_sp.get(), frame_desc_strm.GetData());
Caroline Ticeceb6b132010-10-26 03:11:13 +00001141 }
1142
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001143 return sb_frame;
1144}
1145
Greg Claytonf028a1f2010-12-17 02:26:24 +00001146lldb::SBFrame
1147SBThread::GetSelectedFrame ()
1148{
Greg Clayton5160ce52013-03-27 23:08:40 +00001149 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytonf028a1f2010-12-17 02:26:24 +00001150
1151 SBFrame sb_frame;
Jason Molendab57e4a12013-11-04 09:33:30 +00001152 StackFrameSP frame_sp;
Jim Ingham4fc6cb92012-08-22 21:34:33 +00001153 Mutex::Locker api_locker;
1154 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
1155
Greg Clayton1ac04c32012-02-21 00:09:25 +00001156 if (exe_ctx.HasThreadScope())
Greg Claytonaf67cec2010-12-20 20:49:23 +00001157 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001158 Process::StopLocker stop_locker;
1159 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
1160 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001161 frame_sp = exe_ctx.GetThreadPtr()->GetSelectedFrame ();
1162 sb_frame.SetFrameSP (frame_sp);
1163 }
Greg Claytonc9858e42012-04-06 02:17:47 +00001164 else
1165 {
1166 if (log)
1167 log->Printf ("SBThread(%p)::GetSelectedFrame() => error: process is running", exe_ctx.GetThreadPtr());
1168 }
Greg Claytonaf67cec2010-12-20 20:49:23 +00001169 }
Greg Claytonf028a1f2010-12-17 02:26:24 +00001170
1171 if (log)
1172 {
Greg Clayton481cef22011-01-21 06:11:58 +00001173 SBStream frame_desc_strm;
1174 sb_frame.GetDescription (frame_desc_strm);
Greg Claytonf028a1f2010-12-17 02:26:24 +00001175 log->Printf ("SBThread(%p)::GetSelectedFrame () => SBFrame(%p): %s",
Greg Clayton1ac04c32012-02-21 00:09:25 +00001176 exe_ctx.GetThreadPtr(), frame_sp.get(), frame_desc_strm.GetData());
Greg Claytonf028a1f2010-12-17 02:26:24 +00001177 }
1178
1179 return sb_frame;
1180}
1181
1182lldb::SBFrame
1183SBThread::SetSelectedFrame (uint32_t idx)
1184{
Greg Clayton5160ce52013-03-27 23:08:40 +00001185 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytonf028a1f2010-12-17 02:26:24 +00001186
1187 SBFrame sb_frame;
Jason Molendab57e4a12013-11-04 09:33:30 +00001188 StackFrameSP frame_sp;
Jim Ingham4fc6cb92012-08-22 21:34:33 +00001189 Mutex::Locker api_locker;
1190 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
1191
Greg Clayton1ac04c32012-02-21 00:09:25 +00001192 if (exe_ctx.HasThreadScope())
Greg Claytonf028a1f2010-12-17 02:26:24 +00001193 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001194 Process::StopLocker stop_locker;
1195 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
Greg Claytonf028a1f2010-12-17 02:26:24 +00001196 {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001197 Thread *thread = exe_ctx.GetThreadPtr();
1198 frame_sp = thread->GetStackFrameAtIndex (idx);
1199 if (frame_sp)
1200 {
1201 thread->SetSelectedFrame (frame_sp.get());
1202 sb_frame.SetFrameSP (frame_sp);
1203 }
Greg Claytonf028a1f2010-12-17 02:26:24 +00001204 }
Greg Claytonc9858e42012-04-06 02:17:47 +00001205 else
1206 {
1207 if (log)
1208 log->Printf ("SBThread(%p)::SetSelectedFrame() => error: process is running", exe_ctx.GetThreadPtr());
1209 }
Greg Claytonf028a1f2010-12-17 02:26:24 +00001210 }
1211
1212 if (log)
1213 {
Greg Clayton481cef22011-01-21 06:11:58 +00001214 SBStream frame_desc_strm;
1215 sb_frame.GetDescription (frame_desc_strm);
Greg Claytonf028a1f2010-12-17 02:26:24 +00001216 log->Printf ("SBThread(%p)::SetSelectedFrame (idx=%u) => SBFrame(%p): %s",
Greg Clayton1ac04c32012-02-21 00:09:25 +00001217 exe_ctx.GetThreadPtr(), idx, frame_sp.get(), frame_desc_strm.GetData());
Greg Claytonf028a1f2010-12-17 02:26:24 +00001218 }
1219 return sb_frame;
1220}
1221
Jim Ingham4f465cf2012-10-10 18:32:14 +00001222bool
1223SBThread::EventIsThreadEvent (const SBEvent &event)
1224{
1225 return Thread::ThreadEventData::GetEventDataFromEvent(event.get()) != NULL;
1226}
1227
1228SBFrame
1229SBThread::GetStackFrameFromEvent (const SBEvent &event)
1230{
1231 return Thread::ThreadEventData::GetStackFrameFromEvent (event.get());
1232
1233}
1234
1235SBThread
1236SBThread::GetThreadFromEvent (const SBEvent &event)
1237{
1238 return Thread::ThreadEventData::GetThreadFromEvent (event.get());
1239}
Greg Claytonf028a1f2010-12-17 02:26:24 +00001240
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001241bool
1242SBThread::operator == (const SBThread &rhs) const
1243{
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001244 return m_opaque_sp->GetThreadSP().get() == rhs.m_opaque_sp->GetThreadSP().get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001245}
1246
1247bool
1248SBThread::operator != (const SBThread &rhs) const
1249{
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001250 return m_opaque_sp->GetThreadSP().get() != rhs.m_opaque_sp->GetThreadSP().get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001251}
Caroline Ticedde9cff2010-09-20 05:20:02 +00001252
1253bool
Jim Ingham4f465cf2012-10-10 18:32:14 +00001254SBThread::GetStatus (SBStream &status) const
1255{
1256 Stream &strm = status.ref();
1257
1258 ExecutionContext exe_ctx (m_opaque_sp.get());
1259 if (exe_ctx.HasThreadScope())
1260 {
1261 exe_ctx.GetThreadPtr()->GetStatus(strm, 0, 1, 1);
1262 }
1263 else
1264 strm.PutCString ("No status");
1265
1266 return true;
1267}
1268
1269bool
Caroline Ticeceb6b132010-10-26 03:11:13 +00001270SBThread::GetDescription (SBStream &description) const
1271{
Greg Claytonda7bc7d2011-11-13 06:57:31 +00001272 Stream &strm = description.ref();
1273
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001274 ExecutionContext exe_ctx (m_opaque_sp.get());
Greg Clayton1ac04c32012-02-21 00:09:25 +00001275 if (exe_ctx.HasThreadScope())
Caroline Ticeceb6b132010-10-26 03:11:13 +00001276 {
Daniel Malead01b2952012-11-29 21:49:15 +00001277 strm.Printf("SBThread: tid = 0x%4.4" PRIx64, exe_ctx.GetThreadPtr()->GetID());
Caroline Ticeceb6b132010-10-26 03:11:13 +00001278 }
1279 else
Greg Claytonda7bc7d2011-11-13 06:57:31 +00001280 strm.PutCString ("No value");
Caroline Ticeceb6b132010-10-26 03:11:13 +00001281
1282 return true;
1283}
Jason Molenda5dd49162013-11-06 00:04:44 +00001284
1285SBThread
Jason Molenda95d005c2013-11-06 03:07:33 +00001286SBThread::GetExtendedBacktrace (const char *type)
Jason Molenda5dd49162013-11-06 00:04:44 +00001287{
1288 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1289 Mutex::Locker api_locker;
1290 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
1291 SBThread sb_origin_thread;
1292
1293 if (exe_ctx.HasThreadScope())
1294 {
1295 Process::StopLocker stop_locker;
1296 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
1297 {
1298 ThreadSP real_thread(exe_ctx.GetThreadPtr());
1299 if (real_thread)
1300 {
1301 ConstString type_const (type);
1302 SystemRuntime *runtime = exe_ctx.GetProcessPtr()->GetSystemRuntime();
1303 if (runtime)
1304 {
Jason Molenda95d005c2013-11-06 03:07:33 +00001305 ThreadSP origin_thread = runtime->GetExtendedBacktrace (real_thread, type_const);
Jason Molenda5dd49162013-11-06 00:04:44 +00001306 sb_origin_thread.SetThread (origin_thread);
1307 }
1308 }
1309 }
1310 else
1311 {
1312 if (log)
Jason Molenda95d005c2013-11-06 03:07:33 +00001313 log->Printf ("SBThread(%p)::GetExtendedBacktrace() => error: process is running", exe_ctx.GetThreadPtr());
Jason Molenda5dd49162013-11-06 00:04:44 +00001314 }
1315 }
1316
1317 return sb_origin_thread;
1318}