[英]Can you extract information from a C executable about which source files it was compiled from?
I have a C executable and would like to know if the executable has any information stored in it about which file(s) it was compiled from and, if so, how to access that information? 我有一个C可执行文件,并想知道可执行文件中是否存有关于编译它的文件的任何信息,如果是,如何访问该信息? I am using RedHat Linux 6.
我正在使用RedHat Linux 6。
If your program has been compiled with debugging information, then yes, it's possible. 如果您的程序已经编译了调试信息,那么是的,这是可能的。
For example, I compiled test.c
with gcc -ggdb3 test.c -o test
例如,我编译
test.c
与gcc -ggdb3 test.c -o test
Then, with gdb ./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:
It entirely depends on the architecture, and whether the executable was compiled in debug mode (or similar). 它完全取决于体系结构,以及可执行文件是否以调试模式(或类似)编译。
For example, UNIX systems embed debug information (including file names) in the executable itself, whereas Windows stores the info in a separate file (ie myprog.exe
has a corresponding myprog.pdb
with all the debug info). 例如,UNIX系统在可执行文件本身中嵌入调试信息(包括文件名),而Windows将信息存储在单独的文件中(即
myprog.exe
具有相应的myprog.pdb
以及所有调试信息)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.