]> granicus.if.org Git - strace/log
strace
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>
12 years agoTrivial optimization
Denys Vlasenko [Tue, 24 Jan 2012 10:35:38 +0000 (11:35 +0100)]
Trivial optimization

* strace.c: Set default interactive = 1 statically instead
of doing it in main().

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
12 years agoAllocate -o OUTFILE buffer only if needed
Denys Vlasenko [Tue, 24 Jan 2012 10:31:51 +0000 (11:31 +0100)]
Allocate -o OUTFILE buffer only if needed

   text    data     bss     dec     hex filename
 238258     668   28676  267602   41552 strace.before
 238274     668   20484  259426   3f562 strace

* strace.c (main): Allocate -o OUTFILE buffer only if needed:
unused buffer in bss is not entirely free.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
12 years agoUse single fprintf in verror_msg()
Denys Vlasenko [Tue, 24 Jan 2012 09:17:18 +0000 (10:17 +0100)]
Use single fprintf in verror_msg()

This change partially reverts commit 44d0532.

In code before commit 44d0532, single fprintf was used on purpose:
we want to send entire message as one write() call. Since stderr
is unbuffered, separate fprintf's to it always result in separate
writes, they are not coalesced. If we aren't the only program
which writes to this particular stderr, this may result
in interleaved messages.

Since this function is not performance critical, I guess
it's ok to make it less efficient.

* strace.c (verror_msg): Attempt to print the message in single
write operation. Use separate fprintfs as a fallback if malloc fails.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
12 years agoImprove code readability (logic is unchanged)
Denys Vlasenko [Sat, 21 Jan 2012 03:01:56 +0000 (04:01 +0100)]
Improve code readability (logic is unchanged)

* util.c (umoven): Move assignment out of function call. Make assignment
to a flag variable later, closer to the place where it will be used.
(umovestr): Likewise.
(uload): Likewise.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
12 years agoChange umovestr API: return > 0 instead of 0 if NUL was seen
Denys Vlasenko [Fri, 20 Jan 2012 10:56:00 +0000 (11:56 +0100)]
Change umovestr API: return > 0 instead of 0 if NUL was seen

* pathtrace.c (upathmatch): Adjust umovestr return value check for new API.
* util.c (printpathn): Use umovestr() > 0 return value for more efficient
(and robust - we don't depend on "no overwrote past NUL" behavior anymore)
handling of terminating NUL.
(printstr): Remove useless NUL placement before umovestr() call.
Allocate 1 byte more to outstr[] array - for NUL.
(umovestr): Change to return 1 if NUL was seen.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
12 years agoumovestr result may have no NUL, use "%.*s" instead of "%s" to print it
Denys Vlasenko [Fri, 20 Jan 2012 10:52:12 +0000 (11:52 +0100)]
umovestr result may have no NUL, use "%.*s" instead of "%s" to print it

* system.c (sys_mount): Be careful when printing umovestr result,
it may have no terminating NUL.
(sys_sysmips): Likewise.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
12 years agoEliminate code duplication in time printing, reduce a few static buffers
Denys Vlasenko [Fri, 20 Jan 2012 10:04:04 +0000 (11:04 +0100)]
Eliminate code duplication in time printing, reduce a few static buffers

   text    data     bss     dec     hex filename
 238454     664   28772  267890   41672 strace.before
 238106     664   28676  267446   414b6 strace

* defs.h: Add TIMESPEC_TEXT_BUFSIZE and TIMEVAL_TEXT_BUFSIZE defines.
Add 'int special' parameter to sprinttv().
* time.c (sprinttv): Add 'int special' parameter, and use it
similarly to 'int special' parameter of printtv_bitness().
(printtv_bitness): Use sprinttv() instead of duplicating its code.
(print_timespec): Use sprint_timespec() instead of duplicating
its code.
* desc.c (decode_select): Use TIMEVAL_TEXT_BUFSIZE instead of 128
when checking remaining buffer size.
* net.c (sys_recvmsg): Use TIMESPEC_TEXT_BUFSIZE instead of 128
for static buffer size.
* stream.c (decode_poll): Use TIMESPEC_TEXT_BUFSIZE instead of 128
when checking remaining buffer size.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
12 years agoReduce bss usage and speed up string printing
Denys Vlasenko [Thu, 19 Jan 2012 16:20:23 +0000 (17:20 +0100)]
Reduce bss usage and speed up string printing

   text    data     bss     dec     hex filename
 237913     660   49284  287857   46471 strace.before
 237973     660   28772  267405   4148d strace

This reduces L1 D-cache pressure a bit: instead of dirtying
20k of bss, we will reuse already dirty stack area.

* util.c (printpathn): Use on-stack buffers instead of static ones.
Saves 5*MAXPATHLEN in bss.
(printstr): Use tprints() instead of tprintf("%s") when printing
formatted string. May be a bit faster, depending on libc.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
12 years agoAdd support for compat_statfs64
Andreas Schwab [Tue, 17 Jan 2012 17:14:22 +0000 (18:14 +0100)]
Add support for compat_statfs64

* file.c (struct compat_statfs64, printcompat_statfs64): Define.
(sys_statfs64, sys_fstatfs64): Use it.

12 years agoAdd support for statfs64.f_flags
Andreas Schwab [Tue, 17 Jan 2012 17:13:33 +0000 (18:13 +0100)]
Add support for statfs64.f_flags

* file.c (printstatfs64): Print f_flags if available.

12 years agoFix missing parens
Andreas Schwab [Tue, 17 Jan 2012 16:56:44 +0000 (17:56 +0100)]
Fix missing parens

* signal.c (sys_sigreturn): Add missing parens.

12 years agoGet rid of TCB_SIGTRAPPED
Denys Vlasenko [Wed, 18 Jan 2012 15:30:47 +0000 (16:30 +0100)]
Get rid of TCB_SIGTRAPPED

On attempts to block or set SIGTRAP handler,
for example, using sigaction syscall, we generate
an additional SIGSTOP.

This change gets rid of this SIGSTOP sending/ignoring.
It appears to work just fine.

It also works if I force strace to not use PTRACE_O_TRACESYSGOOD,
which means strace stops will be marked with SIGTRAP,
not (SIGTRAP | 0x80) - I wondered maybe that's when
this hack is needed.

So, why we even have TCB_SIGTRAPPED? No one knows. It predates
version control: this code was present in the initial commit,
in 1999. No adequate comments, either.

Moreover, TCB_SIGTRAPPED is not set in sys_rt_sigaction
and sys_sigprocmask syscalls - the ones which are most usually
used to implement signal blocking, it is only set in obsolete
sys_signal, sys_sigaction, sys_sigsetmask, and in some dead
non-Linux code.

I think whatever bug it was fixing is gone long ago -
at least as long as sys_rt_sigaction is used by glibc.
Again, since glibc (and uclibc) uses sys_rt_sigaction
and sys_sigprocmask, modified code paths are not used
by most programs anyway.

* defs.h: Remove definition of TCB_SIGTRAPPED.
* signal.c (sys_sigvec): Don't set TCB_SIGTRAPPED and don't send SIGSTOP.
(sys_sigsetmask): Likewise.
(sys_sigaction): Likewise.
(sys_signal): Likewise.
* strace.c (trace): Remove code which executes if TCB_SIGTRAPPED is set.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
12 years agoWhen we write log, flush output buffers in a few more cases
Denys Vlasenko [Wed, 18 Jan 2012 15:20:56 +0000 (16:20 +0100)]
When we write log, flush output buffers in a few more cases

I observed a case when signal delivery message was buffered
by stdio until it was flushed along with the next syscall
entry message.

* strace.c (trace): Flush output buffers in a few more cases.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
12 years agoFix old sigaction display
Denys Vlasenko [Wed, 18 Jan 2012 14:30:56 +0000 (15:30 +0100)]
Fix old sigaction display

* signal.c (sys_sigaction): Fix display of sigaction with
SIG_DFL/SIG_IGN handlers.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
12 years agoChange x86_64_regs struct type from pt_regs to user_regs_struct
Denys Vlasenko [Wed, 18 Jan 2012 10:07:24 +0000 (11:07 +0100)]
Change x86_64_regs struct type from pt_regs to user_regs_struct

* syscall.c: Change x86_64_regs struct type from
pt_regs to user_regs_struct, and explain the change in comment.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
12 years agoFix struct pt_regs declaration on i386 and x86-64
Dmitry V. Levin [Tue, 17 Jan 2012 18:37:13 +0000 (18:37 +0000)]
Fix struct pt_regs declaration on i386 and x86-64

* defs.h [I386] (i386_regs): Replace definition with declaration.
[X86_64] (x86_64_regs): Remove.
* syscall.c [X86_64] (x86_64_regs): Make static.

12 years agoMake ERESTARTxyz messages more descriptive
Denys Vlasenko [Thu, 12 Jan 2012 10:26:34 +0000 (11:26 +0100)]
Make ERESTARTxyz messages more descriptive

There is widespread confusion about exact meaning
of ERESTARTxyz codes. Before this change, we were showing
all four of them the same: as "(To be restarted)".

This change prints better explanations for these codes,
and contains verbose comments which explain *why* we display
codes that way - or else someone confused
is bound to come later and mangle them again.
New messages are:

ERESTARTSYS (To be restarted if SA_RESTART is set)
ERESTARTNOINTR (To be restarted)
ERESTARTNOHAND (Interrupted by signal)
ERESTART_RESTARTBLOCK (Interrupted by signal)

* syscall.c (trace_syscall_exiting): Make ERESTARTxyz messages
more descriptive.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
12 years agoFix sigreturn arg count from 1 to 0 on all architectures.
Denys Vlasenko [Tue, 10 Jan 2012 15:48:19 +0000 (16:48 +0100)]
Fix sigreturn arg count from 1 to 0 on all architectures.

* linux/alpha/syscallent.h: Change [rt_]sigreturn's arg count to 0.
* linux/arm/syscallent.h: Likewise.
* linux/avr32/syscallent.h: Likewise.
* linux/bfin/syscallent.h: Likewise.
* linux/m68k/syscallent.h: Likewise.
* linux/microblaze/syscallent.h: Likewise.
* linux/mips/syscallent.h: Likewise.
* linux/powerpc/syscallent.h: Likewise.
* linux/sh/syscallent.h: Likewise.
* linux/sh64/syscallent.h: Likewise.
* linux/sparc/syscallent.h: Likewise.
* linux/tile/syscallent.h: Likewise.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
12 years agoDisplay mask on enter to sigreturn, not on exit
Denys Vlasenko [Tue, 10 Jan 2012 15:40:35 +0000 (16:40 +0100)]
Display mask on enter to sigreturn, not on exit

sys_sigreturn() performs ugly manipulations in order to show
signal mask which is restored by this syscall: on syscall entry,
fetches it from the stack, saves it in tcp->u_arg[]
(where it used to overflow this array - fixed sometime ago),
then retrieves the mask and displays it on syscall exit.

Apparently, the motivation is to make it slightly more obvious
to user that signal mask is restored only when this syscall returns.
IMO, this hardly justifies the necessary hacks. It is much easier
to display the mask at the point when we fetch it - on syscall entry.

While at it, I made it so that we do display returned value/errno.
I see no point in hiding it and showing uninformative "= ?" instead.

Example of pause() being interrupted by ALRM which has installed handler
which re-arms ALRM:

Before the patch:

rt_sigsuspend([INT])                    = ? ERESTARTNOHAND (To be restarted)
--- {si_signo=SIGALRM, si_code=SI_KERNEL} (Alarm clock) ---
alarm(1)                                = 0
sigreturn()                             = ? (mask now [INT])

After:

rt_sigsuspend([INT])                    = ? ERESTARTNOHAND (To be restarted)
--- {si_signo=SIGALRM, si_code=SI_KERNEL} (Alarm clock) ---
alarm(1)                                = 0
sigreturn() (mask [INT])                = -1 EINTR (Interrupted system call)

* defs.h: Declare struct pt_regs i386_regs and struct pt_regs x86_64_regs.
* syscall.c: Remove "static" keywork from these structures' definitions.
* signal.c (sys_sigreturn): Display mask on enter, not on exit.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
12 years agoDo not detach from tracee which experienced ptrace error.
Denys Vlasenko [Wed, 4 Jan 2012 14:15:26 +0000 (15:15 +0100)]
Do not detach from tracee which experienced ptrace error.

Before this patch, if a thread got nuked by exit in another thread
and we happened to poke it at the same time, we print "????(" thingy
and detach the thread. Since we removed "detach before death" logic,
this no longer matches the behavior of other threads.
Before patch:
[pid  1780] exit_group(1)               = ?
[pid  1778] ????( <unfinished ...>
Process 1778 detached
[pid  5860] +++ exited with 1 +++
After:
[pid 17765] exit_group(1)               = ?
[pid 21680] ????( <unfinished ...>
[pid 17791] +++ exited with 1 +++
[pid 21680] +++ exited with 1 +++

* strace (trace): Do not detach from tracee which experienced ptrace error.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
12 years agoRemove sig parameter from detach()
Denys Vlasenko [Wed, 4 Jan 2012 14:11:09 +0000 (15:11 +0100)]
Remove sig parameter from detach()

* strace.c (detach): Drop sig parameter - it is zero in all calls.
(cleanup): Don't pass sig = 0 to detach() call.
(detach): Ditto.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
12 years agoEnhance decoding for personalities with small wordsize
Dmitry V. Levin [Mon, 26 Dec 2011 20:12:02 +0000 (20:12 +0000)]
Enhance decoding for personalities with small wordsize

* util.c (umoven, umovestr) [SUPPORTED_PERSONALITIES > 1]: If current
personality's wordsize is less than sizeof(long), use only significant
bits of the given address.

12 years agoEnhance personality switching
Dmitry V. Levin [Fri, 23 Dec 2011 00:50:49 +0000 (00:50 +0000)]
Enhance personality switching

On syscall entry, save current personality in the tcb structure
along with scno.
On syscall exit, restore current personality from the tcb structure.
* defs.h (struct tcb) [SUPPORTED_PERSONALITIES > 1]: Add currpers
field.
* strace.c (alloc_tcb) [SUPPORTED_PERSONALITIES > 1]: Initialize
tcp->currpers.
* syscall.c (update_personality) [SUPPORTED_PERSONALITIES > 1]: New
function.
(get_scno, trace_syscall_exiting): Use it.

Reported-by: Michael A Fetterman <mafetter@nvidia.com>
12 years ago* net.c (socktcpoptions): Add more TCP_* constants from linux/tcp.h
Dmitry V. Levin [Thu, 1 Dec 2011 21:06:00 +0000 (21:06 +0000)]
* net.c (socktcpoptions): Add more TCP_* constants from linux/tcp.h

Reported-by: Rick Jones <rick.jones2@hp.com>
12 years agoFix sys_ipc/sys_semtimedop decoding on s390
Heiko Carstens [Wed, 30 Nov 2011 12:16:29 +0000 (13:16 +0100)]
Fix sys_ipc/sys_semtimedop decoding on s390

The s390 kernel sys_ipc system call only takes five arguments instead of
six arguments which the common code sys_ipc implementation takes.
One of the arguments of the sys_semtimedop subcall is therefore passed in
a different register than in the common code implementation.
This leads to broken decoding of the timespec argument:

semtimedop(0, 0x3ffffb43832, 1, {...})  = -1 EAGAIN

Fixed it looks like this:

semtimedop(0, 0x3ffffc2c842, 1, {0, 10000000}) = -1 EINTR

* linux/ipc.c (sys_semtimedop): Fix timespec decoding on s390.

Signed-off-by: Heiko Carstens <heiko.carstens@de.ibm.com>
12 years agostrace.c (trace): Fix compilation warning
Dmitry V. Levin [Tue, 29 Nov 2011 00:15:59 +0000 (00:15 +0000)]
strace.c (trace): Fix compilation warning

12 years agolinux/syscall.h: Remove redundant function declarations
Dmitry V. Levin [Mon, 28 Nov 2011 23:54:36 +0000 (23:54 +0000)]
linux/syscall.h: Remove redundant function declarations

Remove 51 function declarations aliased to other declarations in
linux/dummy.h file.

12 years agolinux/syscall.h: Sort function declarations
Dmitry V. Levin [Mon, 28 Nov 2011 23:41:58 +0000 (23:41 +0000)]
linux/syscall.h: Sort function declarations

12 years agolinux/syscall.h: Place one function declaration per line
Dmitry V. Levin [Mon, 28 Nov 2011 23:25:13 +0000 (23:25 +0000)]
linux/syscall.h: Place one function declaration per line

12 years agoRemove redundant parsers
Dmitry V. Levin [Mon, 28 Nov 2011 22:48:53 +0000 (22:48 +0000)]
Remove redundant parsers

* desc.c (sys_dup): Remove.
* file.c (sys_pivotroot, sys_rmdir, sys_fchdir, sys_chroot, sys_fchroot,
sys_unlink, sys_symlink, sys_rename): Remove.
* linux/syscall.h (sys_chroot, sys_dup, sys_fchdir, sys_pivotroot,
sys_rename, sys_rmdir, sys_symlink, sys_unlink): Remove.
* linux/dummy.h: Add aliases for sys_chroot, sys_dup, sys_pivotroot,
sys_rename, sys_rmdir, sys_symlink, sys_unlink.
* pathtrace.c (pathtrace_match): Update.
* sunos4/dummy.h: Add aliases for sys_chroot, sys_dup, sys_fchdir,
sys_fchroot, sys_rename, sys_rmdir, sys_symlink, sys_unlink.
* svr4/dummy.h: Likewise.
* sunos4/syscall.h (sys_chroot, sys_dup, sys_fchdir, sys_fchroot,
sys_rename, sys_rmdir, sys_symlink, sys_unlink): Remove.
* svr4/syscall.h (sys_chroot, sys_dup, sys_fchdir, sys_fchroot,
sys_rename, sys_rmdir, sys_symlink, sys_unlink): Remove.

12 years agoReflect the fact that nfsservctl syscall was removed from linux kernels
Dmitry V. Levin [Mon, 28 Nov 2011 15:53:20 +0000 (15:53 +0000)]
Reflect the fact that nfsservctl syscall was removed from linux kernels

linux/dummy.h: Move nfsservctl to "unimplemented" section.

12 years agox86_64: add getcpu syscall entry
Dmitry V. Levin [Sun, 27 Nov 2011 22:49:04 +0000 (22:49 +0000)]
x86_64: add getcpu syscall entry

* linux/x86_64/syscallent.h: Add syscall entry for getcpu.

12 years agoAdd syscall entries for new linux syscalls
Dmitry V. Levin [Sat, 26 Nov 2011 23:37:23 +0000 (23:37 +0000)]
Add syscall entries for new linux syscalls

* linux/dummy.h: Add printargs parsers for new syscalls.
* linux/arm/syscallent.h: Add entries for sys_clock_adjtime,
sys_name_to_handle_at, sys_open_by_handle_at, sys_sendmmsg, sys_setns
and sys_syncfs.
* linux/i386/syscallent.h: Likewise.
* linux/ia64/syscallent.h: Likewise.
* linux/mips/syscallent.h: Likewise.
* linux/powerpc/syscallent.h: Likewise.
* linux/sh/syscallent.h: Likewise.
* linux/sh64/syscallent.h: Likewise.
* linux/sparc/syscallent.h: Likewise.
* linux/x86_64/syscallent.h: Likewise.
* linux/alpha/syscallent.h: Add entries for sys_clock_adjtime,
sys_name_to_handle_at, sys_open_by_handle_at, sys_setns and sys_syncfs.
* linux/m68k/syscallent.h: Likewise.
* linux/microblaze/syscallent.h: Likewise.
* linux/s390/syscallent.h: Likewise.
* linux/s390x/syscallent.h: Likewise.
* linux/avr32/syscallent.h: Add entry for sys_setns.
* linux/bfin/syscallent.h: Add entries for sys_sendmmsg and sys_setns.
* linux/hppa/syscallent.h: Add entries for sys_clock_adjtime,
fanotify_init, fanotify_mark, sys_name_to_handle_at,
sys_open_by_handle_at, sys_sendmmsg, sys_setns and sys_syncfs.

12 years agoFix prctl syscall entries
Dmitry V. Levin [Sat, 26 Nov 2011 23:14:40 +0000 (23:14 +0000)]
Fix prctl syscall entries

* linux/mips/syscallent.h: Fix prctl handler.
* linux/tile/syscallent.h: Likewise.

12 years agoarm: fix io_* syscall entries
Dmitry V. Levin [Sat, 26 Nov 2011 23:08:14 +0000 (23:08 +0000)]
arm: fix io_* syscall entries

* linux/arm/syscallent.h: Fix handlers for io_setup, io_destroy,
io_getevents, io_submit and io_cancel.

12 years agoFix mincore syscall entries
Dmitry V. Levin [Sat, 26 Nov 2011 23:03:35 +0000 (23:03 +0000)]
Fix mincore syscall entries

* linux/arm/syscallent.h: Fix mincore handler.
* linux/avr32/syscallent.h: Likewise.
* linux/mips/syscallent.h: Likewise.
* linux/sh/syscallent.h: Likewise.
* linux/sh64/syscallent.h: Likewise.

12 years agoFix sendmsg syscall entries
Dmitry V. Levin [Fri, 25 Nov 2011 23:51:53 +0000 (23:51 +0000)]
Fix sendmsg syscall entries

* linux/arm/syscallent.h: Fix number of sendmsg arguments.
* linux/avr32/syscallent.h: Likewise.
* linux/bfin/syscallent.h: Likewise.
* linux/hppa/syscallent.h: Likewise.
* linux/i386/syscallent.h: Likewise.
* linux/m68k/syscallent.h: Likewise.
* linux/microblaze/syscallent.h: Likewise.
* linux/powerpc/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/tile/syscallent.h: Likewise.
* linux/x86_64/syscallent.h: Likewise.

12 years agoFix epoll_wait syscall entries
Dmitry V. Levin [Fri, 25 Nov 2011 23:45:28 +0000 (23:45 +0000)]
Fix epoll_wait syscall entries

* linux/arm/syscallent.h: Fix epoll_wait flags and handler.
* linux/m68k/syscallent.h: Fix epoll_wait flags.
* linux/microblaze/syscallent.h: Fix number of epoll_wait arguments.
* linux/sh/syscallent.h: Likewise.
* linux/sh64/syscallent.h: Likewise.
* linux/x86_64/syscallent.h: Likewise.

12 years agoFix epoll_ctl syscall entries
Dmitry V. Levin [Fri, 25 Nov 2011 23:40:16 +0000 (23:40 +0000)]
Fix epoll_ctl syscall entries

* linux/arm/syscallent.h: Fix epoll_ctl flags and handler.
* linux/m68k/syscallent.h: Fix epoll_ctl flags.
* linux/x86_64/syscallent.h: Fix number of epoll_ctl arguments.

12 years agoarm: fix epoll_create syscall entry
Dmitry V. Levin [Fri, 25 Nov 2011 23:34:12 +0000 (23:34 +0000)]
arm: fix epoll_create syscall entry

* linux/arm/syscallent.h: Fix epoll_create handler.

12 years agoFix mlockall syscall entries
Dmitry V. Levin [Fri, 25 Nov 2011 23:24:48 +0000 (23:24 +0000)]
Fix mlockall syscall entries

* linux/arm/syscallent.h: Fix number of mlockall arguments.
* linux/avr32/syscallent.h: Likewise.
* linux/bfin/syscallent.h: Likewise.
* linux/i386/syscallent.h: Likewise.
* linux/m68k/syscallent.h: Likewise.
* linux/microblaze/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/tile/syscallent.h: Likewise.
* linux/x86_64/syscallent.h: Likewise.

12 years agoFix epoll_pwait syscall entries
Dmitry V. Levin [Fri, 25 Nov 2011 23:19:47 +0000 (23:19 +0000)]
Fix epoll_pwait syscall entries

* linux/alpha/syscallent.h: Fix number of epoll_pwait arguments.
* linux/arm/syscallent.h: Likewise.
* linux/avr32/syscallent.h: Likewise.
* linux/bfin/syscallent.h: Likewise.
* linux/i386/syscallent.h: Likewise.
* linux/ia64/syscallent.h: Likewise.
* linux/m68k/syscallent.h: Likewise.
* linux/microblaze/syscallent.h: Likewise.
* linux/mips/syscallent.h: Likewise.
* linux/powerpc/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/tile/syscallent.h: Likewise.
* linux/x86_64/syscallent.h: Likewise.

12 years agoFix reboot syscall entries
Dmitry V. Levin [Fri, 25 Nov 2011 23:13:15 +0000 (23:13 +0000)]
Fix reboot syscall entries

* linux/alpha/syscallent.h: Fix number of reboot arguments.
* linux/arm/syscallent.h: Likewise.
* linux/avr32/syscallent.h: Likewise.
* linux/bfin/syscallent.h: Likewise.
* linux/hppa/syscallent.h: Likewise.
* linux/i386/syscallent.h: Likewise.
* linux/ia64/syscallent.h: Likewise.
* linux/m68k/syscallent.h: Likewise.
* linux/microblaze/syscallent.h: Likewise.
* linux/mips/syscallent.h: Likewise.
* linux/powerpc/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/tile/syscallent.h: Likewise.
* linux/x86_64/syscallent.h: Likewise.

12 years agoFix swapon syscall entries
Dmitry V. Levin [Fri, 25 Nov 2011 23:04:04 +0000 (23:04 +0000)]
Fix swapon syscall entries

* linux/arm/syscallent.h: Fix number of swapon arguments.
* linux/avr32/syscallent.h: Likewise.
* linux/bfin/syscallent.h: Likewise.
* linux/i386/syscallent.h: Likewise.
* linux/m68k/syscallent.h: Likewise.
* linux/microblaze/syscallent.h: Likewise.
* linux/mips/syscallent.h: Likewise.
* linux/powerpc/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/tile/syscallent.h: Likewise.
* linux/x86_64/syscallent.h: Likewise.
* linux/alpha/syscallent.h: Fix number of swapon arguments, add TF flag.
* linux/hppa/syscallent.h: Likewise.
* linux/ia64/syscallent.h: Likewise.

12 years agoFix sgetmask and ssetmask syscall entries
Dmitry V. Levin [Fri, 25 Nov 2011 21:57:31 +0000 (21:57 +0000)]
Fix sgetmask and ssetmask syscall entries

* linux/hppa/syscallent.h: Fix sgetmask and ssetmask entries.
* linux/powerpc/syscallent.h: Likewise.
* linux/sparc/syscallent.h: Likewise.
* linux/tile/syscallent.h: Likewise.

12 years agoRename siggetmask to sgetmask and sigsetmask to ssetmask
Dmitry V. Levin [Fri, 25 Nov 2011 21:43:01 +0000 (21:43 +0000)]
Rename siggetmask to sgetmask and sigsetmask to ssetmask

* linux/arm/syscallent.h: Rename siggetmask to sgetmask and
sigsetmask to ssetmask.
* linux/bfin/syscallent.h: Likewise.
* linux/i386/syscallent.h: Likewise.
* linux/m68k/syscallent.h: Likewise.
* linux/microblaze/syscallent.h: Likewise.
* linux/mips/syscallent.h: Likewise.
* linux/sh/syscallent.h: Likewise.
* linux/sh64/syscallent.h: Likewise.
* linux/ia64/syscallent.h: Rename sys_sgetmask to sys_siggetmask,
sys_ssetmask to sys_sigsetmask.

12 years agoAdd TRACE_IPC flag to sys_ipc syscall entries
Dmitry V. Levin [Fri, 25 Nov 2011 19:27:23 +0000 (19:27 +0000)]
Add TRACE_IPC flag to sys_ipc syscall entries

* linux/arm/syscallent.h: Add TI flag to sys_ipc entry.
* linux/avr32/syscallent.h: Likewise.
* linux/bfin/syscallent.h: Likewise.
* linux/i386/syscallent.h: Likewise.
* linux/m68k/syscallent.h: Likewise.
* linux/microblaze/syscallent.h: Likewise.
* linux/mips/syscallent.h: Likewise.
* linux/powerpc/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.

12 years agogitlog-to-changelog: update from gnulib
Dmitry V. Levin [Sat, 5 Nov 2011 13:32:27 +0000 (13:32 +0000)]
gitlog-to-changelog: update from gnulib

* gitlog-to-changelog: Update from gnulib.
* Makefile.am: Add --append-dot to gitlog-to-changelog invocation.

12 years agoDecode TIOCSCTTY's third parameter
Denys Vlasenko [Sat, 22 Oct 2011 02:52:18 +0000 (04:52 +0200)]
Decode TIOCSCTTY's third parameter

* term.c (term_ioctl): Decode TIOCSCTTY's third parameter.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
12 years agoRemove useless and obsolete "#if DONE" sections. No code changes
Dmitry V. Levin [Wed, 12 Oct 2011 23:22:06 +0000 (23:22 +0000)]
Remove useless and obsolete "#if DONE" sections.  No code changes

* linux/dummy.h: Remove "#if DONE" section.
* linux/sparc/dummy2.h: Likewise.
* linux/sparc64/dummy2.h: Likewise.
* sunos4/dummy.h: Likewise.
* svr4/dummy.h: Likewise.

12 years agoAdd names for dummy parsers. No code changes
Dmitry V. Levin [Wed, 12 Oct 2011 19:03:29 +0000 (19:03 +0000)]
Add names for dummy parsers.  No code changes

* linux/dummy.h: Add aliases to printargs() for those of dummy parsers
that had no own names before.
* linux/*/syscallent.h: Use these new names instead of printargs.

12 years agoSort definitions of dummy parsers. No code changes
Dmitry V. Levin [Wed, 12 Oct 2011 16:40:17 +0000 (16:40 +0000)]
Sort definitions of dummy parsers.  No code changes

* linux/dummy.h: Sort definitions of parsers implemented as aliases
to printargs().

12 years agosys_epoll_create1: decode flag arguments correctly
Mike Frysinger [Fri, 14 Oct 2011 02:33:45 +0000 (22:33 -0400)]
sys_epoll_create1: decode flag arguments correctly

* desc.c (epollflags): Define.
(sys_epoll_create1): Use epollflags to printflags. Change "O" to "EPOLL".

Reported-by: Марк Коренберг <socketpair@gmail.com>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
12 years agoImplement decoding of splice, tee and vmsplice(2) syscalls
Dmitry V. Levin [Tue, 11 Oct 2011 17:07:05 +0000 (17:07 +0000)]
Implement decoding of splice, tee and vmsplice(2) syscalls

* io.c (print_loff_t): New function.
(sys_sendfile64): Use it.
(splice_flags): New xlat structure.
(sys_tee, sys_splice, sys_vmsplice): New functions.
* linux/syscall.h (sys_tee, sys_splice, sys_vmsplice): Declare them.
* linux/*/syscallent.h: Use them.

12 years agoFix epoll_wait and epoll_pwait decoding
Dmitry V. Levin [Tue, 11 Oct 2011 16:05:57 +0000 (16:05 +0000)]
Fix epoll_wait and epoll_pwait decoding

* desc.c (epoll_wait_common): Print "maxevents" and "timeout" arguments
as integers.

Reported-by: Марк Коренберг <socketpair@gmail.com>
12 years agoDecode EPOLLRDHUP
Dmitry V. Levin [Tue, 11 Oct 2011 15:55:40 +0000 (15:55 +0000)]
Decode EPOLLRDHUP

* desc.c (epollevents): Add EPOLLRDHUP.

Reported-by: Марк Коренберг <socketpair@gmail.com>
12 years agoRemove unreachable code in umoven() and umovestr().
Dmitry V. Levin [Tue, 11 Oct 2011 15:26:15 +0000 (15:26 +0000)]
Remove unreachable code in umoven() and umovestr().

* util.c (umoven, umovestr): Remove unreachable code.

Reported-by: Weichuan Yan <wchyan@marvell.com>
12 years agoDo post-attach initialization earlier; fix "we ignore SIGSTOP on NOMMU" bug
Denys Vlasenko [Mon, 5 Sep 2011 12:05:46 +0000 (14:05 +0200)]
Do post-attach initialization earlier; fix "we ignore SIGSTOP on NOMMU" bug

We set ptrace options when we see post-attach SIGSTOP.
This is wrong: it's better to set them right away on the very first
stop (whichever it will be). It also will make adding SEIZE support easier,
since SEIZE has no post-attach SIGSTOP.

We do it by adding a new bit, TCB_IGNORE_ONE_SIGSTOP, and treating
TCB_STARTUP and TCB_IGNORE_ONE_SIGSTOP as two slightly different things.

* defs.h: Add a new flag bit, TCB_IGNORE_ONE_SIGSTOP.
* process.c (internal_fork): Set TCB_IGNORE_ONE_SIGSTOP on a newly added child.
* strace.c (startup_attach): Set TCB_IGNORE_ONE_SIGSTOP after attach.
Fix a case when "strace -p PID" found PID dead but sone other of its threads
still alive.
(startup_child): Set TCB_IGNORE_ONE_SIGSTOP after attach, _if needed_.
This fixes a bogus case where we can ignore a _real_ SIGSTOP on NOMMU.
(detach): Perform anti-SIGSTOP dance only if TCB_IGNORE_ONE_SIGSTOP is set,
not if TCB_STARTUP is set.
(trace): Set TCB_IGNORE_ONE_SIGSTOP after attach.
Clear TCB_STARTUP and initialize tracee on the very first tracee stop.
Clear TCB_IGNORE_ONE_SIGSTOP when SIGSTOP is seen.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
12 years agoGet rid of TCB_ATTACH_DONE
Denys Vlasenko [Mon, 5 Sep 2011 12:01:33 +0000 (14:01 +0200)]
Get rid of TCB_ATTACH_DONE

* defs.h: Remove TCB_ATTACH_DONE constant.
* strace.c (startup_attach): Use TCB_STARTUP instead of TCB_ATTACH_DONE
to distinquish attached from not-yet-attached threads.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
12 years agoSet TCB_STARTUP only _after_ we attached.
Denys Vlasenko [Mon, 5 Sep 2011 11:59:39 +0000 (13:59 +0200)]
Set TCB_STARTUP only _after_ we attached.

This fixes logic in detach() which thinks that TCB_STARTUP
means that we are already attached, but did not see SIGSTOP yet.
This also allows to get rid of TCB_ATTACH_DONE flag.

* process.c (internal_fork): Set TCB_STARTUP after attach.
* strace.c (startup_attach): Likewise.
(startup_child): Likewise.
(alloc_tcb): Do not set TCB_STARTUP on tcb allocation - we are
not attached yet.
(trace): Set TCB_STARTUP when we detech an auto-attached child.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
12 years agoSimple optimizations in trace()
Denys Vlasenko [Fri, 2 Sep 2011 14:23:53 +0000 (16:23 +0200)]
Simple optimizations in trace()

* strace.c (trace): Calculate WSTOPSIG(status) once,
unify code paths to ptrace(PTRACE_SYSCALL).

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
12 years agoTrivial fixes on error paths
Denys Vlasenko [Fri, 2 Sep 2011 14:19:30 +0000 (16:19 +0200)]
Trivial fixes on error paths

* strace.c (startup_attach): Emit message on fork() failure.
(startup_child): Remove non-informative comment.
* util.c (ptrace_restart): use perror_msg() on error instead of fprintf().

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
12 years agoFix compile failure introduced by last commit
Denys Vlasenko [Thu, 1 Sep 2011 16:18:04 +0000 (18:18 +0200)]
Fix compile failure introduced by last commit

* desc.c (decode_select): Fix double definition of nfds.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
12 years agoRoll back "die on malloc failure" behaviour a bit
Denys Vlasenko [Thu, 1 Sep 2011 14:35:44 +0000 (16:35 +0200)]
Roll back "die on malloc failure" behaviour a bit

After recent change, select(2^31-1, NULL, NULL, NULL)
would make strace exit. This change caps fdsize so that
it is always in [0, 1025*1024], IOW: we will try to allocate at most
1 megabyte, which in practice will almost always work,
unlike malloc(2Gig).

* desc.c (decode_select): Cap fdsize to 1024*1024.
* pathtrace.c (pathtrace_match): Cap fdsize to 1024*1024.
* file.c (sys_getdents): Cap len to 1024*1024.
(sys_getdents64): Cap len to 1024*1024.
* util.c (dumpiov): Refuse to process iov with more than 1024*1024
elements. Don't die on malloc failure.
(dumpstr): Don't die on malloc failure.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
12 years agoAdd stpcpy to autoconf machinery
Denys Vlasenko [Thu, 1 Sep 2011 14:31:48 +0000 (16:31 +0200)]
Add stpcpy to autoconf machinery

* configure.ac: Add stpcpy to AC_CHECK_FUNCS.
* defs.h: Frame stpcpy with "if !defined HAVE_STPCPY".
* util.c: Likewise.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
12 years agoSimplify sprinttv()
Denys Vlasenko [Thu, 1 Sep 2011 09:40:40 +0000 (11:40 +0200)]
Simplify sprinttv()

* time.c (sprinttv): Trivial simplifications.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
12 years ago* desc.c (decode_select): Set tcp->auxstr as late as possible.
Denys Vlasenko [Thu, 1 Sep 2011 09:27:37 +0000 (11:27 +0200)]
* desc.c (decode_select): Set tcp->auxstr as late as possible.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
12 years agoReformat setuid-ing code in startup_child()
Denys Vlasenko [Thu, 1 Sep 2011 08:27:42 +0000 (10:27 +0200)]
Reformat setuid-ing code in startup_child()

New code does the same as old one, but is more readable (I hope).

* strace.c (startup_child): Reformat setuid-ing code.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
12 years agoMinor tweaks in startup_child(). Logic isn't changed (but code is)
Denys Vlasenko [Thu, 1 Sep 2011 08:23:09 +0000 (10:23 +0200)]
Minor tweaks in startup_child(). Logic isn't changed (but code is)

* strace.c (startup_attach): Tweak comment.
(startup_child): Move common code out of ifdef.
Indent nested ifdefs. Tweak comments. Remove two
unnecessary calls to getpid().

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
12 years agoUse tprints with literal strings, it may be faster than tprintf
Denys Vlasenko [Thu, 1 Sep 2011 08:00:28 +0000 (10:00 +0200)]
Use tprints with literal strings, it may be faster than tprintf

* bjm.c: Replace tprintf("str") with tprints("str").
* block.c: Likewise.
* desc.c: Likewise.
* file.c: Likewise.
* io.c: Likewise.
* ipc.c: Likewise.
* mem.c: Likewise.
* net.c: Likewise.
* proc.c: Likewise.
* process.c: Likewise.
* quota.c: Likewise.
* resource.c: Likewise.
* scsi.c: Likewise.
* signal.c: Likewise.
* sock.c: Likewise.
* strace.c: Likewise.
* stream.c: Likewise.
* syscall.c: Likewise.
* system.c: Likewise.
* term.c: Likewise.
* time.c: Likewise.
* util.c: Likewise.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
12 years agoFix "format not a string literal" warning caused by tprintf(str)
Denys Vlasenko [Thu, 1 Sep 2011 07:55:05 +0000 (09:55 +0200)]
Fix "format not a string literal" warning caused by tprintf(str)

* defs.h: Declare tprints().
* strace.c: Define tprints().
(tabto): Use tprints(str), since tprintf(str) was throwing a warning.
* desc.c: Use tprints(str) instead of tprintf("%s", str).
* file.c: Likewise.
* io.c: Likewise.
* net.c: Likewise.
* process.c: Likewise.
* signal.c: Likewise.
* syscall.c: Likewise.
* util.c: Likewise.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
12 years agoAdd README-linux-ptrace file
Denys Vlasenko [Wed, 31 Aug 2011 13:58:06 +0000 (15:58 +0200)]
Add README-linux-ptrace file

I tried to push this doc to Michael Kerrisk <mtk.manpages@gmail.com>,
but got no reply. To avoid losing the document, let it live
in strace tree for now.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
12 years agoMake out-of-memory handling more uniform
Denys Vlasenko [Wed, 31 Aug 2011 12:00:02 +0000 (14:00 +0200)]
Make out-of-memory handling more uniform

This fixes one real bug in dumpstr().

* defs.h: Declare die_out_of_memory().
* strace.c (die_out_of_memory): New function.
(strace_popen): If allocation fails, call die_out_of_memory().
(main): Likewise.
(expand_tcbtab): Likewise.
(rebuild_pollv): Likewise.
* count.c (count_syscall): Likewise.
(call_summary_pers): Likewise.
* desc.c (decode_select): Likewise.
* file.c (sys_getdents): Likewise.
(sys_getdents64): Likewise.
(sys_getdirentries): Likewise.
* pathtrace.c (pathtrace_match): Likewise.
* syscall.c (qualify): Likewise.
* util.c (printstr): Likewise.
(dumpiov): Likewise.
(dumpstr): Likewise.
(fixvfork): Likewise.
* mem.c (sys_mincore): Don't check free() parameter for NULL.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
12 years agoOptimization: eliminate all remaining usages of strcat()
Denys Vlasenko [Wed, 31 Aug 2011 10:26:03 +0000 (12:26 +0200)]
Optimization: eliminate all remaining usages of strcat()

After this change, we don't use strcat() anywhere.

* defs.h: Change sprinttv() return type to char *.
* time.c (sprinttv): Return pointer past last stored char.
* desc.c (decode_select): Change printing logic in order to eliminate
usage of strcat() - use stpcpy(), *outptr++ = ch, sprintf() instead.
Also reduce usage of strlen().
* stream.c (decode_poll): Likewise.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
12 years agoOptimize string_quote() for speed
Denys Vlasenko [Wed, 31 Aug 2011 10:22:56 +0000 (12:22 +0200)]
Optimize string_quote() for speed

* util.c (string_quote): Speed up check for terminating NUL.
Replace strintf() with open-coded binary to hex/oct conversions -
we potentially do them for every single byte, need to be fast.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
12 years agoOptimization: eliminate some usages of strcat()
Denys Vlasenko [Wed, 31 Aug 2011 10:07:38 +0000 (12:07 +0200)]
Optimization: eliminate some usages of strcat()

* defs.h: Declare stpcpy().
* util.c: Define stpcpy().
* file.c: Remove static str_append().
(sprint_open_modes): Use stpcpy() instead of str_append().
(sprintflags): Use stpcpy() instead of strcat().
(printpathn): Eliminate usage of strcat().
(printstr): Eliminate usage of strcat().

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
12 years agoSmall optimization on AVR32
Denys Vlasenko [Tue, 30 Aug 2011 17:04:54 +0000 (19:04 +0200)]
Small optimization on AVR32

* syscall.c (syscall_enter): Optimize tcp->u_arg[i] setting
from regs.FOO for AVR32.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
12 years agoOn X86_64 and I386, use PTRACE_GETREGS to fetch all registers
Denys Vlasenko [Tue, 30 Aug 2011 16:53:49 +0000 (18:53 +0200)]
On X86_64 and I386, use PTRACE_GETREGS to fetch all registers

Before this change, registers were read with PTRACE_PEEKUSER
ptrace operation, one per register. This is slower than
fetching them all in one ptrace operation.

* defs.h: include asm/ptrace.h on X86_64 and I386.
* syscall.c: New static variables i386_regs and x86_64_regs.
Remove static eax/rax variables.
(get_scno): Fetch all registers with single PTRACE_GETREGS operation.
(get_syscall_result): Likewise.
(syscall_fixup_on_sysenter): Use PTRACE_GETREGS results in i386/x86_64_regs.
(syscall_enter): Set tcp->u_arg[i] from PTRACE_GETREGS results.
(get_error): Set tcp->u_rval, tcp->u_error from PTRACE_GETREGS results.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
12 years agoDo not include <limits.h>
Dmitry V. Levin [Tue, 30 Aug 2011 16:07:01 +0000 (16:07 +0000)]
Do not include <limits.h>

* strace.c: Do not include <limits.h> explicitly, it is already included
implicitly by <sys/param.h>.

12 years agoInclude <sys/param.h> to get PATH_MAX definition
Dmitry V. Levin [Tue, 30 Aug 2011 16:05:26 +0000 (16:05 +0000)]
Include <sys/param.h> to get PATH_MAX definition

* pathtrace.c: Include <sys/param.h> instead of <limits.h> to get
PATH_MAX definition.

Reported-by: Steve Bennett <steveb@workware.net.au>
12 years agoIndent a large set of nested ifdefs/endifs. No code changes
Denys Vlasenko [Fri, 26 Aug 2011 17:25:09 +0000 (19:25 +0200)]
Indent a large set of nested ifdefs/endifs. No code changes

* defs.h: Indent a large set of nested ifdefs/endifs

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
12 years agoRename syscall_fixup to syscall_fixup_on_sysenter
Denys Vlasenko [Thu, 25 Aug 2011 08:40:14 +0000 (10:40 +0200)]
Rename syscall_fixup to syscall_fixup_on_sysenter

* defs.h: Tweak comment.
* syscall.c: Rename syscall_fixup to syscall_fixup_on_sysenter.
(trace_syscall_entering): Use new finction name.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
12 years agoMake syscall result reading more consistent among different arches
Denys Vlasenko [Thu, 25 Aug 2011 08:31:24 +0000 (10:31 +0200)]
Make syscall result reading more consistent among different arches

* syscall.c: Eliminate static flags variable for POWERPC.
(syscall_fixup): Don't fetch syscall results. Affected arches:
POWERPC, BFIN, HPPA.
(syscall_fixup_on_sysexit): Move syscall results fetching code
for this function to get_syscall_result. Affected arches:
S390X, POWERPC, BFIN, M68K, HPPA, CRIS, MICROBLAZE.
(get_syscall_result): Add syscall results fetching.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
12 years agoSimplify syscall_fixup[_on_sysexit]
Denys Vlasenko [Thu, 25 Aug 2011 08:25:35 +0000 (10:25 +0200)]
Simplify syscall_fixup[_on_sysexit]

* syscall.c (syscall_fixup): Remove checks for entering(tcp).
Remove code which executes if exiting(tcp).
(syscall_fixup_on_sysexit): Remove code which executes
if entering(tcp). Remove checks for exiting(tcp).

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
12 years agoSplit syscall_fixup into enter/exit pair of functions
Denys Vlasenko [Thu, 25 Aug 2011 08:23:00 +0000 (10:23 +0200)]
Split syscall_fixup into enter/exit pair of functions

* syscall.c: Create syscall_fixup_on_sysexit() which is a copy of
syscall_fixup().
(trace_syscall_exiting): Call syscall_fixup_on_sysexit() instead of
syscall_fixup().

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
12 years agoRemove stray commas in struct initializers. No code changes
Denys Vlasenko [Thu, 25 Aug 2011 08:21:13 +0000 (10:21 +0200)]
Remove stray commas in struct initializers. No code changes

* process.c: Remove stray commas in struct initializers.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
12 years agoOptimize tabto()
Denys Vlasenko [Wed, 24 Aug 2011 23:27:59 +0000 (01:27 +0200)]
Optimize tabto()

tabto is used in many lines of strace output.
On glibc, tprintf("%*s", col - curcol, "") is noticeably slow
compared to tprintf("                 "). Use the latter.
Observed ~15% reduction of time spent in userspace.

* defs.h: Drop extern declaration of acolumn. Make tabto()
take no parameters.
* process.c (sys_exit): Call tabto() with no parameters.
* syscall.c (trace_syscall_exiting): Call tabto() with no parameters.
* strace.c: Make acolumn static, add static char *acolumn_spaces.
(main): Allocate acolumn_spaces as a string of spaces.
(printleader): Call tabto() with no parameters.
(tabto): Use simpler method to print lots of spaces.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
12 years ago* syscall.c (sys_indir): Use %ld for printing long, not %u.
Denys Vlasenko [Wed, 24 Aug 2011 23:23:10 +0000 (01:23 +0200)]
* syscall.c (sys_indir): Use %ld for printing long, not %u.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
12 years agoOpotimize "scno >= 0 && scno < nsyscalls" check
Denys Vlasenko [Wed, 24 Aug 2011 23:13:43 +0000 (01:13 +0200)]
Opotimize "scno >= 0 && scno < nsyscalls" check

gcc can't figure out on its own that this check can be done with
single compare, and does two compares. We can help it by casting
scno to unsigned long: ((unsigned long)(scno) < nsyscalls)

* defs.h: New macro SCNO_IN_RANGE(long_var).
* count.c (count_syscall): Use SCNO_IN_RANGE() instead of open-coded check.
* syscall.c (getrval2): Use SCNO_IN_RANGE() instead of open-coded check.
This fixes a bug: missing check for scno < 0 and scno > nsyscalls
instead of scno >= nsyscalls.
(get_scno): Use SCNO_IN_RANGE() instead of open-coded check.
This fixes a bug: scno > nsyscalls instead of scno >= nsyscalls.
(known_scno): Use SCNO_IN_RANGE() instead of open-coded check.
(internal_syscall): Likewise.
(syscall_enter): Likewise.
(trace_syscall_entering): Likewise.
(get_error): Likewise.
(trace_syscall_exiting): Likewise.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
12 years agoRemove scno_good logic in syscall exit
Denys Vlasenko [Wed, 24 Aug 2011 22:29:56 +0000 (00:29 +0200)]
Remove scno_good logic in syscall exit

* syscall.c (trace_syscall_exiting): Remove scno_good logic,
it can't trigger in syscall exit.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
12 years agoRemove redundant assignments
Denys Vlasenko [Wed, 24 Aug 2011 22:26:38 +0000 (00:26 +0200)]
Remove redundant assignments

* syscall.c (get_error): Remove redundant "u_error = 0" and redundant
and unclear comments.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
12 years agoGroup int-sized fields together in struct tcb
Denys Vlasenko [Wed, 24 Aug 2011 22:25:08 +0000 (00:25 +0200)]
Group int-sized fields together in struct tcb

* defs.h: Group int-sized fields together in struct tcb.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
12 years agoReorder functions in syscall.c. No code changes.
Denys Vlasenko [Wed, 24 Aug 2011 16:07:22 +0000 (18:07 +0200)]
Reorder functions in syscall.c. No code changes.

Old order (basically "in no particular order"):
    dumpio
    decode_subcall
    internal_syscall
    get_scno
    get_syscall_result
    known_scno
    syscall_fixup
    is_negated_errno
    get_error
    syscall_enter
    trace_syscall_entering
    trace_syscall_exiting
    trace_syscall
    printargs
    getrval2
    sys_indir
    is_restart_error

New order:
various utility functions:
    decode_subcall
    printargs
    getrval2
    sys_indir
    is_restart_error
syscall enter handling functions:
    get_scno
    known_scno
    syscall_fixup (also used in syscall exit code)
    internal_syscall (also used in syscall exit code)
    syscall_enter
    trace_syscall_entering
syscall exit handling functions:
    get_syscall_result
    is_negated_errno
    get_error
    dumpio
    trace_syscall_exiting
main syscall enter/exit function:
    trace_syscall

* syscall.c: Reorder functions so that related ones are closer
in the source.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
12 years agoRename some functions, delete unused one. No code changes
Denys Vlasenko [Wed, 24 Aug 2011 15:53:52 +0000 (17:53 +0200)]
Rename some functions, delete unused one. No code changes

* defs.h: Rename get_scno_on_sysenter() to get_scno();
delete force_result() declaration.
* strace.c (proc_open): Rename get_scno_on_sysenter() to get_scno().
* syscall.c: Rename get_scno_on_sysenter() to get_scno().
Rename get_scno_on_sysexit() to get_syscall_result().
Delete unused force_result().

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
12 years agoUnify per-architecture post-execve SIGTRAP check.
Denys Vlasenko [Wed, 24 Aug 2011 15:25:32 +0000 (17:25 +0200)]
Unify per-architecture post-execve SIGTRAP check.

Move post-execve SIGTRAP check from get_scno_on_sysenter
(multitude of places on many architectures) to a single location
in trace_syscall_entering. This loosens the logic for some arches,
since many of them had additional checks such as scno == 0.
However, on non-ancient Linux kernels we should never have post-execve
SIGTRAP in the first place, by virtue of using PTRACE_O_TRACEEXEC.

* syscall.c (get_scno_on_sysenter): Remove tcp->flags & TCB_WAITEXECVE checks.
(trace_syscall_entering): Do tcp->flags & TCB_WAITEXECVE check here.
(get_scno_on_sysexit): Tweak comment.
(syscall_fixup): Likewise.
(trace_syscall_exiting): Likewise.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>