1 //===-- RegisterContextDarwin_x86_64.cpp ----------------------------------===//
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
7 //===----------------------------------------------------------------------===//
15 #include "lldb/Utility/DataBufferHeap.h"
16 #include "lldb/Utility/DataExtractor.h"
17 #include "lldb/Utility/Endian.h"
18 #include "lldb/Utility/Log.h"
19 #include "lldb/Utility/RegisterValue.h"
20 #include "lldb/Utility/Scalar.h"
21 #include "llvm/ADT/STLExtras.h"
22 #include "llvm/Support/Compiler.h"
24 #include "RegisterContextDarwin_x86_64.h"
27 using namespace lldb_private
;
103 enum ehframe_dwarf_regnums
{
104 ehframe_dwarf_gpr_rax
= 0,
105 ehframe_dwarf_gpr_rdx
,
106 ehframe_dwarf_gpr_rcx
,
107 ehframe_dwarf_gpr_rbx
,
108 ehframe_dwarf_gpr_rsi
,
109 ehframe_dwarf_gpr_rdi
,
110 ehframe_dwarf_gpr_rbp
,
111 ehframe_dwarf_gpr_rsp
,
112 ehframe_dwarf_gpr_r8
,
113 ehframe_dwarf_gpr_r9
,
114 ehframe_dwarf_gpr_r10
,
115 ehframe_dwarf_gpr_r11
,
116 ehframe_dwarf_gpr_r12
,
117 ehframe_dwarf_gpr_r13
,
118 ehframe_dwarf_gpr_r14
,
119 ehframe_dwarf_gpr_r15
,
120 ehframe_dwarf_gpr_rip
,
121 ehframe_dwarf_fpu_xmm0
,
122 ehframe_dwarf_fpu_xmm1
,
123 ehframe_dwarf_fpu_xmm2
,
124 ehframe_dwarf_fpu_xmm3
,
125 ehframe_dwarf_fpu_xmm4
,
126 ehframe_dwarf_fpu_xmm5
,
127 ehframe_dwarf_fpu_xmm6
,
128 ehframe_dwarf_fpu_xmm7
,
129 ehframe_dwarf_fpu_xmm8
,
130 ehframe_dwarf_fpu_xmm9
,
131 ehframe_dwarf_fpu_xmm10
,
132 ehframe_dwarf_fpu_xmm11
,
133 ehframe_dwarf_fpu_xmm12
,
134 ehframe_dwarf_fpu_xmm13
,
135 ehframe_dwarf_fpu_xmm14
,
136 ehframe_dwarf_fpu_xmm15
,
137 ehframe_dwarf_fpu_stmm0
,
138 ehframe_dwarf_fpu_stmm1
,
139 ehframe_dwarf_fpu_stmm2
,
140 ehframe_dwarf_fpu_stmm3
,
141 ehframe_dwarf_fpu_stmm4
,
142 ehframe_dwarf_fpu_stmm5
,
143 ehframe_dwarf_fpu_stmm6
,
144 ehframe_dwarf_fpu_stmm7
148 #define GPR_OFFSET(reg) \
149 (LLVM_EXTENSION offsetof(RegisterContextDarwin_x86_64::GPR, reg))
150 #define FPU_OFFSET(reg) \
151 (LLVM_EXTENSION offsetof(RegisterContextDarwin_x86_64::FPU, reg) + \
152 sizeof(RegisterContextDarwin_x86_64::GPR))
153 #define EXC_OFFSET(reg) \
154 (LLVM_EXTENSION offsetof(RegisterContextDarwin_x86_64::EXC, reg) + \
155 sizeof(RegisterContextDarwin_x86_64::GPR) + \
156 sizeof(RegisterContextDarwin_x86_64::FPU))
158 // These macros will auto define the register name, alt name, register size,
159 // register offset, encoding, format and native register. This ensures that the
160 // register state structures are defined correctly and have the correct sizes
162 #define DEFINE_GPR(reg, alt) \
163 #reg, alt, sizeof(((RegisterContextDarwin_x86_64::GPR *) NULL)->reg), \
164 GPR_OFFSET(reg), eEncodingUint, eFormatHex
165 #define DEFINE_FPU_UINT(reg) \
166 #reg, NULL, sizeof(((RegisterContextDarwin_x86_64::FPU *) NULL)->reg), \
167 FPU_OFFSET(reg), eEncodingUint, eFormatHex
168 #define DEFINE_FPU_VECT(reg, i) \
170 sizeof(((RegisterContextDarwin_x86_64::FPU *) NULL)->reg[i].bytes), \
171 FPU_OFFSET(reg[i]), eEncodingVector, eFormatVectorOfUInt8, \
172 {ehframe_dwarf_fpu_##reg##i, \
173 ehframe_dwarf_fpu_##reg##i, LLDB_INVALID_REGNUM, \
174 LLDB_INVALID_REGNUM, fpu_##reg##i }, \
175 nullptr, nullptr, nullptr,
176 #define DEFINE_EXC(reg) \
177 #reg, NULL, sizeof(((RegisterContextDarwin_x86_64::EXC *) NULL)->reg), \
178 EXC_OFFSET(reg), eEncodingUint, eFormatHex
180 #define REG_CONTEXT_SIZE \
181 (sizeof(RegisterContextDarwin_x86_64::GPR) + \
182 sizeof(RegisterContextDarwin_x86_64::FPU) + \
183 sizeof(RegisterContextDarwin_x86_64::EXC))
185 // General purpose registers for 64 bit
186 static RegisterInfo g_register_infos
[] = {
187 // Macro auto defines most stuff EH_FRAME DWARF
188 // GENERIC PROCESS PLUGIN LLDB
189 // =============================== ======================
190 // =================== ========================== ====================
191 // ===================
192 {DEFINE_GPR(rax
, nullptr),
193 {ehframe_dwarf_gpr_rax
, ehframe_dwarf_gpr_rax
, LLDB_INVALID_REGNUM
,
194 LLDB_INVALID_REGNUM
, gpr_rax
},
199 {DEFINE_GPR(rbx
, nullptr),
200 {ehframe_dwarf_gpr_rbx
, ehframe_dwarf_gpr_rbx
, LLDB_INVALID_REGNUM
,
201 LLDB_INVALID_REGNUM
, gpr_rbx
},
206 {DEFINE_GPR(rcx
, nullptr),
207 {ehframe_dwarf_gpr_rcx
, ehframe_dwarf_gpr_rcx
, LLDB_INVALID_REGNUM
,
208 LLDB_INVALID_REGNUM
, gpr_rcx
},
213 {DEFINE_GPR(rdx
, nullptr),
214 {ehframe_dwarf_gpr_rdx
, ehframe_dwarf_gpr_rdx
, LLDB_INVALID_REGNUM
,
215 LLDB_INVALID_REGNUM
, gpr_rdx
},
220 {DEFINE_GPR(rdi
, nullptr),
221 {ehframe_dwarf_gpr_rdi
, ehframe_dwarf_gpr_rdi
, LLDB_INVALID_REGNUM
,
222 LLDB_INVALID_REGNUM
, gpr_rdi
},
227 {DEFINE_GPR(rsi
, nullptr),
228 {ehframe_dwarf_gpr_rsi
, ehframe_dwarf_gpr_rsi
, LLDB_INVALID_REGNUM
,
229 LLDB_INVALID_REGNUM
, gpr_rsi
},
234 {DEFINE_GPR(rbp
, "fp"),
235 {ehframe_dwarf_gpr_rbp
, ehframe_dwarf_gpr_rbp
, LLDB_REGNUM_GENERIC_FP
,
236 LLDB_INVALID_REGNUM
, gpr_rbp
},
241 {DEFINE_GPR(rsp
, "sp"),
242 {ehframe_dwarf_gpr_rsp
, ehframe_dwarf_gpr_rsp
, LLDB_REGNUM_GENERIC_SP
,
243 LLDB_INVALID_REGNUM
, gpr_rsp
},
248 {DEFINE_GPR(r8
, nullptr),
249 {ehframe_dwarf_gpr_r8
, ehframe_dwarf_gpr_r8
, LLDB_INVALID_REGNUM
,
250 LLDB_INVALID_REGNUM
, gpr_r8
},
255 {DEFINE_GPR(r9
, nullptr),
256 {ehframe_dwarf_gpr_r9
, ehframe_dwarf_gpr_r9
, LLDB_INVALID_REGNUM
,
257 LLDB_INVALID_REGNUM
, gpr_r9
},
262 {DEFINE_GPR(r10
, nullptr),
263 {ehframe_dwarf_gpr_r10
, ehframe_dwarf_gpr_r10
, LLDB_INVALID_REGNUM
,
264 LLDB_INVALID_REGNUM
, gpr_r10
},
269 {DEFINE_GPR(r11
, nullptr),
270 {ehframe_dwarf_gpr_r11
, ehframe_dwarf_gpr_r11
, LLDB_INVALID_REGNUM
,
271 LLDB_INVALID_REGNUM
, gpr_r11
},
276 {DEFINE_GPR(r12
, nullptr),
277 {ehframe_dwarf_gpr_r12
, ehframe_dwarf_gpr_r12
, LLDB_INVALID_REGNUM
,
278 LLDB_INVALID_REGNUM
, gpr_r12
},
283 {DEFINE_GPR(r13
, nullptr),
284 {ehframe_dwarf_gpr_r13
, ehframe_dwarf_gpr_r13
, LLDB_INVALID_REGNUM
,
285 LLDB_INVALID_REGNUM
, gpr_r13
},
290 {DEFINE_GPR(r14
, nullptr),
291 {ehframe_dwarf_gpr_r14
, ehframe_dwarf_gpr_r14
, LLDB_INVALID_REGNUM
,
292 LLDB_INVALID_REGNUM
, gpr_r14
},
297 {DEFINE_GPR(r15
, nullptr),
298 {ehframe_dwarf_gpr_r15
, ehframe_dwarf_gpr_r15
, LLDB_INVALID_REGNUM
,
299 LLDB_INVALID_REGNUM
, gpr_r15
},
304 {DEFINE_GPR(rip
, "pc"),
305 {ehframe_dwarf_gpr_rip
, ehframe_dwarf_gpr_rip
, LLDB_REGNUM_GENERIC_PC
,
306 LLDB_INVALID_REGNUM
, gpr_rip
},
311 {DEFINE_GPR(rflags
, "flags"),
312 {LLDB_INVALID_REGNUM
, LLDB_INVALID_REGNUM
, LLDB_REGNUM_GENERIC_FLAGS
,
313 LLDB_INVALID_REGNUM
, gpr_rflags
},
318 {DEFINE_GPR(cs
, nullptr),
319 {LLDB_INVALID_REGNUM
, LLDB_INVALID_REGNUM
, LLDB_INVALID_REGNUM
,
320 LLDB_INVALID_REGNUM
, gpr_cs
},
325 {DEFINE_GPR(fs
, nullptr),
326 {LLDB_INVALID_REGNUM
, LLDB_INVALID_REGNUM
, LLDB_INVALID_REGNUM
,
327 LLDB_INVALID_REGNUM
, gpr_fs
},
332 {DEFINE_GPR(gs
, nullptr),
333 {LLDB_INVALID_REGNUM
, LLDB_INVALID_REGNUM
, LLDB_INVALID_REGNUM
,
334 LLDB_INVALID_REGNUM
, gpr_gs
},
340 {DEFINE_FPU_UINT(fcw
),
341 {LLDB_INVALID_REGNUM
, LLDB_INVALID_REGNUM
, LLDB_INVALID_REGNUM
,
342 LLDB_INVALID_REGNUM
, fpu_fcw
},
347 {DEFINE_FPU_UINT(fsw
),
348 {LLDB_INVALID_REGNUM
, LLDB_INVALID_REGNUM
, LLDB_INVALID_REGNUM
,
349 LLDB_INVALID_REGNUM
, fpu_fsw
},
354 {DEFINE_FPU_UINT(ftw
),
355 {LLDB_INVALID_REGNUM
, LLDB_INVALID_REGNUM
, LLDB_INVALID_REGNUM
,
356 LLDB_INVALID_REGNUM
, fpu_ftw
},
361 {DEFINE_FPU_UINT(fop
),
362 {LLDB_INVALID_REGNUM
, LLDB_INVALID_REGNUM
, LLDB_INVALID_REGNUM
,
363 LLDB_INVALID_REGNUM
, fpu_fop
},
368 {DEFINE_FPU_UINT(ip
),
369 {LLDB_INVALID_REGNUM
, LLDB_INVALID_REGNUM
, LLDB_INVALID_REGNUM
,
370 LLDB_INVALID_REGNUM
, fpu_ip
},
375 {DEFINE_FPU_UINT(cs
),
376 {LLDB_INVALID_REGNUM
, LLDB_INVALID_REGNUM
, LLDB_INVALID_REGNUM
,
377 LLDB_INVALID_REGNUM
, fpu_cs
},
382 {DEFINE_FPU_UINT(dp
),
383 {LLDB_INVALID_REGNUM
, LLDB_INVALID_REGNUM
, LLDB_INVALID_REGNUM
,
384 LLDB_INVALID_REGNUM
, fpu_dp
},
389 {DEFINE_FPU_UINT(ds
),
390 {LLDB_INVALID_REGNUM
, LLDB_INVALID_REGNUM
, LLDB_INVALID_REGNUM
,
391 LLDB_INVALID_REGNUM
, fpu_ds
},
396 {DEFINE_FPU_UINT(mxcsr
),
397 {LLDB_INVALID_REGNUM
, LLDB_INVALID_REGNUM
, LLDB_INVALID_REGNUM
,
398 LLDB_INVALID_REGNUM
, fpu_mxcsr
},
403 {DEFINE_FPU_UINT(mxcsrmask
),
404 {LLDB_INVALID_REGNUM
, LLDB_INVALID_REGNUM
, LLDB_INVALID_REGNUM
,
405 LLDB_INVALID_REGNUM
, fpu_mxcsrmask
},
410 {DEFINE_FPU_VECT(stmm
, 0)},
411 {DEFINE_FPU_VECT(stmm
, 1)},
412 {DEFINE_FPU_VECT(stmm
, 2)},
413 {DEFINE_FPU_VECT(stmm
, 3)},
414 {DEFINE_FPU_VECT(stmm
, 4)},
415 {DEFINE_FPU_VECT(stmm
, 5)},
416 {DEFINE_FPU_VECT(stmm
, 6)},
417 {DEFINE_FPU_VECT(stmm
, 7)},
418 {DEFINE_FPU_VECT(xmm
, 0)},
419 {DEFINE_FPU_VECT(xmm
, 1)},
420 {DEFINE_FPU_VECT(xmm
, 2)},
421 {DEFINE_FPU_VECT(xmm
, 3)},
422 {DEFINE_FPU_VECT(xmm
, 4)},
423 {DEFINE_FPU_VECT(xmm
, 5)},
424 {DEFINE_FPU_VECT(xmm
, 6)},
425 {DEFINE_FPU_VECT(xmm
, 7)},
426 {DEFINE_FPU_VECT(xmm
, 8)},
427 {DEFINE_FPU_VECT(xmm
, 9)},
428 {DEFINE_FPU_VECT(xmm
, 10)},
429 {DEFINE_FPU_VECT(xmm
, 11)},
430 {DEFINE_FPU_VECT(xmm
, 12)},
431 {DEFINE_FPU_VECT(xmm
, 13)},
432 {DEFINE_FPU_VECT(xmm
, 14)},
433 {DEFINE_FPU_VECT(xmm
, 15)},
436 {LLDB_INVALID_REGNUM
, LLDB_INVALID_REGNUM
, LLDB_INVALID_REGNUM
,
437 LLDB_INVALID_REGNUM
, exc_trapno
},
443 {LLDB_INVALID_REGNUM
, LLDB_INVALID_REGNUM
, LLDB_INVALID_REGNUM
,
444 LLDB_INVALID_REGNUM
, exc_err
},
449 {DEFINE_EXC(faultvaddr
),
450 {LLDB_INVALID_REGNUM
, LLDB_INVALID_REGNUM
, LLDB_INVALID_REGNUM
,
451 LLDB_INVALID_REGNUM
, exc_faultvaddr
},
457 static size_t k_num_register_infos
= std::size(g_register_infos
);
459 RegisterContextDarwin_x86_64::RegisterContextDarwin_x86_64(
460 Thread
&thread
, uint32_t concrete_frame_idx
)
461 : RegisterContext(thread
, concrete_frame_idx
), gpr(), fpu(), exc() {
463 for (i
= 0; i
< kNumErrors
; i
++) {
470 RegisterContextDarwin_x86_64::~RegisterContextDarwin_x86_64() = default;
472 void RegisterContextDarwin_x86_64::InvalidateAllRegisters() {
473 InvalidateAllRegisterStates();
476 size_t RegisterContextDarwin_x86_64::GetRegisterCount() {
477 assert(k_num_register_infos
== k_num_registers
);
478 return k_num_registers
;
482 RegisterContextDarwin_x86_64::GetRegisterInfoAtIndex(size_t reg
) {
483 assert(k_num_register_infos
== k_num_registers
);
484 if (reg
< k_num_registers
)
485 return &g_register_infos
[reg
];
489 size_t RegisterContextDarwin_x86_64::GetRegisterInfosCount() {
490 return k_num_register_infos
;
493 const lldb_private::RegisterInfo
*
494 RegisterContextDarwin_x86_64::GetRegisterInfos() {
495 return g_register_infos
;
498 static uint32_t g_gpr_regnums
[] = {
499 gpr_rax
, gpr_rbx
, gpr_rcx
, gpr_rdx
, gpr_rdi
, gpr_rsi
, gpr_rbp
,
500 gpr_rsp
, gpr_r8
, gpr_r9
, gpr_r10
, gpr_r11
, gpr_r12
, gpr_r13
,
501 gpr_r14
, gpr_r15
, gpr_rip
, gpr_rflags
, gpr_cs
, gpr_fs
, gpr_gs
};
503 static uint32_t g_fpu_regnums
[] = {
504 fpu_fcw
, fpu_fsw
, fpu_ftw
, fpu_fop
, fpu_ip
, fpu_cs
,
505 fpu_dp
, fpu_ds
, fpu_mxcsr
, fpu_mxcsrmask
, fpu_stmm0
, fpu_stmm1
,
506 fpu_stmm2
, fpu_stmm3
, fpu_stmm4
, fpu_stmm5
, fpu_stmm6
, fpu_stmm7
,
507 fpu_xmm0
, fpu_xmm1
, fpu_xmm2
, fpu_xmm3
, fpu_xmm4
, fpu_xmm5
,
508 fpu_xmm6
, fpu_xmm7
, fpu_xmm8
, fpu_xmm9
, fpu_xmm10
, fpu_xmm11
,
509 fpu_xmm12
, fpu_xmm13
, fpu_xmm14
, fpu_xmm15
};
511 static uint32_t g_exc_regnums
[] = {exc_trapno
, exc_err
, exc_faultvaddr
};
513 // Number of registers in each register set
514 const size_t k_num_gpr_registers
= std::size(g_gpr_regnums
);
515 const size_t k_num_fpu_registers
= std::size(g_fpu_regnums
);
516 const size_t k_num_exc_registers
= std::size(g_exc_regnums
);
518 // Register set definitions. The first definitions at register set index of
519 // zero is for all registers, followed by other registers sets. The register
520 // information for the all register set need not be filled in.
521 static const RegisterSet g_reg_sets
[] = {
523 "General Purpose Registers", "gpr", k_num_gpr_registers
, g_gpr_regnums
,
525 {"Floating Point Registers", "fpu", k_num_fpu_registers
, g_fpu_regnums
},
526 {"Exception State Registers", "exc", k_num_exc_registers
, g_exc_regnums
}};
528 const size_t k_num_regsets
= std::size(g_reg_sets
);
530 size_t RegisterContextDarwin_x86_64::GetRegisterSetCount() {
531 return k_num_regsets
;
535 RegisterContextDarwin_x86_64::GetRegisterSet(size_t reg_set
) {
536 if (reg_set
< k_num_regsets
)
537 return &g_reg_sets
[reg_set
];
541 int RegisterContextDarwin_x86_64::GetSetForNativeRegNum(int reg_num
) {
542 if (reg_num
< fpu_fcw
)
544 else if (reg_num
< exc_trapno
)
546 else if (reg_num
< k_num_registers
)
551 int RegisterContextDarwin_x86_64::ReadGPR(bool force
) {
553 if (force
|| !RegisterSetIsCached(set
)) {
554 SetError(set
, Read
, DoReadGPR(GetThreadID(), set
, gpr
));
556 return GetError(GPRRegSet
, Read
);
559 int RegisterContextDarwin_x86_64::ReadFPU(bool force
) {
561 if (force
|| !RegisterSetIsCached(set
)) {
562 SetError(set
, Read
, DoReadFPU(GetThreadID(), set
, fpu
));
564 return GetError(FPURegSet
, Read
);
567 int RegisterContextDarwin_x86_64::ReadEXC(bool force
) {
569 if (force
|| !RegisterSetIsCached(set
)) {
570 SetError(set
, Read
, DoReadEXC(GetThreadID(), set
, exc
));
572 return GetError(EXCRegSet
, Read
);
575 int RegisterContextDarwin_x86_64::WriteGPR() {
577 if (!RegisterSetIsCached(set
)) {
578 SetError(set
, Write
, -1);
581 SetError(set
, Write
, DoWriteGPR(GetThreadID(), set
, gpr
));
582 SetError(set
, Read
, -1);
583 return GetError(set
, Write
);
586 int RegisterContextDarwin_x86_64::WriteFPU() {
588 if (!RegisterSetIsCached(set
)) {
589 SetError(set
, Write
, -1);
592 SetError(set
, Write
, DoWriteFPU(GetThreadID(), set
, fpu
));
593 SetError(set
, Read
, -1);
594 return GetError(set
, Write
);
597 int RegisterContextDarwin_x86_64::WriteEXC() {
599 if (!RegisterSetIsCached(set
)) {
600 SetError(set
, Write
, -1);
603 SetError(set
, Write
, DoWriteEXC(GetThreadID(), set
, exc
));
604 SetError(set
, Read
, -1);
605 return GetError(set
, Write
);
608 int RegisterContextDarwin_x86_64::ReadRegisterSet(uint32_t set
, bool force
) {
611 return ReadGPR(force
);
613 return ReadFPU(force
);
615 return ReadEXC(force
);
622 int RegisterContextDarwin_x86_64::WriteRegisterSet(uint32_t set
) {
623 // Make sure we have a valid context to set.
637 bool RegisterContextDarwin_x86_64::ReadRegister(const RegisterInfo
*reg_info
,
638 RegisterValue
&value
) {
639 const uint32_t reg
= reg_info
->kinds
[eRegisterKindLLDB
];
640 int set
= RegisterContextDarwin_x86_64::GetSetForNativeRegNum(reg
);
644 if (ReadRegisterSet(set
, false) != 0)
669 value
= (&gpr
.rax
)[reg
- gpr_rax
];
709 value
= fpu
.mxcsrmask
;
720 value
.SetBytes(fpu
.stmm
[reg
- fpu_stmm0
].bytes
, reg_info
->byte_size
,
721 endian::InlHostByteOrder());
740 value
.SetBytes(fpu
.xmm
[reg
- fpu_xmm0
].bytes
, reg_info
->byte_size
,
741 endian::InlHostByteOrder());
753 value
= exc
.faultvaddr
;
762 bool RegisterContextDarwin_x86_64::WriteRegister(const RegisterInfo
*reg_info
,
763 const RegisterValue
&value
) {
764 const uint32_t reg
= reg_info
->kinds
[eRegisterKindLLDB
];
765 int set
= RegisterContextDarwin_x86_64::GetSetForNativeRegNum(reg
);
770 if (ReadRegisterSet(set
, false) != 0)
795 (&gpr
.rax
)[reg
- gpr_rax
] = value
.GetAsUInt64();
799 fpu
.fcw
= value
.GetAsUInt16();
803 fpu
.fsw
= value
.GetAsUInt16();
807 fpu
.ftw
= value
.GetAsUInt8();
811 fpu
.fop
= value
.GetAsUInt16();
815 fpu
.ip
= value
.GetAsUInt32();
819 fpu
.cs
= value
.GetAsUInt16();
823 fpu
.dp
= value
.GetAsUInt32();
827 fpu
.ds
= value
.GetAsUInt16();
831 fpu
.mxcsr
= value
.GetAsUInt32();
835 fpu
.mxcsrmask
= value
.GetAsUInt32();
846 ::memcpy(fpu
.stmm
[reg
- fpu_stmm0
].bytes
, value
.GetBytes(),
847 value
.GetByteSize());
866 ::memcpy(fpu
.xmm
[reg
- fpu_xmm0
].bytes
, value
.GetBytes(),
867 value
.GetByteSize());
871 exc
.trapno
= value
.GetAsUInt32();
875 exc
.err
= value
.GetAsUInt32();
879 exc
.faultvaddr
= value
.GetAsUInt64();
885 return WriteRegisterSet(set
) == 0;
888 bool RegisterContextDarwin_x86_64::ReadAllRegisterValues(
889 lldb::WritableDataBufferSP
&data_sp
) {
890 data_sp
= std::make_shared
<DataBufferHeap
>(REG_CONTEXT_SIZE
, 0);
891 if (ReadGPR(false) == 0 && ReadFPU(false) == 0 && ReadEXC(false) == 0) {
892 uint8_t *dst
= data_sp
->GetBytes();
893 ::memcpy(dst
, &gpr
, sizeof(gpr
));
896 ::memcpy(dst
, &fpu
, sizeof(fpu
));
899 ::memcpy(dst
, &exc
, sizeof(exc
));
905 bool RegisterContextDarwin_x86_64::WriteAllRegisterValues(
906 const lldb::DataBufferSP
&data_sp
) {
907 if (data_sp
&& data_sp
->GetByteSize() == REG_CONTEXT_SIZE
) {
908 const uint8_t *src
= data_sp
->GetBytes();
909 ::memcpy(&gpr
, src
, sizeof(gpr
));
912 ::memcpy(&fpu
, src
, sizeof(fpu
));
915 ::memcpy(&exc
, src
, sizeof(exc
));
916 uint32_t success_count
= 0;
923 return success_count
== 3;
928 uint32_t RegisterContextDarwin_x86_64::ConvertRegisterKindToRegisterNumber(
929 lldb::RegisterKind kind
, uint32_t reg
) {
930 if (kind
== eRegisterKindGeneric
) {
932 case LLDB_REGNUM_GENERIC_PC
:
934 case LLDB_REGNUM_GENERIC_SP
:
936 case LLDB_REGNUM_GENERIC_FP
:
938 case LLDB_REGNUM_GENERIC_FLAGS
:
940 case LLDB_REGNUM_GENERIC_RA
:
944 } else if (kind
== eRegisterKindEHFrame
|| kind
== eRegisterKindDWARF
) {
946 case ehframe_dwarf_gpr_rax
:
948 case ehframe_dwarf_gpr_rdx
:
950 case ehframe_dwarf_gpr_rcx
:
952 case ehframe_dwarf_gpr_rbx
:
954 case ehframe_dwarf_gpr_rsi
:
956 case ehframe_dwarf_gpr_rdi
:
958 case ehframe_dwarf_gpr_rbp
:
960 case ehframe_dwarf_gpr_rsp
:
962 case ehframe_dwarf_gpr_r8
:
964 case ehframe_dwarf_gpr_r9
:
966 case ehframe_dwarf_gpr_r10
:
968 case ehframe_dwarf_gpr_r11
:
970 case ehframe_dwarf_gpr_r12
:
972 case ehframe_dwarf_gpr_r13
:
974 case ehframe_dwarf_gpr_r14
:
976 case ehframe_dwarf_gpr_r15
:
978 case ehframe_dwarf_gpr_rip
:
980 case ehframe_dwarf_fpu_xmm0
:
982 case ehframe_dwarf_fpu_xmm1
:
984 case ehframe_dwarf_fpu_xmm2
:
986 case ehframe_dwarf_fpu_xmm3
:
988 case ehframe_dwarf_fpu_xmm4
:
990 case ehframe_dwarf_fpu_xmm5
:
992 case ehframe_dwarf_fpu_xmm6
:
994 case ehframe_dwarf_fpu_xmm7
:
996 case ehframe_dwarf_fpu_xmm8
:
998 case ehframe_dwarf_fpu_xmm9
:
1000 case ehframe_dwarf_fpu_xmm10
:
1002 case ehframe_dwarf_fpu_xmm11
:
1004 case ehframe_dwarf_fpu_xmm12
:
1006 case ehframe_dwarf_fpu_xmm13
:
1008 case ehframe_dwarf_fpu_xmm14
:
1010 case ehframe_dwarf_fpu_xmm15
:
1012 case ehframe_dwarf_fpu_stmm0
:
1014 case ehframe_dwarf_fpu_stmm1
:
1016 case ehframe_dwarf_fpu_stmm2
:
1018 case ehframe_dwarf_fpu_stmm3
:
1020 case ehframe_dwarf_fpu_stmm4
:
1022 case ehframe_dwarf_fpu_stmm5
:
1024 case ehframe_dwarf_fpu_stmm6
:
1026 case ehframe_dwarf_fpu_stmm7
:
1031 } else if (kind
== eRegisterKindLLDB
) {
1034 return LLDB_INVALID_REGNUM
;
1037 bool RegisterContextDarwin_x86_64::HardwareSingleStep(bool enable
) {
1038 if (ReadGPR(true) != 0)
1041 const uint64_t trace_bit
= 0x100ull
;
1044 if (gpr
.rflags
& trace_bit
)
1045 return true; // trace bit is already set, there is nothing to do
1047 gpr
.rflags
|= trace_bit
;
1049 if (gpr
.rflags
& trace_bit
)
1050 gpr
.rflags
&= ~trace_bit
;
1052 return true; // trace bit is clear, there is nothing to do
1055 return WriteGPR() == 0;