blob: 3961a7f925a0077a4f38b1d854fdd0bad986977d [file] [log] [blame]
Chris Lattner30fdc8d2010-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 Friedman4c5de692010-06-09 07:44:37 +000010#include "lldb/API/SBThread.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000011
Chris Lattner30fdc8d2010-06-08 16:52:24 +000012#include "lldb/API/SBFileSpec.h"
Caroline Ticedde9cff2010-09-20 05:20:02 +000013#include "lldb/API/SBStream.h"
Kate Stoneb9c1b512016-09-06 20:57:50 +000014#include "lldb/API/SBSymbolContext.h"
Greg Clayton4e78f602010-11-18 18:52:36 +000015#include "lldb/Breakpoint/BreakpointLocation.h"
Greg Clayton66111032010-06-23 01:19:29 +000016#include "lldb/Core/Debugger.h"
Andrew Kaylora75418d2013-04-15 23:33:53 +000017#include "lldb/Core/State.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000018#include "lldb/Core/StreamFile.h"
Jason Molenda705b1802014-06-13 02:37:02 +000019#include "lldb/Core/StructuredData.h"
Zachary Turnera78bd7f2015-03-03 23:11:11 +000020#include "lldb/Core/ValueObject.h"
Greg Clayton66111032010-06-23 01:19:29 +000021#include "lldb/Interpreter/CommandInterpreter.h"
Zachary Turner93749ab2015-03-03 21:51:25 +000022#include "lldb/Symbol/CompileUnit.h"
Kate Stoneb9c1b512016-09-06 20:57:50 +000023#include "lldb/Symbol/SymbolContext.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000024#include "lldb/Target/Process.h"
Jason Molendab9ffa982014-04-25 00:01:15 +000025#include "lldb/Target/Queue.h"
Greg Claytonf4b47e12010-08-04 01:40:35 +000026#include "lldb/Target/StopInfo.h"
Kate Stoneb9c1b512016-09-06 20:57:50 +000027#include "lldb/Target/SystemRuntime.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000028#include "lldb/Target/Target.h"
Kate Stoneb9c1b512016-09-06 20:57:50 +000029#include "lldb/Target/Thread.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000030#include "lldb/Target/ThreadPlan.h"
Kate Stoneb9c1b512016-09-06 20:57:50 +000031#include "lldb/Target/ThreadPlanStepInRange.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000032#include "lldb/Target/ThreadPlanStepInstruction.h"
33#include "lldb/Target/ThreadPlanStepOut.h"
34#include "lldb/Target/ThreadPlanStepRange.h"
Kate Stoneb9c1b512016-09-06 20:57:50 +000035#include "lldb/Target/UnixSignals.h"
Zachary Turnerbf9a7732017-02-02 21:39:50 +000036#include "lldb/Utility/Stream.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000037
Eli Friedman4c5de692010-06-09 07:44:37 +000038#include "lldb/API/SBAddress.h"
Eli Friedman4c5de692010-06-09 07:44:37 +000039#include "lldb/API/SBDebugger.h"
Jim Ingham4f465cf2012-10-10 18:32:14 +000040#include "lldb/API/SBEvent.h"
Jim Ingham73ca05a2011-12-17 01:35:57 +000041#include "lldb/API/SBFrame.h"
Eli Friedman4c5de692010-06-09 07:44:37 +000042#include "lldb/API/SBProcess.h"
Kuba Brecka6a831432016-03-23 15:36:22 +000043#include "lldb/API/SBThreadCollection.h"
Jim Ingham2bdbfd52014-09-29 23:17:18 +000044#include "lldb/API/SBThreadPlan.h"
Jim Ingham73ca05a2011-12-17 01:35:57 +000045#include "lldb/API/SBValue.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000046
47using namespace lldb;
48using namespace lldb_private;
49
Kate Stoneb9c1b512016-09-06 20:57:50 +000050const char *SBThread::GetBroadcasterClassName() {
51 return Thread::GetStaticBroadcasterClass().AsCString();
Jim Ingham4f465cf2012-10-10 18:32:14 +000052}
53
Greg Claytoncfd1ace2010-10-31 03:01:06 +000054//----------------------------------------------------------------------
55// Constructors
56//----------------------------------------------------------------------
Kate Stoneb9c1b512016-09-06 20:57:50 +000057SBThread::SBThread() : m_opaque_sp(new ExecutionContextRef()) {}
Chris Lattner30fdc8d2010-06-08 16:52:24 +000058
Kate Stoneb9c1b512016-09-06 20:57:50 +000059SBThread::SBThread(const ThreadSP &lldb_object_sp)
60 : m_opaque_sp(new ExecutionContextRef(lldb_object_sp)) {}
Chris Lattner30fdc8d2010-06-08 16:52:24 +000061
Kate Stoneb9c1b512016-09-06 20:57:50 +000062SBThread::SBThread(const SBThread &rhs)
63 : m_opaque_sp(new ExecutionContextRef(*rhs.m_opaque_sp)) {}
Chris Lattner30fdc8d2010-06-08 16:52:24 +000064
65//----------------------------------------------------------------------
Greg Claytoncfd1ace2010-10-31 03:01:06 +000066// Assignment operator
67//----------------------------------------------------------------------
68
Kate Stoneb9c1b512016-09-06 20:57:50 +000069const lldb::SBThread &SBThread::operator=(const SBThread &rhs) {
70 if (this != &rhs)
71 *m_opaque_sp = *rhs.m_opaque_sp;
72 return *this;
Greg Claytoncfd1ace2010-10-31 03:01:06 +000073}
74
75//----------------------------------------------------------------------
Chris Lattner30fdc8d2010-06-08 16:52:24 +000076// Destructor
77//----------------------------------------------------------------------
Kate Stoneb9c1b512016-09-06 20:57:50 +000078SBThread::~SBThread() {}
79
80lldb::SBQueue SBThread::GetQueue() const {
81 SBQueue sb_queue;
82 QueueSP queue_sp;
83 std::unique_lock<std::recursive_mutex> lock;
84 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
85
86 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
87 if (exe_ctx.HasThreadScope()) {
88 Process::StopLocker stop_locker;
89 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock())) {
90 queue_sp = exe_ctx.GetThreadPtr()->GetQueue();
91 if (queue_sp) {
92 sb_queue.SetQueue(queue_sp);
93 }
94 } else {
95 if (log)
96 log->Printf("SBThread(%p)::GetQueue() => error: process is running",
97 static_cast<void *>(exe_ctx.GetThreadPtr()));
98 }
99 }
100
101 if (log)
102 log->Printf("SBThread(%p)::GetQueue () => SBQueue(%p)",
103 static_cast<void *>(exe_ctx.GetThreadPtr()),
104 static_cast<void *>(queue_sp.get()));
105
106 return sb_queue;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000107}
108
Kate Stoneb9c1b512016-09-06 20:57:50 +0000109bool SBThread::IsValid() const {
110 std::unique_lock<std::recursive_mutex> lock;
111 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
Jason Molendab9ffa982014-04-25 00:01:15 +0000112
Kate Stoneb9c1b512016-09-06 20:57:50 +0000113 Target *target = exe_ctx.GetTargetPtr();
114 Process *process = exe_ctx.GetProcessPtr();
115 if (target && process) {
116 Process::StopLocker stop_locker;
117 if (stop_locker.TryLock(&process->GetRunLock()))
118 return m_opaque_sp->GetThreadSP().get() != NULL;
119 }
120 // Without a valid target & process, this thread can't be valid.
121 return false;
122}
123
124void SBThread::Clear() { m_opaque_sp->Clear(); }
125
126StopReason SBThread::GetStopReason() {
127 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
128
129 StopReason reason = eStopReasonInvalid;
130 std::unique_lock<std::recursive_mutex> lock;
131 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
132
133 if (exe_ctx.HasThreadScope()) {
134 Process::StopLocker stop_locker;
135 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock())) {
136 return exe_ctx.GetThreadPtr()->GetStopReason();
137 } else {
138 if (log)
139 log->Printf(
140 "SBThread(%p)::GetStopReason() => error: process is running",
141 static_cast<void *>(exe_ctx.GetThreadPtr()));
142 }
143 }
144
145 if (log)
146 log->Printf("SBThread(%p)::GetStopReason () => %s",
147 static_cast<void *>(exe_ctx.GetThreadPtr()),
148 Thread::StopReasonAsCString(reason));
149
150 return reason;
151}
152
153size_t SBThread::GetStopReasonDataCount() {
154 std::unique_lock<std::recursive_mutex> lock;
155 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
156
157 if (exe_ctx.HasThreadScope()) {
158 Process::StopLocker stop_locker;
159 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock())) {
160 StopInfoSP stop_info_sp = exe_ctx.GetThreadPtr()->GetStopInfo();
161 if (stop_info_sp) {
162 StopReason reason = stop_info_sp->GetStopReason();
163 switch (reason) {
164 case eStopReasonInvalid:
165 case eStopReasonNone:
166 case eStopReasonTrace:
167 case eStopReasonExec:
168 case eStopReasonPlanComplete:
169 case eStopReasonThreadExiting:
170 case eStopReasonInstrumentation:
171 // There is no data for these stop reasons.
172 return 0;
173
174 case eStopReasonBreakpoint: {
175 break_id_t site_id = stop_info_sp->GetValue();
176 lldb::BreakpointSiteSP bp_site_sp(
177 exe_ctx.GetProcessPtr()->GetBreakpointSiteList().FindByID(
178 site_id));
179 if (bp_site_sp)
180 return bp_site_sp->GetNumberOfOwners() * 2;
181 else
182 return 0; // Breakpoint must have cleared itself...
183 } break;
184
185 case eStopReasonWatchpoint:
186 return 1;
187
188 case eStopReasonSignal:
189 return 1;
190
191 case eStopReasonException:
192 return 1;
193 }
194 }
195 } else {
196 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
197 if (log)
198 log->Printf("SBThread(%p)::GetStopReasonDataCount() => error: process "
199 "is running",
200 static_cast<void *>(exe_ctx.GetThreadPtr()));
201 }
202 }
203 return 0;
204}
205
206uint64_t SBThread::GetStopReasonDataAtIndex(uint32_t idx) {
207 std::unique_lock<std::recursive_mutex> lock;
208 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
209
210 if (exe_ctx.HasThreadScope()) {
211 Process::StopLocker stop_locker;
212 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock())) {
213 Thread *thread = exe_ctx.GetThreadPtr();
214 StopInfoSP stop_info_sp = thread->GetStopInfo();
215 if (stop_info_sp) {
216 StopReason reason = stop_info_sp->GetStopReason();
217 switch (reason) {
218 case eStopReasonInvalid:
219 case eStopReasonNone:
220 case eStopReasonTrace:
221 case eStopReasonExec:
222 case eStopReasonPlanComplete:
223 case eStopReasonThreadExiting:
224 case eStopReasonInstrumentation:
225 // There is no data for these stop reasons.
226 return 0;
227
228 case eStopReasonBreakpoint: {
229 break_id_t site_id = stop_info_sp->GetValue();
230 lldb::BreakpointSiteSP bp_site_sp(
231 exe_ctx.GetProcessPtr()->GetBreakpointSiteList().FindByID(
232 site_id));
233 if (bp_site_sp) {
234 uint32_t bp_index = idx / 2;
235 BreakpointLocationSP bp_loc_sp(
236 bp_site_sp->GetOwnerAtIndex(bp_index));
237 if (bp_loc_sp) {
238 if (idx & 1) {
239 // Odd idx, return the breakpoint location ID
240 return bp_loc_sp->GetID();
241 } else {
242 // Even idx, return the breakpoint ID
243 return bp_loc_sp->GetBreakpoint().GetID();
244 }
Jason Molendab9ffa982014-04-25 00:01:15 +0000245 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000246 }
247 return LLDB_INVALID_BREAK_ID;
248 } break;
249
250 case eStopReasonWatchpoint:
251 return stop_info_sp->GetValue();
252
253 case eStopReasonSignal:
254 return stop_info_sp->GetValue();
255
256 case eStopReasonException:
257 return stop_info_sp->GetValue();
Jason Molendab9ffa982014-04-25 00:01:15 +0000258 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000259 }
260 } else {
261 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
262 if (log)
263 log->Printf("SBThread(%p)::GetStopReasonDataAtIndex() => error: "
264 "process is running",
265 static_cast<void *>(exe_ctx.GetThreadPtr()));
Jason Molendab9ffa982014-04-25 00:01:15 +0000266 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000267 }
268 return 0;
Jason Molendab9ffa982014-04-25 00:01:15 +0000269}
270
Kate Stoneb9c1b512016-09-06 20:57:50 +0000271bool SBThread::GetStopReasonExtendedInfoAsJSON(lldb::SBStream &stream) {
272 Stream &strm = stream.ref();
Jason Molendab9ffa982014-04-25 00:01:15 +0000273
Kate Stoneb9c1b512016-09-06 20:57:50 +0000274 std::unique_lock<std::recursive_mutex> lock;
275 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
Jim Ingham7fa7dc32016-05-07 00:54:56 +0000276
Kate Stoneb9c1b512016-09-06 20:57:50 +0000277 if (!exe_ctx.HasThreadScope())
Jim Ingham7fa7dc32016-05-07 00:54:56 +0000278 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000279
Kate Stoneb9c1b512016-09-06 20:57:50 +0000280 StopInfoSP stop_info = exe_ctx.GetThreadPtr()->GetStopInfo();
281 StructuredData::ObjectSP info = stop_info->GetExtendedInfo();
282 if (!info)
283 return false;
Greg Clayton48e42542010-07-30 20:12:55 +0000284
Kate Stoneb9c1b512016-09-06 20:57:50 +0000285 info->Dump(strm);
Greg Clayton48e42542010-07-30 20:12:55 +0000286
Kate Stoneb9c1b512016-09-06 20:57:50 +0000287 return true;
Kuba Breckaafdf8422014-10-10 23:43:03 +0000288}
289
Kuba Brecka6a831432016-03-23 15:36:22 +0000290SBThreadCollection
Kate Stoneb9c1b512016-09-06 20:57:50 +0000291SBThread::GetStopReasonExtendedBacktraces(InstrumentationRuntimeType type) {
292 ThreadCollectionSP threads;
293 threads.reset(new ThreadCollection());
Jim Inghamb2e7d282016-06-10 17:22:26 +0000294
Kate Stoneb9c1b512016-09-06 20:57:50 +0000295 // We currently only support ThreadSanitizer.
296 if (type != eInstrumentationRuntimeTypeThreadSanitizer)
297 return threads;
298
299 std::unique_lock<std::recursive_mutex> lock;
300 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
301
302 if (!exe_ctx.HasThreadScope())
303 return threads;
304
305 ProcessSP process_sp = exe_ctx.GetProcessSP();
306
307 StopInfoSP stop_info = exe_ctx.GetThreadPtr()->GetStopInfo();
308 StructuredData::ObjectSP info = stop_info->GetExtendedInfo();
309 if (!info)
310 return threads;
311
312 return process_sp->GetInstrumentationRuntime(type)
313 ->GetBacktracesFromExtendedStopInfo(info);
Kuba Brecka6a831432016-03-23 15:36:22 +0000314}
315
Kate Stoneb9c1b512016-09-06 20:57:50 +0000316size_t SBThread::GetStopDescription(char *dst, size_t dst_len) {
317 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000318
Kate Stoneb9c1b512016-09-06 20:57:50 +0000319 std::unique_lock<std::recursive_mutex> lock;
320 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
Jim Ingham4fc6cb92012-08-22 21:34:33 +0000321
Kate Stoneb9c1b512016-09-06 20:57:50 +0000322 if (exe_ctx.HasThreadScope()) {
323 Process::StopLocker stop_locker;
324 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock())) {
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000325
Kate Stoneb9c1b512016-09-06 20:57:50 +0000326 StopInfoSP stop_info_sp = exe_ctx.GetThreadPtr()->GetStopInfo();
327 if (stop_info_sp) {
328 const char *stop_desc = stop_info_sp->GetDescription();
329 if (stop_desc) {
330 if (log)
331 log->Printf(
332 "SBThread(%p)::GetStopDescription (dst, dst_len) => \"%s\"",
333 static_cast<void *>(exe_ctx.GetThreadPtr()), stop_desc);
334 if (dst)
335 return ::snprintf(dst, dst_len, "%s", stop_desc);
336 else {
337 // NULL dst passed in, return the length needed to contain the
338 // description
339 return ::strlen(stop_desc) + 1; // Include the NULL byte for size
340 }
341 } else {
342 size_t stop_desc_len = 0;
343 switch (stop_info_sp->GetStopReason()) {
344 case eStopReasonTrace:
345 case eStopReasonPlanComplete: {
346 static char trace_desc[] = "step";
347 stop_desc = trace_desc;
348 stop_desc_len =
349 sizeof(trace_desc); // Include the NULL byte for size
350 } break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000351
Kate Stoneb9c1b512016-09-06 20:57:50 +0000352 case eStopReasonBreakpoint: {
353 static char bp_desc[] = "breakpoint hit";
354 stop_desc = bp_desc;
355 stop_desc_len = sizeof(bp_desc); // Include the NULL byte for size
356 } break;
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000357
Kate Stoneb9c1b512016-09-06 20:57:50 +0000358 case eStopReasonWatchpoint: {
359 static char wp_desc[] = "watchpoint hit";
360 stop_desc = wp_desc;
361 stop_desc_len = sizeof(wp_desc); // Include the NULL byte for size
362 } break;
Greg Clayton7fdf9ef2012-04-05 16:12:35 +0000363
Kate Stoneb9c1b512016-09-06 20:57:50 +0000364 case eStopReasonSignal: {
365 stop_desc =
366 exe_ctx.GetProcessPtr()->GetUnixSignals()->GetSignalAsCString(
367 stop_info_sp->GetValue());
368 if (stop_desc == NULL || stop_desc[0] == '\0') {
369 static char signal_desc[] = "signal";
370 stop_desc = signal_desc;
371 stop_desc_len =
372 sizeof(signal_desc); // Include the NULL byte for size
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000373 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000374 } break;
375
376 case eStopReasonException: {
377 char exc_desc[] = "exception";
378 stop_desc = exc_desc;
379 stop_desc_len = sizeof(exc_desc); // Include the NULL byte for size
380 } break;
381
382 case eStopReasonExec: {
383 char exc_desc[] = "exec";
384 stop_desc = exc_desc;
385 stop_desc_len = sizeof(exc_desc); // Include the NULL byte for size
386 } break;
387
388 case eStopReasonThreadExiting: {
389 char limbo_desc[] = "thread exiting";
390 stop_desc = limbo_desc;
391 stop_desc_len = sizeof(limbo_desc);
392 } break;
393 default:
394 break;
395 }
396
397 if (stop_desc && stop_desc[0]) {
Greg Claytonc9858e42012-04-06 02:17:47 +0000398 if (log)
Kate Stoneb9c1b512016-09-06 20:57:50 +0000399 log->Printf(
400 "SBThread(%p)::GetStopDescription (dst, dst_len) => '%s'",
401 static_cast<void *>(exe_ctx.GetThreadPtr()), stop_desc);
402
403 if (dst)
404 return ::snprintf(dst, dst_len, "%s", stop_desc) +
405 1; // Include the NULL byte
406
407 if (stop_desc_len == 0)
408 stop_desc_len = ::strlen(stop_desc) + 1; // Include the NULL byte
409
410 return stop_desc_len;
411 }
Greg Claytonc9858e42012-04-06 02:17:47 +0000412 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000413 }
414 } else {
415 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
416 if (log)
417 log->Printf(
418 "SBThread(%p)::GetStopDescription() => error: process is running",
419 static_cast<void *>(exe_ctx.GetThreadPtr()));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000420 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000421 }
422 if (dst)
423 *dst = 0;
424 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000425}
426
Kate Stoneb9c1b512016-09-06 20:57:50 +0000427SBValue SBThread::GetStopReturnValue() {
428 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
429 ValueObjectSP return_valobj_sp;
430 std::unique_lock<std::recursive_mutex> lock;
431 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
Jim Ingham4fc6cb92012-08-22 21:34:33 +0000432
Kate Stoneb9c1b512016-09-06 20:57:50 +0000433 if (exe_ctx.HasThreadScope()) {
434 Process::StopLocker stop_locker;
435 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock())) {
436 StopInfoSP stop_info_sp = exe_ctx.GetThreadPtr()->GetStopInfo();
437 if (stop_info_sp) {
438 return_valobj_sp = StopInfo::GetReturnValueObject(stop_info_sp);
439 }
440 } else {
441 if (log)
442 log->Printf(
443 "SBThread(%p)::GetStopReturnValue() => error: process is running",
444 static_cast<void *>(exe_ctx.GetThreadPtr()));
Jim Ingham73ca05a2011-12-17 01:35:57 +0000445 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000446 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000447
Kate Stoneb9c1b512016-09-06 20:57:50 +0000448 if (log)
449 log->Printf("SBThread(%p)::GetStopReturnValue () => %s",
450 static_cast<void *>(exe_ctx.GetThreadPtr()),
451 return_valobj_sp.get() ? return_valobj_sp->GetValueAsCString()
452 : "<no return value>");
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000453
Kate Stoneb9c1b512016-09-06 20:57:50 +0000454 return SBValue(return_valobj_sp);
Jim Ingham73ca05a2011-12-17 01:35:57 +0000455}
456
Kate Stoneb9c1b512016-09-06 20:57:50 +0000457void SBThread::SetThread(const ThreadSP &lldb_object_sp) {
458 m_opaque_sp->SetThreadSP(lldb_object_sp);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000459}
460
Kate Stoneb9c1b512016-09-06 20:57:50 +0000461lldb::tid_t SBThread::GetThreadID() const {
462 ThreadSP thread_sp(m_opaque_sp->GetThreadSP());
463 if (thread_sp)
464 return thread_sp->GetID();
465 return LLDB_INVALID_THREAD_ID;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000466}
467
Kate Stoneb9c1b512016-09-06 20:57:50 +0000468uint32_t SBThread::GetIndexID() const {
469 ThreadSP thread_sp(m_opaque_sp->GetThreadSP());
470 if (thread_sp)
471 return thread_sp->GetIndexID();
472 return LLDB_INVALID_INDEX32;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000473}
Greg Clayton1ac04c32012-02-21 00:09:25 +0000474
Kate Stoneb9c1b512016-09-06 20:57:50 +0000475const char *SBThread::GetName() const {
476 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
477 const char *name = NULL;
478 std::unique_lock<std::recursive_mutex> lock;
479 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
Jim Ingham4fc6cb92012-08-22 21:34:33 +0000480
Kate Stoneb9c1b512016-09-06 20:57:50 +0000481 if (exe_ctx.HasThreadScope()) {
482 Process::StopLocker stop_locker;
483 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock())) {
484 name = exe_ctx.GetThreadPtr()->GetName();
485 } else {
486 if (log)
487 log->Printf("SBThread(%p)::GetName() => error: process is running",
488 static_cast<void *>(exe_ctx.GetThreadPtr()));
Greg Claytonaf67cec2010-12-20 20:49:23 +0000489 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000490 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000491
Kate Stoneb9c1b512016-09-06 20:57:50 +0000492 if (log)
493 log->Printf("SBThread(%p)::GetName () => %s",
494 static_cast<void *>(exe_ctx.GetThreadPtr()),
495 name ? name : "NULL");
Caroline Ticeceb6b132010-10-26 03:11:13 +0000496
Kate Stoneb9c1b512016-09-06 20:57:50 +0000497 return name;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000498}
499
Kate Stoneb9c1b512016-09-06 20:57:50 +0000500const char *SBThread::GetQueueName() const {
501 const char *name = NULL;
502 std::unique_lock<std::recursive_mutex> lock;
503 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
Jim Ingham4fc6cb92012-08-22 21:34:33 +0000504
Kate Stoneb9c1b512016-09-06 20:57:50 +0000505 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
506 if (exe_ctx.HasThreadScope()) {
507 Process::StopLocker stop_locker;
508 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock())) {
509 name = exe_ctx.GetThreadPtr()->GetQueueName();
510 } else {
511 if (log)
512 log->Printf("SBThread(%p)::GetQueueName() => error: process is running",
513 static_cast<void *>(exe_ctx.GetThreadPtr()));
Greg Claytonaf67cec2010-12-20 20:49:23 +0000514 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000515 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000516
Kate Stoneb9c1b512016-09-06 20:57:50 +0000517 if (log)
518 log->Printf("SBThread(%p)::GetQueueName () => %s",
519 static_cast<void *>(exe_ctx.GetThreadPtr()),
520 name ? name : "NULL");
Caroline Ticeceb6b132010-10-26 03:11:13 +0000521
Kate Stoneb9c1b512016-09-06 20:57:50 +0000522 return name;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000523}
524
Kate Stoneb9c1b512016-09-06 20:57:50 +0000525lldb::queue_id_t SBThread::GetQueueID() const {
526 queue_id_t id = LLDB_INVALID_QUEUE_ID;
527 std::unique_lock<std::recursive_mutex> lock;
528 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
Jason Molenda4fdb5862013-10-21 23:52:54 +0000529
Kate Stoneb9c1b512016-09-06 20:57:50 +0000530 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
531 if (exe_ctx.HasThreadScope()) {
532 Process::StopLocker stop_locker;
533 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock())) {
534 id = exe_ctx.GetThreadPtr()->GetQueueID();
535 } else {
536 if (log)
537 log->Printf("SBThread(%p)::GetQueueID() => error: process is running",
538 static_cast<void *>(exe_ctx.GetThreadPtr()));
Jason Molenda4fdb5862013-10-21 23:52:54 +0000539 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000540 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000541
Kate Stoneb9c1b512016-09-06 20:57:50 +0000542 if (log)
543 log->Printf("SBThread(%p)::GetQueueID () => 0x%" PRIx64,
544 static_cast<void *>(exe_ctx.GetThreadPtr()), id);
Jason Molenda4fdb5862013-10-21 23:52:54 +0000545
Kate Stoneb9c1b512016-09-06 20:57:50 +0000546 return id;
Jason Molenda4fdb5862013-10-21 23:52:54 +0000547}
548
Kate Stoneb9c1b512016-09-06 20:57:50 +0000549bool SBThread::GetInfoItemByPathAsString(const char *path, SBStream &strm) {
550 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
551 bool success = false;
552 std::unique_lock<std::recursive_mutex> lock;
553 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
Jason Molenda705b1802014-06-13 02:37:02 +0000554
Kate Stoneb9c1b512016-09-06 20:57:50 +0000555 if (exe_ctx.HasThreadScope()) {
556 Process::StopLocker stop_locker;
557 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock())) {
558 Thread *thread = exe_ctx.GetThreadPtr();
559 StructuredData::ObjectSP info_root_sp = thread->GetExtendedInfo();
560 if (info_root_sp) {
561 StructuredData::ObjectSP node =
562 info_root_sp->GetObjectForDotSeparatedPath(path);
563 if (node) {
564 if (node->GetType() == StructuredData::Type::eTypeString) {
565 strm.Printf("%s", node->GetAsString()->GetValue().c_str());
566 success = true;
567 }
568 if (node->GetType() == StructuredData::Type::eTypeInteger) {
569 strm.Printf("0x%" PRIx64, node->GetAsInteger()->GetValue());
570 success = true;
571 }
572 if (node->GetType() == StructuredData::Type::eTypeFloat) {
573 strm.Printf("0x%f", node->GetAsFloat()->GetValue());
574 success = true;
575 }
576 if (node->GetType() == StructuredData::Type::eTypeBoolean) {
577 if (node->GetAsBoolean()->GetValue() == true)
578 strm.Printf("true");
579 else
580 strm.Printf("false");
581 success = true;
582 }
583 if (node->GetType() == StructuredData::Type::eTypeNull) {
584 strm.Printf("null");
585 success = true;
586 }
Jason Molenda705b1802014-06-13 02:37:02 +0000587 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000588 }
589 } else {
590 if (log)
591 log->Printf("SBThread(%p)::GetInfoItemByPathAsString() => error: "
592 "process is running",
593 static_cast<void *>(exe_ctx.GetThreadPtr()));
Jason Molenda705b1802014-06-13 02:37:02 +0000594 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000595 }
Jason Molenda705b1802014-06-13 02:37:02 +0000596
Kate Stoneb9c1b512016-09-06 20:57:50 +0000597 if (log)
Jason Molenda753e13c2017-02-02 03:02:51 +0000598 log->Printf("SBThread(%p)::GetInfoItemByPathAsString (\"%s\") => \"%s\"",
599 static_cast<void *>(exe_ctx.GetThreadPtr()), path, strm.GetData());
Jason Molenda705b1802014-06-13 02:37:02 +0000600
Kate Stoneb9c1b512016-09-06 20:57:50 +0000601 return success;
Jason Molenda705b1802014-06-13 02:37:02 +0000602}
603
Kate Stoneb9c1b512016-09-06 20:57:50 +0000604SBError SBThread::ResumeNewPlan(ExecutionContext &exe_ctx,
605 ThreadPlan *new_plan) {
606 SBError sb_error;
Jason Molenda705b1802014-06-13 02:37:02 +0000607
Kate Stoneb9c1b512016-09-06 20:57:50 +0000608 Process *process = exe_ctx.GetProcessPtr();
609 if (!process) {
610 sb_error.SetErrorString("No process in SBThread::ResumeNewPlan");
Jim Ingham64e7ead2012-05-03 21:19:36 +0000611 return sb_error;
Kate Stoneb9c1b512016-09-06 20:57:50 +0000612 }
613
614 Thread *thread = exe_ctx.GetThreadPtr();
615 if (!thread) {
616 sb_error.SetErrorString("No thread in SBThread::ResumeNewPlan");
617 return sb_error;
618 }
619
620 // User level plans should be Master Plans so they can be interrupted, other
621 // plans executed, and
622 // then a "continue" will resume the plan.
623 if (new_plan != NULL) {
624 new_plan->SetIsMasterPlan(true);
625 new_plan->SetOkayToDiscard(false);
626 }
627
628 // Why do we need to set the current thread by ID here???
629 process->GetThreadList().SetSelectedThreadByID(thread->GetID());
630
631 if (process->GetTarget().GetDebugger().GetAsyncExecution())
632 sb_error.ref() = process->Resume();
633 else
634 sb_error.ref() = process->ResumeSynchronous(NULL);
635
636 return sb_error;
Jim Ingham64e7ead2012-05-03 21:19:36 +0000637}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000638
Kate Stoneb9c1b512016-09-06 20:57:50 +0000639void SBThread::StepOver(lldb::RunMode stop_other_threads) {
640 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000641
Kate Stoneb9c1b512016-09-06 20:57:50 +0000642 std::unique_lock<std::recursive_mutex> lock;
643 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
Caroline Ticeceb6b132010-10-26 03:11:13 +0000644
Kate Stoneb9c1b512016-09-06 20:57:50 +0000645 if (log)
646 log->Printf("SBThread(%p)::StepOver (stop_other_threads='%s')",
647 static_cast<void *>(exe_ctx.GetThreadPtr()),
648 Thread::RunModeAsCString(stop_other_threads));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000649
Kate Stoneb9c1b512016-09-06 20:57:50 +0000650 if (exe_ctx.HasThreadScope()) {
651 Thread *thread = exe_ctx.GetThreadPtr();
652 bool abort_other_plans = false;
653 StackFrameSP frame_sp(thread->GetStackFrameAtIndex(0));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000654
Kate Stoneb9c1b512016-09-06 20:57:50 +0000655 ThreadPlanSP new_plan_sp;
656 if (frame_sp) {
657 if (frame_sp->HasDebugInformation()) {
Jim Ingham4b4b2472014-03-13 02:47:14 +0000658 const LazyBool avoid_no_debug = eLazyBoolCalculate;
Kate Stoneb9c1b512016-09-06 20:57:50 +0000659 SymbolContext sc(frame_sp->GetSymbolContext(eSymbolContextEverything));
660 new_plan_sp = thread->QueueThreadPlanForStepOverRange(
661 abort_other_plans, sc.line_entry, sc, stop_other_threads,
662 avoid_no_debug);
663 } else {
664 new_plan_sp = thread->QueueThreadPlanForStepSingleInstruction(
665 true, abort_other_plans, stop_other_threads);
666 }
Greg Clayton481cef22011-01-21 06:11:58 +0000667 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000668
669 // This returns an error, we should use it!
670 ResumeNewPlan(exe_ctx, new_plan_sp.get());
671 }
Greg Clayton481cef22011-01-21 06:11:58 +0000672}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000673
Kate Stoneb9c1b512016-09-06 20:57:50 +0000674void SBThread::StepInto(lldb::RunMode stop_other_threads) {
675 StepInto(NULL, stop_other_threads);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000676}
677
Kate Stoneb9c1b512016-09-06 20:57:50 +0000678void SBThread::StepInto(const char *target_name,
679 lldb::RunMode stop_other_threads) {
680 SBError error;
681 StepInto(target_name, LLDB_INVALID_LINE_NUMBER, error, stop_other_threads);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000682}
683
Kate Stoneb9c1b512016-09-06 20:57:50 +0000684void SBThread::StepInto(const char *target_name, uint32_t end_line,
685 SBError &error, lldb::RunMode stop_other_threads) {
686 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000687
Kate Stoneb9c1b512016-09-06 20:57:50 +0000688 std::unique_lock<std::recursive_mutex> lock;
689 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
Caroline Ticeceb6b132010-10-26 03:11:13 +0000690
Kate Stoneb9c1b512016-09-06 20:57:50 +0000691 if (log)
692 log->Printf(
693 "SBThread(%p)::StepInto (target_name='%s', stop_other_threads='%s')",
694 static_cast<void *>(exe_ctx.GetThreadPtr()),
695 target_name ? target_name : "<NULL>",
696 Thread::RunModeAsCString(stop_other_threads));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000697
Kate Stoneb9c1b512016-09-06 20:57:50 +0000698 if (exe_ctx.HasThreadScope()) {
699 bool abort_other_plans = false;
Jim Ingham2bdbfd52014-09-29 23:17:18 +0000700
701 Thread *thread = exe_ctx.GetThreadPtr();
Kate Stoneb9c1b512016-09-06 20:57:50 +0000702 StackFrameSP frame_sp(thread->GetStackFrameAtIndex(0));
703 ThreadPlanSP new_plan_sp;
Jim Ingham2bdbfd52014-09-29 23:17:18 +0000704
Kate Stoneb9c1b512016-09-06 20:57:50 +0000705 if (frame_sp && frame_sp->HasDebugInformation()) {
706 SymbolContext sc(frame_sp->GetSymbolContext(eSymbolContextEverything));
707 AddressRange range;
708 if (end_line == LLDB_INVALID_LINE_NUMBER)
709 range = sc.line_entry.range;
710 else {
711 if (!sc.GetAddressRangeFromHereToEndLine(end_line, range, error.ref()))
712 return;
713 }
714
715 const LazyBool step_out_avoids_code_without_debug_info =
716 eLazyBoolCalculate;
717 const LazyBool step_in_avoids_code_without_debug_info =
718 eLazyBoolCalculate;
719 new_plan_sp = thread->QueueThreadPlanForStepInRange(
720 abort_other_plans, range, sc, target_name, stop_other_threads,
721 step_in_avoids_code_without_debug_info,
722 step_out_avoids_code_without_debug_info);
723 } else {
724 new_plan_sp = thread->QueueThreadPlanForStepSingleInstruction(
725 false, abort_other_plans, stop_other_threads);
Jim Ingham2bdbfd52014-09-29 23:17:18 +0000726 }
727
Kate Stoneb9c1b512016-09-06 20:57:50 +0000728 error = ResumeNewPlan(exe_ctx, new_plan_sp.get());
729 }
Jim Ingham2bdbfd52014-09-29 23:17:18 +0000730}
731
Kate Stoneb9c1b512016-09-06 20:57:50 +0000732void SBThread::StepOut() {
733 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
Richard Mittonf86248d2013-09-12 02:20:34 +0000734
Kate Stoneb9c1b512016-09-06 20:57:50 +0000735 std::unique_lock<std::recursive_mutex> lock;
736 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
Richard Mittonf86248d2013-09-12 02:20:34 +0000737
Kate Stoneb9c1b512016-09-06 20:57:50 +0000738 if (log)
739 log->Printf("SBThread(%p)::StepOut ()",
740 static_cast<void *>(exe_ctx.GetThreadPtr()));
Richard Mittonf86248d2013-09-12 02:20:34 +0000741
Kate Stoneb9c1b512016-09-06 20:57:50 +0000742 if (exe_ctx.HasThreadScope()) {
743 bool abort_other_plans = false;
744 bool stop_other_threads = false;
Richard Mittonf86248d2013-09-12 02:20:34 +0000745
746 Thread *thread = exe_ctx.GetThreadPtr();
747
Kate Stoneb9c1b512016-09-06 20:57:50 +0000748 const LazyBool avoid_no_debug = eLazyBoolCalculate;
749 ThreadPlanSP new_plan_sp(thread->QueueThreadPlanForStepOut(
750 abort_other_plans, NULL, false, stop_other_threads, eVoteYes,
751 eVoteNoOpinion, 0, avoid_no_debug));
752
753 // This returns an error, we should use it!
754 ResumeNewPlan(exe_ctx, new_plan_sp.get());
755 }
756}
757
758void SBThread::StepOutOfFrame(lldb::SBFrame &sb_frame) {
759 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
760
761 std::unique_lock<std::recursive_mutex> lock;
762 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
763
764 if (!sb_frame.IsValid()) {
765 if (log)
766 log->Printf(
767 "SBThread(%p)::StepOutOfFrame passed an invalid frame, returning.",
768 static_cast<void *>(exe_ctx.GetThreadPtr()));
769 return;
770 }
771
772 StackFrameSP frame_sp(sb_frame.GetFrameSP());
773 if (log) {
774 SBStream frame_desc_strm;
775 sb_frame.GetDescription(frame_desc_strm);
776 log->Printf("SBThread(%p)::StepOutOfFrame (frame = SBFrame(%p): %s)",
777 static_cast<void *>(exe_ctx.GetThreadPtr()),
778 static_cast<void *>(frame_sp.get()), frame_desc_strm.GetData());
779 }
780
781 if (exe_ctx.HasThreadScope()) {
782 bool abort_other_plans = false;
783 bool stop_other_threads = false;
784 Thread *thread = exe_ctx.GetThreadPtr();
785 if (sb_frame.GetThread().GetThreadID() != thread->GetID()) {
786 log->Printf("SBThread(%p)::StepOutOfFrame passed a frame from another "
787 "thread (0x%" PRIx64 " vrs. 0x%" PRIx64 ", returning.",
788 static_cast<void *>(exe_ctx.GetThreadPtr()),
789 sb_frame.GetThread().GetThreadID(), thread->GetID());
790 }
791
792 ThreadPlanSP new_plan_sp(thread->QueueThreadPlanForStepOut(
793 abort_other_plans, NULL, false, stop_other_threads, eVoteYes,
794 eVoteNoOpinion, frame_sp->GetFrameIndex()));
795
796 // This returns an error, we should use it!
797 ResumeNewPlan(exe_ctx, new_plan_sp.get());
798 }
799}
800
801void SBThread::StepInstruction(bool step_over) {
802 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
803
804 std::unique_lock<std::recursive_mutex> lock;
805 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
806
807 if (log)
808 log->Printf("SBThread(%p)::StepInstruction (step_over=%i)",
809 static_cast<void *>(exe_ctx.GetThreadPtr()), step_over);
810
811 if (exe_ctx.HasThreadScope()) {
812 Thread *thread = exe_ctx.GetThreadPtr();
813 ThreadPlanSP new_plan_sp(
814 thread->QueueThreadPlanForStepSingleInstruction(step_over, true, true));
815
816 // This returns an error, we should use it!
817 ResumeNewPlan(exe_ctx, new_plan_sp.get());
818 }
819}
820
821void SBThread::RunToAddress(lldb::addr_t addr) {
822 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
823
824 std::unique_lock<std::recursive_mutex> lock;
825 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
826
827 if (log)
828 log->Printf("SBThread(%p)::RunToAddress (addr=0x%" PRIx64 ")",
829 static_cast<void *>(exe_ctx.GetThreadPtr()), addr);
830
831 if (exe_ctx.HasThreadScope()) {
832 bool abort_other_plans = false;
833 bool stop_other_threads = true;
834
835 Address target_addr(addr);
836
837 Thread *thread = exe_ctx.GetThreadPtr();
838
839 ThreadPlanSP new_plan_sp(thread->QueueThreadPlanForRunToAddress(
840 abort_other_plans, target_addr, stop_other_threads));
841
842 // This returns an error, we should use it!
843 ResumeNewPlan(exe_ctx, new_plan_sp.get());
844 }
845}
846
847SBError SBThread::StepOverUntil(lldb::SBFrame &sb_frame,
848 lldb::SBFileSpec &sb_file_spec, uint32_t line) {
849 SBError sb_error;
850 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
851 char path[PATH_MAX];
852
853 std::unique_lock<std::recursive_mutex> lock;
854 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
855
856 StackFrameSP frame_sp(sb_frame.GetFrameSP());
857
858 if (log) {
859 SBStream frame_desc_strm;
860 sb_frame.GetDescription(frame_desc_strm);
861 sb_file_spec->GetPath(path, sizeof(path));
862 log->Printf("SBThread(%p)::StepOverUntil (frame = SBFrame(%p): %s, "
863 "file+line = %s:%u)",
864 static_cast<void *>(exe_ctx.GetThreadPtr()),
865 static_cast<void *>(frame_sp.get()), frame_desc_strm.GetData(),
866 path, line);
867 }
868
869 if (exe_ctx.HasThreadScope()) {
870 Target *target = exe_ctx.GetTargetPtr();
871 Thread *thread = exe_ctx.GetThreadPtr();
872
873 if (line == 0) {
874 sb_error.SetErrorString("invalid line argument");
875 return sb_error;
876 }
877
878 if (!frame_sp) {
879 frame_sp = thread->GetSelectedFrame();
880 if (!frame_sp)
881 frame_sp = thread->GetStackFrameAtIndex(0);
882 }
883
884 SymbolContext frame_sc;
885 if (!frame_sp) {
886 sb_error.SetErrorString("no valid frames in thread to step");
887 return sb_error;
888 }
889
890 // If we have a frame, get its line
891 frame_sc = frame_sp->GetSymbolContext(
892 eSymbolContextCompUnit | eSymbolContextFunction |
893 eSymbolContextLineEntry | eSymbolContextSymbol);
894
895 if (frame_sc.comp_unit == NULL) {
896 sb_error.SetErrorStringWithFormat(
897 "frame %u doesn't have debug information", frame_sp->GetFrameIndex());
898 return sb_error;
899 }
900
901 FileSpec step_file_spec;
902 if (sb_file_spec.IsValid()) {
903 // The file spec passed in was valid, so use it
904 step_file_spec = sb_file_spec.ref();
905 } else {
906 if (frame_sc.line_entry.IsValid())
907 step_file_spec = frame_sc.line_entry.file;
908 else {
909 sb_error.SetErrorString("invalid file argument or no file for frame");
910 return sb_error;
911 }
912 }
913
914 // Grab the current function, then we will make sure the "until" address is
915 // within the function. We discard addresses that are out of the current
916 // function, and then if there are no addresses remaining, give an
917 // appropriate
918 // error message.
919
920 bool all_in_function = true;
921 AddressRange fun_range = frame_sc.function->GetAddressRange();
922
923 std::vector<addr_t> step_over_until_addrs;
924 const bool abort_other_plans = false;
925 const bool stop_other_threads = false;
926 const bool check_inlines = true;
927 const bool exact = false;
928
929 SymbolContextList sc_list;
930 const uint32_t num_matches = frame_sc.comp_unit->ResolveSymbolContext(
931 step_file_spec, line, check_inlines, exact, eSymbolContextLineEntry,
932 sc_list);
933 if (num_matches > 0) {
934 SymbolContext sc;
935 for (uint32_t i = 0; i < num_matches; ++i) {
936 if (sc_list.GetContextAtIndex(i, sc)) {
937 addr_t step_addr =
938 sc.line_entry.range.GetBaseAddress().GetLoadAddress(target);
939 if (step_addr != LLDB_INVALID_ADDRESS) {
940 if (fun_range.ContainsLoadAddress(step_addr, target))
941 step_over_until_addrs.push_back(step_addr);
942 else
943 all_in_function = false;
944 }
945 }
946 }
947 }
948
949 if (step_over_until_addrs.empty()) {
950 if (all_in_function) {
951 step_file_spec.GetPath(path, sizeof(path));
952 sb_error.SetErrorStringWithFormat("No line entries for %s:%u", path,
953 line);
954 } else
955 sb_error.SetErrorString("step until target not in current function");
956 } else {
957 ThreadPlanSP new_plan_sp(thread->QueueThreadPlanForStepUntil(
958 abort_other_plans, &step_over_until_addrs[0],
959 step_over_until_addrs.size(), stop_other_threads,
960 frame_sp->GetFrameIndex()));
961
962 sb_error = ResumeNewPlan(exe_ctx, new_plan_sp.get());
963 }
964 } else {
965 sb_error.SetErrorString("this SBThread object is invalid");
966 }
967 return sb_error;
968}
969
970SBError SBThread::StepUsingScriptedThreadPlan(const char *script_class_name) {
971 return StepUsingScriptedThreadPlan(script_class_name, true);
972}
973
974SBError SBThread::StepUsingScriptedThreadPlan(const char *script_class_name,
975 bool resume_immediately) {
976 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
977 SBError sb_error;
978
979 std::unique_lock<std::recursive_mutex> lock;
980 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
981
982 if (log) {
983 log->Printf("SBThread(%p)::StepUsingScriptedThreadPlan: class name: %s",
984 static_cast<void *>(exe_ctx.GetThreadPtr()), script_class_name);
985 }
986
987 if (!exe_ctx.HasThreadScope()) {
988 sb_error.SetErrorString("this SBThread object is invalid");
Richard Mittonf86248d2013-09-12 02:20:34 +0000989 return sb_error;
Kate Stoneb9c1b512016-09-06 20:57:50 +0000990 }
Richard Mittonf86248d2013-09-12 02:20:34 +0000991
Kate Stoneb9c1b512016-09-06 20:57:50 +0000992 Thread *thread = exe_ctx.GetThreadPtr();
993 ThreadPlanSP thread_plan_sp =
994 thread->QueueThreadPlanForStepScripted(false, script_class_name, false);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000995
Kate Stoneb9c1b512016-09-06 20:57:50 +0000996 if (!thread_plan_sp) {
997 sb_error.SetErrorStringWithFormat(
998 "Error queueing thread plan for class: %s", script_class_name);
Jim Ingham44137582012-09-12 00:40:39 +0000999 return sb_error;
Kate Stoneb9c1b512016-09-06 20:57:50 +00001000 }
Jim Ingham44137582012-09-12 00:40:39 +00001001
Kate Stoneb9c1b512016-09-06 20:57:50 +00001002 if (!resume_immediately) {
Jim Ingham4ac8e932016-07-08 02:12:05 +00001003 return sb_error;
Kate Stoneb9c1b512016-09-06 20:57:50 +00001004 }
Jim Ingham4ac8e932016-07-08 02:12:05 +00001005
Kate Stoneb9c1b512016-09-06 20:57:50 +00001006 if (thread_plan_sp)
1007 sb_error = ResumeNewPlan(exe_ctx, thread_plan_sp.get());
1008 else {
1009 sb_error.SetErrorStringWithFormat(
1010 "Error resuming thread plan for class: %s.", script_class_name);
Greg Claytonc9858e42012-04-06 02:17:47 +00001011 if (log)
Kate Stoneb9c1b512016-09-06 20:57:50 +00001012 log->Printf("SBThread(%p)::StepUsingScriptedThreadPlan: Error queuing "
1013 "thread plan for class: %s",
1014 static_cast<void *>(exe_ctx.GetThreadPtr()),
1015 script_class_name);
1016 }
1017
1018 return sb_error;
Greg Clayton722a0cd2011-01-12 02:25:42 +00001019}
1020
Kate Stoneb9c1b512016-09-06 20:57:50 +00001021SBError SBThread::JumpToLine(lldb::SBFileSpec &file_spec, uint32_t line) {
1022 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1023 SBError sb_error;
Jim Inghamb2e7d282016-06-10 17:22:26 +00001024
Kate Stoneb9c1b512016-09-06 20:57:50 +00001025 std::unique_lock<std::recursive_mutex> lock;
1026 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
1027
1028 if (log)
1029 log->Printf("SBThread(%p)::JumpToLine (file+line = %s:%u)",
1030 static_cast<void *>(exe_ctx.GetThreadPtr()),
1031 file_spec->GetPath().c_str(), line);
1032
1033 if (!exe_ctx.HasThreadScope()) {
1034 sb_error.SetErrorString("this SBThread object is invalid");
1035 return sb_error;
1036 }
1037
1038 Thread *thread = exe_ctx.GetThreadPtr();
1039
1040 Error err = thread->JumpToLine(file_spec.get(), line, true);
1041 sb_error.SetError(err);
1042 return sb_error;
Greg Clayton722a0cd2011-01-12 02:25:42 +00001043}
1044
Kate Stoneb9c1b512016-09-06 20:57:50 +00001045SBError SBThread::ReturnFromFrame(SBFrame &frame, SBValue &return_value) {
1046 SBError sb_error;
Jim Inghamb2e7d282016-06-10 17:22:26 +00001047
Kate Stoneb9c1b512016-09-06 20:57:50 +00001048 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1049
1050 std::unique_lock<std::recursive_mutex> lock;
1051 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
1052
1053 if (log)
1054 log->Printf("SBThread(%p)::ReturnFromFrame (frame=%d)",
1055 static_cast<void *>(exe_ctx.GetThreadPtr()),
1056 frame.GetFrameID());
1057
1058 if (exe_ctx.HasThreadScope()) {
1059 Thread *thread = exe_ctx.GetThreadPtr();
1060 sb_error.SetError(
1061 thread->ReturnFromFrame(frame.GetFrameSP(), return_value.GetSP()));
1062 }
1063
1064 return sb_error;
Greg Clayton722a0cd2011-01-12 02:25:42 +00001065}
1066
Kate Stoneb9c1b512016-09-06 20:57:50 +00001067SBError SBThread::UnwindInnermostExpression() {
1068 SBError sb_error;
Jim Inghamb2e7d282016-06-10 17:22:26 +00001069
Kate Stoneb9c1b512016-09-06 20:57:50 +00001070 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1071
1072 std::unique_lock<std::recursive_mutex> lock;
1073 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
1074
1075 if (log)
1076 log->Printf("SBThread(%p)::UnwindExpressionEvaluation",
1077 static_cast<void *>(exe_ctx.GetThreadPtr()));
1078
1079 if (exe_ctx.HasThreadScope()) {
1080 Thread *thread = exe_ctx.GetThreadPtr();
1081 sb_error.SetError(thread->UnwindInnermostExpression());
1082 if (sb_error.Success())
1083 thread->SetSelectedFrameByIndex(0, false);
1084 }
1085
1086 return sb_error;
Andrew Kaylora75418d2013-04-15 23:33:53 +00001087}
1088
Kate Stoneb9c1b512016-09-06 20:57:50 +00001089bool SBThread::Suspend() {
1090 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1091 std::unique_lock<std::recursive_mutex> lock;
1092 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
Jim Inghamb2e7d282016-06-10 17:22:26 +00001093
Kate Stoneb9c1b512016-09-06 20:57:50 +00001094 bool result = false;
1095 if (exe_ctx.HasThreadScope()) {
1096 Process::StopLocker stop_locker;
1097 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock())) {
1098 exe_ctx.GetThreadPtr()->SetResumeState(eStateSuspended);
1099 result = true;
1100 } else {
1101 if (log)
1102 log->Printf("SBThread(%p)::Suspend() => error: process is running",
1103 static_cast<void *>(exe_ctx.GetThreadPtr()));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001104 }
Kate Stoneb9c1b512016-09-06 20:57:50 +00001105 }
1106 if (log)
1107 log->Printf("SBThread(%p)::Suspend() => %i",
1108 static_cast<void *>(exe_ctx.GetThreadPtr()), result);
1109 return result;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001110}
1111
Kate Stoneb9c1b512016-09-06 20:57:50 +00001112bool SBThread::Resume() {
1113 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1114 std::unique_lock<std::recursive_mutex> lock;
1115 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
Caroline Ticeceb6b132010-10-26 03:11:13 +00001116
Kate Stoneb9c1b512016-09-06 20:57:50 +00001117 bool result = false;
1118 if (exe_ctx.HasThreadScope()) {
1119 Process::StopLocker stop_locker;
1120 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock())) {
1121 const bool override_suspend = true;
1122 exe_ctx.GetThreadPtr()->SetResumeState(eStateRunning, override_suspend);
1123 result = true;
1124 } else {
1125 if (log)
1126 log->Printf("SBThread(%p)::Resume() => error: process is running",
1127 static_cast<void *>(exe_ctx.GetThreadPtr()));
Greg Claytonaf67cec2010-12-20 20:49:23 +00001128 }
Kate Stoneb9c1b512016-09-06 20:57:50 +00001129 }
1130 if (log)
1131 log->Printf("SBThread(%p)::Resume() => %i",
1132 static_cast<void *>(exe_ctx.GetThreadPtr()), result);
1133 return result;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001134}
1135
Kate Stoneb9c1b512016-09-06 20:57:50 +00001136bool SBThread::IsSuspended() {
1137 std::unique_lock<std::recursive_mutex> lock;
1138 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
Caroline Ticeceb6b132010-10-26 03:11:13 +00001139
Kate Stoneb9c1b512016-09-06 20:57:50 +00001140 if (exe_ctx.HasThreadScope())
1141 return exe_ctx.GetThreadPtr()->GetResumeState() == eStateSuspended;
1142 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001143}
1144
Kate Stoneb9c1b512016-09-06 20:57:50 +00001145bool SBThread::IsStopped() {
1146 std::unique_lock<std::recursive_mutex> lock;
1147 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
Greg Claytonf028a1f2010-12-17 02:26:24 +00001148
Kate Stoneb9c1b512016-09-06 20:57:50 +00001149 if (exe_ctx.HasThreadScope())
1150 return StateIsStoppedState(exe_ctx.GetThreadPtr()->GetState(), true);
1151 return false;
Greg Claytonf028a1f2010-12-17 02:26:24 +00001152}
1153
Kate Stoneb9c1b512016-09-06 20:57:50 +00001154SBProcess SBThread::GetProcess() {
1155 SBProcess sb_process;
1156 std::unique_lock<std::recursive_mutex> lock;
1157 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
Greg Claytonf028a1f2010-12-17 02:26:24 +00001158
Kate Stoneb9c1b512016-09-06 20:57:50 +00001159 if (exe_ctx.HasThreadScope()) {
1160 // Have to go up to the target so we can get a shared pointer to our
1161 // process...
1162 sb_process.SetSP(exe_ctx.GetProcessSP());
1163 }
Jim Ingham4fc6cb92012-08-22 21:34:33 +00001164
Kate Stoneb9c1b512016-09-06 20:57:50 +00001165 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1166 if (log) {
1167 SBStream frame_desc_strm;
1168 sb_process.GetDescription(frame_desc_strm);
1169 log->Printf("SBThread(%p)::GetProcess () => SBProcess(%p): %s",
1170 static_cast<void *>(exe_ctx.GetThreadPtr()),
1171 static_cast<void *>(sb_process.GetSP().get()),
1172 frame_desc_strm.GetData());
1173 }
1174
1175 return sb_process;
1176}
1177
1178uint32_t SBThread::GetNumFrames() {
1179 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1180
1181 uint32_t num_frames = 0;
1182 std::unique_lock<std::recursive_mutex> lock;
1183 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
1184
1185 if (exe_ctx.HasThreadScope()) {
1186 Process::StopLocker stop_locker;
1187 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock())) {
1188 num_frames = exe_ctx.GetThreadPtr()->GetStackFrameCount();
1189 } else {
1190 if (log)
1191 log->Printf("SBThread(%p)::GetNumFrames() => error: process is running",
1192 static_cast<void *>(exe_ctx.GetThreadPtr()));
1193 }
1194 }
1195
1196 if (log)
1197 log->Printf("SBThread(%p)::GetNumFrames () => %u",
1198 static_cast<void *>(exe_ctx.GetThreadPtr()), num_frames);
1199
1200 return num_frames;
1201}
1202
1203SBFrame SBThread::GetFrameAtIndex(uint32_t idx) {
1204 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1205
1206 SBFrame sb_frame;
1207 StackFrameSP frame_sp;
1208 std::unique_lock<std::recursive_mutex> lock;
1209 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
1210
1211 if (exe_ctx.HasThreadScope()) {
1212 Process::StopLocker stop_locker;
1213 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock())) {
1214 frame_sp = exe_ctx.GetThreadPtr()->GetStackFrameAtIndex(idx);
1215 sb_frame.SetFrameSP(frame_sp);
1216 } else {
1217 if (log)
1218 log->Printf(
1219 "SBThread(%p)::GetFrameAtIndex() => error: process is running",
1220 static_cast<void *>(exe_ctx.GetThreadPtr()));
1221 }
1222 }
1223
1224 if (log) {
1225 SBStream frame_desc_strm;
1226 sb_frame.GetDescription(frame_desc_strm);
1227 log->Printf("SBThread(%p)::GetFrameAtIndex (idx=%d) => SBFrame(%p): %s",
1228 static_cast<void *>(exe_ctx.GetThreadPtr()), idx,
1229 static_cast<void *>(frame_sp.get()), frame_desc_strm.GetData());
1230 }
1231
1232 return sb_frame;
1233}
1234
1235lldb::SBFrame SBThread::GetSelectedFrame() {
1236 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1237
1238 SBFrame sb_frame;
1239 StackFrameSP frame_sp;
1240 std::unique_lock<std::recursive_mutex> lock;
1241 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
1242
1243 if (exe_ctx.HasThreadScope()) {
1244 Process::StopLocker stop_locker;
1245 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock())) {
1246 frame_sp = exe_ctx.GetThreadPtr()->GetSelectedFrame();
1247 sb_frame.SetFrameSP(frame_sp);
1248 } else {
1249 if (log)
1250 log->Printf(
1251 "SBThread(%p)::GetSelectedFrame() => error: process is running",
1252 static_cast<void *>(exe_ctx.GetThreadPtr()));
1253 }
1254 }
1255
1256 if (log) {
1257 SBStream frame_desc_strm;
1258 sb_frame.GetDescription(frame_desc_strm);
1259 log->Printf("SBThread(%p)::GetSelectedFrame () => SBFrame(%p): %s",
1260 static_cast<void *>(exe_ctx.GetThreadPtr()),
1261 static_cast<void *>(frame_sp.get()), frame_desc_strm.GetData());
1262 }
1263
1264 return sb_frame;
1265}
1266
1267lldb::SBFrame SBThread::SetSelectedFrame(uint32_t idx) {
1268 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1269
1270 SBFrame sb_frame;
1271 StackFrameSP frame_sp;
1272 std::unique_lock<std::recursive_mutex> lock;
1273 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
1274
1275 if (exe_ctx.HasThreadScope()) {
1276 Process::StopLocker stop_locker;
1277 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock())) {
1278 Thread *thread = exe_ctx.GetThreadPtr();
1279 frame_sp = thread->GetStackFrameAtIndex(idx);
1280 if (frame_sp) {
1281 thread->SetSelectedFrame(frame_sp.get());
1282 sb_frame.SetFrameSP(frame_sp);
1283 }
1284 } else {
1285 if (log)
1286 log->Printf(
1287 "SBThread(%p)::SetSelectedFrame() => error: process is running",
1288 static_cast<void *>(exe_ctx.GetThreadPtr()));
1289 }
1290 }
1291
1292 if (log) {
1293 SBStream frame_desc_strm;
1294 sb_frame.GetDescription(frame_desc_strm);
1295 log->Printf("SBThread(%p)::SetSelectedFrame (idx=%u) => SBFrame(%p): %s",
1296 static_cast<void *>(exe_ctx.GetThreadPtr()), idx,
1297 static_cast<void *>(frame_sp.get()), frame_desc_strm.GetData());
1298 }
1299 return sb_frame;
1300}
1301
1302bool SBThread::EventIsThreadEvent(const SBEvent &event) {
1303 return Thread::ThreadEventData::GetEventDataFromEvent(event.get()) != NULL;
1304}
1305
1306SBFrame SBThread::GetStackFrameFromEvent(const SBEvent &event) {
1307 return Thread::ThreadEventData::GetStackFrameFromEvent(event.get());
1308}
1309
1310SBThread SBThread::GetThreadFromEvent(const SBEvent &event) {
1311 return Thread::ThreadEventData::GetThreadFromEvent(event.get());
1312}
1313
1314bool SBThread::operator==(const SBThread &rhs) const {
1315 return m_opaque_sp->GetThreadSP().get() ==
1316 rhs.m_opaque_sp->GetThreadSP().get();
1317}
1318
1319bool SBThread::operator!=(const SBThread &rhs) const {
1320 return m_opaque_sp->GetThreadSP().get() !=
1321 rhs.m_opaque_sp->GetThreadSP().get();
1322}
1323
1324bool SBThread::GetStatus(SBStream &status) const {
1325 Stream &strm = status.ref();
1326
1327 std::unique_lock<std::recursive_mutex> lock;
1328 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
1329
1330 if (exe_ctx.HasThreadScope()) {
Jim Ingham6a9767c2016-11-08 20:36:40 +00001331 exe_ctx.GetThreadPtr()->GetStatus(strm, 0, 1, 1, true);
Kate Stoneb9c1b512016-09-06 20:57:50 +00001332 } else
1333 strm.PutCString("No status");
1334
1335 return true;
1336}
1337
1338bool SBThread::GetDescription(SBStream &description) const {
Jim Ingham6a9767c2016-11-08 20:36:40 +00001339 return GetDescription(description, false);
1340}
1341
1342bool SBThread::GetDescription(SBStream &description, bool stop_format) const {
Kate Stoneb9c1b512016-09-06 20:57:50 +00001343 Stream &strm = description.ref();
1344
1345 std::unique_lock<std::recursive_mutex> lock;
1346 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
1347
1348 if (exe_ctx.HasThreadScope()) {
1349 exe_ctx.GetThreadPtr()->DumpUsingSettingsFormat(strm,
Jim Ingham6a9767c2016-11-08 20:36:40 +00001350 LLDB_INVALID_THREAD_ID,
1351 stop_format);
Kate Stoneb9c1b512016-09-06 20:57:50 +00001352 // strm.Printf("SBThread: tid = 0x%4.4" PRIx64,
1353 // exe_ctx.GetThreadPtr()->GetID());
1354 } else
1355 strm.PutCString("No value");
1356
1357 return true;
1358}
1359
1360SBThread SBThread::GetExtendedBacktraceThread(const char *type) {
1361 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1362 std::unique_lock<std::recursive_mutex> lock;
1363 ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
1364 SBThread sb_origin_thread;
1365
1366 if (exe_ctx.HasThreadScope()) {
1367 Process::StopLocker stop_locker;
1368 if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock())) {
1369 ThreadSP real_thread(exe_ctx.GetThreadSP());
1370 if (real_thread) {
1371 ConstString type_const(type);
1372 Process *process = exe_ctx.GetProcessPtr();
1373 if (process) {
1374 SystemRuntime *runtime = process->GetSystemRuntime();
1375 if (runtime) {
1376 ThreadSP new_thread_sp(
1377 runtime->GetExtendedBacktraceThread(real_thread, type_const));
1378 if (new_thread_sp) {
1379 // Save this in the Process' ExtendedThreadList so a strong
1380 // pointer retains the
1381 // object.
1382 process->GetExtendedThreadList().AddThread(new_thread_sp);
1383 sb_origin_thread.SetThread(new_thread_sp);
1384 if (log) {
1385 const char *queue_name = new_thread_sp->GetQueueName();
1386 if (queue_name == NULL)
1387 queue_name = "";
1388 log->Printf("SBThread(%p)::GetExtendedBacktraceThread() => new "
1389 "extended Thread "
1390 "created (%p) with queue_id 0x%" PRIx64
1391 " queue name '%s'",
1392 static_cast<void *>(exe_ctx.GetThreadPtr()),
1393 static_cast<void *>(new_thread_sp.get()),
1394 new_thread_sp->GetQueueID(), queue_name);
1395 }
Greg Clayton7fdf9ef2012-04-05 16:12:35 +00001396 }
Kate Stoneb9c1b512016-09-06 20:57:50 +00001397 }
Greg Claytonf028a1f2010-12-17 02:26:24 +00001398 }
Kate Stoneb9c1b512016-09-06 20:57:50 +00001399 }
1400 } else {
1401 if (log)
1402 log->Printf("SBThread(%p)::GetExtendedBacktraceThread() => error: "
1403 "process is running",
1404 static_cast<void *>(exe_ctx.GetThreadPtr()));
Greg Claytonf028a1f2010-12-17 02:26:24 +00001405 }
Kate Stoneb9c1b512016-09-06 20:57:50 +00001406 }
Greg Claytonf028a1f2010-12-17 02:26:24 +00001407
Kate Stoneb9c1b512016-09-06 20:57:50 +00001408 if (log && sb_origin_thread.IsValid() == false)
1409 log->Printf("SBThread(%p)::GetExtendedBacktraceThread() is not returning a "
1410 "Valid thread",
1411 static_cast<void *>(exe_ctx.GetThreadPtr()));
1412 return sb_origin_thread;
Greg Claytonf028a1f2010-12-17 02:26:24 +00001413}
1414
Kate Stoneb9c1b512016-09-06 20:57:50 +00001415uint32_t SBThread::GetExtendedBacktraceOriginatingIndexID() {
1416 ThreadSP thread_sp(m_opaque_sp->GetThreadSP());
1417 if (thread_sp)
1418 return thread_sp->GetExtendedBacktraceOriginatingIndexID();
1419 return LLDB_INVALID_INDEX32;
Jim Ingham4f465cf2012-10-10 18:32:14 +00001420}
1421
Kate Stoneb9c1b512016-09-06 20:57:50 +00001422bool SBThread::SafeToCallFunctions() {
1423 ThreadSP thread_sp(m_opaque_sp->GetThreadSP());
1424 if (thread_sp)
1425 return thread_sp->SafeToCallFunctions();
1426 return true;
Jim Ingham4f465cf2012-10-10 18:32:14 +00001427}
1428
Kate Stoneb9c1b512016-09-06 20:57:50 +00001429lldb_private::Thread *SBThread::operator->() {
1430 ThreadSP thread_sp(m_opaque_sp->GetThreadSP());
1431 if (thread_sp)
1432 return thread_sp.get();
1433 else
1434 return NULL;
Jim Ingham4f465cf2012-10-10 18:32:14 +00001435}
Greg Claytonf028a1f2010-12-17 02:26:24 +00001436
Kate Stoneb9c1b512016-09-06 20:57:50 +00001437lldb_private::Thread *SBThread::get() {
1438 ThreadSP thread_sp(m_opaque_sp->GetThreadSP());
1439 if (thread_sp)
1440 return thread_sp.get();
1441 else
1442 return NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001443}