This is the mail archive of the gdb@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]

support dwarf 2.1 AT_ranges


It has been known for some time that if one has a nested function
inside of a lexical block that gets duplicated, either by bb-reorder
or unrolling, that dwarf2out will abort, because it doesn't like
being asked to root the same subprogram die into two places.

This has been reported before for ia64 compiling some glibc printf 
routines, and after the recent cfg changes, has started showing up
on alpha linux for some testsuite cases.

This fixes the problem by properly representing non-contiguous
lexical blocks via DW_AT_ranges as per dwarf2.1 draft 6.

Bootstrapped and tested on alphaev6 linux.  Given that this does
affect glibc for some platforms, I may backport this to the 3.0
branch as well.

Hopefully someone will have time to add support for this construct
to gdb in the near future.  I understand that they've just branched
for gdb 5.1, so it probably won't happen immediately.



r~


	* dwarf2out.c (dw_val_class_offset): New.
	(struct dw_ranges_struct, dw_ranges_ref): New.
	(ranges_table, ranges_table_allocated): New.
	(ranges_table_in_use, RANGES_TABLE_INCREMENT): New.
	(add_AT_offset, add_ranges, output_ranges): New.
	(print_die, output_die): Handle dw_val_class_offset.
	(attr_checksum, size_of_die, value_format): Likewise.
	(gen_lexical_block_die): Handle non-contiguous blocks.
	(gen_block_die): Likewise.
	(dwarf2out_finish): Add a DW_AT_entry_pc to the compilation unit
	if needed.  Dump the ranges table.
	* final.c (final_start_function): Remove unnecessary notes and
	rebuild the block tree before numbering the blocks.
	* function.c (reorder_blocks_0): Walk the existing block tree
	to unmark all blocks.
	(reorder_blocks_1): Create block fragments when duplicate block
	notes are seen.
	(reorder_fix_fragments): New.
	(reorder_blocks): Call it.
	* tree.h (BLOCK_FRAGMENT_ORIGIN, BLOCK_FRAGMENT_CHAIN): New.

Index: dwarf2out.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/dwarf2out.c,v
retrieving revision 1.295
diff -c -p -d -r1.295 dwarf2out.c
*** dwarf2out.c	2001/07/26 23:47:14	1.295
--- dwarf2out.c	2001/07/29 01:59:16
*************** typedef struct dw_loc_list_struct *dw_lo
*** 2138,2143 ****
--- 2138,2144 ----
  typedef enum
  {
    dw_val_class_addr,
+   dw_val_class_offset,
    dw_val_class_loc,
    dw_val_class_loc_list,
    dw_val_class_const,
*************** typedef struct dw_val_struct
*** 2181,2186 ****
--- 2182,2188 ----
    union
      {
        rtx val_addr;
+       long unsigned val_offset;
        dw_loc_list_ref  val_loc_list;
        dw_loc_descr_ref val_loc;
        long int val_int;
*************** typedef struct dw_attr_struct *dw_attr_r
*** 3075,3081 ****
  typedef struct dw_line_info_struct *dw_line_info_ref;
  typedef struct dw_separate_line_info_struct *dw_separate_line_info_ref;
  typedef struct pubname_struct *pubname_ref;
! typedef dw_die_ref *arange_ref;
  
  /* Each entry in the line_info_table maintains the file and
     line number associated with the label generated for that
--- 3077,3083 ----
  typedef struct dw_line_info_struct *dw_line_info_ref;
  typedef struct dw_separate_line_info_struct *dw_separate_line_info_ref;
  typedef struct pubname_struct *pubname_ref;
! typedef struct dw_ranges_struct *dw_ranges_ref;
  
  /* Each entry in the line_info_table maintains the file and
     line number associated with the label generated for that
*************** typedef struct pubname_struct
*** 3136,3141 ****
--- 3138,3148 ----
  }
  pubname_entry;
  
+ struct dw_ranges_struct
+ {
+   int block_num;
+ };
+ 
  /* The limbo die list structure.  */
  typedef struct limbo_die_struct
  {
*************** static unsigned pubname_table_in_use;
*** 3346,3354 ****
     pubname_table.  */
  #define PUBNAME_TABLE_INCREMENT 64
  
! /* A pointer to the base of a table that contains a list of publicly
!    accessible names.  */
! static arange_ref arange_table;
  
  /* Number of elements currently allocated for arange_table.  */
  static unsigned arange_table_allocated;
--- 3353,3360 ----
     pubname_table.  */
  #define PUBNAME_TABLE_INCREMENT 64
  
! /* Array of dies for which we should generate .debug_arange info.  */
! static dw_die_ref *arange_table;
  
  /* Number of elements currently allocated for arange_table.  */
  static unsigned arange_table_allocated;
*************** static unsigned arange_table_in_use;
*** 3360,3365 ****
--- 3366,3384 ----
     arange_table.  */
  #define ARANGE_TABLE_INCREMENT 64
  
+ /* Array of dies for which we should generate .debug_ranges info.  */
+ static dw_ranges_ref ranges_table;
+ 
+ /* Number of elements currently allocated for ranges_table.  */
+ static unsigned ranges_table_allocated;
+ 
+ /* Number of elements in ranges_table currently in use.  */
+ static unsigned ranges_table_in_use;
+ 
+ /* Size (in elements) of increments by which we may expand the
+    ranges_table.  */
+ #define RANGES_TABLE_INCREMENT 64
+ 
  /* Whether we have location lists that need outputting */
  static unsigned have_location_lists;
  
*************** static void add_AT_lbl_id		PARAMS ((dw_d
*** 3445,3450 ****
--- 3464,3472 ----
  static void add_AT_lbl_offset		PARAMS ((dw_die_ref,
  						 enum dwarf_attribute,
  						 const char *));
+ static void add_AT_offset		PARAMS ((dw_die_ref,
+ 						 enum dwarf_attribute,
+ 						 unsigned long));
  static dw_attr_ref get_AT		PARAMS ((dw_die_ref,
  						 enum dwarf_attribute));
  static const char *get_AT_low_pc	PARAMS ((dw_die_ref));
*************** static void add_pubname			PARAMS ((tree,
*** 3508,3513 ****
--- 3530,3537 ----
  static void output_pubnames		PARAMS ((void));
  static void add_arange			PARAMS ((tree, dw_die_ref));
  static void output_aranges		PARAMS ((void));
+ static unsigned int add_ranges		PARAMS ((tree));
+ static void output_ranges		PARAMS ((void));
  static void output_line_info		PARAMS ((void));
  static void output_file_names           PARAMS ((void));
  static dw_die_ref base_type_die		PARAMS ((tree));
*************** static char *gen_internal_sym 		PARAMS (
*** 3633,3638 ****
--- 3657,3665 ----
  #ifndef DEBUG_STR_SECTION
  #define DEBUG_STR_SECTION	".debug_str"
  #endif
+ #ifndef DEBUG_RANGES_SECTION
+ #define DEBUG_RANGES_SECTION	".debug_ranges"
+ #endif
  
  /* Standard ELF section names for compiled code and data.  */
  #ifndef TEXT_SECTION
*************** static char *gen_internal_sym 		PARAMS (
*** 3666,3671 ****
--- 3693,3699 ----
  #ifndef DEBUG_MACINFO_SECTION_LABEL
  #define DEBUG_MACINFO_SECTION_LABEL     "Ldebug_macinfo"
  #endif
+ 
  /* Definitions of defaults for formats and names of various special
     (artificial) labels which may be generated within this file (when the -g
     options is used and DWARF_DEBUGGING_INFO is in effect.
*************** dwarf_attr_name (attr)
*** 4030,4035 ****
--- 4058,4088 ----
      case DW_AT_vtable_elem_location:
        return "DW_AT_vtable_elem_location";
  
+     case DW_AT_allocated:
+       return "DW_AT_allocated";
+     case DW_AT_associated:
+       return "DW_AT_associated";
+     case DW_AT_data_location:
+       return "DW_AT_data_location";
+     case DW_AT_stride:
+       return "DW_AT_stride";
+     case DW_AT_entry_pc:
+       return "DW_AT_entry_pc";
+     case DW_AT_use_UTF8:
+       return "DW_AT_use_UTF8";
+     case DW_AT_extension:
+       return "DW_AT_extension";
+     case DW_AT_ranges:
+       return "DW_AT_ranges";
+     case DW_AT_trampoline:
+       return "DW_AT_trampoline";
+     case DW_AT_call_column:
+       return "DW_AT_call_column";
+     case DW_AT_call_file:
+       return "DW_AT_call_file";
+     case DW_AT_call_line:
+       return "DW_AT_call_line";
+ 
      case DW_AT_MIPS_fde:
        return "DW_AT_MIPS_fde";
      case DW_AT_MIPS_loop_begin:
*************** add_AT_lbl_offset (die, attr_kind, label
*** 4602,4607 ****
--- 4655,4677 ----
    add_dwarf_attr (die, attr);
  }
  
+ /* Add a rangeptr attribute value to a DIE.  */
+ 
+ static void
+ add_AT_offset (die, attr_kind, offset)
+      register dw_die_ref die;
+      register enum dwarf_attribute attr_kind;
+      register unsigned long offset;
+ {
+   register 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_offset;
+   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)
*************** print_die (die, outfile)
*** 5014,5024 ****
  	case dw_val_class_addr:
  	  fprintf (outfile, "address");
  	  break;
  	case dw_val_class_loc:
  	  fprintf (outfile, "location descriptor");
  	  break;
  	case dw_val_class_loc_list:
! 	  fprintf (outfile, "location list -> label:%s", AT_loc_list (a)->ll_symbol);
  	  break;
  	case dw_val_class_const:
  	  fprintf (outfile, "%ld", AT_int (a));
--- 5084,5098 ----
  	case dw_val_class_addr:
  	  fprintf (outfile, "address");
  	  break;
+ 	case dw_val_class_offset:
+ 	  fprintf (outfile, "offset");
+ 	  break;
  	case dw_val_class_loc:
  	  fprintf (outfile, "location descriptor");
  	  break;
  	case dw_val_class_loc_list:
! 	  fprintf (outfile, "location list -> label:%s",
! 		   AT_loc_list (a)->ll_symbol);
  	  break;
  	case dw_val_class_const:
  	  fprintf (outfile, "%ld", AT_int (a));
*************** attr_checksum (at, ctx)
*** 5249,5254 ****
--- 5323,5329 ----
      case dw_val_class_str:
        PROCESS_STRING (AT_string (at));
        break;
+ 
      case dw_val_class_addr:
        r = AT_addr (at);
        switch (GET_CODE (r))
*************** attr_checksum (at, ctx)
*** 5262,5267 ****
--- 5337,5346 ----
  	}
        break;
  
+     case dw_val_class_offset:
+       PROCESS (at->dw_attr_val.v.val_offset);
+       break;
+ 
      case dw_val_class_loc:
        for (loc = AT_loc (at); loc; loc = loc->dw_loc_next)
  	loc_checksum (loc, ctx);
*************** attr_checksum (at, ctx)
*** 5275,5280 ****
--- 5354,5360 ----
      case dw_val_class_fde_ref:
      case dw_val_class_lbl_id:
      case dw_val_class_lbl_offset:
+       break;
  
      default:
        break;
*************** size_of_die (die)
*** 5680,5685 ****
--- 5760,5768 ----
  	case dw_val_class_addr:
  	  size += DWARF2_ADDR_SIZE;
  	  break;
+ 	case dw_val_class_offset:
+ 	  size += DWARF_OFFSET_SIZE;
+ 	  break;
  	case dw_val_class_loc:
  	  {
  	    register unsigned long lsize = size_of_locs (AT_loc (a));
*************** value_format (a)
*** 5827,5832 ****
--- 5910,5921 ----
      {
      case dw_val_class_addr:
        return DW_FORM_addr;
+     case dw_val_class_offset:
+       if (DWARF_OFFSET_SIZE == 4)
+ 	return DW_FORM_data4;
+       if (DWARF_OFFSET_SIZE == 8)
+ 	return DW_FORM_data8;
+       abort ();
      case dw_val_class_loc_list:
        /* FIXME: Could be DW_FORM_data8, with a > 32 bit size
  	 .debug_loc section */
*************** value_format (a)
*** 5876,5881 ****
--- 5965,5971 ----
        return DW_FORM_data;
      case dw_val_class_str:
        return DW_FORM_string;
+ 
      default:
        abort ();
      }
*************** add_loc_descr_to_loc_list (list_head, de
*** 5990,5997 ****
    *d = new_loc_list (descr, begin, end, section, 0);
  }
  
- 
- 
  /* Output the location list given to us */
  static void
  output_loc_list (list_head)
--- 6080,6085 ----
*************** output_loc_list (list_head)
*** 5999,6004 ****
--- 6087,6096 ----
  {
    register dw_loc_list_ref curr=list_head;
    ASM_OUTPUT_LABEL (asm_out_file, list_head->ll_symbol);
+ 
+   /* ??? This shouldn't be needed now that we've forced the
+      compilation unit base address to zero when there is code
+      in more than one section.  */
    if (strcmp (curr->section, ".text") == 0)
      {
        /* dw2_asm_output_data will mask off any extra bits in the ~0.  */
*************** output_die (die)
*** 6060,6065 ****
--- 6152,6162 ----
  	  dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, AT_addr (a), "%s", name);
  	  break;
  
+ 	case dw_val_class_offset:
+ 	  dw2_asm_output_data (DWARF_OFFSET_SIZE, a->dw_attr_val.v.val_offset,
+ 			       "%s", name);
+ 	  break;
+ 
  	case dw_val_class_loc:
  	  size = size_of_locs (AT_loc (a));
  
*************** output_die (die)
*** 6121,6134 ****
  	case dw_val_class_flag:
  	  dw2_asm_output_data (1, AT_flag (a), "%s", name);
  	  break;
          case dw_val_class_loc_list:
  	  {
  	    char *sym = AT_loc_list (a)->ll_symbol;
  	    if (sym == 0)
  	      abort();
! 	    dw2_asm_output_delta (DWARF_OFFSET_SIZE, sym, loc_section_label, name);
  	  }
  	  break;
  	case dw_val_class_die_ref:
  	  if (AT_ref_external (a))
  	    {
--- 6218,6234 ----
  	case dw_val_class_flag:
  	  dw2_asm_output_data (1, AT_flag (a), "%s", name);
  	  break;
+ 
          case dw_val_class_loc_list:
  	  {
  	    char *sym = AT_loc_list (a)->ll_symbol;
  	    if (sym == 0)
  	      abort();
! 	    dw2_asm_output_delta (DWARF_OFFSET_SIZE, sym,
! 				  loc_section_label, "%s", name);
  	  }
  	  break;
+ 
  	case dw_val_class_die_ref:
  	  if (AT_ref_external (a))
  	    {
*************** add_arange (decl, die)
*** 6330,6338 ****
    if (arange_table_in_use == arange_table_allocated)
      {
        arange_table_allocated += ARANGE_TABLE_INCREMENT;
!       arange_table
! 	= (arange_ref) xrealloc (arange_table,
! 				 arange_table_allocated * sizeof (dw_die_ref));
      }
  
    arange_table[arange_table_in_use++] = die;
--- 6430,6437 ----
    if (arange_table_in_use == arange_table_allocated)
      {
        arange_table_allocated += ARANGE_TABLE_INCREMENT;
!       arange_table = (dw_die_ref *)
! 	xrealloc (arange_table, arange_table_allocated * sizeof (dw_die_ref));
      }
  
    arange_table[arange_table_in_use++] = die;
*************** output_aranges ()
*** 6418,6424 ****
--- 6517,6597 ----
    dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
  }
  
+ /* Add a new entry to .debug_ranges.  Return the offset at which it
+    was placed.  */
  
+ static unsigned int
+ add_ranges (block)
+      tree block;
+ {
+   unsigned int in_use = ranges_table_in_use;
+ 
+   if (in_use == ranges_table_allocated)
+     {
+       ranges_table_allocated += RANGES_TABLE_INCREMENT;
+       ranges_table = (dw_ranges_ref)
+ 	xrealloc (ranges_table, (ranges_table_allocated
+ 				 * sizeof (struct dw_ranges_struct)));
+     }
+ 
+   ranges_table[in_use].block_num = (block ? BLOCK_NUMBER (block) : 0);
+   ranges_table_in_use = in_use + 1;
+ 
+   return in_use * 2 * DWARF2_ADDR_SIZE;
+ }
+ 
+ static void
+ output_ranges ()
+ {
+   register unsigned i;
+   const char *start_fmt = "Offset 0x%x";
+   const char *fmt = start_fmt;
+ 
+   for (i = 0; i < ranges_table_in_use; ++i)
+     {
+       int block_num = ranges_table[i].block_num;
+ 
+       if (block_num)
+ 	{
+ 	  char blabel[MAX_ARTIFICIAL_LABEL_BYTES];
+ 	  char elabel[MAX_ARTIFICIAL_LABEL_BYTES];
+ 
+ 	  ASM_GENERATE_INTERNAL_LABEL (blabel, BLOCK_BEGIN_LABEL, block_num);
+ 	  ASM_GENERATE_INTERNAL_LABEL (elabel, BLOCK_END_LABEL, block_num);
+ 
+ 	  /* If all code is in the text section, then the compilation
+ 	     unit base address defaults to DW_AT_low_pc, which is the
+ 	     base of the text section.  */
+ 	  if (separate_line_info_table_in_use == 0)
+ 	    {
+ 	      dw2_asm_output_delta (DWARF2_ADDR_SIZE, blabel,
+ 				    text_section_label,
+ 				    fmt, i * 2 * DWARF2_ADDR_SIZE);
+ 	      dw2_asm_output_delta (DWARF2_ADDR_SIZE, elabel,
+ 				    text_section_label, NULL);
+ 	    }
+ 	  /* Otherwise, we add a DW_AT_entry_pc attribute to force the
+ 	     compilation unit base address to zero, which allows us to
+ 	     use absolute addresses, and not worry about whether the
+ 	     target supports cross-section arithmetic.  */
+ 	  else
+ 	    {
+ 	      dw2_asm_output_addr (DWARF2_ADDR_SIZE, blabel,
+ 				   fmt, i * 2 * DWARF2_ADDR_SIZE);
+ 	      dw2_asm_output_addr (DWARF2_ADDR_SIZE, elabel, NULL);
+ 	    }
+ 
+ 	  fmt = NULL;
+ 	}
+       else
+ 	{
+ 	  dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
+ 	  dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
+ 	  fmt = start_fmt;
+ 	}
+     }
+ }
+ 
  /* Data structure containing information about input files.  */
  struct file_info
  {
*************** gen_variable_die (decl, context_die)
*** 9973,9978 ****
--- 10146,10152 ----
    /* ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
       copy decls and set the DECL_ABSTRACT flag on them instead of
       sharing them.  */
+   /* ??? Duplicated blocks have been rewritten to use .debug_ranges.  */
    else if (old_die && TREE_STATIC (decl)
   	   && get_AT_flag (old_die, DW_AT_declaration) == 1)
      {
*************** gen_lexical_block_die (stmt, context_die
*** 10084,10095 ****
  
    if (! BLOCK_ABSTRACT (stmt))
      {
!       ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
! 				   BLOCK_NUMBER (stmt));
!       add_AT_lbl_id (stmt_die, DW_AT_low_pc, label);
!       ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
! 				   BLOCK_NUMBER (stmt));
!       add_AT_lbl_id (stmt_die, DW_AT_high_pc, label);
      }
  
    decls_for_scope (stmt, stmt_die, depth);
--- 10258,10287 ----
  
    if (! BLOCK_ABSTRACT (stmt))
      {
!       if (BLOCK_FRAGMENT_CHAIN (stmt))
! 	{
! 	  tree chain;
! 
! 	  add_AT_offset (stmt_die, DW_AT_ranges, add_ranges (stmt));
! 
! 	  chain = BLOCK_FRAGMENT_CHAIN (stmt);
! 	  do
! 	    {
! 	      add_ranges (chain);
! 	      chain = BLOCK_FRAGMENT_CHAIN (chain);
! 	    }
! 	  while (chain);
! 	  add_ranges (NULL);
! 	}
!       else
! 	{
! 	  ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
! 				       BLOCK_NUMBER (stmt));
! 	  add_AT_lbl_id (stmt_die, DW_AT_low_pc, label);
! 	  ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
! 				       BLOCK_NUMBER (stmt));
! 	  add_AT_lbl_id (stmt_die, DW_AT_high_pc, label);
! 	}
      }
  
    decls_for_scope (stmt, stmt_die, depth);
*************** gen_block_die (stmt, context_die, depth)
*** 10721,10731 ****
    register enum tree_code origin_code;
  
    /* Ignore blocks never really used to make RTL.  */
- 
    if (stmt == NULL_TREE || !TREE_USED (stmt)
        || (!TREE_ASM_WRITTEN (stmt) && !BLOCK_ABSTRACT (stmt)))
      return;
  
    /* Determine the "ultimate origin" of this block.  This block may be an
       inlined instance of an inlined instance of inline function, so we have
       to trace all of the way back through the origin chain to find out what
--- 10913,10934 ----
    register enum tree_code origin_code;
  
    /* Ignore blocks never really used to make RTL.  */
    if (stmt == NULL_TREE || !TREE_USED (stmt)
        || (!TREE_ASM_WRITTEN (stmt) && !BLOCK_ABSTRACT (stmt)))
      return;
  
+   /* If the block is one fragment of a non-contiguous block, do not
+      process the variables, since they will have been done by the
+      origin block.  Do process subblocks.  */
+   if (BLOCK_FRAGMENT_ORIGIN (stmt))
+     {
+       tree sub;
+ 
+       for (sub= BLOCK_SUBBLOCKS (stmt); sub; sub = BLOCK_CHAIN (sub))
+ 	gen_block_die (sub, context_die, depth + 1);
+       return;
+     }
+ 
    /* Determine the "ultimate origin" of this block.  This block may be an
       inlined instance of an inlined instance of inline function, so we have
       to trace all of the way back through the origin chain to find out what
*************** dwarf2out_finish (input_filename)
*** 11607,11612 ****
--- 11810,11820 ----
        add_AT_lbl_id (comp_unit_die, DW_AT_low_pc, text_section_label);
        add_AT_lbl_id (comp_unit_die, DW_AT_high_pc, text_end_label);
      }
+   /* And if it wasn't, we need to give .debug_loc and .debug_ranges
+      an appropriate "base address".  Use zero so that these addresses
+      become absolute.  */
+   else if (have_location_lists || ranges_table_in_use)
+     add_AT_addr (comp_unit_die, DW_AT_entry_pc, const0_rtx);
  
    if (debug_info_level >= DINFO_LEVEL_NORMAL)
      add_AT_lbl_offset (comp_unit_die, DW_AT_stmt_list,
*************** dwarf2out_finish (input_filename)
*** 11640,11646 ****
        ASM_OUTPUT_SECTION (asm_out_file, DEBUG_ARANGES_SECTION);
        output_aranges ();
      }
!   /* Output location list section if necessary */
    if (have_location_lists)
      {
        /* Output the location lists info. */
--- 11848,11855 ----
        ASM_OUTPUT_SECTION (asm_out_file, DEBUG_ARANGES_SECTION);
        output_aranges ();
      }
! 
!   /* Output location list section if necessary.  */
    if (have_location_lists)
      {
        /* Output the location lists info. */
*************** dwarf2out_finish (input_filename)
*** 11649,11660 ****
        have_location_lists = 0;
      }
  
    /* Have to end the primary source file. */
    if (debug_info_level >= DINFO_LEVEL_VERBOSE)
      { 
        ASM_OUTPUT_SECTION (asm_out_file, DEBUG_MACINFO_SECTION);
        dw2_asm_output_data (1, DW_MACINFO_end_file, "End file");
      }
-   
  }
  #endif /* DWARF2_DEBUGGING_INFO */
--- 11858,11875 ----
        have_location_lists = 0;
      }
  
+   /* Output ranges section if necessary.  */
+   if (ranges_table_in_use)
+     {
+       ASM_OUTPUT_SECTION (asm_out_file, DEBUG_RANGES_SECTION);
+       output_ranges ();
+     }
+ 
    /* Have to end the primary source file. */
    if (debug_info_level >= DINFO_LEVEL_VERBOSE)
      { 
        ASM_OUTPUT_SECTION (asm_out_file, DEBUG_MACINFO_SECTION);
        dw2_asm_output_data (1, DW_MACINFO_end_file, "End file");
      }
  }
  #endif /* DWARF2_DEBUGGING_INFO */
Index: final.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/final.c,v
retrieving revision 1.188
diff -c -p -d -r1.188 final.c
*** final.c	2001/07/26 06:56:12	1.188
--- final.c	2001/07/29 01:59:16
*************** final_start_function (first, file, optim
*** 1597,1604 ****
       function.  */
    if (write_symbols)
      {
-       number_blocks (current_function_decl);
        remove_unnecessary_notes ();
        /* We never actually put out begin/end notes for the top-level
  	 block in the function.  But, conceptually, that block is
  	 always needed.  */
--- 1597,1605 ----
       function.  */
    if (write_symbols)
      {
        remove_unnecessary_notes ();
+       reorder_blocks ();
+       number_blocks (current_function_decl);
        /* We never actually put out begin/end notes for the top-level
  	 block in the function.  But, conceptually, that block is
  	 always needed.  */
Index: function.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/function.c,v
retrieving revision 1.284
diff -c -p -d -r1.284 function.c
*** function.c	2001/07/26 05:45:25	1.284
--- function.c	2001/07/29 01:59:16
*************** static void pad_below		PARAMS ((struct a
*** 278,285 ****
  static rtx round_trampoline_addr PARAMS ((rtx));
  static rtx adjust_trampoline_addr PARAMS ((rtx));
  static tree *identify_blocks_1	PARAMS ((rtx, tree *, tree *, tree *));
! static void reorder_blocks_0	PARAMS ((rtx));
  static void reorder_blocks_1	PARAMS ((rtx, tree, varray_type *));
  static tree blocks_nreverse	PARAMS ((tree));
  static int all_blocks		PARAMS ((tree, tree *));
  static tree *get_block_vector   PARAMS ((tree, int *));
--- 278,286 ----
  static rtx round_trampoline_addr PARAMS ((rtx));
  static rtx adjust_trampoline_addr PARAMS ((rtx));
  static tree *identify_blocks_1	PARAMS ((rtx, tree *, tree *, tree *));
! static void reorder_blocks_0	PARAMS ((tree));
  static void reorder_blocks_1	PARAMS ((rtx, tree, varray_type *));
+ static void reorder_fix_fragments PARAMS ((tree));
  static tree blocks_nreverse	PARAMS ((tree));
  static int all_blocks		PARAMS ((tree, tree *));
  static tree *get_block_vector   PARAMS ((tree, int *));
*************** identify_blocks_1 (insns, block_vector, 
*** 5819,5826 ****
    return block_vector;
  }
  
! /* Identify BLOCKs referenced by more than one
!    NOTE_INSN_BLOCK_{BEG,END}, and create duplicate blocks.  */
  
  void
  reorder_blocks ()
--- 5820,5830 ----
    return block_vector;
  }
  
! /* Identify BLOCKs referenced by more than one NOTE_INSN_BLOCK_{BEG,END},
!    and create duplicate blocks.  */
! /* ??? Need an option to either create block fragments or to create
!    abstract origin duplicates of a source block.  It really depends
!    on what optimization has been performed.  */
  
  void
  reorder_blocks ()
*************** reorder_blocks ()
*** 5833,5879 ****
  
    VARRAY_TREE_INIT (block_stack, 10, "block_stack");
  
    /* Prune the old trees away, so that they don't get in the way.  */
    BLOCK_SUBBLOCKS (block) = NULL_TREE;
    BLOCK_CHAIN (block) = NULL_TREE;
  
!   reorder_blocks_0 (get_insns ());
    reorder_blocks_1 (get_insns (), block, &block_stack);
- 
    BLOCK_SUBBLOCKS (block) = blocks_nreverse (BLOCK_SUBBLOCKS (block));
  
    VARRAY_FREE (block_stack);
  }
  
! /* Helper function for reorder_blocks.  Process the insn chain beginning
!    at INSNS.  Recurse for CALL_PLACEHOLDER insns.  */
  
  static void
! reorder_blocks_0 (insns)
!      rtx insns;
  {
!   rtx insn;
! 
!   for (insn = insns; insn; insn = NEXT_INSN (insn))
      {
!       if (GET_CODE (insn) == NOTE)
! 	{
! 	  if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_BEG)
! 	    {
! 	      tree block = NOTE_BLOCK (insn);
! 	      TREE_ASM_WRITTEN (block) = 0;
! 	    }
! 	}
!       else if (GET_CODE (insn) == CALL_INSN
! 	       && GET_CODE (PATTERN (insn)) == CALL_PLACEHOLDER)
! 	{
! 	  rtx cp = PATTERN (insn);
! 	  reorder_blocks_0 (XEXP (cp, 0));
! 	  if (XEXP (cp, 1))
! 	    reorder_blocks_0 (XEXP (cp, 1));
! 	  if (XEXP (cp, 2))
! 	    reorder_blocks_0 (XEXP (cp, 2));
! 	}
      }
  }
  
--- 5837,5870 ----
  
    VARRAY_TREE_INIT (block_stack, 10, "block_stack");
  
+   /* Reset the TREE_ASM_WRITTEN bit for all blocks.  */
+   reorder_blocks_0 (block);
+ 
    /* Prune the old trees away, so that they don't get in the way.  */
    BLOCK_SUBBLOCKS (block) = NULL_TREE;
    BLOCK_CHAIN (block) = NULL_TREE;
  
!   /* Recreate the block tree from the note nesting.  */
    reorder_blocks_1 (get_insns (), block, &block_stack);
    BLOCK_SUBBLOCKS (block) = blocks_nreverse (BLOCK_SUBBLOCKS (block));
  
+   /* Remove deleted blocks from the block fragment chains.  */
+   reorder_fix_fragments (block);
+ 
    VARRAY_FREE (block_stack);
  }
  
! /* Helper function for reorder_blocks.  Reset TREE_ASM_WRITTEN.  */
  
  static void
! reorder_blocks_0 (block)
!      tree block;
  {
!   while (block)
      {
!       TREE_ASM_WRITTEN (block) = 0;
!       reorder_blocks_0 (BLOCK_SUBBLOCKS (block));
!       block = BLOCK_CHAIN (block);
      }
  }
  
*************** reorder_blocks_1 (insns, current_block, 
*** 5892,5903 ****
  	  if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_BEG)
  	    {
  	      tree block = NOTE_BLOCK (insn);
! 	      /* If we have seen this block before, copy it.  */
  	      if (TREE_ASM_WRITTEN (block))
  		{
! 		  block = copy_node (block);
! 		  NOTE_BLOCK (insn) = block;
  		}
  	      BLOCK_SUBBLOCKS (block) = 0;
  	      TREE_ASM_WRITTEN (block) = 1;
  	      BLOCK_SUPERCONTEXT (block) = current_block;
--- 5883,5908 ----
  	  if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_BEG)
  	    {
  	      tree block = NOTE_BLOCK (insn);
! 
! 	      /* If we have seen this block before, that means it now
! 		 spans multiple address regions.  Create a new fragment.  */
  	      if (TREE_ASM_WRITTEN (block))
  		{
! 		  tree new_block = copy_node (block);
! 		  tree origin;
! 
! 		  origin = (BLOCK_FRAGMENT_ORIGIN (block)
! 			    ? BLOCK_FRAGMENT_ORIGIN (block)
! 			    : block);
! 		  BLOCK_FRAGMENT_ORIGIN (new_block) = origin;
! 		  BLOCK_FRAGMENT_CHAIN (new_block)
! 		    = BLOCK_FRAGMENT_CHAIN (origin);
! 		  BLOCK_FRAGMENT_CHAIN (origin) = new_block;
! 
! 		  NOTE_BLOCK (insn) = new_block;
! 		  block = new_block;
  		}
+ 
  	      BLOCK_SUBBLOCKS (block) = 0;
  	      TREE_ASM_WRITTEN (block) = 1;
  	      BLOCK_SUPERCONTEXT (block) = current_block;
*************** reorder_blocks_1 (insns, current_block, 
*** 5925,5930 ****
--- 5930,5991 ----
  	  if (XEXP (cp, 2))
  	    reorder_blocks_1 (XEXP (cp, 2), current_block, p_block_stack);
  	}
+     }
+ }
+ 
+ /* Rationalize BLOCK_FRAGMENT_ORIGIN.  If an origin block no longer
+    appears in the block tree, select one of the fragments to become
+    the new origin block.  */
+ 
+ static void
+ reorder_fix_fragments (block)
+     tree block;
+ {
+   while (block)
+     {
+       tree dup_origin = BLOCK_FRAGMENT_ORIGIN (block);
+       tree new_origin = NULL_TREE;
+ 
+       if (dup_origin)
+ 	{
+ 	  if (! TREE_ASM_WRITTEN (dup_origin))
+ 	    {
+ 	      new_origin = BLOCK_FRAGMENT_CHAIN (dup_origin);
+ 	      
+ 	      /* Find the first of the remaining fragments.  There must
+ 		 be at least one -- the current block.  */
+ 	      while (! TREE_ASM_WRITTEN (new_origin))
+ 		new_origin = BLOCK_FRAGMENT_CHAIN (new_origin);
+ 	      BLOCK_FRAGMENT_ORIGIN (new_origin) = NULL_TREE;
+ 	    }
+ 	}
+       else if (! dup_origin)
+ 	new_origin = block;
+ 
+       /* Re-root the rest of the fragments to the new origin.  In the
+ 	 case that DUP_ORIGIN was null, that means BLOCK was the origin
+ 	 of a chain of fragments and we want to remove those fragments
+ 	 that didn't make it to the output.  */
+       if (new_origin)
+ 	{
+ 	  tree *pp = &BLOCK_FRAGMENT_CHAIN (new_origin);
+ 	  tree chain = *pp;
+ 
+ 	  while (chain)
+ 	    {
+ 	      if (TREE_ASM_WRITTEN (chain))
+ 		{
+ 		  BLOCK_FRAGMENT_ORIGIN (chain) = new_origin;
+ 		  *pp = chain;
+ 		  pp = &BLOCK_FRAGMENT_CHAIN (chain);
+ 		}
+ 	      chain = BLOCK_FRAGMENT_CHAIN (chain);
+ 	    }
+ 	  *pp = NULL_TREE;
+ 	}
+ 
+       reorder_fix_fragments (BLOCK_SUBBLOCKS (block));
+       block = BLOCK_CHAIN (block);
      }
  }
  
Index: tree.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree.h,v
retrieving revision 1.257
diff -c -p -d -r1.257 tree.h
*** tree.h	2001/07/19 21:17:09	1.257
--- tree.h	2001/07/29 01:59:16
*************** struct tree_exp
*** 848,853 ****
--- 848,880 ----
     the debugging output format in use.  */
  #define BLOCK_NUMBER(NODE) (BLOCK_CHECK (NODE)->block.block_num)
  
+ /* If block reordering splits a lexical block into discontiguous
+    address ranges, we'll make a copy of the original block.
+ 
+    Note that this is logically distinct from BLOCK_ABSTRACT_ORIGIN.
+    In that case, we have one source block that has been replicated
+    (through inlining or unrolling) into many logical blocks, and that
+    these logical blocks have different physical variables in them.
+ 
+    In this case, we have one logical block split into several
+    non-contiguous address ranges.  Most debug formats can't actually
+    represent this idea directly, so we fake it by creating multiple
+    logical blocks with the same variables in them.  However, for those
+    that do support non-contiguous regions, these allow the original
+    logical block to be reconstructed, along with the set of address
+    ranges.
+ 
+    One of the logical block fragments is arbitrarily chosen to be
+    the ORIGIN.  The other fragments will point to the origin via
+    BLOCK_FRAGMENT_ORIGIN; the origin itself will have this pointer
+    be null.  The list of fragments will be chained through 
+    BLOCK_FRAGMENT_CHAIN from the origin.  */
+ 
+ #define BLOCK_FRAGMENT_ORIGIN(NODE) \
+   (BLOCK_CHECK (NODE)->block.fragment_origin)
+ #define BLOCK_FRAGMENT_CHAIN(NODE) \
+   (BLOCK_CHECK (NODE)->block.fragment_chain)
+ 
  struct tree_block
  {
    struct tree_common common;
*************** struct tree_block
*** 860,865 ****
--- 887,894 ----
    union tree_node *subblocks;
    union tree_node *supercontext;
    union tree_node *abstract_origin;
+   union tree_node *fragment_origin;
+   union tree_node *fragment_chain;
  };
  
  /* Define fields and accessors for nodes representing data types.  */


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