LLDB mainline
NativeRegisterContextLinux_x86.h
Go to the documentation of this file.
1//===-- NativeRegisterContextLinux_x86.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_h
12#define lldb_NativeRegisterContextLinux_x86_h
13
19#include <optional>
20#include <sys/uio.h>
21
22namespace lldb_private {
23namespace process_linux {
24
26
27class NativeRegisterContextLinux_x86
29 public NativeRegisterContextDBReg_x86 {
30public:
31 NativeRegisterContextLinux_x86(const ArchSpec &target_arch,
32 NativeThreadProtocol &native_thread);
33
34 uint32_t GetRegisterCount() const override;
35
36 const RegisterInfo *GetRegisterInfoAtIndex(uint32_t reg) const override;
37
38 uint32_t GetRegisterSetCount() const override;
39
40 const RegisterSet *GetRegisterSet(uint32_t set_index) const override;
41
42 uint32_t GetUserRegisterCount() const override;
43
44 Status ReadRegister(const RegisterInfo *reg_info,
45 RegisterValue &reg_value) override;
46
47 Status WriteRegister(const RegisterInfo *reg_info,
48 const RegisterValue &reg_value) override;
49
50 Status ReadAllRegisterValues(lldb::WritableDataBufferSP &data_sp) override;
51
52 Status WriteAllRegisterValues(const lldb::DataBufferSP &data_sp) override;
53
54 std::optional<SyscallData> GetSyscallData() override;
55
56 std::optional<MmapData> GetMmapData() override;
57
58 const RegisterInfo *GetDR(int num) const override;
59
60protected:
61 void *GetGPRBuffer() override { return &m_gpr_x86_64; }
62
63 void *GetFPRBuffer() override;
64
65 size_t GetFPRSize() override;
66
67 Status ReadFPR() override;
68
69 Status WriteFPR() override;
70
71 uint32_t GetPtraceOffset(uint32_t reg_index) override;
72
73private:
74 // Private member types.
75 enum class XStateType { Invalid, FXSAVE, XSAVE };
76 enum class RegSet { gpr, fpu, avx, mpx };
77
78 // Info about register ranges.
79 struct RegInfo {
80 uint32_t num_registers;
81 uint32_t num_gpr_registers;
82 uint32_t num_fpr_registers;
83 uint32_t num_avx_registers;
84 uint32_t num_mpx_registers;
85 uint32_t last_gpr;
86 uint32_t first_fpr;
87 uint32_t last_fpr;
88 uint32_t first_st;
89 uint32_t last_st;
90 uint32_t first_mm;
91 uint32_t last_mm;
92 uint32_t first_xmm;
93 uint32_t last_xmm;
94 uint32_t first_ymm;
95 uint32_t last_ymm;
96 uint32_t first_mpxr;
97 uint32_t last_mpxr;
98 uint32_t first_mpxc;
99 uint32_t last_mpxc;
100 uint32_t first_dr;
101 uint32_t last_dr;
102 uint32_t gpr_flags;
103 };
104
105 // Private member variables.
106 mutable XStateType m_xstate_type;
107 std::unique_ptr<FPR, llvm::FreeDeleter>
108 m_xstate; // Extended States Area, named FPR for historical reasons.
109 struct iovec m_iovec;
110 YMM m_ymm_set;
111 MPX m_mpx_set;
112 RegInfo m_reg_info;
113 RegisterInfo m_i386_thread_pointer_info = {};
114 uint64_t m_gpr_x86_64[x86_64_with_base::k_num_gpr_registers];
115 uint32_t m_fctrl_offset_in_userarea;
116
117 // Private member methods.
118 bool IsCPUFeatureAvailable(RegSet feature_code) const;
119
120 bool IsRegisterSetAvailable(uint32_t set_index) const;
121
122 bool IsGPR(uint32_t reg_index) const;
123
124 bool IsFPR(uint32_t reg_index) const;
125
126 bool IsDR(uint32_t reg_index) const;
127
128 bool CopyXSTATEtoYMM(uint32_t reg_index, lldb::ByteOrder byte_order);
129
130 bool CopyYMMtoXSTATE(uint32_t reg, lldb::ByteOrder byte_order);
131
132 bool IsAVX(uint32_t reg_index) const;
133
134 bool CopyXSTATEtoMPX(uint32_t reg);
135
136 bool CopyMPXtoXSTATE(uint32_t reg);
137
138 bool IsMPX(uint32_t reg_index) const;
139
140 bool IsThreadPointer(const RegisterInfo &reg_info) const;
141
142 Status ReadThreadPointer(RegisterValue &reg_value);
143
144 uint32_t GetRegisterInfoIndex(uint32_t lldb_reg) const;
145
146 void UpdateXSTATEforWrite(uint32_t reg_index);
147
148 RegisterContextLinux_x86 &GetRegisterInfo() const {
149 return static_cast<RegisterContextLinux_x86 &>(
150 *m_register_info_interface_up);
151 }
152};
153
154} // namespace process_linux
155} // namespace lldb_private
156
157#endif // #ifndef lldb_NativeRegisterContextLinux_x86_h
158
159#endif // defined(__i386__) || defined(__x86_64__)
#define YMM(n)
Definition ABIX86.cpp:166
Manages communication with the inferior (debugee) process.
A class that represents a running process on the host machine.
ByteOrder
Byte ordering definitions.
std::shared_ptr< lldb_private::DataBuffer > DataBufferSP
std::shared_ptr< lldb_private::WritableDataBuffer > WritableDataBufferSP