From: Fred Fish Date: Sat, 28 Mar 1992 21:06:23 +0000 (+0000) Subject: Add OBJF_SYMS flag and use it to decide whether or not we have already X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=bf349b77faf68ba37c0379bc6c59ea8ace20562a;p=binutils-gdb.git Add OBJF_SYMS flag and use it to decide whether or not we have already tried to read symbols from a file, for mapped objfiles. This fixes a memory leak (actually a constant memory growth) due to reading symbol files with no debug info and thus generating no psymtabs or symtabs. Most typically happened with shared libraries. --- diff --git a/gdb/ChangeLog b/gdb/ChangeLog index fdce940c22a..094aa4de63c 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,10 @@ +Sat Mar 28 13:00:10 1992 Fred Fish (fnf@cygnus.com) + + * objfiles.h (OBJF_SYMS): Define flag bit for objfile flags. + * symfile.c (symbol_file_add): Use OBJF_SYMS to decide whether + or not to try reading symbols from a mapped objfile. Plugs memory + leak due to shared libraries generating no psymtabs or symtabs. + Fri Mar 27 15:44:55 1992 John Gilmore (gnu at cygnus.com) * buildsym.c (MAX_OF_C_TYPE, MIN_OF_C_TYPE): Unused, remove. diff --git a/gdb/objfiles.h b/gdb/objfiles.h index 8efaa93e11d..3551c05a746 100644 --- a/gdb/objfiles.h +++ b/gdb/objfiles.h @@ -236,6 +236,15 @@ struct objfile #define OBJF_MAPPED (1 << 0) /* Objfile data is mmap'd */ +/* When using mapped/remapped predigested gdb symbol information, we need + a flag that indicates that we have previously done an initial symbol + table read from this particular objfile. We can't just look for the + absence of any of the three symbol tables (msymbols, psymtab, symtab) + because if the file has no symbols for example, none of these will + exist. */ + +#define OBJF_SYMS (1 << 1) /* Have tried to read symbols */ + /* The object file that the main symbol table was loaded from (e.g. the argument to the "symbol-file" or "file" command). */ diff --git a/gdb/symfile.c b/gdb/symfile.c index 56220953f4e..9b50d6f2d1a 100644 --- a/gdb/symfile.c +++ b/gdb/symfile.c @@ -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" @@ -39,16 +40,12 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ /* 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 @@ -81,26 +78,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 +305,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 +355,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) @@ -488,11 +480,12 @@ 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); @@ -503,8 +496,8 @@ symbol_file_add (name, from_tty, addr, mainline, mapped, readnow) 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); @@ -512,6 +505,7 @@ symbol_file_add (name, from_tty, addr, mainline, mapped, readnow) fflush (stdout); } syms_from_objfile (objfile, addr, mainline, from_tty); + objfile -> flags |= OBJF_SYMS; } /* We now have at least a partial symbol table. Check to see if the @@ -519,8 +513,7 @@ symbol_file_add (name, from_tty, addr, mainline, mapped, readnow) 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) {