StopInfo.h revision 8a1e6542c5b125613ffce3039aa713ee6ea07dcf
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#include "lldb/Target/Process.h"
21
22namespace lldb_private {
23
24class StopInfo
25{
26    friend class Process::ProcessEventData;
27    friend class ThreadPlanBase;
28
29public:
30    //------------------------------------------------------------------
31    // Constructors and Destructors
32    //------------------------------------------------------------------
33    StopInfo (Thread &thread, uint64_t value);
34
35    virtual ~StopInfo()
36    {
37    }
38
39
40    bool
41    IsValid () const;
42
43    lldb::ThreadSP
44    GetThread() const
45    {
46        return m_thread_wp.lock();
47    }
48
49    // The value of the StopInfo depends on the StopReason.
50    // StopReason                  Meaning
51    // ----------------------------------------------
52    // eStopReasonBreakpoint       BreakpointSiteID
53    // eStopReasonSignal           Signal number
54    // eStopReasonWatchpoint       WatchpointLocationID
55    // eStopReasonPlanComplete     No significance
56
57    uint64_t
58    GetValue() const
59    {
60        return m_value;
61    }
62
63    virtual lldb::StopReason
64    GetStopReason () const = 0;
65
66    // ShouldStopSynchronous will get called before any thread plans are consulted, and if it says we should
67    // resume the target, then we will just immediately resume.  This should not run any code in or resume the
68    // target.
69
70    virtual bool
71    ShouldStopSynchronous (Event *event_ptr)
72    {
73        return true;
74    }
75
76    // If should stop returns false, check if we should notify of this event
77    virtual bool
78    ShouldNotify (Event *event_ptr)
79    {
80        return false;
81    }
82
83    virtual void
84    WillResume (lldb::StateType resume_state)
85    {
86        // By default, don't do anything
87    }
88
89    virtual const char *
90    GetDescription ()
91    {
92        return m_description.c_str();
93    }
94
95    virtual void
96    SetDescription (const char *desc_cstr)
97    {
98        if (desc_cstr && desc_cstr[0])
99            m_description.assign (desc_cstr);
100        else
101            m_description.clear();
102    }
103
104    // Sometimes the thread plan logic will know that it wants a given stop to stop or not,
105    // regardless of what the ordinary logic for that StopInfo would dictate.  The main example
106    // of this is the ThreadPlanCallFunction, which for instance knows - based on how that particular
107    // expression was executed - whether it wants all breakpoints to auto-continue or not.
108    // Use OverrideShouldStop on the StopInfo to implement this.
109
110    void
111    OverrideShouldStop (bool override_value)
112    {
113        m_override_set = true;
114        m_override_value = override_value;
115    }
116
117    bool
118    GetOverrideShouldStop()
119    {
120        return m_override_set;
121    }
122
123    bool
124    GetOverriddenShouldStopValue ()
125    {
126        return m_override_value;
127    }
128
129    static lldb::StopInfoSP
130    CreateStopReasonWithBreakpointSiteID (Thread &thread, lldb::break_id_t break_id);
131
132    // This creates a StopInfo for the thread where the should_stop is already set, and won't be recalculated.
133    static lldb::StopInfoSP
134    CreateStopReasonWithBreakpointSiteID (Thread &thread, lldb::break_id_t break_id, bool should_stop);
135
136    static lldb::StopInfoSP
137    CreateStopReasonWithWatchpointID (Thread &thread, lldb::break_id_t watch_id);
138
139    static lldb::StopInfoSP
140    CreateStopReasonWithSignal (Thread &thread, int signo);
141
142    static lldb::StopInfoSP
143    CreateStopReasonToTrace (Thread &thread);
144
145    static lldb::StopInfoSP
146    CreateStopReasonWithPlan (lldb::ThreadPlanSP &plan, lldb::ValueObjectSP return_valobj_sp);
147
148    static lldb::StopInfoSP
149    CreateStopReasonWithException (Thread &thread, const char *description);
150
151    static lldb::StopInfoSP
152    CreateStopReasonWithExec (Thread &thread);
153
154    static lldb::ValueObjectSP
155    GetReturnValueObject (lldb::StopInfoSP &stop_info_sp);
156
157protected:
158    // Perform any action that is associated with this stop.  This is done as the
159    // Event is removed from the event queue.  ProcessEventData::DoOnRemoval does the job.
160
161    virtual void
162    PerformAction (Event *event_ptr)
163    {
164    }
165
166    // Stop the thread by default. Subclasses can override this to allow
167    // the thread to continue if desired.  The ShouldStop method should not do anything
168    // that might run code.  If you need to run code when deciding whether to stop
169    // at this StopInfo, that must be done in the PerformAction.
170    // The PerformAction will always get called before the ShouldStop.  This is done by the
171    // ProcessEventData::DoOnRemoval, though the ThreadPlanBase needs to consult this later on.
172    virtual bool
173    ShouldStop (Event *event_ptr)
174    {
175        return true;
176    }
177
178    //------------------------------------------------------------------
179    // Classes that inherit from StackID can see and modify these
180    //------------------------------------------------------------------
181    lldb::ThreadWP  m_thread_wp;   // The thread corresponding to the stop reason.
182    uint32_t        m_stop_id;  // The process stop ID for which this stop info is valid
183    uint32_t        m_resume_id; // This is the resume ID when we made this stop ID.
184    uint64_t        m_value;    // A generic value that can be used for things pertaining to this stop info
185    std::string     m_description; // A textual description describing this stop.
186    bool            m_override_set;
187    bool            m_override_value;
188
189    // This determines whether the target has run since this stop info.
190    // N.B. running to evaluate a user expression does not count.
191    bool HasTargetRunSinceMe ();
192
193    // MakeStopInfoValid is necessary to allow saved stop infos to resurrect themselves as valid.
194    // It should only be used by Thread::RestoreThreadStateFromCheckpoint and to make sure the one-step
195    // needed for before-the-fact watchpoints does not prevent us from stopping
196    void
197    MakeStopInfoValid ();
198
199private:
200    friend class Thread;
201
202    DISALLOW_COPY_AND_ASSIGN (StopInfo);
203};
204
205} // namespace lldb_private
206
207#endif  // liblldb_StopInfo_h_
208