Files
binutils-gdb/gdb/selftest-arch.c
Tom de Vries fc18b1c5af [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.
2022-06-01 19:29:40 +02:00

120 lines
3.0 KiB
C

/* GDB self-test for each gdbarch.
Copyright (C) 2017-2022 Free Software Foundation, Inc.
This file is part of GDB.
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/>. */
#include "defs.h"
#include <functional>
#if GDB_SELF_TEST
#include "gdbsupport/selftest.h"
#include "selftest-arch.h"
#include "arch-utils.h"
namespace selftests {
static bool skip_arch (const char *arch)
{
if (strcmp ("fr300", arch) == 0)
{
/* PR 20946 */
return true;
}
if (strcmp ("powerpc:EC603e", arch) == 0
|| strcmp ("powerpc:e500mc", arch) == 0
|| strcmp ("powerpc:e500mc64", arch) == 0
|| strcmp ("powerpc:titan", arch) == 0
|| strcmp ("powerpc:vle", arch) == 0
|| strcmp ("powerpc:e5500", arch) == 0
|| strcmp ("powerpc:e6500", arch) == 0)
{
/* PR 19797 */
return true;
}
return false;
}
/* Generate a selftest for each gdbarch known to GDB. */
static std::vector<selftest>
foreach_arch_test_generator (const std::string &name,
self_test_foreach_arch_function *function)
{
std::vector<selftest> tests;
std::vector<const char *> arches = gdbarch_printable_names ();
tests.reserve (arches.size ());
for (const char *arch : arches)
{
if (skip_arch (arch))
continue;
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;
info.bfd_arch_info = bfd_scan_arch (arch);
struct gdbarch *gdbarch = gdbarch_find_by_info (info);
SELF_CHECK (gdbarch != NULL);
function (gdbarch);
});
tests.emplace_back (string_printf ("%s::%s", name.c_str (), arch),
test_fn);
}
return tests;
}
/* See selftest-arch.h. */
void
register_test_foreach_arch (const std::string &name,
self_test_foreach_arch_function *function)
{
add_lazy_generator ([=] ()
{
return foreach_arch_test_generator (name, function);
});
}
void
reset ()
{
/* Clear GDB internal state. */
registers_changed ();
reinit_frame_cache ();
}
} // namespace selftests
#endif /* GDB_SELF_TEST */