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

osg*_*sgx 12 gdb

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

现在我使用这样的gdb script:

set width 0
set height 0
set verbose off
break puts
commands 1
backtrace
continue
end
Run Code Online (Sandbox Code Playgroud)

但是开始吧

gdb --batch --command=script --args ./some_program arguments
Run Code Online (Sandbox Code Playgroud)

给出错误:

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.
Run Code Online (Sandbox Code Playgroud)

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

Emp*_*ian 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
Run Code Online (Sandbox Code Playgroud)

如果这不起作用,请说明操作系统版本.

编辑:正如osgx正确指出的那样,另一种选择是添加

set breakpoint pending on
Run Code Online (Sandbox Code Playgroud)

之前 break puts

  • 您可以使用`start`而不是`break main; run` (7认同)
  • 在我的系统上,`start`命令创建了一个断点,因此`命令`需要`2`而不是`1`. (2认同)