Index: source/Plugins/Process/FreeBSD/RegisterContextPOSIXProcessMonitor_x86.h =================================================================== --- source/Plugins/Process/FreeBSD/RegisterContextPOSIXProcessMonitor_x86.h +++ source/Plugins/Process/FreeBSD/RegisterContextPOSIXProcessMonitor_x86.h @@ -91,6 +91,7 @@ private: ProcessMonitor & GetMonitor(); + uint32_t m_fctrl_offset_in_userarea; // Offset of 'fctrl' in 'UserArea' Structure }; #endif Index: source/Plugins/Process/FreeBSD/RegisterContextPOSIXProcessMonitor_x86.cpp =================================================================== --- source/Plugins/Process/FreeBSD/RegisterContextPOSIXProcessMonitor_x86.cpp +++ source/Plugins/Process/FreeBSD/RegisterContextPOSIXProcessMonitor_x86.cpp @@ -58,6 +58,9 @@ lldb_private::RegisterInfoInterface *register_info) : RegisterContextPOSIX_x86(thread, concrete_frame_idx, register_info) { + // Store byte offset of fctrl (i.e. first register of FPR) wrt 'UserArea' + const RegisterInfo *reg_info_fctrl = GetRegisterInfoByName("fctrl"); + m_fctrl_offset_in_userarea = reg_info_fctrl->byte_offset; } ProcessMonitor & @@ -254,8 +257,15 @@ } // Get pointer to m_fpr.xstate.fxsave variable and set the data from it. - assert (reg_info->byte_offset < sizeof(m_fpr)); - uint8_t *src = (uint8_t *)&m_fpr + reg_info->byte_offset; + // Byte offsets of all registers are calculated wrt 'UserArea' structure. + // However, ReadFPR() reads fpu registers {using ptrace(PT_GETFPREGS,..)} + // and stores them in 'm_fpr' (of type FPR structure). To extract values of fpu + // registers, m_fpr should be read at byte offsets calculated wrt to FPR structure. + + // Since, FPR structure is also one of the member of UserArea structure. + // byte_offset(fpu wrt FPR) = byte_offset(fpu wrt UserArea) - byte_offset(fctrl wrt UserArea) + assert ( (reg_info->byte_offset - m_fctrl_offset_in_userarea) < sizeof(m_fpr)); + uint8_t *src = (uint8_t *)&m_fpr + reg_info->byte_offset - m_fctrl_offset_in_userarea; switch (reg_info->byte_size) { case 2: @@ -308,8 +318,15 @@ else { // Get pointer to m_fpr.xstate.fxsave variable and set the data to it. - assert (reg_info->byte_offset < sizeof(m_fpr)); - uint8_t *dst = (uint8_t *)&m_fpr + reg_info->byte_offset; + // Byte offsets of all registers are calculated wrt 'UserArea' structure. + // However, WriteFPR() takes m_fpr (of type FPR structure) and writes only fpu + // registers using ptrace(PT_SETFPREGS,..) API. Hence fpu registers should + // be written in m_fpr at byte offsets calculated wrt FPR structure. + + // Since, FPR structure is also one of the member of UserArea structure. + // byte_offset(fpu wrt FPR) = byte_offset(fpu wrt UserArea) - byte_offset(fctrl wrt UserArea) + assert ( (reg_info->byte_offset - m_fctrl_offset_in_userarea) < sizeof(m_fpr)); + uint8_t *dst = (uint8_t *)&m_fpr + reg_info->byte_offset - m_fctrl_offset_in_userarea; switch (reg_info->byte_size) { case 2: