[Lldb-commits] [lldb] r237504 - Constant result ValueObjects are - well - constant

Enrico Granata egranata at apple.com
Fri May 15 18:27:01 PDT 2015


Author: enrico
Date: Fri May 15 20:27:00 2015
New Revision: 237504

URL: http://llvm.org/viewvc/llvm-project?rev=237504&view=rev
Log:
Constant result ValueObjects are - well  - constant
And they also do not have a thread/frame attached to them

That makes dynamic and synthetic values attached to them impossible to update - which, among other things, makes it impossible to properly display persistent variables of types that could have such dynamic/persistent values

Fix this by making it so that a ValueObject can control its constantness (hint: dynamic and synthetic values cannot be constant) and whether it wants to let itself be updated when an invalid thread is around


Added:
    lldb/trunk/test/expression_command/persistent_ptr_update/
    lldb/trunk/test/expression_command/persistent_ptr_update/Makefile
    lldb/trunk/test/expression_command/persistent_ptr_update/TestPersistentPtrUpdate.py
    lldb/trunk/test/expression_command/persistent_ptr_update/main.c
Modified:
    lldb/trunk/include/lldb/Core/ValueObject.h
    lldb/trunk/include/lldb/Core/ValueObjectDynamicValue.h
    lldb/trunk/include/lldb/Core/ValueObjectSyntheticFilter.h
    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=237504&r1=237503&r2=237504&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/ValueObject.h (original)
+++ lldb/trunk/include/lldb/Core/ValueObject.h Fri May 15 20:27:00 2015
@@ -285,18 +285,19 @@ public:
         SetUpdated ();
         
         bool
-        NeedsUpdating()
+        NeedsUpdating(bool accept_invalid_exe_ctx)
         {
-            SyncWithProcessState();
+            SyncWithProcessState(accept_invalid_exe_ctx);
             return m_needs_update;
         }
         
         bool
         IsValid ()
         {
+            const bool accept_invalid_exe_ctx = false;
             if (!m_mod_id.IsValid())
                 return false;
-            else if (SyncWithProcessState ())
+            else if (SyncWithProcessState (accept_invalid_exe_ctx))
             {
                 if (!m_mod_id.IsValid())
                     return false;
@@ -318,7 +319,7 @@ public:
         
     private:
         bool
-        SyncWithProcessState ();
+        SyncWithProcessState (bool accept_invalid_exe_ctx);
                 
         ProcessModID m_mod_id; // This is the stop id when this ValueObject was last evaluated.
         ExecutionContextRef m_exe_ctx_ref;
@@ -851,12 +852,19 @@ public:
     virtual bool
     SetData (DataExtractor &data, Error &error);
 
-    bool
+    virtual bool
     GetIsConstant () const
     {
         return m_update_point.IsConstant();
     }
     
+    virtual bool
+    NeedsUpdating ()
+    {
+        const bool accept_invalid_exe_ctx = false;
+        return m_update_point.NeedsUpdating(accept_invalid_exe_ctx);
+    }
+    
     void
     SetIsConstant ()
     {

Modified: lldb/trunk/include/lldb/Core/ValueObjectDynamicValue.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/ValueObjectDynamicValue.h?rev=237504&r1=237503&r2=237504&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/ValueObjectDynamicValue.h (original)
+++ lldb/trunk/include/lldb/Core/ValueObjectDynamicValue.h Fri May 15 20:27:00 2015
@@ -56,6 +56,19 @@ public:
         return true;
     }
     
+    virtual bool
+    GetIsConstant () const
+    {
+        return false;
+    }
+    
+    virtual bool
+    NeedsUpdating ()
+    {
+        const bool accept_invalid_exe_ctx = true;
+        return m_update_point.NeedsUpdating(accept_invalid_exe_ctx);
+    }
+    
     virtual ValueObject *
     GetParent()
     {

Modified: lldb/trunk/include/lldb/Core/ValueObjectSyntheticFilter.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/ValueObjectSyntheticFilter.h?rev=237504&r1=237503&r2=237504&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/ValueObjectSyntheticFilter.h (original)
+++ lldb/trunk/include/lldb/Core/ValueObjectSyntheticFilter.h Fri May 15 20:27:00 2015
@@ -141,6 +141,19 @@ public:
     }
     
     virtual bool
+    GetIsConstant () const
+    {
+        return false;
+    }
+    
+    virtual bool
+    NeedsUpdating ()
+    {
+        const bool accept_invalid_exe_ctx = true;
+        return m_update_point.NeedsUpdating(accept_invalid_exe_ctx);
+    }
+    
+    virtual bool
     SetValueFromCString (const char *value_str, Error& error);
     
     virtual void

Modified: lldb/trunk/source/Core/ValueObject.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/ValueObject.cpp?rev=237504&r1=237503&r2=237504&view=diff
==============================================================================
--- lldb/trunk/source/Core/ValueObject.cpp (original)
+++ lldb/trunk/source/Core/ValueObject.cpp Fri May 15 20:27:00 2015
@@ -198,7 +198,7 @@ ValueObject::UpdateValueIfNeeded (bool u
 
     bool first_update = IsChecksumEmpty();
     
-    if (m_update_point.NeedsUpdating())
+    if (NeedsUpdating())
     {
         m_update_point.SetUpdated();
         
@@ -3952,9 +3952,8 @@ ValueObject::EvaluationPoint::~Evaluatio
 // exe_scope will be set to the current execution context scope.
 
 bool
-ValueObject::EvaluationPoint::SyncWithProcessState()
+ValueObject::EvaluationPoint::SyncWithProcessState(bool accept_invalid_exe_ctx)
 {
-
     // Start with the target, if it is NULL, then we're obviously not going to get any further:
     const bool thread_and_frame_only_if_stopped = true;
     ExecutionContext exe_ctx(m_exe_ctx_ref.Lock(thread_and_frame_only_if_stopped));
@@ -3997,30 +3996,33 @@ ValueObject::EvaluationPoint::SyncWithPr
     // That way we'll be sure to return a valid exe_scope.
     // If we used to have a thread or a frame but can't find it anymore, then mark ourselves as invalid.
     
-    if (m_exe_ctx_ref.HasThreadRef())
+    if (!accept_invalid_exe_ctx)
     {
-        ThreadSP thread_sp (m_exe_ctx_ref.GetThreadSP());
-        if (thread_sp)
+        if (m_exe_ctx_ref.HasThreadRef())
         {
-            if (m_exe_ctx_ref.HasFrameRef())
+            ThreadSP thread_sp (m_exe_ctx_ref.GetThreadSP());
+            if (thread_sp)
             {
-                StackFrameSP frame_sp (m_exe_ctx_ref.GetFrameSP());
-                if (!frame_sp)
+                if (m_exe_ctx_ref.HasFrameRef())
                 {
-                    // We used to have a frame, but now it is gone
-                    SetInvalid();
-                    changed = was_valid;
+                    StackFrameSP frame_sp (m_exe_ctx_ref.GetFrameSP());
+                    if (!frame_sp)
+                    {
+                        // We used to have a frame, but now it is gone
+                        SetInvalid();
+                        changed = was_valid;
+                    }
                 }
             }
+            else
+            {
+                // We used to have a thread, but now it is gone
+                SetInvalid();
+                changed = was_valid;
+            }
         }
-        else
-        {
-            // We used to have a thread, but now it is gone
-            SetInvalid();
-            changed = was_valid;
-        }
-
     }
+
     return changed;
 }
 

Added: lldb/trunk/test/expression_command/persistent_ptr_update/Makefile
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/expression_command/persistent_ptr_update/Makefile?rev=237504&view=auto
==============================================================================
--- lldb/trunk/test/expression_command/persistent_ptr_update/Makefile (added)
+++ lldb/trunk/test/expression_command/persistent_ptr_update/Makefile Fri May 15 20:27:00 2015
@@ -0,0 +1,7 @@
+LEVEL = ../../make
+
+C_SOURCES := main.c
+
+include $(LEVEL)/Makefile.rules
+
+

Added: lldb/trunk/test/expression_command/persistent_ptr_update/TestPersistentPtrUpdate.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/expression_command/persistent_ptr_update/TestPersistentPtrUpdate.py?rev=237504&view=auto
==============================================================================
--- lldb/trunk/test/expression_command/persistent_ptr_update/TestPersistentPtrUpdate.py (added)
+++ lldb/trunk/test/expression_command/persistent_ptr_update/TestPersistentPtrUpdate.py Fri May 15 20:27:00 2015
@@ -0,0 +1,55 @@
+"""
+Test that we can have persistent pointer variables
+"""
+
+import unittest2
+import lldb
+import lldbutil
+from lldbtest import *
+
+class PersistentPtrUpdateTestCase(TestBase):
+
+    mydir = TestBase.compute_mydir(__file__)
+
+    def setUp(self):
+        # Call super's setUp().
+        TestBase.setUp(self)
+
+    @skipUnlessDarwin
+    @dsym_test
+    def test_with_dsym(self):
+        """Test that we can have persistent pointer variables"""
+        self.buildDsym()
+        self.do_my_test()
+
+    @skipUnlessDarwin
+    @dwarf_test
+    def test_with_dwarf(self):
+        """Test that we can have persistent pointer variables"""
+        self.buildDwarf()
+        self.do_my_test()
+
+    def do_my_test(self):
+        def cleanup():
+            pass
+        
+        # Execute the cleanup function during test case tear down.
+        self.addTearDownHook(cleanup)
+
+        self.runCmd("file a.out", CURRENT_EXECUTABLE_SET)
+        
+        self.runCmd('break set -p here')
+
+        self.runCmd("run", RUN_SUCCEEDED)
+        
+        self.runCmd("expr void* $foo = nullptr")
+        
+        self.runCmd("continue")
+        
+        self.expect("expr $foo", substrs=['$foo','0x0'])
+
+if __name__ == '__main__':
+    import atexit
+    lldb.SBDebugger.Initialize()
+    atexit.register(lambda: lldb.SBDebugger.Terminate())
+    unittest2.main()

Added: lldb/trunk/test/expression_command/persistent_ptr_update/main.c
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/expression_command/persistent_ptr_update/main.c?rev=237504&view=auto
==============================================================================
--- lldb/trunk/test/expression_command/persistent_ptr_update/main.c (added)
+++ lldb/trunk/test/expression_command/persistent_ptr_update/main.c Fri May 15 20:27:00 2015
@@ -0,0 +1,11 @@
+void* foo(void *p)
+{
+  return p; // break here
+}
+
+int main() {
+  while (1) {
+    foo(0);
+  }
+  return 0;
+}





More information about the lldb-commits mailing list