From patchwork Thu Oct 17 22:50:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Alves X-Patchwork-Id: 35115 Received: (qmail 107587 invoked by alias); 17 Oct 2019 22:50:46 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 107457 invoked by uid 89); 17 Oct 2019 22:50:45 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.0 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_HELO_PASS autolearn=ham version=3.3.1 spammy= X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 17 Oct 2019 22:50:44 +0000 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 17E993082E10 for ; Thu, 17 Oct 2019 22:50:43 +0000 (UTC) Received: from localhost.localdomain (ovpn04.gateway.prod.ext.ams2.redhat.com [10.39.146.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9C7291001B08 for ; Thu, 17 Oct 2019 22:50:42 +0000 (UTC) From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH v2 17/24] Fix reconnecting to a gdbserver already debugging multiple processes, II Date: Thu, 17 Oct 2019 23:50:19 +0100 Message-Id: <20191017225026.30496-18-palves@redhat.com> In-Reply-To: <20191017225026.30496-1-palves@redhat.com> References: <20191017225026.30496-1-palves@redhat.com> Another bug exposed by gdb.server/extended-remote-restart.exp in the multi-target work is that remote_target::start_remote can leave inferior_ptid and current_inferior() out of sync: (top-gdb) p current_inferior_->pid $1 = 29541 (top-gdb) p inferior_ptid $2 = {m_pid = 29540, m_lwp = 29540, m_tid = 0} This is caused by writing to inferior_ptid directly instead of using switch_to_thread. Also, "inferior_list->thread_list->ptid" assumes that we want the first thread of the first inferior, but that inferior may not have threads, or with multi-target, that target may be connected to some other target. gdb/ChangeLog: yyyy-mm-dd Pedro Alves * remote.c (remote_target::start_remote): Don't set inferior_ptid directly. Instead find the first thread in the thread list and use switch_to_thread. --- gdb/remote.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/gdb/remote.c b/gdb/remote.c index bc1054b192..ae8720a5f4 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -4707,8 +4707,8 @@ remote_target::start_remote (int from_tty, int extended_p) says should be current. If we're reconnecting to a multi-threaded program, this will ideally be the thread that last reported an event before GDB disconnected. */ - inferior_ptid = get_current_thread (wait_status); - if (inferior_ptid == null_ptid) + ptid_t curr_thread = get_current_thread (wait_status); + if (curr_thread == null_ptid) { /* Odd... The target was able to list threads, but not tell us which thread was current (no "thread" @@ -4720,8 +4720,14 @@ remote_target::start_remote (int from_tty, int extended_p) "warning: couldn't determine remote " "current thread; picking first in list.\n"); - inferior_ptid = inferior_list->thread_list->ptid; + for (thread_info *tp : all_non_exited_threads ()) + { + switch_to_thread (tp); + break; + } } + else + switch_to_thread (find_thread_ptid (curr_thread)); } /* init_wait_for_inferior should be called before get_offsets in order