Question

How to find if debug information contains relative paths or absolute paths?

I am trying to Outputting annotated source (opannotate) using the following link. http://oprofile.sourceforge.net/doc/opannotate.html

I would like to know about it in order to give the following options along with opannotate.

--base-dirs / -b [paths]/ Comma-separated list of path prefixes. This can be used to point OProfile to a different location for source files when the debug information specifies an absolute path on your system for the source that does not exist. The prefix is stripped from the debug source file paths, then searched in the search dirs specified by --search-dirs.

--search-dirs / -d [paths] Comma-separated list of paths to search for source files. This is useful to find source files when the debug information only contains relative paths.

Thanks.

Was it helpful?

Solution

If the C_FLAGS during compilation contain the -g parameter, then all the paths of individual source files are included in the .debug_info section in the resulting binary executable.

The following command will dump to the console, a complete list of all the paths to various .c source files that are present in the binary built with debug-info.

$ readelf --debug-dump=info <binary-executable> | grep "\.c" | awk '{print $8}'

To search for the path of a particular source-file within the debug-info of the binary, one can modify the grep "\.c" to grep "<filename>" as appropriate.

For more details, checkout this excellent article on debug-info in binaries.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top