1
无论何时为断点定义命令,都无法执行例如:步骤,否则以下命令不会执行。如何在gdb断点的命令中执行和执行更多命令
代码例如:
[/tmp]$ cat a.c
void increment(int* x) {
*x = (*x) + 1;
}
int main() {
int a = 1;
for (int i = 0; i < 10; i++)
increment(&a);
return 0;
}
[/tmp]$ gcc --std=c99 a.c -O0 -g
[/tmp]$ gdb a.out
GDB:
(gdb) b increment
Breakpoint 1 at 0x10000600: file a.c, line 2.
(gdb) command 1
Type commands for breakpoint(s) 1, one per line.
End with a line saying just "end".
>p *x
>n
>p *x
>end
(gdb) r
Starting program: /tmp/a.out
Breakpoint 1, increment (x=0x3ffffffff670) at a.c:2
2 *x = (*x) + 1;
$1 = 1
3 }
(gdb) p *x
$2 = 2
它n
那是p *x
之后执行的p *x
和n
,但不是该命令。
这也恰好与c
,fin
,s
...
从[用户手册](https://sourceware.org/gdb/current/onlinedocs/gdb/Break-Commands.html#Break-Commands): '命令列表中的任何其他命令,在命令恢复执行,将被忽略。这是因为任何时候你恢复执行(即使是简单的下一步或步骤),你都可能遇到另一个断点 - 它可能有自己的命令列表,导致关于执行哪个列表的含糊不清。你不能! – gut