From: Jim Blandy <jimb@codesourcery.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: "Michael Snyder" <msnyder@sonic.net>,
drow@false.org, Michael.Snyder@access-company.com,
gdb-patches@sourceware.org
Subject: Re: [OB] Add cleanup, source.c
Date: Tue, 03 Jul 2007 18:13:00 -0000 [thread overview]
Message-ID: <m3sl854b0j.fsf@codesourcery.com> (raw)
In-Reply-To: <uabuhmhfa.fsf@gnu.org> (Eli Zaretskii's message of "Sat, 30 Jun 2007 21:22:01 +0300")
What's going on here is that GDB uses one construct, cleanups, to
implement two different useful behaviors, and does so in a perilous
way.
In Java, you can write:
try {
...;
} catch {
...;
}
Or:
try {
...;
} finally {
...;
}
The 'catch' block gets executed if the 'try' block throws an
exception. The 'finally' block gets executed no matter whether the
try block terminates normally or throws an exception.
In GDB, when we push cleanups that we intend to discard on success,
those are playing the role of a 'catch' block. When we push cleanups
that we're counting on being called even if things go wrong, then
they're playing the role of a 'finally' block. They're both useful
features, and they're definitely not the same feature, because
'finally' blocks get called in more cases.
The problem with GDB is that we decide how to treat the blocks when we
clean up, not when we register. So here's the case we've been talking
about:
foo ()
{
make_cleanup (a 'finally' action)
do stuff which may throw an error
don't call do_cleanups, on at least one path out of the function
}
bar ()
{
make_cleanup (a 'catch' action)
foo ()
discard_cleanups, since we've succeeded and we don't want our catch
action to run
}
Here, if no errors occur, foo's finally action won't get run because
bar's discard_cleanups call applies more broadly than the author of
'bar' intended.
What GDB should do instead is this:
foo ()
{
finally_handler (a 'finally' action)
do stuff which may throw an error
don't call do_cleanups, at least one one path out
}
bar ()
{
failure_handler (a 'failure' action)
foo ()
cleanup_on_success ()
}
where 'cleanup_success' discards failure handlers and runs finally
handlers. The 'error' function would call a companion to that named
'cleanup_on_failure', which runs both finally and failure handlers.
So. Only 270 calls to 'do_cleanups' and 47 calls to
'discard_cleanups' to examine.
next prev parent reply other threads:[~2007-07-03 18:13 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-06-28 22:35 msnyder
2007-06-28 22:49 ` Daniel Jacobowitz
2007-06-28 23:12 ` msnyder
[not found] ` <655C3D4066B7954481633935A40BB36F041427@ussunex02.svl.access-company.com>
2007-06-29 0:24 ` Daniel Jacobowitz
2007-06-29 2:05 ` msnyder
2007-06-29 11:37 ` Daniel Jacobowitz
2007-06-29 17:02 ` Joel Brobecker
2007-06-29 20:34 ` Michael Snyder
2007-06-30 10:19 ` Michael Snyder
2007-06-30 14:17 ` Eli Zaretskii
2007-06-30 16:39 ` Michael Snyder
2007-06-30 16:40 ` Daniel Jacobowitz
2007-06-30 18:25 ` Eli Zaretskii
2007-07-03 18:13 ` Jim Blandy [this message]
2007-07-04 17:35 ` Joel Brobecker
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=m3sl854b0j.fsf@codesourcery.com \
--to=jimb@codesourcery.com \
--cc=Michael.Snyder@access-company.com \
--cc=drow@false.org \
--cc=eliz@gnu.org \
--cc=gdb-patches@sourceware.org \
--cc=msnyder@sonic.net \
/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