public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Simon Marchi <simark@simark.ca>
To: Tom de Vries <tdevries@suse.de>, gdb-patches@sourceware.org
Subject: Re: [PATCH] [gdb] Fix assert in delete_breakpoint
Date: Tue, 21 Nov 2023 11:11:16 -0500	[thread overview]
Message-ID: <114c9994-ed81-4a14-bcc3-bd8086e46340@simark.ca> (raw)
In-Reply-To: <ad47339b-e8b1-4cda-8c66-830919024ebf@suse.de>

On 11/15/23 06:12, Tom de Vries wrote:
> Because it's deleted twice.
> 
> The last thing we see in gdb.log before the internal error is:
> ...
>    [infrun] handle_signal_stop: [13633.13633.0] hit its single-step breakpoint^M
> ...
> 
> And the statement following the infrun_debug_printf printing that message is:
> ...
>   delete_just_stopped_threads_single_step_breakpoints ();
> ...
> 
> So, the following events happen:
> - the single-step breakpoint is hit
> - delete_just_stopped_threads_single_step_breakpoints is called
> - during delete_just_stopped_threads_single_step_breakpoints,
>   delete_breakpoint is called which removes the breakpoint from the
>   breakpoint chain
> - gdb is interrupted by SIGTERM before finish delete_breakpoint
> - the SIGTERM triggers a SCOPE_EXIT cleanup, calling
>   delete_just_stopped_threads_infrun_breakpoints which ends up
>   calling delete_breakpoint again for the same breakpoint.
> 
> The proposed fix tries to handle delete_breakpoint being interrupted, and called again.
> 
> This is an alternative fix:
> ...
> diff --git a/gdb/thread.c b/gdb/thread.c
> index 47cc5c9cd14..7f029f2414c 100644
> --- a/gdb/thread.c
> +++ b/gdb/thread.c
> @@ -93,11 +93,12 @@ inferior_thread (void)
>  static void
>  delete_thread_breakpoint (struct breakpoint **bp_p)
>  {
> -  if (*bp_p != NULL)
> -    {
> -      delete_breakpoint (*bp_p);
> -      *bp_p = NULL;
> -    }
> +  struct breakpoint *bp = *bp_p;
> +
> +  *bp_p = nullptr;
> +
> +  if (bp != nullptr)
> +    delete_breakpoint (bp);
>  }
> 
>  void
> ...
> 
> It makes sure delete_breakpoint is called only once, but I don't think this is the way to go, since it prevents the cleanup.

Err, my intuition is that it doesn't make sense for operations like
that, that update GDB's state (especially the tricky infrun / breakpoint
state) in reaction to target events, to be interruptible by SIGTERM.
It's just a recipe for ending up with half-baked state that is not
up-to-date with the reality.

I suppose that after receiving the SIGTERM, execution is interrupted by
a QUIT macro and a gdb_exception_quit is thrown?  Are you able to tell
which QUIT causes this to happen, and show what the stack looks like at
this point?

Simon

  parent reply	other threads:[~2023-11-21 16:11 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-13 15:26 Tom de Vries
2023-11-14 15:09 ` Simon Marchi
2023-11-15 11:12   ` Tom de Vries
2023-11-15 12:12     ` Tom de Vries
2023-11-21 12:22     ` Tom de Vries
2023-11-21 16:11     ` Simon Marchi [this message]
2023-11-21 16:52       ` Tom de Vries
2023-11-22 12:44         ` Tom de Vries
2023-11-22 14:49           ` Tom de Vries
2023-11-27 10:19           ` Tom de Vries
2023-11-27 16:29             ` Simon Marchi
2023-11-28 15:22               ` Tom de Vries
2023-11-28 15:30               ` Tom Tromey
2023-11-29 12:08                 ` Tom de Vries
2023-11-29 20:46                   ` Tom de Vries
2023-11-29 21:33                 ` Tom de Vries
2023-11-30 17:08                 ` Simon Marchi
2023-11-21 16:40   ` Luis Machado

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=114c9994-ed81-4a14-bcc3-bd8086e46340@simark.ca \
    --to=simark@simark.ca \
    --cc=gdb-patches@sourceware.org \
    --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).