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

Re: Shared libraries on Linux


On Tue, Feb 08, 2000 at 05:01:49PM -0500, Jim Kingdon wrote:
> OK, I'm going to try to review the situation:
> 
> I'm using http://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=5130 as
> the key bug/limitation that *I* want to fix but of course one of the
> things which is making this confusing is that people keep switching
> topics between various bugs (current and past).
> 

This is a new patch. Please ignore the previous ones.



H.J.
----
Tue Feb  8 18:19:22 2000  H.J. Lu  <hjl@gnu.org>

	Based on patches from Sam Lantinga (slouken@devolution.com):

	* solib.c (verify_solib): New function. Reload list of shared
	objects when they are added or deleted and dump symbols from
	unloaded shared objects.
	(solib_add): Call it.

Index: solib.c
===================================================================
RCS file: /work/cvs/gnu/gdb/gdb/solib.c,v
retrieving revision 1.1.1.3
diff -u -p -r1.1.1.3 solib.c
--- solib.c	1999/11/19 23:38:54	1.1.1.3
+++ solib.c	2000/02/09 02:18:55
@@ -194,6 +198,8 @@ static int solib_map_sections PARAMS ((P
 
 #ifdef SVR4_SHARED_LIBS
 
+static void verify_solib PARAMS ((void));
+
 static CORE_ADDR
   elf_locate_base PARAMS ((void));
 
@@ -951,6 +957,69 @@ open_symbol_file_object (arg)
 }
 #endif /* SVR4_SHARED_LIBS */
 
+#ifdef SVR4_SHARED_LIBS
+/*
+  
+LOCAL FUNCTION
+
+	verify_solib -- check solib list consistency and dump symbols
+			from unloaded shared objects
+
+SYNOPSIS
+
+	void verify_solib (void)
+
+DESCRIPTION
+
+	This module is called whenever we hit a dynamic linker
+	breakpoint and allows us to check the consistency of our shared 
+	object list and unload objects which are no longer valid in the
+	in the inferior. Without this, dynamic unlinking of objects
+	could crash us.
+
+AUTHOR
+	Sam Lantinga <hercules@lokigames.com>
+ */
+
+static void
+verify_solib (void)
+{
+  struct objfile *current;
+
+  if (debug_base)
+    {
+      read_memory (debug_base, (char *) &debug_copy,
+		   sizeof (struct r_debug));
+      /* If the shared object state is consistent, we can reload our
+	 list */
+      if ( debug_copy.r_state == RT_CONSISTENT )
+	clear_solib();
+   }
+
+  for (current = symfile_objfile; current; current = current->next)
+    {
+      struct so_list *so;
+      char *bfd_filename;
+      for (so = so_list_head; so; so = so->next)
+	{
+	  if (so->abfd)
+	    {
+	      bfd_filename = bfd_get_filename (so->abfd);
+	      if (bfd_filename 
+	          && strcmp(bfd_filename, current->name) == 0)
+		break;
+            }
+        }
+      if ((current != symfile_objfile) && (so == NULL))
+	{
+	  /*printf("Freeing objfile: %s\n", current->name);*/
+	  free_objfile(current);
+	  break;
+	}
+    }
+}
+#endif	/* SVR4_SHARED_LIBS */
+
 /*
 
    LOCAL FUNCTION
@@ -1165,6 +1234,8 @@ solib_add (arg_string, from_tty, target)
   int old;
 
 #ifdef SVR4_SHARED_LIBS
+  verify_solib ();
+
   /* If we are attaching to a running process for which we 
      have not opened a symbol file, we may be able to get its 
      symbols now!  */

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