https://github.com/Teemperor created 
https://github.com/llvm/llvm-project/pull/206967

A bug in LLDB could make our tests to produce giant ValueObjects with millions 
of children. The same goes for most commands that print out test data. While 
our test system can handle this amount of output, the resulting log output will 
most likely break the storage capacity of our build bots.

This patch adds truncation to the various expect* methods that avoids spamming 
the output in the (unlikely) case this happens.

See also #206444

>From f6d959de801b81e396ba6ac91fee39a0f8bdd023 Mon Sep 17 00:00:00 2001
From: Raphael Isemann <[email protected]>
Date: Wed, 1 Jul 2026 13:24:34 +0100
Subject: [PATCH] [lldb][test] Use a safe ValueObject dumping method

A bug in LLDB could make our tests to produce giant ValueObjects with
millions of children. The same goes for most commands that print out
test data. While our test system can handle this amount of output, the
resulting log output will most likely break the storage capacity of our
build bots.

This patch adds truncation to the various expect* methods that avoids
spamming the output in the (unlikely) case this happens.

See also #206444
---
 .../Python/lldbsuite/test/lldbtest.py         | 44 +++++++++++++++++--
 1 file changed, 41 insertions(+), 3 deletions(-)

diff --git a/lldb/packages/Python/lldbsuite/test/lldbtest.py 
b/lldb/packages/Python/lldbsuite/test/lldbtest.py
index 416b357754015..856c94ebdd473 100644
--- a/lldb/packages/Python/lldbsuite/test/lldbtest.py
+++ b/lldb/packages/Python/lldbsuite/test/lldbtest.py
@@ -259,6 +259,44 @@ def which(program):
     return None
 
 
+def _truncate_for_log(text: str, max_characters: int = 32 * 1024) -> str:
+    """
+    Returns ``text`` unchanged if it fits in ``max_characters``, otherwise
+    returns a truncated copy with a trailing note describing how many
+    characters were dropped.
+    """
+    if len(text) <= max_characters:
+        return text
+    dropped = len(text) - max_characters
+    return "{}\n... (output truncated: {} of {} characters omitted)".format(
+        text[:max_characters], dropped, len(text)
+    )
+
+
+def dump_value_obj(val: lldb.SBValue, max_children: int = 10000) -> str:
+    """
+    Returns a string representation of an SBValue suitable for use in
+    diagnostic messages. If the value has more than ``max_children``
+    direct or indirect children, a short placeholder is returned instead
+    of ``str(val)`` to avoid bloating the test log size.
+    """
+    to_visit = [val]
+    total = 0
+    while to_visit:
+        current = to_visit.pop()
+        n = current.GetNumChildren()
+        if n == 0:
+            continue
+        total += n
+        if total > max_children:
+            return "<SBValue '{}' with more than {} direct/indirect children 
(dump skipped)>".format(
+                val.GetName(), max_children
+            )
+        for i in range(n):
+            to_visit.append(current.GetChildAtIndex(i))
+    return str(val)
+
+
 class ValueCheck:
     def __init__(
         self,
@@ -303,7 +341,7 @@ def check_value(self, test_base, val, error_msg=""):
         """
 
         this_error_msg = error_msg if error_msg else ""
-        this_error_msg += "\nChecking SBValue: " + str(val)
+        this_error_msg += "\nChecking SBValue: " + dump_value_obj(val)
 
         test_base.assertSuccess(val.GetError())
 
@@ -346,7 +384,7 @@ def check_value_children(self, test_base, val, 
error_msg=""):
         """
 
         this_error_msg = error_msg if error_msg else ""
-        this_error_msg += "\nChecking SBValue: " + str(val)
+        this_error_msg += "\nChecking SBValue: " + dump_value_obj(val)
 
         test_base.assertEqual(len(self.children), val.GetNumChildren(), 
this_error_msg)
 
@@ -2850,7 +2888,7 @@ def found_str(matched):
         ]
         if exe:
             # Newline before output to make large strings more readable
-            log_lines.append("Got output:\n{}".format(output))
+            log_lines.append("Got 
output:\n{}".format(_truncate_for_log(output)))
 
         # Assume that we start matched if we want a match
         # Meaning if you have no conditions, matching or

_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to