For example, I define a macro:
#ifdef VERSION
//.... do something
#endif
How can I check if VERSION
exist in my object file or not? I tried to disassemble it with objdump
, but found no actual value of my macro VERSION
. VERSION
is defined in 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_macro
矮部分:
$ readelf --debug-dump=macro path/to/binary
要么
$ objdump --dwarf=macro path/to/binary
您还可以使用dwarfdump path/to/binary
,但它并不容易 ,只留下.debug_macro
节中的输出。