https://github.com/Teemperor updated https://github.com/llvm/llvm-project/pull/206967
>From 7aeb2e7e60caacd3eac651fedfc693844423d9bf 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] Truncate unexpectedly long test outputs 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 | 46 +++++++++++++++++-- 1 file changed, 43 insertions(+), 3 deletions(-) diff --git a/lldb/packages/Python/lldbsuite/test/lldbtest.py b/lldb/packages/Python/lldbsuite/test/lldbtest.py index 416b357754015..6792d91eda49e 100644 --- a/lldb/packages/Python/lldbsuite/test/lldbtest.py +++ b/lldb/packages/Python/lldbsuite/test/lldbtest.py @@ -259,6 +259,46 @@ 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 ( + f"{text[:max_characters]}\n" + f"... (output truncated: {dropped} of {len(text)} characters omitted)" + ) + + +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 ( + f"<SBValue '{val.GetName()}' with more than {max_children} " + f"direct/indirect children (dump skipped)>" + ) + for i in range(n): + to_visit.append(current.GetChildAtIndex(i)) + return str(val) + + class ValueCheck: def __init__( self, @@ -303,7 +343,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 +386,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 +2890,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(f"Got output:\n{_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
