dumping C structure sizes from ELF object file
Solution 1
pahole shows this and other details about structs. Its git repo is at http://www.kernel.org/git/?p=linux/kernel/git/acme/pahole.git;a=summary.
Solution 2
You will have to dig in .debug_info section, objdump will dump it for you if you run it with --dwarf parameter.
You will see your structures there as *DW_TAG_structure_type* and *DW_AT_byte_size* attribute is equivalent to sizeof. Standard Unix tool should be enough to format this data into more readable list.
Solution 3
Install package dwarves, then you have the command "pahole".
Use the "pahole" command against a elf object file, you can get all the structure information, or you can use the "-C" parameter to specific a structure name, for example:
$ pahole vmlinux -C task_struct
Related videos on Youtube
Ray Balogh
Updated on July 10, 2020Comments
-
Ray Balogh almost 4 years
How can you extract the sizes of all C structures from an ELF object file with debugging symbols?
Individual struct sizes can be obtained from GDB using "print sizeof(some_struct)", but what I need is to get a listing of all structures.
I've looked at "nm" and "objdump", but I don't see options to do what I'm looking for. Is there a way to do this with standard Unix tools, or do I need to extract the debug symbol section from the ELF file and process it myself? I'm hoping it's not the latter.
Thanks in advance for any advice. Ray
-
Ray Balogh about 13 yearsThanks a lot -- this works really well. Now I just need to write a Perl script to process the output.
-
Ray Balogh about 13 yearsThanks for the reply, but I can't get nm to list any types (i.e. structs), only symbols with addresses.
-
Ray Balogh about 13 yearsThanks for the help. I'll take a look at pahole.
-
sigjuice about 13 years@Ray Balogh You might be interested in pstruct, a Perl script which does something similar. perldoc.perl.org/pstruct.html
-
Jian Zhang over 7 yearsit's very useful, awesome!