* config/m88k/{tm-delta88.h,tm-delta88v4.h}, m88k-tdep.c:
[deliverable/binutils-gdb.git] / gdb / stabsread.c
index 7e928613413df71288d48e1f3b8524faede4f210..59a659c84f1e5892e5eeaa36732e4c579cf1df8c 100644 (file)
@@ -194,7 +194,8 @@ static int undef_types_length;
 /* Check for and handle cretinous stabs symbol name continuation!  */
 #define STABS_CONTINUE(pp)                             \
   do {                                                 \
-    if (**(pp) == '\\') *(pp) = next_symbol_text ();   \
+    if (**(pp) == '\\' || (**(pp) == '?' && (*(pp))[1] == '\0')) \
+      *(pp) = next_symbol_text ();     \
   } while (0)
 
 \f
@@ -450,6 +451,10 @@ read_type_number (pp, typenums)
 
 static char *type_synonym_name;
 
+#if !defined (REG_STRUCT_HAS_ADDR)
+#define REG_STRUCT_HAS_ADDR(gcc_p) 0
+#endif
+
 /* ARGSUSED */
 struct symbol *
 define_symbol (valu, string, desc, type, objfile)
@@ -931,12 +936,22 @@ define_symbol (valu, string, desc, type, objfile)
             name to represent an argument passed in a register.
             GCC uses 'P' for the same case.  So if we find such a symbol pair
             we combine it into one 'P' symbol.
+
+            But we only do this in the REG_STRUCT_HAS_ADDR case, so that
+            we can still get information about what is going on with the
+            stack (VAX for computing args_printed, using stack slots instead
+            of saved registers in backtraces, etc.).
+
             Note that this code illegally combines
-              main(argc) int argc; { register int argc = 1; }
+              main(argc) struct foo argc; { register struct foo argc; }
             but this case is considered pathological and causes a warning
             from a decent compiler.  */
+
          if (local_symbols
-             && local_symbols->nsyms > 0)
+             && local_symbols->nsyms > 0
+             && REG_STRUCT_HAS_ADDR (processing_gcc_compilation)
+             && (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_STRUCT
+                 || TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_UNION))
            {
              struct symbol *prev_sym;
              prev_sym = local_symbols->symbol[local_symbols->nsyms - 1];
@@ -1123,13 +1138,9 @@ define_symbol (valu, string, desc, type, objfile)
      If REG_STRUCT_HAS_ADDR yields non-zero we have to convert LOC_REGPARM
      to LOC_REGPARM_ADDR for structures and unions.  */
 
-#if !defined (REG_STRUCT_HAS_ADDR)
-#define REG_STRUCT_HAS_ADDR(gcc_p) 0
-#endif
-
   if (SYMBOL_CLASS (sym) == LOC_REGPARM
       && REG_STRUCT_HAS_ADDR (processing_gcc_compilation)
-      && (   (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_STRUCT)
+      && ((TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_STRUCT)
          || (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_UNION)))
     SYMBOL_CLASS (sym) = LOC_REGPARM_ADDR;
 
@@ -1180,7 +1191,7 @@ error_type (pp)
        }
 
       /* Check for and handle cretinous dbx symbol name continuation!  */
-      if ((*pp)[-1] == '\\')
+      if ((*pp)[-1] == '\\' || (*pp)[-1] == '?')
        {
          *pp = next_symbol_text ();
        }
@@ -1214,6 +1225,9 @@ read_type (pp, objfile)
      there is no size attribute.  */
   int type_size = -1;
 
+  /* Used to distinguish string and bitstring from char-array and set. */
+  int is_string = 0;
+
   /* 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".  */
@@ -1263,6 +1277,11 @@ read_type (pp, objfile)
                  if (type_size <= 0)
                    type_size = -1;
                  break;
+
+               case 'S':
+                 is_string = 1;
+                 break;
+
                default:
                  /* Ignore unrecognized type attributes, so future compilers
                     can invent new ones.  */
@@ -1296,7 +1315,7 @@ read_type (pp, objfile)
        char *type_name;
        
        {
-         char *from, *to, *p;
+         char *from, *to, *p, *q1, *q2;
          
          /* Set the type code according to the following letter.  */
          switch ((*pp)[0])
@@ -1322,11 +1341,15 @@ read_type (pp, objfile)
              }
            }
           
+         q1 = strchr(*pp, '<');
          p = strchr(*pp, ':');
          if (p == NULL)
            return error_type (pp);
-         while (p[1] == ':')
+         while (q1 && p > q1 && p[1] == ':')
            {
+              q2 = strchr(q1, '>');
+              if (!q2 || q2 < p)
+                break;
               p += 2;
               p = strchr(p, ':');
               if (p == NULL)
@@ -1346,13 +1369,12 @@ read_type (pp, objfile)
          *pp = from + 1;
        }
 
-       /* Now check to see whether the type has already been declared.  */
-       /* This is necessary at least in the case where the
-          program says something like
-            struct foo bar[5];
-          The compiler puts out a cross-reference; we better find
-          set the length of the structure correctly so we can
-          set the length of the array.  */
+       /* Now check to see whether the type has already been
+          declared.  This was written for arrays of cross-referenced
+          types before we had TYPE_CODE_TARGET_STUBBED, so I'm pretty
+          sure it is not necessary anymore.  But it might be a good
+          idea, to save a little memory.  */
+
        for (ppt = file_symbols; ppt; ppt = ppt->next)
          for (i = 0; i < ppt->nsyms; i++)
            {
@@ -1368,7 +1390,7 @@ read_type (pp, objfile)
                  return type;
                }
            }
-       
+
        /* Didn't find the type to which this refers, so we must
           be dealing with a forward reference.  Allocate a type
           structure for it, and keep track of it so we can
@@ -1397,41 +1419,49 @@ read_type (pp, objfile)
     case '9':
     case '(':
 
-      (*pp)--;
-      if (read_type_number (pp, xtypenums) != 0)
-       return error_type (pp);
+      {
+       char *pp_saved;
 
-      if (typenums[0] == xtypenums[0] && typenums[1] == xtypenums[1])
-       /* It's being defined as itself.  That means it is "void".  */
-       type = init_type (TYPE_CODE_VOID, 0, 0, NULL, objfile);
-      else
-       {
-         struct type *xtype = *dbx_lookup_type (xtypenums);
+       (*pp)--;
+       pp_saved = *pp;
 
-         /* This can happen if we had '-' followed by a garbage character,
-            for example.  */
-         if (xtype == NULL)
-           return error_type (pp);
+       /* Peek ahead at the number to detect void.  */
+       if (read_type_number (pp, xtypenums) != 0)
+         return error_type (pp);
 
-         /* The type is being defined to another type.  So we copy the type.
-            This loses if we copy a C++ class and so we lose track of how
-            the names are mangled (but g++ doesn't output stabs like this
-            now anyway).  */
-
-         type = alloc_type (objfile);
-         memcpy (type, xtype, sizeof (struct type));
-
-         /* The idea behind clearing the names is that the only purpose
-            for defining a type to another type is so that the name of
-            one can be different.  So we probably don't need to worry much
-            about the case where the compiler doesn't give a name to the
-            new type.  */
-         TYPE_NAME (type) = NULL;
-         TYPE_TAG_NAME (type) = NULL;
-       }
-      if (typenums[0] != -1)
-       *dbx_lookup_type (typenums) = type;
-      break;
+       if (typenums[0] == xtypenums[0] && typenums[1] == xtypenums[1])
+         /* It's being defined as itself.  That means it is "void".  */
+         type = init_type (TYPE_CODE_VOID, 0, 0, NULL, objfile);
+       else
+         {
+           struct type *xtype;
+
+           /* Go back to the number and have read_type get it.  This means
+              that we can deal with something like t(1,2)=(3,4)=... which
+              the Lucid compiler uses.  */
+           *pp = pp_saved;
+           xtype = read_type (pp, objfile);
+
+           /* The type is being defined to another type.  So we copy the type.
+              This loses if we copy a C++ class and so we lose track of how
+              the names are mangled (but g++ doesn't output stabs like this
+              now anyway).  */
+
+           type = alloc_type (objfile);
+           memcpy (type, xtype, sizeof (struct type));
+
+           /* The idea behind clearing the names is that the only purpose
+              for defining a type to another type is so that the name of
+              one can be different.  So we probably don't need to worry much
+              about the case where the compiler doesn't give a name to the
+              new type.  */
+           TYPE_NAME (type) = NULL;
+           TYPE_TAG_NAME (type) = NULL;
+         }
+       if (typenums[0] != -1)
+         *dbx_lookup_type (typenums) = type;
+       break;
+      }
 
     /* In the following types, we must be sure to overwrite any existing
        type that the typenums refer to, rather than allocating a new one
@@ -1567,6 +1597,17 @@ read_type (pp, objfile)
       
       type = dbx_alloc_type (typenums, objfile);
       type = read_array_type (pp, type, objfile);
+      if (is_string)
+       TYPE_CODE (type) = TYPE_CODE_STRING;
+      break;
+
+    case 'S':
+      type1 = read_type (pp, objfile);
+      type = create_set_type ((struct type*) NULL, type1);
+      if (is_string)
+       TYPE_CODE (type) = TYPE_CODE_BITSTRING;
+      if (typenums[0] != -1)
+       *dbx_lookup_type (typenums) = type;
       break;
 
     default:
@@ -2344,7 +2385,7 @@ read_struct_fields (fip, pp, type, objfile)
        }
       read_one_struct_field (fip, pp, p, type, objfile);
     }
-  if (p[1] == ':')
+  if (p[0] == ':' && p[1] == ':')
     {
       /* chill the list of fields: the last entry (at the head) is a
         partially constructed entry which we now scrub. */
@@ -2795,7 +2836,7 @@ read_array_type (pp, type, objfile)
     return error_type (pp);
   ++*pp;
 
-  if (!(**pp >= '0' && **pp <= '9'))
+  if (!(**pp >= '0' && **pp <= '9') && **pp != '-')
     {
       (*pp)++;
       adjustable = 1;
@@ -2804,7 +2845,7 @@ read_array_type (pp, type, objfile)
   if (nbits != 0)
     return error_type (pp);
 
-  if (!(**pp >= '0' && **pp <= '9'))
+  if (!(**pp >= '0' && **pp <= '9') && **pp != '-')
     {
       (*pp)++;
       adjustable = 1;
@@ -2827,9 +2868,14 @@ read_array_type (pp, type, objfile)
 
   /* If we have an array whose element type is not yet known, but whose
      bounds *are* known, record it to be adjusted at the end of the file.  */
+  /* FIXME: Why check for zero length rather than TYPE_FLAG_STUB?  I think
+     the two have the same effect except that the latter is cleaner and the
+     former would be wrong for types which really are zero-length (if we
+     have any).  */
 
   if (TYPE_LENGTH (element_type) == 0 && !adjustable)
     {
+      TYPE_FLAGS (type) |= TYPE_FLAG_TARGET_STUB;
       add_undefined_type (type);
     }
 
@@ -2900,7 +2946,7 @@ read_enum_type (pp, type, objfile)
 
   /* Now fill in the fields of the type-structure.  */
 
-  TYPE_LENGTH (type) = sizeof (int);
+  TYPE_LENGTH (type) = TARGET_INT_BIT / HOST_CHAR_BIT;
   TYPE_CODE (type) = TYPE_CODE_ENUM;
   TYPE_FLAGS (type) &= ~TYPE_FLAG_STUB;
   TYPE_NFIELDS (type) = nsyms;
@@ -3527,7 +3573,10 @@ cleanup_undefined_types ()
          case TYPE_CODE_UNION:
          case TYPE_CODE_ENUM:
          {
-           /* Check if it has been defined since.  */
+           /* Check if it has been defined since.  Need to do this here
+              as well as in check_stub_type to deal with the (legitimate in
+              C though not C++) case of several types with the same name
+              in different source files.  */
            if (TYPE_FLAGS (*type) & TYPE_FLAG_STUB)
              {
                struct pending *ppt;
@@ -3562,8 +3611,20 @@ cleanup_undefined_types ()
          }
          break;
 
-         case TYPE_CODE_ARRAY:
+       case TYPE_CODE_ARRAY:
          {
+           /* This is a kludge which is here for historical reasons
+              because I suspect that check_stub_type does not get
+              called everywhere it needs to be called for arrays.  Even
+              with this kludge, those places are broken for the case
+              where the stub type is defined in another compilation
+              unit, but this kludge at least deals with it for the case
+              in which it is the same compilation unit.
+
+              Don't try to do this by calling check_stub_type; it might
+              cause symbols to be read in lookup_symbol, and the symbol
+              reader is not reentrant.  */
+
            struct type *range_type;
            int lower, upper;
 
@@ -3581,6 +3642,9 @@ cleanup_undefined_types ()
            upper = TYPE_FIELD_BITPOS (range_type, 1);
            TYPE_LENGTH (*type) = (upper - lower + 1)
              * TYPE_LENGTH (TYPE_TARGET_TYPE (*type));
+
+           /* If the target type is not a stub, we could be clearing
+              TYPE_FLAG_TARGET_STUB for *type.  */
          }
          break;
 
@@ -3594,6 +3658,7 @@ GDB internal error.  cleanup_undefined_types with bad type %d.", 0, 0};
          break;
        }
     }
+
   undef_types_length = 0;
 }
 
This page took 0.028395 seconds and 4 git commands to generate.