Skip to content

Conversation

@Michael137
Copy link
Member

When dumping variables, LLDB will print a one-time warning about truncating children (when the children count exceeds the default target.max-children-count). But we only do this for frame variable. So if we use dwim-print or expression, the output gets truncated but we don't print a warning. But because we store the fact that we truncated some output on the CommandInterpreter, we fire the warning next time we use frame variable. E.g.,:

(lldb) p arr
(int[1000]) {
  [0] = -5
  [1] = 0
  [2] = 0
  <-- snipped -->
  [253] = 0
  [254] = 0
  [255] = 0
  ...
}
(lldb) v someLocal
(int) someLocal = 10
*** Some of the displayed variables have more members than the debugger
will show by default. To show all of them, you can either use the
--show-all-children option to frame variable or raise the limit by
changing the target.max-children-count setting.

This patch prints the warning for dwim-print and expression.

I only added a test for the target.max-children-count for now because it seems the target.max-children-depth warning is broken (I can't get it to fire).

When dumping variables, LLDB will print a one-time warning about
truncating children (when the children count exceeds the default
`target.max-children-count`). But we only do this for `frame variable`.
So if we use `dwim-print` or `expression`, the output gets truncated but
we don't print a warning. But because we store the fact that we
truncated some output on the `CommandInterpreter`, we fire the warning
next time we use `frame variable`. E.g.,:
```
(lldb) p arr
(int[1000]) {
  [0] = -5
  [1] = 0
  [2] = 0
  <-- snipped -->
  [253] = 0
  [254] = 0
  [255] = 0
  ...
}
(lldb) v someLocal
(int) someLocal = 10
*** Some of the displayed variables have more members than the debugger
will show by default. To show all of them, you can either use the
--show-all-children option to frame variable or raise the limit by
changing the target.max-children-count setting.
```

This patch prints the warning for `dwim-print` and `expression`.

I only added a test for the `target.max-children-count` for now because
it seems the `target.max-children-depth` warning is broken (I can't get
it to fire).
@Michael137 Michael137 requested review from kastiglione and labath July 16, 2025 12:40
@Michael137 Michael137 requested a review from JDevlieghere as a code owner July 16, 2025 12:40
@llvmbot llvmbot added the lldb label Jul 16, 2025
@Michael137 Michael137 changed the title [lldb] Print child-depth warning for DWIM-print and expr [lldb] Print children-count warning for DWIM-print and expr Jul 16, 2025
@Michael137 Michael137 changed the title [lldb] Print children-count warning for DWIM-print and expr [lldb] Print children-count warning for dwim-print and expr Jul 16, 2025
@llvmbot
Copy link
Member

llvmbot commented Jul 16, 2025

@llvm/pr-subscribers-lldb

Author: Michael Buch (Michael137)

Changes

When dumping variables, LLDB will print a one-time warning about truncating children (when the children count exceeds the default target.max-children-count). But we only do this for frame variable. So if we use dwim-print or expression, the output gets truncated but we don't print a warning. But because we store the fact that we truncated some output on the CommandInterpreter, we fire the warning next time we use frame variable. E.g.,:

(lldb) p arr
(int[1000]) {
  [0] = -5
  [1] = 0
  [2] = 0
  &lt;-- snipped --&gt;
  [253] = 0
  [254] = 0
  [255] = 0
  ...
}
(lldb) v someLocal
(int) someLocal = 10
*** Some of the displayed variables have more members than the debugger
will show by default. To show all of them, you can either use the
--show-all-children option to frame variable or raise the limit by
changing the target.max-children-count setting.

This patch prints the warning for dwim-print and expression.

I only added a test for the target.max-children-count for now because it seems the target.max-children-depth warning is broken (I can't get it to fire).


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

3 Files Affected:

  • (modified) lldb/source/Commands/CommandObjectDWIMPrint.cpp (+2)
  • (modified) lldb/source/Commands/CommandObjectExpression.cpp (+3)
  • (added) lldb/test/Shell/Settings/TestChildCountTruncation.test (+67)
diff --git a/lldb/source/Commands/CommandObjectDWIMPrint.cpp b/lldb/source/Commands/CommandObjectDWIMPrint.cpp
index a110eececf4d6..a2c004d0ee97f 100644
--- a/lldb/source/Commands/CommandObjectDWIMPrint.cpp
+++ b/lldb/source/Commands/CommandObjectDWIMPrint.cpp
@@ -150,6 +150,8 @@ void CommandObjectDWIMPrint::DoExecute(StringRef command,
         return;
       }
     }
+    m_interpreter.PrintWarningsIfNecessary(result.GetOutputStream(),
+                                           m_cmd_name);
     result.SetStatus(eReturnStatusSuccessFinishResult);
   };
 
diff --git a/lldb/source/Commands/CommandObjectExpression.cpp b/lldb/source/Commands/CommandObjectExpression.cpp
index a95dea63720ac..c5b91678103d5 100644
--- a/lldb/source/Commands/CommandObjectExpression.cpp
+++ b/lldb/source/Commands/CommandObjectExpression.cpp
@@ -470,6 +470,9 @@ bool CommandObjectExpression::EvaluateExpression(llvm::StringRef expr,
           return false;
         }
 
+        m_interpreter.PrintWarningsIfNecessary(result.GetOutputStream(),
+                                               m_cmd_name);
+
         if (suppress_result)
           if (auto result_var_sp =
                   target.GetPersistentVariable(result_valobj_sp->GetName())) {
diff --git a/lldb/test/Shell/Settings/TestChildCountTruncation.test b/lldb/test/Shell/Settings/TestChildCountTruncation.test
new file mode 100644
index 0000000000000..3b75498297b05
--- /dev/null
+++ b/lldb/test/Shell/Settings/TestChildCountTruncation.test
@@ -0,0 +1,67 @@
+# Test that we warn the user about truncated output
+# when target.max-children-count wasn't explicitly set.
+
+# RUN: split-file %s %t
+# RUN: %clang_host -g -gdwarf %t/main.cpp -o %t.out
+# RUN: %lldb -x -b -s %t/dwim-commands.input %t.out -o exit 2>&1 \
+# RUN:       | FileCheck %s --check-prefix=DWIM
+#
+# RUN: %lldb -x -b -s %t/expr-commands.input %t.out -o exit 2>&1 \
+# RUN:       | FileCheck %s --check-prefix=EXPR
+#
+# RUN: %lldb -x -b -s %t/frame-var-commands.input %t.out -o exit 2>&1 \
+# RUN:       | FileCheck %s --check-prefix=VAR
+#
+# RUN: %lldb -x -b -s %t/with-setting-commands.input %t.out -o exit 2>&1 \
+# RUN:       | FileCheck %s --check-prefix=SETTING
+
+#--- main.cpp
+
+int main() {
+  int arr[512] = { 3 };
+  __builtin_debugtrap();
+}
+
+#--- dwim-commands.input
+
+run
+dwim-print arr
+frame variable arr
+
+DWIM:      (lldb) dwim-print arr
+DWIM:      *** Some of the displayed variables have more members
+DWIM-SAME: use the --show-all-children option to dwim-print
+DWIM:      (lldb) frame variable arr
+DWIM-NOT:  *** Some of the displayed variables have more members
+
+#--- expr-commands.input
+
+run
+expression arr
+frame variable arr
+
+EXPR:      (lldb) expression arr
+EXPR:      *** Some of the displayed variables have more members
+EXPR-SAME: use the --show-all-children option to expression
+EXPR:      (lldb) frame variable arr
+EXPR-NOT:  *** Some of the displayed variables have more members
+
+#--- frame-var-commands.input
+
+run
+frame variable arr
+
+VAR:      (lldb) frame variable arr
+VAR:      *** Some of the displayed variables have more members
+VAR-SAME: use the --show-all-children option to frame variable
+VAR:      (lldb) frame variable arr
+VAR-NOT:  *** Some of the displayed variables have more members
+
+#--- with-setting-commands.input
+
+run
+settings set target.max-children-count 1
+frame variable arr
+
+SETTING:      (lldb) frame variable arr
+SETTING-NOT:  *** Some of the displayed variables have more members

@Michael137 Michael137 merged commit 8c28f49 into llvm:main Jul 16, 2025
11 checks passed
@Michael137 Michael137 deleted the lldb/child-depth-warning branch July 16, 2025 20:47
DavidSpickett added a commit that referenced this pull request Jul 17, 2025
This fails because it tells clang to use DWARF which link.exe
then discards.

The test may not need DWARF, but I'm going to confirm that in
a follow up PR review.

Test added by #149088.
llvm-sync bot pushed a commit to arm/arm-toolchain that referenced this pull request Jul 17, 2025
This fails because it tells clang to use DWARF which link.exe
then discards.

The test may not need DWARF, but I'm going to confirm that in
a follow up PR review.

Test added by llvm/llvm-project#149088.
DavidSpickett added a commit that referenced this pull request Jul 17, 2025
By not forcing the DWARF debug info format. When left as the default,
the tests pass.

Test added by #149088.
llvm-sync bot pushed a commit to arm/arm-toolchain that referenced this pull request Jul 17, 2025
…322)

By not forcing the DWARF debug info format. When left as the default,
the tests pass.

Test added by llvm/llvm-project#149088.
Michael137 added a commit to swiftlang/llvm-project that referenced this pull request Jul 25, 2025
)

When dumping variables, LLDB will print a one-time warning about
truncating children (when the children count exceeds the default
`target.max-children-count`). But we only do this for `frame variable`.
So if we use `dwim-print` or `expression`, the output gets truncated but
we don't print a warning. But because we store the fact that we
truncated some output on the `CommandInterpreter`, we fire the warning
next time we use `frame variable`. E.g.,:
```
(lldb) p arr
(int[1000]) {
  [0] = -5
  [1] = 0
  [2] = 0
  <-- snipped -->
  [253] = 0
  [254] = 0
  [255] = 0
  ...
}
(lldb) v someLocal
(int) someLocal = 10
*** Some of the displayed variables have more members than the debugger
will show by default. To show all of them, you can either use the
--show-all-children option to frame variable or raise the limit by
changing the target.max-children-count setting.
```

This patch prints the warning for `dwim-print` and `expression`.

I only added a test for the `target.max-children-count` for now because
it seems the `target.max-children-depth` warning is broken (I can't get
it to fire).

(cherry picked from commit 8c28f49)
Michael137 pushed a commit to swiftlang/llvm-project that referenced this pull request Jul 25, 2025
By not forcing the DWARF debug info format. When left as the default,
the tests pass.

Test added by llvm#149088.

(cherry picked from commit 4bf82ae)
augusto2112 pushed a commit to augusto2112/llvm-project that referenced this pull request Aug 15, 2025
)

When dumping variables, LLDB will print a one-time warning about
truncating children (when the children count exceeds the default
`target.max-children-count`). But we only do this for `frame variable`.
So if we use `dwim-print` or `expression`, the output gets truncated but
we don't print a warning. But because we store the fact that we
truncated some output on the `CommandInterpreter`, we fire the warning
next time we use `frame variable`. E.g.,:
```
(lldb) p arr
(int[1000]) {
  [0] = -5
  [1] = 0
  [2] = 0
  <-- snipped -->
  [253] = 0
  [254] = 0
  [255] = 0
  ...
}
(lldb) v someLocal
(int) someLocal = 10
*** Some of the displayed variables have more members than the debugger
will show by default. To show all of them, you can either use the
--show-all-children option to frame variable or raise the limit by
changing the target.max-children-count setting.
```

This patch prints the warning for `dwim-print` and `expression`.

I only added a test for the `target.max-children-count` for now because
it seems the `target.max-children-depth` warning is broken (I can't get
it to fire).

(cherry picked from commit 8c28f49)
augusto2112 pushed a commit to augusto2112/llvm-project that referenced this pull request Aug 15, 2025
By not forcing the DWARF debug info format. When left as the default,
the tests pass.

Test added by llvm#149088.

(cherry picked from commit 4bf82ae)
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