selftest-arch.c revision 1.1.1.3.2.1 1 1.1 christos /* GDB self-test for each gdbarch.
2 1.1.1.3.2.1 perseant Copyright (C) 2017-2023 Free Software Foundation, Inc.
3 1.1 christos
4 1.1 christos This file is part of GDB.
5 1.1 christos
6 1.1 christos This program is free software; you can redistribute it and/or modify
7 1.1 christos it under the terms of the GNU General Public License as published by
8 1.1 christos the Free Software Foundation; either version 3 of the License, or
9 1.1 christos (at your option) any later version.
10 1.1 christos
11 1.1 christos This program is distributed in the hope that it will be useful,
12 1.1 christos but WITHOUT ANY WARRANTY; without even the implied warranty of
13 1.1 christos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 1.1 christos GNU General Public License for more details.
15 1.1 christos
16 1.1 christos You should have received a copy of the GNU General Public License
17 1.1 christos along with this program. If not, see <http://www.gnu.org/licenses/>. */
18 1.1 christos
19 1.1 christos #include "defs.h"
20 1.1.1.3.2.1 perseant #include <functional>
21 1.1 christos
22 1.1 christos #if GDB_SELF_TEST
23 1.1.1.3 christos #include "gdbsupport/selftest.h"
24 1.1 christos #include "selftest-arch.h"
25 1.1 christos #include "arch-utils.h"
26 1.1 christos
27 1.1 christos namespace selftests {
28 1.1 christos
29 1.1.1.3.2.1 perseant static bool skip_arch (const char *arch)
30 1.1 christos {
31 1.1.1.3.2.1 perseant if (strcmp ("powerpc:EC603e", arch) == 0
32 1.1.1.3.2.1 perseant || strcmp ("powerpc:e500mc", arch) == 0
33 1.1.1.3.2.1 perseant || strcmp ("powerpc:e500mc64", arch) == 0
34 1.1.1.3.2.1 perseant || strcmp ("powerpc:titan", arch) == 0
35 1.1.1.3.2.1 perseant || strcmp ("powerpc:vle", arch) == 0
36 1.1.1.3.2.1 perseant || strcmp ("powerpc:e5500", arch) == 0
37 1.1.1.3.2.1 perseant || strcmp ("powerpc:e6500", arch) == 0)
38 1.1.1.3.2.1 perseant {
39 1.1.1.3.2.1 perseant /* PR 19797 */
40 1.1.1.3.2.1 perseant return true;
41 1.1.1.3.2.1 perseant }
42 1.1.1.3.2.1 perseant
43 1.1.1.3.2.1 perseant return false;
44 1.1.1.3.2.1 perseant }
45 1.1 christos
46 1.1.1.3.2.1 perseant /* Generate a selftest for each gdbarch known to GDB. */
47 1.1 christos
48 1.1.1.3.2.1 perseant static std::vector<selftest>
49 1.1.1.3.2.1 perseant foreach_arch_test_generator (const std::string &name,
50 1.1.1.3.2.1 perseant self_test_foreach_arch_function *function)
51 1.1.1.3.2.1 perseant {
52 1.1.1.3.2.1 perseant std::vector<selftest> tests;
53 1.1.1.3.2.1 perseant std::vector<const char *> arches = gdbarch_printable_names ();
54 1.1.1.3.2.1 perseant tests.reserve (arches.size ());
55 1.1.1.3.2.1 perseant for (const char *arch : arches)
56 1.1.1.3.2.1 perseant {
57 1.1.1.3.2.1 perseant if (skip_arch (arch))
58 1.1.1.3.2.1 perseant continue;
59 1.1.1.3.2.1 perseant
60 1.1.1.3.2.1 perseant struct gdbarch_info info;
61 1.1.1.3.2.1 perseant info.bfd_arch_info = bfd_scan_arch (arch);
62 1.1.1.3.2.1 perseant info.osabi = GDB_OSABI_NONE;
63 1.1.1.3.2.1 perseant
64 1.1.1.3.2.1 perseant auto test_fn
65 1.1.1.3.2.1 perseant = ([=] ()
66 1.1.1.3.2.1 perseant {
67 1.1.1.3.2.1 perseant struct gdbarch *gdbarch = gdbarch_find_by_info (info);
68 1.1.1.3.2.1 perseant SELF_CHECK (gdbarch != NULL);
69 1.1.1.3.2.1 perseant function (gdbarch);
70 1.1.1.3.2.1 perseant reset ();
71 1.1.1.3.2.1 perseant });
72 1.1.1.3.2.1 perseant
73 1.1.1.3.2.1 perseant std::string id;
74 1.1.1.3.2.1 perseant
75 1.1.1.3.2.1 perseant bool has_sep = strchr (arch, ':') != nullptr;
76 1.1.1.3.2.1 perseant if (has_sep)
77 1.1.1.3.2.1 perseant /* Avoid avr::avr:1. */
78 1.1.1.3.2.1 perseant id = arch;
79 1.1.1.3.2.1 perseant else if (strncasecmp (info.bfd_arch_info->arch_name, arch,
80 1.1.1.3.2.1 perseant strlen (info.bfd_arch_info->arch_name)) == 0)
81 1.1.1.3.2.1 perseant /* Avoid arm::arm. */
82 1.1.1.3.2.1 perseant id = arch;
83 1.1.1.3.2.1 perseant else
84 1.1.1.3.2.1 perseant /* Use arc::A6 instead of A6. This still leaves us with an unfortunate
85 1.1.1.3.2.1 perseant redundant id like am33_2::am33-2, but that doesn't seem worth the
86 1.1.1.3.2.1 perseant effort to avoid. */
87 1.1.1.3.2.1 perseant id = string_printf ("%s::%s", info.bfd_arch_info->arch_name, arch);
88 1.1.1.3.2.1 perseant
89 1.1.1.3.2.1 perseant id = string_printf ("%s::%s", name.c_str (), id.c_str ());
90 1.1.1.3.2.1 perseant tests.emplace_back (id, test_fn);
91 1.1.1.3.2.1 perseant }
92 1.1.1.3.2.1 perseant return tests;
93 1.1.1.3.2.1 perseant }
94 1.1 christos
95 1.1.1.3.2.1 perseant /* See selftest-arch.h. */
96 1.1 christos
97 1.1.1.2 christos void
98 1.1.1.2 christos register_test_foreach_arch (const std::string &name,
99 1.1.1.2 christos self_test_foreach_arch_function *function)
100 1.1.1.2 christos {
101 1.1.1.3.2.1 perseant add_lazy_generator ([=] ()
102 1.1.1.3.2.1 perseant {
103 1.1.1.3.2.1 perseant return foreach_arch_test_generator (name, function);
104 1.1.1.3.2.1 perseant });
105 1.1.1.2 christos }
106 1.1 christos
107 1.1 christos void
108 1.1.1.2 christos reset ()
109 1.1 christos {
110 1.1.1.2 christos /* Clear GDB internal state. */
111 1.1.1.2 christos registers_changed ();
112 1.1.1.2 christos reinit_frame_cache ();
113 1.1 christos }
114 1.1.1.2 christos } // namespace selftests
115 1.1.1.2 christos #endif /* GDB_SELF_TEST */
116