From patchwork Tue Dec 25 19:53:57 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 30838 Received: (qmail 10060 invoked by alias); 25 Dec 2018 19:54:05 -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 9923 invoked by uid 89); 25 Dec 2018 19:54:04 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=declare, sequence, H*Ad:U*tom X-HELO: gateway34.websitewelcome.com Received: from gateway34.websitewelcome.com (HELO gateway34.websitewelcome.com) (192.185.149.105) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 25 Dec 2018 19:54:02 +0000 Received: from cm11.websitewelcome.com (cm11.websitewelcome.com [100.42.49.5]) by gateway34.websitewelcome.com (Postfix) with ESMTP id 412F31E121 for ; Tue, 25 Dec 2018 13:54:01 -0600 (CST) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id bsm9gbGbBdnCebsm9gjymW; Tue, 25 Dec 2018 13:54:01 -0600 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Sender:Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=Zm/J7FZROO1uRRvSuqtGJGqWIiKsutUAmIOWhh5emT4=; b=gkRaukOM0vBBHLm49ExAQlz+9m IinUdGUWXeYvkjAu3C8UpX9dtBmYbpKKdsMrZXxpfwivcYOgyLabSkwTrt3Cc8gmcX7JAQ1pdSEVQ bLd0o0wvM6+ZinRzDg7dxJAKy; Received: from 75-166-72-210.hlrn.qwest.net ([75.166.72.210]:40844 helo=bapiya.Home) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.91) (envelope-from ) id 1gbsm9-003Cqk-1r; Tue, 25 Dec 2018 13:54:01 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 2/3] Consolidate some Python exception-printing functions Date: Tue, 25 Dec 2018 12:53:57 -0700 Message-Id: <20181225195358.19399-3-tom@tromey.com> In-Reply-To: <20181225195358.19399-1-tom@tromey.com> References: <20181225195358.19399-1-tom@tromey.com> A few places in the Python code would either call gdbpy_print_stack, or throw a gdb "quit", depending on the pending exception. This patch consolidates these into a helper function. gdb/ChangeLog 2018-12-25 Tom Tromey * python/python-internal.h (gdbpy_print_stack_or_quit): Declare. * python/py-unwind.c (pyuw_sniffer): Use gdbpy_print_stack_or_quit. * python/py-framefilter.c (throw_quit_or_print_exception): Remove. (gdbpy_apply_frame_filter): Use gdbpy_print_stack_or_quit. * python/python.c (gdbpy_print_stack_or_quit): New function. --- gdb/ChangeLog | 10 ++++++++++ gdb/python/py-framefilter.c | 21 +++------------------ gdb/python/py-unwind.c | 7 +------ gdb/python/python-internal.h | 1 + gdb/python/python.c | 14 ++++++++++++++ 5 files changed, 29 insertions(+), 24 deletions(-) diff --git a/gdb/python/py-framefilter.c b/gdb/python/py-framefilter.c index fe17b70f53..b4bc41306b 100644 --- a/gdb/python/py-framefilter.c +++ b/gdb/python/py-framefilter.c @@ -1054,21 +1054,6 @@ 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 @@ -1139,7 +1124,7 @@ gdbpy_apply_frame_filter (const struct extension_language_defn *extlang, initialization error. This return code will trigger a default backtrace. */ - throw_quit_or_print_exception (); + gdbpy_print_stack_or_quit (); return EXT_LANG_BT_NO_FILTERS; } @@ -1162,7 +1147,7 @@ gdbpy_apply_frame_filter (const struct extension_language_defn *extlang, { if (PyErr_Occurred ()) { - throw_quit_or_print_exception (); + gdbpy_print_stack_or_quit (); return EXT_LANG_BT_ERROR; } break; @@ -1196,7 +1181,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) - throw_quit_or_print_exception (); + gdbpy_print_stack_or_quit (); } return success; diff --git a/gdb/python/py-unwind.c b/gdb/python/py-unwind.c index 469ae489f4..efef4f7e0f 100644 --- a/gdb/python/py-unwind.c +++ b/gdb/python/py-unwind.c @@ -535,12 +535,7 @@ pyuw_sniffer (const struct frame_unwind *self, struct frame_info *this_frame, { /* If the unwinder is cancelled due to a Ctrl-C, then propagate the Ctrl-C as a GDB exception instead of swallowing it. */ - if (PyErr_ExceptionMatches (PyExc_KeyboardInterrupt)) - { - PyErr_Clear (); - quit (); - } - gdbpy_print_stack (); + gdbpy_print_stack_or_quit (); return 0; } if (pyo_unwind_info == Py_None) diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h index 1ac54f9b57..6a0d2328ed 100644 --- a/gdb/python/python-internal.h +++ b/gdb/python/python-internal.h @@ -654,6 +654,7 @@ extern const struct language_defn *python_language; int gdbpy_print_python_errors_p (void); void gdbpy_print_stack (void); +void gdbpy_print_stack_or_quit (); void gdbpy_handle_exception () ATTRIBUTE_NORETURN; gdbpy_ref<> python_string_to_unicode (PyObject *obj); diff --git a/gdb/python/python.c b/gdb/python/python.c index d6453e786c..e65c6524aa 100644 --- a/gdb/python/python.c +++ b/gdb/python/python.c @@ -1278,6 +1278,20 @@ gdbpy_print_stack (void) } } +/* Like gdbpy_print_stack, but if the exception is a + KeyboardException, throw a gdb "quit" instead. */ + +void +gdbpy_print_stack_or_quit () +{ + if (PyErr_ExceptionMatches (PyExc_KeyboardInterrupt)) + { + PyErr_Clear (); + throw_quit ("Quit"); + } + gdbpy_print_stack (); +} + /* Return a sequence holding all the Progspaces. */