+ return result;
+}
+
+/* Given a value of a pointer type or a reference type, return the value
+ referenced. The difference between this function and valpy_dereference is
+ that the latter applies * unary operator to a value, which need not always
+ result in the value referenced. For example, for a value which is a reference
+ to an 'int' pointer ('int *'), valpy_dereference will result in a value of
+ type 'int' while valpy_referenced_value will result in a value of type
+ 'int *'. */
+
+static PyObject *
+valpy_referenced_value (PyObject *self, PyObject *args)
+{
+ PyObject *result = NULL;
+
+ TRY
+ {
+ struct value *self_val, *res_val;
+ scoped_value_mark free_values;
+
+ self_val = ((value_object *) self)->value;
+ switch (TYPE_CODE (check_typedef (value_type (self_val))))
+ {
+ case TYPE_CODE_PTR:
+ res_val = value_ind (self_val);
+ break;
+ case TYPE_CODE_REF:
+ case TYPE_CODE_RVALUE_REF:
+ res_val = coerce_ref (self_val);
+ break;
+ default:
+ error(_("Trying to get the referenced value from a value which is "
+ "neither a pointer nor a reference."));
+ }
+
+ result = value_to_value_object (res_val);
+ }
+ CATCH (except, RETURN_MASK_ALL)
+ {
+ GDB_PY_HANDLE_EXCEPTION (except);
+ }
+ END_CATCH
+
+ return result;
+}
+
+/* Return a value which is a reference to the value. */
+
+static PyObject *
+valpy_reference_value (PyObject *self, PyObject *args, enum type_code refcode)
+{
+ PyObject *result = NULL;
+
+ TRY
+ {
+ struct value *self_val;
+ scoped_value_mark free_values;
+
+ self_val = ((value_object *) self)->value;
+ result = value_to_value_object (value_ref (self_val, refcode));
+ }
+ CATCH (except, RETURN_MASK_ALL)
+ {
+ GDB_PY_HANDLE_EXCEPTION (except);
+ }
+ END_CATCH
+
+ return result;
+}
+
+static PyObject *
+valpy_lvalue_reference_value (PyObject *self, PyObject *args)
+{
+ return valpy_reference_value (self, args, TYPE_CODE_REF);
+}
+
+static PyObject *
+valpy_rvalue_reference_value (PyObject *self, PyObject *args)
+{
+ return valpy_reference_value (self, args, TYPE_CODE_RVALUE_REF);
+}
+
+/* Return a "const" qualified version of the value. */
+
+static PyObject *
+valpy_const_value (PyObject *self, PyObject *args)
+{
+ PyObject *result = NULL;
+
+ TRY
+ {
+ struct value *self_val, *res_val;
+ scoped_value_mark free_values;
+
+ self_val = ((value_object *) self)->value;
+ res_val = make_cv_value (1, 0, self_val);
+ result = value_to_value_object (res_val);
+ }
+ CATCH (except, RETURN_MASK_ALL)
+ {
+ GDB_PY_HANDLE_EXCEPTION (except);
+ }
+ END_CATCH
+
+ return result;