/* Read coff symbol tables and convert to internal format, for GDB.
- Copyright (C) 1987-2020 Free Software Foundation, Inc.
+ Copyright (C) 1987-2021 Free Software Foundation, Inc.
Contributed by David D. Johnson, Brown University (ddj@cs.brown.edu).
This file is part of GDB.
#include "target.h"
#include "block.h"
#include "dictionary.h"
+#include "dwarf2/public.h"
#include "coff-pe-read.h"
#define INITIAL_TYPE_VECTOR_LENGTH 160
static char *linetab = NULL;
-static long linetab_offset;
-static unsigned long linetab_size;
+static file_ptr linetab_offset;
+static file_ptr linetab_size;
static char *stringtab = NULL;
static void patch_opaque_types (struct symtab *);
-static void enter_linenos (long, int, int, struct objfile *);
+static void enter_linenos (file_ptr, int, int, struct objfile *);
-static int init_lineno (bfd *, long, int, gdb::unique_xmalloc_ptr<char> *);
+static int init_lineno (bfd *, file_ptr, file_ptr, gdb::unique_xmalloc_ptr<char> *);
static char *getsymname (struct internal_syment *);
static const char *coff_getfilename (union internal_auxent *);
-static int init_stringtab (bfd *, long, gdb::unique_xmalloc_ptr<char> *);
+static int init_stringtab (bfd *, file_ptr, gdb::unique_xmalloc_ptr<char> *);
static void read_one_sym (struct coff_symbol *,
struct internal_syment *,
union internal_auxent *);
static void coff_symtab_read (minimal_symbol_reader &,
- long, unsigned int, struct objfile *);
-\f
+ file_ptr, unsigned int, struct objfile *);
+
/* 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
const char *s;
/* We can have multiple .stab sections if linked with
- --split-by-reloc. */
+ --split-by-reloc. */
for (s = name + sizeof ".stab" - 1; *s != '\0'; s++)
if (!isdigit (*s))
break;
const char *filename = bfd_get_filename (abfd);
int val;
unsigned int num_symbols;
- int symtab_offset;
- int stringtab_offset;
- int stabstrsize;
+ 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. */
bfd_map_over_sections (abfd, find_linenos, (void *) info);
val = init_lineno (abfd, info->min_lineno_offset,
- info->max_lineno_offset - info->min_lineno_offset,
+ info->max_lineno_offset - info->min_lineno_offset,
&linetab_storage);
if (val < 0)
- error (_("\"%s\": error reading line numbers."), filename);
+ error (_("\"%s\": error reading line numbers."), filename);
}
/* Now read the string table, all at once. */
int lead = bfd_get_symbol_leading_char (objfile->obfd);
struct bound_minimal_symbol found;
- if (lead != '\0' && *name1 == lead)
+ if (lead != '\0' && *name1 == lead)
name1 += 1;
found = lookup_minimal_symbol (name1, NULL, objfile);
}
/* FIXME: dubious. Why can't we use something normal like
- bfd_get_section_contents? */
+ bfd_get_section_contents? */
bfd_seek (abfd, abfd->where, 0);
stabstrsize = bfd_section_size (info->stabstrsect);
dwarf2_build_frame_info (objfile);
/* Try to add separate debug file if no symbols table found. */
- if (!objfile_has_partial_symbols (objfile))
+ if (!objfile->has_partial_symbols ())
{
std::string debugfile = find_separate_debug_file_by_buildid (objfile);
static void
coff_symtab_read (minimal_symbol_reader &reader,
- long symtab_offset, unsigned int nsyms,
+ file_ptr symtab_offset, unsigned int nsyms,
struct objfile *objfile)
{
- struct gdbarch *gdbarch = get_objfile_arch (objfile);
+ struct gdbarch *gdbarch = objfile->arch ();
struct context_stack *newobj = nullptr;
struct coff_symbol coff_symbol;
struct coff_symbol *cs = &coff_symbol;
bfd_seek (objfile->obfd, 0, 0);
/* Position to read the symbol table. */
- val = bfd_seek (objfile->obfd, (long) symtab_offset, 0);
+ val = bfd_seek (objfile->obfd, symtab_offset, 0);
if (val < 0)
perror_with_name (objfile_name (objfile));
sym = process_coff_symbol
(cs, &main_aux, objfile);
SYMBOL_VALUE (sym) = tmpaddr + offset;
- SYMBOL_SECTION (sym) = sec;
+ sym->set_section_index (sec);
}
}
break;
/* Value contains address of first non-init type
code. */
/* main_aux.x_sym.x_misc.x_lnsz.x_lnno
- contains line number of '{' }. */
+ contains line number of '{' }. */
if (cs->c_naux != 1)
complaint (_("`.bf' symbol %d has no aux entry"),
cs->c_symnum);
fcn_first_line_addr = cs->c_value;
/* Might want to check that locals are 0 and
- context_stack_depth is zero, and complain if not. */
+ context_stack_depth is zero, and complain if not. */
depth = 0;
newobj = push_context (depth, fcn_start_addr);
if (!within_function)
error (_("Bad coff function information."));
/* The value of .ef is the address of epilogue code;
- not useful for gdb. */
+ not useful for gdb. */
/* { main_aux.x_sym.x_misc.x_lnsz.x_lnno
- contains number of lines to '}' */
+ contains number of lines to '}' */
if (outermost_context_p ())
{ /* We attempted to pop an empty context stack. */
fcn_last_line = main_aux.x_sym.x_misc.x_lnsz.x_lnno;
}
/* fcn_first_line is the line number of the opening '{'.
- Do not record it - because it would affect gdb's idea
- of the line number of the first statement of the
- function - except for one-line functions, for which
- it is also the line number of all the statements and
- of the closing '}', and for which we do not have any
- other statement-line-number. */
+ Do not record it - because it would affect gdb's idea
+ of the line number of the first statement of the
+ function - except for one-line functions, for which
+ it is also the line number of all the statements and
+ of the closing '}', and for which we do not have any
+ other statement-line-number. */
if (fcn_last_line == 1)
record_line (get_current_subfile (), fcn_first_line,
gdbarch_addr_bits_remove (gdbarch,
sym->n_type, sym->n_sclass,
0, cs->c_naux, (char *) aux);
/* If more than one aux entry, read past it (only the first aux
- is important). */
+ is important). */
for (i = 1; i < cs->c_naux; i++)
{
bytes = bfd_bread (temp_aux, local_auxesz, nlist_bfd_global);
/* Support for string table handling. */
static int
-init_stringtab (bfd *abfd, long offset, gdb::unique_xmalloc_ptr<char> *storage)
+init_stringtab (bfd *abfd, file_ptr offset, gdb::unique_xmalloc_ptr<char> *storage)
{
long length;
int val;
if (symbol_entry->_n._n_n._n_zeroes == 0)
{
/* FIXME: Probably should be detecting corrupt symbol files by
- seeing whether offset points to within the stringtab. */
+ seeing whether offset points to within the stringtab. */
result = stringtab + symbol_entry->_n._n_n._n_offset;
}
else
them into GDB's data structures. */
static int
-init_lineno (bfd *abfd, long offset, int size,
+init_lineno (bfd *abfd, file_ptr offset, file_ptr size,
gdb::unique_xmalloc_ptr<char> *storage)
{
int val;
#endif
static void
-enter_linenos (long file_offset, int first_line,
+enter_linenos (file_ptr file_offset, int first_line,
int last_line, struct objfile *objfile)
{
- struct gdbarch *gdbarch = get_objfile_arch (objfile);
+ struct gdbarch *gdbarch = objfile->arch ();
char *rawptr;
struct internal_lineno lptr;
return;
if (file_offset < linetab_offset)
{
- complaint (_("Line number pointer %ld lower than start of line numbers"),
- file_offset);
+ complaint (_("Line number pointer %s lower than start of line numbers"),
+ plongest (file_offset));
if (file_offset > linetab_size) /* Too big to be an offset? */
return;
file_offset += linetab_offset; /* Try reading at that linetab
{
struct type *target = TYPE_TARGET_TYPE (type);
struct type *real_target = TYPE_TARGET_TYPE (real_type);
- int field_size = TYPE_NFIELDS (real_target) * sizeof (struct field);
+ int field_size = real_target->num_fields () * sizeof (struct field);
TYPE_LENGTH (target) = TYPE_LENGTH (real_target);
- TYPE_NFIELDS (target) = TYPE_NFIELDS (real_target);
- TYPE_FIELDS (target) = (struct field *) TYPE_ALLOC (target,
- field_size);
+ target->set_num_fields (real_target->num_fields ());
- memcpy (TYPE_FIELDS (target),
- TYPE_FIELDS (real_target),
- field_size);
+ field *fields = (struct field *) TYPE_ALLOC (target, field_size);
+ memcpy (fields, real_target->fields (), field_size);
+ target->set_fields (fields);
- if (TYPE_NAME (real_target))
+ if (real_target->name ())
{
/* The previous copy of TYPE_NAME is allocated by
process_coff_symbol. */
- if (TYPE_NAME (target))
- xfree ((char*) TYPE_NAME (target));
- TYPE_NAME (target) = xstrdup (TYPE_NAME (real_target));
+ xfree ((char *) target->name ());
+ target->set_name (xstrdup (real_target->name ()));
}
}
ALL_BLOCK_SYMBOLS (b, iter, real_sym)
{
/* Find completed typedefs to use to fix opaque ones.
- 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. */
+ 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 (SYMBOL_CLASS (real_sym) == LOC_TYPEDEF
&& SYMBOL_DOMAIN (real_sym) == VAR_DOMAIN
- && TYPE_CODE (SYMBOL_TYPE (real_sym)) == TYPE_CODE_PTR
+ && SYMBOL_TYPE (real_sym)->code () == TYPE_CODE_PTR
&& TYPE_LENGTH (TYPE_TARGET_TYPE (SYMBOL_TYPE (real_sym))) != 0)
{
const char *name = real_sym->linkage_name ();
union internal_auxent *aux,
struct objfile *objfile)
{
- struct symbol *sym = allocate_symbol (objfile);
+ struct symbol *sym = new (&objfile->objfile_obstack) symbol;
char *name;
name = cs->c_name;
/* default assumptions */
SYMBOL_VALUE (sym) = cs->c_value;
SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
- SYMBOL_SECTION (sym) = cs_to_section (cs, objfile);
+ sym->set_section_index (cs_to_section (cs, objfile));
if (ISFCN (cs->c_type))
{
SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
/* If type has no name, give it one. */
- if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0)
+ if (SYMBOL_TYPE (sym)->name () == 0)
{
- if (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_PTR
- || TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_FUNC)
+ if (SYMBOL_TYPE (sym)->code () == TYPE_CODE_PTR
+ || SYMBOL_TYPE (sym)->code () == TYPE_CODE_FUNC)
{
/* If we are giving a name to a type such as
"pointer to foo" or "function returning foo", we
;
}
else
- TYPE_NAME (SYMBOL_TYPE (sym)) =
- xstrdup (sym->linkage_name ());
+ SYMBOL_TYPE (sym)->set_name (xstrdup (sym->linkage_name ()));
}
/* Keep track of any type which points to empty structured
not an empty structured type, though; the forward
references work themselves out via the magic of
coff_lookup_type. */
- if (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_PTR
+ if (SYMBOL_TYPE (sym)->code () == TYPE_CODE_PTR
&& TYPE_LENGTH (TYPE_TARGET_TYPE (SYMBOL_TYPE (sym))) == 0
- && TYPE_CODE (TYPE_TARGET_TYPE (SYMBOL_TYPE (sym)))
- != TYPE_CODE_UNDEF)
+ && TYPE_TARGET_TYPE (SYMBOL_TYPE (sym))->code ()
+ != TYPE_CODE_UNDEF)
{
int i = hashname (sym->linkage_name ());
/* Some compilers try to be helpful by inventing "fake"
names for anonymous enums, structures, and unions, like
"~0fake" or ".0fake". Thanks, but no thanks... */
- if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0)
+ if (SYMBOL_TYPE (sym)->name () == 0)
if (sym->linkage_name () != NULL
&& *sym->linkage_name () != '~'
&& *sym->linkage_name () != '.')
- TYPE_NAME (SYMBOL_TYPE (sym)) = xstrdup (sym->linkage_name ());
+ SYMBOL_TYPE (sym)->set_name (xstrdup (sym->linkage_name ()));
add_symbol_to_list (sym, get_file_symbols ());
break;
union internal_auxent *aux,
struct objfile *objfile)
{
- struct gdbarch *gdbarch = get_objfile_arch (objfile);
+ struct gdbarch *gdbarch = objfile->arch ();
struct type *type;
switch (c_type)
{
/* Anonymous structure type. */
type = coff_alloc_type (cs->c_symnum);
- TYPE_CODE (type) = TYPE_CODE_STRUCT;
- TYPE_NAME (type) = NULL;
+ type->set_code (TYPE_CODE_STRUCT);
+ type->set_name (NULL);
INIT_CPLUS_SPECIFIC (type);
TYPE_LENGTH (type) = 0;
- TYPE_FIELDS (type) = 0;
- TYPE_NFIELDS (type) = 0;
+ type->set_fields (nullptr);
+ type->set_num_fields (0);
}
else
{
{
/* Anonymous union type. */
type = coff_alloc_type (cs->c_symnum);
- TYPE_NAME (type) = NULL;
+ type->set_name (NULL);
INIT_CPLUS_SPECIFIC (type);
TYPE_LENGTH (type) = 0;
- TYPE_FIELDS (type) = 0;
- TYPE_NFIELDS (type) = 0;
+ type->set_fields (nullptr);
+ type->set_num_fields (0);
}
else
{
aux->x_sym.x_fcnary.x_fcn.x_endndx.l,
objfile);
}
- TYPE_CODE (type) = TYPE_CODE_UNION;
+ type->set_code (TYPE_CODE_UNION);
return type;
case T_ENUM:
{
/* Anonymous enum type. */
type = coff_alloc_type (cs->c_symnum);
- TYPE_CODE (type) = TYPE_CODE_ENUM;
- TYPE_NAME (type) = NULL;
+ type->set_code (TYPE_CODE_ENUM);
+ type->set_name (NULL);
TYPE_LENGTH (type) = 0;
- TYPE_FIELDS (type) = 0;
- TYPE_NFIELDS (type) = 0;
+ type->set_fields (nullptr);
+ type->set_num_fields (0);
}
else
{
int done = 0;
type = coff_alloc_type (index);
- TYPE_CODE (type) = TYPE_CODE_STRUCT;
+ type->set_code (TYPE_CODE_STRUCT);
INIT_CPLUS_SPECIFIC (type);
TYPE_LENGTH (type) = length;
/* Save the data. */
list->field.name = obstack_strdup (&objfile->objfile_obstack, name);
- FIELD_TYPE (list->field) = decode_type (ms, ms->c_type,
- &sub_aux, objfile);
+ list->field.set_type (decode_type (ms, ms->c_type, &sub_aux,
+ objfile));
SET_FIELD_BITPOS (list->field, 8 * ms->c_value);
FIELD_BITSIZE (list->field) = 0;
nfields++;
/* Save the data. */
list->field.name = obstack_strdup (&objfile->objfile_obstack, name);
- FIELD_TYPE (list->field) = decode_type (ms, ms->c_type,
- &sub_aux, objfile);
+ list->field.set_type (decode_type (ms, ms->c_type, &sub_aux,
+ objfile));
SET_FIELD_BITPOS (list->field, ms->c_value);
FIELD_BITSIZE (list->field) = sub_aux.x_sym.x_misc.x_lnsz.x_size;
nfields++;
}
/* Now create the vector of fields, and record how big it is. */
- TYPE_NFIELDS (type) = nfields;
- TYPE_FIELDS (type) = (struct field *)
- TYPE_ALLOC (type, sizeof (struct field) * nfields);
+ type->set_num_fields (nfields);
+ type->set_fields
+ ((struct field *) TYPE_ALLOC (type, sizeof (struct field) * nfields));
/* Copy the saved-up fields into the field vector. */
for (n = nfields; list; list = list->next)
- TYPE_FIELD (type, --n) = list->field;
+ type->field (--n) = list->field;
return type;
}
coff_read_enum_type (int index, int length, int lastsym,
struct objfile *objfile)
{
- struct gdbarch *gdbarch = get_objfile_arch (objfile);
+ struct gdbarch *gdbarch = objfile->arch ();
struct symbol *sym;
struct type *type;
int nsyms = 0;
switch (ms->c_sclass)
{
case C_MOE:
- sym = allocate_symbol (objfile);
+ sym = new (&objfile->objfile_obstack) symbol;
name = obstack_strdup (&objfile->objfile_obstack, name);
sym->set_linkage_name (name);
TYPE_LENGTH (type) = length;
else /* Assume ints. */
TYPE_LENGTH (type) = gdbarch_int_bit (gdbarch) / TARGET_CHAR_BIT;
- TYPE_CODE (type) = TYPE_CODE_ENUM;
- TYPE_NFIELDS (type) = nsyms;
- TYPE_FIELDS (type) = (struct field *)
- TYPE_ALLOC (type, sizeof (struct field) * nsyms);
+ type->set_code (TYPE_CODE_ENUM);
+ type->set_num_fields (nsyms);
+ type->set_fields
+ ((struct field *) TYPE_ALLOC (type, sizeof (struct field) * nsyms));
/* Find the symbols for the values and put them into the type.
The symbols can be found in the symlist that we put them on
SYMBOL_TYPE (xsym) = type;
TYPE_FIELD_NAME (type, n) = xsym->linkage_name ();
- SET_FIELD_ENUMVAL (TYPE_FIELD (type, n), SYMBOL_VALUE (xsym));
+ SET_FIELD_ENUMVAL (type->field (n), SYMBOL_VALUE (xsym));
if (SYMBOL_VALUE (xsym) < 0)
unsigned_enum = 0;
TYPE_FIELD_BITSIZE (type, n) = 0;
}
if (unsigned_enum)
- TYPE_UNSIGNED (type) = 1;
+ type->set_is_unsigned (true);
return type;
}
for sym_read() */
coff_symfile_read, /* sym_read: read a symbol file into
symtab */
- NULL, /* sym_read_psymbols */
coff_symfile_finish, /* sym_finish: finished with file,
cleanup */
default_symfile_offsets, /* sym_offsets: xlate external to
default_symfile_relocate, /* sym_relocate: Relocate a debug
section. */
NULL, /* sym_probe_fns */
- &psym_functions
};
void _initialize_coffread ();