]> granicus.if.org Git - strace/log
strace
6 years agobpf: print numa_node using xlat
Eugene Syromyatnikov [Fri, 2 Mar 2018 23:30:32 +0000 (00:30 +0100)]
bpf: print numa_node using xlat

As the value of -1 has a special meaning.  The issue is complicated
by the fact that this constant is not exported by UAPI.

* xlat/numa_node.in: New file.
* bpf.c (BEGIN_BPF_CMD_DECODER(BPF_MAP_CREATE)): Print numa_node field
using printxvals_ex with a special xlat style.

6 years agobtrfs: use umove_or_printaddr_ignore_syserror instead of u_error mangling
Eugene Syromyatnikov [Wed, 14 Mar 2018 20:08:34 +0000 (21:08 +0100)]
btrfs: use umove_or_printaddr_ignore_syserror instead of u_error mangling

* btrfs.c (MPERS_PRINTER_DECL(btrfs_ioctl)) <case
BTRFS_IOC_TREE_SEARCH_V2>: Use umove_or_printaddr_ignore_syserror
instead of tcp->u_error mangling around umove_or_printaddr call.

6 years agodefs.h: introduce umove_or_printaddr{,64}_ignore_syserror wrappers
Eugene Syromyatnikov [Wed, 14 Mar 2018 20:02:47 +0000 (21:02 +0100)]
defs.h: introduce umove_or_printaddr{,64}_ignore_syserror wrappers

* defs.h (umove_or_printaddr64_ignore_syserror): New macro, a thin
wrapper around umoven_or_printaddr64_ignore_syserror.
(umove_or_printaddr_ignore_syserror): New macro, a thin wrapper around
umoven_or_printaddr_ignore_syserror.

6 years agoprint_fields.h: add PRINT_FIELD_XVAL_U for printing xlat in %u format
Eugene Syromyatnikov [Tue, 13 Mar 2018 22:51:54 +0000 (23:51 +0100)]
print_fields.h: add PRINT_FIELD_XVAL_U for printing xlat in %u format

* print_fields.h (PRINT_FIELD_XVAL_U): New macro.

6 years agoprint_fields.h: add PRINT_FIELD_U64 for printing u64 with UINT64_MAX handling
Eugene Syromyatnikov [Tue, 13 Mar 2018 22:46:14 +0000 (23:46 +0100)]
print_fields.h: add PRINT_FIELD_U64 for printing u64 with UINT64_MAX handling

* print_fields.h (PRINT_FIELD_U64): New macro.

6 years agobpf_sock_filter: use print_xlat32
Eugene Syromyatnikov [Sat, 10 Mar 2018 05:16:17 +0000 (06:16 +0100)]
bpf_sock_filter: use print_xlat32

We can't simply use print_xlat here due to the way those SKF_*_OFF
constants are defined.

* bpf_sock_filter.c (print_sock_filter_k): Use print_xlat32 for printing
SKF_AD_OFF, SKF_NET_OFF, and SKF_LL_OFF named constants.

6 years agodefs.h: add print_xlat32 macro
Eugene Syromyatnikov [Thu, 12 Apr 2018 22:57:46 +0000 (00:57 +0200)]
defs.h: add print_xlat32 macro

For those cases where inadvertent sign extension is possible.

* defs.h (print_xlat32): New macro, a wrapper for print_xlat_ex.

6 years agoopen: use print_xlat_d in print_dirfd
Eugene Syromyatnikov [Sat, 10 Mar 2018 05:56:21 +0000 (06:56 +0100)]
open: use print_xlat_d in print_dirfd

* open.c (print_dirfd): Use print_xlat_d for printing AT_FDCWD named
constant.

6 years agofanotify: use print_xlat_d
Eugene Syromyatnikov [Sat, 10 Mar 2018 05:17:31 +0000 (06:17 +0100)]
fanotify: use print_xlat_d

* fanotify.c (SYS_FUNC(fanotify_mark)): Use print_xlat_d for printing
FAN_NOFD named constant.

6 years agoAdd print_xlat_u and print_xlat_d shorthands
Eugene Syromyatnikov [Sat, 7 Apr 2018 00:11:07 +0000 (02:11 +0200)]
Add print_xlat_u and print_xlat_d shorthands

Add variants of print_xlat with various value printing formats.

* defs.h (print_xlat_u, print_xlat_d): New macro, a wrapper for
print_xlat_ex.

6 years agoxlat: introduce XLAT_STYLE_FMT_D
Eugene Syromyatnikov [Wed, 4 Apr 2018 11:24:54 +0000 (13:24 +0200)]
xlat: introduce XLAT_STYLE_FMT_D

As there are some possible users for it, apparently.

* defs.h (XLAT_STYLE_FORMAT_MASK): Update the value in order to
accommodate XLAT_STYLE_FMT_D.
(enum xlat_style) <XLAT_STYLE_FMT_D>: New enumeration entity.
(printxval64_d, printxval_d): New function, a shorthand for
printxvals_ex with a single xlat and XLAT_STYLE_FMT_D xlat style.
* xlat.c (sprint_xlat_val): Handle XLAT_STYLE_FMT_D.

6 years agodefs.h: add shorthands for printing xval with XLAT_STYLE_FMT_U
Eugene Syromyatnikov [Wed, 4 Apr 2018 11:22:52 +0000 (13:22 +0200)]
defs.h: add shorthands for printing xval with XLAT_STYLE_FMT_U

* defs.h (printxval_u, printxval64_u): New function, a shorthand for
printxvals_ex with a single xlat and XLAT_STYLE_FMT_U as a style.

6 years agoAdd support for various xlat formats
Eugene Syromyatnikov [Sat, 10 Mar 2018 06:20:26 +0000 (07:20 +0100)]
Add support for various xlat formats

Since xlat printing routines now have a notion of "style" that should be
used for printing xlat values, we can also employ this argument for
passing information about number printing format (unsigned decimal
or hexadecimal, so far).

* defs.h (XLAT_STYLE_FORMAT_SHIFT, XLAT_STYLE_FORMAT_MASK): New macro
constant.
(enum xlat_style) <XLAT_STYLE_FMT_X, XLAT_STYLE_FMT_U>: New enumeration
entities.
* xlat.c (xlat_verbose, xlat_format): New macro for checking specific
aspect of style argument.
(get_xlat_style): Use xlat_verbose for checking xlat verbosity style.
(sprint_xlat_val, print_xlat_val): New function, for easing printing
raw constant number with respect to printing format style.
(printxvals_ex, sprintxval_ex, printxval_searchn_ex,
printxval_searchn_ex, sprintflags_ex, printflags_ex, print_xlat_ex):
Use xlat_verbose macro for xlat verbosity style checks. Use
print_xlat_val instead of direct raw xlat value printing.

6 years agov4l2: use print_xlat in print_v4l2_queryctrl
Eugene Syromyatnikov [Sat, 10 Mar 2018 05:56:40 +0000 (06:56 +0100)]
v4l2: use print_xlat in print_v4l2_queryctrl

* v4la.c (print_v4l2_queryctrl): Use print_xlat for printing
V4L2_CTRL_FLAG_NEXT_CTRL named constant.

6 years agoprctl: use print_xlat_ex to print PR_SET_PTRACER_ANY
Eugene Syromyatnikov [Sat, 10 Mar 2018 05:29:41 +0000 (06:29 +0100)]
prctl: use print_xlat_ex to print PR_SET_PTRACER_ANY

We cannot simply use print_xlat as PR_SET_PTRACER_ANY is defined
differently in kernel headers.

* prctl.c (SYS_FUNC(prctl)) <case PR_SET_PTRACER>: Use print_xlat_ex
for printing PR_SET_PTRACER_ANY named constant.

6 years agonlattr: use print_xlat
Eugene Syromyatnikov [Sat, 10 Mar 2018 05:18:51 +0000 (06:18 +0100)]
nlattr: use print_xlat

* nlattr.c (print_nlattr): Use print_xlat for printing NLA_F_NESTED and
NLA_F_NET_BYTEORDER named constants.

6 years agoipc_defs.h: use print_xlat
Eugene Syromyatnikov [Sat, 10 Mar 2018 05:18:04 +0000 (06:18 +0100)]
ipc_defs.h: use print_xlat

* ipc_defs.h (PRINTCTL): Use print_xlat for printing IPC_64 named
constant.

6 years agofutex: use print_xlat
Eugene Syromyatnikov [Sat, 10 Mar 2018 05:17:47 +0000 (06:17 +0100)]
futex: use print_xlat

* futex.c [!FUTEX_OP_OPARG_SHIFT] (FUTEX_OP_OPARG_SHIFT): New macro
constant.
(SYS_FUNC(futex)): Use print_xlat for printing FUTEX_OP_OPARG_SHIFT
named constant.

6 years agoipc: use printxval for printing key
Eugene Syromyatnikov [Sat, 10 Mar 2018 05:17:11 +0000 (06:17 +0100)]
ipc: use printxval for printing key

Convert explicit constant printing logic into a printxval call in order
to account for xlat style setting.

* defs.h (ipc_private): New xlat array declaration.
* ipc_msg.c (SYS_FUNC(msgget)): Use printxval for printing IPC_PRIVATE.
* ipc_sem.c (SYS_FUNC(semtimedop)): Likewise.
* ipc_shm.c (SYS_FUNC(shmget)): Likewise.
* xlat/ipc_private.in: New file.

6 years agomount: use print_xlat for printing MS_MGC_VAL
Eugene Syromyatnikov [Sat, 10 Mar 2018 04:38:39 +0000 (05:38 +0100)]
mount: use print_xlat for printing MS_MGC_VAL

* mount.c (SYS_FUNC(mount)): Use print_xlat for printing MS_MGC_VAL
named constant.

6 years agoIntroduce print_xlat and print_xlat_ex
Eugene Syromyatnikov [Sat, 10 Mar 2018 04:51:55 +0000 (05:51 +0100)]
Introduce print_xlat and print_xlat_ex

print_xlat_ex prints a named constant in accordance with xlat style
provided, print_xlat is a thin wrapper around print_xlat_ex that passes
stringified constant name as a string and XLAT_STYLE_DEFAULT as a style.

* defs.h (print_xlat_ex): New function prototype.
(print_xlat): New macro, a thin wrapper around print_xlat_ex.
* xlat.c (print_xlat_ex): New function.

Co-Authored-by: Dmitry V. Levin <ldv@altlinux.org>
6 years agoIntroduce XLAT_STYLE_DEFAULT
Eugene Syromyatnikov [Sat, 10 Mar 2018 04:12:02 +0000 (05:12 +0100)]
Introduce XLAT_STYLE_DEFAULT

This will be needed later, with the introduction of user-configurable
xlat style setting (stored in xlat_verbosity variable).

* defs.h (XLAT_STYLE_VERBOSITY_MASK): New macro constant.
(enum xlat_style) <XLAT_STYLE_DEFAULT>: New enumeration entity.
(xlat_verbosity): New external declaration.
(printxvals, printxval_searchn, printxval_search_ex, sprintxval,
sprintflags, printflags64): Use XLAT_STYLE_DEFAULT instead of
XLAT_STYLE_ABBREV.
* strace.c (xlat_verbosity): New variable.
* xlat.c (get_xlat_style): New function.
(printxvals_ex, sprintxval_ex, printxval_searchn_ex, sprintflags_ex,
printflags_ex): Use it.

6 years agoIntroduce xlat verbosity styles
Eugene Syromyatnikov [Sat, 10 Mar 2018 03:48:33 +0000 (04:48 +0100)]
Introduce xlat verbosity styles

* defs.h (printxvals_ex): Rename from printxvals, add style argument.
(enum xlat_style): New enumeration.
(printxvals): New macro, a wrapper for printxvals_ex.
(printxval_searchn_ex): Rename from printxval_searchn, add style
argument.
(printxval_searchn): New macro, a wrapper for printxval_searchn_ex.
(printxval_search_ex): New macro, a wrapper for printxval_searchn_ex.
(sprintxval_ex): Rename from sprintxval, add style argument.
(sprintxval): New macro, a wrapper for sprintxval_ex.
(printflags_ex): Add style argument.
(sprintflags_ex): Rename from sprintflags, add style argument.
(sprintflags): New macro, a wrapper for sprintflags_ex.
(printflags64): Pass XLAT_STYLE_ABBREV as a style in printflags_ex call.
* netlink.c (decode_nlmsg_flags): Pass XLAT_STYLE_ABBREV as a style in
printflags_ex call.
* xlat.c (printxvals_ex): Rename from printxvals, add style argument,
handle it.
(sprintxval_ex): Rename from sprintxval, add style argument, handle it.
(printxval_searchn_ex): Rename from printxval_searchn, add style
argument, handle it.
(sprintflags_ex): Rename from sprintflags, add style argument,
handle it.
(printflags_ex): Add style argument, handle it.

Co-Authored-by: Dmitry V. Levin <ldv@altlinux.org>
References: https://github.com/strace/strace/issues/27

6 years agotests: robustify signal delivery test against kernel bugs
Dmitry V. Levin [Wed, 11 Apr 2018 22:01:37 +0000 (22:01 +0000)]
tests: robustify signal delivery test against kernel bugs

Recent kernel siginfo changes, namely, v4.14-rc1~60^2^2~1,
v4.16-rc1~159^2~37, and v4.16-rc1~159^2~39, introduced ABI regressions
that render the whole siginfo interface unreliable.

Looks like the kernel side is not eager to fix the breakage,
so here is a workaround.

* tests/signal_receive.c (s_sig, s_code, s_pid, s_uid): New volatile
variables.
(handler): Add siginfo_t parameter, save siginfo_t fields.
(sig_print): Remove.
(main): Rewrite.  Use variables saved by handler to print expected
siginfo output. Print diagnostics in case of siginfo mismatch.
* strace.spec.in (%check): Extract the diagnostics.

Closes: https://github.com/strace/strace/issues/21
6 years agoLift experimental status from stack tracing feature
Dmitry V. Levin [Wed, 11 Apr 2018 15:41:40 +0000 (15:41 +0000)]
Lift experimental status from stack tracing feature

* strace.1.in (.SH OPTIONS) <.B \-k>: Remove " (experimental)".
* strace.c (usage) [ENABLE_STACKTRACE]: Likewise.

6 years agoEnable stack tracing in packages on all architectures
Dmitry V. Levin [Sun, 8 Apr 2018 23:07:50 +0000 (23:07 +0000)]
Enable stack tracing in packages on all architectures

The stack tracing feature used to be enabled in packages on x86_64 only.
This change enables -k option on all architectures.

* debian/control (Build-Depends) [!amd64]: Add pkg-config, libdw-dev,
and libiberty-dev.
* strace.spec.in (BuildRequires) [!x86_64]: Add
%buildrequires_stacktrace.

6 years agoUse libdw-based unwinder in ci and packages
Dmitry V. Levin [Sun, 8 Apr 2018 23:07:50 +0000 (23:07 +0000)]
Use libdw-based unwinder in ci and packages

* ci/install-dependencies.sh (common_packages): Add pkg-config,
replace libunwind8-dev with libdw-dev.
* debian/control (Build-Depends) [amd64]: Add pkg-config,
replace libunwind-dev with libdw-dev.
* debian/rules (build-udeb/Makefile): Replace --without-libunwind
with --without-stacktrace.
* strace.spec.in (buildrequires_libunwind_devel): Rename
to buildrequires_stacktrace, replace libunwind-devel with
either elfutils-devel or libdw-devel.

6 years agotests: skip -k tests on unsupported architectures
Dmitry V. Levin [Wed, 11 Apr 2018 15:41:40 +0000 (15:41 +0000)]
tests: skip -k tests on unsupported architectures

* tests/strace-k.test: When actual strace -k output doesn't match the
expected output because of limited architecture support, skip the test
on architectures that are not currently supported by libdw.

6 years agounwind: add libdw as an unwinder
Masatake YAMATO [Tue, 13 Mar 2018 17:28:12 +0000 (02:28 +0900)]
unwind: add libdw as an unwinder

Implement alternative libdw-based unwinder for stack tracing.
Add --with-libdw configure option to control whether libdw can be used
as an unwinder.

* m4/st_libdw.m4: New file.
* m4/st_stacktrace.m4 (st_STACKTRACE): Invoke st_ARG_LIBDW and st_LIBDW,
check for mutually exclusive configure options,
(AM_CONDITIONAL): Add USE_LIBDW.
* unwind-libdw.c: New file.
* Makefile.am [USE_LIBDW] (strace_SOURCES): Append unwind-libdw.c.
[USE_LIBDW] (strace_CPPFLAGS): Append $(libdw_CPPFLAGS).
[USE_LIBDW] (strace_CFLAGS): Append $(libdw_CFLAGS).
[USE_LIBDW] (strace_LDFLAGS): Append $(libdw_LDFLAGS).
[USE_LIBDW] (strace_LDADD): Append $(libdw_LIBS).
* NEWS: Mention this improvement.

Closes: https://github.com/strace/strace/issues/12
Closes: https://github.com/strace/strace/issues/13
Co-Authored-by: Mark Wielaard <mjw@redhat.com>
Co-Authored-by: Dmitry V. Levin <ldv@altlinux.org>
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
6 years agotests: check corner cases of udev_monitor_netlink_header decoding
Dmitry V. Levin [Wed, 11 Apr 2018 15:41:40 +0000 (15:41 +0000)]
tests: check corner cases of udev_monitor_netlink_header decoding

* tests/netlink_kobject_uevent.c (test_nlmsg_type_kernel): Create
a tail-allocated udev_monitor_netlink_header object and pass it
to sys_send.
(test_nlmsg_type_udev): Likewise.  Check decoding of
udev_monitor_netlink_header object that ends in unmapped memory region.

6 years agotests: check decoding of udev_monitor_netlink_header
Harsha Sharma [Sun, 8 Apr 2018 18:18:56 +0000 (23:48 +0530)]
tests: check decoding of udev_monitor_netlink_header

* tests/netlink_kobject_uevent.c: Include <string.h>, <arpa/inet.h>,
and "netlink_kobject_uevent.h".
(test_nlmsg_type_udev, test_nlmsg_type_kernel): New functions.
(main): Use them.

6 years agonetlink: decode libudev netlink header
Harsha Sharma [Sat, 3 Mar 2018 11:11:43 +0000 (16:41 +0530)]
netlink: decode libudev netlink header

* defs.h (decode_netlink_kobject_uevent): New prototype.
* netlink.c (decode_netlink): Decode family kobject_uevent.
* netlink_kobject_uevent.h: New file.
* netlink_kobject_uevent.c: Likewise.
* Makefile.am (strace_SOURCES): Add them.

Co-Authored-by: Dmitry V. Levin <ldv@altlinux.org>
Signed-off-by: Harsha Sharma <harshasharmaiitr@gmail.com>
6 years agotests: check basic decoding of PTP_* ioctl commands
Harsha Sharma [Sun, 11 Mar 2018 13:30:50 +0000 (19:00 +0530)]
tests: check basic decoding of PTP_* ioctl commands

* tests/ioctl_ptp.c: New file.
* tests/gen_tests.in (ioctl_ptp): New entry.
* tests/pure_executables.list: Add ioctl_ptp.
* tests/.gitignore: Likewise.

Co-Authored-by: Dmitry V. Levin <ldv@altlinux.org>
6 years agobpf: decode BPF_PROG_QUERY command
Eugene Syromyatnikov [Thu, 1 Mar 2018 22:54:00 +0000 (23:54 +0100)]
bpf: decode BPF_PROG_QUERY command

BPF_PROG_QUERY was introduced in Linux commit v4.15-rc1~84^2~558^2~6.

* xlat/bpf_commands.in (BPF_PROG_QUERY): New constant.
* xlat/bpf_query_flags.in: New file.
* bpf.c: Include it.
(DECL_BPF_CMD_DECODER): Add priv argument for passing tcb private data.
(BEGIN_BPF_CMD_DECODER(BPF_PROG_QUERY)): New function.
(SYS_FUNC(bpf)) <bpf_cmd_decoders>: Add BPF_PROG_QUERY entry.
(SYS_FUNC(bpf)): Fetch buf on entering and exiting, pass buf on exiting,
retrieve private data on exiting, pass it to decoder as well, explicitly
rework rc handling logic for size argument printing.
* bpf_attr.h (struct BPF_PROG_QUERY_struct): New structure declaration.
(BPF_PROG_QUERY_struct_size, expected_BPF_PROG_QUERY_struct_size): New
macro.
* tests/bpf.c: Add checks for BPF_PROG_QUERY command.

6 years agoMake print_uint64 from btrfs.c globally available
Eugene Syromyatnikov [Mon, 5 Mar 2018 09:20:02 +0000 (10:20 +0100)]
Make print_uint64 from btrfs.c globally available

And rename it to print_uint64_array_member to make the name sensible
without additional context.

* defs.h (print_uint64_array_member): New function prototype.
* btrfs.c (print_uint64): Move...
* util.c (print_uint64_array_member): ...here, drop "static" qualifier.

6 years agoIntroduce umoven_or_printaddr64* functions
Eugene Syromyatnikov [Sun, 25 Mar 2018 09:54:18 +0000 (11:54 +0200)]
Introduce umoven_or_printaddr64* functions

Counterparts for umoven_or_printaddr/umoven_or_printaddr_ignore_syserror
that always print 64 bits of addr (as this is needed in bpf and btrfs
decoders).

* util.c (umoven_or_printaddr64): Rename from umoven_or_printaddr,
change addr argument type to uint64_t, call printaddr64 instead of
printaddr.
(umoven_or_printaddr64_ignore_syserror): Rename from
umoven_or_printaddr_ignore_syserror, change addr argument type to
uint64_t, call printaddr64 instead of printaddr.
* defs.h (umoven_or_printaddr64): Rename from umoven_or_printaddr,
change addr argument type to uint64_t.
(umoven_or_printaddr64_ignore_syserror): Rename from
umoven_or_printaddr_ignore_syserror, change addr argument type to
uint64_t.
(umove_or_printaddr64): New macro, a wrapper for umoven_or_printaddr64.
(umoven_or_printaddr): New function, a wrapper for
umoven_or_printaddr64.
(umoven_or_printaddr_ignore_syserror): New function, a wrapper for
umoven_or_printaddr64_ignore_syserror.

6 years agobpf_filter.c: add support for decoding eBPF instruction codes
Eugene Syromyatnikov [Thu, 22 Feb 2018 06:55:32 +0000 (07:55 +0100)]
bpf_filter.c: add support for decoding eBPF instruction codes

* bpf_filter.c (print_bpf_filter_code): Add extended argument, remove
static qualifier.  Add support for decoding eBPF instruction code.
* defs.h (print_bpf_filter_code): New declaration.
* xlat/ebpf_class.in: New file.
* xlat/ebpf_mode.in: Likewise.
* xlat/ebpf_op_alu.in: Likewise.
* xlat/ebpf_op_jmp.in: Likewise.
* xlat/ebpf_size.in: Likewise.

Co-Authored-by: Dmitry V. Levin <ldv@altlinux.org>
6 years agounwind: prepare configure subsystem for alternative unwinders
Dmitry V. Levin [Sat, 7 Apr 2018 23:35:45 +0000 (23:35 +0000)]
unwind: prepare configure subsystem for alternative unwinders

Introduce --enable-stacktrace configure option to control whether
-k option support is compiled in, --with-libunwind option remains
available to control whether libunwind can be used as an unwinder.

* m4/st_demangle.m4: New file.
* m4/st_libunwind.m4: Likewise.
* m4/st_stacktrace.m4: Likewise.
* configure.ac: Replace all libunwind and libiberty checks
with a single st_STACKTRACE invocation.
* Makefile.am: Conditionalize checks for USE_LIBUNWIND and USE_DEMANGLE
on ENABLE_STACKTRACE.
[ENABLE_STACKTRACE] (strace_SOURCES): Append unwind.c and unwind.h.
* strace.1.in: Replace libunwind with an unwinder-agnostic wording.
* defs.h: Replace USE_LIBUNWIND with ENABLE_STACKTRACE.
* strace.c: Likewise.
(print_version): Print stack-trace instead of stack-unwind.
* syscall.c: Replace USE_LIBUNWIND with ENABLE_STACKTRACE.
* tests/Makefile.am: Likewise.  Replace LIBUNWIND_TESTS
with STACKTRACE_TESTS.
* tests/strace-V.test: Update expected output.

6 years agobpf: implement decoding of prog_name and prog_ifindex fields
Eugene Syromyatnikov [Thu, 22 Feb 2018 02:22:48 +0000 (03:22 +0100)]
bpf: implement decoding of prog_name and prog_ifindex fields

* bpf.c (BEGIN_BPF_CMD_DECODER(BPF_PROG_LOAD)): Add support for decoding
of prog_name (introduced in Linux commit v4.15-rc1~84^2~605^2~4) and
prog_ifindex (introduced as prog_target_ifindex in v4.15-rc1~84^2~127^2~13,
renamed in v4.15-rc1~15^2~5^2~3^2~7).
* bpf_attr.h [!BPF_OBJ_NAME_LEN] (BPF_OBJ_NAME_LEN): New macro constant.
[BPF_OBJ_NAME_LEN]: Check that BPF_OBJ_NAME_LEN is equal to 16.
(struct BPF_PROG_LOAD_struct): Add prog_name and prog_ifindex fields.
(BPF_PROG_LOAD_struct_size, expected_BPF_PROG_LOAD_struct_size): Update.
* tests/bpf.c (init_BPF_PROG_LOAD_attr): Rename
to init_BPF_PROG_LOAD_attr3.
(print_BPF_PROG_LOAD_attr): Rename to print_BPF_PROG_LOAD_attr3.
(init_BPF_PROG_LOAD_attr4, print_BPF_PROG_LOAD_attr4): New functions.
(BPF_PROG_LOAD_checks): Check new decoding features.

6 years agobpf: add support for array fields
Eugene Syromyatnikov [Sun, 8 Apr 2018 18:09:06 +0000 (20:09 +0200)]
bpf: add support for array fields

* gen_bpf_attr_check.sh: Ignore field array size definition.
* m4/gen_bpf_attr_m4.sh (filter_entries): Likewise.

Co-Authored-by: Dmitry V. Levin <ldv@altlinux.org>
6 years agotests: robustify strace -k tests
Dmitry V. Levin [Sat, 7 Apr 2018 23:35:45 +0000 (23:35 +0000)]
tests: robustify strace -k tests

Allow __getpid as an alternative name for getpid,
allow __kernel_vsyscall after getpid.

* tests/strace-k.expected: New file.
* tests/strace-k-demangle.expected: Likewise.
* tests/Makefile.am (EXTRA_DIST): Add them.
* tests/strace-k-demangle.test (expected): Remove.
* tests/strace-k.test: Likewise.  Use grep to check the output.

6 years agoipc_msg: sign extend msgtyp in m32 personality
Eugene Syromyatnikov [Sat, 7 Apr 2018 02:08:44 +0000 (04:08 +0200)]
ipc_msg: sign extend msgtyp in m32 personality

msgtyp has to be treated as a signed type all the way from fetching
to printing.

* ipc_msg.c (fetch_msgrcv_args): Sign extend msgtyp when fetching.

6 years agostrace.spec.in: update Source URL
Dmitry V. Levin [Thu, 5 Apr 2018 19:35:58 +0000 (19:35 +0000)]
strace.spec.in: update Source URL

* strace.spec.in (Source): Change to https://strace.io/files/.

6 years agodebian: enable mpers support for ppc64el and s390x
Dmitry V. Levin [Thu, 5 Apr 2018 19:35:58 +0000 (19:35 +0000)]
debian: enable mpers support for ppc64el and s390x

* debian/control (Build-Depends) [ppc64el, s390x]: Add gcc-multilib.

6 years agoPost-release administrivia
Dmitry V. Levin [Thu, 5 Apr 2018 12:13:14 +0000 (12:13 +0000)]
Post-release administrivia

* NEWS: Add a header line for the next release.
* debian/changelog.in: Add a changelog entry for 4.22-1.
* strace.spec.in: Likewise.

6 years agoPrepare for 4.22 release v4.22
Dmitry V. Levin [Thu, 5 Apr 2018 04:05:06 +0000 (04:05 +0000)]
Prepare for 4.22 release

* NEWS: Update for 4.22 release.

6 years agoUpdate copyright headers
Dmitry V. Levin [Thu, 5 Apr 2018 01:40:00 +0000 (01:40 +0000)]
Update copyright headers

Headers updated automatically using maint/update_copyright_years.sh
script.

6 years agoUpdate NEWS
Eugene Syromyatnikov [Wed, 4 Apr 2018 22:33:05 +0000 (00:33 +0200)]
Update NEWS

6 years agounwind: split unwind code into front-end and back-end
Masatake YAMATO [Tue, 13 Mar 2018 17:28:10 +0000 (02:28 +0900)]
unwind: split unwind code into front-end and back-end

This opens the way for alternative unwinder back-ends.

* unwind.h: New file, defines the unwinder back-end interface.
* unwind.c: Move all libunwind related code ...
* unwind-libunwind.c: ... here.
* Makefile.am [USE_LIBUNWIND] (strace_SOURCES): Add unwind.h
and unwind-libunwind.c.

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
6 years agounwind: rename public functions in an object-oriented fashion
Masatake YAMATO [Tue, 13 Mar 2018 17:28:09 +0000 (02:28 +0900)]
unwind: rename public functions in an object-oriented fashion

This change renames functions exported to strace core part from unwind
subsystem.

The new names imply that unwind subsystem exports two types of
functions.  One is for manipulating back-end itself, "unwind_" prefix
is used for this type.  Another is for manipulating back-end private data
structure (unwind_ctx) attached to tcb, "unwind_tcb_" is used for this
type.

This naming should help people to understand unwind subsystem
and the relation between unwind subsystem and back-ends.

* defs.h (unwind_print_stacktrace): Rename to unwind_tcb_print.
(unwind_capture_stacktrace): Rename to unwind_tcb_capture.
* unwind.c: Ditto.
* syscall.c (syscall_entering_trace, syscall_exiting_trace): Use
new names.

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
6 years agounwind: add unwind_ prefix to struct tcb.queue field and its type
Masatake YAMATO [Tue, 13 Mar 2018 17:28:07 +0000 (02:28 +0900)]
unwind: add unwind_ prefix to struct tcb.queue field and its type

The names given to struct tcb.queue field and its type are too common,
this may cause conflicts in the future if new fields are added
to struct tcb.

* defs.h (struct tcb): Rename queue field to unwind_queue,
rename its type queue_t to unwind_queue_t.
* unwind.c (struct unwind_queue_t): Rename to unwind_queue_t.
All users updated.

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
6 years agounwind: make the field type of struct tcb independent from libunwind
Masatake YAMATO [Tue, 13 Mar 2018 17:28:06 +0000 (02:28 +0900)]
unwind: make the field type of struct tcb independent from libunwind

Narrowing the area where the code refers to names associated with
libunwind is needed to utilize libdw of elfutils as an alternative
unwinder.

* defs.h (struct tcb): Rename libunwind_ui field to unwind_ctx, change
its type to "void *".
* unwind.c (unwind_tcb_init, unwind_tcb_fin, stracetrace_walk): Reflect
* the above field renaming.

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
6 years agotests: robustify options-syntax.test against ash
Dmitry V. Levin [Wed, 4 Apr 2018 21:36:07 +0000 (21:36 +0000)]
tests: robustify options-syntax.test against ash

* tests/options-syntax.test: Do not assume that shell provides $UID,
use "id -u" if it doesn't.

6 years agostrace.c: add support for opening output file in append mode
Eugene Syromyatnikov [Wed, 28 Mar 2018 14:49:57 +0000 (16:49 +0200)]
strace.c: add support for opening output file in append mode

* strace.c (open_append): New variable.
(init): Handle -A option.
(strace_fopen): Open file in "a" mode if open_append is set to true.
* strace.1.in: Document this.
* NEWS: Mention this.

Suggested-by: Philipp Marek <philipp.marek@emerion.com>
Closes: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=528488
6 years agostrace.c: support simultaneous usage of -r and -t options
Eugene Syromyatnikov [Wed, 28 Mar 2018 14:22:04 +0000 (16:22 +0200)]
strace.c: support simultaneous usage of -r and -t options

* strace.c (init): Do not set tflag when rflag is set.
(printleader): Handle rflag and tflag separately.
* strace.1.in (.SH OPTIONS): Add a note about differences between
the monotonic clock time  and the wall clock time.
* tests/options-syntax.test: Remove the check for
"-tt has no effect with -r" warning.
* NEWS: Mention this.

Suggested-by: Josh Triplett <josh@freedesktop.org>
Co-Authored-by: Dmitry V. Levin <ldv@altlinux.org>
Closes: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=466195
6 years agosyscall.c: dump write I/O even if error is returned
Eugene Syromyatnikov [Wed, 28 Mar 2018 13:34:06 +0000 (15:34 +0200)]
syscall.c: dump write I/O even if error is returned

It makes sense to try to dump the argument of write syscalls as they can
be readily available despite the fact that error has been returned.

* syscall.c (dumpio): Move check for syserror and check for fd in
read_set to the end of the function.
* tests/read-write.c: Add a check for this behaviour.
* tests/pread64-pwrite64.c: Update expected output.
* NEWS: Mention this.

Suggested-by: J. Bruce Fields <bfields@fieldses.org>
Closes: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=436284
6 years agostrace: handle possible NULL from localtime() call
Eugene Syromyatnikov [Mon, 26 Mar 2018 06:15:26 +0000 (08:15 +0200)]
strace: handle possible NULL from localtime() call

* strace.c (printleader): Print raw tv_sec value if localtime() returned
NULL.
* tests/localtime.c: New file.
* tests/localtime.test: New test.
* tests/Makefile.am (check_PROGRAMS): Add localtime.
(MISC_TESTS): Add localtime.test.
(localtime_LDADD): New variable.
* tests/.gitignore: Add localtime.
* ci/install-dependencies.sh (common_packages): Add faketime.

Co-Authored-by: Dmitry V. Levin <ldv@altlinux.org>
Closes: https://github.com/strace/strace/issues/42
6 years agoReturn RVAL_STR unconditionally
Eugene Syromyatnikov [Wed, 4 Apr 2018 13:47:49 +0000 (15:47 +0200)]
Return RVAL_STR unconditionally

There is no reason to check for auxstr being non-NULL
because syscall_exiting_trace already does the check.

* sched.c (SYS_FUNC(sched_getscheduler)): Do not check tcp->auxstr,
return RVAL_STR unconditionally.
* time.c (do_adjtimex): Likewise.

6 years agodist/README: s/linux/Linux/
Eugene Syromyatnikov [Wed, 14 Mar 2018 19:45:09 +0000 (20:45 +0100)]
dist/README: s/linux/Linux/

* dist/README: Replace "linux" with "Linux".

6 years agostrace.1.in: fix formatting of -e trace class descriptions
Eugene Syromyatnikov [Sat, 10 Mar 2018 04:09:04 +0000 (05:09 +0100)]
strace.1.in: fix formatting of -e trace class descriptions

Use .TP instead .PP as it is ought to be.

* strace.1.in (.SS Filtering): Use .TP instead .PP as it is ought to be.

6 years agonlattr: check NLA_TYPE_MASK at compile time
Eugene Syromyatnikov [Sat, 10 Mar 2018 05:18:30 +0000 (06:18 +0100)]
nlattr: check NLA_TYPE_MASK at compile time

* nlattr.c: Include "static_assert.h"
(print_nlattr): Check the expectations about NLA_TYPE_MASK.

Co-Authored-by: Dmitry V. Levin <ldv@altlinux.org>
6 years agobpf: add a comment about bpf_attr decoding
Eugene Syromyatnikov [Sun, 4 Mar 2018 19:31:25 +0000 (20:31 +0100)]
bpf: add a comment about bpf_attr decoding

* bpf.c: Add comment.

6 years agotests: check decoding of bpf_attr of size 1
Dmitry V. Levin [Tue, 3 Apr 2018 08:08:09 +0000 (08:08 +0000)]
tests: check decoding of bpf_attr of size 1

* tests/bpf.c (BPF_PROG_GET_NEXT_ID_checks): New entry.

6 years agobpf: use print_big_u64_addr
Eugene Syromyatnikov [Mon, 26 Mar 2018 04:20:44 +0000 (06:20 +0200)]
bpf: use print_big_u64_addr

Since pointers stored in the bpf_attr union are 64-bit regardless
of architecture bitness.

* bpf.c (DEF_BPF_CMD_DECODER(BPF_PROG_LOAD)): Call print_big_u64_addr
for attr.license.
(DEF_BPF_CMD_DECODER(BPF_OBJ_PIN)): Call print_big_u64_addr
for attr.pathname.
* tests/bpf.c (BPF_OBJ_PIN_checks): Check it.

Co-Authored-by: Dmitry V. Levin <ldv@altlinux.org>
6 years agobpf: add support for file mode flags
Eugene Syromyatnikov [Mon, 26 Feb 2018 18:40:08 +0000 (19:40 +0100)]
bpf: add support for file mode flags

These were introduced by Linux commit v4.15-rc1~84^2~384^2~4.

* bpf_attr.h (struct BPF_OBJ_PIN_struct): Add file_flags field.
(struct BPF_PROG_GET_NEXT_ID_struct, struct BPF_PROG_GET_FD_BY_ID_struct,
struct BPF_MAP_GET_FD_BY_ID_struct): Add open_flags field.
(BPF_OBJ_PIN_struct_size, expected_BPF_OBJ_PIN_struct_size,
expected_BPF_PROG_GET_NEXT_ID_struct_size,
expected_BPF_PROG_GET_FD_BY_ID_struct_size,
expected_BPF_MAP_GET_FD_BY_ID_struct_size): Update.
* bpf.c (DEF_BPF_CMD_DECODER(BPF_OBJ_PIN)): Check the length, skip
printing the rest of attributes if it is less than offset of the
end of the bpf_fd field, print file_flags field otherwise.
(DEF_BPF_CMD_DECODER(BPF_PROG_GET_NEXT_ID),
DEF_BPF_CMD_DECODER(BPF_PROG_GET_FD_BY_ID),
DEF_BPF_CMD_DECODER(BPF_MAP_GET_FD_BY_ID)): Check the length, skip
printing the rest of attributes if it is less than offset of the
end of the next_id field, print open_flags field otherwise.
* xlat/bpf_file_mode_flags.in: New file.
* tests/bpf.c (BPF_OBJ_PIN_checks, BPF_PROG_GET_NEXT_ID_checks,
BPF_PROG_GET_FD_BY_ID_checks, BPF_MAP_GET_FD_BY_ID_checks): Check it.

Co-Authored-by: Dmitry V. Levin <ldv@altlinux.org>
6 years agotests: refactor bpf test
Eugene Syromyatnikov [Wed, 21 Mar 2018 18:10:15 +0000 (19:10 +0100)]
tests: refactor bpf test

The aim of this change is to introduce an ability to perform multiple
checks for a specific bpf command.  In order to achieve so, all the
related data is stored in check descriptor, and test_bpf iterates over
it.  There are also some provisions made in regard to future changes
(specifically, the way bpf_attr_data union is defined).

* tests/bpf.c (print_bpf_attr): New function, a wrapper around
struct bpf_check.printer.
(test_bpf_): Rename to...
(test_bpf): ...this.  Replace arguments with struct bpf_check pointer.
Iterate over possible attribute variants. Account for changes in
attribute initialisation routine: provide a pointer to locally defined
union bpf_attr_data and perform memcpy afterwards. Initialise memory
from data each time before a bpf call.
(TEST_BPF, DEF_*, init_*, print_*): Remove.
(init_BPF_PROG_LOAD_attr, print_BPF_PROG_LOAD_attr,
init_BPF_OBJ_PIN_attr): New functions.
(license, pathname): New variables.
(BPF_MAP_CREATE_checks, BPF_MAP_LOOKUP_ELEM_checks,
BPF_MAP_UPDATE_ELEM_checks, BPF_MAP_DELETE_ELEM_checks,
BPF_MAP_GET_NEXT_KEY_checks, BPF_PROG_LOAD_checks, BPF_OBJ_PIN_checks,
BPF_PROG_ATTACH_checks, BPF_PROG_DETACH_checks,
BPF_PROG_TEST_RUN_checks, BPF_PROG_GET_NEXT_ID_checks,
BPF_PROG_GET_FD_BY_ID_checks, BPF_MAP_GET_FD_BY_ID_checks,
BPF_OBJ_GET_INFO_BY_FD_checks): New arrays.
(BPF_OBJ_GET_checks, BPF_MAP_GET_NEXT_ID_checks): New macros.
(CHK): New macro, a shorthand for initialising array of struct bpf_check.
(main): New static constant checks, iterate over checks and run test_bpf
with each element.

Co-Authored-by: Dmitry V. Levin <ldv@altlinux.org>
6 years agoprint_fields.h: introduce PRINT_FIELD_ADDR and PRINT_FIELD_ADDR64 macros
Eugene Syromyatnikov [Thu, 8 Mar 2018 21:51:30 +0000 (22:51 +0100)]
print_fields.h: introduce PRINT_FIELD_ADDR and PRINT_FIELD_ADDR64 macros

* print_fields.h (PRINT_FIELD_ADDR, PRINT_FIELD_ADDR64): New macro.

6 years agoprint_fields.h: introduce PRINT_FIELD_CSTRING_SZ macro
Eugene Syromyatnikov [Sun, 25 Mar 2018 12:11:09 +0000 (14:11 +0200)]
print_fields.h: introduce PRINT_FIELD_CSTRING_SZ macro

A variant of PRINT_FIELD_CSTRING with an ability to pass string size
explicitly.

* print_fields.h (PRINT_FIELD_CSTRING_SZ): New macro.

6 years agoprint_fields.h: check whether passed field is an array in PRINT_FIELD_CSTRING
Eugene Syromyatnikov [Sat, 10 Mar 2018 04:09:42 +0000 (05:09 +0100)]
print_fields.h: check whether passed field is an array in PRINT_FIELD_CSTRING

* print_fields.h (PRINT_FIELD_CSTRING): Add MUST_BE_ARRAY to the size
value in order to check whether (where_).field_ is an array in compile
time.

6 years agoprint_fields.h: whitespace fix in PRINT_FIELD_HEX_ARRAY
Eugene Syromyatnikov [Mon, 5 Mar 2018 14:57:19 +0000 (15:57 +0100)]
print_fields.h: whitespace fix in PRINT_FIELD_HEX_ARRAY

6 years agobpf_attr: add more size checks
Dmitry V. Levin [Wed, 4 Apr 2018 14:50:07 +0000 (14:50 +0000)]
bpf_attr: add more size checks

* bpf_attr.h: Add expected sizes of structures.
* gen_bpf_attr_check.sh: Check them.

6 years agotests: check bpf syscall decoder unconditionally
Dmitry V. Levin [Tue, 3 Apr 2018 00:35:39 +0000 (00:35 +0000)]
tests: check bpf syscall decoder unconditionally

* configure.ac (AC_CHECK_HEADERS([linux/bpf.h])): Check for
struct bpf_insn.
* tests/bpf.c: Remove the test guard, include "scno.h", "bpf_attr.h",
"xlat.h", and "xlat/bpf_commands.h".  Conditionalize inclusion of
<linux/bpf.h> on HAVE_LINUX_BPF_H.  Remove all HAVE_UNION_* checks.
(BPF_ATTR_DATA_FIELD): New macro.
(bpf_attr_data): New union.  Note that it is larger than modern
union bpf_attr, this allows more checks to be implemented in the future.
(sizeof_attr, test_bpf_): Replace union bpf_attr with
union bpf_attr_data.
(DEF_BPF_INIT_FIRST): Replace union bpf_attr with the corresponding
structure.
(init_BPF_MAP_CREATE_attr): Replace union bpf_attr with
struct BPF_MAP_CREATE_struct.
(init_BPF_MAP_LOOKUP_ELEM_attr): Replace union bpf_attr with
struct BPF_MAP_LOOKUP_ELEM_struct.
(init_BPF_MAP_UPDATE_ELEM_attr): Replace union bpf_attr with
struct BPF_MAP_UPDATE_ELEM_struct.
(init_BPF_MAP_DELETE_ELEM_attr): Replace union bpf_attr with
struct BPF_MAP_DELETE_ELEM_struct.
(init_BPF_MAP_GET_NEXT_KEY_attr): Replace union bpf_attr with
struct BPF_MAP_GET_NEXT_KEY_struct.
(init_BPF_PROG_LOAD_attr): Replace union bpf_attr with
struct BPF_PROG_LOAD_struct.
(init_BPF_OBJ_PIN_attr): Replace union bpf_attr with
struct BPF_OBJ_PIN_struct.
(init_BPF_PROG_ATTACH_attr): Replace union bpf_attr with
struct BPF_PROG_ATTACH_struct.
(init_BPF_PROG_DETACH_attr): Replace union bpf_attr with
struct BPF_PROG_DETACH_struct.
(init_BPF_PROG_GET_NEXT_ID_attr): Replace union bpf_attr with
struct BPF_PROG_GET_NEXT_ID_struct.
(sample_BPF_PROG_TEST_RUN_attr): Change type from union bpf_attr to
struct BPF_PROG_TEST_RUN_struct, all users updated.
(sample_BPF_OBJ_GET_INFO_BY_FD_attr): Change type from union bpf_attr
to struct BPF_OBJ_GET_INFO_BY_FD_struct, all users updated.

6 years agoCheck that structures defined by bpf_attr.h match system union bpf_attr
Dmitry V. Levin [Mon, 2 Apr 2018 19:10:55 +0000 (19:10 +0000)]
Check that structures defined by bpf_attr.h match system union bpf_attr

* gen_bpf_attr_check.sh: New file.
* Makefile.am (EXTRA_DIST): Add it.
(strace_SOURCES_check): New variable.
(strace_SOURCES): Add $(strace_SOURCES_check).
(BUILT_SOURCES, CLEANFILES): Add bpf_attr_check.c.
(bpf_attr_check.c): New rule.
(sys_func_h_sources): New variable.
(sys_func.h): Use it instead of strace_SOURCES_c.
* .gitignore: Add /bpf_attr_check.c.

6 years agobuild: generate all union bpf_attr checks automatically
Dmitry V. Levin [Mon, 2 Apr 2018 15:56:31 +0000 (15:56 +0000)]
build: generate all union bpf_attr checks automatically

Rather than list by hand some members of union bpf_attr that we check
for availability, automatically list all members of union bpf_attr we
are aware of.

* m4/gen_bpf_attr_m4.sh: New file.
* bootstrap: Invoke it.
* configure.ac (AC_CHECK_HEADERS([linux/bpf.h])): Use st_BPF_ATTR.
* m4/.gitignore: New file.

6 years agobpf: move definitions of bpf_attr structures to separate header file
Dmitry V. Levin [Mon, 2 Apr 2018 13:12:57 +0000 (13:12 +0000)]
bpf: move definitions of bpf_attr structures to separate header file

This also unifies decoders of bpf commands by moving common code
to new macros.

* bpf_attr.h: New file.
* Makefile.am (strace_SOURCES): Add it.
* bpf.c: Include it.
(DEF_BPF_CMD_DECODER): Rename to BEGIN_BPF_CMD_DECODER, add code common
to all decoders.  All users updated.
(END_BPF_CMD_DECODER): New macro, add its invocation to all users
of BEGIN_BPF_CMD_DECODER macro.

6 years agoIntroduce print_big_u64_addr
Eugene Syromyatnikov [Mon, 26 Mar 2018 04:13:23 +0000 (06:13 +0200)]
Introduce print_big_u64_addr

This is needed at least for bpf, btrfs, and sg_io, as 32-bit tracer
cannot figure out whether the kernel is 32-bit or 64-bit,
and its behaviour differs when it handles u64 as a pointer.

* linux/arch_defs_.h [!CAN_ARCH_BE_COMPAT_ON_64BIT_KERNEL]
(CAN_ARCH_BE_COMPAT_ON_64BIT_KERNEL): New definition, default to 0.
* linux/arm/arch_defs_.h (CAN_ARCH_BE_COMPAT_ON_64BIT_KERNEL):
Define to 1.
* linux/i386/arch_defs_.h (CAN_ARCH_BE_COMPAT_ON_64BIT_KERNEL):
Likewise.
* linux/mips/arch_defs_.h (CAN_ARCH_BE_COMPAT_ON_64BIT_KERNEL):
Likewise.
* linux/powerpc/arch_defs_.h (CAN_ARCH_BE_COMPAT_ON_64BIT_KERNEL):
Likewise.
* linux/riscv/arch_defs_.h (CAN_ARCH_BE_COMPAT_ON_64BIT_KERNEL):
Likewise.
* linux/s390/arch_defs_.h (CAN_ARCH_BE_COMPAT_ON_64BIT_KERNEL):
Likewise.
* linux/sparc/arch_defs_.h (CAN_ARCH_BE_COMPAT_ON_64BIT_KERNEL):
Likewise.
* linux/tile/arch_defs_.h (CAN_ARCH_BE_COMPAT_ON_64BIT_KERNEL):
Likewise.
* defs.h (print_big_u64_addr): New function.

Co-Authored-by: Dmitry V. Levin <ldv@altlinux.org>
6 years agodefs.h: introduce max_addr and max_kaddr macros
Eugene Syromyatnikov [Sun, 25 Mar 2018 15:24:49 +0000 (17:24 +0200)]
defs.h: introduce max_addr and max_kaddr macros

In order to check an address against maximum addr/kaddr value
for the current personality.

* degs.h (max_addr, max_kaddr): New macros.

6 years agoIntroduce static_assert
Dmitry V. Levin [Tue, 3 Apr 2018 22:52:54 +0000 (22:52 +0000)]
Introduce static_assert

We are going to use static_assert provided by <assert.h> or,
if it doesn't work, our cheap imitation that doesn't display
the message specified as the second argument of static_assert.

* configure.ac (AC_CACHE_CHECK): Check for static_assert in <assert.h>,
define HAVE_STATIC_ASSERT if it is available.
* static_assert.h: New file.
* Makefile.am (strace_SOURCES): Add it.

6 years agotests: forward SIZEOF_KERNEL_LONG_T and SIZEOF_LONG to C preprocessor
Dmitry V. Levin [Tue, 3 Apr 2018 08:08:09 +0000 (08:08 +0000)]
tests: forward SIZEOF_KERNEL_LONG_T and SIZEOF_LONG to C preprocessor

* tests/Makefile.am (AM_CPPFLAGS): Forward SIZEOF_KERNEL_LONG_T
and SIZEOF_LONG as TESTS_SIZEOF_KERNEL_LONG_T and TESTS_SIZEOF_LONG.
* tests/tests.h [TESTS_SIZEOF_KERNEL_LONG_T] (SIZEOF_KERNEL_LONG_T):
Redefine to TESTS_SIZEOF_KERNEL_LONG_T.
[TESTS_SIZEOF_LONG] (SIZEOF_LONG): Redefine to TESTS_SIZEOF_LONG.

Complements: v4.21~5 ("Export SIZEOF_LONG and SIZEOF_KERNEL_LONG_T to tests")

6 years agotests/tests.h: fix indentation
Dmitry V. Levin [Tue, 3 Apr 2018 08:08:09 +0000 (08:08 +0000)]
tests/tests.h: fix indentation

6 years agotests: fix potential errno clobbering in netlink_kobject_uevent.test
Dmitry V. Levin [Wed, 4 Apr 2018 12:24:19 +0000 (12:24 +0000)]
tests: fix potential errno clobbering in netlink_kobject_uevent.test

* tests/netlink_kobject_uevent.c (errstr): New variable.
(sys_send): New function.
(main): Use them.

6 years agoRestore kvm ioctl definitions for aarch64 and mips architectures
Gleb Fotengauer-Malinovskiy [Tue, 3 Apr 2018 17:34:48 +0000 (20:34 +0300)]
Restore kvm ioctl definitions for aarch64 and mips architectures

* maint/ioctls_sym.sh: Add aarch64 and mips architectures to the list
of kvm-capable architectures.
* linux/aarch64/ioctls_arch0.h: Regenerate.
* linux/mips/ioctls_arch0.h: Regenerate.

Fixes: v4.15~92 ("Move KVM_* ioctl entries from ioctls_inc*.h to ioctls_arch*.h")
6 years agoUpdate ioctl entries from linux v4.16
Gleb Fotengauer-Malinovskiy [Tue, 3 Apr 2018 17:33:22 +0000 (20:33 +0300)]
Update ioctl entries from linux v4.16

* linux/32/ioctls_inc_align16.h: Update from linux v4.16
using ioctls_gen.sh.
* linux/32/ioctls_inc_align32.h: Likewise.
* linux/32/ioctls_inc_align64.h: Likewise.
* linux/64/ioctls_inc.h: Likewise.
* linux/x32/ioctls_inc0.h: Likewise.
* linux/arm/ioctls_arch0.h: Likewise.
* linux/i386/ioctls_arch0.h: Likewise.
* linux/powerpc/ioctls_arch0.h: Likewise.
* linux/s390/ioctls_arch0.h: Likewise.
* linux/s390x/ioctls_arch0.h: Likewise.
* linux/x86_64/ioctls_arch0.h: Likewise.
* NEWS: Mention this.

6 years agomaint: update for linux 4.16
Gleb Fotengauer-Malinovskiy [Tue, 3 Apr 2018 17:32:40 +0000 (20:32 +0300)]
maint: update for linux 4.16

* maint/ioctls_sym.sh: Add workaround for linux/ndctl.h file.
Update workaround for media/v4l2-common.h file.
(x86_list): Add KVM_GET_MSR_FEATURE_INDEX_LIST.

6 years agoutil.c: amend sprinttime_ex description a bit
Eugene Syromyatnikov [Sun, 18 Mar 2018 06:53:32 +0000 (07:53 +0100)]
util.c: amend sprinttime_ex description a bit

* util.c (sprinttime_ex): Document return value.

6 years agotests/bpf.c: add a check for NULL bpf_attr pointer
Eugene Syromyatnikov [Wed, 21 Mar 2018 18:09:52 +0000 (19:09 +0100)]
tests/bpf.c: add a check for NULL bpf_attr pointer

* tests/bpf.c (main): Add a check with 0 passed in the third argument.

6 years agobpf: print byte range for extra data
Eugene Syromyatnikov [Sat, 3 Mar 2018 02:13:35 +0000 (03:13 +0100)]
bpf: print byte range for extra data

As it could be not entirely clear what bytes are printed.

* bpf.c (decode_attr_extra_data): Print a comment about the byte range
to be printed.
* tests/bpf.c: Update expected output.

6 years agoRemove addflags
Eugene Syromyatnikov [Sat, 10 Mar 2018 04:38:10 +0000 (05:38 +0100)]
Remove addflags

It has only single user and implementation of xlat styles for it would
lead to lots of code duplication.

* defs.h (addflags): Remove declaration.
* mem.c (print_mmap_flags): Convert addflags call into printflags64 with
non-zeroeness flags check.
* xlat.c (addflags): Remove.

6 years agoAdd i18n support
Dmitry V. Levin [Sat, 1 Apr 2017 13:14:15 +0000 (13:14 +0000)]
Add i18n support

Let's make a step towards the growing strace userbase all around
the world and translate something to the language of their choice.

This change enables translation of error messages corresponding
to errno codes, making it consistent with error diagnostics of other
i18n-aware tools, e.g.

$ LANG=es_ES strace -qq -a38 -P /missing unlink /missing
unlink("/missing")                    = -1 ENOENT (No existe el fichero o el directorio)
unlink: no se puede deshacer el enlace '/missing': No existe el fichero o el directorio

* strace.c: Include <locale.h>.
(main): Invoke setlocale.
* tests/init.sh: Export LC_ALL=C.
* NEWS: Mention this enhancement.

6 years agoRemove RVAL_PRINT_ERR_VAL
Dmitry V. Levin [Thu, 29 Mar 2018 16:00:18 +0000 (16:00 +0000)]
Remove RVAL_PRINT_ERR_VAL

* defs.h (RVAL_PRINT_ERR_VAL): Remove.
* ldt.c (SYS_FUNC(modify_ldt)): Return 0.
* syscall.c (syscall_exiting_trace): When printing an error,
always print struct tcb.u_rval as if RVAL_PRINT_ERR_VAL was set.

6 years agoTreat RVAL_DECIMAL the same way as RVAL_UDECIMAL
Dmitry V. Levin [Thu, 29 Mar 2018 16:00:18 +0000 (16:00 +0000)]
Treat RVAL_DECIMAL the same way as RVAL_UDECIMAL

Assuming that syscalls may return negative values only as error codes,
always print non-error syscall return codes as unsigned.

* defs.h (RVAL_UDECIMAL): Remove.
(RVAL_DECIMAL): Rename to RVAL_UDECIMAL.
* syscall.c (syscall_exiting_trace) <case RVAL_DECIMAL>: Remove.
* clone.c (SYS_FUNC(fork)): Remove RVAL_UDECIMAL.
* lseek.c (SYS_FUNC(lseek)): Likewise.
* prctl.c (SYS_FUNC(prctl)): Likewise.
* uid.c (SYS_FUNC(getuid), SYS_FUNC(setfsuid)): Likewise.
* times.c (SYS_FUNC(times)): Always return 0.
* tests/inject-nf.c (main): Update expected output.

6 years agotests: check handling of some invalid delay injection parameters
Dmitry V. Levin [Thu, 29 Mar 2018 01:30:09 +0000 (01:30 +0000)]
tests: check handling of some invalid delay injection parameters

* tests/qual_inject-syntax.test: Check for negative delay injection
parameters.  Check for overriding delay injection parameters.

6 years agoImplement injection of negative return values
Eugene Syromyatnikov [Sun, 11 Feb 2018 23:41:36 +0000 (00:41 +0100)]
Implement injection of negative return values

Extend the range of injected return value to the maximum, print warnings
if negative injection value can be clipped in compat personality or can
inadvertently turn into a fault injection.

* defs.h (INJECT_F_ERROR): New macro.
* filter_qualify.c (parse_inject_token): Revert type of intval local
variable back to int, check INJECT_F_ERROR along with INJECT_F_RETVAL,
use strtoull to parse retval argument, print warnings in case of retval
clipping and inadvertent fault injection.
(qualify_inject_common): Set INJECT_F_ERROR instead of INJECT_F_RETVAL.
* syscall.c (tamper_with_syscall_exiting): Check inject_data.flags
to determine whether a fault injection or retval injection has to be
performed.
(syscall_exiting_trace) <case RVAL_DECIMAL>: Explicitly print
tcp->u_rval as int if current_klongsize < sizeof(tcp->u_rval).
* tests/inject-nf.c (main): Update.
* tests/inject-nf.test: Test injection of negative return values.
* tests/qual_inject-syntax.test: Remove retval=-1 check as it is now
allowed, add checks for invalid retval parameters.

Co-Authored-by: Dmitry V. Levin <ldv@altlinux.org>
6 years agoarch_defs.h: fix typo in comment
Dmitry V. Levin [Wed, 28 Mar 2018 04:29:22 +0000 (04:29 +0000)]
arch_defs.h: fix typo in comment

6 years agoMove delay interface from defs.h to delay.h
Dmitry V. Levin [Wed, 28 Mar 2018 04:29:22 +0000 (04:29 +0000)]
Move delay interface from defs.h to delay.h

* defs.h (alloc_delay_data, fill_delay_data, is_delay_timer_armed,
delay_timer_expired, arm_delay_timer, delay_tcb): Move...
* delay.h: ... to new file.
* Makefile.am (strace_SOURCES): Add it.
* filter_qualify.c: Include it.
* strace.c: Likewise.
* syscall.c: Likewise.

6 years agoTurn struct inject_data.rval into an index
Dmitry V. Levin [Wed, 28 Mar 2018 04:29:22 +0000 (04:29 +0000)]
Turn struct inject_data.rval into an index

Add one level of indirection to decrease the size of struct inject_data
as hundreds of these structures are created for each process when
injection mechanism is activated.

* retval.h: New file.
* retval.c: Likewise.
* Makefile.am (strace_SOURCES): Add them.
* defs.h (struct inject_data): Replace rval field with rval_idx.
* filter_qualify.c: Include "retval.h".
(parse_inject_token, qualify_inject_common): Initialize
struct inject_data.rval_idx using retval_new.
* syscall.c: Include "retval.h".
(tamper_with_syscall_exiting): Obtain the value that has to be injected
using retval_get.

6 years agodefs.h: update comment
Dmitry V. Levin [Tue, 27 Mar 2018 22:22:23 +0000 (22:22 +0000)]
defs.h: update comment

* defs.h (struct inject_data): Update comment about flags.

Complements: v4.21-108-gba8e768 ("Implement delay injection")

6 years agoxlat: cleanup mmap_flags.in
Eugene Syromyatnikov [Thu, 8 Mar 2018 16:55:01 +0000 (17:55 +0100)]
xlat: cleanup mmap_flags.in

* xlat/mmap_flags.in (_MAP_NEW): Remove SunOS-specific comment, add
a comment that this is a SPARC-specific constant (from
arch/sparc/include/uapi/asm/mman.h).
(MAP_GROWSUP): IA-64-specific constant (from
arch/ia64/include/uapi/asm/mman.h).
(MAP_INHERIT): Add a comment that this is a SPARC-specific constant
(from arch/sparc/include/uapi/asm/mman.h).
(_MAP_INHERIT): Add a comment that this is an Alpha-specific constant
(from arch/alpha/include/uapi/asm/mman.h).
(MAP_ANON): Remove, FreeBSD-specific constant.
(MAP_HASSEMAPHORE): Rename to...
(_MAP_HASSEMAPHORE): ...this, add a comment that this is an
Alpha-specific constant (from arch/alpha/include/uapi/asm/mman.h).
(MAP_NOSYNC, MAP_NOCORE): Remove.
(MAP_AUTOGROW, MAP_AUTORSRV, MAP_LOCAL): Add a comment that this is
an architecture-specific constant (from
arch/mips/include/uapi/asm/mman.h, arch/xtensa/include/uapi/asm/mman.h).
(_MAP_UNALIGNED): Add a comment that this is an Alpha-specific constant
(from arch/alpha/include/uapi/asm/mman.h).

6 years agotests: check decoding of kern_features syscall
Eugene Syromyatnikov [Wed, 7 Feb 2018 01:18:28 +0000 (02:18 +0100)]
tests: check decoding of kern_features syscall

* tests/kern_features.c: New file.
* tests/kern_features-fault.test: New test.
* tests/gen_tests.in (kern_features): New entry.
* tests/Makefile.am (DECODER_TESTS): Add kern_features-fault.test.
* tests/pure_executables.list: Add kern_features.
* tests/.gitignore: Likewise.

Co-Authored-by: Dmitry V. Levin <ldv@altlinux.org>
6 years agosparc, sparc64: implement kern_features decoder
Eugene Syromyatnikov [Wed, 7 Feb 2018 01:11:54 +0000 (02:11 +0100)]
sparc, sparc64: implement kern_features decoder

* sparc.c: New file.
* Makefile.am (EXTRA_DIST): Add it.
* linux/sparc/syscallent.h ([340]): Remove NF flag, set kern_features
decoder.
* linux/sparc64/syscallent.h ([340]): Likewise.
* xlat/sparc_kern_features.in: New file.
* NEWS: Mention this enhancement.

Co-Authored-by: Dmitry V. Levin <ldv@altlinux.org>