Mirror of the gdb mailing list
 help / color / mirror / Atom feed
From: Jan Kratochvil <jan.kratochvil@redhat.com>
To: Phil Muldoon <pmuldoon@redhat.com>
Cc: gdb@sourceware.org
Subject: Re: Cleanups and Exception handlers
Date: Wed, 01 May 2013 15:21:00 -0000	[thread overview]
Message-ID: <20130501152116.GA7529@host2.jankratochvil.net> (raw)
In-Reply-To: <5180EE37.3020507@redhat.com>

On Wed, 01 May 2013 12:28:07 +0200, Phil Muldoon wrote:
> Question 1)
> 
> What is the rule regarding cleanup chains that were created outside of
> an exception handler, but where

> additional cleanups were registered
> and not processed (cleanedup) inside the exception handler.

When you end TRY_CATCH block (therefore not exiting the block by a thrown
exception) there must be no leftover cleanups.  You must do_cleanups or
discard_cleanups them all.  Debugging some new gdb_assert at that point here,
it may make sense there.


> Question 2)
> 
> If in the above example, something goes wrong, does one have to call
> do_cleanups() in the exception handling block (IE if (except.reason <
> 0))

You have to call do_cleanups in the same TRY_CATCH block.  TRY_CATCH
completely separates handling of exceptions outside of the block vs. inside of
the block.

Therefore "Example 2" is right:

> Example 2:
> 
> 
>   TRY_CATCH (except, RETURN_MASK_ALL)
>   {
>     struct cleanups cleanups =
>       make_cleanup_ui_out_tuple_begin_end (out, NULL);	
>       ...
>       // Do some other stuff
>     do_cleanups (cleanups);	
>     }
>   if (except.reason < 0)
>     {
>       // Some exception handling code
>     }
> 
> In this example we create a pointer to the cleanup chain, and perform
> a tuple cleanup.  If I call do_cleanups() in this example (assuming
> nothing went wrong in the TRY_CATCH block), the tuple is cleaned up
> properly.  But what happens if something happens and the exception
> handling "if" is called.

In such case cleanups are executed already inside the TRY_CATCH block at the
time the exception was thrown.  throw_exception contains:
	do_cleanups (all_cleanups ());

This will execute all pending cleanup handlers inside the TRY_CATCH block.
But no cleanups outside of the TRY_CATCH block.


> Question 3)
> 
> For cleanups created and registered exclusively in the TRY_CATCH
> block, on some exception being raised are they cleaned up
> automatically?

Yes, see above:
In such case cleanups are executed already inside the TRY_CATCH block at the
time the exception was thrown.  throw_exception contains:
	do_cleanups (all_cleanups ());


> This all came about as MI tuples tend to be "long lived" cleanups and
> in Python we have to handle every potential GDB exception call in an
> exception handler to prevent propagation upwards.

It seemed to me that there were too many TRY_CATCH blocks even in cases where
nothing can throw an exception.


Jan


  reply	other threads:[~2013-05-01 15:21 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-05-01 10:28 Phil Muldoon
2013-05-01 15:21 ` Jan Kratochvil [this message]
2013-05-01 18:46   ` Phil Muldoon
2013-05-01 19:44     ` Jan Kratochvil
2013-05-04 17:52       ` Doug Evans
2013-05-06 17:32 ` 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=20130501152116.GA7529@host2.jankratochvil.net \
    --to=jan.kratochvil@redhat.com \
    --cc=gdb@sourceware.org \
    --cc=pmuldoon@redhat.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