From patchwork Fri Apr 4 14:53:35 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 410 Return-Path: X-Original-To: siddhesh@wilcox.dreamhost.com Delivered-To: siddhesh@wilcox.dreamhost.com Received: from homiemail-mx21.g.dreamhost.com (peon2454.g.dreamhost.com [208.113.200.127]) by wilcox.dreamhost.com (Postfix) with ESMTP id E6031360075 for ; Fri, 4 Apr 2014 07:53:40 -0700 (PDT) Received: by homiemail-mx21.g.dreamhost.com (Postfix, from userid 14314964) id 9B4261AE39EE; Fri, 4 Apr 2014 07:53:40 -0700 (PDT) X-Original-To: gdb@patchwork.siddhesh.in Delivered-To: x14314964@homiemail-mx21.g.dreamhost.com Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by homiemail-mx21.g.dreamhost.com (Postfix) with ESMTPS id 723D31A8C608 for ; Fri, 4 Apr 2014 07:53:40 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:message-id:date:from:mime-version:to:subject :references:in-reply-to:content-type:content-transfer-encoding; q=dns; s=default; b=GKvfwUxlu8FaNKuMfgcBdfdr5HZjjksoEmfDcyJRV8V Gn0TS/F/olJ68SPv9tgGq5Rzi0VF0vOr4y6x3Y0Be+jRNIIWHTYOm5hdUqklWx3P 5uoE8+/oaJ6ASl0jIUDGyh1fKzD+ApxUjxuk8fZyuJdoqgnGYOx7xCBJ4b3me3fw = DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:message-id:date:from:mime-version:to:subject :references:in-reply-to:content-type:content-transfer-encoding; s=default; bh=ubRJ+rWzMnyVmzZ0sYlxvahZzJg=; b=opCslCsENmKfvDE0e ixl3vBAOmnDW98MWa0IuFMHs3ibCHhQiEsoFn4p4Cg6YlkFWDqXrYqL6FV40iQI7 hRM/02E1qIV9WPyX04HN5lE582Am9rwUxMO/FpjVSZkyhJwYxrt9yXAC100avawV vjJe7dqGVH6s/3vaHbdAaXG+3E= 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-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@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, 4 Apr 2014 15:53:35 +0100 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> X-IsSubscribed: yes X-DH-Original-To: gdb@patchwork.siddhesh.in 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. 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 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 *