blob: b28a379f1a6977f106ec67d66f1fe681e0125b38 [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{
Caroline Tice61ba7ec2010-10-26 23:49:36 +000052 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
Caroline Tice7826c882010-10-26 03:11:13 +000053
54 if (log)
Caroline Tice61ba7ec2010-10-26 23:49:36 +000055 {
56 SBStream sstr;
57 GetDescription (sstr);
Greg Clayton3f5ee7f2010-10-29 04:59:35 +000058 log->Printf ("SBThread::SBThread (lldb_object_sp=%p) => SBThread(%p) :%s",
Caroline Tice61ba7ec2010-10-26 23:49:36 +000059 lldb_object_sp.get(), m_opaque_sp.get(), sstr.GetData());
60 }
Chris Lattner24943d22010-06-08 16:52:24 +000061}
62
63SBThread::SBThread (const SBThread &rhs)
64{
Caroline Tice61ba7ec2010-10-26 23:49:36 +000065 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
Caroline Tice7826c882010-10-26 03:11:13 +000066
Greg Clayton63094e02010-06-23 01:19:29 +000067 m_opaque_sp = rhs.m_opaque_sp;
Caroline Tice61ba7ec2010-10-26 23:49:36 +000068
69 if (log)
Greg Clayton3f5ee7f2010-10-29 04:59:35 +000070 log->Printf ("SBThread::SBThread (rhs.sp=%p) => SBThread(%p)",
Caroline Tice61ba7ec2010-10-26 23:49:36 +000071 rhs.m_opaque_sp.get(), m_opaque_sp.get());
72
Chris Lattner24943d22010-06-08 16:52:24 +000073}
74
75//----------------------------------------------------------------------
76// Destructor
77//----------------------------------------------------------------------
78SBThread::~SBThread()
79{
80}
81
82bool
83SBThread::IsValid() const
84{
Greg Clayton63094e02010-06-23 01:19:29 +000085 return m_opaque_sp != NULL;
Chris Lattner24943d22010-06-08 16:52:24 +000086}
87
Greg Clayton43490d12010-07-30 20:12:55 +000088void
89SBThread::Clear ()
90{
91 m_opaque_sp.reset();
92}
93
94
Chris Lattner24943d22010-06-08 16:52:24 +000095StopReason
96SBThread::GetStopReason()
97{
Caroline Tice7826c882010-10-26 03:11:13 +000098 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
99
Caroline Tice7826c882010-10-26 03:11:13 +0000100 StopReason reason = eStopReasonInvalid;
Greg Clayton63094e02010-06-23 01:19:29 +0000101 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000102 {
Jim Ingham6297a3a2010-10-20 00:39:53 +0000103 StopInfoSP stop_info_sp = m_opaque_sp->GetStopInfo ();
104 if (stop_info_sp)
Caroline Tice7826c882010-10-26 03:11:13 +0000105 reason = stop_info_sp->GetStopReason();
Chris Lattner24943d22010-06-08 16:52:24 +0000106 }
Caroline Tice7826c882010-10-26 03:11:13 +0000107
108 if (log)
Greg Clayton3f5ee7f2010-10-29 04:59:35 +0000109 log->Printf ("SBThread(%p)::GetStopReason () => '%s'", m_opaque_sp.get(),
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000110 Thread::StopReasonAsCString (reason));
Caroline Tice7826c882010-10-26 03:11:13 +0000111
112 return reason;
Chris Lattner24943d22010-06-08 16:52:24 +0000113}
114
115size_t
116SBThread::GetStopDescription (char *dst, size_t dst_len)
117{
Caroline Tice7826c882010-10-26 03:11:13 +0000118 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
119
Greg Clayton63094e02010-06-23 01:19:29 +0000120 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000121 {
Jim Ingham6297a3a2010-10-20 00:39:53 +0000122 StopInfoSP stop_info_sp = m_opaque_sp->GetStopInfo ();
123 if (stop_info_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000124 {
Jim Ingham6297a3a2010-10-20 00:39:53 +0000125 const char *stop_desc = stop_info_sp->GetDescription();
Chris Lattner24943d22010-06-08 16:52:24 +0000126 if (stop_desc)
127 {
Caroline Tice7826c882010-10-26 03:11:13 +0000128 if (log)
Greg Clayton3f5ee7f2010-10-29 04:59:35 +0000129 log->Printf ("SBThread(%p)::GetStopDescription (dst, dst_len) => '%s'",
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000130 m_opaque_sp.get(), stop_desc);
Chris Lattner24943d22010-06-08 16:52:24 +0000131 if (dst)
132 return ::snprintf (dst, dst_len, "%s", stop_desc);
133 else
134 {
135 // NULL dst passed in, return the length needed to contain the description
136 return ::strlen (stop_desc) + 1; // Include the NULL byte for size
137 }
138 }
139 else
140 {
Chris Lattner24943d22010-06-08 16:52:24 +0000141 size_t stop_desc_len = 0;
Jim Ingham6297a3a2010-10-20 00:39:53 +0000142 switch (stop_info_sp->GetStopReason())
Chris Lattner24943d22010-06-08 16:52:24 +0000143 {
144 case eStopReasonTrace:
145 case eStopReasonPlanComplete:
146 {
147 static char trace_desc[] = "step";
148 stop_desc = trace_desc;
149 stop_desc_len = sizeof(trace_desc); // Include the NULL byte for size
150 }
151 break;
152
153 case eStopReasonBreakpoint:
154 {
155 static char bp_desc[] = "breakpoint hit";
156 stop_desc = bp_desc;
157 stop_desc_len = sizeof(bp_desc); // Include the NULL byte for size
158 }
159 break;
160
161 case eStopReasonWatchpoint:
162 {
163 static char wp_desc[] = "watchpoint hit";
164 stop_desc = wp_desc;
165 stop_desc_len = sizeof(wp_desc); // Include the NULL byte for size
166 }
167 break;
168
169 case eStopReasonSignal:
170 {
Jim Ingham6297a3a2010-10-20 00:39:53 +0000171 stop_desc = m_opaque_sp->GetProcess().GetUnixSignals ().GetSignalAsCString (stop_info_sp->GetValue());
Chris Lattner24943d22010-06-08 16:52:24 +0000172 if (stop_desc == NULL || stop_desc[0] == '\0')
173 {
174 static char signal_desc[] = "signal";
175 stop_desc = signal_desc;
176 stop_desc_len = sizeof(signal_desc); // Include the NULL byte for size
177 }
178 }
179 break;
180
181 case eStopReasonException:
182 {
183 char exc_desc[] = "exception";
184 stop_desc = exc_desc;
185 stop_desc_len = sizeof(exc_desc); // Include the NULL byte for size
186 }
Greg Clayton54e7afa2010-07-09 20:39:50 +0000187 break;
188
189 default:
190 break;
Chris Lattner24943d22010-06-08 16:52:24 +0000191 }
192
193 if (stop_desc && stop_desc[0])
194 {
Caroline Tice7826c882010-10-26 03:11:13 +0000195 if (log)
Greg Clayton3f5ee7f2010-10-29 04:59:35 +0000196 log->Printf ("SBThread(%p)::GetStopDescription (dst, dst_len) => '%s'",
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000197 m_opaque_sp.get(), stop_desc);
Caroline Tice7826c882010-10-26 03:11:13 +0000198
Chris Lattner24943d22010-06-08 16:52:24 +0000199 if (dst)
200 return ::snprintf (dst, dst_len, "%s", stop_desc) + 1; // Include the NULL byte
201
202 if (stop_desc_len == 0)
203 stop_desc_len = ::strlen (stop_desc) + 1; // Include the NULL byte
204
205 return stop_desc_len;
206 }
207 }
208 }
209 }
210 if (dst)
211 *dst = 0;
212 return 0;
213}
214
215void
216SBThread::SetThread (const ThreadSP& lldb_object_sp)
217{
Greg Clayton63094e02010-06-23 01:19:29 +0000218 m_opaque_sp = lldb_object_sp;
Chris Lattner24943d22010-06-08 16:52:24 +0000219}
220
221
222lldb::tid_t
223SBThread::GetThreadID () const
224{
Caroline Tice7826c882010-10-26 03:11:13 +0000225 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
226
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000227 //if (log)
228 // log->Printf ("SBThread::GetThreadID()");
Caroline Tice7826c882010-10-26 03:11:13 +0000229
230 lldb::tid_t id = LLDB_INVALID_THREAD_ID;
Greg Clayton63094e02010-06-23 01:19:29 +0000231 if (m_opaque_sp)
Caroline Tice7826c882010-10-26 03:11:13 +0000232 id = m_opaque_sp->GetID();
233
234 if (log)
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000235 log->Printf ("SBThread::GetThreadID (this.sp=%p) => %d", m_opaque_sp.get(), (uint32_t) id);
Caroline Tice7826c882010-10-26 03:11:13 +0000236
237 return id;
Chris Lattner24943d22010-06-08 16:52:24 +0000238}
239
240uint32_t
241SBThread::GetIndexID () const
242{
Greg Clayton63094e02010-06-23 01:19:29 +0000243 if (m_opaque_sp)
244 return m_opaque_sp->GetIndexID();
Chris Lattner24943d22010-06-08 16:52:24 +0000245 return LLDB_INVALID_INDEX32;
246}
247const char *
248SBThread::GetName () const
249{
Caroline Tice7826c882010-10-26 03:11:13 +0000250 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
251
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000252 //if (log)
253 // log->Printf ("SBThread::GetName ()");
Caroline Tice7826c882010-10-26 03:11:13 +0000254
Greg Clayton63094e02010-06-23 01:19:29 +0000255 if (m_opaque_sp)
Caroline Tice7826c882010-10-26 03:11:13 +0000256 {
257 if (log)
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000258 log->Printf ("SBThread::GetName (this.sp=%p) => '%s'", m_opaque_sp.get(), m_opaque_sp->GetName());
Greg Clayton63094e02010-06-23 01:19:29 +0000259 return m_opaque_sp->GetName();
Caroline Tice7826c882010-10-26 03:11:13 +0000260 }
261
262 if (log)
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000263 log->Printf ("SBThread::GetName (this.sp=%p) => NULL", m_opaque_sp.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000264
Chris Lattner24943d22010-06-08 16:52:24 +0000265 return NULL;
266}
267
268const char *
269SBThread::GetQueueName () const
270{
Caroline Tice7826c882010-10-26 03:11:13 +0000271 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
272
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000273 //if (log)
274 // log->Printf ("SBThread::GetQueueName ()");
Caroline Tice7826c882010-10-26 03:11:13 +0000275
Greg Clayton63094e02010-06-23 01:19:29 +0000276 if (m_opaque_sp)
Caroline Tice7826c882010-10-26 03:11:13 +0000277 {
278 if (log)
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000279 log->Printf ("SBThread::GetQueueName (this.sp=%p) => '%s'", m_opaque_sp.get(),
280 m_opaque_sp->GetQueueName());
Greg Clayton63094e02010-06-23 01:19:29 +0000281 return m_opaque_sp->GetQueueName();
Caroline Tice7826c882010-10-26 03:11:13 +0000282 }
283
284 if (log)
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000285 log->Printf ("SBThread::GetQueueName (this.sp=%p) => NULL", m_opaque_sp.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000286
Chris Lattner24943d22010-06-08 16:52:24 +0000287 return NULL;
288}
289
290
291void
Chris Lattner24943d22010-06-08 16:52:24 +0000292SBThread::StepOver (lldb::RunMode stop_other_threads)
293{
Caroline Tice7826c882010-10-26 03:11:13 +0000294 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
295
296 if (log)
Greg Clayton3f5ee7f2010-10-29 04:59:35 +0000297 log->Printf ("SBThread(%p)::StepOver (stop_other_threads='%s')", m_opaque_sp.get(),
Caroline Tice7826c882010-10-26 03:11:13 +0000298 Thread::RunModeAsCString (stop_other_threads));
299
Greg Clayton63094e02010-06-23 01:19:29 +0000300 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000301 {
302 bool abort_other_plans = true;
Greg Clayton63094e02010-06-23 01:19:29 +0000303 StackFrameSP frame_sp(m_opaque_sp->GetStackFrameAtIndex (0));
Chris Lattner24943d22010-06-08 16:52:24 +0000304
305 if (frame_sp)
306 {
307 if (frame_sp->HasDebugInformation ())
308 {
309 SymbolContext sc(frame_sp->GetSymbolContext(eSymbolContextEverything));
Greg Clayton63094e02010-06-23 01:19:29 +0000310 m_opaque_sp->QueueThreadPlanForStepRange (abort_other_plans,
Greg Clayton1a3083a2010-10-06 03:53:16 +0000311 eStepTypeOver,
312 sc.line_entry.range,
313 sc,
314 stop_other_threads,
315 false);
Chris Lattner24943d22010-06-08 16:52:24 +0000316
317 }
318 else
319 {
Greg Clayton63094e02010-06-23 01:19:29 +0000320 m_opaque_sp->QueueThreadPlanForStepSingleInstruction (true,
Greg Clayton1a3083a2010-10-06 03:53:16 +0000321 abort_other_plans,
322 stop_other_threads);
Chris Lattner24943d22010-06-08 16:52:24 +0000323 }
324 }
325
Greg Clayton63094e02010-06-23 01:19:29 +0000326 Process &process = m_opaque_sp->GetProcess();
Chris Lattner24943d22010-06-08 16:52:24 +0000327 // Why do we need to set the current thread by ID here???
Jim Inghamc8332952010-08-26 21:32:51 +0000328 process.GetThreadList().SetSelectedThreadByID (m_opaque_sp->GetID());
Greg Clayton1a3083a2010-10-06 03:53:16 +0000329 Error error (process.Resume());
330 if (error.Success())
331 {
332 // If we are doing synchronous mode, then wait for the
333 // process to stop yet again!
334 if (process.GetTarget().GetDebugger().GetAsyncExecution () == false)
335 process.WaitForProcessToStop (NULL);
336 }
Chris Lattner24943d22010-06-08 16:52:24 +0000337 }
338}
339
340void
341SBThread::StepInto (lldb::RunMode stop_other_threads)
342{
Caroline Tice7826c882010-10-26 03:11:13 +0000343 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
344
345 if (log)
Greg Clayton3f5ee7f2010-10-29 04:59:35 +0000346 log->Printf ("SBThread(%p)::StepInto (stop_other_threads='%s')", m_opaque_sp.get(),
Caroline Tice7826c882010-10-26 03:11:13 +0000347 Thread::RunModeAsCString (stop_other_threads));
348
Greg Clayton63094e02010-06-23 01:19:29 +0000349 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000350 {
351 bool abort_other_plans = true;
352
Greg Clayton63094e02010-06-23 01:19:29 +0000353 StackFrameSP frame_sp(m_opaque_sp->GetStackFrameAtIndex (0));
Chris Lattner24943d22010-06-08 16:52:24 +0000354
355 if (frame_sp && frame_sp->HasDebugInformation ())
356 {
Greg Clayton8f5fd6b2010-06-12 18:59:55 +0000357 bool avoid_code_without_debug_info = true;
Chris Lattner24943d22010-06-08 16:52:24 +0000358 SymbolContext sc(frame_sp->GetSymbolContext(eSymbolContextEverything));
Greg Clayton63094e02010-06-23 01:19:29 +0000359 m_opaque_sp->QueueThreadPlanForStepRange (abort_other_plans,
Greg Clayton1a3083a2010-10-06 03:53:16 +0000360 eStepTypeInto,
361 sc.line_entry.range,
362 sc,
363 stop_other_threads,
364 avoid_code_without_debug_info);
Chris Lattner24943d22010-06-08 16:52:24 +0000365 }
366 else
367 {
Greg Clayton63094e02010-06-23 01:19:29 +0000368 m_opaque_sp->QueueThreadPlanForStepSingleInstruction (false,
Greg Clayton1a3083a2010-10-06 03:53:16 +0000369 abort_other_plans,
370 stop_other_threads);
Chris Lattner24943d22010-06-08 16:52:24 +0000371 }
372
Greg Clayton63094e02010-06-23 01:19:29 +0000373 Process &process = m_opaque_sp->GetProcess();
Chris Lattner24943d22010-06-08 16:52:24 +0000374 // Why do we need to set the current thread by ID here???
Jim Inghamc8332952010-08-26 21:32:51 +0000375 process.GetThreadList().SetSelectedThreadByID (m_opaque_sp->GetID());
Greg Clayton1a3083a2010-10-06 03:53:16 +0000376 Error error (process.Resume());
377 if (error.Success())
378 {
379 // If we are doing synchronous mode, then wait for the
380 // process to stop yet again!
381 if (process.GetTarget().GetDebugger().GetAsyncExecution () == false)
382 process.WaitForProcessToStop (NULL);
383 }
Chris Lattner24943d22010-06-08 16:52:24 +0000384 }
385}
386
387void
388SBThread::StepOut ()
389{
Caroline Tice7826c882010-10-26 03:11:13 +0000390 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
391
392 if (log)
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000393 log->Printf ("SBThread::StepOut (this.sp=%p)", m_opaque_sp.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000394
Greg Clayton63094e02010-06-23 01:19:29 +0000395 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000396 {
397 bool abort_other_plans = true;
398 bool stop_other_threads = true;
399
Greg Clayton63094e02010-06-23 01:19:29 +0000400 m_opaque_sp->QueueThreadPlanForStepOut (abort_other_plans, NULL, false, stop_other_threads, eVoteYes, eVoteNoOpinion);
Chris Lattner24943d22010-06-08 16:52:24 +0000401
Greg Clayton63094e02010-06-23 01:19:29 +0000402 Process &process = m_opaque_sp->GetProcess();
Jim Inghamc8332952010-08-26 21:32:51 +0000403 process.GetThreadList().SetSelectedThreadByID (m_opaque_sp->GetID());
Greg Clayton1a3083a2010-10-06 03:53:16 +0000404 Error error (process.Resume());
405 if (error.Success())
406 {
407 // If we are doing synchronous mode, then wait for the
408 // process to stop yet again!
409 if (process.GetTarget().GetDebugger().GetAsyncExecution () == false)
410 process.WaitForProcessToStop (NULL);
411 }
Chris Lattner24943d22010-06-08 16:52:24 +0000412 }
413}
414
415void
416SBThread::StepInstruction (bool step_over)
417{
Caroline Tice7826c882010-10-26 03:11:13 +0000418 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
419
420 if (log)
Greg Clayton3f5ee7f2010-10-29 04:59:35 +0000421 log->Printf ("SBThread(%p)::StepInstruction (step_over=%i)", m_opaque_sp.get(), step_over);
Caroline Tice7826c882010-10-26 03:11:13 +0000422
Greg Clayton63094e02010-06-23 01:19:29 +0000423 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000424 {
Greg Clayton63094e02010-06-23 01:19:29 +0000425 m_opaque_sp->QueueThreadPlanForStepSingleInstruction (step_over, true, true);
426 Process &process = m_opaque_sp->GetProcess();
Jim Inghamc8332952010-08-26 21:32:51 +0000427 process.GetThreadList().SetSelectedThreadByID (m_opaque_sp->GetID());
Greg Clayton1a3083a2010-10-06 03:53:16 +0000428 Error error (process.Resume());
429 if (error.Success())
430 {
431 // If we are doing synchronous mode, then wait for the
432 // process to stop yet again!
433 if (process.GetTarget().GetDebugger().GetAsyncExecution () == false)
434 process.WaitForProcessToStop (NULL);
435 }
Chris Lattner24943d22010-06-08 16:52:24 +0000436 }
437}
438
439void
440SBThread::RunToAddress (lldb::addr_t addr)
441{
Caroline Tice7826c882010-10-26 03:11:13 +0000442 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
443
444 if (log)
Greg Clayton3f5ee7f2010-10-29 04:59:35 +0000445 log->Printf ("SBThread(%p)::RunToAddress (addr=0x%llx)", m_opaque_sp.get(), addr);
Caroline Tice7826c882010-10-26 03:11:13 +0000446
Greg Clayton63094e02010-06-23 01:19:29 +0000447 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000448 {
449 bool abort_other_plans = true;
450 bool stop_other_threads = true;
451
452 Address target_addr (NULL, addr);
453
Greg Clayton63094e02010-06-23 01:19:29 +0000454 m_opaque_sp->QueueThreadPlanForRunToAddress (abort_other_plans, target_addr, stop_other_threads);
455 Process &process = m_opaque_sp->GetProcess();
Jim Inghamc8332952010-08-26 21:32:51 +0000456 process.GetThreadList().SetSelectedThreadByID (m_opaque_sp->GetID());
Greg Clayton1a3083a2010-10-06 03:53:16 +0000457 Error error (process.Resume());
458 if (error.Success())
459 {
460 // If we are doing synchronous mode, then wait for the
461 // process to stop yet again!
462 if (process.GetTarget().GetDebugger().GetAsyncExecution () == false)
463 process.WaitForProcessToStop (NULL);
464 }
Chris Lattner24943d22010-06-08 16:52:24 +0000465 }
466
467}
468
Chris Lattner24943d22010-06-08 16:52:24 +0000469SBProcess
470SBThread::GetProcess ()
471{
Caroline Tice7826c882010-10-26 03:11:13 +0000472
Chris Lattner24943d22010-06-08 16:52:24 +0000473 SBProcess process;
Greg Clayton63094e02010-06-23 01:19:29 +0000474 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000475 {
476 // Have to go up to the target so we can get a shared pointer to our process...
Greg Clayton63094e02010-06-23 01:19:29 +0000477 process.SetProcess(m_opaque_sp->GetProcess().GetTarget().GetProcessSP());
Chris Lattner24943d22010-06-08 16:52:24 +0000478 }
Caroline Tice7826c882010-10-26 03:11:13 +0000479
Caroline Tice926060e2010-10-29 21:48:37 +0000480 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
Caroline Tice7826c882010-10-26 03:11:13 +0000481 if (log)
482 {
483 SBStream sstr;
484 process.GetDescription (sstr);
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000485 log->Printf ("SBThread::GetProcess (this.sp=%p) => SBProcess : this.sp = %p, '%s'", m_opaque_sp.get(),
486 process.get(), sstr.GetData());
Caroline Tice7826c882010-10-26 03:11:13 +0000487 }
488
Chris Lattner24943d22010-06-08 16:52:24 +0000489 return process;
490}
491
492uint32_t
493SBThread::GetNumFrames ()
494{
Caroline Tice7826c882010-10-26 03:11:13 +0000495 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
496
Caroline Tice7826c882010-10-26 03:11:13 +0000497 uint32_t num_frames = 0;
Greg Clayton63094e02010-06-23 01:19:29 +0000498 if (m_opaque_sp)
Caroline Tice7826c882010-10-26 03:11:13 +0000499 num_frames = m_opaque_sp->GetStackFrameCount();
500
501 if (log)
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000502 log->Printf ("SBThread::GetNumFrames (this.sp=%p) => %d", m_opaque_sp.get(), num_frames);
Caroline Tice7826c882010-10-26 03:11:13 +0000503
504 return num_frames;
Chris Lattner24943d22010-06-08 16:52:24 +0000505}
506
507SBFrame
508SBThread::GetFrameAtIndex (uint32_t idx)
509{
Caroline Tice7826c882010-10-26 03:11:13 +0000510 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
511
Chris Lattner24943d22010-06-08 16:52:24 +0000512 SBFrame sb_frame;
Greg Clayton63094e02010-06-23 01:19:29 +0000513 if (m_opaque_sp)
514 sb_frame.SetFrame (m_opaque_sp->GetStackFrameAtIndex (idx));
Caroline Tice7826c882010-10-26 03:11:13 +0000515
516 if (log)
517 {
518 SBStream sstr;
519 sb_frame.GetDescription (sstr);
Greg Clayton3f5ee7f2010-10-29 04:59:35 +0000520 log->Printf ("SBThread(%p)::GetFrameAtIndex (idx=%d) => SBFrame.sp : this = %p, '%s'",
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000521 m_opaque_sp.get(), idx, sb_frame.get(), sstr.GetData());
Caroline Tice7826c882010-10-26 03:11:13 +0000522 }
523
Chris Lattner24943d22010-06-08 16:52:24 +0000524 return sb_frame;
525}
526
527const lldb::SBThread &
528SBThread::operator = (const lldb::SBThread &rhs)
529{
Caroline Tice7826c882010-10-26 03:11:13 +0000530 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
531
532 if (log)
Greg Clayton3f5ee7f2010-10-29 04:59:35 +0000533 log->Printf ("SBThread(%p)::operator= (rhs.sp=%p)", m_opaque_sp.get(), rhs.m_opaque_sp.get());
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000534
Greg Clayton63094e02010-06-23 01:19:29 +0000535 m_opaque_sp = rhs.m_opaque_sp;
Chris Lattner24943d22010-06-08 16:52:24 +0000536 return *this;
537}
538
539bool
540SBThread::operator == (const SBThread &rhs) const
541{
Greg Clayton63094e02010-06-23 01:19:29 +0000542 return m_opaque_sp.get() == rhs.m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000543}
544
545bool
546SBThread::operator != (const SBThread &rhs) const
547{
Greg Clayton63094e02010-06-23 01:19:29 +0000548 return m_opaque_sp.get() != rhs.m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000549}
550
551lldb_private::Thread *
552SBThread::GetLLDBObjectPtr ()
553{
Greg Clayton63094e02010-06-23 01:19:29 +0000554 return m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000555}
556
557const lldb_private::Thread *
558SBThread::operator->() const
559{
Greg Clayton63094e02010-06-23 01:19:29 +0000560 return m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000561}
562
563const lldb_private::Thread &
564SBThread::operator*() const
565{
Greg Clayton63094e02010-06-23 01:19:29 +0000566 return *m_opaque_sp;
Chris Lattner24943d22010-06-08 16:52:24 +0000567}
568
569lldb_private::Thread *
570SBThread::operator->()
571{
Greg Clayton63094e02010-06-23 01:19:29 +0000572 return m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000573}
574
575lldb_private::Thread &
576SBThread::operator*()
577{
Greg Clayton63094e02010-06-23 01:19:29 +0000578 return *m_opaque_sp;
Chris Lattner24943d22010-06-08 16:52:24 +0000579}
Caroline Tice98f930f2010-09-20 05:20:02 +0000580
581bool
582SBThread::GetDescription (SBStream &description)
583{
584 if (m_opaque_sp)
Greg Claytond8c62532010-10-07 04:19:01 +0000585 {
586 StreamString strm;
587 description.Printf("SBThread: tid = 0x%4.4x", m_opaque_sp->GetID());
588 }
Caroline Tice98f930f2010-09-20 05:20:02 +0000589 else
590 description.Printf ("No value");
591
592 return true;
593}
Caroline Tice7826c882010-10-26 03:11:13 +0000594
595bool
596SBThread::GetDescription (SBStream &description) const
597{
598 if (m_opaque_sp)
599 {
600 StreamString strm;
601 description.Printf("SBThread: tid = 0x%4.4x", m_opaque_sp->GetID());
602 }
603 else
604 description.Printf ("No value");
605
606 return true;
607}