summaryrefslogtreecommitdiff
Commit message (Collapse)AuthorAgeFilesLines
...
* unwind: enable dwarf cache of libunwindMasatake YAMATO2014-05-301-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Here is the benchmark of the dwarf cache. Target program: #include <sched.h> int main(void) { unsigned int max = 0x6fff, i; for (i = 0; i < max; i++) sched_yield(); return 0; } Command line: ./strace -o /dev/null -k a.out With the dwarf cache: real 0m12.081s user 0m3.858s sys 0m8.194s Without the dwarf cache: real 0m22.326s user 0m5.218s sys 0m16.952s Signed-off-by: Masatake YAMATO <yamato@redhat.com>
* unwind: report expected backtracing errorMasatake YAMATO2014-05-301-1/+20
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When a file mmap'ed to the target process is unlink'ed, backtracing the stack would fail. Current implementation reports it as "backtracing_error". To avoid confusion, the message is changed to "expected_backtracing_error". Here is the reproducer: $ cat ./p-deleted.c #include <unistd.h> int main(int argc, char **argv) { return unlink(argv[0]) < 0; } $ strace -e unlink -k ./p-deleted unlink("./p-deleted") = 0 > /usr/lib64/libc-2.18.so(unlink+0x7) [0xe7f17] > /home/yamato/var/strace/t_unwind/p-deleted (deleted)(+0x0) [0x575] > /usr/lib64/libc-2.18.so(__libc_start_main+0xf5) [0x21d65] > backtracing_error [0x7ffff1365590] +++ exited with 0 +++ p-deleted is deleted therefore backtracing_error is reported. This patch records the deleted marker when making mmap cache and refers the recorded information in the case "backtracing_error" to switch the message. Here is the output of this patch: $ strace -e unlink -k ./p-deleted unlink("./p-deleted") = 0 > /usr/lib64/libc-2.18.so(unlink+0x7) [0xe7f17] > /home/yamato/var/strace/t_unwind/p-deleted (deleted)(+0x0) [0x575] > /usr/lib64/libc-2.18.so(__libc_start_main+0xf5) [0x21d65] > expected_backtracing_error [0x7ffff1365590] +++ exited with 0 +++ This solution is not perfect: if a file is unlink'ed after making the mmap cache and before unwinding, strace cannot have a chance to record the deleted marker. In this version of patch, hardcoded magic number used in comparing "(delete)" string is replaced with strlen as suggested by Dmitry Levin. In old version of patch, the deleted entry was thrown away from mmap cache to avoid to report "backtracing_error". In this patch I keep it, and just switch the error message. Inspired by the review comment from Dmitry Levin. Signed-off-by: Masatake YAMATO <yamato@redhat.com>
* unwind: call unwind_tcb_fin before printing detached messageMasatake YAMATO2014-05-301-5/+6
| | | | | | | | | | captured stacktrace is printed in unwind_tcb_fin if tcp->queue is not empty. This should happen before printing detached message, so unwind_tcb_fin is moved to the top of droptcb. This is implicitly suggested by Dmitry Levin in patch review process. Signed-off-by: Masatake YAMATO <yamato@redhat.com>
* unwind: implement automatic mmap cache invalidationMasatake YAMATO2014-05-302-11/+58
| | | | | | | | | | | | | | | | | | | | | | | A mmap cache belonging to a tcb was updated when a system call which changed the memory mapping was called. This implementation was assumed the mapping was changed only by the tcb. However, this assumption is incorrect if the target application is multi-threaded; more than two tcbs can shared the same memory mapping and a tcb can modify it without being noticed by the others. This change introduces a global integer variable mmap_cache_generation, and mmap_cache_generation field to struct tcb. The variable is incremented each time a process enters a syscall that can modify its memory mapping. Each tcb records the value of this variable at the moment if building its mmap cache. Every mmap cache associated with the given tcb can be validated by comparing its mmap_cache_generation field with the variable mmap_cache_generation. This implementation is inefficient. If strace attaches two processes which don't share the memory mapping, rebuilding mmap cache of a tcb triggered by another tcb's mmap system call is not necessary. Signed-off-by: Masatake YAMATO <yamato@redhat.com>
* unwind: introduce queue_t for capturing stacktraceMasatake YAMATO2014-05-304-4/+172
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is the second step for splitting capturing from printing. New `queue' field is added to tcb. Captured stacktrace is stored here. The field is initialized/finalized at unwind_tcb_init/unwind_tcb_fin. New API function unwind_capture_stacktrace is added. This function captures the currest stack using stracktrace_walker and records it in tcb. It's printing is delayed to the next call of unwind_print_stacktrace. unwind_print_stacktrace is extended. Now it checks queue field of the given tcb at the start of function. If the function finds a captured stack trace, the latter is printed using stracktrace_walker. Currently unwind_capture_stacktrace invocations are added directly to handlers of mmap, munmap, mprotect, and execve. Here is the difference of output with/without patch: (without patch) execve("./test-fork", ["./test-fork"], [/* 56 vars */]) = 0 > /usr/lib64/ld-2.18.so(check_one_fd.part.0+0x82) [0x11f0] (with patch) execve("./test-fork", ["./test-fork"], [/* 54 vars */]) = 0 > /usr/lib64/libc-2.18.so(execve+0x7) [0xbcd27] > /home/yamato/var/strace/strace(exec_or_die+0x10c) [0x26ac] > /home/yamato/var/strace/strace(startup_child+0x346) [0x134f6] > /home/yamato/var/strace/strace(init+0x89f) [0x13dff] > /home/yamato/var/strace/strace(main+0xa) [0x26ca] > /usr/lib64/libc-2.18.so(__libc_start_main+0xf5) [0x21d65] > /home/yamato/var/strace/strace(_start+0x29) [0x2799] In older version output lines of captured elements were built when printing. In this version they are built when capturing the stack. As result, unneeded dynamic memory allocations are avoided. Suggested by Luca Clementi. In older version the combination of snprintf and realloc were used. In this version they are replaced with asprintf. Suggested by Dmitry Levin. Signed-off-by: Masatake YAMATO <yamato@redhat.com>
* unwind: introduce own debug macroMasatake YAMATO2014-05-301-0/+2
| | | | | | | * unwind.c (DPRINTF): New macro, to be utilized in debugging cache management code. Signed-off-by: Masatake YAMATO <yamato@redhat.com>
* unwind: introduce stacktrace_walkerMasatake YAMATO2014-05-301-24/+104
| | | | | | | | | | | | | | | In current implementation, the stack trace is captured and printed at the same time, in trace_syscall_exiting. This approach cannot provide user expected information when a system call changes the memory mapping. In such cases, the stack trace should be captured on entering syscall and printed on exiting. As the initial step for splitting capturing from printing, this change introduces stacktrace_walker utility function. It can be used both for capturing in trace_syscall_entering and printing in trace_syscall_exiting. Signed-off-by: Masatake YAMATO <yamato@redhat.com>
* unwind: give all exported functions "unwind_" prefixMasatake YAMATO2014-05-306-19/+19
| | | | | | | | | | | | | | | * unwind.c (init_unwind_addr_space): Rename to unwind_init. (init_libunwind_ui): Rename to unwind_tcb_init. (free_libunwind_ui): Rename to unwind_tcb_fin. (delete_mmap_cache): Rename to unwind_cache_invalidate. (print_stacktrace): Rename to unwind_print_stacktrace. * defs.h: Update prototypes. * mem.c: All callers updated. * process.c: Likewise. * strace.c: Likewise. * syscall.c: Likewise. Signed-off-by: Masatake YAMATO <yamato@redhat.com>
* unwind: delete mmap cache in free_libunwind_uiMasatake YAMATO2014-05-302-1/+1
| | | | | | | | | | free_libunwind_ui is expected to release all unwind related resources attached to tcp. * strace.c (droptcb): Move delete_mmap_cache call ... * unwind.c (free_libunwind_ui): ... to here. Signed-off-by: Masatake YAMATO <yamato@redhat.com>
* unwind: make alloc_mmap_cache function localMasatake YAMATO2014-05-302-2/+1
| | | | | | | * defs.h (alloc_mmap_cache): Remove. * unwind.c (alloc_mmap_cache): Add static qualifier. Signed-off-by: Masatake YAMATO <yamato@redhat.com>
* unwind: fix a bug in range updating of binary searchMasatake YAMATO2014-05-301-1/+1
| | | | | | | * unwind.c (print_stacktrace): Fix off-by-one error in binary search. Signed-off-by: Masatake YAMATO <yamato@redhat.com> Signed-off-by: Luca Clementi <luca.clementi@gmail.com>
* Add -k option to print stack trace after each syscallLuca Clementi2014-05-309-1/+465
| | | | | | | | | | | | | | | | | | | | | 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. * configure.ac: Add --with-libunwind option. Check libunwind support. * Makefile.am: Add libunwind support. * defs.h (struct tcb) [USE_LIBUNWIND]: Append libunwind specific fields. [USE_LIBUNWIND] (stack_trace_enabled, alloc_mmap_cache, delete_mmap_cache, print_stacktrace): New prototypes. * mem.c (print_mmap, sys_munmap, sys_mprotect): Add libunwind support. * process.c (sys_execve): Likewise. * strace.c (usage, alloctcb, droptcb, init): Likewise. * syscall.c (trace_syscall_exiting): Likewise. * unwind.c: New file. * strace.1: Document -k option.
* sysctl: update CTL_*, KERN_*, NET_*, and VM_* constantsDmitry V. Levin2014-05-3013-22/+466
| | | | | | | * configure.ac (AC_CHECK_DECLS): Add CTL_*, KERN_*, NET_*, and VM_* constants. * system.c (CTL_PROC, CTL_CPU): Remove definitions. * xlat/sysctl_*.in: Update.
* Check for constants used by waitid functionDmitry V. Levin2014-05-301-0/+12
| | | | * configure.ac (AC_CHECK_DECLS): Add P_* constants.
* Check for LO_FLAGS_READ_ONLY constantDmitry V. Levin2014-05-301-0/+1
| | | | * configure.ac (AC_CHECK_DECLS): Add LO_FLAGS_READ_ONLY.
* Compress blank linesDmitry V. Levin2014-05-3019-73/+3
| | | | Suppress empty lines left after automated xlat conversion.
* xlat: cleanup the aftermath of automatic conversionDmitry V. Levin2014-05-305-0/+23
|
* Generate xlat/*.in filesDmitry V. Levin2014-05-30200-3981/+1983
| | | | | Automatically convert xlat structures from *.c files to xlat/*.in files using "./generate_xlat_in.sh *.c" command.
* Rename several xlat structures to avoid collisionsDmitry V. Levin2014-05-303-11/+11
| | | | | | * bjm.c (which): Rename to qm_which. * ipc.c (msg_flags): Rename to ipc_msg_flags. * time.c (which): Rename to itimer_which.
* Enhance xlat generatorDmitry V. Levin2014-05-301-11/+48
| | | | | | | | | | | * 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.
* Use bootstrap script consistentlyDmitry V. Levin2014-05-304-4/+4
| | | | | | | | | | Now that ./xlat/gen.sh has to be run before autoreconf, replace all autoreconf calls with ./bootstrap call. * bootstrap: Forward arguments to autoreconf. * build_static_example.sh: Replace autoreconf call with bootstrap call. * make-dist: Likewise. * qemu_multiarch_testing/README: Likewise.
* Implement xlat generatorMike Frysinger2014-05-303-0/+104
| | | | | | | | * bootstrap: New file. * xlat/gen.sh: Likewise. * Makefile.am: Include xlat/Makemodule.am (EXTRA_DIST): Add $(XLAT_INPUT_FILES), $(XLAT_HEADER_FILES), and xlat/gen.sh.
* tests: fix SCM_RIGHTS test for big-endian systemsDmitry V. Levin2014-05-302-3/+4
| | | | | | * tests/scm_rights.c (main): Send zero integer to avoid issues with endianness. * tests/scm_rights-fd.test: Update grep patterns.
* Decode file descriptors passed via SCM_RIGHTS control messagesDmitry V. Levin2014-05-305-2/+123
| | | | | | | | | | * net.c (printcmsghdr): Print descriptors from SCM_RIGHTS control messages using printfd. * tests/scm_rights.c: New file. * tests/scm_rights-fd.test: New test. * tests/Makefile.am (check_PROGRAMS): Add scm_rights. (TESTS): Add scm_rights-fd.test. * tests/.gitignore: Add scm_rights and uio.
* tests: add a test for -c and -w optionsDmitry V. Levin2014-05-302-0/+45
| | | | | * tests/count.test: New test. * tests/Makefile.am (TESTS): Add it.
* Optionally produce stats on syscall latencyMark Hills2014-05-295-3/+20
| | | | | | | | | | | | | Time spent in system time is not useful where a syscall depends on some non-CPU resource, eg. typically open() or stat() to a network drive. This patch adds a new flag (-w) to produce a summary of the time difference between beginning and end of the system call (ie. latency) This functionality has been useful to profile slow processes that are not CPU-bound. Signed-off-by: Mark Hills <mark.hills@framestore.com>
* Constify count_syscall functionDmitry V. Levin2014-05-293-9/+9
| | | | | | | | * 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.
* Constify tv_* functionsDmitry V. Levin2014-05-292-14/+14
| | | | | | | * defs.h (tv_nz, tv_cmp, tv_float, tv_add, tv_sub, tv_mul, tv_div): Add const qualifier to read only arguments. * util.c (tv_nz, tv_cmp, tv_float, tv_add, tv_sub, tv_mul, tv_div): Likewise.
* Use printstr for sethostname, setdomainname, and gethostname decodingDmitry V. Levin2014-05-281-3/+3
| | | | | | | | | | 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.
* Fix {get,set}rlimit decoding with unreliable SIZEOF_RLIM_TJames Hogan2014-05-213-12/+13
| | | | | | | | | | | | | | 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>
* Enhance setns syscall decodingMasatake YAMATO2014-05-133-1/+12
| | | | | | | | | | * process.c (sys_setns): New function. Decode the 2nd syscall argument using clone_flags. * linux/syscall.h (sys_setns): New prototype. * linux/dummy.h (sys_setns): Remove. Signed-off-by: Masatake YAMATO <yamato@redhat.com> Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
* mips: fix syscall entries that should have TP flag setDmitry V. Levin2014-05-123-20/+20
|
* xtensa: fix unshare syscall entryDmitry V. Levin2014-05-121-1/+1
|
* alpha, hppa, mips n64: fix waitid syscall entryDmitry V. Levin2014-05-123-3/+3
|
* Add TM flag to shmat and shmdt syscall entriesDmitry V. Levin2014-05-1227-60/+60
|
* Alias sys_vfork to sys_forkDmitry V. Levin2014-05-126-13/+3
| | | | | | | | | * process.c (sys_vfork): Remove. * linux/syscall.h (sys_vfork): Likewise. * linux/dummy.h (sys_vfork): Alias to sys_fork. * linux/alpha/syscallent.h: Fix vfork entry. * util.c (setbpt): Do not check for sys_vfork. * syscall.c (syscall_fixup_for_fork_exec): Likewise.
* epoll_ctl: fix EPOLL_CTL_DEL argument decodingDmitry V. Levin2014-04-171-2/+6
| | | | | | | * desc.c (sys_epoll_ctl): Do not parse the event structure for EPOLL_CTL_DEL operation. Reported-by: Марк Коренберг <socketpair@gmail.com>
* Update CLOCK_* constantsDmitry V. Levin2014-04-171-0/+15
| | | | | | * time.c (clocknames): Add CLOCK_BOOTTIME, CLOCK_REALTIME_ALARM, CLOCK_BOOTTIME_ALARM, CLOCK_SGI_CYCLE, and CLOCK_TAI. Fixes RH#1088455.
* Fix preadv/pwritev offset decodingDmitry V. Levin2014-04-179-34/+42
| | | | | | | | | | | | | | | | | | | | * util.c (printllval): Add align argument. * defs.h (printllval): Update prototype. (printllval_aligned, printllval_unaligned): New macros. * file.c (sys_readahead, sys_truncate64, sys_ftruncate64, sys_fadvise64, sys_fadvise64_64, sys_sync_file_range, sys_sync_file_range2, sys_fallocate): Replace printllval call with printllval_aligned. * io.c (sys_pread, sys_pwrite): Likewise. (sys_preadv, sys_pwritev): Replace printllval call with printllval_unaligned. * linux/arm/syscallent.h: Set the number of preadv and pwritev arguments to 5. * linux/mips/syscallent-o32.h: Likewise. * linux/powerpc/syscallent.h: Likewise. * linux/sh/syscallent.h: Likewise. * linux/xtensa/syscallent.h: Likewise. Reported-by: Dima Kogan <dima@secretsauce.net>
* tests: add a test for pread/pwrite and preadv/pwritev offset decodingDmitry V. Levin2014-04-163-1/+63
| | | | | | | | * tests/uio.c: New file. * tests/uio.test: New test. * tests/Makefile.am (check_PROGRAMS): Add uio. (uio_CFLAGS): Define. (TESTS): Add uio.test.
* Refactor LDT decodingDmitry V. Levin2014-04-105-135/+116
| | | | | | | | | | | | * configure.ac (AC_CHECK_TYPES): Remove struct user_desc. * ldt.c: New file. * Makefile.am (strace_SOURCES): Add ldt.c. * mem.c: Do not include <asm/ldt.h>. (print_ldt_entry): Remove. (sys_modify_ldt, sys_set_thread_area, sys_get_thread_area): Move... * ldt.c: ... here. * process.c: Do not include <asm/ldt.h>. (sys_clone) [I386 || X86_64 || X32]: Use print_user_desc.
* Make int3 example in comments more cut-n-pastableDenys Vlasenko2014-04-101-6/+7
| | | | | | | | | 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. Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
* mips: enable decoding of set_thread_areaDmitry V. Levin2014-04-092-2/+6
| | | | | * linux/dummy.h [MIPS]: Do not redirect sys_set_thread_area to printargs. * mem.c [MIPS] (sys_set_thread_area): Define.
* x86_64, x32: enable decoding of modify_ldt, get_thread_area, and set_thread_areaDmitry V. Levin2014-04-091-6/+6
| | | | | * linux/dummy.h [X86_64 || X32]: Do not redirect sys_modify_ldt, sys_get_thread_area, and sys_set_thread_area to printargs.
* x32: decode clone LDT user_desc entries for x86 processesDmitry V. Levin2014-04-092-8/+8
| | | | | | | | * mem.c [X32]: Include asm/ldt.h. [X32] (print_ldt_entry, sys_modify_ldt, sys_set_thread_area, sys_get_thread_area): Define. * process.c [X32]: Include asm/ldt.h. (sys_clone) [X32]: Decode LDT entry if current_personality == 1.
* x86-64: decode clone LDT user_desc entries for x86 processesElliott Hughes2014-04-092-16/+21
| | | | | | | | | | | * mem.c [X86_64]: Include asm/ldt.h. [X86_64] (print_ldt_entry, sys_modify_ldt, sys_set_thread_area, sys_get_thread_area): Define. * process.c [X86_64]: Include asm/ldt.h. (sys_clone) [X86_64]: Decode LDT entry if current_personality == 1. Signed-off-by: Elliott Hughes <enh@google.com> Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
* x32: fix clone(2) argument order for x86 processesDmitry V. Levin2014-04-091-2/+2
| | | | | | | Apply the same fix that was made for x86_64. * process.c [X32] (ARG_CTID, ARG_TLS): Take current personality into account.
* x86-64: fix clone(2) argument order for x86 processesElliott Hughes2014-04-091-2/+8
| | | | | | | | | | | Without this patch, strace claims that parent_tidptr == tls, which is clearly wrong. It is expected that parent_tidptr == child_tidptr. * process.c [X86_64] (ARG_CTID, ARG_TLS): Take current personality into account. Signed-off-by: Elliott Hughes <enh@google.com> Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
* aarch64: Fix decoding of arm struct stat64Elliott Hughes2014-04-061-11/+19
| | | | | | | | 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. Signed-off-by: Elliott Hughes <enh@google.com>
* ARM EABI: disable OABI support by defaultDmitry V. Levin2014-03-202-3/+14
| | | | | | | | | 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.