[PATCH 0/4] Support PTRACE_SEIZE
dvlasenk at redhat.com
Fri Sep 2 14:13:09 UTC 2011
strace has an annoying bug that ^Z on a straced program
doesn't work as intended.
Linus on at least one occasion ridiculed this.
The problem lies in ptrace API, and recently API
was updated to make it possible to handle stops correctly.
The patches are in Linux kernel git already and will be in
The API fix itself is very simple: a new restarting command,
PTRACE_LISTEN, can be used in group-stops to "restart"
tracee without clearing group-stop. We should use it instead of
PTRACE_SYSCALL when we detect group-stop.
However, PTRACE_LISTEN doesn't work unless tracee was stopped
with new attach-like command, PTRACE_SIEZE. (It's not a kernel bug, it's
by design). Thus, we need to attach using PTRACE_SIEZE now.
I don't know why kernel guys insisted on bundling SEIZE and LISTEN
functionality together, but SEIZE solves another (much less annoying)
bug with SIGSTOP races, so let's kill two birds with one stone.
PTRACE_SIEZE, unlike PTRACE_ATTACH, does not sent SIGSTOP, does not
stop the tracee, and makes auto-attached children not to stop with
SIGSTOP either - they stop with new PTRACE_EVENT_STOP.
New op PTRACE_INTERRUPT can be used to cause PTRACE_EVENT_STOP anytime
(such as: after SEIZE).
This necessitates the following:
* Test for working PTRACE_SIEZE at initialization.
* In "strace cmd args" case, we can't use PTRACE_TRACEME
(there is no SEIZEME). We need to use alternative method.
I chose the following one:
- child SIGSTOPS itself.
- strace waits for child to stop.
- strace SIEZEs and INTERRUPTs child.
- strace sends SIGCONT.
* Use SIEZE + INTERRUPT for -p PID and -D attachments too.
* Do not discard first SIGSTOP - because no stray SIGSTOPs are inserted
Patch 1: Do not set TCB_STARTUP on tcb until we performed attach.
Patch 2: Remove TCB_ATTACH_DONE - patch 1 makes it possible to use
TCB_STARTUP bit instead.
Patch 3: Split TCB_STARTUP into TCB_STARTUP and TCB_IGNORE_ONE_SIGSTOP
bits. This is required by SIEZE because with SIEZE, waiting for SIGSTOP
is not necessary, but initialization is still needed.
Patch 4: Add conditionally enabled SEIZE support.
More information about the Strace-devel