Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Pedro Alves <palves@redhat.com>
To: Tom Tromey <tom@tromey.com>
Cc: gdb-patches@sourceware.org
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)
Date: Wed, 18 Jul 2018 22:31:00 -0000	[thread overview]
Message-ID: <652df685-c1bd-7d91-e1c7-0c17fc86e528@redhat.com> (raw)
In-Reply-To: <87y3e849ux.fsf@tromey.com>

On 07/18/2018 08:33 PM, Tom Tromey wrote:
>>>>>> "Pedro" == Pedro Alves <palves@redhat.com> 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, &register_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, &register_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


  reply	other threads:[~2018-07-18 22:31 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-27 15:20 [RFA 0/4] some simple cleanup removal in guile Tom Tromey
2018-05-27 15:20 ` [RFA 1/4] Use std::string in ppscm_make_pp_type_error_exception Tom Tromey
2018-07-17 13:08   ` Pedro Alves
2018-05-27 15:20 ` [RFA 3/4] Return unique_xmalloc_ptr from gdbscm_safe_eval_string Tom Tromey
2018-07-17 13:08   ` Pedro Alves
2018-05-27 15:40 ` [RFA 2/4] Change gdbscm_exception_message_to_string to return a unique_xmalloc_ptr Tom Tromey
2018-07-17 13:08   ` Pedro Alves
2018-07-17 19:11     ` Tom Tromey
2018-07-18 13:29       ` [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) Pedro Alves
2018-07-18 19:34         ` Tom Tromey
2018-07-18 22:31           ` Pedro Alves [this message]
2018-05-27 15:54 ` [RFA 4/4] Return unique_xmalloc_ptr from gdbscm_scm_to_string Tom Tromey
2018-07-17 13:09   ` Pedro Alves
2018-06-18 14:37 ` [RFA 0/4] some simple cleanup removal in guile Tom Tromey
2018-07-16 16:35   ` Tom Tromey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=652df685-c1bd-7d91-e1c7-0c17fc86e528@redhat.com \
    --to=palves@redhat.com \
    --cc=gdb-patches@sourceware.org \
    --cc=tom@tromey.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox