From 6a053cb1ff643cec3349d7f2f47ae5573f82d613 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Mon, 6 Jan 2020 14:34:52 -0700 Subject: [PATCH] Change section_offsets to a std::vector This changes section_offsets to be specialization of a std::vector and updates all the users. It also removes the ANOFFSET and SIZEOF_N_SECTION_OFFSETS macros. Most of this is just a generic sort of cleanup, that reduces the number of lines of code. However, a couple spots were doing weird things. objfile_relocate did: - std::vector - new_debug_offsets (SIZEOF_N_SECTION_OFFSETS (debug_objfile->num_sections)); ... which seems to greatly over-estimate the number of elements needed. This appeared in set_objfile_default_section_offset: - std::vector offsets (objf->num_sections, - { { offset } }); ... which makes sense due to type safety, but is also actively confusing given that section_offsets was previously also a kind of vector type. Tested on x86-64 Fedora 30. gdb/ChangeLog 2020-01-08 Tom Tromey * xcoffread.c (enter_line_range, read_xcoff_symtab) (process_xcoff_symbol, xcoff_symfile_offsets): Update. * symtab.h (MSYMBOL_VALUE_ADDRESS): Update. (struct section_offsets, ANOFFSET, SIZEOF_N_SECTION_OFFSETS): Remove. (section_offsets): New typedef. * symtab.c (fixup_section, get_msymbol_address): Update. * symmisc.c (dump_msymbols): Update. * symfile.h (relative_addr_info_to_section_offsets) (symfile_map_offsets_to_segments): Update. * symfile.c (build_section_addr_info_from_objfile) (init_objfile_sect_indices): Update. (struct place_section_arg): Change type of "offsets". (place_section): Update. (relative_addr_info_to_section_offsets): Change type of "section_offsets". Remove "num_sections" parameter. (default_symfile_offsets, syms_from_objfile_1) (set_objfile_default_section_offset): Update. (reread_symbols): No need to preserve section offsets by hand. (symfile_map_offsets_to_segments): Change type of "offsets". * stap-probe.c (relocate_address): Update. * stabsread.h (process_one_symbol): Update. * solib-target.c (struct lm_info_target) : Change type. (solib_target_relocate_section_addresses): Update. * solib-svr4.c (enable_break, svr4_relocate_main_executable): Update. * solib-frv.c (frv_relocate_main_executable): Update. * solib-dsbt.c (dsbt_relocate_main_executable): Update. * solib-aix.c (solib_aix_get_section_offsets): Change return type. (solib_aix_solib_create_inferior_hook): Update. * remote.c (remote_target::get_offsets): Update. * psymtab.c (find_pc_sect_psymtab): Update. * psympriv.h (struct partial_symbol) : Update. * objfiles.h (obj_section_offset): Update. (struct objfile) : Change type. : Remove. (objfile_relocate): Update. * objfiles.c (entry_point_address_query): Update (relocate_one_symbol): Change type of "section_offsets". (objfile_relocate1, objfile_relocate1): Change type of "new_offsets". (objfile_rebase1): Update. * mipsread.c (mipscoff_symfile_read): Update. (read_alphacoff_dynamic_symtab): Remove "section_offsets" parameter. * mdebugread.c (parse_symbol): Change type of "section_offsets". (parse_external, psymtab_to_symtab_1): Update. * machoread.c (macho_symfile_offsets): Update. * ia64-tdep.c (ia64_find_unwind_table): Update. * hppa-tdep.c (read_unwind_info): Update. * hppa-bsd-tdep.c (hppabsd_find_global_pointer): Update. * dwarf2read.c (create_addrmap_from_index) (create_addrmap_from_aranges, dw2_find_pc_sect_compunit_symtab) (process_psymtab_comp_unit_reader, add_partial_symbol) (add_partial_subprogram, process_full_comp_unit) (read_file_scope, read_func_scope, read_lexical_block_scope) (read_call_site_scope, dwarf2_rnglists_process) (dwarf2_ranges_process, dwarf2_ranges_read) (dwarf_decode_lines_1, var_decode_location, new_symbol) (dwarf2_fetch_die_loc_sect_off, dwarf2_per_cu_text_offset): Update. * dwarf2-frame.c (execute_cfa_program, dwarf2_frame_find_fde): Update. * dtrace-probe.c (dtrace_probe::get_relocated_address): Update. * dbxread.c (read_dbx_symtab, read_ofile_symtab): Update. (process_one_symbol): Change type of "section_offsets". * ctfread.c (get_objfile_text_range): Update. * coffread.c (coff_symtab_read, enter_linenos) (process_coff_symbol): Update. * coff-pe-read.c (add_pe_forwarded_sym): Update. * amd64-windows-tdep.c (amd64_windows_find_unwind_info): Update. Change-Id: I147eb967e9b44d82f4048039de7bb44b80cd72fb --- gdb/ChangeLog | 76 ++++++++++++++++++++++++++++++++++++++++ gdb/amd64-windows-tdep.c | 4 +-- gdb/coff-pe-read.c | 2 +- gdb/coffread.c | 30 +++++++--------- gdb/ctfread.c | 2 +- gdb/dbxread.c | 30 +++++++--------- gdb/dtrace-probe.c | 4 +-- gdb/dwarf2-frame.c | 7 ++-- gdb/dwarf2read.c | 49 ++++++++++++-------------- gdb/hppa-bsd-tdep.c | 3 +- gdb/hppa-tdep.c | 2 +- gdb/ia64-tdep.c | 2 +- gdb/machoread.c | 7 +--- gdb/mdebugread.c | 24 +++++-------- gdb/mipsread.c | 4 +-- gdb/objfiles.c | 65 +++++++++++++--------------------- gdb/objfiles.h | 8 ++--- gdb/psympriv.h | 9 ++--- gdb/psymtab.c | 3 +- gdb/remote.c | 12 +++---- gdb/solib-aix.c | 22 +++++------- gdb/solib-dsbt.c | 11 +++--- gdb/solib-frv.c | 11 +++--- gdb/solib-svr4.c | 14 ++------ gdb/solib-target.c | 16 ++++----- gdb/stabsread.h | 2 +- gdb/stap-probe.c | 3 +- gdb/symfile.c | 76 ++++++++++++---------------------------- gdb/symfile.h | 5 ++- gdb/symmisc.c | 3 +- gdb/symtab.c | 14 ++++---- gdb/symtab.h | 25 ++----------- gdb/xcoffread.c | 24 +++++-------- 33 files changed, 255 insertions(+), 314 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 9733a106222..b10989a410d 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,79 @@ +2020-01-08 Tom Tromey + + * xcoffread.c (enter_line_range, read_xcoff_symtab) + (process_xcoff_symbol, xcoff_symfile_offsets): Update. + * symtab.h (MSYMBOL_VALUE_ADDRESS): Update. + (struct section_offsets, ANOFFSET, SIZEOF_N_SECTION_OFFSETS): + Remove. + (section_offsets): New typedef. + * symtab.c (fixup_section, get_msymbol_address): Update. + * symmisc.c (dump_msymbols): Update. + * symfile.h (relative_addr_info_to_section_offsets) + (symfile_map_offsets_to_segments): Update. + * symfile.c (build_section_addr_info_from_objfile) + (init_objfile_sect_indices): Update. + (struct place_section_arg): Change type of "offsets". + (place_section): Update. + (relative_addr_info_to_section_offsets): Change type of + "section_offsets". Remove "num_sections" parameter. + (default_symfile_offsets, syms_from_objfile_1) + (set_objfile_default_section_offset): Update. + (reread_symbols): No need to preserve section offsets by hand. + (symfile_map_offsets_to_segments): Change type of "offsets". + * stap-probe.c (relocate_address): Update. + * stabsread.h (process_one_symbol): Update. + * solib-target.c (struct lm_info_target) : Change type. + (solib_target_relocate_section_addresses): Update. + * solib-svr4.c (enable_break, svr4_relocate_main_executable): + Update. + * solib-frv.c (frv_relocate_main_executable): Update. + * solib-dsbt.c (dsbt_relocate_main_executable): Update. + * solib-aix.c (solib_aix_get_section_offsets): Change return + type. + (solib_aix_solib_create_inferior_hook): Update. + * remote.c (remote_target::get_offsets): Update. + * psymtab.c (find_pc_sect_psymtab): Update. + * psympriv.h (struct partial_symbol) : Update. + * objfiles.h (obj_section_offset): Update. + (struct objfile) : Change type. + : Remove. + (objfile_relocate): Update. + * objfiles.c (entry_point_address_query): Update + (relocate_one_symbol): Change type of "section_offsets". + (objfile_relocate1, objfile_relocate1): Change type of + "new_offsets". + (objfile_rebase1): Update. + * mipsread.c (mipscoff_symfile_read): Update. + (read_alphacoff_dynamic_symtab): Remove "section_offsets" + parameter. + * mdebugread.c (parse_symbol): Change type of "section_offsets". + (parse_external, psymtab_to_symtab_1): Update. + * machoread.c (macho_symfile_offsets): Update. + * ia64-tdep.c (ia64_find_unwind_table): Update. + * hppa-tdep.c (read_unwind_info): Update. + * hppa-bsd-tdep.c (hppabsd_find_global_pointer): Update. + * dwarf2read.c (create_addrmap_from_index) + (create_addrmap_from_aranges, dw2_find_pc_sect_compunit_symtab) + (process_psymtab_comp_unit_reader, add_partial_symbol) + (add_partial_subprogram, process_full_comp_unit) + (read_file_scope, read_func_scope, read_lexical_block_scope) + (read_call_site_scope, dwarf2_rnglists_process) + (dwarf2_ranges_process, dwarf2_ranges_read) + (dwarf_decode_lines_1, var_decode_location, new_symbol) + (dwarf2_fetch_die_loc_sect_off, dwarf2_per_cu_text_offset): + Update. + * dwarf2-frame.c (execute_cfa_program, dwarf2_frame_find_fde): + Update. + * dtrace-probe.c (dtrace_probe::get_relocated_address): Update. + * dbxread.c (read_dbx_symtab, read_ofile_symtab): Update. + (process_one_symbol): Change type of "section_offsets". + * ctfread.c (get_objfile_text_range): Update. + * coffread.c (coff_symtab_read, enter_linenos) + (process_coff_symbol): Update. + * coff-pe-read.c (add_pe_forwarded_sym): Update. + * amd64-windows-tdep.c (amd64_windows_find_unwind_info): Update. + 2020-01-08 Tom Tromey * dwarf2read.c (parse_macro_definition): Use std::string. diff --git a/gdb/amd64-windows-tdep.c b/gdb/amd64-windows-tdep.c index 2ce391fb906..e1e777c4355 100644 --- a/gdb/amd64-windows-tdep.c +++ b/gdb/amd64-windows-tdep.c @@ -953,8 +953,8 @@ amd64_windows_find_unwind_info (struct gdbarch *gdbarch, CORE_ADDR pc, pe = pe_data (sec->objfile->obfd); dir = &pe->pe_opthdr.DataDirectory[PE_EXCEPTION_TABLE]; - base = pe->pe_opthdr.ImageBase - + ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); + base = (pe->pe_opthdr.ImageBase + + objfile->section_offsets[SECT_OFF_TEXT (objfile)]); *image_base = base; /* Find the entry. diff --git a/gdb/coff-pe-read.c b/gdb/coff-pe-read.c index d0c1e050c89..b7f7b81ca88 100644 --- a/gdb/coff-pe-read.c +++ b/gdb/coff-pe-read.c @@ -266,7 +266,7 @@ add_pe_forwarded_sym (minimal_symbol_reader &reader, really be relocated properly, but nevertheless we make a stab at it, choosing an approach consistent with the history of this code. */ - baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); + baseaddr = objfile->section_offsets[SECT_OFF_TEXT (objfile)]; reader.record_with_info (qualified_name.c_str (), vma - baseaddr, msymtype, section); diff --git a/gdb/coffread.c b/gdb/coffread.c index 0395d6d8794..60efb59b1a3 100644 --- a/gdb/coffread.c +++ b/gdb/coffread.c @@ -919,8 +919,8 @@ coff_symtab_read (minimal_symbol_reader &reader, file with no symbols. */ if (in_source_file) complete_symtab (filestring, - cs->c_value + ANOFFSET (objfile->section_offsets, - SECT_OFF_TEXT (objfile)), + (cs->c_value + + objfile->section_offsets[SECT_OFF_TEXT (objfile)]), main_aux.x_scn.x_scnlen); in_source_file = 0; } @@ -986,7 +986,7 @@ coff_symtab_read (minimal_symbol_reader &reader, || cs->c_sclass == C_THUMBEXTFUNC || cs->c_sclass == C_THUMBEXT || (pe_file && (cs->c_sclass == C_STAT))) - offset = ANOFFSET (objfile->section_offsets, sec); + offset = objfile->section_offsets[sec]; if (bfd_section->flags & SEC_CODE) { @@ -1113,8 +1113,7 @@ coff_symtab_read (minimal_symbol_reader &reader, NULL, cstk.start_addr, fcn_cs_saved.c_value + fcn_aux_saved.x_sym.x_misc.x_fsize - + ANOFFSET (objfile->section_offsets, - SECT_OFF_TEXT (objfile))); + + objfile->section_offsets[SECT_OFF_TEXT (objfile)]); within_function = 0; } break; @@ -1123,8 +1122,7 @@ coff_symtab_read (minimal_symbol_reader &reader, if (strcmp (cs->c_name, ".bb") == 0) { tmpaddr = cs->c_value; - tmpaddr += ANOFFSET (objfile->section_offsets, - SECT_OFF_TEXT (objfile)); + tmpaddr += objfile->section_offsets[SECT_OFF_TEXT (objfile)]; push_context (++depth, tmpaddr); } else if (strcmp (cs->c_name, ".eb") == 0) @@ -1147,9 +1145,9 @@ coff_symtab_read (minimal_symbol_reader &reader, } if (*get_local_symbols () && !outermost_context_p ()) { - tmpaddr = - cs->c_value + ANOFFSET (objfile->section_offsets, - SECT_OFF_TEXT (objfile)); + tmpaddr + = (cs->c_value + + objfile->section_offsets[SECT_OFF_TEXT (objfile)]); /* Make a block for the local symbols within. */ finish_block (0, cstk.old_blocks, NULL, cstk.start_addr, tmpaddr); @@ -1441,8 +1439,7 @@ enter_linenos (long file_offset, int first_line, if (L_LNNO32 (&lptr) && L_LNNO32 (&lptr) <= last_line) { CORE_ADDR addr = lptr.l_addr.l_paddr; - addr += ANOFFSET (objfile->section_offsets, - SECT_OFF_TEXT (objfile)); + addr += objfile->section_offsets[SECT_OFF_TEXT (objfile)]; record_line (get_current_subfile (), first_line + L_LNNO32 (&lptr), gdbarch_addr_bits_remove (gdbarch, addr)); @@ -1577,8 +1574,7 @@ process_coff_symbol (struct coff_symbol *cs, if (ISFCN (cs->c_type)) { - SYMBOL_VALUE (sym) += ANOFFSET (objfile->section_offsets, - SECT_OFF_TEXT (objfile)); + SYMBOL_VALUE (sym) += objfile->section_offsets[SECT_OFF_TEXT (objfile)]; SYMBOL_TYPE (sym) = lookup_function_type (decode_function_type (cs, cs->c_type, aux, objfile)); @@ -1610,8 +1606,7 @@ process_coff_symbol (struct coff_symbol *cs, SYMBOL_ACLASS_INDEX (sym) = LOC_STATIC; SET_SYMBOL_VALUE_ADDRESS (sym, (CORE_ADDR) cs->c_value - + ANOFFSET (objfile->section_offsets, - SECT_OFF_TEXT (objfile))); + + objfile->section_offsets[SECT_OFF_TEXT (objfile)]); add_symbol_to_list (sym, get_global_symbols ()); break; @@ -1621,8 +1616,7 @@ process_coff_symbol (struct coff_symbol *cs, SYMBOL_ACLASS_INDEX (sym) = LOC_STATIC; SET_SYMBOL_VALUE_ADDRESS (sym, (CORE_ADDR) cs->c_value - + ANOFFSET (objfile->section_offsets, - SECT_OFF_TEXT (objfile))); + + objfile->section_offsets[SECT_OFF_TEXT (objfile)]); if (within_function) { /* Static symbol of local scope. */ diff --git a/gdb/ctfread.c b/gdb/ctfread.c index 990674e0dfc..ebf1eec6a57 100644 --- a/gdb/ctfread.c +++ b/gdb/ctfread.c @@ -1165,7 +1165,7 @@ get_objfile_text_range (struct objfile *of, int *tsize) codes = bfd_get_section_by_name (abfd, ".text"); *tsize = codes ? bfd_section_size (codes) : 0; - return ANOFFSET (of->section_offsets, SECT_OFF_TEXT (of)); + return of->section_offsets[SECT_OFF_TEXT (of)]; } /* Start a symtab for OBJFILE in CTF format. */ diff --git a/gdb/dbxread.c b/gdb/dbxread.c index 0a02acc8ce9..0909c67ccbb 100644 --- a/gdb/dbxread.c +++ b/gdb/dbxread.c @@ -1046,9 +1046,7 @@ read_dbx_symtab (minimal_symbol_reader &reader, struct objfile *objfile) /* If data_sect_index is still -1, that's okay. It's perfectly fine for the file to have no .data, no .bss, and no .text at all, if - it also has no global or static variables. If it does, we will - get an internal error from an ANOFFSET macro below when we try to - use data_sect_index. */ + it also has no global or static variables. */ for (symnum = 0; symnum < DBX_SYMCOUNT (objfile); symnum++) { @@ -2179,13 +2177,12 @@ read_ofile_symtab (struct objfile *objfile, struct partial_symtab *pst) int sym_size; /* Size of symbols to read */ CORE_ADDR text_offset; /* Start of text segment for symbols */ int text_size; /* Size of text segment for symbols */ - struct section_offsets *section_offsets; sym_offset = LDSYMOFF (pst); sym_size = LDSYMLEN (pst); text_offset = pst->text_low (objfile); text_size = pst->text_high (objfile) - pst->text_low (objfile); - section_offsets = objfile->section_offsets; + const section_offsets §ion_offsets = objfile->section_offsets; dbxread_objfile = objfile; @@ -2378,7 +2375,7 @@ cp_set_block_scope (const struct symbol *symbol, void process_one_symbol (int type, int desc, CORE_ADDR valu, const char *name, - const struct section_offsets *section_offsets, + const section_offsets §ion_offsets, struct objfile *objfile, enum language language) { struct gdbarch *gdbarch = get_objfile_arch (objfile); @@ -2469,7 +2466,7 @@ process_one_symbol (int type, int desc, CORE_ADDR valu, const char *name, sline_found_in_function = 0; /* Relocate for dynamic loading. */ - valu += ANOFFSET (section_offsets, SECT_OFF_TEXT (objfile)); + valu += section_offsets[SECT_OFF_TEXT (objfile)]; valu = gdbarch_addr_bits_remove (gdbarch, valu); last_function_start = valu; @@ -2557,7 +2554,7 @@ process_one_symbol (int type, int desc, CORE_ADDR valu, const char *name, case N_FN_SEQ: /* This kind of symbol indicates the start of an object file. Relocate for dynamic loading. */ - valu += ANOFFSET (section_offsets, SECT_OFF_TEXT (objfile)); + valu += section_offsets[SECT_OFF_TEXT (objfile)]; break; case N_SO: @@ -2565,7 +2562,7 @@ process_one_symbol (int type, int desc, CORE_ADDR valu, const char *name, source file. Finish the symbol table of the previous source file (if any) and start accumulating a new symbol table. Relocate for dynamic loading. */ - valu += ANOFFSET (section_offsets, SECT_OFF_TEXT (objfile)); + valu += section_offsets[SECT_OFF_TEXT (objfile)]; n_opt_found = 0; @@ -2601,7 +2598,7 @@ process_one_symbol (int type, int desc, CORE_ADDR valu, const char *name, sub-source-file, one whose contents were copied or included in the compilation of the main source file (whose name was given in the N_SO symbol). Relocate for dynamic loading. */ - valu += ANOFFSET (section_offsets, SECT_OFF_TEXT (objfile)); + valu += section_offsets[SECT_OFF_TEXT (objfile)]; start_subfile (name); break; @@ -2701,7 +2698,7 @@ process_one_symbol (int type, int desc, CORE_ADDR valu, const char *name, symbol_file_add as addr (this is known to affect SunOS 4, and I suspect ELF too). Since there is no Ttext.text symbol, we can get addr from the text offset. */ - valu += ANOFFSET (section_offsets, SECT_OFF_TEXT (objfile)); + valu += section_offsets[SECT_OFF_TEXT (objfile)]; goto define_a_symbol; } } @@ -2723,22 +2720,22 @@ process_one_symbol (int type, int desc, CORE_ADDR valu, const char *name, case_N_STSYM: /* Static symbol in data segment. */ case N_DSLINE: /* Source line number, data segment. */ - valu += ANOFFSET (section_offsets, SECT_OFF_DATA (objfile)); + valu += section_offsets[SECT_OFF_DATA (objfile)]; goto define_a_symbol; case_N_LCSYM: /* Static symbol in BSS segment. */ case N_BSLINE: /* Source line number, BSS segment. */ /* N_BROWS: overlaps with N_BSLINE. */ - valu += ANOFFSET (section_offsets, SECT_OFF_BSS (objfile)); + valu += section_offsets[SECT_OFF_BSS (objfile)]; goto define_a_symbol; case_N_ROSYM: /* Static symbol in read-only data segment. */ - valu += ANOFFSET (section_offsets, SECT_OFF_RODATA (objfile)); + valu += section_offsets[SECT_OFF_RODATA (objfile)]; goto define_a_symbol; case N_ENTRY: /* Alternate entry point. */ /* Relocate for dynamic loading. */ - valu += ANOFFSET (section_offsets, SECT_OFF_TEXT (objfile)); + valu += section_offsets[SECT_OFF_TEXT (objfile)]; goto define_a_symbol; /* The following symbol types we don't know how to process. @@ -2789,8 +2786,7 @@ process_one_symbol (int type, int desc, CORE_ADDR valu, const char *name, /* Deal with the SunPRO 3.0 compiler which omits the address from N_FUN symbols. */ if (type == N_FUN - && valu == ANOFFSET (section_offsets, - SECT_OFF_TEXT (objfile)) + && valu == section_offsets[SECT_OFF_TEXT (objfile)] && gdbarch_sofun_address_maybe_missing (gdbarch)) { struct bound_minimal_symbol minsym diff --git a/gdb/dtrace-probe.c b/gdb/dtrace-probe.c index 6494a8d7cca..85f6c01b6ab 100644 --- a/gdb/dtrace-probe.c +++ b/gdb/dtrace-probe.c @@ -685,8 +685,8 @@ dtrace_probe::is_enabled () const CORE_ADDR dtrace_probe::get_relocated_address (struct objfile *objfile) { - return this->get_address () + ANOFFSET (objfile->section_offsets, - SECT_OFF_DATA (objfile)); + return (this->get_address () + + objfile->section_offsets[SECT_OFF_DATA (objfile)]); } /* Implementation of the get_argument_count method. */ diff --git a/gdb/dwarf2-frame.c b/gdb/dwarf2-frame.c index 9b49daec719..baa47c94389 100644 --- a/gdb/dwarf2-frame.c +++ b/gdb/dwarf2-frame.c @@ -384,8 +384,7 @@ execute_cfa_program (struct dwarf2_fde *fde, const gdb_byte *insn_ptr, fde->cie->ptr_size, insn_ptr, &bytes_read, fde->initial_location); /* Apply the objfile offset for relocatable objects. */ - fs->pc += ANOFFSET (fde->cie->unit->objfile->section_offsets, - SECT_OFF_TEXT (fde->cie->unit->objfile)); + fs->pc += fde->cie->unit->objfile->section_offsets[SECT_OFF_TEXT (fde->cie->unit->objfile)]; insn_ptr += bytes_read; break; @@ -1686,8 +1685,8 @@ dwarf2_frame_find_fde (CORE_ADDR *pc, CORE_ADDR *out_offset) if (fde_table->num_entries == 0) continue; - gdb_assert (objfile->section_offsets); - offset = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); + gdb_assert (!objfile->section_offsets.empty ()); + offset = objfile->section_offsets[SECT_OFF_TEXT (objfile)]; gdb_assert (fde_table->num_entries > 0); if (*pc < offset + fde_table->entries[0]->initial_location) diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c index 40af0b975ba..04979f3d12f 100644 --- a/gdb/dwarf2read.c +++ b/gdb/dwarf2read.c @@ -3170,7 +3170,7 @@ create_addrmap_from_index (struct dwarf2_per_objfile *dwarf2_per_objfile, iter = index->address_table.data (); end = iter + index->address_table.size (); - baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); + baseaddr = objfile->section_offsets[SECT_OFF_TEXT (objfile)]; while (iter < end) { @@ -3216,8 +3216,7 @@ create_addrmap_from_aranges (struct dwarf2_per_objfile *dwarf2_per_objfile, struct objfile *objfile = dwarf2_per_objfile->objfile; bfd *abfd = objfile->obfd; struct gdbarch *gdbarch = get_objfile_arch (objfile); - const CORE_ADDR baseaddr = ANOFFSET (objfile->section_offsets, - SECT_OFF_TEXT (objfile)); + const CORE_ADDR baseaddr = objfile->section_offsets[SECT_OFF_TEXT (objfile)]; auto_obstack temp_obstack; addrmap *mutable_map = addrmap_create_mutable (&temp_obstack); @@ -5237,8 +5236,7 @@ dw2_find_pc_sect_compunit_symtab (struct objfile *objfile, if (!objfile->partial_symtabs->psymtabs_addrmap) return NULL; - CORE_ADDR baseaddr = ANOFFSET (objfile->section_offsets, - SECT_OFF_TEXT (objfile)); + CORE_ADDR baseaddr = objfile->section_offsets[SECT_OFF_TEXT (objfile)]; data = (struct dwarf2_per_cu_data *) addrmap_find (objfile->partial_symtabs->psymtabs_addrmap, pc - baseaddr); if (!data) @@ -8068,7 +8066,7 @@ process_psymtab_comp_unit_reader (const struct die_reader_specs *reader, /* This must be done before calling dwarf2_build_include_psymtabs. */ pst->dirname = dwarf2_string_attr (comp_unit_die, DW_AT_comp_dir, cu); - baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); + baseaddr = objfile->section_offsets[SECT_OFF_TEXT (objfile)]; dwarf2_find_base_address (comp_unit_die, cu); @@ -8947,7 +8945,7 @@ add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu) const char *actual_name = NULL; CORE_ADDR baseaddr; - baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); + baseaddr = objfile->section_offsets[SECT_OFF_TEXT (objfile)]; gdb::unique_xmalloc_ptr built_actual_name = partial_die_full_name (pdi, cu); @@ -9190,8 +9188,7 @@ add_partial_subprogram (struct partial_die_info *pdi, CORE_ADDR this_highpc; CORE_ADDR this_lowpc; - baseaddr = ANOFFSET (objfile->section_offsets, - SECT_OFF_TEXT (objfile)); + baseaddr = objfile->section_offsets[SECT_OFF_TEXT (objfile)]; this_lowpc = (gdbarch_adjust_dwarf2_addr (gdbarch, pdi->lowpc + baseaddr) @@ -10400,7 +10397,7 @@ process_full_comp_unit (struct dwarf2_per_cu_data *per_cu, struct block *static_block; CORE_ADDR addr; - baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); + baseaddr = objfile->section_offsets[SECT_OFF_TEXT (objfile)]; /* Clear the list here in case something was left over. */ cu->method_list.clear (); @@ -11602,7 +11599,7 @@ read_file_scope (struct die_info *die, struct dwarf2_cu *cu) CORE_ADDR baseaddr; prepare_one_comp_unit (cu, die, cu->language); - baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); + baseaddr = objfile->section_offsets[SECT_OFF_TEXT (objfile)]; get_scope_pc_bounds (die, &lowpc, &highpc, cu); @@ -13716,7 +13713,7 @@ read_func_scope (struct die_info *die, struct dwarf2_cu *cu) } } - baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); + baseaddr = objfile->section_offsets[SECT_OFF_TEXT (objfile)]; name = dwarf2_name (die, cu); @@ -13895,7 +13892,7 @@ read_lexical_block_scope (struct die_info *die, struct dwarf2_cu *cu) struct die_info *child_die; CORE_ADDR baseaddr; - baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); + baseaddr = objfile->section_offsets[SECT_OFF_TEXT (objfile)]; /* Ignore blocks with missing or invalid low and high pc attributes. */ /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges @@ -13969,7 +13966,7 @@ read_call_site_scope (struct die_info *die, struct dwarf2_cu *cu) int nparams; struct die_info *child_die; - baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); + baseaddr = objfile->section_offsets[SECT_OFF_TEXT (objfile)]; attr = dwarf2_attr (die, DW_AT_call_return_pc, cu); if (attr == NULL) @@ -14366,7 +14363,7 @@ dwarf2_rnglists_process (unsigned offset, struct dwarf2_cu *cu, } buffer = dwarf2_per_objfile->rnglists.buffer + offset; - baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); + baseaddr = objfile->section_offsets[SECT_OFF_TEXT (objfile)]; while (1) { @@ -14534,7 +14531,7 @@ dwarf2_ranges_process (unsigned offset, struct dwarf2_cu *cu, } buffer = dwarf2_per_objfile->ranges.buffer + offset; - baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); + baseaddr = objfile->section_offsets[SECT_OFF_TEXT (objfile)]; while (1) { @@ -14612,8 +14609,7 @@ dwarf2_ranges_read (unsigned offset, CORE_ADDR *low_return, { struct objfile *objfile = cu->per_cu->dwarf2_per_objfile->objfile; struct gdbarch *gdbarch = get_objfile_arch (objfile); - const CORE_ADDR baseaddr = ANOFFSET (objfile->section_offsets, - SECT_OFF_TEXT (objfile)); + const CORE_ADDR baseaddr = objfile->section_offsets[SECT_OFF_TEXT (objfile)]; int low_set = 0; CORE_ADDR low = 0; CORE_ADDR high = 0; @@ -21382,7 +21378,7 @@ dwarf_decode_lines_1 (struct line_header *lh, struct dwarf2_cu *cu, the line number program). */ bool record_lines_p = !decode_for_pst_p; - baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); + baseaddr = objfile->section_offsets[SECT_OFF_TEXT (objfile)]; line_ptr = lh->statement_program_start; line_end = lh->statement_program_end; @@ -21765,10 +21761,10 @@ var_decode_location (struct attribute *attr, struct symbol *sym, &dummy)); SYMBOL_ACLASS_INDEX (sym) = LOC_STATIC; fixup_symbol_section (sym, objfile); - SET_SYMBOL_VALUE_ADDRESS (sym, - SYMBOL_VALUE_ADDRESS (sym) - + ANOFFSET (objfile->section_offsets, - SYMBOL_SECTION (sym))); + SET_SYMBOL_VALUE_ADDRESS + (sym, + SYMBOL_VALUE_ADDRESS (sym) + + objfile->section_offsets[SYMBOL_SECTION (sym)]); return; } @@ -21810,7 +21806,7 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu, int inlined_func = (die->tag == DW_TAG_inlined_subroutine); - baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); + baseaddr = objfile->section_offsets[SECT_OFF_TEXT (objfile)]; name = dwarf2_name (die, cu); if (name) @@ -23608,8 +23604,7 @@ dwarf2_fetch_die_loc_sect_off (sect_offset sect_off, != dwarf2_per_objfile->abstract_to_concrete.end ())) { CORE_ADDR pc = (*get_frame_pc) (baton); - CORE_ADDR baseaddr - = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); + CORE_ADDR baseaddr = objfile->section_offsets[SECT_OFF_TEXT (objfile)]; struct gdbarch *gdbarch = get_objfile_arch (objfile); for (const auto &cand_off @@ -25626,7 +25621,7 @@ dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data *per_cu) { struct objfile *objfile = per_cu->dwarf2_per_objfile->objfile; - return ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); + return objfile->section_offsets[SECT_OFF_TEXT (objfile)]; } /* Return a type that is a generic pointer type, the size of which matches diff --git a/gdb/hppa-bsd-tdep.c b/gdb/hppa-bsd-tdep.c index 6575c2413c3..34dec20298f 100644 --- a/gdb/hppa-bsd-tdep.c +++ b/gdb/hppa-bsd-tdep.c @@ -87,8 +87,7 @@ hppabsd_find_global_pointer (struct gdbarch *gdbarch, struct value *function) we have to do it ourselves. */ pltgot = extract_unsigned_integer (buf, sizeof buf, byte_order); - pltgot += ANOFFSET (sec->objfile->section_offsets, - SECT_OFF_TEXT (sec->objfile)); + pltgot += sec->objfile->section_offsets[SECT_OFF_TEXT (sec->objfile)]; return pltgot; } diff --git a/gdb/hppa-tdep.c b/gdb/hppa-tdep.c index 9aa274d0baf..1ee1b0ba286 100644 --- a/gdb/hppa-tdep.c +++ b/gdb/hppa-tdep.c @@ -357,7 +357,7 @@ read_unwind_info (struct objfile *objfile) struct hppa_unwind_info *ui; struct hppa_objfile_private *obj_private; - text_offset = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); + text_offset = objfile->section_offsets[SECT_OFF_TEXT (objfile)]; ui = (struct hppa_unwind_info *) obstack_alloc (&objfile->objfile_obstack, sizeof (struct hppa_unwind_info)); diff --git a/gdb/ia64-tdep.c b/gdb/ia64-tdep.c index 382ca3c88cf..40d4fd3c19d 100644 --- a/gdb/ia64-tdep.c +++ b/gdb/ia64-tdep.c @@ -2713,7 +2713,7 @@ ia64_find_unwind_table (struct objfile *objfile, unw_word_t ip, ehdr = elf_tdata (bfd)->elf_header; phdr = elf_tdata (bfd)->phdr; - load_base = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); + load_base = objfile->section_offsets[SECT_OFF_TEXT (objfile)]; for (i = 0; i < ehdr->e_phnum; ++i) { diff --git a/gdb/machoread.c b/gdb/machoread.c index f7dc2806175..2bb3ab32cb3 100644 --- a/gdb/machoread.c +++ b/gdb/machoread.c @@ -907,12 +907,7 @@ macho_symfile_offsets (struct objfile *objfile, struct obj_section *osect; /* Allocate section_offsets. */ - objfile->num_sections = bfd_count_sections (objfile->obfd); - objfile->section_offsets = (struct section_offsets *) - obstack_alloc (&objfile->objfile_obstack, - SIZEOF_N_SECTION_OFFSETS (objfile->num_sections)); - memset (objfile->section_offsets, 0, - SIZEOF_N_SECTION_OFFSETS (objfile->num_sections)); + objfile->section_offsets.assign (bfd_count_sections (objfile->obfd), 0); /* This code is run when we first add the objfile with symfile_add_with_addrs_or_offsets, when "addrs" not "offsets" are diff --git a/gdb/mdebugread.c b/gdb/mdebugread.c index 622ff279249..ff1d1303221 100644 --- a/gdb/mdebugread.c +++ b/gdb/mdebugread.c @@ -580,7 +580,7 @@ add_data_symbol (SYMR *sh, union aux_ext *ax, int bigend, static int parse_symbol (SYMR *sh, union aux_ext *ax, char *ext_sh, int bigend, - struct section_offsets *section_offsets, struct objfile *objfile) + const section_offsets §ion_offsets, struct objfile *objfile) { struct gdbarch *gdbarch = get_objfile_arch (objfile); const bfd_size_type external_sym_size = debug_swap->external_sym_size; @@ -610,18 +610,18 @@ 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 += ANOFFSET (section_offsets, SECT_OFF_TEXT (objfile)); + sh->value += section_offsets[SECT_OFF_TEXT (objfile)]; break; case scData: case scSData: case scRData: case scPData: case scXData: - sh->value += ANOFFSET (section_offsets, SECT_OFF_DATA (objfile)); + sh->value += section_offsets[SECT_OFF_DATA (objfile)]; break; case scBss: case scSBss: - sh->value += ANOFFSET (section_offsets, SECT_OFF_BSS (objfile)); + sh->value += section_offsets[SECT_OFF_BSS (objfile)]; break; } @@ -2023,8 +2023,7 @@ parse_procedure (PDR *pr, struct compunit_symtab *search_symtab, /* GDB expects the absolute function start address for the procedure descriptor in e->pdr.adr. As the address in the procedure descriptor is usually relative, - we would have to relocate e->pdr.adr with cur_fdr->adr and - ANOFFSET (pst->section_offsets, SECT_OFF_TEXT (pst->objfile)). + we would have to relocate e->pdr.adr with cur_fdr->adr. Unfortunately cur_fdr->adr and e->pdr.adr are both absolute in shared libraries on some systems, and on other systems e->pdr.adr is sometimes offset by a bogus value. @@ -2060,11 +2059,8 @@ parse_procedure (PDR *pr, struct compunit_symtab *search_symtab, This routine clobbers top_stack->cur_block and ->cur_st. */ -static void parse_external (EXTR *, int, struct section_offsets *, - struct objfile *); - static void -parse_external (EXTR *es, int bigend, struct section_offsets *section_offsets, +parse_external (EXTR *es, int bigend, const section_offsets §ion_offsets, struct objfile *objfile) { union aux_ext *ax; @@ -3862,7 +3858,7 @@ psymtab_to_symtab_1 (struct objfile *objfile, struct linetable *lines; CORE_ADDR lowest_pdr_addr = 0; int last_symtab_ended = 0; - struct section_offsets *section_offsets = objfile->section_offsets; + const section_offsets §ion_offsets = objfile->section_offsets; if (pst->readin) return; @@ -3980,8 +3976,7 @@ psymtab_to_symtab_1 (struct objfile *objfile, && previous_stab_code != (unsigned char) N_SO && *name == '\000') { - valu += ANOFFSET (section_offsets, - SECT_OFF_TEXT (objfile)); + valu += section_offsets[SECT_OFF_TEXT (objfile)]; previous_stab_code = N_SO; cust = end_symtab (valu, SECT_OFF_TEXT (objfile)); end_stabs (); @@ -4028,8 +4023,7 @@ psymtab_to_symtab_1 (struct objfile *objfile, else { /* Handle encoded stab line number. */ - valu += ANOFFSET (section_offsets, - SECT_OFF_TEXT (objfile)); + valu += section_offsets[SECT_OFF_TEXT (objfile)]; record_line (get_current_subfile (), sh.index, gdbarch_addr_bits_remove (gdbarch, valu)); } diff --git a/gdb/mipsread.c b/gdb/mipsread.c index d7f2aa44b3f..2c11873d444 100644 --- a/gdb/mipsread.c +++ b/gdb/mipsread.c @@ -43,7 +43,6 @@ static void read_alphacoff_dynamic_symtab (minimal_symbol_reader &, - struct section_offsets *, struct objfile *objfile); /* Initialize anything that needs initializing when a completely new @@ -84,7 +83,7 @@ mipscoff_symfile_read (struct objfile *objfile, symfile_add_flags symfile_flags) /* Add alpha coff dynamic symbols. */ - read_alphacoff_dynamic_symtab (reader, objfile->section_offsets, objfile); + read_alphacoff_dynamic_symtab (reader, objfile); /* Install any minimal symbols that have been collected as the current minimal symbols for this objfile. */ @@ -174,7 +173,6 @@ alphacoff_locate_sections (bfd *ignore_abfd, asection *sectp, void *sip) static void read_alphacoff_dynamic_symtab (minimal_symbol_reader &reader, - struct section_offsets *section_offsets, struct objfile *objfile) { bfd *abfd = objfile->obfd; diff --git a/gdb/objfiles.c b/gdb/objfiles.c index ff408b60527..3138049e622 100644 --- a/gdb/objfiles.c +++ b/gdb/objfiles.c @@ -391,9 +391,9 @@ entry_point_address_query (CORE_ADDR *entry_p) if (symfile_objfile == NULL || !symfile_objfile->per_bfd->ei.entry_point_p) return 0; + int idx = symfile_objfile->per_bfd->ei.the_bfd_section_index; *entry_p = (symfile_objfile->per_bfd->ei.entry_point - + ANOFFSET (symfile_objfile->section_offsets, - symfile_objfile->per_bfd->ei.the_bfd_section_index)); + + symfile_objfile->section_offsets[idx]); return 1; } @@ -626,7 +626,7 @@ objfile::~objfile () static void relocate_one_symbol (struct symbol *sym, struct objfile *objfile, - struct section_offsets *delta) + const section_offsets &delta) { fixup_symbol_section (sym, objfile); @@ -640,7 +640,7 @@ relocate_one_symbol (struct symbol *sym, struct objfile *objfile, { SET_SYMBOL_VALUE_ADDRESS (sym, SYMBOL_VALUE_ADDRESS (sym) - + ANOFFSET (delta, SYMBOL_SECTION (sym))); + + delta[SYMBOL_SECTION (sym)]); } } @@ -650,19 +650,16 @@ relocate_one_symbol (struct symbol *sym, struct objfile *objfile, static int objfile_relocate1 (struct objfile *objfile, - const struct section_offsets *new_offsets) + const section_offsets &new_offsets) { - struct section_offsets *delta = - ((struct section_offsets *) - alloca (SIZEOF_N_SECTION_OFFSETS (objfile->num_sections))); + section_offsets delta (objfile->section_offsets.size ()); int something_changed = 0; - for (int i = 0; i < objfile->num_sections; ++i) + for (int i = 0; i < objfile->section_offsets.size (); ++i) { - delta->offsets[i] = - ANOFFSET (new_offsets, i) - ANOFFSET (objfile->section_offsets, i); - if (ANOFFSET (delta, i) != 0) + delta[i] = new_offsets[i] - objfile->section_offsets[i]; + if (delta[i] != 0) something_changed = 1; } if (!something_changed) @@ -681,9 +678,7 @@ objfile_relocate1 (struct objfile *objfile, if (l) { for (int i = 0; i < l->nitems; ++i) - l->item[i].pc += ANOFFSET (delta, - COMPUNIT_BLOCK_LINE_SECTION - (cust)); + l->item[i].pc += delta[COMPUNIT_BLOCK_LINE_SECTION (cust)]; } } } @@ -694,8 +689,7 @@ objfile_relocate1 (struct objfile *objfile, int block_line_section = COMPUNIT_BLOCK_LINE_SECTION (cust); if (BLOCKVECTOR_MAP (bv)) - addrmap_relocate (BLOCKVECTOR_MAP (bv), - ANOFFSET (delta, block_line_section)); + addrmap_relocate (BLOCKVECTOR_MAP (bv), delta[block_line_section]); for (int i = 0; i < BLOCKVECTOR_NBLOCKS (bv); ++i) { @@ -704,16 +698,14 @@ objfile_relocate1 (struct objfile *objfile, struct mdict_iterator miter; b = BLOCKVECTOR_BLOCK (bv, i); - BLOCK_START (b) += ANOFFSET (delta, block_line_section); - BLOCK_END (b) += ANOFFSET (delta, block_line_section); + BLOCK_START (b) += delta[block_line_section]; + BLOCK_END (b) += delta[block_line_section]; if (BLOCK_RANGES (b) != nullptr) for (int j = 0; j < BLOCK_NRANGES (b); j++) { - BLOCK_RANGE_START (b, j) - += ANOFFSET (delta, block_line_section); - BLOCK_RANGE_END (b, j) += ANOFFSET (delta, - block_line_section); + BLOCK_RANGE_START (b, j) += delta[block_line_section]; + BLOCK_RANGE_END (b, j) += delta[block_line_section]; } /* We only want to iterate over the local symbols, not any @@ -741,8 +733,8 @@ objfile_relocate1 (struct objfile *objfile, { int i; - for (i = 0; i < objfile->num_sections; ++i) - (objfile->section_offsets)->offsets[i] = ANOFFSET (new_offsets, i); + for (i = 0; i < objfile->section_offsets.size (); ++i) + objfile->section_offsets[i] = new_offsets[i]; } /* Rebuild section map next time we need it. */ @@ -773,7 +765,7 @@ objfile_relocate1 (struct objfile *objfile, void objfile_relocate (struct objfile *objfile, - const struct section_offsets *new_offsets) + const section_offsets &new_offsets) { int changed = 0; @@ -792,15 +784,13 @@ objfile_relocate (struct objfile *objfile, addr_info_make_relative (&objfile_addrs, debug_objfile->obfd); - gdb_assert (debug_objfile->num_sections + gdb_assert (debug_objfile->section_offsets.size () == gdb_bfd_count_sections (debug_objfile->obfd)); - std::vector - new_debug_offsets (SIZEOF_N_SECTION_OFFSETS (debug_objfile->num_sections)); - relative_addr_info_to_section_offsets (new_debug_offsets.data (), - debug_objfile->num_sections, - objfile_addrs); + section_offsets new_debug_offsets + (debug_objfile->section_offsets.size ()); + relative_addr_info_to_section_offsets (new_debug_offsets, objfile_addrs); - changed |= objfile_relocate1 (debug_objfile, new_debug_offsets.data ()); + changed |= objfile_relocate1 (debug_objfile, new_debug_offsets); } /* Relocate breakpoints as necessary, after things are relocated. */ @@ -815,14 +805,7 @@ objfile_relocate (struct objfile *objfile, static int objfile_rebase1 (struct objfile *objfile, CORE_ADDR slide) { - struct section_offsets *new_offsets = - ((struct section_offsets *) - alloca (SIZEOF_N_SECTION_OFFSETS (objfile->num_sections))); - int i; - - for (i = 0; i < objfile->num_sections; ++i) - new_offsets->offsets[i] = slide; - + section_offsets new_offsets (objfile->section_offsets.size (), slide); return objfile_relocate1 (objfile, new_offsets); } diff --git a/gdb/objfiles.h b/gdb/objfiles.h index 56c72954217..1301f2c23fd 100644 --- a/gdb/objfiles.h +++ b/gdb/objfiles.h @@ -141,7 +141,7 @@ struct obj_section /* Relocation offset applied to S. */ #define obj_section_offset(s) \ - (((s)->objfile->section_offsets)->offsets[gdb_bfd_section_index ((s)->objfile->obfd, (s)->the_bfd_section)]) + (((s)->objfile->section_offsets)[gdb_bfd_section_index ((s)->objfile->obfd, (s)->the_bfd_section)]) /* The memory address of section S (vma + offset). */ #define obj_section_addr(s) \ @@ -560,14 +560,12 @@ public: /* Set of relocation offsets to apply to each section. The table is indexed by the_bfd_section->index, thus it is generally as large as the number of sections in the binary. - The table is stored on the objfile_obstack. These offsets indicate that all symbols (including partial and minimal symbols) which have been read have been relocated by this much. Symbols which are yet to be read need to be relocated by it. */ - struct section_offsets *section_offsets = nullptr; - int num_sections = 0; + ::section_offsets section_offsets; /* Indexes in the section_offsets array. These are initialized by the *_symfile_offsets() family of functions (som_symfile_offsets, @@ -669,7 +667,7 @@ extern void build_objfile_section_table (struct objfile *); extern void free_objfile_separate_debug (struct objfile *); -extern void objfile_relocate (struct objfile *, const struct section_offsets *); +extern void objfile_relocate (struct objfile *, const section_offsets &); extern void objfile_rebase (struct objfile *, CORE_ADDR); extern int objfile_has_partial_symbols (struct objfile *objfile); diff --git a/gdb/psympriv.h b/gdb/psympriv.h index cae45188da2..e7630050e18 100644 --- a/gdb/psympriv.h +++ b/gdb/psympriv.h @@ -55,8 +55,7 @@ struct partial_symbol the offsets provided in OBJFILE. */ CORE_ADDR address (const struct objfile *objfile) const { - return (ginfo.value.address - + ANOFFSET (objfile->section_offsets, ginfo.section)); + return ginfo.value.address + objfile->section_offsets[ginfo.section]; } /* Set the address of this partial symbol. The address must be @@ -120,15 +119,13 @@ struct partial_symtab /* Return the relocated low text address of this partial_symtab. */ CORE_ADDR text_low (struct objfile *objfile) const { - return m_text_low + ANOFFSET (objfile->section_offsets, - SECT_OFF_TEXT (objfile)); + return m_text_low + objfile->section_offsets[SECT_OFF_TEXT (objfile)]; } /* Return the relocated high text address of this partial_symtab. */ CORE_ADDR text_high (struct objfile *objfile) const { - return m_text_high + ANOFFSET (objfile->section_offsets, - SECT_OFF_TEXT (objfile)); + return m_text_high + objfile->section_offsets[SECT_OFF_TEXT (objfile)]; } /* Set the low text address of this partial_symtab. */ diff --git a/gdb/psymtab.c b/gdb/psymtab.c index c835e1e5946..7caf1c6029a 100644 --- a/gdb/psymtab.c +++ b/gdb/psymtab.c @@ -316,8 +316,7 @@ find_pc_sect_psymtab (struct objfile *objfile, CORE_ADDR pc, if (objfile->partial_symtabs->psymtabs != NULL && objfile->partial_symtabs->psymtabs_addrmap != NULL) { - CORE_ADDR baseaddr = ANOFFSET (objfile->section_offsets, - SECT_OFF_TEXT (objfile)); + CORE_ADDR baseaddr = objfile->section_offsets[SECT_OFF_TEXT (objfile)]; struct partial_symtab *pst = ((struct partial_symtab *) diff --git a/gdb/remote.c b/gdb/remote.c index 7923be1d2fc..082499e6e84 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -4049,7 +4049,6 @@ remote_target::get_offsets () char *ptr; int lose, num_segments = 0, do_sections, do_segments; CORE_ADDR text_addr, data_addr, bss_addr, segments[2]; - struct section_offsets *offs; struct symfile_segment_data *data; if (symfile_objfile == NULL) @@ -4128,10 +4127,7 @@ remote_target::get_offsets () else if (*ptr != '\0') warning (_("Target reported unsupported offsets: %s"), buf); - offs = ((struct section_offsets *) - alloca (SIZEOF_N_SECTION_OFFSETS (symfile_objfile->num_sections))); - memcpy (offs, symfile_objfile->section_offsets, - SIZEOF_N_SECTION_OFFSETS (symfile_objfile->num_sections)); + section_offsets offs = symfile_objfile->section_offsets; data = get_symfile_segment_data (symfile_objfile->obfd); do_segments = (data != NULL); @@ -4184,15 +4180,15 @@ remote_target::get_offsets () if (do_sections) { - offs->offsets[SECT_OFF_TEXT (symfile_objfile)] = text_addr; + offs[SECT_OFF_TEXT (symfile_objfile)] = text_addr; /* This is a temporary kludge to force data and bss to use the same offsets because that's what nlmconv does now. The real solution requires changes to the stub and remote.c that I don't have time to do right now. */ - offs->offsets[SECT_OFF_DATA (symfile_objfile)] = data_addr; - offs->offsets[SECT_OFF_BSS (symfile_objfile)] = data_addr; + offs[SECT_OFF_DATA (symfile_objfile)] = data_addr; + offs[SECT_OFF_BSS (symfile_objfile)] = data_addr; } objfile_relocate (symfile_objfile, offs); diff --git a/gdb/solib-aix.c b/gdb/solib-aix.c index f79f005b0a2..f44ea937d94 100644 --- a/gdb/solib-aix.c +++ b/gdb/solib-aix.c @@ -390,19 +390,15 @@ solib_aix_clear_solib (void) } /* Compute and return the OBJFILE's section_offset array, using - the associated loader info (INFO). + the associated loader info (INFO). */ - The resulting array is computed on the heap and must be - deallocated after use. */ - -static gdb::unique_xmalloc_ptr +static section_offsets solib_aix_get_section_offsets (struct objfile *objfile, lm_info_aix *info) { bfd *abfd = objfile->obfd; - gdb::unique_xmalloc_ptr offsets - (XCNEWVEC (struct section_offsets, objfile->num_sections)); + section_offsets offsets (objfile->section_offsets.size ()); /* .text */ @@ -411,7 +407,7 @@ solib_aix_get_section_offsets (struct objfile *objfile, struct bfd_section *sect = objfile->sections[objfile->sect_index_text].the_bfd_section; - offsets->offsets[objfile->sect_index_text] + offsets[objfile->sect_index_text] = info->text_addr + sect->filepos - bfd_section_vma (sect); } @@ -422,7 +418,7 @@ solib_aix_get_section_offsets (struct objfile *objfile, struct bfd_section *sect = objfile->sections[objfile->sect_index_data].the_bfd_section; - offsets->offsets[objfile->sect_index_data] + offsets[objfile->sect_index_data] = info->data_addr - bfd_section_vma (sect); } @@ -435,8 +431,8 @@ solib_aix_get_section_offsets (struct objfile *objfile, if (objfile->sect_index_bss != -1 && objfile->sect_index_data != -1) { - offsets->offsets[objfile->sect_index_bss] - = (offsets->offsets[objfile->sect_index_data] + offsets[objfile->sect_index_bss] + = (offsets[objfile->sect_index_data] + solib_aix_bss_data_overlap (abfd)); } @@ -468,10 +464,10 @@ solib_aix_solib_create_inferior_hook (int from_tty) lm_info_aix &exec_info = (*library_list)[0]; if (symfile_objfile != NULL) { - gdb::unique_xmalloc_ptr offsets + section_offsets offsets = solib_aix_get_section_offsets (symfile_objfile, &exec_info); - objfile_relocate (symfile_objfile, offsets.get ()); + objfile_relocate (symfile_objfile, offsets); } } diff --git a/gdb/solib-dsbt.c b/gdb/solib-dsbt.c index 96c389c291a..52fa0e868aa 100644 --- a/gdb/solib-dsbt.c +++ b/gdb/solib-dsbt.c @@ -911,8 +911,7 @@ dsbt_relocate_main_executable (void) info->main_executable_lm_info = new lm_info_dsbt; info->main_executable_lm_info->map = ldm; - gdb::unique_xmalloc_ptr new_offsets - (XCNEWVEC (struct section_offsets, symfile_objfile->num_sections)); + section_offsets new_offsets (symfile_objfile->section_offsets.size ()); changed = 0; ALL_OBJFILE_OSECTIONS (symfile_objfile, osect) @@ -926,7 +925,7 @@ dsbt_relocate_main_executable (void) /* Current address of section. */ addr = obj_section_addr (osect); /* Offset from where this section started. */ - offset = ANOFFSET (symfile_objfile->section_offsets, osect_idx); + offset = symfile_objfile->section_offsets[osect_idx]; /* Original address prior to any past relocations. */ orig_addr = addr - offset; @@ -935,10 +934,10 @@ dsbt_relocate_main_executable (void) if (ldm->segs[seg].p_vaddr <= orig_addr && orig_addr < ldm->segs[seg].p_vaddr + ldm->segs[seg].p_memsz) { - new_offsets->offsets[osect_idx] + new_offsets[osect_idx] = ldm->segs[seg].addr - ldm->segs[seg].p_vaddr; - if (new_offsets->offsets[osect_idx] != offset) + if (new_offsets[osect_idx] != offset) changed = 1; break; } @@ -946,7 +945,7 @@ dsbt_relocate_main_executable (void) } if (changed) - objfile_relocate (symfile_objfile, new_offsets.get ()); + objfile_relocate (symfile_objfile, new_offsets); /* Now that symfile_objfile has been relocated, we can compute the GOT value and stash it away. */ diff --git a/gdb/solib-frv.c b/gdb/solib-frv.c index a96bfa04941..10476f6250c 100644 --- a/gdb/solib-frv.c +++ b/gdb/solib-frv.c @@ -785,8 +785,7 @@ frv_relocate_main_executable (void) main_executable_lm_info = new lm_info_frv; main_executable_lm_info->map = ldm; - gdb::unique_xmalloc_ptr new_offsets - (XCNEWVEC (struct section_offsets, symfile_objfile->num_sections)); + section_offsets new_offsets (symfile_objfile->section_offsets.size ()); changed = 0; ALL_OBJFILE_OSECTIONS (symfile_objfile, osect) @@ -800,7 +799,7 @@ frv_relocate_main_executable (void) /* Current address of section. */ addr = obj_section_addr (osect); /* Offset from where this section started. */ - offset = ANOFFSET (symfile_objfile->section_offsets, osect_idx); + offset = symfile_objfile->section_offsets[osect_idx]; /* Original address prior to any past relocations. */ orig_addr = addr - offset; @@ -809,10 +808,10 @@ frv_relocate_main_executable (void) if (ldm->segs[seg].p_vaddr <= orig_addr && orig_addr < ldm->segs[seg].p_vaddr + ldm->segs[seg].p_memsz) { - new_offsets->offsets[osect_idx] + new_offsets[osect_idx] = ldm->segs[seg].addr - ldm->segs[seg].p_vaddr; - if (new_offsets->offsets[osect_idx] != offset) + if (new_offsets[osect_idx] != offset) changed = 1; break; } @@ -820,7 +819,7 @@ frv_relocate_main_executable (void) } if (changed) - objfile_relocate (symfile_objfile, new_offsets.get ()); + objfile_relocate (symfile_objfile, new_offsets); /* Now that symfile_objfile has been relocated, we can compute the GOT value and stash it away. */ diff --git a/gdb/solib-svr4.c b/gdb/solib-svr4.c index daf803fb65f..2d275f2b9c0 100644 --- a/gdb/solib-svr4.c +++ b/gdb/solib-svr4.c @@ -2273,8 +2273,7 @@ enable_break (struct svr4_info *info, int from_tty) CORE_ADDR load_addr; tmp_bfd = os->objfile->obfd; - load_addr = ANOFFSET (os->objfile->section_offsets, - SECT_OFF_TEXT (os->objfile)); + load_addr = os->objfile->section_offsets[SECT_OFF_TEXT (os->objfile)]; interp_sect = bfd_get_section_by_name (tmp_bfd, ".text"); if (interp_sect) @@ -2975,15 +2974,8 @@ svr4_relocate_main_executable (void) if (symfile_objfile) { - struct section_offsets *new_offsets; - int i; - - new_offsets = XALLOCAVEC (struct section_offsets, - symfile_objfile->num_sections); - - for (i = 0; i < symfile_objfile->num_sections; i++) - new_offsets->offsets[i] = displacement; - + section_offsets new_offsets (symfile_objfile->section_offsets.size (), + displacement); objfile_relocate (symfile_objfile, new_offsets); } else if (exec_bfd) diff --git a/gdb/solib-target.c b/gdb/solib-target.c index e90107e5782..625f0990d10 100644 --- a/gdb/solib-target.c +++ b/gdb/solib-target.c @@ -46,7 +46,7 @@ struct lm_info_target : public lm_info_base /* The cached offsets for each section of this shared library, determined from SEGMENT_BASES, or SECTION_BASES. */ - gdb::unique_xmalloc_ptr offsets; + section_offsets offsets; }; typedef std::vector> lm_info_vector; @@ -305,12 +305,11 @@ solib_target_relocate_section_addresses (struct so_list *so, /* Build the offset table only once per object file. We can not do it any earlier, since we need to open the file first. */ - if (li->offsets == NULL) + if (li->offsets.empty ()) { int num_sections = gdb_bfd_count_sections (so->abfd); - li->offsets.reset ((struct section_offsets *) - xzalloc (SIZEOF_N_SECTION_OFFSETS (num_sections))); + li->offsets.assign (num_sections, 0); if (!li->section_bases.empty ()) { @@ -355,7 +354,7 @@ Could not relocate shared library \"%s\": wrong number of ALLOC sections"), gdb_assert (so->addr_low <= so->addr_high); found_range = 1; } - li->offsets->offsets[i] = li->section_bases[bases_index]; + li->offsets[i] = li->section_bases[bases_index]; bases_index++; } if (!found_range) @@ -377,7 +376,7 @@ Could not relocate shared library \"%s\": no segments"), so->so_name); int i; if (!symfile_map_offsets_to_segments (so->abfd, data, - li->offsets.get (), + li->offsets, li->segment_bases.size (), li->segment_bases.data ())) warning (_("\ @@ -414,9 +413,8 @@ Could not relocate shared library \"%s\": bad offsets"), so->so_name); } } - offset = li->offsets->offsets[gdb_bfd_section_index - (sec->the_bfd_section->owner, - sec->the_bfd_section)]; + offset = li->offsets[gdb_bfd_section_index (sec->the_bfd_section->owner, + sec->the_bfd_section)]; sec->addr += offset; sec->endaddr += offset; } diff --git a/gdb/stabsread.h b/gdb/stabsread.h index 181b29133ac..aa52a98e72d 100644 --- a/gdb/stabsread.h +++ b/gdb/stabsread.h @@ -178,7 +178,7 @@ extern struct partial_symtab *dbx_end_psymtab int textlow_not_set); extern void process_one_symbol (int, int, CORE_ADDR, const char *, - const struct section_offsets *, + const section_offsets &, struct objfile *, enum language); extern void elfstab_build_psymtabs (struct objfile *objfile, diff --git a/gdb/stap-probe.c b/gdb/stap-probe.c index 39da2900e7a..5e9a043ffeb 100644 --- a/gdb/stap-probe.c +++ b/gdb/stap-probe.c @@ -1290,8 +1290,7 @@ stap_probe::parse_arguments (struct gdbarch *gdbarch) static CORE_ADDR relocate_address (CORE_ADDR address, struct objfile *objfile) { - return address + ANOFFSET (objfile->section_offsets, - SECT_OFF_DATA (objfile)); + return address + objfile->section_offsets[SECT_OFF_DATA (objfile)]; } /* Implementation of the get_relocated_address method. */ diff --git a/gdb/symfile.c b/gdb/symfile.c index 86d61741079..0285f8fc34c 100644 --- a/gdb/symfile.c +++ b/gdb/symfile.c @@ -269,7 +269,7 @@ build_section_addr_info_from_objfile (const struct objfile *objfile) { int sectindex = sap[i].sectindex; - sap[i].addr += objfile->section_offsets->offsets[sectindex]; + sap[i].addr += objfile->section_offsets[sectindex]; } return sap; } @@ -315,14 +315,14 @@ init_objfile_sect_indices (struct objfile *objfile) later, e.g. by the remote qOffsets packet, and then this will be wrong! That's why we try segments first. */ - for (i = 0; i < objfile->num_sections; i++) + for (i = 0; i < objfile->section_offsets.size (); i++) { - if (ANOFFSET (objfile->section_offsets, i) != 0) + if (objfile->section_offsets[i] != 0) { break; } } - if (i == objfile->num_sections) + if (i == objfile->section_offsets.size ()) { if (objfile->sect_index_text == -1) objfile->sect_index_text = 0; @@ -339,7 +339,7 @@ init_objfile_sect_indices (struct objfile *objfile) struct place_section_arg { - struct section_offsets *offsets; + section_offsets *offsets; CORE_ADDR lowest; }; @@ -350,7 +350,8 @@ static void place_section (bfd *abfd, asection *sect, void *obj) { struct place_section_arg *arg = (struct place_section_arg *) obj; - CORE_ADDR *offsets = arg->offsets->offsets, start_addr; + section_offsets &offsets = *arg->offsets; + CORE_ADDR start_addr; int done; ULONGEST align = ((ULONGEST) 1) << bfd_section_alignment (sect); @@ -408,17 +409,15 @@ place_section (bfd *abfd, asection *sect, void *obj) } /* Store section_addr_info as prepared (made relative and with SECTINDEX - filled-in) by addr_info_make_relative into SECTION_OFFSETS of NUM_SECTIONS - entries. */ + filled-in) by addr_info_make_relative into SECTION_OFFSETS. */ void -relative_addr_info_to_section_offsets (struct section_offsets *section_offsets, - int num_sections, +relative_addr_info_to_section_offsets (section_offsets §ion_offsets, const section_addr_info &addrs) { int i; - memset (section_offsets, 0, SIZEOF_N_SECTION_OFFSETS (num_sections)); + section_offsets.assign (section_offsets.size (), 0); /* Now calculate offsets for section that were specified by the caller. */ for (i = 0; i < addrs.size (); i++) @@ -432,7 +431,7 @@ relative_addr_info_to_section_offsets (struct section_offsets *section_offsets, /* Record all sections in offsets. */ /* The section_offsets in the objfile are here filled in using the BFD index. */ - section_offsets->offsets[osp->sectindex] = osp->addr; + section_offsets[osp->sectindex] = osp->addr; } } @@ -636,12 +635,8 @@ void default_symfile_offsets (struct objfile *objfile, const section_addr_info &addrs) { - objfile->num_sections = gdb_bfd_count_sections (objfile->obfd); - objfile->section_offsets = (struct section_offsets *) - obstack_alloc (&objfile->objfile_obstack, - SIZEOF_N_SECTION_OFFSETS (objfile->num_sections)); - relative_addr_info_to_section_offsets (objfile->section_offsets, - objfile->num_sections, addrs); + objfile->section_offsets.resize (gdb_bfd_count_sections (objfile->obfd)); + relative_addr_info_to_section_offsets (objfile->section_offsets, addrs); /* For relocatable files, all loadable sections will start at zero. The zero is meaningless, so try to pick arbitrary addresses such @@ -662,11 +657,11 @@ default_symfile_offsets (struct objfile *objfile, if (cur_sec == NULL) { - CORE_ADDR *offsets = objfile->section_offsets->offsets; + section_offsets &offsets = objfile->section_offsets; /* Pick non-overlapping offsets for sections the user did not place explicitly. */ - arg.offsets = objfile->section_offsets; + arg.offsets = &objfile->section_offsets; arg.lowest = 0; bfd_map_over_sections (objfile->obfd, place_section, &arg); @@ -902,7 +897,7 @@ init_entry_point_info (struct objfile *objfile) (as gleaned by GDB's shared library code). We convert each address into an offset from the section VMA's as it appears in the object file, and then call the file's sym_offsets function to convert this - into a format-specific offset table --- a `struct section_offsets'. + into a format-specific offset table --- a `section_offsets'. The sectindex field is used to control the ordering of sections with the same name. Upon return, it is updated to contain the corresponding BFD section index, or -1 if the section was not found. @@ -926,13 +921,8 @@ syms_from_objfile_1 (struct objfile *objfile, /* No symbols to load, but we still need to make sure that the section_offsets table is allocated. */ int num_sections = gdb_bfd_count_sections (objfile->obfd); - size_t size = SIZEOF_N_SECTION_OFFSETS (num_sections); - objfile->num_sections = num_sections; - objfile->section_offsets - = (struct section_offsets *) obstack_alloc (&objfile->objfile_obstack, - size); - memset (objfile->section_offsets, 0, size); + objfile->section_offsets.assign (num_sections, 0); return; } @@ -2164,8 +2154,7 @@ set_objfile_default_section_offset (struct objfile *objf, CORE_ADDR offset) { /* Add OFFSET to all sections by default. */ - std::vector offsets (objf->num_sections, - { { offset } }); + section_offsets offsets (objf->section_offsets.size (), offset); /* Create sorted lists of all sections in ADDRS as well as all sections in OBJF. */ @@ -2203,11 +2192,11 @@ set_objfile_default_section_offset (struct objfile *objf, } if (cmp == 0) - offsets[objf_sect->sectindex].offsets[0] = 0; + offsets[objf_sect->sectindex] = 0; } /* Apply the new section offsets. */ - objfile_relocate (objf, offsets.data ()); + objfile_relocate (objf, offsets); } /* This function allows the addition of incrementally linked object files. @@ -2479,9 +2468,6 @@ reread_symbols (void) new_modtime = new_statbuf.st_mtime; if (new_modtime != objfile->mtime) { - struct section_offsets *offsets; - int num_offsets; - printf_filtered (_("`%s' has changed; re-reading symbols.\n"), objfile_name (objfile)); @@ -2556,14 +2542,6 @@ reread_symbols (void) error (_("Can't read symbols from %s: %s."), objfile_name (objfile), bfd_errmsg (bfd_get_error ())); - /* Save the offsets, we will nuke them with the rest of the - objfile_obstack. */ - num_offsets = objfile->num_sections; - offsets = ((struct section_offsets *) - alloca (SIZEOF_N_SECTION_OFFSETS (num_offsets))); - memcpy (offsets, objfile->section_offsets, - SIZEOF_N_SECTION_OFFSETS (num_offsets)); - objfile->reset_psymtabs (); /* NB: after this call to obstack_free, objfiles_changed @@ -2595,15 +2573,6 @@ reread_symbols (void) build_objfile_section_table (objfile); - /* We use the same section offsets as from last time. I'm not - sure whether that is always correct for shared libraries. */ - objfile->section_offsets = (struct section_offsets *) - obstack_alloc (&objfile->objfile_obstack, - SIZEOF_N_SECTION_OFFSETS (num_offsets)); - memcpy (objfile->section_offsets, offsets, - SIZEOF_N_SECTION_OFFSETS (num_offsets)); - objfile->num_sections = num_offsets; - /* What the hell is sym_new_init for, anyway? The concept of distinguishing between the main file and additional files in this way seems rather dubious. */ @@ -3705,7 +3674,7 @@ free_symfile_segment_data (struct symfile_segment_data *data) int symfile_map_offsets_to_segments (bfd *abfd, const struct symfile_segment_data *data, - struct section_offsets *offsets, + section_offsets &offsets, int num_segment_bases, const CORE_ADDR *segment_bases) { @@ -3737,8 +3706,7 @@ symfile_map_offsets_to_segments (bfd *abfd, if (which > num_segment_bases) which = num_segment_bases; - offsets->offsets[i] = (segment_bases[which - 1] - - data->segment_bases[which - 1]); + offsets[i] = segment_bases[which - 1] - data->segment_bases[which - 1]; } return 1; diff --git a/gdb/symfile.h b/gdb/symfile.h index 17e02a9da84..5b349752d50 100644 --- a/gdb/symfile.h +++ b/gdb/symfile.h @@ -373,8 +373,7 @@ extern section_addr_info build_section_addr_info_from_objfile (const struct objfile *objfile); extern void relative_addr_info_to_section_offsets - (struct section_offsets *section_offsets, int num_sections, - const section_addr_info &addrs); + (section_offsets §ion_offsets, const section_addr_info &addrs); extern void addr_info_make_relative (section_addr_info *addrs, bfd *abfd); @@ -515,7 +514,7 @@ extern bfd_byte *symfile_relocate_debug_section (struct objfile *, asection *, extern int symfile_map_offsets_to_segments (bfd *, const struct symfile_segment_data *, - struct section_offsets *, + section_offsets &, int, const CORE_ADDR *); struct symfile_segment_data *get_symfile_segment_data (bfd *abfd); void free_symfile_segment_data (struct symfile_segment_data *data); diff --git a/gdb/symmisc.c b/gdb/symmisc.c index b6f1a986ca3..a5b17ffa381 100644 --- a/gdb/symmisc.c +++ b/gdb/symmisc.c @@ -240,8 +240,7 @@ dump_msymbols (struct objfile *objfile, struct ui_file *outfile) /* Use the relocated address as shown in the symbol here -- do not try to respect copy relocations. */ CORE_ADDR addr = (msymbol->value.address - + ANOFFSET (objfile->section_offsets, - msymbol->section)); + + objfile->section_offsets[msymbol->section]); fputs_filtered (paddress (gdbarch, addr), outfile); fprintf_filtered (outfile, " %s", msymbol->linkage_name ()); if (section) diff --git a/gdb/symtab.c b/gdb/symtab.c index 88b8faedb59..5274b88f7ab 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -1687,11 +1687,10 @@ fixup_section (struct general_symbol_info *ginfo, So, instead, search the section table when lookup by name has failed. The ``addr'' and ``endaddr'' fields may have already - been relocated. If so, the relocation offset (i.e. the - ANOFFSET value) needs to be subtracted from these values when - performing the comparison. We unconditionally subtract it, - because, when no relocation has been performed, the ANOFFSET - value will simply be zero. + been relocated. If so, the relocation offset needs to be + subtracted from these values when performing the comparison. + We unconditionally subtract it, because, when no relocation + has been performed, the value will simply be zero. The address of the symbol whose section we're fixing up HAS NOT BEEN adjusted (relocated) yet. It can't have been since @@ -1717,7 +1716,7 @@ fixup_section (struct general_symbol_info *ginfo, ALL_OBJFILE_OSECTIONS (objfile, s) { int idx = s - objfile->sections; - CORE_ADDR offset = ANOFFSET (objfile->section_offsets, idx); + CORE_ADDR offset = objfile->section_offsets[idx]; if (fallback == -1) fallback = idx; @@ -6373,8 +6372,7 @@ get_msymbol_address (struct objfile *objf, const struct minimal_symbol *minsym) return BMSYMBOL_VALUE_ADDRESS (found); } } - return (minsym->value.address - + ANOFFSET (objf->section_offsets, minsym->section)); + return minsym->value.address + objf->section_offsets[minsym->section]; } diff --git a/gdb/symtab.h b/gdb/symtab.h index d84ac5ca682..5fa067b5f48 100644 --- a/gdb/symtab.h +++ b/gdb/symtab.h @@ -726,7 +726,7 @@ extern CORE_ADDR get_msymbol_address (struct objfile *objf, #define MSYMBOL_VALUE_ADDRESS(objfile, symbol) \ (((symbol)->maybe_copied) ? get_msymbol_address (objfile, symbol) \ : ((symbol)->value.address \ - + ANOFFSET ((objfile)->section_offsets, ((symbol)->section)))) + + (objfile)->section_offsets[(symbol)->section])) /* For a bound minsym, we can easily compute the address directly. */ #define BMSYMBOL_VALUE_ADDRESS(symbol) \ MSYMBOL_VALUE_ADDRESS ((symbol).objfile, (symbol).minsym) @@ -1309,30 +1309,11 @@ struct linetable }; /* How to relocate the symbols from each section in a symbol file. - Each struct contains an array of offsets. The ordering and meaning of the offsets is file-type-dependent; typically it is indexed by section numbers or symbol types or - something like that. + something like that. */ - To give us flexibility in changing the internal representation - of these offsets, the ANOFFSET macro must be used to insert and - extract offset values in the struct. */ - -struct section_offsets -{ - CORE_ADDR offsets[1]; /* As many as needed. */ -}; - -#define ANOFFSET(secoff, whichone) \ - ((whichone == -1) \ - ? (internal_error (__FILE__, __LINE__, \ - _("Section index is uninitialized")), -1) \ - : secoff->offsets[whichone]) - -/* The size of a section_offsets table for N sections. */ -#define SIZEOF_N_SECTION_OFFSETS(n) \ - (sizeof (struct section_offsets) \ - + sizeof (((struct section_offsets *) 0)->offsets) * ((n)-1)) +typedef std::vector section_offsets; /* Each source file or header is represented by a struct symtab. The name "symtab" is historical, another name for it is "filetab". diff --git a/gdb/xcoffread.c b/gdb/xcoffread.c index 6985a43d388..d0fa90e49fb 100644 --- a/gdb/xcoffread.c +++ b/gdb/xcoffread.c @@ -864,7 +864,7 @@ enter_line_range (struct subfile *subfile, unsigned beginoffset, addr = (int_lnno.l_lnno ? int_lnno.l_addr.l_paddr : read_symbol_nvalue (int_lnno.l_addr.l_symndx)); - addr += ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); + addr += objfile->section_offsets[SECT_OFF_TEXT (objfile)]; if (addr < startaddr || (endaddr && addr >= endaddr)) return; @@ -1232,8 +1232,7 @@ read_xcoff_symtab (struct objfile *objfile, struct partial_symtab *pst) } file_start_addr = - cs->c_value + ANOFFSET (objfile->section_offsets, - SECT_OFF_TEXT (objfile)); + cs->c_value + objfile->section_offsets[SECT_OFF_TEXT (objfile)]; file_end_addr = file_start_addr + CSECT_LEN (&main_aux); if (cs->c_name && (cs->c_name[0] == '.' || cs->c_name[0] == '@')) @@ -1355,8 +1354,7 @@ read_xcoff_symtab (struct objfile *objfile, struct partial_symtab *pst) case C_FCN: if (strcmp (cs->c_name, ".bf") == 0) { - CORE_ADDR off = ANOFFSET (objfile->section_offsets, - SECT_OFF_TEXT (objfile)); + CORE_ADDR off = objfile->section_offsets[SECT_OFF_TEXT (objfile)]; bfd_coff_swap_aux_in (abfd, raw_auxptr, cs->c_type, cs->c_sclass, 0, cs->c_naux, &main_aux); @@ -1400,8 +1398,7 @@ read_xcoff_symtab (struct objfile *objfile, struct partial_symtab *pst) NULL, cstk.start_addr, (fcn_cs_saved.c_value + fcn_aux_saved.x_sym.x_misc.x_fsize - + ANOFFSET (objfile->section_offsets, - SECT_OFF_TEXT (objfile)))); + + objfile->section_offsets[SECT_OFF_TEXT (objfile)])); within_function = 0; } break; @@ -1468,8 +1465,7 @@ read_xcoff_symtab (struct objfile *objfile, struct partial_symtab *pst) depth++; newobj = push_context (depth, (cs->c_value - + ANOFFSET (objfile->section_offsets, - SECT_OFF_TEXT (objfile)))); + + objfile->section_offsets[SECT_OFF_TEXT (objfile)])); } else if (strcmp (cs->c_name, ".eb") == 0) { @@ -1491,8 +1487,7 @@ read_xcoff_symtab (struct objfile *objfile, struct partial_symtab *pst) cstk.old_blocks, NULL, cstk.start_addr, (cs->c_value - + ANOFFSET (objfile->section_offsets, - SECT_OFF_TEXT (objfile)))); + + objfile->section_offsets[SECT_OFF_TEXT (objfile)])); } *get_local_symbols () = cstk.locals; } @@ -1554,7 +1549,7 @@ process_xcoff_symbol (struct coff_symbol *cs, struct objfile *objfile) else { sec = secnum_to_section (cs->c_secnum, objfile); - off = ANOFFSET (objfile->section_offsets, sec); + off = objfile->section_offsets[sec]; } name = cs->c_name; @@ -1657,8 +1652,7 @@ process_xcoff_symbol (struct coff_symbol *cs, struct objfile *objfile) if (*pp == 'V' && !within_function) *pp = 'S'; sym = define_symbol ((cs->c_value - + ANOFFSET (objfile->section_offsets, - static_block_section)), + + objfile->section_offsets[static_block_section]), cs->c_name, 0, 0, objfile); if (sym != NULL) { @@ -3024,7 +3018,7 @@ xcoff_symfile_offsets (struct objfile *objfile, us to test whether the associated section exists or not, and then access it quickly (without searching it again). */ - if (objfile->num_sections == 0) + if (objfile->section_offsets.empty ()) return; /* Is that even possible? Better safe than sorry. */ first_section_name = bfd_section_name (objfile->sections[0].the_bfd_section); -- 2.30.2