首先构建一个简单的程序:
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从一开始就停止我的程序?
答案 0 :(得分:0)
GDB 8.1添加了一个新的starti
命令,可以解决此问题。与start
相对,main()
在No such file or directory
上设置了一个断点,但不再起作用了。