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 | |
| 10 | #include "lldb/lldb-private-log.h" |
Jim Ingham | 1b54c88 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 11 | #include "lldb/Breakpoint/BreakpointLocation.h" |
Greg Clayton | 0603aa9 | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 12 | #include "lldb/Core/Debugger.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 13 | #include "lldb/Core/Log.h" |
| 14 | #include "lldb/Core/Stream.h" |
| 15 | #include "lldb/Core/StreamString.h" |
Jim Ingham | ee8aea1 | 2010-09-08 03:14:33 +0000 | [diff] [blame] | 16 | #include "lldb/Core/RegularExpression.h" |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 17 | #include "lldb/Host/Host.h" |
Jim Ingham | 1f51e60 | 2012-09-27 01:15:29 +0000 | [diff] [blame] | 18 | #include "lldb/Symbol/Function.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 19 | #include "lldb/Target/DynamicLoader.h" |
| 20 | #include "lldb/Target/ExecutionContext.h" |
Jim Ingham | 5a36912 | 2010-09-28 01:25:32 +0000 | [diff] [blame] | 21 | #include "lldb/Target/ObjCLanguageRuntime.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 22 | #include "lldb/Target/Process.h" |
| 23 | #include "lldb/Target/RegisterContext.h" |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 24 | #include "lldb/Target/StopInfo.h" |
Greg Clayton | 896dff6 | 2010-07-23 16:45:51 +0000 | [diff] [blame] | 25 | #include "lldb/Target/Target.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 26 | #include "lldb/Target/Thread.h" |
| 27 | #include "lldb/Target/ThreadPlan.h" |
| 28 | #include "lldb/Target/ThreadPlanCallFunction.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 29 | #include "lldb/Target/ThreadPlanBase.h" |
| 30 | #include "lldb/Target/ThreadPlanStepInstruction.h" |
| 31 | #include "lldb/Target/ThreadPlanStepOut.h" |
| 32 | #include "lldb/Target/ThreadPlanStepOverBreakpoint.h" |
| 33 | #include "lldb/Target/ThreadPlanStepThrough.h" |
| 34 | #include "lldb/Target/ThreadPlanStepInRange.h" |
| 35 | #include "lldb/Target/ThreadPlanStepOverRange.h" |
| 36 | #include "lldb/Target/ThreadPlanRunToAddress.h" |
| 37 | #include "lldb/Target/ThreadPlanStepUntil.h" |
Jim Ingham | 1b54c88 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 38 | #include "lldb/Target/ThreadSpec.h" |
Jim Ingham | 87c1191 | 2010-08-12 02:14:28 +0000 | [diff] [blame] | 39 | #include "lldb/Target/Unwind.h" |
Greg Clayton | 56d9a1b | 2011-08-22 02:49:39 +0000 | [diff] [blame] | 40 | #include "Plugins/Process/Utility/UnwindLLDB.h" |
| 41 | #include "UnwindMacOSXFrameBackchain.h" |
| 42 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 43 | |
| 44 | using namespace lldb; |
| 45 | using namespace lldb_private; |
| 46 | |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 47 | |
| 48 | const ThreadPropertiesSP & |
| 49 | Thread::GetGlobalProperties() |
| 50 | { |
| 51 | static ThreadPropertiesSP g_settings_sp; |
| 52 | if (!g_settings_sp) |
| 53 | g_settings_sp.reset (new ThreadProperties (true)); |
| 54 | return g_settings_sp; |
| 55 | } |
| 56 | |
| 57 | static PropertyDefinition |
| 58 | g_properties[] = |
| 59 | { |
| 60 | { "step-avoid-regexp", OptionValue::eTypeRegex , true , REG_EXTENDED, "^std::", NULL, "A regular expression defining functions step-in won't stop in." }, |
| 61 | { "trace-thread", OptionValue::eTypeBoolean, false, false, NULL, NULL, "If true, this thread will single-step and log execution." }, |
| 62 | { NULL , OptionValue::eTypeInvalid, false, 0 , NULL, NULL, NULL } |
| 63 | }; |
| 64 | |
| 65 | enum { |
| 66 | ePropertyStepAvoidRegex, |
| 67 | ePropertyEnableThreadTrace |
| 68 | }; |
| 69 | |
| 70 | |
| 71 | class ThreadOptionValueProperties : public OptionValueProperties |
| 72 | { |
| 73 | public: |
| 74 | ThreadOptionValueProperties (const ConstString &name) : |
| 75 | OptionValueProperties (name) |
| 76 | { |
| 77 | } |
| 78 | |
| 79 | // This constructor is used when creating ThreadOptionValueProperties when it |
| 80 | // is part of a new lldb_private::Thread instance. It will copy all current |
| 81 | // global property values as needed |
| 82 | ThreadOptionValueProperties (ThreadProperties *global_properties) : |
Greg Clayton | 6920b52 | 2012-08-22 18:39:03 +0000 | [diff] [blame] | 83 | OptionValueProperties(*global_properties->GetValueProperties()) |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 84 | { |
| 85 | } |
| 86 | |
| 87 | virtual const Property * |
| 88 | GetPropertyAtIndex (const ExecutionContext *exe_ctx, bool will_modify, uint32_t idx) const |
| 89 | { |
| 90 | // When gettings the value for a key from the thread options, we will always |
| 91 | // try and grab the setting from the current thread if there is one. Else we just |
| 92 | // use the one from this instance. |
| 93 | if (exe_ctx) |
| 94 | { |
| 95 | Thread *thread = exe_ctx->GetThreadPtr(); |
| 96 | if (thread) |
| 97 | { |
| 98 | ThreadOptionValueProperties *instance_properties = static_cast<ThreadOptionValueProperties *>(thread->GetValueProperties().get()); |
| 99 | if (this != instance_properties) |
| 100 | return instance_properties->ProtectedGetPropertyAtIndex (idx); |
| 101 | } |
| 102 | } |
| 103 | return ProtectedGetPropertyAtIndex (idx); |
| 104 | } |
| 105 | }; |
| 106 | |
| 107 | |
| 108 | |
| 109 | ThreadProperties::ThreadProperties (bool is_global) : |
| 110 | Properties () |
| 111 | { |
| 112 | if (is_global) |
| 113 | { |
| 114 | m_collection_sp.reset (new ThreadOptionValueProperties(ConstString("thread"))); |
| 115 | m_collection_sp->Initialize(g_properties); |
| 116 | } |
| 117 | else |
| 118 | m_collection_sp.reset (new ThreadOptionValueProperties(Thread::GetGlobalProperties().get())); |
| 119 | } |
| 120 | |
| 121 | ThreadProperties::~ThreadProperties() |
| 122 | { |
| 123 | } |
| 124 | |
| 125 | const RegularExpression * |
| 126 | ThreadProperties::GetSymbolsToAvoidRegexp() |
| 127 | { |
| 128 | const uint32_t idx = ePropertyStepAvoidRegex; |
| 129 | return m_collection_sp->GetPropertyAtIndexAsOptionValueRegex (NULL, idx); |
| 130 | } |
| 131 | |
| 132 | bool |
| 133 | ThreadProperties::GetTraceEnabledState() const |
| 134 | { |
| 135 | const uint32_t idx = ePropertyEnableThreadTrace; |
| 136 | return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0); |
| 137 | } |
| 138 | |
Jim Ingham | 4f465cf | 2012-10-10 18:32:14 +0000 | [diff] [blame] | 139 | //------------------------------------------------------------------ |
| 140 | // Thread Event Data |
| 141 | //------------------------------------------------------------------ |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 142 | |
Jim Ingham | 4f465cf | 2012-10-10 18:32:14 +0000 | [diff] [blame] | 143 | |
| 144 | const ConstString & |
| 145 | Thread::ThreadEventData::GetFlavorString () |
| 146 | { |
| 147 | static ConstString g_flavor ("Thread::ThreadEventData"); |
| 148 | return g_flavor; |
| 149 | } |
| 150 | |
| 151 | Thread::ThreadEventData::ThreadEventData (const lldb::ThreadSP thread_sp) : |
| 152 | m_thread_sp (thread_sp), |
| 153 | m_stack_id () |
| 154 | { |
| 155 | } |
| 156 | |
| 157 | Thread::ThreadEventData::ThreadEventData (const lldb::ThreadSP thread_sp, const StackID &stack_id) : |
| 158 | m_thread_sp (thread_sp), |
| 159 | m_stack_id (stack_id) |
| 160 | { |
| 161 | } |
| 162 | |
| 163 | Thread::ThreadEventData::ThreadEventData () : |
| 164 | m_thread_sp (), |
| 165 | m_stack_id () |
| 166 | { |
| 167 | } |
| 168 | |
| 169 | Thread::ThreadEventData::~ThreadEventData () |
| 170 | { |
| 171 | } |
| 172 | |
| 173 | void |
| 174 | Thread::ThreadEventData::Dump (Stream *s) const |
| 175 | { |
| 176 | |
| 177 | } |
| 178 | |
| 179 | const Thread::ThreadEventData * |
| 180 | Thread::ThreadEventData::GetEventDataFromEvent (const Event *event_ptr) |
| 181 | { |
| 182 | if (event_ptr) |
| 183 | { |
| 184 | const EventData *event_data = event_ptr->GetData(); |
| 185 | if (event_data && event_data->GetFlavor() == ThreadEventData::GetFlavorString()) |
| 186 | return static_cast <const ThreadEventData *> (event_ptr->GetData()); |
| 187 | } |
| 188 | return NULL; |
| 189 | } |
| 190 | |
| 191 | ThreadSP |
| 192 | Thread::ThreadEventData::GetThreadFromEvent (const Event *event_ptr) |
| 193 | { |
| 194 | ThreadSP thread_sp; |
| 195 | const ThreadEventData *event_data = GetEventDataFromEvent (event_ptr); |
| 196 | if (event_data) |
| 197 | thread_sp = event_data->GetThread(); |
| 198 | return thread_sp; |
| 199 | } |
| 200 | |
| 201 | StackID |
| 202 | Thread::ThreadEventData::GetStackIDFromEvent (const Event *event_ptr) |
| 203 | { |
| 204 | StackID stack_id; |
| 205 | const ThreadEventData *event_data = GetEventDataFromEvent (event_ptr); |
| 206 | if (event_data) |
| 207 | stack_id = event_data->GetStackID(); |
| 208 | return stack_id; |
| 209 | } |
| 210 | |
| 211 | StackFrameSP |
| 212 | Thread::ThreadEventData::GetStackFrameFromEvent (const Event *event_ptr) |
| 213 | { |
| 214 | const ThreadEventData *event_data = GetEventDataFromEvent (event_ptr); |
| 215 | StackFrameSP frame_sp; |
| 216 | if (event_data) |
| 217 | { |
| 218 | ThreadSP thread_sp = event_data->GetThread(); |
| 219 | if (thread_sp) |
| 220 | { |
| 221 | frame_sp = thread_sp->GetStackFrameList()->GetFrameWithStackID (event_data->GetStackID()); |
| 222 | } |
| 223 | } |
| 224 | return frame_sp; |
| 225 | } |
| 226 | |
| 227 | //------------------------------------------------------------------ |
| 228 | // Thread class |
| 229 | //------------------------------------------------------------------ |
| 230 | |
| 231 | ConstString & |
| 232 | Thread::GetStaticBroadcasterClass () |
| 233 | { |
| 234 | static ConstString class_name ("lldb.thread"); |
| 235 | return class_name; |
| 236 | } |
| 237 | |
| 238 | Thread::Thread (Process &process, lldb::tid_t tid) : |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 239 | ThreadProperties (false), |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 240 | UserID (tid), |
Jim Ingham | 4f465cf | 2012-10-10 18:32:14 +0000 | [diff] [blame] | 241 | Broadcaster(&process.GetTarget().GetDebugger(), Thread::GetStaticBroadcasterClass().AsCString()), |
| 242 | m_process_wp (process.shared_from_this()), |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 243 | m_actual_stop_info_sp (), |
Jim Ingham | 4f465cf | 2012-10-10 18:32:14 +0000 | [diff] [blame] | 244 | m_index_id (process.GetNextThreadIndexID ()), |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 245 | m_reg_context_sp (), |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 246 | m_state (eStateUnloaded), |
Greg Clayton | 12daf946 | 2010-08-25 00:35:26 +0000 | [diff] [blame] | 247 | m_state_mutex (Mutex::eMutexTypeRecursive), |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 248 | m_plan_stack (), |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 249 | m_completed_plan_stack(), |
Greg Clayton | 39d0ab3 | 2012-03-29 01:41:38 +0000 | [diff] [blame] | 250 | m_frame_mutex (Mutex::eMutexTypeRecursive), |
Greg Clayton | 7e9b1fd | 2011-08-12 21:40:01 +0000 | [diff] [blame] | 251 | m_curr_frames_sp (), |
| 252 | m_prev_frames_sp (), |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 253 | m_resume_signal (LLDB_INVALID_SIGNAL_NUMBER), |
Jim Ingham | 87c1191 | 2010-08-12 02:14:28 +0000 | [diff] [blame] | 254 | m_resume_state (eStateRunning), |
Jim Ingham | 92087d8 | 2012-01-31 23:09:20 +0000 | [diff] [blame] | 255 | m_temporary_resume_state (eStateRunning), |
Jim Ingham | 773d981 | 2010-11-18 02:47:07 +0000 | [diff] [blame] | 256 | m_unwinder_ap (), |
Jim Ingham | 7778703 | 2011-01-20 02:03:18 +0000 | [diff] [blame] | 257 | m_destroy_called (false), |
| 258 | m_thread_stop_reason_stop_id (0) |
Jim Ingham | 87c1191 | 2010-08-12 02:14:28 +0000 | [diff] [blame] | 259 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 260 | { |
Greg Clayton | 2d4edfb | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 261 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 262 | if (log) |
Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 263 | log->Printf ("%p Thread::Thread(tid = 0x%4.4llx)", this, GetID()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 264 | |
Jim Ingham | 4f465cf | 2012-10-10 18:32:14 +0000 | [diff] [blame] | 265 | CheckInWithManager(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 266 | QueueFundamentalPlan(true); |
| 267 | } |
| 268 | |
| 269 | |
| 270 | Thread::~Thread() |
| 271 | { |
Greg Clayton | 2d4edfb | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 272 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 273 | if (log) |
Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 274 | log->Printf ("%p Thread::~Thread(tid = 0x%4.4llx)", this, GetID()); |
Jim Ingham | 773d981 | 2010-11-18 02:47:07 +0000 | [diff] [blame] | 275 | /// If you hit this assert, it means your derived class forgot to call DoDestroy in its destructor. |
| 276 | assert (m_destroy_called); |
| 277 | } |
| 278 | |
| 279 | void |
| 280 | Thread::DestroyThread () |
| 281 | { |
Greg Clayton | 35a4cc5 | 2012-10-29 20:52:08 +0000 | [diff] [blame] | 282 | m_destroy_called = true; |
Jim Ingham | 773d981 | 2010-11-18 02:47:07 +0000 | [diff] [blame] | 283 | m_plan_stack.clear(); |
| 284 | m_discarded_plan_stack.clear(); |
| 285 | m_completed_plan_stack.clear(); |
Jim Ingham | d8ba464 | 2012-04-10 00:44:25 +0000 | [diff] [blame] | 286 | m_actual_stop_info_sp.reset(); |
Greg Clayton | 35a4cc5 | 2012-10-29 20:52:08 +0000 | [diff] [blame] | 287 | m_reg_context_sp.reset(); |
| 288 | m_unwinder_ap.reset(); |
| 289 | Mutex::Locker locker(m_frame_mutex); |
| 290 | m_curr_frames_sp.reset(); |
| 291 | m_prev_frames_sp.reset(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 292 | } |
| 293 | |
Jim Ingham | 4f465cf | 2012-10-10 18:32:14 +0000 | [diff] [blame] | 294 | void |
| 295 | Thread::BroadcastSelectedFrameChange(StackID &new_frame_id) |
| 296 | { |
| 297 | if (EventTypeHasListeners(eBroadcastBitSelectedFrameChanged)) |
| 298 | BroadcastEvent(eBroadcastBitSelectedFrameChanged, new ThreadEventData (this->shared_from_this(), new_frame_id)); |
| 299 | } |
| 300 | |
| 301 | uint32_t |
| 302 | Thread::SetSelectedFrame (lldb_private::StackFrame *frame, bool broadcast) |
| 303 | { |
| 304 | uint32_t ret_value = GetStackFrameList()->SetSelectedFrame(frame); |
| 305 | if (broadcast) |
| 306 | BroadcastSelectedFrameChange(frame->GetStackID()); |
| 307 | return ret_value; |
| 308 | } |
| 309 | |
| 310 | bool |
| 311 | Thread::SetSelectedFrameByIndex (uint32_t frame_idx, bool broadcast) |
| 312 | { |
| 313 | StackFrameSP frame_sp(GetStackFrameList()->GetFrameAtIndex (frame_idx)); |
| 314 | if (frame_sp) |
| 315 | { |
| 316 | GetStackFrameList()->SetSelectedFrame(frame_sp.get()); |
| 317 | if (broadcast) |
| 318 | BroadcastSelectedFrameChange(frame_sp->GetStackID()); |
| 319 | return true; |
| 320 | } |
| 321 | else |
| 322 | return false; |
| 323 | } |
| 324 | |
| 325 | |
Jim Ingham | b15bfc7 | 2010-10-20 00:39:53 +0000 | [diff] [blame] | 326 | lldb::StopInfoSP |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 327 | Thread::GetStopInfo () |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 328 | { |
Jim Ingham | b15bfc7 | 2010-10-20 00:39:53 +0000 | [diff] [blame] | 329 | ThreadPlanSP plan_sp (GetCompletedPlan()); |
Jim Ingham | fbbfe6e | 2012-05-01 18:38:37 +0000 | [diff] [blame] | 330 | if (plan_sp && plan_sp->PlanSucceeded()) |
Jim Ingham | 73ca05a | 2011-12-17 01:35:57 +0000 | [diff] [blame] | 331 | return StopInfo::CreateStopReasonWithPlan (plan_sp, GetReturnValueObject()); |
Jim Ingham | b15bfc7 | 2010-10-20 00:39:53 +0000 | [diff] [blame] | 332 | else |
Jim Ingham | 79c35da | 2011-08-09 00:32:52 +0000 | [diff] [blame] | 333 | { |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 334 | ProcessSP process_sp (GetProcess()); |
| 335 | if (process_sp |
| 336 | && m_actual_stop_info_sp |
Jim Ingham | 79c35da | 2011-08-09 00:32:52 +0000 | [diff] [blame] | 337 | && m_actual_stop_info_sp->IsValid() |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 338 | && m_thread_stop_reason_stop_id == process_sp->GetStopID()) |
Jim Ingham | 79c35da | 2011-08-09 00:32:52 +0000 | [diff] [blame] | 339 | return m_actual_stop_info_sp; |
| 340 | else |
| 341 | return GetPrivateStopReason (); |
| 342 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 343 | } |
| 344 | |
Greg Clayton | 97d5cf0 | 2012-09-25 02:40:06 +0000 | [diff] [blame] | 345 | lldb::StopReason |
| 346 | Thread::GetStopReason() |
| 347 | { |
| 348 | lldb::StopInfoSP stop_info_sp (GetStopInfo ()); |
| 349 | if (stop_info_sp) |
Filipe Cabecinhas | e26391a | 2012-09-28 15:55:43 +0000 | [diff] [blame] | 350 | return stop_info_sp->GetStopReason(); |
Greg Clayton | 97d5cf0 | 2012-09-25 02:40:06 +0000 | [diff] [blame] | 351 | return eStopReasonNone; |
| 352 | } |
| 353 | |
| 354 | |
| 355 | |
Jim Ingham | 7778703 | 2011-01-20 02:03:18 +0000 | [diff] [blame] | 356 | void |
| 357 | Thread::SetStopInfo (const lldb::StopInfoSP &stop_info_sp) |
| 358 | { |
| 359 | m_actual_stop_info_sp = stop_info_sp; |
Jim Ingham | 79c35da | 2011-08-09 00:32:52 +0000 | [diff] [blame] | 360 | if (m_actual_stop_info_sp) |
| 361 | m_actual_stop_info_sp->MakeStopInfoValid(); |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 362 | ProcessSP process_sp (GetProcess()); |
| 363 | if (process_sp) |
| 364 | m_thread_stop_reason_stop_id = process_sp->GetStopID(); |
| 365 | else |
| 366 | m_thread_stop_reason_stop_id = UINT32_MAX; |
Jim Ingham | 7778703 | 2011-01-20 02:03:18 +0000 | [diff] [blame] | 367 | } |
| 368 | |
| 369 | void |
| 370 | Thread::SetStopInfoToNothing() |
| 371 | { |
| 372 | // Note, we can't just NULL out the private reason, or the native thread implementation will try to |
| 373 | // go calculate it again. For now, just set it to a Unix Signal with an invalid signal number. |
| 374 | SetStopInfo (StopInfo::CreateStopReasonWithSignal (*this, LLDB_INVALID_SIGNAL_NUMBER)); |
| 375 | } |
| 376 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 377 | bool |
| 378 | Thread::ThreadStoppedForAReason (void) |
| 379 | { |
Jim Ingham | f94e179 | 2012-08-11 00:35:26 +0000 | [diff] [blame] | 380 | return (bool) GetPrivateStopReason (); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 381 | } |
| 382 | |
Jim Ingham | 7778703 | 2011-01-20 02:03:18 +0000 | [diff] [blame] | 383 | bool |
| 384 | Thread::CheckpointThreadState (ThreadStateCheckpoint &saved_state) |
| 385 | { |
| 386 | if (!SaveFrameZeroState(saved_state.register_backup)) |
| 387 | return false; |
| 388 | |
| 389 | saved_state.stop_info_sp = GetStopInfo(); |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 390 | ProcessSP process_sp (GetProcess()); |
| 391 | if (process_sp) |
| 392 | saved_state.orig_stop_id = process_sp->GetStopID(); |
Jim Ingham | 625fca7 | 2012-09-07 23:36:43 +0000 | [diff] [blame] | 393 | saved_state.current_inlined_depth = GetCurrentInlinedDepth(); |
| 394 | |
Jim Ingham | 7778703 | 2011-01-20 02:03:18 +0000 | [diff] [blame] | 395 | return true; |
| 396 | } |
| 397 | |
| 398 | bool |
| 399 | Thread::RestoreThreadStateFromCheckpoint (ThreadStateCheckpoint &saved_state) |
| 400 | { |
| 401 | RestoreSaveFrameZero(saved_state.register_backup); |
Jim Ingham | 0c27068 | 2011-01-25 02:47:23 +0000 | [diff] [blame] | 402 | if (saved_state.stop_info_sp) |
| 403 | saved_state.stop_info_sp->MakeStopInfoValid(); |
Jim Ingham | 7778703 | 2011-01-20 02:03:18 +0000 | [diff] [blame] | 404 | SetStopInfo(saved_state.stop_info_sp); |
Jim Ingham | 625fca7 | 2012-09-07 23:36:43 +0000 | [diff] [blame] | 405 | GetStackFrameList()->SetCurrentInlinedDepth (saved_state.current_inlined_depth); |
Jim Ingham | 7778703 | 2011-01-20 02:03:18 +0000 | [diff] [blame] | 406 | return true; |
| 407 | } |
| 408 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 409 | StateType |
| 410 | Thread::GetState() const |
| 411 | { |
| 412 | // If any other threads access this we will need a mutex for it |
| 413 | Mutex::Locker locker(m_state_mutex); |
| 414 | return m_state; |
| 415 | } |
| 416 | |
| 417 | void |
| 418 | Thread::SetState(StateType state) |
| 419 | { |
| 420 | Mutex::Locker locker(m_state_mutex); |
| 421 | m_state = state; |
| 422 | } |
| 423 | |
| 424 | void |
| 425 | Thread::WillStop() |
| 426 | { |
| 427 | ThreadPlan *current_plan = GetCurrentPlan(); |
| 428 | |
| 429 | // FIXME: I may decide to disallow threads with no plans. In which |
| 430 | // case this should go to an assert. |
| 431 | |
| 432 | if (!current_plan) |
| 433 | return; |
| 434 | |
| 435 | current_plan->WillStop(); |
| 436 | } |
| 437 | |
| 438 | void |
| 439 | Thread::SetupForResume () |
| 440 | { |
| 441 | if (GetResumeState() != eStateSuspended) |
| 442 | { |
| 443 | |
| 444 | // If we're at a breakpoint push the step-over breakpoint plan. Do this before |
| 445 | // telling the current plan it will resume, since we might change what the current |
| 446 | // plan is. |
| 447 | |
Jim Ingham | 5d88a06 | 2012-10-16 00:09:33 +0000 | [diff] [blame] | 448 | StopReason stop_reason = lldb::eStopReasonInvalid; |
| 449 | StopInfoSP stop_info_sp = GetStopInfo(); |
| 450 | if (stop_info_sp.get()) |
| 451 | stop_reason = stop_info_sp->GetStopReason(); |
| 452 | if (stop_reason == lldb::eStopReasonBreakpoint) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 453 | { |
| 454 | // Note, don't assume there's a ThreadPlanStepOverBreakpoint, the target may not require anything |
| 455 | // special to step over a breakpoint. |
Jim Ingham | b01e742 | 2010-06-19 04:45:32 +0000 | [diff] [blame] | 456 | |
| 457 | ThreadPlan *cur_plan = GetCurrentPlan(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 458 | |
Jim Ingham | b01e742 | 2010-06-19 04:45:32 +0000 | [diff] [blame] | 459 | if (cur_plan->GetKind() != ThreadPlan::eKindStepOverBreakpoint) |
| 460 | { |
| 461 | ThreadPlanStepOverBreakpoint *step_bp_plan = new ThreadPlanStepOverBreakpoint (*this); |
| 462 | if (step_bp_plan) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 463 | { |
Jim Ingham | b01e742 | 2010-06-19 04:45:32 +0000 | [diff] [blame] | 464 | ThreadPlanSP step_bp_plan_sp; |
| 465 | step_bp_plan->SetPrivate (true); |
| 466 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 467 | if (GetCurrentPlan()->RunState() != eStateStepping) |
| 468 | { |
Jim Ingham | b01e742 | 2010-06-19 04:45:32 +0000 | [diff] [blame] | 469 | step_bp_plan->SetAutoContinue(true); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 470 | } |
Jim Ingham | b01e742 | 2010-06-19 04:45:32 +0000 | [diff] [blame] | 471 | step_bp_plan_sp.reset (step_bp_plan); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 472 | QueueThreadPlan (step_bp_plan_sp, false); |
| 473 | } |
| 474 | } |
| 475 | } |
| 476 | } |
| 477 | } |
| 478 | |
| 479 | bool |
| 480 | Thread::WillResume (StateType resume_state) |
| 481 | { |
| 482 | // At this point clear the completed plan stack. |
| 483 | m_completed_plan_stack.clear(); |
| 484 | m_discarded_plan_stack.clear(); |
| 485 | |
Greg Clayton | 97d5cf0 | 2012-09-25 02:40:06 +0000 | [diff] [blame] | 486 | m_temporary_resume_state = resume_state; |
Jim Ingham | 92087d8 | 2012-01-31 23:09:20 +0000 | [diff] [blame] | 487 | |
| 488 | // This is a little dubious, but we are trying to limit how often we actually fetch stop info from |
| 489 | // the target, 'cause that slows down single stepping. So assume that if we got to the point where |
| 490 | // we're about to resume, and we haven't yet had to fetch the stop reason, then it doesn't need to know |
| 491 | // about the fact that we are resuming... |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 492 | const uint32_t process_stop_id = GetProcess()->GetStopID(); |
Jim Ingham | 92087d8 | 2012-01-31 23:09:20 +0000 | [diff] [blame] | 493 | if (m_thread_stop_reason_stop_id == process_stop_id && |
| 494 | (m_actual_stop_info_sp && m_actual_stop_info_sp->IsValid())) |
| 495 | { |
| 496 | StopInfo *stop_info = GetPrivateStopReason().get(); |
| 497 | if (stop_info) |
| 498 | stop_info->WillResume (resume_state); |
| 499 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 500 | |
| 501 | // Tell all the plans that we are about to resume in case they need to clear any state. |
| 502 | // We distinguish between the plan on the top of the stack and the lower |
| 503 | // plans in case a plan needs to do any special business before it runs. |
| 504 | |
| 505 | ThreadPlan *plan_ptr = GetCurrentPlan(); |
Jim Ingham | 513c6bb | 2012-09-01 01:02:41 +0000 | [diff] [blame] | 506 | bool need_to_resume = plan_ptr->WillResume(resume_state, true); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 507 | |
| 508 | while ((plan_ptr = GetPreviousPlan(plan_ptr)) != NULL) |
| 509 | { |
| 510 | plan_ptr->WillResume (resume_state, false); |
| 511 | } |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 512 | |
Jim Ingham | 513c6bb | 2012-09-01 01:02:41 +0000 | [diff] [blame] | 513 | // If the WillResume for the plan says we are faking a resume, then it will have set an appropriate stop info. |
| 514 | // In that case, don't reset it here. |
| 515 | |
Jim Ingham | 5d88a06 | 2012-10-16 00:09:33 +0000 | [diff] [blame] | 516 | if (need_to_resume && resume_state != eStateSuspended) |
Jim Ingham | 513c6bb | 2012-09-01 01:02:41 +0000 | [diff] [blame] | 517 | { |
| 518 | m_actual_stop_info_sp.reset(); |
| 519 | } |
| 520 | |
| 521 | return need_to_resume; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 522 | } |
| 523 | |
| 524 | void |
| 525 | Thread::DidResume () |
| 526 | { |
| 527 | SetResumeSignal (LLDB_INVALID_SIGNAL_NUMBER); |
| 528 | } |
| 529 | |
| 530 | bool |
| 531 | Thread::ShouldStop (Event* event_ptr) |
| 532 | { |
| 533 | ThreadPlan *current_plan = GetCurrentPlan(); |
| 534 | bool should_stop = true; |
| 535 | |
Greg Clayton | 2d4edfb | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 536 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); |
Jim Ingham | 92087d8 | 2012-01-31 23:09:20 +0000 | [diff] [blame] | 537 | |
| 538 | if (GetResumeState () == eStateSuspended) |
| 539 | { |
| 540 | if (log) |
| 541 | log->Printf ("Thread::%s for tid = 0x%4.4llx, should_stop = 0 (ignore since thread was suspended)", |
| 542 | __FUNCTION__, |
| 543 | GetID ()); |
| 544 | // log->Printf ("Thread::%s for tid = 0x%4.4llx, pc = 0x%16.16llx, should_stop = 0 (ignore since thread was suspended)", |
| 545 | // __FUNCTION__, |
| 546 | // GetID (), |
| 547 | // GetRegisterContext()->GetPC()); |
| 548 | return false; |
| 549 | } |
| 550 | |
| 551 | if (GetTemporaryResumeState () == eStateSuspended) |
| 552 | { |
| 553 | if (log) |
| 554 | log->Printf ("Thread::%s for tid = 0x%4.4llx, should_stop = 0 (ignore since thread was suspended)", |
| 555 | __FUNCTION__, |
| 556 | GetID ()); |
| 557 | // log->Printf ("Thread::%s for tid = 0x%4.4llx, pc = 0x%16.16llx, should_stop = 0 (ignore since thread was suspended)", |
| 558 | // __FUNCTION__, |
| 559 | // GetID (), |
| 560 | // GetRegisterContext()->GetPC()); |
| 561 | return false; |
| 562 | } |
| 563 | |
| 564 | if (ThreadStoppedForAReason() == false) |
| 565 | { |
| 566 | if (log) |
| 567 | log->Printf ("Thread::%s for tid = 0x%4.4llx, pc = 0x%16.16llx, should_stop = 0 (ignore since no stop reason)", |
| 568 | __FUNCTION__, |
| 569 | GetID (), |
| 570 | GetRegisterContext()->GetPC()); |
| 571 | return false; |
| 572 | } |
Jim Ingham | 513c6bb | 2012-09-01 01:02:41 +0000 | [diff] [blame] | 573 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 574 | if (log) |
| 575 | { |
Jim Ingham | 92087d8 | 2012-01-31 23:09:20 +0000 | [diff] [blame] | 576 | log->Printf ("Thread::%s for tid = 0x%4.4llx, pc = 0x%16.16llx", |
| 577 | __FUNCTION__, |
| 578 | GetID (), |
| 579 | GetRegisterContext()->GetPC()); |
Jim Ingham | 10c4b24 | 2011-10-15 00:23:43 +0000 | [diff] [blame] | 580 | log->Printf ("^^^^^^^^ Thread::ShouldStop Begin ^^^^^^^^"); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 581 | StreamString s; |
Jim Ingham | 10c4b24 | 2011-10-15 00:23:43 +0000 | [diff] [blame] | 582 | s.IndentMore(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 583 | DumpThreadPlans(&s); |
Jim Ingham | 10c4b24 | 2011-10-15 00:23:43 +0000 | [diff] [blame] | 584 | log->Printf ("Plan stack initial state:\n%s", s.GetData()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 585 | } |
Jim Ingham | 06e827c | 2010-11-11 19:26:09 +0000 | [diff] [blame] | 586 | |
| 587 | // The top most plan always gets to do the trace log... |
| 588 | current_plan->DoTraceLog (); |
Jim Ingham | 6d66ce6 | 2012-04-20 21:16:56 +0000 | [diff] [blame] | 589 | |
| 590 | // First query the stop info's ShouldStopSynchronous. This handles "synchronous" stop reasons, for example the breakpoint |
| 591 | // command on internal breakpoints. If a synchronous stop reason says we should not stop, then we don't have to |
| 592 | // do any more work on this stop. |
| 593 | StopInfoSP private_stop_info (GetPrivateStopReason()); |
| 594 | if (private_stop_info && private_stop_info->ShouldStopSynchronous(event_ptr) == false) |
| 595 | { |
| 596 | if (log) |
| 597 | log->Printf ("StopInfo::ShouldStop async callback says we should not stop, returning ShouldStop of false."); |
| 598 | return false; |
| 599 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 600 | |
Jim Ingham | bad39e4 | 2012-09-05 21:12:49 +0000 | [diff] [blame] | 601 | // If we've already been restarted, don't query the plans since the state they would examine is not current. |
| 602 | if (Process::ProcessEventData::GetRestartedFromEvent(event_ptr)) |
| 603 | return false; |
| 604 | |
| 605 | // Before the plans see the state of the world, calculate the current inlined depth. |
| 606 | GetStackFrameList()->CalculateCurrentInlinedDepth(); |
| 607 | |
Jim Ingham | 25f6670 | 2011-12-03 01:52:59 +0000 | [diff] [blame] | 608 | // If the base plan doesn't understand why we stopped, then we have to find a plan that does. |
| 609 | // If that plan is still working, then we don't need to do any more work. If the plan that explains |
| 610 | // the stop is done, then we should pop all the plans below it, and pop it, and then let the plans above it decide |
| 611 | // whether they still need to do more work. |
| 612 | |
| 613 | bool done_processing_current_plan = false; |
| 614 | |
| 615 | if (!current_plan->PlanExplainsStop()) |
| 616 | { |
| 617 | if (current_plan->TracerExplainsStop()) |
| 618 | { |
| 619 | done_processing_current_plan = true; |
| 620 | should_stop = false; |
| 621 | } |
| 622 | else |
| 623 | { |
Jim Ingham | cf274f9 | 2012-04-09 22:37:39 +0000 | [diff] [blame] | 624 | // 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] | 625 | // does and let it handle the situation. |
| 626 | ThreadPlan *plan_ptr = current_plan; |
| 627 | while ((plan_ptr = GetPreviousPlan(plan_ptr)) != NULL) |
| 628 | { |
| 629 | if (plan_ptr->PlanExplainsStop()) |
| 630 | { |
| 631 | should_stop = plan_ptr->ShouldStop (event_ptr); |
| 632 | |
| 633 | // plan_ptr explains the stop, next check whether plan_ptr is done, if so, then we should take it |
| 634 | // and all the plans below it off the stack. |
| 635 | |
| 636 | if (plan_ptr->MischiefManaged()) |
| 637 | { |
Jim Ingham | 031177e | 2012-05-11 23:49:49 +0000 | [diff] [blame] | 638 | // 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] | 639 | ThreadPlan *prev_plan_ptr = GetPreviousPlan (plan_ptr); |
Jim Ingham | 25f6670 | 2011-12-03 01:52:59 +0000 | [diff] [blame] | 640 | |
| 641 | do |
| 642 | { |
| 643 | if (should_stop) |
| 644 | current_plan->WillStop(); |
| 645 | PopPlan(); |
| 646 | } |
Jim Ingham | 7ba6e99 | 2012-05-11 23:47:32 +0000 | [diff] [blame] | 647 | while ((current_plan = GetCurrentPlan()) != prev_plan_ptr); |
| 648 | // Now, if the responsible plan was not "Okay to discard" then we're done, |
| 649 | // otherwise we forward this to the next plan in the stack below. |
| 650 | if (plan_ptr->IsMasterPlan() && !plan_ptr->OkayToDiscard()) |
| 651 | done_processing_current_plan = true; |
| 652 | else |
| 653 | done_processing_current_plan = false; |
Jim Ingham | 25f6670 | 2011-12-03 01:52:59 +0000 | [diff] [blame] | 654 | } |
| 655 | else |
| 656 | done_processing_current_plan = true; |
| 657 | |
| 658 | break; |
| 659 | } |
| 660 | |
| 661 | } |
| 662 | } |
| 663 | } |
| 664 | |
| 665 | if (!done_processing_current_plan) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 666 | { |
Jim Ingham | b01e742 | 2010-06-19 04:45:32 +0000 | [diff] [blame] | 667 | bool over_ride_stop = current_plan->ShouldAutoContinue(event_ptr); |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 668 | |
Jim Ingham | 10c4b24 | 2011-10-15 00:23:43 +0000 | [diff] [blame] | 669 | if (log) |
| 670 | log->Printf("Plan %s explains stop, auto-continue %i.", current_plan->GetName(), over_ride_stop); |
| 671 | |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 672 | // We're starting from the base plan, so just let it decide; |
| 673 | if (PlanIsBasePlan(current_plan)) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 674 | { |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 675 | should_stop = current_plan->ShouldStop (event_ptr); |
| 676 | if (log) |
Greg Clayton | af247d7 | 2011-05-19 03:54:16 +0000 | [diff] [blame] | 677 | log->Printf("Base plan says should stop: %i.", should_stop); |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 678 | } |
| 679 | else |
| 680 | { |
| 681 | // Otherwise, don't let the base plan override what the other plans say to do, since |
| 682 | // presumably if there were other plans they would know what to do... |
| 683 | while (1) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 684 | { |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 685 | if (PlanIsBasePlan(current_plan)) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 686 | break; |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 687 | |
| 688 | should_stop = current_plan->ShouldStop(event_ptr); |
| 689 | if (log) |
| 690 | log->Printf("Plan %s should stop: %d.", current_plan->GetName(), should_stop); |
| 691 | if (current_plan->MischiefManaged()) |
| 692 | { |
| 693 | if (should_stop) |
| 694 | current_plan->WillStop(); |
| 695 | |
| 696 | // If a Master Plan wants to stop, and wants to stick on the stack, we let it. |
| 697 | // Otherwise, see if the plan's parent wants to stop. |
| 698 | |
| 699 | if (should_stop && current_plan->IsMasterPlan() && !current_plan->OkayToDiscard()) |
| 700 | { |
| 701 | PopPlan(); |
| 702 | break; |
| 703 | } |
| 704 | else |
| 705 | { |
| 706 | |
| 707 | PopPlan(); |
| 708 | |
| 709 | current_plan = GetCurrentPlan(); |
| 710 | if (current_plan == NULL) |
| 711 | { |
| 712 | break; |
| 713 | } |
| 714 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 715 | } |
| 716 | else |
| 717 | { |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 718 | break; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 719 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 720 | } |
| 721 | } |
Jim Ingham | 64e7ead | 2012-05-03 21:19:36 +0000 | [diff] [blame] | 722 | |
Jim Ingham | b01e742 | 2010-06-19 04:45:32 +0000 | [diff] [blame] | 723 | if (over_ride_stop) |
| 724 | should_stop = false; |
Jim Ingham | 64e7ead | 2012-05-03 21:19:36 +0000 | [diff] [blame] | 725 | |
| 726 | // One other potential problem is that we set up a master plan, then stop in before it is complete - for instance |
| 727 | // by hitting a breakpoint during a step-over - then do some step/finish/etc operations that wind up |
| 728 | // past the end point condition of the initial plan. We don't want to strand the original plan on the stack, |
| 729 | // This code clears stale plans off the stack. |
| 730 | |
| 731 | if (should_stop) |
| 732 | { |
| 733 | ThreadPlan *plan_ptr = GetCurrentPlan(); |
| 734 | while (!PlanIsBasePlan(plan_ptr)) |
| 735 | { |
| 736 | bool stale = plan_ptr->IsPlanStale (); |
| 737 | ThreadPlan *examined_plan = plan_ptr; |
| 738 | plan_ptr = GetPreviousPlan (examined_plan); |
| 739 | |
| 740 | if (stale) |
| 741 | { |
| 742 | if (log) |
| 743 | log->Printf("Plan %s being discarded in cleanup, it says it is already done.", examined_plan->GetName()); |
| 744 | DiscardThreadPlansUpToPlan(examined_plan); |
| 745 | } |
| 746 | } |
| 747 | } |
| 748 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 749 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 750 | |
Jim Ingham | 10c4b24 | 2011-10-15 00:23:43 +0000 | [diff] [blame] | 751 | if (log) |
| 752 | { |
| 753 | StreamString s; |
| 754 | s.IndentMore(); |
| 755 | DumpThreadPlans(&s); |
| 756 | log->Printf ("Plan stack final state:\n%s", s.GetData()); |
| 757 | log->Printf ("vvvvvvvv Thread::ShouldStop End (returning %i) vvvvvvvv", should_stop); |
| 758 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 759 | return should_stop; |
| 760 | } |
| 761 | |
| 762 | Vote |
| 763 | Thread::ShouldReportStop (Event* event_ptr) |
| 764 | { |
| 765 | StateType thread_state = GetResumeState (); |
Jim Ingham | 92087d8 | 2012-01-31 23:09:20 +0000 | [diff] [blame] | 766 | StateType temp_thread_state = GetTemporaryResumeState(); |
| 767 | |
Greg Clayton | 2d4edfb | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 768 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); |
Greg Clayton | 2cad65a | 2010-09-03 17:10:42 +0000 | [diff] [blame] | 769 | |
| 770 | if (thread_state == eStateSuspended || thread_state == eStateInvalid) |
| 771 | { |
| 772 | if (log) |
Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 773 | log->Printf ("Thread::ShouldReportStop() tid = 0x%4.4llx: returning vote %i (state was suspended or invalid)\n", GetID(), eVoteNoOpinion); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 774 | return eVoteNoOpinion; |
Greg Clayton | 2cad65a | 2010-09-03 17:10:42 +0000 | [diff] [blame] | 775 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 776 | |
Jim Ingham | 92087d8 | 2012-01-31 23:09:20 +0000 | [diff] [blame] | 777 | if (temp_thread_state == eStateSuspended || temp_thread_state == eStateInvalid) |
| 778 | { |
| 779 | if (log) |
| 780 | log->Printf ("Thread::ShouldReportStop() tid = 0x%4.4llx: returning vote %i (temporary state was suspended or invalid)\n", GetID(), eVoteNoOpinion); |
| 781 | return eVoteNoOpinion; |
| 782 | } |
| 783 | |
| 784 | if (!ThreadStoppedForAReason()) |
| 785 | { |
| 786 | if (log) |
| 787 | log->Printf ("Thread::ShouldReportStop() tid = 0x%4.4llx: returning vote %i (thread didn't stop for a reason.)\n", GetID(), eVoteNoOpinion); |
| 788 | return eVoteNoOpinion; |
| 789 | } |
| 790 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 791 | if (m_completed_plan_stack.size() > 0) |
| 792 | { |
| 793 | // Don't use GetCompletedPlan here, since that suppresses private plans. |
Greg Clayton | 2cad65a | 2010-09-03 17:10:42 +0000 | [diff] [blame] | 794 | if (log) |
Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 795 | log->Printf ("Thread::ShouldReportStop() tid = 0x%4.4llx: returning vote for complete stack's back plan\n", GetID()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 796 | return m_completed_plan_stack.back()->ShouldReportStop (event_ptr); |
| 797 | } |
| 798 | else |
Greg Clayton | 2cad65a | 2010-09-03 17:10:42 +0000 | [diff] [blame] | 799 | { |
| 800 | if (log) |
Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 801 | log->Printf ("Thread::ShouldReportStop() tid = 0x%4.4llx: returning vote for current plan\n", GetID()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 802 | return GetCurrentPlan()->ShouldReportStop (event_ptr); |
Greg Clayton | 2cad65a | 2010-09-03 17:10:42 +0000 | [diff] [blame] | 803 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 804 | } |
| 805 | |
| 806 | Vote |
| 807 | Thread::ShouldReportRun (Event* event_ptr) |
| 808 | { |
| 809 | StateType thread_state = GetResumeState (); |
Jim Ingham | 444586b | 2011-01-24 06:34:17 +0000 | [diff] [blame] | 810 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 811 | if (thread_state == eStateSuspended |
| 812 | || thread_state == eStateInvalid) |
Jim Ingham | 444586b | 2011-01-24 06:34:17 +0000 | [diff] [blame] | 813 | { |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 814 | return eVoteNoOpinion; |
Jim Ingham | 444586b | 2011-01-24 06:34:17 +0000 | [diff] [blame] | 815 | } |
| 816 | |
| 817 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 818 | if (m_completed_plan_stack.size() > 0) |
| 819 | { |
| 820 | // Don't use GetCompletedPlan here, since that suppresses private plans. |
Jim Ingham | 444586b | 2011-01-24 06:34:17 +0000 | [diff] [blame] | 821 | if (log) |
Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 822 | log->Printf ("Current Plan for thread %d (0x%4.4llx): %s being asked whether we should report run.", |
Jim Ingham | 444586b | 2011-01-24 06:34:17 +0000 | [diff] [blame] | 823 | GetIndexID(), |
| 824 | GetID(), |
| 825 | m_completed_plan_stack.back()->GetName()); |
| 826 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 827 | return m_completed_plan_stack.back()->ShouldReportRun (event_ptr); |
| 828 | } |
| 829 | else |
Jim Ingham | 444586b | 2011-01-24 06:34:17 +0000 | [diff] [blame] | 830 | { |
| 831 | if (log) |
Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 832 | log->Printf ("Current Plan for thread %d (0x%4.4llx): %s being asked whether we should report run.", |
Jim Ingham | 444586b | 2011-01-24 06:34:17 +0000 | [diff] [blame] | 833 | GetIndexID(), |
| 834 | GetID(), |
| 835 | GetCurrentPlan()->GetName()); |
| 836 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 837 | return GetCurrentPlan()->ShouldReportRun (event_ptr); |
Jim Ingham | 444586b | 2011-01-24 06:34:17 +0000 | [diff] [blame] | 838 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 839 | } |
| 840 | |
Jim Ingham | 1b54c88 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 841 | bool |
| 842 | Thread::MatchesSpec (const ThreadSpec *spec) |
| 843 | { |
| 844 | if (spec == NULL) |
| 845 | return true; |
Jim Ingham | 1b54c88 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 846 | |
Jim Ingham | 3d90292 | 2012-03-07 22:03:04 +0000 | [diff] [blame] | 847 | return spec->ThreadPassesBasicTests(*this); |
Jim Ingham | 1b54c88 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 848 | } |
| 849 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 850 | void |
| 851 | Thread::PushPlan (ThreadPlanSP &thread_plan_sp) |
| 852 | { |
| 853 | if (thread_plan_sp) |
| 854 | { |
Jim Ingham | 06e827c | 2010-11-11 19:26:09 +0000 | [diff] [blame] | 855 | // If the thread plan doesn't already have a tracer, give it its parent's tracer: |
| 856 | if (!thread_plan_sp->GetThreadPlanTracer()) |
| 857 | thread_plan_sp->SetThreadPlanTracer(m_plan_stack.back()->GetThreadPlanTracer()); |
Jim Ingham | b15bfc7 | 2010-10-20 00:39:53 +0000 | [diff] [blame] | 858 | m_plan_stack.push_back (thread_plan_sp); |
Jim Ingham | 06e827c | 2010-11-11 19:26:09 +0000 | [diff] [blame] | 859 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 860 | thread_plan_sp->DidPush(); |
| 861 | |
Greg Clayton | 2d4edfb | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 862 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 863 | if (log) |
| 864 | { |
| 865 | StreamString s; |
| 866 | thread_plan_sp->GetDescription (&s, lldb::eDescriptionLevelFull); |
Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 867 | log->Printf("Pushing plan: \"%s\", tid = 0x%4.4llx.", |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 868 | s.GetData(), |
Jim Ingham | b15bfc7 | 2010-10-20 00:39:53 +0000 | [diff] [blame] | 869 | thread_plan_sp->GetThread().GetID()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 870 | } |
| 871 | } |
| 872 | } |
| 873 | |
| 874 | void |
| 875 | Thread::PopPlan () |
| 876 | { |
Greg Clayton | 2d4edfb | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 877 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 878 | |
Jim Ingham | 4fc6cb9 | 2012-08-22 21:34:33 +0000 | [diff] [blame] | 879 | if (m_plan_stack.size() <= 1) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 880 | return; |
| 881 | else |
| 882 | { |
| 883 | ThreadPlanSP &plan = m_plan_stack.back(); |
| 884 | if (log) |
| 885 | { |
Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 886 | log->Printf("Popping plan: \"%s\", tid = 0x%4.4llx.", plan->GetName(), plan->GetThread().GetID()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 887 | } |
| 888 | m_completed_plan_stack.push_back (plan); |
| 889 | plan->WillPop(); |
| 890 | m_plan_stack.pop_back(); |
| 891 | } |
| 892 | } |
| 893 | |
| 894 | void |
| 895 | Thread::DiscardPlan () |
| 896 | { |
| 897 | if (m_plan_stack.size() > 1) |
| 898 | { |
| 899 | ThreadPlanSP &plan = m_plan_stack.back(); |
| 900 | m_discarded_plan_stack.push_back (plan); |
| 901 | plan->WillPop(); |
| 902 | m_plan_stack.pop_back(); |
| 903 | } |
| 904 | } |
| 905 | |
| 906 | ThreadPlan * |
| 907 | Thread::GetCurrentPlan () |
| 908 | { |
Jim Ingham | e147123 | 2012-04-19 00:17:05 +0000 | [diff] [blame] | 909 | // There will always be at least the base plan. If somebody is mucking with a |
| 910 | // thread with an empty plan stack, we should assert right away. |
| 911 | assert (!m_plan_stack.empty()); |
| 912 | |
| 913 | return m_plan_stack.back().get(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 914 | } |
| 915 | |
| 916 | ThreadPlanSP |
| 917 | Thread::GetCompletedPlan () |
| 918 | { |
| 919 | ThreadPlanSP empty_plan_sp; |
| 920 | if (!m_completed_plan_stack.empty()) |
| 921 | { |
| 922 | for (int i = m_completed_plan_stack.size() - 1; i >= 0; i--) |
| 923 | { |
| 924 | ThreadPlanSP completed_plan_sp; |
| 925 | completed_plan_sp = m_completed_plan_stack[i]; |
| 926 | if (!completed_plan_sp->GetPrivate ()) |
| 927 | return completed_plan_sp; |
| 928 | } |
| 929 | } |
| 930 | return empty_plan_sp; |
| 931 | } |
| 932 | |
Jim Ingham | 73ca05a | 2011-12-17 01:35:57 +0000 | [diff] [blame] | 933 | ValueObjectSP |
| 934 | Thread::GetReturnValueObject () |
| 935 | { |
| 936 | if (!m_completed_plan_stack.empty()) |
| 937 | { |
| 938 | for (int i = m_completed_plan_stack.size() - 1; i >= 0; i--) |
| 939 | { |
| 940 | ValueObjectSP return_valobj_sp; |
| 941 | return_valobj_sp = m_completed_plan_stack[i]->GetReturnValueObject(); |
| 942 | if (return_valobj_sp) |
| 943 | return return_valobj_sp; |
| 944 | } |
| 945 | } |
| 946 | return ValueObjectSP(); |
| 947 | } |
| 948 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 949 | bool |
| 950 | Thread::IsThreadPlanDone (ThreadPlan *plan) |
| 951 | { |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 952 | if (!m_completed_plan_stack.empty()) |
| 953 | { |
| 954 | for (int i = m_completed_plan_stack.size() - 1; i >= 0; i--) |
| 955 | { |
| 956 | if (m_completed_plan_stack[i].get() == plan) |
| 957 | return true; |
| 958 | } |
| 959 | } |
| 960 | return false; |
| 961 | } |
| 962 | |
| 963 | bool |
| 964 | Thread::WasThreadPlanDiscarded (ThreadPlan *plan) |
| 965 | { |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 966 | if (!m_discarded_plan_stack.empty()) |
| 967 | { |
| 968 | for (int i = m_discarded_plan_stack.size() - 1; i >= 0; i--) |
| 969 | { |
| 970 | if (m_discarded_plan_stack[i].get() == plan) |
| 971 | return true; |
| 972 | } |
| 973 | } |
| 974 | return false; |
| 975 | } |
| 976 | |
| 977 | ThreadPlan * |
| 978 | Thread::GetPreviousPlan (ThreadPlan *current_plan) |
| 979 | { |
| 980 | if (current_plan == NULL) |
| 981 | return NULL; |
| 982 | |
| 983 | int stack_size = m_completed_plan_stack.size(); |
| 984 | for (int i = stack_size - 1; i > 0; i--) |
| 985 | { |
| 986 | if (current_plan == m_completed_plan_stack[i].get()) |
| 987 | return m_completed_plan_stack[i-1].get(); |
| 988 | } |
| 989 | |
| 990 | if (stack_size > 0 && m_completed_plan_stack[0].get() == current_plan) |
| 991 | { |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 992 | if (m_plan_stack.size() > 0) |
| 993 | return m_plan_stack.back().get(); |
| 994 | else |
| 995 | return NULL; |
| 996 | } |
| 997 | |
| 998 | stack_size = m_plan_stack.size(); |
| 999 | for (int i = stack_size - 1; i > 0; i--) |
| 1000 | { |
| 1001 | if (current_plan == m_plan_stack[i].get()) |
| 1002 | return m_plan_stack[i-1].get(); |
| 1003 | } |
| 1004 | return NULL; |
| 1005 | } |
| 1006 | |
| 1007 | void |
| 1008 | Thread::QueueThreadPlan (ThreadPlanSP &thread_plan_sp, bool abort_other_plans) |
| 1009 | { |
| 1010 | if (abort_other_plans) |
| 1011 | DiscardThreadPlans(true); |
| 1012 | |
| 1013 | PushPlan (thread_plan_sp); |
| 1014 | } |
| 1015 | |
Jim Ingham | 06e827c | 2010-11-11 19:26:09 +0000 | [diff] [blame] | 1016 | |
| 1017 | void |
| 1018 | Thread::EnableTracer (bool value, bool single_stepping) |
| 1019 | { |
| 1020 | int stack_size = m_plan_stack.size(); |
| 1021 | for (int i = 0; i < stack_size; i++) |
| 1022 | { |
| 1023 | if (m_plan_stack[i]->GetThreadPlanTracer()) |
| 1024 | { |
| 1025 | m_plan_stack[i]->GetThreadPlanTracer()->EnableTracing(value); |
| 1026 | m_plan_stack[i]->GetThreadPlanTracer()->EnableSingleStep(single_stepping); |
| 1027 | } |
| 1028 | } |
| 1029 | } |
| 1030 | |
| 1031 | void |
| 1032 | Thread::SetTracer (lldb::ThreadPlanTracerSP &tracer_sp) |
| 1033 | { |
| 1034 | int stack_size = m_plan_stack.size(); |
| 1035 | for (int i = 0; i < stack_size; i++) |
| 1036 | m_plan_stack[i]->SetThreadPlanTracer(tracer_sp); |
| 1037 | } |
| 1038 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1039 | void |
Jim Ingham | 399f1ca | 2010-11-05 19:25:48 +0000 | [diff] [blame] | 1040 | Thread::DiscardThreadPlansUpToPlan (lldb::ThreadPlanSP &up_to_plan_sp) |
| 1041 | { |
Jim Ingham | 64e7ead | 2012-05-03 21:19:36 +0000 | [diff] [blame] | 1042 | DiscardThreadPlansUpToPlan (up_to_plan_sp.get()); |
| 1043 | } |
| 1044 | |
| 1045 | void |
| 1046 | Thread::DiscardThreadPlansUpToPlan (ThreadPlan *up_to_plan_ptr) |
| 1047 | { |
Greg Clayton | 2d4edfb | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 1048 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); |
Jim Ingham | 399f1ca | 2010-11-05 19:25:48 +0000 | [diff] [blame] | 1049 | if (log) |
| 1050 | { |
Jim Ingham | 64e7ead | 2012-05-03 21:19:36 +0000 | [diff] [blame] | 1051 | log->Printf("Discarding thread plans for thread tid = 0x%4.4llx, up to %p", GetID(), up_to_plan_ptr); |
Jim Ingham | 399f1ca | 2010-11-05 19:25:48 +0000 | [diff] [blame] | 1052 | } |
| 1053 | |
| 1054 | int stack_size = m_plan_stack.size(); |
| 1055 | |
| 1056 | // If the input plan is NULL, discard all plans. Otherwise make sure this plan is in the |
| 1057 | // stack, and if so discard up to and including it. |
| 1058 | |
Jim Ingham | 64e7ead | 2012-05-03 21:19:36 +0000 | [diff] [blame] | 1059 | if (up_to_plan_ptr == NULL) |
Jim Ingham | 399f1ca | 2010-11-05 19:25:48 +0000 | [diff] [blame] | 1060 | { |
| 1061 | for (int i = stack_size - 1; i > 0; i--) |
| 1062 | DiscardPlan(); |
| 1063 | } |
| 1064 | else |
| 1065 | { |
| 1066 | bool found_it = false; |
| 1067 | for (int i = stack_size - 1; i > 0; i--) |
| 1068 | { |
Jim Ingham | 64e7ead | 2012-05-03 21:19:36 +0000 | [diff] [blame] | 1069 | if (m_plan_stack[i].get() == up_to_plan_ptr) |
Jim Ingham | 399f1ca | 2010-11-05 19:25:48 +0000 | [diff] [blame] | 1070 | found_it = true; |
| 1071 | } |
| 1072 | if (found_it) |
| 1073 | { |
| 1074 | bool last_one = false; |
| 1075 | for (int i = stack_size - 1; i > 0 && !last_one ; i--) |
| 1076 | { |
Jim Ingham | 64e7ead | 2012-05-03 21:19:36 +0000 | [diff] [blame] | 1077 | if (GetCurrentPlan() == up_to_plan_ptr) |
Jim Ingham | 399f1ca | 2010-11-05 19:25:48 +0000 | [diff] [blame] | 1078 | last_one = true; |
| 1079 | DiscardPlan(); |
| 1080 | } |
| 1081 | } |
| 1082 | } |
| 1083 | return; |
| 1084 | } |
| 1085 | |
| 1086 | void |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1087 | Thread::DiscardThreadPlans(bool force) |
| 1088 | { |
Greg Clayton | 2d4edfb | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 1089 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1090 | if (log) |
| 1091 | { |
Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 1092 | log->Printf("Discarding thread plans for thread (tid = 0x%4.4llx, force %d)", GetID(), force); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1093 | } |
| 1094 | |
| 1095 | if (force) |
| 1096 | { |
| 1097 | int stack_size = m_plan_stack.size(); |
| 1098 | for (int i = stack_size - 1; i > 0; i--) |
| 1099 | { |
| 1100 | DiscardPlan(); |
| 1101 | } |
| 1102 | return; |
| 1103 | } |
| 1104 | |
| 1105 | while (1) |
| 1106 | { |
| 1107 | |
| 1108 | int master_plan_idx; |
Jim Ingham | a39ad07 | 2012-09-11 00:09:25 +0000 | [diff] [blame] | 1109 | bool discard = true; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1110 | |
| 1111 | // Find the first master plan, see if it wants discarding, and if yes discard up to it. |
| 1112 | for (master_plan_idx = m_plan_stack.size() - 1; master_plan_idx >= 0; master_plan_idx--) |
| 1113 | { |
| 1114 | if (m_plan_stack[master_plan_idx]->IsMasterPlan()) |
| 1115 | { |
| 1116 | discard = m_plan_stack[master_plan_idx]->OkayToDiscard(); |
| 1117 | break; |
| 1118 | } |
| 1119 | } |
| 1120 | |
| 1121 | if (discard) |
| 1122 | { |
| 1123 | // First pop all the dependent plans: |
| 1124 | for (int i = m_plan_stack.size() - 1; i > master_plan_idx; i--) |
| 1125 | { |
| 1126 | |
| 1127 | // FIXME: Do we need a finalize here, or is the rule that "PrepareForStop" |
| 1128 | // for the plan leaves it in a state that it is safe to pop the plan |
| 1129 | // with no more notice? |
| 1130 | DiscardPlan(); |
| 1131 | } |
| 1132 | |
| 1133 | // Now discard the master plan itself. |
| 1134 | // The bottom-most plan never gets discarded. "OkayToDiscard" for it means |
| 1135 | // discard it's dependent plans, but not it... |
| 1136 | if (master_plan_idx > 0) |
| 1137 | { |
| 1138 | DiscardPlan(); |
| 1139 | } |
| 1140 | } |
| 1141 | else |
| 1142 | { |
| 1143 | // If the master plan doesn't want to get discarded, then we're done. |
| 1144 | break; |
| 1145 | } |
| 1146 | |
| 1147 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1148 | } |
| 1149 | |
Jim Ingham | cf274f9 | 2012-04-09 22:37:39 +0000 | [diff] [blame] | 1150 | bool |
| 1151 | Thread::PlanIsBasePlan (ThreadPlan *plan_ptr) |
| 1152 | { |
| 1153 | if (plan_ptr->IsBasePlan()) |
| 1154 | return true; |
| 1155 | else if (m_plan_stack.size() == 0) |
| 1156 | return false; |
| 1157 | else |
| 1158 | return m_plan_stack[0].get() == plan_ptr; |
| 1159 | } |
| 1160 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1161 | ThreadPlan * |
| 1162 | Thread::QueueFundamentalPlan (bool abort_other_plans) |
| 1163 | { |
| 1164 | ThreadPlanSP thread_plan_sp (new ThreadPlanBase(*this)); |
| 1165 | QueueThreadPlan (thread_plan_sp, abort_other_plans); |
| 1166 | return thread_plan_sp.get(); |
| 1167 | } |
| 1168 | |
| 1169 | ThreadPlan * |
Greg Clayton | 481cef2 | 2011-01-21 06:11:58 +0000 | [diff] [blame] | 1170 | Thread::QueueThreadPlanForStepSingleInstruction |
| 1171 | ( |
| 1172 | bool step_over, |
| 1173 | bool abort_other_plans, |
| 1174 | bool stop_other_threads |
| 1175 | ) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1176 | { |
| 1177 | ThreadPlanSP thread_plan_sp (new ThreadPlanStepInstruction (*this, step_over, stop_other_threads, eVoteNoOpinion, eVoteNoOpinion)); |
| 1178 | QueueThreadPlan (thread_plan_sp, abort_other_plans); |
| 1179 | return thread_plan_sp.get(); |
| 1180 | } |
| 1181 | |
| 1182 | ThreadPlan * |
Greg Clayton | 474966a | 2010-06-12 18:59:55 +0000 | [diff] [blame] | 1183 | Thread::QueueThreadPlanForStepRange |
| 1184 | ( |
| 1185 | bool abort_other_plans, |
| 1186 | StepType type, |
| 1187 | const AddressRange &range, |
| 1188 | const SymbolContext &addr_context, |
| 1189 | lldb::RunMode stop_other_threads, |
| 1190 | bool avoid_code_without_debug_info |
| 1191 | ) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1192 | { |
| 1193 | ThreadPlanSP thread_plan_sp; |
| 1194 | if (type == eStepTypeInto) |
Greg Clayton | 474966a | 2010-06-12 18:59:55 +0000 | [diff] [blame] | 1195 | { |
| 1196 | ThreadPlanStepInRange *plan = new ThreadPlanStepInRange (*this, range, addr_context, stop_other_threads); |
| 1197 | if (avoid_code_without_debug_info) |
| 1198 | plan->GetFlags().Set (ThreadPlanShouldStopHere::eAvoidNoDebug); |
| 1199 | else |
| 1200 | plan->GetFlags().Clear (ThreadPlanShouldStopHere::eAvoidNoDebug); |
| 1201 | thread_plan_sp.reset (plan); |
| 1202 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1203 | else |
| 1204 | thread_plan_sp.reset (new ThreadPlanStepOverRange (*this, range, addr_context, stop_other_threads)); |
| 1205 | |
| 1206 | QueueThreadPlan (thread_plan_sp, abort_other_plans); |
| 1207 | return thread_plan_sp.get(); |
| 1208 | } |
| 1209 | |
| 1210 | |
| 1211 | ThreadPlan * |
| 1212 | Thread::QueueThreadPlanForStepOverBreakpointPlan (bool abort_other_plans) |
| 1213 | { |
| 1214 | ThreadPlanSP thread_plan_sp (new ThreadPlanStepOverBreakpoint (*this)); |
| 1215 | QueueThreadPlan (thread_plan_sp, abort_other_plans); |
| 1216 | return thread_plan_sp.get(); |
| 1217 | } |
| 1218 | |
| 1219 | ThreadPlan * |
Greg Clayton | 481cef2 | 2011-01-21 06:11:58 +0000 | [diff] [blame] | 1220 | Thread::QueueThreadPlanForStepOut |
| 1221 | ( |
| 1222 | bool abort_other_plans, |
| 1223 | SymbolContext *addr_context, |
| 1224 | bool first_insn, |
| 1225 | bool stop_other_threads, |
| 1226 | Vote stop_vote, |
| 1227 | Vote run_vote, |
| 1228 | uint32_t frame_idx |
| 1229 | ) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1230 | { |
Greg Clayton | 481cef2 | 2011-01-21 06:11:58 +0000 | [diff] [blame] | 1231 | ThreadPlanSP thread_plan_sp (new ThreadPlanStepOut (*this, |
| 1232 | addr_context, |
| 1233 | first_insn, |
| 1234 | stop_other_threads, |
| 1235 | stop_vote, |
| 1236 | run_vote, |
| 1237 | frame_idx)); |
Sean Callanan | 708709c | 2012-07-31 22:19:25 +0000 | [diff] [blame] | 1238 | |
| 1239 | if (thread_plan_sp->ValidatePlan(NULL)) |
| 1240 | { |
| 1241 | QueueThreadPlan (thread_plan_sp, abort_other_plans); |
| 1242 | return thread_plan_sp.get(); |
| 1243 | } |
| 1244 | else |
| 1245 | { |
| 1246 | return NULL; |
| 1247 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1248 | } |
| 1249 | |
| 1250 | ThreadPlan * |
Jim Ingham | 18de2fd | 2012-05-10 01:35:39 +0000 | [diff] [blame] | 1251 | 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] | 1252 | { |
Jim Ingham | 18de2fd | 2012-05-10 01:35:39 +0000 | [diff] [blame] | 1253 | 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] | 1254 | if (!thread_plan_sp || !thread_plan_sp->ValidatePlan (NULL)) |
| 1255 | return NULL; |
| 1256 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1257 | QueueThreadPlan (thread_plan_sp, abort_other_plans); |
| 1258 | return thread_plan_sp.get(); |
| 1259 | } |
| 1260 | |
| 1261 | ThreadPlan * |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1262 | Thread::QueueThreadPlanForCallFunction (bool abort_other_plans, |
| 1263 | Address& function, |
| 1264 | lldb::addr_t arg, |
| 1265 | bool stop_other_threads, |
| 1266 | bool discard_on_error) |
| 1267 | { |
Jim Ingham | ef65160 | 2011-12-22 19:12:40 +0000 | [diff] [blame] | 1268 | ThreadPlanSP thread_plan_sp (new ThreadPlanCallFunction (*this, function, ClangASTType(), arg, stop_other_threads, discard_on_error)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1269 | QueueThreadPlan (thread_plan_sp, abort_other_plans); |
| 1270 | return thread_plan_sp.get(); |
| 1271 | } |
| 1272 | |
| 1273 | ThreadPlan * |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1274 | Thread::QueueThreadPlanForRunToAddress (bool abort_other_plans, |
| 1275 | Address &target_addr, |
| 1276 | bool stop_other_threads) |
| 1277 | { |
| 1278 | ThreadPlanSP thread_plan_sp (new ThreadPlanRunToAddress (*this, target_addr, stop_other_threads)); |
| 1279 | QueueThreadPlan (thread_plan_sp, abort_other_plans); |
| 1280 | return thread_plan_sp.get(); |
| 1281 | } |
| 1282 | |
| 1283 | ThreadPlan * |
| 1284 | Thread::QueueThreadPlanForStepUntil (bool abort_other_plans, |
Greg Clayton | 481cef2 | 2011-01-21 06:11:58 +0000 | [diff] [blame] | 1285 | lldb::addr_t *address_list, |
| 1286 | size_t num_addresses, |
| 1287 | bool stop_other_threads, |
| 1288 | uint32_t frame_idx) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1289 | { |
Greg Clayton | 481cef2 | 2011-01-21 06:11:58 +0000 | [diff] [blame] | 1290 | 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] | 1291 | QueueThreadPlan (thread_plan_sp, abort_other_plans); |
| 1292 | return thread_plan_sp.get(); |
| 1293 | |
| 1294 | } |
| 1295 | |
| 1296 | uint32_t |
| 1297 | Thread::GetIndexID () const |
| 1298 | { |
| 1299 | return m_index_id; |
| 1300 | } |
| 1301 | |
| 1302 | void |
| 1303 | Thread::DumpThreadPlans (lldb_private::Stream *s) const |
| 1304 | { |
| 1305 | uint32_t stack_size = m_plan_stack.size(); |
Greg Clayton | 1346f7e | 2010-09-03 22:45:01 +0000 | [diff] [blame] | 1306 | int i; |
Jim Ingham | 10c4b24 | 2011-10-15 00:23:43 +0000 | [diff] [blame] | 1307 | s->Indent(); |
Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 1308 | s->Printf ("Plan Stack for thread #%u: tid = 0x%4.4llx, stack_size = %d\n", GetIndexID(), GetID(), stack_size); |
Greg Clayton | 1346f7e | 2010-09-03 22:45:01 +0000 | [diff] [blame] | 1309 | for (i = stack_size - 1; i >= 0; i--) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1310 | { |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1311 | s->IndentMore(); |
Jim Ingham | 10c4b24 | 2011-10-15 00:23:43 +0000 | [diff] [blame] | 1312 | s->Indent(); |
| 1313 | s->Printf ("Element %d: ", i); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1314 | m_plan_stack[i]->GetDescription (s, eDescriptionLevelFull); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1315 | s->EOL(); |
Jim Ingham | 10c4b24 | 2011-10-15 00:23:43 +0000 | [diff] [blame] | 1316 | s->IndentLess(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1317 | } |
| 1318 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1319 | stack_size = m_completed_plan_stack.size(); |
Jim Ingham | 10c4b24 | 2011-10-15 00:23:43 +0000 | [diff] [blame] | 1320 | if (stack_size > 0) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1321 | { |
Jim Ingham | 10c4b24 | 2011-10-15 00:23:43 +0000 | [diff] [blame] | 1322 | s->Indent(); |
| 1323 | s->Printf ("Completed Plan Stack: %d elements.\n", stack_size); |
| 1324 | for (i = stack_size - 1; i >= 0; i--) |
| 1325 | { |
| 1326 | s->IndentMore(); |
| 1327 | s->Indent(); |
| 1328 | s->Printf ("Element %d: ", i); |
| 1329 | m_completed_plan_stack[i]->GetDescription (s, eDescriptionLevelFull); |
| 1330 | s->EOL(); |
| 1331 | s->IndentLess(); |
| 1332 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1333 | } |
| 1334 | |
| 1335 | stack_size = m_discarded_plan_stack.size(); |
Jim Ingham | 10c4b24 | 2011-10-15 00:23:43 +0000 | [diff] [blame] | 1336 | if (stack_size > 0) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1337 | { |
Jim Ingham | 10c4b24 | 2011-10-15 00:23:43 +0000 | [diff] [blame] | 1338 | s->Indent(); |
| 1339 | s->Printf ("Discarded Plan Stack: %d elements.\n", stack_size); |
| 1340 | for (i = stack_size - 1; i >= 0; i--) |
| 1341 | { |
| 1342 | s->IndentMore(); |
| 1343 | s->Indent(); |
| 1344 | s->Printf ("Element %d: ", i); |
| 1345 | m_discarded_plan_stack[i]->GetDescription (s, eDescriptionLevelFull); |
| 1346 | s->EOL(); |
| 1347 | s->IndentLess(); |
| 1348 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1349 | } |
| 1350 | |
| 1351 | } |
| 1352 | |
Greg Clayton | d9e416c | 2012-02-18 05:35:26 +0000 | [diff] [blame] | 1353 | TargetSP |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1354 | Thread::CalculateTarget () |
| 1355 | { |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 1356 | TargetSP target_sp; |
| 1357 | ProcessSP process_sp(GetProcess()); |
| 1358 | if (process_sp) |
| 1359 | target_sp = process_sp->CalculateTarget(); |
| 1360 | return target_sp; |
| 1361 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1362 | } |
| 1363 | |
Greg Clayton | d9e416c | 2012-02-18 05:35:26 +0000 | [diff] [blame] | 1364 | ProcessSP |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1365 | Thread::CalculateProcess () |
| 1366 | { |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 1367 | return GetProcess(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1368 | } |
| 1369 | |
Greg Clayton | d9e416c | 2012-02-18 05:35:26 +0000 | [diff] [blame] | 1370 | ThreadSP |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1371 | Thread::CalculateThread () |
| 1372 | { |
Greg Clayton | d9e416c | 2012-02-18 05:35:26 +0000 | [diff] [blame] | 1373 | return shared_from_this(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1374 | } |
| 1375 | |
Greg Clayton | d9e416c | 2012-02-18 05:35:26 +0000 | [diff] [blame] | 1376 | StackFrameSP |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1377 | Thread::CalculateStackFrame () |
| 1378 | { |
Greg Clayton | d9e416c | 2012-02-18 05:35:26 +0000 | [diff] [blame] | 1379 | return StackFrameSP(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1380 | } |
| 1381 | |
| 1382 | void |
Greg Clayton | 0603aa9 | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 1383 | Thread::CalculateExecutionContext (ExecutionContext &exe_ctx) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1384 | { |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 1385 | exe_ctx.SetContext (shared_from_this()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1386 | } |
| 1387 | |
Greg Clayton | 12daf946 | 2010-08-25 00:35:26 +0000 | [diff] [blame] | 1388 | |
Greg Clayton | 39d0ab3 | 2012-03-29 01:41:38 +0000 | [diff] [blame] | 1389 | StackFrameListSP |
Greg Clayton | 12daf946 | 2010-08-25 00:35:26 +0000 | [diff] [blame] | 1390 | Thread::GetStackFrameList () |
| 1391 | { |
Greg Clayton | 39d0ab3 | 2012-03-29 01:41:38 +0000 | [diff] [blame] | 1392 | StackFrameListSP frame_list_sp; |
| 1393 | Mutex::Locker locker(m_frame_mutex); |
| 1394 | if (m_curr_frames_sp) |
| 1395 | { |
| 1396 | frame_list_sp = m_curr_frames_sp; |
| 1397 | } |
| 1398 | else |
| 1399 | { |
| 1400 | frame_list_sp.reset(new StackFrameList (*this, m_prev_frames_sp, true)); |
| 1401 | m_curr_frames_sp = frame_list_sp; |
| 1402 | } |
| 1403 | return frame_list_sp; |
Greg Clayton | 12daf946 | 2010-08-25 00:35:26 +0000 | [diff] [blame] | 1404 | } |
| 1405 | |
Greg Clayton | 12daf946 | 2010-08-25 00:35:26 +0000 | [diff] [blame] | 1406 | void |
| 1407 | Thread::ClearStackFrames () |
| 1408 | { |
Greg Clayton | 39d0ab3 | 2012-03-29 01:41:38 +0000 | [diff] [blame] | 1409 | Mutex::Locker locker(m_frame_mutex); |
| 1410 | |
Jim Ingham | b0c72a5 | 2012-02-29 03:40:22 +0000 | [diff] [blame] | 1411 | // Only store away the old "reference" StackFrameList if we got all its frames: |
| 1412 | // FIXME: At some point we can try to splice in the frames we have fetched into |
| 1413 | // the new frame as we make it, but let's not try that now. |
| 1414 | if (m_curr_frames_sp && m_curr_frames_sp->GetAllFramesFetched()) |
Greg Clayton | 7e9b1fd | 2011-08-12 21:40:01 +0000 | [diff] [blame] | 1415 | m_prev_frames_sp.swap (m_curr_frames_sp); |
| 1416 | m_curr_frames_sp.reset(); |
Jim Ingham | 87c1191 | 2010-08-12 02:14:28 +0000 | [diff] [blame] | 1417 | } |
| 1418 | |
| 1419 | lldb::StackFrameSP |
Greg Clayton | 5ccbd29 | 2011-01-06 22:15:06 +0000 | [diff] [blame] | 1420 | Thread::GetFrameWithConcreteFrameIndex (uint32_t unwind_idx) |
| 1421 | { |
Greg Clayton | 39d0ab3 | 2012-03-29 01:41:38 +0000 | [diff] [blame] | 1422 | return GetStackFrameList()->GetFrameWithConcreteFrameIndex (unwind_idx); |
Greg Clayton | 5ccbd29 | 2011-01-06 22:15:06 +0000 | [diff] [blame] | 1423 | } |
| 1424 | |
Jim Ingham | 4413758 | 2012-09-12 00:40:39 +0000 | [diff] [blame] | 1425 | |
| 1426 | Error |
Jim Ingham | 4f465cf | 2012-10-10 18:32:14 +0000 | [diff] [blame] | 1427 | 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] | 1428 | { |
| 1429 | StackFrameSP frame_sp = GetStackFrameAtIndex (frame_idx); |
| 1430 | Error return_error; |
| 1431 | |
| 1432 | if (!frame_sp) |
| 1433 | { |
| 1434 | return_error.SetErrorStringWithFormat("Could not find frame with index %d in thread 0x%llx.", frame_idx, GetID()); |
| 1435 | } |
| 1436 | |
Jim Ingham | 4f465cf | 2012-10-10 18:32:14 +0000 | [diff] [blame] | 1437 | return ReturnFromFrame(frame_sp, return_value_sp, broadcast); |
Jim Ingham | 4413758 | 2012-09-12 00:40:39 +0000 | [diff] [blame] | 1438 | } |
| 1439 | |
| 1440 | Error |
Jim Ingham | 4f465cf | 2012-10-10 18:32:14 +0000 | [diff] [blame] | 1441 | 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] | 1442 | { |
| 1443 | Error return_error; |
| 1444 | |
| 1445 | if (!frame_sp) |
| 1446 | { |
| 1447 | return_error.SetErrorString("Can't return to a null frame."); |
| 1448 | return return_error; |
| 1449 | } |
| 1450 | |
| 1451 | Thread *thread = frame_sp->GetThread().get(); |
Jim Ingham | cb640dd | 2012-09-14 02:14:15 +0000 | [diff] [blame] | 1452 | uint32_t older_frame_idx = frame_sp->GetFrameIndex() + 1; |
| 1453 | StackFrameSP older_frame_sp = thread->GetStackFrameAtIndex(older_frame_idx); |
Jim Ingham | 4413758 | 2012-09-12 00:40:39 +0000 | [diff] [blame] | 1454 | |
| 1455 | if (return_value_sp) |
Jim Ingham | 1f51e60 | 2012-09-27 01:15:29 +0000 | [diff] [blame] | 1456 | { |
Jim Ingham | 4413758 | 2012-09-12 00:40:39 +0000 | [diff] [blame] | 1457 | lldb::ABISP abi = thread->GetProcess()->GetABI(); |
| 1458 | if (!abi) |
| 1459 | { |
| 1460 | return_error.SetErrorString("Could not find ABI to set return value."); |
Jim Ingham | 28eb571 | 2012-10-12 17:34:26 +0000 | [diff] [blame] | 1461 | return return_error; |
Jim Ingham | 4413758 | 2012-09-12 00:40:39 +0000 | [diff] [blame] | 1462 | } |
Jim Ingham | 1f51e60 | 2012-09-27 01:15:29 +0000 | [diff] [blame] | 1463 | SymbolContext sc = frame_sp->GetSymbolContext(eSymbolContextFunction); |
| 1464 | |
| 1465 | // FIXME: ValueObject::Cast doesn't currently work correctly, at least not for scalars. |
| 1466 | // Turn that back on when that works. |
| 1467 | if (0 && sc.function != NULL) |
| 1468 | { |
| 1469 | Type *function_type = sc.function->GetType(); |
| 1470 | if (function_type) |
| 1471 | { |
| 1472 | clang_type_t return_type = sc.function->GetReturnClangType(); |
| 1473 | if (return_type) |
| 1474 | { |
| 1475 | ClangASTType ast_type (function_type->GetClangAST(), return_type); |
| 1476 | StreamString s; |
| 1477 | ast_type.DumpTypeDescription(&s); |
| 1478 | ValueObjectSP cast_value_sp = return_value_sp->Cast(ast_type); |
| 1479 | if (cast_value_sp) |
| 1480 | { |
| 1481 | cast_value_sp->SetFormat(eFormatHex); |
| 1482 | return_value_sp = cast_value_sp; |
| 1483 | } |
| 1484 | } |
| 1485 | } |
| 1486 | } |
| 1487 | |
Jim Ingham | cb640dd | 2012-09-14 02:14:15 +0000 | [diff] [blame] | 1488 | return_error = abi->SetReturnValueObject(older_frame_sp, return_value_sp); |
Jim Ingham | 4413758 | 2012-09-12 00:40:39 +0000 | [diff] [blame] | 1489 | if (!return_error.Success()) |
| 1490 | return return_error; |
| 1491 | } |
| 1492 | |
| 1493 | // Now write the return registers for the chosen frame: |
Jim Ingham | cb640dd | 2012-09-14 02:14:15 +0000 | [diff] [blame] | 1494 | // Note, we can't use ReadAllRegisterValues->WriteAllRegisterValues, since the read & write |
| 1495 | // cook their data |
| 1496 | bool copy_success = thread->GetStackFrameAtIndex(0)->GetRegisterContext()->CopyFromRegisterContext(older_frame_sp->GetRegisterContext()); |
| 1497 | if (copy_success) |
Jim Ingham | 4413758 | 2012-09-12 00:40:39 +0000 | [diff] [blame] | 1498 | { |
| 1499 | thread->DiscardThreadPlans(true); |
Jim Ingham | cb640dd | 2012-09-14 02:14:15 +0000 | [diff] [blame] | 1500 | thread->ClearStackFrames(); |
Jim Ingham | 4f465cf | 2012-10-10 18:32:14 +0000 | [diff] [blame] | 1501 | if (broadcast && EventTypeHasListeners(eBroadcastBitStackChanged)) |
| 1502 | BroadcastEvent(eBroadcastBitStackChanged, new ThreadEventData (this->shared_from_this())); |
Jim Ingham | 4413758 | 2012-09-12 00:40:39 +0000 | [diff] [blame] | 1503 | return return_error; |
| 1504 | } |
| 1505 | else |
| 1506 | { |
| 1507 | return_error.SetErrorString("Could not reset register values."); |
| 1508 | return return_error; |
Jim Ingham | 4413758 | 2012-09-12 00:40:39 +0000 | [diff] [blame] | 1509 | } |
| 1510 | } |
| 1511 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1512 | void |
Greg Clayton | 0603aa9 | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 1513 | Thread::DumpUsingSettingsFormat (Stream &strm, uint32_t frame_idx) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1514 | { |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 1515 | ExecutionContext exe_ctx (shared_from_this()); |
| 1516 | Process *process = exe_ctx.GetProcessPtr(); |
| 1517 | if (process == NULL) |
| 1518 | return; |
| 1519 | |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 1520 | StackFrameSP frame_sp; |
Greg Clayton | 0603aa9 | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 1521 | SymbolContext frame_sc; |
Greg Clayton | 0603aa9 | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 1522 | if (frame_idx != LLDB_INVALID_INDEX32) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1523 | { |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 1524 | frame_sp = GetStackFrameAtIndex (frame_idx); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1525 | if (frame_sp) |
| 1526 | { |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 1527 | exe_ctx.SetFrameSP(frame_sp); |
| 1528 | frame_sc = frame_sp->GetSymbolContext(eSymbolContextEverything); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1529 | } |
| 1530 | } |
| 1531 | |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 1532 | const char *thread_format = exe_ctx.GetTargetRef().GetDebugger().GetThreadFormat(); |
Greg Clayton | 0603aa9 | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 1533 | assert (thread_format); |
| 1534 | const char *end = NULL; |
| 1535 | Debugger::FormatPrompt (thread_format, |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 1536 | frame_sp ? &frame_sc : NULL, |
Greg Clayton | 0603aa9 | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 1537 | &exe_ctx, |
| 1538 | NULL, |
| 1539 | strm, |
| 1540 | &end); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1541 | } |
| 1542 | |
Greg Clayton | 99d0faf | 2010-11-18 23:32:35 +0000 | [diff] [blame] | 1543 | void |
Caroline Tice | 20bd37f | 2011-03-10 22:14:10 +0000 | [diff] [blame] | 1544 | Thread::SettingsInitialize () |
Jim Ingham | ee8aea1 | 2010-09-08 03:14:33 +0000 | [diff] [blame] | 1545 | { |
Greg Clayton | 99d0faf | 2010-11-18 23:32:35 +0000 | [diff] [blame] | 1546 | } |
Jim Ingham | ee8aea1 | 2010-09-08 03:14:33 +0000 | [diff] [blame] | 1547 | |
Greg Clayton | 99d0faf | 2010-11-18 23:32:35 +0000 | [diff] [blame] | 1548 | void |
Caroline Tice | 20bd37f | 2011-03-10 22:14:10 +0000 | [diff] [blame] | 1549 | Thread::SettingsTerminate () |
Greg Clayton | 99d0faf | 2010-11-18 23:32:35 +0000 | [diff] [blame] | 1550 | { |
Greg Clayton | 99d0faf | 2010-11-18 23:32:35 +0000 | [diff] [blame] | 1551 | } |
Jim Ingham | ee8aea1 | 2010-09-08 03:14:33 +0000 | [diff] [blame] | 1552 | |
Jim Ingham | e4284b7 | 2010-09-23 17:40:12 +0000 | [diff] [blame] | 1553 | lldb::StackFrameSP |
| 1554 | Thread::GetStackFrameSPForStackFramePtr (StackFrame *stack_frame_ptr) |
| 1555 | { |
Greg Clayton | 39d0ab3 | 2012-03-29 01:41:38 +0000 | [diff] [blame] | 1556 | return GetStackFrameList()->GetStackFrameSPForStackFramePtr (stack_frame_ptr); |
Jim Ingham | e4284b7 | 2010-09-23 17:40:12 +0000 | [diff] [blame] | 1557 | } |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 1558 | |
| 1559 | const char * |
| 1560 | Thread::StopReasonAsCString (lldb::StopReason reason) |
| 1561 | { |
| 1562 | switch (reason) |
| 1563 | { |
| 1564 | case eStopReasonInvalid: return "invalid"; |
| 1565 | case eStopReasonNone: return "none"; |
| 1566 | case eStopReasonTrace: return "trace"; |
| 1567 | case eStopReasonBreakpoint: return "breakpoint"; |
| 1568 | case eStopReasonWatchpoint: return "watchpoint"; |
| 1569 | case eStopReasonSignal: return "signal"; |
| 1570 | case eStopReasonException: return "exception"; |
| 1571 | case eStopReasonPlanComplete: return "plan complete"; |
| 1572 | } |
| 1573 | |
| 1574 | |
| 1575 | static char unknown_state_string[64]; |
| 1576 | snprintf(unknown_state_string, sizeof (unknown_state_string), "StopReason = %i", reason); |
| 1577 | return unknown_state_string; |
| 1578 | } |
| 1579 | |
| 1580 | const char * |
| 1581 | Thread::RunModeAsCString (lldb::RunMode mode) |
| 1582 | { |
| 1583 | switch (mode) |
| 1584 | { |
| 1585 | case eOnlyThisThread: return "only this thread"; |
| 1586 | case eAllThreads: return "all threads"; |
| 1587 | case eOnlyDuringStepping: return "only during stepping"; |
| 1588 | } |
| 1589 | |
| 1590 | static char unknown_state_string[64]; |
| 1591 | snprintf(unknown_state_string, sizeof (unknown_state_string), "RunMode = %i", mode); |
| 1592 | return unknown_state_string; |
| 1593 | } |
Jim Ingham | 06e827c | 2010-11-11 19:26:09 +0000 | [diff] [blame] | 1594 | |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 1595 | size_t |
| 1596 | Thread::GetStatus (Stream &strm, uint32_t start_frame, uint32_t num_frames, uint32_t num_frames_with_source) |
| 1597 | { |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 1598 | ExecutionContext exe_ctx (shared_from_this()); |
| 1599 | Target *target = exe_ctx.GetTargetPtr(); |
| 1600 | Process *process = exe_ctx.GetProcessPtr(); |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 1601 | size_t num_frames_shown = 0; |
| 1602 | strm.Indent(); |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 1603 | bool is_selected = false; |
| 1604 | if (process) |
| 1605 | { |
| 1606 | if (process->GetThreadList().GetSelectedThread().get() == this) |
| 1607 | is_selected = true; |
| 1608 | } |
| 1609 | strm.Printf("%c ", is_selected ? '*' : ' '); |
| 1610 | if (target && target->GetDebugger().GetUseExternalEditor()) |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 1611 | { |
Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 1612 | StackFrameSP frame_sp = GetStackFrameAtIndex(start_frame); |
Jim Ingham | e610d64 | 2011-08-16 00:07:28 +0000 | [diff] [blame] | 1613 | if (frame_sp) |
Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 1614 | { |
Jim Ingham | e610d64 | 2011-08-16 00:07:28 +0000 | [diff] [blame] | 1615 | SymbolContext frame_sc(frame_sp->GetSymbolContext (eSymbolContextLineEntry)); |
| 1616 | if (frame_sc.line_entry.line != 0 && frame_sc.line_entry.file) |
| 1617 | { |
| 1618 | Host::OpenFileInExternalEditor (frame_sc.line_entry.file, frame_sc.line_entry.line); |
| 1619 | } |
Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 1620 | } |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 1621 | } |
| 1622 | |
| 1623 | DumpUsingSettingsFormat (strm, start_frame); |
| 1624 | |
| 1625 | if (num_frames > 0) |
| 1626 | { |
| 1627 | strm.IndentMore(); |
| 1628 | |
| 1629 | const bool show_frame_info = true; |
Jim Ingham | 5c4df7a | 2011-07-26 02:39:59 +0000 | [diff] [blame] | 1630 | strm.IndentMore (); |
Greg Clayton | 39d0ab3 | 2012-03-29 01:41:38 +0000 | [diff] [blame] | 1631 | num_frames_shown = GetStackFrameList ()->GetStatus (strm, |
| 1632 | start_frame, |
| 1633 | num_frames, |
| 1634 | show_frame_info, |
Greg Clayton | 53eb7ad | 2012-07-11 20:33:48 +0000 | [diff] [blame] | 1635 | num_frames_with_source); |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 1636 | strm.IndentLess(); |
Jim Ingham | 5c4df7a | 2011-07-26 02:39:59 +0000 | [diff] [blame] | 1637 | strm.IndentLess(); |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 1638 | } |
| 1639 | return num_frames_shown; |
| 1640 | } |
| 1641 | |
| 1642 | size_t |
| 1643 | Thread::GetStackFrameStatus (Stream& strm, |
| 1644 | uint32_t first_frame, |
| 1645 | uint32_t num_frames, |
| 1646 | bool show_frame_info, |
Greg Clayton | 53eb7ad | 2012-07-11 20:33:48 +0000 | [diff] [blame] | 1647 | uint32_t num_frames_with_source) |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 1648 | { |
Greg Clayton | 39d0ab3 | 2012-03-29 01:41:38 +0000 | [diff] [blame] | 1649 | return GetStackFrameList()->GetStatus (strm, |
| 1650 | first_frame, |
| 1651 | num_frames, |
| 1652 | show_frame_info, |
Greg Clayton | 53eb7ad | 2012-07-11 20:33:48 +0000 | [diff] [blame] | 1653 | num_frames_with_source); |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 1654 | } |
| 1655 | |
Peter Collingbourne | 5a6fa54 | 2011-06-03 20:40:54 +0000 | [diff] [blame] | 1656 | bool |
| 1657 | Thread::SaveFrameZeroState (RegisterCheckpoint &checkpoint) |
| 1658 | { |
| 1659 | lldb::StackFrameSP frame_sp(GetStackFrameAtIndex (0)); |
| 1660 | if (frame_sp) |
| 1661 | { |
| 1662 | checkpoint.SetStackID(frame_sp->GetStackID()); |
| 1663 | return frame_sp->GetRegisterContext()->ReadAllRegisterValues (checkpoint.GetData()); |
| 1664 | } |
| 1665 | return false; |
| 1666 | } |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 1667 | |
Peter Collingbourne | 5a6fa54 | 2011-06-03 20:40:54 +0000 | [diff] [blame] | 1668 | bool |
| 1669 | Thread::RestoreSaveFrameZero (const RegisterCheckpoint &checkpoint) |
| 1670 | { |
Jim Ingham | 4413758 | 2012-09-12 00:40:39 +0000 | [diff] [blame] | 1671 | return ResetFrameZeroRegisters (checkpoint.GetData()); |
| 1672 | } |
| 1673 | |
| 1674 | bool |
| 1675 | Thread::ResetFrameZeroRegisters (lldb::DataBufferSP register_data_sp) |
| 1676 | { |
Peter Collingbourne | 5a6fa54 | 2011-06-03 20:40:54 +0000 | [diff] [blame] | 1677 | lldb::StackFrameSP frame_sp(GetStackFrameAtIndex (0)); |
| 1678 | if (frame_sp) |
| 1679 | { |
Jim Ingham | 4413758 | 2012-09-12 00:40:39 +0000 | [diff] [blame] | 1680 | bool ret = frame_sp->GetRegisterContext()->WriteAllRegisterValues (register_data_sp); |
Peter Collingbourne | 5a6fa54 | 2011-06-03 20:40:54 +0000 | [diff] [blame] | 1681 | |
| 1682 | // Clear out all stack frames as our world just changed. |
| 1683 | ClearStackFrames(); |
| 1684 | frame_sp->GetRegisterContext()->InvalidateIfNeeded(true); |
Jason Molenda | d525d07 | 2012-11-14 04:26:02 +0000 | [diff] [blame] | 1685 | if (m_unwinder_ap.get()) |
| 1686 | m_unwinder_ap->Clear(); |
Peter Collingbourne | 5a6fa54 | 2011-06-03 20:40:54 +0000 | [diff] [blame] | 1687 | |
| 1688 | return ret; |
| 1689 | } |
| 1690 | return false; |
| 1691 | } |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 1692 | |
Greg Clayton | 56d9a1b | 2011-08-22 02:49:39 +0000 | [diff] [blame] | 1693 | Unwind * |
| 1694 | Thread::GetUnwinder () |
| 1695 | { |
| 1696 | if (m_unwinder_ap.get() == NULL) |
| 1697 | { |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 1698 | const ArchSpec target_arch (CalculateTarget()->GetArchitecture ()); |
Greg Clayton | 56d9a1b | 2011-08-22 02:49:39 +0000 | [diff] [blame] | 1699 | const llvm::Triple::ArchType machine = target_arch.GetMachine(); |
| 1700 | switch (machine) |
| 1701 | { |
| 1702 | case llvm::Triple::x86_64: |
| 1703 | case llvm::Triple::x86: |
| 1704 | case llvm::Triple::arm: |
| 1705 | case llvm::Triple::thumb: |
| 1706 | m_unwinder_ap.reset (new UnwindLLDB (*this)); |
| 1707 | break; |
| 1708 | |
| 1709 | default: |
| 1710 | if (target_arch.GetTriple().getVendor() == llvm::Triple::Apple) |
| 1711 | m_unwinder_ap.reset (new UnwindMacOSXFrameBackchain (*this)); |
| 1712 | break; |
| 1713 | } |
| 1714 | } |
| 1715 | return m_unwinder_ap.get(); |
| 1716 | } |
| 1717 | |
| 1718 | |
Greg Clayton | fa559e5 | 2012-05-18 02:38:05 +0000 | [diff] [blame] | 1719 | void |
| 1720 | Thread::Flush () |
| 1721 | { |
| 1722 | ClearStackFrames (); |
| 1723 | m_reg_context_sp.reset(); |
| 1724 | } |
Jim Ingham | 5d88a06 | 2012-10-16 00:09:33 +0000 | [diff] [blame] | 1725 | |
| 1726 | const bool |
| 1727 | Thread::IsStillAtLastBreakpointHit () |
| 1728 | { |
| 1729 | // If we are currently stopped at a breakpoint, always return that stopinfo and don't reset it. |
| 1730 | // This allows threads to maintain their breakpoint stopinfo, such as when thread-stepping in |
| 1731 | // multithreaded programs. |
| 1732 | if (m_actual_stop_info_sp) { |
| 1733 | StopReason stop_reason = m_actual_stop_info_sp->GetStopReason(); |
| 1734 | if (stop_reason == lldb::eStopReasonBreakpoint) { |
| 1735 | uint64_t value = m_actual_stop_info_sp->GetValue(); |
| 1736 | lldb::addr_t pc = GetRegisterContext()->GetPC(); |
| 1737 | BreakpointSiteSP bp_site_sp = GetProcess()->GetBreakpointSiteList().FindByAddress(pc); |
| 1738 | if (bp_site_sp && value == bp_site_sp->GetID()) |
| 1739 | return true; |
| 1740 | } |
| 1741 | } |
| 1742 | return false; |
| 1743 | } |