This is the mail archive of the gdb@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[RFC] Include BDF machine type in OS ABI selection


I'm facing the challenge of integrating the x86-64 target in the i386
target.  I really want to keep the x86-64 targets optional, but since
both targets share the same BFD architecture I can't use
gdbarch_register_osabi() as it is now to register both i386-linux-gnu
and x86-64-linux-gnu.  The attached patch is an attempt to solve this
poblem.  It adds the BFD machine type as an extra parameter.  This
allows us to register OS ABI handlers for specific machine types.  The
OS ABI selection code will check whether that machine type is
compatible with the desired machine type before running the registered
OS ABI initialization function.

Thoughts?

Mark

Index: osabi.h
===================================================================
RCS file: /cvs/src/src/gdb/osabi.h,v
retrieving revision 1.5
diff -u -p -r1.5 osabi.h
--- osabi.h 11 Sep 2002 22:32:45 -0000 1.5
+++ osabi.h 27 Oct 2002 15:13:51 -0000
@@ -59,9 +59,11 @@ void gdbarch_register_osabi_sniffer (enu
 				     enum bfd_flavour,
 				     enum gdb_osabi (*)(bfd *));
 
-/* Register a handler for an OS ABI variant for a given architecture.  There
-   should be only one handler for a given OS ABI each architecture family.  */
-void gdbarch_register_osabi (enum bfd_architecture, enum gdb_osabi,
+/* Register a handler for an OS ABI variant for a given architecture
+   and machine type.  There should be only one handler for a given OS
+   ABI for each architecture and machine type combination.  */
+void gdbarch_register_osabi (enum bfd_architecture, unsigned long,
+			     enum gdb_osabi,
                              void (*)(struct gdbarch_info,
 				      struct gdbarch *));
 
Index: osabi.c
===================================================================
RCS file: /cvs/src/src/gdb/osabi.c,v
retrieving revision 1.8
diff -u -p -r1.8 osabi.c
--- osabi.c 12 Sep 2002 00:26:30 -0000 1.8
+++ osabi.c 27 Oct 2002 15:13:51 -0000
@@ -19,7 +19,10 @@
    Boston, MA 02111-1307, USA.  */
 
 #include "defs.h"
+
+#include "gdb_assert.h"
 #include "gdb_string.h"
+
 #include "osabi.h"
 
 #include "elf-bfd.h"
@@ -68,7 +71,7 @@ gdbarch_osabi_name (enum gdb_osabi osabi
 struct gdb_osabi_handler  
 {
   struct gdb_osabi_handler *next;
-  enum bfd_architecture arch;
+  const struct bfd_arch_info *arch_info;
   enum gdb_osabi osabi;
   void (*init_osabi)(struct gdbarch_info, struct gdbarch *);
 };
@@ -76,11 +79,13 @@ struct gdb_osabi_handler  
 static struct gdb_osabi_handler *gdb_osabi_handler_list;
 
 void
-gdbarch_register_osabi (enum bfd_architecture arch, enum gdb_osabi osabi,
+gdbarch_register_osabi (enum bfd_architecture arch, unsigned long machine,
+			enum gdb_osabi osabi,
                         void (*init_osabi)(struct gdbarch_info,
 					   struct gdbarch *))
 {
   struct gdb_osabi_handler **handler_p;
+  const struct bfd_arch_info *arch_info = bfd_lookup_arch (arch, machine);
 
   /* Registering an OS ABI handler for "unknown" is not allowed.  */
   if (osabi == GDB_OSABI_UNKNOWN)
@@ -91,14 +96,16 @@ gdbarch_register_osabi (enum bfd_archite
          "OS ABI \"%s\" for architecture %s was made.  The handler will "
 	 "not be registered",
 	 gdbarch_osabi_name (osabi),
-	 bfd_printable_arch_mach (arch, 0));
+	 bfd_printable_arch_mach (arch, machine));
       return;
     }
 
+  gdb_assert (arch_info);
+
   for (handler_p = &gdb_osabi_handler_list; *handler_p != NULL;
        handler_p = &(*handler_p)->next)
     {
-      if ((*handler_p)->arch == arch
+      if ((*handler_p)->arch_info == arch_info
 	  && (*handler_p)->osabi == osabi)
 	{
 	  internal_error
@@ -106,7 +113,7 @@ gdbarch_register_osabi (enum bfd_archite
 	     "gdbarch_register_osabi: A handler for OS ABI \"%s\" "
 	     "has already been registered for architecture %s",
 	     gdbarch_osabi_name (osabi),
-	     bfd_printable_arch_mach (arch, 0));
+	     arch_info->printable_name);
 	  /* If user wants to continue, override previous definition.  */
 	  (*handler_p)->init_osabi = init_osabi;
 	  return;
@@ -116,7 +123,7 @@ gdbarch_register_osabi (enum bfd_archite
   (*handler_p)
     = (struct gdb_osabi_handler *) xmalloc (sizeof (struct gdb_osabi_handler));
   (*handler_p)->next = NULL;
-  (*handler_p)->arch = arch;
+  (*handler_p)->arch_info = arch_info;
   (*handler_p)->osabi = osabi;
   (*handler_p)->init_osabi = init_osabi;
 }
@@ -228,9 +235,9 @@ void
 gdbarch_init_osabi (struct gdbarch_info info, struct gdbarch *gdbarch,
                     enum gdb_osabi osabi)
 {
-  struct gdb_osabi_handler *handler;
-  bfd *abfd = info.abfd;
   const struct bfd_arch_info *arch_info = gdbarch_bfd_arch_info (gdbarch);
+  const struct bfd_arch_info *compatible;
+  struct gdb_osabi_handler *handler;
 
   if (osabi == GDB_OSABI_UNKNOWN)
     {
@@ -242,8 +249,19 @@ gdbarch_init_osabi (struct gdbarch_info 
   for (handler = gdb_osabi_handler_list; handler != NULL;
        handler = handler->next)
     {
-      if (handler->arch == bfd_get_arch (abfd)
-	  && handler->osabi == osabi)
+      if (handler->osabi != osabi)
+	continue;
+
+      /* Check whether the machine type and architecture of the
+         handler are compatible with the desired machine type and
+         architecture.
+
+	 NOTE: kettenis/20021027: There may be more than one machine
+	 type that is compatible with the desired machine type.  Right
+	 now we simply return the first match, which is fine for now.
+	 However, we might want to do something smarter in the future.  */
+      compatible = arch_info->compatible (arch_info, handler->arch_info);
+      if (compatible == handler->arch_info)
 	{
 	  (*handler->init_osabi) (info, gdbarch);
 	  return;


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]