From 59d41830a3dae0120e0d223f91241ad40e7ca737 Mon Sep 17 00:00:00 2001 From: Guinevere Larsen Date: Tue, 10 Sep 2024 14:42:30 -0300 Subject: gdb: fully separate coff and elf reading from dbx With the previous commits, the only thing entangling elf and coff file reading with dbx file reading is the functions {elf|coff}stab_build_psymtabs, defined in dbxread.c. These functions depend on dbx_symfile_read. To solve this, I renamed read_stabs_symtab to read_stabs_symtab_1, and created a function with the original name that does what dbx_symfile_read used to do. This way, dbx_symfile_read can just call read_stabs_symtab, and the elf and coff psymtab builders can also call it directly, fully disentangling the readers, which would allow us to selectively not compile dbxread in the future. Approved-By: Tom Tromey --- gdb/dbxread.c | 259 +--------------------------------------------------------- 1 file changed, 1 insertion(+), 258 deletions(-) (limited to 'gdb/dbxread.c') diff --git a/gdb/dbxread.c b/gdb/dbxread.c index 446ea3a..1b29d6e 100644 --- a/gdb/dbxread.c +++ b/gdb/dbxread.c @@ -58,52 +58,6 @@ #include "gdb-stabs.h" - -/* find_text_range --- find start and end of loadable code sections - - The find_text_range function finds the shortest address range that - encloses all sections containing executable code, and stores it in - objfile's text_addr and text_size members. - - dbx_symfile_read will use this to finish off the partial symbol - table, in some cases. */ - -static void -find_text_range (bfd * sym_bfd, struct objfile *objfile) -{ - asection *sec; - int found_any = 0; - CORE_ADDR start = 0; - CORE_ADDR end = 0; - - for (sec = sym_bfd->sections; sec; sec = sec->next) - if (bfd_section_flags (sec) & SEC_CODE) - { - CORE_ADDR sec_start = bfd_section_vma (sec); - CORE_ADDR sec_end = sec_start + bfd_section_size (sec); - - if (found_any) - { - if (sec_start < start) - start = sec_start; - if (sec_end > end) - end = sec_end; - } - else - { - start = sec_start; - end = sec_end; - } - - found_any = 1; - } - - if (!found_any) - error (_("Can't find any code sections in symbol file")); - - DBX_TEXT_ADDR (objfile) = start; - DBX_TEXT_SIZE (objfile) = end - start; -} @@ -144,40 +98,7 @@ explicit_lookup_type (int real_filenum, int index) static void dbx_symfile_read (struct objfile *objfile, symfile_add_flags symfile_flags) { - bfd *sym_bfd; - int val; - struct dbx_symfile_info *key = dbx_objfile_data_key.get (objfile); - - sym_bfd = objfile->obfd.get (); - - /* .o and .nlm files are relocatables with text, data and bss segs based at - 0. This flag disables special (Solaris stabs-in-elf only) fixups for - symbols with a value of 0. */ - - key->ctx.symfile_relocatable = bfd_get_file_flags (sym_bfd) & HAS_RELOC; - - val = bfd_seek (sym_bfd, DBX_SYMTAB_OFFSET (objfile), SEEK_SET); - if (val < 0) - perror_with_name (objfile_name (objfile)); - - key->ctx.symbol_size = DBX_SYMBOL_SIZE (objfile); - key->ctx.symbol_table_offset = DBX_SYMTAB_OFFSET (objfile); - - scoped_free_pendings free_pending; - - minimal_symbol_reader reader (objfile); - - /* Read stabs data from executable file and define symbols. */ - - psymbol_functions *psf = new psymbol_functions (); - psymtab_storage *partial_symtabs = psf->get_partial_symtabs ().get (); - objfile->qf.emplace_front (psf); - read_stabs_symtab (reader, partial_symtabs, objfile); - - /* Install any minimal symbols that have been collected as the current - minimal symbols for this objfile. */ - - reader.install (); + read_stabs_symtab (objfile, symfile_flags); } /* Initialize anything that needs initializing when a completely new @@ -330,184 +251,6 @@ dbx_symfile_finish (struct objfile *objfile) -/* FIXME: The only difference between this and elfstab_build_psymtabs - is the call to install_minimal_symbols for elf, and the support for - split sections. 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). - TEXTADDR is the address of the text section. - TEXTSIZE is the size of the text section. - STABSECTS is the list of .stab sections in OBJFILE. - 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 (struct objfile *objfile, - CORE_ADDR textaddr, unsigned int textsize, - const std::vector &stabsects, - file_ptr stabstroffset, unsigned int stabstrsize) -{ - int val; - bfd *sym_bfd = objfile->obfd.get (); - const char *name = bfd_get_filename (sym_bfd); - unsigned int stabsize; - - /* Allocate struct to keep track of stab reading. */ - dbx_objfile_data_key.emplace (objfile); - dbx_symfile_info *key = dbx_objfile_data_key.get (objfile); - - DBX_TEXT_ADDR (objfile) = textaddr; - DBX_TEXT_SIZE (objfile) = textsize; - -#define COFF_STABS_SYMBOL_SIZE 12 /* XXX FIXME XXX */ - DBX_SYMBOL_SIZE (objfile) = COFF_STABS_SYMBOL_SIZE; - DBX_STRINGTAB_SIZE (objfile) = stabstrsize; - - if (stabstrsize > bfd_get_size (sym_bfd)) - error (_("ridiculous string table size: %d bytes"), stabstrsize); - DBX_STRINGTAB (objfile) = (char *) - obstack_alloc (&objfile->objfile_obstack, stabstrsize + 1); - OBJSTAT (objfile, sz_strtab += 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, sym_bfd); - if (val != stabstrsize) - perror_with_name (name); - - stabsread_new_init (); - free_header_files (); - init_header_files (); - - key->ctx.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. */ - scoped_restore save_symbuf_sections - = make_scoped_restore (&key->ctx.symbuf_sections); - if (stabsects.size () == 1) - { - stabsize = bfd_section_size (stabsects[0]); - DBX_SYMCOUNT (objfile) = stabsize / DBX_SYMBOL_SIZE (objfile); - DBX_SYMTAB_OFFSET (objfile) = stabsects[0]->filepos; - } - else - { - DBX_SYMCOUNT (objfile) = 0; - for (asection *section : stabsects) - { - stabsize = bfd_section_size (section); - DBX_SYMCOUNT (objfile) += stabsize / DBX_SYMBOL_SIZE (objfile); - } - - DBX_SYMTAB_OFFSET (objfile) = stabsects[0]->filepos; - - key->ctx.sect_idx = 1; - key->ctx.symbuf_sections = &stabsects; - key->ctx.symbuf_left = bfd_section_size (stabsects[0]); - key->ctx.symbuf_read = 0; - } - - dbx_symfile_read (objfile, 0); -} - -/* Scan and build partial symbols for an ELF symbol file. - This ELF 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). - STABSECT is the BFD section information for the .stab section. - 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 elf details. */ - -void -elfstab_build_psymtabs (struct objfile *objfile, asection *stabsect, - file_ptr stabstroffset, unsigned int stabstrsize) -{ - int val; - bfd *sym_bfd = objfile->obfd.get (); - const char *name = bfd_get_filename (sym_bfd); - - stabsread_new_init (); - - /* Allocate struct to keep track of stab reading. */ - dbx_objfile_data_key.emplace (objfile); - dbx_symfile_info *key = dbx_objfile_data_key.get (objfile); - - /* Find the first and last text address. dbx_symfile_read seems to - want this. */ - find_text_range (sym_bfd, objfile); - -#define ELF_STABS_SYMBOL_SIZE 12 /* XXX FIXME XXX */ - DBX_SYMBOL_SIZE (objfile) = ELF_STABS_SYMBOL_SIZE; - DBX_SYMCOUNT (objfile) - = bfd_section_size (stabsect) / DBX_SYMBOL_SIZE (objfile); - DBX_STRINGTAB_SIZE (objfile) = stabstrsize; - DBX_SYMTAB_OFFSET (objfile) = stabsect->filepos; - DBX_STAB_SECTION (objfile) = stabsect; - - if (stabstrsize > bfd_get_size (sym_bfd)) - error (_("ridiculous string table size: %d bytes"), stabstrsize); - DBX_STRINGTAB (objfile) = (char *) - obstack_alloc (&objfile->objfile_obstack, stabstrsize + 1); - OBJSTAT (objfile, sz_strtab += 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, sym_bfd); - if (val != stabstrsize) - perror_with_name (name); - - stabsread_new_init (); - free_header_files (); - init_header_files (); - - key->ctx.processing_acc_compilation = 1; - - key->ctx.symbuf_read = 0; - key->ctx.symbuf_left = bfd_section_size (stabsect); - - scoped_restore restore_stabs_data = make_scoped_restore (&key->ctx.stabs_data); - gdb::unique_xmalloc_ptr data_holder; - - key->ctx.stabs_data = symfile_relocate_debug_section (objfile, stabsect, NULL); - if (key->ctx.stabs_data) - data_holder.reset (key->ctx.stabs_data); - - /* In an elf file, we've already installed the minimal symbols that came - from the elf (non-stab) symbol table, so always act like an - incremental load here. dbx_symfile_read should not generate any new - minimal symbols, since we will have already read the ELF dynamic symbol - table and normal symbol entries won't be in the ".stab" section; but in - case it does, it will install them itself. */ - dbx_symfile_read (objfile, 0); -} /* Scan and build partial symbols for a file with special sections for stabs and stabstrings. The file has already been processed to get its minimal -- cgit v1.1