From 1ee8702db9cb2a329c9df0938667e2415b0c9e46 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Sun, 19 Mar 2023 09:51:32 -0600 Subject: [PATCH] Use unrelocated_addr in psymbols This changes psymbols themselves to use unrelocated_addr. This transform is largely mechanical. I don't think it finds any bugs. --- gdb/ctfread.c | 12 ++++++++---- gdb/dbxread.c | 27 ++++++++++++++++++--------- gdb/mdebugread.c | 43 ++++++++++++++++++++++++++++--------------- gdb/psympriv.h | 12 ++++++------ gdb/psymtab.c | 5 +++-- gdb/symtab.h | 16 ++++++++++++++++ gdb/xcoffread.c | 23 ++++++++++++++--------- 7 files changed, 93 insertions(+), 45 deletions(-) diff --git a/gdb/ctfread.c b/gdb/ctfread.c index 41411abef2b..005862c1097 100644 --- a/gdb/ctfread.c +++ b/gdb/ctfread.c @@ -1291,7 +1291,8 @@ ctf_psymtab_add_enums (struct ctf_context *ccp, ctf_id_t tid) ccp->pst->add_psymbol (ename, true, VAR_DOMAIN, LOC_CONST, -1, psymbol_placement::GLOBAL, - 0, language_c, ccp->partial_symtabs, ccp->of); + unrelocated_addr (0), + language_c, ccp->partial_symtabs, ccp->of); } if (ctf_errno (ccp->fp) != ECTF_NEXT_END) complaint (_("ctf_enum_next ctf_psymtab_add_enums failed - %s"), @@ -1336,7 +1337,8 @@ ctf_psymtab_add_stt_entries (ctf_dict_t *cfp, ctf_psymtab *pst, pst->add_psymbol (tname, true, tdomain, aclass, -1, psymbol_placement::GLOBAL, - 0, language_c, pst->context.partial_symtabs, of); + unrelocated_addr (0), + language_c, pst->context.partial_symtabs, of); } } @@ -1513,7 +1515,8 @@ ctf_psymtab_type_cb (ctf_id_t tid, void *arg) ccp->pst->add_psymbol (name, false, domain, aclass, section, psymbol_placement::STATIC, - 0, language_c, ccp->partial_symtabs, ccp->of); + unrelocated_addr (0), + language_c, ccp->partial_symtabs, ccp->of); return 0; } @@ -1528,7 +1531,8 @@ ctf_psymtab_var_cb (const char *name, ctf_id_t id, void *arg) ccp->pst->add_psymbol (name, true, VAR_DOMAIN, LOC_STATIC, -1, psymbol_placement::GLOBAL, - 0, language_c, ccp->partial_symtabs, ccp->of); + unrelocated_addr (0), + language_c, ccp->partial_symtabs, ccp->of); return 0; } diff --git a/gdb/dbxread.c b/gdb/dbxread.c index 1ae527e9bf3..677e91d7725 100644 --- a/gdb/dbxread.c +++ b/gdb/dbxread.c @@ -1484,7 +1484,8 @@ read_dbx_symtab (minimal_symbol_reader &reader, VAR_DOMAIN, LOC_STATIC, data_sect_index, psymbol_placement::STATIC, - nlist.n_value, psymtab_language, + unrelocated_addr (nlist.n_value), + psymtab_language, partial_symtabs, objfile); else complaint (_("static `%*s' appears to be defined " @@ -1500,7 +1501,8 @@ read_dbx_symtab (minimal_symbol_reader &reader, VAR_DOMAIN, LOC_STATIC, data_sect_index, psymbol_placement::GLOBAL, - nlist.n_value, psymtab_language, + unrelocated_addr (nlist.n_value), + psymtab_language, partial_symtabs, objfile); else complaint (_("global `%*s' appears to be defined " @@ -1523,7 +1525,8 @@ read_dbx_symtab (minimal_symbol_reader &reader, pst->add_psymbol (gdb::string_view (sym_name, sym_len), true, STRUCT_DOMAIN, LOC_TYPEDEF, -1, psymbol_placement::STATIC, - 0, psymtab_language, + unrelocated_addr (0), + psymtab_language, partial_symtabs, objfile); else complaint (_("enum, struct, or union `%*s' appears " @@ -1537,7 +1540,8 @@ read_dbx_symtab (minimal_symbol_reader &reader, pst->add_psymbol (gdb::string_view (sym_name, sym_len), true, VAR_DOMAIN, LOC_TYPEDEF, -1, psymbol_placement::STATIC, - 0, psymtab_language, + unrelocated_addr (0), + psymtab_language, partial_symtabs, objfile); else complaint (_("typedef `%*s' appears to be defined " @@ -1555,7 +1559,8 @@ read_dbx_symtab (minimal_symbol_reader &reader, pst->add_psymbol (gdb::string_view (sym_name, sym_len), true, VAR_DOMAIN, LOC_TYPEDEF, -1, psymbol_placement::STATIC, - 0, psymtab_language, + unrelocated_addr (0), + psymtab_language, partial_symtabs, objfile); else complaint (_("typename `%*s' appears to be defined " @@ -1621,7 +1626,8 @@ read_dbx_symtab (minimal_symbol_reader &reader, if (pst != nullptr) pst->add_psymbol (gdb::string_view (p, q - p), true, VAR_DOMAIN, LOC_CONST, -1, - psymbol_placement::STATIC, 0, + psymbol_placement::STATIC, + unrelocated_addr (0), psymtab_language, partial_symtabs, objfile); else @@ -1645,7 +1651,8 @@ read_dbx_symtab (minimal_symbol_reader &reader, if (pst != nullptr) pst->add_psymbol (gdb::string_view (sym_name, sym_len), true, VAR_DOMAIN, LOC_CONST, -1, - psymbol_placement::STATIC, 0, + psymbol_placement::STATIC, + unrelocated_addr (0), psymtab_language, partial_symtabs, objfile); else @@ -1705,7 +1712,8 @@ read_dbx_symtab (minimal_symbol_reader &reader, VAR_DOMAIN, LOC_BLOCK, SECT_OFF_TEXT (objfile), psymbol_placement::STATIC, - nlist.n_value, psymtab_language, + unrelocated_addr (nlist.n_value), + psymtab_language, partial_symtabs, objfile); continue; @@ -1762,7 +1770,8 @@ read_dbx_symtab (minimal_symbol_reader &reader, VAR_DOMAIN, LOC_BLOCK, SECT_OFF_TEXT (objfile), psymbol_placement::GLOBAL, - nlist.n_value, psymtab_language, + unrelocated_addr (nlist.n_value), + psymtab_language, partial_symtabs, objfile); continue; diff --git a/gdb/mdebugread.c b/gdb/mdebugread.c index 4bcda4b9d74..e0415587646 100644 --- a/gdb/mdebugread.c +++ b/gdb/mdebugread.c @@ -3056,7 +3056,7 @@ parse_partial_symbols (minimal_symbol_reader &reader, true, VAR_DOMAIN, LOC_STATIC, SECT_OFF_DATA (objfile), psymbol_placement::STATIC, - sh.value, + unrelocated_addr (sh.value), psymtab_language, partial_symtabs, objfile); continue; @@ -3069,7 +3069,7 @@ parse_partial_symbols (minimal_symbol_reader &reader, true, VAR_DOMAIN, LOC_STATIC, SECT_OFF_DATA (objfile), psymbol_placement::GLOBAL, - sh.value, + unrelocated_addr (sh.value), psymtab_language, partial_symtabs, objfile); continue; @@ -3088,7 +3088,9 @@ parse_partial_symbols (minimal_symbol_reader &reader, pst->add_psymbol (gdb::string_view (namestring, p - namestring), true, STRUCT_DOMAIN, LOC_TYPEDEF, -1, - psymbol_placement::STATIC, 0, psymtab_language, + psymbol_placement::STATIC, + unrelocated_addr (0), + psymtab_language, partial_symtabs, objfile); if (p[2] == 't') { @@ -3097,7 +3099,8 @@ parse_partial_symbols (minimal_symbol_reader &reader, (gdb::string_view (namestring, p - namestring), true, VAR_DOMAIN, LOC_TYPEDEF, -1, - psymbol_placement::STATIC, 0, + psymbol_placement::STATIC, + unrelocated_addr (0), psymtab_language, partial_symtabs, objfile); p += 1; @@ -3112,7 +3115,9 @@ parse_partial_symbols (minimal_symbol_reader &reader, (gdb::string_view (namestring, p - namestring), true, VAR_DOMAIN, LOC_TYPEDEF, -1, - psymbol_placement::STATIC, 0, psymtab_language, + psymbol_placement::STATIC, + unrelocated_addr (0), + psymtab_language, partial_symtabs, objfile); } check_enum: @@ -3179,7 +3184,8 @@ parse_partial_symbols (minimal_symbol_reader &reader, true, VAR_DOMAIN, LOC_CONST, -1, psymbol_placement::STATIC, - 0, psymtab_language, + unrelocated_addr (0), + psymtab_language, partial_symtabs, objfile); /* Point past the name. */ p = q; @@ -3198,7 +3204,8 @@ parse_partial_symbols (minimal_symbol_reader &reader, p - namestring), true, VAR_DOMAIN, LOC_CONST, -1, psymbol_placement::STATIC, - 0, psymtab_language, + unrelocated_addr (0), + psymtab_language, partial_symtabs, objfile); continue; @@ -3214,7 +3221,7 @@ parse_partial_symbols (minimal_symbol_reader &reader, true, VAR_DOMAIN, LOC_BLOCK, SECT_OFF_TEXT (objfile), psymbol_placement::STATIC, - sh.value, + unrelocated_addr (sh.value), psymtab_language, partial_symtabs, objfile); continue; @@ -3235,7 +3242,7 @@ parse_partial_symbols (minimal_symbol_reader &reader, true, VAR_DOMAIN, LOC_BLOCK, SECT_OFF_TEXT (objfile), psymbol_placement::GLOBAL, - sh.value, + unrelocated_addr (sh.value), psymtab_language, partial_symtabs, objfile); continue; @@ -3475,14 +3482,16 @@ parse_partial_symbols (minimal_symbol_reader &reader, VAR_DOMAIN, LOC_BLOCK, section, psymbol_placement::GLOBAL, - sh.value, psymtab_language, + unrelocated_addr (sh.value), + psymtab_language, partial_symtabs, objfile); else pst->add_psymbol (sym_name, true, VAR_DOMAIN, LOC_BLOCK, section, psymbol_placement::STATIC, - sh.value, psymtab_language, + unrelocated_addr (sh.value), + psymtab_language, partial_symtabs, objfile); procaddr = unrelocated_addr (sh.value); @@ -3549,7 +3558,8 @@ parse_partial_symbols (minimal_symbol_reader &reader, pst->add_psymbol (sym_name, true, STRUCT_DOMAIN, LOC_TYPEDEF, -1, psymbol_placement::STATIC, - 0, psymtab_language, + unrelocated_addr (0), + psymtab_language, partial_symtabs, objfile); } handle_psymbol_enumerators (objfile, partial_symtabs, @@ -3591,7 +3601,8 @@ parse_partial_symbols (minimal_symbol_reader &reader, pst->add_psymbol (sym_name, true, VAR_DOMAIN, theclass, section, psymbol_placement::STATIC, - sh.value, psymtab_language, + unrelocated_addr (sh.value), + psymtab_language, partial_symtabs, objfile); skip: cur_sdx++; /* Go to next file symbol. */ @@ -3671,7 +3682,8 @@ parse_partial_symbols (minimal_symbol_reader &reader, VAR_DOMAIN, theclass, section, psymbol_placement::GLOBAL, - svalue, psymtab_language, + unrelocated_addr (svalue), + psymtab_language, partial_symtabs, objfile); } } @@ -3805,7 +3817,8 @@ handle_psymbol_enumerators (struct objfile *objfile, in psymtabs, just in symtabs. */ pst->add_psymbol (name, true, VAR_DOMAIN, LOC_CONST, -1, - psymbol_placement::STATIC, 0, + psymbol_placement::STATIC, + unrelocated_addr (0), psymtab_language, partial_symtabs, objfile); ext_sym += external_sym_size; } diff --git a/gdb/psympriv.h b/gdb/psympriv.h index 8fb595e2e0b..8f059dc5975 100644 --- a/gdb/psympriv.h +++ b/gdb/psympriv.h @@ -44,24 +44,24 @@ struct partial_symbol } /* Return the unrelocated address of this partial symbol. */ - CORE_ADDR unrelocated_address () const + unrelocated_addr unrelocated_address () const { - return ginfo.value_address (); + return ginfo.unrelocated_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 (ginfo.value_address () + return (CORE_ADDR (ginfo.unrelocated_address ()) + objfile->section_offsets[ginfo.section_index ()]); } /* Set the address of this partial symbol. The address must be unrelocated. */ - void set_unrelocated_address (CORE_ADDR addr) + void set_unrelocated_address (unrelocated_addr addr) { - ginfo.set_value_address (addr); + ginfo.set_unrelocated_address (addr); } /* Note that partial_symbol does not derive from general_symbol_info @@ -241,7 +241,7 @@ struct partial_symtab enum address_class theclass, short section, psymbol_placement where, - CORE_ADDR coreaddr, + unrelocated_addr coreaddr, enum language language, psymtab_storage *partial_symtabs, struct objfile *objfile); diff --git a/gdb/psymtab.c b/gdb/psymtab.c index 484199b4be2..c74280761dd 100644 --- a/gdb/psymtab.c +++ b/gdb/psymtab.c @@ -675,7 +675,8 @@ print_partial_symbols (struct gdbarch *gdbarch, struct objfile *objfile, break; } gdb_puts (", ", outfile); - gdb_puts (paddress (gdbarch, p->unrelocated_address ()), outfile); + gdb_puts (paddress (gdbarch, CORE_ADDR (p->unrelocated_address ())), + outfile); gdb_printf (outfile, "\n"); } } @@ -1212,7 +1213,7 @@ partial_symtab::add_psymbol (gdb::string_view name, bool copy_name, enum address_class theclass, short section, psymbol_placement where, - CORE_ADDR coreaddr, + unrelocated_addr coreaddr, enum language language, psymtab_storage *partial_symtabs, struct objfile *objfile) diff --git a/gdb/symtab.h b/gdb/symtab.h index 6834644ece1..d1ace398fe2 100644 --- a/gdb/symtab.h +++ b/gdb/symtab.h @@ -530,6 +530,18 @@ struct general_symbol_info m_value.address = address; } + /* Return the unrelocated address of this symbol. */ + unrelocated_addr unrelocated_address () const + { + return m_value.unrel_addr; + } + + /* Set the unrelocated address of this symbol. */ + void set_unrelocated_address (unrelocated_addr addr) + { + m_value.unrel_addr = addr; + } + /* Name of the symbol. This is a required field. Storage for the name is allocated on the objfile_obstack for the associated objfile. For languages like C++ that make a distinction between @@ -554,6 +566,10 @@ struct general_symbol_info CORE_ADDR address; + /* The address, if unrelocated. An unrelocated symbol does not + have the runtime section offset applied. */ + unrelocated_addr unrel_addr; + /* A common block. Used with LOC_COMMON_BLOCK. */ const struct common_block *common_block; diff --git a/gdb/xcoffread.c b/gdb/xcoffread.c index ff46cd50776..cbd427f8709 100644 --- a/gdb/xcoffread.c +++ b/gdb/xcoffread.c @@ -2499,7 +2499,7 @@ scan_xcoff_symtab (minimal_symbol_reader &reader, true, VAR_DOMAIN, LOC_STATIC, SECT_OFF_DATA (objfile), psymbol_placement::STATIC, - symbol.n_value, + unrelocated_addr (symbol.n_value), psymtab_language, partial_symtabs, objfile); continue; @@ -2512,7 +2512,7 @@ scan_xcoff_symtab (minimal_symbol_reader &reader, true, VAR_DOMAIN, LOC_STATIC, SECT_OFF_DATA (objfile), psymbol_placement::GLOBAL, - symbol.n_value, + unrelocated_addr (symbol.n_value), psymtab_language, partial_symtabs, objfile); continue; @@ -2532,7 +2532,8 @@ scan_xcoff_symtab (minimal_symbol_reader &reader, p - namestring), true, STRUCT_DOMAIN, LOC_TYPEDEF, -1, psymbol_placement::STATIC, - 0, psymtab_language, + unrelocated_addr (0), + psymtab_language, partial_symtabs, objfile); if (p[2] == 't') { @@ -2541,7 +2542,8 @@ scan_xcoff_symtab (minimal_symbol_reader &reader, p - namestring), true, VAR_DOMAIN, LOC_TYPEDEF, -1, psymbol_placement::STATIC, - 0, psymtab_language, + unrelocated_addr (0), + psymtab_language, partial_symtabs, objfile); p += 1; } @@ -2555,7 +2557,8 @@ scan_xcoff_symtab (minimal_symbol_reader &reader, p - namestring), true, VAR_DOMAIN, LOC_TYPEDEF, -1, psymbol_placement::STATIC, - 0, psymtab_language, + unrelocated_addr (0), + psymtab_language, partial_symtabs, objfile); } check_enum: @@ -2618,7 +2621,8 @@ scan_xcoff_symtab (minimal_symbol_reader &reader, pst->add_psymbol (gdb::string_view (p, q - p), true, VAR_DOMAIN, LOC_CONST, -1, psymbol_placement::STATIC, - 0, psymtab_language, + unrelocated_addr (0), + psymtab_language, partial_symtabs, objfile); /* Point past the name. */ p = q; @@ -2638,7 +2642,8 @@ scan_xcoff_symtab (minimal_symbol_reader &reader, p - namestring), true, VAR_DOMAIN, LOC_CONST, -1, psymbol_placement::STATIC, - 0, psymtab_language, + unrelocated_addr (0), + psymtab_language, partial_symtabs, objfile); continue; @@ -2653,7 +2658,7 @@ scan_xcoff_symtab (minimal_symbol_reader &reader, true, VAR_DOMAIN, LOC_BLOCK, SECT_OFF_TEXT (objfile), psymbol_placement::STATIC, - symbol.n_value, + unrelocated_addr (symbol.n_value), psymtab_language, partial_symtabs, objfile); continue; @@ -2680,7 +2685,7 @@ scan_xcoff_symtab (minimal_symbol_reader &reader, true, VAR_DOMAIN, LOC_BLOCK, SECT_OFF_TEXT (objfile), psymbol_placement::GLOBAL, - symbol.n_value, + unrelocated_addr (symbol.n_value), psymtab_language, partial_symtabs, objfile); continue; -- 2.30.2