#include "symfile.h"
#include "objfiles.h"
#include "buildsym.h"
+#include "gdb-stabs.h"
#include "complaints.h"
#include <obstack.h>
#include <string.h>
#include <time.h> /* For time_t in libbfd.h. */
+#include <sys/types.h> /* For time_t, if not in time.h. */
#include "libbfd.h" /* FIXME secret internal data from BFD */
#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)
coff_lookup_type PARAMS ((int));
\f
+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 (what
+ should they be? I don't think most debug formats have enough
+ special section flags to specify what kind of debug section it is
+ -kingdon). */
+
+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.
return type;
}
\f
-/* Manage the vector of line numbers. FIXME: Use record_line instead. */
+/* Record a line number entry for line LINE at address PC.
+ FIXME: Use record_line instead. */
static void
coff_record_line (line, pc)
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
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 */
/* 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,
install_minimal_symbols (objfile);
+ bfd_map_over_sections (abfd, coff_locate_sections, (PTR) info);
+
+ if (info->stabsect)
+ {
+ /* FIXME: dubious. Why can't we use something normal like
+ bfd_get_section_contents? */
+ 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);
}
coff_new_init (ignore)
struct objfile *ignore;
{
- /* Nothin' to do */
}
/* Perform any local cleanups required when we are done with a particular
* or symnum of first global after last .file.
*/
next_file_symnum = cs->c_value;
- filestring = getfilename (&main_aux);
+ if (cs->c_naux > 0)
+ filestring = getfilename (&main_aux);
+ else
+ filestring = "";
+
/*
* Complete symbol table for last object file
* containing debugging information.
new = pop_context ();
if (depth-- != new->depth)
{
- complain (&eb_complaint, (char *)symnum);
+ complain (&eb_complaint, symnum);
break;
}
if (local_symbols && context_stack_depth > 0)
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 */