This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [PATCH v2 10/11] [PR gdb/14441] gdb: python: support rvalue references in the gdb module
- From: Keith Seitz <keiths at redhat dot com>
- To: Artemiy Volkov <artemiyv at acm dot org>, gdb-patches at sourceware dot org
- Date: Fri, 19 Feb 2016 11:47:57 -0800
- Subject: Re: [PATCH v2 10/11] [PR gdb/14441] gdb: python: support rvalue references in the gdb module
- Authentication-results: sourceware.org; auth=none
- References: <1450661481-31178-1-git-send-email-artemiyv at acm dot org> <1453229609-20159-1-git-send-email-artemiyv at acm dot org> <1453229609-20159-11-git-send-email-artemiyv at acm dot org>
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 <artemiyv@acm.org>
>
> * 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