This is the mail archive of the gdb-patches@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

PATCH: Fix PR 1171


This patch fixes GDB PR 1171 by removing the SECT_OFF_MAX and
MAX_SECTIONS constants; instead, of using these fixed constants the
number of section entries is computed dynamically.

Tested on i686-pc-linux-gnu (by running the DejaGNU testsuite) and on
sparc-sun-solaris2.9 (by running the test program from the PR).

Comments?

--
Mark Mitchell
CodeSourcery, LLC
mark@codesourcery.com


2003-05-15  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.

Index: elfread.c
===================================================================
RCS file: /cvs/src/src/gdb/elfread.c,v
retrieving revision 1.31
diff -c -5 -p -r1.31 elfread.c
*** elfread.c	20 Feb 2003 18:31:14 -0000	1.31
--- elfread.c	15 May 2003 07:29:13 -0000
*************** elf_symtab_read (struct objfile *objfile
*** 370,407 ****
  			  ms_type = mst_bss;
  			}
  		    }
  		  else if (sym->flags & BSF_LOCAL)
  		    {
  		      /* Named Local variable in a Data section.  Check its
  		         name for stabs-in-elf.  The STREQ macro checks the
  		         first character inline, so we only actually do a
  		         strcmp function call on names that start with 'B'
  		         or 'D' */
- 		      index = SECT_OFF_MAX;
  		      if (STREQ ("Bbss.bss", sym->name))
  			{
  			  index = SECT_OFF_BSS (objfile);
  			}
  		      else if (STREQ ("Ddata.data", sym->name))
  			{
  			  index = SECT_OFF_DATA (objfile);
  			}
  		      else if (STREQ ("Drodata.rodata", sym->name))
  			{
  			  index = SECT_OFF_RODATA (objfile);
  			}
! 		      if (index != SECT_OFF_MAX)
  			{
  			  /* Found a special local symbol.  Allocate a
  			     sectinfo, if needed, and fill it in.  */
  			  if (sectinfo == NULL)
  			    {
  			      sectinfo = (struct stab_section_info *)
! 				xmmalloc (objfile->md, sizeof (*sectinfo));
! 			      memset (sectinfo, 0,
! 				      sizeof (*sectinfo));
  			      if (filesym == NULL)
  				{
  				  complaint (&symfile_complaints,
  					     "elf/stab section information %s without a preceding file symbol",
  					     sym->name);
--- 370,420 ----
  			  ms_type = mst_bss;
  			}
  		    }
  		  else if (sym->flags & BSF_LOCAL)
  		    {
+ 		      int special_local_sym_p = 0;
  		      /* Named Local variable in a Data section.  Check its
  		         name for stabs-in-elf.  The STREQ macro checks the
  		         first character inline, so we only actually do a
  		         strcmp function call on names that start with 'B'
  		         or 'D' */
  		      if (STREQ ("Bbss.bss", sym->name))
  			{
  			  index = SECT_OFF_BSS (objfile);
+ 			  special_local_sym_p = 1;
  			}
  		      else if (STREQ ("Ddata.data", sym->name))
  			{
  			  index = SECT_OFF_DATA (objfile);
+ 			  special_local_sym_p = 1;
  			}
  		      else if (STREQ ("Drodata.rodata", sym->name))
  			{
  			  index = SECT_OFF_RODATA (objfile);
+ 			  special_local_sym_p = 1;
  			}
! 		      if (special_local_sym_p)
  			{
  			  /* Found a special local symbol.  Allocate a
  			     sectinfo, if needed, and fill it in.  */
  			  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 *)
! 				xmmalloc (objfile->md, size);
! 			      memset (sectinfo, 0, size);
! 			      sectinfo->num_sections = max_index;
  			      if (filesym == NULL)
  				{
  				  complaint (&symfile_complaints,
  					     "elf/stab section information %s without a preceding file symbol",
  					     sym->name);
*************** elfstab_offset_sections (struct objfile 
*** 738,749 ****
    if (maybe)
      {
        /* Found it!  Allocate a new psymtab struct, and fill it in.  */
        maybe->found++;
        pst->section_offsets = (struct section_offsets *)
! 	obstack_alloc (&objfile->psymbol_obstack, SIZEOF_SECTION_OFFSETS);
!       for (i = 0; i < SECT_OFF_MAX; i++)
  	(pst->section_offsets)->offsets[i] = maybe->sections[i];
        return;
      }
  
    /* We were unable to find any offsets for this file.  Complain.  */
--- 751,763 ----
    if (maybe)
      {
        /* Found it!  Allocate a new psymtab struct, and fill it in.  */
        maybe->found++;
        pst->section_offsets = (struct section_offsets *)
! 	obstack_alloc (&objfile->psymbol_obstack, 
! 		       SIZEOF_N_SECTION_OFFSETS (objfile->num_sections));
!       for (i = 0; i < maybe->num_sections; i++)
  	(pst->section_offsets)->offsets[i] = maybe->sections[i];
        return;
      }
  
    /* We were unable to find any offsets for this file.  Complain.  */
Index: gdb-stabs.h
===================================================================
RCS file: /cvs/src/src/gdb/gdb-stabs.h,v
retrieving revision 1.6
diff -c -5 -p -r1.6 gdb-stabs.h
*** gdb-stabs.h	31 Jan 2003 19:22:18 -0000	1.6
--- gdb-stabs.h	15 May 2003 07:29:13 -0000
***************
*** 27,49 ****
     each others' functions as required.  */
  
  #if !defined (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,
     while psymtabs are being built for the other symbol tables in the 
     objfile.  It is destroyed at the complation of psymtab-reading.
     Any info that was used from it has been copied into psymtabs.  */
  
  struct stab_section_info
    {
      char *filename;
-     CORE_ADDR sections[SECT_OFF_MAX];
      struct stab_section_info *next;
      int found;			/* Count of times it's found in searching */
    };
  
  /* Information is passed among various dbxread routines for accessing
     symbol files.  A pointer to this structure is kept in the sym_stab_info
     field of the objfile struct.  */
--- 27,48 ----
     each others' functions as required.  */
  
  #if !defined (GDBSTABS_H)
  #define GDBSTABS_H
  
  /* The stab_section_info chain remembers info from the ELF symbol table,
     while psymtabs are being built for the other symbol tables in the 
     objfile.  It is destroyed at the complation of psymtab-reading.
     Any info that was used from it has been copied into psymtabs.  */
  
  struct stab_section_info
    {
      char *filename;
      struct stab_section_info *next;
      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
     symbol files.  A pointer to this structure is kept in the sym_stab_info
     field of the objfile struct.  */
Index: i386-interix-tdep.c
===================================================================
RCS file: /cvs/src/src/gdb/i386-interix-tdep.c,v
retrieving revision 1.9
diff -c -5 -p -r1.9 i386-interix-tdep.c
*** i386-interix-tdep.c	11 Apr 2003 18:15:38 -0000	1.9
--- i386-interix-tdep.c	15 May 2003 07:29:13 -0000
*************** pei_adjust_objfile_offsets (struct objfi
*** 88,98 ****
      case adjust_for_dwarf_restore:
      default:
        return;
      }
  
!   for (i = 0; i < SECT_OFF_MAX; i++)
      {
        (objfile->section_offsets)->offsets[i] += symbols_offset;
      }
  }
  
--- 88,98 ----
      case adjust_for_dwarf_restore:
      default:
        return;
      }
  
!   for (i = 0; i < objfile->num_sections; i++)
      {
        (objfile->section_offsets)->offsets[i] += symbols_offset;
      }
  }
  
Index: objfiles.c
===================================================================
RCS file: /cvs/src/src/gdb/objfiles.c,v
retrieving revision 1.31
diff -c -5 -p -r1.31 objfiles.c
*** objfiles.c	14 May 2003 17:43:18 -0000	1.31
--- objfiles.c	15 May 2003 07:29:14 -0000
*************** free_all_objfiles (void)
*** 611,621 ****
     entries in new_offsets.  */
  void
  objfile_relocate (struct objfile *objfile, struct section_offsets *new_offsets)
  {
    struct section_offsets *delta =
!     (struct section_offsets *) alloca (SIZEOF_SECTION_OFFSETS);
  
    {
      int i;
      int something_changed = 0;
      for (i = 0; i < objfile->num_sections; ++i)
--- 611,622 ----
     entries in new_offsets.  */
  void
  objfile_relocate (struct objfile *objfile, struct section_offsets *new_offsets)
  {
    struct section_offsets *delta =
!     ((struct section_offsets *) 
!      alloca (SIZEOF_N_SECTION_OFFSETS (objfile->num_sections)));
  
    {
      int i;
      int something_changed = 0;
      for (i = 0; i < objfile->num_sections; ++i)
Index: pa64solib.c
===================================================================
RCS file: /cvs/src/src/gdb/pa64solib.c,v
retrieving revision 1.16
diff -c -5 -p -r1.16 pa64solib.c
*** pa64solib.c	4 Dec 2002 17:53:26 -0000	1.16
--- pa64solib.c	15 May 2003 07:29:14 -0000
*************** pa64_solib_add_solib_objfile (struct so_
*** 220,232 ****
  			      CORE_ADDR text_addr)
  {
    bfd *tmp_bfd;
    asection *sec;
    obj_private_data_t *obj_private;
!   struct section_addr_info section_addrs;
  
-   memset (&section_addrs, 0, sizeof (section_addrs));
    /* 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.  */
    tmp_bfd = bfd_openr (name, gnutarget);
    if (tmp_bfd == NULL)
      {
--- 220,232 ----
  			      CORE_ADDR text_addr)
  {
    bfd *tmp_bfd;
    asection *sec;
    obj_private_data_t *obj_private;
!   struct section_addr_info *section_addrs;
!   struct cleanup *my_cleanups;
  
    /* 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.  */
    tmp_bfd = bfd_openr (name, gnutarget);
    if (tmp_bfd == NULL)
      {
*************** pa64_solib_add_solib_objfile (struct so_
*** 260,278 ****
  
        /* ??? Add back in the filepos of that lowest section. */
        text_addr += sec->filepos;
      }
  
    /* We are done with the temporary bfd.  Get rid of it and make sure
       nobody else can us it.  */
    bfd_close (tmp_bfd);
    tmp_bfd = NULL;
  
    /* Now let the generic code load up symbols for this library.  */
!   section_addrs.other[0].addr = text_addr;
!   section_addrs.other[0].name = ".text";
!   so->objfile = symbol_file_add (name, from_tty, &section_addrs, 0, OBJF_SHARED);
    so->abfd = so->objfile->obfd;
  
    /* Mark this as a shared library and save private data.  */
    so->objfile->flags |= OBJF_SHARED;
  
--- 260,281 ----
  
        /* ??? Add back in the filepos of that lowest section. */
        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
       nobody else can us it.  */
    bfd_close (tmp_bfd);
    tmp_bfd = NULL;
  
    /* Now let the generic code load up symbols for this library.  */
!   section_addrs->other[0].addr = text_addr;
!   section_addrs->other[0].name = ".text";
!   so->objfile = symbol_file_add (name, from_tty, section_addrs, 0, OBJF_SHARED);
    so->abfd = so->objfile->obfd;
  
    /* Mark this as a shared library and save private data.  */
    so->objfile->flags |= OBJF_SHARED;
  
*************** pa64_solib_add_solib_objfile (struct so_
*** 287,296 ****
--- 290,300 ----
      }
  
    obj_private = (obj_private_data_t *) so->objfile->obj_private;
    obj_private->so_info = so;
    obj_private->dp = so->pa64_solib_desc.linkage_ptr;
+   do_cleanups (my_cleanups);
  }
  
  /* Load debugging information for a shared library.  TARGET may be
     NULL if we are not attaching to a process or reading a core file.  */
  
Index: remote.c
===================================================================
RCS file: /cvs/src/src/gdb/remote.c,v
retrieving revision 1.98
diff -c -5 -p -r1.98 remote.c
*** remote.c	8 May 2003 20:52:48 -0000	1.98
--- remote.c	15 May 2003 07:29:17 -0000
*************** get_offsets (void)
*** 1983,1994 ****
      error ("Malformed response to offset query, %s", buf);
  
    if (symfile_objfile == NULL)
      return;
  
!   offs = (struct section_offsets *) alloca (SIZEOF_SECTION_OFFSETS);
!   memcpy (offs, symfile_objfile->section_offsets, SIZEOF_SECTION_OFFSETS);
  
    offs->offsets[SECT_OFF_TEXT (symfile_objfile)] = text_addr;
  
    /* This is a temporary kludge to force data and bss to use the same offsets
       because that's what nlmconv does now.  The real solution requires changes
--- 1983,1996 ----
      error ("Malformed response to offset query, %s", buf);
  
    if (symfile_objfile == NULL)
      return;
  
!   offs = ((struct 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;
  
    /* This is a temporary kludge to force data and bss to use the same offsets
       because that's what nlmconv does now.  The real solution requires changes
*************** remote_cisco_objfile_relocate (bfd_signe
*** 2095,2106 ****
      {
        /* FIXME: This code assumes gdb-stabs.h is being used; it's
           broken for xcoff, dwarf, sdb-coff, etc.  But there is no
           simple canonical representation for this stuff.  */
  
!       offs = (struct section_offsets *) alloca (SIZEOF_SECTION_OFFSETS);
!       memcpy (offs, symfile_objfile->section_offsets, SIZEOF_SECTION_OFFSETS);
  
        offs->offsets[SECT_OFF_TEXT (symfile_objfile)] = text_off;
        offs->offsets[SECT_OFF_DATA (symfile_objfile)] = data_off;
        offs->offsets[SECT_OFF_BSS (symfile_objfile)] = bss_off;
  
--- 2097,2110 ----
      {
        /* FIXME: This code assumes gdb-stabs.h is being used; it's
           broken for xcoff, dwarf, sdb-coff, etc.  But there is no
           simple canonical representation for this stuff.  */
  
!       offs = (struct 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_DATA (symfile_objfile)] = data_off;
        offs->offsets[SECT_OFF_BSS (symfile_objfile)] = bss_off;
  
Index: somread.c
===================================================================
RCS file: /cvs/src/src/gdb/somread.c,v
retrieving revision 1.18
diff -c -5 -p -r1.18 somread.c
*** somread.c	29 Mar 2003 23:29:47 -0000	1.18
--- somread.c	15 May 2003 07:29:18 -0000
*************** static void
*** 428,440 ****
  som_symfile_offsets (struct objfile *objfile, struct section_addr_info *addrs)
  {
    int i;
    CORE_ADDR text_addr;
  
!   objfile->num_sections = SECT_OFF_MAX;
    objfile->section_offsets = (struct section_offsets *)
!     obstack_alloc (&objfile->psymbol_obstack, SIZEOF_SECTION_OFFSETS);
  
    /* FIXME: ezannoni 2000-04-20 The section names in SOM are not
       .text, .data, etc, but $TEXT$, $DATA$,... We should initialize
       SET_OFF_* from bfd. (See default_symfile_offsets()). But I don't
       know the correspondence between SOM sections and GDB's idea of
--- 428,441 ----
  som_symfile_offsets (struct objfile *objfile, struct section_addr_info *addrs)
  {
    int i;
    CORE_ADDR text_addr;
  
!   objfile->num_sections = bfd_count_sections (objfile->obfd);
    objfile->section_offsets = (struct 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
       .text, .data, etc, but $TEXT$, $DATA$,... We should initialize
       SET_OFF_* from bfd. (See default_symfile_offsets()). But I don't
       know the correspondence between SOM sections and GDB's idea of
*************** som_symfile_offsets (struct objfile *obj
*** 455,465 ****
        for (i = 0; i < SECT_OFF_MAX && addrs->other[i].name; i++)
  	if (strcmp (addrs->other[i].name, ".text") == 0)
  	  break;
        text_addr = addrs->other[i].addr;
  
!       for (i = 0; i < SECT_OFF_MAX; i++)
  	(objfile->section_offsets)->offsets[i] = text_addr;
      }
  }
  
  /* Read in and initialize the SOM import list which is present
--- 456,466 ----
        for (i = 0; i < SECT_OFF_MAX && addrs->other[i].name; i++)
  	if (strcmp (addrs->other[i].name, ".text") == 0)
  	  break;
        text_addr = addrs->other[i].addr;
  
!       for (i = 0; i < objfile->num_sections; i++)
  	(objfile->section_offsets)->offsets[i] = text_addr;
      }
  }
  
  /* Read in and initialize the SOM import list which is present
Index: symfile.c
===================================================================
RCS file: /cvs/src/src/gdb/symfile.c,v
retrieving revision 1.94
diff -c -5 -p -r1.94 symfile.c
*** symfile.c	14 May 2003 17:43:19 -0000	1.94
--- symfile.c	15 May 2003 07:29:20 -0000
*************** find_lowest_section (bfd *abfd, asection
*** 399,408 ****
--- 399,424 ----
  	   && (bfd_section_size (abfd, (*lowest))
  	       <= bfd_section_size (abfd, 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
     an existing section table. */
  
  extern struct section_addr_info *
*************** build_section_addr_info_from_section_tab
*** 411,428 ****
  {
    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 (bfd_get_section_flags (stp->bfd, 
  				 stp->the_bfd_section) & (SEC_ALLOC | SEC_LOAD)
! 	  && oidx < MAX_SECTIONS)
  	{
  	  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;
--- 427,443 ----
  {
    struct section_addr_info *sap;
    const struct section_table *stp;
    int oidx;
  
!   sap = alloc_section_addr_info (end - start);
  
    for (stp = start, oidx = 0; stp != end; stp++)
      {
        if (bfd_get_section_flags (stp->bfd, 
  				 stp->the_bfd_section) & (SEC_ALLOC | SEC_LOAD)
! 	  && oidx < end - 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;
*************** build_section_addr_info_from_section_tab
*** 439,449 ****
  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)
        xfree (sap->other[idx].name);
    xfree (sap);
  }
  
--- 454,464 ----
  extern void
  free_section_addr_info (struct section_addr_info *sap)
  {
    int idx;
  
!   for (idx = 0; idx < sap->num_sections; idx++)
      if (sap->other[idx].name)
        xfree (sap->other[idx].name);
    xfree (sap);
  }
  
*************** void
*** 512,529 ****
  default_symfile_offsets (struct objfile *objfile,
  			 struct section_addr_info *addrs)
  {
    int i;
  
!   objfile->num_sections = SECT_OFF_MAX;
    objfile->section_offsets = (struct section_offsets *)
!     obstack_alloc (&objfile->psymbol_obstack, SIZEOF_SECTION_OFFSETS);
!   memset (objfile->section_offsets, 0, SIZEOF_SECTION_OFFSETS);
  
    /* Now calculate offsets for section that were specified by the
       caller. */
!   for (i = 0; i < MAX_SECTIONS && addrs->other[i].name; i++)
      {
        struct other_sections *osp ;
  
        osp = &addrs->other[i] ;
        if (osp->addr == 0)
--- 527,546 ----
  default_symfile_offsets (struct objfile *objfile,
  			 struct section_addr_info *addrs)
  {
    int i;
  
!   objfile->num_sections = bfd_count_sections (objfile->obfd);
    objfile->section_offsets = (struct section_offsets *)
!     obstack_alloc (&objfile->psymbol_obstack, 
! 		   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
       caller. */
!   for (i = 0; i < addrs->num_sections && addrs->other[i].name; i++)
      {
        struct other_sections *osp ;
  
        osp = &addrs->other[i] ;
        if (osp->addr == 0)
*************** syms_from_objfile (struct objfile *objfi
*** 582,618 ****
                     int verbo)
  {
    asection *lower_sect;
    asection *sect;
    CORE_ADDR lower_offset;
!   struct section_addr_info local_addr;
    struct cleanup *old_chain;
    int i;
  
    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);
    find_sym_fns (objfile);
  
    if (objfile->sf == NULL)
      return;	/* No symbols. */
  
    /* Make sure that partially constructed symbol tables will be cleaned up
       if an error occurs during symbol reading.  */
    old_chain = make_cleanup_free_objfile (objfile);
  
    if (mainline)
      {
        /* We will modify the main symbol table, make sure that all its users
           will be cleaned up if an error occurs during symbol reading.  */
        make_cleanup (clear_symtab_users_cleanup, 0 /*ignore*/);
--- 599,637 ----
                     int verbo)
  {
    asection *lower_sect;
    asection *sect;
    CORE_ADDR lower_offset;
!   struct section_addr_info *local_addr = NULL;
    struct cleanup *old_chain;
    int i;
  
    gdb_assert (! (addrs && offsets));
  
    init_entry_point_info (objfile);
    find_sym_fns (objfile);
  
    if (objfile->sf == NULL)
      return;	/* No symbols. */
  
    /* Make sure that partially constructed symbol tables will be cleaned up
       if an error occurs during symbol reading.  */
    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)
      {
        /* We will modify the main symbol table, make sure that all its users
           will be cleaned up if an error occurs during symbol reading.  */
        make_cleanup (clear_symtab_users_cleanup, 0 /*ignore*/);
*************** syms_from_objfile (struct objfile *objfi
*** 672,682 ****
   	 (the loadable section directly below it in memory).
   	 this_offset = lower_offset = lower_addr - lower_orig_addr */
  
        /* Calculate offsets for sections. */
        if (addrs)
!         for (i=0 ; i < MAX_SECTIONS && addrs->other[i].name; i++)
            {
              if (addrs->other[i].addr != 0)
                {
                  sect = bfd_get_section_by_name (objfile->obfd,
                                                  addrs->other[i].name);
--- 691,701 ----
   	 (the loadable section directly below it in memory).
   	 this_offset = lower_offset = lower_addr - lower_orig_addr */
  
        /* Calculate offsets for sections. */
        if (addrs)
!         for (i=0 ; i < addrs->num_sections && addrs->other[i].name; i++)
            {
              if (addrs->other[i].addr != 0)
                {
                  sect = bfd_get_section_by_name (objfile->obfd,
                                                  addrs->other[i].name);
*************** syms_from_objfile (struct objfile *objfi
*** 756,766 ****
  	{
  	  CORE_ADDR s_addr = 0;
  	  int i;
  
   	    for (i = 0; 
! 	         !s_addr && i < MAX_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 */
--- 775,785 ----
  	{
  	  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 */
*************** symbol_file_add_with_addrs_or_offsets (c
*** 854,867 ****
  {
    struct objfile *objfile;
    struct partial_symtab *psymtab;
    char *debugfile;
    bfd *abfd;
!   struct section_addr_info orig_addrs;
!   
!   if (addrs)
!     orig_addrs = *addrs;
  
    /* Open a bfd for the file, and give user a chance to burp if we'd be
       interactively wiping out any existing symbols.  */
  
    abfd = symfile_bfd_open (name);
--- 873,884 ----
  {
    struct objfile *objfile;
    struct partial_symtab *psymtab;
    char *debugfile;
    bfd *abfd;
!   struct section_addr_info *orig_addrs;
!   struct cleanup *my_cleanups;
  
    /* Open a bfd for the file, and give user a chance to burp if we'd be
       interactively wiping out any existing symbols.  */
  
    abfd = symfile_bfd_open (name);
*************** symbol_file_add_with_addrs_or_offsets (c
*** 872,881 ****
--- 889,903 ----
        && !query ("Load new symbol table from \"%s\"? ", name))
      error ("Not confirmed.");
  
    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
       it, then skip reading any symbols at this time. */
  
    if ((objfile->flags & OBJF_MAPPED) && (objfile->flags & OBJF_SYMS))
      {
*************** symbol_file_add_with_addrs_or_offsets (c
*** 938,948 ****
    if (debugfile)
      {
        if (addrs != NULL)
  	{
  	  objfile->separate_debug_objfile
!             = symbol_file_add (debugfile, from_tty, &orig_addrs, 0, flags);
  	}
        else
  	{
  	  objfile->separate_debug_objfile
              = symbol_file_add (debugfile, from_tty, NULL, 0, flags);
--- 960,970 ----
    if (debugfile)
      {
        if (addrs != NULL)
  	{
  	  objfile->separate_debug_objfile
!             = symbol_file_add (debugfile, from_tty, orig_addrs, 0, flags);
  	}
        else
  	{
  	  objfile->separate_debug_objfile
              = symbol_file_add (debugfile, from_tty, NULL, 0, flags);
*************** symbol_file_add_with_addrs_or_offsets (c
*** 977,986 ****
--- 999,1010 ----
    /* We print some messages regardless of whether 'from_tty ||
       info_verbose' is true, so make sure they go out at the right
       time.  */
    gdb_flush (gdb_stdout);
  
+   do_cleanups (my_cleanups);
+ 
    if (objfile->sf == NULL)
      return objfile;	/* No symbols. */
  
    new_symfile_objfile (objfile, mainline, from_tty);
  
*************** add_symbol_file_command (char *args, int
*** 1694,1723 ****
    int sec_num = 0;
    int i;
    int expecting_sec_name = 0;
    int expecting_sec_addr = 0;
  
!   struct
    {
      char *name;
      char *value;
!   } sect_opts[SECT_OFF_MAX];
  
!   struct section_addr_info section_addrs;
    struct cleanup *my_cleanups = make_cleanup (null_cleanup, NULL);
  
    dont_repeat ();
  
    if (args == NULL)
      error ("add-symbol-file takes a file name and an address");
  
    /* Make a copy of the string that we can safely write into. */
    args = xstrdup (args);
  
-   /* Ensure section_addrs is initialized */
-   memset (&section_addrs, 0, sizeof (section_addrs));
- 
    while (*args != '\000')
      {
        /* Any leading spaces? */
        while (isspace (*args))
  	args++;
--- 1718,1750 ----
    int sec_num = 0;
    int i;
    int expecting_sec_name = 0;
    int expecting_sec_addr = 0;
  
!   struct sect_opt
    {
      char *name;
      char *value;
!   };
  
!   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);
  
+   num_sect_opts = 16;
+   sect_opts = (struct sect_opt *) xmalloc (num_sect_opts 
+ 					   * sizeof (struct sect_opt));
+ 
    dont_repeat ();
  
    if (args == NULL)
      error ("add-symbol-file takes a file name and an address");
  
    /* Make a copy of the string that we can safely write into. */
    args = xstrdup (args);
  
    while (*args != '\000')
      {
        /* Any leading spaces? */
        while (isspace (*args))
  	args++;
*************** add_symbol_file_command (char *args, int
*** 1746,1756 ****
  	  {
  	    /* The second argument is always the text address at which
                 to load the program. */
  	    sect_opts[section_index].name = ".text";
  	    sect_opts[section_index].value = arg;
! 	    section_index++;		  
  	  }
  	else
  	  {
  	    /* It's an option (starting with '-') or it's an argument
  	       to an option */
--- 1773,1790 ----
  	  {
  	    /* The second argument is always the text address at which
                 to load the program. */
  	    sect_opts[section_index].name = ".text";
  	    sect_opts[section_index].value = arg;
! 	    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
  	  {
  	    /* It's an option (starting with '-') or it's an argument
  	       to an option */
*************** add_symbol_file_command (char *args, int
*** 1763,1774 ****
  		  if (strcmp (arg, "-readnow") == 0)
  		    flags |= OBJF_READNOW;
  		  else 
  		    if (strcmp (arg, "-s") == 0)
  		      {
- 			if (section_index >= SECT_OFF_MAX)
- 			  error ("Too many sections specified.");
  			expecting_sec_name = 1;
  			expecting_sec_addr = 1;
  		      }
  	      }
  	    else
--- 1797,1806 ----
*************** add_symbol_file_command (char *args, int
*** 1781,1791 ****
  		else
  		  if (expecting_sec_addr)
  		    {
  		      sect_opts[section_index].value = arg;
  		      expecting_sec_addr = 0;
! 		      section_index++;		  
  		    }
  		  else
  		    error ("USAGE: add-symbol-file <filename> <textaddress> [-mapped] [-readnow] [-s <secname> <addr>]*");
  	      }
  	  }
--- 1813,1830 ----
  		else
  		  if (expecting_sec_addr)
  		    {
  		      sect_opts[section_index].value = arg;
  		      expecting_sec_addr = 0;
! 		      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
  		    error ("USAGE: add-symbol-file <filename> <textaddress> [-mapped] [-readnow] [-s <secname> <addr>]*");
  	      }
  	  }
*************** add_symbol_file_command (char *args, int
*** 1797,1806 ****
--- 1836,1847 ----
       functions.  We have to split this up into separate print
       statements because local_hex_string returns a local static
       string. */
   
    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++)
      {
        CORE_ADDR addr;
        char *val = sect_opts[i].value;
        char *sec = sect_opts[i].name;
*************** add_symbol_file_command (char *args, int
*** 1811,1822 ****
        else
  	addr = strtoul (val, NULL, 10);
  
        /* Here we store the section offsets in the order they were
           entered on the command line. */
!       section_addrs.other[sec_num].name = sec;
!       section_addrs.other[sec_num].addr = addr;
        printf_filtered ("\t%s_addr = %s\n",
  		       sec, 
  		       local_hex_string ((unsigned long)addr));
        sec_num++;
  
--- 1852,1863 ----
        else
  	addr = strtoul (val, NULL, 10);
  
        /* Here we store the section offsets in the order they were
           entered on the command line. */
!       section_addrs->other[sec_num].name = sec;
!       section_addrs->other[sec_num].addr = addr;
        printf_filtered ("\t%s_addr = %s\n",
  		       sec, 
  		       local_hex_string ((unsigned long)addr));
        sec_num++;
  
*************** add_symbol_file_command (char *args, int
*** 1828,1838 ****
      }
  
    if (from_tty && (!query ("%s", "")))
      error ("Not confirmed.");
  
!   symbol_file_add (filename, from_tty, &section_addrs, 0, flags);
  
    /* Getting new symbols may change our opinion about what is
       frameless.  */
    reinit_frame_cache ();
    do_cleanups (my_cleanups);
--- 1869,1879 ----
      }
  
    if (from_tty && (!query ("%s", "")))
      error ("Not confirmed.");
  
!   symbol_file_add (filename, from_tty, section_addrs, 0, flags);
  
    /* Getting new symbols may change our opinion about what is
       frameless.  */
    reinit_frame_cache ();
    do_cleanups (my_cleanups);
*************** reread_symbols (void)
*** 1925,1936 ****
  		       bfd_errmsg (bfd_get_error ()));
  
  	      /* Save the offsets, we will nuke them with the rest of the
  	         psymbol_obstack.  */
  	      num_offsets = objfile->num_sections;
! 	      offsets = (struct section_offsets *) alloca (SIZEOF_SECTION_OFFSETS);
! 	      memcpy (offsets, objfile->section_offsets, SIZEOF_SECTION_OFFSETS);
  
  	      /* Nuke all the state that we will re-read.  Much of the following
  	         code which sets things to NULL really is necessary to tell
  	         other parts of GDB that there is nothing currently there.  */
  
--- 1966,1979 ----
  		       bfd_errmsg (bfd_get_error ()));
  
  	      /* Save the offsets, we will nuke them with the rest of the
  	         psymbol_obstack.  */
  	      num_offsets = objfile->num_sections;
! 	      offsets = ((struct 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
  	         code which sets things to NULL really is necessary to tell
  	         other parts of GDB that there is nothing currently there.  */
  
*************** reread_symbols (void)
*** 1994,2005 ****
                terminate_minimal_symbol_table (objfile);
  
  	      /* We use the same section offsets as from last time.  I'm not
  	         sure whether that is always correct for shared libraries.  */
  	      objfile->section_offsets = (struct section_offsets *)
! 		obstack_alloc (&objfile->psymbol_obstack, SIZEOF_SECTION_OFFSETS);
! 	      memcpy (objfile->section_offsets, offsets, SIZEOF_SECTION_OFFSETS);
  	      objfile->num_sections = num_offsets;
  
  	      /* What the hell is sym_new_init for, anyway?  The concept of
  	         distinguishing between the main file and additional files
  	         in this way seems rather dubious.  */
--- 2037,2050 ----
                terminate_minimal_symbol_table (objfile);
  
  	      /* We use the same section offsets as from last time.  I'm not
  	         sure whether that is always correct for shared libraries.  */
  	      objfile->section_offsets = (struct section_offsets *)
! 		obstack_alloc (&objfile->psymbol_obstack, 
! 			       SIZEOF_N_SECTION_OFFSETS (num_offsets));
! 	      memcpy (objfile->section_offsets, offsets, 
! 		      SIZEOF_N_SECTION_OFFSETS (num_offsets));
  	      objfile->num_sections = num_offsets;
  
  	      /* What the hell is sym_new_init for, anyway?  The concept of
  	         distinguishing between the main file and additional files
  	         in this way seems rather dubious.  */
Index: symfile.h
===================================================================
RCS file: /cvs/src/src/gdb/symfile.h,v
retrieving revision 1.21
diff -c -5 -p -r1.21 symfile.h
*** symfile.h	14 May 2003 17:43:19 -0000	1.21
--- symfile.h	15 May 2003 07:29:20 -0000
*************** struct psymbol_allocation_list
*** 65,84 ****
     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 64
  struct section_addr_info 
  {
    /* Sections whose names are file format dependent. */
    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.  */
  
--- 65,86 ----
     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 (). */
   
  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. */
    struct other_sections
    {
      CORE_ADDR addr;
      char *name;
      int sectindex;
!   } other[1];
  };
  
  /* Structure to keep track of symbol reading functions for various
     object file types.  */
  
*************** extern void syms_from_objfile (struct ob
*** 182,191 ****
--- 184,198 ----
  
  extern void new_symfile_objfile (struct objfile *, int, int);
  
  extern struct objfile *symbol_file_add (char *, 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
     an existing section table. */
  
  struct section_table;
Index: symtab.h
===================================================================
RCS file: /cvs/src/src/gdb/symtab.h,v
retrieving revision 1.70
diff -c -5 -p -r1.70 symtab.h
*** symtab.h	14 May 2003 17:43:20 -0000	1.70
--- symtab.h	15 May 2003 07:29:21 -0000
*************** struct section_offsets
*** 751,763 ****
  /* The size of a section_offsets table for N sections.  */
  #define SIZEOF_N_SECTION_OFFSETS(n) \
    (sizeof (struct section_offsets) \
     + 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. 
     These objects are chained through the `next' field.  */
  
  struct symtab
  {
--- 751,760 ----
Index: win32-nat.c
===================================================================
RCS file: /cvs/src/src/gdb/win32-nat.c,v
retrieving revision 1.74
diff -c -5 -p -r1.74 win32-nat.c
*** win32-nat.c	21 Feb 2003 02:29:18 -0000	1.74
--- win32-nat.c	15 May 2003 07:29:21 -0000
*************** solib_symbols_add (char *name, int from_
*** 840,857 ****
      }
  
    else
      {
        /* Fallback on handling just the .text section. */
!       struct section_addr_info section_addrs;
  
!       memset (&section_addrs, 0, sizeof (section_addrs));
        section_addrs.other[0].name = ".text";
        section_addrs.other[0].addr = load_addr;
  
        result = safe_symbol_file_add (name, from_tty, &section_addrs,
  				     0, OBJF_SHARED);
      }
  
    return result;
  }
  
--- 840,860 ----
      }
  
    else
      {
        /* Fallback on handling just the .text section. */
!       struct section_addr_info *section_addrs;
!       struct cleanup *my_cleanups;
  
!       section_addrs = alloc_section_addr_info (1);
!       my_cleanups = make_cleanup (xfree, section_addrs);
        section_addrs.other[0].name = ".text";
        section_addrs.other[0].addr = load_addr;
  
        result = safe_symbol_file_add (name, from_tty, &section_addrs,
  				     0, OBJF_SHARED);
+       do_cleanups (my_cleanups);
      }
  
    return result;
  }
  
Index: xcoffread.c
===================================================================
RCS file: /cvs/src/src/gdb/xcoffread.c,v
retrieving revision 1.28
diff -c -5 -p -r1.28 xcoffread.c
*** xcoffread.c	14 May 2003 17:43:20 -0000	1.28
--- xcoffread.c	15 May 2003 07:29:23 -0000
*************** static void
*** 2979,2991 ****
  xcoff_symfile_offsets (struct objfile *objfile, struct section_addr_info *addrs)
  {
    asection *sect = NULL;
    int i;
  
!   objfile->num_sections = SECT_OFF_MAX;
    objfile->section_offsets = (struct section_offsets *)
!     obstack_alloc (&objfile->psymbol_obstack, SIZEOF_SECTION_OFFSETS);
  
    /* Initialize the section indexes for future use. */
    sect = bfd_get_section_by_name (objfile->obfd, ".text");
    if (sect) 
      objfile->sect_index_text = sect->index;
--- 2979,2992 ----
  xcoff_symfile_offsets (struct objfile *objfile, struct section_addr_info *addrs)
  {
    asection *sect = NULL;
    int i;
  
!   objfile->num_sections = bfd_count_sections (objfile->obfd);
    objfile->section_offsets = (struct section_offsets *)
!     obstack_alloc (&objfile->psymbol_obstack, 
! 		   SIZEOF_N_SECTION_OFFSETS (objfile->num_sections));
  
    /* Initialize the section indexes for future use. */
    sect = bfd_get_section_by_name (objfile->obfd, ".text");
    if (sect) 
      objfile->sect_index_text = sect->index;


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]