Automatic date update in version.in
[binutils-gdb.git] / gdb / selftest-arch.c
bloba337f76083abc446f581fb3486c6febf313f4134
1 /* GDB self-test for each gdbarch.
2 Copyright (C) 2017-2024 Free Software Foundation, Inc.
4 This file is part of GDB.
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.
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.
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/>. */
19 #include <functional>
21 #if GDB_SELF_TEST
22 #include "gdbsupport/selftest.h"
23 #include "selftest-arch.h"
24 #include "arch-utils.h"
26 namespace selftests {
28 static bool skip_arch (const char *arch)
30 if (strcmp ("powerpc:EC603e", arch) == 0
31 || strcmp ("powerpc:e500mc", arch) == 0
32 || strcmp ("powerpc:e500mc64", arch) == 0
33 || strcmp ("powerpc:titan", arch) == 0
34 || strcmp ("powerpc:vle", arch) == 0
35 || strcmp ("powerpc:e5500", arch) == 0
36 || strcmp ("powerpc:e6500", arch) == 0)
38 /* PR 19797 */
39 return true;
42 return false;
45 /* Generate a selftest for each gdbarch known to GDB. */
47 static std::vector<selftest>
48 foreach_arch_test_generator (const std::string &name,
49 self_test_foreach_arch_function *function)
51 std::vector<selftest> tests;
52 std::vector<const char *> arches = gdbarch_printable_names ();
53 tests.reserve (arches.size ());
54 for (const char *arch : arches)
56 if (skip_arch (arch))
57 continue;
59 struct gdbarch_info info;
60 info.bfd_arch_info = bfd_scan_arch (arch);
61 info.osabi = GDB_OSABI_NONE;
63 auto test_fn
64 = ([=] ()
66 struct gdbarch *gdbarch = gdbarch_find_by_info (info);
67 SELF_CHECK (gdbarch != NULL);
68 function (gdbarch);
69 reset ();
70 });
72 std::string id;
74 bool has_sep = strchr (arch, ':') != nullptr;
75 if (has_sep)
76 /* Avoid avr::avr:1. */
77 id = arch;
78 else if (strncasecmp (info.bfd_arch_info->arch_name, arch,
79 strlen (info.bfd_arch_info->arch_name)) == 0)
80 /* Avoid arm::arm. */
81 id = arch;
82 else
83 /* Use arc::A6 instead of A6. This still leaves us with an unfortunate
84 redundant id like am33_2::am33-2, but that doesn't seem worth the
85 effort to avoid. */
86 id = string_printf ("%s::%s", info.bfd_arch_info->arch_name, arch);
88 id = string_printf ("%s::%s", name.c_str (), id.c_str ());
89 tests.emplace_back (id, test_fn);
91 return tests;
94 /* See selftest-arch.h. */
96 void
97 register_test_foreach_arch (const std::string &name,
98 self_test_foreach_arch_function *function)
100 add_lazy_generator ([=] ()
101 { return foreach_arch_test_generator (name, function); });
104 void
105 reset ()
107 /* Clear GDB internal state. */
108 registers_changed ();
109 reinit_frame_cache ();
111 } // namespace selftests
112 #endif /* GDB_SELF_TEST */