blob: f895a3d40d1b260b858ae211143c0e3db1ee8a88 [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
Eli Friedman7a62c8b2010-06-09 07:44:37 +000010#include "lldb/API/SBThread.h"
Chris Lattner24943d22010-06-08 16:52:24 +000011
12#include "lldb/API/SBSymbolContext.h"
13#include "lldb/API/SBFileSpec.h"
Caroline Tice98f930f2010-09-20 05:20:02 +000014#include "lldb/API/SBStream.h"
Greg Clayton640dc6b2010-11-18 18:52:36 +000015#include "lldb/Breakpoint/BreakpointLocation.h"
Greg Clayton63094e02010-06-23 01:19:29 +000016#include "lldb/Core/Debugger.h"
Chris Lattner24943d22010-06-08 16:52:24 +000017#include "lldb/Core/Stream.h"
18#include "lldb/Core/StreamFile.h"
Greg Clayton63094e02010-06-23 01:19:29 +000019#include "lldb/Interpreter/CommandInterpreter.h"
Chris Lattner24943d22010-06-08 16:52:24 +000020#include "lldb/Target/Thread.h"
21#include "lldb/Target/Process.h"
22#include "lldb/Symbol/SymbolContext.h"
23#include "lldb/Symbol/CompileUnit.h"
Greg Clayton643ee732010-08-04 01:40:35 +000024#include "lldb/Target/StopInfo.h"
Chris Lattner24943d22010-06-08 16:52:24 +000025#include "lldb/Target/Target.h"
26#include "lldb/Target/ThreadPlan.h"
Chris Lattner24943d22010-06-08 16:52:24 +000027#include "lldb/Target/ThreadPlanStepInstruction.h"
28#include "lldb/Target/ThreadPlanStepOut.h"
29#include "lldb/Target/ThreadPlanStepRange.h"
30#include "lldb/Target/ThreadPlanStepInRange.h"
31
32
Eli Friedman7a62c8b2010-06-09 07:44:37 +000033#include "lldb/API/SBAddress.h"
Eli Friedman7a62c8b2010-06-09 07:44:37 +000034#include "lldb/API/SBDebugger.h"
Jim Ingham94a5d0d2012-10-10 18:32:14 +000035#include "lldb/API/SBEvent.h"
Jim Ingham1586d972011-12-17 01:35:57 +000036#include "lldb/API/SBFrame.h"
Eli Friedman7a62c8b2010-06-09 07:44:37 +000037#include "lldb/API/SBProcess.h"
Jim Ingham1586d972011-12-17 01:35:57 +000038#include "lldb/API/SBValue.h"
Chris Lattner24943d22010-06-08 16:52:24 +000039
40using namespace lldb;
41using namespace lldb_private;
42
Jim Ingham94a5d0d2012-10-10 18:32:14 +000043const char *
44SBThread::GetBroadcasterClassName ()
45{
46 return Thread::GetStaticBroadcasterClass().AsCString();
47}
48
Greg Clayton49ce6822010-10-31 03:01:06 +000049//----------------------------------------------------------------------
50// Constructors
51//----------------------------------------------------------------------
Chris Lattner24943d22010-06-08 16:52:24 +000052SBThread::SBThread () :
Greg Claytona894fe72012-04-05 16:12:35 +000053 m_opaque_sp (new ExecutionContextRef())
Chris Lattner24943d22010-06-08 16:52:24 +000054{
55}
56
Chris Lattner24943d22010-06-08 16:52:24 +000057SBThread::SBThread (const ThreadSP& lldb_object_sp) :
Greg Claytona894fe72012-04-05 16:12:35 +000058 m_opaque_sp (new ExecutionContextRef(lldb_object_sp))
Chris Lattner24943d22010-06-08 16:52:24 +000059{
60}
61
Greg Clayton1b284412010-10-30 18:26:59 +000062SBThread::SBThread (const SBThread &rhs) :
Greg Claytona894fe72012-04-05 16:12:35 +000063 m_opaque_sp (new ExecutionContextRef(*rhs.m_opaque_sp))
Chris Lattner24943d22010-06-08 16:52:24 +000064{
Greg Claytona894fe72012-04-05 16:12:35 +000065
Chris Lattner24943d22010-06-08 16:52:24 +000066}
67
68//----------------------------------------------------------------------
Greg Clayton49ce6822010-10-31 03:01:06 +000069// Assignment operator
70//----------------------------------------------------------------------
71
72const lldb::SBThread &
73SBThread::operator = (const SBThread &rhs)
74{
75 if (this != &rhs)
Greg Claytona894fe72012-04-05 16:12:35 +000076 *m_opaque_sp = *rhs.m_opaque_sp;
Greg Clayton49ce6822010-10-31 03:01:06 +000077 return *this;
78}
79
80//----------------------------------------------------------------------
Chris Lattner24943d22010-06-08 16:52:24 +000081// Destructor
82//----------------------------------------------------------------------
83SBThread::~SBThread()
84{
85}
86
87bool
88SBThread::IsValid() const
89{
Greg Claytona894fe72012-04-05 16:12:35 +000090 return m_opaque_sp->GetThreadSP().get() != NULL;
Chris Lattner24943d22010-06-08 16:52:24 +000091}
92
Greg Clayton43490d12010-07-30 20:12:55 +000093void
94SBThread::Clear ()
95{
Greg Claytona894fe72012-04-05 16:12:35 +000096 m_opaque_sp->Clear();
Greg Clayton43490d12010-07-30 20:12:55 +000097}
98
99
Chris Lattner24943d22010-06-08 16:52:24 +0000100StopReason
101SBThread::GetStopReason()
102{
Greg Claytone005f2c2010-11-06 01:53:30 +0000103 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000104
Caroline Tice7826c882010-10-26 03:11:13 +0000105 StopReason reason = eStopReasonInvalid;
Jim Inghamd0bdddf2012-08-22 21:34:33 +0000106 Mutex::Locker api_locker;
107 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
108
Greg Claytonf4124de2012-02-21 00:09:25 +0000109 if (exe_ctx.HasThreadScope())
Chris Lattner24943d22010-06-08 16:52:24 +0000110 {
Greg Claytona894fe72012-04-05 16:12:35 +0000111 Process::StopLocker stop_locker;
112 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
113 {
Greg Clayton3acaa922012-09-25 02:40:06 +0000114 return exe_ctx.GetThreadPtr()->GetStopReason();
Greg Claytona894fe72012-04-05 16:12:35 +0000115 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000116 else
117 {
118 if (log)
119 log->Printf ("SBThread(%p)::GetStopReason() => error: process is running", exe_ctx.GetThreadPtr());
120 }
Chris Lattner24943d22010-06-08 16:52:24 +0000121 }
Caroline Tice7826c882010-10-26 03:11:13 +0000122
123 if (log)
Greg Claytonf4124de2012-02-21 00:09:25 +0000124 log->Printf ("SBThread(%p)::GetStopReason () => %s", exe_ctx.GetThreadPtr(),
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000125 Thread::StopReasonAsCString (reason));
Caroline Tice7826c882010-10-26 03:11:13 +0000126
127 return reason;
Chris Lattner24943d22010-06-08 16:52:24 +0000128}
129
130size_t
Greg Clayton640dc6b2010-11-18 18:52:36 +0000131SBThread::GetStopReasonDataCount ()
132{
Jim Inghamd0bdddf2012-08-22 21:34:33 +0000133 Mutex::Locker api_locker;
134 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
135
Greg Claytonf4124de2012-02-21 00:09:25 +0000136 if (exe_ctx.HasThreadScope())
Greg Clayton640dc6b2010-11-18 18:52:36 +0000137 {
Greg Claytona894fe72012-04-05 16:12:35 +0000138 Process::StopLocker stop_locker;
139 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
Greg Clayton640dc6b2010-11-18 18:52:36 +0000140 {
Greg Claytona894fe72012-04-05 16:12:35 +0000141 StopInfoSP stop_info_sp = exe_ctx.GetThreadPtr()->GetStopInfo ();
142 if (stop_info_sp)
Greg Clayton640dc6b2010-11-18 18:52:36 +0000143 {
Greg Claytona894fe72012-04-05 16:12:35 +0000144 StopReason reason = stop_info_sp->GetStopReason();
145 switch (reason)
Greg Clayton640dc6b2010-11-18 18:52:36 +0000146 {
Greg Claytona894fe72012-04-05 16:12:35 +0000147 case eStopReasonInvalid:
148 case eStopReasonNone:
149 case eStopReasonTrace:
150 case eStopReasonPlanComplete:
151 // There is no data for these stop reasons.
152 return 0;
153
154 case eStopReasonBreakpoint:
155 {
156 break_id_t site_id = stop_info_sp->GetValue();
157 lldb::BreakpointSiteSP bp_site_sp (exe_ctx.GetProcessPtr()->GetBreakpointSiteList().FindByID (site_id));
158 if (bp_site_sp)
159 return bp_site_sp->GetNumberOfOwners () * 2;
160 else
161 return 0; // Breakpoint must have cleared itself...
162 }
163 break;
164
165 case eStopReasonWatchpoint:
166 return 1;
167
168 case eStopReasonSignal:
169 return 1;
170
171 case eStopReasonException:
172 return 1;
Greg Clayton640dc6b2010-11-18 18:52:36 +0000173 }
Greg Clayton640dc6b2010-11-18 18:52:36 +0000174 }
175 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000176 else
177 {
178 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
179 if (log)
180 log->Printf ("SBThread(%p)::GetStopReasonDataCount() => error: process is running", exe_ctx.GetThreadPtr());
181 }
Greg Clayton640dc6b2010-11-18 18:52:36 +0000182 }
183 return 0;
184}
185
186uint64_t
187SBThread::GetStopReasonDataAtIndex (uint32_t idx)
188{
Jim Inghamd0bdddf2012-08-22 21:34:33 +0000189 Mutex::Locker api_locker;
190 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
191
Greg Claytonf4124de2012-02-21 00:09:25 +0000192 if (exe_ctx.HasThreadScope())
Greg Clayton640dc6b2010-11-18 18:52:36 +0000193 {
Greg Claytona894fe72012-04-05 16:12:35 +0000194 Process::StopLocker stop_locker;
195 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
Greg Clayton640dc6b2010-11-18 18:52:36 +0000196 {
Greg Claytona894fe72012-04-05 16:12:35 +0000197 Thread *thread = exe_ctx.GetThreadPtr();
198 StopInfoSP stop_info_sp = thread->GetStopInfo ();
199 if (stop_info_sp)
200 {
201 StopReason reason = stop_info_sp->GetStopReason();
202 switch (reason)
Greg Clayton640dc6b2010-11-18 18:52:36 +0000203 {
Greg Claytona894fe72012-04-05 16:12:35 +0000204 case eStopReasonInvalid:
205 case eStopReasonNone:
206 case eStopReasonTrace:
207 case eStopReasonPlanComplete:
208 // There is no data for these stop reasons.
209 return 0;
210
211 case eStopReasonBreakpoint:
Greg Clayton640dc6b2010-11-18 18:52:36 +0000212 {
Greg Claytona894fe72012-04-05 16:12:35 +0000213 break_id_t site_id = stop_info_sp->GetValue();
214 lldb::BreakpointSiteSP bp_site_sp (exe_ctx.GetProcessPtr()->GetBreakpointSiteList().FindByID (site_id));
215 if (bp_site_sp)
Greg Clayton640dc6b2010-11-18 18:52:36 +0000216 {
Greg Claytona894fe72012-04-05 16:12:35 +0000217 uint32_t bp_index = idx / 2;
218 BreakpointLocationSP bp_loc_sp (bp_site_sp->GetOwnerAtIndex (bp_index));
219 if (bp_loc_sp)
Greg Clayton640dc6b2010-11-18 18:52:36 +0000220 {
Greg Claytona894fe72012-04-05 16:12:35 +0000221 if (bp_index & 1)
222 {
223 // Odd idx, return the breakpoint location ID
224 return bp_loc_sp->GetID();
225 }
226 else
227 {
228 // Even idx, return the breakpoint ID
229 return bp_loc_sp->GetBreakpoint().GetID();
230 }
Greg Clayton640dc6b2010-11-18 18:52:36 +0000231 }
232 }
Greg Claytona894fe72012-04-05 16:12:35 +0000233 return LLDB_INVALID_BREAK_ID;
Greg Clayton640dc6b2010-11-18 18:52:36 +0000234 }
Greg Claytona894fe72012-04-05 16:12:35 +0000235 break;
236
237 case eStopReasonWatchpoint:
238 return stop_info_sp->GetValue();
239
240 case eStopReasonSignal:
241 return stop_info_sp->GetValue();
242
243 case eStopReasonException:
244 return stop_info_sp->GetValue();
Greg Clayton640dc6b2010-11-18 18:52:36 +0000245 }
Greg Clayton640dc6b2010-11-18 18:52:36 +0000246 }
247 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000248 else
249 {
250 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
251 if (log)
252 log->Printf ("SBThread(%p)::GetStopReasonDataAtIndex() => error: process is running", exe_ctx.GetThreadPtr());
253 }
Greg Clayton640dc6b2010-11-18 18:52:36 +0000254 }
255 return 0;
256}
257
258size_t
Chris Lattner24943d22010-06-08 16:52:24 +0000259SBThread::GetStopDescription (char *dst, size_t dst_len)
260{
Greg Claytone005f2c2010-11-06 01:53:30 +0000261 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000262
Jim Inghamd0bdddf2012-08-22 21:34:33 +0000263 Mutex::Locker api_locker;
264 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
265
Greg Claytonf4124de2012-02-21 00:09:25 +0000266 if (exe_ctx.HasThreadScope())
Chris Lattner24943d22010-06-08 16:52:24 +0000267 {
Greg Claytona894fe72012-04-05 16:12:35 +0000268 Process::StopLocker stop_locker;
269 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
Chris Lattner24943d22010-06-08 16:52:24 +0000270 {
Greg Claytona894fe72012-04-05 16:12:35 +0000271
Greg Claytona894fe72012-04-05 16:12:35 +0000272 StopInfoSP stop_info_sp = exe_ctx.GetThreadPtr()->GetStopInfo ();
273 if (stop_info_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000274 {
Greg Claytona894fe72012-04-05 16:12:35 +0000275 const char *stop_desc = stop_info_sp->GetDescription();
276 if (stop_desc)
Chris Lattner24943d22010-06-08 16:52:24 +0000277 {
Caroline Tice7826c882010-10-26 03:11:13 +0000278 if (log)
Greg Claytona894fe72012-04-05 16:12:35 +0000279 log->Printf ("SBThread(%p)::GetStopDescription (dst, dst_len) => \"%s\"",
Greg Claytonf4124de2012-02-21 00:09:25 +0000280 exe_ctx.GetThreadPtr(), stop_desc);
Chris Lattner24943d22010-06-08 16:52:24 +0000281 if (dst)
Greg Claytona894fe72012-04-05 16:12:35 +0000282 return ::snprintf (dst, dst_len, "%s", stop_desc);
283 else
284 {
285 // NULL dst passed in, return the length needed to contain the description
286 return ::strlen (stop_desc) + 1; // Include the NULL byte for size
287 }
288 }
289 else
290 {
291 size_t stop_desc_len = 0;
292 switch (stop_info_sp->GetStopReason())
293 {
294 case eStopReasonTrace:
295 case eStopReasonPlanComplete:
296 {
297 static char trace_desc[] = "step";
298 stop_desc = trace_desc;
299 stop_desc_len = sizeof(trace_desc); // Include the NULL byte for size
300 }
301 break;
Chris Lattner24943d22010-06-08 16:52:24 +0000302
Greg Claytona894fe72012-04-05 16:12:35 +0000303 case eStopReasonBreakpoint:
304 {
305 static char bp_desc[] = "breakpoint hit";
306 stop_desc = bp_desc;
307 stop_desc_len = sizeof(bp_desc); // Include the NULL byte for size
308 }
309 break;
310
311 case eStopReasonWatchpoint:
312 {
313 static char wp_desc[] = "watchpoint hit";
314 stop_desc = wp_desc;
315 stop_desc_len = sizeof(wp_desc); // Include the NULL byte for size
316 }
317 break;
318
319 case eStopReasonSignal:
320 {
321 stop_desc = exe_ctx.GetProcessPtr()->GetUnixSignals ().GetSignalAsCString (stop_info_sp->GetValue());
322 if (stop_desc == NULL || stop_desc[0] == '\0')
323 {
324 static char signal_desc[] = "signal";
325 stop_desc = signal_desc;
326 stop_desc_len = sizeof(signal_desc); // Include the NULL byte for size
327 }
328 }
329 break;
330
331 case eStopReasonException:
332 {
333 char exc_desc[] = "exception";
334 stop_desc = exc_desc;
335 stop_desc_len = sizeof(exc_desc); // Include the NULL byte for size
336 }
337 break;
338
339 default:
340 break;
341 }
342
343 if (stop_desc && stop_desc[0])
344 {
345 if (log)
346 log->Printf ("SBThread(%p)::GetStopDescription (dst, dst_len) => '%s'",
347 exe_ctx.GetThreadPtr(), stop_desc);
348
349 if (dst)
350 return ::snprintf (dst, dst_len, "%s", stop_desc) + 1; // Include the NULL byte
351
352 if (stop_desc_len == 0)
353 stop_desc_len = ::strlen (stop_desc) + 1; // Include the NULL byte
354
355 return stop_desc_len;
356 }
Chris Lattner24943d22010-06-08 16:52:24 +0000357 }
358 }
359 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000360 else
361 {
362 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
363 if (log)
364 log->Printf ("SBThread(%p)::GetStopDescription() => error: process is running", exe_ctx.GetThreadPtr());
365 }
Chris Lattner24943d22010-06-08 16:52:24 +0000366 }
367 if (dst)
368 *dst = 0;
369 return 0;
370}
371
Jim Ingham1586d972011-12-17 01:35:57 +0000372SBValue
373SBThread::GetStopReturnValue ()
374{
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000375 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Jim Ingham1586d972011-12-17 01:35:57 +0000376 ValueObjectSP return_valobj_sp;
Jim Inghamd0bdddf2012-08-22 21:34:33 +0000377 Mutex::Locker api_locker;
378 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
379
Greg Claytonf4124de2012-02-21 00:09:25 +0000380 if (exe_ctx.HasThreadScope())
Jim Ingham1586d972011-12-17 01:35:57 +0000381 {
Greg Claytona894fe72012-04-05 16:12:35 +0000382 Process::StopLocker stop_locker;
383 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
Jim Ingham1586d972011-12-17 01:35:57 +0000384 {
Greg Claytona894fe72012-04-05 16:12:35 +0000385 StopInfoSP stop_info_sp = exe_ctx.GetThreadPtr()->GetStopInfo ();
386 if (stop_info_sp)
387 {
388 return_valobj_sp = StopInfo::GetReturnValueObject (stop_info_sp);
389 }
Jim Ingham1586d972011-12-17 01:35:57 +0000390 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000391 else
392 {
393 if (log)
394 log->Printf ("SBThread(%p)::GetStopReturnValue() => error: process is running", exe_ctx.GetThreadPtr());
395 }
Jim Ingham1586d972011-12-17 01:35:57 +0000396 }
397
Jim Ingham1586d972011-12-17 01:35:57 +0000398 if (log)
Greg Claytonf4124de2012-02-21 00:09:25 +0000399 log->Printf ("SBThread(%p)::GetStopReturnValue () => %s", exe_ctx.GetThreadPtr(),
Jim Ingham1586d972011-12-17 01:35:57 +0000400 return_valobj_sp.get()
401 ? return_valobj_sp->GetValueAsCString()
402 : "<no return value>");
403
404 return SBValue (return_valobj_sp);
405}
406
Chris Lattner24943d22010-06-08 16:52:24 +0000407void
408SBThread::SetThread (const ThreadSP& lldb_object_sp)
409{
Greg Claytona894fe72012-04-05 16:12:35 +0000410 m_opaque_sp->SetThreadSP (lldb_object_sp);
Chris Lattner24943d22010-06-08 16:52:24 +0000411}
412
413
414lldb::tid_t
415SBThread::GetThreadID () const
416{
Greg Claytona894fe72012-04-05 16:12:35 +0000417 ThreadSP thread_sp(m_opaque_sp->GetThreadSP());
Greg Clayton90c52142012-01-30 02:53:15 +0000418 if (thread_sp)
Greg Claytonf4124de2012-02-21 00:09:25 +0000419 return thread_sp->GetID();
420 return LLDB_INVALID_THREAD_ID;
Chris Lattner24943d22010-06-08 16:52:24 +0000421}
422
423uint32_t
424SBThread::GetIndexID () const
425{
Greg Claytona894fe72012-04-05 16:12:35 +0000426 ThreadSP thread_sp(m_opaque_sp->GetThreadSP());
Greg Clayton90c52142012-01-30 02:53:15 +0000427 if (thread_sp)
428 return thread_sp->GetIndexID();
Chris Lattner24943d22010-06-08 16:52:24 +0000429 return LLDB_INVALID_INDEX32;
430}
Greg Claytonf4124de2012-02-21 00:09:25 +0000431
Chris Lattner24943d22010-06-08 16:52:24 +0000432const char *
433SBThread::GetName () const
434{
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000435 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000436 const char *name = NULL;
Jim Inghamd0bdddf2012-08-22 21:34:33 +0000437 Mutex::Locker api_locker;
438 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
439
Greg Claytonf4124de2012-02-21 00:09:25 +0000440 if (exe_ctx.HasThreadScope())
Greg Claytonbdcda462010-12-20 20:49:23 +0000441 {
Greg Claytona894fe72012-04-05 16:12:35 +0000442 Process::StopLocker stop_locker;
443 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
444 {
Greg Claytona894fe72012-04-05 16:12:35 +0000445 name = exe_ctx.GetThreadPtr()->GetName();
446 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000447 else
448 {
449 if (log)
450 log->Printf ("SBThread(%p)::GetName() => error: process is running", exe_ctx.GetThreadPtr());
451 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000452 }
Greg Claytona66ba462010-10-30 04:51:46 +0000453
Caroline Tice7826c882010-10-26 03:11:13 +0000454 if (log)
Greg Claytonf4124de2012-02-21 00:09:25 +0000455 log->Printf ("SBThread(%p)::GetName () => %s", exe_ctx.GetThreadPtr(), name ? name : "NULL");
Caroline Tice7826c882010-10-26 03:11:13 +0000456
Greg Claytona66ba462010-10-30 04:51:46 +0000457 return name;
Chris Lattner24943d22010-06-08 16:52:24 +0000458}
459
460const char *
461SBThread::GetQueueName () const
462{
Greg Claytona66ba462010-10-30 04:51:46 +0000463 const char *name = NULL;
Jim Inghamd0bdddf2012-08-22 21:34:33 +0000464 Mutex::Locker api_locker;
465 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
466
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000467 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytonf4124de2012-02-21 00:09:25 +0000468 if (exe_ctx.HasThreadScope())
Greg Claytonbdcda462010-12-20 20:49:23 +0000469 {
Greg Claytona894fe72012-04-05 16:12:35 +0000470 Process::StopLocker stop_locker;
471 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
472 {
Greg Claytona894fe72012-04-05 16:12:35 +0000473 name = exe_ctx.GetThreadPtr()->GetQueueName();
474 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000475 else
476 {
477 if (log)
478 log->Printf ("SBThread(%p)::GetQueueName() => error: process is running", exe_ctx.GetThreadPtr());
479 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000480 }
Greg Claytona66ba462010-10-30 04:51:46 +0000481
Caroline Tice7826c882010-10-26 03:11:13 +0000482 if (log)
Greg Claytonf4124de2012-02-21 00:09:25 +0000483 log->Printf ("SBThread(%p)::GetQueueName () => %s", exe_ctx.GetThreadPtr(), name ? name : "NULL");
Caroline Tice7826c882010-10-26 03:11:13 +0000484
Greg Claytona66ba462010-10-30 04:51:46 +0000485 return name;
Chris Lattner24943d22010-06-08 16:52:24 +0000486}
487
Jim Ingham88e3de22012-05-03 21:19:36 +0000488SBError
489SBThread::ResumeNewPlan (ExecutionContext &exe_ctx, ThreadPlan *new_plan)
490{
491 SBError sb_error;
492
493 Process *process = exe_ctx.GetProcessPtr();
494 if (!process)
495 {
496 sb_error.SetErrorString("No process in SBThread::ResumeNewPlan");
497 return sb_error;
498 }
499
500 Thread *thread = exe_ctx.GetThreadPtr();
501 if (!thread)
502 {
503 sb_error.SetErrorString("No thread in SBThread::ResumeNewPlan");
504 return sb_error;
505 }
506
507 // User level plans should be Master Plans so they can be interrupted, other plans executed, and
508 // then a "continue" will resume the plan.
509 if (new_plan != NULL)
510 {
511 new_plan->SetIsMasterPlan(true);
512 new_plan->SetOkayToDiscard(false);
513 }
514
515 // Why do we need to set the current thread by ID here???
516 process->GetThreadList().SetSelectedThreadByID (thread->GetID());
517 sb_error.ref() = process->Resume();
518
519 if (sb_error.Success())
520 {
521 // If we are doing synchronous mode, then wait for the
522 // process to stop yet again!
523 if (process->GetTarget().GetDebugger().GetAsyncExecution () == false)
524 process->WaitForProcessToStop (NULL);
525 }
526
527 return sb_error;
528}
Chris Lattner24943d22010-06-08 16:52:24 +0000529
530void
Chris Lattner24943d22010-06-08 16:52:24 +0000531SBThread::StepOver (lldb::RunMode stop_other_threads)
532{
Greg Claytone005f2c2010-11-06 01:53:30 +0000533 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000534
Jim Inghamd0bdddf2012-08-22 21:34:33 +0000535 Mutex::Locker api_locker;
536 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
537
Caroline Tice7826c882010-10-26 03:11:13 +0000538
Greg Clayton90c52142012-01-30 02:53:15 +0000539 if (log)
Greg Claytonf4124de2012-02-21 00:09:25 +0000540 log->Printf ("SBThread(%p)::StepOver (stop_other_threads='%s')", exe_ctx.GetThreadPtr(),
Greg Clayton90c52142012-01-30 02:53:15 +0000541 Thread::RunModeAsCString (stop_other_threads));
542
Greg Claytonf4124de2012-02-21 00:09:25 +0000543 if (exe_ctx.HasThreadScope())
Chris Lattner24943d22010-06-08 16:52:24 +0000544 {
Greg Claytonf4124de2012-02-21 00:09:25 +0000545 Thread *thread = exe_ctx.GetThreadPtr();
Jim Inghamd82bc6d2012-05-11 23:47:32 +0000546 bool abort_other_plans = false;
Greg Claytonf4124de2012-02-21 00:09:25 +0000547 StackFrameSP frame_sp(thread->GetStackFrameAtIndex (0));
Jim Ingham88e3de22012-05-03 21:19:36 +0000548 ThreadPlan *new_plan = NULL;
Chris Lattner24943d22010-06-08 16:52:24 +0000549
550 if (frame_sp)
551 {
552 if (frame_sp->HasDebugInformation ())
553 {
554 SymbolContext sc(frame_sp->GetSymbolContext(eSymbolContextEverything));
Jim Ingham88e3de22012-05-03 21:19:36 +0000555 new_plan = thread->QueueThreadPlanForStepRange (abort_other_plans,
556 eStepTypeOver,
557 sc.line_entry.range,
558 sc,
559 stop_other_threads,
560 false);
Chris Lattner24943d22010-06-08 16:52:24 +0000561
562 }
563 else
564 {
Jim Ingham88e3de22012-05-03 21:19:36 +0000565 new_plan = thread->QueueThreadPlanForStepSingleInstruction (true,
566 abort_other_plans,
567 stop_other_threads);
Chris Lattner24943d22010-06-08 16:52:24 +0000568 }
569 }
570
Jim Ingham88e3de22012-05-03 21:19:36 +0000571 // This returns an error, we should use it!
572 ResumeNewPlan (exe_ctx, new_plan);
Chris Lattner24943d22010-06-08 16:52:24 +0000573 }
574}
575
576void
577SBThread::StepInto (lldb::RunMode stop_other_threads)
578{
Greg Claytone005f2c2010-11-06 01:53:30 +0000579 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000580
Jim Inghamd0bdddf2012-08-22 21:34:33 +0000581 Mutex::Locker api_locker;
582 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
Greg Clayton90c52142012-01-30 02:53:15 +0000583
584 if (log)
Greg Claytonf4124de2012-02-21 00:09:25 +0000585 log->Printf ("SBThread(%p)::StepInto (stop_other_threads='%s')", exe_ctx.GetThreadPtr(),
Greg Clayton90c52142012-01-30 02:53:15 +0000586 Thread::RunModeAsCString (stop_other_threads));
Greg Claytonf4124de2012-02-21 00:09:25 +0000587 if (exe_ctx.HasThreadScope())
Chris Lattner24943d22010-06-08 16:52:24 +0000588 {
Jim Inghamd82bc6d2012-05-11 23:47:32 +0000589 bool abort_other_plans = false;
Chris Lattner24943d22010-06-08 16:52:24 +0000590
Greg Claytonf4124de2012-02-21 00:09:25 +0000591 Thread *thread = exe_ctx.GetThreadPtr();
592 StackFrameSP frame_sp(thread->GetStackFrameAtIndex (0));
Jim Ingham88e3de22012-05-03 21:19:36 +0000593 ThreadPlan *new_plan = NULL;
Chris Lattner24943d22010-06-08 16:52:24 +0000594
595 if (frame_sp && frame_sp->HasDebugInformation ())
596 {
Greg Clayton8f5fd6b2010-06-12 18:59:55 +0000597 bool avoid_code_without_debug_info = true;
Chris Lattner24943d22010-06-08 16:52:24 +0000598 SymbolContext sc(frame_sp->GetSymbolContext(eSymbolContextEverything));
Jim Ingham88e3de22012-05-03 21:19:36 +0000599 new_plan = thread->QueueThreadPlanForStepRange (abort_other_plans,
600 eStepTypeInto,
601 sc.line_entry.range,
602 sc,
603 stop_other_threads,
604 avoid_code_without_debug_info);
Chris Lattner24943d22010-06-08 16:52:24 +0000605 }
606 else
607 {
Jim Ingham88e3de22012-05-03 21:19:36 +0000608 new_plan = thread->QueueThreadPlanForStepSingleInstruction (false,
609 abort_other_plans,
610 stop_other_threads);
Chris Lattner24943d22010-06-08 16:52:24 +0000611 }
Jim Ingham88e3de22012-05-03 21:19:36 +0000612
613 // This returns an error, we should use it!
614 ResumeNewPlan (exe_ctx, new_plan);
Chris Lattner24943d22010-06-08 16:52:24 +0000615 }
616}
617
618void
619SBThread::StepOut ()
620{
Greg Claytone005f2c2010-11-06 01:53:30 +0000621 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000622
Jim Inghamd0bdddf2012-08-22 21:34:33 +0000623 Mutex::Locker api_locker;
624 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
625
Caroline Tice7826c882010-10-26 03:11:13 +0000626
Greg Clayton90c52142012-01-30 02:53:15 +0000627 if (log)
Greg Claytonf4124de2012-02-21 00:09:25 +0000628 log->Printf ("SBThread(%p)::StepOut ()", exe_ctx.GetThreadPtr());
Greg Clayton90c52142012-01-30 02:53:15 +0000629
Greg Claytonf4124de2012-02-21 00:09:25 +0000630 if (exe_ctx.HasThreadScope())
Chris Lattner24943d22010-06-08 16:52:24 +0000631 {
Jim Inghamd82bc6d2012-05-11 23:47:32 +0000632 bool abort_other_plans = false;
Jim Inghambe0cde92012-09-14 21:07:14 +0000633 bool stop_other_threads = false;
Chris Lattner24943d22010-06-08 16:52:24 +0000634
Greg Claytonf4124de2012-02-21 00:09:25 +0000635 Thread *thread = exe_ctx.GetThreadPtr();
636
Jim Ingham88e3de22012-05-03 21:19:36 +0000637 ThreadPlan *new_plan = thread->QueueThreadPlanForStepOut (abort_other_plans,
638 NULL,
639 false,
640 stop_other_threads,
641 eVoteYes,
642 eVoteNoOpinion,
643 0);
644
645 // This returns an error, we should use it!
646 ResumeNewPlan (exe_ctx, new_plan);
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000647 }
648}
Chris Lattner24943d22010-06-08 16:52:24 +0000649
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000650void
651SBThread::StepOutOfFrame (lldb::SBFrame &sb_frame)
652{
653 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
654
Jim Inghamd0bdddf2012-08-22 21:34:33 +0000655 Mutex::Locker api_locker;
656 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
657
Greg Clayton334d33a2012-01-30 07:41:31 +0000658 StackFrameSP frame_sp (sb_frame.GetFrameSP());
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000659 if (log)
660 {
661 SBStream frame_desc_strm;
662 sb_frame.GetDescription (frame_desc_strm);
Greg Claytonf4124de2012-02-21 00:09:25 +0000663 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 +0000664 }
665
Greg Claytonf4124de2012-02-21 00:09:25 +0000666 if (exe_ctx.HasThreadScope())
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000667 {
Jim Inghamd82bc6d2012-05-11 23:47:32 +0000668 bool abort_other_plans = false;
Jim Inghambe0cde92012-09-14 21:07:14 +0000669 bool stop_other_threads = false;
Greg Claytonf4124de2012-02-21 00:09:25 +0000670 Thread *thread = exe_ctx.GetThreadPtr();
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000671
Jim Ingham88e3de22012-05-03 21:19:36 +0000672 ThreadPlan *new_plan = thread->QueueThreadPlanForStepOut (abort_other_plans,
673 NULL,
674 false,
675 stop_other_threads,
676 eVoteYes,
677 eVoteNoOpinion,
678 frame_sp->GetFrameIndex());
679
680 // This returns an error, we should use it!
681 ResumeNewPlan (exe_ctx, new_plan);
Chris Lattner24943d22010-06-08 16:52:24 +0000682 }
683}
684
685void
686SBThread::StepInstruction (bool step_over)
687{
Greg Claytone005f2c2010-11-06 01:53:30 +0000688 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000689
Jim Inghamd0bdddf2012-08-22 21:34:33 +0000690 Mutex::Locker api_locker;
691 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
692
Greg Claytonf4124de2012-02-21 00:09:25 +0000693
Caroline Tice7826c882010-10-26 03:11:13 +0000694
Greg Clayton90c52142012-01-30 02:53:15 +0000695 if (log)
Greg Claytonf4124de2012-02-21 00:09:25 +0000696 log->Printf ("SBThread(%p)::StepInstruction (step_over=%i)", exe_ctx.GetThreadPtr(), step_over);
Greg Clayton90c52142012-01-30 02:53:15 +0000697
Greg Claytonf4124de2012-02-21 00:09:25 +0000698 if (exe_ctx.HasThreadScope())
Chris Lattner24943d22010-06-08 16:52:24 +0000699 {
Greg Claytonf4124de2012-02-21 00:09:25 +0000700 Thread *thread = exe_ctx.GetThreadPtr();
Jim Ingham88e3de22012-05-03 21:19:36 +0000701 ThreadPlan *new_plan = thread->QueueThreadPlanForStepSingleInstruction (step_over, true, true);
702
703 // This returns an error, we should use it!
704 ResumeNewPlan (exe_ctx, new_plan);
Chris Lattner24943d22010-06-08 16:52:24 +0000705 }
706}
707
708void
709SBThread::RunToAddress (lldb::addr_t addr)
710{
Greg Claytone005f2c2010-11-06 01:53:30 +0000711 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000712
Jim Inghamd0bdddf2012-08-22 21:34:33 +0000713 Mutex::Locker api_locker;
714 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
715
Caroline Tice7826c882010-10-26 03:11:13 +0000716
Greg Clayton90c52142012-01-30 02:53:15 +0000717 if (log)
Greg Claytonf4124de2012-02-21 00:09:25 +0000718 log->Printf ("SBThread(%p)::RunToAddress (addr=0x%llx)", exe_ctx.GetThreadPtr(), addr);
Greg Clayton90c52142012-01-30 02:53:15 +0000719
Greg Claytonf4124de2012-02-21 00:09:25 +0000720 if (exe_ctx.HasThreadScope())
Chris Lattner24943d22010-06-08 16:52:24 +0000721 {
Jim Inghamd82bc6d2012-05-11 23:47:32 +0000722 bool abort_other_plans = false;
Chris Lattner24943d22010-06-08 16:52:24 +0000723 bool stop_other_threads = true;
724
Greg Clayton3508c382012-02-24 01:59:29 +0000725 Address target_addr (addr);
Chris Lattner24943d22010-06-08 16:52:24 +0000726
Greg Claytonf4124de2012-02-21 00:09:25 +0000727 Thread *thread = exe_ctx.GetThreadPtr();
Greg Claytonf4124de2012-02-21 00:09:25 +0000728
Jim Ingham88e3de22012-05-03 21:19:36 +0000729 ThreadPlan *new_plan = thread->QueueThreadPlanForRunToAddress (abort_other_plans, target_addr, stop_other_threads);
730
731 // This returns an error, we should use it!
732 ResumeNewPlan (exe_ctx, new_plan);
Chris Lattner24943d22010-06-08 16:52:24 +0000733 }
Chris Lattner24943d22010-06-08 16:52:24 +0000734}
735
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000736SBError
737SBThread::StepOverUntil (lldb::SBFrame &sb_frame,
738 lldb::SBFileSpec &sb_file_spec,
739 uint32_t line)
740{
741 SBError sb_error;
742 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
743 char path[PATH_MAX];
Greg Clayton90c52142012-01-30 02:53:15 +0000744
Jim Inghamd0bdddf2012-08-22 21:34:33 +0000745 Mutex::Locker api_locker;
746 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
747
Greg Clayton334d33a2012-01-30 07:41:31 +0000748 StackFrameSP frame_sp (sb_frame.GetFrameSP());
749
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000750 if (log)
751 {
752 SBStream frame_desc_strm;
753 sb_frame.GetDescription (frame_desc_strm);
754 sb_file_spec->GetPath (path, sizeof(path));
755 log->Printf ("SBThread(%p)::StepOverUntil (frame = SBFrame(%p): %s, file+line = %s:%u)",
Greg Claytonf4124de2012-02-21 00:09:25 +0000756 exe_ctx.GetThreadPtr(),
Greg Clayton334d33a2012-01-30 07:41:31 +0000757 frame_sp.get(),
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000758 frame_desc_strm.GetData(),
759 path, line);
760 }
Greg Clayton90c52142012-01-30 02:53:15 +0000761
Greg Claytonf4124de2012-02-21 00:09:25 +0000762 if (exe_ctx.HasThreadScope())
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000763 {
Greg Claytonf4124de2012-02-21 00:09:25 +0000764 Target *target = exe_ctx.GetTargetPtr();
Greg Claytonf4124de2012-02-21 00:09:25 +0000765 Thread *thread = exe_ctx.GetThreadPtr();
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000766
767 if (line == 0)
768 {
769 sb_error.SetErrorString("invalid line argument");
770 return sb_error;
771 }
772
Greg Clayton334d33a2012-01-30 07:41:31 +0000773 if (!frame_sp)
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000774 {
Greg Claytonf4124de2012-02-21 00:09:25 +0000775 frame_sp = thread->GetSelectedFrame ();
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000776 if (!frame_sp)
Greg Claytonf4124de2012-02-21 00:09:25 +0000777 frame_sp = thread->GetStackFrameAtIndex (0);
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000778 }
779
780 SymbolContext frame_sc;
781 if (!frame_sp)
782 {
783 sb_error.SetErrorString("no valid frames in thread to step");
784 return sb_error;
785 }
786
787 // If we have a frame, get its line
788 frame_sc = frame_sp->GetSymbolContext (eSymbolContextCompUnit |
789 eSymbolContextFunction |
790 eSymbolContextLineEntry |
791 eSymbolContextSymbol );
792
793 if (frame_sc.comp_unit == NULL)
794 {
795 sb_error.SetErrorStringWithFormat("frame %u doesn't have debug information", frame_sp->GetFrameIndex());
796 return sb_error;
797 }
798
799 FileSpec step_file_spec;
800 if (sb_file_spec.IsValid())
801 {
802 // The file spec passed in was valid, so use it
803 step_file_spec = sb_file_spec.ref();
804 }
805 else
806 {
807 if (frame_sc.line_entry.IsValid())
808 step_file_spec = frame_sc.line_entry.file;
809 else
810 {
811 sb_error.SetErrorString("invalid file argument or no file for frame");
812 return sb_error;
813 }
814 }
815
Jim Inghamb07c62a2011-05-08 00:56:32 +0000816 // Grab the current function, then we will make sure the "until" address is
817 // within the function. We discard addresses that are out of the current
818 // function, and then if there are no addresses remaining, give an appropriate
819 // error message.
820
821 bool all_in_function = true;
822 AddressRange fun_range = frame_sc.function->GetAddressRange();
823
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000824 std::vector<addr_t> step_over_until_addrs;
Jim Inghamd82bc6d2012-05-11 23:47:32 +0000825 const bool abort_other_plans = false;
Jim Ingham52124e72012-09-14 18:57:14 +0000826 const bool stop_other_threads = false;
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000827 const bool check_inlines = true;
828 const bool exact = false;
829
830 SymbolContextList sc_list;
Jim Inghamb07c62a2011-05-08 00:56:32 +0000831 const uint32_t num_matches = frame_sc.comp_unit->ResolveSymbolContext (step_file_spec,
832 line,
833 check_inlines,
834 exact,
835 eSymbolContextLineEntry,
836 sc_list);
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000837 if (num_matches > 0)
838 {
839 SymbolContext sc;
840 for (uint32_t i=0; i<num_matches; ++i)
841 {
842 if (sc_list.GetContextAtIndex(i, sc))
843 {
Jim Inghamb07c62a2011-05-08 00:56:32 +0000844 addr_t step_addr = sc.line_entry.range.GetBaseAddress().GetLoadAddress(target);
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000845 if (step_addr != LLDB_INVALID_ADDRESS)
846 {
Jim Inghamb07c62a2011-05-08 00:56:32 +0000847 if (fun_range.ContainsLoadAddress(step_addr, target))
848 step_over_until_addrs.push_back(step_addr);
849 else
850 all_in_function = false;
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000851 }
852 }
853 }
854 }
Jim Inghamb07c62a2011-05-08 00:56:32 +0000855
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000856 if (step_over_until_addrs.empty())
857 {
Jim Inghamb07c62a2011-05-08 00:56:32 +0000858 if (all_in_function)
859 {
860 step_file_spec.GetPath (path, sizeof(path));
Jason Molenda7e5fa7f2011-09-20 21:44:10 +0000861 sb_error.SetErrorStringWithFormat("No line entries for %s:%u", path, line);
Jim Inghamb07c62a2011-05-08 00:56:32 +0000862 }
863 else
Greg Clayton9c236732011-10-26 00:56:27 +0000864 sb_error.SetErrorString ("step until target not in current function");
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000865 }
866 else
867 {
Jim Ingham88e3de22012-05-03 21:19:36 +0000868 ThreadPlan *new_plan = thread->QueueThreadPlanForStepUntil (abort_other_plans,
869 &step_over_until_addrs[0],
870 step_over_until_addrs.size(),
871 stop_other_threads,
872 frame_sp->GetFrameIndex());
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000873
Jim Ingham88e3de22012-05-03 21:19:36 +0000874 sb_error = ResumeNewPlan (exe_ctx, new_plan);
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000875 }
876 }
877 else
878 {
879 sb_error.SetErrorString("this SBThread object is invalid");
880 }
881 return sb_error;
882}
883
Jim Inghama17a81a2012-09-12 00:40:39 +0000884SBError
Jim Inghamf59388a2012-09-14 02:14:15 +0000885SBThread::ReturnFromFrame (SBFrame &frame, SBValue &return_value)
Jim Inghama17a81a2012-09-12 00:40:39 +0000886{
887 SBError sb_error;
888
889 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
890
891 Mutex::Locker api_locker;
892 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
893
894
895 if (log)
Jim Inghamf59388a2012-09-14 02:14:15 +0000896 log->Printf ("SBThread(%p)::ReturnFromFrame (frame=%d)", exe_ctx.GetThreadPtr(), frame.GetFrameID());
Jim Inghama17a81a2012-09-12 00:40:39 +0000897
898 if (exe_ctx.HasThreadScope())
899 {
900 Thread *thread = exe_ctx.GetThreadPtr();
Jim Inghamf59388a2012-09-14 02:14:15 +0000901 sb_error.SetError (thread->ReturnFromFrame(frame.GetFrameSP(), return_value.GetSP()));
Jim Inghama17a81a2012-09-12 00:40:39 +0000902 }
903
904 return sb_error;
905}
906
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000907
Greg Clayton123db402011-01-12 02:25:42 +0000908bool
909SBThread::Suspend()
910{
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000911 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona894fe72012-04-05 16:12:35 +0000912 ExecutionContext exe_ctx (m_opaque_sp.get());
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000913 bool result = false;
Greg Claytonf4124de2012-02-21 00:09:25 +0000914 if (exe_ctx.HasThreadScope())
Greg Clayton123db402011-01-12 02:25:42 +0000915 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000916 Process::StopLocker stop_locker;
917 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
918 {
919 exe_ctx.GetThreadPtr()->SetResumeState (eStateSuspended);
920 result = true;
921 }
922 else
923 {
924 if (log)
925 log->Printf ("SBThread(%p)::Suspend() => error: process is running", exe_ctx.GetThreadPtr());
926 }
Greg Clayton123db402011-01-12 02:25:42 +0000927 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000928 if (log)
929 log->Printf ("SBThread(%p)::Suspend() => %i", exe_ctx.GetThreadPtr(), result);
930 return result;
Greg Clayton123db402011-01-12 02:25:42 +0000931}
932
933bool
934SBThread::Resume ()
935{
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000936 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona894fe72012-04-05 16:12:35 +0000937 ExecutionContext exe_ctx (m_opaque_sp.get());
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000938 bool result = false;
Greg Claytonf4124de2012-02-21 00:09:25 +0000939 if (exe_ctx.HasThreadScope())
Greg Clayton123db402011-01-12 02:25:42 +0000940 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000941 Process::StopLocker stop_locker;
942 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
943 {
944 exe_ctx.GetThreadPtr()->SetResumeState (eStateRunning);
945 result = true;
946 }
947 else
948 {
949 if (log)
950 log->Printf ("SBThread(%p)::Resume() => error: process is running", exe_ctx.GetThreadPtr());
951 }
Greg Clayton123db402011-01-12 02:25:42 +0000952 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000953 if (log)
954 log->Printf ("SBThread(%p)::Resume() => %i", exe_ctx.GetThreadPtr(), result);
955 return result;
Greg Clayton123db402011-01-12 02:25:42 +0000956}
957
958bool
959SBThread::IsSuspended()
960{
Greg Claytona894fe72012-04-05 16:12:35 +0000961 ExecutionContext exe_ctx (m_opaque_sp.get());
Greg Claytonf4124de2012-02-21 00:09:25 +0000962 if (exe_ctx.HasThreadScope())
963 return exe_ctx.GetThreadPtr()->GetResumeState () == eStateSuspended;
Greg Clayton123db402011-01-12 02:25:42 +0000964 return false;
965}
966
Chris Lattner24943d22010-06-08 16:52:24 +0000967SBProcess
968SBThread::GetProcess ()
969{
Caroline Tice7826c882010-10-26 03:11:13 +0000970
Greg Clayton334d33a2012-01-30 07:41:31 +0000971 SBProcess sb_process;
972 ProcessSP process_sp;
Greg Claytona894fe72012-04-05 16:12:35 +0000973 ExecutionContext exe_ctx (m_opaque_sp.get());
Greg Claytonf4124de2012-02-21 00:09:25 +0000974 if (exe_ctx.HasThreadScope())
Chris Lattner24943d22010-06-08 16:52:24 +0000975 {
976 // Have to go up to the target so we can get a shared pointer to our process...
Greg Claytonf4124de2012-02-21 00:09:25 +0000977 sb_process.SetSP (exe_ctx.GetProcessSP());
Chris Lattner24943d22010-06-08 16:52:24 +0000978 }
Caroline Tice7826c882010-10-26 03:11:13 +0000979
Greg Claytone005f2c2010-11-06 01:53:30 +0000980 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000981 if (log)
982 {
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000983 SBStream frame_desc_strm;
Greg Clayton334d33a2012-01-30 07:41:31 +0000984 sb_process.GetDescription (frame_desc_strm);
Greg Claytonf4124de2012-02-21 00:09:25 +0000985 log->Printf ("SBThread(%p)::GetProcess () => SBProcess(%p): %s", exe_ctx.GetThreadPtr(),
Greg Clayton334d33a2012-01-30 07:41:31 +0000986 process_sp.get(), frame_desc_strm.GetData());
Caroline Tice7826c882010-10-26 03:11:13 +0000987 }
988
Greg Clayton334d33a2012-01-30 07:41:31 +0000989 return sb_process;
Chris Lattner24943d22010-06-08 16:52:24 +0000990}
991
992uint32_t
993SBThread::GetNumFrames ()
994{
Greg Claytone005f2c2010-11-06 01:53:30 +0000995 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000996
Caroline Tice7826c882010-10-26 03:11:13 +0000997 uint32_t num_frames = 0;
Jim Inghamd0bdddf2012-08-22 21:34:33 +0000998 Mutex::Locker api_locker;
999 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
1000
Greg Claytonf4124de2012-02-21 00:09:25 +00001001 if (exe_ctx.HasThreadScope())
Greg Claytonbdcda462010-12-20 20:49:23 +00001002 {
Greg Claytona894fe72012-04-05 16:12:35 +00001003 Process::StopLocker stop_locker;
1004 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
1005 {
Greg Claytona894fe72012-04-05 16:12:35 +00001006 num_frames = exe_ctx.GetThreadPtr()->GetStackFrameCount();
1007 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001008 else
1009 {
1010 if (log)
1011 log->Printf ("SBThread(%p)::GetNumFrames() => error: process is running", exe_ctx.GetThreadPtr());
1012 }
Greg Claytonbdcda462010-12-20 20:49:23 +00001013 }
Caroline Tice7826c882010-10-26 03:11:13 +00001014
1015 if (log)
Greg Claytonf4124de2012-02-21 00:09:25 +00001016 log->Printf ("SBThread(%p)::GetNumFrames () => %u", exe_ctx.GetThreadPtr(), num_frames);
Caroline Tice7826c882010-10-26 03:11:13 +00001017
1018 return num_frames;
Chris Lattner24943d22010-06-08 16:52:24 +00001019}
1020
1021SBFrame
1022SBThread::GetFrameAtIndex (uint32_t idx)
1023{
Greg Claytone005f2c2010-11-06 01:53:30 +00001024 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001025
Chris Lattner24943d22010-06-08 16:52:24 +00001026 SBFrame sb_frame;
Greg Clayton334d33a2012-01-30 07:41:31 +00001027 StackFrameSP frame_sp;
Jim Inghamd0bdddf2012-08-22 21:34:33 +00001028 Mutex::Locker api_locker;
1029 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
1030
Greg Claytonf4124de2012-02-21 00:09:25 +00001031 if (exe_ctx.HasThreadScope())
Greg Claytonbdcda462010-12-20 20:49:23 +00001032 {
Greg Claytona894fe72012-04-05 16:12:35 +00001033 Process::StopLocker stop_locker;
1034 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
1035 {
Greg Claytona894fe72012-04-05 16:12:35 +00001036 frame_sp = exe_ctx.GetThreadPtr()->GetStackFrameAtIndex (idx);
1037 sb_frame.SetFrameSP (frame_sp);
1038 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001039 else
1040 {
1041 if (log)
1042 log->Printf ("SBThread(%p)::GetFrameAtIndex() => error: process is running", exe_ctx.GetThreadPtr());
1043 }
Greg Claytonbdcda462010-12-20 20:49:23 +00001044 }
Caroline Tice7826c882010-10-26 03:11:13 +00001045
1046 if (log)
1047 {
Greg Clayton1ebdcc72011-01-21 06:11:58 +00001048 SBStream frame_desc_strm;
1049 sb_frame.GetDescription (frame_desc_strm);
Greg Claytona66ba462010-10-30 04:51:46 +00001050 log->Printf ("SBThread(%p)::GetFrameAtIndex (idx=%d) => SBFrame(%p): %s",
Greg Claytonf4124de2012-02-21 00:09:25 +00001051 exe_ctx.GetThreadPtr(), idx, frame_sp.get(), frame_desc_strm.GetData());
Caroline Tice7826c882010-10-26 03:11:13 +00001052 }
1053
Chris Lattner24943d22010-06-08 16:52:24 +00001054 return sb_frame;
1055}
1056
Greg Claytonc5157ec2010-12-17 02:26:24 +00001057lldb::SBFrame
1058SBThread::GetSelectedFrame ()
1059{
1060 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1061
1062 SBFrame sb_frame;
Greg Clayton334d33a2012-01-30 07:41:31 +00001063 StackFrameSP frame_sp;
Jim Inghamd0bdddf2012-08-22 21:34:33 +00001064 Mutex::Locker api_locker;
1065 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
1066
Greg Claytonf4124de2012-02-21 00:09:25 +00001067 if (exe_ctx.HasThreadScope())
Greg Claytonbdcda462010-12-20 20:49:23 +00001068 {
Greg Claytona894fe72012-04-05 16:12:35 +00001069 Process::StopLocker stop_locker;
1070 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
1071 {
Greg Claytona894fe72012-04-05 16:12:35 +00001072 frame_sp = exe_ctx.GetThreadPtr()->GetSelectedFrame ();
1073 sb_frame.SetFrameSP (frame_sp);
1074 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001075 else
1076 {
1077 if (log)
1078 log->Printf ("SBThread(%p)::GetSelectedFrame() => error: process is running", exe_ctx.GetThreadPtr());
1079 }
Greg Claytonbdcda462010-12-20 20:49:23 +00001080 }
Greg Claytonc5157ec2010-12-17 02:26:24 +00001081
1082 if (log)
1083 {
Greg Clayton1ebdcc72011-01-21 06:11:58 +00001084 SBStream frame_desc_strm;
1085 sb_frame.GetDescription (frame_desc_strm);
Greg Claytonc5157ec2010-12-17 02:26:24 +00001086 log->Printf ("SBThread(%p)::GetSelectedFrame () => SBFrame(%p): %s",
Greg Claytonf4124de2012-02-21 00:09:25 +00001087 exe_ctx.GetThreadPtr(), frame_sp.get(), frame_desc_strm.GetData());
Greg Claytonc5157ec2010-12-17 02:26:24 +00001088 }
1089
1090 return sb_frame;
1091}
1092
1093lldb::SBFrame
1094SBThread::SetSelectedFrame (uint32_t idx)
1095{
1096 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1097
1098 SBFrame sb_frame;
Greg Clayton334d33a2012-01-30 07:41:31 +00001099 StackFrameSP frame_sp;
Jim Inghamd0bdddf2012-08-22 21:34:33 +00001100 Mutex::Locker api_locker;
1101 ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker);
1102
Greg Claytonf4124de2012-02-21 00:09:25 +00001103 if (exe_ctx.HasThreadScope())
Greg Claytonc5157ec2010-12-17 02:26:24 +00001104 {
Greg Claytona894fe72012-04-05 16:12:35 +00001105 Process::StopLocker stop_locker;
1106 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
Greg Claytonc5157ec2010-12-17 02:26:24 +00001107 {
Greg Claytona894fe72012-04-05 16:12:35 +00001108 Thread *thread = exe_ctx.GetThreadPtr();
1109 frame_sp = thread->GetStackFrameAtIndex (idx);
1110 if (frame_sp)
1111 {
1112 thread->SetSelectedFrame (frame_sp.get());
1113 sb_frame.SetFrameSP (frame_sp);
1114 }
Greg Claytonc5157ec2010-12-17 02:26:24 +00001115 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001116 else
1117 {
1118 if (log)
1119 log->Printf ("SBThread(%p)::SetSelectedFrame() => error: process is running", exe_ctx.GetThreadPtr());
1120 }
Greg Claytonc5157ec2010-12-17 02:26:24 +00001121 }
1122
1123 if (log)
1124 {
Greg Clayton1ebdcc72011-01-21 06:11:58 +00001125 SBStream frame_desc_strm;
1126 sb_frame.GetDescription (frame_desc_strm);
Greg Claytonc5157ec2010-12-17 02:26:24 +00001127 log->Printf ("SBThread(%p)::SetSelectedFrame (idx=%u) => SBFrame(%p): %s",
Greg Claytonf4124de2012-02-21 00:09:25 +00001128 exe_ctx.GetThreadPtr(), idx, frame_sp.get(), frame_desc_strm.GetData());
Greg Claytonc5157ec2010-12-17 02:26:24 +00001129 }
1130 return sb_frame;
1131}
1132
Jim Ingham94a5d0d2012-10-10 18:32:14 +00001133bool
1134SBThread::EventIsThreadEvent (const SBEvent &event)
1135{
1136 return Thread::ThreadEventData::GetEventDataFromEvent(event.get()) != NULL;
1137}
1138
1139SBFrame
1140SBThread::GetStackFrameFromEvent (const SBEvent &event)
1141{
1142 return Thread::ThreadEventData::GetStackFrameFromEvent (event.get());
1143
1144}
1145
1146SBThread
1147SBThread::GetThreadFromEvent (const SBEvent &event)
1148{
1149 return Thread::ThreadEventData::GetThreadFromEvent (event.get());
1150}
Greg Claytonc5157ec2010-12-17 02:26:24 +00001151
Chris Lattner24943d22010-06-08 16:52:24 +00001152bool
1153SBThread::operator == (const SBThread &rhs) const
1154{
Greg Claytona894fe72012-04-05 16:12:35 +00001155 return m_opaque_sp->GetThreadSP().get() == rhs.m_opaque_sp->GetThreadSP().get();
Chris Lattner24943d22010-06-08 16:52:24 +00001156}
1157
1158bool
1159SBThread::operator != (const SBThread &rhs) const
1160{
Greg Claytona894fe72012-04-05 16:12:35 +00001161 return m_opaque_sp->GetThreadSP().get() != rhs.m_opaque_sp->GetThreadSP().get();
Chris Lattner24943d22010-06-08 16:52:24 +00001162}
Caroline Tice98f930f2010-09-20 05:20:02 +00001163
1164bool
Jim Ingham94a5d0d2012-10-10 18:32:14 +00001165SBThread::GetStatus (SBStream &status) const
1166{
1167 Stream &strm = status.ref();
1168
1169 ExecutionContext exe_ctx (m_opaque_sp.get());
1170 if (exe_ctx.HasThreadScope())
1171 {
1172 exe_ctx.GetThreadPtr()->GetStatus(strm, 0, 1, 1);
1173 }
1174 else
1175 strm.PutCString ("No status");
1176
1177 return true;
1178}
1179
1180bool
Caroline Tice7826c882010-10-26 03:11:13 +00001181SBThread::GetDescription (SBStream &description) const
1182{
Greg Clayton96154be2011-11-13 06:57:31 +00001183 Stream &strm = description.ref();
1184
Greg Claytona894fe72012-04-05 16:12:35 +00001185 ExecutionContext exe_ctx (m_opaque_sp.get());
Greg Claytonf4124de2012-02-21 00:09:25 +00001186 if (exe_ctx.HasThreadScope())
Caroline Tice7826c882010-10-26 03:11:13 +00001187 {
Greg Claytonf4124de2012-02-21 00:09:25 +00001188 strm.Printf("SBThread: tid = 0x%4.4llx", exe_ctx.GetThreadPtr()->GetID());
Caroline Tice7826c882010-10-26 03:11:13 +00001189 }
1190 else
Greg Clayton96154be2011-11-13 06:57:31 +00001191 strm.PutCString ("No value");
Caroline Tice7826c882010-10-26 03:11:13 +00001192
1193 return true;
1194}