public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Pedro Alves <pedro@palves.net>
To: Kevin Buettner <kevinb@redhat.com>, gdb-patches@sourceware.org
Cc: simark@simark.ca, tdevries@suse.de
Subject: Re: [PATCH v4 1/8] Introduce gdb_exception_forced_quit
Date: Mon, 30 Jan 2023 18:56:57 +0000	[thread overview]
Message-ID: <843ea7fa-f070-198d-900f-b039f9f3f032@palves.net> (raw)
In-Reply-To: <20230112015630.32999-2-kevinb@redhat.com>

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 */
> 


  reply	other threads:[~2023-01-30 18:57 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-12  1:56 [PATCH v4 0/8] Fix gdb.base/gdb-sigterm.exp failure/error Kevin Buettner
2023-01-12  1:56 ` [PATCH v4 1/8] Introduce gdb_exception_forced_quit Kevin Buettner
2023-01-30 18:56   ` Pedro Alves [this message]
2023-01-12  1:56 ` [PATCH v4 2/8] Handle gdb SIGTERM by throwing / catching gdb_exception_force_quit Kevin Buettner
2023-01-30 18:57   ` Pedro Alves
2023-01-12  1:56 ` [PATCH v4 3/8] Catch gdb_exception_error instead of gdb_exception (in many places) Kevin Buettner
2023-01-30 19:00   ` Pedro Alves
2023-02-16 10:52     ` Pedro Alves
2023-01-12  1:56 ` [PATCH v4 4/8] Python QUIT processing updates Kevin Buettner
2023-01-30 19:01   ` Pedro Alves
2023-02-20  2:52     ` Kevin Buettner
2023-02-23 12:50       ` Pedro Alves
2023-01-12  1:56 ` [PATCH v4 5/8] Guile " Kevin Buettner
2023-01-12  1:56 ` [PATCH v4 6/8] Call quit_force for gdb_exception_forced_quit in safe_execute_command Kevin Buettner
2023-01-30 19:01   ` Pedro Alves
2023-01-12  1:56 ` [PATCH v4 7/8] QUIT processing w/ explicit throw for gdb_exception_forced_quit Kevin Buettner
2023-01-30 19:02   ` Pedro Alves
2023-01-12  1:56 ` [PATCH v4 8/8] Forced quit cases handled by resetting sync_quit_force_run Kevin Buettner
2023-01-30 19:02   ` Pedro Alves
2023-01-12 12:37 ` [PATCH v4 0/8] Fix gdb.base/gdb-sigterm.exp failure/error Tom de Vries
2023-01-27 22:03   ` Kevin Buettner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=843ea7fa-f070-198d-900f-b039f9f3f032@palves.net \
    --to=pedro@palves.net \
    --cc=gdb-patches@sourceware.org \
    --cc=kevinb@redhat.com \
    --cc=simark@simark.ca \
    --cc=tdevries@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).