From patchwork Tue Apr 25 19:41:10 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 20146 Received: (qmail 22331 invoked by alias); 25 Apr 2017 19:41:36 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 22173 invoked by uid 89); 25 Apr 2017 19:41:35 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.3 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=ham version=3.3.2 spammy=thrown, Cc, Throw, H*Ad:U*tom X-HELO: gproxy10.mail.unifiedlayer.com Received: from gproxy10-pub.mail.unifiedlayer.com (HELO gproxy10.mail.unifiedlayer.com) (69.89.20.226) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 25 Apr 2017 19:41:33 +0000 Received: from cmgw4 (unknown [10.0.90.85]) by gproxy10.mail.unifiedlayer.com (Postfix) with ESMTP id 4F60C140598 for ; Tue, 25 Apr 2017 13:41:34 -0600 (MDT) Received: from box522.bluehost.com ([74.220.219.122]) by cmgw4 with id CjhW1v00c2f2jeq01jhZvG; Tue, 25 Apr 2017 13:41:34 -0600 X-Authority-Analysis: v=2.2 cv=QdwWhoTv c=1 sm=1 tr=0 a=GsOEXm/OWkKvwdLVJsfwcA==:117 a=GsOEXm/OWkKvwdLVJsfwcA==:17 a=AzvcPWV-tVgA:10 a=zstS-IiYAAAA:8 a=wcRY0TraO8xaX3Vyd84A:9 a=4G6NA9xxw8l3yy4pmD5M:22 Received: from 75-166-63-71.hlrn.qwest.net ([75.166.63.71]:40598 helo=bapiya.Home) by box522.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.87) (envelope-from ) id 1d36L4-0000OG-OL; Tue, 25 Apr 2017 13:41:30 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFA 07/10] Throw a "quit" on a KeyboardException in py-framefilter.c Date: Tue, 25 Apr 2017 13:41:10 -0600 Message-Id: <20170425194113.17862-8-tom@tromey.com> In-Reply-To: <20170425194113.17862-1-tom@tromey.com> References: <20170425194113.17862-1-tom@tromey.com> X-BWhitelist: no X-Exim-ID: 1d36L4-0000OG-OL X-Source-Sender: 75-166-63-71.hlrn.qwest.net (bapiya.Home) [75.166.63.71]:40598 X-Source-Auth: tom+tromey.com X-Email-Count: 8 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTIyLmJsdWVob3N0LmNvbQ== 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. ChangeLog 2017-04-25 Tom Tromey * python/py-framefilter.c (throw_quit_or_print_exception): New function. (gdbpy_apply_frame_filter): Use it. testsuite/ChangeLog 2017-04-25 Tom Tromey * gdb.python/py-framefilter.exp: Add test for KeyboardInterrupt. * gdb.python/py-framefilter.py (name_error): New global. (ErrorInName.function): Use name_error. --- gdb/ChangeLog | 6 ++++++ gdb/python/py-framefilter.c | 21 ++++++++++++++++++--- gdb/testsuite/ChangeLog | 6 ++++++ gdb/testsuite/gdb.python/py-framefilter.exp | 10 ++++++++++ gdb/testsuite/gdb.python/py-framefilter.py | 6 +++++- 5 files changed, 45 insertions(+), 4 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index d0e0be4..0bf5386 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,11 @@ 2017-04-25 Tom Tromey + * python/py-framefilter.c (throw_quit_or_print_exception): New + function. + (gdbpy_apply_frame_filter): Use it. + +2017-04-25 Tom Tromey + PR cli/17716: * python/py-framefilter.c (py_print_type, py_print_value) (enumerate_args, py_print_args, gdbpy_apply_frame_filter): Use diff --git a/gdb/python/py-framefilter.c b/gdb/python/py-framefilter.c index e0a7bd0..76e637c 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 @@ -1363,7 +1378,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; } @@ -1386,7 +1401,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; @@ -1398,7 +1413,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; diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index f9f48c5..6f6bbce 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,5 +1,11 @@ 2017-04-25 Tom Tromey + * gdb.python/py-framefilter.exp: Add test for KeyboardInterrupt. + * gdb.python/py-framefilter.py (name_error): New global. + (ErrorInName.function): Use name_error. + +2017-04-25 Tom Tromey + PR backtrace/15582: * gdb.python/py-framefilter.exp: Add "bt elide" test. diff --git a/gdb/testsuite/gdb.python/py-framefilter.exp b/gdb/testsuite/gdb.python/py-framefilter.exp index 80aa495..1a0572d 100644 --- a/gdb/testsuite/gdb.python/py-framefilter.exp +++ b/gdb/testsuite/gdb.python/py-framefilter.exp @@ -213,6 +213,16 @@ gdb_test_multiple "bt 1" $test { } } +# Now verify that we can see a quit. +gdb_test_no_output "python name_error = KeyboardInterrupt" \ + "Change ErrorFilter to throw KeyboardInterrupt" +set test "bt 1 with KeyboardInterrupt" +gdb_test_multiple "bt 1" $test { + -re "Quit" { + pass $test + } +} + # Test with no debuginfo # We cannot use prepare_for_testing as we have to set the safe-patch diff --git a/gdb/testsuite/gdb.python/py-framefilter.py b/gdb/testsuite/gdb.python/py-framefilter.py index edd0e00..b579ec3 100644 --- a/gdb/testsuite/gdb.python/py-framefilter.py +++ b/gdb/testsuite/gdb.python/py-framefilter.py @@ -134,13 +134,17 @@ class FrameElider (): def filter (self, frame_iter): return ElidingIterator (frame_iter) +# This is here so the test can change the kind of error that is +# thrown. +name_error = RuntimeError + # A simple decorator that gives an error when computing the function. class ErrorInName(FrameDecorator): def __init__(self, frame): FrameDecorator.__init__(self, frame) def function(self): - raise RuntimeError('whoops') + raise name_error('whoops') # A filter that supplies buggy frames. Disabled by default. class ErrorFilter():