Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [RFC] Detect loops in the solib chain
@ 2008-07-17 20:57 Daniel Jacobowitz
  2008-07-17 21:07 ` Stan Shebs
                   ` (2 more replies)
  0 siblings, 3 replies; 18+ messages in thread
From: Daniel Jacobowitz @ 2008-07-17 20:57 UTC (permalink / raw)
  To: gdb-patches

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)


^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2010-06-11 18:34 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-07-17 20:57 [RFC] Detect loops in the solib chain Daniel Jacobowitz
2008-07-17 21:07 ` Stan Shebs
2008-07-17 21:15 ` Thiago Jung Bauermann
2008-07-17 21:42   ` Daniel Jacobowitz
2008-07-17 21:18 ` Paul Pluzhnikov
2008-07-17 21:41   ` Daniel Jacobowitz
2008-07-17 21:57     ` Paul Pluzhnikov
2008-07-17 22:10       ` Daniel Jacobowitz
2008-07-18 23:02         ` Kevin Buettner
2010-04-09 15:41         ` Jan Kratochvil
2010-04-09 21:03           ` Jan Kratochvil
2010-04-12 22:54             ` Kevin Buettner
2010-04-12 23:08             ` Pedro Alves
2010-04-18 20:24               ` OpenSolaris dejagnu workaround [Re: [RFC] Detect loops in the solib chain] Jan Kratochvil
2010-04-23 20:09             ` [RFC] Detect loops in the solib chain Tom Tromey
2010-04-23 21:47               ` Jan Kratochvil
2010-06-11 17:39                 ` Ulrich Weigand
2010-06-11 18:34                   ` Jan Kratochvil

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox