blob: cb7cfc5d76eb24c3a60e862216686d129a650ee5 [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 {
Jim Ingham6297a3a2010-10-20 00:39:53 +0000100 StopInfoSP stop_info_sp = m_opaque_sp->GetStopInfo ();
101 if (stop_info_sp)
Caroline Tice7826c882010-10-26 03:11:13 +0000102 reason = stop_info_sp->GetStopReason();
Chris Lattner24943d22010-06-08 16:52:24 +0000103 }
Caroline Tice7826c882010-10-26 03:11:13 +0000104
105 if (log)
Greg Claytona66ba462010-10-30 04:51:46 +0000106 log->Printf ("SBThread(%p)::GetStopReason () => %s", m_opaque_sp.get(),
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000107 Thread::StopReasonAsCString (reason));
Caroline Tice7826c882010-10-26 03:11:13 +0000108
109 return reason;
Chris Lattner24943d22010-06-08 16:52:24 +0000110}
111
112size_t
Greg Clayton640dc6b2010-11-18 18:52:36 +0000113SBThread::GetStopReasonDataCount ()
114{
115 if (m_opaque_sp)
116 {
117 StopInfoSP stop_info_sp = m_opaque_sp->GetStopInfo ();
118 if (stop_info_sp)
119 {
120 StopReason reason = stop_info_sp->GetStopReason();
121 switch (reason)
122 {
123 case eStopReasonInvalid:
124 case eStopReasonNone:
125 case eStopReasonTrace:
126 case eStopReasonPlanComplete:
127 // There is no data for these stop reasons.
128 return 0;
129
130 case eStopReasonBreakpoint:
131 {
132 break_id_t site_id = stop_info_sp->GetValue();
133 lldb::BreakpointSiteSP bp_site_sp (m_opaque_sp->GetProcess().GetBreakpointSiteList().FindByID (site_id));
134 if (bp_site_sp)
135 return bp_site_sp->GetNumberOfOwners () * 2;
136 else
137 return 0; // Breakpoint must have cleared itself...
138 }
139 break;
140
141 case eStopReasonWatchpoint:
142 assert (!"implement watchpoint support in SBThread::GetStopReasonDataCount ()");
143 return 0; // We don't have watchpoint support yet...
144
145 case eStopReasonSignal:
146 return 1;
147
148 case eStopReasonException:
149 return 1;
150 }
151 }
152 }
153 return 0;
154}
155
156uint64_t
157SBThread::GetStopReasonDataAtIndex (uint32_t idx)
158{
159 if (m_opaque_sp)
160 {
161 StopInfoSP stop_info_sp = m_opaque_sp->GetStopInfo ();
162 if (stop_info_sp)
163 {
164 StopReason reason = stop_info_sp->GetStopReason();
165 switch (reason)
166 {
167 case eStopReasonInvalid:
168 case eStopReasonNone:
169 case eStopReasonTrace:
170 case eStopReasonPlanComplete:
171 // There is no data for these stop reasons.
172 return 0;
173
174 case eStopReasonBreakpoint:
175 {
176 break_id_t site_id = stop_info_sp->GetValue();
177 lldb::BreakpointSiteSP bp_site_sp (m_opaque_sp->GetProcess().GetBreakpointSiteList().FindByID (site_id));
178 if (bp_site_sp)
179 {
180 uint32_t bp_index = idx / 2;
181 BreakpointLocationSP bp_loc_sp (bp_site_sp->GetOwnerAtIndex (bp_index));
182 if (bp_loc_sp)
183 {
184 if (bp_index & 1)
185 {
186 // Odd idx, return the breakpoint location ID
187 return bp_loc_sp->GetID();
188 }
189 else
190 {
191 // Even idx, return the breakpoint ID
192 return bp_loc_sp->GetBreakpoint().GetID();
193 }
194 }
195 }
196 return LLDB_INVALID_BREAK_ID;
197 }
198 break;
199
200 case eStopReasonWatchpoint:
201 assert (!"implement watchpoint support in SBThread::GetStopReasonDataCount ()");
202 return 0; // We don't have watchpoint support yet...
203
204 case eStopReasonSignal:
205 return stop_info_sp->GetValue();
206
207 case eStopReasonException:
208 return stop_info_sp->GetValue();
209 }
210 }
211 }
212 return 0;
213}
214
215size_t
Chris Lattner24943d22010-06-08 16:52:24 +0000216SBThread::GetStopDescription (char *dst, size_t dst_len)
217{
Greg Claytone005f2c2010-11-06 01:53:30 +0000218 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000219
Greg Clayton63094e02010-06-23 01:19:29 +0000220 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000221 {
Jim Ingham6297a3a2010-10-20 00:39:53 +0000222 StopInfoSP stop_info_sp = m_opaque_sp->GetStopInfo ();
223 if (stop_info_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000224 {
Jim Ingham6297a3a2010-10-20 00:39:53 +0000225 const char *stop_desc = stop_info_sp->GetDescription();
Chris Lattner24943d22010-06-08 16:52:24 +0000226 if (stop_desc)
227 {
Caroline Tice7826c882010-10-26 03:11:13 +0000228 if (log)
Greg Claytona66ba462010-10-30 04:51:46 +0000229 log->Printf ("SBThread(%p)::GetStopDescription (dst, dst_len) => \"%s\"",
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000230 m_opaque_sp.get(), stop_desc);
Chris Lattner24943d22010-06-08 16:52:24 +0000231 if (dst)
232 return ::snprintf (dst, dst_len, "%s", stop_desc);
233 else
234 {
235 // NULL dst passed in, return the length needed to contain the description
236 return ::strlen (stop_desc) + 1; // Include the NULL byte for size
237 }
238 }
239 else
240 {
Chris Lattner24943d22010-06-08 16:52:24 +0000241 size_t stop_desc_len = 0;
Jim Ingham6297a3a2010-10-20 00:39:53 +0000242 switch (stop_info_sp->GetStopReason())
Chris Lattner24943d22010-06-08 16:52:24 +0000243 {
244 case eStopReasonTrace:
245 case eStopReasonPlanComplete:
246 {
247 static char trace_desc[] = "step";
248 stop_desc = trace_desc;
249 stop_desc_len = sizeof(trace_desc); // Include the NULL byte for size
250 }
251 break;
252
253 case eStopReasonBreakpoint:
254 {
255 static char bp_desc[] = "breakpoint hit";
256 stop_desc = bp_desc;
257 stop_desc_len = sizeof(bp_desc); // Include the NULL byte for size
258 }
259 break;
260
261 case eStopReasonWatchpoint:
262 {
263 static char wp_desc[] = "watchpoint hit";
264 stop_desc = wp_desc;
265 stop_desc_len = sizeof(wp_desc); // Include the NULL byte for size
266 }
267 break;
268
269 case eStopReasonSignal:
270 {
Jim Ingham6297a3a2010-10-20 00:39:53 +0000271 stop_desc = m_opaque_sp->GetProcess().GetUnixSignals ().GetSignalAsCString (stop_info_sp->GetValue());
Chris Lattner24943d22010-06-08 16:52:24 +0000272 if (stop_desc == NULL || stop_desc[0] == '\0')
273 {
274 static char signal_desc[] = "signal";
275 stop_desc = signal_desc;
276 stop_desc_len = sizeof(signal_desc); // Include the NULL byte for size
277 }
278 }
279 break;
280
281 case eStopReasonException:
282 {
283 char exc_desc[] = "exception";
284 stop_desc = exc_desc;
285 stop_desc_len = sizeof(exc_desc); // Include the NULL byte for size
286 }
Greg Clayton54e7afa2010-07-09 20:39:50 +0000287 break;
288
289 default:
290 break;
Chris Lattner24943d22010-06-08 16:52:24 +0000291 }
292
293 if (stop_desc && stop_desc[0])
294 {
Caroline Tice7826c882010-10-26 03:11:13 +0000295 if (log)
Greg Clayton3f5ee7f2010-10-29 04:59:35 +0000296 log->Printf ("SBThread(%p)::GetStopDescription (dst, dst_len) => '%s'",
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000297 m_opaque_sp.get(), stop_desc);
Caroline Tice7826c882010-10-26 03:11:13 +0000298
Chris Lattner24943d22010-06-08 16:52:24 +0000299 if (dst)
300 return ::snprintf (dst, dst_len, "%s", stop_desc) + 1; // Include the NULL byte
301
302 if (stop_desc_len == 0)
303 stop_desc_len = ::strlen (stop_desc) + 1; // Include the NULL byte
304
305 return stop_desc_len;
306 }
307 }
308 }
309 }
310 if (dst)
311 *dst = 0;
312 return 0;
313}
314
315void
316SBThread::SetThread (const ThreadSP& lldb_object_sp)
317{
Greg Clayton63094e02010-06-23 01:19:29 +0000318 m_opaque_sp = lldb_object_sp;
Chris Lattner24943d22010-06-08 16:52:24 +0000319}
320
321
322lldb::tid_t
323SBThread::GetThreadID () const
324{
Greg Claytone005f2c2010-11-06 01:53:30 +0000325 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000326
Caroline Tice7826c882010-10-26 03:11:13 +0000327 lldb::tid_t id = LLDB_INVALID_THREAD_ID;
Greg Clayton63094e02010-06-23 01:19:29 +0000328 if (m_opaque_sp)
Caroline Tice7826c882010-10-26 03:11:13 +0000329 id = m_opaque_sp->GetID();
330
331 if (log)
Greg Claytona66ba462010-10-30 04:51:46 +0000332 log->Printf ("SBThread(%p)::GetThreadID () => 0x%4.4x", m_opaque_sp.get(), id);
Caroline Tice7826c882010-10-26 03:11:13 +0000333
334 return id;
Chris Lattner24943d22010-06-08 16:52:24 +0000335}
336
337uint32_t
338SBThread::GetIndexID () const
339{
Greg Clayton63094e02010-06-23 01:19:29 +0000340 if (m_opaque_sp)
341 return m_opaque_sp->GetIndexID();
Chris Lattner24943d22010-06-08 16:52:24 +0000342 return LLDB_INVALID_INDEX32;
343}
344const char *
345SBThread::GetName () const
346{
Greg Claytona66ba462010-10-30 04:51:46 +0000347 const char *name = NULL;
Greg Clayton63094e02010-06-23 01:19:29 +0000348 if (m_opaque_sp)
Greg Claytona66ba462010-10-30 04:51:46 +0000349 name = m_opaque_sp->GetName();
350
Greg Claytone005f2c2010-11-06 01:53:30 +0000351 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000352 if (log)
Greg Claytona66ba462010-10-30 04:51:46 +0000353 log->Printf ("SBThread(%p)::GetName () => %s", m_opaque_sp.get(), name ? name : "NULL");
Caroline Tice7826c882010-10-26 03:11:13 +0000354
Greg Claytona66ba462010-10-30 04:51:46 +0000355 return name;
Chris Lattner24943d22010-06-08 16:52:24 +0000356}
357
358const char *
359SBThread::GetQueueName () const
360{
Greg Claytona66ba462010-10-30 04:51:46 +0000361 const char *name = NULL;
Greg Clayton63094e02010-06-23 01:19:29 +0000362 if (m_opaque_sp)
Greg Claytona66ba462010-10-30 04:51:46 +0000363 name = m_opaque_sp->GetQueueName();
364
Greg Claytone005f2c2010-11-06 01:53:30 +0000365 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000366 if (log)
Greg Claytona66ba462010-10-30 04:51:46 +0000367 log->Printf ("SBThread(%p)::GetQueueName () => %s", m_opaque_sp.get(), name ? name : "NULL");
Caroline Tice7826c882010-10-26 03:11:13 +0000368
Greg Claytona66ba462010-10-30 04:51:46 +0000369 return name;
Chris Lattner24943d22010-06-08 16:52:24 +0000370}
371
372
373void
Chris Lattner24943d22010-06-08 16:52:24 +0000374SBThread::StepOver (lldb::RunMode stop_other_threads)
375{
Greg Claytone005f2c2010-11-06 01:53:30 +0000376 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000377
378 if (log)
Greg Clayton3f5ee7f2010-10-29 04:59:35 +0000379 log->Printf ("SBThread(%p)::StepOver (stop_other_threads='%s')", m_opaque_sp.get(),
Caroline Tice7826c882010-10-26 03:11:13 +0000380 Thread::RunModeAsCString (stop_other_threads));
381
Greg Clayton63094e02010-06-23 01:19:29 +0000382 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000383 {
384 bool abort_other_plans = true;
Greg Clayton63094e02010-06-23 01:19:29 +0000385 StackFrameSP frame_sp(m_opaque_sp->GetStackFrameAtIndex (0));
Chris Lattner24943d22010-06-08 16:52:24 +0000386
387 if (frame_sp)
388 {
389 if (frame_sp->HasDebugInformation ())
390 {
391 SymbolContext sc(frame_sp->GetSymbolContext(eSymbolContextEverything));
Greg Clayton63094e02010-06-23 01:19:29 +0000392 m_opaque_sp->QueueThreadPlanForStepRange (abort_other_plans,
Greg Clayton1a3083a2010-10-06 03:53:16 +0000393 eStepTypeOver,
394 sc.line_entry.range,
395 sc,
396 stop_other_threads,
397 false);
Chris Lattner24943d22010-06-08 16:52:24 +0000398
399 }
400 else
401 {
Greg Clayton63094e02010-06-23 01:19:29 +0000402 m_opaque_sp->QueueThreadPlanForStepSingleInstruction (true,
Greg Clayton1a3083a2010-10-06 03:53:16 +0000403 abort_other_plans,
404 stop_other_threads);
Chris Lattner24943d22010-06-08 16:52:24 +0000405 }
406 }
407
Greg Clayton63094e02010-06-23 01:19:29 +0000408 Process &process = m_opaque_sp->GetProcess();
Chris Lattner24943d22010-06-08 16:52:24 +0000409 // Why do we need to set the current thread by ID here???
Jim Inghamc8332952010-08-26 21:32:51 +0000410 process.GetThreadList().SetSelectedThreadByID (m_opaque_sp->GetID());
Greg Clayton1a3083a2010-10-06 03:53:16 +0000411 Error error (process.Resume());
412 if (error.Success())
413 {
414 // If we are doing synchronous mode, then wait for the
415 // process to stop yet again!
416 if (process.GetTarget().GetDebugger().GetAsyncExecution () == false)
417 process.WaitForProcessToStop (NULL);
418 }
Chris Lattner24943d22010-06-08 16:52:24 +0000419 }
420}
421
422void
423SBThread::StepInto (lldb::RunMode stop_other_threads)
424{
Greg Claytone005f2c2010-11-06 01:53:30 +0000425 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000426
427 if (log)
Greg Clayton3f5ee7f2010-10-29 04:59:35 +0000428 log->Printf ("SBThread(%p)::StepInto (stop_other_threads='%s')", m_opaque_sp.get(),
Caroline Tice7826c882010-10-26 03:11:13 +0000429 Thread::RunModeAsCString (stop_other_threads));
430
Greg Clayton63094e02010-06-23 01:19:29 +0000431 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000432 {
433 bool abort_other_plans = true;
434
Greg Clayton63094e02010-06-23 01:19:29 +0000435 StackFrameSP frame_sp(m_opaque_sp->GetStackFrameAtIndex (0));
Chris Lattner24943d22010-06-08 16:52:24 +0000436
437 if (frame_sp && frame_sp->HasDebugInformation ())
438 {
Greg Clayton8f5fd6b2010-06-12 18:59:55 +0000439 bool avoid_code_without_debug_info = true;
Chris Lattner24943d22010-06-08 16:52:24 +0000440 SymbolContext sc(frame_sp->GetSymbolContext(eSymbolContextEverything));
Greg Clayton63094e02010-06-23 01:19:29 +0000441 m_opaque_sp->QueueThreadPlanForStepRange (abort_other_plans,
Greg Clayton1a3083a2010-10-06 03:53:16 +0000442 eStepTypeInto,
443 sc.line_entry.range,
444 sc,
445 stop_other_threads,
446 avoid_code_without_debug_info);
Chris Lattner24943d22010-06-08 16:52:24 +0000447 }
448 else
449 {
Greg Clayton63094e02010-06-23 01:19:29 +0000450 m_opaque_sp->QueueThreadPlanForStepSingleInstruction (false,
Greg Clayton1a3083a2010-10-06 03:53:16 +0000451 abort_other_plans,
452 stop_other_threads);
Chris Lattner24943d22010-06-08 16:52:24 +0000453 }
454
Greg Clayton63094e02010-06-23 01:19:29 +0000455 Process &process = m_opaque_sp->GetProcess();
Chris Lattner24943d22010-06-08 16:52:24 +0000456 // Why do we need to set the current thread by ID here???
Jim Inghamc8332952010-08-26 21:32:51 +0000457 process.GetThreadList().SetSelectedThreadByID (m_opaque_sp->GetID());
Greg Clayton1a3083a2010-10-06 03:53:16 +0000458 Error error (process.Resume());
459 if (error.Success())
460 {
461 // If we are doing synchronous mode, then wait for the
462 // process to stop yet again!
463 if (process.GetTarget().GetDebugger().GetAsyncExecution () == false)
464 process.WaitForProcessToStop (NULL);
465 }
Chris Lattner24943d22010-06-08 16:52:24 +0000466 }
467}
468
469void
470SBThread::StepOut ()
471{
Greg Claytone005f2c2010-11-06 01:53:30 +0000472 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000473
474 if (log)
Greg Claytona66ba462010-10-30 04:51:46 +0000475 log->Printf ("SBThread(%p)::StepOut ()", m_opaque_sp.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000476
Greg Clayton63094e02010-06-23 01:19:29 +0000477 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000478 {
479 bool abort_other_plans = true;
480 bool stop_other_threads = true;
481
Greg Clayton63094e02010-06-23 01:19:29 +0000482 m_opaque_sp->QueueThreadPlanForStepOut (abort_other_plans, NULL, false, stop_other_threads, eVoteYes, eVoteNoOpinion);
Chris Lattner24943d22010-06-08 16:52:24 +0000483
Greg Clayton63094e02010-06-23 01:19:29 +0000484 Process &process = m_opaque_sp->GetProcess();
Jim Inghamc8332952010-08-26 21:32:51 +0000485 process.GetThreadList().SetSelectedThreadByID (m_opaque_sp->GetID());
Greg Clayton1a3083a2010-10-06 03:53:16 +0000486 Error error (process.Resume());
487 if (error.Success())
488 {
489 // If we are doing synchronous mode, then wait for the
490 // process to stop yet again!
491 if (process.GetTarget().GetDebugger().GetAsyncExecution () == false)
492 process.WaitForProcessToStop (NULL);
493 }
Chris Lattner24943d22010-06-08 16:52:24 +0000494 }
495}
496
497void
498SBThread::StepInstruction (bool step_over)
499{
Greg Claytone005f2c2010-11-06 01:53:30 +0000500 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000501
502 if (log)
Greg Clayton3f5ee7f2010-10-29 04:59:35 +0000503 log->Printf ("SBThread(%p)::StepInstruction (step_over=%i)", m_opaque_sp.get(), step_over);
Caroline Tice7826c882010-10-26 03:11:13 +0000504
Greg Clayton63094e02010-06-23 01:19:29 +0000505 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000506 {
Greg Clayton63094e02010-06-23 01:19:29 +0000507 m_opaque_sp->QueueThreadPlanForStepSingleInstruction (step_over, true, true);
508 Process &process = m_opaque_sp->GetProcess();
Jim Inghamc8332952010-08-26 21:32:51 +0000509 process.GetThreadList().SetSelectedThreadByID (m_opaque_sp->GetID());
Greg Clayton1a3083a2010-10-06 03:53:16 +0000510 Error error (process.Resume());
511 if (error.Success())
512 {
513 // If we are doing synchronous mode, then wait for the
514 // process to stop yet again!
515 if (process.GetTarget().GetDebugger().GetAsyncExecution () == false)
516 process.WaitForProcessToStop (NULL);
517 }
Chris Lattner24943d22010-06-08 16:52:24 +0000518 }
519}
520
521void
522SBThread::RunToAddress (lldb::addr_t addr)
523{
Greg Claytone005f2c2010-11-06 01:53:30 +0000524 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000525
526 if (log)
Greg Clayton3f5ee7f2010-10-29 04:59:35 +0000527 log->Printf ("SBThread(%p)::RunToAddress (addr=0x%llx)", m_opaque_sp.get(), addr);
Caroline Tice7826c882010-10-26 03:11:13 +0000528
Greg Clayton63094e02010-06-23 01:19:29 +0000529 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000530 {
531 bool abort_other_plans = true;
532 bool stop_other_threads = true;
533
534 Address target_addr (NULL, addr);
535
Greg Clayton63094e02010-06-23 01:19:29 +0000536 m_opaque_sp->QueueThreadPlanForRunToAddress (abort_other_plans, target_addr, stop_other_threads);
537 Process &process = m_opaque_sp->GetProcess();
Jim Inghamc8332952010-08-26 21:32:51 +0000538 process.GetThreadList().SetSelectedThreadByID (m_opaque_sp->GetID());
Greg Clayton1a3083a2010-10-06 03:53:16 +0000539 Error error (process.Resume());
540 if (error.Success())
541 {
542 // If we are doing synchronous mode, then wait for the
543 // process to stop yet again!
544 if (process.GetTarget().GetDebugger().GetAsyncExecution () == false)
545 process.WaitForProcessToStop (NULL);
546 }
Chris Lattner24943d22010-06-08 16:52:24 +0000547 }
548
549}
550
Chris Lattner24943d22010-06-08 16:52:24 +0000551SBProcess
552SBThread::GetProcess ()
553{
Caroline Tice7826c882010-10-26 03:11:13 +0000554
Chris Lattner24943d22010-06-08 16:52:24 +0000555 SBProcess process;
Greg Clayton63094e02010-06-23 01:19:29 +0000556 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000557 {
558 // Have to go up to the target so we can get a shared pointer to our process...
Greg Clayton63094e02010-06-23 01:19:29 +0000559 process.SetProcess(m_opaque_sp->GetProcess().GetTarget().GetProcessSP());
Chris Lattner24943d22010-06-08 16:52:24 +0000560 }
Caroline Tice7826c882010-10-26 03:11:13 +0000561
Greg Claytone005f2c2010-11-06 01:53:30 +0000562 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000563 if (log)
564 {
565 SBStream sstr;
566 process.GetDescription (sstr);
Greg Claytona66ba462010-10-30 04:51:46 +0000567 log->Printf ("SBThread(%p)::GetProcess () => SBProcess(%p): %s", m_opaque_sp.get(),
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000568 process.get(), sstr.GetData());
Caroline Tice7826c882010-10-26 03:11:13 +0000569 }
570
Chris Lattner24943d22010-06-08 16:52:24 +0000571 return process;
572}
573
574uint32_t
575SBThread::GetNumFrames ()
576{
Greg Claytone005f2c2010-11-06 01:53:30 +0000577 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000578
Caroline Tice7826c882010-10-26 03:11:13 +0000579 uint32_t num_frames = 0;
Greg Clayton63094e02010-06-23 01:19:29 +0000580 if (m_opaque_sp)
Caroline Tice7826c882010-10-26 03:11:13 +0000581 num_frames = m_opaque_sp->GetStackFrameCount();
582
583 if (log)
Greg Claytona66ba462010-10-30 04:51:46 +0000584 log->Printf ("SBThread(%p)::GetNumFrames () => %u", m_opaque_sp.get(), num_frames);
Caroline Tice7826c882010-10-26 03:11:13 +0000585
586 return num_frames;
Chris Lattner24943d22010-06-08 16:52:24 +0000587}
588
589SBFrame
590SBThread::GetFrameAtIndex (uint32_t idx)
591{
Greg Claytone005f2c2010-11-06 01:53:30 +0000592 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000593
Chris Lattner24943d22010-06-08 16:52:24 +0000594 SBFrame sb_frame;
Greg Clayton63094e02010-06-23 01:19:29 +0000595 if (m_opaque_sp)
596 sb_frame.SetFrame (m_opaque_sp->GetStackFrameAtIndex (idx));
Caroline Tice7826c882010-10-26 03:11:13 +0000597
598 if (log)
599 {
600 SBStream sstr;
601 sb_frame.GetDescription (sstr);
Greg Claytona66ba462010-10-30 04:51:46 +0000602 log->Printf ("SBThread(%p)::GetFrameAtIndex (idx=%d) => SBFrame(%p): %s",
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000603 m_opaque_sp.get(), idx, sb_frame.get(), sstr.GetData());
Caroline Tice7826c882010-10-26 03:11:13 +0000604 }
605
Chris Lattner24943d22010-06-08 16:52:24 +0000606 return sb_frame;
607}
608
Greg Claytonc5157ec2010-12-17 02:26:24 +0000609lldb::SBFrame
610SBThread::GetSelectedFrame ()
611{
612 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
613
614 SBFrame sb_frame;
615 if (m_opaque_sp)
616 sb_frame.SetFrame (m_opaque_sp->GetSelectedFrame ());
617
618 if (log)
619 {
620 SBStream sstr;
621 sb_frame.GetDescription (sstr);
622 log->Printf ("SBThread(%p)::GetSelectedFrame () => SBFrame(%p): %s",
623 m_opaque_sp.get(), sb_frame.get(), sstr.GetData());
624 }
625
626 return sb_frame;
627}
628
629lldb::SBFrame
630SBThread::SetSelectedFrame (uint32_t idx)
631{
632 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
633
634 SBFrame sb_frame;
635 if (m_opaque_sp)
636 {
637 lldb::StackFrameSP frame_sp (m_opaque_sp->GetStackFrameAtIndex (idx));
638 if (frame_sp)
639 {
640 m_opaque_sp->SetSelectedFrame (frame_sp.get());
641 sb_frame.SetFrame (frame_sp);
642 }
643 }
644
645 if (log)
646 {
647 SBStream sstr;
648 sb_frame.GetDescription (sstr);
649 log->Printf ("SBThread(%p)::SetSelectedFrame (idx=%u) => SBFrame(%p): %s",
650 m_opaque_sp.get(), idx, sb_frame.get(), sstr.GetData());
651 }
652 return sb_frame;
653}
654
655
Chris Lattner24943d22010-06-08 16:52:24 +0000656bool
657SBThread::operator == (const SBThread &rhs) const
658{
Greg Clayton63094e02010-06-23 01:19:29 +0000659 return m_opaque_sp.get() == rhs.m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000660}
661
662bool
663SBThread::operator != (const SBThread &rhs) const
664{
Greg Clayton63094e02010-06-23 01:19:29 +0000665 return m_opaque_sp.get() != rhs.m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000666}
667
668lldb_private::Thread *
Greg Claytona66ba462010-10-30 04:51:46 +0000669SBThread::get ()
Chris Lattner24943d22010-06-08 16:52:24 +0000670{
Greg Clayton63094e02010-06-23 01:19:29 +0000671 return m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000672}
673
674const lldb_private::Thread *
675SBThread::operator->() const
676{
Greg Clayton63094e02010-06-23 01:19:29 +0000677 return m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000678}
679
680const lldb_private::Thread &
681SBThread::operator*() const
682{
Greg Clayton63094e02010-06-23 01:19:29 +0000683 return *m_opaque_sp;
Chris Lattner24943d22010-06-08 16:52:24 +0000684}
685
686lldb_private::Thread *
687SBThread::operator->()
688{
Greg Clayton63094e02010-06-23 01:19:29 +0000689 return m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000690}
691
692lldb_private::Thread &
693SBThread::operator*()
694{
Greg Clayton63094e02010-06-23 01:19:29 +0000695 return *m_opaque_sp;
Chris Lattner24943d22010-06-08 16:52:24 +0000696}
Caroline Tice98f930f2010-09-20 05:20:02 +0000697
698bool
Caroline Tice7826c882010-10-26 03:11:13 +0000699SBThread::GetDescription (SBStream &description) const
700{
701 if (m_opaque_sp)
702 {
703 StreamString strm;
704 description.Printf("SBThread: tid = 0x%4.4x", m_opaque_sp->GetID());
705 }
706 else
707 description.Printf ("No value");
708
709 return true;
710}