[Lldb-commits] [lldb] r262947 - Support floating point values in 128-bit SSE vector registers

Adrian Prantl via lldb-commits lldb-commits at lists.llvm.org
Tue Mar 8 10:35:09 PST 2016


Author: adrian
Date: Tue Mar  8 12:35:09 2016
New Revision: 262947

URL: http://llvm.org/viewvc/llvm-project?rev=262947&view=rev
Log:
Support floating point values in 128-bit SSE vector registers

The System-V x86_64 ABI requires floating point values to be passed
in 128-but SSE vector registers (xmm0, ...). When printing such a
variable this currently yields an <invalid load address>.

This patch makes LLDB's DWARF expression evaluator accept 128-bit
registers as scalars. It also relaxes the check that the size of the
result of the DWARF expression be equal to the size of the variable to a
greater-than. DWARF defers to the ABI how smaller values are being placed
in a larger register.

Implementation note: I found the code in Value::SetContext() that changes
the m_value_type after the fact to be questionable. I added a sanity check
that the Value's memory buffer has indeed been written to (this is
necessary, because we may have a scalar value in a vector register), but
really I feel like this is the wrong place to be setting it.

Reviewed by Greg Clayton.

http://reviews.llvm.org/D17897
rdar://problem/24944340

Modified:
    lldb/trunk/include/lldb/Core/Value.h
    lldb/trunk/packages/Python/lldbsuite/test/lang/c/register_variables/TestRegisterVariables.py
    lldb/trunk/packages/Python/lldbsuite/test/lang/c/register_variables/test.c
    lldb/trunk/source/Core/RegisterValue.cpp
    lldb/trunk/source/Expression/Materializer.cpp

Modified: lldb/trunk/include/lldb/Core/Value.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/Value.h?rev=262947&r1=262946&r2=262947&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/Value.h (original)
+++ lldb/trunk/include/lldb/Core/Value.h Tue Mar  8 12:35:09 2016
@@ -169,9 +169,8 @@ public:
         m_context = p;
         if (m_context_type == eContextTypeRegisterInfo) {
             RegisterInfo *reg_info = GetRegisterInfo();
-            if (reg_info->encoding == lldb::eEncodingVector)
-                SetValueType(eValueTypeVector);
-            else
+            if (reg_info->encoding == lldb::eEncodingVector &&
+                m_vector.byte_order != lldb::eByteOrderInvalid)
                 SetValueType(eValueTypeScalar);
         }
     }

Modified: lldb/trunk/packages/Python/lldbsuite/test/lang/c/register_variables/TestRegisterVariables.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/lang/c/register_variables/TestRegisterVariables.py?rev=262947&r1=262946&r2=262947&view=diff
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/lang/c/register_variables/TestRegisterVariables.py (original)
+++ lldb/trunk/packages/Python/lldbsuite/test/lang/c/register_variables/TestRegisterVariables.py Tue Mar  8 12:35:09 2016
@@ -24,7 +24,7 @@ class RegisterVariableTestCase(TestBase)
         self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
 
         # Break inside the main.
-        lldbutil.run_break_set_by_source_regexp(self, "break", num_expected_locations=2)
+        lldbutil.run_break_set_by_source_regexp(self, "break", num_expected_locations=3)
 
         ####################
         # First breakpoint
@@ -68,4 +68,22 @@ class RegisterVariableTestCase(TestBase)
         self.expect("expr c", VARIABLES_DISPLAYED_CORRECTLY,
             substrs = ['(int) $3 = 5'])
 
+        #####################
+        # Third breakpoint
+
+        self.runCmd("continue")
+
+        # The stop reason of the thread should be breakpoint.
+        self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
+            substrs = ['stopped',
+                       'stop reason = breakpoint'])
+
+        # The breakpoint should have a hit count of 1.
+        self.expect("breakpoint list -f", BREAKPOINT_HIT_ONCE,
+            substrs = [' resolved, hit count = 1'])
+
+        # Try some variables that should be visible
+        self.expect("expr f", VARIABLES_DISPLAYED_CORRECTLY,
+            substrs = ['(float) $4 = 3.1'])
+
         self.runCmd("kill")

Modified: lldb/trunk/packages/Python/lldbsuite/test/lang/c/register_variables/test.c
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/lang/c/register_variables/test.c?rev=262947&r1=262946&r2=262947&view=diff
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/lang/c/register_variables/test.c (original)
+++ lldb/trunk/packages/Python/lldbsuite/test/lang/c/register_variables/test.c Tue Mar  8 12:35:09 2016
@@ -18,10 +18,18 @@ void f2(struct bar *b)
   printf("%d\n", c); // set breakpoint here
 }
 
+float f3() __attribute__ ((noinline));
+float f3() {
+  return 3.14f;
+}
+
 int main()
 {
   struct bar myBar = { 3, 4 };
   f1(2, &myBar);
   f2(&myBar);
+
+  float f = f3();
+  printf("%f\n", f); // set breakpoint here
   return 0;
 }

Modified: lldb/trunk/source/Core/RegisterValue.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/RegisterValue.cpp?rev=262947&r1=262946&r2=262947&view=diff
==============================================================================
--- lldb/trunk/source/Core/RegisterValue.cpp (original)
+++ lldb/trunk/source/Core/RegisterValue.cpp Tue Mar  8 12:35:09 2016
@@ -247,6 +247,9 @@ RegisterValue::GetScalarValue (Scalar &s
                 case 2:     scalar = *(const uint16_t *)buffer.bytes; return true;
                 case 4:     scalar = *(const uint32_t *)buffer.bytes; return true;
                 case 8:     scalar = *(const uint64_t *)buffer.bytes; return true;
+                case 16:
+                    scalar = llvm::APInt(128, llvm::ArrayRef<uint64_t>((const uint64_t *)buffer.bytes, 2));
+                    return true;
                 }
             }
             break;
@@ -374,6 +377,7 @@ RegisterValue::SetValueFromData (const R
         case eTypeLongDouble:   SetFloat (src.GetLongDouble (&src_offset)); break;
         case eTypeBytes:
         {
+            m_type = eTypeBytes;
             buffer.length = reg_info->byte_size;
             buffer.byte_order = src.GetByteOrder();
             assert (buffer.length <= kMaxRegisterByteSize);

Modified: lldb/trunk/source/Expression/Materializer.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/Materializer.cpp?rev=262947&r1=262946&r2=262947&view=diff
==============================================================================
--- lldb/trunk/source/Expression/Materializer.cpp (original)
+++ lldb/trunk/source/Expression/Materializer.cpp Tue Mar  8 12:35:09 2016
@@ -531,7 +531,7 @@ public:
                     return;
                 }
 
-                if (data.GetByteSize() != m_variable_sp->GetType()->GetByteSize())
+                if (data.GetByteSize() < m_variable_sp->GetType()->GetByteSize())
                 {
                     if (data.GetByteSize() == 0 && m_variable_sp->LocationExpression().IsValid() == false)
                     {
@@ -539,7 +539,7 @@ public:
                     }
                     else
                     {
-                        err.SetErrorStringWithFormat("size of variable %s (%" PRIu64 ") disagrees with the ValueObject's size (%" PRIu64 ")",
+                        err.SetErrorStringWithFormat("size of variable %s (%" PRIu64 ") is larger than the ValueObject's size (%" PRIu64 ")",
                                                      m_variable_sp->GetName().AsCString(),
                                                      m_variable_sp->GetType()->GetByteSize(),
                                                      data.GetByteSize());




More information about the lldb-commits mailing list