[llvm] 9ef60ff - [llvm][utils] Improve the StringRef summary provider (#162298)

via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 24 04:07:16 PDT 2025


Author: Ebuka Ezike
Date: 2025-10-24T12:07:12+01:00
New Revision: 9ef60ff7ff187f5d80e745d3047d0f0b1e684cac

URL: https://github.com/llvm/llvm-project/commit/9ef60ff7ff187f5d80e745d3047d0f0b1e684cac
DIFF: https://github.com/llvm/llvm-project/commit/9ef60ff7ff187f5d80e745d3047d0f0b1e684cac.diff

LOG: [llvm][utils] Improve the StringRef summary provider (#162298)

- check the length of data before casting as `char[N]` because the will
cause lldb to allocate `N` bytes of memory.

---------

Co-authored-by: Dave Lee <davelee.com at gmail.com>

Added: 
    

Modified: 
    llvm/utils/lldbDataFormatters.py

Removed: 
    


################################################################################
diff  --git a/llvm/utils/lldbDataFormatters.py b/llvm/utils/lldbDataFormatters.py
index 5e553caa4446d..a3e4ae15930d9 100644
--- a/llvm/utils/lldbDataFormatters.py
+++ b/llvm/utils/lldbDataFormatters.py
@@ -197,6 +197,11 @@ def StringRefSummaryProvider(valobj, internal_dict):
         return '""'
 
     data = data_pointer.deref
+    # StringRef may be uninitialized with length exceeding available memory,
+    # potentially causing bad_alloc exceptions. Limit the length to max string summary setting.
+    limit_obj = valobj.target.debugger.GetSetting("target.max-string-summary-length")
+    if limit_obj:
+        length = min(length, limit_obj.GetUnsignedIntegerValue())
     # Get a char[N] type, from the underlying char type.
     array_type = data.type.GetArrayType(length)
     # Cast the char* string data to a char[N] array.


        


More information about the llvm-commits mailing list