From: "Rohr, Stephan" <stephan.rohr@intel.com>
To: Eduard-Petru Jipa <ejipa@undo.io>,
"gdb-patches@sourceware.org" <gdb-patches@sourceware.org>
Subject: RE: [PATCH v2] gdb: don't abort shared library reload when one library fails to open
Date: Wed, 7 Oct 2026 15:35:59 +0000 [thread overview]
Message-ID: <DS7PR11MB6247E2F53485C6A8A8BCFEA293942@DS7PR11MB6247.namprd11.prod.outlook.com> (raw)
In-Reply-To: <20261007133620.50516-1-ejipa@undo.io>
Hi Eduard,
I have one suggestion regarding the test, see below.
With that fixed:
Reviewed-By: Rohr, Stephan <stephan.rohr@intel.com>
Thanks
Stephan
> -----Original Message-----
> From: Eduard-Petru Jipa <ejipa@undo.io>
> Sent: Wednesday, 7 October 2026 15:36
> To: gdb-patches@sourceware.org
> Cc: Rohr, Stephan <stephan.rohr@intel.com>; Eduard Jipa <ejipa@undo.io>
> Subject: [PATCH v2] gdb: don't abort shared library reload when one library
> fails to open
>
> From: Eduard Jipa <ejipa@undo.io>
>
> When the set of shared libraries is reloaded, for example after
> 'set sysroot' or 'set solib-search-path', reload_shared_libraries_1
> calls solib_ops::bfd_open for each library in turn. This can throw an
> error, for example if the file found is not in executable format, or
> its architecture is not compatible with the target.
>
> Nothing in the loop catches that error, so a single bad library stops
> the whole reload. Any libraries after it in the list are not reloaded,
> and the error propagates out of the command that triggered the reload.
>
> Catch the error, print it, and carry on with the rest of the
> libraries. This matches what is already done for errors from
> solib_map_sections later in the same loop. The library that failed
> to open is handled as if it had not been found.
>
> Add a test that builds a sysroot in which the first of two libraries
> is not a valid object file, and checks that, after 'set sysroot', the
> first library is no longer loaded and the second library is reloaded
> from the new sysroot.
>
> Tested on x86_64-linux with no regressions.
> ---
>
> Changes in v2:
> - Print the library name only once, on a single line.
> - Reword the commit message: the error is printed, not emitted with
> warning ().
> - Test that lib1 is not loaded after the failed reload.
>
> Thank you Stephan for the review.
>
> gdb/solib.c | 11 ++-
> .../gdb.base/solib-reload-error-lib.c | 25 ++++++
> gdb/testsuite/gdb.base/solib-reload-error.c | 25 ++++++
> gdb/testsuite/gdb.base/solib-reload-error.exp | 86 +++++++++++++++++++
> 4 files changed, 146 insertions(+), 1 deletion(-)
> create mode 100644 gdb/testsuite/gdb.base/solib-reload-error-lib.c
> create mode 100644 gdb/testsuite/gdb.base/solib-reload-error.c
> create mode 100644 gdb/testsuite/gdb.base/solib-reload-error.exp
>
> diff --git a/gdb/solib.c b/gdb/solib.c
> index 7ea3084bf48..cef9a429f45 100644
> --- a/gdb/solib.c
> +++ b/gdb/solib.c
> @@ -1463,7 +1463,16 @@ reload_shared_libraries_1 (int from_tty)
> gdb::unique_xmalloc_ptr<char> filename
> = gdb_rl_tilde_expand (so.original_name.c_str ());
>
> - gdb_bfd_ref_ptr abfd = so.ops ().bfd_open (filename.get ());
> + gdb_bfd_ref_ptr abfd;
> + try
> + {
> + abfd = so.ops ().bfd_open (filename.get ());
> + }
> + catch (const gdb_exception_error &e)
> + {
> + exception_fprintf (gdb_stderr, e,
> + _("Error while opening shared library: "));
> + }
> if (abfd != NULL)
> found_pathname = bfd_get_filename (abfd.get ());
>
> diff --git a/gdb/testsuite/gdb.base/solib-reload-error-lib.c
> b/gdb/testsuite/gdb.base/solib-reload-error-lib.c
> new file mode 100644
> index 00000000000..7aaa13fd697
> --- /dev/null
> +++ b/gdb/testsuite/gdb.base/solib-reload-error-lib.c
> @@ -0,0 +1,25 @@
> +/* This test program is part of GDB, the GNU debugger.
> +
> + Copyright 2026 Free Software Foundation, Inc.
> +
> + This program is free software; you can redistribute it and/or modify
> + it under the terms of the GNU General Public License as published by
> + the Free Software Foundation; either version 3 of the License, or
> + (at your option) any later version.
> +
> + This program is distributed in the hope that it will be useful,
> + but WITHOUT ANY WARRANTY; without even the implied warranty of
> + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> + GNU General Public License for more details.
> +
> + You should have received a copy of the GNU General Public License
> + along with this program. If not, see <http://www.gnu.org/licenses/>. */
> +
> +/* This file is compiled twice, with LIB_FUNC defined to a different
> + name each time. */
> +
> +int
> +LIB_FUNC (void)
> +{
> + return 0;
> +}
> diff --git a/gdb/testsuite/gdb.base/solib-reload-error.c
> b/gdb/testsuite/gdb.base/solib-reload-error.c
> new file mode 100644
> index 00000000000..465cf7e82e6
> --- /dev/null
> +++ b/gdb/testsuite/gdb.base/solib-reload-error.c
> @@ -0,0 +1,25 @@
> +/* This test program is part of GDB, the GNU debugger.
> +
> + Copyright 2026 Free Software Foundation, Inc.
> +
> + This program is free software; you can redistribute it and/or modify
> + it under the terms of the GNU General Public License as published by
> + the Free Software Foundation; either version 3 of the License, or
> + (at your option) any later version.
> +
> + This program is distributed in the hope that it will be useful,
> + but WITHOUT ANY WARRANTY; without even the implied warranty of
> + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> + GNU General Public License for more details.
> +
> + You should have received a copy of the GNU General Public License
> + along with this program. If not, see <http://www.gnu.org/licenses/>. */
> +
> +extern int lib1_func (void);
> +extern int lib2_func (void);
> +
> +int
> +main (void)
> +{
> + return lib1_func () + lib2_func ();
> +}
> diff --git a/gdb/testsuite/gdb.base/solib-reload-error.exp
> b/gdb/testsuite/gdb.base/solib-reload-error.exp
> new file mode 100644
> index 00000000000..a8db733558a
> --- /dev/null
> +++ b/gdb/testsuite/gdb.base/solib-reload-error.exp
> @@ -0,0 +1,86 @@
> +# Copyright 2026 Free Software Foundation, Inc.
> +
> +# This program is free software; you can redistribute it and/or modify
> +# it under the terms of the GNU General Public License as published by
> +# the Free Software Foundation; either version 3 of the License, or
> +# (at your option) any later version.
> +#
> +# This program is distributed in the hope that it will be useful,
> +# but WITHOUT ANY WARRANTY; without even the implied warranty of
> +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> +# GNU General Public License for more details.
> +#
> +# You should have received a copy of the GNU General Public License
> +# along with this program. If not, see <http://www.gnu.org/licenses/>.
> +
> +# Check that an error opening one shared library while reloading
> +# shared libraries (in this case, triggered by 'set sysroot') does not
> +# stop GDB from reloading the shared libraries that come after it.
> +
> +require allow_shlib_tests
> +require {!is_remote host}
> +
> +standard_testfile .c -lib.c
> +
> +set lib1 [standard_output_file ${testfile}-lib1.so]
> +set lib2 [standard_output_file ${testfile}-lib2.so]
> +
> +if { [gdb_compile_shlib $srcdir/$subdir/$srcfile2 $lib1 \
> + {debug additional_flags=-DLIB_FUNC=lib1_func}] != ""
> + || [gdb_compile_shlib $srcdir/$subdir/$srcfile2 $lib2 \
> + {debug additional_flags=-DLIB_FUNC=lib2_func}] != "" } {
> + untested "failed to compile shared libraries"
> + return
> +}
> +
> +# Link against lib1 first, so that it is ahead of lib2 in the list of
> +# shared libraries that GDB reloads.
> +if { [prepare_for_testing "failed to prepare" $testfile $srcfile \
> + [list debug shlib=$lib1 shlib=$lib2]] } {
> + return
> +}
> +
> +gdb_load_shlib $lib1
> +gdb_load_shlib $lib2
> +
> +if { ![runto_main] } {
> + return
> +}
> +
> +# The rest of the test relies on lib1 being reloaded before lib2.
> +if { [gdb_test "info sharedlibrary" \
> + "[string_to_regexp $lib1]\r\n.*[string_to_regexp $lib2]\r\n.*" \
> + "lib1 is ahead of lib2 in the list"] != 0 } {
> + return
> +}
> +
> +# Build a sysroot in which lib1 is not a valid object file, but lib2
> +# is a good copy of the real library.
> +set sysroot [standard_output_file sysroot]
> +set sysroot_lib1 $sysroot$lib1
> +set sysroot_lib2 $sysroot$lib2
> +file delete -force $sysroot
> +file mkdir [file dirname $sysroot_lib1]
> +set fd [open $sysroot_lib1 w]
> +puts $fd "This is not an object file."
> +close $fd
> +file copy $lib2 $sysroot_lib2
> +
> +# Changing the sysroot reloads every shared library. Opening lib1
> +# fails, and GDB should report that and carry on.
> +gdb_test "set sysroot $sysroot" \
> + "Error while opening shared library: `[string_to_regexp $sysroot_lib1]': not
> in executable format: .*" \
> + "set sysroot with bad lib1"
> +
> +# lib1 could not be opened, so its symbols should no longer be loaded.
> +gdb_test "info sharedlibrary" \
> + "\r\n\[ \t\]+No\[ \t\]+[string_to_regexp $lib1]\r\n.*" \
> + "lib1 is not loaded"
> +
> +# lib2 comes after lib1 in the list, so it is only reloaded from the
> +# new sysroot if the error opening lib1 did not stop the reload.
> +gdb_test "info sharedlibrary" \
> + "\r\n$hex\[ \t\]+$hex\[ \t\]+Yes\[^\r\n\]*[string_to_regexp
> $sysroot_lib2]\r\n.*" \
> + "lib2 is reloaded from the new sysroot"
> +
I think we can combine this into a single test statement, e.g.:
gdb_test "info sharedlibrary" \
[multi_line \
"" \
"\[ \t\]+No\[ \t\]+[string_to_regexp $lib1]" \
"$hex\[ \t\]+$hex\[ \t\]+Yes\[^\r\n\]*[string_to_regexp $sysroot_lib2]" \
".*"] \
"lib1 is not loaded and lib2 is reloaded from the new sysroot"
I didn't check this for correctness.
> +gdb_test "info symbol lib2_func" "lib2_func in section \\.text of
> [string_to_regexp $sysroot_lib2]"
> --
> 2.43.0
________________________________________
Intel Deutschland GmbH
Registered Address: Dornacher Strasse 1, 85622 Feldkirchen, Germany
Tel: +49 (89) 99143-0
www.intel.de
Managing Directors: Candice Moore, Jeffrey Schneiderman, Ramachandran Sitaraman
Chairperson of the Supervisory Board: Sonja Pierer
Registered Seat: Munich Commercial Register B: Amtsgericht Munich HRB 186928
This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.
next prev parent reply other threads:[~2026-10-07 15:37 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-07 11:18 [PATCH] " Eduard-Petru Jipa
2026-10-07 12:45 ` Rohr, Stephan
2026-10-07 13:36 ` [PATCH v2] " Eduard-Petru Jipa
2026-10-07 15:35 ` Rohr, Stephan [this message]
2026-10-08 13:06 ` [PATCH v3] " Eduard-Petru Jipa
2026-10-27 14:25 ` Tom Tromey
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=DS7PR11MB6247E2F53485C6A8A8BCFEA293942@DS7PR11MB6247.namprd11.prod.outlook.com \
--to=stephan.rohr@intel.com \
--cc=ejipa@undo.io \
--cc=gdb-patches@sourceware.org \
/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