<div dir="ltr">Please don't submit CLs like this without a test in the future.  This should be testable by writing some assembly to move a value into an FPU register, setting a breakpoint, then querying the register values.  Can you submit this as a followup?</div><br><div class="gmail_quote"><div dir="ltr">On Tue, Oct 6, 2015 at 12:05 AM Abhishek Aggarwal via lldb-commits <<a href="mailto:lldb-commits@lists.llvm.org">lldb-commits@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: abhishek<br>
Date: Tue Oct  6 02:04:03 2015<br>
New Revision: 249379<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=249379&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=249379&view=rev</a><br>
Log:<br>
Bug 25050: X87 FPU Special Purpose Registers<br>
<br>
Summary:<br>
  - For x86_64-FreeBSD Platform:<br>
    -- LLDB now provides correct values of X87 FPU<br>
       Special Purpose Registers like fstat, ftag, fctrl etc..<br>
<br>
Signed-off-by: Abhishek Aggarwal <<a href="mailto:abhishek.a.aggarwal@intel.com" target="_blank">abhishek.a.aggarwal@intel.com</a>><br>
<br>
Reviewers: emaste, mikesart, clayborg<br>
<br>
Subscribers: emaste<br>
<br>
Differential Revision: <a href="http://reviews.llvm.org/D13434" rel="noreferrer" target="_blank">http://reviews.llvm.org/D13434</a><br>
<br>
Modified:<br>
    lldb/trunk/source/Plugins/Process/FreeBSD/RegisterContextPOSIXProcessMonitor_x86.cpp<br>
    lldb/trunk/source/Plugins/Process/FreeBSD/RegisterContextPOSIXProcessMonitor_x86.h<br>
<br>
Modified: lldb/trunk/source/Plugins/Process/FreeBSD/RegisterContextPOSIXProcessMonitor_x86.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/FreeBSD/RegisterContextPOSIXProcessMonitor_x86.cpp?rev=249379&r1=249378&r2=249379&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/FreeBSD/RegisterContextPOSIXProcessMonitor_x86.cpp?rev=249379&r1=249378&r2=249379&view=diff</a><br>
==============================================================================<br>
--- lldb/trunk/source/Plugins/Process/FreeBSD/RegisterContextPOSIXProcessMonitor_x86.cpp (original)<br>
+++ lldb/trunk/source/Plugins/Process/FreeBSD/RegisterContextPOSIXProcessMonitor_x86.cpp Tue Oct  6 02:04:03 2015<br>
@@ -58,6 +58,9 @@ RegisterContextPOSIXProcessMonitor_x86_6<br>
                                                                                      lldb_private::RegisterInfoInterface *register_info)<br>
     : RegisterContextPOSIX_x86(thread, concrete_frame_idx, register_info)<br>
 {<br>
+    // Store byte offset of fctrl (i.e. first register of FPR) wrt 'UserArea'<br>
+    const RegisterInfo *reg_info_fctrl = GetRegisterInfoByName("fctrl");<br>
+    m_fctrl_offset_in_userarea = reg_info_fctrl->byte_offset;<br>
 }<br>
<br>
 ProcessMonitor &<br>
@@ -254,8 +257,15 @@ RegisterContextPOSIXProcessMonitor_x86_6<br>
     }<br>
<br>
     // Get pointer to m_fpr.xstate.fxsave variable and set the data from it.<br>
-    assert (reg_info->byte_offset < sizeof(m_fpr));<br>
-    uint8_t *src = (uint8_t *)&m_fpr + reg_info->byte_offset;<br>
+    // Byte offsets of all registers are calculated wrt 'UserArea' structure.<br>
+    // However, ReadFPR() reads fpu registers {using ptrace(PT_GETFPREGS,..)}<br>
+    // and stores them in 'm_fpr' (of type FPR structure). To extract values of fpu<br>
+    // registers, m_fpr should be read at byte offsets calculated wrt to FPR structure.<br>
+<br>
+    // Since, FPR structure is also one of the member of UserArea structure.<br>
+    // byte_offset(fpu wrt FPR) = byte_offset(fpu wrt UserArea) - byte_offset(fctrl wrt UserArea)<br>
+    assert ( (reg_info->byte_offset - m_fctrl_offset_in_userarea) < sizeof(m_fpr));<br>
+    uint8_t *src = (uint8_t *)&m_fpr + reg_info->byte_offset - m_fctrl_offset_in_userarea;<br>
     switch (reg_info->byte_size)<br>
     {<br>
         case 2:<br>
@@ -308,8 +318,15 @@ RegisterContextPOSIXProcessMonitor_x86_6<br>
         else<br>
         {<br>
             // Get pointer to m_fpr.xstate.fxsave variable and set the data to it.<br>
-            assert (reg_info->byte_offset < sizeof(m_fpr));<br>
-            uint8_t *dst = (uint8_t *)&m_fpr + reg_info->byte_offset;<br>
+            // Byte offsets of all registers are calculated wrt 'UserArea' structure.<br>
+            // However, WriteFPR() takes m_fpr (of type FPR structure) and writes only fpu<br>
+            // registers using ptrace(PT_SETFPREGS,..) API. Hence fpu registers should<br>
+            // be written in m_fpr at byte offsets calculated wrt FPR structure.<br>
+<br>
+            // Since, FPR structure is also one of the member of UserArea structure.<br>
+            // byte_offset(fpu wrt FPR) = byte_offset(fpu wrt UserArea) - byte_offset(fctrl wrt UserArea)<br>
+            assert ( (reg_info->byte_offset - m_fctrl_offset_in_userarea) < sizeof(m_fpr));<br>
+            uint8_t *dst = (uint8_t *)&m_fpr + reg_info->byte_offset - m_fctrl_offset_in_userarea;<br>
             switch (reg_info->byte_size)<br>
             {<br>
                 case 2:<br>
<br>
Modified: lldb/trunk/source/Plugins/Process/FreeBSD/RegisterContextPOSIXProcessMonitor_x86.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/FreeBSD/RegisterContextPOSIXProcessMonitor_x86.h?rev=249379&r1=249378&r2=249379&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/FreeBSD/RegisterContextPOSIXProcessMonitor_x86.h?rev=249379&r1=249378&r2=249379&view=diff</a><br>
==============================================================================<br>
--- lldb/trunk/source/Plugins/Process/FreeBSD/RegisterContextPOSIXProcessMonitor_x86.h (original)<br>
+++ lldb/trunk/source/Plugins/Process/FreeBSD/RegisterContextPOSIXProcessMonitor_x86.h Tue Oct  6 02:04:03 2015<br>
@@ -91,6 +91,7 @@ protected:<br>
 private:<br>
     ProcessMonitor &<br>
     GetMonitor();<br>
+    uint32_t m_fctrl_offset_in_userarea;  // Offset of 'fctrl' in 'UserArea' Structure<br>
 };<br>
<br>
 #endif<br>
<br>
<br>
_______________________________________________<br>
lldb-commits mailing list<br>
<a href="mailto:lldb-commits@lists.llvm.org" target="_blank">lldb-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits</a><br>
</blockquote></div>