* gdbserver/{remote-gutils.c remote-server.c Makefile.in
[deliverable/binutils-gdb.git] / gdb / symfile.c
index 1c8fe1d8ca489cbb7a893a727662c461079a6dfb..ec582da8ca5e95d80aa335bbc43e776fe5353eb3 100644 (file)
@@ -1,5 +1,5 @@
 /* Generic symbol file reading for the GNU debugger, GDB.
-   Copyright 1990, 1991, 1992 Free Software Foundation, Inc.
+   Copyright 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
    Contributed by Cygnus Support, using pieces from other GDB modules.
 
 This file is part of GDB.
@@ -42,6 +42,10 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
 #include <sys/stat.h>
 #include <ctype.h>
 
+#ifndef O_BINARY
+#define O_BINARY 0
+#endif
+
 /* Global variables owned by this file */
 
 int readnow_symbol_files;              /* Read full symbols immediately */
@@ -375,21 +379,6 @@ syms_from_objfile (objfile, addr, mainline, verbo)
   struct section_offsets *section_offsets;
   asection *lowest_sect;
 
-  /* There is a distinction between having no symbol table
-     (we refuse to read the file, leaving the old set of symbols around)
-     and having no debugging symbols in your symbol table (we read
-     the file and end up with a mostly empty symbol table).
-
-     FIXME:  This strategy works correctly when the debugging symbols are
-     intermixed with "normal" symbols.  However, when the debugging symbols
-     are separate, such as with ELF/DWARF, it is perfectly plausible for
-     the symbol table to be missing but still have all the DWARF info
-     intact.  Thus in general it is wrong to assume that having no symbol
-     table implies no debugging information. */
-
-  if (!(bfd_get_file_flags (objfile -> obfd) & HAS_SYMS))
-    return;
-
   init_entry_point_info (objfile);
   find_sym_fns (objfile);
 
@@ -440,29 +429,53 @@ syms_from_objfile (objfile, addr, mainline, verbo)
        addr -= bfd_section_vma (objfile->obfd, lowest_sect);
     }
 
-  /* Debugging check inserted for testing elimination of NAMES_HAVE_UNDERSCORE.
-     Complain if the dynamic setting of NAMES_HAVE_UNDERSCORE from BFD
-     doesn't match the static setting from the GDB config files.
-     FIXME:  Remove this check after a round of testing.  
-                                               -- gnu@cygnus.com, 16dec92 */
-#ifdef NAMES_HAVE_UNDERSCORE
-  if (bfd_get_symbol_leading_char(objfile->obfd) != '_')
-#else
-  if (bfd_get_symbol_leading_char(objfile->obfd) != 0)
-#endif
-    fprintf (stderr,
- "GDB internal error!  NAMES_HAVE_UNDERSCORE set wrong for %s BFD:\n%s\n",
-             objfile->obfd->xvec->name,
-             objfile->obfd->filename);
-  /* End of debugging check.  FIXME.  */
-
   /* Initialize symbol reading routines for this objfile, allow complaints to
      appear for this new file, and record how verbose to be, then do the
      initial symbol reading for this file. */
 
   (*objfile -> sf -> sym_init) (objfile);
   clear_complaints (1, verbo);
+
+  /* If objfile->sf->sym_offsets doesn't set this, we don't care
+     (currently).  */
+  objfile->num_sections = 0;  /* krp-FIXME: why zero? */
   section_offsets = (*objfile -> sf -> sym_offsets) (objfile, addr);
+  objfile->section_offsets = section_offsets;
+
+#ifndef IBM6000_TARGET
+  /* This is a SVR4/SunOS specific hack, I think.  In any event, it
+     screws RS/6000.  sym_offsets should be doing this sort of thing,
+     because it knows the mapping between bfd sections and
+     section_offsets.  */
+  /* This is a hack.  As far as I can tell, section offsets are not
+     target dependent.  They are all set to addr with a couple of
+     exceptions.  The exceptions are sysvr4 shared libraries, whose
+     offsets are kept in solib structures anyway and rs6000 xcoff
+     which handles shared libraries in a completely unique way.
+
+     Section offsets are built similarly, except that they are built
+     by adding addr in all cases because there is no clear mapping
+     from section_offsets into actual sections.  Note that solib.c
+     has a different algorythm for finding section offsets.
+
+     These should probably all be collapsed into some target
+     independent form of shared library support.  FIXME.  */
+
+  if (addr)
+    {
+      struct obj_section *s;
+
+      for (s = objfile->sections; s < objfile->sections_end; ++s)
+       {
+         s->addr -= s->offset;
+         s->addr += addr;
+         s->endaddr -= s->offset;
+         s->endaddr += addr;
+         s->offset += addr;
+       }
+    }
+#endif /* not IBM6000_TARGET */
+
   (*objfile -> sf -> sym_read) (objfile, section_offsets, mainline);
 
   /* Don't allow char * to have a typename (else would get caddr_t.)  */
@@ -531,26 +544,10 @@ symbol_file_add (name, from_tty, addr, mainline, mapped, readnow)
   struct partial_symtab *psymtab;
   bfd *abfd;
 
-  /* Open a bfd for the file and then check to see if the file has a
-     symbol table.  There is a distinction between having no symbol table
-     (we refuse to read the file, leaving the old set of symbols around)
-     and having no debugging symbols in the symbol table (we read the file
-     and end up with a mostly empty symbol table, but with lots of stuff in
-     the minimal symbol table).  We need to make the decision about whether
-     to continue with the file before allocating and building a objfile.
-
-     FIXME:  This strategy works correctly when the debugging symbols are
-     intermixed with "normal" symbols.  However, when the debugging symbols
-     are separate, such as with ELF/DWARF, it is perfectly plausible for
-     the symbol table to be missing but still have all the DWARF info
-     intact.  Thus in general it is wrong to assume that having no symbol
-     table implies no debugging information. */
+  /* Open a bfd for the file, and give user a chance to burp if we'd be
+     interactively wiping out any existing symbols.  */
 
   abfd = symfile_bfd_open (name);
-  if (!(bfd_get_file_flags (abfd) & HAS_SYMS))
-    {
-      error ("%s has no symbol-table", name);
-    }
 
   if ((have_full_symbols () || have_partial_symbols ())
       && mainline
@@ -752,7 +749,7 @@ symfile_bfd_open (name)
   name = tilde_expand (name);  /* Returns 1st new malloc'd copy */
 
   /* Look down path for it, allocate 2nd new malloc'd copy.  */
-  desc = openp (getenv ("PATH"), 1, name, O_RDONLY, 0, &absolute_name);
+  desc = openp (getenv ("PATH"), 1, name, O_RDONLY | O_BINARY, 0, &absolute_name);
   if (desc < 0)
     {
       make_cleanup (free, name);
@@ -967,19 +964,20 @@ enum language
 deduce_language_from_filename (filename)
      char *filename;
 {
-  char *c = strrchr (filename, '.');
+  char *c;
   
-  if (!c) ; /* Get default. */
+  if (0 == filename) 
+    ; /* Get default */
+  else if (0 == (c = strrchr (filename, '.')))
+    ; /* Get default. */
   else if(STREQ(c,".mod"))
-     return language_m2;
+    return language_m2;
   else if(STREQ(c,".c"))
-     return language_c;
+    return language_c;
   else if(STREQ(c,".cc") || STREQ(c,".C"))
-     return language_cplus;
-  /* start-sanitize-chill */
+    return language_cplus;
   else if(STREQ(c,".ch") || STREQ(c,".c186") || STREQ(c,".c286"))
-     return language_chill;
-  /* end-sanitize-chill */
+    return language_chill;
 
   return language_unknown;             /* default */
 }
@@ -1326,22 +1324,7 @@ add_psymbol_to_list (name, namelength, namespace, class, list, val, language,
   SYMBOL_LANGUAGE (psym) = language;
   PSYMBOL_NAMESPACE (psym) = namespace;
   PSYMBOL_CLASS (psym) = class;
-  if (language == language_cplus)
-    {
-      demangled_name =
-       cplus_demangle (SYMBOL_NAME (psym), DMGL_PARAMS | DMGL_ANSI);
-      if (demangled_name == NULL)
-       {
-         SYMBOL_DEMANGLED_NAME (psym) = NULL;
-       }
-      else
-       {
-         SYMBOL_DEMANGLED_NAME (psym) =
-           obsavestring (demangled_name, strlen (demangled_name),
-                         &objfile->psymbol_obstack);
-         free (demangled_name);
-       }
-    }  
+  SYMBOL_INIT_DEMANGLED_NAME (psym, &objfile->psymbol_obstack);
 }
 
 /* Add a symbol with a CORE_ADDR value to a psymtab. */
@@ -1375,22 +1358,7 @@ add_psymbol_addr_to_list (name, namelength, namespace, class, list, val,
   SYMBOL_LANGUAGE (psym) = language;
   PSYMBOL_NAMESPACE (psym) = namespace;
   PSYMBOL_CLASS (psym) = class;
-  if (language == language_cplus)
-    {
-      demangled_name =
-       cplus_demangle (SYMBOL_NAME (psym), DMGL_PARAMS | DMGL_ANSI);
-      if (demangled_name == NULL)
-       {
-         SYMBOL_DEMANGLED_NAME (psym) = NULL;
-       }
-      else
-       {
-         SYMBOL_DEMANGLED_NAME (psym) =
-           obsavestring (demangled_name, strlen (demangled_name),
-                         &objfile->psymbol_obstack);
-         free (demangled_name);
-       }
-    }  
+  SYMBOL_INIT_DEMANGLED_NAME (psym, &objfile->psymbol_obstack);
 }
 
 #endif /* !INLINE_ADD_PSYMBOL */
This page took 0.027052 seconds and 4 git commands to generate.