Report Python errors coming from gdb.post_event
authorTom Tromey <tom@tromey.com>
Sat, 15 Sep 2018 06:07:32 +0000 (00:07 -0600)
committerTom Tromey <tom@tromey.com>
Mon, 24 Sep 2018 05:15:12 +0000 (23:15 -0600)
PR python/14062 points out that errors coming from the gdb.post_event
callback are not reported.  This can make it hard to understand why
your Python code in gdb isn't working.

Because users have control over whether exceptions are printed at all,
it seems good to simply have post_event report errors in the usual
way.

2018-09-23  Tom Tromey  <tom@tromey.com>

PR python/14062:
* python/python.c (gdbpy_run_events): Do not ignore exceptions.

gdb/testsuite/ChangeLog
2018-09-23  Tom Tromey  <tom@tromey.com>

PR python/14062:
* gdb.python/python.exp: Add test for post_event error.

gdb/ChangeLog
gdb/python/python.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.python/python.exp

index a03163ff7ddd2f7c885fd2c58c272c354af745cd..15ae55a18417040f62bc2da6cef2106217b96037 100644 (file)
@@ -1,3 +1,8 @@
+2018-09-23  Tom Tromey  <tom@tromey.com>
+
+       PR python/14062:
+       * python/python.c (gdbpy_run_events): Do not ignore exceptions.
+
 2018-09-23  Tom Tromey  <tom@tromey.com>
 
        PR python/18170:
index c16305b900fe12274e4a5d8b70e86496f32cf7f8..8fbce7846950b54b701f828c97bb2e1efba33943 100644 (file)
@@ -987,10 +987,9 @@ gdbpy_run_events (int error, gdb_client_data client_data)
       if (gdbpy_event_list == NULL)
        gdbpy_event_list_end = &gdbpy_event_list;
 
-      /* Ignore errors.  */
       gdbpy_ref<> call_result (PyObject_CallObject (item->event, NULL));
       if (call_result == NULL)
-       PyErr_Clear ();
+       gdbpy_print_stack ();
 
       Py_DECREF (item->event);
       xfree (item);
index c04f09a352e95489c73e2215a5337d81a42b459e..131940bc184a9efa1bcf6d8fffe3937599328146 100644 (file)
@@ -1,3 +1,8 @@
+2018-09-23  Tom Tromey  <tom@tromey.com>
+
+       PR python/14062:
+       * gdb.python/python.exp: Add test for post_event error.
+
 2018-09-23  Tom Tromey  <tom@tromey.com>
 
        PR python/18170:
index a37113c17c7b13f0fdfc00911afb8ed06fe80881..0723507af3e5990550ea0a097690ce86919c254b 100644 (file)
@@ -134,7 +134,18 @@ gdb_py_test_multiple "post event insertion" \
   "end" ""
 
 gdb_test "python print (someVal)" "1" "test post event execution"
-gdb_test "python gdb.post_event(str(1))" "RuntimeError: Posted event is not callable.*" "test non callable class"
+gdb_test "python gdb.post_event(str(1))" "RuntimeError: Posted event is not callable.*" \
+    "test non callable class"
+
+send_gdb "python gdb.post_event(lambda: invalid())\n"
+gdb_expect {
+    -re "name 'invalid' is not defined" {
+       pass "test post_event error on receipt"
+    }
+    default {
+       fail "test post_event error on receipt"
+    }
+}
 
 # Test (no) pagination of the executed command.
 gdb_test "show height" {Number of lines gdb thinks are in a page is unlimited\.}
This page took 0.053677 seconds and 4 git commands to generate.