从 ELF 目标文件转储 C 结构大小
如何使用调试符号从 ELF 目标文件中提取所有 C 结构的大小?
可以使用“print sizeof(some_struct)”从 GDB 获取各个结构大小,但我需要的是获取所有结构的列表。
我查看了“nm”和“objdump”,但没有看到执行我正在寻找的操作的选项。有没有办法使用标准 Unix 工具来做到这一点,或者我需要从 ELF 文件中提取调试符号部分并自己处理它?我希望不是后者。
预先感谢您的任何建议。 射线
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
pahole 显示了有关结构的此详细信息和其他详细信息。它的 git 仓库位于 https://git.kernel.org/pub /scm/devel/pahole/pahole.git。
pahole shows this and other details about structs. Its git repo is at https://git.kernel.org/pub/scm/devel/pahole/pahole.git.
你必须挖掘 .debug_info 部分,如果你使用 --dwarf 参数运行它,objdump 将为你转储它。
您将看到您的结构为 *DW_TAG_struct_type* 和 *DW_AT_byte_size* 属性相当于 sizeof。标准 Unix 工具应该足以将这些数据格式化为更可读的列表。
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.
安装 dwarves 软件包,然后你就有了命令“pahole”。
对 elf 目标文件使用“pahole”命令,可以获得所有结构信息,也可以使用“-C”参数指定结构名称,例如:
$ pahole vmlinux -C task_struct
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
除非其他人知道某些事情,否则我认为您将必须处理 nm 的输出。
然而, nm 只给你每个结构的开始,而不知道它的结束,所以即使这样也可能不起作用,除非每个支柱后面紧跟着一些其他符号。注意这个问题!
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!