Oops! Retract last change. Didn't mean to pollute things with energize just
[deliverable/binutils-gdb.git] / gdb / symfile.c
index 56220953f4e69fcbf771a1f89b766e2e1977d7b4..740c4c10e52d01dd239cf0a2f66d65b04e3b431c 100644 (file)
@@ -26,6 +26,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
 #include "target.h"
 #include "value.h"
 #include "symfile.h"
+#include "objfiles.h"
 #include "gdbcmd.h"
 #include "breakpoint.h"
 
@@ -36,19 +37,16 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
 #include <fcntl.h>
 #include <string.h>
 #include <sys/stat.h>
+#include <ctype.h>
 
 /* Global variables owned by this file */
 
-CORE_ADDR entry_point;                 /* Where execution starts in symfile */
 int readnow_symbol_files;              /* Read full symbols immediately */
 
 /* External variables and functions referenced. */
 
 extern int info_verbose;
 
-extern CORE_ADDR startup_file_start;   /* From blockframe.c */
-extern CORE_ADDR startup_file_end;     /* From blockframe.c */
-
 /* Functions this file defines */
 
 static void
@@ -72,7 +70,7 @@ symfile_bfd_open PARAMS ((char *));
 static void
 find_sym_fns PARAMS ((struct objfile *));
 
-static void
+void
 clear_symtab_users_once PARAMS ((void));
 
 /* List of all available sym_fns.  On gdb startup, each object file reader
@@ -81,26 +79,6 @@ clear_symtab_users_once PARAMS ((void));
 
 static struct sym_fns *symtab_fns = NULL;
 
-/* When we need to allocate a new type, we need to know which type_obstack
-   to allocate the type on, since there is one for each objfile.  The places
-   where types are allocated are deeply buried in function call hierarchies
-   which know nothing about objfiles, so rather than trying to pass a
-   particular objfile down to them, we just do an end run around them and
-   set current_objfile to be whatever objfile we expect to be using at the
-   time types are being allocated.  For instance, when we start reading
-   symbols for a particular objfile, we set current_objfile to point to that
-   objfile, and when we are done, we set it back to NULL, to ensure that we
-   never put a type someplace other than where we are expecting to put it.
-   FIXME:  Maybe we should review the entire type handling system and
-   see if there is a better way to avoid this problem. */
-
-struct objfile *current_objfile = NULL;
-
-/* The object file that the main symbol table was loaded from (e.g. the
-   argument to the "symbol-file" or "file" command).  */
-
-struct objfile *symfile_objfile = NULL;
-
 /* Structures with which to manage partial symbol allocation.  */
 
 struct psymbol_allocation_list global_psymbols = {0}, static_psymbols = {0};
@@ -328,6 +306,32 @@ psymtab_to_symtab (pst)
   return pst->symtab;
 }
 
+/* Initialize entry point information for this objfile. */
+
+void
+init_entry_point_info (objfile)
+     struct objfile *objfile;
+{
+  /* Save startup file's range of PC addresses to help blockframe.c
+     decide where the bottom of the stack is.  */
+
+  if (bfd_get_file_flags (objfile -> obfd) & EXEC_P)
+    {
+      /* Executable file -- record its entry point so we'll recognize
+        the startup file because it contains the entry point.  */
+      objfile -> ei.entry_point = bfd_get_start_address (objfile -> obfd);
+    }
+  else
+    {
+      /* Examination of non-executable.o files.  Short-circuit this stuff.  */
+      /* ~0 will not be in any file, we hope.  */
+      objfile -> ei.entry_point = ~0;
+      /* set the startup file to be an empty range.  */
+      objfile -> ei.entry_file_lowpc = 0;
+      objfile -> ei.entry_file_highpc = 0;
+    }
+}
+
 /* Process a symbol file, as either the main file or as a dynamically
    loaded file.
 
@@ -352,30 +356,19 @@ syms_from_objfile (objfile, addr, mainline, verbo)
   /* 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).  */
+     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;
 
-  /* Save startup file's range of PC addresses to help blockframe.c
-     decide where the bottom of the stack is.  */
-
-  if (bfd_get_file_flags (objfile -> obfd) & EXEC_P)
-    {
-      /* Executable file -- record its entry point so we'll recognize
-        the startup file because it contains the entry point.  */
-      entry_point = bfd_get_start_address (objfile -> obfd);
-    }
-  else
-    {
-      /* Examination of non-executable.o files.  Short-circuit this stuff.  */
-      /* ~0 will not be in any file, we hope.  */
-      entry_point = ~0;
-      /* set the startup file to be an empty range.  */
-      startup_file_start = 0;
-      startup_file_end = 0;
-    }
-
+  init_entry_point_info (objfile);
   find_sym_fns (objfile);
 
   if (mainline) 
@@ -411,6 +404,22 @@ syms_from_objfile (objfile, addr, mainline, verbo)
   TYPE_NAME (lookup_pointer_type (builtin_type_char)) = 0;
   TYPE_NAME (lookup_pointer_type (builtin_type_void)) = 0;
 
+  /* Mark the objfile has having had initial symbol read attempted.  Note
+     that this does not mean we found any symbols... */
+
+  objfile -> flags |= OBJF_SYMS;
+}
+
+/* Perform required actions immediately after either reading in the initial
+   symbols for a new objfile, or mapping in the symbols from a reusable
+   objfile. */
+   
+void
+new_symfile_objfile (objfile, mainline, verbo)
+     struct objfile *objfile;
+     int mainline;
+     int verbo;
+{
   if (mainline)
     {
       /* OK, make it the "real" symbol file.  */
@@ -454,7 +463,6 @@ symbol_file_add (name, from_tty, addr, mainline, mapped, readnow)
   struct objfile *objfile;
   struct partial_symtab *psymtab;
   bfd *abfd;
-  int mapped_it;
 
   /* 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
@@ -488,23 +496,26 @@ symbol_file_add (name, from_tty, addr, mainline, mapped, readnow)
   /* If the objfile uses a mapped symbol file, and we have a psymtab for
      it, then skip reading any symbols at this time. */
 
-  if ((objfile -> flags & OBJF_MAPPED) && (objfile -> psymtabs != NULL))
+  if ((objfile -> flags & OBJF_MAPPED) && (objfile -> flags & OBJF_SYMS))
     {
       /* We mapped in an existing symbol table file that already has had
-        the psymbols read in.  So we can skip that part.  Notify the user
-        that instead of reading the symbols, they have been mapped. */
+        initial symbol reading performed, so we can skip that part.  Notify
+        the user that instead of reading the symbols, they have been mapped.
+        */
       if (from_tty || info_verbose)
        {
          printf_filtered ("Mapped symbols for %s...", name);
          wrap_here ("");
          fflush (stdout);
        }
+      init_entry_point_info (objfile);
+      find_sym_fns (objfile);
     }
   else
     {
       /* We either created a new mapped symbol table, mapped an existing
-        symbol table file with no partial symbols, or need to read an
-        unmapped symbol table. */
+        symbol table file which has not had initial symbol reading
+        performed, or need to read an unmapped symbol table. */
       if (from_tty || info_verbose)
        {
          printf_filtered ("Reading symbols from %s...", name);
@@ -514,13 +525,14 @@ symbol_file_add (name, from_tty, addr, mainline, mapped, readnow)
       syms_from_objfile (objfile, addr, mainline, from_tty);
     }      
 
+  new_symfile_objfile (objfile, mainline, from_tty);
+
   /* We now have at least a partial symbol table.  Check to see if the
      user requested that all symbols be read on initial access via either
      the gdb startup command line or on a per symbol file basis.  Expand
      all partial symbol tables for this objfile if so. */
 
-  readnow |= readnow_symbol_files;
-  if (readnow)
+  if (readnow || readnow_symbol_files)
     {
       if (from_tty || info_verbose)
        {
@@ -533,7 +545,7 @@ symbol_file_add (name, from_tty, addr, mainline, mapped, readnow)
           psymtab != NULL;
           psymtab = psymtab -> next)
        {
-         (void) psymtab_to_symtab (psymtab);
+         psymtab_to_symtab (psymtab);
        }
     }
 
@@ -557,7 +569,6 @@ symbol_file_command (args, from_tty)
   char **argv;
   char *name = NULL;
   struct cleanup *cleanups;
-  struct objfile *objfile;
   int mapped = 0;
   int readnow = 0;
 
@@ -572,6 +583,10 @@ symbol_file_command (args, from_tty)
        error ("Not confirmed.");
       free_all_objfiles ();
       symfile_objfile = NULL;
+      if (from_tty)
+       {
+         printf ("No symbol file now.\n");
+       }
     }
   else
     {
@@ -610,8 +625,7 @@ symbol_file_command (args, from_tty)
          /* Getting new symbols may change our opinion about what is
             frameless.  */
          reinit_frame_cache ();
-         objfile = symbol_file_add (name, from_tty, (CORE_ADDR)0, 1,
-                                    mapped, readnow);
+         symbol_file_add (name, from_tty, (CORE_ADDR)0, 1, mapped, readnow);
        }
       do_cleanups (cleanups);
     }
@@ -641,6 +655,7 @@ symfile_bfd_open (name)
     }
   free (name);                 /* Free 1st new malloc'd copy */
   name = absolute_name;                /* Keep 2nd malloc'd copy in bfd */
+                               /* It'll be freed in free_objfile(). */
 
   sym_bfd = bfd_fdopenr (name, NULL, desc);
   if (!sym_bfd)
@@ -685,7 +700,7 @@ static void
 find_sym_fns (objfile)
      struct objfile *objfile;
 {
-  struct sym_fns *sf, *sf2;
+  struct sym_fns *sf;
 
   for (sf = symtab_fns; sf != NULL; sf = sf -> next)
     {
@@ -722,8 +737,8 @@ add_symbol_file_command (args, from_tty)
   char *name = NULL;
   CORE_ADDR text_addr;
   char *arg;
-  int readnow;
-  int mapped;
+  int readnow = 0;
+  int mapped = 0;
   
   dont_repeat ();
 
@@ -788,7 +803,7 @@ add_symbol_file_command (args, from_tty)
 
   reinit_frame_cache ();
 
-  (void) symbol_file_add (name, 0, text_addr, 0, mapped, readnow);
+  symbol_file_add (name, 0, text_addr, 0, mapped, readnow);
 }
 \f
 /* Re-read symbols if a symbol-file has changed.  */
@@ -810,7 +825,7 @@ reread_symbols ()
 the_big_top:
   for (objfile = object_files; objfile; objfile = objfile->next) {
     if (objfile->obfd) {
-#ifdef IBM6000
+#ifdef IBM6000_TARGET
      /* If this object is from a shared library, then you should
         stat on the library name, not member name. */
 
@@ -976,7 +991,7 @@ allocate_symtab (filename, objfile)
 
   symtab = (struct symtab *)
     obstack_alloc (&objfile -> symbol_obstack, sizeof (struct symtab));
-  (void) memset (symtab, 0, sizeof (*symtab));
+  memset (symtab, 0, sizeof (*symtab));
   symtab -> filename = obsavestring (filename, strlen (filename),
                                     &objfile -> symbol_obstack);
   symtab -> fullname = NULL;
@@ -1012,7 +1027,7 @@ allocate_psymtab (filename, objfile)
       obstack_alloc (&objfile -> psymbol_obstack,
                     sizeof (struct partial_symtab));
 
-  (void) memset (psymtab, 0, sizeof (struct partial_symtab));
+  memset (psymtab, 0, sizeof (struct partial_symtab));
   psymtab -> filename = obsavestring (filename, strlen (filename),
                                      &objfile -> psymbol_obstack);
   psymtab -> symtab = NULL;
@@ -1055,7 +1070,7 @@ allocate_psymtab (filename, objfile)
 static int clear_symtab_users_queued;
 static int clear_symtab_users_done;
 
-static void
+void
 clear_symtab_users_once ()
 {
   /* Enforce once-per-`do_cleanups'-semantics */
@@ -1134,18 +1149,21 @@ int
 free_named_symtabs (name)
      char *name;
 {
-  register struct symtab *s;
-  register struct symtab *prev;
-  register struct partial_symtab *ps;
-  struct blockvector *bv;
-  int blewit = 0;
-
 #if 0
   /* FIXME:  With the new method of each objfile having it's own
      psymtab list, this function needs serious rethinking.  In particular,
      why was it ever necessary to toss psymtabs with specific compilation
      unit filenames, as opposed to all psymtabs from a particular symbol
-     file. */
+     file?  -- fnf
+     Well, the answer is that some systems permit reloading of particular
+     compilation units.  We want to blow away any old info about these
+     compilation units, regardless of which objfiles they arrived in. --gnu.  */
+
+  register struct symtab *s;
+  register struct symtab *prev;
+  register struct partial_symtab *ps;
+  struct blockvector *bv;
+  int blewit = 0;
 
   /* We only wack things if the symbol-reload switch is set.  */
   if (!symbol_reloading)
@@ -1253,7 +1271,44 @@ start_psymtab_common (objfile, addr,
   psymtab -> statics_offset = static_syms - objfile -> static_psymbols.list;
   return (psymtab);
 }
+\f
+/* Debugging versions of functions that are usually inline macros
+   (see symfile.h).  */
+
+#if 0          /* Don't quite work nowadays... */
+
+/* Add a symbol with a long value to a psymtab.
+   Since one arg is a struct, we pass in a ptr and deref it (sigh).  */
+
+void
+add_psymbol_to_list (name, namelength, namespace, class, list, val)
+     char *name;
+     int namelength;
+     enum namespace namespace;
+     enum address_class class;
+     struct psymbol_allocation_list *list;
+     long val;
+{
+  ADD_PSYMBOL_VT_TO_LIST (name, namelength, namespace, class, (*list), val,
+                         SYMBOL_VALUE);
+}
+
+/* Add a symbol with a CORE_ADDR value to a psymtab. */
+
+void
+add_psymbol_addr_to_list (name, namelength, namespace, class, list, val)
+     char *name;
+     int namelength;
+     enum namespace namespace;
+     enum address_class class;
+     struct psymbol_allocation_list *list;
+     CORE_ADDR val;
+{
+  ADD_PSYMBOL_VT_TO_LIST (name, namelength, namespace, class, (*list), val,
+                         SYMBOL_VALUE_ADDRESS);
+}
 
+#endif /* 0 */
 \f
 void
 _initialize_symfile ()
This page took 0.028703 seconds and 4 git commands to generate.