PR python/11948:
* varobj.c (value_get_print_value): Use val_print_string to print lazy strings. * python/py-prettyprint.c (print_string_repr): Use val_print_string to print lazy strings. Fix cleanup logic. (print_children): Likewise. * python/python-internal.h (gdbpy_extract_lazy_string): Update. * python/py-lazy-string.c (gdbpy_extract_lazy_string): Rewrite. Change return type to 'void', add 'addr' argument. * value.h (val_print_string): Update. * valprint.c (val_print_string): Add 'encoding' argument. * printcmd.c (print_formatted): Update. * p-valprint.c (pascal_val_print): Update. * m2-valprint.c (print_unpacked_pointer): Update. (m2_print_array_contents): Likewise. * jv-valprint.c (java_value_print): Update. * f-valprint.c (f_val_print): Update. * c-valprint.c (c_val_print): Update. * auxv.c (fprint_target_auxv): Update.
This commit is contained in:
parent
92163a10dc
commit
09ca9e2e34
14 changed files with 134 additions and 164 deletions
|
@ -24,6 +24,7 @@
|
|||
#include "exceptions.h"
|
||||
#include "valprint.h"
|
||||
#include "language.h"
|
||||
#include "gdb_assert.h"
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
|
@ -169,86 +170,26 @@ gdbpy_is_lazy_string (PyObject *result)
|
|||
return PyObject_TypeCheck (result, &lazy_string_object_type);
|
||||
}
|
||||
|
||||
/* Extract and return the actual string from the lazy string object
|
||||
STRING. Addtionally, the string type is written to *STR_TYPE, the
|
||||
string length is written to *LENGTH, and the string encoding is
|
||||
written to *ENCODING. On error, NULL is returned. The caller is
|
||||
responsible for freeing the returned buffer. */
|
||||
gdb_byte *
|
||||
gdbpy_extract_lazy_string (PyObject *string, struct type **str_type,
|
||||
long *length, char **encoding)
|
||||
/* Extract the parameters from the lazy string object STRING.
|
||||
ENCODING will either be set to NULL, or will be allocated with
|
||||
xmalloc, in which case the callers is responsible for freeing
|
||||
it. */
|
||||
|
||||
void
|
||||
gdbpy_extract_lazy_string (PyObject *string, CORE_ADDR *addr,
|
||||
struct type **str_type,
|
||||
long *length, char **encoding)
|
||||
{
|
||||
int width;
|
||||
int bytes_read;
|
||||
gdb_byte *buffer = NULL;
|
||||
int errcode = 0;
|
||||
CORE_ADDR addr;
|
||||
struct gdbarch *gdbarch;
|
||||
enum bfd_endian byte_order;
|
||||
PyObject *py_len = NULL, *py_encoding = NULL;
|
||||
PyObject *py_addr = NULL, *py_type = NULL;
|
||||
volatile struct gdb_exception except;
|
||||
lazy_string_object *lazy;
|
||||
|
||||
py_len = PyObject_GetAttrString (string, "length");
|
||||
py_encoding = PyObject_GetAttrString (string, "encoding");
|
||||
py_addr = PyObject_GetAttrString (string, "address");
|
||||
py_type = PyObject_GetAttrString (string, "type");
|
||||
gdb_assert (gdbpy_is_lazy_string (string));
|
||||
|
||||
/* A NULL encoding, length, address or type is not ok. */
|
||||
if (!py_len || !py_encoding || !py_addr || !py_type)
|
||||
goto error;
|
||||
lazy = (lazy_string_object *) string;
|
||||
|
||||
*length = PyLong_AsLong (py_len);
|
||||
addr = PyLong_AsUnsignedLongLong (py_addr);
|
||||
|
||||
/* If the user supplies Py_None an encoding, set encoding to NULL.
|
||||
This will trigger the resulting LA_PRINT_CALL to automatically
|
||||
select an encoding. */
|
||||
if (py_encoding == Py_None)
|
||||
*encoding = NULL;
|
||||
else
|
||||
*encoding = xstrdup (PyString_AsString (py_encoding));
|
||||
|
||||
*str_type = type_object_to_type (py_type);
|
||||
gdbarch = get_type_arch (*str_type);
|
||||
byte_order = gdbarch_byte_order (gdbarch);
|
||||
width = TYPE_LENGTH (*str_type);
|
||||
|
||||
TRY_CATCH (except, RETURN_MASK_ALL)
|
||||
{
|
||||
errcode = read_string (addr, *length, width,
|
||||
*length, byte_order, &buffer,
|
||||
&bytes_read);
|
||||
}
|
||||
if (except.reason < 0)
|
||||
{
|
||||
PyErr_Format (except.reason == RETURN_QUIT \
|
||||
? PyExc_KeyboardInterrupt : PyExc_RuntimeError, \
|
||||
"%s", except.message); \
|
||||
goto error;
|
||||
|
||||
}
|
||||
|
||||
if (errcode)
|
||||
goto error;
|
||||
|
||||
*length = bytes_read / width;
|
||||
|
||||
Py_DECREF (py_encoding);
|
||||
Py_DECREF (py_len);
|
||||
Py_DECREF (py_addr);
|
||||
Py_DECREF (py_type);
|
||||
return buffer;
|
||||
|
||||
error:
|
||||
Py_XDECREF (py_encoding);
|
||||
Py_XDECREF (py_len);
|
||||
Py_XDECREF (py_addr);
|
||||
Py_XDECREF (py_type);
|
||||
xfree (buffer);
|
||||
*length = 0;
|
||||
*str_type = NULL;
|
||||
return NULL;
|
||||
*addr = lazy->address;
|
||||
*str_type = lazy->type;
|
||||
*length = lazy->length;
|
||||
*encoding = lazy->encoding ? xstrdup (lazy->encoding) : NULL;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -275,53 +275,51 @@ print_string_repr (PyObject *printer, const char *hint,
|
|||
py_str = pretty_print_one_value (printer, &replacement);
|
||||
if (py_str)
|
||||
{
|
||||
struct cleanup *cleanup = make_cleanup_py_decref (py_str);
|
||||
|
||||
if (py_str == Py_None)
|
||||
is_py_none = 1;
|
||||
else
|
||||
else if (gdbpy_is_lazy_string (py_str))
|
||||
{
|
||||
gdb_byte *output = NULL;
|
||||
CORE_ADDR addr;
|
||||
long length;
|
||||
struct type *type;
|
||||
char *encoding = NULL;
|
||||
PyObject *string = NULL;
|
||||
int is_lazy;
|
||||
|
||||
is_lazy = gdbpy_is_lazy_string (py_str);
|
||||
if (is_lazy)
|
||||
output = gdbpy_extract_lazy_string (py_str, &type, &length, &encoding);
|
||||
else
|
||||
make_cleanup (free_current_contents, &encoding);
|
||||
gdbpy_extract_lazy_string (py_str, &addr, &type,
|
||||
&length, &encoding);
|
||||
|
||||
val_print_string (type, encoding, addr, (int) length,
|
||||
stream, options);
|
||||
}
|
||||
else
|
||||
{
|
||||
PyObject *string;
|
||||
|
||||
string = python_string_to_target_python_string (py_str);
|
||||
if (string)
|
||||
{
|
||||
string = python_string_to_target_python_string (py_str);
|
||||
if (string)
|
||||
{
|
||||
output = PyString_AsString (string);
|
||||
length = PyString_Size (string);
|
||||
type = builtin_type (gdbarch)->builtin_char;
|
||||
}
|
||||
else
|
||||
gdbpy_print_stack ();
|
||||
|
||||
}
|
||||
|
||||
if (output)
|
||||
{
|
||||
if (is_lazy || (hint && !strcmp (hint, "string")))
|
||||
LA_PRINT_STRING (stream, type, output, length, encoding,
|
||||
gdb_byte *output;
|
||||
long length;
|
||||
struct type *type;
|
||||
|
||||
make_cleanup_py_decref (string);
|
||||
output = PyString_AsString (string);
|
||||
length = PyString_Size (string);
|
||||
type = builtin_type (gdbarch)->builtin_char;
|
||||
|
||||
if (hint && !strcmp (hint, "string"))
|
||||
LA_PRINT_STRING (stream, type, output, length, NULL,
|
||||
0, options);
|
||||
else
|
||||
fputs_filtered (output, stream);
|
||||
}
|
||||
else
|
||||
gdbpy_print_stack ();
|
||||
|
||||
if (string)
|
||||
Py_DECREF (string);
|
||||
else
|
||||
xfree (output);
|
||||
|
||||
xfree (encoding);
|
||||
Py_DECREF (py_str);
|
||||
}
|
||||
|
||||
do_cleanups (cleanup);
|
||||
}
|
||||
else if (replacement)
|
||||
{
|
||||
|
@ -548,32 +546,31 @@ print_children (PyObject *printer, const char *hint,
|
|||
fputs_filtered (" = ", stream);
|
||||
}
|
||||
|
||||
if (gdbpy_is_lazy_string (py_v) || gdbpy_is_string (py_v))
|
||||
if (gdbpy_is_lazy_string (py_v))
|
||||
{
|
||||
gdb_byte *output = NULL;
|
||||
CORE_ADDR addr;
|
||||
struct type *type;
|
||||
long length;
|
||||
char *encoding = NULL;
|
||||
|
||||
if (gdbpy_is_lazy_string (py_v))
|
||||
{
|
||||
struct type *type;
|
||||
long length;
|
||||
char *encoding = NULL;
|
||||
make_cleanup (free_current_contents, &encoding);
|
||||
gdbpy_extract_lazy_string (py_v, &addr, &type, &length, &encoding);
|
||||
|
||||
output = gdbpy_extract_lazy_string (py_v, &type,
|
||||
&length, &encoding);
|
||||
if (!output)
|
||||
gdbpy_print_stack ();
|
||||
LA_PRINT_STRING (stream, type, output, length, encoding,
|
||||
0, options);
|
||||
xfree (encoding);
|
||||
xfree (output);
|
||||
}
|
||||
val_print_string (type, encoding, addr, (int) length, stream,
|
||||
options);
|
||||
|
||||
do_cleanups (inner_cleanup);
|
||||
}
|
||||
else if (gdbpy_is_string (py_v))
|
||||
{
|
||||
gdb_byte *output;
|
||||
|
||||
output = python_string_to_host_string (py_v);
|
||||
if (!output)
|
||||
gdbpy_print_stack ();
|
||||
else
|
||||
{
|
||||
output = python_string_to_host_string (py_v);
|
||||
if (!output)
|
||||
gdbpy_print_stack ();
|
||||
else
|
||||
fputs_filtered (output, stream);
|
||||
fputs_filtered (output, stream);
|
||||
xfree (output);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -209,9 +209,9 @@ char *gdbpy_obj_to_string (PyObject *obj);
|
|||
char *gdbpy_exception_to_string (PyObject *ptype, PyObject *pvalue);
|
||||
|
||||
int gdbpy_is_lazy_string (PyObject *result);
|
||||
gdb_byte *gdbpy_extract_lazy_string (PyObject *string,
|
||||
struct type **str_type,
|
||||
long *length, char **encoding);
|
||||
void gdbpy_extract_lazy_string (PyObject *string, CORE_ADDR *addr,
|
||||
struct type **str_type,
|
||||
long *length, char **encoding);
|
||||
|
||||
int gdbpy_is_value_object (PyObject *obj);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue