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