[Lldb-commits] [PATCH] D105470: [lldb] Clear children of ValueObject on value update

Andy Yankovsky via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Mon Jul 26 07:33:09 PDT 2021


werat updated this revision to Diff 361649.
werat added a comment.

[clang-tidy] Always open files using UTF-8 encoding

The encoding used for opening files depends on the OS and might be different
from UTF-8 (e.g. on Windows it can be CP-1252). The documentation files use
UTF-8 and might be incompatible with other encodings. For example, right now
`clang-tools-extra/docs/clang-tidy/checks/abseil-no-internal-dependencies.rst`
has non-ASCII quotes and running `add_new_check.py` fails on Windows, because
it tries to read the file with incompatible encoding.

Use `io.open` for compatibility with both Python 2 and Python 3.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D105470/new/

https://reviews.llvm.org/D105470

Files:
  lldb/source/Core/ValueObject.cpp
  lldb/test/API/python_api/value/change_values/TestChangeValueAPI.py
  lldb/test/API/python_api/value/change_values/main.c


Index: lldb/test/API/python_api/value/change_values/main.c
===================================================================
--- lldb/test/API/python_api/value/change_values/main.c
+++ lldb/test/API/python_api/value/change_values/main.c
@@ -8,7 +8,12 @@
   uint32_t  second_val;
   uint64_t  third_val;
 };
-  
+
+struct bar
+{
+  int value;
+};
+
 int main ()
 {
   int val = 100;
@@ -18,6 +23,11 @@
   ptr->second_val = 6666;
   ptr->third_val = 66666666;
 
+  struct bar _b1 = {.value = 1};
+  struct bar _b2 = {.value = 2};
+  struct bar *b1 = &_b1;
+  struct bar *b2 = &_b2;
+
   // Stop here and set values
   printf ("Val - %d Mine - %d, %d, %llu. Ptr - %d, %d, %llu\n", val, 
           mine.first_val, mine.second_val, mine.third_val,
Index: lldb/test/API/python_api/value/change_values/TestChangeValueAPI.py
===================================================================
--- lldb/test/API/python_api/value/change_values/TestChangeValueAPI.py
+++ lldb/test/API/python_api/value/change_values/TestChangeValueAPI.py
@@ -130,6 +130,41 @@
         self.assertEquals(actual_value, 98765,
                         "Got the right changed value from ptr->second_val")
 
+        # Test updating the children after updating the parent value.
+        def test_update_parent_value(parent):
+            self.assertEquals(
+                parent.GetValue(),
+                frame0.FindVariable("b1").GetValue())
+            self.assertEquals(parent.GetChildAtIndex(0).GetValue(), "1")
+
+            result = parent.SetValueFromCString(
+                frame0.FindVariable("b2").GetValue())
+            self.assertTrue(result, "Success setting {}".format(parent.name))
+            self.assertEquals(
+                parent.GetValue(),
+                frame0.FindVariable("b2").GetValue())
+            self.assertEquals(parent.GetChildAtIndex(0).GetValue(), "2")
+
+        # Test for value returned by SBFrame::EvaluateExpression.
+        test_update_parent_value(
+            frame0.EvaluateExpression("auto $b_0 = b1; $b_0"))
+
+        # Test for value _created_ by SBFrame::EvaluateExpression.
+        frame0.EvaluateExpression("auto $b_0 = b1")
+        test_update_parent_value(
+            frame0.FindValue('$b_0', lldb.eValueTypeConstResult))
+
+        # Test for value created by SBTarget::CreateValueFromData.
+        b1 = frame0.FindVariable("b1")
+        b1_size = b1.GetByteSize()
+        b1_value = b1.GetValueAsUnsigned()
+        b1_addr_bytes = b1_value.to_bytes(b1_size, 'little')
+        error = lldb.SBError()
+        data = lldb.SBData()
+        data.SetData(error, b1_addr_bytes, lldb.eByteOrderLittle, b1_size)
+        test_update_parent_value(
+            target.CreateValueFromData("b", data, b1.GetType()))
+
         # gcc may set multiple locations for breakpoint
         breakpoint.SetEnabled(False)
 
Index: lldb/source/Core/ValueObject.cpp
===================================================================
--- lldb/source/Core/ValueObject.cpp
+++ lldb/source/Core/ValueObject.cpp
@@ -231,6 +231,10 @@
   // We have to clear the value string here so ConstResult children will notice
   // if their values are changed by hand (i.e. with SetValueAsCString).
   ClearUserVisibleData(eClearUserVisibleDataItemsValue);
+  // Children have to be re-computed after updating the parent value.
+  m_flags.m_children_count_valid = false;
+  m_children.Clear();
+  SetSyntheticChildren(lldb::SyntheticChildrenSP());
 }
 
 void ValueObject::ClearDynamicTypeInformation() {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D105470.361649.patch
Type: text/x-patch
Size: 3521 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20210726/7755f335/attachment-0001.bin>


More information about the lldb-commits mailing list