mirror of
https://sourceware.org/git/binutils-gdb.git
synced 2024-11-27 03:51:15 +08:00
67470b3532
In future commits I want to call set_tdesc_osabi from gdbserver/ code. Currently the only version of set_tdesc_osabi available to gdbserver takes a string representing the osabi. The problem with this is that, having lots of calls to set_tdesc_osabi which all take a string is an invite for a typo to slip in. This typo could potentially go unnoticed until someone tries to debug the wrong combination of GDB and gdbserver, at which point GDB will fail to find the correct gdbarch because it doesn't understand the osabi string. It would be better if the set_tdesc_osabi calls in gdbserver could take an 'enum gdb_osabi' value and then convert this to the "correct" string internally. In this way we are guaranteed to always have a valid, known, osabi string. This commit splits the osabi related code, which currently lives entirely on the GDB side, between gdb/ and gdbsupport/. I've moved the enum definition along with the array of osabi names into gdbsupport/. Then all the functions that access the names list, and which convert between names and enum values are also moved. I've taken the opportunity of this move to add a '.def' file which contains all the enum names along with the name strings. This '.def' file is then used to create 'enum gdb_osabi' as well as the array of osabi name strings. By using a '.def' file we know that the enum order will always match the name string array. This commit is just a refactor, there are no user visible changes after this commit. This commit doesn't change how gdbserver sets the target description osabi string, that will come in the next commit. Approved-By: Luis Machado <luis.machado@arm.com> Approved-By: Simon Marchi <simon.marchi@efficios.com>
99 lines
2.4 KiB
C++
99 lines
2.4 KiB
C++
/* OS ABI variant handling for GDB and gdbserver.
|
|
|
|
Copyright (C) 2001-2024 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 "gdbsupport/osabi.h"
|
|
|
|
/* Names associated with each osabi. */
|
|
|
|
struct osabi_names
|
|
{
|
|
/* The "pretty" name. */
|
|
|
|
const char *pretty;
|
|
|
|
/* The triplet regexp, or NULL if not known. */
|
|
|
|
const char *regexp;
|
|
};
|
|
|
|
/* This table matches the indices assigned to enum gdb_osabi. Keep
|
|
them in sync. */
|
|
static const struct osabi_names gdb_osabi_names[] =
|
|
{
|
|
#define GDB_OSABI_DEF_FIRST(Enum, Name, Regex) \
|
|
{ Name, Regex },
|
|
|
|
#define GDB_OSABI_DEF(Enum, Name, Regex) \
|
|
{ Name, Regex },
|
|
|
|
#define GDB_OSABI_DEF_LAST(Enum, Name, Regex) \
|
|
{ Name, Regex }
|
|
|
|
#include "gdbsupport/osabi.def"
|
|
|
|
#undef GDB_OSABI_DEF_LAST
|
|
#undef GDB_OSABI_DEF
|
|
#undef GDB_OSABI_DEF_FIRST
|
|
};
|
|
|
|
/* See gdbsupport/osabi.h. */
|
|
|
|
const char *
|
|
gdbarch_osabi_name (enum gdb_osabi osabi)
|
|
{
|
|
if (osabi >= GDB_OSABI_UNKNOWN && osabi < GDB_OSABI_INVALID)
|
|
return gdb_osabi_names[osabi].pretty;
|
|
|
|
return gdb_osabi_names[GDB_OSABI_INVALID].pretty;
|
|
}
|
|
|
|
/* See gdbsupport/osabi.h. */
|
|
|
|
enum gdb_osabi
|
|
osabi_from_tdesc_string (const char *name)
|
|
{
|
|
int i;
|
|
|
|
for (i = 0; i < ARRAY_SIZE (gdb_osabi_names); i++)
|
|
if (strcmp (name, gdb_osabi_names[i].pretty) == 0)
|
|
{
|
|
/* See note above: the name table matches the indices assigned
|
|
to enum gdb_osabi. */
|
|
enum gdb_osabi osabi = (enum gdb_osabi) i;
|
|
|
|
if (osabi == GDB_OSABI_INVALID)
|
|
return GDB_OSABI_UNKNOWN;
|
|
else
|
|
return osabi;
|
|
}
|
|
|
|
return GDB_OSABI_UNKNOWN;
|
|
}
|
|
|
|
/* See gdbsupport/osabi.h. */
|
|
|
|
const char *
|
|
osabi_triplet_regexp (enum gdb_osabi osabi)
|
|
{
|
|
if (osabi >= GDB_OSABI_UNKNOWN && osabi < GDB_OSABI_INVALID)
|
|
return gdb_osabi_names[osabi].regexp;
|
|
|
|
return gdb_osabi_names[GDB_OSABI_INVALID].regexp;
|
|
}
|