From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 22300 invoked by alias); 6 May 2013 17:32:07 -0000 Mailing-List: contact gdb-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-owner@sourceware.org Received: (qmail 22285 invoked by uid 89); 6 May 2013 17:32:06 -0000 X-Spam-SWARE-Status: No, score=-7.0 required=5.0 tests=AWL,BAYES_00,RCVD_IN_HOSTKARMA_W,RCVD_IN_HOSTKARMA_WL,RP_MATCHES_RCVD,SPF_HELO_PASS,SPF_PASS autolearn=ham version=3.3.1 Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Mon, 06 May 2013 17:32:06 +0000 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r46HW4eP013776 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 6 May 2013 13:32:04 -0400 Received: from barimba (ovpn-113-163.phx2.redhat.com [10.3.113.163]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id r46HW3TT001187 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO); Mon, 6 May 2013 13:32:04 -0400 From: Tom Tromey To: Phil Muldoon Cc: gdb@sourceware.org Subject: Re: Cleanups and Exception handlers References: <5180EE37.3020507@redhat.com> Date: Mon, 06 May 2013 17:32:00 -0000 In-Reply-To: <5180EE37.3020507@redhat.com> (Phil Muldoon's message of "Wed, 01 May 2013 11:28:07 +0100") Message-ID: <87sj20ypyk.fsf@fleche.redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-SW-Source: 2013-05/txt/msg00027.txt.bz2 >>>>> "Phil" == Phil Muldoon writes: Phil> I'd like to quantify and discuss strategies of cleanups and GDB exception Phil> handlers. It seems I am always making mistakes in this area, and the Phil> comments in the TRY_CATCH macro (well to me) are not adequate about the Phil> mechanics of cleanups in an exception handler. Phil> So I would like to discuss patterns of usage with a view to updating Phil> the comments to be more explanatory. There's also a section in gdbint.texinfo, though it seems reasonably out of date, seeing as it does not mention TRY_CATCH at all. The simplest, and IMO therefore best, way to approach cleanups is to pretend that they introduce blocks. That is, when you see an assignment of a cleanup to a local: cleanup = make_cleanup (...); you should mentally add a "{" to the text. And when you see a do_cleanups or discard_cleanups call, you should mentally add a "}". Then, if the braces in the function -- all of them, the real ones plus the one you added mentally -- do not balance, something is wrong. This approach is sufficient for most of the code in gdb. There are some necessary exceptions to the rule (some functions must return cleanups somehow; and also sometimes the strict lexical rule will not work), some weird code, and some code making assumptions about its caller. The cleanup checker (archer.git tromey/cleanup-checker) diagnoses these. It is of course possible to be more dynamic with cleanups and not to pretend they are block structured. There aren't any actual rules. However, I think the more dynamic style is bug-prone, and my proof of this is the large number of actual bugs in this area that I've fixed over the years, including all the ones fixed on the cleanup-checker branch but not yet submitted. Tom