+/* Return "&value". */
+static PyObject *
+valpy_get_address (PyObject *self, void *closure)
+{
+ struct value *res_val = NULL; /* Initialize to appease gcc warning. */
+ value_object *val_obj = (value_object *) self;
+ volatile struct gdb_exception except;
+
+ if (!val_obj->address)
+ {
+ TRY_CATCH (except, RETURN_MASK_ALL)
+ {
+ res_val = value_addr (val_obj->value);
+ }
+ if (except.reason < 0)
+ {
+ val_obj->address = Py_None;
+ Py_INCREF (Py_None);
+ }
+ else
+ val_obj->address = value_to_value_object (res_val);
+ }
+
+ Py_INCREF (val_obj->address);
+
+ return val_obj->address;
+}
+
+/* Return type of the value. */
+static PyObject *
+valpy_get_type (PyObject *self, void *closure)
+{
+ value_object *obj = (value_object *) self;
+ if (!obj->type)
+ {
+ obj->type = type_to_type_object (value_type (obj->value));
+ if (!obj->type)
+ {
+ obj->type = Py_None;
+ Py_INCREF (obj->type);
+ }
+ }
+ Py_INCREF (obj->type);
+ return obj->type;
+}
+
+/* Implementation of gdb.Value.string ([encoding] [, errors]) -> string
+ Return Unicode string with value contents. If ENCODING is not given,
+ the string is assumed to be encoded in the target's charset. */
+static PyObject *
+valpy_string (PyObject *self, PyObject *args, PyObject *kw)
+{
+ int length, ret = 0;
+ gdb_byte *buffer;
+ struct value *value = ((value_object *) self)->value;
+ volatile struct gdb_exception except;
+ PyObject *unicode;
+ const char *encoding = NULL;
+ const char *errors = NULL;
+ const char *user_encoding = NULL;
+ const char *la_encoding = NULL;
+ static char *keywords[] = { "encoding", "errors" };
+
+ if (!PyArg_ParseTupleAndKeywords (args, kw, "|ss", keywords,
+ &user_encoding, &errors))
+ return NULL;
+
+ TRY_CATCH (except, RETURN_MASK_ALL)
+ {
+ LA_GET_STRING (value, &buffer, &length, &la_encoding);
+ }
+ GDB_PY_HANDLE_EXCEPTION (except);
+
+ encoding = (user_encoding && *user_encoding) ? user_encoding : la_encoding;
+ unicode = PyUnicode_Decode (buffer, length, encoding, errors);
+ xfree (buffer);
+
+ return unicode;
+}
+
+/* Cast a value to a given type. */
+static PyObject *
+valpy_cast (PyObject *self, PyObject *args)
+{
+ PyObject *type_obj;
+ struct type *type;
+ struct value *res_val = NULL; /* Initialize to appease gcc warning. */
+ volatile struct gdb_exception except;
+
+ if (! PyArg_ParseTuple (args, "O", &type_obj))
+ return NULL;
+
+ type = type_object_to_type (type_obj);
+ if (! type)
+ {
+ PyErr_SetString (PyExc_RuntimeError, "argument must be a Type");
+ return NULL;
+ }
+
+ TRY_CATCH (except, RETURN_MASK_ALL)
+ {
+ res_val = value_cast (type, ((value_object *) self)->value);
+ }
+ GDB_PY_HANDLE_EXCEPTION (except);
+
+ return value_to_value_object (res_val);
+}
+