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
|
class map_local(object):
__slots__ = ('_value')
name = 'tmwa::map::map_local'
depth = 1
enabled = True
def __init__(self, value):
if not value:
value = None
self._value = value
def to_string(self):
value = self._value
if value is None:
return '(map_local *) nullptr'
return '(map_local *)'
def children(self):
value = self._value
if value is None:
return
value = value.dereference()
yield '->name', value['name_']
yield '->xs', value['xs']
yield '->ys', value['ys']
tests = [
('static_cast<tmwa::map::map_local *>(nullptr)', '(map_local *) nullptr'),
('fake_map_local("map"_s, 42, 404)', '(map_local *) = {->name = "map", ->xs = 42, ->ys = 404}'),
]
class map_remote(object):
__slots__ = ('_value')
name = 'tmwa::map::map_remote'
depth = 1
enabled = True
def __init__(self, value):
if not value:
value = None
self._value = value
def to_string(self):
value = self._value
if value is None:
return '(map_remote *) nullptr'
return '(map_remote *)'
def children(self):
value = self._value
if value is None:
return
value = value.dereference()
yield '->name', value['name_']
yield '->ip', value['ip']
yield '->port', value['port']
tests = [
('static_cast<tmwa::map::map_remote *>(nullptr)', '(map_remote *) nullptr'),
('fake_map_remote("map"_s, tmwa::IP4Address({8, 8, 8, 8}), 6667)', '(map_remote *) = {->name = "map", ->ip = 8.8.8.8, ->port = 6667}'),
]
class map_abstract(object):
__slots__ = ('_value')
name = 'tmwa::map::map_abstract'
depth = 1
enabled = True
def __init__(self, value):
if not value:
value = None
self._value = value
def to_string(self):
value = self._value
if value is None:
return '(map_abstract *) nullptr'
gat = value.dereference()['gat']
gat = gat.address.cast(gdb.lookup_type('tmwa::map::map_abstract').pointer().pointer()).dereference()
if gat:
return value.cast(gdb.lookup_type('tmwa::map::map_local').pointer())
else:
return value.cast(gdb.lookup_type('tmwa::map::map_remote').pointer())
tests = [
('static_cast<tmwa::map::map_abstract *>(nullptr)', '(map_abstract *) nullptr'),
] + [
('static_cast<tmwa::map::map_abstract *>(%s); value->gat.reset(new tmwa::map::MapCell[1])' % expr, expected)
for (expr, expected) in map_local.tests[1:]
] + [
('static_cast<tmwa::map::map_abstract *>(%s)' % expr, expected)
for (expr, expected) in map_remote.tests[1:]
]
test_extra = '''
using tmwa::operator "" _s;
inline
tmwa::map::map_local *fake_map_local(tmwa::ZString name, int xs, int ys)
{
auto *p = new tmwa::map::map_local{};
p->name_ = tmwa::stringish<tmwa::MapName>(name);
p->xs = xs;
p->ys = ys;
return p;
}
inline
tmwa::map::map_remote *fake_map_remote(tmwa::ZString name, tmwa::IP4Address ip, uint16_t port)
{
auto *p = new tmwa::map::map_remote{};
p->name_ = tmwa::stringish<tmwa::MapName>(name);
p->ip = ip;
p->port = port;
return p;
}
void fake_delete(tmwa::map::map_abstract *);
void fake_delete(tmwa::map::map_abstract *map)
{
delete map;
}
'''
|