[Lldb-commits] [lldb] f94c7ff - [lldb] Never print children if the max depth has been reached
Augusto Noronha via lldb-commits
lldb-commits at lists.llvm.org
Tue Jun 13 11:07:51 PDT 2023
Author: Augusto Noronha
Date: 2023-06-13T11:03:04-07:00
New Revision: f94c7ffe46400559740e7f81d7c60d8c0fe7df82
URL: https://github.com/llvm/llvm-project/commit/f94c7ffe46400559740e7f81d7c60d8c0fe7df82
DIFF: https://github.com/llvm/llvm-project/commit/f94c7ffe46400559740e7f81d7c60d8c0fe7df82.diff
LOG: [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
Added:
Modified:
lldb/include/lldb/DataFormatters/ValueObjectPrinter.h
lldb/source/DataFormatters/ValueObjectPrinter.cpp
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
Removed:
################################################################################
diff --git a/lldb/include/lldb/DataFormatters/ValueObjectPrinter.h b/lldb/include/lldb/DataFormatters/ValueObjectPrinter.h
index a4946a20591a5..2b3936eaa707f 100644
--- a/lldb/include/lldb/DataFormatters/ValueObjectPrinter.h
+++ b/lldb/include/lldb/DataFormatters/ValueObjectPrinter.h
@@ -91,8 +91,7 @@ class ValueObjectPrinter {
bool PrintObjectDescriptionIfNeeded(bool value_printed, bool summary_printed);
bool
- ShouldPrintChildren(bool is_failed_description,
- DumpValueObjectOptions::PointerDepth &curr_ptr_depth);
+ ShouldPrintChildren(DumpValueObjectOptions::PointerDepth &curr_ptr_depth);
bool ShouldExpandEmptyAggregates();
diff --git a/lldb/source/DataFormatters/ValueObjectPrinter.cpp b/lldb/source/DataFormatters/ValueObjectPrinter.cpp
index 16aeff13791c5..8e89b0bd4797e 100644
--- a/lldb/source/DataFormatters/ValueObjectPrinter.cpp
+++ b/lldb/source/DataFormatters/ValueObjectPrinter.cpp
@@ -502,7 +502,6 @@ bool DumpValueObjectOptions::PointerDepth::CanAllowExpansion() const {
}
bool ValueObjectPrinter::ShouldPrintChildren(
- bool is_failed_description,
DumpValueObjectOptions::PointerDepth &curr_ptr_depth) {
const bool is_ref = IsRef();
const bool is_ptr = IsPtr();
@@ -511,6 +510,10 @@ bool ValueObjectPrinter::ShouldPrintChildren(
if (is_uninit)
return false;
+ // If we have reached the maximum depth we shouldn't print any more children.
+ if (HasReachedMaximumDepth())
+ return false;
+
// if the user has specified an element count, always print children as it is
// explicit user demand being honored
if (m_options.m_pointer_as_array)
@@ -523,37 +526,34 @@ bool ValueObjectPrinter::ShouldPrintChildren(
if (TypeSummaryImpl *type_summary = GetSummaryFormatter())
print_children = type_summary->DoesPrintChildren(m_valobj);
- if (is_failed_description || !HasReachedMaximumDepth()) {
- // We will show children for all concrete types. We won't show pointer
- // contents unless a pointer depth has been specified. We won't reference
- // contents unless the reference is the root object (depth of zero).
+ // We will show children for all concrete types. We won't show pointer
+ // contents unless a pointer depth has been specified. We won't reference
+ // contents unless the reference is the root object (depth of zero).
- // Use a new temporary pointer depth in case we override the current
- // pointer depth below...
+ // Use a new temporary pointer depth in case we override the current
+ // pointer depth below...
- if (is_ptr || is_ref) {
- // We have a pointer or reference whose value is an address. Make sure
- // that address is not NULL
- AddressType ptr_address_type;
- if (m_valobj->GetPointerValue(&ptr_address_type) == 0)
- return false;
+ if (is_ptr || is_ref) {
+ // We have a pointer or reference whose value is an address. Make sure
+ // that address is not NULL
+ AddressType ptr_address_type;
+ if (m_valobj->GetPointerValue(&ptr_address_type) == 0)
+ return false;
- const bool is_root_level = m_curr_depth == 0;
+ const bool is_root_level = m_curr_depth == 0;
- if (is_ref && is_root_level && print_children) {
- // If this is the root object (depth is zero) that we are showing and
- // it is a reference, and no pointer depth has been supplied print out
- // what it references. Don't do this at deeper depths otherwise we can
- // end up with infinite recursion...
- return true;
- }
-
- return curr_ptr_depth.CanAllowExpansion();
+ if (is_ref && is_root_level && print_children) {
+ // If this is the root object (depth is zero) that we are showing and
+ // it is a reference, and no pointer depth has been supplied print out
+ // what it references. Don't do this at deeper depths otherwise we can
+ // end up with infinite recursion...
+ return true;
}
- return print_children || m_summary.empty();
+ return curr_ptr_depth.CanAllowExpansion();
}
- return false;
+
+ return print_children || m_summary.empty();
}
bool ValueObjectPrinter::ShouldExpandEmptyAggregates() {
@@ -794,14 +794,10 @@ bool ValueObjectPrinter::PrintChildrenOneLiner(bool hide_names) {
void ValueObjectPrinter::PrintChildrenIfNeeded(bool value_printed,
bool summary_printed) {
- // This flag controls whether we tried to display a description for this
- // object and failed if that happens, we want to display the children if any.
- bool is_failed_description =
- !PrintObjectDescriptionIfNeeded(value_printed, summary_printed);
+ PrintObjectDescriptionIfNeeded(value_printed, summary_printed);
DumpValueObjectOptions::PointerDepth curr_ptr_depth = m_ptr_depth;
- const bool print_children =
- ShouldPrintChildren(is_failed_description, curr_ptr_depth);
+ const bool print_children = ShouldPrintChildren(curr_ptr_depth);
const bool print_oneline =
(curr_ptr_depth.CanAllowExpansion() || m_options.m_show_types ||
!m_options.m_allow_oneliner_mode || m_options.m_flat_output ||
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
index e8fa95ef6469a..49a56c4d6ab89 100644
--- 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
@@ -12,7 +12,7 @@ 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")
+ self, "break here", lldb.SBFileSpec("main.cpp")
)
# Check that we print 5 elements but only 2 levels deep.
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
index 7f787712e0f67..ec7cfa20d3c64 100644
--- 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
@@ -15,5 +15,5 @@ struct C {
int main() {
C *c = new C[5];
puts("break here");
- return 0; // break here
+ return 0;
}
More information about the lldb-commits
mailing list