1254721Semaste//===-- StopInfo.h ----------------------------------------------*- C++ -*-===//
2254721Semaste//
3254721Semaste//                     The LLVM Compiler Infrastructure
4254721Semaste//
5254721Semaste// This file is distributed under the University of Illinois Open Source
6254721Semaste// License. See LICENSE.TXT for details.
7254721Semaste//
8254721Semaste//===----------------------------------------------------------------------===//
9254721Semaste
10254721Semaste#ifndef liblldb_StopInfo_h_
11254721Semaste#define liblldb_StopInfo_h_
12254721Semaste
13254721Semaste// C Includes
14254721Semaste// C++ Includes
15254721Semaste#include <string>
16254721Semaste
17254721Semaste// Other libraries and framework includes
18254721Semaste// Project includes
19254721Semaste#include "lldb/lldb-public.h"
20254721Semaste#include "lldb/Target/Process.h"
21254721Semaste
22254721Semastenamespace lldb_private {
23254721Semaste
24254721Semasteclass StopInfo
25254721Semaste{
26254721Semaste    friend class Process::ProcessEventData;
27254721Semaste    friend class ThreadPlanBase;
28254721Semaste
29254721Semastepublic:
30254721Semaste    //------------------------------------------------------------------
31254721Semaste    // Constructors and Destructors
32254721Semaste    //------------------------------------------------------------------
33254721Semaste    StopInfo (Thread &thread, uint64_t value);
34254721Semaste
35254721Semaste    virtual ~StopInfo()
36254721Semaste    {
37254721Semaste    }
38254721Semaste
39254721Semaste
40254721Semaste    bool
41254721Semaste    IsValid () const;
42254721Semaste
43254721Semaste    void
44254721Semaste    SetThread (const lldb::ThreadSP &thread_sp)
45254721Semaste    {
46254721Semaste        m_thread_wp = thread_sp;
47254721Semaste    }
48254721Semaste
49254721Semaste    lldb::ThreadSP
50254721Semaste    GetThread() const
51254721Semaste    {
52254721Semaste        return m_thread_wp.lock();
53254721Semaste    }
54254721Semaste
55254721Semaste    // The value of the StopInfo depends on the StopReason.
56254721Semaste    // StopReason                  Meaning
57254721Semaste    // ----------------------------------------------
58254721Semaste    // eStopReasonBreakpoint       BreakpointSiteID
59254721Semaste    // eStopReasonSignal           Signal number
60254721Semaste    // eStopReasonWatchpoint       WatchpointLocationID
61254721Semaste    // eStopReasonPlanComplete     No significance
62254721Semaste
63254721Semaste    uint64_t
64254721Semaste    GetValue() const
65254721Semaste    {
66254721Semaste        return m_value;
67254721Semaste    }
68254721Semaste
69254721Semaste    virtual lldb::StopReason
70254721Semaste    GetStopReason () const = 0;
71254721Semaste
72254721Semaste    // ShouldStopSynchronous will get called before any thread plans are consulted, and if it says we should
73254721Semaste    // resume the target, then we will just immediately resume.  This should not run any code in or resume the
74254721Semaste    // target.
75254721Semaste
76254721Semaste    virtual bool
77254721Semaste    ShouldStopSynchronous (Event *event_ptr)
78254721Semaste    {
79254721Semaste        return true;
80254721Semaste    }
81254721Semaste
82254721Semaste    void
83254721Semaste    OverrideShouldNotify (bool override_value)
84254721Semaste    {
85254721Semaste        m_override_should_notify = override_value ? eLazyBoolYes : eLazyBoolNo;
86254721Semaste    }
87254721Semaste
88254721Semaste    // If should stop returns false, check if we should notify of this event
89254721Semaste    virtual bool
90254721Semaste    ShouldNotify (Event *event_ptr)
91254721Semaste    {
92254721Semaste        if (m_override_should_notify == eLazyBoolCalculate)
93254721Semaste            return DoShouldNotify (event_ptr);
94254721Semaste        else
95254721Semaste            return m_override_should_notify == eLazyBoolYes;
96254721Semaste    }
97254721Semaste
98254721Semaste    virtual void
99254721Semaste    WillResume (lldb::StateType resume_state)
100254721Semaste    {
101254721Semaste        // By default, don't do anything
102254721Semaste    }
103254721Semaste
104254721Semaste    virtual const char *
105254721Semaste    GetDescription ()
106254721Semaste    {
107254721Semaste        return m_description.c_str();
108254721Semaste    }
109254721Semaste
110254721Semaste    virtual void
111254721Semaste    SetDescription (const char *desc_cstr)
112254721Semaste    {
113254721Semaste        if (desc_cstr && desc_cstr[0])
114254721Semaste            m_description.assign (desc_cstr);
115254721Semaste        else
116254721Semaste            m_description.clear();
117254721Semaste    }
118254721Semaste
119254721Semaste    // Sometimes the thread plan logic will know that it wants a given stop to stop or not,
120254721Semaste    // regardless of what the ordinary logic for that StopInfo would dictate.  The main example
121254721Semaste    // of this is the ThreadPlanCallFunction, which for instance knows - based on how that particular
122254721Semaste    // expression was executed - whether it wants all breakpoints to auto-continue or not.
123254721Semaste    // Use OverrideShouldStop on the StopInfo to implement this.
124254721Semaste
125254721Semaste    void
126254721Semaste    OverrideShouldStop (bool override_value)
127254721Semaste    {
128254721Semaste        m_override_should_stop = override_value ? eLazyBoolYes : eLazyBoolNo;
129254721Semaste    }
130254721Semaste
131254721Semaste    bool
132254721Semaste    GetOverrideShouldStop()
133254721Semaste    {
134254721Semaste        return m_override_should_stop != eLazyBoolCalculate;
135254721Semaste    }
136254721Semaste
137254721Semaste    bool
138254721Semaste    GetOverriddenShouldStopValue ()
139254721Semaste    {
140254721Semaste        return m_override_should_stop == eLazyBoolYes;
141254721Semaste    }
142254721Semaste
143254721Semaste    static lldb::StopInfoSP
144254721Semaste    CreateStopReasonWithBreakpointSiteID (Thread &thread, lldb::break_id_t break_id);
145254721Semaste
146254721Semaste    // This creates a StopInfo for the thread where the should_stop is already set, and won't be recalculated.
147254721Semaste    static lldb::StopInfoSP
148254721Semaste    CreateStopReasonWithBreakpointSiteID (Thread &thread, lldb::break_id_t break_id, bool should_stop);
149254721Semaste
150254721Semaste    static lldb::StopInfoSP
151254721Semaste    CreateStopReasonWithWatchpointID (Thread &thread, lldb::break_id_t watch_id);
152254721Semaste
153254721Semaste    static lldb::StopInfoSP
154254721Semaste    CreateStopReasonWithSignal (Thread &thread, int signo);
155254721Semaste
156254721Semaste    static lldb::StopInfoSP
157254721Semaste    CreateStopReasonToTrace (Thread &thread);
158254721Semaste
159254721Semaste    static lldb::StopInfoSP
160254721Semaste    CreateStopReasonWithPlan (lldb::ThreadPlanSP &plan, lldb::ValueObjectSP return_valobj_sp);
161254721Semaste
162254721Semaste    static lldb::StopInfoSP
163254721Semaste    CreateStopReasonWithException (Thread &thread, const char *description);
164254721Semaste
165254721Semaste    static lldb::StopInfoSP
166254721Semaste    CreateStopReasonWithExec (Thread &thread);
167254721Semaste
168254721Semaste    static lldb::ValueObjectSP
169254721Semaste    GetReturnValueObject (lldb::StopInfoSP &stop_info_sp);
170254721Semaste
171254721Semasteprotected:
172254721Semaste    // Perform any action that is associated with this stop.  This is done as the
173254721Semaste    // Event is removed from the event queue.  ProcessEventData::DoOnRemoval does the job.
174254721Semaste
175254721Semaste    virtual void
176254721Semaste    PerformAction (Event *event_ptr)
177254721Semaste    {
178254721Semaste    }
179254721Semaste
180254721Semaste    virtual bool
181254721Semaste    DoShouldNotify (Event *event_ptr)
182254721Semaste    {
183254721Semaste        return false;
184254721Semaste    }
185254721Semaste
186254721Semaste    // Stop the thread by default. Subclasses can override this to allow
187254721Semaste    // the thread to continue if desired.  The ShouldStop method should not do anything
188254721Semaste    // that might run code.  If you need to run code when deciding whether to stop
189254721Semaste    // at this StopInfo, that must be done in the PerformAction.
190254721Semaste    // The PerformAction will always get called before the ShouldStop.  This is done by the
191254721Semaste    // ProcessEventData::DoOnRemoval, though the ThreadPlanBase needs to consult this later on.
192254721Semaste    virtual bool
193254721Semaste    ShouldStop (Event *event_ptr)
194254721Semaste    {
195254721Semaste        return true;
196254721Semaste    }
197254721Semaste
198254721Semaste    //------------------------------------------------------------------
199254721Semaste    // Classes that inherit from StackID can see and modify these
200254721Semaste    //------------------------------------------------------------------
201254721Semaste    lldb::ThreadWP  m_thread_wp;   // The thread corresponding to the stop reason.
202254721Semaste    uint32_t        m_stop_id;  // The process stop ID for which this stop info is valid
203254721Semaste    uint32_t        m_resume_id; // This is the resume ID when we made this stop ID.
204254721Semaste    uint64_t        m_value;    // A generic value that can be used for things pertaining to this stop info
205254721Semaste    std::string     m_description; // A textual description describing this stop.
206254721Semaste    LazyBool        m_override_should_notify;
207254721Semaste    LazyBool        m_override_should_stop;
208254721Semaste
209254721Semaste    // This determines whether the target has run since this stop info.
210254721Semaste    // N.B. running to evaluate a user expression does not count.
211254721Semaste    bool HasTargetRunSinceMe ();
212254721Semaste
213254721Semaste    // MakeStopInfoValid is necessary to allow saved stop infos to resurrect themselves as valid.
214254721Semaste    // It should only be used by Thread::RestoreThreadStateFromCheckpoint and to make sure the one-step
215254721Semaste    // needed for before-the-fact watchpoints does not prevent us from stopping
216254721Semaste    void
217254721Semaste    MakeStopInfoValid ();
218254721Semaste
219254721Semasteprivate:
220254721Semaste    friend class Thread;
221254721Semaste
222254721Semaste    DISALLOW_COPY_AND_ASSIGN (StopInfo);
223254721Semaste};
224254721Semaste
225254721Semaste} // namespace lldb_private
226254721Semaste
227254721Semaste#endif  // liblldb_StopInfo_h_
228