例如,我定义了一个宏:
#ifdef VERSION
 //.... do something
#endif
如何检查VERSION我的目标文件中是否存在?我试图用 反汇编它objdump,但没有发现我的宏的实际值VERSION。VERSION在 Makefile 中定义。
例如,我定义了一个宏:
#ifdef VERSION
 //.... do something
#endif
如何检查VERSION我的目标文件中是否存在?我试图用 反汇编它objdump,但没有发现我的宏的实际值VERSION。VERSION在 Makefile 中定义。
尝试使用中的-g3选项进行编译gcc。它也将宏信息存储在生成的 ELF 文件中。
在此之后,如果您在输出可执行文件或目标文件中为它定义MACRO_NAME了一个宏。grep例如,
$ grep MACRO_NAME a.out # any object file will do instead of a.out
Binary file a.out matches
或者你甚至可以尝试,
$ strings -a -n 1 a.out | grep MACRO_NAME
 -a Do not scan only the initialized and loaded sections of object files; 
    scan the whole files.
 -n min-len Print sequences of characters that are at least min-len characters long,
    instead of the default 4.
以下命令显示.debug_macroDWARF 部分的内容:
$ readelf --debug-dump=macro path/to/binary
或者
$ objdump --dwarf=macro path/to/binary
您也可以使用dwarfdump path/to/binary,但在输出中只保留部分并不容易。.debug_macro