diff options
| author | David Lamparter <equinox@diac24.net> | 2021-02-14 01:36:09 +0100 |
|---|---|---|
| committer | David Lamparter <equinox@diac24.net> | 2021-02-23 16:56:58 +0100 |
| commit | a971f0718d25eb9bc553e774bd19a2276e26072e (patch) | |
| tree | 765b1a094e4c731bfc68b46fe666e3bcef145188 /python/tiabwarfo.py | |
| parent | 5e085e529da67deac8171f5a34274f5af7d94492 (diff) | |
python/xrelfo: cross-platform xrefstructs.json
Just get names, types and order from pahole; ditch offset & size since
they're different on 32/64 bit. None of the structs has padding
currently; if we really need that it can be implemented in the future.
(Padding will raise an exception, so it won't break silently.)
Signed-off-by: David Lamparter <equinox@diac24.net>
Diffstat (limited to 'python/tiabwarfo.py')
| -rw-r--r-- | python/tiabwarfo.py | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/python/tiabwarfo.py b/python/tiabwarfo.py index bddbeef268..265173e314 100644 --- a/python/tiabwarfo.py +++ b/python/tiabwarfo.py @@ -52,12 +52,14 @@ def extract(filename='lib/.libs/libfrr.so'): pastructs = struct_re.findall(pahole) out = {} - for name, data in pastructs: - this = out.setdefault(name, {}) + for sname, data in pastructs: + this = out.setdefault(sname, {}) fields = this.setdefault('fields', []) lines = data.strip().splitlines() + next_offs = 0 + for line in lines: if line.strip() == '': continue @@ -81,13 +83,16 @@ def extract(filename='lib/.libs/libfrr.so'): data = { 'name': name, 'type': typ_, - 'offset': offs, - 'size': size, + # 'offset': offs, + # 'size': size, } if m.group('array'): data['array'] = int(m.group('array')) fields.append(data) + if offs != next_offs: + raise ValueError('%d padding bytes before struct %s.%s' % (offs - next_offs, sname, name)) + next_offs = offs + size continue raise ValueError('cannot process line: %s' % line) @@ -122,7 +127,7 @@ class FieldApplicator(object): def resolve(self, cls): out = [] - offset = 0 + #offset = 0 fieldrename = getattr(cls, 'fieldrename', {}) def mkname(n): @@ -132,9 +137,12 @@ class FieldApplicator(object): typs = field['type'].split() typs = [i for i in typs if i not in ['const']] - if field['offset'] != offset: - assert offset < field['offset'] - out.append(('_pad', '%ds' % (field['offset'] - offset,))) + # this will break reuse of xrefstructs.json across 32bit & 64bit + # platforms + + #if field['offset'] != offset: + # assert offset < field['offset'] + # out.append(('_pad', '%ds' % (field['offset'] - offset,))) # pretty hacky C types handling, but covers what we need @@ -158,7 +166,7 @@ class FieldApplicator(object): if typs[1] in self.clsmap: packtype = (self.clsmap[typs[1]],) else: - packtype = ('%ds' % field['size'],) + raise ValueError('embedded struct %s not in extracted data' % (typs[1],)) else: raise ValueError('cannot decode field %s in struct %s (%s)' % ( cls.struct, field['name'], field['type'])) @@ -172,7 +180,7 @@ class FieldApplicator(object): else: out.append(mkname(field['name']) + packtype) - offset = field['offset'] + field['size'] + #offset = field['offset'] + field['size'] cls.fields = out |
