blob: 3f3c90415a05ed093f6f8d2991a17654e4284447 [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:
Andrew Kaylor278f16e2012-12-20 23:08:03 +0000154 case eStopReasonThreadExiting:
Greg Claytona894fe72012-04-05 16:12:35 +0000155 // There is no data for these stop reasons.
156 return 0;
157
158 case eStopReasonBreakpoint:
159 {
160 break_id_t site_id = stop_info_sp->GetValue();
161 lldb::BreakpointSiteSP bp_site_sp (exe_ctx.GetProcessPtr()->GetBreakpointSiteList().FindByID (site_id));
162 if (bp_site_sp)
163 return bp_site_sp->GetNumberOfOwners () * 2;
164 else
165 return 0; // Breakpoint must have cleared itself...
166 }
167 break;
168
169 case eStopReasonWatchpoint:
170 return 1;
171
172 case eStopReasonSignal:
173 return 1;
174
175 case eStopReasonException:
176 return 1;
Greg Clayton640dc6b2010-11-18 18:52:36 +0000177 }
Greg Clayton640dc6b2010-11-18 18:52:36 +0000178 }
179 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000180 else
181 {
182 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
183 if (log)
184 log->Printf ("SBThread(%p)::GetStopReasonDataCount() => error: process is running", exe_ctx.GetThreadPtr());
185 }
Greg Clayton640dc6b2010-11-18 18:52:36 +0000186 }
187 return 0;
188}
189
190uint64_t
191SBThread::GetStopReasonDataAtIndex (uint32_t idx)
192{
Jim Inghamd0bdddf2012-08-22 21:34:33 +0000193 Mutex::Locker api_locker;
194 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
195
Greg Claytonf4124de2012-02-21 00:09:25 +0000196 if (exe_ctx.HasThreadScope())
Greg Clayton640dc6b2010-11-18 18:52:36 +0000197 {
Greg Claytona894fe72012-04-05 16:12:35 +0000198 Process::StopLocker stop_locker;
199 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
Greg Clayton640dc6b2010-11-18 18:52:36 +0000200 {
Greg Claytona894fe72012-04-05 16:12:35 +0000201 Thread *thread = exe_ctx.GetThreadPtr();
202 StopInfoSP stop_info_sp = thread->GetStopInfo ();
203 if (stop_info_sp)
204 {
205 StopReason reason = stop_info_sp->GetStopReason();
206 switch (reason)
Greg Clayton640dc6b2010-11-18 18:52:36 +0000207 {
Greg Claytona894fe72012-04-05 16:12:35 +0000208 case eStopReasonInvalid:
209 case eStopReasonNone:
210 case eStopReasonTrace:
Greg Clayton0bce9a22012-12-05 00:16:59 +0000211 case eStopReasonExec:
Greg Claytona894fe72012-04-05 16:12:35 +0000212 case eStopReasonPlanComplete:
Andrew Kaylor278f16e2012-12-20 23:08:03 +0000213 case eStopReasonThreadExiting:
Greg Claytona894fe72012-04-05 16:12:35 +0000214 // There is no data for these stop reasons.
215 return 0;
216
217 case eStopReasonBreakpoint:
Greg Clayton640dc6b2010-11-18 18:52:36 +0000218 {
Greg Claytona894fe72012-04-05 16:12:35 +0000219 break_id_t site_id = stop_info_sp->GetValue();
220 lldb::BreakpointSiteSP bp_site_sp (exe_ctx.GetProcessPtr()->GetBreakpointSiteList().FindByID (site_id));
221 if (bp_site_sp)
Greg Clayton640dc6b2010-11-18 18:52:36 +0000222 {
Greg Claytona894fe72012-04-05 16:12:35 +0000223 uint32_t bp_index = idx / 2;
224 BreakpointLocationSP bp_loc_sp (bp_site_sp->GetOwnerAtIndex (bp_index));
225 if (bp_loc_sp)
Greg Clayton640dc6b2010-11-18 18:52:36 +0000226 {
Greg Claytona894fe72012-04-05 16:12:35 +0000227 if (bp_index & 1)
228 {
229 // Odd idx, return the breakpoint location ID
230 return bp_loc_sp->GetID();
231 }
232 else
233 {
234 // Even idx, return the breakpoint ID
235 return bp_loc_sp->GetBreakpoint().GetID();
236 }
Greg Clayton640dc6b2010-11-18 18:52:36 +0000237 }
238 }
Greg Claytona894fe72012-04-05 16:12:35 +0000239 return LLDB_INVALID_BREAK_ID;
Greg Clayton640dc6b2010-11-18 18:52:36 +0000240 }
Greg Claytona894fe72012-04-05 16:12:35 +0000241 break;
242
243 case eStopReasonWatchpoint:
244 return stop_info_sp->GetValue();
245
246 case eStopReasonSignal:
247 return stop_info_sp->GetValue();
248
249 case eStopReasonException:
250 return stop_info_sp->GetValue();
Greg Clayton640dc6b2010-11-18 18:52:36 +0000251 }
Greg Clayton640dc6b2010-11-18 18:52:36 +0000252 }
253 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000254 else
255 {
256 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
257 if (log)
258 log->Printf ("SBThread(%p)::GetStopReasonDataAtIndex() => error: process is running", exe_ctx.GetThreadPtr());
259 }
Greg Clayton640dc6b2010-11-18 18:52:36 +0000260 }
261 return 0;
262}
263
264size_t
Chris Lattner24943d22010-06-08 16:52:24 +0000265SBThread::GetStopDescription (char *dst, size_t dst_len)
266{
Greg Claytone005f2c2010-11-06 01:53:30 +0000267 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000268
Jim Inghamd0bdddf2012-08-22 21:34:33 +0000269 Mutex::Locker api_locker;
270 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
271
Greg Claytonf4124de2012-02-21 00:09:25 +0000272 if (exe_ctx.HasThreadScope())
Chris Lattner24943d22010-06-08 16:52:24 +0000273 {
Greg Claytona894fe72012-04-05 16:12:35 +0000274 Process::StopLocker stop_locker;
275 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
Chris Lattner24943d22010-06-08 16:52:24 +0000276 {
Greg Claytona894fe72012-04-05 16:12:35 +0000277
Greg Claytona894fe72012-04-05 16:12:35 +0000278 StopInfoSP stop_info_sp = exe_ctx.GetThreadPtr()->GetStopInfo ();
279 if (stop_info_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000280 {
Greg Claytona894fe72012-04-05 16:12:35 +0000281 const char *stop_desc = stop_info_sp->GetDescription();
282 if (stop_desc)
Chris Lattner24943d22010-06-08 16:52:24 +0000283 {
Caroline Tice7826c882010-10-26 03:11:13 +0000284 if (log)
Greg Claytona894fe72012-04-05 16:12:35 +0000285 log->Printf ("SBThread(%p)::GetStopDescription (dst, dst_len) => \"%s\"",
Greg Claytonf4124de2012-02-21 00:09:25 +0000286 exe_ctx.GetThreadPtr(), stop_desc);
Chris Lattner24943d22010-06-08 16:52:24 +0000287 if (dst)
Greg Claytona894fe72012-04-05 16:12:35 +0000288 return ::snprintf (dst, dst_len, "%s", stop_desc);
289 else
290 {
291 // NULL dst passed in, return the length needed to contain the description
292 return ::strlen (stop_desc) + 1; // Include the NULL byte for size
293 }
294 }
295 else
296 {
297 size_t stop_desc_len = 0;
298 switch (stop_info_sp->GetStopReason())
299 {
300 case eStopReasonTrace:
301 case eStopReasonPlanComplete:
302 {
303 static char trace_desc[] = "step";
304 stop_desc = trace_desc;
305 stop_desc_len = sizeof(trace_desc); // Include the NULL byte for size
306 }
307 break;
Chris Lattner24943d22010-06-08 16:52:24 +0000308
Greg Claytona894fe72012-04-05 16:12:35 +0000309 case eStopReasonBreakpoint:
310 {
311 static char bp_desc[] = "breakpoint hit";
312 stop_desc = bp_desc;
313 stop_desc_len = sizeof(bp_desc); // Include the NULL byte for size
314 }
315 break;
316
317 case eStopReasonWatchpoint:
318 {
319 static char wp_desc[] = "watchpoint hit";
320 stop_desc = wp_desc;
321 stop_desc_len = sizeof(wp_desc); // Include the NULL byte for size
322 }
323 break;
324
325 case eStopReasonSignal:
326 {
327 stop_desc = exe_ctx.GetProcessPtr()->GetUnixSignals ().GetSignalAsCString (stop_info_sp->GetValue());
328 if (stop_desc == NULL || stop_desc[0] == '\0')
329 {
330 static char signal_desc[] = "signal";
331 stop_desc = signal_desc;
332 stop_desc_len = sizeof(signal_desc); // Include the NULL byte for size
333 }
334 }
335 break;
336
337 case eStopReasonException:
338 {
339 char exc_desc[] = "exception";
340 stop_desc = exc_desc;
341 stop_desc_len = sizeof(exc_desc); // Include the NULL byte for size
342 }
343 break;
344
Greg Clayton0bce9a22012-12-05 00:16:59 +0000345 case eStopReasonExec:
346 {
347 char exc_desc[] = "exec";
348 stop_desc = exc_desc;
349 stop_desc_len = sizeof(exc_desc); // Include the NULL byte for size
350 }
351 break;
352
Andrew Kaylor278f16e2012-12-20 23:08:03 +0000353 case eStopReasonThreadExiting:
354 {
355 char limbo_desc[] = "thread exiting";
356 stop_desc = limbo_desc;
357 stop_desc_len = sizeof(limbo_desc);
358 }
359 break;
Greg Claytona894fe72012-04-05 16:12:35 +0000360 default:
361 break;
362 }
363
364 if (stop_desc && stop_desc[0])
365 {
366 if (log)
367 log->Printf ("SBThread(%p)::GetStopDescription (dst, dst_len) => '%s'",
368 exe_ctx.GetThreadPtr(), stop_desc);
369
370 if (dst)
371 return ::snprintf (dst, dst_len, "%s", stop_desc) + 1; // Include the NULL byte
372
373 if (stop_desc_len == 0)
374 stop_desc_len = ::strlen (stop_desc) + 1; // Include the NULL byte
375
376 return stop_desc_len;
377 }
Chris Lattner24943d22010-06-08 16:52:24 +0000378 }
379 }
380 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000381 else
382 {
383 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
384 if (log)
385 log->Printf ("SBThread(%p)::GetStopDescription() => error: process is running", exe_ctx.GetThreadPtr());
386 }
Chris Lattner24943d22010-06-08 16:52:24 +0000387 }
388 if (dst)
389 *dst = 0;
390 return 0;
391}
392
Jim Ingham1586d972011-12-17 01:35:57 +0000393SBValue
394SBThread::GetStopReturnValue ()
395{
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000396 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Jim Ingham1586d972011-12-17 01:35:57 +0000397 ValueObjectSP return_valobj_sp;
Jim Inghamd0bdddf2012-08-22 21:34:33 +0000398 Mutex::Locker api_locker;
399 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
400
Greg Claytonf4124de2012-02-21 00:09:25 +0000401 if (exe_ctx.HasThreadScope())
Jim Ingham1586d972011-12-17 01:35:57 +0000402 {
Greg Claytona894fe72012-04-05 16:12:35 +0000403 Process::StopLocker stop_locker;
404 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
Jim Ingham1586d972011-12-17 01:35:57 +0000405 {
Greg Claytona894fe72012-04-05 16:12:35 +0000406 StopInfoSP stop_info_sp = exe_ctx.GetThreadPtr()->GetStopInfo ();
407 if (stop_info_sp)
408 {
409 return_valobj_sp = StopInfo::GetReturnValueObject (stop_info_sp);
410 }
Jim Ingham1586d972011-12-17 01:35:57 +0000411 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000412 else
413 {
414 if (log)
415 log->Printf ("SBThread(%p)::GetStopReturnValue() => error: process is running", exe_ctx.GetThreadPtr());
416 }
Jim Ingham1586d972011-12-17 01:35:57 +0000417 }
418
Jim Ingham1586d972011-12-17 01:35:57 +0000419 if (log)
Greg Claytonf4124de2012-02-21 00:09:25 +0000420 log->Printf ("SBThread(%p)::GetStopReturnValue () => %s", exe_ctx.GetThreadPtr(),
Jim Ingham1586d972011-12-17 01:35:57 +0000421 return_valobj_sp.get()
422 ? return_valobj_sp->GetValueAsCString()
423 : "<no return value>");
424
425 return SBValue (return_valobj_sp);
426}
427
Chris Lattner24943d22010-06-08 16:52:24 +0000428void
429SBThread::SetThread (const ThreadSP& lldb_object_sp)
430{
Greg Claytona894fe72012-04-05 16:12:35 +0000431 m_opaque_sp->SetThreadSP (lldb_object_sp);
Chris Lattner24943d22010-06-08 16:52:24 +0000432}
433
434
435lldb::tid_t
436SBThread::GetThreadID () 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)
Greg Claytonf4124de2012-02-21 00:09:25 +0000440 return thread_sp->GetID();
441 return LLDB_INVALID_THREAD_ID;
Chris Lattner24943d22010-06-08 16:52:24 +0000442}
443
444uint32_t
445SBThread::GetIndexID () const
446{
Greg Claytona894fe72012-04-05 16:12:35 +0000447 ThreadSP thread_sp(m_opaque_sp->GetThreadSP());
Greg Clayton90c52142012-01-30 02:53:15 +0000448 if (thread_sp)
449 return thread_sp->GetIndexID();
Chris Lattner24943d22010-06-08 16:52:24 +0000450 return LLDB_INVALID_INDEX32;
451}
Greg Claytonf4124de2012-02-21 00:09:25 +0000452
Chris Lattner24943d22010-06-08 16:52:24 +0000453const char *
454SBThread::GetName () const
455{
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000456 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000457 const char *name = NULL;
Jim Inghamd0bdddf2012-08-22 21:34:33 +0000458 Mutex::Locker api_locker;
459 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
460
Greg Claytonf4124de2012-02-21 00:09:25 +0000461 if (exe_ctx.HasThreadScope())
Greg Claytonbdcda462010-12-20 20:49:23 +0000462 {
Greg Claytona894fe72012-04-05 16:12:35 +0000463 Process::StopLocker stop_locker;
464 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
465 {
Greg Claytona894fe72012-04-05 16:12:35 +0000466 name = exe_ctx.GetThreadPtr()->GetName();
467 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000468 else
469 {
470 if (log)
471 log->Printf ("SBThread(%p)::GetName() => error: process is running", exe_ctx.GetThreadPtr());
472 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000473 }
Greg Claytona66ba462010-10-30 04:51:46 +0000474
Caroline Tice7826c882010-10-26 03:11:13 +0000475 if (log)
Greg Claytonf4124de2012-02-21 00:09:25 +0000476 log->Printf ("SBThread(%p)::GetName () => %s", exe_ctx.GetThreadPtr(), name ? name : "NULL");
Caroline Tice7826c882010-10-26 03:11:13 +0000477
Greg Claytona66ba462010-10-30 04:51:46 +0000478 return name;
Chris Lattner24943d22010-06-08 16:52:24 +0000479}
480
481const char *
482SBThread::GetQueueName () const
483{
Greg Claytona66ba462010-10-30 04:51:46 +0000484 const char *name = NULL;
Jim Inghamd0bdddf2012-08-22 21:34:33 +0000485 Mutex::Locker api_locker;
486 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
487
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000488 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytonf4124de2012-02-21 00:09:25 +0000489 if (exe_ctx.HasThreadScope())
Greg Claytonbdcda462010-12-20 20:49:23 +0000490 {
Greg Claytona894fe72012-04-05 16:12:35 +0000491 Process::StopLocker stop_locker;
492 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
493 {
Greg Claytona894fe72012-04-05 16:12:35 +0000494 name = exe_ctx.GetThreadPtr()->GetQueueName();
495 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000496 else
497 {
498 if (log)
499 log->Printf ("SBThread(%p)::GetQueueName() => error: process is running", exe_ctx.GetThreadPtr());
500 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000501 }
Greg Claytona66ba462010-10-30 04:51:46 +0000502
Caroline Tice7826c882010-10-26 03:11:13 +0000503 if (log)
Greg Claytonf4124de2012-02-21 00:09:25 +0000504 log->Printf ("SBThread(%p)::GetQueueName () => %s", exe_ctx.GetThreadPtr(), name ? name : "NULL");
Caroline Tice7826c882010-10-26 03:11:13 +0000505
Greg Claytona66ba462010-10-30 04:51:46 +0000506 return name;
Chris Lattner24943d22010-06-08 16:52:24 +0000507}
508
Jim Ingham88e3de22012-05-03 21:19:36 +0000509SBError
510SBThread::ResumeNewPlan (ExecutionContext &exe_ctx, ThreadPlan *new_plan)
511{
512 SBError sb_error;
513
514 Process *process = exe_ctx.GetProcessPtr();
515 if (!process)
516 {
517 sb_error.SetErrorString("No process in SBThread::ResumeNewPlan");
518 return sb_error;
519 }
520
521 Thread *thread = exe_ctx.GetThreadPtr();
522 if (!thread)
523 {
524 sb_error.SetErrorString("No thread in SBThread::ResumeNewPlan");
525 return sb_error;
526 }
527
528 // User level plans should be Master Plans so they can be interrupted, other plans executed, and
529 // then a "continue" will resume the plan.
530 if (new_plan != NULL)
531 {
532 new_plan->SetIsMasterPlan(true);
533 new_plan->SetOkayToDiscard(false);
534 }
535
536 // Why do we need to set the current thread by ID here???
537 process->GetThreadList().SetSelectedThreadByID (thread->GetID());
538 sb_error.ref() = process->Resume();
539
540 if (sb_error.Success())
541 {
542 // If we are doing synchronous mode, then wait for the
543 // process to stop yet again!
544 if (process->GetTarget().GetDebugger().GetAsyncExecution () == false)
545 process->WaitForProcessToStop (NULL);
546 }
547
548 return sb_error;
549}
Chris Lattner24943d22010-06-08 16:52:24 +0000550
551void
Chris Lattner24943d22010-06-08 16:52:24 +0000552SBThread::StepOver (lldb::RunMode stop_other_threads)
553{
Greg Claytone005f2c2010-11-06 01:53:30 +0000554 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000555
Jim Inghamd0bdddf2012-08-22 21:34:33 +0000556 Mutex::Locker api_locker;
557 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
558
Caroline Tice7826c882010-10-26 03:11:13 +0000559
Greg Clayton90c52142012-01-30 02:53:15 +0000560 if (log)
Greg Claytonf4124de2012-02-21 00:09:25 +0000561 log->Printf ("SBThread(%p)::StepOver (stop_other_threads='%s')", exe_ctx.GetThreadPtr(),
Greg Clayton90c52142012-01-30 02:53:15 +0000562 Thread::RunModeAsCString (stop_other_threads));
563
Greg Claytonf4124de2012-02-21 00:09:25 +0000564 if (exe_ctx.HasThreadScope())
Chris Lattner24943d22010-06-08 16:52:24 +0000565 {
Greg Claytonf4124de2012-02-21 00:09:25 +0000566 Thread *thread = exe_ctx.GetThreadPtr();
Jim Inghamd82bc6d2012-05-11 23:47:32 +0000567 bool abort_other_plans = false;
Greg Claytonf4124de2012-02-21 00:09:25 +0000568 StackFrameSP frame_sp(thread->GetStackFrameAtIndex (0));
Jim Ingham88e3de22012-05-03 21:19:36 +0000569 ThreadPlan *new_plan = NULL;
Chris Lattner24943d22010-06-08 16:52:24 +0000570
571 if (frame_sp)
572 {
573 if (frame_sp->HasDebugInformation ())
574 {
575 SymbolContext sc(frame_sp->GetSymbolContext(eSymbolContextEverything));
Jim Inghamf2ca5732012-12-12 19:58:40 +0000576 new_plan = thread->QueueThreadPlanForStepOverRange (abort_other_plans,
577 sc.line_entry.range,
578 sc,
579 stop_other_threads);
Chris Lattner24943d22010-06-08 16:52:24 +0000580 }
581 else
582 {
Jim Ingham88e3de22012-05-03 21:19:36 +0000583 new_plan = thread->QueueThreadPlanForStepSingleInstruction (true,
584 abort_other_plans,
585 stop_other_threads);
Chris Lattner24943d22010-06-08 16:52:24 +0000586 }
587 }
588
Jim Ingham88e3de22012-05-03 21:19:36 +0000589 // This returns an error, we should use it!
590 ResumeNewPlan (exe_ctx, new_plan);
Chris Lattner24943d22010-06-08 16:52:24 +0000591 }
592}
593
594void
595SBThread::StepInto (lldb::RunMode stop_other_threads)
596{
Jim Inghamf2ca5732012-12-12 19:58:40 +0000597 StepInto (NULL, stop_other_threads);
598}
599
600void
601SBThread::StepInto (const char *target_name, lldb::RunMode stop_other_threads)
602{
Greg Claytone005f2c2010-11-06 01:53:30 +0000603 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000604
Jim Inghamd0bdddf2012-08-22 21:34:33 +0000605 Mutex::Locker api_locker;
606 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
Greg Clayton90c52142012-01-30 02:53:15 +0000607
608 if (log)
Jim Inghamf2ca5732012-12-12 19:58:40 +0000609 log->Printf ("SBThread(%p)::StepInto (target_name='%s', stop_other_threads='%s')",
610 exe_ctx.GetThreadPtr(),
611 target_name? target_name: "<NULL>",
Greg Clayton90c52142012-01-30 02:53:15 +0000612 Thread::RunModeAsCString (stop_other_threads));
Jim Inghamf2ca5732012-12-12 19:58:40 +0000613
Greg Claytonf4124de2012-02-21 00:09:25 +0000614 if (exe_ctx.HasThreadScope())
Chris Lattner24943d22010-06-08 16:52:24 +0000615 {
Jim Inghamd82bc6d2012-05-11 23:47:32 +0000616 bool abort_other_plans = false;
Chris Lattner24943d22010-06-08 16:52:24 +0000617
Greg Claytonf4124de2012-02-21 00:09:25 +0000618 Thread *thread = exe_ctx.GetThreadPtr();
619 StackFrameSP frame_sp(thread->GetStackFrameAtIndex (0));
Jim Ingham88e3de22012-05-03 21:19:36 +0000620 ThreadPlan *new_plan = NULL;
Chris Lattner24943d22010-06-08 16:52:24 +0000621
622 if (frame_sp && frame_sp->HasDebugInformation ())
623 {
Greg Clayton8f5fd6b2010-06-12 18:59:55 +0000624 bool avoid_code_without_debug_info = true;
Chris Lattner24943d22010-06-08 16:52:24 +0000625 SymbolContext sc(frame_sp->GetSymbolContext(eSymbolContextEverything));
Jim Inghamf2ca5732012-12-12 19:58:40 +0000626 new_plan = thread->QueueThreadPlanForStepInRange (abort_other_plans,
627 sc.line_entry.range,
628 sc,
629 target_name,
630 stop_other_threads,
631 avoid_code_without_debug_info);
Chris Lattner24943d22010-06-08 16:52:24 +0000632 }
633 else
634 {
Jim Ingham88e3de22012-05-03 21:19:36 +0000635 new_plan = thread->QueueThreadPlanForStepSingleInstruction (false,
636 abort_other_plans,
637 stop_other_threads);
Chris Lattner24943d22010-06-08 16:52:24 +0000638 }
Jim Ingham88e3de22012-05-03 21:19:36 +0000639
640 // This returns an error, we should use it!
641 ResumeNewPlan (exe_ctx, new_plan);
Chris Lattner24943d22010-06-08 16:52:24 +0000642 }
643}
644
645void
646SBThread::StepOut ()
647{
Greg Claytone005f2c2010-11-06 01:53:30 +0000648 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000649
Jim Inghamd0bdddf2012-08-22 21:34:33 +0000650 Mutex::Locker api_locker;
651 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
652
Caroline Tice7826c882010-10-26 03:11:13 +0000653
Greg Clayton90c52142012-01-30 02:53:15 +0000654 if (log)
Greg Claytonf4124de2012-02-21 00:09:25 +0000655 log->Printf ("SBThread(%p)::StepOut ()", exe_ctx.GetThreadPtr());
Greg Clayton90c52142012-01-30 02:53:15 +0000656
Greg Claytonf4124de2012-02-21 00:09:25 +0000657 if (exe_ctx.HasThreadScope())
Chris Lattner24943d22010-06-08 16:52:24 +0000658 {
Jim Inghamd82bc6d2012-05-11 23:47:32 +0000659 bool abort_other_plans = false;
Jim Inghambe0cde92012-09-14 21:07:14 +0000660 bool stop_other_threads = false;
Chris Lattner24943d22010-06-08 16:52:24 +0000661
Greg Claytonf4124de2012-02-21 00:09:25 +0000662 Thread *thread = exe_ctx.GetThreadPtr();
663
Jim Ingham88e3de22012-05-03 21:19:36 +0000664 ThreadPlan *new_plan = thread->QueueThreadPlanForStepOut (abort_other_plans,
665 NULL,
666 false,
667 stop_other_threads,
668 eVoteYes,
669 eVoteNoOpinion,
670 0);
671
672 // This returns an error, we should use it!
673 ResumeNewPlan (exe_ctx, new_plan);
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000674 }
675}
Chris Lattner24943d22010-06-08 16:52:24 +0000676
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000677void
678SBThread::StepOutOfFrame (lldb::SBFrame &sb_frame)
679{
680 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
681
Jim Inghamd0bdddf2012-08-22 21:34:33 +0000682 Mutex::Locker api_locker;
683 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
684
Greg Clayton334d33a2012-01-30 07:41:31 +0000685 StackFrameSP frame_sp (sb_frame.GetFrameSP());
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000686 if (log)
687 {
688 SBStream frame_desc_strm;
689 sb_frame.GetDescription (frame_desc_strm);
Greg Claytonf4124de2012-02-21 00:09:25 +0000690 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 +0000691 }
692
Greg Claytonf4124de2012-02-21 00:09:25 +0000693 if (exe_ctx.HasThreadScope())
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000694 {
Jim Inghamd82bc6d2012-05-11 23:47:32 +0000695 bool abort_other_plans = false;
Jim Inghambe0cde92012-09-14 21:07:14 +0000696 bool stop_other_threads = false;
Greg Claytonf4124de2012-02-21 00:09:25 +0000697 Thread *thread = exe_ctx.GetThreadPtr();
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000698
Jim Ingham88e3de22012-05-03 21:19:36 +0000699 ThreadPlan *new_plan = thread->QueueThreadPlanForStepOut (abort_other_plans,
700 NULL,
701 false,
702 stop_other_threads,
703 eVoteYes,
704 eVoteNoOpinion,
705 frame_sp->GetFrameIndex());
706
707 // This returns an error, we should use it!
708 ResumeNewPlan (exe_ctx, new_plan);
Chris Lattner24943d22010-06-08 16:52:24 +0000709 }
710}
711
712void
713SBThread::StepInstruction (bool step_over)
714{
Greg Claytone005f2c2010-11-06 01:53:30 +0000715 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000716
Jim Inghamd0bdddf2012-08-22 21:34:33 +0000717 Mutex::Locker api_locker;
718 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
719
Greg Claytonf4124de2012-02-21 00:09:25 +0000720
Caroline Tice7826c882010-10-26 03:11:13 +0000721
Greg Clayton90c52142012-01-30 02:53:15 +0000722 if (log)
Greg Claytonf4124de2012-02-21 00:09:25 +0000723 log->Printf ("SBThread(%p)::StepInstruction (step_over=%i)", exe_ctx.GetThreadPtr(), step_over);
Greg Clayton90c52142012-01-30 02:53:15 +0000724
Greg Claytonf4124de2012-02-21 00:09:25 +0000725 if (exe_ctx.HasThreadScope())
Chris Lattner24943d22010-06-08 16:52:24 +0000726 {
Greg Claytonf4124de2012-02-21 00:09:25 +0000727 Thread *thread = exe_ctx.GetThreadPtr();
Jim Ingham88e3de22012-05-03 21:19:36 +0000728 ThreadPlan *new_plan = thread->QueueThreadPlanForStepSingleInstruction (step_over, true, true);
729
730 // This returns an error, we should use it!
731 ResumeNewPlan (exe_ctx, new_plan);
Chris Lattner24943d22010-06-08 16:52:24 +0000732 }
733}
734
735void
736SBThread::RunToAddress (lldb::addr_t addr)
737{
Greg Claytone005f2c2010-11-06 01:53:30 +0000738 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000739
Jim Inghamd0bdddf2012-08-22 21:34:33 +0000740 Mutex::Locker api_locker;
741 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
742
Caroline Tice7826c882010-10-26 03:11:13 +0000743
Greg Clayton90c52142012-01-30 02:53:15 +0000744 if (log)
Daniel Malea5f35a4b2012-11-29 21:49:15 +0000745 log->Printf ("SBThread(%p)::RunToAddress (addr=0x%" PRIx64 ")", exe_ctx.GetThreadPtr(), addr);
Greg Clayton90c52142012-01-30 02:53:15 +0000746
Greg Claytonf4124de2012-02-21 00:09:25 +0000747 if (exe_ctx.HasThreadScope())
Chris Lattner24943d22010-06-08 16:52:24 +0000748 {
Jim Inghamd82bc6d2012-05-11 23:47:32 +0000749 bool abort_other_plans = false;
Chris Lattner24943d22010-06-08 16:52:24 +0000750 bool stop_other_threads = true;
751
Greg Clayton3508c382012-02-24 01:59:29 +0000752 Address target_addr (addr);
Chris Lattner24943d22010-06-08 16:52:24 +0000753
Greg Claytonf4124de2012-02-21 00:09:25 +0000754 Thread *thread = exe_ctx.GetThreadPtr();
Greg Claytonf4124de2012-02-21 00:09:25 +0000755
Jim Ingham88e3de22012-05-03 21:19:36 +0000756 ThreadPlan *new_plan = thread->QueueThreadPlanForRunToAddress (abort_other_plans, target_addr, stop_other_threads);
757
758 // This returns an error, we should use it!
759 ResumeNewPlan (exe_ctx, new_plan);
Chris Lattner24943d22010-06-08 16:52:24 +0000760 }
Chris Lattner24943d22010-06-08 16:52:24 +0000761}
762
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000763SBError
764SBThread::StepOverUntil (lldb::SBFrame &sb_frame,
765 lldb::SBFileSpec &sb_file_spec,
766 uint32_t line)
767{
768 SBError sb_error;
769 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
770 char path[PATH_MAX];
Greg Clayton90c52142012-01-30 02:53:15 +0000771
Jim Inghamd0bdddf2012-08-22 21:34:33 +0000772 Mutex::Locker api_locker;
773 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
774
Greg Clayton334d33a2012-01-30 07:41:31 +0000775 StackFrameSP frame_sp (sb_frame.GetFrameSP());
776
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000777 if (log)
778 {
779 SBStream frame_desc_strm;
780 sb_frame.GetDescription (frame_desc_strm);
781 sb_file_spec->GetPath (path, sizeof(path));
782 log->Printf ("SBThread(%p)::StepOverUntil (frame = SBFrame(%p): %s, file+line = %s:%u)",
Greg Claytonf4124de2012-02-21 00:09:25 +0000783 exe_ctx.GetThreadPtr(),
Greg Clayton334d33a2012-01-30 07:41:31 +0000784 frame_sp.get(),
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000785 frame_desc_strm.GetData(),
786 path, line);
787 }
Greg Clayton90c52142012-01-30 02:53:15 +0000788
Greg Claytonf4124de2012-02-21 00:09:25 +0000789 if (exe_ctx.HasThreadScope())
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000790 {
Greg Claytonf4124de2012-02-21 00:09:25 +0000791 Target *target = exe_ctx.GetTargetPtr();
Greg Claytonf4124de2012-02-21 00:09:25 +0000792 Thread *thread = exe_ctx.GetThreadPtr();
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000793
794 if (line == 0)
795 {
796 sb_error.SetErrorString("invalid line argument");
797 return sb_error;
798 }
799
Greg Clayton334d33a2012-01-30 07:41:31 +0000800 if (!frame_sp)
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000801 {
Greg Claytonf4124de2012-02-21 00:09:25 +0000802 frame_sp = thread->GetSelectedFrame ();
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000803 if (!frame_sp)
Greg Claytonf4124de2012-02-21 00:09:25 +0000804 frame_sp = thread->GetStackFrameAtIndex (0);
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000805 }
806
807 SymbolContext frame_sc;
808 if (!frame_sp)
809 {
810 sb_error.SetErrorString("no valid frames in thread to step");
811 return sb_error;
812 }
813
814 // If we have a frame, get its line
815 frame_sc = frame_sp->GetSymbolContext (eSymbolContextCompUnit |
816 eSymbolContextFunction |
817 eSymbolContextLineEntry |
818 eSymbolContextSymbol );
819
820 if (frame_sc.comp_unit == NULL)
821 {
822 sb_error.SetErrorStringWithFormat("frame %u doesn't have debug information", frame_sp->GetFrameIndex());
823 return sb_error;
824 }
825
826 FileSpec step_file_spec;
827 if (sb_file_spec.IsValid())
828 {
829 // The file spec passed in was valid, so use it
830 step_file_spec = sb_file_spec.ref();
831 }
832 else
833 {
834 if (frame_sc.line_entry.IsValid())
835 step_file_spec = frame_sc.line_entry.file;
836 else
837 {
838 sb_error.SetErrorString("invalid file argument or no file for frame");
839 return sb_error;
840 }
841 }
842
Jim Inghamb07c62a2011-05-08 00:56:32 +0000843 // Grab the current function, then we will make sure the "until" address is
844 // within the function. We discard addresses that are out of the current
845 // function, and then if there are no addresses remaining, give an appropriate
846 // error message.
847
848 bool all_in_function = true;
849 AddressRange fun_range = frame_sc.function->GetAddressRange();
850
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000851 std::vector<addr_t> step_over_until_addrs;
Jim Inghamd82bc6d2012-05-11 23:47:32 +0000852 const bool abort_other_plans = false;
Jim Ingham52124e72012-09-14 18:57:14 +0000853 const bool stop_other_threads = false;
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000854 const bool check_inlines = true;
855 const bool exact = false;
856
857 SymbolContextList sc_list;
Jim Inghamb07c62a2011-05-08 00:56:32 +0000858 const uint32_t num_matches = frame_sc.comp_unit->ResolveSymbolContext (step_file_spec,
859 line,
860 check_inlines,
861 exact,
862 eSymbolContextLineEntry,
863 sc_list);
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000864 if (num_matches > 0)
865 {
866 SymbolContext sc;
867 for (uint32_t i=0; i<num_matches; ++i)
868 {
869 if (sc_list.GetContextAtIndex(i, sc))
870 {
Jim Inghamb07c62a2011-05-08 00:56:32 +0000871 addr_t step_addr = sc.line_entry.range.GetBaseAddress().GetLoadAddress(target);
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000872 if (step_addr != LLDB_INVALID_ADDRESS)
873 {
Jim Inghamb07c62a2011-05-08 00:56:32 +0000874 if (fun_range.ContainsLoadAddress(step_addr, target))
875 step_over_until_addrs.push_back(step_addr);
876 else
877 all_in_function = false;
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000878 }
879 }
880 }
881 }
Jim Inghamb07c62a2011-05-08 00:56:32 +0000882
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000883 if (step_over_until_addrs.empty())
884 {
Jim Inghamb07c62a2011-05-08 00:56:32 +0000885 if (all_in_function)
886 {
887 step_file_spec.GetPath (path, sizeof(path));
Jason Molenda7e5fa7f2011-09-20 21:44:10 +0000888 sb_error.SetErrorStringWithFormat("No line entries for %s:%u", path, line);
Jim Inghamb07c62a2011-05-08 00:56:32 +0000889 }
890 else
Greg Clayton9c236732011-10-26 00:56:27 +0000891 sb_error.SetErrorString ("step until target not in current function");
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000892 }
893 else
894 {
Jim Ingham88e3de22012-05-03 21:19:36 +0000895 ThreadPlan *new_plan = thread->QueueThreadPlanForStepUntil (abort_other_plans,
896 &step_over_until_addrs[0],
897 step_over_until_addrs.size(),
898 stop_other_threads,
899 frame_sp->GetFrameIndex());
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000900
Jim Ingham88e3de22012-05-03 21:19:36 +0000901 sb_error = ResumeNewPlan (exe_ctx, new_plan);
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000902 }
903 }
904 else
905 {
906 sb_error.SetErrorString("this SBThread object is invalid");
907 }
908 return sb_error;
909}
910
Jim Inghama17a81a2012-09-12 00:40:39 +0000911SBError
Jim Inghamf59388a2012-09-14 02:14:15 +0000912SBThread::ReturnFromFrame (SBFrame &frame, SBValue &return_value)
Jim Inghama17a81a2012-09-12 00:40:39 +0000913{
914 SBError sb_error;
915
916 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
917
918 Mutex::Locker api_locker;
919 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
920
921
922 if (log)
Jim Inghamf59388a2012-09-14 02:14:15 +0000923 log->Printf ("SBThread(%p)::ReturnFromFrame (frame=%d)", exe_ctx.GetThreadPtr(), frame.GetFrameID());
Jim Inghama17a81a2012-09-12 00:40:39 +0000924
925 if (exe_ctx.HasThreadScope())
926 {
927 Thread *thread = exe_ctx.GetThreadPtr();
Jim Inghamf59388a2012-09-14 02:14:15 +0000928 sb_error.SetError (thread->ReturnFromFrame(frame.GetFrameSP(), return_value.GetSP()));
Jim Inghama17a81a2012-09-12 00:40:39 +0000929 }
930
931 return sb_error;
932}
933
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000934
Greg Clayton123db402011-01-12 02:25:42 +0000935bool
936SBThread::Suspend()
937{
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000938 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona894fe72012-04-05 16:12:35 +0000939 ExecutionContext exe_ctx (m_opaque_sp.get());
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000940 bool result = false;
Greg Claytonf4124de2012-02-21 00:09:25 +0000941 if (exe_ctx.HasThreadScope())
Greg Clayton123db402011-01-12 02:25:42 +0000942 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000943 Process::StopLocker stop_locker;
944 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
945 {
946 exe_ctx.GetThreadPtr()->SetResumeState (eStateSuspended);
947 result = true;
948 }
949 else
950 {
951 if (log)
952 log->Printf ("SBThread(%p)::Suspend() => error: process is running", exe_ctx.GetThreadPtr());
953 }
Greg Clayton123db402011-01-12 02:25:42 +0000954 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000955 if (log)
956 log->Printf ("SBThread(%p)::Suspend() => %i", exe_ctx.GetThreadPtr(), result);
957 return result;
Greg Clayton123db402011-01-12 02:25:42 +0000958}
959
960bool
961SBThread::Resume ()
962{
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000963 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona894fe72012-04-05 16:12:35 +0000964 ExecutionContext exe_ctx (m_opaque_sp.get());
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000965 bool result = false;
Greg Claytonf4124de2012-02-21 00:09:25 +0000966 if (exe_ctx.HasThreadScope())
Greg Clayton123db402011-01-12 02:25:42 +0000967 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000968 Process::StopLocker stop_locker;
969 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
970 {
971 exe_ctx.GetThreadPtr()->SetResumeState (eStateRunning);
972 result = true;
973 }
974 else
975 {
976 if (log)
977 log->Printf ("SBThread(%p)::Resume() => error: process is running", exe_ctx.GetThreadPtr());
978 }
Greg Clayton123db402011-01-12 02:25:42 +0000979 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000980 if (log)
981 log->Printf ("SBThread(%p)::Resume() => %i", exe_ctx.GetThreadPtr(), result);
982 return result;
Greg Clayton123db402011-01-12 02:25:42 +0000983}
984
985bool
986SBThread::IsSuspended()
987{
Greg Claytona894fe72012-04-05 16:12:35 +0000988 ExecutionContext exe_ctx (m_opaque_sp.get());
Greg Claytonf4124de2012-02-21 00:09:25 +0000989 if (exe_ctx.HasThreadScope())
990 return exe_ctx.GetThreadPtr()->GetResumeState () == eStateSuspended;
Greg Clayton123db402011-01-12 02:25:42 +0000991 return false;
992}
993
Chris Lattner24943d22010-06-08 16:52:24 +0000994SBProcess
995SBThread::GetProcess ()
996{
Caroline Tice7826c882010-10-26 03:11:13 +0000997
Greg Clayton334d33a2012-01-30 07:41:31 +0000998 SBProcess sb_process;
999 ProcessSP process_sp;
Greg Claytona894fe72012-04-05 16:12:35 +00001000 ExecutionContext exe_ctx (m_opaque_sp.get());
Greg Claytonf4124de2012-02-21 00:09:25 +00001001 if (exe_ctx.HasThreadScope())
Chris Lattner24943d22010-06-08 16:52:24 +00001002 {
1003 // Have to go up to the target so we can get a shared pointer to our process...
Greg Claytonf4124de2012-02-21 00:09:25 +00001004 sb_process.SetSP (exe_ctx.GetProcessSP());
Chris Lattner24943d22010-06-08 16:52:24 +00001005 }
Caroline Tice7826c882010-10-26 03:11:13 +00001006
Greg Claytone005f2c2010-11-06 01:53:30 +00001007 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001008 if (log)
1009 {
Greg Clayton1ebdcc72011-01-21 06:11:58 +00001010 SBStream frame_desc_strm;
Greg Clayton334d33a2012-01-30 07:41:31 +00001011 sb_process.GetDescription (frame_desc_strm);
Greg Claytonf4124de2012-02-21 00:09:25 +00001012 log->Printf ("SBThread(%p)::GetProcess () => SBProcess(%p): %s", exe_ctx.GetThreadPtr(),
Greg Clayton334d33a2012-01-30 07:41:31 +00001013 process_sp.get(), frame_desc_strm.GetData());
Caroline Tice7826c882010-10-26 03:11:13 +00001014 }
1015
Greg Clayton334d33a2012-01-30 07:41:31 +00001016 return sb_process;
Chris Lattner24943d22010-06-08 16:52:24 +00001017}
1018
1019uint32_t
1020SBThread::GetNumFrames ()
1021{
Greg Claytone005f2c2010-11-06 01:53:30 +00001022 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001023
Caroline Tice7826c882010-10-26 03:11:13 +00001024 uint32_t num_frames = 0;
Jim Inghamd0bdddf2012-08-22 21:34:33 +00001025 Mutex::Locker api_locker;
1026 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
1027
Greg Claytonf4124de2012-02-21 00:09:25 +00001028 if (exe_ctx.HasThreadScope())
Greg Claytonbdcda462010-12-20 20:49:23 +00001029 {
Greg Claytona894fe72012-04-05 16:12:35 +00001030 Process::StopLocker stop_locker;
1031 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
1032 {
Greg Claytona894fe72012-04-05 16:12:35 +00001033 num_frames = exe_ctx.GetThreadPtr()->GetStackFrameCount();
1034 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001035 else
1036 {
1037 if (log)
1038 log->Printf ("SBThread(%p)::GetNumFrames() => error: process is running", exe_ctx.GetThreadPtr());
1039 }
Greg Claytonbdcda462010-12-20 20:49:23 +00001040 }
Caroline Tice7826c882010-10-26 03:11:13 +00001041
1042 if (log)
Greg Claytonf4124de2012-02-21 00:09:25 +00001043 log->Printf ("SBThread(%p)::GetNumFrames () => %u", exe_ctx.GetThreadPtr(), num_frames);
Caroline Tice7826c882010-10-26 03:11:13 +00001044
1045 return num_frames;
Chris Lattner24943d22010-06-08 16:52:24 +00001046}
1047
1048SBFrame
1049SBThread::GetFrameAtIndex (uint32_t idx)
1050{
Greg Claytone005f2c2010-11-06 01:53:30 +00001051 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001052
Chris Lattner24943d22010-06-08 16:52:24 +00001053 SBFrame sb_frame;
Greg Clayton334d33a2012-01-30 07:41:31 +00001054 StackFrameSP frame_sp;
Jim Inghamd0bdddf2012-08-22 21:34:33 +00001055 Mutex::Locker api_locker;
1056 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
1057
Greg Claytonf4124de2012-02-21 00:09:25 +00001058 if (exe_ctx.HasThreadScope())
Greg Claytonbdcda462010-12-20 20:49:23 +00001059 {
Greg Claytona894fe72012-04-05 16:12:35 +00001060 Process::StopLocker stop_locker;
1061 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
1062 {
Greg Claytona894fe72012-04-05 16:12:35 +00001063 frame_sp = exe_ctx.GetThreadPtr()->GetStackFrameAtIndex (idx);
1064 sb_frame.SetFrameSP (frame_sp);
1065 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001066 else
1067 {
1068 if (log)
1069 log->Printf ("SBThread(%p)::GetFrameAtIndex() => error: process is running", exe_ctx.GetThreadPtr());
1070 }
Greg Claytonbdcda462010-12-20 20:49:23 +00001071 }
Caroline Tice7826c882010-10-26 03:11:13 +00001072
1073 if (log)
1074 {
Greg Clayton1ebdcc72011-01-21 06:11:58 +00001075 SBStream frame_desc_strm;
1076 sb_frame.GetDescription (frame_desc_strm);
Greg Claytona66ba462010-10-30 04:51:46 +00001077 log->Printf ("SBThread(%p)::GetFrameAtIndex (idx=%d) => SBFrame(%p): %s",
Greg Claytonf4124de2012-02-21 00:09:25 +00001078 exe_ctx.GetThreadPtr(), idx, frame_sp.get(), frame_desc_strm.GetData());
Caroline Tice7826c882010-10-26 03:11:13 +00001079 }
1080
Chris Lattner24943d22010-06-08 16:52:24 +00001081 return sb_frame;
1082}
1083
Greg Claytonc5157ec2010-12-17 02:26:24 +00001084lldb::SBFrame
1085SBThread::GetSelectedFrame ()
1086{
1087 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1088
1089 SBFrame sb_frame;
Greg Clayton334d33a2012-01-30 07:41:31 +00001090 StackFrameSP frame_sp;
Jim Inghamd0bdddf2012-08-22 21:34:33 +00001091 Mutex::Locker api_locker;
1092 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
1093
Greg Claytonf4124de2012-02-21 00:09:25 +00001094 if (exe_ctx.HasThreadScope())
Greg Claytonbdcda462010-12-20 20:49:23 +00001095 {
Greg Claytona894fe72012-04-05 16:12:35 +00001096 Process::StopLocker stop_locker;
1097 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
1098 {
Greg Claytona894fe72012-04-05 16:12:35 +00001099 frame_sp = exe_ctx.GetThreadPtr()->GetSelectedFrame ();
1100 sb_frame.SetFrameSP (frame_sp);
1101 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001102 else
1103 {
1104 if (log)
1105 log->Printf ("SBThread(%p)::GetSelectedFrame() => error: process is running", exe_ctx.GetThreadPtr());
1106 }
Greg Claytonbdcda462010-12-20 20:49:23 +00001107 }
Greg Claytonc5157ec2010-12-17 02:26:24 +00001108
1109 if (log)
1110 {
Greg Clayton1ebdcc72011-01-21 06:11:58 +00001111 SBStream frame_desc_strm;
1112 sb_frame.GetDescription (frame_desc_strm);
Greg Claytonc5157ec2010-12-17 02:26:24 +00001113 log->Printf ("SBThread(%p)::GetSelectedFrame () => SBFrame(%p): %s",
Greg Claytonf4124de2012-02-21 00:09:25 +00001114 exe_ctx.GetThreadPtr(), frame_sp.get(), frame_desc_strm.GetData());
Greg Claytonc5157ec2010-12-17 02:26:24 +00001115 }
1116
1117 return sb_frame;
1118}
1119
1120lldb::SBFrame
1121SBThread::SetSelectedFrame (uint32_t idx)
1122{
1123 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1124
1125 SBFrame sb_frame;
Greg Clayton334d33a2012-01-30 07:41:31 +00001126 StackFrameSP frame_sp;
Jim Inghamd0bdddf2012-08-22 21:34:33 +00001127 Mutex::Locker api_locker;
1128 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
1129
Greg Claytonf4124de2012-02-21 00:09:25 +00001130 if (exe_ctx.HasThreadScope())
Greg Claytonc5157ec2010-12-17 02:26:24 +00001131 {
Greg Claytona894fe72012-04-05 16:12:35 +00001132 Process::StopLocker stop_locker;
1133 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
Greg Claytonc5157ec2010-12-17 02:26:24 +00001134 {
Greg Claytona894fe72012-04-05 16:12:35 +00001135 Thread *thread = exe_ctx.GetThreadPtr();
1136 frame_sp = thread->GetStackFrameAtIndex (idx);
1137 if (frame_sp)
1138 {
1139 thread->SetSelectedFrame (frame_sp.get());
1140 sb_frame.SetFrameSP (frame_sp);
1141 }
Greg Claytonc5157ec2010-12-17 02:26:24 +00001142 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001143 else
1144 {
1145 if (log)
1146 log->Printf ("SBThread(%p)::SetSelectedFrame() => error: process is running", exe_ctx.GetThreadPtr());
1147 }
Greg Claytonc5157ec2010-12-17 02:26:24 +00001148 }
1149
1150 if (log)
1151 {
Greg Clayton1ebdcc72011-01-21 06:11:58 +00001152 SBStream frame_desc_strm;
1153 sb_frame.GetDescription (frame_desc_strm);
Greg Claytonc5157ec2010-12-17 02:26:24 +00001154 log->Printf ("SBThread(%p)::SetSelectedFrame (idx=%u) => SBFrame(%p): %s",
Greg Claytonf4124de2012-02-21 00:09:25 +00001155 exe_ctx.GetThreadPtr(), idx, frame_sp.get(), frame_desc_strm.GetData());
Greg Claytonc5157ec2010-12-17 02:26:24 +00001156 }
1157 return sb_frame;
1158}
1159
Jim Ingham94a5d0d2012-10-10 18:32:14 +00001160bool
1161SBThread::EventIsThreadEvent (const SBEvent &event)
1162{
1163 return Thread::ThreadEventData::GetEventDataFromEvent(event.get()) != NULL;
1164}
1165
1166SBFrame
1167SBThread::GetStackFrameFromEvent (const SBEvent &event)
1168{
1169 return Thread::ThreadEventData::GetStackFrameFromEvent (event.get());
1170
1171}
1172
1173SBThread
1174SBThread::GetThreadFromEvent (const SBEvent &event)
1175{
1176 return Thread::ThreadEventData::GetThreadFromEvent (event.get());
1177}
Greg Claytonc5157ec2010-12-17 02:26:24 +00001178
Chris Lattner24943d22010-06-08 16:52:24 +00001179bool
1180SBThread::operator == (const SBThread &rhs) const
1181{
Greg Claytona894fe72012-04-05 16:12:35 +00001182 return m_opaque_sp->GetThreadSP().get() == rhs.m_opaque_sp->GetThreadSP().get();
Chris Lattner24943d22010-06-08 16:52:24 +00001183}
1184
1185bool
1186SBThread::operator != (const SBThread &rhs) const
1187{
Greg Claytona894fe72012-04-05 16:12:35 +00001188 return m_opaque_sp->GetThreadSP().get() != rhs.m_opaque_sp->GetThreadSP().get();
Chris Lattner24943d22010-06-08 16:52:24 +00001189}
Caroline Tice98f930f2010-09-20 05:20:02 +00001190
1191bool
Jim Ingham94a5d0d2012-10-10 18:32:14 +00001192SBThread::GetStatus (SBStream &status) const
1193{
1194 Stream &strm = status.ref();
1195
1196 ExecutionContext exe_ctx (m_opaque_sp.get());
1197 if (exe_ctx.HasThreadScope())
1198 {
1199 exe_ctx.GetThreadPtr()->GetStatus(strm, 0, 1, 1);
1200 }
1201 else
1202 strm.PutCString ("No status");
1203
1204 return true;
1205}
1206
1207bool
Caroline Tice7826c882010-10-26 03:11:13 +00001208SBThread::GetDescription (SBStream &description) const
1209{
Greg Clayton96154be2011-11-13 06:57:31 +00001210 Stream &strm = description.ref();
1211
Greg Claytona894fe72012-04-05 16:12:35 +00001212 ExecutionContext exe_ctx (m_opaque_sp.get());
Greg Claytonf4124de2012-02-21 00:09:25 +00001213 if (exe_ctx.HasThreadScope())
Caroline Tice7826c882010-10-26 03:11:13 +00001214 {
Daniel Malea5f35a4b2012-11-29 21:49:15 +00001215 strm.Printf("SBThread: tid = 0x%4.4" PRIx64, exe_ctx.GetThreadPtr()->GetID());
Caroline Tice7826c882010-10-26 03:11:13 +00001216 }
1217 else
Greg Clayton96154be2011-11-13 06:57:31 +00001218 strm.PutCString ("No value");
Caroline Tice7826c882010-10-26 03:11:13 +00001219
1220 return true;
1221}