LLDB  mainline
RegisterContextDarwin_x86_64.h
Go to the documentation of this file.
1 //===-- RegisterContextDarwin_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 #ifndef LLDB_SOURCE_PLUGINS_PROCESS_UTILITY_REGISTERCONTEXTDARWIN_X86_64_H
10 #define LLDB_SOURCE_PLUGINS_PROCESS_UTILITY_REGISTERCONTEXTDARWIN_X86_64_H
11 
13 #include "lldb/lldb-private.h"
14 
16 public:
18  uint32_t concrete_frame_idx);
19 
21 
22  void InvalidateAllRegisters() override;
23 
24  size_t GetRegisterCount() override;
25 
26  const lldb_private::RegisterInfo *GetRegisterInfoAtIndex(size_t reg) override;
27 
28  size_t GetRegisterSetCount() override;
29 
30  const lldb_private::RegisterSet *GetRegisterSet(size_t set) override;
31 
32  bool ReadRegister(const lldb_private::RegisterInfo *reg_info,
33  lldb_private::RegisterValue &value) override;
34 
35  bool WriteRegister(const lldb_private::RegisterInfo *reg_info,
36  const lldb_private::RegisterValue &value) override;
37 
38  bool ReadAllRegisterValues(lldb::DataBufferSP &data_sp) override;
39 
40  bool WriteAllRegisterValues(const lldb::DataBufferSP &data_sp) override;
41 
43  uint32_t num) override;
44 
45  bool HardwareSingleStep(bool enable) override;
46 
47  struct GPR {
48  uint64_t rax;
49  uint64_t rbx;
50  uint64_t rcx;
51  uint64_t rdx;
52  uint64_t rdi;
53  uint64_t rsi;
54  uint64_t rbp;
55  uint64_t rsp;
56  uint64_t r8;
57  uint64_t r9;
58  uint64_t r10;
59  uint64_t r11;
60  uint64_t r12;
61  uint64_t r13;
62  uint64_t r14;
63  uint64_t r15;
64  uint64_t rip;
65  uint64_t rflags;
66  uint64_t cs;
67  uint64_t fs;
68  uint64_t gs;
69  };
70 
71  struct MMSReg {
72  uint8_t bytes[10];
73  uint8_t pad[6];
74  };
75 
76  struct XMMReg {
77  uint8_t bytes[16];
78  };
79 
80  struct FPU {
82  uint16_t fcw; // "fctrl"
83  uint16_t fsw; // "fstat"
84  uint8_t ftw; // "ftag"
85  uint8_t pad1;
86  uint16_t fop; // "fop"
87  uint32_t ip; // "fioff"
88  uint16_t cs; // "fiseg"
90  uint32_t dp; // "fooff"
91  uint16_t ds; // "foseg"
96  XMMReg xmm[16];
97  uint8_t pad4[6 * 16];
98  int pad5;
99  };
100 
101  struct EXC {
104  uint64_t faultvaddr;
105  };
106 
107 protected:
108  enum { GPRRegSet = 4, FPURegSet = 5, EXCRegSet = 6 };
109 
110  enum {
111  GPRWordCount = sizeof(GPR) / sizeof(uint32_t),
112  FPUWordCount = sizeof(FPU) / sizeof(uint32_t),
113  EXCWordCount = sizeof(EXC) / sizeof(uint32_t)
114  };
115 
116  enum { Read = 0, Write = 1, kNumErrors = 2 };
117 
121  int gpr_errs[2]; // Read/Write errors
122  int fpu_errs[2]; // Read/Write errors
123  int exc_errs[2]; // Read/Write errors
124 
126  SetError(GPRRegSet, Read, -1);
127  SetError(FPURegSet, Read, -1);
128  SetError(EXCRegSet, Read, -1);
129  }
130 
131  int GetError(int flavor, uint32_t err_idx) const {
132  if (err_idx < kNumErrors) {
133  switch (flavor) {
134  // When getting all errors, just OR all values together to see if
135  // we got any kind of error.
136  case GPRRegSet:
137  return gpr_errs[err_idx];
138  case FPURegSet:
139  return fpu_errs[err_idx];
140  case EXCRegSet:
141  return exc_errs[err_idx];
142  default:
143  break;
144  }
145  }
146  return -1;
147  }
148 
149  bool SetError(int flavor, uint32_t err_idx, int err) {
150  if (err_idx < kNumErrors) {
151  switch (flavor) {
152  case GPRRegSet:
153  gpr_errs[err_idx] = err;
154  return true;
155 
156  case FPURegSet:
157  fpu_errs[err_idx] = err;
158  return true;
159 
160  case EXCRegSet:
161  exc_errs[err_idx] = err;
162  return true;
163 
164  default:
165  break;
166  }
167  }
168  return false;
169  }
170 
171  bool RegisterSetIsCached(int set) const { return GetError(set, Read) == 0; }
172 
173  void LogGPR(lldb_private::Log *log, const char *format, ...);
174 
175  int ReadGPR(bool force);
176 
177  int ReadFPU(bool force);
178 
179  int ReadEXC(bool force);
180 
181  int WriteGPR();
182 
183  int WriteFPU();
184 
185  int WriteEXC();
186 
187  // Subclasses override these to do the actual reading.
188  virtual int DoReadGPR(lldb::tid_t tid, int flavor, GPR &gpr) = 0;
189 
190  virtual int DoReadFPU(lldb::tid_t tid, int flavor, FPU &fpu) = 0;
191 
192  virtual int DoReadEXC(lldb::tid_t tid, int flavor, EXC &exc) = 0;
193 
194  virtual int DoWriteGPR(lldb::tid_t tid, int flavor, const GPR &gpr) = 0;
195 
196  virtual int DoWriteFPU(lldb::tid_t tid, int flavor, const FPU &fpu) = 0;
197 
198  virtual int DoWriteEXC(lldb::tid_t tid, int flavor, const EXC &exc) = 0;
199 
200  int ReadRegisterSet(uint32_t set, bool force);
201 
203 
204  static uint32_t GetRegisterNumber(uint32_t reg_kind, uint32_t reg_num);
205 
206  static int GetSetForNativeRegNum(int reg_num);
207 
208  static size_t GetRegisterInfosCount();
209 
210  static const lldb_private::RegisterInfo *GetRegisterInfos();
211 };
212 
213 #endif // LLDB_SOURCE_PLUGINS_PROCESS_UTILITY_REGISTERCONTEXTDARWIN_X86_64_H
RegisterContextDarwin_x86_64::FPU::ftw
uint8_t ftw
Definition: RegisterContextDarwin_x86_64.h:84
RegisterContextDarwin_x86_64::FPU::mxcsrmask
uint32_t mxcsrmask
Definition: RegisterContextDarwin_x86_64.h:94
RegisterContextDarwin_x86_64::ReadGPR
int ReadGPR(bool force)
Definition: RegisterContextDarwin_x86_64.cpp:551
RegisterContextDarwin_x86_64::GPR::rsp
uint64_t rsp
Definition: RegisterContextDarwin_x86_64.h:55
RegisterContextDarwin_x86_64::DoWriteFPU
virtual int DoWriteFPU(lldb::tid_t tid, int flavor, const FPU &fpu)=0
RegisterContextDarwin_x86_64::RegisterSetIsCached
bool RegisterSetIsCached(int set) const
Definition: RegisterContextDarwin_x86_64.h:171
RegisterContextDarwin_x86_64::GetRegisterInfos
static const lldb_private::RegisterInfo * GetRegisterInfos()
Definition: RegisterContextDarwin_x86_64.cpp:494
lldb_private::RegisterValue
Definition: RegisterValue.h:28
RegisterContextDarwin_x86_64::fpu
FPU fpu
Definition: RegisterContextDarwin_x86_64.h:119
RegisterContextDarwin_x86_64::GPR::rax
uint64_t rax
Definition: RegisterContextDarwin_x86_64.h:48
RegisterContextDarwin_x86_64::ReadRegisterSet
int ReadRegisterSet(uint32_t set, bool force)
Definition: RegisterContextDarwin_x86_64.cpp:608
RegisterContextDarwin_x86_64::XMMReg::bytes
uint8_t bytes[16]
Definition: RegisterContextDarwin_x86_64.h:77
RegisterContextDarwin_x86_64::HardwareSingleStep
bool HardwareSingleStep(bool enable) override
Definition: RegisterContextDarwin_x86_64.cpp:1037
RegisterContextDarwin_x86_64::GPR::rbp
uint64_t rbp
Definition: RegisterContextDarwin_x86_64.h:54
RegisterContextDarwin_x86_64::GPR::r9
uint64_t r9
Definition: RegisterContextDarwin_x86_64.h:57
RegisterContextDarwin_x86_64::FPU::mxcsr
uint32_t mxcsr
Definition: RegisterContextDarwin_x86_64.h:93
RegisterContextDarwin_x86_64::FPU::fcw
uint16_t fcw
Definition: RegisterContextDarwin_x86_64.h:82
RegisterContextDarwin_x86_64::fpu_errs
int fpu_errs[2]
Definition: RegisterContextDarwin_x86_64.h:122
RegisterContextDarwin_x86_64::EXC::trapno
uint32_t trapno
Definition: RegisterContextDarwin_x86_64.h:102
RegisterContextDarwin_x86_64::MMSReg::bytes
uint8_t bytes[10]
Definition: RegisterContextDarwin_x86_64.h:72
RegisterContextDarwin_x86_64::GetRegisterSetCount
size_t GetRegisterSetCount() override
Definition: RegisterContextDarwin_x86_64.cpp:530
RegisterContextDarwin_x86_64::GPR
Definition: RegisterContextDarwin_x86_64.h:47
RegisterContextDarwin_x86_64::GetRegisterNumber
static uint32_t GetRegisterNumber(uint32_t reg_kind, uint32_t reg_num)
RegisterContextDarwin_x86_64::FPUWordCount
@ FPUWordCount
Definition: RegisterContextDarwin_x86_64.h:112
RegisterContextDarwin_x86_64::GPR::cs
uint64_t cs
Definition: RegisterContextDarwin_x86_64.h:66
RegisterContextDarwin_x86_64::GPR::rbx
uint64_t rbx
Definition: RegisterContextDarwin_x86_64.h:49
RegisterContextDarwin_x86_64::FPU::pad5
int pad5
Definition: RegisterContextDarwin_x86_64.h:98
RegisterContextDarwin_x86_64::DoWriteGPR
virtual int DoWriteGPR(lldb::tid_t tid, int flavor, const GPR &gpr)=0
GPR
struct _GPR GPR
RegisterContextDarwin_x86_64::FPU::stmm
MMSReg stmm[8]
Definition: RegisterContextDarwin_x86_64.h:95
RegisterContextDarwin_x86_64::WriteAllRegisterValues
bool WriteAllRegisterValues(const lldb::DataBufferSP &data_sp) override
Definition: RegisterContextDarwin_x86_64.cpp:905
RegisterContextDarwin_x86_64::MMSReg::pad
uint8_t pad[6]
Definition: RegisterContextDarwin_x86_64.h:73
RegisterContextDarwin_x86_64::XMMReg
Definition: RegisterContextDarwin_x86_64.h:76
RegisterContextDarwin_x86_64::GetRegisterInfoAtIndex
const lldb_private::RegisterInfo * GetRegisterInfoAtIndex(size_t reg) override
Definition: RegisterContextDarwin_x86_64.cpp:482
RegisterContextDarwin_x86_64::FPU::dp
uint32_t dp
Definition: RegisterContextDarwin_x86_64.h:90
RegisterContextDarwin_x86_64::FPU::pad3
uint16_t pad3
Definition: RegisterContextDarwin_x86_64.h:92
RegisterContextDarwin_x86_64::FPU::pad2
uint16_t pad2
Definition: RegisterContextDarwin_x86_64.h:89
lldb_private::Thread
Definition: Thread.h:62
RegisterContextDarwin_x86_64::exc_errs
int exc_errs[2]
Definition: RegisterContextDarwin_x86_64.h:123
RegisterContextDarwin_x86_64::GPR::r14
uint64_t r14
Definition: RegisterContextDarwin_x86_64.h:62
RegisterContextDarwin_x86_64::DoReadFPU
virtual int DoReadFPU(lldb::tid_t tid, int flavor, FPU &fpu)=0
RegisterContextDarwin_x86_64::EXC::err
uint32_t err
Definition: RegisterContextDarwin_x86_64.h:103
RegisterContextDarwin_x86_64::GPR::r10
uint64_t r10
Definition: RegisterContextDarwin_x86_64.h:58
RegisterContextDarwin_x86_64::GetRegisterCount
size_t GetRegisterCount() override
Definition: RegisterContextDarwin_x86_64.cpp:476
RegisterContextDarwin_x86_64::GPR::fs
uint64_t fs
Definition: RegisterContextDarwin_x86_64.h:67
RegisterContextDarwin_x86_64::GPR::rsi
uint64_t rsi
Definition: RegisterContextDarwin_x86_64.h:53
RegisterContextDarwin_x86_64::GPR::rcx
uint64_t rcx
Definition: RegisterContextDarwin_x86_64.h:50
RegisterContextDarwin_x86_64::GPRRegSet
@ GPRRegSet
Definition: RegisterContextDarwin_x86_64.h:108
RegisterContextDarwin_x86_64::ReadEXC
int ReadEXC(bool force)
Definition: RegisterContextDarwin_x86_64.cpp:567
RegisterContextDarwin_x86_64::GPR::r11
uint64_t r11
Definition: RegisterContextDarwin_x86_64.h:59
RegisterContextDarwin_x86_64::EXCWordCount
@ EXCWordCount
Definition: RegisterContextDarwin_x86_64.h:113
RegisterContextDarwin_x86_64::GPR::r15
uint64_t r15
Definition: RegisterContextDarwin_x86_64.h:63
RegisterContextDarwin_x86_64::GetSetForNativeRegNum
static int GetSetForNativeRegNum(int reg_num)
Definition: RegisterContextDarwin_x86_64.cpp:541
RegisterContextDarwin_x86_64::WriteRegisterSet
int WriteRegisterSet(uint32_t set)
Definition: RegisterContextDarwin_x86_64.cpp:622
RegisterContextDarwin_x86_64::FPU::xmm
XMMReg xmm[16]
Definition: RegisterContextDarwin_x86_64.h:96
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_x86_64::GPR::rdi
uint64_t rdi
Definition: RegisterContextDarwin_x86_64.h:52
RegisterContextDarwin_x86_64::GPR::r12
uint64_t r12
Definition: RegisterContextDarwin_x86_64.h:60
RegisterContextDarwin_x86_64::GPR::rdx
uint64_t rdx
Definition: RegisterContextDarwin_x86_64.h:51
lldb_private::RegisterContext
Definition: RegisterContext.h:17
lldb::RegisterKind
RegisterKind
Register numbering types.
Definition: lldb-enumerations.h:227
lldb-private.h
RegisterContextDarwin_x86_64::EXC::faultvaddr
uint64_t faultvaddr
Definition: RegisterContextDarwin_x86_64.h:104
RegisterContextDarwin_x86_64::ReadRegister
bool ReadRegister(const lldb_private::RegisterInfo *reg_info, lldb_private::RegisterValue &value) override
Definition: RegisterContextDarwin_x86_64.cpp:637
RegisterContextDarwin_x86_64::DoReadEXC
virtual int DoReadEXC(lldb::tid_t tid, int flavor, EXC &exc)=0
RegisterContextDarwin_x86_64::FPU::ds
uint16_t ds
Definition: RegisterContextDarwin_x86_64.h:91
RegisterContextDarwin_x86_64::InvalidateAllRegisterStates
void InvalidateAllRegisterStates()
Definition: RegisterContextDarwin_x86_64.h:125
GPR
Definition: RegisterContextFreeBSD_i386.cpp:16
RegisterContextDarwin_x86_64::GPR::r8
uint64_t r8
Definition: RegisterContextDarwin_x86_64.h:56
RegisterContextDarwin_x86_64::EXC
Definition: RegisterContextDarwin_x86_64.h:101
RegisterContextDarwin_x86_64::~RegisterContextDarwin_x86_64
~RegisterContextDarwin_x86_64() override
RegisterContextDarwin_x86_64::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_x86_64.cpp:928
RegisterContextDarwin_x86_64::ReadAllRegisterValues
bool ReadAllRegisterValues(lldb::DataBufferSP &data_sp) override
Definition: RegisterContextDarwin_x86_64.cpp:888
RegisterContextDarwin_x86_64::WriteEXC
int WriteEXC()
Definition: RegisterContextDarwin_x86_64.cpp:597
RegisterContextDarwin_x86_64::kNumErrors
@ kNumErrors
Definition: RegisterContextDarwin_x86_64.h:116
RegisterContextDarwin_x86_64::GPR::r13
uint64_t r13
Definition: RegisterContextDarwin_x86_64.h:61
uint32_t
RegisterContextDarwin_x86_64::GPR::rip
uint64_t rip
Definition: RegisterContextDarwin_x86_64.h:64
RegisterContextDarwin_x86_64::FPU::cs
uint16_t cs
Definition: RegisterContextDarwin_x86_64.h:88
RegisterContextDarwin_x86_64::gpr_errs
int gpr_errs[2]
Definition: RegisterContextDarwin_x86_64.h:121
RegisterContextDarwin_x86_64::FPU::fsw
uint16_t fsw
Definition: RegisterContextDarwin_x86_64.h:83
RegisterContextDarwin_x86_64::ReadFPU
int ReadFPU(bool force)
Definition: RegisterContextDarwin_x86_64.cpp:559
RegisterContextDarwin_x86_64
Definition: RegisterContextDarwin_x86_64.h:15
RegisterContextDarwin_x86_64::GPR::gs
uint64_t gs
Definition: RegisterContextDarwin_x86_64.h:68
uint16_t
RegisterContextDarwin_x86_64::FPU::ip
uint32_t ip
Definition: RegisterContextDarwin_x86_64.h:87
RegisterContextDarwin_x86_64::RegisterContextDarwin_x86_64
RegisterContextDarwin_x86_64(lldb_private::Thread &thread, uint32_t concrete_frame_idx)
Definition: RegisterContextDarwin_x86_64.cpp:459
RegisterContextDarwin_x86_64::Write
@ Write
Definition: RegisterContextDarwin_x86_64.h:116
RegisterContextDarwin_x86_64::LogGPR
void LogGPR(lldb_private::Log *log, const char *format,...)
RegisterContextDarwin_x86_64::FPU::pad
uint32_t pad[2]
Definition: RegisterContextDarwin_x86_64.h:81
RegisterContextDarwin_x86_64::GPRWordCount
@ GPRWordCount
Definition: RegisterContextDarwin_x86_64.h:111
RegisterContextDarwin_x86_64::FPU::pad1
uint8_t pad1
Definition: RegisterContextDarwin_x86_64.h:85
RegisterContextDarwin_x86_64::SetError
bool SetError(int flavor, uint32_t err_idx, int err)
Definition: RegisterContextDarwin_x86_64.h:149
RegisterContextDarwin_x86_64::GetRegisterSet
const lldb_private::RegisterSet * GetRegisterSet(size_t set) override
Definition: RegisterContextDarwin_x86_64.cpp:535
RegisterContextDarwin_x86_64::DoReadGPR
virtual int DoReadGPR(lldb::tid_t tid, int flavor, GPR &gpr)=0
RegisterContextDarwin_x86_64::exc
EXC exc
Definition: RegisterContextDarwin_x86_64.h:120
RegisterContextDarwin_x86_64::Read
@ Read
Definition: RegisterContextDarwin_x86_64.h:116
lldb_private::Log
Definition: Log.h:49
RegisterContextDarwin_x86_64::FPU::fop
uint16_t fop
Definition: RegisterContextDarwin_x86_64.h:86
RegisterContextDarwin_x86_64::EXCRegSet
@ EXCRegSet
Definition: RegisterContextDarwin_x86_64.h:108
RegisterContextDarwin_x86_64::WriteFPU
int WriteFPU()
Definition: RegisterContextDarwin_x86_64.cpp:586
RegisterContextDarwin_x86_64::DoWriteEXC
virtual int DoWriteEXC(lldb::tid_t tid, int flavor, const EXC &exc)=0
RegisterContextDarwin_x86_64::GetRegisterInfosCount
static size_t GetRegisterInfosCount()
Definition: RegisterContextDarwin_x86_64.cpp:489
RegisterContextDarwin_x86_64::FPU
Definition: RegisterContextDarwin_x86_64.h:80
RegisterContextDarwin_x86_64::FPURegSet
@ FPURegSet
Definition: RegisterContextDarwin_x86_64.h:108
RegisterContextDarwin_x86_64::InvalidateAllRegisters
void InvalidateAllRegisters() override
Definition: RegisterContextDarwin_x86_64.cpp:472
RegisterContextDarwin_x86_64::gpr
GPR gpr
Definition: RegisterContextDarwin_x86_64.h:118
RegisterContext.h
RegisterContextDarwin_x86_64::WriteGPR
int WriteGPR()
Definition: RegisterContextDarwin_x86_64.cpp:575
RegisterContextDarwin_x86_64::GetError
int GetError(int flavor, uint32_t err_idx) const
Definition: RegisterContextDarwin_x86_64.h:131
RegisterContextDarwin_x86_64::WriteRegister
bool WriteRegister(const lldb_private::RegisterInfo *reg_info, const lldb_private::RegisterValue &value) override
Definition: RegisterContextDarwin_x86_64.cpp:762
RegisterContextDarwin_x86_64::GPR::rflags
uint64_t rflags
Definition: RegisterContextDarwin_x86_64.h:65
lldb::tid_t
uint64_t tid_t
Definition: lldb-types.h:86
RegisterContextDarwin_x86_64::FPU::pad4
uint8_t pad4[6 *16]
Definition: RegisterContextDarwin_x86_64.h:97
RegisterContextDarwin_x86_64::MMSReg
Definition: RegisterContextDarwin_x86_64.h:71