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]

Shared libraries on Linux


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

First there was:
http://sourceware.cygnus.com/ml/gdb/2000-q1/msg00105.html
http://sourceware.cygnus.com/ml/gdb/1999-q4/msg00175.html
(I applied these together).  This combo seems to fix the 5130 test
case for me.  I've enclosed a version of this which is forward-ported
to GDB from CVS.

http://sourceware.cygnus.com/ml/gdb/2000-q1/msg00156.html
As Mark Kettenis points out, this one isn't hooked in the right place.
I tried it on the 5130 test case and it didn't help.

There is another test case at
http://sourceware.cygnus.com/ml/gdb/2000-q1/msg00107.html
which I haven't done anything with yet.

In summary: I'd like to second something Mark Kettenis said: "can we
please first establish what the exact bug is before we start trying to
hack around it!"  All this flamage about cleanliness of code and hacks
and so on seems pretty much beside the point if we don't even have any
clarity about which bug we are trying to fix.

Index: infrun.c
===================================================================
RCS file: /cvs/src/src/gdb/infrun.c,v
retrieving revision 1.1.1.27
diff -u -r1.1.1.27 infrun.c
--- infrun.c	2000/02/05 07:29:43	1.1.1.27
+++ infrun.c	2000/02/08 21:47:02
@@ -1497,6 +1497,9 @@
 		/* Switch terminal for any messages produced by
 		   breakpoint_re_set.  */
 		target_terminal_ours_for_output ();
+#ifdef CHECK_SOLIB_CONSISTENCY
+		CHECK_SOLIB_CONSISTENCY();
+#endif
 		SOLIB_ADD (NULL, 0, NULL);
 		target_terminal_inferior ();
 	      }
@@ -2416,7 +2419,13 @@
 		/* Switch terminal for any messages produced by
 		   breakpoint_re_set.  */
 		target_terminal_ours_for_output ();
+#ifdef CHECK_SOLIB_CONSISTENCY
+		CHECK_SOLIB_CONSISTENCY();
+#endif
 		SOLIB_ADD (NULL, 0, NULL);
+#ifdef UNLOAD_UNUSED_SOLIB
+		UNLOAD_UNUSED_SOLIB();
+#endif
 		target_terminal_inferior ();
 	      }
 
Index: lin-thread.c
===================================================================
RCS file: /cvs/src/src/gdb/lin-thread.c,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 lin-thread.c
--- lin-thread.c	1999/12/22 21:45:07	1.1.1.1
+++ lin-thread.c	2000/02/08 21:47:04
@@ -102,13 +102,7 @@
 #include "inferior.h"
 #include "gdbcmd.h"
 
-#ifdef HAVE_WAIT_H
-#include <wait.h>
-#else
-#ifdef HAVE_SYS_WAIT_H
 #include <sys/wait.h>
-#endif
-#endif
 
 /* "wait.h" fills in the gaps left by <wait.h> */
 #include "wait.h"
Index: solib.c
===================================================================
RCS file: /cvs/src/src/gdb/solib.c,v
retrieving revision 1.1.1.10
diff -u -r1.1.1.10 solib.c
--- solib.c	1999/11/17 02:30:28	1.1.1.10
+++ solib.c	2000/02/08 21:47:05
@@ -952,6 +952,90 @@
 #endif /* SVR4_SHARED_LIBS */
 
 /*
+  
+GLOBAL FUNCTION
+
+       check_solib_consistency -- check solib list consistency
+
+SYNOPSIS
+
+       void check_solib_consistency (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.
+       Without this, dynamic unlinking of objects could crash us.
+ */
+
+void
+check_solib_consistency (void)
+{
+#ifdef SVR4_SHARED_LIBS
+
+  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();
+  }
+
+#endif /* SVR4_SHARED_LIBS */
+}
+
+/*
+
+GLOBAL FUNCTION
+
+       unload_unused_solib -- dump symbols from unloaded shared objects
+
+SYNOPSIS
+
+       void unload_unused_solib (void)
+
+DESCRIPTION
+
+       This module is called whenever we hit a dynamic linker breakpoint
+       and allows us to unload objects which are no longer valid in the
+       in the inferior.
+
+AUTHOR
+       Sam Lantinga <hercules@lokigames.com>
+ */
+
+void
+unload_unused_solib (void)
+{
+
+#ifdef SVR4_SHARED_LIBS
+
+    struct objfile *current;
+
+    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 ) {
+                    if ( 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
 
Index: solib.h
===================================================================
RCS file: /cvs/src/src/gdb/solib.h,v
retrieving revision 1.1.1.3
diff -u -r1.1.1.3 solib.h
--- solib.h	1999/08/31 01:06:02	1.1.1.3
+++ solib.h	2000/02/08 21:47:06
@@ -186,6 +186,15 @@
 extern char *
   solib_address PARAMS ((CORE_ADDR));	/* solib.c */
 
+/* Check shared library consistency */
+
+#define CHECK_SOLIB_CONSISTENCY()      check_solib_consistency()
+extern void check_solib_consistency PARAMS ((void));
+
+/* Brute force check of library consistency */
+
+#define UNLOAD_UNUSED_SOLIB()          unload_unused_solib()
+
 /* If ADDR lies in a shared library, return its name.  */
 
 #define PC_SOLIB(addr)	solib_address (addr)

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