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 | |
parent | lib: get rid of padding in struct cmd_element (diff) | |
download | frr-a971f0718d25eb9bc553e774bd19a2276e26072e.tar.xz frr-a971f0718d25eb9bc553e774bd19a2276e26072e.zip |
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')
-rw-r--r-- | python/tiabwarfo.py | 28 | ||||
-rw-r--r-- | python/xrefstructs.json | 58 |
2 files changed, 19 insertions, 67 deletions
diff --git a/python/tiabwarfo.py b/python/tiabwarfo.py index bddbeef26..265173e31 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 diff --git a/python/xrefstructs.json b/python/xrefstructs.json index e62c351bc..25c48c9d5 100644 --- a/python/xrefstructs.json +++ b/python/xrefstructs.json @@ -3,44 +3,30 @@ "fields": [ { "name": "string", - "offset": 0, - "size": 8, "type": "const char *" }, { "name": "doc", - "offset": 8, - "size": 8, "type": "const char *" }, { "name": "daemon", - "offset": 16, - "size": 4, "type": "int" }, { "name": "attr", - "offset": 20, - "size": 1, - "type": "uint8_t" + "type": "uint32_t" }, { "name": "func", - "offset": 24, - "size": 8, "type": "int *" }, { "name": "name", - "offset": 32, - "size": 8, "type": "const char *" }, { "name": "xref", - "offset": 40, - "size": 32, "type": "struct xref" } ] @@ -49,32 +35,22 @@ "fields": [ { "name": "xrefdata", - "offset": 0, - "size": 8, "type": "struct xrefdata *" }, { "name": "type", - "offset": 8, - "size": 4, "type": "enum xref_type" }, { "name": "line", - "offset": 12, - "size": 4, "type": "int" }, { "name": "file", - "offset": 16, - "size": 8, "type": "const char *" }, { "name": "func", - "offset": 24, - "size": 8, "type": "const char *" } ] @@ -83,20 +59,14 @@ "fields": [ { "name": "xref", - "offset": 0, - "size": 32, "type": "struct xref" }, { "name": "cmd_element", - "offset": 32, - "size": 8, "type": "const struct cmd_element *" }, { "name": "node_type", - "offset": 40, - "size": 4, "type": "enum node_type" } ] @@ -105,32 +75,22 @@ "fields": [ { "name": "xref", - "offset": 0, - "size": 32, "type": "struct xref" }, { "name": "fmtstring", - "offset": 32, - "size": 8, "type": "const char *" }, { "name": "priority", - "offset": 40, - "size": 4, "type": "uint32_t" }, { "name": "ec", - "offset": 44, - "size": 4, "type": "uint32_t" }, { "name": "args", - "offset": 48, - "size": 8, "type": "const char *" } ] @@ -139,26 +99,18 @@ "fields": [ { "name": "xref", - "offset": 0, - "size": 32, "type": "struct xref" }, { "name": "funcname", - "offset": 32, - "size": 8, "type": "const char *" }, { "name": "dest", - "offset": 40, - "size": 8, "type": "const char *" }, { "name": "thread_type", - "offset": 48, - "size": 4, "type": "uint32_t" } ] @@ -167,28 +119,20 @@ "fields": [ { "name": "xref", - "offset": 0, - "size": 8, "type": "const struct xref *" }, { "array": 16, "name": "uid", - "offset": 8, - "size": 16, "type": "char" }, { "name": "hashstr", - "offset": 24, - "size": 8, "type": "const char *" }, { "array": 2, "name": "hashu32", - "offset": 32, - "size": 8, "type": "uint32_t" } ] |