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