diff --git a/gdb/selftest-arch.c b/gdb/selftest-arch.c index 052daed9196..935459def27 100644 --- a/gdb/selftest-arch.c +++ b/gdb/selftest-arch.c @@ -17,6 +17,7 @@ along with this program. If not, see . */ #include "defs.h" +#include #if GDB_SELF_TEST #include "gdbsupport/selftest.h" @@ -25,73 +26,57 @@ namespace selftests { -/* A kind of selftest that calls the test function once for each gdbarch known - to GDB. */ - -struct gdbarch_selftest : public selftest +static bool skip_arch (const char *arch) { - gdbarch_selftest (self_test_foreach_arch_function *function_) - : function (function_) - {} + if (strcmp ("fr300", arch) == 0) + { + /* PR 20946 */ + return true; + } - void operator() () const override - { - std::vector arches = gdbarch_printable_names (); - bool pass = 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; + } - for (const char *arch : arches) - { - if (strcmp ("fr300", arch) == 0) - { - /* PR 20946 */ - continue; - } - else 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 */ - continue; - } + return false; +} - QUIT; - - try - { - 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); - } - catch (const gdb_exception_error &ex) - { - pass = false; - exception_fprintf (gdb_stderr, ex, - _("Self test failed: arch %s: "), arch); - } - - reset (); - } - - SELF_CHECK (pass); - } - - self_test_foreach_arch_function *function; -}; +/* Register a kind of selftest that calls the test function once for each + gdbarch known to GDB. */ void register_test_foreach_arch (const std::string &name, self_test_foreach_arch_function *function) { - register_test (name, new gdbarch_selftest (function)); + std::vector arches = gdbarch_printable_names (); + for (const char *arch : arches) + { + if (skip_arch (arch)) + continue; + + auto test_fn + = ([=] () + { + 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); + reset (); + }); + + std::string test_name + = name + std::string ("::") + std::string (arch); + register_test (test_name, test_fn); + } } void