From patchwork Wed Feb 22 23:46:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Buettner X-Patchwork-Id: 65476 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0C0C6385023D for ; Wed, 22 Feb 2023 23:48:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0C0C6385023D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1677109715; bh=CeGBWyBCRPb4r/9p6so8h4SoA8ZCtmrSUzZjrSza+EY=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=ocQNNPJKhZGd4OA42iyo+DQQWsJo0ZEbC8OVt9rwx+upjONuPFCT+7TCs7bwTnGT2 trju76RLtsefeWnS7EqvsVBRSjGX6tTuT8yKRzIwWZElNEVkvoKPcymEgeqtnXnmXD 9t/E98T4X2HSjiRm29Uwo0tAcKhu/XVsfp7GSQ7A= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 03B913858296 for ; Wed, 22 Feb 2023 23:47:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 03B913858296 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-478-TaVjSnJyPnuUXslD5T8cYw-1; Wed, 22 Feb 2023 18:47:12 -0500 X-MC-Unique: TaVjSnJyPnuUXslD5T8cYw-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D05C318A63EC; Wed, 22 Feb 2023 23:47:11 +0000 (UTC) Received: from f34-1.lan (unknown [10.2.16.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4F600440D9; Wed, 22 Feb 2023 23:47:11 +0000 (UTC) To: gdb-patches@sourceware.org Cc: pedro@palves.net, Kevin Buettner , Tom de Vries Subject: [PATCH v5 6/8] QUIT processing w/ explicit throw for gdb_exception_forced_quit Date: Wed, 22 Feb 2023 16:46:11 -0700 Message-Id: <20230222234613.29662-7-kevinb@redhat.com> In-Reply-To: <20230222234613.29662-1-kevinb@redhat.com> References: <20230222234613.29662-1-kevinb@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-10.6 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Kevin Buettner via Gdb-patches From: Kevin Buettner Reply-To: Kevin Buettner Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" This commit contains changes which have an explicit throw for gdb_exception_forced_quit, or, in a couple of cases for gdb_exception, but with a throw following a check to see if 'reason' is RETURN_FORCED_QUIT. Most of these are straightforward - it made sense to continue to allow an existing catch of gdb_exception to also catch gdb_exception_quit; in these cases, a catch/throw for gdb_exception_forced_quit was added. There are two cases, however, which deserve a more detailed explanation. 1) remote_fileio_request in gdb/remote-fileio.c: The try block calls do_remote_fileio_request which can (in turn) call one of the functions in remote_fio_func_map[]. Taking the first one, remote_fileio_func_open(), we have the following call path to maybe_quit(): remote_fileio_func_open(remote_target*, char*) -> target_read_memory(unsigned long, unsigned char*, long) -> target_read(target_ops*, target_object, char const*, unsigned char*, unsigned long, long) -> maybe_quit() Since there is a path to maybe_quit(), we must ensure that the catch block is not permitted to swallow a QUIT representing a SIGTERM. However, for this case, we must take care not to change the way that Ctrl-C / SIGINT is handled; we want to send a suitable EINTR reply to the remote target should that happen. That being the case, I added a catch/throw for gdb_exception_forced_quit. I also did a bit of rewriting here, adding a catch for gdb_exception_quit in favor of checking the 'reason' code in the catch block for gdb_exception. 2) mi_execute_command in gdb/mi/mi-main.c: The try block calls captured_mi_execute_command(); there exists a call path to maybe_quit(): captured_mi_execute_command(ui_out*, mi_parse*) -> mi_cmd_execute(mi_parse*) -> get_current_frame() -> get_prev_frame_always_1(frame_info*) -> frame_register_unwind_location(frame_info*, int, int*, lval_type*, unsigned long*, int*) -> frame_register_unwind(frame_info*, int, int*, int*, lval_type*, unsigned long*, int*, unsigned char*) -> value_entirely_available(value*) -> value_fetch_lazy(value*) -> value_fetch_lazy_memory(value*) -> read_value_memory(value*, long, int, unsigned long, unsigned char*, unsigned long) -> maybe_quit() That being the case, we can't allow the exception handler (catch block) to swallow a gdb_exception_quit for SIGTERM. However, it does seem reasonable to output the exception via the mi interface so that some suitable message regarding SIGTERM might be printed; therefore, I check the exception's 'reason' field for RETURN_FORCED_QUIT and do a throw for this case. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=26761 Tested-by: Tom de Vries --- gdb/event-top.c | 2 ++ gdb/mi/mi-main.c | 4 ++++ gdb/remote-fileio.c | 13 +++++++++---- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/gdb/event-top.c b/gdb/event-top.c index 14984707df1..563050a4081 100644 --- a/gdb/event-top.c +++ b/gdb/event-top.c @@ -1289,6 +1289,8 @@ async_disconnect (gdb_client_data arg) gdb_puts ("Could not kill the program being debugged", gdb_stderr); exception_print (gdb_stderr, exception); + if (exception.reason == RETURN_FORCED_QUIT) + throw; } for (inferior *inf : all_inferiors ()) diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c index 84a95a24684..0013e5dfafd 100644 --- a/gdb/mi/mi-main.c +++ b/gdb/mi/mi-main.c @@ -1952,6 +1952,10 @@ mi_execute_command (const char *cmd, int from_tty) somewhere. */ mi_print_exception (command->token, result); mi_out_rewind (current_uiout); + + /* Throw to a higher level catch for SIGTERM sent to GDB. */ + if (result.reason == RETURN_FORCED_QUIT) + throw; } bpstat_do_actions (); diff --git a/gdb/remote-fileio.c b/gdb/remote-fileio.c index 3ff2a65b0ec..69b409708a3 100644 --- a/gdb/remote-fileio.c +++ b/gdb/remote-fileio.c @@ -1191,12 +1191,17 @@ remote_fileio_request (remote_target *remote, char *buf, int ctrlc_pending_p) { do_remote_fileio_request (remote, buf); } + catch (const gdb_exception_forced_quit &ex) + { + throw; + } + catch (const gdb_exception_quit &ex) + { + remote_fileio_reply (remote, -1, FILEIO_EINTR); + } catch (const gdb_exception &ex) { - if (ex.reason == RETURN_QUIT) - remote_fileio_reply (remote, -1, FILEIO_EINTR); - else - remote_fileio_reply (remote, -1, FILEIO_EIO); + remote_fileio_reply (remote, -1, FILEIO_EIO); } }