From: Kevin Buettner <kevinb@redhat.com>
To: Markus Metzger via Gdb-patches <gdb-patches@sourceware.org>
Cc: Markus Metzger <markus.t.metzger@intel.com>,
Lu@sourceware.org, Hongjiu <hongjiu.lu@intel.com>
Subject: Re: [PATCH v5 03/15] gdb, gdbserver: support dlmopen()
Date: Sat, 18 Jun 2022 21:02:13 -0700 [thread overview]
Message-ID: <20220618210213.73f6b911@f35-zws-1> (raw)
In-Reply-To: <20220602132514.957983-4-markus.t.metzger@intel.com>
Hi Markus,
This patch looks pretty good. Just a couple of comments/questions...
On Thu, 2 Jun 2022 15:25:02 +0200
Markus Metzger via Gdb-patches <gdb-patches@sourceware.org> wrote:
> diff --git a/gdb/solib-svr4.c b/gdb/solib-svr4.c
> index 6222f79a7a0..1f2abcf16ef 100644
[...]
> @@ -1258,49 +1338,110 @@ svr4_current_sos_direct (struct svr4_info *info)
> if (library_list.main_lm)
> info->main_lm_addr = library_list.main_lm;
>
> - return library_list.head ? library_list.head : svr4_default_sos (info);
> + /* Remove an empty special zero namespace so we know that when there
> + is one, it is actually used, and we have a flat list without
> + namespace information. */
> + if ((library_list.solib_lists.find (0)
> + != library_list.solib_lists.end ())
> + && (library_list.solib_lists[0] == nullptr))
> + library_list.solib_lists.erase (0);
> +
> + std::swap (info->solib_lists, library_list.solib_lists);
> + return;
> }
[...]
> @@ -1697,17 +1872,34 @@ solist_update_incremental (struct svr4_info *info, CORE_ADDR lm)
> if (!svr4_current_sos_via_xfer_libraries (&library_list, annex))
> return 0;
>
> - tail->next = library_list.head;
> + /* We expect gdbserver to provide updates for the namespace that
> + contains LM, which whould be this namespace... */
> + so_list *sos = nullptr;
> + if (library_list.solib_lists.find (debug_base)
> + != library_list.solib_lists.end ())
> + std::swap (sos, library_list.solib_lists[debug_base]);
> + if (sos == nullptr)
> + {
> + /* ...or for the special zero namespace for earlier versions... */
> + if (library_list.solib_lists.find (0)
> + != library_list.solib_lists.end ())
> + std::swap (sos, library_list.solib_lists[0]);
[...]
I was puzzled for a while by the uses of std:swap() in the above
snippets of code. I checked the rest of the GDB sources and found
that (at least in GDB) this is not a common idiom. I'd appreciate
it if you could add a few lines of explanation for at least one
of them.
> diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
> index 6aef39e5e02..98715fdc87e 100644
> --- a/gdb/testsuite/lib/gdb.exp
> +++ b/gdb/testsuite/lib/gdb.exp
> @@ -2451,6 +2451,102 @@ proc skip_shlib_tests {} {
> return 1
> }
>
> +# Return 1 if we should skip dlmopen tests, 0 if we should not.
> +
> +proc skip_dlmopen_tests {} {
> + global srcdir subdir gdb_prompt inferior_exited_re
> +
> + # We need shared library support.
> + if { [skip_shlib_tests] } {
> + return 1
> + }
> +
> + set me "skip_dlmopen_tests"
> + set lib {
> + int foo (void) {
> + return 42;
> + }
> + }
> + set src {
> + #define _GNU_SOURCE
> + #include <dlfcn.h>
> + #include <link.h>
> + #include <stdio.h>
> + #include <errno.h>
> +
> + int main (void) {
> + struct r_debug *r_debug;
> + ElfW(Dyn) *dyn;
> + void *handle;
> +
> + /* The version is kept at 1 until we create a new namespace. */
> + handle = dlmopen (LM_ID_NEWLM, DSO_NAME, RTLD_LAZY | RTLD_LOCAL);
> + if (!handle) {
> + printf ("dlmopen failed: %s.\n", dlerror ());
> + return 1;
> + }
> +
> + r_debug = 0;
> + /* Taken from /usr/include/link.h. */
> + for (dyn = _DYNAMIC; dyn->d_tag != DT_NULL; ++dyn)
> + if (dyn->d_tag == DT_DEBUG)
> + r_debug = (struct r_debug *) dyn->d_un.d_ptr;
> +
> + if (!r_debug) {
> + printf ("r_debug not found.\n");
> + return 1;
> + }
> + if (r_debug->r_version < 2) {
> + printf ("dlmopen debug not supported.\n");
> + return 1;
> + }
> + printf ("dlmopen debug supported.\n");
> + return 0;
> + }
> + }
> +
> + set libsrc [standard_temp_file "libfoo.c"]
> + set libout [standard_temp_file "libfoo.so"]
> + gdb_produce_source $libsrc $lib
> +
> + if { [gdb_compile_shlib $libsrc $libout {debug}] != "" } {
> + verbose -log "failed to build library"
> + return 1
> + }
> + if { ![gdb_simple_compile $me $src executable \
> + [list shlib_load debug \
> + additional_flags=-DDSO_NAME=\"$libout\"]] } {
> + verbose -log "failed to build executable"
> + return 1
> + }
> +
> + gdb_exit
> + gdb_start
> + gdb_reinitialize_dir $srcdir/$subdir
> + gdb_load $obj
> +
> + if { [gdb_run_cmd] != 0 } {
> + verbose -log "failed to start skip test"
> + return 1
> + }
> + gdb_expect {
> + -re "$inferior_exited_re normally.*${gdb_prompt} $" {
> + set skip_dlmopen_tests 0
> + }
> + -re "$inferior_exited_re with code.*${gdb_prompt} $" {
> + set skip_dlmopen_tests 1
> + }
> + default {
> + warning "\n$me: default case taken"
> + set skip_dlmopen_tests 1
> + }
> + }
> + gdb_exit
> +
> + verbose "$me: returning $skip_dlmopen_tests" 2
> + return $skip_dlmopen_tests
> +}
> +
> # Return 1 if we should skip tui related tests.
I'm wondering if this can be a gdb_caching_proc? At the moment, there's
probably not much point since I think it's only used by the new test.
But if we end up with more tests which use it, it might be worthwhile.
Kevin
next prev parent reply other threads:[~2022-06-19 4:02 UTC|newest]
Thread overview: 52+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-02 13:24 [PATCH v5 00/15] basic linker namespace support Markus Metzger
2022-06-02 13:25 ` [PATCH v5 01/15] gdb, testsuite: extend gdb_test_multiple checks Markus Metzger
2022-06-13 1:28 ` Kevin Buettner
2022-06-02 13:25 ` [PATCH v5 02/15] gdb, solib-svr4: remove locate_base() Markus Metzger
2022-06-02 23:04 ` Kevin Buettner
2022-06-02 13:25 ` [PATCH v5 03/15] gdb, gdbserver: support dlmopen() Markus Metzger
2022-06-19 4:02 ` Kevin Buettner [this message]
2022-06-27 12:55 ` Metzger, Markus T
2022-06-30 22:35 ` Kevin Buettner
2022-06-02 13:25 ` [PATCH v5 04/15] gdbserver: move main_lm handling into caller Markus Metzger
2022-06-19 4:22 ` Kevin Buettner
2022-06-02 13:25 ` [PATCH v5 05/15] gdb, gdbserver: extend RSP to support namespaces Markus Metzger
2022-06-02 16:09 ` Eli Zaretskii
2022-06-19 4:32 ` Kevin Buettner
2022-06-02 13:25 ` [PATCH v5 06/15] gdb, compile: unlink objfile stored in module Markus Metzger
2022-06-23 17:20 ` Kevin Buettner
2022-06-02 13:25 ` [PATCH v5 07/15] gdb, python: use gdbarch_iterate_over_objfiles_in_search_order Markus Metzger
2022-06-24 17:18 ` Kevin Buettner
2022-06-02 13:25 ` [PATCH v5 08/15] gdb, ada: collect standard exceptions in all objfiles Markus Metzger
2022-06-24 17:26 ` Kevin Buettner
2022-07-18 16:49 ` Tom Tromey
2022-07-18 5:35 ` Metzger, Markus T
2022-09-14 8:19 ` Metzger, Markus T
2022-09-14 8:37 ` Joel Brobecker
2022-09-14 8:45 ` Metzger, Markus T
2022-06-02 13:25 ` [PATCH v5 09/15] gdb, ada: update ada_lookup_simple_minsym Markus Metzger
2022-06-24 23:42 ` Kevin Buettner
2022-07-18 17:02 ` Tom Tromey
2022-07-19 7:14 ` Metzger, Markus T
2022-09-14 8:19 ` Metzger, Markus T
2022-09-21 16:11 ` Tom Tromey
2022-06-02 13:25 ` [PATCH v5 10/15] gdb, ada: update ada_add_all_symbols Markus Metzger
2022-06-24 23:53 ` Kevin Buettner
2022-07-18 5:36 ` Metzger, Markus T
2022-07-18 16:56 ` Tom Tromey
2022-07-19 7:13 ` Metzger, Markus T
2022-07-19 12:23 ` Tom Tromey
2022-07-19 13:49 ` Metzger, Markus T
2022-06-02 13:25 ` [PATCH v5 11/15] gdb, cp: update add_symbol_overload_list_qualified Markus Metzger
2022-06-24 23:59 ` Kevin Buettner
2022-06-02 13:25 ` [PATCH v5 12/15] gdb, hppa: remove unused hppa_lookup_stub_minimal_symbol Markus Metzger
2022-06-25 0:01 ` Kevin Buettner
2022-06-02 13:25 ` [PATCH v5 13/15] gdb, symtab: inline find_quick_global_symbol_language Markus Metzger
2022-06-25 0:16 ` Kevin Buettner
2022-06-02 13:25 ` [PATCH v5 14/15] gdb: update gnu ifunc resolve Markus Metzger
2022-06-25 0:34 ` Kevin Buettner
2022-06-02 13:25 ` [PATCH v5 15/15] gdb, solib-svr4: support namespaces in DSO iteration Markus Metzger
2022-06-25 0:42 ` Kevin Buettner
2022-07-15 10:30 ` [PATCH v5 00/15] basic linker namespace support Metzger, Markus T
2022-07-16 0:04 ` Kevin Buettner
2022-07-18 5:33 ` Metzger, Markus T
2022-10-05 11:16 ` Metzger, Markus T
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=20220618210213.73f6b911@f35-zws-1 \
--to=kevinb@redhat.com \
--cc=Lu@sourceware.org \
--cc=gdb-patches@sourceware.org \
--cc=hongjiu.lu@intel.com \
--cc=markus.t.metzger@intel.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).