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