From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 22040 invoked by alias); 12 Feb 2011 19:11:02 -0000 Mailing-List: contact archer-help@sourceware.org; run by ezmlm Sender: Precedence: bulk List-Post: List-Help: List-Subscribe: List-Id: Received: (qmail 22029 invoked by uid 22791); 12 Feb 2011 19:11:01 -0000 X-SWARE-Spam-Status: No, hits=-6.3 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_HI,SPF_HELO_PASS,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Date: Sat, 12 Feb 2011 19:11:00 -0000 From: Oleg Nesterov To: Roland McGrath Cc: Project Archer Subject: Re: ptrace improvement: PTRACE_O_INHERIT Message-ID: <20110212190253.GA31866@redhat.com> References: <20110203223905.D0C77180081@magilla.sf.frob.com> <20110210195212.GA3868@redhat.com> <20110211192423.78FFC1802A2@magilla.sf.frob.com> <20110211203755.GA5367@redhat.com> <20110212005855.E764C1814A4@magilla.sf.frob.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20110212005855.E764C1814A4@magilla.sf.frob.com> User-Agent: Mutt/1.5.18 (2008-05-17) X-SW-Source: 2011-q1/txt/msg00049.txt.bz2 On 02/11, Roland McGrath wrote: > > > > > Or. Suppose that clone() under PTRACE_O_INHERIT notifies the tracer > > > > (sends SIGCHLD), and the new tracee gets the new PTRACE_O_INHERITed > > > > mark. Then we can implement wait(W_WHO_WAS_CLONNED) which clears > > > > PTRACE_O_INHERITed and reports the new tracee (just in case, this > > > > doesn't need the stopped tracee). > > > > > > I don't really follow this idea at all, sorry. > > > > I meant, we can intoduce the new W*** flag for do_wait(). If the new > > tracee was PTRACE_O_INHERIT'ed, do_wait() returns its pid. > > I still don't understand the proposal. To simplify the explanation, suppose we add task_struct->unknown_tracee boolean. if tracehook_finish_clone()->ptrace_init_task() does __ptrace_link() because of PTRACE_O_INHERIT, it also sets child->unknown_tracee and notifies the tracee via do_notify_parent_cldstop(). Then we add WCLONNED and modify wait_consider_task(), - if (likely(!ptrace) && unlikely(task_ptrace(p))) { - /* - * This child is hidden by ptrace. - * We aren't allowed to see it now, but eventually we will. - */ - wo->notask_error = 0; - return 0; - } + if (unlikely(ptrace) { + if (unlikely(p->unknown_tracee) && (wo->wo_flags & WCLONNED)) { + // of course, this is racy + p->unknown_tracee = 0; + + // we need wait_task_ptrace_inherited(wo, p); + read_unlock(&tasklist_lock); + return p->pid; + } + + } else if (unlikely(task_ptrace(p))) { + /* + * This child is hidden by ptrace. + * We aren't allowed to see it now, but eventually we will. + */ + wo->notask_error = 0; + return 0; + } Of course this is just incomplete pseudo-code to explain what I mean. > > Well yes, but /proc/PID/task/ is not convenient and reliable. > > Especially if we do not trace all threads. > > Tracing some threads but not all is really an artifact of the ptrace > interface and not something that any real userland debugger-like thing > ever wants to do. Off-topic note: I disagree very much, but this doesn't matter. I agree that ptrace nterface should not be per-thread, and gdb always traces all threads. > But, again, we want to see what GDB really wants to use and only add that. Yes, yes, agreed. Oleg.