blob: 772444de85d4e579815eea34d97b71081e7f759e [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"
34#include "lldb/API/SBFrame.h"
35#include "lldb/API/SBSourceManager.h"
36#include "lldb/API/SBDebugger.h"
37#include "lldb/API/SBProcess.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 Clayton63094e02010-06-23 01:19:29 +000046 m_opaque_sp ()
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 Clayton63094e02010-06-23 01:19:29 +000051 m_opaque_sp (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) :
56 m_opaque_sp (rhs.m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +000057{
Chris Lattner24943d22010-06-08 16:52:24 +000058}
59
60//----------------------------------------------------------------------
Greg Clayton49ce6822010-10-31 03:01:06 +000061// Assignment operator
62//----------------------------------------------------------------------
63
64const lldb::SBThread &
65SBThread::operator = (const SBThread &rhs)
66{
67 if (this != &rhs)
68 m_opaque_sp = rhs.m_opaque_sp;
69 return *this;
70}
71
72//----------------------------------------------------------------------
Chris Lattner24943d22010-06-08 16:52:24 +000073// Destructor
74//----------------------------------------------------------------------
75SBThread::~SBThread()
76{
77}
78
79bool
80SBThread::IsValid() const
81{
Greg Clayton63094e02010-06-23 01:19:29 +000082 return m_opaque_sp != NULL;
Chris Lattner24943d22010-06-08 16:52:24 +000083}
84
Greg Clayton43490d12010-07-30 20:12:55 +000085void
86SBThread::Clear ()
87{
88 m_opaque_sp.reset();
89}
90
91
Chris Lattner24943d22010-06-08 16:52:24 +000092StopReason
93SBThread::GetStopReason()
94{
Greg Claytone005f2c2010-11-06 01:53:30 +000095 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +000096
Caroline Tice7826c882010-10-26 03:11:13 +000097 StopReason reason = eStopReasonInvalid;
Greg Clayton63094e02010-06-23 01:19:29 +000098 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +000099 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000100 Mutex::Locker api_locker (m_opaque_sp->GetProcess().GetTarget().GetAPIMutex());
Jim Ingham6297a3a2010-10-20 00:39:53 +0000101 StopInfoSP stop_info_sp = m_opaque_sp->GetStopInfo ();
102 if (stop_info_sp)
Caroline Tice7826c882010-10-26 03:11:13 +0000103 reason = stop_info_sp->GetStopReason();
Chris Lattner24943d22010-06-08 16:52:24 +0000104 }
Caroline Tice7826c882010-10-26 03:11:13 +0000105
106 if (log)
Greg Claytona66ba462010-10-30 04:51:46 +0000107 log->Printf ("SBThread(%p)::GetStopReason () => %s", m_opaque_sp.get(),
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000108 Thread::StopReasonAsCString (reason));
Caroline Tice7826c882010-10-26 03:11:13 +0000109
110 return reason;
Chris Lattner24943d22010-06-08 16:52:24 +0000111}
112
113size_t
Greg Clayton640dc6b2010-11-18 18:52:36 +0000114SBThread::GetStopReasonDataCount ()
115{
116 if (m_opaque_sp)
117 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000118 Mutex::Locker api_locker (m_opaque_sp->GetProcess().GetTarget().GetAPIMutex());
Greg Clayton640dc6b2010-11-18 18:52:36 +0000119 StopInfoSP stop_info_sp = m_opaque_sp->GetStopInfo ();
120 if (stop_info_sp)
121 {
122 StopReason reason = stop_info_sp->GetStopReason();
123 switch (reason)
124 {
125 case eStopReasonInvalid:
126 case eStopReasonNone:
127 case eStopReasonTrace:
128 case eStopReasonPlanComplete:
129 // There is no data for these stop reasons.
130 return 0;
131
132 case eStopReasonBreakpoint:
133 {
134 break_id_t site_id = stop_info_sp->GetValue();
135 lldb::BreakpointSiteSP bp_site_sp (m_opaque_sp->GetProcess().GetBreakpointSiteList().FindByID (site_id));
136 if (bp_site_sp)
137 return bp_site_sp->GetNumberOfOwners () * 2;
138 else
139 return 0; // Breakpoint must have cleared itself...
140 }
141 break;
142
143 case eStopReasonWatchpoint:
144 assert (!"implement watchpoint support in SBThread::GetStopReasonDataCount ()");
145 return 0; // We don't have watchpoint support yet...
146
147 case eStopReasonSignal:
148 return 1;
149
150 case eStopReasonException:
151 return 1;
152 }
153 }
154 }
155 return 0;
156}
157
158uint64_t
159SBThread::GetStopReasonDataAtIndex (uint32_t idx)
160{
161 if (m_opaque_sp)
162 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000163 Mutex::Locker api_locker (m_opaque_sp->GetProcess().GetTarget().GetAPIMutex());
Greg Clayton640dc6b2010-11-18 18:52:36 +0000164 StopInfoSP stop_info_sp = m_opaque_sp->GetStopInfo ();
165 if (stop_info_sp)
166 {
167 StopReason reason = stop_info_sp->GetStopReason();
168 switch (reason)
169 {
170 case eStopReasonInvalid:
171 case eStopReasonNone:
172 case eStopReasonTrace:
173 case eStopReasonPlanComplete:
174 // There is no data for these stop reasons.
175 return 0;
176
177 case eStopReasonBreakpoint:
178 {
179 break_id_t site_id = stop_info_sp->GetValue();
180 lldb::BreakpointSiteSP bp_site_sp (m_opaque_sp->GetProcess().GetBreakpointSiteList().FindByID (site_id));
181 if (bp_site_sp)
182 {
183 uint32_t bp_index = idx / 2;
184 BreakpointLocationSP bp_loc_sp (bp_site_sp->GetOwnerAtIndex (bp_index));
185 if (bp_loc_sp)
186 {
187 if (bp_index & 1)
188 {
189 // Odd idx, return the breakpoint location ID
190 return bp_loc_sp->GetID();
191 }
192 else
193 {
194 // Even idx, return the breakpoint ID
195 return bp_loc_sp->GetBreakpoint().GetID();
196 }
197 }
198 }
199 return LLDB_INVALID_BREAK_ID;
200 }
201 break;
202
203 case eStopReasonWatchpoint:
204 assert (!"implement watchpoint support in SBThread::GetStopReasonDataCount ()");
205 return 0; // We don't have watchpoint support yet...
206
207 case eStopReasonSignal:
208 return stop_info_sp->GetValue();
209
210 case eStopReasonException:
211 return stop_info_sp->GetValue();
212 }
213 }
214 }
215 return 0;
216}
217
218size_t
Chris Lattner24943d22010-06-08 16:52:24 +0000219SBThread::GetStopDescription (char *dst, size_t dst_len)
220{
Greg Claytone005f2c2010-11-06 01:53:30 +0000221 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000222
Greg Clayton63094e02010-06-23 01:19:29 +0000223 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000224 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000225 Mutex::Locker api_locker (m_opaque_sp->GetProcess().GetTarget().GetAPIMutex());
Jim Ingham6297a3a2010-10-20 00:39:53 +0000226 StopInfoSP stop_info_sp = m_opaque_sp->GetStopInfo ();
227 if (stop_info_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000228 {
Jim Ingham6297a3a2010-10-20 00:39:53 +0000229 const char *stop_desc = stop_info_sp->GetDescription();
Chris Lattner24943d22010-06-08 16:52:24 +0000230 if (stop_desc)
231 {
Caroline Tice7826c882010-10-26 03:11:13 +0000232 if (log)
Greg Claytona66ba462010-10-30 04:51:46 +0000233 log->Printf ("SBThread(%p)::GetStopDescription (dst, dst_len) => \"%s\"",
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000234 m_opaque_sp.get(), stop_desc);
Chris Lattner24943d22010-06-08 16:52:24 +0000235 if (dst)
236 return ::snprintf (dst, dst_len, "%s", stop_desc);
237 else
238 {
239 // NULL dst passed in, return the length needed to contain the description
240 return ::strlen (stop_desc) + 1; // Include the NULL byte for size
241 }
242 }
243 else
244 {
Chris Lattner24943d22010-06-08 16:52:24 +0000245 size_t stop_desc_len = 0;
Jim Ingham6297a3a2010-10-20 00:39:53 +0000246 switch (stop_info_sp->GetStopReason())
Chris Lattner24943d22010-06-08 16:52:24 +0000247 {
248 case eStopReasonTrace:
249 case eStopReasonPlanComplete:
250 {
251 static char trace_desc[] = "step";
252 stop_desc = trace_desc;
253 stop_desc_len = sizeof(trace_desc); // Include the NULL byte for size
254 }
255 break;
256
257 case eStopReasonBreakpoint:
258 {
259 static char bp_desc[] = "breakpoint hit";
260 stop_desc = bp_desc;
261 stop_desc_len = sizeof(bp_desc); // Include the NULL byte for size
262 }
263 break;
264
265 case eStopReasonWatchpoint:
266 {
267 static char wp_desc[] = "watchpoint hit";
268 stop_desc = wp_desc;
269 stop_desc_len = sizeof(wp_desc); // Include the NULL byte for size
270 }
271 break;
272
273 case eStopReasonSignal:
274 {
Jim Ingham6297a3a2010-10-20 00:39:53 +0000275 stop_desc = m_opaque_sp->GetProcess().GetUnixSignals ().GetSignalAsCString (stop_info_sp->GetValue());
Chris Lattner24943d22010-06-08 16:52:24 +0000276 if (stop_desc == NULL || stop_desc[0] == '\0')
277 {
278 static char signal_desc[] = "signal";
279 stop_desc = signal_desc;
280 stop_desc_len = sizeof(signal_desc); // Include the NULL byte for size
281 }
282 }
283 break;
284
285 case eStopReasonException:
286 {
287 char exc_desc[] = "exception";
288 stop_desc = exc_desc;
289 stop_desc_len = sizeof(exc_desc); // Include the NULL byte for size
290 }
Greg Clayton54e7afa2010-07-09 20:39:50 +0000291 break;
292
293 default:
294 break;
Chris Lattner24943d22010-06-08 16:52:24 +0000295 }
296
297 if (stop_desc && stop_desc[0])
298 {
Caroline Tice7826c882010-10-26 03:11:13 +0000299 if (log)
Greg Clayton3f5ee7f2010-10-29 04:59:35 +0000300 log->Printf ("SBThread(%p)::GetStopDescription (dst, dst_len) => '%s'",
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000301 m_opaque_sp.get(), stop_desc);
Caroline Tice7826c882010-10-26 03:11:13 +0000302
Chris Lattner24943d22010-06-08 16:52:24 +0000303 if (dst)
304 return ::snprintf (dst, dst_len, "%s", stop_desc) + 1; // Include the NULL byte
305
306 if (stop_desc_len == 0)
307 stop_desc_len = ::strlen (stop_desc) + 1; // Include the NULL byte
308
309 return stop_desc_len;
310 }
311 }
312 }
313 }
314 if (dst)
315 *dst = 0;
316 return 0;
317}
318
319void
320SBThread::SetThread (const ThreadSP& lldb_object_sp)
321{
Greg Clayton63094e02010-06-23 01:19:29 +0000322 m_opaque_sp = lldb_object_sp;
Chris Lattner24943d22010-06-08 16:52:24 +0000323}
324
325
326lldb::tid_t
327SBThread::GetThreadID () const
328{
Greg Claytone005f2c2010-11-06 01:53:30 +0000329 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000330
Greg Claytonbdcda462010-12-20 20:49:23 +0000331 lldb::tid_t tid = LLDB_INVALID_THREAD_ID;
Greg Clayton63094e02010-06-23 01:19:29 +0000332 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000333 tid = m_opaque_sp->GetID();
Caroline Tice7826c882010-10-26 03:11:13 +0000334
335 if (log)
Greg Claytonbdcda462010-12-20 20:49:23 +0000336 log->Printf ("SBThread(%p)::GetThreadID () => 0x%4.4x", m_opaque_sp.get(), tid);
Caroline Tice7826c882010-10-26 03:11:13 +0000337
Greg Claytonbdcda462010-12-20 20:49:23 +0000338 return tid;
Chris Lattner24943d22010-06-08 16:52:24 +0000339}
340
341uint32_t
342SBThread::GetIndexID () const
343{
Greg Clayton63094e02010-06-23 01:19:29 +0000344 if (m_opaque_sp)
345 return m_opaque_sp->GetIndexID();
Chris Lattner24943d22010-06-08 16:52:24 +0000346 return LLDB_INVALID_INDEX32;
347}
348const char *
349SBThread::GetName () const
350{
Greg Claytona66ba462010-10-30 04:51:46 +0000351 const char *name = NULL;
Greg Clayton63094e02010-06-23 01:19:29 +0000352 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000353 {
354 Mutex::Locker api_locker (m_opaque_sp->GetProcess().GetTarget().GetAPIMutex());
Greg Claytona66ba462010-10-30 04:51:46 +0000355 name = m_opaque_sp->GetName();
Greg Claytonbdcda462010-12-20 20:49:23 +0000356 }
Greg Claytona66ba462010-10-30 04:51:46 +0000357
Greg Claytone005f2c2010-11-06 01:53:30 +0000358 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000359 if (log)
Greg Claytona66ba462010-10-30 04:51:46 +0000360 log->Printf ("SBThread(%p)::GetName () => %s", m_opaque_sp.get(), name ? name : "NULL");
Caroline Tice7826c882010-10-26 03:11:13 +0000361
Greg Claytona66ba462010-10-30 04:51:46 +0000362 return name;
Chris Lattner24943d22010-06-08 16:52:24 +0000363}
364
365const char *
366SBThread::GetQueueName () const
367{
Greg Claytona66ba462010-10-30 04:51:46 +0000368 const char *name = NULL;
Greg Clayton63094e02010-06-23 01:19:29 +0000369 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000370 {
371 Mutex::Locker api_locker (m_opaque_sp->GetProcess().GetTarget().GetAPIMutex());
Greg Claytona66ba462010-10-30 04:51:46 +0000372 name = m_opaque_sp->GetQueueName();
Greg Claytonbdcda462010-12-20 20:49:23 +0000373 }
Greg Claytona66ba462010-10-30 04:51:46 +0000374
Greg Claytone005f2c2010-11-06 01:53:30 +0000375 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000376 if (log)
Greg Claytona66ba462010-10-30 04:51:46 +0000377 log->Printf ("SBThread(%p)::GetQueueName () => %s", m_opaque_sp.get(), name ? name : "NULL");
Caroline Tice7826c882010-10-26 03:11:13 +0000378
Greg Claytona66ba462010-10-30 04:51:46 +0000379 return name;
Chris Lattner24943d22010-06-08 16:52:24 +0000380}
381
382
383void
Chris Lattner24943d22010-06-08 16:52:24 +0000384SBThread::StepOver (lldb::RunMode stop_other_threads)
385{
Greg Claytone005f2c2010-11-06 01:53:30 +0000386 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000387
388 if (log)
Greg Clayton3f5ee7f2010-10-29 04:59:35 +0000389 log->Printf ("SBThread(%p)::StepOver (stop_other_threads='%s')", m_opaque_sp.get(),
Caroline Tice7826c882010-10-26 03:11:13 +0000390 Thread::RunModeAsCString (stop_other_threads));
391
Greg Clayton63094e02010-06-23 01:19:29 +0000392 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000393 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000394 Mutex::Locker api_locker (m_opaque_sp->GetProcess().GetTarget().GetAPIMutex());
Chris Lattner24943d22010-06-08 16:52:24 +0000395 bool abort_other_plans = true;
Greg Clayton63094e02010-06-23 01:19:29 +0000396 StackFrameSP frame_sp(m_opaque_sp->GetStackFrameAtIndex (0));
Chris Lattner24943d22010-06-08 16:52:24 +0000397
398 if (frame_sp)
399 {
400 if (frame_sp->HasDebugInformation ())
401 {
402 SymbolContext sc(frame_sp->GetSymbolContext(eSymbolContextEverything));
Greg Clayton63094e02010-06-23 01:19:29 +0000403 m_opaque_sp->QueueThreadPlanForStepRange (abort_other_plans,
Greg Clayton1a3083a2010-10-06 03:53:16 +0000404 eStepTypeOver,
405 sc.line_entry.range,
406 sc,
407 stop_other_threads,
408 false);
Chris Lattner24943d22010-06-08 16:52:24 +0000409
410 }
411 else
412 {
Greg Clayton63094e02010-06-23 01:19:29 +0000413 m_opaque_sp->QueueThreadPlanForStepSingleInstruction (true,
Greg Clayton1a3083a2010-10-06 03:53:16 +0000414 abort_other_plans,
415 stop_other_threads);
Chris Lattner24943d22010-06-08 16:52:24 +0000416 }
417 }
418
Greg Clayton63094e02010-06-23 01:19:29 +0000419 Process &process = m_opaque_sp->GetProcess();
Chris Lattner24943d22010-06-08 16:52:24 +0000420 // Why do we need to set the current thread by ID here???
Jim Inghamc8332952010-08-26 21:32:51 +0000421 process.GetThreadList().SetSelectedThreadByID (m_opaque_sp->GetID());
Greg Clayton1a3083a2010-10-06 03:53:16 +0000422 Error error (process.Resume());
423 if (error.Success())
424 {
425 // If we are doing synchronous mode, then wait for the
426 // process to stop yet again!
427 if (process.GetTarget().GetDebugger().GetAsyncExecution () == false)
428 process.WaitForProcessToStop (NULL);
429 }
Chris Lattner24943d22010-06-08 16:52:24 +0000430 }
431}
432
433void
434SBThread::StepInto (lldb::RunMode stop_other_threads)
435{
Greg Claytone005f2c2010-11-06 01:53:30 +0000436 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000437
438 if (log)
Greg Clayton3f5ee7f2010-10-29 04:59:35 +0000439 log->Printf ("SBThread(%p)::StepInto (stop_other_threads='%s')", m_opaque_sp.get(),
Caroline Tice7826c882010-10-26 03:11:13 +0000440 Thread::RunModeAsCString (stop_other_threads));
441
Greg Clayton63094e02010-06-23 01:19:29 +0000442 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000443 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000444 Mutex::Locker api_locker (m_opaque_sp->GetProcess().GetTarget().GetAPIMutex());
Chris Lattner24943d22010-06-08 16:52:24 +0000445 bool abort_other_plans = true;
446
Greg Clayton63094e02010-06-23 01:19:29 +0000447 StackFrameSP frame_sp(m_opaque_sp->GetStackFrameAtIndex (0));
Chris Lattner24943d22010-06-08 16:52:24 +0000448
449 if (frame_sp && frame_sp->HasDebugInformation ())
450 {
Greg Clayton8f5fd6b2010-06-12 18:59:55 +0000451 bool avoid_code_without_debug_info = true;
Chris Lattner24943d22010-06-08 16:52:24 +0000452 SymbolContext sc(frame_sp->GetSymbolContext(eSymbolContextEverything));
Greg Clayton63094e02010-06-23 01:19:29 +0000453 m_opaque_sp->QueueThreadPlanForStepRange (abort_other_plans,
Greg Clayton1a3083a2010-10-06 03:53:16 +0000454 eStepTypeInto,
455 sc.line_entry.range,
456 sc,
457 stop_other_threads,
458 avoid_code_without_debug_info);
Chris Lattner24943d22010-06-08 16:52:24 +0000459 }
460 else
461 {
Greg Clayton63094e02010-06-23 01:19:29 +0000462 m_opaque_sp->QueueThreadPlanForStepSingleInstruction (false,
Greg Clayton1a3083a2010-10-06 03:53:16 +0000463 abort_other_plans,
464 stop_other_threads);
Chris Lattner24943d22010-06-08 16:52:24 +0000465 }
466
Greg Clayton63094e02010-06-23 01:19:29 +0000467 Process &process = m_opaque_sp->GetProcess();
Chris Lattner24943d22010-06-08 16:52:24 +0000468 // Why do we need to set the current thread by ID here???
Jim Inghamc8332952010-08-26 21:32:51 +0000469 process.GetThreadList().SetSelectedThreadByID (m_opaque_sp->GetID());
Greg Clayton1a3083a2010-10-06 03:53:16 +0000470 Error error (process.Resume());
471 if (error.Success())
472 {
473 // If we are doing synchronous mode, then wait for the
474 // process to stop yet again!
475 if (process.GetTarget().GetDebugger().GetAsyncExecution () == false)
476 process.WaitForProcessToStop (NULL);
477 }
Chris Lattner24943d22010-06-08 16:52:24 +0000478 }
479}
480
481void
482SBThread::StepOut ()
483{
Greg Claytone005f2c2010-11-06 01:53:30 +0000484 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000485
486 if (log)
Greg Claytona66ba462010-10-30 04:51:46 +0000487 log->Printf ("SBThread(%p)::StepOut ()", m_opaque_sp.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000488
Greg Clayton63094e02010-06-23 01:19:29 +0000489 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000490 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000491 Mutex::Locker api_locker (m_opaque_sp->GetProcess().GetTarget().GetAPIMutex());
Chris Lattner24943d22010-06-08 16:52:24 +0000492 bool abort_other_plans = true;
493 bool stop_other_threads = true;
494
Greg Clayton63094e02010-06-23 01:19:29 +0000495 m_opaque_sp->QueueThreadPlanForStepOut (abort_other_plans, NULL, false, stop_other_threads, eVoteYes, eVoteNoOpinion);
Chris Lattner24943d22010-06-08 16:52:24 +0000496
Greg Clayton63094e02010-06-23 01:19:29 +0000497 Process &process = m_opaque_sp->GetProcess();
Jim Inghamc8332952010-08-26 21:32:51 +0000498 process.GetThreadList().SetSelectedThreadByID (m_opaque_sp->GetID());
Greg Clayton1a3083a2010-10-06 03:53:16 +0000499 Error error (process.Resume());
500 if (error.Success())
501 {
502 // If we are doing synchronous mode, then wait for the
503 // process to stop yet again!
504 if (process.GetTarget().GetDebugger().GetAsyncExecution () == false)
505 process.WaitForProcessToStop (NULL);
506 }
Chris Lattner24943d22010-06-08 16:52:24 +0000507 }
508}
509
510void
511SBThread::StepInstruction (bool step_over)
512{
Greg Claytone005f2c2010-11-06 01:53:30 +0000513 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000514
515 if (log)
Greg Clayton3f5ee7f2010-10-29 04:59:35 +0000516 log->Printf ("SBThread(%p)::StepInstruction (step_over=%i)", m_opaque_sp.get(), step_over);
Caroline Tice7826c882010-10-26 03:11:13 +0000517
Greg Clayton63094e02010-06-23 01:19:29 +0000518 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000519 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000520 Mutex::Locker api_locker (m_opaque_sp->GetProcess().GetTarget().GetAPIMutex());
Greg Clayton63094e02010-06-23 01:19:29 +0000521 m_opaque_sp->QueueThreadPlanForStepSingleInstruction (step_over, true, true);
522 Process &process = m_opaque_sp->GetProcess();
Jim Inghamc8332952010-08-26 21:32:51 +0000523 process.GetThreadList().SetSelectedThreadByID (m_opaque_sp->GetID());
Greg Clayton1a3083a2010-10-06 03:53:16 +0000524 Error error (process.Resume());
525 if (error.Success())
526 {
527 // If we are doing synchronous mode, then wait for the
528 // process to stop yet again!
529 if (process.GetTarget().GetDebugger().GetAsyncExecution () == false)
530 process.WaitForProcessToStop (NULL);
531 }
Chris Lattner24943d22010-06-08 16:52:24 +0000532 }
533}
534
535void
536SBThread::RunToAddress (lldb::addr_t addr)
537{
Greg Claytone005f2c2010-11-06 01:53:30 +0000538 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000539
540 if (log)
Greg Clayton3f5ee7f2010-10-29 04:59:35 +0000541 log->Printf ("SBThread(%p)::RunToAddress (addr=0x%llx)", m_opaque_sp.get(), addr);
Caroline Tice7826c882010-10-26 03:11:13 +0000542
Greg Clayton63094e02010-06-23 01:19:29 +0000543 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000544 {
545 bool abort_other_plans = true;
546 bool stop_other_threads = true;
547
548 Address target_addr (NULL, addr);
549
Greg Clayton63094e02010-06-23 01:19:29 +0000550 m_opaque_sp->QueueThreadPlanForRunToAddress (abort_other_plans, target_addr, stop_other_threads);
551 Process &process = m_opaque_sp->GetProcess();
Jim Inghamc8332952010-08-26 21:32:51 +0000552 process.GetThreadList().SetSelectedThreadByID (m_opaque_sp->GetID());
Greg Clayton1a3083a2010-10-06 03:53:16 +0000553 Error error (process.Resume());
554 if (error.Success())
555 {
556 // If we are doing synchronous mode, then wait for the
557 // process to stop yet again!
558 if (process.GetTarget().GetDebugger().GetAsyncExecution () == false)
559 process.WaitForProcessToStop (NULL);
560 }
Chris Lattner24943d22010-06-08 16:52:24 +0000561 }
562
563}
564
Chris Lattner24943d22010-06-08 16:52:24 +0000565SBProcess
566SBThread::GetProcess ()
567{
Caroline Tice7826c882010-10-26 03:11:13 +0000568
Chris Lattner24943d22010-06-08 16:52:24 +0000569 SBProcess process;
Greg Clayton63094e02010-06-23 01:19:29 +0000570 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000571 {
572 // Have to go up to the target so we can get a shared pointer to our process...
Greg Clayton63094e02010-06-23 01:19:29 +0000573 process.SetProcess(m_opaque_sp->GetProcess().GetTarget().GetProcessSP());
Chris Lattner24943d22010-06-08 16:52:24 +0000574 }
Caroline Tice7826c882010-10-26 03:11:13 +0000575
Greg Claytone005f2c2010-11-06 01:53:30 +0000576 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000577 if (log)
578 {
579 SBStream sstr;
580 process.GetDescription (sstr);
Greg Claytona66ba462010-10-30 04:51:46 +0000581 log->Printf ("SBThread(%p)::GetProcess () => SBProcess(%p): %s", m_opaque_sp.get(),
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000582 process.get(), sstr.GetData());
Caroline Tice7826c882010-10-26 03:11:13 +0000583 }
584
Chris Lattner24943d22010-06-08 16:52:24 +0000585 return process;
586}
587
588uint32_t
589SBThread::GetNumFrames ()
590{
Greg Claytone005f2c2010-11-06 01:53:30 +0000591 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000592
Caroline Tice7826c882010-10-26 03:11:13 +0000593 uint32_t num_frames = 0;
Greg Clayton63094e02010-06-23 01:19:29 +0000594 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000595 {
596 Mutex::Locker api_locker (m_opaque_sp->GetProcess().GetTarget().GetAPIMutex());
Caroline Tice7826c882010-10-26 03:11:13 +0000597 num_frames = m_opaque_sp->GetStackFrameCount();
Greg Claytonbdcda462010-12-20 20:49:23 +0000598 }
Caroline Tice7826c882010-10-26 03:11:13 +0000599
600 if (log)
Greg Claytona66ba462010-10-30 04:51:46 +0000601 log->Printf ("SBThread(%p)::GetNumFrames () => %u", m_opaque_sp.get(), num_frames);
Caroline Tice7826c882010-10-26 03:11:13 +0000602
603 return num_frames;
Chris Lattner24943d22010-06-08 16:52:24 +0000604}
605
606SBFrame
607SBThread::GetFrameAtIndex (uint32_t idx)
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
Chris Lattner24943d22010-06-08 16:52:24 +0000611 SBFrame sb_frame;
Greg Clayton63094e02010-06-23 01:19:29 +0000612 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000613 {
614 Mutex::Locker api_locker (m_opaque_sp->GetProcess().GetTarget().GetAPIMutex());
Greg Clayton63094e02010-06-23 01:19:29 +0000615 sb_frame.SetFrame (m_opaque_sp->GetStackFrameAtIndex (idx));
Greg Claytonbdcda462010-12-20 20:49:23 +0000616 }
Caroline Tice7826c882010-10-26 03:11:13 +0000617
618 if (log)
619 {
620 SBStream sstr;
621 sb_frame.GetDescription (sstr);
Greg Claytona66ba462010-10-30 04:51:46 +0000622 log->Printf ("SBThread(%p)::GetFrameAtIndex (idx=%d) => SBFrame(%p): %s",
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000623 m_opaque_sp.get(), idx, sb_frame.get(), sstr.GetData());
Caroline Tice7826c882010-10-26 03:11:13 +0000624 }
625
Chris Lattner24943d22010-06-08 16:52:24 +0000626 return sb_frame;
627}
628
Greg Claytonc5157ec2010-12-17 02:26:24 +0000629lldb::SBFrame
630SBThread::GetSelectedFrame ()
631{
632 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
633
634 SBFrame sb_frame;
635 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000636 {
637 Mutex::Locker api_locker (m_opaque_sp->GetProcess().GetTarget().GetAPIMutex());
Greg Claytonc5157ec2010-12-17 02:26:24 +0000638 sb_frame.SetFrame (m_opaque_sp->GetSelectedFrame ());
Greg Claytonbdcda462010-12-20 20:49:23 +0000639 }
Greg Claytonc5157ec2010-12-17 02:26:24 +0000640
641 if (log)
642 {
643 SBStream sstr;
644 sb_frame.GetDescription (sstr);
645 log->Printf ("SBThread(%p)::GetSelectedFrame () => SBFrame(%p): %s",
646 m_opaque_sp.get(), sb_frame.get(), sstr.GetData());
647 }
648
649 return sb_frame;
650}
651
652lldb::SBFrame
653SBThread::SetSelectedFrame (uint32_t idx)
654{
655 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
656
657 SBFrame sb_frame;
658 if (m_opaque_sp)
659 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000660 Mutex::Locker api_locker (m_opaque_sp->GetProcess().GetTarget().GetAPIMutex());
Greg Claytonc5157ec2010-12-17 02:26:24 +0000661 lldb::StackFrameSP frame_sp (m_opaque_sp->GetStackFrameAtIndex (idx));
662 if (frame_sp)
663 {
664 m_opaque_sp->SetSelectedFrame (frame_sp.get());
665 sb_frame.SetFrame (frame_sp);
666 }
667 }
668
669 if (log)
670 {
671 SBStream sstr;
672 sb_frame.GetDescription (sstr);
673 log->Printf ("SBThread(%p)::SetSelectedFrame (idx=%u) => SBFrame(%p): %s",
674 m_opaque_sp.get(), idx, sb_frame.get(), sstr.GetData());
675 }
676 return sb_frame;
677}
678
679
Chris Lattner24943d22010-06-08 16:52:24 +0000680bool
681SBThread::operator == (const SBThread &rhs) const
682{
Greg Clayton63094e02010-06-23 01:19:29 +0000683 return m_opaque_sp.get() == rhs.m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000684}
685
686bool
687SBThread::operator != (const SBThread &rhs) const
688{
Greg Clayton63094e02010-06-23 01:19:29 +0000689 return m_opaque_sp.get() != rhs.m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000690}
691
692lldb_private::Thread *
Greg Claytona66ba462010-10-30 04:51:46 +0000693SBThread::get ()
Chris Lattner24943d22010-06-08 16:52:24 +0000694{
Greg Clayton63094e02010-06-23 01:19:29 +0000695 return m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000696}
697
698const lldb_private::Thread *
699SBThread::operator->() const
700{
Greg Clayton63094e02010-06-23 01:19:29 +0000701 return m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000702}
703
704const lldb_private::Thread &
705SBThread::operator*() const
706{
Greg Clayton63094e02010-06-23 01:19:29 +0000707 return *m_opaque_sp;
Chris Lattner24943d22010-06-08 16:52:24 +0000708}
709
710lldb_private::Thread *
711SBThread::operator->()
712{
Greg Clayton63094e02010-06-23 01:19:29 +0000713 return m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000714}
715
716lldb_private::Thread &
717SBThread::operator*()
718{
Greg Clayton63094e02010-06-23 01:19:29 +0000719 return *m_opaque_sp;
Chris Lattner24943d22010-06-08 16:52:24 +0000720}
Caroline Tice98f930f2010-09-20 05:20:02 +0000721
722bool
Caroline Tice7826c882010-10-26 03:11:13 +0000723SBThread::GetDescription (SBStream &description) const
724{
725 if (m_opaque_sp)
726 {
727 StreamString strm;
728 description.Printf("SBThread: tid = 0x%4.4x", m_opaque_sp->GetID());
729 }
730 else
731 description.Printf ("No value");
732
733 return true;
734}