From 6ec13991f583d72713528907d0561c14e4872b31 Mon Sep 17 00:00:00 2001 From: Pavel Labath Date: Mon, 28 Nov 2016 15:51:47 +0000 Subject: [PATCH] Fix floating point register reads x86_64 linux on targets with no AVX support Summary: On for 64-bit targets, the correct register set to read the fxsave are is NT_PRFPREG (only 32-bit targets need NT_PRXFPREG, presumably for historic reasons). Reference: . Reviewers: tberghammer, valentinagiusti Subscribers: lldb-commits Differential Revision: https://reviews.llvm.org/D27161 llvm-svn: 288038 --- .../Process/Linux/NativeRegisterContextLinux_x86_64.cpp | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_x86_64.cpp b/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_x86_64.cpp index 37e748d..2bd819b 100644 --- a/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_x86_64.cpp +++ b/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_x86_64.cpp @@ -20,6 +20,8 @@ #include "Plugins/Process/Utility/RegisterContextLinux_i386.h" #include "Plugins/Process/Utility/RegisterContextLinux_x86_64.h" +#include + using namespace lldb_private; using namespace lldb_private::process_linux; @@ -218,6 +220,12 @@ static const RegisterSet g_reg_sets_x86_64[k_num_register_sets] = { #define NT_PRXFPREG 0x46e62b7f #endif +// On x86_64 NT_PRFPREG is used to access the FXSAVE area. On i386, we need to +// use NT_PRXFPREG. +static inline unsigned int fxsr_regset(const ArchSpec &arch) { + return arch.GetAddressByteSize() == 8 ? NT_PRFPREG : NT_PRXFPREG; +} + // ---------------------------------------------------------------------------- // Required MPX define. // ---------------------------------------------------------------------------- @@ -852,8 +860,9 @@ bool NativeRegisterContextLinux_x86_64::IsFPR(uint32_t reg_index) const { Error NativeRegisterContextLinux_x86_64::WriteFPR() { switch (m_xstate_type) { case XStateType::FXSAVE: - return WriteRegisterSet(&m_iovec, sizeof(m_fpr.xstate.xsave), - NT_PRXFPREG); + return WriteRegisterSet( + &m_iovec, sizeof(m_fpr.xstate.xsave), + fxsr_regset(GetRegisterInfoInterface().GetTargetArchitecture())); case XStateType::XSAVE: return WriteRegisterSet(&m_iovec, sizeof(m_fpr.xstate.xsave), NT_X86_XSTATE); @@ -957,7 +966,9 @@ Error NativeRegisterContextLinux_x86_64::ReadFPR() { return error; } } - error = ReadRegisterSet(&m_iovec, sizeof(m_fpr.xstate.xsave), NT_PRXFPREG); + error = ReadRegisterSet( + &m_iovec, sizeof(m_fpr.xstate.xsave), + fxsr_regset(GetRegisterInfoInterface().GetTargetArchitecture())); if (!error.Fail()) { m_xstate_type = XStateType::FXSAVE; return error; -- 2.7.4