Thread.h revision 52e4391bf4239f770f856392869f652f5417f489
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 "ShouldResume" and 259 // "WillResume" in case a thread needs to change its state before the 260 // ThreadList polls all the threads to figure out which ones actually 261 // will get to run and how. 262 void 263 SetupForResume (); 264 265 // Do not override this function, it is for thread plan logic only 266 bool 267 ShouldResume (lldb::StateType resume_state); 268 269 // Override this to do platform specific tasks before resume. 270 virtual void 271 WillResume (lldb::StateType resume_state) 272 { 273 } 274 275 // This clears generic thread state after a resume. If you subclass this, 276 // be sure to call it. 277 virtual void 278 DidResume (); 279 280 // This notifies the thread when a private stop occurs. 281 virtual void 282 DidStop (); 283 284 virtual void 285 RefreshStateAfterStop() = 0; 286 287 void 288 WillStop (); 289 290 bool 291 ShouldStop (Event *event_ptr); 292 293 Vote 294 ShouldReportStop (Event *event_ptr); 295 296 Vote 297 ShouldReportRun (Event *event_ptr); 298 299 void 300 Flush (); 301 302 // Return whether this thread matches the specification in ThreadSpec. This is a virtual 303 // method because at some point we may extend the thread spec with a platform specific 304 // dictionary of attributes, which then only the platform specific Thread implementation 305 // would know how to match. For now, this just calls through to the ThreadSpec's 306 // ThreadPassesBasicTests method. 307 virtual bool 308 MatchesSpec (const ThreadSpec *spec); 309 310 lldb::StopInfoSP 311 GetStopInfo (); 312 313 lldb::StopReason 314 GetStopReason(); 315 316 // This sets the stop reason to a "blank" stop reason, so you can call functions on the thread 317 // without having the called function run with whatever stop reason you stopped with. 318 void 319 SetStopInfoToNothing(); 320 321 bool 322 ThreadStoppedForAReason (); 323 324 static const char * 325 RunModeAsCString (lldb::RunMode mode); 326 327 static const char * 328 StopReasonAsCString (lldb::StopReason reason); 329 330 virtual const char * 331 GetInfo () 332 { 333 return NULL; 334 } 335 336 virtual const char * 337 GetName () 338 { 339 return NULL; 340 } 341 342 virtual const char * 343 GetQueueName () 344 { 345 return NULL; 346 } 347 348 virtual uint32_t 349 GetStackFrameCount() 350 { 351 return GetStackFrameList()->GetNumFrames(); 352 } 353 354 virtual lldb::StackFrameSP 355 GetStackFrameAtIndex (uint32_t idx) 356 { 357 return GetStackFrameList()->GetFrameAtIndex(idx); 358 } 359 360 virtual lldb::StackFrameSP 361 GetFrameWithConcreteFrameIndex (uint32_t unwind_idx); 362 363 bool 364 DecrementCurrentInlinedDepth() 365 { 366 return GetStackFrameList()->DecrementCurrentInlinedDepth(); 367 } 368 369 uint32_t 370 GetCurrentInlinedDepth() 371 { 372 return GetStackFrameList()->GetCurrentInlinedDepth(); 373 } 374 375 Error 376 ReturnFromFrameWithIndex (uint32_t frame_idx, lldb::ValueObjectSP return_value_sp, bool broadcast = false); 377 378 Error 379 ReturnFromFrame (lldb::StackFrameSP frame_sp, lldb::ValueObjectSP return_value_sp, bool broadcast = false); 380 381 virtual lldb::StackFrameSP 382 GetFrameWithStackID (const StackID &stack_id) 383 { 384 return GetStackFrameList()->GetFrameWithStackID (stack_id); 385 } 386 387 uint32_t 388 GetSelectedFrameIndex () 389 { 390 return GetStackFrameList()->GetSelectedFrameIndex(); 391 } 392 393 lldb::StackFrameSP 394 GetSelectedFrame () 395 { 396 lldb::StackFrameListSP stack_frame_list_sp(GetStackFrameList()); 397 return stack_frame_list_sp->GetFrameAtIndex (stack_frame_list_sp->GetSelectedFrameIndex()); 398 } 399 400 uint32_t 401 SetSelectedFrame (lldb_private::StackFrame *frame, bool broadcast = false); 402 403 404 bool 405 SetSelectedFrameByIndex (uint32_t frame_idx, bool broadcast = false); 406 407 bool 408 SetSelectedFrameByIndexNoisily (uint32_t frame_idx, Stream &output_stream); 409 410 void 411 SetDefaultFileAndLineToSelectedFrame() 412 { 413 GetStackFrameList()->SetDefaultFileAndLineToSelectedFrame(); 414 } 415 416 virtual lldb::RegisterContextSP 417 GetRegisterContext () = 0; 418 419 virtual lldb::RegisterContextSP 420 CreateRegisterContextForFrame (StackFrame *frame) = 0; 421 422 virtual void 423 ClearStackFrames (); 424 425 virtual bool 426 SetBackingThread (const lldb::ThreadSP &thread_sp) 427 { 428 return false; 429 } 430 431 virtual lldb::ThreadSP 432 GetBackingThread () const 433 { 434 return lldb::ThreadSP(); 435 } 436 437 virtual void 438 ClearBackingThread () 439 { 440 // Subclasses can use this function if a thread is actually backed by 441 // another thread. This is currently used for the OperatingSystem plug-ins 442 // where they might have a thread that is in memory, yet its registers 443 // are available through the lldb_private::Thread subclass for the current 444 // lldb_private::Process class. Since each time the process stops the backing 445 // threads for memory threads can change, we need a way to clear the backing 446 // thread for all memory threads each time we stop. 447 } 448 449 void 450 DumpUsingSettingsFormat (Stream &strm, uint32_t frame_idx); 451 452 //------------------------------------------------------------------ 453 // Thread Plan Providers: 454 // This section provides the basic thread plans that the Process control 455 // machinery uses to run the target. ThreadPlan.h provides more details on 456 // how this mechanism works. 457 // The thread provides accessors to a set of plans that perform basic operations. 458 // The idea is that particular Platform plugins can override these methods to 459 // provide the implementation of these basic operations appropriate to their 460 // environment. 461 //------------------------------------------------------------------ 462 463 //------------------------------------------------------------------ 464 /// Queues the base plan for a thread. 465 /// The version returned by Process does some things that are useful, 466 /// like handle breakpoints and signals, so if you return a plugin specific 467 /// one you probably want to call through to the Process one for anything 468 /// your plugin doesn't explicitly handle. 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 QueueFundamentalPlan (bool abort_other_plans); 479 480 //------------------------------------------------------------------ 481 /// Queues the plan used to step over a breakpoint at the current PC of \a thread. 482 /// The default version returned by Process handles trap based breakpoints, and 483 /// will disable the breakpoint, single step over it, then re-enable it. 484 /// 485 /// @param[in] abort_other_plans 486 /// \b true if we discard the currently queued plans and replace them with this one. 487 /// Otherwise this plan will go on the end of the plan stack. 488 /// 489 /// @return 490 /// A pointer to the newly queued thread plan, or NULL if the plan could not be queued. 491 //------------------------------------------------------------------ 492 virtual ThreadPlan * 493 QueueThreadPlanForStepOverBreakpointPlan (bool abort_other_plans); 494 495 //------------------------------------------------------------------ 496 /// Queues the plan used to step one instruction from the current PC of \a thread. 497 /// 498 /// @param[in] step_over 499 /// \b true if we step over calls to functions, false if we step in. 500 /// 501 /// @param[in] abort_other_plans 502 /// \b true if we discard the currently queued plans and replace them with this one. 503 /// Otherwise this plan will go on the end of the plan stack. 504 /// 505 /// @param[in] stop_other_threads 506 /// \b true if we will stop other threads while we single step this one. 507 /// 508 /// @return 509 /// A pointer to the newly queued thread plan, or NULL if the plan could not be queued. 510 //------------------------------------------------------------------ 511 virtual ThreadPlan * 512 QueueThreadPlanForStepSingleInstruction (bool step_over, 513 bool abort_other_plans, 514 bool stop_other_threads); 515 516 //------------------------------------------------------------------ 517 /// Queues the plan used to step through an address range, stepping over 518 /// function calls. 519 /// 520 /// @param[in] abort_other_plans 521 /// \b true if we discard the currently queued plans and replace them with this one. 522 /// Otherwise this plan will go on the end of the plan stack. 523 /// 524 /// @param[in] type 525 /// Type of step to do, only eStepTypeInto and eStepTypeOver are supported by this plan. 526 /// 527 /// @param[in] range 528 /// The address range to step through. 529 /// 530 /// @param[in] addr_context 531 /// When dealing with stepping through inlined functions the current PC is not enough information to know 532 /// what "step" means. For instance a series of nested inline functions might start at the same address. 533 // The \a addr_context provides the current symbol context the step 534 /// is supposed to be out of. 535 // FIXME: Currently unused. 536 /// 537 /// @param[in] stop_other_threads 538 /// \b true if we will stop other threads while we single step this one. 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 QueueThreadPlanForStepOverRange (bool abort_other_plans, 545 const AddressRange &range, 546 const SymbolContext &addr_context, 547 lldb::RunMode stop_other_threads); 548 549 //------------------------------------------------------------------ 550 /// Queues the plan used to step through an address range, stepping into functions. 551 /// 552 /// @param[in] abort_other_plans 553 /// \b true if we discard the currently queued plans and replace them with this one. 554 /// Otherwise this plan will go on the end of the plan stack. 555 /// 556 /// @param[in] type 557 /// Type of step to do, only eStepTypeInto and eStepTypeOver are supported by this plan. 558 /// 559 /// @param[in] range 560 /// The address range to step through. 561 /// 562 /// @param[in] addr_context 563 /// When dealing with stepping through inlined functions the current PC is not enough information to know 564 /// what "step" means. For instance a series of nested inline functions might start at the same address. 565 // The \a addr_context provides the current symbol context the step 566 /// is supposed to be out of. 567 // FIXME: Currently unused. 568 /// 569 /// @param[in] step_in_target 570 /// Name if function we are trying to step into. We will step out if we don't land in that function. 571 /// 572 /// @param[in] stop_other_threads 573 /// \b true if we will stop other threads while we single step this one. 574 /// 575 /// @param[in] avoid_code_without_debug_info 576 /// If \b true we will step out if we step into code with no debug info. 577 /// 578 /// @return 579 /// A pointer to the newly queued thread plan, or NULL if the plan could not be queued. 580 //------------------------------------------------------------------ 581 virtual ThreadPlan * 582 QueueThreadPlanForStepInRange (bool abort_other_plans, 583 const AddressRange &range, 584 const SymbolContext &addr_context, 585 const char *step_in_target, 586 lldb::RunMode stop_other_threads, 587 bool avoid_code_without_debug_info); 588 589 //------------------------------------------------------------------ 590 /// Queue the plan used to step out of the function at the current PC of 591 /// \a thread. 592 /// 593 /// @param[in] abort_other_plans 594 /// \b true if we discard the currently queued plans and replace them with this one. 595 /// Otherwise this plan will go on the end of the plan stack. 596 /// 597 /// @param[in] addr_context 598 /// When dealing with stepping through inlined functions the current PC is not enough information to know 599 /// what "step" means. For instance a series of nested inline functions might start at the same address. 600 // The \a addr_context provides the current symbol context the step 601 /// is supposed to be out of. 602 // FIXME: Currently unused. 603 /// 604 /// @param[in] first_insn 605 /// \b true if this is the first instruction of a function. 606 /// 607 /// @param[in] stop_other_threads 608 /// \b true if we will stop other threads while we single step this one. 609 /// 610 /// @param[in] stop_vote 611 /// @param[in] run_vote 612 /// See standard meanings for the stop & run votes in ThreadPlan.h. 613 /// 614 /// @return 615 /// A pointer to the newly queued thread plan, or NULL if the plan could not be queued. 616 //------------------------------------------------------------------ 617 virtual ThreadPlan * 618 QueueThreadPlanForStepOut (bool abort_other_plans, 619 SymbolContext *addr_context, 620 bool first_insn, 621 bool stop_other_threads, 622 Vote stop_vote, // = eVoteYes, 623 Vote run_vote, // = eVoteNoOpinion); 624 uint32_t frame_idx); 625 626 //------------------------------------------------------------------ 627 /// Gets the plan used to step through the code that steps from a function 628 /// call site at the current PC into the actual function call. 629 /// 630 /// 631 /// @param[in] return_stack_id 632 /// The stack id that we will return to (by setting backstop breakpoints on the return 633 /// address to that frame) if we fail to step through. 634 /// 635 /// @param[in] abort_other_plans 636 /// \b true if we discard the currently queued plans and replace them with this one. 637 /// Otherwise this plan will go on the end of the plan stack. 638 /// 639 /// @param[in] stop_other_threads 640 /// \b true if we will stop other threads while we single step this one. 641 /// 642 /// @return 643 /// A pointer to the newly queued thread plan, or NULL if the plan could not be queued. 644 //------------------------------------------------------------------ 645 virtual ThreadPlan * 646 QueueThreadPlanForStepThrough (StackID &return_stack_id, 647 bool abort_other_plans, 648 bool stop_other_threads); 649 650 //------------------------------------------------------------------ 651 /// Gets the plan used to continue from the current PC. 652 /// This is a simple plan, mostly useful as a backstop when you are continuing 653 /// for some particular purpose. 654 /// 655 /// @param[in] abort_other_plans 656 /// \b true if we discard the currently queued plans and replace them with this one. 657 /// Otherwise this plan will go on the end of the plan stack. 658 /// 659 /// @param[in] target_addr 660 /// The address to which we're running. 661 /// 662 /// @param[in] stop_other_threads 663 /// \b true if we will stop other threads while we single step this one. 664 /// 665 /// @return 666 /// A pointer to the newly queued thread plan, or NULL if the plan could not be queued. 667 //------------------------------------------------------------------ 668 virtual ThreadPlan * 669 QueueThreadPlanForRunToAddress (bool abort_other_plans, 670 Address &target_addr, 671 bool stop_other_threads); 672 673 virtual ThreadPlan * 674 QueueThreadPlanForStepUntil (bool abort_other_plans, 675 lldb::addr_t *address_list, 676 size_t num_addresses, 677 bool stop_others, 678 uint32_t frame_idx); 679 680 virtual ThreadPlan * 681 QueueThreadPlanForCallFunction (bool abort_other_plans, 682 Address& function, 683 lldb::addr_t arg, 684 bool stop_other_threads, 685 bool unwind_on_error = false, 686 bool ignore_breakpoints = true); 687 688 //------------------------------------------------------------------ 689 // Thread Plan accessors: 690 //------------------------------------------------------------------ 691 692 //------------------------------------------------------------------ 693 /// Gets the plan which will execute next on the plan stack. 694 /// 695 /// @return 696 /// A pointer to the next executed plan. 697 //------------------------------------------------------------------ 698 ThreadPlan * 699 GetCurrentPlan (); 700 701 //------------------------------------------------------------------ 702 /// Unwinds the thread stack for the innermost expression plan currently 703 /// on the thread plan stack. 704 /// 705 /// @return 706 /// An error if the thread plan could not be unwound. 707 //------------------------------------------------------------------ 708 709 Error 710 UnwindInnermostExpression(); 711 712private: 713 bool 714 PlanIsBasePlan (ThreadPlan *plan_ptr); 715 716 void 717 BroadcastSelectedFrameChange(StackID &new_frame_id); 718 719public: 720 721 //------------------------------------------------------------------ 722 /// Gets the outer-most plan that was popped off the plan stack in the 723 /// most recent stop. Useful for printing the stop reason accurately. 724 /// 725 /// @return 726 /// A pointer to the last completed plan. 727 //------------------------------------------------------------------ 728 lldb::ThreadPlanSP 729 GetCompletedPlan (); 730 731 //------------------------------------------------------------------ 732 /// Gets the outer-most return value from the completed plans 733 /// 734 /// @return 735 /// A ValueObjectSP, either empty if there is no return value, 736 /// or containing the return value. 737 //------------------------------------------------------------------ 738 lldb::ValueObjectSP 739 GetReturnValueObject (); 740 741 //------------------------------------------------------------------ 742 /// Checks whether the given plan is in the completed plans for this 743 /// stop. 744 /// 745 /// @param[in] plan 746 /// Pointer to the plan you're checking. 747 /// 748 /// @return 749 /// Returns true if the input plan is in the completed plan stack, 750 /// false otherwise. 751 //------------------------------------------------------------------ 752 bool 753 IsThreadPlanDone (ThreadPlan *plan); 754 755 //------------------------------------------------------------------ 756 /// Checks whether the given plan is in the discarded plans for this 757 /// stop. 758 /// 759 /// @param[in] plan 760 /// Pointer to the plan you're checking. 761 /// 762 /// @return 763 /// Returns true if the input plan is in the discarded plan stack, 764 /// false otherwise. 765 //------------------------------------------------------------------ 766 bool 767 WasThreadPlanDiscarded (ThreadPlan *plan); 768 769 //------------------------------------------------------------------ 770 /// Queues a generic thread plan. 771 /// 772 /// @param[in] plan_sp 773 /// The plan to queue. 774 /// 775 /// @param[in] abort_other_plans 776 /// \b true if we discard the currently queued plans and replace them with this one. 777 /// Otherwise this plan will go on the end of the plan stack. 778 /// 779 /// @return 780 /// A pointer to the last completed plan. 781 //------------------------------------------------------------------ 782 void 783 QueueThreadPlan (lldb::ThreadPlanSP &plan_sp, bool abort_other_plans); 784 785 786 //------------------------------------------------------------------ 787 /// Discards the plans queued on the plan stack of the current thread. This is 788 /// arbitrated by the "Master" ThreadPlans, using the "OkayToDiscard" call. 789 // But if \a force is true, all thread plans are discarded. 790 //------------------------------------------------------------------ 791 void 792 DiscardThreadPlans (bool force); 793 794 //------------------------------------------------------------------ 795 /// Discards the plans queued on the plan stack of the current thread up to and 796 /// including up_to_plan_sp. 797 // 798 // @param[in] up_to_plan_sp 799 // Discard all plans up to and including this one. 800 //------------------------------------------------------------------ 801 void 802 DiscardThreadPlansUpToPlan (lldb::ThreadPlanSP &up_to_plan_sp); 803 804 void 805 DiscardThreadPlansUpToPlan (ThreadPlan *up_to_plan_ptr); 806 807 //------------------------------------------------------------------ 808 /// Prints the current plan stack. 809 /// 810 /// @param[in] s 811 /// The stream to which to dump the plan stack info. 812 /// 813 //------------------------------------------------------------------ 814 void 815 DumpThreadPlans (Stream *s) const; 816 817 virtual bool 818 CheckpointThreadState (ThreadStateCheckpoint &saved_state); 819 820 virtual bool 821 RestoreRegisterStateFromCheckpoint (ThreadStateCheckpoint &saved_state); 822 823 virtual bool 824 RestoreThreadStateFromCheckpoint (ThreadStateCheckpoint &saved_state); 825 826 void 827 EnableTracer (bool value, bool single_step); 828 829 void 830 SetTracer (lldb::ThreadPlanTracerSP &tracer_sp); 831 832 //------------------------------------------------------------------ 833 // Get the thread index ID. The index ID that is guaranteed to not 834 // be re-used by a process. They start at 1 and increase with each 835 // new thread. This allows easy command line access by a unique ID 836 // that is easier to type than the actual system thread ID. 837 //------------------------------------------------------------------ 838 uint32_t 839 GetIndexID () const; 840 841 842 //------------------------------------------------------------------ 843 // The API ID is often the same as the Thread::GetID(), but not in 844 // all cases. Thread::GetID() is the user visible thread ID that 845 // clients would want to see. The API thread ID is the thread ID 846 // that is used when sending data to/from the debugging protocol. 847 //------------------------------------------------------------------ 848 virtual lldb::user_id_t 849 GetProtocolID () const 850 { 851 return m_protocol_tid.GetID(); 852 } 853 854 virtual void 855 SetProtocolID (lldb::user_id_t api_tid) 856 { 857 return m_protocol_tid.SetID(api_tid); 858 } 859 860 //------------------------------------------------------------------ 861 // lldb::ExecutionContextScope pure virtual functions 862 //------------------------------------------------------------------ 863 virtual lldb::TargetSP 864 CalculateTarget (); 865 866 virtual lldb::ProcessSP 867 CalculateProcess (); 868 869 virtual lldb::ThreadSP 870 CalculateThread (); 871 872 virtual lldb::StackFrameSP 873 CalculateStackFrame (); 874 875 virtual void 876 CalculateExecutionContext (ExecutionContext &exe_ctx); 877 878 lldb::StackFrameSP 879 GetStackFrameSPForStackFramePtr (StackFrame *stack_frame_ptr); 880 881 size_t 882 GetStatus (Stream &strm, 883 uint32_t start_frame, 884 uint32_t num_frames, 885 uint32_t num_frames_with_source); 886 887 size_t 888 GetStackFrameStatus (Stream& strm, 889 uint32_t first_frame, 890 uint32_t num_frames, 891 bool show_frame_info, 892 uint32_t num_frames_with_source); 893 894 // We need a way to verify that even though we have a thread in a shared 895 // pointer that the object itself is still valid. Currently this won't be 896 // the case if DestroyThread() was called. DestroyThread is called when 897 // a thread has been removed from the Process' thread list. 898 bool 899 IsValid () const 900 { 901 return !m_destroy_called; 902 } 903 904 // When you implement this method, make sure you don't overwrite the m_actual_stop_info if it claims to be 905 // valid. The stop info may be a "checkpointed and restored" stop info, so if it is still around it is right 906 // even if you have not calculated this yourself, or if it disagrees with what you might have calculated. 907 virtual lldb::StopInfoSP 908 GetPrivateStopReason () = 0; 909 910 //---------------------------------------------------------------------- 911 // Gets the temporary resume state for a thread. 912 // 913 // This value gets set in each thread by complex debugger logic in 914 // Thread::ShouldResume() and an appropriate thread resume state will get 915 // set in each thread every time the process is resumed prior to calling 916 // Process::DoResume(). The lldb_private::Process subclass should adhere 917 // to the thread resume state request which will be one of: 918 // 919 // eStateRunning - thread will resume when process is resumed 920 // eStateStepping - thread should step 1 instruction and stop when process 921 // is resumed 922 // eStateSuspended - thread should not execute any instructions when 923 // process is resumed 924 //---------------------------------------------------------------------- 925 lldb::StateType 926 GetTemporaryResumeState() const 927 { 928 return m_temporary_resume_state; 929 } 930 931 void 932 SetStopInfo (const lldb::StopInfoSP &stop_info_sp); 933 934 void 935 SetShouldReportStop (Vote vote); 936 937protected: 938 939 friend class ThreadPlan; 940 friend class ThreadList; 941 friend class ThreadEventData; 942 friend class StackFrameList; 943 friend class StackFrame; 944 friend class OperatingSystem; 945 946 // This is necessary to make sure thread assets get destroyed while the thread is still in good shape 947 // to call virtual thread methods. This must be called by classes that derive from Thread in their destructor. 948 virtual void DestroyThread (); 949 950 void 951 PushPlan (lldb::ThreadPlanSP &plan_sp); 952 953 void 954 PopPlan (); 955 956 void 957 DiscardPlan (); 958 959 ThreadPlan *GetPreviousPlan (ThreadPlan *plan); 960 961 typedef std::vector<lldb::ThreadPlanSP> plan_stack; 962 963 virtual bool 964 SaveFrameZeroState (RegisterCheckpoint &checkpoint); 965 966 virtual bool 967 RestoreSaveFrameZero (const RegisterCheckpoint &checkpoint); 968 969 // register_data_sp must be a DataSP passed to ReadAllRegisterValues. 970 bool 971 ResetFrameZeroRegisters (lldb::DataBufferSP register_data_sp); 972 973 virtual lldb_private::Unwind * 974 GetUnwinder (); 975 976 // Check to see whether the thread is still at the last breakpoint hit that stopped it. 977 virtual bool 978 IsStillAtLastBreakpointHit(); 979 980 // Some threads are threads that are made up by OperatingSystem plugins that 981 // are threads that exist and are context switched out into memory. The 982 // OperatingSystem plug-in need a ways to know if a thread is "real" or made 983 // up. 984 virtual bool 985 IsOperatingSystemPluginThread () const 986 { 987 return false; 988 } 989 990 991 lldb::StackFrameListSP 992 GetStackFrameList (); 993 994 struct ThreadState 995 { 996 uint32_t orig_stop_id; 997 lldb::StopInfoSP stop_info_sp; 998 RegisterCheckpoint register_backup; 999 }; 1000 1001 //------------------------------------------------------------------ 1002 // Classes that inherit from Process can see and modify these 1003 //------------------------------------------------------------------ 1004 lldb::ProcessWP m_process_wp; ///< The process that owns this thread. 1005 lldb::StopInfoSP m_actual_stop_info_sp; ///< The private stop reason for this thread 1006 const uint32_t m_index_id; ///< A unique 1 based index assigned to each thread for easy UI/command line access. 1007 UserID m_protocol_tid; ///< The thread ID used in the system level debugging or protocol functions calls. This is usually the same as the Thread::GetID(), but not always. 1008 lldb::RegisterContextSP m_reg_context_sp; ///< The register context for this thread's current register state. 1009 lldb::StateType m_state; ///< The state of our process. 1010 mutable Mutex m_state_mutex; ///< Multithreaded protection for m_state. 1011 plan_stack m_plan_stack; ///< The stack of plans this thread is executing. 1012 plan_stack m_completed_plan_stack; ///< Plans that have been completed by this stop. They get deleted when the thread resumes. 1013 plan_stack m_discarded_plan_stack; ///< Plans that have been discarded by this stop. They get deleted when the thread resumes. 1014 mutable Mutex m_frame_mutex; ///< Multithreaded protection for m_state. 1015 lldb::StackFrameListSP m_curr_frames_sp; ///< The stack frames that get lazily populated after a thread stops. 1016 lldb::StackFrameListSP m_prev_frames_sp; ///< The previous stack frames from the last time this thread stopped. 1017 int m_resume_signal; ///< The signal that should be used when continuing this thread. 1018 lldb::StateType m_resume_state; ///< This state is used to force a thread to be suspended from outside the ThreadPlan logic. 1019 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. 1020 /// It gets set in Thread::ShoudResume. 1021 std::unique_ptr<lldb_private::Unwind> m_unwinder_ap; 1022 bool m_destroy_called; // This is used internally to make sure derived Thread classes call DestroyThread. 1023 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 1024 // the thread's m_actual_stop_info_sp is current and you don't have to fetch it again 1025 LazyBool m_override_should_notify; 1026private: 1027 //------------------------------------------------------------------ 1028 // For Thread only 1029 //------------------------------------------------------------------ 1030 1031 DISALLOW_COPY_AND_ASSIGN (Thread); 1032 1033}; 1034 1035} // namespace lldb_private 1036 1037#endif // liblldb_Thread_h_ 1038