blob: 8ed211cdf4a56fe30f91cc8e7ac31b79a8e40d96 [file] [log] [blame]
Chris Lattner24943d22010-06-08 16:52:24 +00001//===-- SBThread.cpp --------------------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
Eli Friedman7a62c8b2010-06-09 07:44:37 +000010#include "lldb/API/SBThread.h"
Chris Lattner24943d22010-06-08 16:52:24 +000011
12#include "lldb/API/SBSymbolContext.h"
13#include "lldb/API/SBFileSpec.h"
Caroline Tice98f930f2010-09-20 05:20:02 +000014#include "lldb/API/SBStream.h"
Greg Clayton640dc6b2010-11-18 18:52:36 +000015#include "lldb/Breakpoint/BreakpointLocation.h"
Greg Clayton63094e02010-06-23 01:19:29 +000016#include "lldb/Core/Debugger.h"
Chris Lattner24943d22010-06-08 16:52:24 +000017#include "lldb/Core/Stream.h"
18#include "lldb/Core/StreamFile.h"
Greg Clayton63094e02010-06-23 01:19:29 +000019#include "lldb/Interpreter/CommandInterpreter.h"
Chris Lattner24943d22010-06-08 16:52:24 +000020#include "lldb/Target/Thread.h"
21#include "lldb/Target/Process.h"
22#include "lldb/Symbol/SymbolContext.h"
23#include "lldb/Symbol/CompileUnit.h"
Greg Clayton643ee732010-08-04 01:40:35 +000024#include "lldb/Target/StopInfo.h"
Chris Lattner24943d22010-06-08 16:52:24 +000025#include "lldb/Target/Target.h"
26#include "lldb/Target/ThreadPlan.h"
Chris Lattner24943d22010-06-08 16:52:24 +000027#include "lldb/Target/ThreadPlanStepInstruction.h"
28#include "lldb/Target/ThreadPlanStepOut.h"
29#include "lldb/Target/ThreadPlanStepRange.h"
30#include "lldb/Target/ThreadPlanStepInRange.h"
31
32
Eli Friedman7a62c8b2010-06-09 07:44:37 +000033#include "lldb/API/SBAddress.h"
Eli Friedman7a62c8b2010-06-09 07:44:37 +000034#include "lldb/API/SBDebugger.h"
Jim Ingham1586d972011-12-17 01:35:57 +000035#include "lldb/API/SBFrame.h"
Eli Friedman7a62c8b2010-06-09 07:44:37 +000036#include "lldb/API/SBProcess.h"
Jim Ingham1586d972011-12-17 01:35:57 +000037#include "lldb/API/SBValue.h"
Chris Lattner24943d22010-06-08 16:52:24 +000038
39using namespace lldb;
40using namespace lldb_private;
41
Greg Clayton49ce6822010-10-31 03:01:06 +000042//----------------------------------------------------------------------
43// Constructors
44//----------------------------------------------------------------------
Chris Lattner24943d22010-06-08 16:52:24 +000045SBThread::SBThread () :
Greg Clayton63094e02010-06-23 01:19:29 +000046 m_opaque_sp ()
Chris Lattner24943d22010-06-08 16:52:24 +000047{
48}
49
Chris Lattner24943d22010-06-08 16:52:24 +000050SBThread::SBThread (const ThreadSP& lldb_object_sp) :
Greg Clayton63094e02010-06-23 01:19:29 +000051 m_opaque_sp (lldb_object_sp)
Chris Lattner24943d22010-06-08 16:52:24 +000052{
53}
54
Greg Clayton1b284412010-10-30 18:26:59 +000055SBThread::SBThread (const SBThread &rhs) :
56 m_opaque_sp (rhs.m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +000057{
Chris Lattner24943d22010-06-08 16:52:24 +000058}
59
60//----------------------------------------------------------------------
Greg Clayton49ce6822010-10-31 03:01:06 +000061// Assignment operator
62//----------------------------------------------------------------------
63
64const lldb::SBThread &
65SBThread::operator = (const SBThread &rhs)
66{
67 if (this != &rhs)
68 m_opaque_sp = rhs.m_opaque_sp;
69 return *this;
70}
71
72//----------------------------------------------------------------------
Chris Lattner24943d22010-06-08 16:52:24 +000073// Destructor
74//----------------------------------------------------------------------
75SBThread::~SBThread()
76{
77}
78
79bool
80SBThread::IsValid() const
81{
Greg Claytone40b6422011-09-18 18:59:15 +000082 return m_opaque_sp;
Chris Lattner24943d22010-06-08 16:52:24 +000083}
84
Greg Clayton43490d12010-07-30 20:12:55 +000085void
86SBThread::Clear ()
87{
88 m_opaque_sp.reset();
89}
90
91
Chris Lattner24943d22010-06-08 16:52:24 +000092StopReason
93SBThread::GetStopReason()
94{
Greg Claytone005f2c2010-11-06 01:53:30 +000095 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +000096
Caroline Tice7826c882010-10-26 03:11:13 +000097 StopReason reason = eStopReasonInvalid;
Greg Clayton63094e02010-06-23 01:19:29 +000098 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +000099 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000100 Mutex::Locker api_locker (m_opaque_sp->GetProcess().GetTarget().GetAPIMutex());
Jim Ingham6297a3a2010-10-20 00:39:53 +0000101 StopInfoSP stop_info_sp = m_opaque_sp->GetStopInfo ();
102 if (stop_info_sp)
Caroline Tice7826c882010-10-26 03:11:13 +0000103 reason = stop_info_sp->GetStopReason();
Chris Lattner24943d22010-06-08 16:52:24 +0000104 }
Caroline Tice7826c882010-10-26 03:11:13 +0000105
106 if (log)
Greg Claytona66ba462010-10-30 04:51:46 +0000107 log->Printf ("SBThread(%p)::GetStopReason () => %s", m_opaque_sp.get(),
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000108 Thread::StopReasonAsCString (reason));
Caroline Tice7826c882010-10-26 03:11:13 +0000109
110 return reason;
Chris Lattner24943d22010-06-08 16:52:24 +0000111}
112
113size_t
Greg Clayton640dc6b2010-11-18 18:52:36 +0000114SBThread::GetStopReasonDataCount ()
115{
116 if (m_opaque_sp)
117 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000118 Mutex::Locker api_locker (m_opaque_sp->GetProcess().GetTarget().GetAPIMutex());
Greg Clayton640dc6b2010-11-18 18:52:36 +0000119 StopInfoSP stop_info_sp = m_opaque_sp->GetStopInfo ();
120 if (stop_info_sp)
121 {
122 StopReason reason = stop_info_sp->GetStopReason();
123 switch (reason)
124 {
125 case eStopReasonInvalid:
126 case eStopReasonNone:
127 case eStopReasonTrace:
128 case eStopReasonPlanComplete:
129 // There is no data for these stop reasons.
130 return 0;
131
132 case eStopReasonBreakpoint:
133 {
134 break_id_t site_id = stop_info_sp->GetValue();
135 lldb::BreakpointSiteSP bp_site_sp (m_opaque_sp->GetProcess().GetBreakpointSiteList().FindByID (site_id));
136 if (bp_site_sp)
137 return bp_site_sp->GetNumberOfOwners () * 2;
138 else
139 return 0; // Breakpoint must have cleared itself...
140 }
141 break;
142
143 case eStopReasonWatchpoint:
Johnny Chenbcbefa82011-12-17 02:07:52 +0000144 return 1;
Greg Clayton640dc6b2010-11-18 18:52:36 +0000145
146 case eStopReasonSignal:
147 return 1;
148
149 case eStopReasonException:
150 return 1;
151 }
152 }
153 }
154 return 0;
155}
156
157uint64_t
158SBThread::GetStopReasonDataAtIndex (uint32_t idx)
159{
160 if (m_opaque_sp)
161 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000162 Mutex::Locker api_locker (m_opaque_sp->GetProcess().GetTarget().GetAPIMutex());
Greg Clayton640dc6b2010-11-18 18:52:36 +0000163 StopInfoSP stop_info_sp = m_opaque_sp->GetStopInfo ();
164 if (stop_info_sp)
165 {
166 StopReason reason = stop_info_sp->GetStopReason();
167 switch (reason)
168 {
169 case eStopReasonInvalid:
170 case eStopReasonNone:
171 case eStopReasonTrace:
172 case eStopReasonPlanComplete:
173 // There is no data for these stop reasons.
174 return 0;
175
176 case eStopReasonBreakpoint:
177 {
178 break_id_t site_id = stop_info_sp->GetValue();
179 lldb::BreakpointSiteSP bp_site_sp (m_opaque_sp->GetProcess().GetBreakpointSiteList().FindByID (site_id));
180 if (bp_site_sp)
181 {
182 uint32_t bp_index = idx / 2;
183 BreakpointLocationSP bp_loc_sp (bp_site_sp->GetOwnerAtIndex (bp_index));
184 if (bp_loc_sp)
185 {
186 if (bp_index & 1)
187 {
188 // Odd idx, return the breakpoint location ID
189 return bp_loc_sp->GetID();
190 }
191 else
192 {
193 // Even idx, return the breakpoint ID
194 return bp_loc_sp->GetBreakpoint().GetID();
195 }
196 }
197 }
198 return LLDB_INVALID_BREAK_ID;
199 }
200 break;
201
202 case eStopReasonWatchpoint:
Johnny Chenbcbefa82011-12-17 02:07:52 +0000203 return stop_info_sp->GetValue();
Greg Clayton640dc6b2010-11-18 18:52:36 +0000204
205 case eStopReasonSignal:
206 return stop_info_sp->GetValue();
207
208 case eStopReasonException:
209 return stop_info_sp->GetValue();
210 }
211 }
212 }
213 return 0;
214}
215
216size_t
Chris Lattner24943d22010-06-08 16:52:24 +0000217SBThread::GetStopDescription (char *dst, size_t dst_len)
218{
Greg Claytone005f2c2010-11-06 01:53:30 +0000219 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000220
Greg Clayton63094e02010-06-23 01:19:29 +0000221 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000222 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000223 Mutex::Locker api_locker (m_opaque_sp->GetProcess().GetTarget().GetAPIMutex());
Jim Ingham6297a3a2010-10-20 00:39:53 +0000224 StopInfoSP stop_info_sp = m_opaque_sp->GetStopInfo ();
225 if (stop_info_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000226 {
Jim Ingham6297a3a2010-10-20 00:39:53 +0000227 const char *stop_desc = stop_info_sp->GetDescription();
Chris Lattner24943d22010-06-08 16:52:24 +0000228 if (stop_desc)
229 {
Caroline Tice7826c882010-10-26 03:11:13 +0000230 if (log)
Greg Claytona66ba462010-10-30 04:51:46 +0000231 log->Printf ("SBThread(%p)::GetStopDescription (dst, dst_len) => \"%s\"",
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000232 m_opaque_sp.get(), stop_desc);
Chris Lattner24943d22010-06-08 16:52:24 +0000233 if (dst)
234 return ::snprintf (dst, dst_len, "%s", stop_desc);
235 else
236 {
237 // NULL dst passed in, return the length needed to contain the description
238 return ::strlen (stop_desc) + 1; // Include the NULL byte for size
239 }
240 }
241 else
242 {
Chris Lattner24943d22010-06-08 16:52:24 +0000243 size_t stop_desc_len = 0;
Jim Ingham6297a3a2010-10-20 00:39:53 +0000244 switch (stop_info_sp->GetStopReason())
Chris Lattner24943d22010-06-08 16:52:24 +0000245 {
246 case eStopReasonTrace:
247 case eStopReasonPlanComplete:
248 {
249 static char trace_desc[] = "step";
250 stop_desc = trace_desc;
251 stop_desc_len = sizeof(trace_desc); // Include the NULL byte for size
252 }
253 break;
254
255 case eStopReasonBreakpoint:
256 {
257 static char bp_desc[] = "breakpoint hit";
258 stop_desc = bp_desc;
259 stop_desc_len = sizeof(bp_desc); // Include the NULL byte for size
260 }
261 break;
262
263 case eStopReasonWatchpoint:
264 {
265 static char wp_desc[] = "watchpoint hit";
266 stop_desc = wp_desc;
267 stop_desc_len = sizeof(wp_desc); // Include the NULL byte for size
268 }
269 break;
270
271 case eStopReasonSignal:
272 {
Jim Ingham6297a3a2010-10-20 00:39:53 +0000273 stop_desc = m_opaque_sp->GetProcess().GetUnixSignals ().GetSignalAsCString (stop_info_sp->GetValue());
Chris Lattner24943d22010-06-08 16:52:24 +0000274 if (stop_desc == NULL || stop_desc[0] == '\0')
275 {
276 static char signal_desc[] = "signal";
277 stop_desc = signal_desc;
278 stop_desc_len = sizeof(signal_desc); // Include the NULL byte for size
279 }
280 }
281 break;
282
283 case eStopReasonException:
284 {
285 char exc_desc[] = "exception";
286 stop_desc = exc_desc;
287 stop_desc_len = sizeof(exc_desc); // Include the NULL byte for size
288 }
Greg Clayton54e7afa2010-07-09 20:39:50 +0000289 break;
290
291 default:
292 break;
Chris Lattner24943d22010-06-08 16:52:24 +0000293 }
294
295 if (stop_desc && stop_desc[0])
296 {
Caroline Tice7826c882010-10-26 03:11:13 +0000297 if (log)
Greg Clayton3f5ee7f2010-10-29 04:59:35 +0000298 log->Printf ("SBThread(%p)::GetStopDescription (dst, dst_len) => '%s'",
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000299 m_opaque_sp.get(), stop_desc);
Caroline Tice7826c882010-10-26 03:11:13 +0000300
Chris Lattner24943d22010-06-08 16:52:24 +0000301 if (dst)
302 return ::snprintf (dst, dst_len, "%s", stop_desc) + 1; // Include the NULL byte
303
304 if (stop_desc_len == 0)
305 stop_desc_len = ::strlen (stop_desc) + 1; // Include the NULL byte
306
307 return stop_desc_len;
308 }
309 }
310 }
311 }
312 if (dst)
313 *dst = 0;
314 return 0;
315}
316
Jim Ingham1586d972011-12-17 01:35:57 +0000317SBValue
318SBThread::GetStopReturnValue ()
319{
320 ValueObjectSP return_valobj_sp;
321 if (m_opaque_sp)
322 {
323 Mutex::Locker api_locker (m_opaque_sp->GetProcess().GetTarget().GetAPIMutex());
324 StopInfoSP stop_info_sp = m_opaque_sp->GetStopInfo ();
325 if (stop_info_sp)
326 {
327 return_valobj_sp = StopInfo::GetReturnValueObject (stop_info_sp);
328 }
329 }
330
331 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
332 if (log)
333 log->Printf ("SBThread(%p)::GetStopReturnValue () => %s", m_opaque_sp.get(),
334 return_valobj_sp.get()
335 ? return_valobj_sp->GetValueAsCString()
336 : "<no return value>");
337
338 return SBValue (return_valobj_sp);
339}
340
Chris Lattner24943d22010-06-08 16:52:24 +0000341void
342SBThread::SetThread (const ThreadSP& lldb_object_sp)
343{
Greg Clayton63094e02010-06-23 01:19:29 +0000344 m_opaque_sp = lldb_object_sp;
Chris Lattner24943d22010-06-08 16:52:24 +0000345}
346
347
348lldb::tid_t
349SBThread::GetThreadID () const
350{
Greg Claytone005f2c2010-11-06 01:53:30 +0000351 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000352
Greg Claytonbdcda462010-12-20 20:49:23 +0000353 lldb::tid_t tid = LLDB_INVALID_THREAD_ID;
Greg Clayton63094e02010-06-23 01:19:29 +0000354 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000355 tid = m_opaque_sp->GetID();
Caroline Tice7826c882010-10-26 03:11:13 +0000356
357 if (log)
Greg Claytond9919d32011-12-01 23:28:38 +0000358 log->Printf ("SBThread(%p)::GetThreadID () => 0x%4.4llx", m_opaque_sp.get(), tid);
Caroline Tice7826c882010-10-26 03:11:13 +0000359
Greg Claytonbdcda462010-12-20 20:49:23 +0000360 return tid;
Chris Lattner24943d22010-06-08 16:52:24 +0000361}
362
363uint32_t
364SBThread::GetIndexID () const
365{
Greg Clayton63094e02010-06-23 01:19:29 +0000366 if (m_opaque_sp)
367 return m_opaque_sp->GetIndexID();
Chris Lattner24943d22010-06-08 16:52:24 +0000368 return LLDB_INVALID_INDEX32;
369}
370const char *
371SBThread::GetName () const
372{
Greg Claytona66ba462010-10-30 04:51:46 +0000373 const char *name = NULL;
Greg Clayton63094e02010-06-23 01:19:29 +0000374 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000375 {
376 Mutex::Locker api_locker (m_opaque_sp->GetProcess().GetTarget().GetAPIMutex());
Greg Claytona66ba462010-10-30 04:51:46 +0000377 name = m_opaque_sp->GetName();
Greg Claytonbdcda462010-12-20 20:49:23 +0000378 }
Greg Claytona66ba462010-10-30 04:51:46 +0000379
Greg Claytone005f2c2010-11-06 01:53:30 +0000380 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000381 if (log)
Greg Claytona66ba462010-10-30 04:51:46 +0000382 log->Printf ("SBThread(%p)::GetName () => %s", m_opaque_sp.get(), name ? name : "NULL");
Caroline Tice7826c882010-10-26 03:11:13 +0000383
Greg Claytona66ba462010-10-30 04:51:46 +0000384 return name;
Chris Lattner24943d22010-06-08 16:52:24 +0000385}
386
387const char *
388SBThread::GetQueueName () const
389{
Greg Claytona66ba462010-10-30 04:51:46 +0000390 const char *name = NULL;
Greg Clayton63094e02010-06-23 01:19:29 +0000391 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000392 {
393 Mutex::Locker api_locker (m_opaque_sp->GetProcess().GetTarget().GetAPIMutex());
Greg Claytona66ba462010-10-30 04:51:46 +0000394 name = m_opaque_sp->GetQueueName();
Greg Claytonbdcda462010-12-20 20:49:23 +0000395 }
Greg Claytona66ba462010-10-30 04:51:46 +0000396
Greg Claytone005f2c2010-11-06 01:53:30 +0000397 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000398 if (log)
Greg Claytona66ba462010-10-30 04:51:46 +0000399 log->Printf ("SBThread(%p)::GetQueueName () => %s", m_opaque_sp.get(), name ? name : "NULL");
Caroline Tice7826c882010-10-26 03:11:13 +0000400
Greg Claytona66ba462010-10-30 04:51:46 +0000401 return name;
Chris Lattner24943d22010-06-08 16:52:24 +0000402}
403
404
405void
Chris Lattner24943d22010-06-08 16:52:24 +0000406SBThread::StepOver (lldb::RunMode stop_other_threads)
407{
Greg Claytone005f2c2010-11-06 01:53:30 +0000408 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000409
410 if (log)
Greg Clayton3f5ee7f2010-10-29 04:59:35 +0000411 log->Printf ("SBThread(%p)::StepOver (stop_other_threads='%s')", m_opaque_sp.get(),
Caroline Tice7826c882010-10-26 03:11:13 +0000412 Thread::RunModeAsCString (stop_other_threads));
413
Greg Clayton63094e02010-06-23 01:19:29 +0000414 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000415 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000416 Mutex::Locker api_locker (m_opaque_sp->GetProcess().GetTarget().GetAPIMutex());
Chris Lattner24943d22010-06-08 16:52:24 +0000417 bool abort_other_plans = true;
Greg Clayton63094e02010-06-23 01:19:29 +0000418 StackFrameSP frame_sp(m_opaque_sp->GetStackFrameAtIndex (0));
Chris Lattner24943d22010-06-08 16:52:24 +0000419
420 if (frame_sp)
421 {
422 if (frame_sp->HasDebugInformation ())
423 {
424 SymbolContext sc(frame_sp->GetSymbolContext(eSymbolContextEverything));
Greg Clayton63094e02010-06-23 01:19:29 +0000425 m_opaque_sp->QueueThreadPlanForStepRange (abort_other_plans,
Greg Clayton1a3083a2010-10-06 03:53:16 +0000426 eStepTypeOver,
427 sc.line_entry.range,
428 sc,
429 stop_other_threads,
430 false);
Chris Lattner24943d22010-06-08 16:52:24 +0000431
432 }
433 else
434 {
Greg Clayton63094e02010-06-23 01:19:29 +0000435 m_opaque_sp->QueueThreadPlanForStepSingleInstruction (true,
Greg Clayton1a3083a2010-10-06 03:53:16 +0000436 abort_other_plans,
437 stop_other_threads);
Chris Lattner24943d22010-06-08 16:52:24 +0000438 }
439 }
440
Greg Clayton63094e02010-06-23 01:19:29 +0000441 Process &process = m_opaque_sp->GetProcess();
Chris Lattner24943d22010-06-08 16:52:24 +0000442 // Why do we need to set the current thread by ID here???
Jim Inghamc8332952010-08-26 21:32:51 +0000443 process.GetThreadList().SetSelectedThreadByID (m_opaque_sp->GetID());
Greg Clayton1a3083a2010-10-06 03:53:16 +0000444 Error error (process.Resume());
445 if (error.Success())
446 {
447 // If we are doing synchronous mode, then wait for the
448 // process to stop yet again!
449 if (process.GetTarget().GetDebugger().GetAsyncExecution () == false)
450 process.WaitForProcessToStop (NULL);
451 }
Chris Lattner24943d22010-06-08 16:52:24 +0000452 }
453}
454
455void
456SBThread::StepInto (lldb::RunMode stop_other_threads)
457{
Greg Claytone005f2c2010-11-06 01:53:30 +0000458 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000459
460 if (log)
Greg Clayton3f5ee7f2010-10-29 04:59:35 +0000461 log->Printf ("SBThread(%p)::StepInto (stop_other_threads='%s')", m_opaque_sp.get(),
Caroline Tice7826c882010-10-26 03:11:13 +0000462 Thread::RunModeAsCString (stop_other_threads));
463
Greg Clayton63094e02010-06-23 01:19:29 +0000464 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000465 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000466 Mutex::Locker api_locker (m_opaque_sp->GetProcess().GetTarget().GetAPIMutex());
Chris Lattner24943d22010-06-08 16:52:24 +0000467 bool abort_other_plans = true;
468
Greg Clayton63094e02010-06-23 01:19:29 +0000469 StackFrameSP frame_sp(m_opaque_sp->GetStackFrameAtIndex (0));
Chris Lattner24943d22010-06-08 16:52:24 +0000470
471 if (frame_sp && frame_sp->HasDebugInformation ())
472 {
Greg Clayton8f5fd6b2010-06-12 18:59:55 +0000473 bool avoid_code_without_debug_info = true;
Chris Lattner24943d22010-06-08 16:52:24 +0000474 SymbolContext sc(frame_sp->GetSymbolContext(eSymbolContextEverything));
Greg Clayton63094e02010-06-23 01:19:29 +0000475 m_opaque_sp->QueueThreadPlanForStepRange (abort_other_plans,
Greg Clayton1a3083a2010-10-06 03:53:16 +0000476 eStepTypeInto,
477 sc.line_entry.range,
478 sc,
479 stop_other_threads,
480 avoid_code_without_debug_info);
Chris Lattner24943d22010-06-08 16:52:24 +0000481 }
482 else
483 {
Greg Clayton63094e02010-06-23 01:19:29 +0000484 m_opaque_sp->QueueThreadPlanForStepSingleInstruction (false,
Greg Clayton1a3083a2010-10-06 03:53:16 +0000485 abort_other_plans,
486 stop_other_threads);
Chris Lattner24943d22010-06-08 16:52:24 +0000487 }
488
Greg Clayton63094e02010-06-23 01:19:29 +0000489 Process &process = m_opaque_sp->GetProcess();
Chris Lattner24943d22010-06-08 16:52:24 +0000490 // Why do we need to set the current thread by ID here???
Jim Inghamc8332952010-08-26 21:32:51 +0000491 process.GetThreadList().SetSelectedThreadByID (m_opaque_sp->GetID());
Greg Clayton1a3083a2010-10-06 03:53:16 +0000492 Error error (process.Resume());
493 if (error.Success())
494 {
495 // If we are doing synchronous mode, then wait for the
496 // process to stop yet again!
497 if (process.GetTarget().GetDebugger().GetAsyncExecution () == false)
498 process.WaitForProcessToStop (NULL);
499 }
Chris Lattner24943d22010-06-08 16:52:24 +0000500 }
501}
502
503void
504SBThread::StepOut ()
505{
Greg Claytone005f2c2010-11-06 01:53:30 +0000506 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000507
508 if (log)
Greg Claytona66ba462010-10-30 04:51:46 +0000509 log->Printf ("SBThread(%p)::StepOut ()", m_opaque_sp.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000510
Greg Clayton63094e02010-06-23 01:19:29 +0000511 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000512 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000513 Mutex::Locker api_locker (m_opaque_sp->GetProcess().GetTarget().GetAPIMutex());
Chris Lattner24943d22010-06-08 16:52:24 +0000514 bool abort_other_plans = true;
515 bool stop_other_threads = true;
516
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000517 m_opaque_sp->QueueThreadPlanForStepOut (abort_other_plans,
518 NULL,
519 false,
520 stop_other_threads,
521 eVoteYes,
522 eVoteNoOpinion,
523 0);
524
525 Process &process = m_opaque_sp->GetProcess();
526 process.GetThreadList().SetSelectedThreadByID (m_opaque_sp->GetID());
527 Error error (process.Resume());
528 if (error.Success())
529 {
530 // If we are doing synchronous mode, then wait for the
531 // process to stop yet again!
532 if (process.GetTarget().GetDebugger().GetAsyncExecution () == false)
533 process.WaitForProcessToStop (NULL);
534 }
535 }
536}
Chris Lattner24943d22010-06-08 16:52:24 +0000537
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000538void
539SBThread::StepOutOfFrame (lldb::SBFrame &sb_frame)
540{
541 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
542
543 if (log)
544 {
545 SBStream frame_desc_strm;
546 sb_frame.GetDescription (frame_desc_strm);
547 log->Printf ("SBThread(%p)::StepOutOfFrame (frame = SBFrame(%p): %s)", m_opaque_sp.get(), sb_frame.get(), frame_desc_strm.GetData());
548 }
549
550 if (m_opaque_sp)
551 {
552 Mutex::Locker api_locker (m_opaque_sp->GetProcess().GetTarget().GetAPIMutex());
553 bool abort_other_plans = true;
554 bool stop_other_threads = true;
555
556 m_opaque_sp->QueueThreadPlanForStepOut (abort_other_plans,
557 NULL,
558 false,
559 stop_other_threads,
560 eVoteYes,
561 eVoteNoOpinion,
562 sb_frame->GetFrameIndex());
563
Greg Clayton63094e02010-06-23 01:19:29 +0000564 Process &process = m_opaque_sp->GetProcess();
Jim Inghamc8332952010-08-26 21:32:51 +0000565 process.GetThreadList().SetSelectedThreadByID (m_opaque_sp->GetID());
Greg Clayton1a3083a2010-10-06 03:53:16 +0000566 Error error (process.Resume());
567 if (error.Success())
568 {
569 // If we are doing synchronous mode, then wait for the
570 // process to stop yet again!
571 if (process.GetTarget().GetDebugger().GetAsyncExecution () == false)
572 process.WaitForProcessToStop (NULL);
573 }
Chris Lattner24943d22010-06-08 16:52:24 +0000574 }
575}
576
577void
578SBThread::StepInstruction (bool step_over)
579{
Greg Claytone005f2c2010-11-06 01:53:30 +0000580 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000581
582 if (log)
Greg Clayton3f5ee7f2010-10-29 04:59:35 +0000583 log->Printf ("SBThread(%p)::StepInstruction (step_over=%i)", m_opaque_sp.get(), step_over);
Caroline Tice7826c882010-10-26 03:11:13 +0000584
Greg Clayton63094e02010-06-23 01:19:29 +0000585 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000586 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000587 Mutex::Locker api_locker (m_opaque_sp->GetProcess().GetTarget().GetAPIMutex());
Greg Clayton63094e02010-06-23 01:19:29 +0000588 m_opaque_sp->QueueThreadPlanForStepSingleInstruction (step_over, true, true);
589 Process &process = m_opaque_sp->GetProcess();
Jim Inghamc8332952010-08-26 21:32:51 +0000590 process.GetThreadList().SetSelectedThreadByID (m_opaque_sp->GetID());
Greg Clayton1a3083a2010-10-06 03:53:16 +0000591 Error error (process.Resume());
592 if (error.Success())
593 {
594 // If we are doing synchronous mode, then wait for the
595 // process to stop yet again!
596 if (process.GetTarget().GetDebugger().GetAsyncExecution () == false)
597 process.WaitForProcessToStop (NULL);
598 }
Chris Lattner24943d22010-06-08 16:52:24 +0000599 }
600}
601
602void
603SBThread::RunToAddress (lldb::addr_t addr)
604{
Greg Claytone005f2c2010-11-06 01:53:30 +0000605 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000606
607 if (log)
Greg Clayton3f5ee7f2010-10-29 04:59:35 +0000608 log->Printf ("SBThread(%p)::RunToAddress (addr=0x%llx)", m_opaque_sp.get(), addr);
Caroline Tice7826c882010-10-26 03:11:13 +0000609
Greg Clayton63094e02010-06-23 01:19:29 +0000610 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000611 {
612 bool abort_other_plans = true;
613 bool stop_other_threads = true;
614
615 Address target_addr (NULL, addr);
616
Greg Clayton63094e02010-06-23 01:19:29 +0000617 m_opaque_sp->QueueThreadPlanForRunToAddress (abort_other_plans, target_addr, stop_other_threads);
618 Process &process = m_opaque_sp->GetProcess();
Jim Inghamc8332952010-08-26 21:32:51 +0000619 process.GetThreadList().SetSelectedThreadByID (m_opaque_sp->GetID());
Greg Clayton1a3083a2010-10-06 03:53:16 +0000620 Error error (process.Resume());
621 if (error.Success())
622 {
623 // If we are doing synchronous mode, then wait for the
624 // process to stop yet again!
625 if (process.GetTarget().GetDebugger().GetAsyncExecution () == false)
626 process.WaitForProcessToStop (NULL);
627 }
Chris Lattner24943d22010-06-08 16:52:24 +0000628 }
Chris Lattner24943d22010-06-08 16:52:24 +0000629}
630
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000631SBError
632SBThread::StepOverUntil (lldb::SBFrame &sb_frame,
633 lldb::SBFileSpec &sb_file_spec,
634 uint32_t line)
635{
636 SBError sb_error;
637 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
638 char path[PATH_MAX];
639
640 if (log)
641 {
642 SBStream frame_desc_strm;
643 sb_frame.GetDescription (frame_desc_strm);
644 sb_file_spec->GetPath (path, sizeof(path));
645 log->Printf ("SBThread(%p)::StepOverUntil (frame = SBFrame(%p): %s, file+line = %s:%u)",
646 m_opaque_sp.get(),
647 sb_frame.get(),
648 frame_desc_strm.GetData(),
649 path, line);
650 }
651
652 if (m_opaque_sp)
653 {
654 Mutex::Locker api_locker (m_opaque_sp->GetProcess().GetTarget().GetAPIMutex());
655
656 if (line == 0)
657 {
658 sb_error.SetErrorString("invalid line argument");
659 return sb_error;
660 }
661
662 StackFrameSP frame_sp;
663 if (sb_frame.IsValid())
664 frame_sp = sb_frame.get_sp();
665 else
666 {
667 frame_sp = m_opaque_sp->GetSelectedFrame ();
668 if (!frame_sp)
669 frame_sp = m_opaque_sp->GetStackFrameAtIndex (0);
670 }
671
672 SymbolContext frame_sc;
673 if (!frame_sp)
674 {
675 sb_error.SetErrorString("no valid frames in thread to step");
676 return sb_error;
677 }
678
679 // If we have a frame, get its line
680 frame_sc = frame_sp->GetSymbolContext (eSymbolContextCompUnit |
681 eSymbolContextFunction |
682 eSymbolContextLineEntry |
683 eSymbolContextSymbol );
684
685 if (frame_sc.comp_unit == NULL)
686 {
687 sb_error.SetErrorStringWithFormat("frame %u doesn't have debug information", frame_sp->GetFrameIndex());
688 return sb_error;
689 }
690
691 FileSpec step_file_spec;
692 if (sb_file_spec.IsValid())
693 {
694 // The file spec passed in was valid, so use it
695 step_file_spec = sb_file_spec.ref();
696 }
697 else
698 {
699 if (frame_sc.line_entry.IsValid())
700 step_file_spec = frame_sc.line_entry.file;
701 else
702 {
703 sb_error.SetErrorString("invalid file argument or no file for frame");
704 return sb_error;
705 }
706 }
707
Jim Inghamb07c62a2011-05-08 00:56:32 +0000708 // Grab the current function, then we will make sure the "until" address is
709 // within the function. We discard addresses that are out of the current
710 // function, and then if there are no addresses remaining, give an appropriate
711 // error message.
712
713 bool all_in_function = true;
714 AddressRange fun_range = frame_sc.function->GetAddressRange();
715
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000716 std::vector<addr_t> step_over_until_addrs;
717 const bool abort_other_plans = true;
718 const bool stop_other_threads = true;
719 const bool check_inlines = true;
720 const bool exact = false;
Jim Inghamb07c62a2011-05-08 00:56:32 +0000721 Target *target = &m_opaque_sp->GetProcess().GetTarget();
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000722
723 SymbolContextList sc_list;
Jim Inghamb07c62a2011-05-08 00:56:32 +0000724 const uint32_t num_matches = frame_sc.comp_unit->ResolveSymbolContext (step_file_spec,
725 line,
726 check_inlines,
727 exact,
728 eSymbolContextLineEntry,
729 sc_list);
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000730 if (num_matches > 0)
731 {
732 SymbolContext sc;
733 for (uint32_t i=0; i<num_matches; ++i)
734 {
735 if (sc_list.GetContextAtIndex(i, sc))
736 {
Jim Inghamb07c62a2011-05-08 00:56:32 +0000737 addr_t step_addr = sc.line_entry.range.GetBaseAddress().GetLoadAddress(target);
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000738 if (step_addr != LLDB_INVALID_ADDRESS)
739 {
Jim Inghamb07c62a2011-05-08 00:56:32 +0000740 if (fun_range.ContainsLoadAddress(step_addr, target))
741 step_over_until_addrs.push_back(step_addr);
742 else
743 all_in_function = false;
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000744 }
745 }
746 }
747 }
Jim Inghamb07c62a2011-05-08 00:56:32 +0000748
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000749 if (step_over_until_addrs.empty())
750 {
Jim Inghamb07c62a2011-05-08 00:56:32 +0000751 if (all_in_function)
752 {
753 step_file_spec.GetPath (path, sizeof(path));
Jason Molenda7e5fa7f2011-09-20 21:44:10 +0000754 sb_error.SetErrorStringWithFormat("No line entries for %s:%u", path, line);
Jim Inghamb07c62a2011-05-08 00:56:32 +0000755 }
756 else
Greg Clayton9c236732011-10-26 00:56:27 +0000757 sb_error.SetErrorString ("step until target not in current function");
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000758 }
759 else
760 {
761 m_opaque_sp->QueueThreadPlanForStepUntil (abort_other_plans,
762 &step_over_until_addrs[0],
763 step_over_until_addrs.size(),
764 stop_other_threads,
765 frame_sp->GetFrameIndex());
766
767 m_opaque_sp->GetProcess().GetThreadList().SetSelectedThreadByID (m_opaque_sp->GetID());
768 sb_error.ref() = m_opaque_sp->GetProcess().Resume();
769 if (sb_error->Success())
770 {
771 // If we are doing synchronous mode, then wait for the
772 // process to stop yet again!
773 if (m_opaque_sp->GetProcess().GetTarget().GetDebugger().GetAsyncExecution () == false)
774 m_opaque_sp->GetProcess().WaitForProcessToStop (NULL);
775 }
776 }
777 }
778 else
779 {
780 sb_error.SetErrorString("this SBThread object is invalid");
781 }
782 return sb_error;
783}
784
785
Greg Clayton123db402011-01-12 02:25:42 +0000786bool
787SBThread::Suspend()
788{
789 if (m_opaque_sp)
790 {
791 m_opaque_sp->SetResumeState (eStateSuspended);
792 return true;
793 }
794 return false;
795}
796
797bool
798SBThread::Resume ()
799{
800 if (m_opaque_sp)
801 {
802 m_opaque_sp->SetResumeState (eStateRunning);
803 return true;
804 }
805 return false;
806}
807
808bool
809SBThread::IsSuspended()
810{
811 if (m_opaque_sp)
Greg Claytonf41d4ca2011-01-18 21:43:22 +0000812 return m_opaque_sp->GetResumeState () == eStateSuspended;
Greg Clayton123db402011-01-12 02:25:42 +0000813 return false;
814}
815
Chris Lattner24943d22010-06-08 16:52:24 +0000816SBProcess
817SBThread::GetProcess ()
818{
Caroline Tice7826c882010-10-26 03:11:13 +0000819
Chris Lattner24943d22010-06-08 16:52:24 +0000820 SBProcess process;
Greg Clayton63094e02010-06-23 01:19:29 +0000821 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000822 {
823 // Have to go up to the target so we can get a shared pointer to our process...
Greg Clayton63094e02010-06-23 01:19:29 +0000824 process.SetProcess(m_opaque_sp->GetProcess().GetTarget().GetProcessSP());
Chris Lattner24943d22010-06-08 16:52:24 +0000825 }
Caroline Tice7826c882010-10-26 03:11:13 +0000826
Greg Claytone005f2c2010-11-06 01:53:30 +0000827 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000828 if (log)
829 {
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000830 SBStream frame_desc_strm;
831 process.GetDescription (frame_desc_strm);
Greg Claytona66ba462010-10-30 04:51:46 +0000832 log->Printf ("SBThread(%p)::GetProcess () => SBProcess(%p): %s", m_opaque_sp.get(),
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000833 process.get(), frame_desc_strm.GetData());
Caroline Tice7826c882010-10-26 03:11:13 +0000834 }
835
Chris Lattner24943d22010-06-08 16:52:24 +0000836 return process;
837}
838
839uint32_t
840SBThread::GetNumFrames ()
841{
Greg Claytone005f2c2010-11-06 01:53:30 +0000842 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000843
Caroline Tice7826c882010-10-26 03:11:13 +0000844 uint32_t num_frames = 0;
Greg Clayton63094e02010-06-23 01:19:29 +0000845 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000846 {
847 Mutex::Locker api_locker (m_opaque_sp->GetProcess().GetTarget().GetAPIMutex());
Caroline Tice7826c882010-10-26 03:11:13 +0000848 num_frames = m_opaque_sp->GetStackFrameCount();
Greg Claytonbdcda462010-12-20 20:49:23 +0000849 }
Caroline Tice7826c882010-10-26 03:11:13 +0000850
851 if (log)
Greg Claytona66ba462010-10-30 04:51:46 +0000852 log->Printf ("SBThread(%p)::GetNumFrames () => %u", m_opaque_sp.get(), num_frames);
Caroline Tice7826c882010-10-26 03:11:13 +0000853
854 return num_frames;
Chris Lattner24943d22010-06-08 16:52:24 +0000855}
856
857SBFrame
858SBThread::GetFrameAtIndex (uint32_t idx)
859{
Greg Claytone005f2c2010-11-06 01:53:30 +0000860 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000861
Chris Lattner24943d22010-06-08 16:52:24 +0000862 SBFrame sb_frame;
Greg Clayton63094e02010-06-23 01:19:29 +0000863 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000864 {
865 Mutex::Locker api_locker (m_opaque_sp->GetProcess().GetTarget().GetAPIMutex());
Greg Clayton63094e02010-06-23 01:19:29 +0000866 sb_frame.SetFrame (m_opaque_sp->GetStackFrameAtIndex (idx));
Greg Claytonbdcda462010-12-20 20:49:23 +0000867 }
Caroline Tice7826c882010-10-26 03:11:13 +0000868
869 if (log)
870 {
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000871 SBStream frame_desc_strm;
872 sb_frame.GetDescription (frame_desc_strm);
Greg Claytona66ba462010-10-30 04:51:46 +0000873 log->Printf ("SBThread(%p)::GetFrameAtIndex (idx=%d) => SBFrame(%p): %s",
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000874 m_opaque_sp.get(), idx, sb_frame.get(), frame_desc_strm.GetData());
Caroline Tice7826c882010-10-26 03:11:13 +0000875 }
876
Chris Lattner24943d22010-06-08 16:52:24 +0000877 return sb_frame;
878}
879
Greg Claytonc5157ec2010-12-17 02:26:24 +0000880lldb::SBFrame
881SBThread::GetSelectedFrame ()
882{
883 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
884
885 SBFrame sb_frame;
886 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000887 {
888 Mutex::Locker api_locker (m_opaque_sp->GetProcess().GetTarget().GetAPIMutex());
Greg Claytonc5157ec2010-12-17 02:26:24 +0000889 sb_frame.SetFrame (m_opaque_sp->GetSelectedFrame ());
Greg Claytonbdcda462010-12-20 20:49:23 +0000890 }
Greg Claytonc5157ec2010-12-17 02:26:24 +0000891
892 if (log)
893 {
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000894 SBStream frame_desc_strm;
895 sb_frame.GetDescription (frame_desc_strm);
Greg Claytonc5157ec2010-12-17 02:26:24 +0000896 log->Printf ("SBThread(%p)::GetSelectedFrame () => SBFrame(%p): %s",
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000897 m_opaque_sp.get(), sb_frame.get(), frame_desc_strm.GetData());
Greg Claytonc5157ec2010-12-17 02:26:24 +0000898 }
899
900 return sb_frame;
901}
902
903lldb::SBFrame
904SBThread::SetSelectedFrame (uint32_t idx)
905{
906 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
907
908 SBFrame sb_frame;
909 if (m_opaque_sp)
910 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000911 Mutex::Locker api_locker (m_opaque_sp->GetProcess().GetTarget().GetAPIMutex());
Greg Claytonc5157ec2010-12-17 02:26:24 +0000912 lldb::StackFrameSP frame_sp (m_opaque_sp->GetStackFrameAtIndex (idx));
913 if (frame_sp)
914 {
915 m_opaque_sp->SetSelectedFrame (frame_sp.get());
916 sb_frame.SetFrame (frame_sp);
917 }
918 }
919
920 if (log)
921 {
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000922 SBStream frame_desc_strm;
923 sb_frame.GetDescription (frame_desc_strm);
Greg Claytonc5157ec2010-12-17 02:26:24 +0000924 log->Printf ("SBThread(%p)::SetSelectedFrame (idx=%u) => SBFrame(%p): %s",
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000925 m_opaque_sp.get(), idx, sb_frame.get(), frame_desc_strm.GetData());
Greg Claytonc5157ec2010-12-17 02:26:24 +0000926 }
927 return sb_frame;
928}
929
930
Chris Lattner24943d22010-06-08 16:52:24 +0000931bool
932SBThread::operator == (const SBThread &rhs) const
933{
Greg Clayton63094e02010-06-23 01:19:29 +0000934 return m_opaque_sp.get() == rhs.m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000935}
936
937bool
938SBThread::operator != (const SBThread &rhs) const
939{
Greg Clayton63094e02010-06-23 01:19:29 +0000940 return m_opaque_sp.get() != rhs.m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000941}
942
943lldb_private::Thread *
Greg Claytona66ba462010-10-30 04:51:46 +0000944SBThread::get ()
Chris Lattner24943d22010-06-08 16:52:24 +0000945{
Greg Clayton63094e02010-06-23 01:19:29 +0000946 return m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000947}
948
949const lldb_private::Thread *
950SBThread::operator->() const
951{
Greg Clayton63094e02010-06-23 01:19:29 +0000952 return m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000953}
954
955const lldb_private::Thread &
956SBThread::operator*() const
957{
Greg Clayton63094e02010-06-23 01:19:29 +0000958 return *m_opaque_sp;
Chris Lattner24943d22010-06-08 16:52:24 +0000959}
960
961lldb_private::Thread *
962SBThread::operator->()
963{
Greg Clayton63094e02010-06-23 01:19:29 +0000964 return m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000965}
966
967lldb_private::Thread &
968SBThread::operator*()
969{
Greg Clayton63094e02010-06-23 01:19:29 +0000970 return *m_opaque_sp;
Chris Lattner24943d22010-06-08 16:52:24 +0000971}
Caroline Tice98f930f2010-09-20 05:20:02 +0000972
973bool
Caroline Tice7826c882010-10-26 03:11:13 +0000974SBThread::GetDescription (SBStream &description) const
975{
Greg Clayton96154be2011-11-13 06:57:31 +0000976 Stream &strm = description.ref();
977
Caroline Tice7826c882010-10-26 03:11:13 +0000978 if (m_opaque_sp)
979 {
Greg Clayton96154be2011-11-13 06:57:31 +0000980 strm.Printf("SBThread: tid = 0x%4.4llx", m_opaque_sp->GetID());
Caroline Tice7826c882010-10-26 03:11:13 +0000981 }
982 else
Greg Clayton96154be2011-11-13 06:57:31 +0000983 strm.PutCString ("No value");
Caroline Tice7826c882010-10-26 03:11:13 +0000984
985 return true;
986}