public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
From: "cvs-commit at gcc dot gnu.org" <sourceware-bugzilla@sourceware.org>
To: gdb-prs@sourceware.org
Subject: [Bug gdb/28275] commit_resumed_state assertion failure when killing running inferior and running again
Date: Thu, 01 Dec 2022 15:07:19 +0000	[thread overview]
Message-ID: <bug-28275-4717-aDI31IxeUp@http.sourceware.org/bugzilla/> (raw)
In-Reply-To: <bug-28275-4717@http.sourceware.org/bugzilla/>

https://sourceware.org/bugzilla/show_bug.cgi?id=28275

--- Comment #15 from cvs-commit at gcc dot gnu.org <cvs-commit at gcc dot gnu.org> ---
The gdb-12-branch branch has been updated by Simon Marchi
<simark@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=0fd7bbc90133138d12914608ebb68bab16259b78

commit 0fd7bbc90133138d12914608ebb68bab16259b78
Author: Andrew Burgess <aburgess@redhat.com>
Date:   Mon Nov 21 12:12:11 2022 -0500

    gdb: fix assert when quitting GDB while a thread is stepping

    This commit addresses one of the issues identified in PR gdb/28275.

    Bug gdb/28275 identifies a number of situations in which this assert:

      Assertion `!proc_target->commit_resumed_state' failed.

    could be triggered.  There's actually a number of similar places where
    this assert is found in GDB, the two of interest in gdb/28275 are in
    target_wait and target_stop.

    In one of the comments:

      https://sourceware.org/bugzilla/show_bug.cgi?id=28275#c1

    steps to trigger the assertion within target_stop were identified when
    using a modified version of the gdb.threads/detach-step-over.exp test
    script.

    In the gdb.threads/detach-step-over.exp test, we attach to a
    multi-threaded inferior, and continue the inferior in asynchronous
    (background) mode.  Each thread is continuously hitting a conditional
    breakpoint where the condition is always false.  While the inferior is
    running we detach.  The goal is that we detach while GDB is performing a
    step-over for the conditional breakpoint in at least one thread.

    While detaching, if a step-over is in progress, then GDB has to
    complete the step over before we can detach.  This involves calling
    target_stop and target_wait (see prepare_for_detach).

    As far as gdb/28275 is concerned, the interesting part here, is the
    the process_stratum_target::commit_resumed_state variable must be
    false when target_stop and target_wait are called.

    This is currently ensured because, in detach_command (infrun.c), we
    create an instance of scoped_disable_commit_resumed, this ensures that
    when target_detach is called, ::commit_resumed_state will be false.

    The modification to the test that I propose here, and which exposed
    the bug, is that, instead of using "detach" to detach from the
    inferior, we instead use "quit".  Quitting GDB after attaching to an
    inferior will cause GDB to first detach, and then exit.

    When we quit GDB we end up calling target_detach via a different code
    path, the stack looks like:

      #0 target_detach
      #1 kill_or_detach
      #2 quit_force
      #3 quit_command

    Along this path there is no scoped_disable_commit_resumed created.
    ::commit_resumed_state can be true when we reach prepare_for_detach,
    which calls target_wait and target_stop, so the assertion will trigger.

    In this commit, I propose fixing this by adding the creation of a
    scoped_disable_commit_resumed into target_detach.  This will ensure
    that ::commit_resumed_state is false when calling prepare_for_detach
    from within target_detach.

    I did consider placing the scoped_disable_commit_resumed in
    prepare_for_detach, however, placing it in target_detach ensures that
    the target's commit_resumed_state flag is left to false if the detached
    inferior was the last one for that target.  It's the same rationale as
    for patch "gdb: disable commit resumed in target_kill" that comes later
    in this series, but for detach instead of kill.

    detach_command still includes a scoped_disable_commit_resumed too, but I
    think it is still relevant to cover the resumption at the end of the
    function.

    Co-Authored-By: Simon Marchi <simon.marchi@efficios.com>
    Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=28275
    Change-Id: Ie128f7aba6ef0e018859275eca372e6ea738e96f

-- 
You are receiving this mail because:
You are on the CC list for the bug.

  parent reply	other threads:[~2022-12-01 15:07 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-26 14:35 [Bug gdb/28275] New: " simark at simark dot ca
2021-08-26 19:39 ` [Bug gdb/28275] " andrew.burgess at embecosm dot com
2021-10-29  9:22 ` nyanpasu64 at tuta dot io
2021-10-29 12:54 ` simark at simark dot ca
2022-11-14 15:02 ` vries at gcc dot gnu.org
2022-11-14 15:29 ` simark at simark dot ca
2022-11-14 16:32 ` vries at gcc dot gnu.org
2022-11-15  7:34 ` vries at gcc dot gnu.org
2022-11-15 11:20 ` vries at gcc dot gnu.org
2022-11-15 12:55 ` vries at gcc dot gnu.org
2022-11-16 15:36 ` aburgess at redhat dot com
2022-11-22 15:29 ` brobecker at gnat dot com
2022-11-28 13:03 ` cvs-commit at gcc dot gnu.org
2022-11-28 14:13 ` cvs-commit at gcc dot gnu.org
2022-11-28 14:14 ` simark at simark dot ca
2022-12-01 15:07 ` cvs-commit at gcc dot gnu.org [this message]
2022-12-01 15:07 ` cvs-commit at gcc dot gnu.org
2023-01-04  9:15 ` vries at gcc dot gnu.org
2023-01-04  9:57 ` brobecker at gnat dot com

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=bug-28275-4717-aDI31IxeUp@http.sourceware.org/bugzilla/ \
    --to=sourceware-bugzilla@sourceware.org \
    --cc=gdb-prs@sourceware.org \
    /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).