From: Pedro Alves <palves@redhat.com>
To: Yao Qi <qiyaoltc@gmail.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH 8/8] Fix removing inferiors from within "thread apply" commands
Date: Thu, 13 Apr 2017 12:22:00 -0000 [thread overview]
Message-ID: <3e492ba6-f183-cc41-6b5c-cc23a6ed116a@redhat.com> (raw)
In-Reply-To: <86o9w08ru5.fsf@gmail.com>
On 04/13/2017 12:33 PM, Yao Qi wrote:
> Pedro Alves <palves@redhat.com> writes:
>
>> @@ -313,9 +319,31 @@ public:
>> explicit inferior (int pid);
>> ~inferior ();
>>
>> + /* Returns true if we can delete this inferior. We can't delete it
>> + if it is the current inferior, or if there's code out there that
>> + relies on it existing (m_refcount > 0). */
>> + bool deletable () const
>> + {
>> + return m_refcount == 0 && this != current_inferior ();
>> + }
>> +
>> /* Pointer to next inferior in singly-linked list of inferiors. */
>> struct inferior *next = NULL;
>>
>> + /* Increase the refcount. */
>> + void incref ()
>> + {
>> + gdb_assert (m_refcount >= 0);
>> + m_refcount++;
>> + }
>> +
>> + /* Decrease the refcount. */
>> + void decref ()
>> + {
>> + m_refcount--;
>> + gdb_assert (m_refcount >= 0);
>> + }
>> +
>> /* Convenient handle (GDB inferior id). Unique across all
>> inferiors. */
>> int num = 0;
>> @@ -431,6 +459,12 @@ public:
>>
>> /* Per inferior data-pointers required by other GDB modules. */
>> REGISTRY_FIELDS;
>> +
>> +private:
>> + /* If this is > 0, then it means there's code out there that relies
>> + on this inferior existing. Don't allow deleting it in that
>> + case. */
>> + int m_refcount = 0;
>> };
>
> Can we move them to a super class, so that both thread and inferior can
> extend it?
Just to be clear, would the class include the incref()/decref()
methods + m_refcount, plus some refcount() accessor method,
or more than that? Let me give it a try.
>> +static void
>> +switch_to_thread (thread_info *thr)
>> +{
>> + gdb_assert (thr != NULL);
>> +
>> + if (inferior_ptid == thr->ptid)
>> return;
>>
>> - inferior_ptid = ptid;
>> + /* Switch the current program space and current inferior as
>> + well. */
>> + set_current_program_space (thr->inf->pspace);
>> + set_current_inferior (thr->inf);
>> +
>> + inferior_ptid = thr->ptid;
>
> Can these code be replaced by switch_to_thread_no_regs?
Looks like it. I'm testing the patch below on top.
From c74e7b7b6eb29664e1afded656194266e95ee869 Mon Sep 17 00:00:00 2001
From: Pedro Alves <palves@redhat.com>
Date: Thu, 13 Apr 2017 13:11:39 +0100
Subject: [PATCH] switch_to_thread_no_regs
---
gdb/thread.c | 12 ++----------
1 file changed, 2 insertions(+), 10 deletions(-)
diff --git a/gdb/thread.c b/gdb/thread.c
index f48d871..2c38a9a 100644
--- a/gdb/thread.c
+++ b/gdb/thread.c
@@ -1457,10 +1457,8 @@ info_threads_command (char *arg, int from_tty)
void
switch_to_thread_no_regs (struct thread_info *thread)
{
- struct inferior *inf;
+ struct inferior *inf = thread->inf;
- inf = find_inferior_ptid (thread->ptid);
- gdb_assert (inf != NULL);
set_current_program_space (inf->pspace);
set_current_inferior (inf);
@@ -1491,12 +1489,8 @@ switch_to_thread (thread_info *thr)
if (inferior_ptid == thr->ptid)
return;
- /* Switch the current program space and current inferior as
- well. */
- set_current_program_space (thr->inf->pspace);
- set_current_inferior (thr->inf);
+ switch_to_thread_no_regs (thr);
- inferior_ptid = thr->ptid;
reinit_frame_cache ();
/* We don't check for is_stopped, because we're called at times
@@ -1505,8 +1499,6 @@ switch_to_thread (thread_info *thr)
if (thr->state != THREAD_EXITED
&& !thr->executing)
stop_pc = regcache_read_pc (get_thread_regcache (thr->ptid));
- else
- stop_pc = ~(CORE_ADDR) 0;
}
/* See gdbthread.h. */
--
2.5.5
next prev parent reply other threads:[~2017-04-13 12:22 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-04-11 23:51 [PATCH 0/8] " Pedro Alves
2017-04-11 23:51 ` [PATCH 3/8] C++fy thread_apply_all_command Pedro Alves
2017-04-13 10:06 ` Yao Qi
2017-04-11 23:51 ` [PATCH 7/8] Make inferior::detaching a bool, and introduce scoped_restore::release() Pedro Alves
2017-04-11 23:51 ` [PATCH 1/8] watch_command_1: Fix dangling frame access Pedro Alves
2017-04-13 9:34 ` Yao Qi
2017-04-13 15:26 ` Pedro Alves
2017-04-11 23:51 ` [PATCH 2/8] Fix follow-fork latent bug Pedro Alves
2017-04-13 9:58 ` Yao Qi
2017-04-13 12:09 ` Pedro Alves
2017-04-13 15:33 ` Yao Qi
2017-04-11 23:51 ` [PATCH 6/8] Make inferior a class with cdtors, and use new/delete Pedro Alves
2017-04-13 10:24 ` Yao Qi
2017-04-11 23:51 ` [PATCH 8/8] Fix removing inferiors from within "thread apply" commands Pedro Alves
2017-04-13 11:33 ` Yao Qi
2017-04-13 12:22 ` Pedro Alves [this message]
2017-04-13 14:49 ` Pedro Alves
2017-04-19 8:23 ` Yao Qi
2017-04-19 12:15 ` Pedro Alves
2017-04-19 12:20 ` Pedro Alves
2017-04-13 15:31 ` Yao Qi
2017-04-11 23:56 ` [PATCH 4/8] Improve coverage of the PR threads/13217 regression test Pedro Alves
2017-04-13 10:09 ` Yao Qi
2017-04-11 23:56 ` [PATCH 5/8] GC inferior.c:init_inferior_list Pedro Alves
2017-04-13 10:10 ` 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=3e492ba6-f183-cc41-6b5c-cc23a6ed116a@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