Dmitry V. Levin [Mon, 8 Feb 2016 17:46:58 +0000 (17:46 +0000)]
Create a dummy pipe descriptor instead of opening /dev/null
* strace.c (open_dev_null): Rename to open_dummy_desc. All callers
changed. Create a pipe and return its first descriptor instead of
opening /dev/null.
Keith Owens [Mon, 18 Jan 2016 02:12:26 +0000 (13:12 +1100)]
strace-graph: cope with clone immediately followed by exit
* strace-graph: A clone() followed by exit() with no intervening fork
or execve resulted in the new pid having no seq key. That breaks when
trying to use seq as an array reference. Ensure that clone populates
the new pid with an empty seq entry.
Keith Owens [Mon, 18 Jan 2016 01:57:41 +0000 (12:57 +1100)]
strace-graph: use "strict" and "warnings" pragmas
* strace-graph: Set "use strict" and "use warnings" options. Fix errors
detected by strict/warnings. $result is really a string, it can be "-1"
followed by an error text.
Dmitry V. Levin [Thu, 4 Feb 2016 01:32:45 +0000 (01:32 +0000)]
tests: extend readlink and readlinkat coverage
* tests/readlink.c (PREFIX, TARGET, LINKPATH): New macros.
(main): Allocate memory for string and buffer passed to the syscall
being tested using tail_alloc mechanism. Create and cleanup test
symlink. Test syscall error path output. Print hexquoted strings
using hexquote_strndup.
* tests/readlinkat.c: Likewise.
* tests/readlink.test: Remove creation and cleanup of test symlinks.
Dmitry V. Levin [Wed, 3 Feb 2016 19:19:48 +0000 (19:19 +0000)]
Makefile.am: introduce strace_CFLAGS and derivatives
* Makefile.am (strace_CFLAGS): New variable, set to $(AM_CFLAGS).
(libmpers_CFLAGS): New variable, set to $(strace_CFLAGS).
(libmpers_m32_a_CFLAGS, libmpers_mx32_a_CFLAGS): New variables,
set to $(libmpers_CFLAGS).
Dmitry V. Levin [Mon, 1 Feb 2016 23:14:59 +0000 (23:14 +0000)]
Implement caching of print_sockaddr_by_inode
As -yy parser, compared to -y, needs to do at least 5 extra syscalls
(getxattr, socket, sendmsg, recvmsg, close) to print socket details,
caching results of netlink conversations between strace and kernel
noticeably reduces amount of system time spent by strace.
The caching is safe since sockets do not change their addresses after
successful bind or connect syscall.
* defs.h (string_quote, print_sockaddr_by_inode_cached): New prototypes.
* socketutils.c (cache_entry): New type.
(CACHE_SIZE, CACHE_MASK): New macros.
(cache): New static array.
(cache_and_print_inode_details): New static function.
(print_sockaddr_by_inode_cached): New function.
(inet_parse_response, unix_parse_response): Use
cache_and_print_inode_details.
* util.c (printfd): Use string_quote and print_sockaddr_by_inode_cached.
(string_quote): Remove static qualifier.
* NEWS: Mention this improvement.
* tests/unix-yy.c (main): Update.
Dmitry V. Levin [Sat, 30 Jan 2016 23:50:54 +0000 (23:50 +0000)]
Robustify netlink response parsers
* socketutils.c (inet_parse_response, unix_parse_response): Change
return type from bool to int, return -1 on all parse errors except
inode mismatch.
(receive_responses): Stop on the first nlmsg_type that is not
SOCK_DIAG_BY_FAMILY, also stop when the parser returns -1.
* tests/netlink_inet_diag.c (check_responses): Stop on short messages,
on first nlmsg_type that is not SOCK_DIAG_BY_FAMILY, print more verbose
diagnostics for NLMSG_ERROR.
* tests/netlink_unix_diag.c (check_responses): Likewise.
Dmitry V. Levin [Fri, 29 Jan 2016 01:51:54 +0000 (01:51 +0000)]
Fixed decoding of mincore syscall's last argument
* mem.c (SYS_FUNC(mincore)): Print only those bytes of the vector
that were written by the kernel.
* NEWS: Mention this fix.
* tests/mincore.c: New file.
* tests/mincore.test: New test.
* tests/Makefile.am (check_PROGRAMS): Add mincore.
(TESTS): Add mincore.test.
* tests/.gitignore: Add mincore.
Dmitry V. Levin [Fri, 22 Jan 2016 14:37:14 +0000 (14:37 +0000)]
Implement simultaneous use of -p option and tracing of a command
* strace.c (init): Allow -p option along with a command.
(startup_child): In -D mode, record the parent of the tracer process
as strace_child.
(startup_attach): Save trace_tracer_pid before -D mode fork.
When tracing a command in -f mode, do not check for the command's
threads as it has no threads at this moment.
Never attach to the tracer process.
In -D mode, never attach to the parent of the tracer process,
terminate that process only once at the end of startup_attach,
and reset strace_child.
* strace.1: Document that -p option can be used along with tracing
of a command.
* NEWS: Mention it.
* tests/attach-p-cmd-cmd.c: New file.
* tests/attach-p-cmd-p.c: Likewise.
* tests/attach-p-cmd.test: New test.
* tests/.gitignore: Add attach-p-cmd-cmd and attach-p-cmd-p.
* tests/Makefile.am (check_PROGRAMS): Likewise.
(TESTS): Add attach-p-cmd.test.
Dmitry V. Levin [Thu, 21 Jan 2016 23:52:39 +0000 (23:52 +0000)]
tests: use local nanosleep based sleep utility replacement
* tests/sleep.c: New file.
* tests/.gitignore: Add sleep.
* tests/Makefile.am (check_PROGRAMS): Likewise.
* tests/count.test: Use it instead of system sleep utility.
Dmitry V. Levin [Wed, 20 Jan 2016 00:17:02 +0000 (00:17 +0000)]
Fix decoding and dumping of readv syscall in case of short read
* defs.h (dumpiov_upto): New prototype.
(dumpiov): Change to a wrapper around dumpiov_upto.
* util.c (dumpiov): Rename to dumpiov_upto, add and check data_size
argument.
* io.c (SYS_FUNC(readv)): Call tprint_iov_upto instead
of tprint_iov and specify syscall return value as a data size limit.
* syscall.c (dumpio): In case of SEN_readv, call dumpiov_upto instead
of dumpiov and specify syscall return value as a data size limit.
* NEWS: Mention this fix.
* tests/readv.c: New file.
* tests/readv.test: New test.
* tests/Makefile.am (check_PROGRAMS): Add readv.
(TESTS): Add readv.test.
* tests/.gitignore: Add readv.
Dmitry V. Levin [Tue, 19 Jan 2016 02:10:23 +0000 (02:10 +0000)]
quotactl: add decoding of if_dqinfo.dqi_flags constants
* xlat/if_dqinfo_flags.in: New file.
* quota.c: Include "xlat/if_dqinfo_flags.h".
(decode_cmd_data): Print struct if_dqinfo.dqi_flags using printflags.
Dmitry V. Levin [Tue, 19 Jan 2016 01:15:49 +0000 (01:15 +0000)]
quotactl: consistenly decode all write and unknown commands on entering
* quota.c (decode_cmd_data): Change return type to int.
Return 0 on entering Q_GETQUOTA, Q_V1_GETQUOTA, Q_V2_GETQUOTA,
Q_XGETQUOTA, Q_GETFMT, Q_GETINFO, Q_V2_GETINFO, Q_V1_GETSTATS,
Q_V2_GETSTATS, and Q_XGETQSTAT commands, return RVAL_DECODED
for any other command.
(SYS_FUNC(quotactl)): On entering, print third argument of any command.
For any command except Q_QUOTAON and Q_V1_QUOTAON, call decode_cmd_data
and forward its return value.
Dmitry V. Levin [Mon, 18 Jan 2016 21:34:42 +0000 (21:34 +0000)]
quotactl: fix Q_GETFMT and Q_XQUOTAON commands decoding
* quota.c (decode_cmd_data): As quota format value and xfs quota flags
are in-memory constants, print it like an array of one element instead
of a structure.
Dmitry V. Levin [Sat, 16 Jan 2016 22:50:09 +0000 (22:50 +0000)]
Move definitions of quotactl constants to xlat files
* quota.c (Q_*): Move to xlat/quotacmds.in.
(USRQUOTA, GRPQUOTA): Move to xlat/quotatypes.in.
(QFMT_VFS_OLD, QFMT_VFS_V0): Move to xlat/quota_formats.in.
(XFS_QUOTA_*): Move to xlat/xfs_quota_flags.in.
(XFS_*_QUOTA): Move to xlat/xfs_dqblk_flags.in.
(QIF_*): Move to xlat/if_dqblk_valid.in.
(IIF_*): Move to xlat/if_dqinfo_valid.in.
This fixes the test on platforms where both __NR_sendmmsg and
HAVE_SENDMMSG are defined but the former is not implemented by the
kernel and the second is implemented as an indirect syscall.
* tests/mmsg.c (LENGTH_OF): New macro.
(send_mmsg, recv_mmsg): Print expected output in case of ENOSYS.
(main): Redirect stdout to a new descriptor. Use LENGTH_OF.
Print expected output.
* tests/mmsg.test: Update.
* tests/mmsg.expected: Remove.
* tests/Makefile.am (EXTRA_DIST): Remove mmsg.expected.
Dmitry V. Levin [Wed, 13 Jan 2016 20:53:41 +0000 (20:53 +0000)]
s390, s390x: fix printing of syscalls unknown to the kernel
On s390/s390x, syscalls with NR up to 255 can be implemented
directly using "svc NR", for NR >= 256 "svc 0" with %r1=NR is used.
The latter method is allowed for NR < 256, too.
When the syscall number specified directly or indirectly is recognized
by the kernel, i.e. it is less than its NR_syscalls value, it is stored
in %r2 and is available to arch_get_scno via s390_regset.gprs[2].
For syscall numbers >= NR_syscalls this register is set to 0,
but %r1 remains unchanged and could be used by arch_get_scno
via s390_regset.gprs[1] to decide what the syscall number is.
* linux/s390/get_scno.c (arch_get_scno): If s390_regset.gprs[2] is zero,
take syscall number from s390_regset.gprs[1].
* NEWS: Mention this fix.
This fixes Debian bug #485979 and Fedora bug #1298294.
Dmitry V. Levin [Wed, 13 Jan 2016 12:12:33 +0000 (12:12 +0000)]
travis-ci: update build matrix
Add clang-3.6/x86_64, clang-3.6/x86, and musl-gcc/x86_64 to the matrix.
* .travis.yml (compiler): Add gcc, clang-3.6, and musl-gcc.
(env): Add matrix, remove global ENABLE_GCC_WERROR.
(matrix): Add exclude, remove include.
* travis-ci.sh: Add support for clang and musl-gcc.
Use --enable-gcc-Werror for gcc build unconditionally.
Dmitry V. Levin [Wed, 13 Jan 2016 02:31:12 +0000 (02:31 +0000)]
mpers.awk: add support for DWARF files generated by clang
* mpers.awk: Define default_pointer_size. Initialize byte_size
for DW_TAG_pointer_type to default_pointer_size. Set parent
for DW_TAG_member only. Handle DW_AT_count as an alternative
to DW_AT_upper_bound.
Dmitry V. Levin [Tue, 12 Jan 2016 21:27:36 +0000 (21:27 +0000)]
configure.ac: reorder some statements for better readability
* configure.ac: Sort and group together AC_PROG_*, AC_C_*, AC_TYPE_*,
AC_HEADER_*, AC_CHECK_FUNCS, AC_CHECK_TYPES, AC_CHECK_MEMBERS,
and AC_CHECK_HEADERS.
Dmitry V. Levin [Tue, 12 Jan 2016 14:47:12 +0000 (14:47 +0000)]
scm_rights-fd.test: rewrite without fork
* tests/scm_rights.c (main): Rewrite without fork.
Place all objects passed to sendmsg and recvmsg at the end
of memory pages followed by inaccessible pages.
* tests/scm_rights-fd.test: Update.
Dmitry V. Levin [Tue, 12 Jan 2016 01:13:48 +0000 (01:13 +0000)]
Fix struct sigevent decoding for musl
Do not rely on "struct sigevent.__pad" being located at the same address
as "struct sigevent.sigev_notify_thread_id", it's not the case with musl
libc. Do not rely on struct sigevent definition at all to access
sigev_notify_thread_id.
* configure.ac (AC_CHECK_MEMBERS): Remove struct sigevent._sigev_un._pad
and struct sigevent.__pad.
* sigevent.h: New file.
* Makefile.am (strace_SOURCES): Add it.
* print_sigevent.c: Include it.
* print_sigevent.c (struct_sigevent): Remove.
(print_sigevent): Update all struct_sigevent users.
* tests/timer_create.c: Include "sigevent.h".
(main): Use struct_sigevent instead of struct sigevent,
all struct sigevent clients changed.
Dmitry V. Levin [Tue, 12 Jan 2016 00:03:41 +0000 (00:03 +0000)]
tests: fix TEST_SYSCALL_{NR,STR} and STRUCT_STAT_STR macros for musl
The contents of TEST_SYSCALL_NAME and STRUCT_STAT macros was subject
to macro expansion when used in definitions of TEST_SYSCALL_NR,
TEST_SYSCALL_STR, and STRUCT_STAT_STR macros.
As some libcs, e.g. musl libc, define lfs64 names as macros
(stat64 as stat, lstat64 as lstat, etc.), this might result to incorrect
expansion of TEST_SYSCALL_NR, TEST_SYSCALL_STR, and STRUCT_STAT_STR
macros. To avoid this problem, define these macros directly and remove
TEST_SYSCALL_NAME macro.
The size of off_t is not something one can rely upon. For example,
musl libc unconditionally defines it as an int64_t type on x86.
A cast to the target type helps to avoid these libc differences.
* configure.ac: Call AC_C_TYPEOF.
* tests/struct_flock.c (TYPEOF_FLOCK_OFF_T): New macro.
(test_flock_einval): Use it instead of off_t.
The types that are used to define msg_namelen member of struct msghdr
and cmsg_len member of struct cmsghdr differ between libcs.
For example, glibc defines them as size_t, while musl libc - as type
socklen_t. Print these fields using %lu format to avoid issues caused
by libc differences.
* tests/inet-cmsg.c (main): Cast mh.msg_controllen and c->cmsg_len
to unsigned long and print them using %lu format.
Dmitry V. Levin [Mon, 11 Jan 2016 00:17:36 +0000 (00:17 +0000)]
mmsg.test: check memory access by sendmmsg and recvmmsg decoders
* tests/tests.h (tail_memdup): New prototype.
* tests/tail_alloc.c (tail_memdup): New function.
* tests/mmsg.c (main): Place all objects passed to sendmmsg and recvmmsg
at the end of memory pages followed by inaccessible pages.
Dmitry V. Levin [Mon, 11 Jan 2016 00:16:39 +0000 (00:16 +0000)]
mmsg.test: prefer direct sendmmsg/recvmmsg syscalls to libc wrappers
* tests/mmsg.c: Include <sys/syscall.h>.
Check for __NR_sendmmsg as an alternative to HAVE_SENDMMSG.
[!HAVE_STRUCT_MMSGHDR] (struct mmsghdr): Define.
(send_mmsg, recv_mmsg): New functions.
(main): Use them instead of sendmmsg and recvmmsg.
Dmitry V. Levin [Thu, 7 Jan 2016 01:42:05 +0000 (01:42 +0000)]
tests/vfork-f.c: support platforms without vfork
On some platforms, e.g. hppa glibc, vfork() is implemented using fork
syscall, so the test cannot rely on the parent process remaining blocked
until the child process either terminates or calls execve.
* tests/vfork-f.c (main): Explicitly block the parent until the child
either terminates or calls execve.
Dmitry V. Levin [Thu, 7 Jan 2016 00:31:33 +0000 (00:31 +0000)]
Fix and enhance decoding of sched_[gs]etaffinity syscalls
Print cpu_set_t as a set of integers, similar to the way
fd_set is printed as a set of descriptors.
* affinity.c: Include <sched.h>.
(get_cpuset_size): New function.
(print_affinitylist): Rewrite using get_cpuset_size and next_set_bit.
(sched_getaffinity, sched_setaffinity): Print first two args as ints.
* NEWS: Mention this enhancement.
* tests/sched_xetaffinity.c: New file.
* tests/sched_xetaffinity.test: New test.
* tests/Makefile.am (check_PROGRAMS): Add sched_xetaffinity.
(TESTS): Add sched_xetaffinity.test.
* tests/.gitignore: Add sched_xetaffinity.