[Lldb-commits] [lldb] r193786 - SBValue::GetValueAsUnsigned()/GetValueAsSigned() should not replicate the Scalar manipulation logic found in ValueObject, but rather just call down to it

Enrico Granata egranata at apple.com
Thu Oct 31 11:57:51 PDT 2013


Author: enrico
Date: Thu Oct 31 13:57:50 2013
New Revision: 193786

URL: http://llvm.org/viewvc/llvm-project?rev=193786&view=rev
Log:
SBValue::GetValueAsUnsigned()/GetValueAsSigned() should not replicate the Scalar manipulation logic found in ValueObject, but rather just call down to it

Modified:
    lldb/trunk/include/lldb/Core/ValueObject.h
    lldb/trunk/source/API/SBValue.cpp
    lldb/trunk/source/Core/ValueObject.cpp

Modified: lldb/trunk/include/lldb/Core/ValueObject.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/ValueObject.h?rev=193786&r1=193785&r2=193786&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/ValueObject.h (original)
+++ lldb/trunk/include/lldb/Core/ValueObject.h Thu Oct 31 13:57:50 2013
@@ -505,6 +505,9 @@ public:
     virtual uint64_t
     GetValueAsUnsigned (uint64_t fail_value, bool *success = NULL);
 
+    virtual int64_t
+    GetValueAsSigned (int64_t fail_value, bool *success = NULL);
+    
     virtual bool
     SetValueFromCString (const char *value_str, Error& error);
     

Modified: lldb/trunk/source/API/SBValue.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBValue.cpp?rev=193786&r1=193785&r2=193786&view=diff
==============================================================================
--- lldb/trunk/source/API/SBValue.cpp (original)
+++ lldb/trunk/source/API/SBValue.cpp Thu Oct 31 13:57:50 2013
@@ -1048,11 +1048,12 @@ SBValue::GetValueAsSigned(SBError& error
     lldb::ValueObjectSP value_sp(GetSP(locker));
     if (value_sp)
     {
-        Scalar scalar;
-        if (value_sp->ResolveValue (scalar))
-            return scalar.SLongLong (fail_value);
-        else
-            error.SetErrorString ("could not resolve value");
+        bool success = true;
+        uint64_t ret_val = fail_value;
+        ret_val = value_sp->GetValueAsSigned(fail_value, &success);
+        if (!success)
+            error.SetErrorString("could not resolve value");
+        return ret_val;
     }
     else
         error.SetErrorStringWithFormat ("could not get SBValue: %s", locker.GetError().AsCString());
@@ -1068,11 +1069,12 @@ SBValue::GetValueAsUnsigned(SBError& err
     lldb::ValueObjectSP value_sp(GetSP(locker));
     if (value_sp)
     {
-        Scalar scalar;
-        if (value_sp->ResolveValue (scalar))
-            return scalar.ULongLong(fail_value);
-        else
+        bool success = true;
+        uint64_t ret_val = fail_value;
+        ret_val = value_sp->GetValueAsUnsigned(fail_value, &success);
+        if (!success)
             error.SetErrorString("could not resolve value");
+        return ret_val;
     }
     else
         error.SetErrorStringWithFormat ("could not get SBValue: %s", locker.GetError().AsCString());
@@ -1087,9 +1089,7 @@ SBValue::GetValueAsSigned(int64_t fail_v
     lldb::ValueObjectSP value_sp(GetSP(locker));
     if (value_sp)
     {
-        Scalar scalar;
-        if (value_sp->ResolveValue (scalar))
-            return scalar.SLongLong(fail_value);
+        return value_sp->GetValueAsSigned(fail_value);
     }
     return fail_value;
 }
@@ -1101,9 +1101,7 @@ SBValue::GetValueAsUnsigned(uint64_t fai
     lldb::ValueObjectSP value_sp(GetSP(locker));
     if (value_sp)
     {
-        Scalar scalar;
-        if (value_sp->ResolveValue (scalar))
-            return scalar.ULongLong(fail_value);
+        return value_sp->GetValueAsUnsigned(fail_value);
     }
     return fail_value;
 }

Modified: lldb/trunk/source/Core/ValueObject.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/ValueObject.cpp?rev=193786&r1=193785&r2=193786&view=diff
==============================================================================
--- lldb/trunk/source/Core/ValueObject.cpp (original)
+++ lldb/trunk/source/Core/ValueObject.cpp Thu Oct 31 13:57:50 2013
@@ -1542,6 +1542,27 @@ ValueObject::GetValueAsUnsigned (uint64_
     return fail_value;
 }
 
+int64_t
+ValueObject::GetValueAsSigned (int64_t fail_value, bool *success)
+{
+    // If our byte size is zero this is an aggregate type that has children
+    if (!GetClangType().IsAggregateType())
+    {
+        Scalar scalar;
+        if (ResolveValue (scalar))
+        {
+            if (success)
+                *success = true;
+                return scalar.SLongLong(fail_value);
+        }
+        // fallthrough, otherwise...
+    }
+    
+    if (success)
+        *success = false;
+        return fail_value;
+}
+
 // if any more "special cases" are added to ValueObject::DumpPrintableRepresentation() please keep
 // this call up to date by returning true for your new special cases. We will eventually move
 // to checking this call result before trying to display special cases





More information about the lldb-commits mailing list