[Lldb-commits] [lldb] r156422 - in /lldb/trunk: include/lldb/API/SBValue.h include/lldb/Core/ValueObject.h include/lldb/Core/ValueObjectDynamicValue.h include/lldb/Core/ValueObjectRegister.h scripts/Python/interface/SBValue.i source/API/SBValue.cpp source/Core/ValueObject.cpp source/Core/ValueObjectDynamicValue.cpp source/Core/ValueObjectRegister.cpp

Enrico Granata egranata at apple.com
Tue May 8 14:25:07 PDT 2012


Author: enrico
Date: Tue May  8 16:25:06 2012
New Revision: 156422

URL: http://llvm.org/viewvc/llvm-project?rev=156422&view=rev
Log:
<rdar://problem/11239650> Fixing a bug where the SetValueFromCString() method failed to operate on dynamic values. The fix consists in making the set operation fall through to the parent. We only actually allow this if the dynamic value is at a 0-offset from the parent, or the new value is 0. Other scenarios would need agreement on the actual meaning of the set operation (do we keep offsetting? do we just assume the user knows what they are doing?) so we prevent them, and let the expression parser deal with the complexity

Modified:
    lldb/trunk/include/lldb/API/SBValue.h
    lldb/trunk/include/lldb/Core/ValueObject.h
    lldb/trunk/include/lldb/Core/ValueObjectDynamicValue.h
    lldb/trunk/include/lldb/Core/ValueObjectRegister.h
    lldb/trunk/scripts/Python/interface/SBValue.i
    lldb/trunk/source/API/SBValue.cpp
    lldb/trunk/source/Core/ValueObject.cpp
    lldb/trunk/source/Core/ValueObjectDynamicValue.cpp
    lldb/trunk/source/Core/ValueObjectRegister.cpp

Modified: lldb/trunk/include/lldb/API/SBValue.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBValue.h?rev=156422&r1=156421&r2=156422&view=diff
==============================================================================
--- lldb/trunk/include/lldb/API/SBValue.h (original)
+++ lldb/trunk/include/lldb/API/SBValue.h Tue May  8 16:25:06 2012
@@ -101,8 +101,12 @@
     const char *
     GetLocation ();
 
+    // Deprecated - use the one that takes SBError&
     bool
     SetValueFromCString (const char *value_str);
+
+    bool
+    SetValueFromCString (const char *value_str, lldb::SBError& error);
     
     lldb::SBTypeFormat
     GetTypeFormat ();

Modified: lldb/trunk/include/lldb/Core/ValueObject.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/ValueObject.h?rev=156422&r1=156421&r2=156422&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/ValueObject.h (original)
+++ lldb/trunk/include/lldb/Core/ValueObject.h Tue May  8 16:25:06 2012
@@ -696,8 +696,8 @@
     GetValueAsUnsigned (uint64_t fail_value);
 
     virtual bool
-    SetValueFromCString (const char *value_str);
-
+    SetValueFromCString (const char *value_str, Error& error);
+    
     // Return the module associated with this value object in case the
     // value is from an executable file and might have its data in
     // sections of the file. This can be used for variables.

Modified: lldb/trunk/include/lldb/Core/ValueObjectDynamicValue.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/ValueObjectDynamicValue.h?rev=156422&r1=156421&r2=156422&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/ValueObjectDynamicValue.h (original)
+++ lldb/trunk/include/lldb/Core/ValueObjectDynamicValue.h Tue May  8 16:25:06 2012
@@ -160,6 +160,9 @@
         m_owning_valobj_sp = owning_sp;
     }
     
+    virtual bool
+    SetValueFromCString (const char *value_str, Error& error);
+    
 protected:
     virtual bool
     UpdateValue ();

Modified: lldb/trunk/include/lldb/Core/ValueObjectRegister.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/ValueObjectRegister.h?rev=156422&r1=156421&r2=156422&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/ValueObjectRegister.h (original)
+++ lldb/trunk/include/lldb/Core/ValueObjectRegister.h Tue May  8 16:25:06 2012
@@ -158,7 +158,7 @@
     CalculateNumChildren();
     
     virtual bool
-    SetValueFromCString (const char *value_str);
+    SetValueFromCString (const char *value_str, Error& error);
 
     virtual bool
     ResolveValue (Scalar &scalar);

Modified: lldb/trunk/scripts/Python/interface/SBValue.i
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/Python/interface/SBValue.i?rev=156422&r1=156421&r2=156422&view=diff
==============================================================================
--- lldb/trunk/scripts/Python/interface/SBValue.i (original)
+++ lldb/trunk/scripts/Python/interface/SBValue.i Tue May  8 16:25:06 2012
@@ -139,6 +139,9 @@
     bool
     SetValueFromCString (const char *value_str);
 
+    bool
+    SetValueFromCString (const char *value_str, lldb::SBError& error);
+
     lldb::SBTypeFormat
     GetTypeFormat ();
     

Modified: lldb/trunk/source/API/SBValue.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBValue.cpp?rev=156422&r1=156421&r2=156422&view=diff
==============================================================================
--- lldb/trunk/source/API/SBValue.cpp (original)
+++ lldb/trunk/source/API/SBValue.cpp Tue May  8 16:25:06 2012
@@ -430,9 +430,17 @@
     return cstr;
 }
 
+// Deprecated - use the one that takes an lldb::SBError
 bool
 SBValue::SetValueFromCString (const char *value_str)
 {
+    lldb::SBError dummy;
+    return SetValueFromCString(value_str,dummy);
+}
+
+bool
+SBValue::SetValueFromCString (const char *value_str, lldb::SBError& error)
+{
     bool success = false;
     lldb::ValueObjectSP value_sp(GetSP());
     LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
@@ -451,7 +459,7 @@
             if (target_sp)
             {
                 Mutex::Locker api_locker (target_sp->GetAPIMutex());
-                success = value_sp->SetValueFromCString (value_str);
+                success = value_sp->SetValueFromCString (value_str,error.ref());
             }
         }
     }

Modified: lldb/trunk/source/Core/ValueObject.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/ValueObject.cpp?rev=156422&r1=156421&r2=156422&view=diff
==============================================================================
--- lldb/trunk/source/Core/ValueObject.cpp (original)
+++ lldb/trunk/source/Core/ValueObject.cpp Tue May  8 16:25:06 2012
@@ -1591,12 +1591,16 @@
 }
 
 bool
-ValueObject::SetValueFromCString (const char *value_str)
+ValueObject::SetValueFromCString (const char *value_str, Error& error)
 {
+    error.Clear();
     // Make sure our value is up to date first so that our location and location
     // type is valid.
     if (!UpdateValueIfNeeded(false))
+    {
+        error.SetErrorString("unable to read value");
         return false;
+    }
 
     uint32_t count = 0;
     Encoding encoding = ClangASTType::GetEncoding (GetClangType(), count);
@@ -1615,7 +1619,6 @@
         // If the value fits in a scalar, then make a new scalar and again let the
         // scalar code do the conversion, then figure out where to put the new value.
         Scalar new_scalar;
-        Error error;
         error = new_scalar.SetValueFromCString (value_str, encoding, byte_size);
         if (error.Success())
         {
@@ -1634,8 +1637,13 @@
                                                                              new_scalar, 
                                                                              byte_size, 
                                                                              error);
-                        if (!error.Success() || bytes_written != byte_size)
-                            return false;                            
+                        if (!error.Success())
+                            return false;
+                        if (bytes_written != byte_size)
+                        {
+                            error.SetErrorString("unable to write value to memory");
+                            return false;
+                        }
                     }
                 }
                 break;
@@ -1673,6 +1681,7 @@
     else
     {
         // We don't support setting things bigger than a scalar at present.
+        error.SetErrorString("unable to write aggregate data type");
         return false;
     }
     

Modified: lldb/trunk/source/Core/ValueObjectDynamicValue.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/ValueObjectDynamicValue.cpp?rev=156422&r1=156421&r2=156422&view=diff
==============================================================================
--- lldb/trunk/source/Core/ValueObjectDynamicValue.cpp (original)
+++ lldb/trunk/source/Core/ValueObjectDynamicValue.cpp Tue May  8 16:25:06 2012
@@ -359,3 +359,39 @@
     return m_parent->IsInScope();
 }
 
+bool
+ValueObjectDynamicValue::SetValueFromCString (const char *value_str, Error& error)
+{
+    if (!UpdateValueIfNeeded(false))
+    {
+        error.SetErrorString("unable to read value");
+        return false;
+    }
+    
+    uint64_t my_value = GetValueAsUnsigned(UINT64_MAX);
+    uint64_t parent_value = m_parent->GetValueAsUnsigned(UINT64_MAX);
+    
+    if (my_value == UINT64_MAX || parent_value == UINT64_MAX)
+    {
+        error.SetErrorString("unable to read value");
+        return false;
+    }
+    
+    // if we are at an offset from our parent, in order to set ourselves correctly we would need
+    // to change the new value so that it refers to the correct dynamic type. we choose not to deal
+    // with that - if anything more than a value overwrite is required, you should be using the
+    // expression parser instead of the value editing facility
+    if (my_value != parent_value)
+    {
+        // but NULL'ing out a value should always be allowed
+        if (strcmp(value_str,"0"))
+        {
+            error.SetErrorString("unable to modify dynamic value, use 'expression' command");
+            return false;
+        }
+    }
+    
+    bool ret_val = m_parent->SetValueFromCString(value_str,error);
+    SetNeedsUpdate();
+    return ret_val;
+}

Modified: lldb/trunk/source/Core/ValueObjectRegister.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/ValueObjectRegister.cpp?rev=156422&r1=156421&r2=156422&view=diff
==============================================================================
--- lldb/trunk/source/Core/ValueObjectRegister.cpp (original)
+++ lldb/trunk/source/Core/ValueObjectRegister.cpp Tue May  8 16:25:06 2012
@@ -404,10 +404,10 @@
 }
 
 bool
-ValueObjectRegister::SetValueFromCString (const char *value_str)
+ValueObjectRegister::SetValueFromCString (const char *value_str, Error& error)
 {
     // The new value will be in the m_data.  Copy that into our register value.
-    Error error = m_reg_value.SetValueFromCString (&m_reg_info, value_str); 
+    error = m_reg_value.SetValueFromCString (&m_reg_info, value_str);
     if (error.Success())
     {
         if (m_reg_ctx_sp->WriteRegister (&m_reg_info, m_reg_value))





More information about the lldb-commits mailing list