]> granicus.if.org Git - strace/log
strace
12 years agoRemove an outdated comment
Denys Vlasenko [Thu, 15 Mar 2012 12:02:31 +0000 (13:02 +0100)]
Remove an outdated comment

* defs.h: Remove an outdated comment.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
12 years agoRemove extra include directives. No code changes.
Denys Vlasenko [Thu, 15 Mar 2012 11:56:25 +0000 (12:56 +0100)]
Remove extra include directives. No code changes.

* defs.h: Include <signal.h> unconditionally.
Other files were doing it unconditionally, so no harm done.
* bjm.c: Remove system includes which are already included by defs.h.
* pathtrace.c: Likewise.
* process.c: Likewise.
* signal.c: Likewise.
* strace.c: Likewise.
* stream.c: Likewise.
* syscall.c: Likewise.
* system.c: Likewise.
* util.c: Likewise.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
12 years agoTidy up order of includes; make bool variables explicit.
Denys Vlasenko [Thu, 15 Mar 2012 11:49:52 +0000 (12:49 +0100)]
Tidy up order of includes; make bool variables explicit.

Bool variables are more compact in data and (on x86) on code too:

   text    data     bss     dec     hex filename
 237950     676   19044  257670   3ee86 strace.before
 237838     676   19012  257526   3edf6 strace

* defs.h: Group library includes at the top of the file.
Rename dtime to Tflag, debug to debug_flag.
Change debug_flag,Tflag,qflag,not_failing_only,show_fd_path,tracing_paths
variable declarations from int to bool.
* strace.c: Change corresponding definitions. Do the same for static
variables iflag,rflag,print_pid_pfx.
Rename dtime to Tflag, debug to debug_flag.
* syscall.c: Rename dtime to Tflag, debug to debug_flag.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
12 years agoFix compiler warnings about breaking strict-aliasing rules
Dmitry V. Levin [Thu, 15 Mar 2012 02:03:36 +0000 (02:03 +0000)]
Fix compiler warnings about breaking strict-aliasing rules

* system.c (sys_capget, sys_capset): Use proxy unions to cast long*
pointers to cap_user_header_t and cap_user_data_t pointers without
breaking strict-aliasing rules.

Reported-by: Mike Frysinger <vapier@gentoo.org>
12 years agoppc64: drop unused pid variable
Mike Frysinger [Thu, 15 Mar 2012 00:16:13 +0000 (20:16 -0400)]
ppc64: drop unused pid variable

* syscall.c (get_scno) [POWERPC64]: Delete unused pid variable.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
12 years agoia64: fix compilation warnings
Dmitry V. Levin [Thu, 15 Mar 2012 01:01:25 +0000 (01:01 +0000)]
ia64: fix compilation warnings

* linux/ia64/syscallent.h: Remove improper defines and undefs.

Reported-by: Mike Frysinger <vapier@gentoo.org>
12 years agoEnsure that SWAP_FLAG_* constants are defined
Dmitry V. Levin [Thu, 15 Mar 2012 00:52:22 +0000 (00:52 +0000)]
Ensure that SWAP_FLAG_* constants are defined

* file.c: Define those of SWAP_FLAG_* constants which are not yet
provided by <sys/swap.h>.

Reported-by: Mike Frysinger <vapier@gentoo.org>
12 years agoEnhance *listxattr syscalls decoding
Dmitry V. Levin [Wed, 14 Mar 2012 16:34:32 +0000 (16:34 +0000)]
Enhance *listxattr syscalls decoding

* file.c (print_xattr_list): New function.
(sys_listxattr, sys_flistxattr): Use it.

12 years agoFix *at syscalls flags decoding
Dmitry V. Levin [Tue, 13 Mar 2012 23:26:01 +0000 (23:26 +0000)]
Fix *at syscalls flags decoding

Several *at decoders were defining own incomplete *atflags xlat
structures.  That was error prone, and fchownat decoder actually
failed to recognize AT_EMPTY_PATH.  Merging these incomplete
structures into the single at_flags xlat structure will fix
flags handling in all these decoders altogether.

* file.c: Define all AT_* constants used by *at decoders.
(at_flags): New xlat structure, with records for all AT_* constants.
(fstatatflags, linkat_flags, unlinkatflags): Remove.
(sys_newfstatat, sys_linkat, sys_unlinkat, sys_fchownat,
sys_utimensat):  Use at_flags.

12 years agoFix linkat flags decoding
Dmitry V. Levin [Tue, 13 Mar 2012 23:16:37 +0000 (23:16 +0000)]
Fix linkat flags decoding

* file.c (linkat_flags): New xlat structure.
(sys_linkat): Decode flags using linkat_flags.

12 years agoImplement sys_rt_tgsigqueueinfo syscall decoder
Dmitry V. Levin [Tue, 13 Mar 2012 15:51:13 +0000 (15:51 +0000)]
Implement sys_rt_tgsigqueueinfo syscall decoder

* linux/dummy.h (sys_rt_tgsigqueueinfo): Remove.
* linux/syscall.h (sys_rt_tgsigqueueinfo): New prototype.
* signal.c (print_sigqueueinfo): New function, based on
sys_rt_sigqueueinfo.
(sys_rt_sigqueueinfo): Use print_sigqueueinfo.
(sys_rt_tgsigqueueinfo): New function.

12 years agoImplement syslog syscall decoder
Dmitry V. Levin [Tue, 13 Mar 2012 15:28:01 +0000 (15:28 +0000)]
Implement syslog syscall decoder

* linux/dummy.h (sys_syslog): Remove.
* linux/syscall.h (sys_syslog): New prototype.
* system.c (syslog_action_type): New xlat structure.
(sys_syslog): New function.

12 years agoLess ugly debug display of ptrace events
Denys Vlasenko [Tue, 13 Mar 2012 11:05:27 +0000 (12:05 +0100)]
Less ugly debug display of ptrace events

* strace.c (trace): Less ugly debug display of ptrace events.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
12 years agoMake manpage mention that -p "`pidof PROG`" works
Denys Vlasenko [Tue, 13 Mar 2012 10:48:22 +0000 (11:48 +0100)]
Make manpage mention that -p "`pidof PROG`" works

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
12 years agoFix logging for "strace -o FILE -ff test/threaded_execve" test case
Denys Vlasenko [Tue, 13 Mar 2012 10:44:31 +0000 (11:44 +0100)]
Fix logging for "strace -o FILE -ff test/threaded_execve" test case

Our logic which was deciding whether to print "<unfinished ...>"
thingy wasn't working properly for -ff case.

* defs.h: Group log generation-related declarations together.
Add a large comment which explains how it works.
Add declaration of line_ended() function.
* strace.c (line_ended): New function which sets up internal data
to indicate that previous line was finished.
(printleader): Change logic to fix log generation in -ff mode.
(newoutf): Make check for -ff mode consistent with other places.
(droptcb): Print "<detached ...>" if last line for this tcp wasn't finished.
(cleanup): Remove code to print "<unfinished ...>", printleader()
or detach() will do it instead.
(trace): Remove code to print "<unfinished ...>".
Add code which finishes threaded execve's incomplete line
with " <pid changed to PID ...>" message. Replace printing_tcp = NULL
followed by fflush() by line_ended() call.
* process.c (sys_exit): Call line_ended() to indicate that we finished priting.
* syscall.c (trace_syscall_exiting): Set printing_tcp to current tcp.
Call line_ended() to indicate that we finished priting.
Remove call to fflush(), it is done by line_ended() now.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
12 years agonet.c: recognize MSG_WAITFORONE
Dmitry V. Levin [Tue, 13 Mar 2012 01:26:26 +0000 (01:26 +0000)]
net.c: recognize MSG_WAITFORONE

* net.c (msg_flags): Add MSG_WAITFORONE.

12 years agoTreat -ff without -o FILE as single -f
Denys Vlasenko [Mon, 12 Mar 2012 22:34:13 +0000 (23:34 +0100)]
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>
12 years agoStyle fix. No code changes
Denys Vlasenko [Mon, 12 Mar 2012 22:32:16 +0000 (23:32 +0100)]
Style fix. No code changes

* strace.c (process_opt_p_list): Style fix.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
12 years agoReduce stack usage by ~0.5k
Denys Vlasenko [Mon, 12 Mar 2012 22:05:25 +0000 (23:05 +0100)]
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>
12 years agoPreparatory cosmetic changes for the next commit
Denys Vlasenko [Mon, 12 Mar 2012 22:02:26 +0000 (23:02 +0100)]
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>
12 years agoImplement sendmmsg syscall decoder
Dmitry V. Levin [Sun, 11 Mar 2012 23:59:29 +0000 (23:59 +0000)]
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.

12 years agoImplement sched_rr_get_interval syscall decoder
Dmitry V. Levin [Sun, 11 Mar 2012 23:00:11 +0000 (23:00 +0000)]
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.

12 years agoImplement migrate_pages syscall decoder
Dmitry V. Levin [Sun, 11 Mar 2012 22:44:14 +0000 (22:44 +0000)]
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.

12 years agoImplement get_robust_list syscall decoder
Dmitry V. Levin [Sun, 11 Mar 2012 22:32:26 +0000 (22:32 +0000)]
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.

12 years agoDefine sys_set_robust_list as an alias to sys_munmap
Dmitry V. Levin [Sun, 11 Mar 2012 21:57:57 +0000 (21:57 +0000)]
Define sys_set_robust_list as an alias to sys_munmap

* linux/dummy.h (sys_set_robust_list): Redefine to sys_munmap.

12 years agoImplement clock_adjtime syscall decoder
Dmitry V. Levin [Sun, 11 Mar 2012 21:25:51 +0000 (21:25 +0000)]
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.

12 years agoDefine sys_setns as an alias to sys_inotify_rm_watch
Dmitry V. Levin [Sun, 11 Mar 2012 15:45:20 +0000 (15:45 +0000)]
Define sys_setns as an alias to sys_inotify_rm_watch

* linux/dummy.h (sys_setns): Redefine to sys_inotify_rm_watch.

12 years agoSort definitions of dummy parsers. No code changes
Dmitry V. Levin [Sun, 11 Mar 2012 15:43:04 +0000 (15:43 +0000)]
Sort definitions of dummy parsers.  No code changes

* linux/dummy.h: Sort definitions of parsers implemented as aliases.

12 years agoCorrect inotify_rm_watch decoder
Dmitry V. Levin [Sun, 11 Mar 2012 15:33:34 +0000 (15:33 +0000)]
Correct inotify_rm_watch decoder

* file.c (sys_inotify_rm_watch): Print second argument as int.

12 years agoAlias sys_fsync to sys_close
Dmitry V. Levin [Sun, 11 Mar 2012 15:28:03 +0000 (15:28 +0000)]
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.

12 years agoUpdate ioctl entries
Dmitry V. Levin [Sat, 10 Mar 2012 21:15:58 +0000 (21:15 +0000)]
Update ioctl entries

* linux/ioctlent.h.in: Regenerate from v3.3 headers.
* linux/i386/ioctlent.h.in: Likewise.

12 years agostrace-log-merge: cleanup
Dmitry V. Levin [Sat, 10 Mar 2012 16:10:06 +0000 (16:10 +0000)]
strace-log-merge: cleanup

* strace-log-merge: Redirect usage to stderr, make the check
for numeric suffix simpler.

12 years agoAdd syscall entries for new linux syscalls
Dmitry V. Levin [Sat, 10 Mar 2012 15:04:16 +0000 (15:04 +0000)]
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.

12 years agoImplement process_vm_writev decoder
Dmitry V. Levin [Sat, 10 Mar 2012 14:14:49 +0000 (14:14 +0000)]
Implement process_vm_writev decoder

* process.c (sys_process_vm_writev): New function.
* linux/syscall.h (sys_process_vm_writev): New prototype.

12 years agoOutput iovec length in vmsplice and process_vm_readv decoders
Dmitry V. Levin [Sat, 10 Mar 2012 14:03:25 +0000 (14:03 +0000)]
Output iovec length in vmsplice and process_vm_readv decoders

* io.c (sys_vmsplice): Output iovec length.
* process.c (sys_process_vm_readv): Likewise.

12 years agoswapon: decode swap flags
Dmitry V. Levin [Fri, 9 Mar 2012 21:02:19 +0000 (21:02 +0000)]
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.

12 years agoTrivial simplification
Denys Vlasenko [Fri, 9 Mar 2012 14:34:16 +0000 (15:34 +0100)]
Trivial simplification

* strace.c (detach): Use waitpid instead of wait4.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
12 years agoDon't consider PROG to be our child in "strace -D PROG" case
Denys Vlasenko [Fri, 9 Mar 2012 14:29:45 +0000 (15:29 +0100)]
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>
12 years agoFix the case where we try to detach unattached processes
Denys Vlasenko [Fri, 9 Mar 2012 14:15:24 +0000 (15:15 +0100)]
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>
12 years agoCall PTRACE_CONT with addr=0
Denys Vlasenko [Fri, 9 Mar 2012 14:11:21 +0000 (15:11 +0100)]
Call PTRACE_CONT with addr=0

* strace.c (trace): Call PTRACE_CONT with addr=0.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
12 years agoinstall strace-log-merge by "make install"
Denys Vlasenko [Fri, 9 Mar 2012 13:21:59 +0000 (14:21 +0100)]
install strace-log-merge by "make install"

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
12 years agostrace_log_merge: new file. Helper to merge timestamped strace -ff logs
Denys Vlasenko [Fri, 9 Mar 2012 12:43:44 +0000 (13:43 +0100)]
strace_log_merge: new file. Helper to merge timestamped strace -ff logs

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
12 years agoFix PID prefix printing in "strace -oLOG -ff -p1 -p2 -p3" case
Denys Vlasenko [Fri, 9 Mar 2012 12:03:41 +0000 (13:03 +0100)]
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>
12 years agoAllow -p PID to take comma or whitespace-separated list of PIDs
Denys Vlasenko [Fri, 9 Mar 2012 12:01:04 +0000 (13:01 +0100)]
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>
12 years agoPass addr=0 instead of 1 into restarting ptrace calls
Denys Vlasenko [Thu, 8 Mar 2012 11:13:44 +0000 (12:13 +0100)]
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>
12 years agoTrivial tweaks to error messages
Denys Vlasenko [Thu, 8 Mar 2012 10:54:10 +0000 (11:54 +0100)]
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>
12 years agoRemove stray sys_swapon() declaration
Denys Vlasenko [Tue, 28 Feb 2012 15:39:44 +0000 (16:39 +0100)]
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>
12 years agoCorrect syscall entries for t[g]kill
Denys Vlasenko [Mon, 27 Feb 2012 13:58:06 +0000 (14:58 +0100)]
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>
12 years agoAssorted trivial optimizations
Denys Vlasenko [Mon, 27 Feb 2012 13:37:48 +0000 (14:37 +0100)]
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>
12 years agoAlias a few more syscall printing functions
Denys Vlasenko [Mon, 27 Feb 2012 13:18:02 +0000 (14:18 +0100)]
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>
12 years agoStyle fixes, no code changes
Denys Vlasenko [Mon, 27 Feb 2012 12:56:59 +0000 (13:56 +0100)]
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>
12 years agoCompress blank lines
Dmitry V. Levin [Sat, 25 Feb 2012 15:41:21 +0000 (15:41 +0000)]
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".

12 years agoRemove parts of automake machinery which are not needed on Linux
Dmitry V. Levin [Sat, 25 Feb 2012 14:34:10 +0000 (15:34 +0100)]
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>
12 years agoRemove and update documentation
Dmitry V. Levin [Sat, 25 Feb 2012 14:29:21 +0000 (15:29 +0100)]
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>
12 years agoRemove a few more code parts which are unused on Linux
Denys Vlasenko [Sat, 25 Feb 2012 14:19:02 +0000 (15:19 +0100)]
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>
12 years agoBuild fixes after non-Linux code removal
Denys Vlasenko [Sat, 25 Feb 2012 01:54:34 +0000 (02:54 +0100)]
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>
12 years agoFix defined(FOO) style
Denys Vlasenko [Sat, 25 Feb 2012 01:47:15 +0000 (02:47 +0100)]
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>
12 years agoReindent preprocessor directives in util.c; fix style.
Denys Vlasenko [Sat, 25 Feb 2012 01:46:14 +0000 (02:46 +0100)]
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>
12 years agoReindent preprocessor directives in syscall.c; fix style.
Denys Vlasenko [Sat, 25 Feb 2012 01:44:25 +0000 (02:44 +0100)]
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>
12 years agoReindent defs.h preprocessor directives
Denys Vlasenko [Sat, 25 Feb 2012 01:42:32 +0000 (02:42 +0100)]
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>
12 years agoCleanup after non-Linux code removal.
Denys Vlasenko [Sat, 25 Feb 2012 01:38:52 +0000 (02:38 +0100)]
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>
12 years agoManual removal of non-Linux source, documentation, etc.
Denys Vlasenko [Sat, 25 Feb 2012 01:30:32 +0000 (02:30 +0100)]
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>
12 years agoAutomated removal of non-Linux code
Denys Vlasenko [Sat, 25 Feb 2012 01:24:03 +0000 (02:24 +0100)]
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>
12 years agoWhen accessing data blocks, truncate addr to wordsize
Denys Vlasenko [Fri, 24 Feb 2012 23:43:22 +0000 (00:43 +0100)]
When accessing data blocks, truncate addr to wordsize

* util.c (umoven): Truncate addr to wordsize before use.

12 years agostrace.1: fix a typo
Dmitry V. Levin [Wed, 22 Feb 2012 00:29:44 +0000 (00:29 +0000)]
strace.1: fix a typo

* strace.1: Fix a typo in example description.
This fixes Debian bug #653309.

12 years agoFix sockaddr_un.sun_path name in decoded output
Dmitry V. Levin [Wed, 22 Feb 2012 00:23:52 +0000 (00:23 +0000)]
Fix sockaddr_un.sun_path name in decoded output

* net.c (printsock): Show sockaddr_un.sun_path as "sun_path".
This fixes Debian bug #554946.

12 years agoAvoid potential core file clobbering on exit
Dmitry V. Levin [Wed, 22 Feb 2012 00:15:27 +0000 (00:15 +0000)]
Avoid potential core file clobbering on exit

* strace.c (main): Set RLIMIT_CORE to zero before terminating itself
with a deadly signal.
This fixes Debian bug #656398.

12 years agoEliminate native_scno and known_scno
Dmitry V. Levin [Mon, 20 Feb 2012 21:44:53 +0000 (21:44 +0000)]
Eliminate native_scno and known_scno

* defs.h (known_scno): Remove.
(sysent): Remove native_scno field.
* process.c [IA64]: Replace known_scno(tcp) with tcp->scno.
(internal_fork) [USE_PROCFS || !LINUX]: Likewise.
* syscall.c: Do not define NR_SYSCALL_BASE.
(known_scno): Remove.
(syscall_fixup_on_sysenter) [USE_PROCFS]: Replace known_scno(tcp)
with tcp->scno.
(trace_syscall_entering) [SVR4 || FREEBSD || SUNOS4]: Likewise.
(syscall_fixup_on_sysexit) [SUNOS4]: Likewise.

12 years agoRemove initialization of native_scno field
Dmitry V. Levin [Mon, 20 Feb 2012 21:17:58 +0000 (21:17 +0000)]
Remove initialization of native_scno field

* linux/i386/syscallent.h: Remove native_scno initialization for clone,
fork and vfork.
* linux/ia64/syscallent.h (sys_fork, sys_vfork): Remove redirections
to printargs.
* linux/syscall.h [IA64]: Do not define SYS_fork and SYS_vfork.
* util.c (printcall) [IA64]: Likewise.
(setbpt): Use sys_func to check for clone, fork and vfork syscalls.

12 years agoDo not use SYS_ipc and SYS_socketcall
Dmitry V. Levin [Mon, 20 Feb 2012 17:02:38 +0000 (17:02 +0000)]
Do not use SYS_ipc and SYS_socketcall

* linux/dummy.h (sys_ipc, sys_socketcall): Remove redirections to
printargs.
* linux/ia64/syscallent.h: Likewise.
* linux/i386/syscallent.h: Remove native_scno initialization for "ipc"
and "socketcall".
* linux/syscall.h (sys_ipc, sys_socketcall): New prototypes.
(SYS_ipc, SYS_socketcall): Remove no longer used constants.
[IA64]: Remove undefining of ipc and socket SYS_* constants.
[SPARC || SPARC64]: Remove unused ipc SYS_* constants.
* ipc.c (sys_ipc): New function.
* sock.c (sys_socketcall): Likewise.
* syscall.c (trace_syscall_entering): Use sys_func to check for ipc and
socket subcalls.

12 years agoRemove initialization of native_scno field for most of syscalls
Dmitry V. Levin [Fri, 10 Feb 2012 22:33:36 +0000 (22:33 +0000)]
Remove initialization of native_scno field for most of syscalls

The native_scno field is not so much used in the code than before.
In many cases sys_func is checked instead, and for most of syscall
entries there is no need to initialize native_scno.

* linux/i386/syscallent.h: Remove native_scno initialization for
_exit, read, write, waitpid, execve, wait4, sysfs, readv, writev,
pread64, pwrite64, exit_group, waitid, send, recv, sendto and
recvfrom syscall entries.
* linux/syscall.h: Do not define no longer used SYS_waitid and
SYS_sub_* constants.
[IA64]: Do not define SYS_waitpid and SYS32_* constants.
* defs.h: Do not define no longer used  __NR_exit_group constant.
* strace.c [USE_PROCFS] (proc_open): Use sys_func to check for execve.

12 years agoutil: check for process_vm_readv in C library
Mike Frysinger [Tue, 14 Feb 2012 13:38:28 +0000 (14:38 +0100)]
util: check for process_vm_readv in C library

glibc-2.15 provides process_vm_readv, so trying to provide it ourselves
with that version fails.

* configure.ac (AC_CHECK_FUNCS): Add process_vm_readv.
* util.c: Handle HAVE_PROCESS_VM_READV.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
12 years agoREADME-linux-ptrace: correct the description of suppressed signals
Denys Vlasenko [Thu, 9 Feb 2012 18:57:52 +0000 (19:57 +0100)]
README-linux-ptrace: correct the description of suppressed signals

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
12 years agostrace -P: fix handling of invalid syscalls
Dmitry V. Levin [Mon, 6 Feb 2012 17:13:59 +0000 (17:13 +0000)]
strace -P: fix handling of invalid syscalls

* pathtrace.c (pathtrace_match): Check the given syscall number using
SCNO_IN_RANGE.

12 years agoSkip the syscall entry if the sys_func field is NULL
H.J. Lu [Fri, 3 Feb 2012 18:19:55 +0000 (10:19 -0800)]
Skip the syscall entry if the sys_func field is NULL

Avoid NULL dereference when there are holes in sysent tables.
It can happen with syscall (number, ...) and number is in those holes.
There are no targets with holey systent tables so far, but at least
one such a target, x32, is already on the horizon.

* defs.h (SCNO_IN_RANGE): Also check the sys_func field.

12 years agoDefine RLIM64_INFINITY only if not defined
H.J. Lu [Fri, 3 Feb 2012 18:17:01 +0000 (10:17 -0800)]
Define RLIM64_INFINITY only if not defined

* resource.c (RLIM64_INFINITY): Define only if it isn't defined.

12 years agoCast to long for %l in printf
H.J. Lu [Fri, 3 Feb 2012 18:16:03 +0000 (10:16 -0800)]
Cast to long for %l in printf

Cast a value to long for %l in printf to avoid compiler warning
on systems where it may be long long.

* count.c (call_summary_pers): Cast to long.
* ipc.c (sys_mq_open, printmqattr): Likewise.
* quota.c (decode_cmd_data): Likewise.
* resource.c (sys_sysinfo): Likewise.
* time.c (tprint_timex): Likewise.

12 years agoCheck HAVE_LONG_LONG_OFF_T when printing offset
H.J. Lu [Fri, 3 Feb 2012 18:12:10 +0000 (10:12 -0800)]
Check HAVE_LONG_LONG_OFF_T when printing offset

When HAVE_LONG_LONG_OFF_T is defined, we need to use %llu to print
offset.

* io.c (sys_sendfile): Check HAVE_LONG_LONG_OFF_T when printing
offset.

12 years agoDefine old stat functions only if needed
H.J. Lu [Fri, 3 Feb 2012 18:10:30 +0000 (10:10 -0800)]
Define old stat functions only if needed

When HAVE_LONG_LONG_OFF_T is defined, those old stat functions aren't
used and strace won't link since they use realprintstat which isn't
defined when HAVE_LONG_LONG_OFF_T is defined.

* file.c (convertoldstat, sys_oldstat, sys_oldfstat, sys_oldlstat):
Define only if HAVE_LONG_LONG_OFF_T isn't defined.

12 years agoPrint NULL for zero address in sys_mmap64
H.J. Lu [Fri, 3 Feb 2012 18:07:42 +0000 (10:07 -0800)]
Print NULL for zero address in sys_mmap64

* mem.c (sys_mmap64): Print NULL for zero address so that it is
consistent with sys_mmap.

12 years agoRemove unused sys_pread64 and sys_pwrite64 parsers on Linux
Dmitry V. Levin [Sat, 4 Feb 2012 15:17:43 +0000 (15:17 +0000)]
Remove unused sys_pread64 and sys_pwrite64 parsers on Linux

* io.c [HAVE_LONG_LONG_OFF_T]: Remove sys_pread64 and sys_pwrite64
aliases.
(sys_pread64, sys_pwrite64): Define these functions only on
[SVR4 && _LFS64_LARGEFILE] platform.
* linux/mips/syscallent.h: Use sys_pread and sys_pwrite to handle
appropriate syscalls.
* linux/syscall.h (sys_pread64, sys_pwrite64): Remove.
* syscall.c (dumpio): Check sys_pread64 and sys_pwrite64 only on
[SVR4 && _LFS64_LARGEFILE] platform.

12 years agoTrivial changes to help text. No code changes.
Denys Vlasenko [Fri, 3 Feb 2012 11:17:57 +0000 (12:17 +0100)]
Trivial changes to help text. No code changes.

* strace.c (usage): Tweak help text: remove unpaired closing brackets,
make -V and -h sit on separate lines (hard to see them otherwise).

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
12 years agoSimple optimizations
Denys Vlasenko [Sun, 29 Jan 2012 21:38:35 +0000 (22:38 +0100)]
Simple optimizations

   text    data     bss     dec     hex filename
 239474     672   20484  260630   3fa16 strace.before
 239234     668   19044  258946   3f382 strace

* file.c (sprint_open_modes): Reduce static buffer size.
Simplify separator printing.
* signal.c (sprintsigmask): Reduce static buffer size.
Simplify separator printing and printing of almost full masks.
Use stpcpy instead of sprintf and strcpy+strlen.
* strace.c (startup_child): Don't strchr() for ':' twice in a row.
* util.c (sprintflags): Exit loop early if possible.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
12 years agoTrivial optimization
Denys Vlasenko [Sun, 29 Jan 2012 20:17:56 +0000 (21:17 +0100)]
Trivial optimization

* strace.c (cleanup): Read 'interrupted' volatile variable only once.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
12 years agoMake interactive-ness directly controllable via command line option
Denys Vlasenko [Sun, 29 Jan 2012 15:53:03 +0000 (16:53 +0100)]
Make interactive-ness directly controllable via command line option

Defaults are often ok, but when they are not, people get confused.
"Why can't I kill strace?" and "Why strace dies on ^C when I want
to _tracee_ to die instead?" are typical complaints.

* strace.c: Replace 'interactive' variable with 'opt_intr' variable.
Define INTR_foo constants for its possible values.
Define 'interactive' as a macro.
(usage): Document -I n option.
(main): Parse -I n option, modify signal handling to accomidate new
-I 1 and -I 4 modes.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
12 years agoSuppress compiler warning
Denys Vlasenko [Sun, 29 Jan 2012 15:46:46 +0000 (16:46 +0100)]
Suppress compiler warning

* strace.c (trace): Frame potentially unused label with ifdef/endif.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
12 years agoOn Ctrl-C induced detach, send SIGINT to child tracee, not SIGTERM.
Denys Vlasenko [Sun, 29 Jan 2012 15:43:51 +0000 (16:43 +0100)]
On Ctrl-C induced detach, send SIGINT to child tracee, not SIGTERM.

* strace.c (interrupt): Remember signal number.
(cleanup): If we exiting due to signal, send that signal to child tracee.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
12 years agoAdd experimental code to use PTRACE_SEIZE, disabled by default
Denys Vlasenko [Sun, 29 Jan 2012 01:01:44 +0000 (02:01 +0100)]
Add experimental code to use PTRACE_SEIZE, disabled by default

All new code is predicated on "ifdef USE_SEIZE". If it is not defined,
behavior is not changed.

If USE_SEIZE is enabled and run-time check shows that PTRACE_SEIZE works, then:
- All attaching is done with PTRACE_SEIZE + PTRACE_INTERRUPT.
  This means that we no longer generate (and possibly race with) SIGSTOP.
- PTRACE_EVENT_STOP will be generated if tracee is group-stopped.
  When we detect it, we issue PTRACE_LISTEN instead of PTRACE_SYSCALL.
  This leaves tracee stopped. This fixes the inability to SIGSTOP or ^Z
  a straced process.

* defs.h: Add commented-out "define USE_SEIZE 1" and define PTRACE_SEIZE
and related constants.
* strace.c: New variable post_attach_sigstop shows whether we age going
to expect SIGSTOP on attach (IOW: are we going to use PTRACE_SEIZE).
(ptrace_attach_or_seize): New function. Uses PTRACE_ATTACH or
PTRACE_SEIZE + PTRACE_INTERRUPT to attach to given pid.
(startup_attach): Use ptrace_attach_or_seize() instead of ptrace(PTRACE_ATTACH).
(startup_child): Conditionally use alternative attach method using PTRACE_SEIZE.
(test_ptrace_setoptions_followfork): More robust parameters to PTRACE_TRACEME.
(test_ptrace_seize): New function to test whether PTRACE_SEIZE works.
(main): Call test_ptrace_seize() while initializing.
(trace): If PTRACE_EVENT_STOP is seen, restart using PTRACE_LISTEN in order
to not let tracee run.
* process.c: Decode PTRACE_SEIZE, PTRACE_INTERRUPT, PTRACE_LISTEN.
* util.c (ptrace_restart): Add "LISTEN" to a possible error message.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
12 years agoprocess_vm_readv gets EINVAL if process is gone (SIGKILLed). Don't complain.
Denys Vlasenko [Sat, 28 Jan 2012 01:49:48 +0000 (02:49 +0100)]
process_vm_readv gets EINVAL if process is gone (SIGKILLed). Don't complain.

* util.c (umoven): Don't complain on EINVAL from process_vm_readv.
(umovestr): Likewise.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
12 years agoRevert last change. Add a comment to prevent further misunderstanding
Denys Vlasenko [Sat, 28 Jan 2012 01:29:36 +0000 (02:29 +0100)]
Revert last change. Add a comment to prevent further misunderstanding

* time.c (sys_nanosleep): Display remaining time only on interrupt.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
12 years agoFix nanosleep decoding: second argument was not shown after success
Denys Vlasenko [Sat, 28 Jan 2012 01:16:06 +0000 (02:16 +0100)]
Fix nanosleep decoding: second argument was not shown after success

* time.c (sys_nanosleep): Fix bug - inverted is_restart_error() check.
* syscall.c (is_restart_error): Remove redundant check.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
12 years agoUse process_vm_readv instead of PTRACE_PEEKDATA to read data blocks
Denys Vlasenko [Sat, 28 Jan 2012 00:46:33 +0000 (01:46 +0100)]
Use process_vm_readv instead of PTRACE_PEEKDATA to read data blocks

Currently, we use PTRACE_PEEKDATA to read things like filenames and
data passed by I/O syscalls.
PTRACE_PEEKDATA gets one word per syscall. This is VERY expensive.
For example, in order to print fstat syscall, we need to perform
more than twenty trips into kernel to fetch one struct stat!

Kernel 3.2 got a new syscall, process_vm_readv(), which can be used to
copy data blocks out of process' address space.

This change uses it in umoven() and umovestr() functions if possible,
with fallback to old method if process_vm_readv() fails.
If it returns ENOSYS, we don't try to use it anymore, eliminating
overhead of trying it on older kernels.

Result of "time strace -oLOG ls -l /usr/lib >/dev/null":
before patch: 0.372s
After patch:  0.262s

* util.c (process_vm_readv): Wrapper to call process_vm_readv syscall.
(umoven): Use process_vm_readv for block reads of tracee memory.
(umovestr): Likewise.
* linux/syscall.h: Declare new function sys_process_vm_readv.
* process.c (sys_process_vm_readv): Decoder for new syscall.
* linux/i386/syscallent.h: Add process_vm_readv, process_vm_writev syscalls.
* linux/x86_64/syscallent.h: Likewise.
* linux/powerpc/syscallent.h: Likewise.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
12 years agoFix a case of broken output if last seen syscall was exit
Denys Vlasenko [Sat, 28 Jan 2012 00:25:03 +0000 (01:25 +0100)]
Fix a case of broken output if last seen syscall was exit

* defs.h: Rename tcp_last to printing_tcp. Explain what it means.
Remove printtrailer() function.
* process.c (sys_exit): Convert printtrailer() call to "printing_tcp = NULL".
* strace.c: Add new variable printing_tcp.
(cleanup): Convert printtrailer() call to "printing_tcp = NULL".
(trace): Likewise.
(trace): Fix checks for incomplete line - it was working wrongly if last syscall was exit.
(printleader): Set printing_tcp.
(printtrailer): Remove this function.
* syscall.c: Remove tcp_last variable.
(trace_syscall_entering): Don't set printing_tcp, printleader call now does it.
(trace_syscall_exiting): Convert printtrailer() call to "printing_tcp = NULL".

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
12 years agoFix handling of test/threaded_execve.c testcase
Denys Vlasenko [Sat, 28 Jan 2012 00:16:02 +0000 (01:16 +0100)]
Fix handling of test/threaded_execve.c testcase

Since 3.0, Linux has a way to identify which thread execve'ed.
This patch makes use of it in order to properly dispose
of disappeared ("superseded") thread leader,
and replace it with execve'ed thread.

Before this patch, strace was "leaking" thread which exec'ed.
It was thinking that it still runs. It would look like this:

18460 pause( <unfinished ...>     <=== thread leader
18466 execve("/proc/self/exe", ["exe", "exe"], [/* 47 vars */] <unfinished ...>
18465 +++ exited with 0 +++       <=== exits from other threads
18460 <... pause resumed> )             = 0

The last line is wrong: it's not pause resumed, it's execve resumed.
If thread leader would do exit instead of pause, it is much worse:
strace panics because it thinks it sees return from exit syscall!

And strace isn't aware 18466 (exec'ed thread) is gone.
It still thinks it's executes execve syscall.

* strace.c: New variable "static char *os_release".
(get_os_release): New static function.
(main): Call get_os_release to retrieve Linux version.
(trace): If we see PTRACE_EVENT_EXEC, retrieve old pid, and if it
differs from new one, free one of tcbs and print correct messages.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
12 years agoFix readlink result display - was printing bogus "..." semi-randomly
Denys Vlasenko [Fri, 27 Jan 2012 16:24:26 +0000 (17:24 +0100)]
Fix readlink result display - was printing bogus "..." semi-randomly

* file.c (decode_readlink): Use printstr() instead of printpathn().

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
12 years agoAdd new test program: test/threaded_execve.c
Denys Vlasenko [Fri, 27 Jan 2012 14:37:13 +0000 (15:37 +0100)]
Add new test program: test/threaded_execve.c

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
12 years agoMake pid2tcb static
Denys Vlasenko [Fri, 27 Jan 2012 14:24:48 +0000 (15:24 +0100)]
Make pid2tcb static

* defs.h: Remove pid2tcb declaration.
* strace.c (pid2tcb): Make this function static.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
12 years agoPer Dmitry's request, remove paranoid check in verror_msg()
Denys Vlasenko [Tue, 24 Jan 2012 11:48:02 +0000 (12:48 +0100)]
Per Dmitry's request, remove paranoid check in verror_msg()

* strace.c (verror_msg): Remove redundant check for msg != NULL.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
12 years agoMore robust error check for vasprintf
Denys Vlasenko [Tue, 24 Jan 2012 10:40:45 +0000 (11:40 +0100)]
More robust error check for vasprintf

* strace.c (verror_msg): More robust error check for vasprintf.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
12 years agoSlightly more compact handling of argv[]
Denys Vlasenko [Tue, 24 Jan 2012 10:37:03 +0000 (11:37 +0100)]
Slightly more compact handling of argv[]

   text    data     bss     dec     hex filename
 238274     672   20484  259430   3f566 strace.before
 238226     672   20484  259382   3f536 strace

* strace.c (main): Slightly more compact handling of argv[]

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>