From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 62451 invoked by alias); 13 Apr 2017 12:22:29 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 62442 invoked by uid 89); 13 Apr 2017 12:22:28 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-23.7 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,KAM_LAZY_DOMAIN_SECURITY,RCVD_IN_DNSWL_NONE,RCVD_IN_SORBS_SPAM autolearn=ham version=3.3.2 spammy= X-HELO: mail-wr0-f174.google.com Received: from mail-wr0-f174.google.com (HELO mail-wr0-f174.google.com) (209.85.128.174) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 13 Apr 2017 12:22:27 +0000 Received: by mail-wr0-f174.google.com with SMTP id c55so34616429wrc.3 for ; Thu, 13 Apr 2017 05:22:28 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:cc:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=Z6rUvf9yyby9Oi+hicfIJOBzifE3GOtsI+dfDJkWj1I=; b=l0RwjFAJzial+X/6nKzgJKZKGwfHmVQ/QJwDw47XAIrWv8a5Ftg+Xs0cD0+h4NOkDO xPaTjeh4zq+5r5CdXC+3yFdYgP+mz/M0fz7StqoSu1Dm5eNLhIzzQMiZjcOAVUtpK6aH jfAh/hr/+oWakcJSmYD9b1SH+8CvO9OVZSF4p73H9LvL5GKSNGlQL59XHT2wl23kWcaG vkW/iVb5qUI2W5E2HLBCnv8zFTynbMIQ8eA4UvkAzuYC183Z0wv0q9V55qo9H87cipzc OcoPZ9UlARJTeRZetHrw05HRfn3QumPciqpPsnXgr/DB6v4wC7nKUh0GU2hW1MyFFqnh ijjg== X-Gm-Message-State: AN3rC/68wvsJkRvEW0jlwbJZUktgnBvPwIqEgVxJegTrwit1iCakFKed 9ckicakqBl9sF7Y7 X-Received: by 10.223.129.4 with SMTP id 4mr2932918wrm.62.1492086146490; Thu, 13 Apr 2017 05:22:26 -0700 (PDT) Received: from [192.168.0.101] ([37.189.166.198]) by smtp.gmail.com with ESMTPSA id h3sm29373138wrb.43.2017.04.13.05.22.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 13 Apr 2017 05:22:25 -0700 (PDT) Subject: Re: [PATCH 8/8] Fix removing inferiors from within "thread apply" commands To: Yao Qi References: <1491954673-29172-1-git-send-email-palves@redhat.com> <1491954673-29172-9-git-send-email-palves@redhat.com> <86o9w08ru5.fsf@gmail.com> Cc: gdb-patches@sourceware.org From: Pedro Alves Message-ID: <3e492ba6-f183-cc41-6b5c-cc23a6ed116a@redhat.com> Date: Thu, 13 Apr 2017 12:22:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-Version: 1.0 In-Reply-To: <86o9w08ru5.fsf@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-SW-Source: 2017-04/txt/msg00419.txt.bz2 On 04/13/2017 12:33 PM, Yao Qi wrote: > Pedro Alves 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 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