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" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 17 | #include "lldb/Core/StreamFile.h" |
Zachary Turner | a78bd7f | 2015-03-03 23:11:11 +0000 | [diff] [blame] | 18 | #include "lldb/Core/ValueObject.h" |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 19 | #include "lldb/Interpreter/CommandInterpreter.h" |
Zachary Turner | 93749ab | 2015-03-03 21:51:25 +0000 | [diff] [blame] | 20 | #include "lldb/Symbol/CompileUnit.h" |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 21 | #include "lldb/Symbol/SymbolContext.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 22 | #include "lldb/Target/Process.h" |
Jason Molenda | b9ffa98 | 2014-04-25 00:01:15 +0000 | [diff] [blame] | 23 | #include "lldb/Target/Queue.h" |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 24 | #include "lldb/Target/StopInfo.h" |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 25 | #include "lldb/Target/SystemRuntime.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 26 | #include "lldb/Target/Target.h" |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 27 | #include "lldb/Target/Thread.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 28 | #include "lldb/Target/ThreadPlan.h" |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 29 | #include "lldb/Target/ThreadPlanStepInRange.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 30 | #include "lldb/Target/ThreadPlanStepInstruction.h" |
| 31 | #include "lldb/Target/ThreadPlanStepOut.h" |
| 32 | #include "lldb/Target/ThreadPlanStepRange.h" |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 33 | #include "lldb/Target/UnixSignals.h" |
Pavel Labath | d821c99 | 2018-08-07 11:07:21 +0000 | [diff] [blame] | 34 | #include "lldb/Utility/State.h" |
Zachary Turner | bf9a773 | 2017-02-02 21:39:50 +0000 | [diff] [blame] | 35 | #include "lldb/Utility/Stream.h" |
Pavel Labath | f2a8bcc | 2017-06-27 10:45:31 +0000 | [diff] [blame] | 36 | #include "lldb/Utility/StructuredData.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" |
Abhishek Aggarwal | 5bfee5f | 2017-05-29 08:25:46 +0000 | [diff] [blame] | 46 | #include "lldb/lldb-enumerations.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 47 | |
| 48 | using namespace lldb; |
| 49 | using namespace lldb_private; |
| 50 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 51 | const char *SBThread::GetBroadcasterClassName() { |
| 52 | return Thread::GetStaticBroadcasterClass().AsCString(); |
Jim Ingham | 4f465cf | 2012-10-10 18:32:14 +0000 | [diff] [blame] | 53 | } |
| 54 | |
Greg Clayton | cfd1ace | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 55 | //---------------------------------------------------------------------- |
| 56 | // Constructors |
| 57 | //---------------------------------------------------------------------- |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 58 | SBThread::SBThread() : m_opaque_sp(new ExecutionContextRef()) {} |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 59 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 60 | SBThread::SBThread(const ThreadSP &lldb_object_sp) |
| 61 | : m_opaque_sp(new ExecutionContextRef(lldb_object_sp)) {} |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 62 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 63 | SBThread::SBThread(const SBThread &rhs) |
| 64 | : m_opaque_sp(new ExecutionContextRef(*rhs.m_opaque_sp)) {} |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 65 | |
| 66 | //---------------------------------------------------------------------- |
Greg Clayton | cfd1ace | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 67 | // Assignment operator |
| 68 | //---------------------------------------------------------------------- |
| 69 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 70 | const lldb::SBThread &SBThread::operator=(const SBThread &rhs) { |
| 71 | if (this != &rhs) |
| 72 | *m_opaque_sp = *rhs.m_opaque_sp; |
| 73 | return *this; |
Greg Clayton | cfd1ace | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | //---------------------------------------------------------------------- |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 77 | // Destructor |
| 78 | //---------------------------------------------------------------------- |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 79 | SBThread::~SBThread() {} |
| 80 | |
| 81 | lldb::SBQueue SBThread::GetQueue() const { |
| 82 | SBQueue sb_queue; |
| 83 | QueueSP queue_sp; |
| 84 | std::unique_lock<std::recursive_mutex> lock; |
| 85 | ExecutionContext exe_ctx(m_opaque_sp.get(), lock); |
| 86 | |
| 87 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
| 88 | if (exe_ctx.HasThreadScope()) { |
| 89 | Process::StopLocker stop_locker; |
| 90 | if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock())) { |
| 91 | queue_sp = exe_ctx.GetThreadPtr()->GetQueue(); |
| 92 | if (queue_sp) { |
| 93 | sb_queue.SetQueue(queue_sp); |
| 94 | } |
| 95 | } else { |
| 96 | if (log) |
| 97 | log->Printf("SBThread(%p)::GetQueue() => error: process is running", |
| 98 | static_cast<void *>(exe_ctx.GetThreadPtr())); |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | if (log) |
| 103 | log->Printf("SBThread(%p)::GetQueue () => SBQueue(%p)", |
| 104 | static_cast<void *>(exe_ctx.GetThreadPtr()), |
| 105 | static_cast<void *>(queue_sp.get())); |
| 106 | |
| 107 | return sb_queue; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 108 | } |
| 109 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 110 | bool SBThread::IsValid() const { |
| 111 | std::unique_lock<std::recursive_mutex> lock; |
| 112 | ExecutionContext exe_ctx(m_opaque_sp.get(), lock); |
Jason Molenda | b9ffa98 | 2014-04-25 00:01:15 +0000 | [diff] [blame] | 113 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 114 | Target *target = exe_ctx.GetTargetPtr(); |
| 115 | Process *process = exe_ctx.GetProcessPtr(); |
| 116 | if (target && process) { |
| 117 | Process::StopLocker stop_locker; |
| 118 | if (stop_locker.TryLock(&process->GetRunLock())) |
| 119 | return m_opaque_sp->GetThreadSP().get() != NULL; |
| 120 | } |
| 121 | // Without a valid target & process, this thread can't be valid. |
| 122 | return false; |
| 123 | } |
| 124 | |
| 125 | void SBThread::Clear() { m_opaque_sp->Clear(); } |
| 126 | |
| 127 | StopReason SBThread::GetStopReason() { |
| 128 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
| 129 | |
| 130 | StopReason reason = eStopReasonInvalid; |
| 131 | std::unique_lock<std::recursive_mutex> lock; |
| 132 | ExecutionContext exe_ctx(m_opaque_sp.get(), lock); |
| 133 | |
| 134 | if (exe_ctx.HasThreadScope()) { |
| 135 | Process::StopLocker stop_locker; |
| 136 | if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock())) { |
| 137 | return exe_ctx.GetThreadPtr()->GetStopReason(); |
| 138 | } else { |
| 139 | if (log) |
| 140 | log->Printf( |
| 141 | "SBThread(%p)::GetStopReason() => error: process is running", |
| 142 | static_cast<void *>(exe_ctx.GetThreadPtr())); |
| 143 | } |
| 144 | } |
| 145 | |
| 146 | if (log) |
| 147 | log->Printf("SBThread(%p)::GetStopReason () => %s", |
| 148 | static_cast<void *>(exe_ctx.GetThreadPtr()), |
| 149 | Thread::StopReasonAsCString(reason)); |
| 150 | |
| 151 | return reason; |
| 152 | } |
| 153 | |
| 154 | size_t SBThread::GetStopReasonDataCount() { |
| 155 | std::unique_lock<std::recursive_mutex> lock; |
| 156 | ExecutionContext exe_ctx(m_opaque_sp.get(), lock); |
| 157 | |
| 158 | if (exe_ctx.HasThreadScope()) { |
| 159 | Process::StopLocker stop_locker; |
| 160 | if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock())) { |
| 161 | StopInfoSP stop_info_sp = exe_ctx.GetThreadPtr()->GetStopInfo(); |
| 162 | if (stop_info_sp) { |
| 163 | StopReason reason = stop_info_sp->GetStopReason(); |
| 164 | switch (reason) { |
| 165 | case eStopReasonInvalid: |
| 166 | case eStopReasonNone: |
| 167 | case eStopReasonTrace: |
| 168 | case eStopReasonExec: |
| 169 | case eStopReasonPlanComplete: |
| 170 | case eStopReasonThreadExiting: |
| 171 | case eStopReasonInstrumentation: |
| 172 | // There is no data for these stop reasons. |
| 173 | return 0; |
| 174 | |
| 175 | case eStopReasonBreakpoint: { |
| 176 | break_id_t site_id = stop_info_sp->GetValue(); |
| 177 | lldb::BreakpointSiteSP bp_site_sp( |
| 178 | exe_ctx.GetProcessPtr()->GetBreakpointSiteList().FindByID( |
| 179 | site_id)); |
| 180 | if (bp_site_sp) |
| 181 | return bp_site_sp->GetNumberOfOwners() * 2; |
| 182 | else |
| 183 | return 0; // Breakpoint must have cleared itself... |
| 184 | } break; |
| 185 | |
| 186 | case eStopReasonWatchpoint: |
| 187 | return 1; |
| 188 | |
| 189 | case eStopReasonSignal: |
| 190 | return 1; |
| 191 | |
| 192 | case eStopReasonException: |
| 193 | return 1; |
| 194 | } |
| 195 | } |
| 196 | } else { |
| 197 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
| 198 | if (log) |
| 199 | log->Printf("SBThread(%p)::GetStopReasonDataCount() => error: process " |
| 200 | "is running", |
| 201 | static_cast<void *>(exe_ctx.GetThreadPtr())); |
| 202 | } |
| 203 | } |
| 204 | return 0; |
| 205 | } |
| 206 | |
| 207 | uint64_t SBThread::GetStopReasonDataAtIndex(uint32_t idx) { |
| 208 | std::unique_lock<std::recursive_mutex> lock; |
| 209 | ExecutionContext exe_ctx(m_opaque_sp.get(), lock); |
| 210 | |
| 211 | if (exe_ctx.HasThreadScope()) { |
| 212 | Process::StopLocker stop_locker; |
| 213 | if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock())) { |
| 214 | Thread *thread = exe_ctx.GetThreadPtr(); |
| 215 | StopInfoSP stop_info_sp = thread->GetStopInfo(); |
| 216 | if (stop_info_sp) { |
| 217 | StopReason reason = stop_info_sp->GetStopReason(); |
| 218 | switch (reason) { |
| 219 | case eStopReasonInvalid: |
| 220 | case eStopReasonNone: |
| 221 | case eStopReasonTrace: |
| 222 | case eStopReasonExec: |
| 223 | case eStopReasonPlanComplete: |
| 224 | case eStopReasonThreadExiting: |
| 225 | case eStopReasonInstrumentation: |
| 226 | // There is no data for these stop reasons. |
| 227 | return 0; |
| 228 | |
| 229 | case eStopReasonBreakpoint: { |
| 230 | break_id_t site_id = stop_info_sp->GetValue(); |
| 231 | lldb::BreakpointSiteSP bp_site_sp( |
| 232 | exe_ctx.GetProcessPtr()->GetBreakpointSiteList().FindByID( |
| 233 | site_id)); |
| 234 | if (bp_site_sp) { |
| 235 | uint32_t bp_index = idx / 2; |
| 236 | BreakpointLocationSP bp_loc_sp( |
| 237 | bp_site_sp->GetOwnerAtIndex(bp_index)); |
| 238 | if (bp_loc_sp) { |
| 239 | if (idx & 1) { |
| 240 | // Odd idx, return the breakpoint location ID |
| 241 | return bp_loc_sp->GetID(); |
| 242 | } else { |
| 243 | // Even idx, return the breakpoint ID |
| 244 | return bp_loc_sp->GetBreakpoint().GetID(); |
| 245 | } |
Jason Molenda | b9ffa98 | 2014-04-25 00:01:15 +0000 | [diff] [blame] | 246 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 247 | } |
| 248 | return LLDB_INVALID_BREAK_ID; |
| 249 | } break; |
| 250 | |
| 251 | case eStopReasonWatchpoint: |
| 252 | return stop_info_sp->GetValue(); |
| 253 | |
| 254 | case eStopReasonSignal: |
| 255 | return stop_info_sp->GetValue(); |
| 256 | |
| 257 | case eStopReasonException: |
| 258 | return stop_info_sp->GetValue(); |
Jason Molenda | b9ffa98 | 2014-04-25 00:01:15 +0000 | [diff] [blame] | 259 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 260 | } |
| 261 | } else { |
| 262 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
| 263 | if (log) |
| 264 | log->Printf("SBThread(%p)::GetStopReasonDataAtIndex() => error: " |
| 265 | "process is running", |
| 266 | static_cast<void *>(exe_ctx.GetThreadPtr())); |
Jason Molenda | b9ffa98 | 2014-04-25 00:01:15 +0000 | [diff] [blame] | 267 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 268 | } |
| 269 | return 0; |
Jason Molenda | b9ffa98 | 2014-04-25 00:01:15 +0000 | [diff] [blame] | 270 | } |
| 271 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 272 | bool SBThread::GetStopReasonExtendedInfoAsJSON(lldb::SBStream &stream) { |
| 273 | Stream &strm = stream.ref(); |
Jason Molenda | b9ffa98 | 2014-04-25 00:01:15 +0000 | [diff] [blame] | 274 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 275 | std::unique_lock<std::recursive_mutex> lock; |
| 276 | ExecutionContext exe_ctx(m_opaque_sp.get(), lock); |
Jim Ingham | 7fa7dc3 | 2016-05-07 00:54:56 +0000 | [diff] [blame] | 277 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 278 | if (!exe_ctx.HasThreadScope()) |
Jim Ingham | 7fa7dc3 | 2016-05-07 00:54:56 +0000 | [diff] [blame] | 279 | return false; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 280 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 281 | StopInfoSP stop_info = exe_ctx.GetThreadPtr()->GetStopInfo(); |
| 282 | StructuredData::ObjectSP info = stop_info->GetExtendedInfo(); |
| 283 | if (!info) |
| 284 | return false; |
Greg Clayton | 48e4254 | 2010-07-30 20:12:55 +0000 | [diff] [blame] | 285 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 286 | info->Dump(strm); |
Greg Clayton | 48e4254 | 2010-07-30 20:12:55 +0000 | [diff] [blame] | 287 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 288 | return true; |
Kuba Brecka | afdf842 | 2014-10-10 23:43:03 +0000 | [diff] [blame] | 289 | } |
| 290 | |
Kuba Brecka | 6a83143 | 2016-03-23 15:36:22 +0000 | [diff] [blame] | 291 | SBThreadCollection |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 292 | SBThread::GetStopReasonExtendedBacktraces(InstrumentationRuntimeType type) { |
| 293 | ThreadCollectionSP threads; |
| 294 | threads.reset(new ThreadCollection()); |
Jim Ingham | b2e7d28 | 2016-06-10 17:22:26 +0000 | [diff] [blame] | 295 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 296 | std::unique_lock<std::recursive_mutex> lock; |
| 297 | ExecutionContext exe_ctx(m_opaque_sp.get(), lock); |
| 298 | |
| 299 | if (!exe_ctx.HasThreadScope()) |
| 300 | return threads; |
| 301 | |
| 302 | ProcessSP process_sp = exe_ctx.GetProcessSP(); |
| 303 | |
| 304 | StopInfoSP stop_info = exe_ctx.GetThreadPtr()->GetStopInfo(); |
| 305 | StructuredData::ObjectSP info = stop_info->GetExtendedInfo(); |
| 306 | if (!info) |
| 307 | return threads; |
| 308 | |
| 309 | return process_sp->GetInstrumentationRuntime(type) |
| 310 | ->GetBacktracesFromExtendedStopInfo(info); |
Kuba Brecka | 6a83143 | 2016-03-23 15:36:22 +0000 | [diff] [blame] | 311 | } |
| 312 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 313 | size_t SBThread::GetStopDescription(char *dst, size_t dst_len) { |
| 314 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 315 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 316 | std::unique_lock<std::recursive_mutex> lock; |
| 317 | ExecutionContext exe_ctx(m_opaque_sp.get(), lock); |
Jim Ingham | 4fc6cb9 | 2012-08-22 21:34:33 +0000 | [diff] [blame] | 318 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 319 | if (exe_ctx.HasThreadScope()) { |
| 320 | Process::StopLocker stop_locker; |
| 321 | if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock())) { |
Greg Clayton | 7fdf9ef | 2012-04-05 16:12:35 +0000 | [diff] [blame] | 322 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 323 | StopInfoSP stop_info_sp = exe_ctx.GetThreadPtr()->GetStopInfo(); |
| 324 | if (stop_info_sp) { |
| 325 | const char *stop_desc = stop_info_sp->GetDescription(); |
| 326 | if (stop_desc) { |
| 327 | if (log) |
| 328 | log->Printf( |
| 329 | "SBThread(%p)::GetStopDescription (dst, dst_len) => \"%s\"", |
| 330 | static_cast<void *>(exe_ctx.GetThreadPtr()), stop_desc); |
| 331 | if (dst) |
| 332 | return ::snprintf(dst, dst_len, "%s", stop_desc); |
| 333 | else { |
| 334 | // NULL dst passed in, return the length needed to contain the |
| 335 | // description |
| 336 | return ::strlen(stop_desc) + 1; // Include the NULL byte for size |
| 337 | } |
| 338 | } else { |
| 339 | size_t stop_desc_len = 0; |
| 340 | switch (stop_info_sp->GetStopReason()) { |
| 341 | case eStopReasonTrace: |
| 342 | case eStopReasonPlanComplete: { |
| 343 | static char trace_desc[] = "step"; |
| 344 | stop_desc = trace_desc; |
| 345 | stop_desc_len = |
| 346 | sizeof(trace_desc); // Include the NULL byte for size |
| 347 | } break; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 348 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 349 | case eStopReasonBreakpoint: { |
| 350 | static char bp_desc[] = "breakpoint hit"; |
| 351 | stop_desc = bp_desc; |
| 352 | stop_desc_len = sizeof(bp_desc); // Include the NULL byte for size |
| 353 | } break; |
Greg Clayton | 7fdf9ef | 2012-04-05 16:12:35 +0000 | [diff] [blame] | 354 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 355 | case eStopReasonWatchpoint: { |
| 356 | static char wp_desc[] = "watchpoint hit"; |
| 357 | stop_desc = wp_desc; |
| 358 | stop_desc_len = sizeof(wp_desc); // Include the NULL byte for size |
| 359 | } break; |
Greg Clayton | 7fdf9ef | 2012-04-05 16:12:35 +0000 | [diff] [blame] | 360 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 361 | case eStopReasonSignal: { |
| 362 | stop_desc = |
| 363 | exe_ctx.GetProcessPtr()->GetUnixSignals()->GetSignalAsCString( |
| 364 | stop_info_sp->GetValue()); |
| 365 | if (stop_desc == NULL || stop_desc[0] == '\0') { |
| 366 | static char signal_desc[] = "signal"; |
| 367 | stop_desc = signal_desc; |
| 368 | stop_desc_len = |
| 369 | sizeof(signal_desc); // Include the NULL byte for size |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 370 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 371 | } break; |
| 372 | |
| 373 | case eStopReasonException: { |
| 374 | char exc_desc[] = "exception"; |
| 375 | stop_desc = exc_desc; |
| 376 | stop_desc_len = sizeof(exc_desc); // Include the NULL byte for size |
| 377 | } break; |
| 378 | |
| 379 | case eStopReasonExec: { |
| 380 | char exc_desc[] = "exec"; |
| 381 | stop_desc = exc_desc; |
| 382 | stop_desc_len = sizeof(exc_desc); // Include the NULL byte for size |
| 383 | } break; |
| 384 | |
| 385 | case eStopReasonThreadExiting: { |
| 386 | char limbo_desc[] = "thread exiting"; |
| 387 | stop_desc = limbo_desc; |
| 388 | stop_desc_len = sizeof(limbo_desc); |
| 389 | } break; |
| 390 | default: |
| 391 | break; |
| 392 | } |
| 393 | |
| 394 | if (stop_desc && stop_desc[0]) { |
Greg Clayton | c9858e4 | 2012-04-06 02:17:47 +0000 | [diff] [blame] | 395 | if (log) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 396 | log->Printf( |
| 397 | "SBThread(%p)::GetStopDescription (dst, dst_len) => '%s'", |
| 398 | static_cast<void *>(exe_ctx.GetThreadPtr()), stop_desc); |
| 399 | |
| 400 | if (dst) |
| 401 | return ::snprintf(dst, dst_len, "%s", stop_desc) + |
| 402 | 1; // Include the NULL byte |
| 403 | |
| 404 | if (stop_desc_len == 0) |
| 405 | stop_desc_len = ::strlen(stop_desc) + 1; // Include the NULL byte |
| 406 | |
| 407 | return stop_desc_len; |
| 408 | } |
Greg Clayton | c9858e4 | 2012-04-06 02:17:47 +0000 | [diff] [blame] | 409 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 410 | } |
| 411 | } else { |
| 412 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
| 413 | if (log) |
| 414 | log->Printf( |
| 415 | "SBThread(%p)::GetStopDescription() => error: process is running", |
| 416 | static_cast<void *>(exe_ctx.GetThreadPtr())); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 417 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 418 | } |
| 419 | if (dst) |
| 420 | *dst = 0; |
| 421 | return 0; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 422 | } |
| 423 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 424 | SBValue SBThread::GetStopReturnValue() { |
| 425 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
| 426 | ValueObjectSP return_valobj_sp; |
| 427 | std::unique_lock<std::recursive_mutex> lock; |
| 428 | ExecutionContext exe_ctx(m_opaque_sp.get(), lock); |
Jim Ingham | 4fc6cb9 | 2012-08-22 21:34:33 +0000 | [diff] [blame] | 429 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 430 | if (exe_ctx.HasThreadScope()) { |
| 431 | Process::StopLocker stop_locker; |
| 432 | if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock())) { |
| 433 | StopInfoSP stop_info_sp = exe_ctx.GetThreadPtr()->GetStopInfo(); |
| 434 | if (stop_info_sp) { |
| 435 | return_valobj_sp = StopInfo::GetReturnValueObject(stop_info_sp); |
| 436 | } |
| 437 | } else { |
| 438 | if (log) |
| 439 | log->Printf( |
| 440 | "SBThread(%p)::GetStopReturnValue() => error: process is running", |
| 441 | static_cast<void *>(exe_ctx.GetThreadPtr())); |
Jim Ingham | 73ca05a | 2011-12-17 01:35:57 +0000 | [diff] [blame] | 442 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 443 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 444 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 445 | if (log) |
| 446 | log->Printf("SBThread(%p)::GetStopReturnValue () => %s", |
| 447 | static_cast<void *>(exe_ctx.GetThreadPtr()), |
| 448 | return_valobj_sp.get() ? return_valobj_sp->GetValueAsCString() |
| 449 | : "<no return value>"); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 450 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 451 | return SBValue(return_valobj_sp); |
Jim Ingham | 73ca05a | 2011-12-17 01:35:57 +0000 | [diff] [blame] | 452 | } |
| 453 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 454 | void SBThread::SetThread(const ThreadSP &lldb_object_sp) { |
| 455 | m_opaque_sp->SetThreadSP(lldb_object_sp); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 456 | } |
| 457 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 458 | lldb::tid_t SBThread::GetThreadID() const { |
| 459 | ThreadSP thread_sp(m_opaque_sp->GetThreadSP()); |
| 460 | if (thread_sp) |
| 461 | return thread_sp->GetID(); |
| 462 | return LLDB_INVALID_THREAD_ID; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 463 | } |
| 464 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 465 | uint32_t SBThread::GetIndexID() const { |
| 466 | ThreadSP thread_sp(m_opaque_sp->GetThreadSP()); |
| 467 | if (thread_sp) |
| 468 | return thread_sp->GetIndexID(); |
| 469 | return LLDB_INVALID_INDEX32; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 470 | } |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 471 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 472 | const char *SBThread::GetName() const { |
| 473 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
| 474 | const char *name = NULL; |
| 475 | std::unique_lock<std::recursive_mutex> lock; |
| 476 | ExecutionContext exe_ctx(m_opaque_sp.get(), lock); |
Jim Ingham | 4fc6cb9 | 2012-08-22 21:34:33 +0000 | [diff] [blame] | 477 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 478 | if (exe_ctx.HasThreadScope()) { |
| 479 | Process::StopLocker stop_locker; |
| 480 | if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock())) { |
| 481 | name = exe_ctx.GetThreadPtr()->GetName(); |
| 482 | } else { |
| 483 | if (log) |
| 484 | log->Printf("SBThread(%p)::GetName() => error: process is running", |
| 485 | static_cast<void *>(exe_ctx.GetThreadPtr())); |
Greg Clayton | af67cec | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 486 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 487 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 488 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 489 | if (log) |
| 490 | log->Printf("SBThread(%p)::GetName () => %s", |
| 491 | static_cast<void *>(exe_ctx.GetThreadPtr()), |
| 492 | name ? name : "NULL"); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 493 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 494 | return name; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 495 | } |
| 496 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 497 | const char *SBThread::GetQueueName() const { |
| 498 | const char *name = NULL; |
| 499 | std::unique_lock<std::recursive_mutex> lock; |
| 500 | ExecutionContext exe_ctx(m_opaque_sp.get(), lock); |
Jim Ingham | 4fc6cb9 | 2012-08-22 21:34:33 +0000 | [diff] [blame] | 501 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 502 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
| 503 | if (exe_ctx.HasThreadScope()) { |
| 504 | Process::StopLocker stop_locker; |
| 505 | if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock())) { |
| 506 | name = exe_ctx.GetThreadPtr()->GetQueueName(); |
| 507 | } else { |
| 508 | if (log) |
| 509 | log->Printf("SBThread(%p)::GetQueueName() => error: process is running", |
| 510 | static_cast<void *>(exe_ctx.GetThreadPtr())); |
Greg Clayton | af67cec | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 511 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 512 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 513 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 514 | if (log) |
| 515 | log->Printf("SBThread(%p)::GetQueueName () => %s", |
| 516 | static_cast<void *>(exe_ctx.GetThreadPtr()), |
| 517 | name ? name : "NULL"); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 518 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 519 | return name; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 520 | } |
| 521 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 522 | lldb::queue_id_t SBThread::GetQueueID() const { |
| 523 | queue_id_t id = LLDB_INVALID_QUEUE_ID; |
| 524 | std::unique_lock<std::recursive_mutex> lock; |
| 525 | ExecutionContext exe_ctx(m_opaque_sp.get(), lock); |
Jason Molenda | 4fdb586 | 2013-10-21 23:52:54 +0000 | [diff] [blame] | 526 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 527 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
| 528 | if (exe_ctx.HasThreadScope()) { |
| 529 | Process::StopLocker stop_locker; |
| 530 | if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock())) { |
| 531 | id = exe_ctx.GetThreadPtr()->GetQueueID(); |
| 532 | } else { |
| 533 | if (log) |
| 534 | log->Printf("SBThread(%p)::GetQueueID() => error: process is running", |
| 535 | static_cast<void *>(exe_ctx.GetThreadPtr())); |
Jason Molenda | 4fdb586 | 2013-10-21 23:52:54 +0000 | [diff] [blame] | 536 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 537 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 538 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 539 | if (log) |
| 540 | log->Printf("SBThread(%p)::GetQueueID () => 0x%" PRIx64, |
| 541 | static_cast<void *>(exe_ctx.GetThreadPtr()), id); |
Jason Molenda | 4fdb586 | 2013-10-21 23:52:54 +0000 | [diff] [blame] | 542 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 543 | return id; |
Jason Molenda | 4fdb586 | 2013-10-21 23:52:54 +0000 | [diff] [blame] | 544 | } |
| 545 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 546 | bool SBThread::GetInfoItemByPathAsString(const char *path, SBStream &strm) { |
| 547 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
| 548 | bool success = false; |
| 549 | std::unique_lock<std::recursive_mutex> lock; |
| 550 | ExecutionContext exe_ctx(m_opaque_sp.get(), lock); |
Jason Molenda | 705b180 | 2014-06-13 02:37:02 +0000 | [diff] [blame] | 551 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 552 | if (exe_ctx.HasThreadScope()) { |
| 553 | Process::StopLocker stop_locker; |
| 554 | if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock())) { |
| 555 | Thread *thread = exe_ctx.GetThreadPtr(); |
| 556 | StructuredData::ObjectSP info_root_sp = thread->GetExtendedInfo(); |
| 557 | if (info_root_sp) { |
| 558 | StructuredData::ObjectSP node = |
| 559 | info_root_sp->GetObjectForDotSeparatedPath(path); |
| 560 | if (node) { |
Abhishek Aggarwal | 5bfee5f | 2017-05-29 08:25:46 +0000 | [diff] [blame] | 561 | if (node->GetType() == eStructuredDataTypeString) { |
Zachary Turner | 2833321 | 2017-05-12 05:49:54 +0000 | [diff] [blame] | 562 | strm.Printf("%s", node->GetAsString()->GetValue().str().c_str()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 563 | success = true; |
| 564 | } |
Abhishek Aggarwal | 5bfee5f | 2017-05-29 08:25:46 +0000 | [diff] [blame] | 565 | if (node->GetType() == eStructuredDataTypeInteger) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 566 | strm.Printf("0x%" PRIx64, node->GetAsInteger()->GetValue()); |
| 567 | success = true; |
| 568 | } |
Abhishek Aggarwal | 5bfee5f | 2017-05-29 08:25:46 +0000 | [diff] [blame] | 569 | if (node->GetType() == eStructuredDataTypeFloat) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 570 | strm.Printf("0x%f", node->GetAsFloat()->GetValue()); |
| 571 | success = true; |
| 572 | } |
Abhishek Aggarwal | 5bfee5f | 2017-05-29 08:25:46 +0000 | [diff] [blame] | 573 | if (node->GetType() == eStructuredDataTypeBoolean) { |
Jonas Devlieghere | a6682a4 | 2018-12-15 00:15:33 +0000 | [diff] [blame^] | 574 | if (node->GetAsBoolean()->GetValue()) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 575 | strm.Printf("true"); |
| 576 | else |
| 577 | strm.Printf("false"); |
| 578 | success = true; |
| 579 | } |
Abhishek Aggarwal | 5bfee5f | 2017-05-29 08:25:46 +0000 | [diff] [blame] | 580 | if (node->GetType() == eStructuredDataTypeNull) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 581 | strm.Printf("null"); |
| 582 | success = true; |
| 583 | } |
Jason Molenda | 705b180 | 2014-06-13 02:37:02 +0000 | [diff] [blame] | 584 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 585 | } |
| 586 | } else { |
| 587 | if (log) |
| 588 | log->Printf("SBThread(%p)::GetInfoItemByPathAsString() => error: " |
| 589 | "process is running", |
| 590 | static_cast<void *>(exe_ctx.GetThreadPtr())); |
Jason Molenda | 705b180 | 2014-06-13 02:37:02 +0000 | [diff] [blame] | 591 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 592 | } |
Jason Molenda | 705b180 | 2014-06-13 02:37:02 +0000 | [diff] [blame] | 593 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 594 | if (log) |
Jason Molenda | 753e13c | 2017-02-02 03:02:51 +0000 | [diff] [blame] | 595 | log->Printf("SBThread(%p)::GetInfoItemByPathAsString (\"%s\") => \"%s\"", |
| 596 | static_cast<void *>(exe_ctx.GetThreadPtr()), path, strm.GetData()); |
Jason Molenda | 705b180 | 2014-06-13 02:37:02 +0000 | [diff] [blame] | 597 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 598 | return success; |
Jason Molenda | 705b180 | 2014-06-13 02:37:02 +0000 | [diff] [blame] | 599 | } |
| 600 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 601 | SBError SBThread::ResumeNewPlan(ExecutionContext &exe_ctx, |
| 602 | ThreadPlan *new_plan) { |
| 603 | SBError sb_error; |
Jason Molenda | 705b180 | 2014-06-13 02:37:02 +0000 | [diff] [blame] | 604 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 605 | Process *process = exe_ctx.GetProcessPtr(); |
| 606 | if (!process) { |
| 607 | sb_error.SetErrorString("No process in SBThread::ResumeNewPlan"); |
Jim Ingham | 64e7ead | 2012-05-03 21:19:36 +0000 | [diff] [blame] | 608 | return sb_error; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 609 | } |
| 610 | |
| 611 | Thread *thread = exe_ctx.GetThreadPtr(); |
| 612 | if (!thread) { |
| 613 | sb_error.SetErrorString("No thread in SBThread::ResumeNewPlan"); |
| 614 | return sb_error; |
| 615 | } |
| 616 | |
| 617 | // User level plans should be Master Plans so they can be interrupted, other |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 618 | // plans executed, and then a "continue" will resume the plan. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 619 | if (new_plan != NULL) { |
| 620 | new_plan->SetIsMasterPlan(true); |
| 621 | new_plan->SetOkayToDiscard(false); |
| 622 | } |
| 623 | |
| 624 | // Why do we need to set the current thread by ID here??? |
| 625 | process->GetThreadList().SetSelectedThreadByID(thread->GetID()); |
| 626 | |
| 627 | if (process->GetTarget().GetDebugger().GetAsyncExecution()) |
| 628 | sb_error.ref() = process->Resume(); |
| 629 | else |
| 630 | sb_error.ref() = process->ResumeSynchronous(NULL); |
| 631 | |
| 632 | return sb_error; |
Jim Ingham | 64e7ead | 2012-05-03 21:19:36 +0000 | [diff] [blame] | 633 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 634 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 635 | void SBThread::StepOver(lldb::RunMode stop_other_threads) { |
Alexander Polyakov | 859f54b | 2018-06-20 21:43:16 +0000 | [diff] [blame] | 636 | SBError error; // Ignored |
| 637 | StepOver(stop_other_threads, error); |
| 638 | } |
| 639 | |
| 640 | void SBThread::StepOver(lldb::RunMode stop_other_threads, SBError &error) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 641 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 642 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 643 | std::unique_lock<std::recursive_mutex> lock; |
| 644 | ExecutionContext exe_ctx(m_opaque_sp.get(), lock); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 645 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 646 | if (log) |
| 647 | log->Printf("SBThread(%p)::StepOver (stop_other_threads='%s')", |
| 648 | static_cast<void *>(exe_ctx.GetThreadPtr()), |
| 649 | Thread::RunModeAsCString(stop_other_threads)); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 650 | |
Alexander Polyakov | 859f54b | 2018-06-20 21:43:16 +0000 | [diff] [blame] | 651 | if (!exe_ctx.HasThreadScope()) { |
| 652 | error.SetErrorString("this SBThread object is invalid"); |
| 653 | return; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 654 | } |
Alexander Polyakov | 859f54b | 2018-06-20 21:43:16 +0000 | [diff] [blame] | 655 | |
| 656 | Thread *thread = exe_ctx.GetThreadPtr(); |
| 657 | bool abort_other_plans = false; |
| 658 | StackFrameSP frame_sp(thread->GetStackFrameAtIndex(0)); |
| 659 | |
Jonas Devlieghere | e103ae9 | 2018-11-15 01:18:15 +0000 | [diff] [blame] | 660 | Status new_plan_status; |
Alexander Polyakov | 859f54b | 2018-06-20 21:43:16 +0000 | [diff] [blame] | 661 | ThreadPlanSP new_plan_sp; |
| 662 | if (frame_sp) { |
| 663 | if (frame_sp->HasDebugInformation()) { |
| 664 | const LazyBool avoid_no_debug = eLazyBoolCalculate; |
| 665 | SymbolContext sc(frame_sp->GetSymbolContext(eSymbolContextEverything)); |
| 666 | new_plan_sp = thread->QueueThreadPlanForStepOverRange( |
| 667 | abort_other_plans, sc.line_entry, sc, stop_other_threads, |
Jonas Devlieghere | e103ae9 | 2018-11-15 01:18:15 +0000 | [diff] [blame] | 668 | new_plan_status, avoid_no_debug); |
Alexander Polyakov | 859f54b | 2018-06-20 21:43:16 +0000 | [diff] [blame] | 669 | } else { |
| 670 | new_plan_sp = thread->QueueThreadPlanForStepSingleInstruction( |
Jonas Devlieghere | e103ae9 | 2018-11-15 01:18:15 +0000 | [diff] [blame] | 671 | true, abort_other_plans, stop_other_threads, new_plan_status); |
Alexander Polyakov | 859f54b | 2018-06-20 21:43:16 +0000 | [diff] [blame] | 672 | } |
| 673 | } |
| 674 | error = ResumeNewPlan(exe_ctx, new_plan_sp.get()); |
Greg Clayton | 481cef2 | 2011-01-21 06:11:58 +0000 | [diff] [blame] | 675 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 676 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 677 | void SBThread::StepInto(lldb::RunMode stop_other_threads) { |
| 678 | StepInto(NULL, stop_other_threads); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 679 | } |
| 680 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 681 | void SBThread::StepInto(const char *target_name, |
| 682 | lldb::RunMode stop_other_threads) { |
Alexander Polyakov | 859f54b | 2018-06-20 21:43:16 +0000 | [diff] [blame] | 683 | SBError error; // Ignored |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 684 | StepInto(target_name, LLDB_INVALID_LINE_NUMBER, error, stop_other_threads); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 685 | } |
| 686 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 687 | void SBThread::StepInto(const char *target_name, uint32_t end_line, |
| 688 | SBError &error, lldb::RunMode stop_other_threads) { |
| 689 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
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 | std::unique_lock<std::recursive_mutex> lock; |
| 692 | ExecutionContext exe_ctx(m_opaque_sp.get(), lock); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 693 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 694 | if (log) |
| 695 | log->Printf( |
| 696 | "SBThread(%p)::StepInto (target_name='%s', stop_other_threads='%s')", |
| 697 | static_cast<void *>(exe_ctx.GetThreadPtr()), |
| 698 | target_name ? target_name : "<NULL>", |
| 699 | Thread::RunModeAsCString(stop_other_threads)); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 700 | |
Alexander Polyakov | 859f54b | 2018-06-20 21:43:16 +0000 | [diff] [blame] | 701 | if (!exe_ctx.HasThreadScope()) { |
| 702 | error.SetErrorString("this SBThread object is invalid"); |
| 703 | return; |
| 704 | } |
Jim Ingham | 2bdbfd5 | 2014-09-29 23:17:18 +0000 | [diff] [blame] | 705 | |
Alexander Polyakov | 859f54b | 2018-06-20 21:43:16 +0000 | [diff] [blame] | 706 | bool abort_other_plans = false; |
Jim Ingham | 2bdbfd5 | 2014-09-29 23:17:18 +0000 | [diff] [blame] | 707 | |
Alexander Polyakov | 859f54b | 2018-06-20 21:43:16 +0000 | [diff] [blame] | 708 | Thread *thread = exe_ctx.GetThreadPtr(); |
| 709 | StackFrameSP frame_sp(thread->GetStackFrameAtIndex(0)); |
| 710 | ThreadPlanSP new_plan_sp; |
Jonas Devlieghere | e103ae9 | 2018-11-15 01:18:15 +0000 | [diff] [blame] | 711 | Status new_plan_status; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 712 | |
Alexander Polyakov | 859f54b | 2018-06-20 21:43:16 +0000 | [diff] [blame] | 713 | if (frame_sp && frame_sp->HasDebugInformation()) { |
| 714 | SymbolContext sc(frame_sp->GetSymbolContext(eSymbolContextEverything)); |
| 715 | AddressRange range; |
| 716 | if (end_line == LLDB_INVALID_LINE_NUMBER) |
| 717 | range = sc.line_entry.range; |
| 718 | else { |
| 719 | if (!sc.GetAddressRangeFromHereToEndLine(end_line, range, error.ref())) |
| 720 | return; |
Jim Ingham | 2bdbfd5 | 2014-09-29 23:17:18 +0000 | [diff] [blame] | 721 | } |
| 722 | |
Alexander Polyakov | 859f54b | 2018-06-20 21:43:16 +0000 | [diff] [blame] | 723 | const LazyBool step_out_avoids_code_without_debug_info = |
| 724 | eLazyBoolCalculate; |
| 725 | const LazyBool step_in_avoids_code_without_debug_info = |
| 726 | eLazyBoolCalculate; |
| 727 | new_plan_sp = thread->QueueThreadPlanForStepInRange( |
| 728 | abort_other_plans, range, sc, target_name, stop_other_threads, |
Jonas Devlieghere | e103ae9 | 2018-11-15 01:18:15 +0000 | [diff] [blame] | 729 | new_plan_status, step_in_avoids_code_without_debug_info, |
Alexander Polyakov | 859f54b | 2018-06-20 21:43:16 +0000 | [diff] [blame] | 730 | step_out_avoids_code_without_debug_info); |
| 731 | } else { |
| 732 | new_plan_sp = thread->QueueThreadPlanForStepSingleInstruction( |
Jonas Devlieghere | e103ae9 | 2018-11-15 01:18:15 +0000 | [diff] [blame] | 733 | false, abort_other_plans, stop_other_threads, new_plan_status); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 734 | } |
Jonas Devlieghere | e103ae9 | 2018-11-15 01:18:15 +0000 | [diff] [blame] | 735 | |
| 736 | if (new_plan_status.Success()) |
| 737 | error = ResumeNewPlan(exe_ctx, new_plan_sp.get()); |
| 738 | else |
| 739 | error.SetErrorString(new_plan_status.AsCString()); |
Jim Ingham | 2bdbfd5 | 2014-09-29 23:17:18 +0000 | [diff] [blame] | 740 | } |
| 741 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 742 | void SBThread::StepOut() { |
Alexander Polyakov | 859f54b | 2018-06-20 21:43:16 +0000 | [diff] [blame] | 743 | SBError error; // Ignored |
| 744 | StepOut(error); |
| 745 | } |
| 746 | |
| 747 | void SBThread::StepOut(SBError &error) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 748 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
Richard Mitton | f86248d | 2013-09-12 02:20:34 +0000 | [diff] [blame] | 749 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 750 | std::unique_lock<std::recursive_mutex> lock; |
| 751 | ExecutionContext exe_ctx(m_opaque_sp.get(), lock); |
Richard Mitton | f86248d | 2013-09-12 02:20:34 +0000 | [diff] [blame] | 752 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 753 | if (log) |
| 754 | log->Printf("SBThread(%p)::StepOut ()", |
| 755 | static_cast<void *>(exe_ctx.GetThreadPtr())); |
Richard Mitton | f86248d | 2013-09-12 02:20:34 +0000 | [diff] [blame] | 756 | |
Alexander Polyakov | 859f54b | 2018-06-20 21:43:16 +0000 | [diff] [blame] | 757 | if (!exe_ctx.HasThreadScope()) { |
| 758 | error.SetErrorString("this SBThread object is invalid"); |
| 759 | return; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 760 | } |
Alexander Polyakov | 859f54b | 2018-06-20 21:43:16 +0000 | [diff] [blame] | 761 | |
| 762 | bool abort_other_plans = false; |
| 763 | bool stop_other_threads = false; |
| 764 | |
| 765 | Thread *thread = exe_ctx.GetThreadPtr(); |
| 766 | |
| 767 | const LazyBool avoid_no_debug = eLazyBoolCalculate; |
Jonas Devlieghere | e103ae9 | 2018-11-15 01:18:15 +0000 | [diff] [blame] | 768 | Status new_plan_status; |
Alexander Polyakov | 859f54b | 2018-06-20 21:43:16 +0000 | [diff] [blame] | 769 | ThreadPlanSP new_plan_sp(thread->QueueThreadPlanForStepOut( |
| 770 | abort_other_plans, NULL, false, stop_other_threads, eVoteYes, |
Jonas Devlieghere | e103ae9 | 2018-11-15 01:18:15 +0000 | [diff] [blame] | 771 | eVoteNoOpinion, 0, new_plan_status, avoid_no_debug)); |
Alexander Polyakov | 859f54b | 2018-06-20 21:43:16 +0000 | [diff] [blame] | 772 | |
Jonas Devlieghere | e103ae9 | 2018-11-15 01:18:15 +0000 | [diff] [blame] | 773 | if (new_plan_status.Success()) |
| 774 | error = ResumeNewPlan(exe_ctx, new_plan_sp.get()); |
| 775 | else |
| 776 | error.SetErrorString(new_plan_status.AsCString()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 777 | } |
| 778 | |
Alexander Polyakov | 859f54b | 2018-06-20 21:43:16 +0000 | [diff] [blame] | 779 | void SBThread::StepOutOfFrame(SBFrame &sb_frame) { |
| 780 | SBError error; // Ignored |
| 781 | StepOutOfFrame(sb_frame, error); |
| 782 | } |
| 783 | |
| 784 | void SBThread::StepOutOfFrame(SBFrame &sb_frame, SBError &error) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 785 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
| 786 | |
| 787 | std::unique_lock<std::recursive_mutex> lock; |
| 788 | ExecutionContext exe_ctx(m_opaque_sp.get(), lock); |
| 789 | |
| 790 | if (!sb_frame.IsValid()) { |
| 791 | if (log) |
| 792 | log->Printf( |
| 793 | "SBThread(%p)::StepOutOfFrame passed an invalid frame, returning.", |
| 794 | static_cast<void *>(exe_ctx.GetThreadPtr())); |
Alexander Polyakov | 859f54b | 2018-06-20 21:43:16 +0000 | [diff] [blame] | 795 | error.SetErrorString("passed invalid SBFrame object"); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 796 | return; |
| 797 | } |
| 798 | |
| 799 | StackFrameSP frame_sp(sb_frame.GetFrameSP()); |
| 800 | if (log) { |
| 801 | SBStream frame_desc_strm; |
| 802 | sb_frame.GetDescription(frame_desc_strm); |
| 803 | log->Printf("SBThread(%p)::StepOutOfFrame (frame = SBFrame(%p): %s)", |
| 804 | static_cast<void *>(exe_ctx.GetThreadPtr()), |
| 805 | static_cast<void *>(frame_sp.get()), frame_desc_strm.GetData()); |
| 806 | } |
| 807 | |
Alexander Polyakov | 859f54b | 2018-06-20 21:43:16 +0000 | [diff] [blame] | 808 | if (!exe_ctx.HasThreadScope()) { |
| 809 | error.SetErrorString("this SBThread object is invalid"); |
| 810 | return; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 811 | } |
Alexander Polyakov | 859f54b | 2018-06-20 21:43:16 +0000 | [diff] [blame] | 812 | |
| 813 | bool abort_other_plans = false; |
| 814 | bool stop_other_threads = false; |
| 815 | Thread *thread = exe_ctx.GetThreadPtr(); |
| 816 | if (sb_frame.GetThread().GetThreadID() != thread->GetID()) { |
| 817 | log->Printf("SBThread(%p)::StepOutOfFrame passed a frame from another " |
| 818 | "thread (0x%" PRIx64 " vrs. 0x%" PRIx64 ", returning.", |
| 819 | static_cast<void *>(exe_ctx.GetThreadPtr()), |
| 820 | sb_frame.GetThread().GetThreadID(), thread->GetID()); |
| 821 | error.SetErrorString("passed a frame from another thread"); |
| 822 | return; |
| 823 | } |
| 824 | |
Jonas Devlieghere | e103ae9 | 2018-11-15 01:18:15 +0000 | [diff] [blame] | 825 | Status new_plan_status; |
Alexander Polyakov | 859f54b | 2018-06-20 21:43:16 +0000 | [diff] [blame] | 826 | ThreadPlanSP new_plan_sp(thread->QueueThreadPlanForStepOut( |
| 827 | abort_other_plans, NULL, false, stop_other_threads, eVoteYes, |
Jonas Devlieghere | e103ae9 | 2018-11-15 01:18:15 +0000 | [diff] [blame] | 828 | eVoteNoOpinion, frame_sp->GetFrameIndex(), new_plan_status)); |
Alexander Polyakov | 859f54b | 2018-06-20 21:43:16 +0000 | [diff] [blame] | 829 | |
Jonas Devlieghere | e103ae9 | 2018-11-15 01:18:15 +0000 | [diff] [blame] | 830 | if (new_plan_status.Success()) |
| 831 | error = ResumeNewPlan(exe_ctx, new_plan_sp.get()); |
| 832 | else |
| 833 | error.SetErrorString(new_plan_status.AsCString()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 834 | } |
| 835 | |
| 836 | void SBThread::StepInstruction(bool step_over) { |
Alexander Polyakov | 859f54b | 2018-06-20 21:43:16 +0000 | [diff] [blame] | 837 | SBError error; // Ignored |
| 838 | StepInstruction(step_over, error); |
| 839 | } |
| 840 | |
| 841 | void SBThread::StepInstruction(bool step_over, SBError &error) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 842 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
| 843 | |
| 844 | std::unique_lock<std::recursive_mutex> lock; |
| 845 | ExecutionContext exe_ctx(m_opaque_sp.get(), lock); |
| 846 | |
| 847 | if (log) |
| 848 | log->Printf("SBThread(%p)::StepInstruction (step_over=%i)", |
| 849 | static_cast<void *>(exe_ctx.GetThreadPtr()), step_over); |
| 850 | |
Alexander Polyakov | 859f54b | 2018-06-20 21:43:16 +0000 | [diff] [blame] | 851 | if (!exe_ctx.HasThreadScope()) { |
| 852 | error.SetErrorString("this SBThread object is invalid"); |
| 853 | return; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 854 | } |
Alexander Polyakov | 859f54b | 2018-06-20 21:43:16 +0000 | [diff] [blame] | 855 | |
| 856 | Thread *thread = exe_ctx.GetThreadPtr(); |
Jonas Devlieghere | e103ae9 | 2018-11-15 01:18:15 +0000 | [diff] [blame] | 857 | Status new_plan_status; |
| 858 | ThreadPlanSP new_plan_sp(thread->QueueThreadPlanForStepSingleInstruction( |
| 859 | step_over, true, true, new_plan_status)); |
Alexander Polyakov | 859f54b | 2018-06-20 21:43:16 +0000 | [diff] [blame] | 860 | |
Jonas Devlieghere | e103ae9 | 2018-11-15 01:18:15 +0000 | [diff] [blame] | 861 | if (new_plan_status.Success()) |
| 862 | error = ResumeNewPlan(exe_ctx, new_plan_sp.get()); |
| 863 | else |
| 864 | error.SetErrorString(new_plan_status.AsCString()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 865 | } |
| 866 | |
| 867 | void SBThread::RunToAddress(lldb::addr_t addr) { |
Alexander Polyakov | 859f54b | 2018-06-20 21:43:16 +0000 | [diff] [blame] | 868 | SBError error; // Ignored |
| 869 | RunToAddress(addr, error); |
| 870 | } |
| 871 | |
| 872 | void SBThread::RunToAddress(lldb::addr_t addr, SBError &error) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 873 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
| 874 | |
| 875 | std::unique_lock<std::recursive_mutex> lock; |
| 876 | ExecutionContext exe_ctx(m_opaque_sp.get(), lock); |
| 877 | |
| 878 | if (log) |
| 879 | log->Printf("SBThread(%p)::RunToAddress (addr=0x%" PRIx64 ")", |
| 880 | static_cast<void *>(exe_ctx.GetThreadPtr()), addr); |
| 881 | |
Alexander Polyakov | 859f54b | 2018-06-20 21:43:16 +0000 | [diff] [blame] | 882 | if (!exe_ctx.HasThreadScope()) { |
| 883 | error.SetErrorString("this SBThread object is invalid"); |
| 884 | return; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 885 | } |
Alexander Polyakov | 859f54b | 2018-06-20 21:43:16 +0000 | [diff] [blame] | 886 | |
| 887 | bool abort_other_plans = false; |
| 888 | bool stop_other_threads = true; |
| 889 | |
| 890 | Address target_addr(addr); |
| 891 | |
| 892 | Thread *thread = exe_ctx.GetThreadPtr(); |
| 893 | |
Jonas Devlieghere | e103ae9 | 2018-11-15 01:18:15 +0000 | [diff] [blame] | 894 | Status new_plan_status; |
Alexander Polyakov | 859f54b | 2018-06-20 21:43:16 +0000 | [diff] [blame] | 895 | ThreadPlanSP new_plan_sp(thread->QueueThreadPlanForRunToAddress( |
Jonas Devlieghere | e103ae9 | 2018-11-15 01:18:15 +0000 | [diff] [blame] | 896 | abort_other_plans, target_addr, stop_other_threads, new_plan_status)); |
Alexander Polyakov | 859f54b | 2018-06-20 21:43:16 +0000 | [diff] [blame] | 897 | |
Jonas Devlieghere | e103ae9 | 2018-11-15 01:18:15 +0000 | [diff] [blame] | 898 | if (new_plan_status.Success()) |
| 899 | error = ResumeNewPlan(exe_ctx, new_plan_sp.get()); |
| 900 | else |
| 901 | error.SetErrorString(new_plan_status.AsCString()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 902 | } |
| 903 | |
| 904 | SBError SBThread::StepOverUntil(lldb::SBFrame &sb_frame, |
| 905 | lldb::SBFileSpec &sb_file_spec, uint32_t line) { |
| 906 | SBError sb_error; |
| 907 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
| 908 | char path[PATH_MAX]; |
| 909 | |
| 910 | std::unique_lock<std::recursive_mutex> lock; |
| 911 | ExecutionContext exe_ctx(m_opaque_sp.get(), lock); |
| 912 | |
| 913 | StackFrameSP frame_sp(sb_frame.GetFrameSP()); |
| 914 | |
| 915 | if (log) { |
| 916 | SBStream frame_desc_strm; |
| 917 | sb_frame.GetDescription(frame_desc_strm); |
| 918 | sb_file_spec->GetPath(path, sizeof(path)); |
| 919 | log->Printf("SBThread(%p)::StepOverUntil (frame = SBFrame(%p): %s, " |
| 920 | "file+line = %s:%u)", |
| 921 | static_cast<void *>(exe_ctx.GetThreadPtr()), |
| 922 | static_cast<void *>(frame_sp.get()), frame_desc_strm.GetData(), |
| 923 | path, line); |
| 924 | } |
| 925 | |
| 926 | if (exe_ctx.HasThreadScope()) { |
| 927 | Target *target = exe_ctx.GetTargetPtr(); |
| 928 | Thread *thread = exe_ctx.GetThreadPtr(); |
| 929 | |
| 930 | if (line == 0) { |
| 931 | sb_error.SetErrorString("invalid line argument"); |
| 932 | return sb_error; |
| 933 | } |
| 934 | |
| 935 | if (!frame_sp) { |
| 936 | frame_sp = thread->GetSelectedFrame(); |
| 937 | if (!frame_sp) |
| 938 | frame_sp = thread->GetStackFrameAtIndex(0); |
| 939 | } |
| 940 | |
| 941 | SymbolContext frame_sc; |
| 942 | if (!frame_sp) { |
| 943 | sb_error.SetErrorString("no valid frames in thread to step"); |
| 944 | return sb_error; |
| 945 | } |
| 946 | |
| 947 | // If we have a frame, get its line |
| 948 | frame_sc = frame_sp->GetSymbolContext( |
| 949 | eSymbolContextCompUnit | eSymbolContextFunction | |
| 950 | eSymbolContextLineEntry | eSymbolContextSymbol); |
| 951 | |
| 952 | if (frame_sc.comp_unit == NULL) { |
| 953 | sb_error.SetErrorStringWithFormat( |
| 954 | "frame %u doesn't have debug information", frame_sp->GetFrameIndex()); |
| 955 | return sb_error; |
| 956 | } |
| 957 | |
| 958 | FileSpec step_file_spec; |
| 959 | if (sb_file_spec.IsValid()) { |
| 960 | // The file spec passed in was valid, so use it |
| 961 | step_file_spec = sb_file_spec.ref(); |
| 962 | } else { |
| 963 | if (frame_sc.line_entry.IsValid()) |
| 964 | step_file_spec = frame_sc.line_entry.file; |
| 965 | else { |
| 966 | sb_error.SetErrorString("invalid file argument or no file for frame"); |
| 967 | return sb_error; |
| 968 | } |
| 969 | } |
| 970 | |
| 971 | // Grab the current function, then we will make sure the "until" address is |
| 972 | // within the function. We discard addresses that are out of the current |
| 973 | // function, and then if there are no addresses remaining, give an |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 974 | // appropriate error message. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 975 | |
| 976 | bool all_in_function = true; |
| 977 | AddressRange fun_range = frame_sc.function->GetAddressRange(); |
| 978 | |
| 979 | std::vector<addr_t> step_over_until_addrs; |
| 980 | const bool abort_other_plans = false; |
| 981 | const bool stop_other_threads = false; |
| 982 | const bool check_inlines = true; |
| 983 | const bool exact = false; |
| 984 | |
| 985 | SymbolContextList sc_list; |
| 986 | const uint32_t num_matches = frame_sc.comp_unit->ResolveSymbolContext( |
| 987 | step_file_spec, line, check_inlines, exact, eSymbolContextLineEntry, |
| 988 | sc_list); |
| 989 | if (num_matches > 0) { |
| 990 | SymbolContext sc; |
| 991 | for (uint32_t i = 0; i < num_matches; ++i) { |
| 992 | if (sc_list.GetContextAtIndex(i, sc)) { |
| 993 | addr_t step_addr = |
| 994 | sc.line_entry.range.GetBaseAddress().GetLoadAddress(target); |
| 995 | if (step_addr != LLDB_INVALID_ADDRESS) { |
| 996 | if (fun_range.ContainsLoadAddress(step_addr, target)) |
| 997 | step_over_until_addrs.push_back(step_addr); |
| 998 | else |
| 999 | all_in_function = false; |
| 1000 | } |
| 1001 | } |
| 1002 | } |
| 1003 | } |
| 1004 | |
| 1005 | if (step_over_until_addrs.empty()) { |
| 1006 | if (all_in_function) { |
| 1007 | step_file_spec.GetPath(path, sizeof(path)); |
| 1008 | sb_error.SetErrorStringWithFormat("No line entries for %s:%u", path, |
| 1009 | line); |
| 1010 | } else |
| 1011 | sb_error.SetErrorString("step until target not in current function"); |
| 1012 | } else { |
Jonas Devlieghere | e103ae9 | 2018-11-15 01:18:15 +0000 | [diff] [blame] | 1013 | Status new_plan_status; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1014 | ThreadPlanSP new_plan_sp(thread->QueueThreadPlanForStepUntil( |
| 1015 | abort_other_plans, &step_over_until_addrs[0], |
| 1016 | step_over_until_addrs.size(), stop_other_threads, |
Jonas Devlieghere | e103ae9 | 2018-11-15 01:18:15 +0000 | [diff] [blame] | 1017 | frame_sp->GetFrameIndex(), new_plan_status)); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1018 | |
Jonas Devlieghere | e103ae9 | 2018-11-15 01:18:15 +0000 | [diff] [blame] | 1019 | if (new_plan_status.Success()) |
| 1020 | sb_error = ResumeNewPlan(exe_ctx, new_plan_sp.get()); |
| 1021 | else |
| 1022 | sb_error.SetErrorString(new_plan_status.AsCString()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1023 | } |
| 1024 | } else { |
| 1025 | sb_error.SetErrorString("this SBThread object is invalid"); |
| 1026 | } |
| 1027 | return sb_error; |
| 1028 | } |
| 1029 | |
| 1030 | SBError SBThread::StepUsingScriptedThreadPlan(const char *script_class_name) { |
| 1031 | return StepUsingScriptedThreadPlan(script_class_name, true); |
| 1032 | } |
| 1033 | |
| 1034 | SBError SBThread::StepUsingScriptedThreadPlan(const char *script_class_name, |
| 1035 | bool resume_immediately) { |
| 1036 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
Jonas Devlieghere | e103ae9 | 2018-11-15 01:18:15 +0000 | [diff] [blame] | 1037 | SBError error; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1038 | |
| 1039 | std::unique_lock<std::recursive_mutex> lock; |
| 1040 | ExecutionContext exe_ctx(m_opaque_sp.get(), lock); |
| 1041 | |
| 1042 | if (log) { |
| 1043 | log->Printf("SBThread(%p)::StepUsingScriptedThreadPlan: class name: %s", |
| 1044 | static_cast<void *>(exe_ctx.GetThreadPtr()), script_class_name); |
| 1045 | } |
| 1046 | |
| 1047 | if (!exe_ctx.HasThreadScope()) { |
Jonas Devlieghere | e103ae9 | 2018-11-15 01:18:15 +0000 | [diff] [blame] | 1048 | error.SetErrorString("this SBThread object is invalid"); |
| 1049 | return error; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1050 | } |
Richard Mitton | f86248d | 2013-09-12 02:20:34 +0000 | [diff] [blame] | 1051 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1052 | Thread *thread = exe_ctx.GetThreadPtr(); |
Jonas Devlieghere | e103ae9 | 2018-11-15 01:18:15 +0000 | [diff] [blame] | 1053 | Status new_plan_status; |
| 1054 | ThreadPlanSP new_plan_sp = thread->QueueThreadPlanForStepScripted( |
| 1055 | false, script_class_name, false, new_plan_status); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 1056 | |
Jonas Devlieghere | e103ae9 | 2018-11-15 01:18:15 +0000 | [diff] [blame] | 1057 | if (new_plan_status.Fail()) { |
| 1058 | error.SetErrorString(new_plan_status.AsCString()); |
| 1059 | return error; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1060 | } |
Jim Ingham | 4413758 | 2012-09-12 00:40:39 +0000 | [diff] [blame] | 1061 | |
Jonas Devlieghere | e103ae9 | 2018-11-15 01:18:15 +0000 | [diff] [blame] | 1062 | if (!resume_immediately) |
| 1063 | return error; |
Jim Ingham | 4ac8e93 | 2016-07-08 02:12:05 +0000 | [diff] [blame] | 1064 | |
Jonas Devlieghere | e103ae9 | 2018-11-15 01:18:15 +0000 | [diff] [blame] | 1065 | if (new_plan_status.Success()) |
| 1066 | error = ResumeNewPlan(exe_ctx, new_plan_sp.get()); |
| 1067 | else |
| 1068 | error.SetErrorString(new_plan_status.AsCString()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1069 | |
Jonas Devlieghere | e103ae9 | 2018-11-15 01:18:15 +0000 | [diff] [blame] | 1070 | return error; |
Greg Clayton | 722a0cd | 2011-01-12 02:25:42 +0000 | [diff] [blame] | 1071 | } |
| 1072 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1073 | SBError SBThread::JumpToLine(lldb::SBFileSpec &file_spec, uint32_t line) { |
| 1074 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
| 1075 | SBError sb_error; |
Jim Ingham | b2e7d28 | 2016-06-10 17:22:26 +0000 | [diff] [blame] | 1076 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1077 | std::unique_lock<std::recursive_mutex> lock; |
| 1078 | ExecutionContext exe_ctx(m_opaque_sp.get(), lock); |
| 1079 | |
| 1080 | if (log) |
| 1081 | log->Printf("SBThread(%p)::JumpToLine (file+line = %s:%u)", |
| 1082 | static_cast<void *>(exe_ctx.GetThreadPtr()), |
| 1083 | file_spec->GetPath().c_str(), line); |
| 1084 | |
| 1085 | if (!exe_ctx.HasThreadScope()) { |
| 1086 | sb_error.SetErrorString("this SBThread object is invalid"); |
| 1087 | return sb_error; |
| 1088 | } |
| 1089 | |
| 1090 | Thread *thread = exe_ctx.GetThreadPtr(); |
| 1091 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 1092 | Status err = thread->JumpToLine(file_spec.get(), line, true); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1093 | sb_error.SetError(err); |
| 1094 | return sb_error; |
Greg Clayton | 722a0cd | 2011-01-12 02:25:42 +0000 | [diff] [blame] | 1095 | } |
| 1096 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1097 | SBError SBThread::ReturnFromFrame(SBFrame &frame, SBValue &return_value) { |
| 1098 | SBError sb_error; |
Jim Ingham | b2e7d28 | 2016-06-10 17:22:26 +0000 | [diff] [blame] | 1099 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1100 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
| 1101 | |
| 1102 | std::unique_lock<std::recursive_mutex> lock; |
| 1103 | ExecutionContext exe_ctx(m_opaque_sp.get(), lock); |
| 1104 | |
| 1105 | if (log) |
| 1106 | log->Printf("SBThread(%p)::ReturnFromFrame (frame=%d)", |
| 1107 | static_cast<void *>(exe_ctx.GetThreadPtr()), |
| 1108 | frame.GetFrameID()); |
| 1109 | |
| 1110 | if (exe_ctx.HasThreadScope()) { |
| 1111 | Thread *thread = exe_ctx.GetThreadPtr(); |
| 1112 | sb_error.SetError( |
| 1113 | thread->ReturnFromFrame(frame.GetFrameSP(), return_value.GetSP())); |
| 1114 | } |
| 1115 | |
| 1116 | return sb_error; |
Greg Clayton | 722a0cd | 2011-01-12 02:25:42 +0000 | [diff] [blame] | 1117 | } |
| 1118 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1119 | SBError SBThread::UnwindInnermostExpression() { |
| 1120 | SBError sb_error; |
Jim Ingham | b2e7d28 | 2016-06-10 17:22:26 +0000 | [diff] [blame] | 1121 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1122 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
| 1123 | |
| 1124 | std::unique_lock<std::recursive_mutex> lock; |
| 1125 | ExecutionContext exe_ctx(m_opaque_sp.get(), lock); |
| 1126 | |
| 1127 | if (log) |
| 1128 | log->Printf("SBThread(%p)::UnwindExpressionEvaluation", |
| 1129 | static_cast<void *>(exe_ctx.GetThreadPtr())); |
| 1130 | |
| 1131 | if (exe_ctx.HasThreadScope()) { |
| 1132 | Thread *thread = exe_ctx.GetThreadPtr(); |
| 1133 | sb_error.SetError(thread->UnwindInnermostExpression()); |
| 1134 | if (sb_error.Success()) |
| 1135 | thread->SetSelectedFrameByIndex(0, false); |
| 1136 | } |
| 1137 | |
| 1138 | return sb_error; |
Andrew Kaylor | a75418d | 2013-04-15 23:33:53 +0000 | [diff] [blame] | 1139 | } |
| 1140 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1141 | bool SBThread::Suspend() { |
Alexander Polyakov | 859f54b | 2018-06-20 21:43:16 +0000 | [diff] [blame] | 1142 | SBError error; // Ignored |
| 1143 | return Suspend(error); |
| 1144 | } |
| 1145 | |
| 1146 | bool SBThread::Suspend(SBError &error) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1147 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
| 1148 | std::unique_lock<std::recursive_mutex> lock; |
| 1149 | ExecutionContext exe_ctx(m_opaque_sp.get(), lock); |
Jim Ingham | b2e7d28 | 2016-06-10 17:22:26 +0000 | [diff] [blame] | 1150 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1151 | bool result = false; |
| 1152 | if (exe_ctx.HasThreadScope()) { |
| 1153 | Process::StopLocker stop_locker; |
| 1154 | if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock())) { |
| 1155 | exe_ctx.GetThreadPtr()->SetResumeState(eStateSuspended); |
| 1156 | result = true; |
| 1157 | } else { |
Alexander Polyakov | 859f54b | 2018-06-20 21:43:16 +0000 | [diff] [blame] | 1158 | error.SetErrorString("process is running"); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1159 | if (log) |
| 1160 | log->Printf("SBThread(%p)::Suspend() => error: process is running", |
| 1161 | static_cast<void *>(exe_ctx.GetThreadPtr())); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1162 | } |
Alexander Polyakov | 859f54b | 2018-06-20 21:43:16 +0000 | [diff] [blame] | 1163 | } else |
| 1164 | error.SetErrorString("this SBThread object is invalid"); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1165 | if (log) |
| 1166 | log->Printf("SBThread(%p)::Suspend() => %i", |
| 1167 | static_cast<void *>(exe_ctx.GetThreadPtr()), result); |
| 1168 | return result; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1169 | } |
| 1170 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1171 | bool SBThread::Resume() { |
Alexander Polyakov | 859f54b | 2018-06-20 21:43:16 +0000 | [diff] [blame] | 1172 | SBError error; // Ignored |
| 1173 | return Resume(error); |
| 1174 | } |
| 1175 | |
| 1176 | bool SBThread::Resume(SBError &error) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1177 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
| 1178 | std::unique_lock<std::recursive_mutex> lock; |
| 1179 | ExecutionContext exe_ctx(m_opaque_sp.get(), lock); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 1180 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1181 | bool result = false; |
| 1182 | if (exe_ctx.HasThreadScope()) { |
| 1183 | Process::StopLocker stop_locker; |
| 1184 | if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock())) { |
| 1185 | const bool override_suspend = true; |
| 1186 | exe_ctx.GetThreadPtr()->SetResumeState(eStateRunning, override_suspend); |
| 1187 | result = true; |
| 1188 | } else { |
Alexander Polyakov | 859f54b | 2018-06-20 21:43:16 +0000 | [diff] [blame] | 1189 | error.SetErrorString("process is running"); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1190 | if (log) |
| 1191 | log->Printf("SBThread(%p)::Resume() => error: process is running", |
| 1192 | static_cast<void *>(exe_ctx.GetThreadPtr())); |
Greg Clayton | af67cec | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 1193 | } |
Alexander Polyakov | 859f54b | 2018-06-20 21:43:16 +0000 | [diff] [blame] | 1194 | } else |
| 1195 | error.SetErrorString("this SBThread object is invalid"); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1196 | if (log) |
| 1197 | log->Printf("SBThread(%p)::Resume() => %i", |
| 1198 | static_cast<void *>(exe_ctx.GetThreadPtr()), result); |
| 1199 | return result; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1200 | } |
| 1201 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1202 | bool SBThread::IsSuspended() { |
| 1203 | std::unique_lock<std::recursive_mutex> lock; |
| 1204 | ExecutionContext exe_ctx(m_opaque_sp.get(), lock); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 1205 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1206 | if (exe_ctx.HasThreadScope()) |
| 1207 | return exe_ctx.GetThreadPtr()->GetResumeState() == eStateSuspended; |
| 1208 | return false; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1209 | } |
| 1210 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1211 | bool SBThread::IsStopped() { |
| 1212 | std::unique_lock<std::recursive_mutex> lock; |
| 1213 | ExecutionContext exe_ctx(m_opaque_sp.get(), lock); |
Greg Clayton | f028a1f | 2010-12-17 02:26:24 +0000 | [diff] [blame] | 1214 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1215 | if (exe_ctx.HasThreadScope()) |
| 1216 | return StateIsStoppedState(exe_ctx.GetThreadPtr()->GetState(), true); |
| 1217 | return false; |
Greg Clayton | f028a1f | 2010-12-17 02:26:24 +0000 | [diff] [blame] | 1218 | } |
| 1219 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1220 | SBProcess SBThread::GetProcess() { |
| 1221 | SBProcess sb_process; |
| 1222 | std::unique_lock<std::recursive_mutex> lock; |
| 1223 | ExecutionContext exe_ctx(m_opaque_sp.get(), lock); |
Greg Clayton | f028a1f | 2010-12-17 02:26:24 +0000 | [diff] [blame] | 1224 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1225 | if (exe_ctx.HasThreadScope()) { |
| 1226 | // Have to go up to the target so we can get a shared pointer to our |
| 1227 | // process... |
| 1228 | sb_process.SetSP(exe_ctx.GetProcessSP()); |
| 1229 | } |
Jim Ingham | 4fc6cb9 | 2012-08-22 21:34:33 +0000 | [diff] [blame] | 1230 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1231 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
| 1232 | if (log) { |
| 1233 | SBStream frame_desc_strm; |
| 1234 | sb_process.GetDescription(frame_desc_strm); |
| 1235 | log->Printf("SBThread(%p)::GetProcess () => SBProcess(%p): %s", |
| 1236 | static_cast<void *>(exe_ctx.GetThreadPtr()), |
| 1237 | static_cast<void *>(sb_process.GetSP().get()), |
| 1238 | frame_desc_strm.GetData()); |
| 1239 | } |
| 1240 | |
| 1241 | return sb_process; |
| 1242 | } |
| 1243 | |
| 1244 | uint32_t SBThread::GetNumFrames() { |
| 1245 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
| 1246 | |
| 1247 | uint32_t num_frames = 0; |
| 1248 | std::unique_lock<std::recursive_mutex> lock; |
| 1249 | ExecutionContext exe_ctx(m_opaque_sp.get(), lock); |
| 1250 | |
| 1251 | if (exe_ctx.HasThreadScope()) { |
| 1252 | Process::StopLocker stop_locker; |
| 1253 | if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock())) { |
| 1254 | num_frames = exe_ctx.GetThreadPtr()->GetStackFrameCount(); |
| 1255 | } else { |
| 1256 | if (log) |
| 1257 | log->Printf("SBThread(%p)::GetNumFrames() => error: process is running", |
| 1258 | static_cast<void *>(exe_ctx.GetThreadPtr())); |
| 1259 | } |
| 1260 | } |
| 1261 | |
| 1262 | if (log) |
| 1263 | log->Printf("SBThread(%p)::GetNumFrames () => %u", |
| 1264 | static_cast<void *>(exe_ctx.GetThreadPtr()), num_frames); |
| 1265 | |
| 1266 | return num_frames; |
| 1267 | } |
| 1268 | |
| 1269 | SBFrame SBThread::GetFrameAtIndex(uint32_t idx) { |
| 1270 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
| 1271 | |
| 1272 | SBFrame sb_frame; |
| 1273 | StackFrameSP frame_sp; |
| 1274 | std::unique_lock<std::recursive_mutex> lock; |
| 1275 | ExecutionContext exe_ctx(m_opaque_sp.get(), lock); |
| 1276 | |
| 1277 | if (exe_ctx.HasThreadScope()) { |
| 1278 | Process::StopLocker stop_locker; |
| 1279 | if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock())) { |
| 1280 | frame_sp = exe_ctx.GetThreadPtr()->GetStackFrameAtIndex(idx); |
| 1281 | sb_frame.SetFrameSP(frame_sp); |
| 1282 | } else { |
| 1283 | if (log) |
| 1284 | log->Printf( |
| 1285 | "SBThread(%p)::GetFrameAtIndex() => error: process is running", |
| 1286 | static_cast<void *>(exe_ctx.GetThreadPtr())); |
| 1287 | } |
| 1288 | } |
| 1289 | |
| 1290 | if (log) { |
| 1291 | SBStream frame_desc_strm; |
| 1292 | sb_frame.GetDescription(frame_desc_strm); |
| 1293 | log->Printf("SBThread(%p)::GetFrameAtIndex (idx=%d) => SBFrame(%p): %s", |
| 1294 | static_cast<void *>(exe_ctx.GetThreadPtr()), idx, |
| 1295 | static_cast<void *>(frame_sp.get()), frame_desc_strm.GetData()); |
| 1296 | } |
| 1297 | |
| 1298 | return sb_frame; |
| 1299 | } |
| 1300 | |
| 1301 | lldb::SBFrame SBThread::GetSelectedFrame() { |
| 1302 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
| 1303 | |
| 1304 | SBFrame sb_frame; |
| 1305 | StackFrameSP frame_sp; |
| 1306 | std::unique_lock<std::recursive_mutex> lock; |
| 1307 | ExecutionContext exe_ctx(m_opaque_sp.get(), lock); |
| 1308 | |
| 1309 | if (exe_ctx.HasThreadScope()) { |
| 1310 | Process::StopLocker stop_locker; |
| 1311 | if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock())) { |
| 1312 | frame_sp = exe_ctx.GetThreadPtr()->GetSelectedFrame(); |
| 1313 | sb_frame.SetFrameSP(frame_sp); |
| 1314 | } else { |
| 1315 | if (log) |
| 1316 | log->Printf( |
| 1317 | "SBThread(%p)::GetSelectedFrame() => error: process is running", |
| 1318 | static_cast<void *>(exe_ctx.GetThreadPtr())); |
| 1319 | } |
| 1320 | } |
| 1321 | |
| 1322 | if (log) { |
| 1323 | SBStream frame_desc_strm; |
| 1324 | sb_frame.GetDescription(frame_desc_strm); |
| 1325 | log->Printf("SBThread(%p)::GetSelectedFrame () => SBFrame(%p): %s", |
| 1326 | static_cast<void *>(exe_ctx.GetThreadPtr()), |
| 1327 | static_cast<void *>(frame_sp.get()), frame_desc_strm.GetData()); |
| 1328 | } |
| 1329 | |
| 1330 | return sb_frame; |
| 1331 | } |
| 1332 | |
| 1333 | lldb::SBFrame SBThread::SetSelectedFrame(uint32_t idx) { |
| 1334 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
| 1335 | |
| 1336 | SBFrame sb_frame; |
| 1337 | StackFrameSP frame_sp; |
| 1338 | std::unique_lock<std::recursive_mutex> lock; |
| 1339 | ExecutionContext exe_ctx(m_opaque_sp.get(), lock); |
| 1340 | |
| 1341 | if (exe_ctx.HasThreadScope()) { |
| 1342 | Process::StopLocker stop_locker; |
| 1343 | if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock())) { |
| 1344 | Thread *thread = exe_ctx.GetThreadPtr(); |
| 1345 | frame_sp = thread->GetStackFrameAtIndex(idx); |
| 1346 | if (frame_sp) { |
| 1347 | thread->SetSelectedFrame(frame_sp.get()); |
| 1348 | sb_frame.SetFrameSP(frame_sp); |
| 1349 | } |
| 1350 | } else { |
| 1351 | if (log) |
| 1352 | log->Printf( |
| 1353 | "SBThread(%p)::SetSelectedFrame() => error: process is running", |
| 1354 | static_cast<void *>(exe_ctx.GetThreadPtr())); |
| 1355 | } |
| 1356 | } |
| 1357 | |
| 1358 | if (log) { |
| 1359 | SBStream frame_desc_strm; |
| 1360 | sb_frame.GetDescription(frame_desc_strm); |
| 1361 | log->Printf("SBThread(%p)::SetSelectedFrame (idx=%u) => SBFrame(%p): %s", |
| 1362 | static_cast<void *>(exe_ctx.GetThreadPtr()), idx, |
| 1363 | static_cast<void *>(frame_sp.get()), frame_desc_strm.GetData()); |
| 1364 | } |
| 1365 | return sb_frame; |
| 1366 | } |
| 1367 | |
| 1368 | bool SBThread::EventIsThreadEvent(const SBEvent &event) { |
| 1369 | return Thread::ThreadEventData::GetEventDataFromEvent(event.get()) != NULL; |
| 1370 | } |
| 1371 | |
| 1372 | SBFrame SBThread::GetStackFrameFromEvent(const SBEvent &event) { |
| 1373 | return Thread::ThreadEventData::GetStackFrameFromEvent(event.get()); |
| 1374 | } |
| 1375 | |
| 1376 | SBThread SBThread::GetThreadFromEvent(const SBEvent &event) { |
| 1377 | return Thread::ThreadEventData::GetThreadFromEvent(event.get()); |
| 1378 | } |
| 1379 | |
| 1380 | bool SBThread::operator==(const SBThread &rhs) const { |
| 1381 | return m_opaque_sp->GetThreadSP().get() == |
| 1382 | rhs.m_opaque_sp->GetThreadSP().get(); |
| 1383 | } |
| 1384 | |
| 1385 | bool SBThread::operator!=(const SBThread &rhs) const { |
| 1386 | return m_opaque_sp->GetThreadSP().get() != |
| 1387 | rhs.m_opaque_sp->GetThreadSP().get(); |
| 1388 | } |
| 1389 | |
| 1390 | bool SBThread::GetStatus(SBStream &status) const { |
| 1391 | Stream &strm = status.ref(); |
| 1392 | |
| 1393 | std::unique_lock<std::recursive_mutex> lock; |
| 1394 | ExecutionContext exe_ctx(m_opaque_sp.get(), lock); |
| 1395 | |
| 1396 | if (exe_ctx.HasThreadScope()) { |
Jim Ingham | 6a9767c | 2016-11-08 20:36:40 +0000 | [diff] [blame] | 1397 | exe_ctx.GetThreadPtr()->GetStatus(strm, 0, 1, 1, true); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1398 | } else |
| 1399 | strm.PutCString("No status"); |
| 1400 | |
| 1401 | return true; |
| 1402 | } |
| 1403 | |
| 1404 | bool SBThread::GetDescription(SBStream &description) const { |
Jim Ingham | 6a9767c | 2016-11-08 20:36:40 +0000 | [diff] [blame] | 1405 | return GetDescription(description, false); |
| 1406 | } |
| 1407 | |
| 1408 | bool SBThread::GetDescription(SBStream &description, bool stop_format) const { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1409 | Stream &strm = description.ref(); |
| 1410 | |
| 1411 | std::unique_lock<std::recursive_mutex> lock; |
| 1412 | ExecutionContext exe_ctx(m_opaque_sp.get(), lock); |
| 1413 | |
| 1414 | if (exe_ctx.HasThreadScope()) { |
| 1415 | exe_ctx.GetThreadPtr()->DumpUsingSettingsFormat(strm, |
Jim Ingham | 6a9767c | 2016-11-08 20:36:40 +0000 | [diff] [blame] | 1416 | LLDB_INVALID_THREAD_ID, |
| 1417 | stop_format); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1418 | // strm.Printf("SBThread: tid = 0x%4.4" PRIx64, |
| 1419 | // exe_ctx.GetThreadPtr()->GetID()); |
| 1420 | } else |
| 1421 | strm.PutCString("No value"); |
| 1422 | |
| 1423 | return true; |
| 1424 | } |
| 1425 | |
| 1426 | SBThread SBThread::GetExtendedBacktraceThread(const char *type) { |
| 1427 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
| 1428 | std::unique_lock<std::recursive_mutex> lock; |
| 1429 | ExecutionContext exe_ctx(m_opaque_sp.get(), lock); |
| 1430 | SBThread sb_origin_thread; |
| 1431 | |
| 1432 | if (exe_ctx.HasThreadScope()) { |
| 1433 | Process::StopLocker stop_locker; |
| 1434 | if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock())) { |
| 1435 | ThreadSP real_thread(exe_ctx.GetThreadSP()); |
| 1436 | if (real_thread) { |
| 1437 | ConstString type_const(type); |
| 1438 | Process *process = exe_ctx.GetProcessPtr(); |
| 1439 | if (process) { |
| 1440 | SystemRuntime *runtime = process->GetSystemRuntime(); |
| 1441 | if (runtime) { |
| 1442 | ThreadSP new_thread_sp( |
| 1443 | runtime->GetExtendedBacktraceThread(real_thread, type_const)); |
| 1444 | if (new_thread_sp) { |
| 1445 | // Save this in the Process' ExtendedThreadList so a strong |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 1446 | // pointer retains the object. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1447 | process->GetExtendedThreadList().AddThread(new_thread_sp); |
| 1448 | sb_origin_thread.SetThread(new_thread_sp); |
| 1449 | if (log) { |
| 1450 | const char *queue_name = new_thread_sp->GetQueueName(); |
| 1451 | if (queue_name == NULL) |
| 1452 | queue_name = ""; |
| 1453 | log->Printf("SBThread(%p)::GetExtendedBacktraceThread() => new " |
| 1454 | "extended Thread " |
| 1455 | "created (%p) with queue_id 0x%" PRIx64 |
| 1456 | " queue name '%s'", |
| 1457 | static_cast<void *>(exe_ctx.GetThreadPtr()), |
| 1458 | static_cast<void *>(new_thread_sp.get()), |
| 1459 | new_thread_sp->GetQueueID(), queue_name); |
| 1460 | } |
Greg Clayton | 7fdf9ef | 2012-04-05 16:12:35 +0000 | [diff] [blame] | 1461 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1462 | } |
Greg Clayton | f028a1f | 2010-12-17 02:26:24 +0000 | [diff] [blame] | 1463 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1464 | } |
| 1465 | } else { |
| 1466 | if (log) |
| 1467 | log->Printf("SBThread(%p)::GetExtendedBacktraceThread() => error: " |
| 1468 | "process is running", |
| 1469 | static_cast<void *>(exe_ctx.GetThreadPtr())); |
Greg Clayton | f028a1f | 2010-12-17 02:26:24 +0000 | [diff] [blame] | 1470 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1471 | } |
Greg Clayton | f028a1f | 2010-12-17 02:26:24 +0000 | [diff] [blame] | 1472 | |
Jonas Devlieghere | a6682a4 | 2018-12-15 00:15:33 +0000 | [diff] [blame^] | 1473 | if (log && !sb_origin_thread.IsValid()) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1474 | log->Printf("SBThread(%p)::GetExtendedBacktraceThread() is not returning a " |
| 1475 | "Valid thread", |
| 1476 | static_cast<void *>(exe_ctx.GetThreadPtr())); |
| 1477 | return sb_origin_thread; |
Greg Clayton | f028a1f | 2010-12-17 02:26:24 +0000 | [diff] [blame] | 1478 | } |
| 1479 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1480 | uint32_t SBThread::GetExtendedBacktraceOriginatingIndexID() { |
| 1481 | ThreadSP thread_sp(m_opaque_sp->GetThreadSP()); |
| 1482 | if (thread_sp) |
| 1483 | return thread_sp->GetExtendedBacktraceOriginatingIndexID(); |
| 1484 | return LLDB_INVALID_INDEX32; |
Jim Ingham | 4f465cf | 2012-10-10 18:32:14 +0000 | [diff] [blame] | 1485 | } |
| 1486 | |
Kuba Mracek | e60bc53 | 2018-11-28 22:01:52 +0000 | [diff] [blame] | 1487 | SBValue SBThread::GetCurrentException() { |
| 1488 | ThreadSP thread_sp(m_opaque_sp->GetThreadSP()); |
| 1489 | if (!thread_sp) return SBValue(); |
| 1490 | |
| 1491 | return SBValue(thread_sp->GetCurrentException()); |
| 1492 | } |
| 1493 | |
| 1494 | /* TODO(kubamracek) |
| 1495 | SBThread SBThread::GetCurrentExceptionBacktrace() { |
| 1496 | ThreadSP thread_sp(m_opaque_sp->GetThreadSP()); |
| 1497 | if (!thread_sp) return SBThread(); |
| 1498 | |
| 1499 | return SBThread(thread_sp->GetCurrentExceptionBacktrace()); |
| 1500 | }*/ |
| 1501 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1502 | bool SBThread::SafeToCallFunctions() { |
| 1503 | ThreadSP thread_sp(m_opaque_sp->GetThreadSP()); |
| 1504 | if (thread_sp) |
| 1505 | return thread_sp->SafeToCallFunctions(); |
| 1506 | return true; |
Jim Ingham | 4f465cf | 2012-10-10 18:32:14 +0000 | [diff] [blame] | 1507 | } |
| 1508 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1509 | lldb_private::Thread *SBThread::operator->() { |
| 1510 | ThreadSP thread_sp(m_opaque_sp->GetThreadSP()); |
| 1511 | if (thread_sp) |
| 1512 | return thread_sp.get(); |
| 1513 | else |
| 1514 | return NULL; |
Jim Ingham | 4f465cf | 2012-10-10 18:32:14 +0000 | [diff] [blame] | 1515 | } |
Greg Clayton | f028a1f | 2010-12-17 02:26:24 +0000 | [diff] [blame] | 1516 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1517 | lldb_private::Thread *SBThread::get() { |
| 1518 | ThreadSP thread_sp(m_opaque_sp->GetThreadSP()); |
| 1519 | if (thread_sp) |
| 1520 | return thread_sp.get(); |
| 1521 | else |
| 1522 | return NULL; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1523 | } |