<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman",serif;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal-reply;
        font-family:"Calibri",sans-serif;
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri",sans-serif;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal"><a name="_MailEndCompose"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">I had submitted a patch for the Bug 24457 which is similar kind of bug but on Linux x86_64 Platform. There, I had submitted a new test
 to reproduce this issue. The test is already there in public repository. Since, the same test goes for FreeBSD also therefore I didn’t need to write a new one.<o:p></o:p></span></a></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">-Thanks<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><b><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">From:</span></b><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"> Zachary Turner [mailto:zturner@google.com]
<br>
<b>Sent:</b> Tuesday, October 6, 2015 4:53 PM<br>
<b>To:</b> Aggarwal, Abhishek A; lldb-commits@lists.llvm.org<br>
<b>Subject:</b> Re: [Lldb-commits] [lldb] r249379 - Bug 25050: X87 FPU Special Purpose Registers<o:p></o:p></span></p>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p class="MsoNormal">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?<o:p></o:p></p>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<div>
<p class="MsoNormal">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:<o:p></o:p></p>
</div>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in">
<p class="MsoNormal">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" 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" 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" 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" 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" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits</a><o:p></o:p></p>
</blockquote>
</div>
</div>
<p><font style="font-size: 9px;">Intel Deutschland GmbH<br>
Registered Address: Am Campeon 10-12, 85579 Neubiberg, Germany<br>
Tel: +49 89 99 8853-0, www.intel.de<br>
Managing Directors: Christin Eisenschmid, Prof. Dr. Hermann Eul<br>
Chairperson of the Supervisory Board: Tiffany Doon Silva<br>
Registered Office: Munich<br>
Commercial Register: Amtsgericht Muenchen HRB 186928</font><br>
</p></body>
</html>