简体   繁体   English

GDB在观察点被击中后执行下一条指令

[英]GDB execute next instruction after watchpoint is hit

I have a function of the following form: 我具有以下形式的功能:

void foo(){
    int *a = //...
    *a = 1;
    //some actions
    *a = 2;
    //some actions
    *a = 3;
    //some actions
    //etc...
}

I want to set a watchpoint on a , execute next instruction with si , print registers and then continue until the watchpoint of a is hit again and repeat that. 我想设置一个观察点上a ,用下一个指令si ,打印寄存器,然后一直持续到观察点a被再次命中和重复。

I wrote the following script: 我写了以下脚本:

b foo
watch *a
commands
    si
    info reg
    cont
end
cont

The problem is it stops after the first watchpoint is hit and neither prints registers and nor continues execution. 问题在于它在第一个观察点被击中后停止,既不打印寄存器也不继续执行。 As I read in docs 正如我在文档中阅读的

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. 这是因为任何时候恢复执行(即使是简单的下一步或步骤),都可能会遇到另一个断点,该断点可能具有自己的命令列表,这导致要执行的列表含糊不清。

everything after si is simply ignored. si之后的所有内容都将被忽略。

Is there a way to write such a script ( gdb or python )? 有没有办法编写这样的脚本( gdbpython )?

Before watch *a you may run the program via run . watch *a之前,您可以通过run运行程序。

If not you'll get something like this: No symbol "a" in current context. 如果没有,您将得到如下信息: No symbol "a" in current context.

So try this: 所以试试这个:

b foo
run
watch *a
commands
    si
    info reg
    cont
end
cont

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM