2010-03-05 44 views
11

我想調試一些程序。我需要從某些功能的所有呼叫回溯,例如放。自動化gdb:在每次調用函數時顯示backtrace puts

現在我用這樣的GDB script

set width 0 
set height 0 
set verbose off 
break puts 
commands 1 
backtrace 
continue 
end 

但隨着

gdb --batch --command=script --args ./some_program arguments 

開始它給出了一個錯誤:

Function "puts" not defined. 
Make breakpoint pending on future shared library load? (y or [n]) [answered N; input not from terminal] 
/root/script:5: Error in sourced command file: 
No breakpoint number 1. 

我如何爲庫調用設置斷點腳本?

回答

18

試試這個:

set width 0 
set height 0 
set verbose off 
start # runs to main, so shared libraries are loaded 
     # after you reach main, GDB should have libc symbols, "puts" among them 
break puts 
commands 1 
backtrace 
continue 
end 

如果這不起作用,請註明操作系統版本。

編輯:作爲osgx正確地指出,另一種方法是添加

set breakpoint pending on 

break puts

+1

又是怎麼回事 「斷點掛起」 的設置? Аеще - спасибо。 – osgx

+6

您可以使用'start'而不是'break main;運行' –

+0

是的,'開始'更好。回答固定,謝謝! –

相關問題