Commit Graph

1887 Commits

Author SHA1 Message Date
Denys Vlasenko
907735aec8 Eliminate redundant checks of res variable
* syscall.c (trace_syscall_entering): Eliminate redundant checks of res variable.
(trace_syscall_exiting): Likewise.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2012-03-21 00:23:16 +01:00
Denys Vlasenko
46dc8b2206 Rename POWERPC-specific static variable result to ppc_result
* syscall.c: Rename POWERPC-specific static variable result to ppc_result.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2012-03-21 00:07:25 +01:00
Denys Vlasenko
bb6bb5c179 Remove redundant checks in syscall entry/exit, rename badly named function
* syscall.c (syscall_enter): Rename to get_syscall_args.
Document its return values.
(trace_syscall_entering): Don't check get_syscall_args() return
value for 0, it never returns that.
(syscall_fixup_on_sysexit): Make it return void.
(trace_syscall_exiting): Fix up syscall_fixup_on_sysexit()
call site accordingly.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2012-03-20 17:10:35 +01:00
Denys Vlasenko
b7a6dae9fb Trivial tweaks. No logic changes
* process.c (sys_ptrace): Remove unneeded line wrapping.
* syscall.c (trace_syscall_entering): Use tprints() instead of tprintf().

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2012-03-20 16:48:35 +01:00
Denys Vlasenko
852f98a382 Make ptrace_restart() static. No code changes
* defs.h: Remove ptrace_restart() declaration.
* strace.c (ptrace_restart): Move its definition here.
* util.c (ptrace_restart): Remove its definition.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2012-03-20 16:27:39 +01:00
806fbce4e6 Do not include limits.h unnecessarily
* ioctl.c: Remove limits.h inclusion left after the reverted change.
2012-03-20 14:02:51 +00:00
Denys Vlasenko
feb40c4543 Partially revert last change
Thank you Dmitry for spotting it.

* ioctl.c (compare): Partially revert last change - the new
comparison logic was buggy.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2012-03-20 13:11:51 +01:00
Denys Vlasenko
1c2e912cc3 Simplify search in ioctl table
text	   data	    bss	    dec	    hex	filename
 236973	    704	  18944	 256621	  3ea6d	strace.before
 236929	    704	  18944	 256577	  3ea41	strace

* ioctl.c (compare): Simplify generation of compare result.
(ioctl_lookup): Pass key directly, not as part of dummy struct.
(ioctl_next_match): More readable code. No logic changes.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2012-03-20 10:57:41 +01:00
Denys Vlasenko
8cf2c261ea Update qemu build script: now tries to upload result back to host
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2012-03-19 12:20:32 +01:00
Denys Vlasenko
c1371ebc40 Shrink space needed by undefined syscalls in syscall tables.
Undefined syscall looked like this before this change:
{ 5,    0,      printargs,              "SYS_53"                },
That is, "SYS_53" string had to be allocated and stored in strace binary.
Since now SCNO_IN_RANGE() macro requires sysent[scno].sys_func != NULL
for valid syscalls, we can replace printargs with NULL in such lines
and make them "invalid", thus not requiring syscall name string.

Savings on i386:
   text	   data	    bss	    dec	    hex	filename
 237389	    704	  18944	 257037	  3ec0d	strace.before
 236973	    704	  18944	 256621	  3ea6d	strace
Savings on mips:
 336551  153692   38320  528563   810b3 strace.before
 275543  153688   38320  467551   7225f strace

Tested to still decode undefined syscalls correctly (syscall no. 222 on i386).

* linux/*/syscallent.h: Replace 'printargs, "SYS_nnn"' with
'NULL, NULL'.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2012-03-19 09:51:42 +01:00
Denys Vlasenko
9fd4f96d2a Optimize code if we have only one personality
On i386:
   text	   data	    bss	    dec	    hex	filename
 238025	    672	  18980	 257677	  3ee8d	strace.before
 237389	    704	  18944	 257037	  3ec0d	strace

* defs.h: Define PERSONALITY0_WORDSIZE as sizeof(long) if not defined.
Introduce new define, current_wordsize as
(personality_wordsize[current_personality]).
Make set_personality() no-op, current_personality constant zero,
current_wordsize as PERSONALITY0_WORDSIZE if we have only one personality.
* count.c (call_summary): Use current_wordsize instead of
personality_wordsize[current_personality].
* desc.c (printflock): Likewise.
* file.c (sys_utime): Likewise.
* io.c (tprint_iov): Likewise.
* process.c (printargv): Likewise.
* resource.c (decode_rlimit): Likewise.
* signal.c (sys_kill): Likewise.
(sys_rt_sigaction): Likewise.
* time.c (sprinttv): Likewise.
(sprint_timespec): Likewise.
(printitv_bitness): Likewise.
(tprint_timex): Likewise.
(printsigevent): Likewise.
* util.c (dumpiov): Likewise.
(umoven): Likewise.
(umovestr): Likewise.
* syscall.c: Initialize sysent to sysent0 etc.
Make current_personality, personality_wordsize[], set_personality()
conditional on SUPPORTED_PERSONALITIES > 1.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2012-03-19 09:36:42 +01:00
Denys Vlasenko
1be02798f5 Fix mips64 build failure: sys_pwrite64 doesn't exist.
sys_pwrite seems to do the same thing as sys_pwrite64
which we deleted when we removed non-Linux code.

* linux/mips/syscallent.h: s/sys_pwrite64/sys_pwrite/

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2012-03-18 23:49:07 +01:00
Denys Vlasenko
6acf586aa8 qemu_multiarch_testing/: a directory with scripts for build testing
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2012-03-18 23:27:23 +01:00
Denys Vlasenko
146b944d4a Make internal_fork and internal_exec static
text	   data	    bss	    dec	    hex	filename
 237917	    672	  18980	 257569	  3ee21	strace
 237845	    672	  18980	 257497	  3edd9	strace_new

* defs.h: Remove declarations of internal_fork and internal_exec.
* process.c: Remove definitions of internal_fork and internal_exec.
* syscall.c: Move them here.
(internal_syscall): Return void instead of int. We were always
returning zero, and callers weren't checking it anyway.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2012-03-18 22:10:48 +01:00
Denys Vlasenko
f50e7141d5 Remove code which is not used on Linux
Compile tested in qemu on armv4l,armv4tl,armv5l,armv6l,i686,
mipsel,mips,x86_64

* syscall.c: Remove code which handles RVAL_Lfoo constants.
* defs.h: Remove struct tcb::u_lrval member - it is never set.
Remove RVAL_Lfoo constants which signify return of "long" result -
they are never used.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2012-03-18 04:16:59 +01:00
Denys Vlasenko
88c63f21b1 Remove unused version of sys_lseek
It is buggy: it returns RVAL_LUDECIMAL, which means the return value
is in tcp->u_lrval. But tcp->u_lrval is never set
(on Linux - it used to be set on other OSes).

* file.c (sys_lseek): Remove a version of this function which is
supposed to be used if off_t is long long. It appears to be buggy
and unused.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2012-03-18 04:13:14 +01:00
Denys Vlasenko
8677913953 Revert "Remove underscores from a few syscall names which have them"
This reverts commit 31972d52b1.
2012-03-17 18:00:14 +01:00
Denys Vlasenko
0c163c408f Simplify sys_lseek64 conditional compilation.
It looks like sys_lseek64() is never used.
For one, it is buggy (always shows 0 return value), and no one complains.

From code inspection: sys_lseek64 name is not used anywhere.
It is defined to sys_lseek if HAVE_LONG_LONG_OFF_T is true.
Thus, if !HAVE_LONG_LONG_OFF_T, it is never used.
Therefore "if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T"
conditional it sits in can be simplified to
"if HAVE_LONG_LONG_OFF_T".
Therefore, we can move it a bit up and merge with
"if !HAVE_LONG_LONG_OFF_T, use this sys_lseek()" code block,
by addind an "else" clause to it.
To simplify it more, drop define and just rename sys_lseek64 ->
sys_lseek.

Since the function is buggy, I think it is unused and we can
just drop it. (I checked: at least I386 never uses it).

* file.c (sys_lseek64): Rename to sys_lseek; don't compile it
if _LFS64_LARGEFILE but !HAVE_LONG_LONG_OFF_T since in this case
it is never used.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2012-03-17 16:26:47 +01:00
Denys Vlasenko
31972d52b1 Remove underscores from a few syscall names which have them
Affected names are "_newselect", "_llseek", "_sysctl".
I see no apparent reason why they have leading underscores.
Moreover, some arches have underscored names and some have
non-underscored ones. This is not consistent.

I verified that every architectire I touched did not have
a similarly named syscall without underscore, thus this change
does not introduce new ambiquities.

I left "_exit" untouched for now, but the same points stand for it too:
some architectures use "exit" and no one complains. So why many
arches are using "_exit"?

* linux/*/syscallent.h: Remove underscores from displayed
syscall names for _newselect, _llseek, _sysctl.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2012-03-17 13:23:00 +01:00
Denys Vlasenko
a61a72eacb Remove unused struct tcb::baddr field
* defs.h: Remove unused struct tcb::baddr field.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2012-03-17 12:41:27 +01:00
Denys Vlasenko
e10a0e4734 Remove unused PTRACE_WRITE{TEXT,DATA} constants (they are from SunOS)
* util.c: Remove unused PTRACE_WRITE{TEXT,DATA} constants.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2012-03-17 12:11:10 +01:00
Denys Vlasenko
989ebc9139 Reindent case labels. No code changes
* net.c (printsockopt): Reindent case labels.
* signal.c (sys_signal): Likewise.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2012-03-17 04:42:07 +01:00
Denys Vlasenko
3da9693b81 Remove unused constants. No code changes
* syscall.c: Remove unused ENOIOCTLCMD constant. Fix indentation.
* util.c: Remove unused CLONE_STOPPED constant.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2012-03-17 03:17:15 +01:00
Denys Vlasenko
081533c100 Move change_syscall() to its only user and make it static
* defs.h: Remove declaration of change_syscall().
* process.c (change_syscall): Remove definition of this function.
* util.c (change_syscall): Add definition of change_syscall().

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2012-03-17 02:17:51 +01:00
Denys Vlasenko
2897fb3437 MAP_ANON is the same as MAP_ANONYMOUS, no need to have the former
* mem.c: Do not allocate string for MAP_ANON if it is the same as
MAP_ANONYMOUS.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2012-03-17 01:29:40 +01:00
Denys Vlasenko
3e3490acf7 Indentation and whitespace fixes. No code changes.
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2012-03-17 01:27:37 +01:00
Denys Vlasenko
cb419c52cb test/threaded_execve: make it also test a case when leader is not in syscall
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2012-03-17 01:24:25 +01:00
b468f2320a Implement prlimit64 decoding, rewrite [gs]etrlimit decoding
* configure.ac: Remove AC_RLIM_T_IS_LONG_LONG call.
Define SIZEOF_RLIM_T.
* m4/long_long.m4 (AC_RLIM_T_IS_LONG_LONG): Remove.
* linux/dummy.h (sys_prlimit64): Remove.
* linux/syscall.h (sys_prlimit64): New prototype.
* resource.c (resources): Reindent, add RLIMIT_RTTIME.
(sprintrlim, print_rlimit32, sys_getrlimit, sys_setrlimit): Remove.
[HAVE_LONG_LONG_RLIM_T]: Remove dead code.
[_LFS64_LARGEFILE || HAVE_LONG_LONG_RLIM_T]: Likewise.
(sprint_rlim64, print_rlimit64, decode_rlimit64, sprint_rlim32,
print_rlimit32, decode_rlimit, sys_getrlimit, sys_setrlimit,
sys_prlimit64): New functions.
2012-03-16 19:05:21 +00:00
Denys Vlasenko
9c3861d317 Remove another "interrupt to quit" message
* strace.c (startup_attach): Remove another "interrupt to quit" message.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2012-03-16 15:21:49 +01:00
Denys Vlasenko
3db3b26101 Fix "strace -oFILE -ff -p<nonexistant_pid>" behavior
* strace.c (newoutf): Set tcp->outf in non-ff mode too.
(alloctcb): This define is removed.
(alloc_tcb): Renamed to alloctcb. Does not set tcp->outf anymore.
Lost 'command_options_parsed' flag parameter.
(startup_attach): Do not say "interrupt to quit" in attach message -
^C does not work in all cases, we mislead users.
Call newoutf(tcp) after successful attach.
(startup_child): Call newoutf(tcp) after successful attach.
(trace): Call newoutf(tcp) when we picked up already attached child.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2012-03-16 15:15:14 +01:00
Denys Vlasenko
800ec8ffde Make alloc_tcb and droptcb static. No code changes.
The change is trivial. Diff is large because it is confused
by function definitions being moved around.

* defs.h: Remove declarations of alloc_tcb and droptcb.
* strace.c: Make alloc_tcb and droptcb static.
Shuffle functions around to make compiler happy.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2012-03-16 15:11:34 +01:00
Denys Vlasenko
a6d91ded3f Tidy up includes and copyright notices, fix indentation
The files not mentioned in changelog below had only
copyright notices fixes and indentation fixes.

* defs.h: Include <stdint.h> and <inttypes.h>.
* file.c: Do not include <inttypes.h>.
Move struct kernel_dirent declaration below top include block.
* block.c: Do not include <stdint.h> and <inttypes.h>.
* quota.c: Likewise.
* desc.c: Likewise.
* signal.c: Likewise.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2012-03-16 12:02:22 +01:00
27aeaa2aaa scsi.c: add copyright header
* scsi.c: This file was added back in 2007 without a copyright header.
Add it now.
2012-03-16 10:43:32 +00:00
4a0ffeaf85 Enhance capget and capset syscalls decoding
* system.c (cap_version): New xlat structure.
(print_cap_header, print_cap_data): New functions.
(sys_capget, sys_capset): Use them.
2012-03-15 22:58:39 +00:00
648c22c4b3 Remove unused code
* syscall.c (subcall_style, decode_subcall): Remove.
[SYS_socket_subcall] (decode_socket_subcall): New function, based on
decode_subcall in deref_style.
[SYS_ipc_subcall] (decode_ipc_subcall): New function, based on
decode_subcall in shift_style.
(trace_syscall_entering): Use decode_socket_subcall and
decode_ipc_subcall instead of decode_subcall.
2012-03-15 22:08:55 +00:00
3d7b11bf55 Fix IPC decoding on alpha and arm
* ipc.c (indirect_ipccall): Return 0 on ALPHA and ARM EABI.
(sys_shmat): Use indirect_ipccall for proper return value decoding.
2012-03-15 21:19:36 +00:00
63e4f86bd7 arm: fix compilation warnings
* configure.ac: Define SIZEOF_LONG.
* signal.c (sys_rt_sigaction) [SUPPORTED_PERSONALITIES > 1]: Help
compiler to optimize out unreachable code that is not expected to work
on platforms where sizeof(long) <= 4.
2012-03-15 20:42:46 +00:00
84abf70011 tests: robustify again buggy shells
* tests/init.sh (check_strace): Use "${parameter:-word}" shell syntax
instead of "${parameter-word}".

Reported-by: Mike Frysinger <vapier@gentoo.org>
2012-03-15 20:17:49 +00:00
Mike Frysinger
3362e89f66 improve ifdef check with decode_subcall
Use the same ifdef logic around the call sites of decode_subcall()
to protect the definition of the func itself.  This fixes warnings
for targets like hppa which don't use this func.

* syscall.c (decode_subcall): Wrap in SYS_socket_subcall and
SYS_ipc_subcall define checks.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
2012-03-15 20:14:28 +00:00
Mike Frysinger
dde045c13f alpha: fix decode of osf_sigprocmask
The alpha sigprocmask syscall is special in that it comes from OSF rather
than the style that everyone else uses.

Tested with this simple code:
$ cat test.c
#include <signal.h>
main() {
	sigset_t set, oldset;
	sigemptyset(&set);
	sigaddset(&set, SIGINT);
	sigaddset(&set, SIGHUP);
	sigprocmask(SIG_SETMASK, &set, &oldset);
	sigprocmask(SIG_UNBLOCK, &oldset, &set);
	sleep(3);
}
$ gcc test.c && ./strace ./a.out
...
osf_sigprocmask(SIG_SETMASK, [HUP INT]) = 0 (old mask [])
osf_sigprocmask(SIG_UNBLOCK, [])        = 0x3 (old mask [HUP INT])
osf_sigprocmask(SIG_BLOCK, [CHLD])      = 0x3 (old mask [HUP INT])
...

* linux/alpha/syscallent.h: Call sys_sigprocmask for osf_sigprocmask,
and change number of arguments to two.
* signal.c (sys_sigprocmask): Fix decoding of alpha osf sigprocmask.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
2012-03-15 20:14:17 +00:00
Denys Vlasenko
384b0ada7d Fix array size calculation in previous commit
* pathtrace.c (getfdpath): Fix array size calculation.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2012-03-15 18:11:51 +01:00
Denys Vlasenko
29865e77e6 pathtrace_select() is never called with NULL, remove dead code
pathtrace_select() is only called for -P FILE options,
and FILE is never a NULL pointer.

   text	   data	    bss	    dec	    hex	filename
 239453	    672	  19012	 259137	  3f441	strace.before
 239329	    672	  19012	 259013	  3f3c5	strace

* pathtrace.c (pathtrace_select): Remove "if (path == NULL)...".
(pathtrace_select): Remove code which only executes if path == NULL.
The code was also buggy, it can free non-malloced pointer.
(getfdpath): Simplify snprintf to sprintf.
(pathmatch): Use strcmp() == 0 idiom for string equality test.
(pathtrace_match): Likewise.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2012-03-15 18:03:56 +01:00
Denys Vlasenko
7c2b1a6dd0 manpage: remove bugs which are fixed
"A traced process ignores SIGSTOP" - fixed, expected to be in linux-3.4.x.
"A traced process which tries to block SIGTRAP will be sent a SIGSTOP
in an attempt to force continuation of tracing." - not needed
and no longer done.
"On Linux, exciting as it would be, tracing the init process is forbidden"
- not true anymore.
"When a traced process receives a SIGTRAP signal not
associated with tracing, strace will not report that signal correctly."
- not true anymore.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2012-03-15 17:32:56 +01:00
Denys Vlasenko
a509054aee Simplify SIGCHLD handler setting
* strace.c (init): Set SIGCHLD to SIG_DFL earlier.
(startup_child): Do not bother restoring SIGCHLD handler.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2012-03-15 17:27:49 +01:00
Denys Vlasenko
2c4fb905fe When reporting signals, use short signal names (SIGfoo) instead of strerror
* defs.h: Remove strsignal declaration.
* signal.c: Better check for SI_FROMUSER define.
* strace.c (strerror): Remove this function.
(trace): Use short signal names (SIGfoo) instead of strerror.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2012-03-15 17:24:49 +01:00
Denys Vlasenko
7cba831386 Remove TODO file: it's eleven years old and completely outdated
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2012-03-15 15:55:33 +01:00
Denys Vlasenko
29898149a0 Clean up defs.h order. No code changes
* defs.h: Group together related declarations. No code changes.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2012-03-15 15:02:49 +01:00
Denys Vlasenko
6e0bfd11ac Fix lame kernel version checking code
The code "os_release[0] >= '3'" is not good for any
finer-grained checks such as "kernel >= 3.2.1".
Let's proactively fix it.

* strace.c: Change os_release from string to integer.
(get_os_release): Parse uname.release to KERNEL_VERSION
representation.
(init): Convert kernel version check to KERNEL_VERSION.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2012-03-15 14:36:28 +01:00
Denys Vlasenko
61e7aad9fa Experimental support for "detach on execve" feature
* strace.c: Define new detach_on_execve, skip_startup_execve bool variables.
(init): Set detach_on_execve on -b, set skip_startup_execve if
"strace PROG" form is used.
(trace): Detach from process if -b and we see PTRACE_EVENT_EXEC event.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2012-03-15 13:44:17 +01:00
Denys Vlasenko
3e084ac349 Simple fixes.
* strace.c (usage): Document -d; document that -F is deprecated.
(droptcb): Print "<detached ...>" correctly for non-ff mode too.
(detach): Suppress a warning.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2012-03-15 13:39:05 +01:00