From: Daniel Jacobowitz <drow@false.org>
To: gdb-patches@sourceware.org
Subject: [RFC] Detect loops in the solib chain
Date: Thu, 17 Jul 2008 20:57:00 -0000 [thread overview]
Message-ID: <20080717205721.GA19882@caradoc.them.org> (raw)
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)
next reply other threads:[~2008-07-17 20:57 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-07-17 20:57 Daniel Jacobowitz [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20080717205721.GA19882@caradoc.them.org \
--to=drow@false.org \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox