Dmitry V. Levin [Fri, 10 May 2019 22:27:59 +0000 (22:27 +0000)]
sparc64: implement printer for sparc64-specific struct timex
According to Linux kernel commit v5.1-rc1~160^2~2^2~8, sparc64 is the
only architecture on Linux that has a 'timeval' definition with a 32-bit
tv_usec but a 64-bit tv_sec.
* defs.h [SPARC64] (print_sparc64_timex): New prototype.
* kernel_timex.h [SPARC64] (kernel_sparc64_timex_t): New type.
* print_timex.c [SPARC64] (print_sparc64_timex): New function.
Dmitry V. Levin [Fri, 10 May 2019 22:27:59 +0000 (22:27 +0000)]
Implement printer for kernel_timex32_t
This is going to be used to re-implement parsers of syscalls that deal
with 32-bit struct timex.
* print_timex.h: New file.
* Makefile.am (strace_SOURCES): Add it.
* defs.h (print_timex32): New prototype.
* print_timex.c: Include "kernel_timex.h".
[HAVE_ARCH_TIME32_SYSCALLS] (print_timex32): New function.
Dmitry V. Levin [Fri, 10 May 2019 22:27:59 +0000 (22:27 +0000)]
Introduce kernel_timex32_t
Currently existing parsers of syscalls that deal with 32-bit timex
rely upon struct timex being defined in libc and match the definition
used by the kernel. Given the upcoming y2038 changes in glibc,
this new type is going to be used instead.
* kernel_timex.h: New file.
* Makefile.am (strace_SOURCES): Add it.
Dmitry V. Levin [Thu, 9 May 2019 22:03:30 +0000 (22:03 +0000)]
print_timespec.c: introduce helper macros and functions
They are going to be used to implement printers of other timespec
flavours, e.g. kernel_timespec32_t and kernel_timespec64_t.
* print_timespec.c (TIMESPEC_TO_SEC_NSEC): New macro.
(print_timespec_t_utime, sprint_timespec): Use it.
(print_sec_nsec): New function.
(print_timespec_t): Use it.
Dmitry V. Levin [Sun, 5 May 2019 22:28:34 +0000 (22:28 +0000)]
Introduce kernel_timespec32_t type
Currently existing parsers of syscalls that deal with 32-bit timespec
rely upon struct timespec being defined in libc and match the definition
used by the kernel. Given the upcoming y2038 changes in glibc,
this new type is going to be used instead.
* kernel_timespec.h: New file.
* Makefile.am (strace_SOURCES): Add it.
Dmitry V. Levin [Sat, 4 May 2019 23:15:52 +0000 (23:15 +0000)]
time.c: introduce do_timerfd_gettime and do_timerfd_settime
These are going to be used to implement parsers of timerfd_gettime64
and timerfd_settime64 syscalls.
* time.c (do_timerfd_settime, do_timerfd_gettime): New functions.
((SYS_FUNC(timerfd_settime)): Turn into a thin wrapper around
do_timerfd_settime.
((SYS_FUNC(timerfd_gettime)): Turn into a thin wrapper around
do_timerfd_gettime.
Dmitry V. Levin [Sat, 4 May 2019 23:15:52 +0000 (23:15 +0000)]
time.c: introduce do_timer_gettime and do_timer_settime
These are going to be used to implement parsers of timer_gettime64 and
timer_settime64 syscalls.
* time.c (do_timer_settime, do_timer_gettime): New functions.
((SYS_FUNC(timer_settime)): Turn into a thin wrapper around
do_timer_settime.
((SYS_FUNC(timer_gettime)): Turn into a thin wrapper around
do_timer_gettime.
Dmitry V. Levin [Sat, 4 May 2019 23:15:52 +0000 (23:15 +0000)]
time.c: introduce do_clock_gettime, do_clock_settime, and do_clock_nanosleep
These are going to be used to implement parsers of clock_gettime64,
clock_settime64, and clock_nanosleep_time64 syscalls.
* time.c (do_clock_settime, do_clock_gettime, do_clock_nanosleep): New
functions.
((SYS_FUNC(clock_settime)): Turn into a thin wrapper around
do_clock_settime.
((SYS_FUNC(clock_gettime)): Turn into a thin wrapper around
do_clock_gettime.
((SYS_FUNC(clock_nanosleep)): Turn into a thin wrapper around
do_clock_nanosleep.
Dmitry V. Levin [Sat, 4 May 2019 23:15:52 +0000 (23:15 +0000)]
poll.c: introduce do_ppoll
This is going to be used to implement a parser of ppoll_time64 syscall.
* poll.c (decode_poll_exiting): Add sprint_ts argument.
(SYS_FUNC(poll)): Pass sprint_timespec to decode_poll_exiting.
(do_ppoll): New function.
(SYS_FUNC(ppoll)): Turn into a thin wrapper around do_ppoll.
Dmitry V. Levin [Sat, 4 May 2019 23:15:52 +0000 (23:15 +0000)]
mq.c: introduce do_mq_timedsend and do_mq_timedreceive
These are going to be used to implement parsers of mq_timedsend_time64
and mq_timedreceive_time64 syscalls.
* mq.c (do_mq_timedsend, do_mq_timedreceive): New functions.
(SYS_FUNC(mq_timedsend)): Turn into a thin wrapper around
do_mq_timedsend.
(SYS_FUNC(mq_timedreceive)): Turn into a thin wrapper around
do_mq_timedreceive.
tests: robustify umount and umount2 tests against future kernel changes
Prepare for the rename of umount syscall to umount2 introduced by linux
kernel commits v5.1-rc1~160^2~3^2~12 and v5.1-rc1~160^2~3^2~16 on alpha
and ia64 architectures, respectively.
* tests/umount.c: Check for __NR_umount == __NR_umount2.
* tests/umount2.c: Likewise.
alpha: wire up getegid, geteuid, and getppid syscalls
* linux/alpha/syscallent.h [530..532]: Wire up getegid, geteuid,
and getppid syscalls introduced on this architecture by linux commit
v5.1-rc1~160^2~3^2~1.
* NEWS: Mention this.
* linux/alpha/syscallent.h [528..529]: Wire up statfs64 and fstatfs64
syscalls introduced on this architecture by linux commit
v5.1-rc1~160^2~3^2~2.
* NEWS: Mention this.
Wire up pkey_* and rseq syscalls on remaining architectures
* linux/alpha/syscallent.h [524..527]: Wire up pkey_mprotect,
pkey_alloc, pkey_free, and rseq syscalls introduced on this architecture
by linux commit v5.1-rc1~160^2~3^2~3.
* linux/hppa/syscallent.h [351..354]: Likewise.
* linux/ia64/syscallent.h [1024 + 330..333]: Likewise.
* linux/m68k/syscallent.h [381..384]: Likewise.
* linux/sh/syscallent.h [384..387]: Likewise.
* linux/sparc/syscallent.h [362..365]: Likewise.
* linux/sparc64/syscallent.h: Likewise.
* linux/s390/syscallent.h [384..386]: Wire up pkey_mprotect,
pkey_alloc, and pkey_free syscalls introduced on this architecture
by linux commit v5.1-rc1~160^2~3^2~3.
* linux/s390x/syscallent.h: Likewise.
* linux/xtensa/syscallent.h [352]: Wire up rseq syscall introduced
on this architecture by linux commit v5.1-rc1~160^2~3^2~3.
* NEWS: Mention this.
powerpc, powerpc64: remove direct ipc syscall entries
* linux/powerpc/syscallent.h [366..377]: Remove entries reserved for
direct ipc syscalls, they were added by linux kernel commit
v4.4-rc1~98^2~32 and removed by linux kernel commit v4.4-rc6~5^2~2.
* linux/powerpc64/syscallent.h: Likewise.
ia64: wire up perf_event_open and seccomp syscalls
* linux/ia64/syscallent.h [1024 + 327..328]: Wire up perf_event_open
and seccomp syscalls introduced on ia64 by linux commit
v5.1-rc1~160^2~3^2~14.
* NEWS: Mention this.
* linux/ia64/syscallent.h [1024 + 326..327]: Wire up statx and
io_pgetevents syscalls introduced on ia64 by linux commit
v5.1-rc1~160^2~3^2~15.
* NEWS: Mention this.
Guo Ren [Sat, 23 Mar 2019 00:56:14 +0000 (08:56 +0800)]
Add C-SKY architecture support
This is port of C-SKY architecture for strace. There is a little
difference between abiv1 and abiv2, we use __CSKYABIV2__ from GCC-csky
to distinguish.
Dmitry V. Levin [Mon, 18 Mar 2019 19:06:47 +0000 (19:06 +0000)]
strace-log-merge: enhance pid formatting
* strace-log-merge (max_suffix_length): New variable.
(iterate_logfiles, process_suffix, process_logfile): New functions.
Use them to choose the optimum width for pid column.
* NEWS: Mention this enhancement.
* tests/strace-log-merge-suffix.test: New test.
* tests/Makefile.am (MISC_TESTS): Add it.
Dmitry V. Levin [Mon, 18 Mar 2019 19:06:47 +0000 (19:06 +0000)]
strace-log-merge: fix error diagnostics
* strace-log-merge: Print error diagnostics and exit with a non-zero
status in case of no strace output.
* NEWS: Mention this fix.
* tests/strace-log-merge-error.test: New test.
* tests/Makefile.am (MISC_TESTS): Add it.
Fixes: v4.21~287 "strace-log-merge: work around corner cases of strace -ttt parsing"
Tuan Hoang [Thu, 14 Mar 2019 09:18:22 +0000 (10:18 +0100)]
s390: fix SIGNAL_FRAMESIZE macro
Since __SIGNAL_FRAMESIZE is in private name space, it is better not to
use it directly. This macro has been stable on s390/s390x so it is safe
to use the integer value.
* linux/s390/arch_sigreturn.c [!SIGNAL_FRAMESIZE] (SIGNAL_FRAMESIZE):
Define to 96.
* linux/s390x/arch_sigreturn.c (arch_sigreturn == s390_arch_sigreturn):
Remove S390_SIGNAL_FRAMESIZE and SIGNAL_FRAMESIZE.
(arch_sigreturn == s390x_arch_sigreturn): Define SIGNAL_FRAMESIZE.
* linux/s390/rt_sigframe.h (SIGNAL_FRAMESIZE): Define.
(struct_rt_sigframe): Replace __SIGNAL_FRAMESIZE with SIGNAL_FRAMESIZE.
Signed-off-by: Tuan Hoang <tmhoang@linux.ibm.com> Co-Authored-by: Dmitry V. Levin <ldv@altlinux.org>
Dmitry V. Levin [Wed, 13 Mar 2019 18:38:51 +0000 (18:38 +0000)]
bpf: implement decoding of BPF_MAP_LOOKUP_AND_DELETE_ELEM command
BPF_MAP_LOOKUP_AND_DELETE_ELEM command was introduced by Linux commit
v4.20-rc1~151^2~32^2~11^2~2.
* bpf.c (decode_BPF_MAP_LOOKUP_AND_DELETE_ELEM): Alias
to decode_BPF_MAP_LOOKUP_ELEM.
(SYS_FUNC(bpf)) <bpf_cmd_decoders[]>: Add
BPF_CMD_ENTRY(BPF_MAP_LOOKUP_AND_DELETE_ELEM).
* tests/bpf.c (BPF_MAP_LOOKUP_AND_DELETE_ELEM_checks): Alias
to BPF_MAP_LOOKUP_ELEM_checks.
(main) <checks>: Add CHK(BPF_MAP_LOOKUP_AND_DELETE_ELEM).
Implement queueing of threads before dispatching them
It is possible that some tracees call a lot of cheap syscalls too fast,
and that can stress the tracer to the point some tracees are not served
for indefinite amount of time. In order to avoid that unfairness, try
to collect all the pending tracees first along with the relevant
information and only then dispatch the events.
* defs.h: Include "list.h".
(struct tcb): Add wait_data_idx, delayed_wait_data, and wait_list
fields.
* strace.c (struct tcb_wait_data): Add "msg" field.
(tcb_wait_tab, tcb_wait_tab_size): New static variables.
(alloctcb): Initialize wait_list.
(droptcb): Remove tcp from wait_list.
(maybe_switch_tcbs): Get old pid from
tcb_wait_tab[tcp->wait_data_idx].msg instead of calling
ptrace(PTRACE_GETEVENTMSG).
(trace_wait_data_size, init_trace_wait_data, copy_trace_wait_data,
free_trace_wait_data, tcb_wait_tab_check_size): New functions, in order
to allow the code outside next_event to operate with wait_data as with
an opaque object (needed for dispatch_event and restart_delayed_tcb).
(next_event): Add pending_tcps, extra_tcp, wait_nohang, elem, and
wait_tab_pos variables; check for elements in pending_tcps and skip
waiting if the list is not empty; check for extra_tcp and skip waiting
along with swapping wait_data_idx with wait_extra_data_idx;
after the initial wait4(), call wait4() in loop with WNOHANG flag set;
fetch siginfo on signal and eventmsg on PTRACE_EVENT_EXEC;
return the first tcp in pending_tcps list.
(dispatch_event): Store a pointer to a copy of tcb_wait_data in
tcp->delayed_wait_data if tcp's restart has to be delayed.
(restart_delayed_tcb): Use tcp->delayed_wait_data, create a stub
tcb_wait_data if it is NULL, free temporary trace_wait_data.
* tests/Makefile.am (XFAIL_TEST): Remove looping_threads.test.
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=478419
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=526740
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=851457
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1609318
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1610774 Co-Authored-by: Dmitry V. Levin <ldv@altlinux.org> Co-Authored-by: Denys Vlasenko <dvlasenk@redhat.com> Co-Authored-by: Andreas Schwab <aschwab@redhat.com> Co-Authored-by: Jeff Law <law@redhat.com> Co-Authored-by: DJ Delorie <dj@redhat.com>
The commit v4.24~48 "Implement -e kvm= option on all architectures",
while removing #ifdef, left formatting of the help message string a bit
inconsistent.
* strace.c (usage): Move "\n\" bit after "kvm", remove double quotes.
Complements: v4.24~48 "Implement -e kvm= option on all architectures"
* strace.c (die): Pass 0 as an argument to cleanup().
(cleanup): Add fatal_sig parameter, remove the local variable
of the same name, do not use interrupted.
(terminate): Initialise a new local variable "sig" with "interrupted",
pass it to cleanup() and use it instead of "interrupted" for exit_code
initialisation.
* xlat/gen.sh: Export LC_ALL=C so it could be omitted from individual
invocations.
(cond_def): Remove LC_ALL=C from sed invocation.
(gen_header): Remove LC_COLLATE=C.
Makefile.am: pass D variable to shell scripts' environment
And set -x if D is set to 1, so the commands called by various shell scripts
are easier to see during debugging.
* Makefile.am (bpf_attr_check.c, sen.h, mpers-m%.stamp, $(srcdir)/CREDITS): Pass
D variable in the environment to the shell script call.
* gen_bpf_attr_check.sh: Set -x if D is set to 1.
* generate_mpers_am.sh: Likewise.
* generate_sen.sh: Likewise.
* maint/gen-contributors-list.sh: Likewise.
* mpers.sh: Likewise.
* mpers_test.sh: Likewise.
tests: add checks for dumpstr output into read-write test
util.c:dumpstr() now aligns offsets in accordance with the total length
of the dump and also may perform only partial dump, so let's add checks
for these cases.
* tests/fill_memory.c (fill_memory_ex): Change the type of the period
argument from unsigned char to unsigned int.
* tests/tests.h (fill_memory_ex): Likewise.
* tests/read-write.c (dump_str_ex): Rename from dump_str, add idx_w
argument, support len greater than 240 bytes.
(dump_str): New function, wrapper for dump_str_ex with the default index
width.
(print_hex): Add checks for dumpstr output, close fd 1 later.
Use a buffer of a limited size, use proper type for dump amount, avoid
hard-coding of byte counts, calculate output buffer size more accurately
and minimise its rewriting, pad offset with zeros in accordance
with expected output amount.
* defs.h (dumpstr): Change the type of len argument from int to
kernel_ulong_t.
* macros.h (ROUNDUP_DIV): New macro.
(ROUNDUP): Rewrite using ROUNDUP_DIV.
* util.c (ILOG2_ITER_): New macro.
(ilog2_64, ilog2_32): New functions.
(ilog2_klong): New macro, wrapper around ilog2_32/ilog2_64, so (potentially
more expensive) ilog2_64 is not used for ilog2 calculation
of a kernel_ulong_t-typed variable on architectures with 32-bit kernel long.
(dumpstr): Update.
Co-Authored-by: Dmitry V. Levin <ldv@altlinux.org>
Character class checks and hexadecimal number formatting are open-coded
all over the place, let's try to de-duplicate them a bit.
* print_utils.h: New file.
* Makefile.am (strace_SOURCES): Add it.
* util.c: Include "print_utils.h".
(string_quote, dumpstr): Use sprint_byte_hex and is_print.
* v4l2.c: Include "print_utils.h".
(print_pixelformat): Use is_print and BYTE_HEX_CHARS_PRINTF_QUOTED,
add a note that the routine is rather generic.
cleanup() has exactly two call sites, die() and terminate(), and the
first one resets cflag in order to prevent call_summary() invocation.
Move the call to terminate() in order to avoid bogus cflag reset.
Dmitry V. Levin [Tue, 19 Feb 2019 01:39:32 +0000 (01:39 +0000)]
build: fix --with-libiberty
* m4/st_demangle.m4 (st_DEMANGLE): Move the check for cplus_demangle
out of AC_CHECK_HEADERS because the latter checks for demangle.h in two
different places and an absence of demangle.h in one of these places
would cause a build error in --with-libiberty=yes mode.
* NEWS: Mention this fix.