1

I debug a process with GDB and set watch to break when value in address changed, but it doesn't work!

Here is the initial value:

(gdb) x/s 0x60c010
0x60c010:       "aaaaa"

Set a watch break point

(gdb) watch *0x60c010
Hardware watchpoint 2: *0x60c010
(gdb) commands
Type commands for breakpoint(s) 2, one per line.
End with a line saying just "end".
>echo "changed!!!!"
>end

Check the watch:

(gdb) info breakpoints
Num     Type           Disp Enb Address            What
2       hw watchpoint  keep y                      *0x60c010
        echo "changed!!!!"

Change the value

(gdb) p (void*)memset(0x60c010,'c',5)
$2 = (void *) 0x60c010

Check if value changed

(gdb) x/s 0x60c010
0x60c010:       "ccccc"

The problem that the breakpoint didn't stop the process even I change the value into that address

python3.789
  • 164
  • 9
  • A watchpoint is hit when the target program changes the value at the address, not when you manually edit with gdb. – ssbssa Jun 01 '23 at 04:34
  • 1
    I have to look at it some more, but there is a pair of suspiciously-named functions `disable_watchpoints_before_interactive_call_start` and `enable_watchpoints_after_interactive_call_stop`. – Mark Plotnick Jun 02 '23 at 01:20

0 Answers0