StopInfo.h revision 280031
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 23namespace lldb_private { 24 25class StopInfo 26{ 27 friend class Process::ProcessEventData; 28 friend class ThreadPlanBase; 29 30public: 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 // Sometimes the thread plan logic will know that it wants a given stop to stop or not, 121 // regardless of what the ordinary logic for that StopInfo would dictate. The main example 122 // of this is the ThreadPlanCallFunction, which for instance knows - based on how that particular 123 // expression was executed - whether it wants all breakpoints to auto-continue or not. 124 // Use OverrideShouldStop on the StopInfo to implement this. 125 126 void 127 OverrideShouldStop (bool override_value) 128 { 129 m_override_should_stop = override_value ? eLazyBoolYes : eLazyBoolNo; 130 } 131 132 bool 133 GetOverrideShouldStop() 134 { 135 return m_override_should_stop != eLazyBoolCalculate; 136 } 137 138 bool 139 GetOverriddenShouldStopValue () 140 { 141 return m_override_should_stop == eLazyBoolYes; 142 } 143 144 StructuredData::ObjectSP 145 GetExtendedInfo () 146 { 147 return m_extended_info; 148 } 149 150 static lldb::StopInfoSP 151 CreateStopReasonWithBreakpointSiteID (Thread &thread, lldb::break_id_t break_id); 152 153 // This creates a StopInfo for the thread where the should_stop is already set, and won't be recalculated. 154 static lldb::StopInfoSP 155 CreateStopReasonWithBreakpointSiteID (Thread &thread, lldb::break_id_t break_id, bool should_stop); 156 157 static lldb::StopInfoSP 158 CreateStopReasonWithWatchpointID (Thread &thread, lldb::break_id_t watch_id); 159 160 static lldb::StopInfoSP 161 CreateStopReasonWithSignal (Thread &thread, int signo); 162 163 static lldb::StopInfoSP 164 CreateStopReasonToTrace (Thread &thread); 165 166 static lldb::StopInfoSP 167 CreateStopReasonWithPlan (lldb::ThreadPlanSP &plan, 168 lldb::ValueObjectSP return_valobj_sp, 169 lldb::ClangExpressionVariableSP expression_variable_sp); 170 171 static lldb::StopInfoSP 172 CreateStopReasonWithException (Thread &thread, const char *description); 173 174 static lldb::StopInfoSP 175 CreateStopReasonWithExec (Thread &thread); 176 177 static lldb::ValueObjectSP 178 GetReturnValueObject (lldb::StopInfoSP &stop_info_sp); 179 180 static lldb::ClangExpressionVariableSP 181 GetExpressionVariable (lldb::StopInfoSP &stop_info_sp); 182 183protected: 184 // Perform any action that is associated with this stop. This is done as the 185 // Event is removed from the event queue. ProcessEventData::DoOnRemoval does the job. 186 187 virtual void 188 PerformAction (Event *event_ptr) 189 { 190 } 191 192 virtual bool 193 DoShouldNotify (Event *event_ptr) 194 { 195 return false; 196 } 197 198 // Stop the thread by default. Subclasses can override this to allow 199 // the thread to continue if desired. The ShouldStop method should not do anything 200 // that might run code. If you need to run code when deciding whether to stop 201 // at this StopInfo, that must be done in the PerformAction. 202 // The PerformAction will always get called before the ShouldStop. This is done by the 203 // ProcessEventData::DoOnRemoval, though the ThreadPlanBase needs to consult this later on. 204 virtual bool 205 ShouldStop (Event *event_ptr) 206 { 207 return true; 208 } 209 210 //------------------------------------------------------------------ 211 // Classes that inherit from StackID can see and modify these 212 //------------------------------------------------------------------ 213 lldb::ThreadWP m_thread_wp; // The thread corresponding to the stop reason. 214 uint32_t m_stop_id; // The process stop ID for which this stop info is valid 215 uint32_t m_resume_id; // This is the resume ID when we made this stop ID. 216 uint64_t m_value; // A generic value that can be used for things pertaining to this stop info 217 std::string m_description; // A textual description describing this stop. 218 LazyBool m_override_should_notify; 219 LazyBool m_override_should_stop; 220 221 StructuredData::ObjectSP m_extended_info; // The extended info for this stop info 222 223 // This determines whether the target has run since this stop info. 224 // N.B. running to evaluate a user expression does not count. 225 bool HasTargetRunSinceMe (); 226 227 // MakeStopInfoValid is necessary to allow saved stop infos to resurrect themselves as valid. 228 // It should only be used by Thread::RestoreThreadStateFromCheckpoint and to make sure the one-step 229 // needed for before-the-fact watchpoints does not prevent us from stopping 230 void 231 MakeStopInfoValid (); 232 233private: 234 friend class Thread; 235 236 DISALLOW_COPY_AND_ASSIGN (StopInfo); 237}; 238 239} // namespace lldb_private 240 241#endif // liblldb_StopInfo_h_ 242