]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Translate PyExc_KeyboardInterrupt to gdb "quit"
authorTom Tromey <tom@tromey.com>
Tue, 25 Dec 2018 19:38:01 +0000 (12:38 -0700)
committerTom Tromey <tom@tromey.com>
Thu, 27 Dec 2018 20:34:39 +0000 (13:34 -0700)
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.

gdb/ChangeLog
gdb/python/py-utils.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.python/py-cmd.exp

index 612f82ff7bfe25434ff8f47297acf0c93afa4bfb..eea0c21d17b73d2d0d5b8c809f89bbd930294911 100644 (file)
@@ -1,3 +1,8 @@
+2018-12-27  Tom Tromey  <tom@tromey.com>
+
+       * python/py-utils.c (gdbpy_handle_exception): Translate
+       PyExc_KeyboardInterrupt to quit.
+
 2018-12-27  Tom Tromey  <tom@tromey.com>
 
        * python/python-internal.h (gdbpy_print_stack_or_quit): Declare.
index e0aedb5b58e4e84979dd6536153a37f8942be260..a587644e226f940478da2ca01de9d4286905ae4c 100644 (file)
@@ -422,7 +422,9 @@ gdbpy_handle_exception ()
      for user errors.  However, a missing message for gdb.GdbError
      exceptions is arguably a bug, so we flag it as such.  */
 
-  if (! PyErr_GivenExceptionMatches (ptype, gdbpy_gdberror_exc)
+  if (PyErr_GivenExceptionMatches (ptype, PyExc_KeyboardInterrupt))
+    throw_quit ("Quit");
+  else if (! PyErr_GivenExceptionMatches (ptype, gdbpy_gdberror_exc)
       || msg == NULL || *msg == '\0')
     {
       PyErr_Restore (ptype, pvalue, ptraceback);
index 47572ba14ac16dfea4ef83351b9be12eab359542..b86d6257def5d6d39b3185156eecc512bff3edd3 100644 (file)
@@ -1,3 +1,8 @@
+2018-12-27  Tom Tromey  <tom@tromey.com>
+
+       * gdb.python/py-cmd.exp (test_python_inline_or_multiline): Add
+       pagination test.
+
 2018-12-24  Andrew Burgess  <andrew.burgess@embecosm.com>
 
        * gdb.dwarf2/dw2-unusual-field-names.c: New file.
index 33a5b39842ed9928c976463cf182662d4799666d..473fce23e8738a17e42a2c24fc794795c05e16b0 100644 (file)
@@ -261,3 +261,43 @@ if { [readline_is_used] } {
        }
     }
 }
+
+
+# Test that interrupting pagination throws a gdb quit.
+gdb_test_no_output "set height 10"
+
+gdb_py_test_multiple "input multi-line-output command" \
+  "python" "" \
+  "class test_mline (gdb.Command):" "" \
+  "  \"\"\"Docstring\"\"\"" "" \
+  "  def __init__ (self):" "" \
+  "    super (test_mline, self).__init__ (\"test_multiline\", gdb.COMMAND_USER)" "" \
+  "  def invoke (self, arg, from_tty):" "" \
+  "    for f in range(20):" "" \
+  "      print (\"test_multiline output\")" "" \
+  "test_mline ()" "" \
+  "end" ""
+
+set test "verify pagination from test_multiline"
+gdb_test_multiple "test_multiline" $test {
+    -re "--Type <RET>" {
+       exp_continue
+    }
+    -re " for more, q to quit" {
+       exp_continue
+    }
+    -re ", c to continue without paging--$" {
+       pass $test
+    }
+}
+
+send_gdb "q\n"
+set test "verify pagination from test_multiline: q"
+gdb_test_multiple "test_multiline" $test {
+    -re "Error occurred in Python" {
+       fail $test
+    }
+    -re "Quit" {
+       pass $test
+    }
+}