https://github.com/kastiglione updated https://github.com/llvm/llvm-project/pull/140938
>From f07c408bcbc221e69f56459d0cca27a27ed8551c Mon Sep 17 00:00:00 2001 From: Dave Lee <davelee....@gmail.com> Date: Wed, 21 May 2025 09:44:16 -0700 Subject: [PATCH 1/2] [lldb] Show more children of top level values This changes printing values at the top level (such as variables). The original default value for `target.max-children-count` was 256. The default has since been reduced, to avoid printing too much data (ff127624be). However, users will naturally have expectations that all (or significantly many) children are shown for top level values. The following code keeps 256 as the max count for top level values (unless customized). The value of `target.max-children-count` will continue to apply to nested values (depth >= 1). --- lldb/include/lldb/Target/Target.h | 2 +- lldb/source/API/SBTarget.cpp | 2 +- lldb/source/Core/FormatEntity.cpp | 2 +- lldb/source/DataFormatters/FormatManager.cpp | 2 +- .../DataFormatters/ValueObjectPrinter.cpp | 27 ++++++++++++++++--- .../Plugins/Language/CPlusPlus/LibCxxList.cpp | 2 +- lldb/source/Target/Target.cpp | 9 ++++--- 7 files changed, 34 insertions(+), 12 deletions(-) diff --git a/lldb/include/lldb/Target/Target.h b/lldb/include/lldb/Target/Target.h index 0d4e11b65339e..bcde310378acf 100644 --- a/lldb/include/lldb/Target/Target.h +++ b/lldb/include/lldb/Target/Target.h @@ -186,7 +186,7 @@ class TargetProperties : public Properties { uint32_t GetMaxZeroPaddingInFloatFormat() const; - uint32_t GetMaximumNumberOfChildrenToDisplay() const; + std::pair<uint32_t, bool> GetMaximumNumberOfChildrenToDisplay() const; /// Get the max depth value, augmented with a bool to indicate whether the /// depth is the default. diff --git a/lldb/source/API/SBTarget.cpp b/lldb/source/API/SBTarget.cpp index cd8a770a0ec04..c3e3b6105d56f 100644 --- a/lldb/source/API/SBTarget.cpp +++ b/lldb/source/API/SBTarget.cpp @@ -1713,7 +1713,7 @@ uint32_t SBTarget::GetMaximumNumberOfChildrenToDisplay() const { TargetSP target_sp(GetSP()); if(target_sp){ - return target_sp->GetMaximumNumberOfChildrenToDisplay(); + return target_sp->GetMaximumNumberOfChildrenToDisplay().first; } return 0; } diff --git a/lldb/source/Core/FormatEntity.cpp b/lldb/source/Core/FormatEntity.cpp index 4f2d39873c7fb..98e5bfe37cd62 100644 --- a/lldb/source/Core/FormatEntity.cpp +++ b/lldb/source/Core/FormatEntity.cpp @@ -1025,7 +1025,7 @@ static bool DumpValue(Stream &s, const SymbolContext *sc, if (index_higher < 0) index_higher = valobj->GetNumChildrenIgnoringErrors() - 1; - uint32_t max_num_children = + auto [max_num_children, _] = target->GetTargetSP()->GetMaximumNumberOfChildrenToDisplay(); bool success = true; diff --git a/lldb/source/DataFormatters/FormatManager.cpp b/lldb/source/DataFormatters/FormatManager.cpp index 3b891cecb1c8b..feb69840bc64b 100644 --- a/lldb/source/DataFormatters/FormatManager.cpp +++ b/lldb/source/DataFormatters/FormatManager.cpp @@ -458,7 +458,7 @@ bool FormatManager::ShouldPrintAsOneLiner(ValueObject &valobj) { if (valobj.GetSummaryFormat().get() != nullptr) return valobj.GetSummaryFormat()->IsOneLiner(); - const size_t max_num_children = + const auto [max_num_children, _] = (target_sp ? *target_sp : Target::GetGlobalProperties()) .GetMaximumNumberOfChildrenToDisplay(); auto num_children = valobj.GetNumChildren(max_num_children); diff --git a/lldb/source/DataFormatters/ValueObjectPrinter.cpp b/lldb/source/DataFormatters/ValueObjectPrinter.cpp index 5e04a621bbda8..4890aa8f7ee66 100644 --- a/lldb/source/DataFormatters/ValueObjectPrinter.cpp +++ b/lldb/source/DataFormatters/ValueObjectPrinter.cpp @@ -633,6 +633,27 @@ void ValueObjectPrinter::PrintChild( } } +static uint32_t determineMaxChildren(bool ignore_cap, uint32_t cur_depth, + TargetSP target_sp) { + if (ignore_cap) + return UINT32_MAX; + + const auto [max_num_children, max_is_default] = + target_sp->GetMaximumNumberOfChildrenToDisplay(); + + // Special handling for printing values at the top level (such as variables). + // The original default value for target.max-children-count was 256. The + // default has since been reduced, to avoid printing too much data. However, + // users will naturally have expectations that all children are shown for top + // level values. The following code keeps 256 as the max count for top level + // values (unless customized). + const uint32_t top_level_max_num_childen = 256; + if (cur_depth == 0 && max_is_default) + return top_level_max_num_childen; + + return max_num_children; +} + llvm::Expected<uint32_t> ValueObjectPrinter::GetMaxNumChildrenToPrint(bool &print_dotdotdot) { ValueObject &synth_valobj = GetValueObjectForChildrenGeneration(); @@ -641,10 +662,8 @@ ValueObjectPrinter::GetMaxNumChildrenToPrint(bool &print_dotdotdot) { return m_options.m_pointer_as_array.m_element_count; const uint32_t max_num_children = - m_options.m_ignore_cap ? UINT32_MAX - : GetMostSpecializedValue() - .GetTargetSP() - ->GetMaximumNumberOfChildrenToDisplay(); + determineMaxChildren(m_options.m_ignore_cap, m_curr_depth, + GetMostSpecializedValue().GetTargetSP()); // Ask for one more child than the maximum to see if we should print "...". auto num_children_or_err = synth_valobj.GetNumChildren( llvm::SaturatingAdd(max_num_children, uint32_t(1))); diff --git a/lldb/source/Plugins/Language/CPlusPlus/LibCxxList.cpp b/lldb/source/Plugins/Language/CPlusPlus/LibCxxList.cpp index 30db5f15c388f..87b66697feae9 100644 --- a/lldb/source/Plugins/Language/CPlusPlus/LibCxxList.cpp +++ b/lldb/source/Plugins/Language/CPlusPlus/LibCxxList.cpp @@ -176,7 +176,7 @@ lldb::ChildCacheState AbstractListFrontEnd::Update() { if (m_backend.GetTargetSP()) m_list_capping_size = - m_backend.GetTargetSP()->GetMaximumNumberOfChildrenToDisplay(); + m_backend.GetTargetSP()->GetMaximumNumberOfChildrenToDisplay().first; if (m_list_capping_size == 0) m_list_capping_size = 255; diff --git a/lldb/source/Target/Target.cpp b/lldb/source/Target/Target.cpp index 9660fc97970b0..6e2ca57072fa4 100644 --- a/lldb/source/Target/Target.cpp +++ b/lldb/source/Target/Target.cpp @@ -4814,10 +4814,13 @@ uint32_t TargetProperties::GetMaxZeroPaddingInFloatFormat() const { idx, g_target_properties[idx].default_uint_value); } -uint32_t TargetProperties::GetMaximumNumberOfChildrenToDisplay() const { +std::pair<uint32_t, bool> +TargetProperties::GetMaximumNumberOfChildrenToDisplay() const { const uint32_t idx = ePropertyMaxChildrenCount; - return GetPropertyAtIndexAs<uint64_t>( - idx, g_target_properties[idx].default_uint_value); + auto *option_value = + m_collection_sp->GetPropertyAtIndexAsOptionValueUInt64(idx); + bool is_default = !option_value->OptionWasSet(); + return {option_value->GetCurrentValue(), is_default}; } std::pair<uint32_t, bool> >From 2fd8336294eb773bc7252f4d0264c02add28e406 Mon Sep 17 00:00:00 2001 From: Dave Lee <davelee....@gmail.com> Date: Wed, 28 May 2025 10:52:32 -0700 Subject: [PATCH 2/2] Update max-children-count description --- lldb/source/Target/TargetProperties.td | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lldb/source/Target/TargetProperties.td b/lldb/source/Target/TargetProperties.td index 4aa9e046d6077..2b5afd380315c 100644 --- a/lldb/source/Target/TargetProperties.td +++ b/lldb/source/Target/TargetProperties.td @@ -97,7 +97,7 @@ let Definition = "target" in { Desc<"The maximum number of zeroes to insert when displaying a very small float before falling back to scientific notation.">; def MaxChildrenCount: Property<"max-children-count", "UInt64">, DefaultUnsignedValue<24>, - Desc<"Maximum number of children to expand in any level of depth.">; + Desc<"Maximum number of children to show for nested values. Top level values show up to 256 children.">; def MaxChildrenDepth: Property<"max-children-depth", "UInt64">, DefaultUnsignedValue<0xFFFFFFFF>, Desc<"Maximum depth to expand children.">; _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits