OSDN Git Service

* sh.h (STRUCT_VALUE, RETURN_IN_MEMORY): Define.
[pf3gnuchains/gcc-fork.git] / gcc / dwarf2out.c
index 8b81267..c493d54 100644 (file)
@@ -1,5 +1,6 @@
 /* Output Dwarf2 format symbol table information from the GNU C compiler.
-   Copyright (C) 1992, 93, 95-98, 1999 Free Software Foundation, Inc.
+   Copyright (C) 1992, 1993, 1995, 1996, 1997, 1998, 1999, 2000
+   Free Software Foundation, Inc.
    Contributed by Gary Funck (gary@intrepid.com).
    Derived from DWARF 1 implementation of Ron Guilmette (rfg@monkeys.com).
    Extensively modified by Jason Merrill (jason@cygnus.com).
@@ -21,6 +22,16 @@ along with GNU CC; see the file COPYING.  If not, write to
 the Free Software Foundation, 59 Temple Place - Suite 330,
 Boston, MA 02111-1307, USA.  */
 
+/* TODO: Implement .debug_str handling, and share entries somehow.
+        Eliminate duplicates by putting common info in a separate section
+          to be collected by the linker and referring to it with
+          DW_FORM_ref_addr.
+        Emit .debug_line header even when there are no functions, since
+          the file numbers are used by .debug_info.  Alternately, leave
+          out locations for types and decls.
+        Avoid talking about ctors and op= for PODs.
+        Factor out common prologue sequences into multiple CIEs.  */
+
 /* The first part of this file deals with the DWARF 2 frame unwind
    information, which is also used by the GCC efficient exception handling
    mechanism.  The second part, controlled only by an #ifdef
@@ -43,7 +54,9 @@ Boston, MA 02111-1307, USA.  */
 #include "dwarf2.h"
 #include "dwarf2out.h"
 #include "toplev.h"
-#include "dyn-string.h"
+#include "varray.h"
+#include "ggc.h"
+#include "tm_p.h"
 
 /* We cannot use <assert.h> in GCC source, since that would include
    GCC's assert.h, which may not be compatible with the host compiler.  */
@@ -65,6 +78,7 @@ dwarf2out_do_frame ()
           || DWARF2_FRAME_INFO
 #endif
 #ifdef DWARF2_UNWIND_INFO
+         || flag_unwind_tables
          || (flag_exceptions && ! exceptions_via_longjmp)
 #endif
          );
@@ -115,6 +129,7 @@ typedef struct dw_fde_struct
   char *dw_fde_current_label;
   char *dw_fde_end;
   dw_cfi_ref dw_fde_cfi;
+  int nothrow;
 }
 dw_fde_node;
 
@@ -145,7 +160,7 @@ dw_fde_node;
 
 /* Round SIZE up to the nearest BOUNDARY.  */
 #define DWARF_ROUND(SIZE,BOUNDARY) \
-  (((SIZE) + (BOUNDARY) - 1) & ~((BOUNDARY) - 1))
+  ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
 
 /* Offsets recorded in opcodes are a multiple of this alignment factor.  */
 #ifdef STACK_GROWS_DOWNWARD
@@ -186,25 +201,26 @@ static unsigned current_funcdef_fde;
 
 /* Forward declarations for functions defined in this file.  */
 
-static char *stripattributes           PROTO((char *));
-static char *dwarf_cfi_name            PROTO((unsigned));
-static dw_cfi_ref new_cfi              PROTO((void));
-static void add_cfi                    PROTO((dw_cfi_ref *, dw_cfi_ref));
-static unsigned long size_of_uleb128   PROTO((unsigned long));
-static unsigned long size_of_sleb128   PROTO((long));
-static void output_uleb128             PROTO((unsigned long));
-static void output_sleb128             PROTO((long));
-static void add_fde_cfi                        PROTO((char *, dw_cfi_ref));
-static void lookup_cfa_1               PROTO((dw_cfi_ref, unsigned long *,
-                                              long *));
-static void lookup_cfa                 PROTO((unsigned long *, long *));
-static void reg_save                   PROTO((char *, unsigned, unsigned,
-                                              long));
-static void initial_return_save                PROTO((rtx));
-static void output_cfi                 PROTO((dw_cfi_ref, dw_fde_ref));
-static void output_call_frame_info     PROTO((int));
-static unsigned reg_number             PROTO((rtx));
-static void dwarf2out_stack_adjust     PROTO((rtx));
+static char *stripattributes           PARAMS ((const char *));
+static const char *dwarf_cfi_name      PARAMS ((unsigned));
+static dw_cfi_ref new_cfi              PARAMS ((void));
+static void add_cfi                    PARAMS ((dw_cfi_ref *, dw_cfi_ref));
+static unsigned long size_of_uleb128   PARAMS ((unsigned long));
+static unsigned long size_of_sleb128   PARAMS ((long));
+static void output_uleb128             PARAMS ((unsigned long));
+static void output_sleb128             PARAMS ((long));
+static void add_fde_cfi                        PARAMS ((char *, dw_cfi_ref));
+static void lookup_cfa_1               PARAMS ((dw_cfi_ref, unsigned long *,
+                                                long *));
+static void lookup_cfa                 PARAMS ((unsigned long *, long *));
+static void reg_save                   PARAMS ((char *, unsigned, unsigned,
+                                                long));
+static void initial_return_save                PARAMS ((rtx));
+static void output_cfi                 PARAMS ((dw_cfi_ref, dw_fde_ref));
+static void output_call_frame_info     PARAMS ((int));
+static unsigned int reg_number         PARAMS ((rtx));
+static void dwarf2out_stack_adjust     PARAMS ((rtx));
+static void dwarf2out_frame_debug_expr PARAMS ((rtx, char *));
 
 /* Definitions of defaults for assembler-dependent names of various
    pseudo-ops and section names.
@@ -297,7 +313,8 @@ static void dwarf2out_stack_adjust  PROTO((rtx));
 
 #ifndef UNALIGNED_WORD_ASM_OP
 #define UNALIGNED_WORD_ASM_OP \
-  (PTR_SIZE == 8 ? UNALIGNED_DOUBLE_INT_ASM_OP : UNALIGNED_INT_ASM_OP)
+  ((PTR_SIZE) == 8 ? UNALIGNED_DOUBLE_INT_ASM_OP : \
+   ((PTR_SIZE) == 2 ? UNALIGNED_SHORT_ASM_OP : UNALIGNED_INT_ASM_OP))
 #endif
 
 #ifndef ASM_OUTPUT_DWARF_DELTA2
@@ -343,19 +360,12 @@ static void dwarf2out_stack_adjust        PROTO((rtx));
   } while (0)
 #endif
 
-/* ??? This macro takes an RTX in dwarfout.c and a string in dwarf2out.c.
-   We resolve the conflict by creating a new macro ASM_OUTPUT_DWARF2_ADDR_CONST
-   for ports that want to support both DWARF1 and DWARF2.  This needs a better
-   solution.  See also the comments in sparc/sp64-elf.h.  */
-#ifdef ASM_OUTPUT_DWARF2_ADDR_CONST
-#undef ASM_OUTPUT_DWARF_ADDR_CONST
-#define ASM_OUTPUT_DWARF_ADDR_CONST(FILE,ADDR) \
-  ASM_OUTPUT_DWARF2_ADDR_CONST (FILE, ADDR)
-#endif
-
 #ifndef ASM_OUTPUT_DWARF_ADDR_CONST
-#define ASM_OUTPUT_DWARF_ADDR_CONST(FILE,ADDR)                         \
-  fprintf ((FILE), "\t%s\t%s", UNALIGNED_WORD_ASM_OP, (ADDR))
+#define ASM_OUTPUT_DWARF_ADDR_CONST(FILE,RTX)                          \
+  do {                                                                 \
+    fprintf ((FILE), "\t%s\t", UNALIGNED_WORD_ASM_OP);                 \
+    output_addr_const ((FILE), (RTX));                                 \
+  } while (0)
 #endif
 
 #ifndef ASM_OUTPUT_DWARF_OFFSET4
@@ -426,20 +436,20 @@ static void dwarf2out_stack_adjust        PROTO((rtx));
 
 #define ASM_OUTPUT_DWARF_DELTA2(FILE,LABEL1,LABEL2)                    \
   assemble_integer (gen_rtx_MINUS (HImode,                             \
-                            gen_rtx_SYMBOL_REF (Pmode, LABEL1),        \
-                            gen_rtx_SYMBOL_REF (Pmode, LABEL2)),       \
+                                  gen_rtx_SYMBOL_REF (Pmode, LABEL1),  \
+                                  gen_rtx_SYMBOL_REF (Pmode, LABEL2)), \
                    2, 1)
   
 #define ASM_OUTPUT_DWARF_DELTA4(FILE,LABEL1,LABEL2)                    \
   assemble_integer (gen_rtx_MINUS (SImode,                             \
-                            gen_rtx_SYMBOL_REF (Pmode, LABEL1),        \
-                            gen_rtx_SYMBOL_REF (Pmode, LABEL2)),       \
+                                  gen_rtx_SYMBOL_REF (Pmode, LABEL1),  \
+                                  gen_rtx_SYMBOL_REF (Pmode, LABEL2)), \
                    4, 1)
 
 #define ASM_OUTPUT_DWARF_ADDR_DELTA(FILE,LABEL1,LABEL2)                        \
   assemble_integer (gen_rtx_MINUS (Pmode,                              \
-                            gen_rtx_SYMBOL_REF (Pmode, LABEL1),        \
-                            gen_rtx_SYMBOL_REF (Pmode, LABEL2)),       \
+                                  gen_rtx_SYMBOL_REF (Pmode, LABEL1),  \
+                                  gen_rtx_SYMBOL_REF (Pmode, LABEL2)), \
                    PTR_SIZE, 1)
 
 #define ASM_OUTPUT_DWARF_DELTA(FILE,LABEL1,LABEL2) \
@@ -471,7 +481,7 @@ static void dwarf2out_stack_adjust  PROTO((rtx));
 #define ASM_OUTPUT_DWARF_STRING(FILE,P) \
   do {                                                                       \
     register int slen = strlen(P);                                            \
-    register char *p = (P);                                                  \
+    register const char *p = (P);                                            \
     register int i;                                                          \
     fprintf (FILE, "\t.ascii \"");                                           \
     for (i = 0; i < slen; i++)                                               \
@@ -479,7 +489,7 @@ static void dwarf2out_stack_adjust  PROTO((rtx));
          register int c = p[i];                                              \
          if (c == '\"' || c == '\\')                                         \
            putc ('\\', FILE);                                                \
-         if (c >= ' ' && c < 0177)                                           \
+         if (ISPRINT(c))                                                     \
            putc (c, FILE);                                                   \
          else                                                                \
            {                                                                 \
@@ -498,7 +508,7 @@ static void dwarf2out_stack_adjust  PROTO((rtx));
 #ifdef PC_REGNUM
 #define DWARF_FRAME_RETURN_COLUMN      DWARF_FRAME_REGNUM (PC_REGNUM)
 #else
-#define DWARF_FRAME_RETURN_COLUMN      FIRST_PSEUDO_REGISTER
+#define DWARF_FRAME_RETURN_COLUMN      DWARF_FRAME_REGISTERS
 #endif
 #endif
 
@@ -527,7 +537,7 @@ expand_builtin_dwarf_fp_regnum ()
 
 static inline char *
 stripattributes (s)
-     char *s;
+     const char *s;
 {
   char *stripped = xmalloc (strlen (s) + 2);
   char *p = stripped;
@@ -543,7 +553,7 @@ stripattributes (s)
 
 /* Return the register number described by a given RTL node.  */
 
-static unsigned
+static unsigned int
 reg_number (rtl)
      register rtx rtl;
 {
@@ -559,115 +569,31 @@ reg_number (rtl)
   return regno;
 }
 
-struct reg_size_range
-{
-  int beg;
-  int end;
-  int size;
-};
-
-/* Given a register number in REG_TREE, return an rtx for its size in bytes.
-   We do this in kind of a roundabout way, by building up a list of
-   register size ranges and seeing where our register falls in one of those
-   ranges.  We need to do it this way because REG_TREE is not a constant,
-   and the target macros were not designed to make this task easy.  */
+/* Generate code to initialize the register size table.  */
 
-rtx
-expand_builtin_dwarf_reg_size (reg_tree, target)
-     tree reg_tree;
-     rtx target;
+void
+expand_builtin_init_dwarf_reg_sizes (address)
+     tree address;
 {
-  enum machine_mode mode;
-  int size;
-  struct reg_size_range ranges[5];
-  tree t, t2;
-
-  int i = 0;
-  int n_ranges = 0;
-  int last_size = -1;
+  int i;
+  enum machine_mode mode = TYPE_MODE (char_type_node);
+  rtx addr = expand_expr (address, NULL_RTX, VOIDmode, 0);
+  rtx mem = gen_rtx_MEM (mode, addr);
 
-  for (; i < FIRST_PSEUDO_REGISTER; ++i)
+  for (i = 0; i < DWARF_FRAME_REGISTERS; ++i)
     {
-      /* The return address is out of order on the MIPS, and we don't use
-        copy_reg for it anyway, so we don't care here how large it is.  */
-      if (DWARF_FRAME_REGNUM (i) == DWARF_FRAME_RETURN_COLUMN)
-       continue;
-
-      mode = reg_raw_mode[i];
-
-      /* CCmode is arbitrarily given a size of 4 bytes.  It is more useful
-        to use the same size as word_mode, since that reduces the number
-        of ranges we need.  It should not matter, since the result should
-        never be used for a condition code register anyways.  */
-      if (GET_MODE_CLASS (mode) == MODE_CC)
-       mode = word_mode;
-
-      size = GET_MODE_SIZE (mode);
+      int offset = i * GET_MODE_SIZE (mode);
+      int size = GET_MODE_SIZE (reg_raw_mode[i]);
 
-      /* If this register is not valid in the specified mode and
-        we have a previous size, use that for the size of this
-        register to avoid making junk tiny ranges.  */
-      if (! HARD_REGNO_MODE_OK (i, mode) && last_size != -1)
-       size = last_size;
-
-      if (size != last_size)
-       {
-         ranges[n_ranges].beg = i;
-         ranges[n_ranges].size = last_size = size;
-         ++n_ranges;
-         if (n_ranges >= 5)
-           abort ();
-       }
-      ranges[n_ranges-1].end = i;
-    }
-
-  /* The usual case: fp regs surrounded by general regs.  */
-  if (n_ranges == 3 && ranges[0].size == ranges[2].size)
-    {
-      if ((DWARF_FRAME_REGNUM (ranges[1].end)
-          - DWARF_FRAME_REGNUM (ranges[1].beg))
-         != ranges[1].end - ranges[1].beg)
-       abort ();
-      t  = fold (build (GE_EXPR, integer_type_node, reg_tree,
-                       build_int_2 (DWARF_FRAME_REGNUM (ranges[1].beg), 0)));
-      t2 = fold (build (LE_EXPR, integer_type_node, reg_tree,
-                       build_int_2 (DWARF_FRAME_REGNUM (ranges[1].end), 0)));
-      t = fold (build (TRUTH_ANDIF_EXPR, integer_type_node, t, t2));
-      t = fold (build (COND_EXPR, integer_type_node, t,
-                      build_int_2 (ranges[1].size, 0),
-                      build_int_2 (ranges[0].size, 0)));
-    }
-  else
-    {
-      /* Initialize last_end to be larger than any possible
-        DWARF_FRAME_REGNUM.  */
-      int last_end = 0x7fffffff;
-      --n_ranges;
-      t = build_int_2 (ranges[n_ranges].size, 0);
-      do
-       {
-         int beg = DWARF_FRAME_REGNUM (ranges[n_ranges].beg);
-         int end = DWARF_FRAME_REGNUM (ranges[n_ranges].end);
-         if (beg < 0)
-           continue;
-         if (end >= last_end)
-           abort ();
-         last_end = end;
-         if (end - beg != ranges[n_ranges].end - ranges[n_ranges].beg)
-           abort ();
-         t2 = fold (build (LE_EXPR, integer_type_node, reg_tree,
-                           build_int_2 (end, 0)));
-         t = fold (build (COND_EXPR, integer_type_node, t2,
-                          build_int_2 (ranges[n_ranges].size, 0), t));
-       }
-      while (--n_ranges >= 0);
+      emit_move_insn (change_address (mem, mode,
+                                     plus_constant (addr, offset)),
+                     GEN_INT (size));
     }
-  return expand_expr (t, target, Pmode, 0);
 }
 
 /* Convert a DWARF call frame info. operation to its string name */
 
-static char *
+static const char *
 dwarf_cfi_name (cfi_opc)
      register unsigned cfi_opc;
 {
@@ -719,6 +645,8 @@ dwarf_cfi_name (cfi_opc)
       return "DW_CFA_GNU_window_save";
     case DW_CFA_GNU_args_size:
       return "DW_CFA_GNU_args_size";
+    case DW_CFA_GNU_negative_offset_extended:
+      return "DW_CFA_GNU_negative_offset_extended";
 
     default:
       return "DW_CFA_<unknown>";
@@ -948,9 +876,15 @@ reg_save (label, reg, sreg, offset)
 
       offset /= DWARF_CIE_DATA_ALIGNMENT;
       if (offset < 0)
-       abort ();
+       {
+         cfi->dw_cfi_opc = DW_CFA_GNU_negative_offset_extended;
+         offset = -offset;
+       }
       cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
     }
+  else if (sreg == reg)
+    /* We could emit a DW_CFA_same_value in this case, but don't bother.  */
+    return;
   else
     {
       cfi->dw_cfi_opc = DW_CFA_register;
@@ -1044,7 +978,7 @@ initial_return_save (rtl)
     {
     case REG:
       /* RA is in a register.  */
-      reg = reg_number (rtl);
+      reg = DWARF_FRAME_REGNUM (REGNO (rtl));
       break;
     case MEM:
       /* RA is on the stack.  */
@@ -1243,10 +1177,11 @@ dwarf2out_frame_debug_expr (expr, label)
         case REG:
           if (cfa_reg != (unsigned) REGNO (src))
             abort ();
-          if (REGNO (dest) != STACK_POINTER_REGNUM
-             && !(frame_pointer_needed
-                  && REGNO (dest) == HARD_FRAME_POINTER_REGNUM))
-            abort ();
+
+         /* We used to require that dest be either SP or FP, but the
+            ARM copies SP to a temporary register, and from there to
+            FP.  So we just rely on the backends to only set
+            RTX_FRAME_RELATED_P on appropriate insns.  */
           cfa_reg = REGNO (dest);
           break;
 
@@ -1290,32 +1225,19 @@ dwarf2out_frame_debug_expr (expr, label)
             {
              /* Either setting the FP from an offset of the SP,
                 or adjusting the FP */
-             if (! frame_pointer_needed
-                 || REGNO (dest) != HARD_FRAME_POINTER_REGNUM)
+             if (! frame_pointer_needed)
                abort ();
 
-             if (XEXP (src, 0) == stack_pointer_rtx
+             if (GET_CODE (XEXP (src, 0)) == REG
+                 && (unsigned) REGNO (XEXP (src, 0)) == cfa_reg
                  && GET_CODE (XEXP (src, 1)) == CONST_INT)
                {
-                 if (cfa_reg != STACK_POINTER_REGNUM)
-                   abort ();
                  offset = INTVAL (XEXP (src, 1));
                  if (GET_CODE (src) == PLUS)
                    offset = -offset;
                  cfa_offset += offset;
                  cfa_reg = HARD_FRAME_POINTER_REGNUM;
                }
-             else if (XEXP (src, 0) == hard_frame_pointer_rtx
-                      && GET_CODE (XEXP (src, 1)) == CONST_INT)
-               {
-                 if (cfa_reg != (unsigned) HARD_FRAME_POINTER_REGNUM)
-                   abort ();
-                 offset = INTVAL (XEXP (src, 1));
-                 if (GET_CODE (src) == PLUS)
-                   offset = -offset;
-                 cfa_offset += offset;
-               }
-
              else 
                abort();
             }
@@ -1392,7 +1314,7 @@ dwarf2out_frame_debug_expr (expr, label)
 
          /* Without an offset.  */
        case REG:
-         if (cfa_store_reg != (unsigned) REGNO (XEXP (dest, 0)))
+         if (cfa_store_reg != REGNO (XEXP (dest, 0)))
            abort();
          offset = -cfa_store_offset;
          break;
@@ -1425,7 +1347,7 @@ dwarf2out_frame_debug (insn)
     {
       /* Set up state for generating call frame debug info.  */
       lookup_cfa (&cfa_reg, &cfa_offset);
-      if (cfa_reg != DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM))
+      if (cfa_reg != (unsigned long) DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM))
        abort ();
       cfa_reg = STACK_POINTER_REGNUM;
       cfa_store_reg = cfa_reg;
@@ -1635,6 +1557,7 @@ output_cfi (cfi, fde)
          break;
 #endif
        case DW_CFA_offset_extended:
+       case DW_CFA_GNU_negative_offset_extended:
        case DW_CFA_def_cfa:
          output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
           fputc ('\n', asm_out_file);
@@ -1673,24 +1596,6 @@ output_cfi (cfi, fde)
      }
 }
 
-#if !defined (EH_FRAME_SECTION)
-#if defined (EH_FRAME_SECTION_ASM_OP)
-#define EH_FRAME_SECTION() eh_frame_section();
-#else
-#if defined (ASM_OUTPUT_SECTION_NAME)
-#define EH_FRAME_SECTION()                             \
-  do {                                                 \
-      named_section (NULL_TREE, ".eh_frame", 0);       \
-  } while (0)
-#endif
-#endif
-#endif
-
-/* If we aren't using crtstuff to run ctors, don't use it for EH.  */
-#if !defined (HAS_INIT_SECTION) && !defined (INIT_SECTION_ASM_OP)
-#undef EH_FRAME_SECTION
-#endif
-
 /* Output the call frame information used to used to record information
    that relates to calculating the frame pointer, and records the
    location of saved registers.  */
@@ -1710,6 +1615,17 @@ output_call_frame_info (for_eh)
   /* Do we want to include a pointer to the exception table?  */
   int eh_ptr = for_eh && exception_table_p ();
 
+  /* If we don't have any functions we'll want to unwind out of, don't
+     emit any EH unwind information.  */
+  if (for_eh)
+    {
+      for (i = 0; i < fde_table_in_use; ++i)
+       if (! fde_table[i].nothrow)
+         goto found;
+      return;
+    found:;
+    }
+
   fputc ('\n', asm_out_file);
 
   /* We're going to be generating comments, so turn on app.  */
@@ -1842,6 +1758,10 @@ output_call_frame_info (for_eh)
     {
       fde = &fde_table[i];
 
+      /* Don't emit EH unwind info for leaf functions.  */
+      if (for_eh && fde->nothrow)
+       continue;
+
       ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + i*2);
       ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + i*2);
 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
@@ -1939,6 +1859,7 @@ dwarf2out_begin_prologue ()
   ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL,
                               current_funcdef_number);
   ASM_OUTPUT_LABEL (asm_out_file, label);
+  current_function_func_begin_label = get_identifier (label);
 
   /* Expand the fde table if necessary.  */
   if (fde_table_in_use == fde_table_allocated)
@@ -1958,6 +1879,7 @@ dwarf2out_begin_prologue ()
   fde->dw_fde_current_label = NULL;
   fde->dw_fde_end = NULL;
   fde->dw_fde_cfi = NULL;
+  fde->nothrow = current_function_nothrow;
 
   args_size = old_args_size = 0;
 }
@@ -1984,9 +1906,7 @@ void
 dwarf2out_frame_init ()
 {
   /* Allocate the initial hunk of the fde_table.  */
-  fde_table
-    = (dw_fde_ref) xmalloc (FDE_TABLE_INCREMENT * sizeof (dw_fde_node));
-  bzero ((char *) fde_table, FDE_TABLE_INCREMENT * sizeof (dw_fde_node));
+  fde_table = (dw_fde_ref) xcalloc (FDE_TABLE_INCREMENT, sizeof (dw_fde_node));
   fde_table_allocated = FDE_TABLE_INCREMENT;
   fde_table_in_use = 0;
 
@@ -2007,11 +1927,11 @@ dwarf2out_frame_finish ()
 #ifdef MIPS_DEBUGGING_INFO
   if (write_symbols == DWARF2_DEBUG)
     output_call_frame_info (0);
-  if (flag_exceptions && ! exceptions_via_longjmp)
+  if (flag_unwind_tables || (flag_exceptions && ! exceptions_via_longjmp))
     output_call_frame_info (1);
 #else
   if (write_symbols == DWARF2_DEBUG
-      || (flag_exceptions && ! exceptions_via_longjmp))
+      || flag_unwind_tables || (flag_exceptions && ! exceptions_via_longjmp))
     output_call_frame_info (1);  
 #endif
 }  
@@ -2021,8 +1941,6 @@ dwarf2out_frame_finish ()
 /* And now, the support for symbolic debugging information.  */
 #ifdef DWARF2_DEBUGGING_INFO
 
-extern char *getpwd PROTO((void));
-
 /* NOTE: In the comments in this file, many references are made to
    "Debugging Information Entries".  This term is abbreviated as `DIE'
    throughout the remainder of this file.  */
@@ -2117,7 +2035,7 @@ typedef struct dw_val_struct
   dw_val_class val_class;
   union
     {
-      char *val_addr;
+      rtx val_addr;
       dw_loc_descr_ref val_loc;
       long int val_int;
       long unsigned val_unsigned;
@@ -2163,10 +2081,8 @@ typedef struct die_struct
 {
   enum dwarf_tag die_tag;
   dw_attr_ref die_attr;
-  dw_attr_ref die_attr_last;
   dw_die_ref die_parent;
   dw_die_ref die_child;
-  dw_die_ref die_child_last;
   dw_die_ref die_sib;
   dw_offset die_offset;
   unsigned long die_abbrev;
@@ -2220,8 +2136,6 @@ limbo_die_node;
    language, and compiler version.  */
 
 extern int flag_traditional;
-extern char *version_string;
-extern char *language_string;
 
 /* Fixed size portion of the DWARF compilation unit header.  */
 #define DWARF_COMPILE_UNIT_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 3)
@@ -2236,6 +2150,17 @@ extern char *language_string;
 #define DWARF_ARANGES_HEADER_SIZE \
   (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, PTR_SIZE * 2) - DWARF_OFFSET_SIZE)
 
+/* Size of padding portion in the address range info.  It must be
+   aligned to twice the pointer size.  */
+#define DWARF_ARANGES_PAD_SIZE \
+  (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, PTR_SIZE * 2) \
+   - (2 * DWARF_OFFSET_SIZE + 4))
+
+/* The default is to have gcc emit the line number tables.  */
+#ifndef DWARF2_ASM_LINE_DEBUG_INFO
+#define DWARF2_ASM_LINE_DEBUG_INFO 0
+#endif
+
 /* Define the architecture-dependent minimum instruction length (in bytes).
    In this implementation of DWARF, this field is used for information
    purposes only.  Since GCC generates assembly language, we have
@@ -2292,13 +2217,6 @@ static unsigned file_table_in_use;
    dwarf2out_init.  */
 static char *primary_filename;
 
-/* For Dwarf output, we must assign lexical-blocks id numbers in the order in
-   which their beginnings are encountered. We output Dwarf debugging info
-   that refers to the beginnings and ends of the ranges of code for each
-   lexical block.  The labels themselves are generated in final.c, which
-   assigns numbers to the blocks in the same way.  */
-static unsigned next_block_number = 2;
-
 /* A pointer to the base of a table of references to DIE's that describe
    declarations.  The table is indexed by DECL_UID() which is a unique
    number identifying each decl.  */
@@ -2314,23 +2232,12 @@ static unsigned decl_die_table_in_use;
    decl_die_table.  */
 #define DECL_DIE_TABLE_INCREMENT 256
 
-/* Structure used for the decl_scope table.  scope is the current declaration
-   scope, and previous is the entry that is the parent of this scope.  This
-   is usually but not always the immediately preceeding entry.  */
-
-typedef struct decl_scope_struct
-{
-  tree scope;
-  int previous;
-}
-decl_scope_node;
-
 /* A pointer to the base of a table of references to declaration
    scopes.  This table is a display which tracks the nesting
    of declaration scopes at the current scope and containing
    scopes.  This table is used to find the proper place to
    define type declaration DIE's.  */
-static decl_scope_node *decl_scope_table;
+static tree *decl_scope_table;
 
 /* Number of elements currently allocated for the decl_scope_table.  */
 static int decl_scope_table_allocated;
@@ -2409,23 +2316,6 @@ static unsigned arange_table_in_use;
    arange_table.  */
 #define ARANGE_TABLE_INCREMENT 64
 
-/* A pointer to the base of a list of pending types which we haven't
-   generated DIEs for yet, but which we will have to come back to
-   later on.  */
-
-static tree *pending_types_list;
-
-/* Number of elements currently allocated for the pending_types_list.  */
-static unsigned pending_types_allocated;
-
-/* Number of elements of pending_types_list currently in use.  */
-static unsigned pending_types;
-
-/* Size (in elements) of increments by which we may expand the pending
-   types list.  Actually, a single hunk of space of this size should
-   be enough for most typical programs.         */
-#define PENDING_TYPES_INCREMENT 64
-
 /* A pointer to the base of a list of incomplete types which might be
    completed at some later time.  */
 
@@ -2448,194 +2338,201 @@ static int current_function_has_inlines;
 static int comp_unit_has_inlines;
 #endif
 
-/* A pointer to the ..._DECL node which we have most recently been working
-   on.  We keep this around just in case something about it looks screwy and
-   we want to tell the user what the source coordinates for the actual
-   declaration are.  */
-static tree dwarf_last_decl;
+/* Array of RTXes referenced by the debugging information, which therefore
+   must be kept around forever.  We do this rather than perform GC on
+   the dwarf info because almost all of the dwarf info lives forever, and
+   it's easier to support non-GC frontends this way.  */
+static varray_type used_rtx_varray;
 
 /* Forward declarations for functions defined in this file.  */
 
-static void addr_const_to_string       PROTO((dyn_string_t, rtx));
-static char *addr_to_string            PROTO((rtx));
-static int is_pseudo_reg               PROTO((rtx));
-static tree type_main_variant          PROTO((tree));
-static int is_tagged_type              PROTO((tree));
-static char *dwarf_tag_name            PROTO((unsigned));
-static char *dwarf_attr_name           PROTO((unsigned));
-static char *dwarf_form_name           PROTO((unsigned));
-static char *dwarf_stack_op_name       PROTO((unsigned));
+static int is_pseudo_reg               PARAMS ((rtx));
+static tree type_main_variant          PARAMS ((tree));
+static int is_tagged_type              PARAMS ((tree));
+static const char *dwarf_tag_name      PARAMS ((unsigned));
+static const char *dwarf_attr_name     PARAMS ((unsigned));
+static const char *dwarf_form_name     PARAMS ((unsigned));
+static const char *dwarf_stack_op_name PARAMS ((unsigned));
 #if 0
-static char *dwarf_type_encoding_name  PROTO((unsigned));
+static const char *dwarf_type_encoding_name PARAMS ((unsigned));
 #endif
-static tree decl_ultimate_origin       PROTO((tree));
-static tree block_ultimate_origin      PROTO((tree));
-static tree decl_class_context         PROTO((tree));
-static void add_dwarf_attr             PROTO((dw_die_ref, dw_attr_ref));
-static void add_AT_flag                        PROTO((dw_die_ref,
-                                              enum dwarf_attribute,
-                                              unsigned));
-static void add_AT_int                 PROTO((dw_die_ref,
-                                              enum dwarf_attribute, long));
-static void add_AT_unsigned            PROTO((dw_die_ref,
-                                              enum dwarf_attribute,
-                                              unsigned long));
-static void add_AT_long_long           PROTO((dw_die_ref,
-                                              enum dwarf_attribute,
-                                              unsigned long, unsigned long));
-static void add_AT_float               PROTO((dw_die_ref,
-                                              enum dwarf_attribute,
-                                              unsigned, long *));
-static void add_AT_string              PROTO((dw_die_ref,
-                                              enum dwarf_attribute, char *));
-static void add_AT_die_ref             PROTO((dw_die_ref,
-                                              enum dwarf_attribute,
-                                              dw_die_ref));
-static void add_AT_fde_ref             PROTO((dw_die_ref,
-                                              enum dwarf_attribute,
-                                              unsigned));
-static void add_AT_loc                 PROTO((dw_die_ref,
-                                              enum dwarf_attribute,
-                                              dw_loc_descr_ref));
-static void add_AT_addr                        PROTO((dw_die_ref,
-                                              enum dwarf_attribute, char *));
-static void add_AT_lbl_id              PROTO((dw_die_ref,
-                                              enum dwarf_attribute, char *));
-static void add_AT_lbl_offset          PROTO((dw_die_ref,
-                                              enum dwarf_attribute, char *));
-static int is_extern_subr_die          PROTO((dw_die_ref));
-static dw_attr_ref get_AT              PROTO((dw_die_ref,
-                                              enum dwarf_attribute));
-static char *get_AT_low_pc             PROTO((dw_die_ref));
-static char *get_AT_hi_pc              PROTO((dw_die_ref));
-static char *get_AT_string             PROTO((dw_die_ref,
-                                              enum dwarf_attribute));
-static int get_AT_flag                 PROTO((dw_die_ref,
-                                              enum dwarf_attribute));
-static unsigned get_AT_unsigned                PROTO((dw_die_ref,
-                                              enum dwarf_attribute));
-static int is_c_family                 PROTO((void));
-static int is_fortran                  PROTO((void));
-static void remove_AT                  PROTO((dw_die_ref,
-                                              enum dwarf_attribute));
-static void remove_children            PROTO((dw_die_ref));
-static void add_child_die              PROTO((dw_die_ref, dw_die_ref));
-static dw_die_ref new_die              PROTO((enum dwarf_tag, dw_die_ref));
-static dw_die_ref lookup_type_die      PROTO((tree));
-static void equate_type_number_to_die  PROTO((tree, dw_die_ref));
-static dw_die_ref lookup_decl_die      PROTO((tree));
-static void equate_decl_number_to_die  PROTO((tree, dw_die_ref));
-static dw_loc_descr_ref new_loc_descr  PROTO((enum dwarf_location_atom,
-                                              unsigned long, unsigned long));
-static void add_loc_descr              PROTO((dw_loc_descr_ref *,
-                                              dw_loc_descr_ref));
-static void print_spaces               PROTO((FILE *));
-static void print_die                  PROTO((dw_die_ref, FILE *));
-static void print_dwarf_line_table     PROTO((FILE *));
-static void add_sibling_attributes     PROTO((dw_die_ref));
-static void build_abbrev_table         PROTO((dw_die_ref));
-static unsigned long size_of_string    PROTO((char *));
-static unsigned long size_of_loc_descr PROTO((dw_loc_descr_ref));
-static unsigned long size_of_locs      PROTO((dw_loc_descr_ref));
-static int constant_size               PROTO((long unsigned));
-static unsigned long size_of_die       PROTO((dw_die_ref));
-static void calc_die_sizes             PROTO((dw_die_ref));
-static unsigned long size_of_line_prolog       PROTO((void));
-static unsigned long size_of_line_info PROTO((void));
-static unsigned long size_of_pubnames  PROTO((void));
-static unsigned long size_of_aranges   PROTO((void));
-static enum dwarf_form value_format    PROTO((dw_val_ref));
-static void output_value_format                PROTO((dw_val_ref));
-static void output_abbrev_section      PROTO((void));
-static void output_loc_operands                PROTO((dw_loc_descr_ref));
-static unsigned long sibling_offset    PROTO((dw_die_ref));
-static void output_die                 PROTO((dw_die_ref));
-static void output_compilation_unit_header PROTO((void));
-static char *dwarf2_name               PROTO((tree, int));
-static void add_pubname                        PROTO((tree, dw_die_ref));
-static void output_pubnames            PROTO((void));
-static void add_arange                 PROTO((tree, dw_die_ref));
-static void output_aranges             PROTO((void));
-static void output_line_info           PROTO((void));
-static int is_body_block               PROTO((tree));
-static dw_die_ref base_type_die                PROTO((tree));
-static tree root_type                  PROTO((tree));
-static int is_base_type                        PROTO((tree));
-static dw_die_ref modified_type_die    PROTO((tree, int, int, dw_die_ref));
-static int type_is_enum                        PROTO((tree));
-static dw_loc_descr_ref reg_loc_descriptor PROTO((rtx));
-static dw_loc_descr_ref based_loc_descr        PROTO((unsigned, long));
-static int is_based_loc                        PROTO((rtx));
-static dw_loc_descr_ref mem_loc_descriptor PROTO((rtx));
-static dw_loc_descr_ref concat_loc_descriptor PROTO((rtx, rtx));
-static dw_loc_descr_ref loc_descriptor PROTO((rtx));
-static unsigned ceiling                        PROTO((unsigned, unsigned));
-static tree field_type                 PROTO((tree));
-static unsigned simple_type_align_in_bits PROTO((tree));
-static unsigned simple_type_size_in_bits PROTO((tree));
-static unsigned field_byte_offset              PROTO((tree));
-static void add_AT_location_description        PROTO((dw_die_ref,
-                                              enum dwarf_attribute, rtx));
-static void add_data_member_location_attribute PROTO((dw_die_ref, tree));
-static void add_const_value_attribute  PROTO((dw_die_ref, rtx));
-static void add_location_or_const_value_attribute PROTO((dw_die_ref, tree));
-static void add_name_attribute         PROTO((dw_die_ref, char *));
-static void add_bound_info             PROTO((dw_die_ref,
-                                              enum dwarf_attribute, tree));
-static void add_subscript_info         PROTO((dw_die_ref, tree));
-static void add_byte_size_attribute    PROTO((dw_die_ref, tree));
-static void add_bit_offset_attribute   PROTO((dw_die_ref, tree));
-static void add_bit_size_attribute     PROTO((dw_die_ref, tree));
-static void add_prototyped_attribute   PROTO((dw_die_ref, tree));
-static void add_abstract_origin_attribute PROTO((dw_die_ref, tree));
-static void add_pure_or_virtual_attribute PROTO((dw_die_ref, tree));
-static void add_src_coords_attributes  PROTO((dw_die_ref, tree));
-static void add_name_and_src_coords_attributes PROTO((dw_die_ref, tree));
-static void push_decl_scope            PROTO((tree));
-static dw_die_ref scope_die_for                PROTO((tree, dw_die_ref));
-static void pop_decl_scope             PROTO((void));
-static void add_type_attribute         PROTO((dw_die_ref, tree, int, int,
-                                              dw_die_ref));
-static char *type_tag                  PROTO((tree));
-static tree member_declared_type       PROTO((tree));
+static tree decl_ultimate_origin       PARAMS ((tree));
+static tree block_ultimate_origin      PARAMS ((tree));
+static tree decl_class_context         PARAMS ((tree));
+static void add_dwarf_attr             PARAMS ((dw_die_ref, dw_attr_ref));
+static void add_AT_flag                        PARAMS ((dw_die_ref,
+                                                enum dwarf_attribute,
+                                                unsigned));
+static void add_AT_int                 PARAMS ((dw_die_ref,
+                                                enum dwarf_attribute, long));
+static void add_AT_unsigned            PARAMS ((dw_die_ref,
+                                                enum dwarf_attribute,
+                                                unsigned long));
+static void add_AT_long_long           PARAMS ((dw_die_ref,
+                                                enum dwarf_attribute,
+                                                unsigned long,
+                                                unsigned long));
+static void add_AT_float               PARAMS ((dw_die_ref,
+                                                enum dwarf_attribute,
+                                                unsigned, long *));
+static void add_AT_string              PARAMS ((dw_die_ref,
+                                                enum dwarf_attribute,
+                                                const char *));
+static void add_AT_die_ref             PARAMS ((dw_die_ref,
+                                                enum dwarf_attribute,
+                                                dw_die_ref));
+static void add_AT_fde_ref             PARAMS ((dw_die_ref,
+                                                enum dwarf_attribute,
+                                                unsigned));
+static void add_AT_loc                 PARAMS ((dw_die_ref,
+                                                enum dwarf_attribute,
+                                                dw_loc_descr_ref));
+static void add_AT_addr                        PARAMS ((dw_die_ref,
+                                                enum dwarf_attribute,
+                                                rtx));
+static void add_AT_lbl_id              PARAMS ((dw_die_ref,
+                                                enum dwarf_attribute,
+                                                char *));
+static void add_AT_lbl_offset          PARAMS ((dw_die_ref,
+                                                enum dwarf_attribute,
+                                                char *));
+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 const char *get_AT_hi_pc                PARAMS ((dw_die_ref));
+static const char *get_AT_string       PARAMS ((dw_die_ref,
+                                                enum dwarf_attribute));
+static int get_AT_flag                 PARAMS ((dw_die_ref,
+                                                enum dwarf_attribute));
+static unsigned get_AT_unsigned                PARAMS ((dw_die_ref,
+                                                enum dwarf_attribute));
+static inline dw_die_ref get_AT_ref    PARAMS ((dw_die_ref,
+                                                enum dwarf_attribute));
+static int is_c_family                 PARAMS ((void));
+static int is_fortran                  PARAMS ((void));
+static void remove_AT                  PARAMS ((dw_die_ref,
+                                                enum dwarf_attribute));
+static void remove_children            PARAMS ((dw_die_ref));
+static void add_child_die              PARAMS ((dw_die_ref, dw_die_ref));
+static dw_die_ref new_die              PARAMS ((enum dwarf_tag, dw_die_ref));
+static dw_die_ref lookup_type_die      PARAMS ((tree));
+static void equate_type_number_to_die  PARAMS ((tree, dw_die_ref));
+static dw_die_ref lookup_decl_die      PARAMS ((tree));
+static void equate_decl_number_to_die  PARAMS ((tree, dw_die_ref));
+static dw_loc_descr_ref new_loc_descr  PARAMS ((enum dwarf_location_atom,
+                                                unsigned long,
+                                                unsigned long));
+static void add_loc_descr              PARAMS ((dw_loc_descr_ref *,
+                                                dw_loc_descr_ref));
+static void print_spaces               PARAMS ((FILE *));
+static void print_die                  PARAMS ((dw_die_ref, FILE *));
+static void print_dwarf_line_table     PARAMS ((FILE *));
+static void add_sibling_attributes     PARAMS ((dw_die_ref));
+static void build_abbrev_table         PARAMS ((dw_die_ref));
+static unsigned long size_of_string    PARAMS ((const char *));
+static unsigned long size_of_loc_descr PARAMS ((dw_loc_descr_ref));
+static unsigned long size_of_locs      PARAMS ((dw_loc_descr_ref));
+static int constant_size               PARAMS ((long unsigned));
+static unsigned long size_of_die       PARAMS ((dw_die_ref));
+static void calc_die_sizes             PARAMS ((dw_die_ref));
+static unsigned long size_of_line_prolog PARAMS ((void));
+static unsigned long size_of_pubnames  PARAMS ((void));
+static unsigned long size_of_aranges   PARAMS ((void));
+static enum dwarf_form value_format    PARAMS ((dw_attr_ref));
+static void output_value_format                PARAMS ((dw_attr_ref));
+static void output_abbrev_section      PARAMS ((void));
+static void output_loc_operands                PARAMS ((dw_loc_descr_ref));
+static void output_die                 PARAMS ((dw_die_ref));
+static void output_compilation_unit_header PARAMS ((void));
+static const char *dwarf2_name         PARAMS ((tree, int));
+static void add_pubname                        PARAMS ((tree, dw_die_ref));
+static void output_pubnames            PARAMS ((void));
+static void add_arange                 PARAMS ((tree, dw_die_ref));
+static void output_aranges             PARAMS ((void));
+static void output_line_info           PARAMS ((void));
+static dw_die_ref base_type_die                PARAMS ((tree));
+static tree root_type                  PARAMS ((tree));
+static int is_base_type                        PARAMS ((tree));
+static dw_die_ref modified_type_die    PARAMS ((tree, int, int, dw_die_ref));
+static int type_is_enum                        PARAMS ((tree));
+static dw_loc_descr_ref reg_loc_descriptor PARAMS ((rtx));
+static dw_loc_descr_ref based_loc_descr        PARAMS ((unsigned, long));
+static int is_based_loc                        PARAMS ((rtx));
+static dw_loc_descr_ref mem_loc_descriptor PARAMS ((rtx, enum machine_mode mode));
+static dw_loc_descr_ref concat_loc_descriptor PARAMS ((rtx, rtx));
+static dw_loc_descr_ref loc_descriptor PARAMS ((rtx));
+static HOST_WIDE_INT ceiling           PARAMS ((HOST_WIDE_INT, unsigned int));
+static tree field_type                 PARAMS ((tree));
+static unsigned int simple_type_align_in_bits PARAMS ((tree));
+static unsigned HOST_WIDE_INT simple_type_size_in_bits PARAMS ((tree));
+static HOST_WIDE_INT field_byte_offset PARAMS ((tree));
+static void add_AT_location_description        PARAMS ((dw_die_ref,
+                                                enum dwarf_attribute, rtx));
+static void add_data_member_location_attribute PARAMS ((dw_die_ref, tree));
+static void add_const_value_attribute  PARAMS ((dw_die_ref, rtx));
+static void add_location_or_const_value_attribute PARAMS ((dw_die_ref, tree));
+static void add_name_attribute         PARAMS ((dw_die_ref, const char *));
+static void add_bound_info             PARAMS ((dw_die_ref,
+                                                enum dwarf_attribute, tree));
+static void add_subscript_info         PARAMS ((dw_die_ref, tree));
+static void add_byte_size_attribute    PARAMS ((dw_die_ref, tree));
+static void add_bit_offset_attribute   PARAMS ((dw_die_ref, tree));
+static void add_bit_size_attribute     PARAMS ((dw_die_ref, tree));
+static void add_prototyped_attribute   PARAMS ((dw_die_ref, tree));
+static void add_abstract_origin_attribute PARAMS ((dw_die_ref, tree));
+static void add_pure_or_virtual_attribute PARAMS ((dw_die_ref, tree));
+static void add_src_coords_attributes  PARAMS ((dw_die_ref, tree));
+static void add_name_and_src_coords_attributes PARAMS ((dw_die_ref, tree));
+static void push_decl_scope            PARAMS ((tree));
+static dw_die_ref scope_die_for                PARAMS ((tree, dw_die_ref));
+static void pop_decl_scope             PARAMS ((void));
+static void add_type_attribute         PARAMS ((dw_die_ref, tree, int, int,
+                                                dw_die_ref));
+static char *type_tag                  PARAMS ((tree));
+static tree member_declared_type       PARAMS ((tree));
 #if 0
-static char *decl_start_label          PROTO((tree));
+static char *decl_start_label          PARAMS ((tree));
 #endif
-static void gen_array_type_die         PROTO((tree, dw_die_ref));
-static void gen_set_type_die           PROTO((tree, dw_die_ref));
+static void gen_array_type_die         PARAMS ((tree, dw_die_ref));
+static void gen_set_type_die           PARAMS ((tree, dw_die_ref));
 #if 0
-static void gen_entry_point_die                PROTO((tree, dw_die_ref));
+static void gen_entry_point_die                PARAMS ((tree, dw_die_ref));
 #endif
-static void pend_type                  PROTO((tree));
-static void output_pending_types_for_scope PROTO((dw_die_ref));
-static void gen_inlined_enumeration_type_die PROTO((tree, dw_die_ref));
-static void gen_inlined_structure_type_die PROTO((tree, dw_die_ref));
-static void gen_inlined_union_type_die PROTO((tree, dw_die_ref));
-static void gen_enumeration_type_die   PROTO((tree, dw_die_ref));
-static dw_die_ref gen_formal_parameter_die PROTO((tree, dw_die_ref));
-static void gen_unspecified_parameters_die PROTO((tree, dw_die_ref));
-static void gen_formal_types_die       PROTO((tree, dw_die_ref));
-static void gen_subprogram_die         PROTO((tree, dw_die_ref));
-static void gen_variable_die           PROTO((tree, dw_die_ref));
-static void gen_label_die              PROTO((tree, dw_die_ref));
-static void gen_lexical_block_die      PROTO((tree, dw_die_ref, int));
-static void gen_inlined_subroutine_die PROTO((tree, dw_die_ref, int));
-static void gen_field_die              PROTO((tree, dw_die_ref));
-static void gen_ptr_to_mbr_type_die    PROTO((tree, dw_die_ref));
-static void gen_compile_unit_die       PROTO((char *));
-static void gen_string_type_die                PROTO((tree, dw_die_ref));
-static void gen_inheritance_die                PROTO((tree, dw_die_ref));
-static void gen_member_die             PROTO((tree, dw_die_ref));
-static void gen_struct_or_union_type_die PROTO((tree, dw_die_ref));
-static void gen_subroutine_type_die    PROTO((tree, dw_die_ref));
-static void gen_typedef_die            PROTO((tree, dw_die_ref));
-static void gen_type_die               PROTO((tree, dw_die_ref));
-static void gen_tagged_type_instantiation_die PROTO((tree, dw_die_ref));
-static void gen_block_die              PROTO((tree, dw_die_ref, int));
-static void decls_for_scope            PROTO((tree, dw_die_ref, int));
-static int is_redundant_typedef                PROTO((tree));
-static void gen_decl_die               PROTO((tree, dw_die_ref));
-static unsigned lookup_filename                PROTO((char *));
+static void gen_inlined_enumeration_type_die PARAMS ((tree, dw_die_ref));
+static void gen_inlined_structure_type_die PARAMS ((tree, dw_die_ref));
+static void gen_inlined_union_type_die PARAMS ((tree, dw_die_ref));
+static void gen_enumeration_type_die   PARAMS ((tree, dw_die_ref));
+static dw_die_ref gen_formal_parameter_die PARAMS ((tree, dw_die_ref));
+static void gen_unspecified_parameters_die PARAMS ((tree, dw_die_ref));
+static void gen_formal_types_die       PARAMS ((tree, dw_die_ref));
+static void gen_subprogram_die         PARAMS ((tree, dw_die_ref));
+static void gen_variable_die           PARAMS ((tree, dw_die_ref));
+static void gen_label_die              PARAMS ((tree, dw_die_ref));
+static void gen_lexical_block_die      PARAMS ((tree, dw_die_ref, int));
+static void gen_inlined_subroutine_die PARAMS ((tree, dw_die_ref, int));
+static void gen_field_die              PARAMS ((tree, dw_die_ref));
+static void gen_ptr_to_mbr_type_die    PARAMS ((tree, dw_die_ref));
+static dw_die_ref gen_compile_unit_die PARAMS ((const char *));
+static void gen_string_type_die                PARAMS ((tree, dw_die_ref));
+static void gen_inheritance_die                PARAMS ((tree, dw_die_ref));
+static void gen_member_die             PARAMS ((tree, dw_die_ref));
+static void gen_struct_or_union_type_die PARAMS ((tree, dw_die_ref));
+static void gen_subroutine_type_die    PARAMS ((tree, dw_die_ref));
+static void gen_typedef_die            PARAMS ((tree, dw_die_ref));
+static void gen_type_die               PARAMS ((tree, dw_die_ref));
+static void gen_tagged_type_instantiation_die PARAMS ((tree, dw_die_ref));
+static void gen_block_die              PARAMS ((tree, dw_die_ref, int));
+static void decls_for_scope            PARAMS ((tree, dw_die_ref, int));
+static int is_redundant_typedef                PARAMS ((tree));
+static void gen_decl_die               PARAMS ((tree, dw_die_ref));
+static unsigned lookup_filename                PARAMS ((const char *));
+static void add_incomplete_type                PARAMS ((tree));
+static void retry_incomplete_types     PARAMS ((void));
+static void gen_type_die_for_member    PARAMS ((tree, tree, dw_die_ref));
+static void gen_abstract_function      PARAMS ((tree));
+static rtx save_rtx                    PARAMS ((rtx));
+static void splice_child_die           PARAMS ((dw_die_ref, dw_die_ref));
+static void reverse_die_lists          PARAMS ((dw_die_ref));
 
 /* Section names used to hold DWARF debugging information.  */
 #ifndef DEBUG_INFO_SECTION
@@ -2733,161 +2630,38 @@ static char debug_line_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
 #ifndef SEPARATE_LINE_CODE_LABEL
 #define SEPARATE_LINE_CODE_LABEL       "LSM"
 #endif
-
-/* Convert a reference to the assembler name of a C-level name.  This
-   macro has the same effect as ASM_OUTPUT_LABELREF, but copies to
-   a string rather than writing to a file.  */
-#ifndef ASM_NAME_TO_STRING
-#define ASM_NAME_TO_STRING(STR, NAME)                  \
-  do {                                                 \
-      if ((NAME)[0] == '*')                            \
-       dyn_string_append (STR, NAME + 1);              \
-      else                                             \
-       {                                               \
-         char *newstr;                                 \
-         STRIP_NAME_ENCODING (newstr, NAME);           \
-         dyn_string_append (STR, user_label_prefix);   \
-         dyn_string_append (STR, newstr);              \
-       }                                               \
-  }                                                    \
-  while (0)
-#endif
 \f
-/* Convert an integer constant expression into assembler syntax.  Addition
-   and subtraction are the only arithmetic that may appear in these
-   expressions.   This is an adaptation of output_addr_const in final.c.
-   Here, the target of the conversion is a string buffer.  We can't use
-   output_addr_const directly, because it writes to a file.  */
-
-static void
-addr_const_to_string (str, x)
-     dyn_string_t str;
-     rtx x;
-{
-  char buf1[256];
-
-restart:
-  switch (GET_CODE (x))
-    {
-    case PC:
-      if (flag_pic)
-       dyn_string_append (str, ",");
-      else
-       abort ();
-      break;
-
-    case SYMBOL_REF:
-      ASM_NAME_TO_STRING (str, XSTR (x, 0));
-      break;
-
-    case LABEL_REF:
-      ASM_GENERATE_INTERNAL_LABEL (buf1, "L", CODE_LABEL_NUMBER (XEXP (x, 0)));
-      ASM_NAME_TO_STRING (str, buf1);
-      break;
-
-    case CODE_LABEL:
-      ASM_GENERATE_INTERNAL_LABEL (buf1, "L", CODE_LABEL_NUMBER (x));
-      ASM_NAME_TO_STRING (str, buf1);
-      break;
-
-    case CONST_INT:
-      sprintf (buf1, HOST_WIDE_INT_PRINT_DEC, INTVAL (x));
-      dyn_string_append (str, buf1);
-      break;
-
-    case CONST:
-      /* This used to output parentheses around the expression, but that does 
-         not work on the 386 (either ATT or BSD assembler).  */
-      addr_const_to_string (str, XEXP (x, 0));
-      break;
-
-    case CONST_DOUBLE:
-      if (GET_MODE (x) == VOIDmode)
-       {
-         /* We can use %d if the number is one word and positive.  */
-         if (CONST_DOUBLE_HIGH (x))
-           sprintf (buf1, HOST_WIDE_INT_PRINT_DOUBLE_HEX,
-                    CONST_DOUBLE_HIGH (x), CONST_DOUBLE_LOW (x));
-         else if (CONST_DOUBLE_LOW (x) < 0)
-           sprintf (buf1, HOST_WIDE_INT_PRINT_HEX, CONST_DOUBLE_LOW (x));
-         else
-           sprintf (buf1, HOST_WIDE_INT_PRINT_DEC,
-                    CONST_DOUBLE_LOW (x));
-         dyn_string_append (str, buf1);
-       }
-      else
-       /* We can't handle floating point constants; PRINT_OPERAND must
-          handle them.  */
-       output_operand_lossage ("floating constant misused");
-      break;
+/* We allow a language front-end to designate a function that is to be
+   called to "demangle" any name before it it put into a DIE.  */
 
-    case PLUS:
-      /* Some assemblers need integer constants to appear last (eg masm).  */
-      if (GET_CODE (XEXP (x, 0)) == CONST_INT)
-       {
-         addr_const_to_string (str, XEXP (x, 1));
-         if (INTVAL (XEXP (x, 0)) >= 0)
-           dyn_string_append (str, "+");
-
-         addr_const_to_string (str, XEXP (x, 0));
-       }
-      else
-       {
-         addr_const_to_string (str, XEXP (x, 0));
-         if (INTVAL (XEXP (x, 1)) >= 0)
-           dyn_string_append (str, "+");
-
-         addr_const_to_string (str, XEXP (x, 1));
-       }
-      break;
-
-    case MINUS:
-      /* Avoid outputting things like x-x or x+5-x, since some assemblers
-         can't handle that.  */
-      x = simplify_subtraction (x);
-      if (GET_CODE (x) != MINUS)
-       goto restart;
-
-      addr_const_to_string (str, XEXP (x, 0));
-      dyn_string_append (str, "-");
-      if (GET_CODE (XEXP (x, 1)) == CONST_INT
-         && INTVAL (XEXP (x, 1)) < 0)
-       {
-         dyn_string_append (str, ASM_OPEN_PAREN);
-         addr_const_to_string (str, XEXP (x, 1));
-         dyn_string_append (str, ASM_CLOSE_PAREN);
-       }
-      else
-       addr_const_to_string (str, XEXP (x, 1));
-      break;
-
-    case ZERO_EXTEND:
-    case SIGN_EXTEND:
-      addr_const_to_string (str, XEXP (x, 0));
-      break;
+static const char *(*demangle_name_func) PARAMS ((const char *));
 
-    default:
-      output_operand_lossage ("invalid expression as operand");
-    }
+void
+dwarf2out_set_demangle_name_func (func)
+     const char *(*func) PARAMS ((const char *));
+{
+  demangle_name_func = func;
 }
+\f
+/* Return an rtx like ORIG which lives forever.  If we're doing GC,
+   that means adding it to used_rtx_varray.  If not, that means making
+   a copy on the permanent_obstack.  */
 
-/* Convert an address constant to a string, and return a pointer to
-   a copy of the result, located on the heap.  */
-
-static char *
-addr_to_string (x)
-     rtx x;
+static rtx
+save_rtx (orig)
+     register rtx orig;
 {
-  dyn_string_t ds = dyn_string_new (256);
-  char *s;
+  if (ggc_p)
+    VARRAY_PUSH_RTX (used_rtx_varray, orig);
+  else
+    {
+      push_obstacks_nochange ();
+      end_temporary_allocation ();
+      orig = copy_rtx (orig);
+      pop_obstacks ();
+    }
 
-  addr_const_to_string (ds, x);
-  
-  /* Return the dynamically allocated string, but free the
-     dyn_string_t itself.  */
-  s = ds->s;
-  free (ds);
-  return s;
+  return orig;
 }
 
 /* Test if rtl node points to a pseudo register.  */
@@ -2896,9 +2670,9 @@ static inline int
 is_pseudo_reg (rtl)
      register rtx rtl;
 {
-  return (((GET_CODE (rtl) == REG) && (REGNO (rtl) >= FIRST_PSEUDO_REGISTER))
-         || ((GET_CODE (rtl) == SUBREG)
-             && (REGNO (XEXP (rtl, 0)) >= FIRST_PSEUDO_REGISTER)));
+  return ((GET_CODE (rtl) == REG && REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
+         || (GET_CODE (rtl) == SUBREG
+             && REGNO (XEXP (rtl, 0)) >= FIRST_PSEUDO_REGISTER));
 }
 
 /* Return a reference to a type, with its const and volatile qualifiers
@@ -2936,7 +2710,7 @@ is_tagged_type (type)
 
 /* Convert a DIE tag into its string name.  */
 
-static char *
+static const char *
 dwarf_tag_name (tag)
      register unsigned tag;
 {
@@ -3053,7 +2827,7 @@ dwarf_tag_name (tag)
 
 /* Convert a DWARF attribute code into its string name.  */
 
-static char *
+static const char *
 dwarf_attr_name (attr)
      register unsigned attr;
 {
@@ -3226,7 +3000,7 @@ dwarf_attr_name (attr)
 
 /* Convert a DWARF value form code into its string name.  */
 
-static char *
+static const char *
 dwarf_form_name (form)
      register unsigned form;
 {
@@ -3281,7 +3055,7 @@ dwarf_form_name (form)
 
 /* Convert a DWARF stack opcode into its string name.  */
 
-static char *
+static const char *
 dwarf_stack_op_name (op)
      register unsigned op;
 {
@@ -3585,7 +3359,7 @@ dwarf_stack_op_name (op)
 /* Convert a DWARF type code into its string name.  */
 
 #if 0
-static char *
+static const char *
 dwarf_type_encoding_name (enc)
      register unsigned enc;
 {
@@ -3623,6 +3397,12 @@ static tree
 decl_ultimate_origin (decl)
      register tree decl;
 {
+  /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
+     nodes in the function to point to themselves; ignore that if
+     we're trying to output the abstract instance of this function.  */
+  if (DECL_ABSTRACT (decl) && DECL_ABSTRACT_ORIGIN (decl) == decl)
+    return NULL_TREE;
+
 #ifdef ENABLE_CHECKING 
   if (DECL_FROM_INLINE (DECL_ORIGIN (decl)))
     /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
@@ -3645,6 +3425,12 @@ block_ultimate_origin (block)
 {
   register tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block);
 
+  /* output_inline_function sets BLOCK_ABSTRACT_ORIGIN for all the
+     nodes in the function to point to themselves; ignore that if
+     we're trying to output the abstract instance of this function.  */
+  if (BLOCK_ABSTRACT (block) && immediate_origin == block)
+    return NULL_TREE;
+
   if (immediate_origin == NULL_TREE)
     return NULL_TREE;
   else
@@ -3681,13 +3467,14 @@ decl_class_context (decl)
     context = TYPE_MAIN_VARIANT
       (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
 
-  if (context && TREE_CODE_CLASS (TREE_CODE (context)) != 't')
+  if (context && !TYPE_P (context))
     context = NULL_TREE;
 
   return context;
 }
 \f
-/* Add an attribute/value pair to a DIE */
+/* Add an attribute/value pair to a DIE.  We build the lists up in reverse
+   addition order, and correct that in add_sibling_attributes.  */
 
 static inline void
 add_dwarf_attr (die, attr)
@@ -3696,19 +3483,19 @@ add_dwarf_attr (die, attr)
 {
   if (die != NULL && attr != NULL)
     {
-      if (die->die_attr == NULL)
-       {
-         die->die_attr = attr;
-         die->die_attr_last = attr;
-       }
-      else
-       {
-         die->die_attr_last->dw_attr_next = attr;
-         die->die_attr_last = attr;
-       }
+      attr->dw_attr_next = die->die_attr;
+      die->die_attr = attr;
     }
 }
 
+static inline dw_val_class AT_class PARAMS ((dw_attr_ref));
+static inline dw_val_class
+AT_class (a)
+     dw_attr_ref a;
+{
+  return a->dw_attr_val.val_class;
+}
+
 /* Add a flag value attribute to a DIE.  */
 
 static inline void
@@ -3726,6 +3513,17 @@ add_AT_flag (die, attr_kind, flag)
   add_dwarf_attr (die, attr);
 }
 
+static inline unsigned AT_flag PARAMS ((dw_attr_ref));
+static inline unsigned
+AT_flag (a)
+     register dw_attr_ref a;
+{
+  if (a && AT_class (a) == dw_val_class_flag)
+    return a->dw_attr_val.v.val_flag;
+
+  return 0;
+}
+
 /* Add a signed integer attribute value to a DIE.  */
 
 static inline void
@@ -3743,6 +3541,17 @@ add_AT_int (die, attr_kind, int_val)
   add_dwarf_attr (die, attr);
 }
 
+static inline long int AT_int PARAMS ((dw_attr_ref));
+static inline long int
+AT_int (a)
+     register dw_attr_ref a;
+{
+  if (a && AT_class (a) == dw_val_class_const)
+    return a->dw_attr_val.v.val_int;
+
+  return 0;
+}
+
 /* Add an unsigned integer attribute value to a DIE.  */
 
 static inline void
@@ -3760,6 +3569,17 @@ add_AT_unsigned (die, attr_kind, unsigned_val)
   add_dwarf_attr (die, attr);
 }
 
+static inline unsigned long AT_unsigned PARAMS ((dw_attr_ref));
+static inline unsigned long
+AT_unsigned (a)
+     register dw_attr_ref a;
+{
+  if (a && AT_class (a) == dw_val_class_unsigned_const)
+    return a->dw_attr_val.v.val_unsigned;
+
+  return 0;
+}
+
 /* Add an unsigned double integer attribute value to a DIE.  */
 
 static inline void
@@ -3804,7 +3624,7 @@ static inline void
 add_AT_string (die, attr_kind, str)
      register dw_die_ref die;
      register enum dwarf_attribute attr_kind;
-     register char *str;
+     register const char *str;
 {
   register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
 
@@ -3815,6 +3635,17 @@ add_AT_string (die, attr_kind, str)
   add_dwarf_attr (die, attr);
 }
 
+static inline const char *AT_string PARAMS ((dw_attr_ref));
+static inline const char *
+AT_string (a)
+     register dw_attr_ref a;
+{
+  if (a && AT_class (a) == dw_val_class_str)
+    return a->dw_attr_val.v.val_str;
+
+  return NULL;
+}
+
 /* Add a DIE reference attribute value to a DIE.  */
 
 static inline void
@@ -3832,6 +3663,17 @@ add_AT_die_ref (die, attr_kind, targ_die)
   add_dwarf_attr (die, attr);
 }
 
+static inline dw_die_ref AT_ref PARAMS ((dw_attr_ref));
+static inline dw_die_ref
+AT_ref (a)
+     register dw_attr_ref a;
+{
+  if (a && AT_class (a) == dw_val_class_die_ref)
+    return a->dw_attr_val.v.val_die_ref;
+
+  return NULL;
+}
+
 /* Add an FDE reference attribute value to a DIE.  */
 
 static inline void
@@ -3866,13 +3708,24 @@ add_AT_loc (die, attr_kind, loc)
   add_dwarf_attr (die, attr);
 }
 
+static inline dw_loc_descr_ref AT_loc PARAMS ((dw_attr_ref));
+static inline dw_loc_descr_ref
+AT_loc (a)
+     register dw_attr_ref a;
+{
+  if (a && AT_class (a) == dw_val_class_loc)
+    return a->dw_attr_val.v.val_loc;
+
+  return NULL;
+}
+
 /* Add an address constant attribute value to a DIE.  */
 
 static inline void
 add_AT_addr (die, attr_kind, addr)
      register dw_die_ref die;
      register enum dwarf_attribute attr_kind;
-     char *addr;
+     rtx addr;
 {
   register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
 
@@ -3883,6 +3736,17 @@ add_AT_addr (die, attr_kind, addr)
   add_dwarf_attr (die, attr);
 }
 
+static inline rtx AT_addr PARAMS ((dw_attr_ref));
+static inline rtx
+AT_addr (a)
+     register dw_attr_ref a;
+{
+  if (a && AT_class (a) == dw_val_class_addr)
+    return a->dw_attr_val.v.val_addr;
+
+  return NULL;
+}
+
 /* Add a label identifier attribute value to a DIE.  */
 
 static inline void
@@ -3913,37 +3777,21 @@ add_AT_lbl_offset (die, attr_kind, label)
   attr->dw_attr_next = NULL;
   attr->dw_attr = attr_kind;
   attr->dw_attr_val.val_class = dw_val_class_lbl_offset;
-  attr->dw_attr_val.v.val_lbl_id = label;
+  attr->dw_attr_val.v.val_lbl_id = xstrdup (label);
   add_dwarf_attr (die, attr);
   
 }
 
-/* Test if die refers to an external subroutine.  */
-
-static inline int
-is_extern_subr_die (die)
-     register dw_die_ref die;
+static inline const char *AT_lbl PARAMS ((dw_attr_ref));
+static inline const char *
+AT_lbl (a)
+     register dw_attr_ref a;
 {
-  register dw_attr_ref a;
-  register int is_subr = FALSE;
-  register int is_extern = FALSE;
-
-  if (die != NULL && die->die_tag == DW_TAG_subprogram)
-    {
-      is_subr = TRUE;
-      for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
-       {
-         if (a->dw_attr == DW_AT_external
-             && a->dw_attr_val.val_class == dw_val_class_flag
-             && a->dw_attr_val.v.val_flag != 0)
-           {
-             is_extern = TRUE;
-             break;
-           }
-       }
-    }
+  if (a && (AT_class (a) == dw_val_class_lbl_id
+           || AT_class (a) == dw_val_class_lbl_offset))
+    return a->dw_attr_val.v.val_lbl_id;
 
-  return is_subr && is_extern;
+  return NULL;
 }
 
 /* Get the attribute of type attr_kind.  */
@@ -3965,7 +3813,7 @@ get_AT (die, attr_kind)
 
          if (a->dw_attr == DW_AT_specification
              || a->dw_attr == DW_AT_abstract_origin)
-           spec = a->dw_attr_val.v.val_die_ref;
+           spec = AT_ref (a);
        }
 
       if (spec)
@@ -3980,16 +3828,12 @@ get_AT (die, attr_kind)
    either not prsent, or if it cannot be represented as an
    assembler label identifier.  */
 
-static inline char *
+static inline const char *
 get_AT_low_pc (die)
      register dw_die_ref die;
 {
   register dw_attr_ref a = get_AT (die, DW_AT_low_pc);
-
-  if (a && a->dw_attr_val.val_class == dw_val_class_lbl_id)
-    return a->dw_attr_val.v.val_lbl_id;
-
-  return NULL;
+  return AT_lbl (a);
 }
 
 /* Return the "high pc" attribute value, typically associated with
@@ -3997,32 +3841,24 @@ get_AT_low_pc (die)
    either not prsent, or if it cannot be represented as an
    assembler label identifier.  */
 
-static inline char *
+static inline const char *
 get_AT_hi_pc (die)
      register dw_die_ref die;
 {
   register dw_attr_ref a = get_AT (die, DW_AT_high_pc);
-
-  if (a && a->dw_attr_val.val_class == dw_val_class_lbl_id)
-    return a->dw_attr_val.v.val_lbl_id;
-
-  return NULL;
+  return AT_lbl (a);
 }
 
 /* Return the value of the string attribute designated by ATTR_KIND, or
    NULL if it is not present.  */
 
-static inline char *
+static inline const char *
 get_AT_string (die, attr_kind)
      register dw_die_ref die;
      register enum dwarf_attribute attr_kind;
 {
   register dw_attr_ref a = get_AT (die, attr_kind);
-
-  if (a && a->dw_attr_val.val_class == dw_val_class_str)
-    return a->dw_attr_val.v.val_str;
-
-  return NULL;
+  return AT_string (a);
 }
 
 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
@@ -4034,11 +3870,7 @@ get_AT_flag (die, attr_kind)
      register enum dwarf_attribute attr_kind;
 {
   register dw_attr_ref a = get_AT (die, attr_kind);
-
-  if (a && a->dw_attr_val.val_class == dw_val_class_flag)
-    return a->dw_attr_val.v.val_flag;
-
-  return -1;
+  return AT_flag (a);
 }
 
 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
@@ -4050,11 +3882,16 @@ get_AT_unsigned (die, attr_kind)
      register enum dwarf_attribute attr_kind;
 {
   register dw_attr_ref a = get_AT (die, attr_kind);
+  return AT_unsigned (a);
+}
 
-  if (a && a->dw_attr_val.val_class == dw_val_class_unsigned_const)
-    return a->dw_attr_val.v.val_unsigned;
-
-  return 0;
+static inline dw_die_ref
+get_AT_ref (die, attr_kind)
+     dw_die_ref die;
+     register enum dwarf_attribute attr_kind;
+{
+  register dw_attr_ref a = get_AT (die, attr_kind);
+  return AT_ref (a);
 }
 
 static inline int
@@ -4074,55 +3911,73 @@ is_fortran ()
   return (lang == DW_LANG_Fortran77 || lang == DW_LANG_Fortran90);
 } 
 
-/* Remove the specified attribute if present.  */
+/* Free up the memory used by A.  */
 
+static inline void free_AT PARAMS ((dw_attr_ref));
 static inline void
-remove_AT (die, attr_kind)
-     register dw_die_ref die;
-     register enum dwarf_attribute attr_kind;
+free_AT (a)
+     dw_attr_ref a;
 {
-  register dw_attr_ref a;
-  register dw_attr_ref removed = NULL;;
-
-  if (die != NULL)
+  switch (AT_class (a))
     {
-      if (die->die_attr->dw_attr == attr_kind)
-       {
-         removed = die->die_attr;
-         if (die->die_attr_last == die->die_attr)
-           die->die_attr_last = NULL;
-
-         die->die_attr = die->die_attr->dw_attr_next;
-       }
+    case dw_val_class_str:
+    case dw_val_class_lbl_id:
+    case dw_val_class_lbl_offset:
+      free (a->dw_attr_val.v.val_str);
+      break;
 
-      else
-       for (a = die->die_attr; a->dw_attr_next != NULL;
-            a = a->dw_attr_next)
-         if (a->dw_attr_next->dw_attr == attr_kind)
-           {
-             removed = a->dw_attr_next;
-             if (die->die_attr_last == a->dw_attr_next)
-               die->die_attr_last = a;
+    default:
+      break;
+    }
 
-             a->dw_attr_next = a->dw_attr_next->dw_attr_next;
-             break;
-           }
+  free (a);
+}  
+
+/* Remove the specified attribute if present.  */
+
+static void
+remove_AT (die, attr_kind)
+     register dw_die_ref die;
+     register enum dwarf_attribute attr_kind;
+{
+  register dw_attr_ref *p;
+  register dw_attr_ref removed = NULL;
+
+  if (die != NULL)
+    {
+      for (p = &(die->die_attr); *p; p = &((*p)->dw_attr_next))
+       if ((*p)->dw_attr == attr_kind)
+         {
+           removed = *p;
+           *p = (*p)->dw_attr_next;
+           break;
+         }
 
       if (removed != 0)
-       free (removed);
+       free_AT (removed);
     }
 }
 
-/* Discard the children of this DIE.  */
+/* Free up the memory used by DIE.  */
 
+static inline void free_die PARAMS ((dw_die_ref));
 static inline void
+free_die (die)
+     dw_die_ref die;
+{
+  remove_children (die);
+  free (die);
+}
+
+/* Discard the children of this DIE.  */
+
+static void
 remove_children (die)
      register dw_die_ref die;
 {
   register dw_die_ref child_die = die->die_child;
 
   die->die_child = NULL;
-  die->die_child_last = NULL;
 
   while (child_die != NULL)
     {
@@ -4136,14 +3991,15 @@ remove_children (die)
          register dw_attr_ref tmp_a = a;
 
          a = a->dw_attr_next;
-         free (tmp_a);
+         free_AT (tmp_a);
        }
 
-      free (tmp_die);
+      free_die (tmp_die);
     }
 }
 
-/* Add a child DIE below its parent.  */
+/* Add a child DIE below its parent.  We build the lists up in reverse
+   addition order, and correct that in add_sibling_attributes.  */
 
 static inline void
 add_child_die (die, child_die)
@@ -4155,19 +4011,42 @@ add_child_die (die, child_die)
       if (die == child_die)
        abort ();
       child_die->die_parent = die;
-      child_die->die_sib = NULL;
+      child_die->die_sib = die->die_child;
+      die->die_child = child_die;
+    }
+}
 
-      if (die->die_child == NULL)
-       {
-         die->die_child = child_die;
-         die->die_child_last = child_die;
-       }
-      else
-       {
-         die->die_child_last->die_sib = child_die;
-         die->die_child_last = child_die;
-       }
+/* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
+   is the specification, to the front of PARENT's list of children.  */
+
+static void
+splice_child_die (parent, child)
+     dw_die_ref parent, child;
+{
+  dw_die_ref *p;
+
+  /* We want the declaration DIE from inside the class, not the
+     specification DIE at toplevel.  */
+  if (child->die_parent != parent)
+    {
+      dw_die_ref tmp = get_AT_ref (child, DW_AT_specification);
+      if (tmp)
+       child = tmp;
     }
+
+  if (child->die_parent != parent
+      && child->die_parent != get_AT_ref (parent, DW_AT_specification))
+    abort ();
+
+  for (p = &(parent->die_child); *p; p = &((*p)->die_sib))
+    if (*p == child)
+      {
+       *p = child->die_sib;
+       break;
+      }
+
+  child->die_sib = parent->die_child;
+  parent->die_child = child;
 }
 
 /* Return a pointer to a newly created DIE node.  */
@@ -4185,9 +4064,7 @@ new_die (tag_value, parent_die)
   die->die_child = NULL;
   die->die_parent = NULL;
   die->die_sib = NULL;
-  die->die_child_last = NULL;
   die->die_attr = NULL;
-  die->die_attr_last = NULL;
 
   if (parent_die != NULL)
     add_child_die (parent_die, die);
@@ -4215,7 +4092,7 @@ lookup_type_die (type)
 
 /* Equate a DIE to a given type specifier.  */
 
-static void
+static inline void
 equate_type_number_to_die (type, type_die)
      register tree type;
      register dw_die_ref type_die;
@@ -4343,7 +4220,7 @@ print_die (die, outfile)
       print_spaces (outfile);
       fprintf (outfile, "  %s: ", dwarf_attr_name (a->dw_attr));
 
-      switch (a->dw_attr_val.val_class)
+      switch (AT_class (a))
        {
        case dw_val_class_addr:
          fprintf (outfile, "address");
@@ -4352,10 +4229,10 @@ print_die (die, outfile)
          fprintf (outfile, "location descriptor");
          break;
        case dw_val_class_const:
-         fprintf (outfile, "%ld", a->dw_attr_val.v.val_int);
+         fprintf (outfile, "%ld", AT_int (a));
          break;
        case dw_val_class_unsigned_const:
-         fprintf (outfile, "%lu", a->dw_attr_val.v.val_unsigned);
+         fprintf (outfile, "%lu", AT_unsigned (a));
          break;
        case dw_val_class_long_long:
          fprintf (outfile, "constant (%lu,%lu)",
@@ -4366,22 +4243,21 @@ print_die (die, outfile)
          fprintf (outfile, "floating-point constant");
          break;
        case dw_val_class_flag:
-         fprintf (outfile, "%u", a->dw_attr_val.v.val_flag);
+         fprintf (outfile, "%u", AT_flag (a));
          break;
        case dw_val_class_die_ref:
-         if (a->dw_attr_val.v.val_die_ref != NULL)
-           fprintf (outfile, "die -> %lu",
-                    a->dw_attr_val.v.val_die_ref->die_offset);
+         if (AT_ref (a) != NULL)
+           fprintf (outfile, "die -> %lu", AT_ref (a)->die_offset);
          else
            fprintf (outfile, "die -> <null>");
          break;
        case dw_val_class_lbl_id:
        case dw_val_class_lbl_offset:
-         fprintf (outfile, "label: %s", a->dw_attr_val.v.val_lbl_id);
+         fprintf (outfile, "label: %s", AT_lbl (a));
          break;
        case dw_val_class_str:
-         if (a->dw_attr_val.v.val_str != NULL)
-           fprintf (outfile, "\"%s\"", a->dw_attr_val.v.val_str);
+         if (AT_string (a) != NULL)
+           fprintf (outfile, "\"%s\"", AT_string (a));
          else
            fprintf (outfile, "<null>");
          break;
@@ -4442,34 +4318,54 @@ debug_dwarf ()
 {
   print_indent = 0;
   print_die (comp_unit_die, stderr);
-  print_dwarf_line_table (stderr);
+  if (! DWARF2_ASM_LINE_DEBUG_INFO)
+    print_dwarf_line_table (stderr);
 }
 \f
-/* Traverse the DIE, and add a sibling attribute if it may have the
-   effect of speeding up access to siblings.  To save some space,
-   avoid generating sibling attributes for DIE's without children.  */
+/* We build up the lists of children and attributes by pushing new ones
+   onto the beginning of the list.  Reverse the lists for DIE so that
+   they are in order of addition.  */
 
 static void
-add_sibling_attributes(die)
+reverse_die_lists (die)
      register dw_die_ref die;
 {
-  register dw_die_ref c;
-  register dw_attr_ref attr;
-  if (die != comp_unit_die && die->die_child != NULL)
-    {
-      attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
-      attr->dw_attr_next = NULL;
-      attr->dw_attr = DW_AT_sibling;
-      attr->dw_attr_val.val_class = dw_val_class_die_ref;
-      attr->dw_attr_val.v.val_die_ref = die->die_sib;
+  register dw_die_ref c, cp, cn;
+  register dw_attr_ref a, ap, an;
 
-      /* Add the sibling link to the front of the attribute list.  */
-      attr->dw_attr_next = die->die_attr;
-      if (die->die_attr == NULL)
-       die->die_attr_last = attr;
+  for (a = die->die_attr, ap = 0; a; a = an)
+    {
+      an = a->dw_attr_next;
+      a->dw_attr_next = ap;
+      ap = a;
+    }
+  die->die_attr = ap;
 
-      die->die_attr = attr;
+  for (c = die->die_child, cp = 0; c; c = cn)
+    {
+      cn = c->die_sib;
+      c->die_sib = cp;
+      cp = c;
     }
+  die->die_child = cp;
+}
+
+/* Traverse the DIE, reverse its lists of attributes and children, and
+   add a sibling attribute if it may have the effect of speeding up
+   access to siblings.  To save some space, avoid generating sibling
+   attributes for DIE's without children.  */
+
+static void
+add_sibling_attributes (die)
+     register dw_die_ref die;
+{
+  register dw_die_ref c;
+
+  reverse_die_lists (die);
+
+  if (die != comp_unit_die && die->die_sib && die->die_child != NULL)
+    /* Add the sibling link to the front of the attribute list.  */
+    add_AT_die_ref (die, DW_AT_sibling, die->die_sib);
 
   for (c = die->die_child; c != NULL; c = c->die_sib)
     add_sibling_attributes (c);
@@ -4503,8 +4399,7 @@ build_abbrev_table (die)
              while (a_attr != NULL && d_attr != NULL)
                {
                  if ((a_attr->dw_attr != d_attr->dw_attr)
-                     || (value_format (&a_attr->dw_attr_val)
-                         != value_format (&d_attr->dw_attr_val)))
+                     || (value_format (a_attr) != value_format (d_attr)))
                    break;
 
                  a_attr = a_attr->dw_attr_next;
@@ -4549,7 +4444,7 @@ build_abbrev_table (die)
 
 static unsigned long
 size_of_string (str)
-     register char *str;
+     register const char *str;
 {
   return strlen (str) + 1;
 }
@@ -4703,15 +4598,14 @@ size_of_die (die)
   size += size_of_uleb128 (die->die_abbrev);
   for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
     {
-      switch (a->dw_attr_val.val_class)
+      switch (AT_class (a))
        {
        case dw_val_class_addr:
          size += PTR_SIZE;
          break;
        case dw_val_class_loc:
          {
-           register unsigned long lsize
-             = size_of_locs (a->dw_attr_val.v.val_loc);
+           register unsigned long lsize = size_of_locs (AT_loc (a));
 
            /* Block length.  */
            size += constant_size (lsize);
@@ -4722,7 +4616,7 @@ size_of_die (die)
          size += 4;
          break;
        case dw_val_class_unsigned_const:
-         size += constant_size (a->dw_attr_val.v.val_unsigned);
+         size += constant_size (AT_unsigned (a));
          break;
        case dw_val_class_long_long:
          size += 1 + 8; /* block */
@@ -4746,7 +4640,7 @@ size_of_die (die)
          size += DWARF_OFFSET_SIZE;
          break;
        case dw_val_class_str:
-         size += size_of_string (a->dw_attr_val.v.val_str);
+         size += size_of_string (AT_string (a));
          break;
        default:
          abort ();
@@ -4817,165 +4711,6 @@ size_of_line_prolog ()
   return size;
 }
 
-/* Return the size of the line information generated for this
-   compilation unit.  */
-
-static unsigned long
-size_of_line_info ()
-{
-  register unsigned long size;
-  register unsigned long lt_index;
-  register unsigned long current_line;
-  register long line_offset;
-  register long line_delta;
-  register unsigned long current_file;
-  register unsigned long function;
-  unsigned long size_of_set_address;
-
-  /* Size of a DW_LNE_set_address instruction.  */
-  size_of_set_address = 1 + size_of_uleb128 (1 + PTR_SIZE) + 1 + PTR_SIZE;
-
-  /* Version number.  */
-  size = 2;
-
-  /* Prolog length specifier.  */
-  size += DWARF_OFFSET_SIZE;
-
-  /* Prolog.  */
-  size += size_of_line_prolog ();
-
-  current_file = 1;
-  current_line = 1;
-  for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index)
-    {
-      register dw_line_info_ref line_info = &line_info_table[lt_index];
-
-      if (line_info->dw_line_num == current_line
-         && line_info->dw_file_num == current_file)
-       continue;
-
-      /* Advance pc instruction.  */
-      /* ??? See the DW_LNS_advance_pc comment in output_line_info.  */
-      if (0)
-       size += 1 + 2;
-      else
-       size += size_of_set_address;
-
-      if (line_info->dw_file_num != current_file)
-       {
-         /* Set file number instruction.  */
-         size += 1;
-         current_file = line_info->dw_file_num;
-         size += size_of_uleb128 (current_file);
-       }
-
-      if (line_info->dw_line_num != current_line)
-       {
-         line_offset = line_info->dw_line_num - current_line;
-         line_delta = line_offset - DWARF_LINE_BASE;
-         current_line = line_info->dw_line_num;
-         if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
-           /* 1-byte special line number instruction.  */
-           size += 1;
-         else
-           {
-             /* Advance line instruction.  */
-             size += 1;
-             size += size_of_sleb128 (line_offset);
-             /* Generate line entry instruction.  */
-             size += 1;
-           }
-       }
-    }
-
-  /* Advance pc instruction.  */
-  if (0)
-    size += 1 + 2;
-  else
-    size += size_of_set_address;
-
-  /* End of line number info. marker.  */
-  size += 1 + size_of_uleb128 (1) + 1;
-
-  function = 0;
-  current_file = 1;
-  current_line = 1;
-  for (lt_index = 0; lt_index < separate_line_info_table_in_use; )
-    {
-      register dw_separate_line_info_ref line_info
-       = &separate_line_info_table[lt_index];
-
-      if (line_info->dw_line_num == current_line
-         && line_info->dw_file_num == current_file
-         && line_info->function == function)
-       goto cont;
-
-      if (function != line_info->function)
-       {
-         function = line_info->function;
-         /* Set address register instruction.  */
-         size += size_of_set_address;
-       }
-      else
-       {
-         /* Advance pc instruction.  */
-         if (0)
-           size += 1 + 2;
-         else
-           size += size_of_set_address;
-       }
-
-      if (line_info->dw_file_num != current_file)
-       {
-         /* Set file number instruction.  */
-         size += 1;
-         current_file = line_info->dw_file_num;
-         size += size_of_uleb128 (current_file);
-       }
-
-      if (line_info->dw_line_num != current_line)
-       {
-         line_offset = line_info->dw_line_num - current_line;
-         line_delta = line_offset - DWARF_LINE_BASE;
-         current_line = line_info->dw_line_num;
-         if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
-           /* 1-byte special line number instruction.  */
-           size += 1;
-         else
-           {
-             /* Advance line instruction.  */
-             size += 1;
-             size += size_of_sleb128 (line_offset);
-
-             /* Generate line entry instruction.  */
-             size += 1;
-           }
-       }
-
-    cont:
-      ++lt_index;
-
-      /* If we're done with a function, end its sequence.  */
-      if (lt_index == separate_line_info_table_in_use
-         || separate_line_info_table[lt_index].function != function)
-       {
-         current_file = 1;
-         current_line = 1;
-
-         /* Advance pc instruction.  */
-         if (0)
-           size += 1 + 2;
-         else
-           size += size_of_set_address;
-
-         /* End of line number info. marker.  */
-         size += 1 + size_of_uleb128 (1) + 1;
-       }
-    }
-
-  return size;
-}
-
 /* Return the size of the .debug_pubnames table  generated for the
    compilation unit.  */
 
@@ -5017,15 +4752,15 @@ size_of_aranges ()
 /* Select the encoding of an attribute value.  */
 
 static enum dwarf_form
-value_format (v)
-     dw_val_ref v;
+value_format (a)
+     dw_attr_ref a;
 {
-  switch (v->val_class)
+  switch (a->dw_attr_val.val_class)
     {
     case dw_val_class_addr:
       return DW_FORM_addr;
     case dw_val_class_loc:
-      switch (constant_size (size_of_locs (v->v.val_loc)))
+      switch (constant_size (size_of_locs (AT_loc (a))))
        {
        case 1:
          return DW_FORM_block1;
@@ -5037,7 +4772,7 @@ value_format (v)
     case dw_val_class_const:
       return DW_FORM_data4;
     case dw_val_class_unsigned_const:
-      switch (constant_size (v->v.val_unsigned))
+      switch (constant_size (AT_unsigned (a)))
        {
        case 1:
          return DW_FORM_data1;
@@ -5074,10 +4809,10 @@ value_format (v)
 /* Output the encoding of an attribute value.  */
 
 static void
-output_value_format (v)
-     dw_val_ref v;
+output_value_format (a)
+     dw_attr_ref a;
 {
-  enum dwarf_form form = value_format (v);
+  enum dwarf_form form = value_format (a);
 
   output_uleb128 (form);
   if (flag_debug_asm)
@@ -5130,11 +4865,14 @@ output_abbrev_section ()
                     dwarf_attr_name (a_attr->dw_attr));
 
          fputc ('\n', asm_out_file);
-         output_value_format (&a_attr->dw_attr_val);
+         output_value_format (a_attr);
        }
 
       fprintf (asm_out_file, "\t%s\t0,0\n", ASM_BYTE_OP);
     }
+
+  /* Terminate the table.  */
+  fprintf (asm_out_file, "\t%s\t0\n", ASM_BYTE_OP);
 }
 
 /* Output location description stack opcode's operands (if any).  */
@@ -5256,22 +4994,6 @@ output_loc_operands (loc)
     }
 }
 
-/* Compute the offset of a sibling.  */
-
-static unsigned long
-sibling_offset (die)
-     dw_die_ref die;
-{
-  unsigned long offset;
-
-  if (die->die_child_last == NULL)
-    offset = die->die_offset + size_of_die (die);
-  else
-    offset = sibling_offset (die->die_child_last) + 1;
-
-  return offset;
-}
-
 /* Output the DIE and its attributes.  Called recursively to generate
    the definitions of each child DIE.  */
 
@@ -5281,7 +5003,6 @@ output_die (die)
 {
   register dw_attr_ref a;
   register dw_die_ref c;
-  register unsigned long ref_offset;
   register unsigned long size;
   register dw_loc_descr_ref loc;
 
@@ -5294,15 +5015,14 @@ output_die (die)
 
   for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
     {
-      switch (a->dw_attr_val.val_class)
+      switch (AT_class (a))
        {
        case dw_val_class_addr:
-         ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file,
-                                      a->dw_attr_val.v.val_addr);
+         ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, AT_addr (a));
          break;
 
        case dw_val_class_loc:
-         size = size_of_locs (a->dw_attr_val.v.val_loc);
+         size = size_of_locs (AT_loc (a));
 
          /* Output the block length for this list of location operations.  */
          switch (constant_size (size))
@@ -5322,8 +5042,7 @@ output_die (die)
                     ASM_COMMENT_START, dwarf_attr_name (a->dw_attr));
 
          fputc ('\n', asm_out_file);
-         for (loc = a->dw_attr_val.v.val_loc; loc != NULL;
-              loc = loc->dw_loc_next)
+         for (loc = AT_loc (a); loc != NULL; loc = loc->dw_loc_next)
            {
              /* Output the opcode.  */
              ASM_OUTPUT_DWARF_DATA1 (asm_out_file, loc->dw_loc_opc);
@@ -5339,23 +5058,20 @@ output_die (die)
          break;
 
        case dw_val_class_const:
-         ASM_OUTPUT_DWARF_DATA4 (asm_out_file, a->dw_attr_val.v.val_int);
+         ASM_OUTPUT_DWARF_DATA4 (asm_out_file, AT_int (a));
          break;
 
        case dw_val_class_unsigned_const:
-         switch (constant_size (a->dw_attr_val.v.val_unsigned))
+         switch (constant_size (AT_unsigned (a)))
            {
            case 1:
-             ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
-                                     a->dw_attr_val.v.val_unsigned);
+             ASM_OUTPUT_DWARF_DATA1 (asm_out_file, AT_unsigned (a));
              break;
            case 2:
-             ASM_OUTPUT_DWARF_DATA2 (asm_out_file,
-                                     a->dw_attr_val.v.val_unsigned);
+             ASM_OUTPUT_DWARF_DATA2 (asm_out_file, AT_unsigned (a));
              break;
            case 4:
-             ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
-                                     a->dw_attr_val.v.val_unsigned);
+             ASM_OUTPUT_DWARF_DATA4 (asm_out_file, AT_unsigned (a));
              break;
            case 8:
              ASM_OUTPUT_DWARF_DATA8 (asm_out_file,
@@ -5409,18 +5125,11 @@ output_die (die)
          }
 
        case dw_val_class_flag:
-         ASM_OUTPUT_DWARF_DATA1 (asm_out_file, a->dw_attr_val.v.val_flag);
+         ASM_OUTPUT_DWARF_DATA1 (asm_out_file, AT_flag (a));
          break;
 
        case dw_val_class_die_ref:
-         if (a->dw_attr_val.v.val_die_ref != NULL)
-           ref_offset = a->dw_attr_val.v.val_die_ref->die_offset;
-         else if (a->dw_attr == DW_AT_sibling)
-           ref_offset = sibling_offset(die);
-         else
-           abort ();
-
-         ASM_OUTPUT_DWARF_DATA (asm_out_file, ref_offset);
+         ASM_OUTPUT_DWARF_DATA (asm_out_file, AT_ref (a)->die_offset);
          break;
 
        case dw_val_class_fde_ref:
@@ -5434,29 +5143,28 @@ output_die (die)
          break;
 
        case dw_val_class_lbl_id:
-         ASM_OUTPUT_DWARF_ADDR (asm_out_file, a->dw_attr_val.v.val_lbl_id);
+         ASM_OUTPUT_DWARF_ADDR (asm_out_file, AT_lbl (a));
          break;
 
        case dw_val_class_lbl_offset:
-         ASM_OUTPUT_DWARF_OFFSET (asm_out_file, a->dw_attr_val.v.val_lbl_id);
+         ASM_OUTPUT_DWARF_OFFSET (asm_out_file, AT_lbl (a));
          break;
 
        case dw_val_class_str:
          if (flag_debug_asm)
-           ASM_OUTPUT_DWARF_STRING (asm_out_file, a->dw_attr_val.v.val_str);
+           ASM_OUTPUT_DWARF_STRING (asm_out_file, AT_string (a));
          else
-           ASM_OUTPUT_ASCII (asm_out_file,
-                             a->dw_attr_val.v.val_str,
-                             (int) strlen (a->dw_attr_val.v.val_str) + 1);
+           ASM_OUTPUT_ASCII (asm_out_file, AT_string (a),
+                             (int) strlen (AT_string (a)) + 1);
          break;
 
        default:
          abort ();
        }
 
-      if (a->dw_attr_val.val_class != dw_val_class_loc
-         && a->dw_attr_val.val_class != dw_val_class_long_long
-         && a->dw_attr_val.val_class != dw_val_class_float)
+      if (AT_class (a) != dw_val_class_loc
+         && AT_class (a) != dw_val_class_long_long
+         && AT_class (a) != dw_val_class_float)
        {
          if (flag_debug_asm)
            fprintf (asm_out_file, "\t%s %s",
@@ -5515,7 +5223,7 @@ output_compilation_unit_header ()
    of decl_printable_name for C++ looks like "A::f(int)".  Let's drop the
    argument list, and maybe the scope.  */
 
-static char *
+static const char *
 dwarf2_name (decl, scope)
      tree decl;
      int scope;
@@ -5669,13 +5377,19 @@ output_aranges ()
             ASM_COMMENT_START);
 
   fputc ('\n', asm_out_file);
-  ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 4);
-  if (PTR_SIZE == 8)
-    fprintf (asm_out_file, ",0,0");
 
-  if (flag_debug_asm)
-    fprintf (asm_out_file, "\t%s Pad to %d byte boundary",
-            ASM_COMMENT_START, 2 * PTR_SIZE);
+  /* We need to align to twice the pointer size here.  */
+  if (DWARF_ARANGES_PAD_SIZE)
+    {
+      /* Pad using a 2 bytes word so that padding is correct
+         for any pointer size.  */
+      ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0);
+      for (i = 2; i < DWARF_ARANGES_PAD_SIZE; i += 2)
+        fprintf (asm_out_file, ",0");
+      if (flag_debug_asm)
+        fprintf (asm_out_file, "\t%s Pad to %d byte boundary",
+                 ASM_COMMENT_START, 2 * PTR_SIZE);
+    }
 
   fputc ('\n', asm_out_file);
   ASM_OUTPUT_DWARF_ADDR (asm_out_file, text_section_label);
@@ -5691,29 +5405,39 @@ output_aranges ()
   fputc ('\n', asm_out_file);
   for (i = 0; i < arange_table_in_use; ++i)
     {
-      dw_die_ref a = arange_table[i];
+      dw_die_ref die = arange_table[i];
 
-      if (a->die_tag == DW_TAG_subprogram)
-       ASM_OUTPUT_DWARF_ADDR (asm_out_file, get_AT_low_pc (a));
+      if (die->die_tag == DW_TAG_subprogram)
+       ASM_OUTPUT_DWARF_ADDR (asm_out_file, get_AT_low_pc (die));
       else
        {
-         char *name = get_AT_string (a, DW_AT_MIPS_linkage_name);
-         if (! name)
-           name = get_AT_string (a, DW_AT_name);
+         /* A static variable; extract the symbol from DW_AT_location.
+            Note that this code isn't currently hit, as we only emit
+            aranges for functions (jason 9/23/99).  */
+
+         dw_attr_ref a = get_AT (die, DW_AT_location);
+         dw_loc_descr_ref loc;
+         if (! a || AT_class (a) != dw_val_class_loc)
+           abort ();
 
-         ASM_OUTPUT_DWARF_ADDR (asm_out_file, name);
+         loc = AT_loc (a);
+         if (loc->dw_loc_opc != DW_OP_addr)
+           abort ();
+
+         ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file,
+                                      loc->dw_loc_oprnd1.v.val_addr);
        }
 
       if (flag_debug_asm)
        fprintf (asm_out_file, "\t%s Address", ASM_COMMENT_START);
 
       fputc ('\n', asm_out_file);
-      if (a->die_tag == DW_TAG_subprogram)
-       ASM_OUTPUT_DWARF_ADDR_DELTA (asm_out_file, get_AT_hi_pc (a),
-                                    get_AT_low_pc (a));
+      if (die->die_tag == DW_TAG_subprogram)
+       ASM_OUTPUT_DWARF_ADDR_DELTA (asm_out_file, get_AT_hi_pc (die),
+                                    get_AT_low_pc (die));
       else
        ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file,
-                                   get_AT_unsigned (a, DW_AT_byte_size));
+                                   get_AT_unsigned (die, DW_AT_byte_size));
 
       if (flag_debug_asm)
        fprintf (asm_out_file, "%s Length", ASM_COMMENT_START);
@@ -5729,10 +5453,7 @@ output_aranges ()
 }
 
 /* Output the source line number correspondence information.  This
-   information goes into the .debug_line section.
-
-   If the format of this data changes, then the function size_of_line_info
-   must also be adjusted the same way.  */
+   information goes into the .debug_line section.  */
 
 static void
 output_line_info ()
@@ -5749,12 +5470,13 @@ output_line_info ()
   register unsigned long current_file;
   register unsigned long function;
 
-  ASM_OUTPUT_DWARF_DATA (asm_out_file, size_of_line_info ());
+  ASM_OUTPUT_DWARF_DELTA (asm_out_file, ".LTEND", ".LTSTART");
   if (flag_debug_asm)
     fprintf (asm_out_file, "\t%s Length of Source Line Info.",
             ASM_COMMENT_START);
 
   fputc ('\n', asm_out_file);
+  ASM_OUTPUT_LABEL (asm_out_file, ".LTSTART");
   ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
   if (flag_debug_asm)
     fprintf (asm_out_file, "\t%s DWARF Version", ASM_COMMENT_START);
@@ -5872,12 +5594,18 @@ output_line_info ()
     {
       register dw_line_info_ref line_info = &line_info_table[lt_index];
 
+#if 0
+      /* Disable this optimization for now; GDB wants to see two line notes
+        at the beginning of a function so it can find the end of the
+        prologue.  */
+
       /* Don't emit anything for redundant notes.  Just updating the
          address doesn't accomplish anything, because we already assume
          that anything after the last address is this line.  */
       if (line_info->dw_line_num == current_line
          && line_info->dw_file_num == current_file)
        continue;
+#endif
 
       /* Emit debug info for the address of the current line, choosing
         the encoding that uses the least amount of space.  */
@@ -6010,7 +5738,6 @@ output_line_info ()
       fputc ('\n', asm_out_file);
     }
 
-  /* Output the marker for the end of the line number info.  */
   ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
   if (flag_debug_asm)
     fprintf (asm_out_file, "\t%s DW_LNE_end_sequence", ASM_COMMENT_START);
@@ -6029,11 +5756,13 @@ output_line_info ()
       register dw_separate_line_info_ref line_info
        = &separate_line_info_table[lt_index];
 
+#if 0
       /* Don't emit anything for redundant notes.  */
       if (line_info->dw_line_num == current_line
          && line_info->dw_file_num == current_file
          && line_info->function == function)
        goto cont;
+#endif
 
       /* Emit debug info for the address of the current line.  If this is
         a new function, or the first line of a function, then we need
@@ -6149,7 +5878,9 @@ output_line_info ()
          fputc ('\n', asm_out_file);
        }
 
+#if 0
     cont:
+#endif
       ++lt_index;
 
       /* If we're done with a function, end its sequence.  */
@@ -6201,38 +5932,11 @@ output_line_info ()
          fputc ('\n', asm_out_file);
        }
     }
-}
-\f
-/* Given a pointer to a BLOCK node return non-zero if (and only if) the node
-   in question represents the outermost pair of curly braces (i.e. the "body
-   block") of a function or method.
-
-   For any BLOCK node representing a "body block" of a function or method, the
-   BLOCK_SUPERCONTEXT of the node will point to another BLOCK node which
-   represents the outermost (function) scope for the function or method (i.e.
-   the one which includes the formal parameters).  The BLOCK_SUPERCONTEXT of
-   *that* node in turn will point to the relevant FUNCTION_DECL node. */
 
-static inline int
-is_body_block (stmt)
-     register tree stmt;
-{
-  if (TREE_CODE (stmt) == BLOCK)
-    {
-      register tree parent = BLOCK_SUPERCONTEXT (stmt);
-
-      if (TREE_CODE (parent) == BLOCK)
-       {
-         register tree grandparent = BLOCK_SUPERCONTEXT (parent);
-
-         if (TREE_CODE (grandparent) == FUNCTION_DECL)
-           return 1;
-       }
-    }
-
-  return 0;
+  /* Output the marker for the end of the line number info.  */
+  ASM_OUTPUT_LABEL (asm_out_file, ".LTEND");
 }
-
+\f
 /* Given a pointer to a tree node for some base type, return a pointer to
    a DIE that describes the given type.
 
@@ -6244,7 +5948,7 @@ base_type_die (type)
      register tree type;
 {
   register dw_die_ref base_type_result;
-  register char *type_name;
+  register const char *type_name;
   register enum dwarf_type encoding;
   register tree name = TYPE_NAME (type);
 
@@ -6252,9 +5956,15 @@ base_type_die (type)
       || TREE_CODE (type) == VOID_TYPE)
     return 0;
 
-  if (TREE_CODE (name) == TYPE_DECL)
-    name = DECL_NAME (name);
-  type_name = IDENTIFIER_POINTER (name);
+  if (name)
+    {
+      if (TREE_CODE (name) == TYPE_DECL)
+       name = DECL_NAME (name);
+
+      type_name = IDENTIFIER_POINTER (name);
+    }
+  else
+    type_name = "__unknown__";
 
   switch (TREE_CODE (type))
     {
@@ -6288,8 +5998,13 @@ base_type_die (type)
       encoding = DW_ATE_float;
       break;
 
+      /* Dwarf2 doesn't know anything about complex ints, so use
+        a user defined type for it.  */
     case COMPLEX_TYPE:
-      encoding = DW_ATE_complex_float;
+      if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
+       encoding = DW_ATE_complex_float;
+      else
+       encoding = DW_ATE_lo_user;
       break;
 
     case BOOLEAN_TYPE:
@@ -6302,6 +6017,9 @@ base_type_die (type)
     }
 
   base_type_result = new_die (DW_TAG_base_type, comp_unit_die);
+  if (demangle_name_func)
+    type_name = (*demangle_name_func) (type_name);
+
   add_AT_string (base_type_result, DW_AT_name, type_name);
   add_AT_unsigned (base_type_result, DW_AT_byte_size,
                   int_size_in_bytes (type));
@@ -6562,11 +6280,15 @@ is_based_loc (rtl)
    When creating memory location descriptors, we are effectively transforming
    the RTL for a memory-resident object into its Dwarf postfix expression
    equivalent.  This routine recursively descends an RTL tree, turning
-   it into Dwarf postfix code as it goes.  */
+   it into Dwarf postfix code as it goes.
+
+   MODE is the mode of the memory reference, needed to handle some
+   autoincrement addressing modes.  */
 
 static dw_loc_descr_ref
-mem_loc_descriptor (rtl)
+mem_loc_descriptor (rtl, mode)
      register rtx rtl;
+     enum machine_mode mode;
 {
   dw_loc_descr_ref mem_loc_result = NULL;
   /* Note that for a dynamically sized array, the location we will generate a 
@@ -6574,8 +6296,19 @@ mem_loc_descriptor (rtl)
      actually within the array.  That's *not* necessarily the same as the
      zeroth element of the array.  */
 
+#ifdef ASM_SIMPLIFY_DWARF_ADDR
+  rtl = ASM_SIMPLIFY_DWARF_ADDR (rtl);
+#endif
+
   switch (GET_CODE (rtl))
     {
+    case POST_INC:
+    case POST_DEC:
+      /* POST_INC and POST_DEC can be handled just like a SUBREG.  So we
+        just fall into the SUBREG code.  */
+
+      /* ... fall through ... */
+
     case SUBREG:
       /* The case of a subreg may arise when we have a local (register)
          variable or a formal (register) parameter which doesn't quite fill
@@ -6604,25 +6337,42 @@ mem_loc_descriptor (rtl)
       break;
 
     case MEM:
-      mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0));
+      mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), mode);
       add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0));
       break;
 
+     case LABEL_REF:
+       /* Some ports can transform a symbol ref into a label ref, because
+        the symbol ref is too far away and has to be dumped into a constant
+        pool.  */
     case CONST:
     case SYMBOL_REF:
       mem_loc_result = new_loc_descr (DW_OP_addr, 0, 0);
       mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
-      mem_loc_result->dw_loc_oprnd1.v.val_addr = addr_to_string (rtl);
+      mem_loc_result->dw_loc_oprnd1.v.val_addr = save_rtx (rtl);
       break;
 
+    case PRE_INC:
+    case PRE_DEC:
+      /* Turn these into a PLUS expression and fall into the PLUS code
+        below.  */
+      rtl = gen_rtx_PLUS (word_mode, XEXP (rtl, 0),
+                         GEN_INT (GET_CODE (rtl) == PRE_INC
+                                  ? GET_MODE_UNIT_SIZE (mode) 
+                                  : - GET_MODE_UNIT_SIZE (mode)));
+                         
+      /* ... fall through ... */
+
     case PLUS:
       if (is_based_loc (rtl))
        mem_loc_result = based_loc_descr (reg_number (XEXP (rtl, 0)),
                                          INTVAL (XEXP (rtl, 1)));
       else
        {
-         add_loc_descr (&mem_loc_result, mem_loc_descriptor (XEXP (rtl, 0)));
-         add_loc_descr (&mem_loc_result, mem_loc_descriptor (XEXP (rtl, 1)));
+         add_loc_descr (&mem_loc_result, mem_loc_descriptor (XEXP (rtl, 0),
+                                                             mode));
+         add_loc_descr (&mem_loc_result, mem_loc_descriptor (XEXP (rtl, 1),
+                                                             mode));
          add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_plus, 0, 0));
        }
       break;
@@ -6630,8 +6380,8 @@ mem_loc_descriptor (rtl)
     case MULT:
       /* If a pseudo-reg is optimized away, it is possible for it to
         be replaced with a MEM containing a multiply.  */
-      add_loc_descr (&mem_loc_result, mem_loc_descriptor (XEXP (rtl, 0)));
-      add_loc_descr (&mem_loc_result, mem_loc_descriptor (XEXP (rtl, 1)));
+      add_loc_descr (&mem_loc_result, mem_loc_descriptor (XEXP (rtl, 0), mode));
+      add_loc_descr (&mem_loc_result, mem_loc_descriptor (XEXP (rtl, 1), mode));
       add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_mul, 0, 0));
       break;
 
@@ -6698,7 +6448,7 @@ loc_descriptor (rtl)
       break;
 
     case MEM:
-      loc_result = mem_loc_descriptor (XEXP (rtl, 0));
+      loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl));
       break;
 
     case CONCAT:
@@ -6712,13 +6462,13 @@ loc_descriptor (rtl)
   return loc_result;
 }
 
-/* Given an unsigned value, round it up to the lowest multiple of `boundary'
+/* Given a value, round it up to the lowest multiple of `boundary'
    which is not less than the value itself.  */
 
-static inline unsigned
+static inline HOST_WIDE_INT
 ceiling (value, boundary)
-     register unsigned value;
-     register unsigned boundary;
+     HOST_WIDE_INT value;
+     unsigned int boundary;
 {
   return (((value + boundary - 1) / boundary) * boundary);
 }
@@ -6762,7 +6512,7 @@ simple_type_align_in_bits (type)
    else return BITS_PER_WORD if the type actually turns out to be an
    ERROR_MARK node.  */
 
-static inline unsigned
+static inline unsigned HOST_WIDE_INT
 simple_type_size_in_bits (type)
      register tree type;
 {
@@ -6772,10 +6522,10 @@ simple_type_size_in_bits (type)
     {
       register tree type_size_tree = TYPE_SIZE (type);
 
-      if (TREE_CODE (type_size_tree) != INTEGER_CST)
+      if (! host_integerp (type_size_tree, 1))
        return TYPE_ALIGN (type);
 
-      return (unsigned) TREE_INT_CST_LOW (type_size_tree);
+      return tree_low_cst (type_size_tree, 1);
     }
 }
 
@@ -6786,22 +6536,21 @@ simple_type_size_in_bits (type)
    be a pointer to an ERROR_MARK node, or because the offset is actually
    variable.  (We can't handle the latter case just yet).  */
 
-static unsigned
+static HOST_WIDE_INT
 field_byte_offset (decl)
      register tree decl;
 {
-  register unsigned type_align_in_bytes;
-  register unsigned type_align_in_bits;
-  register unsigned type_size_in_bits;
-  register unsigned object_offset_in_align_units;
-  register unsigned object_offset_in_bits;
-  register unsigned object_offset_in_bytes;
-  register tree type;
-  register tree bitpos_tree;
-  register tree field_size_tree;
-  register unsigned bitpos_int;
-  register unsigned deepest_bitpos;
-  register unsigned field_size_in_bits;
+  unsigned int type_align_in_bytes;
+  unsigned int type_align_in_bits;
+  unsigned HOST_WIDE_INT type_size_in_bits;
+  HOST_WIDE_INT object_offset_in_align_units;
+  HOST_WIDE_INT object_offset_in_bits;
+  HOST_WIDE_INT object_offset_in_bytes;
+  tree type;
+  tree field_size_tree;
+  HOST_WIDE_INT bitpos_int;
+  HOST_WIDE_INT deepest_bitpos;
+  unsigned HOST_WIDE_INT field_size_in_bits;
 
   if (TREE_CODE (decl) == ERROR_MARK)
     return 0;
@@ -6810,21 +6559,31 @@ field_byte_offset (decl)
     abort ();
 
   type = field_type (decl);
-
-  bitpos_tree = DECL_FIELD_BITPOS (decl);
   field_size_tree = DECL_SIZE (decl);
 
-  /* We cannot yet cope with fields whose positions or sizes are variable, so 
+  /* If there was an error, the size could be zero.  */
+  if (! field_size_tree)
+    {
+      if (errorcount)
+       return 0;
+
+      abort ();
+    }
+
+  /* We cannot yet cope with fields whose positions are variable, so 
      for now, when we see such things, we simply return 0.  Someday, we may
      be able to handle such cases, but it will be damn difficult.  */
-  if (TREE_CODE (bitpos_tree) != INTEGER_CST)
+  if (! host_integerp (bit_position (decl), 0))
     return 0;
-  bitpos_int = (unsigned) TREE_INT_CST_LOW (bitpos_tree);
 
-  if (TREE_CODE (field_size_tree) != INTEGER_CST)
-    return 0;
+  bitpos_int = int_bit_position (decl);
+
+    /* If we don't know the size of the field, pretend it's a full word.  */
+  if (host_integerp (field_size_tree, 1))
+    field_size_in_bits = tree_low_cst (field_size_tree, 1);
+  else
+    field_size_in_bits = BITS_PER_WORD;
 
-  field_size_in_bits = (unsigned) TREE_INT_CST_LOW (field_size_tree);
   type_size_in_bits = simple_type_size_in_bits (type);
   type_align_in_bits = simple_type_align_in_bits (type);
   type_align_in_bytes = type_align_in_bits / BITS_PER_UNIT;
@@ -6913,6 +6672,13 @@ add_AT_location_description (die, attr_kind, rtl)
   if (is_pseudo_reg (rtl)
       || (GET_CODE (rtl) == MEM
          && is_pseudo_reg (XEXP (rtl, 0)))
+      /* This can happen for a PARM_DECL with a DECL_INCOMING_RTL which 
+        references the internal argument pointer (a pseudo) in a function
+        where all references to the internal argument pointer were
+        eliminated via the optimizers.  */
+      || (GET_CODE (rtl) == MEM
+         && GET_CODE (XEXP (rtl, 0)) == PLUS
+         && is_pseudo_reg (XEXP (XEXP (rtl, 0), 0)))
       || (GET_CODE (rtl) == CONCAT
          && is_pseudo_reg (XEXP (rtl, 0))
          && is_pseudo_reg (XEXP (rtl, 1))))
@@ -6950,7 +6716,7 @@ add_data_member_location_attribute (die, decl)
   register enum dwarf_location_atom op;
 
   if (TREE_CODE (decl) == TREE_VEC)
-    offset = TREE_INT_CST_LOW (BINFO_OFFSET (decl));
+    offset = tree_low_cst (BINFO_OFFSET (decl), 0);
   else
     offset = field_byte_offset (decl);
 
@@ -7041,7 +6807,7 @@ add_const_value_attribute (die, rtl)
     case SYMBOL_REF:
     case LABEL_REF:
     case CONST:
-      add_AT_addr (die, DW_AT_const_value, addr_to_string (rtl));
+      add_AT_addr (die, DW_AT_const_value, save_rtx (rtl));
       break;
 
     case PLUS:
@@ -7183,7 +6949,8 @@ add_location_or_const_value_attribute (die, decl)
            rtl = DECL_INCOMING_RTL (decl);
          else if (! BYTES_BIG_ENDIAN
                   && TREE_CODE (declared_type) == INTEGER_TYPE
-                  && TYPE_SIZE (declared_type) <= TYPE_SIZE (passed_type))
+                  && (GET_MODE_SIZE (TYPE_MODE (declared_type))
+                      <= GET_MODE_SIZE (TYPE_MODE (passed_type))))
                rtl = DECL_INCOMING_RTL (decl);
        }
 
@@ -7265,10 +7032,15 @@ add_location_or_const_value_attribute (die, decl)
 static inline void
 add_name_attribute (die, name_string)
      register dw_die_ref die;
-     register char *name_string;
+     register const char *name_string;
 {
   if (name_string != NULL && *name_string != 0)
-    add_AT_string (die, DW_AT_name, name_string);
+    {
+      if (demangle_name_func)
+       name_string = (*demangle_name_func) (name_string);
+
+      add_AT_string (die, DW_AT_name, name_string);
+    }
 }
 
 /* Given a tree node describing an array bound (either lower or upper) output
@@ -7280,8 +7052,6 @@ add_bound_info (subrange_die, bound_attr, bound)
      register enum dwarf_attribute bound_attr;
      register tree bound;
 {
-  register unsigned bound_value = 0;
-
   /* If this is an Ada unconstrained array type, then don't emit any debug
      info because the array bounds are unknown.  They are parameterized when
      the type is instantiated.  */
@@ -7295,13 +7065,14 @@ add_bound_info (subrange_die, bound_attr, bound)
 
     /* All fixed-bounds are represented by INTEGER_CST nodes.        */
     case INTEGER_CST:
-      bound_value = TREE_INT_CST_LOW (bound);
-      if (bound_attr == DW_AT_lower_bound
-         && ((is_c_family () && bound_value == 0)
-             || (is_fortran () && bound_value == 1)))
-       /* use the default */;
+      if (! host_integerp (bound, 0)
+         || (bound_attr == DW_AT_lower_bound
+             && ((is_c_family () && integer_zerop (bound))
+                 || (is_fortran () && integer_onep (bound)))))
+       /* use the default */
+       ;
       else
-       add_AT_unsigned (subrange_die, bound_attr, bound_value);
+       add_AT_unsigned (subrange_die, bound_attr, tree_low_cst (bound, 0));
       break;
 
     case CONVERT_EXPR:
@@ -7347,7 +7118,7 @@ add_bound_info (subrange_die, bound_attr, bound)
              rtx new_addr = fix_lexical_addr (XEXP (loc, 0), bound);
 
              if (XEXP (loc, 0) != new_addr)
-               loc = gen_rtx (MEM, GET_MODE (loc), new_addr);
+               loc = gen_rtx_MEM (GET_MODE (loc), new_addr);
            }
 
          add_AT_flag (decl_die, DW_AT_artificial, 1);
@@ -7514,13 +7285,12 @@ add_bit_offset_attribute (die, decl)
      register dw_die_ref die;
      register tree decl;
 {
-  register unsigned object_offset_in_bytes = field_byte_offset (decl);
-  register tree type = DECL_BIT_FIELD_TYPE (decl);
-  register tree bitpos_tree = DECL_FIELD_BITPOS (decl);
-  register unsigned bitpos_int;
-  register unsigned highest_order_object_bit_offset;
-  register unsigned highest_order_field_bit_offset;
-  register unsigned bit_offset;
+  HOST_WIDE_INT object_offset_in_bytes = field_byte_offset (decl);
+  tree type = DECL_BIT_FIELD_TYPE (decl);
+  HOST_WIDE_INT bitpos_int;
+  HOST_WIDE_INT highest_order_object_bit_offset;
+  HOST_WIDE_INT highest_order_field_bit_offset;
+  HOST_WIDE_INT unsigned bit_offset;
 
   /* Must be a field and a bit field.  */
   if (!type
@@ -7529,11 +7299,12 @@ add_bit_offset_attribute (die, decl)
 
   /* We can't yet handle bit-fields whose offsets are variable, so if we
      encounter such things, just return without generating any attribute
-     whatsoever.  */
-  if (TREE_CODE (bitpos_tree) != INTEGER_CST)
+     whatsoever.  Likewise for variable or too large size.  */
+  if (! host_integerp (bit_position (decl), 0)
+      || ! host_integerp (DECL_SIZE (decl), 1))
     return;
 
-  bitpos_int = (unsigned) TREE_INT_CST_LOW (bitpos_tree);
+  bitpos_int = int_bit_position (decl);
 
   /* Note that the bit offset is always the distance (in bits) from the
      highest-order bit of the "containing object" to the highest-order bit of 
@@ -7545,9 +7316,7 @@ add_bit_offset_attribute (die, decl)
 
   if (! BYTES_BIG_ENDIAN)
     {
-      highest_order_field_bit_offset
-       += (unsigned) TREE_INT_CST_LOW (DECL_SIZE (decl));
-
+      highest_order_field_bit_offset += tree_low_cst (DECL_SIZE (decl), 0);
       highest_order_object_bit_offset += simple_type_size_in_bits (type);
     }
 
@@ -7571,8 +7340,9 @@ add_bit_size_attribute (die, decl)
   if (TREE_CODE (decl) != FIELD_DECL
       || ! DECL_BIT_FIELD_TYPE (decl))
     abort ();
-  add_AT_unsigned (die, DW_AT_bit_size,
-                  (unsigned) TREE_INT_CST_LOW (DECL_SIZE (decl)));
+
+  if (host_integerp (DECL_SIZE (decl), 1))
+    add_AT_unsigned (die, DW_AT_bit_size, tree_low_cst (DECL_SIZE (decl), 1));
 }
 
 /* If the compiled language is ANSI C, then add a 'prototyped'
@@ -7599,11 +7369,31 @@ add_abstract_origin_attribute (die, origin)
      register tree origin;
 {
   dw_die_ref origin_die = NULL;
-  if (TREE_CODE_CLASS (TREE_CODE (origin)) == 'd')
+
+  if (TREE_CODE (origin) != FUNCTION_DECL)
+    {
+      /* We may have gotten separated from the block for the inlined
+        function, if we're in an exception handler or some such; make
+        sure that the abstract function has been written out.
+
+         Doing this for nested functions is wrong, however; functions are
+        distinct units, and our context might not even be inline.  */
+      tree fn = origin;
+      if (TYPE_P (fn))
+       fn = TYPE_STUB_DECL (fn);
+      fn = decl_function_context (fn);
+      if (fn)
+       gen_abstract_function (fn);
+    }
+
+  if (DECL_P (origin))
     origin_die = lookup_decl_die (origin);
-  else if (TREE_CODE_CLASS (TREE_CODE (origin)) == 't')
+  else if (TYPE_P (origin))
     origin_die = lookup_type_die (origin);
 
+  if (origin_die == NULL)
+    abort ();
+  
   add_AT_die_ref (die, DW_AT_abstract_origin, origin_die);
 }
 
@@ -7617,10 +7407,12 @@ add_pure_or_virtual_attribute (die, func_decl)
   if (DECL_VINDEX (func_decl))
     {
       add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
-      add_AT_loc (die, DW_AT_vtable_elem_location,
-                 new_loc_descr (DW_OP_constu,
-                                TREE_INT_CST_LOW (DECL_VINDEX (func_decl)),
-                                0));
+
+      if (host_integerp (DECL_VINDEX (func_decl), 0))
+       add_AT_loc (die, DW_AT_vtable_elem_location,
+                   new_loc_descr (DW_OP_constu,
+                                  tree_low_cst (DECL_VINDEX (func_decl), 0),
+                                  0));
 
       /* GNU extension: Record what type this method came from originally.  */
       if (debug_info_level > DINFO_LEVEL_TERSE)
@@ -7656,8 +7448,11 @@ add_name_and_src_coords_attributes (die, decl)
   if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL)
     {
       add_name_attribute (die, dwarf2_name (decl, 0));
-      add_src_coords_attributes (die, decl);
+      if (! DECL_ARTIFICIAL (decl))
+       add_src_coords_attributes (die, decl);
+
       if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL)
+         && TREE_PUBLIC (decl)
          && DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl))
        add_AT_string (die, DW_AT_MIPS_linkage_name,
                       IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
@@ -7670,55 +7465,33 @@ static void
 push_decl_scope (scope)
      tree scope;
 {
-  tree containing_scope;
-  int i;
-
   /* Make room in the decl_scope_table, if necessary.  */
   if (decl_scope_table_allocated == decl_scope_depth)
     {
       decl_scope_table_allocated += DECL_SCOPE_TABLE_INCREMENT;
       decl_scope_table
-       = (decl_scope_node *) xrealloc (decl_scope_table,
-                                       (decl_scope_table_allocated
-                                        * sizeof (decl_scope_node)));
-    }
-
-  decl_scope_table[decl_scope_depth].scope = scope;
-
-  /* Sometimes, while recursively emitting subtypes within a class type,
-     we end up recuring on a subtype at a higher level then the current
-     subtype.  In such a case, we need to search the decl_scope_table to
-     find the parent of this subtype.  */
-
-  if (AGGREGATE_TYPE_P (scope))
-    containing_scope = TYPE_CONTEXT (scope);
-  else
-    containing_scope = NULL_TREE;
-
-  /* The normal case.  */
-  if (decl_scope_depth == 0
-      || containing_scope == NULL_TREE
-      /* Ignore namespaces for the moment.  */
-      || TREE_CODE (containing_scope) == NAMESPACE_DECL
-      || containing_scope == decl_scope_table[decl_scope_depth - 1].scope)
-    decl_scope_table[decl_scope_depth].previous = decl_scope_depth - 1;
-  else
-    {
-      /* We need to search for the containing_scope.  */
-      for (i = 0; i < decl_scope_depth; i++)
-       if (decl_scope_table[i].scope == containing_scope)
-         break;
-
-      if (i == decl_scope_depth)
-       abort ();
-      else
-       decl_scope_table[decl_scope_depth].previous = i;
+       = (tree *) xrealloc (decl_scope_table,
+                            decl_scope_table_allocated * sizeof (tree));
     }
 
+  decl_scope_table[decl_scope_depth] = scope;
   decl_scope_depth++;
 }
 
-/* Return the DIE for the scope that immediately contains this declaration.  */
+/* Pop a declaration scope.  */
+static inline void
+pop_decl_scope ()
+{
+  if (decl_scope_depth <= 0)
+    abort ();
+  --decl_scope_depth;
+}
+
+/* Return the DIE for the scope that immediately contains this type.
+   Non-named types get global scope.  Named types nested in other
+   types get their containing scope if it's open, or global scope
+   otherwise.  All other types (i.e. function-local named types) get
+   the current active scope.  */
 
 static dw_die_ref
 scope_die_for (t, context_die)
@@ -7729,14 +7502,11 @@ scope_die_for (t, context_die)
   register tree containing_scope;
   register int i;
 
-  /* Walk back up the declaration tree looking for a place to define
-     this type.  */
-  if (TREE_CODE_CLASS (TREE_CODE (t)) == 't')
-    containing_scope = TYPE_CONTEXT (t);
-  else if (TREE_CODE (t) == FUNCTION_DECL && DECL_VINDEX (t))
-    containing_scope = decl_class_context (t);
-  else
-    containing_scope = DECL_CONTEXT (t);
+  /* Non-types always go in the current scope.  */
+  if (! TYPE_P (t))
+    abort ();
+
+  containing_scope = TYPE_CONTEXT (t);
 
   /* Ignore namespaces for the moment.  */
   if (containing_scope && TREE_CODE (containing_scope) == NAMESPACE_DECL)
@@ -7748,44 +7518,20 @@ scope_die_for (t, context_die)
   if (containing_scope && TREE_CODE (containing_scope) == FUNCTION_TYPE)
     containing_scope = NULL_TREE;
 
-  /* Function-local tags and functions get stuck in limbo until they are
-     fixed up by decls_for_scope.  */
-  if (context_die == NULL && containing_scope != NULL_TREE
-      && (TREE_CODE (t) == FUNCTION_DECL || is_tagged_type (t)))
-    return NULL;
-
   if (containing_scope == NULL_TREE)
     scope_die = comp_unit_die;
-  else
+  else if (TYPE_P (containing_scope))
     {
-      for (i = decl_scope_depth - 1, scope_die = context_die;
-          i >= 0 && decl_scope_table[i].scope != containing_scope;
-          (scope_die = scope_die->die_parent,
-           i = decl_scope_table[i].previous))
-       ;
+      /* For types, we can just look up the appropriate DIE.  But
+        first we check to see if we're in the middle of emitting it
+        so we know where the new DIE should go.  */
 
-      /* ??? Integrate_decl_tree does not handle BLOCK_TYPE_TAGS, nor
-        does it try to handle types defined by TYPE_DECLs.  Such types
-        thus have an incorrect TYPE_CONTEXT, which points to the block
-        they were originally defined in, instead of the current block
-        created by function inlining.  We try to detect that here and
-        work around it.  */
-
-      if (i < 0 && scope_die == comp_unit_die
-         && TREE_CODE (containing_scope) == BLOCK
-         && is_tagged_type (t)
-         && (block_ultimate_origin (decl_scope_table[decl_scope_depth - 1].scope)
-             == containing_scope))
-       {
-         scope_die = context_die;
-         /* Since the checks below are no longer applicable.  */
-         i = 0;
-       }
+      for (i = decl_scope_depth - 1; i >= 0; --i)
+       if (decl_scope_table[i] == containing_scope)
+         break;
 
       if (i < 0)
        {
-         if (TREE_CODE_CLASS (TREE_CODE (containing_scope)) != 't')
-           abort ();
          if (debug_info_level > DINFO_LEVEL_TERSE
              && !TREE_ASM_WRITTEN (containing_scope))
            abort ();
@@ -7793,18 +7539,39 @@ scope_die_for (t, context_die)
          /* If none of the current dies are suitable, we get file scope.  */
          scope_die = comp_unit_die;
        }
+      else
+       scope_die = lookup_type_die (containing_scope);
     }
+  else
+    scope_die = context_die;
 
   return scope_die;
 }
 
-/* Pop a declaration scope.  */
-static inline void
-pop_decl_scope ()
+/* Returns nonzero iff CONTEXT_DIE is internal to a function.  */
+
+static inline int local_scope_p PARAMS ((dw_die_ref));
+static inline int
+local_scope_p (context_die)
+     dw_die_ref context_die;
 {
-  if (decl_scope_depth <= 0)
-    abort ();
-  --decl_scope_depth;
+  for (; context_die; context_die = context_die->die_parent)
+    if (context_die->die_tag == DW_TAG_inlined_subroutine
+       || context_die->die_tag == DW_TAG_subprogram)
+      return 1;
+  return 0;
+}
+
+/* Returns nonzero iff CONTEXT_DIE is a class.  */
+
+static inline int class_scope_p PARAMS ((dw_die_ref));
+static inline int
+class_scope_p (context_die)
+     dw_die_ref context_die;
+{
+  return (context_die
+         && (context_die->die_tag == DW_TAG_structure_type
+             || context_die->die_tag == DW_TAG_union_type));
 }
 
 /* Many forms of DIEs require a "type description" attribute.  This
@@ -7957,6 +7724,7 @@ gen_array_type_die (type, context_die)
 #endif
     add_subscript_info (array_die, type);
 
+  add_name_attribute (array_die, type_tag (type));
   equate_type_number_to_die (type, array_die);
 
   /* Add representation of the type of the elements of this array type.  */
@@ -8012,45 +7780,6 @@ gen_entry_point_die (decl, context_die)
 }
 #endif
 
-/* Remember a type in the pending_types_list.  */
-
-static void
-pend_type (type)
-     register tree type;
-{
-  if (pending_types == pending_types_allocated)
-    {
-      pending_types_allocated += PENDING_TYPES_INCREMENT;
-      pending_types_list
-       = (tree *) xrealloc (pending_types_list,
-                            sizeof (tree) * pending_types_allocated);
-    }
-
-  pending_types_list[pending_types++] = type;
-}
-
-/* Output any pending types (from the pending_types list) which we can output
-   now (taking into account the scope that we are working on now).
-
-   For each type output, remove the given type from the pending_types_list
-   *before* we try to output it.  */
-
-static void
-output_pending_types_for_scope (context_die)
-     register dw_die_ref context_die;
-{
-  register tree type;
-
-  while (pending_types)
-    {
-      --pending_types;
-      type = pending_types_list[pending_types];
-      gen_type_die (type, context_die);
-      if (!TREE_ASM_WRITTEN (type))
-       abort ();
-    }
-}
-
 /* Remember a type in the incomplete_types_list.  */
 
 static void
@@ -8092,10 +7821,9 @@ gen_inlined_enumeration_type_die (type, context_die)
      register dw_die_ref context_die;
 {
   register dw_die_ref type_die = new_die (DW_TAG_enumeration_type,
-                                         scope_die_for (type, context_die));
-
-  if (!TREE_ASM_WRITTEN (type))
-    abort ();
+                                         context_die);
+  /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
+     be incomplete and such types are not marked.  */
   add_abstract_origin_attribute (type_die, type);
 }
 
@@ -8106,11 +7834,10 @@ gen_inlined_structure_type_die (type, context_die)
      register tree type;
      register dw_die_ref context_die;
 {
-  register dw_die_ref type_die = new_die (DW_TAG_structure_type,
-                                         scope_die_for (type, context_die));
+  register dw_die_ref type_die = new_die (DW_TAG_structure_type, context_die);
 
-  if (!TREE_ASM_WRITTEN (type))
-    abort ();
+  /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
+     be incomplete and such types are not marked.  */
   add_abstract_origin_attribute (type_die, type);
 }
 
@@ -8121,11 +7848,10 @@ gen_inlined_union_type_die (type, context_die)
      register tree type;
      register dw_die_ref context_die;
 {
-  register dw_die_ref type_die = new_die (DW_TAG_union_type,
-                                         scope_die_for (type, context_die));
+  register dw_die_ref type_die = new_die (DW_TAG_union_type, context_die);
 
-  if (!TREE_ASM_WRITTEN (type))
-    abort ();
+  /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
+     be incomplete and such types are not marked.  */
   add_abstract_origin_attribute (type_die, type);
 }
 
@@ -8177,8 +7903,16 @@ gen_enumeration_type_die (type, context_die)
 
          add_name_attribute (enum_die,
                              IDENTIFIER_POINTER (TREE_PURPOSE (link)));
-         add_AT_unsigned (enum_die, DW_AT_const_value,
-                          (unsigned) TREE_INT_CST_LOW (TREE_VALUE (link)));
+
+         if (host_integerp (TREE_VALUE (link), 0))
+           {
+             if (tree_int_cst_sgn (TREE_VALUE (link)) < 0)
+               add_AT_int (enum_die, DW_AT_const_value,
+                           tree_low_cst (TREE_VALUE (link), 0));
+             else
+               add_AT_unsigned (enum_die, DW_AT_const_value,
+                                tree_low_cst (TREE_VALUE (link), 0));
+           }
        }
     }
   else
@@ -8322,6 +8056,61 @@ gen_formal_types_die (function_or_method_type, context_die)
     }
 }
 
+/* We want to generate the DIE for TYPE so that we can generate the
+   die for MEMBER, which has been defined; we will need to refer back
+   to the member declaration nested within TYPE.  If we're trying to
+   generate minimal debug info for TYPE, processing TYPE won't do the
+   trick; we need to attach the member declaration by hand.  */
+
+static void
+gen_type_die_for_member (type, member, context_die)
+     tree type, member;
+     dw_die_ref context_die;
+{
+  gen_type_die (type, context_die);
+
+  /* If we're trying to avoid duplicate debug info, we may not have
+     emitted the member decl for this function.  Emit it now.  */
+  if (TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))
+      && ! lookup_decl_die (member))
+    {
+      if (decl_ultimate_origin (member))
+       abort ();
+
+      push_decl_scope (type);
+      if (TREE_CODE (member) == FUNCTION_DECL)
+       gen_subprogram_die (member, lookup_type_die (type));
+      else
+       gen_variable_die (member, lookup_type_die (type));
+      pop_decl_scope ();
+    }
+}
+
+/* Generate the DWARF2 info for the "abstract" instance
+   of a function which we may later generate inlined and/or
+   out-of-line instances of.  */
+
+static void
+gen_abstract_function (decl)
+     tree decl;
+{
+  register dw_die_ref old_die = lookup_decl_die (decl);
+  tree save_fn;
+
+  if (old_die && get_AT_unsigned (old_die, DW_AT_inline))
+    /* We've already generated the abstract instance.  */
+    return;
+
+  save_fn = current_function_decl;
+  current_function_decl = decl;
+
+  set_decl_abstract_flags (decl, 1);
+  dwarf2out_decl (decl);
+  set_decl_abstract_flags (decl, 0);
+
+  current_function_decl = save_fn;
+}
+
 /* Generate a DIE to represent a declared function (either file-scope or
    block-local).  */
 
@@ -8337,14 +8126,21 @@ gen_subprogram_die (decl, context_die)
   register tree fn_arg_types;
   register tree outer_scope;
   register dw_die_ref old_die = lookup_decl_die (decl);
-  register int declaration
-    = (current_function_decl != decl
-       || (context_die
-          && (context_die->die_tag == DW_TAG_structure_type
-              || context_die->die_tag == DW_TAG_union_type)));
+  register int declaration = (current_function_decl != decl
+                             || class_scope_p (context_die));
+
+  /* Note that it is possible to have both DECL_ABSTRACT and `declaration'
+     be true, if we started to generate the abstract instance of an inline,
+     decided to output its containing class, and proceeded to emit the
+     declaration of the inline from the member list for the class.  In that
+     case, `declaration' takes priority; we'll get back to the abstract
+     instance when we're done with the class.  */
 
   if (origin != NULL)
     {
+      if (declaration && ! local_scope_p (context_die))
+       abort ();
+
       subr_die = new_die (DW_TAG_subprogram, context_die);
       add_abstract_origin_attribute (subr_die, origin);
     }
@@ -8371,7 +8167,6 @@ gen_subprogram_die (decl, context_die)
             we should detect this case and ignore it.  For now, if we have
             already reported an error, any error at all, then assume that
             we got here because of a input error, not a dwarf2 bug.  */
-         extern int errorcount;
          if (errorcount)
            return;
          abort ();
@@ -8383,12 +8178,13 @@ gen_subprogram_die (decl, context_die)
         debugger can find it.  For inlines, that is the concrete instance,
         so we can use the old DIE here.  For non-inline methods, we want a
         specification DIE at toplevel, so we need a new DIE.  For local
-        class methods, this does not apply.  */
+        class methods, this doesn't apply; we just use the old DIE.  */
       if ((DECL_ABSTRACT (decl) || old_die->die_parent == comp_unit_die
           || context_die == NULL)
-         && get_AT_unsigned (old_die, DW_AT_decl_file) == file_index
-         && (get_AT_unsigned (old_die, DW_AT_decl_line)
-             == (unsigned)DECL_SOURCE_LINE (decl)))
+         && (DECL_ARTIFICIAL (decl)
+             || (get_AT_unsigned (old_die, DW_AT_decl_file) == file_index
+                 && (get_AT_unsigned (old_die, DW_AT_decl_line)
+                     == (unsigned)DECL_SOURCE_LINE (decl)))))
        {
          subr_die = old_die;
 
@@ -8410,15 +8206,7 @@ gen_subprogram_die (decl, context_die)
     }
   else
     {
-      register dw_die_ref scope_die;
-
-      if (DECL_CONTEXT (decl))
-       scope_die = scope_die_for (decl, context_die);
-      else
-       /* Don't put block extern declarations under comp_unit_die.  */
-       scope_die = context_die;
-
-      subr_die = new_die (DW_TAG_subprogram, scope_die);
+      subr_die = new_die (DW_TAG_subprogram, context_die);
                         
       if (TREE_PUBLIC (decl))
        add_AT_flag (subr_die, DW_AT_external, 1);
@@ -8443,33 +8231,32 @@ gen_subprogram_die (decl, context_die)
 
   if (declaration)
     {
-      add_AT_flag (subr_die, DW_AT_declaration, 1);
+      if (! origin)
+       add_AT_flag (subr_die, DW_AT_declaration, 1);
 
       /* The first time we see a member function, it is in the context of
          the class to which it belongs.  We make sure of this by emitting
          the class first.  The next time is the definition, which is
          handled above.  The two may come from the same source text.  */
-      if (DECL_CONTEXT (decl))
+      if (DECL_CONTEXT (decl) || DECL_ABSTRACT (decl))
        equate_decl_number_to_die (decl, subr_die);
     }
   else if (DECL_ABSTRACT (decl))
     {
-      /* ??? Checking DECL_DEFER_OUTPUT is correct for static inline functions,
-        but not for extern inline functions.  We can't get this completely
-        correct because information about whether the function was declared
-        inline is not saved anywhere.  */
-      if (DECL_DEFER_OUTPUT (decl))
+      if (DECL_INLINE (decl) && !flag_no_inline)
        {
-         if (DECL_INLINE (decl))
+         /* ??? Checking DECL_DEFER_OUTPUT is correct for static
+            inline functions, but not for extern inline functions.
+            We can't get this completely correct because information
+            about whether the function was declared inline is not
+            saved anywhere.  */
+         if (DECL_DEFER_OUTPUT (decl))
            add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_inlined);
          else
-           add_AT_unsigned (subr_die, DW_AT_inline,
-                            DW_INL_declared_not_inlined);
+           add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined);
        }
-      else if (DECL_INLINE (decl))
-       add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined);
       else
-       abort ();
+       add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_not_inlined);
 
       equate_decl_number_to_die (decl, subr_die);
     }
@@ -8518,7 +8305,6 @@ gen_subprogram_die (decl, context_die)
      FUNCTION_TYPE. If the chain of type nodes hanging off of this
      FUNCTION_TYPE node ends with a void_type_node then there should *not* be 
      an ellipsis at the end.  */
-  push_decl_scope (decl);
 
   /* In the case where we are describing a mere function declaration, all we
      need to do here (and all we *can* do here) is to describe the *types* of 
@@ -8598,8 +8384,6 @@ gen_subprogram_die (decl, context_die)
        }
 #endif
     }
-
-  pop_decl_scope ();
 }
 
 /* Generate a DIE to represent a declared data object.  */
@@ -8613,11 +8397,8 @@ gen_variable_die (decl, context_die)
   register dw_die_ref var_die = new_die (DW_TAG_variable, context_die);
 
   dw_die_ref old_die = lookup_decl_die (decl);
-  int declaration
-    = (DECL_EXTERNAL (decl)
-       || current_function_decl != decl_function_context (decl)
-       || context_die->die_tag == DW_TAG_structure_type
-       || context_die->die_tag == DW_TAG_union_type);
+  int declaration = (DECL_EXTERNAL (decl)
+                    || class_scope_p (context_die));
 
   if (origin != NULL)
     add_abstract_origin_attribute (var_die, origin);
@@ -8629,7 +8410,7 @@ gen_variable_die (decl, context_die)
   else if (old_die && TREE_STATIC (decl)
           && get_AT_flag (old_die, DW_AT_declaration) == 1)
     {
-      /* ??? This is an instantiation of a C++ class level static.  */
+      /* This is a definition of a C++ class level static.  */
       add_AT_die_ref (var_die, DW_AT_specification, old_die);
       if (DECL_NAME (decl))
        {
@@ -8669,12 +8450,11 @@ gen_variable_die (decl, context_die)
   if (declaration)
     add_AT_flag (var_die, DW_AT_declaration, 1);
   
-  if ((declaration && decl_class_context (decl)) || DECL_ABSTRACT (decl))
+  if (class_scope_p (context_die) || DECL_ABSTRACT (decl))
     equate_decl_number_to_die (decl, var_die);
 
   if (! declaration && ! DECL_ABSTRACT (decl))
     {
-      equate_decl_number_to_die (decl, var_die);
       add_location_or_const_value_attribute (var_die, decl);
       add_pubname (decl, var_die);
     }
@@ -8741,15 +8521,14 @@ gen_lexical_block_die (stmt, context_die, depth)
   if (! BLOCK_ABSTRACT (stmt))
     {
       ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
-                                  next_block_number);
+                                  BLOCK_NUMBER (stmt));
       add_AT_lbl_id (stmt_die, DW_AT_low_pc, label);
-      ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL, next_block_number);
+      ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
+                                  BLOCK_NUMBER (stmt));
       add_AT_lbl_id (stmt_die, DW_AT_high_pc, label);
     }
 
-  push_decl_scope (stmt);
   decls_for_scope (stmt, stmt_die, depth);
-  pop_decl_scope ();
 }
 
 /* Generate a DIE for an inlined subprogram.  */
@@ -8767,15 +8546,17 @@ gen_inlined_subroutine_die (stmt, context_die, depth)
       register tree decl = block_ultimate_origin (stmt);
       char label[MAX_ARTIFICIAL_LABEL_BYTES];
 
+      /* Emit info for the abstract instance first, if we haven't yet.  */
+      gen_abstract_function (decl);
+
       add_abstract_origin_attribute (subr_die, decl);
       ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
-                                  next_block_number);
+                                  BLOCK_NUMBER (stmt));
       add_AT_lbl_id (subr_die, DW_AT_low_pc, label);
-      ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL, next_block_number);
+      ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
+                                  BLOCK_NUMBER (stmt));
       add_AT_lbl_id (subr_die, DW_AT_high_pc, label);
-      push_decl_scope (decl);
       decls_for_scope (stmt, subr_die, depth);
-      pop_decl_scope ();
       current_function_has_inlines = 1;
     }
 }
@@ -8868,18 +8649,20 @@ gen_ptr_to_mbr_type_die (type, context_die)
 
 /* Generate the DIE for the compilation unit.  */
 
-static void
-gen_compile_unit_die (main_input_filename)
-     register char *main_input_filename;
+static dw_die_ref
+gen_compile_unit_die (filename)
+     register const char *filename;
 {
+  register dw_die_ref die;
   char producer[250];
   char *wd = getpwd ();
+  int language;
 
-  comp_unit_die = new_die (DW_TAG_compile_unit, NULL);
-  add_name_attribute (comp_unit_die, main_input_filename);
+  die = new_die (DW_TAG_compile_unit, NULL);
+  add_name_attribute (die, filename);
 
-  if (wd != NULL)
-    add_AT_string (comp_unit_die, DW_AT_comp_dir, wd);
+  if (wd != NULL && filename[0] != DIR_SEPARATOR)
+    add_AT_string (die, DW_AT_comp_dir, wd);
 
   sprintf (producer, "%s %s", language_string, version_string);
 
@@ -8894,30 +8677,24 @@ gen_compile_unit_die (main_input_filename)
     strcat (producer, " -g");
 #endif
 
-  add_AT_string (comp_unit_die, DW_AT_producer, producer);
+  add_AT_string (die, DW_AT_producer, producer);
 
   if (strcmp (language_string, "GNU C++") == 0)
-    add_AT_unsigned (comp_unit_die, DW_AT_language, DW_LANG_C_plus_plus);
-
+    language = DW_LANG_C_plus_plus;
   else if (strcmp (language_string, "GNU Ada") == 0)
-    add_AT_unsigned (comp_unit_die, DW_AT_language, DW_LANG_Ada83);
-
+    language = DW_LANG_Ada83;
   else if (strcmp (language_string, "GNU F77") == 0)
-    add_AT_unsigned (comp_unit_die, DW_AT_language, DW_LANG_Fortran77);
-
+    language = DW_LANG_Fortran77;
   else if (strcmp (language_string, "GNU Pascal") == 0)
-    add_AT_unsigned (comp_unit_die, DW_AT_language, DW_LANG_Pascal83);
-
+    language = DW_LANG_Pascal83;
   else if (flag_traditional)
-    add_AT_unsigned (comp_unit_die, DW_AT_language, DW_LANG_C);
-
+    language = DW_LANG_C;
   else
-    add_AT_unsigned (comp_unit_die, DW_AT_language, DW_LANG_C89);
+    language = DW_LANG_C89;
 
-#if 0 /* unimplemented */
-  if (debug_info_level >= DINFO_LEVEL_VERBOSE)
-    add_AT_unsigned (comp_unit_die, DW_AT_macro_info, 0);
-#endif
+  add_AT_unsigned (die, DW_AT_language, language);
+
+  return die;
 }
 
 /* Generate a DIE for a string type.  */
@@ -8967,6 +8744,7 @@ gen_member_die (type, context_die)
      register dw_die_ref context_die;
 {
   register tree member;
+  dw_die_ref child;
 
   /* If this is not an incomplete type, output descriptions of each of its
      members. Note that as we output the DIEs necessary to represent the
@@ -8994,14 +8772,33 @@ gen_member_die (type, context_die)
 
   /* Now output info about the data members and type members.  */
   for (member = TYPE_FIELDS (type); member; member = TREE_CHAIN (member))
-    gen_decl_die (member, context_die);
+    {
+      /* If we thought we were generating minimal debug info for TYPE
+        and then changed our minds, some of the member declarations
+        may have already been defined.  Don't define them again, but
+        do put them in the right order.  */
+
+      child = lookup_decl_die (member);
+      if (child)
+       splice_child_die (context_die, child);
+      else
+       gen_decl_die (member, context_die);
+    }
 
   /* Now output info about the function members (if any).  */
   for (member = TYPE_METHODS (type); member; member = TREE_CHAIN (member))
-    gen_decl_die (member, context_die);
+    {
+      child = lookup_decl_die (member);
+      if (child)
+       splice_child_die (context_die, child);
+      else
+       gen_decl_die (member, context_die);
+    }
 }
 
-/* Generate a DIE for a structure or union type.  */
+/* Generate a DIE for a structure or union type.  If TYPE_DECL_SUPPRESS_DEBUG
+   is set, we pretend that the type was never defined, so we only get the
+   member DIEs needed by later specification DIEs.  */
 
 static void
 gen_struct_or_union_type_die (type, context_die)
@@ -9011,8 +8808,11 @@ gen_struct_or_union_type_die (type, context_die)
   register dw_die_ref type_die = lookup_type_die (type);
   register dw_die_ref scope_die = 0;
   register int nested = 0;
+  int complete = (TYPE_SIZE (type)
+                 && (! TYPE_STUB_DECL (type)
+                     || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))));
 
-  if (type_die && ! TYPE_SIZE (type))
+  if (type_die && ! complete)
     return;
 
   if (TYPE_CONTEXT (type) != NULL_TREE
@@ -9037,16 +8837,9 @@ gen_struct_or_union_type_die (type, context_die)
   else
     remove_AT (type_die, DW_AT_declaration);
 
-  /* If we're not in the right context to be defining this type, defer to
-     avoid tricky recursion.  */
-  if (TYPE_SIZE (type) && decl_scope_depth > 0 && scope_die == comp_unit_die)
-    {
-      add_AT_flag (type_die, DW_AT_declaration, 1);
-      pend_type (type);
-    }
   /* If this type has been completed, then give it a byte_size attribute and
      then give a list of members.  */
-  else if (TYPE_SIZE (type))
+  if (complete)
     {
       /* Prevent infinite recursion in cases where the type of some member of 
          this type is expressed in terms of this type itself.  */
@@ -9077,7 +8870,10 @@ gen_struct_or_union_type_die (type, context_die)
   else
     {
       add_AT_flag (type_die, DW_AT_declaration, 1);
-      add_incomplete_type (type);
+
+      /* We don't need to do this for function-local types.  */
+      if (! decl_function_context (TYPE_STUB_DECL (type)))
+       add_incomplete_type (type);
     }
 }
 
@@ -9112,7 +8908,7 @@ gen_typedef_die (decl, context_die)
     return;
   TREE_ASM_WRITTEN (decl) = 1;
 
-  type_die = new_die (DW_TAG_typedef, scope_die_for (decl, context_die));
+  type_die = new_die (DW_TAG_typedef, context_die);
   origin = decl_ultimate_origin (decl);
   if (origin != NULL)
     add_abstract_origin_attribute (type_die, origin);
@@ -9142,6 +8938,8 @@ gen_type_die (type, context_die)
      register tree type;
      register dw_die_ref context_die;
 {
+  int need_pop;
+
   if (type == NULL_TREE || type == error_mark_node)
     return;
 
@@ -9230,29 +9028,35 @@ gen_type_die (type, context_die)
     case UNION_TYPE:
     case QUAL_UNION_TYPE:
       /* If this is a nested type whose containing class hasn't been
-        written out yet, writing it out will cover this one, too.  */
+        written out yet, writing it out will cover this one, too.
+         This does not apply to instantiations of member class templates;
+        they need to be added to the containing class as they are
+        generated.  FIXME: This hurts the idea of combining type decls
+         from multiple TUs, since we can't predict what set of template
+         instantiations we'll get.  */
       if (TYPE_CONTEXT (type)
          && AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
          && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
        {
          gen_type_die (TYPE_CONTEXT (type), context_die);
 
-         if (TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
+         if (TREE_ASM_WRITTEN (type))
            return;
 
          /* If that failed, attach ourselves to the stub.  */
          push_decl_scope (TYPE_CONTEXT (type));
          context_die = lookup_type_die (TYPE_CONTEXT (type));
+         need_pop = 1;
        }
+      else
+       need_pop = 0;
 
       if (TREE_CODE (type) == ENUMERAL_TYPE)
        gen_enumeration_type_die (type, context_die);
       else
        gen_struct_or_union_type_die (type, context_die);
 
-      if (TYPE_CONTEXT (type)
-         && AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
-         && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
+      if (need_pop)
        pop_decl_scope ();
 
       /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
@@ -9294,10 +9098,12 @@ gen_tagged_type_instantiation_die (type, context_die)
      this type (i.e. without any const or volatile qualifiers) so make sure
      that we have the main variant (i.e. the unqualified version) of this
      type now.  */
-  if (type != type_main_variant (type)
-      || !TREE_ASM_WRITTEN (type))
+  if (type != type_main_variant (type))
     abort ();
 
+  /* Do not check TREE_ASM_WRITTEN (type) as it may not be set if this is
+     an instance of an unresolved type.  */
+  
   switch (TREE_CODE (type))
     {
     case ERROR_MARK:
@@ -9337,7 +9143,8 @@ gen_block_die (stmt, context_die, depth)
 
   /* Ignore blocks never really used to make RTL.  */
 
-  if (stmt == NULL_TREE || !TREE_USED (stmt))
+  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
@@ -9420,9 +9227,6 @@ decls_for_scope (stmt, context_die, depth)
   if (stmt == NULL_TREE || ! TREE_USED (stmt))
     return;
 
-  if (!BLOCK_ABSTRACT (stmt) && depth > 0)
-    next_block_number++;
-
   /* Output the DIEs to represent all of the data objects and typedefs
      declared directly within this block but not within any nested
      sub-blocks.  Also, nested function and tag DIEs have been
@@ -9482,20 +9286,11 @@ gen_decl_die (decl, context_die)
 {
   register tree origin;
 
-  /* Make a note of the decl node we are going to be working on.  We may need 
-     to give the user the source coordinates of where it appeared in case we
-     notice (later on) that something about it looks screwy.  */
-  dwarf_last_decl = decl;
-
   if (TREE_CODE (decl) == ERROR_MARK)
     return;
 
-  /* If this ..._DECL node is marked to be ignored, then ignore it. But don't 
-     ignore a function definition, since that would screw up our count of
-     blocks, and that in turn will completely screw up the labels we will 
-     reference in subsequent DW_AT_low_pc and DW_AT_high_pc attributes (for
-     subsequent blocks).  */
-  if (DECL_IGNORED_P (decl) && TREE_CODE (decl) != FUNCTION_DECL)
+  /* If this ..._DECL node is marked to be ignored, then ignore it.  */
+  if (DECL_IGNORED_P (decl))
     return;
 
   switch (TREE_CODE (decl))
@@ -9509,23 +9304,28 @@ gen_decl_die (decl, context_die)
       /* Don't output any DIEs to represent mere function declarations,
         unless they are class members or explicit block externs.  */
       if (DECL_INITIAL (decl) == NULL_TREE && DECL_CONTEXT (decl) == NULL_TREE
-         && (current_function_decl == NULL_TREE || DECL_ARTIFICIAL (decl)))
+         && (current_function_decl == NULL_TREE || DECL_ARTIFICIAL (decl)))
        break;
 
+      /* Emit info for the abstract instance first, if we haven't yet.  */
+      origin = decl_ultimate_origin (decl);
+      if (origin)
+       gen_abstract_function (origin);
+
       if (debug_info_level > DINFO_LEVEL_TERSE)
        {
          /* Before we describe the FUNCTION_DECL itself, make sure that we
             have described its return type.  */
          gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
 
-         /* And its containing type.  */
-         origin = decl_class_context (decl);
-         if (origin != NULL_TREE)
-           gen_type_die (origin, context_die);
-
          /* And its virtual context.  */
          if (DECL_VINDEX (decl) != NULL_TREE)
            gen_type_die (DECL_CONTEXT (decl), context_die);
+
+         /* And its containing type.  */
+         origin = decl_class_context (decl);
+         if (origin != NULL_TREE)
+           gen_type_die_for_member (origin, decl, context_die);
        }
 
       /* Now output a DIE to represent the function itself.  */
@@ -9545,7 +9345,7 @@ gen_decl_die (decl, context_die)
          inline function) we have to generate a special (abbreviated)
          DW_TAG_structure_type, DW_TAG_union_type, or DW_TAG_enumeration_type 
          DIE here.  */
-      if (TYPE_DECL_IS_STUB (decl) && DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE)
+      if (TYPE_DECL_IS_STUB (decl) && decl_ultimate_origin (decl) != NULL_TREE)
        {
          gen_tagged_type_instantiation_die (TREE_TYPE (decl), context_die);
          break;
@@ -9576,7 +9376,7 @@ gen_decl_die (decl, context_die)
       /* And its containing type.  */
       origin = decl_class_context (decl);
       if (origin != NULL_TREE)
-       gen_type_die (origin, context_die);
+       gen_type_die_for_member (origin, decl, context_die);
 
       /* Now output the DIE to represent the data object itself.  This gets
          complicated because of the possibility that the VAR_DECL really
@@ -9605,11 +9405,39 @@ gen_decl_die (decl, context_die)
       gen_formal_parameter_die (decl, context_die);
       break;
 
+    case NAMESPACE_DECL:
+      /* Ignore for now.  */
+      break;
+
     default:
       abort ();
     }
 }
 \f
+/* Add Ada "use" clause information for SGI Workshop debugger.  */
+
+void
+dwarf2out_add_library_unit_info (filename, context_list)
+     const char *filename;
+     const char *context_list;
+{
+  unsigned int file_index;
+
+  if (filename != NULL)
+    {
+      dw_die_ref unit_die = new_die (DW_TAG_module, comp_unit_die);
+      tree context_list_decl 
+       = build_decl (LABEL_DECL, get_identifier (context_list),
+                     void_type_node);
+
+      TREE_PUBLIC (context_list_decl) = TRUE;
+      add_name_attribute (unit_die, context_list);
+      file_index = lookup_filename (filename);
+      add_AT_unsigned (unit_die, DW_AT_decl_file, file_index);
+      add_pubname (context_list_decl, unit_die);
+    }
+}
+
 /* Write the debugging output for DECL.  */
 
 void
@@ -9621,21 +9449,9 @@ dwarf2out_decl (decl)
   if (TREE_CODE (decl) == ERROR_MARK)
     return;
 
-  /* If this ..._DECL node is marked to be ignored, then ignore it.  We gotta 
-     hope that the node in question doesn't represent a function definition.
-     If it does, then totally ignoring it is bound to screw up our count of
-     blocks, and that in turn will completely screw up the labels we will 
-     reference in subsequent DW_AT_low_pc and DW_AT_high_pc attributes (for
-     subsequent blocks).  (It's too bad that BLOCK nodes don't carry their
-     own sequence numbers with them!) */
+  /* If this ..._DECL node is marked to be ignored, then ignore it.  */
   if (DECL_IGNORED_P (decl))
-    {
-      if (TREE_CODE (decl) == FUNCTION_DECL
-          && DECL_INITIAL (decl) != NULL)
-       abort ();
-
-      return;
-    }
+    return;
 
   switch (TREE_CODE (decl))
     {
@@ -9643,7 +9459,7 @@ dwarf2out_decl (decl)
       /* Ignore this FUNCTION_DECL if it refers to a builtin declaration of a 
          builtin function.  Explicit programmer-supplied declarations of
          these same functions should NOT be ignored however.  */
-      if (DECL_EXTERNAL (decl) && DECL_FUNCTION_CODE (decl))
+      if (DECL_EXTERNAL (decl) && DECL_BUILT_IN (decl))
        return;
 
       /* What we would really like to do here is to filter out all mere
@@ -9654,8 +9470,8 @@ dwarf2out_decl (decl)
          on within the current translation unit). So here we just ignore all
          file-scope function declarations which are not also definitions.  If 
          and when the debugger needs to know something about these functions,
-         it wil have to hunt around and find the DWARF information associated 
-         with the definition of the function. Note that we can't just check
+         it will have to hunt around and find the DWARF information associated 
+         with the definition of the function.  Note that we can't just check
          `DECL_EXTERNAL' to find out which FUNCTION_DECL nodes represent
          definitions and which ones represent mere declarations.  We have to
          check `DECL_INITIAL' instead. That's because the C front-end
@@ -9701,6 +9517,10 @@ dwarf2out_decl (decl)
       break;
 
     case TYPE_DECL:
+      /* Don't emit stubs for types unless they are needed by other DIEs.  */
+      if (TYPE_DECL_SUPPRESS_DEBUG (decl))
+       return;
+
       /* Don't bother trying to generate any DIEs to represent any of the
          normal built-in types for the language we are compiling.  */
       if (DECL_SOURCE_LINE (decl) == 0)
@@ -9731,7 +9551,6 @@ dwarf2out_decl (decl)
     }
 
   gen_decl_die (decl, context_die);
-  output_pending_types_for_scope (comp_unit_die);
 }
 
 /* Output a marker (i.e. a label) for the beginning of the generated code for
@@ -9756,6 +9575,33 @@ dwarf2out_end_block (blocknum)
   ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum);
 }
 
+/* We've decided not to emit any debugging information for BLOCK; make
+   sure that we don't end up with orphans as a result.  */
+
+void
+dwarf2out_ignore_block (block)
+     tree block;
+{
+  tree decl;
+  for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl))
+    {
+      dw_die_ref die;
+
+      if (TREE_CODE (decl) == FUNCTION_DECL)
+       die = lookup_decl_die (decl);
+      else if (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl))
+       die = lookup_type_die (TREE_TYPE (decl));
+      else
+       die = NULL;
+
+      /* Just give them a dummy value for parent so dwarf2out_finish
+        doesn't blow up; we would use add_child_die if we really
+        wanted to add them to comp_unit_die's children.  */
+      if (die && die->die_parent == 0)
+       die->die_parent = comp_unit_die;
+    }
+}
+
 /* Output a marker (i.e. a label) at a point in the assembly code which
    corresponds to a given source level label.  */
 
@@ -9787,7 +9633,7 @@ dwarf2out_label (insn)
 
 static unsigned
 lookup_filename (file_name)
-     char *file_name;
+     const char *file_name;
 {
   static unsigned last_file_lookup_index = 0;
   register unsigned i;
@@ -9829,18 +9675,43 @@ lookup_filename (file_name)
 
 void
 dwarf2out_line (filename, line)
-     register char *filename;
+     register const char *filename;
      register unsigned line;
 {
   if (debug_info_level >= DINFO_LEVEL_NORMAL)
     {
       function_section (current_function_decl);
 
-      if (DECL_SECTION_NAME (current_function_decl))
+      if (DWARF2_ASM_LINE_DEBUG_INFO)
+       {
+         static const char *lastfile;
+
+         /* Emit the .file and .loc directives understood by GNU as.  */
+         if (lastfile == 0 || strcmp (filename, lastfile))
+           {
+             if (lastfile == 0)
+               ggc_add_string_root ((char **) &lastfile, 1);
+
+             fprintf (asm_out_file, "\t.file 0 \"%s\"\n", filename);
+             lastfile = filename;
+           }
+
+         fprintf (asm_out_file, "\t.loc 0 %d 0\n", line);
+
+         /* Indicate that line number info exists.  */
+         ++line_info_table_in_use;
+
+         /* Indicate that multiple line number tables exist.  */
+         if (DECL_SECTION_NAME (current_function_decl))
+           ++separate_line_info_table_in_use;
+       }
+      else if (DECL_SECTION_NAME (current_function_decl))
        {
          register dw_separate_line_info_ref line_info;
          ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, SEPARATE_LINE_CODE_LABEL,
                                     separate_line_info_table_in_use);
+         if (flag_debug_asm)
+           fprintf (asm_out_file, "\t%s line %d", ASM_COMMENT_START, line);
          fputc ('\n', asm_out_file);
 
          /* expand the line info table if necessary */
@@ -9868,6 +9739,8 @@ dwarf2out_line (filename, line)
 
          ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, LINE_CODE_LABEL,
                                     line_info_table_in_use);
+         if (flag_debug_asm)
+           fprintf (asm_out_file, "\t%s line %d", ASM_COMMENT_START, line);
          fputc ('\n', asm_out_file);
 
          /* Expand the line info table if necessary.  */
@@ -9894,7 +9767,7 @@ dwarf2out_line (filename, line)
 
 void
 dwarf2out_start_source_file (filename)
-     register char *filename ATTRIBUTE_UNUSED;
+     register const char *filename ATTRIBUTE_UNUSED;
 {
 }
 
@@ -9913,7 +9786,7 @@ dwarf2out_end_source_file ()
 void
 dwarf2out_define (lineno, buffer)
      register unsigned lineno ATTRIBUTE_UNUSED;
-     register char *buffer ATTRIBUTE_UNUSED;
+     register const char *buffer ATTRIBUTE_UNUSED;
 {
   static int initialized = 0;
   if (!initialized)
@@ -9930,7 +9803,7 @@ dwarf2out_define (lineno, buffer)
 void
 dwarf2out_undef (lineno, buffer)
      register unsigned lineno ATTRIBUTE_UNUSED;
-     register char *buffer ATTRIBUTE_UNUSED;
+     register const char *buffer ATTRIBUTE_UNUSED;
 {
 }
 
@@ -9945,8 +9818,7 @@ dwarf2out_init (asm_out_file, main_input_filename)
   primary_filename = main_input_filename;
 
   /* Allocate the initial hunk of the file_table.  */
-  file_table = (char **) xmalloc (FILE_TABLE_INCREMENT * sizeof (char *));
-  bzero ((char *) file_table, FILE_TABLE_INCREMENT * sizeof (char *));
+  file_table = (char **) xcalloc (FILE_TABLE_INCREMENT, sizeof (char *));
   file_table_allocated = FILE_TABLE_INCREMENT;
 
   /* Skip the first entry - file numbers begin at 1.  */
@@ -9954,37 +9826,28 @@ dwarf2out_init (asm_out_file, main_input_filename)
 
   /* Allocate the initial hunk of the decl_die_table.  */
   decl_die_table
-    = (dw_die_ref *) xmalloc (DECL_DIE_TABLE_INCREMENT * sizeof (dw_die_ref));
-  bzero ((char *) decl_die_table,
-        DECL_DIE_TABLE_INCREMENT * sizeof (dw_die_ref));
+    = (dw_die_ref *) xcalloc (DECL_DIE_TABLE_INCREMENT, sizeof (dw_die_ref));
   decl_die_table_allocated = DECL_DIE_TABLE_INCREMENT;
   decl_die_table_in_use = 0;
 
   /* Allocate the initial hunk of the decl_scope_table.  */
   decl_scope_table
-    = (decl_scope_node *) xmalloc (DECL_SCOPE_TABLE_INCREMENT
-                                  * sizeof (decl_scope_node));
-  bzero ((char *) decl_scope_table,
-        DECL_SCOPE_TABLE_INCREMENT * sizeof (decl_scope_node));
+    = (tree *) xcalloc (DECL_SCOPE_TABLE_INCREMENT, sizeof (tree));
   decl_scope_table_allocated = DECL_SCOPE_TABLE_INCREMENT;
   decl_scope_depth = 0;
 
   /* Allocate the initial hunk of the abbrev_die_table.  */
   abbrev_die_table
-    = (dw_die_ref *) xmalloc (ABBREV_DIE_TABLE_INCREMENT
-                             * sizeof (dw_die_ref));
-  bzero ((char *) abbrev_die_table,
-        ABBREV_DIE_TABLE_INCREMENT * sizeof (dw_die_ref));
+    = (dw_die_ref *) xcalloc (ABBREV_DIE_TABLE_INCREMENT,
+                             sizeof (dw_die_ref));
   abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT;
   /* Zero-th entry is allocated, but unused */
   abbrev_die_table_in_use = 1;
 
   /* Allocate the initial hunk of the line_info_table.  */
   line_info_table
-    = (dw_line_info_ref) xmalloc (LINE_INFO_TABLE_INCREMENT
-                                 * sizeof (dw_line_info_entry));
-  bzero ((char *) line_info_table,
-        LINE_INFO_TABLE_INCREMENT * sizeof (dw_line_info_entry));
+    = (dw_line_info_ref) xcalloc (LINE_INFO_TABLE_INCREMENT,
+                                 sizeof (dw_line_info_entry));
   line_info_table_allocated = LINE_INFO_TABLE_INCREMENT;
   /* Zero-th entry is allocated, but unused */
   line_info_table_in_use = 1;
@@ -9994,11 +9857,20 @@ dwarf2out_init (asm_out_file, main_input_filename)
      will (typically) be a relative pathname and that this pathname should be 
      taken as being relative to the directory from which the compiler was
      invoked when the given (base) source file was compiled.  */
-  gen_compile_unit_die (main_input_filename);
+  comp_unit_die = gen_compile_unit_die (main_input_filename);
+
+  if (ggc_p)
+    {
+      VARRAY_RTX_INIT (used_rtx_varray, 32, "used_rtx_varray");
+      ggc_add_rtx_varray_root (&used_rtx_varray, 1);
+    }
 
   ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0);
   ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label, ABBREV_SECTION_LABEL, 0);
-  ASM_GENERATE_INTERNAL_LABEL (text_section_label, TEXT_SECTION_LABEL, 0);
+  if (DWARF2_GENERATE_TEXT_SECTION_LABEL)
+    ASM_GENERATE_INTERNAL_LABEL (text_section_label, TEXT_SECTION_LABEL, 0);
+  else
+    strcpy (text_section_label, stripattributes (TEXT_SECTION));
   ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label, 
                               DEBUG_INFO_SECTION_LABEL, 0);
   ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label, 
@@ -10006,8 +9878,11 @@ dwarf2out_init (asm_out_file, main_input_filename)
 
   ASM_OUTPUT_SECTION (asm_out_file, ABBREV_SECTION);
   ASM_OUTPUT_LABEL (asm_out_file, abbrev_section_label);
-  ASM_OUTPUT_SECTION (asm_out_file, TEXT_SECTION);
-  ASM_OUTPUT_LABEL (asm_out_file, text_section_label);
+  if (DWARF2_GENERATE_TEXT_SECTION_LABEL)
+    {
+      ASM_OUTPUT_SECTION (asm_out_file, TEXT_SECTION);
+      ASM_OUTPUT_LABEL (asm_out_file, text_section_label);
+    }
   ASM_OUTPUT_SECTION (asm_out_file, DEBUG_INFO_SECTION);
   ASM_OUTPUT_LABEL (asm_out_file, debug_info_section_label);
   ASM_OUTPUT_SECTION (asm_out_file, DEBUG_LINE_SECTION);
@@ -10022,7 +9897,6 @@ dwarf2out_finish ()
 {
   limbo_die_node *node, *next_node;
   dw_die_ref die;
-  dw_attr_ref a;
 
   /* Traverse the limbo die list, and add parent/child links.  The only
      dies without parents that should be here are concrete instances of
@@ -10036,23 +9910,24 @@ dwarf2out_finish ()
 
       if (die->die_parent == NULL)
        {
-         a = get_AT (die, DW_AT_abstract_origin);
-         if (a)
-           add_child_die (a->dw_attr_val.v.val_die_ref->die_parent, die);
+         dw_die_ref origin = get_AT_ref (die, DW_AT_abstract_origin);
+         if (origin)
+           add_child_die (origin->die_parent, die);
          else if (die == comp_unit_die)
-             ;
+           ;
          else
            abort ();
        }
       free (node);
     }
+  limbo_die_list = NULL;
 
   /* Walk through the list of incomplete types again, trying once more to
      emit full debugging info for them.  */
   retry_incomplete_types ();
 
-  /* Traverse the DIE tree and add sibling attributes to those DIE's
-     that have children.  */
+  /* Traverse the DIE's, reverse their lists of attributes and children,
+     and add add sibling attributes to those DIE's that have children.  */
   add_sibling_attributes (comp_unit_die);
 
   /* Output a terminator label for the .text section.  */
@@ -10075,9 +9950,12 @@ dwarf2out_finish ()
   /* Output the source line correspondence table.  */
   if (line_info_table_in_use > 1 || separate_line_info_table_in_use)
     {
-      fputc ('\n', asm_out_file);
-      ASM_OUTPUT_SECTION (asm_out_file, DEBUG_LINE_SECTION);
-      output_line_info ();
+      if (! DWARF2_ASM_LINE_DEBUG_INFO)
+       {
+         fputc ('\n', asm_out_file);
+         ASM_OUTPUT_SECTION (asm_out_file, DEBUG_LINE_SECTION);
+         output_line_info ();
+       }
 
       /* We can only use the low/high_pc attributes if all of the code
         was in .text.  */
@@ -10091,6 +9969,11 @@ dwarf2out_finish ()
                         debug_line_section_label);
     }
 
+#if 0 /* unimplemented */
+  if (debug_info_level >= DINFO_LEVEL_VERBOSE && primary)
+    add_AT_unsigned (die, DW_AT_macro_info, 0);
+#endif
+
   /* Output the abbreviation table.  */
   fputc ('\n', asm_out_file);
   ASM_OUTPUT_SECTION (asm_out_file, ABBREV_SECTION);
@@ -10115,6 +9998,8 @@ dwarf2out_finish ()
       output_pubnames ();
     }
 
+  /* We only put functions in the arange table, so don't write it out if
+     we don't have any.  */
   if (fde_table_in_use)
     {
       /* Output the address range information.  */