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