From e3f090bed709bef5ba7fc4317c7b1d3f20cce967 Mon Sep 17 00:00:00 2001 From: Ebuka Ezike Date: Tue, 7 Oct 2025 16:06:49 +0100 Subject: [PATCH 1/3] [llvm][utils] Improve the StringRef summary provider - check the length of data before casting as `char[N]` because the will cause lldb to allocate `N` bytes of memory. --- llvm/utils/lldbDataFormatters.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/llvm/utils/lldbDataFormatters.py b/llvm/utils/lldbDataFormatters.py index 5e553caa4446d..06cb8cbb1e068 100644 --- a/llvm/utils/lldbDataFormatters.py +++ b/llvm/utils/lldbDataFormatters.py @@ -197,6 +197,13 @@ 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.GetTarget().GetDebugger().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. From 1a911a6eb119702dabe60f7903c3aa5b2c541953 Mon Sep 17 00:00:00 2001 From: Ebuka Ezike Date: Thu, 23 Oct 2025 18:04:29 +0100 Subject: [PATCH 2/3] Update llvm/utils/lldbDataFormatters.py Co-authored-by: Dave Lee --- llvm/utils/lldbDataFormatters.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/llvm/utils/lldbDataFormatters.py b/llvm/utils/lldbDataFormatters.py index 06cb8cbb1e068..d061127369d9a 100644 --- a/llvm/utils/lldbDataFormatters.py +++ b/llvm/utils/lldbDataFormatters.py @@ -200,7 +200,7 @@ def StringRefSummaryProvider(valobj, internal_dict): # 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.GetTarget().GetDebugger().GetSetting("target.max-string-summary-length") + valobj.target.debugger.GetSetting("target.max-string-summary-length") ) if limit_obj: length = min(length, limit_obj.GetUnsignedIntegerValue()) From 2ed4c24766839e1862476646974ec1fd9bd15147 Mon Sep 17 00:00:00 2001 From: Ebuka Ezike Date: Thu, 23 Oct 2025 18:08:35 +0100 Subject: [PATCH 3/3] fix format Refactor string summary length limit retrieval. --- llvm/utils/lldbDataFormatters.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/llvm/utils/lldbDataFormatters.py b/llvm/utils/lldbDataFormatters.py index d061127369d9a..a3e4ae15930d9 100644 --- a/llvm/utils/lldbDataFormatters.py +++ b/llvm/utils/lldbDataFormatters.py @@ -199,9 +199,7 @@ def StringRefSummaryProvider(valobj, internal_dict): 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") - ) + 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.