|
8 | 8 |
|
9 | 9 | import collections |
10 | 10 | import lldb |
11 | | -import json |
12 | 11 |
|
13 | 12 |
|
14 | 13 | def __lldb_init_module(debugger, internal_dict): |
@@ -192,28 +191,19 @@ def SmallStringSummaryProvider(valobj, internal_dict): |
192 | 191 |
|
193 | 192 |
|
194 | 193 | def StringRefSummaryProvider(valobj, internal_dict): |
195 | | - if valobj.GetNumChildren() == 2: |
196 | | - # StringRef's are also used to point at binary blobs in memory, |
197 | | - # so filter out suspiciously long strings. |
198 | | - max_length = 1024 |
199 | | - actual_length = valobj.GetChildAtIndex(1).GetValueAsUnsigned() |
200 | | - truncate = actual_length > max_length |
201 | | - length = min(max_length, actual_length) |
202 | | - if length == 0: |
203 | | - return '""' |
204 | | - |
205 | | - data = valobj.GetChildAtIndex(0).GetPointeeData(item_count=length) |
206 | | - error = lldb.SBError() |
207 | | - string = data.ReadRawData(error, 0, data.GetByteSize()).decode() |
208 | | - if error.Fail(): |
209 | | - return "<error: %s>" % error.description |
210 | | - |
211 | | - # json.dumps conveniently escapes the string for us. |
212 | | - string = json.dumps(string) |
213 | | - if truncate: |
214 | | - string += "..." |
215 | | - return string |
216 | | - return None |
| 194 | + data_pointer = valobj.GetChildMemberWithName("Data") |
| 195 | + length = valobj.GetChildMemberWithName("Length").unsigned |
| 196 | + if data_pointer.unsigned == 0 or length == 0: |
| 197 | + return '""' |
| 198 | + |
| 199 | + data = data_pointer.deref |
| 200 | + # Get a char[N] type, from the underlying char type. |
| 201 | + array_type = data.type.GetArrayType(length) |
| 202 | + # Cast the char* string data to a char[N] array. |
| 203 | + char_array = data.Cast(array_type) |
| 204 | + # Use the builtin summary for its support of max-string-summary-length and |
| 205 | + # display of non-printable bytes. |
| 206 | + return char_array.summary |
217 | 207 |
|
218 | 208 |
|
219 | 209 | def ConstStringSummaryProvider(valobj, internal_dict): |
|
0 commit comments