Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1 | //===-- Thread.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 | |
Daniel Malea | 93a6430 | 2012-12-05 00:20:57 +0000 | [diff] [blame] | 10 | #include "lldb/lldb-python.h" |
| 11 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 12 | #include "lldb/lldb-private-log.h" |
Jim Ingham | 1b54c88 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 13 | #include "lldb/Breakpoint/BreakpointLocation.h" |
Greg Clayton | 0603aa9 | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 14 | #include "lldb/Core/Debugger.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 15 | #include "lldb/Core/Log.h" |
Greg Clayton | 160c9d8 | 2013-05-01 21:54:04 +0000 | [diff] [blame] | 16 | #include "lldb/Core/State.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 17 | #include "lldb/Core/Stream.h" |
| 18 | #include "lldb/Core/StreamString.h" |
Jim Ingham | ee8aea1 | 2010-09-08 03:14:33 +0000 | [diff] [blame] | 19 | #include "lldb/Core/RegularExpression.h" |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 20 | #include "lldb/Host/Host.h" |
Jim Ingham | 1f51e60 | 2012-09-27 01:15:29 +0000 | [diff] [blame] | 21 | #include "lldb/Symbol/Function.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 22 | #include "lldb/Target/DynamicLoader.h" |
| 23 | #include "lldb/Target/ExecutionContext.h" |
Jim Ingham | 5a36912 | 2010-09-28 01:25:32 +0000 | [diff] [blame] | 24 | #include "lldb/Target/ObjCLanguageRuntime.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 25 | #include "lldb/Target/Process.h" |
| 26 | #include "lldb/Target/RegisterContext.h" |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 27 | #include "lldb/Target/StopInfo.h" |
Greg Clayton | 896dff6 | 2010-07-23 16:45:51 +0000 | [diff] [blame] | 28 | #include "lldb/Target/Target.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 29 | #include "lldb/Target/Thread.h" |
| 30 | #include "lldb/Target/ThreadPlan.h" |
| 31 | #include "lldb/Target/ThreadPlanCallFunction.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 32 | #include "lldb/Target/ThreadPlanBase.h" |
| 33 | #include "lldb/Target/ThreadPlanStepInstruction.h" |
| 34 | #include "lldb/Target/ThreadPlanStepOut.h" |
| 35 | #include "lldb/Target/ThreadPlanStepOverBreakpoint.h" |
| 36 | #include "lldb/Target/ThreadPlanStepThrough.h" |
| 37 | #include "lldb/Target/ThreadPlanStepInRange.h" |
| 38 | #include "lldb/Target/ThreadPlanStepOverRange.h" |
| 39 | #include "lldb/Target/ThreadPlanRunToAddress.h" |
| 40 | #include "lldb/Target/ThreadPlanStepUntil.h" |
Jim Ingham | 1b54c88 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 41 | #include "lldb/Target/ThreadSpec.h" |
Jim Ingham | 87c1191 | 2010-08-12 02:14:28 +0000 | [diff] [blame] | 42 | #include "lldb/Target/Unwind.h" |
Greg Clayton | 56d9a1b | 2011-08-22 02:49:39 +0000 | [diff] [blame] | 43 | #include "Plugins/Process/Utility/UnwindLLDB.h" |
| 44 | #include "UnwindMacOSXFrameBackchain.h" |
| 45 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 46 | |
| 47 | using namespace lldb; |
| 48 | using namespace lldb_private; |
| 49 | |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 50 | |
| 51 | const ThreadPropertiesSP & |
| 52 | Thread::GetGlobalProperties() |
| 53 | { |
| 54 | static ThreadPropertiesSP g_settings_sp; |
| 55 | if (!g_settings_sp) |
| 56 | g_settings_sp.reset (new ThreadProperties (true)); |
| 57 | return g_settings_sp; |
| 58 | } |
| 59 | |
| 60 | static PropertyDefinition |
| 61 | g_properties[] = |
| 62 | { |
| 63 | { "step-avoid-regexp", OptionValue::eTypeRegex , true , REG_EXTENDED, "^std::", NULL, "A regular expression defining functions step-in won't stop in." }, |
| 64 | { "trace-thread", OptionValue::eTypeBoolean, false, false, NULL, NULL, "If true, this thread will single-step and log execution." }, |
| 65 | { NULL , OptionValue::eTypeInvalid, false, 0 , NULL, NULL, NULL } |
| 66 | }; |
| 67 | |
| 68 | enum { |
| 69 | ePropertyStepAvoidRegex, |
| 70 | ePropertyEnableThreadTrace |
| 71 | }; |
| 72 | |
| 73 | |
| 74 | class ThreadOptionValueProperties : public OptionValueProperties |
| 75 | { |
| 76 | public: |
| 77 | ThreadOptionValueProperties (const ConstString &name) : |
| 78 | OptionValueProperties (name) |
| 79 | { |
| 80 | } |
| 81 | |
| 82 | // This constructor is used when creating ThreadOptionValueProperties when it |
| 83 | // is part of a new lldb_private::Thread instance. It will copy all current |
| 84 | // global property values as needed |
| 85 | ThreadOptionValueProperties (ThreadProperties *global_properties) : |
Greg Clayton | 6920b52 | 2012-08-22 18:39:03 +0000 | [diff] [blame] | 86 | OptionValueProperties(*global_properties->GetValueProperties()) |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 87 | { |
| 88 | } |
| 89 | |
| 90 | virtual const Property * |
| 91 | GetPropertyAtIndex (const ExecutionContext *exe_ctx, bool will_modify, uint32_t idx) const |
| 92 | { |
| 93 | // When gettings the value for a key from the thread options, we will always |
| 94 | // try and grab the setting from the current thread if there is one. Else we just |
| 95 | // use the one from this instance. |
| 96 | if (exe_ctx) |
| 97 | { |
| 98 | Thread *thread = exe_ctx->GetThreadPtr(); |
| 99 | if (thread) |
| 100 | { |
| 101 | ThreadOptionValueProperties *instance_properties = static_cast<ThreadOptionValueProperties *>(thread->GetValueProperties().get()); |
| 102 | if (this != instance_properties) |
| 103 | return instance_properties->ProtectedGetPropertyAtIndex (idx); |
| 104 | } |
| 105 | } |
| 106 | return ProtectedGetPropertyAtIndex (idx); |
| 107 | } |
| 108 | }; |
| 109 | |
| 110 | |
| 111 | |
| 112 | ThreadProperties::ThreadProperties (bool is_global) : |
| 113 | Properties () |
| 114 | { |
| 115 | if (is_global) |
| 116 | { |
| 117 | m_collection_sp.reset (new ThreadOptionValueProperties(ConstString("thread"))); |
| 118 | m_collection_sp->Initialize(g_properties); |
| 119 | } |
| 120 | else |
| 121 | m_collection_sp.reset (new ThreadOptionValueProperties(Thread::GetGlobalProperties().get())); |
| 122 | } |
| 123 | |
| 124 | ThreadProperties::~ThreadProperties() |
| 125 | { |
| 126 | } |
| 127 | |
| 128 | const RegularExpression * |
| 129 | ThreadProperties::GetSymbolsToAvoidRegexp() |
| 130 | { |
| 131 | const uint32_t idx = ePropertyStepAvoidRegex; |
| 132 | return m_collection_sp->GetPropertyAtIndexAsOptionValueRegex (NULL, idx); |
| 133 | } |
| 134 | |
| 135 | bool |
| 136 | ThreadProperties::GetTraceEnabledState() const |
| 137 | { |
| 138 | const uint32_t idx = ePropertyEnableThreadTrace; |
| 139 | return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0); |
| 140 | } |
| 141 | |
Jim Ingham | 4f465cf | 2012-10-10 18:32:14 +0000 | [diff] [blame] | 142 | //------------------------------------------------------------------ |
| 143 | // Thread Event Data |
| 144 | //------------------------------------------------------------------ |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 145 | |
Jim Ingham | 4f465cf | 2012-10-10 18:32:14 +0000 | [diff] [blame] | 146 | |
| 147 | const ConstString & |
| 148 | Thread::ThreadEventData::GetFlavorString () |
| 149 | { |
| 150 | static ConstString g_flavor ("Thread::ThreadEventData"); |
| 151 | return g_flavor; |
| 152 | } |
| 153 | |
| 154 | Thread::ThreadEventData::ThreadEventData (const lldb::ThreadSP thread_sp) : |
| 155 | m_thread_sp (thread_sp), |
| 156 | m_stack_id () |
| 157 | { |
| 158 | } |
| 159 | |
| 160 | Thread::ThreadEventData::ThreadEventData (const lldb::ThreadSP thread_sp, const StackID &stack_id) : |
| 161 | m_thread_sp (thread_sp), |
| 162 | m_stack_id (stack_id) |
| 163 | { |
| 164 | } |
| 165 | |
| 166 | Thread::ThreadEventData::ThreadEventData () : |
| 167 | m_thread_sp (), |
| 168 | m_stack_id () |
| 169 | { |
| 170 | } |
| 171 | |
| 172 | Thread::ThreadEventData::~ThreadEventData () |
| 173 | { |
| 174 | } |
| 175 | |
| 176 | void |
| 177 | Thread::ThreadEventData::Dump (Stream *s) const |
| 178 | { |
| 179 | |
| 180 | } |
| 181 | |
| 182 | const Thread::ThreadEventData * |
| 183 | Thread::ThreadEventData::GetEventDataFromEvent (const Event *event_ptr) |
| 184 | { |
| 185 | if (event_ptr) |
| 186 | { |
| 187 | const EventData *event_data = event_ptr->GetData(); |
| 188 | if (event_data && event_data->GetFlavor() == ThreadEventData::GetFlavorString()) |
| 189 | return static_cast <const ThreadEventData *> (event_ptr->GetData()); |
| 190 | } |
| 191 | return NULL; |
| 192 | } |
| 193 | |
| 194 | ThreadSP |
| 195 | Thread::ThreadEventData::GetThreadFromEvent (const Event *event_ptr) |
| 196 | { |
| 197 | ThreadSP thread_sp; |
| 198 | const ThreadEventData *event_data = GetEventDataFromEvent (event_ptr); |
| 199 | if (event_data) |
| 200 | thread_sp = event_data->GetThread(); |
| 201 | return thread_sp; |
| 202 | } |
| 203 | |
| 204 | StackID |
| 205 | Thread::ThreadEventData::GetStackIDFromEvent (const Event *event_ptr) |
| 206 | { |
| 207 | StackID stack_id; |
| 208 | const ThreadEventData *event_data = GetEventDataFromEvent (event_ptr); |
| 209 | if (event_data) |
| 210 | stack_id = event_data->GetStackID(); |
| 211 | return stack_id; |
| 212 | } |
| 213 | |
| 214 | StackFrameSP |
| 215 | Thread::ThreadEventData::GetStackFrameFromEvent (const Event *event_ptr) |
| 216 | { |
| 217 | const ThreadEventData *event_data = GetEventDataFromEvent (event_ptr); |
| 218 | StackFrameSP frame_sp; |
| 219 | if (event_data) |
| 220 | { |
| 221 | ThreadSP thread_sp = event_data->GetThread(); |
| 222 | if (thread_sp) |
| 223 | { |
| 224 | frame_sp = thread_sp->GetStackFrameList()->GetFrameWithStackID (event_data->GetStackID()); |
| 225 | } |
| 226 | } |
| 227 | return frame_sp; |
| 228 | } |
| 229 | |
| 230 | //------------------------------------------------------------------ |
| 231 | // Thread class |
| 232 | //------------------------------------------------------------------ |
| 233 | |
| 234 | ConstString & |
| 235 | Thread::GetStaticBroadcasterClass () |
| 236 | { |
| 237 | static ConstString class_name ("lldb.thread"); |
| 238 | return class_name; |
| 239 | } |
| 240 | |
| 241 | Thread::Thread (Process &process, lldb::tid_t tid) : |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 242 | ThreadProperties (false), |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 243 | UserID (tid), |
Jim Ingham | 4f465cf | 2012-10-10 18:32:14 +0000 | [diff] [blame] | 244 | Broadcaster(&process.GetTarget().GetDebugger(), Thread::GetStaticBroadcasterClass().AsCString()), |
| 245 | m_process_wp (process.shared_from_this()), |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 246 | m_actual_stop_info_sp (), |
Han Ming Ong | c2c423e | 2013-01-08 22:10:01 +0000 | [diff] [blame] | 247 | m_index_id (process.GetNextThreadIndexID(tid)), |
Greg Clayton | 160c9d8 | 2013-05-01 21:54:04 +0000 | [diff] [blame] | 248 | m_protocol_tid (tid), |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 249 | m_reg_context_sp (), |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 250 | m_state (eStateUnloaded), |
Greg Clayton | 12daf946 | 2010-08-25 00:35:26 +0000 | [diff] [blame] | 251 | m_state_mutex (Mutex::eMutexTypeRecursive), |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 252 | m_plan_stack (), |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 253 | m_completed_plan_stack(), |
Greg Clayton | 39d0ab3 | 2012-03-29 01:41:38 +0000 | [diff] [blame] | 254 | m_frame_mutex (Mutex::eMutexTypeRecursive), |
Greg Clayton | 7e9b1fd | 2011-08-12 21:40:01 +0000 | [diff] [blame] | 255 | m_curr_frames_sp (), |
| 256 | m_prev_frames_sp (), |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 257 | m_resume_signal (LLDB_INVALID_SIGNAL_NUMBER), |
Jim Ingham | 87c1191 | 2010-08-12 02:14:28 +0000 | [diff] [blame] | 258 | m_resume_state (eStateRunning), |
Jim Ingham | 92087d8 | 2012-01-31 23:09:20 +0000 | [diff] [blame] | 259 | m_temporary_resume_state (eStateRunning), |
Jim Ingham | 773d981 | 2010-11-18 02:47:07 +0000 | [diff] [blame] | 260 | m_unwinder_ap (), |
Jim Ingham | 7778703 | 2011-01-20 02:03:18 +0000 | [diff] [blame] | 261 | m_destroy_called (false), |
| 262 | m_thread_stop_reason_stop_id (0) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 263 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 264 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 265 | if (log) |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 266 | log->Printf ("%p Thread::Thread(tid = 0x%4.4" PRIx64 ")", this, GetID()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 267 | |
Jim Ingham | 4f465cf | 2012-10-10 18:32:14 +0000 | [diff] [blame] | 268 | CheckInWithManager(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 269 | QueueFundamentalPlan(true); |
| 270 | } |
| 271 | |
| 272 | |
| 273 | Thread::~Thread() |
| 274 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 275 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 276 | if (log) |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 277 | log->Printf ("%p Thread::~Thread(tid = 0x%4.4" PRIx64 ")", this, GetID()); |
Jim Ingham | 773d981 | 2010-11-18 02:47:07 +0000 | [diff] [blame] | 278 | /// If you hit this assert, it means your derived class forgot to call DoDestroy in its destructor. |
| 279 | assert (m_destroy_called); |
| 280 | } |
| 281 | |
| 282 | void |
| 283 | Thread::DestroyThread () |
| 284 | { |
Greg Clayton | 35a4cc5 | 2012-10-29 20:52:08 +0000 | [diff] [blame] | 285 | m_destroy_called = true; |
Jim Ingham | 773d981 | 2010-11-18 02:47:07 +0000 | [diff] [blame] | 286 | m_plan_stack.clear(); |
| 287 | m_discarded_plan_stack.clear(); |
| 288 | m_completed_plan_stack.clear(); |
Jim Ingham | d8ba464 | 2012-04-10 00:44:25 +0000 | [diff] [blame] | 289 | m_actual_stop_info_sp.reset(); |
Greg Clayton | 35a4cc5 | 2012-10-29 20:52:08 +0000 | [diff] [blame] | 290 | m_reg_context_sp.reset(); |
| 291 | m_unwinder_ap.reset(); |
| 292 | Mutex::Locker locker(m_frame_mutex); |
| 293 | m_curr_frames_sp.reset(); |
| 294 | m_prev_frames_sp.reset(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 295 | } |
| 296 | |
Jim Ingham | 4f465cf | 2012-10-10 18:32:14 +0000 | [diff] [blame] | 297 | void |
| 298 | Thread::BroadcastSelectedFrameChange(StackID &new_frame_id) |
| 299 | { |
| 300 | if (EventTypeHasListeners(eBroadcastBitSelectedFrameChanged)) |
| 301 | BroadcastEvent(eBroadcastBitSelectedFrameChanged, new ThreadEventData (this->shared_from_this(), new_frame_id)); |
| 302 | } |
| 303 | |
| 304 | uint32_t |
| 305 | Thread::SetSelectedFrame (lldb_private::StackFrame *frame, bool broadcast) |
| 306 | { |
| 307 | uint32_t ret_value = GetStackFrameList()->SetSelectedFrame(frame); |
| 308 | if (broadcast) |
| 309 | BroadcastSelectedFrameChange(frame->GetStackID()); |
| 310 | return ret_value; |
| 311 | } |
| 312 | |
| 313 | bool |
| 314 | Thread::SetSelectedFrameByIndex (uint32_t frame_idx, bool broadcast) |
| 315 | { |
| 316 | StackFrameSP frame_sp(GetStackFrameList()->GetFrameAtIndex (frame_idx)); |
| 317 | if (frame_sp) |
| 318 | { |
| 319 | GetStackFrameList()->SetSelectedFrame(frame_sp.get()); |
| 320 | if (broadcast) |
| 321 | BroadcastSelectedFrameChange(frame_sp->GetStackID()); |
| 322 | return true; |
| 323 | } |
| 324 | else |
| 325 | return false; |
| 326 | } |
| 327 | |
Jim Ingham | 93208b8 | 2013-01-31 21:46:01 +0000 | [diff] [blame] | 328 | bool |
| 329 | Thread::SetSelectedFrameByIndexNoisily (uint32_t frame_idx, Stream &output_stream) |
| 330 | { |
| 331 | const bool broadcast = true; |
| 332 | bool success = SetSelectedFrameByIndex (frame_idx, broadcast); |
| 333 | if (success) |
| 334 | { |
| 335 | StackFrameSP frame_sp = GetSelectedFrame(); |
| 336 | if (frame_sp) |
| 337 | { |
| 338 | bool already_shown = false; |
| 339 | SymbolContext frame_sc(frame_sp->GetSymbolContext(eSymbolContextLineEntry)); |
| 340 | if (GetProcess()->GetTarget().GetDebugger().GetUseExternalEditor() && frame_sc.line_entry.file && frame_sc.line_entry.line != 0) |
| 341 | { |
| 342 | already_shown = Host::OpenFileInExternalEditor (frame_sc.line_entry.file, frame_sc.line_entry.line); |
| 343 | } |
| 344 | |
| 345 | bool show_frame_info = true; |
| 346 | bool show_source = !already_shown; |
| 347 | return frame_sp->GetStatus (output_stream, show_frame_info, show_source); |
| 348 | } |
| 349 | return false; |
| 350 | } |
| 351 | else |
| 352 | return false; |
| 353 | } |
| 354 | |
Jim Ingham | 4f465cf | 2012-10-10 18:32:14 +0000 | [diff] [blame] | 355 | |
Jim Ingham | b15bfc7 | 2010-10-20 00:39:53 +0000 | [diff] [blame] | 356 | lldb::StopInfoSP |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 357 | Thread::GetStopInfo () |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 358 | { |
Jim Ingham | b15bfc7 | 2010-10-20 00:39:53 +0000 | [diff] [blame] | 359 | ThreadPlanSP plan_sp (GetCompletedPlan()); |
Andrew Kaylor | ba4e61d | 2013-05-07 18:35:34 +0000 | [diff] [blame] | 360 | ProcessSP process_sp (GetProcess()); |
| 361 | const uint32_t stop_id = process_sp ? process_sp->GetStopID() : UINT32_MAX; |
Jim Ingham | fbbfe6e | 2012-05-01 18:38:37 +0000 | [diff] [blame] | 362 | if (plan_sp && plan_sp->PlanSucceeded()) |
Andrew Kaylor | ba4e61d | 2013-05-07 18:35:34 +0000 | [diff] [blame] | 363 | { |
Jim Ingham | 73ca05a | 2011-12-17 01:35:57 +0000 | [diff] [blame] | 364 | return StopInfo::CreateStopReasonWithPlan (plan_sp, GetReturnValueObject()); |
Andrew Kaylor | ba4e61d | 2013-05-07 18:35:34 +0000 | [diff] [blame] | 365 | } |
Jim Ingham | b15bfc7 | 2010-10-20 00:39:53 +0000 | [diff] [blame] | 366 | else |
Jim Ingham | 79c35da | 2011-08-09 00:32:52 +0000 | [diff] [blame] | 367 | { |
Andrew Kaylor | ba4e61d | 2013-05-07 18:35:34 +0000 | [diff] [blame] | 368 | if ((m_thread_stop_reason_stop_id == stop_id) || // Stop info is valid, just return what we have (even if empty) |
| 369 | (m_actual_stop_info_sp && m_actual_stop_info_sp->IsValid())) // Stop info is valid, just return what we have |
| 370 | { |
Jim Ingham | 79c35da | 2011-08-09 00:32:52 +0000 | [diff] [blame] | 371 | return m_actual_stop_info_sp; |
Andrew Kaylor | ba4e61d | 2013-05-07 18:35:34 +0000 | [diff] [blame] | 372 | } |
Jim Ingham | 79c35da | 2011-08-09 00:32:52 +0000 | [diff] [blame] | 373 | else |
Andrew Kaylor | ba4e61d | 2013-05-07 18:35:34 +0000 | [diff] [blame] | 374 | { |
| 375 | GetPrivateStopReason (); |
| 376 | return m_actual_stop_info_sp; |
| 377 | } |
Jim Ingham | 79c35da | 2011-08-09 00:32:52 +0000 | [diff] [blame] | 378 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 379 | } |
| 380 | |
Greg Clayton | 97d5cf0 | 2012-09-25 02:40:06 +0000 | [diff] [blame] | 381 | lldb::StopReason |
| 382 | Thread::GetStopReason() |
| 383 | { |
| 384 | lldb::StopInfoSP stop_info_sp (GetStopInfo ()); |
| 385 | if (stop_info_sp) |
Filipe Cabecinhas | e26391a | 2012-09-28 15:55:43 +0000 | [diff] [blame] | 386 | return stop_info_sp->GetStopReason(); |
Greg Clayton | 97d5cf0 | 2012-09-25 02:40:06 +0000 | [diff] [blame] | 387 | return eStopReasonNone; |
| 388 | } |
| 389 | |
| 390 | |
| 391 | |
Jim Ingham | 7778703 | 2011-01-20 02:03:18 +0000 | [diff] [blame] | 392 | void |
| 393 | Thread::SetStopInfo (const lldb::StopInfoSP &stop_info_sp) |
| 394 | { |
| 395 | m_actual_stop_info_sp = stop_info_sp; |
Jim Ingham | 79c35da | 2011-08-09 00:32:52 +0000 | [diff] [blame] | 396 | if (m_actual_stop_info_sp) |
| 397 | m_actual_stop_info_sp->MakeStopInfoValid(); |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 398 | ProcessSP process_sp (GetProcess()); |
| 399 | if (process_sp) |
| 400 | m_thread_stop_reason_stop_id = process_sp->GetStopID(); |
| 401 | else |
| 402 | m_thread_stop_reason_stop_id = UINT32_MAX; |
Jim Ingham | 7778703 | 2011-01-20 02:03:18 +0000 | [diff] [blame] | 403 | } |
| 404 | |
| 405 | void |
| 406 | Thread::SetStopInfoToNothing() |
| 407 | { |
| 408 | // Note, we can't just NULL out the private reason, or the native thread implementation will try to |
| 409 | // go calculate it again. For now, just set it to a Unix Signal with an invalid signal number. |
| 410 | SetStopInfo (StopInfo::CreateStopReasonWithSignal (*this, LLDB_INVALID_SIGNAL_NUMBER)); |
| 411 | } |
| 412 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 413 | bool |
| 414 | Thread::ThreadStoppedForAReason (void) |
| 415 | { |
Jim Ingham | f94e179 | 2012-08-11 00:35:26 +0000 | [diff] [blame] | 416 | return (bool) GetPrivateStopReason (); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 417 | } |
| 418 | |
Jim Ingham | 7778703 | 2011-01-20 02:03:18 +0000 | [diff] [blame] | 419 | bool |
| 420 | Thread::CheckpointThreadState (ThreadStateCheckpoint &saved_state) |
| 421 | { |
| 422 | if (!SaveFrameZeroState(saved_state.register_backup)) |
| 423 | return false; |
| 424 | |
| 425 | saved_state.stop_info_sp = GetStopInfo(); |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 426 | ProcessSP process_sp (GetProcess()); |
| 427 | if (process_sp) |
| 428 | saved_state.orig_stop_id = process_sp->GetStopID(); |
Jim Ingham | 625fca7 | 2012-09-07 23:36:43 +0000 | [diff] [blame] | 429 | saved_state.current_inlined_depth = GetCurrentInlinedDepth(); |
| 430 | |
Jim Ingham | 7778703 | 2011-01-20 02:03:18 +0000 | [diff] [blame] | 431 | return true; |
| 432 | } |
| 433 | |
| 434 | bool |
Jim Ingham | 8559a35 | 2012-11-26 23:52:18 +0000 | [diff] [blame] | 435 | Thread::RestoreRegisterStateFromCheckpoint (ThreadStateCheckpoint &saved_state) |
Jim Ingham | 7778703 | 2011-01-20 02:03:18 +0000 | [diff] [blame] | 436 | { |
| 437 | RestoreSaveFrameZero(saved_state.register_backup); |
Jim Ingham | 8559a35 | 2012-11-26 23:52:18 +0000 | [diff] [blame] | 438 | return true; |
| 439 | } |
| 440 | |
| 441 | bool |
| 442 | Thread::RestoreThreadStateFromCheckpoint (ThreadStateCheckpoint &saved_state) |
| 443 | { |
Jim Ingham | 0c27068 | 2011-01-25 02:47:23 +0000 | [diff] [blame] | 444 | if (saved_state.stop_info_sp) |
| 445 | saved_state.stop_info_sp->MakeStopInfoValid(); |
Jim Ingham | 7778703 | 2011-01-20 02:03:18 +0000 | [diff] [blame] | 446 | SetStopInfo(saved_state.stop_info_sp); |
Jim Ingham | 625fca7 | 2012-09-07 23:36:43 +0000 | [diff] [blame] | 447 | GetStackFrameList()->SetCurrentInlinedDepth (saved_state.current_inlined_depth); |
Jim Ingham | 7778703 | 2011-01-20 02:03:18 +0000 | [diff] [blame] | 448 | return true; |
| 449 | } |
| 450 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 451 | StateType |
| 452 | Thread::GetState() const |
| 453 | { |
| 454 | // If any other threads access this we will need a mutex for it |
| 455 | Mutex::Locker locker(m_state_mutex); |
| 456 | return m_state; |
| 457 | } |
| 458 | |
| 459 | void |
| 460 | Thread::SetState(StateType state) |
| 461 | { |
| 462 | Mutex::Locker locker(m_state_mutex); |
| 463 | m_state = state; |
| 464 | } |
| 465 | |
| 466 | void |
| 467 | Thread::WillStop() |
| 468 | { |
| 469 | ThreadPlan *current_plan = GetCurrentPlan(); |
| 470 | |
| 471 | // FIXME: I may decide to disallow threads with no plans. In which |
| 472 | // case this should go to an assert. |
| 473 | |
| 474 | if (!current_plan) |
| 475 | return; |
| 476 | |
| 477 | current_plan->WillStop(); |
| 478 | } |
| 479 | |
| 480 | void |
| 481 | Thread::SetupForResume () |
| 482 | { |
| 483 | if (GetResumeState() != eStateSuspended) |
| 484 | { |
| 485 | |
| 486 | // If we're at a breakpoint push the step-over breakpoint plan. Do this before |
| 487 | // telling the current plan it will resume, since we might change what the current |
| 488 | // plan is. |
| 489 | |
Greg Clayton | 1afa68e | 2013-04-02 20:32:37 +0000 | [diff] [blame] | 490 | // StopReason stop_reason = lldb::eStopReasonInvalid; |
| 491 | // StopInfoSP stop_info_sp = GetStopInfo(); |
| 492 | // if (stop_info_sp.get()) |
| 493 | // stop_reason = stop_info_sp->GetStopReason(); |
| 494 | // if (stop_reason == lldb::eStopReasonBreakpoint) |
| 495 | lldb::RegisterContextSP reg_ctx_sp (GetRegisterContext()); |
| 496 | if (reg_ctx_sp) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 497 | { |
Greg Clayton | 1afa68e | 2013-04-02 20:32:37 +0000 | [diff] [blame] | 498 | BreakpointSiteSP bp_site_sp = GetProcess()->GetBreakpointSiteList().FindByAddress(reg_ctx_sp->GetPC()); |
| 499 | if (bp_site_sp) |
Jim Ingham | b01e742 | 2010-06-19 04:45:32 +0000 | [diff] [blame] | 500 | { |
Greg Clayton | 1afa68e | 2013-04-02 20:32:37 +0000 | [diff] [blame] | 501 | // Note, don't assume there's a ThreadPlanStepOverBreakpoint, the target may not require anything |
| 502 | // special to step over a breakpoint. |
| 503 | |
| 504 | ThreadPlan *cur_plan = GetCurrentPlan(); |
Jim Ingham | b01e742 | 2010-06-19 04:45:32 +0000 | [diff] [blame] | 505 | |
Greg Clayton | 1afa68e | 2013-04-02 20:32:37 +0000 | [diff] [blame] | 506 | if (cur_plan->GetKind() != ThreadPlan::eKindStepOverBreakpoint) |
| 507 | { |
| 508 | ThreadPlanStepOverBreakpoint *step_bp_plan = new ThreadPlanStepOverBreakpoint (*this); |
| 509 | if (step_bp_plan) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 510 | { |
Greg Clayton | 1afa68e | 2013-04-02 20:32:37 +0000 | [diff] [blame] | 511 | ThreadPlanSP step_bp_plan_sp; |
| 512 | step_bp_plan->SetPrivate (true); |
| 513 | |
| 514 | if (GetCurrentPlan()->RunState() != eStateStepping) |
| 515 | { |
| 516 | step_bp_plan->SetAutoContinue(true); |
| 517 | } |
| 518 | step_bp_plan_sp.reset (step_bp_plan); |
| 519 | QueueThreadPlan (step_bp_plan_sp, false); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 520 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 521 | } |
| 522 | } |
| 523 | } |
| 524 | } |
| 525 | } |
| 526 | |
| 527 | bool |
Greg Clayton | 160c9d8 | 2013-05-01 21:54:04 +0000 | [diff] [blame] | 528 | Thread::ShouldResume (StateType resume_state) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 529 | { |
| 530 | // At this point clear the completed plan stack. |
| 531 | m_completed_plan_stack.clear(); |
| 532 | m_discarded_plan_stack.clear(); |
| 533 | |
Greg Clayton | 97d5cf0 | 2012-09-25 02:40:06 +0000 | [diff] [blame] | 534 | m_temporary_resume_state = resume_state; |
Jim Ingham | 92087d8 | 2012-01-31 23:09:20 +0000 | [diff] [blame] | 535 | |
Greg Clayton | 160c9d8 | 2013-05-01 21:54:04 +0000 | [diff] [blame] | 536 | // Make sure m_actual_stop_info_sp is valid |
| 537 | GetPrivateStopReason(); |
| 538 | |
Jim Ingham | 92087d8 | 2012-01-31 23:09:20 +0000 | [diff] [blame] | 539 | // This is a little dubious, but we are trying to limit how often we actually fetch stop info from |
| 540 | // the target, 'cause that slows down single stepping. So assume that if we got to the point where |
| 541 | // we're about to resume, and we haven't yet had to fetch the stop reason, then it doesn't need to know |
| 542 | // about the fact that we are resuming... |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 543 | const uint32_t process_stop_id = GetProcess()->GetStopID(); |
Jim Ingham | 92087d8 | 2012-01-31 23:09:20 +0000 | [diff] [blame] | 544 | if (m_thread_stop_reason_stop_id == process_stop_id && |
| 545 | (m_actual_stop_info_sp && m_actual_stop_info_sp->IsValid())) |
| 546 | { |
| 547 | StopInfo *stop_info = GetPrivateStopReason().get(); |
| 548 | if (stop_info) |
| 549 | stop_info->WillResume (resume_state); |
| 550 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 551 | |
| 552 | // Tell all the plans that we are about to resume in case they need to clear any state. |
| 553 | // We distinguish between the plan on the top of the stack and the lower |
| 554 | // plans in case a plan needs to do any special business before it runs. |
| 555 | |
Greg Clayton | d1d06e4 | 2013-04-20 00:27:58 +0000 | [diff] [blame] | 556 | bool need_to_resume = false; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 557 | ThreadPlan *plan_ptr = GetCurrentPlan(); |
Greg Clayton | d1d06e4 | 2013-04-20 00:27:58 +0000 | [diff] [blame] | 558 | if (plan_ptr) |
| 559 | { |
| 560 | need_to_resume = plan_ptr->WillResume(resume_state, true); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 561 | |
Greg Clayton | d1d06e4 | 2013-04-20 00:27:58 +0000 | [diff] [blame] | 562 | while ((plan_ptr = GetPreviousPlan(plan_ptr)) != NULL) |
| 563 | { |
| 564 | plan_ptr->WillResume (resume_state, false); |
| 565 | } |
| 566 | |
| 567 | // If the WillResume for the plan says we are faking a resume, then it will have set an appropriate stop info. |
| 568 | // In that case, don't reset it here. |
| 569 | |
| 570 | if (need_to_resume && resume_state != eStateSuspended) |
| 571 | { |
| 572 | m_actual_stop_info_sp.reset(); |
| 573 | } |
Jim Ingham | 513c6bb | 2012-09-01 01:02:41 +0000 | [diff] [blame] | 574 | } |
| 575 | |
Greg Clayton | 160c9d8 | 2013-05-01 21:54:04 +0000 | [diff] [blame] | 576 | if (need_to_resume) |
| 577 | { |
| 578 | ClearStackFrames(); |
| 579 | // Let Thread subclasses do any special work they need to prior to resuming |
| 580 | WillResume (resume_state); |
| 581 | } |
| 582 | |
Jim Ingham | 513c6bb | 2012-09-01 01:02:41 +0000 | [diff] [blame] | 583 | return need_to_resume; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 584 | } |
| 585 | |
| 586 | void |
| 587 | Thread::DidResume () |
| 588 | { |
| 589 | SetResumeSignal (LLDB_INVALID_SIGNAL_NUMBER); |
| 590 | } |
| 591 | |
| 592 | bool |
| 593 | Thread::ShouldStop (Event* event_ptr) |
| 594 | { |
| 595 | ThreadPlan *current_plan = GetCurrentPlan(); |
Greg Clayton | d1d06e4 | 2013-04-20 00:27:58 +0000 | [diff] [blame] | 596 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 597 | bool should_stop = true; |
| 598 | |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 599 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); |
Jim Ingham | 92087d8 | 2012-01-31 23:09:20 +0000 | [diff] [blame] | 600 | |
| 601 | if (GetResumeState () == eStateSuspended) |
| 602 | { |
| 603 | if (log) |
Greg Clayton | 160c9d8 | 2013-05-01 21:54:04 +0000 | [diff] [blame] | 604 | log->Printf ("Thread::%s for tid = 0x%4.4" PRIx64 " 0x%4.4" PRIx64 ", should_stop = 0 (ignore since thread was suspended)", |
Jim Ingham | 92087d8 | 2012-01-31 23:09:20 +0000 | [diff] [blame] | 605 | __FUNCTION__, |
Greg Clayton | 160c9d8 | 2013-05-01 21:54:04 +0000 | [diff] [blame] | 606 | GetID (), |
| 607 | GetProtocolID()); |
Jim Ingham | 92087d8 | 2012-01-31 23:09:20 +0000 | [diff] [blame] | 608 | return false; |
| 609 | } |
| 610 | |
| 611 | if (GetTemporaryResumeState () == eStateSuspended) |
| 612 | { |
| 613 | if (log) |
Greg Clayton | 160c9d8 | 2013-05-01 21:54:04 +0000 | [diff] [blame] | 614 | log->Printf ("Thread::%s for tid = 0x%4.4" PRIx64 " 0x%4.4" PRIx64 ", should_stop = 0 (ignore since thread was suspended)", |
Jim Ingham | 92087d8 | 2012-01-31 23:09:20 +0000 | [diff] [blame] | 615 | __FUNCTION__, |
Greg Clayton | 160c9d8 | 2013-05-01 21:54:04 +0000 | [diff] [blame] | 616 | GetID (), |
| 617 | GetProtocolID()); |
Jim Ingham | 92087d8 | 2012-01-31 23:09:20 +0000 | [diff] [blame] | 618 | return false; |
| 619 | } |
| 620 | |
| 621 | if (ThreadStoppedForAReason() == false) |
| 622 | { |
| 623 | if (log) |
Greg Clayton | 160c9d8 | 2013-05-01 21:54:04 +0000 | [diff] [blame] | 624 | log->Printf ("Thread::%s for tid = 0x%4.4" PRIx64 " 0x%4.4" PRIx64 ", pc = 0x%16.16" PRIx64 ", should_stop = 0 (ignore since no stop reason)", |
Jim Ingham | 92087d8 | 2012-01-31 23:09:20 +0000 | [diff] [blame] | 625 | __FUNCTION__, |
Greg Clayton | 160c9d8 | 2013-05-01 21:54:04 +0000 | [diff] [blame] | 626 | GetID (), |
| 627 | GetProtocolID(), |
Greg Clayton | 1afa68e | 2013-04-02 20:32:37 +0000 | [diff] [blame] | 628 | GetRegisterContext() ? GetRegisterContext()->GetPC() : LLDB_INVALID_ADDRESS); |
Jim Ingham | 92087d8 | 2012-01-31 23:09:20 +0000 | [diff] [blame] | 629 | return false; |
| 630 | } |
Jim Ingham | 513c6bb | 2012-09-01 01:02:41 +0000 | [diff] [blame] | 631 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 632 | if (log) |
| 633 | { |
Greg Clayton | 160c9d8 | 2013-05-01 21:54:04 +0000 | [diff] [blame] | 634 | log->Printf ("Thread::%s for tid = 0x%4.4" PRIx64 " 0x%4.4" PRIx64 ", pc = 0x%16.16" PRIx64, |
Jim Ingham | 92087d8 | 2012-01-31 23:09:20 +0000 | [diff] [blame] | 635 | __FUNCTION__, |
Greg Clayton | 160c9d8 | 2013-05-01 21:54:04 +0000 | [diff] [blame] | 636 | GetID (), |
| 637 | GetProtocolID (), |
Greg Clayton | 1afa68e | 2013-04-02 20:32:37 +0000 | [diff] [blame] | 638 | GetRegisterContext() ? GetRegisterContext()->GetPC() : LLDB_INVALID_ADDRESS); |
Jim Ingham | 10c4b24 | 2011-10-15 00:23:43 +0000 | [diff] [blame] | 639 | log->Printf ("^^^^^^^^ Thread::ShouldStop Begin ^^^^^^^^"); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 640 | StreamString s; |
Jim Ingham | 10c4b24 | 2011-10-15 00:23:43 +0000 | [diff] [blame] | 641 | s.IndentMore(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 642 | DumpThreadPlans(&s); |
Jim Ingham | 10c4b24 | 2011-10-15 00:23:43 +0000 | [diff] [blame] | 643 | log->Printf ("Plan stack initial state:\n%s", s.GetData()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 644 | } |
Jim Ingham | 06e827c | 2010-11-11 19:26:09 +0000 | [diff] [blame] | 645 | |
| 646 | // The top most plan always gets to do the trace log... |
| 647 | current_plan->DoTraceLog (); |
Jim Ingham | 6d66ce6 | 2012-04-20 21:16:56 +0000 | [diff] [blame] | 648 | |
| 649 | // First query the stop info's ShouldStopSynchronous. This handles "synchronous" stop reasons, for example the breakpoint |
| 650 | // command on internal breakpoints. If a synchronous stop reason says we should not stop, then we don't have to |
| 651 | // do any more work on this stop. |
| 652 | StopInfoSP private_stop_info (GetPrivateStopReason()); |
| 653 | if (private_stop_info && private_stop_info->ShouldStopSynchronous(event_ptr) == false) |
| 654 | { |
| 655 | if (log) |
| 656 | log->Printf ("StopInfo::ShouldStop async callback says we should not stop, returning ShouldStop of false."); |
| 657 | return false; |
| 658 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 659 | |
Jim Ingham | bad39e4 | 2012-09-05 21:12:49 +0000 | [diff] [blame] | 660 | // If we've already been restarted, don't query the plans since the state they would examine is not current. |
| 661 | if (Process::ProcessEventData::GetRestartedFromEvent(event_ptr)) |
| 662 | return false; |
| 663 | |
| 664 | // Before the plans see the state of the world, calculate the current inlined depth. |
| 665 | GetStackFrameList()->CalculateCurrentInlinedDepth(); |
| 666 | |
Jim Ingham | 25f6670 | 2011-12-03 01:52:59 +0000 | [diff] [blame] | 667 | // If the base plan doesn't understand why we stopped, then we have to find a plan that does. |
| 668 | // If that plan is still working, then we don't need to do any more work. If the plan that explains |
| 669 | // the stop is done, then we should pop all the plans below it, and pop it, and then let the plans above it decide |
| 670 | // whether they still need to do more work. |
| 671 | |
| 672 | bool done_processing_current_plan = false; |
| 673 | |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 674 | if (!current_plan->PlanExplainsStop(event_ptr)) |
Jim Ingham | 25f6670 | 2011-12-03 01:52:59 +0000 | [diff] [blame] | 675 | { |
| 676 | if (current_plan->TracerExplainsStop()) |
| 677 | { |
| 678 | done_processing_current_plan = true; |
| 679 | should_stop = false; |
| 680 | } |
| 681 | else |
| 682 | { |
Jim Ingham | cf274f9 | 2012-04-09 22:37:39 +0000 | [diff] [blame] | 683 | // If the current plan doesn't explain the stop, then find one that |
Jim Ingham | 25f6670 | 2011-12-03 01:52:59 +0000 | [diff] [blame] | 684 | // does and let it handle the situation. |
| 685 | ThreadPlan *plan_ptr = current_plan; |
| 686 | while ((plan_ptr = GetPreviousPlan(plan_ptr)) != NULL) |
| 687 | { |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 688 | if (plan_ptr->PlanExplainsStop(event_ptr)) |
Jim Ingham | 25f6670 | 2011-12-03 01:52:59 +0000 | [diff] [blame] | 689 | { |
| 690 | should_stop = plan_ptr->ShouldStop (event_ptr); |
| 691 | |
| 692 | // plan_ptr explains the stop, next check whether plan_ptr is done, if so, then we should take it |
| 693 | // and all the plans below it off the stack. |
| 694 | |
| 695 | if (plan_ptr->MischiefManaged()) |
| 696 | { |
Jim Ingham | 031177e | 2012-05-11 23:49:49 +0000 | [diff] [blame] | 697 | // We're going to pop the plans up to and including the plan that explains the stop. |
Jim Ingham | 7ba6e99 | 2012-05-11 23:47:32 +0000 | [diff] [blame] | 698 | ThreadPlan *prev_plan_ptr = GetPreviousPlan (plan_ptr); |
Jim Ingham | 25f6670 | 2011-12-03 01:52:59 +0000 | [diff] [blame] | 699 | |
| 700 | do |
| 701 | { |
| 702 | if (should_stop) |
| 703 | current_plan->WillStop(); |
| 704 | PopPlan(); |
| 705 | } |
Jim Ingham | 7ba6e99 | 2012-05-11 23:47:32 +0000 | [diff] [blame] | 706 | while ((current_plan = GetCurrentPlan()) != prev_plan_ptr); |
| 707 | // Now, if the responsible plan was not "Okay to discard" then we're done, |
| 708 | // otherwise we forward this to the next plan in the stack below. |
| 709 | if (plan_ptr->IsMasterPlan() && !plan_ptr->OkayToDiscard()) |
| 710 | done_processing_current_plan = true; |
| 711 | else |
| 712 | done_processing_current_plan = false; |
Jim Ingham | 25f6670 | 2011-12-03 01:52:59 +0000 | [diff] [blame] | 713 | } |
| 714 | else |
| 715 | done_processing_current_plan = true; |
| 716 | |
| 717 | break; |
| 718 | } |
| 719 | |
| 720 | } |
| 721 | } |
| 722 | } |
| 723 | |
| 724 | if (!done_processing_current_plan) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 725 | { |
Jim Ingham | b01e742 | 2010-06-19 04:45:32 +0000 | [diff] [blame] | 726 | bool over_ride_stop = current_plan->ShouldAutoContinue(event_ptr); |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 727 | |
Jim Ingham | 10c4b24 | 2011-10-15 00:23:43 +0000 | [diff] [blame] | 728 | if (log) |
| 729 | log->Printf("Plan %s explains stop, auto-continue %i.", current_plan->GetName(), over_ride_stop); |
| 730 | |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 731 | // We're starting from the base plan, so just let it decide; |
| 732 | if (PlanIsBasePlan(current_plan)) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 733 | { |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 734 | should_stop = current_plan->ShouldStop (event_ptr); |
| 735 | if (log) |
Greg Clayton | af247d7 | 2011-05-19 03:54:16 +0000 | [diff] [blame] | 736 | log->Printf("Base plan says should stop: %i.", should_stop); |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 737 | } |
| 738 | else |
| 739 | { |
| 740 | // Otherwise, don't let the base plan override what the other plans say to do, since |
| 741 | // presumably if there were other plans they would know what to do... |
| 742 | while (1) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 743 | { |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 744 | if (PlanIsBasePlan(current_plan)) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 745 | break; |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 746 | |
| 747 | should_stop = current_plan->ShouldStop(event_ptr); |
| 748 | if (log) |
| 749 | log->Printf("Plan %s should stop: %d.", current_plan->GetName(), should_stop); |
| 750 | if (current_plan->MischiefManaged()) |
| 751 | { |
| 752 | if (should_stop) |
| 753 | current_plan->WillStop(); |
| 754 | |
| 755 | // If a Master Plan wants to stop, and wants to stick on the stack, we let it. |
| 756 | // Otherwise, see if the plan's parent wants to stop. |
| 757 | |
| 758 | if (should_stop && current_plan->IsMasterPlan() && !current_plan->OkayToDiscard()) |
| 759 | { |
| 760 | PopPlan(); |
| 761 | break; |
| 762 | } |
| 763 | else |
| 764 | { |
| 765 | |
| 766 | PopPlan(); |
| 767 | |
| 768 | current_plan = GetCurrentPlan(); |
| 769 | if (current_plan == NULL) |
| 770 | { |
| 771 | break; |
| 772 | } |
| 773 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 774 | } |
| 775 | else |
| 776 | { |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 777 | break; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 778 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 779 | } |
| 780 | } |
Jim Ingham | 64e7ead | 2012-05-03 21:19:36 +0000 | [diff] [blame] | 781 | |
Jim Ingham | b01e742 | 2010-06-19 04:45:32 +0000 | [diff] [blame] | 782 | if (over_ride_stop) |
| 783 | should_stop = false; |
Jim Ingham | 64e7ead | 2012-05-03 21:19:36 +0000 | [diff] [blame] | 784 | |
| 785 | // One other potential problem is that we set up a master plan, then stop in before it is complete - for instance |
| 786 | // by hitting a breakpoint during a step-over - then do some step/finish/etc operations that wind up |
| 787 | // past the end point condition of the initial plan. We don't want to strand the original plan on the stack, |
| 788 | // This code clears stale plans off the stack. |
| 789 | |
| 790 | if (should_stop) |
| 791 | { |
| 792 | ThreadPlan *plan_ptr = GetCurrentPlan(); |
| 793 | while (!PlanIsBasePlan(plan_ptr)) |
| 794 | { |
| 795 | bool stale = plan_ptr->IsPlanStale (); |
| 796 | ThreadPlan *examined_plan = plan_ptr; |
| 797 | plan_ptr = GetPreviousPlan (examined_plan); |
| 798 | |
| 799 | if (stale) |
| 800 | { |
| 801 | if (log) |
| 802 | log->Printf("Plan %s being discarded in cleanup, it says it is already done.", examined_plan->GetName()); |
| 803 | DiscardThreadPlansUpToPlan(examined_plan); |
| 804 | } |
| 805 | } |
| 806 | } |
| 807 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 808 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 809 | |
Jim Ingham | 10c4b24 | 2011-10-15 00:23:43 +0000 | [diff] [blame] | 810 | if (log) |
| 811 | { |
| 812 | StreamString s; |
| 813 | s.IndentMore(); |
| 814 | DumpThreadPlans(&s); |
| 815 | log->Printf ("Plan stack final state:\n%s", s.GetData()); |
| 816 | log->Printf ("vvvvvvvv Thread::ShouldStop End (returning %i) vvvvvvvv", should_stop); |
| 817 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 818 | return should_stop; |
| 819 | } |
| 820 | |
| 821 | Vote |
| 822 | Thread::ShouldReportStop (Event* event_ptr) |
| 823 | { |
| 824 | StateType thread_state = GetResumeState (); |
Jim Ingham | 92087d8 | 2012-01-31 23:09:20 +0000 | [diff] [blame] | 825 | StateType temp_thread_state = GetTemporaryResumeState(); |
| 826 | |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 827 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); |
Greg Clayton | 2cad65a | 2010-09-03 17:10:42 +0000 | [diff] [blame] | 828 | |
| 829 | if (thread_state == eStateSuspended || thread_state == eStateInvalid) |
| 830 | { |
| 831 | if (log) |
Greg Clayton | 160c9d8 | 2013-05-01 21:54:04 +0000 | [diff] [blame] | 832 | log->Printf ("Thread::ShouldReportStop() tid = 0x%4.4" PRIx64 ": returning vote %i (state was suspended or invalid)", GetID(), eVoteNoOpinion); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 833 | return eVoteNoOpinion; |
Greg Clayton | 2cad65a | 2010-09-03 17:10:42 +0000 | [diff] [blame] | 834 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 835 | |
Jim Ingham | 92087d8 | 2012-01-31 23:09:20 +0000 | [diff] [blame] | 836 | if (temp_thread_state == eStateSuspended || temp_thread_state == eStateInvalid) |
| 837 | { |
| 838 | if (log) |
Greg Clayton | 160c9d8 | 2013-05-01 21:54:04 +0000 | [diff] [blame] | 839 | log->Printf ("Thread::ShouldReportStop() tid = 0x%4.4" PRIx64 ": returning vote %i (temporary state was suspended or invalid)", GetID(), eVoteNoOpinion); |
Jim Ingham | 92087d8 | 2012-01-31 23:09:20 +0000 | [diff] [blame] | 840 | return eVoteNoOpinion; |
| 841 | } |
| 842 | |
| 843 | if (!ThreadStoppedForAReason()) |
| 844 | { |
| 845 | if (log) |
Greg Clayton | 160c9d8 | 2013-05-01 21:54:04 +0000 | [diff] [blame] | 846 | log->Printf ("Thread::ShouldReportStop() tid = 0x%4.4" PRIx64 ": returning vote %i (thread didn't stop for a reason.)", GetID(), eVoteNoOpinion); |
Jim Ingham | 92087d8 | 2012-01-31 23:09:20 +0000 | [diff] [blame] | 847 | return eVoteNoOpinion; |
| 848 | } |
| 849 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 850 | if (m_completed_plan_stack.size() > 0) |
| 851 | { |
| 852 | // Don't use GetCompletedPlan here, since that suppresses private plans. |
Greg Clayton | 2cad65a | 2010-09-03 17:10:42 +0000 | [diff] [blame] | 853 | if (log) |
Greg Clayton | 160c9d8 | 2013-05-01 21:54:04 +0000 | [diff] [blame] | 854 | log->Printf ("Thread::ShouldReportStop() tid = 0x%4.4" PRIx64 ": returning vote for complete stack's back plan", GetID()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 855 | return m_completed_plan_stack.back()->ShouldReportStop (event_ptr); |
| 856 | } |
| 857 | else |
Greg Clayton | 2cad65a | 2010-09-03 17:10:42 +0000 | [diff] [blame] | 858 | { |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 859 | Vote thread_vote = eVoteNoOpinion; |
| 860 | ThreadPlan *plan_ptr = GetCurrentPlan(); |
| 861 | while (1) |
| 862 | { |
| 863 | if (plan_ptr->PlanExplainsStop(event_ptr)) |
| 864 | { |
| 865 | thread_vote = plan_ptr->ShouldReportStop(event_ptr); |
| 866 | break; |
| 867 | } |
| 868 | if (PlanIsBasePlan(plan_ptr)) |
| 869 | break; |
| 870 | else |
| 871 | plan_ptr = GetPreviousPlan(plan_ptr); |
| 872 | } |
Greg Clayton | 2cad65a | 2010-09-03 17:10:42 +0000 | [diff] [blame] | 873 | if (log) |
Greg Clayton | 160c9d8 | 2013-05-01 21:54:04 +0000 | [diff] [blame] | 874 | log->Printf ("Thread::ShouldReportStop() tid = 0x%4.4" PRIx64 ": returning vote %i for current plan", GetID(), thread_vote); |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 875 | |
| 876 | return thread_vote; |
Greg Clayton | 2cad65a | 2010-09-03 17:10:42 +0000 | [diff] [blame] | 877 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 878 | } |
| 879 | |
| 880 | Vote |
| 881 | Thread::ShouldReportRun (Event* event_ptr) |
| 882 | { |
| 883 | StateType thread_state = GetResumeState (); |
Jim Ingham | 444586b | 2011-01-24 06:34:17 +0000 | [diff] [blame] | 884 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 885 | if (thread_state == eStateSuspended |
| 886 | || thread_state == eStateInvalid) |
Jim Ingham | 444586b | 2011-01-24 06:34:17 +0000 | [diff] [blame] | 887 | { |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 888 | return eVoteNoOpinion; |
Jim Ingham | 444586b | 2011-01-24 06:34:17 +0000 | [diff] [blame] | 889 | } |
| 890 | |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 891 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 892 | if (m_completed_plan_stack.size() > 0) |
| 893 | { |
| 894 | // Don't use GetCompletedPlan here, since that suppresses private plans. |
Jim Ingham | 444586b | 2011-01-24 06:34:17 +0000 | [diff] [blame] | 895 | if (log) |
Greg Clayton | 160c9d8 | 2013-05-01 21:54:04 +0000 | [diff] [blame] | 896 | log->Printf ("Current Plan for thread %d (0x%4.4" PRIx64 ", %s): %s being asked whether we should report run.", |
Jim Ingham | 444586b | 2011-01-24 06:34:17 +0000 | [diff] [blame] | 897 | GetIndexID(), |
| 898 | GetID(), |
Greg Clayton | 160c9d8 | 2013-05-01 21:54:04 +0000 | [diff] [blame] | 899 | StateAsCString(GetTemporaryResumeState()), |
Jim Ingham | 444586b | 2011-01-24 06:34:17 +0000 | [diff] [blame] | 900 | m_completed_plan_stack.back()->GetName()); |
| 901 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 902 | return m_completed_plan_stack.back()->ShouldReportRun (event_ptr); |
| 903 | } |
| 904 | else |
Jim Ingham | 444586b | 2011-01-24 06:34:17 +0000 | [diff] [blame] | 905 | { |
| 906 | if (log) |
Greg Clayton | 160c9d8 | 2013-05-01 21:54:04 +0000 | [diff] [blame] | 907 | log->Printf ("Current Plan for thread %d (0x%4.4" PRIx64 ", %s): %s being asked whether we should report run.", |
Jim Ingham | 444586b | 2011-01-24 06:34:17 +0000 | [diff] [blame] | 908 | GetIndexID(), |
| 909 | GetID(), |
Greg Clayton | 160c9d8 | 2013-05-01 21:54:04 +0000 | [diff] [blame] | 910 | StateAsCString(GetTemporaryResumeState()), |
Jim Ingham | 444586b | 2011-01-24 06:34:17 +0000 | [diff] [blame] | 911 | GetCurrentPlan()->GetName()); |
| 912 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 913 | return GetCurrentPlan()->ShouldReportRun (event_ptr); |
Jim Ingham | 444586b | 2011-01-24 06:34:17 +0000 | [diff] [blame] | 914 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 915 | } |
| 916 | |
Jim Ingham | 1b54c88 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 917 | bool |
| 918 | Thread::MatchesSpec (const ThreadSpec *spec) |
| 919 | { |
| 920 | if (spec == NULL) |
| 921 | return true; |
Jim Ingham | 1b54c88 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 922 | |
Jim Ingham | 3d90292 | 2012-03-07 22:03:04 +0000 | [diff] [blame] | 923 | return spec->ThreadPassesBasicTests(*this); |
Jim Ingham | 1b54c88 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 924 | } |
| 925 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 926 | void |
| 927 | Thread::PushPlan (ThreadPlanSP &thread_plan_sp) |
| 928 | { |
| 929 | if (thread_plan_sp) |
| 930 | { |
Jim Ingham | 06e827c | 2010-11-11 19:26:09 +0000 | [diff] [blame] | 931 | // If the thread plan doesn't already have a tracer, give it its parent's tracer: |
| 932 | if (!thread_plan_sp->GetThreadPlanTracer()) |
| 933 | thread_plan_sp->SetThreadPlanTracer(m_plan_stack.back()->GetThreadPlanTracer()); |
Jim Ingham | b15bfc7 | 2010-10-20 00:39:53 +0000 | [diff] [blame] | 934 | m_plan_stack.push_back (thread_plan_sp); |
Jim Ingham | 06e827c | 2010-11-11 19:26:09 +0000 | [diff] [blame] | 935 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 936 | thread_plan_sp->DidPush(); |
| 937 | |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 938 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 939 | if (log) |
| 940 | { |
| 941 | StreamString s; |
| 942 | thread_plan_sp->GetDescription (&s, lldb::eDescriptionLevelFull); |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 943 | log->Printf("Pushing plan: \"%s\", tid = 0x%4.4" PRIx64 ".", |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 944 | s.GetData(), |
Jim Ingham | b15bfc7 | 2010-10-20 00:39:53 +0000 | [diff] [blame] | 945 | thread_plan_sp->GetThread().GetID()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 946 | } |
| 947 | } |
| 948 | } |
| 949 | |
| 950 | void |
| 951 | Thread::PopPlan () |
| 952 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 953 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 954 | |
Jim Ingham | 4fc6cb9 | 2012-08-22 21:34:33 +0000 | [diff] [blame] | 955 | if (m_plan_stack.size() <= 1) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 956 | return; |
| 957 | else |
| 958 | { |
| 959 | ThreadPlanSP &plan = m_plan_stack.back(); |
| 960 | if (log) |
| 961 | { |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 962 | log->Printf("Popping plan: \"%s\", tid = 0x%4.4" PRIx64 ".", plan->GetName(), plan->GetThread().GetID()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 963 | } |
| 964 | m_completed_plan_stack.push_back (plan); |
| 965 | plan->WillPop(); |
| 966 | m_plan_stack.pop_back(); |
| 967 | } |
| 968 | } |
| 969 | |
| 970 | void |
| 971 | Thread::DiscardPlan () |
| 972 | { |
| 973 | if (m_plan_stack.size() > 1) |
| 974 | { |
| 975 | ThreadPlanSP &plan = m_plan_stack.back(); |
| 976 | m_discarded_plan_stack.push_back (plan); |
| 977 | plan->WillPop(); |
| 978 | m_plan_stack.pop_back(); |
| 979 | } |
| 980 | } |
| 981 | |
| 982 | ThreadPlan * |
| 983 | Thread::GetCurrentPlan () |
| 984 | { |
Jim Ingham | e147123 | 2012-04-19 00:17:05 +0000 | [diff] [blame] | 985 | // There will always be at least the base plan. If somebody is mucking with a |
| 986 | // thread with an empty plan stack, we should assert right away. |
Greg Clayton | d1d06e4 | 2013-04-20 00:27:58 +0000 | [diff] [blame] | 987 | if (m_plan_stack.empty()) |
| 988 | return NULL; |
Jim Ingham | e147123 | 2012-04-19 00:17:05 +0000 | [diff] [blame] | 989 | return m_plan_stack.back().get(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 990 | } |
| 991 | |
| 992 | ThreadPlanSP |
| 993 | Thread::GetCompletedPlan () |
| 994 | { |
| 995 | ThreadPlanSP empty_plan_sp; |
| 996 | if (!m_completed_plan_stack.empty()) |
| 997 | { |
| 998 | for (int i = m_completed_plan_stack.size() - 1; i >= 0; i--) |
| 999 | { |
| 1000 | ThreadPlanSP completed_plan_sp; |
| 1001 | completed_plan_sp = m_completed_plan_stack[i]; |
| 1002 | if (!completed_plan_sp->GetPrivate ()) |
| 1003 | return completed_plan_sp; |
| 1004 | } |
| 1005 | } |
| 1006 | return empty_plan_sp; |
| 1007 | } |
| 1008 | |
Jim Ingham | 73ca05a | 2011-12-17 01:35:57 +0000 | [diff] [blame] | 1009 | ValueObjectSP |
| 1010 | Thread::GetReturnValueObject () |
| 1011 | { |
| 1012 | if (!m_completed_plan_stack.empty()) |
| 1013 | { |
| 1014 | for (int i = m_completed_plan_stack.size() - 1; i >= 0; i--) |
| 1015 | { |
| 1016 | ValueObjectSP return_valobj_sp; |
| 1017 | return_valobj_sp = m_completed_plan_stack[i]->GetReturnValueObject(); |
| 1018 | if (return_valobj_sp) |
| 1019 | return return_valobj_sp; |
| 1020 | } |
| 1021 | } |
| 1022 | return ValueObjectSP(); |
| 1023 | } |
| 1024 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1025 | bool |
| 1026 | Thread::IsThreadPlanDone (ThreadPlan *plan) |
| 1027 | { |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1028 | if (!m_completed_plan_stack.empty()) |
| 1029 | { |
| 1030 | for (int i = m_completed_plan_stack.size() - 1; i >= 0; i--) |
| 1031 | { |
| 1032 | if (m_completed_plan_stack[i].get() == plan) |
| 1033 | return true; |
| 1034 | } |
| 1035 | } |
| 1036 | return false; |
| 1037 | } |
| 1038 | |
| 1039 | bool |
| 1040 | Thread::WasThreadPlanDiscarded (ThreadPlan *plan) |
| 1041 | { |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1042 | if (!m_discarded_plan_stack.empty()) |
| 1043 | { |
| 1044 | for (int i = m_discarded_plan_stack.size() - 1; i >= 0; i--) |
| 1045 | { |
| 1046 | if (m_discarded_plan_stack[i].get() == plan) |
| 1047 | return true; |
| 1048 | } |
| 1049 | } |
| 1050 | return false; |
| 1051 | } |
| 1052 | |
| 1053 | ThreadPlan * |
| 1054 | Thread::GetPreviousPlan (ThreadPlan *current_plan) |
| 1055 | { |
| 1056 | if (current_plan == NULL) |
| 1057 | return NULL; |
| 1058 | |
| 1059 | int stack_size = m_completed_plan_stack.size(); |
| 1060 | for (int i = stack_size - 1; i > 0; i--) |
| 1061 | { |
| 1062 | if (current_plan == m_completed_plan_stack[i].get()) |
| 1063 | return m_completed_plan_stack[i-1].get(); |
| 1064 | } |
| 1065 | |
| 1066 | if (stack_size > 0 && m_completed_plan_stack[0].get() == current_plan) |
| 1067 | { |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1068 | if (m_plan_stack.size() > 0) |
| 1069 | return m_plan_stack.back().get(); |
| 1070 | else |
| 1071 | return NULL; |
| 1072 | } |
| 1073 | |
| 1074 | stack_size = m_plan_stack.size(); |
| 1075 | for (int i = stack_size - 1; i > 0; i--) |
| 1076 | { |
| 1077 | if (current_plan == m_plan_stack[i].get()) |
| 1078 | return m_plan_stack[i-1].get(); |
| 1079 | } |
| 1080 | return NULL; |
| 1081 | } |
| 1082 | |
| 1083 | void |
| 1084 | Thread::QueueThreadPlan (ThreadPlanSP &thread_plan_sp, bool abort_other_plans) |
| 1085 | { |
| 1086 | if (abort_other_plans) |
| 1087 | DiscardThreadPlans(true); |
| 1088 | |
| 1089 | PushPlan (thread_plan_sp); |
| 1090 | } |
| 1091 | |
Jim Ingham | 06e827c | 2010-11-11 19:26:09 +0000 | [diff] [blame] | 1092 | |
| 1093 | void |
| 1094 | Thread::EnableTracer (bool value, bool single_stepping) |
| 1095 | { |
| 1096 | int stack_size = m_plan_stack.size(); |
| 1097 | for (int i = 0; i < stack_size; i++) |
| 1098 | { |
| 1099 | if (m_plan_stack[i]->GetThreadPlanTracer()) |
| 1100 | { |
| 1101 | m_plan_stack[i]->GetThreadPlanTracer()->EnableTracing(value); |
| 1102 | m_plan_stack[i]->GetThreadPlanTracer()->EnableSingleStep(single_stepping); |
| 1103 | } |
| 1104 | } |
| 1105 | } |
| 1106 | |
| 1107 | void |
| 1108 | Thread::SetTracer (lldb::ThreadPlanTracerSP &tracer_sp) |
| 1109 | { |
| 1110 | int stack_size = m_plan_stack.size(); |
| 1111 | for (int i = 0; i < stack_size; i++) |
| 1112 | m_plan_stack[i]->SetThreadPlanTracer(tracer_sp); |
| 1113 | } |
| 1114 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1115 | void |
Jim Ingham | 399f1ca | 2010-11-05 19:25:48 +0000 | [diff] [blame] | 1116 | Thread::DiscardThreadPlansUpToPlan (lldb::ThreadPlanSP &up_to_plan_sp) |
| 1117 | { |
Jim Ingham | 64e7ead | 2012-05-03 21:19:36 +0000 | [diff] [blame] | 1118 | DiscardThreadPlansUpToPlan (up_to_plan_sp.get()); |
| 1119 | } |
| 1120 | |
| 1121 | void |
| 1122 | Thread::DiscardThreadPlansUpToPlan (ThreadPlan *up_to_plan_ptr) |
| 1123 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 1124 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); |
Jim Ingham | 399f1ca | 2010-11-05 19:25:48 +0000 | [diff] [blame] | 1125 | if (log) |
| 1126 | { |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 1127 | log->Printf("Discarding thread plans for thread tid = 0x%4.4" PRIx64 ", up to %p", GetID(), up_to_plan_ptr); |
Jim Ingham | 399f1ca | 2010-11-05 19:25:48 +0000 | [diff] [blame] | 1128 | } |
| 1129 | |
| 1130 | int stack_size = m_plan_stack.size(); |
| 1131 | |
| 1132 | // If the input plan is NULL, discard all plans. Otherwise make sure this plan is in the |
| 1133 | // stack, and if so discard up to and including it. |
| 1134 | |
Jim Ingham | 64e7ead | 2012-05-03 21:19:36 +0000 | [diff] [blame] | 1135 | if (up_to_plan_ptr == NULL) |
Jim Ingham | 399f1ca | 2010-11-05 19:25:48 +0000 | [diff] [blame] | 1136 | { |
| 1137 | for (int i = stack_size - 1; i > 0; i--) |
| 1138 | DiscardPlan(); |
| 1139 | } |
| 1140 | else |
| 1141 | { |
| 1142 | bool found_it = false; |
| 1143 | for (int i = stack_size - 1; i > 0; i--) |
| 1144 | { |
Jim Ingham | 64e7ead | 2012-05-03 21:19:36 +0000 | [diff] [blame] | 1145 | if (m_plan_stack[i].get() == up_to_plan_ptr) |
Jim Ingham | 399f1ca | 2010-11-05 19:25:48 +0000 | [diff] [blame] | 1146 | found_it = true; |
| 1147 | } |
| 1148 | if (found_it) |
| 1149 | { |
| 1150 | bool last_one = false; |
| 1151 | for (int i = stack_size - 1; i > 0 && !last_one ; i--) |
| 1152 | { |
Jim Ingham | 64e7ead | 2012-05-03 21:19:36 +0000 | [diff] [blame] | 1153 | if (GetCurrentPlan() == up_to_plan_ptr) |
Jim Ingham | 399f1ca | 2010-11-05 19:25:48 +0000 | [diff] [blame] | 1154 | last_one = true; |
| 1155 | DiscardPlan(); |
| 1156 | } |
| 1157 | } |
| 1158 | } |
| 1159 | return; |
| 1160 | } |
| 1161 | |
| 1162 | void |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1163 | Thread::DiscardThreadPlans(bool force) |
| 1164 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 1165 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1166 | if (log) |
| 1167 | { |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 1168 | log->Printf("Discarding thread plans for thread (tid = 0x%4.4" PRIx64 ", force %d)", GetID(), force); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1169 | } |
| 1170 | |
| 1171 | if (force) |
| 1172 | { |
| 1173 | int stack_size = m_plan_stack.size(); |
| 1174 | for (int i = stack_size - 1; i > 0; i--) |
| 1175 | { |
| 1176 | DiscardPlan(); |
| 1177 | } |
| 1178 | return; |
| 1179 | } |
| 1180 | |
| 1181 | while (1) |
| 1182 | { |
| 1183 | |
| 1184 | int master_plan_idx; |
Jim Ingham | a39ad07 | 2012-09-11 00:09:25 +0000 | [diff] [blame] | 1185 | bool discard = true; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1186 | |
| 1187 | // Find the first master plan, see if it wants discarding, and if yes discard up to it. |
| 1188 | for (master_plan_idx = m_plan_stack.size() - 1; master_plan_idx >= 0; master_plan_idx--) |
| 1189 | { |
| 1190 | if (m_plan_stack[master_plan_idx]->IsMasterPlan()) |
| 1191 | { |
| 1192 | discard = m_plan_stack[master_plan_idx]->OkayToDiscard(); |
| 1193 | break; |
| 1194 | } |
| 1195 | } |
| 1196 | |
| 1197 | if (discard) |
| 1198 | { |
| 1199 | // First pop all the dependent plans: |
| 1200 | for (int i = m_plan_stack.size() - 1; i > master_plan_idx; i--) |
| 1201 | { |
| 1202 | |
| 1203 | // FIXME: Do we need a finalize here, or is the rule that "PrepareForStop" |
| 1204 | // for the plan leaves it in a state that it is safe to pop the plan |
| 1205 | // with no more notice? |
| 1206 | DiscardPlan(); |
| 1207 | } |
| 1208 | |
| 1209 | // Now discard the master plan itself. |
| 1210 | // The bottom-most plan never gets discarded. "OkayToDiscard" for it means |
| 1211 | // discard it's dependent plans, but not it... |
| 1212 | if (master_plan_idx > 0) |
| 1213 | { |
| 1214 | DiscardPlan(); |
| 1215 | } |
| 1216 | } |
| 1217 | else |
| 1218 | { |
| 1219 | // If the master plan doesn't want to get discarded, then we're done. |
| 1220 | break; |
| 1221 | } |
| 1222 | |
| 1223 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1224 | } |
| 1225 | |
Jim Ingham | cf274f9 | 2012-04-09 22:37:39 +0000 | [diff] [blame] | 1226 | bool |
| 1227 | Thread::PlanIsBasePlan (ThreadPlan *plan_ptr) |
| 1228 | { |
| 1229 | if (plan_ptr->IsBasePlan()) |
| 1230 | return true; |
| 1231 | else if (m_plan_stack.size() == 0) |
| 1232 | return false; |
| 1233 | else |
| 1234 | return m_plan_stack[0].get() == plan_ptr; |
| 1235 | } |
| 1236 | |
Jim Ingham | 93208b8 | 2013-01-31 21:46:01 +0000 | [diff] [blame] | 1237 | Error |
| 1238 | Thread::UnwindInnermostExpression() |
| 1239 | { |
| 1240 | Error error; |
| 1241 | int stack_size = m_plan_stack.size(); |
| 1242 | |
| 1243 | // If the input plan is NULL, discard all plans. Otherwise make sure this plan is in the |
| 1244 | // stack, and if so discard up to and including it. |
| 1245 | |
| 1246 | for (int i = stack_size - 1; i > 0; i--) |
| 1247 | { |
| 1248 | if (m_plan_stack[i]->GetKind() == ThreadPlan::eKindCallFunction) |
| 1249 | { |
| 1250 | DiscardThreadPlansUpToPlan(m_plan_stack[i].get()); |
| 1251 | return error; |
| 1252 | } |
| 1253 | } |
| 1254 | error.SetErrorString("No expressions currently active on this thread"); |
| 1255 | return error; |
| 1256 | } |
| 1257 | |
| 1258 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1259 | ThreadPlan * |
| 1260 | Thread::QueueFundamentalPlan (bool abort_other_plans) |
| 1261 | { |
| 1262 | ThreadPlanSP thread_plan_sp (new ThreadPlanBase(*this)); |
| 1263 | QueueThreadPlan (thread_plan_sp, abort_other_plans); |
| 1264 | return thread_plan_sp.get(); |
| 1265 | } |
| 1266 | |
| 1267 | ThreadPlan * |
Greg Clayton | 481cef2 | 2011-01-21 06:11:58 +0000 | [diff] [blame] | 1268 | Thread::QueueThreadPlanForStepSingleInstruction |
| 1269 | ( |
| 1270 | bool step_over, |
| 1271 | bool abort_other_plans, |
| 1272 | bool stop_other_threads |
| 1273 | ) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1274 | { |
| 1275 | ThreadPlanSP thread_plan_sp (new ThreadPlanStepInstruction (*this, step_over, stop_other_threads, eVoteNoOpinion, eVoteNoOpinion)); |
| 1276 | QueueThreadPlan (thread_plan_sp, abort_other_plans); |
| 1277 | return thread_plan_sp.get(); |
| 1278 | } |
| 1279 | |
| 1280 | ThreadPlan * |
Jim Ingham | c627682 | 2012-12-12 19:58:40 +0000 | [diff] [blame] | 1281 | Thread::QueueThreadPlanForStepOverRange |
Greg Clayton | 474966a | 2010-06-12 18:59:55 +0000 | [diff] [blame] | 1282 | ( |
| 1283 | bool abort_other_plans, |
Greg Clayton | 474966a | 2010-06-12 18:59:55 +0000 | [diff] [blame] | 1284 | const AddressRange &range, |
Jim Ingham | c627682 | 2012-12-12 19:58:40 +0000 | [diff] [blame] | 1285 | const SymbolContext &addr_context, |
| 1286 | lldb::RunMode stop_other_threads |
| 1287 | ) |
| 1288 | { |
| 1289 | ThreadPlanSP thread_plan_sp; |
| 1290 | thread_plan_sp.reset (new ThreadPlanStepOverRange (*this, range, addr_context, stop_other_threads)); |
| 1291 | |
| 1292 | QueueThreadPlan (thread_plan_sp, abort_other_plans); |
| 1293 | return thread_plan_sp.get(); |
| 1294 | } |
| 1295 | |
| 1296 | ThreadPlan * |
| 1297 | Thread::QueueThreadPlanForStepInRange |
| 1298 | ( |
| 1299 | bool abort_other_plans, |
| 1300 | const AddressRange &range, |
| 1301 | const SymbolContext &addr_context, |
| 1302 | const char *step_in_target, |
Greg Clayton | 474966a | 2010-06-12 18:59:55 +0000 | [diff] [blame] | 1303 | lldb::RunMode stop_other_threads, |
| 1304 | bool avoid_code_without_debug_info |
| 1305 | ) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1306 | { |
| 1307 | ThreadPlanSP thread_plan_sp; |
Jim Ingham | c627682 | 2012-12-12 19:58:40 +0000 | [diff] [blame] | 1308 | ThreadPlanStepInRange *plan = new ThreadPlanStepInRange (*this, range, addr_context, stop_other_threads); |
| 1309 | if (avoid_code_without_debug_info) |
| 1310 | plan->GetFlags().Set (ThreadPlanShouldStopHere::eAvoidNoDebug); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1311 | else |
Jim Ingham | c627682 | 2012-12-12 19:58:40 +0000 | [diff] [blame] | 1312 | plan->GetFlags().Clear (ThreadPlanShouldStopHere::eAvoidNoDebug); |
| 1313 | if (step_in_target) |
| 1314 | plan->SetStepInTarget(step_in_target); |
| 1315 | thread_plan_sp.reset (plan); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1316 | |
| 1317 | QueueThreadPlan (thread_plan_sp, abort_other_plans); |
| 1318 | return thread_plan_sp.get(); |
| 1319 | } |
| 1320 | |
| 1321 | |
| 1322 | ThreadPlan * |
| 1323 | Thread::QueueThreadPlanForStepOverBreakpointPlan (bool abort_other_plans) |
| 1324 | { |
| 1325 | ThreadPlanSP thread_plan_sp (new ThreadPlanStepOverBreakpoint (*this)); |
| 1326 | QueueThreadPlan (thread_plan_sp, abort_other_plans); |
| 1327 | return thread_plan_sp.get(); |
| 1328 | } |
| 1329 | |
| 1330 | ThreadPlan * |
Greg Clayton | 481cef2 | 2011-01-21 06:11:58 +0000 | [diff] [blame] | 1331 | Thread::QueueThreadPlanForStepOut |
| 1332 | ( |
| 1333 | bool abort_other_plans, |
| 1334 | SymbolContext *addr_context, |
| 1335 | bool first_insn, |
| 1336 | bool stop_other_threads, |
| 1337 | Vote stop_vote, |
| 1338 | Vote run_vote, |
| 1339 | uint32_t frame_idx |
| 1340 | ) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1341 | { |
Greg Clayton | 481cef2 | 2011-01-21 06:11:58 +0000 | [diff] [blame] | 1342 | ThreadPlanSP thread_plan_sp (new ThreadPlanStepOut (*this, |
| 1343 | addr_context, |
| 1344 | first_insn, |
| 1345 | stop_other_threads, |
| 1346 | stop_vote, |
| 1347 | run_vote, |
| 1348 | frame_idx)); |
Sean Callanan | 708709c | 2012-07-31 22:19:25 +0000 | [diff] [blame] | 1349 | |
| 1350 | if (thread_plan_sp->ValidatePlan(NULL)) |
| 1351 | { |
| 1352 | QueueThreadPlan (thread_plan_sp, abort_other_plans); |
| 1353 | return thread_plan_sp.get(); |
| 1354 | } |
| 1355 | else |
| 1356 | { |
| 1357 | return NULL; |
| 1358 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1359 | } |
| 1360 | |
| 1361 | ThreadPlan * |
Jim Ingham | 18de2fd | 2012-05-10 01:35:39 +0000 | [diff] [blame] | 1362 | Thread::QueueThreadPlanForStepThrough (StackID &return_stack_id, bool abort_other_plans, bool stop_other_threads) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1363 | { |
Jim Ingham | 18de2fd | 2012-05-10 01:35:39 +0000 | [diff] [blame] | 1364 | ThreadPlanSP thread_plan_sp(new ThreadPlanStepThrough (*this, return_stack_id, stop_other_threads)); |
Jim Ingham | 25f6670 | 2011-12-03 01:52:59 +0000 | [diff] [blame] | 1365 | if (!thread_plan_sp || !thread_plan_sp->ValidatePlan (NULL)) |
| 1366 | return NULL; |
| 1367 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1368 | QueueThreadPlan (thread_plan_sp, abort_other_plans); |
| 1369 | return thread_plan_sp.get(); |
| 1370 | } |
| 1371 | |
| 1372 | ThreadPlan * |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1373 | Thread::QueueThreadPlanForCallFunction (bool abort_other_plans, |
| 1374 | Address& function, |
| 1375 | lldb::addr_t arg, |
| 1376 | bool stop_other_threads, |
Jim Ingham | 184e981 | 2013-01-15 02:47:48 +0000 | [diff] [blame] | 1377 | bool unwind_on_error, |
| 1378 | bool ignore_breakpoints) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1379 | { |
Jim Ingham | 184e981 | 2013-01-15 02:47:48 +0000 | [diff] [blame] | 1380 | ThreadPlanSP thread_plan_sp (new ThreadPlanCallFunction (*this, |
| 1381 | function, |
| 1382 | ClangASTType(), |
| 1383 | arg, |
| 1384 | stop_other_threads, |
| 1385 | unwind_on_error, |
| 1386 | ignore_breakpoints)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1387 | QueueThreadPlan (thread_plan_sp, abort_other_plans); |
| 1388 | return thread_plan_sp.get(); |
| 1389 | } |
| 1390 | |
| 1391 | ThreadPlan * |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1392 | Thread::QueueThreadPlanForRunToAddress (bool abort_other_plans, |
| 1393 | Address &target_addr, |
| 1394 | bool stop_other_threads) |
| 1395 | { |
| 1396 | ThreadPlanSP thread_plan_sp (new ThreadPlanRunToAddress (*this, target_addr, stop_other_threads)); |
| 1397 | QueueThreadPlan (thread_plan_sp, abort_other_plans); |
| 1398 | return thread_plan_sp.get(); |
| 1399 | } |
| 1400 | |
| 1401 | ThreadPlan * |
| 1402 | Thread::QueueThreadPlanForStepUntil (bool abort_other_plans, |
Greg Clayton | 481cef2 | 2011-01-21 06:11:58 +0000 | [diff] [blame] | 1403 | lldb::addr_t *address_list, |
| 1404 | size_t num_addresses, |
| 1405 | bool stop_other_threads, |
| 1406 | uint32_t frame_idx) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1407 | { |
Greg Clayton | 481cef2 | 2011-01-21 06:11:58 +0000 | [diff] [blame] | 1408 | ThreadPlanSP thread_plan_sp (new ThreadPlanStepUntil (*this, address_list, num_addresses, stop_other_threads, frame_idx)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1409 | QueueThreadPlan (thread_plan_sp, abort_other_plans); |
| 1410 | return thread_plan_sp.get(); |
| 1411 | |
| 1412 | } |
| 1413 | |
| 1414 | uint32_t |
| 1415 | Thread::GetIndexID () const |
| 1416 | { |
| 1417 | return m_index_id; |
| 1418 | } |
| 1419 | |
| 1420 | void |
| 1421 | Thread::DumpThreadPlans (lldb_private::Stream *s) const |
| 1422 | { |
| 1423 | uint32_t stack_size = m_plan_stack.size(); |
Greg Clayton | 1346f7e | 2010-09-03 22:45:01 +0000 | [diff] [blame] | 1424 | int i; |
Jim Ingham | 10c4b24 | 2011-10-15 00:23:43 +0000 | [diff] [blame] | 1425 | s->Indent(); |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 1426 | s->Printf ("Plan Stack for thread #%u: tid = 0x%4.4" PRIx64 ", stack_size = %d\n", GetIndexID(), GetID(), stack_size); |
Greg Clayton | 1346f7e | 2010-09-03 22:45:01 +0000 | [diff] [blame] | 1427 | for (i = stack_size - 1; i >= 0; i--) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1428 | { |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1429 | s->IndentMore(); |
Jim Ingham | 10c4b24 | 2011-10-15 00:23:43 +0000 | [diff] [blame] | 1430 | s->Indent(); |
| 1431 | s->Printf ("Element %d: ", i); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1432 | m_plan_stack[i]->GetDescription (s, eDescriptionLevelFull); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1433 | s->EOL(); |
Jim Ingham | 10c4b24 | 2011-10-15 00:23:43 +0000 | [diff] [blame] | 1434 | s->IndentLess(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1435 | } |
| 1436 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1437 | stack_size = m_completed_plan_stack.size(); |
Jim Ingham | 10c4b24 | 2011-10-15 00:23:43 +0000 | [diff] [blame] | 1438 | if (stack_size > 0) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1439 | { |
Jim Ingham | 10c4b24 | 2011-10-15 00:23:43 +0000 | [diff] [blame] | 1440 | s->Indent(); |
| 1441 | s->Printf ("Completed Plan Stack: %d elements.\n", stack_size); |
| 1442 | for (i = stack_size - 1; i >= 0; i--) |
| 1443 | { |
| 1444 | s->IndentMore(); |
| 1445 | s->Indent(); |
| 1446 | s->Printf ("Element %d: ", i); |
| 1447 | m_completed_plan_stack[i]->GetDescription (s, eDescriptionLevelFull); |
| 1448 | s->EOL(); |
| 1449 | s->IndentLess(); |
| 1450 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1451 | } |
| 1452 | |
| 1453 | stack_size = m_discarded_plan_stack.size(); |
Jim Ingham | 10c4b24 | 2011-10-15 00:23:43 +0000 | [diff] [blame] | 1454 | if (stack_size > 0) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1455 | { |
Jim Ingham | 10c4b24 | 2011-10-15 00:23:43 +0000 | [diff] [blame] | 1456 | s->Indent(); |
| 1457 | s->Printf ("Discarded Plan Stack: %d elements.\n", stack_size); |
| 1458 | for (i = stack_size - 1; i >= 0; i--) |
| 1459 | { |
| 1460 | s->IndentMore(); |
| 1461 | s->Indent(); |
| 1462 | s->Printf ("Element %d: ", i); |
| 1463 | m_discarded_plan_stack[i]->GetDescription (s, eDescriptionLevelFull); |
| 1464 | s->EOL(); |
| 1465 | s->IndentLess(); |
| 1466 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1467 | } |
| 1468 | |
| 1469 | } |
| 1470 | |
Greg Clayton | d9e416c | 2012-02-18 05:35:26 +0000 | [diff] [blame] | 1471 | TargetSP |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1472 | Thread::CalculateTarget () |
| 1473 | { |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 1474 | TargetSP target_sp; |
| 1475 | ProcessSP process_sp(GetProcess()); |
| 1476 | if (process_sp) |
| 1477 | target_sp = process_sp->CalculateTarget(); |
| 1478 | return target_sp; |
| 1479 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1480 | } |
| 1481 | |
Greg Clayton | d9e416c | 2012-02-18 05:35:26 +0000 | [diff] [blame] | 1482 | ProcessSP |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1483 | Thread::CalculateProcess () |
| 1484 | { |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 1485 | return GetProcess(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1486 | } |
| 1487 | |
Greg Clayton | d9e416c | 2012-02-18 05:35:26 +0000 | [diff] [blame] | 1488 | ThreadSP |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1489 | Thread::CalculateThread () |
| 1490 | { |
Greg Clayton | d9e416c | 2012-02-18 05:35:26 +0000 | [diff] [blame] | 1491 | return shared_from_this(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1492 | } |
| 1493 | |
Greg Clayton | d9e416c | 2012-02-18 05:35:26 +0000 | [diff] [blame] | 1494 | StackFrameSP |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1495 | Thread::CalculateStackFrame () |
| 1496 | { |
Greg Clayton | d9e416c | 2012-02-18 05:35:26 +0000 | [diff] [blame] | 1497 | return StackFrameSP(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1498 | } |
| 1499 | |
| 1500 | void |
Greg Clayton | 0603aa9 | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 1501 | Thread::CalculateExecutionContext (ExecutionContext &exe_ctx) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1502 | { |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 1503 | exe_ctx.SetContext (shared_from_this()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1504 | } |
| 1505 | |
Greg Clayton | 12daf946 | 2010-08-25 00:35:26 +0000 | [diff] [blame] | 1506 | |
Greg Clayton | 39d0ab3 | 2012-03-29 01:41:38 +0000 | [diff] [blame] | 1507 | StackFrameListSP |
Greg Clayton | 12daf946 | 2010-08-25 00:35:26 +0000 | [diff] [blame] | 1508 | Thread::GetStackFrameList () |
| 1509 | { |
Greg Clayton | 39d0ab3 | 2012-03-29 01:41:38 +0000 | [diff] [blame] | 1510 | StackFrameListSP frame_list_sp; |
| 1511 | Mutex::Locker locker(m_frame_mutex); |
| 1512 | if (m_curr_frames_sp) |
| 1513 | { |
| 1514 | frame_list_sp = m_curr_frames_sp; |
| 1515 | } |
| 1516 | else |
| 1517 | { |
| 1518 | frame_list_sp.reset(new StackFrameList (*this, m_prev_frames_sp, true)); |
| 1519 | m_curr_frames_sp = frame_list_sp; |
| 1520 | } |
| 1521 | return frame_list_sp; |
Greg Clayton | 12daf946 | 2010-08-25 00:35:26 +0000 | [diff] [blame] | 1522 | } |
| 1523 | |
Greg Clayton | 12daf946 | 2010-08-25 00:35:26 +0000 | [diff] [blame] | 1524 | void |
| 1525 | Thread::ClearStackFrames () |
| 1526 | { |
Greg Clayton | 39d0ab3 | 2012-03-29 01:41:38 +0000 | [diff] [blame] | 1527 | Mutex::Locker locker(m_frame_mutex); |
| 1528 | |
Greg Clayton | 160c9d8 | 2013-05-01 21:54:04 +0000 | [diff] [blame] | 1529 | Unwind *unwinder = GetUnwinder (); |
| 1530 | if (unwinder) |
| 1531 | unwinder->Clear(); |
| 1532 | |
Jim Ingham | b0c72a5 | 2012-02-29 03:40:22 +0000 | [diff] [blame] | 1533 | // Only store away the old "reference" StackFrameList if we got all its frames: |
| 1534 | // FIXME: At some point we can try to splice in the frames we have fetched into |
| 1535 | // the new frame as we make it, but let's not try that now. |
| 1536 | if (m_curr_frames_sp && m_curr_frames_sp->GetAllFramesFetched()) |
Greg Clayton | 7e9b1fd | 2011-08-12 21:40:01 +0000 | [diff] [blame] | 1537 | m_prev_frames_sp.swap (m_curr_frames_sp); |
| 1538 | m_curr_frames_sp.reset(); |
Jim Ingham | 87c1191 | 2010-08-12 02:14:28 +0000 | [diff] [blame] | 1539 | } |
| 1540 | |
| 1541 | lldb::StackFrameSP |
Greg Clayton | 5ccbd29 | 2011-01-06 22:15:06 +0000 | [diff] [blame] | 1542 | Thread::GetFrameWithConcreteFrameIndex (uint32_t unwind_idx) |
| 1543 | { |
Greg Clayton | 39d0ab3 | 2012-03-29 01:41:38 +0000 | [diff] [blame] | 1544 | return GetStackFrameList()->GetFrameWithConcreteFrameIndex (unwind_idx); |
Greg Clayton | 5ccbd29 | 2011-01-06 22:15:06 +0000 | [diff] [blame] | 1545 | } |
| 1546 | |
Jim Ingham | 4413758 | 2012-09-12 00:40:39 +0000 | [diff] [blame] | 1547 | |
| 1548 | Error |
Jim Ingham | 4f465cf | 2012-10-10 18:32:14 +0000 | [diff] [blame] | 1549 | Thread::ReturnFromFrameWithIndex (uint32_t frame_idx, lldb::ValueObjectSP return_value_sp, bool broadcast) |
Jim Ingham | 4413758 | 2012-09-12 00:40:39 +0000 | [diff] [blame] | 1550 | { |
| 1551 | StackFrameSP frame_sp = GetStackFrameAtIndex (frame_idx); |
| 1552 | Error return_error; |
| 1553 | |
| 1554 | if (!frame_sp) |
| 1555 | { |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 1556 | return_error.SetErrorStringWithFormat("Could not find frame with index %d in thread 0x%" PRIx64 ".", frame_idx, GetID()); |
Jim Ingham | 4413758 | 2012-09-12 00:40:39 +0000 | [diff] [blame] | 1557 | } |
| 1558 | |
Jim Ingham | 4f465cf | 2012-10-10 18:32:14 +0000 | [diff] [blame] | 1559 | return ReturnFromFrame(frame_sp, return_value_sp, broadcast); |
Jim Ingham | 4413758 | 2012-09-12 00:40:39 +0000 | [diff] [blame] | 1560 | } |
| 1561 | |
| 1562 | Error |
Jim Ingham | 4f465cf | 2012-10-10 18:32:14 +0000 | [diff] [blame] | 1563 | Thread::ReturnFromFrame (lldb::StackFrameSP frame_sp, lldb::ValueObjectSP return_value_sp, bool broadcast) |
Jim Ingham | 4413758 | 2012-09-12 00:40:39 +0000 | [diff] [blame] | 1564 | { |
| 1565 | Error return_error; |
| 1566 | |
| 1567 | if (!frame_sp) |
| 1568 | { |
| 1569 | return_error.SetErrorString("Can't return to a null frame."); |
| 1570 | return return_error; |
| 1571 | } |
| 1572 | |
| 1573 | Thread *thread = frame_sp->GetThread().get(); |
Jim Ingham | cb640dd | 2012-09-14 02:14:15 +0000 | [diff] [blame] | 1574 | uint32_t older_frame_idx = frame_sp->GetFrameIndex() + 1; |
| 1575 | StackFrameSP older_frame_sp = thread->GetStackFrameAtIndex(older_frame_idx); |
Jim Ingham | 93208b8 | 2013-01-31 21:46:01 +0000 | [diff] [blame] | 1576 | if (!older_frame_sp) |
| 1577 | { |
| 1578 | return_error.SetErrorString("No older frame to return to."); |
| 1579 | return return_error; |
| 1580 | } |
Jim Ingham | 4413758 | 2012-09-12 00:40:39 +0000 | [diff] [blame] | 1581 | |
| 1582 | if (return_value_sp) |
Jim Ingham | 1f51e60 | 2012-09-27 01:15:29 +0000 | [diff] [blame] | 1583 | { |
Jim Ingham | 4413758 | 2012-09-12 00:40:39 +0000 | [diff] [blame] | 1584 | lldb::ABISP abi = thread->GetProcess()->GetABI(); |
| 1585 | if (!abi) |
| 1586 | { |
| 1587 | return_error.SetErrorString("Could not find ABI to set return value."); |
Jim Ingham | 28eb571 | 2012-10-12 17:34:26 +0000 | [diff] [blame] | 1588 | return return_error; |
Jim Ingham | 4413758 | 2012-09-12 00:40:39 +0000 | [diff] [blame] | 1589 | } |
Jim Ingham | 1f51e60 | 2012-09-27 01:15:29 +0000 | [diff] [blame] | 1590 | SymbolContext sc = frame_sp->GetSymbolContext(eSymbolContextFunction); |
| 1591 | |
| 1592 | // FIXME: ValueObject::Cast doesn't currently work correctly, at least not for scalars. |
| 1593 | // Turn that back on when that works. |
| 1594 | if (0 && sc.function != NULL) |
| 1595 | { |
| 1596 | Type *function_type = sc.function->GetType(); |
| 1597 | if (function_type) |
| 1598 | { |
| 1599 | clang_type_t return_type = sc.function->GetReturnClangType(); |
| 1600 | if (return_type) |
| 1601 | { |
| 1602 | ClangASTType ast_type (function_type->GetClangAST(), return_type); |
| 1603 | StreamString s; |
| 1604 | ast_type.DumpTypeDescription(&s); |
| 1605 | ValueObjectSP cast_value_sp = return_value_sp->Cast(ast_type); |
| 1606 | if (cast_value_sp) |
| 1607 | { |
| 1608 | cast_value_sp->SetFormat(eFormatHex); |
| 1609 | return_value_sp = cast_value_sp; |
| 1610 | } |
| 1611 | } |
| 1612 | } |
| 1613 | } |
| 1614 | |
Jim Ingham | cb640dd | 2012-09-14 02:14:15 +0000 | [diff] [blame] | 1615 | return_error = abi->SetReturnValueObject(older_frame_sp, return_value_sp); |
Jim Ingham | 4413758 | 2012-09-12 00:40:39 +0000 | [diff] [blame] | 1616 | if (!return_error.Success()) |
| 1617 | return return_error; |
| 1618 | } |
| 1619 | |
| 1620 | // Now write the return registers for the chosen frame: |
Jim Ingham | cb640dd | 2012-09-14 02:14:15 +0000 | [diff] [blame] | 1621 | // Note, we can't use ReadAllRegisterValues->WriteAllRegisterValues, since the read & write |
Jim Ingham | 93208b8 | 2013-01-31 21:46:01 +0000 | [diff] [blame] | 1622 | // cook their data |
| 1623 | |
| 1624 | StackFrameSP youngest_frame_sp = thread->GetStackFrameAtIndex(0); |
| 1625 | if (youngest_frame_sp) |
Jim Ingham | 4413758 | 2012-09-12 00:40:39 +0000 | [diff] [blame] | 1626 | { |
Greg Clayton | 1afa68e | 2013-04-02 20:32:37 +0000 | [diff] [blame] | 1627 | lldb::RegisterContextSP reg_ctx_sp (youngest_frame_sp->GetRegisterContext()); |
| 1628 | if (reg_ctx_sp) |
Jim Ingham | 93208b8 | 2013-01-31 21:46:01 +0000 | [diff] [blame] | 1629 | { |
Greg Clayton | 1afa68e | 2013-04-02 20:32:37 +0000 | [diff] [blame] | 1630 | bool copy_success = reg_ctx_sp->CopyFromRegisterContext(older_frame_sp->GetRegisterContext()); |
| 1631 | if (copy_success) |
| 1632 | { |
| 1633 | thread->DiscardThreadPlans(true); |
| 1634 | thread->ClearStackFrames(); |
| 1635 | if (broadcast && EventTypeHasListeners(eBroadcastBitStackChanged)) |
| 1636 | BroadcastEvent(eBroadcastBitStackChanged, new ThreadEventData (this->shared_from_this())); |
| 1637 | } |
| 1638 | else |
| 1639 | { |
| 1640 | return_error.SetErrorString("Could not reset register values."); |
| 1641 | } |
Jim Ingham | 93208b8 | 2013-01-31 21:46:01 +0000 | [diff] [blame] | 1642 | } |
| 1643 | else |
| 1644 | { |
Greg Clayton | 1afa68e | 2013-04-02 20:32:37 +0000 | [diff] [blame] | 1645 | return_error.SetErrorString("Frame has no register context."); |
Jim Ingham | 93208b8 | 2013-01-31 21:46:01 +0000 | [diff] [blame] | 1646 | } |
Jim Ingham | 4413758 | 2012-09-12 00:40:39 +0000 | [diff] [blame] | 1647 | } |
| 1648 | else |
| 1649 | { |
Jim Ingham | 93208b8 | 2013-01-31 21:46:01 +0000 | [diff] [blame] | 1650 | return_error.SetErrorString("Returned past top frame."); |
Jim Ingham | 4413758 | 2012-09-12 00:40:39 +0000 | [diff] [blame] | 1651 | } |
Greg Clayton | abb487f | 2013-02-01 02:52:31 +0000 | [diff] [blame] | 1652 | return return_error; |
Jim Ingham | 4413758 | 2012-09-12 00:40:39 +0000 | [diff] [blame] | 1653 | } |
| 1654 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1655 | void |
Greg Clayton | 0603aa9 | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 1656 | Thread::DumpUsingSettingsFormat (Stream &strm, uint32_t frame_idx) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1657 | { |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 1658 | ExecutionContext exe_ctx (shared_from_this()); |
| 1659 | Process *process = exe_ctx.GetProcessPtr(); |
| 1660 | if (process == NULL) |
| 1661 | return; |
| 1662 | |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 1663 | StackFrameSP frame_sp; |
Greg Clayton | 0603aa9 | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 1664 | SymbolContext frame_sc; |
Greg Clayton | 0603aa9 | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 1665 | if (frame_idx != LLDB_INVALID_INDEX32) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1666 | { |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 1667 | frame_sp = GetStackFrameAtIndex (frame_idx); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1668 | if (frame_sp) |
| 1669 | { |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 1670 | exe_ctx.SetFrameSP(frame_sp); |
| 1671 | frame_sc = frame_sp->GetSymbolContext(eSymbolContextEverything); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1672 | } |
| 1673 | } |
| 1674 | |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 1675 | const char *thread_format = exe_ctx.GetTargetRef().GetDebugger().GetThreadFormat(); |
Greg Clayton | 0603aa9 | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 1676 | assert (thread_format); |
| 1677 | const char *end = NULL; |
| 1678 | Debugger::FormatPrompt (thread_format, |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 1679 | frame_sp ? &frame_sc : NULL, |
Greg Clayton | 0603aa9 | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 1680 | &exe_ctx, |
| 1681 | NULL, |
| 1682 | strm, |
| 1683 | &end); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1684 | } |
| 1685 | |
Greg Clayton | 99d0faf | 2010-11-18 23:32:35 +0000 | [diff] [blame] | 1686 | void |
Caroline Tice | 20bd37f | 2011-03-10 22:14:10 +0000 | [diff] [blame] | 1687 | Thread::SettingsInitialize () |
Jim Ingham | ee8aea1 | 2010-09-08 03:14:33 +0000 | [diff] [blame] | 1688 | { |
Greg Clayton | 99d0faf | 2010-11-18 23:32:35 +0000 | [diff] [blame] | 1689 | } |
Jim Ingham | ee8aea1 | 2010-09-08 03:14:33 +0000 | [diff] [blame] | 1690 | |
Greg Clayton | 99d0faf | 2010-11-18 23:32:35 +0000 | [diff] [blame] | 1691 | void |
Caroline Tice | 20bd37f | 2011-03-10 22:14:10 +0000 | [diff] [blame] | 1692 | Thread::SettingsTerminate () |
Greg Clayton | 99d0faf | 2010-11-18 23:32:35 +0000 | [diff] [blame] | 1693 | { |
Greg Clayton | 99d0faf | 2010-11-18 23:32:35 +0000 | [diff] [blame] | 1694 | } |
Jim Ingham | ee8aea1 | 2010-09-08 03:14:33 +0000 | [diff] [blame] | 1695 | |
Jim Ingham | e4284b7 | 2010-09-23 17:40:12 +0000 | [diff] [blame] | 1696 | lldb::StackFrameSP |
| 1697 | Thread::GetStackFrameSPForStackFramePtr (StackFrame *stack_frame_ptr) |
| 1698 | { |
Greg Clayton | 39d0ab3 | 2012-03-29 01:41:38 +0000 | [diff] [blame] | 1699 | return GetStackFrameList()->GetStackFrameSPForStackFramePtr (stack_frame_ptr); |
Jim Ingham | e4284b7 | 2010-09-23 17:40:12 +0000 | [diff] [blame] | 1700 | } |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 1701 | |
| 1702 | const char * |
| 1703 | Thread::StopReasonAsCString (lldb::StopReason reason) |
| 1704 | { |
| 1705 | switch (reason) |
| 1706 | { |
Andrew Kaylor | f85defa | 2012-12-20 23:08:03 +0000 | [diff] [blame] | 1707 | case eStopReasonInvalid: return "invalid"; |
| 1708 | case eStopReasonNone: return "none"; |
| 1709 | case eStopReasonTrace: return "trace"; |
| 1710 | case eStopReasonBreakpoint: return "breakpoint"; |
| 1711 | case eStopReasonWatchpoint: return "watchpoint"; |
| 1712 | case eStopReasonSignal: return "signal"; |
| 1713 | case eStopReasonException: return "exception"; |
| 1714 | case eStopReasonExec: return "exec"; |
| 1715 | case eStopReasonPlanComplete: return "plan complete"; |
| 1716 | case eStopReasonThreadExiting: return "thread exiting"; |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 1717 | } |
| 1718 | |
| 1719 | |
| 1720 | static char unknown_state_string[64]; |
| 1721 | snprintf(unknown_state_string, sizeof (unknown_state_string), "StopReason = %i", reason); |
| 1722 | return unknown_state_string; |
| 1723 | } |
| 1724 | |
| 1725 | const char * |
| 1726 | Thread::RunModeAsCString (lldb::RunMode mode) |
| 1727 | { |
| 1728 | switch (mode) |
| 1729 | { |
| 1730 | case eOnlyThisThread: return "only this thread"; |
| 1731 | case eAllThreads: return "all threads"; |
| 1732 | case eOnlyDuringStepping: return "only during stepping"; |
| 1733 | } |
| 1734 | |
| 1735 | static char unknown_state_string[64]; |
| 1736 | snprintf(unknown_state_string, sizeof (unknown_state_string), "RunMode = %i", mode); |
| 1737 | return unknown_state_string; |
| 1738 | } |
Jim Ingham | 06e827c | 2010-11-11 19:26:09 +0000 | [diff] [blame] | 1739 | |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 1740 | size_t |
| 1741 | Thread::GetStatus (Stream &strm, uint32_t start_frame, uint32_t num_frames, uint32_t num_frames_with_source) |
| 1742 | { |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 1743 | ExecutionContext exe_ctx (shared_from_this()); |
| 1744 | Target *target = exe_ctx.GetTargetPtr(); |
| 1745 | Process *process = exe_ctx.GetProcessPtr(); |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 1746 | size_t num_frames_shown = 0; |
| 1747 | strm.Indent(); |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 1748 | bool is_selected = false; |
| 1749 | if (process) |
| 1750 | { |
| 1751 | if (process->GetThreadList().GetSelectedThread().get() == this) |
| 1752 | is_selected = true; |
| 1753 | } |
| 1754 | strm.Printf("%c ", is_selected ? '*' : ' '); |
| 1755 | if (target && target->GetDebugger().GetUseExternalEditor()) |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 1756 | { |
Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 1757 | StackFrameSP frame_sp = GetStackFrameAtIndex(start_frame); |
Jim Ingham | e610d64 | 2011-08-16 00:07:28 +0000 | [diff] [blame] | 1758 | if (frame_sp) |
Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 1759 | { |
Jim Ingham | e610d64 | 2011-08-16 00:07:28 +0000 | [diff] [blame] | 1760 | SymbolContext frame_sc(frame_sp->GetSymbolContext (eSymbolContextLineEntry)); |
| 1761 | if (frame_sc.line_entry.line != 0 && frame_sc.line_entry.file) |
| 1762 | { |
| 1763 | Host::OpenFileInExternalEditor (frame_sc.line_entry.file, frame_sc.line_entry.line); |
| 1764 | } |
Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 1765 | } |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 1766 | } |
| 1767 | |
| 1768 | DumpUsingSettingsFormat (strm, start_frame); |
| 1769 | |
| 1770 | if (num_frames > 0) |
| 1771 | { |
| 1772 | strm.IndentMore(); |
| 1773 | |
| 1774 | const bool show_frame_info = true; |
Jim Ingham | 5c4df7a | 2011-07-26 02:39:59 +0000 | [diff] [blame] | 1775 | strm.IndentMore (); |
Greg Clayton | 39d0ab3 | 2012-03-29 01:41:38 +0000 | [diff] [blame] | 1776 | num_frames_shown = GetStackFrameList ()->GetStatus (strm, |
| 1777 | start_frame, |
| 1778 | num_frames, |
| 1779 | show_frame_info, |
Greg Clayton | 53eb7ad | 2012-07-11 20:33:48 +0000 | [diff] [blame] | 1780 | num_frames_with_source); |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 1781 | strm.IndentLess(); |
Jim Ingham | 5c4df7a | 2011-07-26 02:39:59 +0000 | [diff] [blame] | 1782 | strm.IndentLess(); |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 1783 | } |
| 1784 | return num_frames_shown; |
| 1785 | } |
| 1786 | |
| 1787 | size_t |
| 1788 | Thread::GetStackFrameStatus (Stream& strm, |
| 1789 | uint32_t first_frame, |
| 1790 | uint32_t num_frames, |
| 1791 | bool show_frame_info, |
Greg Clayton | 53eb7ad | 2012-07-11 20:33:48 +0000 | [diff] [blame] | 1792 | uint32_t num_frames_with_source) |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 1793 | { |
Greg Clayton | 39d0ab3 | 2012-03-29 01:41:38 +0000 | [diff] [blame] | 1794 | return GetStackFrameList()->GetStatus (strm, |
| 1795 | first_frame, |
| 1796 | num_frames, |
| 1797 | show_frame_info, |
Greg Clayton | 53eb7ad | 2012-07-11 20:33:48 +0000 | [diff] [blame] | 1798 | num_frames_with_source); |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 1799 | } |
| 1800 | |
Peter Collingbourne | 5a6fa54 | 2011-06-03 20:40:54 +0000 | [diff] [blame] | 1801 | bool |
| 1802 | Thread::SaveFrameZeroState (RegisterCheckpoint &checkpoint) |
| 1803 | { |
| 1804 | lldb::StackFrameSP frame_sp(GetStackFrameAtIndex (0)); |
| 1805 | if (frame_sp) |
| 1806 | { |
| 1807 | checkpoint.SetStackID(frame_sp->GetStackID()); |
Greg Clayton | 1afa68e | 2013-04-02 20:32:37 +0000 | [diff] [blame] | 1808 | lldb::RegisterContextSP reg_ctx_sp (frame_sp->GetRegisterContext()); |
| 1809 | if (reg_ctx_sp) |
| 1810 | return reg_ctx_sp->ReadAllRegisterValues (checkpoint.GetData()); |
Peter Collingbourne | 5a6fa54 | 2011-06-03 20:40:54 +0000 | [diff] [blame] | 1811 | } |
| 1812 | return false; |
| 1813 | } |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 1814 | |
Peter Collingbourne | 5a6fa54 | 2011-06-03 20:40:54 +0000 | [diff] [blame] | 1815 | bool |
| 1816 | Thread::RestoreSaveFrameZero (const RegisterCheckpoint &checkpoint) |
| 1817 | { |
Jim Ingham | 4413758 | 2012-09-12 00:40:39 +0000 | [diff] [blame] | 1818 | return ResetFrameZeroRegisters (checkpoint.GetData()); |
| 1819 | } |
| 1820 | |
| 1821 | bool |
| 1822 | Thread::ResetFrameZeroRegisters (lldb::DataBufferSP register_data_sp) |
| 1823 | { |
Peter Collingbourne | 5a6fa54 | 2011-06-03 20:40:54 +0000 | [diff] [blame] | 1824 | lldb::StackFrameSP frame_sp(GetStackFrameAtIndex (0)); |
| 1825 | if (frame_sp) |
| 1826 | { |
Greg Clayton | 1afa68e | 2013-04-02 20:32:37 +0000 | [diff] [blame] | 1827 | lldb::RegisterContextSP reg_ctx_sp (frame_sp->GetRegisterContext()); |
| 1828 | if (reg_ctx_sp) |
| 1829 | { |
| 1830 | bool ret = reg_ctx_sp->WriteAllRegisterValues (register_data_sp); |
Peter Collingbourne | 5a6fa54 | 2011-06-03 20:40:54 +0000 | [diff] [blame] | 1831 | |
Greg Clayton | 1afa68e | 2013-04-02 20:32:37 +0000 | [diff] [blame] | 1832 | // Clear out all stack frames as our world just changed. |
| 1833 | ClearStackFrames(); |
| 1834 | reg_ctx_sp->InvalidateIfNeeded(true); |
| 1835 | if (m_unwinder_ap.get()) |
| 1836 | m_unwinder_ap->Clear(); |
| 1837 | return ret; |
| 1838 | } |
Peter Collingbourne | 5a6fa54 | 2011-06-03 20:40:54 +0000 | [diff] [blame] | 1839 | } |
| 1840 | return false; |
| 1841 | } |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 1842 | |
Greg Clayton | 56d9a1b | 2011-08-22 02:49:39 +0000 | [diff] [blame] | 1843 | Unwind * |
| 1844 | Thread::GetUnwinder () |
| 1845 | { |
| 1846 | if (m_unwinder_ap.get() == NULL) |
| 1847 | { |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 1848 | const ArchSpec target_arch (CalculateTarget()->GetArchitecture ()); |
Greg Clayton | 56d9a1b | 2011-08-22 02:49:39 +0000 | [diff] [blame] | 1849 | const llvm::Triple::ArchType machine = target_arch.GetMachine(); |
| 1850 | switch (machine) |
| 1851 | { |
| 1852 | case llvm::Triple::x86_64: |
| 1853 | case llvm::Triple::x86: |
| 1854 | case llvm::Triple::arm: |
| 1855 | case llvm::Triple::thumb: |
| 1856 | m_unwinder_ap.reset (new UnwindLLDB (*this)); |
| 1857 | break; |
| 1858 | |
| 1859 | default: |
| 1860 | if (target_arch.GetTriple().getVendor() == llvm::Triple::Apple) |
| 1861 | m_unwinder_ap.reset (new UnwindMacOSXFrameBackchain (*this)); |
| 1862 | break; |
| 1863 | } |
| 1864 | } |
| 1865 | return m_unwinder_ap.get(); |
| 1866 | } |
| 1867 | |
| 1868 | |
Greg Clayton | fa559e5 | 2012-05-18 02:38:05 +0000 | [diff] [blame] | 1869 | void |
| 1870 | Thread::Flush () |
| 1871 | { |
| 1872 | ClearStackFrames (); |
| 1873 | m_reg_context_sp.reset(); |
| 1874 | } |
Jim Ingham | 5d88a06 | 2012-10-16 00:09:33 +0000 | [diff] [blame] | 1875 | |
Filipe Cabecinhas | b3d5d71 | 2012-11-20 00:11:13 +0000 | [diff] [blame] | 1876 | bool |
Jim Ingham | 5d88a06 | 2012-10-16 00:09:33 +0000 | [diff] [blame] | 1877 | Thread::IsStillAtLastBreakpointHit () |
| 1878 | { |
| 1879 | // If we are currently stopped at a breakpoint, always return that stopinfo and don't reset it. |
| 1880 | // This allows threads to maintain their breakpoint stopinfo, such as when thread-stepping in |
| 1881 | // multithreaded programs. |
| 1882 | if (m_actual_stop_info_sp) { |
| 1883 | StopReason stop_reason = m_actual_stop_info_sp->GetStopReason(); |
| 1884 | if (stop_reason == lldb::eStopReasonBreakpoint) { |
| 1885 | uint64_t value = m_actual_stop_info_sp->GetValue(); |
Greg Clayton | 1afa68e | 2013-04-02 20:32:37 +0000 | [diff] [blame] | 1886 | lldb::RegisterContextSP reg_ctx_sp (GetRegisterContext()); |
| 1887 | if (reg_ctx_sp) |
| 1888 | { |
| 1889 | lldb::addr_t pc = reg_ctx_sp->GetPC(); |
| 1890 | BreakpointSiteSP bp_site_sp = GetProcess()->GetBreakpointSiteList().FindByAddress(pc); |
| 1891 | if (bp_site_sp && value == bp_site_sp->GetID()) |
| 1892 | return true; |
| 1893 | } |
Jim Ingham | 5d88a06 | 2012-10-16 00:09:33 +0000 | [diff] [blame] | 1894 | } |
| 1895 | } |
| 1896 | return false; |
| 1897 | } |