diff options
author | Andrew Burgess <aburgess@redhat.com> | 2024-10-08 10:21:59 +0100 |
---|---|---|
committer | Andrew Burgess <aburgess@redhat.com> | 2024-10-10 17:36:21 +0100 |
commit | 67470b3532fd031959169740fa99550fc8a06b84 (patch) | |
tree | 468894259be20f963a22a59bcfc9d7b63d337464 /gdb | |
parent | cb5997da94752f35bbbc38fe5b1eedc307b0731c (diff) | |
download | binutils-67470b3532fd031959169740fa99550fc8a06b84.zip binutils-67470b3532fd031959169740fa99550fc8a06b84.tar.gz binutils-67470b3532fd031959169740fa99550fc8a06b84.tar.bz2 |
gdb: split osabi support between gdb/ and gdbsupport/ directories
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>
Diffstat (limited to 'gdb')
-rw-r--r-- | gdb/osabi.c | 91 | ||||
-rw-r--r-- | gdb/osabi.h | 41 |
2 files changed, 1 insertions, 131 deletions
diff --git a/gdb/osabi.c b/gdb/osabi.c index 8a1efce..6c00228 100644 --- a/gdb/osabi.c +++ b/gdb/osabi.c @@ -42,93 +42,6 @@ static const char *gdb_osabi_available_names[GDB_OSABI_INVALID + 3] = { }; static const char *set_osabi_string; -/* 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[] = -{ - { "unknown", NULL }, - { "none", NULL }, - - { "SVR4", NULL }, - { "GNU/Hurd", NULL }, - { "Solaris", NULL }, - { "GNU/Linux", "linux(-gnu[^-]*)?" }, - { "FreeBSD", NULL }, - { "NetBSD", NULL }, - { "OpenBSD", NULL }, - { "WindowsCE", NULL }, - { "DJGPP", NULL }, - { "Cygwin", NULL }, - { "Windows", NULL }, - { "AIX", NULL }, - { "DICOS", NULL }, - { "Darwin", NULL }, - { "OpenVMS", NULL }, - { "LynxOS178", NULL }, - { "Newlib", NULL }, - { "SDE", NULL }, - { "PikeOS", NULL }, - - { "<invalid>", NULL } -}; - -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 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; -} - -/* Lookup the OS ABI corresponding to the specified target description - string. */ - -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; -} - /* Handler for a given architecture/OS ABI pair. There should be only one handler for a given OS ABI each architecture family. */ struct gdb_osabi_handler @@ -671,10 +584,6 @@ void _initialize_gdb_osabi (); void _initialize_gdb_osabi () { - if (strcmp (gdb_osabi_names[GDB_OSABI_INVALID].pretty, "<invalid>") != 0) - internal_error - (_("_initialize_gdb_osabi: gdb_osabi_names[] is inconsistent")); - /* Register a generic sniffer for ELF flavoured files. */ gdbarch_register_osabi_sniffer (bfd_arch_unknown, bfd_target_elf_flavour, diff --git a/gdb/osabi.h b/gdb/osabi.h index d2b1a35..9a1681d 100644 --- a/gdb/osabi.h +++ b/gdb/osabi.h @@ -19,35 +19,7 @@ #ifndef OSABI_H #define OSABI_H -/* * List of known OS ABIs. If you change this, make sure to update the - table in osabi.c. */ -enum gdb_osabi -{ - GDB_OSABI_UNKNOWN = 0, /* keep this zero */ - GDB_OSABI_NONE, - - GDB_OSABI_SVR4, - GDB_OSABI_HURD, - GDB_OSABI_SOLARIS, - GDB_OSABI_LINUX, - GDB_OSABI_FREEBSD, - GDB_OSABI_NETBSD, - GDB_OSABI_OPENBSD, - GDB_OSABI_WINCE, - GDB_OSABI_GO32, - GDB_OSABI_CYGWIN, - GDB_OSABI_WINDOWS, - GDB_OSABI_AIX, - GDB_OSABI_DICOS, - GDB_OSABI_DARWIN, - GDB_OSABI_OPENVMS, - GDB_OSABI_LYNXOS178, - GDB_OSABI_NEWLIB, - GDB_OSABI_SDE, - GDB_OSABI_PIKEOS, - - GDB_OSABI_INVALID /* keep this last */ -}; +#include "gdbsupport/osabi.h" /* Register an OS ABI sniffer. Each arch/flavour may have more than one sniffer. This is used to e.g. differentiate one OS's a.out from @@ -69,23 +41,12 @@ void gdbarch_register_osabi (enum bfd_architecture, unsigned long, /* Lookup the OS ABI corresponding to the specified BFD. */ enum gdb_osabi gdbarch_lookup_osabi (bfd *); -/* Lookup the OS ABI corresponding to the specified target description - string. */ -enum gdb_osabi osabi_from_tdesc_string (const char *text); - /* Return true if there's an OS ABI handler for INFO. */ bool has_gdb_osabi_handler (struct gdbarch_info info); /* Initialize the gdbarch for the specified OS ABI variant. */ void gdbarch_init_osabi (struct gdbarch_info, struct gdbarch *); -/* Return the name of the specified OS ABI. */ -const char *gdbarch_osabi_name (enum gdb_osabi); - -/* Return a regular expression that matches the OS part of a GNU - configury triplet for the given OSABI. */ -const char *osabi_triplet_regexp (enum gdb_osabi osabi); - /* Helper routine for ELF file sniffers. This looks at ABI tag note sections to determine the OS ABI from the note. */ void generic_elf_osabi_sniff_abi_tag_sections (bfd *, asection *, |