This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH v2 10/11] [PR gdb/14441] gdb: python: support rvalue references in the gdb module


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.
        * 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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]