Skip to content

Commit 0da5db4

Browse files
committed
[lldb] Never print children if the max depth has been reached
When formatting a variable, the max depth would potentially be ignored if the current value object failed to print itself. Change that to always respect the max depth, even if failure occurs. rdar://109855463 Differential Revision: https://reviews.llvm.org/D152409 (cherry picked from commit f94c7ff)
1 parent 760a779 commit 0da5db4

File tree

4 files changed

+33
-36
lines changed

4 files changed

+33
-36
lines changed

lldb/include/lldb/DataFormatters/ValueObjectPrinter.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,7 @@ class ValueObjectPrinter {
9191
bool PrintObjectDescriptionIfNeeded(bool value_printed, bool summary_printed);
9292

9393
bool
94-
ShouldPrintChildren(bool is_failed_description,
95-
DumpValueObjectOptions::PointerDepth &curr_ptr_depth);
94+
ShouldPrintChildren(DumpValueObjectOptions::PointerDepth &curr_ptr_depth);
9695

9796
bool ShouldExpandEmptyAggregates();
9897

lldb/source/DataFormatters/ValueObjectPrinter.cpp

Lines changed: 30 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,6 @@ bool DumpValueObjectOptions::PointerDepth::CanAllowExpansion() const {
523523
}
524524

525525
bool ValueObjectPrinter::ShouldPrintChildren(
526-
bool is_failed_description,
527526
DumpValueObjectOptions::PointerDepth &curr_ptr_depth) {
528527
const bool is_ref = IsRef();
529528
const bool is_ptr = IsPtr();
@@ -532,6 +531,10 @@ bool ValueObjectPrinter::ShouldPrintChildren(
532531
if (is_uninit)
533532
return false;
534533

534+
// If we have reached the maximum depth we shouldn't print any more children.
535+
if (HasReachedMaximumDepth())
536+
return false;
537+
535538
// if the user has specified an element count, always print children as it is
536539
// explicit user demand being honored
537540
if (m_options.m_pointer_as_array)
@@ -542,38 +545,37 @@ bool ValueObjectPrinter::ShouldPrintChildren(
542545
if (m_options.m_use_objc)
543546
return false;
544547

545-
if (is_failed_description || !HasReachedMaximumDepth()) {
546-
// We will show children for all concrete types. We won't show pointer
547-
// contents unless a pointer depth has been specified. We won't reference
548-
// contents unless the reference is the root object (depth of zero).
548+
bool print_children = true;
549+
if (TypeSummaryImpl *type_summary = GetSummaryFormatter())
550+
print_children = type_summary->DoesPrintChildren(m_valobj);
549551

550-
// Use a new temporary pointer depth in case we override the current
551-
// pointer depth below...
552+
// We will show children for all concrete types. We won't show pointer
553+
// contents unless a pointer depth has been specified. We won't reference
554+
// contents unless the reference is the root object (depth of zero).
552555

553-
if (is_ptr || is_ref) {
554-
// We have a pointer or reference whose value is an address. Make sure
555-
// that address is not NULL
556-
AddressType ptr_address_type;
557-
if (m_valobj->GetPointerValue(&ptr_address_type) == 0)
558-
return false;
556+
// Use a new temporary pointer depth in case we override the current
557+
// pointer depth below...
559558

560-
const bool is_root_level = m_curr_depth == 0;
559+
if (is_ptr || is_ref) {
560+
// We have a pointer or reference whose value is an address. Make sure
561+
// that address is not NULL
562+
AddressType ptr_address_type;
563+
if (m_valobj->GetPointerValue(&ptr_address_type) == 0)
564+
return false;
561565

562-
if (is_ref && is_root_level) {
563-
// If this is the root object (depth is zero) that we are showing and
564-
// it is a reference, and no pointer depth has been supplied print out
565-
// what it references. Don't do this at deeper depths otherwise we can
566-
// end up with infinite recursion...
567-
return true;
568-
}
566+
const bool is_root_level = m_curr_depth == 0;
569567

570-
return curr_ptr_depth.CanAllowExpansion(false, entry, m_valobj,
571-
m_summary);
568+
if (is_ref && is_root_level && print_children) {
569+
// If this is the root object (depth is zero) that we are showing and
570+
// it is a reference, and no pointer depth has been supplied print out
571+
// what it references. Don't do this at deeper depths otherwise we can
572+
// end up with infinite recursion...
573+
return true;
572574
}
573-
574-
return (!entry || entry->DoesPrintChildren(m_valobj) || m_summary.empty());
575+
return curr_ptr_depth.CanAllowExpansion(false, entry, m_valobj, m_summary);
575576
}
576-
return false;
577+
578+
return print_children || m_summary.empty();
577579
}
578580

579581
bool ValueObjectPrinter::ShouldExpandEmptyAggregates() {
@@ -806,14 +808,10 @@ bool ValueObjectPrinter::PrintChildrenOneLiner(bool hide_names) {
806808

807809
void ValueObjectPrinter::PrintChildrenIfNeeded(bool value_printed,
808810
bool summary_printed) {
809-
// This flag controls whether we tried to display a description for this
810-
// object and failed if that happens, we want to display the children if any.
811-
bool is_failed_description =
812-
!PrintObjectDescriptionIfNeeded(value_printed, summary_printed);
811+
PrintObjectDescriptionIfNeeded(value_printed, summary_printed);
813812

814813
DumpValueObjectOptions::PointerDepth curr_ptr_depth = m_ptr_depth;
815-
const bool print_children =
816-
ShouldPrintChildren(is_failed_description, curr_ptr_depth);
814+
const bool print_children = ShouldPrintChildren(curr_ptr_depth);
817815
const bool print_oneline =
818816
(curr_ptr_depth.CanAllowExpansion() || m_options.m_show_types ||
819817
!m_options.m_allow_oneliner_mode || m_options.m_flat_output ||

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def test(self):
1212
"""Test that bool types work in the expression parser"""
1313
self.build()
1414
lldbutil.run_to_source_breakpoint(
15-
self, "// break here", lldb.SBFileSpec("main.cpp")
15+
self, "break here", lldb.SBFileSpec("main.cpp")
1616
)
1717

1818
# Check that we print 5 elements but only 2 levels deep.

lldb/test/API/lang/cpp/frame-var-depth-and-elem-count/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ struct C {
1515
int main() {
1616
C *c = new C[5];
1717
puts("break here");
18-
return 0; // break here
18+
return 0;
1919
}

0 commit comments

Comments
 (0)