【问题标题】:How to step and execute more commands inside a gdb breakpoint's command如何在 gdb 断点的命令中单步执行更多命令
【发布时间】: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 *xn,但没有执行n 之后的命令,即p *x

cfins 也会发生这种情况...

【问题讨论】:

  • 来自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


【解决方案1】:

我找到了出路,但这是一种解决方法....

让我们重新考虑一下我正在编写的 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)

所以基本上如果我需要在nsfin... .

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-11-07
    • 2015-04-13
    • 2020-01-11
    • 1970-01-01
    • 2021-02-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多