Thread.h revision 102b2c2681c9a830afe25bfea35557421905e42c
1//===-- Thread.h ------------------------------------------------*- 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#ifndef liblldb_Thread_h_ 11#define liblldb_Thread_h_ 12 13#include "lldb/lldb-private.h" 14#include "lldb/Host/Mutex.h" 15#include "lldb/Core/Broadcaster.h" 16#include "lldb/Core/Event.h" 17#include "lldb/Core/UserID.h" 18#include "lldb/Core/UserSettingsController.h" 19#include "lldb/Target/ExecutionContextScope.h" 20#include "lldb/Target/StackFrameList.h" 21 22#define LLDB_THREAD_MAX_STOP_EXC_DATA 8 23 24namespace lldb_private { 25 26class ThreadProperties : public Properties 27{ 28public: 29 ThreadProperties(bool is_global); 30 31 virtual 32 ~ThreadProperties(); 33 34 //------------------------------------------------------------------ 35 /// The regular expression returned determines symbols that this 36 /// thread won't stop in during "step-in" operations. 37 /// 38 /// @return 39 /// A pointer to a regular expression to compare against symbols, 40 /// or NULL if all symbols are allowed. 41 /// 42 //------------------------------------------------------------------ 43 const RegularExpression * 44 GetSymbolsToAvoidRegexp(); 45 46 bool 47 GetTraceEnabledState() const; 48}; 49 50typedef std::shared_ptr<ThreadProperties> ThreadPropertiesSP; 51 52class Thread : 53 public std::enable_shared_from_this<Thread>, 54 public ThreadProperties, 55 public UserID, 56 public ExecutionContextScope, 57 public Broadcaster 58{ 59public: 60 //------------------------------------------------------------------ 61 /// Broadcaster event bits definitions. 62 //------------------------------------------------------------------ 63 enum 64 { 65 eBroadcastBitStackChanged = (1 << 0), 66 eBroadcastBitThreadSuspended = (1 << 1), 67 eBroadcastBitThreadResumed = (1 << 2), 68 eBroadcastBitSelectedFrameChanged = (1 << 3), 69 eBroadcastBitThreadSelected = (1 << 4) 70 }; 71 72 static ConstString &GetStaticBroadcasterClass (); 73 74 virtual ConstString &GetBroadcasterClass() const 75 { 76 return GetStaticBroadcasterClass(); 77 } 78 79 class ThreadEventData : 80 public EventData 81 { 82 public: 83 ThreadEventData (const lldb::ThreadSP thread_sp); 84 85 ThreadEventData (const lldb::ThreadSP thread_sp, const StackID &stack_id); 86 87 ThreadEventData(); 88 89 virtual ~ThreadEventData(); 90 91 static const ConstString & 92 GetFlavorString (); 93 94 virtual const ConstString & 95 GetFlavor () const 96 { 97 return ThreadEventData::GetFlavorString (); 98 } 99 100 virtual void 101 Dump (Stream *s) const; 102 103 static const ThreadEventData * 104 GetEventDataFromEvent (const Event *event_ptr); 105 106 static lldb::ThreadSP 107 GetThreadFromEvent (const Event *event_ptr); 108 109 static StackID 110 GetStackIDFromEvent (const Event *event_ptr); 111 112 static lldb::StackFrameSP 113 GetStackFrameFromEvent (const Event *event_ptr); 114 115 lldb::ThreadSP 116 GetThread () const 117 { 118 return m_thread_sp; 119 } 120 121 StackID 122 GetStackID () const 123 { 124 return m_stack_id; 125 } 126 127 private: 128 lldb::ThreadSP m_thread_sp; 129 StackID m_stack_id; 130 DISALLOW_COPY_AND_ASSIGN (ThreadEventData); 131 }; 132 133 // TODO: You shouldn't just checkpoint the register state alone, so this should get 134 // moved to protected. To do that ThreadStateCheckpoint needs to be returned as a token... 135 class RegisterCheckpoint 136 { 137 public: 138 139 RegisterCheckpoint() : 140 m_stack_id (), 141 m_data_sp () 142 { 143 } 144 145 RegisterCheckpoint (const StackID &stack_id) : 146 m_stack_id (stack_id), 147 m_data_sp () 148 { 149 } 150 151 ~RegisterCheckpoint() 152 { 153 } 154 155 const RegisterCheckpoint& 156 operator= (const RegisterCheckpoint &rhs) 157 { 158 if (this != &rhs) 159 { 160 this->m_stack_id = rhs.m_stack_id; 161 this->m_data_sp = rhs.m_data_sp; 162 } 163 return *this; 164 } 165 166 RegisterCheckpoint (const RegisterCheckpoint &rhs) : 167 m_stack_id (rhs.m_stack_id), 168 m_data_sp (rhs.m_data_sp) 169 { 170 } 171 172 const StackID & 173 GetStackID() 174 { 175 return m_stack_id; 176 } 177 178 void 179 SetStackID (const StackID &stack_id) 180 { 181 m_stack_id = stack_id; 182 } 183 184 lldb::DataBufferSP & 185 GetData() 186 { 187 return m_data_sp; 188 } 189 190 const lldb::DataBufferSP & 191 GetData() const 192 { 193 return m_data_sp; 194 } 195 196 protected: 197 StackID m_stack_id; 198 lldb::DataBufferSP m_data_sp; 199 }; 200 201 struct ThreadStateCheckpoint 202 { 203 uint32_t orig_stop_id; // Dunno if I need this yet but it is an interesting bit of data. 204 lldb::StopInfoSP stop_info_sp; // You have to restore the stop info or you might continue with the wrong signals. 205 RegisterCheckpoint register_backup; // You need to restore the registers, of course... 206 uint32_t current_inlined_depth; 207 lldb::addr_t current_inlined_pc; 208 }; 209 210 static void 211 SettingsInitialize (); 212 213 static void 214 SettingsTerminate (); 215 216 static const ThreadPropertiesSP & 217 GetGlobalProperties(); 218 219 Thread (Process &process, lldb::tid_t tid); 220 virtual ~Thread(); 221 222 lldb::ProcessSP 223 GetProcess() const 224 { 225 return m_process_wp.lock(); 226 } 227 228 int 229 GetResumeSignal () const 230 { 231 return m_resume_signal; 232 } 233 234 void 235 SetResumeSignal (int signal) 236 { 237 m_resume_signal = signal; 238 } 239 240 lldb::StateType 241 GetState() const; 242 243 void 244 SetState (lldb::StateType state); 245 246 lldb::StateType 247 GetResumeState () const 248 { 249 return m_resume_state; 250 } 251 252 void 253 SetResumeState (lldb::StateType state) 254 { 255 m_resume_state = state; 256 } 257 258 // This function is called on all the threads before "WillResume" in case 259 // a thread needs to change its state before the ThreadList polls all the 260 // threads to figure out which ones actually will get to run and how. 261 void 262 SetupForResume (); 263 264 // Override this to do platform specific tasks before resume, but always 265 // call the Thread::WillResume at the end of your work. 266 267 virtual bool 268 WillResume (lldb::StateType resume_state); 269 270 // This clears generic thread state after a resume. If you subclass this, 271 // be sure to call it. 272 virtual void 273 DidResume (); 274 275 virtual void 276 RefreshStateAfterStop() = 0; 277 278 void 279 WillStop (); 280 281 bool 282 ShouldStop (Event *event_ptr); 283 284 Vote 285 ShouldReportStop (Event *event_ptr); 286 287 Vote 288 ShouldReportRun (Event *event_ptr); 289 290 void 291 Flush (); 292 293 // Return whether this thread matches the specification in ThreadSpec. This is a virtual 294 // method because at some point we may extend the thread spec with a platform specific 295 // dictionary of attributes, which then only the platform specific Thread implementation 296 // would know how to match. For now, this just calls through to the ThreadSpec's 297 // ThreadPassesBasicTests method. 298 virtual bool 299 MatchesSpec (const ThreadSpec *spec); 300 301 lldb::StopInfoSP 302 GetStopInfo (); 303 304 lldb::StopReason 305 GetStopReason(); 306 307 // This sets the stop reason to a "blank" stop reason, so you can call functions on the thread 308 // without having the called function run with whatever stop reason you stopped with. 309 void 310 SetStopInfoToNothing(); 311 312 bool 313 ThreadStoppedForAReason (); 314 315 static const char * 316 RunModeAsCString (lldb::RunMode mode); 317 318 static const char * 319 StopReasonAsCString (lldb::StopReason reason); 320 321 virtual const char * 322 GetInfo () 323 { 324 return NULL; 325 } 326 327 virtual const char * 328 GetName () 329 { 330 return NULL; 331 } 332 333 virtual const char * 334 GetQueueName () 335 { 336 return NULL; 337 } 338 339 virtual uint32_t 340 GetStackFrameCount() 341 { 342 return GetStackFrameList()->GetNumFrames(); 343 } 344 345 virtual lldb::StackFrameSP 346 GetStackFrameAtIndex (uint32_t idx) 347 { 348 return GetStackFrameList()->GetFrameAtIndex(idx); 349 } 350 351 virtual lldb::StackFrameSP 352 GetFrameWithConcreteFrameIndex (uint32_t unwind_idx); 353 354 bool 355 DecrementCurrentInlinedDepth() 356 { 357 return GetStackFrameList()->DecrementCurrentInlinedDepth(); 358 } 359 360 uint32_t 361 GetCurrentInlinedDepth() 362 { 363 return GetStackFrameList()->GetCurrentInlinedDepth(); 364 } 365 366 Error 367 ReturnFromFrameWithIndex (uint32_t frame_idx, lldb::ValueObjectSP return_value_sp, bool broadcast = false); 368 369 Error 370 ReturnFromFrame (lldb::StackFrameSP frame_sp, lldb::ValueObjectSP return_value_sp, bool broadcast = false); 371 372 virtual lldb::StackFrameSP 373 GetFrameWithStackID (const StackID &stack_id) 374 { 375 return GetStackFrameList()->GetFrameWithStackID (stack_id); 376 } 377 378 uint32_t 379 GetSelectedFrameIndex () 380 { 381 return GetStackFrameList()->GetSelectedFrameIndex(); 382 } 383 384 lldb::StackFrameSP 385 GetSelectedFrame () 386 { 387 lldb::StackFrameListSP stack_frame_list_sp(GetStackFrameList()); 388 return stack_frame_list_sp->GetFrameAtIndex (stack_frame_list_sp->GetSelectedFrameIndex()); 389 } 390 391 uint32_t 392 SetSelectedFrame (lldb_private::StackFrame *frame, bool broadcast = false); 393 394 395 bool 396 SetSelectedFrameByIndex (uint32_t frame_idx, bool broadcast = false); 397 398 bool 399 SetSelectedFrameByIndexNoisily (uint32_t frame_idx, Stream &output_stream); 400 401 void 402 SetDefaultFileAndLineToSelectedFrame() 403 { 404 GetStackFrameList()->SetDefaultFileAndLineToSelectedFrame(); 405 } 406 407 virtual lldb::RegisterContextSP 408 GetRegisterContext () = 0; 409 410 virtual lldb::RegisterContextSP 411 CreateRegisterContextForFrame (StackFrame *frame) = 0; 412 413 virtual void 414 ClearStackFrames (); 415 416 virtual bool 417 SetBackingThread (const lldb::ThreadSP &thread_sp) 418 { 419 return false; 420 } 421 422 virtual void 423 ClearBackingThread () 424 { 425 // Subclasses can use this function if a thread is actually backed by 426 // another thread. This is currently used for the OperatingSystem plug-ins 427 // where they might have a thread that is in memory, yet its registers 428 // are available through the lldb_private::Thread subclass for the current 429 // lldb_private::Process class. Since each time the process stops the backing 430 // threads for memory threads can change, we need a way to clear the backing 431 // thread for all memory threads each time we stop. 432 } 433 434 void 435 DumpUsingSettingsFormat (Stream &strm, uint32_t frame_idx); 436 437 //------------------------------------------------------------------ 438 // Thread Plan Providers: 439 // This section provides the basic thread plans that the Process control 440 // machinery uses to run the target. ThreadPlan.h provides more details on 441 // how this mechanism works. 442 // The thread provides accessors to a set of plans that perform basic operations. 443 // The idea is that particular Platform plugins can override these methods to 444 // provide the implementation of these basic operations appropriate to their 445 // environment. 446 //------------------------------------------------------------------ 447 448 //------------------------------------------------------------------ 449 /// Queues the base plan for a thread. 450 /// The version returned by Process does some things that are useful, 451 /// like handle breakpoints and signals, so if you return a plugin specific 452 /// one you probably want to call through to the Process one for anything 453 /// your plugin doesn't explicitly handle. 454 /// 455 /// @param[in] abort_other_plans 456 /// \b true if we discard the currently queued plans and replace them with this one. 457 /// Otherwise this plan will go on the end of the plan stack. 458 /// 459 /// @return 460 /// A pointer to the newly queued thread plan, or NULL if the plan could not be queued. 461 //------------------------------------------------------------------ 462 virtual ThreadPlan * 463 QueueFundamentalPlan (bool abort_other_plans); 464 465 //------------------------------------------------------------------ 466 /// Queues the plan used to step over a breakpoint at the current PC of \a thread. 467 /// The default version returned by Process handles trap based breakpoints, and 468 /// will disable the breakpoint, single step over it, then re-enable it. 469 /// 470 /// @param[in] abort_other_plans 471 /// \b true if we discard the currently queued plans and replace them with this one. 472 /// Otherwise this plan will go on the end of the plan stack. 473 /// 474 /// @return 475 /// A pointer to the newly queued thread plan, or NULL if the plan could not be queued. 476 //------------------------------------------------------------------ 477 virtual ThreadPlan * 478 QueueThreadPlanForStepOverBreakpointPlan (bool abort_other_plans); 479 480 //------------------------------------------------------------------ 481 /// Queues the plan used to step one instruction from the current PC of \a thread. 482 /// 483 /// @param[in] step_over 484 /// \b true if we step over calls to functions, false if we step in. 485 /// 486 /// @param[in] abort_other_plans 487 /// \b true if we discard the currently queued plans and replace them with this one. 488 /// Otherwise this plan will go on the end of the plan stack. 489 /// 490 /// @param[in] stop_other_threads 491 /// \b true if we will stop other threads while we single step this one. 492 /// 493 /// @return 494 /// A pointer to the newly queued thread plan, or NULL if the plan could not be queued. 495 //------------------------------------------------------------------ 496 virtual ThreadPlan * 497 QueueThreadPlanForStepSingleInstruction (bool step_over, 498 bool abort_other_plans, 499 bool stop_other_threads); 500 501 //------------------------------------------------------------------ 502 /// Queues the plan used to step through an address range, stepping over 503 /// function calls. 504 /// 505 /// @param[in] abort_other_plans 506 /// \b true if we discard the currently queued plans and replace them with this one. 507 /// Otherwise this plan will go on the end of the plan stack. 508 /// 509 /// @param[in] type 510 /// Type of step to do, only eStepTypeInto and eStepTypeOver are supported by this plan. 511 /// 512 /// @param[in] range 513 /// The address range to step through. 514 /// 515 /// @param[in] addr_context 516 /// When dealing with stepping through inlined functions the current PC is not enough information to know 517 /// what "step" means. For instance a series of nested inline functions might start at the same address. 518 // The \a addr_context provides the current symbol context the step 519 /// is supposed to be out of. 520 // FIXME: Currently unused. 521 /// 522 /// @param[in] stop_other_threads 523 /// \b true if we will stop other threads while we single step this one. 524 /// 525 /// @return 526 /// A pointer to the newly queued thread plan, or NULL if the plan could not be queued. 527 //------------------------------------------------------------------ 528 virtual ThreadPlan * 529 QueueThreadPlanForStepOverRange (bool abort_other_plans, 530 const AddressRange &range, 531 const SymbolContext &addr_context, 532 lldb::RunMode stop_other_threads); 533 534 //------------------------------------------------------------------ 535 /// Queues the plan used to step through an address range, stepping into functions. 536 /// 537 /// @param[in] abort_other_plans 538 /// \b true if we discard the currently queued plans and replace them with this one. 539 /// Otherwise this plan will go on the end of the plan stack. 540 /// 541 /// @param[in] type 542 /// Type of step to do, only eStepTypeInto and eStepTypeOver are supported by this plan. 543 /// 544 /// @param[in] range 545 /// The address range to step through. 546 /// 547 /// @param[in] addr_context 548 /// When dealing with stepping through inlined functions the current PC is not enough information to know 549 /// what "step" means. For instance a series of nested inline functions might start at the same address. 550 // The \a addr_context provides the current symbol context the step 551 /// is supposed to be out of. 552 // FIXME: Currently unused. 553 /// 554 /// @param[in] step_in_target 555 /// Name if function we are trying to step into. We will step out if we don't land in that function. 556 /// 557 /// @param[in] stop_other_threads 558 /// \b true if we will stop other threads while we single step this one. 559 /// 560 /// @param[in] avoid_code_without_debug_info 561 /// If \b true we will step out if we step into code with no debug info. 562 /// 563 /// @return 564 /// A pointer to the newly queued thread plan, or NULL if the plan could not be queued. 565 //------------------------------------------------------------------ 566 virtual ThreadPlan * 567 QueueThreadPlanForStepInRange (bool abort_other_plans, 568 const AddressRange &range, 569 const SymbolContext &addr_context, 570 const char *step_in_target, 571 lldb::RunMode stop_other_threads, 572 bool avoid_code_without_debug_info); 573 574 //------------------------------------------------------------------ 575 /// Queue the plan used to step out of the function at the current PC of 576 /// \a thread. 577 /// 578 /// @param[in] abort_other_plans 579 /// \b true if we discard the currently queued plans and replace them with this one. 580 /// Otherwise this plan will go on the end of the plan stack. 581 /// 582 /// @param[in] addr_context 583 /// When dealing with stepping through inlined functions the current PC is not enough information to know 584 /// what "step" means. For instance a series of nested inline functions might start at the same address. 585 // The \a addr_context provides the current symbol context the step 586 /// is supposed to be out of. 587 // FIXME: Currently unused. 588 /// 589 /// @param[in] first_insn 590 /// \b true if this is the first instruction of a function. 591 /// 592 /// @param[in] stop_other_threads 593 /// \b true if we will stop other threads while we single step this one. 594 /// 595 /// @param[in] stop_vote 596 /// @param[in] run_vote 597 /// See standard meanings for the stop & run votes in ThreadPlan.h. 598 /// 599 /// @return 600 /// A pointer to the newly queued thread plan, or NULL if the plan could not be queued. 601 //------------------------------------------------------------------ 602 virtual ThreadPlan * 603 QueueThreadPlanForStepOut (bool abort_other_plans, 604 SymbolContext *addr_context, 605 bool first_insn, 606 bool stop_other_threads, 607 Vote stop_vote, // = eVoteYes, 608 Vote run_vote, // = eVoteNoOpinion); 609 uint32_t frame_idx); 610 611 //------------------------------------------------------------------ 612 /// Gets the plan used to step through the code that steps from a function 613 /// call site at the current PC into the actual function call. 614 /// 615 /// 616 /// @param[in] return_stack_id 617 /// The stack id that we will return to (by setting backstop breakpoints on the return 618 /// address to that frame) if we fail to step through. 619 /// 620 /// @param[in] abort_other_plans 621 /// \b true if we discard the currently queued plans and replace them with this one. 622 /// Otherwise this plan will go on the end of the plan stack. 623 /// 624 /// @param[in] stop_other_threads 625 /// \b true if we will stop other threads while we single step this one. 626 /// 627 /// @return 628 /// A pointer to the newly queued thread plan, or NULL if the plan could not be queued. 629 //------------------------------------------------------------------ 630 virtual ThreadPlan * 631 QueueThreadPlanForStepThrough (StackID &return_stack_id, 632 bool abort_other_plans, 633 bool stop_other_threads); 634 635 //------------------------------------------------------------------ 636 /// Gets the plan used to continue from the current PC. 637 /// This is a simple plan, mostly useful as a backstop when you are continuing 638 /// for some particular purpose. 639 /// 640 /// @param[in] abort_other_plans 641 /// \b true if we discard the currently queued plans and replace them with this one. 642 /// Otherwise this plan will go on the end of the plan stack. 643 /// 644 /// @param[in] target_addr 645 /// The address to which we're running. 646 /// 647 /// @param[in] stop_other_threads 648 /// \b true if we will stop other threads while we single step this one. 649 /// 650 /// @return 651 /// A pointer to the newly queued thread plan, or NULL if the plan could not be queued. 652 //------------------------------------------------------------------ 653 virtual ThreadPlan * 654 QueueThreadPlanForRunToAddress (bool abort_other_plans, 655 Address &target_addr, 656 bool stop_other_threads); 657 658 virtual ThreadPlan * 659 QueueThreadPlanForStepUntil (bool abort_other_plans, 660 lldb::addr_t *address_list, 661 size_t num_addresses, 662 bool stop_others, 663 uint32_t frame_idx); 664 665 virtual ThreadPlan * 666 QueueThreadPlanForCallFunction (bool abort_other_plans, 667 Address& function, 668 lldb::addr_t arg, 669 bool stop_other_threads, 670 bool unwind_on_error = false, 671 bool ignore_breakpoints = true); 672 673 //------------------------------------------------------------------ 674 // Thread Plan accessors: 675 //------------------------------------------------------------------ 676 677 //------------------------------------------------------------------ 678 /// Gets the plan which will execute next on the plan stack. 679 /// 680 /// @return 681 /// A pointer to the next executed plan. 682 //------------------------------------------------------------------ 683 ThreadPlan * 684 GetCurrentPlan (); 685 686 //------------------------------------------------------------------ 687 /// Unwinds the thread stack for the innermost expression plan currently 688 /// on the thread plan stack. 689 /// 690 /// @return 691 /// An error if the thread plan could not be unwound. 692 //------------------------------------------------------------------ 693 694 Error 695 UnwindInnermostExpression(); 696 697private: 698 bool 699 PlanIsBasePlan (ThreadPlan *plan_ptr); 700 701 void 702 BroadcastSelectedFrameChange(StackID &new_frame_id); 703 704public: 705 706 //------------------------------------------------------------------ 707 /// Gets the outer-most plan that was popped off the plan stack in the 708 /// most recent stop. Useful for printing the stop reason accurately. 709 /// 710 /// @return 711 /// A pointer to the last completed plan. 712 //------------------------------------------------------------------ 713 lldb::ThreadPlanSP 714 GetCompletedPlan (); 715 716 //------------------------------------------------------------------ 717 /// Gets the outer-most return value from the completed plans 718 /// 719 /// @return 720 /// A ValueObjectSP, either empty if there is no return value, 721 /// or containing the return value. 722 //------------------------------------------------------------------ 723 lldb::ValueObjectSP 724 GetReturnValueObject (); 725 726 //------------------------------------------------------------------ 727 /// Checks whether the given plan is in the completed plans for this 728 /// stop. 729 /// 730 /// @param[in] plan 731 /// Pointer to the plan you're checking. 732 /// 733 /// @return 734 /// Returns true if the input plan is in the completed plan stack, 735 /// false otherwise. 736 //------------------------------------------------------------------ 737 bool 738 IsThreadPlanDone (ThreadPlan *plan); 739 740 //------------------------------------------------------------------ 741 /// Checks whether the given plan is in the discarded plans for this 742 /// stop. 743 /// 744 /// @param[in] plan 745 /// Pointer to the plan you're checking. 746 /// 747 /// @return 748 /// Returns true if the input plan is in the discarded plan stack, 749 /// false otherwise. 750 //------------------------------------------------------------------ 751 bool 752 WasThreadPlanDiscarded (ThreadPlan *plan); 753 754 //------------------------------------------------------------------ 755 /// Queues a generic thread plan. 756 /// 757 /// @param[in] plan_sp 758 /// The plan to queue. 759 /// 760 /// @param[in] abort_other_plans 761 /// \b true if we discard the currently queued plans and replace them with this one. 762 /// Otherwise this plan will go on the end of the plan stack. 763 /// 764 /// @return 765 /// A pointer to the last completed plan. 766 //------------------------------------------------------------------ 767 void 768 QueueThreadPlan (lldb::ThreadPlanSP &plan_sp, bool abort_other_plans); 769 770 771 //------------------------------------------------------------------ 772 /// Discards the plans queued on the plan stack of the current thread. This is 773 /// arbitrated by the "Master" ThreadPlans, using the "OkayToDiscard" call. 774 // But if \a force is true, all thread plans are discarded. 775 //------------------------------------------------------------------ 776 void 777 DiscardThreadPlans (bool force); 778 779 //------------------------------------------------------------------ 780 /// Discards the plans queued on the plan stack of the current thread up to and 781 /// including up_to_plan_sp. 782 // 783 // @param[in] up_to_plan_sp 784 // Discard all plans up to and including this one. 785 //------------------------------------------------------------------ 786 void 787 DiscardThreadPlansUpToPlan (lldb::ThreadPlanSP &up_to_plan_sp); 788 789 void 790 DiscardThreadPlansUpToPlan (ThreadPlan *up_to_plan_ptr); 791 792 //------------------------------------------------------------------ 793 /// Prints the current plan stack. 794 /// 795 /// @param[in] s 796 /// The stream to which to dump the plan stack info. 797 /// 798 //------------------------------------------------------------------ 799 void 800 DumpThreadPlans (Stream *s) const; 801 802 virtual bool 803 CheckpointThreadState (ThreadStateCheckpoint &saved_state); 804 805 virtual bool 806 RestoreRegisterStateFromCheckpoint (ThreadStateCheckpoint &saved_state); 807 808 virtual bool 809 RestoreThreadStateFromCheckpoint (ThreadStateCheckpoint &saved_state); 810 811 void 812 EnableTracer (bool value, bool single_step); 813 814 void 815 SetTracer (lldb::ThreadPlanTracerSP &tracer_sp); 816 817 // Get the thread index ID. The index ID that is guaranteed to not be 818 // re-used by a process. They start at 1 and increase with each new thread. 819 // This allows easy command line access by a unique ID that is easier to 820 // type than the actual system thread ID. 821 uint32_t 822 GetIndexID () const; 823 824 //------------------------------------------------------------------ 825 // lldb::ExecutionContextScope pure virtual functions 826 //------------------------------------------------------------------ 827 virtual lldb::TargetSP 828 CalculateTarget (); 829 830 virtual lldb::ProcessSP 831 CalculateProcess (); 832 833 virtual lldb::ThreadSP 834 CalculateThread (); 835 836 virtual lldb::StackFrameSP 837 CalculateStackFrame (); 838 839 virtual void 840 CalculateExecutionContext (ExecutionContext &exe_ctx); 841 842 lldb::StackFrameSP 843 GetStackFrameSPForStackFramePtr (StackFrame *stack_frame_ptr); 844 845 size_t 846 GetStatus (Stream &strm, 847 uint32_t start_frame, 848 uint32_t num_frames, 849 uint32_t num_frames_with_source); 850 851 size_t 852 GetStackFrameStatus (Stream& strm, 853 uint32_t first_frame, 854 uint32_t num_frames, 855 bool show_frame_info, 856 uint32_t num_frames_with_source); 857 858 // We need a way to verify that even though we have a thread in a shared 859 // pointer that the object itself is still valid. Currently this won't be 860 // the case if DestroyThread() was called. DestroyThread is called when 861 // a thread has been removed from the Process' thread list. 862 bool 863 IsValid () const 864 { 865 return !m_destroy_called; 866 } 867 868 // When you implement this method, make sure you don't overwrite the m_actual_stop_info if it claims to be 869 // valid. The stop info may be a "checkpointed and restored" stop info, so if it is still around it is right 870 // even if you have not calculated this yourself, or if it disagrees with what you might have calculated. 871 virtual lldb::StopInfoSP 872 GetPrivateStopReason () = 0; 873 874 //---------------------------------------------------------------------- 875 // Gets the temporary resume state for a thread. 876 // 877 // This value gets set in each thread by complex debugger logic in 878 // Thread::WillResume() and an appropriate thread resume state will get 879 // set in each thread every time the process is resumed prior to calling 880 // Process::DoResume(). The lldb_private::Process subclass should adhere 881 // to the thread resume state request which will be one of: 882 // 883 // eStateRunning - thread will resume when process is resumed 884 // eStateStepping - thread should step 1 instruction and stop when process 885 // is resumed 886 // eStateSuspended - thread should not execute any instructions when 887 // process is resumed 888 //---------------------------------------------------------------------- 889 lldb::StateType 890 GetTemporaryResumeState() const 891 { 892 return m_temporary_resume_state; 893 } 894 895protected: 896 897 friend class ThreadPlan; 898 friend class ThreadList; 899 friend class ThreadEventData; 900 friend class StackFrameList; 901 friend class StackFrame; 902 903 // This is necessary to make sure thread assets get destroyed while the thread is still in good shape 904 // to call virtual thread methods. This must be called by classes that derive from Thread in their destructor. 905 virtual void DestroyThread (); 906 907 void 908 PushPlan (lldb::ThreadPlanSP &plan_sp); 909 910 void 911 PopPlan (); 912 913 void 914 DiscardPlan (); 915 916 ThreadPlan *GetPreviousPlan (ThreadPlan *plan); 917 918 typedef std::vector<lldb::ThreadPlanSP> plan_stack; 919 920 void 921 SetStopInfo (const lldb::StopInfoSP &stop_info_sp); 922 923 virtual bool 924 SaveFrameZeroState (RegisterCheckpoint &checkpoint); 925 926 virtual bool 927 RestoreSaveFrameZero (const RegisterCheckpoint &checkpoint); 928 929 // register_data_sp must be a DataSP passed to ReadAllRegisterValues. 930 bool 931 ResetFrameZeroRegisters (lldb::DataBufferSP register_data_sp); 932 933 virtual lldb_private::Unwind * 934 GetUnwinder (); 935 936 // Check to see whether the thread is still at the last breakpoint hit that stopped it. 937 virtual bool 938 IsStillAtLastBreakpointHit(); 939 940 lldb::StackFrameListSP 941 GetStackFrameList (); 942 943 struct ThreadState 944 { 945 uint32_t orig_stop_id; 946 lldb::StopInfoSP stop_info_sp; 947 RegisterCheckpoint register_backup; 948 }; 949 950 //------------------------------------------------------------------ 951 // Classes that inherit from Process can see and modify these 952 //------------------------------------------------------------------ 953 lldb::ProcessWP m_process_wp; ///< The process that owns this thread. 954 lldb::StopInfoSP m_actual_stop_info_sp; ///< The private stop reason for this thread 955 const uint32_t m_index_id; ///< A unique 1 based index assigned to each thread for easy UI/command line access. 956 lldb::RegisterContextSP m_reg_context_sp; ///< The register context for this thread's current register state. 957 lldb::StateType m_state; ///< The state of our process. 958 mutable Mutex m_state_mutex; ///< Multithreaded protection for m_state. 959 plan_stack m_plan_stack; ///< The stack of plans this thread is executing. 960 plan_stack m_completed_plan_stack; ///< Plans that have been completed by this stop. They get deleted when the thread resumes. 961 plan_stack m_discarded_plan_stack; ///< Plans that have been discarded by this stop. They get deleted when the thread resumes. 962 mutable Mutex m_frame_mutex; ///< Multithreaded protection for m_state. 963 lldb::StackFrameListSP m_curr_frames_sp; ///< The stack frames that get lazily populated after a thread stops. 964 lldb::StackFrameListSP m_prev_frames_sp; ///< The previous stack frames from the last time this thread stopped. 965 int m_resume_signal; ///< The signal that should be used when continuing this thread. 966 lldb::StateType m_resume_state; ///< This state is used to force a thread to be suspended from outside the ThreadPlan logic. 967 lldb::StateType m_temporary_resume_state; ///< This state records what the thread was told to do by the thread plan logic for the current resume. 968 /// It gets set in Thread::WillResume. 969 std::unique_ptr<lldb_private::Unwind> m_unwinder_ap; 970 bool m_destroy_called; // This is used internally to make sure derived Thread classes call DestroyThread. 971 uint32_t m_thread_stop_reason_stop_id; // This is the stop id for which the StopInfo is valid. Can use this so you know that 972 // the thread's m_actual_stop_info_sp is current and you don't have to fetch it again 973 974private: 975 //------------------------------------------------------------------ 976 // For Thread only 977 //------------------------------------------------------------------ 978 979 DISALLOW_COPY_AND_ASSIGN (Thread); 980 981}; 982 983} // namespace lldb_private 984 985#endif // liblldb_Thread_h_ 986