This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[RFC][PATCH] Fix for Bugzilla #14062 (Exceptions in callbacks posted by gdb.post_event are silently ignored)


Hi,

This is a proposal for fixing this issue: 
https://sourceware.org/bugzilla/show_bug.cgi?id=14062

When we issue a gdb.post_event with a given callable object, any exceptions that
occur when invoking the callable are ignored.

This patch should be enough to let to the user know that an exception occured,
however the output looks like:

(gdb) python gdb.post_event(lambda: invalid())
(gdb) Python Exception <type 'exceptions.NameError'> global name 'invalid' is not defined:

As we can see, the gdb prompt appears before the Python error message, which may
be confusing. This happens because gdb.post_event results in a successful call
to gdbpy_post_event (which places the event in gdb's internal queue) and thus
the gdb prompt is shown. Immediately after, gdb invokes the callable through
gdbpy_run_events, and only then the exception arises and the error message is
shown.

I'm attaching the patch that makes gdb stop ignoring Python errors. However, I'm
not sure how to fix the output. I'm willing to go on and fix it myself if it's
not too hard, though this should probably be handled by someone who knows the
internals better than me.

Since this is just an RFC, I'm not including a ChangeLog nor unit tests for now.
Thanks!

---
 gdb/python/python.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/gdb/python/python.c b/gdb/python/python.c
index 9c972ec..8841b39 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -953,7 +953,10 @@ gdbpy_run_events (int error, gdb_client_data client_data)
       /* Ignore errors.  */
       call_result = PyObject_CallObject (item->event, NULL);
       if (call_result == NULL)
-	PyErr_Clear ();
+	{
+	  gdbpy_print_stack ();
+	  PyErr_Clear ();
+	}
 
       Py_XDECREF (call_result);
       Py_DECREF (item->event);
-- 
1.9.1


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]