Back to home page

EIC code displayed by LXR

 
 

    


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

0001 //===-- RegisterContext.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_REGISTERCONTEXT_H
0010 #define LLDB_TARGET_REGISTERCONTEXT_H
0011 
0012 #include "lldb/Target/ExecutionContextScope.h"
0013 #include "lldb/lldb-private.h"
0014 
0015 namespace lldb_private {
0016 
0017 class RegisterContext : public std::enable_shared_from_this<RegisterContext>,
0018                         public ExecutionContextScope {
0019 public:
0020   // Constructors and Destructors
0021   RegisterContext(Thread &thread, uint32_t concrete_frame_idx);
0022 
0023   ~RegisterContext() override;
0024 
0025   void InvalidateIfNeeded(bool force);
0026 
0027   // Subclasses must override these functions
0028   virtual void InvalidateAllRegisters() = 0;
0029 
0030   virtual size_t GetRegisterCount() = 0;
0031 
0032   virtual const RegisterInfo *GetRegisterInfoAtIndex(size_t reg) = 0;
0033 
0034   virtual size_t GetRegisterSetCount() = 0;
0035 
0036   virtual const RegisterSet *GetRegisterSet(size_t reg_set) = 0;
0037 
0038   virtual lldb::ByteOrder GetByteOrder();
0039 
0040   virtual bool ReadRegister(const RegisterInfo *reg_info,
0041                             RegisterValue &reg_value) = 0;
0042 
0043   virtual bool WriteRegister(const RegisterInfo *reg_info,
0044                              const RegisterValue &reg_value) = 0;
0045 
0046   virtual bool ReadAllRegisterValues(lldb::WritableDataBufferSP &data_sp) {
0047     return false;
0048   }
0049 
0050   virtual bool WriteAllRegisterValues(const lldb::DataBufferSP &data_sp) {
0051     return false;
0052   }
0053 
0054   virtual bool RegisterWriteCausesReconfigure(const llvm::StringRef name) {
0055     return false;
0056   }
0057 
0058   virtual bool ReconfigureRegisterInfo() { return false; }
0059 
0060   // These two functions are used to implement "push" and "pop" of register
0061   // states.  They are used primarily for expression evaluation, where we need
0062   // to push a new state (storing the old one in data_sp) and then restoring
0063   // the original state by passing the data_sp we got from ReadAllRegisters to
0064   // WriteAllRegisterValues. ReadAllRegisters will do what is necessary to
0065   // return a coherent set of register values for this thread, which may mean
0066   // e.g. interrupting a thread that is sitting in a kernel trap.  That is a
0067   // somewhat disruptive operation, so these API's should only be used when
0068   // this behavior is needed.
0069 
0070   virtual bool
0071   ReadAllRegisterValues(lldb_private::RegisterCheckpoint &reg_checkpoint);
0072 
0073   virtual bool WriteAllRegisterValues(
0074       const lldb_private::RegisterCheckpoint &reg_checkpoint);
0075 
0076   bool CopyFromRegisterContext(lldb::RegisterContextSP context);
0077 
0078   /// Convert from a given register numbering scheme to the lldb register
0079   /// numbering scheme
0080   ///
0081   /// There may be multiple ways to enumerate the registers for a given
0082   /// architecture.  ABI references will specify one to be used with
0083   /// DWARF, the register numberings from process plugin, there may
0084   /// be a variation used for eh_frame unwind instructions (e.g. on Darwin),
0085   /// and so on.  Register 5 by itself is meaningless - RegisterKind
0086   /// enumeration tells you what context that number should be translated as.
0087   ///
0088   /// Inside lldb, register numbers are in the eRegisterKindLLDB scheme;
0089   /// arguments which take a register number should take one in that
0090   /// scheme.
0091   ///
0092   /// eRegisterKindGeneric is a special numbering scheme which gives us
0093   /// constant values for the pc, frame register, stack register, etc., for
0094   /// use within lldb.  They may not be defined for all architectures but
0095   /// it allows generic code to translate these common registers into the
0096   /// lldb numbering scheme.
0097   ///
0098   /// This method translates a given register kind + register number into
0099   /// the eRegisterKindLLDB register numbering.
0100   ///
0101   /// \param [in] kind
0102   ///     The register numbering scheme (RegisterKind) that the following
0103   ///     register number is in.
0104   ///
0105   /// \param [in] num
0106   ///     A register number in the 'kind' register numbering scheme.
0107   ///
0108   /// \return
0109   ///     The equivalent register number in the eRegisterKindLLDB
0110   ///     numbering scheme, if possible, else LLDB_INVALID_REGNUM.
0111   virtual uint32_t ConvertRegisterKindToRegisterNumber(lldb::RegisterKind kind,
0112                                                        uint32_t num);
0113 
0114   // Subclasses can override these functions if desired
0115   virtual uint32_t NumSupportedHardwareBreakpoints();
0116 
0117   virtual uint32_t SetHardwareBreakpoint(lldb::addr_t addr, size_t size);
0118 
0119   virtual bool ClearHardwareBreakpoint(uint32_t hw_idx);
0120 
0121   virtual uint32_t NumSupportedHardwareWatchpoints();
0122 
0123   virtual uint32_t SetHardwareWatchpoint(lldb::addr_t addr, size_t size,
0124                                          bool read, bool write);
0125 
0126   virtual bool ClearHardwareWatchpoint(uint32_t hw_index);
0127 
0128   virtual bool HardwareSingleStep(bool enable);
0129 
0130   virtual Status
0131   ReadRegisterValueFromMemory(const lldb_private::RegisterInfo *reg_info,
0132                               lldb::addr_t src_addr, uint32_t src_len,
0133                               RegisterValue &reg_value);
0134 
0135   virtual Status
0136   WriteRegisterValueToMemory(const lldb_private::RegisterInfo *reg_info,
0137                              lldb::addr_t dst_addr, uint32_t dst_len,
0138                              const RegisterValue &reg_value);
0139 
0140   // Subclasses should not override these
0141   virtual lldb::tid_t GetThreadID() const;
0142 
0143   virtual Thread &GetThread() { return m_thread; }
0144 
0145   const RegisterInfo *GetRegisterInfoByName(llvm::StringRef reg_name,
0146                                             uint32_t start_idx = 0);
0147 
0148   const RegisterInfo *GetRegisterInfo(lldb::RegisterKind reg_kind,
0149                                       uint32_t reg_num);
0150 
0151   uint64_t GetPC(uint64_t fail_value = LLDB_INVALID_ADDRESS);
0152 
0153   // Returns the register value containing thread specific data, like TLS data
0154   // and other thread specific stuff.
0155   uint64_t GetThreadPointer(uint64_t fail_value = LLDB_INVALID_ADDRESS);
0156 
0157   /// Get an address suitable for symbolication.
0158   /// When symbolicating -- computing line, block, function --
0159   /// for a function in the middle of the stack, using the return
0160   /// address can lead to unexpected results for the user.
0161   /// A function that ends in a tail-call may have another function
0162   /// as the "return" address, but it will never actually return.
0163   /// Or a noreturn call in the middle of a function is the end of
0164   /// a block of instructions, and a DWARF location list entry for
0165   /// the return address may be a very different code path with
0166   /// incorrect results when printing variables for this frame.
0167   ///
0168   /// At a source line view, the user expects the current-line indictation
0169   /// to point to the function call they're under, not the next source line.
0170   ///
0171   /// The return address (GetPC()) should always be shown to the user,
0172   /// but when computing context, keeping within the bounds of the
0173   /// call instruction is what the user expects to see.
0174   ///
0175   /// \param [out] address
0176   ///     An Address object that will be filled in, if a PC can be retrieved.
0177   ///
0178   /// \return
0179   ///     Returns true if the Address param was filled in.
0180   bool GetPCForSymbolication(Address &address);
0181 
0182   bool SetPC(uint64_t pc);
0183 
0184   bool SetPC(Address addr);
0185 
0186   uint64_t GetSP(uint64_t fail_value = LLDB_INVALID_ADDRESS);
0187 
0188   bool SetSP(uint64_t sp);
0189 
0190   uint64_t GetFP(uint64_t fail_value = LLDB_INVALID_ADDRESS);
0191 
0192   bool SetFP(uint64_t fp);
0193 
0194   const char *GetRegisterName(uint32_t reg);
0195 
0196   uint64_t GetReturnAddress(uint64_t fail_value = LLDB_INVALID_ADDRESS);
0197 
0198   uint64_t GetFlags(uint64_t fail_value = 0);
0199 
0200   uint64_t ReadRegisterAsUnsigned(uint32_t reg, uint64_t fail_value);
0201 
0202   uint64_t ReadRegisterAsUnsigned(const RegisterInfo *reg_info,
0203                                   uint64_t fail_value);
0204 
0205   bool WriteRegisterFromUnsigned(uint32_t reg, uint64_t uval);
0206 
0207   bool WriteRegisterFromUnsigned(const RegisterInfo *reg_info, uint64_t uval);
0208 
0209   bool ConvertBetweenRegisterKinds(lldb::RegisterKind source_rk,
0210                                    uint32_t source_regnum,
0211                                    lldb::RegisterKind target_rk,
0212                                    uint32_t &target_regnum);
0213 
0214   // lldb::ExecutionContextScope pure virtual functions
0215   lldb::TargetSP CalculateTarget() override;
0216 
0217   lldb::ProcessSP CalculateProcess() override;
0218 
0219   lldb::ThreadSP CalculateThread() override;
0220 
0221   lldb::StackFrameSP CalculateStackFrame() override;
0222 
0223   void CalculateExecutionContext(ExecutionContext &exe_ctx) override;
0224 
0225   uint32_t GetStopID() const { return m_stop_id; }
0226 
0227   void SetStopID(uint32_t stop_id) { m_stop_id = stop_id; }
0228 
0229 protected:
0230   /// Indicates that this frame is currently executing code,
0231   /// that the PC value is not a return-pc but an actual executing
0232   /// instruction.  Some places in lldb will treat a return-pc
0233   /// value differently than the currently-executing-pc value,
0234   /// and this method can indicate if that should be done.
0235   /// The base class implementation only uses the frame index,
0236   /// but subclasses may have additional information that they
0237   /// can use to detect frames in this state, for instance a
0238   /// frame above a trap handler (sigtramp etc)..
0239   virtual bool BehavesLikeZerothFrame() const {
0240     return m_concrete_frame_idx == 0;
0241   }
0242 
0243   // Classes that inherit from RegisterContext can see and modify these
0244   Thread &m_thread; // The thread that this register context belongs to.
0245   uint32_t m_concrete_frame_idx; // The concrete frame index for this register
0246                                  // context
0247   uint32_t m_stop_id; // The stop ID that any data in this context is valid for
0248 private:
0249   // For RegisterContext only
0250   RegisterContext(const RegisterContext &) = delete;
0251   const RegisterContext &operator=(const RegisterContext &) = delete;
0252 };
0253 
0254 } // namespace lldb_private
0255 
0256 #endif // LLDB_TARGET_REGISTERCONTEXT_H