ATLAS Offline Software
Loading...
Searching...
No Matches
offsets.py
Go to the documentation of this file.
1# noqa: ATL902
2# origin: https://github.com/PhilArmstrong/pahole-gdb
3# Original licenced under GPLv3.
4#
5# File: GdbUtils/python/offsets.py
6# Purpose: Dump the offsets of fields in a structure.
7#
8
9import gdb
10
11class Offsets(gdb.Command):
12 """Dump offsets of members in a structure type."""
13
14 def __init__(self):
15 super (Offsets, self).__init__ ('offsets-of', gdb.COMMAND_DATA, gdb.COMPLETE_SYMBOL)
16
17 def invoke(self, arg, from_tty):
18 argv = gdb.string_to_argv(arg)
19 if len(argv) != 1:
20 raise gdb.GdbError('offsets-of takes exactly 1 argument.')
21
22 stype = gdb.lookup_type(argv[0])
23
24 print (argv[0], '{')
25 for field in stype.fields():
26 print (' %s => %d' % (field.name, field.bitpos//8))
27 print ('}')
28
29Offsets()
invoke(self, arg, from_tty)
Definition offsets.py:17