Some Name
Some Name

Reputation: 9521

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.

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.

Is there a way to write such a script (gdb or python)?

Upvotes: 0

Views: 392

Answers (1)

funnydman
funnydman

Reputation: 11326

Before watch *a you may run the program via run.

If not you'll get something like this: No symbol "a" in current context.

So try this:

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

Upvotes: 2

Related Questions