【发布时间】:2013-11-15 20:17:16
【问题描述】:
我有一个 C 可执行文件,并且想知道该可执行文件中是否存储了关于它是从哪个文件编译而来的任何信息,如果有,如何访问该信息?我正在使用 RedHat Linux 6。
【问题讨论】:
-
到目前为止您尝试过什么?我会使用
strings和ldd并自己进行一些猜测
标签: c executable
我有一个 C 可执行文件,并且想知道该可执行文件中是否存储了关于它是从哪个文件编译而来的任何信息,如果有,如何访问该信息?我正在使用 RedHat Linux 6。
【问题讨论】:
strings 和 ldd 并自己进行一些猜测
标签: c executable
如果你的程序已经编译了调试信息,那么是的,这是可能的。
比如我把test.c编译成gcc -ggdb3 test.c -o test
然后,gdb ./test:
(gdb) info functions
All defined functions:
File main.c:
int main(int, char **);
Non-debugging symbols:
0x0000000000400370 _init
0x00000000004003a0 __libc_start_main@plt
0x00000000004003b0 __gmon_start__@plt
0x00000000004003c0 _start
0x00000000004003f0 deregister_tm_clones
0x0000000000400420 register_tm_clones
0x0000000000400460 __do_global_dtors_aux
0x0000000000400480 frame_dummy
0x00000000004004d0 __libc_csu_init
0x0000000000400540 __libc_csu_fini
0x0000000000400544 _fini
(gdb) info sources
Source files for which symbols have been read in:
/home/john/Projects/test/main.c, /usr/include/bits/sys_errlist.h, ...
Source files for which symbols will be read in on demand:
【讨论】:
这完全取决于架构,以及可执行文件是否以调试模式(或类似模式)编译。
例如,UNIX 系统将调试信息(包括文件名)嵌入到可执行文件本身中,而 Windows 将信息存储在单独的文件中(即 myprog.exe 具有对应的 myprog.pdb 与所有调试信息)。
【讨论】: