1 //===-- NativeRegisterContextLinux_x86_64.h ---------------------*- C++ -*-===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #if defined(__i386__) || defined(__x86_64__) 10 11 #ifndef lldb_NativeRegisterContextLinux_x86_64_h 12 #define lldb_NativeRegisterContextLinux_x86_64_h 13 14 #include "Plugins/Process/Linux/NativeRegisterContextLinux.h" 15 #include "Plugins/Process/Utility/NativeRegisterContextDBReg_x86.h" 16 #include "Plugins/Process/Utility/RegisterContextLinux_x86.h" 17 #include "Plugins/Process/Utility/RegisterContext_x86.h" 18 #include "Plugins/Process/Utility/lldb-x86-register-enums.h" 19 #include <optional> 20 #include <sys/uio.h> 21 22 namespace lldb_private { 23 namespace process_linux { 24 25 class NativeProcessLinux; 26 27 class NativeRegisterContextLinux_x86_64 28 : public NativeRegisterContextLinux, 29 public NativeRegisterContextDBReg_x86 { 30 public: 31 NativeRegisterContextLinux_x86_64(const ArchSpec &target_arch, 32 NativeThreadProtocol &native_thread); 33 34 uint32_t GetRegisterSetCount() const override; 35 36 const RegisterSet *GetRegisterSet(uint32_t set_index) const override; 37 38 uint32_t GetUserRegisterCount() const override; 39 40 Status ReadRegister(const RegisterInfo *reg_info, 41 RegisterValue ®_value) override; 42 43 Status WriteRegister(const RegisterInfo *reg_info, 44 const RegisterValue ®_value) override; 45 46 Status ReadAllRegisterValues(lldb::WritableDataBufferSP &data_sp) override; 47 48 Status WriteAllRegisterValues(const lldb::DataBufferSP &data_sp) override; 49 50 std::optional<SyscallData> GetSyscallData() override; 51 52 std::optional<MmapData> GetMmapData() override; 53 54 const RegisterInfo *GetDR(int num) const override; 55 56 protected: GetGPRBuffer()57 void *GetGPRBuffer() override { return &m_gpr_x86_64; } 58 59 void *GetFPRBuffer() override; 60 61 size_t GetFPRSize() override; 62 63 Status ReadFPR() override; 64 65 Status WriteFPR() override; 66 67 uint32_t GetPtraceOffset(uint32_t reg_index) override; 68 69 private: 70 // Private member types. 71 enum class XStateType { Invalid, FXSAVE, XSAVE }; 72 enum class RegSet { gpr, fpu, avx, mpx }; 73 74 // Info about register ranges. 75 struct RegInfo { 76 uint32_t num_registers; 77 uint32_t num_gpr_registers; 78 uint32_t num_fpr_registers; 79 uint32_t num_avx_registers; 80 uint32_t num_mpx_registers; 81 uint32_t last_gpr; 82 uint32_t first_fpr; 83 uint32_t last_fpr; 84 uint32_t first_st; 85 uint32_t last_st; 86 uint32_t first_mm; 87 uint32_t last_mm; 88 uint32_t first_xmm; 89 uint32_t last_xmm; 90 uint32_t first_ymm; 91 uint32_t last_ymm; 92 uint32_t first_mpxr; 93 uint32_t last_mpxr; 94 uint32_t first_mpxc; 95 uint32_t last_mpxc; 96 uint32_t first_dr; 97 uint32_t last_dr; 98 uint32_t gpr_flags; 99 }; 100 101 // Private member variables. 102 mutable XStateType m_xstate_type; 103 std::unique_ptr<FPR, llvm::FreeDeleter> 104 m_xstate; // Extended States Area, named FPR for historical reasons. 105 struct iovec m_iovec; 106 YMM m_ymm_set; 107 MPX m_mpx_set; 108 RegInfo m_reg_info; 109 uint64_t m_gpr_x86_64[x86_64_with_base::k_num_gpr_registers]; 110 uint32_t m_fctrl_offset_in_userarea; 111 112 // Private member methods. 113 bool IsCPUFeatureAvailable(RegSet feature_code) const; 114 115 bool IsRegisterSetAvailable(uint32_t set_index) const; 116 117 bool IsGPR(uint32_t reg_index) const; 118 119 bool IsFPR(uint32_t reg_index) const; 120 121 bool IsDR(uint32_t reg_index) const; 122 123 bool CopyXSTATEtoYMM(uint32_t reg_index, lldb::ByteOrder byte_order); 124 125 bool CopyYMMtoXSTATE(uint32_t reg, lldb::ByteOrder byte_order); 126 127 bool IsAVX(uint32_t reg_index) const; 128 129 bool CopyXSTATEtoMPX(uint32_t reg); 130 131 bool CopyMPXtoXSTATE(uint32_t reg); 132 133 bool IsMPX(uint32_t reg_index) const; 134 135 void UpdateXSTATEforWrite(uint32_t reg_index); 136 GetRegisterInfo()137 RegisterContextLinux_x86 &GetRegisterInfo() const { 138 return static_cast<RegisterContextLinux_x86 &>( 139 *m_register_info_interface_up); 140 } 141 }; 142 143 } // namespace process_linux 144 } // namespace lldb_private 145 146 #endif // #ifndef lldb_NativeRegisterContextLinux_x86_64_h 147 148 #endif // defined(__i386__) || defined(__x86_64__) 149