Skip to content

Commit b1ebfc5

Browse files
committed
[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
1 parent c16b7e5 commit b1ebfc5

File tree

5 files changed

+59
-7
lines changed

5 files changed

+59
-7
lines changed

lldb/include/lldb/DataFormatters/DumpValueObjectOptions.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class DumpValueObjectOptions {
2525
enum class Mode { Always, Default, Never } m_mode;
2626
uint32_t m_count;
2727

28-
PointerDepth operator--() const {
28+
PointerDepth Decremented() const {
2929
if (m_count > 0)
3030
return PointerDepth{m_mode, m_count - 1};
3131
return PointerDepth{m_mode, m_count};

lldb/source/DataFormatters/ValueObjectPrinter.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,7 @@ void ValueObjectPrinter::PrintChildrenPreamble(bool value_printed,
590590
void ValueObjectPrinter::PrintChild(
591591
ValueObjectSP child_sp,
592592
const DumpValueObjectOptions::PointerDepth &curr_ptr_depth) {
593-
const uint32_t consumed_depth = (!m_options.m_pointer_as_array) ? 1 : 0;
593+
const uint32_t consumed_summary_depth = m_options.m_pointer_as_array ? 0 : 1;
594594
const bool does_consume_ptr_depth =
595595
((IsPtr() && !m_options.m_pointer_as_array) || IsRef());
596596

@@ -603,15 +603,18 @@ void ValueObjectPrinter::PrintChild(
603603
.SetHideValue(m_options.m_hide_value)
604604
.SetOmitSummaryDepth(child_options.m_omit_summary_depth > 1
605605
? child_options.m_omit_summary_depth -
606-
consumed_depth
606+
consumed_summary_depth
607607
: 0)
608608
.SetElementCount(0);
609609

610610
if (child_sp.get()) {
611-
ValueObjectPrinter child_printer(
612-
child_sp.get(), m_stream, child_options,
613-
does_consume_ptr_depth ? --curr_ptr_depth : curr_ptr_depth,
614-
m_curr_depth + consumed_depth, m_printed_instance_pointers);
611+
auto ptr_depth = curr_ptr_depth;
612+
if (does_consume_ptr_depth)
613+
ptr_depth = curr_ptr_depth.Decremented();
614+
615+
ValueObjectPrinter child_printer(child_sp.get(), m_stream, child_options,
616+
ptr_depth, m_curr_depth + 1,
617+
m_printed_instance_pointers);
615618
child_printer.PrintValueObject();
616619
}
617620
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
CXX_SOURCES := main.cpp
2+
3+
include Makefile.rules
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
"""
2+
Tests that frame variable --depth and --element-count options work correctly
3+
together
4+
"""
5+
import lldb
6+
from lldbsuite.test.lldbtest import *
7+
import lldbsuite.test.lldbutil as lldbutil
8+
9+
10+
class TestFrameVarDepthAndElemCount(TestBase):
11+
def test(self):
12+
"""Test that bool types work in the expression parser"""
13+
self.build()
14+
lldbutil.run_to_source_breakpoint(
15+
self, "// break here", lldb.SBFileSpec("main.cpp")
16+
)
17+
18+
# Check that we print 5 elements but only 2 levels deep.
19+
self.expect('frame var --depth 2 --element-count 5 -- c',
20+
substrs=[
21+
'[0] = {\n b ={...}\n }',
22+
'[1] = {\n b ={...}\n }',
23+
'[2] = {\n b ={...}\n }',
24+
'[3] = {\n b ={...}\n }',
25+
'[4] = {\n b ={...}\n }',
26+
])
27+
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include <cstdio>
2+
3+
struct A {
4+
int i = 42;
5+
};
6+
7+
struct B {
8+
A a;
9+
};
10+
11+
struct C {
12+
B b;
13+
};
14+
15+
int main() {
16+
C *c = new C[5];
17+
puts("break here");
18+
return 0; // break here
19+
}

0 commit comments

Comments
 (0)