Index: trunk/src/gcc/gcc/dbxout.c
===================================================================
--- trunk/src/gcc/gcc/dbxout.c	(revision 721)
+++ trunk/src/gcc/gcc/dbxout.c	(revision 722)
@@ -310,4 +310,5 @@
 static void print_wide_int		PARAMS ((HOST_WIDE_INT));
 static void dbxout_type_name		PARAMS ((tree));
+static void dbxout_class_name_qualifiers PARAMS ((tree)); /* bird: from 3.3.1 */
 static int dbxout_symbol_location	PARAMS ((tree, tree, const char *, rtx));
 static void dbxout_symbol_name		PARAMS ((tree, const char *, int));
@@ -674,8 +675,14 @@
 {
   if (TREE_CODE (decl) == VAR_DECL
+#ifdef EMX /* bird: debug info for all referenced global vars. */
+      && (   !DECL_EXTERNAL (decl)
+          || (   use_gnu_debug_info_extensions
+              && TREE_SYMBOL_REFERENCED (DECL_NAME (decl))))
+#else
       && ! DECL_EXTERNAL (decl)
+#endif
       && DECL_RTL_SET_P (decl))	/* Not necessary?  */
     dbxout_symbol (decl, 0);
-} 
+}
 
 /* At the end of compilation, finish writing the symbol table.
@@ -1868,5 +1875,5 @@
   CHARS (digs);
 }
-      
+
 /* Output the name of type TYPE, with no punctuation.
    Such names can be set up either by typedef declarations
@@ -1893,4 +1900,32 @@
   fprintf (asmfile, "%s", IDENTIFIER_POINTER (t));
   CHARS (IDENTIFIER_LENGTH (t));
+}
+
+/* bird: from 3.3.1: */
+/* Output leading leading struct or class names needed for qualifying
+   type whose scope is limited to a struct or class.  */
+
+static void
+dbxout_class_name_qualifiers (decl)
+     tree decl;
+{
+  tree context = decl_type_context (decl);
+
+  if (context != NULL_TREE
+      && TREE_CODE(context) == RECORD_TYPE
+      && TYPE_NAME (context) != 0
+      && (TREE_CODE (TYPE_NAME (context)) == IDENTIFIER_NODE
+          || (DECL_NAME (TYPE_NAME (context)) != 0)))
+    {
+      tree name = TYPE_NAME (context);
+
+      if (TREE_CODE (name) == TYPE_DECL)
+	{
+	  dbxout_class_name_qualifiers (name);
+	  name = DECL_NAME (name);
+	}
+      fprintf (asmfile, "%s::", IDENTIFIER_POINTER (name));
+      CHARS (IDENTIFIER_LENGTH (name) + 2);
+    }
 }
 
@@ -2036,7 +2071,21 @@
 	      }
 
+#if 1  /* bird: from 3.3.1 */
+	    /* Output .stabs (or whatever) and leading double quote.  */
+	    fprintf (asmfile, "%s\"", ASM_STABS_OP);
+
+	    if (use_gnu_debug_info_extensions)
+	      {
+		/* Output leading class/struct qualifiers.  */
+		dbxout_class_name_qualifiers (decl);
+	      }
+
 	    /* Output typedef name.  */
+	    fprintf (asmfile, "%s:", IDENTIFIER_POINTER (DECL_NAME (decl)));
+#else
+    	    /* Output typedef name.  */
 	    fprintf (asmfile, "%s\"%s:", ASM_STABS_OP,
 		     IDENTIFIER_POINTER (DECL_NAME (decl)));
+#endif
 
 	    /* Short cut way to output a tag also.  */
@@ -2130,8 +2179,17 @@
       if (! DECL_RTL_SET_P (decl))
 	return 0;
+#ifdef EMX
+      /* Don't mention a variable that is external and unreferenced..
+	 bird: Referenced variables must be mentioned for OMF support.  */
+      if (DECL_EXTERNAL (decl)
+          && (   !use_gnu_debug_info_extensions
+              || !TREE_SYMBOL_REFERENCED (DECL_NAME (decl))))
+        break;
+#else
       /* Don't mention a variable that is external.
 	 Let the file that defines it describe it.  */
       if (DECL_EXTERNAL (decl))
 	break;
+#endif
 
       /* If the variable is really a constant
@@ -2180,5 +2238,5 @@
       result = dbxout_symbol_location (decl, type, 0, DECL_RTL (decl));
       break;
-      
+
     default:
       break;
@@ -2205,5 +2263,5 @@
   /* Don't mention a variable at all
      if it was completely optimized into nothingness.
-     
+
      If the decl was from an inline function, then its rtl
      is not identically the rtl that was used in this
@@ -2249,4 +2307,37 @@
 	  letter = 'G';
 	  current_sym_code = N_GSYM;
+#ifdef EMX
+          /* bird: This is hacks for two things. The first part, to use the
+             value of a 'G', is intended to help resolving global symbols
+             when the variable name isn't equal to the assembler name. f.ex.:
+                class foo { foo() {static const char *psz= "foo";} };
+             The 2nd hack is for external symbols, which we need debug info for
+             on EMX due to HLL conversion. In that case we need to find the
+             variable somehow and generates a special alias symbol for it.
+             The alias is a pretty unique name which includes the string
+             '$hll$' which is what we'll look for. ld accept multiple
+             definitions of aliases so it's not really a problem there. The
+             value of these 'G' stabs are always -12357.  */
+          if (use_gnu_debug_info_extensions)
+            {
+              current_sym_addr = XEXP (home, 0);
+              if (DECL_EXTERNAL (decl))
+                {
+                  struct timeval tv;
+                  /* We'll make a special alias for the external symbol
+                     which the a.out -> omf copy will detect.
+                     Todo: This should really be _after_ the symbol. */
+                  dbxout_symbol_name (decl, suffix, letter);
+                  gettimeofday(&tv, NULL);
+                  fprintf (asmfile, "$hll$%lx%08lx\",%d,0,0,0\n",
+                           tv.tv_sec, tv.tv_usec, /*N_INDR | N_EXT*/11);
+                  fprintf (asmfile, "\t.stabs\t\"");
+                  output_addr_const (asmfile, current_sym_addr);
+                  fprintf (asmfile, "\",%d,0,0,0\n", /*N_EXT*/ 1);
+                  current_sym_addr = 0;
+                  current_sym_value = -12357;
+                }
+            }
+#endif
 	}
       else
@@ -2284,5 +2375,5 @@
 		    current_sym_addr = tmp;
 		}
-  
+
 	      /* Ultrix `as' seems to need this.  */
 #ifdef DBX_STATIC_STAB_DATA_SECTION
@@ -2575,5 +2666,5 @@
 
 	    /* It is quite tempting to use:
-	       
+	
 	           dbxout_type (TREE_TYPE (parms), 0);
 
@@ -2712,5 +2803,6 @@
 	        = INTVAL (XEXP (XEXP (XEXP (DECL_RTL (parms), 0), 0), 1));
 	    current_sym_addr = 0;
-	      
+	    current_sym_code = N_PSYM; /* bird: from 3.3.1 */
+	
 	    FORCE_TEXT;
 	    fprintf (asmfile, "%s\"%s:v", ASM_STABS_OP, decl_name);
@@ -2750,5 +2842,5 @@
 		&& GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (parms))) < UNITS_PER_WORD)
 	      {
-		current_sym_value += 
+		current_sym_value +=
 		    GET_MODE_SIZE (GET_MODE (DECL_RTL (parms)))
 		    - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (parms)));
@@ -2862,5 +2954,5 @@
 
 #if DBX_BLOCKS_FUNCTION_RELATIVE
-  const char *begin_label; 
+  const char *begin_label;
   if (current_function_func_begin_label != NULL_TREE)
     begin_label = IDENTIFIER_POINTER (current_function_func_begin_label);
