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
27 // "function" argument. If you plan to call GetReturnValueObject, then pass
28 // in the return type, otherwise just pass in an invalid CompilerType.
30 ThreadPlanCallFunction(Thread &thread, const Address &function,
31 const CompilerType &return_type,
32 llvm::ArrayRef<lldb::addr_t> args,
33 const EvaluateExpressionOptions &options);
35 ThreadPlanCallFunction(Thread &thread, const Address &function,
36 const EvaluateExpressionOptions &options);
38 ~ThreadPlanCallFunction() override;
40 void GetDescription(Stream *s, lldb::DescriptionLevel level) override;
42 bool ValidatePlan(Stream *error) override;
44 bool ShouldStop(Event *event_ptr) override;
46 Vote ShouldReportStop(Event *event_ptr) override;
48 bool StopOthers() override;
50 lldb::StateType GetPlanRunState() override;
52 void DidPush() override;
54 bool WillStop() override;
56 bool MischiefManaged() override;
58 // To get the return value from a function call you must create a
59 // lldb::ValueSP that contains a valid clang type in its context and call
60 // RequestReturnValue. The ValueSP will be stored and when the function is
61 // done executing, the object will check if there is a requested return
62 // value. If there is, the return value will be retrieved using the
63 // ABI::GetReturnValue() for the ABI in the process. Then after the thread
64 // plan is complete, you can call "GetReturnValue()" to retrieve the value
65 // that was extracted.
67 lldb::ValueObjectSP GetReturnValueObject() override {
68 return m_return_valobj_sp;
71 // Return the stack pointer that the function received on entry. Any stack
72 // address below this should be considered invalid after the function has
74 lldb::addr_t GetFunctionStackPointer() { return m_function_sp; }
76 // Classes that derive from FunctionCaller, and implement their own WillPop
77 // methods should call this so that the thread state gets restored if the
78 // plan gets discarded.
79 void WillPop() override;
81 // If the thread plan stops mid-course, this will be the stop reason that
82 // interrupted us. Once DoTakedown is called, this will be the real stop
83 // reason at the end of the function call. If it hasn't been set for one or
84 // the other of these reasons, we'll return the PrivateStopReason. This is
85 // needed because we want the CallFunction thread plans not to show up as the
86 // stop reason. But if something bad goes wrong, it is nice to be able to
87 // tell the user what really happened.
89 lldb::StopInfoSP GetRealStopInfo() override {
90 if (m_real_stop_info_sp)
91 return m_real_stop_info_sp;
93 return GetPrivateStopInfo();
96 lldb::addr_t GetStopAddress() { return m_stop_address; }
98 bool RestoreThreadState() override;
100 void ThreadDestroyed() override { m_takedown_done = true; }
102 void SetStopOthers(bool new_value) override;
105 void ReportRegisterState(const char *message);
107 bool DoPlanExplainsStop(Event *event_ptr) override;
109 virtual void SetReturnValue();
111 bool ConstructorSetup(Thread &thread, ABI *&abi,
112 lldb::addr_t &start_load_addr,
113 lldb::addr_t &function_load_addr);
115 virtual void DoTakedown(bool success);
117 void SetBreakpoints();
119 void ClearBreakpoints();
121 bool BreakpointsExplainStop();
124 bool m_stop_other_threads;
125 bool m_unwind_on_error;
126 bool m_ignore_breakpoints;
127 bool m_debug_execution;
128 bool m_trap_exceptions;
129 Address m_function_addr;
130 Address m_start_addr;
131 lldb::addr_t m_function_sp;
132 lldb::ThreadPlanSP m_subplan_sp;
133 LanguageRuntime *m_cxx_language_runtime;
134 LanguageRuntime *m_objc_language_runtime;
135 Thread::ThreadStateCheckpoint m_stored_thread_state;
137 m_real_stop_info_sp; // In general we want to hide call function
138 // thread plans, but for reporting purposes, it's
139 // nice to know the real stop reason. This gets set
141 StreamString m_constructor_errors;
142 lldb::ValueObjectSP m_return_valobj_sp; // If this contains a valid pointer,
143 // use the ABI to extract values when
145 bool m_takedown_done; // We want to ensure we only do the takedown once. This
147 bool m_should_clear_objc_exception_bp;
148 bool m_should_clear_cxx_exception_bp;
149 lldb::addr_t m_stop_address; // This is the address we stopped at. Also set
153 CompilerType m_return_type;
154 DISALLOW_COPY_AND_ASSIGN(ThreadPlanCallFunction);
157 } // namespace lldb_private
159 #endif // liblldb_ThreadPlanCallFunction_h_