daily update
[deliverable/binutils-gdb.git] / binutils / stabs.c
index 7af10ef54faed438761b87b9be0deafcc233cd60..ea0a61e411890378de2fa39f115846dd7bc95956 100644 (file)
@@ -1,13 +1,13 @@
 /* stabs.c -- Parse stabs debugging information
-   Copyright 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004
-   Free Software Foundation, Inc.
+   Copyright 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
+   2006, 2007 Free Software Foundation, Inc.
    Written by Ian Lance Taylor <ian@cygnus.com>.
 
    This file is part of GNU Binutils.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2 of the License, or
+   the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.
 
    This program is distributed in the hope that it will be useful,
 
    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
-   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
-   02111-1307, USA.  */
+   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
+   02110-1301, USA.  */
 
 /* This file contains code which parses stabs debugging information.
    The organization of this code is based on the gdb stabs reading
    code.  The job it does is somewhat different, because it is not
    trying to identify the correct address for anything.  */
 
-#include <stdio.h>
-
+#include "sysdep.h"
 #include "bfd.h"
-#include "bucomm.h"
 #include "libiberty.h"
 #include "safe-ctype.h"
 #include "demangle.h"
@@ -203,6 +201,8 @@ static debug_type *stab_demangle_argtypes
   (void *, struct stab_handle *, const char *, bfd_boolean *, unsigned int);
 static debug_type *stab_demangle_v3_argtypes
   (void *, struct stab_handle *, const char *, bfd_boolean *);
+static debug_type *stab_demangle_v3_arglist
+  (void *, struct stab_handle *, struct demangle_component *, bfd_boolean *);
 static debug_type stab_demangle_v3_arg
   (void *, struct stab_handle *, struct demangle_component *, debug_type,
    bfd_boolean *);
@@ -1694,12 +1694,12 @@ parse_stab_range_type (void *dhandle, struct stab_handle *info, const char *type
 #define ULLHIGH "01777777777777777777777;"
       if (index_type == DEBUG_TYPE_NULL)
        {
-         if (strncmp (s2, LLLOW, sizeof LLLOW - 1) == 0
-             && strncmp (s3, LLHIGH, sizeof LLHIGH - 1) == 0)
+         if (CONST_STRNEQ (s2, LLLOW)
+             && CONST_STRNEQ (s3, LLHIGH))
            return debug_make_int_type (dhandle, 8, FALSE);
          if (! ov2
              && n2 == 0
-             && strncmp (s3, ULLHIGH, sizeof ULLHIGH - 1) == 0)
+             && CONST_STRNEQ (s3, ULLHIGH))
            return debug_make_int_type (dhandle, 8, TRUE);
        }
 
@@ -2830,7 +2830,7 @@ parse_stab_argtypes (void *dhandle, struct stab_handle *info,
                                   && (ISDIGIT (argtypes[2])
                                       || argtypes[2] == 'Q'
                                       || argtypes[2] == 't'))
-                                 || strncmp (argtypes, "__ct", 4) == 0);
+                                 || CONST_STRNEQ (argtypes, "__ct"));
 
   is_constructor = (is_full_physname_constructor
                    || (tagname != NULL
@@ -2838,7 +2838,7 @@ parse_stab_argtypes (void *dhandle, struct stab_handle *info,
   is_destructor = ((argtypes[0] == '_'
                    && (argtypes[1] == '$' || argtypes[1] == '.')
                    && argtypes[2] == '_')
-                  || strncmp (argtypes, "__dt", 4) == 0);
+                  || CONST_STRNEQ (argtypes, "__dt"));
   is_v3 = argtypes[0] == '_' && argtypes[1] == 'Z';
 
   if (is_destructor || is_full_physname_constructor || is_v3)
@@ -3839,7 +3839,7 @@ stab_demangle_function_name (struct stab_demangle_info *minfo,
   *pp = scan + 2;
 
   if (*pp - name >= 5
-          && strncmp (name, "type", 4) == 0
+          && CONST_STRNEQ (name, "type")
           && (name[4] == '$' || name[4] == '.'))
     {
       const char *tem;
@@ -4319,7 +4319,8 @@ stab_demangle_template (struct stab_demangle_info *minfo, const char **pp,
            {
              unsigned int len;
 
-             if (! stab_demangle_get_count (pp, &len))
+             len = stab_demangle_count (pp);
+             if (len == 0)
                {
                  stab_bad_demangle (orig);
                  return FALSE;
@@ -5073,7 +5074,6 @@ stab_demangle_v3_argtypes (void *dhandle, struct stab_handle *info,
 {
   struct demangle_component *dc;
   void *mem;
-  unsigned int alloc, count;
   debug_type *pargs;
 
   dc = cplus_demangle_v3_components (physname, DMGL_PARAMS | DMGL_ANSI, &mem);
@@ -5093,13 +5093,35 @@ stab_demangle_v3_argtypes (void *dhandle, struct stab_handle *info,
       return NULL;
     }
 
+  pargs = stab_demangle_v3_arglist (dhandle, info,
+                                   dc->u.s_binary.right->u.s_binary.right,
+                                   pvarargs);
+
+  free (mem);
+
+  return pargs;
+}
+
+/* Demangle an argument list in a struct demangle_component tree.
+   Returns a DEBUG_TYPE_NULL terminated array of argument types, and
+   sets *PVARARGS to indicate whether this is a varargs function.  */
+
+static debug_type *
+stab_demangle_v3_arglist (void *dhandle, struct stab_handle *info,
+                         struct demangle_component *arglist,
+                         bfd_boolean *pvarargs)
+{
+  struct demangle_component *dc;
+  unsigned int alloc, count;
+  debug_type *pargs;
+
   alloc = 10;
   pargs = (debug_type *) xmalloc (alloc * sizeof *pargs);
   *pvarargs = FALSE;
 
   count = 0;
 
-  for (dc = dc->u.s_binary.right->u.s_binary.right;
+  for (dc = arglist;
        dc != NULL;
        dc = dc->u.s_binary.right)
     {
@@ -5108,8 +5130,8 @@ stab_demangle_v3_argtypes (void *dhandle, struct stab_handle *info,
 
       if (dc->type != DEMANGLE_COMPONENT_ARGLIST)
        {
-         fprintf (stderr, _("Unexpected type in demangle tree\n"));
-         free (mem);
+         fprintf (stderr, _("Unexpected type in v3 arglist demangling\n"));
+         free (pargs);
          return NULL;
        }
 
@@ -5122,7 +5144,7 @@ stab_demangle_v3_argtypes (void *dhandle, struct stab_handle *info,
              *pvarargs = TRUE;
              continue;
            }
-         free (mem);
+         free (pargs);
          return NULL;
        }
 
@@ -5138,8 +5160,6 @@ stab_demangle_v3_argtypes (void *dhandle, struct stab_handle *info,
 
   pargs[count] = DEBUG_TYPE_NULL;
 
-  free (mem);
-
   return pargs;
 }
 
@@ -5173,12 +5193,12 @@ stab_demangle_v3_arg (void *dhandle, struct stab_handle *info,
     case DEMANGLE_COMPONENT_COMPLEX:
     case DEMANGLE_COMPONENT_IMAGINARY:
     case DEMANGLE_COMPONENT_VENDOR_TYPE:
-    case DEMANGLE_COMPONENT_FUNCTION_TYPE:
     case DEMANGLE_COMPONENT_ARRAY_TYPE:
     case DEMANGLE_COMPONENT_PTRMEM_TYPE:
     case DEMANGLE_COMPONENT_ARGLIST:
     default:
-      fprintf (stderr, _("Unrecognized demangle component\n"));
+      fprintf (stderr, _("Unrecognized demangle component %d\n"),
+              (int) dc->type);
       return NULL;
 
     case DEMANGLE_COMPONENT_NAME:
@@ -5269,6 +5289,34 @@ stab_demangle_v3_arg (void *dhandle, struct stab_handle *info,
          return debug_make_reference_type (dhandle, dt);
        }
 
+    case DEMANGLE_COMPONENT_FUNCTION_TYPE:
+      {
+       debug_type *pargs;
+       bfd_boolean varargs;
+
+       if (dc->u.s_binary.left == NULL)
+         {
+           /* In this case the return type is actually unknown.
+              However, I'm not sure this will ever arise in practice;
+              normally an unknown return type would only appear at
+              the top level, which is handled above.  */
+           dt = debug_make_void_type (dhandle);
+         }
+       else
+         dt = stab_demangle_v3_arg (dhandle, info, dc->u.s_binary.left, NULL,
+                                    NULL);
+       if (dt == NULL)
+         return NULL;
+
+       pargs = stab_demangle_v3_arglist (dhandle, info,
+                                         dc->u.s_binary.right,
+                                         &varargs);
+       if (pargs == NULL)
+         return NULL;
+
+       return debug_make_function_type (dhandle, dt, pargs, varargs);
+      }
+
     case DEMANGLE_COMPONENT_BUILTIN_TYPE:
       {
        char *p;
This page took 0.026098 seconds and 4 git commands to generate.