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 | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 15 | #include "lldb/Core/Debugger.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 16 | #include "lldb/Core/Stream.h" |
| 17 | #include "lldb/Core/StreamFile.h" |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 18 | #include "lldb/Interpreter/CommandInterpreter.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 19 | #include "lldb/Target/Thread.h" |
| 20 | #include "lldb/Target/Process.h" |
| 21 | #include "lldb/Symbol/SymbolContext.h" |
| 22 | #include "lldb/Symbol/CompileUnit.h" |
Greg Clayton | 643ee73 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 23 | #include "lldb/Target/StopInfo.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 24 | #include "lldb/Target/Target.h" |
| 25 | #include "lldb/Target/ThreadPlan.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 26 | #include "lldb/Target/ThreadPlanStepInstruction.h" |
| 27 | #include "lldb/Target/ThreadPlanStepOut.h" |
| 28 | #include "lldb/Target/ThreadPlanStepRange.h" |
| 29 | #include "lldb/Target/ThreadPlanStepInRange.h" |
| 30 | |
| 31 | |
Eli Friedman | 7a62c8b | 2010-06-09 07:44:37 +0000 | [diff] [blame] | 32 | #include "lldb/API/SBAddress.h" |
| 33 | #include "lldb/API/SBFrame.h" |
| 34 | #include "lldb/API/SBSourceManager.h" |
| 35 | #include "lldb/API/SBDebugger.h" |
| 36 | #include "lldb/API/SBProcess.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 37 | |
| 38 | using namespace lldb; |
| 39 | using namespace lldb_private; |
| 40 | |
| 41 | SBThread::SBThread () : |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 42 | m_opaque_sp () |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 43 | { |
| 44 | } |
| 45 | |
| 46 | //---------------------------------------------------------------------- |
| 47 | // Thread constructor |
| 48 | //---------------------------------------------------------------------- |
| 49 | SBThread::SBThread (const ThreadSP& lldb_object_sp) : |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 50 | m_opaque_sp (lldb_object_sp) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 51 | { |
Caroline Tice | 61ba7ec | 2010-10-26 23:49:36 +0000 | [diff] [blame] | 52 | Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 53 | |
| 54 | if (log) |
Caroline Tice | 61ba7ec | 2010-10-26 23:49:36 +0000 | [diff] [blame] | 55 | { |
| 56 | SBStream sstr; |
| 57 | GetDescription (sstr); |
Greg Clayton | 3f5ee7f | 2010-10-29 04:59:35 +0000 | [diff] [blame] | 58 | log->Printf ("SBThread::SBThread (lldb_object_sp=%p) => SBThread(%p) :%s", |
Caroline Tice | 61ba7ec | 2010-10-26 23:49:36 +0000 | [diff] [blame] | 59 | lldb_object_sp.get(), m_opaque_sp.get(), sstr.GetData()); |
| 60 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | SBThread::SBThread (const SBThread &rhs) |
| 64 | { |
Caroline Tice | 61ba7ec | 2010-10-26 23:49:36 +0000 | [diff] [blame] | 65 | Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 66 | |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 67 | m_opaque_sp = rhs.m_opaque_sp; |
Caroline Tice | 61ba7ec | 2010-10-26 23:49:36 +0000 | [diff] [blame] | 68 | |
| 69 | if (log) |
Greg Clayton | 3f5ee7f | 2010-10-29 04:59:35 +0000 | [diff] [blame] | 70 | log->Printf ("SBThread::SBThread (rhs.sp=%p) => SBThread(%p)", |
Caroline Tice | 61ba7ec | 2010-10-26 23:49:36 +0000 | [diff] [blame] | 71 | rhs.m_opaque_sp.get(), m_opaque_sp.get()); |
| 72 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | //---------------------------------------------------------------------- |
| 76 | // Destructor |
| 77 | //---------------------------------------------------------------------- |
| 78 | SBThread::~SBThread() |
| 79 | { |
| 80 | } |
| 81 | |
| 82 | bool |
| 83 | SBThread::IsValid() const |
| 84 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 85 | return m_opaque_sp != NULL; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 86 | } |
| 87 | |
Greg Clayton | 43490d1 | 2010-07-30 20:12:55 +0000 | [diff] [blame] | 88 | void |
| 89 | SBThread::Clear () |
| 90 | { |
| 91 | m_opaque_sp.reset(); |
| 92 | } |
| 93 | |
| 94 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 95 | StopReason |
| 96 | SBThread::GetStopReason() |
| 97 | { |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 98 | Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API); |
| 99 | |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 100 | StopReason reason = eStopReasonInvalid; |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 101 | if (m_opaque_sp) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 102 | { |
Jim Ingham | 6297a3a | 2010-10-20 00:39:53 +0000 | [diff] [blame] | 103 | StopInfoSP stop_info_sp = m_opaque_sp->GetStopInfo (); |
| 104 | if (stop_info_sp) |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 105 | reason = stop_info_sp->GetStopReason(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 106 | } |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 107 | |
| 108 | if (log) |
Greg Clayton | 3f5ee7f | 2010-10-29 04:59:35 +0000 | [diff] [blame] | 109 | log->Printf ("SBThread(%p)::GetStopReason () => '%s'", m_opaque_sp.get(), |
Caroline Tice | 61ba7ec | 2010-10-26 23:49:36 +0000 | [diff] [blame] | 110 | Thread::StopReasonAsCString (reason)); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 111 | |
| 112 | return reason; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | size_t |
| 116 | SBThread::GetStopDescription (char *dst, size_t dst_len) |
| 117 | { |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 118 | Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API); |
| 119 | |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 120 | if (m_opaque_sp) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 121 | { |
Jim Ingham | 6297a3a | 2010-10-20 00:39:53 +0000 | [diff] [blame] | 122 | StopInfoSP stop_info_sp = m_opaque_sp->GetStopInfo (); |
| 123 | if (stop_info_sp) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 124 | { |
Jim Ingham | 6297a3a | 2010-10-20 00:39:53 +0000 | [diff] [blame] | 125 | const char *stop_desc = stop_info_sp->GetDescription(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 126 | if (stop_desc) |
| 127 | { |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 128 | if (log) |
Greg Clayton | 3f5ee7f | 2010-10-29 04:59:35 +0000 | [diff] [blame] | 129 | log->Printf ("SBThread(%p)::GetStopDescription (dst, dst_len) => '%s'", |
Caroline Tice | 61ba7ec | 2010-10-26 23:49:36 +0000 | [diff] [blame] | 130 | m_opaque_sp.get(), stop_desc); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 131 | if (dst) |
| 132 | return ::snprintf (dst, dst_len, "%s", stop_desc); |
| 133 | else |
| 134 | { |
| 135 | // NULL dst passed in, return the length needed to contain the description |
| 136 | return ::strlen (stop_desc) + 1; // Include the NULL byte for size |
| 137 | } |
| 138 | } |
| 139 | else |
| 140 | { |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 141 | size_t stop_desc_len = 0; |
Jim Ingham | 6297a3a | 2010-10-20 00:39:53 +0000 | [diff] [blame] | 142 | switch (stop_info_sp->GetStopReason()) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 143 | { |
| 144 | case eStopReasonTrace: |
| 145 | case eStopReasonPlanComplete: |
| 146 | { |
| 147 | static char trace_desc[] = "step"; |
| 148 | stop_desc = trace_desc; |
| 149 | stop_desc_len = sizeof(trace_desc); // Include the NULL byte for size |
| 150 | } |
| 151 | break; |
| 152 | |
| 153 | case eStopReasonBreakpoint: |
| 154 | { |
| 155 | static char bp_desc[] = "breakpoint hit"; |
| 156 | stop_desc = bp_desc; |
| 157 | stop_desc_len = sizeof(bp_desc); // Include the NULL byte for size |
| 158 | } |
| 159 | break; |
| 160 | |
| 161 | case eStopReasonWatchpoint: |
| 162 | { |
| 163 | static char wp_desc[] = "watchpoint hit"; |
| 164 | stop_desc = wp_desc; |
| 165 | stop_desc_len = sizeof(wp_desc); // Include the NULL byte for size |
| 166 | } |
| 167 | break; |
| 168 | |
| 169 | case eStopReasonSignal: |
| 170 | { |
Jim Ingham | 6297a3a | 2010-10-20 00:39:53 +0000 | [diff] [blame] | 171 | stop_desc = m_opaque_sp->GetProcess().GetUnixSignals ().GetSignalAsCString (stop_info_sp->GetValue()); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 172 | if (stop_desc == NULL || stop_desc[0] == '\0') |
| 173 | { |
| 174 | static char signal_desc[] = "signal"; |
| 175 | stop_desc = signal_desc; |
| 176 | stop_desc_len = sizeof(signal_desc); // Include the NULL byte for size |
| 177 | } |
| 178 | } |
| 179 | break; |
| 180 | |
| 181 | case eStopReasonException: |
| 182 | { |
| 183 | char exc_desc[] = "exception"; |
| 184 | stop_desc = exc_desc; |
| 185 | stop_desc_len = sizeof(exc_desc); // Include the NULL byte for size |
| 186 | } |
Greg Clayton | 54e7afa | 2010-07-09 20:39:50 +0000 | [diff] [blame] | 187 | break; |
| 188 | |
| 189 | default: |
| 190 | break; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 191 | } |
| 192 | |
| 193 | if (stop_desc && stop_desc[0]) |
| 194 | { |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 195 | if (log) |
Greg Clayton | 3f5ee7f | 2010-10-29 04:59:35 +0000 | [diff] [blame] | 196 | log->Printf ("SBThread(%p)::GetStopDescription (dst, dst_len) => '%s'", |
Caroline Tice | 61ba7ec | 2010-10-26 23:49:36 +0000 | [diff] [blame] | 197 | m_opaque_sp.get(), stop_desc); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 198 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 199 | if (dst) |
| 200 | return ::snprintf (dst, dst_len, "%s", stop_desc) + 1; // Include the NULL byte |
| 201 | |
| 202 | if (stop_desc_len == 0) |
| 203 | stop_desc_len = ::strlen (stop_desc) + 1; // Include the NULL byte |
| 204 | |
| 205 | return stop_desc_len; |
| 206 | } |
| 207 | } |
| 208 | } |
| 209 | } |
| 210 | if (dst) |
| 211 | *dst = 0; |
| 212 | return 0; |
| 213 | } |
| 214 | |
| 215 | void |
| 216 | SBThread::SetThread (const ThreadSP& lldb_object_sp) |
| 217 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 218 | m_opaque_sp = lldb_object_sp; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 219 | } |
| 220 | |
| 221 | |
| 222 | lldb::tid_t |
| 223 | SBThread::GetThreadID () const |
| 224 | { |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 225 | Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API); |
| 226 | |
Caroline Tice | 61ba7ec | 2010-10-26 23:49:36 +0000 | [diff] [blame] | 227 | //if (log) |
| 228 | // log->Printf ("SBThread::GetThreadID()"); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 229 | |
| 230 | lldb::tid_t id = LLDB_INVALID_THREAD_ID; |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 231 | if (m_opaque_sp) |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 232 | id = m_opaque_sp->GetID(); |
| 233 | |
| 234 | if (log) |
Caroline Tice | 61ba7ec | 2010-10-26 23:49:36 +0000 | [diff] [blame] | 235 | log->Printf ("SBThread::GetThreadID (this.sp=%p) => %d", m_opaque_sp.get(), (uint32_t) id); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 236 | |
| 237 | return id; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 238 | } |
| 239 | |
| 240 | uint32_t |
| 241 | SBThread::GetIndexID () const |
| 242 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 243 | if (m_opaque_sp) |
| 244 | return m_opaque_sp->GetIndexID(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 245 | return LLDB_INVALID_INDEX32; |
| 246 | } |
| 247 | const char * |
| 248 | SBThread::GetName () const |
| 249 | { |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 250 | Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API); |
| 251 | |
Caroline Tice | 61ba7ec | 2010-10-26 23:49:36 +0000 | [diff] [blame] | 252 | //if (log) |
| 253 | // log->Printf ("SBThread::GetName ()"); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 254 | |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 255 | if (m_opaque_sp) |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 256 | { |
| 257 | if (log) |
Caroline Tice | 61ba7ec | 2010-10-26 23:49:36 +0000 | [diff] [blame] | 258 | log->Printf ("SBThread::GetName (this.sp=%p) => '%s'", m_opaque_sp.get(), m_opaque_sp->GetName()); |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 259 | return m_opaque_sp->GetName(); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 260 | } |
| 261 | |
| 262 | if (log) |
Caroline Tice | 61ba7ec | 2010-10-26 23:49:36 +0000 | [diff] [blame] | 263 | log->Printf ("SBThread::GetName (this.sp=%p) => NULL", m_opaque_sp.get()); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 264 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 265 | return NULL; |
| 266 | } |
| 267 | |
| 268 | const char * |
| 269 | SBThread::GetQueueName () const |
| 270 | { |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 271 | Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API); |
| 272 | |
Caroline Tice | 61ba7ec | 2010-10-26 23:49:36 +0000 | [diff] [blame] | 273 | //if (log) |
| 274 | // log->Printf ("SBThread::GetQueueName ()"); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 275 | |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 276 | if (m_opaque_sp) |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 277 | { |
| 278 | if (log) |
Caroline Tice | 61ba7ec | 2010-10-26 23:49:36 +0000 | [diff] [blame] | 279 | log->Printf ("SBThread::GetQueueName (this.sp=%p) => '%s'", m_opaque_sp.get(), |
| 280 | m_opaque_sp->GetQueueName()); |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 281 | return m_opaque_sp->GetQueueName(); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 282 | } |
| 283 | |
| 284 | if (log) |
Caroline Tice | 61ba7ec | 2010-10-26 23:49:36 +0000 | [diff] [blame] | 285 | log->Printf ("SBThread::GetQueueName (this.sp=%p) => NULL", m_opaque_sp.get()); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 286 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 287 | return NULL; |
| 288 | } |
| 289 | |
| 290 | |
| 291 | void |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 292 | SBThread::StepOver (lldb::RunMode stop_other_threads) |
| 293 | { |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 294 | Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API); |
| 295 | |
| 296 | if (log) |
Greg Clayton | 3f5ee7f | 2010-10-29 04:59:35 +0000 | [diff] [blame] | 297 | log->Printf ("SBThread(%p)::StepOver (stop_other_threads='%s')", m_opaque_sp.get(), |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 298 | Thread::RunModeAsCString (stop_other_threads)); |
| 299 | |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 300 | if (m_opaque_sp) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 301 | { |
| 302 | bool abort_other_plans = true; |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 303 | StackFrameSP frame_sp(m_opaque_sp->GetStackFrameAtIndex (0)); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 304 | |
| 305 | if (frame_sp) |
| 306 | { |
| 307 | if (frame_sp->HasDebugInformation ()) |
| 308 | { |
| 309 | SymbolContext sc(frame_sp->GetSymbolContext(eSymbolContextEverything)); |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 310 | m_opaque_sp->QueueThreadPlanForStepRange (abort_other_plans, |
Greg Clayton | 1a3083a | 2010-10-06 03:53:16 +0000 | [diff] [blame] | 311 | eStepTypeOver, |
| 312 | sc.line_entry.range, |
| 313 | sc, |
| 314 | stop_other_threads, |
| 315 | false); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 316 | |
| 317 | } |
| 318 | else |
| 319 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 320 | m_opaque_sp->QueueThreadPlanForStepSingleInstruction (true, |
Greg Clayton | 1a3083a | 2010-10-06 03:53:16 +0000 | [diff] [blame] | 321 | abort_other_plans, |
| 322 | stop_other_threads); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 323 | } |
| 324 | } |
| 325 | |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 326 | Process &process = m_opaque_sp->GetProcess(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 327 | // Why do we need to set the current thread by ID here??? |
Jim Ingham | c833295 | 2010-08-26 21:32:51 +0000 | [diff] [blame] | 328 | process.GetThreadList().SetSelectedThreadByID (m_opaque_sp->GetID()); |
Greg Clayton | 1a3083a | 2010-10-06 03:53:16 +0000 | [diff] [blame] | 329 | Error error (process.Resume()); |
| 330 | if (error.Success()) |
| 331 | { |
| 332 | // If we are doing synchronous mode, then wait for the |
| 333 | // process to stop yet again! |
| 334 | if (process.GetTarget().GetDebugger().GetAsyncExecution () == false) |
| 335 | process.WaitForProcessToStop (NULL); |
| 336 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 337 | } |
| 338 | } |
| 339 | |
| 340 | void |
| 341 | SBThread::StepInto (lldb::RunMode stop_other_threads) |
| 342 | { |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 343 | Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API); |
| 344 | |
| 345 | if (log) |
Greg Clayton | 3f5ee7f | 2010-10-29 04:59:35 +0000 | [diff] [blame] | 346 | log->Printf ("SBThread(%p)::StepInto (stop_other_threads='%s')", m_opaque_sp.get(), |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 347 | Thread::RunModeAsCString (stop_other_threads)); |
| 348 | |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 349 | if (m_opaque_sp) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 350 | { |
| 351 | bool abort_other_plans = true; |
| 352 | |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 353 | StackFrameSP frame_sp(m_opaque_sp->GetStackFrameAtIndex (0)); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 354 | |
| 355 | if (frame_sp && frame_sp->HasDebugInformation ()) |
| 356 | { |
Greg Clayton | 8f5fd6b | 2010-06-12 18:59:55 +0000 | [diff] [blame] | 357 | bool avoid_code_without_debug_info = true; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 358 | SymbolContext sc(frame_sp->GetSymbolContext(eSymbolContextEverything)); |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 359 | m_opaque_sp->QueueThreadPlanForStepRange (abort_other_plans, |
Greg Clayton | 1a3083a | 2010-10-06 03:53:16 +0000 | [diff] [blame] | 360 | eStepTypeInto, |
| 361 | sc.line_entry.range, |
| 362 | sc, |
| 363 | stop_other_threads, |
| 364 | avoid_code_without_debug_info); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 365 | } |
| 366 | else |
| 367 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 368 | m_opaque_sp->QueueThreadPlanForStepSingleInstruction (false, |
Greg Clayton | 1a3083a | 2010-10-06 03:53:16 +0000 | [diff] [blame] | 369 | abort_other_plans, |
| 370 | stop_other_threads); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 371 | } |
| 372 | |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 373 | Process &process = m_opaque_sp->GetProcess(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 374 | // Why do we need to set the current thread by ID here??? |
Jim Ingham | c833295 | 2010-08-26 21:32:51 +0000 | [diff] [blame] | 375 | process.GetThreadList().SetSelectedThreadByID (m_opaque_sp->GetID()); |
Greg Clayton | 1a3083a | 2010-10-06 03:53:16 +0000 | [diff] [blame] | 376 | Error error (process.Resume()); |
| 377 | if (error.Success()) |
| 378 | { |
| 379 | // If we are doing synchronous mode, then wait for the |
| 380 | // process to stop yet again! |
| 381 | if (process.GetTarget().GetDebugger().GetAsyncExecution () == false) |
| 382 | process.WaitForProcessToStop (NULL); |
| 383 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 384 | } |
| 385 | } |
| 386 | |
| 387 | void |
| 388 | SBThread::StepOut () |
| 389 | { |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 390 | Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API); |
| 391 | |
| 392 | if (log) |
Caroline Tice | 61ba7ec | 2010-10-26 23:49:36 +0000 | [diff] [blame] | 393 | log->Printf ("SBThread::StepOut (this.sp=%p)", m_opaque_sp.get()); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 394 | |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 395 | if (m_opaque_sp) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 396 | { |
| 397 | bool abort_other_plans = true; |
| 398 | bool stop_other_threads = true; |
| 399 | |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 400 | m_opaque_sp->QueueThreadPlanForStepOut (abort_other_plans, NULL, false, stop_other_threads, eVoteYes, eVoteNoOpinion); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 401 | |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 402 | Process &process = m_opaque_sp->GetProcess(); |
Jim Ingham | c833295 | 2010-08-26 21:32:51 +0000 | [diff] [blame] | 403 | process.GetThreadList().SetSelectedThreadByID (m_opaque_sp->GetID()); |
Greg Clayton | 1a3083a | 2010-10-06 03:53:16 +0000 | [diff] [blame] | 404 | Error error (process.Resume()); |
| 405 | if (error.Success()) |
| 406 | { |
| 407 | // If we are doing synchronous mode, then wait for the |
| 408 | // process to stop yet again! |
| 409 | if (process.GetTarget().GetDebugger().GetAsyncExecution () == false) |
| 410 | process.WaitForProcessToStop (NULL); |
| 411 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 412 | } |
| 413 | } |
| 414 | |
| 415 | void |
| 416 | SBThread::StepInstruction (bool step_over) |
| 417 | { |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 418 | Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API); |
| 419 | |
| 420 | if (log) |
Greg Clayton | 3f5ee7f | 2010-10-29 04:59:35 +0000 | [diff] [blame] | 421 | log->Printf ("SBThread(%p)::StepInstruction (step_over=%i)", m_opaque_sp.get(), step_over); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 422 | |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 423 | if (m_opaque_sp) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 424 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 425 | m_opaque_sp->QueueThreadPlanForStepSingleInstruction (step_over, true, true); |
| 426 | Process &process = m_opaque_sp->GetProcess(); |
Jim Ingham | c833295 | 2010-08-26 21:32:51 +0000 | [diff] [blame] | 427 | process.GetThreadList().SetSelectedThreadByID (m_opaque_sp->GetID()); |
Greg Clayton | 1a3083a | 2010-10-06 03:53:16 +0000 | [diff] [blame] | 428 | Error error (process.Resume()); |
| 429 | if (error.Success()) |
| 430 | { |
| 431 | // If we are doing synchronous mode, then wait for the |
| 432 | // process to stop yet again! |
| 433 | if (process.GetTarget().GetDebugger().GetAsyncExecution () == false) |
| 434 | process.WaitForProcessToStop (NULL); |
| 435 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 436 | } |
| 437 | } |
| 438 | |
| 439 | void |
| 440 | SBThread::RunToAddress (lldb::addr_t addr) |
| 441 | { |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 442 | Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API); |
| 443 | |
| 444 | if (log) |
Greg Clayton | 3f5ee7f | 2010-10-29 04:59:35 +0000 | [diff] [blame] | 445 | log->Printf ("SBThread(%p)::RunToAddress (addr=0x%llx)", m_opaque_sp.get(), addr); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 446 | |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 447 | if (m_opaque_sp) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 448 | { |
| 449 | bool abort_other_plans = true; |
| 450 | bool stop_other_threads = true; |
| 451 | |
| 452 | Address target_addr (NULL, addr); |
| 453 | |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 454 | m_opaque_sp->QueueThreadPlanForRunToAddress (abort_other_plans, target_addr, stop_other_threads); |
| 455 | Process &process = m_opaque_sp->GetProcess(); |
Jim Ingham | c833295 | 2010-08-26 21:32:51 +0000 | [diff] [blame] | 456 | process.GetThreadList().SetSelectedThreadByID (m_opaque_sp->GetID()); |
Greg Clayton | 1a3083a | 2010-10-06 03:53:16 +0000 | [diff] [blame] | 457 | Error error (process.Resume()); |
| 458 | if (error.Success()) |
| 459 | { |
| 460 | // If we are doing synchronous mode, then wait for the |
| 461 | // process to stop yet again! |
| 462 | if (process.GetTarget().GetDebugger().GetAsyncExecution () == false) |
| 463 | process.WaitForProcessToStop (NULL); |
| 464 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 465 | } |
| 466 | |
| 467 | } |
| 468 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 469 | SBProcess |
| 470 | SBThread::GetProcess () |
| 471 | { |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 472 | Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API); |
| 473 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 474 | SBProcess process; |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 475 | if (m_opaque_sp) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 476 | { |
| 477 | // Have to go up to the target so we can get a shared pointer to our process... |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 478 | process.SetProcess(m_opaque_sp->GetProcess().GetTarget().GetProcessSP()); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 479 | } |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 480 | |
| 481 | if (log) |
| 482 | { |
| 483 | SBStream sstr; |
| 484 | process.GetDescription (sstr); |
Caroline Tice | 61ba7ec | 2010-10-26 23:49:36 +0000 | [diff] [blame] | 485 | log->Printf ("SBThread::GetProcess (this.sp=%p) => SBProcess : this.sp = %p, '%s'", m_opaque_sp.get(), |
| 486 | process.get(), sstr.GetData()); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 487 | } |
| 488 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 489 | return process; |
| 490 | } |
| 491 | |
| 492 | uint32_t |
| 493 | SBThread::GetNumFrames () |
| 494 | { |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 495 | Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API); |
| 496 | |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 497 | uint32_t num_frames = 0; |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 498 | if (m_opaque_sp) |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 499 | num_frames = m_opaque_sp->GetStackFrameCount(); |
| 500 | |
| 501 | if (log) |
Caroline Tice | 61ba7ec | 2010-10-26 23:49:36 +0000 | [diff] [blame] | 502 | log->Printf ("SBThread::GetNumFrames (this.sp=%p) => %d", m_opaque_sp.get(), num_frames); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 503 | |
| 504 | return num_frames; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 505 | } |
| 506 | |
| 507 | SBFrame |
| 508 | SBThread::GetFrameAtIndex (uint32_t idx) |
| 509 | { |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 510 | Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API); |
| 511 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 512 | SBFrame sb_frame; |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 513 | if (m_opaque_sp) |
| 514 | sb_frame.SetFrame (m_opaque_sp->GetStackFrameAtIndex (idx)); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 515 | |
| 516 | if (log) |
| 517 | { |
| 518 | SBStream sstr; |
| 519 | sb_frame.GetDescription (sstr); |
Greg Clayton | 3f5ee7f | 2010-10-29 04:59:35 +0000 | [diff] [blame] | 520 | log->Printf ("SBThread(%p)::GetFrameAtIndex (idx=%d) => SBFrame.sp : this = %p, '%s'", |
Caroline Tice | 61ba7ec | 2010-10-26 23:49:36 +0000 | [diff] [blame] | 521 | m_opaque_sp.get(), idx, sb_frame.get(), sstr.GetData()); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 522 | } |
| 523 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 524 | return sb_frame; |
| 525 | } |
| 526 | |
| 527 | const lldb::SBThread & |
| 528 | SBThread::operator = (const lldb::SBThread &rhs) |
| 529 | { |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 530 | Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API); |
| 531 | |
| 532 | if (log) |
Greg Clayton | 3f5ee7f | 2010-10-29 04:59:35 +0000 | [diff] [blame] | 533 | log->Printf ("SBThread(%p)::operator= (rhs.sp=%p)", m_opaque_sp.get(), rhs.m_opaque_sp.get()); |
Caroline Tice | 61ba7ec | 2010-10-26 23:49:36 +0000 | [diff] [blame] | 534 | |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 535 | m_opaque_sp = rhs.m_opaque_sp; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 536 | return *this; |
| 537 | } |
| 538 | |
| 539 | bool |
| 540 | SBThread::operator == (const SBThread &rhs) const |
| 541 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 542 | return m_opaque_sp.get() == rhs.m_opaque_sp.get(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 543 | } |
| 544 | |
| 545 | bool |
| 546 | SBThread::operator != (const SBThread &rhs) const |
| 547 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 548 | return m_opaque_sp.get() != rhs.m_opaque_sp.get(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 549 | } |
| 550 | |
| 551 | lldb_private::Thread * |
| 552 | SBThread::GetLLDBObjectPtr () |
| 553 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 554 | return m_opaque_sp.get(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 555 | } |
| 556 | |
| 557 | const lldb_private::Thread * |
| 558 | SBThread::operator->() const |
| 559 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 560 | return m_opaque_sp.get(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 561 | } |
| 562 | |
| 563 | const lldb_private::Thread & |
| 564 | SBThread::operator*() const |
| 565 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 566 | return *m_opaque_sp; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 567 | } |
| 568 | |
| 569 | lldb_private::Thread * |
| 570 | SBThread::operator->() |
| 571 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 572 | return m_opaque_sp.get(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 573 | } |
| 574 | |
| 575 | lldb_private::Thread & |
| 576 | SBThread::operator*() |
| 577 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 578 | return *m_opaque_sp; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 579 | } |
Caroline Tice | 98f930f | 2010-09-20 05:20:02 +0000 | [diff] [blame] | 580 | |
| 581 | bool |
| 582 | SBThread::GetDescription (SBStream &description) |
| 583 | { |
| 584 | if (m_opaque_sp) |
Greg Clayton | d8c6253 | 2010-10-07 04:19:01 +0000 | [diff] [blame] | 585 | { |
| 586 | StreamString strm; |
| 587 | description.Printf("SBThread: tid = 0x%4.4x", m_opaque_sp->GetID()); |
| 588 | } |
Caroline Tice | 98f930f | 2010-09-20 05:20:02 +0000 | [diff] [blame] | 589 | else |
| 590 | description.Printf ("No value"); |
| 591 | |
| 592 | return true; |
| 593 | } |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 594 | |
| 595 | bool |
| 596 | SBThread::GetDescription (SBStream &description) const |
| 597 | { |
| 598 | if (m_opaque_sp) |
| 599 | { |
| 600 | StreamString strm; |
| 601 | description.Printf("SBThread: tid = 0x%4.4x", m_opaque_sp->GetID()); |
| 602 | } |
| 603 | else |
| 604 | description.Printf ("No value"); |
| 605 | |
| 606 | return true; |
| 607 | } |