This is the mail archive of the mailing list for the GDB project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[RFA 0/4 take 2] Improved linker-debugger interface

Hi all,

This is an updated version of the patch series I posted last week.
After I'd written the incremental library loading part I realised
supporting dlmopen() would be easy, so I added that too.  I've
merged the two large patches as they're now more integrated (the
second patch removed some stuff the first patch added) so the
series is basically three small tweaks and one large patch.

I've regression tested it on F14 x86_64 with a standard glibc,
and on F16 x86_64 with a glibc with the probes interface.  A
quick and dirty speed comparison (on the same machine, with
the same glibc, but with GDB tweaked to disable probes) yielded
the following results:

  no of solibs      100     250     500     1000    2000
  old interface       1       3       9       35     141
  new interface       1       1       3       12      50
  (time in seconds)

GDB is therefore approximately three times faster using the new


This patch series implements an improved debug interface with the
runtime linker to fix the following bugs:
  "_dl_debug_state() RT_CONSISTENT called too early"
  "improve GDB performance on an application performing
  a lot of object loading."
  "gdb does not detect calls to dlmopen"

The current linker-debugger interface has a structure (r_debug)
containing a list of loaded libraries, and an empty function
(_dl_debug_state) for debuggers to set breakpoints on and which
the linker calls both before and after modifying this list.
The problems with the current interface are as follows:

  - There is one place where glibc calls _dl_debug_state earlier than
    Solaris libc.  This is #658851.  It is unlikely that glibc will
    ever be changed to make it compatible with Solaris libc, which
    means GDB reports libraries as loaded and ready before they
    really are.

  - This interface was presumably invented before dlmopen() was, so
    there's only provision in it for one namespace.  In glibc each
    namespace has it's own r_debug structure, but there is no way for
    the linker to communicate the addresses of the others to the
    debugger.  This is PR 11839.

  - There is also no provision for communicating what (if anything)
    has changed when _dl_debug_state is called.  GDB must therefore
    load the entire list of loaded libraries at every stop.  This
    is #698001.

  - In normal use GDB only needs to stop _after_ the list is modified.
    Because _dl_debug_state is called both before and after changes,
    GDB stops twice as often as it needs to.  When stop-on-solib-events
    is set, however, it is useful to stop both before and after library
    loads.  This also is #698001.

My solution is to insert a number of named probes into glibc.  The
glibc patch is here:

The patch adds a probe everywhere _dl_debug_state is called, and an
extra pair to surround relocation events.  New probes can be added as
and when necessary without breaking the interface, and likewise new
arguments can be added to existing probes.

This new interface solves the various problems like so:

  - Debuggers can pick and choose which probes to set breakpoints
    on.  By using the "relocation completed" probe instead of the
    one mirroring _dl_debug_state debuggers can stop after relocations
    have occurred, matching the behaviour of Solaris libc.

  - All probes have namespace id and r_debug address arguments,
    allowing debuggers to see namespaces other than the default.

  - When stop-on-solib-events is unset, GDB does not have to stop
    before changes are made, only after.  By disabling the "before"
    breakpoints the number of stops made can be halved.

  - Probes adding new libraries may optionally supply the address
    of the link-map entry of the first newly added library.  This
    enables debuggers to skip past libraries they already saw.

This patch series modifies GDB to search for named probes in the
runtime linker, and to use them instead of _dl_debug_state if
found. If the probes are not found then GDB will fall back to its
previous behaviour.  When probes are used:

  - GDB stops after relocation events, not before, fixing PR 2328.

  - GDB sees libraries in all namespaces, not just the initial one,
    so code loaded using dlmopen() is visible and debuggable.  This
    fixes PR 11839.

  - Stops before changes are made are inhibited when stop-on-solib-
    events is off, and if the linker supplies the information to
    allow incremental updating then GDB uses it.

All reviews appreciated!



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]