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