问题
I want to get the source code path && source names just through the ELF file, the .debug_str section contains what i need, but how can i filter them out?
回答1:
I suggest to use this command and tools like sed or grep.
$ readelf --string-dump=.debug_str YOUR_PROGRAM
this show path and source file name:
$ readelf --string-dump=.debug_str YOUR_PROGRAM | sed -n '/\/\|\.c/{s/.*\] //p}'
回答2:
$ readelf --string-dump=.debug_str YOUR_PROGRAM
works fine.
However, make sure your_program is not stripped by using command
file YOUR_PROGRAM
回答3:
There is another way:
readelf --syms YOUR-PROGGRAM |tee /tmp/log
vim /tmp/log
:vim "FILE" %
You will get all file names, however without path.
回答4:
readelf
holds the key, but you don't want to dump strings willy-nilly. Use the -wi
option to properly format the info.
For example, create a shell script thus:
readelf -wi $1 | grep -B1 DW_AT_comp_dir | \
awk '/DW_AT_name/{name = $NF; getline; print $NF"/"name}'
which further summarizes the output of readelf -wi
.
来源:https://stackoverflow.com/questions/31333337/how-can-i-get-the-source-code-path-file-names-from-an-elf-filecompired-with