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