This is the mail archive of the 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]

[17/17] target_sections hack

I was surprised to discover that one part of gdb relies on BFDs not
being shared.

In particular, if an solib shares exec_bfd, then remove_target_sections
will happily remove all the sections for both, then unpush the file
target.  Then re-"run"ing will fail.

Unpushing the target here seems like an abstraction inversion.
(However, I don't really know this code very well.)

This patch fixes the problem via a gross hack: bypass the calls if the
BFD is the same as exec_bfd.

It occurs to me now that this approach will still fail if the inferior
calls dlmopen (causing a single library to be mapped more than once, but
after this series still sharing BFDs).  One other idea I had was to
associate a tag with the target_sections; this would be just any handy
void*, like the solib.  Then remove_target_sections could search for the
tag in addition to the BFD.  Any other thoughts on this?


>From 6609c92b8da8473cd3ceb21e66d9fe2ee88218de Mon Sep 17 00:00:00 2001
From: Tom Tromey <>
Date: Mon, 12 Dec 2011 15:00:23 -0700
Subject: [PATCH 17/18] target sections hack solib assumes that we will not
 share BFDs

	* solib.c (solib_map_sections): Conditionally call
	(update_solib_list): Conditionally call remove_target_sections.
	(clear_solib): Conditionally call remove_target_sections.
	(reload_shared_libraries_1): Conditionally call
 gdb/solib.c |   11 +++++++----
 1 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/gdb/solib.c b/gdb/solib.c
index 79d1905..c8f3bfa 100644
--- a/gdb/solib.c
+++ b/gdb/solib.c
@@ -507,7 +507,8 @@ solib_map_sections (struct so_list *so)
      section tables.  Do this immediately after mapping the object so
      that later nodes in the list can query this object, as is needed
      in solib-osf.c.  */
-  add_target_sections (so->sections, so->sections_end);
+  if (so->abfd != exec_bfd)
+    add_target_sections (so->sections, so->sections_end);
   return 1;
@@ -770,7 +771,8 @@ update_solib_list (int from_tty, struct target_ops *target)
 	  /* Some targets' section tables might be referring to
 	     sections from so->abfd; remove them.  */
-	  remove_target_sections (gdb->abfd);
+	  if (gdb->abfd != exec_bfd)
+	    remove_target_sections (gdb->abfd);
 	  free_so (gdb);
 	  gdb = *gdb_link;
@@ -1150,7 +1152,7 @@ clear_solib (void)
       so_list_head = so->next;
       observer_notify_solib_unloaded (so);
-      if (so->abfd)
+      if (so->abfd && so->abfd != exec_bfd)
 	remove_target_sections (so->abfd);
       free_so (so);
@@ -1244,7 +1246,8 @@ reload_shared_libraries_1 (int from_tty)
 	  if (so->objfile && ! (so->objfile->flags & OBJF_USERLOADED)
 	      && !solib_used (so))
 	    free_objfile (so->objfile);
-	  remove_target_sections (so->abfd);
+	  if (so->abfd != exec_bfd)
+	    remove_target_sections (so->abfd);
 	  free_so_symbols (so);

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