GDB“启动”命令失败,并显示“无法插入断点1”和“无法访问地址处的内存”

时间:2019-05-08 01:34:25

标签: debugging gdb breakpoints ubuntu-18.04

首先构建一个简单的程序:

g++ -g -xc++ - <<< 'int main() {throw "hi";}'

这会产生a.out,在运行时会故意崩溃。尝试对其进行调试:

gdb -batch -ex start -ex continue ./a.out

预期的输出是这样的:

Temporary breakpoint 1, main () at <stdin>:1
1   <stdin>: No such file or directory.
terminate called after throwing an instance of 'char const*'

Program received signal SIGABRT, Aborted.
0x00007ffff71ad1f7 in raise () from /lib64/libc.so.6

但是在Ubuntu 18.04(具有GDB 8.1)上,会显示警告,并且start命令失败:

Warning:
Cannot insert breakpoint 1.
Cannot access memory at address 0x4005c7

Command aborted.

如何告诉GDB从一开始就停止我的程序?

1 个答案:

答案 0 :(得分:0)

GDB 8.1添加了一个新的starti命令,可以解决此问题。与start相对,main()No such file or directory上设置了一个断点,但不再起作用了。