[Lldb-commits] [lldb] r192206 - An example of data formatters that generate a summary for a Unicode UTF encoded string represented as a (pointer, length) pair
Greg Clayton
gclayton at apple.com
Tue Oct 8 13:15:57 PDT 2013
Seems like these functions could be placed into the "lldb" module and made to take the expression paths for the pointer and length variables. Maybe something like:
def utf8_summary(value, ptr_path, length_path):
pointer = value.GetValueForExpressionPath(ptr_path).GetValueAsUnsigned(0)
if pointer == 0:
return False
length = value.GetValueForExpressionPath(length_path).GetValueAsUnsigned(0)
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
Then we could call this with:
return lldb.utf8_summary(my_value,
".__r_.__first_.__l.__data_",
".__r_.__first_.__l.__size_")
On Oct 8, 2013, at 10:29 AM, Enrico Granata <egranata at apple.com> wrote:
> Author: enrico
> Date: Tue Oct 8 12:29:27 2013
> New Revision: 192206
>
> URL: http://llvm.org/viewvc/llvm-project?rev=192206&view=rev
> Log:
> An example of data formatters that generate a summary for a Unicode UTF encoded string represented as a (pointer,length) pair
>
>
> Added:
> lldb/trunk/examples/summaries/unicode_strings.py
>
> Added: lldb/trunk/examples/summaries/unicode_strings.py
> URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/examples/summaries/unicode_strings.py?rev=192206&view=auto
> ==============================================================================
> --- lldb/trunk/examples/summaries/unicode_strings.py (added)
> +++ lldb/trunk/examples/summaries/unicode_strings.py Tue Oct 8 12:29:27 2013
> @@ -0,0 +1,48 @@
> +"""
> +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 Compiler Infrastructure
> +This file is distributed under the University of Illinois Open Source
> +License. See LICENSE.TXT for details.
> +"""
> +
> +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)
> + return '"%s"' % (string_data.decode('utf-16').encode('utf-8')) # utf8 is safe to emit as-is on OSX
> +
> +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)
> + return '"%s"' % (string_data.decode('utf-32').encode('utf-8')) # utf8 is safe to emit as-is on OSX
> +
>
>
> _______________________________________________
> lldb-commits mailing list
> lldb-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/lldb-commits
More information about the lldb-commits
mailing list