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