ThreadPlanCallFunction.h revision 263367
1//===-- ThreadPlanCallFunction.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_ThreadPlanCallFunction_h_ 11#define liblldb_ThreadPlanCallFunction_h_ 12 13// C Includes 14// C++ Includes 15// Other libraries and framework includes 16// Project includes 17#include "lldb/lldb-private.h" 18#include "lldb/Target/Thread.h" 19#include "lldb/Target/ThreadPlan.h" 20 21#include "llvm/ADT/ArrayRef.h" 22 23namespace lldb_private { 24 25class ThreadPlanCallFunction : public ThreadPlan 26{ 27 // Create a thread plan to call a function at the address passed in the "function" 28 // argument. If you plan to call GetReturnValueObject, then pass in the 29 // return type, otherwise just pass in an invalid ClangASTType. 30public: 31 ThreadPlanCallFunction (Thread &thread, 32 const Address &function, 33 const ClangASTType &return_type, 34 llvm::ArrayRef<lldb::addr_t> args, 35 const EvaluateExpressionOptions &options); 36 37 virtual 38 ~ThreadPlanCallFunction (); 39 40 virtual void 41 GetDescription (Stream *s, lldb::DescriptionLevel level); 42 43 virtual bool 44 ValidatePlan (Stream *error); 45 46 virtual bool 47 ShouldStop (Event *event_ptr); 48 49 virtual Vote 50 ShouldReportStop(Event *event_ptr); 51 52 virtual bool 53 StopOthers (); 54 55 virtual void 56 SetStopOthers (bool new_value); 57 58 virtual lldb::StateType 59 GetPlanRunState (); 60 61 virtual void 62 DidPush (); 63 64 virtual bool 65 WillStop (); 66 67 virtual bool 68 MischiefManaged (); 69 70 // To get the return value from a function call you must create a 71 // lldb::ValueSP that contains a valid clang type in its context and call 72 // RequestReturnValue. The ValueSP will be stored and when the function is 73 // done executing, the object will check if there is a requested return 74 // value. If there is, the return value will be retrieved using the 75 // ABI::GetReturnValue() for the ABI in the process. Then after the thread 76 // plan is complete, you can call "GetReturnValue()" to retrieve the value 77 // that was extracted. 78 79 virtual lldb::ValueObjectSP 80 GetReturnValueObject () 81 { 82 return m_return_valobj_sp; 83 } 84 85 // Return the stack pointer that the function received 86 // on entry. Any stack address below this should be 87 // considered invalid after the function has been 88 // cleaned up. 89 lldb::addr_t 90 GetFunctionStackPointer() 91 { 92 return m_function_sp; 93 } 94 95 // Classes that derive from ClangFunction, and implement 96 // their own WillPop methods should call this so that the 97 // thread state gets restored if the plan gets discarded. 98 virtual void 99 WillPop (); 100 101 // If the thread plan stops mid-course, this will be the stop reason that interrupted us. 102 // Once DoTakedown is called, this will be the real stop reason at the end of the function call. 103 // If it hasn't been set for one or the other of these reasons, we'll return the PrivateStopReason. 104 // This is needed because we want the CallFunction thread plans not to show up as the stop reason. 105 // But if something bad goes wrong, it is nice to be able to tell the user what really happened. 106 107 virtual lldb::StopInfoSP 108 GetRealStopInfo() 109 { 110 if (m_real_stop_info_sp) 111 return m_real_stop_info_sp; 112 else 113 return GetPrivateStopInfo (); 114 } 115 116 lldb::addr_t 117 GetStopAddress () 118 { 119 return m_stop_address; 120 } 121 122 virtual bool 123 RestoreThreadState(); 124 125 virtual void 126 ThreadDestroyed () 127 { 128 m_takedown_done = true; 129 } 130 131protected: 132 void ReportRegisterState (const char *message); 133 134 virtual bool 135 DoPlanExplainsStop (Event *event_ptr); 136 137private: 138 139 bool 140 ConstructorSetup (Thread &thread, 141 ABI *& abi, 142 lldb::addr_t &start_load_addr, 143 lldb::addr_t &function_load_addr); 144 145 void 146 DoTakedown (bool success); 147 148 void 149 SetBreakpoints (); 150 151 void 152 ClearBreakpoints (); 153 154 bool 155 BreakpointsExplainStop (); 156 157 bool m_valid; 158 bool m_stop_other_threads; 159 bool m_unwind_on_error; 160 bool m_ignore_breakpoints; 161 bool m_debug_execution; 162 bool m_trap_exceptions; 163 Address m_function_addr; 164 Address m_start_addr; 165 lldb::addr_t m_function_sp; 166 lldb::ThreadPlanSP m_subplan_sp; 167 LanguageRuntime *m_cxx_language_runtime; 168 LanguageRuntime *m_objc_language_runtime; 169 Thread::ThreadStateCheckpoint m_stored_thread_state; 170 lldb::StopInfoSP m_real_stop_info_sp; // In general we want to hide call function 171 // thread plans, but for reporting purposes, 172 // it's nice to know the real stop reason. 173 // This gets set in DoTakedown. 174 StreamString m_constructor_errors; 175 ClangASTType m_return_type; 176 lldb::ValueObjectSP m_return_valobj_sp; // If this contains a valid pointer, use the ABI to extract values when complete 177 bool m_takedown_done; // We want to ensure we only do the takedown once. This ensures that. 178 bool m_should_clear_objc_exception_bp; 179 bool m_should_clear_cxx_exception_bp; 180 lldb::addr_t m_stop_address; // This is the address we stopped at. Also set in DoTakedown; 181 182 DISALLOW_COPY_AND_ASSIGN (ThreadPlanCallFunction); 183}; 184 185} // namespace lldb_private 186 187#endif // liblldb_ThreadPlanCallFunction_h_ 188