From patchwork Fri Sep 6 23:28:00 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Alves X-Patchwork-Id: 34426 Received: (qmail 121046 invoked by alias); 6 Sep 2019 23:28:26 -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 120975 invoked by uid 89); 6 Sep 2019 23:28:25 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.9 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=multi-threaded, connected 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; Fri, 06 Sep 2019 23:28:24 +0000 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 42CEF195DB80 for ; Fri, 6 Sep 2019 23:28:23 +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 D31AA5D9D3 for ; Fri, 6 Sep 2019 23:28:22 +0000 (UTC) From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH 16/23] Fix reconnecting to a gdbserver already debugging multiple processes, II Date: Sat, 7 Sep 2019 00:28:00 +0100 Message-Id: <20190906232807.6191-17-palves@redhat.com> In-Reply-To: <20190906232807.6191-1-palves@redhat.com> References: <20190906232807.6191-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 16ef9dbdfd..ef6eb99999 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -4709,8 +4709,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" @@ -4722,8 +4722,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