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