From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2205) id 11C663857364; Wed, 1 Jun 2022 17:29:44 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 11C663857364 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Tom de Vries To: gdb-cvs@sourceware.org Subject: [binutils-gdb] [gdb] Fix warning in foreach_arch selftests X-Act-Checkin: binutils-gdb X-Git-Author: Tom de Vries X-Git-Refname: refs/heads/master X-Git-Oldrev: 80fa4b2a606763e71c4b599fa88288f554a0ea5b X-Git-Newrev: fc18b1c5afd77960b221d81f382de5c9cf5e75d9 Message-Id: <20220601172944.11C663857364@sourceware.org> Date: Wed, 1 Jun 2022 17:29:44 +0000 (GMT) X-BeenThere: gdb-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 01 Jun 2022 17:29:44 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3Dfc18b1c5afd7= 7960b221d81f382de5c9cf5e75d9 commit fc18b1c5afd77960b221d81f382de5c9cf5e75d9 Author: Tom de Vries Date: Wed Jun 1 19:29:40 2022 +0200 [gdb] Fix warning in foreach_arch selftests =20 When running the selftests, I run into: ... $ gdb -q -batch -ex "maint selftest" ... Running selftest execute_cfa_program::aarch64:ilp32. warning: A handler for the OS ABI "GNU/Linux" is not built into this configuration of GDB. Attempting to continue with the default aarch64:= ilp32 settings. ... and likewise for execute_cfa_program::i8086 and execute_cfa_program::ia64-elf32. =20 The warning can easily be reproduced outside the selftests by doing: ... $ gdb -q -batch -ex "set arch aarch64:ilp32" ... and can be prevented by first doing "set osabi none". =20 Fix the warning by setting osabi to none while doing selftests that ite= rate over all architectures. =20 Tested on x86_64-linux. Diff: --- gdb/osabi.c | 50 ++++++++++++++++++++++++++++++++++++++------------ gdb/osabi.h | 13 +++++++++++++ gdb/selftest-arch.c | 18 +++++++++++++++++- 3 files changed, 68 insertions(+), 13 deletions(-) diff --git a/gdb/osabi.c b/gdb/osabi.c index bbd7635532f..776e62069e5 100644 --- a/gdb/osabi.c +++ b/gdb/osabi.c @@ -32,7 +32,7 @@ #endif =20 /* State for the "set osabi" command. */ -static enum { osabi_auto, osabi_default, osabi_user } user_osabi_state; +static enum gdb_osabi_mode user_osabi_state; static enum gdb_osabi user_selected_osabi; static const char *gdb_osabi_available_names[GDB_OSABI_INVALID + 3] =3D { "auto", @@ -595,15 +595,48 @@ generic_elf_osabi_sniffer (bfd *abfd) return osabi; } =0C +/* See osabi.h. */ + +void +set_osabi (enum gdb_osabi_mode mode, enum gdb_osabi osabi) +{ + if (mode =3D=3D osabi_auto) + user_osabi_state =3D osabi_auto; + else if (mode =3D=3D osabi_default) + { + user_selected_osabi =3D GDB_OSABI_DEFAULT; + user_osabi_state =3D osabi_user; + } + else + { + user_selected_osabi =3D osabi; + user_osabi_state =3D osabi_user; + } + + /* NOTE: At some point (true multiple architectures) we'll need to be mo= re + graceful here. */ + gdbarch_info info; + if (! gdbarch_update_p (info)) + internal_error (__FILE__, __LINE__, _("Updating OS ABI failed.")); +} + +/* See osabi.h. */ + +void +get_osabi (enum gdb_osabi_mode &mode, enum gdb_osabi &osabi) +{ + mode =3D user_osabi_state; + osabi =3D user_selected_osabi; +} + static void set_osabi (const char *args, int from_tty, struct cmd_list_element *c) { if (strcmp (set_osabi_string, "auto") =3D=3D 0) - user_osabi_state =3D osabi_auto; + set_osabi (osabi_auto, GDB_OSABI_INVALID); else if (strcmp (set_osabi_string, "default") =3D=3D 0) { - user_selected_osabi =3D GDB_OSABI_DEFAULT; - user_osabi_state =3D osabi_user; + set_osabi (osabi_default, GDB_OSABI_INVALID); } else { @@ -615,8 +648,7 @@ set_osabi (const char *args, int from_tty, struct cmd_l= ist_element *c) =20 if (strcmp (set_osabi_string, gdbarch_osabi_name (osabi)) =3D=3D 0) { - user_selected_osabi =3D osabi; - user_osabi_state =3D osabi_user; + set_osabi (osabi_user, osabi); break; } } @@ -625,12 +657,6 @@ set_osabi (const char *args, int from_tty, struct cmd_= list_element *c) _("Invalid OS ABI \"%s\" passed to command handler."), set_osabi_string); } - - /* NOTE: At some point (true multiple architectures) we'll need to be mo= re - graceful here. */ - gdbarch_info info; - if (! gdbarch_update_p (info)) - internal_error (__FILE__, __LINE__, _("Updating OS ABI failed.")); } =20 static void diff --git a/gdb/osabi.h b/gdb/osabi.h index be016732cbc..3737a77d50e 100644 --- a/gdb/osabi.h +++ b/gdb/osabi.h @@ -50,6 +50,13 @@ enum gdb_osabi GDB_OSABI_INVALID /* keep this last */ }; =20 +enum gdb_osabi_mode +{ + osabi_auto, + osabi_default, + osabi_user +}; + /* Register an OS ABI sniffer. Each arch/flavour may have more than one sniffer. This is used to e.g. differentiate one OS's a.out from another. The first sniffer to return something other than @@ -89,4 +96,10 @@ const char *osabi_triplet_regexp (enum gdb_osabi osabi); void generic_elf_osabi_sniff_abi_tag_sections (bfd *, asection *, enum gdb_osabi *); =20 +/* Set osabi to MODE/OSABI. */ +extern void set_osabi (enum gdb_osabi_mode mode, enum gdb_osabi osabi); + +/* Return current osabi setting in MODE/OSABI. */ +extern void get_osabi (enum gdb_osabi_mode &mode, enum gdb_osabi &osabi); + #endif /* OSABI_H */ diff --git a/gdb/selftest-arch.c b/gdb/selftest-arch.c index f434da718d5..a4d9de5a74d 100644 --- a/gdb/selftest-arch.c +++ b/gdb/selftest-arch.c @@ -66,12 +66,28 @@ foreach_arch_test_generator (const std::string &name, auto test_fn =3D ([=3D] () { + /* Prevent warnings when setting architecture with current osabi + settings, like: + A handler for the OS ABI "GNU/Linux" is not built into this + configuration of GDB. Attempting to continue with the + default aarch64:ilp32 settings. */ + enum gdb_osabi_mode mode; + enum gdb_osabi osabi; + get_osabi (mode, osabi); + + set_osabi (osabi_user, GDB_OSABI_NONE); + SCOPE_EXIT + { + reset (); + set_osabi (mode, osabi); + }; + struct gdbarch_info info; info.bfd_arch_info =3D bfd_scan_arch (arch); struct gdbarch *gdbarch =3D gdbarch_find_by_info (info); SELF_CHECK (gdbarch !=3D NULL); + function (gdbarch); - reset (); }); =20 tests.emplace_back (string_printf ("%s::%s", name.c_str (), arch),