ODR warning for "enum string_repr_result"
[binutils-gdb.git] / gdb / selftest-arch.c
1 /* GDB self-test for each gdbarch.
2 Copyright (C) 2017-2022 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 #include <functional>
21
22 #if GDB_SELF_TEST
23 #include "gdbsupport/selftest.h"
24 #include "selftest-arch.h"
25 #include "arch-utils.h"
26
27 namespace selftests {
28
29 static bool skip_arch (const char *arch)
30 {
31 if (strcmp ("fr300", arch) == 0)
32 {
33 /* PR 20946 */
34 return true;
35 }
36
37 if (strcmp ("powerpc:EC603e", arch) == 0
38 || strcmp ("powerpc:e500mc", arch) == 0
39 || strcmp ("powerpc:e500mc64", arch) == 0
40 || strcmp ("powerpc:titan", arch) == 0
41 || strcmp ("powerpc:vle", arch) == 0
42 || strcmp ("powerpc:e5500", arch) == 0
43 || strcmp ("powerpc:e6500", arch) == 0)
44 {
45 /* PR 19797 */
46 return true;
47 }
48
49 return false;
50 }
51
52 /* Generate a selftest for each gdbarch known to GDB. */
53
54 static std::vector<selftest>
55 foreach_arch_test_generator (const std::string &name,
56 self_test_foreach_arch_function *function)
57 {
58 std::vector<selftest> tests;
59 std::vector<const char *> arches = gdbarch_printable_names ();
60 tests.reserve (arches.size ());
61 for (const char *arch : arches)
62 {
63 if (skip_arch (arch))
64 continue;
65
66 auto test_fn
67 = ([=] ()
68 {
69 /* Prevent warnings when setting architecture with current osabi
70 settings, like:
71 A handler for the OS ABI "GNU/Linux" is not built into this
72 configuration of GDB. Attempting to continue with the
73 default aarch64:ilp32 settings. */
74 enum gdb_osabi_mode mode;
75 enum gdb_osabi osabi;
76 get_osabi (mode, osabi);
77
78 set_osabi (osabi_user, GDB_OSABI_NONE);
79 SCOPE_EXIT
80 {
81 reset ();
82 set_osabi (mode, osabi);
83 };
84
85 struct gdbarch_info info;
86 info.bfd_arch_info = bfd_scan_arch (arch);
87 struct gdbarch *gdbarch = gdbarch_find_by_info (info);
88 SELF_CHECK (gdbarch != NULL);
89
90 function (gdbarch);
91 });
92
93 tests.emplace_back (string_printf ("%s::%s", name.c_str (), arch),
94 test_fn);
95 }
96 return tests;
97 }
98
99 /* See selftest-arch.h. */
100
101 void
102 register_test_foreach_arch (const std::string &name,
103 self_test_foreach_arch_function *function)
104 {
105 add_lazy_generator ([=] ()
106 {
107 return foreach_arch_test_generator (name, function);
108 });
109 }
110
111 void
112 reset ()
113 {
114 /* Clear GDB internal state. */
115 registers_changed ();
116 reinit_frame_cache ();
117 }
118 } // namespace selftests
119 #endif /* GDB_SELF_TEST */