Dmitry V. Levin [Fri, 16 Mar 2018 00:55:58 +0000 (00:55 +0000)]
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.
Dmitry V. Levin [Fri, 16 Mar 2018 00:55:58 +0000 (00:55 +0000)]
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.
* 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>
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
Dmitry V. Levin [Wed, 14 Mar 2018 21:15:55 +0000 (21:15 +0000)]
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).
Dmitry V. Levin [Tue, 13 Mar 2018 13:19:02 +0000 (13:19 +0000)]
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.
Chen Jingpiao [Sat, 10 Mar 2018 01:44:35 +0000 (09:44 +0800)]
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.
Chen Jingpiao [Thu, 8 Mar 2018 14:53:45 +0000 (22:53 +0800)]
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.
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.
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).
* 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>
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.
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.
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.
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.
Add new BPF_PROG_TYPE_CGROUP_DEVICE eBPF program type and new
BPF_CGROUP_DEVICE eBPF program attach type, added in Linux commit
v4.15-rc1~84^2~120^2~2.
* xlat/bpf_attach_type.in (BPF_CGROUP_DEVICE): New constant.
* xlat/bpf_prog_types.in (BPF_PROG_TYPE_CGROUP_DEVICE): Likewise.
* NEWS: Mention it.
Remove some duplicating definitions and add the new ones.
* xlat/evdev_keycode.in (KEY_HANGUEL): Remove, an alternative name for
KEY_HANGEUL.
(KEY_DIRECTION): Remove, an alternative name for KEY_ROTATE_DISPLAY.
(KEY_BRIGHTNESS_ZERO): Remove, an alternative name for
KEY_BRIGHTNESS_AUTO.
(KEY_WIMAX): Remove, an alternative name for KEY_WWAN.
(BTN_A): Remove, an alternative name for BTN_SOUTH.
(BTN_B): Remove, an alternative name for BTN_EAST.
(BTN_X): Remove, an alternative name for BTN_NORTH.
(BTN_Y): Remove, an alternative name for BTN_WEST.
(BTN_STYLUS3): New constant, added in Linux commit v4.15-rc1~114^2^2~1.
(KEY_BRIGHTNESS_TOGGLE): Remove, an alternative name for
KEY_DISPLAYTOGGLE.
(KEY_ROTATE_LOCK_TOGGLE): New constant, added in Linux commit
v4.16-rc1~54^2~67.
(KEY_DATA): New constant, added in Linux commit v4.9-rc8~12^2.
(KEY_ONSCREEN_KEYBOARD): New constant, added in Linux commit
v4.12-rc1~126^2~2^12~5.
* NEWS: Mention it.
xlat: provide fallback definitions for SCTP socket option constants
Values for SCTP_GET_PEER_ADDRS_NUM_OLD, SCTP_GET_PEER_ADDRS_OLD,
SCTP_GET_LOCAL_ADDRS_NUM_OLD, SCTP_GET_LOCAL_ADDRS_OLD are reconstructed
from Linux commit v2.6.33-rc1~388^2~167^2~7.
xlat: update the list of SCTP socket option constants
* xlat/socksctpoptions.in (SCTP_DELAYED_ACK): Rename to...
(SCTP_DELAYED_SACK): ...this, per Linux commit v2.6.38-rc2~33^2.
(SCTP_SOCKOPT_PEELOFF_FLAGS): New constant, introduced in Linux commit
v4.13-rc1~157^2~39.
(SCTP_STREAM_SCHEDULER): New constant, introduced in Linux commit
v4.15-rc1~84^2~567^2~3.
(SCTP_STREAM_SCHEDULER_VALUE): New constant, introduced in Linux commit
v4.15-rc1~84^2~567^2~2.
(SCTP_INTERLEAVING_SUPPORTED): New constant, introduced in Linux commit
v4.16-rc1~123^2~384^2~11.
* NEWS: Mention it.
xlat: update the list of Ethernet protocol constants
* xlat/ethernet_protocols.in (ETH_P_ERSPAN2): New constant, introduced
in Linux commit v4.16-rc1~123^2~355^2~2.
(ETH_P_IBOE): New constant, introduced in commit v4.11-rc1~73^2~74.
* NEWS: Mention it.
* xlat/v4l2_pix_fmts.in: New file.
* xlat/v4l2_sdr_fmts.in: Likewise.
* v4l2.c [!v4l2_fourcc_be] (v4l2_fourcc_be): New macro.
(print_pixelformat): Add xlat parameter, print constant name
as a comment if it has been found in xlat.
(print_v4l2_fmtdesc, print_v4l2_frmivalenum): Pass v4l2_pix_fmts
to print_pixelformat.
(print_v4l2_format_fmt) <case V4L2_BUF_TYPE_VIDEO_CAPTURE, case
V4L2_BUF_TYPE_VIDEO_OUTPUT, case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE,
case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE, case V4L2_BUF_TYPE_VBI_CAPTURE,
case V4L2_BUF_TYPE_VBI_OUTPUT>: Pass v4l2_pix_fmts to print_pixelformat.
(print_v4l2_format_fmt) <case V4L2_BUF_TYPE_SDR_OUTPUT, case
V4L2_BUF_TYPE_SDR_CAPTURE>: Pass v4l2_sdr_fmts to print_pixelformat.
* tests/v4l2.c: Test it, update expected output.
* NEWS: Mention it.
v4l2_fourcc(a, b, c, d) is defined as (a | (b << 8) | (c << 16) | (d << 24)
regardless of endianness (no mnemonic on big-endian architectures),
so we don't need special handling for WORDS_BIGENDIAN both in decoder
and in the test.
* v4l2.c (print_pixelformat): Change initialisation to a simple
assignment of character array.
* tests/ioctl_v4l2.c [WORDS_BIGENDIAN]: Remove.
* NEWS: Mention this fix.
printfd: print character/block device number in -yy mode
* util.c: Include <sys/stat.h>, <sys/sysmacros.h>,
and "largefile_wrappers.h".
(printsocket, printdev): New functions.
(printfd): Move socket matching/printing logic to printsocket. Check
also for printdev. Escape opening angle bracket in addition to closing angle
bracket as it can show up as a separator in printdev.
* tests/fsync-y.c: Update expected output.
* strace.1.in: Mention this.
* NEWS: Likewise.
Co-Authored-by: Dmitry V. Levin <ldv@altlinux.org>
util.c: add support for additional escape characters in string_quote
Quotes are not always used to denote string limits; printfd uses angle
brackets for that, for example. As result, mechanism for supplying
set of additional characters in order to avoid ambiguities regarding
the end of the quoted string is needed.
* defs.h (string_quote): Add escape_chars parameter.
(print_quoted_string_ex): New function prototype.
* util.c (string_quote): Add escape_chars parameter.
(print_quoted_string_ex): Rename from print_quoted_string, add
escape_chars parameter, pass it to string_quote call.
(print_quoted_string): Turn into a thin wrapper around
print_quoted_string_ex.
(printstr_ex): Pass NULL as escape_chars argument of string_quote call.
* socketutils.c (unix_parse_response): Pass NULL as escape_chars
argument of string_quote call.
* tests/print_quoted_string.c (print_octal): New function.
print_quoted_memory_ex): Use it. Add escape_chars parameter.
(print_quoted_memory): Pass NULL as escape_chars argument
of print_quoted_memory_ex call.
* tests/tests.h (print_quoted_string_ex, print_quoted_memory_ex): Add
escape_chars parameter.
* tests/fsync-y.c: Pass NULL as escape_chars argument of
print_quoted_string_ex call.
Co-Authored-by: Dmitry V. Levin <ldv@altlinux.org>
tests: add print_quoted_string_ex and print_quoted_memory_ex functions
* tests/tests.h (print_quoted_string_ex, print_quoted_memory_ex): New
declarations.
* tests/print_quoted_string.c (print_quoted_string_ex): New function,
a thin wrapper around print_quoted_memory_ex wrapper.
(print_quoted_memory_ex): Rename from print_quoted_memory, add quote
argument.
(print_quoted_memory): Turn into a thin wrapper around
print_quoted_memory_ex.
Do not go full octal if the next char is '8' or '9'
* util.c (string_quote): Change the upper limit for the next character
in unabbreviated octal printing from '9' to '7'.
* tests/print_quoted_string.c (print_quoted_memory): Likewise.
* linux/inet_diag.h (INET_DIAG_BC_S_EQ, INET_DIAG_BC_D_EQ): New
enumeration items introduced by linux kernel commit v4.16-rc1~123^2~259.
* xlat/inet_diag_bytecodes.in (INET_DIAG_BC_S_EQ, INET_DIAG_BC_D_EQ): New
constants.
* NEWS: Mention it.
POLL_BUSY_LOOP was introduced by linux kernel commit v3.11-rc1~64^2~129
as POLL_LL and then renamed in v3.11-rc1~64^2~9. POLLRDHUP was
introduced by linux kernel commit v2.6.17-rc1~796. POLLMSG and
POLLREMOVE predate git repository. POLLFREE was introduced by linux
kernel commit v3.3-rc5~8 for internal use only.
* xlat/pollflags.in (POLLMSG, POLLREMOVE, POLLRDHUP, POLL_BUSY_LOOP):
New constants.
* NEWS: Mention it.
* xlat/rtnl_tc_attrs.in (TCA_HW_OFFLOAD, TCA_INGRESS_BLOCK,
TCA_EGRESS_BLOCK): New constants introduced by linux kernel commits
v4.15-rc4~13^2~5^2~2 and v4.16-rc1~123^2~139^2~5.
* rtnl_tc.c (tcmsg_nla_decoders) <TCA_HW_OFFLOAD, TCA_INGRESS_BLOCK,
TCA_EGRESS_BLOCK>: New items.
* rtnl_link.c (decode_ifla_event): New function.
(ifinfomsg_nla_decoders) <[IFLA_EVENT]>: Use it.
* xlat/rtnl_ifla_events.in: New file.
* NEWS: Mention it.
Follow a common practice for printing address:port pair to distinguish
address parts delimiter from address/port delimiter.
* socketutils.c (inet_parse_response) <ob, cb>: New variables,
initialise them to open/closing brackets or empty strings based
on address family.
(inet_parse_response): Print ob and cb around src_buf and dst_buf.
* NEWS: Mention this improvement.
Dmitry V. Levin [Mon, 26 Feb 2018 23:22:24 +0000 (23:22 +0000)]
strace.spec.in: add gcc to build requirements
There are rumors in circulation that some rpm-based distributions
are going to exclude gcc from their default build environments.
Workaround this policy silliness by adding gcc to build requirements.
Dmitry V. Levin [Mon, 26 Feb 2018 23:22:24 +0000 (23:22 +0000)]
Move definitions of fopen_for_input to largefile_wrappers.h
* largefile_wrappers.h (fopen_for_input): Define along with
fopen_for_output.
* mmap_cache.c: Include "largefile_wrappers.h".
(fopen_for_input): Remove.
Masatake YAMATO [Fri, 16 Feb 2018 19:37:13 +0000 (04:37 +0900)]
mmap_cache: add function to enable mmap_cache
mmap_cache was enabled indirectly via unwind feature. As now mmap_cache
can be used by other part of strace, a way to enable mmap_cache directly
is needed.
* defs.h (mmap_cache_enable, mmap_cache_is_enabled): New function
prototypes.
* mmap_cache.c (use_mmap_cache): New file local variable.
(mmap_cache_enable, mmap_cache_is_enabled): New functions.
* syscall.c (syscall_exiting_decode): Use mmap_cache_is_enabled()
instead of stack_trace_enabled.
* unwind.c (unwind_init): Invoke mmap_cache_enable.
Masatake YAMATO [Fri, 16 Feb 2018 19:37:12 +0000 (04:37 +0900)]
mmap_cache, unwind: lift up mmap_cache_delete invocation from unwind.c
mmap_cache_delete function used to be called by destructor of unwind
related code. Now that other parts can use mmap cache,
mmap_cache_delete is called separately from unwind_tcb_fin.
Masatake YAMATO [Fri, 16 Feb 2018 19:37:11 +0000 (04:37 +0900)]
mmap_cache: record protection bits
To make mmap_cache reusable, records protection bits of mmap entries.
* defs.h (mmap_cache_protection): New enum.
* mmap_cache.c (build_mmpa_cache): Don't ignore entries that are not
executable, just record the protection bits here.
* unwind.c (print_stack_frame): Ignore entries that are not executable.
Masatake YAMATO [Fri, 16 Feb 2018 19:37:10 +0000 (04:37 +0900)]
mmap_cache: move code for searching a mmap cache from unwind
print_stack_frame function in unwind.c searches a mmap entry in mmap
cache. The found entry is then used for unwinding. However, a function
searching for a mmap entry may be useful for other purposes than
unwinding.
This change re-factors the function; code for searching an entry is
now defined as a stand-alone function named mmap_cache_search.
* defs.h (mmap_cache_search): New function prototype.
print_stack_frame.
* mmap_cached.c (mmap_cache_search): New function derived from
print_stack_frame.
* unwind.c (print_stack_frame): Use it.
Dmitry V. Levin [Sat, 24 Feb 2018 20:42:03 +0000 (20:42 +0000)]
mpers.awk: use stdint.h instead of inttypes.h
As <inttypes.h> is included in files generated by mpers.awk to obtain
definitions of uintNN_t types provided by <stdint.h>, replace the former
header with the latter.
* mpers.awk: Use <stdint.h> instead of <inttypes.h>.
* mpers_test.sh: Update expected output.
Dmitry V. Levin [Wed, 21 Feb 2018 23:03:27 +0000 (23:03 +0000)]
m68k: fix build
When <sys/reg.h> is included after <linux/ptrace.h>, the build fails
on m68k with the following diagnostics:
In file included from /usr/include/linux/ptrace.h:101:0,
from ptrace.h:51,
from sigreturn.c:2:
/usr/include/m68k-linux-gnu/sys/reg.h:26:3: error: expected identifier
before numeric constant
PT_D1 = 0,
^
Apparently, the only architecture where strace needs definitions
provided by <sys/reg.h> is x86_64, other three (m68k, tile, and x86)
are fine with definitions already provided by <linux/ptrace.h>.
Fix the issue by getting rid of <sys/reg.h> and defining necessary
macros in linux/x86_64/arch_regs.h file.
* configure.ac (AC_CHECK_HEADERS): Remove sys/reg.h.
* regs.h: Do not include <sys/reg.h>.
* linux/x86_64/arch_regs.h (R15, R14, R13, R12, RBP, RBX, R11, R10,
R9, R8, RAX, RCX, RDX, RSI, RDI, ORIG_RAX, RIP, CS, EFLAGS, RSP, SS,
FS_BASE, GS_BASE, DS, ES, FS, GS): New macros.
* NEWS: Mention this fix.
Dmitry V. Levin [Thu, 15 Feb 2018 11:07:03 +0000 (11:07 +0000)]
Demote sourceforge.net
https://sourceforge.net/p/strace/code/ is defunct: it doesn't accept
new commits for too long.
Likewise, https://sourceforge.net/projects/strace/files/ doesn't accept
new files for too long.
* README.md: Remove sourceforge.net URL.
* debian/copyright: Replace the sourceforge.net based strace project URL
with a github based one.
* strace.spec.in (Source): Likewise.