fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / solenv / gdb / libreoffice / sal.py
blobc2e8384537be5b130049f262f6c98f39f6fec57e
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 import gdb
11 import gdb.types
12 import six
14 from libreoffice.util import printing
15 from libreoffice.util.string import StringPrinterHelper
17 class RtlStringPrinter(StringPrinterHelper):
18 '''Prints rtl_String or rtl_uString'''
20 def __init__(self, typename, val, encoding = None):
21 super(RtlStringPrinter, self).__init__(typename, val, encoding)
23 def data(self):
24 return self.val['buffer']
26 def length(self):
27 return self.val['length']
29 class StringPrinter(StringPrinterHelper):
30 '''Prints rtl:: strings and string buffers'''
32 def __init__(self, typename, val, encoding = None):
33 super(StringPrinter, self).__init__(typename, val, encoding)
35 def valid(self):
36 return self.val['pData']
38 def data(self):
39 assert self.val['pData']
40 return self.val['pData'].dereference()['buffer']
42 def length(self):
43 assert self.val['pData']
44 return self.val['pData'].dereference()['length']
46 class SalUnicodePrinter(StringPrinterHelper):
47 '''Prints a sal_Unicode*'''
49 def __init__(self, typename, val):
50 super(SalUnicodePrinter, self).__init__(typename, val, 'utf-16')
52 def data(self):
53 return self.val
55 @staticmethod
56 def query(type):
57 type = type.unqualified()
58 if type.code != gdb.TYPE_CODE_PTR:
59 return False
60 return str(type.target()) == 'sal_Unicode'
62 class RtlReferencePrinter(object):
63 '''Prints rtl::Reference'''
65 def __init__(self, typename, val):
66 self.typename = typename
67 self.val = val
69 def to_string(self):
70 pointee = self.val['m_pBody']
71 if pointee:
72 return '%s to %s' % (self.typename, str(pointee))
73 else:
74 return "empty %s" % self.typename
76 class OslFileStatusPrinter(object):
77 '''Prints oslFileStatus'''
79 def __init__(self, typename, val):
80 self.val = val
82 def to_string(self):
83 osl_file_type = gdb.lookup_type('oslFileType').strip_typedefs()
84 fields_to_enum_val = gdb.types.make_enum_dict(osl_file_type)
86 etype = self.field_val_if_valid('eType')
87 if etype is not None:
88 pretty_etype = '<unknown type>' # in case it's not one of the fields
90 for field_name, field_val in six.iteritems(fields_to_enum_val):
91 if etype == field_val:
92 pretty_etype = self.pretty_file_type(field_name)
93 else:
94 pretty_etype = '<invalid type>'
96 file_url = self.field_val_if_valid('ustrFileURL')
97 if file_url is not None:
98 pretty_file_url = str(file_url.dereference())
99 else:
100 pretty_file_url = '<invalid file url>'
102 pretty_file_status = pretty_etype + ': ' + pretty_file_url
104 # for links append the link target if valid
105 if etype == fields_to_enum_val['osl_File_Type_Link']:
106 link_target = self.field_val_if_valid('ustrLinkTargetURL')
107 if link_target is None:
108 pretty_link_target = '<invalid link target>'
109 else:
110 pretty_link_target = str(link_target.dereference())
112 pretty_file_status += ' -> ' + pretty_link_target
114 return pretty_file_status
116 def pretty_file_type(self, file_type_name):
117 if file_type_name != 'osl_File_Type_Regular':
118 return file_type_name.replace('osl_File_Type_', '').lower()
119 else:
120 return 'file' # regular is not very descriptive, file is better
122 def field_val_if_valid(self, field):
123 mask_for_field = {'eType': 0x00000001,
124 'uAttributes': 0x00000002,
125 'aCreationTime': 0x00000010,
126 'aAccessTime': 0x00000020,
127 'aModifyTime': 0x00000040,
128 'uFileSize': 0x00000080,
129 'ustrFileName': 0x00000100,
130 'ustrFileURL': 0x00000200,
131 'ustrLinkTargetURL': 0x00000400}
133 valid_fields = self.val['uValidFields']
134 if valid_fields & mask_for_field[field]:
135 return self.val[field]
136 else:
137 return None
139 printer = None
141 def build_pretty_printers():
142 global printer
144 printer = printing.Printer("libreoffice/sal")
146 # strings and string buffers
147 printer.add('_rtl_String', RtlStringPrinter)
148 printer.add('_rtl_uString', lambda name, val: RtlStringPrinter(name,
149 val, 'utf-16le'))
150 printer.add('rtl::OString', StringPrinter)
151 printer.add('rtl::OUString', lambda name, val: StringPrinter(name, val, 'utf-16'))
152 printer.add('rtl::OStringBuffer', StringPrinter)
153 printer.add('rtl::OUStringBuffer', lambda name, val: StringPrinter(name, val, 'utf-16'))
154 printer.add('sal_Unicode', SalUnicodePrinter, SalUnicodePrinter.query)
156 # other stuff
157 printer.add('rtl::Reference', RtlReferencePrinter)
158 printer.add('_oslFileStatus', OslFileStatusPrinter)
160 return printer
162 def register_pretty_printers(obj):
163 printing.register_pretty_printer(printer, obj)
165 build_pretty_printers()
167 # vim:set shiftwidth=4 softtabstop=4 expandtab: