0

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? I am using RedHat Linux 6.

1
  • What have you tried so far? I'd use strings and ldd and a bit of guesswork meself Commented Nov 15, 2013 at 20:20

2 Answers 2

1

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

Then, with 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: 
Sign up to request clarification or add additional context in comments.

Comments

1

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 (i.e. myprog.exe has a corresponding myprog.pdb with all the debug info).

1 Comment

In that case, it probably doesn't have any of the source filenames in it.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.