public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Mikaela Szekely <mikaela.szekely@qyriad.me>
To: gdb-patches@sourceware.org
Subject: Re: [PATCH][PR gdb/28874] gdb/remote: switch to added threads if there isn't one already
Date: Sat, 25 Jun 2022 11:29:33 -0600	[thread overview]
Message-ID: <CAGP-VdSjZJ-O3DbcG=n0dx=eaH4FjL-3jSx3u6B7V+pn6v_2jA@mail.gmail.com> (raw)
In-Reply-To: <20220419220135.1714665-1-mikaela.szekely@qyriad.me>

Are there any thoughts on this? I'm happy to answer any questions if
there are any.

On Tue, Apr 19, 2022 at 4:01 PM Mikaela Szekely
<mikaela.szekely@qyriad.me> wrote:
>
> Bug PR gdb/28874 reports a failed assertion when attaching to remote
> targets. This assertion is checked after a call to
> gdb::observers::new_thread.notify from set_running.
> The call to set_running in remote_target::remote_add_thread, however,
> appears to always be called before any call to switch_to_thread
> for remote targets that have set non-stop off.
>
> This commit proposes a new internal function has_inferior_thread in
> gdb/thread.c, which allows remote_target::remote_add_thread to check if
> the current thread has been set or not. And thus I have also adjusted
> the logic of ::remote_add_thread to call switch_to_thread upon thread
> creation if has_inferior_thread returns false.
>
> Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=28874
> ---
>  gdb/gdbthread.h | 3 +++
>  gdb/remote.c    | 6 ++++++
>  gdb/thread.c    | 7 +++++++
>  3 files changed, 16 insertions(+)
>
> diff --git a/gdb/gdbthread.h b/gdb/gdbthread.h
> index 1a33eb61221..bf230410a12 100644
> --- a/gdb/gdbthread.h
> +++ b/gdb/gdbthread.h
> @@ -875,6 +875,9 @@ class scoped_restore_current_thread
>    enum language m_lang;
>  };
>
> +/* Returns true if there is a current inferior thread. */
> +extern bool has_inferior_thread (void);
> +
>  /* Returns a pointer into the thread_info corresponding to
>     INFERIOR_PTID.  INFERIOR_PTID *must* be in the thread list.  */
>  extern struct thread_info* inferior_thread (void);
> diff --git a/gdb/remote.c b/gdb/remote.c
> index aa6a67a96e0..d35387650b3 100644
> --- a/gdb/remote.c
> +++ b/gdb/remote.c
> @@ -2572,6 +2572,12 @@ remote_target::remote_add_thread (ptid_t ptid, bool running, bool executing,
>    else
>      thread = add_thread (this, ptid);
>
> +  /* If there isn't already an active thread, then switch to the
> +     thread we just added, so bare-metal targets don't assert the
> +     current thread as null. */
> +  if (!has_inferior_thread())
> +    switch_to_thread(thread);
> +
>    /* We start by assuming threads are resumed.  That state then gets updated
>       when we process a matching stop reply.  */
>    get_remote_thread_info (thread)->set_resumed ();
> diff --git a/gdb/thread.c b/gdb/thread.c
> index 9d0693bd0b8..e7b418b1c85 100644
> --- a/gdb/thread.c
> +++ b/gdb/thread.c
> @@ -79,6 +79,13 @@ is_current_thread (const thread_info *thr)
>    return thr == current_thread_;
>  }
>
> +
> +bool
> +has_inferior_thread (void)
> +{
> +  return current_thread_ != nullptr;
> +}
> +
>  struct thread_info*
>  inferior_thread (void)
>  {
> --
> 2.35.1
>

  reply	other threads:[~2022-06-25 17:29 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-19 22:01 Mikaela Szekely
2022-06-25 17:29 ` Mikaela Szekely [this message]
2022-07-18 18:51   ` Mikaela Szekely
2022-07-18 22:23     ` Pedro Alves

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='CAGP-VdSjZJ-O3DbcG=n0dx=eaH4FjL-3jSx3u6B7V+pn6v_2jA@mail.gmail.com' \
    --to=mikaela.szekely@qyriad.me \
    --cc=gdb-patches@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).