From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 31242 invoked by alias); 18 Jul 2018 22:31:57 -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 31218 invoked by uid 89); 18 Jul 2018 22:31:56 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-10.9 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_2,GIT_PATCH_3,KAM_LAZY_DOMAIN_SECURITY,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mx1.redhat.com Received: from mx3-rdu2.redhat.com (HELO mx1.redhat.com) (66.187.233.73) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 18 Jul 2018 22:31:55 +0000 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D0C7240201CA; Wed, 18 Jul 2018 22:31:53 +0000 (UTC) Received: from [127.0.0.1] (ovpn04.gateway.prod.ext.ams2.redhat.com [10.39.146.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id AF063111DCEC; Wed, 18 Jul 2018 22:31:52 +0000 (UTC) Subject: Re: [RFC] gdbscm_wrap, eliminate GDBSCM_HANDLE_GDB_EXCEPTION_WITH_CLEANUPS (Re: [RFA 2/4] Change gdbscm_exception_message_to_string to return a unique_xmalloc_ptr) To: Tom Tromey References: <20180527152009.4228-1-tom@tromey.com> <20180527152009.4228-3-tom@tromey.com> <4f3db9e6-4c5a-c29c-46ab-8ce6e1032b3a@redhat.com> <87601dznj3.fsf@tromey.com> <191b7d63-3e83-6bc2-39d6-98a84f3aae27@redhat.com> <87y3e849ux.fsf@tromey.com> Cc: gdb-patches@sourceware.org From: Pedro Alves Message-ID: <652df685-c1bd-7d91-e1c7-0c17fc86e528@redhat.com> Date: Wed, 18 Jul 2018 22:31:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0 MIME-Version: 1.0 In-Reply-To: <87y3e849ux.fsf@tromey.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-SW-Source: 2018-07/txt/msg00568.txt.bz2 On 07/18/2018 08:33 PM, Tom Tromey wrote: >>>>>> "Pedro" == Pedro Alves writes: > > Pedro> I gave this a try today. How about this? > > Pedro> +/* Use this to wrap a callable to throw the appropriate Scheme > Pedro> + exception if the callable throws a GDB error. ARGS are forwarded > Pedro> + to FUNC. Returns the result of FUNC, unless FUNC returns a Scheme > Pedro> + exception, in which case that exception is thrown. Note that while > Pedro> + the callable is free is use objects of types with destructors, > > Typo - "free to use objects". Thanks, fixed. > > Pedro> +++ b/gdb/guile/scm-frame.c > Pedro> @@ -783,13 +783,11 @@ gdbscm_frame_read_register (SCM self, SCM register_scm) > Pedro> char *register_str; > Pedro> struct value *value = NULL; > Pedro> struct frame_info *frame = NULL; > Pedro> - struct cleanup *cleanup; > Pedro> frame_smob *f_smob; > > Pedro> f_smob = frscm_get_frame_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME); > Pedro> gdbscm_parse_function_args (FUNC_NAME, SCM_ARG2, NULL, "s", > Pedro> register_scm, ®ister_str); > Pedro> - cleanup = make_cleanup (xfree, register_str); > > Pedro> TRY > Pedro> { > Pedro> @@ -811,7 +809,7 @@ gdbscm_frame_read_register (SCM self, SCM register_scm) > Pedro> } > Pedro> END_CATCH > > Pedro> - do_cleanups (cleanup); > Pedro> + xfree (register_str); > > I think this will leak register_str if anything throws. Maybe the xfree > should be duplicated in the catch block, or maybe the whole try/catch > should be replaced with a call to gdbscm_wrap (where the callback would > take ownership of register_str). > > This seems like a latent bug here as well - I think the code should be using > GDBSCM_HANDLE_GDB_EXCEPTION_WITH_CLEANUPS here. > Indeed. I fixed this using the same pattern used elsewhere, of saving the exception object in the CATCH block: --- c/gdb/guile/scm-frame.c +++ w/gdb/guile/scm-frame.c @@ -783,13 +783,13 @@ gdbscm_frame_read_register (SCM self, SCM register_scm) char *register_str; struct value *value = NULL; struct frame_info *frame = NULL; - struct cleanup *cleanup; frame_smob *f_smob; f_smob = frscm_get_frame_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME); gdbscm_parse_function_args (FUNC_NAME, SCM_ARG2, NULL, "s", register_scm, ®ister_str); - cleanup = make_cleanup (xfree, register_str); + + struct gdb_exception except = exception_none; TRY { @@ -805,13 +805,14 @@ gdbscm_frame_read_register (SCM self, SCM register_scm) value = value_of_register (regnum, frame); } } - CATCH (except, RETURN_MASK_ALL) + CATCH (ex, RETURN_MASK_ALL) { - GDBSCM_HANDLE_GDB_EXCEPTION (except); + except = ex; } END_CATCH - do_cleanups (cleanup); + xfree (register_str); + GDBSCM_HANDLE_GDB_EXCEPTION (except); if (frame == NULL) { > Otherwise this all looks good to me. Thanks for doing this, guile was > one of the larger cleanup holdouts Great. I wrote a ChangeLog entry and pushed it in: https://sourceware.org/ml/gdb-patches/2018-07/msg00567.html The only other change is that I copied the first paragraph of the commit log to guile/guile-internal.h. Thanks, Pedro Alves