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