blob: b831a4fcb89f00f0f782b48430c85a92d6cec243 [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 Ingham1586d972011-12-17 01:35:57 +000035#include "lldb/API/SBFrame.h"
Eli Friedman7a62c8b2010-06-09 07:44:37 +000036#include "lldb/API/SBProcess.h"
Jim Ingham1586d972011-12-17 01:35:57 +000037#include "lldb/API/SBValue.h"
Chris Lattner24943d22010-06-08 16:52:24 +000038
39using namespace lldb;
40using namespace lldb_private;
41
Greg Clayton49ce6822010-10-31 03:01:06 +000042//----------------------------------------------------------------------
43// Constructors
44//----------------------------------------------------------------------
Chris Lattner24943d22010-06-08 16:52:24 +000045SBThread::SBThread () :
Greg Claytona894fe72012-04-05 16:12:35 +000046 m_opaque_sp (new ExecutionContextRef())
Chris Lattner24943d22010-06-08 16:52:24 +000047{
48}
49
Chris Lattner24943d22010-06-08 16:52:24 +000050SBThread::SBThread (const ThreadSP& lldb_object_sp) :
Greg Claytona894fe72012-04-05 16:12:35 +000051 m_opaque_sp (new ExecutionContextRef(lldb_object_sp))
Chris Lattner24943d22010-06-08 16:52:24 +000052{
53}
54
Greg Clayton1b284412010-10-30 18:26:59 +000055SBThread::SBThread (const SBThread &rhs) :
Greg Claytona894fe72012-04-05 16:12:35 +000056 m_opaque_sp (new ExecutionContextRef(*rhs.m_opaque_sp))
Chris Lattner24943d22010-06-08 16:52:24 +000057{
Greg Claytona894fe72012-04-05 16:12:35 +000058
Chris Lattner24943d22010-06-08 16:52:24 +000059}
60
61//----------------------------------------------------------------------
Greg Clayton49ce6822010-10-31 03:01:06 +000062// Assignment operator
63//----------------------------------------------------------------------
64
65const lldb::SBThread &
66SBThread::operator = (const SBThread &rhs)
67{
68 if (this != &rhs)
Greg Claytona894fe72012-04-05 16:12:35 +000069 *m_opaque_sp = *rhs.m_opaque_sp;
Greg Clayton49ce6822010-10-31 03:01:06 +000070 return *this;
71}
72
73//----------------------------------------------------------------------
Chris Lattner24943d22010-06-08 16:52:24 +000074// Destructor
75//----------------------------------------------------------------------
76SBThread::~SBThread()
77{
78}
79
80bool
81SBThread::IsValid() const
82{
Greg Claytona894fe72012-04-05 16:12:35 +000083 return m_opaque_sp->GetThreadSP().get() != NULL;
Chris Lattner24943d22010-06-08 16:52:24 +000084}
85
Greg Clayton43490d12010-07-30 20:12:55 +000086void
87SBThread::Clear ()
88{
Greg Claytona894fe72012-04-05 16:12:35 +000089 m_opaque_sp->Clear();
Greg Clayton43490d12010-07-30 20:12:55 +000090}
91
92
Chris Lattner24943d22010-06-08 16:52:24 +000093StopReason
94SBThread::GetStopReason()
95{
Greg Claytone005f2c2010-11-06 01:53:30 +000096 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +000097
Caroline Tice7826c882010-10-26 03:11:13 +000098 StopReason reason = eStopReasonInvalid;
Greg Claytona894fe72012-04-05 16:12:35 +000099 ExecutionContext exe_ctx (m_opaque_sp.get());
Greg Claytonf4124de2012-02-21 00:09:25 +0000100 if (exe_ctx.HasThreadScope())
Chris Lattner24943d22010-06-08 16:52:24 +0000101 {
Greg Claytona894fe72012-04-05 16:12:35 +0000102 Process::StopLocker stop_locker;
103 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
104 {
105 Mutex::Locker api_locker (exe_ctx.GetTargetPtr()->GetAPIMutex());
106 StopInfoSP stop_info_sp = exe_ctx.GetThreadPtr()->GetStopInfo ();
107 if (stop_info_sp)
108 reason = stop_info_sp->GetStopReason();
109 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000110 else
111 {
112 if (log)
113 log->Printf ("SBThread(%p)::GetStopReason() => error: process is running", exe_ctx.GetThreadPtr());
114 }
Chris Lattner24943d22010-06-08 16:52:24 +0000115 }
Caroline Tice7826c882010-10-26 03:11:13 +0000116
117 if (log)
Greg Claytonf4124de2012-02-21 00:09:25 +0000118 log->Printf ("SBThread(%p)::GetStopReason () => %s", exe_ctx.GetThreadPtr(),
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000119 Thread::StopReasonAsCString (reason));
Caroline Tice7826c882010-10-26 03:11:13 +0000120
121 return reason;
Chris Lattner24943d22010-06-08 16:52:24 +0000122}
123
124size_t
Greg Clayton640dc6b2010-11-18 18:52:36 +0000125SBThread::GetStopReasonDataCount ()
126{
Greg Claytona894fe72012-04-05 16:12:35 +0000127 ExecutionContext exe_ctx (m_opaque_sp.get());
Greg Claytonf4124de2012-02-21 00:09:25 +0000128 if (exe_ctx.HasThreadScope())
Greg Clayton640dc6b2010-11-18 18:52:36 +0000129 {
Greg Claytona894fe72012-04-05 16:12:35 +0000130 Process::StopLocker stop_locker;
131 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
Greg Clayton640dc6b2010-11-18 18:52:36 +0000132 {
Greg Claytona894fe72012-04-05 16:12:35 +0000133 Mutex::Locker api_locker (exe_ctx.GetTargetPtr()->GetAPIMutex());
134 StopInfoSP stop_info_sp = exe_ctx.GetThreadPtr()->GetStopInfo ();
135 if (stop_info_sp)
Greg Clayton640dc6b2010-11-18 18:52:36 +0000136 {
Greg Claytona894fe72012-04-05 16:12:35 +0000137 StopReason reason = stop_info_sp->GetStopReason();
138 switch (reason)
Greg Clayton640dc6b2010-11-18 18:52:36 +0000139 {
Greg Claytona894fe72012-04-05 16:12:35 +0000140 case eStopReasonInvalid:
141 case eStopReasonNone:
142 case eStopReasonTrace:
143 case eStopReasonPlanComplete:
144 // There is no data for these stop reasons.
145 return 0;
146
147 case eStopReasonBreakpoint:
148 {
149 break_id_t site_id = stop_info_sp->GetValue();
150 lldb::BreakpointSiteSP bp_site_sp (exe_ctx.GetProcessPtr()->GetBreakpointSiteList().FindByID (site_id));
151 if (bp_site_sp)
152 return bp_site_sp->GetNumberOfOwners () * 2;
153 else
154 return 0; // Breakpoint must have cleared itself...
155 }
156 break;
157
158 case eStopReasonWatchpoint:
159 return 1;
160
161 case eStopReasonSignal:
162 return 1;
163
164 case eStopReasonException:
165 return 1;
Greg Clayton640dc6b2010-11-18 18:52:36 +0000166 }
Greg Clayton640dc6b2010-11-18 18:52:36 +0000167 }
168 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000169 else
170 {
171 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
172 if (log)
173 log->Printf ("SBThread(%p)::GetStopReasonDataCount() => error: process is running", exe_ctx.GetThreadPtr());
174 }
Greg Clayton640dc6b2010-11-18 18:52:36 +0000175 }
176 return 0;
177}
178
179uint64_t
180SBThread::GetStopReasonDataAtIndex (uint32_t idx)
181{
Greg Claytona894fe72012-04-05 16:12:35 +0000182 ExecutionContext exe_ctx (m_opaque_sp.get());
Greg Claytonf4124de2012-02-21 00:09:25 +0000183 if (exe_ctx.HasThreadScope())
Greg Clayton640dc6b2010-11-18 18:52:36 +0000184 {
Greg Claytona894fe72012-04-05 16:12:35 +0000185 Process::StopLocker stop_locker;
186 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
Greg Clayton640dc6b2010-11-18 18:52:36 +0000187 {
Greg Clayton640dc6b2010-11-18 18:52:36 +0000188
Greg Claytona894fe72012-04-05 16:12:35 +0000189 Mutex::Locker api_locker (exe_ctx.GetTargetPtr()->GetAPIMutex());
190 Thread *thread = exe_ctx.GetThreadPtr();
191 StopInfoSP stop_info_sp = thread->GetStopInfo ();
192 if (stop_info_sp)
193 {
194 StopReason reason = stop_info_sp->GetStopReason();
195 switch (reason)
Greg Clayton640dc6b2010-11-18 18:52:36 +0000196 {
Greg Claytona894fe72012-04-05 16:12:35 +0000197 case eStopReasonInvalid:
198 case eStopReasonNone:
199 case eStopReasonTrace:
200 case eStopReasonPlanComplete:
201 // There is no data for these stop reasons.
202 return 0;
203
204 case eStopReasonBreakpoint:
Greg Clayton640dc6b2010-11-18 18:52:36 +0000205 {
Greg Claytona894fe72012-04-05 16:12:35 +0000206 break_id_t site_id = stop_info_sp->GetValue();
207 lldb::BreakpointSiteSP bp_site_sp (exe_ctx.GetProcessPtr()->GetBreakpointSiteList().FindByID (site_id));
208 if (bp_site_sp)
Greg Clayton640dc6b2010-11-18 18:52:36 +0000209 {
Greg Claytona894fe72012-04-05 16:12:35 +0000210 uint32_t bp_index = idx / 2;
211 BreakpointLocationSP bp_loc_sp (bp_site_sp->GetOwnerAtIndex (bp_index));
212 if (bp_loc_sp)
Greg Clayton640dc6b2010-11-18 18:52:36 +0000213 {
Greg Claytona894fe72012-04-05 16:12:35 +0000214 if (bp_index & 1)
215 {
216 // Odd idx, return the breakpoint location ID
217 return bp_loc_sp->GetID();
218 }
219 else
220 {
221 // Even idx, return the breakpoint ID
222 return bp_loc_sp->GetBreakpoint().GetID();
223 }
Greg Clayton640dc6b2010-11-18 18:52:36 +0000224 }
225 }
Greg Claytona894fe72012-04-05 16:12:35 +0000226 return LLDB_INVALID_BREAK_ID;
Greg Clayton640dc6b2010-11-18 18:52:36 +0000227 }
Greg Claytona894fe72012-04-05 16:12:35 +0000228 break;
229
230 case eStopReasonWatchpoint:
231 return stop_info_sp->GetValue();
232
233 case eStopReasonSignal:
234 return stop_info_sp->GetValue();
235
236 case eStopReasonException:
237 return stop_info_sp->GetValue();
Greg Clayton640dc6b2010-11-18 18:52:36 +0000238 }
Greg Clayton640dc6b2010-11-18 18:52:36 +0000239 }
240 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000241 else
242 {
243 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
244 if (log)
245 log->Printf ("SBThread(%p)::GetStopReasonDataAtIndex() => error: process is running", exe_ctx.GetThreadPtr());
246 }
Greg Clayton640dc6b2010-11-18 18:52:36 +0000247 }
248 return 0;
249}
250
251size_t
Chris Lattner24943d22010-06-08 16:52:24 +0000252SBThread::GetStopDescription (char *dst, size_t dst_len)
253{
Greg Claytone005f2c2010-11-06 01:53:30 +0000254 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000255
Greg Claytona894fe72012-04-05 16:12:35 +0000256 ExecutionContext exe_ctx (m_opaque_sp.get());
Greg Claytonf4124de2012-02-21 00:09:25 +0000257 if (exe_ctx.HasThreadScope())
Chris Lattner24943d22010-06-08 16:52:24 +0000258 {
Greg Claytona894fe72012-04-05 16:12:35 +0000259 Process::StopLocker stop_locker;
260 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
Chris Lattner24943d22010-06-08 16:52:24 +0000261 {
Greg Claytona894fe72012-04-05 16:12:35 +0000262
263 Mutex::Locker api_locker (exe_ctx.GetTargetPtr()->GetAPIMutex());
264 StopInfoSP stop_info_sp = exe_ctx.GetThreadPtr()->GetStopInfo ();
265 if (stop_info_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000266 {
Greg Claytona894fe72012-04-05 16:12:35 +0000267 const char *stop_desc = stop_info_sp->GetDescription();
268 if (stop_desc)
Chris Lattner24943d22010-06-08 16:52:24 +0000269 {
Caroline Tice7826c882010-10-26 03:11:13 +0000270 if (log)
Greg Claytona894fe72012-04-05 16:12:35 +0000271 log->Printf ("SBThread(%p)::GetStopDescription (dst, dst_len) => \"%s\"",
Greg Claytonf4124de2012-02-21 00:09:25 +0000272 exe_ctx.GetThreadPtr(), stop_desc);
Chris Lattner24943d22010-06-08 16:52:24 +0000273 if (dst)
Greg Claytona894fe72012-04-05 16:12:35 +0000274 return ::snprintf (dst, dst_len, "%s", stop_desc);
275 else
276 {
277 // NULL dst passed in, return the length needed to contain the description
278 return ::strlen (stop_desc) + 1; // Include the NULL byte for size
279 }
280 }
281 else
282 {
283 size_t stop_desc_len = 0;
284 switch (stop_info_sp->GetStopReason())
285 {
286 case eStopReasonTrace:
287 case eStopReasonPlanComplete:
288 {
289 static char trace_desc[] = "step";
290 stop_desc = trace_desc;
291 stop_desc_len = sizeof(trace_desc); // Include the NULL byte for size
292 }
293 break;
Chris Lattner24943d22010-06-08 16:52:24 +0000294
Greg Claytona894fe72012-04-05 16:12:35 +0000295 case eStopReasonBreakpoint:
296 {
297 static char bp_desc[] = "breakpoint hit";
298 stop_desc = bp_desc;
299 stop_desc_len = sizeof(bp_desc); // Include the NULL byte for size
300 }
301 break;
302
303 case eStopReasonWatchpoint:
304 {
305 static char wp_desc[] = "watchpoint hit";
306 stop_desc = wp_desc;
307 stop_desc_len = sizeof(wp_desc); // Include the NULL byte for size
308 }
309 break;
310
311 case eStopReasonSignal:
312 {
313 stop_desc = exe_ctx.GetProcessPtr()->GetUnixSignals ().GetSignalAsCString (stop_info_sp->GetValue());
314 if (stop_desc == NULL || stop_desc[0] == '\0')
315 {
316 static char signal_desc[] = "signal";
317 stop_desc = signal_desc;
318 stop_desc_len = sizeof(signal_desc); // Include the NULL byte for size
319 }
320 }
321 break;
322
323 case eStopReasonException:
324 {
325 char exc_desc[] = "exception";
326 stop_desc = exc_desc;
327 stop_desc_len = sizeof(exc_desc); // Include the NULL byte for size
328 }
329 break;
330
331 default:
332 break;
333 }
334
335 if (stop_desc && stop_desc[0])
336 {
337 if (log)
338 log->Printf ("SBThread(%p)::GetStopDescription (dst, dst_len) => '%s'",
339 exe_ctx.GetThreadPtr(), stop_desc);
340
341 if (dst)
342 return ::snprintf (dst, dst_len, "%s", stop_desc) + 1; // Include the NULL byte
343
344 if (stop_desc_len == 0)
345 stop_desc_len = ::strlen (stop_desc) + 1; // Include the NULL byte
346
347 return stop_desc_len;
348 }
Chris Lattner24943d22010-06-08 16:52:24 +0000349 }
350 }
351 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000352 else
353 {
354 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
355 if (log)
356 log->Printf ("SBThread(%p)::GetStopDescription() => error: process is running", exe_ctx.GetThreadPtr());
357 }
Chris Lattner24943d22010-06-08 16:52:24 +0000358 }
359 if (dst)
360 *dst = 0;
361 return 0;
362}
363
Jim Ingham1586d972011-12-17 01:35:57 +0000364SBValue
365SBThread::GetStopReturnValue ()
366{
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000367 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Jim Ingham1586d972011-12-17 01:35:57 +0000368 ValueObjectSP return_valobj_sp;
Greg Claytona894fe72012-04-05 16:12:35 +0000369 ExecutionContext exe_ctx (m_opaque_sp.get());
Greg Claytonf4124de2012-02-21 00:09:25 +0000370 if (exe_ctx.HasThreadScope())
Jim Ingham1586d972011-12-17 01:35:57 +0000371 {
Greg Claytona894fe72012-04-05 16:12:35 +0000372 Process::StopLocker stop_locker;
373 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
Jim Ingham1586d972011-12-17 01:35:57 +0000374 {
Greg Claytona894fe72012-04-05 16:12:35 +0000375 Mutex::Locker api_locker (exe_ctx.GetTargetPtr()->GetAPIMutex());
376 StopInfoSP stop_info_sp = exe_ctx.GetThreadPtr()->GetStopInfo ();
377 if (stop_info_sp)
378 {
379 return_valobj_sp = StopInfo::GetReturnValueObject (stop_info_sp);
380 }
Jim Ingham1586d972011-12-17 01:35:57 +0000381 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000382 else
383 {
384 if (log)
385 log->Printf ("SBThread(%p)::GetStopReturnValue() => error: process is running", exe_ctx.GetThreadPtr());
386 }
Jim Ingham1586d972011-12-17 01:35:57 +0000387 }
388
Jim Ingham1586d972011-12-17 01:35:57 +0000389 if (log)
Greg Claytonf4124de2012-02-21 00:09:25 +0000390 log->Printf ("SBThread(%p)::GetStopReturnValue () => %s", exe_ctx.GetThreadPtr(),
Jim Ingham1586d972011-12-17 01:35:57 +0000391 return_valobj_sp.get()
392 ? return_valobj_sp->GetValueAsCString()
393 : "<no return value>");
394
395 return SBValue (return_valobj_sp);
396}
397
Chris Lattner24943d22010-06-08 16:52:24 +0000398void
399SBThread::SetThread (const ThreadSP& lldb_object_sp)
400{
Greg Claytona894fe72012-04-05 16:12:35 +0000401 m_opaque_sp->SetThreadSP (lldb_object_sp);
Chris Lattner24943d22010-06-08 16:52:24 +0000402}
403
404
405lldb::tid_t
406SBThread::GetThreadID () const
407{
Greg Claytona894fe72012-04-05 16:12:35 +0000408 ThreadSP thread_sp(m_opaque_sp->GetThreadSP());
Greg Clayton90c52142012-01-30 02:53:15 +0000409 if (thread_sp)
Greg Claytonf4124de2012-02-21 00:09:25 +0000410 return thread_sp->GetID();
411 return LLDB_INVALID_THREAD_ID;
Chris Lattner24943d22010-06-08 16:52:24 +0000412}
413
414uint32_t
415SBThread::GetIndexID () 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)
419 return thread_sp->GetIndexID();
Chris Lattner24943d22010-06-08 16:52:24 +0000420 return LLDB_INVALID_INDEX32;
421}
Greg Claytonf4124de2012-02-21 00:09:25 +0000422
Chris Lattner24943d22010-06-08 16:52:24 +0000423const char *
424SBThread::GetName () const
425{
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000426 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000427 const char *name = NULL;
Greg Claytona894fe72012-04-05 16:12:35 +0000428 ExecutionContext exe_ctx (m_opaque_sp.get());
Greg Claytonf4124de2012-02-21 00:09:25 +0000429 if (exe_ctx.HasThreadScope())
Greg Claytonbdcda462010-12-20 20:49:23 +0000430 {
Greg Claytona894fe72012-04-05 16:12:35 +0000431 Process::StopLocker stop_locker;
432 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
433 {
434 Mutex::Locker api_locker (exe_ctx.GetTargetPtr()->GetAPIMutex());
435 name = exe_ctx.GetThreadPtr()->GetName();
436 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000437 else
438 {
439 if (log)
440 log->Printf ("SBThread(%p)::GetName() => error: process is running", exe_ctx.GetThreadPtr());
441 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000442 }
Greg Claytona66ba462010-10-30 04:51:46 +0000443
Caroline Tice7826c882010-10-26 03:11:13 +0000444 if (log)
Greg Claytonf4124de2012-02-21 00:09:25 +0000445 log->Printf ("SBThread(%p)::GetName () => %s", exe_ctx.GetThreadPtr(), name ? name : "NULL");
Caroline Tice7826c882010-10-26 03:11:13 +0000446
Greg Claytona66ba462010-10-30 04:51:46 +0000447 return name;
Chris Lattner24943d22010-06-08 16:52:24 +0000448}
449
450const char *
451SBThread::GetQueueName () const
452{
Greg Claytona66ba462010-10-30 04:51:46 +0000453 const char *name = NULL;
Greg Claytona894fe72012-04-05 16:12:35 +0000454 ExecutionContext exe_ctx (m_opaque_sp.get());
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000455 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytonf4124de2012-02-21 00:09:25 +0000456 if (exe_ctx.HasThreadScope())
Greg Claytonbdcda462010-12-20 20:49:23 +0000457 {
Greg Claytona894fe72012-04-05 16:12:35 +0000458 Process::StopLocker stop_locker;
459 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
460 {
461 Mutex::Locker api_locker (exe_ctx.GetTargetPtr()->GetAPIMutex());
462 name = exe_ctx.GetThreadPtr()->GetQueueName();
463 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000464 else
465 {
466 if (log)
467 log->Printf ("SBThread(%p)::GetQueueName() => error: process is running", exe_ctx.GetThreadPtr());
468 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000469 }
Greg Claytona66ba462010-10-30 04:51:46 +0000470
Caroline Tice7826c882010-10-26 03:11:13 +0000471 if (log)
Greg Claytonf4124de2012-02-21 00:09:25 +0000472 log->Printf ("SBThread(%p)::GetQueueName () => %s", exe_ctx.GetThreadPtr(), name ? name : "NULL");
Caroline Tice7826c882010-10-26 03:11:13 +0000473
Greg Claytona66ba462010-10-30 04:51:46 +0000474 return name;
Chris Lattner24943d22010-06-08 16:52:24 +0000475}
476
Jim Ingham88e3de22012-05-03 21:19:36 +0000477SBError
478SBThread::ResumeNewPlan (ExecutionContext &exe_ctx, ThreadPlan *new_plan)
479{
480 SBError sb_error;
481
482 Process *process = exe_ctx.GetProcessPtr();
483 if (!process)
484 {
485 sb_error.SetErrorString("No process in SBThread::ResumeNewPlan");
486 return sb_error;
487 }
488
489 Thread *thread = exe_ctx.GetThreadPtr();
490 if (!thread)
491 {
492 sb_error.SetErrorString("No thread in SBThread::ResumeNewPlan");
493 return sb_error;
494 }
495
496 // User level plans should be Master Plans so they can be interrupted, other plans executed, and
497 // then a "continue" will resume the plan.
498 if (new_plan != NULL)
499 {
500 new_plan->SetIsMasterPlan(true);
501 new_plan->SetOkayToDiscard(false);
502 }
503
504 // Why do we need to set the current thread by ID here???
505 process->GetThreadList().SetSelectedThreadByID (thread->GetID());
506 sb_error.ref() = process->Resume();
507
508 if (sb_error.Success())
509 {
510 // If we are doing synchronous mode, then wait for the
511 // process to stop yet again!
512 if (process->GetTarget().GetDebugger().GetAsyncExecution () == false)
513 process->WaitForProcessToStop (NULL);
514 }
515
516 return sb_error;
517}
Chris Lattner24943d22010-06-08 16:52:24 +0000518
519void
Chris Lattner24943d22010-06-08 16:52:24 +0000520SBThread::StepOver (lldb::RunMode stop_other_threads)
521{
Greg Claytone005f2c2010-11-06 01:53:30 +0000522 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000523
Greg Claytona894fe72012-04-05 16:12:35 +0000524 ExecutionContext exe_ctx (m_opaque_sp.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000525
Greg Clayton90c52142012-01-30 02:53:15 +0000526 if (log)
Greg Claytonf4124de2012-02-21 00:09:25 +0000527 log->Printf ("SBThread(%p)::StepOver (stop_other_threads='%s')", exe_ctx.GetThreadPtr(),
Greg Clayton90c52142012-01-30 02:53:15 +0000528 Thread::RunModeAsCString (stop_other_threads));
529
Greg Claytonf4124de2012-02-21 00:09:25 +0000530 if (exe_ctx.HasThreadScope())
Chris Lattner24943d22010-06-08 16:52:24 +0000531 {
Greg Claytonf4124de2012-02-21 00:09:25 +0000532 Mutex::Locker api_locker (exe_ctx.GetTargetPtr()->GetAPIMutex());
533 Thread *thread = exe_ctx.GetThreadPtr();
Jim Inghamd82bc6d2012-05-11 23:47:32 +0000534 bool abort_other_plans = false;
Greg Claytonf4124de2012-02-21 00:09:25 +0000535 StackFrameSP frame_sp(thread->GetStackFrameAtIndex (0));
Jim Ingham88e3de22012-05-03 21:19:36 +0000536 ThreadPlan *new_plan = NULL;
Chris Lattner24943d22010-06-08 16:52:24 +0000537
538 if (frame_sp)
539 {
540 if (frame_sp->HasDebugInformation ())
541 {
542 SymbolContext sc(frame_sp->GetSymbolContext(eSymbolContextEverything));
Jim Ingham88e3de22012-05-03 21:19:36 +0000543 new_plan = thread->QueueThreadPlanForStepRange (abort_other_plans,
544 eStepTypeOver,
545 sc.line_entry.range,
546 sc,
547 stop_other_threads,
548 false);
Chris Lattner24943d22010-06-08 16:52:24 +0000549
550 }
551 else
552 {
Jim Ingham88e3de22012-05-03 21:19:36 +0000553 new_plan = thread->QueueThreadPlanForStepSingleInstruction (true,
554 abort_other_plans,
555 stop_other_threads);
Chris Lattner24943d22010-06-08 16:52:24 +0000556 }
557 }
558
Jim Ingham88e3de22012-05-03 21:19:36 +0000559 // This returns an error, we should use it!
560 ResumeNewPlan (exe_ctx, new_plan);
Chris Lattner24943d22010-06-08 16:52:24 +0000561 }
562}
563
564void
565SBThread::StepInto (lldb::RunMode stop_other_threads)
566{
Greg Claytone005f2c2010-11-06 01:53:30 +0000567 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000568
Greg Claytona894fe72012-04-05 16:12:35 +0000569 ExecutionContext exe_ctx (m_opaque_sp.get());
Greg Clayton90c52142012-01-30 02:53:15 +0000570
571 if (log)
Greg Claytonf4124de2012-02-21 00:09:25 +0000572 log->Printf ("SBThread(%p)::StepInto (stop_other_threads='%s')", exe_ctx.GetThreadPtr(),
Greg Clayton90c52142012-01-30 02:53:15 +0000573 Thread::RunModeAsCString (stop_other_threads));
Greg Claytonf4124de2012-02-21 00:09:25 +0000574 if (exe_ctx.HasThreadScope())
Chris Lattner24943d22010-06-08 16:52:24 +0000575 {
Greg Claytonf4124de2012-02-21 00:09:25 +0000576 Mutex::Locker api_locker (exe_ctx.GetTargetPtr()->GetAPIMutex());
Jim Inghamd82bc6d2012-05-11 23:47:32 +0000577 bool abort_other_plans = false;
Chris Lattner24943d22010-06-08 16:52:24 +0000578
Greg Claytonf4124de2012-02-21 00:09:25 +0000579 Thread *thread = exe_ctx.GetThreadPtr();
580 StackFrameSP frame_sp(thread->GetStackFrameAtIndex (0));
Jim Ingham88e3de22012-05-03 21:19:36 +0000581 ThreadPlan *new_plan = NULL;
Chris Lattner24943d22010-06-08 16:52:24 +0000582
583 if (frame_sp && frame_sp->HasDebugInformation ())
584 {
Greg Clayton8f5fd6b2010-06-12 18:59:55 +0000585 bool avoid_code_without_debug_info = true;
Chris Lattner24943d22010-06-08 16:52:24 +0000586 SymbolContext sc(frame_sp->GetSymbolContext(eSymbolContextEverything));
Jim Ingham88e3de22012-05-03 21:19:36 +0000587 new_plan = thread->QueueThreadPlanForStepRange (abort_other_plans,
588 eStepTypeInto,
589 sc.line_entry.range,
590 sc,
591 stop_other_threads,
592 avoid_code_without_debug_info);
Chris Lattner24943d22010-06-08 16:52:24 +0000593 }
594 else
595 {
Jim Ingham88e3de22012-05-03 21:19:36 +0000596 new_plan = thread->QueueThreadPlanForStepSingleInstruction (false,
597 abort_other_plans,
598 stop_other_threads);
Chris Lattner24943d22010-06-08 16:52:24 +0000599 }
Jim Ingham88e3de22012-05-03 21:19:36 +0000600
601 // This returns an error, we should use it!
602 ResumeNewPlan (exe_ctx, new_plan);
Chris Lattner24943d22010-06-08 16:52:24 +0000603 }
604}
605
606void
607SBThread::StepOut ()
608{
Greg Claytone005f2c2010-11-06 01:53:30 +0000609 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000610
Greg Claytona894fe72012-04-05 16:12:35 +0000611 ExecutionContext exe_ctx (m_opaque_sp.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000612
Greg Clayton90c52142012-01-30 02:53:15 +0000613 if (log)
Greg Claytonf4124de2012-02-21 00:09:25 +0000614 log->Printf ("SBThread(%p)::StepOut ()", exe_ctx.GetThreadPtr());
Greg Clayton90c52142012-01-30 02:53:15 +0000615
Greg Claytonf4124de2012-02-21 00:09:25 +0000616 if (exe_ctx.HasThreadScope())
Chris Lattner24943d22010-06-08 16:52:24 +0000617 {
Greg Claytonf4124de2012-02-21 00:09:25 +0000618 Mutex::Locker api_locker (exe_ctx.GetTargetPtr()->GetAPIMutex());
Jim Inghamd82bc6d2012-05-11 23:47:32 +0000619 bool abort_other_plans = false;
Chris Lattner24943d22010-06-08 16:52:24 +0000620 bool stop_other_threads = true;
621
Greg Claytonf4124de2012-02-21 00:09:25 +0000622 Thread *thread = exe_ctx.GetThreadPtr();
623
Jim Ingham88e3de22012-05-03 21:19:36 +0000624 ThreadPlan *new_plan = thread->QueueThreadPlanForStepOut (abort_other_plans,
625 NULL,
626 false,
627 stop_other_threads,
628 eVoteYes,
629 eVoteNoOpinion,
630 0);
631
632 // This returns an error, we should use it!
633 ResumeNewPlan (exe_ctx, new_plan);
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000634 }
635}
Chris Lattner24943d22010-06-08 16:52:24 +0000636
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000637void
638SBThread::StepOutOfFrame (lldb::SBFrame &sb_frame)
639{
640 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
641
Greg Claytona894fe72012-04-05 16:12:35 +0000642 ExecutionContext exe_ctx (m_opaque_sp.get());
Greg Clayton334d33a2012-01-30 07:41:31 +0000643 StackFrameSP frame_sp (sb_frame.GetFrameSP());
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000644 if (log)
645 {
646 SBStream frame_desc_strm;
647 sb_frame.GetDescription (frame_desc_strm);
Greg Claytonf4124de2012-02-21 00:09:25 +0000648 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 +0000649 }
650
Greg Claytonf4124de2012-02-21 00:09:25 +0000651 if (exe_ctx.HasThreadScope())
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000652 {
Greg Claytonf4124de2012-02-21 00:09:25 +0000653 Mutex::Locker api_locker (exe_ctx.GetTargetPtr()->GetAPIMutex());
Jim Inghamd82bc6d2012-05-11 23:47:32 +0000654 bool abort_other_plans = false;
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000655 bool stop_other_threads = true;
Greg Claytonf4124de2012-02-21 00:09:25 +0000656 Thread *thread = exe_ctx.GetThreadPtr();
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000657
Jim Ingham88e3de22012-05-03 21:19:36 +0000658 ThreadPlan *new_plan = thread->QueueThreadPlanForStepOut (abort_other_plans,
659 NULL,
660 false,
661 stop_other_threads,
662 eVoteYes,
663 eVoteNoOpinion,
664 frame_sp->GetFrameIndex());
665
666 // This returns an error, we should use it!
667 ResumeNewPlan (exe_ctx, new_plan);
Chris Lattner24943d22010-06-08 16:52:24 +0000668 }
669}
670
671void
672SBThread::StepInstruction (bool step_over)
673{
Greg Claytone005f2c2010-11-06 01:53:30 +0000674 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000675
Greg Claytona894fe72012-04-05 16:12:35 +0000676 ExecutionContext exe_ctx (m_opaque_sp.get());
Greg Claytonf4124de2012-02-21 00:09:25 +0000677
Caroline Tice7826c882010-10-26 03:11:13 +0000678
Greg Clayton90c52142012-01-30 02:53:15 +0000679 if (log)
Greg Claytonf4124de2012-02-21 00:09:25 +0000680 log->Printf ("SBThread(%p)::StepInstruction (step_over=%i)", exe_ctx.GetThreadPtr(), step_over);
Greg Clayton90c52142012-01-30 02:53:15 +0000681
Greg Claytonf4124de2012-02-21 00:09:25 +0000682 if (exe_ctx.HasThreadScope())
Chris Lattner24943d22010-06-08 16:52:24 +0000683 {
Greg Claytonf4124de2012-02-21 00:09:25 +0000684 Mutex::Locker api_locker (exe_ctx.GetTargetPtr()->GetAPIMutex());
685 Thread *thread = exe_ctx.GetThreadPtr();
Jim Ingham88e3de22012-05-03 21:19:36 +0000686 ThreadPlan *new_plan = thread->QueueThreadPlanForStepSingleInstruction (step_over, true, true);
687
688 // This returns an error, we should use it!
689 ResumeNewPlan (exe_ctx, new_plan);
Chris Lattner24943d22010-06-08 16:52:24 +0000690 }
691}
692
693void
694SBThread::RunToAddress (lldb::addr_t addr)
695{
Greg Claytone005f2c2010-11-06 01:53:30 +0000696 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000697
Greg Claytona894fe72012-04-05 16:12:35 +0000698 ExecutionContext exe_ctx (m_opaque_sp.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000699
Greg Clayton90c52142012-01-30 02:53:15 +0000700 if (log)
Greg Claytonf4124de2012-02-21 00:09:25 +0000701 log->Printf ("SBThread(%p)::RunToAddress (addr=0x%llx)", exe_ctx.GetThreadPtr(), addr);
Greg Clayton90c52142012-01-30 02:53:15 +0000702
Greg Claytonf4124de2012-02-21 00:09:25 +0000703 if (exe_ctx.HasThreadScope())
Chris Lattner24943d22010-06-08 16:52:24 +0000704 {
Greg Claytonf4124de2012-02-21 00:09:25 +0000705 Mutex::Locker api_locker (exe_ctx.GetTargetPtr()->GetAPIMutex());
Jim Inghamd82bc6d2012-05-11 23:47:32 +0000706 bool abort_other_plans = false;
Chris Lattner24943d22010-06-08 16:52:24 +0000707 bool stop_other_threads = true;
708
Greg Clayton3508c382012-02-24 01:59:29 +0000709 Address target_addr (addr);
Chris Lattner24943d22010-06-08 16:52:24 +0000710
Greg Claytonf4124de2012-02-21 00:09:25 +0000711 Thread *thread = exe_ctx.GetThreadPtr();
Greg Claytonf4124de2012-02-21 00:09:25 +0000712
Jim Ingham88e3de22012-05-03 21:19:36 +0000713 ThreadPlan *new_plan = thread->QueueThreadPlanForRunToAddress (abort_other_plans, target_addr, stop_other_threads);
714
715 // This returns an error, we should use it!
716 ResumeNewPlan (exe_ctx, new_plan);
Chris Lattner24943d22010-06-08 16:52:24 +0000717 }
Chris Lattner24943d22010-06-08 16:52:24 +0000718}
719
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000720SBError
721SBThread::StepOverUntil (lldb::SBFrame &sb_frame,
722 lldb::SBFileSpec &sb_file_spec,
723 uint32_t line)
724{
725 SBError sb_error;
726 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
727 char path[PATH_MAX];
Greg Clayton90c52142012-01-30 02:53:15 +0000728
Greg Claytona894fe72012-04-05 16:12:35 +0000729 ExecutionContext exe_ctx (m_opaque_sp.get());
Greg Clayton334d33a2012-01-30 07:41:31 +0000730 StackFrameSP frame_sp (sb_frame.GetFrameSP());
731
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000732 if (log)
733 {
734 SBStream frame_desc_strm;
735 sb_frame.GetDescription (frame_desc_strm);
736 sb_file_spec->GetPath (path, sizeof(path));
737 log->Printf ("SBThread(%p)::StepOverUntil (frame = SBFrame(%p): %s, file+line = %s:%u)",
Greg Claytonf4124de2012-02-21 00:09:25 +0000738 exe_ctx.GetThreadPtr(),
Greg Clayton334d33a2012-01-30 07:41:31 +0000739 frame_sp.get(),
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000740 frame_desc_strm.GetData(),
741 path, line);
742 }
Greg Clayton90c52142012-01-30 02:53:15 +0000743
Greg Claytonf4124de2012-02-21 00:09:25 +0000744 if (exe_ctx.HasThreadScope())
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000745 {
Greg Claytonf4124de2012-02-21 00:09:25 +0000746 Target *target = exe_ctx.GetTargetPtr();
747 Mutex::Locker api_locker (target->GetAPIMutex());
748 Thread *thread = exe_ctx.GetThreadPtr();
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000749
750 if (line == 0)
751 {
752 sb_error.SetErrorString("invalid line argument");
753 return sb_error;
754 }
755
756 StackFrameSP frame_sp;
Greg Clayton334d33a2012-01-30 07:41:31 +0000757 if (!frame_sp)
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000758 {
Greg Claytonf4124de2012-02-21 00:09:25 +0000759 frame_sp = thread->GetSelectedFrame ();
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000760 if (!frame_sp)
Greg Claytonf4124de2012-02-21 00:09:25 +0000761 frame_sp = thread->GetStackFrameAtIndex (0);
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000762 }
763
764 SymbolContext frame_sc;
765 if (!frame_sp)
766 {
767 sb_error.SetErrorString("no valid frames in thread to step");
768 return sb_error;
769 }
770
771 // If we have a frame, get its line
772 frame_sc = frame_sp->GetSymbolContext (eSymbolContextCompUnit |
773 eSymbolContextFunction |
774 eSymbolContextLineEntry |
775 eSymbolContextSymbol );
776
777 if (frame_sc.comp_unit == NULL)
778 {
779 sb_error.SetErrorStringWithFormat("frame %u doesn't have debug information", frame_sp->GetFrameIndex());
780 return sb_error;
781 }
782
783 FileSpec step_file_spec;
784 if (sb_file_spec.IsValid())
785 {
786 // The file spec passed in was valid, so use it
787 step_file_spec = sb_file_spec.ref();
788 }
789 else
790 {
791 if (frame_sc.line_entry.IsValid())
792 step_file_spec = frame_sc.line_entry.file;
793 else
794 {
795 sb_error.SetErrorString("invalid file argument or no file for frame");
796 return sb_error;
797 }
798 }
799
Jim Inghamb07c62a2011-05-08 00:56:32 +0000800 // Grab the current function, then we will make sure the "until" address is
801 // within the function. We discard addresses that are out of the current
802 // function, and then if there are no addresses remaining, give an appropriate
803 // error message.
804
805 bool all_in_function = true;
806 AddressRange fun_range = frame_sc.function->GetAddressRange();
807
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000808 std::vector<addr_t> step_over_until_addrs;
Jim Inghamd82bc6d2012-05-11 23:47:32 +0000809 const bool abort_other_plans = false;
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000810 const bool stop_other_threads = true;
811 const bool check_inlines = true;
812 const bool exact = false;
813
814 SymbolContextList sc_list;
Jim Inghamb07c62a2011-05-08 00:56:32 +0000815 const uint32_t num_matches = frame_sc.comp_unit->ResolveSymbolContext (step_file_spec,
816 line,
817 check_inlines,
818 exact,
819 eSymbolContextLineEntry,
820 sc_list);
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000821 if (num_matches > 0)
822 {
823 SymbolContext sc;
824 for (uint32_t i=0; i<num_matches; ++i)
825 {
826 if (sc_list.GetContextAtIndex(i, sc))
827 {
Jim Inghamb07c62a2011-05-08 00:56:32 +0000828 addr_t step_addr = sc.line_entry.range.GetBaseAddress().GetLoadAddress(target);
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000829 if (step_addr != LLDB_INVALID_ADDRESS)
830 {
Jim Inghamb07c62a2011-05-08 00:56:32 +0000831 if (fun_range.ContainsLoadAddress(step_addr, target))
832 step_over_until_addrs.push_back(step_addr);
833 else
834 all_in_function = false;
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000835 }
836 }
837 }
838 }
Jim Inghamb07c62a2011-05-08 00:56:32 +0000839
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000840 if (step_over_until_addrs.empty())
841 {
Jim Inghamb07c62a2011-05-08 00:56:32 +0000842 if (all_in_function)
843 {
844 step_file_spec.GetPath (path, sizeof(path));
Jason Molenda7e5fa7f2011-09-20 21:44:10 +0000845 sb_error.SetErrorStringWithFormat("No line entries for %s:%u", path, line);
Jim Inghamb07c62a2011-05-08 00:56:32 +0000846 }
847 else
Greg Clayton9c236732011-10-26 00:56:27 +0000848 sb_error.SetErrorString ("step until target not in current function");
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000849 }
850 else
851 {
Jim Ingham88e3de22012-05-03 21:19:36 +0000852 ThreadPlan *new_plan = thread->QueueThreadPlanForStepUntil (abort_other_plans,
853 &step_over_until_addrs[0],
854 step_over_until_addrs.size(),
855 stop_other_threads,
856 frame_sp->GetFrameIndex());
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000857
Jim Ingham88e3de22012-05-03 21:19:36 +0000858 sb_error = ResumeNewPlan (exe_ctx, new_plan);
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000859 }
860 }
861 else
862 {
863 sb_error.SetErrorString("this SBThread object is invalid");
864 }
865 return sb_error;
866}
867
868
Greg Clayton123db402011-01-12 02:25:42 +0000869bool
870SBThread::Suspend()
871{
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000872 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona894fe72012-04-05 16:12:35 +0000873 ExecutionContext exe_ctx (m_opaque_sp.get());
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000874 bool result = false;
Greg Claytonf4124de2012-02-21 00:09:25 +0000875 if (exe_ctx.HasThreadScope())
Greg Clayton123db402011-01-12 02:25:42 +0000876 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000877 Process::StopLocker stop_locker;
878 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
879 {
880 exe_ctx.GetThreadPtr()->SetResumeState (eStateSuspended);
881 result = true;
882 }
883 else
884 {
885 if (log)
886 log->Printf ("SBThread(%p)::Suspend() => error: process is running", exe_ctx.GetThreadPtr());
887 }
Greg Clayton123db402011-01-12 02:25:42 +0000888 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000889 if (log)
890 log->Printf ("SBThread(%p)::Suspend() => %i", exe_ctx.GetThreadPtr(), result);
891 return result;
Greg Clayton123db402011-01-12 02:25:42 +0000892}
893
894bool
895SBThread::Resume ()
896{
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000897 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona894fe72012-04-05 16:12:35 +0000898 ExecutionContext exe_ctx (m_opaque_sp.get());
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000899 bool result = false;
Greg Claytonf4124de2012-02-21 00:09:25 +0000900 if (exe_ctx.HasThreadScope())
Greg Clayton123db402011-01-12 02:25:42 +0000901 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000902 Process::StopLocker stop_locker;
903 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
904 {
905 exe_ctx.GetThreadPtr()->SetResumeState (eStateRunning);
906 result = true;
907 }
908 else
909 {
910 if (log)
911 log->Printf ("SBThread(%p)::Resume() => error: process is running", exe_ctx.GetThreadPtr());
912 }
Greg Clayton123db402011-01-12 02:25:42 +0000913 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000914 if (log)
915 log->Printf ("SBThread(%p)::Resume() => %i", exe_ctx.GetThreadPtr(), result);
916 return result;
Greg Clayton123db402011-01-12 02:25:42 +0000917}
918
919bool
920SBThread::IsSuspended()
921{
Greg Claytona894fe72012-04-05 16:12:35 +0000922 ExecutionContext exe_ctx (m_opaque_sp.get());
Greg Claytonf4124de2012-02-21 00:09:25 +0000923 if (exe_ctx.HasThreadScope())
924 return exe_ctx.GetThreadPtr()->GetResumeState () == eStateSuspended;
Greg Clayton123db402011-01-12 02:25:42 +0000925 return false;
926}
927
Chris Lattner24943d22010-06-08 16:52:24 +0000928SBProcess
929SBThread::GetProcess ()
930{
Caroline Tice7826c882010-10-26 03:11:13 +0000931
Greg Clayton334d33a2012-01-30 07:41:31 +0000932 SBProcess sb_process;
933 ProcessSP process_sp;
Greg Claytona894fe72012-04-05 16:12:35 +0000934 ExecutionContext exe_ctx (m_opaque_sp.get());
Greg Claytonf4124de2012-02-21 00:09:25 +0000935 if (exe_ctx.HasThreadScope())
Chris Lattner24943d22010-06-08 16:52:24 +0000936 {
937 // Have to go up to the target so we can get a shared pointer to our process...
Greg Claytonf4124de2012-02-21 00:09:25 +0000938 sb_process.SetSP (exe_ctx.GetProcessSP());
Chris Lattner24943d22010-06-08 16:52:24 +0000939 }
Caroline Tice7826c882010-10-26 03:11:13 +0000940
Greg Claytone005f2c2010-11-06 01:53:30 +0000941 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000942 if (log)
943 {
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000944 SBStream frame_desc_strm;
Greg Clayton334d33a2012-01-30 07:41:31 +0000945 sb_process.GetDescription (frame_desc_strm);
Greg Claytonf4124de2012-02-21 00:09:25 +0000946 log->Printf ("SBThread(%p)::GetProcess () => SBProcess(%p): %s", exe_ctx.GetThreadPtr(),
Greg Clayton334d33a2012-01-30 07:41:31 +0000947 process_sp.get(), frame_desc_strm.GetData());
Caroline Tice7826c882010-10-26 03:11:13 +0000948 }
949
Greg Clayton334d33a2012-01-30 07:41:31 +0000950 return sb_process;
Chris Lattner24943d22010-06-08 16:52:24 +0000951}
952
953uint32_t
954SBThread::GetNumFrames ()
955{
Greg Claytone005f2c2010-11-06 01:53:30 +0000956 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000957
Caroline Tice7826c882010-10-26 03:11:13 +0000958 uint32_t num_frames = 0;
Greg Claytona894fe72012-04-05 16:12:35 +0000959 ExecutionContext exe_ctx (m_opaque_sp.get());
Greg Claytonf4124de2012-02-21 00:09:25 +0000960 if (exe_ctx.HasThreadScope())
Greg Claytonbdcda462010-12-20 20:49:23 +0000961 {
Greg Claytona894fe72012-04-05 16:12:35 +0000962 Process::StopLocker stop_locker;
963 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
964 {
965 Mutex::Locker api_locker (exe_ctx.GetTargetPtr()->GetAPIMutex());
966 num_frames = exe_ctx.GetThreadPtr()->GetStackFrameCount();
967 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000968 else
969 {
970 if (log)
971 log->Printf ("SBThread(%p)::GetNumFrames() => error: process is running", exe_ctx.GetThreadPtr());
972 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000973 }
Caroline Tice7826c882010-10-26 03:11:13 +0000974
975 if (log)
Greg Claytonf4124de2012-02-21 00:09:25 +0000976 log->Printf ("SBThread(%p)::GetNumFrames () => %u", exe_ctx.GetThreadPtr(), num_frames);
Caroline Tice7826c882010-10-26 03:11:13 +0000977
978 return num_frames;
Chris Lattner24943d22010-06-08 16:52:24 +0000979}
980
981SBFrame
982SBThread::GetFrameAtIndex (uint32_t idx)
983{
Greg Claytone005f2c2010-11-06 01:53:30 +0000984 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000985
Chris Lattner24943d22010-06-08 16:52:24 +0000986 SBFrame sb_frame;
Greg Clayton334d33a2012-01-30 07:41:31 +0000987 StackFrameSP frame_sp;
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())
Greg Claytonbdcda462010-12-20 20:49:23 +0000990 {
Greg Claytona894fe72012-04-05 16:12:35 +0000991 Process::StopLocker stop_locker;
992 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
993 {
994 Mutex::Locker api_locker (exe_ctx.GetTargetPtr()->GetAPIMutex());
995 frame_sp = exe_ctx.GetThreadPtr()->GetStackFrameAtIndex (idx);
996 sb_frame.SetFrameSP (frame_sp);
997 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000998 else
999 {
1000 if (log)
1001 log->Printf ("SBThread(%p)::GetFrameAtIndex() => error: process is running", exe_ctx.GetThreadPtr());
1002 }
Greg Claytonbdcda462010-12-20 20:49:23 +00001003 }
Caroline Tice7826c882010-10-26 03:11:13 +00001004
1005 if (log)
1006 {
Greg Clayton1ebdcc72011-01-21 06:11:58 +00001007 SBStream frame_desc_strm;
1008 sb_frame.GetDescription (frame_desc_strm);
Greg Claytona66ba462010-10-30 04:51:46 +00001009 log->Printf ("SBThread(%p)::GetFrameAtIndex (idx=%d) => SBFrame(%p): %s",
Greg Claytonf4124de2012-02-21 00:09:25 +00001010 exe_ctx.GetThreadPtr(), idx, frame_sp.get(), frame_desc_strm.GetData());
Caroline Tice7826c882010-10-26 03:11:13 +00001011 }
1012
Chris Lattner24943d22010-06-08 16:52:24 +00001013 return sb_frame;
1014}
1015
Greg Claytonc5157ec2010-12-17 02:26:24 +00001016lldb::SBFrame
1017SBThread::GetSelectedFrame ()
1018{
1019 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1020
1021 SBFrame sb_frame;
Greg Clayton334d33a2012-01-30 07:41:31 +00001022 StackFrameSP frame_sp;
Greg Claytona894fe72012-04-05 16:12:35 +00001023 ExecutionContext exe_ctx (m_opaque_sp.get());
Greg Claytonf4124de2012-02-21 00:09:25 +00001024 if (exe_ctx.HasThreadScope())
Greg Claytonbdcda462010-12-20 20:49:23 +00001025 {
Greg Claytona894fe72012-04-05 16:12:35 +00001026 Process::StopLocker stop_locker;
1027 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
1028 {
1029 Mutex::Locker api_locker (exe_ctx.GetTargetPtr()->GetAPIMutex());
1030 frame_sp = exe_ctx.GetThreadPtr()->GetSelectedFrame ();
1031 sb_frame.SetFrameSP (frame_sp);
1032 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001033 else
1034 {
1035 if (log)
1036 log->Printf ("SBThread(%p)::GetSelectedFrame() => error: process is running", exe_ctx.GetThreadPtr());
1037 }
Greg Claytonbdcda462010-12-20 20:49:23 +00001038 }
Greg Claytonc5157ec2010-12-17 02:26:24 +00001039
1040 if (log)
1041 {
Greg Clayton1ebdcc72011-01-21 06:11:58 +00001042 SBStream frame_desc_strm;
1043 sb_frame.GetDescription (frame_desc_strm);
Greg Claytonc5157ec2010-12-17 02:26:24 +00001044 log->Printf ("SBThread(%p)::GetSelectedFrame () => SBFrame(%p): %s",
Greg Claytonf4124de2012-02-21 00:09:25 +00001045 exe_ctx.GetThreadPtr(), frame_sp.get(), frame_desc_strm.GetData());
Greg Claytonc5157ec2010-12-17 02:26:24 +00001046 }
1047
1048 return sb_frame;
1049}
1050
1051lldb::SBFrame
1052SBThread::SetSelectedFrame (uint32_t idx)
1053{
1054 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1055
1056 SBFrame sb_frame;
Greg Clayton334d33a2012-01-30 07:41:31 +00001057 StackFrameSP frame_sp;
Greg Claytona894fe72012-04-05 16:12:35 +00001058 ExecutionContext exe_ctx (m_opaque_sp.get());
Greg Claytonf4124de2012-02-21 00:09:25 +00001059 if (exe_ctx.HasThreadScope())
Greg Claytonc5157ec2010-12-17 02:26:24 +00001060 {
Greg Claytona894fe72012-04-05 16:12:35 +00001061 Process::StopLocker stop_locker;
1062 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
Greg Claytonc5157ec2010-12-17 02:26:24 +00001063 {
Greg Claytona894fe72012-04-05 16:12:35 +00001064 Mutex::Locker api_locker (exe_ctx.GetTargetPtr()->GetAPIMutex());
1065 Thread *thread = exe_ctx.GetThreadPtr();
1066 frame_sp = thread->GetStackFrameAtIndex (idx);
1067 if (frame_sp)
1068 {
1069 thread->SetSelectedFrame (frame_sp.get());
1070 sb_frame.SetFrameSP (frame_sp);
1071 }
Greg Claytonc5157ec2010-12-17 02:26:24 +00001072 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001073 else
1074 {
1075 if (log)
1076 log->Printf ("SBThread(%p)::SetSelectedFrame() => error: process is running", exe_ctx.GetThreadPtr());
1077 }
Greg Claytonc5157ec2010-12-17 02:26:24 +00001078 }
1079
1080 if (log)
1081 {
Greg Clayton1ebdcc72011-01-21 06:11:58 +00001082 SBStream frame_desc_strm;
1083 sb_frame.GetDescription (frame_desc_strm);
Greg Claytonc5157ec2010-12-17 02:26:24 +00001084 log->Printf ("SBThread(%p)::SetSelectedFrame (idx=%u) => SBFrame(%p): %s",
Greg Claytonf4124de2012-02-21 00:09:25 +00001085 exe_ctx.GetThreadPtr(), idx, frame_sp.get(), frame_desc_strm.GetData());
Greg Claytonc5157ec2010-12-17 02:26:24 +00001086 }
1087 return sb_frame;
1088}
1089
1090
Chris Lattner24943d22010-06-08 16:52:24 +00001091bool
1092SBThread::operator == (const SBThread &rhs) const
1093{
Greg Claytona894fe72012-04-05 16:12:35 +00001094 return m_opaque_sp->GetThreadSP().get() == rhs.m_opaque_sp->GetThreadSP().get();
Chris Lattner24943d22010-06-08 16:52:24 +00001095}
1096
1097bool
1098SBThread::operator != (const SBThread &rhs) const
1099{
Greg Claytona894fe72012-04-05 16:12:35 +00001100 return m_opaque_sp->GetThreadSP().get() != rhs.m_opaque_sp->GetThreadSP().get();
Chris Lattner24943d22010-06-08 16:52:24 +00001101}
Caroline Tice98f930f2010-09-20 05:20:02 +00001102
1103bool
Caroline Tice7826c882010-10-26 03:11:13 +00001104SBThread::GetDescription (SBStream &description) const
1105{
Greg Clayton96154be2011-11-13 06:57:31 +00001106 Stream &strm = description.ref();
1107
Greg Claytona894fe72012-04-05 16:12:35 +00001108 ExecutionContext exe_ctx (m_opaque_sp.get());
Greg Claytonf4124de2012-02-21 00:09:25 +00001109 if (exe_ctx.HasThreadScope())
Caroline Tice7826c882010-10-26 03:11:13 +00001110 {
Greg Claytonf4124de2012-02-21 00:09:25 +00001111 strm.Printf("SBThread: tid = 0x%4.4llx", exe_ctx.GetThreadPtr()->GetID());
Caroline Tice7826c882010-10-26 03:11:13 +00001112 }
1113 else
Greg Clayton96154be2011-11-13 06:57:31 +00001114 strm.PutCString ("No value");
Caroline Tice7826c882010-10-26 03:11:13 +00001115
1116 return true;
1117}