Nahim El Atmani [Sat, 5 Mar 2016 12:35:57 +0000 (13:35 +0100)]
Reduce memory usage while managing tcbs allocation.
* strace.c (init): Remove initial memory allocation for tcbtab.
(expand_tcbtab): Do initial memory allocation when tcbtabsize == 0.
Signed-off-by: Nahim El Atmani <nahim+dev@naam.me> Reviewed-By: Gabriel Laskar <gabriel@lse.epita.fr> Reported-by: haris iqbal <haris.phnx@gmail.com> Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
Dmitry V. Levin [Wed, 17 Feb 2016 05:24:43 +0000 (05:24 +0000)]
Print pid_t arguments of rt_sigqueueinfo and rt_tgsigqueueinfo as int
* signal.c (SYS_FUNC(rt_sigqueueinfo)): Print first syscall argument
using %d format.
(SYS_FUNC(rt_tgsigqueueinfo)): Print first and second syscall arguments
using %d format.
* tests/rt_tgsigqueueinfo.c: New file.
* tests/rt_tgsigqueueinfo.test: New test.
* tests/.gitignore: Add rt_tgsigqueueinfo.
* tests/Makefile.am (check_PROGRAMS): Likewise.
(TESTS): Add rt_tgsigqueueinfo.test.
Dmitry V. Levin [Thu, 18 Feb 2016 00:08:30 +0000 (00:08 +0000)]
Fix corner cases of rt_sigpending syscall decoder
* signal (print_sigset_addr_len_limit): New function, cloned from
print_sigset_addr_len with added minimal length argument.
Treat length less than minimal length or greater than NSIG/8 as invalid.
Do not align length to 4-byte boundary. Align destination buffer
to 4-byte boundary and initialize it with zeroes so that subsequent
call to sprintsigmask_n will not access uninitialized data.
(print_sigset_addr_len): Turn into a wrapper around
print_sigset_addr_len_limit with current_wordsize
as a minimal length argument.
(SYS_FUNC(rt_sigpending)): Call print_sigset_addr_len_limit
instead of print_sigset_addr_len with 1 as a minimal length argument.
* tests/rt_sigpending.c: New file.
* tests/rt_sigpending.test: New test.
* tests/.gitignore: Add rt_sigpending.
* tests/Makefile.am (check_PROGRAMS): Likewise.
(TESTS): Add rt_sigpending.test.
* socketutils.c (unix_send_query): Add NLM_F_DUMP to nlmsg_flags,
remove initialization of udiag_cookie.
* tests/netlink_unix_diag.c (send_query): Remove "inode" argument,
add NLM_F_DUMP to nlmsg_flags, remove initialization of udiag_ino
and udiag_cookie.
(check_responses): Remove "inode" argument and its use.
(main): Remove invocation of inode_of_sockfd and passing of listening
socket inode to send_query and check_responses.
Dmitry V. Levin [Mon, 15 Feb 2016 18:30:02 +0000 (18:30 +0000)]
Print offsets in lseek and _llseek syscalls as signed integers
* lseek.c (SYS_FUNC(lseek)): Print offset using %lld format.
(SYS_FUNC(llseek)): Likewise. Treat high and low components of offset
as unsigned long integers.
* tests/llseek.c (main): Check that negative offset is printed properly.
* tests/lseek.c (main): Likewise.
Dmitry V. Levin [Sat, 13 Feb 2016 01:23:26 +0000 (01:23 +0000)]
tests: robustify execve and execveat tests
* tests/execve.c (main): Use one page gap between two mapped regions
for an address that is more likely to be not yet mapped.
* tests/execveat.c (main): Likewise.
Dmitry V. Levin [Fri, 12 Feb 2016 01:56:10 +0000 (01:56 +0000)]
tests: check decoding of madvise, mlockall, mremap, and msync syscalls
* tests/mmap.c (main): Change output format from regexp to verbatim.
Add tests for madvise, mlockall, mremap, and msync syscalls.
* tests/mmap.test: Convert from match_grep to match_diff.
Add madvise, mlockall, mremap, and msync syscalls to syscall filter.
Dmitry V. Levin [Wed, 10 Feb 2016 17:43:09 +0000 (17:43 +0000)]
socketutils: add const qualifier to variables
* socketutils.c (cache_and_print_inode_details): Make "details"
parameter const.
(print_sockaddr_by_inode_cached): Make "e" variable const.
(inet_send_query): Make struct nlmsghdr and struct inet_diag_req_v2
members const. Make "msg" variable const.
(inet_parse_response): Make "data" parameter and diag_msg variable const.
(receive_responses): Make "h" and "rc" variables const.
(unix_send_query): Make struct nlmsghdr and struct unix_diag_req
members const. Make "msg" variable const.
(unix_print): Make all parameters const.
(print_sockaddr_by_inode): Make proto_name parameter const.
Dmitry V. Levin [Wed, 10 Feb 2016 17:39:57 +0000 (17:39 +0000)]
print_sockaddr_by_inode: cleanup protocol lookup
* socketutils.c (tcp_v4_print, udp_v4_print, tcp_v6_print,
udp_v6_print): New functions.
(print_sockaddr_by_inode): Make "protocols" array static, replace
"family" and "protocol" members with "print" in its underlying
structure. Iterate through protocols array when the protocol name
is specified.
Dmitry V. Levin [Thu, 4 Feb 2016 02:49:01 +0000 (02:49 +0000)]
Introduce libstrace.a for potentially conditional compilation units
Some files are used conditionally depending on architecture and
configuration. Create a library for the purpose of keeping such
compilation units.
* Makefile.am (strace_LDADD, noinst_LIBRARIES): Add libstrace.a.
(libstrace_a_CPPFLAGS): New variable, set to $(strace_CPPFLAGS).
(libstrace_a_CFLAGS): New variable, set to $(strace_CFLAGS).
(libstrace_a_SOURCES): New variable, set to upeek.c.
* util.c (upeek): Move ...
* upeek.c: ... here.
Dmitry V. Levin [Sat, 6 Feb 2016 00:56:55 +0000 (00:56 +0000)]
tests: extend coverage of utime syscall
* tests/utime.c (main): Check decoding of NULL struct utimbuf pointer.
Check decoding of struct utimbuf located at the end of page boundary.
* tests/utime.test: Update.
Dmitry V. Levin [Sat, 6 Feb 2016 00:56:34 +0000 (00:56 +0000)]
tests: extend coverage of sysinfo syscall
* tests/sysinfo.c (main): Check decoding of NULL struct sysinfo pointer.
Check decoding of struct sysinfo located at the end of page boundary.
* tests/sysinfo.test: Update.
Dmitry V. Levin [Sat, 6 Feb 2016 00:56:15 +0000 (00:56 +0000)]
tests: extend coverage of adjtimex syscall
* tests/adjtimex.c (main): Check decoding of NULL struct timex pointer.
Check decoding of struct timex located at the end of page boundary.
* tests/adjtimex.test: Update.
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.