1699b0f92Schristos /* GDB self-test for each gdbarch. 2*6881a400Schristos Copyright (C) 2017-2023 Free Software Foundation, Inc. 3699b0f92Schristos 4699b0f92Schristos This file is part of GDB. 5699b0f92Schristos 6699b0f92Schristos This program is free software; you can redistribute it and/or modify 7699b0f92Schristos it under the terms of the GNU General Public License as published by 8699b0f92Schristos the Free Software Foundation; either version 3 of the License, or 9699b0f92Schristos (at your option) any later version. 10699b0f92Schristos 11699b0f92Schristos This program is distributed in the hope that it will be useful, 12699b0f92Schristos but WITHOUT ANY WARRANTY; without even the implied warranty of 13699b0f92Schristos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14699b0f92Schristos GNU General Public License for more details. 15699b0f92Schristos 16699b0f92Schristos You should have received a copy of the GNU General Public License 17699b0f92Schristos along with this program. If not, see <http://www.gnu.org/licenses/>. */ 18699b0f92Schristos 19699b0f92Schristos #include "defs.h" 20*6881a400Schristos #include <functional> 21699b0f92Schristos 22699b0f92Schristos #if GDB_SELF_TEST 237d62b00eSchristos #include "gdbsupport/selftest.h" 24699b0f92Schristos #include "selftest-arch.h" 25699b0f92Schristos #include "arch-utils.h" 26699b0f92Schristos 27699b0f92Schristos namespace selftests { 28699b0f92Schristos 29*6881a400Schristos static bool skip_arch (const char *arch) 307f2ac410Schristos { 31*6881a400Schristos if (strcmp ("powerpc:EC603e", arch) == 0 32*6881a400Schristos || strcmp ("powerpc:e500mc", arch) == 0 33*6881a400Schristos || strcmp ("powerpc:e500mc64", arch) == 0 34*6881a400Schristos || strcmp ("powerpc:titan", arch) == 0 35*6881a400Schristos || strcmp ("powerpc:vle", arch) == 0 36*6881a400Schristos || strcmp ("powerpc:e5500", arch) == 0 37*6881a400Schristos || strcmp ("powerpc:e6500", arch) == 0) 38699b0f92Schristos { 39699b0f92Schristos /* PR 19797 */ 40*6881a400Schristos return true; 41699b0f92Schristos } 42699b0f92Schristos 43*6881a400Schristos return false; 44*6881a400Schristos } 45699b0f92Schristos 46*6881a400Schristos /* Generate a selftest for each gdbarch known to GDB. */ 47*6881a400Schristos 48*6881a400Schristos static std::vector<selftest> 49*6881a400Schristos foreach_arch_test_generator (const std::string &name, 50*6881a400Schristos self_test_foreach_arch_function *function) 51699b0f92Schristos { 52*6881a400Schristos std::vector<selftest> tests; 53*6881a400Schristos std::vector<const char *> arches = gdbarch_printable_names (); 54*6881a400Schristos tests.reserve (arches.size ()); 55*6881a400Schristos for (const char *arch : arches) 56*6881a400Schristos { 57*6881a400Schristos if (skip_arch (arch)) 58*6881a400Schristos continue; 59*6881a400Schristos 60699b0f92Schristos struct gdbarch_info info; 61*6881a400Schristos info.bfd_arch_info = bfd_scan_arch (arch); 62*6881a400Schristos info.osabi = GDB_OSABI_NONE; 63699b0f92Schristos 64*6881a400Schristos auto test_fn 65*6881a400Schristos = ([=] () 66*6881a400Schristos { 67699b0f92Schristos struct gdbarch *gdbarch = gdbarch_find_by_info (info); 68699b0f92Schristos SELF_CHECK (gdbarch != NULL); 697f2ac410Schristos function (gdbarch); 707f2ac410Schristos reset (); 71*6881a400Schristos }); 72*6881a400Schristos 73*6881a400Schristos std::string id; 74*6881a400Schristos 75*6881a400Schristos bool has_sep = strchr (arch, ':') != nullptr; 76*6881a400Schristos if (has_sep) 77*6881a400Schristos /* Avoid avr::avr:1. */ 78*6881a400Schristos id = arch; 79*6881a400Schristos else if (strncasecmp (info.bfd_arch_info->arch_name, arch, 80*6881a400Schristos strlen (info.bfd_arch_info->arch_name)) == 0) 81*6881a400Schristos /* Avoid arm::arm. */ 82*6881a400Schristos id = arch; 83*6881a400Schristos else 84*6881a400Schristos /* Use arc::A6 instead of A6. This still leaves us with an unfortunate 85*6881a400Schristos redundant id like am33_2::am33-2, but that doesn't seem worth the 86*6881a400Schristos effort to avoid. */ 87*6881a400Schristos id = string_printf ("%s::%s", info.bfd_arch_info->arch_name, arch); 88*6881a400Schristos 89*6881a400Schristos id = string_printf ("%s::%s", name.c_str (), id.c_str ()); 90*6881a400Schristos tests.emplace_back (id, test_fn); 91*6881a400Schristos } 92*6881a400Schristos return tests; 93699b0f92Schristos } 94699b0f92Schristos 95*6881a400Schristos /* See selftest-arch.h. */ 96699b0f92Schristos 97699b0f92Schristos void 987f2ac410Schristos register_test_foreach_arch (const std::string &name, 997f2ac410Schristos self_test_foreach_arch_function *function) 100699b0f92Schristos { 101*6881a400Schristos add_lazy_generator ([=] () 102*6881a400Schristos { 103*6881a400Schristos return foreach_arch_test_generator (name, function); 104*6881a400Schristos }); 105699b0f92Schristos } 1067f2ac410Schristos 1077f2ac410Schristos void 1087f2ac410Schristos reset () 1097f2ac410Schristos { 1107f2ac410Schristos /* Clear GDB internal state. */ 1117f2ac410Schristos registers_changed (); 1127f2ac410Schristos reinit_frame_cache (); 1137f2ac410Schristos } 1147f2ac410Schristos } // namespace selftests 1157f2ac410Schristos #endif /* GDB_SELF_TEST */ 116