[Lldb-commits] [PATCH] Fix ValueObject::GetValueDidChange; Improve test for it

Ilia K ki.stfu at gmail.com
Fri Mar 6 05:57:30 PST 2015


Hi clayborg, zturner, granata.enrico,

ValueObject::GetValueDidChange is a getter for
ValueObject.m_value_did_change, which is set in
ValueObject::UpdateValueIfNeeded. When this method is called, it checks
previous checksum using the ValueObject::IsChecksumEmpty method. If
checksum is empty then it can't determine whether the value was changed
or not. To prevent it we should call ValueObject::UpdateValueIfNeeded
for all children when any ValueObject is created.

Previously ValueObject::GetValueDidChange worked only for simple objects
without children because it called ValueObject::GetNumChildren() which
in its turn called ValueObject::UpdateValueIfNeeded (just luck).

Also this patch contains improvements for TestValueVarUpdate.py test
which checks ValueObject::GetValueDidChange for complex types.

http://reviews.llvm.org/D8103

Files:
  include/lldb/Core/ValueObjectVariable.h
  source/Core/ValueObjectVariable.cpp
  test/python_api/value_var_update/TestValueVarUpdate.py
  test/python_api/value_var_update/main.c

Index: include/lldb/Core/ValueObjectVariable.h
===================================================================
--- include/lldb/Core/ValueObjectVariable.h
+++ include/lldb/Core/ValueObjectVariable.h
@@ -82,6 +82,10 @@
 
 private:
     ValueObjectVariable (ExecutionContextScope *exe_scope, const lldb::VariableSP &var_sp);
+
+    static void
+    UpdateValueObjectAndChildren(lldb::ValueObjectSP &valobj_sp);
+
     //------------------------------------------------------------------
     // For ValueObject only
     //------------------------------------------------------------------
Index: source/Core/ValueObjectVariable.cpp
===================================================================
--- source/Core/ValueObjectVariable.cpp
+++ source/Core/ValueObjectVariable.cpp
@@ -38,7 +38,25 @@
 lldb::ValueObjectSP
 ValueObjectVariable::Create (ExecutionContextScope *exe_scope, const lldb::VariableSP &var_sp)
 {
-    return (new ValueObjectVariable (exe_scope, var_sp))->GetSP();
+    lldb::ValueObjectSP valobj_sp((new ValueObjectVariable (exe_scope, var_sp))->GetSP());
+    UpdateValueObjectAndChildren(valobj_sp);
+    return valobj_sp;
+}
+
+void
+ValueObjectVariable::UpdateValueObjectAndChildren(lldb::ValueObjectSP &valobj_sp)
+{
+    valobj_sp->UpdateValueIfNeeded();
+
+    if (!valobj_sp->IsPointerOrReferenceType())
+    {
+        const size_t valobj_child_num = valobj_sp->GetNumChildren();
+        for (size_t i = 0; i < valobj_child_num; ++i)
+        {
+            lldb::ValueObjectSP child = valobj_sp->GetChildAtIndex(i, true);
+            UpdateValueObjectAndChildren(child);
+        }
+    }
 }
 
 ValueObjectVariable::ValueObjectVariable (ExecutionContextScope *exe_scope, const lldb::VariableSP &var_sp) :
Index: test/python_api/value_var_update/TestValueVarUpdate.py
===================================================================
--- test/python_api/value_var_update/TestValueVarUpdate.py
+++ test/python_api/value_var_update/TestValueVarUpdate.py
@@ -52,6 +52,7 @@
 
         i = self.frame().FindVariable("i")
         i_val = i.GetValueAsUnsigned(0)
+        c = self.frame().FindVariable("c")
         
         if self.TraceOn(): self.runCmd("frame variable")
         
@@ -62,6 +63,9 @@
         self.assertTrue(i_val != i.GetValueAsUnsigned(0), "GetValue() is saying a lie")
         self.assertTrue(i.GetValueDidChange(), "GetValueDidChange() is saying a lie")
 
+        # Check complex type
+        self.assertTrue(c.GetChildAtIndex(0).GetChildAtIndex(0).GetValueDidChange() and
+                        not c.GetChildAtIndex(1).GetValueDidChange(), "GetValueDidChange() is saying a lie")
 
 if __name__ == '__main__':
     import atexit
Index: test/python_api/value_var_update/main.c
===================================================================
--- test/python_api/value_var_update/main.c
+++ test/python_api/value_var_update/main.c
@@ -1,8 +1,14 @@
+struct complex_type {
+    struct { long l; } inner;
+    struct complex_type *complex_ptr;
+};
+
 int main() {
     int i = 0;
+    struct complex_type c = { { 1L }, &c };
     for (int j = 3; j < 20; j++)
     {
-        i += j;
+        c.inner.l += (i += j);
         i = i - 1; // break here
     }
     return i;

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D8103.21345.patch
Type: text/x-patch
Size: 3232 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20150306/75c2fde1/attachment.bin>


More information about the lldb-commits mailing list