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/StructuredData.h"
18 #include "lldb/Core/UserID.h"
19 #include "lldb/Core/UserSettingsController.h"
20 #include "lldb/Target/ExecutionContextScope.h"
21 #include "lldb/Target/RegisterCheckpoint.h"
22 #include "lldb/Target/StackFrameList.h"
24 #define LLDB_THREAD_MAX_STOP_EXC_DATA 8
26 namespace lldb_private {
28 class ThreadProperties : public Properties
31 ThreadProperties(bool is_global);
36 //------------------------------------------------------------------
37 /// The regular expression returned determines symbols that this
38 /// thread won't stop in during "step-in" operations.
41 /// A pointer to a regular expression to compare against symbols,
42 /// or NULL if all symbols are allowed.
44 //------------------------------------------------------------------
45 const RegularExpression *
46 GetSymbolsToAvoidRegexp();
49 GetLibrariesToAvoid() const;
52 GetTraceEnabledState() const;
55 GetStepInAvoidsNoDebug () const;
58 GetStepOutAvoidsNoDebug () const;
61 typedef std::shared_ptr<ThreadProperties> ThreadPropertiesSP;
64 public std::enable_shared_from_this<Thread>,
65 public ThreadProperties,
67 public ExecutionContextScope,
71 //------------------------------------------------------------------
72 /// Broadcaster event bits definitions.
73 //------------------------------------------------------------------
76 eBroadcastBitStackChanged = (1 << 0),
77 eBroadcastBitThreadSuspended = (1 << 1),
78 eBroadcastBitThreadResumed = (1 << 2),
79 eBroadcastBitSelectedFrameChanged = (1 << 3),
80 eBroadcastBitThreadSelected = (1 << 4)
83 static ConstString &GetStaticBroadcasterClass ();
85 virtual ConstString &GetBroadcasterClass() const
87 return GetStaticBroadcasterClass();
90 class ThreadEventData :
94 ThreadEventData (const lldb::ThreadSP thread_sp);
96 ThreadEventData (const lldb::ThreadSP thread_sp, const StackID &stack_id);
100 virtual ~ThreadEventData();
102 static const ConstString &
105 virtual const ConstString &
108 return ThreadEventData::GetFlavorString ();
112 Dump (Stream *s) const;
114 static const ThreadEventData *
115 GetEventDataFromEvent (const Event *event_ptr);
117 static lldb::ThreadSP
118 GetThreadFromEvent (const Event *event_ptr);
121 GetStackIDFromEvent (const Event *event_ptr);
123 static lldb::StackFrameSP
124 GetStackFrameFromEvent (const Event *event_ptr);
139 lldb::ThreadSP m_thread_sp;
141 DISALLOW_COPY_AND_ASSIGN (ThreadEventData);
145 struct ThreadStateCheckpoint
147 uint32_t orig_stop_id; // Dunno if I need this yet but it is an interesting bit of data.
148 lldb::StopInfoSP stop_info_sp; // You have to restore the stop info or you might continue with the wrong signals.
149 lldb::RegisterCheckpointSP register_backup_sp; // You need to restore the registers, of course...
150 uint32_t current_inlined_depth;
151 lldb::addr_t current_inlined_pc;
155 SettingsInitialize ();
158 SettingsTerminate ();
160 static const ThreadPropertiesSP &
161 GetGlobalProperties();
163 //------------------------------------------------------------------
166 /// @param [in] process
170 /// @param [in] use_invalid_index_id
171 /// Optional parameter, defaults to false. The only subclass that
172 /// is likely to set use_invalid_index_id == true is the HistoryThread
173 /// class. In that case, the Thread we are constructing represents
174 /// a thread from earlier in the program execution. We may have the
175 /// tid of the original thread that they represent but we don't want
176 /// to reuse the IndexID of that thread, or create a new one. If a
177 /// client wants to know the original thread's IndexID, they should use
178 /// Thread::GetExtendedBacktraceOriginatingIndexID().
179 //------------------------------------------------------------------
180 Thread (Process &process, lldb::tid_t tid, bool use_invalid_index_id = false);
187 return m_process_wp.lock();
191 GetResumeSignal () const
193 return m_resume_signal;
197 SetResumeSignal (int signal)
199 m_resume_signal = signal;
206 SetState (lldb::StateType state);
209 GetResumeState () const
211 return m_resume_state;
214 // This sets the "external resume state" of the thread. If the thread is suspended here, it should never
215 // get scheduled. Note that just because a thread is marked as "running" does not mean we will let it run in
216 // a given bit of process control. For instance "step" tries to stay on the selected thread it was issued on,
217 // which may involve suspending other threads temporarily. This temporary suspension is NOT reflected in the
218 // state set here and reported in GetResumeState.
220 // If you are just preparing all threads to run, you should not override the threads that are
221 // marked as suspended by the debugger. In that case, pass override_suspend = false. If you want
222 // to force the thread to run (e.g. the "thread continue" command, or are resetting the state
223 // (e.g. in SBThread::Resume()), then pass true to override_suspend.
225 SetResumeState (lldb::StateType state, bool override_suspend = false)
227 if (m_resume_state == lldb::eStateSuspended && !override_suspend)
229 m_resume_state = state;
232 // This function is called on all the threads before "ShouldResume" and
233 // "WillResume" in case a thread needs to change its state before the
234 // ThreadList polls all the threads to figure out which ones actually
235 // will get to run and how.
239 // Do not override this function, it is for thread plan logic only
241 ShouldResume (lldb::StateType resume_state);
243 // Override this to do platform specific tasks before resume.
245 WillResume (lldb::StateType resume_state)
249 // This clears generic thread state after a resume. If you subclass this,
250 // be sure to call it.
254 // This notifies the thread when a private stop occurs.
259 RefreshStateAfterStop() = 0;
265 ShouldStop (Event *event_ptr);
268 ShouldReportStop (Event *event_ptr);
271 ShouldReportRun (Event *event_ptr);
276 // Return whether this thread matches the specification in ThreadSpec. This is a virtual
277 // method because at some point we may extend the thread spec with a platform specific
278 // dictionary of attributes, which then only the platform specific Thread implementation
279 // would know how to match. For now, this just calls through to the ThreadSpec's
280 // ThreadPassesBasicTests method.
282 MatchesSpec (const ThreadSpec *spec);
290 // This sets the stop reason to a "blank" stop reason, so you can call functions on the thread
291 // without having the called function run with whatever stop reason you stopped with.
293 SetStopInfoToNothing();
296 ThreadStoppedForAReason ();
299 RunModeAsCString (lldb::RunMode mode);
302 StopReasonAsCString (lldb::StopReason reason);
310 //------------------------------------------------------------------
311 /// Retrieve a dictionary of information about this thread
313 /// On Mac OS X systems there may be voucher information.
314 /// The top level dictionary returned will have an "activity" key and the
315 /// value of the activity is a dictionary. Keys in that dictionary will
316 /// be "name" and "id", among others.
317 /// There may also be "trace_messages" (an array) with each entry in that array
318 /// being a dictionary (keys include "message" with the text of the trace
320 //------------------------------------------------------------------
321 StructuredData::ObjectSP
324 if (m_extended_info_fetched == false)
326 m_extended_info = FetchThreadExtendedInfo ();
327 m_extended_info_fetched = true;
329 return m_extended_info;
339 SetName (const char *name)
343 //------------------------------------------------------------------
344 /// Retrieve the Queue ID for the queue currently using this Thread
346 /// If this Thread is doing work on behalf of a libdispatch/GCD queue,
347 /// retrieve the QueueID.
349 /// This is a unique identifier for the libdispatch/GCD queue in a
350 /// process. Often starting at 1 for the initial system-created
351 /// queues and incrementing, a QueueID will not be reused for a
352 /// different queue during the lifetime of a proces.
355 /// A QueueID if the Thread subclass implements this, else
356 /// LLDB_INVALID_QUEUE_ID.
357 //------------------------------------------------------------------
358 virtual lldb::queue_id_t
361 return LLDB_INVALID_QUEUE_ID;
365 SetQueueID (lldb::queue_id_t new_val)
369 //------------------------------------------------------------------
370 /// Retrieve the Queue name for the queue currently using this Thread
372 /// If this Thread is doing work on behalf of a libdispatch/GCD queue,
373 /// retrieve the Queue name.
376 /// The Queue name, if the Thread subclass implements this, else
378 //------------------------------------------------------------------
386 SetQueueName (const char *name)
390 //------------------------------------------------------------------
391 /// Retrieve the Queue for this thread, if any.
394 /// A QueueSP for the queue that is currently associated with this
396 /// An empty shared pointer indicates that this thread is not
397 /// associated with a queue, or libdispatch queues are not
398 /// supported on this target.
399 //------------------------------------------------------------------
400 virtual lldb::QueueSP
403 return lldb::QueueSP();
406 //------------------------------------------------------------------
407 /// Retrieve the address of the libdispatch_queue_t struct for queue
408 /// currently using this Thread
410 /// If this Thread is doing work on behalf of a libdispatch/GCD queue,
411 /// retrieve the address of the libdispatch_queue_t structure describing
414 /// This address may be reused for different queues later in the Process
415 /// lifetime and should not be used to identify a queue uniquely. Use
416 /// the GetQueueID() call for that.
419 /// The Queue's libdispatch_queue_t address if the Thread subclass
420 /// implements this, else LLDB_INVALID_ADDRESS.
421 //------------------------------------------------------------------
423 GetQueueLibdispatchQueueAddress ()
425 return LLDB_INVALID_ADDRESS;
431 return GetStackFrameList()->GetNumFrames();
434 virtual lldb::StackFrameSP
435 GetStackFrameAtIndex (uint32_t idx)
437 return GetStackFrameList()->GetFrameAtIndex(idx);
440 virtual lldb::StackFrameSP
441 GetFrameWithConcreteFrameIndex (uint32_t unwind_idx);
444 DecrementCurrentInlinedDepth()
446 return GetStackFrameList()->DecrementCurrentInlinedDepth();
450 GetCurrentInlinedDepth()
452 return GetStackFrameList()->GetCurrentInlinedDepth();
456 ReturnFromFrameWithIndex (uint32_t frame_idx, lldb::ValueObjectSP return_value_sp, bool broadcast = false);
459 ReturnFromFrame (lldb::StackFrameSP frame_sp, lldb::ValueObjectSP return_value_sp, bool broadcast = false);
462 JumpToLine (const FileSpec &file, uint32_t line, bool can_leave_function, std::string *warnings = NULL);
464 virtual lldb::StackFrameSP
465 GetFrameWithStackID (const StackID &stack_id)
467 if (stack_id.IsValid())
468 return GetStackFrameList()->GetFrameWithStackID (stack_id);
469 return lldb::StackFrameSP();
473 GetSelectedFrameIndex ()
475 return GetStackFrameList()->GetSelectedFrameIndex();
481 lldb::StackFrameListSP stack_frame_list_sp(GetStackFrameList());
482 return stack_frame_list_sp->GetFrameAtIndex (stack_frame_list_sp->GetSelectedFrameIndex());
486 SetSelectedFrame (lldb_private::StackFrame *frame, bool broadcast = false);
490 SetSelectedFrameByIndex (uint32_t frame_idx, bool broadcast = false);
493 SetSelectedFrameByIndexNoisily (uint32_t frame_idx, Stream &output_stream);
496 SetDefaultFileAndLineToSelectedFrame()
498 GetStackFrameList()->SetDefaultFileAndLineToSelectedFrame();
501 virtual lldb::RegisterContextSP
502 GetRegisterContext () = 0;
504 virtual lldb::RegisterContextSP
505 CreateRegisterContextForFrame (StackFrame *frame) = 0;
511 SetBackingThread (const lldb::ThreadSP &thread_sp)
516 virtual lldb::ThreadSP
517 GetBackingThread () const
519 return lldb::ThreadSP();
523 ClearBackingThread ()
525 // Subclasses can use this function if a thread is actually backed by
526 // another thread. This is currently used for the OperatingSystem plug-ins
527 // where they might have a thread that is in memory, yet its registers
528 // are available through the lldb_private::Thread subclass for the current
529 // lldb_private::Process class. Since each time the process stops the backing
530 // threads for memory threads can change, we need a way to clear the backing
531 // thread for all memory threads each time we stop.
535 DumpUsingSettingsFormat (Stream &strm, uint32_t frame_idx);
538 GetDescription (Stream &s, lldb::DescriptionLevel level, bool print_json_thread, bool print_json_stopinfo);
540 //------------------------------------------------------------------
541 /// Default implementation for stepping into.
543 /// This function is designed to be used by commands where the
544 /// process is publicly stopped.
546 /// @param[in] source_step
547 /// If true and the frame has debug info, then do a source level
548 /// step in, else do a single instruction step in.
550 /// @param[in] step_in_avoids_code_without_debug_info
551 /// If \a true, then avoid stepping into code that doesn't have
552 /// debug info, else step into any code regardless of whether it
555 /// @param[in] step_out_avoids_code_without_debug_info
556 /// If \a true, then if you step out to code with no debug info, keep
557 /// stepping out till you get to code with debug info.
560 /// An error that describes anything that went wrong
561 //------------------------------------------------------------------
563 StepIn (bool source_step,
564 LazyBool step_in_avoids_code_without_debug_info = eLazyBoolCalculate,
565 LazyBool step_out_avoids_code_without_debug_info = eLazyBoolCalculate);
567 //------------------------------------------------------------------
568 /// Default implementation for stepping over.
570 /// This function is designed to be used by commands where the
571 /// process is publicly stopped.
573 /// @param[in] source_step
574 /// If true and the frame has debug info, then do a source level
575 /// step over, else do a single instruction step over.
578 /// An error that describes anything that went wrong
579 //------------------------------------------------------------------
581 StepOver (bool source_step,
582 LazyBool step_out_avoids_code_without_debug_info = eLazyBoolCalculate);
584 //------------------------------------------------------------------
585 /// Default implementation for stepping out.
587 /// This function is designed to be used by commands where the
588 /// process is publicly stopped.
591 /// An error that describes anything that went wrong
592 //------------------------------------------------------------------
595 //------------------------------------------------------------------
596 /// Retrieves the per-thread data area.
597 /// Most OSs maintain a per-thread pointer (e.g. the FS register on
598 /// x64), which we return the value of here.
601 /// LLDB_INVALID_ADDRESS if not supported, otherwise the thread
603 //------------------------------------------------------------------
607 //------------------------------------------------------------------
608 /// Retrieves the per-module TLS block for a thread.
610 /// @param[in] module
611 /// The module to query TLS data for.
614 /// If the thread has TLS data allocated for the
615 /// module, the address of the TLS block. Otherwise
616 /// LLDB_INVALID_ADDRESS is returned.
617 //------------------------------------------------------------------
619 GetThreadLocalData (const lldb::ModuleSP module);
621 //------------------------------------------------------------------
622 /// Check whether this thread is safe to run functions
624 /// The SystemRuntime may know of certain thread states (functions in
625 /// process of execution, for instance) which can make it unsafe for
626 /// functions to be called.
629 /// True if it is safe to call functions on this thread.
630 /// False if function calls should be avoided on this thread.
631 //------------------------------------------------------------------
633 SafeToCallFunctions ();
635 //------------------------------------------------------------------
636 // Thread Plan Providers:
637 // This section provides the basic thread plans that the Process control
638 // machinery uses to run the target. ThreadPlan.h provides more details on
639 // how this mechanism works.
640 // The thread provides accessors to a set of plans that perform basic operations.
641 // The idea is that particular Platform plugins can override these methods to
642 // provide the implementation of these basic operations appropriate to their
645 // NB: All the QueueThreadPlanXXX providers return Shared Pointers to
646 // Thread plans. This is useful so that you can modify the plans after
647 // creation in ways specific to that plan type. Also, it is often necessary for
648 // ThreadPlans that utilize other ThreadPlans to implement their task to keep a shared
649 // pointer to the sub-plan.
650 // But besides that, the shared pointers should only be held onto by entities who live no longer
651 // than the thread containing the ThreadPlan.
652 // FIXME: If this becomes a problem, we can make a version that just returns a pointer,
653 // which it is clearly unsafe to hold onto, and a shared pointer version, and only allow
654 // ThreadPlan and Co. to use the latter. That is made more annoying to do because there's
655 // no elegant way to friend a method to all sub-classes of a given class.
657 //------------------------------------------------------------------
659 //------------------------------------------------------------------
660 /// Queues the base plan for a thread.
661 /// The version returned by Process does some things that are useful,
662 /// like handle breakpoints and signals, so if you return a plugin specific
663 /// one you probably want to call through to the Process one for anything
664 /// your plugin doesn't explicitly handle.
666 /// @param[in] abort_other_plans
667 /// \b true if we discard the currently queued plans and replace them with this one.
668 /// Otherwise this plan will go on the end of the plan stack.
671 /// A shared pointer to the newly queued thread plan, or NULL if the plan could not be queued.
672 //------------------------------------------------------------------
673 virtual lldb::ThreadPlanSP
674 QueueFundamentalPlan (bool abort_other_plans);
676 //------------------------------------------------------------------
677 /// Queues the plan used to step one instruction from the current PC of \a thread.
679 /// @param[in] step_over
680 /// \b true if we step over calls to functions, false if we step in.
682 /// @param[in] abort_other_plans
683 /// \b true if we discard the currently queued plans and replace them with this one.
684 /// Otherwise this plan will go on the end of the plan stack.
686 /// @param[in] stop_other_threads
687 /// \b true if we will stop other threads while we single step this one.
690 /// A shared pointer to the newly queued thread plan, or NULL if the plan could not be queued.
691 //------------------------------------------------------------------
692 virtual lldb::ThreadPlanSP
693 QueueThreadPlanForStepSingleInstruction (bool step_over,
694 bool abort_other_plans,
695 bool stop_other_threads);
697 //------------------------------------------------------------------
698 /// Queues the plan used to step through an address range, stepping over
701 /// @param[in] abort_other_plans
702 /// \b true if we discard the currently queued plans and replace them with this one.
703 /// Otherwise this plan will go on the end of the plan stack.
706 /// Type of step to do, only eStepTypeInto and eStepTypeOver are supported by this plan.
709 /// The address range to step through.
711 /// @param[in] addr_context
712 /// When dealing with stepping through inlined functions the current PC is not enough information to know
713 /// what "step" means. For instance a series of nested inline functions might start at the same address.
714 // The \a addr_context provides the current symbol context the step
715 /// is supposed to be out of.
716 // FIXME: Currently unused.
718 /// @param[in] stop_other_threads
719 /// \b true if we will stop other threads while we single step this one.
721 /// @param[in] step_out_avoids_code_without_debug_info
722 /// If eLazyBoolYes, if the step over steps out it will continue to step out till it comes to a frame with debug info.
723 /// If eLazyBoolCalculate, we will consult the default set in the thread.
726 /// A shared pointer to the newly queued thread plan, or NULL if the plan could not be queued.
727 //------------------------------------------------------------------
728 virtual lldb::ThreadPlanSP
729 QueueThreadPlanForStepOverRange (bool abort_other_plans,
730 const AddressRange &range,
731 const SymbolContext &addr_context,
732 lldb::RunMode stop_other_threads,
733 LazyBool step_out_avoids_code_without_debug_info = eLazyBoolCalculate);
735 //------------------------------------------------------------------
736 /// Queues the plan used to step through an address range, stepping into functions.
738 /// @param[in] abort_other_plans
739 /// \b true if we discard the currently queued plans and replace them with this one.
740 /// Otherwise this plan will go on the end of the plan stack.
743 /// Type of step to do, only eStepTypeInto and eStepTypeOver are supported by this plan.
746 /// The address range to step through.
748 /// @param[in] addr_context
749 /// When dealing with stepping through inlined functions the current PC is not enough information to know
750 /// what "step" means. For instance a series of nested inline functions might start at the same address.
751 // The \a addr_context provides the current symbol context the step
752 /// is supposed to be out of.
753 // FIXME: Currently unused.
755 /// @param[in] step_in_target
756 /// Name if function we are trying to step into. We will step out if we don't land in that function.
758 /// @param[in] stop_other_threads
759 /// \b true if we will stop other threads while we single step this one.
761 /// @param[in] step_in_avoids_code_without_debug_info
762 /// If eLazyBoolYes we will step out if we step into code with no debug info.
763 /// If eLazyBoolCalculate we will consult the default set in the thread.
765 /// @param[in] step_out_avoids_code_without_debug_info
766 /// If eLazyBoolYes, if the step over steps out it will continue to step out till it comes to a frame with debug info.
767 /// If eLazyBoolCalculate, it will consult the default set in the thread.
770 /// A shared pointer to the newly queued thread plan, or NULL if the plan could not be queued.
771 //------------------------------------------------------------------
772 virtual lldb::ThreadPlanSP
773 QueueThreadPlanForStepInRange (bool abort_other_plans,
774 const AddressRange &range,
775 const SymbolContext &addr_context,
776 const char *step_in_target,
777 lldb::RunMode stop_other_threads,
778 LazyBool step_in_avoids_code_without_debug_info = eLazyBoolCalculate,
779 LazyBool step_out_avoids_code_without_debug_info = eLazyBoolCalculate);
781 //------------------------------------------------------------------
782 /// Queue the plan used to step out of the function at the current PC of
785 /// @param[in] abort_other_plans
786 /// \b true if we discard the currently queued plans and replace them with this one.
787 /// Otherwise this plan will go on the end of the plan stack.
789 /// @param[in] addr_context
790 /// When dealing with stepping through inlined functions the current PC is not enough information to know
791 /// what "step" means. For instance a series of nested inline functions might start at the same address.
792 // The \a addr_context provides the current symbol context the step
793 /// is supposed to be out of.
794 // FIXME: Currently unused.
796 /// @param[in] first_insn
797 /// \b true if this is the first instruction of a function.
799 /// @param[in] stop_other_threads
800 /// \b true if we will stop other threads while we single step this one.
802 /// @param[in] stop_vote
803 /// @param[in] run_vote
804 /// See standard meanings for the stop & run votes in ThreadPlan.h.
806 /// @param[in] step_out_avoids_code_without_debug_info
807 /// If eLazyBoolYes, if the step over steps out it will continue to step out till it comes to a frame with debug info.
808 /// If eLazyBoolCalculate, it will consult the default set in the thread.
811 /// A shared pointer to the newly queued thread plan, or NULL if the plan could not be queued.
812 //------------------------------------------------------------------
813 virtual lldb::ThreadPlanSP
814 QueueThreadPlanForStepOut (bool abort_other_plans,
815 SymbolContext *addr_context,
817 bool stop_other_threads,
818 Vote stop_vote, // = eVoteYes,
819 Vote run_vote, // = eVoteNoOpinion);
821 LazyBool step_out_avoids_code_without_debug_info = eLazyBoolCalculate);
823 //------------------------------------------------------------------
824 /// Queue the plan used to step out of the function at the current PC of
825 /// a thread. This version does not consult the should stop here callback, and should only
826 /// be used by other thread plans when they need to retain control of the step out.
828 /// @param[in] abort_other_plans
829 /// \b true if we discard the currently queued plans and replace them with this one.
830 /// Otherwise this plan will go on the end of the plan stack.
832 /// @param[in] addr_context
833 /// When dealing with stepping through inlined functions the current PC is not enough information to know
834 /// what "step" means. For instance a series of nested inline functions might start at the same address.
835 // The \a addr_context provides the current symbol context the step
836 /// is supposed to be out of.
837 // FIXME: Currently unused.
839 /// @param[in] first_insn
840 /// \b true if this is the first instruction of a function.
842 /// @param[in] stop_other_threads
843 /// \b true if we will stop other threads while we single step this one.
845 /// @param[in] stop_vote
846 /// @param[in] run_vote
847 /// See standard meanings for the stop & run votes in ThreadPlan.h.
850 /// A shared pointer to the newly queued thread plan, or NULL if the plan could not be queued.
851 //------------------------------------------------------------------
852 virtual lldb::ThreadPlanSP
853 QueueThreadPlanForStepOutNoShouldStop (bool abort_other_plans,
854 SymbolContext *addr_context,
856 bool stop_other_threads,
857 Vote stop_vote, // = eVoteYes,
858 Vote run_vote, // = eVoteNoOpinion);
861 //------------------------------------------------------------------
862 /// Gets the plan used to step through the code that steps from a function
863 /// call site at the current PC into the actual function call.
866 /// @param[in] return_stack_id
867 /// The stack id that we will return to (by setting backstop breakpoints on the return
868 /// address to that frame) if we fail to step through.
870 /// @param[in] abort_other_plans
871 /// \b true if we discard the currently queued plans and replace them with this one.
872 /// Otherwise this plan will go on the end of the plan stack.
874 /// @param[in] stop_other_threads
875 /// \b true if we will stop other threads while we single step this one.
878 /// A shared pointer to the newly queued thread plan, or NULL if the plan could not be queued.
879 //------------------------------------------------------------------
880 virtual lldb::ThreadPlanSP
881 QueueThreadPlanForStepThrough (StackID &return_stack_id,
882 bool abort_other_plans,
883 bool stop_other_threads);
885 //------------------------------------------------------------------
886 /// Gets the plan used to continue from the current PC.
887 /// This is a simple plan, mostly useful as a backstop when you are continuing
888 /// for some particular purpose.
890 /// @param[in] abort_other_plans
891 /// \b true if we discard the currently queued plans and replace them with this one.
892 /// Otherwise this plan will go on the end of the plan stack.
894 /// @param[in] target_addr
895 /// The address to which we're running.
897 /// @param[in] stop_other_threads
898 /// \b true if we will stop other threads while we single step this one.
901 /// A shared pointer to the newly queued thread plan, or NULL if the plan could not be queued.
902 //------------------------------------------------------------------
903 virtual lldb::ThreadPlanSP
904 QueueThreadPlanForRunToAddress (bool abort_other_plans,
905 Address &target_addr,
906 bool stop_other_threads);
908 virtual lldb::ThreadPlanSP
909 QueueThreadPlanForStepUntil (bool abort_other_plans,
910 lldb::addr_t *address_list,
911 size_t num_addresses,
915 virtual lldb::ThreadPlanSP
916 QueueThreadPlanForStepScripted (bool abort_other_plans,
917 const char *class_name,
918 bool stop_other_threads);
920 //------------------------------------------------------------------
921 // Thread Plan accessors:
922 //------------------------------------------------------------------
924 //------------------------------------------------------------------
925 /// Gets the plan which will execute next on the plan stack.
928 /// A pointer to the next executed plan.
929 //------------------------------------------------------------------
933 //------------------------------------------------------------------
934 /// Unwinds the thread stack for the innermost expression plan currently
935 /// on the thread plan stack.
938 /// An error if the thread plan could not be unwound.
939 //------------------------------------------------------------------
942 UnwindInnermostExpression();
946 PlanIsBasePlan (ThreadPlan *plan_ptr);
949 BroadcastSelectedFrameChange(StackID &new_frame_id);
953 //------------------------------------------------------------------
954 /// Gets the outer-most plan that was popped off the plan stack in the
955 /// most recent stop. Useful for printing the stop reason accurately.
958 /// A pointer to the last completed plan.
959 //------------------------------------------------------------------
963 //------------------------------------------------------------------
964 /// Gets the outer-most return value from the completed plans
967 /// A ValueObjectSP, either empty if there is no return value,
968 /// or containing the return value.
969 //------------------------------------------------------------------
971 GetReturnValueObject ();
973 //------------------------------------------------------------------
974 /// Gets the outer-most expression variable from the completed plans
977 /// A ClangExpressionVariableSP, either empty if there is no
978 /// plan completed an expression during the current stop
979 /// or the expression variable that was made for the completed expression.
980 //------------------------------------------------------------------
981 lldb::ClangExpressionVariableSP
982 GetExpressionVariable ();
984 //------------------------------------------------------------------
985 /// Checks whether the given plan is in the completed plans for this
989 /// Pointer to the plan you're checking.
992 /// Returns true if the input plan is in the completed plan stack,
994 //------------------------------------------------------------------
996 IsThreadPlanDone (ThreadPlan *plan);
998 //------------------------------------------------------------------
999 /// Checks whether the given plan is in the discarded plans for this
1003 /// Pointer to the plan you're checking.
1006 /// Returns true if the input plan is in the discarded plan stack,
1007 /// false otherwise.
1008 //------------------------------------------------------------------
1010 WasThreadPlanDiscarded (ThreadPlan *plan);
1012 //------------------------------------------------------------------
1013 /// Queues a generic thread plan.
1015 /// @param[in] plan_sp
1016 /// The plan to queue.
1018 /// @param[in] abort_other_plans
1019 /// \b true if we discard the currently queued plans and replace them with this one.
1020 /// Otherwise this plan will go on the end of the plan stack.
1023 /// A pointer to the last completed plan.
1024 //------------------------------------------------------------------
1026 QueueThreadPlan (lldb::ThreadPlanSP &plan_sp, bool abort_other_plans);
1029 //------------------------------------------------------------------
1030 /// Discards the plans queued on the plan stack of the current thread. This is
1031 /// arbitrated by the "Master" ThreadPlans, using the "OkayToDiscard" call.
1032 // But if \a force is true, all thread plans are discarded.
1033 //------------------------------------------------------------------
1035 DiscardThreadPlans (bool force);
1037 //------------------------------------------------------------------
1038 /// Discards the plans queued on the plan stack of the current thread up to and
1039 /// including up_to_plan_sp.
1041 // @param[in] up_to_plan_sp
1042 // Discard all plans up to and including this one.
1043 //------------------------------------------------------------------
1045 DiscardThreadPlansUpToPlan (lldb::ThreadPlanSP &up_to_plan_sp);
1048 DiscardThreadPlansUpToPlan (ThreadPlan *up_to_plan_ptr);
1050 //------------------------------------------------------------------
1051 /// Discards the plans queued on the plan stack of the current thread up to and
1052 /// including the plan in that matches \a thread_index counting only
1053 /// the non-Private plans.
1055 /// @param[in] up_to_plan_sp
1056 /// Discard all plans up to and including this user plan given by this index.
1059 /// \b true if there was a thread plan with that user index, \b false otherwise.
1060 //------------------------------------------------------------------
1062 DiscardUserThreadPlansUpToIndex (uint32_t thread_index);
1064 //------------------------------------------------------------------
1065 /// Prints the current plan stack.
1068 /// The stream to which to dump the plan stack info.
1070 //------------------------------------------------------------------
1072 DumpThreadPlans (Stream *s,
1073 lldb::DescriptionLevel desc_level = lldb::eDescriptionLevelVerbose,
1074 bool include_internal = true,
1075 bool ignore_boring = false) const;
1078 CheckpointThreadState (ThreadStateCheckpoint &saved_state);
1081 RestoreRegisterStateFromCheckpoint (ThreadStateCheckpoint &saved_state);
1084 RestoreThreadStateFromCheckpoint (ThreadStateCheckpoint &saved_state);
1087 EnableTracer (bool value, bool single_step);
1090 SetTracer (lldb::ThreadPlanTracerSP &tracer_sp);
1092 //------------------------------------------------------------------
1093 // Get the thread index ID. The index ID that is guaranteed to not
1094 // be re-used by a process. They start at 1 and increase with each
1095 // new thread. This allows easy command line access by a unique ID
1096 // that is easier to type than the actual system thread ID.
1097 //------------------------------------------------------------------
1099 GetIndexID () const;
1101 //------------------------------------------------------------------
1102 // Get the originating thread's index ID.
1103 // In the case of an "extended" thread -- a thread which represents
1104 // the stack that enqueued/spawned work that is currently executing --
1105 // we need to provide the IndexID of the thread that actually did
1106 // this work. We don't want to just masquerade as that thread's IndexID
1107 // by using it in our own IndexID because that way leads to madness -
1108 // but the driver program which is iterating over extended threads
1109 // may ask for the OriginatingThreadID to display that information
1111 // Normal threads will return the same thing as GetIndexID();
1112 //------------------------------------------------------------------
1114 GetExtendedBacktraceOriginatingIndexID ()
1116 return GetIndexID ();
1119 //------------------------------------------------------------------
1120 // The API ID is often the same as the Thread::GetID(), but not in
1121 // all cases. Thread::GetID() is the user visible thread ID that
1122 // clients would want to see. The API thread ID is the thread ID
1123 // that is used when sending data to/from the debugging protocol.
1124 //------------------------------------------------------------------
1125 virtual lldb::user_id_t
1126 GetProtocolID () const
1131 //------------------------------------------------------------------
1132 // lldb::ExecutionContextScope pure virtual functions
1133 //------------------------------------------------------------------
1134 virtual lldb::TargetSP
1137 virtual lldb::ProcessSP
1138 CalculateProcess ();
1140 virtual lldb::ThreadSP
1143 virtual lldb::StackFrameSP
1144 CalculateStackFrame ();
1147 CalculateExecutionContext (ExecutionContext &exe_ctx);
1150 GetStackFrameSPForStackFramePtr (StackFrame *stack_frame_ptr);
1153 GetStatus (Stream &strm,
1154 uint32_t start_frame,
1155 uint32_t num_frames,
1156 uint32_t num_frames_with_source);
1159 GetStackFrameStatus (Stream& strm,
1160 uint32_t first_frame,
1161 uint32_t num_frames,
1162 bool show_frame_info,
1163 uint32_t num_frames_with_source);
1165 // We need a way to verify that even though we have a thread in a shared
1166 // pointer that the object itself is still valid. Currently this won't be
1167 // the case if DestroyThread() was called. DestroyThread is called when
1168 // a thread has been removed from the Process' thread list.
1172 return !m_destroy_called;
1175 // Sets and returns a valid stop info based on the process stop ID and the
1176 // current thread plan. If the thread stop ID does not match the process'
1177 // stop ID, the private stop reason is not set and an invalid StopInfoSP may
1180 // NOTE: This function must be called before the current thread plan is
1181 // moved to the completed plan stack (in Thread::ShouldStop()).
1183 // NOTE: If subclasses override this function, ensure they do not overwrite
1184 // the m_actual_stop_info if it is valid. The stop info may be a
1185 // "checkpointed and restored" stop info, so if it is still around it is
1186 // right even if you have not calculated this yourself, or if it disagrees
1187 // with what you might have calculated.
1188 virtual lldb::StopInfoSP
1189 GetPrivateStopInfo ();
1191 //----------------------------------------------------------------------
1192 // Ask the thread subclass to set its stop info.
1194 // Thread subclasses should call Thread::SetStopInfo(...) with the
1195 // reason the thread stopped.
1198 // True if Thread::SetStopInfo(...) was called, false otherwise.
1199 //----------------------------------------------------------------------
1201 CalculateStopInfo () = 0;
1203 //----------------------------------------------------------------------
1204 // Gets the temporary resume state for a thread.
1206 // This value gets set in each thread by complex debugger logic in
1207 // Thread::ShouldResume() and an appropriate thread resume state will get
1208 // set in each thread every time the process is resumed prior to calling
1209 // Process::DoResume(). The lldb_private::Process subclass should adhere
1210 // to the thread resume state request which will be one of:
1212 // eStateRunning - thread will resume when process is resumed
1213 // eStateStepping - thread should step 1 instruction and stop when process
1215 // eStateSuspended - thread should not execute any instructions when
1216 // process is resumed
1217 //----------------------------------------------------------------------
1219 GetTemporaryResumeState() const
1221 return m_temporary_resume_state;
1225 SetStopInfo (const lldb::StopInfoSP &stop_info_sp);
1228 SetShouldReportStop (Vote vote);
1230 //----------------------------------------------------------------------
1231 /// Sets the extended backtrace token for this thread
1233 /// Some Thread subclasses may maintain a token to help with providing
1234 /// an extended backtrace. The SystemRuntime plugin will set/request this.
1236 /// @param [in] token
1237 //----------------------------------------------------------------------
1239 SetExtendedBacktraceToken (uint64_t token) { }
1241 //----------------------------------------------------------------------
1242 /// Gets the extended backtrace token for this thread
1244 /// Some Thread subclasses may maintain a token to help with providing
1245 /// an extended backtrace. The SystemRuntime plugin will set/request this.
1248 /// The token needed by the SystemRuntime to create an extended backtrace.
1249 /// LLDB_INVALID_ADDRESS is returned if no token is available.
1250 //----------------------------------------------------------------------
1252 GetExtendedBacktraceToken ()
1254 return LLDB_INVALID_ADDRESS;
1259 friend class ThreadPlan;
1260 friend class ThreadList;
1261 friend class ThreadEventData;
1262 friend class StackFrameList;
1263 friend class StackFrame;
1264 friend class OperatingSystem;
1266 // This is necessary to make sure thread assets get destroyed while the thread is still in good shape
1267 // to call virtual thread methods. This must be called by classes that derive from Thread in their destructor.
1268 virtual void DestroyThread ();
1271 PushPlan (lldb::ThreadPlanSP &plan_sp);
1279 ThreadPlan *GetPreviousPlan (ThreadPlan *plan);
1281 typedef std::vector<lldb::ThreadPlanSP> plan_stack;
1283 virtual lldb_private::Unwind *
1286 // Check to see whether the thread is still at the last breakpoint hit that stopped it.
1288 IsStillAtLastBreakpointHit();
1290 // Some threads are threads that are made up by OperatingSystem plugins that
1291 // are threads that exist and are context switched out into memory. The
1292 // OperatingSystem plug-in need a ways to know if a thread is "real" or made
1295 IsOperatingSystemPluginThread () const
1300 // Subclasses that have a way to get an extended info dictionary for this thread should
1302 virtual lldb_private::StructuredData::ObjectSP
1303 FetchThreadExtendedInfo ()
1305 return StructuredData::ObjectSP();
1308 lldb::StackFrameListSP
1309 GetStackFrameList ();
1312 //------------------------------------------------------------------
1313 // Classes that inherit from Process can see and modify these
1314 //------------------------------------------------------------------
1315 lldb::ProcessWP m_process_wp; ///< The process that owns this thread.
1316 lldb::StopInfoSP m_stop_info_sp; ///< The private stop reason for this thread
1317 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
1318 uint32_t m_stop_info_override_stop_id; // The stop ID containing the last time the stop info was checked against the stop info override
1319 // the thread's m_stop_info_sp is current and you don't have to fetch it again
1320 const uint32_t m_index_id; ///< A unique 1 based index assigned to each thread for easy UI/command line access.
1321 lldb::RegisterContextSP m_reg_context_sp; ///< The register context for this thread's current register state.
1322 lldb::StateType m_state; ///< The state of our process.
1323 mutable Mutex m_state_mutex; ///< Multithreaded protection for m_state.
1324 plan_stack m_plan_stack; ///< The stack of plans this thread is executing.
1325 plan_stack m_completed_plan_stack; ///< Plans that have been completed by this stop. They get deleted when the thread resumes.
1326 plan_stack m_discarded_plan_stack; ///< Plans that have been discarded by this stop. They get deleted when the thread resumes.
1327 mutable Mutex m_frame_mutex; ///< Multithreaded protection for m_state.
1328 lldb::StackFrameListSP m_curr_frames_sp; ///< The stack frames that get lazily populated after a thread stops.
1329 lldb::StackFrameListSP m_prev_frames_sp; ///< The previous stack frames from the last time this thread stopped.
1330 int m_resume_signal; ///< The signal that should be used when continuing this thread.
1331 lldb::StateType m_resume_state; ///< This state is used to force a thread to be suspended from outside the ThreadPlan logic.
1332 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.
1333 /// It gets set in Thread::ShouldResume.
1334 std::unique_ptr<lldb_private::Unwind> m_unwinder_ap;
1335 bool m_destroy_called; // This is used internally to make sure derived Thread classes call DestroyThread.
1336 LazyBool m_override_should_notify;
1338 bool m_extended_info_fetched; // Have we tried to retrieve the m_extended_info for this thread?
1339 StructuredData::ObjectSP m_extended_info; // The extended info for this thread
1340 //------------------------------------------------------------------
1342 //------------------------------------------------------------------
1344 DISALLOW_COPY_AND_ASSIGN (Thread);
1348 } // namespace lldb_private
1350 #endif // liblldb_Thread_h_