Dmitry V. Levin [Tue, 13 Dec 2016 19:59:47 +0000 (19:59 +0000)]
tests: workaround a bug in GNU grep
Workaround a bug introduced in GNU grep 2.27, for details see
https://lists.gnu.org/archive/html/bug-grep/2016-12/msg00011.html
* tests/init.sh (grep_pid_status): New function.
* tests/detach-running.test: Use it instead of grep to search
in /proc/$pid/status.
* tests/detach-sleeping.test: Likewise.
* tests/detach-stopped.test: Likewise.
Sean Stangl [Thu, 8 Dec 2016 19:54:24 +0000 (09:54 -1000)]
Fix libunwind segfault when -p is passed before -k
* strace.c (init) [USE_LIBUNWIND]: Call unwind_tcb_init after
unwind_init for all allocated tcb structures if stack trace is enabled.
* unwind.c (unwind_tcb_init): Skip if tcb is already initialized.
Co-authored-by: Dmitry V. Levin <ldv@altlinux.org>
Dmitry V. Levin [Wed, 7 Dec 2016 16:57:42 +0000 (16:57 +0000)]
tests: skip fault injection tests on unsupported platforms
* tests/fault_injection.sh: New file.
* tests/Makefile.am (EXTRA_DIST): Add it.
* tests/fault_injection-exit_group.test: Use it.
* tests/fault_injection.test: Likewise.
Dmitry V. Levin [Wed, 7 Dec 2016 18:05:28 +0000 (18:05 +0000)]
tests: introduce require_min_kernel_version_or_skip function
* tests/init.sh (kernel_version_code,
require_min_kernel_version_or_skip): New functions.
* tests/threads-execve.test: Use require_min_kernel_version_or_skip.
Makefile.am: don't confuse CFLAGS and CFLAGS_FOR_BUILD
Commit dc427d50d96b15c9a64d7e78d97ce4d194622a63 enabled a number of extra
warning flags through configure.ac. The configure script will determine
dynamically if CC supports these flags before adding them to WARN_CFLAGS.
ioctlsort is compiled with CC_FOR_BUILD, rather than CC. Nevertheless,
the flags passed to this compilation also include WARN_CFLAGS (through
AM_CFLAGS). This is incorrect: in a cross-compilation use case, CC
and CC_FOR_BUILD are not the same. The former is the cross-compiler,
the latter is the host compiler. Both may be of different versions
and support different warning flags.
In particular, this posed a problem when cross-compiling with a host
compiler gcc 4.1, which does not support all the new flags:
* Makefile.am (AM_CFLAGS_FOR_BUILD, AM_CPPFLAGS_FOR_BUILD): New
variables.
(ioctlsort_CPPFLAGS): Use AM_CPPFLAGS_FOR_BUILD instead of AM_CPPFLAGS.
(ioctlsort_CFLAGS): Use AM_CFLAGS_FOR_BUILD instead of AM_CFLAGS.
(ioctlsort_LDFLAGS): Use AM_LDFLAGS_FOR_BUILD instead of AM_LDFLAGS.
* m4/ax_prog_cc_for_build.m4 (AX_PROG_CC_FOR_BUILD): Redirect
WARN_CFLAGS and gl_unknown_warnings_are_errors, call st_WARN_CFLAGS,
substitute WARN_CFLAGS_FOR_BUILD.
Signed-off-by: Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
Dmitry V. Levin [Wed, 7 Dec 2016 01:08:44 +0000 (01:08 +0000)]
m4: prepare gl_WARN_ADD for simultaneous use of multiple compilers
* m4/warnings.m4 (gl_COMPILER_OPTION_IF): Change gl_Flags to use
_AC_LANG_PREFIX[]FLAGS in unquoted form. Change gl_Warn to use gl_Flags
instead of _AC_LANG_ABBREV. Change notification message to mention
the variable name of the compiler.
(gl_UNKNOWN_WARNINGS_ARE_ERRORS): Do nothing if
gl_unknown_warnings_are_errors is set.
(gl_WARN_ADD): Change the use of gl_UNKNOWN_WARNINGS_ARE_ERRORS from
AC_REQUIRE to a regular call.
Dmitry V. Levin [Wed, 7 Dec 2016 00:59:12 +0000 (00:59 +0000)]
AX_PROG_CC_FOR_BUILD: redirect more variables related to C compiler
Some of these variables cannot be redirected using traditional
pushdef/popdef mechanism because of complex constructions like
[ac_cv_[]_AC_LANG_ABBREV[]_compiler_gnu] employed by autoconf macros.
Use st_SAVE_VAR/st_RESTORE_VAR to workaround this issue.
* m4/ax_prog_cc_for_build.m4: Redirect ac_cv_prog_cc_stdc,
ac_cv_prog_cc_c11, ac_cv_prog_cc_c99, ac_cv_prog_cc_c89,
am_cv_prog_cc_c_o, and am_cv_CC_dependencies_compiler_type using
pushdef/popdef.
Redirect ac_c_decl_warn_flag, ac_c_preproc_warn_flag, ac_c_werror_flag,
ac_compile, ac_compiler_gnu, ac_cpp, ac_cv_c_compiler_gnu,
ac_cv_c_decl_report, and ac_link using st_SAVE_VAR/st_RESTORE_VAR.
Dmitry V. Levin [Tue, 6 Dec 2016 08:55:41 +0000 (08:55 +0000)]
tests: fix expected output in strace-ttt.test
If strace -ttt is running too long, it might happen that time stamps
before and after its invocation differ for more than a second.
Adjust expected output to handle this rare but possible case.
* tests/strace-ttt.test: Allow any time stamp between start and finish
of strace invocation.
Dmitry V. Levin [Tue, 6 Dec 2016 08:50:31 +0000 (08:50 +0000)]
tests: fix expected output in strace-tt.test
If strace -tt is running too long, it might happen that time stamps
before and after its invocation differ for more than a second.
Adjust expected output to handle this rare but possible case.
* tests/strace-tt.test: Allow any time stamp between start and finish
of strace invocation.
Dmitry V. Levin [Tue, 6 Dec 2016 01:54:13 +0000 (01:54 +0000)]
tests: robustify attach-f-p.test against race conditions
Introduce a synchronization mechanism between attach-f-p and strace.
* tests/attach-f-p-cmd.c: New file.
* tests/Makefile.am (check_PROGRAMS): Add attach-f-p-cmd.
* tests/attach-f-p.c: Include <sys/stat.h>.
(main): Write to stdout instead of descriptor 3. Wait for the peer
writing to stdout.
* tests/attach-f-p.test: Assume that ./attach-f-p-cmd works.
Use $OUT for expected output. Use attach-f-p-cmd for unlocking $OUT.
Dmitry V. Levin [Tue, 6 Dec 2016 00:32:06 +0000 (00:32 +0000)]
tests: robustify attach-p-cmd.test against race conditions
Introduce a synchronization mechanism between attach-p-cmd-p
and attach-p-cmd-cmd processes.
* tests/attach-p-cmd-cmd.c: Include <errno.h> and <sys/stat.h>.
(main): Wait for the lock directory creation by attach-p-cmd-p.
* tests/attach-p-cmd-p.c: Include <errno.h> and <sys/stat.h>.
(main): Create a lock directory and wait for its removal
by attach-p-cmd-cmd.
* tests/attach-p-cmd.test: Assume that test programs work.
Dmitry V. Levin [Sat, 3 Dec 2016 22:37:19 +0000 (22:37 +0000)]
Rewrite qual_signal using bit sets
* defs.h (signal_set): New variable prototypes.
(qualify_signals): New function prototypes.
(QUAL_SIGNAL): Change to a value greater than 0xff.
(QUAL_FAULT): Change to a lower value.
* qualify.c (signal_set): New variable.
(sigstr_to_uint, qualify_signals): New functions.
* syscall.c (qual_signal): Remove.
(qual_options): Replace qual_signal with NULL.
(qualify): Use qualify_signals.
* strace.c (print_signalled, print_stopped): Use is_number_in_set
with signal_set argument.
Dmitry V. Levin [Fri, 2 Dec 2016 22:16:40 +0000 (22:16 +0000)]
Rewrite qual_desc using bit sets
As a side effect, this also fixes support of negated sets
of descriptors.
* defs.h (struct number_set): New forward declaration.
(read_set, write_set): New variable prototypes.
(is_number_in_set, qualify_read, qualify_write): New function
prototypes.
(QUAL_READ, QUAL_WRITE): Change to values greater than 0xff.
* qualify.c: New file.
* Makefile.am (strace_SOURCES): Add it.
* syscall.c (qual_desc): Remove.
(qual_options): Replace qual_desc with NULL.
(qualify): Use qualify_read and qualify_write.
(dumpio): Use is_number_in_set.
* tests/options-syntax.test: Check invalid sets of descriptors.
* tests/readv.test: Check dumping of negated sets of descriptors.
Dmitry V. Levin [Mon, 5 Dec 2016 10:34:33 +0000 (10:34 +0000)]
tests: skip redirect-fds.test when strace is wrapped with valgrind
valgrind is not as transparent as strace wrt standard descriptors,
so if strace is wrapped with valgrind, the test would check valgrind
transparency properties and fail imminently.
* tests/redirect-fds.test: Skip the test when $STRACE shows a presence
of valgrind.
Dmitry V. Levin [Mon, 5 Dec 2016 00:58:36 +0000 (00:58 +0000)]
tests: make options-syntax.test tolerant of strace wrappers
Change the test to allow wrappers like STRACE="valgrind ./strace".
* tests/options-syntax.test: Strip all words but last from $STRACE
variable in all contexts where the name of strace executable is expected
in its output.
* uid.c (setfsuid, get_print_uid, print_gid): Use printuid.
* tests/setfsugid.c (printuid): New function.
(main): Use it to print UID/GID values.
* tests/setgroups.c: Likewise.
* tests/setugid.c (ugid2int): Remove.
(printuid): New function.
(main): Use it to print UID/GID values.
The string literal "__NR_syscall_4294967295" is semantically incorrect
as there is no such constant defined.
* syscall.c (syscall_name): Return NULL if there is no syscall
corresponding to the given number.
* defs.h (syscall_name): Document this behaviour.
* printsiginfo.c (print_si_info): Print syscall name with "__NR_" prefix
only if there is a syscall corresponding to si_syscall number; print
a plain syscall number otherwise.
* tests/ptrace.c (main): Update expected output.
* print_statfs.c: Print f_fsid as a structure containing field "val"
which, in turn, is an array of two elements that used to be printed
as members of f_fsid structure.
* tests/statfs.expected: Update expected output.
* tests/xstatfsx.c (print_statfs): Likewise.
* swapon.c (SYS_FUNC(swapon)): Do not check for non-zero the value
of the prio variable in order to print it.
* tests/swap.c (main): Update expected output.
Dmitry V. Levin [Tue, 29 Nov 2016 22:56:49 +0000 (22:56 +0000)]
Fix dumping of io syscalls when descriptor argument has unused bits set
* syscall.c (dumpio): Explicitly cast the first argument of syscall
to "int", the same way as the kernel does.
* tests/read-write.c: Include <asm/unistd.h> and "kernel_types.h".
(k_read, k_write): New functions.
(test_dump, main): Use them.
Dmitry V. Levin [Tue, 29 Nov 2016 19:51:15 +0000 (19:51 +0000)]
x32: fix preadv2-pwritev2.test
* tests/preadv2-pwritev2.c: Include "kernel_types.h".
(main): Use kernel_ulong_t instead of unsigned long as types
of arguments of preadv2 and pwritev2 syscalls.
Elvira Khabirova [Sat, 13 Aug 2016 17:27:38 +0000 (20:27 +0300)]
Make date output format conform to ISO 8601
* util.c (sprinttime): Make date output conform to ISO 8601.
* tests/utime.c (print_tm): Update expected output.
* tests/xstatx.c (print_time): Likewise.
Dmitry V. Levin [Tue, 29 Nov 2016 02:11:48 +0000 (02:11 +0000)]
Fix meaning of negated sets in fault expressions
Change the parser of fault expression to follow the POLA:
-e fault=!SET
means that all syscalls except those from SET are subject to fault
injection;
-e fault=!SET1:error=ERRNO1, -e fault=!SET2:error=ERRNO2
means that all syscalls except those from SET2 are subject to fault
injection with error code ERRNO2, and all syscalls from SET2 that are
not in SET1 are subject to fault injection with error code ERRNO1.
* syscall.c (qualify_scno, qualify_syscall_class, qualify_syscall_name):
Handle negated QUAL_FAULT case differently.
* tests/fault_syntax.test: Add checks of negated sets.
utime: fix omission of field names in utimbuf structure printing
* utime.c (SYS_FUNC(utime)): Print struct utimbuf as a structure,
not as an array (use curly brackets instead of square ones).
Add field names to the output.
* tests/utime.c (main): Update expected output.
util: provide information whether xlat value has been found
This is necessary for the upcoming change in the output format
of the val3 argument of the FUTEX_WAKE_OP futex command.
* defs.h (printxvals, printxval_searchn): Change return type to int.
(printxval64, printxval, printxval_long): Likewise. Forward the value
returned by printxvals call.
* util.c (printxvals, printxval_searchn): Change return type to int,
return 1 if xlat value has been found, 0 otherwise.
Dmitry V. Levin [Mon, 28 Nov 2016 19:46:50 +0000 (19:46 +0000)]
aarch64, arm, sparc: add comments on fault injection support in kernel
* linux/aarch64/set_scno.c: Note the kernel commit that introduced
NT_ARM_SYSTEM_CALL support.
* linux/arm/set_scno.c: Note the kernel commit that introduced
PTRACE_SET_SYSCALL support.
* linux/sparc/set_scno.c: Note the kernel commit that introduced
reloading from the syscall number register.
Dmitry V. Levin [Mon, 28 Nov 2016 15:03:08 +0000 (15:03 +0000)]
Fix -r option syntax
While -r option implies -t, it should not literally have the effect
of -t option, e.g. -rr should not increment tflag twice.
* strace.c (init): In the getopt loop, do not increment tflag for each
occurrence of -r option. After the getopt loop, if rflag is set, set
tflag to 1. Issue a warning that -tt has no effect with -r.
* print_timeval.c (print_timeval_item): New function.
(print_timeval_pair): Use it as a print_function in print_array call.
* tests/futimesat.c (main): Update to test new behaviour.
* tests/utimes.c (main): Likewise.
Dmitry V. Levin [Mon, 28 Nov 2016 04:21:11 +0000 (04:21 +0000)]
alpha: print struct timeval32 consistently
* defs.h [ALPHA] (timeval32_t): New type.
[ALPHA] (print_timeval32_t): New prototype.
* print_timeval.c [ALPHA] (timeval32_t): Remove.
[ALPHA] (print_timeval32_t): Remove static keyword.
* printrusage.c [ALPHA] (printrusage32): Use timeval32_t instead
of local definition of struct timeval32. Use print_timeval32_t.
Dmitry V. Levin [Mon, 28 Nov 2016 02:45:13 +0000 (02:45 +0000)]
Split print_time.c
After commit v4.14-136-g151d1d1 that removed the last object common
for timespec and timeval parsers there is no need to keep them all
in a single file.
* print_timespec.c: New file.
* print_timeval.c: Likewise.
* Makefile.am (strace_SOURCES): Add them.
* print_time.c: Move all timespec related code to print_timespec.c.
Move all timeval related code to print_timeval.c.
Dmitry V. Levin [Sat, 26 Nov 2016 23:45:05 +0000 (23:45 +0000)]
Set PTRACE_O_TRACEEXIT option and handle PTRACE_EVENT_EXIT events
Do not assume that some syscalls do not generate syscall-exit-stops.
When syscalls fail for any reason they may generate syscall-exit-stops.
The solution is to wait for an actual exit reported by PTRACE_EVENT_EXIT
and print the end of unfinished exiting syscall properly.
* exit.c: Remove.
* Makefile.am (strace_SOURCES): Remove exit.c.
* linux/dummy.h (sys_exit): Alias to printargs_d.
* strace.c (ptrace_setoptions): Add PTRACE_O_TRACEEXIT bit.
(print_event_exit): New function.
(trace): Use it in case of PTRACE_EVENT_EXIT.
* syscall.c (trace_syscall_entering): Remove special handling
of SEN_exit.
Dmitry V. Levin [Sun, 27 Nov 2016 14:19:09 +0000 (14:19 +0000)]
Change printargs to return RVAL_DECODED
As printargs is invoked as a generic syscall decoder only and
it is not supposed to print anything on exiting, change printargs
to return RVAL_DECODED so it would not be called on exiting at all.
Dmitry V. Levin [Sat, 26 Nov 2016 18:08:01 +0000 (18:08 +0000)]
Move two global flags to tracee scope
A simultaneous use of -p option and tracing of a command available
since commit v4.11-183-gfa8c286 introduces a race condition because
the flags whether the first exec has happened are global.
Fix the race by moving hide_log_until_execve and hide_log_until_execve
global variables to TCB_HIDE_LOG and TCB_SKIP_DETACH_ON_FIRST_EXEC bits
in struct tcb.flags, correspondingly.
* defs.h (TCB_HIDE_LOG, TCB_SKIP_DETACH_ON_FIRST_EXEC, hide_log):
New macros.
(hide_log_until_execve): Remove prototype.
* strace.c (skip_one_b_execve, hide_log_until_execve): Remove.
(startup_child): Set TCB_HIDE_LOG and TCB_SKIP_DETACH_ON_FIRST_EXEC bits
in the allocated tcb structure.
(init): Remove initialization of hide_log_until_execve and
skip_one_b_execve.
(print_stopped): Use hide_log() instead of hide_log_until_execve.
(trace): Check and clear TCB_SKIP_DETACH_ON_FIRST_EXEC flag instead
of skip_one_b_execve.
* syscall.c (trace_syscall_entering): Clear TCB_HIDE_LOG flag instead of
hide_log_until_execve.
(trace_syscall_entering, trace_syscall_exiting): Check hide_log()
instead of hide_log_until_execve.
Dmitry V. Levin [Fri, 25 Nov 2016 23:47:32 +0000 (23:47 +0000)]
Change parser of fault expressions to conform the documentation
Make expressions like fault=SYSCALL1,SYSCALL2:error=EPERM work
as documented, i.e. fail both SYSCALL1 and SYSCALL2 with EPERM.
* syscall.c (parse_fault_expression): Remove const qualifier from
"name" and "token: variables, as well as from the return value.
(qual_fault): Remove const qualifier from "name" variables.
Split "name" into comma delimited tokens and pass each token
to individual qual_syscall_ex call.
(qualify): For QUAL_FAULT options, pass the whole option value
to their qualify methods without prior splitting into comma
delimited tokens.
* tests/fault_injection.test: Check it.
* tests/fault_syntax.test: Check empty syscall sets.
Dmitry V. Levin [Tue, 22 Nov 2016 00:20:49 +0000 (00:20 +0000)]
maint: add more workarounds for alpha and powerpc
* maint/ioctls_sym.sh: Skip asm/core_*.h. Filter out from
asm-generic/ioctls.h those macros that are defined using unavailable
struct termios2 on alpha and powerpc.
Dmitry V. Levin [Mon, 21 Nov 2016 16:08:08 +0000 (16:08 +0000)]
maint: rework workarounds for linux/kvm.h
* maint/ioctls_sym.sh: Remove pre-include linux/kvm.h workarounds.
Skip linux/kvm.h on those architectures that have no asm/kvm.h file.
Introduce post-process workarounds, add post-process workarounds
for linux/kvm.h.
The prctl syscall does not use compat on x32/n32, so argument types
are in fact kernel_ulong_t.
* prctl.c (print_prctl_args): Use getarg_ull, print as "%#llx" instead
of "%#lx".
(SYS_FUNC(prctl)): Use getarg_ull to store call arguments in arg2, arg3,
arg4, arg5 variables of type unsigned long long. Use them in printing
routines.
(SYS_FUNC(arch_prctl)): Use getarg_ull to store call argument in addr
variable of type unsigned long long. Print it as "%#llx" instead of
"%#lx".