自动化gdb:在每次调用函数put时显示回溯

时间:2010-03-05 17:51:54

标签: gdb

我想调试一些程序。我需要从一些函数的所有调用中回溯,例如放。

现在我使用这样的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.

如何在脚本中为库调用设置断点?

1 个答案:

答案 0 :(得分:19)

请改为尝试:

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