blob: ca356244d780cdd3d315b15f8ee71fb65d43939c [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 Clayton63094e02010-06-23 01:19:29 +000015#include "lldb/Core/Debugger.h"
Chris Lattner24943d22010-06-08 16:52:24 +000016#include "lldb/Core/Stream.h"
17#include "lldb/Core/StreamFile.h"
Greg Clayton63094e02010-06-23 01:19:29 +000018#include "lldb/Interpreter/CommandInterpreter.h"
Chris Lattner24943d22010-06-08 16:52:24 +000019#include "lldb/Target/Thread.h"
20#include "lldb/Target/Process.h"
21#include "lldb/Symbol/SymbolContext.h"
22#include "lldb/Symbol/CompileUnit.h"
Greg Clayton643ee732010-08-04 01:40:35 +000023#include "lldb/Target/StopInfo.h"
Chris Lattner24943d22010-06-08 16:52:24 +000024#include "lldb/Target/Target.h"
25#include "lldb/Target/ThreadPlan.h"
Chris Lattner24943d22010-06-08 16:52:24 +000026#include "lldb/Target/ThreadPlanStepInstruction.h"
27#include "lldb/Target/ThreadPlanStepOut.h"
28#include "lldb/Target/ThreadPlanStepRange.h"
29#include "lldb/Target/ThreadPlanStepInRange.h"
30
31
Eli Friedman7a62c8b2010-06-09 07:44:37 +000032#include "lldb/API/SBAddress.h"
33#include "lldb/API/SBFrame.h"
34#include "lldb/API/SBSourceManager.h"
35#include "lldb/API/SBDebugger.h"
36#include "lldb/API/SBProcess.h"
Chris Lattner24943d22010-06-08 16:52:24 +000037
38using namespace lldb;
39using namespace lldb_private;
40
Greg Clayton49ce6822010-10-31 03:01:06 +000041//----------------------------------------------------------------------
42// Constructors
43//----------------------------------------------------------------------
Chris Lattner24943d22010-06-08 16:52:24 +000044SBThread::SBThread () :
Greg Clayton63094e02010-06-23 01:19:29 +000045 m_opaque_sp ()
Chris Lattner24943d22010-06-08 16:52:24 +000046{
47}
48
Chris Lattner24943d22010-06-08 16:52:24 +000049SBThread::SBThread (const ThreadSP& lldb_object_sp) :
Greg Clayton63094e02010-06-23 01:19:29 +000050 m_opaque_sp (lldb_object_sp)
Chris Lattner24943d22010-06-08 16:52:24 +000051{
52}
53
Greg Clayton1b284412010-10-30 18:26:59 +000054SBThread::SBThread (const SBThread &rhs) :
55 m_opaque_sp (rhs.m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +000056{
Chris Lattner24943d22010-06-08 16:52:24 +000057}
58
59//----------------------------------------------------------------------
Greg Clayton49ce6822010-10-31 03:01:06 +000060// Assignment operator
61//----------------------------------------------------------------------
62
63const lldb::SBThread &
64SBThread::operator = (const SBThread &rhs)
65{
66 if (this != &rhs)
67 m_opaque_sp = rhs.m_opaque_sp;
68 return *this;
69}
70
71//----------------------------------------------------------------------
Chris Lattner24943d22010-06-08 16:52:24 +000072// Destructor
73//----------------------------------------------------------------------
74SBThread::~SBThread()
75{
76}
77
78bool
79SBThread::IsValid() const
80{
Greg Clayton63094e02010-06-23 01:19:29 +000081 return m_opaque_sp != NULL;
Chris Lattner24943d22010-06-08 16:52:24 +000082}
83
Greg Clayton43490d12010-07-30 20:12:55 +000084void
85SBThread::Clear ()
86{
87 m_opaque_sp.reset();
88}
89
90
Chris Lattner24943d22010-06-08 16:52:24 +000091StopReason
92SBThread::GetStopReason()
93{
Caroline Tice7826c882010-10-26 03:11:13 +000094 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
95
Caroline Tice7826c882010-10-26 03:11:13 +000096 StopReason reason = eStopReasonInvalid;
Greg Clayton63094e02010-06-23 01:19:29 +000097 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +000098 {
Jim Ingham6297a3a2010-10-20 00:39:53 +000099 StopInfoSP stop_info_sp = m_opaque_sp->GetStopInfo ();
100 if (stop_info_sp)
Caroline Tice7826c882010-10-26 03:11:13 +0000101 reason = stop_info_sp->GetStopReason();
Chris Lattner24943d22010-06-08 16:52:24 +0000102 }
Caroline Tice7826c882010-10-26 03:11:13 +0000103
104 if (log)
Greg Claytona66ba462010-10-30 04:51:46 +0000105 log->Printf ("SBThread(%p)::GetStopReason () => %s", m_opaque_sp.get(),
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000106 Thread::StopReasonAsCString (reason));
Caroline Tice7826c882010-10-26 03:11:13 +0000107
108 return reason;
Chris Lattner24943d22010-06-08 16:52:24 +0000109}
110
111size_t
112SBThread::GetStopDescription (char *dst, size_t dst_len)
113{
Caroline Tice7826c882010-10-26 03:11:13 +0000114 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
115
Greg Clayton63094e02010-06-23 01:19:29 +0000116 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000117 {
Jim Ingham6297a3a2010-10-20 00:39:53 +0000118 StopInfoSP stop_info_sp = m_opaque_sp->GetStopInfo ();
119 if (stop_info_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000120 {
Jim Ingham6297a3a2010-10-20 00:39:53 +0000121 const char *stop_desc = stop_info_sp->GetDescription();
Chris Lattner24943d22010-06-08 16:52:24 +0000122 if (stop_desc)
123 {
Caroline Tice7826c882010-10-26 03:11:13 +0000124 if (log)
Greg Claytona66ba462010-10-30 04:51:46 +0000125 log->Printf ("SBThread(%p)::GetStopDescription (dst, dst_len) => \"%s\"",
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000126 m_opaque_sp.get(), stop_desc);
Chris Lattner24943d22010-06-08 16:52:24 +0000127 if (dst)
128 return ::snprintf (dst, dst_len, "%s", stop_desc);
129 else
130 {
131 // NULL dst passed in, return the length needed to contain the description
132 return ::strlen (stop_desc) + 1; // Include the NULL byte for size
133 }
134 }
135 else
136 {
Chris Lattner24943d22010-06-08 16:52:24 +0000137 size_t stop_desc_len = 0;
Jim Ingham6297a3a2010-10-20 00:39:53 +0000138 switch (stop_info_sp->GetStopReason())
Chris Lattner24943d22010-06-08 16:52:24 +0000139 {
140 case eStopReasonTrace:
141 case eStopReasonPlanComplete:
142 {
143 static char trace_desc[] = "step";
144 stop_desc = trace_desc;
145 stop_desc_len = sizeof(trace_desc); // Include the NULL byte for size
146 }
147 break;
148
149 case eStopReasonBreakpoint:
150 {
151 static char bp_desc[] = "breakpoint hit";
152 stop_desc = bp_desc;
153 stop_desc_len = sizeof(bp_desc); // Include the NULL byte for size
154 }
155 break;
156
157 case eStopReasonWatchpoint:
158 {
159 static char wp_desc[] = "watchpoint hit";
160 stop_desc = wp_desc;
161 stop_desc_len = sizeof(wp_desc); // Include the NULL byte for size
162 }
163 break;
164
165 case eStopReasonSignal:
166 {
Jim Ingham6297a3a2010-10-20 00:39:53 +0000167 stop_desc = m_opaque_sp->GetProcess().GetUnixSignals ().GetSignalAsCString (stop_info_sp->GetValue());
Chris Lattner24943d22010-06-08 16:52:24 +0000168 if (stop_desc == NULL || stop_desc[0] == '\0')
169 {
170 static char signal_desc[] = "signal";
171 stop_desc = signal_desc;
172 stop_desc_len = sizeof(signal_desc); // Include the NULL byte for size
173 }
174 }
175 break;
176
177 case eStopReasonException:
178 {
179 char exc_desc[] = "exception";
180 stop_desc = exc_desc;
181 stop_desc_len = sizeof(exc_desc); // Include the NULL byte for size
182 }
Greg Clayton54e7afa2010-07-09 20:39:50 +0000183 break;
184
185 default:
186 break;
Chris Lattner24943d22010-06-08 16:52:24 +0000187 }
188
189 if (stop_desc && stop_desc[0])
190 {
Caroline Tice7826c882010-10-26 03:11:13 +0000191 if (log)
Greg Clayton3f5ee7f2010-10-29 04:59:35 +0000192 log->Printf ("SBThread(%p)::GetStopDescription (dst, dst_len) => '%s'",
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000193 m_opaque_sp.get(), stop_desc);
Caroline Tice7826c882010-10-26 03:11:13 +0000194
Chris Lattner24943d22010-06-08 16:52:24 +0000195 if (dst)
196 return ::snprintf (dst, dst_len, "%s", stop_desc) + 1; // Include the NULL byte
197
198 if (stop_desc_len == 0)
199 stop_desc_len = ::strlen (stop_desc) + 1; // Include the NULL byte
200
201 return stop_desc_len;
202 }
203 }
204 }
205 }
206 if (dst)
207 *dst = 0;
208 return 0;
209}
210
211void
212SBThread::SetThread (const ThreadSP& lldb_object_sp)
213{
Greg Clayton63094e02010-06-23 01:19:29 +0000214 m_opaque_sp = lldb_object_sp;
Chris Lattner24943d22010-06-08 16:52:24 +0000215}
216
217
218lldb::tid_t
219SBThread::GetThreadID () const
220{
Caroline Tice7826c882010-10-26 03:11:13 +0000221 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
222
Caroline Tice7826c882010-10-26 03:11:13 +0000223 lldb::tid_t id = LLDB_INVALID_THREAD_ID;
Greg Clayton63094e02010-06-23 01:19:29 +0000224 if (m_opaque_sp)
Caroline Tice7826c882010-10-26 03:11:13 +0000225 id = m_opaque_sp->GetID();
226
227 if (log)
Greg Claytona66ba462010-10-30 04:51:46 +0000228 log->Printf ("SBThread(%p)::GetThreadID () => 0x%4.4x", m_opaque_sp.get(), id);
Caroline Tice7826c882010-10-26 03:11:13 +0000229
230 return id;
Chris Lattner24943d22010-06-08 16:52:24 +0000231}
232
233uint32_t
234SBThread::GetIndexID () const
235{
Greg Clayton63094e02010-06-23 01:19:29 +0000236 if (m_opaque_sp)
237 return m_opaque_sp->GetIndexID();
Chris Lattner24943d22010-06-08 16:52:24 +0000238 return LLDB_INVALID_INDEX32;
239}
240const char *
241SBThread::GetName () const
242{
Greg Claytona66ba462010-10-30 04:51:46 +0000243 const char *name = NULL;
Greg Clayton63094e02010-06-23 01:19:29 +0000244 if (m_opaque_sp)
Greg Claytona66ba462010-10-30 04:51:46 +0000245 name = m_opaque_sp->GetName();
246
247 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
Caroline Tice7826c882010-10-26 03:11:13 +0000248 if (log)
Greg Claytona66ba462010-10-30 04:51:46 +0000249 log->Printf ("SBThread(%p)::GetName () => %s", m_opaque_sp.get(), name ? name : "NULL");
Caroline Tice7826c882010-10-26 03:11:13 +0000250
Greg Claytona66ba462010-10-30 04:51:46 +0000251 return name;
Chris Lattner24943d22010-06-08 16:52:24 +0000252}
253
254const char *
255SBThread::GetQueueName () const
256{
Greg Claytona66ba462010-10-30 04:51:46 +0000257 const char *name = NULL;
Greg Clayton63094e02010-06-23 01:19:29 +0000258 if (m_opaque_sp)
Greg Claytona66ba462010-10-30 04:51:46 +0000259 name = m_opaque_sp->GetQueueName();
260
261 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
Caroline Tice7826c882010-10-26 03:11:13 +0000262 if (log)
Greg Claytona66ba462010-10-30 04:51:46 +0000263 log->Printf ("SBThread(%p)::GetQueueName () => %s", m_opaque_sp.get(), name ? name : "NULL");
Caroline Tice7826c882010-10-26 03:11:13 +0000264
Greg Claytona66ba462010-10-30 04:51:46 +0000265 return name;
Chris Lattner24943d22010-06-08 16:52:24 +0000266}
267
268
269void
Chris Lattner24943d22010-06-08 16:52:24 +0000270SBThread::StepOver (lldb::RunMode stop_other_threads)
271{
Caroline Tice7826c882010-10-26 03:11:13 +0000272 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
273
274 if (log)
Greg Clayton3f5ee7f2010-10-29 04:59:35 +0000275 log->Printf ("SBThread(%p)::StepOver (stop_other_threads='%s')", m_opaque_sp.get(),
Caroline Tice7826c882010-10-26 03:11:13 +0000276 Thread::RunModeAsCString (stop_other_threads));
277
Greg Clayton63094e02010-06-23 01:19:29 +0000278 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000279 {
280 bool abort_other_plans = true;
Greg Clayton63094e02010-06-23 01:19:29 +0000281 StackFrameSP frame_sp(m_opaque_sp->GetStackFrameAtIndex (0));
Chris Lattner24943d22010-06-08 16:52:24 +0000282
283 if (frame_sp)
284 {
285 if (frame_sp->HasDebugInformation ())
286 {
287 SymbolContext sc(frame_sp->GetSymbolContext(eSymbolContextEverything));
Greg Clayton63094e02010-06-23 01:19:29 +0000288 m_opaque_sp->QueueThreadPlanForStepRange (abort_other_plans,
Greg Clayton1a3083a2010-10-06 03:53:16 +0000289 eStepTypeOver,
290 sc.line_entry.range,
291 sc,
292 stop_other_threads,
293 false);
Chris Lattner24943d22010-06-08 16:52:24 +0000294
295 }
296 else
297 {
Greg Clayton63094e02010-06-23 01:19:29 +0000298 m_opaque_sp->QueueThreadPlanForStepSingleInstruction (true,
Greg Clayton1a3083a2010-10-06 03:53:16 +0000299 abort_other_plans,
300 stop_other_threads);
Chris Lattner24943d22010-06-08 16:52:24 +0000301 }
302 }
303
Greg Clayton63094e02010-06-23 01:19:29 +0000304 Process &process = m_opaque_sp->GetProcess();
Chris Lattner24943d22010-06-08 16:52:24 +0000305 // Why do we need to set the current thread by ID here???
Jim Inghamc8332952010-08-26 21:32:51 +0000306 process.GetThreadList().SetSelectedThreadByID (m_opaque_sp->GetID());
Greg Clayton1a3083a2010-10-06 03:53:16 +0000307 Error error (process.Resume());
308 if (error.Success())
309 {
310 // If we are doing synchronous mode, then wait for the
311 // process to stop yet again!
312 if (process.GetTarget().GetDebugger().GetAsyncExecution () == false)
313 process.WaitForProcessToStop (NULL);
314 }
Chris Lattner24943d22010-06-08 16:52:24 +0000315 }
316}
317
318void
319SBThread::StepInto (lldb::RunMode stop_other_threads)
320{
Caroline Tice7826c882010-10-26 03:11:13 +0000321 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
322
323 if (log)
Greg Clayton3f5ee7f2010-10-29 04:59:35 +0000324 log->Printf ("SBThread(%p)::StepInto (stop_other_threads='%s')", m_opaque_sp.get(),
Caroline Tice7826c882010-10-26 03:11:13 +0000325 Thread::RunModeAsCString (stop_other_threads));
326
Greg Clayton63094e02010-06-23 01:19:29 +0000327 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000328 {
329 bool abort_other_plans = true;
330
Greg Clayton63094e02010-06-23 01:19:29 +0000331 StackFrameSP frame_sp(m_opaque_sp->GetStackFrameAtIndex (0));
Chris Lattner24943d22010-06-08 16:52:24 +0000332
333 if (frame_sp && frame_sp->HasDebugInformation ())
334 {
Greg Clayton8f5fd6b2010-06-12 18:59:55 +0000335 bool avoid_code_without_debug_info = true;
Chris Lattner24943d22010-06-08 16:52:24 +0000336 SymbolContext sc(frame_sp->GetSymbolContext(eSymbolContextEverything));
Greg Clayton63094e02010-06-23 01:19:29 +0000337 m_opaque_sp->QueueThreadPlanForStepRange (abort_other_plans,
Greg Clayton1a3083a2010-10-06 03:53:16 +0000338 eStepTypeInto,
339 sc.line_entry.range,
340 sc,
341 stop_other_threads,
342 avoid_code_without_debug_info);
Chris Lattner24943d22010-06-08 16:52:24 +0000343 }
344 else
345 {
Greg Clayton63094e02010-06-23 01:19:29 +0000346 m_opaque_sp->QueueThreadPlanForStepSingleInstruction (false,
Greg Clayton1a3083a2010-10-06 03:53:16 +0000347 abort_other_plans,
348 stop_other_threads);
Chris Lattner24943d22010-06-08 16:52:24 +0000349 }
350
Greg Clayton63094e02010-06-23 01:19:29 +0000351 Process &process = m_opaque_sp->GetProcess();
Chris Lattner24943d22010-06-08 16:52:24 +0000352 // Why do we need to set the current thread by ID here???
Jim Inghamc8332952010-08-26 21:32:51 +0000353 process.GetThreadList().SetSelectedThreadByID (m_opaque_sp->GetID());
Greg Clayton1a3083a2010-10-06 03:53:16 +0000354 Error error (process.Resume());
355 if (error.Success())
356 {
357 // If we are doing synchronous mode, then wait for the
358 // process to stop yet again!
359 if (process.GetTarget().GetDebugger().GetAsyncExecution () == false)
360 process.WaitForProcessToStop (NULL);
361 }
Chris Lattner24943d22010-06-08 16:52:24 +0000362 }
363}
364
365void
366SBThread::StepOut ()
367{
Caroline Tice7826c882010-10-26 03:11:13 +0000368 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
369
370 if (log)
Greg Claytona66ba462010-10-30 04:51:46 +0000371 log->Printf ("SBThread(%p)::StepOut ()", m_opaque_sp.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000372
Greg Clayton63094e02010-06-23 01:19:29 +0000373 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000374 {
375 bool abort_other_plans = true;
376 bool stop_other_threads = true;
377
Greg Clayton63094e02010-06-23 01:19:29 +0000378 m_opaque_sp->QueueThreadPlanForStepOut (abort_other_plans, NULL, false, stop_other_threads, eVoteYes, eVoteNoOpinion);
Chris Lattner24943d22010-06-08 16:52:24 +0000379
Greg Clayton63094e02010-06-23 01:19:29 +0000380 Process &process = m_opaque_sp->GetProcess();
Jim Inghamc8332952010-08-26 21:32:51 +0000381 process.GetThreadList().SetSelectedThreadByID (m_opaque_sp->GetID());
Greg Clayton1a3083a2010-10-06 03:53:16 +0000382 Error error (process.Resume());
383 if (error.Success())
384 {
385 // If we are doing synchronous mode, then wait for the
386 // process to stop yet again!
387 if (process.GetTarget().GetDebugger().GetAsyncExecution () == false)
388 process.WaitForProcessToStop (NULL);
389 }
Chris Lattner24943d22010-06-08 16:52:24 +0000390 }
391}
392
393void
394SBThread::StepInstruction (bool step_over)
395{
Caroline Tice7826c882010-10-26 03:11:13 +0000396 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
397
398 if (log)
Greg Clayton3f5ee7f2010-10-29 04:59:35 +0000399 log->Printf ("SBThread(%p)::StepInstruction (step_over=%i)", m_opaque_sp.get(), step_over);
Caroline Tice7826c882010-10-26 03:11:13 +0000400
Greg Clayton63094e02010-06-23 01:19:29 +0000401 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000402 {
Greg Clayton63094e02010-06-23 01:19:29 +0000403 m_opaque_sp->QueueThreadPlanForStepSingleInstruction (step_over, true, true);
404 Process &process = m_opaque_sp->GetProcess();
Jim Inghamc8332952010-08-26 21:32:51 +0000405 process.GetThreadList().SetSelectedThreadByID (m_opaque_sp->GetID());
Greg Clayton1a3083a2010-10-06 03:53:16 +0000406 Error error (process.Resume());
407 if (error.Success())
408 {
409 // If we are doing synchronous mode, then wait for the
410 // process to stop yet again!
411 if (process.GetTarget().GetDebugger().GetAsyncExecution () == false)
412 process.WaitForProcessToStop (NULL);
413 }
Chris Lattner24943d22010-06-08 16:52:24 +0000414 }
415}
416
417void
418SBThread::RunToAddress (lldb::addr_t addr)
419{
Caroline Tice7826c882010-10-26 03:11:13 +0000420 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
421
422 if (log)
Greg Clayton3f5ee7f2010-10-29 04:59:35 +0000423 log->Printf ("SBThread(%p)::RunToAddress (addr=0x%llx)", m_opaque_sp.get(), addr);
Caroline Tice7826c882010-10-26 03:11:13 +0000424
Greg Clayton63094e02010-06-23 01:19:29 +0000425 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000426 {
427 bool abort_other_plans = true;
428 bool stop_other_threads = true;
429
430 Address target_addr (NULL, addr);
431
Greg Clayton63094e02010-06-23 01:19:29 +0000432 m_opaque_sp->QueueThreadPlanForRunToAddress (abort_other_plans, target_addr, stop_other_threads);
433 Process &process = m_opaque_sp->GetProcess();
Jim Inghamc8332952010-08-26 21:32:51 +0000434 process.GetThreadList().SetSelectedThreadByID (m_opaque_sp->GetID());
Greg Clayton1a3083a2010-10-06 03:53:16 +0000435 Error error (process.Resume());
436 if (error.Success())
437 {
438 // If we are doing synchronous mode, then wait for the
439 // process to stop yet again!
440 if (process.GetTarget().GetDebugger().GetAsyncExecution () == false)
441 process.WaitForProcessToStop (NULL);
442 }
Chris Lattner24943d22010-06-08 16:52:24 +0000443 }
444
445}
446
Chris Lattner24943d22010-06-08 16:52:24 +0000447SBProcess
448SBThread::GetProcess ()
449{
Caroline Tice7826c882010-10-26 03:11:13 +0000450
Chris Lattner24943d22010-06-08 16:52:24 +0000451 SBProcess process;
Greg Clayton63094e02010-06-23 01:19:29 +0000452 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000453 {
454 // Have to go up to the target so we can get a shared pointer to our process...
Greg Clayton63094e02010-06-23 01:19:29 +0000455 process.SetProcess(m_opaque_sp->GetProcess().GetTarget().GetProcessSP());
Chris Lattner24943d22010-06-08 16:52:24 +0000456 }
Caroline Tice7826c882010-10-26 03:11:13 +0000457
Caroline Tice926060e2010-10-29 21:48:37 +0000458 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
Caroline Tice7826c882010-10-26 03:11:13 +0000459 if (log)
460 {
461 SBStream sstr;
462 process.GetDescription (sstr);
Greg Claytona66ba462010-10-30 04:51:46 +0000463 log->Printf ("SBThread(%p)::GetProcess () => SBProcess(%p): %s", m_opaque_sp.get(),
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000464 process.get(), sstr.GetData());
Caroline Tice7826c882010-10-26 03:11:13 +0000465 }
466
Chris Lattner24943d22010-06-08 16:52:24 +0000467 return process;
468}
469
470uint32_t
471SBThread::GetNumFrames ()
472{
Caroline Tice7826c882010-10-26 03:11:13 +0000473 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
474
Caroline Tice7826c882010-10-26 03:11:13 +0000475 uint32_t num_frames = 0;
Greg Clayton63094e02010-06-23 01:19:29 +0000476 if (m_opaque_sp)
Caroline Tice7826c882010-10-26 03:11:13 +0000477 num_frames = m_opaque_sp->GetStackFrameCount();
478
479 if (log)
Greg Claytona66ba462010-10-30 04:51:46 +0000480 log->Printf ("SBThread(%p)::GetNumFrames () => %u", m_opaque_sp.get(), num_frames);
Caroline Tice7826c882010-10-26 03:11:13 +0000481
482 return num_frames;
Chris Lattner24943d22010-06-08 16:52:24 +0000483}
484
485SBFrame
486SBThread::GetFrameAtIndex (uint32_t idx)
487{
Caroline Tice7826c882010-10-26 03:11:13 +0000488 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
489
Chris Lattner24943d22010-06-08 16:52:24 +0000490 SBFrame sb_frame;
Greg Clayton63094e02010-06-23 01:19:29 +0000491 if (m_opaque_sp)
492 sb_frame.SetFrame (m_opaque_sp->GetStackFrameAtIndex (idx));
Caroline Tice7826c882010-10-26 03:11:13 +0000493
494 if (log)
495 {
496 SBStream sstr;
497 sb_frame.GetDescription (sstr);
Greg Claytona66ba462010-10-30 04:51:46 +0000498 log->Printf ("SBThread(%p)::GetFrameAtIndex (idx=%d) => SBFrame(%p): %s",
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000499 m_opaque_sp.get(), idx, sb_frame.get(), sstr.GetData());
Caroline Tice7826c882010-10-26 03:11:13 +0000500 }
501
Chris Lattner24943d22010-06-08 16:52:24 +0000502 return sb_frame;
503}
504
Chris Lattner24943d22010-06-08 16:52:24 +0000505bool
506SBThread::operator == (const SBThread &rhs) const
507{
Greg Clayton63094e02010-06-23 01:19:29 +0000508 return m_opaque_sp.get() == rhs.m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000509}
510
511bool
512SBThread::operator != (const SBThread &rhs) const
513{
Greg Clayton63094e02010-06-23 01:19:29 +0000514 return m_opaque_sp.get() != rhs.m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000515}
516
517lldb_private::Thread *
Greg Claytona66ba462010-10-30 04:51:46 +0000518SBThread::get ()
Chris Lattner24943d22010-06-08 16:52:24 +0000519{
Greg Clayton63094e02010-06-23 01:19:29 +0000520 return m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000521}
522
523const lldb_private::Thread *
524SBThread::operator->() const
525{
Greg Clayton63094e02010-06-23 01:19:29 +0000526 return m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000527}
528
529const lldb_private::Thread &
530SBThread::operator*() const
531{
Greg Clayton63094e02010-06-23 01:19:29 +0000532 return *m_opaque_sp;
Chris Lattner24943d22010-06-08 16:52:24 +0000533}
534
535lldb_private::Thread *
536SBThread::operator->()
537{
Greg Clayton63094e02010-06-23 01:19:29 +0000538 return m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000539}
540
541lldb_private::Thread &
542SBThread::operator*()
543{
Greg Clayton63094e02010-06-23 01:19:29 +0000544 return *m_opaque_sp;
Chris Lattner24943d22010-06-08 16:52:24 +0000545}
Caroline Tice98f930f2010-09-20 05:20:02 +0000546
547bool
Caroline Tice7826c882010-10-26 03:11:13 +0000548SBThread::GetDescription (SBStream &description) const
549{
550 if (m_opaque_sp)
551 {
552 StreamString strm;
553 description.Printf("SBThread: tid = 0x%4.4x", m_opaque_sp->GetID());
554 }
555 else
556 description.Printf ("No value");
557
558 return true;
559}