From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm1-f41.google.com (mail-wm1-f41.google.com [209.85.128.41]) by sourceware.org (Postfix) with ESMTPS id E204F3858C2F for ; Mon, 30 Jan 2023 18:57:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E204F3858C2F 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-f41.google.com with SMTP id c4-20020a1c3504000000b003d9e2f72093so10760936wma.1 for ; Mon, 30 Jan 2023 10:57:00 -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=/0thHXsbOZspL2S8JrxrSmcuF8m48QSxQAhf2pRSFEs=; b=fqIC6zYV5500y4qEItbEvU3aE6VSGlU0EFVEMESxkKYQjrBzpytwCI+TZB3Wx9eRwo kq8y3WXXH/EELnoSJgXtZH+uqfU1+yaHwuopTlRSSjlhovUYyebskX//O/bd8rJOqANF 1iw79vK71it/I1+Fyvgqj97saHWdYNZQce9D//Lg34Qa2BWHAiH+4aXpRBWoYQohpkIG J/cJJgTkSaSMLo1l35DhtKK2yatbKA2QgEKOjE6ZOG2x1SEQVrwcLdgycDIJgcyT11s7 YBv+WJrn4VSZcEYJeuQiL/WDx1vXIW7I4d6Tlmk2pDyuOXeOW3Xm0LLzfuDGs7OvfXKw qXxg== X-Gm-Message-State: AO0yUKXolljs1MaaSamIczxCyKvvOSMOCtKY3H0E2yaEM+4/Ncli0XB2 34fG5otpIkW7rNLu3bu/H8o= X-Google-Smtp-Source: AK7set+IR4COfQ1sSnLdGR6bDzbBffwNZBZWOJ/y0XygguZ9heAjBIptz6+xXMVTHeE7nNvxbWxTlA== X-Received: by 2002:a05:600c:4928:b0:3dc:51ad:9dc4 with SMTP id f40-20020a05600c492800b003dc51ad9dc4mr7036723wmp.18.1675105019656; Mon, 30 Jan 2023 10:56:59 -0800 (PST) Received: from ?IPv6:2001:8a0:f92b:9e00::1fe? ([2001:8a0:f92b:9e00::1fe]) by smtp.gmail.com with ESMTPSA id r7-20020a5d52c7000000b002bdf5832843sm12540990wrv.66.2023.01.30.10.56.59 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 30 Jan 2023 10:56:59 -0800 (PST) Subject: Re: [PATCH v4 1/8] Introduce 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-2-kevinb@redhat.com> From: Pedro Alves Message-ID: <843ea7fa-f070-198d-900f-b039f9f3f032@palves.net> Date: Mon, 30 Jan 2023 18:56:57 +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-2-kevinb@redhat.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-10.1 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 adds a new exception 'gdb_exception_forced_quit', reason > code 'REASON_FORCED_QUIT', return mask 'RETURN_MASK_FORCED_QUIT', and > a wrapper for throwing the exception, throw_forced_quit(). > > The addition of this exception plus supporting code will allow us to > recognize that a SIGTERM has been received by GDB and then propagate > recognition of that fact to the upper levels of GDB where it can be > correctly handled. At the moment, when GDB receives a SIGTERM, it > will attempt to exit via a series of calls from the QUIT checking > code. However, before it can exit, it must do various cleanups, such > as killing or detaching all inferiors. Should these cleanups be > attempted while GDB is executing very low level code, such as reading > target memory from within ps_xfer_memory(), it can happen that some of > GDB's state is out of sync with regard to the cleanup code's > expectations. In the case just mentioned, it's been observed that > inferior_ptid and the current_thread_ are not in sync; this triggers > an assert / internal error. > > This commit only introduces the exception plus supporting machinery; > changes which use this new exception are in later commits in this > series. OK. > > Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=26761 > --- > gdbsupport/common-exceptions.cc | 14 ++++++++++++++ > gdbsupport/common-exceptions.h | 22 +++++++++++++++++++++- > 2 files changed, 35 insertions(+), 1 deletion(-) > > diff --git a/gdbsupport/common-exceptions.cc b/gdbsupport/common-exceptions.cc > index d0dd8081c41..edc1b56181a 100644 > --- a/gdbsupport/common-exceptions.cc > +++ b/gdbsupport/common-exceptions.cc > @@ -184,6 +184,8 @@ throw_exception (gdb_exception &&exception) > { > if (exception.reason == RETURN_QUIT) > throw gdb_exception_quit (std::move (exception)); > + else if (exception.reason == RETURN_FORCED_QUIT) > + throw gdb_exception_forced_quit (std::move (exception)); > else if (exception.reason == RETURN_ERROR) > throw gdb_exception_error (std::move (exception)); > else > @@ -196,6 +198,8 @@ throw_it (enum return_reason reason, enum errors error, const char *fmt, > { > if (reason == RETURN_QUIT) > throw gdb_exception_quit (fmt, ap); > + else if (reason == RETURN_FORCED_QUIT) > + throw gdb_exception_forced_quit (fmt, ap); > else if (reason == RETURN_ERROR) > throw gdb_exception_error (error, fmt, ap); > else > @@ -233,3 +237,13 @@ throw_quit (const char *fmt, ...) > throw_vquit (fmt, args); > va_end (args); > } > + > +void > +throw_forced_quit (const char *fmt, ...) > +{ > + va_list args; > + > + va_start (args, fmt); > + throw_it (RETURN_FORCED_QUIT, GDB_NO_ERROR, fmt, args); > + va_end (args); > +} > diff --git a/gdbsupport/common-exceptions.h b/gdbsupport/common-exceptions.h > index a2a4f5a3892..f9b59ece736 100644 > --- a/gdbsupport/common-exceptions.h > +++ b/gdbsupport/common-exceptions.h > @@ -32,6 +32,8 @@ > > enum return_reason > { > + /* SIGTERM sent to GDB. */ > + RETURN_FORCED_QUIT = -3, > /* User interrupt. */ > RETURN_QUIT = -2, > /* Any other error. */ > @@ -42,9 +44,10 @@ enum return_reason > > typedef enum > { > + RETURN_MASK_FORCED_QUIT = RETURN_MASK (RETURN_FORCED_QUIT), > RETURN_MASK_QUIT = RETURN_MASK (RETURN_QUIT), > RETURN_MASK_ERROR = RETURN_MASK (RETURN_ERROR), > - RETURN_MASK_ALL = (RETURN_MASK_QUIT | RETURN_MASK_ERROR) > + RETURN_MASK_ALL = (RETURN_MASK_FORCED_QUIT | RETURN_MASK_QUIT | RETURN_MASK_ERROR) > } return_mask; > > /* Describe all exceptions. */ > @@ -294,6 +297,21 @@ struct gdb_exception_quit : public gdb_exception > } > }; > > +struct gdb_exception_forced_quit : public gdb_exception > +{ > + gdb_exception_forced_quit (const char *fmt, va_list ap) > + ATTRIBUTE_PRINTF (2, 0) > + : gdb_exception (RETURN_FORCED_QUIT, GDB_NO_ERROR, fmt, ap) > + { > + } > + > + explicit gdb_exception_forced_quit (gdb_exception &&ex) noexcept > + : gdb_exception (std::move (ex)) > + { > + gdb_assert (ex.reason == RETURN_FORCED_QUIT); > + } > +}; > + > /* An exception type that inherits from both std::bad_alloc and a gdb > exception. This is necessary because operator new can only throw > std::bad_alloc, and OTOH, we want exceptions thrown due to memory > @@ -336,5 +354,7 @@ extern void throw_error (enum errors error, const char *fmt, ...) > ATTRIBUTE_NORETURN ATTRIBUTE_PRINTF (2, 3); > extern void throw_quit (const char *fmt, ...) > ATTRIBUTE_NORETURN ATTRIBUTE_PRINTF (1, 2); > +extern void throw_forced_quit (const char *fmt, ...) > + ATTRIBUTE_NORETURN ATTRIBUTE_PRINTF (1, 2); > > #endif /* COMMON_COMMON_EXCEPTIONS_H */ >