Back to home page

EIC code displayed by LXR

 
 

    


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

0001 //===-- ABI.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_ABI_H
0010 #define LLDB_TARGET_ABI_H
0011 
0012 #include "lldb/Core/PluginInterface.h"
0013 #include "lldb/Symbol/UnwindPlan.h"
0014 #include "lldb/Target/DynamicRegisterInfo.h"
0015 #include "lldb/Utility/Status.h"
0016 #include "lldb/lldb-private.h"
0017 
0018 #include "llvm/ADT/ArrayRef.h"
0019 #include "llvm/MC/MCRegisterInfo.h"
0020 
0021 namespace llvm {
0022 class Type;
0023 }
0024 
0025 namespace lldb_private {
0026 
0027 class ABI : public PluginInterface {
0028 public:
0029   struct CallArgument {
0030     enum eType {
0031       HostPointer = 0, /* pointer to host data */
0032       TargetValue,     /* value is on the target or literal */
0033     };
0034     eType type;  /* value of eType */
0035     size_t size; /* size in bytes of this argument */
0036 
0037     lldb::addr_t value;                 /* literal value */
0038     std::unique_ptr<uint8_t[]> data_up; /* host data pointer */
0039   };
0040 
0041   ~ABI() override;
0042 
0043   virtual size_t GetRedZoneSize() const = 0;
0044 
0045   virtual bool PrepareTrivialCall(lldb_private::Thread &thread, lldb::addr_t sp,
0046                                   lldb::addr_t functionAddress,
0047                                   lldb::addr_t returnAddress,
0048                                   llvm::ArrayRef<lldb::addr_t> args) const = 0;
0049 
0050   // Prepare trivial call used from ThreadPlanFunctionCallUsingABI
0051   // AD:
0052   //  . Because i don't want to change other ABI's this is not declared pure
0053   //  virtual.
0054   //    The dummy implementation will simply fail.  Only HexagonABI will
0055   //    currently
0056   //    use this method.
0057   //  . Two PrepareTrivialCall's is not good design so perhaps this should be
0058   //  combined.
0059   //
0060   virtual bool PrepareTrivialCall(lldb_private::Thread &thread, lldb::addr_t sp,
0061                                   lldb::addr_t functionAddress,
0062                                   lldb::addr_t returnAddress,
0063                                   llvm::Type &prototype,
0064                                   llvm::ArrayRef<CallArgument> args) const;
0065 
0066   virtual bool GetArgumentValues(Thread &thread, ValueList &values) const = 0;
0067 
0068   lldb::ValueObjectSP GetReturnValueObject(Thread &thread, CompilerType &type,
0069                                            bool persistent = true) const;
0070 
0071   // specialized to work with llvm IR types
0072   lldb::ValueObjectSP GetReturnValueObject(Thread &thread, llvm::Type &type,
0073                                            bool persistent = true) const;
0074 
0075   // Set the Return value object in the current frame as though a function with
0076   virtual Status SetReturnValueObject(lldb::StackFrameSP &frame_sp,
0077                                       lldb::ValueObjectSP &new_value) = 0;
0078 
0079 protected:
0080   // This is the method the ABI will call to actually calculate the return
0081   // value. Don't put it in a persistent value object, that will be done by the
0082   // ABI::GetReturnValueObject.
0083   virtual lldb::ValueObjectSP
0084   GetReturnValueObjectImpl(Thread &thread, CompilerType &ast_type) const = 0;
0085 
0086   // specialized to work with llvm IR types
0087   virtual lldb::ValueObjectSP
0088   GetReturnValueObjectImpl(Thread &thread, llvm::Type &ir_type) const;
0089 
0090   /// Request to get a Process shared pointer.
0091   ///
0092   /// This ABI object may not have been created with a Process object,
0093   /// or the Process object may no longer be alive.  Be sure to handle
0094   /// the case where the shared pointer returned does not have an
0095   /// object inside it.
0096   lldb::ProcessSP GetProcessSP() const { return m_process_wp.lock(); }
0097 
0098 public:
0099   virtual bool CreateFunctionEntryUnwindPlan(UnwindPlan &unwind_plan) = 0;
0100 
0101   virtual bool CreateDefaultUnwindPlan(UnwindPlan &unwind_plan) = 0;
0102 
0103   virtual bool RegisterIsVolatile(const RegisterInfo *reg_info) = 0;
0104 
0105   virtual bool GetFallbackRegisterLocation(
0106       const RegisterInfo *reg_info,
0107       UnwindPlan::Row::AbstractRegisterLocation &unwind_regloc);
0108 
0109   // Should take a look at a call frame address (CFA) which is just the stack
0110   // pointer value upon entry to a function. ABIs usually impose alignment
0111   // restrictions (4, 8 or 16 byte aligned), and zero is usually not allowed.
0112   // This function should return true if "cfa" is valid call frame address for
0113   // the ABI, and false otherwise. This is used by the generic stack frame
0114   // unwinding code to help determine when a stack ends.
0115   virtual bool CallFrameAddressIsValid(lldb::addr_t cfa) = 0;
0116 
0117   // Validates a possible PC value and returns true if an opcode can be at
0118   // "pc".
0119   virtual bool CodeAddressIsValid(lldb::addr_t pc) = 0;
0120 
0121   /// Some targets might use bits in a code address to indicate a mode switch.
0122   /// ARM uses bit zero to signify a code address is thumb, so any ARM ABI
0123   /// plug-ins would strip those bits.
0124   /// @{
0125   virtual lldb::addr_t FixCodeAddress(lldb::addr_t pc);
0126   virtual lldb::addr_t FixDataAddress(lldb::addr_t pc);
0127   /// @}
0128 
0129   /// Use this method when you do not know, or do not care what kind of address
0130   /// you are fixing. On platforms where there would be a difference between the
0131   /// two types, it will pick the safest option.
0132   ///
0133   /// Its purpose is to signal that no specific choice was made and provide an
0134   /// alternative to randomly picking FixCode/FixData address. Which could break
0135   /// platforms where there is a difference (only Arm Thumb at this time).
0136   virtual lldb::addr_t FixAnyAddress(lldb::addr_t pc) {
0137     // On Arm Thumb fixing a code address zeroes the bottom bit, so FixData is
0138     // the safe choice. On any other platform (so far) code and data addresses
0139     // are fixed in the same way.
0140     return FixDataAddress(pc);
0141   }
0142 
0143   llvm::MCRegisterInfo &GetMCRegisterInfo() { return *m_mc_register_info_up; }
0144 
0145   virtual void
0146   AugmentRegisterInfo(std::vector<DynamicRegisterInfo::Register> &regs) = 0;
0147 
0148   virtual bool GetPointerReturnRegister(const char *&name) { return false; }
0149 
0150   virtual uint64_t GetStackFrameSize() { return 512 * 1024; }
0151 
0152   static lldb::ABISP FindPlugin(lldb::ProcessSP process_sp, const ArchSpec &arch);
0153 
0154 protected:
0155   ABI(lldb::ProcessSP process_sp, std::unique_ptr<llvm::MCRegisterInfo> info_up)
0156       : m_process_wp(process_sp), m_mc_register_info_up(std::move(info_up)) {
0157     assert(m_mc_register_info_up && "ABI must have MCRegisterInfo");
0158   }
0159 
0160   /// Utility function to construct a MCRegisterInfo using the ArchSpec triple.
0161   /// Plugins wishing to customize the construction can construct the
0162   /// MCRegisterInfo themselves.
0163   static std::unique_ptr<llvm::MCRegisterInfo>
0164   MakeMCRegisterInfo(const ArchSpec &arch);
0165 
0166   lldb::ProcessWP m_process_wp;
0167   std::unique_ptr<llvm::MCRegisterInfo> m_mc_register_info_up;
0168 
0169 private:
0170   ABI(const ABI &) = delete;
0171   const ABI &operator=(const ABI &) = delete;
0172 };
0173 
0174 class RegInfoBasedABI : public ABI {
0175 public:
0176   void AugmentRegisterInfo(
0177       std::vector<DynamicRegisterInfo::Register> &regs) override;
0178 
0179 protected:
0180   using ABI::ABI;
0181 
0182   bool GetRegisterInfoByName(llvm::StringRef name, RegisterInfo &info);
0183 
0184   virtual const RegisterInfo *GetRegisterInfoArray(uint32_t &count) = 0;
0185 };
0186 
0187 class MCBasedABI : public ABI {
0188 public:
0189   void AugmentRegisterInfo(
0190       std::vector<DynamicRegisterInfo::Register> &regs) override;
0191 
0192   /// If the register name is of the form "<from_prefix>[<number>]" then change
0193   /// the name to "<to_prefix>[<number>]". Otherwise, leave the name unchanged.
0194   static void MapRegisterName(std::string &reg, llvm::StringRef from_prefix,
0195                               llvm::StringRef to_prefix);
0196 
0197 protected:
0198   using ABI::ABI;
0199 
0200   /// Return eh_frame and dwarf numbers for the given register.
0201   virtual std::pair<uint32_t, uint32_t> GetEHAndDWARFNums(llvm::StringRef reg);
0202 
0203   /// Return the generic number of the given register.
0204   virtual uint32_t GetGenericNum(llvm::StringRef reg) = 0;
0205 
0206   /// For the given (capitalized) lldb register name, return the name of this
0207   /// register in the MCRegisterInfo struct.
0208   virtual std::string GetMCName(std::string reg) { return reg; }
0209 };
0210 
0211 } // namespace lldb_private
0212 
0213 #endif // LLDB_TARGET_ABI_H