StopInfo.h revision 043f8c230739ceab194257a617731ecd28e1a912
1//===-- StopInfo.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_StopInfo_h_
11#define liblldb_StopInfo_h_
12
13// C Includes
14// C++ Includes
15#include <string>
16
17// Other libraries and framework includes
18// Project includes
19#include "lldb/lldb-public.h"
20
21namespace lldb_private {
22
23class StopInfo
24{
25public:
26    //------------------------------------------------------------------
27    // Constructors and Destructors
28    //------------------------------------------------------------------
29    StopInfo (Thread &thread, uint64_t value);
30
31    virtual ~StopInfo()
32    {
33    }
34
35
36    bool
37    IsValid () const;
38
39    Thread &
40    GetThread()
41    {
42        return m_thread;
43    }
44
45    const Thread &
46    GetThread() const
47    {
48        return m_thread;
49    }
50
51    // The value of the StopInfo depends on the StopReason.
52    // StopReason                  Meaning
53    // ----------------------------------------------
54    // eStopReasonBreakpoint       BreakpointSiteID
55    // eStopReasonSignal           Signal number
56    // eStopReasonWatchpoint       WatchpointLocationID
57    // eStopReasonPlanComplete     No significance
58
59    uint64_t
60    GetValue() const
61    {
62        return m_value;
63    }
64
65    virtual lldb::StopReason
66    GetStopReason () const = 0;
67
68    // Perform any action that is associated with this stop.  This is done as the
69    // Event is removed from the event queue.
70    virtual void
71    PerformAction (Event *event_ptr)
72    {
73    }
74
75    // Stop the thread by default. Subclasses can override this to allow
76    // the thread to continue if desired.
77    virtual bool
78    ShouldStop (Event *event_ptr)
79    {
80        return true;
81    }
82
83    // If should stop returns false, check if we should notify of this event
84    virtual bool
85    ShouldNotify (Event *event_ptr)
86    {
87        return false;
88    }
89
90    virtual void
91    WillResume (lldb::StateType resume_state)
92    {
93        // By default, don't do anything
94    }
95
96    virtual const char *
97    GetDescription ()
98    {
99        return m_description.c_str();
100    }
101
102    virtual void
103    SetDescription (const char *desc_cstr)
104    {
105        if (desc_cstr && desc_cstr[0])
106            m_description.assign (desc_cstr);
107        else
108            m_description.clear();
109    }
110
111    static lldb::StopInfoSP
112    CreateStopReasonWithBreakpointSiteID (Thread &thread, lldb::break_id_t break_id);
113
114    // This creates a StopInfo for the thread where the should_stop is already set, and won't be recalculated.
115    static lldb::StopInfoSP
116    CreateStopReasonWithBreakpointSiteID (Thread &thread, lldb::break_id_t break_id, bool should_stop);
117
118    static lldb::StopInfoSP
119    CreateStopReasonWithWatchpointID (Thread &thread, lldb::break_id_t watch_id);
120
121    static lldb::StopInfoSP
122    CreateStopReasonWithSignal (Thread &thread, int signo);
123
124    static lldb::StopInfoSP
125    CreateStopReasonToTrace (Thread &thread);
126
127    static lldb::StopInfoSP
128    CreateStopReasonWithPlan (lldb::ThreadPlanSP &plan);
129
130    static lldb::StopInfoSP
131    CreateStopReasonWithException (Thread &thread, const char *description);
132
133protected:
134    //------------------------------------------------------------------
135    // Classes that inherit from StackID can see and modify these
136    //------------------------------------------------------------------
137    Thread &        m_thread;   // The thread corresponding to the stop reason.
138    uint32_t        m_stop_id;  // The process stop ID for which this stop info is valid
139    uint64_t        m_value;    // A generic value that can be used for things pertaining to this stop info
140    std::string     m_description; // A textual description describing this stop.
141
142    // This provides an accessor to the PrivateEventState of the process for StopInfo's w/o having to make each
143    // StopInfo subclass a friend of Process.
144    lldb::StateType
145    GetPrivateState ();
146
147private:
148    friend class Thread;
149
150    // MakeStopInfoValid is necessary to allow saved stop infos to resurrect themselves as valid.  It should
151    // only need to be called by Thread::RestoreThreadStateFromCheckpoint.
152    void
153    MakeStopInfoValid ();
154
155    DISALLOW_COPY_AND_ASSIGN (StopInfo);
156};
157
158} // namespace lldb_private
159
160#endif  // liblldb_StopInfo_h_
161