diff options
Diffstat (limited to 'gdb/selftest-arch.c')
-rw-r--r-- | gdb/selftest-arch.c | 134 |
1 files changed, 66 insertions, 68 deletions
diff --git a/gdb/selftest-arch.c b/gdb/selftest-arch.c index 522b1da..1ddc663 100644 --- a/gdb/selftest-arch.c +++ b/gdb/selftest-arch.c @@ -25,12 +25,75 @@ namespace selftests { -static std::vector<self_test_foreach_arch_function *> gdbarch_tests; +/* A kind of selftest that calls the test function once for each gdbarch known + to GDB. */ + +struct gdbarch_selftest : public selftest +{ + 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 (ex, RETURN_MASK_ERROR) + { + pass = false; + exception_fprintf (gdb_stderr, ex, + _("Self test failed: arch %s: "), arches[i]); + } + END_CATCH + + reset (); + } + + SELF_CHECK (pass); + } + + self_test_foreach_arch_function *function; +}; void -register_test_foreach_arch (self_test_foreach_arch_function *function) +register_test_foreach_arch (const std::string &name, + self_test_foreach_arch_function *function) { - gdbarch_tests.push_back (function); + register_test (name, new gdbarch_selftest (function)); } void @@ -40,70 +103,5 @@ reset () registers_changed (); reinit_frame_cache (); } - -static void -tests_with_arch () -{ - 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 - - reset (); - } - } - - SELF_CHECK (failed == 0); -} - } // namespace selftests #endif /* GDB_SELF_TEST */ - -void -_initialize_selftests_foreach_arch () -{ -#if GDB_SELF_TEST - selftests::register_test (selftests::tests_with_arch); -#endif -} |