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

[RFA] Fix handling of "set sysroot foo"


Hi.

We were getting bogus backtraces from a core dump because
gdb was using the wrong load address for libc.

We were running gdb like this: gdb -ex "set sysroot ." file core.
Yes, -iex would be better :-), but -ex should still work.

-ex gets processed after loading the shared libraries for the core,
so this meant that gdb was loading all the shared libraries
and then throwing all that away to reload them again when processing
"set sysroot .".

The bug turned out to be due to the fact that lm_info.l_addr_p
doesn't get reset when we reload shared libraries so gdb
was using the previous value of l_addr.

I kinda like and dislike clear_solist as the new name for free_so_symbols.
- the old free_so_symbols does more than just free
- target_so_ops.clear_solib is used for similar "reset and/or free" purposes
- it's nice to have the target function's name match
- target_so_ops function free_so already exists
Hence the rename.

Ok to check in?

2013-04-12  Doug Evans  <dje@google.com>

	* solist.h (struct target_so_ops): New member clear_solist.
	* solib-svr4.c (svr4_clear_solist): New function.
	(_initialize_svr4_solib): Set svr4_so_ops.clear_solist.
	* solib.c (clear_solist): Renamed from free_so_symbols.
	All callers updated.  Call target clear_solist if it exists.

Index: solib-svr4.c
===================================================================
RCS file: /cvs/src/src/gdb/solib-svr4.c,v
retrieving revision 1.175
diff -u -p -r1.175 solib-svr4.c
--- solib-svr4.c	8 Apr 2013 14:03:56 -0000	1.175
+++ solib-svr4.c	12 Apr 2013 17:56:09 -0000
@@ -966,6 +966,14 @@ svr4_free_so (struct so_list *so)
   xfree (so->lm_info);
 }
 
+/* Implement target_so_ops.clear_solist.  */
+
+static void
+svr4_clear_solist (struct so_list *so)
+{
+  so->lm_info->l_addr_p = 0;
+}
+
 /* Free so_list built so far (called via cleanup).  */
 
 static void
@@ -2448,6 +2456,7 @@ _initialize_svr4_solib (void)
 
   svr4_so_ops.relocate_section_addresses = svr4_relocate_section_addresses;
   svr4_so_ops.free_so = svr4_free_so;
+  svr4_so_ops.clear_solist = svr4_clear_solist;
   svr4_so_ops.clear_solib = svr4_clear_solib;
   svr4_so_ops.solib_create_inferior_hook = svr4_solib_create_inferior_hook;
   svr4_so_ops.special_symbol_handling = svr4_special_symbol_handling;
Index: solib.c
===================================================================
RCS file: /cvs/src/src/gdb/solib.c,v
retrieving revision 1.170
diff -u -p -r1.170 solib.c
--- solib.c	11 Apr 2013 01:18:49 -0000	1.170
+++ solib.c	12 Apr 2013 17:56:09 -0000
@@ -498,17 +498,20 @@ solib_map_sections (struct so_list *so)
   return 1;
 }
 
-/* Free symbol-file related contents of SO.  If we have opened a BFD
-   for SO, close it.  If we have placed SO's sections in some target's
-   section table, the caller is responsible for removing them.
+/* Free symbol-file related contents of SO and reset for possible reloading
+   of SO.  If we have opened a BFD for SO, close it.  If we have placed SO's
+   sections in some target's section table, the caller is responsible for
+   removing them.
 
    This function doesn't mess with objfiles at all.  If there is an
    objfile associated with SO that needs to be removed, the caller is
    responsible for taking care of that.  */
 
 static void
-free_so_symbols (struct so_list *so)
+clear_solist (struct so_list *so)
 {
+  struct target_so_ops *ops = solib_ops (target_gdbarch ());
+
   if (so->sections)
     {
       xfree (so->sections);
@@ -527,6 +530,10 @@ free_so_symbols (struct so_list *so)
   /* Restore the target-supplied file name.  SO_NAME may be the path
      of the symbol file.  */
   strcpy (so->so_name, so->so_original_name);
+
+  /* Do the same for target-specific data.  */
+  if (ops->clear_solist != NULL)
+    ops->clear_solist (so);
 }
 
 /* Free the storage associated with the `struct so_list' object SO.
@@ -545,7 +552,7 @@ free_so (struct so_list *so)
 {
   struct target_so_ops *ops = solib_ops (target_gdbarch ());
 
-  free_so_symbols (so);
+  clear_solist (so);
   ops->free_so (so);
 
   xfree (so);
@@ -1237,7 +1244,7 @@ reload_shared_libraries_1 (int from_tty)
 	      && !solib_used (so))
 	    free_objfile (so->objfile);
 	  remove_target_sections (so, so->abfd);
-	  free_so_symbols (so);
+	  clear_solist (so);
 	}
 
       /* If this shared library is now associated with a new symbol
Index: solist.h
===================================================================
RCS file: /cvs/src/src/gdb/solist.h,v
retrieving revision 1.38
diff -u -p -r1.38 solist.h
--- solist.h	1 Jan 2013 06:32:51 -0000	1.38
+++ solist.h	12 Apr 2013 17:56:09 -0000
@@ -88,6 +88,10 @@ struct target_so_ops
        associated with a so_list entry.  */
     void (*free_so) (struct so_list *so);
 
+    /* Reset or free private data structures associated with
+       so_list entries.  */
+    void (*clear_solist) (struct so_list *so);
+
     /* Reset or free private data structures not associated with
        so_list entries.  */
     void (*clear_solib) (void);


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