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