diff mbox

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

Message ID 1450661481-31178-11-git-send-email-artemiyv@acm.org
State New
Headers show

Commit Message

Artemiy Volkov Dec. 21, 2015, 1:31 a.m. UTC
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  <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 mbox

Patch

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,