今天發(fā)現(xiàn)項(xiàng)目里的Makefile在debug和release版本之間有兩行不一樣的地方:
@objcopy --only-keep-debug bin/Release/Server bin/Release/Server.symbol
@objcopy --strip-debug bin/Release/Server
在這兩行之前都是調(diào)用子目錄里的Makefile來生成Server二進(jìn)制文件掺炭,這兩行我不知道是什么意思辫诅,于是man了一下objcopy凭戴,發(fā)現(xiàn)手冊(cè)里是這樣解釋的:
objcopy - copy and translate object files.
--strip-debug
Do not copy debugging symbols or sections from the source file.
不從源文件中拷貝調(diào)試符號(hào)或段。
--only-keep-debug
Strip a file, removing contents of any sections that would not be stripped by --strip-debug and leaving the debugging sections intact.
這個(gè)正好與--strip-debug相反炕矮,是從文件中抽離--strip-debug所剩下的內(nèi)容么夫,也就是留下完整的調(diào)試信息。
這樣處理之后肤视,就將原來的Server文件一分為二档痪,產(chǎn)生了一個(gè)沒有調(diào)試信息的文件Server和一個(gè)只有調(diào)試信息的Server.symbol,Server文件明顯變小了邢滑。
那么symbol文件如何使用呢腐螟?假如我們運(yùn)行這個(gè)Server程序時(shí)因?yàn)槟撤N原因宕掉了,需要用gdb來調(diào)試困后。因?yàn)镾erver本身不包含任何debug信息乐纸,這時(shí)候就需要加載symbol文件。
可以在gdb啟動(dòng)時(shí)制定symbol文件:
$ gdb -s Server.symbol -e Server -c core
也可以在gdb運(yùn)行過程中加載:
$gdb Server core
#(這里中間略去gdb啟動(dòng)的信息)
(gdb) symbol-file Server.symbol
這樣就可以用symbol文件來進(jìn)行調(diào)試了摇予。