[PATCH] Use the new DWARF4 mandated DW_FORMs for -gdwarf-4

Jakub Jelinek jakub@redhat.com
Wed Mar 31 23:46:00 GMT 2010


On Wed, Mar 31, 2010 at 11:35:54AM -0700, Cary Coutant wrote:
> gdb does already support the use of DW_FORM_ref_sig8 and
> DW_TAG_type_unit, etc., as extensions to DWARF-3. The -gdwarf-4 flag
> is currently used to enable that, while still writing "3" as the DWARF
> version number in the CU header. You'll need to remove the following
> code from output_compilation_unit_header() that downgrades
> dwarf_version to 3:
> 
>   /* Don't mark the output as DWARF-4 until we make full use of the
>      version 4 extensions, and gdb supports them.  For now, -gdwarf-4
>      selects only a few extensions from the DWARF-4 spec.  */
>   if (ver > 3)
>     ver = 3;

Done in the following patch.

I've also added the new DW_AT_lower_bound language defaults that DWARF4
adds.

Ok for trunk?

2010-03-31  Jakub Jelinek  <jakub@redhat.com>

	* dwarf2out.c (output_compilation_unit_header, output_line_info): For
	-gdwarf-4 use version 4 instead of version 3.

	* dwarf2out.c (is_c_family, is_java): Remove.
	(lower_bound_default): New function.
	(add_bound_info, gen_descr_array_type_die): Use it.

--- gcc/dwarf2out.c.jj	2010-03-31 17:44:06.000000000 +0200
+++ gcc/dwarf2out.c	2010-03-31 23:59:30.000000000 +0200
@@ -5964,9 +5964,7 @@ static const char *get_AT_string (dw_die
 static int get_AT_flag (dw_die_ref, enum dwarf_attribute);
 static unsigned get_AT_unsigned (dw_die_ref, enum dwarf_attribute);
 static inline dw_die_ref get_AT_ref (dw_die_ref, enum dwarf_attribute);
-static bool is_c_family (void);
 static bool is_cxx (void);
-static bool is_java (void);
 static bool is_fortran (void);
 static bool is_ada (void);
 static void remove_AT (dw_die_ref, enum dwarf_attribute);
@@ -7443,18 +7441,6 @@ get_AT_file (dw_die_ref die, enum dwarf_
   return a ? AT_file (a) : NULL;
 }
 
-/* Return TRUE if the language is C or C++.  */
-
-static inline bool
-is_c_family (void)
-{
-  unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
-
-  return (lang == DW_LANG_C || lang == DW_LANG_C89 || lang == DW_LANG_ObjC
-	  || lang == DW_LANG_C99
-	  || lang == DW_LANG_C_plus_plus || lang == DW_LANG_ObjC_plus_plus);
-}
-
 /* Return TRUE if the language is C++.  */
 
 static inline bool
@@ -7477,16 +7463,6 @@ is_fortran (void)
 	  || lang == DW_LANG_Fortran95);
 }
 
-/* Return TRUE if the language is Java.  */
-
-static inline bool
-is_java (void)
-{
-  unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
-
-  return lang == DW_LANG_Java;
-}
-
 /* Return TRUE if the language is Ada.  */
 
 static inline bool
@@ -10687,11 +10663,6 @@ output_compilation_unit_header (void)
 {
   int ver = dwarf_version;
 
-  /* Don't mark the output as DWARF-4 until we make full use of the
-     version 4 extensions, and gdb supports them.  For now, -gdwarf-4
-     selects only a few extensions from the DWARF-4 spec.  */
-  if (ver > 3)
-    ver = 3;
   if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
     dw2_asm_output_data (4, 0xffffffff,
       "Initial length escape value indicating 64-bit DWARF extension");
@@ -11538,12 +11509,6 @@ output_line_info (void)
   unsigned long function;
   int ver = dwarf_version;
 
-  /* Don't mark the output as DWARF-4 until we make full use of the
-     version 4 extensions, and gdb supports them.  For now, -gdwarf-4
-     selects only a few extensions from the DWARF-4 spec.  */
-  if (ver > 3)
-    ver = 3;
-
   ASM_GENERATE_INTERNAL_LABEL (l1, LINE_NUMBER_BEGIN_LABEL, 0);
   ASM_GENERATE_INTERNAL_LABEL (l2, LINE_NUMBER_END_LABEL, 0);
   ASM_GENERATE_INTERNAL_LABEL (p1, LN_PROLOG_AS_LABEL, 0);
@@ -16339,6 +16304,42 @@ add_comp_dir_attribute (dw_die_ref die)
     add_AT_string (die, DW_AT_comp_dir, remap_debug_filename (wd));
 }
 
+/* Return the default for DW_AT_lower_bound, or -1 if there is not any
+   default.  */
+
+static int
+lower_bound_default (void)
+{
+  switch (get_AT_unsigned (comp_unit_die, DW_AT_language))
+    {
+    case DW_LANG_C:
+    case DW_LANG_C89:
+    case DW_LANG_C99:
+    case DW_LANG_C_plus_plus:
+    case DW_LANG_ObjC:
+    case DW_LANG_ObjC_plus_plus:
+    case DW_LANG_Java:
+      return 0;
+    case DW_LANG_Fortran77:
+    case DW_LANG_Fortran90:
+    case DW_LANG_Fortran95:
+      return 1;
+    case DW_LANG_UPC:
+    case DW_LANG_D:
+      return dwarf_version >= 4 ? 0 : -1;
+    case DW_LANG_Ada95:
+    case DW_LANG_Ada83:
+    case DW_LANG_Cobol74:
+    case DW_LANG_Cobol85:
+    case DW_LANG_Pascal83:
+    case DW_LANG_Modula2:
+    case DW_LANG_PLI:
+      return dwarf_version >= 4 ? 1 : -1;
+    default:
+      return -1;
+    }
+}
+
 /* Given a tree node describing an array bound (either lower or upper) output
    a representation for that bound.  */
 
@@ -16356,11 +16357,13 @@ add_bound_info (dw_die_ref subrange_die,
     case INTEGER_CST:
       {
 	unsigned int prec = simple_type_size_in_bits (TREE_TYPE (bound));
+	int dflt;
 
 	/* Use the default if possible.  */
 	if (bound_attr == DW_AT_lower_bound
-	    && (((is_c_family () || is_java ()) && integer_zerop (bound))
-	        || (is_fortran () && integer_onep (bound))))
+	    && host_integerp (bound, 0)
+	    && (dflt = lower_bound_default ()) != -1
+	    && tree_low_cst (bound, 0) == dflt)
 	  ;
 
 	/* Otherwise represent the bound as an unsigned value with the
@@ -17261,11 +17264,11 @@ gen_descr_array_type_die (tree type, str
       if (info->dimen[dim].lower_bound)
 	{
 	  /* If it is the default value, omit it.  */
-	  if ((is_c_family () || is_java ())
-	      && integer_zerop (info->dimen[dim].lower_bound))
-	    ;
-	  else if (is_fortran ()
-		   && integer_onep (info->dimen[dim].lower_bound))
+	  int dflt;
+
+	  if (host_integerp (info->dimen[dim].lower_bound, 0)
+	      && (dflt = lower_bound_default ()) != -1
+	      && tree_low_cst (info->dimen[dim].lower_bound, 0) == dflt)
 	    ;
 	  else
 	    add_descr_info_field (subrange_die, DW_AT_lower_bound,


	Jakub



More information about the Gcc-patches mailing list