LLDB mainline
NativeRegisterContextLinux_arm64.h
Go to the documentation of this file.
1//===-- NativeRegisterContextLinux_arm64.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(__arm64__) || defined(__aarch64__)
10
11#ifndef lldb_NativeRegisterContextLinux_arm64_h
12#define lldb_NativeRegisterContextLinux_arm64_h
13
18
19#include <asm/ptrace.h>
20
21namespace lldb_private {
22namespace process_linux {
23
25
26class NativeRegisterContextLinux_arm64
28 public NativeRegisterContextDBReg_arm64 {
29public:
30 NativeRegisterContextLinux_arm64(
31 const ArchSpec &target_arch, NativeThreadProtocol &native_thread,
32 std::unique_ptr<RegisterInfoPOSIX_arm64> register_info_up);
33
34 uint32_t GetRegisterSetCount() const override;
35
36 uint32_t GetUserRegisterCount() const override;
37
38 const RegisterSet *GetRegisterSet(uint32_t set_index) const override;
39
40 Status ReadRegister(const RegisterInfo *reg_info,
41 RegisterValue &reg_value) override;
42
43 Status WriteRegister(const RegisterInfo *reg_info,
44 const RegisterValue &reg_value) override;
45
46 Status ReadAllRegisterValues(lldb::WritableDataBufferSP &data_sp) override;
47
48 Status WriteAllRegisterValues(const lldb::DataBufferSP &data_sp) override;
49
50 void InvalidateAllRegisters() override;
51
52 std::vector<uint32_t>
53 GetExpeditedRegisters(ExpeditedRegs expType) const override;
54
55 bool RegisterOffsetIsDynamic() const override { return true; }
56
57 llvm::Expected<MemoryTaggingDetails>
58 GetMemoryTaggingDetails(int32_t type) override;
59
60protected:
61 Status ReadGPR() override;
62
63 Status WriteGPR() override;
64
65 Status ReadFPR() override;
66
67 Status WriteFPR() override;
68
69 void *GetGPRBuffer() override { return &m_gpr_arm64; }
70
71 // GetGPRBufferSize returns sizeof arm64 GPR ptrace buffer, it is different
72 // from GetGPRSize which returns sizeof RegisterInfoPOSIX_arm64::GPR.
73 size_t GetGPRBufferSize() { return sizeof(m_gpr_arm64); }
74
75 void *GetFPRBuffer() override { return &m_fpr; }
76
77 size_t GetFPRSize() override { return sizeof(m_fpr); }
78
79 lldb::addr_t FixWatchpointHitAddress(lldb::addr_t hit_addr) override;
80
81private:
82 bool m_gpr_is_valid;
83 bool m_fpu_is_valid;
84 bool m_sve_buffer_is_valid;
85 bool m_mte_ctrl_is_valid;
86 bool m_zt_buffer_is_valid;
87 bool m_fpmr_is_valid;
88
89 bool m_sve_header_is_valid;
90 bool m_za_buffer_is_valid;
91 bool m_za_header_is_valid;
92 bool m_pac_mask_is_valid;
93 bool m_tls_is_valid;
94 size_t m_tls_size;
95 bool m_gcs_is_valid;
96 bool m_poe_is_valid;
97
98 struct user_pt_regs m_gpr_arm64; // 64-bit general purpose registers.
99
100 RegisterInfoPOSIX_arm64::FPU
101 m_fpr; // floating-point registers including extended register sets.
102
103 SVEState m_sve_state = SVEState::Unknown;
104 struct sve::user_sve_header m_sve_header;
105 std::vector<uint8_t> m_sve_ptrace_payload;
106
107 sve::user_za_header m_za_header;
108 std::vector<uint8_t> m_za_ptrace_payload;
109
110 bool m_refresh_hwdebug_info;
111
112 struct user_pac_mask {
113 uint64_t data_mask;
114 uint64_t insn_mask;
115 };
116
117 struct user_pac_mask m_pac_mask;
118
119 uint64_t m_mte_ctrl_reg;
120
121 struct sme_pseudo_regs {
122 uint64_t ctrl_reg;
123 uint64_t svg_reg;
124 };
125
126 struct sme_pseudo_regs m_sme_pseudo_regs;
127
128 struct tls_regs {
129 uint64_t tpidr_reg;
130 // Only valid when SME is present.
131 uint64_t tpidr2_reg;
132 };
133
134 struct tls_regs m_tls_regs;
135
136 // SME2's ZT is a 512 bit register.
137 std::array<uint8_t, 64> m_zt_reg;
138
139 uint64_t m_fpmr_reg;
140
141 struct poe_regs {
142 uint64_t por_reg;
143 };
144
145 struct poe_regs m_poe_regs;
146
147 struct gcs_regs {
148 uint64_t features_enabled;
149 uint64_t features_locked;
150 uint64_t gcspr_e0;
151 } m_gcs_regs;
152
153 bool IsGPR(unsigned reg) const;
154
155 bool IsFPR(unsigned reg) const;
156
157 Status ReadAllSVE();
158
159 Status WriteAllSVE();
160
161 Status ReadSVEHeader();
162
163 Status WriteSVEHeader();
164
165 Status ReadPAuthMask();
166
167 Status ReadMTEControl();
168
169 Status WriteMTEControl();
170
171 Status ReadTLS();
172
173 Status WriteTLS();
174
175 Status ReadSMESVG();
176
177 Status ReadZAHeader();
178
179 Status ReadZA();
180
181 Status WriteZA();
182
183 Status ReadGCS();
184
185 Status WriteGCS();
186
187 // No WriteZAHeader because writing only the header will disable ZA.
188 // Instead use WriteZA and ensure you have the correct ZA buffer size set
189 // beforehand if you wish to disable it.
190
191 Status ReadZT();
192
193 Status WriteZT();
194
195 // SVCR is a pseudo register and we do not allow writes to it.
196 Status ReadSMEControl();
197
198 Status ReadFPMR();
199
200 Status WriteFPMR();
201
202 Status ReadPOE();
203
204 Status WritePOE();
205
206 bool IsSVE(unsigned reg) const;
207 bool IsSME(unsigned reg) const;
208 bool IsPAuth(unsigned reg) const;
209 bool IsMTE(unsigned reg) const;
210 bool IsTLS(unsigned reg) const;
211 bool IsFPMR(unsigned reg) const;
212 bool IsGCS(unsigned reg) const;
213 bool IsPOE(unsigned reg) const;
214
215 uint64_t GetSVERegVG() { return m_sve_header.vl / 8; }
216
217 void SetSVERegVG(uint64_t vg) { m_sve_header.vl = vg * 8; }
218
219 void *GetSVEHeader() { return &m_sve_header; }
220
221 void *GetZAHeader() { return &m_za_header; }
222
223 size_t GetZAHeaderSize() { return sizeof(m_za_header); }
224
225 void *GetPACMask() { return &m_pac_mask; }
226
227 void *GetMTEControl() { return &m_mte_ctrl_reg; }
228
229 void *GetTLSBuffer() { return &m_tls_regs; }
230
231 void *GetSMEPseudoBuffer() { return &m_sme_pseudo_regs; }
232
233 void *GetZTBuffer() { return m_zt_reg.data(); }
234
235 void *GetSVEBuffer() { return m_sve_ptrace_payload.data(); }
236
237 void *GetFPMRBuffer() { return &m_fpmr_reg; }
238
239 void *GetGCSBuffer() { return &m_gcs_regs; }
240
241 void *GetPOEBuffer() { return &m_poe_regs; }
242
243 size_t GetSVEHeaderSize() { return sizeof(m_sve_header); }
244
245 size_t GetPACMaskSize() { return sizeof(m_pac_mask); }
246
247 size_t GetSVEBufferSize() { return m_sve_ptrace_payload.size(); }
248
249 unsigned GetSVERegSet();
250
251 void *GetZABuffer() { return m_za_ptrace_payload.data(); };
252
253 size_t GetZABufferSize() { return m_za_ptrace_payload.size(); }
254
255 size_t GetMTEControlSize() { return sizeof(m_mte_ctrl_reg); }
256
257 size_t GetTLSBufferSize() { return m_tls_size; }
258
259 size_t GetSMEPseudoBufferSize() { return sizeof(m_sme_pseudo_regs); }
260
261 size_t GetZTBufferSize() { return m_zt_reg.size(); }
262
263 size_t GetFPMRBufferSize() { return sizeof(m_fpmr_reg); }
264
265 size_t GetGCSBufferSize() { return sizeof(m_gcs_regs); }
266
267 size_t GetPOEBufferSize() { return sizeof(m_poe_regs); }
268
269 llvm::Error ReadHardwareDebugInfo() override;
270
271 llvm::Error WriteHardwareDebugRegs(DREGType hwbType) override;
272
273 uint32_t CalculateFprOffset(const RegisterInfo *reg_info) const;
274
275 RegisterInfoPOSIX_arm64 &GetRegisterInfo() const;
276
277 void ConfigureRegisterContext();
278
279 uint32_t CalculateSVEOffset(const RegisterInfo *reg_info) const;
280
281 Status CacheAllRegisters(uint32_t &cached_size);
282};
283
284} // namespace process_linux
285} // namespace lldb_private
286
287#endif // #ifndef lldb_NativeRegisterContextLinux_arm64_h
288
289#endif // defined (__arm64__) || defined (__aarch64__)
Manages communication with the inferior (debugee) process.
Status WriteHardwareDebugRegs(int hwbType, ::pid_t tid, uint32_t max_supported, const std::array< NativeRegisterContextDBReg::DREG, 16 > &regs)
Status ReadHardwareDebugInfo(::pid_t tid, uint32_t &max_hwp_supported, uint32_t &max_hbp_supported)
A class that represents a running process on the host machine.
std::shared_ptr< lldb_private::DataBuffer > DataBufferSP
std::shared_ptr< lldb_private::WritableDataBuffer > WritableDataBufferSP
uint64_t addr_t
Definition lldb-types.h:80