]> granicus.if.org Git - strace/log
strace
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>
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>