diff options
-rw-r--r-- | gdb/ChangeLog | 30 | ||||
-rw-r--r-- | gdb/coffread.c | 2 | ||||
-rw-r--r-- | gdb/elfread.c | 10 | ||||
-rw-r--r-- | gdb/gdb_bfd.c | 30 | ||||
-rw-r--r-- | gdb/gdb_bfd.h | 14 | ||||
-rw-r--r-- | gdb/machoread.c | 10 | ||||
-rw-r--r-- | gdb/objfiles.c | 75 | ||||
-rw-r--r-- | gdb/objfiles.h | 21 | ||||
-rw-r--r-- | gdb/solib-dsbt.c | 2 | ||||
-rw-r--r-- | gdb/solib-frv.c | 2 | ||||
-rw-r--r-- | gdb/solib-target.c | 3 | ||||
-rw-r--r-- | gdb/symfile.c | 9 | ||||
-rw-r--r-- | gdb/symtab.c | 2 | ||||
-rw-r--r-- | gdb/xcoffread.c | 2 |
14 files changed, 154 insertions, 58 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 793aa91..bfb7c6b 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,35 @@ 2013-04-08 Tom Tromey <tromey@redhat.com> + * coffread.c (cs_to_section): Use gdb_bfd_section_index. + * elfread.c (record_minimal_symbol, elf_symtab_read): Use + gdb_bfd_section_index. + * gdb_bfd.c (gdb_bfd_section_index, gdb_bfd_count_sections): + New functions. + * gdb_bfd.h (gdb_bfd_section_index, gdb_bfd_count_sections): + Declare. + * machoread.c (macho_symtab_add_minsym, macho_symfile_offsets): + Update. + * objfiles.c (add_to_objfile_sections_full): New function. + (add_to_objfile_sections): Use it. + (build_section_table): Rewrite. + (objfile_relocate1): Use gdb_bfd_section_index. Update. + * objfiles.h (obj_section_offset): Use gdb_bfd_section_index. + (struct objfile) <sections>: Update comment. + (ALL_OBJFILE_OSECTIONS): Skip sections where the_bfd_section + is NULL. + (ALL_OBJSECTIONS): Use it. + * solib-dsbt.c (dsbt_relocate_main_executable): Update. + * solib-frv.c (frv_relocate_main_executable): Update. + * solib-target.c (solib_target_relocate_section_addresses): + Use gdb_bfd_section_index. + * symfile.c (build_section_addr_info_from_section_table): + Use gdb_bfd_section_index. + (build_section_addr_info_from_bfd, place_section): Likewise. + * symtab.c (fixup_section): Update. + * xcoffread.c (find_targ_sec): Use gdb_bfd_section_index. + +2013-04-08 Tom Tromey <tromey@redhat.com> + * minsyms.h (struct bound_minimal_symbol): New. (lookup_minimal_symbol_and_objfile): Return bound_minimal_symbol. Remove objfile argument. diff --git a/gdb/coffread.c b/gdb/coffread.c index f4f2afd..9076262 100644 --- a/gdb/coffread.c +++ b/gdb/coffread.c @@ -297,7 +297,7 @@ cs_to_section (struct coff_symbol *cs, struct objfile *objfile) if (sect == NULL) return SECT_OFF_TEXT (objfile); - return sect->index; + return gdb_bfd_section_index (objfile->obfd, sect); } /* Return the address of the section of a COFF symbol. */ diff --git a/gdb/elfread.c b/gdb/elfread.c index 866e496..668b974 100644 --- a/gdb/elfread.c +++ b/gdb/elfread.c @@ -208,7 +208,9 @@ record_minimal_symbol (const char *name, int name_len, int copy_name, address = gdbarch_addr_bits_remove (gdbarch, address); return prim_record_minimal_symbol_full (name, name_len, copy_name, address, - ms_type, bfd_section->index, + ms_type, + gdb_bfd_section_index (objfile->obfd, + bfd_section), bfd_section, objfile); } @@ -271,7 +273,8 @@ elf_symtab_read (struct objfile *objfile, int type, continue; } - offset = ANOFFSET (objfile->section_offsets, sym->section->index); + offset = ANOFFSET (objfile->section_offsets, + gdb_bfd_section_index (objfile->obfd, sym->section)); if (type == ST_DYNAMIC && sym->section == bfd_und_section_ptr && (sym->flags & BSF_FUNCTION)) @@ -326,7 +329,8 @@ elf_symtab_read (struct objfile *objfile, int type, && bfd_get_section_by_name (abfd, ".plt") != NULL) continue; - symaddr += ANOFFSET (objfile->section_offsets, sect->index); + symaddr += ANOFFSET (objfile->section_offsets, + gdb_bfd_section_index (objfile->obfd, sect)); msym = record_minimal_symbol (sym->name, strlen (sym->name), copy_names, diff --git a/gdb/gdb_bfd.c b/gdb/gdb_bfd.c index 53c3a12..e7cd523 100644 --- a/gdb/gdb_bfd.c +++ b/gdb/gdb_bfd.c @@ -605,6 +605,36 @@ gdb_bfd_fdopenr (const char *filename, const char *target, int fd) +gdb_static_assert (ARRAY_SIZE (_bfd_std_section) == 4); + +/* See gdb_bfd.h. */ + +int +gdb_bfd_section_index (bfd *abfd, asection *section) +{ + if (section == NULL) + return -1; + else if (section == bfd_com_section_ptr) + return bfd_count_sections (abfd) + 1; + else if (section == bfd_und_section_ptr) + return bfd_count_sections (abfd) + 2; + else if (section == bfd_abs_section_ptr) + return bfd_count_sections (abfd) + 3; + else if (section == bfd_ind_section_ptr) + return bfd_count_sections (abfd) + 4; + return section->index; +} + +/* See gdb_bfd.h. */ + +int +gdb_bfd_count_sections (bfd *abfd) +{ + return bfd_count_sections (abfd) + 4; +} + + + /* A callback for htab_traverse that prints a single BFD. */ static int diff --git a/gdb/gdb_bfd.h b/gdb/gdb_bfd.h index 1e74bfe..ca2eddc 100644 --- a/gdb/gdb_bfd.h +++ b/gdb/gdb_bfd.h @@ -121,4 +121,18 @@ bfd *gdb_bfd_openr_next_archived_file (bfd *archive, bfd *previous); bfd *gdb_bfd_fdopenr (const char *filename, const char *target, int fd); + + +/* Return the index of the BFD section SECTION. Ordinarily this is + just the section's index, but for some special sections, like + bfd_com_section_ptr, it will be a synthesized value. */ + +int gdb_bfd_section_index (bfd *abfd, asection *section); + + +/* Like bfd_count_sections, but include any possible global sections, + like bfd_com_section_ptr. */ + +int gdb_bfd_count_sections (bfd *abfd); + #endif /* GDB_BFD_H */ diff --git a/gdb/machoread.c b/gdb/machoread.c index eff8bdf..54d8e31 100644 --- a/gdb/machoread.c +++ b/gdb/machoread.c @@ -116,7 +116,8 @@ macho_symtab_add_minsym (struct objfile *objfile, const asymbol *sym) CORE_ADDR offset; enum minimal_symbol_type ms_type; - offset = ANOFFSET (objfile->section_offsets, sym->section->index); + offset = ANOFFSET (objfile->section_offsets, + gdb_bfd_section_index (objfile->obfd, sym->section)); /* Bfd symbols are section relative. */ symaddr = sym->value + sym->section->vma; @@ -164,8 +165,9 @@ macho_symtab_add_minsym (struct objfile *objfile, const asymbol *sym) return; /* Skip this symbol. */ prim_record_minimal_symbol_and_info - (sym->name, symaddr, ms_type, sym->section->index, - sym->section, objfile); + (sym->name, symaddr, ms_type, + gdb_bfd_section_index (objfile->obfd, sym->section), + sym->section, objfile); } } @@ -1008,7 +1010,7 @@ macho_symfile_offsets (struct objfile *objfile, ALL_OBJFILE_OSECTIONS (objfile, osect) { const char *bfd_sect_name = osect->the_bfd_section->name; - int sect_index = osect->the_bfd_section->index; + int sect_index = osect - objfile->sections;; if (strncmp (bfd_sect_name, "LC_SEGMENT.", 11) == 0) bfd_sect_name += 11; diff --git a/gdb/objfiles.c b/gdb/objfiles.c index 3017fdf..93b7ba7 100644 --- a/gdb/objfiles.c +++ b/gdb/objfiles.c @@ -182,50 +182,55 @@ set_objfile_per_bfd (struct objfile *objfile) the end of the table (objfile->sections_end). */ static void +add_to_objfile_sections_full (struct bfd *abfd, struct bfd_section *asect, + struct objfile *objfile, int force) +{ + struct obj_section *section; + + if (!force) + { + flagword aflag; + + aflag = bfd_get_section_flags (abfd, asect); + if (!(aflag & SEC_ALLOC)) + return; + } + + section = &objfile->sections[gdb_bfd_section_index (abfd, asect)]; + section->objfile = objfile; + section->the_bfd_section = asect; + section->ovly_mapped = 0; +} + +static void add_to_objfile_sections (struct bfd *abfd, struct bfd_section *asect, void *objfilep) { - struct objfile *objfile = (struct objfile *) objfilep; - struct obj_section section; - flagword aflag; - - aflag = bfd_get_section_flags (abfd, asect); - if (!(aflag & SEC_ALLOC)) - return; - if (bfd_section_size (abfd, asect) == 0) - return; - - section.objfile = objfile; - section.the_bfd_section = asect; - section.ovly_mapped = 0; - obstack_grow (&objfile->objfile_obstack, - (char *) §ion, sizeof (section)); - objfile->sections_end - = (struct obj_section *) (((size_t) objfile->sections_end) + 1); + add_to_objfile_sections_full (abfd, asect, objfilep, 0); } /* Builds a section table for OBJFILE. - Note that while we are building the table, which goes into the - objfile obstack, we hijack the sections_end pointer to instead hold - a count of the number of sections. When bfd_map_over_sections - returns, this count is used to compute the pointer to the end of - the sections table, which then overwrites the count. - - Also note that the OFFSET and OVLY_MAPPED in each table entry - are initialized to zero. - - Also note that if anything else writes to the objfile obstack while - we are building the table, we're pretty much hosed. */ + Note that the OFFSET and OVLY_MAPPED in each table entry are + initialized to zero. */ void build_objfile_section_table (struct objfile *objfile) { - objfile->sections_end = 0; + int count = gdb_bfd_count_sections (objfile->obfd); + + objfile->sections = OBSTACK_CALLOC (&objfile->objfile_obstack, + count, + struct obj_section); + objfile->sections_end = (objfile->sections + count); bfd_map_over_sections (objfile->obfd, add_to_objfile_sections, (void *) objfile); - objfile->sections = obstack_finish (&objfile->objfile_obstack); - objfile->sections_end = objfile->sections + (size_t) objfile->sections_end; + + /* See gdb_bfd_section_index. */ + add_to_objfile_sections_full (objfile->obfd, bfd_com_section_ptr, objfile, 1); + add_to_objfile_sections_full (objfile->obfd, bfd_und_section_ptr, objfile, 1); + add_to_objfile_sections_full (objfile->obfd, bfd_abs_section_ptr, objfile, 1); + add_to_objfile_sections_full (objfile->obfd, bfd_ind_section_ptr, objfile, 1); } /* Given a pointer to an initialized bfd (ABFD) and some flag bits @@ -804,7 +809,11 @@ objfile_relocate1 (struct objfile *objfile, struct obj_section *s; s = find_pc_section (objfile->ei.entry_point); if (s) - objfile->ei.entry_point += ANOFFSET (delta, s->the_bfd_section->index); + { + int idx = gdb_bfd_section_index (objfile->obfd, s->the_bfd_section); + + objfile->ei.entry_point += ANOFFSET (delta, idx); + } else objfile->ei.entry_point += ANOFFSET (delta, SECT_OFF_TEXT (objfile)); } @@ -822,7 +831,7 @@ objfile_relocate1 (struct objfile *objfile, /* Update the table in exec_ops, used to read memory. */ ALL_OBJFILE_OSECTIONS (objfile, s) { - int idx = s->the_bfd_section->index; + int idx = s - objfile->sections; exec_set_section_address (bfd_get_filename (objfile->obfd), idx, obj_section_addr (s)); diff --git a/gdb/objfiles.h b/gdb/objfiles.h index 9646bbd..1fbb255 100644 --- a/gdb/objfiles.h +++ b/gdb/objfiles.h @@ -24,6 +24,7 @@ #include "symfile.h" /* For struct psymbol_allocation_list. */ #include "progspace.h" #include "registry.h" +#include "gdb_bfd.h" struct bcache; struct htab; @@ -123,7 +124,7 @@ struct obj_section /* Relocation offset applied to S. */ #define obj_section_offset(s) \ - (((s)->objfile->section_offsets)->offsets[(s)->the_bfd_section->index]) + (((s)->objfile->section_offsets)->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) \ @@ -349,9 +350,10 @@ struct objfile among other things, is used to map pc addresses into sections. SECTIONS points to the first entry in the table, and SECTIONS_END points to the first location past the last entry - in the table. The table is stored on the objfile_obstack. - There is no particular order to the sections in this table, and it - only contains sections we care about (e.g. non-empty, SEC_ALLOC). */ + in the table. The table is stored on the objfile_obstack. The + sections are indexed by the BFD section index; but the + structure data is only valid for certain sections + (e.g. non-empty, SEC_ALLOC). */ struct obj_section *sections, *sections_end; @@ -576,7 +578,12 @@ extern void default_iterate_over_objfiles_in_search_order ALL_OBJFILE_MSYMBOLS (objfile, m) #define ALL_OBJFILE_OSECTIONS(objfile, osect) \ - for (osect = objfile->sections; osect < objfile->sections_end; osect++) + for (osect = objfile->sections; osect < objfile->sections_end; osect++) \ + if (osect->the_bfd_section == NULL) \ + { \ + /* Nothing. */ \ + } \ + else /* Traverse all obj_sections in all objfiles in the current program space. @@ -612,9 +619,7 @@ extern void default_iterate_over_objfiles_in_search_order ? ((objfile) = (objfile)->next, \ (objfile) != NULL ? (osect) = (objfile)->sections_end : 0) \ : 0)) \ - for ((osect) = (objfile)->sections; \ - (osect) < (objfile)->sections_end; \ - (osect)++) + ALL_OBJFILE_OSECTIONS (objfile, osect) #define SECT_OFF_DATA(objfile) \ ((objfile->sect_index_data == -1) \ diff --git a/gdb/solib-dsbt.c b/gdb/solib-dsbt.c index ea2acd1..e2822c1 100644 --- a/gdb/solib-dsbt.c +++ b/gdb/solib-dsbt.c @@ -1054,7 +1054,7 @@ dsbt_relocate_main_executable (void) int osect_idx; int seg; - osect_idx = osect->the_bfd_section->index; + osect_idx = osect - symfile_objfile->sections; /* Current address of section. */ addr = obj_section_addr (osect); diff --git a/gdb/solib-frv.c b/gdb/solib-frv.c index 57e418f..52588bc 100644 --- a/gdb/solib-frv.c +++ b/gdb/solib-frv.c @@ -812,7 +812,7 @@ frv_relocate_main_executable (void) int osect_idx; int seg; - osect_idx = osect->the_bfd_section->index; + osect_idx = osect - symfile_objfile->sections; /* Current address of section. */ addr = obj_section_addr (osect); diff --git a/gdb/solib-target.c b/gdb/solib-target.c index d897bc0..0ad29ba 100644 --- a/gdb/solib-target.c +++ b/gdb/solib-target.c @@ -456,7 +456,8 @@ Could not relocate shared library \"%s\": bad offsets"), so->so_name); } } - offset = so->lm_info->offsets->offsets[sec->the_bfd_section->index]; + offset = so->lm_info->offsets->offsets[gdb_bfd_section_index (sec->bfd, + sec->the_bfd_section)]; sec->addr += offset; sec->endaddr += offset; } diff --git a/gdb/symfile.c b/gdb/symfile.c index edb05e4..3e66bd1 100644 --- a/gdb/symfile.c +++ b/gdb/symfile.c @@ -237,7 +237,8 @@ build_section_addr_info_from_section_table (const struct target_section *start, sap->other[oidx].addr = stp->addr; sap->other[oidx].name = xstrdup (bfd_section_name (stp->bfd, stp->the_bfd_section)); - sap->other[oidx].sectindex = stp->the_bfd_section->index; + sap->other[oidx].sectindex + = gdb_bfd_section_index (stp->bfd, stp->the_bfd_section); oidx++; } } @@ -262,7 +263,7 @@ build_section_addr_info_from_bfd (bfd *abfd) { sap->other[i].addr = bfd_get_section_vma (abfd, sec); sap->other[i].name = xstrdup (bfd_get_section_name (abfd, sec)); - sap->other[i].sectindex = sec->index; + sap->other[i].sectindex = gdb_bfd_section_index (abfd, sec); i++; } @@ -389,7 +390,7 @@ place_section (bfd *abfd, asection *sect, void *obj) return; /* If the user specified an offset, honor it. */ - if (offsets[sect->index] != 0) + if (offsets[gdb_bfd_section_index (abfd, sect)] != 0) return; /* Otherwise, let's try to find a place for the section. */ @@ -433,7 +434,7 @@ place_section (bfd *abfd, asection *sect, void *obj) } while (!done); - offsets[sect->index] = start_addr; + offsets[gdb_bfd_section_index (abfd, sect)] = start_addr; arg->lowest = start_addr + bfd_get_section_size (sect); } diff --git a/gdb/symtab.c b/gdb/symtab.c index 1922d9b..2526503 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -1064,7 +1064,7 @@ fixup_section (struct general_symbol_info *ginfo, ALL_OBJFILE_OSECTIONS (objfile, s) { - int idx = s->the_bfd_section->index; + int idx = s - objfile->sections; CORE_ADDR offset = ANOFFSET (objfile->section_offsets, idx); if (obj_section_addr (s) - offset <= addr diff --git a/gdb/xcoffread.c b/gdb/xcoffread.c index 45cb8f4..e6a562d 100644 --- a/gdb/xcoffread.c +++ b/gdb/xcoffread.c @@ -278,7 +278,7 @@ find_targ_sec (bfd *abfd, asection *sect, void *obj) else if (bfd_get_section_flags (abfd, sect) & SEC_LOAD) *args->resultp = SECT_OFF_DATA (objfile); else - *args->resultp = sect->index; + *args->resultp = gdb_bfd_section_index (abfd, sect); *args->bfd_sect = sect; } } |