]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commit
Fix setting watchpoints when current thread is running
authorPedro Alves <pedro@palves.net>
Tue, 2 May 2023 14:04:28 +0000 (15:04 +0100)
committerPedro Alves <pedro@palves.net>
Fri, 12 Apr 2024 17:54:08 +0000 (18:54 +0100)
commitc223d3738832011ced54e8415fa218934aebd0e4
treed3b9fe1cadd701f5d4f4fcc1e82e3f719b86bc57
parentec48903170926f3827144525b50ddd3c6ae3fbf0
Fix setting watchpoints when current thread is running

Currently, when the current thread is running, you can print global
variables.  However, if you try to set a watchpoint on the same
globals, GDB errors out, complaining that the selected thread is
running.  Like so:

 (gdb) c&
 Continuing.
 (gdb) p global
 $1 = 1098377287
 (gdb) watch global
 Selected thread is running.

This patch makes setting the watchpoint work.  You'll now get:

 (gdb) c&
 Continuing.
 (gdb) [New Thread 0x7ffff7d6e640 (LWP 434993)]
 [New Thread 0x7ffff756d640 (LWP 434994)]
 p global
 $1 = 88168
 (gdb) watch global
 Hardware watchpoint 2: global
 (gdb) [Switching to Thread 0x7ffff7d6e640 (LWP 434993)]

 Thread 2 "function0" hit Hardware watchpoint 2: global

 Old value = 185420
 New value = 185423
 int_return () at threads.c:39
 39      }

The problem is that update_watchpoint calls get_selected_frame
unconditionally.  We can skip it if the watchpoint expression is only
watching globals.

This adds a testcase that exercises both all-stop and non-stop, and
also software and hardware watchpoints.  It is kfailed for software
watchpoints, as those require another fix not handled by this patch
(the sw watchpoint doesn't fire because GDB doesn't force the
running-free thread to switch to single-stepping).

Change-Id: I68ca948541aea3edd4f70741f272f543187abe40
gdb/breakpoint.c
gdb/testsuite/gdb.base/watchpoint-running.c [new file with mode: 0644]
gdb/testsuite/gdb.base/watchpoint-running.exp [new file with mode: 0644]