From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 10205 invoked by alias); 1 Oct 2011 09:05:07 -0000 Received: (qmail 10187 invoked by uid 22791); 1 Oct 2011 09:05:05 -0000 X-SWARE-Spam-Status: No, hits=-6.7 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,SPF_HELO_PASS,TW_GJ X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sat, 01 Oct 2011 09:04:48 +0000 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p9194lE3030990 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Sat, 1 Oct 2011 05:04:47 -0400 Received: from host1.jankratochvil.net (ovpn-116-16.ams2.redhat.com [10.36.116.16]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id p9194iOo012682 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Sat, 1 Oct 2011 05:04:46 -0400 Received: from host1.jankratochvil.net (localhost [127.0.0.1]) by host1.jankratochvil.net (8.14.4/8.14.4) with ESMTP id p9194io2012475; Sat, 1 Oct 2011 11:04:44 +0200 Received: (from jkratoch@localhost) by host1.jankratochvil.net (8.14.4/8.14.4/Submit) id p9194h1L012474; Sat, 1 Oct 2011 11:04:43 +0200 Date: Sat, 01 Oct 2011 09:05:00 -0000 From: Jan Kratochvil To: Paul Koning Cc: pmuldoon@redhat.com, gdb-patches@sourceware.org Subject: Re: Python: fetch value when building gdb.Value object Message-ID: <20111001090443.GA11227@host1.jankratochvil.net> References: <36B29E9D-F2B3-446F-AF8A-97254A3AAEE2@comcast.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) X-IsSubscribed: yes 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 X-SW-Source: 2011-10/txt/msg00005.txt.bz2 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 * 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; }