gdb: include a still-mapped flag in solib unload notification

Consider the gdb.base/dlmopen.exp test case.  The executable in this
test uses dlmopen to load libraries into multiple linker namespaces.

When a library is loaded into a separate namespace, its dependencies
are also loaded into that namespace.

This means that an inferior can have multiple copies of some
libraries, including the dynamic linker, loaded at once.

However, glibc optimises at least the dynamic linker case.  Though the
library appears to be mapped multiple times (it is in the inferior's
solib list multiple times), there is really only one copy mapped into
the inferior's address space.  Here is the 'info sharedlibrary' output
on an x86-64/Linux machine once all the libraries are loaded:

  (gdb) info sharedlibrary
  From                To                  Syms Read   Shared Object Library
  0x00007ffff7fca000  0x00007ffff7ff03f5  Yes         /lib64/ld-linux-x86-64.so.2
  0x00007ffff7eda3d0  0x00007ffff7f4e898  Yes         /lib64/libm.so.6
  0x00007ffff7d0e800  0x00007ffff7e6dccd  Yes         /lib64/libc.so.6
  0x00007ffff7fbd040  0x00007ffff7fbd116  Yes         /tmp/build/gdb/testsuite/outputs/gdb.base/dlmopen/dlmopen-lib.1.so
  0x00007ffff7fb8040  0x00007ffff7fb80f9  Yes         /tmp/build/gdb/testsuite/outputs/gdb.base/dlmopen/dlmopen-lib-dep.so
  0x00007ffff7bfe3d0  0x00007ffff7c72898  Yes         /lib64/libm.so.6
  0x00007ffff7a32800  0x00007ffff7b91ccd  Yes         /lib64/libc.so.6
  0x00007ffff7fca000  0x00007ffff7ff03f5  Yes         /lib64/ld-linux-x86-64.so.2
  0x00007ffff7fb3040  0x00007ffff7fb3116  Yes         /tmp/build/gdb/testsuite/outputs/gdb.base/dlmopen/dlmopen-lib.1.so
  0x00007ffff7fae040  0x00007ffff7fae0f9  Yes         /tmp/build/gdb/testsuite/outputs/gdb.base/dlmopen/dlmopen-lib-dep.so
  0x00007ffff7ce1040  0x00007ffff7ce1116  Yes         /tmp/build/gdb/testsuite/outputs/gdb.base/dlmopen/dlmopen-lib.1.so
  0x00007ffff7cdc040  0x00007ffff7cdc0f9  Yes         /tmp/build/gdb/testsuite/outputs/gdb.base/dlmopen/dlmopen-lib-dep.so
  0x00007ffff79253d0  0x00007ffff7999898  Yes         /lib64/libm.so.6
  0x00007ffff7759800  0x00007ffff78b8ccd  Yes         /lib64/libc.so.6
  0x00007ffff7fca000  0x00007ffff7ff03f5  Yes         /lib64/ld-linux-x86-64.so.2
  0x00007ffff7cd7040  0x00007ffff7cd7116  Yes         /tmp/build/gdb/testsuite/outputs/gdb.base/dlmopen/dlmopen-lib.2.so

Notice that every copy of /lib64/ld-linux-x86-64.so.2 is mapped at the
same address.

As the inferior closes the libraries that it loaded, the various
copies of the dynamic linker will also be unloaded.

Currently, when this happens GDB calls notify_solib_unloaded, which
triggers the gdb::observers::solib_unloaded observer.  This observer
will call disable_breakpoints_in_unloaded_shlib (in breakpoint.c),
which disables any breakpoints in the unloaded solib.

The problem with this, is that, when the dynamic linker (or any solib)
is only really mapped once as is the case here, we only want to
disable breakpoints in the library when the last instance of the
library is unloaded.

The first idea that comes to mind is that GDB should not emit the
solib_unloaded notification if a shared library is still in use,
however, this could break MI consumers.

Currently, every time a copy of ld-linux-x86-64.so.2 is unloaded,
GDB's MI interpreter will emit a =library-unloaded event.  An MI
consumer might use this to update the library list that it displays to
the user, and fewer notify_solib_unloaded calls will mean fewer MI
events, which will mean the MI consumer's library list could get out
of sync with GDB.

Instead I propose that we extend GDB's solib_unloaded event to add a
new flag.  The new flag indicates if the library mapping is still in
use within the inferior.  Now the MI will continue to emit the
expected =library-unloaded events, but
disable_breakpoints_in_unloaded_shlib can check the new flag, when it
is true (indicating that the library is still mapped into the
inferior), no breakpoints should be disabled.

The other user of the solib_unloaded observer, in bsd-uthread.c,
should, I think, do nothing if the mapping is still in use.  This
observer is also disabling breakpoints when a library is unloaded.

Most of the changes in this commit relate to passing the new flag
around for the event.  The interesting changes are mostly in solib.c,
where the flag value is determined, and in breakpoint.c and
bsd-uthread.c, where the flag value is read.

There's a new MI test, the source of which is mostly copied from the
gdb.base/dlmopen.exp test.  This new test is checking we see all the
expected =library-unloaded events.
15 files changed