9#if defined(__i386__) || defined(__x86_64__)
15#include <x86/specialreg.h>
76 k_num_gpr_registers_x86_64,
77 "g_gpr_regnums_x86_64 has wrong number of register infos");
80static const uint32_t g_fpu_regnums_x86_64[] = {
98static_assert((
sizeof(g_fpu_regnums_x86_64) /
sizeof(g_fpu_regnums_x86_64[0])) -
100 k_num_fpr_registers_x86_64,
101 "g_fpu_regnums_x86_64 has wrong number of register infos");
112 k_num_avx_registers_x86_64,
113 "g_avx_regnums_x86_64 has wrong number of register infos");
115static const uint32_t g_mpx_regnums_x86_64[] = {
122static_assert((
sizeof(g_mpx_regnums_x86_64) /
sizeof(g_mpx_regnums_x86_64[0])) -
124 k_num_mpx_registers_x86_64,
125 "g_mpx_regnums_x86_64 has wrong number of register infos");
128static const uint32_t g_dbr_regnums_x86_64[] = {
133static_assert((
sizeof(g_dbr_regnums_x86_64) /
sizeof(g_dbr_regnums_x86_64[0])) -
135 k_num_dbr_registers_x86_64,
136 "g_dbr_regnums_x86_64 has wrong number of register infos");
152 k_num_gpr_registers_i386,
153 "g_gpr_regnums_i386 has wrong number of register infos");
156static const uint32_t g_fpu_regnums_i386[] = {
168static_assert((
sizeof(g_fpu_regnums_i386) /
sizeof(g_fpu_regnums_i386[0])) -
170 k_num_fpr_registers_i386,
171 "g_fpu_regnums_i386 has wrong number of register infos");
180 k_num_avx_registers_i386,
181 "g_avx_regnums_i386 has wrong number of register infos");
183static const uint32_t g_mpx_regnums_i386[] = {
190static_assert((
sizeof(g_mpx_regnums_i386) /
sizeof(g_mpx_regnums_i386[0])) -
192 k_num_mpx_registers_i386,
193 "g_mpx_regnums_i386 has wrong number of register infos");
196static const uint32_t g_dbr_regnums_i386[] = {
201static_assert((
sizeof(g_dbr_regnums_i386) /
sizeof(g_dbr_regnums_i386[0])) -
203 k_num_dbr_registers_i386,
204 "g_dbr_regnums_i386 has wrong number of register infos");
227 g_fpu_regnums_x86_64},
229 g_dbr_regnums_x86_64},
233 g_mpx_regnums_x86_64},
236#define REG_CONTEXT_SIZE (GetRegisterInfoInterface().GetGPRSize())
239NativeRegisterContextFreeBSD::CreateHostNativeRegisterContextFreeBSD(
241 return new NativeRegisterContextFreeBSD_x86_64(target_arch, native_thread);
247CreateRegisterInfoInterface(
const ArchSpec &target_arch) {
248 if (HostInfo::GetArchitecture().GetAddressByteSize() == 4) {
252 assert((HostInfo::GetArchitecture().GetAddressByteSize() == 8) &&
253 "Register setting path assumes this is a 64-bit host");
260NativeRegisterContextFreeBSD_x86_64::NativeRegisterContextFreeBSD_x86_64(
263 native_thread, CreateRegisterInfoInterface(target_arch)),
265 assert(m_gpr.size() == GetRegisterInfoInterface().GetGPRSize());
266 std::array<uint32_t, MaxRegSet + 1> first_regnos;
268 switch (GetRegisterInfoInterface().GetTargetArchitecture().GetMachine()) {
269 case llvm::Triple::x86:
273 case llvm::Triple::x86_64:
278 llvm_unreachable(
"Unhandled target architecture.");
281 for (
int i : {FPRegSet, DBRegSet})
282 m_regset_offsets[i] = GetRegisterInfoInterface()
283 .GetRegisterInfo()[first_regnos[i]]
287uint32_t NativeRegisterContextFreeBSD_x86_64::GetRegisterSetCount()
const {
292NativeRegisterContextFreeBSD_x86_64::GetRegisterSet(uint32_t set_index)
const {
293 switch (GetRegisterInfoInterface().GetTargetArchitecture().GetMachine()) {
294 case llvm::Triple::x86:
296 case llvm::Triple::x86_64:
299 llvm_unreachable(
"Unhandled target architecture.");
303std::optional<NativeRegisterContextFreeBSD_x86_64::RegSetKind>
304NativeRegisterContextFreeBSD_x86_64::GetSetForNativeRegNum(
305 uint32_t reg_num)
const {
306 switch (GetRegisterInfoInterface().GetTargetArchitecture().GetMachine()) {
307 case llvm::Triple::x86:
308 if (reg_num >= k_first_gpr_i386 && reg_num <= k_last_gpr_i386)
310 if (reg_num >= k_first_fpr_i386 && reg_num <= k_last_fpr_i386)
312 if (reg_num >= k_first_avx_i386 && reg_num <= k_last_avx_i386)
314 if (reg_num >= k_first_mpxr_i386 && reg_num <= k_last_mpxr_i386)
316 if (reg_num >= k_first_mpxc_i386 && reg_num <= k_last_mpxc_i386)
318 if (reg_num >= k_first_dbr_i386 && reg_num <= k_last_dbr_i386)
321 case llvm::Triple::x86_64:
322 if (reg_num >= k_first_gpr_x86_64 && reg_num <= k_last_gpr_x86_64)
324 if (reg_num >= k_first_fpr_x86_64 && reg_num <= k_last_fpr_x86_64)
326 if (reg_num >= k_first_avx_x86_64 && reg_num <= k_last_avx_x86_64)
328 if (reg_num >= k_first_mpxr_x86_64 && reg_num <= k_last_mpxr_x86_64)
330 if (reg_num >= k_first_mpxc_x86_64 && reg_num <= k_last_mpxc_x86_64)
332 if (reg_num >= k_first_dbr_x86_64 && reg_num <= k_last_dbr_x86_64)
336 llvm_unreachable(
"Unhandled target architecture.");
339 llvm_unreachable(
"Register does not belong to any register set");
342Status NativeRegisterContextFreeBSD_x86_64::ReadRegisterSet(RegSetKind set) {
345 return NativeProcessFreeBSD::PtraceWrapper(PT_GETREGS, m_thread.GetID(),
348#if defined(__x86_64__)
349 return NativeProcessFreeBSD::PtraceWrapper(PT_GETFPREGS, m_thread.GetID(),
352 return NativeProcessFreeBSD::PtraceWrapper(PT_GETXMMREGS, m_thread.GetID(),
356 return NativeProcessFreeBSD::PtraceWrapper(PT_GETDBREGS, m_thread.GetID(),
360 struct ptrace_xstate_info info;
361 Status ret = NativeProcessFreeBSD::PtraceWrapper(
362 PT_GETXSTATE_INFO, GetProcessPid(), &info,
sizeof(info));
366 assert(info.xsave_mask & XFEATURE_ENABLED_X87);
367 assert(info.xsave_mask & XFEATURE_ENABLED_SSE);
369 m_xsave_offsets[YMMRegSet] = LLDB_INVALID_XSAVE_OFFSET;
370 if (info.xsave_mask & XFEATURE_ENABLED_YMM_HI128) {
372 __get_cpuid_count(0x0D, 2, &
eax, &m_xsave_offsets[YMMRegSet], &
ecx, &
edx);
375 m_xsave.resize(info.xsave_len);
376 return NativeProcessFreeBSD::PtraceWrapper(PT_GETXSTATE, GetProcessPid(),
377 m_xsave.data(), m_xsave.size());
380 llvm_unreachable(
"NativeRegisterContextFreeBSD_x86_64::ReadRegisterSet");
383Status NativeRegisterContextFreeBSD_x86_64::WriteRegisterSet(RegSetKind set) {
386 return NativeProcessFreeBSD::PtraceWrapper(PT_SETREGS, m_thread.GetID(),
389#if defined(__x86_64__)
390 return NativeProcessFreeBSD::PtraceWrapper(PT_SETFPREGS, m_thread.GetID(),
393 return NativeProcessFreeBSD::PtraceWrapper(PT_SETXMMREGS, m_thread.GetID(),
397 return NativeProcessFreeBSD::PtraceWrapper(PT_SETDBREGS, m_thread.GetID(),
402 assert(m_xsave.size() > 0);
403 return NativeProcessFreeBSD::PtraceWrapper(PT_SETXSTATE, GetProcessPid(),
404 m_xsave.data(), m_xsave.size());
406 llvm_unreachable(
"NativeRegisterContextFreeBSD_x86_64::WriteRegisterSet");
410NativeRegisterContextFreeBSD_x86_64::ReadRegister(
const RegisterInfo *reg_info,
415 error.SetErrorString(
"reg_info NULL");
423 error.SetErrorStringWithFormat(
"register \"%s\" is an internal-only lldb "
424 "register, cannot read directly",
429 std::optional<RegSetKind> opt_set = GetSetForNativeRegNum(reg);
433 error.SetErrorStringWithFormat(
"register \"%s\" is in unrecognized set",
438 RegSetKind set = opt_set.value();
439 error = ReadRegisterSet(set);
447 void *data = GetOffsetRegSetData(set, reg_info->
byte_offset);
449 if (data == &fpr->
ftag)
457 std::optional<YMMSplitPtr> ymm_reg = GetYMMSplitReg(reg);
459 error.SetErrorStringWithFormat(
460 "register \"%s\" not supported by CPU/kernel", reg_info->
name);
464 endian::InlHostByteOrder());
469 llvm_unreachable(
"MPX regset should have returned error");
475Status NativeRegisterContextFreeBSD_x86_64::WriteRegister(
481 error.SetErrorString(
"reg_info NULL");
489 error.SetErrorStringWithFormat(
"register \"%s\" is an internal-only lldb "
490 "register, cannot read directly",
495 std::optional<RegSetKind> opt_set = GetSetForNativeRegNum(reg);
499 error.SetErrorStringWithFormat(
"register \"%s\" is in unrecognized set",
504 RegSetKind set = opt_set.value();
505 error = ReadRegisterSet(set);
513 void *data = GetOffsetRegSetData(set, reg_info->
byte_offset);
515 if (data == &fpr->
ftag)
522 std::optional<YMMSplitPtr> ymm_reg = GetYMMSplitReg(reg);
524 error.SetErrorStringWithFormat(
525 "register \"%s\" not supported by CPU/kernel", reg_info->
name);
534 llvm_unreachable(
"MPX regset should have returned error");
537 return WriteRegisterSet(set);
540Status NativeRegisterContextFreeBSD_x86_64::ReadAllRegisterValues(
545 error = ReadRegisterSet(GPRegSet);
549 uint8_t *dst = data_sp->GetBytes();
550 ::memcpy(dst, m_gpr.data(), GetRegisterInfoInterface().GetGPRSize());
551 dst += GetRegisterInfoInterface().GetGPRSize();
556Status NativeRegisterContextFreeBSD_x86_64::WriteAllRegisterValues(
561 error.SetErrorStringWithFormat(
562 "NativeRegisterContextFreeBSD_x86_64::%s invalid data_sp provided",
568 error.SetErrorStringWithFormat(
569 "NativeRegisterContextFreeBSD_x86_64::%s data_sp contained mismatched "
570 "data size, expected %zu, actual %" PRIu64,
575 const uint8_t *src = data_sp->GetBytes();
576 if (src ==
nullptr) {
577 error.SetErrorStringWithFormat(
"NativeRegisterContextFreeBSD_x86_64::%s "
578 "DataBuffer::GetBytes() returned a null "
583 ::memcpy(m_gpr.data(), src, GetRegisterInfoInterface().GetGPRSize());
585 error = WriteRegisterSet(GPRegSet);
588 src += GetRegisterInfoInterface().GetGPRSize();
593llvm::Error NativeRegisterContextFreeBSD_x86_64::CopyHardwareWatchpointsFrom(
595 auto &r_source =
static_cast<NativeRegisterContextFreeBSD_x86_64 &
>(source);
598 Status res = r_source.ReadRegister(GetDR(7), dr7);
602 return llvm::Error::success();
604 m_dbr = r_source.m_dbr;
605 res = WriteRegisterSet(DBRegSet);
611NativeRegisterContextFreeBSD_x86_64::GetOffsetRegSetData(RegSetKind set,
625 llvm_unreachable(
"GetRegSetData() is unsuitable for this regset.");
627 llvm_unreachable(
"MPX regset should have returned error");
629 assert(reg_offset >= m_regset_offsets[set]);
630 return base + (reg_offset - m_regset_offsets[set]);
633std::optional<NativeRegisterContextFreeBSD_x86_64::YMMSplitPtr>
634NativeRegisterContextFreeBSD_x86_64::GetYMMSplitReg(uint32_t reg) {
635 uint32_t offset = m_xsave_offsets[YMMRegSet];
636 if (offset == LLDB_INVALID_XSAVE_OFFSET)
640 switch (GetRegisterInfoInterface().GetTargetArchitecture().GetMachine()) {
641 case llvm::Triple::x86:
644 case llvm::Triple::x86_64:
648 llvm_unreachable(
"Unhandled target architecture.");
651 auto *fpreg =
reinterpret_cast<struct savexmm_ymm *
>(m_xsave.data());
652 auto *ymmreg =
reinterpret_cast<struct ymmacc *
>(m_xsave.data() + offset);
654 return YMMSplitPtr{&fpreg->sv_xmm[reg_index], &ymmreg[reg_index]};
static llvm::raw_ostream & error(Stream &strm)
constexpr size_t k_num_register_sets
static const RegisterSet g_reg_sets_i386[]
static const uint32_t g_gpr_regnums_x86_64[]
const uint32_t g_gpr_regnums_i386[]
static const RegisterSet g_reg_sets_x86_64[]
const uint32_t g_avx_regnums_i386[]
static const uint32_t g_avx_regnums_x86_64[]
An architecture specification class.
A subclass of DataBuffer that stores a data buffer on the heap.
RegisterInfo interface to patch RegisterInfo structure for archs.
uint16_t GetAsUInt16(uint16_t fail_value=UINT16_MAX, bool *success_ptr=nullptr) const
void SetUInt16(uint16_t uint)
uint64_t GetAsUInt64(uint64_t fail_value=UINT64_MAX, bool *success_ptr=nullptr) const
void SetBytes(const void *bytes, size_t length, lldb::ByteOrder byte_order)
const void * GetBytes() const
uint32_t GetByteSize() const
llvm::Error ToError() const
bool Fail() const
Test for error condition.
#define LLDB_INVALID_REGNUM
A class that represents a running process on the host machine.
void YMMToXState(const YMMReg &input, void *xmm_bytes, void *ymmh_bytes)
uint16_t AbridgedToFullTagWord(uint8_t abridged_tw, uint16_t sw, llvm::ArrayRef< MMSReg > st_regs)
YMMReg XStateToYMM(const void *xmm_bytes, const void *ymmh_bytes)
@ k_num_avx_registers_i386
@ k_num_fpr_registers_i386
@ k_num_mpx_registers_i386
@ k_num_dbr_registers_i386
@ k_num_gpr_registers_i386
uint8_t FullToAbridgedTagWord(uint16_t tw)
@ k_num_fpr_registers_x86_64
@ k_num_avx_registers_x86_64
@ k_num_dbr_registers_x86_64
@ k_num_mpx_registers_x86_64
@ k_num_gpr_registers_x86_64
std::shared_ptr< lldb_private::DataBuffer > DataBufferSP
std::shared_ptr< lldb_private::WritableDataBuffer > WritableDataBufferSP
@ eRegisterKindLLDB
lldb's internal register numbers
Every register is described in detail including its name, alternate name (optional),...
uint32_t byte_offset
The byte offset in the register context data where this register's value is found.
uint32_t byte_size
Size in bytes of the register.
uint32_t kinds[lldb::kNumRegisterKinds]
Holds all of the various register numbers for all register kinds.
const char * name
Name of this register, can't be NULL.
Registers are grouped into register sets.