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