dumping C structure sizes from ELF object file

前端 未结 4 1929
佛祖请我去吃肉
佛祖请我去吃肉 2021-02-01 09:16

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(s

相关标签:
4条回答
  • 2021-02-01 09:28

    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.

    0 讨论(0)
  • 2021-02-01 09:32

    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

    0 讨论(0)
  • 2021-02-01 09:35

    Unless someone else known something, I think you will have to process the output of nm .

    However, nm only gives you the start of each struct and knows nothing about its end so even that may not work unless each strut is immediately followed by some other symbol. Watch out for this issue!

    0 讨论(0)
  • 2021-02-01 09:49

    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.

    0 讨论(0)
提交回复
热议问题