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