[v3,08/11,PR,gdb/14441] gdb: python: support rvalue references in the gdb module
Commit Message
This patch adds the ability to inspect rvalue reference types and values using
the gdb python module. This is achieved by simply 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-03-04 Artemiy Volkov <artemiyv@acm.org>
* 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) <TYPE_CODE_RVALUE_REF>: New
constant.
* python/py-value.c (valpy_getitem): Add an rvalue reference
check.
* 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 | 3 +++
gdb/python/py-xmethods.c | 14 ++++++++------
5 files changed, 16 insertions(+), 8 deletions(-)
Comments
On 03/04/2016 07:19 PM, Artemiy Volkov wrote:
> This patch adds the ability to inspect rvalue reference types and values using
> the gdb python module. This is achieved by simply 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-03-04 Artemiy Volkov <artemiyv@acm.org>
>
> * 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) <TYPE_CODE_RVALUE_REF>: New
> constant.
> * python/py-value.c (valpy_getitem): Add an rvalue reference
> check.
> * 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 | 3 +++
> gdb/python/py-xmethods.c | 14 ++++++++------
> 5 files changed, 16 insertions(+), 8 deletions(-)
>
> diff --git a/gdb/python/py-xmethods.c b/gdb/python/py-xmethods.c
> index d70cdd1..859e346 100644
> --- a/gdb/python/py-xmethods.c
> +++ b/gdb/python/py-xmethods.c
> @@ -548,10 +548,11 @@ 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 = TYPE_CODE (obj_type) == TYPE_CODE_REF
> + ? lookup_lvalue_reference_type (this_type)
> + : lookup_rvalue_reference_type (this_type);
> if (!types_equal (obj_type, this_ref))
> obj = value_cast (this_ref, obj);
> }
I see this same paradigm repeated in a handful of places... In other
places, I've seen
struct type *this_ref
= lookup_reference_type (this_type, TYPE_CODE (obj_type);
Those are equivalent, right? If so, let's use the above. It's a lot
easier/quicker to read than the ternary conditional.
> @@ -634,10 +635,11 @@ 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 = TYPE_CODE (obj_type) == TYPE_CODE_REF
> + ? lookup_lvalue_reference_type (this_type)
> + : lookup_rvalue_reference_type (this_type);
> if (!types_equal (obj_type, this_ref))
> obj = value_cast (this_ref, obj);
> }
>
Likewise?
Keith
@@ -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."""
@@ -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()
@@ -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),
@@ -768,6 +768,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);
}
@@ -548,10 +548,11 @@ 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 = TYPE_CODE (obj_type) == TYPE_CODE_REF
+ ? lookup_lvalue_reference_type (this_type)
+ : lookup_rvalue_reference_type (this_type);
if (!types_equal (obj_type, this_ref))
obj = value_cast (this_ref, obj);
}
@@ -634,10 +635,11 @@ 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 = TYPE_CODE (obj_type) == TYPE_CODE_REF
+ ? lookup_lvalue_reference_type (this_type)
+ : lookup_rvalue_reference_type (this_type);
if (!types_equal (obj_type, this_ref))
obj = value_cast (this_ref, obj);
}