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