aboutsummaryrefslogtreecommitdiff
path: root/gdb/coffread.c
diff options
context:
space:
mode:
Diffstat (limited to 'gdb/coffread.c')
-rw-r--r--gdb/coffread.c194
1 files changed, 41 insertions, 153 deletions
diff --git a/gdb/coffread.c b/gdb/coffread.c
index c470668..cdb2bcf 100644
--- a/gdb/coffread.c
+++ b/gdb/coffread.c
@@ -1,5 +1,5 @@
/* Read coff symbol tables and convert to internal format, for GDB.
- Copyright (C) 1987-2024 Free Software Foundation, Inc.
+ Copyright (C) 1987-2025 Free Software Foundation, Inc.
Contributed by David D. Johnson, Brown University (ddj@cs.brown.edu).
This file is part of GDB.
@@ -25,19 +25,16 @@
#include "bfd.h"
#include "gdbsupport/gdb_obstack.h"
-#include <ctype.h>
#include "coff/internal.h"
#include "libcoff.h"
#include "objfiles.h"
#include "buildsym-legacy.h"
-#include "stabsread.h"
#include "complaints.h"
#include "target.h"
#include "block.h"
#include "dictionary.h"
#include "dwarf2/public.h"
-#include "gdb-stabs.h"
#include "coff-pe-read.h"
@@ -160,6 +157,10 @@ static file_ptr linetab_size;
static char *stringtab = NULL;
static long stringtab_length = 0;
+/* Used when reading coff symbols. */
+static int symnum;
+static bool within_function;
+
extern void stabsread_clear_cache (void);
static struct type *coff_read_struct_type (int, int, int,
@@ -205,99 +206,6 @@ static void read_one_sym (struct coff_symbol *,
static void coff_symtab_read (minimal_symbol_reader &,
file_ptr, unsigned int, struct objfile *);
-/* 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<asection *> &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;
-
- stabs_deprecated_warning ();
- /* 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;
- }
-
- read_stabs_symtab (objfile, 0);
-}
-
/* 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
@@ -336,7 +244,7 @@ coff_locate_sections (bfd *abfd, asection *sectp, void *csip)
/* We can have multiple .stab sections if linked with
--split-by-reloc. */
for (s = name + sizeof ".stab" - 1; *s != '\0'; s++)
- if (!isdigit (*s))
+ if (!c_isdigit (*s))
break;
if (*s == '\0')
csi->stabsects->push_back (sectp);
@@ -406,7 +314,7 @@ cs_section_address (struct coff_symbol *cs, bfd *abfd)
/* 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.
+ The type-number is in INDEX.
This can be used for finding the type associated with that index
or for associating a new type with the index. */
@@ -459,7 +367,6 @@ coff_alloc_type (int index)
static void
coff_start_compunit_symtab (struct objfile *objfile, const char *name)
{
- within_function = 0;
start_compunit_symtab (objfile,
name,
/* We never know the directory name for COFF. */
@@ -525,9 +432,9 @@ is_import_fixup_symbol (struct coff_symbol *cs,
/* The name must start with "__fu<digits>__". */
if (!startswith (cs->c_name, "__fu"))
return 0;
- if (! isdigit (cs->c_name[4]))
+ if (! c_isdigit (cs->c_name[4]))
return 0;
- for (i = 5; cs->c_name[i] != '\0' && isdigit (cs->c_name[i]); i++)
+ for (i = 5; cs->c_name[i] != '\0' && c_isdigit (cs->c_name[i]); i++)
/* Nothing, just incrementing index past all digits. */;
if (cs->c_name[i] != '_' || cs->c_name[i + 1] != '_')
return 0;
@@ -538,7 +445,7 @@ is_import_fixup_symbol (struct coff_symbol *cs,
static struct minimal_symbol *
record_minimal_symbol (minimal_symbol_reader &reader,
struct coff_symbol *cs, unrelocated_addr address,
- enum minimal_symbol_type type, int section,
+ enum minimal_symbol_type type, int section,
struct objfile *objfile)
{
/* We don't want TDESC entry points in the minimal symbol table. */
@@ -706,8 +613,7 @@ coff_symfile_read (struct objfile *objfile, symfile_add_flags symfile_flags)
unsigned int num_symbols;
file_ptr symtab_offset;
file_ptr stringtab_offset;
- unsigned int stabstrsize;
-
+
info = coff_objfile_data_key.get (objfile);
symfile_bfd = abfd; /* Kludge for swap routines. */
@@ -794,23 +700,7 @@ coff_symfile_read (struct objfile *objfile, symfile_add_flags symfile_flags)
bfd_map_over_sections (abfd, coff_locate_sections, (void *) info);
if (!info->stabsects->empty())
- {
- if (!info->stabstrsect)
- {
- error (_("The debugging information in `%s' is corrupted.\nThe "
- "file has a `.stabs' section, but no `.stabstr' section."),
- filename);
- }
-
- /* FIXME: dubious. Why can't we use something normal like
- bfd_get_section_contents? */
- stabstrsize = bfd_section_size (info->stabstrsect);
-
- coffstab_build_psymtabs (objfile,
- info->textaddr, info->textsize,
- *info->stabsects,
- info->stabstrsect->filepos, stabstrsize);
- }
+ warning (_("stabs debug information is not supported."));
if (dwarf2_initialize_objfile (objfile))
{
@@ -841,8 +731,6 @@ coff_new_init (struct objfile *ignore)
static void
coff_symfile_finish (struct objfile *objfile)
{
- /* Let stabs reader clean up. */
- stabsread_clear_cache ();
}
@@ -882,6 +770,9 @@ coff_symtab_read (minimal_symbol_reader &reader,
scoped_free_pendings free_pending;
+ within_function = false;
+ symnum = 0;
+
/* Position to read the symbol table. */
val = bfd_seek (objfile->obfd.get (), symtab_offset, 0);
if (val < 0)
@@ -900,10 +791,9 @@ coff_symtab_read (minimal_symbol_reader &reader,
coff_start_compunit_symtab (objfile, "");
- symnum = 0;
while (symnum < nsyms)
{
- QUIT; /* Make this command interruptable. */
+ QUIT; /* Make this command interruptible. */
read_one_sym (cs, &main_sym, &main_aux);
@@ -1123,7 +1013,7 @@ coff_symtab_read (minimal_symbol_reader &reader,
case C_FCN:
if (strcmp (cs->c_name, ".bf") == 0)
{
- within_function = 1;
+ within_function = true;
/* Value contains address of first non-init type
code. */
@@ -1142,7 +1032,7 @@ coff_symtab_read (minimal_symbol_reader &reader,
newobj = push_context (depth, fcn_start_addr);
fcn_cs_saved.c_name = getsymname (&fcn_sym_saved);
newobj->name =
- process_coff_symbol (&fcn_cs_saved,
+ process_coff_symbol (&fcn_cs_saved,
&fcn_aux_saved, objfile);
}
else if (strcmp (cs->c_name, ".ef") == 0)
@@ -1159,7 +1049,7 @@ coff_symtab_read (minimal_symbol_reader &reader,
complaint (_("`.ef' symbol without matching `.bf' "
"symbol ignored starting at symnum %d"),
cs->c_symnum);
- within_function = 0;
+ within_function = false;
break;
}
@@ -1170,7 +1060,7 @@ coff_symtab_read (minimal_symbol_reader &reader,
complaint (_("Unmatched .ef symbol(s) ignored "
"starting at symnum %d"),
cs->c_symnum);
- within_function = 0;
+ within_function = false;
break;
}
if (cs->c_naux != 1)
@@ -1204,7 +1094,7 @@ coff_symtab_read (minimal_symbol_reader &reader,
fcn_cs_saved.c_value
+ fcn_aux_saved.x_sym.x_misc.x_fsize
+ objfile->text_section_offset ());
- within_function = 0;
+ within_function = false;
}
break;
@@ -1257,9 +1147,9 @@ coff_symtab_read (minimal_symbol_reader &reader,
/* Patch up any opaque types (references to types that are not defined
in the file where they are referenced, e.g. "struct foo *bar"). */
{
- for (compunit_symtab *cu : objfile->compunits ())
+ for (compunit_symtab &cu : objfile->compunits ())
{
- for (symtab *s : cu->filetabs ())
+ for (symtab *s : cu.filetabs ())
patch_opaque_types (s);
}
}
@@ -1567,7 +1457,7 @@ patch_opaque_types (struct symtab *s)
Remove syms from the chain when their types are stored,
but search the whole chain, as there may be several syms
from different files with the same name. */
- if (real_sym->aclass () == LOC_TYPEDEF
+ if (real_sym->loc_class () == LOC_TYPEDEF
&& real_sym->domain () == TYPE_DOMAIN
&& real_sym->type ()->code () == TYPE_CODE_PTR
&& real_sym->type ()->target_type ()->length () != 0)
@@ -1614,7 +1504,7 @@ static const struct symbol_register_ops coff_register_funcs = {
coff_reg_to_regnum
};
-/* The "aclass" index for computed COFF symbols. */
+/* The "loc_class" index for computed COFF symbols. */
static int coff_register_index;
@@ -1646,7 +1536,7 @@ process_coff_symbol (struct coff_symbol *cs,
(lookup_function_type (decode_function_type (cs, cs->c_type,
aux, objfile)));
- sym->set_aclass_index (LOC_BLOCK);
+ sym->set_loc_class_index (LOC_BLOCK);
if (cs->c_sclass == C_STAT || cs->c_sclass == C_THUMBSTAT
|| cs->c_sclass == C_THUMBSTATFUNC)
add_symbol_to_list (sym, get_file_symbols ());
@@ -1663,14 +1553,14 @@ process_coff_symbol (struct coff_symbol *cs,
break;
case C_AUTO:
- sym->set_aclass_index (LOC_LOCAL);
+ sym->set_loc_class_index (LOC_LOCAL);
add_symbol_to_list (sym, get_local_symbols ());
break;
case C_THUMBEXT:
case C_THUMBEXTFUNC:
case C_EXT:
- sym->set_aclass_index (LOC_STATIC);
+ sym->set_loc_class_index (LOC_STATIC);
sym->set_value_address ((CORE_ADDR) cs->c_value
+ objfile->section_offsets[SECT_OFF_TEXT (objfile)]);
add_symbol_to_list (sym, get_global_symbols ());
@@ -1679,7 +1569,7 @@ process_coff_symbol (struct coff_symbol *cs,
case C_THUMBSTAT:
case C_THUMBSTATFUNC:
case C_STAT:
- sym->set_aclass_index (LOC_STATIC);
+ sym->set_loc_class_index (LOC_STATIC);
sym->set_value_address ((CORE_ADDR) cs->c_value
+ objfile->section_offsets[SECT_OFF_TEXT (objfile)]);
if (within_function)
@@ -1698,7 +1588,7 @@ process_coff_symbol (struct coff_symbol *cs,
case C_GLBLREG:
#endif
case C_REG:
- sym->set_aclass_index (coff_register_index);
+ sym->set_loc_class_index (coff_register_index);
sym->set_value_longest (cs->c_value);
add_symbol_to_list (sym, get_local_symbols ());
break;
@@ -1708,20 +1598,20 @@ process_coff_symbol (struct coff_symbol *cs,
break;
case C_ARG:
- sym->set_aclass_index (LOC_ARG);
+ sym->set_loc_class_index (LOC_ARG);
sym->set_is_argument (1);
add_symbol_to_list (sym, get_local_symbols ());
break;
case C_REGPARM:
- sym->set_aclass_index (coff_register_index);
+ sym->set_loc_class_index (coff_register_index);
sym->set_is_argument (1);
sym->set_value_longest (cs->c_value);
add_symbol_to_list (sym, get_local_symbols ());
break;
case C_TPDEF:
- sym->set_aclass_index (LOC_TYPEDEF);
+ sym->set_loc_class_index (LOC_TYPEDEF);
sym->set_domain (TYPE_DOMAIN);
/* If type has no name, give it one. */
@@ -1733,7 +1623,7 @@ process_coff_symbol (struct coff_symbol *cs,
/* If we are giving a name to a type such as
"pointer to foo" or "function returning foo", we
better not set the TYPE_NAME. If the program
- contains "typedef char *caddr_t;", we don't want
+ contains "typedef char *caddr_t;", we don't want
all variables of type char * to print as caddr_t.
This is not just a consequence of GDB's type
management; CC and GCC (at least through version
@@ -1776,7 +1666,7 @@ process_coff_symbol (struct coff_symbol *cs,
case C_STRTAG:
case C_UNTAG:
case C_ENTAG:
- sym->set_aclass_index (LOC_TYPEDEF);
+ sym->set_loc_class_index (LOC_TYPEDEF);
sym->set_domain (STRUCT_DOMAIN);
/* Some compilers try to be helpful by inventing "fake"
@@ -1880,9 +1770,9 @@ decode_type (struct coff_symbol *cs, unsigned int c_type,
return the type that the function returns. */
static struct type *
-decode_function_type (struct coff_symbol *cs,
+decode_function_type (struct coff_symbol *cs,
unsigned int c_type,
- union internal_auxent *aux,
+ union internal_auxent *aux,
struct objfile *objfile)
{
if (aux->x_sym.x_tagndx.u32 == 0)
@@ -1895,9 +1785,9 @@ decode_function_type (struct coff_symbol *cs,
/* Basic C types. */
static struct type *
-decode_base_type (struct coff_symbol *cs,
+decode_base_type (struct coff_symbol *cs,
unsigned int c_type,
- union internal_auxent *aux,
+ union internal_auxent *aux,
struct objfile *objfile)
{
struct gdbarch *gdbarch = objfile->arch ();
@@ -2165,7 +2055,7 @@ coff_read_enum_type (int index, int length, int lastsym,
name = obstack_strdup (&objfile->objfile_obstack, name);
sym->set_linkage_name (name);
- sym->set_aclass_index (LOC_CONST);
+ sym->set_loc_class_index (LOC_CONST);
sym->set_domain (VAR_DOMAIN);
sym->set_value_longest (ms->c_value);
add_symbol_to_list (sym, symlist);
@@ -2248,9 +2138,7 @@ static const struct sym_fns coff_sym_fns =
NULL, /* sym_probe_fns */
};
-void _initialize_coffread ();
-void
-_initialize_coffread ()
+INIT_GDB_FILE (coffread)
{
add_symtab_fns (bfd_target_coff_flavour, &coff_sym_fns);