to reflect the new license. We understand that people may be surprised that we're moving the header entirely to discuss the new license. We checked this carefully with the Foundation's lawyer and we believe this is the correct approach. Essentially, all code in the project is now made available by the LLVM project under our new license, so you will see that the license headers include that license only. Some of our contributors have contributed code under our old license, and accordingly, we have retained a copy of our old license notice in the top-level files in each project and repository. llvm-svn: 351636
54 lines
1.9 KiB
Python
54 lines
1.9 KiB
Python
"""
|
|
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'))
|