2 Example data formatters for strings represented as (pointer,length) pairs
3 encoded in UTF8/16/32 for use with the LLDB debugger
5 To use in your projects, tweak the children names as appropriate for your data structures
6 and use as summaries for your data types
8 Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
9 See https://llvm.org/LICENSE.txt for license information.
10 SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
16 def utf8_summary(value
, unused
):
17 pointer
= value
.GetChildMemberWithName("first").GetValueAsUnsigned(0)
18 length
= value
.GetChildMemberWithName("second").GetValueAsUnsigned(0)
23 error
= lldb
.SBError()
24 string_data
= value
.process
.ReadMemory(pointer
, length
, error
)
25 return '"%s"' % (string_data
) # utf8 is safe to emit as-is on OSX
28 def utf16_summary(value
, unused
):
29 pointer
= value
.GetChildMemberWithName("first").GetValueAsUnsigned(0)
30 length
= value
.GetChildMemberWithName("second").GetValueAsUnsigned(0)
31 # assume length is in bytes - if in UTF16 chars, just multiply by 2
36 error
= lldb
.SBError()
37 string_data
= value
.process
.ReadMemory(pointer
, length
, error
)
38 # utf8 is safe to emit as-is on OSX
39 return '"%s"' % (string_data
.decode("utf-16").encode("utf-8"))
42 def utf32_summary(value
, unused
):
43 pointer
= value
.GetChildMemberWithName("first").GetValueAsUnsigned(0)
44 length
= value
.GetChildMemberWithName("second").GetValueAsUnsigned(0)
45 # assume length is in bytes - if in UTF32 chars, just multiply by 4
50 error
= lldb
.SBError()
51 string_data
= value
.process
.ReadMemory(pointer
, length
, error
)
52 # utf8 is safe to emit as-is on OSX
53 return '"%s"' % (string_data
.decode("utf-32").encode("utf-8"))