1 /* OS ABI variant handling for GDB and gdbserver. 2 3 Copyright (C) 2001-2024 Free Software Foundation, Inc. 4 5 This file is part of GDB. 6 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. 11 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. 16 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/>. */ 19 20 #include "gdbsupport/osabi.h" 21 22 /* Names associated with each osabi. */ 23 24 struct osabi_names 25 { 26 /* The "pretty" name. */ 27 28 const char *pretty; 29 30 /* The triplet regexp, or NULL if not known. */ 31 32 const char *regexp; 33 }; 34 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[] = 38 { 39 #define GDB_OSABI_DEF_FIRST(Enum, Name, Regex) \ 40 { Name, Regex }, 41 42 #define GDB_OSABI_DEF(Enum, Name, Regex) \ 43 { Name, Regex }, 44 45 #define GDB_OSABI_DEF_LAST(Enum, Name, Regex) \ 46 { Name, Regex } 47 48 #include "gdbsupport/osabi.def" 49 50 #undef GDB_OSABI_DEF_LAST 51 #undef GDB_OSABI_DEF 52 #undef GDB_OSABI_DEF_FIRST 53 }; 54 55 /* See gdbsupport/osabi.h. */ 56 57 const char * 58 gdbarch_osabi_name (enum gdb_osabi osabi) 59 { 60 if (osabi >= GDB_OSABI_UNKNOWN && osabi < GDB_OSABI_INVALID) 61 return gdb_osabi_names[osabi].pretty; 62 63 return gdb_osabi_names[GDB_OSABI_INVALID].pretty; 64 } 65 66 /* See gdbsupport/osabi.h. */ 67 68 enum gdb_osabi 69 osabi_from_tdesc_string (const char *name) 70 { 71 int i; 72 73 for (i = 0; i < ARRAY_SIZE (gdb_osabi_names); i++) 74 if (strcmp (name, gdb_osabi_names[i].pretty) == 0) 75 { 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; 79 80 if (osabi == GDB_OSABI_INVALID) 81 return GDB_OSABI_UNKNOWN; 82 else 83 return osabi; 84 } 85 86 return GDB_OSABI_UNKNOWN; 87 } 88 89 /* See gdbsupport/osabi.h. */ 90 91 const char * 92 osabi_triplet_regexp (enum gdb_osabi osabi) 93 { 94 if (osabi >= GDB_OSABI_UNKNOWN && osabi < GDB_OSABI_INVALID) 95 return gdb_osabi_names[osabi].regexp; 96 97 return gdb_osabi_names[GDB_OSABI_INVALID].regexp; 98 } 99