1 //===-- ThreadPlanCallFunction.h --------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef liblldb_ThreadPlanCallFunction_h_
11 #define liblldb_ThreadPlanCallFunction_h_
15 // Other libraries and framework includes
17 #include "lldb/lldb-private.h"
18 #include "lldb/Target/Thread.h"
19 #include "lldb/Target/ThreadPlan.h"
21 namespace lldb_private {
23 class ThreadPlanCallFunction : public ThreadPlan
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.
29 ThreadPlanCallFunction (Thread &thread,
30 const Address &function,
31 const ClangASTType &return_type,
33 bool stop_other_threads,
34 bool unwind_on_error = true,
35 bool ignore_breakpoints = false,
36 lldb::addr_t *this_arg = 0,
37 lldb::addr_t *cmd_arg = 0);
39 ThreadPlanCallFunction (Thread &thread,
40 const Address &function,
41 const ClangASTType &return_type,
42 bool stop_other_threads,
44 bool ignore_breakpoints,
45 lldb::addr_t *arg1_ptr = NULL,
46 lldb::addr_t *arg2_ptr = NULL,
47 lldb::addr_t *arg3_ptr = NULL,
48 lldb::addr_t *arg4_ptr = NULL,
49 lldb::addr_t *arg5_ptr = NULL,
50 lldb::addr_t *arg6_ptr = NULL);
53 ~ThreadPlanCallFunction ();
56 GetDescription (Stream *s, lldb::DescriptionLevel level);
59 ValidatePlan (Stream *error);
62 ShouldStop (Event *event_ptr);
65 ShouldReportStop(Event *event_ptr);
71 SetStopOthers (bool new_value);
73 virtual lldb::StateType
85 // To get the return value from a function call you must create a
86 // lldb::ValueSP that contains a valid clang type in its context and call
87 // RequestReturnValue. The ValueSP will be stored and when the function is
88 // done executing, the object will check if there is a requested return
89 // value. If there is, the return value will be retrieved using the
90 // ABI::GetReturnValue() for the ABI in the process. Then after the thread
91 // plan is complete, you can call "GetReturnValue()" to retrieve the value
92 // that was extracted.
94 virtual lldb::ValueObjectSP
95 GetReturnValueObject ()
97 return m_return_valobj_sp;
100 // Return the stack pointer that the function received
101 // on entry. Any stack address below this should be
102 // considered invalid after the function has been
105 GetFunctionStackPointer()
107 return m_function_sp;
110 // Classes that derive from ClangFunction, and implement
111 // their own WillPop methods should call this so that the
112 // thread state gets restored if the plan gets discarded.
116 // If the thread plan stops mid-course, this will be the stop reason that interrupted us.
117 // Once DoTakedown is called, this will be the real stop reason at the end of the function call.
118 // If it hasn't been set for one or the other of these reasons, we'll return the PrivateStopReason.
119 // This is needed because we want the CallFunction thread plans not to show up as the stop reason.
120 // But if something bad goes wrong, it is nice to be able to tell the user what really happened.
122 virtual lldb::StopInfoSP
125 if (m_real_stop_info_sp)
126 return m_real_stop_info_sp;
128 return GetPrivateStopInfo ();
134 return m_stop_address;
138 RestoreThreadState();
141 void ReportRegisterState (const char *message);
144 DoPlanExplainsStop (Event *event_ptr);
149 ConstructorSetup (Thread &thread,
151 lldb::addr_t &start_load_addr,
152 lldb::addr_t &function_load_addr);
155 DoTakedown (bool success);
164 BreakpointsExplainStop ();
167 bool m_stop_other_threads;
168 Address m_function_addr;
169 Address m_start_addr;
170 lldb::addr_t m_function_sp;
171 Thread::RegisterCheckpoint m_register_backup;
172 lldb::ThreadPlanSP m_subplan_sp;
173 LanguageRuntime *m_cxx_language_runtime;
174 LanguageRuntime *m_objc_language_runtime;
175 Thread::ThreadStateCheckpoint m_stored_thread_state;
176 lldb::StopInfoSP m_real_stop_info_sp; // In general we want to hide call function
177 // thread plans, but for reporting purposes,
178 // it's nice to know the real stop reason.
179 // This gets set in DoTakedown.
180 StreamString m_constructor_errors;
181 ClangASTType m_return_type;
182 lldb::ValueObjectSP m_return_valobj_sp; // If this contains a valid pointer, use the ABI to extract values when complete
183 bool m_takedown_done; // We want to ensure we only do the takedown once. This ensures that.
184 lldb::addr_t m_stop_address; // This is the address we stopped at. Also set in DoTakedown;
185 bool m_unwind_on_error;
186 bool m_ignore_breakpoints;
188 DISALLOW_COPY_AND_ASSIGN (ThreadPlanCallFunction);
191 } // namespace lldb_private
193 #endif // liblldb_ThreadPlanCallFunction_h_