blob: fc13631b1376c0a80b48d042efe9509af956147d [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
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//----------------------------------------------------------------------
60// Destructor
61//----------------------------------------------------------------------
62SBThread::~SBThread()
63{
64}
65
66bool
67SBThread::IsValid() const
68{
Greg Clayton63094e02010-06-23 01:19:29 +000069 return m_opaque_sp != NULL;
Chris Lattner24943d22010-06-08 16:52:24 +000070}
71
Greg Clayton43490d12010-07-30 20:12:55 +000072void
73SBThread::Clear ()
74{
75 m_opaque_sp.reset();
76}
77
78
Chris Lattner24943d22010-06-08 16:52:24 +000079StopReason
80SBThread::GetStopReason()
81{
Caroline Tice7826c882010-10-26 03:11:13 +000082 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
83
Caroline Tice7826c882010-10-26 03:11:13 +000084 StopReason reason = eStopReasonInvalid;
Greg Clayton63094e02010-06-23 01:19:29 +000085 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +000086 {
Jim Ingham6297a3a2010-10-20 00:39:53 +000087 StopInfoSP stop_info_sp = m_opaque_sp->GetStopInfo ();
88 if (stop_info_sp)
Caroline Tice7826c882010-10-26 03:11:13 +000089 reason = stop_info_sp->GetStopReason();
Chris Lattner24943d22010-06-08 16:52:24 +000090 }
Caroline Tice7826c882010-10-26 03:11:13 +000091
92 if (log)
Greg Claytona66ba462010-10-30 04:51:46 +000093 log->Printf ("SBThread(%p)::GetStopReason () => %s", m_opaque_sp.get(),
Caroline Tice61ba7ec2010-10-26 23:49:36 +000094 Thread::StopReasonAsCString (reason));
Caroline Tice7826c882010-10-26 03:11:13 +000095
96 return reason;
Chris Lattner24943d22010-06-08 16:52:24 +000097}
98
99size_t
100SBThread::GetStopDescription (char *dst, size_t dst_len)
101{
Caroline Tice7826c882010-10-26 03:11:13 +0000102 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
103
Greg Clayton63094e02010-06-23 01:19:29 +0000104 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000105 {
Jim Ingham6297a3a2010-10-20 00:39:53 +0000106 StopInfoSP stop_info_sp = m_opaque_sp->GetStopInfo ();
107 if (stop_info_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000108 {
Jim Ingham6297a3a2010-10-20 00:39:53 +0000109 const char *stop_desc = stop_info_sp->GetDescription();
Chris Lattner24943d22010-06-08 16:52:24 +0000110 if (stop_desc)
111 {
Caroline Tice7826c882010-10-26 03:11:13 +0000112 if (log)
Greg Claytona66ba462010-10-30 04:51:46 +0000113 log->Printf ("SBThread(%p)::GetStopDescription (dst, dst_len) => \"%s\"",
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000114 m_opaque_sp.get(), stop_desc);
Chris Lattner24943d22010-06-08 16:52:24 +0000115 if (dst)
116 return ::snprintf (dst, dst_len, "%s", stop_desc);
117 else
118 {
119 // NULL dst passed in, return the length needed to contain the description
120 return ::strlen (stop_desc) + 1; // Include the NULL byte for size
121 }
122 }
123 else
124 {
Chris Lattner24943d22010-06-08 16:52:24 +0000125 size_t stop_desc_len = 0;
Jim Ingham6297a3a2010-10-20 00:39:53 +0000126 switch (stop_info_sp->GetStopReason())
Chris Lattner24943d22010-06-08 16:52:24 +0000127 {
128 case eStopReasonTrace:
129 case eStopReasonPlanComplete:
130 {
131 static char trace_desc[] = "step";
132 stop_desc = trace_desc;
133 stop_desc_len = sizeof(trace_desc); // Include the NULL byte for size
134 }
135 break;
136
137 case eStopReasonBreakpoint:
138 {
139 static char bp_desc[] = "breakpoint hit";
140 stop_desc = bp_desc;
141 stop_desc_len = sizeof(bp_desc); // Include the NULL byte for size
142 }
143 break;
144
145 case eStopReasonWatchpoint:
146 {
147 static char wp_desc[] = "watchpoint hit";
148 stop_desc = wp_desc;
149 stop_desc_len = sizeof(wp_desc); // Include the NULL byte for size
150 }
151 break;
152
153 case eStopReasonSignal:
154 {
Jim Ingham6297a3a2010-10-20 00:39:53 +0000155 stop_desc = m_opaque_sp->GetProcess().GetUnixSignals ().GetSignalAsCString (stop_info_sp->GetValue());
Chris Lattner24943d22010-06-08 16:52:24 +0000156 if (stop_desc == NULL || stop_desc[0] == '\0')
157 {
158 static char signal_desc[] = "signal";
159 stop_desc = signal_desc;
160 stop_desc_len = sizeof(signal_desc); // Include the NULL byte for size
161 }
162 }
163 break;
164
165 case eStopReasonException:
166 {
167 char exc_desc[] = "exception";
168 stop_desc = exc_desc;
169 stop_desc_len = sizeof(exc_desc); // Include the NULL byte for size
170 }
Greg Clayton54e7afa2010-07-09 20:39:50 +0000171 break;
172
173 default:
174 break;
Chris Lattner24943d22010-06-08 16:52:24 +0000175 }
176
177 if (stop_desc && stop_desc[0])
178 {
Caroline Tice7826c882010-10-26 03:11:13 +0000179 if (log)
Greg Clayton3f5ee7f2010-10-29 04:59:35 +0000180 log->Printf ("SBThread(%p)::GetStopDescription (dst, dst_len) => '%s'",
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000181 m_opaque_sp.get(), stop_desc);
Caroline Tice7826c882010-10-26 03:11:13 +0000182
Chris Lattner24943d22010-06-08 16:52:24 +0000183 if (dst)
184 return ::snprintf (dst, dst_len, "%s", stop_desc) + 1; // Include the NULL byte
185
186 if (stop_desc_len == 0)
187 stop_desc_len = ::strlen (stop_desc) + 1; // Include the NULL byte
188
189 return stop_desc_len;
190 }
191 }
192 }
193 }
194 if (dst)
195 *dst = 0;
196 return 0;
197}
198
199void
200SBThread::SetThread (const ThreadSP& lldb_object_sp)
201{
Greg Clayton63094e02010-06-23 01:19:29 +0000202 m_opaque_sp = lldb_object_sp;
Chris Lattner24943d22010-06-08 16:52:24 +0000203}
204
205
206lldb::tid_t
207SBThread::GetThreadID () const
208{
Caroline Tice7826c882010-10-26 03:11:13 +0000209 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
210
Caroline Tice7826c882010-10-26 03:11:13 +0000211 lldb::tid_t id = LLDB_INVALID_THREAD_ID;
Greg Clayton63094e02010-06-23 01:19:29 +0000212 if (m_opaque_sp)
Caroline Tice7826c882010-10-26 03:11:13 +0000213 id = m_opaque_sp->GetID();
214
215 if (log)
Greg Claytona66ba462010-10-30 04:51:46 +0000216 log->Printf ("SBThread(%p)::GetThreadID () => 0x%4.4x", m_opaque_sp.get(), id);
Caroline Tice7826c882010-10-26 03:11:13 +0000217
218 return id;
Chris Lattner24943d22010-06-08 16:52:24 +0000219}
220
221uint32_t
222SBThread::GetIndexID () const
223{
Greg Clayton63094e02010-06-23 01:19:29 +0000224 if (m_opaque_sp)
225 return m_opaque_sp->GetIndexID();
Chris Lattner24943d22010-06-08 16:52:24 +0000226 return LLDB_INVALID_INDEX32;
227}
228const char *
229SBThread::GetName () const
230{
Greg Claytona66ba462010-10-30 04:51:46 +0000231 const char *name = NULL;
Greg Clayton63094e02010-06-23 01:19:29 +0000232 if (m_opaque_sp)
Greg Claytona66ba462010-10-30 04:51:46 +0000233 name = m_opaque_sp->GetName();
234
235 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
Caroline Tice7826c882010-10-26 03:11:13 +0000236 if (log)
Greg Claytona66ba462010-10-30 04:51:46 +0000237 log->Printf ("SBThread(%p)::GetName () => %s", m_opaque_sp.get(), name ? name : "NULL");
Caroline Tice7826c882010-10-26 03:11:13 +0000238
Greg Claytona66ba462010-10-30 04:51:46 +0000239 return name;
Chris Lattner24943d22010-06-08 16:52:24 +0000240}
241
242const char *
243SBThread::GetQueueName () const
244{
Greg Claytona66ba462010-10-30 04:51:46 +0000245 const char *name = NULL;
Greg Clayton63094e02010-06-23 01:19:29 +0000246 if (m_opaque_sp)
Greg Claytona66ba462010-10-30 04:51:46 +0000247 name = m_opaque_sp->GetQueueName();
248
249 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
Caroline Tice7826c882010-10-26 03:11:13 +0000250 if (log)
Greg Claytona66ba462010-10-30 04:51:46 +0000251 log->Printf ("SBThread(%p)::GetQueueName () => %s", m_opaque_sp.get(), name ? name : "NULL");
Caroline Tice7826c882010-10-26 03:11:13 +0000252
Greg Claytona66ba462010-10-30 04:51:46 +0000253 return name;
Chris Lattner24943d22010-06-08 16:52:24 +0000254}
255
256
257void
Chris Lattner24943d22010-06-08 16:52:24 +0000258SBThread::StepOver (lldb::RunMode stop_other_threads)
259{
Caroline Tice7826c882010-10-26 03:11:13 +0000260 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
261
262 if (log)
Greg Clayton3f5ee7f2010-10-29 04:59:35 +0000263 log->Printf ("SBThread(%p)::StepOver (stop_other_threads='%s')", m_opaque_sp.get(),
Caroline Tice7826c882010-10-26 03:11:13 +0000264 Thread::RunModeAsCString (stop_other_threads));
265
Greg Clayton63094e02010-06-23 01:19:29 +0000266 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000267 {
268 bool abort_other_plans = true;
Greg Clayton63094e02010-06-23 01:19:29 +0000269 StackFrameSP frame_sp(m_opaque_sp->GetStackFrameAtIndex (0));
Chris Lattner24943d22010-06-08 16:52:24 +0000270
271 if (frame_sp)
272 {
273 if (frame_sp->HasDebugInformation ())
274 {
275 SymbolContext sc(frame_sp->GetSymbolContext(eSymbolContextEverything));
Greg Clayton63094e02010-06-23 01:19:29 +0000276 m_opaque_sp->QueueThreadPlanForStepRange (abort_other_plans,
Greg Clayton1a3083a2010-10-06 03:53:16 +0000277 eStepTypeOver,
278 sc.line_entry.range,
279 sc,
280 stop_other_threads,
281 false);
Chris Lattner24943d22010-06-08 16:52:24 +0000282
283 }
284 else
285 {
Greg Clayton63094e02010-06-23 01:19:29 +0000286 m_opaque_sp->QueueThreadPlanForStepSingleInstruction (true,
Greg Clayton1a3083a2010-10-06 03:53:16 +0000287 abort_other_plans,
288 stop_other_threads);
Chris Lattner24943d22010-06-08 16:52:24 +0000289 }
290 }
291
Greg Clayton63094e02010-06-23 01:19:29 +0000292 Process &process = m_opaque_sp->GetProcess();
Chris Lattner24943d22010-06-08 16:52:24 +0000293 // Why do we need to set the current thread by ID here???
Jim Inghamc8332952010-08-26 21:32:51 +0000294 process.GetThreadList().SetSelectedThreadByID (m_opaque_sp->GetID());
Greg Clayton1a3083a2010-10-06 03:53:16 +0000295 Error error (process.Resume());
296 if (error.Success())
297 {
298 // If we are doing synchronous mode, then wait for the
299 // process to stop yet again!
300 if (process.GetTarget().GetDebugger().GetAsyncExecution () == false)
301 process.WaitForProcessToStop (NULL);
302 }
Chris Lattner24943d22010-06-08 16:52:24 +0000303 }
304}
305
306void
307SBThread::StepInto (lldb::RunMode stop_other_threads)
308{
Caroline Tice7826c882010-10-26 03:11:13 +0000309 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
310
311 if (log)
Greg Clayton3f5ee7f2010-10-29 04:59:35 +0000312 log->Printf ("SBThread(%p)::StepInto (stop_other_threads='%s')", m_opaque_sp.get(),
Caroline Tice7826c882010-10-26 03:11:13 +0000313 Thread::RunModeAsCString (stop_other_threads));
314
Greg Clayton63094e02010-06-23 01:19:29 +0000315 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000316 {
317 bool abort_other_plans = true;
318
Greg Clayton63094e02010-06-23 01:19:29 +0000319 StackFrameSP frame_sp(m_opaque_sp->GetStackFrameAtIndex (0));
Chris Lattner24943d22010-06-08 16:52:24 +0000320
321 if (frame_sp && frame_sp->HasDebugInformation ())
322 {
Greg Clayton8f5fd6b2010-06-12 18:59:55 +0000323 bool avoid_code_without_debug_info = true;
Chris Lattner24943d22010-06-08 16:52:24 +0000324 SymbolContext sc(frame_sp->GetSymbolContext(eSymbolContextEverything));
Greg Clayton63094e02010-06-23 01:19:29 +0000325 m_opaque_sp->QueueThreadPlanForStepRange (abort_other_plans,
Greg Clayton1a3083a2010-10-06 03:53:16 +0000326 eStepTypeInto,
327 sc.line_entry.range,
328 sc,
329 stop_other_threads,
330 avoid_code_without_debug_info);
Chris Lattner24943d22010-06-08 16:52:24 +0000331 }
332 else
333 {
Greg Clayton63094e02010-06-23 01:19:29 +0000334 m_opaque_sp->QueueThreadPlanForStepSingleInstruction (false,
Greg Clayton1a3083a2010-10-06 03:53:16 +0000335 abort_other_plans,
336 stop_other_threads);
Chris Lattner24943d22010-06-08 16:52:24 +0000337 }
338
Greg Clayton63094e02010-06-23 01:19:29 +0000339 Process &process = m_opaque_sp->GetProcess();
Chris Lattner24943d22010-06-08 16:52:24 +0000340 // Why do we need to set the current thread by ID here???
Jim Inghamc8332952010-08-26 21:32:51 +0000341 process.GetThreadList().SetSelectedThreadByID (m_opaque_sp->GetID());
Greg Clayton1a3083a2010-10-06 03:53:16 +0000342 Error error (process.Resume());
343 if (error.Success())
344 {
345 // If we are doing synchronous mode, then wait for the
346 // process to stop yet again!
347 if (process.GetTarget().GetDebugger().GetAsyncExecution () == false)
348 process.WaitForProcessToStop (NULL);
349 }
Chris Lattner24943d22010-06-08 16:52:24 +0000350 }
351}
352
353void
354SBThread::StepOut ()
355{
Caroline Tice7826c882010-10-26 03:11:13 +0000356 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
357
358 if (log)
Greg Claytona66ba462010-10-30 04:51:46 +0000359 log->Printf ("SBThread(%p)::StepOut ()", m_opaque_sp.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000360
Greg Clayton63094e02010-06-23 01:19:29 +0000361 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000362 {
363 bool abort_other_plans = true;
364 bool stop_other_threads = true;
365
Greg Clayton63094e02010-06-23 01:19:29 +0000366 m_opaque_sp->QueueThreadPlanForStepOut (abort_other_plans, NULL, false, stop_other_threads, eVoteYes, eVoteNoOpinion);
Chris Lattner24943d22010-06-08 16:52:24 +0000367
Greg Clayton63094e02010-06-23 01:19:29 +0000368 Process &process = m_opaque_sp->GetProcess();
Jim Inghamc8332952010-08-26 21:32:51 +0000369 process.GetThreadList().SetSelectedThreadByID (m_opaque_sp->GetID());
Greg Clayton1a3083a2010-10-06 03:53:16 +0000370 Error error (process.Resume());
371 if (error.Success())
372 {
373 // If we are doing synchronous mode, then wait for the
374 // process to stop yet again!
375 if (process.GetTarget().GetDebugger().GetAsyncExecution () == false)
376 process.WaitForProcessToStop (NULL);
377 }
Chris Lattner24943d22010-06-08 16:52:24 +0000378 }
379}
380
381void
382SBThread::StepInstruction (bool step_over)
383{
Caroline Tice7826c882010-10-26 03:11:13 +0000384 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
385
386 if (log)
Greg Clayton3f5ee7f2010-10-29 04:59:35 +0000387 log->Printf ("SBThread(%p)::StepInstruction (step_over=%i)", m_opaque_sp.get(), step_over);
Caroline Tice7826c882010-10-26 03:11:13 +0000388
Greg Clayton63094e02010-06-23 01:19:29 +0000389 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000390 {
Greg Clayton63094e02010-06-23 01:19:29 +0000391 m_opaque_sp->QueueThreadPlanForStepSingleInstruction (step_over, true, true);
392 Process &process = m_opaque_sp->GetProcess();
Jim Inghamc8332952010-08-26 21:32:51 +0000393 process.GetThreadList().SetSelectedThreadByID (m_opaque_sp->GetID());
Greg Clayton1a3083a2010-10-06 03:53:16 +0000394 Error error (process.Resume());
395 if (error.Success())
396 {
397 // If we are doing synchronous mode, then wait for the
398 // process to stop yet again!
399 if (process.GetTarget().GetDebugger().GetAsyncExecution () == false)
400 process.WaitForProcessToStop (NULL);
401 }
Chris Lattner24943d22010-06-08 16:52:24 +0000402 }
403}
404
405void
406SBThread::RunToAddress (lldb::addr_t addr)
407{
Caroline Tice7826c882010-10-26 03:11:13 +0000408 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
409
410 if (log)
Greg Clayton3f5ee7f2010-10-29 04:59:35 +0000411 log->Printf ("SBThread(%p)::RunToAddress (addr=0x%llx)", m_opaque_sp.get(), addr);
Caroline Tice7826c882010-10-26 03:11:13 +0000412
Greg Clayton63094e02010-06-23 01:19:29 +0000413 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000414 {
415 bool abort_other_plans = true;
416 bool stop_other_threads = true;
417
418 Address target_addr (NULL, addr);
419
Greg Clayton63094e02010-06-23 01:19:29 +0000420 m_opaque_sp->QueueThreadPlanForRunToAddress (abort_other_plans, target_addr, stop_other_threads);
421 Process &process = m_opaque_sp->GetProcess();
Jim Inghamc8332952010-08-26 21:32:51 +0000422 process.GetThreadList().SetSelectedThreadByID (m_opaque_sp->GetID());
Greg Clayton1a3083a2010-10-06 03:53:16 +0000423 Error error (process.Resume());
424 if (error.Success())
425 {
426 // If we are doing synchronous mode, then wait for the
427 // process to stop yet again!
428 if (process.GetTarget().GetDebugger().GetAsyncExecution () == false)
429 process.WaitForProcessToStop (NULL);
430 }
Chris Lattner24943d22010-06-08 16:52:24 +0000431 }
432
433}
434
Chris Lattner24943d22010-06-08 16:52:24 +0000435SBProcess
436SBThread::GetProcess ()
437{
Caroline Tice7826c882010-10-26 03:11:13 +0000438
Chris Lattner24943d22010-06-08 16:52:24 +0000439 SBProcess process;
Greg Clayton63094e02010-06-23 01:19:29 +0000440 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000441 {
442 // Have to go up to the target so we can get a shared pointer to our process...
Greg Clayton63094e02010-06-23 01:19:29 +0000443 process.SetProcess(m_opaque_sp->GetProcess().GetTarget().GetProcessSP());
Chris Lattner24943d22010-06-08 16:52:24 +0000444 }
Caroline Tice7826c882010-10-26 03:11:13 +0000445
Caroline Tice926060e2010-10-29 21:48:37 +0000446 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
Caroline Tice7826c882010-10-26 03:11:13 +0000447 if (log)
448 {
449 SBStream sstr;
450 process.GetDescription (sstr);
Greg Claytona66ba462010-10-30 04:51:46 +0000451 log->Printf ("SBThread(%p)::GetProcess () => SBProcess(%p): %s", m_opaque_sp.get(),
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000452 process.get(), sstr.GetData());
Caroline Tice7826c882010-10-26 03:11:13 +0000453 }
454
Chris Lattner24943d22010-06-08 16:52:24 +0000455 return process;
456}
457
458uint32_t
459SBThread::GetNumFrames ()
460{
Caroline Tice7826c882010-10-26 03:11:13 +0000461 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
462
Caroline Tice7826c882010-10-26 03:11:13 +0000463 uint32_t num_frames = 0;
Greg Clayton63094e02010-06-23 01:19:29 +0000464 if (m_opaque_sp)
Caroline Tice7826c882010-10-26 03:11:13 +0000465 num_frames = m_opaque_sp->GetStackFrameCount();
466
467 if (log)
Greg Claytona66ba462010-10-30 04:51:46 +0000468 log->Printf ("SBThread(%p)::GetNumFrames () => %u", m_opaque_sp.get(), num_frames);
Caroline Tice7826c882010-10-26 03:11:13 +0000469
470 return num_frames;
Chris Lattner24943d22010-06-08 16:52:24 +0000471}
472
473SBFrame
474SBThread::GetFrameAtIndex (uint32_t idx)
475{
Caroline Tice7826c882010-10-26 03:11:13 +0000476 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
477
Chris Lattner24943d22010-06-08 16:52:24 +0000478 SBFrame sb_frame;
Greg Clayton63094e02010-06-23 01:19:29 +0000479 if (m_opaque_sp)
480 sb_frame.SetFrame (m_opaque_sp->GetStackFrameAtIndex (idx));
Caroline Tice7826c882010-10-26 03:11:13 +0000481
482 if (log)
483 {
484 SBStream sstr;
485 sb_frame.GetDescription (sstr);
Greg Claytona66ba462010-10-30 04:51:46 +0000486 log->Printf ("SBThread(%p)::GetFrameAtIndex (idx=%d) => SBFrame(%p): %s",
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000487 m_opaque_sp.get(), idx, sb_frame.get(), sstr.GetData());
Caroline Tice7826c882010-10-26 03:11:13 +0000488 }
489
Chris Lattner24943d22010-06-08 16:52:24 +0000490 return sb_frame;
491}
492
493const lldb::SBThread &
Greg Clayton1b284412010-10-30 18:26:59 +0000494SBThread::operator = (const SBThread &rhs)
Chris Lattner24943d22010-06-08 16:52:24 +0000495{
Greg Claytona66ba462010-10-30 04:51:46 +0000496 if (this != &rhs)
497 m_opaque_sp = rhs.m_opaque_sp;
Chris Lattner24943d22010-06-08 16:52:24 +0000498 return *this;
499}
500
501bool
502SBThread::operator == (const SBThread &rhs) const
503{
Greg Clayton63094e02010-06-23 01:19:29 +0000504 return m_opaque_sp.get() == rhs.m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000505}
506
507bool
508SBThread::operator != (const SBThread &rhs) const
509{
Greg Clayton63094e02010-06-23 01:19:29 +0000510 return m_opaque_sp.get() != rhs.m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000511}
512
513lldb_private::Thread *
Greg Claytona66ba462010-10-30 04:51:46 +0000514SBThread::get ()
Chris Lattner24943d22010-06-08 16:52:24 +0000515{
Greg Clayton63094e02010-06-23 01:19:29 +0000516 return m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000517}
518
519const lldb_private::Thread *
520SBThread::operator->() const
521{
Greg Clayton63094e02010-06-23 01:19:29 +0000522 return m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000523}
524
525const lldb_private::Thread &
526SBThread::operator*() const
527{
Greg Clayton63094e02010-06-23 01:19:29 +0000528 return *m_opaque_sp;
Chris Lattner24943d22010-06-08 16:52:24 +0000529}
530
531lldb_private::Thread *
532SBThread::operator->()
533{
Greg Clayton63094e02010-06-23 01:19:29 +0000534 return m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000535}
536
537lldb_private::Thread &
538SBThread::operator*()
539{
Greg Clayton63094e02010-06-23 01:19:29 +0000540 return *m_opaque_sp;
Chris Lattner24943d22010-06-08 16:52:24 +0000541}
Caroline Tice98f930f2010-09-20 05:20:02 +0000542
543bool
Caroline Tice7826c882010-10-26 03:11:13 +0000544SBThread::GetDescription (SBStream &description) const
545{
546 if (m_opaque_sp)
547 {
548 StreamString strm;
549 description.Printf("SBThread: tid = 0x%4.4x", m_opaque_sp->GetID());
550 }
551 else
552 description.Printf ("No value");
553
554 return true;
555}