diff options
author | Alan Modra <amodra@gmail.com> | 2023-03-03 11:15:35 +1030 |
---|---|---|
committer | Alan Modra <amodra@gmail.com> | 2023-03-03 12:31:24 +1030 |
commit | 945efa5c538d3967857ff9fa42e763577534c36d (patch) | |
tree | 12f92678fd499143a6c9be13f74bc5e1d06becef /binutils/rdcoff.c | |
parent | de357ff4e4f8fa7aaf621d680fde72a010b026d2 (diff) | |
download | gdb-945efa5c538d3967857ff9fa42e763577534c36d.zip gdb-945efa5c538d3967857ff9fa42e763577534c36d.tar.gz gdb-945efa5c538d3967857ff9fa42e763577534c36d.tar.bz2 |
Tidy type handling in binutils/rdcoff.c
There isn't really any good reason for code in rdcoff.c to distinguish
between "basic" types and any other type. This patch dispenses with
the array reserved for basic types and instead handles all types using
coff_get_slot, simplifying the code.
* rdcoff.c (struct coff_types, coff_slots): Merge. Delete
coff_slots.
(T_MAX): Delete.
(parse_coff_base_type): Use coff_get_slot to store baseic types.
(coff_get_slot, parse_coff_type, parse_coff_base_type),
(parse_coff_struct_type, parse_coff_enum_type),
(parse_coff_symbol, parse_coff): Pass types as coff_types**.
Diffstat (limited to 'binutils/rdcoff.c')
-rw-r--r-- | binutils/rdcoff.c | 106 |
1 files changed, 26 insertions, 80 deletions
diff --git a/binutils/rdcoff.c b/binutils/rdcoff.c index 1a4f00d..4d18d47 100644 --- a/binutils/rdcoff.c +++ b/binutils/rdcoff.c @@ -58,82 +58,58 @@ struct coff_symbols long coff_symno; }; -/* The largest basic type we are prepared to handle. */ - -#define T_MAX (T_LNGDBL) - -/* This structure is used to hold slots. */ +/* This structure is used to map symbol indices to types. */ -struct coff_slots +struct coff_types { /* Next set of slots. */ - struct coff_slots *next; - /* Where the SLOTS array starts. */ + struct coff_types *next; + /* Where the TYPES array starts. */ unsigned int base_index; /* Slots. */ #define COFF_SLOTS (16) - debug_type slots[COFF_SLOTS]; + debug_type types[COFF_SLOTS]; }; -/* This structure is used to map symbol indices to types. */ - -struct coff_types -{ - /* Slots. */ - struct coff_slots *slots; - /* Basic types. */ - debug_type basic[T_MAX + 1]; -}; - -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); /* Return the slot for a type. */ static debug_type * -coff_get_slot (struct coff_types *types, long indx) +coff_get_slot (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; - while (*pps && (*pps)->base_index < base_index) - pps = &(*pps)->next; + while (*types && (*types)->base_index < base_index) + types = &(*types)->next; - if (*pps == NULL || (*pps)->base_index != base_index) + if (*types == NULL || (*types)->base_index != base_index) { - struct coff_slots *n = xcalloc (1, sizeof (*n)); - n->next = *pps; + struct coff_types *n = xcalloc (1, sizeof (*n)); + n->next = *types; n->base_index = base_index; - *pps = n; + *types = n; } - 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) { @@ -230,21 +206,11 @@ parse_coff_type (bfd *abfd, struct coff_symbols *symbols, 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) { @@ -321,11 +287,6 @@ parse_coff_base_type (bfd *abfd, struct coff_symbols *symbols, 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: @@ -334,11 +295,6 @@ parse_coff_base_type (bfd *abfd, struct coff_symbols *symbols, 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: @@ -347,21 +303,14 @@ parse_coff_base_type (bfd *abfd, struct coff_symbols *symbols, (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 (types, coff_symno); + *slot = ret; return ret; } @@ -370,7 +319,7 @@ parse_coff_base_type (bfd *abfd, struct coff_symbols *symbols, 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; @@ -479,7 +428,7 @@ parse_coff_struct_type (bfd *abfd, struct coff_symbols *symbols, 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; @@ -549,7 +498,7 @@ parse_coff_enum_type (bfd *abfd, struct coff_symbols *symbols, /* 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) @@ -657,8 +606,7 @@ bool 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; @@ -673,9 +621,7 @@ parse_coff (bfd *abfd, asymbol **syms, long symcount, void *dhandle) 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; |