From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 21150 invoked by alias); 19 Feb 2016 19:48:02 -0000 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 Received: (qmail 21060 invoked by uid 89); 19 Feb 2016 19:48:00 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=sk:Referen, inspect X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Fri, 19 Feb 2016 19:47:59 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (Postfix) with ESMTPS id 9199D8051E; Fri, 19 Feb 2016 19:47:58 +0000 (UTC) Received: from valrhona.uglyboxes.com (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u1JJlvMb018996 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Fri, 19 Feb 2016 14:47:58 -0500 From: Keith Seitz Subject: Re: [PATCH v2 10/11] [PR gdb/14441] gdb: python: support rvalue references in the gdb module To: Artemiy Volkov , gdb-patches@sourceware.org References: <1450661481-31178-1-git-send-email-artemiyv@acm.org> <1453229609-20159-1-git-send-email-artemiyv@acm.org> <1453229609-20159-11-git-send-email-artemiyv@acm.org> Message-ID: <56C7716D.60409@redhat.com> Date: Fri, 19 Feb 2016 19:48:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.1.0 MIME-Version: 1.0 In-Reply-To: <1453229609-20159-11-git-send-email-artemiyv@acm.org> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit X-IsSubscribed: yes X-SW-Source: 2016-02/txt/msg00621.txt.bz2 On 01/19/2016 10:53 AM, Artemiy Volkov wrote: > This patch adds the ability to inspect rvalue reference types and values using > the gdb python module. Changes include the RvalueReferenceExplorer method > providing mechanism to get a type and a referenced value for an rvalue > reference object, and the valpy_rvalue_reference_value() function used > to create an rvalue reference to an object of any type. > > ./ChangeLog: > > 2016-01-19 Artemiy Volkov > > * gdb/python/lib/gdb/command/explore.py: Add > RvalueReferenceExplorer class. The usual way to do this would be to mention the class first: * python/lib/gdb/command/explore.py (RvalueReferenceExplorer): New class. But more on this later... > * gdb/python/lib/gdb/types.py: Implement get_basic_type() for > rvalue reference types. Similarly, * python/lib/gdb/types.py (get_basic_type): Handle TYPE_CODE_RVALUE_REFERENCE. > * gdb/python/py-type.c: Add TYPE_CODE_RVALUE_REF to pyty_codes. I would do the same here, too. > * gdb/python/py-value.c (valpy_rvalue_reference_value): Add value > getter function. > --- > gdb/python/lib/gdb/command/explore.py | 21 +++++++++++++++++++++ > gdb/python/lib/gdb/types.py | 4 +++- > gdb/python/py-type.c | 1 + > gdb/python/py-value.c | 26 ++++++++++++++++++++++++++ > 4 files changed, 51 insertions(+), 1 deletion(-) > > diff --git a/gdb/python/lib/gdb/command/explore.py b/gdb/python/lib/gdb/command/explore.py > index 6c9f17b..a980274 100644 > --- a/gdb/python/lib/gdb/command/explore.py > +++ b/gdb/python/lib/gdb/command/explore.py > @@ -318,6 +319,26 @@ class ReferenceExplorer(object): > Explorer.explore_type(name, target_type, is_child) > return False > > +class RvalueReferenceExplorer(object): > + """Internal class used to explore rvalue reference (TYPE_CODE_RVALUE_REF) values.""" > + > + @staticmethod > + def explore_expr(expr, value, is_child): > + """Function to explore array values. > + See Explorer.explore_expr for more information. > + """ > + referenced_value = value.referenced_value() > + Explorer.explore_expr(expr, referenced_value, is_child) > + return False > + > + @staticmethod > + def explore_type(name, datatype, is_child): > + """Function to explore pointer types. > + See Explorer.explore_type for more information. > + """ > + target_type = datatype.target() > + Explorer.explore_type(name, target_type, is_child) > + return False I'm not all that familiar with python, but is there a reason for this to be a new class? It looks identical to ReferenceExplorer? > class ArrayExplorer(object): > """Internal class used to explore arrays.""" > diff --git a/gdb/python/py-value.c b/gdb/python/py-value.c > index 81d1225..dcc0cf9 100644 > --- a/gdb/python/py-value.c > +++ b/gdb/python/py-value.c > @@ -263,6 +263,30 @@ valpy_reference_value (PyObject *self, PyObject *args) > return result; > } > > +/* Return a value which is an rvalue reference to the value. */ > + > +static PyObject * > +valpy_rvalue_reference_value (PyObject *self, PyObject *args) > +{ > + PyObject *result = NULL; > + > + TRY > + { > + struct value *self_val; > + struct cleanup *cleanup = make_cleanup_value_free_to_mark (value_mark ()); > + > + self_val = ((value_object *) self)->value; > + result = value_to_value_object (value_ref (self_val, TYPE_CODE_RVALUE_REF)); > + do_cleanups (cleanup); > + } > + CATCH (except, RETURN_MASK_ALL) > + { > + GDB_PY_HANDLE_EXCEPTION (except); > + } > + END_CATCH > + > + return result; > +} > /* Return a "const" qualified version of the value. */ > > static PyObject * > @@ -1778,6 +1802,8 @@ reinterpret_cast operator." > "Return the value referenced by a TYPE_CODE_REF or TYPE_CODE_PTR value." }, > { "reference_value", valpy_reference_value, METH_NOARGS, > "Return a value of type TYPE_CODE_REF referencing this value." }, > + { "rvalue_reference_value", valpy_rvalue_reference_value, METH_NOARGS, > + "Return a value of type TYPE_CODE_RVALUE_REF referencing this value." }, > { "const_value", valpy_const_value, METH_NOARGS, > "Return a 'const' qualied version of the same value." }, > { "lazy_string", (PyCFunction) valpy_lazy_string, Same question here... rvalue_reference_value/valpy_rvalue_reference_value have nearly identical implementations as reference_value/valpy_reference_value. Does TYPE_CODE (value_type (self_val)) not tell us which of the types we are looking at? If so, I think it would be better to unify reference handling into a common implementation, noting that the class handles both types of references. Keith