blob: c1e834bbd92aad8e199524930b95d96228a3ff6d [file] [log] [blame]
Chris Lattner24943d22010-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 Malead891f9b2012-12-05 00:20:57 +000010#include "lldb/lldb-python.h"
11
Eli Friedman7a62c8b2010-06-09 07:44:37 +000012#include "lldb/API/SBThread.h"
Chris Lattner24943d22010-06-08 16:52:24 +000013
14#include "lldb/API/SBSymbolContext.h"
15#include "lldb/API/SBFileSpec.h"
Caroline Tice98f930f2010-09-20 05:20:02 +000016#include "lldb/API/SBStream.h"
Greg Clayton640dc6b2010-11-18 18:52:36 +000017#include "lldb/Breakpoint/BreakpointLocation.h"
Greg Clayton63094e02010-06-23 01:19:29 +000018#include "lldb/Core/Debugger.h"
Chris Lattner24943d22010-06-08 16:52:24 +000019#include "lldb/Core/Stream.h"
20#include "lldb/Core/StreamFile.h"
Greg Clayton63094e02010-06-23 01:19:29 +000021#include "lldb/Interpreter/CommandInterpreter.h"
Chris Lattner24943d22010-06-08 16:52:24 +000022#include "lldb/Target/Thread.h"
23#include "lldb/Target/Process.h"
24#include "lldb/Symbol/SymbolContext.h"
25#include "lldb/Symbol/CompileUnit.h"
Greg Clayton643ee732010-08-04 01:40:35 +000026#include "lldb/Target/StopInfo.h"
Chris Lattner24943d22010-06-08 16:52:24 +000027#include "lldb/Target/Target.h"
28#include "lldb/Target/ThreadPlan.h"
Chris Lattner24943d22010-06-08 16:52:24 +000029#include "lldb/Target/ThreadPlanStepInstruction.h"
30#include "lldb/Target/ThreadPlanStepOut.h"
31#include "lldb/Target/ThreadPlanStepRange.h"
32#include "lldb/Target/ThreadPlanStepInRange.h"
33
34
Eli Friedman7a62c8b2010-06-09 07:44:37 +000035#include "lldb/API/SBAddress.h"
Eli Friedman7a62c8b2010-06-09 07:44:37 +000036#include "lldb/API/SBDebugger.h"
Jim Ingham94a5d0d2012-10-10 18:32:14 +000037#include "lldb/API/SBEvent.h"
Jim Ingham1586d972011-12-17 01:35:57 +000038#include "lldb/API/SBFrame.h"
Eli Friedman7a62c8b2010-06-09 07:44:37 +000039#include "lldb/API/SBProcess.h"
Jim Ingham1586d972011-12-17 01:35:57 +000040#include "lldb/API/SBValue.h"
Chris Lattner24943d22010-06-08 16:52:24 +000041
42using namespace lldb;
43using namespace lldb_private;
44
Jim Ingham94a5d0d2012-10-10 18:32:14 +000045const char *
46SBThread::GetBroadcasterClassName ()
47{
48 return Thread::GetStaticBroadcasterClass().AsCString();
49}
50
Greg Clayton49ce6822010-10-31 03:01:06 +000051//----------------------------------------------------------------------
52// Constructors
53//----------------------------------------------------------------------
Chris Lattner24943d22010-06-08 16:52:24 +000054SBThread::SBThread () :
Greg Claytona894fe72012-04-05 16:12:35 +000055 m_opaque_sp (new ExecutionContextRef())
Chris Lattner24943d22010-06-08 16:52:24 +000056{
57}
58
Chris Lattner24943d22010-06-08 16:52:24 +000059SBThread::SBThread (const ThreadSP& lldb_object_sp) :
Greg Claytona894fe72012-04-05 16:12:35 +000060 m_opaque_sp (new ExecutionContextRef(lldb_object_sp))
Chris Lattner24943d22010-06-08 16:52:24 +000061{
62}
63
Greg Clayton1b284412010-10-30 18:26:59 +000064SBThread::SBThread (const SBThread &rhs) :
Greg Claytona894fe72012-04-05 16:12:35 +000065 m_opaque_sp (new ExecutionContextRef(*rhs.m_opaque_sp))
Chris Lattner24943d22010-06-08 16:52:24 +000066{
Greg Claytona894fe72012-04-05 16:12:35 +000067
Chris Lattner24943d22010-06-08 16:52:24 +000068}
69
70//----------------------------------------------------------------------
Greg Clayton49ce6822010-10-31 03:01:06 +000071// Assignment operator
72//----------------------------------------------------------------------
73
74const lldb::SBThread &
75SBThread::operator = (const SBThread &rhs)
76{
77 if (this != &rhs)
Greg Claytona894fe72012-04-05 16:12:35 +000078 *m_opaque_sp = *rhs.m_opaque_sp;
Greg Clayton49ce6822010-10-31 03:01:06 +000079 return *this;
80}
81
82//----------------------------------------------------------------------
Chris Lattner24943d22010-06-08 16:52:24 +000083// Destructor
84//----------------------------------------------------------------------
85SBThread::~SBThread()
86{
87}
88
89bool
90SBThread::IsValid() const
91{
Greg Claytona894fe72012-04-05 16:12:35 +000092 return m_opaque_sp->GetThreadSP().get() != NULL;
Chris Lattner24943d22010-06-08 16:52:24 +000093}
94
Greg Clayton43490d12010-07-30 20:12:55 +000095void
96SBThread::Clear ()
97{
Greg Claytona894fe72012-04-05 16:12:35 +000098 m_opaque_sp->Clear();
Greg Clayton43490d12010-07-30 20:12:55 +000099}
100
101
Chris Lattner24943d22010-06-08 16:52:24 +0000102StopReason
103SBThread::GetStopReason()
104{
Greg Claytone005f2c2010-11-06 01:53:30 +0000105 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000106
Caroline Tice7826c882010-10-26 03:11:13 +0000107 StopReason reason = eStopReasonInvalid;
Jim Inghamd0bdddf2012-08-22 21:34:33 +0000108 Mutex::Locker api_locker;
109 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
110
Greg Claytonf4124de2012-02-21 00:09:25 +0000111 if (exe_ctx.HasThreadScope())
Chris Lattner24943d22010-06-08 16:52:24 +0000112 {
Greg Claytona894fe72012-04-05 16:12:35 +0000113 Process::StopLocker stop_locker;
114 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
115 {
Greg Clayton3acaa922012-09-25 02:40:06 +0000116 return exe_ctx.GetThreadPtr()->GetStopReason();
Greg Claytona894fe72012-04-05 16:12:35 +0000117 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000118 else
119 {
120 if (log)
121 log->Printf ("SBThread(%p)::GetStopReason() => error: process is running", exe_ctx.GetThreadPtr());
122 }
Chris Lattner24943d22010-06-08 16:52:24 +0000123 }
Caroline Tice7826c882010-10-26 03:11:13 +0000124
125 if (log)
Greg Claytonf4124de2012-02-21 00:09:25 +0000126 log->Printf ("SBThread(%p)::GetStopReason () => %s", exe_ctx.GetThreadPtr(),
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000127 Thread::StopReasonAsCString (reason));
Caroline Tice7826c882010-10-26 03:11:13 +0000128
129 return reason;
Chris Lattner24943d22010-06-08 16:52:24 +0000130}
131
132size_t
Greg Clayton640dc6b2010-11-18 18:52:36 +0000133SBThread::GetStopReasonDataCount ()
134{
Jim Inghamd0bdddf2012-08-22 21:34:33 +0000135 Mutex::Locker api_locker;
136 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
137
Greg Claytonf4124de2012-02-21 00:09:25 +0000138 if (exe_ctx.HasThreadScope())
Greg Clayton640dc6b2010-11-18 18:52:36 +0000139 {
Greg Claytona894fe72012-04-05 16:12:35 +0000140 Process::StopLocker stop_locker;
141 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
Greg Clayton640dc6b2010-11-18 18:52:36 +0000142 {
Greg Claytona894fe72012-04-05 16:12:35 +0000143 StopInfoSP stop_info_sp = exe_ctx.GetThreadPtr()->GetStopInfo ();
144 if (stop_info_sp)
Greg Clayton640dc6b2010-11-18 18:52:36 +0000145 {
Greg Claytona894fe72012-04-05 16:12:35 +0000146 StopReason reason = stop_info_sp->GetStopReason();
147 switch (reason)
Greg Clayton640dc6b2010-11-18 18:52:36 +0000148 {
Greg Claytona894fe72012-04-05 16:12:35 +0000149 case eStopReasonInvalid:
150 case eStopReasonNone:
151 case eStopReasonTrace:
Greg Clayton0bce9a22012-12-05 00:16:59 +0000152 case eStopReasonExec:
Greg Claytona894fe72012-04-05 16:12:35 +0000153 case eStopReasonPlanComplete:
154 // There is no data for these stop reasons.
155 return 0;
156
157 case eStopReasonBreakpoint:
158 {
159 break_id_t site_id = stop_info_sp->GetValue();
160 lldb::BreakpointSiteSP bp_site_sp (exe_ctx.GetProcessPtr()->GetBreakpointSiteList().FindByID (site_id));
161 if (bp_site_sp)
162 return bp_site_sp->GetNumberOfOwners () * 2;
163 else
164 return 0; // Breakpoint must have cleared itself...
165 }
166 break;
167
168 case eStopReasonWatchpoint:
169 return 1;
170
171 case eStopReasonSignal:
172 return 1;
173
174 case eStopReasonException:
175 return 1;
Greg Clayton640dc6b2010-11-18 18:52:36 +0000176 }
Greg Clayton640dc6b2010-11-18 18:52:36 +0000177 }
178 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000179 else
180 {
181 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
182 if (log)
183 log->Printf ("SBThread(%p)::GetStopReasonDataCount() => error: process is running", exe_ctx.GetThreadPtr());
184 }
Greg Clayton640dc6b2010-11-18 18:52:36 +0000185 }
186 return 0;
187}
188
189uint64_t
190SBThread::GetStopReasonDataAtIndex (uint32_t idx)
191{
Jim Inghamd0bdddf2012-08-22 21:34:33 +0000192 Mutex::Locker api_locker;
193 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
194
Greg Claytonf4124de2012-02-21 00:09:25 +0000195 if (exe_ctx.HasThreadScope())
Greg Clayton640dc6b2010-11-18 18:52:36 +0000196 {
Greg Claytona894fe72012-04-05 16:12:35 +0000197 Process::StopLocker stop_locker;
198 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
Greg Clayton640dc6b2010-11-18 18:52:36 +0000199 {
Greg Claytona894fe72012-04-05 16:12:35 +0000200 Thread *thread = exe_ctx.GetThreadPtr();
201 StopInfoSP stop_info_sp = thread->GetStopInfo ();
202 if (stop_info_sp)
203 {
204 StopReason reason = stop_info_sp->GetStopReason();
205 switch (reason)
Greg Clayton640dc6b2010-11-18 18:52:36 +0000206 {
Greg Claytona894fe72012-04-05 16:12:35 +0000207 case eStopReasonInvalid:
208 case eStopReasonNone:
209 case eStopReasonTrace:
Greg Clayton0bce9a22012-12-05 00:16:59 +0000210 case eStopReasonExec:
Greg Claytona894fe72012-04-05 16:12:35 +0000211 case eStopReasonPlanComplete:
212 // There is no data for these stop reasons.
213 return 0;
214
215 case eStopReasonBreakpoint:
Greg Clayton640dc6b2010-11-18 18:52:36 +0000216 {
Greg Claytona894fe72012-04-05 16:12:35 +0000217 break_id_t site_id = stop_info_sp->GetValue();
218 lldb::BreakpointSiteSP bp_site_sp (exe_ctx.GetProcessPtr()->GetBreakpointSiteList().FindByID (site_id));
219 if (bp_site_sp)
Greg Clayton640dc6b2010-11-18 18:52:36 +0000220 {
Greg Claytona894fe72012-04-05 16:12:35 +0000221 uint32_t bp_index = idx / 2;
222 BreakpointLocationSP bp_loc_sp (bp_site_sp->GetOwnerAtIndex (bp_index));
223 if (bp_loc_sp)
Greg Clayton640dc6b2010-11-18 18:52:36 +0000224 {
Greg Claytona894fe72012-04-05 16:12:35 +0000225 if (bp_index & 1)
226 {
227 // Odd idx, return the breakpoint location ID
228 return bp_loc_sp->GetID();
229 }
230 else
231 {
232 // Even idx, return the breakpoint ID
233 return bp_loc_sp->GetBreakpoint().GetID();
234 }
Greg Clayton640dc6b2010-11-18 18:52:36 +0000235 }
236 }
Greg Claytona894fe72012-04-05 16:12:35 +0000237 return LLDB_INVALID_BREAK_ID;
Greg Clayton640dc6b2010-11-18 18:52:36 +0000238 }
Greg Claytona894fe72012-04-05 16:12:35 +0000239 break;
240
241 case eStopReasonWatchpoint:
242 return stop_info_sp->GetValue();
243
244 case eStopReasonSignal:
245 return stop_info_sp->GetValue();
246
247 case eStopReasonException:
248 return stop_info_sp->GetValue();
Greg Clayton640dc6b2010-11-18 18:52:36 +0000249 }
Greg Clayton640dc6b2010-11-18 18:52:36 +0000250 }
251 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000252 else
253 {
254 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
255 if (log)
256 log->Printf ("SBThread(%p)::GetStopReasonDataAtIndex() => error: process is running", exe_ctx.GetThreadPtr());
257 }
Greg Clayton640dc6b2010-11-18 18:52:36 +0000258 }
259 return 0;
260}
261
262size_t
Chris Lattner24943d22010-06-08 16:52:24 +0000263SBThread::GetStopDescription (char *dst, size_t dst_len)
264{
Greg Claytone005f2c2010-11-06 01:53:30 +0000265 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000266
Jim Inghamd0bdddf2012-08-22 21:34:33 +0000267 Mutex::Locker api_locker;
268 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
269
Greg Claytonf4124de2012-02-21 00:09:25 +0000270 if (exe_ctx.HasThreadScope())
Chris Lattner24943d22010-06-08 16:52:24 +0000271 {
Greg Claytona894fe72012-04-05 16:12:35 +0000272 Process::StopLocker stop_locker;
273 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
Chris Lattner24943d22010-06-08 16:52:24 +0000274 {
Greg Claytona894fe72012-04-05 16:12:35 +0000275
Greg Claytona894fe72012-04-05 16:12:35 +0000276 StopInfoSP stop_info_sp = exe_ctx.GetThreadPtr()->GetStopInfo ();
277 if (stop_info_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000278 {
Greg Claytona894fe72012-04-05 16:12:35 +0000279 const char *stop_desc = stop_info_sp->GetDescription();
280 if (stop_desc)
Chris Lattner24943d22010-06-08 16:52:24 +0000281 {
Caroline Tice7826c882010-10-26 03:11:13 +0000282 if (log)
Greg Claytona894fe72012-04-05 16:12:35 +0000283 log->Printf ("SBThread(%p)::GetStopDescription (dst, dst_len) => \"%s\"",
Greg Claytonf4124de2012-02-21 00:09:25 +0000284 exe_ctx.GetThreadPtr(), stop_desc);
Chris Lattner24943d22010-06-08 16:52:24 +0000285 if (dst)
Greg Claytona894fe72012-04-05 16:12:35 +0000286 return ::snprintf (dst, dst_len, "%s", stop_desc);
287 else
288 {
289 // NULL dst passed in, return the length needed to contain the description
290 return ::strlen (stop_desc) + 1; // Include the NULL byte for size
291 }
292 }
293 else
294 {
295 size_t stop_desc_len = 0;
296 switch (stop_info_sp->GetStopReason())
297 {
298 case eStopReasonTrace:
299 case eStopReasonPlanComplete:
300 {
301 static char trace_desc[] = "step";
302 stop_desc = trace_desc;
303 stop_desc_len = sizeof(trace_desc); // Include the NULL byte for size
304 }
305 break;
Chris Lattner24943d22010-06-08 16:52:24 +0000306
Greg Claytona894fe72012-04-05 16:12:35 +0000307 case eStopReasonBreakpoint:
308 {
309 static char bp_desc[] = "breakpoint hit";
310 stop_desc = bp_desc;
311 stop_desc_len = sizeof(bp_desc); // Include the NULL byte for size
312 }
313 break;
314
315 case eStopReasonWatchpoint:
316 {
317 static char wp_desc[] = "watchpoint hit";
318 stop_desc = wp_desc;
319 stop_desc_len = sizeof(wp_desc); // Include the NULL byte for size
320 }
321 break;
322
323 case eStopReasonSignal:
324 {
325 stop_desc = exe_ctx.GetProcessPtr()->GetUnixSignals ().GetSignalAsCString (stop_info_sp->GetValue());
326 if (stop_desc == NULL || stop_desc[0] == '\0')
327 {
328 static char signal_desc[] = "signal";
329 stop_desc = signal_desc;
330 stop_desc_len = sizeof(signal_desc); // Include the NULL byte for size
331 }
332 }
333 break;
334
335 case eStopReasonException:
336 {
337 char exc_desc[] = "exception";
338 stop_desc = exc_desc;
339 stop_desc_len = sizeof(exc_desc); // Include the NULL byte for size
340 }
341 break;
342
Greg Clayton0bce9a22012-12-05 00:16:59 +0000343 case eStopReasonExec:
344 {
345 char exc_desc[] = "exec";
346 stop_desc = exc_desc;
347 stop_desc_len = sizeof(exc_desc); // Include the NULL byte for size
348 }
349 break;
350
Greg Claytona894fe72012-04-05 16:12:35 +0000351 default:
352 break;
353 }
354
355 if (stop_desc && stop_desc[0])
356 {
357 if (log)
358 log->Printf ("SBThread(%p)::GetStopDescription (dst, dst_len) => '%s'",
359 exe_ctx.GetThreadPtr(), stop_desc);
360
361 if (dst)
362 return ::snprintf (dst, dst_len, "%s", stop_desc) + 1; // Include the NULL byte
363
364 if (stop_desc_len == 0)
365 stop_desc_len = ::strlen (stop_desc) + 1; // Include the NULL byte
366
367 return stop_desc_len;
368 }
Chris Lattner24943d22010-06-08 16:52:24 +0000369 }
370 }
371 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000372 else
373 {
374 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
375 if (log)
376 log->Printf ("SBThread(%p)::GetStopDescription() => error: process is running", exe_ctx.GetThreadPtr());
377 }
Chris Lattner24943d22010-06-08 16:52:24 +0000378 }
379 if (dst)
380 *dst = 0;
381 return 0;
382}
383
Jim Ingham1586d972011-12-17 01:35:57 +0000384SBValue
385SBThread::GetStopReturnValue ()
386{
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000387 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Jim Ingham1586d972011-12-17 01:35:57 +0000388 ValueObjectSP return_valobj_sp;
Jim Inghamd0bdddf2012-08-22 21:34:33 +0000389 Mutex::Locker api_locker;
390 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
391
Greg Claytonf4124de2012-02-21 00:09:25 +0000392 if (exe_ctx.HasThreadScope())
Jim Ingham1586d972011-12-17 01:35:57 +0000393 {
Greg Claytona894fe72012-04-05 16:12:35 +0000394 Process::StopLocker stop_locker;
395 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
Jim Ingham1586d972011-12-17 01:35:57 +0000396 {
Greg Claytona894fe72012-04-05 16:12:35 +0000397 StopInfoSP stop_info_sp = exe_ctx.GetThreadPtr()->GetStopInfo ();
398 if (stop_info_sp)
399 {
400 return_valobj_sp = StopInfo::GetReturnValueObject (stop_info_sp);
401 }
Jim Ingham1586d972011-12-17 01:35:57 +0000402 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000403 else
404 {
405 if (log)
406 log->Printf ("SBThread(%p)::GetStopReturnValue() => error: process is running", exe_ctx.GetThreadPtr());
407 }
Jim Ingham1586d972011-12-17 01:35:57 +0000408 }
409
Jim Ingham1586d972011-12-17 01:35:57 +0000410 if (log)
Greg Claytonf4124de2012-02-21 00:09:25 +0000411 log->Printf ("SBThread(%p)::GetStopReturnValue () => %s", exe_ctx.GetThreadPtr(),
Jim Ingham1586d972011-12-17 01:35:57 +0000412 return_valobj_sp.get()
413 ? return_valobj_sp->GetValueAsCString()
414 : "<no return value>");
415
416 return SBValue (return_valobj_sp);
417}
418
Chris Lattner24943d22010-06-08 16:52:24 +0000419void
420SBThread::SetThread (const ThreadSP& lldb_object_sp)
421{
Greg Claytona894fe72012-04-05 16:12:35 +0000422 m_opaque_sp->SetThreadSP (lldb_object_sp);
Chris Lattner24943d22010-06-08 16:52:24 +0000423}
424
425
426lldb::tid_t
427SBThread::GetThreadID () const
428{
Greg Claytona894fe72012-04-05 16:12:35 +0000429 ThreadSP thread_sp(m_opaque_sp->GetThreadSP());
Greg Clayton90c52142012-01-30 02:53:15 +0000430 if (thread_sp)
Greg Claytonf4124de2012-02-21 00:09:25 +0000431 return thread_sp->GetID();
432 return LLDB_INVALID_THREAD_ID;
Chris Lattner24943d22010-06-08 16:52:24 +0000433}
434
435uint32_t
436SBThread::GetIndexID () const
437{
Greg Claytona894fe72012-04-05 16:12:35 +0000438 ThreadSP thread_sp(m_opaque_sp->GetThreadSP());
Greg Clayton90c52142012-01-30 02:53:15 +0000439 if (thread_sp)
440 return thread_sp->GetIndexID();
Chris Lattner24943d22010-06-08 16:52:24 +0000441 return LLDB_INVALID_INDEX32;
442}
Greg Claytonf4124de2012-02-21 00:09:25 +0000443
Chris Lattner24943d22010-06-08 16:52:24 +0000444const char *
445SBThread::GetName () const
446{
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000447 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000448 const char *name = NULL;
Jim Inghamd0bdddf2012-08-22 21:34:33 +0000449 Mutex::Locker api_locker;
450 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
451
Greg Claytonf4124de2012-02-21 00:09:25 +0000452 if (exe_ctx.HasThreadScope())
Greg Claytonbdcda462010-12-20 20:49:23 +0000453 {
Greg Claytona894fe72012-04-05 16:12:35 +0000454 Process::StopLocker stop_locker;
455 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
456 {
Greg Claytona894fe72012-04-05 16:12:35 +0000457 name = exe_ctx.GetThreadPtr()->GetName();
458 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000459 else
460 {
461 if (log)
462 log->Printf ("SBThread(%p)::GetName() => error: process is running", exe_ctx.GetThreadPtr());
463 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000464 }
Greg Claytona66ba462010-10-30 04:51:46 +0000465
Caroline Tice7826c882010-10-26 03:11:13 +0000466 if (log)
Greg Claytonf4124de2012-02-21 00:09:25 +0000467 log->Printf ("SBThread(%p)::GetName () => %s", exe_ctx.GetThreadPtr(), name ? name : "NULL");
Caroline Tice7826c882010-10-26 03:11:13 +0000468
Greg Claytona66ba462010-10-30 04:51:46 +0000469 return name;
Chris Lattner24943d22010-06-08 16:52:24 +0000470}
471
472const char *
473SBThread::GetQueueName () const
474{
Greg Claytona66ba462010-10-30 04:51:46 +0000475 const char *name = NULL;
Jim Inghamd0bdddf2012-08-22 21:34:33 +0000476 Mutex::Locker api_locker;
477 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
478
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000479 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytonf4124de2012-02-21 00:09:25 +0000480 if (exe_ctx.HasThreadScope())
Greg Claytonbdcda462010-12-20 20:49:23 +0000481 {
Greg Claytona894fe72012-04-05 16:12:35 +0000482 Process::StopLocker stop_locker;
483 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
484 {
Greg Claytona894fe72012-04-05 16:12:35 +0000485 name = exe_ctx.GetThreadPtr()->GetQueueName();
486 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000487 else
488 {
489 if (log)
490 log->Printf ("SBThread(%p)::GetQueueName() => error: process is running", exe_ctx.GetThreadPtr());
491 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000492 }
Greg Claytona66ba462010-10-30 04:51:46 +0000493
Caroline Tice7826c882010-10-26 03:11:13 +0000494 if (log)
Greg Claytonf4124de2012-02-21 00:09:25 +0000495 log->Printf ("SBThread(%p)::GetQueueName () => %s", exe_ctx.GetThreadPtr(), name ? name : "NULL");
Caroline Tice7826c882010-10-26 03:11:13 +0000496
Greg Claytona66ba462010-10-30 04:51:46 +0000497 return name;
Chris Lattner24943d22010-06-08 16:52:24 +0000498}
499
Jim Ingham88e3de22012-05-03 21:19:36 +0000500SBError
501SBThread::ResumeNewPlan (ExecutionContext &exe_ctx, ThreadPlan *new_plan)
502{
503 SBError sb_error;
504
505 Process *process = exe_ctx.GetProcessPtr();
506 if (!process)
507 {
508 sb_error.SetErrorString("No process in SBThread::ResumeNewPlan");
509 return sb_error;
510 }
511
512 Thread *thread = exe_ctx.GetThreadPtr();
513 if (!thread)
514 {
515 sb_error.SetErrorString("No thread in SBThread::ResumeNewPlan");
516 return sb_error;
517 }
518
519 // User level plans should be Master Plans so they can be interrupted, other plans executed, and
520 // then a "continue" will resume the plan.
521 if (new_plan != NULL)
522 {
523 new_plan->SetIsMasterPlan(true);
524 new_plan->SetOkayToDiscard(false);
525 }
526
527 // Why do we need to set the current thread by ID here???
528 process->GetThreadList().SetSelectedThreadByID (thread->GetID());
529 sb_error.ref() = process->Resume();
530
531 if (sb_error.Success())
532 {
533 // If we are doing synchronous mode, then wait for the
534 // process to stop yet again!
535 if (process->GetTarget().GetDebugger().GetAsyncExecution () == false)
536 process->WaitForProcessToStop (NULL);
537 }
538
539 return sb_error;
540}
Chris Lattner24943d22010-06-08 16:52:24 +0000541
542void
Chris Lattner24943d22010-06-08 16:52:24 +0000543SBThread::StepOver (lldb::RunMode stop_other_threads)
544{
Greg Claytone005f2c2010-11-06 01:53:30 +0000545 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000546
Jim Inghamd0bdddf2012-08-22 21:34:33 +0000547 Mutex::Locker api_locker;
548 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
549
Caroline Tice7826c882010-10-26 03:11:13 +0000550
Greg Clayton90c52142012-01-30 02:53:15 +0000551 if (log)
Greg Claytonf4124de2012-02-21 00:09:25 +0000552 log->Printf ("SBThread(%p)::StepOver (stop_other_threads='%s')", exe_ctx.GetThreadPtr(),
Greg Clayton90c52142012-01-30 02:53:15 +0000553 Thread::RunModeAsCString (stop_other_threads));
554
Greg Claytonf4124de2012-02-21 00:09:25 +0000555 if (exe_ctx.HasThreadScope())
Chris Lattner24943d22010-06-08 16:52:24 +0000556 {
Greg Claytonf4124de2012-02-21 00:09:25 +0000557 Thread *thread = exe_ctx.GetThreadPtr();
Jim Inghamd82bc6d2012-05-11 23:47:32 +0000558 bool abort_other_plans = false;
Greg Claytonf4124de2012-02-21 00:09:25 +0000559 StackFrameSP frame_sp(thread->GetStackFrameAtIndex (0));
Jim Ingham88e3de22012-05-03 21:19:36 +0000560 ThreadPlan *new_plan = NULL;
Chris Lattner24943d22010-06-08 16:52:24 +0000561
562 if (frame_sp)
563 {
564 if (frame_sp->HasDebugInformation ())
565 {
566 SymbolContext sc(frame_sp->GetSymbolContext(eSymbolContextEverything));
Jim Inghamf2ca5732012-12-12 19:58:40 +0000567 new_plan = thread->QueueThreadPlanForStepOverRange (abort_other_plans,
568 sc.line_entry.range,
569 sc,
570 stop_other_threads);
Chris Lattner24943d22010-06-08 16:52:24 +0000571 }
572 else
573 {
Jim Ingham88e3de22012-05-03 21:19:36 +0000574 new_plan = thread->QueueThreadPlanForStepSingleInstruction (true,
575 abort_other_plans,
576 stop_other_threads);
Chris Lattner24943d22010-06-08 16:52:24 +0000577 }
578 }
579
Jim Ingham88e3de22012-05-03 21:19:36 +0000580 // This returns an error, we should use it!
581 ResumeNewPlan (exe_ctx, new_plan);
Chris Lattner24943d22010-06-08 16:52:24 +0000582 }
583}
584
585void
586SBThread::StepInto (lldb::RunMode stop_other_threads)
587{
Jim Inghamf2ca5732012-12-12 19:58:40 +0000588 StepInto (NULL, stop_other_threads);
589}
590
591void
592SBThread::StepInto (const char *target_name, lldb::RunMode stop_other_threads)
593{
Greg Claytone005f2c2010-11-06 01:53:30 +0000594 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000595
Jim Inghamd0bdddf2012-08-22 21:34:33 +0000596 Mutex::Locker api_locker;
597 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
Greg Clayton90c52142012-01-30 02:53:15 +0000598
599 if (log)
Jim Inghamf2ca5732012-12-12 19:58:40 +0000600 log->Printf ("SBThread(%p)::StepInto (target_name='%s', stop_other_threads='%s')",
601 exe_ctx.GetThreadPtr(),
602 target_name? target_name: "<NULL>",
Greg Clayton90c52142012-01-30 02:53:15 +0000603 Thread::RunModeAsCString (stop_other_threads));
Jim Inghamf2ca5732012-12-12 19:58:40 +0000604
Greg Claytonf4124de2012-02-21 00:09:25 +0000605 if (exe_ctx.HasThreadScope())
Chris Lattner24943d22010-06-08 16:52:24 +0000606 {
Jim Inghamd82bc6d2012-05-11 23:47:32 +0000607 bool abort_other_plans = false;
Chris Lattner24943d22010-06-08 16:52:24 +0000608
Greg Claytonf4124de2012-02-21 00:09:25 +0000609 Thread *thread = exe_ctx.GetThreadPtr();
610 StackFrameSP frame_sp(thread->GetStackFrameAtIndex (0));
Jim Ingham88e3de22012-05-03 21:19:36 +0000611 ThreadPlan *new_plan = NULL;
Chris Lattner24943d22010-06-08 16:52:24 +0000612
613 if (frame_sp && frame_sp->HasDebugInformation ())
614 {
Greg Clayton8f5fd6b2010-06-12 18:59:55 +0000615 bool avoid_code_without_debug_info = true;
Chris Lattner24943d22010-06-08 16:52:24 +0000616 SymbolContext sc(frame_sp->GetSymbolContext(eSymbolContextEverything));
Jim Inghamf2ca5732012-12-12 19:58:40 +0000617 new_plan = thread->QueueThreadPlanForStepInRange (abort_other_plans,
618 sc.line_entry.range,
619 sc,
620 target_name,
621 stop_other_threads,
622 avoid_code_without_debug_info);
Chris Lattner24943d22010-06-08 16:52:24 +0000623 }
624 else
625 {
Jim Ingham88e3de22012-05-03 21:19:36 +0000626 new_plan = thread->QueueThreadPlanForStepSingleInstruction (false,
627 abort_other_plans,
628 stop_other_threads);
Chris Lattner24943d22010-06-08 16:52:24 +0000629 }
Jim Ingham88e3de22012-05-03 21:19:36 +0000630
631 // This returns an error, we should use it!
632 ResumeNewPlan (exe_ctx, new_plan);
Chris Lattner24943d22010-06-08 16:52:24 +0000633 }
634}
635
636void
637SBThread::StepOut ()
638{
Greg Claytone005f2c2010-11-06 01:53:30 +0000639 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000640
Jim Inghamd0bdddf2012-08-22 21:34:33 +0000641 Mutex::Locker api_locker;
642 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
643
Caroline Tice7826c882010-10-26 03:11:13 +0000644
Greg Clayton90c52142012-01-30 02:53:15 +0000645 if (log)
Greg Claytonf4124de2012-02-21 00:09:25 +0000646 log->Printf ("SBThread(%p)::StepOut ()", exe_ctx.GetThreadPtr());
Greg Clayton90c52142012-01-30 02:53:15 +0000647
Greg Claytonf4124de2012-02-21 00:09:25 +0000648 if (exe_ctx.HasThreadScope())
Chris Lattner24943d22010-06-08 16:52:24 +0000649 {
Jim Inghamd82bc6d2012-05-11 23:47:32 +0000650 bool abort_other_plans = false;
Jim Inghambe0cde92012-09-14 21:07:14 +0000651 bool stop_other_threads = false;
Chris Lattner24943d22010-06-08 16:52:24 +0000652
Greg Claytonf4124de2012-02-21 00:09:25 +0000653 Thread *thread = exe_ctx.GetThreadPtr();
654
Jim Ingham88e3de22012-05-03 21:19:36 +0000655 ThreadPlan *new_plan = thread->QueueThreadPlanForStepOut (abort_other_plans,
656 NULL,
657 false,
658 stop_other_threads,
659 eVoteYes,
660 eVoteNoOpinion,
661 0);
662
663 // This returns an error, we should use it!
664 ResumeNewPlan (exe_ctx, new_plan);
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000665 }
666}
Chris Lattner24943d22010-06-08 16:52:24 +0000667
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000668void
669SBThread::StepOutOfFrame (lldb::SBFrame &sb_frame)
670{
671 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
672
Jim Inghamd0bdddf2012-08-22 21:34:33 +0000673 Mutex::Locker api_locker;
674 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
675
Greg Clayton334d33a2012-01-30 07:41:31 +0000676 StackFrameSP frame_sp (sb_frame.GetFrameSP());
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000677 if (log)
678 {
679 SBStream frame_desc_strm;
680 sb_frame.GetDescription (frame_desc_strm);
Greg Claytonf4124de2012-02-21 00:09:25 +0000681 log->Printf ("SBThread(%p)::StepOutOfFrame (frame = SBFrame(%p): %s)", exe_ctx.GetThreadPtr(), frame_sp.get(), frame_desc_strm.GetData());
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000682 }
683
Greg Claytonf4124de2012-02-21 00:09:25 +0000684 if (exe_ctx.HasThreadScope())
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000685 {
Jim Inghamd82bc6d2012-05-11 23:47:32 +0000686 bool abort_other_plans = false;
Jim Inghambe0cde92012-09-14 21:07:14 +0000687 bool stop_other_threads = false;
Greg Claytonf4124de2012-02-21 00:09:25 +0000688 Thread *thread = exe_ctx.GetThreadPtr();
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000689
Jim Ingham88e3de22012-05-03 21:19:36 +0000690 ThreadPlan *new_plan = thread->QueueThreadPlanForStepOut (abort_other_plans,
691 NULL,
692 false,
693 stop_other_threads,
694 eVoteYes,
695 eVoteNoOpinion,
696 frame_sp->GetFrameIndex());
697
698 // This returns an error, we should use it!
699 ResumeNewPlan (exe_ctx, new_plan);
Chris Lattner24943d22010-06-08 16:52:24 +0000700 }
701}
702
703void
704SBThread::StepInstruction (bool step_over)
705{
Greg Claytone005f2c2010-11-06 01:53:30 +0000706 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000707
Jim Inghamd0bdddf2012-08-22 21:34:33 +0000708 Mutex::Locker api_locker;
709 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
710
Greg Claytonf4124de2012-02-21 00:09:25 +0000711
Caroline Tice7826c882010-10-26 03:11:13 +0000712
Greg Clayton90c52142012-01-30 02:53:15 +0000713 if (log)
Greg Claytonf4124de2012-02-21 00:09:25 +0000714 log->Printf ("SBThread(%p)::StepInstruction (step_over=%i)", exe_ctx.GetThreadPtr(), step_over);
Greg Clayton90c52142012-01-30 02:53:15 +0000715
Greg Claytonf4124de2012-02-21 00:09:25 +0000716 if (exe_ctx.HasThreadScope())
Chris Lattner24943d22010-06-08 16:52:24 +0000717 {
Greg Claytonf4124de2012-02-21 00:09:25 +0000718 Thread *thread = exe_ctx.GetThreadPtr();
Jim Ingham88e3de22012-05-03 21:19:36 +0000719 ThreadPlan *new_plan = thread->QueueThreadPlanForStepSingleInstruction (step_over, true, true);
720
721 // This returns an error, we should use it!
722 ResumeNewPlan (exe_ctx, new_plan);
Chris Lattner24943d22010-06-08 16:52:24 +0000723 }
724}
725
726void
727SBThread::RunToAddress (lldb::addr_t addr)
728{
Greg Claytone005f2c2010-11-06 01:53:30 +0000729 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000730
Jim Inghamd0bdddf2012-08-22 21:34:33 +0000731 Mutex::Locker api_locker;
732 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
733
Caroline Tice7826c882010-10-26 03:11:13 +0000734
Greg Clayton90c52142012-01-30 02:53:15 +0000735 if (log)
Daniel Malea5f35a4b2012-11-29 21:49:15 +0000736 log->Printf ("SBThread(%p)::RunToAddress (addr=0x%" PRIx64 ")", exe_ctx.GetThreadPtr(), addr);
Greg Clayton90c52142012-01-30 02:53:15 +0000737
Greg Claytonf4124de2012-02-21 00:09:25 +0000738 if (exe_ctx.HasThreadScope())
Chris Lattner24943d22010-06-08 16:52:24 +0000739 {
Jim Inghamd82bc6d2012-05-11 23:47:32 +0000740 bool abort_other_plans = false;
Chris Lattner24943d22010-06-08 16:52:24 +0000741 bool stop_other_threads = true;
742
Greg Clayton3508c382012-02-24 01:59:29 +0000743 Address target_addr (addr);
Chris Lattner24943d22010-06-08 16:52:24 +0000744
Greg Claytonf4124de2012-02-21 00:09:25 +0000745 Thread *thread = exe_ctx.GetThreadPtr();
Greg Claytonf4124de2012-02-21 00:09:25 +0000746
Jim Ingham88e3de22012-05-03 21:19:36 +0000747 ThreadPlan *new_plan = thread->QueueThreadPlanForRunToAddress (abort_other_plans, target_addr, stop_other_threads);
748
749 // This returns an error, we should use it!
750 ResumeNewPlan (exe_ctx, new_plan);
Chris Lattner24943d22010-06-08 16:52:24 +0000751 }
Chris Lattner24943d22010-06-08 16:52:24 +0000752}
753
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000754SBError
755SBThread::StepOverUntil (lldb::SBFrame &sb_frame,
756 lldb::SBFileSpec &sb_file_spec,
757 uint32_t line)
758{
759 SBError sb_error;
760 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
761 char path[PATH_MAX];
Greg Clayton90c52142012-01-30 02:53:15 +0000762
Jim Inghamd0bdddf2012-08-22 21:34:33 +0000763 Mutex::Locker api_locker;
764 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
765
Greg Clayton334d33a2012-01-30 07:41:31 +0000766 StackFrameSP frame_sp (sb_frame.GetFrameSP());
767
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000768 if (log)
769 {
770 SBStream frame_desc_strm;
771 sb_frame.GetDescription (frame_desc_strm);
772 sb_file_spec->GetPath (path, sizeof(path));
773 log->Printf ("SBThread(%p)::StepOverUntil (frame = SBFrame(%p): %s, file+line = %s:%u)",
Greg Claytonf4124de2012-02-21 00:09:25 +0000774 exe_ctx.GetThreadPtr(),
Greg Clayton334d33a2012-01-30 07:41:31 +0000775 frame_sp.get(),
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000776 frame_desc_strm.GetData(),
777 path, line);
778 }
Greg Clayton90c52142012-01-30 02:53:15 +0000779
Greg Claytonf4124de2012-02-21 00:09:25 +0000780 if (exe_ctx.HasThreadScope())
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000781 {
Greg Claytonf4124de2012-02-21 00:09:25 +0000782 Target *target = exe_ctx.GetTargetPtr();
Greg Claytonf4124de2012-02-21 00:09:25 +0000783 Thread *thread = exe_ctx.GetThreadPtr();
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000784
785 if (line == 0)
786 {
787 sb_error.SetErrorString("invalid line argument");
788 return sb_error;
789 }
790
Greg Clayton334d33a2012-01-30 07:41:31 +0000791 if (!frame_sp)
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000792 {
Greg Claytonf4124de2012-02-21 00:09:25 +0000793 frame_sp = thread->GetSelectedFrame ();
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000794 if (!frame_sp)
Greg Claytonf4124de2012-02-21 00:09:25 +0000795 frame_sp = thread->GetStackFrameAtIndex (0);
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000796 }
797
798 SymbolContext frame_sc;
799 if (!frame_sp)
800 {
801 sb_error.SetErrorString("no valid frames in thread to step");
802 return sb_error;
803 }
804
805 // If we have a frame, get its line
806 frame_sc = frame_sp->GetSymbolContext (eSymbolContextCompUnit |
807 eSymbolContextFunction |
808 eSymbolContextLineEntry |
809 eSymbolContextSymbol );
810
811 if (frame_sc.comp_unit == NULL)
812 {
813 sb_error.SetErrorStringWithFormat("frame %u doesn't have debug information", frame_sp->GetFrameIndex());
814 return sb_error;
815 }
816
817 FileSpec step_file_spec;
818 if (sb_file_spec.IsValid())
819 {
820 // The file spec passed in was valid, so use it
821 step_file_spec = sb_file_spec.ref();
822 }
823 else
824 {
825 if (frame_sc.line_entry.IsValid())
826 step_file_spec = frame_sc.line_entry.file;
827 else
828 {
829 sb_error.SetErrorString("invalid file argument or no file for frame");
830 return sb_error;
831 }
832 }
833
Jim Inghamb07c62a2011-05-08 00:56:32 +0000834 // Grab the current function, then we will make sure the "until" address is
835 // within the function. We discard addresses that are out of the current
836 // function, and then if there are no addresses remaining, give an appropriate
837 // error message.
838
839 bool all_in_function = true;
840 AddressRange fun_range = frame_sc.function->GetAddressRange();
841
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000842 std::vector<addr_t> step_over_until_addrs;
Jim Inghamd82bc6d2012-05-11 23:47:32 +0000843 const bool abort_other_plans = false;
Jim Ingham52124e72012-09-14 18:57:14 +0000844 const bool stop_other_threads = false;
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000845 const bool check_inlines = true;
846 const bool exact = false;
847
848 SymbolContextList sc_list;
Jim Inghamb07c62a2011-05-08 00:56:32 +0000849 const uint32_t num_matches = frame_sc.comp_unit->ResolveSymbolContext (step_file_spec,
850 line,
851 check_inlines,
852 exact,
853 eSymbolContextLineEntry,
854 sc_list);
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000855 if (num_matches > 0)
856 {
857 SymbolContext sc;
858 for (uint32_t i=0; i<num_matches; ++i)
859 {
860 if (sc_list.GetContextAtIndex(i, sc))
861 {
Jim Inghamb07c62a2011-05-08 00:56:32 +0000862 addr_t step_addr = sc.line_entry.range.GetBaseAddress().GetLoadAddress(target);
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000863 if (step_addr != LLDB_INVALID_ADDRESS)
864 {
Jim Inghamb07c62a2011-05-08 00:56:32 +0000865 if (fun_range.ContainsLoadAddress(step_addr, target))
866 step_over_until_addrs.push_back(step_addr);
867 else
868 all_in_function = false;
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000869 }
870 }
871 }
872 }
Jim Inghamb07c62a2011-05-08 00:56:32 +0000873
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000874 if (step_over_until_addrs.empty())
875 {
Jim Inghamb07c62a2011-05-08 00:56:32 +0000876 if (all_in_function)
877 {
878 step_file_spec.GetPath (path, sizeof(path));
Jason Molenda7e5fa7f2011-09-20 21:44:10 +0000879 sb_error.SetErrorStringWithFormat("No line entries for %s:%u", path, line);
Jim Inghamb07c62a2011-05-08 00:56:32 +0000880 }
881 else
Greg Clayton9c236732011-10-26 00:56:27 +0000882 sb_error.SetErrorString ("step until target not in current function");
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000883 }
884 else
885 {
Jim Ingham88e3de22012-05-03 21:19:36 +0000886 ThreadPlan *new_plan = thread->QueueThreadPlanForStepUntil (abort_other_plans,
887 &step_over_until_addrs[0],
888 step_over_until_addrs.size(),
889 stop_other_threads,
890 frame_sp->GetFrameIndex());
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000891
Jim Ingham88e3de22012-05-03 21:19:36 +0000892 sb_error = ResumeNewPlan (exe_ctx, new_plan);
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000893 }
894 }
895 else
896 {
897 sb_error.SetErrorString("this SBThread object is invalid");
898 }
899 return sb_error;
900}
901
Jim Inghama17a81a2012-09-12 00:40:39 +0000902SBError
Jim Inghamf59388a2012-09-14 02:14:15 +0000903SBThread::ReturnFromFrame (SBFrame &frame, SBValue &return_value)
Jim Inghama17a81a2012-09-12 00:40:39 +0000904{
905 SBError sb_error;
906
907 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
908
909 Mutex::Locker api_locker;
910 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
911
912
913 if (log)
Jim Inghamf59388a2012-09-14 02:14:15 +0000914 log->Printf ("SBThread(%p)::ReturnFromFrame (frame=%d)", exe_ctx.GetThreadPtr(), frame.GetFrameID());
Jim Inghama17a81a2012-09-12 00:40:39 +0000915
916 if (exe_ctx.HasThreadScope())
917 {
918 Thread *thread = exe_ctx.GetThreadPtr();
Jim Inghamf59388a2012-09-14 02:14:15 +0000919 sb_error.SetError (thread->ReturnFromFrame(frame.GetFrameSP(), return_value.GetSP()));
Jim Inghama17a81a2012-09-12 00:40:39 +0000920 }
921
922 return sb_error;
923}
924
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000925
Greg Clayton123db402011-01-12 02:25:42 +0000926bool
927SBThread::Suspend()
928{
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000929 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona894fe72012-04-05 16:12:35 +0000930 ExecutionContext exe_ctx (m_opaque_sp.get());
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000931 bool result = false;
Greg Claytonf4124de2012-02-21 00:09:25 +0000932 if (exe_ctx.HasThreadScope())
Greg Clayton123db402011-01-12 02:25:42 +0000933 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000934 Process::StopLocker stop_locker;
935 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
936 {
937 exe_ctx.GetThreadPtr()->SetResumeState (eStateSuspended);
938 result = true;
939 }
940 else
941 {
942 if (log)
943 log->Printf ("SBThread(%p)::Suspend() => error: process is running", exe_ctx.GetThreadPtr());
944 }
Greg Clayton123db402011-01-12 02:25:42 +0000945 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000946 if (log)
947 log->Printf ("SBThread(%p)::Suspend() => %i", exe_ctx.GetThreadPtr(), result);
948 return result;
Greg Clayton123db402011-01-12 02:25:42 +0000949}
950
951bool
952SBThread::Resume ()
953{
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000954 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona894fe72012-04-05 16:12:35 +0000955 ExecutionContext exe_ctx (m_opaque_sp.get());
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000956 bool result = false;
Greg Claytonf4124de2012-02-21 00:09:25 +0000957 if (exe_ctx.HasThreadScope())
Greg Clayton123db402011-01-12 02:25:42 +0000958 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000959 Process::StopLocker stop_locker;
960 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
961 {
962 exe_ctx.GetThreadPtr()->SetResumeState (eStateRunning);
963 result = true;
964 }
965 else
966 {
967 if (log)
968 log->Printf ("SBThread(%p)::Resume() => error: process is running", exe_ctx.GetThreadPtr());
969 }
Greg Clayton123db402011-01-12 02:25:42 +0000970 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000971 if (log)
972 log->Printf ("SBThread(%p)::Resume() => %i", exe_ctx.GetThreadPtr(), result);
973 return result;
Greg Clayton123db402011-01-12 02:25:42 +0000974}
975
976bool
977SBThread::IsSuspended()
978{
Greg Claytona894fe72012-04-05 16:12:35 +0000979 ExecutionContext exe_ctx (m_opaque_sp.get());
Greg Claytonf4124de2012-02-21 00:09:25 +0000980 if (exe_ctx.HasThreadScope())
981 return exe_ctx.GetThreadPtr()->GetResumeState () == eStateSuspended;
Greg Clayton123db402011-01-12 02:25:42 +0000982 return false;
983}
984
Chris Lattner24943d22010-06-08 16:52:24 +0000985SBProcess
986SBThread::GetProcess ()
987{
Caroline Tice7826c882010-10-26 03:11:13 +0000988
Greg Clayton334d33a2012-01-30 07:41:31 +0000989 SBProcess sb_process;
990 ProcessSP process_sp;
Greg Claytona894fe72012-04-05 16:12:35 +0000991 ExecutionContext exe_ctx (m_opaque_sp.get());
Greg Claytonf4124de2012-02-21 00:09:25 +0000992 if (exe_ctx.HasThreadScope())
Chris Lattner24943d22010-06-08 16:52:24 +0000993 {
994 // Have to go up to the target so we can get a shared pointer to our process...
Greg Claytonf4124de2012-02-21 00:09:25 +0000995 sb_process.SetSP (exe_ctx.GetProcessSP());
Chris Lattner24943d22010-06-08 16:52:24 +0000996 }
Caroline Tice7826c882010-10-26 03:11:13 +0000997
Greg Claytone005f2c2010-11-06 01:53:30 +0000998 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000999 if (log)
1000 {
Greg Clayton1ebdcc72011-01-21 06:11:58 +00001001 SBStream frame_desc_strm;
Greg Clayton334d33a2012-01-30 07:41:31 +00001002 sb_process.GetDescription (frame_desc_strm);
Greg Claytonf4124de2012-02-21 00:09:25 +00001003 log->Printf ("SBThread(%p)::GetProcess () => SBProcess(%p): %s", exe_ctx.GetThreadPtr(),
Greg Clayton334d33a2012-01-30 07:41:31 +00001004 process_sp.get(), frame_desc_strm.GetData());
Caroline Tice7826c882010-10-26 03:11:13 +00001005 }
1006
Greg Clayton334d33a2012-01-30 07:41:31 +00001007 return sb_process;
Chris Lattner24943d22010-06-08 16:52:24 +00001008}
1009
1010uint32_t
1011SBThread::GetNumFrames ()
1012{
Greg Claytone005f2c2010-11-06 01:53:30 +00001013 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001014
Caroline Tice7826c882010-10-26 03:11:13 +00001015 uint32_t num_frames = 0;
Jim Inghamd0bdddf2012-08-22 21:34:33 +00001016 Mutex::Locker api_locker;
1017 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
1018
Greg Claytonf4124de2012-02-21 00:09:25 +00001019 if (exe_ctx.HasThreadScope())
Greg Claytonbdcda462010-12-20 20:49:23 +00001020 {
Greg Claytona894fe72012-04-05 16:12:35 +00001021 Process::StopLocker stop_locker;
1022 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
1023 {
Greg Claytona894fe72012-04-05 16:12:35 +00001024 num_frames = exe_ctx.GetThreadPtr()->GetStackFrameCount();
1025 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001026 else
1027 {
1028 if (log)
1029 log->Printf ("SBThread(%p)::GetNumFrames() => error: process is running", exe_ctx.GetThreadPtr());
1030 }
Greg Claytonbdcda462010-12-20 20:49:23 +00001031 }
Caroline Tice7826c882010-10-26 03:11:13 +00001032
1033 if (log)
Greg Claytonf4124de2012-02-21 00:09:25 +00001034 log->Printf ("SBThread(%p)::GetNumFrames () => %u", exe_ctx.GetThreadPtr(), num_frames);
Caroline Tice7826c882010-10-26 03:11:13 +00001035
1036 return num_frames;
Chris Lattner24943d22010-06-08 16:52:24 +00001037}
1038
1039SBFrame
1040SBThread::GetFrameAtIndex (uint32_t idx)
1041{
Greg Claytone005f2c2010-11-06 01:53:30 +00001042 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001043
Chris Lattner24943d22010-06-08 16:52:24 +00001044 SBFrame sb_frame;
Greg Clayton334d33a2012-01-30 07:41:31 +00001045 StackFrameSP frame_sp;
Jim Inghamd0bdddf2012-08-22 21:34:33 +00001046 Mutex::Locker api_locker;
1047 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
1048
Greg Claytonf4124de2012-02-21 00:09:25 +00001049 if (exe_ctx.HasThreadScope())
Greg Claytonbdcda462010-12-20 20:49:23 +00001050 {
Greg Claytona894fe72012-04-05 16:12:35 +00001051 Process::StopLocker stop_locker;
1052 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
1053 {
Greg Claytona894fe72012-04-05 16:12:35 +00001054 frame_sp = exe_ctx.GetThreadPtr()->GetStackFrameAtIndex (idx);
1055 sb_frame.SetFrameSP (frame_sp);
1056 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001057 else
1058 {
1059 if (log)
1060 log->Printf ("SBThread(%p)::GetFrameAtIndex() => error: process is running", exe_ctx.GetThreadPtr());
1061 }
Greg Claytonbdcda462010-12-20 20:49:23 +00001062 }
Caroline Tice7826c882010-10-26 03:11:13 +00001063
1064 if (log)
1065 {
Greg Clayton1ebdcc72011-01-21 06:11:58 +00001066 SBStream frame_desc_strm;
1067 sb_frame.GetDescription (frame_desc_strm);
Greg Claytona66ba462010-10-30 04:51:46 +00001068 log->Printf ("SBThread(%p)::GetFrameAtIndex (idx=%d) => SBFrame(%p): %s",
Greg Claytonf4124de2012-02-21 00:09:25 +00001069 exe_ctx.GetThreadPtr(), idx, frame_sp.get(), frame_desc_strm.GetData());
Caroline Tice7826c882010-10-26 03:11:13 +00001070 }
1071
Chris Lattner24943d22010-06-08 16:52:24 +00001072 return sb_frame;
1073}
1074
Greg Claytonc5157ec2010-12-17 02:26:24 +00001075lldb::SBFrame
1076SBThread::GetSelectedFrame ()
1077{
1078 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1079
1080 SBFrame sb_frame;
Greg Clayton334d33a2012-01-30 07:41:31 +00001081 StackFrameSP frame_sp;
Jim Inghamd0bdddf2012-08-22 21:34:33 +00001082 Mutex::Locker api_locker;
1083 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
1084
Greg Claytonf4124de2012-02-21 00:09:25 +00001085 if (exe_ctx.HasThreadScope())
Greg Claytonbdcda462010-12-20 20:49:23 +00001086 {
Greg Claytona894fe72012-04-05 16:12:35 +00001087 Process::StopLocker stop_locker;
1088 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
1089 {
Greg Claytona894fe72012-04-05 16:12:35 +00001090 frame_sp = exe_ctx.GetThreadPtr()->GetSelectedFrame ();
1091 sb_frame.SetFrameSP (frame_sp);
1092 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001093 else
1094 {
1095 if (log)
1096 log->Printf ("SBThread(%p)::GetSelectedFrame() => error: process is running", exe_ctx.GetThreadPtr());
1097 }
Greg Claytonbdcda462010-12-20 20:49:23 +00001098 }
Greg Claytonc5157ec2010-12-17 02:26:24 +00001099
1100 if (log)
1101 {
Greg Clayton1ebdcc72011-01-21 06:11:58 +00001102 SBStream frame_desc_strm;
1103 sb_frame.GetDescription (frame_desc_strm);
Greg Claytonc5157ec2010-12-17 02:26:24 +00001104 log->Printf ("SBThread(%p)::GetSelectedFrame () => SBFrame(%p): %s",
Greg Claytonf4124de2012-02-21 00:09:25 +00001105 exe_ctx.GetThreadPtr(), frame_sp.get(), frame_desc_strm.GetData());
Greg Claytonc5157ec2010-12-17 02:26:24 +00001106 }
1107
1108 return sb_frame;
1109}
1110
1111lldb::SBFrame
1112SBThread::SetSelectedFrame (uint32_t idx)
1113{
1114 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1115
1116 SBFrame sb_frame;
Greg Clayton334d33a2012-01-30 07:41:31 +00001117 StackFrameSP frame_sp;
Jim Inghamd0bdddf2012-08-22 21:34:33 +00001118 Mutex::Locker api_locker;
1119 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
1120
Greg Claytonf4124de2012-02-21 00:09:25 +00001121 if (exe_ctx.HasThreadScope())
Greg Claytonc5157ec2010-12-17 02:26:24 +00001122 {
Greg Claytona894fe72012-04-05 16:12:35 +00001123 Process::StopLocker stop_locker;
1124 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
Greg Claytonc5157ec2010-12-17 02:26:24 +00001125 {
Greg Claytona894fe72012-04-05 16:12:35 +00001126 Thread *thread = exe_ctx.GetThreadPtr();
1127 frame_sp = thread->GetStackFrameAtIndex (idx);
1128 if (frame_sp)
1129 {
1130 thread->SetSelectedFrame (frame_sp.get());
1131 sb_frame.SetFrameSP (frame_sp);
1132 }
Greg Claytonc5157ec2010-12-17 02:26:24 +00001133 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001134 else
1135 {
1136 if (log)
1137 log->Printf ("SBThread(%p)::SetSelectedFrame() => error: process is running", exe_ctx.GetThreadPtr());
1138 }
Greg Claytonc5157ec2010-12-17 02:26:24 +00001139 }
1140
1141 if (log)
1142 {
Greg Clayton1ebdcc72011-01-21 06:11:58 +00001143 SBStream frame_desc_strm;
1144 sb_frame.GetDescription (frame_desc_strm);
Greg Claytonc5157ec2010-12-17 02:26:24 +00001145 log->Printf ("SBThread(%p)::SetSelectedFrame (idx=%u) => SBFrame(%p): %s",
Greg Claytonf4124de2012-02-21 00:09:25 +00001146 exe_ctx.GetThreadPtr(), idx, frame_sp.get(), frame_desc_strm.GetData());
Greg Claytonc5157ec2010-12-17 02:26:24 +00001147 }
1148 return sb_frame;
1149}
1150
Jim Ingham94a5d0d2012-10-10 18:32:14 +00001151bool
1152SBThread::EventIsThreadEvent (const SBEvent &event)
1153{
1154 return Thread::ThreadEventData::GetEventDataFromEvent(event.get()) != NULL;
1155}
1156
1157SBFrame
1158SBThread::GetStackFrameFromEvent (const SBEvent &event)
1159{
1160 return Thread::ThreadEventData::GetStackFrameFromEvent (event.get());
1161
1162}
1163
1164SBThread
1165SBThread::GetThreadFromEvent (const SBEvent &event)
1166{
1167 return Thread::ThreadEventData::GetThreadFromEvent (event.get());
1168}
Greg Claytonc5157ec2010-12-17 02:26:24 +00001169
Chris Lattner24943d22010-06-08 16:52:24 +00001170bool
1171SBThread::operator == (const SBThread &rhs) const
1172{
Greg Claytona894fe72012-04-05 16:12:35 +00001173 return m_opaque_sp->GetThreadSP().get() == rhs.m_opaque_sp->GetThreadSP().get();
Chris Lattner24943d22010-06-08 16:52:24 +00001174}
1175
1176bool
1177SBThread::operator != (const SBThread &rhs) const
1178{
Greg Claytona894fe72012-04-05 16:12:35 +00001179 return m_opaque_sp->GetThreadSP().get() != rhs.m_opaque_sp->GetThreadSP().get();
Chris Lattner24943d22010-06-08 16:52:24 +00001180}
Caroline Tice98f930f2010-09-20 05:20:02 +00001181
1182bool
Jim Ingham94a5d0d2012-10-10 18:32:14 +00001183SBThread::GetStatus (SBStream &status) const
1184{
1185 Stream &strm = status.ref();
1186
1187 ExecutionContext exe_ctx (m_opaque_sp.get());
1188 if (exe_ctx.HasThreadScope())
1189 {
1190 exe_ctx.GetThreadPtr()->GetStatus(strm, 0, 1, 1);
1191 }
1192 else
1193 strm.PutCString ("No status");
1194
1195 return true;
1196}
1197
1198bool
Caroline Tice7826c882010-10-26 03:11:13 +00001199SBThread::GetDescription (SBStream &description) const
1200{
Greg Clayton96154be2011-11-13 06:57:31 +00001201 Stream &strm = description.ref();
1202
Greg Claytona894fe72012-04-05 16:12:35 +00001203 ExecutionContext exe_ctx (m_opaque_sp.get());
Greg Claytonf4124de2012-02-21 00:09:25 +00001204 if (exe_ctx.HasThreadScope())
Caroline Tice7826c882010-10-26 03:11:13 +00001205 {
Daniel Malea5f35a4b2012-11-29 21:49:15 +00001206 strm.Printf("SBThread: tid = 0x%4.4" PRIx64, exe_ctx.GetThreadPtr()->GetID());
Caroline Tice7826c882010-10-26 03:11:13 +00001207 }
1208 else
Greg Clayton96154be2011-11-13 06:57:31 +00001209 strm.PutCString ("No value");
Caroline Tice7826c882010-10-26 03:11:13 +00001210
1211 return true;
1212}