use remote-utils facilities for baud_rate
[deliverable/binutils-gdb.git] / gdb / dbxread.c
index 4c33fe611c49984c4afad8821dc0f22ea2df6d5e..cc0c43ea9f7bdee82085178f13037a8bd227760b 100644 (file)
@@ -407,8 +407,8 @@ explicit_lookup_type (real_filenum, index)
       f->length *= 2;
       f->vector = (struct type **)
        xrealloc (f->vector, f->length * sizeof (struct type *));
-      bzero (&f->vector[f->length / 2],
-            f->length * sizeof (struct type *) / 2);
+      memset (&f->vector[f->length / 2],
+            '\0', f->length * sizeof (struct type *) / 2);
     }
   return &f->vector[index];
 }
@@ -423,19 +423,77 @@ record_minimal_symbol (name, address, type, objfile)
 {
   enum minimal_symbol_type ms_type;
 
-  switch (type &~ N_EXT) {
-    case N_TEXT:  ms_type = mst_text; break;
-    case N_DATA:  ms_type = mst_data; break;
-    case N_BSS:   ms_type = mst_bss;  break;
-    case N_ABS:   ms_type = mst_abs;  break;
+  switch (type)
+    {
+    case N_TEXT | N_EXT:  ms_type = mst_text; break;
+    case N_DATA | N_EXT:  ms_type = mst_data; break;
+    case N_BSS | N_EXT:   ms_type = mst_bss;  break;
+    case N_ABS | N_EXT:   ms_type = mst_abs;  break;
 #ifdef N_SETV
-    case N_SETV:  ms_type = mst_data; break;
+    case N_SETV | N_EXT:  ms_type = mst_data; break;
+    case N_SETV:
+      /* I don't think this type actually exists; since a N_SETV is the result
+        of going over many .o files, it doesn't make sense to have one
+        file local.  */
+      ms_type = mst_file_data;
+      break;
 #endif
+    case N_TEXT:
+      /* Don't put gcc_compiled, __gnu_compiled_cplus, and friends into
+        the minimal symbols, because if there is also another symbol
+        at the same address (e.g. the first function of the file),
+        lookup_minimal_symbol_by_pc would have no way of getting the
+        right one.  */
+      if (name[0] == 'g'
+         && (strcmp (name, GCC_COMPILED_FLAG_SYMBOL) == 0
+             || strcmp (name, GCC2_COMPILED_FLAG_SYMBOL) == 0))
+       return;
+
+      {
+       char *tempstring = name;
+       if (tempstring[0] == bfd_get_symbol_leading_char (objfile->obfd))
+         ++tempstring;
+       if (STREQN (tempstring, "__gnu_compiled", 14))
+         return;
+      }
+
+    case N_NBTEXT:
+    case N_FN:
+    case N_FN_SEQ:
+      ms_type = mst_file_text;
+      break;
+
+    case N_DATA:
+      ms_type = mst_file_data;
+
+      /* Check for __DYNAMIC, which is used by Sun shared libraries. 
+        Record it as global even if it's local, not global, so
+        lookup_minimal_symbol can find it.  We don't check symbol_leading_char
+        because for SunOS4 it always is '_'.  */
+      if (name[8] == 'C' && STREQ ("__DYNAMIC", name))
+       ms_type = mst_data;
+
+      /* Same with virtual function tables, both global and static.  */
+      {
+       char *tempstring = name;
+       if (tempstring[0] == bfd_get_symbol_leading_char (objfile->obfd))
+         ++tempstring;
+       if (VTBL_PREFIX_P ((tempstring)))
+         ms_type = mst_data;
+      }
+      break;
+
+    case N_BSS:
+      ms_type = mst_file_bss;
+      break;
+
     default:      ms_type = mst_unknown; break;
   }
 
-  prim_record_minimal_symbol (obsavestring (name, strlen (name), &objfile -> symbol_obstack),
-                            address, ms_type);
+  prim_record_minimal_symbol
+    (obsavestring (name, strlen (name), &objfile -> symbol_obstack),
+     address,
+     ms_type);
 }
 \f
 /* Scan and build partial symbols for a symbol file.
@@ -456,6 +514,7 @@ dbx_symfile_read (objfile, section_offsets, mainline)
 {
   bfd *sym_bfd;
   int val;
+  struct cleanup *back_to;
 
   sym_bfd = objfile->obfd;
   val = bfd_seek (objfile->obfd, DBX_SYMTAB_OFFSET (objfile), SEEK_SET);
@@ -470,7 +529,7 @@ dbx_symfile_read (objfile, section_offsets, mainline)
   symbol_table_offset = DBX_SYMTAB_OFFSET (objfile);
 
   pending_blocks = 0;
-  make_cleanup (really_free_pendings, 0);
+  back_to = make_cleanup (really_free_pendings, 0);
 
   init_minimal_symbol_collection ();
   make_cleanup (discard_minimal_symbols, 0);
@@ -492,6 +551,8 @@ dbx_symfile_read (objfile, section_offsets, mainline)
     printf_filtered ("(no debugging symbols found)...");
     wrap_here ("");
   }
+
+  do_cleanups (back_to);
 }
 
 /* Initialize anything that needs initializing when a completely new
@@ -815,7 +876,7 @@ read_dbx_symtab (section_offsets, objfile, text_addr, text_size)
   int nsl;
   int past_first_source_file = 0;
   CORE_ADDR last_o_file_start = 0;
-  struct cleanup *old_chain;
+  struct cleanup *back_to;
   bfd *abfd;
 
   /* End of the text segment of the executable file.  */
@@ -853,11 +914,9 @@ read_dbx_symtab (section_offsets, objfile, text_addr, text_size)
     (struct partial_symtab **) alloca (dependencies_allocated *
                                       sizeof (struct partial_symtab *));
 
-  old_chain = make_cleanup (free_objfile, objfile);
-
   /* Init bincl list */
   init_bincl_list (20, objfile);
-  make_cleanup (free_bincl_list, objfile);
+  back_to = make_cleanup (free_bincl_list, objfile);
 
   last_source_file = NULL;
 
@@ -943,8 +1002,7 @@ read_dbx_symtab (section_offsets, objfile, text_addr, text_size)
                   dependency_list, dependencies_used);
     }
 
-  free_bincl_list (objfile);
-  discard_cleanups (old_chain);
+  do_cleanups (back_to);
 }
 
 /* Allocate and partially fill a partial symtab.  It will be
@@ -991,19 +1049,12 @@ start_psymtab (objfile, section_offsets,
   return result;
 }
 
-/* Close off the current usage of a partial_symbol table entry.  This
-   involves setting the correct number of includes (with a realloc),
-   setting the high text mark, setting the symbol length in the
-   executable, and setting the length of the global and static lists
-   of psymbols.
+/* Close off the current usage of PST.  
+   Returns PST or NULL if the partial symtab was empty and thrown away.
 
-   The global symbols and static symbols are then seperately sorted.
+   FIXME:  List variables and peculiarities of same.  */
 
-   Then the partial symtab is put on the global list.
-   *** List variables and peculiarities of same. ***
-   */
-
-void
+struct partial_symtab *
 end_psymtab (pst, include_list, num_includes, capping_symbol_offset,
             capping_text, dependency_list, number_dependencies)
      struct partial_symtab *pst;
@@ -1187,7 +1238,11 @@ end_psymtab (pst, include_list, num_includes, capping_symbol_offset,
 
     pst->next = pst->objfile->free_psymtabs;
     pst->objfile->free_psymtabs = pst;
+
+    /* Indicate that psymtab was thrown away.  */
+    pst = (struct partial_symtab *)NULL;
   }
+  return pst;
 }
 \f
 static void
@@ -1301,7 +1356,6 @@ read_ofile_symtab (pst)
   unsigned char type;
   unsigned max_symnum;
   register bfd *abfd;
-  struct symtab *rtn;
   struct objfile *objfile;
   int sym_offset;              /* Offset to start of symbols to read */
   int sym_size;                        /* Size of symbols to read */
@@ -1486,16 +1540,19 @@ process_one_symbol (type, desc, valu, name, section_offsets, objfile)
      other than Solaris 2, this just holds the SECT_OFF_TEXT value, and is
      used to relocate these symbol types rather than SECTION_OFFSETS.  */
   static CORE_ADDR function_start_offset;
-  char *colon_pos;
 
   /* If this is nonzero, N_LBRAC, N_RBRAC, and N_SLINE entries are relative
      to the function start address.  */
   int block_address_function_relative;
 
   /* If this is nonzero, we've seen a non-gcc N_OPT symbol for this source
-     file.  */
+     file.  Used to detect the SunPRO solaris compiler.  */
   int n_opt_found;
 
+  /* The stab type used for the definition of the last function.
+     N_STSYM or N_GSYM for SunOS4 acc; N_FUN for other compilers.  */
+  static int function_stab_type = 0;
+
   /* This is true for Solaris (and all other stabs-in-elf systems, hopefully,
      since it would be silly to do things differently from Solaris), and
      false for SunOS4 and other a.out file formats.  */
@@ -1523,60 +1580,9 @@ process_one_symbol (type, desc, valu, name, section_offsets, objfile)
     {
     case N_FUN:
     case N_FNAME:
-#if 0
-/* It seems that the Sun ANSI C compiler (acc) replaces N_FUN with N_GSYM and
-   N_STSYM with a type code of f or F.  Can't enable this until we get some
-   stuff straightened out with psymtabs.  FIXME. */
-
-    case N_GSYM:
-    case N_STSYM:
-#endif /* 0 */
-
       /* Relocate for dynamic loading */
       valu += ANOFFSET (section_offsets, SECT_OFF_TEXT);
-
-      /* Either of these types of symbols indicates the start of
-        a new function.  We must process its "name" normally for dbx,
-        but also record the start of a new lexical context, and possibly
-        also the end of the lexical context for the previous function.  */
-      /* This is not always true.  This type of symbol may indicate a
-         text segment variable.  */
-
-      colon_pos = strchr (name, ':');
-      if (!colon_pos++
-         || (*colon_pos != 'f' && *colon_pos != 'F'))
-       {
-         define_symbol (valu, name, desc, type, objfile);
-         break;
-       }
-
-#ifdef SUN_FIXED_LBRAC_BUG
-      last_pc_address = valu;  /* Save for SunOS bug circumcision */
-#endif
-
-      if (block_address_function_relative)
-       /* On Solaris 2.0 compilers, the block addresses and N_SLINE's
-          are relative to the start of the function.  On normal systems,
-          and when using gcc on Solaris 2.0, these addresses are just
-          absolute, or relative to the N_SO, depending on
-          BLOCK_ADDRESS_ABSOLUTE.  */
-       function_start_offset = valu;   
-
-      within_function = 1;
-      if (context_stack_depth > 0)
-       {
-         new = pop_context ();
-         /* Make a block for the local symbols within.  */
-         finish_block (new->name, &local_symbols, new->old_blocks,
-                       new->start_addr, valu, objfile);
-       }
-      /* Stack must be empty now.  */
-      if (context_stack_depth != 0)
-       complain (&lbrac_unmatched_complaint, symnum);
-
-      new = push_context (0, valu);
-      new->name = define_symbol (valu, name, desc, type, objfile);
-      break;
+      goto define_a_symbol;
 
     case N_LBRAC:
       /* This "symbol" just indicates the start of an inner lexical
@@ -1803,7 +1809,10 @@ process_one_symbol (type, desc, valu, name, section_offsets, objfile)
        .stab "foo:V...",N_STSYM        is relative (section base subtracted).
        This leaves us no choice but to search for the 'S' or 'V'...
        (or pass the whole section_offsets stuff down ONE MORE function
-       call level, which we really don't want to do).  */
+       call level, which we really don't want to do).
+
+       The above is indeed true for Solaris 2.1.  I'm not sure what
+       happens in Solaris 2.3, in which ld stops relocating stabs.  */
       {
        char *p;
        p = strchr (name, ':');
@@ -1811,7 +1820,9 @@ process_one_symbol (type, desc, valu, name, section_offsets, objfile)
          {
            /* FIXME!  We relocate it by the TEXT offset, in case the
               whole module moved in memory.  But this is wrong, since
-              the sections can side around independently.  */
+              the sections can side around independently.  (I suspect that
+              the text offset is always zero anyway--elfread.c doesn't
+              process (and Sun cc doesn't produce) Ttext.text symbols).  */
            valu += ANOFFSET (section_offsets, SECT_OFF_TEXT);
            goto define_a_symbol;
          }
@@ -1844,6 +1855,24 @@ process_one_symbol (type, desc, valu, name, section_offsets, objfile)
       valu += ANOFFSET (section_offsets, SECT_OFF_TEXT);
       goto define_a_symbol;
 
+    /* The following symbol types we don't know how to process.  Handle
+       them in a "default" way, but complain to people who care.  */
+    default:
+    case N_CATCH:              /* Exception handler catcher */
+    case N_EHDECL:             /* Exception handler name */
+    case N_PC:                 /* Global symbol in Pascal */
+    case N_M2C:                        /* Modula-2 compilation unit */
+    /*   N_MOD2:       overlaps with N_EHDECL */
+    case N_SCOPE:              /* Modula-2 scope information */
+    case N_ECOML:              /* End common (local name) */
+    case N_NBTEXT:             /* Gould Non-Base-Register symbols??? */
+    case N_NBDATA:
+    case N_NBBSS:
+    case N_NBSTS:
+    case N_NBLCS:
+      complain (&unknown_symtype_complaint, local_hex_string(type));
+      /* FALLTHROUGH */
+
     /* The following symbol types don't need the address field relocated,
        since it is either unused, or is absolute.  */
     define_a_symbol:
@@ -1857,7 +1886,94 @@ process_one_symbol (type, desc, valu, name, section_offsets, objfile)
     case N_PSYM:               /* Parameter variable */
     case N_LENG:               /* Length of preceding symbol type */
       if (name)
-       define_symbol (valu, name, desc, type, objfile);
+       {
+         int deftype;
+         char *colon_pos = strchr (name, ':');
+         if (colon_pos == NULL)
+           deftype = '\0';
+         else
+           deftype = colon_pos[1];
+
+         switch (deftype)
+           {
+           case 'f':
+           case 'F':
+             function_stab_type = type;
+
+#ifdef SUN_FIXED_LBRAC_BUG
+             /* The Sun acc compiler, under SunOS4, puts out
+                functions with N_GSYM or N_STSYM.  The problem is
+                that the address of the symbol is no good (for N_GSYM
+                it doesn't even attept an address; for N_STSYM it
+                puts out an address but then it gets relocated
+                relative to the data segment, not the text segment).
+                Currently we can't fix this up later as we do for
+                some types of symbol in scan_file_globals.
+                Fortunately we do have a way of finding the address -
+                we know that the value in last_pc_address is either
+                the one we want (if we're dealing with the first
+                function in an object file), or somewhere in the
+                previous function. This means that we can use the
+                minimal symbol table to get the address.  */
+
+             /* On solaris up to 2.2, the N_FUN stab gets relocated.
+                On Solaris 2.3, ld no longer relocates stabs (which
+                is good), and the N_FUN's value is now always zero.
+                We only provide this correction for functions, not for
+                all N_FUN symbols, because that is easiest and all
+                readonly variables seem to go in the .rodata on Solaris.  */
+
+             if (type == N_GSYM || type == N_STSYM
+                 || (type == N_FUN && valu == 0))
+               {
+                 struct minimal_symbol *m;
+                 int l = colon_pos - name;
+
+                 m = lookup_minimal_symbol_by_pc (last_pc_address);
+                 if (m && STREQN (SYMBOL_NAME (m), name, l))
+                   /* last_pc_address was in this function */
+                   valu = SYMBOL_VALUE (m);
+                 else if (m && STREQN (SYMBOL_NAME (m+1), name, l))
+                   /* last_pc_address was in last function */
+                   valu = SYMBOL_VALUE (m+1);
+                 else
+                   /* Not found - use last_pc_address (for finish_block) */
+                   valu = last_pc_address;
+               }
+
+             last_pc_address = valu;   /* Save for SunOS bug circumcision */
+#endif
+
+             if (block_address_function_relative)
+               /* For Solaris 2.0 compilers, the block addresses and
+                  N_SLINE's are relative to the start of the
+                  function.  On normal systems, and when using gcc on
+                  Solaris 2.0, these addresses are just absolute, or
+                  relative to the N_SO, depending on
+                  BLOCK_ADDRESS_ABSOLUTE.  */
+               function_start_offset = valu;   
+
+             within_function = 1;
+             if (context_stack_depth > 0)
+               {
+                 new = pop_context ();
+                 /* Make a block for the local symbols within.  */
+                 finish_block (new->name, &local_symbols, new->old_blocks,
+                               new->start_addr, valu, objfile);
+               }
+             /* Stack must be empty now.  */
+             if (context_stack_depth != 0)
+               complain (&lbrac_unmatched_complaint, symnum);
+
+             new = push_context (0, valu);
+             new->name = define_symbol (valu, name, desc, type, objfile);
+             break;
+
+           default:
+             define_symbol (valu, name, desc, type, objfile);
+             break;
+           }
+       }
       break;
 
     /* We use N_OPT to carry the gcc2_compiled flag.  Sun uses it
@@ -1889,25 +2005,6 @@ process_one_symbol (type, desc, valu, name, section_offsets, objfile)
     case N_ENDM:               /* Solaris 2:  End of module */
     case N_MAIN:               /* Name of main routine.  */
       break;
-      
-    /* The following symbol types we don't know how to process.  Handle
-       them in a "default" way, but complain to people who care.  */
-    default:
-    case N_CATCH:              /* Exception handler catcher */
-    case N_EHDECL:             /* Exception handler name */
-    case N_PC:                 /* Global symbol in Pascal */
-    case N_M2C:                        /* Modula-2 compilation unit */
-    /*   N_MOD2:       overlaps with N_EHDECL */
-    case N_SCOPE:              /* Modula-2 scope information */
-    case N_ECOML:              /* End common (local name) */
-    case N_NBTEXT:             /* Gould Non-Base-Register symbols??? */
-    case N_NBDATA:
-    case N_NBBSS:
-    case N_NBSTS:
-    case N_NBLCS:
-      complain (&unknown_symtype_complaint, local_hex_string(type));
-      if (name)
-       define_symbol (valu, name, desc, type, objfile);
     }
 
   previous_stab_code = type;
@@ -1992,8 +2089,7 @@ elfstab_build_psymtabs (objfile, section_offsets, mainline,
   DBX_STRINGTAB_SIZE (objfile) = stabstrsize;
   DBX_SYMTAB_OFFSET  (objfile) = staboffset;
   
-  if (stabstrsize < 0  /* FIXME:  stabstrsize is unsigned; never true! */
-      || stabstrsize > bfd_get_size (sym_bfd))
+  if (stabstrsize > bfd_get_size (sym_bfd))
     error ("ridiculous string table size: %d bytes", stabstrsize);
   DBX_STRINGTAB (objfile) = (char *)
     obstack_alloc (&objfile->psymbol_obstack, stabstrsize+1);
@@ -2071,7 +2167,7 @@ dbx_symfile_offsets (objfile, addr)
 }
 \f
 /* Register our willingness to decode symbols for SunOS and a.out and
-   b.out files handled by BFD... */
+   NetBSD and b.out files handled by BFD... */
 static struct sym_fns sunos_sym_fns =
 {
   "sunOs",             /* sym_name: name or name prefix of BFD target type */
This page took 0.028219 seconds and 4 git commands to generate.