# -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*-
# Version: MPL 1.1 / GPLv3+ / LGPLv3+
#
# The contents of this file are subject to the Mozilla Public License Version
# 1.1 (the "License"); you may not use this file except in compliance with
# the License or as specified alternatively below. You may obtain a copy of
# the License at http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
# for the specific language governing rights and limitations under the
# License.
#
# Major Contributor(s):
# Copyright (C) 2012 Tor Lillqvist <tml@iki.fi> (initial developer)
# Copyright (C) 2012 SUSE Linux http://suse.com (initial developer's employer)
#
# All Rights Reserved.
#
# For minor contributions see the git repository.
#
# Alternatively, the contents of this file may be used under the terms of
# either the GNU General Public License Version 3 or later (the "GPLv3+"), or
# the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
# in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
# instead of those above.

# To use, add something like this to your ~/.lldbinit:

# script sys.path[:0] = [os.path.expanduser('~/lo/ios/solenv/lldb/libreoffice')]
# script import LO
# type summary add --python-function LO.rtluString_summary rtl_uString
# type summary add --python-function LO.rtl_OUString_summary rtl::OUString

import lldb

def rtluString_summary(rtlustring, dict):
    e = lldb.SBError()

    length = rtlustring.GetChildMemberWithName('length').GetValueAsUnsigned(0)
    buffer = rtlustring.GetChildMemberWithName('buffer')

    s = '"'
    i = 0
    while i < length:
        c = buffer.GetPointeeData(i, 1).GetUnsignedInt16(e, 0)
        if c == ord('"'):
            s = s + '\\"'
        elif c == ord('\\'):
            s = s + '\\\\'
        elif c == ord('\n'):
            s = s + '\\n'
        elif c == ord('\r'):
            s = s + '\\r'
        elif c == ord('\t'):
            s = s + '\\t'
        elif c < ord(' '):
            s = s + '\\{:03o}'.format(c)
        elif c < 127:
            s = s + chr(c)
        else:
            s = s + '\\u{:04x}'.format(c)
        i = i + 1
    s = s + '"'

    return s

def rtl_OUString_summary(rtloustring, dict):
    return rtluString_summary(rtloustring.GetChildMemberWithName('pData'), dict)

# vim:set shiftwidth=4 softtabstop=4 expandtab:

@@ -1359,32 +1359,50 @@
 ype summary add 
+--skip-references 
 --python-functio
@@ -1409,16 +1409,17 @@
 n LO.rtl
+_
 uString_
@@ -1457,16 +1457,50 @@
 ary add 
+--skip-pointers --skip-references 
 --python
@@ -1564,24 +1564,25 @@
 ldb%0A%0Adef rtl
+_
 uString_summ
@@ -1585,26 +1585,22 @@
 summary(
-rtlustring
+valobj
 , dict):
@@ -1632,27 +1632,448 @@
     
-le
+# print %22valobj = %22 + str(valobj) + %22, valobj.GetData() = %22 + str(valobj.GetData()) + %22, valobj.GetTypeName() = %22 + str(valobj.GetTypeName())%0A%0A    # As we don't use --skip-pointers when doi
 ng
+ 
 th
- = rtlustring
+e %22type summary add%22 for this function,%0A    # the value to be printed might actually be a pointer to a rtl_uString. Weird, huh?%0A    if valobj.TypeIsPointerType():%0A        return rtl_uString_summary(valobj.Dereference(), dict)%0A%0A    length = valobj
 .Get
@@ -2141,18 +2141,14 @@
 r = 
-rtlustring
+valobj
 .Get
@@ -2178,16 +2178,54 @@
 ffer')%0A%0A
+    buffer_ptr = buffer.AddressOf();%0A%0A
     s = 
@@ -2278,16 +2278,20 @@
 = buffer
+_ptr
 .GetPoin
@@ -2847,27 +2847,22 @@
 summary(
-rtloustring
+valobj
 , dict):
@@ -2876,16 +2876,17 @@
 turn rtl
+_
 uString_
@@ -2897,19 +2897,14 @@
 ary(
-rtloustring
+valobj
 .Get

Make the rtl_uString pretty-printer work better