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