* elfread.c (elf_symtab_read): Avoid use of SECT_OFF_MAX.

(elfstab_offset_sections): Likewise.
	* gdb-stabs.h (stab_section_info): Likewise.
	* i386-interix-tdep.c (pei_adjust_objfile_offsets): Likewise.
	* objfiles.c (objfile_relocate): Likewise.
	* pa64solib.c (pa64_solib_add_solib_objfile): Likewise.
	* remote.c (get_offsets): Likewise.
	(remote_cisco_objfile_relocate): Likewise.
	* somread.c (som_symfile_offsets): Likewise.
	* symfile.c (alloc_section_addr_info): New function.
	(build_section_addr_info_from_section_tab): Use it.
	(free_section_addr_info): Adjust.
	(default_symfile_offsets): Avoid use of SECT_OFF_MAX.
	(syms_from_objfile): Allocate local_addr dynamically.
	(symbol_file_add_with_addrs_or_offsets): Allocate orig_addrs
	dynamically.
	(add_symbol_file_command): Allocate sect_opts dynamically.
	(reread_symbols): Avoid use of SECT_OFF_MAX.
	* symfile.h (section_addr_info): Do not use MAX_SECTIONS.
	(alloc_section_addr_info): Declare it.
	* symtab.h (SIZEOF_SECTION_OFFSETS): Remove.
	* win32-nat.c (solib_symbols_add): Allocate section_addrs
	dynamically.
	* xcoffread.c (xcoff_symfile_offsets): Avoid use of SECT_OFF_MAX.
This commit is contained in:
Mark Mitchell 2003-06-06 23:33:00 +00:00
parent 539ee71a87
commit a39a16c41b
14 changed files with 185 additions and 79 deletions

View file

@ -1,3 +1,30 @@
2003-06-06 Mark Mitchell <mark@codesourcery.com>
* elfread.c (elf_symtab_read): Avoid use of SECT_OFF_MAX.
(elfstab_offset_sections): Likewise.
* gdb-stabs.h (stab_section_info): Likewise.
* i386-interix-tdep.c (pei_adjust_objfile_offsets): Likewise.
* objfiles.c (objfile_relocate): Likewise.
* pa64solib.c (pa64_solib_add_solib_objfile): Likewise.
* remote.c (get_offsets): Likewise.
(remote_cisco_objfile_relocate): Likewise.
* somread.c (som_symfile_offsets): Likewise.
* symfile.c (alloc_section_addr_info): New function.
(build_section_addr_info_from_section_tab): Use it.
(free_section_addr_info): Adjust.
(default_symfile_offsets): Avoid use of SECT_OFF_MAX.
(syms_from_objfile): Allocate local_addr dynamically.
(symbol_file_add_with_addrs_or_offsets): Allocate orig_addrs
dynamically.
(add_symbol_file_command): Allocate sect_opts dynamically.
(reread_symbols): Avoid use of SECT_OFF_MAX.
* symfile.h (section_addr_info): Do not use MAX_SECTIONS.
(alloc_section_addr_info): Declare it.
* symtab.h (SIZEOF_SECTION_OFFSETS): Remove.
* win32-nat.c (solib_symbols_add): Allocate section_addrs
dynamically.
* xcoffread.c (xcoff_symfile_offsets): Avoid use of SECT_OFF_MAX.
2003-06-06 Andrew Cagney <cagney@redhat.com> 2003-06-06 Andrew Cagney <cagney@redhat.com>
* d10v-tdep.c (struct d10v_unwind_cache): Delete "return_pc". * d10v-tdep.c (struct d10v_unwind_cache): Delete "return_pc".

View file

@ -372,34 +372,47 @@ elf_symtab_read (struct objfile *objfile, int dynamic)
} }
else if (sym->flags & BSF_LOCAL) else if (sym->flags & BSF_LOCAL)
{ {
int special_local_sym_p = 0;
/* Named Local variable in a Data section. Check its /* Named Local variable in a Data section. Check its
name for stabs-in-elf. The STREQ macro checks the name for stabs-in-elf. The STREQ macro checks the
first character inline, so we only actually do a first character inline, so we only actually do a
strcmp function call on names that start with 'B' strcmp function call on names that start with 'B'
or 'D' */ or 'D' */
index = SECT_OFF_MAX;
if (STREQ ("Bbss.bss", sym->name)) if (STREQ ("Bbss.bss", sym->name))
{ {
index = SECT_OFF_BSS (objfile); index = SECT_OFF_BSS (objfile);
special_local_sym_p = 1;
} }
else if (STREQ ("Ddata.data", sym->name)) else if (STREQ ("Ddata.data", sym->name))
{ {
index = SECT_OFF_DATA (objfile); index = SECT_OFF_DATA (objfile);
special_local_sym_p = 1;
} }
else if (STREQ ("Drodata.rodata", sym->name)) else if (STREQ ("Drodata.rodata", sym->name))
{ {
index = SECT_OFF_RODATA (objfile); index = SECT_OFF_RODATA (objfile);
special_local_sym_p = 1;
} }
if (index != SECT_OFF_MAX) if (special_local_sym_p)
{ {
/* Found a special local symbol. Allocate a /* Found a special local symbol. Allocate a
sectinfo, if needed, and fill it in. */ sectinfo, if needed, and fill it in. */
if (sectinfo == NULL) if (sectinfo == NULL)
{ {
int max_index;
size_t size;
max_index
= max (SECT_OFF_BSS (objfile),
max (SECT_OFF_DATA (objfile),
SECT_OFF_RODATA (objfile)));
size = (sizeof (struct stab_section_info)
+ (sizeof (CORE_ADDR)
* (max_index - 1)));
sectinfo = (struct stab_section_info *) sectinfo = (struct stab_section_info *)
xmmalloc (objfile->md, sizeof (*sectinfo)); xmmalloc (objfile->md, size);
memset (sectinfo, 0, memset (sectinfo, 0, size);
sizeof (*sectinfo)); sectinfo->num_sections = max_index;
if (filesym == NULL) if (filesym == NULL)
{ {
complaint (&symfile_complaints, complaint (&symfile_complaints,
@ -740,8 +753,9 @@ elfstab_offset_sections (struct objfile *objfile, struct partial_symtab *pst)
/* Found it! Allocate a new psymtab struct, and fill it in. */ /* Found it! Allocate a new psymtab struct, and fill it in. */
maybe->found++; maybe->found++;
pst->section_offsets = (struct section_offsets *) pst->section_offsets = (struct section_offsets *)
obstack_alloc (&objfile->psymbol_obstack, SIZEOF_SECTION_OFFSETS); obstack_alloc (&objfile->psymbol_obstack,
for (i = 0; i < SECT_OFF_MAX; i++) SIZEOF_N_SECTION_OFFSETS (objfile->num_sections));
for (i = 0; i < maybe->num_sections; i++)
(pst->section_offsets)->offsets[i] = maybe->sections[i]; (pst->section_offsets)->offsets[i] = maybe->sections[i];
return; return;
} }

View file

@ -29,8 +29,6 @@
#if !defined (GDBSTABS_H) #if !defined (GDBSTABS_H)
#define GDBSTABS_H #define GDBSTABS_H
#define SECT_OFF_MAX 64 /* Count of possible values */
/* The stab_section_info chain remembers info from the ELF symbol table, /* The stab_section_info chain remembers info from the ELF symbol table,
while psymtabs are being built for the other symbol tables in the while psymtabs are being built for the other symbol tables in the
objfile. It is destroyed at the complation of psymtab-reading. objfile. It is destroyed at the complation of psymtab-reading.
@ -39,9 +37,10 @@
struct stab_section_info struct stab_section_info
{ {
char *filename; char *filename;
CORE_ADDR sections[SECT_OFF_MAX];
struct stab_section_info *next; struct stab_section_info *next;
int found; /* Count of times it's found in searching */ int found; /* Count of times it's found in searching */
size_t num_sections;
CORE_ADDR sections[1];
}; };
/* Information is passed among various dbxread routines for accessing /* Information is passed among various dbxread routines for accessing

View file

@ -90,7 +90,7 @@ pei_adjust_objfile_offsets (struct objfile *objfile,
return; return;
} }
for (i = 0; i < SECT_OFF_MAX; i++) for (i = 0; i < objfile->num_sections; i++)
{ {
(objfile->section_offsets)->offsets[i] += symbols_offset; (objfile->section_offsets)->offsets[i] += symbols_offset;
} }

View file

@ -613,7 +613,8 @@ void
objfile_relocate (struct objfile *objfile, struct section_offsets *new_offsets) objfile_relocate (struct objfile *objfile, struct section_offsets *new_offsets)
{ {
struct section_offsets *delta = struct section_offsets *delta =
(struct section_offsets *) alloca (SIZEOF_SECTION_OFFSETS); ((struct section_offsets *)
alloca (SIZEOF_N_SECTION_OFFSETS (objfile->num_sections)));
{ {
int i; int i;

View file

@ -222,9 +222,9 @@ pa64_solib_add_solib_objfile (struct so_list *so, char *name, int from_tty,
bfd *tmp_bfd; bfd *tmp_bfd;
asection *sec; asection *sec;
obj_private_data_t *obj_private; obj_private_data_t *obj_private;
struct section_addr_info section_addrs; struct section_addr_info *section_addrs;
struct cleanup *my_cleanups;
memset (&section_addrs, 0, sizeof (section_addrs));
/* We need the BFD so that we can look at its sections. We open up the /* We need the BFD so that we can look at its sections. We open up the
file temporarily, then close it when we are done. */ file temporarily, then close it when we are done. */
tmp_bfd = bfd_openr (name, gnutarget); tmp_bfd = bfd_openr (name, gnutarget);
@ -262,15 +262,18 @@ pa64_solib_add_solib_objfile (struct so_list *so, char *name, int from_tty,
text_addr += sec->filepos; text_addr += sec->filepos;
} }
section_addrs = alloc_section_addr_info (bfd_count_sections (tmp_bfd));
my_cleanups = make_cleanup (xfree, section_addrs);
/* We are done with the temporary bfd. Get rid of it and make sure /* We are done with the temporary bfd. Get rid of it and make sure
nobody else can us it. */ nobody else can us it. */
bfd_close (tmp_bfd); bfd_close (tmp_bfd);
tmp_bfd = NULL; tmp_bfd = NULL;
/* Now let the generic code load up symbols for this library. */ /* Now let the generic code load up symbols for this library. */
section_addrs.other[0].addr = text_addr; section_addrs->other[0].addr = text_addr;
section_addrs.other[0].name = ".text"; section_addrs->other[0].name = ".text";
so->objfile = symbol_file_add (name, from_tty, &section_addrs, 0, OBJF_SHARED); so->objfile = symbol_file_add (name, from_tty, section_addrs, 0, OBJF_SHARED);
so->abfd = so->objfile->obfd; so->abfd = so->objfile->obfd;
/* Mark this as a shared library and save private data. */ /* Mark this as a shared library and save private data. */
@ -289,6 +292,7 @@ pa64_solib_add_solib_objfile (struct so_list *so, char *name, int from_tty,
obj_private = (obj_private_data_t *) so->objfile->obj_private; obj_private = (obj_private_data_t *) so->objfile->obj_private;
obj_private->so_info = so; obj_private->so_info = so;
obj_private->dp = so->pa64_solib_desc.linkage_ptr; obj_private->dp = so->pa64_solib_desc.linkage_ptr;
do_cleanups (my_cleanups);
} }
/* Load debugging information for a shared library. TARGET may be /* Load debugging information for a shared library. TARGET may be

View file

@ -1989,8 +1989,10 @@ get_offsets (void)
if (symfile_objfile == NULL) if (symfile_objfile == NULL)
return; return;
offs = (struct section_offsets *) alloca (SIZEOF_SECTION_OFFSETS); offs = ((struct section_offsets *)
memcpy (offs, symfile_objfile->section_offsets, SIZEOF_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));
offs->offsets[SECT_OFF_TEXT (symfile_objfile)] = text_addr; offs->offsets[SECT_OFF_TEXT (symfile_objfile)] = text_addr;
@ -2101,8 +2103,10 @@ remote_cisco_objfile_relocate (bfd_signed_vma text_off, bfd_signed_vma data_off,
broken for xcoff, dwarf, sdb-coff, etc. But there is no broken for xcoff, dwarf, sdb-coff, etc. But there is no
simple canonical representation for this stuff. */ simple canonical representation for this stuff. */
offs = (struct section_offsets *) alloca (SIZEOF_SECTION_OFFSETS); offs = (struct section_offsets *)
memcpy (offs, symfile_objfile->section_offsets, SIZEOF_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));
offs->offsets[SECT_OFF_TEXT (symfile_objfile)] = text_off; offs->offsets[SECT_OFF_TEXT (symfile_objfile)] = text_off;
offs->offsets[SECT_OFF_DATA (symfile_objfile)] = data_off; offs->offsets[SECT_OFF_DATA (symfile_objfile)] = data_off;

View file

@ -430,9 +430,10 @@ som_symfile_offsets (struct objfile *objfile, struct section_addr_info *addrs)
int i; int i;
CORE_ADDR text_addr; CORE_ADDR text_addr;
objfile->num_sections = SECT_OFF_MAX; objfile->num_sections = bfd_count_sections (objfile->obfd);
objfile->section_offsets = (struct section_offsets *) objfile->section_offsets = (struct section_offsets *)
obstack_alloc (&objfile->psymbol_obstack, SIZEOF_SECTION_OFFSETS); obstack_alloc (&objfile->psymbol_obstack,
SIZEOF_N_SECTION_OFFSETS (objfile->num_sections));
/* FIXME: ezannoni 2000-04-20 The section names in SOM are not /* FIXME: ezannoni 2000-04-20 The section names in SOM are not
.text, .data, etc, but $TEXT$, $DATA$,... We should initialize .text, .data, etc, but $TEXT$, $DATA$,... We should initialize
@ -457,7 +458,7 @@ som_symfile_offsets (struct objfile *objfile, struct section_addr_info *addrs)
break; break;
text_addr = addrs->other[i].addr; text_addr = addrs->other[i].addr;
for (i = 0; i < SECT_OFF_MAX; i++) for (i = 0; i < objfile->num_sections; i++)
(objfile->section_offsets)->offsets[i] = text_addr; (objfile->section_offsets)->offsets[i] = text_addr;
} }
} }

View file

@ -401,6 +401,22 @@ find_lowest_section (bfd *abfd, asection *sect, void *obj)
*lowest = sect; *lowest = sect;
} }
/* Create a new section_addr_info, with room for NUM_SECTIONS. */
struct section_addr_info *
alloc_section_addr_info (size_t num_sections)
{
struct section_addr_info *sap;
size_t size;
size = (sizeof (struct section_addr_info)
+ sizeof (struct other_sections) * (num_sections - 1));
sap = (struct section_addr_info *) xmalloc (size);
memset (sap, 0, size);
sap->num_sections = num_sections;
return sap;
}
/* Build (allocate and populate) a section_addr_info struct from /* Build (allocate and populate) a section_addr_info struct from
an existing section table. */ an existing section table. */
@ -413,14 +429,13 @@ build_section_addr_info_from_section_table (const struct section_table *start,
const struct section_table *stp; const struct section_table *stp;
int oidx; int oidx;
sap = xmalloc (sizeof (struct section_addr_info)); sap = alloc_section_addr_info (end - start);
memset (sap, 0, sizeof (struct section_addr_info));
for (stp = start, oidx = 0; stp != end; stp++) for (stp = start, oidx = 0; stp != end; stp++)
{ {
if (bfd_get_section_flags (stp->bfd, if (bfd_get_section_flags (stp->bfd,
stp->the_bfd_section) & (SEC_ALLOC | SEC_LOAD) stp->the_bfd_section) & (SEC_ALLOC | SEC_LOAD)
&& oidx < MAX_SECTIONS) && oidx < end - start)
{ {
sap->other[oidx].addr = stp->addr; sap->other[oidx].addr = stp->addr;
sap->other[oidx].name sap->other[oidx].name
@ -441,7 +456,7 @@ free_section_addr_info (struct section_addr_info *sap)
{ {
int idx; int idx;
for (idx = 0; idx < MAX_SECTIONS; idx++) for (idx = 0; idx < sap->num_sections; idx++)
if (sap->other[idx].name) if (sap->other[idx].name)
xfree (sap->other[idx].name); xfree (sap->other[idx].name);
xfree (sap); xfree (sap);
@ -514,14 +529,16 @@ default_symfile_offsets (struct objfile *objfile,
{ {
int i; int i;
objfile->num_sections = SECT_OFF_MAX; objfile->num_sections = bfd_count_sections (objfile->obfd);
objfile->section_offsets = (struct section_offsets *) objfile->section_offsets = (struct section_offsets *)
obstack_alloc (&objfile->psymbol_obstack, SIZEOF_SECTION_OFFSETS); obstack_alloc (&objfile->psymbol_obstack,
memset (objfile->section_offsets, 0, SIZEOF_SECTION_OFFSETS); SIZEOF_N_SECTION_OFFSETS (objfile->num_sections));
memset (objfile->section_offsets, 0,
SIZEOF_N_SECTION_OFFSETS (objfile->num_sections));
/* Now calculate offsets for section that were specified by the /* Now calculate offsets for section that were specified by the
caller. */ caller. */
for (i = 0; i < MAX_SECTIONS && addrs->other[i].name; i++) for (i = 0; i < addrs->num_sections && addrs->other[i].name; i++)
{ {
struct other_sections *osp ; struct other_sections *osp ;
@ -584,23 +601,12 @@ syms_from_objfile (struct objfile *objfile,
asection *lower_sect; asection *lower_sect;
asection *sect; asection *sect;
CORE_ADDR lower_offset; CORE_ADDR lower_offset;
struct section_addr_info local_addr; struct section_addr_info *local_addr = NULL;
struct cleanup *old_chain; struct cleanup *old_chain;
int i; int i;
gdb_assert (! (addrs && offsets)); gdb_assert (! (addrs && offsets));
/* If ADDRS and OFFSETS are both NULL, put together a dummy address
list. We now establish the convention that an addr of zero means
no load address was specified. */
if (! addrs && ! offsets)
{
memset (&local_addr, 0, sizeof (local_addr));
addrs = &local_addr;
}
/* Now either addrs or offsets is non-zero. */
init_entry_point_info (objfile); init_entry_point_info (objfile);
find_sym_fns (objfile); find_sym_fns (objfile);
@ -611,6 +617,19 @@ syms_from_objfile (struct objfile *objfile,
if an error occurs during symbol reading. */ if an error occurs during symbol reading. */
old_chain = make_cleanup_free_objfile (objfile); old_chain = make_cleanup_free_objfile (objfile);
/* If ADDRS and OFFSETS are both NULL, put together a dummy address
list. We now establish the convention that an addr of zero means
no load address was specified. */
if (! addrs && ! offsets)
{
local_addr
= alloc_section_addr_info (bfd_count_sections (objfile->obfd));
make_cleanup (xfree, local_addr);
addrs = local_addr;
}
/* Now either addrs or offsets is non-zero. */
if (mainline) if (mainline)
{ {
/* We will modify the main symbol table, make sure that all its users /* We will modify the main symbol table, make sure that all its users
@ -674,7 +693,7 @@ syms_from_objfile (struct objfile *objfile,
/* Calculate offsets for sections. */ /* Calculate offsets for sections. */
if (addrs) if (addrs)
for (i=0 ; i < MAX_SECTIONS && addrs->other[i].name; i++) for (i=0 ; i < addrs->num_sections && addrs->other[i].name; i++)
{ {
if (addrs->other[i].addr != 0) if (addrs->other[i].addr != 0)
{ {
@ -758,7 +777,7 @@ syms_from_objfile (struct objfile *objfile,
int i; int i;
for (i = 0; for (i = 0;
!s_addr && i < MAX_SECTIONS && addrs->other[i].name; !s_addr && i < addrs->num_sections && addrs->other[i].name;
i++) i++)
if (strcmp (bfd_section_name (s->objfile->obfd, if (strcmp (bfd_section_name (s->objfile->obfd,
s->the_bfd_section), s->the_bfd_section),
@ -849,10 +868,8 @@ symbol_file_add_with_addrs_or_offsets (char *name, int from_tty,
struct partial_symtab *psymtab; struct partial_symtab *psymtab;
char *debugfile; char *debugfile;
bfd *abfd; bfd *abfd;
struct section_addr_info orig_addrs; struct section_addr_info *orig_addrs;
struct cleanup *my_cleanups;
if (addrs)
orig_addrs = *addrs;
/* Open a bfd for the file, and give user a chance to burp if we'd be /* Open a bfd for the file, and give user a chance to burp if we'd be
interactively wiping out any existing symbols. */ interactively wiping out any existing symbols. */
@ -867,6 +884,11 @@ symbol_file_add_with_addrs_or_offsets (char *name, int from_tty,
objfile = allocate_objfile (abfd, flags); objfile = allocate_objfile (abfd, flags);
orig_addrs = alloc_section_addr_info (bfd_count_sections (abfd));
my_cleanups = make_cleanup (xfree, orig_addrs);
if (addrs)
*orig_addrs = *addrs;
/* If the objfile uses a mapped symbol file, and we have a psymtab for /* If the objfile uses a mapped symbol file, and we have a psymtab for
it, then skip reading any symbols at this time. */ it, then skip reading any symbols at this time. */
@ -933,7 +955,7 @@ symbol_file_add_with_addrs_or_offsets (char *name, int from_tty,
if (addrs != NULL) if (addrs != NULL)
{ {
objfile->separate_debug_objfile objfile->separate_debug_objfile
= symbol_file_add (debugfile, from_tty, &orig_addrs, 0, flags); = symbol_file_add (debugfile, from_tty, orig_addrs, 0, flags);
} }
else else
{ {
@ -972,6 +994,8 @@ symbol_file_add_with_addrs_or_offsets (char *name, int from_tty,
time. */ time. */
gdb_flush (gdb_stdout); gdb_flush (gdb_stdout);
do_cleanups (my_cleanups);
if (objfile->sf == NULL) if (objfile->sf == NULL)
return objfile; /* No symbols. */ return objfile; /* No symbols. */
@ -1689,15 +1713,21 @@ add_symbol_file_command (char *args, int from_tty)
int expecting_sec_name = 0; int expecting_sec_name = 0;
int expecting_sec_addr = 0; int expecting_sec_addr = 0;
struct struct sect_opt
{ {
char *name; char *name;
char *value; char *value;
} sect_opts[SECT_OFF_MAX]; };
struct section_addr_info section_addrs; struct section_addr_info *section_addrs;
struct sect_opt *sect_opts = NULL;
size_t num_sect_opts = 0;
struct cleanup *my_cleanups = make_cleanup (null_cleanup, NULL); struct cleanup *my_cleanups = make_cleanup (null_cleanup, NULL);
num_sect_opts = 16;
sect_opts = (struct sect_opt *) xmalloc (num_sect_opts
* sizeof (struct sect_opt));
dont_repeat (); dont_repeat ();
if (args == NULL) if (args == NULL)
@ -1706,9 +1736,6 @@ add_symbol_file_command (char *args, int from_tty)
/* Make a copy of the string that we can safely write into. */ /* Make a copy of the string that we can safely write into. */
args = xstrdup (args); args = xstrdup (args);
/* Ensure section_addrs is initialized */
memset (&section_addrs, 0, sizeof (section_addrs));
while (*args != '\000') while (*args != '\000')
{ {
/* Any leading spaces? */ /* Any leading spaces? */
@ -1741,7 +1768,14 @@ add_symbol_file_command (char *args, int from_tty)
to load the program. */ to load the program. */
sect_opts[section_index].name = ".text"; sect_opts[section_index].name = ".text";
sect_opts[section_index].value = arg; sect_opts[section_index].value = arg;
section_index++; if (++section_index > num_sect_opts)
{
num_sect_opts *= 2;
sect_opts = ((struct sect_opt *)
xrealloc (sect_opts,
num_sect_opts
* sizeof (struct sect_opt)));
}
} }
else else
{ {
@ -1758,8 +1792,6 @@ add_symbol_file_command (char *args, int from_tty)
else else
if (strcmp (arg, "-s") == 0) if (strcmp (arg, "-s") == 0)
{ {
if (section_index >= SECT_OFF_MAX)
error ("Too many sections specified.");
expecting_sec_name = 1; expecting_sec_name = 1;
expecting_sec_addr = 1; expecting_sec_addr = 1;
} }
@ -1776,7 +1808,14 @@ add_symbol_file_command (char *args, int from_tty)
{ {
sect_opts[section_index].value = arg; sect_opts[section_index].value = arg;
expecting_sec_addr = 0; expecting_sec_addr = 0;
section_index++; if (++section_index > num_sect_opts)
{
num_sect_opts *= 2;
sect_opts = ((struct sect_opt *)
xrealloc (sect_opts,
num_sect_opts
* sizeof (struct sect_opt)));
}
} }
else else
error ("USAGE: add-symbol-file <filename> <textaddress> [-mapped] [-readnow] [-s <secname> <addr>]*"); error ("USAGE: add-symbol-file <filename> <textaddress> [-mapped] [-readnow] [-s <secname> <addr>]*");
@ -1792,6 +1831,8 @@ add_symbol_file_command (char *args, int from_tty)
string. */ string. */
printf_filtered ("add symbol table from file \"%s\" at\n", filename); printf_filtered ("add symbol table from file \"%s\" at\n", filename);
section_addrs = alloc_section_addr_info (section_index);
make_cleanup (xfree, section_addrs);
for (i = 0; i < section_index; i++) for (i = 0; i < section_index; i++)
{ {
CORE_ADDR addr; CORE_ADDR addr;
@ -1806,8 +1847,8 @@ add_symbol_file_command (char *args, int from_tty)
/* Here we store the section offsets in the order they were /* Here we store the section offsets in the order they were
entered on the command line. */ entered on the command line. */
section_addrs.other[sec_num].name = sec; section_addrs->other[sec_num].name = sec;
section_addrs.other[sec_num].addr = addr; section_addrs->other[sec_num].addr = addr;
printf_filtered ("\t%s_addr = %s\n", printf_filtered ("\t%s_addr = %s\n",
sec, sec,
local_hex_string ((unsigned long)addr)); local_hex_string ((unsigned long)addr));
@ -1823,7 +1864,7 @@ add_symbol_file_command (char *args, int from_tty)
if (from_tty && (!query ("%s", ""))) if (from_tty && (!query ("%s", "")))
error ("Not confirmed."); error ("Not confirmed.");
symbol_file_add (filename, from_tty, &section_addrs, 0, flags); symbol_file_add (filename, from_tty, section_addrs, 0, flags);
/* Getting new symbols may change our opinion about what is /* Getting new symbols may change our opinion about what is
frameless. */ frameless. */
@ -1920,8 +1961,10 @@ reread_symbols (void)
/* Save the offsets, we will nuke them with the rest of the /* Save the offsets, we will nuke them with the rest of the
psymbol_obstack. */ psymbol_obstack. */
num_offsets = objfile->num_sections; num_offsets = objfile->num_sections;
offsets = (struct section_offsets *) alloca (SIZEOF_SECTION_OFFSETS); offsets = ((struct section_offsets *)
memcpy (offsets, objfile->section_offsets, SIZEOF_SECTION_OFFSETS); alloca (SIZEOF_N_SECTION_OFFSETS (num_offsets)));
memcpy (offsets, objfile->section_offsets,
SIZEOF_N_SECTION_OFFSETS (num_offsets));
/* Nuke all the state that we will re-read. Much of the following /* Nuke all the state that we will re-read. Much of the following
code which sets things to NULL really is necessary to tell code which sets things to NULL really is necessary to tell
@ -1989,8 +2032,10 @@ reread_symbols (void)
/* We use the same section offsets as from last time. I'm not /* We use the same section offsets as from last time. I'm not
sure whether that is always correct for shared libraries. */ sure whether that is always correct for shared libraries. */
objfile->section_offsets = (struct section_offsets *) objfile->section_offsets = (struct section_offsets *)
obstack_alloc (&objfile->psymbol_obstack, SIZEOF_SECTION_OFFSETS); obstack_alloc (&objfile->psymbol_obstack,
memcpy (objfile->section_offsets, offsets, SIZEOF_SECTION_OFFSETS); SIZEOF_N_SECTION_OFFSETS (num_offsets));
memcpy (objfile->section_offsets, offsets,
SIZEOF_N_SECTION_OFFSETS (num_offsets));
objfile->num_sections = num_offsets; objfile->num_sections = num_offsets;
/* What the hell is sym_new_init for, anyway? The concept of /* What the hell is sym_new_init for, anyway? The concept of

View file

@ -67,16 +67,18 @@ struct psymbol_allocation_list
solib.c to communicate the section addresses in shared objects to solib.c to communicate the section addresses in shared objects to
symbol_file_add (). */ symbol_file_add (). */
#define MAX_SECTIONS 64
struct section_addr_info struct section_addr_info
{ {
/* The number of sections for which address information is
available. */
size_t num_sections;
/* Sections whose names are file format dependent. */ /* Sections whose names are file format dependent. */
struct other_sections struct other_sections
{ {
CORE_ADDR addr; CORE_ADDR addr;
char *name; char *name;
int sectindex; int sectindex;
} other[MAX_SECTIONS]; } other[1];
}; };
/* Structure to keep track of symbol reading functions for various /* Structure to keep track of symbol reading functions for various
@ -185,6 +187,11 @@ extern void new_symfile_objfile (struct objfile *, int, int);
extern struct objfile *symbol_file_add (char *, int, extern struct objfile *symbol_file_add (char *, int,
struct section_addr_info *, int, int); struct section_addr_info *, int, int);
/* Create a new section_addr_info, with room for NUM_SECTIONS. */
extern struct section_addr_info *
alloc_section_addr_info (size_t num_sections);
/* Build (allocate and populate) a section_addr_info struct from /* Build (allocate and populate) a section_addr_info struct from
an existing section table. */ an existing section table. */

View file

@ -743,9 +743,6 @@ struct section_offsets
(sizeof (struct section_offsets) \ (sizeof (struct section_offsets) \
+ sizeof (((struct section_offsets *) 0)->offsets) * ((n)-1)) + sizeof (((struct section_offsets *) 0)->offsets) * ((n)-1))
/* The maximum possible size of a section_offsets table. */
#define SIZEOF_SECTION_OFFSETS (SIZEOF_N_SECTION_OFFSETS (SECT_OFF_MAX))
/* Each source file or header is represented by a struct symtab. /* Each source file or header is represented by a struct symtab.
These objects are chained through the `next' field. */ These objects are chained through the `next' field. */

View file

@ -842,14 +842,17 @@ solib_symbols_add (char *name, int from_tty, CORE_ADDR load_addr)
else else
{ {
/* Fallback on handling just the .text section. */ /* Fallback on handling just the .text section. */
struct section_addr_info section_addrs; struct section_addr_info *section_addrs;
struct cleanup *my_cleanups;
memset (&section_addrs, 0, sizeof (section_addrs)); section_addrs = alloc_section_addr_info (1);
my_cleanups = make_cleanup (xfree, section_addrs);
section_addrs.other[0].name = ".text"; section_addrs.other[0].name = ".text";
section_addrs.other[0].addr = load_addr; section_addrs.other[0].addr = load_addr;
result = safe_symbol_file_add (name, from_tty, &section_addrs, result = safe_symbol_file_add (name, from_tty, &section_addrs,
0, OBJF_SHARED); 0, OBJF_SHARED);
do_cleanups (my_cleanups);
} }
return result; return result;

View file

@ -842,14 +842,17 @@ solib_symbols_add (char *name, int from_tty, CORE_ADDR load_addr)
else else
{ {
/* Fallback on handling just the .text section. */ /* Fallback on handling just the .text section. */
struct section_addr_info section_addrs; struct section_addr_info *section_addrs;
struct cleanup *my_cleanups;
memset (&section_addrs, 0, sizeof (section_addrs)); section_addrs = alloc_section_addr_info (1);
my_cleanups = make_cleanup (xfree, section_addrs);
section_addrs.other[0].name = ".text"; section_addrs.other[0].name = ".text";
section_addrs.other[0].addr = load_addr; section_addrs.other[0].addr = load_addr;
result = safe_symbol_file_add (name, from_tty, &section_addrs, result = safe_symbol_file_add (name, from_tty, &section_addrs,
0, OBJF_SHARED); 0, OBJF_SHARED);
do_cleanups (my_cleanups);
} }
return result; return result;

View file

@ -2981,9 +2981,10 @@ xcoff_symfile_offsets (struct objfile *objfile, struct section_addr_info *addrs)
asection *sect = NULL; asection *sect = NULL;
int i; int i;
objfile->num_sections = SECT_OFF_MAX; objfile->num_sections = bfd_count_sections (objfile->obfd);
objfile->section_offsets = (struct section_offsets *) objfile->section_offsets = (struct section_offsets *)
obstack_alloc (&objfile->psymbol_obstack, SIZEOF_SECTION_OFFSETS); obstack_alloc (&objfile->psymbol_obstack,
SIZEOF_N_SECTION_OFFSETS (objfile->num_sections));
/* Initialize the section indexes for future use. */ /* Initialize the section indexes for future use. */
sect = bfd_get_section_by_name (objfile->obfd, ".text"); sect = bfd_get_section_by_name (objfile->obfd, ".text");