public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
* [Bug breakpoints/30335] New: Watchpoints aren't triggered when calling program functions
@ 2023-04-11 16:15 joe at lothan dot net
  2023-04-11 16:39 ` [Bug breakpoints/30335] " joe at lothan dot net
  0 siblings, 1 reply; 2+ messages in thread
From: joe at lothan dot net @ 2023-04-11 16:15 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=30335

            Bug ID: 30335
           Summary: Watchpoints aren't triggered when calling program
                    functions
           Product: gdb
           Version: HEAD
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: breakpoints
          Assignee: unassigned at sourceware dot org
          Reporter: joe at lothan dot net
  Target Milestone: ---
             Build: Current

When calling program functions using `call` or `print`, existing watchpoints
are not triggered even if the value changes. For example:

$ cat test.c
#include <stdio.h>

int towatch = 0;

void change_var() {
    towatch ++;
    printf("new towatch: %d\n", towatch);
}

int main() {
    for (int i = 0; i < 5; i++)
        change_var();
}
$ gcc -g -o test test.c
$ ./test
new towatch: 1
new towatch: 2
new towatch: 3
new towatch: 4
new towatch: 5
$ gdb ./test
GNU gdb (GDB) 14.0.50.20230411-git
Copyright (C) 2023 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-pc-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from ./test...
(gdb) break main
Breakpoint 1 at 0x118b: file test.c, line 11.
(gdb) run
Starting program: /home/joe/test
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".

Breakpoint 1, main () at test.c:11
11          for (int i = 0; i < 5; i++)
(gdb) watch towatch
Hardware watchpoint 2: towatch
(gdb) p towatch
$1 = 0
(gdb) # I'd expect the watchpoint to trigger with the following call, but it
doesn't
(gdb) call change_var()
new towatch: 1
(gdb) p towatch
$2 = 1
(gdb) continue
Continuing.

Hardware watchpoint 2: towatch

Old value = 0
New value = 2
change_var () at test.c:7
7           printf("new towatch: %d\n", towatch);


This also happens if I pass the `-location` parameter with `watch`: 

$ gdb -q ./test
Reading symbols from ./test...
(gdb) break main
Breakpoint 1 at 0x118b: file test.c, line 11.
(gdb) run
Starting program: /home/joe/test
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".

Breakpoint 1, main () at test.c:11
11          for (int i = 0; i < 5; i++)
(gdb) watch -location towatch
Hardware watchpoint 2: -location towatch
(gdb) call change_var()
new towatch: 1
(gdb)


And when using a software watchpoints: 

$ gdb -q ./test
Reading symbols from ./test...
(gdb) break main
Breakpoint 1 at 0x118b: file test.c, line 11.
(gdb) run
Starting program: /home/joe/test
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".

Breakpoint 1, main () at test.c:11
11          for (int i = 0; i < 5; i++)
(gdb) show can-use-hw-watchpoints
Debugger's willingness to use watchpoint hardware is 1.
(gdb) set can-use-hw-watchpoints 0
(gdb) watch towatch
Watchpoint 2: towatch
(gdb) i breakpoints 2
Num     Type           Disp Enb Address            What
2       watchpoint     keep y                      towatch
(gdb) call change_var()
new towatch: 1
(gdb)

Thanks to tromey and BigKnife for the help in #gdb. First time submitting a bug
in gdb, can provide more info if need be.

Cheers,
Joe

Environment:
gdb version 14.0.50.20230411-git
gdb configuration x86_64-pc-linux-gnu
Ubuntu 22.04.1 LTS
Linux 5.15.0-58-generic
gcc version 11.3.0

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [Bug breakpoints/30335] Watchpoints aren't triggered when calling program functions
  2023-04-11 16:15 [Bug breakpoints/30335] New: Watchpoints aren't triggered when calling program functions joe at lothan dot net
@ 2023-04-11 16:39 ` joe at lothan dot net
  0 siblings, 0 replies; 2+ messages in thread
From: joe at lothan dot net @ 2023-04-11 16:39 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=30335

--- Comment #1 from Joe Lothan <joe at lothan dot net> ---
Forgot to mention that breakpoints do trigger when calling program functions,
it's just watchpoints that do not. And interestingly enough, when a breakpoint
is hit, it allows the watchpoint to be hit later in the program function
execution.

Using the same example: 
$ gdb -q ./test
Reading symbols from ./test...
(gdb) break main
Breakpoint 1 at 0x118b: file test.c, line 11.
(gdb) run
Starting program: /home/joe/test
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".

Breakpoint 1, main () at test.c:11
11          for (int i = 0; i < 5; i++)
(gdb) watch towatch
Hardware watchpoint 2: towatch
(gdb) break change_var
Breakpoint 3 at 0x555555555151: file test.c, line 6.
(gdb) call change_var()

Breakpoint 3, change_var () at test.c:6
6           towatch ++;
The program being debugged stopped while in a function called from GDB.
Evaluation of the expression containing the function
(change_var) will be abandoned.
When the function is done executing, GDB will silently stop.
(gdb) finish
Run till exit from #0  change_var () at test.c:6

Hardware watchpoint 2: towatch

Old value = 0
New value = 1
change_var () at test.c:7
7           printf("new towatch: %d\n", towatch);
(gdb)

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-04-11 16:39 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-11 16:15 [Bug breakpoints/30335] New: Watchpoints aren't triggered when calling program functions joe at lothan dot net
2023-04-11 16:39 ` [Bug breakpoints/30335] " joe at lothan dot net

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).