亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何在構建目標之外生成gcc調試符號?

如何在構建目標之外生成gcc調試符號?

如何在構建目標之外生成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}"


查看完整回答
反對 回復 2019-07-31
?
慕尼黑8549860

TA貢獻1818條經驗 獲得超11個贊

查看strip命令的“--only-keep-debug”選項。

從鏈接:

目的是將此選項與--add-gnu-debuglink結合使用以創建兩部分可執行文件。一個剝離的二進制文件占用RAM和分布中較少的空間,第二個是調試信息文件,僅在需要調試功能時才需要。


查看完整回答
反對 回復 2019-07-31
  • 3 回答
  • 0 關注
  • 707 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號