【发布时间】:2017-03-23 05:34:27
【问题描述】:
每当为断点定义命令时,它都无法执行,例如:步骤,否则以下命令不会执行。
代码示例:
[/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
它执行了p *x 和n,但没有执行n 之后的命令,即p *x。
c、fin、s 也会发生这种情况...
【问题讨论】:
-
来自the user manual:
Any other commands in the command list, after a command that resumes execution, are ignored. This is because any time you resume execution (even with a simple next or step), you may encounter another breakpoint—which could have its own command list, leading to ambiguities about which list to execute.tldr;你不能!
标签: gdb