2371 Commits

Author SHA1 Message Date
Denys Vlasenko
c169d94718 PTRACE_SEIZE can set ptrace options immediately, use this feature
This eliminates some rare bugs, such as post-execve SIGTRAP
generation when we attach to a process, and it manages to finish
execve'ing before we set TRACEEXEC option to suppress that.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
2013-07-10 14:36:28 +02:00
Denys Vlasenko
7c41ce2878 If -o|logger is in use, exit trace loop if nprocs == 0.
Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
2013-07-08 13:55:04 +02:00
Denys Vlasenko
d2e1f42d8a Exit trace loop if got ECHILD, not if nprocs == 0.
Comment gives a testcase which wasn't handled correctly
by the old code.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
2013-07-08 11:28:27 +02:00
Denys Vlasenko
f5730e9614 s390[x]: get rid of syscall_mode, delete code which never triggers
Before this change, the logic was as follows:
syscall entry:
  get_scno:
    syscall_mode = GPR2
    scno = syscall_mode unless syscall_mode == -ENOSYS
    (if -ENOSYS, scn is retrieved by decoding current insn)
  fixup:
    gpr2 = GPR2
    syscall_mode = scno unless syscall_mode == -ENOSYS
    if (gpr2 != syscall_mode) stray_entry
syscall exit:
  get_res:
    gpr2 = GRP2
  fixup:
    syscall_mode = scno unless syscall_mode == -ENOSYS
    if (WAITEXECVE && gpr2 in (-ENOSYS, scno)) gpr2 = 0;
  get_error:
    gpr2 is retval

Entry fixup's if() can never trigger:
regardless whether GPR2 is -ENOSYS or not, syscall_mode is always
equal to GRP2 value there. So it can be removed.

On sysexit path, syscall mode is never used.

Therefore, syscall_mode variable is deleted. grp2 is read from
GPR2 register in get_scno, redundant read in entry fixup is removed.
As a result, entry fixup's s390 code block vanishes completely.

gpr2 variable is renamed s390_gpr2 to match the convention used
by other arches.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
2013-07-07 12:56:42 +02:00
Denys Vlasenko
8b7aa2b35d ARM: add STRACE_KNOWS_ONLY_EABI define which can be used to omit OABI support
Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
2013-07-04 09:54:19 +02:00
Denys Vlasenko
6162a3f34f Add paranoia check before passing a long to pid2tcb(int pid)
Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
2013-07-04 09:26:24 +02:00
Denys Vlasenko
38eab5d6ea In debug output, show waitpid status with 6 hex digits, not 4
This shows event byte values better (without variable offset):

 [wait(0x01057f) = 29491] WIFSTOPPED,sig=SIGTRAP,EVENT_FORK (1)
 [wait(0x80057f) = 29492] WIFSTOPPED,sig=SIGTRAP,EVENT_STOP (128)
         ^^

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
2013-07-02 12:18:22 +02:00
Denys Vlasenko
519af5ad34 Replace suspicious popen_pid assignment with an obviously correct one
popen_pid = vfork() does work correctly, but for a subtle reason
that wrong assignment of 0 happens in the child _first_,
and _then_ correct value overwrites it in the parent.

(And in a hyphothetical system where vfork = fork,
popen_pid wouldn't be shared, so it will also be ok.)

However, it's not necessary to be difficult.
This change makes it so that assignment is done only in parent.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
2013-07-02 11:31:24 +02:00
Denys Vlasenko
d0ffdf494a Convert trace() from returning int to returning void
The cleanup sequence in error cases, and on normal code path
was nearly the same, no point in duplicating it.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
2013-07-01 13:02:33 +02:00
Denys Vlasenko
5a2483ba25 Remove ia64-specific printing of current address on signal delivery
The address is printed anyway by printleader() if -i is active.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
2013-07-01 12:49:14 +02:00
Denys Vlasenko
c09646aa9e Rename ia32 to ia64_ia32mode, and make it bool, not long
Grepping for just ia32 was turning up many false positives.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
2013-07-01 12:28:17 +02:00
Denys Vlasenko
4793221a53 Fold is_restart_error() into its sole user
Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
2013-06-30 23:53:49 +02:00
Denys Vlasenko
254b5a7a97 Update qemu_multiarch_testing/README
Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
2013-06-29 14:34:48 +02:00
Denys Vlasenko
d083016e03 sys_clone: add a comment about CLONE_PTRACE and CLONE_UNTRACED
No code changes.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
2013-06-28 18:57:27 +02:00
Denys Vlasenko
44a6d04e5e POWERPC: get rid of "static long ppc_result"
Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
2013-06-28 16:47:38 +02:00
Denys Vlasenko
6b3016e435 POWERPC: read ppc_regs.nip if -i
Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
2013-06-28 14:51:50 +02:00
Denys Vlasenko
7eb893236c POWERPC: if GETREGS fails with EIO, don't try it again
Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
2013-06-28 14:41:30 +02:00
Denys Vlasenko
7f5a132c81 Get rid of powerpc_getreg(), it's a copy of upeek()
Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
2013-06-28 14:36:39 +02:00
Denys Vlasenko
752e5a02e6 Change upeek() to take pid, not full tcp.
This will be used by next change.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
2013-06-28 14:35:47 +02:00
Anton Blanchard
14d51a6423 powerpc: Provide a fallback for old kernels without PTRACE_GETREGS
PTRACE_GETREGS was added to the ppc kernel in 2.6.23. In order to
provide backward compatibility for very old kernels, add a manual
fallback.

* syscall.c (powerpc_getreg, powerpc_getregs_old): New functions.
(get_regs): Call powerpc_getregs_old if PTRACE_GETREGS is not supported.

Signed-off-by: Anton Blanchard <anton@samba.org>
Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
2013-06-26 15:57:29 +02:00
Anton Blanchard
ce6e33be1d powerpc: Use PTRACE_GETREGS to fetch all registers
* defs.h: declare ppc_regs and get_regs_error.
* signal.c (sys_sigreturn): Use ppc_regs instead of upeek.
* syscall.c: define ppc_regs.
(printcall): Use ppc_regs instead of upeek.
(get_scno): Replace multiple upeek calls with one PTRACE_GETREGS call.
(get_syscall_result): Likewise.

Signed-off-by: Anton Blanchard <anton@samba.org>
Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
2013-06-26 15:56:53 +02:00
Denys Vlasenko
711b17c44b Another manpage tweak
Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
2013-06-26 15:40:13 +02:00
Denys Vlasenko
b5370530d5 Manpage update
Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
2013-06-26 15:35:16 +02:00
Denys Vlasenko
aeb6e30493 Update build_static_example.sh
Now it also contains a tested example of i686 build on 64-bit host.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
2013-06-26 15:07:23 +02:00
Denys Vlasenko
c8511f07ab In -f mode, do not assume that new pid is stopped - handle exits too
Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
2013-06-26 14:58:03 +02:00
Denys Vlasenko
e8681c926c Set strace_child only in the right branch
"strace_child = pid" assignment was racing in NOMMU case
because of vfork (no way to know which process would win).

After this change, strace_child is set to nonzero only
in one process after [v]fork.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
2013-06-26 14:58:03 +02:00
Denys Vlasenko
fadbf6679c Get rid of TCB_INUSE and TCB_STRACE_CHILD
We can use tcb::pid == 0 as an indicator of free tcb,
and we already have strace_child variable which holds
pid of our child, if any.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
2013-06-26 14:58:03 +02:00
Denys Vlasenko
1b2bfbc825 Fix debug output of wait4 result (was reusing buf[] on unknown events)
Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
2013-06-21 16:41:50 +02:00
Denys Vlasenko
4e020c0f4b Show PTRACE_EVENT_STOP correctly in debug output
Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
2013-06-21 16:33:56 +02:00
Denys Vlasenko
71d3d29a9d Panic a bit less when we see an unknown pid
I stumbeld over this case when I used "exec stace ...".

* strace.c (trace): Do not exit if we see an unknown pid in wait4.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
2013-06-21 16:19:46 +02:00
Denys Vlasenko
e2567d54dd detach(): Reorganize code. Logic is the same.
* strace.c (detach): Use goto's instead of excessive nesting.
Drop sigstop_expected and interrupt_done variables.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
2013-06-21 16:11:10 +02:00
Denys Vlasenko
a2de9dacec Eat pending SIGSTOP _before_ PTRACE_DETACH in detach()
* strace.c (detach): If TCB_IGNORE_ONE_SIGSTOP is set,
di not PTRACE_DETACH - wait for SIGSTOP first.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
2013-06-21 15:50:41 +02:00
Denys Vlasenko
fdfa47af7e detach(): warn if we see ECHILD from waitpid
* strace.c (detach): Warn if we see ECHILD from waitpid.
Explain in comments that we don't normally expect !WIFSTOPPED
either, and also that PTRACE_CONT failure isn't expected
(the "break" there is a "I'm confused, bailing out" code style)..

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
2013-06-20 15:34:12 +02:00
Denys Vlasenko
4a9ba989e6 Improve error messages in detach()
* strace.c (detach): Change return type from int to void.
Improve error meesages: show PID, tell exactly which operation fails.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
2013-06-20 11:23:00 +02:00
Denys Vlasenko
725dd425a6 Remove workarounds for ancient kernels lacking __WALL
__WALL is available and working at least since 2.4 kernels: 10 years ago.

* strace (detach): Remove workarounds for ancient kernels lacking __WALL.
Add missing EINTR check.
(trace): Remove workarounds for ancient kernels lacking __WALL.
Remove redundant double error printout.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
2013-06-20 11:23:00 +02:00
Denys Vlasenko
69e27ef244 USE_SEIZE: fix detaching from stopped processes
V3: split SEIZE/!SEIZE code paths to reduce confusion.
Extensively comment every possible case.
Verified that all tests/detach* tests work in both SEIZE and !SEIZE
cases.

* strace.c (detach): If PTRACE_SEIZE API is in use, stop the tracee
using PTRACE_INTERRUPT instead of sending it a SIGSTOP.
In a subsequent waitpid loop, correctly wait and suppress SIGSTOP
on detach if PTRACE_INTERRUPT wasn't used, or wait for any ptrace
stop and detach without suppressing signals.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
2013-06-20 11:23:00 +02:00
0d7c3653c5 tests: disable /proc based checks when /proc is not mounted
* tests/detach-running: Disable /proc based checks when
/proc/self/status is not available.
* tests/detach-sleeping: Likewise.
* tests/detach-stopped: Likewise.
2013-06-19 14:57:05 +00:00
Denys Vlasenko
a815185d55 tests/detach-{running,sleeping,stopped}: check post-detach state
Check that traced process still exists and is in a right state
after strace detached from it.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
2013-06-19 16:37:24 +02:00
78460f8bb2 tests: ensure that strace can detach from running processes
* tests/detach-running: New test.
* tests/Makefile.am (TESTS): Add it.
2013-06-19 10:22:18 +00:00
223e9a6f85 tests: ensure that strace does not leave sleeping processes stopped
* tests/detach-sleeping: Do not send SIGCONT to the sleeping process.
2013-06-19 01:05:30 +00:00
3cb7a0cd00 tests: fix parallel-tests support in detach-* tests
* tests/detach-sleeping: Use $LOG file for set_ptracer_any output.
* tests/detach-stopped: Likewise.
2013-06-18 22:37:08 +00:00
1e0a28063f tests: parametrize "sleep 1"
* tests/init.sh (SLEEP_A_BIT): New variable.
* tests/detach-sleeping: Use it.
* tests/detach-stopped: Likewise.
2013-06-18 20:51:49 +00:00
97c85088a2 tests: ensure that strace can detach from sleeping and stopped processes
* tests/set_ptracer_any.c: New file.
* tests/detach-sleeping: New test.
* tests/detach-stopped: Likewise.
* tests/Makefile.am (check_PROGRAMS): Add set_ptracer_any.
(TESTS): Add detach-sleeping and detach-stopped.
* tests/.gitignore: Add set_ptracer_any.
2013-06-18 17:07:48 +00:00
f60347d857 tests: enhance timeout checks
Run each test using a wrapper that does all necessary timeout checks.

* tests/run.sh: New file.
* tests/Makefile.am (EXTRA_DIST, LOG_COMPILER): Add it.
* tests/init.sh (check_strace, check_timeout): Remove.
* tests/detach-stopped: Update callers.
* tests/net: Likewise.
* tests/ptrace_setoptions: Likewise.
* tests/qual_syscall: Likewise.
* tests/stat: Likewise.
* tests/strace-f: Likewise.
2013-06-18 17:07:37 +00:00
3cf90b64ae tests: enable parallel-tests support
* configure.ac (AM_INIT_AUTOMAKE): Add parallel-tests.
2013-06-18 16:58:29 +00:00
107ceb935f tests: prepare for parallel-tests support
* tests/Makefile.am (CLEANFILES): Calculate dynamically from TESTS.
* tests/init.sh (LOG): New variable.
* tests/detach-stopped: Use it.
* tests/net: Likewise.
* tests/qual_syscall: Likewise.
* tests/stat: Likewise.
* tests/strace-f: Likewise.
2013-06-18 16:58:02 +00:00
Denys Vlasenko
f1669e7975 Cleanups. No logic changes.
* defs.h: Define new ptrace constants unconditionally.
* strace.c (detach): Fix comment.
(trace): Remove now unnecessary "if USE_SEIZE".

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
2013-06-18 18:15:51 +02:00
02d2c708de maint: post-release administrivia
* NEWS: Add header line for next release.
2013-06-05 21:33:45 +00:00
1cd3f5f844 ioctlent: add UAPI support
* Makefile.am (IOCTLSORT_INCLUDEDIR): Define.
(ioctlsort): Use it.
* linux/ioctlent.sh (lookup_ioctls): Look into uapi directory tree.
Strip "uapi/" prefix from output path names.
* linux/ioctlent.h.in: Regenerate from v3.9 headers.
* NEWS: Mention it.
v4.8
2013-06-03 16:24:53 +00:00
d845411e8c Prepare for 4.8 release
* NEWS: Update for 4.8 release.
* debian/changelog: 4.8-1.
* strace.spec: 4.8-1.
2013-06-03 12:34:56 +00:00