[Lldb-commits] [PATCH] D151950: [lldb] Unconditionally increment depth when printing children

Augusto Noronha via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Wed Jun 7 16:13:34 PDT 2023


augusto2112 updated this revision to Diff 529463.
augusto2112 added a comment.

Add test


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151950

Files:
  lldb/source/DataFormatters/ValueObjectPrinter.cpp
  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


Index: lldb/test/API/lang/cpp/frame-var-depth-and-elem-count/main.cpp
===================================================================
--- /dev/null
+++ lldb/test/API/lang/cpp/frame-var-depth-and-elem-count/main.cpp
@@ -0,0 +1,16 @@
+struct A {
+  int i = 42;
+};
+
+struct B {
+  A a;
+};
+
+struct C {
+  B b;
+};
+
+int main() {
+  C *c = new C[5];
+  return 0; // break here
+}
Index: lldb/test/API/lang/cpp/frame-var-depth-and-elem-count/TestFrameVarDepthAndElemCount.py
===================================================================
--- /dev/null
+++ 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  }',
+            ])
+
Index: lldb/test/API/lang/cpp/frame-var-depth-and-elem-count/Makefile
===================================================================
--- /dev/null
+++ lldb/test/API/lang/cpp/frame-var-depth-and-elem-count/Makefile
@@ -0,0 +1,3 @@
+CXX_SOURCES := main.cpp
+
+include Makefile.rules
Index: lldb/source/DataFormatters/ValueObjectPrinter.cpp
===================================================================
--- lldb/source/DataFormatters/ValueObjectPrinter.cpp
+++ lldb/source/DataFormatters/ValueObjectPrinter.cpp
@@ -590,7 +590,7 @@
 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,7 +603,7 @@
       .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);
 
@@ -611,7 +611,7 @@
     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);
+        m_curr_depth + 1, m_printed_instance_pointers);
     child_printer.PrintValueObject();
   }
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D151950.529463.patch
Type: text/x-patch
Size: 3202 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20230607/006d7d6f/attachment.bin>


More information about the lldb-commits mailing list