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/28405] arm-none-eabi: internal-error: ptid_t remote_target::select_thread_for_ambiguous_stop_reply(const target_waitstatus*): Assertion `first_resumed_thread != nullptr' failed
Date: Thu, 23 Dec 2021 12:19:07 +0000	[thread overview]
Message-ID: <bug-28405-4717-p2PG1t8GXN@http.sourceware.org/bugzilla/> (raw)
In-Reply-To: <bug-28405-4717@http.sourceware.org/bugzilla/>

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

--- Comment #11 from cvs-commit at gcc dot gnu.org <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Andrew Burgess <aburgess@sourceware.org>:

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

commit b622494ee378fd0a490c934c509364b4c7735273
Author: Andrew Burgess <andrew.burgess@embecosm.com>
Date:   Mon Oct 4 15:48:11 2021 +0100

    gdb/remote: handle attach when stop packet lacks thread-id

    Bug PR gdb/28405 reports a regression when using attach with an
    extended-remote target.  In this case the target is not including a
    thread-id in the stop packet it sends back after the attach.

    The regression was introduced with this commit:

      commit 8f66807b98f7634c43149ea62e454ea8f877691d
      Date:   Wed Jan 13 20:26:58 2021 -0500

          gdb: better handling of 'S' packets

    The problem is that when GDB processes the stop packet, it sees that
    there is no thread-id and so has to "guess" which thread the stop
    should apply to.

    In this case the target only has one thread, so really, there's no
    guessing needed, but GDB still runs through the same process, this
    shouldn't cause us any problems.

    However, after the above commit, GDB now expects itself to be more
    internally consistent, specifically, only a thread that GDB thinks is
    resumed, can be a candidate for having stopped.

    It turns out that, when GDB attaches to a process through an
    extended-remote target, the threads of the process being attached too,
    are not, initially, marked as resumed.

    And so, when GDB tries to figure out which thread the stop might apply
    too, it finds no threads in the processes marked resumed, and so an
    assert triggers.

    In extended_remote_target::attach we create a new thread with a call
    to add_thread_silent, rather than remote_target::remote_add_thread,
    the reason is that calling the latter will result in a call to
    'add_thread' rather than 'add_thread_silent'.  However,
    remote_target::remote_add_thread includes additional
    actions (i.e. calling remote_thread_info::set_resumed and set_running)
    which are missing from extended_remote_target::attach.  These missing
    calls are what would serve to mark the new thread as resumed.

    In this commit I propose that we add an extra parameter to
    remote_target::remote_add_thread.  This new parameter will force the
    new thread to be added with a call to add_thread_silent.  We can now
    call remote_add_thread from the ::attach method, the extra
    actions (listed above) will now be performed, and the thread will be
    left in the correct state.

    Additionally, in PR gdb/28405, a segfault is reported.  This segfault
    triggers when 'set debug remote 1' is used before trying to reproduce
    the original assertion failure.  The cause of this is in
    remote_target::select_thread_for_ambiguous_stop_reply, where we do
    this:

      remote_debug_printf ("first resumed thread is %s",
                           pid_to_str (first_resumed_thread->ptid).c_str ());
      remote_debug_printf ("is this guess ambiguous? = %d", ambiguous);

      gdb_assert (first_resumed_thread != nullptr);

    Notice that when debug printing is on we dereference
    first_resumed_thread before we assert that the pointer is not
    nullptr.  This is the cause of the segfault, and is resolved by moving
    the assert before the debug printing code.

    I've extended an existing test, ext-attach.exp, so that the original
    test is run multiple times; we run in the original mode, as normal,
    but also, we now run with different packets disabled in gdbserver.  In
    particular, disabling Tthread would trigger the assertion as it was
    reported in the original bug.  I also run the test in all-stop and
    non-stop modes now for extra coverage, we also run the tests with
    target-async enabled, and disabled.

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

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

  parent reply	other threads:[~2021-12-23 12:19 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-01  9:45 [Bug gdb/28405] New: " git at jbrengineering dot co.uk
2021-10-01  9:45 ` [Bug gdb/28405] " git at jbrengineering dot co.uk
2021-10-01  9:46 ` git at jbrengineering dot co.uk
2021-10-01  9:47 ` git at jbrengineering dot co.uk
2021-10-01 13:48 ` simark at simark dot ca
2021-10-01 15:15 ` git at jbrengineering dot co.uk
2021-10-01 16:56 ` simon.marchi at polymtl dot ca
2021-10-04 12:14 ` simark at simark dot ca
2021-10-04 13:52 ` andrew.burgess at embecosm dot com
2021-10-04 14:10 ` andrew.burgess at embecosm dot com
2021-10-04 15:29 ` andrew.burgess at embecosm dot com
2021-10-04 17:57 ` simark at simark dot ca
2021-10-05 14:20 ` git at jbrengineering dot co.uk
2021-10-06  8:11 ` andrew.burgess at embecosm dot com
2021-10-22  6:42 ` uzytkownik2 at gmail dot com
2021-12-23 12:19 ` cvs-commit at gcc dot gnu.org [this message]
2021-12-23 13:17 ` cvs-commit at gcc dot gnu.org
2021-12-23 13:18 ` aburgess at redhat 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-28405-4717-p2PG1t8GXN@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).