Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[lldb] Fix ForwardListFrontEnd::CalculateNumChildren #139805

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
Loading
from

Conversation

kastiglione
Copy link
Contributor

Fixes the calculation of the number of children for std::forward_list to no longer be
capped. The calculation was capped by the value of target.max-children-count.

This resulted in at least the following problems:

  1. The summary formatter would display the incorrect size when the size was greater than
    max-child-count.
  2. The elision marker (...) would not be shown when the number of elements was greater
    than max-child-count.

Fixes the calculation of the number of children for `std::forward_list` to no longer be
capped. The calculation was capped by the value of `target.max-children-count`.

This resulted in at least the following problems:

1. The summary formatter would display the incorrect size when the size was greater than
   `max-child-count`.
2. The elision marker (`...`) would not be shown when the number of elements was greater
   than `max-child-count`.
@llvmbot
Copy link
Member

llvmbot commented May 13, 2025

@llvm/pr-subscribers-lldb

Author: Dave Lee (kastiglione)

Changes

Fixes the calculation of the number of children for std::forward_list to no longer be
capped. The calculation was capped by the value of target.max-children-count.

This resulted in at least the following problems:

  1. The summary formatter would display the incorrect size when the size was greater than
    max-child-count.
  2. The elision marker (...) would not be shown when the number of elements was greater
    than max-child-count.

Full diff: https://github.com/llvm/llvm-project/pull/139805.diff

2 Files Affected:

  • (modified) lldb/source/Plugins/Language/CPlusPlus/LibCxxList.cpp (+1-1)
  • (modified) lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/forward_list/TestDataFormatterGenericForwardList.py (+6-5)
diff --git a/lldb/source/Plugins/Language/CPlusPlus/LibCxxList.cpp b/lldb/source/Plugins/Language/CPlusPlus/LibCxxList.cpp
index 30db5f15c388f..e3c200da6a0f5 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/LibCxxList.cpp
+++ b/lldb/source/Plugins/Language/CPlusPlus/LibCxxList.cpp
@@ -251,7 +251,7 @@ llvm::Expected<uint32_t> ForwardListFrontEnd::CalculateNumChildren() {
 
   ListEntry current(m_head);
   m_count = 0;
-  while (current && m_count < m_list_capping_size) {
+  while (current) {
     ++m_count;
     current = current.next();
   }
diff --git a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/forward_list/TestDataFormatterGenericForwardList.py b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/forward_list/TestDataFormatterGenericForwardList.py
index 185a24cf6dce3..1639d7275b407 100644
--- a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/forward_list/TestDataFormatterGenericForwardList.py
+++ b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/forward_list/TestDataFormatterGenericForwardList.py
@@ -53,13 +53,14 @@ def do_test(self, stdlib_type):
             substrs=["target.max-children-count (unsigned) = 256"],
         )
 
+        self.runCmd("settings set target.max-children-count 256", check=False)
         self.expect(
             "frame variable thousand_elts",
             matching=False,
-            substrs=["[256]", "[333]", "[444]", "[555]", "[666]", "..."],
+            substrs=["[256]", "[333]", "[444]", "[555]", "[666]"],
         )
-        self.runCmd("settings set target.max-children-count 3", check=False)
 
+        self.runCmd("settings set target.max-children-count 3", check=False)
         self.expect(
             "frame variable thousand_elts",
             matching=False,
@@ -73,7 +74,7 @@ def do_test(self, stdlib_type):
         self.expect(
             "frame variable thousand_elts",
             matching=True,
-            substrs=["size=256", "[0]", "[1]", "[2]", "..."],
+            substrs=["size=1000", "[0]", "[1]", "[2]", "..."],
         )
 
     def do_test_ptr_and_ref(self, stdlib_type):
@@ -138,7 +139,7 @@ def do_test_ptr_and_ref(self, stdlib_type):
             "frame variable ref",
             matching=True,
             substrs=[
-                "size=256",
+                "size=1000",
                 "[0] = 999",
                 "[1] = 998",
                 "[2] = 997",
@@ -149,7 +150,7 @@ def do_test_ptr_and_ref(self, stdlib_type):
             "frame variable *ptr",
             matching=True,
             substrs=[
-                "size=256",
+                "size=1000",
                 "[0] = 999",
                 "[1] = 998",
                 "[2] = 997",

@kastiglione kastiglione requested a review from Michael137 May 14, 2025 00:00
@labath
Copy link
Collaborator

labath commented May 14, 2025

I'm very much in favor of removing this dependence on the setting value, as I think it should be handled at a higher level. However, I fear this is going to make printing large std::forward_list very slow. Since computing the size of the list requires iterating through all the elements, which is a lot of pointer chasing, printing of large lists (like, 10k elements or more) could take a very long time (and I think that's the reason this limit was originally introduced).

Fortunately, we already have a mechanism to prevent this -- we mave GetNumChildren overload with the max argument which basically says "if the number of children is larger than this, don't bother giving me the exact value". The general printing logic (in frame var and lldb-dap) should already know how to make use of this (I've made sure of that because I was supporting some formatters like this), but for std::forward_list, its summary provider will force the calculation of the size (because it prints the size in the summary).

For this, I think the fix is to change the formatter to not print the exact size (all the time). For example, it could call GetNumChildren(X) and if the result is smaller than X, it can print the exact size (size=x). Otherwise it can just print the lower bound (size>=X ?).

The value of X might be derived from the setting, but I think it'd also make sense have an independent constant, because not every client has to display the values according to this setting (for example, VSCode always prints the first 100 values).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.