* inftarg.c (child_thread_alive): New function to see if a
[deliverable/binutils-gdb.git] / gdb / stabsread.c
index 6c81c10ae7eb76d8fc28480515b97d45aa28d403..ccd7b8e28b0db7496a2bc7855e4d7b3d92706de8 100644 (file)
@@ -1,5 +1,5 @@
 /* Support routines for decoding "stabs" debugging information format.
-   Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994
+   Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995
              Free Software Foundation, Inc.
 
 This file is part of GDB.
@@ -33,6 +33,9 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
 #include "symfile.h"
 #include "objfiles.h"
 #include "aout/stab_gnu.h"     /* We always use GNU stabs, not native */
+#include "libaout.h"
+#include "aout/aout64.h"
+#include "gdb-stabs.h"
 #include "buildsym.h"
 #include "complaints.h"
 #include "demangle.h"
@@ -183,6 +186,9 @@ struct complaint unrecognized_cplus_name_complaint =
 struct complaint rs6000_builtin_complaint =
   {"Unknown builtin type %d", 0, 0};
 
+struct complaint unresolved_sym_chain_complaint =
+  {"%s: `%s' from global_sym_chain unresolved", 0, 0};
+
 struct complaint stabs_general_complaint =
   {"%s", 0, 0};
 
@@ -540,6 +546,19 @@ define_symbol (valu, string, desc, type, objfile)
     obstack_alloc (&objfile -> symbol_obstack, sizeof (struct symbol));
   memset (sym, 0, sizeof (struct symbol));
 
+  switch (type & N_TYPE)
+    {
+    case N_TEXT:
+      SYMBOL_SECTION(sym) = SECT_OFF_TEXT;
+      break;
+    case N_DATA:
+      SYMBOL_SECTION(sym) = SECT_OFF_DATA;
+      break;
+    case N_BSS:
+      SYMBOL_SECTION(sym) = SECT_OFF_BSS;
+      break;
+    }
+
   if (processing_gcc_compilation)
     {
       /* GCC 2.x puts the line number in desc.  SunOS apparently puts in the
@@ -574,6 +593,12 @@ define_symbol (valu, string, desc, type, objfile)
            /* This was an anonymous type that was never fixed up.  */
            goto normal;
 
+#ifdef STATIC_TRANSFORM_NAME
+         case 'X':
+           /* SunPRO (3.0 at least) static variable encoding.  */
+           goto normal;
+#endif
+
          default:
            complain (&unrecognized_cplus_name_complaint, string);
            goto normal;                /* Do *something* with it */
@@ -758,23 +783,7 @@ define_symbol (valu, string, desc, type, objfile)
         We need to convert this to the function-returning-type-X type
         in GDB.  E.g. "int" is converted to "function returning int".  */
       if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_FUNC)
-       {
-#if 0
-         /* This code doesn't work -- it needs to realloc and can't.  */
-         /* Attempt to set up to record a function prototype... */
-         struct type *new = alloc_type (objfile);
-
-         /* Generate a template for the type of this function.  The 
-            types of the arguments will be added as we read the symbol 
-            table. */
-         *new = *lookup_function_type (SYMBOL_TYPE(sym));
-         SYMBOL_TYPE(sym) = new;
-         TYPE_OBJFILE (new) = objfile;
-         in_function_type = new;
-#else
-         SYMBOL_TYPE (sym) = lookup_function_type (SYMBOL_TYPE (sym));
-#endif
-       }
+       SYMBOL_TYPE (sym) = lookup_function_type (SYMBOL_TYPE (sym));
       /* fall into process_prototype_types */
 
     process_prototype_types:
@@ -845,17 +854,15 @@ define_symbol (valu, string, desc, type, objfile)
       SYMBOL_CLASS (sym) = DBX_PARM_SYMBOL_CLASS (type);
       SYMBOL_VALUE (sym) = valu;
       SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
-#if 0
-      /* This doesn't work yet.  */
-      add_param_to_type (&in_function_type, sym);
-#endif
       add_symbol_to_list (sym, &local_symbols);
 
-#if TARGET_BYTE_ORDER == LITTLE_ENDIAN
-      /* On little-endian machines, this crud is never necessary, and,
-        if the extra bytes contain garbage, is harmful.  */
-      break;
-#else /* Big endian.  */
+      if (TARGET_BYTE_ORDER != BIG_ENDIAN)
+       {
+         /* On little-endian machines, this crud is never necessary,
+            and, if the extra bytes contain garbage, is harmful.  */
+         break;
+       }
+
       /* If it's gcc-compiled, if it says `short', believe it.  */
       if (processing_gcc_compilation || BELIEVE_PCC_PROMOTION)
        break;
@@ -934,7 +941,6 @@ define_symbol (valu, string, desc, type, objfile)
 #endif /* no BELIEVE_PCC_PROMOTION_TYPE.  */
       }
 #endif /* !BELIEVE_PCC_PROMOTION.  */
-#endif /* Big endian.  */
 
     case 'P':
       /* acc seems to use P to delare the prototypes of functions that
@@ -977,9 +983,11 @@ define_symbol (valu, string, desc, type, objfile)
          /* Sun cc uses a pair of symbols, one 'p' and one 'r' with the same
             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.
+            we combine it into one 'P' symbol.  For Sun cc we need to do this
+            regardless of REG_STRUCT_HAS_ADDR, because the compiler puts out
+            the 'p' symbol even if it never saves the argument onto the stack.
 
-            But we only do this in the REG_STRUCT_HAS_ADDR case, so that
+            On most machines, we want to preserve both symbols, 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.).
@@ -991,14 +999,18 @@ define_symbol (valu, string, desc, type, objfile)
 
          if (local_symbols
              && local_symbols->nsyms > 0
+#ifndef USE_REGISTER_NOT_ARG
              && REG_STRUCT_HAS_ADDR (processing_gcc_compilation,
                                      SYMBOL_TYPE (sym))
              && (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_STRUCT
-                 || TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_UNION))
+                 || TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_UNION)
+#endif
+             )
            {
              struct symbol *prev_sym;
              prev_sym = local_symbols->symbol[local_symbols->nsyms - 1];
-             if (SYMBOL_CLASS (prev_sym) == LOC_REF_ARG
+             if ((SYMBOL_CLASS (prev_sym) == LOC_REF_ARG
+                  || SYMBOL_CLASS (prev_sym) == LOC_ARG)
                  && STREQ (SYMBOL_NAME (prev_sym), SYMBOL_NAME(sym)))
                {
                  SYMBOL_CLASS (prev_sym) = LOC_REGPARM;
@@ -1021,6 +1033,18 @@ define_symbol (valu, string, desc, type, objfile)
       SYMBOL_TYPE (sym) = read_type (&p, objfile);
       SYMBOL_CLASS (sym) = LOC_STATIC;
       SYMBOL_VALUE_ADDRESS (sym) = valu;
+#ifdef STATIC_TRANSFORM_NAME
+      if (SYMBOL_NAME (sym)[0] == '$')
+      {
+       struct minimal_symbol *msym;
+       msym = lookup_minimal_symbol (SYMBOL_NAME (sym), NULL, objfile);
+       if (msym != NULL)
+         {
+           SYMBOL_NAME (sym) = STATIC_TRANSFORM_NAME (SYMBOL_NAME (sym));
+           SYMBOL_VALUE_ADDRESS (sym) = SYMBOL_VALUE_ADDRESS (msym);
+         }
+      }
+#endif
       SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
       add_symbol_to_list (sym, &file_symbols);
       break;
@@ -1053,7 +1077,13 @@ define_symbol (valu, string, desc, type, objfile)
 
       if (TYPE_NAME (SYMBOL_TYPE (sym)) == NULL)
        {
-         if (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_PTR
+         /* gcc-2.6 or later (when using -fvtable-thunks)
+            emits a unique named type for a vtable entry.
+            Some gdb code depends on that specific name. */
+         extern const char vtbl_ptr_name[];
+
+         if ((TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_PTR
+              && strcmp (SYMBOL_NAME (sym), vtbl_ptr_name))
              || TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_FUNC)
            {
              /* If we are giving a name to a type such as "pointer to
@@ -1141,6 +1171,18 @@ define_symbol (valu, string, desc, type, objfile)
       SYMBOL_TYPE (sym) = read_type (&p, objfile);
       SYMBOL_CLASS (sym) = LOC_STATIC;
       SYMBOL_VALUE_ADDRESS (sym) = valu;
+#ifdef STATIC_TRANSFORM_NAME
+      if (SYMBOL_NAME (sym)[0] == '$')
+      {
+       struct minimal_symbol *msym;
+       msym = lookup_minimal_symbol (SYMBOL_NAME (sym), NULL, objfile);
+       if (msym != NULL)
+         {
+           SYMBOL_NAME (sym) = STATIC_TRANSFORM_NAME (SYMBOL_NAME (sym));
+           SYMBOL_VALUE_ADDRESS (sym) = SYMBOL_VALUE_ADDRESS (msym);
+         }
+      }
+#endif
       SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
       if (os9k_stabs)
        add_symbol_to_list (sym, &global_symbols);
@@ -1157,6 +1199,20 @@ define_symbol (valu, string, desc, type, objfile)
       add_symbol_to_list (sym, &local_symbols);
       break;
 
+    case 'a':
+      /* Reference parameter which is in a register.  */
+      SYMBOL_TYPE (sym) = read_type (&p, objfile);
+      SYMBOL_CLASS (sym) = LOC_REGPARM_ADDR;
+      SYMBOL_VALUE (sym) = STAB_REG_TO_REGNUM (valu);
+      if (SYMBOL_VALUE (sym) >= NUM_REGS)
+       {
+         complain (&reg_value_complaint, SYMBOL_SOURCE_NAME (sym));
+         SYMBOL_VALUE (sym) = SP_REGNUM;  /* Known safe, though useless */
+       }
+      SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
+      add_symbol_to_list (sym, &local_symbols);
+      break;
+
     case 'X':
       /* This is used by Sun FORTRAN for "function result value".
         Sun claims ("dbx and dbxtool interfaces", 2nd ed)
@@ -1539,13 +1595,17 @@ read_type (pp, objfile)
     case 'f':                          /* Function returning another type */
       if (os9k_stabs && **pp == '(')
        {
-         /* Function prototype; skip it.
+         /* Function prototype; parse it.
             We must conditionalize this on os9k_stabs because otherwise
             it could be confused with a Sun-style (1,3) typenumber
             (I think).  */
-         while (**pp != ')')
-           ++*pp;
+         struct type *t;
          ++*pp;
+         while (**pp != ')')
+            {
+              t = read_type(pp, objfile);
+              if (**pp == ',') ++*pp;
+            }
        }
       type1 = read_type (pp, objfile);
       type = make_function_type (type1, dbx_lookup_type (typenums));
@@ -1707,7 +1767,7 @@ read_type (pp, objfile)
 
   /* Size specified in a type attribute overrides any other size.  */
   if (type_size != -1)
-    TYPE_LENGTH (type) = type_size / TARGET_CHAR_BIT;
+    TYPE_LENGTH (type) = (type_size + TARGET_CHAR_BIT - 1) / TARGET_CHAR_BIT;
 
   return type;
 }
@@ -1720,7 +1780,7 @@ rs6000_builtin_type (typenum)
      int typenum;
 {
   /* We recognize types numbered from -NUMBER_RECOGNIZED to -1.  */
-#define NUMBER_RECOGNIZED 30
+#define NUMBER_RECOGNIZED 34
   /* This includes an empty slot for type number -0.  */
   static struct type *negative_types[NUMBER_RECOGNIZED + 1];
   struct type *rettype = NULL;
@@ -1854,6 +1914,20 @@ rs6000_builtin_type (typenum)
     case 30:
       rettype = init_type (TYPE_CODE_CHAR, 2, 0, "wchar", NULL);
       break;
+    case 31:
+      rettype = init_type (TYPE_CODE_INT, 8, 0, "long long", NULL);
+      break;
+    case 32:
+      rettype = init_type (TYPE_CODE_INT, 8, TYPE_FLAG_UNSIGNED,
+                          "unsigned long long", NULL);
+      break;
+    case 33:
+      rettype = init_type (TYPE_CODE_INT, 8, TYPE_FLAG_UNSIGNED,
+                          "logical*8", NULL);
+      break;
+    case 34:
+      rettype = init_type (TYPE_CODE_INT, 8, 0, "integer*8", NULL);
+      break;
     }
   negative_types[-typenum] = rettype;
   return rettype;
@@ -2423,6 +2497,7 @@ read_struct_fields (fip, pp, type, objfile)
 
   while (**pp != ';')
     {
+      if (os9k_stabs && **pp == ',') break;
       STABS_CONTINUE (pp);
       /* Get space to record the next field's data.  */
       new = (struct nextfield *) xmalloc (sizeof (struct nextfield));
@@ -2717,17 +2792,6 @@ attach_fn_fields_to_type (fip, type)
 {
   register int n;
 
-  for (n = 0; n < TYPE_N_BASECLASSES (type); n++)
-    {
-      if (TYPE_CODE (TYPE_BASECLASS (type, n)) == TYPE_CODE_UNDEF)
-       {
-         /* @@ Memory leak on objfile -> type_obstack?  */
-         return 0;
-       }
-      TYPE_NFN_FIELDS_TOTAL (type) +=
-       TYPE_NFN_FIELDS_TOTAL (TYPE_BASECLASS (type, n));
-    }
-
   for (n = TYPE_NFN_FIELDS (type);
        fip -> fnlist != NULL;
        fip -> fnlist = fip -> fnlist -> next)
@@ -2956,12 +3020,8 @@ 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)
+  if ((TYPE_FLAGS (element_type) & TYPE_FLAG_STUB) && !adjustable)
     {
       TYPE_FLAGS (type) |= TYPE_FLAG_TARGET_STUB;
       add_undefined_type (type);
@@ -3060,12 +3120,11 @@ read_enum_type (pp, type, objfile)
      that in something like "enum {FOO, LAST_THING=FOO}" we print
      FOO, not LAST_THING.  */
 
-  for (syms = *symlist, n = 0; syms; syms = syms->next)
+  for (syms = *symlist, n = nsyms - 1; ; syms = syms->next)
     {
-      int j = 0;
-      if (syms == osyms)
-       j = o_nsyms;
-      for (; j < syms->nsyms; j++,n++)
+      int last = syms == osyms ? o_nsyms : 0;
+      int j = syms->nsyms;
+      for (; --j >= last; --n)
        {
          struct symbol *xsym = syms->symbol[j];
          SYMBOL_TYPE (xsym) = type;
@@ -3232,7 +3291,11 @@ read_huge_number (pp, end, bits)
       p++;
     }
 
-  upper_limit = LONG_MAX / radix;
+  if (os9k_stabs)
+    upper_limit = ULONG_MAX / radix;
+  else
+    upper_limit = LONG_MAX / radix;
+
   while ((c = *p++) >= '0' && c < ('0' + radix))
     {
       if (n <= upper_limit)
@@ -3310,22 +3373,27 @@ read_range_type (pp, typenums, objfile)
      int typenums[2];
      struct objfile *objfile;
 {
+  char *orig_pp = *pp;
   int rangenums[2];
   long n2, n3;
   int n2bits, n3bits;
   int self_subrange;
   struct type *result_type;
-  struct type *index_type;
+  struct type *index_type = NULL;
 
   /* First comes a type we are a subrange of.
      In C it is usually 0, 1 or the type being defined.  */
-  /* FIXME: according to stabs.texinfo and AIX doc, this can be a type-id
-     not just a type number.  */
   if (read_type_number (pp, rangenums) != 0)
     return error_type (pp);
   self_subrange = (rangenums[0] == typenums[0] &&
                   rangenums[1] == typenums[1]);
 
+  if (**pp == '=')
+    {
+      *pp = orig_pp;
+      index_type = read_type (pp, objfile);
+    }
+
   /* A semicolon should now follow; skip it.  */
   if (**pp == ';')
     (*pp)++;
@@ -3337,7 +3405,10 @@ read_range_type (pp, typenums, objfile)
 
   if (n2bits == -1 || n3bits == -1)
     return error_type (pp);
-  
+
+  if (index_type)
+    goto handle_true_range;
+
   /* If limits are huge, must be large integral type.  */
   if (n2bits != 0 || n3bits != 0)
     {
@@ -3445,6 +3516,7 @@ read_range_type (pp, typenums, objfile)
 
   /* We have a real range type on our hands.  Allocate space and
      return a real pointer.  */
+ handle_true_range:
 
   /* At this point I don't have the faintest idea how to deal with
      a self_subrange type; I'm going to assume that this is used
@@ -3764,23 +3836,47 @@ GDB internal error.  cleanup_undefined_types with bad type %d.", 0, 0};
 
 /* Scan through all of the global symbols defined in the object file,
    assigning values to the debugging symbols that need to be assigned
-   to.  Get these symbols from the minimal symbol table.  */
+   to.  Get these symbols from the minimal symbol table.
+   Return 1 if there might still be unresolved debugging symbols, else 0.  */
 
-void
-scan_file_globals (objfile)
+static int scan_file_globals_1 PARAMS ((struct objfile *));
+
+static int
+scan_file_globals_1 (objfile)
      struct objfile *objfile;
 {
   int hash;
   struct minimal_symbol *msymbol;
   struct symbol *sym, *prev;
 
+  /* Avoid expensive loop through all minimal symbols if there are
+     no unresolved symbols.  */
+  for (hash = 0; hash < HASHSIZE; hash++)
+    {
+      if (global_sym_chain[hash])
+       break;
+    }
+  if (hash >= HASHSIZE)
+    return 0;
+
   if (objfile->msymbols == 0)          /* Beware the null file.  */
-    return;
+    return 1;
 
   for (msymbol = objfile -> msymbols; SYMBOL_NAME (msymbol) != NULL; msymbol++)
     {
       QUIT;
 
+      /* Skip static symbols.  */
+      switch (MSYMBOL_TYPE (msymbol))
+       {
+       case mst_file_text:
+       case mst_file_data:
+       case mst_file_bss:
+         continue;
+       default:
+         break;
+       }
+
       prev = NULL;
 
       /* Get the hash index and check all the symbols
@@ -3816,6 +3912,8 @@ scan_file_globals (objfile)
                {
                  SYMBOL_VALUE_ADDRESS (sym) = SYMBOL_VALUE_ADDRESS (msymbol);
                }
+
+             SYMBOL_SECTION (sym) = SYMBOL_SECTION (msymbol);
              
              if (prev)
                {
@@ -3833,6 +3931,42 @@ scan_file_globals (objfile)
            }
        }
     }
+  return 1;
+}
+
+/* Assign values to global debugging symbols.
+   Search the passed objfile first, then try the runtime common symbols.
+   Complain about any remaining unresolved symbols and remove them
+   from the chain.  */
+
+void
+scan_file_globals (objfile)
+     struct objfile *objfile;
+{
+  int hash;
+  struct symbol *sym, *prev;
+
+  if (scan_file_globals_1 (objfile) == 0)
+    return;
+  if (rt_common_objfile && scan_file_globals_1 (rt_common_objfile) == 0)
+    return;
+
+  for (hash = 0; hash < HASHSIZE; hash++)
+    {
+      sym = global_sym_chain[hash];
+      while (sym)
+       {
+         complain (&unresolved_sym_chain_complaint,
+                   objfile->name, SYMBOL_NAME (sym));
+
+         /* Change the symbol address from the misleading chain value
+            to address zero.  */
+         prev = sym;
+         sym = SYMBOL_VALUE_CHAIN (sym);
+         SYMBOL_VALUE_ADDRESS (prev) = 0;
+       }
+    }
+  memset (global_sym_chain, 0, sizeof (global_sym_chain));
 }
 
 /* Initialize anything that needs initializing when starting to read
This page took 0.028853 seconds and 4 git commands to generate.