]> granicus.if.org Git - strace/log
strace
10 years agoUse struct sigcontext instead of struct sigcontext_struct
Dmitry V. Levin [Tue, 12 Nov 2013 15:27:38 +0000 (15:27 +0000)]
Use struct sigcontext instead of struct sigcontext_struct

* configure.ac (AC_CHECK_TYPES): Remove struct sigcontext_struct.
* signal.c (sys_sigreturn) [S390 || S390X || POWERPC || ALPHA): Replace
struct sigcontext_struct with struct sigcontext.

Reported by John Spencer.

10 years agoUse standard names of sched_param structure members
Dmitry V. Levin [Tue, 12 Nov 2013 15:09:56 +0000 (15:09 +0000)]
Use standard names of sched_param structure members

* process.c (sys_sched_setscheduler, sys_sched_getparam,
sys_sched_setparam): Use portable struct sched_param member name
sched_priority instead of glibc specific __sched_priority.

Reported by John Spencer.

10 years agoMake SIGEV_THREAD_ID decoding less glibc specific
Dmitry V. Levin [Mon, 11 Nov 2013 23:54:30 +0000 (23:54 +0000)]
Make SIGEV_THREAD_ID decoding less glibc specific

SIGEV_THREAD_ID decoding requires access to an internal member of
struct sigevent.  There seems to be no portable way to do it besides
adding a configure check.

* configure.ac (AC_CHECK_MEMBERS): Check for
struct sigevent._sigev_un._pad and struct sigevent.__pad.
* time.c (printsigevent): Use an appropriate struct sigevent member
to print thread id.

Reported by John Spencer.

10 years agoRemove unused configure checks
Dmitry V. Levin [Mon, 11 Nov 2013 15:59:49 +0000 (15:59 +0000)]
Remove unused configure checks

* configure.ac (AC_CHECK_MEMBERS): Remove T_conn_res.QUEUE_ptr,
T_conn_res.ACCEPTOR_id, dqblk.dqb_curblocks, sigcontext.sc_hi2.

10 years agoAssume "long long" availability
Dmitry V. Levin [Mon, 11 Nov 2013 15:52:37 +0000 (15:52 +0000)]
Assume "long long" availability

Most of the code already uses long long types unconditionally.

* configure.ac: Remove the check for long long.
* file.c (printstat64): Remove HAVE_LONG_LONG checks, use %llu format
string unconditionally.

10 years agoInclude <sys/poll.h> only if there is no <poll.h>
Dmitry V. Levin [Wed, 6 Nov 2013 01:17:05 +0000 (01:17 +0000)]
Include <sys/poll.h> only if there is no <poll.h>

* pathtrace.c: Do not include <sys/poll.h> if <poll.h> is available.
* stream.c: Likewise.

10 years agoMove io_* syscalls decoding to a separate file
Dmitry V. Levin [Mon, 11 Nov 2013 15:06:18 +0000 (15:06 +0000)]
Move io_* syscalls decoding to a separate file

* desc.c (sys_io_setup, sys_io_destroy, sys_io_submit, sys_io_cancel,
sys_io_getevents, declarations from libaio.h): Move to ...
* aio.c: new file.
* Makefile.am (strace_SOURCES): Add aio.c.

10 years agoStop using external libaio.h.
Denys Vlasenko [Mon, 11 Nov 2013 11:50:47 +0000 (12:50 +0100)]
Stop using external libaio.h.

This change incorporates a partial copy instead
of using external libaio.h.
Why?
Because we want to properly decode 32-bit aio calls
by 64-bit strace. For that, we need more definitions than
libaio.h provides.
(These defs are not done yet, but will eventually be done).
Keeping our local 32-bit compat defs in sync with libaio.h
_without seeing libaio structs_ is hard/more bug prone.
A smaller benefit is that we don't need libaio installed.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
10 years agosys_io_submit: simplify iocb_cmd_lookup() helper.
Denys Vlasenko [Mon, 11 Nov 2013 11:31:18 +0000 (12:31 +0100)]
sys_io_submit: simplify iocb_cmd_lookup() helper.

This helper returns two values (a string and an enum).
The caller prints the string. It's simpler to just print
the string in the caller itself. This eliminates
"return by reference" and more importantly, an intermediate
static string buffer for the string result.

Since function of the helper is different now,
it is renamed to tprint_lio_opcode().

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
10 years agosys_io_submit: stop traversing iocb vector after first failure.
Denys Vlasenko [Mon, 11 Nov 2013 11:24:29 +0000 (12:24 +0100)]
sys_io_submit: stop traversing iocb vector after first failure.

The program may use a very large nr but supply either outright
invalid iocbpp[], or one with far fewer elements than nr.
We used to try reading iocbpp[i] until i == nr.
With this change, we stop on the first failure.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
11 years agoFix pathtrace_match() to match recent fixes to select decoding.
Denys Vlasenko [Sat, 9 Nov 2013 19:46:55 +0000 (20:46 +0100)]
Fix pathtrace_match() to match recent fixes to select decoding.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
11 years agoFix select decoding on e.g. 32-bit ppc process by 64-bit strace.
Denys Vlasenko [Sat, 9 Nov 2013 19:40:31 +0000 (20:40 +0100)]
Fix select decoding on e.g. 32-bit ppc process by 64-bit strace.

Added next_set_bit() function which finds the next set bit,
properly taking into account word size of the traced process.
Use it in decode_select() instead of fd_isset().
Also, properly round fdsize up to word size of traced process,
not to strace's word size.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
11 years agoSpeed up and explain fd_isset()
Denys Vlasenko [Wed, 6 Nov 2013 10:34:02 +0000 (11:34 +0100)]
Speed up and explain fd_isset()

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
11 years agoAdd a test for the latest select decoding fix
Dr. David Alan Gilbert [Tue, 5 Nov 2013 23:28:56 +0000 (23:28 +0000)]
Add a test for the latest select decoding fix

* test/select.c (main): Add a test for nfds larger than FD_SETSIZE.

11 years agoFix select decoding for glibc in _FORTIFY_SOURCE mode
Dmitry V. Levin [Tue, 5 Nov 2013 23:00:22 +0000 (23:00 +0000)]
Fix select decoding for glibc in _FORTIFY_SOURCE mode

glibc in _FORTIFY_SOURCE mode raises SIGABRT when descriptor greater
or equal to FD_SETSIZE is passed to FD_ISSET.  Select family syscalls,
however, can legitimately accept such descriptors.  To overcome this
limitation, we have to replace FD_ISSET with an equivalent that imposes
no such restrictions.

* desc.c (fd_isset): New function.
(decode_select): Use it instead of FD_ISSET.

11 years agoMore select decoding fixes
Dmitry V. Levin [Tue, 5 Nov 2013 22:46:43 +0000 (22:46 +0000)]
More select decoding fixes

* desc.c (decode_select): Actually print arg[0] as int on entering
syscall.  When arg[0] is negative, do not attempt to fetch and decode
descriptor sets on entering syscall, kernel will reject it anyway.
On exiting syscall, stop checking descriptor sets as soon as all
returned descriptors are found.

11 years agoTruncate arg[0] to int in select decoding.
Denys Vlasenko [Tue, 5 Nov 2013 15:20:16 +0000 (16:20 +0100)]
Truncate arg[0] to int in select decoding.

This matches kernel's behavior.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
11 years agotest/select.c: make comment more understandable.
Denys Vlasenko [Tue, 5 Nov 2013 11:44:55 +0000 (12:44 +0100)]
test/select.c: make comment more understandable.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
11 years agoFix select decoding with bogus (huge or negative) nfds.
Dr. David Alan Gilbert [Tue, 5 Nov 2013 10:54:51 +0000 (11:54 +0100)]
Fix select decoding with bogus (huge or negative) nfds.

We used to allocate and fetch bit arrays using a sanitized
length, but then iterate over them with "j < arg[0]" condition,
where arg[0] is not sanitized. This segfaults if arg[0] is huge
or negative. This change fixes this.

Add test/select.c to capture the case.

Signed-off-by: Dr. David Alan Gilbert <dave@treblig.org>
Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
11 years agoWork around conflict between <sys/ptrace.h> and <linux/ptrace.h>
Ali Polatel [Tue, 24 Sep 2013 17:04:32 +0000 (20:04 +0300)]
Work around conflict between <sys/ptrace.h> and <linux/ptrace.h>

Since glibc-2.18~39 <sys/ptrace.h> defines ptrace_peeksiginfo_args
which collides with <linux/ptrace.h>.

* configure.ac: Check for `struct ptrace_peeksiginfo_args' in
<sys/ptrace.h>.
* process.c: Work around potential conflict between <sys/ptrace.h>
and <linux/ptrace.h> by redefining ptrace_peeksiginfo_args.
* signal.c: Likewise.
* syscall.c: Likewise.
* util.c: Likewise.

Signed-off-by: Ali Polatel <alip@exherbo.org>
11 years agoAdd support for ARC Cores from Synopsys
Vineet Gupta [Fri, 16 Aug 2013 07:17:06 +0000 (12:47 +0530)]
Add support for ARC Cores from Synopsys

Take #2 on mainlining strace support for ARC (last one was 4.6 based back
in March 2011), see
http://sourceforge.net/p/strace/mailman/message/27210168/

The syscall ABI is asm-generic/unistd.h based (so no legacy syscalls),
hence very similar to metag port.

test/* all seem to work well.

* linux/arc/ioctlent.h.in: New file.
* linux/arc/syscallent.h: Likewise.
* Makefile.am (EXTRA_DIST): Add linux/arc/ioctlent.h.in and
linux/arc/syscallent.h.
* configure.ac: Add ARC to the list of supported architectures.
* defs.h: Add ARC support.
* process.c (struct_user_offsets): Likewise.
* signal.c (sys_sigreturn): Likewise.
* syscall.c (print_pc, get_regset, get_regs, get_scno, get_syscall_args,
get_syscall_result, get_error): Likewise.
* util.c (change_syscall): Likewise.

Signed-off-by: Vineet Gupta <vgupta@synopsys.com>
Acked-by: Mike Frysinger <vapier@gentoo.org>
11 years agoAdd support for decoding sync_file_range
William Manley [Fri, 9 Aug 2013 17:04:11 +0000 (18:04 +0100)]
Add support for decoding sync_file_range

* file.c (sync_file_range_flags): New xlat structure.
(sys_sync_file_range, sys_sync_file_range2): New functions.
* linux/syscall.h (sys_sync_file_range, sys_sync_file_range2): New
prototypes.
* linux/dummy.h (sys_sync_file_range, sys_sync_file_range2): Remove.
* linux/mips/syscallent-o32.h: Set the number of sync_file_range
arguments to 7.

11 years agofanotify_mark: fix number of args for 32bit arches
Mike Frysinger [Mon, 19 Aug 2013 05:00:39 +0000 (01:00 -0400)]
fanotify_mark: fix number of args for 32bit arches

The fanotify_mark func takes a 64bit mask, so 32bit arches have to split
it up into two fields.  When the syscall was added, it was listed as only
having 5 fields total (since that's correct for 64bit systems).

* linux/arm/syscallent.h: Set the number of fanotify_mark arguments to 6.
* linux/bfin/syscallent.h: Likewise.
* linux/hppa/syscallent.h: Likewise.
* linux/i386/syscallent.h: Likewise.
* linux/m68k/syscallent.h: Likewise.
* linux/metag/syscallent.h: Likewise.
* linux/microblaze/syscallent.h: Likewise.
* linux/mips/syscallent-o32.h: Likewise.
* linux/or1k/syscallent.h: Likewise.
* linux/powerpc/syscallent.h: Likewise.
* linux/s390/syscallent.h: Likewise.
* linux/sh/syscallent.h: Likewise.
* linux/sparc/syscallent.h: Likewise.
* linux/tile/syscallent1.h: Likewise.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Acked-by: Chris Metcalf <cmetcalf@tilera.com> [for tile]
11 years agox86, x86_64: fix compilation warnings
Dmitry V. Levin [Wed, 11 Sep 2013 13:26:17 +0000 (13:26 +0000)]
x86, x86_64: fix compilation warnings

Fix "dereferencing type-punned pointer will break strict-aliasing rules"
warnings introduced by commit v4.8-52-gb51f364.

* signal.c (sys_sigreturn): Avoid dereferencing type-punned pointers.

11 years agoRemove rt parameter from [s]printsigmask()
Denys Vlasenko [Thu, 18 Jul 2013 18:42:41 +0000 (20:42 +0200)]
Remove rt parameter from [s]printsigmask()

In almost all cases, the parameter was 1 ("decode RT sigs too").
This change hardwires it to be 1.

The cases where it was 0 are, and why the change to "decode RT sigs too"
is fine:

IA64: 64-bit arch, all 64 signals fit in one word in any case.
S390[x]: sc.oldmask is a sigset_t on kernel side,
(sigset_t *)&sc.oldmask[0] does contain all 64 signals.
TILE: uc.uc_sigmask is a sigset_t on kernel side,
memcpy(&sigm, &uc.uc_sigmask, NSIG / 8) copies all 64 signals.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
11 years agoConvert some uses of long_to_sigmask+printsigmask to sprintsigmask_long
Denys Vlasenko [Thu, 18 Jul 2013 18:37:06 +0000 (20:37 +0200)]
Convert some uses of long_to_sigmask+printsigmask to sprintsigmask_long

This allows to drop long_to_sigmask function,
and a whole bunch of sigset_t variables.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
11 years agoSimplify some sigmask manipulations
Denys Vlasenko [Thu, 18 Jul 2013 18:12:33 +0000 (20:12 +0200)]
Simplify some sigmask manipulations

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
11 years agoAdd compat support for sys_pselect6
Denys Vlasenko [Thu, 18 Jul 2013 16:10:13 +0000 (18:10 +0200)]
Add compat support for sys_pselect6

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
11 years agoI386: fix signedness mismatch warning
Denys Vlasenko [Thu, 18 Jul 2013 15:40:45 +0000 (17:40 +0200)]
I386: fix signedness mismatch warning

&i386_regs.esp is a pointer to long, not unsigned long.
It needs a cast.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
11 years agoFix sigset printing via print_sigset().
Denys Vlasenko [Thu, 18 Jul 2013 15:02:21 +0000 (17:02 +0200)]
Fix sigset printing via print_sigset().

Replace print_sigset() with print_sigset_addr_len(),
which takes not only addr, but also len parameter.
This allows us to drop "do we need to print RT signals?" parameter,
and this fixes RT signals printing in many syscalls.

sys_epoll_pwait: print RT signals too, print sigmask size argument.

sys_sigprocmask: print_sigset -> print_sigset_addr_len(current_wordsize),
no change in functionality.

sys_sigpending: use print_sigset_addr_len(current_wordsize)
instead of open-coding it.

sys_rt_sigprocmask: use print_sigset_addr_len instead of open-coding it.
sys_rt_sigpending: ditto.
sys_rt_sigsuspend: ditto.
sys_rt_sigtimedwait: ditto.

do_signalfd: print_sigset -> print_sigset_addr_len. This fixes
RT signals printing (wasn't showing them before).

sys_ppoll: ditto.

copy_sigset_len() is folded into its only user, print_sigset_addr_len(),
and copy_sigset() is gone.

While at it, checked kernel sources and noted where kernel enforces
sigset_size == NSIG / 8 (== sizeof(kernel_sigset_t)),
and where it allows word-sized sigset_size ([rt_]sigpending).

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
11 years agosys_rt_sigaction: fix sigset copying
Denys Vlasenko [Thu, 18 Jul 2013 08:10:46 +0000 (10:10 +0200)]
sys_rt_sigaction: fix sigset copying

In practice, we always copy as many bytes as syscall param says
(8, or 16 on mips). However, malicious program can call sigaction
with wrong sigset size. Such syscall will result in EINVAL,
but we (strace) end up copying 128 bytes (sizeof(sigset_t)),
which copyes some garbage from stack after struct sigaction.

Now we always copy NSIG / 8 bytes (which is 8 bytes, or 16 on mips).

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
11 years agoARM: remove wrong NSIG = 32 define
Denys Vlasenko [Thu, 18 Jul 2013 07:41:20 +0000 (09:41 +0200)]
ARM: remove wrong NSIG = 32 define

ARM in fact has 64 signals (1..64), and NSIG should be 65
(as usual, rememebr that NSIG_libc == NSIG_kernel+1).

I carefully reviewed all usages of NSIG. In syscall.c,
the only usage is:
        for (i = 0; i <= NSIG; i++)
                if (strcasecmp(s, signame(i) + 3) == 0)...
which is safe even if NSIG is way too big - signame(i)
returns a well-formed string for any i.

In signal.c, memcpy(&sigset, &sc.sc_mask, NSIG / 8) is used by
IA64 and TILE code, so ARM change can't affect it. And final
usage is:
 struct new_sigaction::unsigned long sa_mask[NSIG / sizeof(long)];
It will grow on ARM (and become correct in the process).
Its only use is
 memcpy(&sigset, &sa.sa_mask, NSIG / 8);
 printsigmask(&sigset, 1);
which used to copy garbage in high bits, now it will copy actual data.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
11 years agoARM: fix sigreturn decoding
Denys Vlasenko [Wed, 17 Jul 2013 15:26:56 +0000 (17:26 +0200)]
ARM: fix sigreturn decoding

Decoding of test/sigreturn testcase:
Was:
sigreturn() (mask [QUIT TRAP ABRT BUS SEGV USR2 PIPE STKFLT STOP XCPU VTALRM PROF WINCH IO PWR RTMIN]) = 0
Now:
sigreturn() (mask [CHLD RT_1 RT_3 RT_31 RT_32]) = 0

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
11 years agoGroup USE_CUSTOM_PRINTF define with other tweakables
Denys Vlasenko [Tue, 16 Jul 2013 10:18:59 +0000 (12:18 +0200)]
Group USE_CUSTOM_PRINTF define with other tweakables

No code changes.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
11 years agoImprove sigreturn decoding on x86 to show RT signal bits too.
Denys Vlasenko [Tue, 16 Jul 2013 10:06:25 +0000 (12:06 +0200)]
Improve sigreturn decoding on x86 to show RT signal bits too.

This includes decoding of 32-bit sigreturn by 64-bit strace,
which previously wasn't done.

Added a test for it.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
11 years agopowerpc: enhance 32/64bit detection
Anton Blanchard [Thu, 11 Jul 2013 02:03:57 +0000 (12:03 +1000)]
powerpc: enhance 32/64bit detection

We were using uname to determine if userspace was 32 or 64bit.
This fails when we have a 64bit kernel and a 32bit userspace.

* configure.ac (powerpc*): Similar to x86, use a runtime test
to determine if we are 32 or 64bit.

Signed-off-by: Anton Blanchard <anton@samba.org>
11 years agopowerpc: fix some compiler warnings
Anton Blanchard [Fri, 12 Jul 2013 10:24:02 +0000 (12:24 +0200)]
powerpc: fix some compiler warnings

Fix a number of differing signedness warnings when building on
powerpc.

Signed-off-by: Anton Blanchard <anton@samba.org>
Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
11 years agopowerpc: fix iflag build issue (static -> extern)
Anton Blanchard [Fri, 12 Jul 2013 10:22:06 +0000 (12:22 +0200)]
powerpc: fix iflag build issue (static -> extern)

Signed-off-by: Anton Blanchard <anton@samba.org>
Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
11 years agoPTRACE_SEIZE can set ptrace options immediately, use this feature
Denys Vlasenko [Wed, 10 Jul 2013 12:33:05 +0000 (14:33 +0200)]
PTRACE_SEIZE can set ptrace options immediately, use this feature

This eliminates some rare bugs, such as post-execve SIGTRAP
generation when we attach to a process, and it manages to finish
execve'ing before we set TRACEEXEC option to suppress that.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
11 years agoIf -o|logger is in use, exit trace loop if nprocs == 0.
Denys Vlasenko [Mon, 8 Jul 2013 11:55:04 +0000 (13:55 +0200)]
If -o|logger is in use, exit trace loop if nprocs == 0.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
11 years agoExit trace loop if got ECHILD, not if nprocs == 0.
Denys Vlasenko [Mon, 8 Jul 2013 09:28:27 +0000 (11:28 +0200)]
Exit trace loop if got ECHILD, not if nprocs == 0.

Comment gives a testcase which wasn't handled correctly
by the old code.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
11 years agos390[x]: get rid of syscall_mode, delete code which never triggers
Denys Vlasenko [Sun, 7 Jul 2013 10:47:39 +0000 (12:47 +0200)]
s390[x]: get rid of syscall_mode, delete code which never triggers

Before this change, the logic was as follows:
syscall entry:
  get_scno:
    syscall_mode = GPR2
    scno = syscall_mode unless syscall_mode == -ENOSYS
    (if -ENOSYS, scn is retrieved by decoding current insn)
  fixup:
    gpr2 = GPR2
    syscall_mode = scno unless syscall_mode == -ENOSYS
    if (gpr2 != syscall_mode) stray_entry
syscall exit:
  get_res:
    gpr2 = GRP2
  fixup:
    syscall_mode = scno unless syscall_mode == -ENOSYS
    if (WAITEXECVE && gpr2 in (-ENOSYS, scno)) gpr2 = 0;
  get_error:
    gpr2 is retval

Entry fixup's if() can never trigger:
regardless whether GPR2 is -ENOSYS or not, syscall_mode is always
equal to GRP2 value there. So it can be removed.

On sysexit path, syscall mode is never used.

Therefore, syscall_mode variable is deleted. grp2 is read from
GPR2 register in get_scno, redundant read in entry fixup is removed.
As a result, entry fixup's s390 code block vanishes completely.

gpr2 variable is renamed s390_gpr2 to match the convention used
by other arches.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
11 years agoARM: add STRACE_KNOWS_ONLY_EABI define which can be used to omit OABI support
Denys Vlasenko [Thu, 4 Jul 2013 07:54:19 +0000 (09:54 +0200)]
ARM: add STRACE_KNOWS_ONLY_EABI define which can be used to omit OABI support

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
11 years agoAdd paranoia check before passing a long to pid2tcb(int pid)
Denys Vlasenko [Thu, 4 Jul 2013 07:26:24 +0000 (09:26 +0200)]
Add paranoia check before passing a long to pid2tcb(int pid)

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
11 years agoIn debug output, show waitpid status with 6 hex digits, not 4
Denys Vlasenko [Tue, 2 Jul 2013 10:18:22 +0000 (12:18 +0200)]
In debug output, show waitpid status with 6 hex digits, not 4

This shows event byte values better (without variable offset):

 [wait(0x01057f) = 29491] WIFSTOPPED,sig=SIGTRAP,EVENT_FORK (1)
 [wait(0x80057f) = 29492] WIFSTOPPED,sig=SIGTRAP,EVENT_STOP (128)
         ^^

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
11 years agoReplace suspicious popen_pid assignment with an obviously correct one
Denys Vlasenko [Tue, 2 Jul 2013 09:31:24 +0000 (11:31 +0200)]
Replace suspicious popen_pid assignment with an obviously correct one

popen_pid = vfork() does work correctly, but for a subtle reason
that wrong assignment of 0 happens in the child _first_,
and _then_ correct value overwrites it in the parent.

(And in a hyphothetical system where vfork = fork,
popen_pid wouldn't be shared, so it will also be ok.)

However, it's not necessary to be difficult.
This change makes it so that assignment is done only in parent.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
11 years agoConvert trace() from returning int to returning void
Denys Vlasenko [Mon, 1 Jul 2013 11:02:33 +0000 (13:02 +0200)]
Convert trace() from returning int to returning void

The cleanup sequence in error cases, and on normal code path
was nearly the same, no point in duplicating it.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
11 years agoRemove ia64-specific printing of current address on signal delivery
Denys Vlasenko [Mon, 1 Jul 2013 10:49:14 +0000 (12:49 +0200)]
Remove ia64-specific printing of current address on signal delivery

The address is printed anyway by printleader() if -i is active.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
11 years agoRename ia32 to ia64_ia32mode, and make it bool, not long
Denys Vlasenko [Mon, 1 Jul 2013 10:28:17 +0000 (12:28 +0200)]
Rename ia32 to ia64_ia32mode, and make it bool, not long

Grepping for just ia32 was turning up many false positives.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
11 years agoFold is_restart_error() into its sole user
Denys Vlasenko [Sun, 30 Jun 2013 21:53:49 +0000 (23:53 +0200)]
Fold is_restart_error() into its sole user

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
11 years agoUpdate qemu_multiarch_testing/README
Denys Vlasenko [Sat, 29 Jun 2013 12:34:48 +0000 (14:34 +0200)]
Update qemu_multiarch_testing/README

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
11 years agosys_clone: add a comment about CLONE_PTRACE and CLONE_UNTRACED
Denys Vlasenko [Fri, 28 Jun 2013 16:57:27 +0000 (18:57 +0200)]
sys_clone: add a comment about CLONE_PTRACE and CLONE_UNTRACED

No code changes.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
11 years agoPOWERPC: get rid of "static long ppc_result"
Denys Vlasenko [Fri, 28 Jun 2013 14:47:38 +0000 (16:47 +0200)]
POWERPC: get rid of "static long ppc_result"

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
11 years agoPOWERPC: read ppc_regs.nip if -i
Denys Vlasenko [Fri, 28 Jun 2013 12:51:50 +0000 (14:51 +0200)]
POWERPC: read ppc_regs.nip if -i

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
11 years agoPOWERPC: if GETREGS fails with EIO, don't try it again
Denys Vlasenko [Fri, 28 Jun 2013 12:41:30 +0000 (14:41 +0200)]
POWERPC: if GETREGS fails with EIO, don't try it again

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
11 years agoGet rid of powerpc_getreg(), it's a copy of upeek()
Denys Vlasenko [Fri, 28 Jun 2013 12:36:39 +0000 (14:36 +0200)]
Get rid of powerpc_getreg(), it's a copy of upeek()

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
11 years agoChange upeek() to take pid, not full tcp.
Denys Vlasenko [Fri, 28 Jun 2013 12:35:47 +0000 (14:35 +0200)]
Change upeek() to take pid, not full tcp.

This will be used by next change.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
11 years agopowerpc: Provide a fallback for old kernels without PTRACE_GETREGS
Anton Blanchard [Wed, 26 Jun 2013 04:42:37 +0000 (14:42 +1000)]
powerpc: Provide a fallback for old kernels without PTRACE_GETREGS

PTRACE_GETREGS was added to the ppc kernel in 2.6.23. In order to
provide backward compatibility for very old kernels, add a manual
fallback.

* syscall.c (powerpc_getreg, powerpc_getregs_old): New functions.
(get_regs): Call powerpc_getregs_old if PTRACE_GETREGS is not supported.

Signed-off-by: Anton Blanchard <anton@samba.org>
Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
11 years agopowerpc: Use PTRACE_GETREGS to fetch all registers
Anton Blanchard [Wed, 26 Jun 2013 13:53:33 +0000 (15:53 +0200)]
powerpc: Use PTRACE_GETREGS to fetch all registers

* defs.h: declare ppc_regs and get_regs_error.
* signal.c (sys_sigreturn): Use ppc_regs instead of upeek.
* syscall.c: define ppc_regs.
(printcall): Use ppc_regs instead of upeek.
(get_scno): Replace multiple upeek calls with one PTRACE_GETREGS call.
(get_syscall_result): Likewise.

Signed-off-by: Anton Blanchard <anton@samba.org>
Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
11 years agoAnother manpage tweak
Denys Vlasenko [Wed, 26 Jun 2013 13:40:13 +0000 (15:40 +0200)]
Another manpage tweak

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
11 years agoManpage update
Denys Vlasenko [Wed, 26 Jun 2013 13:35:16 +0000 (15:35 +0200)]
Manpage update

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
11 years agoUpdate build_static_example.sh
Denys Vlasenko [Wed, 26 Jun 2013 13:07:23 +0000 (15:07 +0200)]
Update build_static_example.sh

Now it also contains a tested example of i686 build on 64-bit host.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
11 years agoIn -f mode, do not assume that new pid is stopped - handle exits too
Denys Vlasenko [Wed, 26 Jun 2013 12:29:19 +0000 (14:29 +0200)]
In -f mode, do not assume that new pid is stopped - handle exits too

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
11 years agoSet strace_child only in the right branch
Denys Vlasenko [Wed, 26 Jun 2013 12:27:11 +0000 (14:27 +0200)]
Set strace_child only in the right branch

"strace_child = pid" assignment was racing in NOMMU case
because of vfork (no way to know which process would win).

After this change, strace_child is set to nonzero only
in one process after [v]fork.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
11 years agoGet rid of TCB_INUSE and TCB_STRACE_CHILD
Denys Vlasenko [Wed, 26 Jun 2013 12:14:29 +0000 (14:14 +0200)]
Get rid of TCB_INUSE and TCB_STRACE_CHILD

We can use tcb::pid == 0 as an indicator of free tcb,
and we already have strace_child variable which holds
pid of our child, if any.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
11 years agoFix debug output of wait4 result (was reusing buf[] on unknown events)
Denys Vlasenko [Fri, 21 Jun 2013 14:41:50 +0000 (16:41 +0200)]
Fix debug output of wait4 result (was reusing buf[] on unknown events)

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
11 years agoShow PTRACE_EVENT_STOP correctly in debug output
Denys Vlasenko [Fri, 21 Jun 2013 14:33:56 +0000 (16:33 +0200)]
Show PTRACE_EVENT_STOP correctly in debug output

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
11 years agoPanic a bit less when we see an unknown pid
Denys Vlasenko [Fri, 21 Jun 2013 14:19:46 +0000 (16:19 +0200)]
Panic a bit less when we see an unknown pid

I stumbeld over this case when I used "exec stace ...".

* strace.c (trace): Do not exit if we see an unknown pid in wait4.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
11 years agodetach(): Reorganize code. Logic is the same.
Denys Vlasenko [Fri, 21 Jun 2013 14:11:10 +0000 (16:11 +0200)]
detach(): Reorganize code. Logic is the same.

* strace.c (detach): Use goto's instead of excessive nesting.
Drop sigstop_expected and interrupt_done variables.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
11 years agoEat pending SIGSTOP _before_ PTRACE_DETACH in detach()
Denys Vlasenko [Fri, 21 Jun 2013 13:50:41 +0000 (15:50 +0200)]
Eat pending SIGSTOP _before_ PTRACE_DETACH in detach()

* strace.c (detach): If TCB_IGNORE_ONE_SIGSTOP is set,
di not PTRACE_DETACH - wait for SIGSTOP first.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
11 years agodetach(): warn if we see ECHILD from waitpid
Denys Vlasenko [Thu, 20 Jun 2013 10:10:21 +0000 (12:10 +0200)]
detach(): warn if we see ECHILD from waitpid

* strace.c (detach): Warn if we see ECHILD from waitpid.
Explain in comments that we don't normally expect !WIFSTOPPED
either, and also that PTRACE_CONT failure isn't expected
(the "break" there is a "I'm confused, bailing out" code style)..

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
11 years agoImprove error messages in detach()
Denys Vlasenko [Thu, 20 Jun 2013 09:20:23 +0000 (11:20 +0200)]
Improve error messages in detach()

* strace.c (detach): Change return type from int to void.
Improve error meesages: show PID, tell exactly which operation fails.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
11 years agoRemove workarounds for ancient kernels lacking __WALL
Denys Vlasenko [Thu, 20 Jun 2013 09:06:58 +0000 (11:06 +0200)]
Remove workarounds for ancient kernels lacking __WALL

__WALL is available and working at least since 2.4 kernels: 10 years ago.

* strace (detach): Remove workarounds for ancient kernels lacking __WALL.
Add missing EINTR check.
(trace): Remove workarounds for ancient kernels lacking __WALL.
Remove redundant double error printout.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
11 years agoUSE_SEIZE: fix detaching from stopped processes
Denys Vlasenko [Wed, 19 Jun 2013 13:31:39 +0000 (15:31 +0200)]
USE_SEIZE: fix detaching from stopped processes

V3: split SEIZE/!SEIZE code paths to reduce confusion.
Extensively comment every possible case.
Verified that all tests/detach* tests work in both SEIZE and !SEIZE
cases.

* strace.c (detach): If PTRACE_SEIZE API is in use, stop the tracee
using PTRACE_INTERRUPT instead of sending it a SIGSTOP.
In a subsequent waitpid loop, correctly wait and suppress SIGSTOP
on detach if PTRACE_INTERRUPT wasn't used, or wait for any ptrace
stop and detach without suppressing signals.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
11 years agotests: disable /proc based checks when /proc is not mounted
Dmitry V. Levin [Wed, 19 Jun 2013 14:57:05 +0000 (14:57 +0000)]
tests: disable /proc based checks when /proc is not mounted

* tests/detach-running: Disable /proc based checks when
/proc/self/status is not available.
* tests/detach-sleeping: Likewise.
* tests/detach-stopped: Likewise.

11 years agotests/detach-{running,sleeping,stopped}: check post-detach state
Denys Vlasenko [Wed, 19 Jun 2013 14:37:24 +0000 (16:37 +0200)]
tests/detach-{running,sleeping,stopped}: check post-detach state

Check that traced process still exists and is in a right state
after strace detached from it.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
11 years agotests: ensure that strace can detach from running processes
Dmitry V. Levin [Wed, 19 Jun 2013 10:22:18 +0000 (10:22 +0000)]
tests: ensure that strace can detach from running processes

* tests/detach-running: New test.
* tests/Makefile.am (TESTS): Add it.

11 years agotests: ensure that strace does not leave sleeping processes stopped
Dmitry V. Levin [Wed, 19 Jun 2013 01:05:30 +0000 (01:05 +0000)]
tests: ensure that strace does not leave sleeping processes stopped

* tests/detach-sleeping: Do not send SIGCONT to the sleeping process.

11 years agotests: fix parallel-tests support in detach-* tests
Dmitry V. Levin [Tue, 18 Jun 2013 22:31:58 +0000 (22:31 +0000)]
tests: fix parallel-tests support in detach-* tests

* tests/detach-sleeping: Use $LOG file for set_ptracer_any output.
* tests/detach-stopped: Likewise.

11 years agotests: parametrize "sleep 1"
Dmitry V. Levin [Tue, 18 Jun 2013 20:51:49 +0000 (20:51 +0000)]
tests: parametrize "sleep 1"

* tests/init.sh (SLEEP_A_BIT): New variable.
* tests/detach-sleeping: Use it.
* tests/detach-stopped: Likewise.

11 years agotests: ensure that strace can detach from sleeping and stopped processes
Dmitry V. Levin [Tue, 18 Jun 2013 16:50:18 +0000 (16:50 +0000)]
tests: ensure that strace can detach from sleeping and stopped processes

* tests/set_ptracer_any.c: New file.
* tests/detach-sleeping: New test.
* tests/detach-stopped: Likewise.
* tests/Makefile.am (check_PROGRAMS): Add set_ptracer_any.
(TESTS): Add detach-sleeping and detach-stopped.
* tests/.gitignore: Add set_ptracer_any.

11 years agotests: enhance timeout checks
Dmitry V. Levin [Tue, 18 Jun 2013 15:28:47 +0000 (15:28 +0000)]
tests: enhance timeout checks

Run each test using a wrapper that does all necessary timeout checks.

* tests/run.sh: New file.
* tests/Makefile.am (EXTRA_DIST, LOG_COMPILER): Add it.
* tests/init.sh (check_strace, check_timeout): Remove.
* tests/detach-stopped: Update callers.
* tests/net: Likewise.
* tests/ptrace_setoptions: Likewise.
* tests/qual_syscall: Likewise.
* tests/stat: Likewise.
* tests/strace-f: Likewise.

11 years agotests: enable parallel-tests support
Dmitry V. Levin [Tue, 18 Jun 2013 14:31:57 +0000 (14:31 +0000)]
tests: enable parallel-tests support

* configure.ac (AM_INIT_AUTOMAKE): Add parallel-tests.

11 years agotests: prepare for parallel-tests support
Dmitry V. Levin [Tue, 18 Jun 2013 13:35:29 +0000 (13:35 +0000)]
tests: prepare for parallel-tests support

* tests/Makefile.am (CLEANFILES): Calculate dynamically from TESTS.
* tests/init.sh (LOG): New variable.
* tests/detach-stopped: Use it.
* tests/net: Likewise.
* tests/qual_syscall: Likewise.
* tests/stat: Likewise.
* tests/strace-f: Likewise.

11 years agoCleanups. No logic changes.
Denys Vlasenko [Tue, 18 Jun 2013 16:09:39 +0000 (18:09 +0200)]
Cleanups. No logic changes.

* defs.h: Define new ptrace constants unconditionally.
* strace.c (detach): Fix comment.
(trace): Remove now unnecessary "if USE_SEIZE".

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
11 years agomaint: post-release administrivia
Dmitry V. Levin [Wed, 5 Jun 2013 21:33:45 +0000 (21:33 +0000)]
maint: post-release administrivia

* NEWS: Add header line for next release.

11 years agoioctlent: add UAPI support v4.8
Dmitry V. Levin [Mon, 3 Jun 2013 16:24:53 +0000 (16:24 +0000)]
ioctlent: add UAPI support

* Makefile.am (IOCTLSORT_INCLUDEDIR): Define.
(ioctlsort): Use it.
* linux/ioctlent.sh (lookup_ioctls): Look into uapi directory tree.
Strip "uapi/" prefix from output path names.
* linux/ioctlent.h.in: Regenerate from v3.9 headers.
* NEWS: Mention it.

11 years agoPrepare for 4.8 release
Dmitry V. Levin [Mon, 3 Jun 2013 12:34:56 +0000 (12:34 +0000)]
Prepare for 4.8 release

* NEWS: Update for 4.8 release.
* debian/changelog: 4.8-1.
* strace.spec: 4.8-1.

11 years agoFix "make dist" on recently added architectures
Dmitry V. Levin [Sun, 2 Jun 2013 18:12:44 +0000 (18:12 +0000)]
Fix "make dist" on recently added architectures

* Makefile.am (EXTRA_DIST): Add linux/aarch64/errnoent1.h,
linux/aarch64/ioctlent.h.in, linux/aarch64/ioctlent1.h,
linux/aarch64/signalent1.h, linux/aarch64/syscallent.h,
linux/aarch64/syscallent1.h, linux/metag/ioctlent.h.in,
linux/metag/syscallent.h, linux/or1k/ioctlent.h.in,
linux/or1k/syscallent.h, linux/tile/errnoent1.h, linux/tile/ioctlent1.h,
linux/tile/signalent1.h, linux/tile/syscallent1.h, linux/ubi-user.h,
linux/xtensa/ioctlent.h.in, and linux/xtensa/syscallent.h.

11 years agoFix "make dist" regression introduced by commit v4.7-184-gd648f29
Dmitry V. Levin [Sun, 2 Jun 2013 18:09:44 +0000 (18:09 +0000)]
Fix "make dist" regression introduced by commit v4.7-184-gd648f29

* Makefile.am (EXTRA_DIST): Add linux/ubi-user.h.

11 years agoDo not suppress signal delivery messages with -qq
Dmitry V. Levin [Tue, 28 May 2013 20:27:10 +0000 (20:27 +0000)]
Do not suppress signal delivery messages with -qq

Current implementation of -qq does not allow suppressing exit status
messages without suppressing signal delivery messages, which is not
good.  There is a traditional "-e signal=none" syntax that can be used
to suppress all signal delivery messages.
This partially reverts commit v4.7-222-g01997cf.

* strace.c (trace): Do not suppress signal delivery messages with -qq.
* strace.1: Update documentation about -qq option.

11 years agotile: use siginfo_t, not struct siginfo
Chris Metcalf [Wed, 22 May 2013 00:25:22 +0000 (20:25 -0400)]
tile: use siginfo_t, not struct siginfo

As of glibc 2.16, "struct siginfo" is no longer supported,
and "siginfo_t" must be used instead.

Signed-off-by: Chris Metcalf <cmetcalf@tilera.com>
Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
11 years agotile: remove MAP_CACHE_xxx support in mem.c
Chris Metcalf [Tue, 21 May 2013 20:40:50 +0000 (16:40 -0400)]
tile: remove MAP_CACHE_xxx support in mem.c

These flags support functionality in mmap() that has not been
pushed back to the community, and which may or may not eventually
end up being the final community model.  In the interim, having
these flags unconditionally present for "#ifdef TILE" just means
that the TILE build breaks if using the community versions of
the kernel and glibc, so just revert the code until such time
as it may end up in the community.

Signed-off-by: Chris Metcalf <cmetcalf@tilera.com>
Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
11 years agoRename COPYRIGHT to COPYING
Mike Frysinger [Wed, 15 May 2013 20:33:09 +0000 (16:33 -0400)]
Rename COPYRIGHT to COPYING

The standard name people have adopted is "COPYING" rather than
"COPYRIGHT".  Use that as a lot of license scanning tools look for it.

* COPYRIGHT: Rename to ...
* COPYING: ... this.
* Makefile.am (EXTRA_DIST): Rename COPYRIGHT to COPYING.
* README: Likewise.
* strace.spec (%files): Likewise.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
11 years agoSync strace.spec and debian/ with packages
Dmitry V. Levin [Fri, 17 May 2013 23:16:39 +0000 (23:16 +0000)]
Sync strace.spec and debian/ with packages

* debian/changelog: Sync with 4.7-1.
* debian/strace.docs: Likewise.
* strace.spec: Sync with 4.7-3.

11 years agoUpdate PTRACE_O_* constants
Dmitry V. Levin [Fri, 17 May 2013 22:22:19 +0000 (22:22 +0000)]
Update PTRACE_O_* constants

* process.c (ptrace_setoptions_flags): Sync with Linux 3.9.

11 years agoUpdate AF_*, PF_*, MSG_*, and TCP_* constants
Dmitry V. Levin [Thu, 16 May 2013 22:19:30 +0000 (22:19 +0000)]
Update AF_*, PF_*, MSG_*, and TCP_* constants

* net.c (domains, addrfams, protocols, socktcpoptions): Sync with
Linux 3.9.

11 years agoNOMMU: do not hide startup syscalls unless in -D mode
Dmitry V. Levin [Tue, 14 May 2013 22:35:46 +0000 (22:35 +0000)]
NOMMU: do not hide startup syscalls unless in -D mode

On NOMMU systems in "strace PROG" case, we have no way to attach to
the tracee before it calls execve unless in -D mode.  That is, the
first execve call is very likely to be missed, and setting
hide_log_until_execve just results to empty log.

* strace.c (init) [NOMMU_SYSTEM]: Do not set hide_log_until_execve
unless in -D mode.

11 years agoMake -D mode work when the Yama LSM is enabled
Dmitry V. Levin [Mon, 13 May 2013 18:43:28 +0000 (18:43 +0000)]
Make -D mode work when the Yama LSM is enabled

* strace.c [HAVE_PRCTL]: Include sys/prctl.h.
(startup_child) [HAVE_PRCTL && PR_SET_PTRACER && PR_SET_PTRACER_ANY]:
In -D mode, allow tracing the process that is going to become the
tracee.

11 years agoUpdate PR_* constants
Dmitry V. Levin [Mon, 13 May 2013 18:34:15 +0000 (18:34 +0000)]
Update PR_* constants

* process.c (prctl_options): Add PR_SET_PTRACER.