6457 Commits

Author SHA1 Message Date
Eugene Syromyatnikov
bf4aaabfed ci: install libunwind8-dev
While in debian/control we use libunwind-dev in Build-Depends, in case
of ci we have to be more conservative and use the name portable across
different ci implementations.

* ci/install-dependencies.sh (common_packages): Add libunwind8-dev.

Co-Authored-by: Dmitry V. Levin <ldv@altlinux.org>
2018-03-26 13:10:06 +00:00
Eugene Syromyatnikov
58598cd7f6 tests: check injection of return values into a "never fails" syscall
* tests/inject-nf.c: New file.
* tests/inject-nf.test: New test.
* tests/.gitignore: Add inject-nf.
* tests/Makefile.am (check_PROGRAMS): Likewise.
(MISC_TESTS): Add inject-nf.test.

Co-Authored-by: Dmitry V. Levin <ldv@altlinux.org>
2018-03-23 13:43:13 +00:00
dcfb3c0d47 Introduce raw syscall invocation wrappers
Unfortunately, syscall(3) provided by libc is too smart
for some of our needs.

* linux/raw_syscall.h: New file.
* linux/aarch64/raw_syscall.h: Likewise.
* linux/alpha/raw_syscall.h: Likewise.
* linux/arc/raw_syscall.h: Likewise.
* linux/arm/raw_syscall.h: Likewise.
* linux/avr32/raw_syscall.h: Likewise.
* linux/bfin/raw_syscall.h: Likewise.
* linux/hppa/raw_syscall.h: Likewise.
* linux/i386/raw_syscall.h: Likewise.
* linux/ia64/raw_syscall.h: Likewise.
* linux/m68k/raw_syscall.h: Likewise.
* linux/metag/raw_syscall.h: Likewise.
* linux/microblaze/raw_syscall.h: Likewise.
* linux/mips/raw_syscall.h: Likewise.
* linux/nios2/raw_syscall.h: Likewise.
* linux/or1k/raw_syscall.h: Likewise.
* linux/powerpc/raw_syscall.h: Likewise.
* linux/powerpc64/raw_syscall.h: Likewise.
* linux/riscv/raw_syscall.h: Likewise.
* linux/s390/raw_syscall.h: Likewise.
* linux/s390x/raw_syscall.h: Likewise.
* linux/sh/raw_syscall.h: Likewise.
* linux/sh64/raw_syscall.h: Likewise.
* linux/sparc/raw_syscall.h: Likewise.
* linux/sparc64/raw_syscall.h: Likewise.
* linux/tile/raw_syscall.h: Likewise.
* linux/x32/raw_syscall.h: Likewise.
* linux/x86_64/raw_syscall.h: Likewise.
* linux/xtensa/raw_syscall.h: Likewise.
* Makefile.am (EXTRA_DIST): Add them.
2018-03-23 13:43:13 +00:00
73edd445e2 tests: fix potentially unbound variable in kernel_version_code
Fix the following use case:

	$ sh -uc '. tests/init.sh; kernel_version_code 4.5'
	tests/init.sh: line 242: 3: unbound variable

* tests/init.sh (kernel_version_code): Fix potentially unbound variable.
2018-03-23 13:43:13 +00:00
5c0896d9d8 strace: further optimize unblocking of the delay signal handler
Do not unblock the delay signal handler unless the delay timer is armed.

* defs.h (is_delay_timer_created): Remove.
(is_delay_timer_armed, delay_timer_expired): New prototypes.
* delay.c (delay_timer_is_armed): New static variable.
(is_delay_timer_created): Add static qualifier.
(is_delay_timer_armed, delay_timer_expired): New functions.
(arm_delay_timer): Set delay_timer_is_armed.
* strace.c (next_event): Use is_delay_timer_armed instead of
is_delay_timer_created to check whether the delay signal handler
has to be unblocked.
(timer_sighandler): Invoke delay_timer_expired.
2018-03-23 00:20:33 +00:00
f56a3feb32 strace: rewrite restart error handling without sigsetjmp/siglongjmp
Further simplify and optimize error handling of the delay signal handler
by replacing sigsetjmp/siglongjmp mechanism with an error flag.

* strace.c: Do not include <setjmp.h>.
(restart_failed): New volatile variable.
(timer_jmp_buf): Remove.
(next_event): Cache is_delay_timer_created() return value,
remove sigsetjmp invocation, check restart_failed instead.
(timer_sighandler): Replace siglongjmp with setting restart_failed.
2018-03-23 00:20:33 +00:00
4976ce2f31 strace: do not call sigsetjmp without a delay timer
As sigsetjmp costs a syscall, do not call it unless a delay timer
is already created and its signal handler is going to be unblocked.

* strace.c (next_event): Move sigsetjmp invocation under
is_delay_timer_created() condition.

Optimizes: v4.21-108-gba8e768 ("Implement delay injection")
2018-03-23 00:20:33 +00:00
Eugene Syromyatnikov
51f0ef5140 tests/bpf.c: convert TEST_BPF_ macro to a function
As it looks like there's no compelling reason to keep it as a macro and
leaving it so quite complicates modification of the routine and makes
them error-prone.

* tests/bpf.c (TEST_BPF_): Convert it to...
(test_bpf): ...this.  Rename cmd_ to cmd, cmd_str_ to cmd_str,
init_first_ to init_first, print_first_ to print_first, init_attr_
to init_attr, print_attr_ to print_attr.
(TEST_BPF): Call test_bpf_ instead of TEST_BPF_.
2018-03-22 21:35:12 +00:00
Eugene Syromyatnikov
afb25ea58d tests: btrfs.c whitespace cleanup
* tests/btrfs.c: Add spaces after PRI* format specifiers.
2018-03-22 21:35:12 +00:00
Elvira Khabirova
a3bef655cb tests: check delay injection
* tests/delay.c: New file.
* tests/delay.test: New test.
* tests/.gitignore: Add delay.
* tests/Makefile.am (check_PROGRAMS): Likewise.
(delay_LDADD): New variable.
(MISC_TESTS): Add delay.test.

Co-Authored-by: Dmitry V. Levin <ldv@altlinux.org>
2018-03-22 06:23:25 +00:00
Elvira Khabirova
ba8e768a80 Implement delay injection
Add -e inject=SET:delay_enter= and -e inject=SET:delay_exit= options.

* configure.ac (AC_SEARCH_LIBS): Check for timer_create -lrt.
* delay.c: New file.
* Makefile.am (strace_SOURCES): Add it.
(strace_LDADD): Add $(timer_LIBS).
* defs.h (INJECT_F_DELAY_ENTER, INJECT_F_DELAY_EXIT,
TCB_INJECT_DELAY_EXIT, TCB_DELAYED, inject_delay_exit, syscall_delayed):
New macros.
(alloc_delay_data, fill_delay_data, is_delay_timer_created,
arm_delay_timer, delay_tcb): New prototypes.
(struct inject_data): Replace reserved field with delay_idx.
(struct tcb): Add delay_expiration_time field.
* filter_qualify.c (parse_delay_token): New function.
(parse_inject_token): Use it.
(qualify_inject_common): Initialize struct inject_opts.data.delay_idx.
* strace.c: Include <setjmp.h>
(timer_jmp_buf, timer_set): New static variables.
(timer_sighandler, restart_delayed_tcb, restart_delayed_tcbs): New
functions.
(init): Block SIGALRM, set SIGALRM handler.
(dispatch_event): Do not restart delayed syscalls.
(next_event): Unblock SIGALRM during wait4 invocation.
* syscall.c (tamper_with_syscall_entering): Arm delay timer if
INJECT_F_DELAY_ENTER injection flag is set, set TCB_INJECT_DELAY_EXIT
flag if INJECT_F_DELAY_EXIT injection flag is set.
tamper_with_syscall_exiting): Arm delay timer if inject_delay_exit.
(syscall_exiting_trace): Call tamper_with_syscall_exiting in case of
inject_delay_exit.
(syscall_exiting_finish): Clear TCB_INJECT_DELAY_EXIT flag.
* strace.1.in: Document delay injection.
* NEWS: Mention this improvement.

Co-Authored-by: Dmitry V. Levin <ldv@altlinux.org>
2018-03-22 06:23:25 +00:00
c3393d4770 Do not block handled signals in interactive mode
Let these signals be handled asynchronously as they are acted on
only when waiting for process state changes.

* strace.c (start_set, blocked_set): Remove.
(set_sighandler): Do not update blocked_set.
(startup_attach, init, next_event): Remove all sigprocmask calls.
2018-03-22 06:23:25 +00:00
Eugene Syromyatnikov
2bcf86777b bpf: improve handling of various sizes of bpf_prog_attr structure
As program attributes have been added gradually over kernel versions,
attribute size less than expected should be printed accordingly.

* bpf.c (DEF_BPF_CMD_DECODER(BPF_PROG_LOAD)): Do not print structure
fields if their size is less than the initially introduced (in Linux
commit v3.18-rc1~52^2~1^2~7) version.  Print fields of union bpf_attr
introduced in various kernel versions when the length is big enough
(new fields were introduced in Linux commits v3.18-rc1~52^2~1^2~4,
v4.1-rc1~84^2~50, and v4.12-rc2~34^2~29^2~2).
* tests/bpf.c (print_BPF_PROG_LOAD_first): Update expected output.

Co-Authored-by: Dmitry V. Levin <ldv@altlinux.org>
2018-03-21 05:00:03 +03:00
Eugene Syromyatnikov
8fa209cf0a btrfs: print struct btrfs_ioctl_logical_ino_args.reserved if non-zero
* btrfs.c (btrfs_ioctl) <case BTRFS_IOC_LOGICAL_INO>: Print
struct btrfs_ioctl_logical_ino_args.reserved field if it is not zero.
* tests/btrfs.c (btrfs_test_ino_path_ioctls): Check it.

Co-Authored-by: Dmitry V. Levin <ldv@altlinux.org>
2018-03-20 20:44:34 +00:00
Eugene Syromyatnikov
41a1380c19 Move is_filled and IS_ZERO to macros.h, rename IS_ZERO to IS_ARRAY_ZERO
* s390.c: Replace all IS_ZERO invocations with IS_ARRAY_ZERO.
(is_filled, IS_ZERO): Move...
* macros.h: ...here.
(is_filled): Add inline qualifier, add const qualifier to ptr.
(IS_ZERO): Rename to IS_ARRAY_ZERO, cast arr_ to "const char *".

Co-Authored-by: Dmitry V. Levin <ldv@altlinux.org>
2018-03-20 20:44:34 +00:00
63080cac4d mpers.m4: enhance workaround for missing gnu/stubs-*.h files
Make generated empty gnu stub files available for mpers_test.sh check.

* m4/mpers.m4 (st_MPERS): Add $IFLAG to CPPFLAGS for mpers_test.sh
invocation.

Complements: v4.11~223 ("mpers.m4: workaround missing gnu/stubs-*.h files")
2018-03-20 20:44:34 +00:00
Eugene Syromyatnikov
52af037708 README.md: add references to binary strace packages
* README.md: Add references to binary strace packages in OBS,
Fedora rawhide, and Sisyphus.

Co-Authored-by: Dmitry V. Levin <ldv@altlinux.org>
2018-03-20 13:45:10 +00:00
Eugene Syromyatnikov
a5605700bd INSTALL-git.md: enhance phrasing
* INSTALL-git.md: Enhance phrasing.

Co-Authored-by: Dmitry V. Levin <ldv@altlinux.org>
2018-03-20 13:45:10 +00:00
a696393c65 bootstrap: distribute README
* bootstrap: Install README before invoking autoreconf to get README
included into distributed tarball.

Fixes: v4.21-93-g4bb8454 ("Move README to dist subdirectory")
2018-03-20 12:11:34 +00:00
17935497e2 Replace struct timeval with struct timespec in time measurements
This is required to implement more precise time measurements.

* Makefile.am (strace_LDADD): Add $(clock_LIBS).
* defs.h (struct tcb): Change the type of stime, dtime, and etime fields
from struct timeval to struct timespec, all users updated.
(syscall_exiting_decode, syscall_exiting_trace, count_syscall): Change
the type of "struct timeval *" argument to "struct timespec *", all
users updated.
(tv_nz, tv_cmp, tv_float, tv_add, tv_sub, tv_div, tv_mul): Rename to
ts_nz, ts_cmp, ts_float, ts_add, ts_sub, ts_div, and ts_mul.  Change
the type of all "struct timeval *" arguments to "struct timespec *",
all users updated.
* util.c (tv_nz, tv_cmp, tv_float, tv_add, tv_sub, tv_div, tv_mul):
Rename to ts_nz, ts_cmp, ts_float, ts_add, ts_sub, ts_div, and ts_mul.
Change the type of all "struct timeval *" arguments to "struct timespec *".
* count.c (struct call_counts): Change the type of "time" field
from struct timeval to struct timespec, all users updated.
(overhead): Change type from struct timeval to struct timespec, all
users updated.
(count_syscall): Change the type of "struct timeval *" argument to
"struct timespec *".
* strace.c (printleader): Change the type of struct timeval variables
to struct timespec, call clock_gettime instead of gettimeofday.
(next_event, trace_syscall): Change the type of struct timeval variables
to struct timespec.
* syscall.c (syscall_entering_finish, syscall_exiting_decode): Call
clock_gettime instead of gettimeofday.
2018-03-20 02:30:24 +00:00
dfccb60a75 Fix -O option handling
Fast syscalls usually take less than a microsecond of system cpu time
nowadays, making -O option almost useless.

* count.c (call_summary_pers): Avoid negative time counts.
* tests/count.test: Check it.
* NEWS: Mention it.
2018-03-20 02:30:24 +00:00
b66af24f61 count: cleanup count_syscall
* count.c (shortest): Remove.
(overhead): Initialize to zero.
(call_summary_pers): Remove shortest handling.
(count_syscall): Remove dead code.  The remaining code does the same
wrong calculations as before the change, though.
2018-03-16 00:55:58 +00:00
24c5884e0e printleader: cleanup tflag handling
* strace.c (printleader): Move declarations of variables closer
to their first use.
2018-03-16 00:55:58 +00:00
743f0ae5ce Move install.texi to maint subdirectory
This file comes from GNU Autoconf and is used to generate INSTALL file.

* install.texi: Move...
* maint/install.texi: ...here.
2018-03-16 00:55:58 +00:00
Eugene Syromyatnikov
87869b3ac2 doc: update commit requirements
* README-hacking (Requirements): Enhance phrasing.
(Commit log requirements): Rename to "Commit requirements",
describe "absence of whitespace errors" requirement, add references
to the Linux kernel coding style and scripts/checkpatch.pl script.

Co-Authored-by: Dmitry V. Levin <ldv@altlinux.org>
2018-03-16 00:55:58 +00:00
Eugene Syromyatnikov
4bb845478c Move README to dist subdirectory
README was originally written for users of distribution tarballs.
Nowadays it appears to be confusing for those who build strace
using a GIT version of strace source code.

* README: Move...
* dist/README: ...here.
* bootstrap: Copy README from dist subdirectory to the toplevel
directory after successful autoreconf.

Co-Authored-by: Dmitry V. Levin <ldv@altlinux.org>
References: https://github.com/strace/strace/issues/56
2018-03-16 00:55:58 +00:00
Eugene Syromyatnikov
b1e1eb7731 README: synchronise with README.md
* README: Extend description, reference COPYING.
2018-03-15 16:30:53 +00:00
Eugene Syromyatnikov
d89a9e4e1d poll.c: remove special INFTIM handling
On Linux, poll syscall interprets any negative timeout value as an
infinite timeout, so no need to handle BSD-specific INFTIM.

* poll.c (SYS_FUNC(poll)): Remove INFTIM handling.
2018-03-15 14:24:22 +00:00
85b35818db build: do not hardcode -lrt
Depending on libc implementation, various -lrt functions can be
implemented either in -lc or in -lrt.  For example, starting with
glibc-2.17 the clock_* suite of functions is available directly in -lc.

Check whether clock_* and mq_* suites of functions are provided
by -lrt or by the main C library, do not link with -lrt unnecessarily.

This change affects only tests yet, but this is going to be
more important as soon as strace starts using clock_gettime.

* configure.ac (AC_SEARCH_LIBS): Check for clock_gettime and mq_open
in -lrt.
(AC_SUBST): Add clock_LIBS and mq_LIBS.
* tests/Makefile.am (mq_LDADD): Replace -lrt with $(mq_LIBS).
(threads_execve_LDADD, times_LDADD): Replace -lrt with $(clock_LIBS).
2018-03-14 21:15:55 +00:00
a51d9f9647 tests: do not link with -lrt unnecessarily
* tests/Makefile.am (attach_f_p_LDADD): Remove -lrt.
(clock_xettime_LDADD, mq_sendrecv_LDADD, mq_sendrecv_read_LDADD,
mq_sendrecv_write_LDADD): Remove.
2018-03-14 21:15:55 +00:00
e8cb814cf2 Optimize pid2tcb
Introduce an internal cache of pid2tcb translations.
This can save more than 80% of CPU user time spent by strace.

Tested using the following setup:

	#include <unistd.h>
	#include <sys/stat.h>
	#include <sys/wait.h>
	int main()
	{
		int i;
		sleep(1);
		for (i = 1; i < 1000; ++i) {
			pid_t pid = fork();
			if (pid < 0)
				return 2;
			if (pid)
				return wait(&i) != pid || i;
		}
		sleep(1);
		for (i = 0; i < 10000000; ++i)
			umask(0777);
		return 0;
	}

	old$ ./set_ptracer_any ./pid2tcb >pid2tcb.wait & \
	  while [ ! -s pid2tcb.wait ]; do sleep 0.1; done; \
	  time -f '%Uuser %Ssystem %eelapsed %PCPU' \
	  ../strace -qq -enone -esignal=none -f -p $!
	5.51user 104.90system 122.45elapsed 90%CPU

	new$ ./set_ptracer_any ./pid2tcb >pid2tcb.wait & \
	  while [ ! -s pid2tcb.wait ]; do sleep 0.1; done; \
	  time -f '%Uuser %Ssystem %eelapsed %PCPU' \
	  ../strace -qq -enone -esignal=none -f -p $!
	1.29user 102.78system 114.97elapsed 90%CPU
2018-03-13 22:33:48 +00:00
55df9a9251 Enable USE_SEIZE code unconditionally
It is by no means an experimental code.

* defs.h (USE_SEIZE): Remove.
* strace.c [!USE_SEIZE]: Remove.
2018-03-13 20:54:25 +00:00
595fd1a2b2 ci: clone musl from the local server
Assume that strace project on the local server contains an appropriate
musl repository, use this repository instead of hardcoded github
location.

* ci/install-dependencies.sh (clone_repo): Use local server by default.
(musl-gcc): Un-hardcode the location of musl repository.
2018-03-13 15:12:14 +00:00
8727472041 ci: refactor cloning of additional repositories
* ci/install-dependencies.sh (clone_repo): New function.
Use it instead of direct invocations of git clone.
2018-03-13 15:12:14 +00:00
8d00c56663 ci: extend error diagnostics when configure invocation fails
* ci/run-build-and-tests.sh: Include $CC -dumpspecs output in addition
to config.log when ./configure fails.
2018-03-13 15:12:14 +00:00
8c00b612e5 ci: rename travis-build.sh and travis-install.sh scripts
* travis-build.sh: Rename to ci/run-build-and-tests.sh, all callers
updated.
* travis-install.sh: Rename to ci/install-dependencies.sh, all callers
updated.
2018-03-13 13:19:02 +00:00
3de1462ed8 tests: extend ioctl.test libc protection to -y output
* tests/ioctl.test: Extend the filter of ioctl calls with standard
descriptor arguments to -y output.
2018-03-13 01:53:04 +00:00
Harsha Sharma
babc639416 ptp.c: print field names and use macros form print_fields.h
* ptp.c: Include "print_fields.h".
(ptp_ioctl): Print field names with field values for PTP_PEROUT_REQUEST,
use macros from print_fields.h.
2018-03-12 13:52:32 +00:00
Chen Jingpiao
8932ac050e tests: add check for decoding of netfilter subsystem
* tests/netlink_netfilter.c(test_nfgenmsg): Add check for decoding
of netfilter subsystem.
2018-03-11 15:35:19 +00:00
Chen Jingpiao
073d93827f nfnetlink: introduce generic netfilter subsystem decoder
* netlink_netfilter.c: Include "nlattr.h".
(decode_netlink_netfilter): Call decode_nlattr.
2018-03-11 15:35:19 +00:00
Chen Jingpiao
547b90e239 Move nl_netfilter_msg_types definition from netlink.c to netlink_netfilter.c
The side effect of #include "xlat/nl_netfilter_msg_types.h" is
NFNL_MSG_BATCH_* constants properly defined in that header file.
While netlink.c does not use these constants itself,
netlink_netfilter.c is going to need them soon.

* defs.h (nl_netfilter_msg_types): New xlat prototype.
* netlink.c: Move inclusion of "xlat/nl_netfilter_msg_types.h" ...
* netlink_netfilter.c: ... here.
2018-03-11 14:49:25 +00:00
Chen Jingpiao
91497f718e tests: add check for NETLINK_NETFILTER parser
* tests/netlink_netfilter.c: Include <netinet/in.h>, <arpa/inet.h>
and <linux/netfilter/nf_tables.h>.
Replace "netlink.h" with "test_netlink.h".
(NFNL_SUBSYS_NFTABLES, NFT_MSG_NEWTABLE): New macros.
(test_nlmsg_done, test_nfgenmsg): New functions.
(main): Use them.
2018-03-11 14:49:25 +00:00
Chen Jingpiao
106731a96c netlink: introduce NETLINK_NETFILTER parser
* netlink_netfilter.c: New file.
* Makefile.am (strace_SOURCES): Add it.
* defs.h (decode_netlink_netfilter): New prototype.
* netlink.c (netlink_decoders): Add NETLINK_NETFILTER.
* xlat/netfilter_versions.in: New file.
2018-03-11 14:49:25 +00:00
Chen Jingpiao
46471eeb42 xlat: remove NFNL_SUBSYS_COUNT constant
NFNL_SUBSYS_COUNT is not a symbol with some constant value, it changes
with time, just print it as an unrecognized number.

* xlat/nl_netfilter_subsys_ids.in (NFNL_SUBSYS_COUNT): Remove.
2018-03-11 14:49:25 +00:00
3524376809 inject_data: make room for more injection features
* defs.h (struct inject_data): Squeeze flags and signo fields from
uint16_t to uint8_t to make room for more injection features.
2018-03-10 00:13:04 +00:00
Eugene Syromyatnikov
8919eaa558 xlat: sort v4l2_pix_fmts.in and v4l2_sdr_fmts.in
* xlat/v4l2_pix_fmts.in: Sort by value, add a comment about sorting.
* xlat/v4l2_sdr_fmts.in: Likewise.
2018-03-09 02:48:30 +00:00
c7c7f94d83 xlat: add comments to all sorted xlat files
Add a short comment describing the method used to sort entries.

* xlat/ethernet_protocols.in: Update the comment about sorting.
* xlat/fsmagic.in: Likewise.
* xlat/evdev_keycode.in: Add a comment about sorting.
* xlat/hw_breakpoint_type.in: Likewise.
* xlat/perf_hw_cache_id.in: Likewise.
* xlat/perf_hw_cache_op_id.in: Likewise.
* xlat/perf_hw_cache_op_result_id.in: Likewise.
* xlat/perf_hw_id.in: Likewise.
* xlat/perf_sw_ids.in: Likewise.
* xlat/perf_type_id.in: Likewise.
2018-03-09 02:48:30 +00:00
Eugene Syromyatnikov
9ffdd1dfb6 bpf: remove page size caching
get_pagesize() has a static cache anyway, no need to duplicate it.

* bpf.c (SYS_FUNC(bpf)): Remove static size_t page_size and its
initialisation, use get_pagesize() as the size of buf directly.
2018-03-09 01:04:28 +00:00
Eugene Syromyatnikov
fcce81ed1a bpf_filter: fix indentation of the switch clause
* bpf_filter.c (print_bpf_filter_code): Fix switch clause indentation.
2018-03-09 01:04:28 +00:00
4d1da8537d xlat: provide fallback definitions for arch-independent mmap flags
This is important for recently introduced MAP_SHARED_VALIDATE flag.

* xlat/mmap_flags.in (MAP_SHARED, MAP_PRIVATE, MAP_SHARED_VALIDATE):
Add constant values.

Fixes: v4.21-67-g8c209d1 ("tests: fix remap_file_pages.test breakage on hppa")
2018-03-08 22:27:26 +00:00