This is the mail archive of the archer@sourceware.org mailing list for the Archer project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: ptrace improvement: PTRACE_O_INHERIT


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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]