Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make gcc put relative filenames in debug information

The project I'm compiling uses CMake, which loves absolute pathnames.

When I compile with debugging information enabled, gcc puts those long names into .debug_str sections, which is bad for debugging. I'd like to have short relative-to-project-root pathnames there instead.

Is there some option to tell gcc to strip some part of pathname before emitting debug data? Or, maybe, there is some tool that could do that on compiled binaries?

I've tried using SET(CMAKE_USE_RELATIVE_PATHS ON) (which seems to be frowned upon by devs) option, but as I'm using out-of-source builds, pathnames are still not in the form I'd want them to be. I.e. they're ./../src/mod_foo/foo.c instead of mod_foo/foo.c.

like image 467
drdaeman Avatar asked Mar 07 '12 18:03

drdaeman


1 Answers

You can use the -fdebug-prefix-map flag to remap the debugging information paths. For example, to make the paths relative to the build location use: -fdebug-prefix-map=/full/build/path=.

like image 92
hetman Avatar answered Sep 22 '22 14:09

hetman