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 RFA] solib.c, symfile.c, symtab.h, and target.h changes


Yesterday, I submitted an RFA for changes to solib.c in

    http://sourceware.cygnus.com/ml/gdb-patches/2000-q1/msg00746.html

Jim Blandy asked me to restructure the code somewhat.  He said,

    I have only one request:  the code which scans an array of
    section_table entries and fills in a struct section_addr_info is
    hardly specific to shared libraries.  Could you turn it into a
    function, put it in symfile.c, and just call it from solib.c?  I
    guess you'll need a corresponding cleanup function to free the
    names.

I have done this and am submitting for approval the patch below.  This
patch supersedes the patches contained in

    http://sourceware.cygnus.com/ml/gdb/2000-q1/msg00681.html
    http://sourceware.cygnus.com/ml/gdb-patches/2000-q1/msg00746.html

The difficult part was choosing names for the new functions and
deciding which header file should be used to declare the new
functions.  I ended up putting them next to the declaration of 
build_section_table() in target.h.  target.h was the best choice
for the following reasons:

  1) The prototype for build_section_addr_info_from_section_table()
     refers to struct section_table *.  This type is declared in
     target.h.

  2) The return type for build_section_addr_info_from_section_table()
     is struct section_addr_info *.  This type is declared in symtab.h.
     But target.h includes symtab.h.  So this type is available to
     target.h as well.

  3) target.h already has a declaration for a function dealing with
     struct section_table *.

Jim B. "pre-approved" me for checking in the changes to solib.c,
symtab.h, and symfile.c.  It's not clear to me who the maintainer
for target.h is, so I'm seeking approval for those changes.  (My
guess is that Andrew is the maintainer by default.)

	* symtab.h (MAX_SECTIONS): Increase to 30.
	* solib.c (symbol_add_stub): Make symbol_file_add() aware of
	all section addresses, not just .text.
	* target.h, symfile.h (free_section_addr_info,
	build_section_addr_info_from_section_table): New functions.

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/18 01:49:43
@@ -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/18 01:49:47
@@ -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 (struct section_table *start,
+                                            struct section_table *end)
+{
+  struct section_addr_info *sap;
+  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
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/18 01:49:48
@@ -842,7 +842,7 @@ struct section_offsets
    can keep track of the section names until we read the file and
    can map them to bfd sections. */
  
-#define MAX_SECTIONS 12
+#define MAX_SECTIONS 30
 struct section_addr_info 
 {
   /* Sections whose names are always known to gdb. */
Index: target.h
===================================================================
RCS file: /cvs/src/src/gdb/target.h,v
retrieving revision 1.2
diff -u -p -r1.2 target.h
--- target.h	2000/03/15 16:55:07	1.2
+++ target.h	2000/03/18 01:49:49
@@ -1326,6 +1326,18 @@ extern int
 build_section_table PARAMS ((bfd *, struct section_table **,
 			     struct section_table **));
 
+/* 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 (struct section_table *start,
+                                            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 *);
+
 /* From mem-break.c */
 
 extern int memory_remove_breakpoint PARAMS ((CORE_ADDR, char *));


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