selftest-arch.c revision 1.1.1.3 1 1.1 christos /* GDB self-test for each gdbarch.
2 1.1.1.3 christos Copyright (C) 2017-2020 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 christos
21 1.1 christos #if GDB_SELF_TEST
22 1.1.1.3 christos #include "gdbsupport/selftest.h"
23 1.1 christos #include "selftest-arch.h"
24 1.1 christos #include "arch-utils.h"
25 1.1 christos
26 1.1 christos namespace selftests {
27 1.1 christos
28 1.1.1.2 christos /* A kind of selftest that calls the test function once for each gdbarch known
29 1.1.1.2 christos to GDB. */
30 1.1.1.2 christos
31 1.1.1.2 christos struct gdbarch_selftest : public selftest
32 1.1 christos {
33 1.1.1.2 christos gdbarch_selftest (self_test_foreach_arch_function *function_)
34 1.1.1.2 christos : function (function_)
35 1.1.1.2 christos {}
36 1.1.1.2 christos
37 1.1.1.2 christos void operator() () const override
38 1.1.1.2 christos {
39 1.1.1.2 christos const char **arches = gdbarch_printable_names ();
40 1.1.1.2 christos bool pass = true;
41 1.1.1.2 christos
42 1.1.1.2 christos for (int i = 0; arches[i] != NULL; i++)
43 1.1.1.2 christos {
44 1.1.1.2 christos if (strcmp ("fr300", arches[i]) == 0)
45 1.1.1.2 christos {
46 1.1.1.2 christos /* PR 20946 */
47 1.1.1.2 christos continue;
48 1.1.1.2 christos }
49 1.1.1.2 christos else if (strcmp ("powerpc:EC603e", arches[i]) == 0
50 1.1.1.2 christos || strcmp ("powerpc:e500mc", arches[i]) == 0
51 1.1.1.2 christos || strcmp ("powerpc:e500mc64", arches[i]) == 0
52 1.1.1.2 christos || strcmp ("powerpc:titan", arches[i]) == 0
53 1.1.1.2 christos || strcmp ("powerpc:vle", arches[i]) == 0
54 1.1.1.2 christos || strcmp ("powerpc:e5500", arches[i]) == 0
55 1.1.1.2 christos || strcmp ("powerpc:e6500", arches[i]) == 0)
56 1.1.1.2 christos {
57 1.1.1.2 christos /* PR 19797 */
58 1.1.1.2 christos continue;
59 1.1.1.2 christos }
60 1.1.1.2 christos
61 1.1.1.2 christos QUIT;
62 1.1.1.2 christos
63 1.1.1.3 christos try
64 1.1.1.2 christos {
65 1.1.1.2 christos struct gdbarch_info info;
66 1.1.1.2 christos
67 1.1.1.2 christos gdbarch_info_init (&info);
68 1.1.1.2 christos info.bfd_arch_info = bfd_scan_arch (arches[i]);
69 1.1.1.2 christos
70 1.1.1.2 christos struct gdbarch *gdbarch = gdbarch_find_by_info (info);
71 1.1.1.2 christos SELF_CHECK (gdbarch != NULL);
72 1.1.1.2 christos
73 1.1.1.2 christos function (gdbarch);
74 1.1.1.2 christos }
75 1.1.1.3 christos catch (const gdb_exception_error &ex)
76 1.1.1.2 christos {
77 1.1.1.2 christos pass = false;
78 1.1.1.2 christos exception_fprintf (gdb_stderr, ex,
79 1.1.1.2 christos _("Self test failed: arch %s: "), arches[i]);
80 1.1.1.2 christos }
81 1.1 christos
82 1.1.1.2 christos reset ();
83 1.1.1.2 christos }
84 1.1 christos
85 1.1.1.2 christos SELF_CHECK (pass);
86 1.1.1.2 christos }
87 1.1 christos
88 1.1.1.2 christos self_test_foreach_arch_function *function;
89 1.1.1.2 christos };
90 1.1 christos
91 1.1.1.2 christos void
92 1.1.1.2 christos register_test_foreach_arch (const std::string &name,
93 1.1.1.2 christos self_test_foreach_arch_function *function)
94 1.1.1.2 christos {
95 1.1.1.2 christos register_test (name, new gdbarch_selftest (function));
96 1.1.1.2 christos }
97 1.1 christos
98 1.1 christos void
99 1.1.1.2 christos reset ()
100 1.1 christos {
101 1.1.1.2 christos /* Clear GDB internal state. */
102 1.1.1.2 christos registers_changed ();
103 1.1.1.2 christos reinit_frame_cache ();
104 1.1 christos }
105 1.1.1.2 christos } // namespace selftests
106 1.1.1.2 christos #endif /* GDB_SELF_TEST */
107