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