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

Message ID 1461081936-13813-1-git-send-email-leonardo.boquillon@tallertechnologies.com
State New, archived
Headers

Commit Message

Leonardo Boquillon April 19, 2016, 4:05 p.m. UTC
  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(-)
  

Comments

Tom Tromey April 19, 2016, 5:17 p.m. UTC | #1
>>>>> "Leonardo" == Leonardo Boquillon <leonardo.boquillon@tallertechnologies.com> writes:

Leonardo> -	PyErr_Clear ();
Leonardo> +	{
Leonardo> +	  gdbpy_print_stack ();
Leonardo> +	  PyErr_Clear ();
Leonardo> +	}

gdbpy_print_stack implicitly clears the error, so the call to
PyErr_Clear can just be removed here.

Tom
  
Leonardo Boquillon April 19, 2016, 6:09 p.m. UTC | #2
Hi Tom,

Ok but the output issue, mentioned above, stands.

Thanks

On Tue, Apr 19, 2016 at 2:17 PM, Tom Tromey <tom@tromey.com> wrote:
>>>>>> "Leonardo" == Leonardo Boquillon <leonardo.boquillon@tallertechnologies.com> writes:
>
> Leonardo> -     PyErr_Clear ();
> Leonardo> +     {
> Leonardo> +       gdbpy_print_stack ();
> Leonardo> +       PyErr_Clear ();
> Leonardo> +     }
>
> gdbpy_print_stack implicitly clears the error, so the call to
> PyErr_Clear can just be removed here.
>
> Tom
  

Patch

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);