Bug 21969

Summary: watchpoint break not triggered on reverse continue
Product: gdb Reporter: jfhart085
Component: breakpointsAssignee: Not yet assigned to anyone <unassigned>
Status: RESOLVED FIXED    
Severity: normal CC: simark, ssbssa
Priority: P2    
Version: 7.10   
Target Milestone: 15.1   
Host: Target:
Build: Last reconfirmed: 2017-09-03 00:00:00
Attachments: utl1.c - test program with deliberate stack overwrite

Description jfhart085 2017-08-18 02:12:00 UTC
Created attachment 10351 [details]
utl1.c - test program with deliberate stack overwrite

bash-3.2$ uname -a
Linux DellXPS 4.10.0 #1 SMP Thu Apr 13 09:55:54 EDT 2017 x86_64 GNU/Linux

build utl1.c as follows: 
gcc -Wall -Wno-unused-but-set-variable -g utl1.c -o0 -o utl1

# forward continue - watch break triggered
gdb utl1
c-x 2
b *main    # break on 1st main() instruction
run
record
watch -l *((long *)$sp)
continue

# reverse continue - watch break not triggered
gdb utl1
c-x 2
b *main    # break on 1st main() instruction
b *main+41 # break on retq instruction
run
record
continue
watch -l *((long *)$sp)
reverse-continue
Comment 1 Simon Marchi 2017-09-03 17:51:56 UTC
Thanks for reporting.  I see the same behavior, hardware watchpoints don't trigger in reverse execution or in replay.  As a workaround, you can use "set can-use-hw-watchpoints 0" to force the use of software watchpoints.
Comment 2 Sourceware Commits 2023-12-06 12:47:43 UTC
The master branch has been updated by Hannes Domani <ssbssa@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=288363c1737f93e2f7cb8c06026c11a5ff77fb58

commit 288363c1737f93e2f7cb8c06026c11a5ff77fb58
Author: Hannes Domani <ssbssa@yahoo.de>
Date:   Wed Dec 6 13:45:51 2023 +0100

    Fix hardware watchpoints in replay mode
    
    Changes introduced by commit 9e8915c6cee5c37637521b424d723e990e06d597
    caused a regression that meant hardware watchpoint stops would not
    trigger in reverse execution or replay mode.  This was documented in
    PR breakpoints/21969.
    The problem is that record_check_stopped_by_breakpoint always overwrites
    record_full_stop_reason, thus loosing the TARGET_STOPPED_BY_WATCHPOINT
    value which would be checked afterwards.
    
    This commit fixes that by not overwriting the stop-reason in
    record_full_stop_reason if we're not stopped at a breakpoint.
    
    And the test for hw watchpoints in gdb.reverse/watch-reverse.exp actually
    tested sw watchpoints again, since "set can-use-hw-watchpoints 1"
    doesn't convert enabled watchpoints to use hardware.
    This is fixed by disabling said watchpoint while enabling hw watchpoints.
    The same is not done for gdb.reverse/watch-precsave.exp, since it's not
    possible to use hw watchpoints in restored recordings anyways.
    
    Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=21969
    Approved-by: Guinevere Larsen <blarsen@redhat.com>
Comment 3 Hannes Domani 2023-12-06 12:48:40 UTC
Fixed.