[4/7] Report Python errors coming from gdb.post_event
Commit Message
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.
gdb/ChangeLog
2018-09-15 Tom Tromey <tom@tromey.com>
PR python/14062:
* python/python.c (gdbpy_run_events): Do not ignore exceptions.
gdb/testsuite/ChangeLog
2018-09-15 Tom Tromey <tom@tromey.com>
PR python/14062:
* gdb.python/python.exp: Add test for post_event error.
---
gdb/ChangeLog | 5 +++++
gdb/python/python.c | 3 +--
gdb/testsuite/ChangeLog | 5 +++++
gdb/testsuite/gdb.python/python.exp | 13 ++++++++++++-
4 files changed, 23 insertions(+), 3 deletions(-)
@@ -1043,10 +1043,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);
@@ -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\.}