How to print the compilation directory recored in linux elf binary?

Viewed 301

The gdb docs say the compilation directory may be recorded in the executable file https://sourceware.org/gdb/current/onlinedocs/gdb/Source-Path.html

Executable programs sometimes do not record the directories of the source files from which they were compiled, just the names. Even when they do, the directories could be moved between the compilation and your debugging session.

Assuming the executable file records the compilation directory. How to print the compilation directory ?

1 Answers

Like so:

cd /tmp
gcc -g t.c
readelf -Wwi a.out | grep DW_AT_comp_dir

    <15>   DW_AT_comp_dir    : (indirect string, offset: 0x2ab): /tmp
Related