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 | 4da6206 | 2014-01-23 21:52:47 +0000 | [diff] [blame] | 21 | #include "lldb/Interpreter/OptionValueFileSpecList.h" |
Jim Ingham | 1f51e60 | 2012-09-27 01:15:29 +0000 | [diff] [blame] | 22 | #include "lldb/Symbol/Function.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 23 | #include "lldb/Target/DynamicLoader.h" |
| 24 | #include "lldb/Target/ExecutionContext.h" |
Jim Ingham | 5a36912 | 2010-09-28 01:25:32 +0000 | [diff] [blame] | 25 | #include "lldb/Target/ObjCLanguageRuntime.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 26 | #include "lldb/Target/Process.h" |
| 27 | #include "lldb/Target/RegisterContext.h" |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 28 | #include "lldb/Target/StopInfo.h" |
Jason Molenda | b4892cd | 2014-05-13 22:02:48 +0000 | [diff] [blame] | 29 | #include "lldb/Target/SystemRuntime.h" |
Greg Clayton | 896dff6 | 2010-07-23 16:45:51 +0000 | [diff] [blame] | 30 | #include "lldb/Target/Target.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 31 | #include "lldb/Target/Thread.h" |
| 32 | #include "lldb/Target/ThreadPlan.h" |
| 33 | #include "lldb/Target/ThreadPlanCallFunction.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 34 | #include "lldb/Target/ThreadPlanBase.h" |
Jim Ingham | 2bdbfd5 | 2014-09-29 23:17:18 +0000 | [diff] [blame] | 35 | #include "lldb/Target/ThreadPlanPython.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 36 | #include "lldb/Target/ThreadPlanStepInstruction.h" |
| 37 | #include "lldb/Target/ThreadPlanStepOut.h" |
| 38 | #include "lldb/Target/ThreadPlanStepOverBreakpoint.h" |
| 39 | #include "lldb/Target/ThreadPlanStepThrough.h" |
| 40 | #include "lldb/Target/ThreadPlanStepInRange.h" |
| 41 | #include "lldb/Target/ThreadPlanStepOverRange.h" |
| 42 | #include "lldb/Target/ThreadPlanRunToAddress.h" |
| 43 | #include "lldb/Target/ThreadPlanStepUntil.h" |
Jim Ingham | 1b54c88 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 44 | #include "lldb/Target/ThreadSpec.h" |
Jim Ingham | 87c1191 | 2010-08-12 02:14:28 +0000 | [diff] [blame] | 45 | #include "lldb/Target/Unwind.h" |
Greg Clayton | 56d9a1b | 2011-08-22 02:49:39 +0000 | [diff] [blame] | 46 | #include "Plugins/Process/Utility/UnwindLLDB.h" |
Todd Fiala | cacde7d | 2014-09-27 16:54:22 +0000 | [diff] [blame] | 47 | #include "Plugins/Process/Utility/UnwindMacOSXFrameBackchain.h" |
Greg Clayton | 56d9a1b | 2011-08-22 02:49:39 +0000 | [diff] [blame] | 48 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 49 | |
| 50 | using namespace lldb; |
| 51 | using namespace lldb_private; |
| 52 | |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 53 | |
| 54 | const ThreadPropertiesSP & |
| 55 | Thread::GetGlobalProperties() |
| 56 | { |
| 57 | static ThreadPropertiesSP g_settings_sp; |
| 58 | if (!g_settings_sp) |
| 59 | g_settings_sp.reset (new ThreadProperties (true)); |
| 60 | return g_settings_sp; |
| 61 | } |
| 62 | |
| 63 | static PropertyDefinition |
| 64 | g_properties[] = |
| 65 | { |
Jim Ingham | 4b4b247 | 2014-03-13 02:47:14 +0000 | [diff] [blame] | 66 | { "step-in-avoid-nodebug", OptionValue::eTypeBoolean, true, true, NULL, NULL, "If true, step-in will not stop in functions with no debug information." }, |
| 67 | { "step-out-avoid-nodebug", OptionValue::eTypeBoolean, true, false, NULL, NULL, "If true, when step-in/step-out/step-over leave the current frame, they will continue to step out till they come to a function with " |
| 68 | "debug information. Passing a frame argument to step-out will override this option." }, |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 69 | { "step-avoid-regexp", OptionValue::eTypeRegex , true , REG_EXTENDED, "^std::", NULL, "A regular expression defining functions step-in won't stop in." }, |
Jim Ingham | 4da6206 | 2014-01-23 21:52:47 +0000 | [diff] [blame] | 70 | { "step-avoid-libraries", OptionValue::eTypeFileSpecList , true , REG_EXTENDED, NULL, NULL, "A list of libraries that source stepping won't stop in." }, |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 71 | { "trace-thread", OptionValue::eTypeBoolean, false, false, NULL, NULL, "If true, this thread will single-step and log execution." }, |
| 72 | { NULL , OptionValue::eTypeInvalid, false, 0 , NULL, NULL, NULL } |
| 73 | }; |
| 74 | |
| 75 | enum { |
Jim Ingham | 4b4b247 | 2014-03-13 02:47:14 +0000 | [diff] [blame] | 76 | ePropertyStepInAvoidsNoDebug, |
| 77 | ePropertyStepOutAvoidsNoDebug, |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 78 | ePropertyStepAvoidRegex, |
Jim Ingham | 4da6206 | 2014-01-23 21:52:47 +0000 | [diff] [blame] | 79 | ePropertyStepAvoidLibraries, |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 80 | ePropertyEnableThreadTrace |
| 81 | }; |
| 82 | |
| 83 | |
| 84 | class ThreadOptionValueProperties : public OptionValueProperties |
| 85 | { |
| 86 | public: |
| 87 | ThreadOptionValueProperties (const ConstString &name) : |
| 88 | OptionValueProperties (name) |
| 89 | { |
| 90 | } |
| 91 | |
| 92 | // This constructor is used when creating ThreadOptionValueProperties when it |
| 93 | // is part of a new lldb_private::Thread instance. It will copy all current |
| 94 | // global property values as needed |
| 95 | ThreadOptionValueProperties (ThreadProperties *global_properties) : |
Greg Clayton | 6920b52 | 2012-08-22 18:39:03 +0000 | [diff] [blame] | 96 | OptionValueProperties(*global_properties->GetValueProperties()) |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 97 | { |
| 98 | } |
| 99 | |
| 100 | virtual const Property * |
| 101 | GetPropertyAtIndex (const ExecutionContext *exe_ctx, bool will_modify, uint32_t idx) const |
| 102 | { |
Bruce Mitchener | d93c4a3 | 2014-07-01 21:22:11 +0000 | [diff] [blame] | 103 | // When getting the value for a key from the thread options, we will always |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 104 | // try and grab the setting from the current thread if there is one. Else we just |
| 105 | // use the one from this instance. |
| 106 | if (exe_ctx) |
| 107 | { |
| 108 | Thread *thread = exe_ctx->GetThreadPtr(); |
| 109 | if (thread) |
| 110 | { |
| 111 | ThreadOptionValueProperties *instance_properties = static_cast<ThreadOptionValueProperties *>(thread->GetValueProperties().get()); |
| 112 | if (this != instance_properties) |
| 113 | return instance_properties->ProtectedGetPropertyAtIndex (idx); |
| 114 | } |
| 115 | } |
| 116 | return ProtectedGetPropertyAtIndex (idx); |
| 117 | } |
| 118 | }; |
| 119 | |
| 120 | |
| 121 | |
| 122 | ThreadProperties::ThreadProperties (bool is_global) : |
| 123 | Properties () |
| 124 | { |
| 125 | if (is_global) |
| 126 | { |
| 127 | m_collection_sp.reset (new ThreadOptionValueProperties(ConstString("thread"))); |
| 128 | m_collection_sp->Initialize(g_properties); |
| 129 | } |
| 130 | else |
| 131 | m_collection_sp.reset (new ThreadOptionValueProperties(Thread::GetGlobalProperties().get())); |
| 132 | } |
| 133 | |
| 134 | ThreadProperties::~ThreadProperties() |
| 135 | { |
| 136 | } |
| 137 | |
| 138 | const RegularExpression * |
| 139 | ThreadProperties::GetSymbolsToAvoidRegexp() |
| 140 | { |
| 141 | const uint32_t idx = ePropertyStepAvoidRegex; |
| 142 | return m_collection_sp->GetPropertyAtIndexAsOptionValueRegex (NULL, idx); |
| 143 | } |
| 144 | |
Jim Ingham | 4da6206 | 2014-01-23 21:52:47 +0000 | [diff] [blame] | 145 | FileSpecList & |
| 146 | ThreadProperties::GetLibrariesToAvoid() const |
| 147 | { |
| 148 | const uint32_t idx = ePropertyStepAvoidLibraries; |
| 149 | OptionValueFileSpecList *option_value = m_collection_sp->GetPropertyAtIndexAsOptionValueFileSpecList (NULL, false, idx); |
| 150 | assert(option_value); |
| 151 | return option_value->GetCurrentValue(); |
| 152 | } |
| 153 | |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 154 | bool |
| 155 | ThreadProperties::GetTraceEnabledState() const |
| 156 | { |
| 157 | const uint32_t idx = ePropertyEnableThreadTrace; |
| 158 | return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0); |
| 159 | } |
| 160 | |
Jim Ingham | 4b4b247 | 2014-03-13 02:47:14 +0000 | [diff] [blame] | 161 | bool |
| 162 | ThreadProperties::GetStepInAvoidsNoDebug() const |
| 163 | { |
| 164 | const uint32_t idx = ePropertyStepInAvoidsNoDebug; |
| 165 | return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0); |
| 166 | } |
| 167 | |
| 168 | bool |
| 169 | ThreadProperties::GetStepOutAvoidsNoDebug() const |
| 170 | { |
| 171 | const uint32_t idx = ePropertyStepOutAvoidsNoDebug; |
| 172 | return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0); |
| 173 | } |
| 174 | |
| 175 | |
Jim Ingham | 4f465cf | 2012-10-10 18:32:14 +0000 | [diff] [blame] | 176 | //------------------------------------------------------------------ |
| 177 | // Thread Event Data |
| 178 | //------------------------------------------------------------------ |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 179 | |
Jim Ingham | 4f465cf | 2012-10-10 18:32:14 +0000 | [diff] [blame] | 180 | |
| 181 | const ConstString & |
| 182 | Thread::ThreadEventData::GetFlavorString () |
| 183 | { |
| 184 | static ConstString g_flavor ("Thread::ThreadEventData"); |
| 185 | return g_flavor; |
| 186 | } |
| 187 | |
| 188 | Thread::ThreadEventData::ThreadEventData (const lldb::ThreadSP thread_sp) : |
| 189 | m_thread_sp (thread_sp), |
| 190 | m_stack_id () |
| 191 | { |
| 192 | } |
| 193 | |
| 194 | Thread::ThreadEventData::ThreadEventData (const lldb::ThreadSP thread_sp, const StackID &stack_id) : |
| 195 | m_thread_sp (thread_sp), |
| 196 | m_stack_id (stack_id) |
| 197 | { |
| 198 | } |
| 199 | |
| 200 | Thread::ThreadEventData::ThreadEventData () : |
| 201 | m_thread_sp (), |
| 202 | m_stack_id () |
| 203 | { |
| 204 | } |
| 205 | |
| 206 | Thread::ThreadEventData::~ThreadEventData () |
| 207 | { |
| 208 | } |
| 209 | |
| 210 | void |
| 211 | Thread::ThreadEventData::Dump (Stream *s) const |
| 212 | { |
| 213 | |
| 214 | } |
| 215 | |
| 216 | const Thread::ThreadEventData * |
| 217 | Thread::ThreadEventData::GetEventDataFromEvent (const Event *event_ptr) |
| 218 | { |
| 219 | if (event_ptr) |
| 220 | { |
| 221 | const EventData *event_data = event_ptr->GetData(); |
| 222 | if (event_data && event_data->GetFlavor() == ThreadEventData::GetFlavorString()) |
| 223 | return static_cast <const ThreadEventData *> (event_ptr->GetData()); |
| 224 | } |
| 225 | return NULL; |
| 226 | } |
| 227 | |
| 228 | ThreadSP |
| 229 | Thread::ThreadEventData::GetThreadFromEvent (const Event *event_ptr) |
| 230 | { |
| 231 | ThreadSP thread_sp; |
| 232 | const ThreadEventData *event_data = GetEventDataFromEvent (event_ptr); |
| 233 | if (event_data) |
| 234 | thread_sp = event_data->GetThread(); |
| 235 | return thread_sp; |
| 236 | } |
| 237 | |
| 238 | StackID |
| 239 | Thread::ThreadEventData::GetStackIDFromEvent (const Event *event_ptr) |
| 240 | { |
| 241 | StackID stack_id; |
| 242 | const ThreadEventData *event_data = GetEventDataFromEvent (event_ptr); |
| 243 | if (event_data) |
| 244 | stack_id = event_data->GetStackID(); |
| 245 | return stack_id; |
| 246 | } |
| 247 | |
Jason Molenda | b57e4a1 | 2013-11-04 09:33:30 +0000 | [diff] [blame] | 248 | StackFrameSP |
Jim Ingham | 4f465cf | 2012-10-10 18:32:14 +0000 | [diff] [blame] | 249 | Thread::ThreadEventData::GetStackFrameFromEvent (const Event *event_ptr) |
| 250 | { |
| 251 | const ThreadEventData *event_data = GetEventDataFromEvent (event_ptr); |
Jason Molenda | b57e4a1 | 2013-11-04 09:33:30 +0000 | [diff] [blame] | 252 | StackFrameSP frame_sp; |
Jim Ingham | 4f465cf | 2012-10-10 18:32:14 +0000 | [diff] [blame] | 253 | if (event_data) |
| 254 | { |
| 255 | ThreadSP thread_sp = event_data->GetThread(); |
| 256 | if (thread_sp) |
| 257 | { |
| 258 | frame_sp = thread_sp->GetStackFrameList()->GetFrameWithStackID (event_data->GetStackID()); |
| 259 | } |
| 260 | } |
| 261 | return frame_sp; |
| 262 | } |
| 263 | |
| 264 | //------------------------------------------------------------------ |
| 265 | // Thread class |
| 266 | //------------------------------------------------------------------ |
| 267 | |
| 268 | ConstString & |
| 269 | Thread::GetStaticBroadcasterClass () |
| 270 | { |
| 271 | static ConstString class_name ("lldb.thread"); |
| 272 | return class_name; |
| 273 | } |
| 274 | |
Jason Molenda | a8ff543 | 2014-03-06 06:31:18 +0000 | [diff] [blame] | 275 | Thread::Thread (Process &process, lldb::tid_t tid, bool use_invalid_index_id) : |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 276 | ThreadProperties (false), |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 277 | UserID (tid), |
Jim Ingham | 4f465cf | 2012-10-10 18:32:14 +0000 | [diff] [blame] | 278 | Broadcaster(&process.GetTarget().GetDebugger(), Thread::GetStaticBroadcasterClass().AsCString()), |
| 279 | m_process_wp (process.shared_from_this()), |
Greg Clayton | 6e0ff1a | 2013-05-09 01:55:29 +0000 | [diff] [blame] | 280 | m_stop_info_sp (), |
| 281 | m_stop_info_stop_id (0), |
Jason Molenda | a8ff543 | 2014-03-06 06:31:18 +0000 | [diff] [blame] | 282 | m_index_id (use_invalid_index_id ? LLDB_INVALID_INDEX32 : process.GetNextThreadIndexID(tid)), |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 283 | m_reg_context_sp (), |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 284 | m_state (eStateUnloaded), |
Greg Clayton | 12daf946 | 2010-08-25 00:35:26 +0000 | [diff] [blame] | 285 | m_state_mutex (Mutex::eMutexTypeRecursive), |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 286 | m_plan_stack (), |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 287 | m_completed_plan_stack(), |
Greg Clayton | 39d0ab3 | 2012-03-29 01:41:38 +0000 | [diff] [blame] | 288 | m_frame_mutex (Mutex::eMutexTypeRecursive), |
Greg Clayton | 7e9b1fd | 2011-08-12 21:40:01 +0000 | [diff] [blame] | 289 | m_curr_frames_sp (), |
| 290 | m_prev_frames_sp (), |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 291 | m_resume_signal (LLDB_INVALID_SIGNAL_NUMBER), |
Jim Ingham | 87c1191 | 2010-08-12 02:14:28 +0000 | [diff] [blame] | 292 | m_resume_state (eStateRunning), |
Jim Ingham | 92087d8 | 2012-01-31 23:09:20 +0000 | [diff] [blame] | 293 | m_temporary_resume_state (eStateRunning), |
Jim Ingham | 773d981 | 2010-11-18 02:47:07 +0000 | [diff] [blame] | 294 | m_unwinder_ap (), |
Jim Ingham | 7778703 | 2011-01-20 02:03:18 +0000 | [diff] [blame] | 295 | m_destroy_called (false), |
Jason Molenda | 705b180 | 2014-06-13 02:37:02 +0000 | [diff] [blame] | 296 | m_override_should_notify (eLazyBoolCalculate), |
| 297 | m_extended_info_fetched (false), |
| 298 | m_extended_info () |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 299 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 300 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 301 | if (log) |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 302 | log->Printf ("%p Thread::Thread(tid = 0x%4.4" PRIx64 ")", |
| 303 | static_cast<void*>(this), GetID()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 304 | |
Jim Ingham | 4f465cf | 2012-10-10 18:32:14 +0000 | [diff] [blame] | 305 | CheckInWithManager(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 306 | QueueFundamentalPlan(true); |
| 307 | } |
| 308 | |
| 309 | |
| 310 | Thread::~Thread() |
| 311 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 312 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 313 | if (log) |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 314 | log->Printf ("%p Thread::~Thread(tid = 0x%4.4" PRIx64 ")", |
| 315 | static_cast<void*>(this), GetID()); |
Jim Ingham | 773d981 | 2010-11-18 02:47:07 +0000 | [diff] [blame] | 316 | /// If you hit this assert, it means your derived class forgot to call DoDestroy in its destructor. |
| 317 | assert (m_destroy_called); |
| 318 | } |
| 319 | |
| 320 | void |
| 321 | Thread::DestroyThread () |
| 322 | { |
Jim Ingham | b149924 | 2013-10-18 17:11:02 +0000 | [diff] [blame] | 323 | // Tell any plans on the plan stacks that the thread is being destroyed since |
| 324 | // any plans that have a thread go away in the middle of might need |
| 325 | // to do cleanup, or in some cases NOT do cleanup... |
Greg Clayton | 6e0ff1a | 2013-05-09 01:55:29 +0000 | [diff] [blame] | 326 | for (auto plan : m_plan_stack) |
| 327 | plan->ThreadDestroyed(); |
| 328 | |
Jim Ingham | b149924 | 2013-10-18 17:11:02 +0000 | [diff] [blame] | 329 | for (auto plan : m_discarded_plan_stack) |
| 330 | plan->ThreadDestroyed(); |
| 331 | |
| 332 | for (auto plan : m_completed_plan_stack) |
| 333 | plan->ThreadDestroyed(); |
| 334 | |
Greg Clayton | 35a4cc5 | 2012-10-29 20:52:08 +0000 | [diff] [blame] | 335 | m_destroy_called = true; |
Jim Ingham | 773d981 | 2010-11-18 02:47:07 +0000 | [diff] [blame] | 336 | m_plan_stack.clear(); |
| 337 | m_discarded_plan_stack.clear(); |
| 338 | m_completed_plan_stack.clear(); |
Greg Clayton | 6e10f14 | 2013-07-30 00:23:06 +0000 | [diff] [blame] | 339 | |
| 340 | // Push a ThreadPlanNull on the plan stack. That way we can continue assuming that the |
| 341 | // plan stack is never empty, but if somebody errantly asks questions of a destroyed thread |
| 342 | // without checking first whether it is destroyed, they won't crash. |
| 343 | ThreadPlanSP null_plan_sp(new ThreadPlanNull (*this)); |
| 344 | m_plan_stack.push_back (null_plan_sp); |
| 345 | |
Greg Clayton | 6e0ff1a | 2013-05-09 01:55:29 +0000 | [diff] [blame] | 346 | m_stop_info_sp.reset(); |
Greg Clayton | 35a4cc5 | 2012-10-29 20:52:08 +0000 | [diff] [blame] | 347 | m_reg_context_sp.reset(); |
| 348 | m_unwinder_ap.reset(); |
| 349 | Mutex::Locker locker(m_frame_mutex); |
| 350 | m_curr_frames_sp.reset(); |
| 351 | m_prev_frames_sp.reset(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 352 | } |
| 353 | |
Jim Ingham | 4f465cf | 2012-10-10 18:32:14 +0000 | [diff] [blame] | 354 | void |
| 355 | Thread::BroadcastSelectedFrameChange(StackID &new_frame_id) |
| 356 | { |
| 357 | if (EventTypeHasListeners(eBroadcastBitSelectedFrameChanged)) |
| 358 | BroadcastEvent(eBroadcastBitSelectedFrameChanged, new ThreadEventData (this->shared_from_this(), new_frame_id)); |
| 359 | } |
| 360 | |
| 361 | uint32_t |
Jason Molenda | b57e4a1 | 2013-11-04 09:33:30 +0000 | [diff] [blame] | 362 | Thread::SetSelectedFrame (lldb_private::StackFrame *frame, bool broadcast) |
Jim Ingham | 4f465cf | 2012-10-10 18:32:14 +0000 | [diff] [blame] | 363 | { |
| 364 | uint32_t ret_value = GetStackFrameList()->SetSelectedFrame(frame); |
| 365 | if (broadcast) |
| 366 | BroadcastSelectedFrameChange(frame->GetStackID()); |
| 367 | return ret_value; |
| 368 | } |
| 369 | |
| 370 | bool |
| 371 | Thread::SetSelectedFrameByIndex (uint32_t frame_idx, bool broadcast) |
| 372 | { |
Jason Molenda | b57e4a1 | 2013-11-04 09:33:30 +0000 | [diff] [blame] | 373 | StackFrameSP frame_sp(GetStackFrameList()->GetFrameAtIndex (frame_idx)); |
Jim Ingham | 4f465cf | 2012-10-10 18:32:14 +0000 | [diff] [blame] | 374 | if (frame_sp) |
| 375 | { |
| 376 | GetStackFrameList()->SetSelectedFrame(frame_sp.get()); |
| 377 | if (broadcast) |
| 378 | BroadcastSelectedFrameChange(frame_sp->GetStackID()); |
| 379 | return true; |
| 380 | } |
| 381 | else |
| 382 | return false; |
| 383 | } |
| 384 | |
Jim Ingham | 93208b8 | 2013-01-31 21:46:01 +0000 | [diff] [blame] | 385 | bool |
| 386 | Thread::SetSelectedFrameByIndexNoisily (uint32_t frame_idx, Stream &output_stream) |
| 387 | { |
| 388 | const bool broadcast = true; |
| 389 | bool success = SetSelectedFrameByIndex (frame_idx, broadcast); |
| 390 | if (success) |
| 391 | { |
Jason Molenda | b57e4a1 | 2013-11-04 09:33:30 +0000 | [diff] [blame] | 392 | StackFrameSP frame_sp = GetSelectedFrame(); |
Jim Ingham | 93208b8 | 2013-01-31 21:46:01 +0000 | [diff] [blame] | 393 | if (frame_sp) |
| 394 | { |
| 395 | bool already_shown = false; |
| 396 | SymbolContext frame_sc(frame_sp->GetSymbolContext(eSymbolContextLineEntry)); |
| 397 | if (GetProcess()->GetTarget().GetDebugger().GetUseExternalEditor() && frame_sc.line_entry.file && frame_sc.line_entry.line != 0) |
| 398 | { |
| 399 | already_shown = Host::OpenFileInExternalEditor (frame_sc.line_entry.file, frame_sc.line_entry.line); |
| 400 | } |
| 401 | |
| 402 | bool show_frame_info = true; |
| 403 | bool show_source = !already_shown; |
| 404 | return frame_sp->GetStatus (output_stream, show_frame_info, show_source); |
| 405 | } |
| 406 | return false; |
| 407 | } |
| 408 | else |
| 409 | return false; |
| 410 | } |
| 411 | |
Jim Ingham | 4f465cf | 2012-10-10 18:32:14 +0000 | [diff] [blame] | 412 | |
Jim Ingham | b15bfc7 | 2010-10-20 00:39:53 +0000 | [diff] [blame] | 413 | lldb::StopInfoSP |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 414 | Thread::GetStopInfo () |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 415 | { |
Greg Clayton | 6e10f14 | 2013-07-30 00:23:06 +0000 | [diff] [blame] | 416 | if (m_destroy_called) |
| 417 | return m_stop_info_sp; |
| 418 | |
Jim Ingham | b15bfc7 | 2010-10-20 00:39:53 +0000 | [diff] [blame] | 419 | ThreadPlanSP plan_sp (GetCompletedPlan()); |
Andrew Kaylor | ba4e61d | 2013-05-07 18:35:34 +0000 | [diff] [blame] | 420 | ProcessSP process_sp (GetProcess()); |
| 421 | const uint32_t stop_id = process_sp ? process_sp->GetStopID() : UINT32_MAX; |
Jim Ingham | fbbfe6e | 2012-05-01 18:38:37 +0000 | [diff] [blame] | 422 | if (plan_sp && plan_sp->PlanSucceeded()) |
Andrew Kaylor | ba4e61d | 2013-05-07 18:35:34 +0000 | [diff] [blame] | 423 | { |
Jim Ingham | 30fadaf | 2014-07-08 01:07:32 +0000 | [diff] [blame] | 424 | return StopInfo::CreateStopReasonWithPlan (plan_sp, GetReturnValueObject(), GetExpressionVariable()); |
Andrew Kaylor | ba4e61d | 2013-05-07 18:35:34 +0000 | [diff] [blame] | 425 | } |
Jim Ingham | b15bfc7 | 2010-10-20 00:39:53 +0000 | [diff] [blame] | 426 | else |
Jim Ingham | 79c35da | 2011-08-09 00:32:52 +0000 | [diff] [blame] | 427 | { |
Greg Clayton | 6e0ff1a | 2013-05-09 01:55:29 +0000 | [diff] [blame] | 428 | if ((m_stop_info_stop_id == stop_id) || // Stop info is valid, just return what we have (even if empty) |
| 429 | (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] | 430 | { |
Greg Clayton | 6e0ff1a | 2013-05-09 01:55:29 +0000 | [diff] [blame] | 431 | return m_stop_info_sp; |
Andrew Kaylor | ba4e61d | 2013-05-07 18:35:34 +0000 | [diff] [blame] | 432 | } |
Jim Ingham | 79c35da | 2011-08-09 00:32:52 +0000 | [diff] [blame] | 433 | else |
Andrew Kaylor | ba4e61d | 2013-05-07 18:35:34 +0000 | [diff] [blame] | 434 | { |
Greg Clayton | 6e0ff1a | 2013-05-09 01:55:29 +0000 | [diff] [blame] | 435 | GetPrivateStopInfo (); |
| 436 | return m_stop_info_sp; |
Andrew Kaylor | ba4e61d | 2013-05-07 18:35:34 +0000 | [diff] [blame] | 437 | } |
Jim Ingham | 79c35da | 2011-08-09 00:32:52 +0000 | [diff] [blame] | 438 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 439 | } |
| 440 | |
Greg Clayton | 6e0ff1a | 2013-05-09 01:55:29 +0000 | [diff] [blame] | 441 | lldb::StopInfoSP |
| 442 | Thread::GetPrivateStopInfo () |
| 443 | { |
Greg Clayton | 6e10f14 | 2013-07-30 00:23:06 +0000 | [diff] [blame] | 444 | if (m_destroy_called) |
| 445 | return m_stop_info_sp; |
| 446 | |
Greg Clayton | 6e0ff1a | 2013-05-09 01:55:29 +0000 | [diff] [blame] | 447 | ProcessSP process_sp (GetProcess()); |
| 448 | if (process_sp) |
| 449 | { |
Daniel Malea | 246cb61 | 2013-05-14 15:20:12 +0000 | [diff] [blame] | 450 | const uint32_t process_stop_id = process_sp->GetStopID(); |
| 451 | if (m_stop_info_stop_id != process_stop_id) |
Greg Clayton | 6e0ff1a | 2013-05-09 01:55:29 +0000 | [diff] [blame] | 452 | { |
Daniel Malea | 246cb61 | 2013-05-14 15:20:12 +0000 | [diff] [blame] | 453 | if (m_stop_info_sp) |
Greg Clayton | 6e0ff1a | 2013-05-09 01:55:29 +0000 | [diff] [blame] | 454 | { |
Daniel Malea | 246cb61 | 2013-05-14 15:20:12 +0000 | [diff] [blame] | 455 | if (m_stop_info_sp->IsValid() |
| 456 | || IsStillAtLastBreakpointHit() |
| 457 | || GetCurrentPlan()->IsVirtualStep()) |
| 458 | SetStopInfo (m_stop_info_sp); |
| 459 | else |
| 460 | m_stop_info_sp.reset(); |
| 461 | } |
| 462 | |
| 463 | if (!m_stop_info_sp) |
| 464 | { |
| 465 | if (CalculateStopInfo() == false) |
| 466 | SetStopInfo (StopInfoSP()); |
Greg Clayton | 6e0ff1a | 2013-05-09 01:55:29 +0000 | [diff] [blame] | 467 | } |
| 468 | } |
| 469 | } |
| 470 | return m_stop_info_sp; |
| 471 | } |
| 472 | |
| 473 | |
Greg Clayton | 97d5cf0 | 2012-09-25 02:40:06 +0000 | [diff] [blame] | 474 | lldb::StopReason |
| 475 | Thread::GetStopReason() |
| 476 | { |
| 477 | lldb::StopInfoSP stop_info_sp (GetStopInfo ()); |
| 478 | if (stop_info_sp) |
Filipe Cabecinhas | e26391a | 2012-09-28 15:55:43 +0000 | [diff] [blame] | 479 | return stop_info_sp->GetStopReason(); |
Greg Clayton | 97d5cf0 | 2012-09-25 02:40:06 +0000 | [diff] [blame] | 480 | return eStopReasonNone; |
| 481 | } |
| 482 | |
| 483 | |
| 484 | |
Jim Ingham | 7778703 | 2011-01-20 02:03:18 +0000 | [diff] [blame] | 485 | void |
| 486 | Thread::SetStopInfo (const lldb::StopInfoSP &stop_info_sp) |
| 487 | { |
Greg Clayton | 6e0ff1a | 2013-05-09 01:55:29 +0000 | [diff] [blame] | 488 | m_stop_info_sp = stop_info_sp; |
| 489 | if (m_stop_info_sp) |
Jim Ingham | 221d51c | 2013-05-08 00:35:16 +0000 | [diff] [blame] | 490 | { |
Greg Clayton | 6e0ff1a | 2013-05-09 01:55:29 +0000 | [diff] [blame] | 491 | m_stop_info_sp->MakeStopInfoValid(); |
Jim Ingham | 221d51c | 2013-05-08 00:35:16 +0000 | [diff] [blame] | 492 | // If we are overriding the ShouldReportStop, do that here: |
| 493 | if (m_override_should_notify != eLazyBoolCalculate) |
Greg Clayton | 6e0ff1a | 2013-05-09 01:55:29 +0000 | [diff] [blame] | 494 | m_stop_info_sp->OverrideShouldNotify (m_override_should_notify == eLazyBoolYes); |
Jim Ingham | 221d51c | 2013-05-08 00:35:16 +0000 | [diff] [blame] | 495 | } |
| 496 | |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 497 | ProcessSP process_sp (GetProcess()); |
| 498 | if (process_sp) |
Greg Clayton | 6e0ff1a | 2013-05-09 01:55:29 +0000 | [diff] [blame] | 499 | m_stop_info_stop_id = process_sp->GetStopID(); |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 500 | else |
Greg Clayton | 6e0ff1a | 2013-05-09 01:55:29 +0000 | [diff] [blame] | 501 | m_stop_info_stop_id = UINT32_MAX; |
Greg Clayton | 8cda7f0 | 2013-05-21 21:55:59 +0000 | [diff] [blame] | 502 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_THREAD)); |
| 503 | if (log) |
Ed Maste | 2bc7643 | 2014-06-25 00:38:35 +0000 | [diff] [blame] | 504 | log->Printf("%p: tid = 0x%" PRIx64 ": stop info = %s (stop_id = %u)", |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 505 | static_cast<void*>(this), GetID(), |
| 506 | stop_info_sp ? stop_info_sp->GetDescription() : "<NULL>", |
| 507 | m_stop_info_stop_id); |
Jim Ingham | 7778703 | 2011-01-20 02:03:18 +0000 | [diff] [blame] | 508 | } |
| 509 | |
| 510 | void |
Jim Ingham | 221d51c | 2013-05-08 00:35:16 +0000 | [diff] [blame] | 511 | Thread::SetShouldReportStop (Vote vote) |
| 512 | { |
| 513 | if (vote == eVoteNoOpinion) |
| 514 | return; |
| 515 | else |
| 516 | { |
| 517 | m_override_should_notify = (vote == eVoteYes ? eLazyBoolYes : eLazyBoolNo); |
Greg Clayton | 6e0ff1a | 2013-05-09 01:55:29 +0000 | [diff] [blame] | 518 | if (m_stop_info_sp) |
| 519 | m_stop_info_sp->OverrideShouldNotify (m_override_should_notify == eLazyBoolYes); |
Jim Ingham | 221d51c | 2013-05-08 00:35:16 +0000 | [diff] [blame] | 520 | } |
| 521 | } |
| 522 | |
| 523 | void |
Jim Ingham | 7778703 | 2011-01-20 02:03:18 +0000 | [diff] [blame] | 524 | Thread::SetStopInfoToNothing() |
| 525 | { |
| 526 | // Note, we can't just NULL out the private reason, or the native thread implementation will try to |
| 527 | // go calculate it again. For now, just set it to a Unix Signal with an invalid signal number. |
| 528 | SetStopInfo (StopInfo::CreateStopReasonWithSignal (*this, LLDB_INVALID_SIGNAL_NUMBER)); |
| 529 | } |
| 530 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 531 | bool |
| 532 | Thread::ThreadStoppedForAReason (void) |
| 533 | { |
Greg Clayton | 6e0ff1a | 2013-05-09 01:55:29 +0000 | [diff] [blame] | 534 | return (bool) GetPrivateStopInfo (); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 535 | } |
| 536 | |
Jim Ingham | 7778703 | 2011-01-20 02:03:18 +0000 | [diff] [blame] | 537 | bool |
| 538 | Thread::CheckpointThreadState (ThreadStateCheckpoint &saved_state) |
| 539 | { |
Greg Clayton | f74cf86 | 2013-11-13 23:28:31 +0000 | [diff] [blame] | 540 | saved_state.register_backup_sp.reset(); |
| 541 | lldb::StackFrameSP frame_sp(GetStackFrameAtIndex (0)); |
| 542 | if (frame_sp) |
| 543 | { |
| 544 | lldb::RegisterCheckpointSP reg_checkpoint_sp(new RegisterCheckpoint(RegisterCheckpoint::Reason::eExpression)); |
| 545 | if (reg_checkpoint_sp) |
| 546 | { |
| 547 | lldb::RegisterContextSP reg_ctx_sp (frame_sp->GetRegisterContext()); |
| 548 | if (reg_ctx_sp && reg_ctx_sp->ReadAllRegisterValues (*reg_checkpoint_sp)) |
| 549 | saved_state.register_backup_sp = reg_checkpoint_sp; |
| 550 | } |
| 551 | } |
| 552 | if (!saved_state.register_backup_sp) |
Jim Ingham | 7778703 | 2011-01-20 02:03:18 +0000 | [diff] [blame] | 553 | return false; |
| 554 | |
| 555 | saved_state.stop_info_sp = GetStopInfo(); |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 556 | ProcessSP process_sp (GetProcess()); |
| 557 | if (process_sp) |
| 558 | saved_state.orig_stop_id = process_sp->GetStopID(); |
Jim Ingham | 625fca7 | 2012-09-07 23:36:43 +0000 | [diff] [blame] | 559 | saved_state.current_inlined_depth = GetCurrentInlinedDepth(); |
| 560 | |
Jim Ingham | 7778703 | 2011-01-20 02:03:18 +0000 | [diff] [blame] | 561 | return true; |
| 562 | } |
| 563 | |
| 564 | bool |
Jim Ingham | 8559a35 | 2012-11-26 23:52:18 +0000 | [diff] [blame] | 565 | Thread::RestoreRegisterStateFromCheckpoint (ThreadStateCheckpoint &saved_state) |
Jim Ingham | 7778703 | 2011-01-20 02:03:18 +0000 | [diff] [blame] | 566 | { |
Greg Clayton | f74cf86 | 2013-11-13 23:28:31 +0000 | [diff] [blame] | 567 | if (saved_state.register_backup_sp) |
| 568 | { |
| 569 | lldb::StackFrameSP frame_sp(GetStackFrameAtIndex (0)); |
| 570 | if (frame_sp) |
| 571 | { |
| 572 | lldb::RegisterContextSP reg_ctx_sp (frame_sp->GetRegisterContext()); |
| 573 | if (reg_ctx_sp) |
| 574 | { |
| 575 | bool ret = reg_ctx_sp->WriteAllRegisterValues (*saved_state.register_backup_sp); |
| 576 | |
| 577 | // Clear out all stack frames as our world just changed. |
| 578 | ClearStackFrames(); |
| 579 | reg_ctx_sp->InvalidateIfNeeded(true); |
| 580 | if (m_unwinder_ap.get()) |
| 581 | m_unwinder_ap->Clear(); |
| 582 | return ret; |
| 583 | } |
| 584 | } |
| 585 | } |
| 586 | return false; |
Jim Ingham | 8559a35 | 2012-11-26 23:52:18 +0000 | [diff] [blame] | 587 | } |
| 588 | |
| 589 | bool |
| 590 | Thread::RestoreThreadStateFromCheckpoint (ThreadStateCheckpoint &saved_state) |
| 591 | { |
Jim Ingham | 0c27068 | 2011-01-25 02:47:23 +0000 | [diff] [blame] | 592 | if (saved_state.stop_info_sp) |
| 593 | saved_state.stop_info_sp->MakeStopInfoValid(); |
Jim Ingham | 7778703 | 2011-01-20 02:03:18 +0000 | [diff] [blame] | 594 | SetStopInfo(saved_state.stop_info_sp); |
Jim Ingham | 625fca7 | 2012-09-07 23:36:43 +0000 | [diff] [blame] | 595 | GetStackFrameList()->SetCurrentInlinedDepth (saved_state.current_inlined_depth); |
Jim Ingham | 7778703 | 2011-01-20 02:03:18 +0000 | [diff] [blame] | 596 | return true; |
| 597 | } |
| 598 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 599 | StateType |
| 600 | Thread::GetState() const |
| 601 | { |
| 602 | // If any other threads access this we will need a mutex for it |
| 603 | Mutex::Locker locker(m_state_mutex); |
| 604 | return m_state; |
| 605 | } |
| 606 | |
| 607 | void |
| 608 | Thread::SetState(StateType state) |
| 609 | { |
| 610 | Mutex::Locker locker(m_state_mutex); |
| 611 | m_state = state; |
| 612 | } |
| 613 | |
| 614 | void |
| 615 | Thread::WillStop() |
| 616 | { |
| 617 | ThreadPlan *current_plan = GetCurrentPlan(); |
| 618 | |
| 619 | // FIXME: I may decide to disallow threads with no plans. In which |
| 620 | // case this should go to an assert. |
| 621 | |
| 622 | if (!current_plan) |
| 623 | return; |
| 624 | |
| 625 | current_plan->WillStop(); |
| 626 | } |
| 627 | |
| 628 | void |
| 629 | Thread::SetupForResume () |
| 630 | { |
| 631 | if (GetResumeState() != eStateSuspended) |
| 632 | { |
| 633 | |
| 634 | // If we're at a breakpoint push the step-over breakpoint plan. Do this before |
| 635 | // telling the current plan it will resume, since we might change what the current |
| 636 | // plan is. |
| 637 | |
Greg Clayton | 1afa68e | 2013-04-02 20:32:37 +0000 | [diff] [blame] | 638 | // StopReason stop_reason = lldb::eStopReasonInvalid; |
| 639 | // StopInfoSP stop_info_sp = GetStopInfo(); |
| 640 | // if (stop_info_sp.get()) |
| 641 | // stop_reason = stop_info_sp->GetStopReason(); |
| 642 | // if (stop_reason == lldb::eStopReasonBreakpoint) |
| 643 | lldb::RegisterContextSP reg_ctx_sp (GetRegisterContext()); |
| 644 | if (reg_ctx_sp) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 645 | { |
Greg Clayton | 1afa68e | 2013-04-02 20:32:37 +0000 | [diff] [blame] | 646 | BreakpointSiteSP bp_site_sp = GetProcess()->GetBreakpointSiteList().FindByAddress(reg_ctx_sp->GetPC()); |
| 647 | if (bp_site_sp) |
Jim Ingham | b01e742 | 2010-06-19 04:45:32 +0000 | [diff] [blame] | 648 | { |
Greg Clayton | 1afa68e | 2013-04-02 20:32:37 +0000 | [diff] [blame] | 649 | // Note, don't assume there's a ThreadPlanStepOverBreakpoint, the target may not require anything |
| 650 | // special to step over a breakpoint. |
| 651 | |
| 652 | ThreadPlan *cur_plan = GetCurrentPlan(); |
Jim Ingham | b01e742 | 2010-06-19 04:45:32 +0000 | [diff] [blame] | 653 | |
Greg Clayton | 1afa68e | 2013-04-02 20:32:37 +0000 | [diff] [blame] | 654 | if (cur_plan->GetKind() != ThreadPlan::eKindStepOverBreakpoint) |
| 655 | { |
Jim Ingham | 2bdbfd5 | 2014-09-29 23:17:18 +0000 | [diff] [blame] | 656 | ThreadPlanSP step_bp_plan_sp (new ThreadPlanStepOverBreakpoint (*this)); |
| 657 | if (step_bp_plan_sp) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 658 | { |
Jim Ingham | 2bdbfd5 | 2014-09-29 23:17:18 +0000 | [diff] [blame] | 659 | ; |
| 660 | step_bp_plan_sp->SetPrivate (true); |
Greg Clayton | 1afa68e | 2013-04-02 20:32:37 +0000 | [diff] [blame] | 661 | |
| 662 | if (GetCurrentPlan()->RunState() != eStateStepping) |
| 663 | { |
Jim Ingham | 2bdbfd5 | 2014-09-29 23:17:18 +0000 | [diff] [blame] | 664 | ThreadPlanStepOverBreakpoint *step_bp_plan |
| 665 | = static_cast<ThreadPlanStepOverBreakpoint *>(step_bp_plan_sp.get()); |
Greg Clayton | 1afa68e | 2013-04-02 20:32:37 +0000 | [diff] [blame] | 666 | step_bp_plan->SetAutoContinue(true); |
| 667 | } |
Greg Clayton | 1afa68e | 2013-04-02 20:32:37 +0000 | [diff] [blame] | 668 | QueueThreadPlan (step_bp_plan_sp, false); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 669 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 670 | } |
| 671 | } |
| 672 | } |
| 673 | } |
| 674 | } |
| 675 | |
| 676 | bool |
Greg Clayton | 160c9d8 | 2013-05-01 21:54:04 +0000 | [diff] [blame] | 677 | Thread::ShouldResume (StateType resume_state) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 678 | { |
| 679 | // At this point clear the completed plan stack. |
| 680 | m_completed_plan_stack.clear(); |
| 681 | m_discarded_plan_stack.clear(); |
Jim Ingham | 221d51c | 2013-05-08 00:35:16 +0000 | [diff] [blame] | 682 | m_override_should_notify = eLazyBoolCalculate; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 683 | |
Greg Clayton | 97d5cf0 | 2012-09-25 02:40:06 +0000 | [diff] [blame] | 684 | m_temporary_resume_state = resume_state; |
Jim Ingham | 92087d8 | 2012-01-31 23:09:20 +0000 | [diff] [blame] | 685 | |
Greg Clayton | 6e0ff1a | 2013-05-09 01:55:29 +0000 | [diff] [blame] | 686 | lldb::ThreadSP backing_thread_sp (GetBackingThread ()); |
| 687 | if (backing_thread_sp) |
| 688 | backing_thread_sp->m_temporary_resume_state = resume_state; |
| 689 | |
| 690 | // Make sure m_stop_info_sp is valid |
| 691 | GetPrivateStopInfo(); |
Greg Clayton | 160c9d8 | 2013-05-01 21:54:04 +0000 | [diff] [blame] | 692 | |
Jim Ingham | 92087d8 | 2012-01-31 23:09:20 +0000 | [diff] [blame] | 693 | // This is a little dubious, but we are trying to limit how often we actually fetch stop info from |
| 694 | // the target, 'cause that slows down single stepping. So assume that if we got to the point where |
| 695 | // we're about to resume, and we haven't yet had to fetch the stop reason, then it doesn't need to know |
| 696 | // about the fact that we are resuming... |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 697 | const uint32_t process_stop_id = GetProcess()->GetStopID(); |
Greg Clayton | 6e0ff1a | 2013-05-09 01:55:29 +0000 | [diff] [blame] | 698 | if (m_stop_info_stop_id == process_stop_id && |
| 699 | (m_stop_info_sp && m_stop_info_sp->IsValid())) |
Jim Ingham | 92087d8 | 2012-01-31 23:09:20 +0000 | [diff] [blame] | 700 | { |
Greg Clayton | 6e0ff1a | 2013-05-09 01:55:29 +0000 | [diff] [blame] | 701 | StopInfo *stop_info = GetPrivateStopInfo().get(); |
Jim Ingham | 92087d8 | 2012-01-31 23:09:20 +0000 | [diff] [blame] | 702 | if (stop_info) |
| 703 | stop_info->WillResume (resume_state); |
| 704 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 705 | |
| 706 | // Tell all the plans that we are about to resume in case they need to clear any state. |
| 707 | // We distinguish between the plan on the top of the stack and the lower |
| 708 | // plans in case a plan needs to do any special business before it runs. |
| 709 | |
Greg Clayton | d1d06e4 | 2013-04-20 00:27:58 +0000 | [diff] [blame] | 710 | bool need_to_resume = false; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 711 | ThreadPlan *plan_ptr = GetCurrentPlan(); |
Greg Clayton | d1d06e4 | 2013-04-20 00:27:58 +0000 | [diff] [blame] | 712 | if (plan_ptr) |
| 713 | { |
| 714 | need_to_resume = plan_ptr->WillResume(resume_state, true); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 715 | |
Greg Clayton | d1d06e4 | 2013-04-20 00:27:58 +0000 | [diff] [blame] | 716 | while ((plan_ptr = GetPreviousPlan(plan_ptr)) != NULL) |
| 717 | { |
| 718 | plan_ptr->WillResume (resume_state, false); |
| 719 | } |
| 720 | |
| 721 | // If the WillResume for the plan says we are faking a resume, then it will have set an appropriate stop info. |
| 722 | // In that case, don't reset it here. |
| 723 | |
| 724 | if (need_to_resume && resume_state != eStateSuspended) |
| 725 | { |
Greg Clayton | 6e0ff1a | 2013-05-09 01:55:29 +0000 | [diff] [blame] | 726 | m_stop_info_sp.reset(); |
Greg Clayton | d1d06e4 | 2013-04-20 00:27:58 +0000 | [diff] [blame] | 727 | } |
Jim Ingham | 513c6bb | 2012-09-01 01:02:41 +0000 | [diff] [blame] | 728 | } |
| 729 | |
Greg Clayton | 160c9d8 | 2013-05-01 21:54:04 +0000 | [diff] [blame] | 730 | if (need_to_resume) |
| 731 | { |
| 732 | ClearStackFrames(); |
| 733 | // Let Thread subclasses do any special work they need to prior to resuming |
| 734 | WillResume (resume_state); |
| 735 | } |
| 736 | |
Jim Ingham | 513c6bb | 2012-09-01 01:02:41 +0000 | [diff] [blame] | 737 | return need_to_resume; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 738 | } |
| 739 | |
| 740 | void |
| 741 | Thread::DidResume () |
| 742 | { |
| 743 | SetResumeSignal (LLDB_INVALID_SIGNAL_NUMBER); |
| 744 | } |
| 745 | |
Andrew Kaylor | 29d6574 | 2013-05-10 17:19:04 +0000 | [diff] [blame] | 746 | void |
| 747 | Thread::DidStop () |
| 748 | { |
| 749 | SetState (eStateStopped); |
| 750 | } |
| 751 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 752 | bool |
| 753 | Thread::ShouldStop (Event* event_ptr) |
| 754 | { |
| 755 | ThreadPlan *current_plan = GetCurrentPlan(); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 756 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 757 | bool should_stop = true; |
| 758 | |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 759 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 760 | |
Jim Ingham | 92087d8 | 2012-01-31 23:09:20 +0000 | [diff] [blame] | 761 | if (GetResumeState () == eStateSuspended) |
| 762 | { |
| 763 | if (log) |
Greg Clayton | 160c9d8 | 2013-05-01 21:54:04 +0000 | [diff] [blame] | 764 | log->Printf ("Thread::%s for tid = 0x%4.4" PRIx64 " 0x%4.4" PRIx64 ", should_stop = 0 (ignore since thread was suspended)", |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 765 | __FUNCTION__, GetID (), GetProtocolID()); |
Jim Ingham | 92087d8 | 2012-01-31 23:09:20 +0000 | [diff] [blame] | 766 | return false; |
| 767 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 768 | |
Jim Ingham | 92087d8 | 2012-01-31 23:09:20 +0000 | [diff] [blame] | 769 | if (GetTemporaryResumeState () == eStateSuspended) |
| 770 | { |
| 771 | if (log) |
Greg Clayton | 160c9d8 | 2013-05-01 21:54:04 +0000 | [diff] [blame] | 772 | log->Printf ("Thread::%s for tid = 0x%4.4" PRIx64 " 0x%4.4" PRIx64 ", should_stop = 0 (ignore since thread was suspended)", |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 773 | __FUNCTION__, GetID (), GetProtocolID()); |
Jim Ingham | 92087d8 | 2012-01-31 23:09:20 +0000 | [diff] [blame] | 774 | return false; |
| 775 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 776 | |
Daniel Malea | 246cb61 | 2013-05-14 15:20:12 +0000 | [diff] [blame] | 777 | // Based on the current thread plan and process stop info, check if this |
| 778 | // thread caused the process to stop. NOTE: this must take place before |
| 779 | // the plan is moved from the current plan stack to the completed plan |
| 780 | // stack. |
Jim Ingham | 92087d8 | 2012-01-31 23:09:20 +0000 | [diff] [blame] | 781 | if (ThreadStoppedForAReason() == false) |
| 782 | { |
| 783 | if (log) |
Greg Clayton | 160c9d8 | 2013-05-01 21:54:04 +0000 | [diff] [blame] | 784 | 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)", |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 785 | __FUNCTION__, GetID (), GetProtocolID(), |
Greg Clayton | 1afa68e | 2013-04-02 20:32:37 +0000 | [diff] [blame] | 786 | GetRegisterContext() ? GetRegisterContext()->GetPC() : LLDB_INVALID_ADDRESS); |
Jim Ingham | 92087d8 | 2012-01-31 23:09:20 +0000 | [diff] [blame] | 787 | return false; |
| 788 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 789 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 790 | if (log) |
| 791 | { |
Jim Ingham | dee1bc9 | 2013-06-22 00:27:45 +0000 | [diff] [blame] | 792 | log->Printf ("Thread::%s(%p) for tid = 0x%4.4" PRIx64 " 0x%4.4" PRIx64 ", pc = 0x%16.16" PRIx64, |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 793 | __FUNCTION__, static_cast<void*>(this), GetID (), |
Greg Clayton | 160c9d8 | 2013-05-01 21:54:04 +0000 | [diff] [blame] | 794 | GetProtocolID (), |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 795 | GetRegisterContext() |
| 796 | ? GetRegisterContext()->GetPC() |
| 797 | : LLDB_INVALID_ADDRESS); |
Jim Ingham | 10c4b24 | 2011-10-15 00:23:43 +0000 | [diff] [blame] | 798 | log->Printf ("^^^^^^^^ Thread::ShouldStop Begin ^^^^^^^^"); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 799 | StreamString s; |
Jim Ingham | 10c4b24 | 2011-10-15 00:23:43 +0000 | [diff] [blame] | 800 | s.IndentMore(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 801 | DumpThreadPlans(&s); |
Jim Ingham | 10c4b24 | 2011-10-15 00:23:43 +0000 | [diff] [blame] | 802 | log->Printf ("Plan stack initial state:\n%s", s.GetData()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 803 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 804 | |
Jim Ingham | 06e827c | 2010-11-11 19:26:09 +0000 | [diff] [blame] | 805 | // The top most plan always gets to do the trace log... |
| 806 | current_plan->DoTraceLog (); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 807 | |
Jim Ingham | 6d66ce6 | 2012-04-20 21:16:56 +0000 | [diff] [blame] | 808 | // First query the stop info's ShouldStopSynchronous. This handles "synchronous" stop reasons, for example the breakpoint |
| 809 | // command on internal breakpoints. If a synchronous stop reason says we should not stop, then we don't have to |
| 810 | // do any more work on this stop. |
Greg Clayton | 6e0ff1a | 2013-05-09 01:55:29 +0000 | [diff] [blame] | 811 | StopInfoSP private_stop_info (GetPrivateStopInfo()); |
Jim Ingham | 6d66ce6 | 2012-04-20 21:16:56 +0000 | [diff] [blame] | 812 | if (private_stop_info && private_stop_info->ShouldStopSynchronous(event_ptr) == false) |
| 813 | { |
| 814 | if (log) |
| 815 | log->Printf ("StopInfo::ShouldStop async callback says we should not stop, returning ShouldStop of false."); |
| 816 | return false; |
| 817 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 818 | |
Jim Ingham | bad39e4 | 2012-09-05 21:12:49 +0000 | [diff] [blame] | 819 | // If we've already been restarted, don't query the plans since the state they would examine is not current. |
| 820 | if (Process::ProcessEventData::GetRestartedFromEvent(event_ptr)) |
| 821 | return false; |
| 822 | |
| 823 | // Before the plans see the state of the world, calculate the current inlined depth. |
| 824 | GetStackFrameList()->CalculateCurrentInlinedDepth(); |
| 825 | |
Jim Ingham | 25f6670 | 2011-12-03 01:52:59 +0000 | [diff] [blame] | 826 | // If the base plan doesn't understand why we stopped, then we have to find a plan that does. |
| 827 | // If that plan is still working, then we don't need to do any more work. If the plan that explains |
| 828 | // the stop is done, then we should pop all the plans below it, and pop it, and then let the plans above it decide |
| 829 | // whether they still need to do more work. |
| 830 | |
| 831 | bool done_processing_current_plan = false; |
| 832 | |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 833 | if (!current_plan->PlanExplainsStop(event_ptr)) |
Jim Ingham | 25f6670 | 2011-12-03 01:52:59 +0000 | [diff] [blame] | 834 | { |
| 835 | if (current_plan->TracerExplainsStop()) |
| 836 | { |
| 837 | done_processing_current_plan = true; |
| 838 | should_stop = false; |
| 839 | } |
| 840 | else |
| 841 | { |
Jim Ingham | cf274f9 | 2012-04-09 22:37:39 +0000 | [diff] [blame] | 842 | // 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] | 843 | // does and let it handle the situation. |
| 844 | ThreadPlan *plan_ptr = current_plan; |
| 845 | while ((plan_ptr = GetPreviousPlan(plan_ptr)) != NULL) |
| 846 | { |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 847 | if (plan_ptr->PlanExplainsStop(event_ptr)) |
Jim Ingham | 25f6670 | 2011-12-03 01:52:59 +0000 | [diff] [blame] | 848 | { |
| 849 | should_stop = plan_ptr->ShouldStop (event_ptr); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 850 | |
Jim Ingham | 25f6670 | 2011-12-03 01:52:59 +0000 | [diff] [blame] | 851 | // plan_ptr explains the stop, next check whether plan_ptr is done, if so, then we should take it |
| 852 | // and all the plans below it off the stack. |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 853 | |
Jim Ingham | 25f6670 | 2011-12-03 01:52:59 +0000 | [diff] [blame] | 854 | if (plan_ptr->MischiefManaged()) |
| 855 | { |
Jim Ingham | 031177e | 2012-05-11 23:49:49 +0000 | [diff] [blame] | 856 | // 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] | 857 | ThreadPlan *prev_plan_ptr = GetPreviousPlan (plan_ptr); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 858 | |
Jim Ingham | 25f6670 | 2011-12-03 01:52:59 +0000 | [diff] [blame] | 859 | do |
| 860 | { |
| 861 | if (should_stop) |
| 862 | current_plan->WillStop(); |
| 863 | PopPlan(); |
| 864 | } |
Jim Ingham | 7ba6e99 | 2012-05-11 23:47:32 +0000 | [diff] [blame] | 865 | while ((current_plan = GetCurrentPlan()) != prev_plan_ptr); |
| 866 | // Now, if the responsible plan was not "Okay to discard" then we're done, |
| 867 | // otherwise we forward this to the next plan in the stack below. |
| 868 | if (plan_ptr->IsMasterPlan() && !plan_ptr->OkayToDiscard()) |
| 869 | done_processing_current_plan = true; |
| 870 | else |
| 871 | done_processing_current_plan = false; |
Jim Ingham | 25f6670 | 2011-12-03 01:52:59 +0000 | [diff] [blame] | 872 | } |
| 873 | else |
| 874 | done_processing_current_plan = true; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 875 | |
Jim Ingham | 25f6670 | 2011-12-03 01:52:59 +0000 | [diff] [blame] | 876 | break; |
| 877 | } |
| 878 | |
| 879 | } |
| 880 | } |
| 881 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 882 | |
Jim Ingham | 25f6670 | 2011-12-03 01:52:59 +0000 | [diff] [blame] | 883 | if (!done_processing_current_plan) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 884 | { |
Jim Ingham | b01e742 | 2010-06-19 04:45:32 +0000 | [diff] [blame] | 885 | bool over_ride_stop = current_plan->ShouldAutoContinue(event_ptr); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 886 | |
Jim Ingham | 10c4b24 | 2011-10-15 00:23:43 +0000 | [diff] [blame] | 887 | if (log) |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 888 | log->Printf("Plan %s explains stop, auto-continue %i.", |
| 889 | current_plan->GetName(), over_ride_stop); |
| 890 | |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 891 | // We're starting from the base plan, so just let it decide; |
| 892 | if (PlanIsBasePlan(current_plan)) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 893 | { |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 894 | should_stop = current_plan->ShouldStop (event_ptr); |
| 895 | if (log) |
Greg Clayton | af247d7 | 2011-05-19 03:54:16 +0000 | [diff] [blame] | 896 | log->Printf("Base plan says should stop: %i.", should_stop); |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 897 | } |
| 898 | else |
| 899 | { |
| 900 | // Otherwise, don't let the base plan override what the other plans say to do, since |
| 901 | // presumably if there were other plans they would know what to do... |
| 902 | while (1) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 903 | { |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 904 | if (PlanIsBasePlan(current_plan)) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 905 | break; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 906 | |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 907 | should_stop = current_plan->ShouldStop(event_ptr); |
| 908 | if (log) |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 909 | log->Printf("Plan %s should stop: %d.", |
| 910 | current_plan->GetName(), should_stop); |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 911 | if (current_plan->MischiefManaged()) |
| 912 | { |
| 913 | if (should_stop) |
| 914 | current_plan->WillStop(); |
| 915 | |
| 916 | // If a Master Plan wants to stop, and wants to stick on the stack, we let it. |
| 917 | // Otherwise, see if the plan's parent wants to stop. |
| 918 | |
| 919 | if (should_stop && current_plan->IsMasterPlan() && !current_plan->OkayToDiscard()) |
| 920 | { |
| 921 | PopPlan(); |
| 922 | break; |
| 923 | } |
| 924 | else |
| 925 | { |
| 926 | |
| 927 | PopPlan(); |
| 928 | |
| 929 | current_plan = GetCurrentPlan(); |
| 930 | if (current_plan == NULL) |
| 931 | { |
| 932 | break; |
| 933 | } |
| 934 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 935 | } |
| 936 | else |
| 937 | { |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 938 | break; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 939 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 940 | } |
| 941 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 942 | |
Jim Ingham | b01e742 | 2010-06-19 04:45:32 +0000 | [diff] [blame] | 943 | if (over_ride_stop) |
| 944 | should_stop = false; |
Jim Ingham | 64e7ead | 2012-05-03 21:19:36 +0000 | [diff] [blame] | 945 | |
Jim Ingham | 8b91d0c | 2014-10-08 01:03:54 +0000 | [diff] [blame] | 946 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 947 | |
Jim Ingham | 8b91d0c | 2014-10-08 01:03:54 +0000 | [diff] [blame] | 948 | // One other potential problem is that we set up a master plan, then stop in before it is complete - for instance |
| 949 | // by hitting a breakpoint during a step-over - then do some step/finish/etc operations that wind up |
| 950 | // past the end point condition of the initial plan. We don't want to strand the original plan on the stack, |
| 951 | // This code clears stale plans off the stack. |
| 952 | |
| 953 | if (should_stop) |
| 954 | { |
| 955 | ThreadPlan *plan_ptr = GetCurrentPlan(); |
| 956 | while (!PlanIsBasePlan(plan_ptr)) |
Jim Ingham | 64e7ead | 2012-05-03 21:19:36 +0000 | [diff] [blame] | 957 | { |
Jim Ingham | 8b91d0c | 2014-10-08 01:03:54 +0000 | [diff] [blame] | 958 | bool stale = plan_ptr->IsPlanStale (); |
| 959 | ThreadPlan *examined_plan = plan_ptr; |
| 960 | plan_ptr = GetPreviousPlan (examined_plan); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 961 | |
Jim Ingham | 8b91d0c | 2014-10-08 01:03:54 +0000 | [diff] [blame] | 962 | if (stale) |
| 963 | { |
| 964 | if (log) |
| 965 | log->Printf("Plan %s being discarded in cleanup, it says it is already done.", |
| 966 | examined_plan->GetName()); |
| 967 | DiscardThreadPlansUpToPlan(examined_plan); |
Jim Ingham | 64e7ead | 2012-05-03 21:19:36 +0000 | [diff] [blame] | 968 | } |
| 969 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 970 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 971 | |
Jim Ingham | 10c4b24 | 2011-10-15 00:23:43 +0000 | [diff] [blame] | 972 | if (log) |
| 973 | { |
| 974 | StreamString s; |
| 975 | s.IndentMore(); |
| 976 | DumpThreadPlans(&s); |
| 977 | log->Printf ("Plan stack final state:\n%s", s.GetData()); |
| 978 | log->Printf ("vvvvvvvv Thread::ShouldStop End (returning %i) vvvvvvvv", should_stop); |
| 979 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 980 | return should_stop; |
| 981 | } |
| 982 | |
| 983 | Vote |
| 984 | Thread::ShouldReportStop (Event* event_ptr) |
| 985 | { |
| 986 | StateType thread_state = GetResumeState (); |
Jim Ingham | 92087d8 | 2012-01-31 23:09:20 +0000 | [diff] [blame] | 987 | StateType temp_thread_state = GetTemporaryResumeState(); |
| 988 | |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 989 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); |
Greg Clayton | 2cad65a | 2010-09-03 17:10:42 +0000 | [diff] [blame] | 990 | |
| 991 | if (thread_state == eStateSuspended || thread_state == eStateInvalid) |
| 992 | { |
| 993 | if (log) |
Greg Clayton | 160c9d8 | 2013-05-01 21:54:04 +0000 | [diff] [blame] | 994 | 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] | 995 | return eVoteNoOpinion; |
Greg Clayton | 2cad65a | 2010-09-03 17:10:42 +0000 | [diff] [blame] | 996 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 997 | |
Jim Ingham | 92087d8 | 2012-01-31 23:09:20 +0000 | [diff] [blame] | 998 | if (temp_thread_state == eStateSuspended || temp_thread_state == eStateInvalid) |
| 999 | { |
| 1000 | if (log) |
Greg Clayton | 160c9d8 | 2013-05-01 21:54:04 +0000 | [diff] [blame] | 1001 | 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] | 1002 | return eVoteNoOpinion; |
| 1003 | } |
| 1004 | |
| 1005 | if (!ThreadStoppedForAReason()) |
| 1006 | { |
| 1007 | if (log) |
Greg Clayton | 160c9d8 | 2013-05-01 21:54:04 +0000 | [diff] [blame] | 1008 | 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] | 1009 | return eVoteNoOpinion; |
| 1010 | } |
| 1011 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1012 | if (m_completed_plan_stack.size() > 0) |
| 1013 | { |
| 1014 | // Don't use GetCompletedPlan here, since that suppresses private plans. |
Greg Clayton | 2cad65a | 2010-09-03 17:10:42 +0000 | [diff] [blame] | 1015 | if (log) |
Greg Clayton | 160c9d8 | 2013-05-01 21:54:04 +0000 | [diff] [blame] | 1016 | 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] | 1017 | return m_completed_plan_stack.back()->ShouldReportStop (event_ptr); |
| 1018 | } |
| 1019 | else |
Greg Clayton | 2cad65a | 2010-09-03 17:10:42 +0000 | [diff] [blame] | 1020 | { |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 1021 | Vote thread_vote = eVoteNoOpinion; |
| 1022 | ThreadPlan *plan_ptr = GetCurrentPlan(); |
| 1023 | while (1) |
| 1024 | { |
| 1025 | if (plan_ptr->PlanExplainsStop(event_ptr)) |
| 1026 | { |
| 1027 | thread_vote = plan_ptr->ShouldReportStop(event_ptr); |
| 1028 | break; |
| 1029 | } |
| 1030 | if (PlanIsBasePlan(plan_ptr)) |
| 1031 | break; |
| 1032 | else |
| 1033 | plan_ptr = GetPreviousPlan(plan_ptr); |
| 1034 | } |
Greg Clayton | 2cad65a | 2010-09-03 17:10:42 +0000 | [diff] [blame] | 1035 | if (log) |
Greg Clayton | 160c9d8 | 2013-05-01 21:54:04 +0000 | [diff] [blame] | 1036 | 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] | 1037 | |
| 1038 | return thread_vote; |
Greg Clayton | 2cad65a | 2010-09-03 17:10:42 +0000 | [diff] [blame] | 1039 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1040 | } |
| 1041 | |
| 1042 | Vote |
| 1043 | Thread::ShouldReportRun (Event* event_ptr) |
| 1044 | { |
| 1045 | StateType thread_state = GetResumeState (); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 1046 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1047 | if (thread_state == eStateSuspended |
| 1048 | || thread_state == eStateInvalid) |
Jim Ingham | 444586b | 2011-01-24 06:34:17 +0000 | [diff] [blame] | 1049 | { |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1050 | return eVoteNoOpinion; |
Jim Ingham | 444586b | 2011-01-24 06:34:17 +0000 | [diff] [blame] | 1051 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 1052 | |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 1053 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1054 | if (m_completed_plan_stack.size() > 0) |
| 1055 | { |
| 1056 | // Don't use GetCompletedPlan here, since that suppresses private plans. |
Jim Ingham | 444586b | 2011-01-24 06:34:17 +0000 | [diff] [blame] | 1057 | if (log) |
Jim Ingham | dee1bc9 | 2013-06-22 00:27:45 +0000 | [diff] [blame] | 1058 | log->Printf ("Current Plan for thread %d(%p) (0x%4.4" PRIx64 ", %s): %s being asked whether we should report run.", |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 1059 | GetIndexID(), static_cast<void*>(this), GetID(), |
Greg Clayton | 160c9d8 | 2013-05-01 21:54:04 +0000 | [diff] [blame] | 1060 | StateAsCString(GetTemporaryResumeState()), |
Jim Ingham | 444586b | 2011-01-24 06:34:17 +0000 | [diff] [blame] | 1061 | m_completed_plan_stack.back()->GetName()); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 1062 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1063 | return m_completed_plan_stack.back()->ShouldReportRun (event_ptr); |
| 1064 | } |
| 1065 | else |
Jim Ingham | 444586b | 2011-01-24 06:34:17 +0000 | [diff] [blame] | 1066 | { |
| 1067 | if (log) |
Jim Ingham | dee1bc9 | 2013-06-22 00:27:45 +0000 | [diff] [blame] | 1068 | log->Printf ("Current Plan for thread %d(%p) (0x%4.4" PRIx64 ", %s): %s being asked whether we should report run.", |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 1069 | GetIndexID(), static_cast<void*>(this), GetID(), |
Greg Clayton | 160c9d8 | 2013-05-01 21:54:04 +0000 | [diff] [blame] | 1070 | StateAsCString(GetTemporaryResumeState()), |
Jim Ingham | 444586b | 2011-01-24 06:34:17 +0000 | [diff] [blame] | 1071 | GetCurrentPlan()->GetName()); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 1072 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1073 | return GetCurrentPlan()->ShouldReportRun (event_ptr); |
Jim Ingham | 444586b | 2011-01-24 06:34:17 +0000 | [diff] [blame] | 1074 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1075 | } |
| 1076 | |
Jim Ingham | 1b54c88 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 1077 | bool |
| 1078 | Thread::MatchesSpec (const ThreadSpec *spec) |
| 1079 | { |
| 1080 | if (spec == NULL) |
| 1081 | return true; |
Jim Ingham | 1b54c88 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 1082 | |
Jim Ingham | 3d90292 | 2012-03-07 22:03:04 +0000 | [diff] [blame] | 1083 | return spec->ThreadPassesBasicTests(*this); |
Jim Ingham | 1b54c88 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 1084 | } |
| 1085 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1086 | void |
| 1087 | Thread::PushPlan (ThreadPlanSP &thread_plan_sp) |
| 1088 | { |
| 1089 | if (thread_plan_sp) |
| 1090 | { |
Jim Ingham | 06e827c | 2010-11-11 19:26:09 +0000 | [diff] [blame] | 1091 | // If the thread plan doesn't already have a tracer, give it its parent's tracer: |
| 1092 | if (!thread_plan_sp->GetThreadPlanTracer()) |
| 1093 | thread_plan_sp->SetThreadPlanTracer(m_plan_stack.back()->GetThreadPlanTracer()); |
Jim Ingham | b15bfc7 | 2010-10-20 00:39:53 +0000 | [diff] [blame] | 1094 | m_plan_stack.push_back (thread_plan_sp); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 1095 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1096 | thread_plan_sp->DidPush(); |
| 1097 | |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 1098 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1099 | if (log) |
| 1100 | { |
| 1101 | StreamString s; |
| 1102 | thread_plan_sp->GetDescription (&s, lldb::eDescriptionLevelFull); |
Jim Ingham | dee1bc9 | 2013-06-22 00:27:45 +0000 | [diff] [blame] | 1103 | log->Printf("Thread::PushPlan(0x%p): \"%s\", tid = 0x%4.4" PRIx64 ".", |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 1104 | static_cast<void*>(this), s.GetData(), |
Jim Ingham | b15bfc7 | 2010-10-20 00:39:53 +0000 | [diff] [blame] | 1105 | thread_plan_sp->GetThread().GetID()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1106 | } |
| 1107 | } |
| 1108 | } |
| 1109 | |
| 1110 | void |
| 1111 | Thread::PopPlan () |
| 1112 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 1113 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1114 | |
Jim Ingham | 4fc6cb9 | 2012-08-22 21:34:33 +0000 | [diff] [blame] | 1115 | if (m_plan_stack.size() <= 1) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1116 | return; |
| 1117 | else |
| 1118 | { |
| 1119 | ThreadPlanSP &plan = m_plan_stack.back(); |
| 1120 | if (log) |
| 1121 | { |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 1122 | 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] | 1123 | } |
| 1124 | m_completed_plan_stack.push_back (plan); |
| 1125 | plan->WillPop(); |
| 1126 | m_plan_stack.pop_back(); |
| 1127 | } |
| 1128 | } |
| 1129 | |
| 1130 | void |
| 1131 | Thread::DiscardPlan () |
| 1132 | { |
Jim Ingham | dee1bc9 | 2013-06-22 00:27:45 +0000 | [diff] [blame] | 1133 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1134 | if (m_plan_stack.size() > 1) |
| 1135 | { |
| 1136 | ThreadPlanSP &plan = m_plan_stack.back(); |
Jim Ingham | dee1bc9 | 2013-06-22 00:27:45 +0000 | [diff] [blame] | 1137 | if (log) |
| 1138 | log->Printf("Discarding plan: \"%s\", tid = 0x%4.4" PRIx64 ".", plan->GetName(), plan->GetThread().GetID()); |
| 1139 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1140 | m_discarded_plan_stack.push_back (plan); |
| 1141 | plan->WillPop(); |
| 1142 | m_plan_stack.pop_back(); |
| 1143 | } |
| 1144 | } |
| 1145 | |
| 1146 | ThreadPlan * |
| 1147 | Thread::GetCurrentPlan () |
| 1148 | { |
Jim Ingham | e147123 | 2012-04-19 00:17:05 +0000 | [diff] [blame] | 1149 | // There will always be at least the base plan. If somebody is mucking with a |
| 1150 | // thread with an empty plan stack, we should assert right away. |
Greg Clayton | d1d06e4 | 2013-04-20 00:27:58 +0000 | [diff] [blame] | 1151 | if (m_plan_stack.empty()) |
| 1152 | return NULL; |
Jim Ingham | e147123 | 2012-04-19 00:17:05 +0000 | [diff] [blame] | 1153 | return m_plan_stack.back().get(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1154 | } |
| 1155 | |
| 1156 | ThreadPlanSP |
| 1157 | Thread::GetCompletedPlan () |
| 1158 | { |
| 1159 | ThreadPlanSP empty_plan_sp; |
| 1160 | if (!m_completed_plan_stack.empty()) |
| 1161 | { |
| 1162 | for (int i = m_completed_plan_stack.size() - 1; i >= 0; i--) |
| 1163 | { |
| 1164 | ThreadPlanSP completed_plan_sp; |
| 1165 | completed_plan_sp = m_completed_plan_stack[i]; |
| 1166 | if (!completed_plan_sp->GetPrivate ()) |
| 1167 | return completed_plan_sp; |
| 1168 | } |
| 1169 | } |
| 1170 | return empty_plan_sp; |
| 1171 | } |
| 1172 | |
Jim Ingham | 73ca05a | 2011-12-17 01:35:57 +0000 | [diff] [blame] | 1173 | ValueObjectSP |
| 1174 | Thread::GetReturnValueObject () |
| 1175 | { |
| 1176 | if (!m_completed_plan_stack.empty()) |
| 1177 | { |
| 1178 | for (int i = m_completed_plan_stack.size() - 1; i >= 0; i--) |
| 1179 | { |
| 1180 | ValueObjectSP return_valobj_sp; |
| 1181 | return_valobj_sp = m_completed_plan_stack[i]->GetReturnValueObject(); |
| 1182 | if (return_valobj_sp) |
| 1183 | return return_valobj_sp; |
| 1184 | } |
| 1185 | } |
| 1186 | return ValueObjectSP(); |
| 1187 | } |
| 1188 | |
Jim Ingham | 30fadaf | 2014-07-08 01:07:32 +0000 | [diff] [blame] | 1189 | ClangExpressionVariableSP |
| 1190 | Thread::GetExpressionVariable () |
| 1191 | { |
| 1192 | if (!m_completed_plan_stack.empty()) |
| 1193 | { |
| 1194 | for (int i = m_completed_plan_stack.size() - 1; i >= 0; i--) |
| 1195 | { |
| 1196 | ClangExpressionVariableSP expression_variable_sp; |
| 1197 | expression_variable_sp = m_completed_plan_stack[i]->GetExpressionVariable(); |
| 1198 | if (expression_variable_sp) |
| 1199 | return expression_variable_sp; |
| 1200 | } |
| 1201 | } |
| 1202 | return ClangExpressionVariableSP(); |
| 1203 | } |
| 1204 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1205 | bool |
| 1206 | Thread::IsThreadPlanDone (ThreadPlan *plan) |
| 1207 | { |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1208 | if (!m_completed_plan_stack.empty()) |
| 1209 | { |
| 1210 | for (int i = m_completed_plan_stack.size() - 1; i >= 0; i--) |
| 1211 | { |
| 1212 | if (m_completed_plan_stack[i].get() == plan) |
| 1213 | return true; |
| 1214 | } |
| 1215 | } |
| 1216 | return false; |
| 1217 | } |
| 1218 | |
| 1219 | bool |
| 1220 | Thread::WasThreadPlanDiscarded (ThreadPlan *plan) |
| 1221 | { |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1222 | if (!m_discarded_plan_stack.empty()) |
| 1223 | { |
| 1224 | for (int i = m_discarded_plan_stack.size() - 1; i >= 0; i--) |
| 1225 | { |
| 1226 | if (m_discarded_plan_stack[i].get() == plan) |
| 1227 | return true; |
| 1228 | } |
| 1229 | } |
| 1230 | return false; |
| 1231 | } |
| 1232 | |
| 1233 | ThreadPlan * |
| 1234 | Thread::GetPreviousPlan (ThreadPlan *current_plan) |
| 1235 | { |
| 1236 | if (current_plan == NULL) |
| 1237 | return NULL; |
| 1238 | |
| 1239 | int stack_size = m_completed_plan_stack.size(); |
| 1240 | for (int i = stack_size - 1; i > 0; i--) |
| 1241 | { |
| 1242 | if (current_plan == m_completed_plan_stack[i].get()) |
| 1243 | return m_completed_plan_stack[i-1].get(); |
| 1244 | } |
| 1245 | |
| 1246 | if (stack_size > 0 && m_completed_plan_stack[0].get() == current_plan) |
| 1247 | { |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1248 | if (m_plan_stack.size() > 0) |
| 1249 | return m_plan_stack.back().get(); |
| 1250 | else |
| 1251 | return NULL; |
| 1252 | } |
| 1253 | |
| 1254 | stack_size = m_plan_stack.size(); |
| 1255 | for (int i = stack_size - 1; i > 0; i--) |
| 1256 | { |
| 1257 | if (current_plan == m_plan_stack[i].get()) |
| 1258 | return m_plan_stack[i-1].get(); |
| 1259 | } |
| 1260 | return NULL; |
| 1261 | } |
| 1262 | |
| 1263 | void |
| 1264 | Thread::QueueThreadPlan (ThreadPlanSP &thread_plan_sp, bool abort_other_plans) |
| 1265 | { |
| 1266 | if (abort_other_plans) |
| 1267 | DiscardThreadPlans(true); |
| 1268 | |
| 1269 | PushPlan (thread_plan_sp); |
| 1270 | } |
| 1271 | |
Jim Ingham | 06e827c | 2010-11-11 19:26:09 +0000 | [diff] [blame] | 1272 | |
| 1273 | void |
| 1274 | Thread::EnableTracer (bool value, bool single_stepping) |
| 1275 | { |
| 1276 | int stack_size = m_plan_stack.size(); |
| 1277 | for (int i = 0; i < stack_size; i++) |
| 1278 | { |
| 1279 | if (m_plan_stack[i]->GetThreadPlanTracer()) |
| 1280 | { |
| 1281 | m_plan_stack[i]->GetThreadPlanTracer()->EnableTracing(value); |
| 1282 | m_plan_stack[i]->GetThreadPlanTracer()->EnableSingleStep(single_stepping); |
| 1283 | } |
| 1284 | } |
| 1285 | } |
| 1286 | |
| 1287 | void |
| 1288 | Thread::SetTracer (lldb::ThreadPlanTracerSP &tracer_sp) |
| 1289 | { |
| 1290 | int stack_size = m_plan_stack.size(); |
| 1291 | for (int i = 0; i < stack_size; i++) |
| 1292 | m_plan_stack[i]->SetThreadPlanTracer(tracer_sp); |
| 1293 | } |
| 1294 | |
Jim Ingham | 2bdbfd5 | 2014-09-29 23:17:18 +0000 | [diff] [blame] | 1295 | bool |
| 1296 | Thread::DiscardUserThreadPlansUpToIndex (uint32_t thread_index) |
| 1297 | { |
| 1298 | // Count the user thread plans from the back end to get the number of the one we want |
| 1299 | // to discard: |
| 1300 | |
| 1301 | uint32_t idx = 0; |
| 1302 | ThreadPlan *up_to_plan_ptr = nullptr; |
| 1303 | |
| 1304 | for (ThreadPlanSP plan_sp : m_plan_stack) |
| 1305 | { |
| 1306 | if (plan_sp->GetPrivate()) |
| 1307 | continue; |
| 1308 | if (idx == thread_index) |
| 1309 | { |
| 1310 | up_to_plan_ptr = plan_sp.get(); |
| 1311 | break; |
| 1312 | } |
| 1313 | else |
| 1314 | idx++; |
| 1315 | } |
| 1316 | |
| 1317 | if (up_to_plan_ptr == nullptr) |
| 1318 | return false; |
| 1319 | |
| 1320 | DiscardThreadPlansUpToPlan(up_to_plan_ptr); |
| 1321 | return true; |
| 1322 | } |
| 1323 | |
| 1324 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1325 | void |
Jim Ingham | 399f1ca | 2010-11-05 19:25:48 +0000 | [diff] [blame] | 1326 | Thread::DiscardThreadPlansUpToPlan (lldb::ThreadPlanSP &up_to_plan_sp) |
| 1327 | { |
Jim Ingham | 64e7ead | 2012-05-03 21:19:36 +0000 | [diff] [blame] | 1328 | DiscardThreadPlansUpToPlan (up_to_plan_sp.get()); |
| 1329 | } |
| 1330 | |
| 1331 | void |
| 1332 | Thread::DiscardThreadPlansUpToPlan (ThreadPlan *up_to_plan_ptr) |
| 1333 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 1334 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); |
Jim Ingham | 399f1ca | 2010-11-05 19:25:48 +0000 | [diff] [blame] | 1335 | if (log) |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 1336 | log->Printf("Discarding thread plans for thread tid = 0x%4.4" PRIx64 ", up to %p", |
| 1337 | GetID(), static_cast<void*>(up_to_plan_ptr)); |
Jim Ingham | 399f1ca | 2010-11-05 19:25:48 +0000 | [diff] [blame] | 1338 | |
| 1339 | int stack_size = m_plan_stack.size(); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 1340 | |
Jim Ingham | 399f1ca | 2010-11-05 19:25:48 +0000 | [diff] [blame] | 1341 | // If the input plan is NULL, discard all plans. Otherwise make sure this plan is in the |
| 1342 | // stack, and if so discard up to and including it. |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 1343 | |
Jim Ingham | 64e7ead | 2012-05-03 21:19:36 +0000 | [diff] [blame] | 1344 | if (up_to_plan_ptr == NULL) |
Jim Ingham | 399f1ca | 2010-11-05 19:25:48 +0000 | [diff] [blame] | 1345 | { |
| 1346 | for (int i = stack_size - 1; i > 0; i--) |
| 1347 | DiscardPlan(); |
| 1348 | } |
| 1349 | else |
| 1350 | { |
| 1351 | bool found_it = false; |
| 1352 | for (int i = stack_size - 1; i > 0; i--) |
| 1353 | { |
Jim Ingham | 64e7ead | 2012-05-03 21:19:36 +0000 | [diff] [blame] | 1354 | if (m_plan_stack[i].get() == up_to_plan_ptr) |
Jim Ingham | 399f1ca | 2010-11-05 19:25:48 +0000 | [diff] [blame] | 1355 | found_it = true; |
| 1356 | } |
| 1357 | if (found_it) |
| 1358 | { |
| 1359 | bool last_one = false; |
| 1360 | for (int i = stack_size - 1; i > 0 && !last_one ; i--) |
| 1361 | { |
Jim Ingham | 64e7ead | 2012-05-03 21:19:36 +0000 | [diff] [blame] | 1362 | if (GetCurrentPlan() == up_to_plan_ptr) |
Jim Ingham | 399f1ca | 2010-11-05 19:25:48 +0000 | [diff] [blame] | 1363 | last_one = true; |
| 1364 | DiscardPlan(); |
| 1365 | } |
| 1366 | } |
| 1367 | } |
| 1368 | return; |
| 1369 | } |
| 1370 | |
| 1371 | void |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1372 | Thread::DiscardThreadPlans(bool force) |
| 1373 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 1374 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1375 | if (log) |
| 1376 | { |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 1377 | 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] | 1378 | } |
| 1379 | |
| 1380 | if (force) |
| 1381 | { |
| 1382 | int stack_size = m_plan_stack.size(); |
| 1383 | for (int i = stack_size - 1; i > 0; i--) |
| 1384 | { |
| 1385 | DiscardPlan(); |
| 1386 | } |
| 1387 | return; |
| 1388 | } |
| 1389 | |
| 1390 | while (1) |
| 1391 | { |
| 1392 | |
| 1393 | int master_plan_idx; |
Jim Ingham | a39ad07 | 2012-09-11 00:09:25 +0000 | [diff] [blame] | 1394 | bool discard = true; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1395 | |
| 1396 | // Find the first master plan, see if it wants discarding, and if yes discard up to it. |
| 1397 | for (master_plan_idx = m_plan_stack.size() - 1; master_plan_idx >= 0; master_plan_idx--) |
| 1398 | { |
| 1399 | if (m_plan_stack[master_plan_idx]->IsMasterPlan()) |
| 1400 | { |
| 1401 | discard = m_plan_stack[master_plan_idx]->OkayToDiscard(); |
| 1402 | break; |
| 1403 | } |
| 1404 | } |
| 1405 | |
| 1406 | if (discard) |
| 1407 | { |
| 1408 | // First pop all the dependent plans: |
| 1409 | for (int i = m_plan_stack.size() - 1; i > master_plan_idx; i--) |
| 1410 | { |
| 1411 | |
| 1412 | // FIXME: Do we need a finalize here, or is the rule that "PrepareForStop" |
| 1413 | // for the plan leaves it in a state that it is safe to pop the plan |
| 1414 | // with no more notice? |
| 1415 | DiscardPlan(); |
| 1416 | } |
| 1417 | |
| 1418 | // Now discard the master plan itself. |
| 1419 | // The bottom-most plan never gets discarded. "OkayToDiscard" for it means |
| 1420 | // discard it's dependent plans, but not it... |
| 1421 | if (master_plan_idx > 0) |
| 1422 | { |
| 1423 | DiscardPlan(); |
| 1424 | } |
| 1425 | } |
| 1426 | else |
| 1427 | { |
| 1428 | // If the master plan doesn't want to get discarded, then we're done. |
| 1429 | break; |
| 1430 | } |
| 1431 | |
| 1432 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1433 | } |
| 1434 | |
Jim Ingham | cf274f9 | 2012-04-09 22:37:39 +0000 | [diff] [blame] | 1435 | bool |
| 1436 | Thread::PlanIsBasePlan (ThreadPlan *plan_ptr) |
| 1437 | { |
| 1438 | if (plan_ptr->IsBasePlan()) |
| 1439 | return true; |
| 1440 | else if (m_plan_stack.size() == 0) |
| 1441 | return false; |
| 1442 | else |
| 1443 | return m_plan_stack[0].get() == plan_ptr; |
| 1444 | } |
| 1445 | |
Jim Ingham | 93208b8 | 2013-01-31 21:46:01 +0000 | [diff] [blame] | 1446 | Error |
| 1447 | Thread::UnwindInnermostExpression() |
| 1448 | { |
| 1449 | Error error; |
| 1450 | int stack_size = m_plan_stack.size(); |
| 1451 | |
| 1452 | // If the input plan is NULL, discard all plans. Otherwise make sure this plan is in the |
| 1453 | // stack, and if so discard up to and including it. |
| 1454 | |
| 1455 | for (int i = stack_size - 1; i > 0; i--) |
| 1456 | { |
| 1457 | if (m_plan_stack[i]->GetKind() == ThreadPlan::eKindCallFunction) |
| 1458 | { |
| 1459 | DiscardThreadPlansUpToPlan(m_plan_stack[i].get()); |
| 1460 | return error; |
| 1461 | } |
| 1462 | } |
| 1463 | error.SetErrorString("No expressions currently active on this thread"); |
| 1464 | return error; |
| 1465 | } |
| 1466 | |
| 1467 | |
Jim Ingham | 4d56e9c | 2013-07-18 21:48:26 +0000 | [diff] [blame] | 1468 | ThreadPlanSP |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1469 | Thread::QueueFundamentalPlan (bool abort_other_plans) |
| 1470 | { |
| 1471 | ThreadPlanSP thread_plan_sp (new ThreadPlanBase(*this)); |
| 1472 | QueueThreadPlan (thread_plan_sp, abort_other_plans); |
Jim Ingham | 4d56e9c | 2013-07-18 21:48:26 +0000 | [diff] [blame] | 1473 | return thread_plan_sp; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1474 | } |
| 1475 | |
Jim Ingham | 4d56e9c | 2013-07-18 21:48:26 +0000 | [diff] [blame] | 1476 | ThreadPlanSP |
Greg Clayton | 481cef2 | 2011-01-21 06:11:58 +0000 | [diff] [blame] | 1477 | Thread::QueueThreadPlanForStepSingleInstruction |
| 1478 | ( |
| 1479 | bool step_over, |
| 1480 | bool abort_other_plans, |
| 1481 | bool stop_other_threads |
| 1482 | ) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1483 | { |
| 1484 | ThreadPlanSP thread_plan_sp (new ThreadPlanStepInstruction (*this, step_over, stop_other_threads, eVoteNoOpinion, eVoteNoOpinion)); |
| 1485 | QueueThreadPlan (thread_plan_sp, abort_other_plans); |
Jim Ingham | 4d56e9c | 2013-07-18 21:48:26 +0000 | [diff] [blame] | 1486 | return thread_plan_sp; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1487 | } |
| 1488 | |
Jim Ingham | 4d56e9c | 2013-07-18 21:48:26 +0000 | [diff] [blame] | 1489 | ThreadPlanSP |
Jim Ingham | c627682 | 2012-12-12 19:58:40 +0000 | [diff] [blame] | 1490 | Thread::QueueThreadPlanForStepOverRange |
Greg Clayton | 474966a | 2010-06-12 18:59:55 +0000 | [diff] [blame] | 1491 | ( |
| 1492 | bool abort_other_plans, |
Greg Clayton | 474966a | 2010-06-12 18:59:55 +0000 | [diff] [blame] | 1493 | const AddressRange &range, |
Jim Ingham | c627682 | 2012-12-12 19:58:40 +0000 | [diff] [blame] | 1494 | const SymbolContext &addr_context, |
Jim Ingham | 4b4b247 | 2014-03-13 02:47:14 +0000 | [diff] [blame] | 1495 | lldb::RunMode stop_other_threads, |
| 1496 | LazyBool step_out_avoids_code_withoug_debug_info |
Jim Ingham | c627682 | 2012-12-12 19:58:40 +0000 | [diff] [blame] | 1497 | ) |
| 1498 | { |
| 1499 | ThreadPlanSP thread_plan_sp; |
Jim Ingham | 4b4b247 | 2014-03-13 02:47:14 +0000 | [diff] [blame] | 1500 | thread_plan_sp.reset (new ThreadPlanStepOverRange (*this, range, addr_context, stop_other_threads, step_out_avoids_code_withoug_debug_info)); |
| 1501 | |
Jim Ingham | c627682 | 2012-12-12 19:58:40 +0000 | [diff] [blame] | 1502 | QueueThreadPlan (thread_plan_sp, abort_other_plans); |
Jim Ingham | 4d56e9c | 2013-07-18 21:48:26 +0000 | [diff] [blame] | 1503 | return thread_plan_sp; |
Jim Ingham | c627682 | 2012-12-12 19:58:40 +0000 | [diff] [blame] | 1504 | } |
| 1505 | |
Jim Ingham | 4d56e9c | 2013-07-18 21:48:26 +0000 | [diff] [blame] | 1506 | ThreadPlanSP |
Jim Ingham | c627682 | 2012-12-12 19:58:40 +0000 | [diff] [blame] | 1507 | Thread::QueueThreadPlanForStepInRange |
| 1508 | ( |
| 1509 | bool abort_other_plans, |
| 1510 | const AddressRange &range, |
| 1511 | const SymbolContext &addr_context, |
| 1512 | const char *step_in_target, |
Greg Clayton | 474966a | 2010-06-12 18:59:55 +0000 | [diff] [blame] | 1513 | lldb::RunMode stop_other_threads, |
Jim Ingham | 4b4b247 | 2014-03-13 02:47:14 +0000 | [diff] [blame] | 1514 | LazyBool step_in_avoids_code_without_debug_info, |
| 1515 | LazyBool step_out_avoids_code_without_debug_info |
Greg Clayton | 474966a | 2010-06-12 18:59:55 +0000 | [diff] [blame] | 1516 | ) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1517 | { |
Jim Ingham | 2bdbfd5 | 2014-09-29 23:17:18 +0000 | [diff] [blame] | 1518 | ThreadPlanSP thread_plan_sp (new ThreadPlanStepInRange (*this, |
Jim Ingham | 4b4b247 | 2014-03-13 02:47:14 +0000 | [diff] [blame] | 1519 | range, |
| 1520 | addr_context, |
| 1521 | stop_other_threads, |
| 1522 | step_in_avoids_code_without_debug_info, |
Jim Ingham | 2bdbfd5 | 2014-09-29 23:17:18 +0000 | [diff] [blame] | 1523 | step_out_avoids_code_without_debug_info)); |
| 1524 | ThreadPlanStepInRange *plan = static_cast<ThreadPlanStepInRange *>(thread_plan_sp.get()); |
Jim Ingham | 4b4b247 | 2014-03-13 02:47:14 +0000 | [diff] [blame] | 1525 | |
Jim Ingham | c627682 | 2012-12-12 19:58:40 +0000 | [diff] [blame] | 1526 | if (step_in_target) |
| 1527 | plan->SetStepInTarget(step_in_target); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1528 | |
| 1529 | QueueThreadPlan (thread_plan_sp, abort_other_plans); |
Jim Ingham | 4d56e9c | 2013-07-18 21:48:26 +0000 | [diff] [blame] | 1530 | return thread_plan_sp; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1531 | } |
| 1532 | |
| 1533 | |
Jim Ingham | 4d56e9c | 2013-07-18 21:48:26 +0000 | [diff] [blame] | 1534 | ThreadPlanSP |
Greg Clayton | 481cef2 | 2011-01-21 06:11:58 +0000 | [diff] [blame] | 1535 | Thread::QueueThreadPlanForStepOut |
| 1536 | ( |
| 1537 | bool abort_other_plans, |
| 1538 | SymbolContext *addr_context, |
| 1539 | bool first_insn, |
| 1540 | bool stop_other_threads, |
| 1541 | Vote stop_vote, |
| 1542 | Vote run_vote, |
Jim Ingham | 4b4b247 | 2014-03-13 02:47:14 +0000 | [diff] [blame] | 1543 | uint32_t frame_idx, |
| 1544 | LazyBool step_out_avoids_code_withoug_debug_info |
Greg Clayton | 481cef2 | 2011-01-21 06:11:58 +0000 | [diff] [blame] | 1545 | ) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1546 | { |
Greg Clayton | 481cef2 | 2011-01-21 06:11:58 +0000 | [diff] [blame] | 1547 | ThreadPlanSP thread_plan_sp (new ThreadPlanStepOut (*this, |
| 1548 | addr_context, |
| 1549 | first_insn, |
| 1550 | stop_other_threads, |
| 1551 | stop_vote, |
| 1552 | run_vote, |
Jim Ingham | 4b4b247 | 2014-03-13 02:47:14 +0000 | [diff] [blame] | 1553 | frame_idx, |
| 1554 | step_out_avoids_code_withoug_debug_info)); |
| 1555 | |
| 1556 | if (thread_plan_sp->ValidatePlan(NULL)) |
| 1557 | { |
| 1558 | QueueThreadPlan (thread_plan_sp, abort_other_plans); |
| 1559 | return thread_plan_sp; |
| 1560 | } |
| 1561 | else |
| 1562 | { |
| 1563 | return ThreadPlanSP(); |
| 1564 | } |
| 1565 | } |
| 1566 | |
| 1567 | ThreadPlanSP |
| 1568 | Thread::QueueThreadPlanForStepOutNoShouldStop |
| 1569 | ( |
| 1570 | bool abort_other_plans, |
| 1571 | SymbolContext *addr_context, |
| 1572 | bool first_insn, |
| 1573 | bool stop_other_threads, |
| 1574 | Vote stop_vote, |
| 1575 | Vote run_vote, |
| 1576 | uint32_t frame_idx |
| 1577 | ) |
| 1578 | { |
Jim Ingham | 2bdbfd5 | 2014-09-29 23:17:18 +0000 | [diff] [blame] | 1579 | ThreadPlanSP thread_plan_sp(new ThreadPlanStepOut (*this, |
Jim Ingham | 4b4b247 | 2014-03-13 02:47:14 +0000 | [diff] [blame] | 1580 | addr_context, |
| 1581 | first_insn, |
| 1582 | stop_other_threads, |
| 1583 | stop_vote, |
| 1584 | run_vote, |
| 1585 | frame_idx, |
Jim Ingham | 2bdbfd5 | 2014-09-29 23:17:18 +0000 | [diff] [blame] | 1586 | eLazyBoolNo)); |
| 1587 | |
| 1588 | ThreadPlanStepOut *new_plan = static_cast<ThreadPlanStepOut *>(thread_plan_sp.get()); |
Jim Ingham | 4b4b247 | 2014-03-13 02:47:14 +0000 | [diff] [blame] | 1589 | new_plan->ClearShouldStopHereCallbacks(); |
Jim Ingham | 2bdbfd5 | 2014-09-29 23:17:18 +0000 | [diff] [blame] | 1590 | |
Sean Callanan | 708709c | 2012-07-31 22:19:25 +0000 | [diff] [blame] | 1591 | if (thread_plan_sp->ValidatePlan(NULL)) |
| 1592 | { |
| 1593 | QueueThreadPlan (thread_plan_sp, abort_other_plans); |
Jim Ingham | 4d56e9c | 2013-07-18 21:48:26 +0000 | [diff] [blame] | 1594 | return thread_plan_sp; |
Sean Callanan | 708709c | 2012-07-31 22:19:25 +0000 | [diff] [blame] | 1595 | } |
| 1596 | else |
| 1597 | { |
Jim Ingham | 4d56e9c | 2013-07-18 21:48:26 +0000 | [diff] [blame] | 1598 | return ThreadPlanSP(); |
Sean Callanan | 708709c | 2012-07-31 22:19:25 +0000 | [diff] [blame] | 1599 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1600 | } |
| 1601 | |
Jim Ingham | 4d56e9c | 2013-07-18 21:48:26 +0000 | [diff] [blame] | 1602 | ThreadPlanSP |
Jim Ingham | 18de2fd | 2012-05-10 01:35:39 +0000 | [diff] [blame] | 1603 | 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] | 1604 | { |
Jim Ingham | 18de2fd | 2012-05-10 01:35:39 +0000 | [diff] [blame] | 1605 | 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] | 1606 | if (!thread_plan_sp || !thread_plan_sp->ValidatePlan (NULL)) |
Jim Ingham | 4d56e9c | 2013-07-18 21:48:26 +0000 | [diff] [blame] | 1607 | return ThreadPlanSP(); |
Jim Ingham | 25f6670 | 2011-12-03 01:52:59 +0000 | [diff] [blame] | 1608 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1609 | QueueThreadPlan (thread_plan_sp, abort_other_plans); |
Jim Ingham | 4d56e9c | 2013-07-18 21:48:26 +0000 | [diff] [blame] | 1610 | return thread_plan_sp; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1611 | } |
| 1612 | |
Jim Ingham | 4d56e9c | 2013-07-18 21:48:26 +0000 | [diff] [blame] | 1613 | ThreadPlanSP |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1614 | Thread::QueueThreadPlanForRunToAddress (bool abort_other_plans, |
| 1615 | Address &target_addr, |
| 1616 | bool stop_other_threads) |
| 1617 | { |
| 1618 | ThreadPlanSP thread_plan_sp (new ThreadPlanRunToAddress (*this, target_addr, stop_other_threads)); |
| 1619 | QueueThreadPlan (thread_plan_sp, abort_other_plans); |
Jim Ingham | 4d56e9c | 2013-07-18 21:48:26 +0000 | [diff] [blame] | 1620 | return thread_plan_sp; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1621 | } |
| 1622 | |
Jim Ingham | 4d56e9c | 2013-07-18 21:48:26 +0000 | [diff] [blame] | 1623 | ThreadPlanSP |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1624 | Thread::QueueThreadPlanForStepUntil (bool abort_other_plans, |
Greg Clayton | 481cef2 | 2011-01-21 06:11:58 +0000 | [diff] [blame] | 1625 | lldb::addr_t *address_list, |
| 1626 | size_t num_addresses, |
| 1627 | bool stop_other_threads, |
| 1628 | uint32_t frame_idx) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1629 | { |
Greg Clayton | 481cef2 | 2011-01-21 06:11:58 +0000 | [diff] [blame] | 1630 | 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] | 1631 | QueueThreadPlan (thread_plan_sp, abort_other_plans); |
Jim Ingham | 4d56e9c | 2013-07-18 21:48:26 +0000 | [diff] [blame] | 1632 | return thread_plan_sp; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1633 | |
| 1634 | } |
| 1635 | |
Jim Ingham | 2bdbfd5 | 2014-09-29 23:17:18 +0000 | [diff] [blame] | 1636 | lldb::ThreadPlanSP |
| 1637 | Thread::QueueThreadPlanForStepScripted (bool abort_other_plans, |
| 1638 | const char *class_name, |
| 1639 | bool stop_other_threads) |
| 1640 | { |
| 1641 | ThreadPlanSP thread_plan_sp (new ThreadPlanPython (*this, class_name)); |
| 1642 | QueueThreadPlan (thread_plan_sp, abort_other_plans); |
| 1643 | // This seems a little funny, but I don't want to have to split up the constructor and the |
| 1644 | // DidPush in the scripted plan, that seems annoying. |
| 1645 | // That means the constructor has to be in DidPush. |
| 1646 | // So I have to validate the plan AFTER pushing it, and then take it off again... |
| 1647 | if (!thread_plan_sp->ValidatePlan(nullptr)) |
| 1648 | { |
| 1649 | DiscardThreadPlansUpToPlan(thread_plan_sp); |
| 1650 | return ThreadPlanSP(); |
| 1651 | } |
| 1652 | else |
| 1653 | return thread_plan_sp; |
| 1654 | |
| 1655 | } |
| 1656 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1657 | uint32_t |
| 1658 | Thread::GetIndexID () const |
| 1659 | { |
| 1660 | return m_index_id; |
| 1661 | } |
| 1662 | |
Jim Ingham | 2bdbfd5 | 2014-09-29 23:17:18 +0000 | [diff] [blame] | 1663 | static void |
| 1664 | PrintPlanElement (Stream *s, const ThreadPlanSP &plan, lldb::DescriptionLevel desc_level, int32_t elem_idx) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1665 | { |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1666 | s->IndentMore(); |
Jim Ingham | 10c4b24 | 2011-10-15 00:23:43 +0000 | [diff] [blame] | 1667 | s->Indent(); |
Jim Ingham | 2bdbfd5 | 2014-09-29 23:17:18 +0000 | [diff] [blame] | 1668 | s->Printf ("Element %d: ", elem_idx); |
| 1669 | plan->GetDescription (s, desc_level); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1670 | s->EOL(); |
Jim Ingham | 10c4b24 | 2011-10-15 00:23:43 +0000 | [diff] [blame] | 1671 | s->IndentLess(); |
Jim Ingham | 2bdbfd5 | 2014-09-29 23:17:18 +0000 | [diff] [blame] | 1672 | } |
| 1673 | |
| 1674 | static void |
| 1675 | PrintPlanStack (Stream *s, const std::vector<lldb::ThreadPlanSP> &plan_stack, lldb::DescriptionLevel desc_level, bool include_internal) |
| 1676 | { |
| 1677 | int32_t print_idx = 0; |
| 1678 | for (ThreadPlanSP plan_sp : plan_stack) |
| 1679 | { |
| 1680 | if (include_internal || !plan_sp->GetPrivate()) |
| 1681 | { |
| 1682 | PrintPlanElement (s, plan_sp, desc_level, print_idx++); |
| 1683 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1684 | } |
Jim Ingham | 2bdbfd5 | 2014-09-29 23:17:18 +0000 | [diff] [blame] | 1685 | } |
| 1686 | |
| 1687 | void |
| 1688 | Thread::DumpThreadPlans (Stream *s, |
| 1689 | lldb::DescriptionLevel desc_level, |
| 1690 | bool include_internal, |
| 1691 | bool ignore_boring_threads) const |
| 1692 | { |
| 1693 | uint32_t stack_size = m_plan_stack.size(); |
| 1694 | |
| 1695 | if (ignore_boring_threads) |
| 1696 | { |
| 1697 | uint32_t stack_size = m_plan_stack.size(); |
| 1698 | uint32_t completed_stack_size = m_completed_plan_stack.size(); |
| 1699 | uint32_t discarded_stack_size = m_discarded_plan_stack.size(); |
| 1700 | if (stack_size == 1 && completed_stack_size == 0 && discarded_stack_size == 0) |
| 1701 | { |
| 1702 | s->Printf ("thread #%u: tid = 0x%4.4" PRIx64 "\n", GetIndexID(), GetID()); |
| 1703 | s->IndentMore(); |
| 1704 | s->Indent(); |
| 1705 | s->Printf("No active thread plans\n"); |
| 1706 | s->IndentLess(); |
| 1707 | return; |
| 1708 | } |
| 1709 | } |
| 1710 | |
| 1711 | s->Indent(); |
| 1712 | s->Printf ("thread #%u: tid = 0x%4.4" PRIx64 ":\n", GetIndexID(), GetID()); |
| 1713 | s->IndentMore(); |
| 1714 | s->Indent(); |
| 1715 | s->Printf ("Active plan stack:\n"); |
| 1716 | PrintPlanStack (s, m_plan_stack, desc_level, include_internal); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1717 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1718 | stack_size = m_completed_plan_stack.size(); |
Jim Ingham | 10c4b24 | 2011-10-15 00:23:43 +0000 | [diff] [blame] | 1719 | if (stack_size > 0) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1720 | { |
Jim Ingham | 10c4b24 | 2011-10-15 00:23:43 +0000 | [diff] [blame] | 1721 | s->Indent(); |
Jim Ingham | 2bdbfd5 | 2014-09-29 23:17:18 +0000 | [diff] [blame] | 1722 | s->Printf ("Completed Plan Stack:\n"); |
| 1723 | PrintPlanStack (s, m_completed_plan_stack, desc_level, include_internal); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1724 | } |
| 1725 | |
| 1726 | stack_size = m_discarded_plan_stack.size(); |
Jim Ingham | 10c4b24 | 2011-10-15 00:23:43 +0000 | [diff] [blame] | 1727 | if (stack_size > 0) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1728 | { |
Jim Ingham | 10c4b24 | 2011-10-15 00:23:43 +0000 | [diff] [blame] | 1729 | s->Indent(); |
Jim Ingham | 2bdbfd5 | 2014-09-29 23:17:18 +0000 | [diff] [blame] | 1730 | s->Printf ("Discarded Plan Stack:\n"); |
| 1731 | PrintPlanStack (s, m_discarded_plan_stack, desc_level, include_internal); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1732 | } |
| 1733 | |
Jim Ingham | 2bdbfd5 | 2014-09-29 23:17:18 +0000 | [diff] [blame] | 1734 | s->IndentLess(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1735 | } |
| 1736 | |
Greg Clayton | d9e416c | 2012-02-18 05:35:26 +0000 | [diff] [blame] | 1737 | TargetSP |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1738 | Thread::CalculateTarget () |
| 1739 | { |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 1740 | TargetSP target_sp; |
| 1741 | ProcessSP process_sp(GetProcess()); |
| 1742 | if (process_sp) |
| 1743 | target_sp = process_sp->CalculateTarget(); |
| 1744 | return target_sp; |
| 1745 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1746 | } |
| 1747 | |
Greg Clayton | d9e416c | 2012-02-18 05:35:26 +0000 | [diff] [blame] | 1748 | ProcessSP |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1749 | Thread::CalculateProcess () |
| 1750 | { |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 1751 | return GetProcess(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1752 | } |
| 1753 | |
Greg Clayton | d9e416c | 2012-02-18 05:35:26 +0000 | [diff] [blame] | 1754 | ThreadSP |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1755 | Thread::CalculateThread () |
| 1756 | { |
Greg Clayton | d9e416c | 2012-02-18 05:35:26 +0000 | [diff] [blame] | 1757 | return shared_from_this(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1758 | } |
| 1759 | |
Jason Molenda | b57e4a1 | 2013-11-04 09:33:30 +0000 | [diff] [blame] | 1760 | StackFrameSP |
| 1761 | Thread::CalculateStackFrame () |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1762 | { |
Jason Molenda | b57e4a1 | 2013-11-04 09:33:30 +0000 | [diff] [blame] | 1763 | return StackFrameSP(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1764 | } |
| 1765 | |
| 1766 | void |
Greg Clayton | 0603aa9 | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 1767 | Thread::CalculateExecutionContext (ExecutionContext &exe_ctx) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1768 | { |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 1769 | exe_ctx.SetContext (shared_from_this()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1770 | } |
| 1771 | |
Greg Clayton | 12daf946 | 2010-08-25 00:35:26 +0000 | [diff] [blame] | 1772 | |
Greg Clayton | 39d0ab3 | 2012-03-29 01:41:38 +0000 | [diff] [blame] | 1773 | StackFrameListSP |
Greg Clayton | 12daf946 | 2010-08-25 00:35:26 +0000 | [diff] [blame] | 1774 | Thread::GetStackFrameList () |
| 1775 | { |
Greg Clayton | 39d0ab3 | 2012-03-29 01:41:38 +0000 | [diff] [blame] | 1776 | StackFrameListSP frame_list_sp; |
| 1777 | Mutex::Locker locker(m_frame_mutex); |
| 1778 | if (m_curr_frames_sp) |
| 1779 | { |
| 1780 | frame_list_sp = m_curr_frames_sp; |
| 1781 | } |
| 1782 | else |
| 1783 | { |
| 1784 | frame_list_sp.reset(new StackFrameList (*this, m_prev_frames_sp, true)); |
| 1785 | m_curr_frames_sp = frame_list_sp; |
| 1786 | } |
| 1787 | return frame_list_sp; |
Greg Clayton | 12daf946 | 2010-08-25 00:35:26 +0000 | [diff] [blame] | 1788 | } |
| 1789 | |
Greg Clayton | 12daf946 | 2010-08-25 00:35:26 +0000 | [diff] [blame] | 1790 | void |
| 1791 | Thread::ClearStackFrames () |
| 1792 | { |
Greg Clayton | 39d0ab3 | 2012-03-29 01:41:38 +0000 | [diff] [blame] | 1793 | Mutex::Locker locker(m_frame_mutex); |
| 1794 | |
Greg Clayton | 160c9d8 | 2013-05-01 21:54:04 +0000 | [diff] [blame] | 1795 | Unwind *unwinder = GetUnwinder (); |
| 1796 | if (unwinder) |
| 1797 | unwinder->Clear(); |
| 1798 | |
Jim Ingham | b0c72a5 | 2012-02-29 03:40:22 +0000 | [diff] [blame] | 1799 | // Only store away the old "reference" StackFrameList if we got all its frames: |
| 1800 | // FIXME: At some point we can try to splice in the frames we have fetched into |
| 1801 | // the new frame as we make it, but let's not try that now. |
| 1802 | if (m_curr_frames_sp && m_curr_frames_sp->GetAllFramesFetched()) |
Greg Clayton | 7e9b1fd | 2011-08-12 21:40:01 +0000 | [diff] [blame] | 1803 | m_prev_frames_sp.swap (m_curr_frames_sp); |
| 1804 | m_curr_frames_sp.reset(); |
Jason Molenda | 705b180 | 2014-06-13 02:37:02 +0000 | [diff] [blame] | 1805 | |
| 1806 | m_extended_info.reset(); |
| 1807 | m_extended_info_fetched = false; |
Jim Ingham | 87c1191 | 2010-08-12 02:14:28 +0000 | [diff] [blame] | 1808 | } |
| 1809 | |
Jason Molenda | b57e4a1 | 2013-11-04 09:33:30 +0000 | [diff] [blame] | 1810 | lldb::StackFrameSP |
Greg Clayton | 5ccbd29 | 2011-01-06 22:15:06 +0000 | [diff] [blame] | 1811 | Thread::GetFrameWithConcreteFrameIndex (uint32_t unwind_idx) |
| 1812 | { |
Greg Clayton | 39d0ab3 | 2012-03-29 01:41:38 +0000 | [diff] [blame] | 1813 | return GetStackFrameList()->GetFrameWithConcreteFrameIndex (unwind_idx); |
Greg Clayton | 5ccbd29 | 2011-01-06 22:15:06 +0000 | [diff] [blame] | 1814 | } |
| 1815 | |
Jim Ingham | 4413758 | 2012-09-12 00:40:39 +0000 | [diff] [blame] | 1816 | |
| 1817 | Error |
Jim Ingham | 4f465cf | 2012-10-10 18:32:14 +0000 | [diff] [blame] | 1818 | 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] | 1819 | { |
Jason Molenda | b57e4a1 | 2013-11-04 09:33:30 +0000 | [diff] [blame] | 1820 | StackFrameSP frame_sp = GetStackFrameAtIndex (frame_idx); |
Jim Ingham | 4413758 | 2012-09-12 00:40:39 +0000 | [diff] [blame] | 1821 | Error return_error; |
| 1822 | |
| 1823 | if (!frame_sp) |
| 1824 | { |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 1825 | 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] | 1826 | } |
| 1827 | |
Jim Ingham | 4f465cf | 2012-10-10 18:32:14 +0000 | [diff] [blame] | 1828 | return ReturnFromFrame(frame_sp, return_value_sp, broadcast); |
Jim Ingham | 4413758 | 2012-09-12 00:40:39 +0000 | [diff] [blame] | 1829 | } |
| 1830 | |
| 1831 | Error |
Jason Molenda | b57e4a1 | 2013-11-04 09:33:30 +0000 | [diff] [blame] | 1832 | 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] | 1833 | { |
| 1834 | Error return_error; |
| 1835 | |
| 1836 | if (!frame_sp) |
| 1837 | { |
| 1838 | return_error.SetErrorString("Can't return to a null frame."); |
| 1839 | return return_error; |
| 1840 | } |
| 1841 | |
| 1842 | Thread *thread = frame_sp->GetThread().get(); |
Jim Ingham | cb640dd | 2012-09-14 02:14:15 +0000 | [diff] [blame] | 1843 | uint32_t older_frame_idx = frame_sp->GetFrameIndex() + 1; |
Jason Molenda | b57e4a1 | 2013-11-04 09:33:30 +0000 | [diff] [blame] | 1844 | StackFrameSP older_frame_sp = thread->GetStackFrameAtIndex(older_frame_idx); |
Jim Ingham | 93208b8 | 2013-01-31 21:46:01 +0000 | [diff] [blame] | 1845 | if (!older_frame_sp) |
| 1846 | { |
| 1847 | return_error.SetErrorString("No older frame to return to."); |
| 1848 | return return_error; |
| 1849 | } |
Jim Ingham | 4413758 | 2012-09-12 00:40:39 +0000 | [diff] [blame] | 1850 | |
| 1851 | if (return_value_sp) |
Jim Ingham | 1f51e60 | 2012-09-27 01:15:29 +0000 | [diff] [blame] | 1852 | { |
Jim Ingham | 4413758 | 2012-09-12 00:40:39 +0000 | [diff] [blame] | 1853 | lldb::ABISP abi = thread->GetProcess()->GetABI(); |
| 1854 | if (!abi) |
| 1855 | { |
| 1856 | return_error.SetErrorString("Could not find ABI to set return value."); |
Jim Ingham | 28eb571 | 2012-10-12 17:34:26 +0000 | [diff] [blame] | 1857 | return return_error; |
Jim Ingham | 4413758 | 2012-09-12 00:40:39 +0000 | [diff] [blame] | 1858 | } |
Jim Ingham | 1f51e60 | 2012-09-27 01:15:29 +0000 | [diff] [blame] | 1859 | SymbolContext sc = frame_sp->GetSymbolContext(eSymbolContextFunction); |
| 1860 | |
| 1861 | // FIXME: ValueObject::Cast doesn't currently work correctly, at least not for scalars. |
| 1862 | // Turn that back on when that works. |
| 1863 | if (0 && sc.function != NULL) |
| 1864 | { |
| 1865 | Type *function_type = sc.function->GetType(); |
| 1866 | if (function_type) |
| 1867 | { |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1868 | ClangASTType return_type = sc.function->GetClangType().GetFunctionReturnType(); |
Jim Ingham | 1f51e60 | 2012-09-27 01:15:29 +0000 | [diff] [blame] | 1869 | if (return_type) |
| 1870 | { |
Jim Ingham | 1f51e60 | 2012-09-27 01:15:29 +0000 | [diff] [blame] | 1871 | StreamString s; |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1872 | return_type.DumpTypeDescription(&s); |
| 1873 | ValueObjectSP cast_value_sp = return_value_sp->Cast(return_type); |
Jim Ingham | 1f51e60 | 2012-09-27 01:15:29 +0000 | [diff] [blame] | 1874 | if (cast_value_sp) |
| 1875 | { |
| 1876 | cast_value_sp->SetFormat(eFormatHex); |
| 1877 | return_value_sp = cast_value_sp; |
| 1878 | } |
| 1879 | } |
| 1880 | } |
| 1881 | } |
| 1882 | |
Jim Ingham | cb640dd | 2012-09-14 02:14:15 +0000 | [diff] [blame] | 1883 | return_error = abi->SetReturnValueObject(older_frame_sp, return_value_sp); |
Jim Ingham | 4413758 | 2012-09-12 00:40:39 +0000 | [diff] [blame] | 1884 | if (!return_error.Success()) |
| 1885 | return return_error; |
| 1886 | } |
| 1887 | |
| 1888 | // Now write the return registers for the chosen frame: |
Jim Ingham | cb640dd | 2012-09-14 02:14:15 +0000 | [diff] [blame] | 1889 | // Note, we can't use ReadAllRegisterValues->WriteAllRegisterValues, since the read & write |
Jim Ingham | 93208b8 | 2013-01-31 21:46:01 +0000 | [diff] [blame] | 1890 | // cook their data |
| 1891 | |
Jason Molenda | b57e4a1 | 2013-11-04 09:33:30 +0000 | [diff] [blame] | 1892 | StackFrameSP youngest_frame_sp = thread->GetStackFrameAtIndex(0); |
Jim Ingham | 93208b8 | 2013-01-31 21:46:01 +0000 | [diff] [blame] | 1893 | if (youngest_frame_sp) |
Jim Ingham | 4413758 | 2012-09-12 00:40:39 +0000 | [diff] [blame] | 1894 | { |
Greg Clayton | 1afa68e | 2013-04-02 20:32:37 +0000 | [diff] [blame] | 1895 | lldb::RegisterContextSP reg_ctx_sp (youngest_frame_sp->GetRegisterContext()); |
| 1896 | if (reg_ctx_sp) |
Jim Ingham | 93208b8 | 2013-01-31 21:46:01 +0000 | [diff] [blame] | 1897 | { |
Greg Clayton | 1afa68e | 2013-04-02 20:32:37 +0000 | [diff] [blame] | 1898 | bool copy_success = reg_ctx_sp->CopyFromRegisterContext(older_frame_sp->GetRegisterContext()); |
| 1899 | if (copy_success) |
| 1900 | { |
| 1901 | thread->DiscardThreadPlans(true); |
| 1902 | thread->ClearStackFrames(); |
| 1903 | if (broadcast && EventTypeHasListeners(eBroadcastBitStackChanged)) |
| 1904 | BroadcastEvent(eBroadcastBitStackChanged, new ThreadEventData (this->shared_from_this())); |
| 1905 | } |
| 1906 | else |
| 1907 | { |
| 1908 | return_error.SetErrorString("Could not reset register values."); |
| 1909 | } |
Jim Ingham | 93208b8 | 2013-01-31 21:46:01 +0000 | [diff] [blame] | 1910 | } |
| 1911 | else |
| 1912 | { |
Greg Clayton | 1afa68e | 2013-04-02 20:32:37 +0000 | [diff] [blame] | 1913 | return_error.SetErrorString("Frame has no register context."); |
Jim Ingham | 93208b8 | 2013-01-31 21:46:01 +0000 | [diff] [blame] | 1914 | } |
Jim Ingham | 4413758 | 2012-09-12 00:40:39 +0000 | [diff] [blame] | 1915 | } |
| 1916 | else |
| 1917 | { |
Jim Ingham | 93208b8 | 2013-01-31 21:46:01 +0000 | [diff] [blame] | 1918 | return_error.SetErrorString("Returned past top frame."); |
Jim Ingham | 4413758 | 2012-09-12 00:40:39 +0000 | [diff] [blame] | 1919 | } |
Greg Clayton | abb487f | 2013-02-01 02:52:31 +0000 | [diff] [blame] | 1920 | return return_error; |
Jim Ingham | 4413758 | 2012-09-12 00:40:39 +0000 | [diff] [blame] | 1921 | } |
| 1922 | |
Richard Mitton | f86248d | 2013-09-12 02:20:34 +0000 | [diff] [blame] | 1923 | static void DumpAddressList (Stream &s, const std::vector<Address> &list, ExecutionContextScope *exe_scope) |
| 1924 | { |
| 1925 | for (size_t n=0;n<list.size();n++) |
| 1926 | { |
| 1927 | s << "\t"; |
| 1928 | list[n].Dump (&s, exe_scope, Address::DumpStyleResolvedDescription, Address::DumpStyleSectionNameOffset); |
| 1929 | s << "\n"; |
| 1930 | } |
| 1931 | } |
| 1932 | |
| 1933 | Error |
| 1934 | Thread::JumpToLine (const FileSpec &file, uint32_t line, bool can_leave_function, std::string *warnings) |
| 1935 | { |
| 1936 | ExecutionContext exe_ctx (GetStackFrameAtIndex(0)); |
| 1937 | Target *target = exe_ctx.GetTargetPtr(); |
| 1938 | TargetSP target_sp = exe_ctx.GetTargetSP(); |
| 1939 | RegisterContext *reg_ctx = exe_ctx.GetRegisterContext(); |
Jason Molenda | b57e4a1 | 2013-11-04 09:33:30 +0000 | [diff] [blame] | 1940 | StackFrame *frame = exe_ctx.GetFramePtr(); |
Richard Mitton | f86248d | 2013-09-12 02:20:34 +0000 | [diff] [blame] | 1941 | const SymbolContext &sc = frame->GetSymbolContext(eSymbolContextFunction); |
| 1942 | |
| 1943 | // Find candidate locations. |
| 1944 | std::vector<Address> candidates, within_function, outside_function; |
| 1945 | target->GetImages().FindAddressesForLine (target_sp, file, line, sc.function, within_function, outside_function); |
| 1946 | |
| 1947 | // If possible, we try and stay within the current function. |
| 1948 | // Within a function, we accept multiple locations (optimized code may do this, |
| 1949 | // there's no solution here so we do the best we can). |
| 1950 | // However if we're trying to leave the function, we don't know how to pick the |
| 1951 | // right location, so if there's more than one then we bail. |
| 1952 | if (!within_function.empty()) |
| 1953 | candidates = within_function; |
| 1954 | else if (outside_function.size() == 1 && can_leave_function) |
| 1955 | candidates = outside_function; |
| 1956 | |
| 1957 | // Check if we got anything. |
| 1958 | if (candidates.empty()) |
| 1959 | { |
| 1960 | if (outside_function.empty()) |
| 1961 | { |
| 1962 | return Error("Cannot locate an address for %s:%i.", |
| 1963 | file.GetFilename().AsCString(), line); |
| 1964 | } |
| 1965 | else if (outside_function.size() == 1) |
| 1966 | { |
| 1967 | return Error("%s:%i is outside the current function.", |
| 1968 | file.GetFilename().AsCString(), line); |
| 1969 | } |
| 1970 | else |
| 1971 | { |
| 1972 | StreamString sstr; |
| 1973 | DumpAddressList(sstr, outside_function, target); |
| 1974 | return Error("%s:%i has multiple candidate locations:\n%s", |
| 1975 | file.GetFilename().AsCString(), line, sstr.GetString().c_str()); |
| 1976 | } |
| 1977 | } |
| 1978 | |
| 1979 | // Accept the first location, warn about any others. |
| 1980 | Address dest = candidates[0]; |
| 1981 | if (warnings && candidates.size() > 1) |
| 1982 | { |
| 1983 | StreamString sstr; |
| 1984 | sstr.Printf("%s:%i appears multiple times in this function, selecting the first location:\n", |
| 1985 | file.GetFilename().AsCString(), line); |
| 1986 | DumpAddressList(sstr, candidates, target); |
| 1987 | *warnings = sstr.GetString(); |
| 1988 | } |
| 1989 | |
| 1990 | if (!reg_ctx->SetPC (dest)) |
| 1991 | return Error("Cannot change PC to target address."); |
| 1992 | |
| 1993 | return Error(); |
| 1994 | } |
| 1995 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1996 | void |
Greg Clayton | 0603aa9 | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 1997 | Thread::DumpUsingSettingsFormat (Stream &strm, uint32_t frame_idx) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1998 | { |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 1999 | ExecutionContext exe_ctx (shared_from_this()); |
| 2000 | Process *process = exe_ctx.GetProcessPtr(); |
| 2001 | if (process == NULL) |
| 2002 | return; |
| 2003 | |
Jason Molenda | b57e4a1 | 2013-11-04 09:33:30 +0000 | [diff] [blame] | 2004 | StackFrameSP frame_sp; |
Greg Clayton | 0603aa9 | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 2005 | SymbolContext frame_sc; |
Greg Clayton | 0603aa9 | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 2006 | if (frame_idx != LLDB_INVALID_INDEX32) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2007 | { |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 2008 | frame_sp = GetStackFrameAtIndex (frame_idx); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2009 | if (frame_sp) |
| 2010 | { |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 2011 | exe_ctx.SetFrameSP(frame_sp); |
| 2012 | frame_sc = frame_sp->GetSymbolContext(eSymbolContextEverything); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2013 | } |
| 2014 | } |
| 2015 | |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 2016 | const char *thread_format = exe_ctx.GetTargetRef().GetDebugger().GetThreadFormat(); |
Greg Clayton | 0603aa9 | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 2017 | assert (thread_format); |
Greg Clayton | 0603aa9 | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 2018 | Debugger::FormatPrompt (thread_format, |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 2019 | frame_sp ? &frame_sc : NULL, |
Greg Clayton | 0603aa9 | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 2020 | &exe_ctx, |
| 2021 | NULL, |
Michael Sartain | c3ce7f27 | 2013-05-23 20:47:45 +0000 | [diff] [blame] | 2022 | strm); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2023 | } |
| 2024 | |
Greg Clayton | 99d0faf | 2010-11-18 23:32:35 +0000 | [diff] [blame] | 2025 | void |
Caroline Tice | 20bd37f | 2011-03-10 22:14:10 +0000 | [diff] [blame] | 2026 | Thread::SettingsInitialize () |
Jim Ingham | ee8aea1 | 2010-09-08 03:14:33 +0000 | [diff] [blame] | 2027 | { |
Greg Clayton | 99d0faf | 2010-11-18 23:32:35 +0000 | [diff] [blame] | 2028 | } |
Jim Ingham | ee8aea1 | 2010-09-08 03:14:33 +0000 | [diff] [blame] | 2029 | |
Greg Clayton | 99d0faf | 2010-11-18 23:32:35 +0000 | [diff] [blame] | 2030 | void |
Caroline Tice | 20bd37f | 2011-03-10 22:14:10 +0000 | [diff] [blame] | 2031 | Thread::SettingsTerminate () |
Greg Clayton | 99d0faf | 2010-11-18 23:32:35 +0000 | [diff] [blame] | 2032 | { |
Greg Clayton | 99d0faf | 2010-11-18 23:32:35 +0000 | [diff] [blame] | 2033 | } |
Jim Ingham | ee8aea1 | 2010-09-08 03:14:33 +0000 | [diff] [blame] | 2034 | |
Richard Mitton | 0a55835 | 2013-10-17 21:14:00 +0000 | [diff] [blame] | 2035 | lldb::addr_t |
| 2036 | Thread::GetThreadPointer () |
| 2037 | { |
| 2038 | return LLDB_INVALID_ADDRESS; |
| 2039 | } |
| 2040 | |
| 2041 | addr_t |
| 2042 | Thread::GetThreadLocalData (const ModuleSP module) |
| 2043 | { |
| 2044 | // The default implementation is to ask the dynamic loader for it. |
| 2045 | // This can be overridden for specific platforms. |
| 2046 | DynamicLoader *loader = GetProcess()->GetDynamicLoader(); |
| 2047 | if (loader) |
| 2048 | return loader->GetThreadLocalData (module, shared_from_this()); |
| 2049 | else |
| 2050 | return LLDB_INVALID_ADDRESS; |
| 2051 | } |
| 2052 | |
Jason Molenda | b4892cd | 2014-05-13 22:02:48 +0000 | [diff] [blame] | 2053 | bool |
| 2054 | Thread::SafeToCallFunctions () |
| 2055 | { |
| 2056 | Process *process = GetProcess().get(); |
| 2057 | if (process) |
| 2058 | { |
| 2059 | SystemRuntime *runtime = process->GetSystemRuntime (); |
| 2060 | if (runtime) |
| 2061 | { |
| 2062 | return runtime->SafeToCallFunctionsOnThisThread (shared_from_this()); |
| 2063 | } |
| 2064 | } |
| 2065 | return true; |
| 2066 | } |
| 2067 | |
Jason Molenda | b57e4a1 | 2013-11-04 09:33:30 +0000 | [diff] [blame] | 2068 | lldb::StackFrameSP |
| 2069 | Thread::GetStackFrameSPForStackFramePtr (StackFrame *stack_frame_ptr) |
Jim Ingham | e4284b7 | 2010-09-23 17:40:12 +0000 | [diff] [blame] | 2070 | { |
Jason Molenda | b57e4a1 | 2013-11-04 09:33:30 +0000 | [diff] [blame] | 2071 | return GetStackFrameList()->GetStackFrameSPForStackFramePtr (stack_frame_ptr); |
Jim Ingham | e4284b7 | 2010-09-23 17:40:12 +0000 | [diff] [blame] | 2072 | } |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 2073 | |
| 2074 | const char * |
| 2075 | Thread::StopReasonAsCString (lldb::StopReason reason) |
| 2076 | { |
| 2077 | switch (reason) |
| 2078 | { |
Andrew Kaylor | f85defa | 2012-12-20 23:08:03 +0000 | [diff] [blame] | 2079 | case eStopReasonInvalid: return "invalid"; |
| 2080 | case eStopReasonNone: return "none"; |
| 2081 | case eStopReasonTrace: return "trace"; |
| 2082 | case eStopReasonBreakpoint: return "breakpoint"; |
| 2083 | case eStopReasonWatchpoint: return "watchpoint"; |
| 2084 | case eStopReasonSignal: return "signal"; |
| 2085 | case eStopReasonException: return "exception"; |
| 2086 | case eStopReasonExec: return "exec"; |
| 2087 | case eStopReasonPlanComplete: return "plan complete"; |
| 2088 | case eStopReasonThreadExiting: return "thread exiting"; |
Kuba Brecka | afdf842 | 2014-10-10 23:43:03 +0000 | [diff] [blame] | 2089 | case eStopReasonInstrumentation: return "instrumentation break"; |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 2090 | } |
| 2091 | |
| 2092 | |
| 2093 | static char unknown_state_string[64]; |
| 2094 | snprintf(unknown_state_string, sizeof (unknown_state_string), "StopReason = %i", reason); |
| 2095 | return unknown_state_string; |
| 2096 | } |
| 2097 | |
| 2098 | const char * |
| 2099 | Thread::RunModeAsCString (lldb::RunMode mode) |
| 2100 | { |
| 2101 | switch (mode) |
| 2102 | { |
| 2103 | case eOnlyThisThread: return "only this thread"; |
| 2104 | case eAllThreads: return "all threads"; |
| 2105 | case eOnlyDuringStepping: return "only during stepping"; |
| 2106 | } |
| 2107 | |
| 2108 | static char unknown_state_string[64]; |
| 2109 | snprintf(unknown_state_string, sizeof (unknown_state_string), "RunMode = %i", mode); |
| 2110 | return unknown_state_string; |
| 2111 | } |
Jim Ingham | 06e827c | 2010-11-11 19:26:09 +0000 | [diff] [blame] | 2112 | |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 2113 | size_t |
| 2114 | Thread::GetStatus (Stream &strm, uint32_t start_frame, uint32_t num_frames, uint32_t num_frames_with_source) |
| 2115 | { |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 2116 | ExecutionContext exe_ctx (shared_from_this()); |
| 2117 | Target *target = exe_ctx.GetTargetPtr(); |
| 2118 | Process *process = exe_ctx.GetProcessPtr(); |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 2119 | size_t num_frames_shown = 0; |
| 2120 | strm.Indent(); |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 2121 | bool is_selected = false; |
| 2122 | if (process) |
| 2123 | { |
| 2124 | if (process->GetThreadList().GetSelectedThread().get() == this) |
| 2125 | is_selected = true; |
| 2126 | } |
| 2127 | strm.Printf("%c ", is_selected ? '*' : ' '); |
| 2128 | if (target && target->GetDebugger().GetUseExternalEditor()) |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 2129 | { |
Jason Molenda | b57e4a1 | 2013-11-04 09:33:30 +0000 | [diff] [blame] | 2130 | StackFrameSP frame_sp = GetStackFrameAtIndex(start_frame); |
Jim Ingham | e610d64 | 2011-08-16 00:07:28 +0000 | [diff] [blame] | 2131 | if (frame_sp) |
Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 2132 | { |
Jim Ingham | e610d64 | 2011-08-16 00:07:28 +0000 | [diff] [blame] | 2133 | SymbolContext frame_sc(frame_sp->GetSymbolContext (eSymbolContextLineEntry)); |
| 2134 | if (frame_sc.line_entry.line != 0 && frame_sc.line_entry.file) |
| 2135 | { |
| 2136 | Host::OpenFileInExternalEditor (frame_sc.line_entry.file, frame_sc.line_entry.line); |
| 2137 | } |
Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 2138 | } |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 2139 | } |
| 2140 | |
| 2141 | DumpUsingSettingsFormat (strm, start_frame); |
| 2142 | |
| 2143 | if (num_frames > 0) |
| 2144 | { |
| 2145 | strm.IndentMore(); |
| 2146 | |
| 2147 | const bool show_frame_info = true; |
Jim Ingham | 8ec10ef | 2013-10-18 17:38:31 +0000 | [diff] [blame] | 2148 | |
| 2149 | const char *selected_frame_marker = NULL; |
| 2150 | if (num_frames == 1 || (GetID() != GetProcess()->GetThreadList().GetSelectedThread()->GetID())) |
| 2151 | strm.IndentMore (); |
| 2152 | else |
| 2153 | selected_frame_marker = "* "; |
| 2154 | |
Greg Clayton | 39d0ab3 | 2012-03-29 01:41:38 +0000 | [diff] [blame] | 2155 | num_frames_shown = GetStackFrameList ()->GetStatus (strm, |
| 2156 | start_frame, |
| 2157 | num_frames, |
| 2158 | show_frame_info, |
Jim Ingham | 8ec10ef | 2013-10-18 17:38:31 +0000 | [diff] [blame] | 2159 | num_frames_with_source, |
| 2160 | selected_frame_marker); |
| 2161 | if (num_frames == 1) |
| 2162 | strm.IndentLess(); |
Jim Ingham | 5c4df7a | 2011-07-26 02:39:59 +0000 | [diff] [blame] | 2163 | strm.IndentLess(); |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 2164 | } |
| 2165 | return num_frames_shown; |
| 2166 | } |
| 2167 | |
Jason Molenda | 705b180 | 2014-06-13 02:37:02 +0000 | [diff] [blame] | 2168 | bool |
Kuba Brecka | afdf842 | 2014-10-10 23:43:03 +0000 | [diff] [blame] | 2169 | Thread::GetDescription (Stream &strm, lldb::DescriptionLevel level, bool print_json_thread, bool print_json_stopinfo) |
Jason Molenda | 705b180 | 2014-06-13 02:37:02 +0000 | [diff] [blame] | 2170 | { |
| 2171 | DumpUsingSettingsFormat (strm, 0); |
| 2172 | strm.Printf("\n"); |
| 2173 | |
| 2174 | StructuredData::ObjectSP thread_info = GetExtendedInfo(); |
Kuba Brecka | afdf842 | 2014-10-10 23:43:03 +0000 | [diff] [blame] | 2175 | StructuredData::ObjectSP stop_info = m_stop_info_sp->GetExtendedInfo(); |
| 2176 | |
| 2177 | if (print_json_thread || print_json_stopinfo) |
Jason Molenda | 705b180 | 2014-06-13 02:37:02 +0000 | [diff] [blame] | 2178 | { |
Kuba Brecka | afdf842 | 2014-10-10 23:43:03 +0000 | [diff] [blame] | 2179 | if (thread_info && print_json_thread) |
| 2180 | { |
| 2181 | thread_info->Dump (strm); |
| 2182 | strm.Printf("\n"); |
| 2183 | } |
| 2184 | |
| 2185 | if (stop_info && print_json_stopinfo) |
| 2186 | { |
| 2187 | stop_info->Dump (strm); |
| 2188 | strm.Printf("\n"); |
| 2189 | } |
| 2190 | |
Jason Molenda | 705b180 | 2014-06-13 02:37:02 +0000 | [diff] [blame] | 2191 | return true; |
| 2192 | } |
| 2193 | |
| 2194 | if (thread_info) |
| 2195 | { |
| 2196 | StructuredData::ObjectSP activity = thread_info->GetObjectForDotSeparatedPath("activity"); |
| 2197 | StructuredData::ObjectSP breadcrumb = thread_info->GetObjectForDotSeparatedPath("breadcrumb"); |
| 2198 | StructuredData::ObjectSP messages = thread_info->GetObjectForDotSeparatedPath("trace_messages"); |
| 2199 | |
| 2200 | bool printed_activity = false; |
| 2201 | if (activity && activity->GetType() == StructuredData::Type::eTypeDictionary) |
| 2202 | { |
| 2203 | StructuredData::Dictionary *activity_dict = activity->GetAsDictionary(); |
| 2204 | StructuredData::ObjectSP id = activity_dict->GetValueForKey("id"); |
| 2205 | StructuredData::ObjectSP name = activity_dict->GetValueForKey("name"); |
| 2206 | if (name && name->GetType() == StructuredData::Type::eTypeString |
| 2207 | && id && id->GetType() == StructuredData::Type::eTypeInteger) |
| 2208 | { |
| 2209 | strm.Printf(" Activity '%s', 0x%" PRIx64 "\n", name->GetAsString()->GetValue().c_str(), id->GetAsInteger()->GetValue()); |
| 2210 | } |
| 2211 | printed_activity = true; |
| 2212 | } |
| 2213 | bool printed_breadcrumb = false; |
| 2214 | if (breadcrumb && breadcrumb->GetType() == StructuredData::Type::eTypeDictionary) |
| 2215 | { |
| 2216 | if (printed_activity) |
| 2217 | strm.Printf ("\n"); |
| 2218 | StructuredData::Dictionary *breadcrumb_dict = breadcrumb->GetAsDictionary(); |
| 2219 | StructuredData::ObjectSP breadcrumb_text = breadcrumb_dict->GetValueForKey ("name"); |
| 2220 | if (breadcrumb_text && breadcrumb_text->GetType() == StructuredData::Type::eTypeString) |
| 2221 | { |
| 2222 | strm.Printf (" Current Breadcrumb: %s\n", breadcrumb_text->GetAsString()->GetValue().c_str()); |
| 2223 | } |
| 2224 | printed_breadcrumb = true; |
| 2225 | } |
| 2226 | if (messages && messages->GetType() == StructuredData::Type::eTypeArray) |
| 2227 | { |
| 2228 | if (printed_breadcrumb) |
| 2229 | strm.Printf("\n"); |
| 2230 | StructuredData::Array *messages_array = messages->GetAsArray(); |
| 2231 | const size_t msg_count = messages_array->GetSize(); |
| 2232 | if (msg_count > 0) |
| 2233 | { |
| 2234 | strm.Printf (" %zu trace messages:\n", msg_count); |
| 2235 | for (size_t i = 0; i < msg_count; i++) |
| 2236 | { |
| 2237 | StructuredData::ObjectSP message = messages_array->GetItemAtIndex(i); |
| 2238 | if (message && message->GetType() == StructuredData::Type::eTypeDictionary) |
| 2239 | { |
| 2240 | StructuredData::Dictionary *message_dict = message->GetAsDictionary(); |
| 2241 | StructuredData::ObjectSP message_text = message_dict->GetValueForKey ("message"); |
| 2242 | if (message_text && message_text->GetType() == StructuredData::Type::eTypeString) |
| 2243 | { |
| 2244 | strm.Printf (" %s\n", message_text->GetAsString()->GetValue().c_str()); |
| 2245 | } |
| 2246 | } |
| 2247 | } |
| 2248 | } |
| 2249 | } |
| 2250 | } |
| 2251 | |
| 2252 | return true; |
| 2253 | } |
| 2254 | |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 2255 | size_t |
| 2256 | Thread::GetStackFrameStatus (Stream& strm, |
| 2257 | uint32_t first_frame, |
| 2258 | uint32_t num_frames, |
| 2259 | bool show_frame_info, |
Greg Clayton | 53eb7ad | 2012-07-11 20:33:48 +0000 | [diff] [blame] | 2260 | uint32_t num_frames_with_source) |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 2261 | { |
Greg Clayton | 39d0ab3 | 2012-03-29 01:41:38 +0000 | [diff] [blame] | 2262 | return GetStackFrameList()->GetStatus (strm, |
| 2263 | first_frame, |
| 2264 | num_frames, |
| 2265 | show_frame_info, |
Greg Clayton | 53eb7ad | 2012-07-11 20:33:48 +0000 | [diff] [blame] | 2266 | num_frames_with_source); |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 2267 | } |
| 2268 | |
Greg Clayton | 56d9a1b | 2011-08-22 02:49:39 +0000 | [diff] [blame] | 2269 | Unwind * |
| 2270 | Thread::GetUnwinder () |
| 2271 | { |
| 2272 | if (m_unwinder_ap.get() == NULL) |
| 2273 | { |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 2274 | const ArchSpec target_arch (CalculateTarget()->GetArchitecture ()); |
Greg Clayton | 56d9a1b | 2011-08-22 02:49:39 +0000 | [diff] [blame] | 2275 | const llvm::Triple::ArchType machine = target_arch.GetMachine(); |
| 2276 | switch (machine) |
| 2277 | { |
| 2278 | case llvm::Triple::x86_64: |
| 2279 | case llvm::Triple::x86: |
| 2280 | case llvm::Triple::arm: |
Todd Fiala | d8eaa17 | 2014-07-23 14:37:35 +0000 | [diff] [blame] | 2281 | case llvm::Triple::aarch64: |
Greg Clayton | 56d9a1b | 2011-08-22 02:49:39 +0000 | [diff] [blame] | 2282 | case llvm::Triple::thumb: |
Ed Maste | b73f844 | 2013-10-10 00:59:47 +0000 | [diff] [blame] | 2283 | case llvm::Triple::mips64: |
Deepak Panickal | 6d3df42 | 2014-02-19 11:16:46 +0000 | [diff] [blame] | 2284 | case llvm::Triple::hexagon: |
Greg Clayton | 56d9a1b | 2011-08-22 02:49:39 +0000 | [diff] [blame] | 2285 | m_unwinder_ap.reset (new UnwindLLDB (*this)); |
| 2286 | break; |
| 2287 | |
| 2288 | default: |
| 2289 | if (target_arch.GetTriple().getVendor() == llvm::Triple::Apple) |
| 2290 | m_unwinder_ap.reset (new UnwindMacOSXFrameBackchain (*this)); |
| 2291 | break; |
| 2292 | } |
| 2293 | } |
| 2294 | return m_unwinder_ap.get(); |
| 2295 | } |
| 2296 | |
| 2297 | |
Greg Clayton | fa559e5 | 2012-05-18 02:38:05 +0000 | [diff] [blame] | 2298 | void |
| 2299 | Thread::Flush () |
| 2300 | { |
| 2301 | ClearStackFrames (); |
| 2302 | m_reg_context_sp.reset(); |
| 2303 | } |
Jim Ingham | 5d88a06 | 2012-10-16 00:09:33 +0000 | [diff] [blame] | 2304 | |
Filipe Cabecinhas | b3d5d71 | 2012-11-20 00:11:13 +0000 | [diff] [blame] | 2305 | bool |
Jim Ingham | 5d88a06 | 2012-10-16 00:09:33 +0000 | [diff] [blame] | 2306 | Thread::IsStillAtLastBreakpointHit () |
| 2307 | { |
| 2308 | // If we are currently stopped at a breakpoint, always return that stopinfo and don't reset it. |
| 2309 | // This allows threads to maintain their breakpoint stopinfo, such as when thread-stepping in |
| 2310 | // multithreaded programs. |
Greg Clayton | 6e0ff1a | 2013-05-09 01:55:29 +0000 | [diff] [blame] | 2311 | if (m_stop_info_sp) { |
| 2312 | StopReason stop_reason = m_stop_info_sp->GetStopReason(); |
Jim Ingham | 5d88a06 | 2012-10-16 00:09:33 +0000 | [diff] [blame] | 2313 | if (stop_reason == lldb::eStopReasonBreakpoint) { |
Greg Clayton | 6e0ff1a | 2013-05-09 01:55:29 +0000 | [diff] [blame] | 2314 | uint64_t value = m_stop_info_sp->GetValue(); |
Greg Clayton | 1afa68e | 2013-04-02 20:32:37 +0000 | [diff] [blame] | 2315 | lldb::RegisterContextSP reg_ctx_sp (GetRegisterContext()); |
| 2316 | if (reg_ctx_sp) |
| 2317 | { |
| 2318 | lldb::addr_t pc = reg_ctx_sp->GetPC(); |
| 2319 | BreakpointSiteSP bp_site_sp = GetProcess()->GetBreakpointSiteList().FindByAddress(pc); |
Saleem Abdulrasool | 3985c8c | 2014-04-02 03:51:35 +0000 | [diff] [blame] | 2320 | if (bp_site_sp && |
| 2321 | static_cast<break_id_t>(value) == bp_site_sp->GetID()) |
Greg Clayton | 1afa68e | 2013-04-02 20:32:37 +0000 | [diff] [blame] | 2322 | return true; |
| 2323 | } |
Jim Ingham | 5d88a06 | 2012-10-16 00:09:33 +0000 | [diff] [blame] | 2324 | } |
| 2325 | } |
| 2326 | return false; |
| 2327 | } |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 2328 | |
| 2329 | |
| 2330 | Error |
| 2331 | Thread::StepIn (bool source_step, |
Jim Ingham | 4b4b247 | 2014-03-13 02:47:14 +0000 | [diff] [blame] | 2332 | LazyBool step_in_avoids_code_without_debug_info, |
| 2333 | LazyBool step_out_avoids_code_without_debug_info) |
| 2334 | |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 2335 | { |
| 2336 | Error error; |
| 2337 | Process *process = GetProcess().get(); |
| 2338 | if (StateIsStoppedState (process->GetState(), true)) |
| 2339 | { |
| 2340 | StackFrameSP frame_sp = GetStackFrameAtIndex (0); |
| 2341 | ThreadPlanSP new_plan_sp; |
| 2342 | const lldb::RunMode run_mode = eOnlyThisThread; |
| 2343 | const bool abort_other_plans = false; |
| 2344 | |
| 2345 | if (source_step && frame_sp && frame_sp->HasDebugInformation ()) |
| 2346 | { |
| 2347 | SymbolContext sc(frame_sp->GetSymbolContext(eSymbolContextEverything)); |
| 2348 | new_plan_sp = QueueThreadPlanForStepInRange (abort_other_plans, |
| 2349 | sc.line_entry.range, |
| 2350 | sc, |
| 2351 | NULL, |
| 2352 | run_mode, |
Jim Ingham | 4b4b247 | 2014-03-13 02:47:14 +0000 | [diff] [blame] | 2353 | step_in_avoids_code_without_debug_info, |
| 2354 | step_out_avoids_code_without_debug_info); |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 2355 | } |
| 2356 | else |
| 2357 | { |
| 2358 | new_plan_sp = QueueThreadPlanForStepSingleInstruction (false, |
| 2359 | abort_other_plans, |
| 2360 | run_mode); |
| 2361 | } |
| 2362 | |
| 2363 | new_plan_sp->SetIsMasterPlan(true); |
| 2364 | new_plan_sp->SetOkayToDiscard(false); |
| 2365 | |
| 2366 | // Why do we need to set the current thread by ID here??? |
| 2367 | process->GetThreadList().SetSelectedThreadByID (GetID()); |
| 2368 | error = process->Resume(); |
| 2369 | } |
| 2370 | else |
| 2371 | { |
| 2372 | error.SetErrorString("process not stopped"); |
| 2373 | } |
| 2374 | return error; |
| 2375 | } |
| 2376 | |
| 2377 | Error |
Jim Ingham | 4b4b247 | 2014-03-13 02:47:14 +0000 | [diff] [blame] | 2378 | Thread::StepOver (bool source_step, |
| 2379 | LazyBool step_out_avoids_code_without_debug_info) |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 2380 | { |
| 2381 | Error error; |
| 2382 | Process *process = GetProcess().get(); |
| 2383 | if (StateIsStoppedState (process->GetState(), true)) |
| 2384 | { |
| 2385 | StackFrameSP frame_sp = GetStackFrameAtIndex (0); |
| 2386 | ThreadPlanSP new_plan_sp; |
| 2387 | |
| 2388 | const lldb::RunMode run_mode = eOnlyThisThread; |
| 2389 | const bool abort_other_plans = false; |
| 2390 | |
| 2391 | if (source_step && frame_sp && frame_sp->HasDebugInformation ()) |
| 2392 | { |
| 2393 | SymbolContext sc(frame_sp->GetSymbolContext(eSymbolContextEverything)); |
| 2394 | new_plan_sp = QueueThreadPlanForStepOverRange (abort_other_plans, |
| 2395 | sc.line_entry.range, |
| 2396 | sc, |
Jim Ingham | 4b4b247 | 2014-03-13 02:47:14 +0000 | [diff] [blame] | 2397 | run_mode, |
| 2398 | step_out_avoids_code_without_debug_info); |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 2399 | } |
| 2400 | else |
| 2401 | { |
| 2402 | new_plan_sp = QueueThreadPlanForStepSingleInstruction (true, |
| 2403 | abort_other_plans, |
| 2404 | run_mode); |
| 2405 | } |
| 2406 | |
| 2407 | new_plan_sp->SetIsMasterPlan(true); |
| 2408 | new_plan_sp->SetOkayToDiscard(false); |
| 2409 | |
| 2410 | // Why do we need to set the current thread by ID here??? |
| 2411 | process->GetThreadList().SetSelectedThreadByID (GetID()); |
| 2412 | error = process->Resume(); |
| 2413 | } |
| 2414 | else |
| 2415 | { |
| 2416 | error.SetErrorString("process not stopped"); |
| 2417 | } |
| 2418 | return error; |
| 2419 | } |
| 2420 | |
| 2421 | Error |
| 2422 | Thread::StepOut () |
| 2423 | { |
| 2424 | Error error; |
| 2425 | Process *process = GetProcess().get(); |
| 2426 | if (StateIsStoppedState (process->GetState(), true)) |
| 2427 | { |
| 2428 | const bool first_instruction = false; |
| 2429 | const bool stop_other_threads = false; |
| 2430 | const bool abort_other_plans = false; |
| 2431 | |
| 2432 | ThreadPlanSP new_plan_sp(QueueThreadPlanForStepOut (abort_other_plans, |
| 2433 | NULL, |
| 2434 | first_instruction, |
| 2435 | stop_other_threads, |
| 2436 | eVoteYes, |
| 2437 | eVoteNoOpinion, |
| 2438 | 0)); |
| 2439 | |
| 2440 | new_plan_sp->SetIsMasterPlan(true); |
| 2441 | new_plan_sp->SetOkayToDiscard(false); |
| 2442 | |
| 2443 | // Why do we need to set the current thread by ID here??? |
| 2444 | process->GetThreadList().SetSelectedThreadByID (GetID()); |
| 2445 | error = process->Resume(); |
| 2446 | } |
| 2447 | else |
| 2448 | { |
| 2449 | error.SetErrorString("process not stopped"); |
| 2450 | } |
| 2451 | return error; |
Jim Ingham | 4b4b247 | 2014-03-13 02:47:14 +0000 | [diff] [blame] | 2452 | } |