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 8/8] Forced quit cases handled by resetting sync_quit_force_run
Date: Mon, 30 Jan 2023 19:02:23 +0000	[thread overview]
Message-ID: <6c35f63b-5eda-20ea-126f-4e5390710a0c@palves.net> (raw)
In-Reply-To: <20230112015630.32999-9-kevinb@redhat.com>

On 2023-01-12 1:56 a.m., Kevin Buettner wrote:
> During my audit of the use of gdb_exception with regard to QUIT
> processing, I found a try/catch in the scoped_switch_fork_info
> destructor.
> 
> Static analysis found this call path from the destructor to
> maybe_quit():
> 
>   scoped_switch_fork_info::~scoped_switch_fork_info()
>     -> remove_breakpoints()
>     -> remove_breakpoint(bp_location*)
>     -> remove_breakpoint_1(bp_location*, remove_bp_reason)
>     -> memory_validate_breakpoint(gdbarch*, bp_target_info*)
>     -> target_read_memory(unsigned long, unsigned char*, long)
>     -> target_read(target_ops*, target_object, char const*, unsigned char*, unsigned long, long)
>     -> maybe_quit()
> 
> Since it's not safe to do a 'throw' from a destructor, we simply
> call set_quit_flag and, for gdb_exception_forced_quit, also
> set sync_quit_force_run.  This will cause the appropriate
> exception to be rethrown at the next QUIT check.
> 
> Another case is the try / catch in tui_getc() in tui-io.c.  The
> existing catch swallows the exception.  I've added a catch for
> 'gdb_exception_forced_quit', which also swallows the exception,
> but also sets sync_quit_force_run and calls set_quit_flag in
> order to restart forced quit processing at the next QUIT check.
> This is required because it isn't safe to throw into/through
> readline.
> 
> Thanks to Pedro Alves for suggesting this idea.
> 
> Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=26761
> ---
>  gdb/linux-fork.c | 13 +++++++++++++
>  gdb/tui/tui-io.c |  9 +++++++++
>  2 files changed, 22 insertions(+)
> 
> diff --git a/gdb/linux-fork.c b/gdb/linux-fork.c
> index 61545b859ea..fc2f00d0766 100644
> --- a/gdb/linux-fork.c
> +++ b/gdb/linux-fork.c
> @@ -430,6 +430,19 @@ class scoped_switch_fork_info
>  	    fork_load_infrun_state (m_oldfp);
>  	    insert_breakpoints ();
>  	  }
> +	catch (const gdb_exception_quit &ex)
> +	  {
> +	    /* We can't throw from a destructor, so re-set the quit flag
> +	      for later QUIT checking.  */
> +	    set_quit_flag ();
> +	  }
> +	catch (const gdb_exception_forced_quit &ex)
> +	  {
> +	    /* Like above, but (eventually) cause GDB to terminate by
> +	       setting sync_quit_force_run.  */
> +	    sync_quit_force_run = 1;
> +	    set_quit_flag ();

I think it'd be nice if we had a function that did both of these for us.
Something like "set_force_quit_flag()".

> +	  }
>  	catch (const gdb_exception &ex)
>  	  {
>  	    warning (_("Couldn't restore checkpoint state in %s: %s"),
> diff --git a/gdb/tui/tui-io.c b/gdb/tui/tui-io.c
> index 2f39e34df2f..ac3c7296499 100644
> --- a/gdb/tui/tui-io.c
> +++ b/gdb/tui/tui-io.c
> @@ -1275,6 +1275,15 @@ tui_getc (FILE *fp)
>      {
>        return tui_getc_1 (fp);
>      }
> +  catch (const gdb_exception_forced_quit &ex)
> +    {
> +      /* As noted below, it's not safe to let an exception escape
> +         to newline, so, for this case,  reset the quit flag for

Spurious double space before "reset".

> +	 later QUIT checking.  */
> +      sync_quit_force_run = 1;
> +      set_quit_flag ();
> +      return 0;
> +    }
>    catch (const gdb_exception &ex)
>      {
>        /* Just in case, don't ever let an exception escape to readline.
> 


  reply	other threads:[~2023-01-30 19:02 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
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 [this message]
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=6c35f63b-5eda-20ea-126f-4e5390710a0c@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).