aboutsummaryrefslogtreecommitdiff
path: root/gdb/selftest-arch.c
blob: 7045c45660d85c7bbd40e69ce1fe0440fe643386 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/* GDB self-test for each gdbarch.
   Copyright (C) 2017-2018 Free Software Foundation, Inc.

   This file is part of GDB.

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 3 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */

#include "defs.h"

#if GDB_SELF_TEST
#include "selftest.h"
#include "selftest-arch.h"
#include "arch-utils.h"

namespace selftests {

/* A kind of selftest that calls the test function once for each gdbarch known
   to GDB.  */

struct gdbarch_selftest : public selftest
{
  gdbarch_selftest (self_test_foreach_arch_function *function_)
  : function (function_)
  {}

  void operator() () const override
  {
    const char **arches = gdbarch_printable_names ();
    bool pass = true;

    for (int i = 0; arches[i] != NULL; i++)
      {
	if (strcmp ("fr300", arches[i]) == 0)
	  {
	    /* PR 20946 */
	    continue;
	  }
	else if (strcmp ("powerpc:EC603e", arches[i]) == 0
		 || strcmp ("powerpc:e500mc", arches[i]) == 0
		 || strcmp ("powerpc:e500mc64", arches[i]) == 0
		 || strcmp ("powerpc:titan", arches[i]) == 0
		 || strcmp ("powerpc:vle", arches[i]) == 0
		 || strcmp ("powerpc:e5500", arches[i]) == 0
		 || strcmp ("powerpc:e6500", arches[i]) == 0)
	  {
	    /* PR 19797 */
	    continue;
	  }

	QUIT;

	TRY
	  {
	    struct gdbarch_info info;

	    gdbarch_info_init (&info);
	    info.bfd_arch_info = bfd_scan_arch (arches[i]);

	    struct gdbarch *gdbarch = gdbarch_find_by_info (info);
	    SELF_CHECK (gdbarch != NULL);

	    function (gdbarch);
	  }
	CATCH (ex, RETURN_MASK_ERROR)
	  {
	    pass = false;
	    exception_fprintf (gdb_stderr, ex,
			       _("Self test failed: arch %s: "), arches[i]);
	  }
	END_CATCH

	reset ();
      }

    SELF_CHECK (pass);
  }

  self_test_foreach_arch_function *function;
};

void
register_test_foreach_arch (const std::string &name,
			    self_test_foreach_arch_function *function)
{
  register_test (name, new gdbarch_selftest (function));
}

void
reset ()
{
  /* Clear GDB internal state.  */
  registers_changed ();
  reinit_frame_cache ();
}
} // namespace selftests
#endif /* GDB_SELF_TEST */