Chris Lattner | 24943d2 | 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 | 3c7b5b9 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 11 | #include "lldb/Breakpoint/BreakpointLocation.h" |
Greg Clayton | a830adb | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 12 | #include "lldb/Core/Debugger.h" |
Chris Lattner | 24943d2 | 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 | 20594b1 | 2010-09-08 03:14:33 +0000 | [diff] [blame] | 16 | #include "lldb/Core/RegularExpression.h" |
Greg Clayton | abe0fed | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 17 | #include "lldb/Host/Host.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 18 | #include "lldb/Target/DynamicLoader.h" |
| 19 | #include "lldb/Target/ExecutionContext.h" |
Jim Ingham | b66cd07 | 2010-09-28 01:25:32 +0000 | [diff] [blame] | 20 | #include "lldb/Target/ObjCLanguageRuntime.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 21 | #include "lldb/Target/Process.h" |
| 22 | #include "lldb/Target/RegisterContext.h" |
Greg Clayton | 643ee73 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 23 | #include "lldb/Target/StopInfo.h" |
Greg Clayton | 7661a98 | 2010-07-23 16:45:51 +0000 | [diff] [blame] | 24 | #include "lldb/Target/Target.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 25 | #include "lldb/Target/Thread.h" |
| 26 | #include "lldb/Target/ThreadPlan.h" |
| 27 | #include "lldb/Target/ThreadPlanCallFunction.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 28 | #include "lldb/Target/ThreadPlanBase.h" |
| 29 | #include "lldb/Target/ThreadPlanStepInstruction.h" |
| 30 | #include "lldb/Target/ThreadPlanStepOut.h" |
| 31 | #include "lldb/Target/ThreadPlanStepOverBreakpoint.h" |
| 32 | #include "lldb/Target/ThreadPlanStepThrough.h" |
| 33 | #include "lldb/Target/ThreadPlanStepInRange.h" |
| 34 | #include "lldb/Target/ThreadPlanStepOverRange.h" |
| 35 | #include "lldb/Target/ThreadPlanRunToAddress.h" |
| 36 | #include "lldb/Target/ThreadPlanStepUntil.h" |
Jim Ingham | 3c7b5b9 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 37 | #include "lldb/Target/ThreadSpec.h" |
Jim Ingham | 7121908 | 2010-08-12 02:14:28 +0000 | [diff] [blame] | 38 | #include "lldb/Target/Unwind.h" |
Greg Clayton | 37f962e | 2011-08-22 02:49:39 +0000 | [diff] [blame] | 39 | #include "Plugins/Process/Utility/UnwindLLDB.h" |
| 40 | #include "UnwindMacOSXFrameBackchain.h" |
| 41 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 42 | |
| 43 | using namespace lldb; |
| 44 | using namespace lldb_private; |
| 45 | |
Greg Clayton | 73844aa | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 46 | |
| 47 | const ThreadPropertiesSP & |
| 48 | Thread::GetGlobalProperties() |
| 49 | { |
| 50 | static ThreadPropertiesSP g_settings_sp; |
| 51 | if (!g_settings_sp) |
| 52 | g_settings_sp.reset (new ThreadProperties (true)); |
| 53 | return g_settings_sp; |
| 54 | } |
| 55 | |
| 56 | static PropertyDefinition |
| 57 | g_properties[] = |
| 58 | { |
| 59 | { "step-avoid-regexp", OptionValue::eTypeRegex , true , REG_EXTENDED, "^std::", NULL, "A regular expression defining functions step-in won't stop in." }, |
| 60 | { "trace-thread", OptionValue::eTypeBoolean, false, false, NULL, NULL, "If true, this thread will single-step and log execution." }, |
| 61 | { NULL , OptionValue::eTypeInvalid, false, 0 , NULL, NULL, NULL } |
| 62 | }; |
| 63 | |
| 64 | enum { |
| 65 | ePropertyStepAvoidRegex, |
| 66 | ePropertyEnableThreadTrace |
| 67 | }; |
| 68 | |
| 69 | |
| 70 | class ThreadOptionValueProperties : public OptionValueProperties |
| 71 | { |
| 72 | public: |
| 73 | ThreadOptionValueProperties (const ConstString &name) : |
| 74 | OptionValueProperties (name) |
| 75 | { |
| 76 | } |
| 77 | |
| 78 | // This constructor is used when creating ThreadOptionValueProperties when it |
| 79 | // is part of a new lldb_private::Thread instance. It will copy all current |
| 80 | // global property values as needed |
| 81 | ThreadOptionValueProperties (ThreadProperties *global_properties) : |
Greg Clayton | c6e82e4 | 2012-08-22 18:39:03 +0000 | [diff] [blame] | 82 | OptionValueProperties(*global_properties->GetValueProperties()) |
Greg Clayton | 73844aa | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 83 | { |
| 84 | } |
| 85 | |
| 86 | virtual const Property * |
| 87 | GetPropertyAtIndex (const ExecutionContext *exe_ctx, bool will_modify, uint32_t idx) const |
| 88 | { |
| 89 | // When gettings the value for a key from the thread options, we will always |
| 90 | // try and grab the setting from the current thread if there is one. Else we just |
| 91 | // use the one from this instance. |
| 92 | if (exe_ctx) |
| 93 | { |
| 94 | Thread *thread = exe_ctx->GetThreadPtr(); |
| 95 | if (thread) |
| 96 | { |
| 97 | ThreadOptionValueProperties *instance_properties = static_cast<ThreadOptionValueProperties *>(thread->GetValueProperties().get()); |
| 98 | if (this != instance_properties) |
| 99 | return instance_properties->ProtectedGetPropertyAtIndex (idx); |
| 100 | } |
| 101 | } |
| 102 | return ProtectedGetPropertyAtIndex (idx); |
| 103 | } |
| 104 | }; |
| 105 | |
| 106 | |
| 107 | |
| 108 | ThreadProperties::ThreadProperties (bool is_global) : |
| 109 | Properties () |
| 110 | { |
| 111 | if (is_global) |
| 112 | { |
| 113 | m_collection_sp.reset (new ThreadOptionValueProperties(ConstString("thread"))); |
| 114 | m_collection_sp->Initialize(g_properties); |
| 115 | } |
| 116 | else |
| 117 | m_collection_sp.reset (new ThreadOptionValueProperties(Thread::GetGlobalProperties().get())); |
| 118 | } |
| 119 | |
| 120 | ThreadProperties::~ThreadProperties() |
| 121 | { |
| 122 | } |
| 123 | |
| 124 | const RegularExpression * |
| 125 | ThreadProperties::GetSymbolsToAvoidRegexp() |
| 126 | { |
| 127 | const uint32_t idx = ePropertyStepAvoidRegex; |
| 128 | return m_collection_sp->GetPropertyAtIndexAsOptionValueRegex (NULL, idx); |
| 129 | } |
| 130 | |
| 131 | bool |
| 132 | ThreadProperties::GetTraceEnabledState() const |
| 133 | { |
| 134 | const uint32_t idx = ePropertyEnableThreadTrace; |
| 135 | return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0); |
| 136 | } |
| 137 | |
| 138 | |
Greg Clayton | f4124de | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 139 | Thread::Thread (const ProcessSP &process_sp, lldb::tid_t tid) : |
Greg Clayton | 73844aa | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 140 | ThreadProperties (false), |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 141 | UserID (tid), |
Greg Clayton | f4124de | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 142 | m_process_wp (process_sp), |
Greg Clayton | 643ee73 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 143 | m_actual_stop_info_sp (), |
Greg Clayton | f4124de | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 144 | m_index_id (process_sp->GetNextThreadIndexID ()), |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 145 | m_reg_context_sp (), |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 146 | m_state (eStateUnloaded), |
Greg Clayton | 782b9cc | 2010-08-25 00:35:26 +0000 | [diff] [blame] | 147 | m_state_mutex (Mutex::eMutexTypeRecursive), |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 148 | m_plan_stack (), |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 149 | m_completed_plan_stack(), |
Greg Clayton | 2450cb1 | 2012-03-29 01:41:38 +0000 | [diff] [blame] | 150 | m_frame_mutex (Mutex::eMutexTypeRecursive), |
Greg Clayton | c51ffbf | 2011-08-12 21:40:01 +0000 | [diff] [blame] | 151 | m_curr_frames_sp (), |
| 152 | m_prev_frames_sp (), |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 153 | m_resume_signal (LLDB_INVALID_SIGNAL_NUMBER), |
Jim Ingham | 7121908 | 2010-08-12 02:14:28 +0000 | [diff] [blame] | 154 | m_resume_state (eStateRunning), |
Jim Ingham | 149d1f5 | 2012-01-31 23:09:20 +0000 | [diff] [blame] | 155 | m_temporary_resume_state (eStateRunning), |
Jim Ingham | cdea236 | 2010-11-18 02:47:07 +0000 | [diff] [blame] | 156 | m_unwinder_ap (), |
Jim Ingham | 15dcb7c | 2011-01-20 02:03:18 +0000 | [diff] [blame] | 157 | m_destroy_called (false), |
| 158 | m_thread_stop_reason_stop_id (0) |
Jim Ingham | 7121908 | 2010-08-12 02:14:28 +0000 | [diff] [blame] | 159 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 160 | { |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 161 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT)); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 162 | if (log) |
Greg Clayton | 444e35b | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 163 | log->Printf ("%p Thread::Thread(tid = 0x%4.4llx)", this, GetID()); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 164 | |
| 165 | QueueFundamentalPlan(true); |
| 166 | } |
| 167 | |
| 168 | |
| 169 | Thread::~Thread() |
| 170 | { |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 171 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT)); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 172 | if (log) |
Greg Clayton | 444e35b | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 173 | log->Printf ("%p Thread::~Thread(tid = 0x%4.4llx)", this, GetID()); |
Jim Ingham | cdea236 | 2010-11-18 02:47:07 +0000 | [diff] [blame] | 174 | /// If you hit this assert, it means your derived class forgot to call DoDestroy in its destructor. |
| 175 | assert (m_destroy_called); |
| 176 | } |
| 177 | |
| 178 | void |
| 179 | Thread::DestroyThread () |
| 180 | { |
| 181 | m_plan_stack.clear(); |
| 182 | m_discarded_plan_stack.clear(); |
| 183 | m_completed_plan_stack.clear(); |
Jim Ingham | e93055a | 2012-04-10 00:44:25 +0000 | [diff] [blame] | 184 | m_actual_stop_info_sp.reset(); |
Jim Ingham | cdea236 | 2010-11-18 02:47:07 +0000 | [diff] [blame] | 185 | m_destroy_called = true; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 186 | } |
| 187 | |
Jim Ingham | 6297a3a | 2010-10-20 00:39:53 +0000 | [diff] [blame] | 188 | lldb::StopInfoSP |
Greg Clayton | 643ee73 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 189 | Thread::GetStopInfo () |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 190 | { |
Jim Ingham | 6297a3a | 2010-10-20 00:39:53 +0000 | [diff] [blame] | 191 | ThreadPlanSP plan_sp (GetCompletedPlan()); |
Jim Ingham | 707b7a8 | 2012-05-01 18:38:37 +0000 | [diff] [blame] | 192 | if (plan_sp && plan_sp->PlanSucceeded()) |
Jim Ingham | 1586d97 | 2011-12-17 01:35:57 +0000 | [diff] [blame] | 193 | return StopInfo::CreateStopReasonWithPlan (plan_sp, GetReturnValueObject()); |
Jim Ingham | 6297a3a | 2010-10-20 00:39:53 +0000 | [diff] [blame] | 194 | else |
Jim Ingham | 24e0d61 | 2011-08-09 00:32:52 +0000 | [diff] [blame] | 195 | { |
Greg Clayton | f4124de | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 196 | ProcessSP process_sp (GetProcess()); |
| 197 | if (process_sp |
| 198 | && m_actual_stop_info_sp |
Jim Ingham | 24e0d61 | 2011-08-09 00:32:52 +0000 | [diff] [blame] | 199 | && m_actual_stop_info_sp->IsValid() |
Greg Clayton | f4124de | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 200 | && m_thread_stop_reason_stop_id == process_sp->GetStopID()) |
Jim Ingham | 24e0d61 | 2011-08-09 00:32:52 +0000 | [diff] [blame] | 201 | return m_actual_stop_info_sp; |
| 202 | else |
| 203 | return GetPrivateStopReason (); |
| 204 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 205 | } |
| 206 | |
Jim Ingham | 15dcb7c | 2011-01-20 02:03:18 +0000 | [diff] [blame] | 207 | void |
| 208 | Thread::SetStopInfo (const lldb::StopInfoSP &stop_info_sp) |
| 209 | { |
| 210 | m_actual_stop_info_sp = stop_info_sp; |
Jim Ingham | 24e0d61 | 2011-08-09 00:32:52 +0000 | [diff] [blame] | 211 | if (m_actual_stop_info_sp) |
| 212 | m_actual_stop_info_sp->MakeStopInfoValid(); |
Greg Clayton | f4124de | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 213 | ProcessSP process_sp (GetProcess()); |
| 214 | if (process_sp) |
| 215 | m_thread_stop_reason_stop_id = process_sp->GetStopID(); |
| 216 | else |
| 217 | m_thread_stop_reason_stop_id = UINT32_MAX; |
Jim Ingham | 15dcb7c | 2011-01-20 02:03:18 +0000 | [diff] [blame] | 218 | } |
| 219 | |
| 220 | void |
| 221 | Thread::SetStopInfoToNothing() |
| 222 | { |
| 223 | // Note, we can't just NULL out the private reason, or the native thread implementation will try to |
| 224 | // go calculate it again. For now, just set it to a Unix Signal with an invalid signal number. |
| 225 | SetStopInfo (StopInfo::CreateStopReasonWithSignal (*this, LLDB_INVALID_SIGNAL_NUMBER)); |
| 226 | } |
| 227 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 228 | bool |
| 229 | Thread::ThreadStoppedForAReason (void) |
| 230 | { |
Jim Ingham | 9880efa | 2012-08-11 00:35:26 +0000 | [diff] [blame] | 231 | return (bool) GetPrivateStopReason (); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 232 | } |
| 233 | |
Jim Ingham | 15dcb7c | 2011-01-20 02:03:18 +0000 | [diff] [blame] | 234 | bool |
| 235 | Thread::CheckpointThreadState (ThreadStateCheckpoint &saved_state) |
| 236 | { |
| 237 | if (!SaveFrameZeroState(saved_state.register_backup)) |
| 238 | return false; |
| 239 | |
| 240 | saved_state.stop_info_sp = GetStopInfo(); |
Greg Clayton | f4124de | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 241 | ProcessSP process_sp (GetProcess()); |
| 242 | if (process_sp) |
| 243 | saved_state.orig_stop_id = process_sp->GetStopID(); |
Jim Ingham | 15dcb7c | 2011-01-20 02:03:18 +0000 | [diff] [blame] | 244 | return true; |
| 245 | } |
| 246 | |
| 247 | bool |
| 248 | Thread::RestoreThreadStateFromCheckpoint (ThreadStateCheckpoint &saved_state) |
| 249 | { |
| 250 | RestoreSaveFrameZero(saved_state.register_backup); |
Jim Ingham | 11a837d | 2011-01-25 02:47:23 +0000 | [diff] [blame] | 251 | if (saved_state.stop_info_sp) |
| 252 | saved_state.stop_info_sp->MakeStopInfoValid(); |
Jim Ingham | 15dcb7c | 2011-01-20 02:03:18 +0000 | [diff] [blame] | 253 | SetStopInfo(saved_state.stop_info_sp); |
| 254 | return true; |
| 255 | } |
| 256 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 257 | StateType |
| 258 | Thread::GetState() const |
| 259 | { |
| 260 | // If any other threads access this we will need a mutex for it |
| 261 | Mutex::Locker locker(m_state_mutex); |
| 262 | return m_state; |
| 263 | } |
| 264 | |
| 265 | void |
| 266 | Thread::SetState(StateType state) |
| 267 | { |
| 268 | Mutex::Locker locker(m_state_mutex); |
| 269 | m_state = state; |
| 270 | } |
| 271 | |
| 272 | void |
| 273 | Thread::WillStop() |
| 274 | { |
| 275 | ThreadPlan *current_plan = GetCurrentPlan(); |
| 276 | |
| 277 | // FIXME: I may decide to disallow threads with no plans. In which |
| 278 | // case this should go to an assert. |
| 279 | |
| 280 | if (!current_plan) |
| 281 | return; |
| 282 | |
| 283 | current_plan->WillStop(); |
| 284 | } |
| 285 | |
| 286 | void |
| 287 | Thread::SetupForResume () |
| 288 | { |
| 289 | if (GetResumeState() != eStateSuspended) |
| 290 | { |
| 291 | |
| 292 | // If we're at a breakpoint push the step-over breakpoint plan. Do this before |
| 293 | // telling the current plan it will resume, since we might change what the current |
| 294 | // plan is. |
| 295 | |
| 296 | lldb::addr_t pc = GetRegisterContext()->GetPC(); |
Greg Clayton | f4124de | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 297 | BreakpointSiteSP bp_site_sp = GetProcess()->GetBreakpointSiteList().FindByAddress(pc); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 298 | if (bp_site_sp && bp_site_sp->IsEnabled()) |
| 299 | { |
| 300 | // Note, don't assume there's a ThreadPlanStepOverBreakpoint, the target may not require anything |
| 301 | // special to step over a breakpoint. |
Jim Ingham | 5a47e8b | 2010-06-19 04:45:32 +0000 | [diff] [blame] | 302 | |
| 303 | ThreadPlan *cur_plan = GetCurrentPlan(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 304 | |
Jim Ingham | 5a47e8b | 2010-06-19 04:45:32 +0000 | [diff] [blame] | 305 | if (cur_plan->GetKind() != ThreadPlan::eKindStepOverBreakpoint) |
| 306 | { |
| 307 | ThreadPlanStepOverBreakpoint *step_bp_plan = new ThreadPlanStepOverBreakpoint (*this); |
| 308 | if (step_bp_plan) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 309 | { |
Jim Ingham | 5a47e8b | 2010-06-19 04:45:32 +0000 | [diff] [blame] | 310 | ThreadPlanSP step_bp_plan_sp; |
| 311 | step_bp_plan->SetPrivate (true); |
| 312 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 313 | if (GetCurrentPlan()->RunState() != eStateStepping) |
| 314 | { |
Jim Ingham | 5a47e8b | 2010-06-19 04:45:32 +0000 | [diff] [blame] | 315 | step_bp_plan->SetAutoContinue(true); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 316 | } |
Jim Ingham | 5a47e8b | 2010-06-19 04:45:32 +0000 | [diff] [blame] | 317 | step_bp_plan_sp.reset (step_bp_plan); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 318 | QueueThreadPlan (step_bp_plan_sp, false); |
| 319 | } |
| 320 | } |
| 321 | } |
| 322 | } |
| 323 | } |
| 324 | |
| 325 | bool |
| 326 | Thread::WillResume (StateType resume_state) |
| 327 | { |
| 328 | // At this point clear the completed plan stack. |
| 329 | m_completed_plan_stack.clear(); |
| 330 | m_discarded_plan_stack.clear(); |
| 331 | |
Jim Ingham | 149d1f5 | 2012-01-31 23:09:20 +0000 | [diff] [blame] | 332 | SetTemporaryResumeState(resume_state); |
| 333 | |
| 334 | // This is a little dubious, but we are trying to limit how often we actually fetch stop info from |
| 335 | // the target, 'cause that slows down single stepping. So assume that if we got to the point where |
| 336 | // we're about to resume, and we haven't yet had to fetch the stop reason, then it doesn't need to know |
| 337 | // about the fact that we are resuming... |
Greg Clayton | f4124de | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 338 | const uint32_t process_stop_id = GetProcess()->GetStopID(); |
Jim Ingham | 149d1f5 | 2012-01-31 23:09:20 +0000 | [diff] [blame] | 339 | if (m_thread_stop_reason_stop_id == process_stop_id && |
| 340 | (m_actual_stop_info_sp && m_actual_stop_info_sp->IsValid())) |
| 341 | { |
| 342 | StopInfo *stop_info = GetPrivateStopReason().get(); |
| 343 | if (stop_info) |
| 344 | stop_info->WillResume (resume_state); |
| 345 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 346 | |
| 347 | // Tell all the plans that we are about to resume in case they need to clear any state. |
| 348 | // We distinguish between the plan on the top of the stack and the lower |
| 349 | // plans in case a plan needs to do any special business before it runs. |
| 350 | |
| 351 | ThreadPlan *plan_ptr = GetCurrentPlan(); |
| 352 | plan_ptr->WillResume(resume_state, true); |
| 353 | |
| 354 | while ((plan_ptr = GetPreviousPlan(plan_ptr)) != NULL) |
| 355 | { |
| 356 | plan_ptr->WillResume (resume_state, false); |
| 357 | } |
Greg Clayton | 643ee73 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 358 | |
Greg Clayton | 643ee73 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 359 | m_actual_stop_info_sp.reset(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 360 | return true; |
| 361 | } |
| 362 | |
| 363 | void |
| 364 | Thread::DidResume () |
| 365 | { |
| 366 | SetResumeSignal (LLDB_INVALID_SIGNAL_NUMBER); |
| 367 | } |
| 368 | |
| 369 | bool |
| 370 | Thread::ShouldStop (Event* event_ptr) |
| 371 | { |
| 372 | ThreadPlan *current_plan = GetCurrentPlan(); |
| 373 | bool should_stop = true; |
| 374 | |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 375 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); |
Jim Ingham | 149d1f5 | 2012-01-31 23:09:20 +0000 | [diff] [blame] | 376 | |
| 377 | if (GetResumeState () == eStateSuspended) |
| 378 | { |
| 379 | if (log) |
| 380 | log->Printf ("Thread::%s for tid = 0x%4.4llx, should_stop = 0 (ignore since thread was suspended)", |
| 381 | __FUNCTION__, |
| 382 | GetID ()); |
| 383 | // log->Printf ("Thread::%s for tid = 0x%4.4llx, pc = 0x%16.16llx, should_stop = 0 (ignore since thread was suspended)", |
| 384 | // __FUNCTION__, |
| 385 | // GetID (), |
| 386 | // GetRegisterContext()->GetPC()); |
| 387 | return false; |
| 388 | } |
| 389 | |
| 390 | if (GetTemporaryResumeState () == eStateSuspended) |
| 391 | { |
| 392 | if (log) |
| 393 | log->Printf ("Thread::%s for tid = 0x%4.4llx, should_stop = 0 (ignore since thread was suspended)", |
| 394 | __FUNCTION__, |
| 395 | GetID ()); |
| 396 | // log->Printf ("Thread::%s for tid = 0x%4.4llx, pc = 0x%16.16llx, should_stop = 0 (ignore since thread was suspended)", |
| 397 | // __FUNCTION__, |
| 398 | // GetID (), |
| 399 | // GetRegisterContext()->GetPC()); |
| 400 | return false; |
| 401 | } |
| 402 | |
| 403 | if (ThreadStoppedForAReason() == false) |
| 404 | { |
| 405 | if (log) |
| 406 | log->Printf ("Thread::%s for tid = 0x%4.4llx, pc = 0x%16.16llx, should_stop = 0 (ignore since no stop reason)", |
| 407 | __FUNCTION__, |
| 408 | GetID (), |
| 409 | GetRegisterContext()->GetPC()); |
| 410 | return false; |
| 411 | } |
| 412 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 413 | if (log) |
| 414 | { |
Jim Ingham | 149d1f5 | 2012-01-31 23:09:20 +0000 | [diff] [blame] | 415 | log->Printf ("Thread::%s for tid = 0x%4.4llx, pc = 0x%16.16llx", |
| 416 | __FUNCTION__, |
| 417 | GetID (), |
| 418 | GetRegisterContext()->GetPC()); |
Jim Ingham | e8f4e11 | 2011-10-15 00:23:43 +0000 | [diff] [blame] | 419 | log->Printf ("^^^^^^^^ Thread::ShouldStop Begin ^^^^^^^^"); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 420 | StreamString s; |
Jim Ingham | e8f4e11 | 2011-10-15 00:23:43 +0000 | [diff] [blame] | 421 | s.IndentMore(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 422 | DumpThreadPlans(&s); |
Jim Ingham | e8f4e11 | 2011-10-15 00:23:43 +0000 | [diff] [blame] | 423 | log->Printf ("Plan stack initial state:\n%s", s.GetData()); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 424 | } |
Jim Ingham | 745ac7a | 2010-11-11 19:26:09 +0000 | [diff] [blame] | 425 | |
| 426 | // The top most plan always gets to do the trace log... |
| 427 | current_plan->DoTraceLog (); |
Jim Ingham | e787c7e | 2012-04-20 21:16:56 +0000 | [diff] [blame] | 428 | |
| 429 | // First query the stop info's ShouldStopSynchronous. This handles "synchronous" stop reasons, for example the breakpoint |
| 430 | // command on internal breakpoints. If a synchronous stop reason says we should not stop, then we don't have to |
| 431 | // do any more work on this stop. |
| 432 | StopInfoSP private_stop_info (GetPrivateStopReason()); |
| 433 | if (private_stop_info && private_stop_info->ShouldStopSynchronous(event_ptr) == false) |
| 434 | { |
| 435 | if (log) |
| 436 | log->Printf ("StopInfo::ShouldStop async callback says we should not stop, returning ShouldStop of false."); |
| 437 | return false; |
| 438 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 439 | |
Jim Ingham | ad382c5 | 2011-12-03 01:52:59 +0000 | [diff] [blame] | 440 | // If the base plan doesn't understand why we stopped, then we have to find a plan that does. |
| 441 | // If that plan is still working, then we don't need to do any more work. If the plan that explains |
| 442 | // the stop is done, then we should pop all the plans below it, and pop it, and then let the plans above it decide |
| 443 | // whether they still need to do more work. |
| 444 | |
| 445 | bool done_processing_current_plan = false; |
| 446 | |
| 447 | if (!current_plan->PlanExplainsStop()) |
| 448 | { |
| 449 | if (current_plan->TracerExplainsStop()) |
| 450 | { |
| 451 | done_processing_current_plan = true; |
| 452 | should_stop = false; |
| 453 | } |
| 454 | else |
| 455 | { |
Jim Ingham | 2bcbaf6 | 2012-04-09 22:37:39 +0000 | [diff] [blame] | 456 | // If the current plan doesn't explain the stop, then find one that |
Jim Ingham | ad382c5 | 2011-12-03 01:52:59 +0000 | [diff] [blame] | 457 | // does and let it handle the situation. |
| 458 | ThreadPlan *plan_ptr = current_plan; |
| 459 | while ((plan_ptr = GetPreviousPlan(plan_ptr)) != NULL) |
| 460 | { |
| 461 | if (plan_ptr->PlanExplainsStop()) |
| 462 | { |
| 463 | should_stop = plan_ptr->ShouldStop (event_ptr); |
| 464 | |
| 465 | // plan_ptr explains the stop, next check whether plan_ptr is done, if so, then we should take it |
| 466 | // and all the plans below it off the stack. |
| 467 | |
| 468 | if (plan_ptr->MischiefManaged()) |
| 469 | { |
Jim Ingham | d1ec3d6 | 2012-05-11 23:49:49 +0000 | [diff] [blame] | 470 | // We're going to pop the plans up to and including the plan that explains the stop. |
Jim Ingham | d82bc6d | 2012-05-11 23:47:32 +0000 | [diff] [blame] | 471 | ThreadPlan *prev_plan_ptr = GetPreviousPlan (plan_ptr); |
Jim Ingham | ad382c5 | 2011-12-03 01:52:59 +0000 | [diff] [blame] | 472 | |
| 473 | do |
| 474 | { |
| 475 | if (should_stop) |
| 476 | current_plan->WillStop(); |
| 477 | PopPlan(); |
| 478 | } |
Jim Ingham | d82bc6d | 2012-05-11 23:47:32 +0000 | [diff] [blame] | 479 | while ((current_plan = GetCurrentPlan()) != prev_plan_ptr); |
| 480 | // Now, if the responsible plan was not "Okay to discard" then we're done, |
| 481 | // otherwise we forward this to the next plan in the stack below. |
| 482 | if (plan_ptr->IsMasterPlan() && !plan_ptr->OkayToDiscard()) |
| 483 | done_processing_current_plan = true; |
| 484 | else |
| 485 | done_processing_current_plan = false; |
Jim Ingham | ad382c5 | 2011-12-03 01:52:59 +0000 | [diff] [blame] | 486 | } |
| 487 | else |
| 488 | done_processing_current_plan = true; |
| 489 | |
| 490 | break; |
| 491 | } |
| 492 | |
| 493 | } |
| 494 | } |
| 495 | } |
| 496 | |
| 497 | if (!done_processing_current_plan) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 498 | { |
Jim Ingham | 5a47e8b | 2010-06-19 04:45:32 +0000 | [diff] [blame] | 499 | bool over_ride_stop = current_plan->ShouldAutoContinue(event_ptr); |
Jim Ingham | f9f40c2 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 500 | |
Jim Ingham | e8f4e11 | 2011-10-15 00:23:43 +0000 | [diff] [blame] | 501 | if (log) |
| 502 | log->Printf("Plan %s explains stop, auto-continue %i.", current_plan->GetName(), over_ride_stop); |
| 503 | |
Jim Ingham | f9f40c2 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 504 | // We're starting from the base plan, so just let it decide; |
| 505 | if (PlanIsBasePlan(current_plan)) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 506 | { |
Jim Ingham | f9f40c2 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 507 | should_stop = current_plan->ShouldStop (event_ptr); |
| 508 | if (log) |
Greg Clayton | 628cead | 2011-05-19 03:54:16 +0000 | [diff] [blame] | 509 | log->Printf("Base plan says should stop: %i.", should_stop); |
Jim Ingham | f9f40c2 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 510 | } |
| 511 | else |
| 512 | { |
| 513 | // Otherwise, don't let the base plan override what the other plans say to do, since |
| 514 | // presumably if there were other plans they would know what to do... |
| 515 | while (1) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 516 | { |
Jim Ingham | f9f40c2 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 517 | if (PlanIsBasePlan(current_plan)) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 518 | break; |
Jim Ingham | f9f40c2 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 519 | |
| 520 | should_stop = current_plan->ShouldStop(event_ptr); |
| 521 | if (log) |
| 522 | log->Printf("Plan %s should stop: %d.", current_plan->GetName(), should_stop); |
| 523 | if (current_plan->MischiefManaged()) |
| 524 | { |
| 525 | if (should_stop) |
| 526 | current_plan->WillStop(); |
| 527 | |
| 528 | // If a Master Plan wants to stop, and wants to stick on the stack, we let it. |
| 529 | // Otherwise, see if the plan's parent wants to stop. |
| 530 | |
| 531 | if (should_stop && current_plan->IsMasterPlan() && !current_plan->OkayToDiscard()) |
| 532 | { |
| 533 | PopPlan(); |
| 534 | break; |
| 535 | } |
| 536 | else |
| 537 | { |
| 538 | |
| 539 | PopPlan(); |
| 540 | |
| 541 | current_plan = GetCurrentPlan(); |
| 542 | if (current_plan == NULL) |
| 543 | { |
| 544 | break; |
| 545 | } |
| 546 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 547 | } |
| 548 | else |
| 549 | { |
Jim Ingham | f9f40c2 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 550 | break; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 551 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 552 | } |
| 553 | } |
Jim Ingham | 88e3de2 | 2012-05-03 21:19:36 +0000 | [diff] [blame] | 554 | |
Jim Ingham | 5a47e8b | 2010-06-19 04:45:32 +0000 | [diff] [blame] | 555 | if (over_ride_stop) |
| 556 | should_stop = false; |
Jim Ingham | 88e3de2 | 2012-05-03 21:19:36 +0000 | [diff] [blame] | 557 | |
| 558 | // One other potential problem is that we set up a master plan, then stop in before it is complete - for instance |
| 559 | // by hitting a breakpoint during a step-over - then do some step/finish/etc operations that wind up |
| 560 | // past the end point condition of the initial plan. We don't want to strand the original plan on the stack, |
| 561 | // This code clears stale plans off the stack. |
| 562 | |
| 563 | if (should_stop) |
| 564 | { |
| 565 | ThreadPlan *plan_ptr = GetCurrentPlan(); |
| 566 | while (!PlanIsBasePlan(plan_ptr)) |
| 567 | { |
| 568 | bool stale = plan_ptr->IsPlanStale (); |
| 569 | ThreadPlan *examined_plan = plan_ptr; |
| 570 | plan_ptr = GetPreviousPlan (examined_plan); |
| 571 | |
| 572 | if (stale) |
| 573 | { |
| 574 | if (log) |
| 575 | log->Printf("Plan %s being discarded in cleanup, it says it is already done.", examined_plan->GetName()); |
| 576 | DiscardThreadPlansUpToPlan(examined_plan); |
| 577 | } |
| 578 | } |
| 579 | } |
| 580 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 581 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 582 | |
Jim Ingham | e8f4e11 | 2011-10-15 00:23:43 +0000 | [diff] [blame] | 583 | if (log) |
| 584 | { |
| 585 | StreamString s; |
| 586 | s.IndentMore(); |
| 587 | DumpThreadPlans(&s); |
| 588 | log->Printf ("Plan stack final state:\n%s", s.GetData()); |
| 589 | log->Printf ("vvvvvvvv Thread::ShouldStop End (returning %i) vvvvvvvv", should_stop); |
| 590 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 591 | return should_stop; |
| 592 | } |
| 593 | |
| 594 | Vote |
| 595 | Thread::ShouldReportStop (Event* event_ptr) |
| 596 | { |
| 597 | StateType thread_state = GetResumeState (); |
Jim Ingham | 149d1f5 | 2012-01-31 23:09:20 +0000 | [diff] [blame] | 598 | StateType temp_thread_state = GetTemporaryResumeState(); |
| 599 | |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 600 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); |
Greg Clayton | 5205f0b | 2010-09-03 17:10:42 +0000 | [diff] [blame] | 601 | |
| 602 | if (thread_state == eStateSuspended || thread_state == eStateInvalid) |
| 603 | { |
| 604 | if (log) |
Greg Clayton | 444e35b | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 605 | log->Printf ("Thread::ShouldReportStop() tid = 0x%4.4llx: returning vote %i (state was suspended or invalid)\n", GetID(), eVoteNoOpinion); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 606 | return eVoteNoOpinion; |
Greg Clayton | 5205f0b | 2010-09-03 17:10:42 +0000 | [diff] [blame] | 607 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 608 | |
Jim Ingham | 149d1f5 | 2012-01-31 23:09:20 +0000 | [diff] [blame] | 609 | if (temp_thread_state == eStateSuspended || temp_thread_state == eStateInvalid) |
| 610 | { |
| 611 | if (log) |
| 612 | log->Printf ("Thread::ShouldReportStop() tid = 0x%4.4llx: returning vote %i (temporary state was suspended or invalid)\n", GetID(), eVoteNoOpinion); |
| 613 | return eVoteNoOpinion; |
| 614 | } |
| 615 | |
| 616 | if (!ThreadStoppedForAReason()) |
| 617 | { |
| 618 | if (log) |
| 619 | log->Printf ("Thread::ShouldReportStop() tid = 0x%4.4llx: returning vote %i (thread didn't stop for a reason.)\n", GetID(), eVoteNoOpinion); |
| 620 | return eVoteNoOpinion; |
| 621 | } |
| 622 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 623 | if (m_completed_plan_stack.size() > 0) |
| 624 | { |
| 625 | // Don't use GetCompletedPlan here, since that suppresses private plans. |
Greg Clayton | 5205f0b | 2010-09-03 17:10:42 +0000 | [diff] [blame] | 626 | if (log) |
Greg Clayton | 444e35b | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 627 | log->Printf ("Thread::ShouldReportStop() tid = 0x%4.4llx: returning vote for complete stack's back plan\n", GetID()); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 628 | return m_completed_plan_stack.back()->ShouldReportStop (event_ptr); |
| 629 | } |
| 630 | else |
Greg Clayton | 5205f0b | 2010-09-03 17:10:42 +0000 | [diff] [blame] | 631 | { |
| 632 | if (log) |
Greg Clayton | 444e35b | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 633 | log->Printf ("Thread::ShouldReportStop() tid = 0x%4.4llx: returning vote for current plan\n", GetID()); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 634 | return GetCurrentPlan()->ShouldReportStop (event_ptr); |
Greg Clayton | 5205f0b | 2010-09-03 17:10:42 +0000 | [diff] [blame] | 635 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 636 | } |
| 637 | |
| 638 | Vote |
| 639 | Thread::ShouldReportRun (Event* event_ptr) |
| 640 | { |
| 641 | StateType thread_state = GetResumeState (); |
Jim Ingham | ac95966 | 2011-01-24 06:34:17 +0000 | [diff] [blame] | 642 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 643 | if (thread_state == eStateSuspended |
| 644 | || thread_state == eStateInvalid) |
Jim Ingham | ac95966 | 2011-01-24 06:34:17 +0000 | [diff] [blame] | 645 | { |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 646 | return eVoteNoOpinion; |
Jim Ingham | ac95966 | 2011-01-24 06:34:17 +0000 | [diff] [blame] | 647 | } |
| 648 | |
| 649 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 650 | if (m_completed_plan_stack.size() > 0) |
| 651 | { |
| 652 | // Don't use GetCompletedPlan here, since that suppresses private plans. |
Jim Ingham | ac95966 | 2011-01-24 06:34:17 +0000 | [diff] [blame] | 653 | if (log) |
Greg Clayton | 444e35b | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 654 | log->Printf ("Current Plan for thread %d (0x%4.4llx): %s being asked whether we should report run.", |
Jim Ingham | ac95966 | 2011-01-24 06:34:17 +0000 | [diff] [blame] | 655 | GetIndexID(), |
| 656 | GetID(), |
| 657 | m_completed_plan_stack.back()->GetName()); |
| 658 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 659 | return m_completed_plan_stack.back()->ShouldReportRun (event_ptr); |
| 660 | } |
| 661 | else |
Jim Ingham | ac95966 | 2011-01-24 06:34:17 +0000 | [diff] [blame] | 662 | { |
| 663 | if (log) |
Greg Clayton | 444e35b | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 664 | log->Printf ("Current Plan for thread %d (0x%4.4llx): %s being asked whether we should report run.", |
Jim Ingham | ac95966 | 2011-01-24 06:34:17 +0000 | [diff] [blame] | 665 | GetIndexID(), |
| 666 | GetID(), |
| 667 | GetCurrentPlan()->GetName()); |
| 668 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 669 | return GetCurrentPlan()->ShouldReportRun (event_ptr); |
Jim Ingham | ac95966 | 2011-01-24 06:34:17 +0000 | [diff] [blame] | 670 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 671 | } |
| 672 | |
Jim Ingham | 3c7b5b9 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 673 | bool |
| 674 | Thread::MatchesSpec (const ThreadSpec *spec) |
| 675 | { |
| 676 | if (spec == NULL) |
| 677 | return true; |
Jim Ingham | 3c7b5b9 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 678 | |
Jim Ingham | a266491 | 2012-03-07 22:03:04 +0000 | [diff] [blame] | 679 | return spec->ThreadPassesBasicTests(*this); |
Jim Ingham | 3c7b5b9 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 680 | } |
| 681 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 682 | void |
| 683 | Thread::PushPlan (ThreadPlanSP &thread_plan_sp) |
| 684 | { |
| 685 | if (thread_plan_sp) |
| 686 | { |
Jim Ingham | 745ac7a | 2010-11-11 19:26:09 +0000 | [diff] [blame] | 687 | // If the thread plan doesn't already have a tracer, give it its parent's tracer: |
| 688 | if (!thread_plan_sp->GetThreadPlanTracer()) |
| 689 | thread_plan_sp->SetThreadPlanTracer(m_plan_stack.back()->GetThreadPlanTracer()); |
Jim Ingham | 6297a3a | 2010-10-20 00:39:53 +0000 | [diff] [blame] | 690 | m_plan_stack.push_back (thread_plan_sp); |
Jim Ingham | 745ac7a | 2010-11-11 19:26:09 +0000 | [diff] [blame] | 691 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 692 | thread_plan_sp->DidPush(); |
| 693 | |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 694 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 695 | if (log) |
| 696 | { |
| 697 | StreamString s; |
| 698 | thread_plan_sp->GetDescription (&s, lldb::eDescriptionLevelFull); |
Greg Clayton | 444e35b | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 699 | log->Printf("Pushing plan: \"%s\", tid = 0x%4.4llx.", |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 700 | s.GetData(), |
Jim Ingham | 6297a3a | 2010-10-20 00:39:53 +0000 | [diff] [blame] | 701 | thread_plan_sp->GetThread().GetID()); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 702 | } |
| 703 | } |
| 704 | } |
| 705 | |
| 706 | void |
| 707 | Thread::PopPlan () |
| 708 | { |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 709 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 710 | |
Jim Ingham | d0bdddf | 2012-08-22 21:34:33 +0000 | [diff] [blame^] | 711 | if (m_plan_stack.size() <= 1) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 712 | return; |
| 713 | else |
| 714 | { |
| 715 | ThreadPlanSP &plan = m_plan_stack.back(); |
| 716 | if (log) |
| 717 | { |
Greg Clayton | 444e35b | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 718 | log->Printf("Popping plan: \"%s\", tid = 0x%4.4llx.", plan->GetName(), plan->GetThread().GetID()); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 719 | } |
| 720 | m_completed_plan_stack.push_back (plan); |
| 721 | plan->WillPop(); |
| 722 | m_plan_stack.pop_back(); |
| 723 | } |
| 724 | } |
| 725 | |
| 726 | void |
| 727 | Thread::DiscardPlan () |
| 728 | { |
| 729 | if (m_plan_stack.size() > 1) |
| 730 | { |
| 731 | ThreadPlanSP &plan = m_plan_stack.back(); |
| 732 | m_discarded_plan_stack.push_back (plan); |
| 733 | plan->WillPop(); |
| 734 | m_plan_stack.pop_back(); |
| 735 | } |
| 736 | } |
| 737 | |
| 738 | ThreadPlan * |
| 739 | Thread::GetCurrentPlan () |
| 740 | { |
Jim Ingham | 2f41d27 | 2012-04-19 00:17:05 +0000 | [diff] [blame] | 741 | // There will always be at least the base plan. If somebody is mucking with a |
| 742 | // thread with an empty plan stack, we should assert right away. |
| 743 | assert (!m_plan_stack.empty()); |
| 744 | |
| 745 | return m_plan_stack.back().get(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 746 | } |
| 747 | |
| 748 | ThreadPlanSP |
| 749 | Thread::GetCompletedPlan () |
| 750 | { |
| 751 | ThreadPlanSP empty_plan_sp; |
| 752 | if (!m_completed_plan_stack.empty()) |
| 753 | { |
| 754 | for (int i = m_completed_plan_stack.size() - 1; i >= 0; i--) |
| 755 | { |
| 756 | ThreadPlanSP completed_plan_sp; |
| 757 | completed_plan_sp = m_completed_plan_stack[i]; |
| 758 | if (!completed_plan_sp->GetPrivate ()) |
| 759 | return completed_plan_sp; |
| 760 | } |
| 761 | } |
| 762 | return empty_plan_sp; |
| 763 | } |
| 764 | |
Jim Ingham | 1586d97 | 2011-12-17 01:35:57 +0000 | [diff] [blame] | 765 | ValueObjectSP |
| 766 | Thread::GetReturnValueObject () |
| 767 | { |
| 768 | if (!m_completed_plan_stack.empty()) |
| 769 | { |
| 770 | for (int i = m_completed_plan_stack.size() - 1; i >= 0; i--) |
| 771 | { |
| 772 | ValueObjectSP return_valobj_sp; |
| 773 | return_valobj_sp = m_completed_plan_stack[i]->GetReturnValueObject(); |
| 774 | if (return_valobj_sp) |
| 775 | return return_valobj_sp; |
| 776 | } |
| 777 | } |
| 778 | return ValueObjectSP(); |
| 779 | } |
| 780 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 781 | bool |
| 782 | Thread::IsThreadPlanDone (ThreadPlan *plan) |
| 783 | { |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 784 | if (!m_completed_plan_stack.empty()) |
| 785 | { |
| 786 | for (int i = m_completed_plan_stack.size() - 1; i >= 0; i--) |
| 787 | { |
| 788 | if (m_completed_plan_stack[i].get() == plan) |
| 789 | return true; |
| 790 | } |
| 791 | } |
| 792 | return false; |
| 793 | } |
| 794 | |
| 795 | bool |
| 796 | Thread::WasThreadPlanDiscarded (ThreadPlan *plan) |
| 797 | { |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 798 | if (!m_discarded_plan_stack.empty()) |
| 799 | { |
| 800 | for (int i = m_discarded_plan_stack.size() - 1; i >= 0; i--) |
| 801 | { |
| 802 | if (m_discarded_plan_stack[i].get() == plan) |
| 803 | return true; |
| 804 | } |
| 805 | } |
| 806 | return false; |
| 807 | } |
| 808 | |
| 809 | ThreadPlan * |
| 810 | Thread::GetPreviousPlan (ThreadPlan *current_plan) |
| 811 | { |
| 812 | if (current_plan == NULL) |
| 813 | return NULL; |
| 814 | |
| 815 | int stack_size = m_completed_plan_stack.size(); |
| 816 | for (int i = stack_size - 1; i > 0; i--) |
| 817 | { |
| 818 | if (current_plan == m_completed_plan_stack[i].get()) |
| 819 | return m_completed_plan_stack[i-1].get(); |
| 820 | } |
| 821 | |
| 822 | if (stack_size > 0 && m_completed_plan_stack[0].get() == current_plan) |
| 823 | { |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 824 | if (m_plan_stack.size() > 0) |
| 825 | return m_plan_stack.back().get(); |
| 826 | else |
| 827 | return NULL; |
| 828 | } |
| 829 | |
| 830 | stack_size = m_plan_stack.size(); |
| 831 | for (int i = stack_size - 1; i > 0; i--) |
| 832 | { |
| 833 | if (current_plan == m_plan_stack[i].get()) |
| 834 | return m_plan_stack[i-1].get(); |
| 835 | } |
| 836 | return NULL; |
| 837 | } |
| 838 | |
| 839 | void |
| 840 | Thread::QueueThreadPlan (ThreadPlanSP &thread_plan_sp, bool abort_other_plans) |
| 841 | { |
| 842 | if (abort_other_plans) |
| 843 | DiscardThreadPlans(true); |
| 844 | |
| 845 | PushPlan (thread_plan_sp); |
| 846 | } |
| 847 | |
Jim Ingham | 745ac7a | 2010-11-11 19:26:09 +0000 | [diff] [blame] | 848 | |
| 849 | void |
| 850 | Thread::EnableTracer (bool value, bool single_stepping) |
| 851 | { |
| 852 | int stack_size = m_plan_stack.size(); |
| 853 | for (int i = 0; i < stack_size; i++) |
| 854 | { |
| 855 | if (m_plan_stack[i]->GetThreadPlanTracer()) |
| 856 | { |
| 857 | m_plan_stack[i]->GetThreadPlanTracer()->EnableTracing(value); |
| 858 | m_plan_stack[i]->GetThreadPlanTracer()->EnableSingleStep(single_stepping); |
| 859 | } |
| 860 | } |
| 861 | } |
| 862 | |
| 863 | void |
| 864 | Thread::SetTracer (lldb::ThreadPlanTracerSP &tracer_sp) |
| 865 | { |
| 866 | int stack_size = m_plan_stack.size(); |
| 867 | for (int i = 0; i < stack_size; i++) |
| 868 | m_plan_stack[i]->SetThreadPlanTracer(tracer_sp); |
| 869 | } |
| 870 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 871 | void |
Jim Ingham | ea9d426 | 2010-11-05 19:25:48 +0000 | [diff] [blame] | 872 | Thread::DiscardThreadPlansUpToPlan (lldb::ThreadPlanSP &up_to_plan_sp) |
| 873 | { |
Jim Ingham | 88e3de2 | 2012-05-03 21:19:36 +0000 | [diff] [blame] | 874 | DiscardThreadPlansUpToPlan (up_to_plan_sp.get()); |
| 875 | } |
| 876 | |
| 877 | void |
| 878 | Thread::DiscardThreadPlansUpToPlan (ThreadPlan *up_to_plan_ptr) |
| 879 | { |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 880 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); |
Jim Ingham | ea9d426 | 2010-11-05 19:25:48 +0000 | [diff] [blame] | 881 | if (log) |
| 882 | { |
Jim Ingham | 88e3de2 | 2012-05-03 21:19:36 +0000 | [diff] [blame] | 883 | log->Printf("Discarding thread plans for thread tid = 0x%4.4llx, up to %p", GetID(), up_to_plan_ptr); |
Jim Ingham | ea9d426 | 2010-11-05 19:25:48 +0000 | [diff] [blame] | 884 | } |
| 885 | |
| 886 | int stack_size = m_plan_stack.size(); |
| 887 | |
| 888 | // If the input plan is NULL, discard all plans. Otherwise make sure this plan is in the |
| 889 | // stack, and if so discard up to and including it. |
| 890 | |
Jim Ingham | 88e3de2 | 2012-05-03 21:19:36 +0000 | [diff] [blame] | 891 | if (up_to_plan_ptr == NULL) |
Jim Ingham | ea9d426 | 2010-11-05 19:25:48 +0000 | [diff] [blame] | 892 | { |
| 893 | for (int i = stack_size - 1; i > 0; i--) |
| 894 | DiscardPlan(); |
| 895 | } |
| 896 | else |
| 897 | { |
| 898 | bool found_it = false; |
| 899 | for (int i = stack_size - 1; i > 0; i--) |
| 900 | { |
Jim Ingham | 88e3de2 | 2012-05-03 21:19:36 +0000 | [diff] [blame] | 901 | if (m_plan_stack[i].get() == up_to_plan_ptr) |
Jim Ingham | ea9d426 | 2010-11-05 19:25:48 +0000 | [diff] [blame] | 902 | found_it = true; |
| 903 | } |
| 904 | if (found_it) |
| 905 | { |
| 906 | bool last_one = false; |
| 907 | for (int i = stack_size - 1; i > 0 && !last_one ; i--) |
| 908 | { |
Jim Ingham | 88e3de2 | 2012-05-03 21:19:36 +0000 | [diff] [blame] | 909 | if (GetCurrentPlan() == up_to_plan_ptr) |
Jim Ingham | ea9d426 | 2010-11-05 19:25:48 +0000 | [diff] [blame] | 910 | last_one = true; |
| 911 | DiscardPlan(); |
| 912 | } |
| 913 | } |
| 914 | } |
| 915 | return; |
| 916 | } |
| 917 | |
| 918 | void |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 919 | Thread::DiscardThreadPlans(bool force) |
| 920 | { |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 921 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 922 | if (log) |
| 923 | { |
Greg Clayton | 444e35b | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 924 | log->Printf("Discarding thread plans for thread (tid = 0x%4.4llx, force %d)", GetID(), force); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 925 | } |
| 926 | |
| 927 | if (force) |
| 928 | { |
| 929 | int stack_size = m_plan_stack.size(); |
| 930 | for (int i = stack_size - 1; i > 0; i--) |
| 931 | { |
| 932 | DiscardPlan(); |
| 933 | } |
| 934 | return; |
| 935 | } |
| 936 | |
| 937 | while (1) |
| 938 | { |
| 939 | |
| 940 | int master_plan_idx; |
| 941 | bool discard; |
| 942 | |
| 943 | // Find the first master plan, see if it wants discarding, and if yes discard up to it. |
| 944 | for (master_plan_idx = m_plan_stack.size() - 1; master_plan_idx >= 0; master_plan_idx--) |
| 945 | { |
| 946 | if (m_plan_stack[master_plan_idx]->IsMasterPlan()) |
| 947 | { |
| 948 | discard = m_plan_stack[master_plan_idx]->OkayToDiscard(); |
| 949 | break; |
| 950 | } |
| 951 | } |
| 952 | |
| 953 | if (discard) |
| 954 | { |
| 955 | // First pop all the dependent plans: |
| 956 | for (int i = m_plan_stack.size() - 1; i > master_plan_idx; i--) |
| 957 | { |
| 958 | |
| 959 | // FIXME: Do we need a finalize here, or is the rule that "PrepareForStop" |
| 960 | // for the plan leaves it in a state that it is safe to pop the plan |
| 961 | // with no more notice? |
| 962 | DiscardPlan(); |
| 963 | } |
| 964 | |
| 965 | // Now discard the master plan itself. |
| 966 | // The bottom-most plan never gets discarded. "OkayToDiscard" for it means |
| 967 | // discard it's dependent plans, but not it... |
| 968 | if (master_plan_idx > 0) |
| 969 | { |
| 970 | DiscardPlan(); |
| 971 | } |
| 972 | } |
| 973 | else |
| 974 | { |
| 975 | // If the master plan doesn't want to get discarded, then we're done. |
| 976 | break; |
| 977 | } |
| 978 | |
| 979 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 980 | } |
| 981 | |
Jim Ingham | 2bcbaf6 | 2012-04-09 22:37:39 +0000 | [diff] [blame] | 982 | bool |
| 983 | Thread::PlanIsBasePlan (ThreadPlan *plan_ptr) |
| 984 | { |
| 985 | if (plan_ptr->IsBasePlan()) |
| 986 | return true; |
| 987 | else if (m_plan_stack.size() == 0) |
| 988 | return false; |
| 989 | else |
| 990 | return m_plan_stack[0].get() == plan_ptr; |
| 991 | } |
| 992 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 993 | ThreadPlan * |
| 994 | Thread::QueueFundamentalPlan (bool abort_other_plans) |
| 995 | { |
| 996 | ThreadPlanSP thread_plan_sp (new ThreadPlanBase(*this)); |
| 997 | QueueThreadPlan (thread_plan_sp, abort_other_plans); |
| 998 | return thread_plan_sp.get(); |
| 999 | } |
| 1000 | |
| 1001 | ThreadPlan * |
Greg Clayton | 1ebdcc7 | 2011-01-21 06:11:58 +0000 | [diff] [blame] | 1002 | Thread::QueueThreadPlanForStepSingleInstruction |
| 1003 | ( |
| 1004 | bool step_over, |
| 1005 | bool abort_other_plans, |
| 1006 | bool stop_other_threads |
| 1007 | ) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1008 | { |
| 1009 | ThreadPlanSP thread_plan_sp (new ThreadPlanStepInstruction (*this, step_over, stop_other_threads, eVoteNoOpinion, eVoteNoOpinion)); |
| 1010 | QueueThreadPlan (thread_plan_sp, abort_other_plans); |
| 1011 | return thread_plan_sp.get(); |
| 1012 | } |
| 1013 | |
| 1014 | ThreadPlan * |
Greg Clayton | 8f5fd6b | 2010-06-12 18:59:55 +0000 | [diff] [blame] | 1015 | Thread::QueueThreadPlanForStepRange |
| 1016 | ( |
| 1017 | bool abort_other_plans, |
| 1018 | StepType type, |
| 1019 | const AddressRange &range, |
| 1020 | const SymbolContext &addr_context, |
| 1021 | lldb::RunMode stop_other_threads, |
| 1022 | bool avoid_code_without_debug_info |
| 1023 | ) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1024 | { |
| 1025 | ThreadPlanSP thread_plan_sp; |
| 1026 | if (type == eStepTypeInto) |
Greg Clayton | 8f5fd6b | 2010-06-12 18:59:55 +0000 | [diff] [blame] | 1027 | { |
| 1028 | ThreadPlanStepInRange *plan = new ThreadPlanStepInRange (*this, range, addr_context, stop_other_threads); |
| 1029 | if (avoid_code_without_debug_info) |
| 1030 | plan->GetFlags().Set (ThreadPlanShouldStopHere::eAvoidNoDebug); |
| 1031 | else |
| 1032 | plan->GetFlags().Clear (ThreadPlanShouldStopHere::eAvoidNoDebug); |
| 1033 | thread_plan_sp.reset (plan); |
| 1034 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1035 | else |
| 1036 | thread_plan_sp.reset (new ThreadPlanStepOverRange (*this, range, addr_context, stop_other_threads)); |
| 1037 | |
| 1038 | QueueThreadPlan (thread_plan_sp, abort_other_plans); |
| 1039 | return thread_plan_sp.get(); |
| 1040 | } |
| 1041 | |
| 1042 | |
| 1043 | ThreadPlan * |
| 1044 | Thread::QueueThreadPlanForStepOverBreakpointPlan (bool abort_other_plans) |
| 1045 | { |
| 1046 | ThreadPlanSP thread_plan_sp (new ThreadPlanStepOverBreakpoint (*this)); |
| 1047 | QueueThreadPlan (thread_plan_sp, abort_other_plans); |
| 1048 | return thread_plan_sp.get(); |
| 1049 | } |
| 1050 | |
| 1051 | ThreadPlan * |
Greg Clayton | 1ebdcc7 | 2011-01-21 06:11:58 +0000 | [diff] [blame] | 1052 | Thread::QueueThreadPlanForStepOut |
| 1053 | ( |
| 1054 | bool abort_other_plans, |
| 1055 | SymbolContext *addr_context, |
| 1056 | bool first_insn, |
| 1057 | bool stop_other_threads, |
| 1058 | Vote stop_vote, |
| 1059 | Vote run_vote, |
| 1060 | uint32_t frame_idx |
| 1061 | ) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1062 | { |
Greg Clayton | 1ebdcc7 | 2011-01-21 06:11:58 +0000 | [diff] [blame] | 1063 | ThreadPlanSP thread_plan_sp (new ThreadPlanStepOut (*this, |
| 1064 | addr_context, |
| 1065 | first_insn, |
| 1066 | stop_other_threads, |
| 1067 | stop_vote, |
| 1068 | run_vote, |
| 1069 | frame_idx)); |
Sean Callanan | f6d5fea | 2012-07-31 22:19:25 +0000 | [diff] [blame] | 1070 | |
| 1071 | if (thread_plan_sp->ValidatePlan(NULL)) |
| 1072 | { |
| 1073 | QueueThreadPlan (thread_plan_sp, abort_other_plans); |
| 1074 | return thread_plan_sp.get(); |
| 1075 | } |
| 1076 | else |
| 1077 | { |
| 1078 | return NULL; |
| 1079 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1080 | } |
| 1081 | |
| 1082 | ThreadPlan * |
Jim Ingham | 038fa8e | 2012-05-10 01:35:39 +0000 | [diff] [blame] | 1083 | Thread::QueueThreadPlanForStepThrough (StackID &return_stack_id, bool abort_other_plans, bool stop_other_threads) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1084 | { |
Jim Ingham | 038fa8e | 2012-05-10 01:35:39 +0000 | [diff] [blame] | 1085 | ThreadPlanSP thread_plan_sp(new ThreadPlanStepThrough (*this, return_stack_id, stop_other_threads)); |
Jim Ingham | ad382c5 | 2011-12-03 01:52:59 +0000 | [diff] [blame] | 1086 | if (!thread_plan_sp || !thread_plan_sp->ValidatePlan (NULL)) |
| 1087 | return NULL; |
| 1088 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1089 | QueueThreadPlan (thread_plan_sp, abort_other_plans); |
| 1090 | return thread_plan_sp.get(); |
| 1091 | } |
| 1092 | |
| 1093 | ThreadPlan * |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1094 | Thread::QueueThreadPlanForCallFunction (bool abort_other_plans, |
| 1095 | Address& function, |
| 1096 | lldb::addr_t arg, |
| 1097 | bool stop_other_threads, |
| 1098 | bool discard_on_error) |
| 1099 | { |
Jim Ingham | 016ef88 | 2011-12-22 19:12:40 +0000 | [diff] [blame] | 1100 | ThreadPlanSP thread_plan_sp (new ThreadPlanCallFunction (*this, function, ClangASTType(), arg, stop_other_threads, discard_on_error)); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1101 | QueueThreadPlan (thread_plan_sp, abort_other_plans); |
| 1102 | return thread_plan_sp.get(); |
| 1103 | } |
| 1104 | |
| 1105 | ThreadPlan * |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1106 | Thread::QueueThreadPlanForRunToAddress (bool abort_other_plans, |
| 1107 | Address &target_addr, |
| 1108 | bool stop_other_threads) |
| 1109 | { |
| 1110 | ThreadPlanSP thread_plan_sp (new ThreadPlanRunToAddress (*this, target_addr, stop_other_threads)); |
| 1111 | QueueThreadPlan (thread_plan_sp, abort_other_plans); |
| 1112 | return thread_plan_sp.get(); |
| 1113 | } |
| 1114 | |
| 1115 | ThreadPlan * |
| 1116 | Thread::QueueThreadPlanForStepUntil (bool abort_other_plans, |
Greg Clayton | 1ebdcc7 | 2011-01-21 06:11:58 +0000 | [diff] [blame] | 1117 | lldb::addr_t *address_list, |
| 1118 | size_t num_addresses, |
| 1119 | bool stop_other_threads, |
| 1120 | uint32_t frame_idx) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1121 | { |
Greg Clayton | 1ebdcc7 | 2011-01-21 06:11:58 +0000 | [diff] [blame] | 1122 | ThreadPlanSP thread_plan_sp (new ThreadPlanStepUntil (*this, address_list, num_addresses, stop_other_threads, frame_idx)); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1123 | QueueThreadPlan (thread_plan_sp, abort_other_plans); |
| 1124 | return thread_plan_sp.get(); |
| 1125 | |
| 1126 | } |
| 1127 | |
| 1128 | uint32_t |
| 1129 | Thread::GetIndexID () const |
| 1130 | { |
| 1131 | return m_index_id; |
| 1132 | } |
| 1133 | |
| 1134 | void |
| 1135 | Thread::DumpThreadPlans (lldb_private::Stream *s) const |
| 1136 | { |
| 1137 | uint32_t stack_size = m_plan_stack.size(); |
Greg Clayton | f04d661 | 2010-09-03 22:45:01 +0000 | [diff] [blame] | 1138 | int i; |
Jim Ingham | e8f4e11 | 2011-10-15 00:23:43 +0000 | [diff] [blame] | 1139 | s->Indent(); |
Greg Clayton | 444e35b | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 1140 | s->Printf ("Plan Stack for thread #%u: tid = 0x%4.4llx, stack_size = %d\n", GetIndexID(), GetID(), stack_size); |
Greg Clayton | f04d661 | 2010-09-03 22:45:01 +0000 | [diff] [blame] | 1141 | for (i = stack_size - 1; i >= 0; i--) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1142 | { |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1143 | s->IndentMore(); |
Jim Ingham | e8f4e11 | 2011-10-15 00:23:43 +0000 | [diff] [blame] | 1144 | s->Indent(); |
| 1145 | s->Printf ("Element %d: ", i); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1146 | m_plan_stack[i]->GetDescription (s, eDescriptionLevelFull); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1147 | s->EOL(); |
Jim Ingham | e8f4e11 | 2011-10-15 00:23:43 +0000 | [diff] [blame] | 1148 | s->IndentLess(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1149 | } |
| 1150 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1151 | stack_size = m_completed_plan_stack.size(); |
Jim Ingham | e8f4e11 | 2011-10-15 00:23:43 +0000 | [diff] [blame] | 1152 | if (stack_size > 0) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1153 | { |
Jim Ingham | e8f4e11 | 2011-10-15 00:23:43 +0000 | [diff] [blame] | 1154 | s->Indent(); |
| 1155 | s->Printf ("Completed Plan Stack: %d elements.\n", stack_size); |
| 1156 | for (i = stack_size - 1; i >= 0; i--) |
| 1157 | { |
| 1158 | s->IndentMore(); |
| 1159 | s->Indent(); |
| 1160 | s->Printf ("Element %d: ", i); |
| 1161 | m_completed_plan_stack[i]->GetDescription (s, eDescriptionLevelFull); |
| 1162 | s->EOL(); |
| 1163 | s->IndentLess(); |
| 1164 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1165 | } |
| 1166 | |
| 1167 | stack_size = m_discarded_plan_stack.size(); |
Jim Ingham | e8f4e11 | 2011-10-15 00:23:43 +0000 | [diff] [blame] | 1168 | if (stack_size > 0) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1169 | { |
Jim Ingham | e8f4e11 | 2011-10-15 00:23:43 +0000 | [diff] [blame] | 1170 | s->Indent(); |
| 1171 | s->Printf ("Discarded Plan Stack: %d elements.\n", stack_size); |
| 1172 | for (i = stack_size - 1; i >= 0; i--) |
| 1173 | { |
| 1174 | s->IndentMore(); |
| 1175 | s->Indent(); |
| 1176 | s->Printf ("Element %d: ", i); |
| 1177 | m_discarded_plan_stack[i]->GetDescription (s, eDescriptionLevelFull); |
| 1178 | s->EOL(); |
| 1179 | s->IndentLess(); |
| 1180 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1181 | } |
| 1182 | |
| 1183 | } |
| 1184 | |
Greg Clayton | 289afcb | 2012-02-18 05:35:26 +0000 | [diff] [blame] | 1185 | TargetSP |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1186 | Thread::CalculateTarget () |
| 1187 | { |
Greg Clayton | f4124de | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 1188 | TargetSP target_sp; |
| 1189 | ProcessSP process_sp(GetProcess()); |
| 1190 | if (process_sp) |
| 1191 | target_sp = process_sp->CalculateTarget(); |
| 1192 | return target_sp; |
| 1193 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1194 | } |
| 1195 | |
Greg Clayton | 289afcb | 2012-02-18 05:35:26 +0000 | [diff] [blame] | 1196 | ProcessSP |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1197 | Thread::CalculateProcess () |
| 1198 | { |
Greg Clayton | f4124de | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 1199 | return GetProcess(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1200 | } |
| 1201 | |
Greg Clayton | 289afcb | 2012-02-18 05:35:26 +0000 | [diff] [blame] | 1202 | ThreadSP |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1203 | Thread::CalculateThread () |
| 1204 | { |
Greg Clayton | 289afcb | 2012-02-18 05:35:26 +0000 | [diff] [blame] | 1205 | return shared_from_this(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1206 | } |
| 1207 | |
Greg Clayton | 289afcb | 2012-02-18 05:35:26 +0000 | [diff] [blame] | 1208 | StackFrameSP |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1209 | Thread::CalculateStackFrame () |
| 1210 | { |
Greg Clayton | 289afcb | 2012-02-18 05:35:26 +0000 | [diff] [blame] | 1211 | return StackFrameSP(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1212 | } |
| 1213 | |
| 1214 | void |
Greg Clayton | a830adb | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 1215 | Thread::CalculateExecutionContext (ExecutionContext &exe_ctx) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1216 | { |
Greg Clayton | f4124de | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 1217 | exe_ctx.SetContext (shared_from_this()); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1218 | } |
| 1219 | |
Greg Clayton | 782b9cc | 2010-08-25 00:35:26 +0000 | [diff] [blame] | 1220 | |
Greg Clayton | 2450cb1 | 2012-03-29 01:41:38 +0000 | [diff] [blame] | 1221 | StackFrameListSP |
Greg Clayton | 782b9cc | 2010-08-25 00:35:26 +0000 | [diff] [blame] | 1222 | Thread::GetStackFrameList () |
| 1223 | { |
Greg Clayton | 2450cb1 | 2012-03-29 01:41:38 +0000 | [diff] [blame] | 1224 | StackFrameListSP frame_list_sp; |
| 1225 | Mutex::Locker locker(m_frame_mutex); |
| 1226 | if (m_curr_frames_sp) |
| 1227 | { |
| 1228 | frame_list_sp = m_curr_frames_sp; |
| 1229 | } |
| 1230 | else |
| 1231 | { |
| 1232 | frame_list_sp.reset(new StackFrameList (*this, m_prev_frames_sp, true)); |
| 1233 | m_curr_frames_sp = frame_list_sp; |
| 1234 | } |
| 1235 | return frame_list_sp; |
Greg Clayton | 782b9cc | 2010-08-25 00:35:26 +0000 | [diff] [blame] | 1236 | } |
| 1237 | |
Greg Clayton | 782b9cc | 2010-08-25 00:35:26 +0000 | [diff] [blame] | 1238 | void |
| 1239 | Thread::ClearStackFrames () |
| 1240 | { |
Greg Clayton | 2450cb1 | 2012-03-29 01:41:38 +0000 | [diff] [blame] | 1241 | Mutex::Locker locker(m_frame_mutex); |
| 1242 | |
Jim Ingham | bf97d74 | 2012-02-29 03:40:22 +0000 | [diff] [blame] | 1243 | // Only store away the old "reference" StackFrameList if we got all its frames: |
| 1244 | // FIXME: At some point we can try to splice in the frames we have fetched into |
| 1245 | // the new frame as we make it, but let's not try that now. |
| 1246 | if (m_curr_frames_sp && m_curr_frames_sp->GetAllFramesFetched()) |
Greg Clayton | c51ffbf | 2011-08-12 21:40:01 +0000 | [diff] [blame] | 1247 | m_prev_frames_sp.swap (m_curr_frames_sp); |
| 1248 | m_curr_frames_sp.reset(); |
Jim Ingham | 7121908 | 2010-08-12 02:14:28 +0000 | [diff] [blame] | 1249 | } |
| 1250 | |
| 1251 | lldb::StackFrameSP |
Greg Clayton | 08d7d3a | 2011-01-06 22:15:06 +0000 | [diff] [blame] | 1252 | Thread::GetFrameWithConcreteFrameIndex (uint32_t unwind_idx) |
| 1253 | { |
Greg Clayton | 2450cb1 | 2012-03-29 01:41:38 +0000 | [diff] [blame] | 1254 | return GetStackFrameList()->GetFrameWithConcreteFrameIndex (unwind_idx); |
Greg Clayton | 08d7d3a | 2011-01-06 22:15:06 +0000 | [diff] [blame] | 1255 | } |
| 1256 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1257 | void |
Greg Clayton | a830adb | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 1258 | Thread::DumpUsingSettingsFormat (Stream &strm, uint32_t frame_idx) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1259 | { |
Greg Clayton | f4124de | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 1260 | ExecutionContext exe_ctx (shared_from_this()); |
| 1261 | Process *process = exe_ctx.GetProcessPtr(); |
| 1262 | if (process == NULL) |
| 1263 | return; |
| 1264 | |
Greg Clayton | 567e7f3 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 1265 | StackFrameSP frame_sp; |
Greg Clayton | a830adb | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 1266 | SymbolContext frame_sc; |
Greg Clayton | a830adb | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 1267 | if (frame_idx != LLDB_INVALID_INDEX32) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1268 | { |
Greg Clayton | 567e7f3 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 1269 | frame_sp = GetStackFrameAtIndex (frame_idx); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1270 | if (frame_sp) |
| 1271 | { |
Greg Clayton | 567e7f3 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 1272 | exe_ctx.SetFrameSP(frame_sp); |
| 1273 | frame_sc = frame_sp->GetSymbolContext(eSymbolContextEverything); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1274 | } |
| 1275 | } |
| 1276 | |
Greg Clayton | f4124de | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 1277 | const char *thread_format = exe_ctx.GetTargetRef().GetDebugger().GetThreadFormat(); |
Greg Clayton | a830adb | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 1278 | assert (thread_format); |
| 1279 | const char *end = NULL; |
| 1280 | Debugger::FormatPrompt (thread_format, |
Greg Clayton | 567e7f3 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 1281 | frame_sp ? &frame_sc : NULL, |
Greg Clayton | a830adb | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 1282 | &exe_ctx, |
| 1283 | NULL, |
| 1284 | strm, |
| 1285 | &end); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1286 | } |
| 1287 | |
Greg Clayton | 990de7b | 2010-11-18 23:32:35 +0000 | [diff] [blame] | 1288 | void |
Caroline Tice | 2a45681 | 2011-03-10 22:14:10 +0000 | [diff] [blame] | 1289 | Thread::SettingsInitialize () |
Jim Ingham | 20594b1 | 2010-09-08 03:14:33 +0000 | [diff] [blame] | 1290 | { |
Greg Clayton | 990de7b | 2010-11-18 23:32:35 +0000 | [diff] [blame] | 1291 | } |
Jim Ingham | 20594b1 | 2010-09-08 03:14:33 +0000 | [diff] [blame] | 1292 | |
Greg Clayton | 990de7b | 2010-11-18 23:32:35 +0000 | [diff] [blame] | 1293 | void |
Caroline Tice | 2a45681 | 2011-03-10 22:14:10 +0000 | [diff] [blame] | 1294 | Thread::SettingsTerminate () |
Greg Clayton | 990de7b | 2010-11-18 23:32:35 +0000 | [diff] [blame] | 1295 | { |
Greg Clayton | 990de7b | 2010-11-18 23:32:35 +0000 | [diff] [blame] | 1296 | } |
Jim Ingham | 20594b1 | 2010-09-08 03:14:33 +0000 | [diff] [blame] | 1297 | |
Jim Ingham | ccd584d | 2010-09-23 17:40:12 +0000 | [diff] [blame] | 1298 | lldb::StackFrameSP |
| 1299 | Thread::GetStackFrameSPForStackFramePtr (StackFrame *stack_frame_ptr) |
| 1300 | { |
Greg Clayton | 2450cb1 | 2012-03-29 01:41:38 +0000 | [diff] [blame] | 1301 | return GetStackFrameList()->GetStackFrameSPForStackFramePtr (stack_frame_ptr); |
Jim Ingham | ccd584d | 2010-09-23 17:40:12 +0000 | [diff] [blame] | 1302 | } |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 1303 | |
| 1304 | const char * |
| 1305 | Thread::StopReasonAsCString (lldb::StopReason reason) |
| 1306 | { |
| 1307 | switch (reason) |
| 1308 | { |
| 1309 | case eStopReasonInvalid: return "invalid"; |
| 1310 | case eStopReasonNone: return "none"; |
| 1311 | case eStopReasonTrace: return "trace"; |
| 1312 | case eStopReasonBreakpoint: return "breakpoint"; |
| 1313 | case eStopReasonWatchpoint: return "watchpoint"; |
| 1314 | case eStopReasonSignal: return "signal"; |
| 1315 | case eStopReasonException: return "exception"; |
| 1316 | case eStopReasonPlanComplete: return "plan complete"; |
| 1317 | } |
| 1318 | |
| 1319 | |
| 1320 | static char unknown_state_string[64]; |
| 1321 | snprintf(unknown_state_string, sizeof (unknown_state_string), "StopReason = %i", reason); |
| 1322 | return unknown_state_string; |
| 1323 | } |
| 1324 | |
| 1325 | const char * |
| 1326 | Thread::RunModeAsCString (lldb::RunMode mode) |
| 1327 | { |
| 1328 | switch (mode) |
| 1329 | { |
| 1330 | case eOnlyThisThread: return "only this thread"; |
| 1331 | case eAllThreads: return "all threads"; |
| 1332 | case eOnlyDuringStepping: return "only during stepping"; |
| 1333 | } |
| 1334 | |
| 1335 | static char unknown_state_string[64]; |
| 1336 | snprintf(unknown_state_string, sizeof (unknown_state_string), "RunMode = %i", mode); |
| 1337 | return unknown_state_string; |
| 1338 | } |
Jim Ingham | 745ac7a | 2010-11-11 19:26:09 +0000 | [diff] [blame] | 1339 | |
Greg Clayton | abe0fed | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 1340 | size_t |
| 1341 | Thread::GetStatus (Stream &strm, uint32_t start_frame, uint32_t num_frames, uint32_t num_frames_with_source) |
| 1342 | { |
Greg Clayton | f4124de | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 1343 | ExecutionContext exe_ctx (shared_from_this()); |
| 1344 | Target *target = exe_ctx.GetTargetPtr(); |
| 1345 | Process *process = exe_ctx.GetProcessPtr(); |
Greg Clayton | abe0fed | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 1346 | size_t num_frames_shown = 0; |
| 1347 | strm.Indent(); |
Greg Clayton | f4124de | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 1348 | bool is_selected = false; |
| 1349 | if (process) |
| 1350 | { |
| 1351 | if (process->GetThreadList().GetSelectedThread().get() == this) |
| 1352 | is_selected = true; |
| 1353 | } |
| 1354 | strm.Printf("%c ", is_selected ? '*' : ' '); |
| 1355 | if (target && target->GetDebugger().GetUseExternalEditor()) |
Greg Clayton | abe0fed | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 1356 | { |
Greg Clayton | c5dca6c | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 1357 | StackFrameSP frame_sp = GetStackFrameAtIndex(start_frame); |
Jim Ingham | c2da8eb | 2011-08-16 00:07:28 +0000 | [diff] [blame] | 1358 | if (frame_sp) |
Greg Clayton | c5dca6c | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 1359 | { |
Jim Ingham | c2da8eb | 2011-08-16 00:07:28 +0000 | [diff] [blame] | 1360 | SymbolContext frame_sc(frame_sp->GetSymbolContext (eSymbolContextLineEntry)); |
| 1361 | if (frame_sc.line_entry.line != 0 && frame_sc.line_entry.file) |
| 1362 | { |
| 1363 | Host::OpenFileInExternalEditor (frame_sc.line_entry.file, frame_sc.line_entry.line); |
| 1364 | } |
Greg Clayton | c5dca6c | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 1365 | } |
Greg Clayton | abe0fed | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 1366 | } |
| 1367 | |
| 1368 | DumpUsingSettingsFormat (strm, start_frame); |
| 1369 | |
| 1370 | if (num_frames > 0) |
| 1371 | { |
| 1372 | strm.IndentMore(); |
| 1373 | |
| 1374 | const bool show_frame_info = true; |
Jim Ingham | 7868bcc | 2011-07-26 02:39:59 +0000 | [diff] [blame] | 1375 | strm.IndentMore (); |
Greg Clayton | 2450cb1 | 2012-03-29 01:41:38 +0000 | [diff] [blame] | 1376 | num_frames_shown = GetStackFrameList ()->GetStatus (strm, |
| 1377 | start_frame, |
| 1378 | num_frames, |
| 1379 | show_frame_info, |
Greg Clayton | a7d3dc7 | 2012-07-11 20:33:48 +0000 | [diff] [blame] | 1380 | num_frames_with_source); |
Greg Clayton | abe0fed | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 1381 | strm.IndentLess(); |
Jim Ingham | 7868bcc | 2011-07-26 02:39:59 +0000 | [diff] [blame] | 1382 | strm.IndentLess(); |
Greg Clayton | abe0fed | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 1383 | } |
| 1384 | return num_frames_shown; |
| 1385 | } |
| 1386 | |
| 1387 | size_t |
| 1388 | Thread::GetStackFrameStatus (Stream& strm, |
| 1389 | uint32_t first_frame, |
| 1390 | uint32_t num_frames, |
| 1391 | bool show_frame_info, |
Greg Clayton | a7d3dc7 | 2012-07-11 20:33:48 +0000 | [diff] [blame] | 1392 | uint32_t num_frames_with_source) |
Greg Clayton | abe0fed | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 1393 | { |
Greg Clayton | 2450cb1 | 2012-03-29 01:41:38 +0000 | [diff] [blame] | 1394 | return GetStackFrameList()->GetStatus (strm, |
| 1395 | first_frame, |
| 1396 | num_frames, |
| 1397 | show_frame_info, |
Greg Clayton | a7d3dc7 | 2012-07-11 20:33:48 +0000 | [diff] [blame] | 1398 | num_frames_with_source); |
Greg Clayton | abe0fed | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 1399 | } |
| 1400 | |
Peter Collingbourne | e426d85 | 2011-06-03 20:40:54 +0000 | [diff] [blame] | 1401 | bool |
| 1402 | Thread::SaveFrameZeroState (RegisterCheckpoint &checkpoint) |
| 1403 | { |
| 1404 | lldb::StackFrameSP frame_sp(GetStackFrameAtIndex (0)); |
| 1405 | if (frame_sp) |
| 1406 | { |
| 1407 | checkpoint.SetStackID(frame_sp->GetStackID()); |
| 1408 | return frame_sp->GetRegisterContext()->ReadAllRegisterValues (checkpoint.GetData()); |
| 1409 | } |
| 1410 | return false; |
| 1411 | } |
Greg Clayton | abe0fed | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 1412 | |
Peter Collingbourne | e426d85 | 2011-06-03 20:40:54 +0000 | [diff] [blame] | 1413 | bool |
| 1414 | Thread::RestoreSaveFrameZero (const RegisterCheckpoint &checkpoint) |
| 1415 | { |
| 1416 | lldb::StackFrameSP frame_sp(GetStackFrameAtIndex (0)); |
| 1417 | if (frame_sp) |
| 1418 | { |
| 1419 | bool ret = frame_sp->GetRegisterContext()->WriteAllRegisterValues (checkpoint.GetData()); |
| 1420 | |
| 1421 | // Clear out all stack frames as our world just changed. |
| 1422 | ClearStackFrames(); |
| 1423 | frame_sp->GetRegisterContext()->InvalidateIfNeeded(true); |
| 1424 | |
| 1425 | return ret; |
| 1426 | } |
| 1427 | return false; |
| 1428 | } |
Greg Clayton | abe0fed | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 1429 | |
Greg Clayton | 37f962e | 2011-08-22 02:49:39 +0000 | [diff] [blame] | 1430 | Unwind * |
| 1431 | Thread::GetUnwinder () |
| 1432 | { |
| 1433 | if (m_unwinder_ap.get() == NULL) |
| 1434 | { |
Greg Clayton | f4124de | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 1435 | const ArchSpec target_arch (CalculateTarget()->GetArchitecture ()); |
Greg Clayton | 37f962e | 2011-08-22 02:49:39 +0000 | [diff] [blame] | 1436 | const llvm::Triple::ArchType machine = target_arch.GetMachine(); |
| 1437 | switch (machine) |
| 1438 | { |
| 1439 | case llvm::Triple::x86_64: |
| 1440 | case llvm::Triple::x86: |
| 1441 | case llvm::Triple::arm: |
| 1442 | case llvm::Triple::thumb: |
| 1443 | m_unwinder_ap.reset (new UnwindLLDB (*this)); |
| 1444 | break; |
| 1445 | |
| 1446 | default: |
| 1447 | if (target_arch.GetTriple().getVendor() == llvm::Triple::Apple) |
| 1448 | m_unwinder_ap.reset (new UnwindMacOSXFrameBackchain (*this)); |
| 1449 | break; |
| 1450 | } |
| 1451 | } |
| 1452 | return m_unwinder_ap.get(); |
| 1453 | } |
| 1454 | |
| 1455 | |
Greg Clayton | cf5927e | 2012-05-18 02:38:05 +0000 | [diff] [blame] | 1456 | void |
| 1457 | Thread::Flush () |
| 1458 | { |
| 1459 | ClearStackFrames (); |
| 1460 | m_reg_context_sp.reset(); |
| 1461 | } |