Remove unnecessary function prototypes.
[external/binutils.git] / gdb / selftest-arch.c
1 /* GDB self-test for each gdbarch.
2    Copyright (C) 2017 Free Software Foundation, Inc.
3
4    This file is part of GDB.
5
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 3 of the License, or
9    (at your option) any later version.
10
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15
16    You should have received a copy of the GNU General Public License
17    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
18
19 #include "defs.h"
20
21 #if GDB_SELF_TEST
22 #include "selftest.h"
23 #include "selftest-arch.h"
24 #include "arch-utils.h"
25
26 namespace selftests {
27
28 static std::vector<self_test_foreach_arch_function *> gdbarch_tests;
29
30 void
31 register_test_foreach_arch (self_test_foreach_arch_function *function)
32 {
33   gdbarch_tests.push_back (function);
34 }
35
36 void
37 reset ()
38 {
39   /* Clear GDB internal state.  */
40   registers_changed ();
41   reinit_frame_cache ();
42 }
43
44 static void
45 tests_with_arch ()
46 {
47   int failed = 0;
48
49   for (const auto &f : gdbarch_tests)
50     {
51       const char **arches = gdbarch_printable_names ();
52
53       for (int i = 0; arches[i] != NULL; i++)
54         {
55           if (strcmp ("fr300", arches[i]) == 0)
56             {
57               /* PR 20946 */
58               continue;
59             }
60           else if (strcmp ("powerpc:EC603e", arches[i]) == 0
61                    || strcmp ("powerpc:e500mc", arches[i]) == 0
62                    || strcmp ("powerpc:e500mc64", arches[i]) == 0
63                    || strcmp ("powerpc:titan", arches[i]) == 0
64                    || strcmp ("powerpc:vle", arches[i]) == 0
65                    || strcmp ("powerpc:e5500", arches[i]) == 0
66                    || strcmp ("powerpc:e6500", arches[i]) == 0)
67             {
68               /* PR 19797 */
69               continue;
70             }
71
72           QUIT;
73
74           TRY
75             {
76               struct gdbarch_info info;
77
78               gdbarch_info_init (&info);
79               info.bfd_arch_info = bfd_scan_arch (arches[i]);
80
81               struct gdbarch *gdbarch = gdbarch_find_by_info (info);
82               SELF_CHECK (gdbarch != NULL);
83               f (gdbarch);
84             }
85           CATCH (ex, RETURN_MASK_ERROR)
86             {
87               ++failed;
88               exception_fprintf (gdb_stderr, ex,
89                                  _("Self test failed: arch %s: "), arches[i]);
90             }
91           END_CATCH
92
93           reset ();
94         }
95     }
96
97   SELF_CHECK (failed == 0);
98 }
99
100 } // namespace selftests
101 #endif /* GDB_SELF_TEST */
102
103 void
104 _initialize_selftests_foreach_arch ()
105 {
106 #if GDB_SELF_TEST
107   selftests::register_test (selftests::tests_with_arch);
108 #endif
109 }