From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 124505 invoked by alias); 3 Mar 2015 15:12:55 -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 124427 invoked by uid 89); 3 Mar 2015 15:12:55 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.0 required=5.0 tests=AWL,BAYES_00,SPF_HELO_PASS,SPF_PASS,T_RP_MATCHES_RCVD 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; Tue, 03 Mar 2015 15:12:54 +0000 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t23FCphc026652 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 3 Mar 2015 10:12:52 -0500 Received: from [127.0.0.1] (ovpn01.gateway.prod.ext.ams2.redhat.com [10.39.146.11]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t23FCnSO021647; Tue, 3 Mar 2015 10:12:50 -0500 Message-ID: <54F5CF70.2090706@redhat.com> Date: Tue, 03 Mar 2015 15:12:00 -0000 From: Pedro Alves User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.3.0 MIME-Version: 1.0 To: Mark Kettenis CC: gdb-patches@sourceware.org Subject: Re: [PATCH] Linux/ptrace: don't convert ptids when asking inf-ptrace layer to resume LWP References: <201503031439.t23EdHZv020814@glazunov.sibelius.xs4all.nl> In-Reply-To: <201503031439.t23EdHZv020814@glazunov.sibelius.xs4all.nl> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit X-SW-Source: 2015-03/txt/msg00087.txt.bz2 On 03/03/2015 02:39 PM, Mark Kettenis wrote: >> From: Pedro Alves >> Date: Tue, 3 Mar 2015 13:33:44 +0000 >> >> Tested on x86-64 Fedora 20, -m32. >> >> gdb/ChangeLog: >> 2015-03-03 Pedro Alves >> >> * i386-linux-nat.c (i386_linux_resume): Get the ptrace PID out of >> the lwp field of ptid. Pass the full ptid to get_thread_regcache. >> * inf-ptrace.c (get_ptrace_pid): New function. >> (inf_ptrace_resume): Use it. >> * linux-nat.c (linux_resume_one_lwp): Pass the LWP's ptid ummodified >> to the lower layer. >> --- >> gdb/ChangeLog | 9 +++++++++ >> gdb/i386-linux-nat.c | 5 ++--- >> gdb/inf-ptrace.c | 25 ++++++++++++++++++++++--- >> gdb/linux-nat.c | 6 +----- >> 4 files changed, 34 insertions(+), 11 deletions(-) > > I have some fear this is going to break non-Linux targets. > >> --- a/gdb/inf-ptrace.c >> +++ b/gdb/inf-ptrace.c >> @@ -289,6 +289,22 @@ inf_ptrace_stop (struct target_ops *self, ptid_t ptid) >> kill (-inferior_process_group (), SIGINT); >> } >> >> +/* Return which PID to pass to ptrace in order to observe/control the >> + tracee identified by PTID. */ >> + >> +static pid_t >> +get_ptrace_pid (ptid_t ptid) >> +{ >> + pid_t pid; >> + >> + /* If we have an LWPID to work with, use it. Otherwise, we're >> + dealing with a non-threaded program/target. */ >> + pid = ptid_get_lwp (ptid); >> + if (pid == 0) >> + pid = ptid_get_pid (ptid); >> + return pid; >> +} >> + >> /* Resume execution of thread PTID, or all threads if PTID is -1. If >> STEP is nonzero, single-step it. If SIGNAL is nonzero, give it >> that signal. */ >> @@ -297,13 +313,16 @@ static void >> inf_ptrace_resume (struct target_ops *ops, >> ptid_t ptid, int step, enum gdb_signal signal) >> { >> - pid_t pid = ptid_get_pid (ptid); >> + pid_t pid; >> + >> int request; > > Please don't introduce a blank line here. Darn, LOL, I removed one, added another...: i386_linux_resume (struct target_ops *ops, ptid_t ptid, int step, enum gdb_signal signal) { - int pid = ptid_get_pid (ptid); - + int pid = ptid_get_lwp (ptid); int request; I'll remove the one I added... > >> - if (pid == -1) >> + if (ptid_equal (minus_one_ptid, ptid)) >> /* Resume all threads. Traditionally ptrace() only supports >> single-threaded processes, so simply resume the inferior. */ >> - pid = ptid_get_pid (inferior_ptid); >> + pid = get_ptrace_pid (inferior_ptid); > > This defenitely should remain ptid_get_pid(); you want to resume the > entire process and not an individual thread. My thinking is that it doesn't matter in practice. Or is it that if there are multiple kernel threads in the process, ptrace(PTRACE_CONT, PID) on bsd actually resumes them all? Then other things must be broken anyway. I was assuming that on BSD targets that use this method, there would only be one thread in the core thread list, and it would either have LWPID==0, or have PID==LWPID, thus it didn't matter if get_ptrace_pid returned the PID or the LWPID. If there anything that actually creates other threads with a different LWPID on these targets? > >> + else >> + pid = get_ptrace_pid (ptid); > > This should work for OpenBSD, and probably works for FreeBSD. It > won't work for NetBSD, but they will probably need their own > implementation of this function, so it's probably fine. > Thanks, Pedro Alves