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