Back to home page

EIC code displayed by LXR

 
 

    


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

0001 //===-- NativeRegisterContext.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_HOST_COMMON_NATIVEREGISTERCONTEXT_H
0010 #define LLDB_HOST_COMMON_NATIVEREGISTERCONTEXT_H
0011 
0012 #include "lldb/Host/common/NativeWatchpointList.h"
0013 #include "lldb/lldb-private.h"
0014 
0015 namespace lldb_private {
0016 
0017 class NativeThreadProtocol;
0018 
0019 enum class ExpeditedRegs { Minimal, Full };
0020 
0021 class NativeRegisterContext
0022     : public std::enable_shared_from_this<NativeRegisterContext> {
0023 public:
0024   // Constructors and Destructors
0025   NativeRegisterContext(NativeThreadProtocol &thread);
0026 
0027   virtual ~NativeRegisterContext();
0028 
0029   // void
0030   // InvalidateIfNeeded (bool force);
0031 
0032   // Subclasses must override these functions
0033   // virtual void
0034   // InvalidateAllRegisters () = 0;
0035 
0036   virtual uint32_t GetRegisterCount() const = 0;
0037 
0038   virtual uint32_t GetUserRegisterCount() const = 0;
0039 
0040   virtual const RegisterInfo *GetRegisterInfoAtIndex(uint32_t reg) const = 0;
0041 
0042   const char *GetRegisterSetNameForRegisterAtIndex(uint32_t reg_index) const;
0043 
0044   virtual uint32_t GetRegisterSetCount() const = 0;
0045 
0046   virtual const RegisterSet *GetRegisterSet(uint32_t set_index) const = 0;
0047 
0048   virtual Status ReadRegister(const RegisterInfo *reg_info,
0049                               RegisterValue &reg_value) = 0;
0050 
0051   virtual Status WriteRegister(const RegisterInfo *reg_info,
0052                                const RegisterValue &reg_value) = 0;
0053 
0054   virtual Status ReadAllRegisterValues(lldb::WritableDataBufferSP &data_sp) = 0;
0055 
0056   virtual Status WriteAllRegisterValues(const lldb::DataBufferSP &data_sp) = 0;
0057 
0058   uint32_t ConvertRegisterKindToRegisterNumber(uint32_t kind,
0059                                                uint32_t num) const;
0060 
0061   // Subclasses can override these functions if desired
0062   virtual uint32_t NumSupportedHardwareBreakpoints();
0063 
0064   virtual uint32_t SetHardwareBreakpoint(lldb::addr_t addr, size_t size);
0065 
0066   virtual bool ClearHardwareBreakpoint(uint32_t hw_idx);
0067 
0068   virtual Status ClearAllHardwareBreakpoints();
0069 
0070   virtual Status GetHardwareBreakHitIndex(uint32_t &bp_index,
0071                                           lldb::addr_t trap_addr);
0072 
0073   virtual uint32_t NumSupportedHardwareWatchpoints();
0074 
0075   virtual uint32_t SetHardwareWatchpoint(lldb::addr_t addr, size_t size,
0076                                          uint32_t watch_flags);
0077 
0078   virtual bool ClearHardwareWatchpoint(uint32_t hw_index);
0079 
0080   virtual Status ClearWatchpointHit(uint32_t hw_index);
0081 
0082   virtual Status ClearAllHardwareWatchpoints();
0083 
0084   virtual Status IsWatchpointHit(uint32_t wp_index, bool &is_hit);
0085 
0086   virtual Status GetWatchpointHitIndex(uint32_t &wp_index,
0087                                        lldb::addr_t trap_addr);
0088 
0089   virtual Status IsWatchpointVacant(uint32_t wp_index, bool &is_vacant);
0090 
0091   virtual lldb::addr_t GetWatchpointAddress(uint32_t wp_index);
0092 
0093   // MIPS Linux kernel returns a masked address (last 3bits are masked)
0094   // when a HW watchpoint is hit. However user may not have set a watchpoint on
0095   // this address. This function emulates the instruction at PC and finds the
0096   // base address used in the load/store instruction. This gives the exact
0097   // address used to read/write the variable being watched. For example: 'n' is
0098   // at 0x120010d00 and 'm' is 0x120010d04. When a watchpoint is set at 'm',
0099   // then watch exception is generated even when 'n' is read/written. This
0100   // function returns address of 'n' so that client can check whether a
0101   // watchpoint is set on this address or not.
0102   virtual lldb::addr_t GetWatchpointHitAddress(uint32_t wp_index);
0103 
0104   virtual bool HardwareSingleStep(bool enable);
0105 
0106   virtual Status
0107   ReadRegisterValueFromMemory(const lldb_private::RegisterInfo *reg_info,
0108                               lldb::addr_t src_addr, size_t src_len,
0109                               RegisterValue &reg_value);
0110 
0111   virtual Status
0112   WriteRegisterValueToMemory(const lldb_private::RegisterInfo *reg_info,
0113                              lldb::addr_t dst_addr, size_t dst_len,
0114                              const RegisterValue &reg_value);
0115 
0116   // Subclasses should not override these
0117   virtual lldb::tid_t GetThreadID() const;
0118 
0119   virtual NativeThreadProtocol &GetThread() { return m_thread; }
0120 
0121   virtual std::vector<uint32_t>
0122   GetExpeditedRegisters(ExpeditedRegs expType) const;
0123 
0124   virtual bool RegisterOffsetIsDynamic() const { return false; }
0125 
0126   const RegisterInfo *GetRegisterInfoByName(llvm::StringRef reg_name,
0127                                             uint32_t start_idx = 0);
0128 
0129   const RegisterInfo *GetRegisterInfo(uint32_t reg_kind, uint32_t reg_num);
0130 
0131   lldb::addr_t GetPC(lldb::addr_t fail_value = LLDB_INVALID_ADDRESS);
0132 
0133   virtual lldb::addr_t
0134   GetPCfromBreakpointLocation(lldb::addr_t fail_value = LLDB_INVALID_ADDRESS);
0135 
0136   Status SetPC(lldb::addr_t pc);
0137 
0138   lldb::addr_t GetSP(lldb::addr_t fail_value = LLDB_INVALID_ADDRESS);
0139 
0140   Status SetSP(lldb::addr_t sp);
0141 
0142   lldb::addr_t GetFP(lldb::addr_t fail_value = LLDB_INVALID_ADDRESS);
0143 
0144   Status SetFP(lldb::addr_t fp);
0145 
0146   const char *GetRegisterName(uint32_t reg);
0147 
0148   lldb::addr_t GetReturnAddress(lldb::addr_t fail_value = LLDB_INVALID_ADDRESS);
0149 
0150   lldb::addr_t GetFlags(lldb::addr_t fail_value = 0);
0151 
0152   lldb::addr_t ReadRegisterAsUnsigned(uint32_t reg, lldb::addr_t fail_value);
0153 
0154   lldb::addr_t ReadRegisterAsUnsigned(const RegisterInfo *reg_info,
0155                                       lldb::addr_t fail_value);
0156 
0157   Status WriteRegisterFromUnsigned(uint32_t reg, uint64_t uval);
0158 
0159   Status WriteRegisterFromUnsigned(const RegisterInfo *reg_info, uint64_t uval);
0160 
0161   // uint32_t
0162   // GetStopID () const
0163   // {
0164   //     return m_stop_id;
0165   // }
0166 
0167   // void
0168   // SetStopID (uint32_t stop_id)
0169   // {
0170   //     m_stop_id = stop_id;
0171   // }
0172 
0173 protected:
0174   // Classes that inherit from RegisterContext can see and modify these
0175   NativeThreadProtocol
0176       &m_thread; // The thread that this register context belongs to.
0177   // uint32_t m_stop_id;             // The stop ID that any data in this
0178   // context is valid for
0179 
0180 private:
0181   // For RegisterContext only
0182   NativeRegisterContext(const NativeRegisterContext &) = delete;
0183   const NativeRegisterContext &
0184   operator=(const NativeRegisterContext &) = delete;
0185 };
0186 
0187 } // namespace lldb_private
0188 
0189 #endif // LLDB_HOST_COMMON_NATIVEREGISTERCONTEXT_H