Forget watchpoint locations when inferior exits or is killed/detached
authorPedro Alves <palves@redhat.com>
Fri, 1 Jul 2016 10:16:32 +0000 (11:16 +0100)
committerPedro Alves <palves@redhat.com>
Fri, 1 Jul 2016 10:25:58 +0000 (11:25 +0100)
commit630008884535a5b26828325e48e729034c110536
tree87f9363be7389f7d084ff798d2a1b3a87afde6bd
parent0f48b757071509040d800ff9f7c8726e5828bd1a
Forget watchpoint locations when inferior exits or is killed/detached

If you have two inferiors (or more), set watchpoints in one of the
inferiors, and then that inferior exits, until you manually delete the
watchpoint (or something forces a breakpoint re-set), you can't resume
the other inferior.

This is exercised by the test added by this commit.  Without the GDB
fix, this test fails like this:

 FAIL: gdb.multi/watchpoint-multi-exit.exp: dispose=kill: continue to marker in inferior 1
 FAIL: gdb.multi/watchpoint-multi-exit.exp: dispose=detach: continue to marker in inferior 1
 FAIL: gdb.multi/watchpoint-multi-exit.exp: dispose=exit: continue to marker in inferior 1

and gdb.log shows (in all three cases):

 (gdb) continue
 Continuing.
 Warning:
 Could not insert hardware watchpoint 2.
 Could not insert hardware breakpoints:
 You may have requested too many hardware breakpoints/watchpoints.

 Command aborted.
 (gdb) FAIL: gdb.multi/watchpoint-multi-exit.exp: dispose=kill: continue to marker in inferior 1

The problem is that GDB doesn't forget about the locations of
watchpoints set in the inferior that is now dead.  When we try to
continue the inferior that is still alive, we reach
insert_breakpoint_locations, which has the the loop that triggers the
error:

  /* If we failed to insert all locations of a watchpoint, remove
     them, as half-inserted watchpoint is of limited use.  */

That loop finds locations that are not marked inserted, but which
according to should_be_inserted should have been inserted, and so
errors out.

gdb/ChangeLog:
2016-07-01  Pedro Alves  <palves@redhat.com>

* breakpoint.c (breakpoint_init_inferior): Discard watchpoint
locations.
* infcmd.c (detach_command): Call breakpoint_init_inferior.

gdb/testsuite/ChangeLog:
2016-07-01  Pedro Alves  <palves@redhat.com>

* gdb.multi/watchpoint-multi-exit.c: New file.
* gdb.multi/watchpoint-multi-exit.exp: New file.
gdb/ChangeLog
gdb/breakpoint.c
gdb/infcmd.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.multi/watchpoint-multi-exit.c [new file with mode: 0644]
gdb/testsuite/gdb.multi/watchpoint-multi-exit.exp [new file with mode: 0644]