Author: Augusto Noronha
Date: 2023-06-08T13:30:30-07:00
New Revision: b1ebfc5de34ef4c91aa6f163989de600fb5227f8

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

LOG: [lldb] Unconditionally increment depth when printing children

The `target.max-children-depth` setting and `--depth` flag would be
ignored if treating pointer as arrays, fix that by always incrementing
the current depth when printing a new child.

rdar://109855463

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

Added: 
    lldb/test/API/lang/cpp/frame-var-depth-and-elem-count/Makefile
    
lldb/test/API/lang/cpp/frame-var-depth-and-elem-count/TestFrameVarDepthAndElemCount.py
    lldb/test/API/lang/cpp/frame-var-depth-and-elem-count/main.cpp

Modified: 
    lldb/include/lldb/DataFormatters/DumpValueObjectOptions.h
    lldb/source/DataFormatters/ValueObjectPrinter.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/include/lldb/DataFormatters/DumpValueObjectOptions.h 
b/lldb/include/lldb/DataFormatters/DumpValueObjectOptions.h
index b622c34ec3e0f..c7f8cccc116c4 100644
--- a/lldb/include/lldb/DataFormatters/DumpValueObjectOptions.h
+++ b/lldb/include/lldb/DataFormatters/DumpValueObjectOptions.h
@@ -25,7 +25,7 @@ class DumpValueObjectOptions {
     enum class Mode { Always, Default, Never } m_mode;
     uint32_t m_count;
 
-    PointerDepth operator--() const {
+    PointerDepth Decremented() const {
       if (m_count > 0)
         return PointerDepth{m_mode, m_count - 1};
       return PointerDepth{m_mode, m_count};

diff  --git a/lldb/source/DataFormatters/ValueObjectPrinter.cpp 
b/lldb/source/DataFormatters/ValueObjectPrinter.cpp
index fac319f67c805..16aeff13791c5 100644
--- a/lldb/source/DataFormatters/ValueObjectPrinter.cpp
+++ b/lldb/source/DataFormatters/ValueObjectPrinter.cpp
@@ -590,7 +590,7 @@ void ValueObjectPrinter::PrintChildrenPreamble(bool 
value_printed,
 void ValueObjectPrinter::PrintChild(
     ValueObjectSP child_sp,
     const DumpValueObjectOptions::PointerDepth &curr_ptr_depth) {
-  const uint32_t consumed_depth = (!m_options.m_pointer_as_array) ? 1 : 0;
+  const uint32_t consumed_summary_depth = m_options.m_pointer_as_array ? 0 : 1;
   const bool does_consume_ptr_depth =
       ((IsPtr() && !m_options.m_pointer_as_array) || IsRef());
 
@@ -603,15 +603,18 @@ void ValueObjectPrinter::PrintChild(
       .SetHideValue(m_options.m_hide_value)
       .SetOmitSummaryDepth(child_options.m_omit_summary_depth > 1
                                ? child_options.m_omit_summary_depth -
-                                     consumed_depth
+                                     consumed_summary_depth
                                : 0)
       .SetElementCount(0);
 
   if (child_sp.get()) {
-    ValueObjectPrinter child_printer(
-        child_sp.get(), m_stream, child_options,
-        does_consume_ptr_depth ? --curr_ptr_depth : curr_ptr_depth,
-        m_curr_depth + consumed_depth, m_printed_instance_pointers);
+    auto ptr_depth = curr_ptr_depth;
+    if (does_consume_ptr_depth)
+      ptr_depth = curr_ptr_depth.Decremented();
+
+    ValueObjectPrinter child_printer(child_sp.get(), m_stream, child_options,
+                                     ptr_depth, m_curr_depth + 1,
+                                     m_printed_instance_pointers);
     child_printer.PrintValueObject();
   }
 }

diff  --git a/lldb/test/API/lang/cpp/frame-var-depth-and-elem-count/Makefile 
b/lldb/test/API/lang/cpp/frame-var-depth-and-elem-count/Makefile
new file mode 100644
index 0000000000000..99998b20bcb05
--- /dev/null
+++ b/lldb/test/API/lang/cpp/frame-var-depth-and-elem-count/Makefile
@@ -0,0 +1,3 @@
+CXX_SOURCES := main.cpp
+
+include Makefile.rules

diff  --git 
a/lldb/test/API/lang/cpp/frame-var-depth-and-elem-count/TestFrameVarDepthAndElemCount.py
 
b/lldb/test/API/lang/cpp/frame-var-depth-and-elem-count/TestFrameVarDepthAndElemCount.py
new file mode 100644
index 0000000000000..e8fa95ef6469a
--- /dev/null
+++ 
b/lldb/test/API/lang/cpp/frame-var-depth-and-elem-count/TestFrameVarDepthAndElemCount.py
@@ -0,0 +1,27 @@
+"""
+Tests that frame variable --depth and --element-count options work correctly
+together
+"""
+import lldb
+from lldbsuite.test.lldbtest import *
+import lldbsuite.test.lldbutil as lldbutil
+
+
+class TestFrameVarDepthAndElemCount(TestBase):
+    def test(self):
+        """Test that bool types work in the expression parser"""
+        self.build()
+        lldbutil.run_to_source_breakpoint(
+            self, "// break here", lldb.SBFileSpec("main.cpp")
+        )
+
+        # Check that we print 5 elements but only 2 levels deep.
+        self.expect('frame var --depth 2 --element-count 5 -- c', 
+        substrs=[
+            '[0] = {\n    b ={...}\n  }',
+            '[1] = {\n    b ={...}\n  }',
+            '[2] = {\n    b ={...}\n  }',
+            '[3] = {\n    b ={...}\n  }',
+            '[4] = {\n    b ={...}\n  }',
+            ])
+

diff  --git a/lldb/test/API/lang/cpp/frame-var-depth-and-elem-count/main.cpp 
b/lldb/test/API/lang/cpp/frame-var-depth-and-elem-count/main.cpp
new file mode 100644
index 0000000000000..7f787712e0f67
--- /dev/null
+++ b/lldb/test/API/lang/cpp/frame-var-depth-and-elem-count/main.cpp
@@ -0,0 +1,19 @@
+#include <cstdio>
+
+struct A {
+  int i = 42;
+};
+
+struct B {
+  A a;
+};
+
+struct C {
+  B b;
+};
+
+int main() {
+  C *c = new C[5];
+  puts("break here");
+  return 0; // break here
+}


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

Reply via email to