From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 15FAC3857363 for ; Wed, 25 May 2022 17:12:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 15FAC3857363 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-582-dB66NWo_MYyHcFoNt5al_w-1; Wed, 25 May 2022 13:12:06 -0400 X-MC-Unique: dB66NWo_MYyHcFoNt5al_w-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 320D418A0722; Wed, 25 May 2022 17:12:06 +0000 (UTC) Received: from f35-zws-1 (unknown [10.2.17.65]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BA6B72166B26; Wed, 25 May 2022 17:12:05 +0000 (UTC) Date: Wed, 25 May 2022 10:12:04 -0700 From: Kevin Buettner To: gdb-patches@sourceware.org Subject: Re: [PATCH v4] gdb, gdbserver: support dlmopen() Message-ID: <20220525101204.087efe18@f35-zws-1> In-Reply-To: <20211117142812.3685162-1-markus.t.metzger@intel.com> References: <20211117142812.3685162-1-markus.t.metzger@intel.com> Organization: Red Hat MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.8 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 25 May 2022 17:12:09 -0000 On Wed, 17 Nov 2021 15:28:12 +0100 Markus Metzger via Gdb-patches 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=, flag=) 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=, phnum=, user_entry=, auxv=) at rtld.c:1832 #4 0x00007ffff7fe328f in _dl_sysdep_start ( start_argptr=start_argptr@entry=0x7fffffffdbe0, dl_main=dl_main@entry=0x7ffff7fe52a0 ) 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