From: Pedro Alves <palves@redhat.com>
To: Yao Qi <qiyaoltc@gmail.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH 2/2] Don't delete thread_info if refcount isn't zero
Date: Fri, 07 Apr 2017 10:29:00 -0000 [thread overview]
Message-ID: <228668fb-05be-3f9b-9290-c12059a25cab@redhat.com> (raw)
In-Reply-To: <86a87sk1wz.fsf@gmail.com>
On 04/07/2017 10:22 AM, Yao Qi wrote:
> Pedro Alves <palves@redhat.com> writes:
>
>>> - tp = find_thread_ptid (old->inferior_ptid);
>>> -
>>> - /* If the previously selected thread belonged to a process that has
>>> - in the mean time been deleted (due to normal exit, detach, etc.),
>>> - then don't revert back to it, but instead simply drop back to no
>>> - thread selected. */
>>
>> This comment still makes sense, with a small tweak -- saying "deleted"
>> has always been a bit misleading here:
>>
>> /* If the previously selected thread belonged to a process that has
>> in the mean time exited (or killed, detached, etc.), then don't revert
>> back to it, but instead simply drop back to no thread selected. */
>>
>> I'll be happy with restoring this comment alongside your new comment.
>
> The comments describe something different from what the code does.
It doesn't. See below.
> With
> my patch, in make_cleanup_restore_current_thread, if we can find
> thread_info by inferior_ptid, saved it in old->thread and increase the
> refcount, so that it won't be deleted, but it can be marked as exited.
> Then, in do_restore_current_thread_cleanup,
>
> + if (old->thread != NULL
> + && find_inferior_ptid (old->thread->ptid) != NULL)
> + restore_current_thread (old->thread->ptid);
> else
> {
> restore_current_thread (null_ptid);
>
> the first line means we previously selected one existing thread, we
> still switch to that thread, which may be already marked as exited. It
> is nothing wrong as far as I can see.
I'm not sure what you mean by "wrong". I'm saying that the old comment
still makes sense. That comment is talking about the
"find_inferior_ptid (old->thread->ptid) != NULL" line, which is a
lookup for an _inferior_ not a thread. Both the inferior and thread_info
object are still around, but the process may have exited/been detached
meanwhile, and consequently the inferior's "pid" field is now
zero. And in that case, we don't restore back the selected thread.
E.g., with:
start
thread apply all detach
#1 - the current thread (thread 1), has its refcount incremented.
#2 - detach gets rid of all threads of the process. The "thread 1"
object is left around, marked exited, because it was not
deletable.
#3 - when we try to restore the previous thread, its
_inferior_ has meanwhile gotten its "pid" field zeroed,
so a look up for an inferior with the pid of the previous
thread's "ptid" (which just looks at the pid) won't
find any inferior. (Unless it finds the wrong inferior
that happened to reuse the pid meanwhile.)
Hopefully that makes the rest of my comments in my previous
message clearer.
Thanks,
Pedro Alves
next prev parent reply other threads:[~2017-04-07 10:29 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-28 8:24 [PATCH 0/2] Fix thread_info refcount Yao Qi
2017-03-28 8:24 ` [PATCH 2/2] Delete thread_info is refcount is zero Yao Qi
2017-03-28 12:10 ` Pedro Alves
2017-04-05 21:15 ` [PATCH 0/2] Don't delete thread_info if refcount isn't zero Yao Qi
2017-04-05 21:15 ` [PATCH 1/2] Hoist code on marking thread as exited Yao Qi
2017-04-06 9:27 ` Pedro Alves
2017-04-05 21:15 ` [PATCH 2/2] Don't delete thread_info if refcount isn't zero Yao Qi
2017-04-06 10:18 ` Pedro Alves
2017-04-07 9:22 ` Yao Qi
2017-04-07 10:29 ` Pedro Alves [this message]
2017-04-10 13:40 ` Yao Qi
2017-04-10 14:50 ` [pushed] GC gdb/thread.c:current_thread_cleanup_chain (Re: [PATCH 2/2] Don't delete thread_info if refcount isn't zero) Pedro Alves
2017-04-10 15:57 ` [PATCH 2/2] Don't delete thread_info if refcount isn't zero Pedro Alves
[not found] ` <1490689483-16084-2-git-send-email-yao.qi@linaro.org>
2017-03-28 12:12 ` [PATCH 1/2] Add constructor and destructor to thread_info Pedro Alves
2017-03-28 14:08 ` Yao Qi
2017-03-28 14:47 ` Pedro Alves
2017-03-28 15:40 ` Yao Qi
2017-03-28 22:35 ` Pedro Alves
2017-03-29 15:59 ` Yao Qi
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=228668fb-05be-3f9b-9290-c12059a25cab@redhat.com \
--to=palves@redhat.com \
--cc=gdb-patches@sourceware.org \
--cc=qiyaoltc@gmail.com \
/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