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