This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC 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] Fix .debug_ranges and a bug in output_loc_list


Hi!

The following patch makes all rangelist attributes emitted as
.Ldebug_ranges+offset
so that it works properly even in presence of multiple input .debug_ranges
section in the final link.
Also, DWARF standard (at least V3 draft 7) sais .debug_loc location
expression length should be a 2-byte field, while current code was using
constant_size(size).
Ok to commit?

2001-12-11  Jakub Jelinek  <jakub@redhat.com>

	* dwarf2out.c (dw_val_class): Add dw_val_class_range_list.
	(DEBUG_RANGES_SECTION_LABEL): Define.
	(ranges_section_label): Add.
	(add_AT_range_list): New.
	(print_die, sizeof_die, value_format): Handle dw_val_class_range_list.
	(output_loc_list): Location expression length is always 2-byte.
	(output_die): Handle dw_val_class_range_list.
	(gen_lexical_block_die): Call add_AT_range_list.
	(dwarf2out_init): Initialize ranges_section_label.
	(dwarf2out_finish): Emit ranges_section_label.
	* dwarf2asm.h (dw2_asm_output_offset_addend): Add prototype.
	* dwarf2asm.c (dw2_asm_output_offset_addend): New.

--- gcc/dwarf2out.c.jj	Tue Dec  4 11:21:26 2001
+++ gcc/dwarf2out.c	Tue Dec 11 19:08:23 2001
@@ -2140,6 +2140,7 @@ typedef enum
   dw_val_class_offset,
   dw_val_class_loc,
   dw_val_class_loc_list,
+  dw_val_class_range_list,
   dw_val_class_const,
   dw_val_class_unsigned_const,
   dw_val_class_long_long,
@@ -3672,6 +3673,9 @@ static char *gen_internal_sym 		PARAMS (
 #ifndef DEBUG_LOC_SECTION_LABEL
 #define DEBUG_LOC_SECTION_LABEL		"Ldebug_loc"
 #endif
+#ifndef DEBUG_RANGES_SECTION_LABEL
+#define DEBUG_RANGES_SECTION_LABEL	"Ldebug_ranges"
+#endif
 #ifndef DEBUG_MACINFO_SECTION_LABEL
 #define DEBUG_MACINFO_SECTION_LABEL     "Ldebug_macinfo"
 #endif
@@ -3689,6 +3693,7 @@ static char debug_info_section_label[MAX
 static char debug_line_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
 static char macinfo_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
 static char loc_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
+static char ranges_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
 #ifndef TEXT_END_LABEL
 #define TEXT_END_LABEL		"Letext"
 #endif
@@ -4714,6 +4719,23 @@ add_AT_offset (die, attr_kind, offset)
   add_dwarf_attr (die, attr);
 }
 
+/* Add an range_list attribute value to a DIE.  */
+
+static void
+add_AT_range_list (die, attr_kind, offset)
+     dw_die_ref die;
+     enum dwarf_attribute attr_kind;
+     unsigned long offset;
+{
+  dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
+
+  attr->dw_attr_next = NULL;
+  attr->dw_attr = attr_kind;
+  attr->dw_attr_val.val_class = dw_val_class_range_list;
+  attr->dw_attr_val.v.val_offset = offset;
+  add_dwarf_attr (die, attr);
+}
+
 static inline const char *AT_lbl PARAMS ((dw_attr_ref));
 static inline const char *
 AT_lbl (a)
@@ -5147,6 +5169,9 @@ print_die (die, outfile)
 	  fprintf (outfile, "location list -> label:%s",
 		   AT_loc_list (a)->ll_symbol);
 	  break;
+	case dw_val_class_range_list:
+	  fprintf (outfile, "range list");
+	  break;
 	case dw_val_class_const:
 	  fprintf (outfile, "%ld", AT_int (a));
 	  break;
@@ -5818,6 +5843,9 @@ size_of_die (die)
 	case dw_val_class_loc_list:
 	  size += DWARF_OFFSET_SIZE;
 	  break;
+	case dw_val_class_range_list:
+	  size += DWARF_OFFSET_SIZE;
+	  break;
 	case dw_val_class_const:
 	  size += size_of_sleb128 (AT_int (a));
 	  break;
@@ -5956,6 +5984,7 @@ value_format (a)
     {
     case dw_val_class_addr:
       return DW_FORM_addr;
+    case dw_val_class_range_list:
     case dw_val_class_offset:
       if (DWARF_OFFSET_SIZE == 4)
 	return DW_FORM_data4;
@@ -6147,7 +6176,7 @@ output_loc_list (list_head)
     }
   for (curr = list_head; curr != NULL; curr=curr->dw_loc_next)
     {
-      int size;
+      unsigned long size;
       dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->begin, curr->section,
 			    "Location list begin address (%s)",
 			    list_head->ll_symbol);
@@ -6157,9 +6186,10 @@ output_loc_list (list_head)
       size = size_of_locs (curr->expr);
       
       /* Output the block length for this list of location operations.  */
-      dw2_asm_output_data (constant_size (size), size, "%s",
-			   "Location expression size");
-      
+      if (size > 0xffff)
+	abort ();
+      dw2_asm_output_data (2, size, "%s", "Location expression size");
+
       output_loc_sequence (curr->expr);
     }
   dw2_asm_output_data (DWARF_OFFSET_SIZE, 0,
@@ -6204,6 +6234,13 @@ output_die (die)
 			       "%s", name);
 	  break;
 
+	case dw_val_class_range_list:
+	  dw2_asm_output_offset_addend (DWARF_OFFSET_SIZE,
+					ranges_section_label,
+					a->dw_attr_val.v.val_offset,
+					"%s", name);
+	  break;
+
 	case dw_val_class_loc:
 	  size = size_of_locs (AT_loc (a));
 
@@ -10388,7 +10425,7 @@ gen_lexical_block_die (stmt, context_die
 	{
 	  tree chain;
 
-	  add_AT_offset (stmt_die, DW_AT_ranges, add_ranges (stmt));
+	  add_AT_range_list (stmt_die, DW_AT_ranges, add_ranges (stmt));
 
 	  chain = BLOCK_FRAGMENT_CHAIN (stmt);
 	  do
@@ -11832,6 +11869,8 @@ dwarf2out_init (main_input_filename)
 			       DEBUG_INFO_SECTION_LABEL, 0);
   ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label,
 			       DEBUG_LINE_SECTION_LABEL, 0);
+  ASM_GENERATE_INTERNAL_LABEL (ranges_section_label,
+			       DEBUG_RANGES_SECTION_LABEL, 0);
   named_section_flags (DEBUG_ABBREV_SECTION, SECTION_DEBUG);
   ASM_OUTPUT_LABEL (asm_out_file, abbrev_section_label);
   named_section_flags (DEBUG_INFO_SECTION, SECTION_DEBUG);
@@ -12023,6 +12062,7 @@ dwarf2out_finish (input_filename)
   if (ranges_table_in_use)
     {
       named_section_flags (DEBUG_RANGES_SECTION, SECTION_DEBUG);
+      ASM_OUTPUT_LABEL (asm_out_file, ranges_section_label);
       output_ranges ();
     }
 
--- gcc/dwarf2asm.c.jj	Tue Dec  4 11:21:26 2001
+++ gcc/dwarf2asm.c	Tue Dec 11 19:14:38 2001
@@ -158,7 +158,7 @@ dw2_asm_output_delta VPARAMS ((int size,
 
 void
 dw2_asm_output_offset VPARAMS ((int size, const char *label,
-			       const char *comment, ...))
+				const char *comment, ...))
 {
   VA_OPEN (ap, comment);
   VA_FIXEDARG (ap, int, size);
@@ -176,6 +176,49 @@ dw2_asm_output_offset VPARAMS ((int size
 #endif
 #endif
 
+  if (flag_debug_asm && comment)
+    {
+      fprintf (asm_out_file, "\t%s ", ASM_COMMENT_START);
+      vfprintf (asm_out_file, comment, ap);
+    }
+  fputc ('\n', asm_out_file);
+
+  VA_CLOSE (ap);
+}
+
+/* Like dw2_asm_output_offset, but use label + addend as offset.  */
+
+void
+dw2_asm_output_offset_addend VPARAMS ((int size, const char *label,
+				       unsigned long int addend,
+				       const char *comment, ...))
+{
+  VA_OPEN (ap, comment);
+  VA_FIXEDARG (ap, int, size);
+  VA_FIXEDARG (ap, const char *, label);
+  VA_FIXEDARG (ap, const char *, comment);
+
+#ifdef ASM_OUTPUT_DWARF_OFFSET
+  ASM_OUTPUT_DWARF_OFFSET (asm_out_file, size, label);
+  if (addend)
+    fprintf (asm_out_file, "+0x%lx", addend);
+#else
+#ifdef UNALIGNED_INT_ASM_OP
+  fputs (unaligned_integer_asm_op (size), asm_out_file);
+  assemble_name (asm_out_file, label);
+  if (addend)
+    fprintf (asm_out_file, "+0x%lx", addend);
+#else
+  {
+    rtx tem = gen_rtx_SYMBOL_REF (Pmode, label);
+
+    if (addend)
+      tem = gen_rtx_PLUS (Pmode, tem, GEN_INT (addend));
+    assemble_integer (tem, size, BITS_PER_UNIT, 1);
+  }
+#endif
+#endif
+
   if (flag_debug_asm && comment)
     {
       fprintf (asm_out_file, "\t%s ", ASM_COMMENT_START);
--- gcc/dwarf2asm.h.jj	Tue Nov  6 20:02:22 2001
+++ gcc/dwarf2asm.h	Tue Dec 11 18:50:44 2001
@@ -36,6 +36,11 @@ extern void dw2_asm_output_offset	PARAMS
 						 const char *, ...))
      /* ATTRIBUTE_PRINTF_3 */;
 
+extern void dw2_asm_output_offset_addend PARAMS ((int, const char *,
+						  unsigned long int,
+						  const char *, ...))
+     /* ATTRIBUTE_PRINTF_4 */;
+
 extern void dw2_asm_output_pcrel	PARAMS ((int, const char *,
 						 const char *, ...))
      /* ATTRIBUTE_PRINTF_3 */;

	Jakub


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