return value_to_value_object (res_val);
}
+/* 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;
+}
+
static Py_ssize_t
valpy_length (PyObject *self)
{
return result;
}
+/* Implements gdb.Value.is_optimized_out. */
+static PyObject *
+valpy_get_is_optimized_out (PyObject *self, void *closure)
+{
+ struct value *value = ((value_object *) self)->value;
+
+ if (value_optimized_out (value))
+ Py_RETURN_TRUE;
+
+ Py_RETURN_FALSE;
+}
+
enum valpy_opcode
{
VALPY_ADD,
a gdb.Value object and need to convert it from python as well. */
arg1 = convert_value_from_python (self);
if (arg1 == NULL)
- return NULL;
+ break;
arg2 = convert_value_from_python (other);
if (arg2 == NULL)
- return NULL;
+ break;
switch (opcode)
{
}
GDB_PY_HANDLE_EXCEPTION (except);
- return value_to_value_object (res_val);
+ return res_val ? value_to_value_object (res_val) : NULL;
}
static PyObject *
}
}
else if (PyObject_TypeCheck (obj, &value_object_type))
- value = ((value_object *) obj)->value;
+ value = value_copy (((value_object *) obj)->value);
else
PyErr_Format (PyExc_TypeError, _("Could not convert Python object: %s"),
PyString_AsString (PyObject_Str (obj)));
values_in_python = NULL;
}
+static PyGetSetDef value_object_getset[] = {
+ { "is_optimized_out", valpy_get_is_optimized_out, NULL,
+ "Boolean telling whether the value is optimized out (i.e., not available).",
+ NULL },
+ {NULL} /* Sentinel */
+};
+
static PyMethodDef value_object_methods[] = {
{ "address", valpy_address, METH_NOARGS, "Return the address of the value." },
{ "dereference", valpy_dereference, METH_NOARGS, "Dereferences the value." },
+ { "string", (PyCFunction) valpy_string, METH_VARARGS | METH_KEYWORDS,
+ "string ([encoding] [, errors]) -> string\n\
+Return Unicode string representation of the value." },
{NULL} /* Sentinel */
};
0, /* tp_iternext */
value_object_methods, /* tp_methods */
0, /* tp_members */
- 0, /* tp_getset */
+ value_object_getset, /* tp_getset */
0, /* tp_base */
0, /* tp_dict */
0, /* tp_descr_get */