[gdb] Fix warning in foreach_arch selftests

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.

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".

Fix the warning by setting osabi to none while doing selftests that iterate
over all architectures.

Tested on x86_64-linux.
This commit is contained in:
Tom de Vries 2022-06-01 19:29:40 +02:00
parent 80fa4b2a60
commit fc18b1c5af
3 changed files with 68 additions and 13 deletions

View file

@ -32,7 +32,7 @@
#endif #endif
/* State for the "set osabi" command. */ /* 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 enum gdb_osabi user_selected_osabi;
static const char *gdb_osabi_available_names[GDB_OSABI_INVALID + 3] = { static const char *gdb_osabi_available_names[GDB_OSABI_INVALID + 3] = {
"auto", "auto",
@ -595,15 +595,48 @@ generic_elf_osabi_sniffer (bfd *abfd)
return osabi; return osabi;
} }
/* See osabi.h. */
void
set_osabi (enum gdb_osabi_mode mode, enum gdb_osabi osabi)
{
if (mode == osabi_auto)
user_osabi_state = osabi_auto;
else if (mode == osabi_default)
{
user_selected_osabi = GDB_OSABI_DEFAULT;
user_osabi_state = osabi_user;
}
else
{
user_selected_osabi = osabi;
user_osabi_state = osabi_user;
}
/* NOTE: At some point (true multiple architectures) we'll need to be more
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 = user_osabi_state;
osabi = user_selected_osabi;
}
static void static void
set_osabi (const char *args, int from_tty, struct cmd_list_element *c) set_osabi (const char *args, int from_tty, struct cmd_list_element *c)
{ {
if (strcmp (set_osabi_string, "auto") == 0) if (strcmp (set_osabi_string, "auto") == 0)
user_osabi_state = osabi_auto; set_osabi (osabi_auto, GDB_OSABI_INVALID);
else if (strcmp (set_osabi_string, "default") == 0) else if (strcmp (set_osabi_string, "default") == 0)
{ {
user_selected_osabi = GDB_OSABI_DEFAULT; set_osabi (osabi_default, GDB_OSABI_INVALID);
user_osabi_state = osabi_user;
} }
else else
{ {
@ -615,8 +648,7 @@ set_osabi (const char *args, int from_tty, struct cmd_list_element *c)
if (strcmp (set_osabi_string, gdbarch_osabi_name (osabi)) == 0) if (strcmp (set_osabi_string, gdbarch_osabi_name (osabi)) == 0)
{ {
user_selected_osabi = osabi; set_osabi (osabi_user, osabi);
user_osabi_state = osabi_user;
break; 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."), _("Invalid OS ABI \"%s\" passed to command handler."),
set_osabi_string); set_osabi_string);
} }
/* NOTE: At some point (true multiple architectures) we'll need to be more
graceful here. */
gdbarch_info info;
if (! gdbarch_update_p (info))
internal_error (__FILE__, __LINE__, _("Updating OS ABI failed."));
} }
static void static void

View file

@ -50,6 +50,13 @@ enum gdb_osabi
GDB_OSABI_INVALID /* keep this last */ GDB_OSABI_INVALID /* keep this last */
}; };
enum gdb_osabi_mode
{
osabi_auto,
osabi_default,
osabi_user
};
/* Register an OS ABI sniffer. Each arch/flavour may have more than /* 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 one sniffer. This is used to e.g. differentiate one OS's a.out from
another. The first sniffer to return something other than 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 *, void generic_elf_osabi_sniff_abi_tag_sections (bfd *, asection *,
enum gdb_osabi *); enum gdb_osabi *);
/* 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 */ #endif /* OSABI_H */

View file

@ -66,12 +66,28 @@ foreach_arch_test_generator (const std::string &name,
auto test_fn auto test_fn
= ([=] () = ([=] ()
{ {
/* 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; struct gdbarch_info info;
info.bfd_arch_info = bfd_scan_arch (arch); info.bfd_arch_info = bfd_scan_arch (arch);
struct gdbarch *gdbarch = gdbarch_find_by_info (info); struct gdbarch *gdbarch = gdbarch_find_by_info (info);
SELF_CHECK (gdbarch != NULL); SELF_CHECK (gdbarch != NULL);
function (gdbarch); function (gdbarch);
reset ();
}); });
tests.emplace_back (string_printf ("%s::%s", name.c_str (), arch), tests.emplace_back (string_printf ("%s::%s", name.c_str (), arch),