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 #include "llvm/ADT/ArrayRef.h"
23 namespace lldb_private {
25 class ThreadPlanCallFunction : public ThreadPlan
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.
31 ThreadPlanCallFunction (Thread &thread,
32 const Address &function,
33 const ClangASTType &return_type,
34 llvm::ArrayRef<lldb::addr_t> args,
35 const EvaluateExpressionOptions &options);
38 ~ThreadPlanCallFunction ();
41 GetDescription (Stream *s, lldb::DescriptionLevel level);
44 ValidatePlan (Stream *error);
47 ShouldStop (Event *event_ptr);
50 ShouldReportStop(Event *event_ptr);
56 SetStopOthers (bool new_value);
58 virtual lldb::StateType
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.
79 virtual lldb::ValueObjectSP
80 GetReturnValueObject ()
82 return m_return_valobj_sp;
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
90 GetFunctionStackPointer()
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.
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.
107 virtual lldb::StopInfoSP
110 if (m_real_stop_info_sp)
111 return m_real_stop_info_sp;
113 return GetPrivateStopInfo ();
119 return m_stop_address;
123 RestoreThreadState();
128 m_takedown_done = true;
132 void ReportRegisterState (const char *message);
135 DoPlanExplainsStop (Event *event_ptr);
140 ConstructorSetup (Thread &thread,
142 lldb::addr_t &start_load_addr,
143 lldb::addr_t &function_load_addr);
146 DoTakedown (bool success);
155 BreakpointsExplainStop ();
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;
182 DISALLOW_COPY_AND_ASSIGN (ThreadPlanCallFunction);
185 } // namespace lldb_private
187 #endif // liblldb_ThreadPlanCallFunction_h_