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