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
30 double_type
= gdb
.lookup_type('double')
31 string_type
= gdb
.lookup_type('char').pointer()
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
))
39 return long(f
['m_nVal']) / (1. * (1 << 28))
42 return fixed_value(a
['value']) * 57.2957795131
45 def __init__(self
, value
):
49 return str(fixed_value(self
.value
))
52 def __init__(self
, value
):
56 return str(angle_value(self
.value
))
58 class AngleRangePrinter
:
59 def __init__(self
, value
):
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
):
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
):
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
):
98 bearing
= AnglePrinter(self
.value
['bearing']).to_string()
99 distance
= fixed_value(self
.value
['distance'])
101 return 'GeoVector::INVALID'
103 return 'GeoVector(%s %s)' % (bearing
, distance
)
105 class SpeedVectorPrinter
:
106 def __init__(self
, value
):
110 bearing
= AnglePrinter(self
.value
['bearing']).to_string()
111 norm
= fixed_value(self
.value
['norm'])
113 return 'GeoVector::INVALID'
115 return 'GeoVector::ZERO'
117 return 'SpeedVector(%s %s)' % (bearing
, norm
)
119 class ValidityPrinter
:
120 def __init__(self
, value
):
124 return 'Validity(%u)' % self
.value
['last']
126 class StaticStringPrinter
:
127 def __init__(self
, value
):
131 return self
.value
['data'].cast(string_type
)
133 class BrokenDatePrinter
:
134 def __init__(self
, value
):
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
):
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
):
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
):
171 value
= int(self
.value
['value'])
173 return 'RoughTime::INVALID'
175 return 'RoughTime(%02u:%02u)' % (value
/ 60, value
% 60)
177 class RoughTimeSpanPrinter
:
178 def __init__(self
, value
):
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'
191 start
= '%02u:%02u' % (start
/ 60, start
% 60)
196 end
= '%02u:%02u' % (end
/ 60, end
% 60)
198 return 'RoughTimeSpan(%s..%s)' % (start
, end
)
200 def lookup_function(value
):
203 if type.code
== gdb
.TYPE_CODE_REF
:
204 type = type.target ()
206 type = type.unqualified().strip_typedefs()
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
)
242 gdb
.pretty_printers
.append(lookup_function
)