blob: a0a00c1ec618c38317df67611fff0f57064d3d3f [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{
Caroline Tice7826c882010-10-26 03:11:13 +000044 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API | LIBLLDB_LOG_VERBOSE);
45
46 if (log)
47 log->Printf ("SBThread::SBThread () ==> this = %p", this);
Chris Lattner24943d22010-06-08 16:52:24 +000048}
49
50//----------------------------------------------------------------------
51// Thread constructor
52//----------------------------------------------------------------------
53SBThread::SBThread (const ThreadSP& lldb_object_sp) :
Greg Clayton63094e02010-06-23 01:19:29 +000054 m_opaque_sp (lldb_object_sp)
Chris Lattner24943d22010-06-08 16:52:24 +000055{
Caroline Tice7826c882010-10-26 03:11:13 +000056 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API | LIBLLDB_LOG_VERBOSE);
57
58 if (log)
59 log->Printf ("SBThread::SBThread (const ThreadSP &lldb_object_sp) lldb_object_sp.get() = %p ==> this = %p",
60 lldb_object_sp.get(), this);
Chris Lattner24943d22010-06-08 16:52:24 +000061}
62
63SBThread::SBThread (const SBThread &rhs)
64{
Caroline Tice7826c882010-10-26 03:11:13 +000065 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API | LIBLLDB_LOG_VERBOSE);
66
67 if (log)
68 log->Printf ("SBThread::SBThread (const SBThread &rhs) rhs.m_opaque_sp.get() = %p ==> this = %p",
69 rhs.m_opaque_sp.get(), this);
70
Greg Clayton63094e02010-06-23 01:19:29 +000071 m_opaque_sp = rhs.m_opaque_sp;
Chris Lattner24943d22010-06-08 16:52:24 +000072}
73
74//----------------------------------------------------------------------
75// Destructor
76//----------------------------------------------------------------------
77SBThread::~SBThread()
78{
79}
80
81bool
82SBThread::IsValid() const
83{
Greg Clayton63094e02010-06-23 01:19:29 +000084 return m_opaque_sp != NULL;
Chris Lattner24943d22010-06-08 16:52:24 +000085}
86
Greg Clayton43490d12010-07-30 20:12:55 +000087void
88SBThread::Clear ()
89{
90 m_opaque_sp.reset();
91}
92
93
Chris Lattner24943d22010-06-08 16:52:24 +000094StopReason
95SBThread::GetStopReason()
96{
Caroline Tice7826c882010-10-26 03:11:13 +000097 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
98
99 if (log)
100 log->Printf ("SBThread::GetStopReason ()");
101
102 StopReason reason = eStopReasonInvalid;
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)
Caroline Tice7826c882010-10-26 03:11:13 +0000107 reason = stop_info_sp->GetStopReason();
Chris Lattner24943d22010-06-08 16:52:24 +0000108 }
Caroline Tice7826c882010-10-26 03:11:13 +0000109
110 if (log)
111 log->Printf ("SBThread::GetStopReason ==> %s", Thread::StopReasonAsCString (reason));
112
113 return reason;
Chris Lattner24943d22010-06-08 16:52:24 +0000114}
115
116size_t
117SBThread::GetStopDescription (char *dst, size_t dst_len)
118{
Caroline Tice7826c882010-10-26 03:11:13 +0000119 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
120
121 if (log)
122 log->Printf ("SBThread::GetStopDescription (char *dst, size_t dst_len)");
123
Greg Clayton63094e02010-06-23 01:19:29 +0000124 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000125 {
Jim Ingham6297a3a2010-10-20 00:39:53 +0000126 StopInfoSP stop_info_sp = m_opaque_sp->GetStopInfo ();
127 if (stop_info_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000128 {
Jim Ingham6297a3a2010-10-20 00:39:53 +0000129 const char *stop_desc = stop_info_sp->GetDescription();
Chris Lattner24943d22010-06-08 16:52:24 +0000130 if (stop_desc)
131 {
Caroline Tice7826c882010-10-26 03:11:13 +0000132 if (log)
133 log->Printf ("SBThread::GetStopDescription ==> %s", stop_desc);
Chris Lattner24943d22010-06-08 16:52:24 +0000134 if (dst)
135 return ::snprintf (dst, dst_len, "%s", stop_desc);
136 else
137 {
138 // NULL dst passed in, return the length needed to contain the description
139 return ::strlen (stop_desc) + 1; // Include the NULL byte for size
140 }
141 }
142 else
143 {
Chris Lattner24943d22010-06-08 16:52:24 +0000144 size_t stop_desc_len = 0;
Jim Ingham6297a3a2010-10-20 00:39:53 +0000145 switch (stop_info_sp->GetStopReason())
Chris Lattner24943d22010-06-08 16:52:24 +0000146 {
147 case eStopReasonTrace:
148 case eStopReasonPlanComplete:
149 {
150 static char trace_desc[] = "step";
151 stop_desc = trace_desc;
152 stop_desc_len = sizeof(trace_desc); // Include the NULL byte for size
153 }
154 break;
155
156 case eStopReasonBreakpoint:
157 {
158 static char bp_desc[] = "breakpoint hit";
159 stop_desc = bp_desc;
160 stop_desc_len = sizeof(bp_desc); // Include the NULL byte for size
161 }
162 break;
163
164 case eStopReasonWatchpoint:
165 {
166 static char wp_desc[] = "watchpoint hit";
167 stop_desc = wp_desc;
168 stop_desc_len = sizeof(wp_desc); // Include the NULL byte for size
169 }
170 break;
171
172 case eStopReasonSignal:
173 {
Jim Ingham6297a3a2010-10-20 00:39:53 +0000174 stop_desc = m_opaque_sp->GetProcess().GetUnixSignals ().GetSignalAsCString (stop_info_sp->GetValue());
Chris Lattner24943d22010-06-08 16:52:24 +0000175 if (stop_desc == NULL || stop_desc[0] == '\0')
176 {
177 static char signal_desc[] = "signal";
178 stop_desc = signal_desc;
179 stop_desc_len = sizeof(signal_desc); // Include the NULL byte for size
180 }
181 }
182 break;
183
184 case eStopReasonException:
185 {
186 char exc_desc[] = "exception";
187 stop_desc = exc_desc;
188 stop_desc_len = sizeof(exc_desc); // Include the NULL byte for size
189 }
Greg Clayton54e7afa2010-07-09 20:39:50 +0000190 break;
191
192 default:
193 break;
Chris Lattner24943d22010-06-08 16:52:24 +0000194 }
195
196 if (stop_desc && stop_desc[0])
197 {
Caroline Tice7826c882010-10-26 03:11:13 +0000198 if (log)
199 log->Printf ("SBThread::GetStopDescription ==> %s", stop_desc);
200
Chris Lattner24943d22010-06-08 16:52:24 +0000201 if (dst)
202 return ::snprintf (dst, dst_len, "%s", stop_desc) + 1; // Include the NULL byte
203
204 if (stop_desc_len == 0)
205 stop_desc_len = ::strlen (stop_desc) + 1; // Include the NULL byte
206
207 return stop_desc_len;
208 }
209 }
210 }
211 }
212 if (dst)
213 *dst = 0;
214 return 0;
215}
216
217void
218SBThread::SetThread (const ThreadSP& lldb_object_sp)
219{
Greg Clayton63094e02010-06-23 01:19:29 +0000220 m_opaque_sp = lldb_object_sp;
Chris Lattner24943d22010-06-08 16:52:24 +0000221}
222
223
224lldb::tid_t
225SBThread::GetThreadID () const
226{
Caroline Tice7826c882010-10-26 03:11:13 +0000227 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
228
229 if (log)
230 log->Printf ("SBThread::GetThreadID()");
231
232 lldb::tid_t id = LLDB_INVALID_THREAD_ID;
Greg Clayton63094e02010-06-23 01:19:29 +0000233 if (m_opaque_sp)
Caroline Tice7826c882010-10-26 03:11:13 +0000234 id = m_opaque_sp->GetID();
235
236 if (log)
237 log->Printf ("SBThread::GetThreadID ==> %d", id);
238
239 return id;
Chris Lattner24943d22010-06-08 16:52:24 +0000240}
241
242uint32_t
243SBThread::GetIndexID () const
244{
Greg Clayton63094e02010-06-23 01:19:29 +0000245 if (m_opaque_sp)
246 return m_opaque_sp->GetIndexID();
Chris Lattner24943d22010-06-08 16:52:24 +0000247 return LLDB_INVALID_INDEX32;
248}
249const char *
250SBThread::GetName () const
251{
Caroline Tice7826c882010-10-26 03:11:13 +0000252 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
253
254 if (log)
255 log->Printf ("SBThread::GetName ()");
256
Greg Clayton63094e02010-06-23 01:19:29 +0000257 if (m_opaque_sp)
Caroline Tice7826c882010-10-26 03:11:13 +0000258 {
259 if (log)
260 log->Printf ("SBThread::GetName ==> %s", m_opaque_sp->GetName());
Greg Clayton63094e02010-06-23 01:19:29 +0000261 return m_opaque_sp->GetName();
Caroline Tice7826c882010-10-26 03:11:13 +0000262 }
263
264 if (log)
265 log->Printf ("SBThread::GetName ==> NULL");
266
Chris Lattner24943d22010-06-08 16:52:24 +0000267 return NULL;
268}
269
270const char *
271SBThread::GetQueueName () const
272{
Caroline Tice7826c882010-10-26 03:11:13 +0000273 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
274
275 if (log)
276 log->Printf ("SBThread::GetQueueName ()");
277
Greg Clayton63094e02010-06-23 01:19:29 +0000278 if (m_opaque_sp)
Caroline Tice7826c882010-10-26 03:11:13 +0000279 {
280 if (log)
281 log->Printf ("SBThread::GetQueueName ==> %s", m_opaque_sp->GetQueueName());
Greg Clayton63094e02010-06-23 01:19:29 +0000282 return m_opaque_sp->GetQueueName();
Caroline Tice7826c882010-10-26 03:11:13 +0000283 }
284
285 if (log)
286 log->Printf ("SBThread::GetQueueName ==> NULL");
287
Chris Lattner24943d22010-06-08 16:52:24 +0000288 return NULL;
289}
290
291
292void
Chris Lattner24943d22010-06-08 16:52:24 +0000293SBThread::StepOver (lldb::RunMode stop_other_threads)
294{
Caroline Tice7826c882010-10-26 03:11:13 +0000295 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
296
297 if (log)
298 log->Printf ("SBThread::StepOver (lldb::RunMode stop_other_threads) stop_other_threads = %s)",
299 Thread::RunModeAsCString (stop_other_threads));
300
Greg Clayton63094e02010-06-23 01:19:29 +0000301 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000302 {
303 bool abort_other_plans = true;
Greg Clayton63094e02010-06-23 01:19:29 +0000304 StackFrameSP frame_sp(m_opaque_sp->GetStackFrameAtIndex (0));
Chris Lattner24943d22010-06-08 16:52:24 +0000305
306 if (frame_sp)
307 {
308 if (frame_sp->HasDebugInformation ())
309 {
310 SymbolContext sc(frame_sp->GetSymbolContext(eSymbolContextEverything));
Greg Clayton63094e02010-06-23 01:19:29 +0000311 m_opaque_sp->QueueThreadPlanForStepRange (abort_other_plans,
Greg Clayton1a3083a2010-10-06 03:53:16 +0000312 eStepTypeOver,
313 sc.line_entry.range,
314 sc,
315 stop_other_threads,
316 false);
Chris Lattner24943d22010-06-08 16:52:24 +0000317
318 }
319 else
320 {
Greg Clayton63094e02010-06-23 01:19:29 +0000321 m_opaque_sp->QueueThreadPlanForStepSingleInstruction (true,
Greg Clayton1a3083a2010-10-06 03:53:16 +0000322 abort_other_plans,
323 stop_other_threads);
Chris Lattner24943d22010-06-08 16:52:24 +0000324 }
325 }
326
Greg Clayton63094e02010-06-23 01:19:29 +0000327 Process &process = m_opaque_sp->GetProcess();
Chris Lattner24943d22010-06-08 16:52:24 +0000328 // Why do we need to set the current thread by ID here???
Jim Inghamc8332952010-08-26 21:32:51 +0000329 process.GetThreadList().SetSelectedThreadByID (m_opaque_sp->GetID());
Greg Clayton1a3083a2010-10-06 03:53:16 +0000330 Error error (process.Resume());
331 if (error.Success())
332 {
333 // If we are doing synchronous mode, then wait for the
334 // process to stop yet again!
335 if (process.GetTarget().GetDebugger().GetAsyncExecution () == false)
336 process.WaitForProcessToStop (NULL);
337 }
Chris Lattner24943d22010-06-08 16:52:24 +0000338 }
339}
340
341void
342SBThread::StepInto (lldb::RunMode stop_other_threads)
343{
Caroline Tice7826c882010-10-26 03:11:13 +0000344 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
345
346 if (log)
347 log->Printf ("SBThread::StepInto (lldb::RunMode stop_other_threads) stop_other_threads =%s",
348 Thread::RunModeAsCString (stop_other_threads));
349
Greg Clayton63094e02010-06-23 01:19:29 +0000350 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000351 {
352 bool abort_other_plans = true;
353
Greg Clayton63094e02010-06-23 01:19:29 +0000354 StackFrameSP frame_sp(m_opaque_sp->GetStackFrameAtIndex (0));
Chris Lattner24943d22010-06-08 16:52:24 +0000355
356 if (frame_sp && frame_sp->HasDebugInformation ())
357 {
Greg Clayton8f5fd6b2010-06-12 18:59:55 +0000358 bool avoid_code_without_debug_info = true;
Chris Lattner24943d22010-06-08 16:52:24 +0000359 SymbolContext sc(frame_sp->GetSymbolContext(eSymbolContextEverything));
Greg Clayton63094e02010-06-23 01:19:29 +0000360 m_opaque_sp->QueueThreadPlanForStepRange (abort_other_plans,
Greg Clayton1a3083a2010-10-06 03:53:16 +0000361 eStepTypeInto,
362 sc.line_entry.range,
363 sc,
364 stop_other_threads,
365 avoid_code_without_debug_info);
Chris Lattner24943d22010-06-08 16:52:24 +0000366 }
367 else
368 {
Greg Clayton63094e02010-06-23 01:19:29 +0000369 m_opaque_sp->QueueThreadPlanForStepSingleInstruction (false,
Greg Clayton1a3083a2010-10-06 03:53:16 +0000370 abort_other_plans,
371 stop_other_threads);
Chris Lattner24943d22010-06-08 16:52:24 +0000372 }
373
Greg Clayton63094e02010-06-23 01:19:29 +0000374 Process &process = m_opaque_sp->GetProcess();
Chris Lattner24943d22010-06-08 16:52:24 +0000375 // Why do we need to set the current thread by ID here???
Jim Inghamc8332952010-08-26 21:32:51 +0000376 process.GetThreadList().SetSelectedThreadByID (m_opaque_sp->GetID());
Greg Clayton1a3083a2010-10-06 03:53:16 +0000377 Error error (process.Resume());
378 if (error.Success())
379 {
380 // If we are doing synchronous mode, then wait for the
381 // process to stop yet again!
382 if (process.GetTarget().GetDebugger().GetAsyncExecution () == false)
383 process.WaitForProcessToStop (NULL);
384 }
Chris Lattner24943d22010-06-08 16:52:24 +0000385 }
386}
387
388void
389SBThread::StepOut ()
390{
Caroline Tice7826c882010-10-26 03:11:13 +0000391 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
392
393 if (log)
394 log->Printf ("SBThread::StepOut ()");
395
Greg Clayton63094e02010-06-23 01:19:29 +0000396 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000397 {
398 bool abort_other_plans = true;
399 bool stop_other_threads = true;
400
Greg Clayton63094e02010-06-23 01:19:29 +0000401 m_opaque_sp->QueueThreadPlanForStepOut (abort_other_plans, NULL, false, stop_other_threads, eVoteYes, eVoteNoOpinion);
Chris Lattner24943d22010-06-08 16:52:24 +0000402
Greg Clayton63094e02010-06-23 01:19:29 +0000403 Process &process = m_opaque_sp->GetProcess();
Jim Inghamc8332952010-08-26 21:32:51 +0000404 process.GetThreadList().SetSelectedThreadByID (m_opaque_sp->GetID());
Greg Clayton1a3083a2010-10-06 03:53:16 +0000405 Error error (process.Resume());
406 if (error.Success())
407 {
408 // If we are doing synchronous mode, then wait for the
409 // process to stop yet again!
410 if (process.GetTarget().GetDebugger().GetAsyncExecution () == false)
411 process.WaitForProcessToStop (NULL);
412 }
Chris Lattner24943d22010-06-08 16:52:24 +0000413 }
414}
415
416void
417SBThread::StepInstruction (bool step_over)
418{
Caroline Tice7826c882010-10-26 03:11:13 +0000419 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
420
421 if (log)
422 log->Printf ("SBThread::StepInstruction (bool step_over) step_over = %s", (step_over ? "true" : "false"));
423
Greg Clayton63094e02010-06-23 01:19:29 +0000424 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000425 {
Greg Clayton63094e02010-06-23 01:19:29 +0000426 m_opaque_sp->QueueThreadPlanForStepSingleInstruction (step_over, true, true);
427 Process &process = m_opaque_sp->GetProcess();
Jim Inghamc8332952010-08-26 21:32:51 +0000428 process.GetThreadList().SetSelectedThreadByID (m_opaque_sp->GetID());
Greg Clayton1a3083a2010-10-06 03:53:16 +0000429 Error error (process.Resume());
430 if (error.Success())
431 {
432 // If we are doing synchronous mode, then wait for the
433 // process to stop yet again!
434 if (process.GetTarget().GetDebugger().GetAsyncExecution () == false)
435 process.WaitForProcessToStop (NULL);
436 }
Chris Lattner24943d22010-06-08 16:52:24 +0000437 }
438}
439
440void
441SBThread::RunToAddress (lldb::addr_t addr)
442{
Caroline Tice7826c882010-10-26 03:11:13 +0000443 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
444
445 if (log)
446 log->Printf ("SBThread::RunToAddress (lldb:;addr_t addr) addr = %p", addr);
447
Greg Clayton63094e02010-06-23 01:19:29 +0000448 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000449 {
450 bool abort_other_plans = true;
451 bool stop_other_threads = true;
452
453 Address target_addr (NULL, addr);
454
Greg Clayton63094e02010-06-23 01:19:29 +0000455 m_opaque_sp->QueueThreadPlanForRunToAddress (abort_other_plans, target_addr, stop_other_threads);
456 Process &process = m_opaque_sp->GetProcess();
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}
469
Chris Lattner24943d22010-06-08 16:52:24 +0000470SBProcess
471SBThread::GetProcess ()
472{
Caroline Tice7826c882010-10-26 03:11:13 +0000473 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
474
475 if (log)
476 log->Printf ("SBThread::GetProcess ()");
477
Chris Lattner24943d22010-06-08 16:52:24 +0000478 SBProcess process;
Greg Clayton63094e02010-06-23 01:19:29 +0000479 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000480 {
481 // Have to go up to the target so we can get a shared pointer to our process...
Greg Clayton63094e02010-06-23 01:19:29 +0000482 process.SetProcess(m_opaque_sp->GetProcess().GetTarget().GetProcessSP());
Chris Lattner24943d22010-06-08 16:52:24 +0000483 }
Caroline Tice7826c882010-10-26 03:11:13 +0000484
485 if (log)
486 {
487 SBStream sstr;
488 process.GetDescription (sstr);
489 log->Printf ("SBThread::GetProcess ==> SBProcess (this = %p, '%s')", &process, sstr.GetData());
490 }
491
Chris Lattner24943d22010-06-08 16:52:24 +0000492 return process;
493}
494
495uint32_t
496SBThread::GetNumFrames ()
497{
Caroline Tice7826c882010-10-26 03:11:13 +0000498 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
499
500 if (log)
501 log->Printf ("SBThread::GetNumFrames ()");
502
503 uint32_t num_frames = 0;
Greg Clayton63094e02010-06-23 01:19:29 +0000504 if (m_opaque_sp)
Caroline Tice7826c882010-10-26 03:11:13 +0000505 num_frames = m_opaque_sp->GetStackFrameCount();
506
507 if (log)
508 log->Printf ("SBThread::GetNumFrames ==> %d", num_frames);
509
510 return num_frames;
Chris Lattner24943d22010-06-08 16:52:24 +0000511}
512
513SBFrame
514SBThread::GetFrameAtIndex (uint32_t idx)
515{
Caroline Tice7826c882010-10-26 03:11:13 +0000516 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
517
518 if (log)
519 log->Printf ("SBThread::GetFrameAtIndex (uint32_t idx) idx = %d", idx);
520
Chris Lattner24943d22010-06-08 16:52:24 +0000521 SBFrame sb_frame;
Greg Clayton63094e02010-06-23 01:19:29 +0000522 if (m_opaque_sp)
523 sb_frame.SetFrame (m_opaque_sp->GetStackFrameAtIndex (idx));
Caroline Tice7826c882010-10-26 03:11:13 +0000524
525 if (log)
526 {
527 SBStream sstr;
528 sb_frame.GetDescription (sstr);
529 log->Printf ("SBThread::GetFrameAtIndex ==> SBFrame (this = %p, '%s')", &sb_frame, sstr.GetData());
530 }
531
Chris Lattner24943d22010-06-08 16:52:24 +0000532 return sb_frame;
533}
534
535const lldb::SBThread &
536SBThread::operator = (const lldb::SBThread &rhs)
537{
Caroline Tice7826c882010-10-26 03:11:13 +0000538 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
539
540 if (log)
541 log->Printf ("SBThread::operator= (const lldb::SBThread &rhs) rhs.m_opaque_sp.get() = %p ==> this = %p",
542 rhs.m_opaque_sp.get(), this);
543
Greg Clayton63094e02010-06-23 01:19:29 +0000544 m_opaque_sp = rhs.m_opaque_sp;
Chris Lattner24943d22010-06-08 16:52:24 +0000545 return *this;
546}
547
548bool
549SBThread::operator == (const SBThread &rhs) const
550{
Greg Clayton63094e02010-06-23 01:19:29 +0000551 return m_opaque_sp.get() == rhs.m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000552}
553
554bool
555SBThread::operator != (const SBThread &rhs) const
556{
Greg Clayton63094e02010-06-23 01:19:29 +0000557 return m_opaque_sp.get() != rhs.m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000558}
559
560lldb_private::Thread *
561SBThread::GetLLDBObjectPtr ()
562{
Greg Clayton63094e02010-06-23 01:19:29 +0000563 return m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000564}
565
566const lldb_private::Thread *
567SBThread::operator->() const
568{
Greg Clayton63094e02010-06-23 01:19:29 +0000569 return m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000570}
571
572const lldb_private::Thread &
573SBThread::operator*() const
574{
Greg Clayton63094e02010-06-23 01:19:29 +0000575 return *m_opaque_sp;
Chris Lattner24943d22010-06-08 16:52:24 +0000576}
577
578lldb_private::Thread *
579SBThread::operator->()
580{
Greg Clayton63094e02010-06-23 01:19:29 +0000581 return m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000582}
583
584lldb_private::Thread &
585SBThread::operator*()
586{
Greg Clayton63094e02010-06-23 01:19:29 +0000587 return *m_opaque_sp;
Chris Lattner24943d22010-06-08 16:52:24 +0000588}
Caroline Tice98f930f2010-09-20 05:20:02 +0000589
590bool
591SBThread::GetDescription (SBStream &description)
592{
593 if (m_opaque_sp)
Greg Claytond8c62532010-10-07 04:19:01 +0000594 {
595 StreamString strm;
596 description.Printf("SBThread: tid = 0x%4.4x", m_opaque_sp->GetID());
597 }
Caroline Tice98f930f2010-09-20 05:20:02 +0000598 else
599 description.Printf ("No value");
600
601 return true;
602}
Caroline Tice7826c882010-10-26 03:11:13 +0000603
604bool
605SBThread::GetDescription (SBStream &description) const
606{
607 if (m_opaque_sp)
608 {
609 StreamString strm;
610 description.Printf("SBThread: tid = 0x%4.4x", m_opaque_sp->GetID());
611 }
612 else
613 description.Printf ("No value");
614
615 return true;
616}