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