如何在構建目標之外生成gcc調試符號?我知道我可以使用-g選項生成調試符號。但是,符號將嵌入目標文件中。gcc可以在結果可執行文件/庫之外生成調試符號嗎?像Windows VC ++編譯器的.pdb文件一樣。
3 回答

慕沐林林
TA貢獻2016條經驗 獲得超9個贊
您需要使用objcopy來分隔調試信息:
objcopy --only-keep-debug "${tostripfile}" "${debugdir}/${debugfile}"strip --strip-debug --strip-unneeded "${tostripfile}"objcopy --add-gnu-debuglink="${debugdir}/${debugfile}" "${tostripfile}"
我使用下面的bash腳本將調試信息分離為.debug目錄中帶有.debug擴展名的文件。這樣我可以在一個tar文件和另一個tar文件中的.debug目錄中tar和庫和可執行文件。如果我想稍后添加調試信息,我只需提取調試tar文件,瞧我有符號調試信息。
這是bash腳本:
#!/bin/bashscriptdir=`dirname ${0}`scriptdir=`(cd ${scriptdir}; pwd)`scriptname=`basename ${0}`set -e function errorexit(){ errorcode=${1} shift echo $@ exit ${errorcode}}function usage(){ echo "USAGE ${scriptname} <tostrip>"}tostripdir=`dirname "$1"`tostripfile=`basename "$1"`if [ -z ${tostripfile} ] ; then usage errorexit 0 "tostrip must be specified"fi cd "${tostripdir}"debugdir=.debug debugfile="${tostripfile}.debug"if [ ! -d "${debugdir}" ] ; then echo "creating dir ${tostripdir}/${debugdir}" mkdir -p "${debugdir}"fi echo "stripping ${tostripfile}, putting debug info into ${debugfile}"objcopy --only-keep-debug "${tostripfile}" "${debugdir}/${debugfile}"strip --strip-debug --strip-unneeded "${tostripfile}"objcopy --add-gnu-debuglink="${debugdir}/${debugfile}" "${tostripfile}"chmod -x "${debugdir}/${debugfile}"

慕尼黑8549860
TA貢獻1818條經驗 獲得超11個贊
查看strip命令的“--only-keep-debug”選項。
從鏈接:
目的是將此選項與--add-gnu-debuglink結合使用以創建兩部分可執行文件。一個剝離的二進制文件占用RAM和分布中較少的空間,第二個是調試信息文件,僅在需要調試功能時才需要。
添加回答
舉報
0/150
提交
取消