Look/Fonts: Flush text cache after resizing InfoBox fonts
[xcsoar.git] / gdb.py
blob447db7e7365f4525808abefbca987962f229f0a8
2 # XCSoar Glide Computer - http://www.xcsoar.org/
3 # Copyright (C) 2000-2012 The XCSoar Project
4 # A detailed list of copyright holders can be found in the file "AUTHORS".
6 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License
8 # as published by the Free Software Foundation; either version 2
9 # of the License, or (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 # This is a gdb module that aids debugging XCSoar. To load it, launch
23 # gdb and type:
25 # source gdb.py
28 import gdb
30 double_type = gdb.lookup_type('double')
31 string_type = gdb.lookup_type('char').pointer()
33 def fixed_value(f):
34 """Extracts the floating point value of a 'fixed' instance."""
36 if f.type.unqualified().strip_typedefs().code == double_type.code:
37 return float(f.cast(double_type))
38 else:
39 return long(f['m_nVal']) / (1. * (1 << 28))
41 def angle_value(a):
42 return fixed_value(a['value']) * 57.2957795131
44 class FixedPrinter:
45 def __init__(self, value):
46 self.value = value
48 def to_string(self):
49 return str(fixed_value(self.value))
51 class AnglePrinter:
52 def __init__(self, value):
53 self.value = value
55 def to_string(self):
56 return str(angle_value(self.value))
58 class AngleRangePrinter:
59 def __init__(self, value):
60 self.value = value
62 def to_string(self):
63 start = AnglePrinter(self.value['start']).to_string()
64 end = AnglePrinter(self.value['end']).to_string()
65 return 'AngleRange(%s..%s)' % (start, end)
67 class GeoPointPrinter:
68 def __init__(self, value):
69 self.value = value
71 def to_string(self):
72 if angle_value(self.value['latitude']) >= 180:
73 return 'GeoPoint::INVALID'
75 longitude = AnglePrinter(self.value['longitude']).to_string()
76 latitude = AnglePrinter(self.value['latitude']).to_string()
77 return 'GeoPoint(%s %s)' % (longitude, latitude)
79 class GeoBoundsPrinter:
80 def __init__(self, value):
81 self.value = value
83 def to_string(self):
84 if angle_value(self.value['latitude']['end']) >= 180:
85 return 'GeoBounds::INVALID'
87 west = AnglePrinter(self.value['longitude']['start']).to_string()
88 east = AnglePrinter(self.value['longitude']['end']).to_string()
89 south = AnglePrinter(self.value['latitude']['start']).to_string()
90 north = AnglePrinter(self.value['latitude']['end']).to_string()
91 return 'GeoBounds([%s .. %s] [%s .. %s])' % (west, east, south, north)
93 class GeoVectorPrinter:
94 def __init__(self, value):
95 self.value = value
97 def to_string(self):
98 bearing = AnglePrinter(self.value['bearing']).to_string()
99 distance = fixed_value(self.value['distance'])
100 if distance < 0:
101 return 'GeoVector::INVALID'
103 return 'GeoVector(%s %s)' % (bearing, distance)
105 class SpeedVectorPrinter:
106 def __init__(self, value):
107 self.value = value
109 def to_string(self):
110 bearing = AnglePrinter(self.value['bearing']).to_string()
111 norm = fixed_value(self.value['norm'])
112 if norm < 0:
113 return 'GeoVector::INVALID'
114 if norm == 0:
115 return 'GeoVector::ZERO'
117 return 'SpeedVector(%s %s)' % (bearing, norm)
119 class ValidityPrinter:
120 def __init__(self, value):
121 self.value = value
123 def to_string(self):
124 return 'Validity(%u)' % self.value['last']
126 class StaticStringPrinter:
127 def __init__(self, value):
128 self.value = value
130 def to_string(self):
131 return self.value['data'].cast(string_type)
133 class BrokenDatePrinter:
134 def __init__(self, value):
135 self.value = value
137 def to_string(self):
138 return 'Date(%04u/%02u/%02u)' % \
139 (int(self.value['year']),
140 int(self.value['month']),
141 int(self.value['day']))
143 class BrokenTimePrinter:
144 def __init__(self, value):
145 self.value = value
147 def to_string(self):
148 return 'Time(%02u:%02u:%02u)' % \
149 (int(self.value['hour']),
150 int(self.value['minute']),
151 int(self.value['second']))
153 class BrokenDateTimePrinter:
154 def __init__(self, value):
155 self.value = value
157 def to_string(self):
158 return 'DateTime(%04u/%02u/%02u %02u:%02u:%02u)' % \
159 (int(self.value['year']),
160 int(self.value['month']),
161 int(self.value['day']),
162 int(self.value['hour']),
163 int(self.value['minute']),
164 int(self.value['second']))
166 class RoughTimePrinter:
167 def __init__(self, value):
168 self.value = value
170 def to_string(self):
171 value = int(self.value['value'])
172 if value == 0xffff:
173 return 'RoughTime::INVALID'
175 return 'RoughTime(%02u:%02u)' % (value / 60, value % 60)
177 class RoughTimeSpanPrinter:
178 def __init__(self, value):
179 self.value = value
181 def to_string(self):
182 start = int(self.value['start']['value'])
183 end = int(self.value['start']['value'])
185 if start == 0xffff and end == 0xffff:
186 return 'RoughTimeSpan::INVALID'
188 if start == 0xffff:
189 start = ''
190 else:
191 start = '%02u:%02u' % (start / 60, start % 60)
193 if end == 0xffff:
194 end = ''
195 else:
196 end = '%02u:%02u' % (end / 60, end % 60)
198 return 'RoughTimeSpan(%s..%s)' % (start, end)
200 def lookup_function(value):
201 type = value.type
203 if type.code == gdb.TYPE_CODE_REF:
204 type = type.target ()
206 type = type.unqualified().strip_typedefs()
207 typename = type.tag
208 if typename == None:
209 return None
211 if typename == 'fixed':
212 return FixedPrinter(value)
213 elif typename == 'Angle':
214 return AnglePrinter(value)
215 elif typename == 'AngleRange':
216 return AngleRangePrinter(value)
217 elif typename == 'GeoPoint':
218 return GeoPointPrinter(value)
219 elif typename == 'GeoBounds':
220 return GeoBoundsPrinter(value)
221 elif typename == 'GeoVector':
222 return GeoVectorPrinter(value)
223 elif typename == 'SpeedVector':
224 return SpeedVectorPrinter(value)
225 elif typename == 'Validity':
226 return ValidityPrinter(value)
227 elif typename == 'BrokenDate':
228 return BrokenDatePrinter(value)
229 elif typename == 'BrokenTime':
230 return BrokenTimePrinter(value)
231 elif typename == 'BrokenDateTime':
232 return BrokenDateTimePrinter(value)
233 elif typename == 'RoughTime':
234 return RoughTimePrinter(value)
235 elif typename == 'RoughTimeSpan':
236 return RoughTimeSpanPrinter(value)
237 elif typename[:12] == 'StaticString' or typename[:12] == 'NarrowString':
238 return StaticStringPrinter(value)
240 return None
242 gdb.pretty_printers.append(lookup_function)