Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1 | //===-- 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 Friedman | 4c5de69 | 2010-06-09 07:44:37 +0000 | [diff] [blame] | 10 | #include "lldb/API/SBThread.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 11 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 12 | #include "lldb/API/SBFileSpec.h" |
Caroline Tice | dde9cff | 2010-09-20 05:20:02 +0000 | [diff] [blame] | 13 | #include "lldb/API/SBStream.h" |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 14 | #include "lldb/API/SBSymbolContext.h" |
Greg Clayton | 4e78f60 | 2010-11-18 18:52:36 +0000 | [diff] [blame] | 15 | #include "lldb/Breakpoint/BreakpointLocation.h" |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 16 | #include "lldb/Core/Debugger.h" |
Andrew Kaylor | a75418d | 2013-04-15 23:33:53 +0000 | [diff] [blame] | 17 | #include "lldb/Core/State.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 18 | #include "lldb/Core/StreamFile.h" |
Jason Molenda | 705b180 | 2014-06-13 02:37:02 +0000 | [diff] [blame] | 19 | #include "lldb/Core/StructuredData.h" |
Zachary Turner | a78bd7f | 2015-03-03 23:11:11 +0000 | [diff] [blame] | 20 | #include "lldb/Core/ValueObject.h" |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 21 | #include "lldb/Interpreter/CommandInterpreter.h" |
Zachary Turner | 93749ab | 2015-03-03 21:51:25 +0000 | [diff] [blame] | 22 | #include "lldb/Symbol/CompileUnit.h" |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 23 | #include "lldb/Symbol/SymbolContext.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 24 | #include "lldb/Target/Process.h" |
Jason Molenda | b9ffa98 | 2014-04-25 00:01:15 +0000 | [diff] [blame] | 25 | #include "lldb/Target/Queue.h" |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 26 | #include "lldb/Target/StopInfo.h" |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 27 | #include "lldb/Target/SystemRuntime.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 28 | #include "lldb/Target/Target.h" |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 29 | #include "lldb/Target/Thread.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 30 | #include "lldb/Target/ThreadPlan.h" |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 31 | #include "lldb/Target/ThreadPlanStepInRange.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 32 | #include "lldb/Target/ThreadPlanStepInstruction.h" |
| 33 | #include "lldb/Target/ThreadPlanStepOut.h" |
| 34 | #include "lldb/Target/ThreadPlanStepRange.h" |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 35 | #include "lldb/Target/UnixSignals.h" |
Zachary Turner | bf9a773 | 2017-02-02 21:39:50 +0000 | [diff] [blame] | 36 | #include "lldb/Utility/Stream.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 37 | |
Eli Friedman | 4c5de69 | 2010-06-09 07:44:37 +0000 | [diff] [blame] | 38 | #include "lldb/API/SBAddress.h" |
Eli Friedman | 4c5de69 | 2010-06-09 07:44:37 +0000 | [diff] [blame] | 39 | #include "lldb/API/SBDebugger.h" |
Jim Ingham | 4f465cf | 2012-10-10 18:32:14 +0000 | [diff] [blame] | 40 | #include "lldb/API/SBEvent.h" |
Jim Ingham | 73ca05a | 2011-12-17 01:35:57 +0000 | [diff] [blame] | 41 | #include "lldb/API/SBFrame.h" |
Eli Friedman | 4c5de69 | 2010-06-09 07:44:37 +0000 | [diff] [blame] | 42 | #include "lldb/API/SBProcess.h" |
Kuba Brecka | 6a83143 | 2016-03-23 15:36:22 +0000 | [diff] [blame] | 43 | #include "lldb/API/SBThreadCollection.h" |
Jim Ingham | 2bdbfd5 | 2014-09-29 23:17:18 +0000 | [diff] [blame] | 44 | #include "lldb/API/SBThreadPlan.h" |
Jim Ingham | 73ca05a | 2011-12-17 01:35:57 +0000 | [diff] [blame] | 45 | #include "lldb/API/SBValue.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 46 | |
| 47 | using namespace lldb; |
| 48 | using namespace lldb_private; |
| 49 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 50 | const char *SBThread::GetBroadcasterClassName() { |
| 51 | return Thread::GetStaticBroadcasterClass().AsCString(); |
Jim Ingham | 4f465cf | 2012-10-10 18:32:14 +0000 | [diff] [blame] | 52 | } |
| 53 | |
Greg Clayton | cfd1ace | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 54 | //---------------------------------------------------------------------- |
| 55 | // Constructors |
| 56 | //---------------------------------------------------------------------- |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 57 | SBThread::SBThread() : m_opaque_sp(new ExecutionContextRef()) {} |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 58 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 59 | SBThread::SBThread(const ThreadSP &lldb_object_sp) |
| 60 | : m_opaque_sp(new ExecutionContextRef(lldb_object_sp)) {} |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 61 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 62 | SBThread::SBThread(const SBThread &rhs) |
| 63 | : m_opaque_sp(new ExecutionContextRef(*rhs.m_opaque_sp)) {} |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 64 | |
| 65 | //---------------------------------------------------------------------- |
Greg Clayton | cfd1ace | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 66 | // Assignment operator |
| 67 | //---------------------------------------------------------------------- |
| 68 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 69 | const lldb::SBThread &SBThread::operator=(const SBThread &rhs) { |
| 70 | if (this != &rhs) |
| 71 | *m_opaque_sp = *rhs.m_opaque_sp; |
| 72 | return *this; |
Greg Clayton | cfd1ace | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | //---------------------------------------------------------------------- |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 76 | // Destructor |
| 77 | //---------------------------------------------------------------------- |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 78 | SBThread::~SBThread() {} |
| 79 | |
| 80 | lldb::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 Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 107 | } |
| 108 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 109 | bool SBThread::IsValid() const { |
| 110 | std::unique_lock<std::recursive_mutex> lock; |
| 111 | ExecutionContext exe_ctx(m_opaque_sp.get(), lock); |
Jason Molenda | b9ffa98 | 2014-04-25 00:01:15 +0000 | [diff] [blame] | 112 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 113 | 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 | |
| 124 | void SBThread::Clear() { m_opaque_sp->Clear(); } |
| 125 | |
| 126 | StopReason 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 | |
| 153 | size_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 | |
| 206 | uint64_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 Molenda | b9ffa98 | 2014-04-25 00:01:15 +0000 | [diff] [blame] | 245 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 246 | } |
| 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 Molenda | b9ffa98 | 2014-04-25 00:01:15 +0000 | [diff] [blame] | 258 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 259 | } |
| 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 Molenda | b9ffa98 | 2014-04-25 00:01:15 +0000 | [diff] [blame] | 266 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 267 | } |
| 268 | return 0; |
Jason Molenda | b9ffa98 | 2014-04-25 00:01:15 +0000 | [diff] [blame] | 269 | } |
| 270 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 271 | bool SBThread::GetStopReasonExtendedInfoAsJSON(lldb::SBStream &stream) { |
| 272 | Stream &strm = stream.ref(); |
Jason Molenda | b9ffa98 | 2014-04-25 00:01:15 +0000 | [diff] [blame] | 273 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 274 | std::unique_lock<std::recursive_mutex> lock; |
| 275 | ExecutionContext exe_ctx(m_opaque_sp.get(), lock); |
Jim Ingham | 7fa7dc3 | 2016-05-07 00:54:56 +0000 | [diff] [blame] | 276 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 277 | if (!exe_ctx.HasThreadScope()) |
Jim Ingham | 7fa7dc3 | 2016-05-07 00:54:56 +0000 | [diff] [blame] | 278 | return false; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 279 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 280 | StopInfoSP stop_info = exe_ctx.GetThreadPtr()->GetStopInfo(); |
| 281 | StructuredData::ObjectSP info = stop_info->GetExtendedInfo(); |
| 282 | if (!info) |
| 283 | return false; |
Greg Clayton | 48e4254 | 2010-07-30 20:12:55 +0000 | [diff] [blame] | 284 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 285 | info->Dump(strm); |
Greg Clayton | 48e4254 | 2010-07-30 20:12:55 +0000 | [diff] [blame] | 286 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 287 | return true; |
Kuba Brecka | afdf842 | 2014-10-10 23:43:03 +0000 | [diff] [blame] | 288 | } |
| 289 | |
Kuba Brecka | 6a83143 | 2016-03-23 15:36:22 +0000 | [diff] [blame] | 290 | SBThreadCollection |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 291 | SBThread::GetStopReasonExtendedBacktraces(InstrumentationRuntimeType type) { |
| 292 | ThreadCollectionSP threads; |
| 293 | threads.reset(new ThreadCollection()); |
Jim Ingham | b2e7d28 | 2016-06-10 17:22:26 +0000 | [diff] [blame] | 294 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 295 | // 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 Brecka | 6a83143 | 2016-03-23 15:36:22 +0000 | [diff] [blame] | 314 | } |
| 315 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 316 | size_t SBThread::GetStopDescription(char *dst, size_t dst_len) { |
| 317 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 318 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 319 | std::unique_lock<std::recursive_mutex> lock; |
| 320 | ExecutionContext exe_ctx(m_opaque_sp.get(), lock); |
Jim Ingham | 4fc6cb9 | 2012-08-22 21:34:33 +0000 | [diff] [blame] | 321 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 322 | if (exe_ctx.HasThreadScope()) { |
| 323 | Process::StopLocker stop_locker; |
| 324 | if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock())) { |
Greg Clayton | 7fdf9ef | 2012-04-05 16:12:35 +0000 | [diff] [blame] | 325 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 326 | 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 Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 351 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 352 | 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 Clayton | 7fdf9ef | 2012-04-05 16:12:35 +0000 | [diff] [blame] | 357 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 358 | 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 Clayton | 7fdf9ef | 2012-04-05 16:12:35 +0000 | [diff] [blame] | 363 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 364 | 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 Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 373 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 374 | } 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 Clayton | c9858e4 | 2012-04-06 02:17:47 +0000 | [diff] [blame] | 398 | if (log) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 399 | 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 Clayton | c9858e4 | 2012-04-06 02:17:47 +0000 | [diff] [blame] | 412 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 413 | } |
| 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 Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 420 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 421 | } |
| 422 | if (dst) |
| 423 | *dst = 0; |
| 424 | return 0; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 425 | } |
| 426 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 427 | SBValue 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 Ingham | 4fc6cb9 | 2012-08-22 21:34:33 +0000 | [diff] [blame] | 432 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 433 | 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 Ingham | 73ca05a | 2011-12-17 01:35:57 +0000 | [diff] [blame] | 445 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 446 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 447 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 448 | 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 Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 453 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 454 | return SBValue(return_valobj_sp); |
Jim Ingham | 73ca05a | 2011-12-17 01:35:57 +0000 | [diff] [blame] | 455 | } |
| 456 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 457 | void SBThread::SetThread(const ThreadSP &lldb_object_sp) { |
| 458 | m_opaque_sp->SetThreadSP(lldb_object_sp); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 459 | } |
| 460 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 461 | lldb::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 Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 466 | } |
| 467 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 468 | uint32_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 Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 473 | } |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 474 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 475 | const 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 Ingham | 4fc6cb9 | 2012-08-22 21:34:33 +0000 | [diff] [blame] | 480 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 481 | 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 Clayton | af67cec | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 489 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 490 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 491 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 492 | if (log) |
| 493 | log->Printf("SBThread(%p)::GetName () => %s", |
| 494 | static_cast<void *>(exe_ctx.GetThreadPtr()), |
| 495 | name ? name : "NULL"); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 496 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 497 | return name; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 498 | } |
| 499 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 500 | const 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 Ingham | 4fc6cb9 | 2012-08-22 21:34:33 +0000 | [diff] [blame] | 504 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 505 | 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 Clayton | af67cec | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 514 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 515 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 516 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 517 | if (log) |
| 518 | log->Printf("SBThread(%p)::GetQueueName () => %s", |
| 519 | static_cast<void *>(exe_ctx.GetThreadPtr()), |
| 520 | name ? name : "NULL"); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 521 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 522 | return name; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 523 | } |
| 524 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 525 | lldb::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 Molenda | 4fdb586 | 2013-10-21 23:52:54 +0000 | [diff] [blame] | 529 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 530 | 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 Molenda | 4fdb586 | 2013-10-21 23:52:54 +0000 | [diff] [blame] | 539 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 540 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 541 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 542 | if (log) |
| 543 | log->Printf("SBThread(%p)::GetQueueID () => 0x%" PRIx64, |
| 544 | static_cast<void *>(exe_ctx.GetThreadPtr()), id); |
Jason Molenda | 4fdb586 | 2013-10-21 23:52:54 +0000 | [diff] [blame] | 545 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 546 | return id; |
Jason Molenda | 4fdb586 | 2013-10-21 23:52:54 +0000 | [diff] [blame] | 547 | } |
| 548 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 549 | bool 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 Molenda | 705b180 | 2014-06-13 02:37:02 +0000 | [diff] [blame] | 554 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 555 | 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 Molenda | 705b180 | 2014-06-13 02:37:02 +0000 | [diff] [blame] | 587 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 588 | } |
| 589 | } else { |
| 590 | if (log) |
| 591 | log->Printf("SBThread(%p)::GetInfoItemByPathAsString() => error: " |
| 592 | "process is running", |
| 593 | static_cast<void *>(exe_ctx.GetThreadPtr())); |
Jason Molenda | 705b180 | 2014-06-13 02:37:02 +0000 | [diff] [blame] | 594 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 595 | } |
Jason Molenda | 705b180 | 2014-06-13 02:37:02 +0000 | [diff] [blame] | 596 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 597 | if (log) |
Jason Molenda | 753e13c | 2017-02-02 03:02:51 +0000 | [diff] [blame] | 598 | log->Printf("SBThread(%p)::GetInfoItemByPathAsString (\"%s\") => \"%s\"", |
| 599 | static_cast<void *>(exe_ctx.GetThreadPtr()), path, strm.GetData()); |
Jason Molenda | 705b180 | 2014-06-13 02:37:02 +0000 | [diff] [blame] | 600 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 601 | return success; |
Jason Molenda | 705b180 | 2014-06-13 02:37:02 +0000 | [diff] [blame] | 602 | } |
| 603 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 604 | SBError SBThread::ResumeNewPlan(ExecutionContext &exe_ctx, |
| 605 | ThreadPlan *new_plan) { |
| 606 | SBError sb_error; |
Jason Molenda | 705b180 | 2014-06-13 02:37:02 +0000 | [diff] [blame] | 607 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 608 | Process *process = exe_ctx.GetProcessPtr(); |
| 609 | if (!process) { |
| 610 | sb_error.SetErrorString("No process in SBThread::ResumeNewPlan"); |
Jim Ingham | 64e7ead | 2012-05-03 21:19:36 +0000 | [diff] [blame] | 611 | return sb_error; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 612 | } |
| 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 Ingham | 64e7ead | 2012-05-03 21:19:36 +0000 | [diff] [blame] | 637 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 638 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 639 | void SBThread::StepOver(lldb::RunMode stop_other_threads) { |
| 640 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 641 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 642 | std::unique_lock<std::recursive_mutex> lock; |
| 643 | ExecutionContext exe_ctx(m_opaque_sp.get(), lock); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 644 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 645 | 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 Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 649 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 650 | if (exe_ctx.HasThreadScope()) { |
| 651 | Thread *thread = exe_ctx.GetThreadPtr(); |
| 652 | bool abort_other_plans = false; |
| 653 | StackFrameSP frame_sp(thread->GetStackFrameAtIndex(0)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 654 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 655 | ThreadPlanSP new_plan_sp; |
| 656 | if (frame_sp) { |
| 657 | if (frame_sp->HasDebugInformation()) { |
Jim Ingham | 4b4b247 | 2014-03-13 02:47:14 +0000 | [diff] [blame] | 658 | const LazyBool avoid_no_debug = eLazyBoolCalculate; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 659 | 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 Clayton | 481cef2 | 2011-01-21 06:11:58 +0000 | [diff] [blame] | 667 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 668 | |
| 669 | // This returns an error, we should use it! |
| 670 | ResumeNewPlan(exe_ctx, new_plan_sp.get()); |
| 671 | } |
Greg Clayton | 481cef2 | 2011-01-21 06:11:58 +0000 | [diff] [blame] | 672 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 673 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 674 | void SBThread::StepInto(lldb::RunMode stop_other_threads) { |
| 675 | StepInto(NULL, stop_other_threads); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 676 | } |
| 677 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 678 | void 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 Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 682 | } |
| 683 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 684 | void 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 Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 687 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 688 | std::unique_lock<std::recursive_mutex> lock; |
| 689 | ExecutionContext exe_ctx(m_opaque_sp.get(), lock); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 690 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 691 | 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 Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 697 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 698 | if (exe_ctx.HasThreadScope()) { |
| 699 | bool abort_other_plans = false; |
Jim Ingham | 2bdbfd5 | 2014-09-29 23:17:18 +0000 | [diff] [blame] | 700 | |
| 701 | Thread *thread = exe_ctx.GetThreadPtr(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 702 | StackFrameSP frame_sp(thread->GetStackFrameAtIndex(0)); |
| 703 | ThreadPlanSP new_plan_sp; |
Jim Ingham | 2bdbfd5 | 2014-09-29 23:17:18 +0000 | [diff] [blame] | 704 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 705 | 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 Ingham | 2bdbfd5 | 2014-09-29 23:17:18 +0000 | [diff] [blame] | 726 | } |
| 727 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 728 | error = ResumeNewPlan(exe_ctx, new_plan_sp.get()); |
| 729 | } |
Jim Ingham | 2bdbfd5 | 2014-09-29 23:17:18 +0000 | [diff] [blame] | 730 | } |
| 731 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 732 | void SBThread::StepOut() { |
| 733 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
Richard Mitton | f86248d | 2013-09-12 02:20:34 +0000 | [diff] [blame] | 734 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 735 | std::unique_lock<std::recursive_mutex> lock; |
| 736 | ExecutionContext exe_ctx(m_opaque_sp.get(), lock); |
Richard Mitton | f86248d | 2013-09-12 02:20:34 +0000 | [diff] [blame] | 737 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 738 | if (log) |
| 739 | log->Printf("SBThread(%p)::StepOut ()", |
| 740 | static_cast<void *>(exe_ctx.GetThreadPtr())); |
Richard Mitton | f86248d | 2013-09-12 02:20:34 +0000 | [diff] [blame] | 741 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 742 | if (exe_ctx.HasThreadScope()) { |
| 743 | bool abort_other_plans = false; |
| 744 | bool stop_other_threads = false; |
Richard Mitton | f86248d | 2013-09-12 02:20:34 +0000 | [diff] [blame] | 745 | |
| 746 | Thread *thread = exe_ctx.GetThreadPtr(); |
| 747 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 748 | 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 | |
| 758 | void 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 | |
| 801 | void 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 | |
| 821 | void 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 | |
| 847 | SBError 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 | |
| 970 | SBError SBThread::StepUsingScriptedThreadPlan(const char *script_class_name) { |
| 971 | return StepUsingScriptedThreadPlan(script_class_name, true); |
| 972 | } |
| 973 | |
| 974 | SBError 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 Mitton | f86248d | 2013-09-12 02:20:34 +0000 | [diff] [blame] | 989 | return sb_error; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 990 | } |
Richard Mitton | f86248d | 2013-09-12 02:20:34 +0000 | [diff] [blame] | 991 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 992 | Thread *thread = exe_ctx.GetThreadPtr(); |
| 993 | ThreadPlanSP thread_plan_sp = |
| 994 | thread->QueueThreadPlanForStepScripted(false, script_class_name, false); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 995 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 996 | if (!thread_plan_sp) { |
| 997 | sb_error.SetErrorStringWithFormat( |
| 998 | "Error queueing thread plan for class: %s", script_class_name); |
Jim Ingham | 4413758 | 2012-09-12 00:40:39 +0000 | [diff] [blame] | 999 | return sb_error; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1000 | } |
Jim Ingham | 4413758 | 2012-09-12 00:40:39 +0000 | [diff] [blame] | 1001 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1002 | if (!resume_immediately) { |
Jim Ingham | 4ac8e93 | 2016-07-08 02:12:05 +0000 | [diff] [blame] | 1003 | return sb_error; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1004 | } |
Jim Ingham | 4ac8e93 | 2016-07-08 02:12:05 +0000 | [diff] [blame] | 1005 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1006 | 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 Clayton | c9858e4 | 2012-04-06 02:17:47 +0000 | [diff] [blame] | 1011 | if (log) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1012 | 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 Clayton | 722a0cd | 2011-01-12 02:25:42 +0000 | [diff] [blame] | 1019 | } |
| 1020 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1021 | SBError SBThread::JumpToLine(lldb::SBFileSpec &file_spec, uint32_t line) { |
| 1022 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
| 1023 | SBError sb_error; |
Jim Ingham | b2e7d28 | 2016-06-10 17:22:26 +0000 | [diff] [blame] | 1024 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1025 | 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 Clayton | 722a0cd | 2011-01-12 02:25:42 +0000 | [diff] [blame] | 1043 | } |
| 1044 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1045 | SBError SBThread::ReturnFromFrame(SBFrame &frame, SBValue &return_value) { |
| 1046 | SBError sb_error; |
Jim Ingham | b2e7d28 | 2016-06-10 17:22:26 +0000 | [diff] [blame] | 1047 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1048 | 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 Clayton | 722a0cd | 2011-01-12 02:25:42 +0000 | [diff] [blame] | 1065 | } |
| 1066 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1067 | SBError SBThread::UnwindInnermostExpression() { |
| 1068 | SBError sb_error; |
Jim Ingham | b2e7d28 | 2016-06-10 17:22:26 +0000 | [diff] [blame] | 1069 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1070 | 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 Kaylor | a75418d | 2013-04-15 23:33:53 +0000 | [diff] [blame] | 1087 | } |
| 1088 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1089 | bool 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 Ingham | b2e7d28 | 2016-06-10 17:22:26 +0000 | [diff] [blame] | 1093 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1094 | 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 Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1104 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1105 | } |
| 1106 | if (log) |
| 1107 | log->Printf("SBThread(%p)::Suspend() => %i", |
| 1108 | static_cast<void *>(exe_ctx.GetThreadPtr()), result); |
| 1109 | return result; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1110 | } |
| 1111 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1112 | bool 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 Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 1116 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1117 | 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 Clayton | af67cec | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 1128 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1129 | } |
| 1130 | if (log) |
| 1131 | log->Printf("SBThread(%p)::Resume() => %i", |
| 1132 | static_cast<void *>(exe_ctx.GetThreadPtr()), result); |
| 1133 | return result; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1134 | } |
| 1135 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1136 | bool SBThread::IsSuspended() { |
| 1137 | std::unique_lock<std::recursive_mutex> lock; |
| 1138 | ExecutionContext exe_ctx(m_opaque_sp.get(), lock); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 1139 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1140 | if (exe_ctx.HasThreadScope()) |
| 1141 | return exe_ctx.GetThreadPtr()->GetResumeState() == eStateSuspended; |
| 1142 | return false; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1143 | } |
| 1144 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1145 | bool SBThread::IsStopped() { |
| 1146 | std::unique_lock<std::recursive_mutex> lock; |
| 1147 | ExecutionContext exe_ctx(m_opaque_sp.get(), lock); |
Greg Clayton | f028a1f | 2010-12-17 02:26:24 +0000 | [diff] [blame] | 1148 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1149 | if (exe_ctx.HasThreadScope()) |
| 1150 | return StateIsStoppedState(exe_ctx.GetThreadPtr()->GetState(), true); |
| 1151 | return false; |
Greg Clayton | f028a1f | 2010-12-17 02:26:24 +0000 | [diff] [blame] | 1152 | } |
| 1153 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1154 | SBProcess SBThread::GetProcess() { |
| 1155 | SBProcess sb_process; |
| 1156 | std::unique_lock<std::recursive_mutex> lock; |
| 1157 | ExecutionContext exe_ctx(m_opaque_sp.get(), lock); |
Greg Clayton | f028a1f | 2010-12-17 02:26:24 +0000 | [diff] [blame] | 1158 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1159 | 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 Ingham | 4fc6cb9 | 2012-08-22 21:34:33 +0000 | [diff] [blame] | 1164 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1165 | 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 | |
| 1178 | uint32_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 | |
| 1203 | SBFrame 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 | |
| 1235 | lldb::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 | |
| 1267 | lldb::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 | |
| 1302 | bool SBThread::EventIsThreadEvent(const SBEvent &event) { |
| 1303 | return Thread::ThreadEventData::GetEventDataFromEvent(event.get()) != NULL; |
| 1304 | } |
| 1305 | |
| 1306 | SBFrame SBThread::GetStackFrameFromEvent(const SBEvent &event) { |
| 1307 | return Thread::ThreadEventData::GetStackFrameFromEvent(event.get()); |
| 1308 | } |
| 1309 | |
| 1310 | SBThread SBThread::GetThreadFromEvent(const SBEvent &event) { |
| 1311 | return Thread::ThreadEventData::GetThreadFromEvent(event.get()); |
| 1312 | } |
| 1313 | |
| 1314 | bool SBThread::operator==(const SBThread &rhs) const { |
| 1315 | return m_opaque_sp->GetThreadSP().get() == |
| 1316 | rhs.m_opaque_sp->GetThreadSP().get(); |
| 1317 | } |
| 1318 | |
| 1319 | bool SBThread::operator!=(const SBThread &rhs) const { |
| 1320 | return m_opaque_sp->GetThreadSP().get() != |
| 1321 | rhs.m_opaque_sp->GetThreadSP().get(); |
| 1322 | } |
| 1323 | |
| 1324 | bool 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 Ingham | 6a9767c | 2016-11-08 20:36:40 +0000 | [diff] [blame] | 1331 | exe_ctx.GetThreadPtr()->GetStatus(strm, 0, 1, 1, true); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1332 | } else |
| 1333 | strm.PutCString("No status"); |
| 1334 | |
| 1335 | return true; |
| 1336 | } |
| 1337 | |
| 1338 | bool SBThread::GetDescription(SBStream &description) const { |
Jim Ingham | 6a9767c | 2016-11-08 20:36:40 +0000 | [diff] [blame] | 1339 | return GetDescription(description, false); |
| 1340 | } |
| 1341 | |
| 1342 | bool SBThread::GetDescription(SBStream &description, bool stop_format) const { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1343 | 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 Ingham | 6a9767c | 2016-11-08 20:36:40 +0000 | [diff] [blame] | 1350 | LLDB_INVALID_THREAD_ID, |
| 1351 | stop_format); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1352 | // 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 | |
| 1360 | SBThread 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 Clayton | 7fdf9ef | 2012-04-05 16:12:35 +0000 | [diff] [blame] | 1396 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1397 | } |
Greg Clayton | f028a1f | 2010-12-17 02:26:24 +0000 | [diff] [blame] | 1398 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1399 | } |
| 1400 | } else { |
| 1401 | if (log) |
| 1402 | log->Printf("SBThread(%p)::GetExtendedBacktraceThread() => error: " |
| 1403 | "process is running", |
| 1404 | static_cast<void *>(exe_ctx.GetThreadPtr())); |
Greg Clayton | f028a1f | 2010-12-17 02:26:24 +0000 | [diff] [blame] | 1405 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1406 | } |
Greg Clayton | f028a1f | 2010-12-17 02:26:24 +0000 | [diff] [blame] | 1407 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1408 | 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 Clayton | f028a1f | 2010-12-17 02:26:24 +0000 | [diff] [blame] | 1413 | } |
| 1414 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1415 | uint32_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 Ingham | 4f465cf | 2012-10-10 18:32:14 +0000 | [diff] [blame] | 1420 | } |
| 1421 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1422 | bool SBThread::SafeToCallFunctions() { |
| 1423 | ThreadSP thread_sp(m_opaque_sp->GetThreadSP()); |
| 1424 | if (thread_sp) |
| 1425 | return thread_sp->SafeToCallFunctions(); |
| 1426 | return true; |
Jim Ingham | 4f465cf | 2012-10-10 18:32:14 +0000 | [diff] [blame] | 1427 | } |
| 1428 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1429 | lldb_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 Ingham | 4f465cf | 2012-10-10 18:32:14 +0000 | [diff] [blame] | 1435 | } |
Greg Clayton | f028a1f | 2010-12-17 02:26:24 +0000 | [diff] [blame] | 1436 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1437 | lldb_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 Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1443 | } |