-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathwt_gdb_prettyprinter.py
More file actions
198 lines (153 loc) · 8.19 KB
/
wt_gdb_prettyprinter.py
File metadata and controls
198 lines (153 loc) · 8.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
import gdb.printing
import math
from termcolor import colored
quantity_colour = 'cyan'
variable_colour = 'yellow'
def print_quantity_type(type):
s = str(gdb.types.get_basic_type(type))
if (not s.startswith('mp_units::quantity')):
s = s[s.find('mp_units::quantity<'):].removesuffix(' >')
if (s.find('mp_units::quantity<mp_units::reference<mp_units::isq::thermodynamic_temperature, mp_units::si::kelvin>(),') >= 0):
s = 'K'
elif (s.find('mp_units::quantity<mp_units::reference<mp_units::isq::thermodynamic_temperature, mp_units::si::deg_C>(),') >= 0):
s = '°C'
elif (s.find('mp_units::quantity<mp_units::reference<mp_units::angular::angle, mp_units::angular::radian>(), ') >= 0):
s = 'rad'
elif (s.find('mp_units::quantity<mp_units::reference<mp_units::angular::angle, mp_units::angular::degree>(), ') >= 0):
s = '°'
elif (s.find('mp_units::quantity<mp_units::reference<mp_units::isq::length, mp_units::si::metre>(), ') >= 0):
s = 'm'
elif (s.find('mp_units::quantity<mp_units::reference<mp_units::derived_quantity_spec<mp_units::dimensionless, mp_units::per<mp_units::isq::length> >, mp_units::derived_unit<mp_units::one, mp_units::per<mp_units::si::milli_<mp_units::si::metre> > > >(), ') >= 0):
s = '1/mm'
elif (s.find('mp_units::quantity<mp_units::reference<mp_units::isq::length, mp_units::si::milli_<mp_units::si::metre> >(), ') >= 0):
s = 'mm'
else:
s = s.removeprefix('mp_units::quantity<').removesuffix('>')\
.replace('mp_units::','')\
.replace('derived_unit','')\
.replace('derived_quantity_spec','spec')\
.replace('power<','pow<')\
.replace(' >','>')\
.replace('dimensionless','1')\
.replace('one','1')\
.replace('thermodynamic_temperature','temp')\
.replace('()','')\
.replace('isq::','')\
.replace('si::','')\
.replace(', per<','/<')\
.removeprefix('detail::reference_t')\
.removeprefix('reference')\
.rstrip().rsplit(' ', 1)[0].rstrip().removesuffix(',')\
.removeprefix('<').removesuffix('>')
return colored('['+s+']', quantity_colour)
class vec2Printer:
def __init__(self, val):
self.val = val
def to_string (self):
return '{' + colored(str(self.val['x']), attrs=["bold"]) +','+ colored(str(self.val['y']), attrs=["bold"]) + '}'
class vec3Printer:
def __init__(self, val):
self.val = val
def to_string (self):
return '{' + colored(str(self.val['x']), attrs=["bold"]) +','+ colored(str(self.val['y']), attrs=["bold"]) +','+ colored(str(self.val['z']), attrs=["bold"]) + '}'
class vec4Printer:
def __init__(self, val):
self.val = val
def to_string (self):
return '{' + colored(str(self.val['x']), attrs=["bold"]) +','+ colored(str(self.val['y']), attrs=["bold"]) +','+ colored(str(self.val['z']), attrs=["bold"]) +','+ colored(str(self.val['w']), attrs=["bold"]) + '}'
class qvec2Printer:
def __init__(self, val):
self.val = val
def to_string (self):
return '{' + \
colored(str(self.val['x']['numerical_value_is_an_implementation_detail_']), attrs=["bold"]) +','+ \
colored(str(self.val['y']['numerical_value_is_an_implementation_detail_']), attrs=["bold"]) + '} ' + print_quantity_type(self.val.type)
class qvec3Printer:
def __init__(self, val):
self.val = val
def to_string (self):
return '{' + \
colored(str(self.val['x']['numerical_value_is_an_implementation_detail_']), attrs=["bold"]) +','+ \
colored(str(self.val['y']['numerical_value_is_an_implementation_detail_']), attrs=["bold"]) +','+ \
colored(str(self.val['z']['numerical_value_is_an_implementation_detail_']), attrs=["bold"]) + '} ' + print_quantity_type(self.val.type)
class qvec4Printer:
def __init__(self, val):
self.val = val
def to_string (self):
return '{' + \
colored(str(self.val['x']['numerical_value_is_an_implementation_detail_']), attrs=["bold"]) +','+ \
colored(str(self.val['y']['numerical_value_is_an_implementation_detail_']), attrs=["bold"]) +','+ \
colored(str(self.val['z']['numerical_value_is_an_implementation_detail_']), attrs=["bold"]) +','+ \
colored(str(self.val['w']['numerical_value_is_an_implementation_detail_']), attrs=["bold"]) + '} ' + print_quantity_type(self.val.type)
class rayPrinter:
def __init__(self, val):
self.val = val
def to_string (self):
return str(self.val['o']) + ' -> ' + str(self.val['d'])
class ellipticConePrinter:
def __init__(self, val):
self.val = val
def to_string (self):
e = self.val['e']
x = self.val['x']
ecc = math.sqrt(max(0,1-1/(e*e)))
alpha = math.atan(self.val['tan_alpha'])
if e>=1:
ecc_text = colored('ε',variable_colour) + '=' + colored(str(ecc), attrs=["bold"])
else:
ecc_text = colored('e',variable_colour) + '=' + colored(str(e), 'red', attrs=["bold"])
return '( ' + str(self.val['r']) + ', ' +\
colored('α', variable_colour) + '=' + colored(str(alpha), attrs=["bold"]) + ', '+\
ecc_text + ', '+\
colored('x', variable_colour) + '=' + colored(str(self.val['tangent']), attrs=["bold"]) + ' ⨯ ' + colored(str(self.val['initial_x_length']), attrs=["bold"]) +\
' )'
class beamPrinter:
def __init__(self, val):
self.val = val
def to_string (self):
return '( ' +\
colored('S', variable_colour) + '=' + str(self.val['S']) + ', '+\
colored('envelope', variable_colour) + '=' + str(self.val['envelope']) + ', '+\
colored('self_intersection_distance', variable_colour) + '=' + colored(str(self.val['self_intersection_distance']), attrs=["bold"]) + ', '+\
colored('intersection_offset', variable_colour) + '=' + colored(str(self.val['intersection_offset']), attrs=["bold"]) + ', '+\
' )'
class quantityPrinter:
def __init__(self, val):
self.val = val
def to_string (self):
return colored(str(self.val['numerical_value_is_an_implementation_detail_']), attrs=["bold"]) + " " + print_quantity_type(self.val.type)
class quantityPointPrinter:
def __init__(self, val):
self.val = val
def to_string (self):
return colored(str(self.val['quantity_from_origin_is_an_implementation_detail_']), attrs=["bold"])
class emptyUnitPrinter:
def __init__(self, val):
self.val = val
def to_string (self):
return 'unitless'
class namedUnitPrinter:
def __init__(self, val):
self.val = val
def to_string (self):
return colored(str(self.val['_symbol_']['utf8_']['data_']), quantity_colour)
def build_prettyprinters():
pp = gdb.printing.RegexpCollectionPrettyPrinter("wt")
pp.add_printer('vec2_t', '^glm::vec<2,.*>$', vec2Printer)
pp.add_printer('vec3_t', '^glm::vec<3,.*>$', vec3Printer)
pp.add_printer('vec4_t', '^glm::vec<4,.*>$', vec4Printer)
pp.add_printer('dir2_t', '^wt::unit_vector<2,.*>$', vec2Printer)
pp.add_printer('dir3_t', '^wt::unit_vector<3,.*>$', vec3Printer)
pp.add_printer('dir4_t', '^wt::unit_vector<4,.*>$', vec4Printer)
pp.add_printer('qvec2_t', '^wt::quantity_vector<2,.*>$', qvec2Printer)
pp.add_printer('qvec3_t', '^wt::quantity_vector<3,.*>$', qvec3Printer)
pp.add_printer('qvec4_t', '^wt::quantity_vector<4,.*>$', qvec4Printer)
pp.add_printer('ray_t', '^wt::ray_t$', rayPrinter)
pp.add_printer('elliptic_cone_t', '^wt::elliptic_cone_t$', ellipticConePrinter)
pp.add_printer('quantity', '^mp_units::quantity<.*>$', quantityPrinter)
pp.add_printer('quantity_point', '^mp_units::quantity_point<.*>$', quantityPointPrinter)
pp.add_printer('mp_units::unit', '^mp_units::detail::derived_unit_impl<>$', emptyUnitPrinter)
pp.add_printer('mp_units::named_unit', '^mp_units::named_unit<.*>$', namedUnitPrinter)
pp.add_printer('beam_t', '^wt::beam_t$', beamPrinter)
return pp
gdb.printing.register_pretty_printer(gdb.current_objfile(),build_prettyprinters())