* breakpoint.c, breakpoint.h (breakpoint_init_inferior): New function
[deliverable/binutils-gdb.git] / gdb / dbxread.c
index cc66a152e7bda3abdeea276a0a1d6c969ba4f4a9..9d1a423607f7f94899a702237a253363fd8ef19f 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];
 }
@@ -438,10 +438,28 @@ record_minimal_symbol (name, address, type, objfile)
       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:
-    case N_TEXT:
       ms_type = mst_file_text;
       break;
 
@@ -450,9 +468,8 @@ record_minimal_symbol (name, address, type, objfile)
 
       /* 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.
-        FIXME:  this might want to check for _DYNAMIC and the current
-        symbol_leading_char.  */
+        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;
 
@@ -497,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);
@@ -511,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);
@@ -533,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
@@ -574,7 +594,7 @@ dbx_symfile_init (objfile)
   unsigned char size_temp[DBX_STRINGTAB_SIZE_SIZE];
 
   /* Allocate struct to keep track of the symfile */
-  objfile->sym_private = (PTR)
+  objfile->sym_stab_info = (PTR)
     xmmalloc (objfile -> md, sizeof (struct dbx_symfile_info));
 
   /* FIXME POKING INSIDE BFD DATA STRUCTURES */
@@ -676,9 +696,9 @@ static void
 dbx_symfile_finish (objfile)
      struct objfile *objfile;
 {
-  if (objfile->sym_private != NULL)
+  if (objfile->sym_stab_info != NULL)
     {
-      mfree (objfile -> md, objfile->sym_private);
+      mfree (objfile -> md, objfile->sym_stab_info);
     }
   free_header_files ();
 }
@@ -856,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.  */
@@ -894,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;
 
@@ -984,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
@@ -1032,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.
-
-   The global symbols and static symbols are then seperately sorted.
+/* Close off the current usage of PST.  
+   Returns PST or NULL if the partial symtab was empty and thrown away.
 
-   Then the partial symtab is put on the global list.
-   *** List variables and peculiarities of same. ***
-   */
+   FIXME:  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;
@@ -1104,7 +1114,7 @@ end_psymtab (pst, include_list, num_includes, capping_symbol_offset,
 
     if (minsym) {
       pst->texthigh = SYMBOL_VALUE_ADDRESS (minsym) +
-       (int) MSYMBOL_INFO (minsym);
+       (long) MSYMBOL_INFO (minsym);
     } else {
       /* This file ends with a static function, and it's
         difficult to imagine how hard it would be to track down
@@ -1228,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
@@ -1342,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 */
@@ -1752,6 +1765,10 @@ process_one_symbol (type, desc, valu, name, section_offsets, objfile)
     case N_BCOMM:
       if (common_block)
        {
+         /* Note: this does not detect nesting if the previous N_BCOMM
+            was at the beginning of a scope (and thus common_block was
+            NULL).  Not necessarily worth worrying about unless we run
+            into a compiler which actually has this bug.  */
          static struct complaint msg = {
            "Invalid symbol data: common within common at symtab pos %d",
            0, 0};
@@ -1762,11 +1779,21 @@ process_one_symbol (type, desc, valu, name, section_offsets, objfile)
       break;
 
     case N_ECOMM:
+
       /* Symbols declared since the BCOMM are to have the common block
-        start address added in when we know it.  common_block points to
-        the first symbol after the BCOMM in the local_symbols list;
-        copy the list and hang it off the symbol for the common block name
-        for later fixup.  */
+        start address added in when we know it.  common_block and
+        common_block_i point to the first symbol after the BCOMM in
+        the local_symbols list; copy the list and hang it off the
+        symbol for the common block name for later fixup.  */
+
+      /* If there is a N_ECOMM unmatched by a N_BCOMM, we treat all
+        the local_symbols as part of the common block.  It might be
+        better to just ignore the N_ECOMM, but then we'd need to
+        distinguish between a N_BCOMM at the start of a scope, or no
+        N_BCOMM at all (currently they both have common_block NULL).
+        Not necessarily worth worrying about unless we run into a
+        compiler which actually has this bug.  */
+
       {
        int i;
        struct symbol *sym =
@@ -1796,7 +1823,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, ':');
@@ -1804,7 +1834,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;
          }
@@ -1852,7 +1884,8 @@ process_one_symbol (type, desc, valu, name, section_offsets, objfile)
     case N_NBBSS:
     case N_NBSTS:
     case N_NBLCS:
-      complain (&unknown_symtype_complaint, local_hex_string(type));
+      complain (&unknown_symtype_complaint,
+               local_hex_string((unsigned long) type));
       /* FALLTHROUGH */
 
     /* The following symbol types don't need the address field relocated,
@@ -1898,6 +1931,15 @@ process_one_symbol (type, desc, valu, name, section_offsets, objfile)
                 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.
+                The following code can't deal with this, because
+                last_pc_address depends on getting the address from a
+                N_SLINE or some such and in Solaris those are function
+                relative.  Best fix is probably to create a Ttext.text symbol
+                and handle this like Ddata.data and so on.  */
+
              if (type == N_GSYM || type == N_STSYM)
                {
                  struct minimal_symbol *m;
@@ -2005,13 +2047,96 @@ copy_pending (beg, endi, end)
        add_symbol_to_list (next->symbol[j], &new);
     }
 
-  /* Copy however much of END we need.  */
-  for (j = endi; j < end->nsyms; j++)
-    add_symbol_to_list (end->symbol[j], &new);
+  /* Copy however much of END we need.  If END is NULL, it means copy
+     all the local symbols (which we already did above).  */
+  if (end != NULL)
+    for (j = endi; j < end->nsyms; j++)
+      add_symbol_to_list (end->symbol[j], &new);
 
   return new;
 }
 \f
+/* FIXME: The only difference between this and elfstab_build_psymtabs is
+   the call to install_minimal_symbols for elf.  If the differences are
+   really that small, the code should be shared.  */
+
+/* Scan and build partial symbols for an coff symbol file.
+   The coff file has already been processed to get its minimal symbols.
+
+   This routine is the equivalent of dbx_symfile_init and dbx_symfile_read
+   rolled into one.
+
+   OBJFILE is the object file we are reading symbols from.
+   ADDR is the address relative to which the symbols are (e.g.
+   the base address of the text segment).
+   MAINLINE is true if we are reading the main symbol
+   table (as opposed to a shared lib or dynamically loaded file).
+   STABOFFSET and STABSIZE define the location in OBJFILE where the .stab
+   section exists.
+   STABSTROFFSET and STABSTRSIZE define the location in OBJFILE where the
+   .stabstr section exists.
+
+   This routine is mostly copied from dbx_symfile_init and dbx_symfile_read,
+   adjusted for coff details. */
+
+void
+coffstab_build_psymtabs (objfile, section_offsets, mainline, 
+                              staboffset, stabsize,
+                              stabstroffset, stabstrsize)
+      struct objfile *objfile;
+      struct section_offsets *section_offsets;
+      int mainline;
+      file_ptr staboffset;
+      unsigned int stabsize;
+      file_ptr stabstroffset;
+      unsigned int stabstrsize;
+{
+  int val;
+  bfd *sym_bfd = objfile->obfd;
+  char *name = bfd_get_filename (sym_bfd);
+  struct dbx_symfile_info *info;
+
+  /* There is already a dbx_symfile_info allocated by our caller.
+     It might even contain some info from the coff symtab to help us.  */
+  info = (struct dbx_symfile_info *) objfile->sym_stab_info;
+
+  DBX_TEXT_SECT (objfile) = bfd_get_section_by_name (sym_bfd, ".text");
+  if (!DBX_TEXT_SECT (objfile))
+    error ("Can't find .text section in symbol file");
+
+#define        COFF_STABS_SYMBOL_SIZE  12      /* XXX FIXME XXX */
+  DBX_SYMBOL_SIZE    (objfile) = COFF_STABS_SYMBOL_SIZE;
+  DBX_SYMCOUNT       (objfile) = stabsize / DBX_SYMBOL_SIZE (objfile);
+  DBX_STRINGTAB_SIZE (objfile) = stabstrsize;
+  DBX_SYMTAB_OFFSET  (objfile) = staboffset;
+  
+  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);
+
+  /* Now read in the string table in one big gulp.  */
+
+  val = bfd_seek (sym_bfd, stabstroffset, SEEK_SET);
+  if (val < 0)
+    perror_with_name (name);
+  val = bfd_read (DBX_STRINGTAB (objfile), stabstrsize, 1, sym_bfd);
+  if (val != stabstrsize)
+    perror_with_name (name);
+
+  stabsread_new_init ();
+  buildsym_new_init ();
+  free_header_files ();
+  init_header_files ();
+
+  processing_acc_compilation = 1;
+
+  /* In a coff file, we've already installed the minimal symbols that came
+     from the coff (non-stab) symbol table, so always act like an
+     incremental load here. */
+  dbx_symfile_read (objfile, section_offsets, 0);
+}
+\f
 /* Scan and build partial symbols for an ELF symbol file.
    This ELF file has already been processed to get its minimal symbols,
    and any DWARF symbols that were in it.
@@ -2051,7 +2176,7 @@ elfstab_build_psymtabs (objfile, section_offsets, mainline,
 
   /* There is already a dbx_symfile_info allocated by our caller.
      It might even contain some info from the ELF symtab to help us.  */
-  info = (struct dbx_symfile_info *) objfile->sym_private;
+  info = (struct dbx_symfile_info *) objfile->sym_stab_info;
 
   DBX_TEXT_SECT (objfile) = bfd_get_section_by_name (sym_bfd, ".text");
   if (!DBX_TEXT_SECT (objfile))
@@ -2063,8 +2188,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);
@@ -2142,7 +2266,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.027629 seconds and 4 git commands to generate.