]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blobdiff - binutils/ieee.c
Change sources over to using GPLv3
[thirdparty/binutils-gdb.git] / binutils / ieee.c
index e1bef29136216698a4af4f9da9d89841d2044f09..0645db937810172983def62fe907287aaa974655 100644 (file)
@@ -1,12 +1,13 @@
 /* ieee.c -- Read and write IEEE-695 debugging information.
-   Copyright (C) 1996 Free Software Foundation, Inc.
+   Copyright 1996, 1998, 1999, 2000, 2001, 2002, 2003, 2006, 2007
+   Free Software Foundation, Inc.
    Written by Ian Lance Taylor <ian@cygnus.com>.
 
    This file is part of GNU Binutils.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2 of the License, or
+   the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.
 
    This program is distributed in the hope that it will be useful,
 
    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
-   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
-   02111-1307, USA.  */
+   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
+   02110-1301, USA.  */
 
 /* This file reads and writes IEEE-695 debugging information.  */
 
-#include <stdio.h>
+#include "sysdep.h"
 #include <assert.h>
-
 #include "bfd.h"
 #include "ieee.h"
-#include "bucomm.h"
 #include "libiberty.h"
 #include "debug.h"
 #include "budbg.h"
+#include "filenames.h"
 
 /* This structure holds an entry on the block stack.  */
 
@@ -39,6 +39,10 @@ struct ieee_block
   int kind;
   /* The source file name, for a BB5 block.  */
   const char *filename;
+  /* The index of the function type, for a BB4 or BB6 block.  */
+  unsigned int fnindx;
+  /* TRUE if this function is being skipped.  */
+  bfd_boolean skip;
 };
 
 /* This structure is the block stack.  */
@@ -63,6 +67,18 @@ struct ieee_var
   unsigned long namlen;
   /* Type.  */
   debug_type type;
+  /* Slot if we make an indirect type.  */
+  debug_type *pslot;
+  /* Kind of variable or function.  */
+  enum
+    {
+      IEEE_UNKNOWN,
+      IEEE_EXTERNAL,
+      IEEE_GLOBAL,
+      IEEE_STATIC,
+      IEEE_LOCAL,
+      IEEE_FUNCTION
+    } kind;
 };
 
 /* This structure holds all the variables.  */
@@ -84,6 +100,8 @@ struct ieee_type
   debug_type type;
   /* Slot if this is type is referenced before it is defined.  */
   debug_type *pslot;
+  /* Slots for arguments if we make indirect types for them.  */
+  debug_type *arg_slots;
   /* If this is a bitfield, this is the size in bits.  If this is not
      a bitfield, this is zero.  */
   unsigned long bitsize;
@@ -115,19 +133,10 @@ struct ieee_tag
   debug_type type;
   /* The tagged type is an indirect type pointing at this slot.  */
   debug_type slot;
-};
-
-/* This structure holds a linked list of functions with their argument
-   types, so that we can convert them to C++ methods if necessary.  */
-
-struct ieee_function
-{
-  /* Next function.  */
-  struct ieee_function *next;
-  /* This function name.  */
-  const char *name;
-  /* The function type.  */
-  debug_type type;
+  /* This is an array of slots used when a field type is converted
+     into a indirect type, in case it needs to be later converted into
+     a reference type.  */
+  debug_type *fslots;
 };
 
 /* This structure holds the information we pass around to the parsing
@@ -136,7 +145,7 @@ struct ieee_function
 struct ieee_info
 {
   /* The debugging handle.  */
-  PTR dhandle;
+  void *dhandle;
   /* The BFD.  */
   bfd *abfd;
   /* The start of the bytes to be parsed.  */
@@ -145,14 +154,18 @@ struct ieee_info
   const bfd_byte *pend;
   /* The block stack.  */
   struct ieee_blockstack blockstack;
+  /* Whether we have seen a BB1 or BB2.  */
+  bfd_boolean saw_filename;
   /* The variables.  */
   struct ieee_vars vars;
+  /* The global variables, after a global typedef block.  */
+  struct ieee_vars *global_vars;
   /* The types.  */
   struct ieee_types types;
+  /* The global types, after a global typedef block.  */
+  struct ieee_types *global_types;
   /* The list of tagged structs.  */
   struct ieee_tag *tags;
-  /* The list of functions.  */
-  struct ieee_function *functions;
 };
 
 /* Basic builtin types, not including the pointers.  */
@@ -235,52 +248,50 @@ enum builtin_types
 
 /* Local functions.  */
 
-static void ieee_error
-  PARAMS ((struct ieee_info *, const bfd_byte *, const char *));
-static void ieee_eof PARAMS ((struct ieee_info *));
-static char *savestring PARAMS ((const char *, unsigned long));
-static boolean ieee_read_number
-  PARAMS ((struct ieee_info *, const bfd_byte **, bfd_vma *));
-static boolean ieee_read_optional_number
-  PARAMS ((struct ieee_info *, const bfd_byte **, bfd_vma *, boolean *));
-static boolean ieee_read_id
-  PARAMS ((struct ieee_info *, const bfd_byte **, const char **,
-          unsigned long *));
-static boolean ieee_read_optional_id
-  PARAMS ((struct ieee_info *, const bfd_byte **, const char **,
-          unsigned long *, boolean *));
-static boolean ieee_read_expression
-  PARAMS ((struct ieee_info *, const bfd_byte **, bfd_vma *));
+static void ieee_error (struct ieee_info *, const bfd_byte *, const char *);
+static void ieee_eof (struct ieee_info *);
+static char *savestring (const char *, unsigned long);
+static bfd_boolean ieee_read_number
+  (struct ieee_info *, const bfd_byte **, bfd_vma *);
+static bfd_boolean ieee_read_optional_number
+  (struct ieee_info *, const bfd_byte **, bfd_vma *, bfd_boolean *);
+static bfd_boolean ieee_read_id
+  (struct ieee_info *, const bfd_byte **, const char **, unsigned long *);
+static bfd_boolean ieee_read_optional_id
+  (struct ieee_info *, const bfd_byte **, const char **, unsigned long *,
+   bfd_boolean *);
+static bfd_boolean ieee_read_expression
+  (struct ieee_info *, const bfd_byte **, bfd_vma *);
 static debug_type ieee_builtin_type
-  PARAMS ((struct ieee_info *, const bfd_byte *, unsigned int));
-static boolean ieee_alloc_type
-  PARAMS ((struct ieee_info *, unsigned int, boolean));
-static boolean ieee_read_type_index
-  PARAMS ((struct ieee_info *, const bfd_byte **, debug_type *));
-static int ieee_regno_to_genreg PARAMS ((bfd *, int));
-static int ieee_genreg_to_regno PARAMS ((bfd *, int));
-static boolean parse_ieee_bb PARAMS ((struct ieee_info *, const bfd_byte **));
-static boolean parse_ieee_be PARAMS ((struct ieee_info *, const bfd_byte **));
-static boolean parse_ieee_nn PARAMS ((struct ieee_info *, const bfd_byte **));
-static boolean parse_ieee_ty PARAMS ((struct ieee_info *, const bfd_byte **));
-static boolean parse_ieee_atn PARAMS ((struct ieee_info *, const bfd_byte **));
-static boolean ieee_read_cxx_misc
-  PARAMS ((struct ieee_info *, const bfd_byte **, unsigned long));
-static boolean ieee_read_cxx_class
-  PARAMS ((struct ieee_info *, const bfd_byte **, unsigned long));
-static boolean ieee_require_asn
-  PARAMS ((struct ieee_info *, const bfd_byte **, bfd_vma *));
-static boolean ieee_require_atn65
-  PARAMS ((struct ieee_info *, const bfd_byte **, const char **,
-          unsigned long *));
+  (struct ieee_info *, const bfd_byte *, unsigned int);
+static bfd_boolean ieee_alloc_type
+  (struct ieee_info *, unsigned int, bfd_boolean);
+static bfd_boolean ieee_read_type_index
+  (struct ieee_info *, const bfd_byte **, debug_type *);
+static int ieee_regno_to_genreg (bfd *, int);
+static int ieee_genreg_to_regno (bfd *, int);
+static bfd_boolean parse_ieee_bb (struct ieee_info *, const bfd_byte **);
+static bfd_boolean parse_ieee_be (struct ieee_info *, const bfd_byte **);
+static bfd_boolean parse_ieee_nn (struct ieee_info *, const bfd_byte **);
+static bfd_boolean parse_ieee_ty (struct ieee_info *, const bfd_byte **);
+static bfd_boolean parse_ieee_atn (struct ieee_info *, const bfd_byte **);
+static bfd_boolean ieee_read_cxx_misc
+  (struct ieee_info *, const bfd_byte **, unsigned long);
+static bfd_boolean ieee_read_cxx_class
+  (struct ieee_info *, const bfd_byte **, unsigned long);
+static bfd_boolean ieee_read_cxx_defaults
+  (struct ieee_info *, const bfd_byte **, unsigned long);
+static bfd_boolean ieee_read_reference
+  (struct ieee_info *, const bfd_byte **);
+static bfd_boolean ieee_require_asn
+  (struct ieee_info *, const bfd_byte **, bfd_vma *);
+static bfd_boolean ieee_require_atn65
+  (struct ieee_info *, const bfd_byte **, const char **, unsigned long *);
 
 /* Report an error in the IEEE debugging information.  */
 
 static void
-ieee_error (info, p, s)
-     struct ieee_info *info;
-     const bfd_byte *p;
-     const char *s;
+ieee_error (struct ieee_info *info, const bfd_byte *p, const char *s)
 {
   if (p != NULL)
     fprintf (stderr, "%s: 0x%lx: %s (0x%x)\n", bfd_get_filename (info->abfd),
@@ -292,19 +303,16 @@ ieee_error (info, p, s)
 /* Report an unexpected EOF in the IEEE debugging information.  */
 
 static void
-ieee_eof (info)
-     struct ieee_info *info;
+ieee_eof (struct ieee_info *info)
 {
   ieee_error (info, (const bfd_byte *) NULL,
-             "unexpected end of debugging information");
+             _("unexpected end of debugging information"));
 }
 
 /* Save a string in memory.  */
 
 static char *
-savestring (start, len)
-     const char *start;
-     unsigned long len;
+savestring (const char *start, unsigned long len)
 {
   char *ret;
 
@@ -316,24 +324,18 @@ savestring (start, len)
 
 /* Read a number which must be present in an IEEE file.  */
 
-static boolean
-ieee_read_number (info, pp, pv)
-     struct ieee_info *info;
-     const bfd_byte **pp;
-     bfd_vma *pv;
+static bfd_boolean
+ieee_read_number (struct ieee_info *info, const bfd_byte **pp, bfd_vma *pv)
 {
-  return ieee_read_optional_number (info, pp, pv, (boolean *) NULL);
+  return ieee_read_optional_number (info, pp, pv, (bfd_boolean *) NULL);
 }
 
 /* Read a number in an IEEE file.  If ppresent is not NULL, the number
-   need not be there. */
-
-static boolean
-ieee_read_optional_number (info, pp, pv, ppresent)
-     struct ieee_info *info;
-     const bfd_byte **pp;
-     bfd_vma *pv;
-     boolean *ppresent;
+   need not be there.  */
+
+static bfd_boolean
+ieee_read_optional_number (struct ieee_info *info, const bfd_byte **pp,
+                          bfd_vma *pv, bfd_boolean *ppresent)
 {
   ieee_record_enum_type b;
 
@@ -341,11 +343,11 @@ ieee_read_optional_number (info, pp, pv, ppresent)
     {
       if (ppresent != NULL)
        {
-         *ppresent = false;
-         return true;
+         *ppresent = FALSE;
+         return TRUE;
        }
       ieee_eof (info);
-      return false;
+      return FALSE;
     }
 
   b = (ieee_record_enum_type) **pp;
@@ -355,8 +357,8 @@ ieee_read_optional_number (info, pp, pv, ppresent)
     {
       *pv = (bfd_vma) b;
       if (ppresent != NULL)
-       *ppresent = true;
-      return true;
+       *ppresent = TRUE;
+      return TRUE;
     }
 
   if (b >= ieee_number_repeat_start_enum && b <= ieee_number_repeat_end_enum)
@@ -367,7 +369,7 @@ ieee_read_optional_number (info, pp, pv, ppresent)
       if (*pp + i - 1 >= info->pend)
        {
          ieee_eof (info);
-         return false;
+         return FALSE;
        }
 
       *pv = 0;
@@ -379,44 +381,38 @@ ieee_read_optional_number (info, pp, pv, ppresent)
        }
 
       if (ppresent != NULL)
-       *ppresent = true;
+       *ppresent = TRUE;
 
-      return true;
+      return TRUE;
     }
 
   if (ppresent != NULL)
     {
       --*pp;
-      *ppresent = false;
-      return true;
+      *ppresent = FALSE;
+      return TRUE;
     }
 
-  ieee_error (info, *pp - 1, "invalid number");
-  return false;  
+  ieee_error (info, *pp - 1, _("invalid number"));
+  return FALSE;
 }
 
 /* Read a required string from an IEEE file.  */
 
-static boolean
-ieee_read_id (info, pp, pname, pnamlen)
-     struct ieee_info *info;
-     const bfd_byte **pp;
-     const char **pname;
-     unsigned long *pnamlen;
+static bfd_boolean
+ieee_read_id (struct ieee_info *info, const bfd_byte **pp,
+             const char **pname, unsigned long *pnamlen)
 {
-  return ieee_read_optional_id (info, pp, pname, pnamlen, (boolean *) NULL);
+  return ieee_read_optional_id (info, pp, pname, pnamlen, (bfd_boolean *) NULL);
 }
 
 /* Read a string from an IEEE file.  If ppresent is not NULL, the
    string is optional.  */
 
-static boolean
-ieee_read_optional_id (info, pp, pname, pnamlen, ppresent)
-     struct ieee_info *info;
-     const bfd_byte **pp;
-     const char **pname;
-     unsigned long *pnamlen;
-     boolean *ppresent;
+static bfd_boolean
+ieee_read_optional_id (struct ieee_info *info, const bfd_byte **pp,
+                      const char **pname, unsigned long *pnamlen,
+                      bfd_boolean *ppresent)
 {
   bfd_byte b;
   unsigned long len;
@@ -424,7 +420,7 @@ ieee_read_optional_id (info, pp, pname, pnamlen, ppresent)
   if (*pp >= info->pend)
     {
       ieee_eof (info);
-      return false;
+      return FALSE;
     }
 
   b = **pp;
@@ -447,17 +443,17 @@ ieee_read_optional_id (info, pp, pname, pnamlen, ppresent)
       if (ppresent != NULL)
        {
          --*pp;
-         *ppresent = false;
-         return true;
+         *ppresent = FALSE;
+         return TRUE;
        }
-      ieee_error (info, *pp - 1, "invalid string length");
-      return false;
+      ieee_error (info, *pp - 1, _("invalid string length"));
+      return FALSE;
     }
 
   if ((unsigned long) (info->pend - *pp) < len)
     {
       ieee_eof (info);
-      return false;
+      return FALSE;
     }
 
   *pname = (const char *) *pp;
@@ -465,9 +461,9 @@ ieee_read_optional_id (info, pp, pname, pnamlen, ppresent)
   *pp += len;
 
   if (ppresent != NULL)
-    *ppresent = true;
+    *ppresent = TRUE;
 
-  return true;
+  return TRUE;
 }
 
 /* Read an expression from an IEEE file.  Since this code is only used
@@ -476,11 +472,9 @@ ieee_read_optional_id (info, pp, pname, pnamlen, ppresent)
    seen in debugging information.  This can be easily extended if
    necessary.  */
 
-static boolean
-ieee_read_expression (info, pp, pv)
-     struct ieee_info *info;
-     const bfd_byte **pp;
-     bfd_vma *pv;
+static bfd_boolean
+ieee_read_expression (struct ieee_info *info, const bfd_byte **pp,
+                     bfd_vma *pv)
 {
   const bfd_byte *expr_start;
 #define EXPR_STACK_SIZE (10)
@@ -495,20 +489,20 @@ ieee_read_expression (info, pp, pv)
     {
       const bfd_byte *start;
       bfd_vma val;
-      boolean present;
+      bfd_boolean present;
       ieee_record_enum_type c;
 
       start = *pp;
 
       if (! ieee_read_optional_number (info, pp, &val, &present))
-       return false;
+       return FALSE;
 
       if (present)
        {
          if (esp - expr_stack >= EXPR_STACK_SIZE)
            {
-             ieee_error (info, start, "expression stack overflow");
-             return false;
+             ieee_error (info, start, _("expression stack overflow"));
+             return FALSE;
            }
          *esp++ = val;
          continue;
@@ -527,7 +521,7 @@ ieee_read_expression (info, pp, pv)
       switch (c)
        {
        default:
-         ieee_error (info, start, "unsupported IEEE expression operator");
+         ieee_error (info, start, _("unsupported IEEE expression operator"));
          break;
 
        case ieee_variable_R_enum:
@@ -536,20 +530,20 @@ ieee_read_expression (info, pp, pv)
            asection *s;
 
            if (! ieee_read_number (info, pp, &indx))
-             return false;
+             return FALSE;
            for (s = info->abfd->sections; s != NULL; s = s->next)
              if ((bfd_vma) s->target_index == indx)
                break;
            if (s == NULL)
              {
-               ieee_error (info, start, "unknown section");
-               return false;
+               ieee_error (info, start, _("unknown section"));
+               return FALSE;
              }
-           
+
            if (esp - expr_stack >= EXPR_STACK_SIZE)
              {
-               ieee_error (info, start, "expression stack overflow");
-               return false;
+               ieee_error (info, start, _("expression stack overflow"));
+               return FALSE;
              }
 
            *esp++ = bfd_get_section_vma (info->abfd, s);
@@ -563,8 +557,8 @@ ieee_read_expression (info, pp, pv)
 
            if (esp - expr_stack < 2)
              {
-               ieee_error (info, start, "expression stack underflow");
-               return false;
+               ieee_error (info, start, _("expression stack underflow"));
+               return FALSE;
              }
 
            v1 = *--esp;
@@ -577,24 +571,22 @@ ieee_read_expression (info, pp, pv)
 
   if (esp - 1 != expr_stack)
     {
-      ieee_error (info, expr_start, "expression stack mismatch");
-      return false;
+      ieee_error (info, expr_start, _("expression stack mismatch"));
+      return FALSE;
     }
 
   *pv = *--esp;
 
-  return true;
+  return TRUE;
 }
 
 /* Return an IEEE builtin type.  */
 
 static debug_type
-ieee_builtin_type (info, p, indx)
-     struct ieee_info *info;
-     const bfd_byte *p;
-     unsigned int indx;
+ieee_builtin_type (struct ieee_info *info, const bfd_byte *p,
+                  unsigned int indx)
 {
-  PTR dhandle;
+  void *dhandle;
   debug_type type;
   const char *name;
 
@@ -616,7 +608,7 @@ ieee_builtin_type (info, p, indx)
   switch ((enum builtin_types) indx)
     {
     default:
-      ieee_error (info, p, "unknown builtin type");
+      ieee_error (info, p, _("unknown builtin type"));
       return NULL;
 
     case builtin_unknown:
@@ -630,42 +622,42 @@ ieee_builtin_type (info, p, indx)
       break;
 
     case builtin_signed_char:
-      type = debug_make_int_type (dhandle, 1, false);
+      type = debug_make_int_type (dhandle, 1, FALSE);
       name = "signed char";
       break;
 
     case builtin_unsigned_char:
-      type = debug_make_int_type (dhandle, 1, true);
+      type = debug_make_int_type (dhandle, 1, TRUE);
       name = "unsigned char";
       break;
 
     case builtin_signed_short_int:
-      type = debug_make_int_type (dhandle, 2, false);
+      type = debug_make_int_type (dhandle, 2, FALSE);
       name = "signed short int";
       break;
 
     case builtin_unsigned_short_int:
-      type = debug_make_int_type (dhandle, 2, true);
+      type = debug_make_int_type (dhandle, 2, TRUE);
       name = "unsigned short int";
       break;
 
     case builtin_signed_long:
-      type = debug_make_int_type (dhandle, 4, false);
+      type = debug_make_int_type (dhandle, 4, FALSE);
       name = "signed long";
       break;
 
     case builtin_unsigned_long:
-      type = debug_make_int_type (dhandle, 4, true);
+      type = debug_make_int_type (dhandle, 4, TRUE);
       name = "unsigned long";
       break;
 
     case builtin_signed_long_long:
-      type = debug_make_int_type (dhandle, 8, false);
+      type = debug_make_int_type (dhandle, 8, FALSE);
       name = "signed long long";
       break;
 
     case builtin_unsigned_long_long:
-      type = debug_make_int_type (dhandle, 8, true);
+      type = debug_make_int_type (dhandle, 8, TRUE);
       name = "unsigned long long";
       break;
 
@@ -699,70 +691,70 @@ ieee_builtin_type (info, p, indx)
                                    ieee_builtin_type (info, p,
                                                       ((unsigned int)
                                                        builtin_int)),
-                                   0, -1, true);
+                                   0, -1, TRUE);
       name = "QUOTED STRING";
       break;
 
     case builtin_instruction_address:
       /* FIXME: This should be a code address.  */
-      type = debug_make_int_type (dhandle, 4, true);
+      type = debug_make_int_type (dhandle, 4, TRUE);
       name = "instruction address";
       break;
 
     case builtin_int:
       /* FIXME: The size for this type should depend upon the
          processor.  */
-      type = debug_make_int_type (dhandle, 4, false);
+      type = debug_make_int_type (dhandle, 4, FALSE);
       name = "int";
       break;
 
     case builtin_unsigned:
       /* FIXME: The size for this type should depend upon the
          processor.  */
-      type = debug_make_int_type (dhandle, 4, true);
+      type = debug_make_int_type (dhandle, 4, TRUE);
       name = "unsigned";
       break;
 
     case builtin_unsigned_int:
       /* FIXME: The size for this type should depend upon the
          processor.  */
-      type = debug_make_int_type (dhandle, 4, true);
+      type = debug_make_int_type (dhandle, 4, TRUE);
       name = "unsigned int";
       break;
 
     case builtin_char:
-      type = debug_make_int_type (dhandle, 1, false);
+      type = debug_make_int_type (dhandle, 1, FALSE);
       name = "char";
       break;
 
     case builtin_long:
-      type = debug_make_int_type (dhandle, 4, false);
+      type = debug_make_int_type (dhandle, 4, FALSE);
       name = "long";
       break;
 
     case builtin_short:
-      type = debug_make_int_type (dhandle, 2, false);
+      type = debug_make_int_type (dhandle, 2, FALSE);
       name = "short";
       break;
 
     case builtin_unsigned_short:
-      type = debug_make_int_type (dhandle, 2, true);
+      type = debug_make_int_type (dhandle, 2, TRUE);
       name = "unsigned short";
       break;
 
     case builtin_short_int:
-      type = debug_make_int_type (dhandle, 2, false);
+      type = debug_make_int_type (dhandle, 2, FALSE);
       name = "short int";
       break;
 
     case builtin_signed_short:
-      type = debug_make_int_type (dhandle, 2, false);
+      type = debug_make_int_type (dhandle, 2, FALSE);
       name = "signed short";
       break;
 
     case builtin_bcd_float:
-      ieee_error (info, p, "BCD float type not supported");
-      return false;
+      ieee_error (info, p, _("BCD float type not supported"));
+      return DEBUG_TYPE_NULL;
     }
 
   if (name != NULL)
@@ -775,15 +767,12 @@ ieee_builtin_type (info, p, indx)
   return type;
 }
 
-/* Allocate more space in the type table.  If ref is true, this is a
+/* Allocate more space in the type table.  If ref is TRUE, this is a
    reference to the type; if it is not already defined, we should set
    up an indirect type.  */
 
-static boolean
-ieee_alloc_type (info, indx, ref)
-     struct ieee_info *info;
-     unsigned int indx;
-     boolean ref;
+static bfd_boolean
+ieee_alloc_type (struct ieee_info *info, unsigned int indx, bfd_boolean ref)
 {
   unsigned int nalloc;
   register struct ieee_type *t;
@@ -821,20 +810,18 @@ ieee_alloc_type (info, indx, ref)
          t->type = debug_make_indirect_type (info->dhandle, t->pslot,
                                              (const char *) NULL);
          if (t->type == NULL)
-           return false;
+           return FALSE;
        }
     }
 
-  return true;
+  return TRUE;
 }
 
 /* Read a type index and return the corresponding type.  */
 
-static boolean
-ieee_read_type_index (info, pp, ptype)
-     struct ieee_info *info;
-     const bfd_byte **pp;
-     debug_type *ptype;
+static bfd_boolean
+ieee_read_type_index (struct ieee_info *info, const bfd_byte **pp,
+                     debug_type *ptype)
 {
   const bfd_byte *start;
   bfd_vma indx;
@@ -842,34 +829,30 @@ ieee_read_type_index (info, pp, ptype)
   start = *pp;
 
   if (! ieee_read_number (info, pp, &indx))
-    return false;
+    return FALSE;
 
   if (indx < 256)
     {
       *ptype = ieee_builtin_type (info, start, indx);
       if (*ptype == NULL)
-       return false;
-      return true;
+       return FALSE;
+      return TRUE;
     }
 
   indx -= 256;
-  if (! ieee_alloc_type (info, indx, true))
-    return false;
+  if (! ieee_alloc_type (info, indx, TRUE))
+    return FALSE;
 
   *ptype = info->types.types[indx].type;
 
-  return true;
+  return TRUE;
 }
 
 /* Parse IEEE debugging information for a file.  This is passed the
    bytes which compose the Debug Information Part of an IEEE file.  */
 
-boolean
-parse_ieee (dhandle, abfd, bytes, len)
-     PTR dhandle;
-     bfd *abfd;
-     const bfd_byte *bytes;
-     bfd_size_type len;
+bfd_boolean
+parse_ieee (void *dhandle, bfd *abfd, const bfd_byte *bytes, bfd_size_type len)
 {
   struct ieee_info info;
   unsigned int i;
@@ -880,12 +863,14 @@ parse_ieee (dhandle, abfd, bytes, len)
   info.bytes = bytes;
   info.pend = bytes + len;
   info.blockstack.bsp = info.blockstack.stack;
+  info.saw_filename = FALSE;
   info.vars.alloc = 0;
   info.vars.vars = NULL;
+  info.global_vars = NULL;
   info.types.alloc = 0;
   info.types.types = NULL;
+  info.global_types = NULL;
   info.tags = NULL;
-  info.functions = NULL;
   for (i = 0; i < BUILTIN_TYPE_COUNT; i++)
     info.types.builtins[i] = DEBUG_TYPE_NULL;
 
@@ -905,39 +890,39 @@ parse_ieee (dhandle, abfd, bytes, len)
 
       if (c <= ieee_number_repeat_end_enum)
        {
-         ieee_error (&info, record_start, "unexpected number");
-         return false;
+         ieee_error (&info, record_start, _("unexpected number"));
+         return FALSE;
        }
 
       switch (c)
        {
        default:
-         ieee_error (&info, record_start, "unexpected record type");
-         return false;
+         ieee_error (&info, record_start, _("unexpected record type"));
+         return FALSE;
 
        case ieee_bb_record_enum:
          if (! parse_ieee_bb (&info, &p))
-           return false;
+           return FALSE;
          break;
 
        case ieee_be_record_enum:
          if (! parse_ieee_be (&info, &p))
-           return false;
+           return FALSE;
          break;
 
        case ieee_nn_record:
          if (! parse_ieee_nn (&info, &p))
-           return false;
+           return FALSE;
          break;
 
        case ieee_ty_record_enum:
          if (! parse_ieee_ty (&info, &p))
-           return false;
+           return FALSE;
          break;
 
        case ieee_atn_record_enum:
          if (! parse_ieee_atn (&info, &p))
-           return false;
+           return FALSE;
          break;
        }
     }
@@ -945,27 +930,27 @@ parse_ieee (dhandle, abfd, bytes, len)
   if (info.blockstack.bsp != info.blockstack.stack)
     {
       ieee_error (&info, (const bfd_byte *) NULL,
-                 "blocks left on stack at end");
-      return false;
+                 _("blocks left on stack at end"));
+      return FALSE;
     }
 
-  return true;
+  return TRUE;
 }
 
 /* Handle an IEEE BB record.  */
 
-static boolean
-parse_ieee_bb (info, pp)
-     struct ieee_info *info;
-     const bfd_byte **pp;
+static bfd_boolean
+parse_ieee_bb (struct ieee_info *info, const bfd_byte **pp)
 {
   const bfd_byte *block_start;
   bfd_byte b;
   bfd_vma size;
   const char *name;
   unsigned long namlen;
-  char *namcopy;
-           
+  char *namcopy = NULL;
+  unsigned int fnindx;
+  bfd_boolean skip;
+
   block_start = *pp;
 
   b = **pp;
@@ -973,7 +958,10 @@ parse_ieee_bb (info, pp)
 
   if (! ieee_read_number (info, pp, &size)
       || ! ieee_read_id (info, pp, &name, &namlen))
-    return false;
+    return FALSE;
+
+  fnindx = (unsigned int) -1;
+  skip = FALSE;
 
   switch (b)
     {
@@ -981,16 +969,40 @@ parse_ieee_bb (info, pp)
       /* BB1: Type definitions local to a module.  */
       namcopy = savestring (name, namlen);
       if (namcopy == NULL)
-       return false;
+       return FALSE;
       if (! debug_set_filename (info->dhandle, namcopy))
-       return false;
+       return FALSE;
+      info->saw_filename = TRUE;
+
+      /* Discard any variables or types we may have seen before.  */
+      if (info->vars.vars != NULL)
+       free (info->vars.vars);
+      info->vars.vars = NULL;
+      info->vars.alloc = 0;
+      if (info->types.types != NULL)
+       free (info->types.types);
+      info->types.types = NULL;
+      info->types.alloc = 0;
+
+      /* Initialize the types to the global types.  */
+      if (info->global_types != NULL)
+       {
+         info->types.alloc = info->global_types->alloc;
+         info->types.types = ((struct ieee_type *)
+                              xmalloc (info->types.alloc
+                                       * sizeof (*info->types.types)));
+         memcpy (info->types.types, info->global_types->types,
+                 info->types.alloc * sizeof (*info->types.types));
+       }
+
       break;
 
     case 2:
       /* BB2: Global type definitions.  The name is supposed to be
-        empty, but we don't check. */
+        empty, but we don't check.  */
       if (! debug_set_filename (info->dhandle, "*global*"))
-       return false;
+       return FALSE;
+      info->saw_filename = TRUE;
       break;
 
     case 3:
@@ -1003,49 +1015,40 @@ parse_ieee_bb (info, pp)
       /* BB4: Global function.  */
       {
        bfd_vma stackspace, typindx, offset;
-       debug_type type, return_type;
-       struct ieee_function *func;
+       debug_type return_type;
 
        if (! ieee_read_number (info, pp, &stackspace)
            || ! ieee_read_number (info, pp, &typindx)
            || ! ieee_read_expression (info, pp, &offset))
-         return false;
+         return FALSE;
 
        /* We have no way to record the stack space.  FIXME.  */
 
        if (typindx < 256)
          {
-           type = ieee_builtin_type (info, block_start, typindx);
-           if (type == NULL)
-             return false;
-           return_type = type;
+           return_type = ieee_builtin_type (info, block_start, typindx);
+           if (return_type == DEBUG_TYPE_NULL)
+             return FALSE;
          }
        else
          {
            typindx -= 256;
-           if (! ieee_alloc_type (info, typindx, true))
-             return false;
-           type = info->types.types[typindx].type;
-           if (debug_get_type_kind (info->dhandle, type)
-               != DEBUG_KIND_FUNCTION)
-             return_type = type;
-           else
-             return_type = debug_get_return_type (info->dhandle, type);
+           if (! ieee_alloc_type (info, typindx, TRUE))
+             return FALSE;
+           fnindx = typindx;
+           return_type = info->types.types[typindx].type;
+           if (debug_get_type_kind (info->dhandle, return_type)
+               == DEBUG_KIND_FUNCTION)
+             return_type = debug_get_return_type (info->dhandle,
+                                                  return_type);
          }
 
        namcopy = savestring (name, namlen);
        if (namcopy == NULL)
-         return false;
+         return FALSE;
        if (! debug_record_function (info->dhandle, namcopy, return_type,
-                                    true, offset))
-         return false;
-
-       func = (struct ieee_function *) xmalloc (sizeof *func);
-       memset (func, 0, sizeof *func);
-       func->next = info->functions;
-       info->functions = func;
-       func->name = namcopy;
-       func->type = type;
+                                    TRUE, offset))
+         return FALSE;
       }
       break;
 
@@ -1058,19 +1061,19 @@ parse_ieee_bb (info, pp)
        for (i = 0; i < 6; i++)
          {
            bfd_vma ignore;
-           boolean present;
+           bfd_boolean present;
 
            if (! ieee_read_optional_number (info, pp, &ignore, &present))
-             return false;
+             return FALSE;
            if (! present)
              break;
          }
 
        namcopy = savestring (name, namlen);
        if (namcopy == NULL)
-         return false;
+         return FALSE;
        if (! debug_start_source (info->dhandle, namcopy))
-         return false;
+         return FALSE;
       }
       break;
 
@@ -1082,70 +1085,92 @@ parse_ieee_bb (info, pp)
        if (! ieee_read_number (info, pp, &stackspace)
            || ! ieee_read_number (info, pp, &typindx)
            || ! ieee_read_expression (info, pp, &offset))
-         return false;
+         return FALSE;
 
        /* We have no way to record the stack space.  FIXME.  */
 
        if (namlen == 0)
          {
            if (! debug_start_block (info->dhandle, offset))
-             return false;
+             return FALSE;
            /* Change b to indicate that this is a block
               rather than a function.  */
            b = 0x86;
          }
        else
          {
-           debug_type return_type;
-
-           if (typindx < 256)
-             {
-               return_type = ieee_builtin_type (info, block_start, typindx);
-               if (return_type == NULL)
-                 return false;
-             }
+           /* The MRI C++ compiler will output a fake function named
+              __XRYCPP to hold C++ debugging information.  We skip
+              that function.  This is not crucial, but it makes
+              converting from IEEE to other debug formats work
+              better.  */
+           if (strncmp (name, "__XRYCPP", namlen) == 0)
+             skip = TRUE;
            else
              {
-               typindx -= 256;
-               if (! ieee_alloc_type (info, typindx, true))
-                 return false;
-               return_type = info->types.types[typindx].type;
-               if (debug_get_type_kind (info->dhandle, return_type)
-                   == DEBUG_KIND_FUNCTION)
-                 return_type = debug_get_return_type (info->dhandle,
-                                                      return_type);
-             }
+               debug_type return_type;
 
-           namcopy = savestring (name, namlen);
-           if (namcopy == NULL)
-             return false;
-           if (! debug_record_function (info->dhandle, namcopy, return_type,
-                                        false, offset))
-             return false;
+               if (typindx < 256)
+                 {
+                   return_type = ieee_builtin_type (info, block_start,
+                                                    typindx);
+                   if (return_type == NULL)
+                     return FALSE;
+                 }
+               else
+                 {
+                   typindx -= 256;
+                   if (! ieee_alloc_type (info, typindx, TRUE))
+                     return FALSE;
+                   fnindx = typindx;
+                   return_type = info->types.types[typindx].type;
+                   if (debug_get_type_kind (info->dhandle, return_type)
+                       == DEBUG_KIND_FUNCTION)
+                     return_type = debug_get_return_type (info->dhandle,
+                                                          return_type);
+                 }
+
+               namcopy = savestring (name, namlen);
+               if (namcopy == NULL)
+                 return FALSE;
+               if (! debug_record_function (info->dhandle, namcopy,
+                                            return_type, FALSE, offset))
+                 return FALSE;
+             }
          }
       }
       break;
 
     case 10:
-      /* BB10: Assembler module scope.  We completely ignore all this
-        information.  FIXME.  */
+      /* BB10: Assembler module scope.  In the normal case, we
+        completely ignore all this information.  FIXME.  */
       {
        const char *inam, *vstr;
        unsigned long inamlen, vstrlen;
        bfd_vma tool_type;
-       boolean present;
+       bfd_boolean present;
        unsigned int i;
 
+       if (! info->saw_filename)
+         {
+           namcopy = savestring (name, namlen);
+           if (namcopy == NULL)
+             return FALSE;
+           if (! debug_set_filename (info->dhandle, namcopy))
+             return FALSE;
+           info->saw_filename = TRUE;
+         }
+
        if (! ieee_read_id (info, pp, &inam, &inamlen)
            || ! ieee_read_number (info, pp, &tool_type)
            || ! ieee_read_optional_id (info, pp, &vstr, &vstrlen, &present))
-         return false;
+         return FALSE;
        for (i = 0; i < 6; i++)
          {
            bfd_vma ignore;
 
            if (! ieee_read_optional_number (info, pp, &ignore, &present))
-             return false;
+             return FALSE;
            if (! present)
              break;
          }
@@ -1157,19 +1182,19 @@ parse_ieee_bb (info, pp)
         information.  FIXME.  */
       {
        bfd_vma sectype, secindx, offset, map;
-       boolean present;
+       bfd_boolean present;
 
        if (! ieee_read_number (info, pp, &sectype)
            || ! ieee_read_number (info, pp, &secindx)
            || ! ieee_read_expression (info, pp, &offset)
            || ! ieee_read_optional_number (info, pp, &map, &present))
-         return false;
+         return FALSE;
       }
       break;
 
     default:
-      ieee_error (info, block_start, "unknown BB type");
-      return false;
+      ieee_error (info, block_start, _("unknown BB type"));
+      return FALSE;
     }
 
 
@@ -1177,51 +1202,85 @@ parse_ieee_bb (info, pp)
 
   if (info->blockstack.bsp >= info->blockstack.stack + BLOCKSTACK_SIZE)
     {
-      ieee_error (info, (const bfd_byte *) NULL, "stack overflow");
-      return false;
+      ieee_error (info, (const bfd_byte *) NULL, _("stack overflow"));
+      return FALSE;
     }
 
   info->blockstack.bsp->kind = b;
   if (b == 5)
     info->blockstack.bsp->filename = namcopy;
+  info->blockstack.bsp->fnindx = fnindx;
+  info->blockstack.bsp->skip = skip;
   ++info->blockstack.bsp;
 
-  return true;
+  return TRUE;
 }
 
 /* Handle an IEEE BE record.  */
 
-static boolean
-parse_ieee_be (info, pp)
-     struct ieee_info *info;
-     const bfd_byte **pp;
+static bfd_boolean
+parse_ieee_be (struct ieee_info *info, const bfd_byte **pp)
 {
   bfd_vma offset;
 
   if (info->blockstack.bsp <= info->blockstack.stack)
     {
-      ieee_error (info, *pp, "stack underflow");
-      return false;
+      ieee_error (info, *pp, _("stack underflow"));
+      return FALSE;
     }
   --info->blockstack.bsp;
 
   switch (info->blockstack.bsp->kind)
     {
+    case 2:
+      /* When we end the global typedefs block, we copy out the
+         contents of info->vars.  This is because the variable indices
+         may be reused in the local blocks.  However, we need to
+         preserve them so that we can locate a function returning a
+         reference variable whose type is named in the global typedef
+         block.  */
+      info->global_vars = ((struct ieee_vars *)
+                          xmalloc (sizeof *info->global_vars));
+      info->global_vars->alloc = info->vars.alloc;
+      info->global_vars->vars = ((struct ieee_var *)
+                                xmalloc (info->vars.alloc
+                                         * sizeof (*info->vars.vars)));
+      memcpy (info->global_vars->vars, info->vars.vars,
+             info->vars.alloc * sizeof (*info->vars.vars));
+
+      /* We also copy out the non builtin parts of info->types, since
+         the types are discarded when we start a new block.  */
+      info->global_types = ((struct ieee_types *)
+                           xmalloc (sizeof *info->global_types));
+      info->global_types->alloc = info->types.alloc;
+      info->global_types->types = ((struct ieee_type *)
+                                  xmalloc (info->types.alloc
+                                           * sizeof (*info->types.types)));
+      memcpy (info->global_types->types, info->types.types,
+             info->types.alloc * sizeof (*info->types.types));
+      memset (info->global_types->builtins, 0,
+             sizeof (info->global_types->builtins));
+
+      break;
+
     case 4:
     case 6:
       if (! ieee_read_expression (info, pp, &offset))
-       return false;
-      if (! debug_end_function (info->dhandle, offset))
-       return false;
+       return FALSE;
+      if (! info->blockstack.bsp->skip)
+       {
+         if (! debug_end_function (info->dhandle, offset + 1))
+           return FALSE;
+       }
       break;
 
     case 0x86:
       /* This is BE6 when BB6 started a block rather than a local
         function.  */
       if (! ieee_read_expression (info, pp, &offset))
-       return false;
-      if (! debug_end_block (info->dhandle, offset))
-       return false;
+       return FALSE;
+      if (! debug_end_block (info->dhandle, offset + 1))
+       return FALSE;
       break;
 
     case 5:
@@ -1238,7 +1297,7 @@ parse_ieee_be (info, pp)
              if (bl->kind == 5)
                {
                  if (! debug_start_source (info->dhandle, bl->filename))
-                   return false;
+                   return FALSE;
                  break;
                }
            }
@@ -1248,7 +1307,7 @@ parse_ieee_be (info, pp)
 
     case 11:
       if (! ieee_read_expression (info, pp, &offset))
-       return false;
+       return FALSE;
       /* We just ignore the module size.  FIXME.  */
       break;
 
@@ -1257,15 +1316,13 @@ parse_ieee_be (info, pp)
       break;
     }
 
-  return true;
+  return TRUE;
 }
 
 /* Parse an NN record.  */
 
-static boolean
-parse_ieee_nn (info, pp)
-     struct ieee_info *info;
-     const bfd_byte **pp;
+static bfd_boolean
+parse_ieee_nn (struct ieee_info *info, const bfd_byte **pp)
 {
   const bfd_byte *nn_start;
   bfd_vma varindx;
@@ -1276,12 +1333,12 @@ parse_ieee_nn (info, pp)
 
   if (! ieee_read_number (info, pp, &varindx)
       || ! ieee_read_id (info, pp, &name, &namlen))
-    return false;
+    return FALSE;
 
   if (varindx < 32)
     {
-      ieee_error (info, nn_start, "illegal variable index");
-      return false;
+      ieee_error (info, nn_start, _("illegal variable index"));
+      return FALSE;
     }
   varindx -= 32;
 
@@ -1305,78 +1362,78 @@ parse_ieee_nn (info, pp)
   info->vars.vars[varindx].name = name;
   info->vars.vars[varindx].namlen = namlen;
 
-  return true;
+  return TRUE;
 }
 
 /* Parse a TY record.  */
 
-static boolean
-parse_ieee_ty (info, pp)
-     struct ieee_info *info;
-     const bfd_byte **pp;
+static bfd_boolean
+parse_ieee_ty (struct ieee_info *info, const bfd_byte **pp)
 {
   const bfd_byte *ty_start, *ty_var_start, *ty_code_start;
   bfd_vma typeindx, varindx, tc;
-  PTR dhandle;
-  boolean tag, typdef;
+  void *dhandle;
+  bfd_boolean tag, typdef;
+  debug_type *arg_slots;
   unsigned long type_bitsize;
   debug_type type;
 
   ty_start = *pp;
 
   if (! ieee_read_number (info, pp, &typeindx))
-    return false;
+    return FALSE;
 
   if (typeindx < 256)
     {
-      ieee_error (info, ty_start, "illegal type index");
-      return false;
+      ieee_error (info, ty_start, _("illegal type index"));
+      return FALSE;
     }
 
   typeindx -= 256;
-  if (! ieee_alloc_type (info, typeindx, false))
-    return false;
+  if (! ieee_alloc_type (info, typeindx, FALSE))
+    return FALSE;
 
   if (**pp != 0xce)
     {
-      ieee_error (info, *pp, "unknown TY code");
-      return false;
+      ieee_error (info, *pp, _("unknown TY code"));
+      return FALSE;
     }
   ++*pp;
 
   ty_var_start = *pp;
 
   if (! ieee_read_number (info, pp, &varindx))
-    return false;
+    return FALSE;
 
   if (varindx < 32)
     {
-      ieee_error (info, ty_var_start, "illegal variable index");
-      return false;
+      ieee_error (info, ty_var_start, _("illegal variable index"));
+      return FALSE;
     }
   varindx -= 32;
 
   if (varindx >= info->vars.alloc || info->vars.vars[varindx].name == NULL)
     {
-      ieee_error (info, ty_var_start, "undefined variable in TY");
-      return false;
+      ieee_error (info, ty_var_start, _("undefined variable in TY"));
+      return FALSE;
     }
 
   ty_code_start = *pp;
 
   if (! ieee_read_number (info, pp, &tc))
-    return false;
+    return FALSE;
 
   dhandle = info->dhandle;
 
-  tag = false;
-  typdef = false;
+  tag = FALSE;
+  typdef = FALSE;
+  arg_slots = NULL;
   type_bitsize = 0;
   switch (tc)
     {
     default:
-      ieee_error (info, ty_code_start, "unknown TY code");
-      return false;
+      ieee_error (info, ty_code_start, _("unknown TY code"));
+      return FALSE;
 
     case '!':
       /* Unknown type, with size.  We treat it as int.  FIXME.  */
@@ -1384,8 +1441,8 @@ parse_ieee_ty (info, pp)
        bfd_vma size;
 
        if (! ieee_read_number (info, pp, &size))
-         return false;
-       type = debug_make_int_type (dhandle, size, false);
+         return FALSE;
+       type = debug_make_int_type (dhandle, size, FALSE);
       }
       break;
 
@@ -1399,14 +1456,14 @@ parse_ieee_ty (info, pp)
        if (! ieee_read_type_index (info, pp, &ele_type)
            || ! ieee_read_number (info, pp, &lower)
            || ! ieee_read_number (info, pp, &upper))
-         return false;
+         return FALSE;
        type = debug_make_array_type (dhandle, ele_type,
                                      ieee_builtin_type (info, ty_code_start,
                                                         ((unsigned int)
                                                          builtin_int)),
                                      (bfd_signed_vma) lower,
                                      (bfd_signed_vma) upper,
-                                     false);
+                                     FALSE);
       }
       break;
 
@@ -1421,7 +1478,7 @@ parse_ieee_ty (info, pp)
        unsigned int i;
 
        if (! ieee_read_number (info, pp, &size))
-         return false;
+         return FALSE;
        /* FIXME: we ignore the enumeration size.  */
 
        alloc = 10;
@@ -1432,10 +1489,10 @@ parse_ieee_ty (info, pp)
          {
            const char *name;
            unsigned long namlen;
-           boolean present;
+           bfd_boolean present;
 
            if (! ieee_read_optional_id (info, pp, &name, &namlen, &present))
-             return false;
+             return FALSE;
            if (! present)
              break;
 
@@ -1448,7 +1505,7 @@ parse_ieee_ty (info, pp)
 
            names[c] = savestring (name, namlen);
            if (names[c] == NULL)
-             return false;
+             return FALSE;
            ++c;
          }
 
@@ -1459,7 +1516,7 @@ parse_ieee_ty (info, pp)
          vals[i] = i;
 
        type = debug_make_enum_type (dhandle, names, vals);
-       tag = true;
+       tag = TRUE;
       }
       break;
 
@@ -1472,7 +1529,7 @@ parse_ieee_ty (info, pp)
        unsigned int c;
 
        if (! ieee_read_number (info, pp, &size))
-         return false;
+         return FALSE;
 
        alloc = 10;
        fields = (debug_field *) xmalloc (alloc * sizeof *fields);
@@ -1481,18 +1538,18 @@ parse_ieee_ty (info, pp)
          {
            const char *name;
            unsigned long namlen;
-           boolean present;
+           bfd_boolean present;
            debug_type ftype;
            bfd_vma bitpos, bitsize;
 
            if (! ieee_read_optional_id (info, pp, &name, &namlen, &present))
-             return false;
+             return FALSE;
            if (! present)
              break;
            if (! ieee_read_type_index (info, pp, &ftype)
                || ! ieee_read_number (info, pp, &bitpos)
                || ! ieee_read_number (info, pp, &bitsize))
-             return false;
+             return FALSE;
 
            if (c + 1 >= alloc)
              {
@@ -1505,14 +1562,14 @@ parse_ieee_ty (info, pp)
                                          ftype, bitpos, bitsize,
                                          DEBUG_VISIBILITY_PUBLIC);
            if (fields[c] == NULL)
-             return false;
+             return FALSE;
            ++c;
          }
 
        fields[c] = NULL;
 
-       type = debug_make_struct_type (dhandle, true, size, fields);
-       tag = true;
+       type = debug_make_struct_type (dhandle, TRUE, size, fields);
+       tag = TRUE;
       }
       break;
 
@@ -1532,15 +1589,15 @@ parse_ieee_ty (info, pp)
          {
            const char *name;
            unsigned long namlen;
-           boolean present;
+           bfd_boolean present;
            bfd_vma val;
 
            if (! ieee_read_optional_id (info, pp, &name, &namlen, &present))
-             return false;
+             return FALSE;
            if (! present)
              break;
            if (! ieee_read_number (info, pp, &val))
-             return false;
+             return FALSE;
 
            /* If the length of the name is zero, then the value is
                actually the size of the enum.  We ignore this
@@ -1559,7 +1616,7 @@ parse_ieee_ty (info, pp)
 
            names[c] = savestring (name, namlen);
            if (names[c] == NULL)
-             return false;
+             return FALSE;
            vals[c] = (bfd_signed_vma) val;
            ++c;
          }
@@ -1567,7 +1624,7 @@ parse_ieee_ty (info, pp)
        names[c] = NULL;
 
        type = debug_make_enum_type (dhandle, names, vals);
-       tag = true;
+       tag = TRUE;
       }
       break;
 
@@ -1578,7 +1635,7 @@ parse_ieee_ty (info, pp)
        debug_type t;
 
        if (! ieee_read_type_index (info, pp, &t))
-         return false;
+         return FALSE;
        type = debug_make_pointer_type (dhandle, t);
       }
       break;
@@ -1592,7 +1649,7 @@ parse_ieee_ty (info, pp)
            || ! ieee_read_number (info, pp, &high)
            || ! ieee_read_number (info, pp, &signedp)
            || ! ieee_read_number (info, pp, &size))
-         return false;
+         return FALSE;
 
        type = debug_make_range_type (dhandle,
                                      debug_make_int_type (dhandle, size,
@@ -1611,7 +1668,7 @@ parse_ieee_ty (info, pp)
        unsigned int c;
 
        if (! ieee_read_number (info, pp, &size))
-         return false;
+         return FALSE;
 
        alloc = 10;
        fields = (debug_field *) xmalloc (alloc * sizeof *fields);
@@ -1620,19 +1677,19 @@ parse_ieee_ty (info, pp)
          {
            const char *name;
            unsigned long namlen;
-           boolean present;
+           bfd_boolean present;
            bfd_vma tindx;
            bfd_vma offset;
            debug_type ftype;
            bfd_vma bitsize;
 
            if (! ieee_read_optional_id (info, pp, &name, &namlen, &present))
-             return false;
+             return FALSE;
            if (! present)
              break;
            if (! ieee_read_number (info, pp, &tindx)
                || ! ieee_read_number (info, pp, &offset))
-             return false;
+             return FALSE;
 
            if (tindx < 256)
              {
@@ -1645,8 +1702,8 @@ parse_ieee_ty (info, pp)
                struct ieee_type *t;
 
                tindx -= 256;
-               if (! ieee_alloc_type (info, tindx, true))
-                 return false;
+               if (! ieee_alloc_type (info, tindx, TRUE))
+                 return FALSE;
                t = info->types.types + tindx;
                ftype = t->type;
                bitsize = t->bitsize;
@@ -1665,22 +1722,22 @@ parse_ieee_ty (info, pp)
                                          ftype, offset, bitsize,
                                          DEBUG_VISIBILITY_PUBLIC);
            if (fields[c] == NULL)
-             return false;
+             return FALSE;
            ++c;
          }
 
        fields[c] = NULL;
 
        type = debug_make_struct_type (dhandle, tc == 'S', size, fields);
-       tag = true;
+       tag = TRUE;
       }
       break;
 
     case 'T':
       /* Typedef.  */
       if (! ieee_read_type_index (info, pp, &type))
-       return false;
-      typdef = true;
+       return FALSE;
+      typdef = TRUE;
       break;
 
     case 'X':
@@ -1690,29 +1747,49 @@ parse_ieee_ty (info, pp)
        bfd_vma attr;
        debug_type rtype;
        bfd_vma nargs;
-       boolean present;
+       bfd_boolean present;
+       struct ieee_var *pv;
 
        /* FIXME: We ignore the attribute and the argument names.  */
 
        if (! ieee_read_number (info, pp, &attr)
            || ! ieee_read_type_index (info, pp, &rtype)
            || ! ieee_read_number (info, pp, &nargs))
-         return false;
+         return FALSE;
        do
          {
            const char *name;
            unsigned long namlen;
 
            if (! ieee_read_optional_id (info, pp, &name, &namlen, &present))
-             return false;
+             return FALSE;
          }
        while (present);
 
+       pv = info->vars.vars + varindx;
+       pv->kind = IEEE_EXTERNAL;
+       if (pv->namlen > 0
+           && debug_get_type_kind (dhandle, rtype) == DEBUG_KIND_POINTER)
+         {
+           /* Set up the return type as an indirect type pointing to
+               the variable slot, so that we can change it to a
+               reference later if appropriate.  */
+           pv->pslot = (debug_type *) xmalloc (sizeof *pv->pslot);
+           *pv->pslot = rtype;
+           rtype = debug_make_indirect_type (dhandle, pv->pslot,
+                                             (const char *) NULL);
+         }
+
        type = debug_make_function_type (dhandle, rtype, (debug_type *) NULL,
-                                        false);
+                                        FALSE);
       }
       break;
 
+    case 'V':
+      /* Void.  This is not documented, but the MRI compiler emits it.  */
+      type = debug_make_void_type (dhandle);
+      break;
+
     case 'Z':
       /* Array with 0 lower bound.  */
       {
@@ -1721,13 +1798,13 @@ parse_ieee_ty (info, pp)
 
        if (! ieee_read_type_index (info, pp, &etype)
            || ! ieee_read_number (info, pp, &high))
-         return false;
+         return FALSE;
 
        type = debug_make_array_type (dhandle, etype,
                                      ieee_builtin_type (info, ty_code_start,
                                                         ((unsigned int)
                                                          builtin_int)),
-                                     0, (bfd_signed_vma) high, false);
+                                     0, (bfd_signed_vma) high, FALSE);
       }
       break;
 
@@ -1740,7 +1817,7 @@ parse_ieee_ty (info, pp)
        /* FIXME: I don't know what the name means.  */
 
        if (! ieee_read_id (info, pp, &name, &namlen))
-         return false;
+         return FALSE;
 
        type = debug_make_complex_type (dhandle, tc == 'c' ? 4 : 8);
       }
@@ -1748,22 +1825,37 @@ parse_ieee_ty (info, pp)
 
     case 'f':
       /* Pascal file name.  FIXME.  */
-      ieee_error (info, ty_code_start, "Pascal file name not supported");
-      return false;
+      ieee_error (info, ty_code_start, _("Pascal file name not supported"));
+      return FALSE;
 
     case 'g':
       /* Bitfield type.  */
       {
-       bfd_vma signedp, bitsize;
+       bfd_vma signedp, bitsize, dummy;
+       const bfd_byte *hold;
+       bfd_boolean present;
 
        if (! ieee_read_number (info, pp, &signedp)
-           || ! ieee_read_number (info, pp, &bitsize)
-           || ! ieee_read_type_index (info, pp, &type))
-         return false;
-
-       /* FIXME: This is just a guess.  */
-       if (! signedp)
-         type = debug_make_int_type (dhandle, 4, true);
+           || ! ieee_read_number (info, pp, &bitsize))
+         return FALSE;
+
+       /* I think the documentation says that there is a type index,
+           but some actual files do not have one.  */
+       hold = *pp;
+       if (! ieee_read_optional_number (info, pp, &dummy, &present))
+         return FALSE;
+       if (! present)
+         {
+           /* FIXME: This is just a guess.  */
+           type = debug_make_int_type (dhandle, 4,
+                                       signedp ? FALSE : TRUE);
+         }
+       else
+         {
+           *pp = hold;
+           if (! ieee_read_type_index (info, pp, &type))
+             return FALSE;
+         }
        type_bitsize = bitsize;
       }
       break;
@@ -1776,13 +1868,13 @@ parse_ieee_ty (info, pp)
 
        if (! ieee_read_number (info, pp, &kind)
            || ! ieee_read_type_index (info, pp, &t))
-         return false;
+         return FALSE;
 
        switch (kind)
          {
          default:
-           ieee_error (info, ty_start, "unsupported qualifer");
-           return false;
+           ieee_error (info, ty_start, _("unsupported qualifier"));
+           return FALSE;
 
          case 1:
            type = debug_make_const_type (dhandle, t);
@@ -1803,36 +1895,38 @@ parse_ieee_ty (info, pp)
 
        if (! ieee_read_number (info, pp, &size)
            || ! ieee_read_type_index (info, pp, &etype))
-         return false;
+         return FALSE;
 
        /* FIXME: We ignore the size.  */
 
-       type = debug_make_set_type (dhandle, etype, false);
+       type = debug_make_set_type (dhandle, etype, FALSE);
       }
       break;
 
     case 'x':
-      /* Procedure with compiler dependencies.  FIXME: This is an
-         extern declaration, which we have no way of representing.  */
+      /* Procedure with compiler dependencies.  */
       {
+       struct ieee_var *pv;
        bfd_vma attr, frame_type, push_mask, nargs, level, father;
        debug_type rtype;
        debug_type *arg_types;
-       boolean varargs;
-       boolean present;
+       bfd_boolean varargs;
+       bfd_boolean present;
+
+       /* FIXME: We ignore some of this information.  */
 
-       /* FIXME: We ignore almost all this information.  */
+       pv = info->vars.vars + varindx;
 
        if (! ieee_read_number (info, pp, &attr)
            || ! ieee_read_number (info, pp, &frame_type)
            || ! ieee_read_number (info, pp, &push_mask)
            || ! ieee_read_type_index (info, pp, &rtype)
            || ! ieee_read_number (info, pp, &nargs))
-         return false;
+         return FALSE;
        if (nargs == (bfd_vma) -1)
          {
            arg_types = NULL;
-           varargs = false;
+           varargs = FALSE;
          }
        else
          {
@@ -1842,11 +1936,11 @@ parse_ieee_ty (info, pp)
                         xmalloc ((nargs + 1) * sizeof *arg_types));
            for (i = 0; i < nargs; i++)
              if (! ieee_read_type_index (info, pp, arg_types + i))
-               return false;
+               return FALSE;
 
            /* If the last type is pointer to void, this is really a
                varargs function.  */
-           varargs = false;
+           varargs = FALSE;
            if (nargs > 0)
              {
                debug_type last;
@@ -1859,7 +1953,29 @@ parse_ieee_ty (info, pp)
                        == DEBUG_KIND_VOID))
                  {
                    --nargs;
-                   varargs = true;
+                   varargs = TRUE;
+                 }
+             }
+
+           /* If there are any pointer arguments, turn them into
+               indirect types in case we later need to convert them to
+               reference types.  */
+           for (i = 0; i < nargs; i++)
+             {
+               if (debug_get_type_kind (dhandle, arg_types[i])
+                   == DEBUG_KIND_POINTER)
+                 {
+                   if (arg_slots == NULL)
+                     {
+                       arg_slots = ((debug_type *)
+                                    xmalloc (nargs * sizeof *arg_slots));
+                       memset (arg_slots, 0, nargs * sizeof *arg_slots);
+                     }
+                   arg_slots[i] = arg_types[i];
+                   arg_types[i] =
+                     debug_make_indirect_type (dhandle,
+                                               arg_slots + i,
+                                               (const char *) NULL);
                  }
              }
 
@@ -1867,18 +1983,35 @@ parse_ieee_ty (info, pp)
          }
        if (! ieee_read_number (info, pp, &level)
            || ! ieee_read_optional_number (info, pp, &father, &present))
-         return false;
+         return FALSE;
+
+       /* We can't distinguish between a global function and a static
+           function.  */
+       pv->kind = IEEE_FUNCTION;
+
+       if (pv->namlen > 0
+           && debug_get_type_kind (dhandle, rtype) == DEBUG_KIND_POINTER)
+         {
+           /* Set up the return type as an indirect type pointing to
+               the variable slot, so that we can change it to a
+               reference later if appropriate.  */
+           pv->pslot = (debug_type *) xmalloc (sizeof *pv->pslot);
+           *pv->pslot = rtype;
+           rtype = debug_make_indirect_type (dhandle, pv->pslot,
+                                             (const char *) NULL);
+         }
 
        type = debug_make_function_type (dhandle, rtype, arg_types, varargs);
       }
       break;
     }
 
-  /* Record the type in the table.  If the corresponding NN record has
-     a name, name it.  FIXME: Is this always correct?  */
+  /* Record the type in the table.  */
 
-  if (type == NULL)
-    return false;
+  if (type == DEBUG_TYPE_NULL)
+    return FALSE;
+
+  info->vars.vars[varindx].type = type;
 
   if ((tag || typdef)
       && info->vars.vars[varindx].namlen > 0)
@@ -1912,10 +2045,11 @@ parse_ieee_ty (info, pp)
          it->type = type;
        }
       if (type == NULL)
-       return false;
+       return FALSE;
     }
 
   info->types.types[typeindx].type = type;
+  info->types.types[typeindx].arg_slots = arg_slots;
   info->types.types[typeindx].bitsize = type_bitsize;
 
   /* We may have already allocated type as an indirect type pointing
@@ -1925,99 +2059,162 @@ parse_ieee_ty (info, pp)
   if (info->types.types[typeindx].pslot != NULL)
     *info->types.types[typeindx].pslot = type;
 
-  return true;
+  return TRUE;
 }
 
 /* Parse an ATN record.  */
 
-static boolean
-parse_ieee_atn (info, pp)
-     struct ieee_info *info;
-     const bfd_byte **pp;
+static bfd_boolean
+parse_ieee_atn (struct ieee_info *info, const bfd_byte **pp)
 {
   const bfd_byte *atn_start, *atn_code_start;
   bfd_vma varindx;
-  boolean zeroindx;
+  struct ieee_var *pvar;
   debug_type type;
   bfd_vma atn_code;
-  PTR dhandle;
+  void *dhandle;
   bfd_vma v, v2, v3, v4, v5;
   const char *name;
   unsigned long namlen;
   char *namcopy;
-  boolean present;
+  bfd_boolean present;
   int blocktype;
 
   atn_start = *pp;
 
   if (! ieee_read_number (info, pp, &varindx)
       || ! ieee_read_type_index (info, pp, &type))
-    return false;
+    return FALSE;
 
   atn_code_start = *pp;
 
   if (! ieee_read_number (info, pp, &atn_code))
-    return false;
+    return FALSE;
 
   if (varindx == 0)
     {
-      zeroindx = true;
+      pvar = NULL;
       name = "";
       namlen = 0;
     }
   else if (varindx < 32)
     {
-      ieee_error (info, atn_start, "illegal variable index");
-      return false;
+      /* The MRI compiler reportedly sometimes emits variable lifetime
+         information for a register.  We just ignore it.  */
+      if (atn_code == 9)
+       return ieee_read_number (info, pp, &v);
+
+      ieee_error (info, atn_start, _("illegal variable index"));
+      return FALSE;
     }
   else
     {
       varindx -= 32;
-      zeroindx = false;
       if (varindx >= info->vars.alloc
          || info->vars.vars[varindx].name == NULL)
        {
-         ieee_error (info, atn_start, "undefined variable in ATN");
-         return false;
+         /* The MRI compiler or linker sometimes omits the NN record
+             for a pmisc record.  */
+         if (atn_code == 62)
+           {
+             if (varindx >= info->vars.alloc)
+               {
+                 unsigned int alloc;
+
+                 alloc = info->vars.alloc;
+                 if (alloc == 0)
+                   alloc = 4;
+                 while (varindx >= alloc)
+                   alloc *= 2;
+                 info->vars.vars = ((struct ieee_var *)
+                                    xrealloc (info->vars.vars,
+                                              (alloc
+                                               * sizeof *info->vars.vars)));
+                 memset (info->vars.vars + info->vars.alloc, 0,
+                         ((alloc - info->vars.alloc)
+                          * sizeof *info->vars.vars));
+                 info->vars.alloc = alloc;
+               }
+
+             pvar = info->vars.vars + varindx;
+             pvar->name = "";
+             pvar->namlen = 0;
+           }
+         else
+           {
+             ieee_error (info, atn_start, _("undefined variable in ATN"));
+             return FALSE;
+           }
        }
 
-      info->vars.vars[varindx].type = type;
+      pvar = info->vars.vars + varindx;
+
+      pvar->type = type;
 
-      name = info->vars.vars[varindx].name;
-      namlen = info->vars.vars[varindx].namlen;
+      name = pvar->name;
+      namlen = pvar->namlen;
     }
 
   dhandle = info->dhandle;
 
+  /* If we are going to call debug_record_variable with a pointer
+     type, change the type to an indirect type so that we can later
+     change it to a reference type if we encounter a C++ pmisc 'R'
+     record.  */
+  if (pvar != NULL
+      && type != DEBUG_TYPE_NULL
+      && debug_get_type_kind (dhandle, type) == DEBUG_KIND_POINTER)
+    {
+      switch (atn_code)
+       {
+       case 1:
+       case 2:
+       case 3:
+       case 5:
+       case 8:
+       case 10:
+         pvar->pslot = (debug_type *) xmalloc (sizeof *pvar->pslot);
+         *pvar->pslot = type;
+         type = debug_make_indirect_type (dhandle, pvar->pslot,
+                                          (const char *) NULL);
+         pvar->type = type;
+         break;
+       }
+    }
+
   switch (atn_code)
     {
     default:
-      ieee_error (info, atn_code_start, "unknown ATN type");
-      return false;
+      ieee_error (info, atn_code_start, _("unknown ATN type"));
+      return FALSE;
 
     case 1:
       /* Automatic variable.  */
       if (! ieee_read_number (info, pp, &v))
-       return false;
+       return FALSE;
       namcopy = savestring (name, namlen);
       if (type == NULL)
        type = debug_make_void_type (dhandle);
+      if (pvar != NULL)
+       pvar->kind = IEEE_LOCAL;
       return debug_record_variable (dhandle, namcopy, type, DEBUG_LOCAL, v);
 
     case 2:
       /* Register variable.  */
       if (! ieee_read_number (info, pp, &v))
-       return false;
+       return FALSE;
       namcopy = savestring (name, namlen);
       if (type == NULL)
        type = debug_make_void_type (dhandle);
+      if (pvar != NULL)
+       pvar->kind = IEEE_LOCAL;
       return debug_record_variable (dhandle, namcopy, type, DEBUG_REGISTER,
                                    ieee_regno_to_genreg (info->abfd, v));
 
     case 3:
       /* Static variable.  */
       if (! ieee_require_asn (info, pp, &v))
-       return false;
+       return FALSE;
       namcopy = savestring (name, namlen);
       if (type == NULL)
        type = debug_make_void_type (dhandle);
@@ -2025,6 +2222,13 @@ parse_ieee_atn (info, pp)
        blocktype = 0;
       else
        blocktype = info->blockstack.bsp[-1].kind;
+      if (pvar != NULL)
+       {
+         if (blocktype == 4 || blocktype == 6)
+           pvar->kind = IEEE_LOCAL;
+         else
+           pvar->kind = IEEE_STATIC;
+       }
       return debug_record_variable (dhandle, namcopy, type,
                                    (blocktype == 4 || blocktype == 6
                                     ? DEBUG_LOCAL_STATIC
@@ -2033,28 +2237,32 @@ parse_ieee_atn (info, pp)
 
     case 4:
       /* External function.  We don't currently record these.  FIXME.  */
-      return true;
+      if (pvar != NULL)
+       pvar->kind = IEEE_EXTERNAL;
+      return TRUE;
 
     case 5:
       /* External variable.  We don't currently record these.  FIXME.  */
-      return true;
+      if (pvar != NULL)
+       pvar->kind = IEEE_EXTERNAL;
+      return TRUE;
 
     case 7:
       if (! ieee_read_number (info, pp, &v)
          || ! ieee_read_number (info, pp, &v2)
          || ! ieee_read_optional_number (info, pp, &v3, &present))
-       return false;
+       return FALSE;
       if (present)
        {
          if (! ieee_read_optional_number (info, pp, &v4, &present))
-           return false;
+           return FALSE;
        }
 
       /* We just ignore the two optional fields in v3 and v4, since
          they are not defined.  */
 
       if (! ieee_require_asn (info, pp, &v3))
-       return false;
+       return FALSE;
 
       /* We have no way to record the column number.  FIXME.  */
 
@@ -2063,25 +2271,29 @@ parse_ieee_atn (info, pp)
     case 8:
       /* Global variable.  */
       if (! ieee_require_asn (info, pp, &v))
-       return false;
+       return FALSE;
       namcopy = savestring (name, namlen);
       if (type == NULL)
        type = debug_make_void_type (dhandle);
+      if (pvar != NULL)
+       pvar->kind = IEEE_GLOBAL;
       return debug_record_variable (dhandle, namcopy, type, DEBUG_GLOBAL, v);
 
     case 9:
       /* Variable lifetime information.  */
       if (! ieee_read_number (info, pp, &v))
-       return false;
+       return FALSE;
 
       /* We have no way to record this information.  FIXME.  */
-      return true;
+      return TRUE;
 
     case 10:
-      /* Locked register.  */
+      /* Locked register.  The spec says that there are two required
+         fields, but at least on occasion the MRI compiler only emits
+         one.  */
       if (! ieee_read_number (info, pp, &v)
-         || ! ieee_read_number (info, pp, &v2))
-       return false;
+         || ! ieee_read_optional_number (info, pp, &v2, &present))
+       return FALSE;
 
       /* I think this means a variable that is both in a register and
          a frame slot.  We ignore the frame slot.  FIXME.  */
@@ -2089,14 +2301,16 @@ parse_ieee_atn (info, pp)
       namcopy = savestring (name, namlen);
       if (type == NULL)
        type = debug_make_void_type (dhandle);
+      if (pvar != NULL)
+       pvar->kind = IEEE_LOCAL;
       return debug_record_variable (dhandle, namcopy, type, DEBUG_REGISTER, v);
 
     case 11:
       /* Reserved for FORTRAN common.  */
-      ieee_error (info, atn_code_start, "unsupported ATN11");
+      ieee_error (info, atn_code_start, _("unsupported ATN11"));
 
-      /* Return true to keep going.  */
-      return true;
+      /* Return TRUE to keep going.  */
+      return TRUE;
 
     case 12:
       /* Based variable.  */
@@ -2106,49 +2320,49 @@ parse_ieee_atn (info, pp)
       if (! ieee_read_number (info, pp, &v)
          || ! ieee_read_number (info, pp, &v2)
          || ! ieee_read_optional_number (info, pp, &v3, &present))
-       return false;
+       return FALSE;
       if (present)
        {
          if (! ieee_read_optional_number (info, pp, &v4, &present))
-           return false;
+           return FALSE;
          if (present)
            {
              if (! ieee_read_optional_number (info, pp, &v5, &present))
-               return false;
+               return FALSE;
            }
        }
 
       /* We have no way to record this information.  FIXME.  */
 
-      ieee_error (info, atn_code_start, "unsupported ATN12");
+      ieee_error (info, atn_code_start, _("unsupported ATN12"));
 
-      /* Return true to keep going.  */
-      return true;
+      /* Return TRUE to keep going.  */
+      return TRUE;
 
     case 16:
       /* Constant.  The description of this that I have is ambiguous,
          so I'm not going to try to implement it.  */
       if (! ieee_read_number (info, pp, &v)
          || ! ieee_read_optional_number (info, pp, &v2, &present))
-       return false;
+       return FALSE;
       if (present)
        {
          if (! ieee_read_optional_number (info, pp, &v2, &present))
-           return false;
+           return FALSE;
          if (present)
            {
              if (! ieee_read_optional_id (info, pp, &name, &namlen, &present))
-               return false;
+               return FALSE;
            }
        }
 
       if ((ieee_record_enum_type) **pp == ieee_e2_first_byte_enum)
        {
          if (! ieee_require_asn (info, pp, &v3))
-           return false;
+           return FALSE;
        }
 
-      return true;
+      return TRUE;
 
     case 19:
       /* Static variable from assembler.  */
@@ -2156,7 +2370,7 @@ parse_ieee_atn (info, pp)
       if (! ieee_read_number (info, pp, &v)
          || ! ieee_read_optional_number (info, pp, &v2, &present)
          || ! ieee_require_asn (info, pp, &v3))
-       return false;
+       return FALSE;
       namcopy = savestring (name, namlen);
       /* We don't really handle this correctly.  FIXME.  */
       return debug_record_variable (dhandle, namcopy,
@@ -2173,15 +2387,15 @@ parse_ieee_atn (info, pp)
       if (! ieee_read_number (info, pp, &v)
          || ! ieee_read_number (info, pp, &v2)
          || ! ieee_read_optional_id (info, pp, &name, &namlen, &present))
-       return false;
+       return FALSE;
 
       if (atn_code == 62 && v == 80)
        {
          if (present)
            {
              ieee_error (info, atn_code_start,
-                         "unexpected string in C++ misc");
-             return false;
+                         _("unexpected string in C++ misc"));
+             return FALSE;
            }
          return ieee_read_cxx_misc (info, pp, v2);
        }
@@ -2193,22 +2407,22 @@ parse_ieee_atn (info, pp)
          switch ((ieee_record_enum_type) **pp)
            {
            default:
-             ieee_error (info, *pp, "bad misc record");
-             return false;
+             ieee_error (info, *pp, _("bad misc record"));
+             return FALSE;
 
            case ieee_at_record_enum:
              if (! ieee_require_atn65 (info, pp, &name, &namlen))
-               return false;
+               return FALSE;
              break;
 
            case ieee_e2_first_byte_enum:
              if (! ieee_require_asn (info, pp, &v3))
-               return false;
+               return FALSE;
              break;
            }
        }
 
-      return true;
+      return TRUE;
     }
 
   /*NOTREACHED*/
@@ -2217,11 +2431,9 @@ parse_ieee_atn (info, pp)
 /* Handle C++ debugging miscellaneous records.  This is called for
    procedure miscellaneous records of type 80.  */
 
-static boolean
-ieee_read_cxx_misc (info, pp, count)
-     struct ieee_info *info;
-     const bfd_byte **pp;
-     unsigned long count;
+static bfd_boolean
+ieee_read_cxx_misc (struct ieee_info *info, const bfd_byte **pp,
+                   unsigned long count)
 {
   const bfd_byte *start;
   bfd_vma category;
@@ -2230,18 +2442,18 @@ ieee_read_cxx_misc (info, pp, count)
 
   /* Get the category of C++ misc record.  */
   if (! ieee_require_asn (info, pp, &category))
-    return false;
+    return FALSE;
   --count;
 
   switch (category)
     {
     default:
-      ieee_error (info, start, "unrecognized C++ misc record");
-      return false;
+      ieee_error (info, start, _("unrecognized C++ misc record"));
+      return FALSE;
 
     case 'T':
       if (! ieee_read_cxx_class (info, pp, count))
-       return false;
+       return FALSE;
       break;
 
     case 'M':
@@ -2255,12 +2467,12 @@ ieee_read_cxx_misc (info, pp, count)
            function.  */
 
        if (! ieee_require_asn (info, pp, &flags))
-         return false;
+         return FALSE;
        if (*pp < info->pend
            && (ieee_record_enum_type) **pp == ieee_at_record_enum)
          {
            if (! ieee_require_atn65 (info, pp, &name, &namlen))
-             return false;
+             return FALSE;
          }
 
        /* This is emitted for method functions, but I don't think we
@@ -2271,52 +2483,8 @@ ieee_read_cxx_misc (info, pp, count)
       break;
 
     case 'B':
-      {
-       const char *fnname, *strval;
-       unsigned long fnlen, strvallen;
-       bfd_vma count, type, val;
-
-       /* Specify default argument values.  We have no way to store
-           these, so we just ignore them.  FIXME.  */
-
-       /* Giving the function name before the argument count is an
-           addendum to the spec.  */
-       if (! ieee_require_atn65 (info, pp, &fnname, &fnlen)
-           || ! ieee_require_asn (info, pp, &count)
-           || ! ieee_require_asn (info, pp, &type))
-         return false;
-
-       switch (type)
-         {
-         case 0:
-         case 4:
-           break;
-
-         case 1:
-         case 2:
-           if (! ieee_require_asn (info, pp, &val))
-             return false;
-           break;
-
-         case 3:
-         case 7:
-           if (! ieee_require_atn65 (info, pp, &strval, &strvallen))
-             return false;
-           break;
-
-         default:
-           ieee_error (info, start, "unrecognized C++ B type");
-           return false;
-         }
-
-       while (count-- > 0)
-         {
-           bfd_vma pos;
-
-           if (! ieee_require_asn (info, pp, &pos))
-             return false;
-         }
-      }
+      if (! ieee_read_cxx_defaults (info, pp, count))
+       return FALSE;
       break;
 
     case 'z':
@@ -2331,59 +2499,34 @@ ieee_read_cxx_misc (info, pp, count)
            || ! ieee_require_atn65 (info, pp, &mangled, &mangledlen)
            || ! ieee_require_atn65 (info, pp, &class, &classlen)
            || ! ieee_require_asn (info, pp, &control))
-         return false;
+         return FALSE;
 
        /* FIXME: We should now track down name and change its type.  */
       }
       break;
 
     case 'R':
-      {
-       bfd_vma flags;
-       const char *class, *name;
-       unsigned long classlen, namlen;
-
-       /* Indicates that an object actually has reference type.  */
-
-       if (! ieee_require_asn (info, pp, &flags))
-         return false;
-
-       /* Giving the class name before the member name is in an
-           addendum to the spec.  */
-       if (flags == 3)
-         {
-           if (! ieee_require_atn65 (info, pp, &class, &classlen))
-             return false;
-         }
-
-       if (! ieee_require_atn65 (info, pp, &name, &namlen))
-         return false;
-
-       /* FIXME: Now we are supposed to track down the variable or
-           function or class member and convert the type into a
-           reference type.  */
-      }
+      if (! ieee_read_reference (info, pp))
+       return FALSE;
       break;
     }
 
-  return true;
+  return TRUE;
 }
 
 /* Read a C++ class definition.  This is a pmisc type 80 record of
    category 'T'.  */
 
-static boolean
-ieee_read_cxx_class (info, pp, count)
-     struct ieee_info *info;
-     const bfd_byte **pp;
-     unsigned long count;
+static bfd_boolean
+ieee_read_cxx_class (struct ieee_info *info, const bfd_byte **pp,
+                    unsigned long count)
 {
   const bfd_byte *start;
   bfd_vma class;
   const char *tag;
   unsigned long taglen;
   struct ieee_tag *it;
-  PTR dhandle;
+  void *dhandle;
   debug_field *fields;
   unsigned int field_count, field_alloc;
   debug_baseclass *baseclasses;
@@ -2399,17 +2542,17 @@ ieee_read_cxx_class (info, pp, count)
     } *methods;
   unsigned int methods_count, methods_alloc;
   debug_type vptrbase;
-  boolean ownvptr;
+  bfd_boolean ownvptr;
   debug_method *dmethods;
 
   start = *pp;
 
   if (! ieee_require_asn (info, pp, &class))
-    return false;
+    return FALSE;
   --count;
 
   if (! ieee_require_atn65 (info, pp, &tag, &taglen))
-    return false;
+    return FALSE;
   --count;
 
   /* Find the C struct with this name.  */
@@ -2420,8 +2563,8 @@ ieee_read_cxx_class (info, pp, count)
       break;
   if (it == NULL)
     {
-      ieee_error (info, start, "undefined C++ object");
-      return false;
+      ieee_error (info, start, _("undefined C++ object"));
+      return FALSE;
     }
 
   dhandle = info->dhandle;
@@ -2436,7 +2579,7 @@ ieee_read_cxx_class (info, pp, count)
   methods_count = 0;
   methods_alloc = 0;
   vptrbase = DEBUG_TYPE_NULL;
-  ownvptr = false;
+  ownvptr = FALSE;
 
   structfields = debug_get_fields (dhandle, it->type);
 
@@ -2448,14 +2591,14 @@ ieee_read_cxx_class (info, pp, count)
       spec_start = *pp;
 
       if (! ieee_require_asn (info, pp, &id))
-       return false;
+       return FALSE;
       --count;
 
       switch (id)
        {
        default:
-         ieee_error (info, spec_start, "unrecognized C++ object spec");
-         return false;
+         ieee_error (info, spec_start, _("unrecognized C++ object spec"));
+         return FALSE;
 
        case 'b':
          {
@@ -2465,7 +2608,7 @@ ieee_read_cxx_class (info, pp, count)
            char *basecopy;
            debug_type basetype;
            bfd_vma bitpos;
-           boolean virtualp;
+           bfd_boolean virtualp;
            enum debug_visibility visibility;
            debug_baseclass baseclass;
 
@@ -2475,7 +2618,7 @@ ieee_read_cxx_class (info, pp, count)
                || ! ieee_require_atn65 (info, pp, &basename, &baselen)
                || ! ieee_require_asn (info, pp, &cinline)
                || ! ieee_require_atn65 (info, pp, &fieldname, &fieldlen))
-             return false;
+             return FALSE;
            count -= 4;
 
            /* We have no way of recording friend information, so we
@@ -2490,8 +2633,8 @@ ieee_read_cxx_class (info, pp, count)
 
            if ((fieldlen == 0) == (cinline == 0))
              {
-               ieee_error (info, start, "unsupported C++ object type");
-               return false;
+               ieee_error (info, start, _("unsupported C++ object type"));
+               return FALSE;
              }
 
            basecopy = savestring (basename, baselen);
@@ -2500,8 +2643,8 @@ ieee_read_cxx_class (info, pp, count)
            free (basecopy);
            if (basetype == DEBUG_TYPE_NULL)
              {
-               ieee_error (info, start, "C++ base class not defined");
-               return false;
+               ieee_error (info, start, _("C++ base class not defined"));
+               return FALSE;
              }
 
            if (fieldlen == 0)
@@ -2512,8 +2655,8 @@ ieee_read_cxx_class (info, pp, count)
 
                if (structfields == NULL)
                  {
-                   ieee_error (info, start, "C++ object has no fields");
-                   return false;
+                   ieee_error (info, start, _("C++ object has no fields"));
+                   return FALSE;
                  }
 
                for (pf = structfields; *pf != DEBUG_FIELD_NULL; pf++)
@@ -2522,7 +2665,7 @@ ieee_read_cxx_class (info, pp, count)
 
                    fname = debug_get_field_name (dhandle, *pf);
                    if (fname == NULL)
-                     return false;
+                     return FALSE;
                    if (fname[0] == fieldname[0]
                        && strncmp (fname, fieldname, fieldlen) == 0
                        && strlen (fname) == fieldlen)
@@ -2531,17 +2674,17 @@ ieee_read_cxx_class (info, pp, count)
                if (*pf == DEBUG_FIELD_NULL)
                  {
                    ieee_error (info, start,
-                               "C++ base class not found in container");
-                   return false;
+                               _("C++ base class not found in container"));
+                   return FALSE;
                  }
 
                bitpos = debug_get_field_bitpos (dhandle, *pf);
              }
 
            if ((flags & BASEFLAGS_VIRTUAL) != 0)
-             virtualp = true;
+             virtualp = TRUE;
            else
-             virtualp = false;
+             virtualp = FALSE;
            if ((flags & BASEFLAGS_PRIVATE) != 0)
              visibility = DEBUG_VISIBILITY_PRIVATE;
            else
@@ -2550,7 +2693,7 @@ ieee_read_cxx_class (info, pp, count)
            baseclass = debug_make_baseclass (dhandle, basetype, bitpos,
                                              virtualp, visibility);
            if (baseclass == DEBUG_BASECLASS_NULL)
-             return false;
+             return FALSE;
 
            if (baseclasses_count + 1 >= baseclasses_alloc)
              {
@@ -2573,9 +2716,9 @@ ieee_read_cxx_class (info, pp, count)
            const char *fieldname, *mangledname;
            unsigned long fieldlen, mangledlen;
            char *fieldcopy;
-           boolean staticp;
+           bfd_boolean staticp;
            debug_type ftype;
-           const debug_field *pf;
+           const debug_field *pf = NULL;
            enum debug_visibility visibility;
            debug_field field;
 
@@ -2584,38 +2727,52 @@ ieee_read_cxx_class (info, pp, count)
            if (! ieee_require_asn (info, pp, &flags)
                || ! ieee_require_atn65 (info, pp, &fieldname, &fieldlen)
                || ! ieee_require_atn65 (info, pp, &mangledname, &mangledlen))
-             return false;
+             return FALSE;
            count -= 3;
 
            fieldcopy = savestring (fieldname, fieldlen);
 
-           staticp = (flags & CXXFLAGS_STATIC) != 0 ? true : false;
+           staticp = (flags & CXXFLAGS_STATIC) != 0 ? TRUE : FALSE;
 
            if (staticp)
              {
-               /* We can only figure out the type here if mangledname
-                   happens to have already been defined, but that is
-                   not necessarily the case.  In fact, it may never be
-                   defined.  For now, we don't even try.  FIXME.  */
-               pf = NULL;
-               ftype = ieee_builtin_type (info, start,
-                                          (unsigned int) builtin_void);
+               struct ieee_var *pv, *pvend;
+
+               /* See if we can find a definition for this variable.  */
+               pv = info->vars.vars;
+               pvend = pv + info->vars.alloc;
+               for (; pv < pvend; pv++)
+                 if (pv->namlen == mangledlen
+                     && strncmp (pv->name, mangledname, mangledlen) == 0)
+                   break;
+               if (pv < pvend)
+                 ftype = pv->type;
+               else
+                 {
+                   /* This can happen if the variable is never used.  */
+                   ftype = ieee_builtin_type (info, start,
+                                              (unsigned int) builtin_void);
+                 }
              }
            else
              {
+               unsigned int findx;
+
                if (structfields == NULL)
                  {
-                   ieee_error (info, start, "C++ object has no fields");
-                   return false;
+                   ieee_error (info, start, _("C++ object has no fields"));
+                   return FALSE;
                  }
 
-               for (pf = structfields; *pf != DEBUG_FIELD_NULL; pf++)
+               for (pf = structfields, findx = 0;
+                    *pf != DEBUG_FIELD_NULL;
+                    pf++, findx++)
                  {
                    const char *fname;
 
                    fname = debug_get_field_name (dhandle, *pf);
                    if (fname == NULL)
-                     return false;
+                     return FALSE;
                    if (fname[0] == mangledname[0]
                        && strncmp (fname, mangledname, mangledlen) == 0
                        && strlen (fname) == mangledlen)
@@ -2624,20 +2781,49 @@ ieee_read_cxx_class (info, pp, count)
                if (*pf == DEBUG_FIELD_NULL)
                  {
                    ieee_error (info, start,
-                               "C++ data member not found in container");
-                   return false;
+                               _("C++ data member not found in container"));
+                   return FALSE;
                  }
 
                ftype = debug_get_field_type (dhandle, *pf);
+
+               if (debug_get_type_kind (dhandle, ftype) == DEBUG_KIND_POINTER)
+                 {
+                   /* We might need to convert this field into a
+                       reference type later on, so make it an indirect
+                       type.  */
+                   if (it->fslots == NULL)
+                     {
+                       unsigned int fcnt;
+                       const debug_field *pfcnt;
+
+                       fcnt = 0;
+                       for (pfcnt = structfields;
+                            *pfcnt != DEBUG_FIELD_NULL;
+                            pfcnt++)
+                         ++fcnt;
+                       it->fslots = ((debug_type *)
+                                     xmalloc (fcnt * sizeof *it->fslots));
+                       memset (it->fslots, 0,
+                               fcnt * sizeof *it->fslots);
+                     }
+
+                   if (ftype == DEBUG_TYPE_NULL)
+                     return FALSE;
+                   it->fslots[findx] = ftype;
+                   ftype = debug_make_indirect_type (dhandle,
+                                                     it->fslots + findx,
+                                                     (const char *) NULL);
+                 }
              }
            if (ftype == DEBUG_TYPE_NULL)
-             return false;
+             return FALSE;
 
            switch (flags & CXXFLAGS_VISIBILITY)
              {
              default:
-               ieee_error (info, start, "unknown C++ visibility");
-               return false;
+               ieee_error (info, start, _("unknown C++ visibility"));
+               return FALSE;
 
              case CXXFLAGS_VISIBILITY_PUBLIC:
                visibility = DEBUG_VISIBILITY_PUBLIC;
@@ -2652,7 +2838,7 @@ ieee_read_cxx_class (info, pp, count)
                break;
              }
 
-           if ((flags & CXXFLAGS_STATIC) != 0)
+           if (staticp)
              {
                char *mangledcopy;
 
@@ -2670,15 +2856,15 @@ ieee_read_cxx_class (info, pp, count)
                bitsize = debug_get_field_bitsize (dhandle, *pf);
                if (bitpos == (bfd_vma) -1 || bitsize == (bfd_vma) -1)
                  {
-                   ieee_error (info, start, "bad C++ field bit pos or size");
-                   return false;
+                   ieee_error (info, start, _("bad C++ field bit pos or size"));
+                   return FALSE;
                  }
                field = debug_make_field (dhandle, fieldcopy, ftype, bitpos,
                                          bitsize, visibility);
              }
 
            if (field == DEBUG_FIELD_NULL)
-             return false;
+             return FALSE;
 
            if (field_count + 1 >= field_alloc)
              {
@@ -2696,13 +2882,13 @@ ieee_read_cxx_class (info, pp, count)
        case 'm':
        case 'v':
          {
-           bfd_vma flags, virtindex, control;
+           bfd_vma flags, voffset, control;
            const char *name, *mangled;
            unsigned long namlen, mangledlen;
-           struct ieee_function *func;
+           struct ieee_var *pv, *pvend;
            debug_type type;
            enum debug_visibility visibility;
-           boolean constp, volatilep;
+           bfd_boolean constp, volatilep;
            char *mangledcopy;
            debug_method_variant mv;
            struct ieee_method *meth;
@@ -2711,16 +2897,18 @@ ieee_read_cxx_class (info, pp, count)
            if (! ieee_require_asn (info, pp, &flags)
                || ! ieee_require_atn65 (info, pp, &name, &namlen)
                || ! ieee_require_atn65 (info, pp, &mangled, &mangledlen))
-             return false;
+             return FALSE;
            count -= 3;
-           if (id == 'v')
+           if (id != 'v')
+             voffset = 0;
+           else
              {
-               if (! ieee_require_asn (info, pp, &virtindex))
-                 return false;
+               if (! ieee_require_asn (info, pp, &voffset))
+                 return FALSE;
                --count;
              }
            if (! ieee_require_asn (info, pp, &control))
-             return false;
+             return FALSE;
            --count;
 
            /* We just ignore the control information.  */
@@ -2730,15 +2918,15 @@ ieee_read_cxx_class (info, pp, count)
            if ((flags & CXXFLAGS_FRIEND) != 0)
              break;
 
-           /* We should already have seen debugging information for
-               the function itself, which will include type
-               information.  */
-           for (func = info->functions; func != NULL; func = func->next)
-             if (func->name[0] == mangled[0]
-                 && strncmp (func->name, mangled, mangledlen)
-                 && strlen (func->name) == mangledlen)
+           /* We should already have seen a type for the function.  */
+           pv = info->vars.vars;
+           pvend = pv + info->vars.alloc;
+           for (; pv < pvend; pv++)
+             if (pv->namlen == mangledlen
+                 && strncmp (pv->name, mangled, mangledlen) == 0)
                break;
-           if (func == NULL)
+
+           if (pv >= pvend)
              {
                /* We won't have type information for this function if
                   it is not included in this file.  We don't try to
@@ -2748,30 +2936,30 @@ ieee_read_cxx_class (info, pp, count)
                         ieee_builtin_type (info, start,
                                            (unsigned int) builtin_void),
                         (debug_type *) NULL,
-                        false));
+                        FALSE));
              }
            else
              {
                debug_type return_type;
                const debug_type *arg_types;
-               boolean varargs;
+               bfd_boolean varargs;
 
-               if (debug_get_type_kind (dhandle, func->type)
+               if (debug_get_type_kind (dhandle, pv->type)
                    != DEBUG_KIND_FUNCTION)
                  {
                    ieee_error (info, start,
-                               "bad type for C++ method function");
-                   return false;
+                               _("bad type for C++ method function"));
+                   return FALSE;
                  }
 
-               return_type = debug_get_return_type (dhandle, func->type);
-               arg_types = debug_get_parameter_types (dhandle, func->type,
+               return_type = debug_get_return_type (dhandle, pv->type);
+               arg_types = debug_get_parameter_types (dhandle, pv->type,
                                                       &varargs);
                if (return_type == DEBUG_TYPE_NULL || arg_types == NULL)
                  {
                    ieee_error (info, start,
-                               "no type information for C++ method function");
-                   return false;
+                               _("no type information for C++ method function"));
+                   return FALSE;
                  }
 
                type = debug_make_method_type (dhandle, return_type, it->type,
@@ -2779,13 +2967,13 @@ ieee_read_cxx_class (info, pp, count)
                                               varargs);
              }
            if (type == DEBUG_TYPE_NULL)
-             return false;
+             return FALSE;
 
            switch (flags & CXXFLAGS_VISIBILITY)
              {
              default:
-               ieee_error (info, start, "unknown C++ visibility");
-               return false;
+               ieee_error (info, start, _("unknown C++ visibility"));
+               return FALSE;
 
              case CXXFLAGS_VISIBILITY_PUBLIC:
                visibility = DEBUG_VISIBILITY_PUBLIC;
@@ -2800,8 +2988,8 @@ ieee_read_cxx_class (info, pp, count)
                break;
              }
 
-           constp = (flags & CXXFLAGS_CONST) != 0 ? true : false;
-           volatilep = (flags & CXXFLAGS_VOLATILE) != 0 ? true : false;
+           constp = (flags & CXXFLAGS_CONST) != 0 ? TRUE : FALSE;
+           volatilep = (flags & CXXFLAGS_VOLATILE) != 0 ? TRUE : FALSE;
 
            mangledcopy = savestring (mangled, mangledlen);
 
@@ -2809,8 +2997,8 @@ ieee_read_cxx_class (info, pp, count)
              {
                if (id == 'v')
                  {
-                   ieee_error (info, start, "C++ static virtual method");
-                   return false;
+                   ieee_error (info, start, _("C++ static virtual method"));
+                   return FALSE;
                  }
                mv = debug_make_static_method_variant (dhandle, mangledcopy,
                                                       type, visibility,
@@ -2818,19 +3006,12 @@ ieee_read_cxx_class (info, pp, count)
              }
            else
              {
-               bfd_vma voffset;
                debug_type vcontext;
 
                if (id != 'v')
-                 {
-                   voffset = 0;
-                   vcontext = DEBUG_TYPE_NULL;
-                 }
+                 vcontext = DEBUG_TYPE_NULL;
                else
                  {
-                   /* FIXME: This should depend upon the pointer
-                       size.  */
-                   voffset = virtindex * 4;
                    /* FIXME: How can we calculate this correctly?  */
                    vcontext = it->type;
                  }
@@ -2840,7 +3021,7 @@ ieee_read_cxx_class (info, pp, count)
                                                vcontext);
              }
            if (mv == DEBUG_METHOD_VARIANT_NULL)
-             return false;
+             return FALSE;
 
            for (meth = methods, im = 0; im < methods_count; meth++, im++)
              if (meth->namlen == namlen
@@ -2886,7 +3067,7 @@ ieee_read_cxx_class (info, pp, count)
            /* We have no way to store this information, so we just
               ignore it.  */
            if (! ieee_require_asn (info, pp, &spec))
-             return false;
+             return FALSE;
            --count;
            if ((spec & 4) != 0)
              {
@@ -2896,7 +3077,7 @@ ieee_read_cxx_class (info, pp, count)
 
                if (! ieee_require_atn65 (info, pp, &filename, &filenamlen)
                    || ! ieee_require_asn (info, pp, &lineno))
-                 return false;
+                 return FALSE;
                count -= 2;
              }
            else if ((spec & 8) != 0)
@@ -2905,14 +3086,14 @@ ieee_read_cxx_class (info, pp, count)
                unsigned long mangledlen;
 
                if (! ieee_require_atn65 (info, pp, &mangled, &mangledlen))
-                 return false;
+                 return FALSE;
                --count;
              }
            else
              {
                ieee_error (info, start,
-                           "unrecognized C++ object overhead spec");
-               return false;
+                           _("unrecognized C++ object overhead spec"));
+               return FALSE;
              }
          }
          break;
@@ -2929,7 +3110,7 @@ ieee_read_cxx_class (info, pp, count)
                || ! ieee_require_asn (info, pp, &vsize)
                || ! ieee_require_atn65 (info, pp, &basename, &baselen)
                || ! ieee_require_asn (info, pp, &control))
-             return false;
+             return FALSE;
            count -= 4;
 
            /* We just ignore the control number.  We don't care what
@@ -2939,7 +3120,7 @@ ieee_read_cxx_class (info, pp, count)
            /* FIXME: We can't handle multiple virtual table pointers.  */
 
            if (baselen == 0)
-             ownvptr = true;
+             ownvptr = TRUE;
            else
              {
                char *basecopy;
@@ -2950,8 +3131,8 @@ ieee_read_cxx_class (info, pp, count)
                free (basecopy);
                if (vptrbase == DEBUG_TYPE_NULL)
                  {
-                   ieee_error (info, start, "undefined C++ vtable");
-                   return false;
+                   ieee_error (info, start, _("undefined C++ vtable"));
+                   return FALSE;
                  }
              }
          }
@@ -2978,8 +3159,9 @@ ieee_read_cxx_class (info, pp, count)
          dmethods[i] = debug_make_method (dhandle, namcopy,
                                           methods[i].variants);
          if (dmethods[i] == DEBUG_METHOD_NULL)
-           return false;
+           return FALSE;
        }
+      dmethods[i] = DEBUG_METHOD_NULL;
       free (methods);
     }
 
@@ -2993,18 +3175,291 @@ ieee_read_cxx_class (info, pp, count)
                                     fields, baseclasses, dmethods,
                                     vptrbase, ownvptr);
   if (it->slot == DEBUG_TYPE_NULL)
-    return false;
+    return FALSE;
+
+  return TRUE;
+}
+
+/* Read C++ default argument value and reference type information.  */
+
+static bfd_boolean
+ieee_read_cxx_defaults (struct ieee_info *info, const bfd_byte **pp,
+                       unsigned long count)
+{
+  const bfd_byte *start;
+  const char *fnname;
+  unsigned long fnlen;
+  bfd_vma defcount;
+
+  start = *pp;
+
+  /* Giving the function name before the argument count is an addendum
+     to the spec.  The function name is demangled, though, so this
+     record must always refer to the current function.  */
+
+  if (info->blockstack.bsp <= info->blockstack.stack
+      || info->blockstack.bsp[-1].fnindx == (unsigned int) -1)
+    {
+      ieee_error (info, start, _("C++ default values not in a function"));
+      return FALSE;
+    }
+
+  if (! ieee_require_atn65 (info, pp, &fnname, &fnlen)
+      || ! ieee_require_asn (info, pp, &defcount))
+    return FALSE;
+  count -= 2;
+
+  while (defcount-- > 0)
+    {
+      bfd_vma type, val;
+      const char *strval;
+      unsigned long strvallen;
+
+      if (! ieee_require_asn (info, pp, &type))
+       return FALSE;
+      --count;
+
+      switch (type)
+       {
+       case 0:
+       case 4:
+         break;
+
+       case 1:
+       case 2:
+         if (! ieee_require_asn (info, pp, &val))
+           return FALSE;
+         --count;
+         break;
+
+       case 3:
+       case 7:
+         if (! ieee_require_atn65 (info, pp, &strval, &strvallen))
+           return FALSE;
+         --count;
+         break;
+
+       default:
+         ieee_error (info, start, _("unrecognized C++ default type"));
+         return FALSE;
+       }
+
+      /* We have no way to record the default argument values, so we
+         just ignore them.  FIXME.  */
+    }
+
+  /* Any remaining arguments are indices of parameters that are really
+     reference type.  */
+  if (count > 0)
+    {
+      void *dhandle;
+      debug_type *arg_slots;
+
+      dhandle = info->dhandle;
+      arg_slots = info->types.types[info->blockstack.bsp[-1].fnindx].arg_slots;
+      while (count-- > 0)
+       {
+         bfd_vma indx;
+         debug_type target;
+
+         if (! ieee_require_asn (info, pp, &indx))
+           return FALSE;
+         /* The index is 1 based.  */
+         --indx;
+         if (arg_slots == NULL
+             || arg_slots[indx] == DEBUG_TYPE_NULL
+             || (debug_get_type_kind (dhandle, arg_slots[indx])
+                 != DEBUG_KIND_POINTER))
+           {
+             ieee_error (info, start, _("reference parameter is not a pointer"));
+             return FALSE;
+           }
+
+         target = debug_get_target_type (dhandle, arg_slots[indx]);
+         arg_slots[indx] = debug_make_reference_type (dhandle, target);
+         if (arg_slots[indx] == DEBUG_TYPE_NULL)
+           return FALSE;
+       }
+    }
+
+  return TRUE;
+}
+
+/* Read a C++ reference definition.  */
+
+static bfd_boolean
+ieee_read_reference (struct ieee_info *info, const bfd_byte **pp)
+{
+  const bfd_byte *start;
+  bfd_vma flags;
+  const char *class, *name;
+  unsigned long classlen, namlen;
+  debug_type *pslot;
+  debug_type target;
+
+  start = *pp;
+
+  if (! ieee_require_asn (info, pp, &flags))
+    return FALSE;
+
+  /* Giving the class name before the member name is in an addendum to
+     the spec.  */
+  if (flags == 3)
+    {
+      if (! ieee_require_atn65 (info, pp, &class, &classlen))
+       return FALSE;
+    }
+
+  if (! ieee_require_atn65 (info, pp, &name, &namlen))
+    return FALSE;
+
+  pslot = NULL;
+  if (flags != 3)
+    {
+      int pass;
+
+      /* We search from the last variable indices to the first in
+        hopes of finding local variables correctly.  We search the
+        local variables on the first pass, and the global variables
+        on the second.  FIXME: This probably won't work in all cases.
+        On the other hand, I don't know what will.  */
+      for (pass = 0; pass < 2; pass++)
+       {
+         struct ieee_vars *vars;
+         int i;
+         struct ieee_var *pv = NULL;
+
+         if (pass == 0)
+           vars = &info->vars;
+         else
+           {
+             vars = info->global_vars;
+             if (vars == NULL)
+               break;
+           }
+
+         for (i = (int) vars->alloc - 1; i >= 0; i--)
+           {
+             bfd_boolean found;
+
+             pv = vars->vars + i;
+
+             if (pv->pslot == NULL
+                 || pv->namlen != namlen
+                 || strncmp (pv->name, name, namlen) != 0)
+               continue;
+
+             found = FALSE;
+             switch (flags)
+               {
+               default:
+                 ieee_error (info, start,
+                             _("unrecognized C++ reference type"));
+                 return FALSE;
+
+               case 0:
+                 /* Global variable or function.  */
+                 if (pv->kind == IEEE_GLOBAL
+                     || pv->kind == IEEE_EXTERNAL
+                     || pv->kind == IEEE_FUNCTION)
+                   found = TRUE;
+                 break;
+
+               case 1:
+                 /* Global static variable or function.  */
+                 if (pv->kind == IEEE_STATIC
+                     || pv->kind == IEEE_FUNCTION)
+                   found = TRUE;
+                 break;
+
+               case 2:
+                 /* Local variable.  */
+                 if (pv->kind == IEEE_LOCAL)
+                   found = TRUE;
+                 break;
+               }
+
+             if (found)
+               break;
+           }
+
+         if (i >= 0)
+           {
+             pslot = pv->pslot;
+             break;
+           }
+       }
+    }
+  else
+    {
+      struct ieee_tag *it;
+
+      for (it = info->tags; it != NULL; it = it->next)
+       {
+         if (it->name[0] == class[0]
+             && strncmp (it->name, class, classlen) == 0
+             && strlen (it->name) == classlen)
+           {
+             if (it->fslots != NULL)
+               {
+                 const debug_field *pf;
+                 unsigned int findx;
+
+                 pf = debug_get_fields (info->dhandle, it->type);
+                 if (pf == NULL)
+                   {
+                     ieee_error (info, start,
+                                 "C++ reference in class with no fields");
+                     return FALSE;
+                   }
+
+                 for (findx = 0; *pf != DEBUG_FIELD_NULL; pf++, findx++)
+                   {
+                     const char *fname;
+
+                     fname = debug_get_field_name (info->dhandle, *pf);
+                     if (fname == NULL)
+                       return FALSE;
+                     if (strncmp (fname, name, namlen) == 0
+                         && strlen (fname) == namlen)
+                       {
+                         pslot = it->fslots + findx;
+                         break;
+                       }
+                   }
+               }
+
+             break;
+           }
+       }
+    }
+
+  if (pslot == NULL)
+    {
+      ieee_error (info, start, _("C++ reference not found"));
+      return FALSE;
+    }
+
+  /* We allocated the type of the object as an indirect type pointing
+     to *pslot, which we can now update to be a reference type.  */
+  if (debug_get_type_kind (info->dhandle, *pslot) != DEBUG_KIND_POINTER)
+    {
+      ieee_error (info, start, _("C++ reference is not pointer"));
+      return FALSE;
+    }
 
-  return true;
+  target = debug_get_target_type (info->dhandle, *pslot);
+  *pslot = debug_make_reference_type (info->dhandle, target);
+  if (*pslot == DEBUG_TYPE_NULL)
+    return FALSE;
+
+  return TRUE;
 }
 
 /* Require an ASN record.  */
 
-static boolean
-ieee_require_asn (info, pp, pv)
-     struct ieee_info *info;
-     const bfd_byte **pp;
-     bfd_vma *pv;
+static bfd_boolean
+ieee_require_asn (struct ieee_info *info, const bfd_byte **pp, bfd_vma *pv)
 {
   const bfd_byte *start;
   ieee_record_enum_type c;
@@ -3015,34 +3470,31 @@ ieee_require_asn (info, pp, pv)
   c = (ieee_record_enum_type) **pp;
   if (c != ieee_e2_first_byte_enum)
     {
-      ieee_error (info, start, "missing required ASN");
-      return false;
+      ieee_error (info, start, _("missing required ASN"));
+      return FALSE;
     }
   ++*pp;
 
   c = (ieee_record_enum_type) (((unsigned int) c << 8) | **pp);
   if (c != ieee_asn_record_enum)
     {
-      ieee_error (info, start, "missing required ASN");
-      return false;
+      ieee_error (info, start, _("missing required ASN"));
+      return FALSE;
     }
   ++*pp;
 
   /* Just ignore the variable index.  */
   if (! ieee_read_number (info, pp, &varindx))
-    return false;
+    return FALSE;
 
   return ieee_read_expression (info, pp, pv);
 }
 
 /* Require an ATN65 record.  */
 
-static boolean
-ieee_require_atn65 (info, pp, pname, pnamlen)
-     struct ieee_info *info;
-     const bfd_byte **pp;
-     const char **pname;
-     unsigned long *pnamlen;
+static bfd_boolean
+ieee_require_atn65 (struct ieee_info *info, const bfd_byte **pp,
+                   const char **pname, unsigned long *pnamlen)
 {
   const bfd_byte *start;
   ieee_record_enum_type c;
@@ -3053,30 +3505,30 @@ ieee_require_atn65 (info, pp, pname, pnamlen)
   c = (ieee_record_enum_type) **pp;
   if (c != ieee_at_record_enum)
     {
-      ieee_error (info, start, "missing required ATN65");
-      return false;
+      ieee_error (info, start, _("missing required ATN65"));
+      return FALSE;
     }
   ++*pp;
 
   c = (ieee_record_enum_type) (((unsigned int) c << 8) | **pp);
   if (c != ieee_atn_record_enum)
     {
-      ieee_error (info, start, "missing required ATN65");
-      return false;
+      ieee_error (info, start, _("missing required ATN65"));
+      return FALSE;
     }
   ++*pp;
 
   if (! ieee_read_number (info, pp, &name_indx)
       || ! ieee_read_number (info, pp, &type_indx)
       || ! ieee_read_number (info, pp, &atn_code))
-    return false;
+    return FALSE;
 
   /* Just ignore name_indx.  */
 
   if (type_indx != 0 || atn_code != 65)
     {
-      ieee_error (info, start, "bad ATN65 record");
-      return false;
+      ieee_error (info, start, _("bad ATN65 record"));
+      return FALSE;
     }
 
   return ieee_read_id (info, pp, pname, pnamlen);
@@ -3086,20 +3538,54 @@ ieee_require_atn65 (info, pp, pname, pnamlen)
    generic register number.  */
 
 static int
-ieee_regno_to_genreg (abfd, r)
-     bfd *abfd;
-     int r;
+ieee_regno_to_genreg (bfd *abfd, int r)
 {
+  switch (bfd_get_arch (abfd))
+    {
+    case bfd_arch_m68k:
+      /* For some reasons stabs adds 2 to the floating point register
+         numbers.  */
+      if (r >= 16)
+       r += 2;
+      break;
+
+    case bfd_arch_i960:
+      /* Stabs uses 0 to 15 for r0 to r15, 16 to 31 for g0 to g15, and
+         32 to 35 for fp0 to fp3.  */
+      --r;
+      break;
+
+    default:
+      break;
+    }
+
   return r;
 }
 
 /* Convert a generic register number to an IEEE specific one.  */
 
 static int
-ieee_genreg_to_regno (abfd, r)
-     bfd *abfd;
-     int r;
+ieee_genreg_to_regno (bfd *abfd, int r)
 {
+  switch (bfd_get_arch (abfd))
+    {
+    case bfd_arch_m68k:
+      /* For some reason stabs add 2 to the floating point register
+         numbers.  */
+      if (r >= 18)
+       r -= 2;
+      break;
+
+    case bfd_arch_i960:
+      /* Stabs uses 0 to 15 for r0 to r15, 16 to 31 for g0 to g15, and
+         32 to 35 for fp0 to fp3.  */
+      ++r;
+      break;
+
+    default:
+      break;
+    }
+
   return r;
 }
 \f
@@ -3122,6 +3608,16 @@ struct ieee_buf
   bfd_byte buf[IEEE_BUFSIZE];
 };
 
+/* A list of buffers.  */
+
+struct ieee_buflist
+{
+  /* Head of list.  */
+  struct ieee_buf *head;
+  /* Tail--last buffer on list.  */
+  struct ieee_buf *tail;
+};
+
 /* In order to generate the BB11 blocks required by the HP emulator,
    we keep track of ranges of addresses which correspond to a given
    compilation unit.  */
@@ -3140,23 +3636,23 @@ struct ieee_range
 
 struct ieee_type_class
 {
-  /* The name of the class.  */
-  const char *name;
   /* The name index in the debugging information.  */
   unsigned int indx;
   /* The pmisc records for the class.  */
-  struct ieee_buf *pmiscbuf;
+  struct ieee_buflist pmiscbuf;
   /* The number of pmisc records.  */
   unsigned int pmisccount;
   /* The name of the class holding the virtual table, if not this
      class.  */
   const char *vclass;
   /* Whether this class holds its own virtual table.  */
-  boolean ownvptr;
+  bfd_boolean ownvptr;
   /* The largest virtual table offset seen so far.  */
   bfd_vma voffset;
   /* The current method.  */
   const char *method;
+  /* Additional pmisc records used to record fields of reference type.  */
+  struct ieee_buflist refs;
 };
 
 /* This is how we store types for the writing routines.  Most types
@@ -3168,15 +3664,25 @@ struct ieee_write_type
   unsigned int indx;
   /* The size of the type, if known.  */
   unsigned int size;
+  /* The name of the type, if any.  */
+  const char *name;
+  /* If this is a function or method type, we build the type here, and
+     only add it to the output buffers if we need it.  */
+  struct ieee_buflist fndef;
   /* If this is a struct, this is where the struct definition is
      built.  */
-  struct ieee_buf *strdef;
+  struct ieee_buflist strdef;
   /* If this is a class, this is where the class information is built.  */
   struct ieee_type_class *classdef;
   /* Whether the type is unsigned.  */
   unsigned int unsignedp : 1;
   /* Whether this is a reference type.  */
   unsigned int referencep : 1;
+  /* Whether this is in the local type block.  */
+  unsigned int localp : 1;
+  /* Whether this is a duplicate struct definition which we are
+     ignoring.  */
+  unsigned int ignorep : 1;
 };
 
 /* This is the type stack used by the debug writing routines.  FIXME:
@@ -3191,15 +3697,16 @@ struct ieee_type_stack
   struct ieee_write_type type;
 };
 
-/* This is a list of associations between names and types.  This could
-   be more efficiently implemented as a hash table.  */
+/* This is a list of associations between a name and some types.
+   These are used for typedefs and tags.  */
 
 struct ieee_name_type
 {
-  /* Next name/type assocation.  */
+  /* Next type for this name.  */
   struct ieee_name_type *next;
-  /* Name.  */
-  const char *name;
+  /* ID number.  For a typedef, this is the index of the type to which
+     this name is typedefed.  */
+  unsigned int id;
   /* Type.  */
   struct ieee_write_type type;
   /* If this is a tag which has not yet been defined, this is the
@@ -3207,6 +3714,69 @@ struct ieee_name_type
   enum debug_type_kind kind;
 };
 
+/* We use a hash table to associate names and types.  */
+
+struct ieee_name_type_hash_table
+{
+  struct bfd_hash_table root;
+};
+
+struct ieee_name_type_hash_entry
+{
+  struct bfd_hash_entry root;
+  /* Information for this name.  */
+  struct ieee_name_type *types;
+};
+
+/* This is a list of enums.  */
+
+struct ieee_defined_enum
+{
+  /* Next enum.  */
+  struct ieee_defined_enum *next;
+  /* Type index.  */
+  unsigned int indx;
+  /* Whether this enum has been defined.  */
+  bfd_boolean defined;
+  /* Tag.  */
+  const char *tag;
+  /* Names.  */
+  const char **names;
+  /* Values.  */
+  bfd_signed_vma *vals;
+};
+
+/* We keep a list of modified versions of types, so that we don't
+   output them more than once.  */
+
+struct ieee_modified_type
+{
+  /* Pointer to this type.  */
+  unsigned int pointer;
+  /* Function with unknown arguments returning this type.  */
+  unsigned int function;
+  /* Const version of this type.  */
+  unsigned int const_qualified;
+  /* Volatile version of this type.  */
+  unsigned int volatile_qualified;
+  /* List of arrays of this type of various bounds.  */
+  struct ieee_modified_array_type *arrays;
+};
+
+/* A list of arrays bounds.  */
+
+struct ieee_modified_array_type
+{
+  /* Next array bounds.  */
+  struct ieee_modified_array_type *next;
+  /* Type index with these bounds.  */
+  unsigned int indx;
+  /* Low bound.  */
+  bfd_signed_vma low;
+  /* High bound.  */
+  bfd_signed_vma high;
+};
+
 /* This is a list of pending function parameter information.  We don't
    output them until we see the first block.  */
 
@@ -3218,6 +3788,8 @@ struct ieee_pending_parm
   const char *name;
   /* Type index.  */
   unsigned int type;
+  /* Whether the type is a reference.  */
+  bfd_boolean referencep;
   /* Kind.  */
   enum debug_parm_kind kind;
   /* Value.  */
@@ -3230,26 +3802,35 @@ struct ieee_handle
 {
   /* BFD we are writing to.  */
   bfd *abfd;
+  /* Whether we got an error in a subroutine called via traverse or
+     map_over_sections.  */
+  bfd_boolean error;
+  /* Current data buffer list.  */
+  struct ieee_buflist *current;
   /* Current data buffer.  */
-  struct ieee_buf *current;
+  struct ieee_buf *curbuf;
   /* Filename of current compilation unit.  */
   const char *filename;
   /* Module name of current compilation unit.  */
   const char *modname;
+  /* List of buffer for global types.  */
+  struct ieee_buflist global_types;
   /* List of finished data buffers.  */
-  struct ieee_buf *data;
+  struct ieee_buflist data;
   /* List of buffers for typedefs in the current compilation unit.  */
-  struct ieee_buf *types;
+  struct ieee_buflist types;
   /* List of buffers for variables and functions in the current
      compilation unit.  */
-  struct ieee_buf *vars;
+  struct ieee_buflist vars;
   /* List of buffers for C++ class definitions in the current
      compilation unit.  */
-  struct ieee_buf *cxx;
+  struct ieee_buflist cxx;
   /* List of buffers for line numbers in the current compilation unit.  */
-  struct ieee_buf *linenos;
+  struct ieee_buflist linenos;
   /* Ranges for the current compilation unit.  */
   struct ieee_range *ranges;
+  /* Ranges for all debugging information.  */
+  struct ieee_range *global_ranges;
   /* Nested pending ranges.  */
   struct ieee_range *pending_ranges;
   /* Type stack.  */
@@ -3259,110 +3840,151 @@ struct ieee_handle
   /* Next unallocated name index.  */
   unsigned int name_indx;
   /* Typedefs.  */
-  struct ieee_name_type *typedefs;
+  struct ieee_name_type_hash_table typedefs;
   /* Tags.  */
-  struct ieee_name_type *tags;
+  struct ieee_name_type_hash_table tags;
+  /* Enums.  */
+  struct ieee_defined_enum *enums;
+  /* Modified versions of types.  */
+  struct ieee_modified_type *modified;
+  /* Number of entries allocated in modified.  */
+  unsigned int modified_alloc;
+  /* 4 byte complex type.  */
+  unsigned int complex_float_index;
+  /* 8 byte complex type.  */
+  unsigned int complex_double_index;
   /* The depth of block nesting.  This is 0 outside a function, and 1
      just after start_function is called.  */
   unsigned int block_depth;
+  /* The name of the current function.  */
+  const char *fnname;
+  /* List of buffers for the type of the function we are currently
+     writing out.  */
+  struct ieee_buflist fntype;
+  /* List of buffers for the parameters of the function we are
+     currently writing out.  */
+  struct ieee_buflist fnargs;
+  /* Number of arguments written to fnargs.  */
+  unsigned int fnargcount;
   /* Pending function parameters.  */
   struct ieee_pending_parm *pending_parms;
   /* Current line number filename.  */
   const char *lineno_filename;
   /* Line number name index.  */
   unsigned int lineno_name_indx;
+  /* Filename of pending line number.  */
+  const char *pending_lineno_filename;
+  /* Pending line number.  */
+  unsigned long pending_lineno;
+  /* Address of pending line number.  */
+  bfd_vma pending_lineno_addr;
   /* Highest address seen at end of procedure.  */
   bfd_vma highaddr;
 };
 
-static boolean ieee_change_buffer
-  PARAMS ((struct ieee_handle *, struct ieee_buf **));
-static boolean ieee_push_type
-  PARAMS ((struct ieee_handle *, unsigned int, unsigned int, boolean));
-static unsigned int ieee_pop_type PARAMS ((struct ieee_handle *));
-static boolean ieee_add_range
-  PARAMS ((struct ieee_handle *, bfd_vma, bfd_vma));
-static boolean ieee_start_range PARAMS ((struct ieee_handle *, bfd_vma));
-static boolean ieee_end_range PARAMS ((struct ieee_handle *, bfd_vma));
-static boolean ieee_real_write_byte PARAMS ((struct ieee_handle *, int));
-static boolean ieee_write_2bytes PARAMS ((struct ieee_handle *, int));
-static boolean ieee_write_number PARAMS ((struct ieee_handle *, bfd_vma));
-static boolean ieee_write_id PARAMS ((struct ieee_handle *, const char *));
-static boolean ieee_write_asn
-  PARAMS ((struct ieee_handle *, unsigned int, bfd_vma));
-static boolean ieee_write_atn65
-  PARAMS ((struct ieee_handle *, unsigned int, const char *));
-static boolean ieee_define_type
-  PARAMS ((struct ieee_handle *, unsigned int, boolean));
-static boolean ieee_define_named_type
-  PARAMS ((struct ieee_handle *, const char *, boolean, unsigned int,
-          unsigned int, boolean, struct ieee_buf **));
-static boolean ieee_finish_compilation_unit PARAMS ((struct ieee_handle *));
-static boolean ieee_output_pending_parms PARAMS ((struct ieee_handle *));
-static unsigned int ieee_vis_to_flags PARAMS ((enum debug_visibility));
-static boolean ieee_class_method_var
-  PARAMS ((struct ieee_handle *, const char *, enum debug_visibility, boolean,
-          boolean, boolean, bfd_vma, boolean));
-
-static boolean ieee_start_compilation_unit PARAMS ((PTR, const char *));
-static boolean ieee_start_source PARAMS ((PTR, const char *));
-static boolean ieee_empty_type PARAMS ((PTR));
-static boolean ieee_void_type PARAMS ((PTR));
-static boolean ieee_int_type PARAMS ((PTR, unsigned int, boolean));
-static boolean ieee_float_type PARAMS ((PTR, unsigned int));
-static boolean ieee_complex_type PARAMS ((PTR, unsigned int));
-static boolean ieee_bool_type PARAMS ((PTR, unsigned int));
-static boolean ieee_enum_type
-  PARAMS ((PTR, const char *, const char **, bfd_signed_vma *));
-static boolean ieee_pointer_type PARAMS ((PTR));
-static boolean ieee_function_type PARAMS ((PTR, int, boolean));
-static boolean ieee_reference_type PARAMS ((PTR));
-static boolean ieee_range_type PARAMS ((PTR, bfd_signed_vma, bfd_signed_vma));
-static boolean ieee_array_type
-  PARAMS ((PTR, bfd_signed_vma, bfd_signed_vma, boolean));
-static boolean ieee_set_type PARAMS ((PTR, boolean));
-static boolean ieee_offset_type PARAMS ((PTR));
-static boolean ieee_method_type PARAMS ((PTR, boolean, int, boolean));
-static boolean ieee_const_type PARAMS ((PTR));
-static boolean ieee_volatile_type PARAMS ((PTR));
-static boolean ieee_start_struct_type
-  PARAMS ((PTR, const char *, unsigned int, boolean, unsigned int));
-static boolean ieee_struct_field
-  PARAMS ((PTR, const char *, bfd_vma, bfd_vma, enum debug_visibility));
-static boolean ieee_end_struct_type PARAMS ((PTR));
-static boolean ieee_start_class_type
-  PARAMS ((PTR, const char *, unsigned int, boolean, unsigned int, boolean,
-          boolean));
-static boolean ieee_class_static_member
-  PARAMS ((PTR, const char *, const char *, enum debug_visibility));
-static boolean ieee_class_baseclass
-  PARAMS ((PTR, bfd_vma, boolean, enum debug_visibility));
-static boolean ieee_class_start_method PARAMS ((PTR, const char *));
-static boolean ieee_class_method_variant
-  PARAMS ((PTR, const char *, enum debug_visibility, boolean, boolean,
-          bfd_vma, boolean));
-static boolean ieee_class_static_method_variant
-  PARAMS ((PTR, const char *, enum debug_visibility, boolean, boolean));
-static boolean ieee_class_end_method PARAMS ((PTR));
-static boolean ieee_end_class_type PARAMS ((PTR));
-static boolean ieee_typedef_type PARAMS ((PTR, const char *));
-static boolean ieee_tag_type
-  PARAMS ((PTR, const char *, unsigned int, enum debug_type_kind));
-static boolean ieee_typdef PARAMS ((PTR, const char *));
-static boolean ieee_tag PARAMS ((PTR, const char *));
-static boolean ieee_int_constant PARAMS ((PTR, const char *, bfd_vma));
-static boolean ieee_float_constant PARAMS ((PTR, const char *, double));
-static boolean ieee_typed_constant PARAMS ((PTR, const char *, bfd_vma));
-static boolean ieee_variable
-  PARAMS ((PTR, const char *, enum debug_var_kind, bfd_vma));
-static boolean ieee_start_function PARAMS ((PTR, const char *, boolean));
-static boolean ieee_function_parameter
-  PARAMS ((PTR, const char *, enum debug_parm_kind, bfd_vma));
-static boolean ieee_start_block PARAMS ((PTR, bfd_vma));
-static boolean ieee_end_block PARAMS ((PTR, bfd_vma));
-static boolean ieee_end_function PARAMS ((PTR));
-static boolean ieee_lineno
-  PARAMS ((PTR, const char *, unsigned long, bfd_vma));
+static bfd_boolean ieee_init_buffer
+  (struct ieee_handle *, struct ieee_buflist *);
+static bfd_boolean ieee_change_buffer
+  (struct ieee_handle *, struct ieee_buflist *);
+static bfd_boolean ieee_append_buffer
+  (struct ieee_handle *, struct ieee_buflist *, struct ieee_buflist *);
+static bfd_boolean ieee_real_write_byte (struct ieee_handle *, int);
+static bfd_boolean ieee_write_2bytes (struct ieee_handle *, int);
+static bfd_boolean ieee_write_number (struct ieee_handle *, bfd_vma);
+static bfd_boolean ieee_write_id (struct ieee_handle *, const char *);
+static bfd_boolean ieee_write_asn
+  (struct ieee_handle *, unsigned int, bfd_vma);
+static bfd_boolean ieee_write_atn65
+  (struct ieee_handle *, unsigned int, const char *);
+static bfd_boolean ieee_push_type
+  (struct ieee_handle *, unsigned int, unsigned int, bfd_boolean,
+   bfd_boolean);
+static unsigned int ieee_pop_type (struct ieee_handle *);
+static void ieee_pop_unused_type (struct ieee_handle *);
+static unsigned int ieee_pop_type_used (struct ieee_handle *, bfd_boolean);
+static bfd_boolean ieee_add_range
+  (struct ieee_handle *, bfd_boolean, bfd_vma, bfd_vma);
+static bfd_boolean ieee_start_range (struct ieee_handle *, bfd_vma);
+static bfd_boolean ieee_end_range (struct ieee_handle *, bfd_vma);
+static bfd_boolean ieee_define_type
+  (struct ieee_handle *, unsigned int, bfd_boolean, bfd_boolean);
+static bfd_boolean ieee_define_named_type
+  (struct ieee_handle *, const char *, unsigned int, unsigned int,
+   bfd_boolean, bfd_boolean, struct ieee_buflist *);
+static struct ieee_modified_type *ieee_get_modified_info
+  (struct ieee_handle *, unsigned int);
+static struct bfd_hash_entry *ieee_name_type_newfunc
+  (struct bfd_hash_entry *, struct bfd_hash_table *, const char *);
+static bfd_boolean ieee_write_undefined_tag
+  (struct ieee_name_type_hash_entry *, void *);
+static bfd_boolean ieee_finish_compilation_unit (struct ieee_handle *);
+static void ieee_add_bb11_blocks (bfd *, asection *, void *);
+static bfd_boolean ieee_add_bb11
+  (struct ieee_handle *, asection *, bfd_vma, bfd_vma);
+static bfd_boolean ieee_output_pending_parms (struct ieee_handle *);
+static unsigned int ieee_vis_to_flags (enum debug_visibility);
+static bfd_boolean ieee_class_method_var
+  (struct ieee_handle *, const char *, enum debug_visibility, bfd_boolean,
+   bfd_boolean, bfd_boolean, bfd_vma, bfd_boolean);
+
+static bfd_boolean ieee_start_compilation_unit (void *, const char *);
+static bfd_boolean ieee_start_source (void *, const char *);
+static bfd_boolean ieee_empty_type (void *);
+static bfd_boolean ieee_void_type (void *);
+static bfd_boolean ieee_int_type (void *, unsigned int, bfd_boolean);
+static bfd_boolean ieee_float_type (void *, unsigned int);
+static bfd_boolean ieee_complex_type (void *, unsigned int);
+static bfd_boolean ieee_bool_type (void *, unsigned int);
+static bfd_boolean ieee_enum_type
+  (void *, const char *, const char **, bfd_signed_vma *);
+static bfd_boolean ieee_pointer_type (void *);
+static bfd_boolean ieee_function_type (void *, int, bfd_boolean);
+static bfd_boolean ieee_reference_type (void *);
+static bfd_boolean ieee_range_type (void *, bfd_signed_vma, bfd_signed_vma);
+static bfd_boolean ieee_array_type
+  (void *, bfd_signed_vma, bfd_signed_vma, bfd_boolean);
+static bfd_boolean ieee_set_type (void *, bfd_boolean);
+static bfd_boolean ieee_offset_type (void *);
+static bfd_boolean ieee_method_type (void *, bfd_boolean, int, bfd_boolean);
+static bfd_boolean ieee_const_type (void *);
+static bfd_boolean ieee_volatile_type (void *);
+static bfd_boolean ieee_start_struct_type
+  (void *, const char *, unsigned int, bfd_boolean, unsigned int);
+static bfd_boolean ieee_struct_field
+  (void *, const char *, bfd_vma, bfd_vma, enum debug_visibility);
+static bfd_boolean ieee_end_struct_type (void *);
+static bfd_boolean ieee_start_class_type
+  (void *, const char *, unsigned int, bfd_boolean, unsigned int, bfd_boolean,
+   bfd_boolean);
+static bfd_boolean ieee_class_static_member
+  (void *, const char *, const char *, enum debug_visibility);
+static bfd_boolean ieee_class_baseclass
+  (void *, bfd_vma, bfd_boolean, enum debug_visibility);
+static bfd_boolean ieee_class_start_method (void *, const char *);
+static bfd_boolean ieee_class_method_variant
+  (void *, const char *, enum debug_visibility, bfd_boolean, bfd_boolean,
+   bfd_vma, bfd_boolean);
+static bfd_boolean ieee_class_static_method_variant
+  (void *, const char *, enum debug_visibility, bfd_boolean, bfd_boolean);
+static bfd_boolean ieee_class_end_method (void *);
+static bfd_boolean ieee_end_class_type (void *);
+static bfd_boolean ieee_typedef_type (void *, const char *);
+static bfd_boolean ieee_tag_type
+  (void *, const char *, unsigned int, enum debug_type_kind);
+static bfd_boolean ieee_typdef (void *, const char *);
+static bfd_boolean ieee_tag (void *, const char *);
+static bfd_boolean ieee_int_constant (void *, const char *, bfd_vma);
+static bfd_boolean ieee_float_constant (void *, const char *, double);
+static bfd_boolean ieee_typed_constant (void *, const char *, bfd_vma);
+static bfd_boolean ieee_variable
+  (void *, const char *, enum debug_var_kind, bfd_vma);
+static bfd_boolean ieee_start_function (void *, const char *, bfd_boolean);
+static bfd_boolean ieee_function_parameter
+  (void *, const char *, enum debug_parm_kind, bfd_vma);
+static bfd_boolean ieee_start_block (void *, bfd_vma);
+static bfd_boolean ieee_end_block (void *, bfd_vma);
+static bfd_boolean ieee_end_function (void *);
+static bfd_boolean ieee_lineno (void *, const char *, unsigned long, bfd_vma);
 
 static const struct debug_write_fns ieee_fns =
 {
@@ -3412,197 +4034,97 @@ static const struct debug_write_fns ieee_fns =
   ieee_lineno
 };
 
-/* Change the current buffer to a specified buffer chain.  */
-
-static boolean
-ieee_change_buffer (info, ppbuf)
-     struct ieee_handle *info;
-     struct ieee_buf **ppbuf;
-{
-  struct ieee_buf *buf;
-
-  if (*ppbuf != NULL)
-    {
-      for (buf = *ppbuf; buf->next != NULL; buf = buf->next)
-       ;
-    }
-  else
-    {
-      buf = (struct ieee_buf *) xmalloc (sizeof *buf);
-      buf->next = NULL;
-      buf->c = 0;
-      *ppbuf = buf;
-    }
-
-  info->current = buf;
-  return true;
-}
+/* Initialize a buffer to be empty.  */
 
-/* Push a type index onto the type stack.  */
-
-static boolean
-ieee_push_type (info, indx, size, unsignedp)
-     struct ieee_handle *info;
-     unsigned int indx;
-     unsigned int size;
-     boolean unsignedp;
+static bfd_boolean
+ieee_init_buffer (struct ieee_handle *info ATTRIBUTE_UNUSED,
+                 struct ieee_buflist *buflist)
 {
-  struct ieee_type_stack *ts;
-
-  ts = (struct ieee_type_stack *) xmalloc (sizeof *ts);
-  memset (ts, 0, sizeof *ts);
-
-  ts->type.indx = indx;
-  ts->type.size = size;
-  ts->type.unsignedp = unsignedp;
-
-  ts->next = info->type_stack;
-  info->type_stack = ts;
-
-  return true;
+  buflist->head = NULL;
+  buflist->tail = NULL;
+  return TRUE;
 }
 
-/* Pop a type index off the type stack.  */
-
-static unsigned int
-ieee_pop_type (info)
-     struct ieee_handle *info;
-{
-  struct ieee_type_stack *ts;
-  unsigned int ret;
+/* See whether a buffer list has any data.  */
 
-  ts = info->type_stack;
-  assert (ts != NULL);
-  ret = ts->type.indx;
-  info->type_stack = ts->next;
-  free (ts);
-  return ret;
-}
+#define ieee_buffer_emptyp(buflist) ((buflist)->head == NULL)
 
-/* Add a range of bytes included in the current compilation unit.  */
+/* Change the current buffer to a specified buffer chain.  */
 
-static boolean
-ieee_add_range (info, low, high)
-     struct ieee_handle *info;
-     bfd_vma low;
-     bfd_vma high;
+static bfd_boolean
+ieee_change_buffer (struct ieee_handle *info, struct ieee_buflist *buflist)
 {
-  struct ieee_range *r, **pr;
-
-  if (low == (bfd_vma) -1 || high == (bfd_vma) -1)
-    return true;
-
-  for (r = info->ranges; r != NULL; r = r->next)
+  if (buflist->head == NULL)
     {
-      if (high >= r->low && low <= r->high)
-       {
-         /* The new range overlaps r.  */
-         if (low < r->low)
-           r->low = low;
-         if (high > r->high)
-           r->high = high;
-         pr = &r->next;
-         while (*pr != NULL && (*pr)->low <= r->high)
-           {
-             struct ieee_range *n;
+      struct ieee_buf *buf;
 
-             if ((*pr)->high > r->high)
-               r->high = (*pr)->high;
-             n = (*pr)->next;
-             free (*pr);
-             *pr = n;
-           }
-         return true;
-       }
+      buf = (struct ieee_buf *) xmalloc (sizeof *buf);
+      buf->next = NULL;
+      buf->c = 0;
+      buflist->head = buf;
+      buflist->tail = buf;
     }
 
-  r = (struct ieee_range *) xmalloc (sizeof *r);
-  memset (r, 0, sizeof *r);
-
-  r->low = low;
-  r->high = high;
-
-  /* Store the ranges sorted by address.  */
-  for (pr = &info->ranges; *pr != NULL; pr = &(*pr)->next)
-    if ((*pr)->next != NULL && (*pr)->next->low > high)
-      break;
-  r->next = *pr;
-  *pr = r;
+  info->current = buflist;
+  info->curbuf = buflist->tail;
 
-  return true;
+  return TRUE;
 }
 
-/* Start a new range for which we only have the low address.  */
-
-static boolean
-ieee_start_range (info, low)
-     struct ieee_handle *info;
-     bfd_vma low;
-{
-  struct ieee_range *r;
-
-  r = (struct ieee_range *) xmalloc (sizeof *r);
-  memset (r, 0, sizeof *r);
-  r->low = low;
-  r->next = info->pending_ranges;
-  info->pending_ranges = r;
-  return true;
-}  
-
-/* Finish a range started by ieee_start_range.  */
+/* Append a buffer chain.  */
 
-static boolean
-ieee_end_range (info, high)
-     struct ieee_handle *info;
-     bfd_vma high;
+static bfd_boolean
+ieee_append_buffer (struct ieee_handle *info ATTRIBUTE_UNUSED,
+                   struct ieee_buflist *mainbuf,
+                   struct ieee_buflist *newbuf)
 {
-  struct ieee_range *r;
-  bfd_vma low;
-
-  assert (info->pending_ranges != NULL);
-  r = info->pending_ranges;
-  low = r->low;
-  info->pending_ranges = r->next;
-  free (r);
-  return ieee_add_range (info, low, high);
+  if (newbuf->head != NULL)
+    {
+      if (mainbuf->head == NULL)
+       mainbuf->head = newbuf->head;
+      else
+       mainbuf->tail->next = newbuf->head;
+      mainbuf->tail = newbuf->tail;
+    }
+  return TRUE;
 }
 
 /* Write a byte into the buffer.  We use a macro for speed and a
    function for the complex cases.  */
 
 #define ieee_write_byte(info, b)                               \
-  ((info)->current->c < IEEE_BUFSIZE                           \
-   ? ((info)->current->buf[(info)->current->c++] = (b), true)  \
+  ((info)->curbuf->c < IEEE_BUFSIZE                            \
+   ? ((info)->curbuf->buf[(info)->curbuf->c++] = (b), TRUE)    \
    : ieee_real_write_byte ((info), (b)))
 
-static boolean
-ieee_real_write_byte (info, b)
-     struct ieee_handle *info;
-     int b;
+static bfd_boolean
+ieee_real_write_byte (struct ieee_handle *info, int b)
 {
-  if (info->current->c >= IEEE_BUFSIZE)
+  if (info->curbuf->c >= IEEE_BUFSIZE)
     {
       struct ieee_buf *n;
 
       n = (struct ieee_buf *) xmalloc (sizeof *n);
       n->next = NULL;
       n->c = 0;
-      info->current->next = n;
-      info->current = n;
+      if (info->current->head == NULL)
+       info->current->head = n;
+      else
+       info->current->tail->next = n;
+      info->current->tail = n;
+      info->curbuf = n;
     }
 
-  info->current->buf[info->current->c] = b;
-  ++info->current->c;
+  info->curbuf->buf[info->curbuf->c] = b;
+  ++info->curbuf->c;
 
-  return true;
+  return TRUE;
 }
 
 /* Write out two bytes.  */
 
-static boolean
-ieee_write_2bytes (info, i)
-     struct ieee_handle *info;
-     int i;
+static bfd_boolean
+ieee_write_2bytes (struct ieee_handle *info, int i)
 {
   return (ieee_write_byte (info, i >> 8)
          && ieee_write_byte (info, i & 0xff));
@@ -3610,10 +4132,8 @@ ieee_write_2bytes (info, i)
 
 /* Write out an integer.  */
 
-static boolean
-ieee_write_number (info, v)
-     struct ieee_handle *info;
-     bfd_vma v;
+static bfd_boolean
+ieee_write_number (struct ieee_handle *info, bfd_vma v)
 {
   bfd_vma t;
   bfd_byte ab[20];
@@ -3635,29 +4155,27 @@ ieee_write_number (info, v)
   if (c > (unsigned int) (ieee_number_repeat_end_enum
                          - ieee_number_repeat_start_enum))
     {
-      fprintf (stderr, "IEEE numeric overflow: 0x");
+      fprintf (stderr, _("IEEE numeric overflow: 0x"));
       fprintf_vma (stderr, v);
       fprintf (stderr, "\n");
-      return false;
+      return FALSE;
     }
 
   if (! ieee_write_byte (info, (int) ieee_number_repeat_start_enum + c))
-    return false;
+    return FALSE;
   for (; c > 0; --c, ++p)
     {
       if (! ieee_write_byte (info, *p))
-       return false;
+       return FALSE;
     }
 
-  return true;
+  return TRUE;
 }
 
 /* Write out a string.  */
 
-static boolean
-ieee_write_id (info, s)
-     struct ieee_handle *info;
-     const char *s;
+static bfd_boolean
+ieee_write_id (struct ieee_handle *info, const char *s)
 {
   unsigned int len;
 
@@ -3665,40 +4183,37 @@ ieee_write_id (info, s)
   if (len <= 0x7f)
     {
       if (! ieee_write_byte (info, len))
-       return false;
+       return FALSE;
     }
   else if (len <= 0xff)
     {
       if (! ieee_write_byte (info, (int) ieee_extension_length_1_enum)
          || ! ieee_write_byte (info, len))
-       return false;
+       return FALSE;
     }
   else if (len <= 0xffff)
     {
       if (! ieee_write_byte (info, (int) ieee_extension_length_2_enum)
          || ! ieee_write_2bytes (info, len))
-       return false;
+       return FALSE;
     }
   else
     {
-      fprintf (stderr, "IEEE string length overflow: %u\n", len);
-      return false;
+      fprintf (stderr, _("IEEE string length overflow: %u\n"), len);
+      return FALSE;
     }
 
   for (; *s != '\0'; s++)
     if (! ieee_write_byte (info, *s))
-      return false;
+      return FALSE;
 
-  return true;
+  return TRUE;
 }
 
 /* Write out an ASN record.  */
 
-static boolean
-ieee_write_asn (info, indx, val)
-     struct ieee_handle *info;
-     unsigned int indx;
-     bfd_vma val;
+static bfd_boolean
+ieee_write_asn (struct ieee_handle *info, unsigned int indx, bfd_vma val)
 {
   return (ieee_write_2bytes (info, (int) ieee_asn_record_enum)
          && ieee_write_number (info, indx)
@@ -3707,11 +4222,8 @@ ieee_write_asn (info, indx, val)
 
 /* Write out an ATN65 record.  */
 
-static boolean
-ieee_write_atn65 (info, indx, s)
-     struct ieee_handle *info;
-     unsigned int indx;
-     const char *s;
+static bfd_boolean
+ieee_write_atn65 (struct ieee_handle *info, unsigned int indx, const char *s)
 {
   return (ieee_write_2bytes (info, (int) ieee_atn_record_enum)
          && ieee_write_number (info, indx)
@@ -3720,78 +4232,215 @@ ieee_write_atn65 (info, indx, s)
          && ieee_write_id (info, s));
 }
 
-/* Start defining a type.  */
+/* Push a type index onto the type stack.  */
 
-static boolean
-ieee_define_type (info, size, unsignedp)
-     struct ieee_handle *info;
-     unsigned int size;
-     boolean unsignedp;
+static bfd_boolean
+ieee_push_type (struct ieee_handle *info, unsigned int indx,
+               unsigned int size, bfd_boolean unsignedp, bfd_boolean localp)
 {
-  return ieee_define_named_type (info, (const char *) NULL, false, 0, size,
-                                unsignedp, (struct ieee_buf **) NULL);
+  struct ieee_type_stack *ts;
+
+  ts = (struct ieee_type_stack *) xmalloc (sizeof *ts);
+  memset (ts, 0, sizeof *ts);
+
+  ts->type.indx = indx;
+  ts->type.size = size;
+  ts->type.unsignedp = unsignedp;
+  ts->type.localp = localp;
+
+  ts->next = info->type_stack;
+  info->type_stack = ts;
+
+  return TRUE;
 }
 
-/* Start defining a named type.  */
+/* Pop a type index off the type stack.  */
 
-static boolean
-ieee_define_named_type (info, name, tagp, id, size, unsignedp, ppbuf)
-     struct ieee_handle *info;
-     const char *name;
-     boolean tagp;
-     unsigned int id;
-     unsigned int size;
-     boolean unsignedp;
-     struct ieee_buf **ppbuf;
+static unsigned int
+ieee_pop_type (struct ieee_handle *info)
 {
-  unsigned int type_indx;
-  unsigned int name_indx;
+  return ieee_pop_type_used (info, TRUE);
+}
 
-  if (! tagp || id == (unsigned int) -1)
-    {
-      type_indx = info->type_indx;
-      ++info->type_indx;
-    }
-  else
+/* Pop an unused type index off the type stack.  */
+
+static void
+ieee_pop_unused_type (struct ieee_handle *info)
+{
+  (void) ieee_pop_type_used (info, FALSE);
+}
+
+/* Pop a used or unused type index off the type stack.  */
+
+static unsigned int
+ieee_pop_type_used (struct ieee_handle *info, bfd_boolean used)
+{
+  struct ieee_type_stack *ts;
+  unsigned int ret;
+
+  ts = info->type_stack;
+  assert (ts != NULL);
+
+  /* If this is a function type, and we need it, we need to append the
+     actual definition to the typedef block now.  */
+  if (used && ! ieee_buffer_emptyp (&ts->type.fndef))
     {
-      struct ieee_name_type *nt;
-      const char *tag;
-      char ab[20];
+      struct ieee_buflist *buflist;
 
-      /* We need to create a tag for internal use even if we don't
-         want one for external use.  This will let us refer to an
-         anonymous struct.  */
-      if (name != NULL)
-       tag = name;
+      if (ts->type.localp)
+       {
+         /* Make sure we have started the types block.  */
+         if (ieee_buffer_emptyp (&info->types))
+           {
+             if (! ieee_change_buffer (info, &info->types)
+                 || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
+                 || ! ieee_write_byte (info, 1)
+                 || ! ieee_write_number (info, 0)
+                 || ! ieee_write_id (info, info->modname))
+               return FALSE;
+           }
+         buflist = &info->types;
+       }
       else
        {
-         sprintf (ab, "__anon%u", id);
-         tag = ab;
+         /* Make sure we started the global type block.  */
+         if (ieee_buffer_emptyp (&info->global_types))
+           {
+             if (! ieee_change_buffer (info, &info->global_types)
+                 || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
+                 || ! ieee_write_byte (info, 2)
+                 || ! ieee_write_number (info, 0)
+                 || ! ieee_write_id (info, ""))
+               return FALSE;
+           }
+         buflist = &info->global_types;
        }
 
-      /* The name is a tag.  If we have already defined the tag, we
-         must use the existing type index.  */
-      for (nt = info->tags; nt != NULL; nt = nt->next)
-       if (nt->name[0] == tag[0]
-           && strcmp (nt->name, tag) == 0)
-         break;
+      if (! ieee_append_buffer (info, buflist, &ts->type.fndef))
+       return FALSE;
+    }
+
+  ret = ts->type.indx;
+  info->type_stack = ts->next;
+  free (ts);
+  return ret;
+}
 
-      if (nt == NULL)
+/* Add a range of bytes included in the current compilation unit.  */
+
+static bfd_boolean
+ieee_add_range (struct ieee_handle *info, bfd_boolean global, bfd_vma low,
+               bfd_vma high)
+{
+  struct ieee_range **plist, *r, **pr;
+
+  if (low == (bfd_vma) -1 || high == (bfd_vma) -1 || low == high)
+    return TRUE;
+
+  if (global)
+    plist = &info->global_ranges;
+  else
+    plist = &info->ranges;
+
+  for (r = *plist; r != NULL; r = r->next)
+    {
+      if (high >= r->low && low <= r->high)
        {
-         nt = (struct ieee_name_type *) xmalloc (sizeof *nt);
-         memset (nt, 0, sizeof *nt);
-         nt->name = tag;
-         nt->next = info->tags;
-         info->tags = nt;
-         nt->type.indx = info->type_indx;
-         ++info->type_indx;
+         /* The new range overlaps r.  */
+         if (low < r->low)
+           r->low = low;
+         if (high > r->high)
+           r->high = high;
+         pr = &r->next;
+         while (*pr != NULL && (*pr)->low <= r->high)
+           {
+             struct ieee_range *n;
+
+             if ((*pr)->high > r->high)
+               r->high = (*pr)->high;
+             n = (*pr)->next;
+             free (*pr);
+             *pr = n;
+           }
+         return TRUE;
        }
+    }
+
+  r = (struct ieee_range *) xmalloc (sizeof *r);
+  memset (r, 0, sizeof *r);
 
-      nt->type.size = size;
-      nt->type.unsignedp = unsignedp;
-      nt->kind = DEBUG_KIND_ILLEGAL;
+  r->low = low;
+  r->high = high;
+
+  /* Store the ranges sorted by address.  */
+  for (pr = plist; *pr != NULL; pr = &(*pr)->next)
+    if ((*pr)->low > high)
+      break;
+  r->next = *pr;
+  *pr = r;
 
-      type_indx = nt->type.indx;
+  return TRUE;
+}
+
+/* Start a new range for which we only have the low address.  */
+
+static bfd_boolean
+ieee_start_range (struct ieee_handle *info, bfd_vma low)
+{
+  struct ieee_range *r;
+
+  r = (struct ieee_range *) xmalloc (sizeof *r);
+  memset (r, 0, sizeof *r);
+  r->low = low;
+  r->next = info->pending_ranges;
+  info->pending_ranges = r;
+  return TRUE;
+}
+
+/* Finish a range started by ieee_start_range.  */
+
+static bfd_boolean
+ieee_end_range (struct ieee_handle *info, bfd_vma high)
+{
+  struct ieee_range *r;
+  bfd_vma low;
+
+  assert (info->pending_ranges != NULL);
+  r = info->pending_ranges;
+  low = r->low;
+  info->pending_ranges = r->next;
+  free (r);
+  return ieee_add_range (info, FALSE, low, high);
+}
+
+/* Start defining a type.  */
+
+static bfd_boolean
+ieee_define_type (struct ieee_handle *info, unsigned int size,
+                 bfd_boolean unsignedp, bfd_boolean localp)
+{
+  return ieee_define_named_type (info, (const char *) NULL,
+                                (unsigned int) -1, size, unsignedp,
+                                localp, (struct ieee_buflist *) NULL);
+}
+
+/* Start defining a named type.  */
+
+static bfd_boolean
+ieee_define_named_type (struct ieee_handle *info, const char *name,
+                       unsigned int indx, unsigned int size,
+                       bfd_boolean unsignedp, bfd_boolean localp,
+                       struct ieee_buflist *buflist)
+{
+  unsigned int type_indx;
+  unsigned int name_indx;
+
+  if (indx != (unsigned int) -1)
+    type_indx = indx;
+  else
+    {
+      type_indx = info->type_indx;
+      ++info->type_indx;
     }
 
   name_indx = info->name_indx;
@@ -3800,33 +4449,56 @@ ieee_define_named_type (info, name, tagp, id, size, unsignedp, ppbuf)
   if (name == NULL)
     name = "";
 
-  /* If we were given a buffer, use it; otherwise, use the general
-     type information, and make sure that the type block is started.  */
-  if (ppbuf != NULL)
+  /* If we were given a buffer, use it; otherwise, use either the
+     local or the global type information, and make sure that the type
+     block is started.  */
+  if (buflist != NULL)
     {
-      if (! ieee_change_buffer (info, ppbuf))
-       return false;
+      if (! ieee_change_buffer (info, buflist))
+       return FALSE;
     }
-  else if (info->types != NULL)
+  else if (localp)
     {
-      if (! ieee_change_buffer (info, &info->types))
-       return false;
+      if (! ieee_buffer_emptyp (&info->types))
+       {
+         if (! ieee_change_buffer (info, &info->types))
+           return FALSE;
+       }
+      else
+       {
+         if (! ieee_change_buffer (info, &info->types)
+             || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
+             || ! ieee_write_byte (info, 1)
+             || ! ieee_write_number (info, 0)
+             || ! ieee_write_id (info, info->modname))
+           return FALSE;
+       }
     }
   else
     {
-      if (! ieee_change_buffer (info, &info->types)
-         || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
-         || ! ieee_write_byte (info, 1)
-         || ! ieee_write_number (info, 0)
-         || ! ieee_write_id (info, info->modname))
-       return false;
+      if (! ieee_buffer_emptyp (&info->global_types))
+       {
+         if (! ieee_change_buffer (info, &info->global_types))
+           return FALSE;
+       }
+      else
+       {
+         if (! ieee_change_buffer (info, &info->global_types)
+             || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
+             || ! ieee_write_byte (info, 2)
+             || ! ieee_write_number (info, 0)
+             || ! ieee_write_id (info, ""))
+           return FALSE;
+       }
     }
 
   /* Push the new type on the type stack, write out an NN record, and
      write out the start of a TY record.  The caller will then finish
      the TY record.  */
-  return (ieee_push_type (info, type_indx, size, unsignedp)
-         && ieee_write_byte (info, (int) ieee_nn_record)
+  if (! ieee_push_type (info, type_indx, size, unsignedp, localp))
+    return FALSE;
+
+  return (ieee_write_byte (info, (int) ieee_nn_record)
          && ieee_write_number (info, name_indx)
          && ieee_write_id (info, name)
          && ieee_write_byte (info, (int) ieee_ty_record_enum)
@@ -3834,17 +4506,83 @@ ieee_define_named_type (info, name, tagp, id, size, unsignedp, ppbuf)
          && ieee_write_byte (info, 0xce)
          && ieee_write_number (info, name_indx));
 }
+
+/* Get an entry to the list of modified versions of a type.  */
+
+static struct ieee_modified_type *
+ieee_get_modified_info (struct ieee_handle *info, unsigned int indx)
+{
+  if (indx >= info->modified_alloc)
+    {
+      unsigned int nalloc;
+
+      nalloc = info->modified_alloc;
+      if (nalloc == 0)
+       nalloc = 16;
+      while (indx >= nalloc)
+       nalloc *= 2;
+      info->modified = ((struct ieee_modified_type *)
+                       xrealloc (info->modified,
+                                 nalloc * sizeof *info->modified));
+      memset (info->modified + info->modified_alloc, 0,
+             (nalloc - info->modified_alloc) * sizeof *info->modified);
+      info->modified_alloc = nalloc;
+    }
+
+  return info->modified + indx;
+}
+\f
+/* Routines for the hash table mapping names to types.  */
+
+/* Initialize an entry in the hash table.  */
+
+static struct bfd_hash_entry *
+ieee_name_type_newfunc (struct bfd_hash_entry *entry,
+                       struct bfd_hash_table *table, const char *string)
+{
+  struct ieee_name_type_hash_entry *ret =
+    (struct ieee_name_type_hash_entry *) entry;
+
+  /* Allocate the structure if it has not already been allocated by a
+     subclass.  */
+  if (ret == NULL)
+    ret = ((struct ieee_name_type_hash_entry *)
+          bfd_hash_allocate (table, sizeof *ret));
+  if (ret == NULL)
+    return NULL;
+
+  /* Call the allocation method of the superclass.  */
+  ret = ((struct ieee_name_type_hash_entry *)
+        bfd_hash_newfunc ((struct bfd_hash_entry *) ret, table, string));
+  if (ret)
+    {
+      /* Set local fields.  */
+      ret->types = NULL;
+    }
+
+  return (struct bfd_hash_entry *) ret;
+}
+
+/* Look up an entry in the hash table.  */
+
+#define ieee_name_type_hash_lookup(table, string, create, copy) \
+  ((struct ieee_name_type_hash_entry *) \
+   bfd_hash_lookup (&(table)->root, (string), (create), (copy)))
+
+/* Traverse the hash table.  */
+
+#define ieee_name_type_hash_traverse(table, func, info)                        \
+  (bfd_hash_traverse                                                   \
+   (&(table)->root,                                                    \
+    (bfd_boolean (*) (struct bfd_hash_entry *, void *)) (func),                \
+    (info)))
 \f
 /* The general routine to write out IEEE debugging information.  */
 
-boolean
-write_ieee_debugging_info (abfd, dhandle)
-     bfd *abfd;
-     PTR dhandle;
+bfd_boolean
+write_ieee_debugging_info (bfd *abfd, void *dhandle)
 {
   struct ieee_handle info;
-  struct ieee_buf *tags;
-  struct ieee_name_type *nt;
   asection *s;
   const char *err;
   struct ieee_buf *b;
@@ -3854,85 +4592,88 @@ write_ieee_debugging_info (abfd, dhandle)
   info.type_indx = 256;
   info.name_indx = 32;
 
-  if (! debug_write (dhandle, &ieee_fns, (PTR) &info))
-    return false;
+  if (!bfd_hash_table_init (&info.typedefs.root, ieee_name_type_newfunc,
+                           sizeof (struct ieee_name_type_hash_entry))
+      || !bfd_hash_table_init (&info.tags.root, ieee_name_type_newfunc,
+                              sizeof (struct ieee_name_type_hash_entry)))
+    return FALSE;
+
+  if (! ieee_init_buffer (&info, &info.global_types)
+      || ! ieee_init_buffer (&info, &info.data)
+      || ! ieee_init_buffer (&info, &info.types)
+      || ! ieee_init_buffer (&info, &info.vars)
+      || ! ieee_init_buffer (&info, &info.cxx)
+      || ! ieee_init_buffer (&info, &info.linenos)
+      || ! ieee_init_buffer (&info, &info.fntype)
+      || ! ieee_init_buffer (&info, &info.fnargs))
+    return FALSE;
+
+  if (! debug_write (dhandle, &ieee_fns, (void *) &info))
+    return FALSE;
 
   if (info.filename != NULL)
     {
       if (! ieee_finish_compilation_unit (&info))
-       return false;
+       return FALSE;
     }
 
   /* Put any undefined tags in the global typedef information.  */
-  tags = NULL;
-  for (nt = info.tags; nt != NULL; nt = nt->next)
+  info.error = FALSE;
+  ieee_name_type_hash_traverse (&info.tags,
+                               ieee_write_undefined_tag,
+                               (void *) &info);
+  if (info.error)
+    return FALSE;
+
+  /* Prepend the global typedef information to the other data.  */
+  if (! ieee_buffer_emptyp (&info.global_types))
     {
-      unsigned int name_indx;
-      char code;
-
-      if (nt->kind == DEBUG_KIND_ILLEGAL)
-       continue;
-      if (tags == NULL)
-       {
-         if (! ieee_change_buffer (&info, &tags)
-             || ! ieee_write_byte (&info, (int) ieee_bb_record_enum)
-             || ! ieee_write_byte (&info, 2)
-             || ! ieee_write_number (&info, 0)
-             || ! ieee_write_id (&info, ""))
-           return false;
-       }
-      name_indx = info.name_indx;
-      ++info.name_indx;
-      if (! ieee_write_byte (&info, (int) ieee_nn_record)
-         || ! ieee_write_number (&info, name_indx)
-         || ! ieee_write_id (&info, nt->name)
+      /* The HP debugger seems to have a bug in which it ignores the
+         last entry in the global types, so we add a dummy entry.  */
+      if (! ieee_change_buffer (&info, &info.global_types)
+         || ! ieee_write_byte (&info, (int) ieee_nn_record)
+         || ! ieee_write_number (&info, info.name_indx)
+         || ! ieee_write_id (&info, "")
          || ! ieee_write_byte (&info, (int) ieee_ty_record_enum)
-         || ! ieee_write_number (&info, nt->type.indx)
+         || ! ieee_write_number (&info, info.type_indx)
          || ! ieee_write_byte (&info, 0xce)
-         || ! ieee_write_number (&info, name_indx))
-       return false;
-      switch (nt->kind)
-       {
-       default:
-         abort ();
-         return false;
-       case DEBUG_KIND_STRUCT:
-       case DEBUG_KIND_CLASS:
-         code = 'S';
-         break;
-       case DEBUG_KIND_UNION:
-       case DEBUG_KIND_UNION_CLASS:
-         code = 'U';
-         break;
-       case DEBUG_KIND_ENUM:
-         code = 'E';
-         break;
-       }
-      if (! ieee_write_number (&info, code)
-         || ! ieee_write_number (&info, 0))
-       return false;
+         || ! ieee_write_number (&info, info.name_indx)
+         || ! ieee_write_number (&info, 'P')
+         || ! ieee_write_number (&info, (int) builtin_void + 32)
+         || ! ieee_write_byte (&info, (int) ieee_be_record_enum))
+       return FALSE;
+
+      if (! ieee_append_buffer (&info, &info.global_types, &info.data))
+       return FALSE;
+      info.data = info.global_types;
     }
-  if (tags != NULL)
-    {
-      struct ieee_buf **pb;
 
-      if (! ieee_write_byte (&info, (int) ieee_be_record_enum))
-       return false;
+  /* Make sure that we have declare BB11 blocks for each range in the
+     file.  They are added to info->vars.  */
+  info.error = FALSE;
+  if (! ieee_init_buffer (&info, &info.vars))
+    return FALSE;
+  bfd_map_over_sections (abfd, ieee_add_bb11_blocks, (void *) &info);
+  if (info.error)
+    return FALSE;
+  if (! ieee_buffer_emptyp (&info.vars))
+    {
+      if (! ieee_change_buffer (&info, &info.vars)
+         || ! ieee_write_byte (&info, (int) ieee_be_record_enum))
+       return FALSE;
 
-      for (pb = &tags; *pb != NULL; pb = &(*pb)->next)
-       ;
-      *pb = info.data;
-      info.data = tags;
+      if (! ieee_append_buffer (&info, &info.data, &info.vars))
+       return FALSE;
     }
 
   /* Now all the data is in info.data.  Write it out to the BFD.  We
      normally would need to worry about whether all the other sections
      are set up yet, but the IEEE backend will handle this particular
      case correctly regardless.  */
-  if (info.data == NULL)
+  if (ieee_buffer_emptyp (&info.data))
     {
       /* There is no debugging information.  */
-      return true;
+      return TRUE;
     }
   err = NULL;
   s = bfd_make_section (abfd, ".debug");
@@ -3948,7 +4689,7 @@ write_ieee_debugging_info (abfd, dhandle)
       bfd_size_type size;
 
       size = 0;
-      for (b = info.data; b != NULL; b = b->next)
+      for (b = info.data.head; b != NULL; b = b->next)
        size += b->c;
       if (! bfd_set_section_size (abfd, s, size))
        err = "bfd_set_section_size";
@@ -3958,7 +4699,7 @@ write_ieee_debugging_info (abfd, dhandle)
       file_ptr offset;
 
       offset = 0;
-      for (b = info.data; b != NULL; b = b->next)
+      for (b = info.data.head; b != NULL; b = b->next)
        {
          if (! bfd_set_section_contents (abfd, s, b->buf, offset, b->c))
            {
@@ -3973,90 +4714,188 @@ write_ieee_debugging_info (abfd, dhandle)
     {
       fprintf (stderr, "%s: %s: %s\n", bfd_get_filename (abfd), err,
               bfd_errmsg (bfd_get_error ()));
-      return false;
+      return FALSE;
+    }
+
+  bfd_hash_table_free (&info.typedefs.root);
+  bfd_hash_table_free (&info.tags.root);
+
+  return TRUE;
+}
+
+/* Write out information for an undefined tag.  This is called via
+   ieee_name_type_hash_traverse.  */
+
+static bfd_boolean
+ieee_write_undefined_tag (struct ieee_name_type_hash_entry *h, void *p)
+{
+  struct ieee_handle *info = (struct ieee_handle *) p;
+  struct ieee_name_type *nt;
+
+  for (nt = h->types; nt != NULL; nt = nt->next)
+    {
+      unsigned int name_indx;
+      char code;
+
+      if (nt->kind == DEBUG_KIND_ILLEGAL)
+       continue;
+
+      if (ieee_buffer_emptyp (&info->global_types))
+       {
+         if (! ieee_change_buffer (info, &info->global_types)
+             || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
+             || ! ieee_write_byte (info, 2)
+             || ! ieee_write_number (info, 0)
+             || ! ieee_write_id (info, ""))
+           {
+             info->error = TRUE;
+             return FALSE;
+           }
+       }
+      else
+       {
+         if (! ieee_change_buffer (info, &info->global_types))
+           {
+             info->error = TRUE;
+             return FALSE;
+           }
+       }
+
+      name_indx = info->name_indx;
+      ++info->name_indx;
+      if (! ieee_write_byte (info, (int) ieee_nn_record)
+         || ! ieee_write_number (info, name_indx)
+         || ! ieee_write_id (info, nt->type.name)
+         || ! ieee_write_byte (info, (int) ieee_ty_record_enum)
+         || ! ieee_write_number (info, nt->type.indx)
+         || ! ieee_write_byte (info, 0xce)
+         || ! ieee_write_number (info, name_indx))
+       {
+         info->error = TRUE;
+         return FALSE;
+       }
+
+      switch (nt->kind)
+       {
+       default:
+         abort ();
+         info->error = TRUE;
+         return FALSE;
+       case DEBUG_KIND_STRUCT:
+       case DEBUG_KIND_CLASS:
+         code = 'S';
+         break;
+       case DEBUG_KIND_UNION:
+       case DEBUG_KIND_UNION_CLASS:
+         code = 'U';
+         break;
+       case DEBUG_KIND_ENUM:
+         code = 'E';
+         break;
+       }
+      if (! ieee_write_number (info, code)
+         || ! ieee_write_number (info, 0))
+       {
+         info->error = TRUE;
+         return FALSE;
+       }
     }
 
-  return true;
+  return TRUE;
 }
 
 /* Start writing out information for a compilation unit.  */
 
-static boolean
-ieee_start_compilation_unit (p, filename)
-     PTR p;
-     const char *filename;
+static bfd_boolean
+ieee_start_compilation_unit (void *p, const char *filename)
 {
   struct ieee_handle *info = (struct ieee_handle *) p;
   const char *modname;
+#ifdef HAVE_DOS_BASED_FILE_SYSTEM
+  const char *backslash;
+#endif
   char *c, *s;
+  unsigned int nindx;
 
   if (info->filename != NULL)
     {
       if (! ieee_finish_compilation_unit (info))
-       return false;
+       return FALSE;
     }
 
   info->filename = filename;
   modname = strrchr (filename, '/');
+#ifdef HAVE_DOS_BASED_FILE_SYSTEM
+  /* We could have a mixed forward/back slash case.  */
+  backslash = strrchr (filename, '\\');
+  if (modname == NULL || (backslash != NULL && backslash > modname))
+    modname = backslash;
+#endif
+
   if (modname != NULL)
     ++modname;
+#ifdef HAVE_DOS_BASED_FILE_SYSTEM
+  else if (filename[0] && filename[1] == ':')
+    modname = filename + 2;
+#endif
   else
-    {
-      modname = strrchr (filename, '\\');
-      if (modname != NULL)
-       ++modname;
-      else
-       modname = filename;
-    }
+    modname = filename;
+
   c = xstrdup (modname);
   s = strrchr (c, '.');
   if (s != NULL)
     *s = '\0';
   info->modname = c;
 
-  info->types = NULL;
-  info->vars = NULL;
-  info->cxx = NULL;
-  info->linenos = NULL;
+  if (! ieee_init_buffer (info, &info->types)
+      || ! ieee_init_buffer (info, &info->vars)
+      || ! ieee_init_buffer (info, &info->cxx)
+      || ! ieee_init_buffer (info, &info->linenos))
+    return FALSE;
   info->ranges = NULL;
 
-  return true;
+  /* Always include a BB1 and a BB3 block.  That is what the output of
+     the MRI linker seems to look like.  */
+  if (! ieee_change_buffer (info, &info->types)
+      || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
+      || ! ieee_write_byte (info, 1)
+      || ! ieee_write_number (info, 0)
+      || ! ieee_write_id (info, info->modname))
+    return FALSE;
+
+  nindx = info->name_indx;
+  ++info->name_indx;
+  if (! ieee_change_buffer (info, &info->vars)
+      || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
+      || ! ieee_write_byte (info, 3)
+      || ! ieee_write_number (info, 0)
+      || ! ieee_write_id (info, info->modname))
+    return FALSE;
+
+  return TRUE;
 }
 
 /* Finish up a compilation unit.  */
 
-static boolean
-ieee_finish_compilation_unit (info)
-     struct ieee_handle *info;
+static bfd_boolean
+ieee_finish_compilation_unit (struct ieee_handle *info)
 {
-  struct ieee_buf **pp;
   struct ieee_range *r;
 
-  if (info->types != NULL)
+  if (! ieee_buffer_emptyp (&info->types))
     {
       if (! ieee_change_buffer (info, &info->types)
          || ! ieee_write_byte (info, (int) ieee_be_record_enum))
-       return false;
+       return FALSE;
     }
 
-  if (info->cxx != NULL)
+  if (! ieee_buffer_emptyp (&info->cxx))
     {
       /* Append any C++ information to the global function and
          variable information.  */
-      if (info->vars != NULL)
-       {
-         if (! ieee_change_buffer (info, &info->vars))
-           return false;
-       }
-      else
-       {
-         if (! ieee_change_buffer (info, &info->vars)
-             || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
-             || ! ieee_write_byte (info, 3)
-             || ! ieee_write_number (info, 0)
-             || ! ieee_write_id (info, info->modname))
-           return false;
-       }
+      assert (! ieee_buffer_emptyp (&info->vars));
+      if (! ieee_change_buffer (info, &info->vars))
+       return FALSE;
 
       /* We put the pmisc records in a dummy procedure, just as the
          MRI compiler does.  */
@@ -4066,46 +4905,50 @@ ieee_finish_compilation_unit (info)
          || ! ieee_write_id (info, "__XRYCPP")
          || ! ieee_write_number (info, 0)
          || ! ieee_write_number (info, 0)
-         || ! ieee_write_number (info, info->highaddr))
-       return false;
-
-      for (pp = &info->vars; *pp != NULL; pp = &(*pp)->next)
-       ;
-      *pp = info->cxx;
-
-      if (! ieee_change_buffer (info, &info->vars)
+         || ! ieee_write_number (info, info->highaddr - 1)
+         || ! ieee_append_buffer (info, &info->vars, &info->cxx)
+         || ! ieee_change_buffer (info, &info->vars)
          || ! ieee_write_byte (info, (int) ieee_be_record_enum)
-         || ! ieee_write_number (info, info->highaddr))
-       return false;
+         || ! ieee_write_number (info, info->highaddr - 1))
+       return FALSE;
     }
 
-  if (info->vars != NULL)
+  if (! ieee_buffer_emptyp (&info->vars))
     {
       if (! ieee_change_buffer (info, &info->vars)
          || ! ieee_write_byte (info, (int) ieee_be_record_enum))
-       return false;
+       return FALSE;
     }
 
-  if (info->linenos != NULL)
+  if (info->pending_lineno_filename != NULL)
+    {
+      /* Force out the pending line number.  */
+      if (! ieee_lineno ((void *) info, (const char *) NULL, 0, (bfd_vma) -1))
+       return FALSE;
+    }
+  if (! ieee_buffer_emptyp (&info->linenos))
     {
       if (! ieee_change_buffer (info, &info->linenos)
          || ! ieee_write_byte (info, (int) ieee_be_record_enum))
-       return false;
+       return FALSE;
+      if (strcmp (info->filename, info->lineno_filename) != 0)
+       {
+         /* We were not in the main file.  We just closed the
+             included line number block, and now we must close the
+             main line number block.  */
+         if (! ieee_write_byte (info, (int) ieee_be_record_enum))
+           return FALSE;
+       }
     }
 
-  for (pp = &info->data; *pp != NULL; pp = &(*pp)->next)
-    ;
-  *pp = info->types;
-  for (; *pp != NULL; pp = &(*pp)->next)
-    ;
-  *pp = info->vars;
-  for (; *pp != NULL; pp = &(*pp)->next)
-    ;
-  *pp = info->linenos;
+  if (! ieee_append_buffer (info, &info->data, &info->types)
+      || ! ieee_append_buffer (info, &info->data, &info->vars)
+      || ! ieee_append_buffer (info, &info->data, &info->linenos))
+    return FALSE;
 
   /* Build BB10/BB11 blocks based on the ranges we recorded.  */
   if (! ieee_change_buffer (info, &info->data))
-    return false;
+    return FALSE;
 
   if (! ieee_write_byte (info, (int) ieee_bb_record_enum)
       || ! ieee_write_byte (info, 10)
@@ -4114,7 +4957,7 @@ ieee_finish_compilation_unit (info)
       || ! ieee_write_id (info, "")
       || ! ieee_write_number (info, 0)
       || ! ieee_write_id (info, "GNU objcopy"))
-    return false;
+    return FALSE;
 
   for (r = info->ranges; r != NULL; r = r->next)
     {
@@ -4142,13 +4985,13 @@ ieee_finish_compilation_unit (info)
 
       /* Coalesce ranges if it seems reasonable.  */
       while (r->next != NULL
-            && high + 64 >= r->next->low
+            && high + 0x1000 >= r->next->low
             && (r->next->high
                 <= (bfd_get_section_vma (info->abfd, s)
                     + bfd_section_size (info->abfd, s))))
        {
          r = r->next;
-         high = r->next->high;
+         high = r->high;
        }
 
       if ((s->flags & SEC_CODE) != 0)
@@ -4163,17 +5006,142 @@ ieee_finish_compilation_unit (info)
          || ! ieee_write_number (info, 0)
          || ! ieee_write_id (info, "")
          || ! ieee_write_number (info, kind)
-         || ! ieee_write_number (info, s->index)
+         || ! ieee_write_number (info, s->index + IEEE_SECTION_NUMBER_BASE)
          || ! ieee_write_number (info, low)
          || ! ieee_write_byte (info, (int) ieee_be_record_enum)
          || ! ieee_write_number (info, high - low))
-       return false;
+       return FALSE;
+
+      /* Add this range to the list of global ranges.  */
+      if (! ieee_add_range (info, TRUE, low, high))
+       return FALSE;
     }
 
   if (! ieee_write_byte (info, (int) ieee_be_record_enum))
-    return false;
+    return FALSE;
+
+  return TRUE;
+}
+
+/* Add BB11 blocks describing each range that we have not already
+   described.  */
+
+static void
+ieee_add_bb11_blocks (bfd *abfd ATTRIBUTE_UNUSED, asection *sec, void *data)
+{
+  struct ieee_handle *info = (struct ieee_handle *) data;
+  bfd_vma low, high;
+  struct ieee_range *r;
+
+  low = bfd_get_section_vma (abfd, sec);
+  high = low + bfd_section_size (abfd, sec);
+
+  /* Find the first range at or after this section.  The ranges are
+     sorted by address.  */
+  for (r = info->global_ranges; r != NULL; r = r->next)
+    if (r->high > low)
+      break;
+
+  while (low < high)
+    {
+      if (r == NULL || r->low >= high)
+       {
+         if (! ieee_add_bb11 (info, sec, low, high))
+           info->error = TRUE;
+         return;
+       }
+
+      if (low < r->low
+         && r->low - low > 0x100)
+       {
+         if (! ieee_add_bb11 (info, sec, low, r->low))
+           {
+             info->error = TRUE;
+             return;
+           }
+       }
+      low = r->high;
+
+      r = r->next;
+    }
+}
+
+/* Add a single BB11 block for a range.  We add it to info->vars.  */
+
+static bfd_boolean
+ieee_add_bb11 (struct ieee_handle *info, asection *sec, bfd_vma low,
+              bfd_vma high)
+{
+  int kind;
+
+  if (! ieee_buffer_emptyp (&info->vars))
+    {
+      if (! ieee_change_buffer (info, &info->vars))
+       return FALSE;
+    }
+  else
+    {
+      const char *filename, *modname;
+#ifdef HAVE_DOS_BASED_FILE_SYSTEM
+      const char *backslash;
+#endif
+      char *c, *s;
+
+      /* Start the enclosing BB10 block.  */
+      filename = bfd_get_filename (info->abfd);
+      modname = strrchr (filename, '/');
+#ifdef HAVE_DOS_BASED_FILE_SYSTEM
+      backslash = strrchr (filename, '\\');
+      if (modname == NULL || (backslash != NULL && backslash > modname))
+       modname = backslash;
+#endif
+
+      if (modname != NULL)
+       ++modname;
+#ifdef HAVE_DOS_BASED_FILE_SYSTEM
+      else if (filename[0] && filename[1] == ':')
+       modname = filename + 2;
+#endif
+      else
+       modname = filename;
+
+      c = xstrdup (modname);
+      s = strrchr (c, '.');
+      if (s != NULL)
+       *s = '\0';
+
+      if (! ieee_change_buffer (info, &info->vars)
+         || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
+         || ! ieee_write_byte (info, 10)
+         || ! ieee_write_number (info, 0)
+         || ! ieee_write_id (info, c)
+         || ! ieee_write_id (info, "")
+         || ! ieee_write_number (info, 0)
+         || ! ieee_write_id (info, "GNU objcopy"))
+       return FALSE;
+
+      free (c);
+    }
+
+  if ((sec->flags & SEC_CODE) != 0)
+    kind = 1;
+  else if ((sec->flags & SEC_READONLY) != 0)
+    kind = 3;
+  else
+    kind = 2;
+
+  if (! ieee_write_byte (info, (int) ieee_bb_record_enum)
+      || ! ieee_write_byte (info, 11)
+      || ! ieee_write_number (info, 0)
+      || ! ieee_write_id (info, "")
+      || ! ieee_write_number (info, kind)
+      || ! ieee_write_number (info, sec->index + IEEE_SECTION_NUMBER_BASE)
+      || ! ieee_write_number (info, low)
+      || ! ieee_write_byte (info, (int) ieee_be_record_enum)
+      || ! ieee_write_number (info, high - low))
+    return FALSE;
 
-  return true;
+  return TRUE;
 }
 
 /* Start recording information from a particular source file.  This is
@@ -4182,44 +5150,37 @@ ieee_finish_compilation_unit (info)
    down the file name anyhow.  IEEE debugging information doesn't seem
    to store this information anywhere.  */
 
-/*ARGSUSED*/
-static boolean
-ieee_start_source (p, filename)
-     PTR p;
-     const char *filename;
+static bfd_boolean
+ieee_start_source (void *p ATTRIBUTE_UNUSED,
+                  const char *filename ATTRIBUTE_UNUSED)
 {
-  return true;
+  return TRUE;
 }
 
 /* Make an empty type.  */
 
-static boolean
-ieee_empty_type (p)
-     PTR p;
+static bfd_boolean
+ieee_empty_type (void *p)
 {
   struct ieee_handle *info = (struct ieee_handle *) p;
 
-  return ieee_push_type (info, 0, 0, false);
+  return ieee_push_type (info, (int) builtin_unknown, 0, FALSE, FALSE);
 }
 
 /* Make a void type.  */
 
-static boolean
-ieee_void_type (p)
-     PTR p;
+static bfd_boolean
+ieee_void_type (void *p)
 {
   struct ieee_handle *info = (struct ieee_handle *) p;
 
-  return ieee_push_type (info, 1, 0, false);
+  return ieee_push_type (info, (int) builtin_void, 0, FALSE, FALSE);
 }
 
 /* Make an integer type.  */
 
-static boolean
-ieee_int_type (p, size, unsignedp)
-     PTR p;
-     unsigned int size;
-     boolean unsignedp;
+static bfd_boolean
+ieee_int_type (void *p, unsigned int size, bfd_boolean unsignedp)
 {
   struct ieee_handle *info = (struct ieee_handle *) p;
   unsigned int indx;
@@ -4239,22 +5200,20 @@ ieee_int_type (p, size, unsignedp)
       indx = (int) builtin_signed_long_long;
       break;
     default:
-      fprintf (stderr, "IEEE unsupported integer type size %u\n", size);
-      return false;
+      fprintf (stderr, _("IEEE unsupported integer type size %u\n"), size);
+      return FALSE;
     }
 
   if (unsignedp)
     ++indx;
 
-  return ieee_push_type (info, indx, size, unsignedp);
+  return ieee_push_type (info, indx, size, unsignedp, FALSE);
 }
 
 /* Make a floating point type.  */
 
-static boolean
-ieee_float_type (p, size)
-     PTR p;
-     unsigned int size;
+static bfd_boolean
+ieee_float_type (void *p, unsigned int size)
 {
   struct ieee_handle *info = (struct ieee_handle *) p;
   unsigned int indx;
@@ -4275,19 +5234,17 @@ ieee_float_type (p, size)
       indx = (int) builtin_long_long_double;
       break;
     default:
-      fprintf (stderr, "IEEE unsupported float type size %u\n", size);
-      return false;
+      fprintf (stderr, _("IEEE unsupported float type size %u\n"), size);
+      return FALSE;
     }
 
-  return ieee_push_type (info, indx, size, false);
+  return ieee_push_type (info, indx, size, FALSE, FALSE);
 }
 
 /* Make a complex type.  */
 
-static boolean
-ieee_complex_type (p, size)
-     PTR p;
-     unsigned int size;
+static bfd_boolean
+ieee_complex_type (void *p, unsigned int size)
 {
   struct ieee_handle *info = (struct ieee_handle *) p;
   char code;
@@ -4295,150 +5252,282 @@ ieee_complex_type (p, size)
   switch (size)
     {
     case 4:
+      if (info->complex_float_index != 0)
+       return ieee_push_type (info, info->complex_float_index, size * 2,
+                              FALSE, FALSE);
       code = 'c';
       break;
+    case 12:
+    case 16:
+      /* These cases can be output by gcc -gstabs.  Outputting the
+         wrong type is better than crashing.  */
     case 8:
+      if (info->complex_double_index != 0)
+       return ieee_push_type (info, info->complex_double_index, size * 2,
+                              FALSE, FALSE);
       code = 'd';
       break;
     default:
-      fprintf (stderr, "IEEE unsupported complex type size %u\n", size);
-      return false;
+      fprintf (stderr, _("IEEE unsupported complex type size %u\n"), size);
+      return FALSE;
     }
 
   /* FIXME: I don't know what the string is for.  */
-  return (ieee_define_type (info, size, false)
-         && ieee_write_number (info, code)
-         && ieee_write_id (info, ""));
+  if (! ieee_define_type (info, size * 2, FALSE, FALSE)
+      || ! ieee_write_number (info, code)
+      || ! ieee_write_id (info, ""))
+    return FALSE;
+
+  if (size == 4)
+    info->complex_float_index = info->type_stack->type.indx;
+  else
+    info->complex_double_index = info->type_stack->type.indx;
+
+  return TRUE;
 }
 
 /* Make a boolean type.  IEEE doesn't support these, so we just make
    an integer type instead.  */
 
-static boolean
-ieee_bool_type (p, size)
-     PTR p;
-     unsigned int size;
+static bfd_boolean
+ieee_bool_type (void *p, unsigned int size)
 {
-  return ieee_int_type (p, size, true);
+  return ieee_int_type (p, size, TRUE);
 }
 
 /* Make an enumeration.  */
 
-static boolean
-ieee_enum_type (p, tag, names, vals)
-     PTR p;
-     const char *tag;
-     const char **names;
-     bfd_signed_vma *vals;
+static bfd_boolean
+ieee_enum_type (void *p, const char *tag, const char **names,
+               bfd_signed_vma *vals)
 {
   struct ieee_handle *info = (struct ieee_handle *) p;
-  boolean simple;
-  int i;
+  struct ieee_defined_enum *e;
+  bfd_boolean localp, simple;
+  unsigned int indx;
+  int i = 0;
+
+  localp = FALSE;
+  indx = (unsigned int) -1;
+  for (e = info->enums; e != NULL; e = e->next)
+    {
+      if (tag == NULL)
+       {
+         if (e->tag != NULL)
+           continue;
+       }
+      else
+       {
+         if (e->tag == NULL
+             || tag[0] != e->tag[0]
+             || strcmp (tag, e->tag) != 0)
+           continue;
+       }
+
+      if (! e->defined)
+       {
+         /* This enum tag has been seen but not defined.  */
+         indx = e->indx;
+         break;
+       }
+
+      if (names != NULL && e->names != NULL)
+       {
+         for (i = 0; names[i] != NULL && e->names[i] != NULL; i++)
+           {
+             if (names[i][0] != e->names[i][0]
+                 || vals[i] != e->vals[i]
+                 || strcmp (names[i], e->names[i]) != 0)
+               break;
+           }
+       }
+
+      if ((names == NULL && e->names == NULL)
+         || (names != NULL
+             && e->names != NULL
+             && names[i] == NULL
+             && e->names[i] == NULL))
+       {
+         /* We've seen this enum before.  */
+         return ieee_push_type (info, e->indx, 0, TRUE, FALSE);
+       }
+
+      if (tag != NULL)
+       {
+         /* We've already seen an enum of the same name, so we must make
+            sure to output this one locally.  */
+         localp = TRUE;
+         break;
+       }
+    }
 
   /* If this is a simple enumeration, in which the values start at 0
      and always increment by 1, we can use type E.  Otherwise we must
      use type N.  */
 
-  simple = true;
+  simple = TRUE;
   if (names != NULL)
     {
       for (i = 0; names[i] != NULL; i++)
        {
          if (vals[i] != i)
            {
-             simple = false;
+             simple = FALSE;
              break;
            }
        }
     }
 
-  if (! ieee_define_named_type (info, tag, true, (unsigned int) -1, 0,
-                               true, (struct ieee_buf **) NULL)
+  if (! ieee_define_named_type (info, tag, indx, 0, TRUE, localp,
+                               (struct ieee_buflist *) NULL)
       || ! ieee_write_number (info, simple ? 'E' : 'N'))
-    return false;
+    return FALSE;
   if (simple)
     {
       /* FIXME: This is supposed to be the enumeration size, but we
          don't store that.  */
       if (! ieee_write_number (info, 4))
-       return false;
+       return FALSE;
     }
   if (names != NULL)
     {
       for (i = 0; names[i] != NULL; i++)
        {
          if (! ieee_write_id (info, names[i]))
-           return false;
+           return FALSE;
          if (! simple)
            {
              if (! ieee_write_number (info, vals[i]))
-               return false;
+               return FALSE;
            }
        }
     }
 
-  return true;
+  if (! localp)
+    {
+      if (indx == (unsigned int) -1)
+       {
+         e = (struct ieee_defined_enum *) xmalloc (sizeof *e);
+         memset (e, 0, sizeof *e);
+         e->indx = info->type_stack->type.indx;
+         e->tag = tag;
+
+         e->next = info->enums;
+         info->enums = e;
+       }
+
+      e->names = names;
+      e->vals = vals;
+      e->defined = TRUE;
+    }
+
+  return TRUE;
 }
 
 /* Make a pointer type.  */
 
-static boolean
-ieee_pointer_type (p)
-     PTR p;
+static bfd_boolean
+ieee_pointer_type (void *p)
 {
   struct ieee_handle *info = (struct ieee_handle *) p;
+  bfd_boolean localp;
   unsigned int indx;
+  struct ieee_modified_type *m = NULL;
 
+  localp = info->type_stack->type.localp;
   indx = ieee_pop_type (info);
 
-  /* A pointer to a simple builtin type can be obtained by adding 32.  */
+  /* A pointer to a simple builtin type can be obtained by adding 32.
+     FIXME: Will this be a short pointer, and will that matter?  */
   if (indx < 32)
-    return ieee_push_type (info, indx + 32, 0, true);
+    return ieee_push_type (info, indx + 32, 0, TRUE, FALSE);
+
+  if (! localp)
+    {
+      m = ieee_get_modified_info (p, indx);
+      if (m == NULL)
+       return FALSE;
+
+      /* FIXME: The size should depend upon the architecture.  */
+      if (m->pointer > 0)
+       return ieee_push_type (info, m->pointer, 4, TRUE, FALSE);
+    }
+
+  if (! ieee_define_type (info, 4, TRUE, localp)
+      || ! ieee_write_number (info, 'P')
+      || ! ieee_write_number (info, indx))
+    return FALSE;
+
+  if (! localp)
+    m->pointer = info->type_stack->type.indx;
 
-  return (ieee_define_type (info, 0, true)
-         && ieee_write_number (info, 'P')
-         && ieee_write_number (info, indx));
+  return TRUE;
 }
 
-/* Make a function type.  */
+/* Make a function type.  This will be called for a method, but we
+   don't want to actually add it to the type table in that case.  We
+   handle this by defining the type in a private buffer, and only
+   adding that buffer to the typedef block if we are going to use it.  */
 
-static boolean
-ieee_function_type (p, argcount, varargs)
-     PTR p;
-     int argcount;
-     boolean varargs;
+static bfd_boolean
+ieee_function_type (void *p, int argcount, bfd_boolean varargs)
 {
   struct ieee_handle *info = (struct ieee_handle *) p;
+  bfd_boolean localp;
   unsigned int *args = NULL;
   int i;
   unsigned int retindx;
+  struct ieee_buflist fndef;
+  struct ieee_modified_type *m;
+
+  localp = FALSE;
 
   if (argcount > 0)
     {
       args = (unsigned int *) xmalloc (argcount * sizeof *args);
       for (i = argcount - 1; i >= 0; i--)
-       args[i] = ieee_pop_type (info);
+       {
+         if (info->type_stack->type.localp)
+           localp = TRUE;
+         args[i] = ieee_pop_type (info);
+       }
     }
   else if (argcount < 0)
-    varargs = false;
+    varargs = FALSE;
 
+  if (info->type_stack->type.localp)
+    localp = TRUE;
   retindx = ieee_pop_type (info);
 
+  m = NULL;
+  if (argcount < 0 && ! localp)
+    {
+      m = ieee_get_modified_info (p, retindx);
+      if (m == NULL)
+       return FALSE;
+
+      if (m->function > 0)
+       return ieee_push_type (info, m->function, 0, TRUE, FALSE);
+    }
+
   /* An attribute of 0x41 means that the frame and push mask are
      unknown.  */
-  if (! ieee_define_type (info, 0, true)
+  if (! ieee_init_buffer (info, &fndef)
+      || ! ieee_define_named_type (info, (const char *) NULL,
+                                  (unsigned int) -1, 0, TRUE, localp,
+                                  &fndef)
       || ! ieee_write_number (info, 'x')
       || ! ieee_write_number (info, 0x41)
       || ! ieee_write_number (info, 0)
       || ! ieee_write_number (info, 0)
       || ! ieee_write_number (info, retindx)
       || ! ieee_write_number (info, (bfd_vma) argcount + (varargs ? 1 : 0)))
-    return false;
+    return FALSE;
   if (argcount > 0)
     {
       for (i = 0; i < argcount; i++)
        if (! ieee_write_number (info, args[i]))
-         return false;
+         return FALSE;
       free (args);
     }
   if (varargs)
@@ -4446,17 +5535,26 @@ ieee_function_type (p, argcount, varargs)
       /* A varargs function is represented by writing out the last
          argument as type void *, although this makes little sense.  */
       if (! ieee_write_number (info, (bfd_vma) builtin_void + 32))
-       return false;
+       return FALSE;
     }
 
-  return ieee_write_number (info, 0);
+  if (! ieee_write_number (info, 0))
+    return FALSE;
+
+  /* We wrote the information into fndef, in case we don't need it.
+     It will be appended to info->types by ieee_pop_type.  */
+  info->type_stack->type.fndef = fndef;
+
+  if (m != NULL)
+    m->function = info->type_stack->type.indx;
+
+  return TRUE;
 }
 
 /* Make a reference type.  */
 
-static boolean
-ieee_reference_type (p)
-     PTR p;
+static bfd_boolean
+ieee_reference_type (void *p)
 {
   struct ieee_handle *info = (struct ieee_handle *) p;
 
@@ -4464,27 +5562,25 @@ ieee_reference_type (p)
      pmisc record to indicate that it is really a reference.  */
 
   if (! ieee_pointer_type (p))
-    return false;
-  info->type_stack->type.referencep = true;
-  return true;
+    return FALSE;
+  info->type_stack->type.referencep = TRUE;
+  return TRUE;
 }
 
 /* Make a range type.  */
 
-static boolean
-ieee_range_type (p, low, high)
-     PTR p;
-     bfd_signed_vma low;
-     bfd_signed_vma high;
+static bfd_boolean
+ieee_range_type (void *p, bfd_signed_vma low, bfd_signed_vma high)
 {
   struct ieee_handle *info = (struct ieee_handle *) p;
   unsigned int size;
-  boolean unsignedp;
+  bfd_boolean unsignedp, localp;
 
   size = info->type_stack->type.size;
   unsignedp = info->type_stack->type.unsignedp;
-  (void) ieee_pop_type (info);
-  return (ieee_define_type (info, size, unsignedp)
+  localp = info->type_stack->type.localp;
+  ieee_pop_unused_type (info);
+  return (ieee_define_type (info, size, unsignedp, localp)
          && ieee_write_number (info, 'R')
          && ieee_write_number (info, (bfd_vma) low)
          && ieee_write_number (info, (bfd_vma) high)
@@ -4494,49 +5590,85 @@ ieee_range_type (p, low, high)
 
 /* Make an array type.  */
 
-/*ARGSUSED*/
-static boolean
-ieee_array_type (p, low, high, stringp)
-     PTR p;
-     bfd_signed_vma low;
-     bfd_signed_vma high;
-     boolean stringp;
+static bfd_boolean
+ieee_array_type (void *p, bfd_signed_vma low, bfd_signed_vma high,
+                bfd_boolean stringp ATTRIBUTE_UNUSED)
 {
   struct ieee_handle *info = (struct ieee_handle *) p;
   unsigned int eleindx;
+  bfd_boolean localp;
+  unsigned int size;
+  struct ieee_modified_type *m = NULL;
+  struct ieee_modified_array_type *a;
 
   /* IEEE does not store the range, so we just ignore it.  */
-  (void) ieee_pop_type (info);
+  ieee_pop_unused_type (info);
+  localp = info->type_stack->type.localp;
+  size = info->type_stack->type.size;
   eleindx = ieee_pop_type (info);
 
-  if (! ieee_define_type (info, 0, false)
+  /* If we don't know the range, treat the size as exactly one
+     element.  */
+  if (low < high)
+    size *= (high - low) + 1;
+
+  if (! localp)
+    {
+      m = ieee_get_modified_info (info, eleindx);
+      if (m == NULL)
+       return FALSE;
+
+      for (a = m->arrays; a != NULL; a = a->next)
+       {
+         if (a->low == low && a->high == high)
+           return ieee_push_type (info, a->indx, size, FALSE, FALSE);
+       }
+    }
+
+  if (! ieee_define_type (info, size, FALSE, localp)
       || ! ieee_write_number (info, low == 0 ? 'Z' : 'C')
       || ! ieee_write_number (info, eleindx))
-    return false;
+    return FALSE;
   if (low != 0)
     {
       if (! ieee_write_number (info, low))
-       return false;
+       return FALSE;
+    }
+
+  if (! ieee_write_number (info, high + 1))
+    return FALSE;
+
+  if (! localp)
+    {
+      a = (struct ieee_modified_array_type *) xmalloc (sizeof *a);
+      memset (a, 0, sizeof *a);
+
+      a->indx = info->type_stack->type.indx;
+      a->low = low;
+      a->high = high;
+
+      a->next = m->arrays;
+      m->arrays = a;
     }
 
-  return ieee_write_number (info, high);
+  return TRUE;
 }
 
 /* Make a set type.  */
 
-static boolean
-ieee_set_type (p, bitstringp)
-     PTR p;
-     boolean bitstringp;
+static bfd_boolean
+ieee_set_type (void *p, bfd_boolean bitstringp ATTRIBUTE_UNUSED)
 {
   struct ieee_handle *info = (struct ieee_handle *) p;
+  bfd_boolean localp;
   unsigned int eleindx;
 
+  localp = info->type_stack->type.localp;
   eleindx = ieee_pop_type (info);
 
   /* FIXME: We don't know the size, so we just use 4.  */
 
-  return (ieee_define_type (info, 0, true)
+  return (ieee_define_type (info, 0, TRUE, localp)
          && ieee_write_number (info, 's')
          && ieee_write_number (info, 4)
          && ieee_write_number (info, eleindx));
@@ -4544,9 +5676,8 @@ ieee_set_type (p, bitstringp)
 
 /* Make an offset type.  */
 
-static boolean
-ieee_offset_type (p)
-     PTR p;
+static bfd_boolean
+ieee_offset_type (void *p)
 {
   struct ieee_handle *info = (struct ieee_handle *) p;
   unsigned int targetindx, baseindx;
@@ -4561,17 +5692,14 @@ ieee_offset_type (p)
      member.  Unfortunately, it does not describe the target type,
      which seems pretty important.  I'm going to punt this for now.  */
 
-  return ieee_int_type (p, 4, true);
-}  
+  return ieee_int_type (p, 4, TRUE);
+}
 
 /* Make a method type.  */
 
-static boolean
-ieee_method_type (p, domain, argcount, varargs)
-     PTR p;
-     boolean domain;
-     int argcount;
-     boolean varargs;
+static bfd_boolean
+ieee_method_type (void *p, bfd_boolean domain, int argcount,
+                 bfd_boolean varargs)
 {
   struct ieee_handle *info = (struct ieee_handle *) p;
 
@@ -4580,56 +5708,93 @@ ieee_method_type (p, domain, argcount, varargs)
      type.  */
 
   if (domain)
-    (void) ieee_pop_type (info);
+    ieee_pop_unused_type (info);
 
   return ieee_function_type (p, argcount, varargs);
 }
 
 /* Make a const qualified type.  */
 
-static boolean
-ieee_const_type (p)
-     PTR p;
+static bfd_boolean
+ieee_const_type (void *p)
 {
   struct ieee_handle *info = (struct ieee_handle *) p;
   unsigned int size;
-  boolean unsignedp;
+  bfd_boolean unsignedp, localp;
   unsigned int indx;
+  struct ieee_modified_type *m = NULL;
 
   size = info->type_stack->type.size;
   unsignedp = info->type_stack->type.unsignedp;
+  localp = info->type_stack->type.localp;
   indx = ieee_pop_type (info);
-  return (ieee_define_type (info, size, unsignedp)
-         && ieee_write_number (info, 'n')
-         && ieee_write_number (info, 1)
-         && ieee_write_number (info, indx));
+
+  if (! localp)
+    {
+      m = ieee_get_modified_info (info, indx);
+      if (m == NULL)
+       return FALSE;
+
+      if (m->const_qualified > 0)
+       return ieee_push_type (info, m->const_qualified, size, unsignedp,
+                              FALSE);
+    }
+
+  if (! ieee_define_type (info, size, unsignedp, localp)
+      || ! ieee_write_number (info, 'n')
+      || ! ieee_write_number (info, 1)
+      || ! ieee_write_number (info, indx))
+    return FALSE;
+
+  if (! localp)
+    m->const_qualified = info->type_stack->type.indx;
+
+  return TRUE;
 }
 
 /* Make a volatile qualified type.  */
 
-static boolean
-ieee_volatile_type (p)
-     PTR p;
+static bfd_boolean
+ieee_volatile_type (void *p)
 {
   struct ieee_handle *info = (struct ieee_handle *) p;
   unsigned int size;
-  boolean unsignedp;
+  bfd_boolean unsignedp, localp;
   unsigned int indx;
+  struct ieee_modified_type *m = NULL;
 
   size = info->type_stack->type.size;
   unsignedp = info->type_stack->type.unsignedp;
+  localp = info->type_stack->type.localp;
   indx = ieee_pop_type (info);
-  return (ieee_define_type (info, size, unsignedp)
-         && ieee_write_number (info, 'n')
-         && ieee_write_number (info, 2)
-         && ieee_write_number (info, indx));
+
+  if (! localp)
+    {
+      m = ieee_get_modified_info (info, indx);
+      if (m == NULL)
+       return FALSE;
+
+      if (m->volatile_qualified > 0)
+       return ieee_push_type (info, m->volatile_qualified, size, unsignedp,
+                              FALSE);
+    }
+
+  if (! ieee_define_type (info, size, unsignedp, localp)
+      || ! ieee_write_number (info, 'n')
+      || ! ieee_write_number (info, 2)
+      || ! ieee_write_number (info, indx))
+    return FALSE;
+
+  if (! localp)
+    m->volatile_qualified = info->type_stack->type.indx;
+
+  return TRUE;
 }
 
 /* Convert an enum debug_visibility into a CXXFLAGS value.  */
 
 static unsigned int
-ieee_vis_to_flags (visibility)
-     enum debug_visibility visibility;
+ieee_vis_to_flags (enum debug_visibility visibility)
 {
   switch (visibility)
     {
@@ -4649,49 +5814,141 @@ ieee_vis_to_flags (visibility)
    the stack, to avoid confusing type definitions required by the
    fields with the struct type itself.  */
 
-static boolean
-ieee_start_struct_type (p, tag, id, structp, size)
-     PTR p;
-     const char *tag;
-     unsigned int id;
-     boolean structp;
-     unsigned int size;
+static bfd_boolean
+ieee_start_struct_type (void *p, const char *tag, unsigned int id,
+                       bfd_boolean structp, unsigned int size)
 {
   struct ieee_handle *info = (struct ieee_handle *) p;
-  struct ieee_buf *strdef;
+  bfd_boolean localp, ignorep;
+  bfd_boolean copy;
+  char ab[20];
+  const char *look;
+  struct ieee_name_type_hash_entry *h;
+  struct ieee_name_type *nt, *ntlook;
+  struct ieee_buflist strdef;
+
+  localp = FALSE;
+  ignorep = FALSE;
+
+  /* We need to create a tag for internal use even if we don't want
+     one for external use.  This will let us refer to an anonymous
+     struct.  */
+  if (tag != NULL)
+    {
+      look = tag;
+      copy = FALSE;
+    }
+  else
+    {
+      sprintf (ab, "__anon%u", id);
+      look = ab;
+      copy = TRUE;
+    }
+
+  /* If we already have references to the tag, we must use the
+     existing type index.  */
+  h = ieee_name_type_hash_lookup (&info->tags, look, TRUE, copy);
+  if (h == NULL)
+    return FALSE;
+
+  nt = NULL;
+  for (ntlook = h->types; ntlook != NULL; ntlook = ntlook->next)
+    {
+      if (ntlook->id == id)
+       nt = ntlook;
+      else if (! ntlook->type.localp)
+       {
+         /* We are creating a duplicate definition of a globally
+            defined tag.  Force it to be local to avoid
+            confusion.  */
+         localp = TRUE;
+       }
+    }
+
+  if (nt != NULL)
+    {
+      assert (localp == nt->type.localp);
+      if (nt->kind == DEBUG_KIND_ILLEGAL && ! localp)
+       {
+         /* We've already seen a global definition of the type.
+             Ignore this new definition.  */
+         ignorep = TRUE;
+       }
+    }
+  else
+    {
+      nt = (struct ieee_name_type *) xmalloc (sizeof *nt);
+      memset (nt, 0, sizeof *nt);
+      nt->id = id;
+      nt->type.name = h->root.string;
+      nt->next = h->types;
+      h->types = nt;
+      nt->type.indx = info->type_indx;
+      ++info->type_indx;
+    }
+
+  nt->kind = DEBUG_KIND_ILLEGAL;
 
-  strdef = NULL;
-  if (! ieee_define_named_type (info, tag, true, id, size, true, &strdef)
+  if (! ieee_init_buffer (info, &strdef)
+      || ! ieee_define_named_type (info, tag, nt->type.indx, size, TRUE,
+                                  localp, &strdef)
       || ! ieee_write_number (info, structp ? 'S' : 'U')
       || ! ieee_write_number (info, size))
-    return false;
+    return FALSE;
 
+  if (! ignorep)
+    {
+      const char *hold;
+
+      /* We never want nt->type.name to be NULL.  We want the rest of
+        the type to be the object set up on the type stack; it will
+        have a NULL name if tag is NULL.  */
+      hold = nt->type.name;
+      nt->type = info->type_stack->type;
+      nt->type.name = hold;
+    }
+
+  info->type_stack->type.name = tag;
   info->type_stack->type.strdef = strdef;
+  info->type_stack->type.ignorep = ignorep;
 
-  return true;
+  return TRUE;
 }
 
 /* Add a field to a struct.  */
 
-static boolean
-ieee_struct_field (p, name, bitpos, bitsize, visibility)
-     PTR p;
-     const char *name;
-     bfd_vma bitpos;
-     bfd_vma bitsize;
-     enum debug_visibility visibility;
+static bfd_boolean
+ieee_struct_field (void *p, const char *name, bfd_vma bitpos, bfd_vma bitsize,
+                  enum debug_visibility visibility)
 {
   struct ieee_handle *info = (struct ieee_handle *) p;
   unsigned int size;
-  boolean unsignedp;
+  bfd_boolean unsignedp;
+  bfd_boolean referencep;
+  bfd_boolean localp;
   unsigned int indx;
   bfd_vma offset;
 
+  assert (info->type_stack != NULL
+         && info->type_stack->next != NULL
+         && ! ieee_buffer_emptyp (&info->type_stack->next->type.strdef));
+
+  /* If we are ignoring this struct definition, just pop and ignore
+     the type.  */
+  if (info->type_stack->next->type.ignorep)
+    {
+      ieee_pop_unused_type (info);
+      return TRUE;
+    }
+
   size = info->type_stack->type.size;
   unsignedp = info->type_stack->type.unsignedp;
+  referencep = info->type_stack->type.referencep;
+  localp = info->type_stack->type.localp;
   indx = ieee_pop_type (info);
 
-  assert (info->type_stack != NULL && info->type_stack->type.strdef != NULL);
+  if (localp)
+    info->type_stack->type.localp = TRUE;
 
   if (info->type_stack->type.classdef != NULL)
     {
@@ -4709,21 +5966,53 @@ ieee_struct_field (p, name, bitpos, bitsize, visibility)
          || ! ieee_write_asn (info, nindx, flags)
          || ! ieee_write_atn65 (info, nindx, name)
          || ! ieee_write_atn65 (info, nindx, name))
-       return false;
+       return FALSE;
       info->type_stack->type.classdef->pmisccount += 4;
+
+      if (referencep)
+       {
+         unsigned int nindx;
+
+         /* We need to output a record recording that this field is
+             really of reference type.  We put this on the refs field
+             of classdef, so that it can be appended to the C++
+             records after the class is defined.  */
+
+         nindx = info->name_indx;
+         ++info->name_indx;
+
+         if (! ieee_change_buffer (info,
+                                   &info->type_stack->type.classdef->refs)
+             || ! ieee_write_byte (info, (int) ieee_nn_record)
+             || ! ieee_write_number (info, nindx)
+             || ! ieee_write_id (info, "")
+             || ! ieee_write_2bytes (info, (int) ieee_atn_record_enum)
+             || ! ieee_write_number (info, nindx)
+             || ! ieee_write_number (info, 0)
+             || ! ieee_write_number (info, 62)
+             || ! ieee_write_number (info, 80)
+             || ! ieee_write_number (info, 4)
+             || ! ieee_write_asn (info, nindx, 'R')
+             || ! ieee_write_asn (info, nindx, 3)
+             || ! ieee_write_atn65 (info, nindx, info->type_stack->type.name)
+             || ! ieee_write_atn65 (info, nindx, name))
+           return FALSE;
+       }
     }
 
   /* If the bitsize doesn't match the expected size, we need to output
      a bitfield type.  */
-  if (size == 0 || bitsize == size * 8)
+  if (size == 0 || bitsize == 0 || bitsize == size * 8)
     offset = bitpos / 8;
   else
     {
-      if (! ieee_define_type (info, 0, unsignedp)
+      if (! ieee_define_type (info, 0, unsignedp,
+                             info->type_stack->type.localp)
          || ! ieee_write_number (info, 'g')
          || ! ieee_write_number (info, unsignedp ? 0 : 1)
+         || ! ieee_write_number (info, bitsize)
          || ! ieee_write_number (info, indx))
-       return false;
+       return FALSE;
       indx = ieee_pop_type (info);
       offset = bitpos;
     }
@@ -4738,55 +6027,76 @@ ieee_struct_field (p, name, bitpos, bitsize, visibility)
 
 /* Finish up a struct type.  */
 
-static boolean
-ieee_end_struct_type (p)
-     PTR p;
+static bfd_boolean
+ieee_end_struct_type (void *p)
 {
   struct ieee_handle *info = (struct ieee_handle *) p;
-  struct ieee_buf **pb;
-
-  assert (info->type_stack != NULL && info->type_stack->type.strdef != NULL);
+  struct ieee_buflist *pb;
 
-  /* Make sure we have started the types block.  */
-  if (info->types == NULL)
+  assert (info->type_stack != NULL
+         && ! ieee_buffer_emptyp (&info->type_stack->type.strdef));
+
+  /* If we were ignoring this struct definition because it was a
+     duplicate definition, just through away whatever bytes we have
+     accumulated.  Leave the type on the stack.  */
+  if (info->type_stack->type.ignorep)
+    return TRUE;
+
+  /* If this is not a duplicate definition of this tag, then localp
+     will be FALSE, and we can put it in the global type block.
+     FIXME: We should avoid outputting duplicate definitions which are
+     the same.  */
+  if (! info->type_stack->type.localp)
     {
-      if (! ieee_change_buffer (info, &info->types)
-         || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
-         || ! ieee_write_byte (info, 1)
-         || ! ieee_write_number (info, 0)
-         || ! ieee_write_id (info, info->modname))
-       return false;
+      /* Make sure we have started the global type block.  */
+      if (ieee_buffer_emptyp (&info->global_types))
+       {
+         if (! ieee_change_buffer (info, &info->global_types)
+             || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
+             || ! ieee_write_byte (info, 2)
+             || ! ieee_write_number (info, 0)
+             || ! ieee_write_id (info, ""))
+           return FALSE;
+       }
+      pb = &info->global_types;
+    }
+  else
+    {
+      /* Make sure we have started the types block.  */
+      if (ieee_buffer_emptyp (&info->types))
+       {
+         if (! ieee_change_buffer (info, &info->types)
+             || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
+             || ! ieee_write_byte (info, 1)
+             || ! ieee_write_number (info, 0)
+             || ! ieee_write_id (info, info->modname))
+           return FALSE;
+       }
+      pb = &info->types;
     }
 
   /* Append the struct definition to the types.  */
-  for (pb = &info->types; *pb != NULL; pb = &(*pb)->next)
-    ;
-  *pb = info->type_stack->type.strdef;
-  info->type_stack->type.strdef = NULL;
+  if (! ieee_append_buffer (info, pb, &info->type_stack->type.strdef)
+      || ! ieee_init_buffer (info, &info->type_stack->type.strdef))
+    return FALSE;
 
   /* Leave the struct on the type stack.  */
 
-  return true;
+  return TRUE;
 }
 
 /* Start a class type.  */
 
-static boolean
-ieee_start_class_type (p, tag, id, structp, size, vptr, ownvptr)
-     PTR p;
-     const char *tag;
-     unsigned int id;
-     boolean structp;
-     unsigned int size;
-     boolean vptr;
-     boolean ownvptr;
+static bfd_boolean
+ieee_start_class_type (void *p, const char *tag, unsigned int id,
+                      bfd_boolean structp, unsigned int size,
+                      bfd_boolean vptr, bfd_boolean ownvptr)
 {
   struct ieee_handle *info = (struct ieee_handle *) p;
   const char *vclass;
-  struct ieee_buf *pmiscbuf;
+  struct ieee_buflist pmiscbuf;
   unsigned int indx;
   struct ieee_type_class *classdef;
-  struct ieee_name_type *nt;
 
   /* A C++ class is output as a C++ struct along with a set of pmisc
      records describing the class.  */
@@ -4808,13 +6118,15 @@ ieee_start_class_type (p, tag, id, structp, size, vptr, ownvptr)
   vclass = NULL;
   if (vptr && ! ownvptr)
     {
-      assert (info->type_stack->type.classdef != NULL);
-      vclass = info->type_stack->type.classdef->name;
+      vclass = info->type_stack->type.name;
+      assert (vclass != NULL);
+      /* We don't call ieee_pop_unused_type, since the class should
+         get defined.  */
       (void) ieee_pop_type (info);
     }
 
   if (! ieee_start_struct_type (p, tag, id, structp, size))
-    return false;
+    return FALSE;
 
   indx = info->name_indx;
   ++info->name_indx;
@@ -4822,17 +6134,16 @@ ieee_start_class_type (p, tag, id, structp, size, vptr, ownvptr)
   /* We write out pmisc records into the classdef field.  We will
      write out the pmisc start after we know the number of records we
      need.  */
-  pmiscbuf = NULL;
-  if (! ieee_change_buffer (info, &pmiscbuf)
+  if (! ieee_init_buffer (info, &pmiscbuf)
+      || ! ieee_change_buffer (info, &pmiscbuf)
       || ! ieee_write_asn (info, indx, 'T')
       || ! ieee_write_asn (info, indx, structp ? 'o' : 'u')
       || ! ieee_write_atn65 (info, indx, tag))
-    return false;
+    return FALSE;
 
   classdef = (struct ieee_type_class *) xmalloc (sizeof *classdef);
   memset (classdef, 0, sizeof *classdef);
 
-  classdef->name = tag;
   classdef->indx = indx;
   classdef->pmiscbuf = pmiscbuf;
   classdef->pmisccount = 3;
@@ -4841,35 +6152,23 @@ ieee_start_class_type (p, tag, id, structp, size, vptr, ownvptr)
 
   info->type_stack->type.classdef = classdef;
 
-  /* We need to fill in the classdef in the tag as well, so that it
-     will be set when ieee_tag_type is called.  */
-  for (nt = info->tags; nt != NULL; nt = nt->next)
-    if (nt->name[0] == tag[0]
-       && strcmp (nt->name, tag) == 0)
-      break;
-  assert (nt != NULL);
-  nt->type.classdef = classdef;
-
-  return true;
+  return TRUE;
 }
 
 /* Add a static member to a class.  */
 
-static boolean
-ieee_class_static_member (p, name, physname, visibility)
-     PTR p;
-     const char *name;
-     const char *physname;
-     enum debug_visibility visibility;
+static bfd_boolean
+ieee_class_static_member (void *p, const char *name, const char *physname,
+                         enum debug_visibility visibility)
 {
   struct ieee_handle *info = (struct ieee_handle *) p;
   unsigned int flags;
   unsigned int nindx;
 
-  /* We don't care about the type.  Hopefully there will be a call
+  /* We don't care about the type.  Hopefully there will be a call to
      ieee_variable declaring the physical name and the type, since
      that is where an IEEE consumer must get the type.  */
-  (void) ieee_pop_type (info);
+  ieee_pop_unused_type (info);
 
   assert (info->type_stack != NULL
          && info->type_stack->type.classdef != NULL);
@@ -4884,35 +6183,34 @@ ieee_class_static_member (p, name, physname, visibility)
       || ! ieee_write_asn (info, nindx, flags)
       || ! ieee_write_atn65 (info, nindx, name)
       || ! ieee_write_atn65 (info, nindx, physname))
-    return false;
+    return FALSE;
   info->type_stack->type.classdef->pmisccount += 4;
 
-  return true;
+  return TRUE;
 }
 
 /* Add a base class to a class.  */
 
-static boolean
-ieee_class_baseclass (p, bitpos, virtual, visibility)
-     PTR p;
-     bfd_vma bitpos;
-     boolean virtual;
-     enum debug_visibility visibility;
+static bfd_boolean
+ieee_class_baseclass (void *p, bfd_vma bitpos, bfd_boolean virtual,
+                     enum debug_visibility visibility)
 {
   struct ieee_handle *info = (struct ieee_handle *) p;
   const char *bname;
+  bfd_boolean localp;
   unsigned int bindx;
   char *fname;
   unsigned int flags;
   unsigned int nindx;
 
   assert (info->type_stack != NULL
-         && info->type_stack->type.classdef != NULL
+         && info->type_stack->type.name != NULL
          && info->type_stack->next != NULL
          && info->type_stack->next->type.classdef != NULL
-         && info->type_stack->next->type.strdef != NULL);
+         && ! ieee_buffer_emptyp (&info->type_stack->next->type.strdef));
 
-  bname = info->type_stack->type.classdef->name;
+  bname = info->type_stack->type.name;
+  localp = info->type_stack->type.localp;
   bindx = ieee_pop_type (info);
 
   /* We are currently defining both a struct and a class.  We must
@@ -4928,6 +6226,9 @@ ieee_class_baseclass (p, bitpos, virtual, visibility)
     }
   else
     {
+      if (localp)
+       info->type_stack->type.localp = TRUE;
+
       fname = (char *) xmalloc (strlen (bname) + sizeof "_b$");
       sprintf (fname, "_b$%s", bname);
 
@@ -4935,7 +6236,7 @@ ieee_class_baseclass (p, bitpos, virtual, visibility)
          || ! ieee_write_id (info, fname)
          || ! ieee_write_number (info, bindx)
          || ! ieee_write_number (info, bitpos / 8))
-       return false;
+       return FALSE;
       flags = 0;
     }
 
@@ -4950,20 +6251,18 @@ ieee_class_baseclass (p, bitpos, virtual, visibility)
       || ! ieee_write_atn65 (info, nindx, bname)
       || ! ieee_write_asn (info, nindx, 0)
       || ! ieee_write_atn65 (info, nindx, fname))
-    return false;
+    return FALSE;
   info->type_stack->type.classdef->pmisccount += 5;
 
   free (fname);
 
-  return true;
+  return TRUE;
 }
 
 /* Start building a method for a class.  */
 
-static boolean
-ieee_class_start_method (p, name)
-     PTR p;
-     const char *name;
+static bfd_boolean
+ieee_class_start_method (void *p, const char *name)
 {
   struct ieee_handle *info = (struct ieee_handle *) p;
 
@@ -4973,36 +6272,31 @@ ieee_class_start_method (p, name)
 
   info->type_stack->type.classdef->method = name;
 
-  return true;
+  return TRUE;
 }
 
 /* Define a new method variant, either static or not.  */
 
-static boolean
-ieee_class_method_var (info, physname, visibility, staticp, constp,
-                      volatilep, voffset, context)
-     struct ieee_handle *info;
-     const char *physname;
-     enum debug_visibility visibility;
-     boolean staticp;
-     boolean constp;
-     boolean volatilep;
-     bfd_vma voffset;
-     boolean context;
+static bfd_boolean
+ieee_class_method_var (struct ieee_handle *info, const char *physname,
+                      enum debug_visibility visibility,
+                      bfd_boolean staticp, bfd_boolean constp,
+                      bfd_boolean volatilep, bfd_vma voffset,
+                      bfd_boolean context)
 {
   unsigned int flags;
   unsigned int nindx;
-  boolean virtual;
+  bfd_boolean virtual;
 
   /* We don't need the type of the method.  An IEEE consumer which
      wants the type must track down the function by the physical name
      and get the type from that.  */
-  (void) ieee_pop_type (info);
+  ieee_pop_unused_type (info);
 
   /* We don't use the context.  FIXME: We probably ought to use it to
      adjust the voffset somehow, but I don't really know how.  */
   if (context)
-    (void) ieee_pop_type (info);
+    ieee_pop_unused_type (info);
 
   assert (info->type_stack != NULL
          && info->type_stack->type.classdef != NULL
@@ -5031,67 +6325,56 @@ ieee_class_method_var (info, physname, visibility, staticp, constp,
       || ! ieee_write_atn65 (info, nindx,
                             info->type_stack->type.classdef->method)
       || ! ieee_write_atn65 (info, nindx, physname))
-    return false;
+    return FALSE;
 
   if (virtual)
     {
       if (voffset > info->type_stack->type.classdef->voffset)
        info->type_stack->type.classdef->voffset = voffset;
-      /* FIXME: The size of a vtable entry depends upon the
-         architecture.  */
-      if (! ieee_write_asn (info, nindx, (voffset / 4) + 1))
-       return false;
+      if (! ieee_write_asn (info, nindx, voffset))
+       return FALSE;
       ++info->type_stack->type.classdef->pmisccount;
     }
 
   if (! ieee_write_asn (info, nindx, 0))
-    return false;
+    return FALSE;
 
   info->type_stack->type.classdef->pmisccount += 5;
 
-  return true;
+  return TRUE;
 }
 
 /* Define a new method variant.  */
 
-static boolean
-ieee_class_method_variant (p, physname, visibility, constp, volatilep,
-                          voffset, context)
-     PTR p;
-     const char *physname;
-     enum debug_visibility visibility;
-     boolean constp;
-     boolean volatilep;
-     bfd_vma voffset;
-     boolean context;
+static bfd_boolean
+ieee_class_method_variant (void *p, const char *physname,
+                          enum debug_visibility visibility,
+                          bfd_boolean constp, bfd_boolean volatilep,
+                          bfd_vma voffset, bfd_boolean context)
 {
   struct ieee_handle *info = (struct ieee_handle *) p;
 
-  return ieee_class_method_var (info, physname, visibility, false, constp,
+  return ieee_class_method_var (info, physname, visibility, FALSE, constp,
                                volatilep, voffset, context);
 }
 
 /* Define a new static method variant.  */
 
-static boolean
-ieee_class_static_method_variant (p, physname, visibility, constp, volatilep)
-     PTR p;
-     const char *physname;
-     enum debug_visibility visibility;
-     boolean constp;
-     boolean volatilep;
+static bfd_boolean
+ieee_class_static_method_variant (void *p, const char *physname,
+                                 enum debug_visibility visibility,
+                                 bfd_boolean constp, bfd_boolean volatilep)
 {
   struct ieee_handle *info = (struct ieee_handle *) p;
 
-  return ieee_class_method_var (info, physname, visibility, true, constp,
-                               volatilep, 0, false);
+  return ieee_class_method_var (info, physname, visibility, TRUE, constp,
+                               volatilep, 0, FALSE);
 }
 
 /* Finish up a method.  */
 
-static boolean
-ieee_class_end_method (p)
-     PTR p;
+static bfd_boolean
+ieee_class_end_method (void *p)
 {
   struct ieee_handle *info = (struct ieee_handle *) p;
 
@@ -5101,52 +6384,52 @@ ieee_class_end_method (p)
 
   info->type_stack->type.classdef->method = NULL;
 
-  return true;
+  return TRUE;
 }
 
 /* Finish up a class.  */
 
-static boolean
-ieee_end_class_type (p)
-     PTR p;
+static bfd_boolean
+ieee_end_class_type (void *p)
 {
   struct ieee_handle *info = (struct ieee_handle *) p;
   unsigned int nindx;
-  struct ieee_buf **pb;
 
   assert (info->type_stack != NULL
          && info->type_stack->type.classdef != NULL);
 
+  /* If we were ignoring this class definition because it was a
+     duplicate definition, just through away whatever bytes we have
+     accumulated.  Leave the type on the stack.  */
+  if (info->type_stack->type.ignorep)
+    return TRUE;
+
   nindx = info->type_stack->type.classdef->indx;
 
   /* If we have a virtual table, we can write out the information now.  */
   if (info->type_stack->type.classdef->vclass != NULL
       || info->type_stack->type.classdef->ownvptr)
     {
-      bfd_vma vsize;
-
-      /* FIXME: This calculation is architecture dependent.  */
-      vsize = (info->type_stack->type.classdef->voffset + 4) / 4;
-
       if (! ieee_change_buffer (info,
                                &info->type_stack->type.classdef->pmiscbuf)
          || ! ieee_write_asn (info, nindx, 'z')
          || ! ieee_write_atn65 (info, nindx, "")
-         || ! ieee_write_asn (info, nindx, vsize))
-       return false;
+         || ! ieee_write_asn (info, nindx,
+                              info->type_stack->type.classdef->voffset))
+       return FALSE;
       if (info->type_stack->type.classdef->ownvptr)
        {
          if (! ieee_write_atn65 (info, nindx, ""))
-           return false;
+           return FALSE;
        }
       else
        {
          if (! ieee_write_atn65 (info, nindx,
                                  info->type_stack->type.classdef->vclass))
-           return false;
+           return FALSE;
        }
       if (! ieee_write_asn (info, nindx, 0))
-       return false;
+       return FALSE;
       info->type_stack->type.classdef->pmisccount += 5;
     }
 
@@ -5165,125 +6448,167 @@ ieee_end_class_type (p)
       || ! ieee_write_number (info, 80)
       || ! ieee_write_number (info,
                              info->type_stack->type.classdef->pmisccount))
-    return false;
+    return FALSE;
 
-  for (pb = &info->cxx; *pb != NULL; pb = &(*pb)->next)
-    ;
-  *pb = info->type_stack->type.classdef->pmiscbuf;
+  if (! ieee_append_buffer (info, &info->cxx,
+                           &info->type_stack->type.classdef->pmiscbuf))
+    return FALSE;
+  if (! ieee_buffer_emptyp (&info->type_stack->type.classdef->refs))
+    {
+      if (! ieee_append_buffer (info, &info->cxx,
+                               &info->type_stack->type.classdef->refs))
+       return FALSE;
+    }
 
   return ieee_end_struct_type (p);
 }
 
 /* Push a previously seen typedef onto the type stack.  */
 
-static boolean
-ieee_typedef_type (p, name)
-     PTR p;
-     const char *name;
+static bfd_boolean
+ieee_typedef_type (void *p, const char *name)
 {
   struct ieee_handle *info = (struct ieee_handle *) p;
-  register struct ieee_name_type *nt;
+  struct ieee_name_type_hash_entry *h;
+  struct ieee_name_type *nt;
 
-  for (nt = info->typedefs; nt != NULL; nt = nt->next)
-    {
-      if (nt->name[0] == name[0]
-         && strcmp (nt->name, name) == 0)
-       {
-         if (! ieee_push_type (info, nt->type.indx, nt->type.size,
-                               nt->type.unsignedp))
-           return false;
-         /* Copy over any other type information we may have.  */
-         info->type_stack->type = nt->type;
-         return true;
-       }
-    }
+  h = ieee_name_type_hash_lookup (&info->typedefs, name, FALSE, FALSE);
+
+  /* h should never be NULL, since that would imply that the generic
+     debugging code has asked for a typedef which it has not yet
+     defined.  */
+  assert (h != NULL);
+
+  /* We always use the most recently defined type for this name, which
+     will be the first one on the list.  */
 
-  abort ();
+  nt = h->types;
+  if (! ieee_push_type (info, nt->type.indx, nt->type.size,
+                       nt->type.unsignedp, nt->type.localp))
+    return FALSE;
+
+  /* Copy over any other type information we may have.  */
+  info->type_stack->type = nt->type;
+
+  return TRUE;
 }
 
 /* Push a tagged type onto the type stack.  */
 
-static boolean
-ieee_tag_type (p, name, id, kind)
-     PTR p;
-     const char *name;
-     unsigned int id;
-     enum debug_type_kind kind;
+static bfd_boolean
+ieee_tag_type (void *p, const char *name, unsigned int id,
+              enum debug_type_kind kind)
 {
   struct ieee_handle *info = (struct ieee_handle *) p;
-  register struct ieee_name_type *nt;
+  bfd_boolean localp;
+  bfd_boolean copy;
   char ab[20];
+  struct ieee_name_type_hash_entry *h;
+  struct ieee_name_type *nt;
+
+  if (kind == DEBUG_KIND_ENUM)
+    {
+      struct ieee_defined_enum *e;
+
+      if (name == NULL)
+       abort ();
+      for (e = info->enums; e != NULL; e = e->next)
+       if (e->tag != NULL && strcmp (e->tag, name) == 0)
+         return ieee_push_type (info, e->indx, 0, TRUE, FALSE);
+
+      e = (struct ieee_defined_enum *) xmalloc (sizeof *e);
+      memset (e, 0, sizeof *e);
+
+      e->indx = info->type_indx;
+      ++info->type_indx;
+      e->tag = name;
+      e->defined = FALSE;
+
+      e->next = info->enums;
+      info->enums = e;
+
+      return ieee_push_type (info, e->indx, 0, TRUE, FALSE);
+    }
 
+  localp = FALSE;
+
+  copy = FALSE;
   if (name == NULL)
     {
       sprintf (ab, "__anon%u", id);
       name = ab;
+      copy = TRUE;
     }
 
-  for (nt = info->tags; nt != NULL; nt = nt->next)
+  h = ieee_name_type_hash_lookup (&info->tags, name, TRUE, copy);
+  if (h == NULL)
+    return FALSE;
+
+  for (nt = h->types; nt != NULL; nt = nt->next)
     {
-      if (nt->name[0] == name[0]
-         && strcmp (nt->name, name) == 0)
+      if (nt->id == id)
        {
          if (! ieee_push_type (info, nt->type.indx, nt->type.size,
-                               nt->type.unsignedp))
-           return false;
+                               nt->type.unsignedp, nt->type.localp))
+           return FALSE;
          /* Copy over any other type information we may have.  */
          info->type_stack->type = nt->type;
-         return true;
+         return TRUE;
+       }
+
+      if (! nt->type.localp)
+       {
+         /* This is a duplicate of a global type, so it must be
+             local.  */
+         localp = TRUE;
        }
     }
 
   nt = (struct ieee_name_type *) xmalloc (sizeof *nt);
   memset (nt, 0, sizeof *nt);
 
-  nt->name = name;
+  nt->id = id;
+  nt->type.name = h->root.string;
   nt->type.indx = info->type_indx;
+  nt->type.localp = localp;
   ++info->type_indx;
   nt->kind = kind;
 
-  nt->next = info->tags;
-  info->tags = nt;
+  nt->next = h->types;
+  h->types = nt;
+
+  if (! ieee_push_type (info, nt->type.indx, 0, FALSE, localp))
+    return FALSE;
 
-  return ieee_push_type (info, nt->type.indx, 0, false);
+  info->type_stack->type.name = h->root.string;
+
+  return TRUE;
 }
 
 /* Output a typedef.  */
 
-static boolean
-ieee_typdef (p, name)
-     PTR p;
-     const char *name;
+static bfd_boolean
+ieee_typdef (void *p, const char *name)
 {
   struct ieee_handle *info = (struct ieee_handle *) p;
-  struct ieee_name_type *nt;
-  unsigned int size;
-  boolean unsignedp;
+  struct ieee_write_type type;
   unsigned int indx;
+  bfd_boolean found;
+  bfd_boolean localp;
+  struct ieee_name_type_hash_entry *h;
+  struct ieee_name_type *nt;
 
-  nt = (struct ieee_name_type *) xmalloc (sizeof *nt);
-  memset (nt, 0, sizeof *nt);
-  nt->name = name;
-  nt->type = info->type_stack->type;
-  nt->kind = DEBUG_KIND_ILLEGAL;
-
-  nt->next = info->typedefs;
-  info->typedefs = nt;
-
-  size = info->type_stack->type.size;
-  unsignedp = info->type_stack->type.unsignedp;
-  indx = ieee_pop_type (info);
+  type = info->type_stack->type;
+  indx = type.indx;
 
   /* If this is a simple builtin type using a builtin name, we don't
      want to output the typedef itself.  We also want to change the
      type index to correspond to the name being used.  We recognize
      names used in stabs debugging output even if they don't exactly
      correspond to the names used for the IEEE builtin types.  */
+  found = FALSE;
   if (indx <= (unsigned int) builtin_bcd_float)
     {
-      boolean found;
-
-      found = false;
       switch ((enum builtin_types) indx)
        {
        default:
@@ -5291,7 +6616,7 @@ ieee_typdef (p, name)
 
        case builtin_void:
          if (strcmp (name, "void") == 0)
-           found = true;
+           found = TRUE;
          break;
 
        case builtin_signed_char:
@@ -5299,18 +6624,18 @@ ieee_typdef (p, name)
          if (strcmp (name, "signed char") == 0)
            {
              indx = (unsigned int) builtin_signed_char;
-             found = true;
+             found = TRUE;
            }
          else if (strcmp (name, "char") == 0)
            {
              indx = (unsigned int) builtin_char;
-             found = true;
+             found = TRUE;
            }
          break;
 
        case builtin_unsigned_char:
          if (strcmp (name, "unsigned char") == 0)
-           found = true;
+           found = TRUE;
          break;
 
        case builtin_signed_short_int:
@@ -5320,22 +6645,22 @@ ieee_typdef (p, name)
          if (strcmp (name, "signed short int") == 0)
            {
              indx = (unsigned int) builtin_signed_short_int;
-             found = true;
+             found = TRUE;
            }
          else if (strcmp (name, "short") == 0)
            {
              indx = (unsigned int) builtin_short;
-             found = true;
+             found = TRUE;
            }
          else if (strcmp (name, "short int") == 0)
            {
              indx = (unsigned int) builtin_short_int;
-             found = true;
+             found = TRUE;
            }
          else if (strcmp (name, "signed short") == 0)
            {
              indx = (unsigned int) builtin_signed_short;
-             found = true;
+             found = TRUE;
            }
          break;
 
@@ -5345,12 +6670,12 @@ ieee_typdef (p, name)
              || strcmp (name, "short unsigned int") == 0)
            {
              indx = builtin_unsigned_short_int;
-             found = true;
+             found = TRUE;
            }
          else if (strcmp (name, "unsigned short") == 0)
            {
              indx = builtin_unsigned_short;
-             found = true;
+             found = TRUE;
            }
          break;
 
@@ -5360,18 +6685,18 @@ ieee_typdef (p, name)
          if (strcmp (name, "signed long") == 0)
            {
              indx = builtin_signed_long;
-             found = true;
+             found = TRUE;
            }
          else if (strcmp (name, "int") == 0)
            {
              indx = builtin_int;
-             found = true;
+             found = TRUE;
            }
          else if (strcmp (name, "long") == 0
                   || strcmp (name, "long int") == 0)
            {
              indx = builtin_long;
-             found = true;
+             found = TRUE;
            }
          break;
 
@@ -5382,161 +6707,192 @@ ieee_typdef (p, name)
              || strcmp (name, "long unsigned int") == 0)
            {
              indx = builtin_unsigned_long;
-             found = true;
+             found = TRUE;
            }
          else if (strcmp (name, "unsigned") == 0)
            {
              indx = builtin_unsigned;
-             found = true;
+             found = TRUE;
            }
          else if (strcmp (name, "unsigned int") == 0)
            {
              indx = builtin_unsigned_int;
-             found = true;
+             found = TRUE;
            }
          break;
 
        case builtin_signed_long_long:
          if (strcmp (name, "signed long long") == 0
              || strcmp (name, "long long int") == 0)
-           found = true;
+           found = TRUE;
          break;
 
        case builtin_unsigned_long_long:
          if (strcmp (name, "unsigned long long") == 0
              || strcmp (name, "long long unsigned int") == 0)
-           found = true;
+           found = TRUE;
          break;
 
        case builtin_float:
          if (strcmp (name, "float") == 0)
-           found = true;
+           found = TRUE;
          break;
 
        case builtin_double:
          if (strcmp (name, "double") == 0)
-           found = true;
+           found = TRUE;
          break;
 
        case builtin_long_double:
          if (strcmp (name, "long double") == 0)
-           found = true;
+           found = TRUE;
          break;
 
        case builtin_long_long_double:
          if (strcmp (name, "long long double") == 0)
-           found = true;
+           found = TRUE;
          break;
        }
 
       if (found)
+       type.indx = indx;
+    }
+
+  h = ieee_name_type_hash_lookup (&info->typedefs, name, TRUE, FALSE);
+  if (h == NULL)
+    return FALSE;
+
+  /* See if we have already defined this type with this name.  */
+  localp = type.localp;
+  for (nt = h->types; nt != NULL; nt = nt->next)
+    {
+      if (nt->id == indx)
+       {
+         /* If this is a global definition, then we don't need to
+            do anything here.  */
+         if (! nt->type.localp)
+           {
+             ieee_pop_unused_type (info);
+             return TRUE;
+           }
+       }
+      else
        {
-         nt->type.indx = indx;
-         return true;
+         /* This is a duplicate definition, so make this one local.  */
+         localp = TRUE;
        }
     }
 
-  if (! ieee_define_named_type (info, name, false, 0, size, unsignedp,
-                               (struct ieee_buf **) NULL)
+  /* We need to add a new typedef for this type.  */
+
+  nt = (struct ieee_name_type *) xmalloc (sizeof *nt);
+  memset (nt, 0, sizeof *nt);
+  nt->id = indx;
+  nt->type = type;
+  nt->type.name = name;
+  nt->type.localp = localp;
+  nt->kind = DEBUG_KIND_ILLEGAL;
+
+  nt->next = h->types;
+  h->types = nt;
+
+  if (found)
+    {
+      /* This is one of the builtin typedefs, so we don't need to
+         actually define it.  */
+      ieee_pop_unused_type (info);
+      return TRUE;
+    }
+
+  indx = ieee_pop_type (info);
+
+  if (! ieee_define_named_type (info, name, (unsigned int) -1, type.size,
+                               type.unsignedp, localp,
+                               (struct ieee_buflist *) NULL)
       || ! ieee_write_number (info, 'T')
       || ! ieee_write_number (info, indx))
-    return false;
+    return FALSE;
 
-  /* Remove the type we just added to the type stack.  */
+  /* Remove the type we just added to the type stack.  This should not
+     be ieee_pop_unused_type, since the type is used, we just don't
+     need it now.  */
   (void) ieee_pop_type (info);
 
-  return true;
+  return TRUE;
 }
 
 /* Output a tag for a type.  We don't have to do anything here.  */
 
-static boolean
-ieee_tag (p, name)
-     PTR p;
-     const char *name;
+static bfd_boolean
+ieee_tag (void *p, const char *name ATTRIBUTE_UNUSED)
 {
   struct ieee_handle *info = (struct ieee_handle *) p;
 
+  /* This should not be ieee_pop_unused_type, since we want the type
+     to be defined.  */
   (void) ieee_pop_type (info);
-  return true;
+  return TRUE;
 }
 
 /* Output an integer constant.  */
 
-static boolean
-ieee_int_constant (p, name, val)
-     PTR p;
-     const char *name;
-     bfd_vma val;
+static bfd_boolean
+ieee_int_constant (void *p ATTRIBUTE_UNUSED, const char *name ATTRIBUTE_UNUSED,
+                  bfd_vma val ATTRIBUTE_UNUSED)
 {
   /* FIXME.  */
-  return true;
+  return TRUE;
 }
 
 /* Output a floating point constant.  */
 
-static boolean
-ieee_float_constant (p, name, val)
-     PTR p;
-     const char *name;
-     double val;
+static bfd_boolean
+ieee_float_constant (void *p ATTRIBUTE_UNUSED,
+                    const char *name ATTRIBUTE_UNUSED,
+                    double val ATTRIBUTE_UNUSED)
 {
   /* FIXME.  */
-  return true;
+  return TRUE;
 }
 
 /* Output a typed constant.  */
 
-static boolean
-ieee_typed_constant (p, name, val)
-     PTR p;
-     const char *name;
-     bfd_vma val;
+static bfd_boolean
+ieee_typed_constant (void *p, const char *name ATTRIBUTE_UNUSED,
+                    bfd_vma val ATTRIBUTE_UNUSED)
 {
   struct ieee_handle *info = (struct ieee_handle *) p;
 
   /* FIXME.  */
-  (void) ieee_pop_type (info);
-  return true;
+  ieee_pop_unused_type (info);
+  return TRUE;
 }
 
 /* Output a variable.  */
 
-static boolean
-ieee_variable (p, name, kind, val)
-     PTR p;
-     const char *name;
-     enum debug_var_kind kind;
-     bfd_vma val;
+static bfd_boolean
+ieee_variable (void *p, const char *name, enum debug_var_kind kind,
+              bfd_vma val)
 {
   struct ieee_handle *info = (struct ieee_handle *) p;
   unsigned int name_indx;
   unsigned int size;
+  bfd_boolean referencep;
   unsigned int type_indx;
-  boolean asn;
+  bfd_boolean asn;
+  int refflag;
 
-  /* Make sure the variable section is started.  */
-  if (info->vars != NULL)
-    {
-      if (! ieee_change_buffer (info, &info->vars))
-       return false;
-    }
-  else
-    {
-      if (! ieee_change_buffer (info, &info->vars)
-         || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
-         || ! ieee_write_byte (info, 3)
-         || ! ieee_write_number (info, 0)
-         || ! ieee_write_id (info, info->modname))
-       return false;
-    }
+  size = info->type_stack->type.size;
+  referencep = info->type_stack->type.referencep;
+  type_indx = ieee_pop_type (info);
+
+  assert (! ieee_buffer_emptyp (&info->vars));
+  if (! ieee_change_buffer (info, &info->vars))
+    return FALSE;
 
   name_indx = info->name_indx;
   ++info->name_indx;
 
-  size = info->type_stack->type.size;
-  type_indx = ieee_pop_type (info);
-
   /* Write out an NN and an ATN record for this variable.  */
   if (! ieee_write_byte (info, (int) ieee_nn_record)
       || ! ieee_write_number (info, name_indx)
@@ -5544,77 +6900,162 @@ ieee_variable (p, name, kind, val)
       || ! ieee_write_2bytes (info, (int) ieee_atn_record_enum)
       || ! ieee_write_number (info, name_indx)
       || ! ieee_write_number (info, type_indx))
-    return false;
+    return FALSE;
   switch (kind)
     {
     default:
       abort ();
-      return false;
+      return FALSE;
     case DEBUG_GLOBAL:
       if (! ieee_write_number (info, 8)
-         || ! ieee_add_range (info, val, val + size))
-       return false;
-      asn = true;
+         || ! ieee_add_range (info, FALSE, val, val + size))
+       return FALSE;
+      refflag = 0;
+      asn = TRUE;
       break;
     case DEBUG_STATIC:
+      if (! ieee_write_number (info, 3)
+         || ! ieee_add_range (info, FALSE, val, val + size))
+       return FALSE;
+      refflag = 1;
+      asn = TRUE;
+      break;
     case DEBUG_LOCAL_STATIC:
       if (! ieee_write_number (info, 3)
-         || ! ieee_add_range (info, val, val + size))
-       return false;
-      asn = true;
+         || ! ieee_add_range (info, FALSE, val, val + size))
+       return FALSE;
+      refflag = 2;
+      asn = TRUE;
       break;
     case DEBUG_LOCAL:
       if (! ieee_write_number (info, 1)
          || ! ieee_write_number (info, val))
-       return false;
-      asn = false;
+       return FALSE;
+      refflag = 2;
+      asn = FALSE;
       break;
     case DEBUG_REGISTER:
       if (! ieee_write_number (info, 2)
          || ! ieee_write_number (info,
                                  ieee_genreg_to_regno (info->abfd, val)))
-       return false;
-      asn = false;
+       return FALSE;
+      refflag = 2;
+      asn = FALSE;
       break;
     }
 
   if (asn)
     {
       if (! ieee_write_asn (info, name_indx, val))
-       return false;
+       return FALSE;
+    }
+
+  /* If this is really a reference type, then we just output it with
+     pointer type, and must now output a C++ record indicating that it
+     is really reference type.  */
+  if (referencep)
+    {
+      unsigned int nindx;
+
+      nindx = info->name_indx;
+      ++info->name_indx;
+
+      /* If this is a global variable, we want to output the misc
+         record in the C++ misc record block.  Otherwise, we want to
+         output it just after the variable definition, which is where
+         the current buffer is.  */
+      if (refflag != 2)
+       {
+         if (! ieee_change_buffer (info, &info->cxx))
+           return FALSE;
+       }
+
+      if (! ieee_write_byte (info, (int) ieee_nn_record)
+         || ! ieee_write_number (info, nindx)
+         || ! ieee_write_id (info, "")
+         || ! ieee_write_2bytes (info, (int) ieee_atn_record_enum)
+         || ! ieee_write_number (info, nindx)
+         || ! ieee_write_number (info, 0)
+         || ! ieee_write_number (info, 62)
+         || ! ieee_write_number (info, 80)
+         || ! ieee_write_number (info, 3)
+         || ! ieee_write_asn (info, nindx, 'R')
+         || ! ieee_write_asn (info, nindx, refflag)
+         || ! ieee_write_atn65 (info, nindx, name))
+       return FALSE;
     }
 
-  return true;
+  return TRUE;
 }
 
 /* Start outputting information for a function.  */
 
-static boolean
-ieee_start_function (p, name, global)
-     PTR p;
-     const char *name;
-     boolean global;
+static bfd_boolean
+ieee_start_function (void *p, const char *name, bfd_boolean global)
 {
   struct ieee_handle *info = (struct ieee_handle *) p;
-  unsigned int indx;
+  bfd_boolean referencep;
+  unsigned int retindx, typeindx;
+
+  referencep = info->type_stack->type.referencep;
+  retindx = ieee_pop_type (info);
 
-  /* Make sure the variable section is started.  */
-  if (info->vars != NULL)
+  /* Besides recording a BB4 or BB6 block, we record the type of the
+     function in the BB1 typedef block.  We can't write out the full
+     type until we have seen all the parameters, so we accumulate it
+     in info->fntype and info->fnargs.  */
+  if (! ieee_buffer_emptyp (&info->fntype))
     {
-      if (! ieee_change_buffer (info, &info->vars))
-       return false;
+      /* FIXME: This might happen someday if we support nested
+         functions.  */
+      abort ();
     }
-  else
+
+  info->fnname = name;
+
+  /* An attribute of 0x40 means that the push mask is unknown.  */
+  if (! ieee_define_named_type (info, name, (unsigned int) -1, 0, FALSE, TRUE,
+                               &info->fntype)
+      || ! ieee_write_number (info, 'x')
+      || ! ieee_write_number (info, 0x40)
+      || ! ieee_write_number (info, 0)
+      || ! ieee_write_number (info, 0)
+      || ! ieee_write_number (info, retindx))
+    return FALSE;
+
+  typeindx = ieee_pop_type (info);
+
+  if (! ieee_init_buffer (info, &info->fnargs))
+    return FALSE;
+  info->fnargcount = 0;
+
+  /* If the function return value is actually a reference type, we
+     must add a record indicating that.  */
+  if (referencep)
     {
-      if (! ieee_change_buffer (info, &info->vars)
-         || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
-         || ! ieee_write_byte (info, 3)
+      unsigned int nindx;
+
+      nindx = info->name_indx;
+      ++info->name_indx;
+      if (! ieee_change_buffer (info, &info->cxx)
+         || ! ieee_write_byte (info, (int) ieee_nn_record)
+         || ! ieee_write_number (info, nindx)
+         || ! ieee_write_id (info, "")
+         || ! ieee_write_2bytes (info, (int) ieee_atn_record_enum)
+         || ! ieee_write_number (info, nindx)
          || ! ieee_write_number (info, 0)
-         || ! ieee_write_id (info, info->modname))
-       return false;
+         || ! ieee_write_number (info, 62)
+         || ! ieee_write_number (info, 80)
+         || ! ieee_write_number (info, 3)
+         || ! ieee_write_asn (info, nindx, 'R')
+         || ! ieee_write_asn (info, nindx, global ? 0 : 1)
+         || ! ieee_write_atn65 (info, nindx, name))
+       return FALSE;
     }
 
-  indx = ieee_pop_type (info);
+  assert (! ieee_buffer_emptyp (&info->vars));
+  if (! ieee_change_buffer (info, &info->vars))
+    return FALSE;
 
   /* The address is written out as the first block.  */
 
@@ -5625,18 +7066,15 @@ ieee_start_function (p, name, global)
          && ieee_write_number (info, 0)
          && ieee_write_id (info, name)
          && ieee_write_number (info, 0)
-         && ieee_write_number (info, indx));
+         && ieee_write_number (info, typeindx));
 }
 
 /* Add a function parameter.  This will normally be called before the
    first block, so we postpone them until we see the block.  */
 
-static boolean
-ieee_function_parameter (p, name, kind, val)
-     PTR p;
-     const char *name;
-     enum debug_parm_kind kind;
-     bfd_vma val;
+static bfd_boolean
+ieee_function_parameter (void *p, const char *name, enum debug_parm_kind kind,
+                        bfd_vma val)
 {
   struct ieee_handle *info = (struct ieee_handle *) p;
   struct ieee_pending_parm *m, **pm;
@@ -5648,6 +7086,7 @@ ieee_function_parameter (p, name, kind, val)
 
   m->next = NULL;
   m->name = name;
+  m->referencep = info->type_stack->type.referencep;
   m->type = ieee_pop_type (info);
   m->kind = kind;
   m->val = val;
@@ -5656,28 +7095,33 @@ ieee_function_parameter (p, name, kind, val)
     ;
   *pm = m;
 
-  return true;  
+  /* Add the type to the fnargs list.  */
+  if (! ieee_change_buffer (info, &info->fnargs)
+      || ! ieee_write_number (info, m->type))
+    return FALSE;
+  ++info->fnargcount;
+
+  return TRUE;
 }
 
 /* Output pending function parameters.  */
 
-static boolean
-ieee_output_pending_parms (info)
-     struct ieee_handle *info;
+static bfd_boolean
+ieee_output_pending_parms (struct ieee_handle *info)
 {
   struct ieee_pending_parm *m;
+  unsigned int refcount;
 
-  m = info->pending_parms;
-  while (m != NULL)
+  refcount = 0;
+  for (m = info->pending_parms; m != NULL; m = m->next)
     {
-      struct ieee_pending_parm *next;
       enum debug_var_kind vkind;
 
       switch (m->kind)
        {
        default:
          abort ();
-         return false;
+         return FALSE;
        case DEBUG_PARM_STACK:
        case DEBUG_PARM_REFERENCE:
          vkind = DEBUG_LOCAL;
@@ -5688,40 +7132,82 @@ ieee_output_pending_parms (info)
          break;
        }
 
-      if (! ieee_push_type (info, m->type, 0, false)
-         || ! ieee_variable ((PTR) info, m->name, vkind, m->val))
-       return false;
+      if (! ieee_push_type (info, m->type, 0, FALSE, FALSE))
+       return FALSE;
+      info->type_stack->type.referencep = m->referencep;
+      if (m->referencep)
+       ++refcount;
+      if (! ieee_variable ((void *) info, m->name, vkind, m->val))
+       return FALSE;
+    }
+
+  /* If there are any reference parameters, we need to output a
+     miscellaneous record indicating them.  */
+  if (refcount > 0)
+    {
+      unsigned int nindx, varindx;
+
+      /* FIXME: The MRI compiler outputs the demangled function name
+         here, but we are outputting the mangled name.  */
+      nindx = info->name_indx;
+      ++info->name_indx;
+      if (! ieee_change_buffer (info, &info->vars)
+         || ! ieee_write_byte (info, (int) ieee_nn_record)
+         || ! ieee_write_number (info, nindx)
+         || ! ieee_write_id (info, "")
+         || ! ieee_write_2bytes (info, (int) ieee_atn_record_enum)
+         || ! ieee_write_number (info, nindx)
+         || ! ieee_write_number (info, 0)
+         || ! ieee_write_number (info, 62)
+         || ! ieee_write_number (info, 80)
+         || ! ieee_write_number (info, refcount + 3)
+         || ! ieee_write_asn (info, nindx, 'B')
+         || ! ieee_write_atn65 (info, nindx, info->fnname)
+         || ! ieee_write_asn (info, nindx, 0))
+       return FALSE;
+      for (m = info->pending_parms, varindx = 1;
+          m != NULL;
+          m = m->next, varindx++)
+       {
+         if (m->referencep)
+           {
+             if (! ieee_write_asn (info, nindx, varindx))
+               return FALSE;
+           }
+       }
+    }
 
-      /* FIXME: We should output a pmisc note here for reference
-         parameters.  */
+  m = info->pending_parms;
+  while (m != NULL)
+    {
+      struct ieee_pending_parm *next;
 
       next = m->next;
       free (m);
       m = next;
     }
+
   info->pending_parms = NULL;
 
-  return true;
+  return TRUE;
 }
 
 /* Start a block.  If this is the first block, we output the address
    to finish the BB4 or BB6, and then output the function parameters.  */
 
-static boolean
-ieee_start_block (p, addr)
-     PTR p;
-     bfd_vma addr;
+static bfd_boolean
+ieee_start_block (void *p, bfd_vma addr)
 {
   struct ieee_handle *info = (struct ieee_handle *) p;
 
   if (! ieee_change_buffer (info, &info->vars))
-    return false;
+    return FALSE;
 
   if (info->block_depth == 1)
     {
       if (! ieee_write_number (info, addr)
          || ! ieee_output_pending_parms (info))
-       return false;
+       return FALSE;
     }
   else
     {
@@ -5732,47 +7218,47 @@ ieee_start_block (p, addr)
          || ! ieee_write_number (info, 0)
          || ! ieee_write_number (info, 0)
          || ! ieee_write_number (info, addr))
-       return false;
+       return FALSE;
     }
 
   if (! ieee_start_range (info, addr))
-    return false;
+    return FALSE;
 
   ++info->block_depth;
 
-  return true;
+  return TRUE;
 }
 
 /* End a block.  */
 
-static boolean
-ieee_end_block (p, addr)
-     PTR p;
-     bfd_vma addr;
+static bfd_boolean
+ieee_end_block (void *p, bfd_vma addr)
 {
   struct ieee_handle *info = (struct ieee_handle *) p;
 
+  /* The address we are given is the end of the block, but IEEE seems
+     to want to the address of the last byte in the block, so we
+     subtract one.  */
   if (! ieee_change_buffer (info, &info->vars)
       || ! ieee_write_byte (info, (int) ieee_be_record_enum)
-      || ! ieee_write_number (info, addr))
-    return false;
+      || ! ieee_write_number (info, addr - 1))
+    return FALSE;
 
   if (! ieee_end_range (info, addr))
-    return false;
+    return FALSE;
 
   --info->block_depth;
 
   if (addr > info->highaddr)
     info->highaddr = addr;
 
-  return true;
+  return TRUE;
 }
 
 /* End a function.  */
 
-static boolean
-ieee_end_function (p)
-     PTR p;
+static bfd_boolean
+ieee_end_function (void *p)
 {
   struct ieee_handle *info = (struct ieee_handle *) p;
 
@@ -5780,71 +7266,132 @@ ieee_end_function (p)
 
   --info->block_depth;
 
-  return true;
+  /* Now we can finish up fntype, and add it to the typdef section.
+     At this point, fntype is the 'x' type up to the argument count,
+     and fnargs is the argument types.  We must add the argument
+     count, and we must add the level.  FIXME: We don't record varargs
+     functions correctly.  In fact, stabs debugging does not give us
+     enough information to do so.  */
+  if (! ieee_change_buffer (info, &info->fntype)
+      || ! ieee_write_number (info, info->fnargcount)
+      || ! ieee_change_buffer (info, &info->fnargs)
+      || ! ieee_write_number (info, 0))
+    return FALSE;
+
+  /* Make sure the typdef block has been started.  */
+  if (ieee_buffer_emptyp (&info->types))
+    {
+      if (! ieee_change_buffer (info, &info->types)
+         || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
+         || ! ieee_write_byte (info, 1)
+         || ! ieee_write_number (info, 0)
+         || ! ieee_write_id (info, info->modname))
+       return FALSE;
+    }
+
+  if (! ieee_append_buffer (info, &info->types, &info->fntype)
+      || ! ieee_append_buffer (info, &info->types, &info->fnargs))
+    return FALSE;
+
+  info->fnname = NULL;
+  if (! ieee_init_buffer (info, &info->fntype)
+      || ! ieee_init_buffer (info, &info->fnargs))
+    return FALSE;
+  info->fnargcount = 0;
+
+  return TRUE;
 }
 
 /* Record line number information.  */
 
-static boolean
-ieee_lineno (p, filename, lineno, addr)
-     PTR p;
-     const char *filename;
-     unsigned long lineno;
-     bfd_vma addr;
+static bfd_boolean
+ieee_lineno (void *p, const char *filename, unsigned long lineno, bfd_vma addr)
 {
   struct ieee_handle *info = (struct ieee_handle *) p;
 
   assert (info->filename != NULL);
 
-  /* Make sure we have a line number block.  */
-  if (info->linenos != NULL)
-    {
-      if (! ieee_change_buffer (info, &info->linenos))
-       return false;
-    }
-  else
-    {
-      info->lineno_name_indx = info->name_indx;
-      ++info->name_indx;
-      if (! ieee_change_buffer (info, &info->linenos)
-         || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
-         || ! ieee_write_byte (info, 5)
-         || ! ieee_write_number (info, 0)
-         || ! ieee_write_id (info, info->filename)
-         || ! ieee_write_byte (info, (int) ieee_nn_record)
-         || ! ieee_write_number (info, info->lineno_name_indx)
-         || ! ieee_write_id (info, ""))
-       return false;
-      info->lineno_filename = info->filename;
-    }
-
-  if (strcmp (filename, info->lineno_filename) != 0)
+  /* The HP simulator seems to get confused when more than one line is
+     listed for the same address, at least if they are in different
+     files.  We handle this by always listing the last line for a
+     given address, since that seems to be the one that gdb uses.  */
+  if (info->pending_lineno_filename != NULL
+      && addr != info->pending_lineno_addr)
     {
-      if (strcmp (info->filename, info->lineno_filename) != 0)
+      /* Make sure we have a line number block.  */
+      if (! ieee_buffer_emptyp (&info->linenos))
        {
-         /* We were not in the main file.  Close the block for the
-             included file.  */
-         if (! ieee_write_byte (info, (int) ieee_be_record_enum))
-           return false;
+         if (! ieee_change_buffer (info, &info->linenos))
+           return FALSE;
        }
-      if (strcmp (info->filename, filename) != 0)
+      else
        {
-         /* We are not changing to the main file.  Open a block for
-             the new included file.  */
-         if (! ieee_write_byte (info, (int) ieee_bb_record_enum)
+         info->lineno_name_indx = info->name_indx;
+         ++info->name_indx;
+         if (! ieee_change_buffer (info, &info->linenos)
+             || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
              || ! ieee_write_byte (info, 5)
              || ! ieee_write_number (info, 0)
-             || ! ieee_write_id (info, filename))
-           return false;
+             || ! ieee_write_id (info, info->filename)
+             || ! ieee_write_byte (info, (int) ieee_nn_record)
+             || ! ieee_write_number (info, info->lineno_name_indx)
+             || ! ieee_write_id (info, ""))
+           return FALSE;
+         info->lineno_filename = info->filename;
+       }
+
+      if (strcmp (info->pending_lineno_filename, info->lineno_filename) != 0)
+       {
+         if (strcmp (info->filename, info->lineno_filename) != 0)
+           {
+             /* We were not in the main file.  Close the block for the
+                included file.  */
+             if (! ieee_write_byte (info, (int) ieee_be_record_enum))
+               return FALSE;
+             if (strcmp (info->filename, info->pending_lineno_filename) == 0)
+               {
+                 /* We need a new NN record, and we aren't about to
+                    output one.  */
+                 info->lineno_name_indx = info->name_indx;
+                 ++info->name_indx;
+                 if (! ieee_write_byte (info, (int) ieee_nn_record)
+                     || ! ieee_write_number (info, info->lineno_name_indx)
+                     || ! ieee_write_id (info, ""))
+                   return FALSE;
+               }
+           }
+         if (strcmp (info->filename, info->pending_lineno_filename) != 0)
+           {
+             /* We are not changing to the main file.  Open a block for
+                the new included file.  */
+             info->lineno_name_indx = info->name_indx;
+             ++info->name_indx;
+             if (! ieee_write_byte (info, (int) ieee_bb_record_enum)
+                 || ! ieee_write_byte (info, 5)
+                 || ! ieee_write_number (info, 0)
+                 || ! ieee_write_id (info, info->pending_lineno_filename)
+                 || ! ieee_write_byte (info, (int) ieee_nn_record)
+                 || ! ieee_write_number (info, info->lineno_name_indx)
+                 || ! ieee_write_id (info, ""))
+               return FALSE;
+           }
+         info->lineno_filename = info->pending_lineno_filename;
        }
-      info->lineno_filename = filename;
+
+      if (! ieee_write_2bytes (info, (int) ieee_atn_record_enum)
+         || ! ieee_write_number (info, info->lineno_name_indx)
+         || ! ieee_write_number (info, 0)
+         || ! ieee_write_number (info, 7)
+         || ! ieee_write_number (info, info->pending_lineno)
+         || ! ieee_write_number (info, 0)
+         || ! ieee_write_asn (info, info->lineno_name_indx,
+                              info->pending_lineno_addr))
+       return FALSE;
     }
 
-  return (ieee_write_2bytes (info, (int) ieee_atn_record_enum)
-         && ieee_write_number (info, info->lineno_name_indx)
-         && ieee_write_number (info, 0)
-         && ieee_write_number (info, 7)
-         && ieee_write_number (info, lineno)
-         && ieee_write_number (info, 0)
-         && ieee_write_asn (info, info->lineno_name_indx, addr));
+  info->pending_lineno_filename = filename;
+  info->pending_lineno = lineno;
+  info->pending_lineno_addr = addr;
+
+  return TRUE;
 }