================
@@ -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:
----------------
Teemperor wrote:
[Yes](https://docs.python.org/3/library/stdtypes.html#truth-value-testing), and
it's I guess considered 'pythonic' (but backtraces and unexplained bugs are
also 'pythonic' I guess). I'm happy with making it more explicit.
```python
>>> oh_no = [0]
>>> "true" if oh_no else "false"
'true'
>>> oh_no = []
>>> "true" if oh_no else "false"
'false'
```
https://github.com/llvm/llvm-project/pull/206967
_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits