滄海一幻覺
2019-07-31 14:28:48
如何在構(gòu)建目標(biāo)之外生成gcc調(diào)試符號(hào)?我知道我可以使用-g選項(xiàng)生成調(diào)試符號(hào)。但是,符號(hào)將嵌入目標(biāo)文件中。gcc可以在結(jié)果可執(zhí)行文件/庫(kù)之外生成調(diào)試符號(hào)嗎?像Windows VC ++編譯器的.pdb文件一樣。
3 回答

慕沐林林
TA貢獻(xiàn)2016條經(jīng)驗(yàn) 獲得超9個(gè)贊
您需要使用objcopy來分隔調(diào)試信息:
objcopy --only-keep-debug "${tostripfile}" "${debugdir}/${debugfile}"strip --strip-debug --strip-unneeded "${tostripfile}"objcopy --add-gnu-debuglink="${debugdir}/${debugfile}" "${tostripfile}"
我使用下面的bash腳本將調(diào)試信息分離為.debug目錄中帶有.debug擴(kuò)展名的文件。這樣我可以在一個(gè)tar文件和另一個(gè)tar文件中的.debug目錄中tar和庫(kù)和可執(zhí)行文件。如果我想稍后添加調(diào)試信息,我只需提取調(diào)試tar文件,瞧我有符號(hào)調(diào)試信息。
這是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貢獻(xiàn)1818條經(jīng)驗(yàn) 獲得超11個(gè)贊
查看strip命令的“--only-keep-debug”選項(xiàng)。
從鏈接:
目的是將此選項(xiàng)與--add-gnu-debuglink結(jié)合使用以創(chuàng)建兩部分可執(zhí)行文件。一個(gè)剝離的二進(jìn)制文件占用RAM和分布中較少的空間,第二個(gè)是調(diào)試信息文件,僅在需要調(diào)試功能時(shí)才需要。
添加回答
舉報(bào)
0/150
提交
取消