GDB "start" 命令失败 "Cannot insert breakpoint 1" 和 "Cannot access memory at address"
GDB "start" command fails with "Cannot insert breakpoint 1" and "Cannot access memory at address"
首先构建一个简单的程序:
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 在一开始就停止我的程序?
GDB 8.1 添加了一个新的 starti
命令来解决这个问题。这会在第一条指令处停止程序,而不是 start
,它在 main()
上设置断点但不再工作。
首先构建一个简单的程序:
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 在一开始就停止我的程序?
GDB 8.1 添加了一个新的 starti
命令来解决这个问题。这会在第一条指令处停止程序,而不是 start
,它在 main()
上设置断点但不再工作。