Commit Graph

365 Commits

Author SHA1 Message Date
d6c71dd061 Fix preprocessor indentation
Indent the C preprocessor directives to reflect their nesting
using the following script:

$ cppi -l $(git grep -El '^[[:space:]]*#[[:space:]]*(if|ifdef|ifndef|elif|else|endif|define|pragma)[[:space:]]' |grep -v '\.sh$') |while read f; do
	cppi < "$f" > "$f".cppi; mv "$f".cppi "$f"
done
2018-12-30 15:35:21 +00:00
b93d52fe3d Change the license of strace to LGPL-2.1-or-later
strace is now provided under the terms of the GNU Lesser General
Public License version 2.1 or later, see COPYING for more details.

strace test suite is now provided under the terms of the GNU General
Public License version 2 or later, see tests/COPYING for more details.
2018-12-10 00:00:00 +00:00
Eugene Syromyatnikov
30fe991db8 print_array: add support for printing array indices
* defs.h (XLAT_STYLE_SPEC_BITS, XLAT_STYLE_MASK): New macro constants.
(tfetch_mem_fn, print_fn): New typedefs.
(enum print_array_flag_bits, enum print_array_flags): New enumerations.
(print_array_ex): Rename from print_array, add flags, index_xlat,
index_xlat_size, and index_dflt arguments.
(print_array): New static inline function, a thin wrapper around
print_array_ex.
util.c: Include "xlat.h".
(print_array): Rename to print_array_ex, add flags, index_xlat,
index_xlat_size, and index_dflt arguments.  Print array indices
according to the style settings specified by flags if PAF_PRINT_INDICES
is set.
2018-05-30 10:13:06 +00:00
d54388e1ce print_array: enhance printing of unfetchable object addresses
When umoven_func invocation fails to fetch data, it prints the faulty
address.  If this happens to a subsequent umoven_func invocation,
the printed address may be undistinguishable from a valid data printed
by print_func, e.g. when the data is printed in a numeric form like
[0x1, 0x2, 0x3, 0xdefaced].

Fix this source of confusion by moving the printing of the faulty
address from umoven_func to print_array itself.  This change renames
umoven_func to tfetch_mem_func and changes its semantics, so that
 - tfetch_mem_func never prints anything;
 - tfetch_mem_func returns true if the fetch succeeded,
   and false otherwise.

* defs.h (print_array): Replace umoven_func argument with
tfetch_mem_func.
* util.c (print_array): Replace umoven_func argument with
tfetch_mem_func, document expected tfetch_mem_func return value
semantics.  When tfetch_mem_func returns false, print either addr
or "... /* addr */" depending on the context (inside the array or not).
* bpf.c (print_ebpf_prog, print_bpf_prog_info,
BEGIN_BPF_CMD_DECODER(BPF_PROG_QUERY)): Replace umoven_or_printaddr
argument of print_array with tfetch_mem.
* bpf_filter.c (print_bpf_fprog): Likewise.
* btrfs.c (btrfs_print_logical_ino_container,
btrfs_print_ino_path_container, btrfs_print_qgroup_inherit,
btrfs_ioctl): Likewise.
* dm.c (dm_decode_dm_target_deps): Likewise.
* epoll.c (epoll_wait_common): Likewise.
* file_ioctl.c (file_ioctl): Likewise.
* ipc_sem.c (tprint_sembuf_array): Likewise.
* kexec.c (print_kexec_segments): Likewise.
* mem.c (SYS_FUNC(subpage_prot)): Likewise.
* net.c (print_getsockopt): Likewise.
* netlink.c (decode_nlmsgerr_attr_cookie): Likewise.
* netlink_netlink_diag.c (decode_netlink_diag_groups): Likewise.
* netlink_packet_diag.c (decode_packet_diag_mclist): Likewise.
* netlink_unix_diag.c (decode_unix_diag_inode): Likewise.
* nlattr.c (decode_nla_meminfo): Likewise.
* numa.c (print_nodemask, SYS_FUNC(move_pages),
* perf_ioctl.c (perf_ioctl_query_bpf): Likewise.
* poll.c (decode_poll_entering): Likewise.
* printsiginfo.c (print_siginfo_array): Likewise.
* rtnl_tc.c (decode_tca_stab_data): Likewise.
* sock.c (decode_ifconf): Likewise.
* uid.c (print_groups): Likewise.
* io.c (SYS_FUNC(io_submit), SYS_FUNC(io_getevents)): Replace
umoven_or_printaddr argument of print_array with tfetch_mem.
(tprint_iov_upto): Replace umoven_or_printaddr_ignore_syserror
with tfetch_mem_ignore_syserror.
* v4l2.c (print_v4l2_format_fmt): Replace umoven_or_printaddr argument
of print_array with tfetch_mem.
(print_v4l2_ext_controls): Replace umoven_or_printaddr_ignore_syserror
with tfetch_mem_ignore_syserror.
* mmsghdr.c (fetch_struct_mmsghdr_or_printaddr): Rename
to fetch_struct_mmsghdr_for_print, do not print address, return bool.
(decode_mmsgvec): Replace fetch_struct_mmsghdr_or_printaddr
with fetch_struct_mmsghdr_for_print.
* tests/aio.c (main): Update expected output.
* tests/bpf.c (print_BPF_PROG_QUERY_attr5): Likewise.
* tests/ioctl_perf-success.c (main): Likewise.
* tests/ioctl_v4l2.c (main): Update expected output.
* tests/kexec_load.c (main): Likewise.
* tests/mmsg_name.c (test_mmsg_name): Update expected output.
* tests/move_pages.c (print_page_array, print_node_array): Likewise.
* tests/poll.c (print_pollfd_array_entering): Likewise.
* tests/preadv-pwritev.c (main): Likewise.
* tests/preadv2-pwritev2.c (dumpio): Likewise.
* tests/process_vm_readv_writev.c (print_iov): Likewise.
* tests/pwritev.c (print_iovec): Likewise.
* tests/readv.c (main): Likewise.
* tests/seccomp-filter-v.c
* tests/semop.c (main): Likewise.
* tests/set_mempolicy.c (print_nodes): Likewise.
* tests/setgroups.c (main): Likewise.
* tests/test_nlattr.h (print_nlattr) Likewise.

Co-Authored-by: Eugene Syromyatnikov <evgsyr@gmail.com>
2018-05-29 09:58:10 +00:00
143d007bbd Introduce tfetch_* family of functions and macros
These new functions are going to be used instead of umove_or_printaddr*
as umoven_func argument of print_array.

* defs.h (tfetch_mem64, tfetch_mem64_ignore_syserror): New
function prototypes.
(tfetch_mem, tfetch_mem_ignore_syserror): New static inline
wrappers.
(tfetch_obj): New macro wrapper around tfetch_mem.
* util.c (tfetch_mem64, tfetch_mem64_ignore_syserror): New
functions.
(umoven_or_printaddr64, umoven_or_printaddr64_ignore_syserror): Use
them.
2018-05-29 09:58:10 +00:00
87faa97539 Turn printaddr into a thin wrapper around printaddr64
* util.c (printaddr): Move ...
* defs.h: ... here, add "static inline" qualifiers.
2018-05-29 09:58:10 +00:00
Eugene Syromyatnikov
4245bdfe41 Introduce print_uint32_array_member helper function
Analogous to print_int32_array_member, this helper is going to be used
in various decoders, including BPF_PROG_QUERY, PERF_EVENT_IOC_*,
and netlink meminfo.

* defs.h (print_uint32_array_member): New declaration.
* util.c (print_uint32_array_member): New function.
2018-05-23 23:27:43 +00:00
Eugene Syromyatnikov
ddf97dcf74 Introduce print_int32_array_member helper function
Analogous to print_uint64_array_member, this helper is going to be used
for IFLA_AF_SPEC decoding.

* defs.h (print_int32_array_member): New declaration.
* util.c (print_int32_array_member): New function.
2018-05-23 23:27:43 +00:00
Eugene Syromyatnikov
0b578fd0ba util.c: make memory allocation error messages more informative
As those are pretty unusual, let's add some additional information
that can be reported by users.

* util.c (print_quoted_string_ex, dumpstr): Add reasons for memory
allocation errors.
(sizeof_iov): Change type from size_t to unsigned int.
(dumpiov_upto): Rewrite size initialisation similarly to the way it's
done in print_quoted_string_ex, add reasons for memory allocation errors.

Co-Authored-by: Dmitry V. Levin <ldv@altlinux.org>
2018-05-21 11:02:54 +00:00
Eugene Syromyatnikov
973687fd92 util.c: add len sanity checks to dumpstr
Reported by clang.

* util.c (dumpstr): Check that len is sane.
2018-05-03 00:09:53 +00:00
Eugene Syromyatnikov
fbb12e77d5 util.c: make "Out of memory" messages a bit more informative
Since these are emitted in multiple places and are not expected during
any normal operation, it makes sense to report the caller name.

* util.c (print_quoted_string_ex, print_quoted_string_ex, dumpiov_upto,
dumpstr): Replace error_msg with error_func_msg.
2018-04-24 00:35:27 +00:00
Eugene Syromyatnikov
459ea39686 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.
2018-04-10 03:38:10 +00:00
Eugene Syromyatnikov
1aee6198c7 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.
2018-04-10 03:38:10 +00:00
Eugene Syromyatnikov
b5a02fe645 util.c: amend sprinttime_ex description a bit
* util.c (sprinttime_ex): Document return value.
2018-04-01 13:14:15 +00:00
17935497e2 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.
2018-03-20 02:30:24 +00:00
Eugene Syromyatnikov
84c03b20b4 util.c: introduce printaddr64
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.
2018-03-06 23:52:08 +00:00
Eugene Syromyatnikov
48feeb3723 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>
2018-03-01 01:00:24 +00:00
Eugene Syromyatnikov
6d36a70868 util.c: escape closing angle bracket in printfd
* util.c (printfd): Use print_quoted_string_ex instead of
print_quoted_string, specify ">" as escape_chars argument.
* tests/fsync-y.c (main): Update expected output.
* NEWS: Mention it.
2018-03-01 01:00:24 +00:00
Eugene Syromyatnikov
0b732f7e9d 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>
2018-03-01 01:00:24 +00:00
Eugene Syromyatnikov
f6f7b82d4b 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.
2018-03-01 01:00:24 +00:00
Eugene Syromyatnikov
1f64f75320 util.c: reduce indentation in non-hexadecimal case in string_quote
As it is already too deep there.

* util.c (string_quote): Add string_ended label, jump there
after the loop in "if (usehex)" case.
2018-03-01 01:00:24 +00:00
Eugene Syromyatnikov
3c0be8d36d util.c: fix switch statement indentation in string_quote
While we are here, let's also remove unnecessary break statement
in the default case.
2018-03-01 01:00:24 +00:00
daaf8ab7fe Update copyright headers
Headers updated automatically using maint/update_copyright_years.sh
script.
2018-02-13 22:00:00 +00:00
f2bb704a92 Include <limits.h> instead of <sys/param.h>
Do not include <sys/param.h> unnecessarily as it includes <signal.h>.

* pathtrace.c: Include <limits.h> instead of <sys/param.h>.
* strace.c: Likewise.
* syscall.c: Likewise.
* util.c: Likewise.
* tests/getcwd.c: Likewise.
* tests/group_req.c: Likewise.
* tests/inode_of_sockfd.c: Likewise.
* tests/ip_mreq.c: Likewise.
* tests/printpath-umovestr.c: Likewise.
* tests/qual_fault.c: Likewise.
* tests/test_printpath.c: Likewise.
* tests/umovestr3.c: Likewise.
* tests/net-y-unix.c: Do not include <sys/param.h>.
* tests/net-yy-unix.c: Likewise.
2018-02-11 00:26:09 +00:00
Eugene Syromyatnikov
501611115f Add print_quoted_string flag to generate comment
Because there are never enough print_quoted_string flags.

* defs.h (QUOTE_EMIT_COMMENT): New quoting flag macro constant.
* util.c (string_quote): Emit " /* " in the beginning and " */" in the
end if QUOTE_EMIT_COMMENT is passed.
(print_quoted_string): Increase alloc_size by 7 if QUOTE_EMIT_COMMENT is
passed.
2018-01-29 14:10:10 +01:00
Eugene Syromyatnikov
b96c599af8 util: return string size in printstr
As umovestr now returns something useful, let's propagate it further.

* defs.h (printstr_ex, printpathn, printpath): Change return type from
void to int.
(printstrn, printstr): Change return type from void to int, return
printstr_ex result.
* util.c (printpathn): Return -1 on NULL addr, nul_seen (exit code of
umovestr) on success.
(printpath): Return printpathn result.
(printstr_ex): Return -1 on NULL addr, umoven/umovestr result otherwise.
2018-01-19 22:45:34 +00:00
Eugene Syromiatnikov
bf2e6250bb Pass tcp argument to get_optmem_max/read_int_from_file
In preparation to passing tcp to all tracee-related syscalls.

* defs.h (read_int_from_file): Add "struct tcb *" as the first argument.
* util.c (read_int_from_file): Likewise.
* msghdr.c (get_optmem_max): Add "struct tcb *tcp" as the first
argument, pass it to read_int_from_file call.
(decode_msg_control): Pass tcp to get_optmem_max.
2018-01-07 16:46:32 +00:00
ed22f8e219 util.c: use x*sprintf instead of s*printf
* util.c: Include "xstring.h".
(sprinttime_ex): Replace snprintf with xsnprintf.
(getfdproto): Replace sprintf with xsprintf.
2018-01-07 00:05:42 +00:00
Edgar Kaziakhmedov
b1fab45b47 Move string_to_uint* functions to a separate file
Make string_to_uint* functions available to other binaries
included in the strace package.

* string_to_uint.h: New file.
* defs.h: Include it.
(string_to_uint_ex, string_to_uint_upto, string_to_uint): Move
to string_to_uint.h.
* util.c (string_to_uint_ex, string_to_uint): Move ...
* string_to_uint.c: ... to the new file.
* Makefile.am (strace_SOURCES): Add string_to_uint.h and string_to_uint.c.

Signed-off-by: Edgar Kaziakhmedov <edgar.kaziakhmedov@virtuozzo.com>
Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
2017-08-22 15:24:05 +00:00
d7a45f8dcc printpath: do not fetch more than PATH_MAX bytes from tracee's memory
The kernel does not copy more than PATH_MAX bytes from userspace
pathnames, treating non-NUL-terminated pathnames as ENAMETOOLONG.

* util.c (printpathn): Decrease buffer size to PATH_MAX.
(printpath): Specify PATH_MAX - 1 as the maximum pathname length
to match the kernel behaviour.  The underlying umovestr call will fetch
up to PATH_MAX bytes from tracee's memory, but no more than first
PATH_MAX - 1 bytes will be printed.
2017-08-01 20:59:48 +00:00
429c08130b util: move umoven and umovestr to a separate file
These functions are more kernel-specific compared to all other functions
defined in util.c.

* ucopy.c: New file.
* Makefile.am (strace_SOURCES): Add it.
* util.c (umoven, umovestr): Move to ucopy.c.
2017-07-28 10:24:35 +00:00
de484eced5 Introduce print_quoted_cstring
In many places where kernel expects a NUL-terminated string of length
up to a known fixed limit, e.g. when a NUL-terminated string is
a fixed-size field of a structure, strace does not print the last byte
assuming it is NUL, which is not always the case.

Change output format for such strings to distinguish NUL-terminated
strings from non-NUL-terminated ones: append ellipsis to the output
when the string is not NUL-terminated.

* defs.h (print_quoted_cstring): New prototype.
* util.c (print_quoted_cstring): New function.
(printpathn): Use it instead of print_quoted_string with
QUOTE_0_TERMINATED argument.
* print_fields.h (PRINT_FIELD_CSTRING): Likewise.
* btrfs.c (btrfs_ioctl): Likewise.
* dirent.c (SYS_FUNC(getdents)): Likewise.
* dirent64.c (SYS_FUNC(getdents64)): Likewise.
* print_ifindex.c (print_ifindex): Likewise.
* sysmips.c (SYS_FUNC(sysmips)): Likewise.
* ubi.c (ubi_ioctl): Likewise.
* tests/tests.h (print_quoted_cstring): New prototype.
* tests/print_quoted_string.c (print_quoted_cstring): New function.
* tests/ioctl_block.c (main): Update expected output.
* tests/ioctl_dm.c (main): Likewise.
* tests/ioctl_loop.c (print_loop_info, print_loop_info64): Likewise.
* tests/netlink_crypto.c (test_crypto_msg_newalg): Likewise.
2017-07-24 12:10:54 +00:00
11621507fb Check -s argument early
* util.c (printstr_ex): Move the check that -s argument
does not exceed -1U / 4 ...
* strace.c (init): ... here.
* tests/options-syntax.test: Check it.
2017-06-26 22:30:19 +00:00
184e94ba05 Fix a few spacing style issues
Reported by kernel's checkpatch.pl script.
2017-06-17 22:54:08 +00:00
3baf7ef953 Fix a few initialization style issues
Do not initialise statics and globals to 0, NULL, or false.

Reported by kernel's checkpatch.pl script.
2017-06-17 20:49:09 +00:00
a74c084611 Fix a few sizeof style issues
Reported by kernel's checkpatch.pl script.
2017-06-17 18:49:58 +00:00
88a34fa6da Move xlat related functions to a separate file
* util.c (xlookup, xlat_bsearch_compare, xlat_search, printxvals,
printxval_searchn, addflags, sprintflags, printflags_ex): Move ...
* xlat.c: ... to this new file.
* Makefile.am (strace_SOURCES): Add it.
2017-06-12 16:44:45 +00:00
127962f217 Introduce printflags_ex function
Add printflags_ex extension over printflags64 that, similar
to printxvals, takes a NULL-terminated sequence of xlat pointers.

* defs.h (printflags_ex): New prototype.
(printflags64): Turn into a thin wrapper around printflags_ex.
* netlink.c (decode_nlmsg_flags): Use printflags_ex.
* util.c (printflags_ex): New function.
(printflags64): Remove.
* xlat/netlink_get_flags.in: Remove entries listed
in xlat/netlink_flags.in file.
* xlat/netlink_new_flags.in: Likewise.
2017-06-08 22:26:46 +00:00
Fabien Siron
f26c22d8b2 Introduce getfdinode to obtain inode from fd
* defs.h (getfdinode): New prototype.
* utils.c (getfdinode): New function.

Co-authored-by: Dmitry V. Levin <ldv@altlinux.org>
2017-06-05 11:52:11 +00:00
e16bdb1bb9 Unexport print_sockaddr_by_inode_cached
Change print_sockaddr_by_inode to be the only function exposed,
hide print_sockaddr_by_inode_cached as a part of implementation.

* defs.h (print_sockaddr_by_inode_cached): Remove prototype.
(print_sockaddr_by_inode): Add struct tcb * and descriptor arguments.
* socketutils.c (print_sockaddr_by_inode_cached): Make static.
(print_sockaddr_by_inode): Rename to print_sockaddr_by_inode_uncached,
make static.
(print_sockaddr_by_inode): New function.
* util.c (printfd): Update to use new print_sockaddr_by_inode.
2017-06-03 17:52:24 +00:00
1459d07f94 Introduce str_strip_prefix_len function and STR_STRIP_PREFIX macro
Address proliferation of string prefix check implementations.

* defs.h (str_strip_prefix_len): New inline function.
(STR_STRIP_PREFIX): New macro.
* qualify.c (strip_prefix): Remove.
(parse_inject_token): Use STR_STRIP_PREFIX instead of strip_prefix.
(qualify): Use str_strip_prefix_len.
* socketutils.c (netlink_parse_response): Likewise.
* util.c (printfd): Likewise.
2017-06-03 16:55:12 +00:00
Eugene Syromyatnikov
9d095c7860 Add copyright headers 2017-05-22 17:33:51 +00:00
Eugene Syromyatnikov
3277a2370a Always print raw values of time data fields
Refactor sprinttime: implement sprinttime_nsec and sprinttime_usec
that handle nanoseconds and microseconds, respectively.
Always print raw values of time data fields, format string
representations of time as comments.

* defs.h (sprinttime): Change argument type from time_t to long long.
(sprinttime_nsec, sprinttime_usec): New prototypes.
* util.c (sprinttime_ex, sprinttime_nsec, sprinttime_usec): New
functions.
(sprinttime): Turn into a thin wrapper around sprinttime_ex.
* stat.h (struct strace_stat): Add has_nsec field.
* fetch_struct_stat.c (HAVE_NSEC): New macro.
(fetch_struct_stat): Initialize has_nsec field with HAVE_NSEC.
* fetch_struct_stat64.c (HAVE_NSEC): New macro.
(fetch_struct_stat64): Initialize has_nsec field with HAVE_NSEC.
* print_struct_stat.c (print_struct_stat) <PRINT_ST_TIME>:
Print raw values of time fields, use sprinttime_nsec to format a string
representation of time, use tprints_comment to print it as a comment.
* statx.c (SYS_FUNC(statx)) <PRINT_FIELD_TIME>: Likewise.
* utime.c (SYS_FUNC(utime)): Print raw values of struct utimbuf.actime
and struct utimbuf.modtime fields, use sprinttime to format a string
representation of time, use tprints_comment to print it as a comment.
* tests/tests.h (print_time_t_nsec): Add int argument.
* tests/print_time.c (print_time_t_ex): New function.
(print_time_t_nsec): Add int argument, turn into a thin wrapper around
print_time_t_ex.
* tests/utime.c (main): Update expected output.
* tests/xstatx.c [!IS_STATX] (HAVE_NSEC): New macro.
[!IS_STATX] (PRINT_ST_TIME), [IS_STATX] (PRINT_FIELD_TIME): Update
expected output.
* NEWS: Mention this timestamps representation improvement.

Co-authored-by: Dmitry V. Levin <ldv@altlinux.org>
2017-04-24 23:14:57 +00:00
c34952709d Introduce tprintf_comment and tprints_comment functions
* defs.h (tprintf_comment, tprints_comment): New prototypes.
* strace.c (tvprintf): New function.
(tprintf): Use it.
(tprintf_comment, tprints_comment): New functions.
* aio.c (tprint_lio_opcode): Use tprints_comment.
* dm.c (dm_decode_dm_target_spec, dm_decode_dm_target_deps,
dm_decode_dm_name_list, dm_decode_dm_target_versions,
dm_decode_dm_target_msg, dm_decode_string, dm_known_ioctl): Likewise.
* futex.c (SYS_FUNC(futex)): Likewise.
* perf.c (print_perf_event_attr): Likewise.
* seccomp.c (decode_bpf_code): Likewise.
* util.c (printxvals, printxval_searchn, printflags64): Likewise.
* btrfs.c (print_u64, btrfs_print_key_type, btrfs_print_objectid,
print_key_value_internal): Likewise.
(btrfs_ioctl): Use tprints_comment and tprintf_comment.
* dirent.c (SYS_FUNC(getdents)): Likewise.
* dirent64.c (SYS_FUNC(getdents64)): Likewise.
* execve.c (printargc): Use tprintf_comment.
* tests/btrfs.c (btrfs_test_get_dev_stats_ioctl,
btrfs_test_features_ioctls): Update expected output.
2017-04-24 19:31:54 +00:00
Eugene Syromyatnikov
0f07b184c8 util: return pointer to string literal directly in sprinttime
There is no sense to copy it to static buffer first.

* util.c (sprinttime): Just return "0", do not copy it to internal
buffer first.
2017-04-21 21:57:56 +00:00
a8d2417e97 aarch64: workaround gcc+kernel bug
Due to a subtle gcc bug that leads to miscompiled aarch64 kernels,
the 3rd argument of sched_getattr syscall is not quite 32-bit
on aarch64 as on other architectures.  For more details see
https://sourceforge.net/p/strace/mailman/message/35721703/

* defs.h (print_abnormal_hi): New prototype.
* util.c (print_abnormal_hi): New function.
* sched.c (SYS_FUNC(sched_getattr)) [AARCH64]: Use it.
* tests/sched_xetattr.c (main) [__arm64__ || __aarch64__]: Test it.
2017-03-29 18:27:14 +00:00
Victor Krapivensky
c9731a0dbe util.c: remove a wrong comment
4924dbd6d7 modified the return type, but
not the comment.
2017-03-13 15:19:22 +00:00
Eugene Syromyatnikov
34a920baad util: add support for forcing printing string as hex-escaped
This could be useful in cases when some binary data should not be
interpreted as an ASCII string, but rather as an array of byte values.

* defs.h (QUOTE_FORCE_HEX): New macro constant.
* util.c (quote_string): Enable use_hex when QUOTE_FORCE_HEX is set
in user_style parameter.
2017-01-06 11:39:54 +00:00
b58f75c5d4 Remove checks of __NR_* availability from strace source code
* strace.c: Remove __NR_tkill checks, assume it is always defined.
* util.c: Remove __NR_process_vm_readv checks and fallback definitions,
assume it is always defined.
2017-01-03 13:46:26 +00:00
2dd365f912 Include "scno.h" in files that check __NR_* constants
* strace.c: Include "scno.h".
* util.c: Likewise.
2017-01-03 11:27:35 +00:00