Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tom Tromey <tromey@redhat.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tromey@redhat.com>
Subject: [PATCH 1/2] avoid infinite loop with bad debuginfo
Date: Wed, 13 Nov 2013 22:03:00 -0000	[thread overview]
Message-ID: <1384375873-32160-2-git-send-email-tromey@redhat.com> (raw)
In-Reply-To: <1384375873-32160-1-git-send-email-tromey@redhat.com>

The immediate failure in PR 16155 is an infinite loop in
value_fetch_lazy.  Each iteration of the loop inside the lval_register
branch computes a value with the same frame id and same register
number as the previous iteration.  It never makes progress, using
progressively more memory creating new values.

It seems to me that it never makes sense to let this loop run
indefinitely.  This patch adds a check and throws an exception if the
same register is returned.  I intentionally did not use an internal
error, because this situation can be caused by bad debuginfo.

I did not go the full distance and have the code check all previous
values.  I could do that if folks want.

With this patch at least the infinite loop is gone.  Now the test case
yields:

    (gdb) bt
    #0  0x0000007fb7ed485c in nanosleep () from /lib64/libc.so.6
    #1  0x0000007fb7ed4508 in sleep () from /lib64/libc.so.6
    #2  0x00000000004008bc in thread_function (arg=0x4) at threadapply.c:73
    #3  0x0000007fb7fad950 in start_thread () from /lib64/libpthread.so.0
    #4  0x0000007fb7f0956c in clone () from /lib64/libc.so.6
    #5  0x0000007fb7f0956c in clone () from /lib64/libc.so.6
    Backtrace stopped: previous frame identical to this frame (corrupt stack?)

2013-11-13  Tom Tromey  <tromey@redhat.com>

	PR backtrace/16155:
	* value.c (value_fetch_lazy): Throw exception if
	get_frame_register_value returns the same register.
---
 gdb/ChangeLog | 6 ++++++
 gdb/value.c   | 9 ++++++++-
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/gdb/value.c b/gdb/value.c
index 1f562f5..f8831ae 100644
--- a/gdb/value.c
+++ b/gdb/value.c
@@ -3507,7 +3507,9 @@ value_fetch_lazy (struct value *val)
 
       while (VALUE_LVAL (new_val) == lval_register && value_lazy (new_val))
 	{
-	  frame = frame_find_by_id (VALUE_FRAME_ID (new_val));
+	  struct frame_id last_frame_id = VALUE_FRAME_ID (new_val);
+
+	  frame = frame_find_by_id (last_frame_id);
 	  regnum = VALUE_REGNUM (new_val);
 
 	  gdb_assert (frame != NULL);
@@ -3521,6 +3523,11 @@ value_fetch_lazy (struct value *val)
 						   regnum, type));
 
 	  new_val = get_frame_register_value (frame, regnum);
+	  if (VALUE_LVAL (new_val) == lval_register
+	      && value_lazy (new_val)
+	      && frame_id_eq (VALUE_FRAME_ID (new_val), last_frame_id))
+	    error (_("infinite loop while fetching a register; "
+		     "probably bad debug info"));
 	}
 
       /* If it's still lazy (for instance, a saved register on the
-- 
1.8.1.4


  parent reply	other threads:[~2013-11-13 20:51 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-11-13 20:51 [PATCH 0/2] fix multi-threaded unwinding on AArch64 Tom Tromey
2013-11-13 20:51 ` [PATCH 2/2] handle an unspecified return address column Tom Tromey
2013-11-22 18:22   ` Tom Tromey
2013-11-26 13:55   ` Joel Brobecker
2013-11-26 14:30     ` Mark Kettenis
2013-11-26 14:37       ` Joel Brobecker
2013-11-26 14:41         ` Mark Kettenis
2013-11-26 14:42           ` Joel Brobecker
2013-11-26 14:50           ` Tom Tromey
2013-11-26 15:05           ` Tom Tromey
2013-11-26 15:16       ` Tom Tromey
2013-11-26 16:11         ` Joel Brobecker
2013-11-13 22:03 ` Tom Tromey [this message]
2013-11-14 17:34   ` [PATCH 1/2] avoid infinite loop with bad debuginfo Pedro Alves
2013-11-18 18:25     ` Tom Tromey
2013-11-19 15:10       ` Pedro Alves
2013-11-19 15:47         ` Tom Tromey
2013-11-19 16:33           ` Pedro Alves
2013-11-19 19:07             ` Tom Tromey
2013-11-19 20:24               ` Pedro Alves
2013-11-19 20:56                 ` Tom Tromey
2013-11-20 18:27                   ` [PATCH] Don't let two frames with the same id end up in the frame chain. (Re: [PATCH 1/2] avoid infinite loop with bad debuginfo) Pedro Alves
2013-11-21  0:33                     ` Tom Tromey
2013-11-21 16:40                       ` Pedro Alves
2013-11-21 19:25                         ` Tom Tromey
2013-11-22 14:13                           ` [COMMITTED] Make use of the frame stash to detect wider stack cycles. (was: Re: [PATCH] Don't let two frames with the same id end up in the frame chain. (Re: [PATCH 1/2] avoid infinite loop with bad debuginfo)) Pedro Alves
2013-11-22 14:29                         ` [PATCH] Don't let two frames with the same id end up in the frame chain. (Re: [PATCH 1/2] avoid infinite loop with bad debuginfo) Pedro Alves
2013-11-22 14:52       ` [PATCH 1/2] avoid infinite loop with bad debuginfo Pedro Alves
2013-11-22 17:16         ` Tom Tromey
2013-11-22 17:56           ` Pedro Alves
2013-11-19 15:52     ` Tom Tromey

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=1384375873-32160-2-git-send-email-tromey@redhat.com \
    --to=tromey@redhat.com \
    --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