]> granicus.if.org Git - strace/log
strace
9 years agoioctlent.sh: update the list of directories exported by headers_install
Dmitry V. Levin [Mon, 3 Nov 2014 18:38:51 +0000 (18:38 +0000)]
ioctlent.sh: update the list of directories exported by headers_install

* linux/ioctlent.sh: Add drm, mtd, rdma, video, and xen directories.

9 years agoAdd a function for dumping iovec in msghdr used in sendmsg and recvmsg
Masatake YAMATO [Wed, 15 Oct 2014 13:11:43 +0000 (22:11 +0900)]
Add a function for dumping iovec in msghdr used in sendmsg and recvmsg

Here is an example session:

    $ ./strace -e write=all ip link change dev enp0s25 mtu 1501 > /dev/null
    sendmsg(3, {msg_name(12)={sa_family=AF_NETLINK, pid=0, groups=00000000}, msg_iov(1)=[{"(...
     * 40 bytes in buffer 0
     | 00000  28 00 00 00 10 00 05 00  d0 d9 aa 53 00 00 00 00  (..........S.... |
     | 00010  00 00 00 00 02 00 00 00  00 00 00 00 00 00 00 00  ................ |
     | 00020  08 00 04 00 dd 05 00 00                           ........         |
    ...

    $ ./strace -e read=all ip link show > /dev/null
    recvmsg(3, {msg_name(12)={sa_family=AF_NETLINK, pid=0, groups=00000000}, msg_iov(1)=[{"...
     * 8192 bytes in buffer 0
     | 00000  34 00 00 00 02 00 00 00  00 00 00 00 ff 23 00 00  4............#.. |
     | 00010  ff ff ff ff 20 00 00 00  10 00 05 00 00 00 00 00  .... ........... |
    ...

* defs.h (dumpiov_in_msghdr): New prototype.
* net.c (extractmsghdr): New function derived from printmsghdr.
(printmsghdr): Use extractmsghdr.
(dumpiov_in_msghdr): New function.
* syscall.c (dumpio) [HAVE_SENDMSG]: Call dumpiov_in_msghdr for recvmsg
and sendmsg syscalls.

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
9 years agoInclude <linux/ptrace.h> regardless of <sys/reg.h> existence
Maarten ter Huurne [Sun, 19 Oct 2014 23:02:48 +0000 (01:02 +0200)]
Include <linux/ptrace.h> regardless of <sys/reg.h> existence

This fixes compilation with musl libc.
This approach was already used in process.c, so I assume it is safe.

* signal.c: Move [HAVE_LINUX_PTRACE_H] code out of [HAVE_SYS_REG_H] check.
* syscall.c: Likewise.
* util.c: Likewise.

Signed-off-by: Maarten ter Huurne <maarten@treewalker.org>
9 years agosock: decode SIOCSIFNAME on entering syscall
Dmitry V. Levin [Fri, 31 Oct 2014 19:36:01 +0000 (19:36 +0000)]
sock: decode SIOCSIFNAME on entering syscall

* sock.c (sock_ioctl): Handle SIOCSIFNAME on entering syscall.

9 years agosock: fix decoding of SIOCSIFNAME
Mike Frysinger [Tue, 21 Oct 2014 12:34:08 +0000 (08:34 -0400)]
sock: fix decoding of SIOCSIFNAME

The decoding of SIOCSIFNAME is incorrect.  It does not use
the ifr_index field to look things up, but ifr_newname.

* sock.c (sock_ioctl): Split out SIOCSIFNAME from SIOCGIFNAME and
display ifr_newname.

9 years agosock: fix decoding of struct ifreq.ifr_name
Mike Frysinger [Tue, 21 Oct 2014 12:34:08 +0000 (08:34 -0400)]
sock: fix decoding of struct ifreq.ifr_name

The ifr name fields of the ifreq structure might not be NUL terminated.
If the user makes an ioctl call where they aren't, then strace ends up
reading random content from its own stack.  Limit the printf lengths.

* sock.c (sock_ioctl): Add explicit length limits to ifr_name printfs.

9 years agoDon't risk truncating open flags by using mode_t
Elliott Hughes [Wed, 24 Sep 2014 02:09:50 +0000 (19:09 -0700)]
Don't risk truncating open flags by using mode_t

On Android, 32-bit arm and x86 use __kernel_mode_t (an unsigned short)
as their mode_t.  The open(2) flags are actually an int, so high ones
like O_CLOEXEC get truncated if you coerce them to mode_t.

* defs.h (tprint_open_modes, sprint_open_modes): Change argument type
from mode_t to int.
* file.c (tprint_open_modes, sprint_open_modes): Likewise.

Signed-off-by: Elliott Hughes <enh@google.com>
Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
9 years agoEnhance sysinfo decoding
Dmitry V. Levin [Mon, 29 Sep 2014 23:29:56 +0000 (23:29 +0000)]
Enhance sysinfo decoding

* configure.ac (AC_CHECK_MEMBERS): Check for struct sysinfo.totalhigh,
struct sysinfo.freehigh, and struct sysinfo.mem_unit.
* sysinfo.c (sys_sysinfo): Treat failed umove() call as syserror().
Print totalhigh, freehigh, and mem_unit members when struct sysinfo
supports them.

9 years agoMove sysinfo parser to a separate file
Dmitry V. Levin [Mon, 29 Sep 2014 23:13:05 +0000 (23:13 +0000)]
Move sysinfo parser to a separate file

* sysinfo.c: New file.
* Makefile.am (strace_SOURCES): Add it.
* resource.c (sys_sysinfo): Move to sysinfo.c.

9 years agoFix build with musl libc
Dmitry V. Levin [Mon, 29 Sep 2014 23:09:22 +0000 (23:09 +0000)]
Fix build with musl libc

* resource.c: Include <sys/sysinfo.h> for struct sysinfo definition.

Reported-by: Steven Honeyman <stevenhoneyman@gmail.com>
9 years agotests: cleanup checks for basic programs
Dmitry V. Levin [Tue, 23 Sep 2014 01:51:05 +0000 (01:51 +0000)]
tests: cleanup checks for basic programs

* tests/init.sh: Check for cat and rm.
* tests/getdents.test: Check for awk.
* tests/ptrace_setoptions.test: Check for grep.
* tests/net-fd.test: Do not check for rm.
* tests/net.test: Likewise.
* tests/scm_rights-fd.test: Likewise.
* tests/stat.test: Likewise.
* tests/uio.test: Likewise.

9 years agotests: add a test for -yy option
Dmitry V. Levin [Tue, 23 Sep 2014 00:14:04 +0000 (00:14 +0000)]
tests: add a test for -yy option

* tests/net-yy.test: New test.
* tests/inet-accept-connect-send-recv.c: New file.
* tests/netlink_inet_diag.c: Likewise.
* tests/net-yy-accept.awk: Likewise.
* tests/net-yy-connect.awk: Likewise.
* tests/.gitignore: Add inet-accept-connect-send-recv,
netlink_inet_diag, *.tmp-*, and *.tmp.*.
* tests/Makefile.am (check_PROGRAMS): Add inet-accept-connect-send-recv
and netlink_inet_diag.
(TESTS): Add net-yy.test.
(EXTRA_DIST): Add net-yy-accept.awk and net-yy-connect.awk.

9 years agoMove statfs related parsers to a separate file
Dmitry V. Levin [Mon, 22 Sep 2014 00:17:42 +0000 (00:17 +0000)]
Move statfs related parsers to a separate file

* statfs.c: New file.
* Makefile.am (strace_SOURCES): Add it.
* file.c (sprintfstype, printstatfs, sys_statfs, sys_fstatfs): Move
to statfs.c.
[HAVE_STATFS64] (printstatfs64, printcompat_statfs64, sys_statfs64,
sys_fstatfs64): Likewise.
[ALPHA] (osf_statfs, osf_fstatfs): Likewise.

9 years agofsmagic: sort array by value and use bsearch for faster lookup
Dmitry V. Levin [Sun, 21 Sep 2014 22:42:45 +0000 (22:42 +0000)]
fsmagic: sort array by value and use bsearch for faster lookup

* defs.h (xlat_search): New prototype.
* util.c (xlat_bsearch_compare, xlat_search): New functions.
* file.c (sprintfstype): Use xlat_search for fsmagic lookup.
* xlat/fsmagic.in: Sort by value and mark as not NULL-terminated.
* tests/statfs.c: New file.
* tests/statfs.test: New test.
* tests/Makefile.am (check_PROGRAMS): Add statfs.
(statfs_CFLAGS): Define.
(TESTS): Add statfs.test.
* tests/.gitignore: Add statfs.

9 years agofsmagic: update from <linux/magic.h>
Dmitry V. Levin [Sun, 21 Sep 2014 20:31:16 +0000 (20:31 +0000)]
fsmagic: update from <linux/magic.h>

* xlat/fsmagic.in: Add new constants from <linux/magic.h>.
Reported by Elliott Hughes.

9 years agoAdd -yy option: print ip and port associated with socket descriptors
Dmitry V. Levin [Thu, 21 Aug 2014 03:17:48 +0000 (03:17 +0000)]
Add -yy option: print ip and port associated with socket descriptors

When two ore more -y options are given, print local and remote ip:port
pairs associated with socket descriptors.  This implementation uses
NETLINK_INET_DIAG for sockaddr lookup; it's based on the patch
prepared by Zubin Mithra as a part of his GSoC 2014 strace project.

* Makefile.am (strace_SOURCES): Add socketutils.c
(EXTRA_DIST): Add linux/inet_diag.h and linux/sock_diag.h.
* defs.h (print_sockaddr_by_inode): New prototype.
* linux/inet_diag.h: New file.
* linux/sock_diag.h: Likewise.
* socketutils.c: Likewise.
* strace.1: Document -yy option.
* strace.c (usage): Likewise.
* util.c (printfd): Use print_sockaddr_by_inode.

9 years agosigaction: wrap sa_restorer in #ifdef SA_RESTORER consistently
Vicente Olivert Riera [Thu, 11 Sep 2014 19:05:18 +0000 (20:05 +0100)]
sigaction: wrap sa_restorer in #ifdef SA_RESTORER consistently

Wrap sa_restorer member definitions in #ifdef SA_RESTORER to be
consistent with their use.
If an architecture does not provide sa_restorer members but still
defines SA_RESTORER macro, the latter has to be explicitly undefined.

This change fixes compilation failures like this one:
signal.c: In function 'decode_old_sigaction':
signal.c:631:21: error: 'struct old_sigaction' has no member named 'sa_restorer'
signal.c: In function 'decode_new_sigaction':
signal.c:1224:21: error: 'struct new_sigaction' has no member named 'sa_restorer'

* signal.c (struct old_sigaction, struct old_sigaction32,
struct new_sigaction, struct new_sigaction32):
Wrap sa_restorer member in #ifdef SA_RESTORER.
(decode_old_sigaction, decode_new_sigaction):
Wrap use of sa32.sa_restorer in #ifdef SA_RESTORER.

Signed-off-by: Vicente Olivert Riera <vincent.riera@imgtec.com>
9 years agoFix compilation warnings reported by gcc -Wsign-compare
Dmitry V. Levin [Wed, 10 Sep 2014 13:46:04 +0000 (13:46 +0000)]
Fix compilation warnings reported by gcc -Wsign-compare

* configure.ac (gl_WARN_ADD): Add -Wsign-compare.
* defs.h (struct tcb): Change 'currpers' type to unsigned.
(struct xlat): Change 'val' type to unsigned
(signame): Add 'const' qualifier to its argument.
(xlookup, printxval): Add 'const' qualifier to the 2nd argument and
change its type to unsigned.
(printpathn): Change the 3rd argument type to unsigned.
(ioctl_lookup): Change 1st argument type to unsigned.
* count.c (call_summary_pers, call_summary): Change 'i' type to unsigned.
* file.c (print_xattr_list): Fix comparisons between signed and unsigned
long values.
* ioctl.c (compare): Fix cast.
(ioctl_lookup): Change 1st argument type to to unsigned.
(ioctl_next_match): Change 'code' type to unsigned.
* mem.c (sys_move_pages): Change 'i' type to unsigned.
* mtd.c (mtd_ioctl): Change 'i' and 'j' types to unsigned.
Print 'i' using %u format string.
* process.c (sys_prctl): Change 'i' type to unsigned.
(printargv): Change 'n' type to unsigned.
(sys_ptrace): Change 'addr' type to unsigned.
* scsi.c (print_sg_io_buffer): Add 'const' qualifier to 'len' argument
and change its type to unsigned.  Change 'i' and 'allocated' types
to unsigned.
* signal.c (signame): Add 'const' qualifier to its argument.
Fix comparisons between signed and unsigned values.
(sprintsigmask_n, printsiginfo): Fix comparisons between signed and
unsigned values.
* sock.c (sock_ioctl): Change 'i' and 'nifra' types to unsigned.
* strace.c (expand_tcbtab, alloctcb): Change 'i' type to unsigned.
(detach): Change 'sig' type to unsigned.
(startup_attach): Change 'tcbi' type to unsigned.
(startup_child): Change 'm', 'n', and 'len' types to unsigned.
(init): Use new variable to iterate 'tcbtab'.
(pid2tcb): Change 'i' type to unsigned.
(cleanup): Change 'i' and 'sig' types to unsigned.
* syscall.c (update_personality): Change 'personality' argument type
to unsigned.
(struct qual_options): Change 'bitflag' type to unsigned.
(reallocate_qual): Add 'const' qualifier to its argument and change its
type to unsigned.
(qualify_one): Change 'n' and 'bitflag' arguments types to unsigned.
Add 'const' qualifier to 'n', 'not', and 'pers' arguments.
Change 'p' type to signed int.
(qual_syscall): Change 'bitflag' argument type to unsigned.
Add 'const' qualifier to 'bitflag' and 'not' arguments.
Change 'p' type to signed int.
(qual_signal): Change 'bitflag' argument type to unsigned.
Add 'const' qualifier to 'bitflag' and 'not' arguments.
Change 'i' type to unsigned.
(qual_desc): Change 'bitflag' argument type to unsigned.
Add 'const' qualifier to 'bitflag' and 'not' arguments.
(qualify): Change 'i' type to unsigned.
(get_scno): Change 'currpers' type to unsigned.
Fix a comparison between signed and unsigned values.
* system.c (sys_sysctl): Change 'cnt' and 'max_cnt' types to unsigned.
Fix comparisons between signed and unsigned values.
* util.c (xlookup, printxval): Add 'const' qualifier to 'val' argument
and change its type to unsigned.
(printuid): Fix a comparison between signed and unsigned values.
(printpathn): Change 'n' argument type to unsigned.
(printstr): Change 'size' type to unsigned.
Fix a comparison between signed and unsigned values.
(setbpt): Change 'i' type to unsigned.
* net.c (printsock): Silence a compilation warning.
* reboot.c (sys_reboot): Likewise.

10 years agoMove dirent related parsers to a separate file
Dmitry V. Levin [Thu, 11 Sep 2014 22:40:37 +0000 (22:40 +0000)]
Move dirent related parsers to a separate file

* dirent.c: New file.
* Makefile.am (strace_SOURCES): Add it.
* file.c (print_old_dirent, sys_readdir, sys_getdents, sys_getdents64):
Move to dirent.c.

10 years agogetdents, getdents64: fix potential out-of-bounds read issues
Dmitry V. Levin [Wed, 10 Sep 2014 00:07:32 +0000 (00:07 +0000)]
getdents, getdents64: fix potential out-of-bounds read issues

* file.c (sys_getdents): Check for invalid d_reclen.
Avoid reading from uninitialized memory.
(sys_getdents64): Likewise.
* tests/getdents.awk: New file.
* tests/getdents.test: New test.
* tests/Makefile.am (TESTS): Add it.
(EXTRA_DIST): Add getdents.awk.

10 years agotprint_sock_type: remove unused parameter
Dmitry V. Levin [Wed, 10 Sep 2014 17:48:28 +0000 (17:48 +0000)]
tprint_sock_type: remove unused parameter

* net.c (tprint_sock_type): Remove unused parameter 'tcp'.
(sys_socket, sys_socketpair): Update callers.

10 years agoprintsock: fix decoding of unrecognized AF_PACKET packet types
Dmitry V. Levin [Wed, 10 Sep 2014 00:13:56 +0000 (00:13 +0000)]
printsock: fix decoding of unrecognized AF_PACKET packet types

* net.c (printsock): Fix fallback string for AF_PACKET packet types.

10 years agodecode_select: fix potential use of an uninitialized variable
Dmitry V. Levin [Tue, 9 Sep 2014 22:42:12 +0000 (22:42 +0000)]
decode_select: fix potential use of an uninitialized variable

A pointer to fd_set was used uninitialized when nfds == 0.

* desc.c (decode_select): Initialize fds.

Reported-by: Zubin Mithra <zubin.mithra@gmail.com>
10 years agoUse external libaio.h
Dmitry V. Levin [Mon, 8 Sep 2014 15:20:10 +0000 (15:20 +0000)]
Use external libaio.h

Stop using an outdated partial copy of libaio.h, switch back to external
libaio.h from libaio.
This partially reverts commit 2df03c494eb3c36c4178eba35c374831031d1a58.

* aio.c: Drop a partial copy of libaio.h, include <libaio.h> instead.
(print_common_flags): Check for HAVE_STRUCT_IOCB_U_C_FLAGS.
(sys_io_submit): Check for HAVE_DECL_IO_CMD_PWRITE and
HAVE_DECL_IO_CMD_PWRITEV.
* configure.ac: Check for libaio.h and declaration it provides.

10 years agomaint: post-release administrivia
Dmitry V. Levin [Tue, 19 Aug 2014 11:34:44 +0000 (11:34 +0000)]
maint: post-release administrivia

* NEWS: Add header line for next release.

10 years agoPrepare for 4.9 release v4.9
Dmitry V. Levin [Fri, 15 Aug 2014 13:14:15 +0000 (13:14 +0000)]
Prepare for 4.9 release

* NEWS: Update for 4.9 release.
* debian/changelog: 4.9-1.
* strace.spec: 4.9-1.

10 years agoSync strace.spec and debian/ with packages
Dmitry V. Levin [Fri, 15 Aug 2014 13:14:15 +0000 (13:14 +0000)]
Sync strace.spec and debian/ with packages

* debian/changelog: Sync with 4.8-1.1.
* debian/control: Likewise.
* debian/rules: Likewise.
* strace.spec: Sync with 4.8-5.

10 years agoNEWS: Update for 4.9 release
Dmitry V. Levin [Fri, 15 Aug 2014 00:36:36 +0000 (00:36 +0000)]
NEWS: Update for 4.9 release

10 years agoUpdate syscall tables to the point where they include renameat2
Mike Frysinger [Thu, 14 Aug 2014 08:05:41 +0000 (04:05 -0400)]
Update syscall tables to the point where they include renameat2

* linux/dummy.h: Add printargs aliases for sys_sched_getattr and
sys_sched_setattr.
* linux/aarch64/syscallent1.h: Add kcmp/finit_module/sched_setattr/
sched_getattr/renameat2.
* linux/alpha/syscallent.h: Add kcmp/finit_module.
* linux/arm/syscallent.h: Add sched_setattr/sched_getattr/renameat2.
* linux/hppa/syscallent.h: Add sched_setattr/sched_getattr/utimes/renameat2.
* linux/i386/syscallent.h: Add sched_setattr/sched_getattr/renameat2.
* linux/ia64/syscallent.h: Likewise.
* linux/m68k/syscallent.h: Likewise.
* linux/microblaze/syscallent.h: Likewise.
* linux/mips/syscallent-n32.h: Likewise.
* linux/mips/syscallent-n64.h: Add getdents64/sched_setattr/sched_getattr/
renameat2.
* linux/mips/syscallent-o32.h: Add sched_setattr/sched_getattr/renameat2.
* linux/powerpc/syscallent.h: Fix finit_module/kcmp order.  Add sched_setattr/
sched_getattr/renameat2.
* linux/s390/syscallent.h: Add sched_setattr/sched_getattr/renameat2.
* linux/s390x/syscallent.h: Likewise.
* linux/sparc/syscallent.h: Likewise.
* linux/x32/syscallent.h: Likewise.
* linux/x86_64/syscallent.h: Likewise.
* linux/xtensa/syscallent.h: Add sched_setattr/sched_getattr.

10 years agorenameat2: add decoding support
Mike Frysinger [Thu, 14 Aug 2014 08:05:41 +0000 (04:05 -0400)]
renameat2: add decoding support

* file.c (decode_renameat, sys_renameat2): New functions.
(sys_renameat): Use decode_renameat.
* pathtrace.c (pathtrace_match): Handle sys_renameat2.
* linux/syscall.h (sys_renameat2): New prototype.
* xlat/rename_flags.in: New file.

10 years agoCREDITS: fix generation in out of tree builds
Mike Frysinger [Thu, 14 Aug 2014 08:05:37 +0000 (04:05 -0400)]
CREDITS: fix generation in out of tree builds

The {...} code changes the working dir with `cd`, but the commands outside
of that block expects to be in the original dir.  Change to a subshell so
the path outside of this block remains unchanged.

* Makefile.am ($(srcdir)/CREDITS): Change {...} to (...).

10 years agoia64: add missing syscalls
Mike Frysinger [Thu, 14 Aug 2014 05:02:16 +0000 (01:02 -0400)]
ia64: add missing syscalls

When the preadv/pwritev syscalls were added, the ones before it in the
ia64 list were missed, so all the syscalls there and later were not in
the right location (causing things to be decoded incorrectly).

Add the missing syscalls before preadv which also re-aligns all the
syscalls after that point.  This fixes the uio.test.

* linux/ia64/syscallent.h: Add syscalls 1310 through 1318.

10 years agoia64: fix sigaction decoding
Mike Frysinger [Thu, 14 Aug 2014 04:30:24 +0000 (00:30 -0400)]
ia64: fix sigaction decoding

Looks like ia64 doesn't have sa_restorer either, yet still defines
SA_RESTORER.  Deploy the same trick that HPPA is using to make the
test pass.

* signal.c (SA_RESTORER): Undefine when IA64 is defined.
(struct new_sigaction) [IA64]: Disable sa_restorer.

10 years agotests: skip detach-stopped.test when PTRACE_SEIZE doesn't work
Dmitry V. Levin [Mon, 11 Aug 2014 23:18:56 +0000 (23:18 +0000)]
tests: skip detach-stopped.test when PTRACE_SEIZE doesn't work

detach-stopped.test is known to fail when PTRACE_SEIZE is not available,
so skip the test in that case.

* tests/detach-stopped.test: Check for "strace -d" output and skip the
test when it says that PTRACE_SEIZE doesn't work.

10 years agosh: fix syscall numbering for recv and sendto
Erik Johansson [Mon, 11 Aug 2014 08:26:56 +0000 (10:26 +0200)]
sh: fix syscall numbering for recv and sendto

* linux/sh/syscallent.h: Swap recv and sendto syscall entries.

10 years agotests: fix uio building w/out preadv/pwritev
Mike Frysinger [Mon, 11 Aug 2014 06:52:08 +0000 (02:52 -0400)]
tests: fix uio building w/out preadv/pwritev

The preadv/pwritev symbols weren't added to glibc until the 2.10 release,
so trying to build the uio test leads to link failures.  Add configure
tests and update uio.test to handle this.

* configure.ac (AC_CHECK_FUNCS): Add preadv/pwritev.
* tests/uio.c: Include config.h.
(main): Check for HAVE_PREADV and HAVE_PWRITEV.
* tests/uio.test: Check exit status of uio helper.

10 years agotests: ignore *.tmp files
Mike Frysinger [Mon, 11 Aug 2014 05:40:24 +0000 (01:40 -0400)]
tests: ignore *.tmp files

The tests like to generate random .tmp files, so ignore them.

* tests/.gitignore: Add *.tmp.

10 years agotests: fix shell errors in detach tests
Mike Frysinger [Mon, 11 Aug 2014 05:31:23 +0000 (01:31 -0400)]
tests: fix shell errors in detach tests

The current detach test code does:
set -e
...
cleanup() {
set +e
kill ...
wait ...
}
...
cleanup
exit 0

The problem is that while `set -e` is disabled for the body of the
cleanup function, it isn't necessarily disabled in the caller scope.
So if the return value of the cleanup function (`wait` in this case)
is non-zero, the script ends up failing overall.

Add an explicit return 0 to the cleanup function so that we don't kill
the overall test pipeline.

* tests/detach-running.test (cleanup): Add return 0.
* tests/detach-sleeping.test (cleanup): Likewise.
* tests/detach-stopped.test (cleanup): Likewise.

10 years agoset_ptracer_any: add a little documentation
Mike Frysinger [Mon, 11 Aug 2014 05:31:09 +0000 (01:31 -0400)]
set_ptracer_any: add a little documentation

This way I don't have to keep reading up on these options and wondering
why the code isn't aborting when the call fails.

* tests/set_ptracer_any.c (main): Note prctl failures are ok.

10 years agosignal: fix thinko in sa_restorer
Mike Frysinger [Sun, 10 Aug 2014 02:12:55 +0000 (22:12 -0400)]
signal: fix thinko in sa_restorer

Previous commit here re-added the bugs trying to be fixed due to a
logic thinko.  The patches were tested in isolation and hand merged
later.  Oops.

* signal.c (struct new_sigaction): Change || to &&.

10 years agosigaction test: support arches w/out SA_RESTORER and swapped args
Mike Frysinger [Sat, 9 Aug 2014 13:32:20 +0000 (09:32 -0400)]
sigaction test: support arches w/out SA_RESTORER and swapped args

Running Linux 3.15 (sparc64) and glibc 2.17 (sparc32) triggers a
rt_sigaction call that does not use SA_RESTORER and has an order
where it inserts a restorer and a size.  The current tests don't
support that ordering, so add another regex.

* tests/sigaction.awk: Support no SA_RESTORER and swapped args.

10 years agoalpha/sparc: fix arg count for rt_sigaction
Mike Frysinger [Sat, 9 Aug 2014 13:21:37 +0000 (09:21 -0400)]
alpha/sparc: fix arg count for rt_sigaction

Both these arches have a rt_sigaction syscall that takes 5 args, not 4.

* linux/alpha/syscallent.h (rt_sigaction): Change nargs to 5.
* linux/sparc/syscallent.h (rt_sigaction): Change nargs to 5.

10 years agohppa: fix sigaction decoding
Mike Frysinger [Sat, 9 Aug 2014 13:04:18 +0000 (09:04 -0400)]
hppa: fix sigaction decoding

Since the rt_sigaction syscall on hppa doesn't have a sa_restorer,
do not include it in the kernel struct.

We also have to undefine SA_RESTORER so that code doesn't try to
use it.  The headers will export this, but the syscall doesn't
actually respect it.

* signal.c (SA_RESTORER): Undefine when HPPA is defined.
(struct new_sigaction): Disable sa_restorer on hppa.

10 years agoalpha: fix sigaction decoding
Mike Frysinger [Sat, 9 Aug 2014 12:52:04 +0000 (08:52 -0400)]
alpha: fix sigaction decoding

Since the rt_sigaction syscall on alpha doesn't have a sa_restorer,
do not include it in the kernel struct.

* signal.c (struct new_sigaction): Disable sa_restorer on alpha.

10 years agoPrepare for -yy option support
Dmitry V. Levin [Fri, 8 Aug 2014 23:38:26 +0000 (23:38 +0000)]
Prepare for -yy option support

* defs.h (show_fd_path): Change type to unsigned int.
* strace.c (show_fd_path): Likewise.
(init): Handle repeated -y option.

10 years agoFix preadv/pwritev offset decoding on ILP32 architectures
Dmitry V. Levin [Thu, 7 Aug 2014 11:42:46 +0000 (11:42 +0000)]
Fix preadv/pwritev offset decoding on ILP32 architectures

This fixes regression introduced by the previous commit.

* io.c (print_llu_from_low_high_val) [SIZEOF_LONG != SIZEOF_LONG_LONG]:
Cast argument to unsigned long before casting it to unsigned long long.

10 years agoFix preadv/pwritev offset decoding on bigendian architectures
Dmitry V. Levin [Thu, 7 Aug 2014 00:07:28 +0000 (00:07 +0000)]
Fix preadv/pwritev offset decoding on bigendian architectures

This partially reverts commit 7845a42b39e59e904d01e75e21f7bc7eb6462560.

* util.c (printllval): Remove align argument.
* defs.h (printllval): Update prototype.
(printllval_aligned, printllval_unaligned): Remove.
* file.c (sys_readahead, sys_truncate64, sys_ftruncate64, sys_fadvise64,
sys_fadvise64_64, sys_sync_file_range, sys_sync_file_range2,
sys_fallocate): Replace printllval_aligned call with printllval.
* io.c (sys_pread, sys_pwrite): Likewise.
(print_llu_from_low_high_val): New function.
(sys_preadv, sys_pwritev): Use it instead of printllval_unaligned.

10 years agoDecode file descriptors returned by accept and accept4 syscalls
Dmitry V. Levin [Wed, 6 Aug 2014 16:46:13 +0000 (16:46 +0000)]
Decode file descriptors returned by accept and accept4 syscalls

* net.c (do_accept): Rename to do_sockname.
(sys_accept, sys_accept4): Update callers, return RVAL_FD.
(sys_getsockname, sys_getpeername): Call do_sockname directly.
* tests/net-fd.test: Update.

10 years agox32: update io_{setup,submit} syscalls
Mike Frysinger [Fri, 1 Aug 2014 11:00:24 +0000 (07:00 -0400)]
x32: update io_{setup,submit} syscalls

Starting in 3.16, these two syscalls have gotten their own entry
point for x32.  See linux 7fd44dacdd803c0bbf38bf478d51d280902bb0f1.

* linux/x32/syscallent.h: Change existing io_{setup,submit} to 64bit,
and add new entry points for x32 specifically.

10 years agoxtensa: sort values in struct_user_offsets
Max Filippov [Wed, 18 Jun 2014 02:04:06 +0000 (06:04 +0400)]
xtensa: sort values in struct_user_offsets

Otherwise ptrace syscall argument decoding is wrong:
  ptrace(PTRACE_PEEKUSER, 296, syscall_nr, [0x4048eb]) = 0
  ptrace(PTRACE_PEEKUSER, 296, syscall_nr, [0x3fa6cd30]) = 0
  ptrace(PTRACE_PEEKUSER, 296, syscall_nr, [0x8040676d]) = 0
instead of
  ptrace(PTRACE_PEEKUSER, 296, pc, [0x4048eb]) = 0
  ptrace(PTRACE_PEEKUSER, 296, a1, [0x3fa6cd30]) = 0
  ptrace(PTRACE_PEEKUSER, 296, a0, [0x8040676d]) = 0

* process.c (struct_user_offsets) [XTENSA]: Sort values.

10 years agoDocument -k option as experimental
Dmitry V. Levin [Wed, 18 Jun 2014 15:34:27 +0000 (15:34 +0000)]
Document -k option as experimental

strace -k does not produce a reliable output on all supported
configurations yet, even basic strace-k.test is known to fail
on some of them.

* strace.c (usage): Document -k option as experimental.
* strace.1: Likewise.
* NEWS: Likewise.

10 years agotests: robustify -k test
Dmitry V. Levin [Mon, 16 Jun 2014 21:45:52 +0000 (21:45 +0000)]
tests: robustify -k test

Split stack-fcall.c into several compilation units so that intermediate
function calls would not be optimized out by compiler.

* tests/stack-fcall.c: Move intermediate functions to ...
* tests/stack-fcall-*.c: ... new files.
* tests/Makefile.am (stack_fcall_SOURCES): Add stack-fcall-*.c.

10 years agotests: enhance -k test
Dmitry V. Levin [Fri, 13 Jun 2014 15:07:24 +0000 (15:07 +0000)]
tests: enhance -k test

Add two more function calls to the stack.  Suggested by Masatake YAMATO.

* tests/stack-fcall.c (f1): Rename to f3.
(f1, f2): New functions.
* tests/strace-k.test: Update.

10 years agounwind: ignore memory mappings that have no PROT_EXEC bit set
Dmitry V. Levin [Fri, 13 Jun 2014 14:50:24 +0000 (18:50 +0400)]
unwind: ignore memory mappings that have no PROT_EXEC bit set

* unwind.c (build_mmap_cache): For each memory mapping being scanned,
save its PROT_EXEC bit and skip the mapping if it is not set.

10 years agounwind: cleanup build_mmap_cache
Dmitry V. Levin [Thu, 12 Jun 2014 14:01:45 +0000 (18:01 +0400)]
unwind: cleanup build_mmap_cache

* unwind.c (build_mmap_cache): Move local variables to the code branch
where they are used.  Check return code of sscanf and strdup.  Do not
treat unusual memory mappings as fatal errors.  Do not skip memory
mappings with path names starting with "[".

10 years agounwind: remove unused field from mmap_cache_t
Dmitry V. Levin [Fri, 13 Jun 2014 14:20:08 +0000 (18:20 +0400)]
unwind: remove unused field from mmap_cache_t

* unwind.c (mmap_cache_t): Remove "deleted" field.
(build_mmap_cache): Remove initialization of "deleted" field.

10 years agounwind: refactor stacktrace_walk
Dmitry V. Levin [Thu, 5 Jun 2014 22:28:57 +0000 (22:28 +0000)]
unwind: refactor stacktrace_walk

* unwind.c (stacktrace_walk): Move stack frame printing code
to separate function print_stack_frame.

10 years agounwind: constify binary_filename and symbol_name functions arguments
Dmitry V. Levin [Thu, 5 Jun 2014 22:37:09 +0000 (22:37 +0000)]
unwind: constify binary_filename and symbol_name functions arguments

* unwind.c (call_action_fn, print_call_cb, sprint_call_or_error,
queue_put, queue_put_call): Add const qualifier to binary_filename and
symbol_name arguments.

10 years agounwind: disable stack trace with multiple personalities
Luca Clementi [Tue, 10 Jun 2014 05:05:38 +0000 (22:05 -0700)]
unwind: disable stack trace with multiple personalities

* unwind.c (unwind_cache_invalidate, unwind_print_stacktrace,
unwind_capture_stacktrace): Disable stack tracing of non-default
personality processes.

10 years agounwind: rename function_off_set to function_offset
Dmitry V. Levin [Thu, 5 Jun 2014 21:44:40 +0000 (21:44 +0000)]
unwind: rename function_off_set to function_offset

* unwind.c (call_action_fn, stacktrace_walk, STACK_ENTRY_SYMBOL_FMT,
print_call_cb, sprint_call_or_error, queue_put, queue_put_call):
Rename function_off_set to function_offset.

10 years agounwind: fix a bug in range updating of binary search
Dmitry V. Levin [Thu, 5 Jun 2014 21:40:43 +0000 (21:40 +0000)]
unwind: fix a bug in range updating of binary search

* unwind.c (print_stacktrace): Fix another off-by-one error in binary search.

10 years agounwind: use fopen64 instead of fopen
Dmitry V. Levin [Thu, 5 Jun 2014 15:12:42 +0000 (15:12 +0000)]
unwind: use fopen64 instead of fopen

* unwind.c (fopen_for_input): Define to fopen64 iff
[_LARGEFILE64_SOURCE && HAVE_FOPEN64], otherwise define it to fopen.
(build_mmap_cache): Use fopen_for_input instead of fopen.

10 years agounwind: fix build on 32-bit architectures
Dmitry V. Levin [Thu, 5 Jun 2014 14:37:04 +0000 (14:37 +0000)]
unwind: fix build on 32-bit architectures

Fix compilation warnings in unwind.c on 32-bit architectures.
On some architectures getuid is actually getuid32, so change the test
to use getpid instead of getuid.

* unwind.c (STACK_ENTRY_SYMBOL_FMT): Explicitly cast function_off_set
to unsigned long.
(queue_put_error): Change the 3rd argument's type to unsigned long.
* tests/stack-fcall.c (f1): Use getpid instead of getuid.
* tests/strace-k.test: Likewise.

10 years agotests: robustify -w option test
Dmitry V. Levin [Thu, 5 Jun 2014 14:53:06 +0000 (14:53 +0000)]
tests: robustify -w option test

* tests/count.test: Allow nanosleep to spend a bit less time than 1 second.

10 years agoFix delete_module decoding
Dmitry V. Levin [Wed, 4 Jun 2014 15:51:55 +0000 (15:51 +0000)]
Fix delete_module decoding

* xlat/delete_module_flags.in: New file.
* file.c (sys_delete_module): Move ...
* bjm.c (sys_delete_module): ... to here.
Decode 1st argument using printstr instead of printpath.
* NEWS: Mention it.

10 years agoDecode paths associated with file descriptors returned by syscalls
Zubin Mithra [Wed, 4 Jun 2014 03:00:41 +0000 (08:30 +0530)]
Decode paths associated with file descriptors returned by syscalls

* defs.h (RVAL_FD): New macro.
(RVAL_MASK, RVAL_STR, RVAL_NONE): Update.
* desc.c (sys_dup, sys_delete_module): New functions.
(do_dup2, decode_open, sys_creat): Change return value to RVAL_FD.
* linux/dummy.h (sys_delete_module, sys_dup): Remove.
* linux/syscall.h (sys_delete_module, sys_dup): New prototypes.
* syscall.c (trace_syscall_exiting): Handle RVAL_FD.

Signed-off-by: Zubin Mithra <zubin.mithra@gmail.com>
10 years agoNEWS: Prepare for 4.9 release
Dmitry V. Levin [Tue, 3 Jun 2014 13:31:37 +0000 (13:31 +0000)]
NEWS: Prepare for 4.9 release

10 years agoWarn about flags that have no effect with -c
Dmitry V. Levin [Tue, 3 Jun 2014 13:20:05 +0000 (13:20 +0000)]
Warn about flags that have no effect with -c

* strace.c (init): Issue a warning if -i, -k, -r, -t, -T, or -y is used
along with -c.
This fixes Debian bug #443895.

10 years agodebian: enable security hardening features
Dmitry V. Levin [Tue, 3 Jun 2014 12:56:42 +0000 (12:56 +0000)]
debian: enable security hardening features

* debian/rules: Follow the advice in https://wiki.debian.org/Hardening
and enable maximum hardening as for programs that handle untrusted data.
Patch by Markus <waldeck@gmx.de>.

10 years agodebian: update control file
Dmitry V. Levin [Tue, 3 Jun 2014 12:16:53 +0000 (12:16 +0000)]
debian: update control file

* debian/control (strace64): Fix a typo in package description.
Patch by Pascal De Vuyst <pascal.devuyst@gmail.com>.
(strace, strace-udeb): Add x32 to architecture list.
Patch by Guillaume Morin <guillaume@morinfr.org>.
(strace, strace-udeb): Add or1k to architecture list.
Patch by Christian Svensson <debian@cmd.nu>.
(strace, strace-udeb): Add arm64 to architecture list,
and remove defunct arm.
Patch by Wookey <wookey@debian.org>.

This fixes Debian bugs: #697625, #727018, #742235, #749956.

10 years agomanpage: minor corrections
Dmitry V. Levin [Tue, 3 Jun 2014 12:03:41 +0000 (12:03 +0000)]
manpage: minor corrections

$ groff -ww -mandoc -z strace.1
strace.1:65: warning: macro `IX' not defined

* strace.1: define IX macro as empty for groff.
Change remaining '-' as minus to '\-'.
Have two word spaces after a full stop as an end of sentence.
Use extra space ('\,' or '\/') between roman and italic characters.
Based on patch by Bjarni Ingi Gislason <bjarniig@rhi.hi.is>.
This fixes Debian bug #725987.

10 years agounwind: tests: add a test for -k option
Masatake YAMATO [Wed, 14 May 2014 04:16:29 +0000 (13:16 +0900)]
unwind: tests: add a test for -k option

* tests/stack-fcall.c: New test target.
* tests/strace-k.test: New test driver.
* tests/Makefile.am (check_PROGRAMS): Add stack-fcall.
(TESTS): Add strace-k.test.
* tests/.gitignore: Add stack-fcall.

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
10 years agounwind: move stacktrace capturing and mmap cache invalidating to trace_syscall_entering
Masatake YAMATO [Wed, 16 Apr 2014 06:33:35 +0000 (15:33 +0900)]
unwind: move stacktrace capturing and mmap cache invalidating to trace_syscall_entering

Instead of handling stacktrace capturing and mmap cache invalidating in
sys_* functions, handle them uniformly in trace_syscall_entering using
new flags introduced by previous two commits.

The patch is simpler than its older version(v3).  The value of
hide_log_until_execve is just ignored.  I found the value is nothing
to do with this patch.  unwind_cache_invalidate is mentioned only
once in trace_syscall_exiting.
Both are suggested by Dmitry Levin.

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
10 years agounwind: add SE and SI flags to syscall entries for all architectures
Dmitry V. Levin [Mon, 12 May 2014 14:37:50 +0000 (14:37 +0000)]
unwind: add SE and SI flags to syscall entries for all architectures

Add SE flag to execve, exit, and exit_group syscall entries.
Add SI flag to brk, execve, mmap, mprotect, mremap, munmap,
remap_file_pages, shmat, and shmdt syscall entries.

10 years agounwind: introduce markers specifying the needs of special care in unwinding
Masatake YAMATO [Wed, 16 Apr 2014 06:33:11 +0000 (15:33 +0900)]
unwind: introduce markers specifying the needs of special care in unwinding

Some system calls require capturing the stack trace before they are
processed in kernel.  Typical one is execve.  Some system calls require
invalidating mmap cache after they are processed in kernel.

In current implementation these requirements are handled directly by
appropriate syscall handlers.  However, it is difficult to keep the
source code maintainable using this approach to cover all system calls
which have such requirements.

A more generic way to implement this is to flag all syscalls that
require special processing, and handle these flags right in
trace_syscall_entering instead of changing syscall handlers.

This patch just defines new flags: STACKTRACE_INVALIDATE_CACHE and
STACKTRACE_CAPTURE_ON_ENTER.

The names of macros are suggested by Dmitry Levin.

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
10 years agounwind: enable dwarf cache of libunwind
Masatake YAMATO [Wed, 16 Apr 2014 06:33:10 +0000 (15:33 +0900)]
unwind: enable dwarf cache of libunwind

Here is the benchmark of the dwarf cache.

Target program:

    #include <sched.h>
    int main(void)
    {
      unsigned int max = 0x6fff, i;
      for (i = 0; i < max; i++)
sched_yield();
      return 0;
    }

Command line:

./strace -o /dev/null -k a.out

With the dwarf cache:

    real 0m12.081s
    user 0m3.858s
    sys  0m8.194s

Without the dwarf cache:

    real 0m22.326s
    user 0m5.218s
    sys 0m16.952s

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
10 years agounwind: report expected backtracing error
Masatake YAMATO [Wed, 16 Apr 2014 06:33:09 +0000 (15:33 +0900)]
unwind: report expected backtracing error

When a file mmap'ed to the target process is unlink'ed, backtracing the
stack would fail.  Current implementation reports it as
"backtracing_error".  To avoid confusion, the message is changed to
"expected_backtracing_error".

Here is the reproducer:

  $ cat ./p-deleted.c
  #include <unistd.h>

  int main(int argc, char **argv) {
    return unlink(argv[0]) < 0;
  }

  $ strace -e unlink -k ./p-deleted
  unlink("./p-deleted")                   = 0
   > /usr/lib64/libc-2.18.so(unlink+0x7) [0xe7f17]
   > /home/yamato/var/strace/t_unwind/p-deleted (deleted)(+0x0) [0x575]
   > /usr/lib64/libc-2.18.so(__libc_start_main+0xf5) [0x21d65]
   > backtracing_error [0x7ffff1365590]
  +++ exited with 0 +++

p-deleted is deleted therefore backtracing_error is reported.  This
patch records the deleted marker when making mmap cache and refers the
recorded information in the case "backtracing_error" to switch the
message.

Here is the output of this patch:

  $ strace -e unlink -k ./p-deleted
  unlink("./p-deleted")                   = 0
   > /usr/lib64/libc-2.18.so(unlink+0x7) [0xe7f17]
   > /home/yamato/var/strace/t_unwind/p-deleted (deleted)(+0x0) [0x575]
   > /usr/lib64/libc-2.18.so(__libc_start_main+0xf5) [0x21d65]
   > expected_backtracing_error [0x7ffff1365590]
  +++ exited with 0 +++

This solution is not perfect: if a file is unlink'ed after making the
mmap cache and before unwinding, strace cannot have a chance to record
the deleted marker.

In this version of patch, hardcoded magic number used in comparing "(delete)"
string is replaced with strlen as suggested by Dmitry Levin.

In old version of patch, the deleted entry was thrown away from mmap
cache to avoid to report "backtracing_error".  In this patch I keep it,
and just switch the error message.
Inspired by the review comment from Dmitry Levin.

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
10 years agounwind: call unwind_tcb_fin before printing detached message
Masatake YAMATO [Wed, 16 Apr 2014 06:33:08 +0000 (15:33 +0900)]
unwind: call unwind_tcb_fin before printing detached message

captured stacktrace is printed in unwind_tcb_fin if tcp->queue is not
empty.  This should happen before printing detached message, so
unwind_tcb_fin is moved to the top of droptcb.

This is implicitly suggested by Dmitry Levin in patch review process.

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
10 years agounwind: implement automatic mmap cache invalidation
Masatake YAMATO [Wed, 16 Apr 2014 06:33:07 +0000 (15:33 +0900)]
unwind: implement automatic mmap cache invalidation

A mmap cache belonging to a tcb was updated when a system call which
changed the memory mapping was called.  This implementation was assumed
the mapping was changed only by the tcb.  However, this assumption is
incorrect if the target application is multi-threaded; more than two
tcbs can shared the same memory mapping and a tcb can modify it without
being noticed by the others.

This change introduces a global integer variable mmap_cache_generation,
and mmap_cache_generation field to struct tcb.  The variable
is incremented each time a process enters a syscall that can modify its
memory mapping.  Each tcb records the value of this variable at the
moment if  building its mmap cache.  Every mmap cache associated with
the given tcb can be validated by comparing its mmap_cache_generation
field with the variable mmap_cache_generation.

This implementation is inefficient.  If strace attaches two processes
which don't share the memory mapping, rebuilding mmap cache of a tcb
triggered by another tcb's mmap system call is not necessary.

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
10 years agounwind: introduce queue_t for capturing stacktrace
Masatake YAMATO [Wed, 16 Apr 2014 06:33:06 +0000 (15:33 +0900)]
unwind: introduce queue_t for capturing stacktrace

This is the second step for splitting capturing from printing.

New `queue' field is added to tcb.  Captured stacktrace is stored here.
The field is initialized/finalized at unwind_tcb_init/unwind_tcb_fin.

New API function unwind_capture_stacktrace is added.  This function
captures the currest stack using stracktrace_walker and records it in
tcb.  It's printing is delayed to the next call of
unwind_print_stacktrace.

unwind_print_stacktrace is extended.  Now it checks queue field of
the given tcb at the start of function.  If the function finds a
captured stack trace, the latter is printed using stracktrace_walker.

Currently unwind_capture_stacktrace invocations are added directly to
handlers of mmap, munmap, mprotect, and execve.

Here is the difference of output with/without patch:

(without patch)
  execve("./test-fork", ["./test-fork"], [/* 56 vars */]) = 0
   > /usr/lib64/ld-2.18.so(check_one_fd.part.0+0x82) [0x11f0]

(with patch)
  execve("./test-fork", ["./test-fork"], [/* 54 vars */]) = 0
   > /usr/lib64/libc-2.18.so(execve+0x7) [0xbcd27]
   > /home/yamato/var/strace/strace(exec_or_die+0x10c) [0x26ac]
   > /home/yamato/var/strace/strace(startup_child+0x346) [0x134f6]
   > /home/yamato/var/strace/strace(init+0x89f) [0x13dff]
   > /home/yamato/var/strace/strace(main+0xa) [0x26ca]
   > /usr/lib64/libc-2.18.so(__libc_start_main+0xf5) [0x21d65]
   > /home/yamato/var/strace/strace(_start+0x29) [0x2799]

In older version output lines of captured elements were built when
printing.  In this version they are built when capturing the stack.
As result, unneeded dynamic memory allocations are avoided.
Suggested by Luca Clementi.

In older version the combination of snprintf and realloc were used.
In this version they are replaced with asprintf.
Suggested by Dmitry Levin.

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
10 years agounwind: introduce own debug macro
Masatake YAMATO [Wed, 16 Apr 2014 06:33:05 +0000 (15:33 +0900)]
unwind: introduce own debug macro

* unwind.c (DPRINTF): New macro, to be utilized in debugging cache
management code.

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
10 years agounwind: introduce stacktrace_walker
Masatake YAMATO [Wed, 16 Apr 2014 06:33:04 +0000 (15:33 +0900)]
unwind: introduce stacktrace_walker

In current implementation, the stack trace is captured and printed at
the same time, in trace_syscall_exiting.  This approach cannot
provide user expected information when a system call changes the
memory mapping.  In such cases, the stack trace should be captured on
entering syscall and printed on exiting.

As the initial step for splitting capturing from printing, this change
introduces stacktrace_walker utility function.  It can be used both for
capturing in trace_syscall_entering and printing in
trace_syscall_exiting.

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
10 years agounwind: give all exported functions "unwind_" prefix
Masatake YAMATO [Wed, 16 Apr 2014 06:33:02 +0000 (15:33 +0900)]
unwind: give all exported functions "unwind_" prefix

* unwind.c (init_unwind_addr_space): Rename to unwind_init.
(init_libunwind_ui): Rename to unwind_tcb_init.
(free_libunwind_ui): Rename to unwind_tcb_fin.
(delete_mmap_cache): Rename to unwind_cache_invalidate.
(print_stacktrace): Rename to unwind_print_stacktrace.
* defs.h: Update prototypes.
* mem.c: All callers updated.
* process.c: Likewise.
* strace.c: Likewise.
* syscall.c: Likewise.

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
10 years agounwind: delete mmap cache in free_libunwind_ui
Masatake YAMATO [Wed, 16 Apr 2014 06:33:01 +0000 (15:33 +0900)]
unwind: delete mmap cache in free_libunwind_ui

free_libunwind_ui is expected to release all unwind related resources
attached to tcp.

* strace.c (droptcb): Move delete_mmap_cache call ...
* unwind.c (free_libunwind_ui): ... to here.

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
10 years agounwind: make alloc_mmap_cache function local
Masatake YAMATO [Wed, 16 Apr 2014 06:33:00 +0000 (15:33 +0900)]
unwind: make alloc_mmap_cache function local

* defs.h (alloc_mmap_cache): Remove.
* unwind.c (alloc_mmap_cache): Add static qualifier.

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
10 years agounwind: fix a bug in range updating of binary search
Masatake YAMATO [Wed, 16 Apr 2014 06:32:59 +0000 (15:32 +0900)]
unwind: fix a bug in range updating of binary search

* unwind.c (print_stacktrace): Fix off-by-one error in binary search.

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
Signed-off-by: Luca Clementi <luca.clementi@gmail.com>
10 years agoAdd -k option to print stack trace after each syscall
Luca Clementi [Tue, 23 Jul 2013 07:11:35 +0000 (00:11 -0700)]
Add -k option to print stack trace after each syscall

Print the stack trace of the traced process after each system call when
-k option is specified.  It is implemented using libunwind to unwind the
stack and to obtain the function name pointed by the IP.

Based on the code that was originally taken from strace-plus
of Philip J. Guo.

* configure.ac: Add --with-libunwind option.  Check libunwind support.
* Makefile.am: Add libunwind support.
* defs.h (struct tcb) [USE_LIBUNWIND]: Append libunwind specific fields.
[USE_LIBUNWIND] (stack_trace_enabled, alloc_mmap_cache,
delete_mmap_cache, print_stacktrace): New prototypes.
* mem.c (print_mmap, sys_munmap, sys_mprotect): Add libunwind support.
* process.c (sys_execve): Likewise.
* strace.c (usage, alloctcb, droptcb, init): Likewise.
* syscall.c (trace_syscall_exiting): Likewise.
* unwind.c: New file.
* strace.1: Document -k option.

10 years agosysctl: update CTL_*, KERN_*, NET_*, and VM_* constants
Dmitry V. Levin [Sat, 26 Apr 2014 13:54:12 +0000 (13:54 +0000)]
sysctl: update CTL_*, KERN_*, NET_*, and VM_* constants

* configure.ac (AC_CHECK_DECLS): Add CTL_*, KERN_*, NET_*, and
VM_* constants.
* system.c (CTL_PROC, CTL_CPU): Remove definitions.
* xlat/sysctl_*.in: Update.

10 years agoCheck for constants used by waitid function
Dmitry V. Levin [Sat, 26 Apr 2014 15:22:08 +0000 (15:22 +0000)]
Check for constants used by waitid function

* configure.ac (AC_CHECK_DECLS): Add P_* constants.

10 years agoCheck for LO_FLAGS_READ_ONLY constant
Dmitry V. Levin [Sat, 26 Apr 2014 14:12:33 +0000 (14:12 +0000)]
Check for LO_FLAGS_READ_ONLY constant

* configure.ac (AC_CHECK_DECLS): Add LO_FLAGS_READ_ONLY.

10 years agoCompress blank lines
Dmitry V. Levin [Sat, 26 Apr 2014 18:10:19 +0000 (18:10 +0000)]
Compress blank lines

Suppress empty lines left after automated xlat conversion.

10 years agoxlat: cleanup the aftermath of automatic conversion
Dmitry V. Levin [Sat, 26 Apr 2014 15:35:02 +0000 (15:35 +0000)]
xlat: cleanup the aftermath of automatic conversion

10 years agoGenerate xlat/*.in files
Dmitry V. Levin [Fri, 25 Apr 2014 23:30:54 +0000 (23:30 +0000)]
Generate xlat/*.in files

Automatically convert xlat structures from *.c files to xlat/*.in files
using "./generate_xlat_in.sh *.c" command.

10 years agoRename several xlat structures to avoid collisions
Dmitry V. Levin [Fri, 25 Apr 2014 23:39:20 +0000 (23:39 +0000)]
Rename several xlat structures to avoid collisions

* bjm.c (which): Rename to qm_which.
* ipc.c (msg_flags): Rename to ipc_msg_flags.
* time.c (which): Rename to itimer_which.

10 years agoEnhance xlat generator
Dmitry V. Levin [Fri, 25 Apr 2014 23:04:13 +0000 (23:04 +0000)]
Enhance xlat generator

* xlat/gen.sh: Define all xlat structs not declared in defs.h as static.
Some symbolic constants are not macros, extend #ifdef check to cover
symbolic constants checked by AC_CHECK_DECLS.
Handle complex symbolic constants in SYMBOL|... form.
Handle symbolic constants in 1<<SYMBOL form.
Handle numeric constants.
Implement #unconditional directive that turns off preprocessor checks.
Implement #unterminated directive that turns off adding XLAT_END.

10 years agoUse bootstrap script consistently
Dmitry V. Levin [Fri, 25 Apr 2014 22:52:06 +0000 (22:52 +0000)]
Use bootstrap script consistently

Now that ./xlat/gen.sh has to be run before autoreconf,
replace all autoreconf calls with ./bootstrap call.

* bootstrap: Forward arguments to autoreconf.
* build_static_example.sh: Replace autoreconf call with bootstrap call.
* make-dist: Likewise.
* qemu_multiarch_testing/README: Likewise.

10 years agoImplement xlat generator
Mike Frysinger [Sun, 16 Feb 2014 06:59:20 +0000 (01:59 -0500)]
Implement xlat generator

* bootstrap: New file.
* xlat/gen.sh: Likewise.
* Makefile.am: Include xlat/Makemodule.am
(EXTRA_DIST): Add $(XLAT_INPUT_FILES), $(XLAT_HEADER_FILES), and
xlat/gen.sh.

10 years agotests: fix SCM_RIGHTS test for big-endian systems
Dmitry V. Levin [Fri, 30 May 2014 15:18:00 +0000 (15:18 +0000)]
tests: fix SCM_RIGHTS test for big-endian systems

* tests/scm_rights.c (main): Send zero integer to avoid issues with
endianness.
* tests/scm_rights-fd.test: Update grep patterns.

10 years agoDecode file descriptors passed via SCM_RIGHTS control messages
Dmitry V. Levin [Thu, 29 May 2014 21:35:34 +0000 (21:35 +0000)]
Decode file descriptors passed via SCM_RIGHTS control messages

* net.c (printcmsghdr): Print descriptors from SCM_RIGHTS control
messages using printfd.
* tests/scm_rights.c: New file.
* tests/scm_rights-fd.test: New test.
* tests/Makefile.am (check_PROGRAMS): Add scm_rights.
(TESTS): Add scm_rights-fd.test.
* tests/.gitignore: Add scm_rights and uio.

10 years agotests: add a test for -c and -w options
Dmitry V. Levin [Thu, 29 May 2014 21:14:14 +0000 (21:14 +0000)]
tests: add a test for -c and -w options

* tests/count.test: New test.
* tests/Makefile.am (TESTS): Add it.