Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Kevin Buettner via Gdb-patches <gdb-patches@sourceware.org>
To: gdb-patches@sourceware.org
Subject: Re: [PATCH v4] gdb, gdbserver: support dlmopen()
Date: Wed, 25 May 2022 10:12:04 -0700	[thread overview]
Message-ID: <20220525101204.087efe18@f35-zws-1> (raw)
In-Reply-To: <20211117142812.3685162-1-markus.t.metzger@intel.com>

On Wed, 17 Nov 2021 15:28:12 +0100
Markus Metzger via Gdb-patches <gdb-patches@sourceware.org> wrote:

> This patch was originally developed by H.J.  Last version:
> https://sourceware.org/pipermail/gdb-patches/2021-October/182353.html
> 
> Changes in v4:
> 
> 1. add gdb.base/dlmopen.exp
> 2. extend svr4_same() to compare the load offset in addition to the name
> 3. supply l_addr_inferior for default DSO to make it work with #2
> 4. fix bugs in gdbserver/linux-low.cc
> 
> Changes in v3:
> 
> 1. Fix gdbserver support.
> 
> Changes in v2:
> 
> 1. Don't check shared libraries in other namespaces when updating shared
> libraries in a new namespace.
> 
> Regression-tested on x86-64 linux.
> 
> ---
> 
> In glibc, the r_debug structure contains (amongst others) the following
> fields:
> 
>   int r_version:
>     Version number for this protocol.  It should be greater than 0.
> 
> If r_version is 2, struct r_debug is extended to struct r_debug_extended
> with one additional field:
> 
>   struct r_debug_extended *r_next;
>     Link to the next r_debug_extended structure.  Each r_debug_extended
>     structure represents a different namespace.  The first r_debug_extended
>     structure is for the default namespace.
> 
> 1. Change solib_svr4_r_map argument to take the debug base.
> 2. Add solib_svr4_r_next to find the link map in the next namespace from
> the r_next field.
> 3. Update svr4_current_sos_direct to get the link map in the next namespace
> from the r_next field.
> 4. Don't check shared libraries in other namespaces when updating shared
> libraries in a new namespace.
> 5. Update svr4_same to check the load offset in addition to the name
> 6. Update svr4_default_sos to also set l_addr_inferior
> 
> Add gdb.base/dlmopen.exp to test this.
> 
> This fixes PR 11839.

I've been playing around with this patch on Fedora 36 which uses
glibc-2.35.  I also found an LD_AUDIT library to play with.  See:

https://github.com/buildsi/ldaudit-yaml

Here are the interesting portions of a session when debugging whoami
while using the audit library on F36:

  [kev@f36-1 ldaudit-yaml]$ /mesquite2/sourceware-git/f36-dlmopen/inst/bin/gdb -q whoami
  Reading symbols from whoami...
  [...]
  (gdb) b main
  Breakpoint 1 at 0x25a0: file ../src/whoami.c, line 59.
  (gdb) set env LD_AUDIT=./auditlib.so
  (gdb) run
  Starting program: /usr/bin/whoami 
  auditlib:
    la_version: 2
    audits:
    - event: handshake
	function: la_version
	value: 2
  [lots of output from the audit library snipped]
  Breakpoint 1, main (argc=1, argv=0x7fffffffdbe8) at ../src/whoami.c:59
  59	{
  (gdb) info shared
  From                To                  Syms Read   Shared Object Library
  0x00007ffff7fc8090  0x00007ffff7feea45  Yes         /lib64/ld-linux-x86-64.so.2
  0x00007ffff7fb12a0  0x00007ffff7fb9022  Yes         ./auditlib.so
  0x00007ffff7df73f0  0x00007ffff7eff532  Yes         /lib64/libstdc++.so.6
  0x00007ffff7c873b0  0x00007ffff7cf8b58  Yes         /lib64/libm.so.6
  0x00007ffff7c5a670  0x00007ffff7c70c05  Yes         /lib64/libgcc_s.so.1
  0x00007ffff7a82740  0x00007ffff7bf371d  Yes         /lib64/libc.so.6
  0x00007ffff7fc8090  0x00007ffff7feea45  Yes         /lib64/ld-linux-x86-64.so.2
  0x00007ffff777d740  0x00007ffff78ee71d  Yes         /lib64/libc.so.6

Without this patch (or when running on an OS with a version of glibc
earlier than 2.35), I see:

  (gdb) info shared
  From                To                  Syms Read   Shared Object Library
  0x00007ffff7fc9090  0x00007ffff7fee593  Yes         /lib64/ld-linux-x86-64.so.2
  0x00007ffff778c740  0x00007ffff78fee3d  Yes         /lib64/libc.so.6

I found that I can also place breakpoints in the audit library and run
to those breakpoints.  When stopped at a breakpoint, the backtrace looks
reasonable.  E.g...

  Breakpoint 2, doPrint (output=...) at auditlib.cpp:30
  30	  char * out = getenv("LDAUDIT_OUTFILE");
  (gdb) bt
  #0  doPrint (output=...) at auditlib.cpp:30
  #1  0x00007ffff7fb4cf0 in la_activity (cookie=<optimized out>, 
	flag=<optimized out>) at /usr/include/c++/11/bits/char_traits.h:357
  #2  0x00007ffff7fdf415 in _dl_audit_activity_map (l=l@entry=0x7ffff7ffe2a0, 
	action=action@entry=1) at dl-audit.c:33
  #3  0x00007ffff7fe6c98 in dl_main (phdr=<optimized out>, 
	phnum=<optimized out>, user_entry=<optimized out>, auxv=<optimized out>)
	at rtld.c:1832
  #4  0x00007ffff7fe328f in _dl_sysdep_start (
	start_argptr=start_argptr@entry=0x7fffffffdbe0, 
	dl_main=dl_main@entry=0x7ffff7fe52a0 <dl_main>) at ../elf/dl-sysdep.c:256
  #5  0x00007ffff7fe503e in _dl_start_final (arg=0x7fffffffdbe0) at rtld.c:507
  #6  _dl_start (arg=0x7fffffffdbe0) at rtld.c:596
  #7  0x00007ffff7fe3e38 in _start () from /lib64/ld-linux-x86-64.so.2

While I'm convinced that other work will be needed to improve GDB's UI
to both display linker namespaces (e.g.  in the "info shared" command)
and accept namespace qualifiers when specifying a symbol (e.g. with a
breakpoint command), I think that this current patch is useful as
is.  I.e., I'd like to see it (or a modest update) go in as soon as
possible.

Kevin


  parent reply	other threads:[~2022-05-25 17:12 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-17 14:28 Markus Metzger via Gdb-patches
2022-01-21 11:42 ` Metzger, Markus T via Gdb-patches
2022-03-01 19:10 ` Tom Tromey
2022-03-09 12:23   ` Metzger, Markus T via Gdb-patches
2022-03-03 18:32 ` Pedro Alves
2022-03-09 12:24   ` Metzger, Markus T via Gdb-patches
2022-03-09 14:15     ` Pedro Alves
2022-03-29 16:13       ` Metzger, Markus T via Gdb-patches
2022-04-08 12:40         ` Metzger, Markus T via Gdb-patches
2022-05-25 17:12 ` Kevin Buettner via Gdb-patches [this message]
2022-05-31  9:29   ` Metzger, Markus T via Gdb-patches
2022-05-31 18:44     ` Ben Woodard via Gdb-patches
2022-05-24 18:40 Ben Woodard via Gdb-patches

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220525101204.087efe18@f35-zws-1 \
    --to=gdb-patches@sourceware.org \
    --cc=kevinb@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox