Add experimental code to use PTRACE_SEIZE, disabled by default

All new code is predicated on "ifdef USE_SEIZE". If it is not defined,
behavior is not changed.

If USE_SEIZE is enabled and run-time check shows that PTRACE_SEIZE works, then:
- All attaching is done with PTRACE_SEIZE + PTRACE_INTERRUPT.
  This means that we no longer generate (and possibly race with) SIGSTOP.
- PTRACE_EVENT_STOP will be generated if tracee is group-stopped.
  When we detect it, we issue PTRACE_LISTEN instead of PTRACE_SYSCALL.
  This leaves tracee stopped. This fixes the inability to SIGSTOP or ^Z
  a straced process.

* defs.h: Add commented-out "define USE_SEIZE 1" and define PTRACE_SEIZE
and related constants.
* strace.c: New variable post_attach_sigstop shows whether we age going
to expect SIGSTOP on attach (IOW: are we going to use PTRACE_SEIZE).
(ptrace_attach_or_seize): New function. Uses PTRACE_ATTACH or
PTRACE_SEIZE + PTRACE_INTERRUPT to attach to given pid.
(startup_attach): Use ptrace_attach_or_seize() instead of ptrace(PTRACE_ATTACH).
(startup_child): Conditionally use alternative attach method using PTRACE_SEIZE.
(test_ptrace_setoptions_followfork): More robust parameters to PTRACE_TRACEME.
(test_ptrace_seize): New function to test whether PTRACE_SEIZE works.
(main): Call test_ptrace_seize() while initializing.
(trace): If PTRACE_EVENT_STOP is seen, restart using PTRACE_LISTEN in order
to not let tracee run.
* process.c: Decode PTRACE_SEIZE, PTRACE_INTERRUPT, PTRACE_LISTEN.
* util.c (ptrace_restart): Add "LISTEN" to a possible error message.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
diff --git a/defs.h b/defs.h
index 108b532..8bcd34e 100644
--- a/defs.h
+++ b/defs.h
@@ -383,6 +383,24 @@
 # if !HAVE_DECL_PTRACE_EVENT_EXIT
 #  define PTRACE_EVENT_EXIT	6
 # endif
+
+/* Experimental code using PTRACE_SEIZE can be enabled here: */
+//# define USE_SEIZE 1
+
+# ifdef USE_SEIZE
+#  undef PTRACE_SEIZE
+#  define PTRACE_SEIZE		0x4206
+#  undef PTRACE_INTERRUPT
+#  define PTRACE_INTERRUPT	0x4207
+#  undef PTRACE_LISTEN
+#  define PTRACE_LISTEN		0x4208
+#  undef PTRACE_SEIZE_DEVEL
+#  define PTRACE_SEIZE_DEVEL	0x80000000
+#  undef PTRACE_EVENT_STOP
+#  define PTRACE_EVENT_STOP	7
+#  define PTRACE_EVENT_STOP1	128
+# endif
+
 #endif /* LINUX */
 
 #if !defined __GNUC__