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