GDB (xrefs)
/tmp/gdb-8.1/gdb/selftest-arch.c
Go to the documentation of this file.
1 /* GDB self-test for each gdbarch.
2  Copyright (C) 2017-2018 Free Software Foundation, Inc.
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"
20 
21 #if GDB_SELF_TEST
22 #include "selftest.h"
23 #include "selftest-arch.h"
24 #include "arch-utils.h"
25 
26 namespace selftests {
27 
28 /* A kind of selftest that calls the test function once for each gdbarch known
29  to GDB. */
30 
31 struct gdbarch_selftest : public selftest
32 {
33  gdbarch_selftest (self_test_foreach_arch_function *function_)
34  : function (function_)
35  {}
36 
37  void operator() () const override
38  {
39  const char **arches = gdbarch_printable_names ();
40  bool pass = true;
41 
42  for (int i = 0; arches[i] != NULL; i++)
43  {
44  if (strcmp ("fr300", arches[i]) == 0)
45  {
46  /* PR 20946 */
47  continue;
48  }
49  else if (strcmp ("powerpc:EC603e", arches[i]) == 0
50  || strcmp ("powerpc:e500mc", arches[i]) == 0
51  || strcmp ("powerpc:e500mc64", arches[i]) == 0
52  || strcmp ("powerpc:titan", arches[i]) == 0
53  || strcmp ("powerpc:vle", arches[i]) == 0
54  || strcmp ("powerpc:e5500", arches[i]) == 0
55  || strcmp ("powerpc:e6500", arches[i]) == 0)
56  {
57  /* PR 19797 */
58  continue;
59  }
60 
61  QUIT;
62 
63  TRY
64  {
65  struct gdbarch_info info;
66 
67  gdbarch_info_init (&info);
68  info.bfd_arch_info = bfd_scan_arch (arches[i]);
69 
70  struct gdbarch *gdbarch = gdbarch_find_by_info (info);
71  SELF_CHECK (gdbarch != NULL);
72 
73  function (gdbarch);
74  }
76  {
77  pass = false;
79  _("Self test failed: arch %s: "), arches[i]);
80  }
81  END_CATCH
82 
83  reset ();
84  }
85 
86  SELF_CHECK (pass);
87  }
88 
90 };
91 
92 void
95 {
96  register_test (name, new gdbarch_selftest (function));
97 }
98 
99 void
100 reset ()
101 {
102  /* Clear GDB internal state. */
105 }
106 } // namespace selftests
107 #endif /* GDB_SELF_TEST */
const char * string
Definition: signals.c:50
void reset()
void self_test_foreach_arch_function(struct gdbarch *)
Definition: selftest-arch.h:22
struct gdbarch * gdbarch_find_by_info(struct gdbarch_info info)
Definition: gdbarch.c:5332
const char ** gdbarch_printable_names(void)
Definition: gdbarch.c:5227
#define _(String)
Definition: gdb_locale.h:35
void register_test_foreach_arch(const std::string &name, self_test_foreach_arch_function *function)
#define END_CATCH
#define TRY
const char *const name
Definition: aarch64-tdep.c:76
#define CATCH(EXCEPTION, MASK)
void exception_fprintf(struct ui_file *file, struct gdb_exception e, const char *prefix,...)
Definition: exceptions.c:119
#define gdb_stderr
Definition: utils.h:344
void gdbarch_info_init(struct gdbarch_info *info)
Definition: arch-utils.c:725
void registers_changed(void)
Definition: regcache.c:522
void reinit_frame_cache(void)
Definition: frame.c:1809
#define QUIT
Definition: defs.h:179
void register_test(const std::string &name, selftest *test)
Definition: selftest.c:52
#define SELF_CHECK(VALUE)
Definition: selftest.h:67