Make sure section addresses from a shared object are correctly set in

a new struct objfile.
This commit is contained in:
Kevin Buettner 2000-03-21 22:37:42 +00:00
parent cb7450ea08
commit 62557bbcee
5 changed files with 119 additions and 36 deletions

View file

@ -1,3 +1,20 @@
2000-03-21 Kevin Buettner <kevinb@redhat.com>
* symtab.h (MAX_SECTIONS, struct section_addr_info,
symbol_file_add): Move declarations from here...
* symfile.h: ...to here.
* solib.c (symbol_add_stub): Make symbol_file_add () aware of
all section addresses, not just .text.
* symfile.h, symfile.c (free_section_addr_info,
build_section_addr_info_from_section_table): New functions.
* symfile.h (MAX_SECTIONS): Increase value to 40.
* symfile.c (syms_from_objfile): Add bounds check prior to
accessing ``other'' array in a section_addr_info_struct.
Remove unused variable section_offsets.
(add_symbol_file_command): Remove unused variable text_addr.
2000-03-21 Eli Zaretskii <eliz@is.elta.co.il>
* breakpoint.c (bpstat_stop_status): Don't stop if a read

View file

@ -1155,6 +1155,7 @@ symbol_add_stub (arg)
{
register struct so_list *so = (struct so_list *) arg; /* catch_errs bogon */
CORE_ADDR text_addr = 0;
struct section_addr_info *sap;
/* Have we already loaded this shared object? */
ALL_OBJFILES (so->objfile)
@ -1181,15 +1182,12 @@ symbol_add_stub (arg)
+ LM_ADDR (so);
}
{
struct section_addr_info section_addrs;
memset (&section_addrs, 0, sizeof (section_addrs));
section_addrs.text_addr = text_addr;
so->objfile = symbol_file_add (so->so_name, so->from_tty,
&section_addrs, 0, OBJF_SHARED);
}
sap = build_section_addr_info_from_section_table (so->sections,
so->sections_end);
sap->text_addr = text_addr;
so->objfile = symbol_file_add (so->so_name, so->from_tty,
sap, 0, OBJF_SHARED);
free_section_addr_info (sap);
return (1);
}

View file

@ -461,6 +461,58 @@ find_lowest_section (abfd, sect, obj)
*lowest = sect;
}
/* Build (allocate and populate) a section_addr_info struct from
an existing section table. */
extern struct section_addr_info *
build_section_addr_info_from_section_table (const struct section_table *start,
const struct section_table *end)
{
struct section_addr_info *sap;
const struct section_table *stp;
int oidx;
sap = xmalloc (sizeof (struct section_addr_info));
memset (sap, 0, sizeof (struct section_addr_info));
for (stp = start, oidx = 0; stp != end; stp++)
{
if (strcmp (stp->the_bfd_section->name, ".text") == 0)
sap->text_addr = stp->addr;
else if (strcmp (stp->the_bfd_section->name, ".data") == 0)
sap->data_addr = stp->addr;
else if (strcmp (stp->the_bfd_section->name, ".bss") == 0)
sap->bss_addr = stp->addr;
if (stp->the_bfd_section->flags & (SEC_ALLOC | SEC_LOAD)
&& oidx < MAX_SECTIONS)
{
sap->other[oidx].addr = stp->addr;
sap->other[oidx].name = xstrdup (stp->the_bfd_section->name);
sap->other[oidx].sectindex = stp->the_bfd_section->index;
oidx++;
}
}
return sap;
}
/* Free all memory allocated by build_section_addr_info_from_section_table. */
extern void
free_section_addr_info (struct section_addr_info *sap)
{
int idx;
for (idx = 0; idx < MAX_SECTIONS; idx++)
if (sap->other[idx].name)
free (sap->other[idx].name);
free (sap);
}
/* Parse the user's idea of an offset for dynamic linking, into our idea
of how to represent it for fast symbol reading. This is the default
version of the sym_fns.sym_offsets function for symbol readers that
@ -531,7 +583,6 @@ syms_from_objfile (objfile, addrs, mainline, verbo)
int mainline;
int verbo;
{
struct section_offsets *section_offsets;
asection *lower_sect;
asection *sect;
CORE_ADDR lower_offset;
@ -738,7 +789,9 @@ syms_from_objfile (objfile, addrs, mainline, verbo)
else if (strcmp (s->the_bfd_section->name, ".bss") == 0)
s_addr = addrs->bss_addr;
else
for (i = 0; !s_addr && addrs->other[i].name; i++)
for (i = 0;
!s_addr && i < MAX_SECTIONS && addrs->other[i].name;
i++)
if (strcmp (s->the_bfd_section->name, addrs->other[i].name) == 0)
s_addr = addrs->other[i].addr; /* end added for gdb/13815 */
@ -1460,7 +1513,6 @@ add_symbol_file_command (args, from_tty)
int from_tty;
{
char *name = NULL;
CORE_ADDR text_addr;
int flags = OBJF_USERLOADED;
char *arg;
int expecting_option = 0;

View file

@ -54,6 +54,29 @@ struct psymbol_allocation_list
int size;
};
/* Define an array of addresses to accommodate non-contiguous dynamic
loading of modules. This is for use when entering commands, so we
can keep track of the section names until we read the file and
can map them to bfd sections. This structure is also used by
solib.c to communicate the section addresses in shared objects to
symbol_file_add (). */
#define MAX_SECTIONS 40
struct section_addr_info
{
/* Sections whose names are always known to gdb. */
CORE_ADDR text_addr;
CORE_ADDR data_addr;
CORE_ADDR bss_addr;
/* Sections whose names are file format dependant. */
struct other_sections
{
CORE_ADDR addr;
char *name;
int sectindex;
} other[MAX_SECTIONS];
};
/* Structure to keep track of symbol reading functions for various
object file types. */
@ -163,6 +186,23 @@ syms_from_objfile PARAMS ((struct objfile *, struct section_addr_info *, int, in
extern void
new_symfile_objfile PARAMS ((struct objfile *, int, int));
extern struct objfile *
symbol_file_add PARAMS ((char *, int, struct section_addr_info *, int, int));
/* Build (allocate and populate) a section_addr_info struct from
an existing section table. */
struct section_table;
extern struct section_addr_info *
build_section_addr_info_from_section_table (const struct section_table *start,
const struct section_table *end);
/* Free all memory allocated by build_section_addr_info_from_section_table. */
extern void
free_section_addr_info (struct section_addr_info *);
extern struct partial_symtab *
start_psymtab_common PARAMS ((struct objfile *, struct section_offsets *,
char *, CORE_ADDR,

View file

@ -837,27 +837,6 @@ struct section_offsets
(sizeof (struct section_offsets) \
+ sizeof (((struct section_offsets *) 0)->offsets) * (SECT_OFF_MAX-1))
/* Define an array of addresses to accommodate non-contiguous dynamic
loading of modules. This is for use when entering commands, so we
can keep track of the section names until we read the file and
can map them to bfd sections. */
#define MAX_SECTIONS 12
struct section_addr_info
{
/* Sections whose names are always known to gdb. */
CORE_ADDR text_addr;
CORE_ADDR data_addr;
CORE_ADDR bss_addr;
/* Sections whose names are file format dependant. */
struct other_sections
{
CORE_ADDR addr;
char *name;
int sectindex;
} other[MAX_SECTIONS];
};
/* Each source file or header is represented by a struct symtab.
These objects are chained through the `next' field. */
@ -1437,9 +1416,6 @@ extern struct symtab *
extern void
clear_solib PARAMS ((void));
extern struct objfile *
symbol_file_add PARAMS ((char *, int, struct section_addr_info *, int, int));
/* source.c */
extern int