From b5b186a2cd2fd9fd03cbdf574ec48490b978e182 Mon Sep 17 00:00:00 2001 From: Stan Shebs Date: Wed, 29 Sep 1993 01:53:52 +0000 Subject: [PATCH] Additions to support stabs-in-coff. --- gdb/ChangeLog | 17 +++++++- gdb/coffread.c | 106 +++++++++++++++++++++++++++++++++++++++++-------- gdb/dbxread.c | 77 +++++++++++++++++++++++++++++++++++ 3 files changed, 182 insertions(+), 18 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index b43b79bbd51..ef2fa78a41c 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,18 @@ +Tue Sep 28 18:39:37 1993 Stan Shebs (shebs@rtl.cygnus.com) + + * configure.in: Rename ...-lynx* to ...-lynxos*. + Add m68*-*-lynxos* configuration. + * dbxread.c (coffstab_build_psymtabs): New function, + interfaces coffread.c to dbxread functions. + * coffread.c (coff_symfile_info): Expand to include + dbx_symfile_info slots. + (coff_symfile_init): Init coff_symfile_info struct. + (coff_locate_sections): New functions, finds the stab and stabstr + sections. + (coff_symfile_read): Call coffstab_build_psymtabs if a stab + section is present. + (coff_section_offsets): Replace fake version with real offsets. + Tue Sep 28 18:00:50 1993 Jim Kingdon (kingdon@lioth.cygnus.com) * infcmd.c (run_stack_dummy): Set the frame in the bp_call_dummy @@ -11,7 +26,7 @@ Tue Sep 28 17:53:26 1993 Ian Lance Taylor (ian@tweedledumb.cygnus.com) * config/i386/i386v4.mt (TDEPFILES): Move solib.o from here... * config/i386/i386v4.mh (NATDEPFILES): ...to here. * config/i386/nm-i386v4.h: Include nm-sysv4.h. - * config/m68k/amix.mt (TDEPFIES): Move solib.o from here... + * config/m68k/amix.mt (TDEPFILES): Move solib.o from here... * config/m68k/amix.mh (NATDEPFILES): ...to here. Tue Sep 28 09:45:38 1993 Peter Schauer (pes@regent.e-technik.tu-muenchen.de) diff --git a/gdb/coffread.c b/gdb/coffread.c index 2accd5b9f04..8b3530dd336 100644 --- a/gdb/coffread.c +++ b/gdb/coffread.c @@ -27,6 +27,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "symfile.h" #include "objfiles.h" #include "buildsym.h" +#include "gdb-stabs.h" #include "complaints.h" #include @@ -38,6 +39,25 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "coff/internal.h" /* Internal format of COFF symbols in BFD */ #include "libcoff.h" /* FIXME secret internal data from BFD */ +struct coff_symfile_info { + asection *text_sect; /* Text section accessor */ + int symcount; /* How many symbols are there in the file */ + char *stringtab; /* The actual string table */ + int stringtab_size; /* Its size */ + file_ptr symtab_offset; /* Offset in file to symbol table */ + int symbol_size; /* Bytes in a single symbol */ + struct stab_section_info *stab_section_info; /* section starting points + of the original .o files before linking. */ + + asection *stabsect; /* Section pointer for .stab section */ + asection *stabstrsect; /* Section pointer for .stab section */ + asection *stabindexsect; /* Section pointer for .stab.index section */ + char *stabstrdata; + + file_ptr min_lineno_offset; /* Where in file lowest line#s are */ + file_ptr max_lineno_offset; /* 1+last byte of line#s in file */ +}; + /* Translate an external name string into a user-visible name. */ #define EXTERNAL_NAME(string, abfd) \ (string[0] == bfd_get_symbol_leading_char(abfd)? string+1: string) @@ -268,6 +288,39 @@ static struct type ** coff_lookup_type PARAMS ((int)); +static void +coff_locate_sections PARAMS ((bfd *, asection *, PTR)); + +/* We are called once per section from coff_symfile_read. We + need to examine each section we are passed, check to see + if it is something we are interested in processing, and + if so, stash away some access information for the section. + + FIXME: The section names should not be hardwired strings. */ + +static void +coff_locate_sections (ignore_abfd, sectp, csip) + bfd *ignore_abfd; + asection *sectp; + PTR csip; +{ + register struct coff_symfile_info *csi; + + csi = (struct coff_symfile_info *) csip; + if (STREQ (sectp->name, ".stab")) + { + csi->stabsect = sectp; + } + else if (STREQ (sectp->name, ".stabstr")) + { + csi->stabstrsect = sectp; + } + else if (STREQ (sectp->name, ".stab.index")) + { + csi->stabindexsect = sectp; + } +} + /* Look up a coff type-number index. Return the address of the slot where the type for that index is stored. The type-number is in INDEX. @@ -318,8 +371,6 @@ coff_alloc_type (index) return type; } -/* Manage the vector of line numbers. FIXME: Use record_line instead. */ - static void coff_record_line (line, pc) int line; @@ -459,32 +510,29 @@ record_minimal_symbol (name, address, type) The ultimate result is a new symtab (or, FIXME, eventually a psymtab). */ -struct coff_symfile_info { - file_ptr min_lineno_offset; /* Where in file lowest line#s are */ - file_ptr max_lineno_offset; /* 1+last byte of line#s in file */ -}; - static int text_bfd_scnum; static void coff_symfile_init (objfile) struct objfile *objfile; { - asection *section; + asection *section, *strsection; bfd *abfd = objfile->obfd; /* Allocate struct to keep track of the symfile */ objfile -> sym_private = xmmalloc (objfile -> md, sizeof (struct coff_symfile_info)); + memset (objfile->sym_private, 0, sizeof (struct coff_symfile_info)); + init_entry_point_info (objfile); /* Save the section number for the text section */ - section = bfd_get_section_by_name(abfd,".text"); + section = bfd_get_section_by_name (abfd, ".text"); if (section) text_bfd_scnum = section->index; else - text_bfd_scnum = -1; + text_bfd_scnum = -1; } /* This function is called for every section; it finds the outer limits @@ -550,6 +598,7 @@ coff_symfile_read (objfile, section_offsets, mainline) int symtab_offset; int stringtab_offset; struct cleanup *back_to; + int stabsize, stabstrsize; info = (struct coff_symfile_info *) objfile -> sym_private; symfile_bfd = abfd; /* Kludge for swap routines */ @@ -583,7 +632,7 @@ coff_symfile_read (objfile, section_offsets, mainline) /* Read the line number table, all at once. */ info->min_lineno_offset = 0; info->max_lineno_offset = 0; - bfd_map_over_sections (abfd, find_linenos, (PTR)info); + bfd_map_over_sections (abfd, find_linenos, (PTR) info); make_cleanup (free_linetab, 0); val = init_lineno (desc, info->min_lineno_offset, @@ -615,6 +664,23 @@ coff_symfile_read (objfile, section_offsets, mainline) install_minimal_symbols (objfile); + bfd_map_over_sections (abfd, coff_locate_sections, (PTR) info); + + if (info->stabsect) + { + /* dubious */ + fseek ((FILE *) abfd->iostream, abfd->where, 0); + + stabsize = bfd_section_size (abfd, info->stabsect); + stabstrsize = bfd_section_size (abfd, info->stabstrsect); + + coffstab_build_psymtabs (objfile, + section_offsets, + mainline, + info->stabsect->filepos, stabsize, + info->stabstrsect->filepos, stabstrsize); + } + do_cleanups (back_to); } @@ -622,7 +688,6 @@ static void coff_new_init (ignore) struct objfile *ignore; { - /* Nothin' to do */ } /* Perform any local cleanups required when we are done with a particular @@ -1960,16 +2025,23 @@ coff_read_enum_type (index, length, lastsym) return type; } -/* Fake up support for relocating symbol addresses. FIXME. */ - -struct section_offsets coff_symfile_faker = {{0}}; - struct section_offsets * coff_symfile_offsets (objfile, addr) struct objfile *objfile; CORE_ADDR addr; { - return &coff_symfile_faker; + struct section_offsets *section_offsets; + int i; + + section_offsets = (struct section_offsets *) + obstack_alloc (&objfile -> psymbol_obstack, + sizeof (struct section_offsets) + + sizeof (section_offsets->offsets) * (SECT_OFF_MAX-1)); + + for (i = 0; i < SECT_OFF_MAX; i++) + ANOFFSET (section_offsets, i) = addr; + + return section_offsets; } /* Register our ability to parse symbols for coff BFD files */ diff --git a/gdb/dbxread.c b/gdb/dbxread.c index 3a871777fd3..e55c36a9c3b 100644 --- a/gdb/dbxread.c +++ b/gdb/dbxread.c @@ -2056,6 +2056,83 @@ copy_pending (beg, endi, end) return new; } +/* 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). + MAINLINE is true if we are reading the main symbol + table (as opposed to a shared lib or dynamically loaded file). + STABOFFSET and STABSIZE define the location in OBJFILE where the .stab + section exists. + 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 (objfile, section_offsets, mainline, + staboffset, stabsize, + stabstroffset, stabstrsize) + struct objfile *objfile; + struct section_offsets *section_offsets; + int mainline; + file_ptr staboffset; + unsigned int stabsize; + file_ptr stabstroffset; + unsigned int stabstrsize; +{ + int val; + bfd *sym_bfd = objfile->obfd; + char *name = bfd_get_filename (sym_bfd); + struct dbx_symfile_info *info; + + /* There is already a dbx_symfile_info allocated by our caller. + It might even contain some info from the coff symtab to help us. */ + info = (struct dbx_symfile_info *) objfile->sym_private; + + DBX_TEXT_SECT (objfile) = bfd_get_section_by_name (sym_bfd, ".text"); + if (!DBX_TEXT_SECT (objfile)) + error ("Can't find .text section in symbol file"); + +#define COFF_STABS_SYMBOL_SIZE 12 /* XXX FIXME XXX */ + DBX_SYMBOL_SIZE (objfile) = COFF_STABS_SYMBOL_SIZE; + DBX_SYMCOUNT (objfile) = stabsize / DBX_SYMBOL_SIZE (objfile); + DBX_STRINGTAB_SIZE (objfile) = stabstrsize; + DBX_SYMTAB_OFFSET (objfile) = staboffset; + + if (stabstrsize > bfd_get_size (sym_bfd)) + error ("ridiculous string table size: %d bytes", stabstrsize); + DBX_STRINGTAB (objfile) = (char *) + obstack_alloc (&objfile->psymbol_obstack, 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, 1, sym_bfd); + if (val != stabstrsize) + perror_with_name (name); + + stabsread_new_init (); + buildsym_new_init (); + free_header_files (); + init_header_files (); + + 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. */ + dbx_symfile_read (objfile, section_offsets, 0); +} + /* Scan and build partial symbols for an ELF symbol file. This ELF file has already been processed to get its minimal symbols, and any DWARF symbols that were in it. -- 2.30.2