From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm1-f42.google.com (mail-wm1-f42.google.com [209.85.128.42]) by sourceware.org (Postfix) with ESMTPS id AA8303858D1E for ; Mon, 30 Jan 2023 19:02:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AA8303858D1E Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=palves.net Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-wm1-f42.google.com with SMTP id k8-20020a05600c1c8800b003dc57ea0dfeso2789206wms.0 for ; Mon, 30 Jan 2023 11:02:07 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:content-language:in-reply-to:mime-version :user-agent:date:message-id:from:references:cc:to:subject :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=JHVvDIazKMEanQnjLv7Ll7wsNI9bzFNKerOSizDT+iY=; b=kXPJqC6+WvCMlLWbVwwwjRDDDEYJeKSauUZ9X1YulNwHa6nVq1oaXXPri6DqESfLl4 ErnoYwORLmzQ3nP2zsDxJsMPPUouk6x+TjaongOn7LVKA+k0DzYUklXRexlL5SKdAbNg BJ2ipQ20ZYu0d4XrL3yN3UTpVmhrJQ8NguQ+U4AMhvLibhi9ooBIwJPhtvNY+eCmo1MQ k27eQiK2DiAbtcbgkyhiAn6CirOQ6MIxAN43/fK9XSZtQK+xqhUhRbIHnCbtjcGJ3+Mh wTeAQ6hFIitksreF8BtsYXmj4QjshpKcTvCFTb11LVkalUZXxtuh4cvLIelmqaK1k1SX ctLw== X-Gm-Message-State: AO0yUKXyomuobTei4WoKzkCfImEAC2gY9xhbE0ZN4/dTw1QHufJjKlSm Lcv7KL4KYdreGYDPC9QOFrk= X-Google-Smtp-Source: AK7set8OPPwKwRdrjGIdW8QJWnGtm4u08dn9JaJIvdyY1WVQ0J66mUHO4PV98htngnOe82yWql98YA== X-Received: by 2002:a05:600c:350a:b0:3dd:1c45:a36d with SMTP id h10-20020a05600c350a00b003dd1c45a36dmr62479wmq.27.1675105326671; Mon, 30 Jan 2023 11:02:06 -0800 (PST) Received: from ?IPv6:2001:8a0:f92b:9e00::1fe? ([2001:8a0:f92b:9e00::1fe]) by smtp.gmail.com with ESMTPSA id bi5-20020a05600c3d8500b003db0bb81b6asm14215946wmb.1.2023.01.30.11.02.06 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 30 Jan 2023 11:02:06 -0800 (PST) Subject: Re: [PATCH v4 7/8] QUIT processing w/ explicit throw for gdb_exception_forced_quit To: Kevin Buettner , gdb-patches@sourceware.org Cc: simark@simark.ca, tdevries@suse.de References: <20230112015630.32999-1-kevinb@redhat.com> <20230112015630.32999-8-kevinb@redhat.com> From: Pedro Alves Message-ID: <6948775e-c771-bf35-8c26-6201d80b4536@palves.net> Date: Mon, 30 Jan 2023 19:02:04 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.10.1 MIME-Version: 1.0 In-Reply-To: <20230112015630.32999-8-kevinb@redhat.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-10.2 required=5.0 tests=BAYES_00,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,GIT_PATCH_0,HEADER_FROM_DIFFERENT_DOMAINS,KAM_DMARC_STATUS,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS,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 List-Id: On 2023-01-12 1:56 a.m., Kevin Buettner wrote: > 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 > --- > gdb/event-top.c | 2 ++ > gdb/mi/mi-main.c | 4 ++++ > gdb/remote-fileio.c | 15 ++++++++++----- > gdb/tui/tui.c | 4 ++++ > 4 files changed, 20 insertions(+), 5 deletions(-) > > diff --git a/gdb/event-top.c b/gdb/event-top.c > index 4a46e1b9346..9d34e574653 100644 > --- a/gdb/event-top.c > +++ b/gdb/event-top.c > @@ -1281,6 +1281,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 e0cade2edc3..d7ca7843d6f 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..c804b0b2098 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 &ex) > + catch (const gdb_exception_forced_quit &ex) > + { > + throw; > + } Tabs vs spaces above. > + catch (const gdb_exception_quit &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_EINTR); > + } > + catch (const gdb_exception &ex) > + { > + remote_fileio_reply (remote, -1, FILEIO_EIO); > } Ditto. > } > > diff --git a/gdb/tui/tui.c b/gdb/tui/tui.c > index cdae9ffe02b..23b47ee163c 100644 > --- a/gdb/tui/tui.c > +++ b/gdb/tui/tui.c > @@ -122,6 +122,10 @@ tui_rl_switch_mode (int notused1, int notused2) > tui_enable (); > } > } > + catch (const gdb_exception_forced_quit &ex) > + { > + throw; > + } We can't let the exception propagate here. See comment just above, which reads: /* Don't let exceptions escape. We're in the middle of a readline callback that isn't prepared for that. */ try { ... I think we need to use the set_quit_flag()-to-rethrow-later trick here. > catch (const gdb_exception &ex) > { > exception_print (gdb_stderr, ex); >