diff --git a/lldb/include/lldb/DataFormatters/DumpValueObjectOptions.h b/lldb/include/lldb/DataFormatters/DumpValueObjectOptions.h --- a/lldb/include/lldb/DataFormatters/DumpValueObjectOptions.h +++ b/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}; diff --git a/lldb/source/DataFormatters/ValueObjectPrinter.cpp b/lldb/source/DataFormatters/ValueObjectPrinter.cpp --- a/lldb/source/DataFormatters/ValueObjectPrinter.cpp +++ b/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(); } } 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 --- /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 --- /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 --- /dev/null +++ b/lldb/test/API/lang/cpp/frame-var-depth-and-elem-count/main.cpp @@ -0,0 +1,19 @@ +#include + +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 +}