Commit Graph

1822 Commits

Author SHA1 Message Date
3df080af31 net.c: recognize MSG_WAITFORONE
* net.c (msg_flags): Add MSG_WAITFORONE.
2012-03-13 01:26:26 +00:00
Denys Vlasenko
328bf250bd Treat -ff without -o FILE as single -f
* strace.c (init): Treat -ff without -o FILE as single -f.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2012-03-12 23:34:13 +01:00
Denys Vlasenko
558e5127fb Style fix. No code changes
* strace.c (process_opt_p_list): Style fix.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2012-03-12 23:32:16 +01:00
Denys Vlasenko
ecc8b97c9b Reduce stack usage by ~0.5k
main() uses ~0.5k of stack for local variables and such. When we enter
main tracing loop, most of these variables are no longer used.
But they still take up stack for the entire life of strace.
We can avoid this wastage if we move init code into a separate function.
(Need to be careful and not allow automatic inlining).

* strace.c (init): New function. Most of pre-existing code of
main is now living here.
(main): Call init() to do initialization.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2012-03-12 23:05:25 +01:00
Denys Vlasenko
2e856a1c92 Preparatory cosmetic changes for the next commit
* strace.c (tprintf): Move function up in the source file. No code changes.
(tprints): Likewise.
(printleader): Likewise.
(tabto): Likewise.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2012-03-12 23:02:26 +01:00
7af9f35001 Implement sendmmsg syscall decoder
* linux/dummy.h (sys_sendmmsg): Remove.
* linux/syscall.h (sys_sendmmsg): New prototype.
* net.c (printmmsghdr): Add index argument specifying the element in
mmsghdr array to print.
(decode_mmsg): New function, prints the whole mmsghdr array, its length
and message flags.
(sys_sendmmsg): New function.
(sys_recvmmsg): Use decode_mmsg to fix mmsghdr array decoding.
2012-03-11 23:59:29 +00:00
1ff463d154 Implement sched_rr_get_interval syscall decoder
* linux/dummy.h (sys_sched_rr_get_interval): Remove.
* linux/syscall.h (sys_sched_rr_get_interval): New prototype.
* process.c (sys_sched_rr_get_interval): New function.
2012-03-11 23:00:11 +00:00
64d0e71f8b Implement migrate_pages syscall decoder
* linux/dummy.h (sys_migrate_pages): Remove.
* linux/syscall.h (sys_migrate_pages): New prototype.
* mem.c (sys_migrate_pages): New function.
2012-03-11 22:44:14 +00:00
1b0bae2969 Implement get_robust_list syscall decoder
* linux/dummy.h (sys_get_robust_list): Remove.
* linux/syscall.h (sys_get_robust_list): New prototype.
* process.c (sys_get_robust_list): New function.
2012-03-11 22:32:26 +00:00
1e8ed076ce Define sys_set_robust_list as an alias to sys_munmap
* linux/dummy.h (sys_set_robust_list): Redefine to sys_munmap.
2012-03-11 21:57:57 +00:00
73215473ce Implement clock_adjtime syscall decoder
* linux/dummy.h (sys_clock_adjtime): Remove.
* linux/syscall.h (sys_clock_adjtime): New prototype.
* time.c (do_adjtimex): New function, based on sys_adjtimex.
(sys_adjtimex): Use it.
(sys_clock_adjtime): New function.
2012-03-11 21:25:51 +00:00
51dba35d38 Define sys_setns as an alias to sys_inotify_rm_watch
* linux/dummy.h (sys_setns): Redefine to sys_inotify_rm_watch.
2012-03-11 15:45:20 +00:00
6bbe69609b Sort definitions of dummy parsers. No code changes
* linux/dummy.h: Sort definitions of parsers implemented as aliases.
2012-03-11 15:43:04 +00:00
ab1a70c7a1 Correct inotify_rm_watch decoder
* file.c (sys_inotify_rm_watch): Print second argument as int.
2012-03-11 15:33:34 +00:00
531af48779 Alias sys_fsync to sys_close
* file.c (sys_fsync): Remove.
* linux/syscall.h (sys_fsync): Likewise.
* linux/dummy.h (sys_fsync): Alias to sys_close.
* linux/m68k/syscallent.h: Add TD flag to fsync entry.
* linux/microblaze/syscallent.h: Likewise.
* linux/mips/syscallent.h: Likewise.
2012-03-11 15:28:03 +00:00
eb420ef585 Update ioctl entries
* linux/ioctlent.h.in: Regenerate from v3.3 headers.
* linux/i386/ioctlent.h.in: Likewise.
2012-03-10 21:15:58 +00:00
63c5e63f2c strace-log-merge: cleanup
* strace-log-merge: Redirect usage to stderr, make the check
for numeric suffix simpler.
2012-03-10 16:10:06 +00:00
d92029ef88 Add syscall entries for new linux syscalls
* linux/i386/syscallent.h: Update process_vm_writev handler.
* linux/powerpc/syscallent.h: Likewise.
* linux/x86_64/syscallent.h: Likewise.
* linux/alpha/syscallent.h: Add entries for accept4 and sendmmsg.
* linux/arm/syscallent.h: Add entries for process_vm_readv and
process_vm_writev.
* linux/m68k/syscallent.h: Likewise.
* linux/mips/syscallent.h: Likewise.
* linux/s390/syscallent.h: Likewise.
* linux/s390x/syscallent.h: Likewise.
* linux/sh/syscallent.h: Likewise.
* linux/sh64/syscallent.h: Likewise.
* linux/sparc/syscallent.h: Likewise.
* linux/ia64/syscallent.h: Add entries for process_vm_readv,
process_vm_writev and accept4.
* linux/microblaze/syscallent.h: Add entries for sendmmsg,
process_vm_readv and process_vm_writev.
2012-03-10 15:04:16 +00:00
039521051e Implement process_vm_writev decoder
* process.c (sys_process_vm_writev): New function.
* linux/syscall.h (sys_process_vm_writev): New prototype.
2012-03-10 14:14:49 +00:00
0bfd74436d Output iovec length in vmsplice and process_vm_readv decoders
* io.c (sys_vmsplice): Output iovec length.
* process.c (sys_process_vm_readv): Likewise.
2012-03-10 14:03:25 +00:00
8829365654 swapon: decode swap flags
* file.c: Include <sys/swap.h>.
(swap_flags): New xlat structure.
(sys_swapon): New function.
* linux/dummy.h (sys_swapon): Remove.
* linux/syscall.h (sys_swapon): New declaration.
2012-03-09 21:02:19 +00:00
Denys Vlasenko
37ab4b79de Trivial simplification
* strace.c (detach): Use waitpid instead of wait4.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2012-03-09 15:34:16 +01:00
Denys Vlasenko
f20250266e Don't consider PROG to be our child in "strace -D PROG" case
TCB_STRACE_CHILD is used for the case when "strace PROG" is ^C-ed
or something like that. strace should not just exit - it should
do something with its child (such as signal it too).

In -D case, PROG is not really a child of _strace_, it is a child
of strace's parent. It's ok to handle it exactly as an attached process.

While we are at it, remove nonsensical special-casing of TCB_STRACE_CHILD
in printing of "<unfinished ...>" message.

* strace.c (startup_attach): Don't set TCB_STRACE_CHILD if -D.
(trace): Print "<unfinished ...>" on error regardless of TCB_STRACE_CHILD.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2012-03-09 15:29:45 +01:00
Denys Vlasenko
75fe85c2ee Fix the case where we try to detach unattached processes
Before this change:
$ strace -D -p1
strace: -D and -p are mutually exclusive options
Process 1 detached  <==== WRONG! (and we try to SIGSTOP it!!!)

* defs.h: Change the meaning of TCB_ATTACHED: now it means "this tracee
is attached to us". Add TCB_STRACE_CHILD: "this tracee is our child".
* strace.c (kill_save_errno): Move up. No code changes.
(process_opt_p_list): Don't set TCB_ATTACHED on new tcb.
(startup_attach): Change how we work with TCB_ATTACHED.
Set TCB_STRACE_CHILD on -D.
(startup_child): Use kill_save_errno instead of kill.
Set TCB_ATTACHED and TCB_STRACE_CHILD on attached strace child.
If we are in -D case, don't set TCB_ATTACHED (we aren't attached yet).
(detach): do not do PTRACE_DETACH if TCB_ATTACHED is not set.
(cleanup): Check TCB_STRACE_CHILD instead of TCB_ATTACHED.
(trace): Likewise.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2012-03-09 15:15:24 +01:00
Denys Vlasenko
97c503fa2e Call PTRACE_CONT with addr=0
* strace.c (trace): Call PTRACE_CONT with addr=0.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2012-03-09 15:11:21 +01:00
Denys Vlasenko
796f6e82b4 install strace-log-merge by "make install"
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2012-03-09 14:21:59 +01:00
Denys Vlasenko
da3657d4e7 strace_log_merge: new file. Helper to merge timestamped strace -ff logs
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2012-03-09 13:43:44 +01:00
Denys Vlasenko
fd88338067 Fix PID prefix printing in "strace -oLOG -ff -p1 -p2 -p3" case
In this case we were printing PIDs to LOG.* files
even though it is not necessary.

The fix is in the addition of "&& followfork < 2" condition.

* strace.c: Remove pflag_seen variable, add print_pid_pfx one.
(process_opt_p_list): Do not pflag_seen++.
(main): Use "nprocs != 0" condition instead of "pflag_seen != 0".
Set print_pid_pfx before entering main tracing loop.
(printleader): Use print_pid_pfx to decide whether to print pid prefix.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2012-03-09 13:03:41 +01:00
Denys Vlasenko
e8172b79e3 Allow -p PID to take comma or whitespace-separated list of PIDs
* defs.h: Clarify meaning of TCB_ATTACHED. No code changes.
* strace.c (process_opt_p_list): New function.
(main): Call process_opt_p_list to process -p PIDs argument.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2012-03-09 13:01:04 +01:00
Denys Vlasenko
114aefd618 Pass addr=0 instead of 1 into restarting ptrace calls
While we are at it, fold do_ptrace into its lone caller.
We no longer set tcp->ptrace_errno = ESRCH on ESRC error in upeek.
Other code paths where ptrace fails wern't doing it, and the code which
checks tcp->ptrace_errno even assumes it is never set to ESRCH.
(It was me who added this code sometime ago, so it was my fault
that it was a bit messy)

I ran sigkill_rain test and verified that unfinished syscalls are
still handled correctly.

* util.c (ptrace_restart): Do not pass addr=1 to ptrace(), pass 0 instead.
I have no idea why we were passing 1. Ptrace documentation says
that addr parameter is ignored.
(do_ptrace): Remove this function.
(upeek): Use ptrace() instead of do_ptrace().
* defs.h: Remove do_ptrace() declaration.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2012-03-08 12:13:44 +01:00
Denys Vlasenko
4c65c44478 Trivial tweaks to error messages
* strace.c (test_ptrace_setoptions_followfork): Use kill_save_errno
instead of kill.
(trace): Use perror_msg instead of perror.
* count.c (set_sortby): Use error_msg_and_die instead of fprintf.
* syscall.c (qualify): Likewise.
* util.c (ptrace_restart): Expand error message.
(umoven): Likewise.
(umovestr): Likewise.
(upeek): Use perror_msg instead of sprintf + perror.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2012-03-08 11:54:10 +01:00
Denys Vlasenko
aea4b876c8 Remove stray sys_swapon() declaration
* linux/syscall.h: Remove stray sys_swapon() declaration.
* linux/mips/syscallent.h: Include dummy.h with correct relative path.
* linux/dummy.h: Tweak one place where spaces are used instead of tabs.
* linux/dummy_check.sh: New script. It helps in finding stray syscall
handler declarations.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2012-02-28 16:39:44 +01:00
Denys Vlasenko
3b60542041 Correct syscall entries for t[g]kill
* linux/hppa/syscallent.h: Make tgkill use sys_tgkill, not printargs.
* linux/sh/syscallent.h: Change tkill type TD -> TS.
* linux/sh64/syscallent.h: Likewise.
* linux/mips/syscallent.h: Change tkill type 0 -> TS.
* linux/x86_64/syscallent.h: Likewise.
* linux/avr32/syscallent.h: Likewise.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2012-02-27 14:58:06 +01:00
Denys Vlasenko
1945ccc3fb Assorted trivial optimizations
text	   data	    bss	    dec	    hex	filename
 236448	    672	  19044	 256164	  3e8a4	strace.before
 236360	    672	  19044	 256076	  3e84c	strace

* file.c (sprintmode): Use smaller static buffer, eliminate strlen call.
(sprinttime): Use smaller static buffer.
(printstat_sparc64): Coalesce two printing calls into one.
(printstat_powerpc32): Likewise.
(printcompat_statfs6): Likewise.
(sys_utime): Do not fetch personality_wordsize[current_personality]
repeatedly - cache it in local variable instead.
* process.c (printargv): Likewise.
* resource.c (sprintrlim): Return const char*, not char*. This allows
to eliminate sprintf(buf, "RLIM_INFINITY"). Use smaller static buffer.
(sprintrlim64): Likewise.
* strace.c (strerror): Use smaller static buffer.
(strsignal): Likewise.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2012-02-27 14:37:48 +01:00
Denys Vlasenko
72879c6a35 Alias a few more syscall printing functions
text	   data	    bss	    dec	    hex	filename
 237384	    672	  19044	 257100	  3ec4c	strace.before
 236448	    672	  19044	 256164	  3e8a4	strace

* defs.h: Declare new functions printargs_lu(), printargs_ld()
which simply print syscall all args as unsigned or signed longs.
* desc.c (sys_epoll_create): Call printargs_ld() instead of open-coding it.
* linux/syscall.h: Remove declarations of the following functions:
sys_alarm, sys_getresgid, sys_getsid, sys_nice, sys_setgid, sys_setpgid,
sys_setpgrp, sys_setregid, sys_setresgid.
* process.c (sys_setgid): Delete this function: now aliased to sys_setuid().
(sys_getresgid): Delete this function: now aliased to sys_getresuid().
(sys_setregid): Delete this function: now aliased to sys_setreuid().
(sys_setresgid): Delete this function: now aliased to sys_setresuid().
(sys_setpgrp): Delete this function: now aliased to printargs_lu().
(sys_getsid): Likewise.
(sys_setpgid): Likewise.
(sys_alarm): Likewise.
(sys_getpgrp): Delete this function: was unused - was already shadowed
by a define in linux/dummy.h.
(sys_setsid): Likewise.
(sys_getpgid): Likewise.
* resource.c (sys_nice): Delete this function: now aliased to printargs_ld().
* linux/dummy.h: Define new aliases (see above for the list).
* syscall.c (printargs_lu): New function.
(printargs_ld): New function.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2012-02-27 14:18:02 +01:00
Denys Vlasenko
b237b1b20d Style fixes, no code changes
* desc.c (sys_io_getevents): Indentation fix.
* file.c (sys_xstat): Remove space after function name.
(decode_mknod): Indentation fix.
* net.c (printsockopt): Indentation fix.
* process.c (unalignctl_string): Indentation fix.
(sys_sched_getscheduler): Remove space after ! operator.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2012-02-27 13:56:59 +01:00
e83e157021 Compress blank lines
Suppress repeated empty lines left after automated code removal.
This change was made by filtering every source code file through
"cat -s".
2012-02-25 15:41:21 +00:00
ee245d8ca3 Remove parts of automake machinery which are not needed on Linux
This change is a verbatim part of Dmitry's changes to remove support
for non-Linux architectures.

* Makefile.am: Don't install PORTING file. Install README-linux-ptrace file.
Set OS variable to linux unconditionally.
* configure.ac: Remove code to set opsys variable, and its usage.
Remove checks for headers which are never present on Linux.
* m4/stat.m4: Remove 'ifdef LINUX' check.
* m4/statfs.m4: Likewise.

Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2012-02-25 15:34:10 +01:00
dd762c302d Remove and update documentation
This change is a verbatim part of Dmitry's changes to remove support
for non-Linux architectures.

* PORTING: Deleted.
* INSTALL: Modified.
* README: Modified.
* strace.1: Modified: bugs should be reported to mailing list, not Debian.
* strace.spec: do not install PORTING file.

Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2012-02-25 15:29:21 +01:00
Denys Vlasenko
aa925db236 Remove a few more code parts which are unused on Linux
This change is abapted from Dmitry's changes to remove support for
non-Linux architectures.

* Makefile.am: Remove if LINUX/endif pairs.
* defs.h: Remove stream_ioctl() declaration.
* ioctl.c (ioctl_decode): Remove 'ifdef HAVE_SYS_STREAM_H' block.
* resource.c: Use 'defined(FOO)' instead of 'defined FOO' form.
* util.c: Likewise.
* signal.c: Remove conditional includes which are never used on Linux.
* stream.c: Likewise.
* file.c: Remove excessive empty lines.

Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2012-02-25 15:19:02 +01:00
Denys Vlasenko
1a3cf10c30 Build fixes after non-Linux code removal
* configure.ac: Remove calls to proc-based ptrace checks.
* proc.c: Remove, it's empty now.
* Makefile.am: Remove reference to proc.c.
* net.c: Remove trailing newlines.
* quota.c: Likewise
* resource.c: Likewise
* strace.c: Likewise
* stream.c: Likewise
* time.c: Likewise

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2012-02-25 02:54:34 +01:00
Denys Vlasenko
c36c352329 Fix defined(FOO) style
* file.c: Consistently use defined(FOO) instead of defined (FOO).
* mem.c: Likewise.
* net.c: Likewise.
* signal.c: Likewise.
* sock.c: Likewise.
* linux/mips/syscallent.h: Likewise.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2012-02-25 02:47:15 +01:00
Denys Vlasenko
2d1e90f958 Reindent preprocessor directives in util.c; fix style.
* util.c: Fix indentation of preprocessor directives broken by
automatic removal of non-Linux code. Fix style to use consistent
defined(FOO) instead of defined (FOO).

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2012-02-25 02:46:14 +01:00
Denys Vlasenko
523635f4da Reindent preprocessor directives in syscall.c; fix style.
* syscall.c: Fix indentation of preprocessor directives broken by
automatic removal of non-Linux code. Fix style to use consistent
defined(FOO) instead of defined (FOO).

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2012-02-25 02:44:25 +01:00
Denys Vlasenko
329655a466 Reindent defs.h preprocessor directives
* defs.h: Fix indentation of preprocessor directives broken by
automatic removal of non-Linux code.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2012-02-25 02:42:32 +01:00
Denys Vlasenko
8470374cba Cleanup after non-Linux code removal.
Conditions such as defined(LINUX) are always true now,
defined(FREEBSD) etc are always false.
When if directive has them as subexpressions, it can be simplified.
Another trivial changes here are fixes for directive indentation.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2012-02-25 02:38:52 +01:00
Denys Vlasenko
5afdf12572 Manual removal of non-Linux source, documentation, etc.
Remove non-Linux source directories: freebsd/, svr4/, sunos4/, svr4/.
Remove README-freebsd, README-sunos4, README-svr4, m4/procfs.m4.

linux/sparc/{errnoent1,ioctlent1,signalent1}.h used to point to svr4/ files -
replace their contents with copies of used (and now deleted) files.
Make linux/sparc64/{errnoent1,ioctlent1,signalent1}.h include these files
instead of svr4/* ones.

Makefile.am: remove references to deleted files.
configure.ac: Remove a few tests which make no sense on Linux.
Man page: remove non-Linux quirks information.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2012-02-25 02:30:32 +01:00
Denys Vlasenko
ed720fda5d Automated removal of non-Linux code
This change is generated by running every source through the following command:

unifdef -DLINUX -Dlinux -USUNOS4 -USVR4 -UUNIXWARE -UFREEBSD
-USUNOS4_KERNEL_ARCH_KLUDGE -UHAVE_MP_PROCFS
-UHAVE_POLLABLE_PROCFS -UHAVE_PR_SYSCALL -UUSE_PROCFS file.c

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2012-02-25 02:24:03 +01:00
Denys Vlasenko
d2a660f534 When accessing data blocks, truncate addr to wordsize
* util.c (umoven): Truncate addr to wordsize before use.
2012-02-25 00:43:22 +01:00
9b3eb84a85 strace.1: fix a typo
* strace.1: Fix a typo in example description.
This fixes Debian bug #653309.
2012-02-22 00:29:44 +00:00