@@ -0,0 +1,1818 @@
+%22%22%22%0AExample data formatters for strings represented as (pointer,length) pairs%0Aencoded in UTF8/16/32 for use with the LLDB debugger%0A%0ATo use in your projects, tweak the children names as appropriate for your data structures%0Aand use as summaries for your data types%0A%0Apart of The LLVM Compiler Infrastructure%0AThis file is distributed under the University of Illinois Open Source%0ALicense. See LICENSE.TXT for details.%0A%22%22%22%0A%0Aimport lldb%0Adef utf8_summary(value,unused):%0A%09pointer = value.GetChildMemberWithName(%22first%22).GetValueAsUnsigned(0)%0A%09length = value.GetChildMemberWithName(%22second%22).GetValueAsUnsigned(0)%0A%09if pointer == 0:%0A%09%09return False%0A%09if length == 0:%0A%09%09return '%22%22'%0A%09error = lldb.SBError()%0A%09string_data = value.process.ReadMemory(pointer, length, error)%0A%09return '%22%25s%22' %25 (string_data) # utf8 is safe to emit as-is on OSX%0A%0Adef utf16_summary(value,unused):%0A%09pointer = value.GetChildMemberWithName(%22first%22).GetValueAsUnsigned(0)%0A%09length = value.GetChildMemberWithName(%22second%22).GetValueAsUnsigned(0)%0A%09# assume length is in bytes - if in UTF16 chars, just multiply by 2%0A%09if pointer == 0:%0A%09%09return False%0A%09if length == 0:%0A%09%09return '%22%22'%0A%09error = lldb.SBError()%0A%09string_data = value.process.ReadMemory(pointer, length, error)%0A%09return '%22%25s%22' %25 (string_data.decode('utf-16').encode('utf-8')) # utf8 is safe to emit as-is on OSX%0A%0Adef utf32_summary(value,unused):%0A%09pointer = value.GetChildMemberWithName(%22first%22).GetValueAsUnsigned(0)%0A%09length = value.GetChildMemberWithName(%22second%22).GetValueAsUnsigned(0)%0A%09# assume length is in bytes - if in UTF32 chars, just multiply by 4%0A%09if pointer == 0:%0A%09%09return False%0A%09if length == 0:%0A%09%09return '%22%22'%0A%09error = lldb.SBError()%0A%09string_data = value.process.ReadMemory(pointer, length, error)%0A%09return '%22%25s%22' %25 (string_data.decode('utf-32').encode('utf-8')) # utf8 is safe to emit as-is on OSX%0A%0A

An example of data formatters that generate a summary for a Unicode UTF encoded string represented as a (pointer,length) pair