aboutsummaryrefslogtreecommitdiff
path: root/gdb/objfiles.c
diff options
context:
space:
mode:
authorK. Richard Pixley <rich@cygnus>1993-04-07 07:04:26 +0000
committerK. Richard Pixley <rich@cygnus>1993-04-07 07:04:26 +0000
commit73d0fc782010af6ad1784c9e3a8fc41997ec922b (patch)
treeb2b30811f85c276e9ef87d1bc3b87c67288e937a /gdb/objfiles.c
parent07861607f5b7010e4b5f908361783aac2c096e1e (diff)
downloadgdb-73d0fc782010af6ad1784c9e3a8fc41997ec922b.zip
gdb-73d0fc782010af6ad1784c9e3a8fc41997ec922b.tar.gz
gdb-73d0fc782010af6ad1784c9e3a8fc41997ec922b.tar.bz2
Add section table to objfile struct. Use it for find_pc_section.
* objfiles.c (add_to_objfile_sections, build_objfile_section_table, find_pc_section): new functions. (allocate_objfile): build section table. * objfiles.h (struct obj_section): new structure. (struct objfile): add section table. (find_pc_section): new prototype. * solib.[ch] (find_pc_section_from_so_list): removed. * sparc-tdep.c: include objfiles.h for find_pc_section. include symfile.h for objfiles.h. (in_solib_trampoline): adjusted for new find_pc_section prototype. Removed BAD_RICH_HACK ifdefs. * symfile.c (syms_from_objfile): offset objfile sections. (find_pc_section): removed. Also removed BAD_RICH_HACK ifdefs. * symfile.h (find_pc_section): prototype removed. Also fixed comment typo NUL -> NULL. * target.[ch] (find_pc_section_from_targets): removed. * config/sparc/tm-sun4sol2.h (BAD_RICHH_HACK): removed.
Diffstat (limited to 'gdb/objfiles.c')
-rw-r--r--gdb/objfiles.c71
1 files changed, 71 insertions, 0 deletions
diff --git a/gdb/objfiles.c b/gdb/objfiles.c
index 7fb53e7..541941a 100644
--- a/gdb/objfiles.c
+++ b/gdb/objfiles.c
@@ -60,6 +60,51 @@ struct objfile *symfile_objfile; /* Main symbol table loaded from */
int mapped_symbol_files; /* Try to use mapped symbol files */
+/* Locate all mappable sections of a BFD file.
+ objfile_p_char is a char * to get it through
+ bfd_map_over_sections; we cast it back to its proper type. */
+
+static void
+add_to_objfile_sections (abfd, asect, objfile_p_char)
+ bfd *abfd;
+ sec_ptr asect;
+ PTR objfile_p_char;
+{
+ struct objfile *objfile = (struct objfile *) objfile_p_char;
+ struct obj_section section;
+ flagword aflag;
+
+ aflag = bfd_get_section_flags (abfd, asect);
+ /* FIXME, we need to handle BSS segment here...it alloc's but doesn't load */
+ if (!(aflag & SEC_LOAD))
+ return;
+ if (0 == bfd_section_size (abfd, asect))
+ return;
+ section.offset = 0;
+ section.sec_ptr = asect;
+ section.addr = bfd_section_vma (abfd, asect);
+ section.endaddr = section.addr + bfd_section_size (abfd, asect);
+ obstack_grow (&objfile->psymbol_obstack, &section, sizeof(section));
+ objfile->sections_end = (struct obj_section *) (((int) objfile->sections_end) + 1);
+}
+
+/* Builds a section table for OBJFILE.
+ Returns 0 if OK, 1 on error. */
+
+static int
+build_objfile_section_table (objfile)
+ struct objfile *objfile;
+{
+ if (objfile->sections)
+ abort();
+
+ objfile->sections_end = 0;
+ bfd_map_over_sections (objfile->obfd, add_to_objfile_sections, (char *)objfile);
+ objfile->sections = obstack_finish (&objfile->psymbol_obstack);
+ objfile->sections_end = objfile->sections + (int) objfile->sections_end;
+ return(0);
+}
+
/* Given a pointer to an initialized bfd (ABFD) and a flag that indicates
whether or not an objfile is to be mapped (MAPPED), allocate a new objfile
struct, fill it in as best we can, link it into the list of all known
@@ -188,6 +233,14 @@ allocate_objfile (abfd, mapped)
objfile -> name = mstrsave (objfile -> md, bfd_get_filename (abfd));
objfile -> mtime = bfd_get_mtime (abfd);
+ /* Build section table. */
+
+ if (build_objfile_section_table (objfile))
+ {
+ error ("Can't find the file sections in `%s': %s",
+ objfile -> name, bfd_errmsg (bfd_error));
+ }
+
/* Push this file onto the head of the linked list of other such files. */
objfile -> next = object_files;
@@ -658,3 +711,21 @@ map_to_address ()
}
#endif /* !defined(NO_MMALLOC) && defined(HAVE_MMAP) */
+
+/* Returns a section whose range includes PC or NULL if none found. */
+
+sec_ptr
+find_pc_section(pc)
+ CORE_ADDR pc;
+{
+ struct obj_section *s;
+ struct objfile *objfile;
+
+ ALL_OBJFILES (objfile)
+ for (s = objfile->sections; s < objfile->sections_end; ++s)
+ if (s->addr <= pc
+ && pc < s->endaddr)
+ return(s->sec_ptr);
+
+ return(NULL);
+}