From 02e9e7f7e2bed3b82cb6541f566caf07256b9b2f Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Thu, 3 May 2018 16:36:18 -0600 Subject: [PATCH 1/1] Introduce partial_symbol::address This introduces a partial_symbol::address method. This method takes an objfile argument. This is necessary so that we can later relocate a partial symbol at its point of use. It also adds an accessor to compute the unrelocated value; and a method to be used for setting the field. Note that the new method doesn't actually perform any relocation yet. That will come in a subsequent patch. However, the comments are written to reflect the intended, rather than the temporary, semantics. gdb/ChangeLog 2018-07-26 Tom Tromey * psympriv.h (struct partial_symbol) : New methods. * psymtab.c (find_pc_sect_psymtab_closer, find_pc_sect_psymbol) (fixup_psymbol_section, relocate_psymtabs): Update. (print_partial_symbols): Add 'objfile' parameter. Update. (dump_psymtab, add_psymbol_to_bcache, psym_fill_psymbol_map): Update. --- gdb/ChangeLog | 10 ++++++++++ gdb/psympriv.h | 20 ++++++++++++++++++++ gdb/psymtab.c | 43 +++++++++++++++++++++++-------------------- 3 files changed, 53 insertions(+), 20 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index c6df5ebec7..8c6471b9a9 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,13 @@ +2018-07-26 Tom Tromey + + * psympriv.h (struct partial_symbol) : New methods. + * psymtab.c (find_pc_sect_psymtab_closer, find_pc_sect_psymbol) + (fixup_psymbol_section, relocate_psymtabs): Update. + (print_partial_symbols): Add 'objfile' parameter. Update. + (dump_psymtab, add_psymbol_to_bcache, psym_fill_psymbol_map): + Update. + 2018-07-26 Tom Tromey * dwarf-index-write.c (write_psymbols, debug_names::insert) diff --git a/gdb/psympriv.h b/gdb/psympriv.h index f3cb0a6ba1..be574bf8b7 100644 --- a/gdb/psympriv.h +++ b/gdb/psympriv.h @@ -44,6 +44,26 @@ struct partial_symbol : public general_symbol_info return nullptr; } + /* Return the unrelocated address of this partial symbol. */ + CORE_ADDR unrelocated_address () const + { + return value.address; + } + + /* Return the address of this partial symbol, relocated according to + the offsets provided in OBJFILE. */ + CORE_ADDR address (const struct objfile *objfile) const + { + return value.address; + } + + /* Set the address of this partial symbol. The address must be + unrelocated. */ + void set_address (CORE_ADDR addr) + { + value.address = addr; + } + /* Name space code. */ ENUM_BITFIELD(domain_enum_tag) domain : SYMBOL_DOMAIN_BITS; diff --git a/gdb/psymtab.c b/gdb/psymtab.c index 9a06d68f91..f144fa3396 100644 --- a/gdb/psymtab.c +++ b/gdb/psymtab.c @@ -267,7 +267,7 @@ find_pc_sect_psymtab_closer (struct objfile *objfile, object's symbol table. */ p = find_pc_sect_psymbol (objfile, tpst, pc, section); if (p != NULL - && (p->value.address == BMSYMBOL_VALUE_ADDRESS (msymbol))) + && (p->address (objfile) == BMSYMBOL_VALUE_ADDRESS (msymbol))) return tpst; /* Also accept the textlow value of a psymtab as a @@ -275,7 +275,7 @@ find_pc_sect_psymtab_closer (struct objfile *objfile, symbol tables with line information but no debug symbols (e.g. those produced by an assembler). */ if (p != NULL) - this_addr = p->value.address; + this_addr = p->address (objfile); else this_addr = tpst->textlow; @@ -333,7 +333,8 @@ find_pc_sect_psymtab (struct objfile *objfile, CORE_ADDR pc, object's symbol table. */ p = find_pc_sect_psymbol (objfile, pst, pc, section); if (p == NULL - || (p->value.address != BMSYMBOL_VALUE_ADDRESS (msymbol))) + || (p->address (objfile) + != BMSYMBOL_VALUE_ADDRESS (msymbol))) goto next; } @@ -425,10 +426,10 @@ find_pc_sect_psymbol (struct objfile *objfile, if (p->domain == VAR_DOMAIN && p->aclass == LOC_BLOCK - && pc >= p->value.address - && (p->value.address > best_pc + && pc >= p->address (objfile) + && (p->address (objfile) > best_pc || (psymtab->textlow == 0 - && best_pc == 0 && p->value.address == 0))) + && best_pc == 0 && p->address (objfile) == 0))) { if (section != NULL) /* Match on a specific section. */ { @@ -437,7 +438,7 @@ find_pc_sect_psymbol (struct objfile *objfile, section)) continue; } - best_pc = p->value.address; + best_pc = p->address (objfile); best = p; } } @@ -448,10 +449,10 @@ find_pc_sect_psymbol (struct objfile *objfile, if (p->domain == VAR_DOMAIN && p->aclass == LOC_BLOCK - && pc >= p->value.address - && (p->value.address > best_pc + && pc >= p->address (objfile) + && (p->address (objfile) > best_pc || (psymtab->textlow == 0 - && best_pc == 0 && p->value.address == 0))) + && best_pc == 0 && p->address (objfile) == 0))) { if (section != NULL) /* Match on a specific section. */ { @@ -460,7 +461,7 @@ find_pc_sect_psymbol (struct objfile *objfile, section)) continue; } - best_pc = p->value.address; + best_pc = p->address (objfile); best = p; } } @@ -486,7 +487,7 @@ fixup_psymbol_section (struct partial_symbol *psym, struct objfile *objfile) case LOC_STATIC: case LOC_LABEL: case LOC_BLOCK: - addr = psym->value.address; + addr = psym->address (objfile); break; default: /* Nothing else will be listed in the minsyms -- no use looking @@ -813,13 +814,15 @@ psym_relocate (struct objfile *objfile, { fixup_psymbol_section (psym, objfile); if (psym->section >= 0) - psym->value.address += ANOFFSET (delta, psym->section); + psym->set_address (psym->unrelocated_address () + + ANOFFSET (delta, psym->section)); } for (partial_symbol *psym : objfile->static_psymbols) { fixup_psymbol_section (psym, objfile); if (psym->section >= 0) - psym->value.address += ANOFFSET (delta, psym->section); + psym->set_address (psym->unrelocated_address () + + ANOFFSET (delta, psym->section)); } objfile->psymbol_map.clear (); @@ -883,7 +886,7 @@ psym_forget_cached_source_info (struct objfile *objfile) } static void -print_partial_symbols (struct gdbarch *gdbarch, +print_partial_symbols (struct gdbarch *gdbarch, struct objfile *objfile, struct partial_symbol **p, int count, const char *what, struct ui_file *outfile) { @@ -967,7 +970,7 @@ print_partial_symbols (struct gdbarch *gdbarch, break; } fputs_filtered (", ", outfile); - fputs_filtered (paddress (gdbarch, (*p)->value.address), outfile); + fputs_filtered (paddress (gdbarch, (*p)->unrelocated_address ()), outfile); fprintf_filtered (outfile, "\n"); p++; } @@ -1032,13 +1035,13 @@ dump_psymtab (struct objfile *objfile, struct partial_symtab *psymtab, } if (psymtab->n_global_syms > 0) { - print_partial_symbols (gdbarch, + print_partial_symbols (gdbarch, objfile, &objfile->global_psymbols[psymtab->globals_offset], psymtab->n_global_syms, "Global", outfile); } if (psymtab->n_static_syms > 0) { - print_partial_symbols (gdbarch, + print_partial_symbols (gdbarch, objfile, &objfile->static_psymbols[psymtab->statics_offset], psymtab->n_static_syms, "Static", outfile); } @@ -1475,7 +1478,7 @@ psym_fill_psymbol_map (struct objfile *objfile, if (psym->aclass == LOC_STATIC) { - CORE_ADDR addr = psym->value.address; + CORE_ADDR addr = psym->address (objfile); if (seen_addrs->find (addr) == seen_addrs->end ()) { seen_addrs->insert (addr); @@ -1718,7 +1721,7 @@ add_psymbol_to_bcache (const char *name, int namelength, int copy_name, { struct partial_symbol psymbol; - psymbol.value.address = coreaddr; + psymbol.set_address (coreaddr); psymbol.section = -1; psymbol.domain = domain; psymbol.aclass = theclass; -- 2.34.1