Re: [PATCHSET RFC] ptrace,signal: clean transition between STOPPED and TRACED

Oleg Nesterov
2011-01-13T16:00:48Z

On 01/12, Jan Kratochvil wrote:
>
> FSF GDB for `T (stopped)' processes currently does:
> PTRACE_ATTACH
> check /proc/%d/status for `T (stopped)' (by GDB's pid_is_stopped)
> if found then kill (PID, SIGSTOP) && ptrace (PTRACE_CONT, PID, 0, 0).
> waitpid (pid, &status, 0) - so that this one does not get stuck if the stop
> event was already eaten out before.
>
> If the `T (stopped)' will now always FAIL then at leat the waitpid then should
> never get stuck.

I think it won't stuck. With this change the tracee always goes from
TASK_STOPPED to TASK_TRACED with the correct (and nonzero) stop code.

Btw, this should fix the case when ->exit_code was already consumed
by the previous debugger.

> FSF gdbserver --multi does PTRACE_ATTACH followed by waitpid (WNOHANG) and it
> fails if it returns ECHILD on the first try.

Not sure I understand... With or without this change waitpid()
shouldn't return ECHILD. But (again, with or without this change)
it can return 0 due to WNOHANG.

> ptrace(PTRACE_ATTACH, 22049, 0, 0) = 0
> wait4(-1, [{WIFSTOPPED(s) && WSTOPSIG(s) == SIGSTOP}], WNOHANG, NULL) = 22049
>
> It may be also a gdbserver bug, though.

I do not know if this matters or not, but just in case...

gdb shouldn't assume the tracee will report SIGSTOP after attach.
Yes, PTRACE_ATTACH sends this signal implicitly, but the tracee can
dequeue and report another pending signal before SIGSTOP.

Oleg.