Branch libreoffice-5-0-4
[LibreOffice.git] / solenv / lldb / libreoffice / LO.py
blob10d368f85d570c45f8b66c6cddcd6000950c000a
1 # -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*-
3 # This file is part of the LibreOffice project.
5 # This Source Code Form is subject to the terms of the Mozilla Public
6 # License, v. 2.0. If a copy of the MPL was not distributed with this
7 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 # To use, add something like this to your ~/.lldbinit:
11 # command script import '~/lo/sim/solenv/lldb/libreoffice/LO.py'
13 import lldb
15 def rtl_uString_summary(valobj, dict):
16 # print "valobj = " + str(valobj) + ", valobj.GetData() = " + str(valobj.GetData()) + ", valobj.GetTypeName() = " + str(valobj.GetTypeName())
18 # As we don't use --skip-pointers when doing the "type summary add" for this function,
19 # the value to be printed might actually be a pointer to a rtl_uString. Weird, huh?
20 if valobj.TypeIsPointerType():
21 return rtl_uString_summary(valobj.Dereference(), dict)
23 length = valobj.GetChildMemberWithName('length').GetValueAsUnsigned(0)
24 buffer = valobj.GetChildMemberWithName('buffer')
26 buffer_ptr = buffer.AddressOf();
28 return sal_unicode_string(buffer_ptr, length)
30 def rtl_OUString_summary(valobj, dict):
31 return rtl_uString_summary(valobj.GetChildMemberWithName('pData'), dict)
33 def UniStringData_summary(valobj, dict):
34 if valobj.TypeIsPointerType():
35 return UniStringData_summary(valobj.Dereference(), dict)
37 length = valobj.GetChildMemberWithName('mnLen').GetValueAsUnsigned(0)
38 buffer = valobj.GetChildMemberWithName('maStr')
40 buffer_ptr = buffer.AddressOf();
42 return sal_unicode_string(buffer_ptr, length)
44 def String_summary(valobj, dict):
45 return UniStringData_summary(valobj.GetChildMemberWithName('mpData'), dict)
47 def sal_unicode_string(buffer_ptr, length):
48 e = lldb.SBError()
50 s = '"'
51 i = 0
52 while i < length:
53 c = buffer_ptr.GetPointeeData(i, 1).GetUnsignedInt16(e, 0)
54 if c == ord('"'):
55 s = s + '\\"'
56 elif c == ord('\\'):
57 s = s + '\\\\'
58 elif c == ord('\n'):
59 s = s + '\\n'
60 elif c == ord('\r'):
61 s = s + '\\r'
62 elif c == ord('\t'):
63 s = s + '\\t'
64 elif c < ord(' '):
65 s = s + '\\{:03o}'.format(c)
66 elif c < 127:
67 s = s + chr(c)
68 else:
69 s = s + '\\u{:04x}'.format(c)
70 i = i + 1
71 s = s + '"'
73 return s
75 # Automatically install the above summary functions when this is loaded
76 def __lldb_init_module(debugger, dict):
77 debugger.HandleCommand("type summary add --skip-references --python-function LO.rtl_uString_summary rtl_uString")
78 debugger.HandleCommand("type summary add --skip-pointers --skip-references --python-function LO.rtl_OUString_summary rtl::OUString")
79 debugger.HandleCommand("type summary add --skip-references --python-function LO.UniStringData_summary UniStringData")
80 debugger.HandleCommand("type summary add --skip-pointers --skip-references --python-function LO.String_summary String")
82 # vim:set shiftwidth=4 softtabstop=4 expandtab: