blob: ed34dc65c5496c99cea99fd11fffea912edeb5f6 [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);
58 log->Printf ("SBThread::SBThread (lldb_object_sp=%p) => this.sp = %p (%s)",
59 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)
70 log->Printf ("SBThread::SBThread (rhs.sp=%p) => this.sp = %p",
71 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 Tice61ba7ec2010-10-26 23:49:36 +0000100 //if (log)
101 // log->Printf ("SBThread::GetStopReason ()");
Caroline Tice7826c882010-10-26 03:11:13 +0000102
103 StopReason reason = eStopReasonInvalid;
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)
Caroline Tice7826c882010-10-26 03:11:13 +0000108 reason = stop_info_sp->GetStopReason();
Chris Lattner24943d22010-06-08 16:52:24 +0000109 }
Caroline Tice7826c882010-10-26 03:11:13 +0000110
111 if (log)
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000112 log->Printf ("SBThread::GetStopReason (this.sp=%p) => '%s'", m_opaque_sp.get(),
113 Thread::StopReasonAsCString (reason));
Caroline Tice7826c882010-10-26 03:11:13 +0000114
115 return reason;
Chris Lattner24943d22010-06-08 16:52:24 +0000116}
117
118size_t
119SBThread::GetStopDescription (char *dst, size_t dst_len)
120{
Caroline Tice7826c882010-10-26 03:11:13 +0000121 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
122
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000123 //if (log)
124 // log->Printf ("SBThread::GetStopDescription (char *dst, size_t dst_len)");
Caroline Tice7826c882010-10-26 03:11:13 +0000125
Greg Clayton63094e02010-06-23 01:19:29 +0000126 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000127 {
Jim Ingham6297a3a2010-10-20 00:39:53 +0000128 StopInfoSP stop_info_sp = m_opaque_sp->GetStopInfo ();
129 if (stop_info_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000130 {
Jim Ingham6297a3a2010-10-20 00:39:53 +0000131 const char *stop_desc = stop_info_sp->GetDescription();
Chris Lattner24943d22010-06-08 16:52:24 +0000132 if (stop_desc)
133 {
Caroline Tice7826c882010-10-26 03:11:13 +0000134 if (log)
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000135 log->Printf ("SBThread::GetStopDescription (this.sp=%p, dst, dst_len) => '%s'",
136 m_opaque_sp.get(), stop_desc);
Chris Lattner24943d22010-06-08 16:52:24 +0000137 if (dst)
138 return ::snprintf (dst, dst_len, "%s", stop_desc);
139 else
140 {
141 // NULL dst passed in, return the length needed to contain the description
142 return ::strlen (stop_desc) + 1; // Include the NULL byte for size
143 }
144 }
145 else
146 {
Chris Lattner24943d22010-06-08 16:52:24 +0000147 size_t stop_desc_len = 0;
Jim Ingham6297a3a2010-10-20 00:39:53 +0000148 switch (stop_info_sp->GetStopReason())
Chris Lattner24943d22010-06-08 16:52:24 +0000149 {
150 case eStopReasonTrace:
151 case eStopReasonPlanComplete:
152 {
153 static char trace_desc[] = "step";
154 stop_desc = trace_desc;
155 stop_desc_len = sizeof(trace_desc); // Include the NULL byte for size
156 }
157 break;
158
159 case eStopReasonBreakpoint:
160 {
161 static char bp_desc[] = "breakpoint hit";
162 stop_desc = bp_desc;
163 stop_desc_len = sizeof(bp_desc); // Include the NULL byte for size
164 }
165 break;
166
167 case eStopReasonWatchpoint:
168 {
169 static char wp_desc[] = "watchpoint hit";
170 stop_desc = wp_desc;
171 stop_desc_len = sizeof(wp_desc); // Include the NULL byte for size
172 }
173 break;
174
175 case eStopReasonSignal:
176 {
Jim Ingham6297a3a2010-10-20 00:39:53 +0000177 stop_desc = m_opaque_sp->GetProcess().GetUnixSignals ().GetSignalAsCString (stop_info_sp->GetValue());
Chris Lattner24943d22010-06-08 16:52:24 +0000178 if (stop_desc == NULL || stop_desc[0] == '\0')
179 {
180 static char signal_desc[] = "signal";
181 stop_desc = signal_desc;
182 stop_desc_len = sizeof(signal_desc); // Include the NULL byte for size
183 }
184 }
185 break;
186
187 case eStopReasonException:
188 {
189 char exc_desc[] = "exception";
190 stop_desc = exc_desc;
191 stop_desc_len = sizeof(exc_desc); // Include the NULL byte for size
192 }
Greg Clayton54e7afa2010-07-09 20:39:50 +0000193 break;
194
195 default:
196 break;
Chris Lattner24943d22010-06-08 16:52:24 +0000197 }
198
199 if (stop_desc && stop_desc[0])
200 {
Caroline Tice7826c882010-10-26 03:11:13 +0000201 if (log)
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000202 log->Printf ("SBThread::GetStopDescription (this.sp=%p, dst, dst_len) => '%s'",
203 m_opaque_sp.get(), stop_desc);
Caroline Tice7826c882010-10-26 03:11:13 +0000204
Chris Lattner24943d22010-06-08 16:52:24 +0000205 if (dst)
206 return ::snprintf (dst, dst_len, "%s", stop_desc) + 1; // Include the NULL byte
207
208 if (stop_desc_len == 0)
209 stop_desc_len = ::strlen (stop_desc) + 1; // Include the NULL byte
210
211 return stop_desc_len;
212 }
213 }
214 }
215 }
216 if (dst)
217 *dst = 0;
218 return 0;
219}
220
221void
222SBThread::SetThread (const ThreadSP& lldb_object_sp)
223{
Greg Clayton63094e02010-06-23 01:19:29 +0000224 m_opaque_sp = lldb_object_sp;
Chris Lattner24943d22010-06-08 16:52:24 +0000225}
226
227
228lldb::tid_t
229SBThread::GetThreadID () const
230{
Caroline Tice7826c882010-10-26 03:11:13 +0000231 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
232
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000233 //if (log)
234 // log->Printf ("SBThread::GetThreadID()");
Caroline Tice7826c882010-10-26 03:11:13 +0000235
236 lldb::tid_t id = LLDB_INVALID_THREAD_ID;
Greg Clayton63094e02010-06-23 01:19:29 +0000237 if (m_opaque_sp)
Caroline Tice7826c882010-10-26 03:11:13 +0000238 id = m_opaque_sp->GetID();
239
240 if (log)
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000241 log->Printf ("SBThread::GetThreadID (this.sp=%p) => %d", m_opaque_sp.get(), (uint32_t) id);
Caroline Tice7826c882010-10-26 03:11:13 +0000242
243 return id;
Chris Lattner24943d22010-06-08 16:52:24 +0000244}
245
246uint32_t
247SBThread::GetIndexID () const
248{
Greg Clayton63094e02010-06-23 01:19:29 +0000249 if (m_opaque_sp)
250 return m_opaque_sp->GetIndexID();
Chris Lattner24943d22010-06-08 16:52:24 +0000251 return LLDB_INVALID_INDEX32;
252}
253const char *
254SBThread::GetName () const
255{
Caroline Tice7826c882010-10-26 03:11:13 +0000256 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
257
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000258 //if (log)
259 // log->Printf ("SBThread::GetName ()");
Caroline Tice7826c882010-10-26 03:11:13 +0000260
Greg Clayton63094e02010-06-23 01:19:29 +0000261 if (m_opaque_sp)
Caroline Tice7826c882010-10-26 03:11:13 +0000262 {
263 if (log)
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000264 log->Printf ("SBThread::GetName (this.sp=%p) => '%s'", m_opaque_sp.get(), m_opaque_sp->GetName());
Greg Clayton63094e02010-06-23 01:19:29 +0000265 return m_opaque_sp->GetName();
Caroline Tice7826c882010-10-26 03:11:13 +0000266 }
267
268 if (log)
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000269 log->Printf ("SBThread::GetName (this.sp=%p) => NULL", m_opaque_sp.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000270
Chris Lattner24943d22010-06-08 16:52:24 +0000271 return NULL;
272}
273
274const char *
275SBThread::GetQueueName () const
276{
Caroline Tice7826c882010-10-26 03:11:13 +0000277 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
278
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000279 //if (log)
280 // log->Printf ("SBThread::GetQueueName ()");
Caroline Tice7826c882010-10-26 03:11:13 +0000281
Greg Clayton63094e02010-06-23 01:19:29 +0000282 if (m_opaque_sp)
Caroline Tice7826c882010-10-26 03:11:13 +0000283 {
284 if (log)
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000285 log->Printf ("SBThread::GetQueueName (this.sp=%p) => '%s'", m_opaque_sp.get(),
286 m_opaque_sp->GetQueueName());
Greg Clayton63094e02010-06-23 01:19:29 +0000287 return m_opaque_sp->GetQueueName();
Caroline Tice7826c882010-10-26 03:11:13 +0000288 }
289
290 if (log)
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000291 log->Printf ("SBThread::GetQueueName (this.sp=%p) => NULL", m_opaque_sp.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000292
Chris Lattner24943d22010-06-08 16:52:24 +0000293 return NULL;
294}
295
296
297void
Chris Lattner24943d22010-06-08 16:52:24 +0000298SBThread::StepOver (lldb::RunMode stop_other_threads)
299{
Caroline Tice7826c882010-10-26 03:11:13 +0000300 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
301
302 if (log)
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000303 log->Printf ("SBThread::StepOver (this.sp=%p, stop_other_threads='%s')", m_opaque_sp.get(),
Caroline Tice7826c882010-10-26 03:11:13 +0000304 Thread::RunModeAsCString (stop_other_threads));
305
Greg Clayton63094e02010-06-23 01:19:29 +0000306 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000307 {
308 bool abort_other_plans = true;
Greg Clayton63094e02010-06-23 01:19:29 +0000309 StackFrameSP frame_sp(m_opaque_sp->GetStackFrameAtIndex (0));
Chris Lattner24943d22010-06-08 16:52:24 +0000310
311 if (frame_sp)
312 {
313 if (frame_sp->HasDebugInformation ())
314 {
315 SymbolContext sc(frame_sp->GetSymbolContext(eSymbolContextEverything));
Greg Clayton63094e02010-06-23 01:19:29 +0000316 m_opaque_sp->QueueThreadPlanForStepRange (abort_other_plans,
Greg Clayton1a3083a2010-10-06 03:53:16 +0000317 eStepTypeOver,
318 sc.line_entry.range,
319 sc,
320 stop_other_threads,
321 false);
Chris Lattner24943d22010-06-08 16:52:24 +0000322
323 }
324 else
325 {
Greg Clayton63094e02010-06-23 01:19:29 +0000326 m_opaque_sp->QueueThreadPlanForStepSingleInstruction (true,
Greg Clayton1a3083a2010-10-06 03:53:16 +0000327 abort_other_plans,
328 stop_other_threads);
Chris Lattner24943d22010-06-08 16:52:24 +0000329 }
330 }
331
Greg Clayton63094e02010-06-23 01:19:29 +0000332 Process &process = m_opaque_sp->GetProcess();
Chris Lattner24943d22010-06-08 16:52:24 +0000333 // Why do we need to set the current thread by ID here???
Jim Inghamc8332952010-08-26 21:32:51 +0000334 process.GetThreadList().SetSelectedThreadByID (m_opaque_sp->GetID());
Greg Clayton1a3083a2010-10-06 03:53:16 +0000335 Error error (process.Resume());
336 if (error.Success())
337 {
338 // If we are doing synchronous mode, then wait for the
339 // process to stop yet again!
340 if (process.GetTarget().GetDebugger().GetAsyncExecution () == false)
341 process.WaitForProcessToStop (NULL);
342 }
Chris Lattner24943d22010-06-08 16:52:24 +0000343 }
344}
345
346void
347SBThread::StepInto (lldb::RunMode stop_other_threads)
348{
Caroline Tice7826c882010-10-26 03:11:13 +0000349 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
350
351 if (log)
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000352 log->Printf ("SBThread::StepInto (this.sp=%p, stop_other_threads='%s')", m_opaque_sp.get(),
Caroline Tice7826c882010-10-26 03:11:13 +0000353 Thread::RunModeAsCString (stop_other_threads));
354
Greg Clayton63094e02010-06-23 01:19:29 +0000355 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000356 {
357 bool abort_other_plans = true;
358
Greg Clayton63094e02010-06-23 01:19:29 +0000359 StackFrameSP frame_sp(m_opaque_sp->GetStackFrameAtIndex (0));
Chris Lattner24943d22010-06-08 16:52:24 +0000360
361 if (frame_sp && frame_sp->HasDebugInformation ())
362 {
Greg Clayton8f5fd6b2010-06-12 18:59:55 +0000363 bool avoid_code_without_debug_info = true;
Chris Lattner24943d22010-06-08 16:52:24 +0000364 SymbolContext sc(frame_sp->GetSymbolContext(eSymbolContextEverything));
Greg Clayton63094e02010-06-23 01:19:29 +0000365 m_opaque_sp->QueueThreadPlanForStepRange (abort_other_plans,
Greg Clayton1a3083a2010-10-06 03:53:16 +0000366 eStepTypeInto,
367 sc.line_entry.range,
368 sc,
369 stop_other_threads,
370 avoid_code_without_debug_info);
Chris Lattner24943d22010-06-08 16:52:24 +0000371 }
372 else
373 {
Greg Clayton63094e02010-06-23 01:19:29 +0000374 m_opaque_sp->QueueThreadPlanForStepSingleInstruction (false,
Greg Clayton1a3083a2010-10-06 03:53:16 +0000375 abort_other_plans,
376 stop_other_threads);
Chris Lattner24943d22010-06-08 16:52:24 +0000377 }
378
Greg Clayton63094e02010-06-23 01:19:29 +0000379 Process &process = m_opaque_sp->GetProcess();
Chris Lattner24943d22010-06-08 16:52:24 +0000380 // Why do we need to set the current thread by ID here???
Jim Inghamc8332952010-08-26 21:32:51 +0000381 process.GetThreadList().SetSelectedThreadByID (m_opaque_sp->GetID());
Greg Clayton1a3083a2010-10-06 03:53:16 +0000382 Error error (process.Resume());
383 if (error.Success())
384 {
385 // If we are doing synchronous mode, then wait for the
386 // process to stop yet again!
387 if (process.GetTarget().GetDebugger().GetAsyncExecution () == false)
388 process.WaitForProcessToStop (NULL);
389 }
Chris Lattner24943d22010-06-08 16:52:24 +0000390 }
391}
392
393void
394SBThread::StepOut ()
395{
Caroline Tice7826c882010-10-26 03:11:13 +0000396 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
397
398 if (log)
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000399 log->Printf ("SBThread::StepOut (this.sp=%p)", m_opaque_sp.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000400
Greg Clayton63094e02010-06-23 01:19:29 +0000401 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000402 {
403 bool abort_other_plans = true;
404 bool stop_other_threads = true;
405
Greg Clayton63094e02010-06-23 01:19:29 +0000406 m_opaque_sp->QueueThreadPlanForStepOut (abort_other_plans, NULL, false, stop_other_threads, eVoteYes, eVoteNoOpinion);
Chris Lattner24943d22010-06-08 16:52:24 +0000407
Greg Clayton63094e02010-06-23 01:19:29 +0000408 Process &process = m_opaque_sp->GetProcess();
Jim Inghamc8332952010-08-26 21:32:51 +0000409 process.GetThreadList().SetSelectedThreadByID (m_opaque_sp->GetID());
Greg Clayton1a3083a2010-10-06 03:53:16 +0000410 Error error (process.Resume());
411 if (error.Success())
412 {
413 // If we are doing synchronous mode, then wait for the
414 // process to stop yet again!
415 if (process.GetTarget().GetDebugger().GetAsyncExecution () == false)
416 process.WaitForProcessToStop (NULL);
417 }
Chris Lattner24943d22010-06-08 16:52:24 +0000418 }
419}
420
421void
422SBThread::StepInstruction (bool step_over)
423{
Caroline Tice7826c882010-10-26 03:11:13 +0000424 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
425
426 if (log)
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000427 log->Printf ("SBThread::StepInstruction (this.sp=%p, step_over=%s)", m_opaque_sp.get(),
428 (step_over ? "true" : "false"));
Caroline Tice7826c882010-10-26 03:11:13 +0000429
Greg Clayton63094e02010-06-23 01:19:29 +0000430 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000431 {
Greg Clayton63094e02010-06-23 01:19:29 +0000432 m_opaque_sp->QueueThreadPlanForStepSingleInstruction (step_over, true, true);
433 Process &process = m_opaque_sp->GetProcess();
Jim Inghamc8332952010-08-26 21:32:51 +0000434 process.GetThreadList().SetSelectedThreadByID (m_opaque_sp->GetID());
Greg Clayton1a3083a2010-10-06 03:53:16 +0000435 Error error (process.Resume());
436 if (error.Success())
437 {
438 // If we are doing synchronous mode, then wait for the
439 // process to stop yet again!
440 if (process.GetTarget().GetDebugger().GetAsyncExecution () == false)
441 process.WaitForProcessToStop (NULL);
442 }
Chris Lattner24943d22010-06-08 16:52:24 +0000443 }
444}
445
446void
447SBThread::RunToAddress (lldb::addr_t addr)
448{
Caroline Tice7826c882010-10-26 03:11:13 +0000449 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
450
451 if (log)
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000452 log->Printf ("SBThread::RunToAddress (this.sp=%p, addr=%p)", m_opaque_sp.get(), addr);
Caroline Tice7826c882010-10-26 03:11:13 +0000453
Greg Clayton63094e02010-06-23 01:19:29 +0000454 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000455 {
456 bool abort_other_plans = true;
457 bool stop_other_threads = true;
458
459 Address target_addr (NULL, addr);
460
Greg Clayton63094e02010-06-23 01:19:29 +0000461 m_opaque_sp->QueueThreadPlanForRunToAddress (abort_other_plans, target_addr, stop_other_threads);
462 Process &process = m_opaque_sp->GetProcess();
Jim Inghamc8332952010-08-26 21:32:51 +0000463 process.GetThreadList().SetSelectedThreadByID (m_opaque_sp->GetID());
Greg Clayton1a3083a2010-10-06 03:53:16 +0000464 Error error (process.Resume());
465 if (error.Success())
466 {
467 // If we are doing synchronous mode, then wait for the
468 // process to stop yet again!
469 if (process.GetTarget().GetDebugger().GetAsyncExecution () == false)
470 process.WaitForProcessToStop (NULL);
471 }
Chris Lattner24943d22010-06-08 16:52:24 +0000472 }
473
474}
475
Chris Lattner24943d22010-06-08 16:52:24 +0000476SBProcess
477SBThread::GetProcess ()
478{
Caroline Tice7826c882010-10-26 03:11:13 +0000479 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
480
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000481 //if (log)
482 // log->Printf ("SBThread::GetProcess ()");
Caroline Tice7826c882010-10-26 03:11:13 +0000483
Chris Lattner24943d22010-06-08 16:52:24 +0000484 SBProcess process;
Greg Clayton63094e02010-06-23 01:19:29 +0000485 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000486 {
487 // Have to go up to the target so we can get a shared pointer to our process...
Greg Clayton63094e02010-06-23 01:19:29 +0000488 process.SetProcess(m_opaque_sp->GetProcess().GetTarget().GetProcessSP());
Chris Lattner24943d22010-06-08 16:52:24 +0000489 }
Caroline Tice7826c882010-10-26 03:11:13 +0000490
491 if (log)
492 {
493 SBStream sstr;
494 process.GetDescription (sstr);
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000495 log->Printf ("SBThread::GetProcess (this.sp=%p) => SBProcess : this.sp = %p, '%s'", m_opaque_sp.get(),
496 process.get(), sstr.GetData());
Caroline Tice7826c882010-10-26 03:11:13 +0000497 }
498
Chris Lattner24943d22010-06-08 16:52:24 +0000499 return process;
500}
501
502uint32_t
503SBThread::GetNumFrames ()
504{
Caroline Tice7826c882010-10-26 03:11:13 +0000505 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
506
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000507 //if (log)
508 // log->Printf ("SBThread::GetNumFrames ()");
Caroline Tice7826c882010-10-26 03:11:13 +0000509
510 uint32_t num_frames = 0;
Greg Clayton63094e02010-06-23 01:19:29 +0000511 if (m_opaque_sp)
Caroline Tice7826c882010-10-26 03:11:13 +0000512 num_frames = m_opaque_sp->GetStackFrameCount();
513
514 if (log)
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000515 log->Printf ("SBThread::GetNumFrames (this.sp=%p) => %d", m_opaque_sp.get(), num_frames);
Caroline Tice7826c882010-10-26 03:11:13 +0000516
517 return num_frames;
Chris Lattner24943d22010-06-08 16:52:24 +0000518}
519
520SBFrame
521SBThread::GetFrameAtIndex (uint32_t idx)
522{
Caroline Tice7826c882010-10-26 03:11:13 +0000523 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
524
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000525 //if (log)
526 // log->Printf ("SBThread::GetFrameAtIndex (uint32_t idx) idx = %d", idx);
Caroline Tice7826c882010-10-26 03:11:13 +0000527
Chris Lattner24943d22010-06-08 16:52:24 +0000528 SBFrame sb_frame;
Greg Clayton63094e02010-06-23 01:19:29 +0000529 if (m_opaque_sp)
530 sb_frame.SetFrame (m_opaque_sp->GetStackFrameAtIndex (idx));
Caroline Tice7826c882010-10-26 03:11:13 +0000531
532 if (log)
533 {
534 SBStream sstr;
535 sb_frame.GetDescription (sstr);
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000536 log->Printf ("SBThread::GetFrameAtIndex (this.sp=%p, idx=%d) => SBFrame.sp : this = %p, '%s'",
537 m_opaque_sp.get(), idx, sb_frame.get(), sstr.GetData());
Caroline Tice7826c882010-10-26 03:11:13 +0000538 }
539
Chris Lattner24943d22010-06-08 16:52:24 +0000540 return sb_frame;
541}
542
543const lldb::SBThread &
544SBThread::operator = (const lldb::SBThread &rhs)
545{
Caroline Tice7826c882010-10-26 03:11:13 +0000546 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
547
548 if (log)
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000549 log->Printf ("SBThread::operator= (this.sp=%p, rhs.sp=%p)", m_opaque_sp.get(), rhs.m_opaque_sp.get());
550
Greg Clayton63094e02010-06-23 01:19:29 +0000551 m_opaque_sp = rhs.m_opaque_sp;
Chris Lattner24943d22010-06-08 16:52:24 +0000552 return *this;
553}
554
555bool
556SBThread::operator == (const SBThread &rhs) const
557{
Greg Clayton63094e02010-06-23 01:19:29 +0000558 return m_opaque_sp.get() == rhs.m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000559}
560
561bool
562SBThread::operator != (const SBThread &rhs) const
563{
Greg Clayton63094e02010-06-23 01:19:29 +0000564 return m_opaque_sp.get() != rhs.m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000565}
566
567lldb_private::Thread *
568SBThread::GetLLDBObjectPtr ()
569{
Greg Clayton63094e02010-06-23 01:19:29 +0000570 return m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000571}
572
573const lldb_private::Thread *
574SBThread::operator->() const
575{
Greg Clayton63094e02010-06-23 01:19:29 +0000576 return m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000577}
578
579const lldb_private::Thread &
580SBThread::operator*() const
581{
Greg Clayton63094e02010-06-23 01:19:29 +0000582 return *m_opaque_sp;
Chris Lattner24943d22010-06-08 16:52:24 +0000583}
584
585lldb_private::Thread *
586SBThread::operator->()
587{
Greg Clayton63094e02010-06-23 01:19:29 +0000588 return m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000589}
590
591lldb_private::Thread &
592SBThread::operator*()
593{
Greg Clayton63094e02010-06-23 01:19:29 +0000594 return *m_opaque_sp;
Chris Lattner24943d22010-06-08 16:52:24 +0000595}
Caroline Tice98f930f2010-09-20 05:20:02 +0000596
597bool
598SBThread::GetDescription (SBStream &description)
599{
600 if (m_opaque_sp)
Greg Claytond8c62532010-10-07 04:19:01 +0000601 {
602 StreamString strm;
603 description.Printf("SBThread: tid = 0x%4.4x", m_opaque_sp->GetID());
604 }
Caroline Tice98f930f2010-09-20 05:20:02 +0000605 else
606 description.Printf ("No value");
607
608 return true;
609}
Caroline Tice7826c882010-10-26 03:11:13 +0000610
611bool
612SBThread::GetDescription (SBStream &description) const
613{
614 if (m_opaque_sp)
615 {
616 StreamString strm;
617 description.Printf("SBThread: tid = 0x%4.4x", m_opaque_sp->GetID());
618 }
619 else
620 description.Printf ("No value");
621
622 return true;
623}