Commit Graph

6540 Commits

Author SHA1 Message Date
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
Eugene Syromyatnikov
ffcd3a837f bpf: print kern_version in the form of KERNEL_VERSION macro
* bpf.c (DEF_BPF_CMD_DECODER(BPF_PROG_LOAD)): Print
union bpf_attr.kern_version in the form of KERNEL_VERSION macro call.
* tests/bpf.c: Update expected output.
2018-03-07 22:07:20 +00:00
Eugene Syromyatnikov
8c209d1ad1 tests: fix remap_file_pages.test breakage on hppa
Apparently, hppa is the only architecture that has MAP_TYPE
defined to 0x3 instead of 0xf, and the tests hit that corner case.

* tests/remap_file_pages.c (main) [MAP_HUGETLB]: Print the value
of mapping type depending on the architecture (MAP_SHARED_VALIDATE
for hppa and unknown value for other architectures).

Fixes: v4.21~59 ("xlat: update MAP_* constants")
2018-03-07 22:07:20 +00:00
Eugene Syromyatnikov
9495ddada4 Sort Ethernet protocols xlat
* defs.h (ethernet_protocols_size): New declaration.
* netlink_packet_diag.c (decode_packet_diag_req): Use
printxval_searchnn to print Ethernet protocols.
* sockaddr.c (ethernet_protocols_size): New constant, item count
in ethernet_protocols array.
(print_sockaddr_data_ll): Use printxval_search instead of
printxval to print Ethernet protocols.
* xlat/ethernet_protocols.in: Sort it by value, add comment
about the fact.

Co-Authored-by: Dmitry V. Levin <ldv@altlinux.org>
2018-03-07 18:13:29 +00:00
Eugene Syromyatnikov
9611ebbb97 Change sorted arrays to be terminated with XLAT_END like unsorted arrays
It is quite unwieldy to have this distinction between sorted and
unsorted arrays when we can just decrement the size in a wrapper.

* defs.h (printxval_search): Decrement array size.
* xlat/fsmagic.in (#unterminated): Remove.
* xlat/hw_breakpoint_type.in (#unterminated): Remove.
* xlat/perf_hw_cache_id.in (#unterminated): Remove.
* xlat/perf_hw_cache_op_id.in (#unterminated): Remove.
* xlat/perf_hw_cache_op_result_id.in (#unterminated): Remove.
* xlat/perf_hw_id.in (#unterminated): Remove.
* xlat/perf_sw_ids.in (#unterminated): Remove.
* xlat/perf_type_id.in (#unterminated): Remove.
* xlat/gen.sh (gen_header): Remove #unterminated support.

Co-Authored-by: Dmitry V. Levin <ldv@altlinux.org>
2018-03-07 18:13:29 +00:00
Eugene Syromyatnikov
07a6399dd6 strace.1.in: add a note about tracing of scripts without shebang
* strace.1.in (.SH NOTES): Note that tracing of scripts without shebang
won't work.

Reported-by: Mike Parker
Closes: https://github.com/strace/strace/issues/46
2018-03-06 23:52:08 +00:00
Eugene Syromyatnikov
e4e34b31ab strace.1.in: mention that -c suppresses regular output
As the note that -C makes strace "also print regular output" can be
easily overlooked.

* strace.1.in (.SS Statistics) <.TP .B \-c>: Mention that -c supresses
regular output.
2018-03-06 23:52:08 +00:00
Eugene Syromyatnikov
08e1a244eb errnoent.h: add ERECALLCONFLICT
* linux/errnoent.h ([530]): Add ERECALLCONFLICT error introduced by
Linux commit v4.7-rc1~40^2~6.
* linux/alpha/errnoent.h ([530]): Likewise.
* linux/hppa/errnoent.h ([530]): Likewise.
* linux/mips/errnoent.h ([530]): Likewise.
* linux/sparc/errnoent.h ([530]): Likewise.
2018-03-06 23:52:08 +00:00
Eugene Syromyatnikov
f5feb87faa xlat: add BPF_F_ALLOW_MULTI constant
* xlat/bpf_attach_flags.in (BPF_F_ALLOW_MULTI): New constant, introduced
by Linux commit v4.15-rc1~84^2~558^2~7.
2018-03-06 23:52:08 +00:00
Eugene Syromyatnikov
edc666f7ce xlat: add BPF_MAP_TYPE_CPUMAP constant
* xlat/bpf_map_types.in (BPF_MAP_TYPE_CPUMAP): New constant, introduced
by Linux commit v4.15-rc1~84^2~427^2~4.
2018-03-06 23:52:08 +00:00
Eugene Syromyatnikov
94810c80f9 tests/test_printstrn.c: do not declare i again 2018-03-06 23:52:08 +00:00
Eugene Syromyatnikov
87cd971e49 tests/s390_sthyi.c: make utility functions inline
When built with --enable-gcc-Werror, s390_sthyi test build fails
with the following error:

	s390_sthyi.c:63:1: error: ‘print_u8’ defined but not used [-Werror=unused-function]
	 print_u8(const char *prefix, unsigned char *buf, unsigned int offs, bool zero)
	 ^~~~~~~~

Apparently, after some back and forth, all occurrences of printing u8
values landed under verbose printing, so this function is no longer
used in non-verbose mode.  Let's avoid this in the future by inlining
all the utility functions in this test.

* tests/s390_sthyi.c (print_0x8, print_u8, print_u16, print_x32,
print_weight, ebcdic2ascii, is_empty, print_ebcdic): Add inline
qualifier.
[!VERBOSE] (is_empty): Remove "# if VERBOSE" guard.
2018-03-06 23:52:08 +00:00
Eugene Syromyatnikov
bad2d7437c btrfs: print struct btrfs_ioctl_logical_ino_args.flags field
The field has been introduced in Linux commit v4.15-rc1~135^2~17.

* btrfs.c: Implement decoding of
struct btrfs_ioctl_logical_ino_args.flags field.
* configure.ac: Check for struct btrfs_ioctl_logical_ino_args.flags
presence in linux/btrfs.h.
* tests/btrfs.c: Update expected output, add additional checks.
* xlat/btrfs_logical_ino_args_flags.in: New file.
2018-03-06 23:52:08 +00:00
Eugene Syromyatnikov
1ed1866ebd btrfs.c: print __u64 fields with pointer semantics using printaddr64
* btrfs.c (btrfs_ioctl) <case BTRFS_IOC_INO_PATHS>: Print fspath field
with printaddr64.
(btrfs_ioctl) <case BTRFS_IOC_LOGICAL_INO>: Print inodes field with
printaddr64.
* tests/btrfs.c: Add checks for NULL in fspath and inodes fields.
* NEWS: Mention it.
2018-03-06 23:52:08 +00:00
Eugene Syromyatnikov
84c03b20b4 util.c: introduce printaddr64
Sometimes, 64-bit value is expected to be interpreted as an address
(in BTRFS ioctl interface, for example).

* defs.h (printaddr64): New declaration.
* util.c (printaddr64): Rename from printaddr, change argument type
to uint64_t.
(printaddr): Turn into a thin wrapper around printaddr64.
(printnum_addr_int, printnum_addr_int64): Use printaddr64 instead of
printaddr.  printnum_addr_int64 is not used outside the cases where
kernel_long is less or equal than 64 bit currently, so this change
should be safe.
2018-03-06 23:52:08 +00:00
Eugene Syromyatnikov
beafdd36e1 prctl: add decoding of PR_SVE_SET_VL and PR_SVE_GET_VL commands
These commands were introduced in Linux commit v4.15-rc1~110^2~9.

* xlat/pr_sve_vl_flags.in: New file.
* xlat/prctl_options.in: Likewise.
* prctl.c: Include "xstring.h" and "xlat/pr_sve_vl_flags.h".
[!PR_SVE_VL_LEN_MASK] (PR_SVE_VL_LEN_MASK): New macro constant.
(sprint_sve_val): New function.
(SYS_FUNC(prctl)): Add decoding for PR_SVE_GET_VL and PR_SVE_SET_VL
commands.
* NEWS: Mention it.
2018-03-06 23:52:08 +00:00
Eugene Syromyatnikov
fd02ce4ff8 Implement PTRACE_SECCOMP_GET_METADATA ptrace request decoding
* defs.h (seccomp_filter_flags): New declaration.
* process.c (SYS_FUNC(ptrace)): Implement PTRACE_SECCOMP_GET_METADATA
request decoding.
* ptrace.h [!PTRACE_SECCOMP_GET_METADATA] (PTRACE_SECCOMP_GET_METADATA):
New macro constant.
* xlat/ptrace_cmds.in (PTRACE_SECCOMP_GET_METADATA): New constant.
* tests/ptrace.c (main): Add some checks for PTRACE_SECCOMP_GET_METADATA
request decoding.
* NEWS: Mention it.

Co-Authored-by: Dmitry V. Levin <ldv@altlinux.org>
2018-03-06 23:52:08 +00:00
0b03de74bc build: prepare for -Wimplicit-fallthrough=5
* gcc_compat.h (ATTRIBUTE_FALLTHROUGH): New macro.
* block.c (block_ioctl): Use it instead of "fall through" comment.
* btrfs.c (btrfs_ioctl): Likewise.
* loop.c (loop_ioctl): Likewise.
* mtd.c (mtd_ioctl): Likewise.
* rtc.c (rtc_ioctl): Likewise.
* v4l2.c (v4l2_ioctl): Likewise.
* dm.c (dm_decode_values): Likewise.
* process.c (SYS_FUNC(ptrace)): Likewise.
* quota.c (decode_cmd_data): Likewise.
* ucopy.c (umovestr): Likewise.
* unwind.c (unwind_print_stacktrace, unwind_capture_stacktrace)):
Likewise.
* term.c (term_ioctl): Add ATTRIBUTE_FALLTHROUGH.
* ioctl.c (ioctl_decode) [ALPHA || POWERPC]: Likewise.
* m4/st_warn_cflags.m4 (gl_WARN_ADD): Add -Wimplicit-fallthrough=5.
* tests/ioctl_v4l2.c (init_v4l2_format): Reorganize the switch statement
without implicit fallthrough.
2018-03-06 23:52:08 +00:00