Skip to content

Commit 9de52aa

Browse files
committed
[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 (ff12762). 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).
1 parent 8199f18 commit 9de52aa

File tree

7 files changed

+34
-12
lines changed

7 files changed

+34
-12
lines changed

lldb/include/lldb/Target/Target.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ class TargetProperties : public Properties {
186186

187187
uint32_t GetMaxZeroPaddingInFloatFormat() const;
188188

189-
uint32_t GetMaximumNumberOfChildrenToDisplay() const;
189+
std::pair<uint32_t, bool> GetMaximumNumberOfChildrenToDisplay() const;
190190

191191
/// Get the max depth value, augmented with a bool to indicate whether the
192192
/// depth is the default.

lldb/source/API/SBTarget.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1648,7 +1648,7 @@ uint32_t SBTarget::GetMaximumNumberOfChildrenToDisplay() const {
16481648
LLDB_INSTRUMENT_VA(this);
16491649

16501650
if (TargetSP target_sp = GetSP())
1651-
return target_sp->GetMaximumNumberOfChildrenToDisplay();
1651+
return target_sp->GetMaximumNumberOfChildrenToDisplay().first;
16521652
return 0;
16531653
}
16541654

lldb/source/Core/FormatEntity.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1027,7 +1027,7 @@ static bool DumpValue(Stream &s, const SymbolContext *sc,
10271027
if (index_higher < 0)
10281028
index_higher = valobj->GetNumChildrenIgnoringErrors() - 1;
10291029

1030-
uint32_t max_num_children =
1030+
auto [max_num_children, _] =
10311031
target->GetTargetSP()->GetMaximumNumberOfChildrenToDisplay();
10321032

10331033
bool success = true;

lldb/source/DataFormatters/FormatManager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ bool FormatManager::ShouldPrintAsOneLiner(ValueObject &valobj) {
466466
if (valobj.GetSummaryFormat().get() != nullptr)
467467
return valobj.GetSummaryFormat()->IsOneLiner();
468468

469-
const size_t max_num_children =
469+
const auto [max_num_children, _] =
470470
(target_sp ? *target_sp : Target::GetGlobalProperties())
471471
.GetMaximumNumberOfChildrenToDisplay();
472472
auto num_children = valobj.GetNumChildren(max_num_children);

lldb/source/DataFormatters/ValueObjectPrinter.cpp

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,27 @@ void ValueObjectPrinter::PrintChild(
633633
}
634634
}
635635

636+
static uint32_t determineMaxChildren(bool ignore_cap, uint32_t cur_depth,
637+
TargetSP target_sp) {
638+
if (ignore_cap)
639+
return UINT32_MAX;
640+
641+
const auto [max_num_children, max_is_default] =
642+
target_sp->GetMaximumNumberOfChildrenToDisplay();
643+
644+
// Special handling for printing values at the top level (such as variables).
645+
// The original default value for target.max-children-count was 256. The
646+
// default has since been reduced, to avoid printing too much data. However,
647+
// users will naturally have expectations that all children are shown for top
648+
// level values. The following code keeps 256 as the max count for top level
649+
// values (unless customized).
650+
const uint32_t top_level_max_num_childen = 256;
651+
if (cur_depth == 0 && max_is_default)
652+
return top_level_max_num_childen;
653+
654+
return max_num_children;
655+
}
656+
636657
llvm::Expected<uint32_t>
637658
ValueObjectPrinter::GetMaxNumChildrenToPrint(bool &print_dotdotdot) {
638659
ValueObject &synth_valobj = GetValueObjectForChildrenGeneration();
@@ -641,10 +662,8 @@ ValueObjectPrinter::GetMaxNumChildrenToPrint(bool &print_dotdotdot) {
641662
return m_options.m_pointer_as_array.m_element_count;
642663

643664
const uint32_t max_num_children =
644-
m_options.m_ignore_cap ? UINT32_MAX
645-
: GetMostSpecializedValue()
646-
.GetTargetSP()
647-
->GetMaximumNumberOfChildrenToDisplay();
665+
determineMaxChildren(m_options.m_ignore_cap, m_curr_depth,
666+
GetMostSpecializedValue().GetTargetSP());
648667
// Ask for one more child than the maximum to see if we should print "...".
649668
auto num_children_or_err = synth_valobj.GetNumChildren(
650669
llvm::SaturatingAdd(max_num_children, uint32_t(1)));

lldb/source/Plugins/Language/CPlusPlus/LibCxxList.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ lldb::ChildCacheState AbstractListFrontEnd::Update() {
176176

177177
if (m_backend.GetTargetSP())
178178
m_list_capping_size =
179-
m_backend.GetTargetSP()->GetMaximumNumberOfChildrenToDisplay();
179+
m_backend.GetTargetSP()->GetMaximumNumberOfChildrenToDisplay().first;
180180
if (m_list_capping_size == 0)
181181
m_list_capping_size = 255;
182182

lldb/source/Target/Target.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4814,10 +4814,13 @@ uint32_t TargetProperties::GetMaxZeroPaddingInFloatFormat() const {
48144814
idx, g_target_properties[idx].default_uint_value);
48154815
}
48164816

4817-
uint32_t TargetProperties::GetMaximumNumberOfChildrenToDisplay() const {
4817+
std::pair<uint32_t, bool>
4818+
TargetProperties::GetMaximumNumberOfChildrenToDisplay() const {
48184819
const uint32_t idx = ePropertyMaxChildrenCount;
4819-
return GetPropertyAtIndexAs<uint64_t>(
4820-
idx, g_target_properties[idx].default_uint_value);
4820+
auto *option_value =
4821+
m_collection_sp->GetPropertyAtIndexAsOptionValueUInt64(idx);
4822+
bool is_default = !option_value->OptionWasSet();
4823+
return {option_value->GetCurrentValue(), is_default};
48214824
}
48224825

48234826
std::pair<uint32_t, bool>

0 commit comments

Comments
 (0)