From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 26947 invoked by alias); 6 Jun 2016 19:23:10 -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 26805 invoked by uid 89); 6 Jun 2016 19:23:09 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.5 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=ham version=3.3.2 spammy=1056, sk:type_is, sk:TYPE_IS, 105,6 X-HELO: mail-lf0-f65.google.com Received: from mail-lf0-f65.google.com (HELO mail-lf0-f65.google.com) (209.85.215.65) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Mon, 06 Jun 2016 19:22:56 +0000 Received: by mail-lf0-f65.google.com with SMTP id h68so14390651lfh.3 for ; Mon, 06 Jun 2016 12:22:55 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=ZnRWgdaAuPbg7v1Qj/Rs313e1+66j13fOY1GFjpihJk=; b=Ob4zlsTMlspOjF8T82zsHRyVV2FdLUCVtJhx6XJLwMgI2eSWRqjmNvQ5Am37J3UWpB XThPevLLoK7BP943+pN3kGUbbjPdTYUgi3oQnKI8+ONlQwj2hoeVhl/owQ1shTpB3Lt2 i7BX/8Y8Bfp+qwAkOa6ys5GtD7tOMCTPJQiAM8ziGq7ueGtzWS2x+vRY1aP02GxSKLkc zxgD3XV6PzV8WScMnyqutZRAy+t4BiKEySz11N6C2+xkYOKy+08SLezL9XxINSbcAzFC qGIatX6h2N15XJ13T7GCFcT6YAE9+kBFUnpG+mz9jVMH8ggRr4lh+yAA8Y217KwlkRQQ 8mgA== X-Gm-Message-State: ALyK8tI8VSQLBFnuwBnmFfRi5XWga2KlGqp+CAyINlgqM2lPxtzvQMXIIDQlryRceZMxeA== X-Received: by 10.25.16.230 with SMTP id 99mr1683360lfq.21.1465240973042; Mon, 06 Jun 2016 12:22:53 -0700 (PDT) Received: from localhost.localdomain (broadband-90-154-70-138.nationalcablenetworks.ru. [90.154.70.138]) by smtp.gmail.com with ESMTPSA id jv7sm1970253lbc.4.2016.06.06.12.22.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 Jun 2016 12:22:52 -0700 (PDT) From: Artemiy Volkov To: gdb-patches@sourceware.org Cc: palves@redhat.com, keiths@redhat.com, Artemiy Volkov Subject: [PATCH v5 08/11] [PR gdb/14441] gdb: python: support rvalue references in the gdb module Date: Mon, 06 Jun 2016 19:23:00 -0000 Message-Id: <20160606192225.12384-9-artemiyv@acm.org> In-Reply-To: <20160606192225.12384-1-artemiyv@acm.org> References: <1458593958-25656-1-git-send-email-artemiyv@acm.org> <20160606192225.12384-1-artemiyv@acm.org> X-IsSubscribed: yes X-SW-Source: 2016-06/txt/msg00111.txt.bz2 This patch adds the ability to inspect rvalue reference types and values using the gdb python module. This is achieved by creating two wrappers for valpy_reference_value(), using the ReferenceExplorer class to handle the objects of rvalue reference types and placing necessary checks for a TYPE_CODE_RVALUE_REF type code next to the checks for a TYPE_CODE_REF type code. gdb/ChangeLog: 2016-06-06 Artemiy Volkov PR gdb/14441 * python/lib/gdb/command/explore.py: Support exploring values of rvalue reference types. * python/lib/gdb/types.py: Implement get_basic_type() for rvalue reference types. * python/py-type.c (pyty_codes) : New constant. * python/py-value.c (valpy_getitem): Add an rvalue reference check. (valpy_reference_value): Add new parameter "refcode". (valpy_lvalue_reference_value, valpy_rvalue_reference_value): New wrappers for valpy_reference_value(). * python/py-xmethods.c (gdbpy_get_xmethod_result_type) (gdbpy_invoke_xmethod): Likewise. --- gdb/python/lib/gdb/command/explore.py | 2 +- gdb/python/lib/gdb/types.py | 4 +++- gdb/python/py-type.c | 1 + gdb/python/py-value.c | 26 +++++++++++++++++++++----- gdb/python/py-xmethods.c | 10 ++++++---- 5 files changed, 32 insertions(+), 11 deletions(-) diff --git a/gdb/python/lib/gdb/command/explore.py b/gdb/python/lib/gdb/command/explore.py index 6c9f17b..ed25fa6 100644 --- a/gdb/python/lib/gdb/command/explore.py +++ b/gdb/python/lib/gdb/command/explore.py @@ -132,6 +132,7 @@ class Explorer(object): gdb.TYPE_CODE_UNION : CompoundExplorer, gdb.TYPE_CODE_PTR : PointerExplorer, gdb.TYPE_CODE_REF : ReferenceExplorer, + gdb.TYPE_CODE_RVALUE_REF : ReferenceExplorer, gdb.TYPE_CODE_TYPEDEF : TypedefExplorer, gdb.TYPE_CODE_ARRAY : ArrayExplorer } @@ -318,7 +319,6 @@ class ReferenceExplorer(object): Explorer.explore_type(name, target_type, is_child) return False - class ArrayExplorer(object): """Internal class used to explore arrays.""" diff --git a/gdb/python/lib/gdb/types.py b/gdb/python/lib/gdb/types.py index c22e8a9..59b7df2 100644 --- a/gdb/python/lib/gdb/types.py +++ b/gdb/python/lib/gdb/types.py @@ -31,8 +31,10 @@ def get_basic_type(type_): """ while (type_.code == gdb.TYPE_CODE_REF or + type_.code == gdb.TYPE_CODE_RVALUE_REF or type_.code == gdb.TYPE_CODE_TYPEDEF): - if type_.code == gdb.TYPE_CODE_REF: + if (type_.code == gdb.TYPE_CODE_REF or + type_.code == gdb.TYPE_CODE_RVALUE_REF): type_ = type_.target() else: type_ = type_.strip_typedefs() diff --git a/gdb/python/py-type.c b/gdb/python/py-type.c index 4ec920e..259bb70 100644 --- a/gdb/python/py-type.c +++ b/gdb/python/py-type.c @@ -105,6 +105,7 @@ static struct pyty_code pyty_codes[] = ENTRY (TYPE_CODE_METHODPTR), ENTRY (TYPE_CODE_MEMBERPTR), ENTRY (TYPE_CODE_REF), + ENTRY (TYPE_CODE_RVALUE_REF), ENTRY (TYPE_CODE_CHAR), ENTRY (TYPE_CODE_BOOL), ENTRY (TYPE_CODE_COMPLEX), diff --git a/gdb/python/py-value.c b/gdb/python/py-value.c index 73cc6bd..a422796 100644 --- a/gdb/python/py-value.c +++ b/gdb/python/py-value.c @@ -239,7 +239,7 @@ valpy_referenced_value (PyObject *self, PyObject *args) /* Return a value which is a reference to the value. */ static PyObject * -valpy_reference_value (PyObject *self, PyObject *args) +valpy_reference_value (PyObject *self, PyObject *args, enum type_code refcode) { PyObject *result = NULL; @@ -249,7 +249,7 @@ valpy_reference_value (PyObject *self, PyObject *args) 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_REF)); + result = value_to_value_object (value_ref (self_val, refcode)); do_cleanups (cleanup); } @@ -262,6 +262,18 @@ valpy_reference_value (PyObject *self, PyObject *args) return result; } +static PyObject * +valpy_lvalue_reference_value (PyObject *self, PyObject *args) +{ + return valpy_reference_value (self, args, TYPE_CODE_REF); +} + +static PyObject * +valpy_rvalue_reference_value (PyObject *self, PyObject *args) +{ + return valpy_reference_value (self, args, TYPE_CODE_RVALUE_REF); +} + /* Return a "const" qualified version of the value. */ static PyObject * @@ -598,8 +610,7 @@ value_has_field (struct value *v, PyObject *field) { val_type = value_type (v); val_type = check_typedef (val_type); - if (TYPE_CODE (val_type) == TYPE_CODE_REF - || TYPE_CODE (val_type) == TYPE_CODE_PTR) + if (TYPE_IS_REFERENCE (val_type) || TYPE_CODE (val_type) == TYPE_CODE_PTR) val_type = check_typedef (TYPE_TARGET_TYPE (val_type)); type_code = TYPE_CODE (val_type); @@ -768,6 +779,9 @@ valpy_getitem (PyObject *self, PyObject *key) else if (TYPE_CODE (val_type) == TYPE_CODE_REF) res_val = value_cast (lookup_lvalue_reference_type (base_class_type), tmp); + else if (TYPE_CODE (val_type) == TYPE_CODE_RVALUE_REF) + res_val = value_cast (lookup_rvalue_reference_type (base_class_type), + tmp); else res_val = value_cast (base_class_type, tmp); } @@ -1776,8 +1790,10 @@ reinterpret_cast operator." { "dereference", valpy_dereference, METH_NOARGS, "Dereferences the value." }, { "referenced_value", valpy_referenced_value, METH_NOARGS, "Return the value referenced by a TYPE_CODE_REF or TYPE_CODE_PTR value." }, - { "reference_value", valpy_reference_value, METH_NOARGS, + { "reference_value", valpy_lvalue_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, diff --git a/gdb/python/py-xmethods.c b/gdb/python/py-xmethods.c index d70cdd1..debc3a8 100644 --- a/gdb/python/py-xmethods.c +++ b/gdb/python/py-xmethods.c @@ -548,9 +548,10 @@ gdbpy_get_xmethod_result_type (const struct extension_language_defn *extlang, if (!types_equal (obj_type, this_ptr)) obj = value_cast (this_ptr, obj); } - else if (TYPE_CODE (obj_type) == TYPE_CODE_REF) + else if (TYPE_IS_REFERENCE (obj_type)) { - struct type *this_ref = lookup_lvalue_reference_type (this_type); + struct type *this_ref + = lookup_reference_type (this_type, TYPE_CODE (obj_type)); if (!types_equal (obj_type, this_ref)) obj = value_cast (this_ref, obj); @@ -634,9 +635,10 @@ gdbpy_invoke_xmethod (const struct extension_language_defn *extlang, if (!types_equal (obj_type, this_ptr)) obj = value_cast (this_ptr, obj); } - else if (TYPE_CODE (obj_type) == TYPE_CODE_REF) + else if (TYPE_IS_REFERENCE (obj_type)) { - struct type *this_ref = lookup_lvalue_reference_type (this_type); + struct type *this_ref + = lookup_reference_type (this_type, TYPE_CODE (obj_type)); if (!types_equal (obj_type, this_ref)) obj = value_cast (this_ref, obj); -- 2.8.3