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