This is the mail archive of the gdb-patches@sourceware.cygnus.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]

[PATCH] symtab.h, symfile.h, symfile.c, and solib.c changes


I just committed the following changes.  I've built/run the test suite
on three platforms (linux/ia32, linux/ia64, linux/ppc) and all looks
well.

	* 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.

Index: solib.c
===================================================================
RCS file: /cvs/src/src/gdb/solib.c,v
retrieving revision 1.5
diff -u -p -r1.5 solib.c
--- solib.c	2000/03/17 20:12:23	1.5
+++ solib.c	2000/03/21 22:12:33
@@ -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);
 }
Index: symfile.c
===================================================================
RCS file: /cvs/src/src/gdb/symfile.c,v
retrieving revision 1.2
diff -u -p -r1.2 symfile.c
--- symfile.c	2000/03/15 19:43:57	1.2
+++ symfile.c	2000/03/21 22:12:37
@@ -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, mainl
      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, mainl
  	  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;
Index: symfile.h
===================================================================
RCS file: /cvs/src/src/gdb/symfile.h,v
retrieving revision 1.1.1.6
diff -u -p -r1.1.1.6 symfile.h
--- symfile.h	1999/10/19 02:46:39	1.1.1.6
+++ symfile.h	2000/03/21 22:12:37
@@ -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.  */
 
@@ -162,6 +185,23 @@ syms_from_objfile PARAMS ((struct objfil
 
 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 *,
Index: symtab.h
===================================================================
RCS file: /cvs/src/src/gdb/symtab.h,v
retrieving revision 1.3
diff -u -p -r1.3 symtab.h
--- symtab.h	2000/03/14 19:58:02	1.3
+++ symtab.h	2000/03/21 22:12:39
@@ -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.  */
 
@@ -1436,9 +1415,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 */
 


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