]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blobdiff - binutils/prdbg.c
import gdb-1999-12-21 snapshot
[thirdparty/binutils-gdb.git] / binutils / prdbg.c
index 133973ca0a747a52cf43a22dbdc22dfb4dce1889..abd684dfeb0709ab5c65ab20d71076d799419755 100644 (file)
@@ -1,5 +1,5 @@
 /* prdbg.c -- Print out generic debugging information.
-   Copyright (C) 1995, 1996 Free Software Foundation, Inc.
+   Copyright (C) 1995, 1996, 1999 Free Software Foundation, Inc.
    Written by Ian Lance Taylor <ian@cygnus.com>.
 
    This file is part of GNU Binutils.
@@ -81,23 +81,24 @@ static boolean pr_bool_type PARAMS ((PTR, unsigned int));
 static boolean pr_enum_type
   PARAMS ((PTR, const char *, const char **, bfd_signed_vma *));
 static boolean pr_pointer_type PARAMS ((PTR));
-static boolean pr_function_type PARAMS ((PTR));
+static boolean pr_function_type PARAMS ((PTR, int, boolean));
 static boolean pr_reference_type PARAMS ((PTR));
 static boolean pr_range_type PARAMS ((PTR, bfd_signed_vma, bfd_signed_vma));
 static boolean pr_array_type
   PARAMS ((PTR, bfd_signed_vma, bfd_signed_vma, boolean));
 static boolean pr_set_type PARAMS ((PTR, boolean));
 static boolean pr_offset_type PARAMS ((PTR));
-static boolean pr_method_type PARAMS ((PTR, boolean, int));
+static boolean pr_method_type PARAMS ((PTR, boolean, int, boolean));
 static boolean pr_const_type PARAMS ((PTR));
 static boolean pr_volatile_type PARAMS ((PTR));
 static boolean pr_start_struct_type
-  PARAMS ((PTR, const char *, boolean, unsigned int));
+  PARAMS ((PTR, const char *, unsigned int, boolean, unsigned int));
 static boolean pr_struct_field
   PARAMS ((PTR, const char *, bfd_vma, bfd_vma, enum debug_visibility));
 static boolean pr_end_struct_type PARAMS ((PTR));
 static boolean pr_start_class_type
-  PARAMS ((PTR, const char *, boolean, unsigned int, boolean, boolean));
+  PARAMS ((PTR, const char *, unsigned int, boolean, unsigned int, boolean,
+          boolean));
 static boolean pr_class_static_member
   PARAMS ((PTR, const char *, const char *, enum debug_visibility));
 static boolean pr_class_baseclass
@@ -111,7 +112,8 @@ static boolean pr_class_static_method_variant
 static boolean pr_class_end_method PARAMS ((PTR));
 static boolean pr_end_class_type PARAMS ((PTR));
 static boolean pr_typedef_type PARAMS ((PTR, const char *));
-static boolean pr_tag_type PARAMS ((PTR, const char *, enum debug_type_kind));
+static boolean pr_tag_type
+  PARAMS ((PTR, const char *, unsigned int, enum debug_type_kind));
 static boolean pr_typdef PARAMS ((PTR, const char *));
 static boolean pr_tag PARAMS ((PTR, const char *));
 static boolean pr_int_constant PARAMS ((PTR, const char *, bfd_vma));
@@ -563,23 +565,91 @@ pr_pointer_type (p)
      PTR p;
 {
   struct pr_handle *info = (struct pr_handle *) p;
+  char *s;
 
   assert (info->stack != NULL);
 
+  s = strchr (info->stack->type, '|');
+  if (s != NULL && s[1] == '[')
+    return substitute_type (info, "(*|)");
   return substitute_type (info, "*|");
 }
 
 /* Turn the top type on the stack into a function returning that type.  */
 
 static boolean
-pr_function_type (p)
+pr_function_type (p, argcount, varargs)
      PTR p;
+     int argcount;
+     boolean varargs;
 {
   struct pr_handle *info = (struct pr_handle *) p;
+  char **arg_types;
+  unsigned int len;
+  char *s;
 
   assert (info->stack != NULL);
 
-  return substitute_type (info, "(|) ()");
+  len = 10;
+
+  if (argcount <= 0)
+    {
+      arg_types = NULL;
+      len += 15;
+    }
+  else
+    {
+      int i;
+
+      arg_types = (char **) xmalloc (argcount * sizeof *arg_types);
+      for (i = argcount - 1; i >= 0; i--)
+       {
+         if (! substitute_type (info, ""))
+           return false;
+         arg_types[i] = pop_type (info);
+         if (arg_types[i] == NULL)
+           return false;
+         len += strlen (arg_types[i]) + 2;
+       }
+      if (varargs)
+       len += 5;
+    }
+
+  /* Now the return type is on the top of the stack.  */
+
+  s = (char *) xmalloc (len);
+  strcpy (s, "(|) (");
+
+  if (argcount < 0)
+    strcat (s, "/* unknown */");
+  else
+    {
+      int i;
+
+      for (i = 0; i < argcount; i++)
+       {
+         if (i > 0)
+           strcat (s, ", ");
+         strcat (s, arg_types[i]);
+       }
+      if (varargs)
+       {
+         if (i > 0)
+           strcat (s, ", ");
+         strcat (s, "...");
+       }
+      if (argcount > 0)
+       free (arg_types);
+    }
+
+  strcat (s, ")");
+
+  if (! substitute_type (info, s))
+    return false;
+
+  free (s);
+
+  return true;
 }
 
 /* Turn the top type on the stack into a reference to that type.  */
@@ -726,10 +796,11 @@ pr_offset_type (p)
 /* Make a method type.  */
 
 static boolean
-pr_method_type (p, domain, argcount)
+pr_method_type (p, domain, argcount, varargs)
      PTR p;
      boolean domain;
      int argcount;
+     boolean varargs;
 {
   struct pr_handle *info = (struct pr_handle *) p;
   unsigned int len;
@@ -778,6 +849,8 @@ pr_method_type (p, domain, argcount)
            return false;
          len += strlen (arg_types[i]) + 2;
        }
+      if (varargs)
+       len += 5;
     }
 
   /* Now the return type is on the top of the stack.  */
@@ -801,6 +874,14 @@ pr_method_type (p, domain, argcount)
            strcat (s, ", ");
          strcat (s, arg_types[i]);
        }
+      if (varargs)
+       {
+         if (i > 0)
+           strcat (s, ", ");
+         strcat (s, "...");
+       }
+      if (argcount > 0)
+       free (arg_types);
     }
 
   strcat (s, ")");
@@ -838,14 +919,14 @@ pr_volatile_type (p)
 /* Start accumulating a struct type.  */
 
 static boolean
-pr_start_struct_type (p, tag, structp, size)
+pr_start_struct_type (p, tag, id, structp, size)
      PTR p;
      const char *tag;
+     unsigned int id;
      boolean structp;
      unsigned int size;
 {
   struct pr_handle *info = (struct pr_handle *) p;
-  char ab[30];
 
   info->indent += 2;
 
@@ -853,17 +934,47 @@ pr_start_struct_type (p, tag, structp, size)
     return false;
   if (tag != NULL)
     {
-      if (! append_type (info, tag)
-         || ! append_type (info, " "))
+      if (! append_type (info, tag))
        return false;
     }
-  if (size != 0)
-    sprintf (ab, "{ /* size %u */\n", size);
   else
-    strcpy (ab, "{\n");
-  if (! append_type (info, ab))
+    {
+      char idbuf[20];
+
+      sprintf (idbuf, "%%anon%u", id);
+      if (! append_type (info, idbuf))
+       return false;
+    }
+
+  if (! append_type (info, " {"))
+    return false;
+  if (size != 0 || tag != NULL)
+    {
+      char ab[30];
+
+      if (! append_type (info, " /*"))
+       return false;
+
+      if (size != 0)
+       {
+         sprintf (ab, " size %u", size);
+         if (! append_type (info, ab))
+           return false;
+       }
+      if (tag != NULL)
+       {
+         sprintf (ab, " id %u", id);
+         if (! append_type (info, ab))
+           return false;
+       }
+      if (! append_type (info, " */"))
+       return false;
+    }
+  if (! append_type (info, "\n"))
     return false;
+
   info->stack->visibility = DEBUG_VISIBILITY_PUBLIC;
+
   return indent_type (info);
 }
 
@@ -874,17 +985,16 @@ pr_fix_visibility (info, visibility)
      struct pr_handle *info;
      enum debug_visibility visibility;
 {
-  const char *s;
-  struct pr_stack *top;
+  const char *s = NULL;
   char *t;
   unsigned int len;
 
-  assert (info->stack != NULL && info->stack->next != NULL);
+  assert (info->stack != NULL);
 
-  if (info->stack->next->visibility == visibility)
+  if (info->stack->visibility == visibility)
     return true;
 
-  assert (info->stack->next->visibility != DEBUG_VISIBILITY_IGNORE);
+  assert (info->stack->visibility != DEBUG_VISIBILITY_IGNORE);
 
   switch (visibility)
     {
@@ -897,18 +1007,16 @@ pr_fix_visibility (info, visibility)
     case DEBUG_VISIBILITY_PROTECTED:
       s = "protected";
       break;
+    case DEBUG_VISIBILITY_IGNORE:
+      s = "/* ignore */";
+      break;
     default:
       abort ();
       return false;
     }
 
   /* Trim off a trailing space in the struct string, to make the
-     output look a bit better, then stick on the visibility string.
-     Pop the stack temporarily to make the string manipulation
-     simpler.  */
-
-  top = info->stack;
-  info->stack = top->next;
+     output look a bit better, then stick on the visibility string.  */
 
   t = info->stack->type;
   len = strlen (t);
@@ -922,8 +1030,6 @@ pr_fix_visibility (info, visibility)
 
   info->stack->visibility = visibility;
 
-  info->stack = top;
-
   return true;
 }
 
@@ -939,9 +1045,7 @@ pr_struct_field (p, name, bitpos, bitsize, visibility)
 {
   struct pr_handle *info = (struct pr_handle *) p;
   char ab[20];
-
-  if (! pr_fix_visibility (info, visibility))
-    return false;
+  char *t;
 
   if (! substitute_type (info, name))
     return false;
@@ -965,7 +1069,14 @@ pr_struct_field (p, name, bitpos, bitsize, visibility)
       || ! indent_type (info))
     return false;
 
-  return append_type (info, pop_type (info));
+  t = pop_type (info);
+  if (t == NULL)
+    return false;
+
+  if (! pr_fix_visibility (info, visibility))
+    return false;
+
+  return append_type (info, t);
 }
 
 /* Finish a struct type.  */
@@ -984,7 +1095,7 @@ pr_end_struct_type (p)
 
   /* Change the trailing indentation to have a close brace.  */
   s = info->stack->type + strlen (info->stack->type) - 2;
-  assert (strcmp (s, "  ") == 0);
+  assert (s[0] == ' ' && s[1] == ' ' && s[2] == '\0');
 
   *s++ = '}';
   *s = '\0';
@@ -995,9 +1106,10 @@ pr_end_struct_type (p)
 /* Start a class type.  */
 
 static boolean
-pr_start_class_type (p, tag, structp, size, vptr, ownvptr)
+pr_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;
@@ -1019,13 +1131,21 @@ pr_start_class_type (p, tag, structp, size, vptr, ownvptr)
     return false;
   if (tag != NULL)
     {
-      if (! append_type (info, tag)
-         || ! append_type (info, " "))
+      if (! append_type (info, tag))
        return false;
     }
-  if (! append_type (info, "{"))
+  else
+    {
+      char idbuf[20];
+
+      sprintf (idbuf, "%%anon%u", id);
+      if (! append_type (info, idbuf))
+       return false;
+    }
+
+  if (! append_type (info, " {"))
     return false;
-  if (size != 0 || vptr || ownvptr)
+  if (size != 0 || vptr || ownvptr || tag != NULL)
     {
       if (! append_type (info, " /*"))
        return false;
@@ -1057,6 +1177,15 @@ pr_start_class_type (p, tag, structp, size, vptr, ownvptr)
            }
        }
 
+      if (tag != NULL)
+       {
+         char ab[30];
+
+         sprintf (ab, " id %u", id);
+         if (! append_type (info, ab))
+           return false;
+       }
+
       if (! append_type (info, " */"))
        return false;
     }
@@ -1077,19 +1206,26 @@ pr_class_static_member (p, name, physname, visibility)
      enum debug_visibility visibility;
 {
   struct pr_handle *info = (struct pr_handle *) p;
+  char *t;
 
-  if (! pr_fix_visibility (info, visibility))
+  if (! substitute_type (info, name))
     return false;
 
-  if (! substitute_type (info, name))
+  if (! prepend_type (info, "static ")
+      || ! append_type (info, "; /* ")
+      || ! append_type (info, physname)
+      || ! append_type (info, " */\n")
+      || ! indent_type (info))
     return false;
 
-  return (prepend_type (info, "static ")
-         && append_type (info, "; /* physname ")
-         && append_type (info, physname)
-         && append_type (info, " */\n")
-         && indent_type (info)
-         && append_type (info, pop_type (info)));
+  t = pop_type (info);
+  if (t == NULL)
+    return false;
+
+  if (! pr_fix_visibility (info, visibility))
+    return false;
+
+  return append_type (info, t);
 }
 
 /* Add a base class to a class.  */
@@ -1200,8 +1336,7 @@ pr_class_start_method (p, name)
 {
   struct pr_handle *info = (struct pr_handle *) p;
 
-  if (! push_type (info, ""))
-    return false;
+  assert (info->stack != NULL);
   info->stack->method = name;
   return true;
 }
@@ -1209,10 +1344,10 @@ pr_class_start_method (p, name)
 /* Add a variant to a method.  */
 
 static boolean
-pr_class_method_variant (p, argtypes, visibility, constp, volatilep, voffset,
+pr_class_method_variant (p, physname, visibility, constp, volatilep, voffset,
                         context)
      PTR p;
-     const char *argtypes;
+     const char *physname;
      enum debug_visibility visibility;
      boolean constp;
      boolean volatilep;
@@ -1229,12 +1364,12 @@ pr_class_method_variant (p, argtypes, visibility, constp, volatilep, voffset,
   /* Put the const and volatile qualifiers on the type.  */
   if (volatilep)
     {
-      if (! prepend_type (info, "volatile "))
+      if (! append_type (info, " volatile"))
        return false;
     }
   if (constp)
     {
-      if (! prepend_type (info, "const "))
+      if (! append_type (info, " const"))
        return false;
     }
 
@@ -1260,15 +1395,15 @@ pr_class_method_variant (p, argtypes, visibility, constp, volatilep, voffset,
        return false;
     }
 
-  /* Now the top of the stack is the holder for the method, and the
-     second element on the stack is the class.  */
+  /* Now the top of the stack is the class.  */
 
   if (! pr_fix_visibility (info, visibility))
     return false;
 
   if (! append_type (info, method_type)
       || ! append_type (info, " /* ")
-      || ! append_type (info, argtypes))
+      || ! append_type (info, physname)
+      || ! append_type (info, " "))
     return false;
   if (context || voffset != 0)
     {
@@ -1294,9 +1429,9 @@ pr_class_method_variant (p, argtypes, visibility, constp, volatilep, voffset,
 /* Add a static variant to a method.  */
 
 static boolean
-pr_class_static_method_variant (p, argtypes, visibility, constp, volatilep)
+pr_class_static_method_variant (p, physname, visibility, constp, volatilep)
      PTR p;
-     const char *argtypes;
+     const char *physname;
      enum debug_visibility visibility;
      boolean constp;
      boolean volatilep;
@@ -1311,12 +1446,12 @@ pr_class_static_method_variant (p, argtypes, visibility, constp, volatilep)
   /* Put the const and volatile qualifiers on the type.  */
   if (volatilep)
     {
-      if (! prepend_type (info, "volatile "))
+      if (! append_type (info, " volatile"))
        return false;
     }
   if (constp)
     {
-      if (! prepend_type (info, "const "))
+      if (! append_type (info, " const"))
        return false;
     }
 
@@ -1333,15 +1468,14 @@ pr_class_static_method_variant (p, argtypes, visibility, constp, volatilep)
   if (method_type == NULL)
     return false;
 
-  /* Now the top of the stack is the holder for the method, and the
-     second element on the stack is the class.  */
+  /* Now the top of the stack is the class.  */
 
   if (! pr_fix_visibility (info, visibility))
     return false;
 
   return (append_type (info, method_type)
          && append_type (info, " /* ")
-         && append_type (info, argtypes)
+         && append_type (info, physname)
          && append_type (info, " */;\n")
          && indent_type (info));
 }
@@ -1354,11 +1488,8 @@ pr_class_end_method (p)
 {
   struct pr_handle *info = (struct pr_handle *) p;
 
-  /* The method variants have been appended to the string on top of
-     the stack with the correct indentation.  We just need the append
-     the string on top of the stack to the class string that is second
-     on the stack.  */
-  return append_type (info, pop_type (info));
+  info->stack->method = NULL;
+  return true;
 }
 
 /* Finish up a class.  */
@@ -1385,13 +1516,15 @@ pr_typedef_type (p, name)
 /* Push a type on the stack using a tag name.  */
 
 static boolean
-pr_tag_type (p, name, kind)
+pr_tag_type (p, name, id, kind)
      PTR p;
      const char *name;
+     unsigned int id;
      enum debug_type_kind kind;
 {
   struct pr_handle *info = (struct pr_handle *) p;
-  const char *t;
+  const char *t, *tag;
+  char idbuf[20];
 
   switch (kind)
     {
@@ -1415,8 +1548,26 @@ pr_tag_type (p, name, kind)
       return false;
     }
 
-  return (push_type (info, t)
-         && append_type (info, name));
+  if (! push_type (info, t))
+    return false;
+  if (name != NULL)
+    tag = name;
+  else
+    {
+      sprintf (idbuf, "%%anon%u", id);
+      tag = idbuf;
+    }
+
+  if (! append_type (info, tag))
+    return false;
+  if (name != NULL && kind != DEBUG_KIND_ENUM)
+    {
+      sprintf (idbuf, " /* id %u */", id);
+      if (! append_type (info, idbuf))
+       return false;
+    }
+
+  return true;
 }
 
 /* Output a typedef.  */
@@ -1451,7 +1602,7 @@ pr_typdef (p, name)
 static boolean
 pr_tag (p, name)
      PTR p;
-     const char *name;
+     const char *name ATTRIBUTE_UNUSED;
 {
   struct pr_handle *info = (struct pr_handle *) p;
   char *t;
@@ -1476,7 +1627,7 @@ pr_int_constant (p, name, val)
      const char *name;
      bfd_vma val;
 {
-  struct pr_handle *info = (struct pr_handle *) info;
+  struct pr_handle *info = (struct pr_handle *) p;
   char ab[20];
 
   indent (info);
@@ -1493,7 +1644,7 @@ pr_float_constant (p, name, val)
      const char *name;
      double val;
 {
-  struct pr_handle *info = (struct pr_handle *) info;
+  struct pr_handle *info = (struct pr_handle *) p;
 
   indent (info);
   fprintf (info->f, "const double %s = %g;\n", name, val);
@@ -1705,7 +1856,7 @@ pr_end_block (p, addr)
 /*ARGSUSED*/
 static boolean
 pr_end_function (p)
-     PTR p;
+     PTR p ATTRIBUTE_UNUSED;
 {
   return true;
 }