* configure.in: Make --without-x work.
[deliverable/binutils-gdb.git] / binutils / debug.c
index d7ff67d5760e829c8f8300ae70bbf307c57117de..3ce609bdca90027f130fe7b32f90f5f04254e929 100644 (file)
@@ -1,5 +1,5 @@
 /* debug.c -- Handle generic debugging information.
-   Copyright (C) 1995, 1996, 1998 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.
@@ -541,6 +541,17 @@ struct debug_type_compare_list
   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 *));
@@ -552,7 +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));
+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 *));
@@ -591,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;
@@ -1027,8 +1039,8 @@ 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"));
@@ -1039,8 +1051,8 @@ 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"));
@@ -1131,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;
 }
 
@@ -1199,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;
 {
@@ -1766,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);
@@ -1794,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;
@@ -1825,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;
@@ -1851,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;
 {
@@ -1878,11 +1885,10 @@ 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, physname, type, visibility, constp,
                           volatilep, voffset, context)
-     PTR handle;
+     PTR handle ATTRIBUTE_UNUSED;
      const char *physname;
      debug_type type;
      enum debug_visibility visibility;
@@ -1914,7 +1920,7 @@ debug_make_method_variant (handle, physname, type, visibility, constp,
 debug_method_variant
 debug_make_static_method_variant (handle, physname, type, visibility,
                                  constp, volatilep)
-     PTR handle;
+     PTR handle ATTRIBUTE_UNUSED;
      const char *physname;
      debug_type type;
      enum debug_visibility visibility;
@@ -1956,7 +1962,7 @@ debug_name_type (handle, name, type)
       || info->current_file == NULL)
     {
       debug_error (_("debug_name_type: no current file"));
-      return false;
+      return DEBUG_TYPE_NULL;
     }
 
   t = debug_make_type (info, DEBUG_KIND_NAMED, 0);
@@ -1976,7 +1982,7 @@ debug_name_type (handle, name, type)
   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;
 
@@ -2032,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;
 
@@ -2043,10 +2049,9 @@ 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;
 {
@@ -2111,7 +2116,7 @@ debug_find_named_type (handle, name)
        }
     }
 
-  return DEBUG_TYPE_NULL;        
+  return DEBUG_TYPE_NULL;
 }
 
 /* Find a tagged type.  */
@@ -2154,24 +2159,54 @@ debug_find_tagged_type (handle, name, kind)
   return DEBUG_TYPE_NULL;
 }
 
-/* Get a base type.  */
+/* 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)
+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);
+       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);
+      return debug_get_real_type (handle, type->u.knamed->type, &rl);
     }
   /*NOTREACHED*/
 }
@@ -2185,7 +2220,9 @@ debug_get_type_kind (handle, type)
 {
   if (type == NULL)
     return DEBUG_KIND_ILLEGAL;
-  type = debug_get_real_type (handle, type);
+  type = debug_get_real_type (handle, type, NULL);
+  if (type == NULL)
+    return DEBUG_KIND_ILLEGAL;
   return type->kind;
 }
 
@@ -2248,7 +2285,9 @@ debug_get_return_type (handle, type)
 {
   if (type == NULL)
     return DEBUG_TYPE_NULL;
-  type = debug_get_real_type (handle, type);
+  type = debug_get_real_type (handle, type, NULL);
+  if (type == NULL)
+    return DEBUG_TYPE_NULL;
   switch (type->kind)
     {
     default:
@@ -2258,7 +2297,7 @@ debug_get_return_type (handle, type)
     case DEBUG_KIND_METHOD:
       return type->u.kmethod->return_type;
     }
-  /*NOTREACHED*/      
+  /*NOTREACHED*/
 }
 
 /* Get the parameter types of a function or method type (except that
@@ -2272,7 +2311,9 @@ debug_get_parameter_types (handle, type, pvarargs)
 {
   if (type == NULL)
     return NULL;
-  type = debug_get_real_type (handle, type);
+  type = debug_get_real_type (handle, type, NULL);
+  if (type == NULL)
+    return NULL;
   switch (type->kind)
     {
     default:
@@ -2296,7 +2337,9 @@ debug_get_target_type (handle, type)
 {
   if (type == NULL)
     return NULL;
-  type = debug_get_real_type (handle, type);
+  type = debug_get_real_type (handle, type, NULL);
+  if (type == NULL)
+    return NULL;
   switch (type->kind)
     {
     default:
@@ -2323,7 +2366,9 @@ debug_get_fields (handle, type)
 {
   if (type == NULL)
     return NULL;
-  type = debug_get_real_type (handle, type);
+  type = debug_get_real_type (handle, type, NULL);
+  if (type == NULL)
+    return NULL;
   switch (type->kind)
     {
     default:
@@ -2339,10 +2384,9 @@ debug_get_fields (handle, type)
 
 /* Get the type of a field.  */
 
-/*ARGSUSED*/
 debug_type
 debug_get_field_type (handle, field)
-     PTR handle;
+     PTR handle ATTRIBUTE_UNUSED;
      debug_field field;
 {
   if (field == NULL)
@@ -2352,10 +2396,9 @@ debug_get_field_type (handle, field)
 
 /* Get the name of a field.  */
 
-/*ARGSUSED*/
 const char *
 debug_get_field_name (handle, field)
-     PTR handle;
+     PTR handle ATTRIBUTE_UNUSED;
      debug_field field;
 {
   if (field == NULL)
@@ -2365,10 +2408,9 @@ debug_get_field_name (handle, field)
 
 /* Get the bit position of a field.  */
 
-/*ARGSUSED*/
 bfd_vma
 debug_get_field_bitpos (handle, field)
-     PTR handle;
+     PTR handle ATTRIBUTE_UNUSED;
      debug_field field;
 {
   if (field == NULL || field->static_member)
@@ -2378,10 +2420,9 @@ debug_get_field_bitpos (handle, field)
 
 /* Get the bit size of a field.  */
 
-/*ARGSUSED*/
 bfd_vma
 debug_get_field_bitsize (handle, field)
-     PTR handle;
+     PTR handle ATTRIBUTE_UNUSED;
      debug_field field;
 {
   if (field == NULL || field->static_member)
@@ -2391,10 +2432,9 @@ debug_get_field_bitsize (handle, field)
 
 /* Get the visibility of a field.  */
 
-/*ARGSUSED*/
 enum debug_visibility
 debug_get_field_visibility (handle, field)
-     PTR handle;
+     PTR handle ATTRIBUTE_UNUSED;
      debug_field field;
 {
   if (field == NULL)
@@ -2406,7 +2446,7 @@ debug_get_field_visibility (handle, field)
 
 const char *
 debug_get_field_physname (handle, field)
-     PTR handle;
+     PTR handle ATTRIBUTE_UNUSED;
      debug_field field;
 {
   if (field == NULL || ! field->static_member)
@@ -2546,7 +2586,7 @@ debug_write_type (info, fns, fhandle, type, name)
 {
   unsigned int i;
   int is;
-  const char *tag;
+  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
@@ -2564,7 +2604,9 @@ debug_write_type (info, fns, fhandle, type, name)
          struct debug_type *real;
          unsigned int id;
 
-         real = debug_get_real_type ((PTR) info, type);
+         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
@@ -2594,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)
@@ -3261,7 +3302,7 @@ debug_type_samep (info, t1, t2)
     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,
@@ -3421,9 +3462,9 @@ debug_class_type_samep (info, t1, t2)
          if (strcmp (f1->name, f2->name) != 0
              || ! debug_type_samep (info,
                                     debug_get_real_type ((PTR) info,
-                                                         f1->type),
+                                                         f1->type, NULL),
                                     debug_get_real_type ((PTR) info,
-                                                         f2->type)))
+                                                         f2->type, NULL)))
            return false;
        }
       if (*pf1 != NULL || *pf2 != NULL)
This page took 0.048309 seconds and 4 git commands to generate.