Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatic access to old and new values of a watchpoint in gdb

Tags:

What I'm really doing is trying to set a watchpoint on the setting or clearing of a single bit. I do that by setting a watchpoint on the word containing the bit, then making it conditional on *word & mask (for setting, or (~*word) & mask for clearing.)

The problem is that some other bit in the same word may be modified, and the condition may happen to already match. If I had the old and new values, I could set a condition of (($old ^ $new) & mask).

I looked at the python gdb.Breakpoint class, but it doesn't seem to receive this information either.

I suppose I could go crazy and set a command list that records the current value whenever the value of *word changes, and use that as $old. But half the time I'm using this, I'm actually using it through rr, so I might be going backwards.

like image 228
sfink Avatar asked Feb 17 '17 00:02

sfink


1 Answers

There's no direct way to get these values in gdb; it's been a wish-list bug (with your exact case as the example...) for years.. The information is stored in the old_val field of the struct bpstats object associated with the breakpoint; but this is only used to print the old value and not exposed elsewhere.

One option might be to change gdb to expose this value via a convenience variable or via Python.

I suppose I could go crazy and set a command list that records the current value whenever the value of *word changes, and use that as $old. But half the time I'm using this, I'm actually using it through rr, so I might be going backwards.

This seems doable. Your script could check the current execution direction. The main difficulty is remembering to reset the saved value when making this watchpoint, or after disabling and then re-enabling it.

like image 183
Tom Tromey Avatar answered Sep 23 '22 09:09

Tom Tromey