1 //===-- Thread.h ------------------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef liblldb_Thread_h_
11 #define liblldb_Thread_h_
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/RegisterCheckpoint.h"
21 #include "lldb/Target/StackFrameList.h"
23 #define LLDB_THREAD_MAX_STOP_EXC_DATA 8
25 namespace lldb_private {
27 class ThreadProperties : public Properties
30 ThreadProperties(bool is_global);
35 //------------------------------------------------------------------
36 /// The regular expression returned determines symbols that this
37 /// thread won't stop in during "step-in" operations.
40 /// A pointer to a regular expression to compare against symbols,
41 /// or NULL if all symbols are allowed.
43 //------------------------------------------------------------------
44 const RegularExpression *
45 GetSymbolsToAvoidRegexp();
48 GetLibrariesToAvoid() const;
51 GetTraceEnabledState() const;
54 typedef std::shared_ptr<ThreadProperties> ThreadPropertiesSP;
57 public std::enable_shared_from_this<Thread>,
58 public ThreadProperties,
60 public ExecutionContextScope,
64 //------------------------------------------------------------------
65 /// Broadcaster event bits definitions.
66 //------------------------------------------------------------------
69 eBroadcastBitStackChanged = (1 << 0),
70 eBroadcastBitThreadSuspended = (1 << 1),
71 eBroadcastBitThreadResumed = (1 << 2),
72 eBroadcastBitSelectedFrameChanged = (1 << 3),
73 eBroadcastBitThreadSelected = (1 << 4)
76 static ConstString &GetStaticBroadcasterClass ();
78 virtual ConstString &GetBroadcasterClass() const
80 return GetStaticBroadcasterClass();
83 class ThreadEventData :
87 ThreadEventData (const lldb::ThreadSP thread_sp);
89 ThreadEventData (const lldb::ThreadSP thread_sp, const StackID &stack_id);
93 virtual ~ThreadEventData();
95 static const ConstString &
98 virtual const ConstString &
101 return ThreadEventData::GetFlavorString ();
105 Dump (Stream *s) const;
107 static const ThreadEventData *
108 GetEventDataFromEvent (const Event *event_ptr);
110 static lldb::ThreadSP
111 GetThreadFromEvent (const Event *event_ptr);
114 GetStackIDFromEvent (const Event *event_ptr);
116 static lldb::StackFrameSP
117 GetStackFrameFromEvent (const Event *event_ptr);
132 lldb::ThreadSP m_thread_sp;
134 DISALLOW_COPY_AND_ASSIGN (ThreadEventData);
138 struct ThreadStateCheckpoint
140 uint32_t orig_stop_id; // Dunno if I need this yet but it is an interesting bit of data.
141 lldb::StopInfoSP stop_info_sp; // You have to restore the stop info or you might continue with the wrong signals.
142 lldb::RegisterCheckpointSP register_backup_sp; // You need to restore the registers, of course...
143 uint32_t current_inlined_depth;
144 lldb::addr_t current_inlined_pc;
148 SettingsInitialize ();
151 SettingsTerminate ();
153 static const ThreadPropertiesSP &
154 GetGlobalProperties();
156 Thread (Process &process, lldb::tid_t tid);
162 return m_process_wp.lock();
166 GetResumeSignal () const
168 return m_resume_signal;
172 SetResumeSignal (int signal)
174 m_resume_signal = signal;
181 SetState (lldb::StateType state);
184 GetResumeState () const
186 return m_resume_state;
190 SetResumeState (lldb::StateType state)
192 m_resume_state = state;
195 // This function is called on all the threads before "ShouldResume" and
196 // "WillResume" in case a thread needs to change its state before the
197 // ThreadList polls all the threads to figure out which ones actually
198 // will get to run and how.
202 // Do not override this function, it is for thread plan logic only
204 ShouldResume (lldb::StateType resume_state);
206 // Override this to do platform specific tasks before resume.
208 WillResume (lldb::StateType resume_state)
212 // This clears generic thread state after a resume. If you subclass this,
213 // be sure to call it.
217 // This notifies the thread when a private stop occurs.
222 RefreshStateAfterStop() = 0;
228 ShouldStop (Event *event_ptr);
231 ShouldReportStop (Event *event_ptr);
234 ShouldReportRun (Event *event_ptr);
239 // Return whether this thread matches the specification in ThreadSpec. This is a virtual
240 // method because at some point we may extend the thread spec with a platform specific
241 // dictionary of attributes, which then only the platform specific Thread implementation
242 // would know how to match. For now, this just calls through to the ThreadSpec's
243 // ThreadPassesBasicTests method.
245 MatchesSpec (const ThreadSpec *spec);
253 // This sets the stop reason to a "blank" stop reason, so you can call functions on the thread
254 // without having the called function run with whatever stop reason you stopped with.
256 SetStopInfoToNothing();
259 ThreadStoppedForAReason ();
262 RunModeAsCString (lldb::RunMode mode);
265 StopReasonAsCString (lldb::StopReason reason);
280 SetName (const char *name)
284 virtual lldb::queue_id_t
287 return LLDB_INVALID_QUEUE_ID;
291 SetQueueID (lldb::queue_id_t new_val)
302 SetQueueName (const char *name)
309 return GetStackFrameList()->GetNumFrames();
312 virtual lldb::StackFrameSP
313 GetStackFrameAtIndex (uint32_t idx)
315 return GetStackFrameList()->GetFrameAtIndex(idx);
318 virtual lldb::StackFrameSP
319 GetFrameWithConcreteFrameIndex (uint32_t unwind_idx);
322 DecrementCurrentInlinedDepth()
324 return GetStackFrameList()->DecrementCurrentInlinedDepth();
328 GetCurrentInlinedDepth()
330 return GetStackFrameList()->GetCurrentInlinedDepth();
334 ReturnFromFrameWithIndex (uint32_t frame_idx, lldb::ValueObjectSP return_value_sp, bool broadcast = false);
337 ReturnFromFrame (lldb::StackFrameSP frame_sp, lldb::ValueObjectSP return_value_sp, bool broadcast = false);
340 JumpToLine (const FileSpec &file, uint32_t line, bool can_leave_function, std::string *warnings = NULL);
342 virtual lldb::StackFrameSP
343 GetFrameWithStackID (const StackID &stack_id)
345 if (stack_id.IsValid())
346 return GetStackFrameList()->GetFrameWithStackID (stack_id);
347 return lldb::StackFrameSP();
351 GetSelectedFrameIndex ()
353 return GetStackFrameList()->GetSelectedFrameIndex();
359 lldb::StackFrameListSP stack_frame_list_sp(GetStackFrameList());
360 return stack_frame_list_sp->GetFrameAtIndex (stack_frame_list_sp->GetSelectedFrameIndex());
364 SetSelectedFrame (lldb_private::StackFrame *frame, bool broadcast = false);
368 SetSelectedFrameByIndex (uint32_t frame_idx, bool broadcast = false);
371 SetSelectedFrameByIndexNoisily (uint32_t frame_idx, Stream &output_stream);
374 SetDefaultFileAndLineToSelectedFrame()
376 GetStackFrameList()->SetDefaultFileAndLineToSelectedFrame();
379 virtual lldb::RegisterContextSP
380 GetRegisterContext () = 0;
382 virtual lldb::RegisterContextSP
383 CreateRegisterContextForFrame (StackFrame *frame) = 0;
389 SetBackingThread (const lldb::ThreadSP &thread_sp)
394 virtual lldb::ThreadSP
395 GetBackingThread () const
397 return lldb::ThreadSP();
401 ClearBackingThread ()
403 // Subclasses can use this function if a thread is actually backed by
404 // another thread. This is currently used for the OperatingSystem plug-ins
405 // where they might have a thread that is in memory, yet its registers
406 // are available through the lldb_private::Thread subclass for the current
407 // lldb_private::Process class. Since each time the process stops the backing
408 // threads for memory threads can change, we need a way to clear the backing
409 // thread for all memory threads each time we stop.
413 DumpUsingSettingsFormat (Stream &strm, uint32_t frame_idx);
415 //------------------------------------------------------------------
416 /// Default implementation for stepping into.
418 /// This function is designed to be used by commands where the
419 /// process is publicly stopped.
421 /// @param[in] source_step
422 /// If true and the frame has debug info, then do a source level
423 /// step in, else do a single instruction step in.
425 /// @param[in] avoid_code_without_debug_info
426 /// If \a true, then avoid stepping into code that doesn't have
427 /// debug info, else step into any code regardless of wether it
431 /// An error that describes anything that went wrong
432 //------------------------------------------------------------------
434 StepIn (bool source_step,
435 bool avoid_code_without_debug_info);
437 //------------------------------------------------------------------
438 /// Default implementation for stepping over.
440 /// This function is designed to be used by commands where the
441 /// process is publicly stopped.
443 /// @param[in] source_step
444 /// If true and the frame has debug info, then do a source level
445 /// step over, else do a single instruction step over.
448 /// An error that describes anything that went wrong
449 //------------------------------------------------------------------
451 StepOver (bool source_step);
453 //------------------------------------------------------------------
454 /// Default implementation for stepping out.
456 /// This function is designed to be used by commands where the
457 /// process is publicly stopped.
460 /// An error that describes anything that went wrong
461 //------------------------------------------------------------------
464 //------------------------------------------------------------------
465 /// Retrieves the per-thread data area.
466 /// Most OSs maintain a per-thread pointer (e.g. the FS register on
467 /// x64), which we return the value of here.
470 /// LLDB_INVALID_ADDRESS if not supported, otherwise the thread
472 //------------------------------------------------------------------
476 //------------------------------------------------------------------
477 /// Retrieves the per-module TLS block for a thread.
479 /// @param[in] module
480 /// The module to query TLS data for.
483 /// If the thread has TLS data allocated for the
484 /// module, the address of the TLS block. Otherwise
485 /// LLDB_INVALID_ADDRESS is returned.
486 //------------------------------------------------------------------
488 GetThreadLocalData (const lldb::ModuleSP module);
491 //------------------------------------------------------------------
492 // Thread Plan Providers:
493 // This section provides the basic thread plans that the Process control
494 // machinery uses to run the target. ThreadPlan.h provides more details on
495 // how this mechanism works.
496 // The thread provides accessors to a set of plans that perform basic operations.
497 // The idea is that particular Platform plugins can override these methods to
498 // provide the implementation of these basic operations appropriate to their
501 // NB: All the QueueThreadPlanXXX providers return Shared Pointers to
502 // Thread plans. This is useful so that you can modify the plans after
503 // creation in ways specific to that plan type. Also, it is often necessary for
504 // ThreadPlans that utilize other ThreadPlans to implement their task to keep a shared
505 // pointer to the sub-plan.
506 // But besides that, the shared pointers should only be held onto by entities who live no longer
507 // than the thread containing the ThreadPlan.
508 // FIXME: If this becomes a problem, we can make a version that just returns a pointer,
509 // which it is clearly unsafe to hold onto, and a shared pointer version, and only allow
510 // ThreadPlan and Co. to use the latter. That is made more annoying to do because there's
511 // no elegant way to friend a method to all sub-classes of a given class.
513 //------------------------------------------------------------------
515 //------------------------------------------------------------------
516 /// Queues the base plan for a thread.
517 /// The version returned by Process does some things that are useful,
518 /// like handle breakpoints and signals, so if you return a plugin specific
519 /// one you probably want to call through to the Process one for anything
520 /// your plugin doesn't explicitly handle.
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.
527 /// A shared pointer to the newly queued thread plan, or NULL if the plan could not be queued.
528 //------------------------------------------------------------------
529 virtual lldb::ThreadPlanSP
530 QueueFundamentalPlan (bool abort_other_plans);
532 //------------------------------------------------------------------
533 /// Queues the plan used to step one instruction from the current PC of \a thread.
535 /// @param[in] step_over
536 /// \b true if we step over calls to functions, false if we step in.
538 /// @param[in] abort_other_plans
539 /// \b true if we discard the currently queued plans and replace them with this one.
540 /// Otherwise this plan will go on the end of the plan stack.
542 /// @param[in] stop_other_threads
543 /// \b true if we will stop other threads while we single step this one.
546 /// A shared pointer to the newly queued thread plan, or NULL if the plan could not be queued.
547 //------------------------------------------------------------------
548 virtual lldb::ThreadPlanSP
549 QueueThreadPlanForStepSingleInstruction (bool step_over,
550 bool abort_other_plans,
551 bool stop_other_threads);
553 //------------------------------------------------------------------
554 /// Queues the plan used to step through an address range, stepping over
557 /// @param[in] abort_other_plans
558 /// \b true if we discard the currently queued plans and replace them with this one.
559 /// Otherwise this plan will go on the end of the plan stack.
562 /// Type of step to do, only eStepTypeInto and eStepTypeOver are supported by this plan.
565 /// The address range to step through.
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.
574 /// @param[in] stop_other_threads
575 /// \b true if we will stop other threads while we single step this one.
578 /// A shared pointer to the newly queued thread plan, or NULL if the plan could not be queued.
579 //------------------------------------------------------------------
580 virtual lldb::ThreadPlanSP
581 QueueThreadPlanForStepOverRange (bool abort_other_plans,
582 const AddressRange &range,
583 const SymbolContext &addr_context,
584 lldb::RunMode stop_other_threads);
586 //------------------------------------------------------------------
587 /// Queues the plan used to step through an address range, stepping into functions.
589 /// @param[in] abort_other_plans
590 /// \b true if we discard the currently queued plans and replace them with this one.
591 /// Otherwise this plan will go on the end of the plan stack.
594 /// Type of step to do, only eStepTypeInto and eStepTypeOver are supported by this plan.
597 /// The address range to step through.
599 /// @param[in] addr_context
600 /// When dealing with stepping through inlined functions the current PC is not enough information to know
601 /// what "step" means. For instance a series of nested inline functions might start at the same address.
602 // The \a addr_context provides the current symbol context the step
603 /// is supposed to be out of.
604 // FIXME: Currently unused.
606 /// @param[in] step_in_target
607 /// Name if function we are trying to step into. We will step out if we don't land in that function.
609 /// @param[in] stop_other_threads
610 /// \b true if we will stop other threads while we single step this one.
612 /// @param[in] avoid_code_without_debug_info
613 /// If \b true we will step out if we step into code with no debug info.
616 /// A shared pointer to the newly queued thread plan, or NULL if the plan could not be queued.
617 //------------------------------------------------------------------
618 virtual lldb::ThreadPlanSP
619 QueueThreadPlanForStepInRange (bool abort_other_plans,
620 const AddressRange &range,
621 const SymbolContext &addr_context,
622 const char *step_in_target,
623 lldb::RunMode stop_other_threads,
624 bool avoid_code_without_debug_info);
626 //------------------------------------------------------------------
627 /// Queue the plan used to step out of the function at the current PC of
630 /// @param[in] abort_other_plans
631 /// \b true if we discard the currently queued plans and replace them with this one.
632 /// Otherwise this plan will go on the end of the plan stack.
634 /// @param[in] addr_context
635 /// When dealing with stepping through inlined functions the current PC is not enough information to know
636 /// what "step" means. For instance a series of nested inline functions might start at the same address.
637 // The \a addr_context provides the current symbol context the step
638 /// is supposed to be out of.
639 // FIXME: Currently unused.
641 /// @param[in] first_insn
642 /// \b true if this is the first instruction of a function.
644 /// @param[in] stop_other_threads
645 /// \b true if we will stop other threads while we single step this one.
647 /// @param[in] stop_vote
648 /// @param[in] run_vote
649 /// See standard meanings for the stop & run votes in ThreadPlan.h.
652 /// A shared pointer to the newly queued thread plan, or NULL if the plan could not be queued.
653 //------------------------------------------------------------------
654 virtual lldb::ThreadPlanSP
655 QueueThreadPlanForStepOut (bool abort_other_plans,
656 SymbolContext *addr_context,
658 bool stop_other_threads,
659 Vote stop_vote, // = eVoteYes,
660 Vote run_vote, // = eVoteNoOpinion);
663 //------------------------------------------------------------------
664 /// Gets the plan used to step through the code that steps from a function
665 /// call site at the current PC into the actual function call.
668 /// @param[in] return_stack_id
669 /// The stack id that we will return to (by setting backstop breakpoints on the return
670 /// address to that frame) if we fail to step through.
672 /// @param[in] abort_other_plans
673 /// \b true if we discard the currently queued plans and replace them with this one.
674 /// Otherwise this plan will go on the end of the plan stack.
676 /// @param[in] stop_other_threads
677 /// \b true if we will stop other threads while we single step this one.
680 /// A shared pointer to the newly queued thread plan, or NULL if the plan could not be queued.
681 //------------------------------------------------------------------
682 virtual lldb::ThreadPlanSP
683 QueueThreadPlanForStepThrough (StackID &return_stack_id,
684 bool abort_other_plans,
685 bool stop_other_threads);
687 //------------------------------------------------------------------
688 /// Gets the plan used to continue from the current PC.
689 /// This is a simple plan, mostly useful as a backstop when you are continuing
690 /// for some particular purpose.
692 /// @param[in] abort_other_plans
693 /// \b true if we discard the currently queued plans and replace them with this one.
694 /// Otherwise this plan will go on the end of the plan stack.
696 /// @param[in] target_addr
697 /// The address to which we're running.
699 /// @param[in] stop_other_threads
700 /// \b true if we will stop other threads while we single step this one.
703 /// A shared pointer to the newly queued thread plan, or NULL if the plan could not be queued.
704 //------------------------------------------------------------------
705 virtual lldb::ThreadPlanSP
706 QueueThreadPlanForRunToAddress (bool abort_other_plans,
707 Address &target_addr,
708 bool stop_other_threads);
710 virtual lldb::ThreadPlanSP
711 QueueThreadPlanForStepUntil (bool abort_other_plans,
712 lldb::addr_t *address_list,
713 size_t num_addresses,
717 //------------------------------------------------------------------
718 // Thread Plan accessors:
719 //------------------------------------------------------------------
721 //------------------------------------------------------------------
722 /// Gets the plan which will execute next on the plan stack.
725 /// A pointer to the next executed plan.
726 //------------------------------------------------------------------
730 //------------------------------------------------------------------
731 /// Unwinds the thread stack for the innermost expression plan currently
732 /// on the thread plan stack.
735 /// An error if the thread plan could not be unwound.
736 //------------------------------------------------------------------
739 UnwindInnermostExpression();
743 PlanIsBasePlan (ThreadPlan *plan_ptr);
746 BroadcastSelectedFrameChange(StackID &new_frame_id);
750 //------------------------------------------------------------------
751 /// Gets the outer-most plan that was popped off the plan stack in the
752 /// most recent stop. Useful for printing the stop reason accurately.
755 /// A pointer to the last completed plan.
756 //------------------------------------------------------------------
760 //------------------------------------------------------------------
761 /// Gets the outer-most return value from the completed plans
764 /// A ValueObjectSP, either empty if there is no return value,
765 /// or containing the return value.
766 //------------------------------------------------------------------
768 GetReturnValueObject ();
770 //------------------------------------------------------------------
771 /// Checks whether the given plan is in the completed plans for this
775 /// Pointer to the plan you're checking.
778 /// Returns true if the input plan is in the completed plan stack,
780 //------------------------------------------------------------------
782 IsThreadPlanDone (ThreadPlan *plan);
784 //------------------------------------------------------------------
785 /// Checks whether the given plan is in the discarded plans for this
789 /// Pointer to the plan you're checking.
792 /// Returns true if the input plan is in the discarded plan stack,
794 //------------------------------------------------------------------
796 WasThreadPlanDiscarded (ThreadPlan *plan);
798 //------------------------------------------------------------------
799 /// Queues a generic thread plan.
801 /// @param[in] plan_sp
802 /// The plan to queue.
804 /// @param[in] abort_other_plans
805 /// \b true if we discard the currently queued plans and replace them with this one.
806 /// Otherwise this plan will go on the end of the plan stack.
809 /// A pointer to the last completed plan.
810 //------------------------------------------------------------------
812 QueueThreadPlan (lldb::ThreadPlanSP &plan_sp, bool abort_other_plans);
815 //------------------------------------------------------------------
816 /// Discards the plans queued on the plan stack of the current thread. This is
817 /// arbitrated by the "Master" ThreadPlans, using the "OkayToDiscard" call.
818 // But if \a force is true, all thread plans are discarded.
819 //------------------------------------------------------------------
821 DiscardThreadPlans (bool force);
823 //------------------------------------------------------------------
824 /// Discards the plans queued on the plan stack of the current thread up to and
825 /// including up_to_plan_sp.
827 // @param[in] up_to_plan_sp
828 // Discard all plans up to and including this one.
829 //------------------------------------------------------------------
831 DiscardThreadPlansUpToPlan (lldb::ThreadPlanSP &up_to_plan_sp);
834 DiscardThreadPlansUpToPlan (ThreadPlan *up_to_plan_ptr);
836 //------------------------------------------------------------------
837 /// Prints the current plan stack.
840 /// The stream to which to dump the plan stack info.
842 //------------------------------------------------------------------
844 DumpThreadPlans (Stream *s) const;
847 CheckpointThreadState (ThreadStateCheckpoint &saved_state);
850 RestoreRegisterStateFromCheckpoint (ThreadStateCheckpoint &saved_state);
853 RestoreThreadStateFromCheckpoint (ThreadStateCheckpoint &saved_state);
856 EnableTracer (bool value, bool single_step);
859 SetTracer (lldb::ThreadPlanTracerSP &tracer_sp);
861 //------------------------------------------------------------------
862 // Get the thread index ID. The index ID that is guaranteed to not
863 // be re-used by a process. They start at 1 and increase with each
864 // new thread. This allows easy command line access by a unique ID
865 // that is easier to type than the actual system thread ID.
866 //------------------------------------------------------------------
870 //------------------------------------------------------------------
871 // Get the originating thread's index ID.
872 // In the case of an "extended" thread -- a thread which represents
873 // the stack that enqueued/spawned work that is currently executing --
874 // we need to provide the IndexID of the thread that actually did
875 // this work. We don't want to just masquerade as that thread's IndexID
876 // by using it in our own IndexID because that way leads to madness -
877 // but the driver program which is iterating over extended threads
878 // may ask for the OriginatingThreadID to display that information
880 // Normal threads will return the same thing as GetIndexID();
881 //------------------------------------------------------------------
883 GetExtendedBacktraceOriginatingIndexID ()
885 return GetIndexID ();
888 //------------------------------------------------------------------
889 // The API ID is often the same as the Thread::GetID(), but not in
890 // all cases. Thread::GetID() is the user visible thread ID that
891 // clients would want to see. The API thread ID is the thread ID
892 // that is used when sending data to/from the debugging protocol.
893 //------------------------------------------------------------------
894 virtual lldb::user_id_t
895 GetProtocolID () const
900 //------------------------------------------------------------------
901 // lldb::ExecutionContextScope pure virtual functions
902 //------------------------------------------------------------------
903 virtual lldb::TargetSP
906 virtual lldb::ProcessSP
909 virtual lldb::ThreadSP
912 virtual lldb::StackFrameSP
913 CalculateStackFrame ();
916 CalculateExecutionContext (ExecutionContext &exe_ctx);
919 GetStackFrameSPForStackFramePtr (StackFrame *stack_frame_ptr);
922 GetStatus (Stream &strm,
923 uint32_t start_frame,
925 uint32_t num_frames_with_source);
928 GetStackFrameStatus (Stream& strm,
929 uint32_t first_frame,
931 bool show_frame_info,
932 uint32_t num_frames_with_source);
934 // We need a way to verify that even though we have a thread in a shared
935 // pointer that the object itself is still valid. Currently this won't be
936 // the case if DestroyThread() was called. DestroyThread is called when
937 // a thread has been removed from the Process' thread list.
941 return !m_destroy_called;
944 // Sets and returns a valid stop info based on the process stop ID and the
945 // current thread plan. If the thread stop ID does not match the process'
946 // stop ID, the private stop reason is not set and an invalid StopInfoSP may
949 // NOTE: This function must be called before the current thread plan is
950 // moved to the completed plan stack (in Thread::ShouldStop()).
952 // NOTE: If subclasses override this function, ensure they do not overwrite
953 // the m_actual_stop_info if it is valid. The stop info may be a
954 // "checkpointed and restored" stop info, so if it is still around it is
955 // right even if you have not calculated this yourself, or if it disagrees
956 // with what you might have calculated.
957 virtual lldb::StopInfoSP
958 GetPrivateStopInfo ();
960 //----------------------------------------------------------------------
961 // Ask the thread subclass to set its stop info.
963 // Thread subclasses should call Thread::SetStopInfo(...) with the
964 // reason the thread stopped.
967 // True if Thread::SetStopInfo(...) was called, false otherwise.
968 //----------------------------------------------------------------------
970 CalculateStopInfo () = 0;
972 //----------------------------------------------------------------------
973 // Gets the temporary resume state for a thread.
975 // This value gets set in each thread by complex debugger logic in
976 // Thread::ShouldResume() and an appropriate thread resume state will get
977 // set in each thread every time the process is resumed prior to calling
978 // Process::DoResume(). The lldb_private::Process subclass should adhere
979 // to the thread resume state request which will be one of:
981 // eStateRunning - thread will resume when process is resumed
982 // eStateStepping - thread should step 1 instruction and stop when process
984 // eStateSuspended - thread should not execute any instructions when
985 // process is resumed
986 //----------------------------------------------------------------------
988 GetTemporaryResumeState() const
990 return m_temporary_resume_state;
994 SetStopInfo (const lldb::StopInfoSP &stop_info_sp);
997 SetShouldReportStop (Vote vote);
999 //----------------------------------------------------------------------
1000 /// Sets the extended backtrace token for this thread
1002 /// Some Thread subclasses may maintain a token to help with providing
1003 /// an extended backtrace. The SystemRuntime plugin will set/request this.
1005 /// @param [in] token
1006 //----------------------------------------------------------------------
1008 SetExtendedBacktraceToken (uint64_t token) { }
1010 //----------------------------------------------------------------------
1011 /// Gets the extended backtrace token for this thread
1013 /// Some Thread subclasses may maintain a token to help with providing
1014 /// an extended backtrace. The SystemRuntime plugin will set/request this.
1017 /// The token needed by the SystemRuntime to create an extended backtrace.
1018 /// LLDB_INVALID_ADDRESS is returned if no token is available.
1019 //----------------------------------------------------------------------
1021 GetExtendedBacktraceToken ()
1023 return LLDB_INVALID_ADDRESS;
1028 friend class ThreadPlan;
1029 friend class ThreadList;
1030 friend class ThreadEventData;
1031 friend class StackFrameList;
1032 friend class StackFrame;
1033 friend class OperatingSystem;
1035 // This is necessary to make sure thread assets get destroyed while the thread is still in good shape
1036 // to call virtual thread methods. This must be called by classes that derive from Thread in their destructor.
1037 virtual void DestroyThread ();
1040 PushPlan (lldb::ThreadPlanSP &plan_sp);
1048 ThreadPlan *GetPreviousPlan (ThreadPlan *plan);
1050 typedef std::vector<lldb::ThreadPlanSP> plan_stack;
1052 virtual lldb_private::Unwind *
1055 // Check to see whether the thread is still at the last breakpoint hit that stopped it.
1057 IsStillAtLastBreakpointHit();
1059 // Some threads are threads that are made up by OperatingSystem plugins that
1060 // are threads that exist and are context switched out into memory. The
1061 // OperatingSystem plug-in need a ways to know if a thread is "real" or made
1064 IsOperatingSystemPluginThread () const
1070 lldb::StackFrameListSP
1071 GetStackFrameList ();
1074 //------------------------------------------------------------------
1075 // Classes that inherit from Process can see and modify these
1076 //------------------------------------------------------------------
1077 lldb::ProcessWP m_process_wp; ///< The process that owns this thread.
1078 lldb::StopInfoSP m_stop_info_sp; ///< The private stop reason for this thread
1079 uint32_t m_stop_info_stop_id; // This is the stop id for which the StopInfo is valid. Can use this so you know that
1080 // the thread's m_stop_info_sp is current and you don't have to fetch it again
1081 const uint32_t m_index_id; ///< A unique 1 based index assigned to each thread for easy UI/command line access.
1082 lldb::RegisterContextSP m_reg_context_sp; ///< The register context for this thread's current register state.
1083 lldb::StateType m_state; ///< The state of our process.
1084 mutable Mutex m_state_mutex; ///< Multithreaded protection for m_state.
1085 plan_stack m_plan_stack; ///< The stack of plans this thread is executing.
1086 plan_stack m_completed_plan_stack; ///< Plans that have been completed by this stop. They get deleted when the thread resumes.
1087 plan_stack m_discarded_plan_stack; ///< Plans that have been discarded by this stop. They get deleted when the thread resumes.
1088 mutable Mutex m_frame_mutex; ///< Multithreaded protection for m_state.
1089 lldb::StackFrameListSP m_curr_frames_sp; ///< The stack frames that get lazily populated after a thread stops.
1090 lldb::StackFrameListSP m_prev_frames_sp; ///< The previous stack frames from the last time this thread stopped.
1091 int m_resume_signal; ///< The signal that should be used when continuing this thread.
1092 lldb::StateType m_resume_state; ///< This state is used to force a thread to be suspended from outside the ThreadPlan logic.
1093 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.
1094 /// It gets set in Thread::ShoudResume.
1095 std::unique_ptr<lldb_private::Unwind> m_unwinder_ap;
1096 bool m_destroy_called; // This is used internally to make sure derived Thread classes call DestroyThread.
1097 LazyBool m_override_should_notify;
1099 //------------------------------------------------------------------
1101 //------------------------------------------------------------------
1103 DISALLOW_COPY_AND_ASSIGN (Thread);
1107 } // namespace lldb_private
1109 #endif // liblldb_Thread_h_