From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id C9073385B52E for ; Thu, 12 Jan 2023 01:57:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C9073385B52E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1673488626; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=S8GaHFkKAQBU5+TZm8XO9dGZxble4ufG970IP+C2P+U=; b=Ll6bXsvix9EgUjEDB720Pxg6FIs5gMEdXNVoOU1i1iR+1NHPBO9bBXXg7Ep8UeWEy5IZaT oK2dp5w2rmmNJ3H+AbzKEFa2xJH0QBG8Ra00TSy0BDXp5hAkudQAPmxT6XlBmmLIz0MOJC iw++XFUL2NXU8KmeTHJmuN2wInXUdu4= 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-263-yz-zbe77M7KeAyosMPZU4w-1; Wed, 11 Jan 2023 20:57:03 -0500 X-MC-Unique: yz-zbe77M7KeAyosMPZU4w-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 113A1185A78B; Thu, 12 Jan 2023 01:57:03 +0000 (UTC) Received: from f34-1.lan (unknown [10.2.17.76]) by smtp.corp.redhat.com (Postfix) with ESMTP id 600CA492C14; Thu, 12 Jan 2023 01:57:02 +0000 (UTC) From: Kevin Buettner To: gdb-patches@sourceware.org Cc: pedro@palves.net, simark@simark.ca, tdevries@suse.de, Kevin Buettner Subject: [PATCH v4 1/8] Introduce gdb_exception_forced_quit Date: Wed, 11 Jan 2023 18:56:23 -0700 Message-Id: <20230112015630.32999-2-kevinb@redhat.com> In-Reply-To: <20230112015630.32999-1-kevinb@redhat.com> References: <20230112015630.32999-1-kevinb@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true 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 List-Id: 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. 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 */ -- 2.34.3