From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 23824 invoked by alias); 1 Oct 2011 12:17:06 -0000 Received: (qmail 23813 invoked by uid 22791); 1 Oct 2011 12:17:03 -0000 X-SWARE-Spam-Status: No, hits=-6.8 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,SPF_HELO_PASS 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 12:16:47 +0000 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p91CGk9x010464 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Sat, 1 Oct 2011 08:16:46 -0400 Received: from host1.jankratochvil.net (ovpn-116-16.ams2.redhat.com [10.36.116.16]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id p91CGhxb015584 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Sat, 1 Oct 2011 08:16:45 -0400 Received: from host1.jankratochvil.net (localhost [127.0.0.1]) by host1.jankratochvil.net (8.14.4/8.14.4) with ESMTP id p91CGhIG029571; Sat, 1 Oct 2011 14:16:43 +0200 Received: (from jkratoch@localhost) by host1.jankratochvil.net (8.14.4/8.14.4/Submit) id p91CGgjX029570; Sat, 1 Oct 2011 14:16:42 +0200 Date: Sat, 01 Oct 2011 12:17:00 -0000 From: Jan Kratochvil To: Phil Muldoon Cc: Paul Koning , gdb-patches@sourceware.org Subject: Re: Python: fetch value when building gdb.Value object [rediff] Message-ID: <20111001121642.GA29550@host1.jankratochvil.net> References: <36B29E9D-F2B3-446F-AF8A-97254A3AAEE2@comcast.net> <20111001092852.GB11227@host1.jankratochvil.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20111001092852.GB11227@host1.jankratochvil.net> 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/msg00010.txt.bz2 Updated for current HEAD: On Sat, 01 Oct 2011 11:28:52 +0200, Jan Kratochvil wrote: On Wed, 28 Sep 2011 21:24:45 +0200, Phil Muldoon wrote: > What scenario will this test catch that the previous test won't? I'm > not saying you are incorrect, I just don't understand. What > error-trigger does the assignment to "inval" trigger? I would prefer here a testcase more clearly showing the bug, attached below. I believe the patch is right, as Phil hasn't yet agreed posting it only. Thanks, Jan gdb/ 2011-09-21 Paul Koning * python/py-value.c (valpy_get_address): Use Py_XINCREF. (value_to_value_object): Fetch value if it was lazy. testsuite/ 2011-09-21 Paul Koning Jan Kratochvil * gdb.python/py-value.exp (python inval = gdb.parse_and_eval('*(int*)0')) (python argc_lazy = gdb.parse_and_eval('argc'), sanity check argc) (set argc=2, python print argc_lazy): New tests. --- a/gdb/python/py-value.c +++ b/gdb/python/py-value.c @@ -209,7 +209,7 @@ valpy_get_address (PyObject *self, void *closure) val_obj->address = value_to_value_object (res_val); } - Py_INCREF (val_obj->address); + Py_XINCREF (val_obj->address); return val_obj->address; } @@ -1045,7 +1045,15 @@ PyObject * value_to_value_object (struct value *val) { value_object *val_obj; + volatile struct gdb_exception except; + TRY_CATCH (except, RETURN_MASK_ALL) + { + if (value_lazy (val)) + value_fetch_lazy (val); + } + GDB_PY_HANDLE_EXCEPTION (except); + val_obj = PyObject_New (value_object, &value_object_type); if (val_obj != NULL) { --- a/gdb/testsuite/gdb.python/py-value.exp +++ b/gdb/testsuite/gdb.python/py-value.exp @@ -236,6 +236,18 @@ proc test_value_in_inferior {} { gdb_test "python print gdb.parse_and_eval('*(int*)0')" "gdb.MemoryError: Cannot access memory at address 0x0.*" $test } + # Test Python values are not lazy. + set test "memory error occurs even for possibly lazy values" + if {$can_read_0} { + untested $test + } else { + gdb_test "python inval = gdb.parse_and_eval('*(int*)0')" "gdb.MemoryError: Cannot access memory at address 0x0.*" $test + } + gdb_test "python argc_lazy = gdb.parse_and_eval('argc')" + gdb_test "print argc" " = 1" "sanity check argc" + gdb_test_no_output "set argc=2" + gdb_test "python print argc_lazy" "\r\n1" + # Test string fetches, both partial and whole. gdb_test "print st" "\"divide et impera\"" gdb_py_test_silent_cmd "python st = gdb.history (0)" "get value from history" 1