Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/extjs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/gwt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何检查C中的对象文件中是否存在宏?_C_Object Files - Fatal编程技术网

如何检查C中的对象文件中是否存在宏?

如何检查C中的对象文件中是否存在宏?,c,object-files,C,Object Files,例如,我定义了一个宏: #ifdef VERSION //.... do something #endif 如何检查对象文件中是否存在VERSION?我试图用objdump反汇编它,但没有发现我的宏版本的实际值版本在Makefile中定义。尝试使用gcc中的-g3选项进行编译。它还将宏信息存储在生成的ELF文件中 在此之后,如果您已经在输出可执行文件或对象文件中为其定义了一个宏macro\u NAME。比如说, $ grep MACRO_NAME a.out # any object fil

例如,我定义了一个宏:

#ifdef VERSION
 //.... do something
#endif

如何检查对象文件中是否存在
VERSION
?我试图用
objdump
反汇编它,但没有发现我的宏
版本的实际值<代码>版本在Makefile中定义。

尝试使用
gcc
中的
-g3
选项进行编译。它还将宏信息存储在生成的ELF文件中

在此之后,如果您已经在输出可执行文件或对象文件中为其定义了一个宏
macro\u NAME
。比如说,

$ 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.

尝试使用
gcc
中的
-g3
选项进行编译。它还将宏信息存储在生成的ELF文件中

在此之后,如果您已经在输出可执行文件或对象文件中为其定义了一个宏
macro\u NAME
。比如说,

$ 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\u宏
DWARF部分的内容:

$ readelf --debug-dump=macro path/to/binary


您也可以使用
dwarfdump path/to/binary
,但只能在输出中保留
.debug\u macro
部分。以下命令显示
.debug\u macro
DWARF部分的内容:

$ readelf --debug-dump=macro path/to/binary


您也可以使用
dwarfdump path/to/binary
,但只在输出中保留
.debug\u macro
部分。

+1表示
-g3
…-为了在二进制文件中找到宏,我更喜欢
strings | grep
@alk。我尝试了字符串版本,但是
宏\u名称
嵌入到目标文件中,以至于
字符串
没有将其视为字符串,grep失败了。我刚刚测试了这个,似乎你是对的。需要调查这件事。。。出去挖好了,明白了…-使用:
strings-a | grep
,它可以工作。请参见
人字串
。@哎呀,不知怎的,我昏昏欲睡的头脑无法识别打字错误。帮助:)+1表示
-g3
…-为了在二进制文件中找到宏,我更喜欢
strings | grep
@alk。我尝试了字符串版本,但是
宏\u名称
嵌入到目标文件中,以至于
字符串
没有将其视为字符串,grep失败了。我刚刚测试了这个,似乎你是对的。需要调查这件事。。。出去挖好了,明白了…-使用:
strings-a | grep
,它可以工作。请参见
人字串
。@哎呀,不知怎的,我昏昏欲睡的头脑无法识别打字错误。帮助:)