This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[4/5] RFC: fix bug in gdbpy_flush
- From: Tom Tromey <tromey at redhat dot com>
- To: gdb-patches at sourceware dot org
- Date: Thu, 07 Feb 2013 14:04:30 -0700
- Subject: [4/5] RFC: fix bug in gdbpy_flush
The exception checker pointed out that fprintf_filtered can throw an
exception -- which makes sense, it might cause pagination.
This patch fixes the problem by ignoring such exceptions.
This seems a bit weird, but it isn't clear what else would make sense.
We're usually calling gdbpy_print_stack specifically to deal with a
Python exception that can't otherwise be meaningfully handled...
Tom
* python/python.c (gdbpy_print_stack): Call begin_line and
fprintf_filtered inside TRY_CATCH.
---
gdb/python/python.c | 29 +++++++++++++++++++----------
1 files changed, 19 insertions(+), 10 deletions(-)
diff --git a/gdb/python/python.c b/gdb/python/python.c
index e2c19b3..405eb5b 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -1043,6 +1043,8 @@ gdbpy_flush (PyObject *self, PyObject *args, PyObject *kw)
void
gdbpy_print_stack (void)
{
+ volatile struct gdb_exception except;
+
/* Print "none", just clear exception. */
if (gdbpy_should_print_stack == python_excp_none)
{
@@ -1055,7 +1057,10 @@ gdbpy_print_stack (void)
/* PyErr_Print doesn't necessarily end output with a newline.
This works because Python's stdout/stderr is fed through
printf_filtered. */
- begin_line ();
+ TRY_CATCH (except, RETURN_MASK_ALL)
+ {
+ begin_line ();
+ }
}
/* Print "message", just error print message. */
else
@@ -1068,17 +1073,21 @@ gdbpy_print_stack (void)
/* Fetch the error message contained within ptype, pvalue. */
msg = gdbpy_exception_to_string (ptype, pvalue);
type = gdbpy_obj_to_string (ptype);
- if (msg == NULL)
+
+ TRY_CATCH (except, RETURN_MASK_ALL)
{
- /* An error occurred computing the string representation of the
- error message. */
- fprintf_filtered (gdb_stderr,
- _("Error occurred computing Python error" \
- "message.\n"));
+ if (msg == NULL)
+ {
+ /* An error occurred computing the string representation of the
+ error message. */
+ fprintf_filtered (gdb_stderr,
+ _("Error occurred computing Python error" \
+ "message.\n"));
+ }
+ else
+ fprintf_filtered (gdb_stderr, "Python Exception %s %s: \n",
+ type, msg);
}
- else
- fprintf_filtered (gdb_stderr, "Python Exception %s %s: \n",
- type, msg);
Py_XDECREF (ptype);
Py_XDECREF (pvalue);
--
1.7.7.6