From: John Gilmore Date: Sat, 13 Jun 1992 07:24:30 +0000 (+0000) Subject: * elfread.c (record_minimal_symbol_and_info): Kludged to put X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=346168a2c65e34dc6f2d073bbc0d158fb1aaa219;p=binutils-gdb.git * elfread.c (record_minimal_symbol_and_info): Kludged to put extra info in the minimal symbol. (elf_symtab_read): The extra info is the size of an ELF object, which was kludged to us in the `udata' field of the BFD symbol. Gag me with a crowbar... (elf_symfile_read): Keep track of both the absolute load address, and the offset between load addr and symbols. Handle STABS as well as DWARF sections, passing the absolute load address to elfstab_build_psymtabs. * objfiles.c (free_objfile): Eliminate storage leaks. Contributed by . * symfile.c (symfile_bfd_open): Comment where name is freed. * symmisc.c (extend_psymbol_list): Comment where list is freed. --- diff --git a/gdb/ChangeLog b/gdb/ChangeLog index e9effecccf3..186dc6bb817 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,58 @@ Fri Jun 12 18:54:40 1992 John Gilmore (gnu at cygnus.com) + * arm-pinsn.c, i960-pinsn.c, m68k-pinsn.c, mips-pinsn.c, + ns32k-pinsn.c, pyr-pinsn.c, sparc-pinsn.c, tahoe-pinsn.c, + vax-pinsn.c: Remove reg_names decl (now in defs.h). + + Solaris-2 support on SPARC: + + * dbxread.c: Add symbol_size to struct dbx_symfile_info. + Add symbol_size and file offsets to struct symloc. + Add static symbol_table_offset, string_table_offset, + file_string_table_offset, next_file_string_table_offset, + last_function_name. + (add_old_header_file): Convert error() to complain()t. + (dbx_symfile_read): Get symbol size via the objfile. + Also get symbol_table_offset. + (dbx_symfile_init): Record symbol size and count via the objfile. + (dbx_next_symbol_text): Always add file_string_table_offset when + accessing string table. + (read_dbx_symtab): Initialize file_string_table_offset to 0. + (SET_NAMESTRING): Use the offset. + (end_psymtab): Large kludge to determine addresses where source + files start and end (for the psymtab header). + (psymtab_to_symtab_1): Set file_string_table_offset before reading. + Get this, symbol size, and symbol offset, from psymtab. + (read_ofile_symtab): Don't back up one symbol for Solaris2. + Patch up last_source_start_addr if zero in N_SO. + (process_one_symbol): Add variable function_start_offset. + ( "", N_FUN, N_LBRAC, N_RBRAC, N_SLINE): Add ifdef for + BLOCK_ADDRESS_FUNCTION_RELATIVE. + ( "", N_OBJ, N_OPT): Ignore. + (elfstab_build_psymtabs): New function to read stabs out of + an ELF file. + + * Makefile.in: Accept $(BISON) even though we really want $(YACC). + (gdb): use GLOBAL_CFLAGS when linking, too. + * partial-stab.h (N_UNDF): Deal with Sol2 relative stringtab offsets. + (N_OBJ, N_OPT): Ignore. + ('f', 'F'): Save last function name. + + * elfread.c (record_minimal_symbol_and_info): Kludged to put + extra info in the minimal symbol. + (elf_symtab_read): The extra info is the size of an ELF object, + which was kludged to us in the `udata' field of the BFD symbol. + Gag me with a crowbar... + (elf_symfile_read): Keep track of both the absolute load address, + and the offset between load addr and symbols. Handle STABS as + well as DWARF sections, passing the absolute load address to + elfstab_build_psymtabs. + + * symfile.h: Prototype elfstab_build_psymtabs. + * symfile.c: Add almost-OK debug versions of add_psymbol_*to_list. + + * xm-sysv4.h: Add to avoid conflicting defns in defs.h. + * buildsym.h: Add processing_acc_compilation flag. * buildsym.c (read_sun_builtin_type, read_sun_floating_type): New. (define_symbol): Skip arg types in function entries. Resolve @@ -15,6 +68,11 @@ Fri Jun 12 18:54:40 1992 John Gilmore (gnu at cygnus.com) * configure.in: Solaris config is sparc-sun-solaris2. * config/sun4os5.m[ht]: Rename to config/sun4sol2.m[ht]; new xm, tm. + * objfiles.c (free_objfile): Eliminate storage leaks. Contributed + by . + * symfile.c (symfile_bfd_open): Comment where name is freed. + * symmisc.c (extend_psymbol_list): Comment where list is freed. + Fri Jun 12 12:49:43 1992 Fred Fish (fnf@cygnus.com) * expprint.c (print_subexp): Add missing ']'. diff --git a/gdb/elfread.c b/gdb/elfread.c index c2d133c62d2..bc997ef0b7b 100644 --- a/gdb/elfread.c +++ b/gdb/elfread.c @@ -49,6 +49,8 @@ struct elfinfo { unsigned int dbsize; /* Size of dwarf debug section */ unsigned int lnoffset; /* Offset to dwarf line number section */ unsigned int lnsize; /* Size of dwarf line number section */ + asection *stabsect; /* Section pointer for .stab section */ + asection *stabindexsect; /* Section pointer for .stab.index section */ }; static void @@ -84,6 +86,9 @@ elf_locate_sections PARAMS ((bfd *, asection *, PTR)); knowledge of DWARF (by design, so any debugging format can be used). + We also recognize the ".stab" sections used by the Sun compilers + released with Solaris 2. + FIXME: The section names should not be hardwired strings. */ static void @@ -105,6 +110,14 @@ elf_locate_sections (ignore_abfd, sectp, eip) ei -> lnoffset = sectp -> filepos; ei -> lnsize = bfd_get_section_size_before_reloc (sectp); } + else if (STREQ (sectp -> name, ".stab")) + { + ei -> stabsect = sectp; + } + else if (STREQ (sectp -> name, ".stab.index")) + { + ei -> stabindexsect = sectp; + } } #if 0 /* Currently unused */ @@ -166,6 +179,18 @@ record_minimal_symbol (name, address, ms_type, objfile) prim_record_minimal_symbol (name, address, ms_type); } +static void +record_minimal_symbol_and_info (name, address, ms_type, info, objfile) + char *name; + CORE_ADDR address; + enum minimal_symbol_type ms_type; + char *info; /* FIXME, is this really char *? */ + struct objfile *objfile; +{ + name = obsavestring (name, strlen (name), &objfile -> symbol_obstack); + prim_record_minimal_symbol_and_info (name, address, ms_type, info); +} + /* LOCAL FUNCTION @@ -239,7 +264,9 @@ elf_symtab_read (abfd, addr, objfile) { ms_type = mst_unknown; } - record_minimal_symbol ((char *) sym -> name, symaddr, ms_type, objfile); + /* Pass symbol size field in via BFD. FIXME!!! */ + record_minimal_symbol_and_info ((char *) sym -> name, + symaddr, ms_type, sym->udata, objfile); } } do_cleanups (back_to); @@ -262,15 +289,19 @@ elf_symtab_read (abfd, addr, objfile) symbol tables. When more extensive information is requested of a file, the corresponding partial symbol table is mutated into a full fledged symbol table by going back and reading the symbols - for real. The function dwarf_psymtab_to_symtab() is the function that - does this for DWARF symbols. + for real. + + We look for sections with specific names, to tell us what debug + format to look for: FIXME!!! + + dwarf_build_psymtabs() builds psymtabs for DWARF symbols; + elfstab_build_psymtabs() handles STABS symbols. Note that ELF files have a "minimal" symbol table, which looks a lot like a COFF symbol table, but has only the minimal information necessary - for linking. We process this also, and just use the information to - add to gdb's minimal symbol table. This gives us some minimal debugging - capability even for files compiled without -g. - */ + for linking. We process this also, and use the information to + build gdb's minimal symbol table. This gives us some minimal debugging + capability even for files compiled without -g. */ static void elf_symfile_read (objfile, addr, mainline) @@ -282,6 +313,7 @@ elf_symfile_read (objfile, addr, mainline) struct elfinfo ei; struct cleanup *back_to; asection *text_sect; + CORE_ADDR offset; init_minimal_symbol_collection (); back_to = make_cleanup (discard_minimal_symbols, 0); @@ -292,25 +324,47 @@ elf_symfile_read (objfile, addr, mainline) of the text section, we can compute the relocation amount. */ text_sect = bfd_get_section_by_name (objfile -> obfd, ".text"); - addr -= bfd_section_vma (objfile -> obfd, text_sect); + offset = addr - bfd_section_vma (objfile -> obfd, text_sect); /* Process the normal ELF symbol table first. */ - elf_symtab_read (abfd, addr, objfile); + elf_symtab_read (abfd, offset, objfile); - /* Now process the DWARF debugging information, which is contained in + /* Now process debugging information, which is contained in special ELF sections. We first have to find them... */ (void) memset ((char *) &ei, 0, sizeof (ei)); bfd_map_over_sections (abfd, elf_locate_sections, (PTR) &ei); if (ei.dboffset && ei.lnoffset) { + /* DWARF sections */ dwarf_build_psymtabs (fileno ((FILE *)(abfd -> iostream)), bfd_get_filename (abfd), - addr, mainline, + offset, mainline, ei.dboffset, ei.dbsize, ei.lnoffset, ei.lnsize, objfile); } + if (ei.stabsect) + { + /* STABS sections */ + + /* FIXME: Sun didn't really know how to implement this well. + They made .stab sections that don't point to the .stabstr + section with the sh_link field. BFD doesn't make string table + sections visible to the caller. So we have to search the + ELF section table, not the BFD section table, for the string + table. */ + Elf_Internal_Shdr *elf_sect = bfd_elf_find_section (abfd, ".stabstr"); + + if (elf_sect) + elfstab_build_psymtabs (objfile, + addr, /* We really pass the text seg addr, not the offset, here. */ + mainline, + ei.stabsect->filepos, /* .stab offset */ + bfd_get_section_size_before_reloc (ei.stabsect),/* .stab size */ + elf_sect->sh_offset, /* .stabstr offset */ + elf_sect->sh_size); /* .stabstr size */ + } if (!have_partial_symbols ()) { @@ -331,8 +385,7 @@ elf_symfile_read (objfile, addr, mainline) file is specified (not just adding some symbols from another file, e.g. a shared library). - For now at least, we have nothing in particular to do, so this function is - just a stub. */ + We reinitialize buildsym, since we may be reading stabs from an ELF file. */ static void elf_new_init (ignore) diff --git a/gdb/objfiles.c b/gdb/objfiles.c index 1ad5d94c49e..9b30c0fb4dc 100644 --- a/gdb/objfiles.c +++ b/gdb/objfiles.c @@ -267,15 +267,15 @@ free_objfile (objfile) if (objfile -> obfd != NULL) { + char *name = bfd_get_filename (objfile->obfd); bfd_close (objfile -> obfd); + free (name); } /* Remove it from the chain of all objfiles. */ unlink_objfile (objfile); -#if 0 /* FIXME!! */ - /* Before the symbol table code was redone to make it easier to selectively load and remove information particular to a specific linkage unit, gdb used to do these things whenever the monolithic @@ -289,8 +289,6 @@ free_objfile (objfile) #endif clear_pc_function_cache (); -#endif - /* The last thing we do is free the objfile struct itself for the non-reusable case, or detach from the mapped file for the reusable case. Note that the mmalloc_detach or the mfree is the last thing @@ -319,6 +317,10 @@ free_objfile (objfile) { mfree (objfile -> md, objfile -> name); } + if (objfile->global_psymbols.list) + mfree (objfile->md, objfile->global_psymbols.list); + if (objfile->static_psymbols.list) + mfree (objfile->md, objfile->static_psymbols.list); /* Free the obstacks for non-reusable objfiles */ obstack_free (&objfile -> psymbol_obstack, 0); obstack_free (&objfile -> symbol_obstack, 0); diff --git a/gdb/symfile.c b/gdb/symfile.c index de7f3a6ff3c..3ba11de8830 100644 --- a/gdb/symfile.c +++ b/gdb/symfile.c @@ -656,6 +656,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) diff --git a/gdb/symmisc.c b/gdb/symmisc.c index 285ac07b7d4..a78b399f24c 100644 --- a/gdb/symmisc.c +++ b/gdb/symmisc.c @@ -711,7 +711,9 @@ block_depth (block) } -/* Increase the space allocated for LISTP. */ +/* Increase the space allocated for LISTP, which is probably + global_psymbol_list or static_psymbol_list. This space will eventually + be freed in free_objfile(). */ void extend_psymbol_list (listp, objfile)