From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 26234 invoked by alias); 18 Apr 2012 00:43:29 -0000 Received: (qmail 26221 invoked by uid 22791); 18 Apr 2012 00:43:28 -0000 X-SWARE-Spam-Status: No, hits=-5.4 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,KHOP_RCVD_TRUST,KHOP_THREADED,RCVD_IN_DNSWL_LOW,RCVD_IN_HOSTKARMA_YE,TW_EG,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mail-vx0-f169.google.com (HELO mail-vx0-f169.google.com) (209.85.220.169) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 18 Apr 2012 00:43:15 +0000 Received: by vcbfk14 with SMTP id fk14so5664747vcb.0 for ; Tue, 17 Apr 2012 17:43:15 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding:x-system-of-record :x-gm-message-state; bh=9lY/NgurR9+tQAijacSrsjH2pxutppUBIt/13jyFvJU=; b=laDk9n7tSzlLT7oXNgEfg1XpTtkTCeJEDseofmcThkYmonfwtkyVrG/qe0iWlFM/qM XPvFjRDlRkPNqsGG15EcARpLF2Sm5he4q9y2t8kgXPIjiTN0Y+ypanNms/Qc66z8M/Bx 7+59TyobAuJE1KK8lDRDQThlFcO/QL2EcWNtEd0dQXeqXLVSusPYBI0ggZMO2CGk25O0 gbZQqt7vSa8FYmxHA3kM9r0CKRtCUG91AixHGc6BO0U/8OrkcnhahqxipmzIjxAr5v3O CxA0Qu7seaOOrolqRzYLOBjkN0OsXasC5t/z95MYpEJhEfkcRy45GIjjkEJoxFelr9ND Aquw== Received: by 10.220.63.9 with SMTP id z9mr106713vch.64.1334709795171; Tue, 17 Apr 2012 17:43:15 -0700 (PDT) MIME-Version: 1.0 Received: by 10.220.63.9 with SMTP id z9mr106703vch.64.1334709794985; Tue, 17 Apr 2012 17:43:14 -0700 (PDT) Received: by 10.220.115.78 with HTTP; Tue, 17 Apr 2012 17:43:14 -0700 (PDT) In-Reply-To: References: <20120416144011.GH2852@adacore.com> <4F8C3350.1030601@redhat.com> Date: Wed, 18 Apr 2012 01:06:00 -0000 Message-ID: Subject: Re: [RFA] Ensure result of make_cleanup is never NULL. From: Doug Evans To: Pedro Alves , Joel Brobecker Cc: gdb-patches Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-System-Of-Record: true X-Gm-Message-State: ALoCoQmTp1HoC93iFkngIuaXbvdQcHmHncA4HpXTwDBoqjbrKdPDdDUIMQ+eFPk6sv8h0xoaNVPTZwgPVlqkXFdsGNzgYSwIRYSepGFMxQ0KsPEG3bBkKje//bk0TAWDgQ3fasLVuaHx5EMAH0lojwafgOKxUON9/g== X-IsSubscribed: yes 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 X-SW-Source: 2012-04/txt/msg00530.txt.bz2 On Tue, Apr 17, 2012 at 4:00 PM, Doug Evans wrote: > On Mon, Apr 16, 2012 at 8:21 AM, Doug Evans wrote: >> >> On Apr 16, 2012 7:58 AM, "Pedro Alves" wrote: >>> >>> On 04/16/2012 03:40 PM, Joel Brobecker wrote: >>> >>> >> +/* A fencepost used to mark the end of a cleanup chain. >>> >> + =A0 The value is chosen to be non-NULL so that make_cleanup never >>> >> returns NULL, >>> >> + =A0 and cause a segv if dereferenced. =A0*/ >>> >> +#define CLEANUP_FENCEPOST ((struct cleanup *) 1) >>> > >>> > Just a tiny idea, not really important, but JIC: Could we use an enum >>> > intead of a define so that GDB prints "CLEANUP_FENCEPOST" rather than >>> > a numeric value when we print a cleanup pointer that's the fencepost? >>> >>> >>> No, because what you'll be printing will have type struct cleanup point= er, >>> not >>> whatever enum it was cast from. >>> >>> I see at least two ways to get something like that: >>> >>> - a gdb specific pretty printer for cleanups. >>> >>> - Make the sentinel a real object: >>> >>> =A0 static struct cleanup sentinel_cleanup; >>> =A0 #define CLEANUP_FENCEPOST &sentinel_cleanup >>> >>> =A0And get Tromey's "set print symbol" patch in, which IIRC/IIUC, the >>> =A0latest version makes GDB print the symbol name corresponding >>> =A0to addresses by default. =A0Then gdb would print something like: >>> >>> =A0 (gdb) p old_chain >>> =A0 $1 =3D 0xfoobar >>> >>> -- >>> Pedro Alves >> >> That was my other plan.=A0 I can do that instead. > > How about this? > > > 2012-04-17 =A0Doug Evans =A0 > > =A0 =A0 =A0 =A0* cleanups.h (struct cleanup): Move to cleanups.c. > =A0 =A0 =A0 =A0(make_cleanup_dtor_ftype): New typedef. > =A0 =A0 =A0 =A0(make_cleanup_dtor): Use it. > =A0 =A0 =A0 =A0(ALL_CLEANUPS): Replace with ... > =A0 =A0 =A0 =A0(all_cleanups): ... this. =A0Declare. =A0All uses updated. > =A0 =A0 =A0 =A0* cleanups.c (cleanup_sentinel): New static global. > =A0 =A0 =A0 =A0(CLEANUP_SENTINEL): Define. > =A0 =A0 =A0 =A0(cleanup_chain, final_cleanup_chain): Initialize to CLEANU= P_SENTINEL. > =A0 =A0 =A0 =A0(make_my_cleanup2): Assert result is non-NULL. > =A0 =A0 =A0 =A0(all_cleanups): New function. > =A0 =A0 =A0 =A0(save_my_cleanups): Initialize new chain to CLEANUP_SENTIN= EL instead > =A0 =A0 =A0 =A0of NULL. btw, I thought about making cleanup_sentinel const here, for a bit of extra robustness.