Search This Blog

Thursday, November 19, 2009

Size of all structures in your program

There are some cases when you want to find size of all structures in your program/project. For a given program it is easy because we can manually calculate or put a printf sizeof() to calculate a few structures. But for a project with few hundred files it is difficult. There is noway AFAIK in gcc to dump all the structure sizes while it compiles.

Here is a way todo it using dwarf debugging info if you are using gnu compiler tools. Compile your project output file with -g option, this will generate debugging information in your program. Then run objdump to dump the debug info. This debugging information contains all the information about your program, filter the output for "DW_TAG_structure_type" and you will get only structure information.

Here is how I did it:

objdump -W kernel.debug.reloc >

grep -e "DW_TAG_structure_type" --after-context=5 --mmap > structs.txt