[Lldb-commits] [lldb] r167033 - in /lldb/trunk: include/lldb/Core/Value.h source/Core/ValueObject.cpp source/Core/ValueObjectVariable.cpp source/Expression/ClangExpressionDeclMap.cpp source/Expression/IRInterpreter.cpp

Greg Clayton gclayton at apple.com
Tue Oct 30 11:18:43 PDT 2012


Author: gclayton
Date: Tue Oct 30 13:18:43 2012
New Revision: 167033

URL: http://llvm.org/viewvc/llvm-project?rev=167033&view=rev
Log:
Path from Ashok Thirumurthi:

The attached patch adds eValueTypeVector to lldb_private::Value.  The nested struct Vector is patterned after RegisterValue::m_data.buffer.  This change to Value allows ClangExpressionDeclMap::LookupDecl to return vector register data for consumption by InterpreterStackFrame::ResolveValue.  Note that ResolveValue was tweaked slightly to allocate enough memory for vector registers.
 
An immediate result of this patch is that "expr $xmm0" generates the same results on Linux as on the Mac, which is good enough for TestRegisters.py.  In addition, the log of m_memory.PrintData(data_region.m_base, data_region.m_extent) shows that the register content has been resolved successfully.  On the other hand, the output is glaringly empty:
    runCmd: expr $xmm0
    output: (unsigned char __attribute__((ext_vector_type(16)))) $0 = {}
    Expecting sub string: vector_type
    Matched


Modified:
    lldb/trunk/include/lldb/Core/Value.h
    lldb/trunk/source/Core/ValueObject.cpp
    lldb/trunk/source/Core/ValueObjectVariable.cpp
    lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp
    lldb/trunk/source/Expression/IRInterpreter.cpp

Modified: lldb/trunk/include/lldb/Core/Value.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/Value.h?rev=167033&r1=167032&r2=167033&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/Value.h (original)
+++ lldb/trunk/include/lldb/Core/Value.h Tue Oct 30 13:18:43 2012
@@ -12,6 +12,7 @@
 
 // C Includes
 // C++ Includes
+#include <string>
 #include <vector>
 // Other libraries and framework includes
 // Project includes
@@ -34,6 +35,7 @@
                                         // m_value contains...
                                         // ============================
         eValueTypeScalar,               // raw scalar value
+        eValueTypeVector,               // byte array of m_vector.length with endianness of m_vector.byte_order
         eValueTypeFileAddress,          // file address value
         eValueTypeLoadAddress,          // load address value
         eValueTypeHostAddress           // host address value (for memory in the process that is using liblldb)
@@ -45,13 +47,78 @@
                                         // ====================
         eContextTypeInvalid,            // undefined
         eContextTypeClangType,          // void * (an opaque clang::QualType * that can be fed to "static QualType QualType::getFromOpaquePtr(void *)")
-        eContextTypeRegisterInfo,       // RegisterInfo *
+        eContextTypeRegisterInfo,       // RegisterInfo * (can be a scalar or a vector register)
         eContextTypeLLDBType,           // lldb_private::Type *
         eContextTypeVariable            // lldb_private::Variable *
     };
 
+    enum
+    {
+        kMaxByteSize = 32u
+    };
+
+    struct Vector
+    {
+        // The byte array must be big enough to hold vector registers for any supported target.
+        uint8_t bytes[kMaxByteSize];
+        size_t length;
+        lldb::ByteOrder byte_order;
+
+        Vector() : 
+			length(0), 
+			byte_order(lldb::eByteOrderInvalid) 
+        {
+		}
+
+        Vector(const Vector& vector) 
+		{ *this = vector; 
+        }
+        const Vector& 
+		operator=(const Vector& vector) 
+		{
+            SetBytes((uint8_t *)vector.bytes, vector.length, vector.byte_order);
+            return *this;
+        }
+
+        bool 
+		SetBytes(uint8_t *bytes, size_t length, lldb::ByteOrder byte_order)
+		{
+            this->length = length;
+            this->byte_order = byte_order;
+            if (length)
+                ::memcpy(this->bytes, bytes, length < kMaxByteSize ? length : kMaxByteSize);
+            return IsValid();
+        }
+
+        bool
+		IsValid() const 
+		{
+            return (length > 0 && length < kMaxByteSize && byte_order != lldb::eByteOrderInvalid);
+        }
+        // Casts a vector, if valid, to an unsigned int of matching or largest supported size.
+        // Truncates to the beginning of the vector if required.
+        // Returns a default constructed Scalar if the Vector data is internally inconsistent.
+        Scalar 
+		GetAsScalar() const 
+		{
+            Scalar scalar;
+            if (IsValid())
+                if (length == 1) scalar = *(uint8_t *)bytes;
+                if (length == 2) scalar = *(uint16_t *)bytes;
+                if (length == 4) scalar = *(uint32_t *)bytes;
+                if (length == 8) scalar = *(uint64_t *)bytes;
+#if defined (ENABLE_128_BIT_SUPPORT)
+                if (length >= 16) scalar = *(__uint128_t *)bytes;
+#else
+                if (length >= 16) scalar = *(__uint64_t *)bytes;
+#endif
+            return scalar;
+        }
+    };
+
     Value();
     Value(const Scalar& scalar);
+    Value(const Vector& vector);
     Value(const uint8_t *bytes, int len);
     Value(const Value &rhs);
     
@@ -91,6 +158,13 @@
     {
         m_context_type = context_type;
         m_context = p;
+        if (m_context_type == eContextTypeRegisterInfo) {
+            RegisterInfo *reg_info = GetRegisterInfo();
+            if (reg_info->encoding == lldb::eEncodingVector)
+                SetValueType(eValueTypeVector);
+            else
+                SetValueType(eValueTypeScalar);
+        }
     }
 
     RegisterInfo *
@@ -108,6 +182,36 @@
         return m_value;
     }
     
+    Vector &
+    GetVector()
+    {
+        return m_vector;
+    }
+
+    bool
+    SetVectorBytes(const Vector& vector) 
+	{
+        m_vector = vector;
+        return m_vector.IsValid();
+    }
+    
+    bool
+    SetVectorBytes(uint8_t *bytes, size_t length, lldb::ByteOrder byte_order) 
+	{
+        return m_vector.SetBytes(bytes, length, byte_order);
+    }
+
+    bool
+    SetScalarFromVector() 
+	{
+        if (m_vector.IsValid()) 
+		{
+            m_value = m_vector.GetAsScalar();
+            return true;
+        }
+        return false;
+    }
+
     void
     ResizeData(int len);
 
@@ -144,6 +248,7 @@
 
 protected:
     Scalar          m_value;
+    Vector          m_vector;
     ValueType       m_value_type;
     void *          m_context;
     ContextType     m_context_type;

Modified: lldb/trunk/source/Core/ValueObject.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/ValueObject.cpp?rev=167033&r1=167032&r2=167033&view=diff
==============================================================================
--- lldb/trunk/source/Core/ValueObject.cpp (original)
+++ lldb/trunk/source/Core/ValueObject.cpp Tue Oct 30 13:18:43 2012
@@ -422,6 +422,7 @@
                 break;
 
             case Value::eValueTypeScalar:
+            case Value::eValueTypeVector:
                 if (m_value.GetContextType() == Value::eContextTypeRegisterInfo)
                 {
                     RegisterInfo *reg_info = m_value.GetRegisterInfo();
@@ -431,10 +432,10 @@
                             m_location_str = reg_info->name;
                         else if (reg_info->alt_name)
                             m_location_str = reg_info->alt_name;
-                        break;
+
+                        m_location_str = (reg_info->encoding == lldb::eEncodingVector) ? "vector" : "scalar";
                     }
                 }
-                m_location_str = "scalar";
                 break;
 
             case Value::eValueTypeLoadAddress:
@@ -1585,6 +1586,7 @@
     switch (m_value.GetValueType())
     {
     case Value::eValueTypeScalar:
+    case Value::eValueTypeVector:
         if (scalar_is_load_address)
         {
             if(address_type)
@@ -1621,6 +1623,7 @@
     switch (m_value.GetValueType())
     {
     case Value::eValueTypeScalar:
+    case Value::eValueTypeVector:
         address = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
         break;
 
@@ -1720,7 +1723,8 @@
                 break;
             case Value::eValueTypeFileAddress:
             case Value::eValueTypeScalar:
-                break;    
+            case Value::eValueTypeVector:
+                break;
             }
         }
         else

Modified: lldb/trunk/source/Core/ValueObjectVariable.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/ValueObjectVariable.cpp?rev=167033&r1=167032&r2=167033&view=diff
==============================================================================
--- lldb/trunk/source/Core/ValueObjectVariable.cpp (original)
+++ lldb/trunk/source/Core/ValueObjectVariable.cpp Tue Oct 30 13:18:43 2012
@@ -176,6 +176,7 @@
                     break;
                 case Value::eValueTypeLoadAddress:
                 case Value::eValueTypeScalar:
+                case Value::eValueTypeVector:
                     SetAddressTypeOfChildren(eAddressTypeLoad);
                     break;
             }

Modified: lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp?rev=167033&r1=167032&r2=167033&view=diff
==============================================================================
--- lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp (original)
+++ lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp Tue Oct 30 13:18:43 2012
@@ -1083,8 +1083,13 @@
             Value ret;
             
             ret.SetContext(Value::eContextTypeRegisterInfo, reg_info);
-            if (!reg_value.GetScalarValue(ret.GetScalar()))
-                return Value();
+            if (reg_info->encoding == eEncodingVector) 
+			{
+                if (ret.SetVectorBytes((uint8_t *)reg_value.GetBytes(), reg_value.GetByteSize(), reg_value.GetByteOrder()))
+                    ret.SetScalarFromVector();
+            }
+            else if (!reg_value.GetScalarValue(ret.GetScalar()))
+				return Value();
             
             return ret;
         }

Modified: lldb/trunk/source/Expression/IRInterpreter.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/IRInterpreter.cpp?rev=167033&r1=167032&r2=167033&view=diff
==============================================================================
--- lldb/trunk/source/Expression/IRInterpreter.cpp (original)
+++ lldb/trunk/source/Expression/IRInterpreter.cpp Tue Oct 30 13:18:43 2012
@@ -676,7 +676,11 @@
                     if (bare_register)
                         indirect_variable = false;
                     
-                    Memory::Region data_region = m_memory.Malloc(value->getType());
+                    lldb_private::RegisterInfo *reg_info = resolved_value.GetRegisterInfo();
+                    Memory::Region data_region = (reg_info->encoding == lldb::eEncodingVector) ?
+                        m_memory.Malloc(reg_info->byte_size, m_target_data.getPrefTypeAlignment(value->getType())) :
+                        m_memory.Malloc(value->getType());
+
                     data_region.m_allocation->m_origin = resolved_value;
                     Memory::Region ref_region = m_memory.Malloc(value->getType());
                     Memory::Region pointer_region;





More information about the lldb-commits mailing list