From patchwork Mon Dec 21 01:31:20 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Artemiy Volkov X-Patchwork-Id: 10084 Received: (qmail 97703 invoked by alias); 20 Dec 2015 22:35:47 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 97149 invoked by uid 89); 20 Dec 2015 22:35:41 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.6 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 spammy=1327, 318, sk:referen X-HELO: mail-lb0-f193.google.com Received: from mail-lb0-f193.google.com (HELO mail-lb0-f193.google.com) (209.85.217.193) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Sun, 20 Dec 2015 22:35:28 +0000 Received: by mail-lb0-f193.google.com with SMTP id l5so8805929lbs.1 for ; Sun, 20 Dec 2015 14:35:27 -0800 (PST) X-Received: by 10.112.182.100 with SMTP id ed4mr5156650lbc.143.1450650924736; Sun, 20 Dec 2015 14:35:24 -0800 (PST) Received: from localhost.localdomain ([37.204.1.155]) by smtp.gmail.com with ESMTPSA id m75sm4420435lfg.15.2015.12.20.14.35.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 20 Dec 2015 14:35:23 -0800 (PST) From: Artemiy Volkov To: gdb-patches@sourceware.org Cc: Artemiy Volkov Subject: [PATCH 10/11] [PR gdb/14441] gdb: python: support rvalue references in the gdb module Date: Mon, 21 Dec 2015 04:31:20 +0300 Message-Id: <1450661481-31178-11-git-send-email-artemiyv@acm.org> In-Reply-To: <1450661481-31178-1-git-send-email-artemiyv@acm.org> References: <1450661481-31178-1-git-send-email-artemiyv@acm.org> X-IsSubscribed: yes 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: 2015-12-20 Artemiy Volkov * gdb/python/lib/gdb/command/explore.py: Add RvalueReferenceExplorer class. * gdb/python/lib/gdb/types.py: Implement get_basic_type() for rvalue reference types. * gdb/python/py-type.c: Add TYPE_CODE_RVALUE_REF to pyty_codes. * 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 88f3e9a..2f6f692 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 : RvalueReferenceExplorer, gdb.TYPE_CODE_TYPEDEF : TypedefExplorer, gdb.TYPE_CODE_ARRAY : ArrayExplorer } @@ -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 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 5c9f5a9..f7055a7 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 2c071cc..a251d57 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 e97a040..0e049f9 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,