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