Add support for FreeBSD/i386 ELF.
[deliverable/binutils-gdb.git] / gdb / stabsread.c
index ec59cf36bd08f22464cf40f6e0d90bb2210c195b..206310e4d421e2fe94d3d644dbd450979dbcc95c 100644 (file)
@@ -194,6 +194,8 @@ static CORE_ADDR
 static int
 resolve_symbol_reference PARAMS ((struct objfile *, struct symbol *, char *));
 
+void stabsread_clear_cache PARAMS ((void));
+
 static const char vptr_name[] =
 {'_', 'v', 'p', 't', 'r', CPLUS_MARKER, '\0'};
 static const char vb_name[] =
@@ -292,7 +294,7 @@ static void
 os9k_init_type_vector (tv)
      struct type **tv;
 {
-  int i;
+  unsigned int i;
   for (i = 0; i < sizeof (os9k_type_vector) / sizeof (struct type **); i++)
     tv[i] = (os9k_type_vector[i] == 0 ? 0 : *(os9k_type_vector[i]));
 }
@@ -557,10 +559,6 @@ read_type_number (pp, typenums)
 }
 \f
 
-#if !defined (REG_STRUCT_HAS_ADDR)
-#define REG_STRUCT_HAS_ADDR(gcc_p,type) 0
-#endif
-
 #define VISIBILITY_PRIVATE     '0'     /* Stabs character for private field */
 #define VISIBILITY_PROTECTED   '1'     /* Stabs character for protected fld */
 #define VISIBILITY_PUBLIC      '2'     /* Stabs character for public field */
@@ -1192,6 +1190,16 @@ static int ref_count = 0;
 /* Number of chunks malloced. */
 static int ref_chunk = 0;
 
+/* This file maintains a cache of stabs aliases found in the symbol
+   table. If the symbol table changes, this cache must be cleared
+   or we are left holding onto data in invalid obstacks. */
+void
+stabsread_clear_cache ()
+{
+  ref_count = 0;
+  ref_chunk = 0;
+}
+
 /* Create array of pointers mapping refids to symbols and stab strings.
    Add pointers to reference definition symbols and/or their values as we 
    find them, using their reference numbers as our index. 
@@ -1343,13 +1351,13 @@ define_symbol (valu, string, desc, type, objfile)
   switch (type & N_TYPE)
     {
     case N_TEXT:
-      SYMBOL_SECTION (sym) = SECT_OFF_TEXT;
+      SYMBOL_SECTION (sym) = SECT_OFF_TEXT (objfile);
       break;
     case N_DATA:
-      SYMBOL_SECTION (sym) = SECT_OFF_DATA;
+      SYMBOL_SECTION (sym) = SECT_OFF_DATA (objfile);
       break;
     case N_BSS:
-      SYMBOL_SECTION (sym) = SECT_OFF_BSS;
+      SYMBOL_SECTION (sym) = SECT_OFF_BSS (objfile);
       break;
     }
 
@@ -1887,6 +1895,7 @@ define_symbol (valu, string, desc, type, objfile)
          if (local_symbols
              && local_symbols->nsyms > 0
 #ifndef USE_REGISTER_NOT_ARG
+             && REG_STRUCT_HAS_ADDR_P ()
              && REG_STRUCT_HAS_ADDR (processing_gcc_compilation,
                                      SYMBOL_TYPE (sym))
              && (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_STRUCT
@@ -2144,8 +2153,9 @@ define_symbol (valu, string, desc, type, objfile)
   /* When passing structures to a function, some systems sometimes pass
      the address in a register, not the structure itself. */
 
-  if (REG_STRUCT_HAS_ADDR (processing_gcc_compilation, SYMBOL_TYPE (sym))
-    && (SYMBOL_CLASS (sym) == LOC_REGPARM || SYMBOL_CLASS (sym) == LOC_ARG))
+  if (REG_STRUCT_HAS_ADDR_P ()
+      && REG_STRUCT_HAS_ADDR (processing_gcc_compilation, SYMBOL_TYPE (sym))
+      && (SYMBOL_CLASS (sym) == LOC_REGPARM || SYMBOL_CLASS (sym) == LOC_ARG))
     {
       struct type *symbol_type = check_typedef (SYMBOL_TYPE (sym));
 
@@ -3712,7 +3722,8 @@ read_baseclasses (fip, pp, type, objfile)
          {
            static struct complaint msg =
            {
-             "Unknown visibility `%c' for baseclass", 0, 0};
+             "Unknown visibility `%c' for baseclass", 0, 0
+           };
            complain (&msg, new->visibility);
            new->visibility = VISIBILITY_PUBLIC;
          }
@@ -4701,18 +4712,30 @@ read_range_type (pp, typenums, objfile)
   /* We used to do this only for subrange of self or subrange of int.  */
   else if (n2 == 0)
     {
+      /* -1 is used for the upper bound of (4 byte) "unsigned int" and
+         "unsigned long", and we already checked for that,
+         so don't need to test for it here.  */
+
       if (n3 < 0)
        /* n3 actually gives the size.  */
        return init_type (TYPE_CODE_INT, -n3, TYPE_FLAG_UNSIGNED,
                          NULL, objfile);
-      if (n3 == 0xff)
-       return init_type (TYPE_CODE_INT, 1, TYPE_FLAG_UNSIGNED, NULL, objfile);
-      if (n3 == 0xffff)
-       return init_type (TYPE_CODE_INT, 2, TYPE_FLAG_UNSIGNED, NULL, objfile);
 
-      /* -1 is used for the upper bound of (4 byte) "unsigned int" and
-         "unsigned long", and we already checked for that,
-         so don't need to test for it here.  */
+      /* Is n3 == 2**(8n)-1 for some integer n?  Then it's an
+         unsigned n-byte integer.  But do require n to be a power of
+         two; we don't want 3- and 5-byte integers flying around.  */
+      {
+       int bytes;
+       unsigned long bits;
+
+       bits = n3;
+       for (bytes = 0; (bits & 0xff) == 0xff; bytes++)
+         bits >>= 8;
+       if (bits == 0
+           && ((bytes - 1) & bytes) == 0) /* "bytes is a power of two" */
+         return init_type (TYPE_CODE_INT, bytes, TYPE_FLAG_UNSIGNED, NULL,
+                           objfile);
+      }
     }
   /* I think this is for Convex "long long".  Since I don't know whether
      Convex sets self_subrange, I also accept that particular size regardless
This page took 0.024886 seconds and 4 git commands to generate.