augusto2112 updated this revision to Diff 529709.
augusto2112 marked an inline comment as done.
augusto2112 added a comment.
Addressed comments
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D151950/new/
https://reviews.llvm.org/D151950
Files:
lldb/include/lldb/DataFormatters/DumpValueObjectOptions.h
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,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
+}
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,15 +603,18 @@
.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();
}
}
Index: lldb/include/lldb/DataFormatters/DumpValueObjectOptions.h
===================================================================
--- lldb/include/lldb/DataFormatters/DumpValueObjectOptions.h
+++ lldb/include/lldb/DataFormatters/DumpValueObjectOptions.h
@@ -25,7 +25,7 @@
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};
_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits