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