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