如何在gdb断点内单步执行更多命令';s命令

如何在gdb断点内单步执行更多命令';s命令,gdb,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

每当为断点定义命令时,它都无法执行,例如:步骤,否则将不执行以下命令

代码示例:

[/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
它执行
p*x
n
,但不执行
n
之后的命令,即
p*x


这也发生在
c
fin
s

我找到了一条出路,但这是一个解决办法

让我们重新思考一下我正在编写的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
>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) b
Breakpoint 2 at 0x1000061c: file a.c, line 3.
(gdb) command 2
Type commands for breakpoint(s) 2, one per line.
End with a line saying just "end".
>p *x
>end
(gdb) p *x
$2 = 2
(gdb) c
Continuing.

Breakpoint 1, increment (x=0x3ffffffff670) at a.c:2
2         *x = (*x) + 1;
$3 = 2

Breakpoint 2, increment (x=0x3ffffffff670) at a.c:3
3       }
$4 = 3
(gdb)

所以基本上如果我需要在一个
n
s
fin
之后做其他事情的话。。。在此之后,我定义了一个中断,并为这个新断点定义了一个新命令,该命令将执行我想执行的任何操作。

我找到了一个解决方法,但这是一个解决方法

让我们重新思考一下我正在编写的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
>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) b
Breakpoint 2 at 0x1000061c: file a.c, line 3.
(gdb) command 2
Type commands for breakpoint(s) 2, one per line.
End with a line saying just "end".
>p *x
>end
(gdb) p *x
$2 = 2
(gdb) c
Continuing.

Breakpoint 1, increment (x=0x3ffffffff670) at a.c:2
2         *x = (*x) + 1;
$3 = 2

Breakpoint 2, increment (x=0x3ffffffff670) at a.c:3
3       }
$4 = 3
(gdb)
所以基本上如果我需要在一个
n
s
fin
之后做其他事情的话。。。在此之后,我定义了一个中断,并为这个新断点定义了一个新命令,它将执行我想执行的任何操作。

From:
在命令列表中,在命令恢复执行后,任何其他命令都将被忽略。这是因为在任何时候恢复执行(即使是简单的下一步或步骤),您都可能会遇到另一个断点,该断点可能有自己的命令列表,从而导致关于要执行哪个列表的歧义。
tldr;你不能!From:
命令列表中的任何其他命令在命令恢复执行后将被忽略。这是因为在任何时候恢复执行(即使是简单的下一步或步骤),您都可能会遇到另一个断点,该断点可能有自己的命令列表,从而导致关于要执行哪个列表的歧义。
tldr;你不能!