LLDB  mainline
RegisterContextDarwin_arm64.h
Go to the documentation of this file.
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 //===----------------------------------------------------------------------===//
9 
10 #ifndef LLDB_SOURCE_PLUGINS_PROCESS_UTILITY_REGISTERCONTEXTDARWIN_ARM64_H
11 #define LLDB_SOURCE_PLUGINS_PROCESS_UTILITY_REGISTERCONTEXTDARWIN_ARM64_H
12 
14 #include "lldb/lldb-private.h"
15 
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))
21 
22 #define WCR_ENABLE ((uint32_t)(1u))
23 
24 // Watchpoint load/store
25 #define WCR_LOAD ((uint32_t)(1u << 3))
26 #define WCR_STORE ((uint32_t)(1u << 4))
27 
29 public:
31  uint32_t concrete_frame_idx);
32 
34 
35  void InvalidateAllRegisters() override;
36 
37  size_t GetRegisterCount() override;
38 
39  const lldb_private::RegisterInfo *GetRegisterInfoAtIndex(size_t reg) override;
40 
41  size_t GetRegisterSetCount() override;
42 
43  const lldb_private::RegisterSet *GetRegisterSet(size_t set) override;
44 
45  bool ReadRegister(const lldb_private::RegisterInfo *reg_info,
46  lldb_private::RegisterValue &reg_value) override;
47 
48  bool WriteRegister(const lldb_private::RegisterInfo *reg_info,
49  const lldb_private::RegisterValue &reg_value) override;
50 
51  bool ReadAllRegisterValues(lldb::DataBufferSP &data_sp) override;
52 
53  bool WriteAllRegisterValues(const lldb::DataBufferSP &data_sp) override;
54 
56  uint32_t num) override;
57 
59 
60  uint32_t SetHardwareWatchpoint(lldb::addr_t addr, size_t size, bool read,
61  bool write) override;
62 
63  bool ClearHardwareWatchpoint(uint32_t hw_index) override;
64 
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
73  };
74 
75  struct VReg {
76  alignas(16) char bytes[16];
77  };
78 
79  // mirrors <mach/arm/thread_status.h> arm_neon_state64_t
80  struct FPU {
81  VReg v[32];
84  };
85 
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
91  };
92 
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;
100  };
101 
102  static void LogDBGRegisters(lldb_private::Log *log, const DBG &dbg);
103 
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
110  };
111 
112  enum {
113  GPRWordCount = sizeof(GPR) / sizeof(uint32_t), // ARM_THREAD_STATE64_COUNT
114  FPUWordCount = sizeof(FPU) / sizeof(uint32_t), // ARM_NEON_STATE64_COUNT
116  sizeof(EXC) / sizeof(uint32_t), // ARM_EXCEPTION_STATE64_COUNT
117  DBGWordCount = sizeof(DBG) / sizeof(uint32_t) // ARM_DEBUG_STATE64_COUNT
118  };
119 
120  enum { Read = 0, Write = 1, kNumErrors = 2 };
121 
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
130 
132  SetError(GPRRegSet, Read, -1);
133  SetError(FPURegSet, Read, -1);
134  SetError(EXCRegSet, Read, -1);
135  }
136 
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;
152  }
153  }
154  return -1;
155  }
156 
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;
163 
164  case FPURegSet:
165  fpu_errs[err_idx] = err;
166  return true;
167 
168  case EXCRegSet:
169  exc_errs[err_idx] = err;
170  return true;
171 
172  case DBGRegSet:
173  exc_errs[err_idx] = err;
174  return true;
175 
176  default:
177  break;
178  }
179  }
180  return false;
181  }
182 
183  bool RegisterSetIsCached(int set) const { return GetError(set, Read) == 0; }
184 
185  int ReadGPR(bool force);
186 
187  int ReadFPU(bool force);
188 
189  int ReadEXC(bool force);
190 
191  int ReadDBG(bool force);
192 
193  int WriteGPR();
194 
195  int WriteFPU();
196 
197  int WriteEXC();
198 
199  int WriteDBG();
200 
201  // Subclasses override these to do the actual reading.
202  virtual int DoReadGPR(lldb::tid_t tid, int flavor, GPR &gpr) { return -1; }
203 
204  virtual int DoReadFPU(lldb::tid_t tid, int flavor, FPU &fpu) = 0;
205 
206  virtual int DoReadEXC(lldb::tid_t tid, int flavor, EXC &exc) = 0;
207 
208  virtual int DoReadDBG(lldb::tid_t tid, int flavor, DBG &dbg) = 0;
209 
210  virtual int DoWriteGPR(lldb::tid_t tid, int flavor, const GPR &gpr) = 0;
211 
212  virtual int DoWriteFPU(lldb::tid_t tid, int flavor, const FPU &fpu) = 0;
213 
214  virtual int DoWriteEXC(lldb::tid_t tid, int flavor, const EXC &exc) = 0;
215 
216  virtual int DoWriteDBG(lldb::tid_t tid, int flavor, const DBG &dbg) = 0;
217 
218  int ReadRegisterSet(uint32_t set, bool force);
219 
221 
222  static uint32_t GetRegisterNumber(uint32_t reg_kind, uint32_t reg_num);
223 
224  static int GetSetForNativeRegNum(int reg_num);
225 
226  static size_t GetRegisterInfosCount();
227 
228  static const lldb_private::RegisterInfo *GetRegisterInfos();
229 };
230 
231 #endif // LLDB_SOURCE_PLUGINS_PROCESS_UTILITY_REGISTERCONTEXTDARWIN_ARM64_H
RegisterContextDarwin_arm64::WriteFPU
int WriteFPU()
Definition: RegisterContextDarwin_arm64.cpp:215
DBG
Definition: RegisterContextFreeBSD_i386.cpp:38
RegisterContextDarwin_arm64::FPUWordCount
@ FPUWordCount
Definition: RegisterContextDarwin_arm64.h:114
RegisterContextDarwin_arm64::ConvertRegisterKindToRegisterNumber
uint32_t ConvertRegisterKindToRegisterNumber(lldb::RegisterKind kind, uint32_t num) override
Convert from a given register numbering scheme to the lldb register numbering scheme.
Definition: RegisterContextDarwin_arm64.cpp:686
lldb_private::RegisterValue
Definition: RegisterValue.h:28
RegisterContextDarwin_arm64::Write
@ Write
Definition: RegisterContextDarwin_arm64.h:120
RegisterContextDarwin_arm64::InvalidateAllRegisters
void InvalidateAllRegisters() override
Definition: RegisterContextDarwin_arm64.cpp:109
RegisterContextDarwin_arm64::WriteDBG
int WriteDBG()
Definition: RegisterContextDarwin_arm64.cpp:237
RegisterContextDarwin_arm64::~RegisterContextDarwin_arm64
~RegisterContextDarwin_arm64() override
RegisterContextDarwin_arm64::dbg_errs
int dbg_errs[2]
Definition: RegisterContextDarwin_arm64.h:129
RegisterContextDarwin_arm64::ReadFPU
int ReadFPU(bool force)
Definition: RegisterContextDarwin_arm64.cpp:180
RegisterContextDarwin_arm64::GetRegisterCount
size_t GetRegisterCount() override
Definition: RegisterContextDarwin_arm64.cpp:113
RegisterContextDarwin_arm64::InvalidateAllRegisterStates
void InvalidateAllRegisterStates()
Definition: RegisterContextDarwin_arm64.h:131
RegisterContextDarwin_arm64::DoWriteGPR
virtual int DoWriteGPR(lldb::tid_t tid, int flavor, const GPR &gpr)=0
RegisterContextDarwin_arm64::EXCWordCount
@ EXCWordCount
Definition: RegisterContextDarwin_arm64.h:115
lldb::addr_t
uint64_t addr_t
Definition: lldb-types.h:83
RegisterContextDarwin_arm64::FPU::fpsr
uint32_t fpsr
Definition: RegisterContextDarwin_arm64.h:82
RegisterContextDarwin_arm64::GetRegisterSetCount
size_t GetRegisterSetCount() override
Definition: RegisterContextDarwin_arm64.cpp:151
RegisterContextDarwin_arm64::DBG::wcr
uint64_t wcr[16]
Definition: RegisterContextDarwin_arm64.h:98
RegisterContextDarwin_arm64::RegisterContextDarwin_arm64
RegisterContextDarwin_arm64(lldb_private::Thread &thread, uint32_t concrete_frame_idx)
Definition: RegisterContextDarwin_arm64.cpp:96
RegisterContextDarwin_arm64
Definition: RegisterContextDarwin_arm64.h:28
RegisterContextDarwin_arm64::GPR::lr
uint64_t lr
Definition: RegisterContextDarwin_arm64.h:69
RegisterContextDarwin_arm64::gpr
GPR gpr
Definition: RegisterContextDarwin_arm64.h:122
RegisterContextDarwin_arm64::EXC
Definition: RegisterContextDarwin_arm64.h:87
RegisterContextDarwin_arm64::exc_errs
int exc_errs[2]
Definition: RegisterContextDarwin_arm64.h:128
RegisterContextDarwin_arm64::GPR::cpsr
uint32_t cpsr
Definition: RegisterContextDarwin_arm64.h:72
RegisterContextDarwin_arm64::kNumErrors
@ kNumErrors
Definition: RegisterContextDarwin_arm64.h:120
RegisterContextDarwin_arm64::DoWriteDBG
virtual int DoWriteDBG(lldb::tid_t tid, int flavor, const DBG &dbg)=0
GPR
struct _GPR GPR
RegisterContextDarwin_arm64::GPR::fp
uint64_t fp
Definition: RegisterContextDarwin_arm64.h:68
RegisterContextDarwin_arm64::EXC::far
uint64_t far
Definition: RegisterContextDarwin_arm64.h:88
RegisterContextDarwin_arm64::GPRRegSet
@ GPRRegSet
Definition: RegisterContextDarwin_arm64.h:106
lldb_private::Thread
Definition: Thread.h:62
RegisterContextDarwin_arm64::DoReadFPU
virtual int DoReadFPU(lldb::tid_t tid, int flavor, FPU &fpu)=0
RegisterContextDarwin_arm64::EXC::esr
uint32_t esr
Definition: RegisterContextDarwin_arm64.h:89
RegisterContextDarwin_arm64::DoWriteEXC
virtual int DoWriteEXC(lldb::tid_t tid, int flavor, const EXC &exc)=0
RegisterContextDarwin_arm64::DoReadEXC
virtual int DoReadEXC(lldb::tid_t tid, int flavor, EXC &exc)=0
RegisterContextDarwin_arm64::WriteGPR
int WriteGPR()
Definition: RegisterContextDarwin_arm64.cpp:204
RegisterContextDarwin_arm64::GPR::x
uint64_t x[29]
Definition: RegisterContextDarwin_arm64.h:67
RegisterContextDarwin_arm64::ReadRegisterSet
int ReadRegisterSet(uint32_t set, bool force)
Definition: RegisterContextDarwin_arm64.cpp:248
RegisterContextDarwin_arm64::EXCRegSet
@ EXCRegSet
Definition: RegisterContextDarwin_arm64.h:108
RegisterContextDarwin_arm64::DBG::wvr
uint64_t wvr[16]
Definition: RegisterContextDarwin_arm64.h:97
RegisterContextDarwin_arm64::DoWriteFPU
virtual int DoWriteFPU(lldb::tid_t tid, int flavor, const FPU &fpu)=0
RegisterContextDarwin_arm64::DoReadGPR
virtual int DoReadGPR(lldb::tid_t tid, int flavor, GPR &gpr)
Definition: RegisterContextDarwin_arm64.h:202
RegisterContextDarwin_arm64::Read
@ Read
Definition: RegisterContextDarwin_arm64.h:120
set
set(option_framework FRAMEWORK) endif() if(LLDB_ENABLE_PYTHON) get_target_property(python_bindings_dir swig_wrapper_python BINARY_DIR) set(lldb_python_wrapper $
Definition: API/CMakeLists.txt:9
RegisterContextDarwin_arm64::ClearHardwareWatchpoint
bool ClearHardwareWatchpoint(uint32_t hw_index) override
Definition: RegisterContextDarwin_arm64.cpp:1019
lldb_private::RegisterContext
Definition: RegisterContext.h:17
RegisterContextDarwin_arm64::DoReadDBG
virtual int DoReadDBG(lldb::tid_t tid, int flavor, DBG &dbg)=0
lldb::RegisterKind
RegisterKind
Register numbering types.
Definition: lldb-enumerations.h:227
lldb-private.h
RegisterContextDarwin_arm64::NumSupportedHardwareWatchpoints
uint32_t NumSupportedHardwareWatchpoints() override
Definition: RegisterContextDarwin_arm64.cpp:920
RegisterContextDarwin_arm64::ReadEXC
int ReadEXC(bool force)
Definition: RegisterContextDarwin_arm64.cpp:188
RegisterContextDarwin_arm64::GetRegisterSet
const lldb_private::RegisterSet * GetRegisterSet(size_t set) override
Definition: RegisterContextDarwin_arm64.cpp:155
RegisterContextDarwin_arm64::WriteRegister
bool WriteRegister(const lldb_private::RegisterInfo *reg_info, const lldb_private::RegisterValue &reg_value) override
Definition: RegisterContextDarwin_arm64.cpp:536
RegisterContextDarwin_arm64::GetRegisterInfos
static const lldb_private::RegisterInfo * GetRegisterInfos()
Definition: RegisterContextDarwin_arm64.cpp:130
RegisterContextDarwin_arm64::SetError
bool SetError(int flavor, uint32_t err_idx, int err)
Definition: RegisterContextDarwin_arm64.h:157
RegisterContextDarwin_arm64::FPURegSet
@ FPURegSet
Definition: RegisterContextDarwin_arm64.h:107
RegisterContextDarwin_arm64::VReg
Definition: RegisterContextDarwin_arm64.h:75
RegisterContextDarwin_arm64::fpu_errs
int fpu_errs[2]
Definition: RegisterContextDarwin_arm64.h:127
GPR
Definition: RegisterContextFreeBSD_i386.cpp:16
RegisterContextDarwin_arm64::DBG
Definition: RegisterContextDarwin_arm64.h:94
RegisterContextDarwin_arm64::GPR::sp
uint64_t sp
Definition: RegisterContextDarwin_arm64.h:70
RegisterContextDarwin_arm64::dbg
DBG dbg
Definition: RegisterContextDarwin_arm64.h:125
uint32_t
RegisterContextDarwin_arm64::gpr_errs
int gpr_errs[2]
Definition: RegisterContextDarwin_arm64.h:126
RegisterContextDarwin_arm64::FPU::v
VReg v[32]
Definition: RegisterContextDarwin_arm64.h:81
RegisterContextDarwin_arm64::DBG::bcr
uint64_t bcr[16]
Definition: RegisterContextDarwin_arm64.h:96
RegisterContextDarwin_arm64::GetRegisterNumber
static uint32_t GetRegisterNumber(uint32_t reg_kind, uint32_t reg_num)
RegisterContextDarwin_arm64::GPR
Definition: RegisterContextDarwin_arm64.h:66
RegisterContextDarwin_arm64::WriteEXC
int WriteEXC()
Definition: RegisterContextDarwin_arm64.cpp:226
RegisterContextDarwin_arm64::ReadAllRegisterValues
bool ReadAllRegisterValues(lldb::DataBufferSP &data_sp) override
Definition: RegisterContextDarwin_arm64.cpp:645
RegisterContextDarwin_arm64::RegisterSetIsCached
bool RegisterSetIsCached(int set) const
Definition: RegisterContextDarwin_arm64.h:183
RegisterContextDarwin_arm64::GPR::pc
uint64_t pc
Definition: RegisterContextDarwin_arm64.h:71
RegisterContextDarwin_arm64::ReadDBG
int ReadDBG(bool force)
Definition: RegisterContextDarwin_arm64.cpp:196
RegisterContextDarwin_arm64::WriteAllRegisterValues
bool WriteAllRegisterValues(const lldb::DataBufferSP &data_sp) override
Definition: RegisterContextDarwin_arm64.cpp:663
RegisterContextDarwin_arm64::GPRWordCount
@ GPRWordCount
Definition: RegisterContextDarwin_arm64.h:113
RegisterContextDarwin_arm64::DBG::bvr
uint64_t bvr[16]
Definition: RegisterContextDarwin_arm64.h:95
RegisterContextDarwin_arm64::EXC::exception
uint32_t exception
Definition: RegisterContextDarwin_arm64.h:90
RegisterContextDarwin_arm64::LogDBGRegisters
static void LogDBGRegisters(lldb_private::Log *log, const DBG &dbg)
Definition: RegisterContextDarwin_arm64.cpp:283
RegisterContextDarwin_arm64::FPU::fpcr
uint32_t fpcr
Definition: RegisterContextDarwin_arm64.h:83
RegisterContextDarwin_arm64::FPU
Definition: RegisterContextDarwin_arm64.h:80
RegisterContextDarwin_arm64::DBGWordCount
@ DBGWordCount
Definition: RegisterContextDarwin_arm64.h:117
RegisterContextDarwin_arm64::exc
EXC exc
Definition: RegisterContextDarwin_arm64.h:124
RegisterContextDarwin_arm64::SetHardwareWatchpoint
uint32_t SetHardwareWatchpoint(lldb::addr_t addr, size_t size, bool read, bool write) override
Definition: RegisterContextDarwin_arm64.cpp:939
lldb_private::Log
Definition: Log.h:49
RegisterContextDarwin_arm64::GetSetForNativeRegNum
static int GetSetForNativeRegNum(int reg_num)
Definition: RegisterContextDarwin_arm64.cpp:162
RegisterContextDarwin_arm64::VReg::bytes
char bytes[16]
Definition: RegisterContextDarwin_arm64.h:76
RegisterContextDarwin_arm64::DBGRegSet
@ DBGRegSet
Definition: RegisterContextDarwin_arm64.h:109
RegisterContextDarwin_arm64::GetRegisterInfosCount
static size_t GetRegisterInfosCount()
Definition: RegisterContextDarwin_arm64.cpp:126
RegisterContextDarwin_arm64::ReadGPR
int ReadGPR(bool force)
Definition: RegisterContextDarwin_arm64.cpp:172
RegisterContextDarwin_arm64::ReadRegister
bool ReadRegister(const lldb_private::RegisterInfo *reg_info, lldb_private::RegisterValue &reg_value) override
Definition: RegisterContextDarwin_arm64.cpp:294
RegisterContextDarwin_arm64::GetError
int GetError(int flavor, uint32_t err_idx) const
Definition: RegisterContextDarwin_arm64.h:137
RegisterContextDarwin_arm64::DBG::mdscr_el1
uint64_t mdscr_el1
Definition: RegisterContextDarwin_arm64.h:99
RegisterContext.h
RegisterContextDarwin_arm64::fpu
FPU fpu
Definition: RegisterContextDarwin_arm64.h:123
RegisterContextDarwin_arm64::GetRegisterInfoAtIndex
const lldb_private::RegisterInfo * GetRegisterInfoAtIndex(size_t reg) override
Definition: RegisterContextDarwin_arm64.cpp:119
RegisterContextDarwin_arm64::WriteRegisterSet
int WriteRegisterSet(uint32_t set)
Definition: RegisterContextDarwin_arm64.cpp:264
lldb::tid_t
uint64_t tid_t
Definition: lldb-types.h:86