]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb/gdbserver: change shared set_tdesc_osabi to take gdb_osabi
authorAndrew Burgess <aburgess@redhat.com>
Tue, 8 Oct 2024 09:34:02 +0000 (10:34 +0100)
committerAndrew Burgess <aburgess@redhat.com>
Thu, 10 Oct 2024 16:36:21 +0000 (17:36 +0100)
There is a single declaration of set_tdesc_osabi that is shared
between gdbserver/ and gdb/, this declaration takes a 'const char *'
argument which is the string representing an osabi.

Then in gdb/ we have an overload of set_tdesc_osabi which takes an
'enum gdb_osabi'.

In this commit I change the shared set_tdesc_osabi to be the version
which takes an 'enum gdb_osabi', and I remove the version which takes
a 'const char *'.  All users of set_tdesc_osabi are updated to pass an
'enum gdb_osabi'.

The features/ code, which is generated from the xml files, requires a
new function to be added to osabi.{c,h} which can return a string
representation of an 'enum gdb_osabi'.  With that new function in
place the features/ code is regenerated.

This change is being made to support the next commit.  In the next
commit gdbserver will be updated to call set_tdesc_osabi in more
cases.  The problem is that gdbserver stores the osabi as a string.
The issue here is that a typo in the gdbserver/ code might go
unnoticed and result in gdbserver sending back an invalid osabi
string.

To fix this we want gdbserver to pass an 'enum gdb_osabi' to the
set_tdesc_osabi function.  With that requirement in place it seems to
make sense if all calls to set_tdesc_osabi pass an 'enum gdb_osabi'.

There should be no user visible changes after this commit.

Approved-By: Luis Machado <luis.machado@arm.com>
Approved-By: Simon Marchi <simon.marchi@efficios.com>
14 files changed:
gdb/arch/amd64.c
gdb/arch/i386.c
gdb/arch/tic6x.c
gdb/features/mips-dsp-linux.c
gdb/features/mips-linux.c
gdb/features/or1k-linux.c
gdb/features/sparc/sparc32-solaris.c
gdb/features/sparc/sparc64-solaris.c
gdb/osabi.c
gdb/osabi.h
gdb/target-descriptions.c
gdb/target-descriptions.h
gdbserver/tdesc.cc
gdbsupport/tdesc.h

index 548b32f252f58b3f4eda83de7345f5c16c63277d..5fc9947d489398b8833d706c5fe6d50e749d843f 100644 (file)
@@ -17,6 +17,7 @@
 
 #include "amd64.h"
 #include "gdbsupport/x86-xstate.h"
+#include "gdbsupport/osabi.h"
 #include <stdlib.h>
 
 #include "../features/i386/64bit-avx.c"
@@ -45,7 +46,7 @@ amd64_create_target_description (uint64_t xcr0, bool is_x32, bool is_linux,
                          is_x32 ? "i386:x64-32" : "i386:x86-64");
 
   if (is_linux)
-    set_tdesc_osabi (tdesc.get (), "GNU/Linux");
+    set_tdesc_osabi (tdesc.get (), GDB_OSABI_LINUX);
 #endif
 
   long regnum = 0;
index 49375e7c49594410bfde5f6bbc9b6dfd56cd7620..2072eae88add7ddea80afd481983cc8dcc4ff7bb 100644 (file)
@@ -18,6 +18,7 @@
 #include "i386.h"
 #include "gdbsupport/tdesc.h"
 #include "gdbsupport/x86-xstate.h"
+#include "gdbsupport/osabi.h"
 #include <stdlib.h>
 
 #include "../features/i386/32bit-core.c"
@@ -38,7 +39,7 @@ i386_create_target_description (uint64_t xcr0, bool is_linux, bool segments)
 #ifndef IN_PROCESS_AGENT
   set_tdesc_architecture (tdesc.get (), "i386");
   if (is_linux)
-    set_tdesc_osabi (tdesc.get (), "GNU/Linux");
+    set_tdesc_osabi (tdesc.get (), GDB_OSABI_LINUX);
 #endif
 
   long regnum = 0;
index 680a79420708a2cad4ff4fdd7c4b8621ee34f5a5..b8a722b2cae05dcf03db7fc4c55226f0bebc7006 100644 (file)
@@ -16,6 +16,7 @@
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 #include "gdbsupport/tdesc.h"
+#include "gdbsupport/osabi.h"
 #include "tic6x.h"
 
 #include "../features/tic6x-core.c"
@@ -30,7 +31,7 @@ tic6x_create_target_description (enum c6x_feature feature)
   target_desc_up tdesc = allocate_target_description ();
 
   set_tdesc_architecture (tdesc.get (), "tic6x");
-  set_tdesc_osabi (tdesc.get (), "GNU/Linux");
+  set_tdesc_osabi (tdesc.get (), GDB_OSABI_LINUX);
 
   long regnum = 0;
 
index 17d30aac68f6d90abe3ca59362b70938040b52ee..4873037b69d3e41debbea5e63f12aac559454b34 100644 (file)
@@ -11,7 +11,7 @@ initialize_tdesc_mips_dsp_linux (void)
   target_desc_up result = allocate_target_description ();
   set_tdesc_architecture (result.get (), bfd_scan_arch ("mips"));
 
-  set_tdesc_osabi (result.get (), "GNU/Linux");
+  set_tdesc_osabi (result.get (), GDB_OSABI_LINUX);
 
   struct tdesc_feature *feature;
 
index a43526db24ee03310855f9bd872fdc217807b16b..5ff2e5fb92d76e2da2194b258bfc0eee1859d5b4 100644 (file)
@@ -11,7 +11,7 @@ initialize_tdesc_mips_linux (void)
   target_desc_up result = allocate_target_description ();
   set_tdesc_architecture (result.get (), bfd_scan_arch ("mips"));
 
-  set_tdesc_osabi (result.get (), "GNU/Linux");
+  set_tdesc_osabi (result.get (), GDB_OSABI_LINUX);
 
   struct tdesc_feature *feature;
 
index 551b38f59c0fd869d00f9eaf0e296882dd8b8811..85a681f89ba0d3c1343d7245794aa16d1dcdca31 100644 (file)
@@ -11,7 +11,7 @@ initialize_tdesc_or1k_linux (void)
   target_desc_up result = allocate_target_description ();
   set_tdesc_architecture (result.get (), bfd_scan_arch ("or1k"));
 
-  set_tdesc_osabi (result.get (), "GNU/Linux");
+  set_tdesc_osabi (result.get (), GDB_OSABI_LINUX);
 
   struct tdesc_feature *feature;
 
index ce57abaaaf2696181fc35e199a08cc7934253da5..70affdbc5b5d5fd392466a5f20a27b842d37066b 100644 (file)
@@ -11,7 +11,7 @@ initialize_tdesc_sparc32_solaris (void)
   target_desc_up result = allocate_target_description ();
   set_tdesc_architecture (result.get (), bfd_scan_arch ("sparc"));
 
-  set_tdesc_osabi (result.get (), "Solaris");
+  set_tdesc_osabi (result.get (), GDB_OSABI_SOLARIS);
 
   struct tdesc_feature *feature;
 
index 92cc88cd5cf70ac452eb697d1a45cfb71bc3a2cd..98edabe38644d29f76529ad742ab48508d3496c9 100644 (file)
@@ -11,7 +11,7 @@ initialize_tdesc_sparc64_solaris (void)
   target_desc_up result = allocate_target_description ();
   set_tdesc_architecture (result.get (), bfd_scan_arch ("sparc:v9"));
 
-  set_tdesc_osabi (result.get (), "Solaris");
+  set_tdesc_osabi (result.get (), GDB_OSABI_SOLARIS);
 
   struct tdesc_feature *feature;
 
index 6c00228fb4ae97dfb4e5b5ad812c2f8d23aad3d5..236d42553ddf42f71b71db4fcbec984fb5a9d331 100644 (file)
@@ -524,6 +524,35 @@ generic_elf_osabi_sniffer (bfd *abfd)
 
   return osabi;
 }
+
+/* See osabi.h.  */
+
+const char *
+gdbarch_osabi_enum_name (enum gdb_osabi osabi)
+{
+  switch (osabi)
+    {
+#define GDB_OSABI_DEF_FIRST(Enum, Name, Regex) \
+      case GDB_OSABI_ ## Enum:                 \
+       return "GDB_OSABI_" #Enum;
+
+#define GDB_OSABI_DEF(Enum, Name, Regex)       \
+      case GDB_OSABI_ ## Enum:                 \
+       return "GDB_OSABI_" #Enum;
+
+#define GDB_OSABI_DEF_LAST(Enum, Name, Regex)  \
+      case GDB_OSABI_ ## Enum:                 \
+       return "GDB_OSABI_" #Enum;
+
+#include "gdbsupport/osabi.def"
+
+#undef GDB_OSABI_DEF_LAST
+#undef GDB_OSABI_DEF
+#undef GDB_OSABI_DEF_FIRST
+    }
+
+  gdb_assert_not_reached ();
+}
 \f
 static void
 set_osabi (const char *args, int from_tty, struct cmd_list_element *c)
index 9a1681db96b0bdf16944b870eb536945515aae39..2d828d54227594857374cf1156e8d6c603b888e5 100644 (file)
@@ -52,4 +52,8 @@ void gdbarch_init_osabi (struct gdbarch_info, struct gdbarch *);
 void generic_elf_osabi_sniff_abi_tag_sections (bfd *, asection *,
                                               enum gdb_osabi *);
 
+/* Return a string version of OSABI.  This is used when generating code
+   which calls set_tdesc_osabi and an 'enum gdb_osabi' value is needed.  */
+const char *gdbarch_osabi_enum_name (enum gdb_osabi osabi);
+
 #endif /* OSABI_H */
index c165750c6c52af5a8c977463e09556fbbc445b9d..1bd22c273a2999bcbd72bbb818b7dac3fb4d1da3 100644 (file)
@@ -1199,12 +1199,6 @@ set_tdesc_architecture (struct target_desc *target_desc,
 
 /* See gdbsupport/tdesc.h.  */
 
-void
-set_tdesc_osabi (struct target_desc *target_desc, const char *name)
-{
-  set_tdesc_osabi (target_desc, osabi_from_tdesc_string (name));
-}
-
 void
 set_tdesc_osabi (struct target_desc *target_desc, enum gdb_osabi osabi)
 {
@@ -1317,9 +1311,8 @@ public:
     if (tdesc_osabi (e) > GDB_OSABI_UNKNOWN
        && tdesc_osabi (e) < GDB_OSABI_INVALID)
       {
-       gdb_printf
-         ("  set_tdesc_osabi (result.get (), \"%s\");\n",
-          gdbarch_osabi_name (tdesc_osabi (e)));
+       const char *enum_name = gdbarch_osabi_enum_name (tdesc_osabi (e));
+       gdb_printf ("  set_tdesc_osabi (result.get (), %s);\n", enum_name);
        gdb_printf ("\n");
       }
 
index d708dbd3589ee887551fb0a1dd7759a73ade61f0..dc83db0acf28c35f67d915d29b87549f99e416a6 100644 (file)
@@ -219,7 +219,6 @@ int tdesc_register_in_reggroup_p (struct gdbarch *gdbarch, int regno,
 
 void set_tdesc_architecture (struct target_desc *,
                             const struct bfd_arch_info *);
-void set_tdesc_osabi (struct target_desc *, enum gdb_osabi osabi);
 void set_tdesc_property (struct target_desc *,
                         const char *key, const char *value);
 void tdesc_add_compatible (struct target_desc *,
index 7f11120c31859bcbed5adc3f2e71376461ba237c..d052f43c76e69c6f47f40e124b08866de3b2ba40 100644 (file)
@@ -179,8 +179,9 @@ tdesc_osabi_name (const struct target_desc *target_desc)
 /* See gdbsupport/tdesc.h.  */
 
 void
-set_tdesc_osabi (struct target_desc *target_desc, const char *name)
+set_tdesc_osabi (struct target_desc *target_desc, enum gdb_osabi osabi)
 {
+  const char *name = gdbarch_osabi_name (osabi);
   target_desc->osabi = make_unique_xstrdup (name);
 }
 
index fa9431b5b651cf4082574113755ff46bebfdaa06..c9e7603369cbf986187908c2d1f8fbe35a0dc02d 100644 (file)
@@ -18,6 +18,8 @@
 #ifndef COMMON_TDESC_H
 #define COMMON_TDESC_H
 
+#include "gdbsupport/osabi.h"
+
 struct tdesc_feature;
 struct tdesc_type;
 struct tdesc_type_builtin;
@@ -338,8 +340,8 @@ void set_tdesc_architecture (target_desc *target_desc,
    or NULL if no architecture was specified.  */
 const char *tdesc_architecture_name (const struct target_desc *target_desc);
 
-/* Set TARGET_DESC's osabi by NAME.  */
-void set_tdesc_osabi (target_desc *target_desc, const char *name);
+/* Set TARGET_DESC's osabi to OSABI.  */
+void set_tdesc_osabi (target_desc *target_desc, enum gdb_osabi osabi);
 
 /* Return the osabi associated with this target description as a string,
    or NULL if no osabi was specified.  */