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