diff options
author | Tom Tromey <tom@tromey.com> | 2017-04-24 21:47:59 -0600 |
---|---|---|
committer | Tom Tromey <tom@tromey.com> | 2018-03-26 21:57:12 -0600 |
commit | 4ca59a9f3616ba324952632233acc657fffa8be1 (patch) | |
tree | cc109167eec74ae3047bcf8b0389be3089da8703 /gdb/python | |
parent | 92256134f3e5557dcc321c63c48e8175ea90ca27 (diff) | |
download | gdb-4ca59a9f3616ba324952632233acc657fffa8be1.zip gdb-4ca59a9f3616ba324952632233acc657fffa8be1.tar.gz gdb-4ca59a9f3616ba324952632233acc657fffa8be1.tar.bz2 |
Throw a "quit" on a KeyboardException in py-framefilter.c
If a C-c comes while the Python code for a frame filter is running, it
will be turned into a Python KeyboardException. It seems good for
this to be treated like a GDB quit, so this patch changes
py-framefilter.c to notice this situation and call throw_quit in this
case.
gdb/ChangeLog
2018-03-26 Tom Tromey <tom@tromey.com>
* python/py-framefilter.c (throw_quit_or_print_exception): New
function.
(gdbpy_apply_frame_filter): Use it.
gdb/testsuite/ChangeLog
2018-03-26 Tom Tromey <tom@tromey.com>
* gdb.python/py-framefilter.exp: Add test for KeyboardInterrupt.
* gdb.python/py-framefilter.py (name_error): New global.
(ErrorInName.function): Use name_error.
Diffstat (limited to 'gdb/python')
-rw-r--r-- | gdb/python/py-framefilter.c | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/gdb/python/py-framefilter.c b/gdb/python/py-framefilter.c index 28d5c37..0662e68 100644 --- a/gdb/python/py-framefilter.c +++ b/gdb/python/py-framefilter.c @@ -1305,6 +1305,21 @@ bootstrap_python_frame_filters (struct frame_info *frame, return iterable.release (); } +/* A helper function that will either print an exception or, if it is + a KeyboardException, throw a quit. This can only be called when + the Python exception is set. */ + +static void +throw_quit_or_print_exception () +{ + if (PyErr_ExceptionMatches (PyExc_KeyboardInterrupt)) + { + PyErr_Clear (); + throw_quit ("Quit"); + } + gdbpy_print_stack (); +} + /* This is the only publicly exported function in this file. FRAME is the source frame to start frame-filter invocation. FLAGS is an integer holding the flags for printing. The following elements of @@ -1375,7 +1390,7 @@ gdbpy_apply_frame_filter (const struct extension_language_defn *extlang, initialization error. This return code will trigger a default backtrace. */ - gdbpy_print_stack (); + throw_quit_or_print_exception (); return EXT_LANG_BT_NO_FILTERS; } @@ -1398,7 +1413,7 @@ gdbpy_apply_frame_filter (const struct extension_language_defn *extlang, { if (PyErr_Occurred ()) { - gdbpy_print_stack (); + throw_quit_or_print_exception (); return EXT_LANG_BT_ERROR; } break; @@ -1423,7 +1438,7 @@ gdbpy_apply_frame_filter (const struct extension_language_defn *extlang, /* Do not exit on error printing a single frame. Print the error and continue with other frames. */ if (success == EXT_LANG_BT_ERROR) - gdbpy_print_stack (); + throw_quit_or_print_exception (); } return success; |