X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=gdb%2Fselftest-arch.c;h=91d9f8673724e7b3160867bb5e6eb68b8afa3349;hb=991fb595e34598291a52b533fdc8005e1ead0799;hp=dfcbe274328b35350db17969208f5f75b3daefc1;hpb=7649770c8e52afe2696a70bb50ac3039c844d381;p=deliverable%2Fbinutils-gdb.git diff --git a/gdb/selftest-arch.c b/gdb/selftest-arch.c index dfcbe27432..91d9f86737 100644 --- a/gdb/selftest-arch.c +++ b/gdb/selftest-arch.c @@ -1,5 +1,5 @@ /* GDB self-test for each gdbarch. - Copyright (C) 2017 Free Software Foundation, Inc. + Copyright (C) 2017-2020 Free Software Foundation, Inc. This file is part of GDB. @@ -19,88 +19,88 @@ #include "defs.h" #if GDB_SELF_TEST -#include "selftest.h" +#include "gdbsupport/selftest.h" #include "selftest-arch.h" #include "arch-utils.h" namespace selftests { -static std::vector gdbarch_tests; +/* A kind of selftest that calls the test function once for each gdbarch known + to GDB. */ -void -register_test_foreach_arch (self_test_foreach_arch_function *function) +struct gdbarch_selftest : public selftest { - gdbarch_tests.push_back (function); -} + gdbarch_selftest (self_test_foreach_arch_function *function_) + : function (function_) + {} + + void operator() () const override + { + const char **arches = gdbarch_printable_names (); + bool pass = true; + + for (int i = 0; arches[i] != NULL; i++) + { + if (strcmp ("fr300", arches[i]) == 0) + { + /* PR 20946 */ + continue; + } + else if (strcmp ("powerpc:EC603e", arches[i]) == 0 + || strcmp ("powerpc:e500mc", arches[i]) == 0 + || strcmp ("powerpc:e500mc64", arches[i]) == 0 + || strcmp ("powerpc:titan", arches[i]) == 0 + || strcmp ("powerpc:vle", arches[i]) == 0 + || strcmp ("powerpc:e5500", arches[i]) == 0 + || strcmp ("powerpc:e6500", arches[i]) == 0) + { + /* PR 19797 */ + continue; + } + + QUIT; + + try + { + struct gdbarch_info info; + + gdbarch_info_init (&info); + info.bfd_arch_info = bfd_scan_arch (arches[i]); + + 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: "), arches[i]); + } + + reset (); + } + + SELF_CHECK (pass); + } + + self_test_foreach_arch_function *function; +}; -static void -tests_with_arch () +void +register_test_foreach_arch (const std::string &name, + self_test_foreach_arch_function *function) { - int failed = 0; - - for (const auto &f : gdbarch_tests) - { - const char **arches = gdbarch_printable_names (); - - for (int i = 0; arches[i] != NULL; i++) - { - if (strcmp ("fr300", arches[i]) == 0) - { - /* PR 20946 */ - continue; - } - else if (strcmp ("powerpc:EC603e", arches[i]) == 0 - || strcmp ("powerpc:e500mc", arches[i]) == 0 - || strcmp ("powerpc:e500mc64", arches[i]) == 0 - || strcmp ("powerpc:titan", arches[i]) == 0 - || strcmp ("powerpc:vle", arches[i]) == 0 - || strcmp ("powerpc:e5500", arches[i]) == 0 - || strcmp ("powerpc:e6500", arches[i]) == 0) - { - /* PR 19797 */ - continue; - } - - QUIT; - - TRY - { - struct gdbarch_info info; - - gdbarch_info_init (&info); - info.bfd_arch_info = bfd_scan_arch (arches[i]); - - struct gdbarch *gdbarch = gdbarch_find_by_info (info); - SELF_CHECK (gdbarch != NULL); - f (gdbarch); - } - CATCH (ex, RETURN_MASK_ERROR) - { - ++failed; - exception_fprintf (gdb_stderr, ex, - _("Self test failed: arch %s: "), arches[i]); - } - END_CATCH - - /* Clear GDB internal state. */ - registers_changed (); - reinit_frame_cache (); - } - } - - SELF_CHECK (failed == 0); + register_test (name, new gdbarch_selftest (function)); } -} // namespace selftests -#endif /* GDB_SELF_TEST */ - -/* Suppress warning from -Wmissing-prototypes. */ -extern initialize_file_ftype _initialize_selftests_foreach_arch; - void -_initialize_selftests_foreach_arch () +reset () { -#if GDB_SELF_TEST - selftests::register_test (selftests::tests_with_arch); -#endif + /* Clear GDB internal state. */ + registers_changed (); + reinit_frame_cache (); } +} // namespace selftests +#endif /* GDB_SELF_TEST */