* configure.in: Make --without-x work.
[deliverable/binutils-gdb.git] / binutils / debug.c
index 239abdbb80313f3838b53cee9a2ae42f47285ab8..3ce609bdca90027f130fe7b32f90f5f04254e929 100644 (file)
@@ -1,5 +1,5 @@
 /* debug.c -- Handle generic debugging information.
-   Copyright (C) 1995, 1996 Free Software Foundation, Inc.
+   Copyright 1995, 1996, 1997, 1998, 2000, 2002 Free Software Foundation, Inc.
    Written by Ian Lance Taylor <ian@cygnus.com>.
 
    This file is part of GNU Binutils.
@@ -52,8 +52,18 @@ struct debug_handle
   struct debug_lineno *current_lineno;
   /* Mark.  This is used by debug_write.  */
   unsigned int mark;
-  /* Another mark used by debug_write.  */
-  unsigned int class_mark;
+  /* A struct/class ID used by debug_write.  */
+  unsigned int class_id;
+  /* The base for class_id for this call to debug_write.  */
+  unsigned int base_id;
+  /* The current line number in debug_write.  */
+  struct debug_lineno *current_write_lineno;
+  unsigned int current_write_lineno_index;
+  /* A list of classes which have assigned ID's during debug_write.
+     This is linked through the next_id field of debug_class_type.  */
+  struct debug_class_id *id_list;
+  /* A list used to avoid recursion during debug_type_samep.  */
+  struct debug_type_compare_list *compare_list;
 };
 
 /* Information we keep for a single compilation unit.  */
@@ -148,8 +158,11 @@ struct debug_class_type
 {
   /* NULL terminated array of fields.  */
   debug_field *fields;
-  /* A mark field used to avoid recursively printing out structs.  */
+  /* A mark field which indicates whether the struct has already been
+     printed.  */
   unsigned int mark;
+  /* This is used to uniquely identify unnamed structs when printing.  */
+  unsigned int id;
   /* The remaining fields are only used for DEBUG_KIND_CLASS and
      DEBUG_KIND_UNION_CLASS.  */
   /* NULL terminated array of base classes.  */
@@ -178,6 +191,10 @@ struct debug_function_type
 {
   /* Return type.  */
   debug_type return_type;
+  /* NULL terminated array of argument types.  */
+  debug_type *arg_types;
+  /* Whether the function takes a variable number of arguments.  */
+  boolean varargs;
 };
 
 /* Information kept for a range.  */
@@ -238,6 +255,8 @@ struct debug_method_type
   debug_type domain_type;
   /* A NULL terminated array of argument types.  */
   debug_type *arg_types;
+  /* Whether the method takes a variable number of arguments.  */
+  boolean varargs;
 };
 
 /* Information kept for a named type.  */
@@ -309,8 +328,8 @@ struct debug_method
 
 struct debug_method_variant
 {
-  /* The argument types of the function.  */
-  const char *argtypes;
+  /* The physical name of the function.  */
+  const char *physname;
   /* The type of the function.  */
   struct debug_type *type;
   /* The visibility of the function.  */
@@ -322,7 +341,7 @@ struct debug_method_variant
   /* The offset to the function in the virtual function table.  */
   bfd_vma voffset;
   /* If voffset is VOFFSET_STATIC_METHOD, this is a static method.  */
-#define VOFFSET_STATIC_METHOD (1)
+#define VOFFSET_STATIC_METHOD ((bfd_vma) -1)
   /* Context of a virtual method function.  */
   struct debug_type *context;
 };
@@ -497,6 +516,44 @@ struct debug_name
     } u;
 };
 
+/* During debug_write, a linked list of these structures is used to
+   keep track of ID numbers that have been assigned to classes.  */
+
+struct debug_class_id
+{
+  /* Next ID number.  */
+  struct debug_class_id *next;
+  /* The type with the ID.  */
+  struct debug_type *type;
+  /* The tag; NULL if no tag.  */
+  const char *tag;
+};
+
+/* During debug_type_samep, a linked list of these structures is kept
+   on the stack to avoid infinite recursion.  */
+
+struct debug_type_compare_list
+{
+  /* Next type on list.  */
+  struct debug_type_compare_list *next;
+  /* The types we are comparing.  */
+  struct debug_type *t1;
+  struct debug_type *t2;
+};
+
+/* During debug_get_real_type, a linked list of these structures is
+   kept on the stack to avoid infinite recursion.  */
+
+struct debug_type_real_list
+{
+  /* Next type on list.  */
+  struct debug_type_real_list *next;
+  /* The type we are checking.  */
+  struct debug_type *t;
+};
+
+/* Local functions.  */
+
 static void debug_error PARAMS ((const char *));
 static struct debug_name *debug_add_to_namespace
   PARAMS ((struct debug_handle *, struct debug_namespace **, const char *,
@@ -506,6 +563,8 @@ static struct debug_name *debug_add_to_current_namespace
           enum debug_object_linkage));
 static struct debug_type *debug_make_type
   PARAMS ((struct debug_handle *, enum debug_type_kind, unsigned int));
+static struct debug_type *debug_get_real_type
+  PARAMS ((PTR, debug_type, struct debug_type_real_list *));
 static boolean debug_write_name
   PARAMS ((struct debug_handle *, const struct debug_write_fns *, PTR,
           struct debug_name *));
@@ -521,6 +580,15 @@ static boolean debug_write_function
 static boolean debug_write_block
   PARAMS ((struct debug_handle *, const struct debug_write_fns *, PTR,
           struct debug_block *));
+static boolean debug_write_linenos
+  PARAMS ((struct debug_handle *, const struct debug_write_fns *, PTR,
+          bfd_vma));
+static boolean debug_set_class_id
+  PARAMS ((struct debug_handle *, const char *, struct debug_type *));
+static boolean debug_type_samep
+  PARAMS ((struct debug_handle *, struct debug_type *, struct debug_type *));
+static boolean debug_class_type_samep
+  PARAMS ((struct debug_handle *, struct debug_type *, struct debug_type *));
 \f
 /* Issue an error message.  */
 
@@ -535,7 +603,7 @@ debug_error (message)
 
 static struct debug_name *
 debug_add_to_namespace (info, nsp, name, kind, linkage)
-     struct debug_handle *info;
+     struct debug_handle *info ATTRIBUTE_UNUSED;
      struct debug_namespace **nsp;
      const char *name;
      enum debug_object_kind kind;
@@ -582,7 +650,7 @@ debug_add_to_current_namespace (info, name, kind, linkage)
   if (info->current_unit == NULL
       || info->current_file == NULL)
     {
-      debug_error ("debug_add_to_current_namespace: no current file");
+      debug_error (_("debug_add_to_current_namespace: no current file"));
       return NULL;
     }
 
@@ -649,34 +717,6 @@ debug_set_filename (handle, name)
   return true;
 }
 
-/* Append a string to the source filename.  */
-
-boolean
-debug_append_filename (handle, string)
-     PTR handle;
-     const char *string;
-{
-  struct debug_handle *info = (struct debug_handle *) handle;
-  char *n;
-
-  if (string == NULL)
-    string = "";
-
-  if (info->current_unit == NULL)
-    {
-      debug_error ("debug_append_filename: no current file");
-      return false;
-    }
-
-  n = (char *) xmalloc (strlen (info->current_unit->files->filename)
-                       + strlen (string)
-                       + 1);
-  sprintf (n, "%s%s", info->current_unit->files->filename, string);
-  info->current_unit->files->filename = n;
-
-  return true;
-}
-
 /* Change source files to the given file name.  This is used for
    include files in a single compilation unit.  */
 
@@ -693,7 +733,7 @@ debug_start_source (handle, name)
 
   if (info->current_unit == NULL)
     {
-      debug_error ("debug_start_source: no debug_set_filename call");
+      debug_error (_("debug_start_source: no debug_set_filename call"));
       return false;
     }
 
@@ -730,8 +770,7 @@ debug_start_source (handle, name)
    The bfd_vma is the address of the start of the function.  Currently
    the parameter types are specified by calls to
    debug_record_parameter.  FIXME: There is no way to specify nested
-   functions.  FIXME: I don't think there is any way to record where a
-   function ends.  */
+   functions.  */
 
 boolean
 debug_record_function (handle, name, return_type, global, addr)
@@ -753,7 +792,7 @@ debug_record_function (handle, name, return_type, global, addr)
 
   if (info->current_unit == NULL)
     {
-      debug_error ("debug_record_function: no debug_set_filename call");
+      debug_error (_("debug_record_function: no debug_set_filename call"));
       return false;
     }
 
@@ -809,7 +848,7 @@ debug_record_parameter (handle, name, type, kind, val)
   if (info->current_unit == NULL
       || info->current_function == NULL)
     {
-      debug_error ("debug_record_parameter: no current function");
+      debug_error (_("debug_record_parameter: no current function"));
       return false;
     }
 
@@ -843,13 +882,13 @@ debug_end_function (handle, addr)
       || info->current_block == NULL
       || info->current_function == NULL)
     {
-      debug_error ("debug_end_function: no current function");
+      debug_error (_("debug_end_function: no current function"));
       return false;
     }
 
   if (info->current_block->parent != NULL)
     {
-      debug_error ("debug_end_function: some blocks were not closed");
+      debug_error (_("debug_end_function: some blocks were not closed"));
       return false;
     }
 
@@ -879,7 +918,7 @@ debug_start_block (handle, addr)
   if (info->current_unit == NULL
       || info->current_block == NULL)
     {
-      debug_error ("debug_start_block: no current block");
+      debug_error (_("debug_start_block: no current block"));
       return false;
     }
 
@@ -917,14 +956,14 @@ debug_end_block (handle, addr)
   if (info->current_unit == NULL
       || info->current_block == NULL)
     {
-      debug_error ("debug_end_block: no current block");
+      debug_error (_("debug_end_block: no current block"));
       return false;
     }
 
   parent = info->current_block->parent;
   if (parent == NULL)
     {
-      debug_error ("debug_end_block: attempt to close top level block");
+      debug_error (_("debug_end_block: attempt to close top level block"));
       return false;
     }
 
@@ -950,7 +989,7 @@ debug_record_line (handle, lineno, addr)
 
   if (info->current_unit == NULL)
     {
-      debug_error ("debug_record_line: no current unit");
+      debug_error (_("debug_record_line: no current unit"));
       return false;
     }
 
@@ -1000,11 +1039,11 @@ debug_record_line (handle, lineno, addr)
 
 boolean
 debug_start_common_block (handle, name)
-     PTR handle;
-     const char *name;
+     PTR handle ATTRIBUTE_UNUSED;
+     const char *name ATTRIBUTE_UNUSED;
 {
   /* FIXME */
-  debug_error ("debug_start_common_block: not implemented");
+  debug_error (_("debug_start_common_block: not implemented"));
   return false;
 }
 
@@ -1012,11 +1051,11 @@ debug_start_common_block (handle, name)
 
 boolean
 debug_end_common_block (handle, name)
-     PTR handle;
-     const char *name;
+     PTR handle ATTRIBUTE_UNUSED;
+     const char *name ATTRIBUTE_UNUSED;
 {
   /* FIXME */
-  debug_error ("debug_end_common_block: not implemented");
+  debug_error (_("debug_end_common_block: not implemented"));
   return false;
 }
 
@@ -1104,13 +1143,13 @@ debug_record_typed_const (handle, name, type, val)
 
 boolean
 debug_record_label (handle, name, type, addr)
-     PTR handle;
-     const char *name;
-     debug_type type;
-     bfd_vma addr;
+     PTR handle ATTRIBUTE_UNUSED;
+     const char *name ATTRIBUTE_UNUSED;
+     debug_type type ATTRIBUTE_UNUSED;
+     bfd_vma addr ATTRIBUTE_UNUSED;
 {
   /* FIXME.  */
-  debug_error ("debug_record_label not implemented");
+  debug_error (_("debug_record_label: not implemented"));
   return false;
 }
 
@@ -1136,7 +1175,7 @@ debug_record_variable (handle, name, type, kind, val)
   if (info->current_unit == NULL
       || info->current_file == NULL)
     {
-      debug_error ("debug_record_variable: no current file");
+      debug_error (_("debug_record_variable: no current file"));
       return false;
     }
 
@@ -1152,7 +1191,7 @@ debug_record_variable (handle, name, type, kind, val)
     {
       if (info->current_block == NULL)
        {
-         debug_error ("debug_record_variable: no current block");
+         debug_error (_("debug_record_variable: no current block"));
          return false;
        }
       nsp = &info->current_block->locals;
@@ -1172,15 +1211,14 @@ debug_record_variable (handle, name, type, kind, val)
 
   n->u.variable = v;
 
-  return true;  
+  return true;
 }
 
 /* Make a type with a given kind and size.  */
 
-/*ARGSUSED*/
 static struct debug_type *
 debug_make_type (info, kind, size)
-     struct debug_handle *info;
+     struct debug_handle *info ATTRIBUTE_UNUSED;
      enum debug_type_kind kind;
      unsigned int size;
 {
@@ -1428,9 +1466,11 @@ debug_make_pointer_type (handle, type)
    to record the parameter types.  */
 
 debug_type
-debug_make_function_type (handle, type)
+debug_make_function_type (handle, type, arg_types, varargs)
      PTR handle;
      debug_type type;
+     debug_type *arg_types;
+     boolean varargs;
 {
   struct debug_handle *info = (struct debug_handle *) handle;
   struct debug_type *t;
@@ -1447,6 +1487,8 @@ debug_make_function_type (handle, type)
   memset (f, 0, sizeof *f);
 
   f->return_type = type;
+  f->arg_types = arg_types;
+  f->varargs = varargs;
 
   t->u.kfunction = f;
 
@@ -1618,11 +1660,12 @@ debug_make_offset_type (handle, base_type, target_type)
    argument is a NULL terminated array of argument types.  */
 
 debug_type
-debug_make_method_type (handle, return_type, domain_type, arg_types)
+debug_make_method_type (handle, return_type, domain_type, arg_types, varargs)
      PTR handle;
      debug_type return_type;
      debug_type domain_type;
      debug_type *arg_types;
+     boolean varargs;
 {
   struct debug_handle *info = (struct debug_handle *) handle;
   struct debug_type *t;
@@ -1641,6 +1684,7 @@ debug_make_method_type (handle, return_type, domain_type, arg_types)
   m->return_type = return_type;
   m->domain_type = domain_type;
   m->arg_types = arg_types;
+  m->varargs = varargs;
 
   t->u.kmethod = m;
 
@@ -1706,6 +1750,20 @@ debug_make_undefined_tagged_type (handle, name, kind)
   if (name == NULL)
     return DEBUG_TYPE_NULL;
 
+  switch (kind)
+    {
+    case DEBUG_KIND_STRUCT:
+    case DEBUG_KIND_UNION:
+    case DEBUG_KIND_CLASS:
+    case DEBUG_KIND_UNION_CLASS:
+    case DEBUG_KIND_ENUM:
+      break;
+
+    default:
+      debug_error (_("debug_make_undefined_type: unsupported kind"));
+      return DEBUG_TYPE_NULL;
+    }
+
   t = debug_make_type (info, kind, 0);
   if (t == NULL)
     return DEBUG_TYPE_NULL;
@@ -1719,15 +1777,14 @@ debug_make_undefined_tagged_type (handle, name, kind)
    The fourth argument is whether this is a virtual class.  The fifth
    argument is the visibility of the base class.  */
 
-/*ARGSUSED*/
 debug_baseclass
 debug_make_baseclass (handle, type, bitpos, virtual, visibility)
-     PTR handle;
+     PTR handle ATTRIBUTE_UNUSED;
      debug_type type;
      bfd_vma bitpos;
      boolean virtual;
      enum debug_visibility visibility;
-{     
+{
   struct debug_baseclass *b;
 
   b = (struct debug_baseclass *) xmalloc (sizeof *b);
@@ -1747,10 +1804,9 @@ debug_make_baseclass (handle, type, bitpos, virtual, visibility)
    the field (it may be zero).  The sixth argument is the visibility
    of the field.  */
 
-/*ARGSUSED*/
 debug_field
 debug_make_field (handle, name, type, bitpos, bitsize, visibility)
-     PTR handle;
+     PTR handle ATTRIBUTE_UNUSED;
      const char *name;
      debug_type type;
      bfd_vma bitpos;
@@ -1778,10 +1834,9 @@ debug_make_field (handle, name, type, bitpos, bitsize, visibility)
    global variable).  The fifth argument is the visibility of the
    member.  */
 
-/*ARGSUSED*/
 debug_field
 debug_make_static_member (handle, name, type, physname, visibility)
-     PTR handle;
+     PTR handle ATTRIBUTE_UNUSED;
      const char *name;
      debug_type type;
      const char *physname;
@@ -1804,10 +1859,9 @@ debug_make_static_member (handle, name, type, physname, visibility)
 /* Make a method.  The second argument is the name, and the third
    argument is a NULL terminated array of method variants.  */
 
-/*ARGSUSED*/
 debug_method
 debug_make_method (handle, name, variants)
-     PTR handle;
+     PTR handle ATTRIBUTE_UNUSED;
      const char *name;
      debug_method_variant *variants;
 {
@@ -1831,12 +1885,11 @@ debug_make_method (handle, name, variants)
    function context.  FIXME: Are the const and volatile arguments
    necessary?  Could we just use debug_make_const_type?  */
 
-/*ARGSUSED*/
 debug_method_variant
-debug_make_method_variant (handle, argtypes, type, visibility, constp,
+debug_make_method_variant (handle, physname, type, visibility, constp,
                           volatilep, voffset, context)
-     PTR handle;
-     const char *argtypes;
+     PTR handle ATTRIBUTE_UNUSED;
+     const char *physname;
      debug_type type;
      enum debug_visibility visibility;
      boolean constp;
@@ -1849,7 +1902,7 @@ debug_make_method_variant (handle, argtypes, type, visibility, constp,
   m = (struct debug_method_variant *) xmalloc (sizeof *m);
   memset (m, 0, sizeof *m);
 
-  m->argtypes = argtypes;
+  m->physname = physname;
   m->type = type;
   m->visibility = visibility;
   m->constp = constp;
@@ -1865,10 +1918,10 @@ debug_make_method_variant (handle, argtypes, type, visibility, constp,
    since a static method can not also be virtual.  */
 
 debug_method_variant
-debug_make_static_method_variant (handle, argtypes, type, visibility,
+debug_make_static_method_variant (handle, physname, type, visibility,
                                  constp, volatilep)
-     PTR handle;
-     const char *argtypes;
+     PTR handle ATTRIBUTE_UNUSED;
+     const char *physname;
      debug_type type;
      enum debug_visibility visibility;
      boolean constp;
@@ -1879,7 +1932,7 @@ debug_make_static_method_variant (handle, argtypes, type, visibility,
   m = (struct debug_method_variant *) xmalloc (sizeof *m);
   memset (m, 0, sizeof *m);
 
-  m->argtypes = argtypes;
+  m->physname = physname;
   m->type = type;
   m->visibility = visibility;
   m->constp = constp;
@@ -1905,6 +1958,13 @@ debug_name_type (handle, name, type)
   if (name == NULL || type == NULL)
     return DEBUG_TYPE_NULL;
 
+  if (info->current_unit == NULL
+      || info->current_file == NULL)
+    {
+      debug_error (_("debug_name_type: no current file"));
+      return DEBUG_TYPE_NULL;
+    }
+
   t = debug_make_type (info, DEBUG_KIND_NAMED, 0);
   if (t == NULL)
     return DEBUG_TYPE_NULL;
@@ -1916,12 +1976,13 @@ debug_name_type (handle, name, type)
 
   t->u.knamed = n;
 
-  /* We also need to add the name to the current namespace.  */
+  /* We always add the name to the global namespace.  This is probably
+     wrong in some cases, but it seems to be right for stabs.  FIXME.  */
 
-  nm = debug_add_to_current_namespace (info, name, DEBUG_OBJECT_TYPE,
-                                      DEBUG_LINKAGE_NONE);
+  nm = debug_add_to_namespace (info, &info->current_file->globals, name,
+                              DEBUG_OBJECT_TYPE, DEBUG_LINKAGE_NONE);
   if (nm == NULL)
-    return false;
+    return DEBUG_TYPE_NULL;
 
   nm->u.type = t;
 
@@ -1948,7 +2009,7 @@ debug_tag_type (handle, name, type)
 
   if (info->current_file == NULL)
     {
-      debug_error ("debug_tag_type: no current file");
+      debug_error (_("debug_tag_type: no current file"));
       return DEBUG_TYPE_NULL;
     }
 
@@ -1956,7 +2017,7 @@ debug_tag_type (handle, name, type)
     {
       if (strcmp (type->u.knamed->name->name, name) == 0)
        return type;
-      debug_error ("debug_tag_type: extra tag attempted");
+      debug_error (_("debug_tag_type: extra tag attempted"));
       return DEBUG_TYPE_NULL;
     }
 
@@ -1977,7 +2038,7 @@ debug_tag_type (handle, name, type)
   nm = debug_add_to_namespace (info, &info->current_file->globals, name,
                               DEBUG_OBJECT_TAG, DEBUG_LINKAGE_NONE);
   if (nm == NULL)
-    return false;
+    return DEBUG_TYPE_NULL;
 
   nm->u.tag = t;
 
@@ -1988,15 +2049,14 @@ debug_tag_type (handle, name, type)
 
 /* Record the size of a given type.  */
 
-/*ARGSUSED*/
 boolean
 debug_record_type_size (handle, type, size)
-     PTR handle;
+     PTR handle ATTRIBUTE_UNUSED;
      debug_type type;
      unsigned int size;
 {
   if (type->size != 0 && type->size != size)
-    fprintf (stderr, "Warning: changing type size from %d to %d\n",
+    fprintf (stderr, _("Warning: changing type size from %d to %d\n"),
             type->size, size);
 
   type->size = size;
@@ -2004,6 +2064,61 @@ debug_record_type_size (handle, type, size)
   return true;
 }
 
+/* Find a named type.  */
+
+debug_type
+debug_find_named_type (handle, name)
+     PTR handle;
+     const char *name;
+{
+  struct debug_handle *info = (struct debug_handle *) handle;
+  struct debug_block *b;
+  struct debug_file *f;
+
+  /* We only search the current compilation unit.  I don't know if
+     this is right or not.  */
+
+  if (info->current_unit == NULL)
+    {
+      debug_error (_("debug_find_named_type: no current compilation unit"));
+      return DEBUG_TYPE_NULL;
+    }
+
+  for (b = info->current_block; b != NULL; b = b->parent)
+    {
+      if (b->locals != NULL)
+       {
+         struct debug_name *n;
+
+         for (n = b->locals->list; n != NULL; n = n->next)
+           {
+             if (n->kind == DEBUG_OBJECT_TYPE
+                 && n->name[0] == name[0]
+                 && strcmp (n->name, name) == 0)
+               return n->u.type;
+           }
+       }
+    }
+
+  for (f = info->current_unit->files; f != NULL; f = f->next)
+    {
+      if (f->globals != NULL)
+       {
+         struct debug_name *n;
+
+         for (n = f->globals->list; n != NULL; n = n->next)
+           {
+             if (n->kind == DEBUG_OBJECT_TYPE
+                 && n->name[0] == name[0]
+                 && strcmp (n->name, name) == 0)
+               return n->u.type;
+           }
+       }
+    }
+
+  return DEBUG_TYPE_NULL;
+}
+
 /* Find a tagged type.  */
 
 debug_type
@@ -2031,7 +2146,7 @@ debug_find_tagged_type (handle, name, kind)
              for (n = f->globals->list; n != NULL; n = n->next)
                {
                  if (n->kind == DEBUG_OBJECT_TAG
-                     && (kind == DEBUG_KIND_VOID
+                     && (kind == DEBUG_KIND_ILLEGAL
                          || n->u.tag->kind == kind)
                      && n->name[0] == name[0]
                      && strcmp (n->name, name) == 0)
@@ -2044,9 +2159,75 @@ debug_find_tagged_type (handle, name, kind)
   return DEBUG_TYPE_NULL;
 }
 
+/* Get a base type.  We build a linked list on the stack to avoid
+   crashing if the type is defined circularly.  */
+
+static struct debug_type *
+debug_get_real_type (handle, type, list)
+     PTR handle;
+     debug_type type;
+     struct debug_type_real_list *list;
+{
+  struct debug_type_real_list *l;
+  struct debug_type_real_list rl;
+
+  switch (type->kind)
+    {
+    default:
+      return type;
+
+    case DEBUG_KIND_INDIRECT:
+    case DEBUG_KIND_NAMED:
+    case DEBUG_KIND_TAGGED:
+      break;
+    }
+
+  for (l = list; l != NULL; l = l->next)
+    {
+      if (l->t == type)
+       {
+         fprintf (stderr,
+                  _("debug_get_real_type: circular debug information for %s\n"),
+                  debug_get_type_name (handle, type));
+         return NULL;
+       }
+    }
+
+  rl.next = list;
+  rl.t = type;
+
+  switch (type->kind)
+    {
+      /* The default case is just here to avoid warnings.  */
+    default:
+    case DEBUG_KIND_INDIRECT:
+      if (*type->u.kindirect->slot != NULL)
+       return debug_get_real_type (handle, *type->u.kindirect->slot, &rl);
+      return type;
+    case DEBUG_KIND_NAMED:
+    case DEBUG_KIND_TAGGED:
+      return debug_get_real_type (handle, type->u.knamed->type, &rl);
+    }
+  /*NOTREACHED*/
+}
+
+/* Get the kind of a type.  */
+
+enum debug_type_kind
+debug_get_type_kind (handle, type)
+     PTR handle;
+     debug_type type;
+{
+  if (type == NULL)
+    return DEBUG_KIND_ILLEGAL;
+  type = debug_get_real_type (handle, type, NULL);
+  if (type == NULL)
+    return DEBUG_KIND_ILLEGAL;
+  return type->kind;
+}
+
 /* Get the name of a type.  */
 
-/*ARGSUSED*/
 const char *
 debug_get_type_name (handle, type)
      PTR handle;
@@ -2063,88 +2244,295 @@ debug_get_type_name (handle, type)
     return type->u.knamed->name->name;
   return NULL;
 }
-\f
-/* Write out the debugging information.  This is given a handle to
-   debugging information, and a set of function pointers to call.  */
 
-boolean
-debug_write (handle, fns, fhandle)
+/* Get the size of a type.  */
+
+bfd_vma
+debug_get_type_size (handle, type)
      PTR handle;
-     const struct debug_write_fns *fns;
-     PTR fhandle;
+     debug_type type;
 {
-  struct debug_handle *info = (struct debug_handle *) handle;
-  struct debug_unit *u;
-
-  /* We use a mark to tell whether we have already written out a
-     particular name.  We use an integer, so that we don't have to
-     clear the mark fields if we happen to write out the same
-     information more than once.  */
-  ++info->mark;
+  if (type == NULL)
+    return 0;
 
-  for (u = info->units; u != NULL; u = u->next)
-    {
-      struct debug_file *f;
-      boolean first_file;
-      struct debug_lineno *l;
+  /* We don't call debug_get_real_type, because somebody might have
+     called debug_record_type_size on a named or indirect type.  */
 
-      if (! (*fns->start_compilation_unit) (fhandle, u->files->filename))
-       return false;
+  if (type->size != 0)
+    return type->size;
 
-      first_file = true;
-      for (f = u->files; f != NULL; f = f->next)
-       {
-         struct debug_name *n;
+  switch (type->kind)
+    {
+    default:
+      return 0;
+    case DEBUG_KIND_INDIRECT:
+      if (*type->u.kindirect->slot != NULL)
+       return debug_get_type_size (handle, *type->u.kindirect->slot);
+      return 0;
+    case DEBUG_KIND_NAMED:
+    case DEBUG_KIND_TAGGED:
+      return debug_get_type_size (handle, type->u.knamed->type);
+    }
+  /*NOTREACHED*/
+}
 
-         if (first_file)
-           first_file = false;
-         else
-           {
-             if (! (*fns->start_source) (fhandle, f->filename))
-               return false;
-           }
+/* Get the return type of a function or method type.  */
 
-         if (f->globals != NULL)
-           {
-             for (n = f->globals->list; n != NULL; n = n->next)
-               {
-                 if (! debug_write_name (info, fns, fhandle, n))
-                   return false;
-               }
-           }
-       }
+debug_type
+debug_get_return_type (handle, type)
+     PTR handle;
+     debug_type type;
+{
+  if (type == NULL)
+    return DEBUG_TYPE_NULL;
+  type = debug_get_real_type (handle, type, NULL);
+  if (type == NULL)
+    return DEBUG_TYPE_NULL;
+  switch (type->kind)
+    {
+    default:
+      return DEBUG_TYPE_NULL;
+    case DEBUG_KIND_FUNCTION:
+      return type->u.kfunction->return_type;
+    case DEBUG_KIND_METHOD:
+      return type->u.kmethod->return_type;
+    }
+  /*NOTREACHED*/
+}
 
-      for (l = u->linenos; l != NULL; l = l->next)
-       {
-         unsigned int i;
+/* Get the parameter types of a function or method type (except that
+   we don't currently store the parameter types of a function).  */
 
-         for (i = 0; i < DEBUG_LINENO_COUNT; i++)
-           {
-             if (l->linenos[i] == (unsigned long) -1)
-               break;
-             if (! (*fns->lineno) (fhandle, l->file->filename, l->linenos[i],
-                                   l->addrs[i]))
-               return false;
-           }
-       }
+const debug_type *
+debug_get_parameter_types (handle, type, pvarargs)
+     PTR handle;
+     debug_type type;
+     boolean *pvarargs;
+{
+  if (type == NULL)
+    return NULL;
+  type = debug_get_real_type (handle, type, NULL);
+  if (type == NULL)
+    return NULL;
+  switch (type->kind)
+    {
+    default:
+      return NULL;
+    case DEBUG_KIND_FUNCTION:
+      *pvarargs = type->u.kfunction->varargs;
+      return type->u.kfunction->arg_types;
+    case DEBUG_KIND_METHOD:
+      *pvarargs = type->u.kmethod->varargs;
+      return type->u.kmethod->arg_types;
     }
-
-  return true;
+  /*NOTREACHED*/
 }
 
-/* Write out an element in a namespace.  */
+/* Get the target type of a type.  */
 
-static boolean
-debug_write_name (info, fns, fhandle, n)
-     struct debug_handle *info;
-     const struct debug_write_fns *fns;
-     PTR fhandle;
-     struct debug_name *n;
+debug_type
+debug_get_target_type (handle, type)
+     PTR handle;
+     debug_type type;
 {
-  /* The class_mark field is used to prevent recursively outputting a
-     struct or class.  */
-  ++info->class_mark;
+  if (type == NULL)
+    return NULL;
+  type = debug_get_real_type (handle, type, NULL);
+  if (type == NULL)
+    return NULL;
+  switch (type->kind)
+    {
+    default:
+      return NULL;
+    case DEBUG_KIND_POINTER:
+      return type->u.kpointer;
+    case DEBUG_KIND_REFERENCE:
+      return type->u.kreference;
+    case DEBUG_KIND_CONST:
+      return type->u.kconst;
+    case DEBUG_KIND_VOLATILE:
+      return type->u.kvolatile;
+    }
+  /*NOTREACHED*/
+}
+
+/* Get the NULL terminated array of fields for a struct, union, or
+   class.  */
+
+const debug_field *
+debug_get_fields (handle, type)
+     PTR handle;
+     debug_type type;
+{
+  if (type == NULL)
+    return NULL;
+  type = debug_get_real_type (handle, type, NULL);
+  if (type == NULL)
+    return NULL;
+  switch (type->kind)
+    {
+    default:
+      return NULL;
+    case DEBUG_KIND_STRUCT:
+    case DEBUG_KIND_UNION:
+    case DEBUG_KIND_CLASS:
+    case DEBUG_KIND_UNION_CLASS:
+      return type->u.kclass->fields;
+    }
+  /*NOTREACHED*/
+}
+
+/* Get the type of a field.  */
+
+debug_type
+debug_get_field_type (handle, field)
+     PTR handle ATTRIBUTE_UNUSED;
+     debug_field field;
+{
+  if (field == NULL)
+    return NULL;
+  return field->type;
+}
+
+/* Get the name of a field.  */
+
+const char *
+debug_get_field_name (handle, field)
+     PTR handle ATTRIBUTE_UNUSED;
+     debug_field field;
+{
+  if (field == NULL)
+    return NULL;
+  return field->name;
+}
+
+/* Get the bit position of a field.  */
+
+bfd_vma
+debug_get_field_bitpos (handle, field)
+     PTR handle ATTRIBUTE_UNUSED;
+     debug_field field;
+{
+  if (field == NULL || field->static_member)
+    return (bfd_vma) -1;
+  return field->u.f.bitpos;
+}
+
+/* Get the bit size of a field.  */
+
+bfd_vma
+debug_get_field_bitsize (handle, field)
+     PTR handle ATTRIBUTE_UNUSED;
+     debug_field field;
+{
+  if (field == NULL || field->static_member)
+    return (bfd_vma) -1;
+  return field->u.f.bitsize;
+}
+
+/* Get the visibility of a field.  */
+
+enum debug_visibility
+debug_get_field_visibility (handle, field)
+     PTR handle ATTRIBUTE_UNUSED;
+     debug_field field;
+{
+  if (field == NULL)
+    return DEBUG_VISIBILITY_IGNORE;
+  return field->visibility;
+}
+
+/* Get the physical name of a field.  */
+
+const char *
+debug_get_field_physname (handle, field)
+     PTR handle ATTRIBUTE_UNUSED;
+     debug_field field;
+{
+  if (field == NULL || ! field->static_member)
+    return NULL;
+  return field->u.s.physname;
+}
+\f
+/* Write out the debugging information.  This is given a handle to
+   debugging information, and a set of function pointers to call.  */
+
+boolean
+debug_write (handle, fns, fhandle)
+     PTR handle;
+     const struct debug_write_fns *fns;
+     PTR fhandle;
+{
+  struct debug_handle *info = (struct debug_handle *) handle;
+  struct debug_unit *u;
+
+  /* We use a mark to tell whether we have already written out a
+     particular name.  We use an integer, so that we don't have to
+     clear the mark fields if we happen to write out the same
+     information more than once.  */
+  ++info->mark;
+
+  /* The base_id field holds an ID value which will never be used, so
+     that we can tell whether we have assigned an ID during this call
+     to debug_write.  */
+  info->base_id = info->class_id;
+
+  /* We keep a linked list of classes for which was have assigned ID's
+     during this call to debug_write.  */
+  info->id_list = NULL;
+
+  for (u = info->units; u != NULL; u = u->next)
+    {
+      struct debug_file *f;
+      boolean first_file;
+
+      info->current_write_lineno = u->linenos;
+      info->current_write_lineno_index = 0;
+
+      if (! (*fns->start_compilation_unit) (fhandle, u->files->filename))
+       return false;
+
+      first_file = true;
+      for (f = u->files; f != NULL; f = f->next)
+       {
+         struct debug_name *n;
+
+         if (first_file)
+           first_file = false;
+         else
+           {
+             if (! (*fns->start_source) (fhandle, f->filename))
+               return false;
+           }
+
+         if (f->globals != NULL)
+           {
+             for (n = f->globals->list; n != NULL; n = n->next)
+               {
+                 if (! debug_write_name (info, fns, fhandle, n))
+                   return false;
+               }
+           }
+       }
+
+      /* Output any line number information which hasn't already been
+         handled.  */
+      if (! debug_write_linenos (info, fns, fhandle, (bfd_vma) -1))
+       return false;
+    }
 
+  return true;
+}
+
+/* Write out an element in a namespace.  */
+
+static boolean
+debug_write_name (info, fns, fhandle, n)
+     struct debug_handle *info;
+     const struct debug_write_fns *fns;
+     PTR fhandle;
+     struct debug_name *n;
+{
   switch (n->kind)
     {
     case DEBUG_OBJECT_TYPE:
@@ -2197,7 +2585,8 @@ debug_write_type (info, fns, fhandle, type, name)
      struct debug_name *name;
 {
   unsigned int i;
-  const char *tag;
+  int is;
+  const char *tag = NULL;
 
   /* If we have a name for this type, just output it.  We only output
      typedef names after they have been defined.  We output type tags
@@ -2211,8 +2600,33 @@ debug_write_type (info, fns, fhandle, type, name)
       if (type->kind == DEBUG_KIND_NAMED)
        return (*fns->typedef_type) (fhandle, type->u.knamed->name->name);
       else
-       return (*fns->tag_type) (fhandle, type->u.knamed->name->name,
-                                type->u.knamed->type->kind);
+       {
+         struct debug_type *real;
+         unsigned int id;
+
+         real = debug_get_real_type ((PTR) info, type, NULL);
+         if (real == NULL)
+           return (*fns->empty_type) (fhandle);
+         id = 0;
+         if ((real->kind == DEBUG_KIND_STRUCT
+              || real->kind == DEBUG_KIND_UNION
+              || real->kind == DEBUG_KIND_CLASS
+              || real->kind == DEBUG_KIND_UNION_CLASS)
+             && real->u.kclass != NULL)
+           {
+             if (real->u.kclass->id <= info->base_id)
+               {
+                 if (! debug_set_class_id (info,
+                                           type->u.knamed->name->name,
+                                           real))
+                   return false;
+               }
+             id = real->u.kclass->id;
+           }
+
+         return (*fns->tag_type) (fhandle, type->u.knamed->name->name, id,
+                                  real->kind);
+       }
     }
 
   /* Mark the name after we have already looked for a known name, so
@@ -2222,7 +2636,6 @@ debug_write_type (info, fns, fhandle, type, name)
   if (name != NULL)
     name->mark = info->mark;
 
-  tag = NULL;
   if (name != NULL
       && type->kind != DEBUG_KIND_NAMED
       && type->kind != DEBUG_KIND_TAGGED)
@@ -2233,11 +2646,14 @@ debug_write_type (info, fns, fhandle, type, name)
 
   switch (type->kind)
     {
+    case DEBUG_KIND_ILLEGAL:
+      debug_error (_("debug_write_type: illegal type encountered"));
+      return false;
     case DEBUG_KIND_INDIRECT:
       if (*type->u.kindirect->slot == DEBUG_TYPE_NULL)
        return (*fns->empty_type) (fhandle);
       return debug_write_type (info, fns, fhandle, *type->u.kindirect->slot,
-                              (struct debug_name *) NULL);
+                              name);
     case DEBUG_KIND_VOID:
       return (*fns->void_type) (fhandle);
     case DEBUG_KIND_INT:
@@ -2250,19 +2666,35 @@ debug_write_type (info, fns, fhandle, type, name)
       return (*fns->bool_type) (fhandle, type->size);
     case DEBUG_KIND_STRUCT:
     case DEBUG_KIND_UNION:
-      if (info->class_mark == type->u.kclass->mark)
+      if (type->u.kclass != NULL)
        {
-         /* We are currently outputting this struct.  I don't know if
-             this can happen, but it can happen for a class.  */
-         return (*fns->tag_type) (fhandle, "?defining?", type->kind);
+         if (type->u.kclass->id <= info->base_id)
+           {
+             if (! debug_set_class_id (info, tag, type))
+               return false;
+           }
+
+         if (info->mark == type->u.kclass->mark)
+           {
+             /* We are currently outputting this struct, or we have
+                already output it.  I don't know if this can happen,
+                but it can happen for a class.  */
+             assert (type->u.kclass->id > info->base_id);
+             return (*fns->tag_type) (fhandle, tag, type->u.kclass->id,
+                                      type->kind);
+           }
+         type->u.kclass->mark = info->mark;
        }
-      type->u.kclass->mark = info->class_mark;
 
       if (! (*fns->start_struct_type) (fhandle, tag,
+                                      (type->u.kclass != NULL
+                                       ? type->u.kclass->id
+                                       : 0),
                                       type->kind == DEBUG_KIND_STRUCT,
                                       type->size))
        return false;
-      if (type->u.kclass->fields != NULL)
+      if (type->u.kclass != NULL
+         && type->u.kclass->fields != NULL)
        {
          for (i = 0; type->u.kclass->fields[i] != NULL; i++)
            {
@@ -2281,6 +2713,9 @@ debug_write_type (info, fns, fhandle, type, name)
     case DEBUG_KIND_UNION_CLASS:
       return debug_write_class_type (info, fns, fhandle, type, tag);
     case DEBUG_KIND_ENUM:
+      if (type->u.kenum == NULL)
+       return (*fns->enum_type) (fhandle, tag, (const char **) NULL,
+                                 (bfd_signed_vma *) NULL);
       return (*fns->enum_type) (fhandle, tag, type->u.kenum->names,
                                type->u.kenum->values);
     case DEBUG_KIND_POINTER:
@@ -2293,7 +2728,18 @@ debug_write_type (info, fns, fhandle, type, name)
                              type->u.kfunction->return_type,
                              (struct debug_name *) NULL))
        return false;
-      return (*fns->function_type) (fhandle);
+      if (type->u.kfunction->arg_types == NULL)
+       is = -1;
+      else
+       {
+         for (is = 0; type->u.kfunction->arg_types[is] != NULL; is++)
+           if (! debug_write_type (info, fns, fhandle,
+                                   type->u.kfunction->arg_types[is],
+                                   (struct debug_name *) NULL))
+             return false;
+       }
+      return (*fns->function_type) (fhandle, is,
+                                   type->u.kfunction->varargs);
     case DEBUG_KIND_REFERENCE:
       if (! debug_write_type (info, fns, fhandle, type->u.kreference,
                              (struct debug_name *) NULL))
@@ -2334,16 +2780,14 @@ debug_write_type (info, fns, fhandle, type, name)
                              (struct debug_name *) NULL))
        return false;
       if (type->u.kmethod->arg_types == NULL)
-       i = -1;
+       is = -1;
       else
        {
-         for (i = 0; type->u.kmethod->arg_types[i] != NULL; i++)
-           {
-             if (! debug_write_type (info, fns, fhandle,
-                                     type->u.kmethod->arg_types[i],
-                                     (struct debug_name *) NULL))
-               return false;
-           }
+         for (is = 0; type->u.kmethod->arg_types[is] != NULL; is++)
+           if (! debug_write_type (info, fns, fhandle,
+                                   type->u.kmethod->arg_types[is],
+                                   (struct debug_name *) NULL))
+             return false;
        }
       if (type->u.kmethod->domain_type != NULL)
        {
@@ -2354,7 +2798,8 @@ debug_write_type (info, fns, fhandle, type, name)
        }
       return (*fns->method_type) (fhandle,
                                  type->u.kmethod->domain_type != NULL,
-                                 i);
+                                 is,
+                                 type->u.kmethod->varargs);
     case DEBUG_KIND_CONST:
       if (! debug_write_type (info, fns, fhandle, type->u.kconst,
                              (struct debug_name *) NULL))
@@ -2388,116 +2833,141 @@ debug_write_class_type (info, fns, fhandle, type, tag)
      const char *tag;
 {
   unsigned int i;
+  unsigned int id;
+  struct debug_type *vptrbase;
 
-  if (info->class_mark == type->u.kclass->mark)
+  if (type->u.kclass == NULL)
     {
-      /* We are currently outputting this class.  This can happen when
-         there are methods for an anonymous class.  */
-      return (*fns->tag_type) (fhandle, "?defining?", type->kind);
+      id = 0;
+      vptrbase = NULL;
     }
-  type->u.kclass->mark = info->class_mark;
-
-  if (type->u.kclass->vptrbase != NULL
-      && type->u.kclass->vptrbase != type)
-    {
-      if (! debug_write_type (info, fns, fhandle, type->u.kclass->vptrbase,
-                             (struct debug_name *) NULL))
-       return false;
-    }
-
-  if (! (*fns->start_class_type) (fhandle, tag,
-                                 type->kind == DEBUG_KIND_CLASS,
-                                 type->size,
-                                 type->u.kclass->vptrbase != NULL,
-                                 type->u.kclass->vptrbase == type))
-    return false;
-  if (type->u.kclass->fields != NULL)
+  else
     {
-      for (i = 0; type->u.kclass->fields[i] != NULL; i++)
+      if (type->u.kclass->id <= info->base_id)
        {
-         struct debug_field *f;
-
-         f = type->u.kclass->fields[i];
-         if (! debug_write_type (info, fns, fhandle, f->type,
-                                 (struct debug_name *) NULL))
+         if (! debug_set_class_id (info, tag, type))
            return false;
-         if (f->static_member)
-           {
-             if (! (*fns->class_static_member) (fhandle, f->name,
-                                                f->u.s.physname,
-                                                f->visibility))
-               return false;
-           }
-         else
-           {
-             if (! (*fns->struct_field) (fhandle, f->name, f->u.f.bitpos,
-                                         f->u.f.bitsize, f->visibility))
-               return false;
-           }
        }
-    }
 
-  if (type->u.kclass->baseclasses != NULL)
-    {
-      for (i = 0; type->u.kclass->baseclasses[i] != NULL; i++)
+      if (info->mark == type->u.kclass->mark)
        {
-         struct debug_baseclass *b;
+         /* We are currently outputting this class, or we have
+            already output it.  This can happen when there are
+            methods for an anonymous class.  */
+         assert (type->u.kclass->id > info->base_id);
+         return (*fns->tag_type) (fhandle, tag, type->u.kclass->id,
+                                  type->kind);
+       }
+      type->u.kclass->mark = info->mark;
+      id = type->u.kclass->id;
 
-         b = type->u.kclass->baseclasses[i];
-         if (! debug_write_type (info, fns, fhandle, b->type,
+      vptrbase = type->u.kclass->vptrbase;
+      if (vptrbase != NULL && vptrbase != type)
+       {
+         if (! debug_write_type (info, fns, fhandle, vptrbase,
                                  (struct debug_name *) NULL))
            return false;
-         if (! (*fns->class_baseclass) (fhandle, b->bitpos, b->virtual,
-                                        b->visibility))
-           return false;
        }
     }
 
-  if (type->u.kclass->methods != NULL)
+  if (! (*fns->start_class_type) (fhandle, tag, id,
+                                 type->kind == DEBUG_KIND_CLASS,
+                                 type->size,
+                                 vptrbase != NULL,
+                                 vptrbase == type))
+    return false;
+
+  if (type->u.kclass != NULL)
     {
-      for (i = 0; type->u.kclass->methods[i] != NULL; i++)
+      if (type->u.kclass->fields != NULL)
        {
-         struct debug_method *m;
-         unsigned int j;
-
-         m = type->u.kclass->methods[i];
-         if (! (*fns->class_start_method) (fhandle, m->name))
-           return false;
-         for (j = 0; m->variants[j] != NULL; j++)
+         for (i = 0; type->u.kclass->fields[i] != NULL; i++)
            {
-             struct debug_method_variant *v;
+             struct debug_field *f;
 
-             v = m->variants[j];
-             if (v->context != NULL)
-               {
-                 if (! debug_write_type (info, fns, fhandle, v->context,
-                                         (struct debug_name *) NULL))
-                   return false;
-               }
-             if (! debug_write_type (info, fns, fhandle, v->type,
+             f = type->u.kclass->fields[i];
+             if (! debug_write_type (info, fns, fhandle, f->type,
                                      (struct debug_name *) NULL))
                return false;
-             if (v->voffset != VOFFSET_STATIC_METHOD)
+             if (f->static_member)
                {
-                 if (! (*fns->class_method_variant) (fhandle, v->argtypes,
-                                                     v->visibility,
-                                                     v->constp, v->volatilep,
-                                                     v->voffset,
-                                                     v->context != NULL))
+                 if (! (*fns->class_static_member) (fhandle, f->name,
+                                                    f->u.s.physname,
+                                                    f->visibility))
                    return false;
                }
              else
                {
-                 if (! (*fns->class_static_method_variant) (fhandle,
-                                                            v->argtypes,
-                                                            v->visibility,
-                                                            v->constp,
-                                                            v->volatilep))
+                 if (! (*fns->struct_field) (fhandle, f->name, f->u.f.bitpos,
+                                             f->u.f.bitsize, f->visibility))
                    return false;
                }
            }
-         if (! (*fns->class_end_method) (fhandle))
-           return false;
+       }
+
+      if (type->u.kclass->baseclasses != NULL)
+       {
+         for (i = 0; type->u.kclass->baseclasses[i] != NULL; i++)
+           {
+             struct debug_baseclass *b;
+
+             b = type->u.kclass->baseclasses[i];
+             if (! debug_write_type (info, fns, fhandle, b->type,
+                                     (struct debug_name *) NULL))
+               return false;
+             if (! (*fns->class_baseclass) (fhandle, b->bitpos, b->virtual,
+                                            b->visibility))
+               return false;
+           }
+       }
+
+      if (type->u.kclass->methods != NULL)
+       {
+         for (i = 0; type->u.kclass->methods[i] != NULL; i++)
+           {
+             struct debug_method *m;
+             unsigned int j;
+
+             m = type->u.kclass->methods[i];
+             if (! (*fns->class_start_method) (fhandle, m->name))
+               return false;
+             for (j = 0; m->variants[j] != NULL; j++)
+               {
+                 struct debug_method_variant *v;
+
+                 v = m->variants[j];
+                 if (v->context != NULL)
+                   {
+                     if (! debug_write_type (info, fns, fhandle, v->context,
+                                             (struct debug_name *) NULL))
+                       return false;
+                   }
+                 if (! debug_write_type (info, fns, fhandle, v->type,
+                                         (struct debug_name *) NULL))
+                   return false;
+                 if (v->voffset != VOFFSET_STATIC_METHOD)
+                   {
+                     if (! (*fns->class_method_variant) (fhandle, v->physname,
+                                                         v->visibility,
+                                                         v->constp,
+                                                         v->volatilep,
+                                                         v->voffset,
+                                                         v->context != NULL))
+                       return false;
+                   }
+                 else
+                   {
+                     if (! (*fns->class_static_method_variant) (fhandle,
+                                                                v->physname,
+                                                                v->visibility,
+                                                                v->constp,
+                                                                v->volatilep))
+                       return false;
+                   }
+               }
+             if (! (*fns->class_end_method) (fhandle))
+               return false;
+           }
        }
     }
 
@@ -2518,6 +2988,9 @@ debug_write_function (info, fns, fhandle, name, linkage, function)
   struct debug_parameter *p;
   struct debug_block *b;
 
+  if (! debug_write_linenos (info, fns, fhandle, function->blocks->start))
+    return false;
+
   if (! debug_write_type (info, fns, fhandle, function->return_type,
                          (struct debug_name *) NULL))
     return false;
@@ -2555,9 +3028,17 @@ debug_write_block (info, fns, fhandle, block)
   struct debug_name *n;
   struct debug_block *b;
 
-  if (! (*fns->start_block) (fhandle, block->start))
+  if (! debug_write_linenos (info, fns, fhandle, block->start))
     return false;
 
+  /* I can't see any point to writing out a block with no local
+     variables, so we don't bother, except for the top level block.  */
+  if (block->locals != NULL || block->parent == NULL)
+    {
+      if (! (*fns->start_block) (fhandle, block->start))
+       return false;
+    }
+
   if (block->locals != NULL)
     {
       for (n = block->locals->list; n != NULL; n = n->next)
@@ -2573,5 +3054,502 @@ debug_write_block (info, fns, fhandle, block)
        return false;
     }
 
-  return (*fns->end_block) (fhandle, block->end);
+  if (! debug_write_linenos (info, fns, fhandle, block->end))
+    return false;
+
+  if (block->locals != NULL || block->parent == NULL)
+    {
+      if (! (*fns->end_block) (fhandle, block->end))
+       return false;
+    }
+
+  return true;
+}
+
+/* Write out line number information up to ADDRESS.  */
+
+static boolean
+debug_write_linenos (info, fns, fhandle, address)
+     struct debug_handle *info;
+     const struct debug_write_fns *fns;
+     PTR fhandle;
+     bfd_vma address;
+{
+  while (info->current_write_lineno != NULL)
+    {
+      struct debug_lineno *l;
+
+      l = info->current_write_lineno;
+
+      while (info->current_write_lineno_index < DEBUG_LINENO_COUNT)
+       {
+         if (l->linenos[info->current_write_lineno_index]
+             == (unsigned long) -1)
+           break;
+
+         if (l->addrs[info->current_write_lineno_index] >= address)
+           return true;
+
+         if (! (*fns->lineno) (fhandle, l->file->filename,
+                               l->linenos[info->current_write_lineno_index],
+                               l->addrs[info->current_write_lineno_index]))
+           return false;
+
+         ++info->current_write_lineno_index;
+       }
+
+      info->current_write_lineno = l->next;
+      info->current_write_lineno_index = 0;
+    }
+
+  return true;
+}
+
+/* Get the ID number for a class.  If during the same call to
+   debug_write we find a struct with the same definition with the same
+   name, we use the same ID.  This type of things happens because the
+   same struct will be defined by multiple compilation units.  */
+
+static boolean
+debug_set_class_id (info, tag, type)
+     struct debug_handle *info;
+     const char *tag;
+     struct debug_type *type;
+{
+  struct debug_class_type *c;
+  struct debug_class_id *l;
+
+  assert (type->kind == DEBUG_KIND_STRUCT
+         || type->kind == DEBUG_KIND_UNION
+         || type->kind == DEBUG_KIND_CLASS
+         || type->kind == DEBUG_KIND_UNION_CLASS);
+
+  c = type->u.kclass;
+
+  if (c->id > info->base_id)
+    return true;
+
+  for (l = info->id_list; l != NULL; l = l->next)
+    {
+      if (l->type->kind != type->kind)
+       continue;
+
+      if (tag == NULL)
+       {
+         if (l->tag != NULL)
+           continue;
+       }
+      else
+       {
+         if (l->tag == NULL
+             || l->tag[0] != tag[0]
+             || strcmp (l->tag, tag) != 0)
+           continue;
+       }
+
+      if (debug_type_samep (info, l->type, type))
+       {
+         c->id = l->type->u.kclass->id;
+         return true;
+       }
+    }
+
+  /* There are no identical types.  Use a new ID, and add it to the
+     list.  */
+  ++info->class_id;
+  c->id = info->class_id;
+
+  l = (struct debug_class_id *) xmalloc (sizeof *l);
+  memset (l, 0, sizeof *l);
+
+  l->type = type;
+  l->tag = tag;
+
+  l->next = info->id_list;
+  info->id_list = l;
+
+  return true;
+}
+
+/* See if two types are the same.  At this point, we don't care about
+   tags and the like.  */
+
+static boolean
+debug_type_samep (info, t1, t2)
+     struct debug_handle *info;
+     struct debug_type *t1;
+     struct debug_type *t2;
+{
+  struct debug_type_compare_list *l;
+  struct debug_type_compare_list top;
+  boolean ret;
+
+  if (t1 == NULL)
+    return t2 == NULL;
+  if (t2 == NULL)
+    return false;
+
+  while (t1->kind == DEBUG_KIND_INDIRECT)
+    {
+      t1 = *t1->u.kindirect->slot;
+      if (t1 == NULL)
+       return false;
+    }
+  while (t2->kind == DEBUG_KIND_INDIRECT)
+    {
+      t2 = *t2->u.kindirect->slot;
+      if (t2 == NULL)
+       return false;
+    }
+
+  if (t1 == t2)
+    return true;
+
+  /* As a special case, permit a typedef to match a tag, since C++
+     debugging output will sometimes add a typedef where C debugging
+     output will not.  */
+  if (t1->kind == DEBUG_KIND_NAMED
+      && t2->kind == DEBUG_KIND_TAGGED)
+    return debug_type_samep (info, t1->u.knamed->type, t2);
+  else if (t1->kind == DEBUG_KIND_TAGGED
+          && t2->kind == DEBUG_KIND_NAMED)
+    return debug_type_samep (info, t1, t2->u.knamed->type);
+
+  if (t1->kind != t2->kind
+      || t1->size != t2->size)
+    return false;
+
+  /* Get rid of the trivial cases first.  */
+  switch (t1->kind)
+    {
+    default:
+      break;
+    case DEBUG_KIND_VOID:
+    case DEBUG_KIND_FLOAT:
+    case DEBUG_KIND_COMPLEX:
+    case DEBUG_KIND_BOOL:
+      return true;
+    case DEBUG_KIND_INT:
+      return t1->u.kint == t2->u.kint;
+    }
+
+  /* We have to avoid an infinite recursion.  We do this by keeping a
+     list of types which we are comparing.  We just keep the list on
+     the stack.  If we encounter a pair of types we are currently
+     comparing, we just assume that they are equal.  */
+  for (l = info->compare_list; l != NULL; l = l->next)
+    {
+      if (l->t1 == t1 && l->t2 == t2)
+       return true;
+    }
+
+  top.t1 = t1;
+  top.t2 = t2;
+  top.next = info->compare_list;
+  info->compare_list = &top;
+
+  switch (t1->kind)
+    {
+    default:
+      abort ();
+      ret = false;
+      break;
+
+    case DEBUG_KIND_STRUCT:
+    case DEBUG_KIND_UNION:
+    case DEBUG_KIND_CLASS:
+    case DEBUG_KIND_UNION_CLASS:
+      if (t1->u.kclass == NULL)
+       ret = t2->u.kclass == NULL;
+      else if (t2->u.kclass == NULL)
+       ret = false;
+      else if (t1->u.kclass->id > info->base_id
+              && t1->u.kclass->id == t2->u.kclass->id)
+       ret = true;
+      else
+       ret = debug_class_type_samep (info, t1, t2);
+      break;
+
+    case DEBUG_KIND_ENUM:
+      if (t1->u.kenum == NULL)
+       ret = t2->u.kenum == NULL;
+      else if (t2->u.kenum == NULL)
+       ret = false;
+      else
+       {
+         const char **pn1, **pn2;
+         bfd_signed_vma *pv1, *pv2;
+
+         pn1 = t1->u.kenum->names;
+         pn2 = t2->u.kenum->names;
+         pv1 = t1->u.kenum->values;
+         pv2 = t2->u.kenum->values;
+         while (*pn1 != NULL && *pn2 != NULL)
+           {
+             if (**pn1 != **pn2
+                 || *pv1 != *pv2
+                 || strcmp (*pn1, *pn2) != 0)
+               break;
+             ++pn1;
+             ++pn2;
+             ++pv1;
+             ++pv2;
+           }
+         ret = *pn1 == NULL && *pn2 == NULL;
+       }
+      break;
+
+    case DEBUG_KIND_POINTER:
+      ret = debug_type_samep (info, t1->u.kpointer, t2->u.kpointer);
+      break;
+
+    case DEBUG_KIND_FUNCTION:
+      if (t1->u.kfunction->varargs != t2->u.kfunction->varargs
+         || ! debug_type_samep (info, t1->u.kfunction->return_type,
+                                t2->u.kfunction->return_type)
+         || ((t1->u.kfunction->arg_types == NULL)
+             != (t2->u.kfunction->arg_types == NULL)))
+       ret = false;
+      else if (t1->u.kfunction->arg_types == NULL)
+       ret = true;
+      else
+       {
+         struct debug_type **a1, **a2;
+
+         a1 = t1->u.kfunction->arg_types;
+         a2 = t2->u.kfunction->arg_types;
+         while (*a1 != NULL && *a2 != NULL)
+           {
+             if (! debug_type_samep (info, *a1, *a2))
+               break;
+             ++a1;
+             ++a2;
+           }
+         ret = *a1 == NULL && *a2 == NULL;
+       }
+      break;
+
+    case DEBUG_KIND_REFERENCE:
+      ret = debug_type_samep (info, t1->u.kreference, t2->u.kreference);
+      break;
+
+    case DEBUG_KIND_RANGE:
+      ret = (t1->u.krange->lower == t2->u.krange->lower
+            && t1->u.krange->upper == t2->u.krange->upper
+            && debug_type_samep (info, t1->u.krange->type,
+                                 t2->u.krange->type));
+
+    case DEBUG_KIND_ARRAY:
+      ret = (t1->u.karray->lower == t2->u.karray->lower
+            && t1->u.karray->upper == t2->u.karray->upper
+            && t1->u.karray->stringp == t2->u.karray->stringp
+            && debug_type_samep (info, t1->u.karray->element_type,
+                                 t2->u.karray->element_type));
+      break;
+
+    case DEBUG_KIND_SET:
+      ret = (t1->u.kset->bitstringp == t2->u.kset->bitstringp
+            && debug_type_samep (info, t1->u.kset->type, t2->u.kset->type));
+      break;
+
+    case DEBUG_KIND_OFFSET:
+      ret = (debug_type_samep (info, t1->u.koffset->base_type,
+                              t2->u.koffset->base_type)
+            && debug_type_samep (info, t1->u.koffset->target_type,
+                                 t2->u.koffset->target_type));
+      break;
+
+    case DEBUG_KIND_METHOD:
+      if (t1->u.kmethod->varargs != t2->u.kmethod->varargs
+         || ! debug_type_samep (info, t1->u.kmethod->return_type,
+                                t2->u.kmethod->return_type)
+         || ! debug_type_samep (info, t1->u.kmethod->domain_type,
+                                t2->u.kmethod->domain_type)
+         || ((t1->u.kmethod->arg_types == NULL)
+             != (t2->u.kmethod->arg_types == NULL)))
+       ret = false;
+      else if (t1->u.kmethod->arg_types == NULL)
+       ret = true;
+      else
+       {
+         struct debug_type **a1, **a2;
+
+         a1 = t1->u.kmethod->arg_types;
+         a2 = t2->u.kmethod->arg_types;
+         while (*a1 != NULL && *a2 != NULL)
+           {
+             if (! debug_type_samep (info, *a1, *a2))
+               break;
+             ++a1;
+             ++a2;
+           }
+         ret = *a1 == NULL && *a2 == NULL;
+       }
+      break;
+
+    case DEBUG_KIND_CONST:
+      ret = debug_type_samep (info, t1->u.kconst, t2->u.kconst);
+      break;
+
+    case DEBUG_KIND_VOLATILE:
+      ret = debug_type_samep (info, t1->u.kvolatile, t2->u.kvolatile);
+      break;
+
+    case DEBUG_KIND_NAMED:
+    case DEBUG_KIND_TAGGED:
+      ret = (strcmp (t1->u.knamed->name->name, t2->u.knamed->name->name) == 0
+            && debug_type_samep (info, t1->u.knamed->type,
+                                 t2->u.knamed->type));
+      break;
+    }
+
+  info->compare_list = top.next;
+
+  return ret;
+}
+
+/* See if two classes are the same.  This is a subroutine of
+   debug_type_samep.  */
+
+static boolean
+debug_class_type_samep (info, t1, t2)
+     struct debug_handle *info;
+     struct debug_type *t1;
+     struct debug_type *t2;
+{
+  struct debug_class_type *c1, *c2;
+
+  c1 = t1->u.kclass;
+  c2 = t2->u.kclass;
+
+  if ((c1->fields == NULL) != (c2->fields == NULL)
+      || (c1->baseclasses == NULL) != (c2->baseclasses == NULL)
+      || (c1->methods == NULL) != (c2->methods == NULL)
+      || (c1->vptrbase == NULL) != (c2->vptrbase == NULL))
+    return false;
+
+  if (c1->fields != NULL)
+    {
+      struct debug_field **pf1, **pf2;
+
+      for (pf1 = c1->fields, pf2 = c2->fields;
+          *pf1 != NULL && *pf2 != NULL;
+          pf1++, pf2++)
+       {
+         struct debug_field *f1, *f2;
+
+         f1 = *pf1;
+         f2 = *pf2;
+         if (f1->name[0] != f2->name[0]
+             || f1->visibility != f2->visibility
+             || f1->static_member != f2->static_member)
+           return false;
+         if (f1->static_member)
+           {
+             if (strcmp (f1->u.s.physname, f2->u.s.physname) != 0)
+               return false;
+           }
+         else
+           {
+             if (f1->u.f.bitpos != f2->u.f.bitpos
+                 || f1->u.f.bitsize != f2->u.f.bitsize)
+               return false;
+           }
+         /* We do the checks which require function calls last.  We
+             don't require that the types of fields have the same
+             names, since that sometimes fails in the presence of
+             typedefs and we really don't care.  */
+         if (strcmp (f1->name, f2->name) != 0
+             || ! debug_type_samep (info,
+                                    debug_get_real_type ((PTR) info,
+                                                         f1->type, NULL),
+                                    debug_get_real_type ((PTR) info,
+                                                         f2->type, NULL)))
+           return false;
+       }
+      if (*pf1 != NULL || *pf2 != NULL)
+       return false;
+    }
+
+  if (c1->vptrbase != NULL)
+    {
+      if (! debug_type_samep (info, c1->vptrbase, c2->vptrbase))
+       return false;
+    }
+
+  if (c1->baseclasses != NULL)
+    {
+      struct debug_baseclass **pb1, **pb2;
+
+      for (pb1 = c1->baseclasses, pb2 = c2->baseclasses;
+          *pb1 != NULL && *pb2 != NULL;
+          ++pb1, ++pb2)
+       {
+         struct debug_baseclass *b1, *b2;
+
+         b1 = *pb1;
+         b2 = *pb2;
+         if (b1->bitpos != b2->bitpos
+             || b1->virtual != b2->virtual
+             || b1->visibility != b2->visibility
+             || ! debug_type_samep (info, b1->type, b2->type))
+           return false;
+       }
+      if (*pb1 != NULL || *pb2 != NULL)
+       return false;
+    }
+
+  if (c1->methods != NULL)
+    {
+      struct debug_method **pm1, **pm2;
+
+      for (pm1 = c1->methods, pm2 = c2->methods;
+          *pm1 != NULL && *pm2 != NULL;
+          ++pm1, ++pm2)
+       {
+         struct debug_method *m1, *m2;
+
+         m1 = *pm1;
+         m2 = *pm2;
+         if (m1->name[0] != m2->name[0]
+             || strcmp (m1->name, m2->name) != 0
+             || (m1->variants == NULL) != (m2->variants == NULL))
+           return false;
+         if (m1->variants == NULL)
+           {
+             struct debug_method_variant **pv1, **pv2;
+
+             for (pv1 = m1->variants, pv2 = m2->variants;
+                  *pv1 != NULL && *pv2 != NULL;
+                  ++pv1, ++pv2)
+               {
+                 struct debug_method_variant *v1, *v2;
+
+                 v1 = *pv1;
+                 v2 = *pv2;
+                 if (v1->physname[0] != v2->physname[0]
+                     || v1->visibility != v2->visibility
+                     || v1->constp != v2->constp
+                     || v1->volatilep != v2->volatilep
+                     || v1->voffset != v2->voffset
+                     || (v1->context == NULL) != (v2->context == NULL)
+                     || strcmp (v1->physname, v2->physname) != 0
+                     || ! debug_type_samep (info, v1->type, v2->type))
+                   return false;
+                 if (v1->context != NULL)
+                   {
+                     if (! debug_type_samep (info, v1->context,
+                                             v2->context))
+                       return false;
+                   }
+               }
+             if (*pv1 != NULL || *pv2 != NULL)
+               return false;
+           }
+       }
+      if (*pm1 != NULL || *pm2 != NULL)
+       return false;
+    }
+
+  return true;
 }
This page took 0.054841 seconds and 4 git commands to generate.