blob: 811096728fd11bf967f15035c0ef0e921ed085ef [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
477
478void
Chris Lattner24943d22010-06-08 16:52:24 +0000479SBThread::StepOver (lldb::RunMode stop_other_threads)
480{
Greg Claytone005f2c2010-11-06 01:53:30 +0000481 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000482
Greg Claytona894fe72012-04-05 16:12:35 +0000483 ExecutionContext exe_ctx (m_opaque_sp.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000484
Greg Clayton90c52142012-01-30 02:53:15 +0000485 if (log)
Greg Claytonf4124de2012-02-21 00:09:25 +0000486 log->Printf ("SBThread(%p)::StepOver (stop_other_threads='%s')", exe_ctx.GetThreadPtr(),
Greg Clayton90c52142012-01-30 02:53:15 +0000487 Thread::RunModeAsCString (stop_other_threads));
488
Greg Claytonf4124de2012-02-21 00:09:25 +0000489 if (exe_ctx.HasThreadScope())
Chris Lattner24943d22010-06-08 16:52:24 +0000490 {
Greg Claytonf4124de2012-02-21 00:09:25 +0000491 Mutex::Locker api_locker (exe_ctx.GetTargetPtr()->GetAPIMutex());
492 Thread *thread = exe_ctx.GetThreadPtr();
Chris Lattner24943d22010-06-08 16:52:24 +0000493 bool abort_other_plans = true;
Greg Claytonf4124de2012-02-21 00:09:25 +0000494 StackFrameSP frame_sp(thread->GetStackFrameAtIndex (0));
Chris Lattner24943d22010-06-08 16:52:24 +0000495
496 if (frame_sp)
497 {
498 if (frame_sp->HasDebugInformation ())
499 {
500 SymbolContext sc(frame_sp->GetSymbolContext(eSymbolContextEverything));
Greg Claytonf4124de2012-02-21 00:09:25 +0000501 thread->QueueThreadPlanForStepRange (abort_other_plans,
Greg Clayton9af596d2012-03-28 17:12:37 +0000502 eStepTypeOver,
503 sc.line_entry.range,
504 sc,
505 stop_other_threads,
506 false);
Chris Lattner24943d22010-06-08 16:52:24 +0000507
508 }
509 else
510 {
Greg Claytonf4124de2012-02-21 00:09:25 +0000511 thread->QueueThreadPlanForStepSingleInstruction (true,
Greg Clayton9af596d2012-03-28 17:12:37 +0000512 abort_other_plans,
513 stop_other_threads);
Chris Lattner24943d22010-06-08 16:52:24 +0000514 }
515 }
516
Greg Claytonf4124de2012-02-21 00:09:25 +0000517 Process *process = exe_ctx.GetProcessPtr();
Chris Lattner24943d22010-06-08 16:52:24 +0000518 // Why do we need to set the current thread by ID here???
Greg Claytonf4124de2012-02-21 00:09:25 +0000519 process->GetThreadList().SetSelectedThreadByID (thread->GetID());
520 Error error (process->Resume());
Greg Clayton1a3083a2010-10-06 03:53:16 +0000521 if (error.Success())
522 {
523 // If we are doing synchronous mode, then wait for the
524 // process to stop yet again!
Greg Claytonf4124de2012-02-21 00:09:25 +0000525 if (process->GetTarget().GetDebugger().GetAsyncExecution () == false)
526 process->WaitForProcessToStop (NULL);
Greg Clayton1a3083a2010-10-06 03:53:16 +0000527 }
Chris Lattner24943d22010-06-08 16:52:24 +0000528 }
529}
530
531void
532SBThread::StepInto (lldb::RunMode stop_other_threads)
533{
Greg Claytone005f2c2010-11-06 01:53:30 +0000534 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000535
Greg Claytona894fe72012-04-05 16:12:35 +0000536 ExecutionContext exe_ctx (m_opaque_sp.get());
Greg Clayton90c52142012-01-30 02:53:15 +0000537
538 if (log)
Greg Claytonf4124de2012-02-21 00:09:25 +0000539 log->Printf ("SBThread(%p)::StepInto (stop_other_threads='%s')", exe_ctx.GetThreadPtr(),
Greg Clayton90c52142012-01-30 02:53:15 +0000540 Thread::RunModeAsCString (stop_other_threads));
Greg Claytonf4124de2012-02-21 00:09:25 +0000541 if (exe_ctx.HasThreadScope())
Chris Lattner24943d22010-06-08 16:52:24 +0000542 {
Greg Claytonf4124de2012-02-21 00:09:25 +0000543 Mutex::Locker api_locker (exe_ctx.GetTargetPtr()->GetAPIMutex());
Chris Lattner24943d22010-06-08 16:52:24 +0000544 bool abort_other_plans = true;
545
Greg Claytonf4124de2012-02-21 00:09:25 +0000546 Thread *thread = exe_ctx.GetThreadPtr();
547 StackFrameSP frame_sp(thread->GetStackFrameAtIndex (0));
Chris Lattner24943d22010-06-08 16:52:24 +0000548
549 if (frame_sp && frame_sp->HasDebugInformation ())
550 {
Greg Clayton8f5fd6b2010-06-12 18:59:55 +0000551 bool avoid_code_without_debug_info = true;
Chris Lattner24943d22010-06-08 16:52:24 +0000552 SymbolContext sc(frame_sp->GetSymbolContext(eSymbolContextEverything));
Greg Claytonf4124de2012-02-21 00:09:25 +0000553 thread->QueueThreadPlanForStepRange (abort_other_plans,
554 eStepTypeInto,
555 sc.line_entry.range,
556 sc,
557 stop_other_threads,
558 avoid_code_without_debug_info);
Chris Lattner24943d22010-06-08 16:52:24 +0000559 }
560 else
561 {
Greg Claytonf4124de2012-02-21 00:09:25 +0000562 thread->QueueThreadPlanForStepSingleInstruction (false,
563 abort_other_plans,
564 stop_other_threads);
Chris Lattner24943d22010-06-08 16:52:24 +0000565 }
566
Greg Claytonf4124de2012-02-21 00:09:25 +0000567 Process *process = exe_ctx.GetProcessPtr();
Chris Lattner24943d22010-06-08 16:52:24 +0000568 // Why do we need to set the current thread by ID here???
Greg Claytonf4124de2012-02-21 00:09:25 +0000569 process->GetThreadList().SetSelectedThreadByID (thread->GetID());
570 Error error (process->Resume());
Greg Clayton1a3083a2010-10-06 03:53:16 +0000571 if (error.Success())
572 {
573 // If we are doing synchronous mode, then wait for the
574 // process to stop yet again!
Greg Claytonf4124de2012-02-21 00:09:25 +0000575 if (process->GetTarget().GetDebugger().GetAsyncExecution () == false)
576 process->WaitForProcessToStop (NULL);
Greg Clayton1a3083a2010-10-06 03:53:16 +0000577 }
Chris Lattner24943d22010-06-08 16:52:24 +0000578 }
579}
580
581void
582SBThread::StepOut ()
583{
Greg Claytone005f2c2010-11-06 01:53:30 +0000584 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000585
Greg Claytona894fe72012-04-05 16:12:35 +0000586 ExecutionContext exe_ctx (m_opaque_sp.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000587
Greg Clayton90c52142012-01-30 02:53:15 +0000588 if (log)
Greg Claytonf4124de2012-02-21 00:09:25 +0000589 log->Printf ("SBThread(%p)::StepOut ()", exe_ctx.GetThreadPtr());
Greg Clayton90c52142012-01-30 02:53:15 +0000590
Greg Claytonf4124de2012-02-21 00:09:25 +0000591 if (exe_ctx.HasThreadScope())
Chris Lattner24943d22010-06-08 16:52:24 +0000592 {
Greg Claytonf4124de2012-02-21 00:09:25 +0000593 Mutex::Locker api_locker (exe_ctx.GetTargetPtr()->GetAPIMutex());
Chris Lattner24943d22010-06-08 16:52:24 +0000594 bool abort_other_plans = true;
595 bool stop_other_threads = true;
596
Greg Claytonf4124de2012-02-21 00:09:25 +0000597 Thread *thread = exe_ctx.GetThreadPtr();
598
599 thread->QueueThreadPlanForStepOut (abort_other_plans,
Greg Clayton90c52142012-01-30 02:53:15 +0000600 NULL,
601 false,
602 stop_other_threads,
603 eVoteYes,
604 eVoteNoOpinion,
605 0);
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000606
Greg Claytonf4124de2012-02-21 00:09:25 +0000607 Process *process = exe_ctx.GetProcessPtr();
608 process->GetThreadList().SetSelectedThreadByID (thread->GetID());
609 Error error (process->Resume());
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000610 if (error.Success())
611 {
612 // If we are doing synchronous mode, then wait for the
613 // process to stop yet again!
Greg Claytonf4124de2012-02-21 00:09:25 +0000614 if (process->GetTarget().GetDebugger().GetAsyncExecution () == false)
615 process->WaitForProcessToStop (NULL);
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000616 }
617 }
618}
Chris Lattner24943d22010-06-08 16:52:24 +0000619
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000620void
621SBThread::StepOutOfFrame (lldb::SBFrame &sb_frame)
622{
623 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
624
Greg Claytona894fe72012-04-05 16:12:35 +0000625 ExecutionContext exe_ctx (m_opaque_sp.get());
Greg Clayton334d33a2012-01-30 07:41:31 +0000626 StackFrameSP frame_sp (sb_frame.GetFrameSP());
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000627 if (log)
628 {
629 SBStream frame_desc_strm;
630 sb_frame.GetDescription (frame_desc_strm);
Greg Claytonf4124de2012-02-21 00:09:25 +0000631 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 +0000632 }
633
Greg Claytonf4124de2012-02-21 00:09:25 +0000634 if (exe_ctx.HasThreadScope())
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000635 {
Greg Claytonf4124de2012-02-21 00:09:25 +0000636 Mutex::Locker api_locker (exe_ctx.GetTargetPtr()->GetAPIMutex());
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000637 bool abort_other_plans = true;
638 bool stop_other_threads = true;
Greg Claytonf4124de2012-02-21 00:09:25 +0000639 Thread *thread = exe_ctx.GetThreadPtr();
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000640
Greg Claytonf4124de2012-02-21 00:09:25 +0000641 thread->QueueThreadPlanForStepOut (abort_other_plans,
Greg Clayton90c52142012-01-30 02:53:15 +0000642 NULL,
643 false,
644 stop_other_threads,
645 eVoteYes,
646 eVoteNoOpinion,
Greg Clayton334d33a2012-01-30 07:41:31 +0000647 frame_sp->GetFrameIndex());
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000648
Greg Claytonf4124de2012-02-21 00:09:25 +0000649 Process *process = exe_ctx.GetProcessPtr();
650 process->GetThreadList().SetSelectedThreadByID (thread->GetID());
651 Error error (process->Resume());
Greg Clayton1a3083a2010-10-06 03:53:16 +0000652 if (error.Success())
653 {
654 // If we are doing synchronous mode, then wait for the
655 // process to stop yet again!
Greg Claytonf4124de2012-02-21 00:09:25 +0000656 if (process->GetTarget().GetDebugger().GetAsyncExecution () == false)
657 process->WaitForProcessToStop (NULL);
Greg Clayton1a3083a2010-10-06 03:53:16 +0000658 }
Chris Lattner24943d22010-06-08 16:52:24 +0000659 }
660}
661
662void
663SBThread::StepInstruction (bool step_over)
664{
Greg Claytone005f2c2010-11-06 01:53:30 +0000665 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000666
Greg Claytona894fe72012-04-05 16:12:35 +0000667 ExecutionContext exe_ctx (m_opaque_sp.get());
Greg Claytonf4124de2012-02-21 00:09:25 +0000668
Caroline Tice7826c882010-10-26 03:11:13 +0000669
Greg Clayton90c52142012-01-30 02:53:15 +0000670 if (log)
Greg Claytonf4124de2012-02-21 00:09:25 +0000671 log->Printf ("SBThread(%p)::StepInstruction (step_over=%i)", exe_ctx.GetThreadPtr(), step_over);
Greg Clayton90c52142012-01-30 02:53:15 +0000672
Greg Claytonf4124de2012-02-21 00:09:25 +0000673 if (exe_ctx.HasThreadScope())
Chris Lattner24943d22010-06-08 16:52:24 +0000674 {
Greg Claytonf4124de2012-02-21 00:09:25 +0000675 Mutex::Locker api_locker (exe_ctx.GetTargetPtr()->GetAPIMutex());
676 Thread *thread = exe_ctx.GetThreadPtr();
677 Process *process = exe_ctx.GetProcessPtr();
678 thread->QueueThreadPlanForStepSingleInstruction (step_over, true, true);
679 process->GetThreadList().SetSelectedThreadByID (thread->GetID());
680 Error error (process->Resume());
Greg Clayton1a3083a2010-10-06 03:53:16 +0000681 if (error.Success())
682 {
683 // If we are doing synchronous mode, then wait for the
684 // process to stop yet again!
Greg Claytonf4124de2012-02-21 00:09:25 +0000685 if (process->GetTarget().GetDebugger().GetAsyncExecution () == false)
686 process->WaitForProcessToStop (NULL);
Greg Clayton1a3083a2010-10-06 03:53:16 +0000687 }
Chris Lattner24943d22010-06-08 16:52:24 +0000688 }
689}
690
691void
692SBThread::RunToAddress (lldb::addr_t addr)
693{
Greg Claytone005f2c2010-11-06 01:53:30 +0000694 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000695
Greg Claytona894fe72012-04-05 16:12:35 +0000696 ExecutionContext exe_ctx (m_opaque_sp.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000697
Greg Clayton90c52142012-01-30 02:53:15 +0000698 if (log)
Greg Claytonf4124de2012-02-21 00:09:25 +0000699 log->Printf ("SBThread(%p)::RunToAddress (addr=0x%llx)", exe_ctx.GetThreadPtr(), addr);
Greg Clayton90c52142012-01-30 02:53:15 +0000700
Greg Claytonf4124de2012-02-21 00:09:25 +0000701 if (exe_ctx.HasThreadScope())
Chris Lattner24943d22010-06-08 16:52:24 +0000702 {
Greg Claytonf4124de2012-02-21 00:09:25 +0000703 Mutex::Locker api_locker (exe_ctx.GetTargetPtr()->GetAPIMutex());
Chris Lattner24943d22010-06-08 16:52:24 +0000704 bool abort_other_plans = true;
705 bool stop_other_threads = true;
706
Greg Clayton3508c382012-02-24 01:59:29 +0000707 Address target_addr (addr);
Chris Lattner24943d22010-06-08 16:52:24 +0000708
Greg Claytonf4124de2012-02-21 00:09:25 +0000709 Thread *thread = exe_ctx.GetThreadPtr();
710 Process *process = exe_ctx.GetProcessPtr();
711
712 thread->QueueThreadPlanForRunToAddress (abort_other_plans, target_addr, stop_other_threads);
713 process->GetThreadList().SetSelectedThreadByID (thread->GetID());
714 Error error (process->Resume());
Greg Clayton1a3083a2010-10-06 03:53:16 +0000715 if (error.Success())
716 {
717 // If we are doing synchronous mode, then wait for the
718 // process to stop yet again!
Greg Claytonf4124de2012-02-21 00:09:25 +0000719 if (process->GetTarget().GetDebugger().GetAsyncExecution () == false)
720 process->WaitForProcessToStop (NULL);
Greg Clayton1a3083a2010-10-06 03:53:16 +0000721 }
Chris Lattner24943d22010-06-08 16:52:24 +0000722 }
Chris Lattner24943d22010-06-08 16:52:24 +0000723}
724
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000725SBError
726SBThread::StepOverUntil (lldb::SBFrame &sb_frame,
727 lldb::SBFileSpec &sb_file_spec,
728 uint32_t line)
729{
730 SBError sb_error;
731 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
732 char path[PATH_MAX];
Greg Clayton90c52142012-01-30 02:53:15 +0000733
Greg Claytona894fe72012-04-05 16:12:35 +0000734 ExecutionContext exe_ctx (m_opaque_sp.get());
Greg Clayton334d33a2012-01-30 07:41:31 +0000735 StackFrameSP frame_sp (sb_frame.GetFrameSP());
736
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000737 if (log)
738 {
739 SBStream frame_desc_strm;
740 sb_frame.GetDescription (frame_desc_strm);
741 sb_file_spec->GetPath (path, sizeof(path));
742 log->Printf ("SBThread(%p)::StepOverUntil (frame = SBFrame(%p): %s, file+line = %s:%u)",
Greg Claytonf4124de2012-02-21 00:09:25 +0000743 exe_ctx.GetThreadPtr(),
Greg Clayton334d33a2012-01-30 07:41:31 +0000744 frame_sp.get(),
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000745 frame_desc_strm.GetData(),
746 path, line);
747 }
Greg Clayton90c52142012-01-30 02:53:15 +0000748
Greg Claytonf4124de2012-02-21 00:09:25 +0000749 if (exe_ctx.HasThreadScope())
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000750 {
Greg Claytonf4124de2012-02-21 00:09:25 +0000751 Target *target = exe_ctx.GetTargetPtr();
752 Mutex::Locker api_locker (target->GetAPIMutex());
753 Thread *thread = exe_ctx.GetThreadPtr();
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000754
755 if (line == 0)
756 {
757 sb_error.SetErrorString("invalid line argument");
758 return sb_error;
759 }
760
761 StackFrameSP frame_sp;
Greg Clayton334d33a2012-01-30 07:41:31 +0000762 if (!frame_sp)
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000763 {
Greg Claytonf4124de2012-02-21 00:09:25 +0000764 frame_sp = thread->GetSelectedFrame ();
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000765 if (!frame_sp)
Greg Claytonf4124de2012-02-21 00:09:25 +0000766 frame_sp = thread->GetStackFrameAtIndex (0);
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000767 }
768
769 SymbolContext frame_sc;
770 if (!frame_sp)
771 {
772 sb_error.SetErrorString("no valid frames in thread to step");
773 return sb_error;
774 }
775
776 // If we have a frame, get its line
777 frame_sc = frame_sp->GetSymbolContext (eSymbolContextCompUnit |
778 eSymbolContextFunction |
779 eSymbolContextLineEntry |
780 eSymbolContextSymbol );
781
782 if (frame_sc.comp_unit == NULL)
783 {
784 sb_error.SetErrorStringWithFormat("frame %u doesn't have debug information", frame_sp->GetFrameIndex());
785 return sb_error;
786 }
787
788 FileSpec step_file_spec;
789 if (sb_file_spec.IsValid())
790 {
791 // The file spec passed in was valid, so use it
792 step_file_spec = sb_file_spec.ref();
793 }
794 else
795 {
796 if (frame_sc.line_entry.IsValid())
797 step_file_spec = frame_sc.line_entry.file;
798 else
799 {
800 sb_error.SetErrorString("invalid file argument or no file for frame");
801 return sb_error;
802 }
803 }
804
Jim Inghamb07c62a2011-05-08 00:56:32 +0000805 // Grab the current function, then we will make sure the "until" address is
806 // within the function. We discard addresses that are out of the current
807 // function, and then if there are no addresses remaining, give an appropriate
808 // error message.
809
810 bool all_in_function = true;
811 AddressRange fun_range = frame_sc.function->GetAddressRange();
812
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000813 std::vector<addr_t> step_over_until_addrs;
814 const bool abort_other_plans = true;
815 const bool stop_other_threads = true;
816 const bool check_inlines = true;
817 const bool exact = false;
818
819 SymbolContextList sc_list;
Jim Inghamb07c62a2011-05-08 00:56:32 +0000820 const uint32_t num_matches = frame_sc.comp_unit->ResolveSymbolContext (step_file_spec,
821 line,
822 check_inlines,
823 exact,
824 eSymbolContextLineEntry,
825 sc_list);
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000826 if (num_matches > 0)
827 {
828 SymbolContext sc;
829 for (uint32_t i=0; i<num_matches; ++i)
830 {
831 if (sc_list.GetContextAtIndex(i, sc))
832 {
Jim Inghamb07c62a2011-05-08 00:56:32 +0000833 addr_t step_addr = sc.line_entry.range.GetBaseAddress().GetLoadAddress(target);
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000834 if (step_addr != LLDB_INVALID_ADDRESS)
835 {
Jim Inghamb07c62a2011-05-08 00:56:32 +0000836 if (fun_range.ContainsLoadAddress(step_addr, target))
837 step_over_until_addrs.push_back(step_addr);
838 else
839 all_in_function = false;
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000840 }
841 }
842 }
843 }
Jim Inghamb07c62a2011-05-08 00:56:32 +0000844
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000845 if (step_over_until_addrs.empty())
846 {
Jim Inghamb07c62a2011-05-08 00:56:32 +0000847 if (all_in_function)
848 {
849 step_file_spec.GetPath (path, sizeof(path));
Jason Molenda7e5fa7f2011-09-20 21:44:10 +0000850 sb_error.SetErrorStringWithFormat("No line entries for %s:%u", path, line);
Jim Inghamb07c62a2011-05-08 00:56:32 +0000851 }
852 else
Greg Clayton9c236732011-10-26 00:56:27 +0000853 sb_error.SetErrorString ("step until target not in current function");
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000854 }
855 else
856 {
Greg Claytonf4124de2012-02-21 00:09:25 +0000857 thread->QueueThreadPlanForStepUntil (abort_other_plans,
858 &step_over_until_addrs[0],
859 step_over_until_addrs.size(),
860 stop_other_threads,
861 frame_sp->GetFrameIndex());
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000862
Greg Claytonf4124de2012-02-21 00:09:25 +0000863 Process *process = exe_ctx.GetProcessPtr();
864
865 process->GetThreadList().SetSelectedThreadByID (thread->GetID());
866 sb_error.ref() = process->Resume();
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000867 if (sb_error->Success())
868 {
869 // If we are doing synchronous mode, then wait for the
870 // process to stop yet again!
Greg Claytonf4124de2012-02-21 00:09:25 +0000871 if (process->GetTarget().GetDebugger().GetAsyncExecution () == false)
872 process->WaitForProcessToStop (NULL);
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000873 }
874 }
875 }
876 else
877 {
878 sb_error.SetErrorString("this SBThread object is invalid");
879 }
880 return sb_error;
881}
882
883
Greg Clayton123db402011-01-12 02:25:42 +0000884bool
885SBThread::Suspend()
886{
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000887 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona894fe72012-04-05 16:12:35 +0000888 ExecutionContext exe_ctx (m_opaque_sp.get());
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000889 bool result = false;
Greg Claytonf4124de2012-02-21 00:09:25 +0000890 if (exe_ctx.HasThreadScope())
Greg Clayton123db402011-01-12 02:25:42 +0000891 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000892 Process::StopLocker stop_locker;
893 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
894 {
895 exe_ctx.GetThreadPtr()->SetResumeState (eStateSuspended);
896 result = true;
897 }
898 else
899 {
900 if (log)
901 log->Printf ("SBThread(%p)::Suspend() => error: process is running", exe_ctx.GetThreadPtr());
902 }
Greg Clayton123db402011-01-12 02:25:42 +0000903 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000904 if (log)
905 log->Printf ("SBThread(%p)::Suspend() => %i", exe_ctx.GetThreadPtr(), result);
906 return result;
Greg Clayton123db402011-01-12 02:25:42 +0000907}
908
909bool
910SBThread::Resume ()
911{
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000912 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona894fe72012-04-05 16:12:35 +0000913 ExecutionContext exe_ctx (m_opaque_sp.get());
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000914 bool result = false;
Greg Claytonf4124de2012-02-21 00:09:25 +0000915 if (exe_ctx.HasThreadScope())
Greg Clayton123db402011-01-12 02:25:42 +0000916 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000917 Process::StopLocker stop_locker;
918 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
919 {
920 exe_ctx.GetThreadPtr()->SetResumeState (eStateRunning);
921 result = true;
922 }
923 else
924 {
925 if (log)
926 log->Printf ("SBThread(%p)::Resume() => error: process is running", exe_ctx.GetThreadPtr());
927 }
Greg Clayton123db402011-01-12 02:25:42 +0000928 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000929 if (log)
930 log->Printf ("SBThread(%p)::Resume() => %i", exe_ctx.GetThreadPtr(), result);
931 return result;
Greg Clayton123db402011-01-12 02:25:42 +0000932}
933
934bool
935SBThread::IsSuspended()
936{
Greg Claytona894fe72012-04-05 16:12:35 +0000937 ExecutionContext exe_ctx (m_opaque_sp.get());
Greg Claytonf4124de2012-02-21 00:09:25 +0000938 if (exe_ctx.HasThreadScope())
939 return exe_ctx.GetThreadPtr()->GetResumeState () == eStateSuspended;
Greg Clayton123db402011-01-12 02:25:42 +0000940 return false;
941}
942
Chris Lattner24943d22010-06-08 16:52:24 +0000943SBProcess
944SBThread::GetProcess ()
945{
Caroline Tice7826c882010-10-26 03:11:13 +0000946
Greg Clayton334d33a2012-01-30 07:41:31 +0000947 SBProcess sb_process;
948 ProcessSP process_sp;
Greg Claytona894fe72012-04-05 16:12:35 +0000949 ExecutionContext exe_ctx (m_opaque_sp.get());
Greg Claytonf4124de2012-02-21 00:09:25 +0000950 if (exe_ctx.HasThreadScope())
Chris Lattner24943d22010-06-08 16:52:24 +0000951 {
952 // Have to go up to the target so we can get a shared pointer to our process...
Greg Claytonf4124de2012-02-21 00:09:25 +0000953 sb_process.SetSP (exe_ctx.GetProcessSP());
Chris Lattner24943d22010-06-08 16:52:24 +0000954 }
Caroline Tice7826c882010-10-26 03:11:13 +0000955
Greg Claytone005f2c2010-11-06 01:53:30 +0000956 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000957 if (log)
958 {
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000959 SBStream frame_desc_strm;
Greg Clayton334d33a2012-01-30 07:41:31 +0000960 sb_process.GetDescription (frame_desc_strm);
Greg Claytonf4124de2012-02-21 00:09:25 +0000961 log->Printf ("SBThread(%p)::GetProcess () => SBProcess(%p): %s", exe_ctx.GetThreadPtr(),
Greg Clayton334d33a2012-01-30 07:41:31 +0000962 process_sp.get(), frame_desc_strm.GetData());
Caroline Tice7826c882010-10-26 03:11:13 +0000963 }
964
Greg Clayton334d33a2012-01-30 07:41:31 +0000965 return sb_process;
Chris Lattner24943d22010-06-08 16:52:24 +0000966}
967
968uint32_t
969SBThread::GetNumFrames ()
970{
Greg Claytone005f2c2010-11-06 01:53:30 +0000971 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000972
Caroline Tice7826c882010-10-26 03:11:13 +0000973 uint32_t num_frames = 0;
Greg Claytona894fe72012-04-05 16:12:35 +0000974 ExecutionContext exe_ctx (m_opaque_sp.get());
Greg Claytonf4124de2012-02-21 00:09:25 +0000975 if (exe_ctx.HasThreadScope())
Greg Claytonbdcda462010-12-20 20:49:23 +0000976 {
Greg Claytona894fe72012-04-05 16:12:35 +0000977 Process::StopLocker stop_locker;
978 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
979 {
980 Mutex::Locker api_locker (exe_ctx.GetTargetPtr()->GetAPIMutex());
981 num_frames = exe_ctx.GetThreadPtr()->GetStackFrameCount();
982 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000983 else
984 {
985 if (log)
986 log->Printf ("SBThread(%p)::GetNumFrames() => error: process is running", exe_ctx.GetThreadPtr());
987 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000988 }
Caroline Tice7826c882010-10-26 03:11:13 +0000989
990 if (log)
Greg Claytonf4124de2012-02-21 00:09:25 +0000991 log->Printf ("SBThread(%p)::GetNumFrames () => %u", exe_ctx.GetThreadPtr(), num_frames);
Caroline Tice7826c882010-10-26 03:11:13 +0000992
993 return num_frames;
Chris Lattner24943d22010-06-08 16:52:24 +0000994}
995
996SBFrame
997SBThread::GetFrameAtIndex (uint32_t idx)
998{
Greg Claytone005f2c2010-11-06 01:53:30 +0000999 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +00001000
Chris Lattner24943d22010-06-08 16:52:24 +00001001 SBFrame sb_frame;
Greg Clayton334d33a2012-01-30 07:41:31 +00001002 StackFrameSP frame_sp;
Greg Claytona894fe72012-04-05 16:12:35 +00001003 ExecutionContext exe_ctx (m_opaque_sp.get());
Greg Claytonf4124de2012-02-21 00:09:25 +00001004 if (exe_ctx.HasThreadScope())
Greg Claytonbdcda462010-12-20 20:49:23 +00001005 {
Greg Claytona894fe72012-04-05 16:12:35 +00001006 Process::StopLocker stop_locker;
1007 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
1008 {
1009 Mutex::Locker api_locker (exe_ctx.GetTargetPtr()->GetAPIMutex());
1010 frame_sp = exe_ctx.GetThreadPtr()->GetStackFrameAtIndex (idx);
1011 sb_frame.SetFrameSP (frame_sp);
1012 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001013 else
1014 {
1015 if (log)
1016 log->Printf ("SBThread(%p)::GetFrameAtIndex() => error: process is running", exe_ctx.GetThreadPtr());
1017 }
Greg Claytonbdcda462010-12-20 20:49:23 +00001018 }
Caroline Tice7826c882010-10-26 03:11:13 +00001019
1020 if (log)
1021 {
Greg Clayton1ebdcc72011-01-21 06:11:58 +00001022 SBStream frame_desc_strm;
1023 sb_frame.GetDescription (frame_desc_strm);
Greg Claytona66ba462010-10-30 04:51:46 +00001024 log->Printf ("SBThread(%p)::GetFrameAtIndex (idx=%d) => SBFrame(%p): %s",
Greg Claytonf4124de2012-02-21 00:09:25 +00001025 exe_ctx.GetThreadPtr(), idx, frame_sp.get(), frame_desc_strm.GetData());
Caroline Tice7826c882010-10-26 03:11:13 +00001026 }
1027
Chris Lattner24943d22010-06-08 16:52:24 +00001028 return sb_frame;
1029}
1030
Greg Claytonc5157ec2010-12-17 02:26:24 +00001031lldb::SBFrame
1032SBThread::GetSelectedFrame ()
1033{
1034 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1035
1036 SBFrame sb_frame;
Greg Clayton334d33a2012-01-30 07:41:31 +00001037 StackFrameSP frame_sp;
Greg Claytona894fe72012-04-05 16:12:35 +00001038 ExecutionContext exe_ctx (m_opaque_sp.get());
Greg Claytonf4124de2012-02-21 00:09:25 +00001039 if (exe_ctx.HasThreadScope())
Greg Claytonbdcda462010-12-20 20:49:23 +00001040 {
Greg Claytona894fe72012-04-05 16:12:35 +00001041 Process::StopLocker stop_locker;
1042 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
1043 {
1044 Mutex::Locker api_locker (exe_ctx.GetTargetPtr()->GetAPIMutex());
1045 frame_sp = exe_ctx.GetThreadPtr()->GetSelectedFrame ();
1046 sb_frame.SetFrameSP (frame_sp);
1047 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001048 else
1049 {
1050 if (log)
1051 log->Printf ("SBThread(%p)::GetSelectedFrame() => error: process is running", exe_ctx.GetThreadPtr());
1052 }
Greg Claytonbdcda462010-12-20 20:49:23 +00001053 }
Greg Claytonc5157ec2010-12-17 02:26:24 +00001054
1055 if (log)
1056 {
Greg Clayton1ebdcc72011-01-21 06:11:58 +00001057 SBStream frame_desc_strm;
1058 sb_frame.GetDescription (frame_desc_strm);
Greg Claytonc5157ec2010-12-17 02:26:24 +00001059 log->Printf ("SBThread(%p)::GetSelectedFrame () => SBFrame(%p): %s",
Greg Claytonf4124de2012-02-21 00:09:25 +00001060 exe_ctx.GetThreadPtr(), frame_sp.get(), frame_desc_strm.GetData());
Greg Claytonc5157ec2010-12-17 02:26:24 +00001061 }
1062
1063 return sb_frame;
1064}
1065
1066lldb::SBFrame
1067SBThread::SetSelectedFrame (uint32_t idx)
1068{
1069 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1070
1071 SBFrame sb_frame;
Greg Clayton334d33a2012-01-30 07:41:31 +00001072 StackFrameSP frame_sp;
Greg Claytona894fe72012-04-05 16:12:35 +00001073 ExecutionContext exe_ctx (m_opaque_sp.get());
Greg Claytonf4124de2012-02-21 00:09:25 +00001074 if (exe_ctx.HasThreadScope())
Greg Claytonc5157ec2010-12-17 02:26:24 +00001075 {
Greg Claytona894fe72012-04-05 16:12:35 +00001076 Process::StopLocker stop_locker;
1077 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
Greg Claytonc5157ec2010-12-17 02:26:24 +00001078 {
Greg Claytona894fe72012-04-05 16:12:35 +00001079 Mutex::Locker api_locker (exe_ctx.GetTargetPtr()->GetAPIMutex());
1080 Thread *thread = exe_ctx.GetThreadPtr();
1081 frame_sp = thread->GetStackFrameAtIndex (idx);
1082 if (frame_sp)
1083 {
1084 thread->SetSelectedFrame (frame_sp.get());
1085 sb_frame.SetFrameSP (frame_sp);
1086 }
Greg Claytonc5157ec2010-12-17 02:26:24 +00001087 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001088 else
1089 {
1090 if (log)
1091 log->Printf ("SBThread(%p)::SetSelectedFrame() => error: process is running", exe_ctx.GetThreadPtr());
1092 }
Greg Claytonc5157ec2010-12-17 02:26:24 +00001093 }
1094
1095 if (log)
1096 {
Greg Clayton1ebdcc72011-01-21 06:11:58 +00001097 SBStream frame_desc_strm;
1098 sb_frame.GetDescription (frame_desc_strm);
Greg Claytonc5157ec2010-12-17 02:26:24 +00001099 log->Printf ("SBThread(%p)::SetSelectedFrame (idx=%u) => SBFrame(%p): %s",
Greg Claytonf4124de2012-02-21 00:09:25 +00001100 exe_ctx.GetThreadPtr(), idx, frame_sp.get(), frame_desc_strm.GetData());
Greg Claytonc5157ec2010-12-17 02:26:24 +00001101 }
1102 return sb_frame;
1103}
1104
1105
Chris Lattner24943d22010-06-08 16:52:24 +00001106bool
1107SBThread::operator == (const SBThread &rhs) const
1108{
Greg Claytona894fe72012-04-05 16:12:35 +00001109 return m_opaque_sp->GetThreadSP().get() == rhs.m_opaque_sp->GetThreadSP().get();
Chris Lattner24943d22010-06-08 16:52:24 +00001110}
1111
1112bool
1113SBThread::operator != (const SBThread &rhs) const
1114{
Greg Claytona894fe72012-04-05 16:12:35 +00001115 return m_opaque_sp->GetThreadSP().get() != rhs.m_opaque_sp->GetThreadSP().get();
Chris Lattner24943d22010-06-08 16:52:24 +00001116}
Caroline Tice98f930f2010-09-20 05:20:02 +00001117
1118bool
Caroline Tice7826c882010-10-26 03:11:13 +00001119SBThread::GetDescription (SBStream &description) const
1120{
Greg Clayton96154be2011-11-13 06:57:31 +00001121 Stream &strm = description.ref();
1122
Greg Claytona894fe72012-04-05 16:12:35 +00001123 ExecutionContext exe_ctx (m_opaque_sp.get());
Greg Claytonf4124de2012-02-21 00:09:25 +00001124 if (exe_ctx.HasThreadScope())
Caroline Tice7826c882010-10-26 03:11:13 +00001125 {
Greg Claytonf4124de2012-02-21 00:09:25 +00001126 strm.Printf("SBThread: tid = 0x%4.4llx", exe_ctx.GetThreadPtr()->GetID());
Caroline Tice7826c882010-10-26 03:11:13 +00001127 }
1128 else
Greg Clayton96154be2011-11-13 06:57:31 +00001129 strm.PutCString ("No value");
Caroline Tice7826c882010-10-26 03:11:13 +00001130
1131 return true;
1132}