Skip to content

Commit bc543c9

Browse files
committed
Translate PyExc_KeyboardInterrupt to gdb "quit"
A while back I typed "info pretty-printers" with a large number of printers installed, and I typed "q" to stop the pagination. I noticed that gdb printed a Python exception in this case. It seems to me that, instead, quitting pagination (or control-c'ing a Python command generally) should be handled the same way that gdb normally handles a quit. This patch implements this idea by changing gdbpy_handle_exception to treat PyExc_KeyboardInterrupt specially. gdb/ChangeLog 2018-12-27 Tom Tromey <tom@tromey.com> * python/py-utils.c (gdbpy_handle_exception): Translate PyExc_KeyboardInterrupt to quit. gdb/testsuite/ChangeLog 2018-12-27 Tom Tromey <tom@tromey.com> * gdb.python/py-cmd.exp (test_python_inline_or_multiline): Add pagination test.
1 parent 6ef2312 commit bc543c9

4 files changed

Lines changed: 53 additions & 1 deletion

File tree

‎gdb/ChangeLog‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
2018-12-27 Tom Tromey <tom@tromey.com>
2+
3+
* python/py-utils.c (gdbpy_handle_exception): Translate
4+
PyExc_KeyboardInterrupt to quit.
5+
16
2018-12-27 Tom Tromey <tom@tromey.com>
27

38
* python/python-internal.h (gdbpy_print_stack_or_quit): Declare.

‎gdb/python/py-utils.c‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,9 @@ gdbpy_handle_exception ()
422422
for user errors. However, a missing message for gdb.GdbError
423423
exceptions is arguably a bug, so we flag it as such. */
424424

425-
if (! PyErr_GivenExceptionMatches (ptype, gdbpy_gdberror_exc)
425+
if (PyErr_GivenExceptionMatches (ptype, PyExc_KeyboardInterrupt))
426+
throw_quit ("Quit");
427+
else if (! PyErr_GivenExceptionMatches (ptype, gdbpy_gdberror_exc)
426428
|| msg == NULL || *msg == '\0')
427429
{
428430
PyErr_Restore (ptype, pvalue, ptraceback);

‎gdb/testsuite/ChangeLog‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
2018-12-27 Tom Tromey <tom@tromey.com>
2+
3+
* gdb.python/py-cmd.exp (test_python_inline_or_multiline): Add
4+
pagination test.
5+
16
2018-12-24 Andrew Burgess <andrew.burgess@embecosm.com>
27

38
* gdb.dwarf2/dw2-unusual-field-names.c: New file.

‎gdb/testsuite/gdb.python/py-cmd.exp‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,3 +261,43 @@ if { [readline_is_used] } {
261261
}
262262
}
263263
}
264+
265+
266+
# Test that interrupting pagination throws a gdb quit.
267+
gdb_test_no_output "set height 10"
268+
269+
gdb_py_test_multiple "input multi-line-output command" \
270+
"python" "" \
271+
"class test_mline (gdb.Command):" "" \
272+
" \"\"\"Docstring\"\"\"" "" \
273+
" def __init__ (self):" "" \
274+
" super (test_mline, self).__init__ (\"test_multiline\", gdb.COMMAND_USER)" "" \
275+
" def invoke (self, arg, from_tty):" "" \
276+
" for f in range(20):" "" \
277+
" print (\"test_multiline output\")" "" \
278+
"test_mline ()" "" \
279+
"end" ""
280+
281+
set test "verify pagination from test_multiline"
282+
gdb_test_multiple "test_multiline" $test {
283+
-re "--Type <RET>" {
284+
exp_continue
285+
}
286+
-re " for more, q to quit" {
287+
exp_continue
288+
}
289+
-re ", c to continue without paging--$" {
290+
pass $test
291+
}
292+
}
293+
294+
send_gdb "q\n"
295+
set test "verify pagination from test_multiline: q"
296+
gdb_test_multiple "test_multiline" $test {
297+
-re "Error occurred in Python" {
298+
fail $test
299+
}
300+
-re "Quit" {
301+
pass $test
302+
}
303+
}

0 commit comments

Comments
 (0)