Author: Walter Erquinigo
Date: 2021-05-26T14:52:38-07:00
New Revision: 0283abee5c87e86552b456a34d01311b66c37207

URL: 
https://github.com/llvm/llvm-project/commit/0283abee5c87e86552b456a34d01311b66c37207
DIFF: 
https://github.com/llvm/llvm-project/commit/0283abee5c87e86552b456a34d01311b66c37207.diff

LOG: [lldb] Fix gnu_libstdcpp's update methods

The variable.rst documentation says:

```
If it returns a value, and that value is True, LLDB will be allowed to cache 
the children and the children count it previously obtained, and will not return 
to the provider class to ask.  If nothing, None, or anything other than True is 
returned, LLDB will discard the cached information and ask. Regardless, 
whenever necessary LLDB will call update.
```

However, several update methods in gnu_libstdcpp.py were returning True,
which made lldb unaware of any changes in the corresponding objects.
This problem was visible by lldb-vscode in the following way:

- If a breakpoint is hit and there's a vector with the contents {1, 2},
  it'll be displayed correctly.
- Then the user steps and the next stop contains the vector modified.
  The program changed it to {1, 2, 3}
- frame var then displays {1, 2} incorrectly, due to the caching caused
by the update method

It's worth mentioning that none of libcxx.py'd update methods return True. Same 
for LibCxxVector.cpp, which returns false.

Added a very simple test that fails without this fix.

Differential Revision: https://reviews.llvm.org/D103209

Added: 
    

Modified: 
    lldb/examples/synthetic/gnu_libstdcpp.py
    lldb/test/API/tools/lldb-vscode/evaluate/TestVSCode_evaluate.py
    lldb/test/API/tools/lldb-vscode/evaluate/main.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/examples/synthetic/gnu_libstdcpp.py 
b/lldb/examples/synthetic/gnu_libstdcpp.py
index 35f009e1bcba8..528b28349bb1a 100644
--- a/lldb/examples/synthetic/gnu_libstdcpp.py
+++ b/lldb/examples/synthetic/gnu_libstdcpp.py
@@ -148,6 +148,7 @@ def update(self):
             self.data_size = self.data_type.GetByteSize()
         except:
             pass
+        return False
 
     def has_children(self):
         return True
@@ -235,7 +236,7 @@ def update(self):
                     self.count = 0
             except:
                 pass
-            return True
+            return False 
 
     class StdVBoolImplementation(object):
 
@@ -282,7 +283,7 @@ def update(self):
                 self.valid = True
             except:
                 self.valid = False
-            return True
+            return False
 
     def __init__(self, valobj, dict):
         logger = lldb.formatters.Logger.Logger()
@@ -378,6 +379,7 @@ def update(self):
             self.skip_size = self.Mheader.GetType().GetByteSize()
         except:
             pass
+        return False
 
     def num_children(self):
         logger = lldb.formatters.Logger.Logger()

diff  --git a/lldb/test/API/tools/lldb-vscode/evaluate/TestVSCode_evaluate.py 
b/lldb/test/API/tools/lldb-vscode/evaluate/TestVSCode_evaluate.py
index c0ccd2ef43be3..fdd5c47398d00 100644
--- a/lldb/test/API/tools/lldb-vscode/evaluate/TestVSCode_evaluate.py
+++ b/lldb/test/API/tools/lldb-vscode/evaluate/TestVSCode_evaluate.py
@@ -39,7 +39,11 @@ def run_test_evaluate_expressions(self, context=None):
             [
                 line_number(source, "// breakpoint 1"),
                 line_number(source, "// breakpoint 2"),
-                line_number(source, "// breakpoint 3")
+                line_number(source, "// breakpoint 3"),
+                line_number(source, "// breakpoint 4"),
+                line_number(source, "// breakpoint 5"),
+                line_number(source, "// breakpoint 6"),
+                line_number(source, "// breakpoint 7"),
             ]
         )
         self.continue_to_next_stop()
@@ -132,6 +136,20 @@ def run_test_evaluate_expressions(self, context=None):
             self.assertEvaluateFailure("foo_func")
             self.assertEvaluateFailure("foo_var")
 
+        # Now we check that values are updated after stepping
+        self.continue_to_next_stop()
+        self.assertEvaluate("my_vec", "size=2")
+        self.continue_to_next_stop()
+        self.assertEvaluate("my_vec", "size=3")
+
+        self.assertEvaluate("my_map", "size=2")
+        self.continue_to_next_stop()
+        self.assertEvaluate("my_map", "size=3")
+        
+        self.assertEvaluate("my_bool_vec", "size=1")
+        self.continue_to_next_stop()
+        self.assertEvaluate("my_bool_vec", "size=2")
+
     @skipIfWindows
     @skipIfRemote
     def test_generic_evaluate_expressions(self):

diff  --git a/lldb/test/API/tools/lldb-vscode/evaluate/main.cpp 
b/lldb/test/API/tools/lldb-vscode/evaluate/main.cpp
index 564660da7119c..3a541b21b2208 100644
--- a/lldb/test/API/tools/lldb-vscode/evaluate/main.cpp
+++ b/lldb/test/API/tools/lldb-vscode/evaluate/main.cpp
@@ -1,5 +1,8 @@
 #include "foo.h"
 
+#include <vector>
+#include <map>
+
 static int static_int = 42;
 
 int non_static_int = 43;
@@ -25,5 +28,21 @@ int main(int argc, char const *argv[]) {
   }
   a_function(var3);
   foo_func();
+
+  std::vector<int> my_vec;
+  my_vec.push_back(1);
+  my_vec.push_back(2);
+  my_vec.push_back(3); // breakpoint 4
+
+  std::map<int, int> my_map;
+  my_map[1] = 2;
+  my_map[2] = 3;
+  my_map[3] = 4; // breakpoint 5
+
+  std::vector<bool> my_bool_vec;
+  my_bool_vec.push_back(true);
+  my_bool_vec.push_back(false); // breakpoint 6
+  my_bool_vec.push_back(true); // breakpoint 7
+  
   return 0;
 }


        
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to