From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 109860 invoked by alias); 23 Nov 2015 18:42:10 -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 109851 invoked by uid 89); 23 Nov 2015 18:42:09 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.2 required=5.0 tests=AWL,BAYES_00,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=ham version=3.3.2 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 (AES256-GCM-SHA384 encrypted) ESMTPS; Mon, 23 Nov 2015 18:42:04 +0000 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (Postfix) with ESMTPS id 9F8128F03D; Mon, 23 Nov 2015 18:42:03 +0000 (UTC) Received: from [127.0.0.1] (ovpn01.gateway.prod.ext.ams2.redhat.com [10.39.146.11]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id tANIg2DN013047; Mon, 23 Nov 2015 13:42:02 -0500 Message-ID: <56535DF9.4010408@redhat.com> Date: Mon, 23 Nov 2015 18:42:00 -0000 From: Pedro Alves User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 MIME-Version: 1.0 To: Yao Qi CC: gdb-patches@sourceware.org Subject: Re: [PATCH 03/18] attach + target always in non-stop mode: stop all threads References: <1444836486-25679-1-git-send-email-palves@redhat.com> <1444836486-25679-4-git-send-email-palves@redhat.com> <86r3ki0vzy.fsf@gmail.com> <565357B1.4070805@redhat.com> In-Reply-To: <565357B1.4070805@redhat.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-SW-Source: 2015-11/txt/msg00493.txt.bz2 On 11/23/2015 06:15 PM, Pedro Alves wrote: > On 10/26/2015 10:22 AM, Yao Qi wrote: >> Pedro Alves writes: >> >>> In addition, it's not defined whith thread manages to report the >> >> s/whith/which >> >>> initial attach stop, so always pick the lowest one (otherwise >>> multi-attach.exp regresses). >> >> Shouldn't GDB pick the main thread rather than the lowest one? > > It actually ends up being the same, and bit more generic to go with > lowest, because target_attach should always adds the main thread first. > Otherwise, there's no such concept of "main" thread in the common code. > "The thread with pid == lwpid" holds true for NTPL/Linux, but not everywhere, > and even then the leader thread may have exited already. I'll update > the comment. > Like so? Subject: [PATCH] attach + target always in non-stop mode: stop all threads When running with "maint set target-non-stop on", and in all-stop mode, nothing is stopping all threads after attaching. vAttach in non-stop can leave all threads running and GDB has to explicitly pause them. This is not visible with the native target, as in that case, attach always stops all threads (the core re-resumes them in case of "attach&"). In addition, it's not defined which thread manages to report the initial attach stop, so always pick the lowest one (otherwise multi-attach.exp regresses). gdb/ChangeLog: 2015-11-23 Pedro Alves * infcmd.c (attach_post_wait): If the target is always in non-stop mode, and the UI is in all-stop mode, stop all threads and pick the one with lowest number as current. --- gdb/infcmd.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/gdb/infcmd.c b/gdb/infcmd.c index 9aae860..e481feb 100644 --- a/gdb/infcmd.c +++ b/gdb/infcmd.c @@ -2697,8 +2697,31 @@ attach_post_wait (char *args, int from_tty, enum attach_post_wait_mode mode) selected thread is stopped, others may still be executing. Be sure to explicitly stop all threads of the process. This should have no effect on already stopped threads. */ - if (target_is_non_stop_p ()) + if (non_stop) target_stop (pid_to_ptid (inferior->pid)); + else if (target_is_non_stop_p ()) + { + struct thread_info *thread; + struct thread_info *lowest = inferior_thread (); + int pid = current_inferior ()->pid; + + stop_all_threads (); + + /* It's not defined which thread will report the attach + stop. For consistency, always select the thread with + lowest number, which should be the main thread, if it + still exists. */ + ALL_NON_EXITED_THREADS (thread) + { + if (ptid_get_pid (thread->ptid) == pid) + { + if (thread->num < lowest->num) + lowest = thread; + } + } + + switch_to_thread (lowest->ptid); + } /* Tell the user/frontend where we're stopped. */ normal_stop (); -- 1.9.3