From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 7831 invoked by alias); 19 Jan 2016 18:54:23 -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 7731 invoked by uid 89); 19 Jan 2016 18:54:23 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.6 required=5.0 tests=BAYES_00,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=ham version=3.3.2 spammy=1327, 132,7, TRY, end_catch X-HELO: mail-lf0-f67.google.com Received: from mail-lf0-f67.google.com (HELO mail-lf0-f67.google.com) (209.85.215.67) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Tue, 19 Jan 2016 18:54:18 +0000 Received: by mail-lf0-f67.google.com with SMTP id n70so30063705lfn.1 for ; Tue, 19 Jan 2016 10:54:17 -0800 (PST) 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=U8yJRHyn4WQ3AiH9lqO1O+3S99kwbE6BWvg3VsACVqc=; b=m3cCzdLwkSBSrOlRaIumuKBAxpNURutXyQGf4bw2AFNB7bmWP5kFMH3ynXfOSXF3yq P3Ej3y/WCamDMGXpenTxA/gVB3g2f9ReDspNgXqq4YjObjN/zEPSH33tTBNZy4NghPGM B7JOe2gPKR5iVqrK7gdF7jdWyuBjpVlnJoKnbo43tq18zkX7JTmMFy33GlJCoUx9Mczq e/IP0alCf94ZriL6xgYUeYSP0+TUbum61ZEhc56eg3kYeudT0dNH4XBfVebS607YHd/v p7CSGHd6LDMBCZwxwielf2E6Zc59PUKZLkzbOBuMESkG+uQKXw57KM+PHRTAcK81nlOE HYhg== X-Gm-Message-State: ALoCoQmz0HEa+MTYy4XRW2Zn7rVe3QmwAQO+7CIwEfQekKWMfgvNLEeeGdW5uQ0TbeYkahNk+8YFH3mLDWwthvs94iO278nlwA== X-Received: by 10.25.152.148 with SMTP id a142mr11292926lfe.139.1453229654811; Tue, 19 Jan 2016 10:54:14 -0800 (PST) Received: from arch.smware.local ([37.204.1.155]) by smtp.gmail.com with ESMTPSA id p66sm4247278lfe.42.2016.01.19.10.54.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 19 Jan 2016 10:54:13 -0800 (PST) From: Artemiy Volkov To: gdb-patches@sourceware.org Cc: palves@redhat.com, Artemiy Volkov Subject: [PATCH v2 10/11] [PR gdb/14441] gdb: python: support rvalue references in the gdb module Date: Tue, 19 Jan 2016 18:55:00 -0000 Message-Id: <1453229609-20159-11-git-send-email-artemiyv@acm.org> In-Reply-To: <1453229609-20159-1-git-send-email-artemiyv@acm.org> References: <1450661481-31178-1-git-send-email-artemiyv@acm.org> <1453229609-20159-1-git-send-email-artemiyv@acm.org> X-IsSubscribed: yes X-SW-Source: 2016-01/txt/msg00459.txt.bz2 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. * 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 6c9f17b..a980274 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 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 dcdc20f..313f003 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 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, -- 2.7.0