/* stabs.c -- Parse COFF debugging information
- Copyright (C) 1996-2022 Free Software Foundation, Inc.
+ Copyright (C) 1996-2023 Free Software Foundation, Inc.
Written by Ian Lance Taylor <ian@cygnus.com>.
This file is part of GNU Binutils.
long coff_symno;
};
-/* The largest basic type we are prepared to handle. */
-
-#define T_MAX (T_LNGDBL)
-
-/* This structure is used to hold slots. */
-
-struct coff_slots
-{
- /* Next set of slots. */
- struct coff_slots *next;
- /* Slots. */
-#define COFF_SLOTS (16)
- debug_type slots[COFF_SLOTS];
-};
-
/* This structure is used to map symbol indices to types. */
struct coff_types
{
+ /* Next set of slots. */
+ struct coff_types *next;
+ /* Where the TYPES array starts. */
+ unsigned int base_index;
/* Slots. */
- struct coff_slots *slots;
- /* Basic types. */
- debug_type basic[T_MAX + 1];
+#define COFF_SLOTS (16)
+ debug_type types[COFF_SLOTS];
};
-static debug_type *coff_get_slot (struct coff_types *, long);
-static debug_type parse_coff_type
- (bfd *, struct coff_symbols *, struct coff_types *, long, int,
- union internal_auxent *, bool, void *);
static debug_type parse_coff_base_type
- (bfd *, struct coff_symbols *, struct coff_types *, long, int,
+ (bfd *, struct coff_symbols *, struct coff_types **, long, int,
union internal_auxent *, void *);
static debug_type parse_coff_struct_type
- (bfd *, struct coff_symbols *, struct coff_types *, int,
+ (bfd *, struct coff_symbols *, struct coff_types **, int,
union internal_auxent *, void *);
static debug_type parse_coff_enum_type
- (bfd *, struct coff_symbols *, struct coff_types *,
+ (bfd *, struct coff_symbols *, struct coff_types **,
union internal_auxent *, void *);
-static bool parse_coff_symbol
- (bfd *, struct coff_types *, asymbol *, long, struct internal_syment *,
- void *, debug_type, bool);
-static bool external_coff_symbol_p (int sym_class);
\f
/* Return the slot for a type. */
static debug_type *
-coff_get_slot (struct coff_types *types, long indx)
+coff_get_slot (void *dhandle, struct coff_types **types, long indx)
{
- struct coff_slots **pps;
+ unsigned int base_index;
- pps = &types->slots;
+ base_index = indx / COFF_SLOTS * COFF_SLOTS;
+ indx -= base_index;
- /* PR 17512: file: 078-18333-0.001:0.1.
- FIXME: The value of 1000 is a guess. Maybe a better heuristic is needed. */
- if (indx / COFF_SLOTS > 1000)
- fatal (_("Excessively large slot index: %lx"), indx);
+ while (*types && (*types)->base_index < base_index)
+ types = &(*types)->next;
- while (indx >= COFF_SLOTS)
+ if (*types == NULL || (*types)->base_index != base_index)
{
- if (*pps == NULL)
- {
- *pps = (struct coff_slots *) xmalloc (sizeof **pps);
- memset (*pps, 0, sizeof **pps);
- }
- pps = &(*pps)->next;
- indx -= COFF_SLOTS;
+ struct coff_types *n = debug_xzalloc (dhandle, sizeof (*n));
+ n->next = *types;
+ n->base_index = base_index;
+ *types = n;
}
- if (*pps == NULL)
- {
- *pps = (struct coff_slots *) xmalloc (sizeof **pps);
- memset (*pps, 0, sizeof **pps);
- }
-
- return (*pps)->slots + indx;
+ return (*types)->types + indx;
}
/* Parse a COFF type code in NTYPE. */
static debug_type
parse_coff_type (bfd *abfd, struct coff_symbols *symbols,
- struct coff_types *types, long coff_symno, int ntype,
+ struct coff_types **types, long coff_symno, int ntype,
union internal_auxent *pauxent, bool useaux,
void *dhandle)
{
return type;
}
- if (pauxent != NULL && pauxent->x_sym.x_tagndx.l > 0)
+ if (pauxent != NULL && (int32_t) pauxent->x_sym.x_tagndx.u32 > 0)
{
debug_type *slot;
/* This is a reference to an existing type. FIXME: gdb checks
that the class is not C_STRTAG, nor C_UNTAG, nor C_ENTAG. */
- slot = coff_get_slot (types, pauxent->x_sym.x_tagndx.l);
+ slot = coff_get_slot (dhandle, types, pauxent->x_sym.x_tagndx.u32);
if (*slot != DEBUG_TYPE_NULL)
return *slot;
else
static debug_type
parse_coff_base_type (bfd *abfd, struct coff_symbols *symbols,
- struct coff_types *types, long coff_symno, int ntype,
+ struct coff_types **types, long coff_symno, int ntype,
union internal_auxent *pauxent, void *dhandle)
{
debug_type ret;
- bool set_basic;
- const char *name;
- debug_type *slot;
-
- if (ntype >= 0
- && ntype <= T_MAX
- && types->basic[ntype] != DEBUG_TYPE_NULL)
- return types->basic[ntype];
-
- set_basic = true;
- name = NULL;
+ const char *name = NULL;
switch (ntype)
{
else
ret = parse_coff_struct_type (abfd, symbols, types, ntype, pauxent,
dhandle);
-
- slot = coff_get_slot (types, coff_symno);
- *slot = ret;
-
- set_basic = false;
break;
case T_UNION:
else
ret = parse_coff_struct_type (abfd, symbols, types, ntype, pauxent,
dhandle);
-
- slot = coff_get_slot (types, coff_symno);
- *slot = ret;
-
- set_basic = false;
break;
case T_ENUM:
(bfd_signed_vma *) NULL);
else
ret = parse_coff_enum_type (abfd, symbols, types, pauxent, dhandle);
-
- slot = coff_get_slot (types, coff_symno);
- *slot = ret;
-
- set_basic = false;
break;
}
if (name != NULL)
ret = debug_name_type (dhandle, name, ret);
- if (set_basic
- && ntype >= 0
- && ntype <= T_MAX)
- types->basic[ntype] = ret;
+ debug_type *slot = coff_get_slot (dhandle, types, coff_symno);
+ *slot = ret;
return ret;
}
static debug_type
parse_coff_struct_type (bfd *abfd, struct coff_symbols *symbols,
- struct coff_types *types, int ntype,
+ struct coff_types **types, int ntype,
union internal_auxent *pauxent, void *dhandle)
{
long symend;
int alloc;
- debug_field *fields;
+ debug_field *fields, *xfields;
int count;
bool done;
- symend = pauxent->x_sym.x_fcnary.x_fcn.x_endndx.l;
+ symend = pauxent->x_sym.x_fcnary.x_fcn.x_endndx.u32;
alloc = 10;
fields = (debug_field *) xmalloc (alloc * sizeof *fields);
case C_FIELD:
bitpos = bfd_asymbol_value (sym);
- bitsize = auxent.x_sym.x_misc.x_lnsz.x_size;
+ if (psubaux != NULL)
+ bitsize = psubaux->x_sym.x_misc.x_lnsz.x_size;
break;
case C_EOS:
f = debug_make_field (dhandle, bfd_asymbol_name (sym), ftype,
bitpos, bitsize, DEBUG_VISIBILITY_PUBLIC);
if (f == DEBUG_FIELD_NULL)
- return DEBUG_TYPE_NULL;
+ {
+ free (fields);
+ return DEBUG_TYPE_NULL;
+ }
if (count + 1 >= alloc)
{
}
fields[count] = DEBUG_FIELD_NULL;
+ xfields = debug_xalloc (dhandle, (count + 1) * sizeof (*fields));
+ memcpy (xfields, fields, (count + 1) * sizeof (*fields));
+ free (fields);
return debug_make_struct_type (dhandle, ntype == T_STRUCT,
pauxent->x_sym.x_misc.x_lnsz.x_size,
- fields);
+ xfields);
}
/* Parse an enum type. */
static debug_type
parse_coff_enum_type (bfd *abfd, struct coff_symbols *symbols,
- struct coff_types *types ATTRIBUTE_UNUSED,
+ struct coff_types **types ATTRIBUTE_UNUSED,
union internal_auxent *pauxent, void *dhandle)
{
long symend;
int alloc;
- const char **names;
- bfd_signed_vma *vals;
+ const char **names, **xnames;
+ bfd_signed_vma *vals, *xvals;
int count;
bool done;
- symend = pauxent->x_sym.x_fcnary.x_fcn.x_endndx.l;
+ symend = pauxent->x_sym.x_fcnary.x_fcn.x_endndx.u32;
alloc = 10;
names = (const char **) xmalloc (alloc * sizeof *names);
}
names[count] = NULL;
-
- return debug_make_enum_type (dhandle, names, vals);
+ vals[count] = 0;
+ xnames = debug_xalloc (dhandle, (count + 1) * sizeof (*names));
+ memcpy (xnames, names, (count + 1) * sizeof (*names));
+ free (names);
+ xvals = debug_xalloc (dhandle, (count + 1) * sizeof (*vals));
+ memcpy (xvals, vals, (count + 1) * sizeof (*vals));
+ free (vals);
+
+ return debug_make_enum_type (dhandle, xnames, xvals);
}
/* Handle a single COFF symbol. */
static bool
-parse_coff_symbol (bfd *abfd ATTRIBUTE_UNUSED, struct coff_types *types,
+parse_coff_symbol (bfd *abfd ATTRIBUTE_UNUSED, struct coff_types **types,
asymbol *sym, long coff_symno,
struct internal_syment *psyment, void *dhandle,
debug_type type, bool within_function)
/* Store the named type into the slot, so that references get
the name. */
- slot = coff_get_slot (types, coff_symno);
+ slot = coff_get_slot (dhandle, types, coff_symno);
*slot = type;
}
break;
parse_coff (bfd *abfd, asymbol **syms, long symcount, void *dhandle)
{
struct coff_symbols symbols;
- struct coff_types types;
- int i;
+ struct coff_types *types;
long next_c_file;
const char *fnname;
int fnclass;
symbols.symno = 0;
symbols.coff_symno = 0;
- types.slots = NULL;
- for (i = 0; i <= T_MAX; i++)
- types.basic[i] = DEBUG_TYPE_NULL;
+ types= NULL;
next_c_file = -1;
fnname = NULL;