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

15

我想调试一些程序,我需要得到所有调用某个函数(例如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.

我怎样在脚本中为库调用设置断点?

1个回答

22

改用这个:

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
7
你可以使用 start 代替 break main; run - R Samuel Klatchko
3
在我的系统上,start命令创建了一个断点,所以commands需要使用2而不是1 - doug65536

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接