Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / lldb / source / Plugins / Process / Utility / RegisterContextDarwin_arm64.h
bloba0d7821ae9e8b5866e0bd587392d49b1bdfef725
1 //===-- RegisterContextDarwin_arm64.h -----------------------------*- C++
2 //-*-===//
3 //
4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 // See https://llvm.org/LICENSE.txt for license information.
6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //
8 //===----------------------------------------------------------------------===//
10 #ifndef LLDB_SOURCE_PLUGINS_PROCESS_UTILITY_REGISTERCONTEXTDARWIN_ARM64_H
11 #define LLDB_SOURCE_PLUGINS_PROCESS_UTILITY_REGISTERCONTEXTDARWIN_ARM64_H
13 #include "lldb/Target/RegisterContext.h"
14 #include "lldb/lldb-private.h"
16 // Break only in privileged or user mode
17 #define S_RSVD ((uint32_t)(0u << 1))
18 #define S_PRIV ((uint32_t)(1u << 1))
19 #define S_USER ((uint32_t)(2u << 1))
20 #define S_PRIV_USER ((S_PRIV) | (S_USER))
22 #define WCR_ENABLE ((uint32_t)(1u))
24 // Watchpoint load/store
25 #define WCR_LOAD ((uint32_t)(1u << 3))
26 #define WCR_STORE ((uint32_t)(1u << 4))
28 class RegisterContextDarwin_arm64 : public lldb_private::RegisterContext {
29 public:
30 RegisterContextDarwin_arm64(lldb_private::Thread &thread,
31 uint32_t concrete_frame_idx);
33 ~RegisterContextDarwin_arm64() override;
35 void InvalidateAllRegisters() override;
37 size_t GetRegisterCount() override;
39 const lldb_private::RegisterInfo *GetRegisterInfoAtIndex(size_t reg) override;
41 size_t GetRegisterSetCount() override;
43 const lldb_private::RegisterSet *GetRegisterSet(size_t set) override;
45 bool ReadRegister(const lldb_private::RegisterInfo *reg_info,
46 lldb_private::RegisterValue &reg_value) override;
48 bool WriteRegister(const lldb_private::RegisterInfo *reg_info,
49 const lldb_private::RegisterValue &reg_value) override;
51 bool ReadAllRegisterValues(lldb::WritableDataBufferSP &data_sp) override;
53 bool WriteAllRegisterValues(const lldb::DataBufferSP &data_sp) override;
55 uint32_t ConvertRegisterKindToRegisterNumber(lldb::RegisterKind kind,
56 uint32_t num) override;
58 uint32_t NumSupportedHardwareWatchpoints() override;
60 uint32_t SetHardwareWatchpoint(lldb::addr_t addr, size_t size, bool read,
61 bool write) override;
63 bool ClearHardwareWatchpoint(uint32_t hw_index) override;
65 // mirrors <mach/arm/thread_status.h> arm_thread_state64_t
66 struct GPR {
67 uint64_t x[29]; // x0-x28
68 uint64_t fp; // x29
69 uint64_t lr; // x30
70 uint64_t sp; // x31
71 uint64_t pc; // pc
72 uint32_t cpsr; // cpsr
75 struct VReg {
76 alignas(16) char bytes[16];
79 // mirrors <mach/arm/thread_status.h> arm_neon_state64_t
80 struct FPU {
81 VReg v[32];
82 uint32_t fpsr;
83 uint32_t fpcr;
86 // mirrors <mach/arm/thread_status.h> arm_exception_state64_t
87 struct EXC {
88 uint64_t far; // Virtual Fault Address
89 uint32_t esr; // Exception syndrome
90 uint32_t exception; // number of arm exception token
93 // mirrors <mach/arm/thread_status.h> arm_debug_state64_t
94 struct DBG {
95 uint64_t bvr[16];
96 uint64_t bcr[16];
97 uint64_t wvr[16];
98 uint64_t wcr[16];
99 uint64_t mdscr_el1;
102 static void LogDBGRegisters(lldb_private::Log *log, const DBG &dbg);
104 protected:
105 enum {
106 GPRRegSet = 6, // ARM_THREAD_STATE64
107 FPURegSet = 17, // ARM_NEON_STATE64
108 EXCRegSet = 7, // ARM_EXCEPTION_STATE64
109 DBGRegSet = 15 // ARM_DEBUG_STATE64
112 enum {
113 GPRWordCount = sizeof(GPR) / sizeof(uint32_t), // ARM_THREAD_STATE64_COUNT
114 FPUWordCount = sizeof(FPU) / sizeof(uint32_t), // ARM_NEON_STATE64_COUNT
115 EXCWordCount =
116 sizeof(EXC) / sizeof(uint32_t), // ARM_EXCEPTION_STATE64_COUNT
117 DBGWordCount = sizeof(DBG) / sizeof(uint32_t) // ARM_DEBUG_STATE64_COUNT
120 enum { Read = 0, Write = 1, kNumErrors = 2 };
122 GPR gpr;
123 FPU fpu;
124 EXC exc;
125 DBG dbg;
126 int gpr_errs[2]; // Read/Write errors
127 int fpu_errs[2]; // Read/Write errors
128 int exc_errs[2]; // Read/Write errors
129 int dbg_errs[2]; // Read/Write errors
131 void InvalidateAllRegisterStates() {
132 SetError(GPRRegSet, Read, -1);
133 SetError(FPURegSet, Read, -1);
134 SetError(EXCRegSet, Read, -1);
137 int GetError(int flavor, uint32_t err_idx) const {
138 if (err_idx < kNumErrors) {
139 switch (flavor) {
140 // When getting all errors, just OR all values together to see if
141 // we got any kind of error.
142 case GPRRegSet:
143 return gpr_errs[err_idx];
144 case FPURegSet:
145 return fpu_errs[err_idx];
146 case EXCRegSet:
147 return exc_errs[err_idx];
148 case DBGRegSet:
149 return dbg_errs[err_idx];
150 default:
151 break;
154 return -1;
157 bool SetError(int flavor, uint32_t err_idx, int err) {
158 if (err_idx < kNumErrors) {
159 switch (flavor) {
160 case GPRRegSet:
161 gpr_errs[err_idx] = err;
162 return true;
164 case FPURegSet:
165 fpu_errs[err_idx] = err;
166 return true;
168 case EXCRegSet:
169 exc_errs[err_idx] = err;
170 return true;
172 case DBGRegSet:
173 exc_errs[err_idx] = err;
174 return true;
176 default:
177 break;
180 return false;
183 bool RegisterSetIsCached(int set) const { return GetError(set, Read) == 0; }
185 int ReadGPR(bool force);
187 int ReadFPU(bool force);
189 int ReadEXC(bool force);
191 int ReadDBG(bool force);
193 int WriteGPR();
195 int WriteFPU();
197 int WriteEXC();
199 int WriteDBG();
201 // Subclasses override these to do the actual reading.
202 virtual int DoReadGPR(lldb::tid_t tid, int flavor, GPR &gpr) { return -1; }
204 virtual int DoReadFPU(lldb::tid_t tid, int flavor, FPU &fpu) = 0;
206 virtual int DoReadEXC(lldb::tid_t tid, int flavor, EXC &exc) = 0;
208 virtual int DoReadDBG(lldb::tid_t tid, int flavor, DBG &dbg) = 0;
210 virtual int DoWriteGPR(lldb::tid_t tid, int flavor, const GPR &gpr) = 0;
212 virtual int DoWriteFPU(lldb::tid_t tid, int flavor, const FPU &fpu) = 0;
214 virtual int DoWriteEXC(lldb::tid_t tid, int flavor, const EXC &exc) = 0;
216 virtual int DoWriteDBG(lldb::tid_t tid, int flavor, const DBG &dbg) = 0;
218 int ReadRegisterSet(uint32_t set, bool force);
220 int WriteRegisterSet(uint32_t set);
222 static uint32_t GetRegisterNumber(uint32_t reg_kind, uint32_t reg_num);
224 static int GetSetForNativeRegNum(int reg_num);
226 static size_t GetRegisterInfosCount();
228 static const lldb_private::RegisterInfo *GetRegisterInfos();
231 #endif // LLDB_SOURCE_PLUGINS_PROCESS_UTILITY_REGISTERCONTEXTDARWIN_ARM64_H