forked from Imagelibrary/binutils-gdb
PR python/18089
gdb/ChangeLog: PR python/18089 * python/py-prettyprint.c (print_children): Verify result of children iterator. Provide better error message. * python/python-internal..h (gdbpy_print_python_errors_p): Declare. * python/python.c (gdbpy_print_python_errors_p): New function. gdb/testsuite/ChangeLog: * gdb.python/py-bad-printers.c: New file. * gdb.python/py-bad-printers.py: New file. * gdb.python/py-bad-printers.exp: New file.
This commit is contained in:
@@ -554,8 +554,22 @@ print_children (PyObject *printer, const char *hint,
|
||||
break;
|
||||
}
|
||||
|
||||
if (! PyTuple_Check (item) || PyTuple_Size (item) != 2)
|
||||
{
|
||||
PyErr_SetString (PyExc_TypeError,
|
||||
_("Result of children iterator not a tuple"
|
||||
" of two elements."));
|
||||
gdbpy_print_stack ();
|
||||
Py_DECREF (item);
|
||||
continue;
|
||||
}
|
||||
if (! PyArg_ParseTuple (item, "sO", &name, &py_v))
|
||||
{
|
||||
/* The user won't necessarily get a stack trace here, so provide
|
||||
more context. */
|
||||
if (gdbpy_print_python_errors_p ())
|
||||
fprintf_unfiltered (gdb_stderr,
|
||||
_("Bad result from children iterator.\n"));
|
||||
gdbpy_print_stack ();
|
||||
Py_DECREF (item);
|
||||
continue;
|
||||
|
||||
@@ -527,6 +527,7 @@ extern const struct language_defn *python_language;
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
int gdbpy_print_python_errors_p (void);
|
||||
void gdbpy_print_stack (void);
|
||||
|
||||
PyObject *python_string_to_unicode (PyObject *obj);
|
||||
|
||||
@@ -1182,6 +1182,14 @@ gdbpy_flush (PyObject *self, PyObject *args, PyObject *kw)
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
/* Return non-zero if print-stack is not "none". */
|
||||
|
||||
int
|
||||
gdbpy_print_python_errors_p (void)
|
||||
{
|
||||
return gdbpy_should_print_stack != python_excp_none;
|
||||
}
|
||||
|
||||
/* Print a python exception trace, print just a message, or print
|
||||
nothing and clear the python exception, depending on
|
||||
gdbpy_should_print_stack. Only call this if a python exception is
|
||||
|
||||
Reference in New Issue
Block a user