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