lok: vcl: fix multiple floatwin removal case more robustly.
[LibreOffice.git] / solenv / lldb / libreoffice / LO.py
blob3c1134ccadc4804ea13bc1ed1136bf9836763fb3
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_String_summary(valobj, dict):
16 if valobj.TypeIsPointerType():
17 return rtl_String_summary(valobj.Dereference(), dict)
19 length = valobj.GetChildMemberWithName('length').GetValueAsUnsigned(0)
20 buffer = valobj.GetChildMemberWithName('buffer')
21 buffer_ptr = buffer.AddressOf();
23 # return '"' + buffer_ptr.GetPointeeData(0, length).GetString(lldb.SBError(), 0) + '"'
24 return sal_ascii_string(buffer_ptr, length)
26 def rtl_OString_summary(valobj, dict):
27 return rtl_String_summary(valobj.GetChildMemberWithName('pData'), dict)
29 def sal_ascii_string(buffer_ptr, length):
30 e = lldb.SBError()
32 s = '"'
33 i = 0
34 while i < length:
35 c = buffer_ptr.GetPointeeData(i, 1).GetUnsignedInt8(e, 0)
36 if c == ord('"'): s = s + '\\"'
37 elif c == ord('\\'): s = s + '\\\\'
38 elif c == ord('\n'): s = s + '\\n'
39 elif c == ord('\r'): s = s + '\\r'
40 elif c == ord('\t'):
41 s = s + '\\t'
42 elif c < ord(' '):
43 s = s + '\\{:03o}'.format(c)
44 elif c < 127:
45 s = s + chr(c)
46 else:
47 s = s + '\\u{:04x}'.format(c)
48 i = i + 1
49 s = s + '"'
51 return s
53 def rtl_uString_summary(valobj, dict):
54 # print "valobj = " + str(valobj) + ", valobj.GetData() = " + str(valobj.GetData()) + ", valobj.GetTypeName() = " + str(valobj.GetTypeName())
56 # As we don't use --skip-pointers when doing the "type summary add" for this function,
57 # the value to be printed might actually be a pointer to a rtl_uString. Weird, huh?
58 if valobj.TypeIsPointerType():
59 return rtl_uString_summary(valobj.Dereference(), dict)
61 length = valobj.GetChildMemberWithName('length').GetValueAsUnsigned(0)
62 buffer = valobj.GetChildMemberWithName('buffer')
64 buffer_ptr = buffer.AddressOf();
66 return sal_unicode_string(buffer_ptr, length)
68 def rtl_OUString_summary(valobj, dict):
69 return rtl_uString_summary(valobj.GetChildMemberWithName('pData'), dict)
71 def sal_unicode_string(buffer_ptr, length):
72 e = lldb.SBError()
74 s = '"'
75 i = 0
76 while i < length:
77 c = buffer_ptr.GetPointeeData(i, 1).GetUnsignedInt16(e, 0)
78 if c == ord('"'):
79 s = s + '\\"'
80 elif c == ord('\\'):
81 s = s + '\\\\'
82 elif c == ord('\n'):
83 s = s + '\\n'
84 elif c == ord('\r'):
85 s = s + '\\r'
86 elif c == ord('\t'):
87 s = s + '\\t'
88 elif c < ord(' '):
89 s = s + '\\{:03o}'.format(c)
90 elif c < 127:
91 s = s + chr(c)
92 else:
93 s = s + '\\u{:04x}'.format(c)
94 i = i + 1
95 s = s + '"'
97 return s
99 # Automatically install the above summary functions when this is loaded
100 def __lldb_init_module(debugger, dict):
101 debugger.HandleCommand("type summary add --skip-references --python-function LO.rtl_String_summary rtl_String")
102 debugger.HandleCommand("type summary add --skip-pointers --skip-references --python-function LO.rtl_OString_summary rtl::OString")
103 debugger.HandleCommand("type summary add --skip-references --python-function LO.rtl_uString_summary rtl_uString")
104 debugger.HandleCommand("type summary add --skip-pointers --skip-references --python-function LO.rtl_OUString_summary rtl::OUString")
106 # vim:set shiftwidth=4 softtabstop=4 expandtab: