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