selftest-arch.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /* GDB self-test for each gdbarch.
  2. Copyright (C) 2017-2022 Free Software Foundation, Inc.
  3. This file is part of GDB.
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  14. #include "defs.h"
  15. #include <functional>
  16. #if GDB_SELF_TEST
  17. #include "gdbsupport/selftest.h"
  18. #include "selftest-arch.h"
  19. #include "arch-utils.h"
  20. namespace selftests {
  21. static bool skip_arch (const char *arch)
  22. {
  23. if (strcmp ("fr300", arch) == 0)
  24. {
  25. /* PR 20946 */
  26. return true;
  27. }
  28. if (strcmp ("powerpc:EC603e", arch) == 0
  29. || strcmp ("powerpc:e500mc", arch) == 0
  30. || strcmp ("powerpc:e500mc64", arch) == 0
  31. || strcmp ("powerpc:titan", arch) == 0
  32. || strcmp ("powerpc:vle", arch) == 0
  33. || strcmp ("powerpc:e5500", arch) == 0
  34. || strcmp ("powerpc:e6500", arch) == 0)
  35. {
  36. /* PR 19797 */
  37. return true;
  38. }
  39. return false;
  40. }
  41. /* Register a kind of selftest that calls the test function once for each
  42. gdbarch known to GDB. */
  43. void
  44. register_test_foreach_arch (const std::string &name,
  45. self_test_foreach_arch_function *function)
  46. {
  47. std::vector<const char *> arches = gdbarch_printable_names ();
  48. for (const char *arch : arches)
  49. {
  50. if (skip_arch (arch))
  51. continue;
  52. auto test_fn
  53. = ([=] ()
  54. {
  55. struct gdbarch_info info;
  56. info.bfd_arch_info = bfd_scan_arch (arch);
  57. struct gdbarch *gdbarch = gdbarch_find_by_info (info);
  58. SELF_CHECK (gdbarch != NULL);
  59. function (gdbarch);
  60. reset ();
  61. });
  62. std::string test_name
  63. = name + std::string ("::") + std::string (arch);
  64. register_test (test_name, test_fn);
  65. }
  66. }
  67. void
  68. reset ()
  69. {
  70. /* Clear GDB internal state. */
  71. registers_changed ();
  72. reinit_frame_cache ();
  73. }
  74. } // namespace selftests
  75. #endif /* GDB_SELF_TEST */