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]

[RFC] Detect loops in the solib chain


A MontaVista customer had a very interestingly corrupt core file -
there was a stray pointer in the list of loaded shared libraries.  But
it pointed to something which looked enough like a shared library
entry to get by, and the bad entry's l_next pointed back at the
corrupted entry that led to it.  So around and around we went, adding
the same two libraries to the list.  When the solib chain reached
about 2GB, GDB was killed.

The best I could think of was to detect cycles.  It's a linked list
that we're walking, so without cycles we're bounded by the amount of
memory in the debuggee; it's by no means foolproof, but this should
prevent more cases of wandering off into the woods than we do now.

Does this look OK?  Tested on x86_64-linux, no regressions.

-- 
Daniel Jacobowitz
CodeSourcery

2008-07-17  Daniel Jacobowitz  <dan@codesourcery.com>

	* solib-svr4.c (svr4_current_sos): Check for cycles in the list.

Index: solib-svr4.c
===================================================================
RCS file: /cvs/src/src/gdb/solib-svr4.c,v
retrieving revision 1.87
diff -u -p -r1.87 solib-svr4.c
--- solib-svr4.c	3 Jun 2008 12:59:37 -0000	1.87
+++ solib-svr4.c	17 Jul 2008 20:36:23 -0000
@@ -751,7 +751,8 @@ static struct so_list *
 svr4_current_sos (void)
 {
   CORE_ADDR lm;
-  struct so_list *head = 0;
+  int loop_flag = 0;
+  struct so_list *head = 0, *loop_so_list = NULL;
   struct so_list **link_ptr = &head;
   CORE_ADDR ldsomap = 0;
 
@@ -825,6 +826,13 @@ svr4_current_sos (void)
 	      new->next = 0;
 	      *link_ptr = new;
 	      link_ptr = &new->next;
+
+	      /* Advance loop_so_list at half speed.  */
+	      if (loop_so_list == NULL)
+		loop_so_list = new;
+	      else if (loop_flag)
+		loop_so_list = loop_so_list->next;
+	      loop_flag = !loop_flag;
 	    }
 	}
 
@@ -836,6 +844,13 @@ svr4_current_sos (void)
 	lm = ldsomap = solib_svr4_r_ldsomap ();
 
       discard_cleanups (old_chain);
+
+      /* Check for cycles in the list.  */
+      if (loop_so_list && loop_so_list->lm_info->lm_addr == lm)
+	{
+	  warning (_("Corrupt shared library list"));
+	  break;
+	}
     }
 
   if (head == NULL)


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