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