From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 1891 invoked by alias); 29 Mar 2009 21:16:17 -0000 Received: (qmail 1877 invoked by uid 22791); 29 Mar 2009 21:16:15 -0000 X-SWARE-Spam-Status: No, hits=-2.4 required=5.0 tests=AWL,BAYES_00,J_CHICKENPOX_37,SPF_PASS X-Spam-Check-By: sourceware.org Received: from e24smtp03.br.ibm.com (HELO e24smtp03.br.ibm.com) (32.104.18.24) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sun, 29 Mar 2009 21:16:10 +0000 Received: from mailhub1.br.ibm.com (mailhub1.br.ibm.com [9.18.232.109]) by e24smtp03.br.ibm.com (8.13.1/8.13.1) with ESMTP id n2TLC0WL020759 for ; Sun, 29 Mar 2009 18:12:00 -0300 Received: from d24av02.br.ibm.com (d24av02.br.ibm.com [9.18.232.47]) by mailhub1.br.ibm.com (8.13.8/8.13.8/NCO v9.2) with ESMTP id n2TLGPQN885128 for ; Sun, 29 Mar 2009 18:16:25 -0300 Received: from d24av02.br.ibm.com (loopback [127.0.0.1]) by d24av02.br.ibm.com (8.12.11.20060308/8.13.3) with ESMTP id n2TLG7Ya002852 for ; Sun, 29 Mar 2009 18:16:07 -0300 Received: from [9.8.15.217] ([9.8.15.217]) by d24av02.br.ibm.com (8.12.11.20060308/8.12.11) with ESMTP id n2TLG68d002846; Sun, 29 Mar 2009 18:16:06 -0300 Subject: Re: [RFA][Python] Change gdb.Value.address from a method to an attribute. From: Thiago Jung Bauermann To: Eli Zaretskii Cc: Tom Tromey , gdb-patches@sourceware.org In-Reply-To: References: <20090310125945.GA4376@caradoc.them.org> <1236700079.11106.1.camel@localhost.localdomain> <1236710732.11106.30.camel@localhost.localdomain> <1237771863.25721.17.camel@localhost.localdomain> <1238275138.8292.3.camel@localhost.localdomain> Content-Type: text/plain; charset=utf-8 Date: Sun, 29 Mar 2009 21:22:00 -0000 Message-Id: <1238361366.7100.4.camel@localhost.localdomain> Mime-Version: 1.0 Content-Transfer-Encoding: 8bit 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: 2009-03/txt/msg00662.txt.bz2 El dom, 29-03-2009 a las 21:10 +0300, Eli Zaretskii escribió: > > From: Tom Tromey > > Date: Sun, 29 Mar 2009 09:41:48 -0600 > > But perhaps the first "the @code{}" can be changed to "this". > > Fine with me, thanks. Ok, I committed the following. -- []'s Thiago Jung Bauermann IBM Linux Technology Center gdb/ Change gdb.Value.address from a method to an attribute. * python/python-value.c (value_object): Add `address' element. (valpy_dealloc): Decrement reference to self->address if set. (valpy_new): Initialize val_obj->address. (valpy_address): Rename to ... (valpy_get_address): ... this. Change signature from method to attribute. Update self->address if not set. (value_to_value_object): Initialize val_obj->address. (value_object_getset): Add `address' element. (value_object_methods): Remove `address' element. gdb/testsuite/ * gdb.python/python-value.exp: Add tests for the address attribute. gdb/doc/ * gdb.texinfo (Values From Inferior): Change gdb.Value.address from a method to an attribute. Index: src/gdb/doc/gdb.texinfo =================================================================== --- src.orig/gdb/doc/gdb.texinfo 2009-03-28 17:55:49.000000000 -0300 +++ src/gdb/doc/gdb.texinfo 2009-03-29 18:03:09.000000000 -0300 @@ -18325,9 +18325,15 @@ bar = some_val['foo'] Again, @code{bar} will also be a @code{gdb.Value} object. -The following attribute is provided: +The following attributes are provided: @table @code +@defmethod Value address +If this object is addressable, this read-only attribute holds a +@code{gdb.Value} object representing the address. Otherwise, +this attribute holds @code{None}. +@end defmethod + @cindex optimized out value in Python @defmethod Value is_optimized_out This read-only boolean attribute is true if the compiler optimized out Index: src/gdb/python/python-value.c =================================================================== --- src.orig/gdb/python/python-value.c 2009-03-28 17:55:49.000000000 -0300 +++ src/gdb/python/python-value.c 2009-03-28 17:55:51.000000000 -0300 @@ -59,6 +59,7 @@ typedef struct { PyObject_HEAD struct value *value; int owned_by_gdb; + PyObject *address; } value_object; /* Called by the Python interpreter when deallocating a value object. */ @@ -71,6 +72,13 @@ valpy_dealloc (PyObject *obj) if (!self->owned_by_gdb) value_free (self->value); + + if (self->address) + /* Use braces to appease gcc warning. *sigh* */ + { + Py_DECREF (self->address); + } + self->ob_type->tp_free (self); } @@ -105,6 +113,7 @@ valpy_new (PyTypeObject *subtype, PyObje value_obj->value = value; value_obj->owned_by_gdb = 0; + value_obj->address = NULL; release_value (value); value_prepend_to_list (&values_in_python, value); @@ -129,18 +138,30 @@ valpy_dereference (PyObject *self, PyObj /* Return "&value". */ static PyObject * -valpy_address (PyObject *self, PyObject *args) +valpy_get_address (PyObject *self, void *closure) { struct value *res_val = NULL; /* Initialize to appease gcc warning. */ + value_object *val_obj = (value_object *) self; volatile struct gdb_exception except; - TRY_CATCH (except, RETURN_MASK_ALL) + if (!val_obj->address) { - res_val = value_addr (((value_object *) self)->value); + TRY_CATCH (except, RETURN_MASK_ALL) + { + res_val = value_addr (val_obj->value); + } + if (except.reason < 0) + { + val_obj->address = Py_None; + Py_INCREF (Py_None); + } + else + val_obj->address = value_to_value_object (res_val); } - GDB_PY_HANDLE_EXCEPTION (except); - return value_to_value_object (res_val); + Py_INCREF (val_obj->address); + + return val_obj->address; } /* Implementation of gdb.Value.string ([encoding] [, errors]) -> string @@ -726,6 +747,7 @@ value_to_value_object (struct value *val { val_obj->value = val; val_obj->owned_by_gdb = 0; + val_obj->address = NULL; release_value (val); value_prepend_to_list (&values_in_python, val); } @@ -838,6 +860,8 @@ gdbpy_initialize_values (void) } static PyGetSetDef value_object_getset[] = { + { "address", valpy_get_address, NULL, "The address of the value.", + NULL }, { "is_optimized_out", valpy_get_is_optimized_out, NULL, "Boolean telling whether the value is optimized out (i.e., not available).", NULL }, @@ -845,7 +869,6 @@ static PyGetSetDef value_object_getset[] }; static PyMethodDef value_object_methods[] = { - { "address", valpy_address, METH_NOARGS, "Return the address of the value." }, { "dereference", valpy_dereference, METH_NOARGS, "Dereferences the value." }, { "string", (PyCFunction) valpy_string, METH_VARARGS | METH_KEYWORDS, "string ([encoding] [, errors]) -> string\n\ Index: src/gdb/testsuite/gdb.python/python-value.exp =================================================================== --- src.orig/gdb/testsuite/gdb.python/python-value.exp 2009-03-28 17:55:49.000000000 -0300 +++ src/gdb/testsuite/gdb.python/python-value.exp 2009-03-28 17:55:51.000000000 -0300 @@ -70,6 +70,9 @@ proc test_value_creation {} { gdb_py_test_silent_cmd "python a = gdb.Value (u'unicode test')" "create unicode value" 1 gdb_test "python print a" "\"unicode test\"" "print Unicode string" gdb_test "python print a.__class__" "" "verify type of unicode string" + + # Test address attribute is None in a non-addressable value + gdb_test "python print 'result =', i.address" "= None" "Test address attribute in non-addressable value" } proc test_value_numeric_ops {} { @@ -228,6 +231,9 @@ proc test_value_in_inferior {} { # Smoke-test is_optimized_out attribute gdb_test "python print 'result =', arg0.is_optimized_out" "= False" "Test is_optimized_out attribute" + + # Test address attribute + gdb_test "python print 'result =', arg0.address" "= 0x\[\[:xdigit:\]\]+" "Test address attribute" }