Skip to content

Commit f94c7ff

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
1 parent 894d047 commit f94c7ff

File tree

4 files changed

+30
-35
lines changed

4 files changed

+30
-35
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: 27 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,6 @@ bool DumpValueObjectOptions::PointerDepth::CanAllowExpansion() const {
502502
}
503503

504504
bool ValueObjectPrinter::ShouldPrintChildren(
505-
bool is_failed_description,
506505
DumpValueObjectOptions::PointerDepth &curr_ptr_depth) {
507506
const bool is_ref = IsRef();
508507
const bool is_ptr = IsPtr();
@@ -511,6 +510,10 @@ bool ValueObjectPrinter::ShouldPrintChildren(
511510
if (is_uninit)
512511
return false;
513512

513+
// If we have reached the maximum depth we shouldn't print any more children.
514+
if (HasReachedMaximumDepth())
515+
return false;
516+
514517
// if the user has specified an element count, always print children as it is
515518
// explicit user demand being honored
516519
if (m_options.m_pointer_as_array)
@@ -523,37 +526,34 @@ bool ValueObjectPrinter::ShouldPrintChildren(
523526
if (TypeSummaryImpl *type_summary = GetSummaryFormatter())
524527
print_children = type_summary->DoesPrintChildren(m_valobj);
525528

526-
if (is_failed_description || !HasReachedMaximumDepth()) {
527-
// We will show children for all concrete types. We won't show pointer
528-
// contents unless a pointer depth has been specified. We won't reference
529-
// contents unless the reference is the root object (depth of zero).
529+
// We will show children for all concrete types. We won't show pointer
530+
// contents unless a pointer depth has been specified. We won't reference
531+
// contents unless the reference is the root object (depth of zero).
530532

531-
// Use a new temporary pointer depth in case we override the current
532-
// pointer depth below...
533+
// Use a new temporary pointer depth in case we override the current
534+
// pointer depth below...
533535

534-
if (is_ptr || is_ref) {
535-
// We have a pointer or reference whose value is an address. Make sure
536-
// that address is not NULL
537-
AddressType ptr_address_type;
538-
if (m_valobj->GetPointerValue(&ptr_address_type) == 0)
539-
return false;
536+
if (is_ptr || is_ref) {
537+
// We have a pointer or reference whose value is an address. Make sure
538+
// that address is not NULL
539+
AddressType ptr_address_type;
540+
if (m_valobj->GetPointerValue(&ptr_address_type) == 0)
541+
return false;
540542

541-
const bool is_root_level = m_curr_depth == 0;
543+
const bool is_root_level = m_curr_depth == 0;
542544

543-
if (is_ref && is_root_level && print_children) {
544-
// If this is the root object (depth is zero) that we are showing and
545-
// it is a reference, and no pointer depth has been supplied print out
546-
// what it references. Don't do this at deeper depths otherwise we can
547-
// end up with infinite recursion...
548-
return true;
549-
}
550-
551-
return curr_ptr_depth.CanAllowExpansion();
545+
if (is_ref && is_root_level && print_children) {
546+
// If this is the root object (depth is zero) that we are showing and
547+
// it is a reference, and no pointer depth has been supplied print out
548+
// what it references. Don't do this at deeper depths otherwise we can
549+
// end up with infinite recursion...
550+
return true;
552551
}
553552

554-
return print_children || m_summary.empty();
553+
return curr_ptr_depth.CanAllowExpansion();
555554
}
556-
return false;
555+
556+
return print_children || m_summary.empty();
557557
}
558558

559559
bool ValueObjectPrinter::ShouldExpandEmptyAggregates() {
@@ -794,14 +794,10 @@ bool ValueObjectPrinter::PrintChildrenOneLiner(bool hide_names) {
794794

795795
void ValueObjectPrinter::PrintChildrenIfNeeded(bool value_printed,
796796
bool summary_printed) {
797-
// This flag controls whether we tried to display a description for this
798-
// object and failed if that happens, we want to display the children if any.
799-
bool is_failed_description =
800-
!PrintObjectDescriptionIfNeeded(value_printed, summary_printed);
797+
PrintObjectDescriptionIfNeeded(value_printed, summary_printed);
801798

802799
DumpValueObjectOptions::PointerDepth curr_ptr_depth = m_ptr_depth;
803-
const bool print_children =
804-
ShouldPrintChildren(is_failed_description, curr_ptr_depth);
800+
const bool print_children = ShouldPrintChildren(curr_ptr_depth);
805801
const bool print_oneline =
806802
(curr_ptr_depth.CanAllowExpansion() || m_options.m_show_types ||
807803
!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)