Paul Chaignon [Mon, 1 Apr 2019 20:50:45 +0000 (22:50 +0200)]
tests: check status qualifier
This change adds 8 test cases for -e status with unfinished, failed,
none, successful, detached, and the whole set. The test cases for
failed, successful, and the whole set use chdir(2). Threaded test cases
for unfinished and none rely on a child thread execve'ing the lead
thread. There are additional single-threaded tests for status=none and
status=unfinished. The test case for detached interrupts strace while
attached to a sleeping process.
Paul Chaignon [Sat, 15 Jun 2019 05:32:03 +0000 (07:32 +0200)]
Implement -e status=set option
The status qualifier enables filtering based on the return status of
syscalls. -z and -Z become aliases for -e status=successful and -e
status=failed. Staged output is only enabled when at least one status
is filtered, that is, when the set is incomplete.
* signal.c (popcount32): Move ...
* defs.h (popcount32): ... here.
(not_failing_only, failing_only): Remove.
* filter_qualify.c (status_set): New number_set variable.
(statuses): New variable for names of statuses.
(statusstr_to_uint, qualify_status): New functions.
(qual_options): Handle status qualifier.
* number_set.c (get_number_setbit, is_complete_set): New functions.
* number_set.h (is_complete_set): New prototype.
(status_t): New enumeration for statuses.
(status_set): New prototype.
* strace.1.in: Document new status qualifier.
* strace.c (not_failing_only, failing_only): Remove.
(droptcb): Handle status=detached option.
(init): Handle new status qualifier, set status_set variable on -z and -Z
options, warn on -zZ and -Zz, use is_complete_set.
(maybe_switch_tcbs): Reopen memstream after tcb switch.
(print_event_exit): Handle status=unfinished option.
* syscall.c (syscall_entering_trace): Use is_complete_set.
(syscall_exiting_trace): Use is_complete_set, handle status=unavailable
option.
* NEWS: Mention this change.
Signed-off-by: Paul Chaignon <paul.chaignon@gmail.com>
Paul Chaignon [Sat, 15 Jun 2019 05:21:44 +0000 (07:21 +0200)]
Stage output for -z and -Z options
-z and -Z options print only successful and failing syscalls respectively.
However, failure of syscall is only known after syscall return. Thus, we
end up with something like this on, e.g., ENOENT:
open("does_not_exist", O_RDONLY <unfinished ...>
whereas the intended result is that the open(...) line is not shown at all.
This change fixes this issue using open_memstream. When either the -z or
the -Z option is used, the output is staged in memory (using
open_memstream) until we know the syscall return status. If the
open_memstream function is not available, these new options error out.
Document -z and -Z options as new features since they have never worked
properly before and were undocumented since commit v4.4.95~21.
* stage_output.c: New file.
* Makefile.am (strace_SOURCES): Add it.
* configure.ac (AC_CHECK_FUNCS): Add open_memstream.
* defs.h (struct tcb): Add real_outf, memfptr, and memfloc fields for
memstream.
(strace_open_memstream, strace_close_memstream): New prototypes.
* strace.1.in: Document -z and -Z options.
* strace.c (usage): Mention -z and -Z options.
(init): Error on -z and -Z options if open_memstream if unavailable.
(maybe_switch_tcbs): Handle switch of memstream between tcbs.
(printleader): Avoid marking staged syscalls as unfinished.
* syscall.c (syscall_entering_trace): Open memstream.
(syscall_exiting_trace): Filter failed syscalls if failing_only is set,
handle raw(tcp) case.
(print_syscall_resume): Avoid marking staged syscalls as resumed.
* NEWS: Mention this change.
Paul Chaignon [Mon, 1 Apr 2019 20:26:00 +0000 (22:26 +0200)]
Add -Z option to print only failing syscalls
Existing -z option prints only successful syscalls.
This change adds a -Z option to print only failing syscalls.
Both options will start to behave properly with the subsequent commit.
* strace.c (init): Handle new -Z option.
* defs.h (failing_only): New prototype.
* syscall.c (failing_only): New variable.
(syscall_exiting_trace): Ignore failed syscalls if failing_only is set.
References: https://github.com/strace/strace/issues/50 Co-Authored-by: Burkhard Kohl <burkhard.kohl@intel.com> Signed-off-by: Paul Chaignon <paul.chaignon@gmail.com>
In file included from statx.c:44:
xstatx.c:47:16: error: ‘struct libc_statx’ declared inside parameter list will not be visible outside of this definition or declaration [-Werror]
* tests/xstatx.c (struct statx): New forward declaration.
Change maybe_switch_tcbs to return NULL when no switching is necessary.
Introduce maybe_switch_current_tcp as a thing wrapper around
maybe_switch_tcbs.
* strace.c (maybe_switch_current_tcp): New function.
(dispatch_event): Use it instead of maybe_switch_tcbs, move comments
and the os_release check before maybe_switch_tcbs invocation ...
(maybe_switch_tcbs): ... here. Change return value to NULL
if no switching was performed.
tests: robustify strace -k tests against link-time optimizer
Some distributions enable by default a link-time optimizer that
mangles stack_fcall sample executables in a way that renders them
unusable for test purposes.
Robustify tests to defeat link-time optimizer.
* tests/stack-fcall.h (f0, f1, f2, f3): Add second parameter.
* tests/stack-fcall.c (main): Pass main as the second parameter to f0.
* tests/stack-fcall-0.c (f0): Add second parameter f, pass the xor of it
and f0 to f1.
* tests/stack-fcall-1.c (f1): Add second parameter f, pass the xor of it
and f1 to f2.
* tests/stack-fcall-2.c (f2): Add second parameter f, pass the xor of it
and f2 to f3.
* tests/stack-fcall-3.c: Include <asm/unistd.h>.
(f3): Add second parameter f, invoke __NR_gettid syscall with the xor
of f and f3 as its argument.
tests: check decoding of mode argument of mbind and set_mempolicy syscalls
* tests/mbind.c: Include "scno.h".
(errstr): New variable.
(k_mbind): New function.
(out_str): New macro.
(mpol_modes): New array.
(main): Use it and k_mbind.
* tests/set_mempolicy.c: Include "scno.h", do not include <errno.h>,
"xlat.h" and "xlat/mpol_modes.h".
(errstr): New variable.
(k_set_mempolicy): New function.
(out_str): New macro.
(mpol_modes): New array.
(print_nodes): Use it and k_set_mempolicy.
(main): Likewise.
* tests/mbind-Xabbrev.c: New file.
* tests/mbind-Xraw.c: Likewise.
* tests/mbind-Xverbose.c: Likewise.
* tests/set_mempolicy-Xabbrev.c: Likewise.
* tests/set_mempolicy-Xraw.c: Likewise.
* tests/set_mempolicy-Xverbose.c: Likewise.
* tests/gen_tests.in (mbind-Xabbrev, mbind-Xraw, mbind-Xverbose,
set_mempolicy-Xabbrev, set_mempolicy-Xraw, set_mempolicy-Xverbose):
New entries.
* tests/pure_executables.list: Add mbind-Xabbrev, mbind-Xraw,
mbind-Xverbose, set_mempolicy-Xabbrev, set_mempolicy-Xraw,
and set_mempolicy-Xverbose.
* tests/.gitignore: Likewise.
numa: enhance decoding of mode argument of mbind and set_mempolicy syscalls
Implement decoding of memory policy mode flags introduced by Linux
kernel commits v2.6.26-rc1~990 and v2.6.26-rc1~988.
* xlat/mpol_mode_flags.in: New file.
* numa.c: Include "xlat/mpol_mode_flags.h".
(print_mode): Print MPOL_MODE_FLAGS part of mode argument as flags.
* NEWS: Mention this.
sparc, sparc64: refactor arch_set_error and arch_set_success
* linux/sparc/set_error.c (sparc_set_o0_psr): New function.
(arch_set_error, arch_set_success): Use it.
* linux/sparc64/set_error.c (sparc64_set_o0_tstate): New function.
(arch_set_error, arch_set_success): Use it.
sparc, sparc64: fix syscall tampering when PTRACE_GET_SYSCALL_INFO is in use
When PTRACE_GET_SYSCALL_INFO is in use on sparc, psr is not loaded,
so it has to be loaded explicitly before tampering.
Likewise, when PTRACE_GET_SYSCALL_INFO is in use on sparc64, tstate
is not loaded, so it has to be loaded explicitly before tampering.
* linux/sparc/set_error.c (arch_set_error, arch_set_success): Explicitly
call get_regs before changing psr when PTRACE_GET_SYSCALL_INFO is in use.
* linux/sparc64/set_error.c (arch_set_error, arch_set_success):
Explicitly call get_regs before changing tstate when
PTRACE_GET_SYSCALL_INFO is in use.
* NEWS: Mention this fix.
powerpc: fix syscall tampering when PTRACE_GET_SYSCALL_INFO is in use
When PTRACE_GET_SYSCALL_INFO is in use, CCR is not loaded, so it has
to be loaded explicitly before tampering.
* linux/powerpc/set_error.c (arch_set_error, arch_set_success):
Explicitly load CCR before changing it when PTRACE_GET_SYSCALL_INFO
is in use.
* NEWS: Mention this fix.
* xlat/bpf_attach_type.in (BPF_CGROUP_SYSCTL): New constant introduced
by Linux kernel commit v5.2-rc1~133^2~132^2~39^2~19.
(BPF_CGROUP_UDP4_RECVMSG, BPF_CGROUP_UDP6_RECVMSG): New constants
introduced by Linux kernel commit v5.2-rc6~33^2~44^2^2~5.
* xlat/bpf_commands.in (BPF_MAP_FREEZE): New constant introduced
by Linux kernel commit v5.2-rc1~133^2~193^2~12^2~12.
* xlat/bpf_map_flags.in (BPF_F_RDONLY_PROG, BPF_F_WRONLY_PROG): New
constants introduced by Linux kernel commit
v5.2-rc1~133^2~193^2~12^2~13.
* xlat/bpf_map_types.in (BPF_MAP_TYPE_SK_STORAGE): New constant
introduced by Linux kernel commit v5.2-rc1~133^2~80^2^2~6.
* xlat/bpf_prog_types.in (BPF_PROG_TYPE_CGROUP_SYSCTL): New constant
introduced by Linux kernel commit v5.2-rc1~133^2~132^2~39^2~19.
(BPF_PROG_TYPE_RAW_TRACEPOINT_WRITABLE): New constant introduced
by Linux kernel commit v5.2-rc1~133^2~80^2~1^2~4.
* NEWS: Mention this.
* tests/bpf.c (BPF_MAP_CREATE_checks, BPF_PROG_LOAD_checks,
BPF_PROG_QUERY_checks): Update.
* tests/kernel_version.c (print_bpf_attr): Update.
Dmitry V. Levin [Thu, 27 Jun 2019 16:51:33 +0000 (16:51 +0000)]
print_dirfd: do not print trailing comma
It was fine to print trailing comma in print_dirfd until introduction
of a syscall with the last argument being a dirfd.
Now it's time to change print_dirfd.
Dmitry V. Levin [Wed, 26 Jun 2019 08:00:39 +0000 (08:00 +0000)]
mips: refactor syscallent initializers
Change format of designated initializers to BASE_NR + offset.
* linux/mips/syscallent-n32.h (BASE_NR): New macro. Use it in designated
initializers.
* linux/mips/syscallent-n64.h: Likewise.
* linux/mips/syscallent-o32.h: Likewise.
Paul Chaignon [Fri, 28 Jun 2019 15:51:42 +0000 (17:51 +0200)]
travis: Move fastest test configuration first
I use Travis CI to check each patch before sending my patchsets. Most
failures are simple and make all test configurations fail. However, since
Travis CI runs test configurations in order and given that the first three
configurations are the slowest ones, it takes about twenty minutes to see
the failure. Moving the fastest test configuration first would allow to
fail earlier. It would become about 3x faster to fail in case of simple
mistakes.
* .travis.yml (CC=gcc, STACKTRACE=no): Move to first position.
Signed-off-by: Paul Chaignon <paul.chaignon@gmail.com>
Dmitry V. Levin [Thu, 20 Jun 2019 09:49:27 +0000 (09:49 +0000)]
Enhance decoding of CLONE_PARENT_SETTID flag of clone syscall
* clone.c (SYS_FUNC(clone)): Print the parent_tid returned by the kernel
instead of its address when CLONE_PARENT_SETTID flag is set.
* tests/clone-flags.c (main): Check it.
Dmitry V. Levin [Mon, 27 May 2019 21:25:52 +0000 (21:25 +0000)]
xlat: update KVM_CAP_* constants
* xlat/clone_flags.in (KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2): New
constant introduced by Linux kernel commit v5.2-rc1~17^2~11.
(KVM_CAP_PPC_IRQ_XIVE): New constant introduced by Linux kernel commits
v5.2-rc1~17^2~2^2~19 and v5.2-rc1~17^2~2.
(KVM_CAP_ARM_SVE): New constant introduced by Linux kernel commit
v5.2-rc1~17^2~1^2~31.
(KVM_CAP_ARM_PTRAUTH_ADDRESS, KVM_CAP_ARM_PTRAUTH_GENERIC): New
constants introduced by Linux kernel commits v5.2-rc1~17^2~1^2~10
and v5.2-rc1~17^2~1.
* NEWS: Mention this.
Dmitry V. Levin [Sun, 26 May 2019 22:08:55 +0000 (22:08 +0000)]
xlat: update V4L2_PIX_* constants
* xlat/v4l2_pix_fmts.in (V4L2_PIX_FMT_FWHT_STATELESS): New constant
introduced by Linux kernel commit v5.2-rc1~33^2~132.
(V4L2_PIX_FMT_BGRA32, V4L2_PIX_FMT_BGRX32, V4L2_PIX_FMT_RGBA32,
V4L2_PIX_FMT_RGBX32): New constants introduced by Linux kernel commit
v5.2-rc1~33^2~25.
(V4L2_PIX_FMT_RGBA444, V4L2_PIX_FMT_RGBX444, V4L2_PIX_FMT_ABGR444,
V4L2_PIX_FMT_XBGR444, V4L2_PIX_FMT_XBGR444, V4L2_PIX_FMT_BGRX444): New
constants introduced by Linux kernel commit v5.2-rc1~33^2~24.
(V4L2_PIX_FMT_RGBA555, V4L2_PIX_FMT_RGBX555, V4L2_PIX_FMT_ABGR555,
V4L2_PIX_FMT_XBGR555, V4L2_PIX_FMT_BGRA555, V4L2_PIX_FMT_BGRX555): New
constants introduced by Linux kernel commit v5.2-rc1~33^2~23.
Dmitry V. Levin [Sun, 26 May 2019 22:08:55 +0000 (22:08 +0000)]
xlat: update V4L2_CID_* constants
* xlat/v4l2_control_ids.in (V4L2_CID_FWHT_I_FRAME_QP,
V4L2_CID_FWHT_P_FRAME_QP): New constants introduced by Linux kernel
commit v5.2-rc1~33^2~132.
(V4L2_CID_MPEG_VIDEO_H264_I_FRAME_MIN_QP,
V4L2_CID_MPEG_VIDEO_H264_I_FRAME_MAX_QP,
V4L2_CID_MPEG_VIDEO_H264_P_FRAME_MIN_QP,
V4L2_CID_MPEG_VIDEO_H264_P_FRAME_MAX_QP): New constants introduced by
Linux kernel commit v5.2-rc1~33^2~95.
* NEWS: Mention this.
Dmitry V. Levin [Sat, 25 May 2019 22:12:30 +0000 (22:12 +0000)]
xlat: update AUDIT_* constants
* xlat/nl_audit_types.in (AUDIT_FANOTIFY): New constant introduced by
Linux kernel commit v4.15-rc1~130^2^2~11.
(AUDIT_TIME_INJOFFSET): New constant introduced by Linux kernel commit
v5.2-rc1~144^2~2.
(AUDIT_TIME_ADJNTPVAL): New constant introduced by Linux kernel commit
v5.2-rc1~144^2~1.
Dmitry V. Levin [Fri, 24 May 2019 21:54:17 +0000 (21:54 +0000)]
xlat: update AUDIT_ARCH_* constants
* xlat/audit_arch.in (AUDIT_ARCH_ARCOMPACT, AUDIT_ARCH_ARCOMPACTBE,
AUDIT_ARCH_ARCV2, AUDIT_ARCH_ARCV2BE): New constants introduced by Linux
kernel commit v5.2-rc1~144^2~16.
(AUDIT_ARCH_C6X, AUDIT_ARCH_C6XBE): New constants introduced by Linux
kernel commit v5.2-rc1~144^2~15.
(AUDIT_ARCH_CSKY): New constant introduced by Linux kernel commit
v5.0-rc1~37^2~15.
(AUDIT_ARCH_H8300): New constant introduced by Linux kernel commit
v5.2-rc1~144^2~14.
(AUDIT_ARCH_HEXAGON): New constant introduced by Linux kernel commit
v5.2-rc1~144^2~12.
(AUDIT_ARCH_NDS32, AUDIT_ARCH_NDS32BE): New constants introduced by
Linux kernel commit v5.2-rc1~144^2~9.
(AUDIT_ARCH_NIOS2): New constant introduced by Linux kernel commit
v5.2-rc1~144^2~8.
(AUDIT_ARCH_RISCV32, AUDIT_ARCH_RISCV64): New constants introduced by
Linux kernel commit v5.0-rc2~23^2~1^2~5.
(AUDIT_ARCH_TILEGX, AUDIT_ARCH_TILEGX32, AUDIT_ARCH_TILEPRO): New
constants introduced by Linux kernel commit v4.3-rc1~83^2~3.
(AUDIT_ARCH_UNICORE): New constant introduced by Linux kernel commit
v5.2-rc1~144^2~6.
(AUDIT_ARCH_XTENSA): New constant introduced by Linux kernel commit
v5.0-rc1~92^2~8.
* NEWS: Mention this.
Dmitry V. Levin [Tue, 21 May 2019 23:30:35 +0000 (23:30 +0000)]
tests: robustify bpf-obj_get_info_by_fd test against future kernels
* tests/bpf-obj_get_info_by_fd.c (print_prog_load, main): Change
log_level from 42 to 7, to placate Linux kernels containing commit
v5.2-rc1~133^2~193^2~18^2~9.
Dmitry V. Levin [Tue, 21 May 2019 21:26:52 +0000 (21:26 +0000)]
xlat: update IPV6_* constants
* xlat/sock_ipv6_options.in (IPV6_MULTICAST_ALL): New constant
introduced by Linux kernel commit v4.20-rc1~14^2~384.
(IPV6_ROUTER_ALERT_ISOLATE): New constant introduced
by Linux kernel commit v5.1-rc1~178^2~22.
* NEWS: Mention this.
Dmitry V. Levin [Mon, 20 May 2019 22:50:44 +0000 (22:50 +0000)]
xlat: update BPF_* constants
* xlat/ebpf_class.in (BPF_JMP32): New constant introduced
by Linux kernel commit v5.1-rc1~178^2~404^2~4^2~15.
* xlat/bpf_map_update_elem_flags.in (BPF_F_LOCK): New constant
introduced by Linux kernel commit v5.1-rc1~178^2~375^2~4^2~3.
* NEWS: Mention this.
Dmitry V. Levin [Mon, 20 May 2019 22:50:44 +0000 (22:50 +0000)]
xlat: update V4L2_* constants
* xlat/v4l2_control_ids.in
(V4L2_CID_MPEG_VIDEO_H264_CONSTRAINED_INTRA_PREDICTION): New constant
introduced by Linux kernel commit v5.1-rc1~88^2~261.
(V4L2_CID_MPEG_VIDEO_H264_CHROMA_QP_INDEX_OFFSET): New constant
introduced by Linux kernel commit v5.1-rc1~88^2~260.
* xlat/v4l2_pix_fmts.in (V4L2_PIX_FMT_AYUV32, V4L2_PIX_FMT_XYUV32,
V4L2_PIX_FMT_VUYA32, V4L2_PIX_FMT_VUYX32): New constants
introduced by Linux kernel commit v5.1-rc1~88^2~90.
* NEWS: Mention this.
Dmitry V. Levin [Fri, 17 May 2019 16:16:29 +0000 (16:16 +0000)]
tests: check decoding of SO_TIMESTAMP*_NEW control messages
* configure.ac (AC_CHECK_TYPES): Check for struct __kernel_timespec
and struct __kernel_sock_timeval.
* tests/msg_control.c [HAVE_STRUCT___KERNEL_SOCK_TIMEVAL ||
HAVE_STRUCT___KERNEL_TIMESPEC]: Include <linux/time_types.h>.
(test_scm_timestamp): Rename to test_scm_timestamp_old.
(test_scm_timestampns): Rename to test_scm_timestampns_old.
(test_scm_timestamping): Rename to test_scm_timestamping_old.
[HAVE_STRUCT___KERNEL_SOCK_TIMEVAL] (test_scm_timestamp_new): New
function.
[HAVE_STRUCT___KERNEL_TIMESPEC] (test_scm_timestampns_new,
test_scm_timestamping_new): New functions.
(test_sol_socket): Use them.
* tests/sockopt-timestamp.c [HAVE_STRUCT___KERNEL_SOCK_TIMEVAL ||
HAVE_STRUCT___KERNEL_TIMESPEC]: Include <linux/time_types.h>.
Include "xlat/sock_options.h" in XLAT_MACROS_ONLY mode.
(print_timestampns_old): Define unconditionally.
[HAVE_STRUCT___KERNEL_SOCK_TIMEVAL] (print_timestamp_new): New function.
[HAVE_STRUCT___KERNEL_TIMESPEC] (print_timestampns_new): Likewise.
(main): Test SO_TIMESTAMPNS_OLD unconditionally.
[HAVE_STRUCT___KERNEL_SOCK_TIMEVAL]: Test SO_TIMESTAMP_NEW.
[HAVE_STRUCT___KERNEL_TIMESPEC]: Test SO_TIMESTAMPNS_NEW.
Dmitry V. Levin [Fri, 17 May 2019 16:16:29 +0000 (16:16 +0000)]
print_timespec.h: parametrize TIMESPEC_T.tv_nsec
This is going to be used to implement a parser of SO_TIMESTAMP_NEW
control message.
* print_timespec.h [!TIMESPEC_NSEC] (TIMESPEC_NSEC): Define to tv_sec.
(TIMESPEC_TO_SEC_NSEC, timespec_fmt, print_timespec_t_utime): Use
TIMESPEC_NSEC instead of tv_sec.