diff options
author | Tom Tromey <tromey@adacore.com> | 2023-01-13 08:57:08 -0700 |
---|---|---|
committer | Tom Tromey <tromey@adacore.com> | 2023-02-08 08:20:12 -0700 |
commit | b8a6e9878141f5f1ac6c790e85257eadd51fff8f (patch) | |
tree | 8016847c255500606857c94e63a1e38db594acd2 /gdb/mdebugread.c | |
parent | 3f01c12b9006227529823a07aee8a21627da63dd (diff) | |
download | binutils-b8a6e9878141f5f1ac6c790e85257eadd51fff8f.zip binutils-b8a6e9878141f5f1ac6c790e85257eadd51fff8f.tar.gz binutils-b8a6e9878141f5f1ac6c790e85257eadd51fff8f.tar.bz2 |
Set section indices when symbols are made
Most places in gdb that create a new symbol will apply a section
offset to the address. It seems to me that the choice of offset here
is also an implicit choice of the section. This is particularly true
if you examine fixup_section, which notes that it must be called
before such offsets are applied -- meaning that if any such call has
an effect, it's purely by accident.
This patch cleans up this area by tracking the section index and
applying it to a symbol when the address is set. This is done for
nearly every case -- the remaining cases will be handled in later
patches.
Diffstat (limited to 'gdb/mdebugread.c')
-rw-r--r-- | gdb/mdebugread.c | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/gdb/mdebugread.c b/gdb/mdebugread.c index 8dc836a..4feee39 100644 --- a/gdb/mdebugread.c +++ b/gdb/mdebugread.c @@ -597,6 +597,7 @@ parse_symbol (SYMR *sh, union aux_ext *ax, char *ext_sh, int bigend, else name = debug_info->ss + cur_fdr->issBase + sh->iss; + int section_index = -1; switch (sh->sc) { case scText: @@ -607,21 +608,24 @@ parse_symbol (SYMR *sh, union aux_ext *ax, char *ext_sh, int bigend, The value of a stBlock symbol is the displacement from the procedure address. */ if (sh->st != stEnd && sh->st != stBlock) - sh->value += section_offsets[SECT_OFF_TEXT (objfile)]; + section_index = SECT_OFF_TEXT (objfile); break; case scData: case scSData: case scRData: case scPData: case scXData: - sh->value += section_offsets[SECT_OFF_DATA (objfile)]; + section_index = SECT_OFF_DATA (objfile); break; case scBss: case scSBss: - sh->value += section_offsets[SECT_OFF_BSS (objfile)]; + section_index = SECT_OFF_BSS (objfile); break; } + if (section_index != -1) + sh->value += section_offsets[section_index]; + switch (sh->st) { case stNil: @@ -630,6 +634,7 @@ parse_symbol (SYMR *sh, union aux_ext *ax, char *ext_sh, int bigend, case stGlobal: /* External symbol, goes into global block. */ b = top_stack->cur_st->compunit ()->blockvector ()->global_block (); s = new_symbol (name); + s->set_section_index (section_index); s->set_value_address (sh->value); add_data_symbol (sh, ax, bigend, s, LOC_STATIC, b, objfile, name); break; @@ -647,7 +652,10 @@ parse_symbol (SYMR *sh, union aux_ext *ax, char *ext_sh, int bigend, global_sym_chain[bucket] = s; } else - s->set_value_address (sh->value); + { + s->set_section_index (section_index); + s->set_value_address (sh->value); + } add_data_symbol (sh, ax, bigend, s, LOC_STATIC, b, objfile, name); break; @@ -704,6 +712,7 @@ parse_symbol (SYMR *sh, union aux_ext *ax, char *ext_sh, int bigend, s = new_symbol (name); s->set_domain (VAR_DOMAIN); /* So that it can be used */ s->set_aclass_index (LOC_LABEL); /* but not misused. */ + s->set_section_index (section_index); s->set_value_address (sh->value); s->set_type (objfile_type (objfile)->builtin_int); add_symbol (s, top_stack->cur_st, top_stack->cur_block); @@ -745,6 +754,7 @@ parse_symbol (SYMR *sh, union aux_ext *ax, char *ext_sh, int bigend, s = new_symbol (name); s->set_domain (VAR_DOMAIN); s->set_aclass_index (LOC_BLOCK); + s->set_section_index (section_index); /* Type of the return value. */ if (SC_IS_UNDEF (sh->sc) || sh->sc == scNil) t = objfile_type (objfile)->builtin_int; |