]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/selftest-arch.c
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / selftest-arch.c
CommitLineData
79843d45 1/* GDB self-test for each gdbarch.
213516ef 2 Copyright (C) 2017-2023 Free Software Foundation, Inc.
79843d45
YQ
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"
ff1c1bb9 20#include <functional>
79843d45
YQ
21
22#if GDB_SELF_TEST
268a13a5 23#include "gdbsupport/selftest.h"
79843d45
YQ
24#include "selftest-arch.h"
25#include "arch-utils.h"
26
7649770c
YQ
27namespace selftests {
28
ff1c1bb9 29static bool skip_arch (const char *arch)
1526853e 30{
ff1c1bb9
TV
31 if (strcmp ("powerpc:EC603e", arch) == 0
32 || strcmp ("powerpc:e500mc", arch) == 0
33 || strcmp ("powerpc:e500mc64", arch) == 0
34 || strcmp ("powerpc:titan", arch) == 0
35 || strcmp ("powerpc:vle", arch) == 0
36 || strcmp ("powerpc:e5500", arch) == 0
37 || strcmp ("powerpc:e6500", arch) == 0)
38 {
39 /* PR 19797 */
40 return true;
41 }
42
43 return false;
44}
1526853e 45
531c82a1 46/* Generate a selftest for each gdbarch known to GDB. */
79843d45 47
531c82a1
LS
48static std::vector<selftest>
49foreach_arch_test_generator (const std::string &name,
50 self_test_foreach_arch_function *function)
79843d45 51{
531c82a1 52 std::vector<selftest> tests;
ff1c1bb9 53 std::vector<const char *> arches = gdbarch_printable_names ();
531c82a1 54 tests.reserve (arches.size ());
ff1c1bb9
TV
55 for (const char *arch : arches)
56 {
57 if (skip_arch (arch))
58 continue;
59
38015f67
TV
60 struct gdbarch_info info;
61 info.bfd_arch_info = bfd_scan_arch (arch);
62 info.osabi = GDB_OSABI_NONE;
63
ff1c1bb9
TV
64 auto test_fn
65 = ([=] ()
66 {
ff1c1bb9
TV
67 struct gdbarch *gdbarch = gdbarch_find_by_info (info);
68 SELF_CHECK (gdbarch != NULL);
69 function (gdbarch);
0e02119e 70 reset ();
ff1c1bb9
TV
71 });
72
38015f67
TV
73 std::string id;
74
75 bool has_sep = strchr (arch, ':') != nullptr;
76 if (has_sep)
77 /* Avoid avr::avr:1. */
78 id = arch;
79 else if (strncasecmp (info.bfd_arch_info->arch_name, arch,
80 strlen (info.bfd_arch_info->arch_name)) == 0)
81 /* Avoid arm::arm. */
82 id = arch;
83 else
84 /* Use arc::A6 instead of A6. This still leaves us with an unfortunate
85 redundant id like am33_2::am33-2, but that doesn't seem worth the
86 effort to avoid. */
87 id = string_printf ("%s::%s", info.bfd_arch_info->arch_name, arch);
88
89 id = string_printf ("%s::%s", name.c_str (), id.c_str ());
90 tests.emplace_back (id, test_fn);
ff1c1bb9 91 }
531c82a1
LS
92 return tests;
93}
94
95/* See selftest-arch.h. */
96
97void
98register_test_foreach_arch (const std::string &name,
99 self_test_foreach_arch_function *function)
100{
101 add_lazy_generator ([=] ()
102 {
103 return foreach_arch_test_generator (name, function);
104 });
79843d45
YQ
105}
106
6d580b63
YQ
107void
108reset ()
109{
110 /* Clear GDB internal state. */
111 registers_changed ();
112 reinit_frame_cache ();
113}
79843d45
YQ
114} // namespace selftests
115#endif /* GDB_SELF_TEST */