Add translations for various sub-directories
[binutils-gdb.git] / gdbsupport / osabi.cc
blob1e41b5f35c9eba7e17fd199210aa1a7244715b03
1 /* OS ABI variant handling for GDB and gdbserver.
3 Copyright (C) 2001-2024 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 #include "gdbsupport/osabi.h"
22 /* Names associated with each osabi. */
24 struct osabi_names
26 /* The "pretty" name. */
28 const char *pretty;
30 /* The triplet regexp, or NULL if not known. */
32 const char *regexp;
35 /* This table matches the indices assigned to enum gdb_osabi. Keep
36 them in sync. */
37 static const struct osabi_names gdb_osabi_names[] =
39 #define GDB_OSABI_DEF_FIRST(Enum, Name, Regex) \
40 { Name, Regex },
42 #define GDB_OSABI_DEF(Enum, Name, Regex) \
43 { Name, Regex },
45 #define GDB_OSABI_DEF_LAST(Enum, Name, Regex) \
46 { Name, Regex }
48 #include "gdbsupport/osabi.def"
50 #undef GDB_OSABI_DEF_LAST
51 #undef GDB_OSABI_DEF
52 #undef GDB_OSABI_DEF_FIRST
55 /* See gdbsupport/osabi.h. */
57 const char *
58 gdbarch_osabi_name (enum gdb_osabi osabi)
60 if (osabi >= GDB_OSABI_UNKNOWN && osabi < GDB_OSABI_INVALID)
61 return gdb_osabi_names[osabi].pretty;
63 return gdb_osabi_names[GDB_OSABI_INVALID].pretty;
66 /* See gdbsupport/osabi.h. */
68 enum gdb_osabi
69 osabi_from_tdesc_string (const char *name)
71 int i;
73 for (i = 0; i < ARRAY_SIZE (gdb_osabi_names); i++)
74 if (strcmp (name, gdb_osabi_names[i].pretty) == 0)
76 /* See note above: the name table matches the indices assigned
77 to enum gdb_osabi. */
78 enum gdb_osabi osabi = (enum gdb_osabi) i;
80 if (osabi == GDB_OSABI_INVALID)
81 return GDB_OSABI_UNKNOWN;
82 else
83 return osabi;
86 return GDB_OSABI_UNKNOWN;
89 /* See gdbsupport/osabi.h. */
91 const char *
92 osabi_triplet_regexp (enum gdb_osabi osabi)
94 if (osabi >= GDB_OSABI_UNKNOWN && osabi < GDB_OSABI_INVALID)
95 return gdb_osabi_names[osabi].regexp;
97 return gdb_osabi_names[GDB_OSABI_INVALID].regexp;