gdb/
2009-02-05 Thiago Jung Bauermann <bauerman@br.ibm.com> Tom Tromey <tromey@redhat.com> * python/python-utils.c (target_string_to_unicode): New function. * python/python-internal.h (target_string_to_unicode): New prototype. * python/python-value.c (valpy_string): New function. (value_object_methods): Add `string' entry. gdb/doc/ 2009-02-05 Tom Tromey <tromey@redhat.com> * gdb.texinfo (Values From Inferior): Document Value.string.
This commit is contained in:
parent
54ba13f733
commit
b6cb8e7dea
6 changed files with 86 additions and 0 deletions
|
@ -91,6 +91,7 @@ PyObject *python_string_to_unicode (PyObject *obj);
|
|||
char *unicode_to_target_string (PyObject *unicode_str);
|
||||
char *python_string_to_target_string (PyObject *obj);
|
||||
char *python_string_to_host_string (PyObject *obj);
|
||||
PyObject *target_string_to_unicode (const gdb_byte *str, int length);
|
||||
int gdbpy_is_string (PyObject *obj);
|
||||
|
||||
#endif /* GDB_PYTHON_INTERNAL_H */
|
||||
|
|
|
@ -160,6 +160,19 @@ python_string_to_host_string (PyObject *obj)
|
|||
return unicode_to_encoded_string (str, host_charset ());
|
||||
}
|
||||
|
||||
/* Converts a target string of LENGTH bytes in the target's charset to a
|
||||
Python Unicode string. If LENGTH is -1, convert until a null byte is found.
|
||||
|
||||
Returns NULL on error, with a python exception set. */
|
||||
PyObject *
|
||||
target_string_to_unicode (const gdb_byte *str, int length)
|
||||
{
|
||||
if (length == -1)
|
||||
length = strlen (str);
|
||||
|
||||
return PyUnicode_Decode (str, length, target_charset (), NULL);
|
||||
}
|
||||
|
||||
/* Return true if OBJ is a Python string or unicode object, false
|
||||
otherwise. */
|
||||
|
||||
|
|
|
@ -143,6 +143,37 @@ valpy_address (PyObject *self, PyObject *args)
|
|||
return value_to_value_object (res_val);
|
||||
}
|
||||
|
||||
/* Return Unicode string with value contents (assumed to be encoded in the
|
||||
target's charset). */
|
||||
static PyObject *
|
||||
valpy_string (PyObject *self, PyObject *args)
|
||||
{
|
||||
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;
|
||||
|
||||
if (!PyArg_ParseTuple (args, "|ss", &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)
|
||||
{
|
||||
|
@ -794,6 +825,8 @@ gdbpy_initialize_values (void)
|
|||
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", valpy_string, METH_VARARGS,
|
||||
"Return Unicode string representation of the value." },
|
||||
{NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue