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