blob: 782569e5306bbdf19cecca5f55bbb70384d13e85 [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
41SBThread::SBThread () :
Greg Clayton63094e02010-06-23 01:19:29 +000042 m_opaque_sp ()
Chris Lattner24943d22010-06-08 16:52:24 +000043{
44}
45
46//----------------------------------------------------------------------
47// Thread constructor
48//----------------------------------------------------------------------
49SBThread::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
54SBThread::SBThread (const SBThread &rhs)
55{
Chris Lattner24943d22010-06-08 16:52:24 +000056}
57
58//----------------------------------------------------------------------
59// Destructor
60//----------------------------------------------------------------------
61SBThread::~SBThread()
62{
63}
64
65bool
66SBThread::IsValid() const
67{
Greg Clayton63094e02010-06-23 01:19:29 +000068 return m_opaque_sp != NULL;
Chris Lattner24943d22010-06-08 16:52:24 +000069}
70
Greg Clayton43490d12010-07-30 20:12:55 +000071void
72SBThread::Clear ()
73{
74 m_opaque_sp.reset();
75}
76
77
Chris Lattner24943d22010-06-08 16:52:24 +000078StopReason
79SBThread::GetStopReason()
80{
Caroline Tice7826c882010-10-26 03:11:13 +000081 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
82
Caroline Tice7826c882010-10-26 03:11:13 +000083 StopReason reason = eStopReasonInvalid;
Greg Clayton63094e02010-06-23 01:19:29 +000084 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +000085 {
Jim Ingham6297a3a2010-10-20 00:39:53 +000086 StopInfoSP stop_info_sp = m_opaque_sp->GetStopInfo ();
87 if (stop_info_sp)
Caroline Tice7826c882010-10-26 03:11:13 +000088 reason = stop_info_sp->GetStopReason();
Chris Lattner24943d22010-06-08 16:52:24 +000089 }
Caroline Tice7826c882010-10-26 03:11:13 +000090
91 if (log)
Greg Claytona66ba462010-10-30 04:51:46 +000092 log->Printf ("SBThread(%p)::GetStopReason () => %s", m_opaque_sp.get(),
Caroline Tice61ba7ec2010-10-26 23:49:36 +000093 Thread::StopReasonAsCString (reason));
Caroline Tice7826c882010-10-26 03:11:13 +000094
95 return reason;
Chris Lattner24943d22010-06-08 16:52:24 +000096}
97
98size_t
99SBThread::GetStopDescription (char *dst, size_t dst_len)
100{
Caroline Tice7826c882010-10-26 03:11:13 +0000101 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
102
Greg Clayton63094e02010-06-23 01:19:29 +0000103 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000104 {
Jim Ingham6297a3a2010-10-20 00:39:53 +0000105 StopInfoSP stop_info_sp = m_opaque_sp->GetStopInfo ();
106 if (stop_info_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000107 {
Jim Ingham6297a3a2010-10-20 00:39:53 +0000108 const char *stop_desc = stop_info_sp->GetDescription();
Chris Lattner24943d22010-06-08 16:52:24 +0000109 if (stop_desc)
110 {
Caroline Tice7826c882010-10-26 03:11:13 +0000111 if (log)
Greg Claytona66ba462010-10-30 04:51:46 +0000112 log->Printf ("SBThread(%p)::GetStopDescription (dst, dst_len) => \"%s\"",
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000113 m_opaque_sp.get(), stop_desc);
Chris Lattner24943d22010-06-08 16:52:24 +0000114 if (dst)
115 return ::snprintf (dst, dst_len, "%s", stop_desc);
116 else
117 {
118 // NULL dst passed in, return the length needed to contain the description
119 return ::strlen (stop_desc) + 1; // Include the NULL byte for size
120 }
121 }
122 else
123 {
Chris Lattner24943d22010-06-08 16:52:24 +0000124 size_t stop_desc_len = 0;
Jim Ingham6297a3a2010-10-20 00:39:53 +0000125 switch (stop_info_sp->GetStopReason())
Chris Lattner24943d22010-06-08 16:52:24 +0000126 {
127 case eStopReasonTrace:
128 case eStopReasonPlanComplete:
129 {
130 static char trace_desc[] = "step";
131 stop_desc = trace_desc;
132 stop_desc_len = sizeof(trace_desc); // Include the NULL byte for size
133 }
134 break;
135
136 case eStopReasonBreakpoint:
137 {
138 static char bp_desc[] = "breakpoint hit";
139 stop_desc = bp_desc;
140 stop_desc_len = sizeof(bp_desc); // Include the NULL byte for size
141 }
142 break;
143
144 case eStopReasonWatchpoint:
145 {
146 static char wp_desc[] = "watchpoint hit";
147 stop_desc = wp_desc;
148 stop_desc_len = sizeof(wp_desc); // Include the NULL byte for size
149 }
150 break;
151
152 case eStopReasonSignal:
153 {
Jim Ingham6297a3a2010-10-20 00:39:53 +0000154 stop_desc = m_opaque_sp->GetProcess().GetUnixSignals ().GetSignalAsCString (stop_info_sp->GetValue());
Chris Lattner24943d22010-06-08 16:52:24 +0000155 if (stop_desc == NULL || stop_desc[0] == '\0')
156 {
157 static char signal_desc[] = "signal";
158 stop_desc = signal_desc;
159 stop_desc_len = sizeof(signal_desc); // Include the NULL byte for size
160 }
161 }
162 break;
163
164 case eStopReasonException:
165 {
166 char exc_desc[] = "exception";
167 stop_desc = exc_desc;
168 stop_desc_len = sizeof(exc_desc); // Include the NULL byte for size
169 }
Greg Clayton54e7afa2010-07-09 20:39:50 +0000170 break;
171
172 default:
173 break;
Chris Lattner24943d22010-06-08 16:52:24 +0000174 }
175
176 if (stop_desc && stop_desc[0])
177 {
Caroline Tice7826c882010-10-26 03:11:13 +0000178 if (log)
Greg Clayton3f5ee7f2010-10-29 04:59:35 +0000179 log->Printf ("SBThread(%p)::GetStopDescription (dst, dst_len) => '%s'",
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000180 m_opaque_sp.get(), stop_desc);
Caroline Tice7826c882010-10-26 03:11:13 +0000181
Chris Lattner24943d22010-06-08 16:52:24 +0000182 if (dst)
183 return ::snprintf (dst, dst_len, "%s", stop_desc) + 1; // Include the NULL byte
184
185 if (stop_desc_len == 0)
186 stop_desc_len = ::strlen (stop_desc) + 1; // Include the NULL byte
187
188 return stop_desc_len;
189 }
190 }
191 }
192 }
193 if (dst)
194 *dst = 0;
195 return 0;
196}
197
198void
199SBThread::SetThread (const ThreadSP& lldb_object_sp)
200{
Greg Clayton63094e02010-06-23 01:19:29 +0000201 m_opaque_sp = lldb_object_sp;
Chris Lattner24943d22010-06-08 16:52:24 +0000202}
203
204
205lldb::tid_t
206SBThread::GetThreadID () const
207{
Caroline Tice7826c882010-10-26 03:11:13 +0000208 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
209
Caroline Tice7826c882010-10-26 03:11:13 +0000210 lldb::tid_t id = LLDB_INVALID_THREAD_ID;
Greg Clayton63094e02010-06-23 01:19:29 +0000211 if (m_opaque_sp)
Caroline Tice7826c882010-10-26 03:11:13 +0000212 id = m_opaque_sp->GetID();
213
214 if (log)
Greg Claytona66ba462010-10-30 04:51:46 +0000215 log->Printf ("SBThread(%p)::GetThreadID () => 0x%4.4x", m_opaque_sp.get(), id);
Caroline Tice7826c882010-10-26 03:11:13 +0000216
217 return id;
Chris Lattner24943d22010-06-08 16:52:24 +0000218}
219
220uint32_t
221SBThread::GetIndexID () const
222{
Greg Clayton63094e02010-06-23 01:19:29 +0000223 if (m_opaque_sp)
224 return m_opaque_sp->GetIndexID();
Chris Lattner24943d22010-06-08 16:52:24 +0000225 return LLDB_INVALID_INDEX32;
226}
227const char *
228SBThread::GetName () const
229{
Greg Claytona66ba462010-10-30 04:51:46 +0000230 const char *name = NULL;
Greg Clayton63094e02010-06-23 01:19:29 +0000231 if (m_opaque_sp)
Greg Claytona66ba462010-10-30 04:51:46 +0000232 name = m_opaque_sp->GetName();
233
234 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
Caroline Tice7826c882010-10-26 03:11:13 +0000235 if (log)
Greg Claytona66ba462010-10-30 04:51:46 +0000236 log->Printf ("SBThread(%p)::GetName () => %s", m_opaque_sp.get(), name ? name : "NULL");
Caroline Tice7826c882010-10-26 03:11:13 +0000237
Greg Claytona66ba462010-10-30 04:51:46 +0000238 return name;
Chris Lattner24943d22010-06-08 16:52:24 +0000239}
240
241const char *
242SBThread::GetQueueName () const
243{
Greg Claytona66ba462010-10-30 04:51:46 +0000244 const char *name = NULL;
Greg Clayton63094e02010-06-23 01:19:29 +0000245 if (m_opaque_sp)
Greg Claytona66ba462010-10-30 04:51:46 +0000246 name = m_opaque_sp->GetQueueName();
247
248 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
Caroline Tice7826c882010-10-26 03:11:13 +0000249 if (log)
Greg Claytona66ba462010-10-30 04:51:46 +0000250 log->Printf ("SBThread(%p)::GetQueueName () => %s", m_opaque_sp.get(), name ? name : "NULL");
Caroline Tice7826c882010-10-26 03:11:13 +0000251
Greg Claytona66ba462010-10-30 04:51:46 +0000252 return name;
Chris Lattner24943d22010-06-08 16:52:24 +0000253}
254
255
256void
Chris Lattner24943d22010-06-08 16:52:24 +0000257SBThread::StepOver (lldb::RunMode stop_other_threads)
258{
Caroline Tice7826c882010-10-26 03:11:13 +0000259 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
260
261 if (log)
Greg Clayton3f5ee7f2010-10-29 04:59:35 +0000262 log->Printf ("SBThread(%p)::StepOver (stop_other_threads='%s')", m_opaque_sp.get(),
Caroline Tice7826c882010-10-26 03:11:13 +0000263 Thread::RunModeAsCString (stop_other_threads));
264
Greg Clayton63094e02010-06-23 01:19:29 +0000265 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000266 {
267 bool abort_other_plans = true;
Greg Clayton63094e02010-06-23 01:19:29 +0000268 StackFrameSP frame_sp(m_opaque_sp->GetStackFrameAtIndex (0));
Chris Lattner24943d22010-06-08 16:52:24 +0000269
270 if (frame_sp)
271 {
272 if (frame_sp->HasDebugInformation ())
273 {
274 SymbolContext sc(frame_sp->GetSymbolContext(eSymbolContextEverything));
Greg Clayton63094e02010-06-23 01:19:29 +0000275 m_opaque_sp->QueueThreadPlanForStepRange (abort_other_plans,
Greg Clayton1a3083a2010-10-06 03:53:16 +0000276 eStepTypeOver,
277 sc.line_entry.range,
278 sc,
279 stop_other_threads,
280 false);
Chris Lattner24943d22010-06-08 16:52:24 +0000281
282 }
283 else
284 {
Greg Clayton63094e02010-06-23 01:19:29 +0000285 m_opaque_sp->QueueThreadPlanForStepSingleInstruction (true,
Greg Clayton1a3083a2010-10-06 03:53:16 +0000286 abort_other_plans,
287 stop_other_threads);
Chris Lattner24943d22010-06-08 16:52:24 +0000288 }
289 }
290
Greg Clayton63094e02010-06-23 01:19:29 +0000291 Process &process = m_opaque_sp->GetProcess();
Chris Lattner24943d22010-06-08 16:52:24 +0000292 // Why do we need to set the current thread by ID here???
Jim Inghamc8332952010-08-26 21:32:51 +0000293 process.GetThreadList().SetSelectedThreadByID (m_opaque_sp->GetID());
Greg Clayton1a3083a2010-10-06 03:53:16 +0000294 Error error (process.Resume());
295 if (error.Success())
296 {
297 // If we are doing synchronous mode, then wait for the
298 // process to stop yet again!
299 if (process.GetTarget().GetDebugger().GetAsyncExecution () == false)
300 process.WaitForProcessToStop (NULL);
301 }
Chris Lattner24943d22010-06-08 16:52:24 +0000302 }
303}
304
305void
306SBThread::StepInto (lldb::RunMode stop_other_threads)
307{
Caroline Tice7826c882010-10-26 03:11:13 +0000308 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
309
310 if (log)
Greg Clayton3f5ee7f2010-10-29 04:59:35 +0000311 log->Printf ("SBThread(%p)::StepInto (stop_other_threads='%s')", m_opaque_sp.get(),
Caroline Tice7826c882010-10-26 03:11:13 +0000312 Thread::RunModeAsCString (stop_other_threads));
313
Greg Clayton63094e02010-06-23 01:19:29 +0000314 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000315 {
316 bool abort_other_plans = true;
317
Greg Clayton63094e02010-06-23 01:19:29 +0000318 StackFrameSP frame_sp(m_opaque_sp->GetStackFrameAtIndex (0));
Chris Lattner24943d22010-06-08 16:52:24 +0000319
320 if (frame_sp && frame_sp->HasDebugInformation ())
321 {
Greg Clayton8f5fd6b2010-06-12 18:59:55 +0000322 bool avoid_code_without_debug_info = true;
Chris Lattner24943d22010-06-08 16:52:24 +0000323 SymbolContext sc(frame_sp->GetSymbolContext(eSymbolContextEverything));
Greg Clayton63094e02010-06-23 01:19:29 +0000324 m_opaque_sp->QueueThreadPlanForStepRange (abort_other_plans,
Greg Clayton1a3083a2010-10-06 03:53:16 +0000325 eStepTypeInto,
326 sc.line_entry.range,
327 sc,
328 stop_other_threads,
329 avoid_code_without_debug_info);
Chris Lattner24943d22010-06-08 16:52:24 +0000330 }
331 else
332 {
Greg Clayton63094e02010-06-23 01:19:29 +0000333 m_opaque_sp->QueueThreadPlanForStepSingleInstruction (false,
Greg Clayton1a3083a2010-10-06 03:53:16 +0000334 abort_other_plans,
335 stop_other_threads);
Chris Lattner24943d22010-06-08 16:52:24 +0000336 }
337
Greg Clayton63094e02010-06-23 01:19:29 +0000338 Process &process = m_opaque_sp->GetProcess();
Chris Lattner24943d22010-06-08 16:52:24 +0000339 // Why do we need to set the current thread by ID here???
Jim Inghamc8332952010-08-26 21:32:51 +0000340 process.GetThreadList().SetSelectedThreadByID (m_opaque_sp->GetID());
Greg Clayton1a3083a2010-10-06 03:53:16 +0000341 Error error (process.Resume());
342 if (error.Success())
343 {
344 // If we are doing synchronous mode, then wait for the
345 // process to stop yet again!
346 if (process.GetTarget().GetDebugger().GetAsyncExecution () == false)
347 process.WaitForProcessToStop (NULL);
348 }
Chris Lattner24943d22010-06-08 16:52:24 +0000349 }
350}
351
352void
353SBThread::StepOut ()
354{
Caroline Tice7826c882010-10-26 03:11:13 +0000355 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
356
357 if (log)
Greg Claytona66ba462010-10-30 04:51:46 +0000358 log->Printf ("SBThread(%p)::StepOut ()", m_opaque_sp.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000359
Greg Clayton63094e02010-06-23 01:19:29 +0000360 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000361 {
362 bool abort_other_plans = true;
363 bool stop_other_threads = true;
364
Greg Clayton63094e02010-06-23 01:19:29 +0000365 m_opaque_sp->QueueThreadPlanForStepOut (abort_other_plans, NULL, false, stop_other_threads, eVoteYes, eVoteNoOpinion);
Chris Lattner24943d22010-06-08 16:52:24 +0000366
Greg Clayton63094e02010-06-23 01:19:29 +0000367 Process &process = m_opaque_sp->GetProcess();
Jim Inghamc8332952010-08-26 21:32:51 +0000368 process.GetThreadList().SetSelectedThreadByID (m_opaque_sp->GetID());
Greg Clayton1a3083a2010-10-06 03:53:16 +0000369 Error error (process.Resume());
370 if (error.Success())
371 {
372 // If we are doing synchronous mode, then wait for the
373 // process to stop yet again!
374 if (process.GetTarget().GetDebugger().GetAsyncExecution () == false)
375 process.WaitForProcessToStop (NULL);
376 }
Chris Lattner24943d22010-06-08 16:52:24 +0000377 }
378}
379
380void
381SBThread::StepInstruction (bool step_over)
382{
Caroline Tice7826c882010-10-26 03:11:13 +0000383 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
384
385 if (log)
Greg Clayton3f5ee7f2010-10-29 04:59:35 +0000386 log->Printf ("SBThread(%p)::StepInstruction (step_over=%i)", m_opaque_sp.get(), step_over);
Caroline Tice7826c882010-10-26 03:11:13 +0000387
Greg Clayton63094e02010-06-23 01:19:29 +0000388 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000389 {
Greg Clayton63094e02010-06-23 01:19:29 +0000390 m_opaque_sp->QueueThreadPlanForStepSingleInstruction (step_over, true, true);
391 Process &process = m_opaque_sp->GetProcess();
Jim Inghamc8332952010-08-26 21:32:51 +0000392 process.GetThreadList().SetSelectedThreadByID (m_opaque_sp->GetID());
Greg Clayton1a3083a2010-10-06 03:53:16 +0000393 Error error (process.Resume());
394 if (error.Success())
395 {
396 // If we are doing synchronous mode, then wait for the
397 // process to stop yet again!
398 if (process.GetTarget().GetDebugger().GetAsyncExecution () == false)
399 process.WaitForProcessToStop (NULL);
400 }
Chris Lattner24943d22010-06-08 16:52:24 +0000401 }
402}
403
404void
405SBThread::RunToAddress (lldb::addr_t addr)
406{
Caroline Tice7826c882010-10-26 03:11:13 +0000407 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
408
409 if (log)
Greg Clayton3f5ee7f2010-10-29 04:59:35 +0000410 log->Printf ("SBThread(%p)::RunToAddress (addr=0x%llx)", m_opaque_sp.get(), addr);
Caroline Tice7826c882010-10-26 03:11:13 +0000411
Greg Clayton63094e02010-06-23 01:19:29 +0000412 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000413 {
414 bool abort_other_plans = true;
415 bool stop_other_threads = true;
416
417 Address target_addr (NULL, addr);
418
Greg Clayton63094e02010-06-23 01:19:29 +0000419 m_opaque_sp->QueueThreadPlanForRunToAddress (abort_other_plans, target_addr, stop_other_threads);
420 Process &process = m_opaque_sp->GetProcess();
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}
433
Chris Lattner24943d22010-06-08 16:52:24 +0000434SBProcess
435SBThread::GetProcess ()
436{
Caroline Tice7826c882010-10-26 03:11:13 +0000437
Chris Lattner24943d22010-06-08 16:52:24 +0000438 SBProcess process;
Greg Clayton63094e02010-06-23 01:19:29 +0000439 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000440 {
441 // Have to go up to the target so we can get a shared pointer to our process...
Greg Clayton63094e02010-06-23 01:19:29 +0000442 process.SetProcess(m_opaque_sp->GetProcess().GetTarget().GetProcessSP());
Chris Lattner24943d22010-06-08 16:52:24 +0000443 }
Caroline Tice7826c882010-10-26 03:11:13 +0000444
Caroline Tice926060e2010-10-29 21:48:37 +0000445 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
Caroline Tice7826c882010-10-26 03:11:13 +0000446 if (log)
447 {
448 SBStream sstr;
449 process.GetDescription (sstr);
Greg Claytona66ba462010-10-30 04:51:46 +0000450 log->Printf ("SBThread(%p)::GetProcess () => SBProcess(%p): %s", m_opaque_sp.get(),
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000451 process.get(), sstr.GetData());
Caroline Tice7826c882010-10-26 03:11:13 +0000452 }
453
Chris Lattner24943d22010-06-08 16:52:24 +0000454 return process;
455}
456
457uint32_t
458SBThread::GetNumFrames ()
459{
Caroline Tice7826c882010-10-26 03:11:13 +0000460 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
461
Caroline Tice7826c882010-10-26 03:11:13 +0000462 uint32_t num_frames = 0;
Greg Clayton63094e02010-06-23 01:19:29 +0000463 if (m_opaque_sp)
Caroline Tice7826c882010-10-26 03:11:13 +0000464 num_frames = m_opaque_sp->GetStackFrameCount();
465
466 if (log)
Greg Claytona66ba462010-10-30 04:51:46 +0000467 log->Printf ("SBThread(%p)::GetNumFrames () => %u", m_opaque_sp.get(), num_frames);
Caroline Tice7826c882010-10-26 03:11:13 +0000468
469 return num_frames;
Chris Lattner24943d22010-06-08 16:52:24 +0000470}
471
472SBFrame
473SBThread::GetFrameAtIndex (uint32_t idx)
474{
Caroline Tice7826c882010-10-26 03:11:13 +0000475 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
476
Chris Lattner24943d22010-06-08 16:52:24 +0000477 SBFrame sb_frame;
Greg Clayton63094e02010-06-23 01:19:29 +0000478 if (m_opaque_sp)
479 sb_frame.SetFrame (m_opaque_sp->GetStackFrameAtIndex (idx));
Caroline Tice7826c882010-10-26 03:11:13 +0000480
481 if (log)
482 {
483 SBStream sstr;
484 sb_frame.GetDescription (sstr);
Greg Claytona66ba462010-10-30 04:51:46 +0000485 log->Printf ("SBThread(%p)::GetFrameAtIndex (idx=%d) => SBFrame(%p): %s",
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000486 m_opaque_sp.get(), idx, sb_frame.get(), sstr.GetData());
Caroline Tice7826c882010-10-26 03:11:13 +0000487 }
488
Chris Lattner24943d22010-06-08 16:52:24 +0000489 return sb_frame;
490}
491
492const lldb::SBThread &
493SBThread::operator = (const lldb::SBThread &rhs)
494{
Greg Claytona66ba462010-10-30 04:51:46 +0000495 if (this != &rhs)
496 m_opaque_sp = rhs.m_opaque_sp;
Chris Lattner24943d22010-06-08 16:52:24 +0000497 return *this;
498}
499
500bool
501SBThread::operator == (const SBThread &rhs) const
502{
Greg Clayton63094e02010-06-23 01:19:29 +0000503 return m_opaque_sp.get() == rhs.m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000504}
505
506bool
507SBThread::operator != (const SBThread &rhs) const
508{
Greg Clayton63094e02010-06-23 01:19:29 +0000509 return m_opaque_sp.get() != rhs.m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000510}
511
512lldb_private::Thread *
Greg Claytona66ba462010-10-30 04:51:46 +0000513SBThread::get ()
Chris Lattner24943d22010-06-08 16:52:24 +0000514{
Greg Clayton63094e02010-06-23 01:19:29 +0000515 return m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000516}
517
518const lldb_private::Thread *
519SBThread::operator->() const
520{
Greg Clayton63094e02010-06-23 01:19:29 +0000521 return m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000522}
523
524const lldb_private::Thread &
525SBThread::operator*() const
526{
Greg Clayton63094e02010-06-23 01:19:29 +0000527 return *m_opaque_sp;
Chris Lattner24943d22010-06-08 16:52:24 +0000528}
529
530lldb_private::Thread *
531SBThread::operator->()
532{
Greg Clayton63094e02010-06-23 01:19:29 +0000533 return m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000534}
535
536lldb_private::Thread &
537SBThread::operator*()
538{
Greg Clayton63094e02010-06-23 01:19:29 +0000539 return *m_opaque_sp;
Chris Lattner24943d22010-06-08 16:52:24 +0000540}
Caroline Tice98f930f2010-09-20 05:20:02 +0000541
542bool
Caroline Tice7826c882010-10-26 03:11:13 +0000543SBThread::GetDescription (SBStream &description) const
544{
545 if (m_opaque_sp)
546 {
547 StreamString strm;
548 description.Printf("SBThread: tid = 0x%4.4x", m_opaque_sp->GetID());
549 }
550 else
551 description.Printf ("No value");
552
553 return true;
554}