gdb: add inferior-specific breakpoints
authorAndrew Burgess <aburgess@redhat.com>
Tue, 8 Nov 2022 12:32:51 +0000 (12:32 +0000)
committerAndrew Burgess <aburgess@redhat.com>
Thu, 17 Aug 2023 15:42:39 +0000 (16:42 +0100)
commitb080fe54fb3414b488b8ef323c6c50def061f918
tree7b0b54ca4a9a44fb37e3838fb68a01b572380b3d
parent0c9546b152f6b01756475ce259c895d3fa446774
gdb: add inferior-specific breakpoints

This commit extends the breakpoint mechanism to allow for inferior
specific breakpoints (but not watchpoints in this commit).

As GDB gains better support for multiple connections, and so for
running multiple (possibly unrelated) inferiors, then it is not hard
to imagine that a user might wish to create breakpoints that apply to
any thread in a single inferior.  To achieve this currently, the user
would need to create a condition possibly making use of the $_inferior
convenience variable, which, though functional, isn't the most user
friendly.

This commit adds a new 'inferior' keyword that allows for the creation
of inferior specific breakpoints.

Inferior specific breakpoints are automatically deleted when the
associated inferior is removed from GDB, this is similar to how
thread-specific breakpoints are deleted when the associated thread is
deleted.

Watchpoints are already per-program-space, which in most cases mean
watchpoints are already inferior specific.  There is a small window
where inferior-specific watchpoints might make sense, which is after a
vfork, when two processes are sharing the same address space.
However, I'm leaving that as an exercise for another day.  For now,
attempting to use the inferior keyword with a watchpoint will give an
error, like this:

  (gdb) watch a8 inferior 1
  Cannot use 'inferior' keyword with watchpoints

A final note on the implementation: currently, inferior specific
breakpoints, like thread-specific breakpoints, are inserted into every
inferior, GDB then checks once the inferior stops if we are in the
correct thread or inferior, and resumes automatically if we stopped in
the wrong thread/inferior.

An obvious optimisation here is to only insert breakpoint locations
into the specific program space (which mostly means inferior) that
contains either the inferior or thread we are interested in.  This
would reduce the number times GDB has to stop and then resume again in
a multi-inferior setup.

I have a series on the mailing list[1] that implements this
optimisation for thread-specific breakpoints.  Once this series has
landed I'll update that series to also handle inferior specific
breakpoints in the same way.  For now, inferior specific breakpoints
are just slightly less optimal, but this is no different to
thread-specific breakpoints in a multi-inferior debug session, so I
don't see this as a huge problem.

[1] https://inbox.sourceware.org/gdb-patches/cover.1685479504.git.aburgess@redhat.com/
25 files changed:
gdb/NEWS
gdb/breakpoint.c
gdb/breakpoint.h
gdb/doc/gdb.texinfo
gdb/doc/python.texi
gdb/guile/scm-breakpoint.c
gdb/infcmd.c
gdb/inferior.h
gdb/linespec.c
gdb/mi/mi-cmd-break.c
gdb/mi/mi-main.c
gdb/mi/mi-main.h
gdb/python/py-breakpoint.c
gdb/python/py-finishbreakpoint.c
gdb/testsuite/gdb.ada/tasks.exp
gdb/testsuite/gdb.linespec/cpcompletion.exp
gdb/testsuite/gdb.linespec/explicit.exp
gdb/testsuite/gdb.mi/new-ui-bp-deleted.c [new file with mode: 0644]
gdb/testsuite/gdb.mi/new-ui-bp-deleted.exp [new file with mode: 0644]
gdb/testsuite/gdb.multi/inferior-specific-bp-1.c [new file with mode: 0644]
gdb/testsuite/gdb.multi/inferior-specific-bp-2.c [new file with mode: 0644]
gdb/testsuite/gdb.multi/inferior-specific-bp.exp [new file with mode: 0644]
gdb/testsuite/gdb.python/py-breakpoint.exp
gdb/testsuite/lib/completion-support.exp
gdb/testsuite/lib/mi-support.exp