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