summaryrefslogtreecommitdiffstats
path: root/gnu/llvm/lldb/examples/summaries/unicode_strings.py
diff options
context:
space:
mode:
authorpatrick <patrick@openbsd.org>2020-08-03 14:33:06 +0000
committerpatrick <patrick@openbsd.org>2020-08-03 14:33:06 +0000
commit061da546b983eb767bad15e67af1174fb0bcf31c (patch)
tree83c78b820819d70aa40c36d90447978b300078c5 /gnu/llvm/lldb/examples/summaries/unicode_strings.py
parentImport LLVM 10.0.0 release including clang, lld and lldb. (diff)
downloadwireguard-openbsd-061da546b983eb767bad15e67af1174fb0bcf31c.tar.xz
wireguard-openbsd-061da546b983eb767bad15e67af1174fb0bcf31c.zip
Import LLVM 10.0.0 release including clang, lld and lldb.
ok hackroom tested by plenty
Diffstat (limited to 'gnu/llvm/lldb/examples/summaries/unicode_strings.py')
-rw-r--r--gnu/llvm/lldb/examples/summaries/unicode_strings.py53
1 files changed, 53 insertions, 0 deletions
diff --git a/gnu/llvm/lldb/examples/summaries/unicode_strings.py b/gnu/llvm/lldb/examples/summaries/unicode_strings.py
new file mode 100644
index 00000000000..8c382df5abf
--- /dev/null
+++ b/gnu/llvm/lldb/examples/summaries/unicode_strings.py
@@ -0,0 +1,53 @@
+"""
+Example data formatters for strings represented as (pointer,length) pairs
+encoded in UTF8/16/32 for use with the LLDB debugger
+
+To use in your projects, tweak the children names as appropriate for your data structures
+and use as summaries for your data types
+
+Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+See https://llvm.org/LICENSE.txt for license information.
+SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+"""
+
+import lldb
+
+
+def utf8_summary(value, unused):
+ pointer = value.GetChildMemberWithName("first").GetValueAsUnsigned(0)
+ length = value.GetChildMemberWithName("second").GetValueAsUnsigned(0)
+ if pointer == 0:
+ return False
+ if length == 0:
+ return '""'
+ error = lldb.SBError()
+ string_data = value.process.ReadMemory(pointer, length, error)
+ return '"%s"' % (string_data) # utf8 is safe to emit as-is on OSX
+
+
+def utf16_summary(value, unused):
+ pointer = value.GetChildMemberWithName("first").GetValueAsUnsigned(0)
+ length = value.GetChildMemberWithName("second").GetValueAsUnsigned(0)
+ # assume length is in bytes - if in UTF16 chars, just multiply by 2
+ if pointer == 0:
+ return False
+ if length == 0:
+ return '""'
+ error = lldb.SBError()
+ string_data = value.process.ReadMemory(pointer, length, error)
+ # utf8 is safe to emit as-is on OSX
+ return '"%s"' % (string_data.decode('utf-16').encode('utf-8'))
+
+
+def utf32_summary(value, unused):
+ pointer = value.GetChildMemberWithName("first").GetValueAsUnsigned(0)
+ length = value.GetChildMemberWithName("second").GetValueAsUnsigned(0)
+ # assume length is in bytes - if in UTF32 chars, just multiply by 4
+ if pointer == 0:
+ return False
+ if length == 0:
+ return '""'
+ error = lldb.SBError()
+ string_data = value.process.ReadMemory(pointer, length, error)
+ # utf8 is safe to emit as-is on OSX
+ return '"%s"' % (string_data.decode('utf-32').encode('utf-8'))