* objfiles.h (struct obj_section): Remove addr and endaddr fields.

(obj_section_offset, obj_section_addr, obj_section_endaddr): New
	macros.
	* objfiles.c (add_to_objfile_sections): Don't set addr, endaddr
	and offset.  Use size_t instead of unsigned long.
	(build_objfile_section_table): Use size_t instead of unsigned
	long.
	(objfile_relocate): Don't relocate s->addr and s->endaddr, they're
	gone.
	(find_pc_sect_section): Use obj_section_addr and
	obj_section_endaddr.
	* symfile.c (symfile.c): Remove code that maps sections
	offsets in "addr" to the object's sections.
	* blockframe.c (find_pc_partial_function): Use obj_section_endaddr.
	* gcore.c (gcore_create_callback): Use obj_section_addr and
	obj_section_endaddr.
	* maint.c (print_objfile_section_info): Likewise.
	* printcmd.c (sym_info): Use obj_section_addr and
	obj_section_endaddr.
	* symtab.c (fixup_section): Likewise.
This commit is contained in:
Pedro Alves 2008-08-20 11:21:44 +00:00
parent b365f67721
commit f1f6aadf8c
9 changed files with 63 additions and 111 deletions

View file

@ -1,3 +1,26 @@
2008-08-20 Pedro Alves <pedro@codesourcery.com>
* objfiles.h (struct obj_section): Remove addr and endaddr fields.
(obj_section_offset, obj_section_addr, obj_section_endaddr): New
macros.
* objfiles.c (add_to_objfile_sections): Don't set addr, endaddr
and offset. Use size_t instead of unsigned long.
(build_objfile_section_table): Use size_t instead of unsigned
long.
(objfile_relocate): Don't relocate s->addr and s->endaddr, they're
gone.
(find_pc_sect_section): Use obj_section_addr and
obj_section_endaddr.
* symfile.c (symfile.c): Remove code that maps sections
offsets in "addr" to the object's sections.
* blockframe.c (find_pc_partial_function): Use obj_section_endaddr.
* gcore.c (gcore_create_callback): Use obj_section_addr and
obj_section_endaddr.
* maint.c (print_objfile_section_info): Likewise.
* printcmd.c (sym_info): Use obj_section_addr and
obj_section_endaddr.
* symtab.c (fixup_section): Likewise.
2008-08-20 Mark Kettenis <kettenis@gnu.org> 2008-08-20 Mark Kettenis <kettenis@gnu.org>
* sparc-tdep.c: Make some comments catch up with reality. * sparc-tdep.c: Make some comments catch up with reality.

View file

@ -299,12 +299,12 @@ find_pc_partial_function (CORE_ADDR pc, char **name, CORE_ADDR *address,
} }
if (DEPRECATED_SYMBOL_NAME (msymbol + i) != NULL if (DEPRECATED_SYMBOL_NAME (msymbol + i) != NULL
&& SYMBOL_VALUE_ADDRESS (msymbol + i) < osect->endaddr) && SYMBOL_VALUE_ADDRESS (msymbol + i) < obj_section_endaddr (osect))
cache_pc_function_high = SYMBOL_VALUE_ADDRESS (msymbol + i); cache_pc_function_high = SYMBOL_VALUE_ADDRESS (msymbol + i);
else else
/* We got the start address from the last msymbol in the objfile. /* We got the start address from the last msymbol in the objfile.
So the end address is the end of the section. */ So the end address is the end of the section. */
cache_pc_function_high = osect->endaddr; cache_pc_function_high = obj_section_endaddr (osect);
} }
return_cached_value: return_cached_value:

View file

@ -344,8 +344,8 @@ gcore_create_callback (CORE_ADDR vaddr, unsigned long size,
asection *asec = objsec->the_bfd_section; asection *asec = objsec->the_bfd_section;
bfd_vma align = (bfd_vma) 1 << bfd_get_section_alignment (abfd, bfd_vma align = (bfd_vma) 1 << bfd_get_section_alignment (abfd,
asec); asec);
bfd_vma start = objsec->addr & -align; bfd_vma start = obj_section_addr (objsec) & -align;
bfd_vma end = (objsec->endaddr + align - 1) & -align; bfd_vma end = (obj_section_endaddr (objsec) + align - 1) & -align;
/* Match if either the entire memory region lies inside the /* Match if either the entire memory region lies inside the
section (i.e. a mapping covering some pages of a large section (i.e. a mapping covering some pages of a large
segment) or the entire section lies inside the memory region segment) or the entire section lies inside the memory region
@ -415,7 +415,7 @@ objfile_find_memory_regions (int (*func) (CORE_ADDR, unsigned long,
int size = bfd_section_size (ibfd, isec); int size = bfd_section_size (ibfd, isec);
int ret; int ret;
ret = (*func) (objsec->addr, bfd_section_size (ibfd, isec), ret = (*func) (obj_section_addr (objsec), bfd_section_size (ibfd, isec),
1, /* All sections will be readable. */ 1, /* All sections will be readable. */
(flags & SEC_READONLY) == 0, /* Writable. */ (flags & SEC_READONLY) == 0, /* Writable. */
(flags & SEC_CODE) != 0, /* Executable. */ (flags & SEC_CODE) != 0, /* Executable. */

View file

@ -348,8 +348,10 @@ print_objfile_section_info (bfd *abfd,
|| match_substring (string, name) || match_substring (string, name)
|| match_bfd_flags (string, flags)) || match_bfd_flags (string, flags))
{ {
maint_print_section_info (name, flags, asect->addr, asect->endaddr, maint_print_section_info (name, flags,
asect->the_bfd_section->filepos); obj_section_addr (asect),
obj_section_endaddr (asect),
asect->the_bfd_section->filepos);
} }
} }

View file

@ -88,14 +88,12 @@ add_to_objfile_sections (struct bfd *abfd, struct bfd_section *asect,
if (0 == bfd_section_size (abfd, asect)) if (0 == bfd_section_size (abfd, asect))
return; return;
section.offset = 0;
section.objfile = objfile; section.objfile = objfile;
section.the_bfd_section = asect; section.the_bfd_section = asect;
section.ovly_mapped = 0; section.ovly_mapped = 0;
section.addr = bfd_section_vma (abfd, asect);
section.endaddr = section.addr + bfd_section_size (abfd, asect);
obstack_grow (&objfile->objfile_obstack, (char *) &section, sizeof (section)); obstack_grow (&objfile->objfile_obstack, (char *) &section, sizeof (section));
objfile->sections_end = (struct obj_section *) (((unsigned long) objfile->sections_end) + 1); objfile->sections_end
= (struct obj_section *) (((size_t) objfile->sections_end) + 1);
} }
/* Builds a section table for OBJFILE. /* Builds a section table for OBJFILE.
@ -124,10 +122,10 @@ build_objfile_section_table (struct objfile *objfile)
waste some memory. */ waste some memory. */
objfile->sections_end = 0; objfile->sections_end = 0;
bfd_map_over_sections (objfile->obfd, add_to_objfile_sections, (char *) objfile); bfd_map_over_sections (objfile->obfd,
objfile->sections = (struct obj_section *) add_to_objfile_sections, (void *) objfile);
obstack_finish (&objfile->objfile_obstack); objfile->sections = obstack_finish (&objfile->objfile_obstack);
objfile->sections_end = objfile->sections + (unsigned long) objfile->sections_end; objfile->sections_end = objfile->sections + (size_t) objfile->sections_end;
return (0); return (0);
} }
@ -664,28 +662,13 @@ objfile_relocate (struct objfile *objfile, struct section_offsets *new_offsets)
objfile->ei.entry_point += ANOFFSET (delta, SECT_OFF_TEXT (objfile)); objfile->ei.entry_point += ANOFFSET (delta, SECT_OFF_TEXT (objfile));
} }
{
struct obj_section *s;
bfd *abfd;
abfd = objfile->obfd;
ALL_OBJFILE_OSECTIONS (objfile, s)
{
int idx = s->the_bfd_section->index;
s->addr += ANOFFSET (delta, idx);
s->endaddr += ANOFFSET (delta, idx);
}
}
/* Update the table in exec_ops, used to read memory. */ /* Update the table in exec_ops, used to read memory. */
ALL_OBJFILE_OSECTIONS (objfile, s) ALL_OBJFILE_OSECTIONS (objfile, s)
{ {
int idx = s->the_bfd_section->index; int idx = s->the_bfd_section->index;
exec_set_section_address (bfd_get_filename (objfile->obfd), idx, exec_set_section_address (bfd_get_filename (objfile->obfd), idx,
s->addr); obj_section_addr (s));
} }
/* Relocate breakpoints as necessary, after things are relocated. */ /* Relocate breakpoints as necessary, after things are relocated. */
@ -784,8 +767,8 @@ find_pc_sect_section (CORE_ADDR pc, struct bfd_section *section)
struct objfile *objfile; struct objfile *objfile;
ALL_OBJSECTIONS (objfile, s) ALL_OBJSECTIONS (objfile, s)
if ((section == 0 || section == s->the_bfd_section) && if ((section == 0 || section == s->the_bfd_section)
s->addr <= pc && pc < s->endaddr) && obj_section_addr (s) <= pc && pc < obj_section_endaddr (s))
return (s); return (s);
return (NULL); return (NULL);

View file

@ -110,34 +110,11 @@ struct entry_info
}; };
/* Sections in an objfile. /* Sections in an objfile. The section offsets are stored in the
OBJFILE. */
It is strange that we have both this notion of "sections"
and the one used by section_offsets. Section as used
here, (currently at least) means a BFD section, and the sections
are set up from the BFD sections in allocate_objfile.
The sections in section_offsets have their meaning determined by
the symbol format, and they are set up by the sym_offsets function
for that symbol file format.
I'm not sure this could or should be changed, however. */
struct obj_section struct obj_section
{ {
CORE_ADDR addr; /* lowest address in section */
CORE_ADDR endaddr; /* 1+highest address in section */
/* This field is being used for nefarious purposes by syms_from_objfile.
It is said to be redundant with section_offsets; it's not really being
used that way, however, it's some sort of hack I don't understand
and am not going to try to eliminate (yet, anyway). FIXME.
It was documented as "offset between (end)addr and actual memory
addresses", but that's not true; addr & endaddr are actual memory
addresses. */
CORE_ADDR offset;
struct bfd_section *the_bfd_section; /* BFD section pointer */ struct bfd_section *the_bfd_section; /* BFD section pointer */
/* Objfile this section is part of. */ /* Objfile this section is part of. */
@ -147,6 +124,21 @@ struct obj_section
int ovly_mapped; int ovly_mapped;
}; };
/* Relocation offset applied to S. */
#define obj_section_offset(s) \
(((s)->objfile->section_offsets)->offsets[(s)->the_bfd_section->index])
/* The memory address of section S (vma + offset). */
#define obj_section_addr(s) \
(bfd_get_section_vma ((s)->objfile->abfd, s->the_bfd_section) \
+ obj_section_offset (s))
/* The one-passed-the-end memory address of section S
(vma + size + offset). */
#define obj_section_endaddr(s) \
(bfd_get_section_vma ((s)->objfile->abfd, s->the_bfd_section) \
+ bfd_get_section_size ((s)->the_bfd_section) \
+ obj_section_offset (s))
/* The "objstats" structure provides a place for gdb to record some /* The "objstats" structure provides a place for gdb to record some
interesting information about its internal state at runtime, on a interesting information about its internal state at runtime, on a

View file

@ -995,8 +995,9 @@ sym_info (char *arg, int from_tty)
sect = osect->the_bfd_section; sect = osect->the_bfd_section;
sect_addr = overlay_mapped_address (addr, sect); sect_addr = overlay_mapped_address (addr, sect);
if (osect->addr <= sect_addr && sect_addr < osect->endaddr && if (obj_section_addr (osect) <= sect_addr
(msymbol = lookup_minimal_symbol_by_pc_section (sect_addr, sect))) && sect_addr < obj_section_endaddr (osect)
&& (msymbol = lookup_minimal_symbol_by_pc_section (sect_addr, sect)))
{ {
matches = 1; matches = 1;
offset = sect_addr - SYMBOL_VALUE_ADDRESS (msymbol); offset = sect_addr - SYMBOL_VALUE_ADDRESS (msymbol);

View file

@ -895,56 +895,6 @@ syms_from_objfile (struct objfile *objfile,
init_objfile_sect_indices (objfile); init_objfile_sect_indices (objfile);
} }
#ifndef DEPRECATED_IBM6000_TARGET
/* This is a SVR4/SunOS specific hack, I think. In any event, it
screws RS/6000. sym_offsets should be doing this sort of thing,
because it knows the mapping between bfd sections and
section_offsets. */
/* This is a hack. As far as I can tell, section offsets are not
target dependent. They are all set to addr with a couple of
exceptions. The exceptions are sysvr4 shared libraries, whose
offsets are kept in solib structures anyway and rs6000 xcoff
which handles shared libraries in a completely unique way.
Section offsets are built similarly, except that they are built
by adding addr in all cases because there is no clear mapping
from section_offsets into actual sections. Note that solib.c
has a different algorithm for finding section offsets.
These should probably all be collapsed into some target
independent form of shared library support. FIXME. */
if (addrs)
{
struct obj_section *s;
/* Map section offsets in "addr" back to the object's
sections by comparing the section names with bfd's
section names. Then adjust the section address by
the offset. */ /* for gdb/13815 */
ALL_OBJFILE_OSECTIONS (objfile, s)
{
CORE_ADDR s_addr = 0;
int i;
for (i = 0;
!s_addr && i < addrs->num_sections && addrs->other[i].name;
i++)
if (strcmp (bfd_section_name (s->objfile->obfd,
s->the_bfd_section),
addrs->other[i].name) == 0)
s_addr = addrs->other[i].addr; /* end added for gdb/13815 */
s->addr -= s->offset;
s->addr += s_addr;
s->endaddr -= s->offset;
s->endaddr += s_addr;
s->offset += s_addr;
}
}
#endif /* not DEPRECATED_IBM6000_TARGET */
(*objfile->sf->sym_read) (objfile, mainline); (*objfile->sf->sym_read) (objfile, mainline);
/* Don't allow char * to have a typename (else would get caddr_t). /* Don't allow char * to have a typename (else would get caddr_t).

View file

@ -1081,7 +1081,8 @@ fixup_section (struct general_symbol_info *ginfo,
int idx = s->the_bfd_section->index; int idx = s->the_bfd_section->index;
CORE_ADDR offset = ANOFFSET (objfile->section_offsets, idx); CORE_ADDR offset = ANOFFSET (objfile->section_offsets, idx);
if (s->addr - offset <= addr && addr < s->endaddr - offset) if (obj_section_addr (s) - offset <= addr
&& addr < obj_section_endaddr (s) - offset)
{ {
ginfo->bfd_section = s->the_bfd_section; ginfo->bfd_section = s->the_bfd_section;
ginfo->section = idx; ginfo->section = idx;