Skip to content

Commit e3f090b

Browse files
committed
[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.
1 parent bc39a8f commit e3f090b

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

llvm/utils/lldbDataFormatters.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,13 @@ def StringRefSummaryProvider(valobj, internal_dict):
197197
return '""'
198198

199199
data = data_pointer.deref
200+
# StringRef may be uninitialized with length exceeding available memory,
201+
# potentially causing bad_alloc exceptions. Limit the length to max string summary setting.
202+
limit_obj = (
203+
valobj.GetTarget().GetDebugger().GetSetting("target.max-string-summary-length")
204+
)
205+
if limit_obj:
206+
length = min(length, limit_obj.GetUnsignedIntegerValue())
200207
# Get a char[N] type, from the underlying char type.
201208
array_type = data.type.GetArrayType(length)
202209
# Cast the char* string data to a char[N] array.

0 commit comments

Comments
 (0)