Thread.h revision 9acf3699d2bea583b45c762f4cd82b2a4af6131b
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
398    bool
399    SetSelectedFrameByIndex (uint32_t frame_idx, bool broadcast = false);
400
401    bool
402    SetSelectedFrameByIndexNoisily (uint32_t frame_idx, Stream &output_stream);
403
404    void
405    SetDefaultFileAndLineToSelectedFrame()
406    {
407        GetStackFrameList()->SetDefaultFileAndLineToSelectedFrame();
408    }
409
410    virtual lldb::RegisterContextSP
411    GetRegisterContext () = 0;
412
413    virtual lldb::RegisterContextSP
414    CreateRegisterContextForFrame (StackFrame *frame) = 0;
415
416    virtual void
417    ClearStackFrames ();
418
419    virtual bool
420    SetBackingThread (const lldb::ThreadSP &thread_sp)
421    {
422        return false;
423    }
424
425    virtual void
426    ClearBackingThread ()
427    {
428        // Subclasses can use this function if a thread is actually backed by
429        // another thread. This is currently used for the OperatingSystem plug-ins
430        // where they might have a thread that is in memory, yet its registers
431        // are available through the lldb_private::Thread subclass for the current
432        // lldb_private::Process class. Since each time the process stops the backing
433        // threads for memory threads can change, we need a way to clear the backing
434        // thread for all memory threads each time we stop.
435    }
436
437    void
438    DumpUsingSettingsFormat (Stream &strm, uint32_t frame_idx);
439
440    //------------------------------------------------------------------
441    // Thread Plan Providers:
442    // This section provides the basic thread plans that the Process control
443    // machinery uses to run the target.  ThreadPlan.h provides more details on
444    // how this mechanism works.
445    // The thread provides accessors to a set of plans that perform basic operations.
446    // The idea is that particular Platform plugins can override these methods to
447    // provide the implementation of these basic operations appropriate to their
448    // environment.
449    //------------------------------------------------------------------
450
451    //------------------------------------------------------------------
452    /// Queues the base plan for a thread.
453    /// The version returned by Process does some things that are useful,
454    /// like handle breakpoints and signals, so if you return a plugin specific
455    /// one you probably want to call through to the Process one for anything
456    /// your plugin doesn't explicitly handle.
457    ///
458    /// @param[in] abort_other_plans
459    ///    \b true if we discard the currently queued plans and replace them with this one.
460    ///    Otherwise this plan will go on the end of the plan stack.
461    ///
462    /// @return
463    ///     A pointer to the newly queued thread plan, or NULL if the plan could not be queued.
464    //------------------------------------------------------------------
465    virtual ThreadPlan *
466    QueueFundamentalPlan (bool abort_other_plans);
467
468    //------------------------------------------------------------------
469    /// Queues the plan used to step over a breakpoint at the current PC of \a thread.
470    /// The default version returned by Process handles trap based breakpoints, and
471    /// will disable the breakpoint, single step over it, then re-enable it.
472    ///
473    /// @param[in] abort_other_plans
474    ///    \b true if we discard the currently queued plans and replace them with this one.
475    ///    Otherwise this plan will go on the end of the plan stack.
476    ///
477    /// @return
478    ///     A pointer to the newly queued thread plan, or NULL if the plan could not be queued.
479    //------------------------------------------------------------------
480    virtual ThreadPlan *
481    QueueThreadPlanForStepOverBreakpointPlan (bool abort_other_plans);
482
483    //------------------------------------------------------------------
484    /// Queues the plan used to step one instruction from the current PC of \a thread.
485    ///
486    /// @param[in] step_over
487    ///    \b true if we step over calls to functions, false if we step in.
488    ///
489    /// @param[in] abort_other_plans
490    ///    \b true if we discard the currently queued plans and replace them with this one.
491    ///    Otherwise this plan will go on the end of the plan stack.
492    ///
493    /// @param[in] stop_other_threads
494    ///    \b true if we will stop other threads while we single step this one.
495    ///
496    /// @return
497    ///     A pointer to the newly queued thread plan, or NULL if the plan could not be queued.
498    //------------------------------------------------------------------
499    virtual ThreadPlan *
500    QueueThreadPlanForStepSingleInstruction (bool step_over,
501                                             bool abort_other_plans,
502                                             bool stop_other_threads);
503
504    //------------------------------------------------------------------
505    /// Queues the plan used to step through an address range, stepping  over
506    /// function calls.
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] type
513    ///    Type of step to do, only eStepTypeInto and eStepTypeOver are supported by this plan.
514    ///
515    /// @param[in] range
516    ///    The address range to step through.
517    ///
518    /// @param[in] addr_context
519    ///    When dealing with stepping through inlined functions the current PC is not enough information to know
520    ///    what "step" means.  For instance a series of nested inline functions might start at the same address.
521    //     The \a addr_context provides the current symbol context the step
522    ///    is supposed to be out of.
523    //   FIXME: Currently unused.
524    ///
525    /// @param[in] stop_other_threads
526    ///    \b true if we will stop other threads while we single step this one.
527    ///
528    /// @return
529    ///     A pointer to the newly queued thread plan, or NULL if the plan could not be queued.
530    //------------------------------------------------------------------
531    virtual ThreadPlan *
532    QueueThreadPlanForStepOverRange (bool abort_other_plans,
533                                 const AddressRange &range,
534                                 const SymbolContext &addr_context,
535                                 lldb::RunMode stop_other_threads);
536
537    //------------------------------------------------------------------
538    /// Queues the plan used to step through an address range, stepping into functions.
539    ///
540    /// @param[in] abort_other_plans
541    ///    \b true if we discard the currently queued plans and replace them with this one.
542    ///    Otherwise this plan will go on the end of the plan stack.
543    ///
544    /// @param[in] type
545    ///    Type of step to do, only eStepTypeInto and eStepTypeOver are supported by this plan.
546    ///
547    /// @param[in] range
548    ///    The address range to step through.
549    ///
550    /// @param[in] addr_context
551    ///    When dealing with stepping through inlined functions the current PC is not enough information to know
552    ///    what "step" means.  For instance a series of nested inline functions might start at the same address.
553    //     The \a addr_context provides the current symbol context the step
554    ///    is supposed to be out of.
555    //   FIXME: Currently unused.
556    ///
557    /// @param[in] step_in_target
558    ///    Name if function we are trying to step into.  We will step out if we don't land in that function.
559    ///
560    /// @param[in] stop_other_threads
561    ///    \b true if we will stop other threads while we single step this one.
562    ///
563    /// @param[in] avoid_code_without_debug_info
564    ///    If \b true we will step out if we step into code with no debug info.
565    ///
566    /// @return
567    ///     A pointer to the newly queued thread plan, or NULL if the plan could not be queued.
568    //------------------------------------------------------------------
569    virtual ThreadPlan *
570    QueueThreadPlanForStepInRange (bool abort_other_plans,
571                                 const AddressRange &range,
572                                 const SymbolContext &addr_context,
573                                 const char *step_in_target,
574                                 lldb::RunMode stop_other_threads,
575                                 bool avoid_code_without_debug_info);
576
577    //------------------------------------------------------------------
578    /// Queue the plan used to step out of the function at the current PC of
579    /// \a thread.
580    ///
581    /// @param[in] abort_other_plans
582    ///    \b true if we discard the currently queued plans and replace them with this one.
583    ///    Otherwise this plan will go on the end of the plan stack.
584    ///
585    /// @param[in] addr_context
586    ///    When dealing with stepping through inlined functions the current PC is not enough information to know
587    ///    what "step" means.  For instance a series of nested inline functions might start at the same address.
588    //     The \a addr_context provides the current symbol context the step
589    ///    is supposed to be out of.
590    //   FIXME: Currently unused.
591    ///
592    /// @param[in] first_insn
593    ///     \b true if this is the first instruction of a function.
594    ///
595    /// @param[in] stop_other_threads
596    ///    \b true if we will stop other threads while we single step this one.
597    ///
598    /// @param[in] stop_vote
599    /// @param[in] run_vote
600    ///    See standard meanings for the stop & run votes in ThreadPlan.h.
601    ///
602    /// @return
603    ///     A pointer to the newly queued thread plan, or NULL if the plan could not be queued.
604    //------------------------------------------------------------------
605    virtual ThreadPlan *
606    QueueThreadPlanForStepOut (bool abort_other_plans,
607                               SymbolContext *addr_context,
608                               bool first_insn,
609                               bool stop_other_threads,
610                               Vote stop_vote, // = eVoteYes,
611                               Vote run_vote, // = eVoteNoOpinion);
612                               uint32_t frame_idx);
613
614    //------------------------------------------------------------------
615    /// Gets the plan used to step through the code that steps from a function
616    /// call site at the current PC into the actual function call.
617    ///
618    ///
619    /// @param[in] return_stack_id
620    ///    The stack id that we will return to (by setting backstop breakpoints on the return
621    ///    address to that frame) if we fail to step through.
622    ///
623    /// @param[in] abort_other_plans
624    ///    \b true if we discard the currently queued plans and replace them with this one.
625    ///    Otherwise this plan will go on the end of the plan stack.
626    ///
627    /// @param[in] stop_other_threads
628    ///    \b true if we will stop other threads while we single step this one.
629    ///
630    /// @return
631    ///     A pointer to the newly queued thread plan, or NULL if the plan could not be queued.
632    //------------------------------------------------------------------
633    virtual ThreadPlan *
634    QueueThreadPlanForStepThrough (StackID &return_stack_id,
635                                   bool abort_other_plans,
636                                   bool stop_other_threads);
637
638    //------------------------------------------------------------------
639    /// Gets the plan used to continue from the current PC.
640    /// This is a simple plan, mostly useful as a backstop when you are continuing
641    /// for some particular purpose.
642    ///
643    /// @param[in] abort_other_plans
644    ///    \b true if we discard the currently queued plans and replace them with this one.
645    ///    Otherwise this plan will go on the end of the plan stack.
646    ///
647    /// @param[in] target_addr
648    ///    The address to which we're running.
649    ///
650    /// @param[in] stop_other_threads
651    ///    \b true if we will stop other threads while we single step this one.
652    ///
653    /// @return
654    ///     A pointer to the newly queued thread plan, or NULL if the plan could not be queued.
655    //------------------------------------------------------------------
656    virtual ThreadPlan *
657    QueueThreadPlanForRunToAddress (bool abort_other_plans,
658                                    Address &target_addr,
659                                    bool stop_other_threads);
660
661    virtual ThreadPlan *
662    QueueThreadPlanForStepUntil (bool abort_other_plans,
663                                 lldb::addr_t *address_list,
664                                 size_t num_addresses,
665                                 bool stop_others,
666                                 uint32_t frame_idx);
667
668    virtual ThreadPlan *
669    QueueThreadPlanForCallFunction (bool abort_other_plans,
670                                    Address& function,
671                                    lldb::addr_t arg,
672                                    bool stop_other_threads,
673                                    bool unwind_on_error = false,
674                                    bool ignore_breakpoints = true);
675
676    //------------------------------------------------------------------
677    // Thread Plan accessors:
678    //------------------------------------------------------------------
679
680    //------------------------------------------------------------------
681    /// Gets the plan which will execute next on the plan stack.
682    ///
683    /// @return
684    ///     A pointer to the next executed plan.
685    //------------------------------------------------------------------
686    ThreadPlan *
687    GetCurrentPlan ();
688
689    //------------------------------------------------------------------
690    /// Unwinds the thread stack for the innermost expression plan currently
691    /// on the thread plan stack.
692    ///
693    /// @return
694    ///     An error if the thread plan could not be unwound.
695    //------------------------------------------------------------------
696
697    Error
698    UnwindInnermostExpression();
699
700private:
701    bool
702    PlanIsBasePlan (ThreadPlan *plan_ptr);
703
704    void
705    BroadcastSelectedFrameChange(StackID &new_frame_id);
706
707public:
708
709    //------------------------------------------------------------------
710    /// Gets the outer-most plan that was popped off the plan stack in the
711    /// most recent stop.  Useful for printing the stop reason accurately.
712    ///
713    /// @return
714    ///     A pointer to the last completed plan.
715    //------------------------------------------------------------------
716    lldb::ThreadPlanSP
717    GetCompletedPlan ();
718
719    //------------------------------------------------------------------
720    /// Gets the outer-most return value from the completed plans
721    ///
722    /// @return
723    ///     A ValueObjectSP, either empty if there is no return value,
724    ///     or containing the return value.
725    //------------------------------------------------------------------
726    lldb::ValueObjectSP
727    GetReturnValueObject ();
728
729    //------------------------------------------------------------------
730    ///  Checks whether the given plan is in the completed plans for this
731    ///  stop.
732    ///
733    /// @param[in] plan
734    ///     Pointer to the plan you're checking.
735    ///
736    /// @return
737    ///     Returns true if the input plan is in the completed plan stack,
738    ///     false otherwise.
739    //------------------------------------------------------------------
740    bool
741    IsThreadPlanDone (ThreadPlan *plan);
742
743    //------------------------------------------------------------------
744    ///  Checks whether the given plan is in the discarded plans for this
745    ///  stop.
746    ///
747    /// @param[in] plan
748    ///     Pointer to the plan you're checking.
749    ///
750    /// @return
751    ///     Returns true if the input plan is in the discarded plan stack,
752    ///     false otherwise.
753    //------------------------------------------------------------------
754    bool
755    WasThreadPlanDiscarded (ThreadPlan *plan);
756
757    //------------------------------------------------------------------
758    /// Queues a generic thread plan.
759    ///
760    /// @param[in] plan_sp
761    ///    The plan to queue.
762    ///
763    /// @param[in] abort_other_plans
764    ///    \b true if we discard the currently queued plans and replace them with this one.
765    ///    Otherwise this plan will go on the end of the plan stack.
766    ///
767    /// @return
768    ///     A pointer to the last completed plan.
769    //------------------------------------------------------------------
770    void
771    QueueThreadPlan (lldb::ThreadPlanSP &plan_sp, bool abort_other_plans);
772
773
774    //------------------------------------------------------------------
775    /// Discards the plans queued on the plan stack of the current thread.  This is
776    /// arbitrated by the "Master" ThreadPlans, using the "OkayToDiscard" call.
777    //  But if \a force is true, all thread plans are discarded.
778    //------------------------------------------------------------------
779    void
780    DiscardThreadPlans (bool force);
781
782    //------------------------------------------------------------------
783    /// Discards the plans queued on the plan stack of the current thread up to and
784    /// including up_to_plan_sp.
785    //
786    // @param[in] up_to_plan_sp
787    //   Discard all plans up to and including this one.
788    //------------------------------------------------------------------
789    void
790    DiscardThreadPlansUpToPlan (lldb::ThreadPlanSP &up_to_plan_sp);
791
792    void
793    DiscardThreadPlansUpToPlan (ThreadPlan *up_to_plan_ptr);
794
795    //------------------------------------------------------------------
796    /// Prints the current plan stack.
797    ///
798    /// @param[in] s
799    ///    The stream to which to dump the plan stack info.
800    ///
801    //------------------------------------------------------------------
802    void
803    DumpThreadPlans (Stream *s) const;
804
805    virtual bool
806    CheckpointThreadState (ThreadStateCheckpoint &saved_state);
807
808    virtual bool
809    RestoreRegisterStateFromCheckpoint (ThreadStateCheckpoint &saved_state);
810
811    virtual bool
812    RestoreThreadStateFromCheckpoint (ThreadStateCheckpoint &saved_state);
813
814    void
815    EnableTracer (bool value, bool single_step);
816
817    void
818    SetTracer (lldb::ThreadPlanTracerSP &tracer_sp);
819
820    // Get the thread index ID. The index ID that is guaranteed to not be
821    // re-used by a process. They start at 1 and increase with each new thread.
822    // This allows easy command line access by a unique ID that is easier to
823    // type than the actual system thread ID.
824    uint32_t
825    GetIndexID () const;
826
827    //------------------------------------------------------------------
828    // lldb::ExecutionContextScope pure virtual functions
829    //------------------------------------------------------------------
830    virtual lldb::TargetSP
831    CalculateTarget ();
832
833    virtual lldb::ProcessSP
834    CalculateProcess ();
835
836    virtual lldb::ThreadSP
837    CalculateThread ();
838
839    virtual lldb::StackFrameSP
840    CalculateStackFrame ();
841
842    virtual void
843    CalculateExecutionContext (ExecutionContext &exe_ctx);
844
845    lldb::StackFrameSP
846    GetStackFrameSPForStackFramePtr (StackFrame *stack_frame_ptr);
847
848    size_t
849    GetStatus (Stream &strm,
850               uint32_t start_frame,
851               uint32_t num_frames,
852               uint32_t num_frames_with_source);
853
854    size_t
855    GetStackFrameStatus (Stream& strm,
856                         uint32_t first_frame,
857                         uint32_t num_frames,
858                         bool show_frame_info,
859                         uint32_t num_frames_with_source);
860
861    // We need a way to verify that even though we have a thread in a shared
862    // pointer that the object itself is still valid. Currently this won't be
863    // the case if DestroyThread() was called. DestroyThread is called when
864    // a thread has been removed from the Process' thread list.
865    bool
866    IsValid () const
867    {
868        return !m_destroy_called;
869    }
870
871    // When you implement this method, make sure you don't overwrite the m_actual_stop_info if it claims to be
872    // valid.  The stop info may be a "checkpointed and restored" stop info, so if it is still around it is right
873    // even if you have not calculated this yourself, or if it disagrees with what you might have calculated.
874    virtual lldb::StopInfoSP
875    GetPrivateStopReason () = 0;
876
877    //----------------------------------------------------------------------
878    // Gets the temporary resume state for a thread.
879    //
880    // This value gets set in each thread by complex debugger logic in
881    // Thread::WillResume() and an appropriate thread resume state will get
882    // set in each thread every time the process is resumed prior to calling
883    // Process::DoResume(). The lldb_private::Process subclass should adhere
884    // to the thread resume state request which will be one of:
885    //
886    //  eStateRunning   - thread will resume when process is resumed
887    //  eStateStepping  - thread should step 1 instruction and stop when process
888    //                    is resumed
889    //  eStateSuspended - thread should not execute any instructions when
890    //                    process is resumed
891    //----------------------------------------------------------------------
892    lldb::StateType
893    GetTemporaryResumeState() const
894    {
895        return m_temporary_resume_state;
896    }
897
898protected:
899
900    friend class ThreadPlan;
901    friend class ThreadList;
902    friend class StackFrameList;
903    friend class StackFrame;
904
905    // This is necessary to make sure thread assets get destroyed while the thread is still in good shape
906    // to call virtual thread methods.  This must be called by classes that derive from Thread in their destructor.
907    virtual void DestroyThread ();
908
909    void
910    PushPlan (lldb::ThreadPlanSP &plan_sp);
911
912    void
913    PopPlan ();
914
915    void
916    DiscardPlan ();
917
918    ThreadPlan *GetPreviousPlan (ThreadPlan *plan);
919
920    typedef std::vector<lldb::ThreadPlanSP> plan_stack;
921
922    void
923    SetStopInfo (const lldb::StopInfoSP &stop_info_sp);
924
925    virtual bool
926    SaveFrameZeroState (RegisterCheckpoint &checkpoint);
927
928    virtual bool
929    RestoreSaveFrameZero (const RegisterCheckpoint &checkpoint);
930
931    // register_data_sp must be a DataSP passed to ReadAllRegisterValues.
932    bool
933    ResetFrameZeroRegisters (lldb::DataBufferSP register_data_sp);
934
935    virtual lldb_private::Unwind *
936    GetUnwinder ();
937
938    // Check to see whether the thread is still at the last breakpoint hit that stopped it.
939    virtual bool
940    IsStillAtLastBreakpointHit();
941
942    lldb::StackFrameListSP
943    GetStackFrameList ();
944
945    struct ThreadState
946    {
947        uint32_t           orig_stop_id;
948        lldb::StopInfoSP   stop_info_sp;
949        RegisterCheckpoint register_backup;
950    };
951
952    //------------------------------------------------------------------
953    // Classes that inherit from Process can see and modify these
954    //------------------------------------------------------------------
955    lldb::ProcessWP     m_process_wp;           ///< The process that owns this thread.
956    lldb::StopInfoSP    m_actual_stop_info_sp;  ///< The private stop reason for this thread
957    const uint32_t      m_index_id;             ///< A unique 1 based index assigned to each thread for easy UI/command line access.
958    lldb::RegisterContextSP m_reg_context_sp;   ///< The register context for this thread's current register state.
959    lldb::StateType     m_state;                ///< The state of our process.
960    mutable Mutex       m_state_mutex;          ///< Multithreaded protection for m_state.
961    plan_stack          m_plan_stack;           ///< The stack of plans this thread is executing.
962    plan_stack          m_completed_plan_stack; ///< Plans that have been completed by this stop.  They get deleted when the thread resumes.
963    plan_stack          m_discarded_plan_stack; ///< Plans that have been discarded by this stop.  They get deleted when the thread resumes.
964    mutable Mutex       m_frame_mutex;          ///< Multithreaded protection for m_state.
965    lldb::StackFrameListSP m_curr_frames_sp;    ///< The stack frames that get lazily populated after a thread stops.
966    lldb::StackFrameListSP m_prev_frames_sp;    ///< The previous stack frames from the last time this thread stopped.
967    int                 m_resume_signal;        ///< The signal that should be used when continuing this thread.
968    lldb::StateType     m_resume_state;         ///< This state is used to force a thread to be suspended from outside the ThreadPlan logic.
969    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.
970                                                  /// It gets set in Thread::WillResume.
971    std::auto_ptr<lldb_private::Unwind> m_unwinder_ap;
972    bool                m_destroy_called;       // This is used internally to make sure derived Thread classes call DestroyThread.
973    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
974                                                // the thread's m_actual_stop_info_sp is current and you don't have to fetch it again
975
976private:
977    //------------------------------------------------------------------
978    // For Thread only
979    //------------------------------------------------------------------
980
981    DISALLOW_COPY_AND_ASSIGN (Thread);
982
983};
984
985} // namespace lldb_private
986
987#endif  // liblldb_Thread_h_
988