This is the mail archive of the gdb-patches@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: "set osabi"


As promised.  I'm also looking for comments on this patch.  I know it needs
documentation still; that's on hold for a moment because it would conflict
with one of my other pending doc patches (since I want to put them in the
same section).  I'll do the docs before committing this.

This patch implements:
  - "set osabi"
  - "show osabi"
  - The concept of a "default OS ABI" which will be applied instead
    of GDB_OSABI_UNKNOWN to an untagged binary.

It looks like this:

(gdb) show osabi
The current OS ABI is "auto" (currently "GNU/Linux").
The default OS ABI is "GNU/Linux".
(gdb) set osabi
Requires an argument. Valid arguments are auto, default, none, SVR4, DJGPP,
NetWare, GNU/Linux.
(gdb) set osabi SVR4
(gdb) show osabi
The current OS ABI is "SVR4".
The default OS ABI is "GNU/Linux".
(gdb) set osabi default
(gdb) show osabi
The current OS ABI is "GNU/Linux".
The default OS ABI is "GNU/Linux".
(gdb) set osabi auto
(gdb) show osabi
The current OS ABI is "auto" (currently "GNU/Linux").
The default OS ABI is "GNU/Linux".


Right now, it doesn't handle architectures refusing an OSABI terribly
gracefully.  This doesn't bother me because:
  - The logical place to handle this gracefully is clearly marked
  - The interfaces to handle it are already there via gdbarch
  - None of our architectures ever actually refuse an OSABI anyway as far
    as I can see; they just treat unknowns as, well, unknown.  That needs
    to change some day.
We'll cross that bridge when we come to it.

Comments?  Tentatively I'll apply this in a week or so, after I get feedback
on the preceding patch (which this requires).

-- 
Daniel Jacobowitz
MontaVista Software                         Debian GNU/Linux Developer

2002-12-27  Daniel Jacobowitz  <drow@mvista.com>

	* Makefile.in (acconfig_h): Remove incorrect macro.
	(config_h): Define.
	(osabi.o): Update dependencies.
	* configure.tgt: Set gdb_osabi based on target triplet.
	* configure.in: Define GDB_OSABI_DEFAULT based on gdb_osabi.
	* configure: Regenerated.
	* config.in: Regenerated.
	* osabi.c: Include "arch-utils.h", "gdbcmd.h", and "command.h".
	(GDB_OSABI_DEFAULT): Define if not already defined.
	(user_osabi_state, user_selected_osabi, gdb_osabi_available_names)
	(set_osabi_string): New variables.
	(gdbarch_register_osabi): Add new OS ABI to
	gdb_osabi_available_names.
	(gdbarch_lookup_osabi): Honor specified and default OS ABIs.
	(set_osabi, show_osabi): New functions.
	(_initialize_gdb_osabi): Add "set osabi" and "show osabi" commands.

diff -urp -x configure gdb.osabi1/Makefile.in gdb/Makefile.in
--- gdb.osabi1/Makefile.in	2002-12-27 18:23:37.000000000 -0500
+++ gdb/Makefile.in	2002-12-27 22:18:41.000000000 -0500
@@ -610,7 +610,6 @@ nm_h =		@nm_h@
 # gdb/ header files
 #
 
-acconfig_h = acconfig.h
 ada_lang_h = ada-lang.h $(value_h) $(gdbtypes_h)
 alpha_tdep_h = alpha-tdep.h
 alphabsd_tdep_h = alphabsd-tdep.h
@@ -631,6 +630,7 @@ coff_solib_h = coff-solib.h
 command_h = command.h
 complaints_h = complaints.h
 completer_h = completer.h
+config_h = config.h
 cp_abi_h = cp-abi.h
 cp_support_h = cp-support.h
 dcache_h = dcache.h
@@ -2012,7 +2012,8 @@ ocd.o: ocd.c $(defs_h) $(gdbcore_h) $(gd
 op50-rom.o: op50-rom.c $(defs_h) $(gdbcore_h) $(target_h) $(monitor_h) \
 	$(serial_h)
 # OBSOLETE os9kread.o: os9kread.c
-osabi.o: osabi.c $(defs_h) $(gdb_string_h) $(osabi_h) $(elf_bfd_h)
+osabi.o: osabi.c $(defs_h) $(gdb_string_h) $(osabi_h) $(elf_bfd_h) \
+	$(gdbcmd_h) $(command_h) $(arch_utils_h)
 p-lang.o: p-lang.c $(defs_h) $(gdb_string_h) $(symtab_h) $(gdbtypes_h) \
 	$(expression_h) $(parser_defs_h) $(language_h) $(p_lang_h) \
 	$(valprint_h)
diff -urp -x configure gdb.osabi1/configure.in gdb/configure.in
--- gdb.osabi1/configure.in	2002-12-02 21:27:07.000000000 -0500
+++ gdb/configure.in	2002-12-27 21:32:28.000000000 -0500
@@ -1340,6 +1340,11 @@ case "${GDB_MULTI_ARCH}" in
     *)  AC_MSG_ERROR("GDB: Unknown GDB_MULTI_ARCH value ${GDB_MULTI_ARCH}");;
 esac
 
+if test x"${gdb_osabi}" != x ; then
+    AC_DEFINE_UNQUOTED(GDB_OSABI_DEFAULT, $gdb_osabi,
+		       [Define to the default OS ABI for this configuration.])
+fi
+
 if test "${enable_multi_ice}" = "yes"; then
   SUBDIRS="${SUBDIRS} multi-ice"
 fi
diff -urp -x configure gdb.osabi1/configure.tgt gdb/configure.tgt
--- gdb.osabi1/configure.tgt	2002-12-25 13:31:52.000000000 -0500
+++ gdb/configure.tgt	2002-12-27 22:35:11.000000000 -0500
@@ -309,3 +309,10 @@ v850)           gdb_multi_arch=yes ;;
 xstormy16)      gdb_multi_arch=yes ;;
 mcore)		gdb_multi_arch=yes ;;
 esac
+
+# map target onto default OS ABI
+
+case "${target}" in
+*-*-linux*)	gdb_osabi=GDB_OSABI_LINUX ;;
+*-*-gnu*)	gdb_osabi=GDB_OSABI_HURD ;;
+esac
diff -urp -x configure gdb.osabi1/osabi.c gdb/osabi.c
--- gdb.osabi1/osabi.c	2002-12-27 16:51:51.000000000 -0500
+++ gdb/osabi.c	2002-12-27 22:33:41.000000000 -0500
@@ -24,15 +24,32 @@
 #include "gdb_string.h"
 
 #include "osabi.h"
+#include "arch-utils.h"
+#include "gdbcmd.h"
+#include "command.h"
 
 #include "elf-bfd.h"
 
+#ifndef GDB_OSABI_DEFAULT
+#define GDB_OSABI_DEFAULT GDB_OSABI_UNKNOWN
+#endif
+
+/* State for the "set osabi" command.  */
+static enum { osabi_auto, osabi_default, osabi_user } user_osabi_state;
+static enum gdb_osabi user_selected_osabi;
+static const char *gdb_osabi_available_names[GDB_OSABI_INVALID + 3] = {
+  "auto",
+  "default",
+  "none",
+  NULL
+};
+static const char *set_osabi_string;
 
 /* This table matches the indices assigned to enum gdb_osabi.  Keep
    them in sync.  */
 static const char * const gdb_osabi_names[] =
 {
-  "<unknown>",
+  "none",
 
   "SVR4",
   "GNU/Hurd",
@@ -88,6 +105,7 @@ gdbarch_register_osabi (enum bfd_archite
 {
   struct gdb_osabi_handler **handler_p;
   const struct bfd_arch_info *arch_info = bfd_lookup_arch (arch, machine);
+  const char **name_ptr;
 
   /* Registering an OS ABI handler for "unknown" is not allowed.  */
   if (osabi == GDB_OSABI_UNKNOWN)
@@ -128,6 +146,16 @@ gdbarch_register_osabi (enum bfd_archite
   (*handler_p)->arch_info = arch_info;
   (*handler_p)->osabi = osabi;
   (*handler_p)->init_osabi = init_osabi;
+
+  /* Add this OS ABI to the list of enum values for "set osabi", if it isn't
+     already there.  */
+  for (name_ptr = gdb_osabi_available_names; *name_ptr; name_ptr ++)
+    {
+      if (*name_ptr == gdbarch_osabi_name (osabi))
+	return;
+    }
+  *name_ptr++ = gdbarch_osabi_name (osabi);
+  *name_ptr = NULL;
 }
 
 
@@ -171,8 +199,19 @@ gdbarch_lookup_osabi (bfd *abfd)
   enum gdb_osabi osabi, match;
   int match_specific;
 
-  if (abfd == NULL)
-    return GDB_OSABI_UNINITIALIZED;
+  /* If we aren't in "auto" mode, return the specified OS ABI.  */
+  if (user_osabi_state == osabi_user)
+    return user_selected_osabi;
+
+  /* If we don't have a binary, return the default OS ABI (if set) or
+     an inconclusive result (otherwise).  */
+  if (abfd == NULL) 
+    {
+      if (GDB_OSABI_DEFAULT != GDB_OSABI_UNKNOWN)
+	return GDB_OSABI_DEFAULT;
+      else
+	return GDB_OSABI_UNINITIALIZED;
+    }
 
   match = GDB_OSABI_UNKNOWN;
   match_specific = 0;
@@ -233,7 +272,12 @@ gdbarch_lookup_osabi (bfd *abfd)
 	}
     }
 
-  return match;
+  /* If we didn't find a match, but a default was specified at configure
+     time, return the default.  */
+  if (GDB_OSABI_DEFAULT != GDB_OSABI_UNKNOWN && match == GDB_OSABI_UNKNOWN)
+    return GDB_OSABI_DEFAULT;
+  else
+    return match;
 }
 
 void
@@ -444,10 +488,66 @@ generic_elf_osabi_sniffer (bfd *abfd)
   return osabi;
 }
 
+static void
+set_osabi (char *args, int from_tty, struct cmd_list_element *c)
+{
+  struct gdbarch_info info;
+
+  if (strcmp (set_osabi_string, "auto") == 0)
+    user_osabi_state = osabi_auto;
+  else if (strcmp (set_osabi_string, "default") == 0)
+    {
+      user_selected_osabi = GDB_OSABI_DEFAULT;
+      user_osabi_state = osabi_user;
+    }
+  else if (strcmp (set_osabi_string, "none") == 0)
+    {
+      user_selected_osabi = GDB_OSABI_UNKNOWN;
+      user_osabi_state = osabi_user;
+    }
+  else
+    {
+      int i;
+      for (i = 1; i < GDB_OSABI_INVALID; i++)
+	if (strcmp (set_osabi_string, gdbarch_osabi_name (i)) == 0)
+	  {
+	    user_selected_osabi = i;
+	    user_osabi_state = osabi_user;
+	    break;
+	  }
+      if (i == GDB_OSABI_INVALID)
+	internal_error (__FILE__, __LINE__,
+			"Invalid OS ABI \"%s\" passed to command handler.",
+			set_osabi_string);
+    }
+
+  /* NOTE: At some point (true multiple architectures) we'll need to be more
+     graceful here.  */
+  gdbarch_info_init (&info);
+  if (! gdbarch_update_p (info))
+    internal_error (__FILE__, __LINE__, "Updating OS ABI failed.");
+}
 
 void
+show_osabi (char *args, int from_tty)
+{
+  if (user_osabi_state == osabi_auto)
+    printf_filtered ("The current OS ABI is \"auto\" (currently \"%s\").\n",
+		     gdbarch_osabi_name (gdbarch_osabi (current_gdbarch)));
+  else
+    printf_filtered ("The current OS ABI is \"%s\".\n",
+		     gdbarch_osabi_name (user_selected_osabi));
+
+  if (GDB_OSABI_DEFAULT != GDB_OSABI_UNKNOWN)
+    printf_filtered ("The default OS ABI is \"%s\".\n",
+		     gdbarch_osabi_name (GDB_OSABI_DEFAULT));
+}
+
+void
 _initialize_gdb_osabi (void)
 {
+  struct cmd_list_element *c;
+
   if (strcmp (gdb_osabi_names[GDB_OSABI_INVALID], "<invalid>") != 0)
     internal_error
       (__FILE__, __LINE__,
@@ -457,4 +557,16 @@ _initialize_gdb_osabi (void)
   gdbarch_register_osabi_sniffer (bfd_arch_unknown,
 				  bfd_target_elf_flavour,
 				  generic_elf_osabi_sniffer);
+
+  if (!GDB_MULTI_ARCH)
+    return;
+
+  /* Register the "set osabi" command.  */
+  c = add_set_enum_cmd ("osabi", class_support, gdb_osabi_available_names,
+			&set_osabi_string, "Set OS ABI of target.", &setlist);
+
+  set_cmd_sfunc (c, set_osabi);
+  add_cmd ("osabi", class_support, show_osabi, "Show OS/ABI of target.",
+	   &showlist);
+  user_osabi_state = osabi_auto;
 }


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