linux - CMake save stripped debug information -


it's usual practice compile debug symbols , separate binary using objcopy release executable , file debug information (then wrap separate packages or store on symbol server).

how separate debug symbols in cmake? i've seen discussions , incomplete code samples.

platform linux , gcc.

cmake doesn't have direct support this, can use post_build , install steps achieve result want. is, however, worth noting using objcopy isn't way sort of thing. can make use of build-id , may easier implement robustly cmake.

rather repeat whole thing here, there's pretty description of choices , methods posted cmake mailing list few years ago michael hertling. i'll pick out working alternative here reference, recommend reading link. there's more complete discussion of 2 alternatives in gdb documentation should fill in remaining blanks 2 approaches (debug link versus build-id). here's michael's general build-id approach (the build-id explicitly given in example, read referenced articles explanation of expected represent):

cmake_minimum_required(version 2.8 fatal_error) project(buildid c) set(cmake_verbose_makefile on) set(buildid "abcdef1234") string(substring "${buildid}" 0 2 buildidprefix) string(substring "${buildid}" 2 8 buildidsuffix) file(write ${cmake_binary_dir}/main.c "int main(void){return 0;}\n") add_executable(main main.c) set_target_properties(main properties     link_flags "-wl,--build-id=0x${buildid}") add_custom_command(target main post_build     command ${cmake_command} -e copy $<target_file:main>                                      ${cmake_binary_dir}/main.debug     command ${cmake_strip} -g $<target_file:main>) install(files ${cmake_binary_dir}/main.debug     destination ${cmake_binary_dir}/.build-id/${buildidprefix}     rename ${buildidsuffix}.debug) 

configure cmake_build_type==debug , build; subsequently, invoke

gdb -ex "set debug-file-directory ." -ex "file main"

from within cmake_binary_dir, , read "no debugging symbols found" expected. now, issue "make install", re-invoke gdb , read:

"reading symbols .../.build-id/ab/cdef1234.debug"

as can see, debug info file connected stripped executable solely build id; no objcopy in sight.

the above makes use of fact .debug file expected normal executable debug info not stripped.


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -