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/RegisterContext_x86.h" 16 #include "Plugins/Process/Utility/lldb-x86-register-enums.h" 17 #include <sys/uio.h> 18 19 namespace lldb_private { 20 namespace process_linux { 21 22 class NativeProcessLinux; 23 24 class NativeRegisterContextLinux_x86_64 : public NativeRegisterContextLinux { 25 public: 26 NativeRegisterContextLinux_x86_64(const ArchSpec &target_arch, 27 NativeThreadProtocol &native_thread); 28 29 uint32_t GetRegisterSetCount() const override; 30 31 const RegisterSet *GetRegisterSet(uint32_t set_index) const override; 32 33 uint32_t GetUserRegisterCount() const override; 34 35 Status ReadRegister(const RegisterInfo *reg_info, 36 RegisterValue ®_value) override; 37 38 Status WriteRegister(const RegisterInfo *reg_info, 39 const RegisterValue ®_value) override; 40 41 Status ReadAllRegisterValues(lldb::DataBufferSP &data_sp) override; 42 43 Status WriteAllRegisterValues(const lldb::DataBufferSP &data_sp) override; 44 45 Status IsWatchpointHit(uint32_t wp_index, bool &is_hit) override; 46 47 Status GetWatchpointHitIndex(uint32_t &wp_index, 48 lldb::addr_t trap_addr) override; 49 50 Status IsWatchpointVacant(uint32_t wp_index, bool &is_vacant) override; 51 52 bool ClearHardwareWatchpoint(uint32_t wp_index) override; 53 54 Status ClearAllHardwareWatchpoints() override; 55 56 Status SetHardwareWatchpointWithIndex(lldb::addr_t addr, size_t size, 57 uint32_t watch_flags, 58 uint32_t wp_index); 59 60 uint32_t SetHardwareWatchpoint(lldb::addr_t addr, size_t size, 61 uint32_t watch_flags) override; 62 63 lldb::addr_t GetWatchpointAddress(uint32_t wp_index) override; 64 65 uint32_t NumSupportedHardwareWatchpoints() override; 66 67 protected: 68 void *GetGPRBuffer() override { return &m_gpr_x86_64; } 69 70 void *GetFPRBuffer() override; 71 72 size_t GetFPRSize() override; 73 74 Status ReadFPR() override; 75 76 Status WriteFPR() override; 77 78 uint32_t GetPtraceOffset(uint32_t reg_index) override; 79 80 private: 81 // Private member types. 82 enum class XStateType { Invalid, FXSAVE, XSAVE }; 83 enum class RegSet { gpr, fpu, avx, mpx }; 84 85 // Info about register ranges. 86 struct RegInfo { 87 uint32_t num_registers; 88 uint32_t num_gpr_registers; 89 uint32_t num_fpr_registers; 90 uint32_t num_avx_registers; 91 uint32_t num_mpx_registers; 92 uint32_t last_gpr; 93 uint32_t first_fpr; 94 uint32_t last_fpr; 95 uint32_t first_st; 96 uint32_t last_st; 97 uint32_t first_mm; 98 uint32_t last_mm; 99 uint32_t first_xmm; 100 uint32_t last_xmm; 101 uint32_t first_ymm; 102 uint32_t last_ymm; 103 uint32_t first_mpxr; 104 uint32_t last_mpxr; 105 uint32_t first_mpxc; 106 uint32_t last_mpxc; 107 uint32_t first_dr; 108 uint32_t gpr_flags; 109 }; 110 111 // Private member variables. 112 mutable XStateType m_xstate_type; 113 std::unique_ptr<FPR, llvm::FreeDeleter> 114 m_xstate; // Extended States Area, named FPR for historical reasons. 115 struct iovec m_iovec; 116 YMM m_ymm_set; 117 MPX m_mpx_set; 118 RegInfo m_reg_info; 119 uint64_t m_gpr_x86_64[k_num_gpr_registers_x86_64]; 120 uint32_t m_fctrl_offset_in_userarea; 121 122 // Private member methods. 123 bool IsCPUFeatureAvailable(RegSet feature_code) const; 124 125 bool IsRegisterSetAvailable(uint32_t set_index) const; 126 127 bool IsGPR(uint32_t reg_index) const; 128 129 bool IsFPR(uint32_t reg_index) const; 130 131 bool CopyXSTATEtoYMM(uint32_t reg_index, lldb::ByteOrder byte_order); 132 133 bool CopyYMMtoXSTATE(uint32_t reg, lldb::ByteOrder byte_order); 134 135 bool IsAVX(uint32_t reg_index) const; 136 137 bool CopyXSTATEtoMPX(uint32_t reg); 138 139 bool CopyMPXtoXSTATE(uint32_t reg); 140 141 bool IsMPX(uint32_t reg_index) const; 142 143 void UpdateXSTATEforWrite(uint32_t reg_index); 144 }; 145 146 } // namespace process_linux 147 } // namespace lldb_private 148 149 #endif // #ifndef lldb_NativeRegisterContextLinux_x86_64_h 150 151 #endif // defined(__i386__) || defined(__x86_64__) 152