从编译的二进制文件中获取宏值(带调试)
我需要确定编译二进制文件时使用的特定宏的值。
该文件是Linux共享库文件。
是否可以?
I need to determine the value of a specific macro the binary was compiled with.
The file is a Linux shared library file.
Is it possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
鉴于宏是由预处理器处理的,甚至实际的编译器也不知道它们。唯一的选择是对 cod 进行逆向工程,找到您知道使用宏的位置并从那里提取值。
编辑:我刚刚检查了 DWARF 规范,该标准定义了
.debug_macinfo
部分,专门用于存储有关宏的调试信息,该部分包含一个DW_MACINFO_define
记录每个定义的宏。因此,如果您有该库的调试版本,您可以尝试使用 dwarfdump -m 或 readelf --debug-dump=macro 来提取此信息。
但是:我已经在系统中的几个库上进行了尝试,但它们都不包含任何宏记录。默认情况下,
gcc
不会发出它们,必须使用gcc -g3
编译该库(该开关会增加调试信息级别)。我想这对你来说是个坏消息。Given that macros are handled by a preprocessor, even the actual compiler is not aware of them. The only option is to reverse engineer the cod, find the place where you know the macro is used and extract the value from there.
Edit: I've just checked DWARF specification, the standard defines
.debug_macinfo
section especially to store debug info about macros, this section contains aDW_MACINFO_define
record for each defined macro.So, if you have a debug version of the library, you can try to use
dwarfdump -m
orreadelf --debug-dump=macro
to extract this info.However: I've tried it on a few libraries in my system, and none of them contained any macro records. By default
gcc
doesn't emit them, the library has to be compiled withgcc -g3
(the switch increases the debug info level). This is sort of bad news for you, I suppose.