Tidy up formatting of --help output.
[deliverable/binutils-gdb.git] / binutils / stabs.c
index a47b3bd4cadd4c34bf729edc0156192062a9d56f..bbc06320e747d327a3437d01357ba41bb68ced5d 100644 (file)
@@ -1,5 +1,6 @@
 /* stabs.c -- Parse stabs debugging information
-   Copyright (C) 1995, 1996, 1997, 1998 Free Software Foundation, Inc.
+   Copyright 1995, 1996, 1997, 1998, 1999, 2000, 2001
+   Free Software Foundation, Inc.
    Written by Ian Lance Taylor <ian@cygnus.com>.
 
    This file is part of GNU Binutils.
    trying to identify the correct address for anything.  */
 
 #include <stdio.h>
-#include <ctype.h>
 
 #include "bfd.h"
 #include "bucomm.h"
 #include "libiberty.h"
+#include "safe-ctype.h"
 #include "demangle.h"
 #include "debug.h"
 #include "budbg.h"
+#include "filenames.h"
 
 /* Meaningless definition needs by aout64.h.  FIXME.  */
 #define BYTES_IN_WORD 4
 #include "aout/aout64.h"
 #include "aout/stab_gnu.h"
 
-#ifndef DIR_SEPARATOR
-#ifdef _WIN32
-#define DIR_SEPARATOR '\\'
-#else
-#define DIR_SEPARATOR '/'
-#endif
-#endif
-
 /* The number of predefined XCOFF types.  */
 
 #define XCOFF_TYPE_COUNT 34
@@ -313,11 +307,11 @@ parse_number (pp, poverflow)
          int d;
 
          d = *p++;
-         if (isdigit ((unsigned char) d))
+         if (ISDIGIT (d))
            d -= '0';
-         else if (isupper ((unsigned char) d))
+         else if (ISUPPER (d))
            d -= 'A';
-         else if (islower ((unsigned char) d))
+         else if (ISLOWER (d))
            d -= 'a';
          else
            break;
@@ -375,7 +369,7 @@ warn_stab (p, err)
 /*ARGSUSED*/
 PTR
 start_stab (dhandle, abfd, sections, syms, symcount)
-     PTR dhandle;
+     PTR dhandle ATTRIBUTE_UNUSED;
      bfd *abfd;
      boolean sections;
      asymbol **syms;
@@ -568,12 +562,7 @@ parse_stab (dhandle, handle, type, desc, value, string)
 
          f = info->so_string;
 
-         if (   (string[0] == '/')
-             || (string[0] == DIR_SEPARATOR)
-             || (   (DIR_SEPARATOR == '\\')
-                 && (string[1] == ':')
-                 && (   (string[2] == DIR_SEPARATOR)
-                     || (string[2] == '/'))))
+          if (IS_ABSOLUTE_PATH (string))
            info->so_string = xstrdup (string);
          else
            info->so_string = concat (info->so_string, string,
@@ -706,6 +695,7 @@ parse_stab (dhandle, handle, type, desc, value, string)
     case N_OBJ:
     case N_ENDM:
     case N_MAIN:
+    case N_WARNING:
       break;
     }
 
@@ -791,7 +781,7 @@ parse_stab_string (dhandle, info, stabtype, desc, value, string)
     }
 
   ++p;
-  if (isdigit ((unsigned char) *p) || *p == '(' || *p == '-')
+  if (ISDIGIT (*p) || *p == '(' || *p == '-')
     type = 'l';
   else
     type = *p++;
@@ -1195,7 +1185,7 @@ parse_stab_type (dhandle, info, typename, pp, slotp)
   /* Read type number if present.  The type number may be omitted.
      for instance in a two-dimensional array declared with type
      "ar1;1;10;ar1;1;10;4".  */
-  if (! isdigit ((unsigned char) **pp) && **pp != '(' && **pp != '-')
+  if (! ISDIGIT (**pp) && **pp != '(' && **pp != '-')
     {
       /* 'typenums=' not present, type is anonymous.  Read and return
         the definition, but don't put it in the type vector.  */
@@ -1238,7 +1228,7 @@ parse_stab_type (dhandle, info, typename, pp, slotp)
          const char *p = *pp + 1;
          const char *attr;
 
-         if (isdigit ((unsigned char) *p) || *p == '(' || *p == '-')
+         if (ISDIGIT (*p) || *p == '(' || *p == '-')
            {
              /* Member type.  */
              break;
@@ -1261,6 +1251,7 @@ parse_stab_type (dhandle, info, typename, pp, slotp)
            {
            case 's':
              size = atoi (attr + 1);
+             size /= 8;  /* Size is in bits.  We store it in bytes.  */
              if (size <= 0)
                size = -1;
              break;
@@ -1316,14 +1307,21 @@ parse_stab_type (dhandle, info, typename, pp, slotp)
            bad_stab (orig);
            return DEBUG_TYPE_NULL;
          }
-       while (q1 != NULL && p > q1 && p[1] == ':')
+       if (q1 != NULL && p > q1 && p[1] == ':')
          {
-           q2 = strchr (q1, '>');
-           if (q2 == NULL || q2 < p)
-             break;
-           p += 2;
-           p = strchr (p, ':');
-           if (p == NULL)
+           int nest = 0;
+
+           for (q2 = q1; *q2 != '\0'; ++q2)
+             {
+               if (*q2 == '<')
+                 ++nest;
+               else if (*q2 == '>')
+                 --nest;
+               else if (*q2 == ':' && nest == 0)
+                 break;
+             }
+           p = q2;
+           if (*p != ':')
              {
                bad_stab (orig);
                return DEBUG_TYPE_NULL;
@@ -1632,7 +1630,7 @@ parse_stab_type (dhandle, info, typename, pp, slotp)
   if (size != -1)
     {
       if (! debug_record_type_size (dhandle, dtype, (unsigned int) size))
-       return false;
+       return DEBUG_TYPE_NULL;
     }
 
   return dtype;
@@ -1811,10 +1809,10 @@ parse_stab_range_type (dhandle, info, typename, pp, typenums)
            return debug_make_int_type (dhandle, 1, true);
          else if (n3 == 0xffff)
            return debug_make_int_type (dhandle, 2, true);
-         else if (n3 == 0xffffffff)
+         else if (n3 == (bfd_signed_vma) 0xffffffff)
            return debug_make_int_type (dhandle, 4, true);
 #ifdef BFD64
-         else if (n3 == ((((bfd_vma) 0xffffffff) << 32) | 0xffffffff))
+         else if (n3 == ((((bfd_signed_vma) 0xffffffff) << 32) | 0xffffffff))
            return debug_make_int_type (dhandle, 8, true);
 #endif
        }
@@ -2915,7 +2913,7 @@ parse_stab_argtypes (dhandle, info, class_type, fieldname, tagname,
   /* Constructors are sometimes handled specially.  */
   is_full_physname_constructor = ((argtypes[0] == '_'
                                   && argtypes[1] == '_'
-                                  && (isdigit ((unsigned char) argtypes[2])
+                                  && (ISDIGIT (argtypes[2])
                                       || argtypes[2] == 'Q'
                                       || argtypes[2] == 't'))
                                  || strncmp (argtypes, "__ct", 4) == 0);
@@ -3124,7 +3122,7 @@ parse_stab_array_type (dhandle, info, pp, stringp)
   /* If the index type is type 0, we take it as int.  */
   p = *pp;
   if (! parse_stab_type_number (&p, typenums))
-    return false;
+    return DEBUG_TYPE_NULL;
   if (typenums[0] == 0 && typenums[1] == 0 && **pp != '=')
     {
       index_type = debug_find_named_type (dhandle, "int");
@@ -3132,7 +3130,7 @@ parse_stab_array_type (dhandle, info, pp, stringp)
        {
          index_type = debug_make_int_type (dhandle, 4, false);
          if (index_type == DEBUG_TYPE_NULL)
-           return false;
+           return DEBUG_TYPE_NULL;
        }
       *pp = p;
     }
@@ -3151,7 +3149,7 @@ parse_stab_array_type (dhandle, info, pp, stringp)
 
   adjustable = false;
 
-  if (! isdigit ((unsigned char) **pp) && **pp != '-')
+  if (! ISDIGIT (**pp) && **pp != '-')
     {
       ++*pp;
       adjustable = true;
@@ -3161,11 +3159,11 @@ parse_stab_array_type (dhandle, info, pp, stringp)
   if (**pp != ';')
     {
       bad_stab (orig);
-      return false;
+      return DEBUG_TYPE_NULL;
     }
   ++*pp;
 
-  if (! isdigit ((unsigned char) **pp) && **pp != '-')
+  if (! ISDIGIT (**pp) && **pp != '-')
     {
       ++*pp;
       adjustable = true;
@@ -3175,14 +3173,14 @@ parse_stab_array_type (dhandle, info, pp, stringp)
   if (**pp != ';')
     {
       bad_stab (orig);
-      return false;
+      return DEBUG_TYPE_NULL;
     }
   ++*pp;
 
   element_type = parse_stab_type (dhandle, info, (const char *) NULL, pp,
                                  (debug_type **) NULL);
   if (element_type == DEBUG_TYPE_NULL)
-    return false;
+    return DEBUG_TYPE_NULL;
 
   if (adjustable)
     {
@@ -3432,7 +3430,7 @@ stab_find_type (dhandle, info, typenums)
 
 static boolean
 stab_record_type (dhandle, info, typenums, type)
-     PTR dhandle;
+     PTR dhandle ATTRIBUTE_UNUSED;
      struct stab_handle *info;
      const int *typenums;
      debug_type type;
@@ -3774,7 +3772,7 @@ stab_demangle_count (pp)
   unsigned int count;
 
   count = 0;
-  while (isdigit ((unsigned char) **pp))
+  while (ISDIGIT (**pp))
     {
       count *= 10;
       count += **pp - '0';
@@ -3791,12 +3789,12 @@ stab_demangle_get_count (pp, pi)
      const char **pp;
      unsigned int *pi;
 {
-  if (! isdigit ((unsigned char) **pp))
+  if (! ISDIGIT (**pp))
     return false;
 
   *pi = **pp - '0';
   ++*pp;
-  if (isdigit ((unsigned char) **pp))
+  if (ISDIGIT (**pp))
     {
       unsigned int count;
       const char *p;
@@ -3809,7 +3807,7 @@ stab_demangle_get_count (pp, pi)
          count += *p - '0';
          ++p;
        }
-      while (isdigit ((unsigned char) *p));
+      while (ISDIGIT (*p));
       if (*p == '_')
        {
          *pp = p + 1;
@@ -3904,7 +3902,7 @@ stab_demangle_prefix (minfo, pp)
     scan += i - 2;
 
   if (scan == *pp
-      && (isdigit ((unsigned char) scan[2])
+      && (ISDIGIT (scan[2])
          || scan[2] == 'Q'
          || scan[2] == 't'))
     {
@@ -3913,7 +3911,7 @@ stab_demangle_prefix (minfo, pp)
       return true;
     }
   else if (scan == *pp
-          && ! isdigit ((unsigned char) scan[2])
+          && ! ISDIGIT (scan[2])
           && scan[2] != 't')
     {
       /* Look for the `__' that separates the prefix from the
@@ -4128,13 +4126,13 @@ stab_demangle_qualified (minfo, pp, ptype)
         preceded by an underscore (to distinguish it from the <= 9
         case) and followed by an underscore.  */
       p = *pp + 2;
-      if (! isdigit ((unsigned char) *p) || *p == '0')
+      if (! ISDIGIT (*p) || *p == '0')
        {
          stab_bad_demangle (orig);
          return false;
        }
       qualifiers = atoi (p);
-      while (isdigit ((unsigned char) *p))
+      while (ISDIGIT (*p))
        ++p;
       if (*p != '_')
        {
@@ -4399,7 +4397,7 @@ stab_demangle_template (minfo, pp, pname)
            {
              if (**pp == 'm')
                ++*pp;
-             while (isdigit ((unsigned char) **pp))
+             while (ISDIGIT (**pp))
                ++*pp;
            }
          else if (charp)
@@ -4430,18 +4428,18 @@ stab_demangle_template (minfo, pp, pname)
            {
              if (**pp == 'm')
                ++*pp;
-             while (isdigit ((unsigned char) **pp))
+             while (ISDIGIT (**pp))
                ++*pp;
              if (**pp == '.')
                {
                  ++*pp;
-                 while (isdigit ((unsigned char) **pp))
+                 while (ISDIGIT (**pp))
                    ++*pp;
                }
              if (**pp == 'e')
                {
                  ++*pp;
-                 while (isdigit ((unsigned char) **pp))
+                 while (ISDIGIT (**pp))
                    ++*pp;
                }
            }
@@ -4463,7 +4461,7 @@ stab_demangle_template (minfo, pp, pname)
      regular demangling routine.  */
   if (pname != NULL)
     {
-      char *s1, *s2, *s3, *s4;
+      char *s1, *s2, *s3, *s4 = NULL;
       char *from, *to;
 
       s1 = savestring (orig, *pp - orig);
@@ -4506,7 +4504,7 @@ stab_demangle_template (minfo, pp, pname)
 
 static boolean
 stab_demangle_class (minfo, pp, pstart)
-     struct stab_demangle_info *minfo;
+     struct stab_demangle_info *minfo ATTRIBUTE_UNUSED;
      const char **pp;
      const char **pstart;
 {
@@ -4694,7 +4692,7 @@ stab_demangle_type (minfo, pp, ptype)
        high = 0;
        while (**pp != '\0' && **pp != '_')
          {
-           if (! isdigit ((unsigned char) **pp))
+           if (! ISDIGIT (**pp))
              {
                stab_bad_demangle (orig);
                return false;
@@ -4785,6 +4783,7 @@ stab_demangle_type (minfo, pp, ptype)
     case 'O':
       {
        boolean memberp, constp, volatilep;
+       debug_type class_type = DEBUG_TYPE_NULL;
        debug_type *args;
        boolean varargs;
        unsigned int n;
@@ -4797,19 +4796,40 @@ stab_demangle_type (minfo, pp, ptype)
        varargs = false;
 
        ++*pp;
-       if (! isdigit ((unsigned char) **pp))
+       if (ISDIGIT (**pp))
          {
-           stab_bad_demangle (orig);
-           return false;
+           n = stab_demangle_count (pp);
+           if (strlen (*pp) < n)
+             {
+               stab_bad_demangle (orig);
+               return false;
+             }
+           name = *pp;
+           *pp += n;
+
+           if (ptype != NULL)
+             {
+               class_type = stab_find_tagged_type (minfo->dhandle,
+                                                   minfo->info,
+                                                   name, (int) n,
+                                                   DEBUG_KIND_CLASS);
+               if (class_type == DEBUG_TYPE_NULL)
+                 return false;
+             }
+         }
+       else if (**pp == 'Q')
+         {
+           if (! stab_demangle_qualified (minfo, pp,
+                                          (ptype == NULL
+                                           ? (debug_type *) NULL
+                                           : &class_type)))
+             return false;
          }
-       n = stab_demangle_count (pp);
-       if (strlen (*pp) < n)
+       else
          {
            stab_bad_demangle (orig);
            return false;
          }
-       name = *pp;
-       *pp += n;
 
        if (memberp)
          {
@@ -4851,14 +4871,6 @@ stab_demangle_type (minfo, pp, ptype)
 
        if (ptype != NULL)
          {
-           debug_type class_type;
-
-           class_type = stab_find_tagged_type (minfo->dhandle, minfo->info,
-                                               name, (int) n,
-                                               DEBUG_KIND_CLASS);
-           if (class_type == DEBUG_TYPE_NULL)
-             return false;
-
            if (! memberp)
              *ptype = debug_make_offset_type (minfo->dhandle, class_type,
                                               *ptype);
@@ -5094,7 +5106,7 @@ stab_demangle_fund_type (minfo, pp, ptype)
 
     case 'G':
       ++*pp;
-      if (! isdigit ((unsigned char) **pp))
+      if (! ISDIGIT (**pp))
        {
          stab_bad_demangle (orig);
          return false;
This page took 0.031219 seconds and 4 git commands to generate.