Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:42:56

0001 //===-- ThreadPlanCallFunction.h --------------------------------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef LLDB_TARGET_THREADPLANCALLFUNCTION_H
0010 #define LLDB_TARGET_THREADPLANCALLFUNCTION_H
0011 
0012 #include "lldb/Target/Thread.h"
0013 #include "lldb/Target/ThreadPlan.h"
0014 #include "lldb/lldb-private.h"
0015 
0016 #include "llvm/ADT/ArrayRef.h"
0017 
0018 namespace lldb_private {
0019 
0020 class ThreadPlanCallFunction : public ThreadPlan {
0021   // Create a thread plan to call a function at the address passed in the
0022   // "function" argument.  If you plan to call GetReturnValueObject, then pass
0023   // in the return type, otherwise just pass in an invalid CompilerType.
0024 public:
0025   ThreadPlanCallFunction(Thread &thread, const Address &function,
0026                          const CompilerType &return_type,
0027                          llvm::ArrayRef<lldb::addr_t> args,
0028                          const EvaluateExpressionOptions &options);
0029 
0030   ThreadPlanCallFunction(Thread &thread, const Address &function,
0031                          const EvaluateExpressionOptions &options);
0032 
0033   ~ThreadPlanCallFunction() override;
0034 
0035   void GetDescription(Stream *s, lldb::DescriptionLevel level) override;
0036 
0037   bool ValidatePlan(Stream *error) override;
0038 
0039   bool ShouldStop(Event *event_ptr) override;
0040 
0041   Vote ShouldReportStop(Event *event_ptr) override;
0042 
0043   bool StopOthers() override;
0044 
0045   lldb::StateType GetPlanRunState() override;
0046 
0047   void DidPush() override;
0048 
0049   bool WillStop() override;
0050 
0051   bool MischiefManaged() override;
0052 
0053   // To get the return value from a function call you must create a
0054   // lldb::ValueSP that contains a valid clang type in its context and call
0055   // RequestReturnValue. The ValueSP will be stored and when the function is
0056   // done executing, the object will check if there is a requested return
0057   // value. If there is, the return value will be retrieved using the
0058   // ABI::GetReturnValue() for the ABI in the process. Then after the thread
0059   // plan is complete, you can call "GetReturnValue()" to retrieve the value
0060   // that was extracted.
0061 
0062   lldb::ValueObjectSP GetReturnValueObject() override {
0063     return m_return_valobj_sp;
0064   }
0065 
0066   // Return the stack pointer that the function received on entry.  Any stack
0067   // address below this should be considered invalid after the function has
0068   // been cleaned up.
0069   lldb::addr_t GetFunctionStackPointer() { return m_function_sp; }
0070 
0071   // Classes that derive from FunctionCaller, and implement their own DidPop
0072   // methods should call this so that the thread state gets restored if the
0073   // plan gets discarded.
0074   void DidPop() override;
0075 
0076   // If the thread plan stops mid-course, this will be the stop reason that
0077   // interrupted us. Once DoTakedown is called, this will be the real stop
0078   // reason at the end of the function call. If it hasn't been set for one or
0079   // the other of these reasons, we'll return the PrivateStopReason. This is
0080   // needed because we want the CallFunction thread plans not to show up as the
0081   // stop reason. But if something bad goes wrong, it is nice to be able to
0082   // tell the user what really happened.
0083 
0084   virtual lldb::StopInfoSP GetRealStopInfo() {
0085     if (m_real_stop_info_sp)
0086       return m_real_stop_info_sp;
0087     else
0088       return GetPrivateStopInfo();
0089   }
0090 
0091   lldb::addr_t GetStopAddress() { return m_stop_address; }
0092 
0093   void RestoreThreadState() override;
0094 
0095   void ThreadDestroyed() override { m_takedown_done = true; }
0096 
0097   void SetStopOthers(bool new_value) override;
0098 
0099 protected:
0100   void ReportRegisterState(const char *message);
0101 
0102   bool DoPlanExplainsStop(Event *event_ptr) override;
0103 
0104   virtual void SetReturnValue();
0105 
0106   bool ConstructorSetup(Thread &thread, ABI *&abi,
0107                         lldb::addr_t &start_load_addr,
0108                         lldb::addr_t &function_load_addr);
0109 
0110   virtual void DoTakedown(bool success);
0111 
0112   void SetBreakpoints();
0113 
0114   void ClearBreakpoints();
0115 
0116   bool BreakpointsExplainStop();
0117 
0118   bool m_valid;
0119   bool m_stop_other_threads;
0120   bool m_unwind_on_error;
0121   bool m_ignore_breakpoints;
0122   bool m_debug_execution;
0123   bool m_trap_exceptions;
0124   Address m_function_addr;
0125   Address m_start_addr;
0126   lldb::addr_t m_function_sp;
0127   lldb::ThreadPlanSP m_subplan_sp;
0128   LanguageRuntime *m_cxx_language_runtime;
0129   LanguageRuntime *m_objc_language_runtime;
0130   Thread::ThreadStateCheckpoint m_stored_thread_state;
0131   lldb::StopInfoSP
0132       m_real_stop_info_sp; // In general we want to hide call function
0133                            // thread plans, but for reporting purposes, it's
0134                            // nice to know the real stop reason. This gets set
0135                            // in DoTakedown.
0136   StreamString m_constructor_errors;
0137   lldb::ValueObjectSP m_return_valobj_sp; // If this contains a valid pointer,
0138                                           // use the ABI to extract values when
0139                                           // complete
0140   bool m_takedown_done; // We want to ensure we only do the takedown once.  This
0141                         // ensures that.
0142   bool m_should_clear_objc_exception_bp;
0143   bool m_should_clear_cxx_exception_bp;
0144   lldb::addr_t m_stop_address; // This is the address we stopped at.  Also set
0145                                // in DoTakedown;
0146 
0147 private:
0148   CompilerType m_return_type;
0149   ThreadPlanCallFunction(const ThreadPlanCallFunction &) = delete;
0150   const ThreadPlanCallFunction &
0151   operator=(const ThreadPlanCallFunction &) = delete;
0152 };
0153 
0154 } // namespace lldb_private
0155 
0156 #endif // LLDB_TARGET_THREADPLANCALLFUNCTION_H