Add -k option to print stack trace after each syscall
Print the stack trace of the traced process after each system call when
-k option is specified. It is implemented using libunwind to unwind the
stack and to obtain the function name pointed by the IP.
Based on the code that was originally taken from strace-plus
of Philip J. Guo.
* xlat/gen.sh: Define all xlat structs not declared in defs.h as static.
Some symbolic constants are not macros, extend #ifdef check to cover
symbolic constants checked by AC_CHECK_DECLS.
Handle complex symbolic constants in SYMBOL|... form.
Handle symbolic constants in 1<<SYMBOL form.
Handle numeric constants.
Implement #unconditional directive that turns off preprocessor checks.
Implement #unterminated directive that turns off adding XLAT_END.
Dmitry V. Levin [Thu, 29 May 2014 18:10:00 +0000 (18:10 +0000)]
Constify count_syscall function
* count.c (count_syscall): Add const qualifier to timeval argument and
rename it. Store the wall clock time spent while in syscall in separate
timeval variable.
* defs.h (count_syscall): Update prototype.
* syscall.c (trace_syscall_exiting): Update count_syscall invocation.
Dmitry V. Levin [Wed, 28 May 2014 16:38:44 +0000 (16:38 +0000)]
Use printstr for sethostname, setdomainname, and gethostname decoding
The argument passed to sethostname and setdomainname syscalls, as well
as the string returned by gethostname syscall, is not a pathname, so
printpathn is not the right method for its decoding.
* process.c (sys_sethostname, sys_setdomainname): Decode 1st argument
using printstr instead of printpathn.
[ALPHA] (sys_gethostname): Likewise.
James Hogan [Fri, 2 May 2014 13:15:41 +0000 (14:15 +0100)]
Fix {get,set}rlimit decoding with unreliable SIZEOF_RLIM_T
When strace is built with large file support definitions in CFLAGS (as
may be provided by buildroot) the C library headers may expose a 64-bit
rlim_t even though the struct rlimit fields used by the system call
interface are only 32-bit. The SIZEOF_RLIM_T will then be 8 which
results in bad decoding of the getrlimit and setrlimit syscalls.
This is fixed by replacing unreliable SIZEOF_RLIM_T based checks with
checks for current_wordsize.
Signed-off-by: James Hogan <james.hogan@imgtec.com> Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
I found that I use it quite often. Lets make it so that
after cut-n-pasting it into a file, there is no need
to edit the result (e.g. no need to remove C comment
chars from every line.
We need to handle this situation more like x86-64. 32-bit arm and i386
actually have a common struct stat64, except the arm one must not be
packed. Additionally, on aarch64 the 32-bit personality is personality 0.
Dmitry V. Levin [Tue, 18 Mar 2014 23:37:43 +0000 (23:37 +0000)]
ARM EABI: disable OABI support by default
OABI is rarely used in ARM EABI systems nowadays, so disable its support
by default. Add --enable-arm-oabi option to enable ARM OABI support.
* configure.ac: New option --enable-arm-oabi.
* syscall.c (get_scno) [ARM]: Check ENABLE_ARM_OABI macro defined by
configure instead of undocumented STRACE_KNOWS_ONLY_EABI macro.
Elliott Hughes [Wed, 12 Mar 2014 17:31:04 +0000 (10:31 -0700)]
Fix stat decoding for LP64 bionic
Patch fb642bb6d63f7ffe2228bf48a6008bc8f56f67ff fixed building with
HAVE_STAT64 for aarch64 with uapi kernel headers but not x86_64.
The workaround needed to be applied to all LP64 architectures, not
just aarch64. This patch fixes that and adds an explanatory comment.
Elliott Hughes [Mon, 10 Mar 2014 19:27:22 +0000 (19:27 +0000)]
Improve SI_TIMER decoding
Decode siginfo_t more clearly for si_code SI_TIMER.
The 'pid' is actually a POSIX timer id, and the 'uid' is actually the
overrun.
Also factor out the si_value dumping so it's the same for every si_code.
Dmitry V. Levin [Mon, 3 Mar 2014 23:09:47 +0000 (23:09 +0000)]
Fix fcntl decoding
Assume that F_SETLK64, F_SETLKW64, and F_GETLK64 are either defined or
not defined altogether.
Do not assume that sizeof(off_t) < sizeof(long long) when F_SETLK64 is
undefined.
This change fixes build with musl libc on x86.
* configure.ac: Define SIZEOF_OFF_T.
* desc.c (USE_PRINTFLOCK64): New macro.
(struct flock64, printflock64): Do not define on X32.
(printflock): Replace X32 specific workaround with SIZEOF_OFF_T check.
Fix printing off_t members of struct flock.
(sys_fcntl): Use USE_PRINTFLOCK64.
Dmitry V. Levin [Sat, 1 Mar 2014 21:17:17 +0000 (21:17 +0000)]
sys_fcntl: remove F_FREESP and F_FREESP64 support
F_FREESP and F_FREESP64 fcntl commands are not available in Linux
and therefore the code implementing their decoding is useless.
Besides that, F_FREESP64 decoding is too complicated to support.
* desc.c (fcntlcmds): Remove F_FREESP and F_FREESP64.
Remove F_FREESP64 from the check whether to define struct flock64.
(sys_fcntl): Remove F_FREESP and F_FREESP64 support.
Elliott Hughes [Fri, 28 Feb 2014 23:16:32 +0000 (23:16 +0000)]
Fix decoding of arm struct stat64 by aarch64 strace.
aarch64's uapi header files have a struct stat but no struct stat64.
To correctly decode a 32-bit process' s struct stat64 we need
HAVE_STAT64, but then the build fails because there is no struct stat64.
Luckily, the aarch64 struct stat is structurally equivalent to the arm
struct stat64, so we can just reuse that.
Dmitry V. Levin [Wed, 26 Feb 2014 16:51:28 +0000 (16:51 +0000)]
Rewrite signal mask decoding without sigset_t
The sigset_t provided by libc is not quite convenient.
In glibc, sigset_t is an array with space for 1024 bits, which is much
more than required: all architectures supported by Linux have only 64
signals except MIPS, which has 128.
In bionic libc, LP32 sigset_t is only 4 bytes long, which is less than
necessary.
With this change, signal mask is decoded without use of intermediate
sigset_t structure, which saves us some cpu cycles in case of glibc with
its inflated sigset_t, and enables build with libcs where sigset_t is
broken.
Old implementation used to check each signal number in the given signal
mask twice using sigismember().
New implementation is based on popcount and next_set_bit() so it's
noticeably faster.
* configure.ac: Check for __builtin_popcount.
* signal.c: Ensure that NSIG >= 32.
(sprintsigmask, sprintsigmask_long, printsigmask): Remove.
(popcount32, sprintsigmask_n): New functions.
(tprintsigmask_addr, sprintsigmask_val, tprintsigmask_val): New macros.
(print_sigset_addr_len, sys_sigsetmask, sys_sigreturn, sys_siggetmask,
sys_sigsuspend, sys_sigprocmask, decode_new_sigaction): Update to use
new signal mask decoding interface.
* tests/sigaction.c (main): Add a test with almost filled signal mask.
* tests/sigaction.awk: Update.
Dmitry V. Levin [Wed, 26 Feb 2014 00:01:00 +0000 (00:01 +0000)]
Fix build with Bionic libc
Add generic tests for fopen64 and fputs_unlocked functions to fix build
with Bionic libc that does not provide them.
* configure.ac (AC_CHECK_FUNCS): Add fopen64 and fputs_unlocked.
* strace.c [_LARGEFILE64_SOURCE]: Use fopen instead of fopen64
if !HAVE_FOPEN64.
Use fputs instead of fputs_unlocked if !HAVE_FPUTS_UNLOCKED.
* vsprintf.c: Use fputs instead of fputs_unlocked
if !HAVE_FPUTS_UNLOCKED.
Dmitry V. Levin [Tue, 25 Feb 2014 23:04:55 +0000 (23:04 +0000)]
Do not compile scsi ioctl decoding if <scsi/sg.h> is not available
Add a generic test for <scsi/sg.h> availability to fix build with
Bionic libc that does not provide <scsi/sg.h>.
* configure.ac (AC_CHECK_HEADERS): Add scsi/sg.h.
* ioctl.c (ioctl_decode): Do not call scsi_ioctl if !HAVE_SCSI_SG_H.
* scsi.c: Do not compile scsi ioctl decoding if !HAVE_SCSI_SG_H.
Dmitry V. Levin [Sat, 8 Feb 2014 00:26:06 +0000 (00:26 +0000)]
Fix sigaction reporting on non-x86 architectures
If SA_RESTORER is not defined by libc headers but defined by kernel
headers, use the definition provided by kernel headers for proper
sigaction decoding.
* signal.c [!SA_RESTORER]: Define to ASM_SA_RESTORER if the latter is
defined, regardless of architecure.
Dmitry V. Levin [Sat, 8 Feb 2014 00:15:52 +0000 (00:15 +0000)]
Check for SA_RESTORER definition in <asm/signal.h>
Kernel header <asm/signal.h> cannot be included from regular code
because it conflicts with libc headers, but SA_RESTORER is needed in
signal.c, so SA_RESTORER value is forwarded from <asm/signal.h> to
config.h using a configure check.
* configure.ac (ASM_SA_RESTORER): Define if SA_RESTORER is defined
in <asm/signal.h>.
Ezequiel Garcia [Thu, 6 Feb 2014 17:53:54 +0000 (14:53 -0300)]
Add support for Altera's Nios-II softcore architecture
This commit adds strace support for Altera's Nios-II official
kernel port as found in git://git.rocketboards.org/linux-socfpga.git
Notice that this an out-of-tree kernel architectural port, and uses the
legacy (non-generic) system call ABI. In particular, the port doesn't
support PTRACE_GETREGSET, so the implementation is based on PTRACE_GETREGS.
Given it's mandatory for new architectures to support the generic
syscall ABI and PTRACE_GETREGSET, if the nios2 architecure is ever
mainlined, the strace support will have to be re-factored accordingly.
* linux/nios2/ioctlent.h.in: New file.
* linux/nios2/syscallent.h: Likewise.
* Makefile.am (EXTRA_DIST): Add linux/nios2/ioctlent.h.in and
linux/nios2/syscallent.h.
* configure.ac: Add NIOS2 to the list of supported architectures.
* defs.h [NIOS2]: Use register reading system.
* process.c (struct_user_offsets): Add NIOS2 support.
* syscall.c (get_regs, get_scno, get_syscall_args,
get_syscall_result, get_error): Likewise.
* util.c (change_syscall): Likewise.
* mem.c (sys_getpagesize): Define on NIOS2.
* system.c [NIOS2] (sys_cacheflush, sys_nios2cmpxchg): New functions.
Signed-off-by: Ezequiel Garcia <ezequiel@vanguardiasur.com.ar> Acked-by: Mike Frysinger <vapier@gentoo.org>
Dmitry V. Levin [Wed, 5 Feb 2014 02:20:51 +0000 (02:20 +0000)]
Use XLAT_END macro
Automatically update all xlat structures using the following sed regexp:
s/^[[:space:]]*{[[:space:]]*0[[:space:]]*,[[:space:]]*NULL[[:space:]]*,\?[[:space:]]*}[[:space:]]*,\?[[:space:]]*/\tXLAT_END/
Dmitry V. Levin [Wed, 5 Feb 2014 01:33:50 +0000 (01:33 +0000)]
Use XLAT macro
Automatically convert all xlat structures to XLAT form
using the following sed regexp:
s/^[[:space:]]*{[[:space:]]*\([^",}[:space:]]\+\)[[:space:]]*,[[:space:]]*"\1",\?[[:space:]]*}[[:space:]]*/\tXLAT(\1)/
Stefan Sørensen [Mon, 3 Feb 2014 09:01:27 +0000 (10:01 +0100)]
Decode dynamic posix clocks
* time.c (cpuclocknames): New xlat structure.
(printclockname): New function that decodes posix clock names,
including dynamic fd encoded clocks.
(sys_clock_settime, sys_clock_gettime, sys_clock_nanosleep,
sys_clock_adjtime, sys_timer_create, sys_timerfd, sys_timerfd_create):
Use it.
Signed-off-by: Stefan Sørensen <stefan.sorensen@spectralink.com>
Chris Dearman [Tue, 10 Dec 2013 03:58:42 +0000 (19:58 -0800)]
mips: fix sigaction reporting
MIPS userland uses the same sigaction structure with a full signal
mask for old_sigaction and new_sigaction and does does not have
an sa_restorer field.
These changes have been tested on MIPS O32 big/little endian, MIPS N64
big endian and x86-64.
* signal.c (old_sigaction) [MIPS]: Add definition for MIPS.
(decode_old_sigaction) [MIPS]: Print sa_mask according to its definition.
(new_sigaction) [MIPS]: Add definition for MIPS.
Signed-off-by: Chris Dearman <chris.dearman@imgtec.com> Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
Dmitry V. Levin [Tue, 7 Jan 2014 22:41:30 +0000 (22:41 +0000)]
Factor out struct sigaction printing code
* signal.c [HAVE_SIGACTION] (decode_old_sigaction): New function.
[HAVE_SIGACTION] (sys_sigaction): Use it.
(decode_new_sigaction): New function.
(sys_rt_sigaction): Use it.
Dmitry V. Levin [Tue, 7 Jan 2014 19:32:32 +0000 (19:32 +0000)]
tests: add a test for rt_sigaction output
Since "struct sigaction" varies between architectures, rt_sigaction
decoding sometimes produces incorrect output. This test is expected
to catch basic rt_sigaction decoding bugs.
Mike Frysinger [Tue, 31 Dec 2013 07:43:17 +0000 (02:43 -0500)]
Delete old PTRACE_{PEEK,POKE}USR logic
The code base has settled on PTRACE_{PEEK,POKE}USER (with an E) and has
logic in defs.h to make sure it's set sanely. Delete this old logic as
the defs.h takes care of it now.
Dmitry V. Levin [Wed, 13 Nov 2013 18:09:04 +0000 (18:09 +0000)]
Assume that <sys/ptrace.h> provides a valid ptrace prototype
We used to explicitly list architectures where <sys/ptrace.h> from glibc
is known to provide a valid prototype for ptrace, and use a homegrown
replacement for all the rest. Situation seems to be better nowadays,
glibc is not the only libc available, so let's use ptrace prototype from
<sys/ptrace.h> by default, leaving the replacement for rare broken cases
if any.
* defs.h: Use ptrace prototype workaround iff
NEED_PTRACE_PROTOTYPE_WORKAROUND is defined.
Dmitry V. Levin [Tue, 12 Nov 2013 22:34:42 +0000 (22:34 +0000)]
Stop using _LFS64_LARGEFILE
There is only one place left in the code where strace guesses whether
libc provides LFS64 functions and structures. The most natural thing to
do there is to check for _LARGEFILE64_SOURCE - the macro provided by
glibc. Other libc implementations that provide nondegenerate LFS64
interfaces are expected to define this macro as well.
* defs.h (_LFS64_LARGEFILE): Remove.
* strace.c: Use _LARGEFILE64_SOURCE instead of _LFS64_LARGEFILE.
Dmitry V. Levin [Tue, 12 Nov 2013 22:25:06 +0000 (22:25 +0000)]
Define truncate64, ftruncate64, and getdents64 decoders unconditionally
These decoders are referenced by most architectures, there were no
undefined references so far because _LFS64_LARGEFILE appears to be
always defined by glibc when _GNU_SOURCE is defined.
Dmitry V. Levin [Tue, 12 Nov 2013 21:49:03 +0000 (21:49 +0000)]
Define printflock64 only if it is referenced by other code
* configure.ac (AC_CHECK_TYPES): Add struct flock64.
* desc.c (HAVE_F_SETLK64, HAVE_F_SETLKW64, HAVE_F_GETLK64): New macros.
[!HAVE_STRUCT_FLOCK64] (struct flock64): Define.
(printflock64): Define only if referenced by other code.
(sys_fcntl): Handle F_FREESP64, F_SETLK64, F_SETLKW64, and F_GETLK64 iff
these constants are defined and differ from their non-64bit versions.
Dmitry V. Levin [Tue, 12 Nov 2013 21:20:50 +0000 (21:20 +0000)]
Make PTRACE_PEEKUSER/PTRACE_POKEUSER checks less glibc specific
* configure.ac (AC_CHECK_DECLS): Add PTRACE_PEEKUSER and
PTRACE_POKEUSER.
* defs.h: Define PTRACE_PEEKUSER and PTRACE_POKEUSER only if
they are not provided by <sys/ptrace.h>.