From: Jan Kratochvil <jan.kratochvil@redhat.com>
To: Paul Koning <paulkoning@comcast.net>
Cc: pmuldoon@redhat.com, gdb-patches@sourceware.org
Subject: Re: Python: fetch value when building gdb.Value object
Date: Sat, 01 Oct 2011 09:05:00 -0000 [thread overview]
Message-ID: <20111001090443.GA11227@host1.jankratochvil.net> (raw)
In-Reply-To: <D9AC6973-91CF-42D4-AD81-0C4A41D3DD2A@comcast.net>
On Wed, 28 Sep 2011 22:40:50 +0200, Paul Koning wrote:
> If I use RETURN_MASK_ERROR and control/C is hit, does that mean the
> currently running code aborts and the outer handler that does have
> RETURN_MASK_ALL is entered?
Yes.
> If so, most of the Python code seems to be a candidate for
> RETURN_MASK_ERROR.
In fact I do not know, it is a Python thing.
RETURN_MASK_ALL is right if returned PyExc_KeyboardInterrupt will really abort
any execution of Python code. It is probably so, as suggested by:
http://docs.python.org/library/exceptions.html#exceptions.KeyboardInterrupt
RETURN_MASK_ERROR is right otherwise, but only if it is safe to longjmp out
from a code called by Python. This may not be true. Python may be C++
exceptions throwing safe but it cannot be safe for the GDB longjmp exceptions.
But this case would mean Python is buggy for CTRL-C on its own so
RETURN_MASK_ERROR probably is not right.
> One exception is valpy_getitem (in py-value.c) since it has an xfree(value)
> after the TRY_CATCH but before the GDB_PY_HANDLE_EXCEPTION (outside the
> TRY_CATCH block, though -- is that right?)
It is right as long as RETURN_MASK_ALL is right. It is more usual to call
make_cleanup though - as shown in the attached change. The change could be
just a code cleanup without functionality change if that RETURN_MASK_ALL is
kept there.
> Probably related: I just tried an infinite Python loop and found that
> control-C had no effect. I wonder if the Python interpreter is setting up
> its own control-C trap (quite possibly -- that's a Python exception after
> all) and we're losing it somewhere along the lines.
Yes, this is the kind of bug from it, thanks for checking it.
Thanks,
Jan
only FYI, not intended for commit:
gdb/
2011-10-01 Jan Kratochvil <jan.kratochvil@redhat.com>
* python/py-value.c (valpy_getitem): New variable back_to. Register
xfree of field to it. Call do_cleanups for it. Use RETURN_MASK_ERROR
instead of RETURN_MASK_ALL.
--- a/gdb/python/py-value.c
+++ b/gdb/python/py-value.c
@@ -448,6 +448,7 @@ valpy_getitem (PyObject *self, PyObject *key)
char *field = NULL;
struct value *res_val = NULL;
volatile struct gdb_exception except;
+ struct cleanup *back_to;
if (gdbpy_is_string (key))
{
@@ -456,7 +457,9 @@ valpy_getitem (PyObject *self, PyObject *key)
return NULL;
}
- TRY_CATCH (except, RETURN_MASK_ALL)
+ back_to = make_cleanup (xfree, field);
+
+ TRY_CATCH (except, RETURN_MASK_ERROR)
{
struct value *tmp = self_value->value;
@@ -485,10 +488,10 @@ valpy_getitem (PyObject *self, PyObject *key)
}
}
}
-
- xfree (field);
GDB_PY_HANDLE_EXCEPTION (except);
+ do_cleanups (back_to);
+
return res_val ? value_to_value_object (res_val) : NULL;
}
next prev parent reply other threads:[~2011-10-01 9:05 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-09-21 16:17 Paul Koning
2011-09-28 19:29 ` Phil Muldoon
2011-09-28 20:06 ` Paul Koning
2011-10-04 15:43 ` Tom Tromey
2011-09-28 20:42 ` Paul Koning
2011-10-01 9:05 ` Jan Kratochvil [this message]
2011-10-03 10:22 ` Phil Muldoon
2011-10-04 15:40 ` Tom Tromey
2011-10-01 9:29 ` Jan Kratochvil
2011-10-01 10:23 ` Pedro Alves
2011-10-01 11:03 ` Jan Kratochvil
2011-10-01 12:17 ` Python: fetch value when building gdb.Value object [rediff] Jan Kratochvil
2011-10-01 18:58 ` Paul Koning
2011-10-03 10:19 ` Phil Muldoon
2011-10-03 16:16 ` Paul Koning
2011-10-01 1:00 ` [PING] [RFA] Re: Python: fetch value when building gdb.Value object Paul Koning
2011-10-04 15:45 ` Tom Tromey
2011-10-04 15:51 ` Paul Koning
2011-10-14 20:03 ` Tom Tromey
2011-10-14 20:30 ` Paul Koning
2011-10-19 20:56 ` Tom Tromey
2011-10-19 20:58 ` Paul Koning
2011-10-20 15:09 ` Tom Tromey
2011-10-21 7:46 ` Paul Koning
2011-10-21 17:13 ` Tom Tromey
2011-10-14 23:36 ` Jim Blandy
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=20111001090443.GA11227@host1.jankratochvil.net \
--to=jan.kratochvil@redhat.com \
--cc=gdb-patches@sourceware.org \
--cc=paulkoning@comcast.net \
--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