如何检查C中的目标文件中是否存在宏?
例如,我定义了一个宏:
#ifdef VERSION //.... do something #endif
如何检查目标文件中是否存在VERSION
? 我试图用objdump
反汇编它,但没有找到我的宏VERSION
实际值。 VERSION
在Makefile中定义。
尝试在gcc
使用-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_macro
DWARF部分的内容:
$ readelf --debug-dump=macro path/to/binary
要么
$ objdump --dwarf=macro path/to/binary
你也可以使用dwarfdump path/to/binary
,但是在输出中只留下.debug_macro
部分并不容易 。