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-python.h" 11 12 #include "lldb/lldb-private-log.h" 13 #include "lldb/Breakpoint/BreakpointLocation.h" 14 #include "lldb/Core/Debugger.h" 15 #include "lldb/Core/Log.h" 16 #include "lldb/Core/State.h" 17 #include "lldb/Core/Stream.h" 18 #include "lldb/Core/StreamString.h" 19 #include "lldb/Core/RegularExpression.h" 20 #include "lldb/Host/Host.h" 21 #include "lldb/Symbol/Function.h" 22 #include "lldb/Target/DynamicLoader.h" 23 #include "lldb/Target/ExecutionContext.h" 24 #include "lldb/Target/ObjCLanguageRuntime.h" 25 #include "lldb/Target/Process.h" 26 #include "lldb/Target/RegisterContext.h" 27 #include "lldb/Target/StopInfo.h" 28 #include "lldb/Target/Target.h" 29 #include "lldb/Target/Thread.h" 30 #include "lldb/Target/ThreadPlan.h" 31 #include "lldb/Target/ThreadPlanCallFunction.h" 32 #include "lldb/Target/ThreadPlanBase.h" 33 #include "lldb/Target/ThreadPlanStepInstruction.h" 34 #include "lldb/Target/ThreadPlanStepOut.h" 35 #include "lldb/Target/ThreadPlanStepOverBreakpoint.h" 36 #include "lldb/Target/ThreadPlanStepThrough.h" 37 #include "lldb/Target/ThreadPlanStepInRange.h" 38 #include "lldb/Target/ThreadPlanStepOverRange.h" 39 #include "lldb/Target/ThreadPlanRunToAddress.h" 40 #include "lldb/Target/ThreadPlanStepUntil.h" 41 #include "lldb/Target/ThreadSpec.h" 42 #include "lldb/Target/Unwind.h" 43 #include "Plugins/Process/Utility/UnwindLLDB.h" 44 #include "UnwindMacOSXFrameBackchain.h" 45 46 47 using namespace lldb; 48 using namespace lldb_private; 49 50 51 const ThreadPropertiesSP & 52 Thread::GetGlobalProperties() 53 { 54 static ThreadPropertiesSP g_settings_sp; 55 if (!g_settings_sp) 56 g_settings_sp.reset (new ThreadProperties (true)); 57 return g_settings_sp; 58 } 59 60 static PropertyDefinition 61 g_properties[] = 62 { 63 { "step-avoid-regexp", OptionValue::eTypeRegex , true , REG_EXTENDED, "^std::", NULL, "A regular expression defining functions step-in won't stop in." }, 64 { "trace-thread", OptionValue::eTypeBoolean, false, false, NULL, NULL, "If true, this thread will single-step and log execution." }, 65 { NULL , OptionValue::eTypeInvalid, false, 0 , NULL, NULL, NULL } 66 }; 67 68 enum { 69 ePropertyStepAvoidRegex, 70 ePropertyEnableThreadTrace 71 }; 72 73 74 class ThreadOptionValueProperties : public OptionValueProperties 75 { 76 public: 77 ThreadOptionValueProperties (const ConstString &name) : 78 OptionValueProperties (name) 79 { 80 } 81 82 // This constructor is used when creating ThreadOptionValueProperties when it 83 // is part of a new lldb_private::Thread instance. It will copy all current 84 // global property values as needed 85 ThreadOptionValueProperties (ThreadProperties *global_properties) : 86 OptionValueProperties(*global_properties->GetValueProperties()) 87 { 88 } 89 90 virtual const Property * 91 GetPropertyAtIndex (const ExecutionContext *exe_ctx, bool will_modify, uint32_t idx) const 92 { 93 // When gettings the value for a key from the thread options, we will always 94 // try and grab the setting from the current thread if there is one. Else we just 95 // use the one from this instance. 96 if (exe_ctx) 97 { 98 Thread *thread = exe_ctx->GetThreadPtr(); 99 if (thread) 100 { 101 ThreadOptionValueProperties *instance_properties = static_cast<ThreadOptionValueProperties *>(thread->GetValueProperties().get()); 102 if (this != instance_properties) 103 return instance_properties->ProtectedGetPropertyAtIndex (idx); 104 } 105 } 106 return ProtectedGetPropertyAtIndex (idx); 107 } 108 }; 109 110 111 112 ThreadProperties::ThreadProperties (bool is_global) : 113 Properties () 114 { 115 if (is_global) 116 { 117 m_collection_sp.reset (new ThreadOptionValueProperties(ConstString("thread"))); 118 m_collection_sp->Initialize(g_properties); 119 } 120 else 121 m_collection_sp.reset (new ThreadOptionValueProperties(Thread::GetGlobalProperties().get())); 122 } 123 124 ThreadProperties::~ThreadProperties() 125 { 126 } 127 128 const RegularExpression * 129 ThreadProperties::GetSymbolsToAvoidRegexp() 130 { 131 const uint32_t idx = ePropertyStepAvoidRegex; 132 return m_collection_sp->GetPropertyAtIndexAsOptionValueRegex (NULL, idx); 133 } 134 135 bool 136 ThreadProperties::GetTraceEnabledState() const 137 { 138 const uint32_t idx = ePropertyEnableThreadTrace; 139 return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0); 140 } 141 142 //------------------------------------------------------------------ 143 // Thread Event Data 144 //------------------------------------------------------------------ 145 146 147 const ConstString & 148 Thread::ThreadEventData::GetFlavorString () 149 { 150 static ConstString g_flavor ("Thread::ThreadEventData"); 151 return g_flavor; 152 } 153 154 Thread::ThreadEventData::ThreadEventData (const lldb::ThreadSP thread_sp) : 155 m_thread_sp (thread_sp), 156 m_stack_id () 157 { 158 } 159 160 Thread::ThreadEventData::ThreadEventData (const lldb::ThreadSP thread_sp, const StackID &stack_id) : 161 m_thread_sp (thread_sp), 162 m_stack_id (stack_id) 163 { 164 } 165 166 Thread::ThreadEventData::ThreadEventData () : 167 m_thread_sp (), 168 m_stack_id () 169 { 170 } 171 172 Thread::ThreadEventData::~ThreadEventData () 173 { 174 } 175 176 void 177 Thread::ThreadEventData::Dump (Stream *s) const 178 { 179 180 } 181 182 const Thread::ThreadEventData * 183 Thread::ThreadEventData::GetEventDataFromEvent (const Event *event_ptr) 184 { 185 if (event_ptr) 186 { 187 const EventData *event_data = event_ptr->GetData(); 188 if (event_data && event_data->GetFlavor() == ThreadEventData::GetFlavorString()) 189 return static_cast <const ThreadEventData *> (event_ptr->GetData()); 190 } 191 return NULL; 192 } 193 194 ThreadSP 195 Thread::ThreadEventData::GetThreadFromEvent (const Event *event_ptr) 196 { 197 ThreadSP thread_sp; 198 const ThreadEventData *event_data = GetEventDataFromEvent (event_ptr); 199 if (event_data) 200 thread_sp = event_data->GetThread(); 201 return thread_sp; 202 } 203 204 StackID 205 Thread::ThreadEventData::GetStackIDFromEvent (const Event *event_ptr) 206 { 207 StackID stack_id; 208 const ThreadEventData *event_data = GetEventDataFromEvent (event_ptr); 209 if (event_data) 210 stack_id = event_data->GetStackID(); 211 return stack_id; 212 } 213 214 StackFrameSP 215 Thread::ThreadEventData::GetStackFrameFromEvent (const Event *event_ptr) 216 { 217 const ThreadEventData *event_data = GetEventDataFromEvent (event_ptr); 218 StackFrameSP frame_sp; 219 if (event_data) 220 { 221 ThreadSP thread_sp = event_data->GetThread(); 222 if (thread_sp) 223 { 224 frame_sp = thread_sp->GetStackFrameList()->GetFrameWithStackID (event_data->GetStackID()); 225 } 226 } 227 return frame_sp; 228 } 229 230 //------------------------------------------------------------------ 231 // Thread class 232 //------------------------------------------------------------------ 233 234 ConstString & 235 Thread::GetStaticBroadcasterClass () 236 { 237 static ConstString class_name ("lldb.thread"); 238 return class_name; 239 } 240 241 Thread::Thread (Process &process, lldb::tid_t tid) : 242 ThreadProperties (false), 243 UserID (tid), 244 Broadcaster(&process.GetTarget().GetDebugger(), Thread::GetStaticBroadcasterClass().AsCString()), 245 m_process_wp (process.shared_from_this()), 246 m_stop_info_sp (), 247 m_stop_info_stop_id (0), 248 m_index_id (process.GetNextThreadIndexID(tid)), 249 m_reg_context_sp (), 250 m_state (eStateUnloaded), 251 m_state_mutex (Mutex::eMutexTypeRecursive), 252 m_plan_stack (), 253 m_completed_plan_stack(), 254 m_frame_mutex (Mutex::eMutexTypeRecursive), 255 m_curr_frames_sp (), 256 m_prev_frames_sp (), 257 m_resume_signal (LLDB_INVALID_SIGNAL_NUMBER), 258 m_resume_state (eStateRunning), 259 m_temporary_resume_state (eStateRunning), 260 m_unwinder_ap (), 261 m_destroy_called (false), 262 m_override_should_notify (eLazyBoolCalculate) 263 { 264 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT)); 265 if (log) 266 log->Printf ("%p Thread::Thread(tid = 0x%4.4" PRIx64 ")", this, GetID()); 267 268 CheckInWithManager(); 269 QueueFundamentalPlan(true); 270 } 271 272 273 Thread::~Thread() 274 { 275 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT)); 276 if (log) 277 log->Printf ("%p Thread::~Thread(tid = 0x%4.4" PRIx64 ")", this, GetID()); 278 /// If you hit this assert, it means your derived class forgot to call DoDestroy in its destructor. 279 assert (m_destroy_called); 280 } 281 282 void 283 Thread::DestroyThread () 284 { 285 // Tell any plans on the plan stacks that the thread is being destroyed since 286 // any plans that have a thread go away in the middle of might need 287 // to do cleanup, or in some cases NOT do cleanup... 288 for (auto plan : m_plan_stack) 289 plan->ThreadDestroyed(); 290 291 for (auto plan : m_discarded_plan_stack) 292 plan->ThreadDestroyed(); 293 294 for (auto plan : m_completed_plan_stack) 295 plan->ThreadDestroyed(); 296 297 m_destroy_called = true; 298 m_plan_stack.clear(); 299 m_discarded_plan_stack.clear(); 300 m_completed_plan_stack.clear(); 301 302 // Push a ThreadPlanNull on the plan stack. That way we can continue assuming that the 303 // plan stack is never empty, but if somebody errantly asks questions of a destroyed thread 304 // without checking first whether it is destroyed, they won't crash. 305 ThreadPlanSP null_plan_sp(new ThreadPlanNull (*this)); 306 m_plan_stack.push_back (null_plan_sp); 307 308 m_stop_info_sp.reset(); 309 m_reg_context_sp.reset(); 310 m_unwinder_ap.reset(); 311 Mutex::Locker locker(m_frame_mutex); 312 m_curr_frames_sp.reset(); 313 m_prev_frames_sp.reset(); 314 } 315 316 void 317 Thread::BroadcastSelectedFrameChange(StackID &new_frame_id) 318 { 319 if (EventTypeHasListeners(eBroadcastBitSelectedFrameChanged)) 320 BroadcastEvent(eBroadcastBitSelectedFrameChanged, new ThreadEventData (this->shared_from_this(), new_frame_id)); 321 } 322 323 uint32_t 324 Thread::SetSelectedFrame (lldb_private::StackFrame *frame, bool broadcast) 325 { 326 uint32_t ret_value = GetStackFrameList()->SetSelectedFrame(frame); 327 if (broadcast) 328 BroadcastSelectedFrameChange(frame->GetStackID()); 329 return ret_value; 330 } 331 332 bool 333 Thread::SetSelectedFrameByIndex (uint32_t frame_idx, bool broadcast) 334 { 335 StackFrameSP frame_sp(GetStackFrameList()->GetFrameAtIndex (frame_idx)); 336 if (frame_sp) 337 { 338 GetStackFrameList()->SetSelectedFrame(frame_sp.get()); 339 if (broadcast) 340 BroadcastSelectedFrameChange(frame_sp->GetStackID()); 341 return true; 342 } 343 else 344 return false; 345 } 346 347 bool 348 Thread::SetSelectedFrameByIndexNoisily (uint32_t frame_idx, Stream &output_stream) 349 { 350 const bool broadcast = true; 351 bool success = SetSelectedFrameByIndex (frame_idx, broadcast); 352 if (success) 353 { 354 StackFrameSP frame_sp = GetSelectedFrame(); 355 if (frame_sp) 356 { 357 bool already_shown = false; 358 SymbolContext frame_sc(frame_sp->GetSymbolContext(eSymbolContextLineEntry)); 359 if (GetProcess()->GetTarget().GetDebugger().GetUseExternalEditor() && frame_sc.line_entry.file && frame_sc.line_entry.line != 0) 360 { 361 already_shown = Host::OpenFileInExternalEditor (frame_sc.line_entry.file, frame_sc.line_entry.line); 362 } 363 364 bool show_frame_info = true; 365 bool show_source = !already_shown; 366 return frame_sp->GetStatus (output_stream, show_frame_info, show_source); 367 } 368 return false; 369 } 370 else 371 return false; 372 } 373 374 375 lldb::StopInfoSP 376 Thread::GetStopInfo () 377 { 378 if (m_destroy_called) 379 return m_stop_info_sp; 380 381 ThreadPlanSP plan_sp (GetCompletedPlan()); 382 ProcessSP process_sp (GetProcess()); 383 const uint32_t stop_id = process_sp ? process_sp->GetStopID() : UINT32_MAX; 384 if (plan_sp && plan_sp->PlanSucceeded()) 385 { 386 return StopInfo::CreateStopReasonWithPlan (plan_sp, GetReturnValueObject()); 387 } 388 else 389 { 390 if ((m_stop_info_stop_id == stop_id) || // Stop info is valid, just return what we have (even if empty) 391 (m_stop_info_sp && m_stop_info_sp->IsValid())) // Stop info is valid, just return what we have 392 { 393 return m_stop_info_sp; 394 } 395 else 396 { 397 GetPrivateStopInfo (); 398 return m_stop_info_sp; 399 } 400 } 401 } 402 403 lldb::StopInfoSP 404 Thread::GetPrivateStopInfo () 405 { 406 if (m_destroy_called) 407 return m_stop_info_sp; 408 409 ProcessSP process_sp (GetProcess()); 410 if (process_sp) 411 { 412 const uint32_t process_stop_id = process_sp->GetStopID(); 413 if (m_stop_info_stop_id != process_stop_id) 414 { 415 if (m_stop_info_sp) 416 { 417 if (m_stop_info_sp->IsValid() 418 || IsStillAtLastBreakpointHit() 419 || GetCurrentPlan()->IsVirtualStep()) 420 SetStopInfo (m_stop_info_sp); 421 else 422 m_stop_info_sp.reset(); 423 } 424 425 if (!m_stop_info_sp) 426 { 427 if (CalculateStopInfo() == false) 428 SetStopInfo (StopInfoSP()); 429 } 430 } 431 } 432 return m_stop_info_sp; 433 } 434 435 436 lldb::StopReason 437 Thread::GetStopReason() 438 { 439 lldb::StopInfoSP stop_info_sp (GetStopInfo ()); 440 if (stop_info_sp) 441 return stop_info_sp->GetStopReason(); 442 return eStopReasonNone; 443 } 444 445 446 447 void 448 Thread::SetStopInfo (const lldb::StopInfoSP &stop_info_sp) 449 { 450 m_stop_info_sp = stop_info_sp; 451 if (m_stop_info_sp) 452 { 453 m_stop_info_sp->MakeStopInfoValid(); 454 // If we are overriding the ShouldReportStop, do that here: 455 if (m_override_should_notify != eLazyBoolCalculate) 456 m_stop_info_sp->OverrideShouldNotify (m_override_should_notify == eLazyBoolYes); 457 } 458 459 ProcessSP process_sp (GetProcess()); 460 if (process_sp) 461 m_stop_info_stop_id = process_sp->GetStopID(); 462 else 463 m_stop_info_stop_id = UINT32_MAX; 464 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_THREAD)); 465 if (log) 466 log->Printf("%p: tid = 0x%" PRIx64 ": stop info = %s (stop_id = %u)\n", this, GetID(), stop_info_sp ? stop_info_sp->GetDescription() : "<NULL>", m_stop_info_stop_id); 467 } 468 469 void 470 Thread::SetShouldReportStop (Vote vote) 471 { 472 if (vote == eVoteNoOpinion) 473 return; 474 else 475 { 476 m_override_should_notify = (vote == eVoteYes ? eLazyBoolYes : eLazyBoolNo); 477 if (m_stop_info_sp) 478 m_stop_info_sp->OverrideShouldNotify (m_override_should_notify == eLazyBoolYes); 479 } 480 } 481 482 void 483 Thread::SetStopInfoToNothing() 484 { 485 // Note, we can't just NULL out the private reason, or the native thread implementation will try to 486 // go calculate it again. For now, just set it to a Unix Signal with an invalid signal number. 487 SetStopInfo (StopInfo::CreateStopReasonWithSignal (*this, LLDB_INVALID_SIGNAL_NUMBER)); 488 } 489 490 bool 491 Thread::ThreadStoppedForAReason (void) 492 { 493 return (bool) GetPrivateStopInfo (); 494 } 495 496 bool 497 Thread::CheckpointThreadState (ThreadStateCheckpoint &saved_state) 498 { 499 if (!SaveFrameZeroState(saved_state.register_backup)) 500 return false; 501 502 saved_state.stop_info_sp = GetStopInfo(); 503 ProcessSP process_sp (GetProcess()); 504 if (process_sp) 505 saved_state.orig_stop_id = process_sp->GetStopID(); 506 saved_state.current_inlined_depth = GetCurrentInlinedDepth(); 507 508 return true; 509 } 510 511 bool 512 Thread::RestoreRegisterStateFromCheckpoint (ThreadStateCheckpoint &saved_state) 513 { 514 return RestoreSaveFrameZero(saved_state.register_backup); 515 } 516 517 bool 518 Thread::RestoreThreadStateFromCheckpoint (ThreadStateCheckpoint &saved_state) 519 { 520 if (saved_state.stop_info_sp) 521 saved_state.stop_info_sp->MakeStopInfoValid(); 522 SetStopInfo(saved_state.stop_info_sp); 523 GetStackFrameList()->SetCurrentInlinedDepth (saved_state.current_inlined_depth); 524 return true; 525 } 526 527 StateType 528 Thread::GetState() const 529 { 530 // If any other threads access this we will need a mutex for it 531 Mutex::Locker locker(m_state_mutex); 532 return m_state; 533 } 534 535 void 536 Thread::SetState(StateType state) 537 { 538 Mutex::Locker locker(m_state_mutex); 539 m_state = state; 540 } 541 542 void 543 Thread::WillStop() 544 { 545 ThreadPlan *current_plan = GetCurrentPlan(); 546 547 // FIXME: I may decide to disallow threads with no plans. In which 548 // case this should go to an assert. 549 550 if (!current_plan) 551 return; 552 553 current_plan->WillStop(); 554 } 555 556 void 557 Thread::SetupForResume () 558 { 559 if (GetResumeState() != eStateSuspended) 560 { 561 562 // If we're at a breakpoint push the step-over breakpoint plan. Do this before 563 // telling the current plan it will resume, since we might change what the current 564 // plan is. 565 566 // StopReason stop_reason = lldb::eStopReasonInvalid; 567 // StopInfoSP stop_info_sp = GetStopInfo(); 568 // if (stop_info_sp.get()) 569 // stop_reason = stop_info_sp->GetStopReason(); 570 // if (stop_reason == lldb::eStopReasonBreakpoint) 571 lldb::RegisterContextSP reg_ctx_sp (GetRegisterContext()); 572 if (reg_ctx_sp) 573 { 574 BreakpointSiteSP bp_site_sp = GetProcess()->GetBreakpointSiteList().FindByAddress(reg_ctx_sp->GetPC()); 575 if (bp_site_sp) 576 { 577 // Note, don't assume there's a ThreadPlanStepOverBreakpoint, the target may not require anything 578 // special to step over a breakpoint. 579 580 ThreadPlan *cur_plan = GetCurrentPlan(); 581 582 if (cur_plan->GetKind() != ThreadPlan::eKindStepOverBreakpoint) 583 { 584 ThreadPlanStepOverBreakpoint *step_bp_plan = new ThreadPlanStepOverBreakpoint (*this); 585 if (step_bp_plan) 586 { 587 ThreadPlanSP step_bp_plan_sp; 588 step_bp_plan->SetPrivate (true); 589 590 if (GetCurrentPlan()->RunState() != eStateStepping) 591 { 592 step_bp_plan->SetAutoContinue(true); 593 } 594 step_bp_plan_sp.reset (step_bp_plan); 595 QueueThreadPlan (step_bp_plan_sp, false); 596 } 597 } 598 } 599 } 600 } 601 } 602 603 bool 604 Thread::ShouldResume (StateType resume_state) 605 { 606 // At this point clear the completed plan stack. 607 m_completed_plan_stack.clear(); 608 m_discarded_plan_stack.clear(); 609 m_override_should_notify = eLazyBoolCalculate; 610 611 m_temporary_resume_state = resume_state; 612 613 lldb::ThreadSP backing_thread_sp (GetBackingThread ()); 614 if (backing_thread_sp) 615 backing_thread_sp->m_temporary_resume_state = resume_state; 616 617 // Make sure m_stop_info_sp is valid 618 GetPrivateStopInfo(); 619 620 // This is a little dubious, but we are trying to limit how often we actually fetch stop info from 621 // the target, 'cause that slows down single stepping. So assume that if we got to the point where 622 // we're about to resume, and we haven't yet had to fetch the stop reason, then it doesn't need to know 623 // about the fact that we are resuming... 624 const uint32_t process_stop_id = GetProcess()->GetStopID(); 625 if (m_stop_info_stop_id == process_stop_id && 626 (m_stop_info_sp && m_stop_info_sp->IsValid())) 627 { 628 StopInfo *stop_info = GetPrivateStopInfo().get(); 629 if (stop_info) 630 stop_info->WillResume (resume_state); 631 } 632 633 // Tell all the plans that we are about to resume in case they need to clear any state. 634 // We distinguish between the plan on the top of the stack and the lower 635 // plans in case a plan needs to do any special business before it runs. 636 637 bool need_to_resume = false; 638 ThreadPlan *plan_ptr = GetCurrentPlan(); 639 if (plan_ptr) 640 { 641 need_to_resume = plan_ptr->WillResume(resume_state, true); 642 643 while ((plan_ptr = GetPreviousPlan(plan_ptr)) != NULL) 644 { 645 plan_ptr->WillResume (resume_state, false); 646 } 647 648 // If the WillResume for the plan says we are faking a resume, then it will have set an appropriate stop info. 649 // In that case, don't reset it here. 650 651 if (need_to_resume && resume_state != eStateSuspended) 652 { 653 m_stop_info_sp.reset(); 654 } 655 } 656 657 if (need_to_resume) 658 { 659 ClearStackFrames(); 660 // Let Thread subclasses do any special work they need to prior to resuming 661 WillResume (resume_state); 662 } 663 664 return need_to_resume; 665 } 666 667 void 668 Thread::DidResume () 669 { 670 SetResumeSignal (LLDB_INVALID_SIGNAL_NUMBER); 671 } 672 673 void 674 Thread::DidStop () 675 { 676 SetState (eStateStopped); 677 } 678 679 bool 680 Thread::ShouldStop (Event* event_ptr) 681 { 682 ThreadPlan *current_plan = GetCurrentPlan(); 683 684 bool should_stop = true; 685 686 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); 687 688 if (GetResumeState () == eStateSuspended) 689 { 690 if (log) 691 log->Printf ("Thread::%s for tid = 0x%4.4" PRIx64 " 0x%4.4" PRIx64 ", should_stop = 0 (ignore since thread was suspended)", 692 __FUNCTION__, 693 GetID (), 694 GetProtocolID()); 695 return false; 696 } 697 698 if (GetTemporaryResumeState () == eStateSuspended) 699 { 700 if (log) 701 log->Printf ("Thread::%s for tid = 0x%4.4" PRIx64 " 0x%4.4" PRIx64 ", should_stop = 0 (ignore since thread was suspended)", 702 __FUNCTION__, 703 GetID (), 704 GetProtocolID()); 705 return false; 706 } 707 708 // Based on the current thread plan and process stop info, check if this 709 // thread caused the process to stop. NOTE: this must take place before 710 // the plan is moved from the current plan stack to the completed plan 711 // stack. 712 if (ThreadStoppedForAReason() == false) 713 { 714 if (log) 715 log->Printf ("Thread::%s for tid = 0x%4.4" PRIx64 " 0x%4.4" PRIx64 ", pc = 0x%16.16" PRIx64 ", should_stop = 0 (ignore since no stop reason)", 716 __FUNCTION__, 717 GetID (), 718 GetProtocolID(), 719 GetRegisterContext() ? GetRegisterContext()->GetPC() : LLDB_INVALID_ADDRESS); 720 return false; 721 } 722 723 if (log) 724 { 725 log->Printf ("Thread::%s(%p) for tid = 0x%4.4" PRIx64 " 0x%4.4" PRIx64 ", pc = 0x%16.16" PRIx64, 726 __FUNCTION__, 727 this, 728 GetID (), 729 GetProtocolID (), 730 GetRegisterContext() ? GetRegisterContext()->GetPC() : LLDB_INVALID_ADDRESS); 731 log->Printf ("^^^^^^^^ Thread::ShouldStop Begin ^^^^^^^^"); 732 StreamString s; 733 s.IndentMore(); 734 DumpThreadPlans(&s); 735 log->Printf ("Plan stack initial state:\n%s", s.GetData()); 736 } 737 738 // The top most plan always gets to do the trace log... 739 current_plan->DoTraceLog (); 740 741 // First query the stop info's ShouldStopSynchronous. This handles "synchronous" stop reasons, for example the breakpoint 742 // command on internal breakpoints. If a synchronous stop reason says we should not stop, then we don't have to 743 // do any more work on this stop. 744 StopInfoSP private_stop_info (GetPrivateStopInfo()); 745 if (private_stop_info && private_stop_info->ShouldStopSynchronous(event_ptr) == false) 746 { 747 if (log) 748 log->Printf ("StopInfo::ShouldStop async callback says we should not stop, returning ShouldStop of false."); 749 return false; 750 } 751 752 // If we've already been restarted, don't query the plans since the state they would examine is not current. 753 if (Process::ProcessEventData::GetRestartedFromEvent(event_ptr)) 754 return false; 755 756 // Before the plans see the state of the world, calculate the current inlined depth. 757 GetStackFrameList()->CalculateCurrentInlinedDepth(); 758 759 // If the base plan doesn't understand why we stopped, then we have to find a plan that does. 760 // If that plan is still working, then we don't need to do any more work. If the plan that explains 761 // the stop is done, then we should pop all the plans below it, and pop it, and then let the plans above it decide 762 // whether they still need to do more work. 763 764 bool done_processing_current_plan = false; 765 766 if (!current_plan->PlanExplainsStop(event_ptr)) 767 { 768 if (current_plan->TracerExplainsStop()) 769 { 770 done_processing_current_plan = true; 771 should_stop = false; 772 } 773 else 774 { 775 // If the current plan doesn't explain the stop, then find one that 776 // does and let it handle the situation. 777 ThreadPlan *plan_ptr = current_plan; 778 while ((plan_ptr = GetPreviousPlan(plan_ptr)) != NULL) 779 { 780 if (plan_ptr->PlanExplainsStop(event_ptr)) 781 { 782 should_stop = plan_ptr->ShouldStop (event_ptr); 783 784 // plan_ptr explains the stop, next check whether plan_ptr is done, if so, then we should take it 785 // and all the plans below it off the stack. 786 787 if (plan_ptr->MischiefManaged()) 788 { 789 // We're going to pop the plans up to and including the plan that explains the stop. 790 ThreadPlan *prev_plan_ptr = GetPreviousPlan (plan_ptr); 791 792 do 793 { 794 if (should_stop) 795 current_plan->WillStop(); 796 PopPlan(); 797 } 798 while ((current_plan = GetCurrentPlan()) != prev_plan_ptr); 799 // Now, if the responsible plan was not "Okay to discard" then we're done, 800 // otherwise we forward this to the next plan in the stack below. 801 if (plan_ptr->IsMasterPlan() && !plan_ptr->OkayToDiscard()) 802 done_processing_current_plan = true; 803 else 804 done_processing_current_plan = false; 805 } 806 else 807 done_processing_current_plan = true; 808 809 break; 810 } 811 812 } 813 } 814 } 815 816 if (!done_processing_current_plan) 817 { 818 bool over_ride_stop = current_plan->ShouldAutoContinue(event_ptr); 819 820 if (log) 821 log->Printf("Plan %s explains stop, auto-continue %i.", current_plan->GetName(), over_ride_stop); 822 823 // We're starting from the base plan, so just let it decide; 824 if (PlanIsBasePlan(current_plan)) 825 { 826 should_stop = current_plan->ShouldStop (event_ptr); 827 if (log) 828 log->Printf("Base plan says should stop: %i.", should_stop); 829 } 830 else 831 { 832 // Otherwise, don't let the base plan override what the other plans say to do, since 833 // presumably if there were other plans they would know what to do... 834 while (1) 835 { 836 if (PlanIsBasePlan(current_plan)) 837 break; 838 839 should_stop = current_plan->ShouldStop(event_ptr); 840 if (log) 841 log->Printf("Plan %s should stop: %d.", current_plan->GetName(), should_stop); 842 if (current_plan->MischiefManaged()) 843 { 844 if (should_stop) 845 current_plan->WillStop(); 846 847 // If a Master Plan wants to stop, and wants to stick on the stack, we let it. 848 // Otherwise, see if the plan's parent wants to stop. 849 850 if (should_stop && current_plan->IsMasterPlan() && !current_plan->OkayToDiscard()) 851 { 852 PopPlan(); 853 break; 854 } 855 else 856 { 857 858 PopPlan(); 859 860 current_plan = GetCurrentPlan(); 861 if (current_plan == NULL) 862 { 863 break; 864 } 865 } 866 } 867 else 868 { 869 break; 870 } 871 } 872 } 873 874 if (over_ride_stop) 875 should_stop = false; 876 877 // One other potential problem is that we set up a master plan, then stop in before it is complete - for instance 878 // by hitting a breakpoint during a step-over - then do some step/finish/etc operations that wind up 879 // past the end point condition of the initial plan. We don't want to strand the original plan on the stack, 880 // This code clears stale plans off the stack. 881 882 if (should_stop) 883 { 884 ThreadPlan *plan_ptr = GetCurrentPlan(); 885 while (!PlanIsBasePlan(plan_ptr)) 886 { 887 bool stale = plan_ptr->IsPlanStale (); 888 ThreadPlan *examined_plan = plan_ptr; 889 plan_ptr = GetPreviousPlan (examined_plan); 890 891 if (stale) 892 { 893 if (log) 894 log->Printf("Plan %s being discarded in cleanup, it says it is already done.", examined_plan->GetName()); 895 DiscardThreadPlansUpToPlan(examined_plan); 896 } 897 } 898 } 899 900 } 901 902 if (log) 903 { 904 StreamString s; 905 s.IndentMore(); 906 DumpThreadPlans(&s); 907 log->Printf ("Plan stack final state:\n%s", s.GetData()); 908 log->Printf ("vvvvvvvv Thread::ShouldStop End (returning %i) vvvvvvvv", should_stop); 909 } 910 return should_stop; 911 } 912 913 Vote 914 Thread::ShouldReportStop (Event* event_ptr) 915 { 916 StateType thread_state = GetResumeState (); 917 StateType temp_thread_state = GetTemporaryResumeState(); 918 919 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); 920 921 if (thread_state == eStateSuspended || thread_state == eStateInvalid) 922 { 923 if (log) 924 log->Printf ("Thread::ShouldReportStop() tid = 0x%4.4" PRIx64 ": returning vote %i (state was suspended or invalid)", GetID(), eVoteNoOpinion); 925 return eVoteNoOpinion; 926 } 927 928 if (temp_thread_state == eStateSuspended || temp_thread_state == eStateInvalid) 929 { 930 if (log) 931 log->Printf ("Thread::ShouldReportStop() tid = 0x%4.4" PRIx64 ": returning vote %i (temporary state was suspended or invalid)", GetID(), eVoteNoOpinion); 932 return eVoteNoOpinion; 933 } 934 935 if (!ThreadStoppedForAReason()) 936 { 937 if (log) 938 log->Printf ("Thread::ShouldReportStop() tid = 0x%4.4" PRIx64 ": returning vote %i (thread didn't stop for a reason.)", GetID(), eVoteNoOpinion); 939 return eVoteNoOpinion; 940 } 941 942 if (m_completed_plan_stack.size() > 0) 943 { 944 // Don't use GetCompletedPlan here, since that suppresses private plans. 945 if (log) 946 log->Printf ("Thread::ShouldReportStop() tid = 0x%4.4" PRIx64 ": returning vote for complete stack's back plan", GetID()); 947 return m_completed_plan_stack.back()->ShouldReportStop (event_ptr); 948 } 949 else 950 { 951 Vote thread_vote = eVoteNoOpinion; 952 ThreadPlan *plan_ptr = GetCurrentPlan(); 953 while (1) 954 { 955 if (plan_ptr->PlanExplainsStop(event_ptr)) 956 { 957 thread_vote = plan_ptr->ShouldReportStop(event_ptr); 958 break; 959 } 960 if (PlanIsBasePlan(plan_ptr)) 961 break; 962 else 963 plan_ptr = GetPreviousPlan(plan_ptr); 964 } 965 if (log) 966 log->Printf ("Thread::ShouldReportStop() tid = 0x%4.4" PRIx64 ": returning vote %i for current plan", GetID(), thread_vote); 967 968 return thread_vote; 969 } 970 } 971 972 Vote 973 Thread::ShouldReportRun (Event* event_ptr) 974 { 975 StateType thread_state = GetResumeState (); 976 977 if (thread_state == eStateSuspended 978 || thread_state == eStateInvalid) 979 { 980 return eVoteNoOpinion; 981 } 982 983 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); 984 if (m_completed_plan_stack.size() > 0) 985 { 986 // Don't use GetCompletedPlan here, since that suppresses private plans. 987 if (log) 988 log->Printf ("Current Plan for thread %d(%p) (0x%4.4" PRIx64 ", %s): %s being asked whether we should report run.", 989 GetIndexID(), 990 this, 991 GetID(), 992 StateAsCString(GetTemporaryResumeState()), 993 m_completed_plan_stack.back()->GetName()); 994 995 return m_completed_plan_stack.back()->ShouldReportRun (event_ptr); 996 } 997 else 998 { 999 if (log) 1000 log->Printf ("Current Plan for thread %d(%p) (0x%4.4" PRIx64 ", %s): %s being asked whether we should report run.", 1001 GetIndexID(), 1002 this, 1003 GetID(), 1004 StateAsCString(GetTemporaryResumeState()), 1005 GetCurrentPlan()->GetName()); 1006 1007 return GetCurrentPlan()->ShouldReportRun (event_ptr); 1008 } 1009 } 1010 1011 bool 1012 Thread::MatchesSpec (const ThreadSpec *spec) 1013 { 1014 if (spec == NULL) 1015 return true; 1016 1017 return spec->ThreadPassesBasicTests(*this); 1018 } 1019 1020 void 1021 Thread::PushPlan (ThreadPlanSP &thread_plan_sp) 1022 { 1023 if (thread_plan_sp) 1024 { 1025 // If the thread plan doesn't already have a tracer, give it its parent's tracer: 1026 if (!thread_plan_sp->GetThreadPlanTracer()) 1027 thread_plan_sp->SetThreadPlanTracer(m_plan_stack.back()->GetThreadPlanTracer()); 1028 m_plan_stack.push_back (thread_plan_sp); 1029 1030 thread_plan_sp->DidPush(); 1031 1032 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); 1033 if (log) 1034 { 1035 StreamString s; 1036 thread_plan_sp->GetDescription (&s, lldb::eDescriptionLevelFull); 1037 log->Printf("Thread::PushPlan(0x%p): \"%s\", tid = 0x%4.4" PRIx64 ".", 1038 this, 1039 s.GetData(), 1040 thread_plan_sp->GetThread().GetID()); 1041 } 1042 } 1043 } 1044 1045 void 1046 Thread::PopPlan () 1047 { 1048 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); 1049 1050 if (m_plan_stack.size() <= 1) 1051 return; 1052 else 1053 { 1054 ThreadPlanSP &plan = m_plan_stack.back(); 1055 if (log) 1056 { 1057 log->Printf("Popping plan: \"%s\", tid = 0x%4.4" PRIx64 ".", plan->GetName(), plan->GetThread().GetID()); 1058 } 1059 m_completed_plan_stack.push_back (plan); 1060 plan->WillPop(); 1061 m_plan_stack.pop_back(); 1062 } 1063 } 1064 1065 void 1066 Thread::DiscardPlan () 1067 { 1068 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); 1069 if (m_plan_stack.size() > 1) 1070 { 1071 ThreadPlanSP &plan = m_plan_stack.back(); 1072 if (log) 1073 log->Printf("Discarding plan: \"%s\", tid = 0x%4.4" PRIx64 ".", plan->GetName(), plan->GetThread().GetID()); 1074 1075 m_discarded_plan_stack.push_back (plan); 1076 plan->WillPop(); 1077 m_plan_stack.pop_back(); 1078 } 1079 } 1080 1081 ThreadPlan * 1082 Thread::GetCurrentPlan () 1083 { 1084 // There will always be at least the base plan. If somebody is mucking with a 1085 // thread with an empty plan stack, we should assert right away. 1086 if (m_plan_stack.empty()) 1087 return NULL; 1088 return m_plan_stack.back().get(); 1089 } 1090 1091 ThreadPlanSP 1092 Thread::GetCompletedPlan () 1093 { 1094 ThreadPlanSP empty_plan_sp; 1095 if (!m_completed_plan_stack.empty()) 1096 { 1097 for (int i = m_completed_plan_stack.size() - 1; i >= 0; i--) 1098 { 1099 ThreadPlanSP completed_plan_sp; 1100 completed_plan_sp = m_completed_plan_stack[i]; 1101 if (!completed_plan_sp->GetPrivate ()) 1102 return completed_plan_sp; 1103 } 1104 } 1105 return empty_plan_sp; 1106 } 1107 1108 ValueObjectSP 1109 Thread::GetReturnValueObject () 1110 { 1111 if (!m_completed_plan_stack.empty()) 1112 { 1113 for (int i = m_completed_plan_stack.size() - 1; i >= 0; i--) 1114 { 1115 ValueObjectSP return_valobj_sp; 1116 return_valobj_sp = m_completed_plan_stack[i]->GetReturnValueObject(); 1117 if (return_valobj_sp) 1118 return return_valobj_sp; 1119 } 1120 } 1121 return ValueObjectSP(); 1122 } 1123 1124 bool 1125 Thread::IsThreadPlanDone (ThreadPlan *plan) 1126 { 1127 if (!m_completed_plan_stack.empty()) 1128 { 1129 for (int i = m_completed_plan_stack.size() - 1; i >= 0; i--) 1130 { 1131 if (m_completed_plan_stack[i].get() == plan) 1132 return true; 1133 } 1134 } 1135 return false; 1136 } 1137 1138 bool 1139 Thread::WasThreadPlanDiscarded (ThreadPlan *plan) 1140 { 1141 if (!m_discarded_plan_stack.empty()) 1142 { 1143 for (int i = m_discarded_plan_stack.size() - 1; i >= 0; i--) 1144 { 1145 if (m_discarded_plan_stack[i].get() == plan) 1146 return true; 1147 } 1148 } 1149 return false; 1150 } 1151 1152 ThreadPlan * 1153 Thread::GetPreviousPlan (ThreadPlan *current_plan) 1154 { 1155 if (current_plan == NULL) 1156 return NULL; 1157 1158 int stack_size = m_completed_plan_stack.size(); 1159 for (int i = stack_size - 1; i > 0; i--) 1160 { 1161 if (current_plan == m_completed_plan_stack[i].get()) 1162 return m_completed_plan_stack[i-1].get(); 1163 } 1164 1165 if (stack_size > 0 && m_completed_plan_stack[0].get() == current_plan) 1166 { 1167 if (m_plan_stack.size() > 0) 1168 return m_plan_stack.back().get(); 1169 else 1170 return NULL; 1171 } 1172 1173 stack_size = m_plan_stack.size(); 1174 for (int i = stack_size - 1; i > 0; i--) 1175 { 1176 if (current_plan == m_plan_stack[i].get()) 1177 return m_plan_stack[i-1].get(); 1178 } 1179 return NULL; 1180 } 1181 1182 void 1183 Thread::QueueThreadPlan (ThreadPlanSP &thread_plan_sp, bool abort_other_plans) 1184 { 1185 if (abort_other_plans) 1186 DiscardThreadPlans(true); 1187 1188 PushPlan (thread_plan_sp); 1189 } 1190 1191 1192 void 1193 Thread::EnableTracer (bool value, bool single_stepping) 1194 { 1195 int stack_size = m_plan_stack.size(); 1196 for (int i = 0; i < stack_size; i++) 1197 { 1198 if (m_plan_stack[i]->GetThreadPlanTracer()) 1199 { 1200 m_plan_stack[i]->GetThreadPlanTracer()->EnableTracing(value); 1201 m_plan_stack[i]->GetThreadPlanTracer()->EnableSingleStep(single_stepping); 1202 } 1203 } 1204 } 1205 1206 void 1207 Thread::SetTracer (lldb::ThreadPlanTracerSP &tracer_sp) 1208 { 1209 int stack_size = m_plan_stack.size(); 1210 for (int i = 0; i < stack_size; i++) 1211 m_plan_stack[i]->SetThreadPlanTracer(tracer_sp); 1212 } 1213 1214 void 1215 Thread::DiscardThreadPlansUpToPlan (lldb::ThreadPlanSP &up_to_plan_sp) 1216 { 1217 DiscardThreadPlansUpToPlan (up_to_plan_sp.get()); 1218 } 1219 1220 void 1221 Thread::DiscardThreadPlansUpToPlan (ThreadPlan *up_to_plan_ptr) 1222 { 1223 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); 1224 if (log) 1225 { 1226 log->Printf("Discarding thread plans for thread tid = 0x%4.4" PRIx64 ", up to %p", GetID(), up_to_plan_ptr); 1227 } 1228 1229 int stack_size = m_plan_stack.size(); 1230 1231 // If the input plan is NULL, discard all plans. Otherwise make sure this plan is in the 1232 // stack, and if so discard up to and including it. 1233 1234 if (up_to_plan_ptr == NULL) 1235 { 1236 for (int i = stack_size - 1; i > 0; i--) 1237 DiscardPlan(); 1238 } 1239 else 1240 { 1241 bool found_it = false; 1242 for (int i = stack_size - 1; i > 0; i--) 1243 { 1244 if (m_plan_stack[i].get() == up_to_plan_ptr) 1245 found_it = true; 1246 } 1247 if (found_it) 1248 { 1249 bool last_one = false; 1250 for (int i = stack_size - 1; i > 0 && !last_one ; i--) 1251 { 1252 if (GetCurrentPlan() == up_to_plan_ptr) 1253 last_one = true; 1254 DiscardPlan(); 1255 } 1256 } 1257 } 1258 return; 1259 } 1260 1261 void 1262 Thread::DiscardThreadPlans(bool force) 1263 { 1264 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); 1265 if (log) 1266 { 1267 log->Printf("Discarding thread plans for thread (tid = 0x%4.4" PRIx64 ", force %d)", GetID(), force); 1268 } 1269 1270 if (force) 1271 { 1272 int stack_size = m_plan_stack.size(); 1273 for (int i = stack_size - 1; i > 0; i--) 1274 { 1275 DiscardPlan(); 1276 } 1277 return; 1278 } 1279 1280 while (1) 1281 { 1282 1283 int master_plan_idx; 1284 bool discard = true; 1285 1286 // Find the first master plan, see if it wants discarding, and if yes discard up to it. 1287 for (master_plan_idx = m_plan_stack.size() - 1; master_plan_idx >= 0; master_plan_idx--) 1288 { 1289 if (m_plan_stack[master_plan_idx]->IsMasterPlan()) 1290 { 1291 discard = m_plan_stack[master_plan_idx]->OkayToDiscard(); 1292 break; 1293 } 1294 } 1295 1296 if (discard) 1297 { 1298 // First pop all the dependent plans: 1299 for (int i = m_plan_stack.size() - 1; i > master_plan_idx; i--) 1300 { 1301 1302 // FIXME: Do we need a finalize here, or is the rule that "PrepareForStop" 1303 // for the plan leaves it in a state that it is safe to pop the plan 1304 // with no more notice? 1305 DiscardPlan(); 1306 } 1307 1308 // Now discard the master plan itself. 1309 // The bottom-most plan never gets discarded. "OkayToDiscard" for it means 1310 // discard it's dependent plans, but not it... 1311 if (master_plan_idx > 0) 1312 { 1313 DiscardPlan(); 1314 } 1315 } 1316 else 1317 { 1318 // If the master plan doesn't want to get discarded, then we're done. 1319 break; 1320 } 1321 1322 } 1323 } 1324 1325 bool 1326 Thread::PlanIsBasePlan (ThreadPlan *plan_ptr) 1327 { 1328 if (plan_ptr->IsBasePlan()) 1329 return true; 1330 else if (m_plan_stack.size() == 0) 1331 return false; 1332 else 1333 return m_plan_stack[0].get() == plan_ptr; 1334 } 1335 1336 Error 1337 Thread::UnwindInnermostExpression() 1338 { 1339 Error error; 1340 int stack_size = m_plan_stack.size(); 1341 1342 // If the input plan is NULL, discard all plans. Otherwise make sure this plan is in the 1343 // stack, and if so discard up to and including it. 1344 1345 for (int i = stack_size - 1; i > 0; i--) 1346 { 1347 if (m_plan_stack[i]->GetKind() == ThreadPlan::eKindCallFunction) 1348 { 1349 DiscardThreadPlansUpToPlan(m_plan_stack[i].get()); 1350 return error; 1351 } 1352 } 1353 error.SetErrorString("No expressions currently active on this thread"); 1354 return error; 1355 } 1356 1357 1358 ThreadPlanSP 1359 Thread::QueueFundamentalPlan (bool abort_other_plans) 1360 { 1361 ThreadPlanSP thread_plan_sp (new ThreadPlanBase(*this)); 1362 QueueThreadPlan (thread_plan_sp, abort_other_plans); 1363 return thread_plan_sp; 1364 } 1365 1366 ThreadPlanSP 1367 Thread::QueueThreadPlanForStepSingleInstruction 1368 ( 1369 bool step_over, 1370 bool abort_other_plans, 1371 bool stop_other_threads 1372 ) 1373 { 1374 ThreadPlanSP thread_plan_sp (new ThreadPlanStepInstruction (*this, step_over, stop_other_threads, eVoteNoOpinion, eVoteNoOpinion)); 1375 QueueThreadPlan (thread_plan_sp, abort_other_plans); 1376 return thread_plan_sp; 1377 } 1378 1379 ThreadPlanSP 1380 Thread::QueueThreadPlanForStepOverRange 1381 ( 1382 bool abort_other_plans, 1383 const AddressRange &range, 1384 const SymbolContext &addr_context, 1385 lldb::RunMode stop_other_threads 1386 ) 1387 { 1388 ThreadPlanSP thread_plan_sp; 1389 thread_plan_sp.reset (new ThreadPlanStepOverRange (*this, range, addr_context, stop_other_threads)); 1390 1391 QueueThreadPlan (thread_plan_sp, abort_other_plans); 1392 return thread_plan_sp; 1393 } 1394 1395 ThreadPlanSP 1396 Thread::QueueThreadPlanForStepInRange 1397 ( 1398 bool abort_other_plans, 1399 const AddressRange &range, 1400 const SymbolContext &addr_context, 1401 const char *step_in_target, 1402 lldb::RunMode stop_other_threads, 1403 bool avoid_code_without_debug_info 1404 ) 1405 { 1406 ThreadPlanSP thread_plan_sp; 1407 ThreadPlanStepInRange *plan = new ThreadPlanStepInRange (*this, range, addr_context, stop_other_threads); 1408 if (avoid_code_without_debug_info) 1409 plan->GetFlags().Set (ThreadPlanShouldStopHere::eAvoidNoDebug); 1410 else 1411 plan->GetFlags().Clear (ThreadPlanShouldStopHere::eAvoidNoDebug); 1412 if (step_in_target) 1413 plan->SetStepInTarget(step_in_target); 1414 thread_plan_sp.reset (plan); 1415 1416 QueueThreadPlan (thread_plan_sp, abort_other_plans); 1417 return thread_plan_sp; 1418 } 1419 1420 1421 ThreadPlanSP 1422 Thread::QueueThreadPlanForStepOverBreakpointPlan (bool abort_other_plans) 1423 { 1424 ThreadPlanSP thread_plan_sp (new ThreadPlanStepOverBreakpoint (*this)); 1425 QueueThreadPlan (thread_plan_sp, abort_other_plans); 1426 return thread_plan_sp; 1427 } 1428 1429 ThreadPlanSP 1430 Thread::QueueThreadPlanForStepOut 1431 ( 1432 bool abort_other_plans, 1433 SymbolContext *addr_context, 1434 bool first_insn, 1435 bool stop_other_threads, 1436 Vote stop_vote, 1437 Vote run_vote, 1438 uint32_t frame_idx 1439 ) 1440 { 1441 ThreadPlanSP thread_plan_sp (new ThreadPlanStepOut (*this, 1442 addr_context, 1443 first_insn, 1444 stop_other_threads, 1445 stop_vote, 1446 run_vote, 1447 frame_idx)); 1448 1449 if (thread_plan_sp->ValidatePlan(NULL)) 1450 { 1451 QueueThreadPlan (thread_plan_sp, abort_other_plans); 1452 return thread_plan_sp; 1453 } 1454 else 1455 { 1456 return ThreadPlanSP(); 1457 } 1458 } 1459 1460 ThreadPlanSP 1461 Thread::QueueThreadPlanForStepThrough (StackID &return_stack_id, bool abort_other_plans, bool stop_other_threads) 1462 { 1463 ThreadPlanSP thread_plan_sp(new ThreadPlanStepThrough (*this, return_stack_id, stop_other_threads)); 1464 if (!thread_plan_sp || !thread_plan_sp->ValidatePlan (NULL)) 1465 return ThreadPlanSP(); 1466 1467 QueueThreadPlan (thread_plan_sp, abort_other_plans); 1468 return thread_plan_sp; 1469 } 1470 1471 ThreadPlanSP 1472 Thread::QueueThreadPlanForCallFunction (bool abort_other_plans, 1473 Address& function, 1474 lldb::addr_t arg, 1475 bool stop_other_threads, 1476 bool unwind_on_error, 1477 bool ignore_breakpoints) 1478 { 1479 ThreadPlanSP thread_plan_sp (new ThreadPlanCallFunction (*this, 1480 function, 1481 ClangASTType(), 1482 arg, 1483 stop_other_threads, 1484 unwind_on_error, 1485 ignore_breakpoints)); 1486 QueueThreadPlan (thread_plan_sp, abort_other_plans); 1487 return thread_plan_sp; 1488 } 1489 1490 ThreadPlanSP 1491 Thread::QueueThreadPlanForRunToAddress (bool abort_other_plans, 1492 Address &target_addr, 1493 bool stop_other_threads) 1494 { 1495 ThreadPlanSP thread_plan_sp (new ThreadPlanRunToAddress (*this, target_addr, stop_other_threads)); 1496 QueueThreadPlan (thread_plan_sp, abort_other_plans); 1497 return thread_plan_sp; 1498 } 1499 1500 ThreadPlanSP 1501 Thread::QueueThreadPlanForStepUntil (bool abort_other_plans, 1502 lldb::addr_t *address_list, 1503 size_t num_addresses, 1504 bool stop_other_threads, 1505 uint32_t frame_idx) 1506 { 1507 ThreadPlanSP thread_plan_sp (new ThreadPlanStepUntil (*this, address_list, num_addresses, stop_other_threads, frame_idx)); 1508 QueueThreadPlan (thread_plan_sp, abort_other_plans); 1509 return thread_plan_sp; 1510 1511 } 1512 1513 uint32_t 1514 Thread::GetIndexID () const 1515 { 1516 return m_index_id; 1517 } 1518 1519 void 1520 Thread::DumpThreadPlans (lldb_private::Stream *s) const 1521 { 1522 uint32_t stack_size = m_plan_stack.size(); 1523 int i; 1524 s->Indent(); 1525 s->Printf ("Plan Stack for thread #%u: tid = 0x%4.4" PRIx64 ", stack_size = %d\n", GetIndexID(), GetID(), stack_size); 1526 for (i = stack_size - 1; i >= 0; i--) 1527 { 1528 s->IndentMore(); 1529 s->Indent(); 1530 s->Printf ("Element %d: ", i); 1531 m_plan_stack[i]->GetDescription (s, eDescriptionLevelFull); 1532 s->EOL(); 1533 s->IndentLess(); 1534 } 1535 1536 stack_size = m_completed_plan_stack.size(); 1537 if (stack_size > 0) 1538 { 1539 s->Indent(); 1540 s->Printf ("Completed Plan Stack: %d elements.\n", stack_size); 1541 for (i = stack_size - 1; i >= 0; i--) 1542 { 1543 s->IndentMore(); 1544 s->Indent(); 1545 s->Printf ("Element %d: ", i); 1546 m_completed_plan_stack[i]->GetDescription (s, eDescriptionLevelFull); 1547 s->EOL(); 1548 s->IndentLess(); 1549 } 1550 } 1551 1552 stack_size = m_discarded_plan_stack.size(); 1553 if (stack_size > 0) 1554 { 1555 s->Indent(); 1556 s->Printf ("Discarded Plan Stack: %d elements.\n", stack_size); 1557 for (i = stack_size - 1; i >= 0; i--) 1558 { 1559 s->IndentMore(); 1560 s->Indent(); 1561 s->Printf ("Element %d: ", i); 1562 m_discarded_plan_stack[i]->GetDescription (s, eDescriptionLevelFull); 1563 s->EOL(); 1564 s->IndentLess(); 1565 } 1566 } 1567 1568 } 1569 1570 TargetSP 1571 Thread::CalculateTarget () 1572 { 1573 TargetSP target_sp; 1574 ProcessSP process_sp(GetProcess()); 1575 if (process_sp) 1576 target_sp = process_sp->CalculateTarget(); 1577 return target_sp; 1578 1579 } 1580 1581 ProcessSP 1582 Thread::CalculateProcess () 1583 { 1584 return GetProcess(); 1585 } 1586 1587 ThreadSP 1588 Thread::CalculateThread () 1589 { 1590 return shared_from_this(); 1591 } 1592 1593 StackFrameSP 1594 Thread::CalculateStackFrame () 1595 { 1596 return StackFrameSP(); 1597 } 1598 1599 void 1600 Thread::CalculateExecutionContext (ExecutionContext &exe_ctx) 1601 { 1602 exe_ctx.SetContext (shared_from_this()); 1603 } 1604 1605 1606 StackFrameListSP 1607 Thread::GetStackFrameList () 1608 { 1609 StackFrameListSP frame_list_sp; 1610 Mutex::Locker locker(m_frame_mutex); 1611 if (m_curr_frames_sp) 1612 { 1613 frame_list_sp = m_curr_frames_sp; 1614 } 1615 else 1616 { 1617 frame_list_sp.reset(new StackFrameList (*this, m_prev_frames_sp, true)); 1618 m_curr_frames_sp = frame_list_sp; 1619 } 1620 return frame_list_sp; 1621 } 1622 1623 void 1624 Thread::ClearStackFrames () 1625 { 1626 Mutex::Locker locker(m_frame_mutex); 1627 1628 Unwind *unwinder = GetUnwinder (); 1629 if (unwinder) 1630 unwinder->Clear(); 1631 1632 // Only store away the old "reference" StackFrameList if we got all its frames: 1633 // FIXME: At some point we can try to splice in the frames we have fetched into 1634 // the new frame as we make it, but let's not try that now. 1635 if (m_curr_frames_sp && m_curr_frames_sp->GetAllFramesFetched()) 1636 m_prev_frames_sp.swap (m_curr_frames_sp); 1637 m_curr_frames_sp.reset(); 1638 } 1639 1640 lldb::StackFrameSP 1641 Thread::GetFrameWithConcreteFrameIndex (uint32_t unwind_idx) 1642 { 1643 return GetStackFrameList()->GetFrameWithConcreteFrameIndex (unwind_idx); 1644 } 1645 1646 1647 Error 1648 Thread::ReturnFromFrameWithIndex (uint32_t frame_idx, lldb::ValueObjectSP return_value_sp, bool broadcast) 1649 { 1650 StackFrameSP frame_sp = GetStackFrameAtIndex (frame_idx); 1651 Error return_error; 1652 1653 if (!frame_sp) 1654 { 1655 return_error.SetErrorStringWithFormat("Could not find frame with index %d in thread 0x%" PRIx64 ".", frame_idx, GetID()); 1656 } 1657 1658 return ReturnFromFrame(frame_sp, return_value_sp, broadcast); 1659 } 1660 1661 Error 1662 Thread::ReturnFromFrame (lldb::StackFrameSP frame_sp, lldb::ValueObjectSP return_value_sp, bool broadcast) 1663 { 1664 Error return_error; 1665 1666 if (!frame_sp) 1667 { 1668 return_error.SetErrorString("Can't return to a null frame."); 1669 return return_error; 1670 } 1671 1672 Thread *thread = frame_sp->GetThread().get(); 1673 uint32_t older_frame_idx = frame_sp->GetFrameIndex() + 1; 1674 StackFrameSP older_frame_sp = thread->GetStackFrameAtIndex(older_frame_idx); 1675 if (!older_frame_sp) 1676 { 1677 return_error.SetErrorString("No older frame to return to."); 1678 return return_error; 1679 } 1680 1681 if (return_value_sp) 1682 { 1683 lldb::ABISP abi = thread->GetProcess()->GetABI(); 1684 if (!abi) 1685 { 1686 return_error.SetErrorString("Could not find ABI to set return value."); 1687 return return_error; 1688 } 1689 SymbolContext sc = frame_sp->GetSymbolContext(eSymbolContextFunction); 1690 1691 // FIXME: ValueObject::Cast doesn't currently work correctly, at least not for scalars. 1692 // Turn that back on when that works. 1693 if (0 && sc.function != NULL) 1694 { 1695 Type *function_type = sc.function->GetType(); 1696 if (function_type) 1697 { 1698 ClangASTType return_type = sc.function->GetClangType().GetFunctionReturnType(); 1699 if (return_type) 1700 { 1701 StreamString s; 1702 return_type.DumpTypeDescription(&s); 1703 ValueObjectSP cast_value_sp = return_value_sp->Cast(return_type); 1704 if (cast_value_sp) 1705 { 1706 cast_value_sp->SetFormat(eFormatHex); 1707 return_value_sp = cast_value_sp; 1708 } 1709 } 1710 } 1711 } 1712 1713 return_error = abi->SetReturnValueObject(older_frame_sp, return_value_sp); 1714 if (!return_error.Success()) 1715 return return_error; 1716 } 1717 1718 // Now write the return registers for the chosen frame: 1719 // Note, we can't use ReadAllRegisterValues->WriteAllRegisterValues, since the read & write 1720 // cook their data 1721 1722 StackFrameSP youngest_frame_sp = thread->GetStackFrameAtIndex(0); 1723 if (youngest_frame_sp) 1724 { 1725 lldb::RegisterContextSP reg_ctx_sp (youngest_frame_sp->GetRegisterContext()); 1726 if (reg_ctx_sp) 1727 { 1728 bool copy_success = reg_ctx_sp->CopyFromRegisterContext(older_frame_sp->GetRegisterContext()); 1729 if (copy_success) 1730 { 1731 thread->DiscardThreadPlans(true); 1732 thread->ClearStackFrames(); 1733 if (broadcast && EventTypeHasListeners(eBroadcastBitStackChanged)) 1734 BroadcastEvent(eBroadcastBitStackChanged, new ThreadEventData (this->shared_from_this())); 1735 } 1736 else 1737 { 1738 return_error.SetErrorString("Could not reset register values."); 1739 } 1740 } 1741 else 1742 { 1743 return_error.SetErrorString("Frame has no register context."); 1744 } 1745 } 1746 else 1747 { 1748 return_error.SetErrorString("Returned past top frame."); 1749 } 1750 return return_error; 1751 } 1752 1753 static void DumpAddressList (Stream &s, const std::vector<Address> &list, ExecutionContextScope *exe_scope) 1754 { 1755 for (size_t n=0;n<list.size();n++) 1756 { 1757 s << "\t"; 1758 list[n].Dump (&s, exe_scope, Address::DumpStyleResolvedDescription, Address::DumpStyleSectionNameOffset); 1759 s << "\n"; 1760 } 1761 } 1762 1763 Error 1764 Thread::JumpToLine (const FileSpec &file, uint32_t line, bool can_leave_function, std::string *warnings) 1765 { 1766 ExecutionContext exe_ctx (GetStackFrameAtIndex(0)); 1767 Target *target = exe_ctx.GetTargetPtr(); 1768 TargetSP target_sp = exe_ctx.GetTargetSP(); 1769 RegisterContext *reg_ctx = exe_ctx.GetRegisterContext(); 1770 StackFrame *frame = exe_ctx.GetFramePtr(); 1771 const SymbolContext &sc = frame->GetSymbolContext(eSymbolContextFunction); 1772 1773 // Find candidate locations. 1774 std::vector<Address> candidates, within_function, outside_function; 1775 target->GetImages().FindAddressesForLine (target_sp, file, line, sc.function, within_function, outside_function); 1776 1777 // If possible, we try and stay within the current function. 1778 // Within a function, we accept multiple locations (optimized code may do this, 1779 // there's no solution here so we do the best we can). 1780 // However if we're trying to leave the function, we don't know how to pick the 1781 // right location, so if there's more than one then we bail. 1782 if (!within_function.empty()) 1783 candidates = within_function; 1784 else if (outside_function.size() == 1 && can_leave_function) 1785 candidates = outside_function; 1786 1787 // Check if we got anything. 1788 if (candidates.empty()) 1789 { 1790 if (outside_function.empty()) 1791 { 1792 return Error("Cannot locate an address for %s:%i.", 1793 file.GetFilename().AsCString(), line); 1794 } 1795 else if (outside_function.size() == 1) 1796 { 1797 return Error("%s:%i is outside the current function.", 1798 file.GetFilename().AsCString(), line); 1799 } 1800 else 1801 { 1802 StreamString sstr; 1803 DumpAddressList(sstr, outside_function, target); 1804 return Error("%s:%i has multiple candidate locations:\n%s", 1805 file.GetFilename().AsCString(), line, sstr.GetString().c_str()); 1806 } 1807 } 1808 1809 // Accept the first location, warn about any others. 1810 Address dest = candidates[0]; 1811 if (warnings && candidates.size() > 1) 1812 { 1813 StreamString sstr; 1814 sstr.Printf("%s:%i appears multiple times in this function, selecting the first location:\n", 1815 file.GetFilename().AsCString(), line); 1816 DumpAddressList(sstr, candidates, target); 1817 *warnings = sstr.GetString(); 1818 } 1819 1820 if (!reg_ctx->SetPC (dest)) 1821 return Error("Cannot change PC to target address."); 1822 1823 return Error(); 1824 } 1825 1826 void 1827 Thread::DumpUsingSettingsFormat (Stream &strm, uint32_t frame_idx) 1828 { 1829 ExecutionContext exe_ctx (shared_from_this()); 1830 Process *process = exe_ctx.GetProcessPtr(); 1831 if (process == NULL) 1832 return; 1833 1834 StackFrameSP frame_sp; 1835 SymbolContext frame_sc; 1836 if (frame_idx != LLDB_INVALID_INDEX32) 1837 { 1838 frame_sp = GetStackFrameAtIndex (frame_idx); 1839 if (frame_sp) 1840 { 1841 exe_ctx.SetFrameSP(frame_sp); 1842 frame_sc = frame_sp->GetSymbolContext(eSymbolContextEverything); 1843 } 1844 } 1845 1846 const char *thread_format = exe_ctx.GetTargetRef().GetDebugger().GetThreadFormat(); 1847 assert (thread_format); 1848 Debugger::FormatPrompt (thread_format, 1849 frame_sp ? &frame_sc : NULL, 1850 &exe_ctx, 1851 NULL, 1852 strm); 1853 } 1854 1855 void 1856 Thread::SettingsInitialize () 1857 { 1858 } 1859 1860 void 1861 Thread::SettingsTerminate () 1862 { 1863 } 1864 1865 lldb::addr_t 1866 Thread::GetThreadPointer () 1867 { 1868 return LLDB_INVALID_ADDRESS; 1869 } 1870 1871 addr_t 1872 Thread::GetThreadLocalData (const ModuleSP module) 1873 { 1874 // The default implementation is to ask the dynamic loader for it. 1875 // This can be overridden for specific platforms. 1876 DynamicLoader *loader = GetProcess()->GetDynamicLoader(); 1877 if (loader) 1878 return loader->GetThreadLocalData (module, shared_from_this()); 1879 else 1880 return LLDB_INVALID_ADDRESS; 1881 } 1882 1883 lldb::StackFrameSP 1884 Thread::GetStackFrameSPForStackFramePtr (StackFrame *stack_frame_ptr) 1885 { 1886 return GetStackFrameList()->GetStackFrameSPForStackFramePtr (stack_frame_ptr); 1887 } 1888 1889 const char * 1890 Thread::StopReasonAsCString (lldb::StopReason reason) 1891 { 1892 switch (reason) 1893 { 1894 case eStopReasonInvalid: return "invalid"; 1895 case eStopReasonNone: return "none"; 1896 case eStopReasonTrace: return "trace"; 1897 case eStopReasonBreakpoint: return "breakpoint"; 1898 case eStopReasonWatchpoint: return "watchpoint"; 1899 case eStopReasonSignal: return "signal"; 1900 case eStopReasonException: return "exception"; 1901 case eStopReasonExec: return "exec"; 1902 case eStopReasonPlanComplete: return "plan complete"; 1903 case eStopReasonThreadExiting: return "thread exiting"; 1904 } 1905 1906 1907 static char unknown_state_string[64]; 1908 snprintf(unknown_state_string, sizeof (unknown_state_string), "StopReason = %i", reason); 1909 return unknown_state_string; 1910 } 1911 1912 const char * 1913 Thread::RunModeAsCString (lldb::RunMode mode) 1914 { 1915 switch (mode) 1916 { 1917 case eOnlyThisThread: return "only this thread"; 1918 case eAllThreads: return "all threads"; 1919 case eOnlyDuringStepping: return "only during stepping"; 1920 } 1921 1922 static char unknown_state_string[64]; 1923 snprintf(unknown_state_string, sizeof (unknown_state_string), "RunMode = %i", mode); 1924 return unknown_state_string; 1925 } 1926 1927 size_t 1928 Thread::GetStatus (Stream &strm, uint32_t start_frame, uint32_t num_frames, uint32_t num_frames_with_source) 1929 { 1930 ExecutionContext exe_ctx (shared_from_this()); 1931 Target *target = exe_ctx.GetTargetPtr(); 1932 Process *process = exe_ctx.GetProcessPtr(); 1933 size_t num_frames_shown = 0; 1934 strm.Indent(); 1935 bool is_selected = false; 1936 if (process) 1937 { 1938 if (process->GetThreadList().GetSelectedThread().get() == this) 1939 is_selected = true; 1940 } 1941 strm.Printf("%c ", is_selected ? '*' : ' '); 1942 if (target && target->GetDebugger().GetUseExternalEditor()) 1943 { 1944 StackFrameSP frame_sp = GetStackFrameAtIndex(start_frame); 1945 if (frame_sp) 1946 { 1947 SymbolContext frame_sc(frame_sp->GetSymbolContext (eSymbolContextLineEntry)); 1948 if (frame_sc.line_entry.line != 0 && frame_sc.line_entry.file) 1949 { 1950 Host::OpenFileInExternalEditor (frame_sc.line_entry.file, frame_sc.line_entry.line); 1951 } 1952 } 1953 } 1954 1955 DumpUsingSettingsFormat (strm, start_frame); 1956 1957 if (num_frames > 0) 1958 { 1959 strm.IndentMore(); 1960 1961 const bool show_frame_info = true; 1962 1963 const char *selected_frame_marker = NULL; 1964 if (num_frames == 1 || (GetID() != GetProcess()->GetThreadList().GetSelectedThread()->GetID())) 1965 strm.IndentMore (); 1966 else 1967 selected_frame_marker = "* "; 1968 1969 num_frames_shown = GetStackFrameList ()->GetStatus (strm, 1970 start_frame, 1971 num_frames, 1972 show_frame_info, 1973 num_frames_with_source, 1974 selected_frame_marker); 1975 if (num_frames == 1) 1976 strm.IndentLess(); 1977 strm.IndentLess(); 1978 } 1979 return num_frames_shown; 1980 } 1981 1982 size_t 1983 Thread::GetStackFrameStatus (Stream& strm, 1984 uint32_t first_frame, 1985 uint32_t num_frames, 1986 bool show_frame_info, 1987 uint32_t num_frames_with_source) 1988 { 1989 return GetStackFrameList()->GetStatus (strm, 1990 first_frame, 1991 num_frames, 1992 show_frame_info, 1993 num_frames_with_source); 1994 } 1995 1996 bool 1997 Thread::SaveFrameZeroState (RegisterCheckpoint &checkpoint) 1998 { 1999 lldb::StackFrameSP frame_sp(GetStackFrameAtIndex (0)); 2000 if (frame_sp) 2001 { 2002 checkpoint.SetStackID(frame_sp->GetStackID()); 2003 lldb::RegisterContextSP reg_ctx_sp (frame_sp->GetRegisterContext()); 2004 if (reg_ctx_sp) 2005 return reg_ctx_sp->ReadAllRegisterValues (checkpoint.GetData()); 2006 } 2007 return false; 2008 } 2009 2010 bool 2011 Thread::RestoreSaveFrameZero (const RegisterCheckpoint &checkpoint) 2012 { 2013 return ResetFrameZeroRegisters (checkpoint.GetData()); 2014 } 2015 2016 bool 2017 Thread::ResetFrameZeroRegisters (lldb::DataBufferSP register_data_sp) 2018 { 2019 lldb::StackFrameSP frame_sp(GetStackFrameAtIndex (0)); 2020 if (frame_sp) 2021 { 2022 lldb::RegisterContextSP reg_ctx_sp (frame_sp->GetRegisterContext()); 2023 if (reg_ctx_sp) 2024 { 2025 bool ret = reg_ctx_sp->WriteAllRegisterValues (register_data_sp); 2026 2027 // Clear out all stack frames as our world just changed. 2028 ClearStackFrames(); 2029 reg_ctx_sp->InvalidateIfNeeded(true); 2030 if (m_unwinder_ap.get()) 2031 m_unwinder_ap->Clear(); 2032 return ret; 2033 } 2034 } 2035 return false; 2036 } 2037 2038 Unwind * 2039 Thread::GetUnwinder () 2040 { 2041 if (m_unwinder_ap.get() == NULL) 2042 { 2043 const ArchSpec target_arch (CalculateTarget()->GetArchitecture ()); 2044 const llvm::Triple::ArchType machine = target_arch.GetMachine(); 2045 switch (machine) 2046 { 2047 case llvm::Triple::x86_64: 2048 case llvm::Triple::x86: 2049 case llvm::Triple::arm: 2050 case llvm::Triple::thumb: 2051 case llvm::Triple::mips64: 2052 m_unwinder_ap.reset (new UnwindLLDB (*this)); 2053 break; 2054 2055 default: 2056 if (target_arch.GetTriple().getVendor() == llvm::Triple::Apple) 2057 m_unwinder_ap.reset (new UnwindMacOSXFrameBackchain (*this)); 2058 break; 2059 } 2060 } 2061 return m_unwinder_ap.get(); 2062 } 2063 2064 2065 void 2066 Thread::Flush () 2067 { 2068 ClearStackFrames (); 2069 m_reg_context_sp.reset(); 2070 } 2071 2072 bool 2073 Thread::IsStillAtLastBreakpointHit () 2074 { 2075 // If we are currently stopped at a breakpoint, always return that stopinfo and don't reset it. 2076 // This allows threads to maintain their breakpoint stopinfo, such as when thread-stepping in 2077 // multithreaded programs. 2078 if (m_stop_info_sp) { 2079 StopReason stop_reason = m_stop_info_sp->GetStopReason(); 2080 if (stop_reason == lldb::eStopReasonBreakpoint) { 2081 uint64_t value = m_stop_info_sp->GetValue(); 2082 lldb::RegisterContextSP reg_ctx_sp (GetRegisterContext()); 2083 if (reg_ctx_sp) 2084 { 2085 lldb::addr_t pc = reg_ctx_sp->GetPC(); 2086 BreakpointSiteSP bp_site_sp = GetProcess()->GetBreakpointSiteList().FindByAddress(pc); 2087 if (bp_site_sp && value == bp_site_sp->GetID()) 2088 return true; 2089 } 2090 } 2091 } 2092 return false; 2093 } 2094