From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1028) id D4DA33858C5F; Mon, 27 Feb 2023 23:21:21 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D4DA33858C5F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1677540081; bh=xt/SR8K/cQsEjwY5Od2x7KjkuDyaEfIzP/RQ4OwNb08=; h=From:To:Subject:Date:From; b=JQP+4VS8BmLUuAcD14jGxntwrPR/21tNKLpi/tqn5iZ+hd8aK3ntpUWmlZZYK2JiV oDl8DgcBeqJgUQdZgwJP4teCMd8LvHrlTnPwV1Z4mUkVRau+bLW555zNzjJm3Xf61D Q4Q11wSyBXmAm/q0N59pfhJsaPJLWaH6sHELk1nA= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Kevin Buettner To: gdb-cvs@sourceware.org Subject: [binutils-gdb] Introduce gdb_exception_forced_quit X-Act-Checkin: binutils-gdb X-Git-Author: Kevin Buettner X-Git-Refname: refs/heads/master X-Git-Oldrev: f3d3bbbcdd8af6295458eee3b023447c13edabd3 X-Git-Newrev: 522044dc5fa76f9fef70fe746274daf09bbf64fe Message-Id: <20230227232121.D4DA33858C5F@sourceware.org> Date: Mon, 27 Feb 2023 23:21:21 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D522044dc5fa7= 6f9fef70fe746274daf09bbf64fe commit 522044dc5fa76f9fef70fe746274daf09bbf64fe Author: Kevin Buettner Date: Mon Feb 27 16:11:37 2023 -0700 Introduce gdb_exception_forced_quit =20 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(). =20 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. =20 This commit only introduces the exception plus supporting machinery; changes which use this new exception are in later commits in this series. =20 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=3D26761 Tested-by: Tom de Vries Approved-by: Pedro Alves Diff: --- 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 =3D=3D RETURN_QUIT) throw gdb_exception_quit (std::move (exception)); + else if (exception.reason =3D=3D RETURN_FORCED_QUIT) + throw gdb_exception_forced_quit (std::move (exception)); else if (exception.reason =3D=3D 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 =3D=3D RETURN_QUIT) throw gdb_exception_quit (fmt, ap); + else if (reason =3D=3D RETURN_FORCED_QUIT) + throw gdb_exception_forced_quit (fmt, ap); else if (reason =3D=3D 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 @@ =20 enum return_reason { + /* SIGTERM sent to GDB. */ + RETURN_FORCED_QUIT =3D -3, /* User interrupt. */ RETURN_QUIT =3D -2, /* Any other error. */ @@ -42,9 +44,10 @@ enum return_reason =20 typedef enum { + RETURN_MASK_FORCED_QUIT =3D RETURN_MASK (RETURN_FORCED_QUIT), RETURN_MASK_QUIT =3D RETURN_MASK (RETURN_QUIT), RETURN_MASK_ERROR =3D RETURN_MASK (RETURN_ERROR), - RETURN_MASK_ALL =3D (RETURN_MASK_QUIT | RETURN_MASK_ERROR) + RETURN_MASK_ALL =3D (RETURN_MASK_FORCED_QUIT | RETURN_MASK_QUIT | RETURN= _MASK_ERROR) } return_mask; =20 /* Describe all exceptions. */ @@ -294,6 +297,21 @@ struct gdb_exception_quit : public gdb_exception } }; =20 +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 =3D=3D 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); =20 #endif /* COMMON_COMMON_EXCEPTIONS_H */