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/Target/Thread.h"
18 #include "lldb/Target/ThreadPlan.h"
19 #include "lldb/lldb-private.h"
21 #include "llvm/ADT/ArrayRef.h"
23 namespace lldb_private {
25 class ThreadPlanCallFunction : public ThreadPlan {
26 // Create a thread plan to call a function at the address passed in the
28 // argument. If you plan to call GetReturnValueObject, then pass in the
29 // return type, otherwise just pass in an invalid CompilerType.
31 ThreadPlanCallFunction(Thread &thread, const Address &function,
32 const CompilerType &return_type,
33 llvm::ArrayRef<lldb::addr_t> args,
34 const EvaluateExpressionOptions &options);
36 ThreadPlanCallFunction(Thread &thread, const Address &function,
37 const EvaluateExpressionOptions &options);
39 ~ThreadPlanCallFunction() override;
41 void GetDescription(Stream *s, lldb::DescriptionLevel level) override;
43 bool ValidatePlan(Stream *error) override;
45 bool ShouldStop(Event *event_ptr) override;
47 Vote ShouldReportStop(Event *event_ptr) override;
49 bool StopOthers() override;
51 lldb::StateType GetPlanRunState() override;
53 void DidPush() override;
55 bool WillStop() override;
57 bool MischiefManaged() override;
59 // To get the return value from a function call you must create a
60 // lldb::ValueSP that contains a valid clang type in its context and call
61 // RequestReturnValue. The ValueSP will be stored and when the function is
62 // done executing, the object will check if there is a requested return
63 // value. If there is, the return value will be retrieved using the
64 // ABI::GetReturnValue() for the ABI in the process. Then after the thread
65 // plan is complete, you can call "GetReturnValue()" to retrieve the value
66 // that was extracted.
68 lldb::ValueObjectSP GetReturnValueObject() override {
69 return m_return_valobj_sp;
72 // Return the stack pointer that the function received
73 // on entry. Any stack address below this should be
74 // considered invalid after the function has been
76 lldb::addr_t GetFunctionStackPointer() { return m_function_sp; }
78 // Classes that derive from FunctionCaller, and implement
79 // their own WillPop methods should call this so that the
80 // thread state gets restored if the plan gets discarded.
81 void WillPop() override;
83 // If the thread plan stops mid-course, this will be the stop reason that
85 // Once DoTakedown is called, this will be the real stop reason at the end of
87 // If it hasn't been set for one or the other of these reasons, we'll return
88 // the PrivateStopReason.
89 // This is needed because we want the CallFunction thread plans not to show up
90 // as the stop reason.
91 // But if something bad goes wrong, it is nice to be able to tell the user
92 // what really happened.
94 lldb::StopInfoSP GetRealStopInfo() override {
95 if (m_real_stop_info_sp)
96 return m_real_stop_info_sp;
98 return GetPrivateStopInfo();
101 lldb::addr_t GetStopAddress() { return m_stop_address; }
103 bool RestoreThreadState() override;
105 void ThreadDestroyed() override { m_takedown_done = true; }
107 void SetStopOthers(bool new_value) override;
110 void ReportRegisterState(const char *message);
112 bool DoPlanExplainsStop(Event *event_ptr) override;
114 virtual void SetReturnValue();
116 bool ConstructorSetup(Thread &thread, ABI *&abi,
117 lldb::addr_t &start_load_addr,
118 lldb::addr_t &function_load_addr);
120 virtual void DoTakedown(bool success);
122 void SetBreakpoints();
124 void ClearBreakpoints();
126 bool BreakpointsExplainStop();
129 bool m_stop_other_threads;
130 bool m_unwind_on_error;
131 bool m_ignore_breakpoints;
132 bool m_debug_execution;
133 bool m_trap_exceptions;
134 Address m_function_addr;
135 Address m_start_addr;
136 lldb::addr_t m_function_sp;
137 lldb::ThreadPlanSP m_subplan_sp;
138 LanguageRuntime *m_cxx_language_runtime;
139 LanguageRuntime *m_objc_language_runtime;
140 Thread::ThreadStateCheckpoint m_stored_thread_state;
142 m_real_stop_info_sp; // In general we want to hide call function
143 // thread plans, but for reporting purposes,
144 // it's nice to know the real stop reason.
145 // This gets set in DoTakedown.
146 StreamString m_constructor_errors;
147 lldb::ValueObjectSP m_return_valobj_sp; // If this contains a valid pointer,
148 // use the ABI to extract values when
150 bool m_takedown_done; // We want to ensure we only do the takedown once. This
152 bool m_should_clear_objc_exception_bp;
153 bool m_should_clear_cxx_exception_bp;
154 lldb::addr_t m_stop_address; // This is the address we stopped at. Also set
158 CompilerType m_return_type;
159 DISALLOW_COPY_AND_ASSIGN(ThreadPlanCallFunction);
162 } // namespace lldb_private
164 #endif // liblldb_ThreadPlanCallFunction_h_