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]

[patch/rfc] Fix gdb/1426: osabi initialization race condition


Hello,

ref: http://sources.redhat.com/gdb/bugs/1426 for details.

The attached implements the "hack" suggested in tdep/1426 to work around a bogus error message:

A handler for the OS ABI "GNU/Linux" is not built into this configuration of GDB. Attempting to continue with the default rs6000:6000 settingsGNU gdb 2003-10-23-cvs
Copyright 2003 Free Software Foundation, Inc.
...


that appears on some platforms during startup.

Baring comment, I'll commit this in a few days.

Andrew
2003-10-23  Andrew Cagney  <cagney@redhat.com>

	* osabi.c (GDB_OSABI_DEFAULT): Delete macro definition.
	(user_osabi_default): New static variable.
	(_initialize_gdb_osabi): Initialize "user_osabi_default" to
	GDB_OSABI_DEFAULT if defined, GDB_OSABI_UNKNOWN otherwize.
	(gdbarch_lookup_osabi): Replace GDB_OSABI_DEFAULT with
	"user_osabi_default".
	(set_osabi, show_osabi): Ditto.
	Work around GDB PR tdep/1426.

Index: osabi.c
===================================================================
RCS file: /cvs/src/src/gdb/osabi.c,v
retrieving revision 1.17
diff -u -r1.17 osabi.c
--- osabi.c	24 Aug 2003 11:47:18 -0000	1.17
+++ osabi.c	24 Oct 2003 02:30:08 -0000
@@ -30,10 +30,6 @@
 
 #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;
@@ -45,6 +41,23 @@
 };
 static const char *set_osabi_string;
 
+/* Value for the "default" osabi.
+
+   It is initialized, during per-file initialization, by the function
+   _initialize_osabi below, to the build-time macro GDB_OSABI_DEFAULT.
+   Due to a race condition with the code trying to create the initial
+   "static" architecture, it is not statically initialized to
+   GDB_OSABI_DEFAULT.
+
+   The problem with static initialization is that the code creating
+   that initial "static" architecture calls gdbarch_osabi_init
+   (requesting the "default" OSABI) before any per-file initialization
+   has occured, but it is only during that per-file initialization
+   that the OSABI target code gets to register that said "default"
+   OSABI.  Starting the user_osabi_default out as "uninitialized", and
+   then initializing it at per-file time works around the problem.  */
+static int user_osabi_default = GDB_OSABI_UNINITIALIZED;
+
 /* This table matches the indices assigned to enum gdb_osabi.  Keep
    them in sync.  */
 static const char * const gdb_osabi_names[] =
@@ -210,8 +223,8 @@
      an inconclusive result (otherwise).  */
   if (abfd == NULL) 
     {
-      if (GDB_OSABI_DEFAULT != GDB_OSABI_UNKNOWN)
-	return GDB_OSABI_DEFAULT;
+      if (user_osabi_default != GDB_OSABI_UNKNOWN)
+	return user_osabi_default;
       else
 	return GDB_OSABI_UNINITIALIZED;
     }
@@ -277,8 +290,8 @@
 
   /* 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;
+  if (user_osabi_default != GDB_OSABI_UNKNOWN && match == GDB_OSABI_UNKNOWN)
+    return user_osabi_default;
   else
     return match;
 }
@@ -504,7 +517,7 @@
     user_osabi_state = osabi_auto;
   else if (strcmp (set_osabi_string, "default") == 0)
     {
-      user_selected_osabi = GDB_OSABI_DEFAULT;
+      user_selected_osabi = user_osabi_default;
       user_osabi_state = osabi_user;
     }
   else if (strcmp (set_osabi_string, "none") == 0)
@@ -545,9 +558,9 @@
     printf_filtered ("The current OS ABI is \"%s\".\n",
 		     gdbarch_osabi_name (user_selected_osabi));
 
-  if (GDB_OSABI_DEFAULT != GDB_OSABI_UNKNOWN)
+  if (user_osabi_default != GDB_OSABI_UNKNOWN)
     printf_filtered ("The default OS ABI is \"%s\".\n",
-		     gdbarch_osabi_name (GDB_OSABI_DEFAULT));
+		     gdbarch_osabi_name (user_osabi_default));
 }
 
 extern initialize_file_ftype _initialize_gdb_osabi; /* -Wmissing-prototype */
@@ -577,4 +590,9 @@
   add_cmd ("osabi", class_support, show_osabi, "Show OS/ABI of target.",
 	   &showlist);
   user_osabi_state = osabi_auto;
+#ifdef GDB_OSABI_DEFAULT
+  user_osabi_default = GDB_OSABI_DEFAULT;
+#else
+  user_osabi_default = GDB_OSABI_UNKNOWN;
+#endif
 }

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