From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 21996 invoked by alias); 4 Apr 2014 14:53:38 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 21986 invoked by uid 89); 4 Apr 2014 14:53:38 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.1 required=5.0 tests=AWL,BAYES_00,RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: mail-gw2-out.broadcom.com Received: from mail-gw2-out.broadcom.com (HELO mail-gw2-out.broadcom.com) (216.31.210.63) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 04 Apr 2014 14:53:37 +0000 Received: from irvexchcas08.broadcom.com (HELO IRVEXCHCAS08.corp.ad.broadcom.com) ([10.9.208.57]) by mail-gw2-out.broadcom.com with ESMTP; 04 Apr 2014 08:15:10 -0700 Received: from IRVEXCHSMTP2.corp.ad.broadcom.com (10.9.207.52) by IRVEXCHCAS08.corp.ad.broadcom.com (10.9.208.57) with Microsoft SMTP Server (TLS) id 14.3.174.1; Fri, 4 Apr 2014 07:53:35 -0700 Received: from mail-irva-13.broadcom.com (10.10.10.20) by IRVEXCHSMTP2.corp.ad.broadcom.com (10.9.207.52) with Microsoft SMTP Server id 14.3.174.1; Fri, 4 Apr 2014 07:53:36 -0700 Received: from [10.177.73.80] (unknown [10.177.73.80]) by mail-irva-13.broadcom.com (Postfix) with ESMTP id C0875EAD4C for ; Fri, 4 Apr 2014 07:53:35 -0700 (PDT) Message-ID: <533EC76F.4040204@broadcom.com> Date: Fri, 04 Apr 2014 14:53:00 -0000 From: Andrew Burgess User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:24.0) Gecko/20100101 Thunderbird/24.4.0 MIME-Version: 1.0 To: Subject: Re: [RFC 2/4] Remove previous frame if we error during compute_frame_id References: <533EC5B7.6080600@broadcom.com> <533EC64E.1010302@broadcom.com> In-Reply-To: <533EC64E.1010302@broadcom.com> Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7bit X-IsSubscribed: yes X-SW-Source: 2014-04/txt/msg00069.txt.bz2 Gah! The patch was corrupted in the last post. Try again: In get_prev_frame_if_no_cycle, if we throw an error during compute_frame_id then we are left in a state where THIS_FRAME has a PREV_FRAME attached, but PREV_FRAME has no frame id. This is an unexpected state that causes internal errors and assertions to fire. This patch adds a cleanup that removes the previous frame created by get_prev_frame_raw if we get an error. OK to apply? Thanks, Andrew gdb/ChangeLog: * frame.c (remove_prev_frame): New function. (get_prev_frame_if_no_cycle): Create / discard cleanup using remove_prev_frame. diff --git a/gdb/frame.c b/gdb/frame.c index 97d54e9..5f05968 100644 --- a/gdb/frame.c +++ b/gdb/frame.c @@ -1733,6 +1733,22 @@ frame_register_unwind_location (struct frame_info *this_frame, int regnum, } } +/* Called during frame unwinding to remove a previous frame pointer from a + frame passed in ARG. */ + +static void +remove_prev_frame (void *arg) +{ + struct frame_info *this_frame, *prev_frame; + + this_frame = (struct frame_info *) arg; + prev_frame = this_frame->prev; + gdb_assert (prev_frame != NULL); + + prev_frame->next = NULL; + this_frame->prev = NULL; +} + /* Get the previous raw frame, and check that it is not identical to same other frame frame already in the chain. If it is, there is most likely a stack cycle, so we discard it, and mark THIS_FRAME as @@ -1745,28 +1761,36 @@ static struct frame_info * get_prev_frame_if_no_cycle (struct frame_info *this_frame) { struct frame_info *prev_frame; + struct cleanup *prev_frame_cleanup; prev_frame = get_prev_frame_raw (this_frame); if (prev_frame == NULL) return NULL; - compute_frame_id (prev_frame); - if (frame_stash_add (prev_frame)) - return prev_frame; + /* The cleanup will remove the previous frame that get_prev_frame_raw + linked onto THIS_FRAME. */ + prev_frame_cleanup = make_cleanup (remove_prev_frame, this_frame); - /* Another frame with the same id was already in the stash. We just - detected a cycle. */ - if (frame_debug) + compute_frame_id (prev_frame); + if (!frame_stash_add (prev_frame)) { - fprintf_unfiltered (gdb_stdlog, "-> "); - fprint_frame (gdb_stdlog, NULL); - fprintf_unfiltered (gdb_stdlog, " // this frame has same ID }\n"); + /* Another frame with the same id was already in the stash. We just + detected a cycle. */ + if (frame_debug) + { + fprintf_unfiltered (gdb_stdlog, "-> "); + fprint_frame (gdb_stdlog, NULL); + fprintf_unfiltered (gdb_stdlog, " // this frame has same ID }\n"); + } + this_frame->stop_reason = UNWIND_SAME_ID; + /* Unlink. */ + prev_frame->next = NULL; + this_frame->prev = NULL; + prev_frame = NULL; } - this_frame->stop_reason = UNWIND_SAME_ID; - /* Unlink. */ - prev_frame->next = NULL; - this_frame->prev = NULL; - return NULL; + + discard_cleanups (prev_frame_cleanup); + return prev_frame; } /* Return a "struct frame_info" corresponding to the frame that called