summaryrefslogtreecommitdiff
path: root/util.c
Commit message (Collapse)AuthorAge
* Remove unnecessary "return 0" statementsDenys Vlasenko2013-02-15
| | | | | | * util.c (change_syscall): Remove dummy "return 0"s. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* Add support for the OpenRISC 1000 platformChristian Svensson2013-02-14
| | | | | | | | | | | | | | | | | | | | | * configure.ac: Added or1k architecture.. * defs.h: Added or1k to use register reading system. * linux/or1k/ioctlent.h.in: Use i386 ioctls. * linux/or1k/syscallent.h: New file. * process.c: Added or1k register defs to struct_user_offsets[]. * syscall.c: Added or1k_io iovec for or1k GETREGSET,   regset structure for or1k.   (printcall): Added handling for or1k.   (get_regs): Likewise.   (get_scno): Likewise.   (get_syscall_args): Likewise.   (get_syscall_result): Likewise. (get_error): Likewise. * util.c (change_syscall): Added dummy handling for or1k. * system.c (sys_or1k_atomic): New function (or1k specific syscall). Signed-off-by: Christian Svensson <blue@cmd.nu> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* Remove hacks for old kernels for architectures which require new kernelsDenys Vlasenko2013-02-12
| | | | | | | | * util.c (change_syscall): For MICROBLAZE, replace code with dummy "return 0" and a comment explaining why that is ok for this architecture. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* Remove hacks for old kernels for architectures which require new kernelsDenys Vlasenko2013-02-12
| | | | | | | | | * defs.h: Do not define TCB_WAITEXECVE for AARCH64. * util.c (change_syscall): For AARCH64 and X32, replace code with dummy "return 0" and a comment explaining why that is ok for these architectures. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* Remove old kernel hacks for architectures which require new kernelsDenys Vlasenko2013-02-12
| | | | | | | | | * defs.h: Do not define TCB_WAITEXECVE for AVR32, BFIN and TILE. * util.c (change_syscall): For AVR32, BFIN and TILE, replace code with dummy "return 0" and a comment explaining why that is ok for these architectures. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* If we are on a glibc system, assume it's at least glibc 2.1Denys Vlasenko2013-02-08
| | | | | | | | | | | It is not likely anyone uses glibc older that that: glibc 2.1.1 was released in 1999 * net.c: Remove test for glibc >= 2.1. * signal.c: Remove code which is compiled only for glibc < 2.1. * util.c: Likewise. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* Add tilegx support to straceChris Metcalf2013-02-05
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | tilegx support has been in the kernel since 3.0. In addition, fix some issues with the tilepro support already present in strace, primarily the decision to use the <asm/unistd.h> numbering space for system calls. * defs.h [TILE]: Include <asm/ptrace.h> and provide an extern struct pt_regs tile_regs for efficiency. Provide compat 32-bit personality via SUPPORTED_PERSONALITIES, PERSONALITY0_WORDSIZE, PERSONALITY1_WORDSIZE, and DEFAULT_PERSONALITY. * linux/tile/errnoent1.h: New file, includes linux/errnoent.h. * linux/tile/ioctlent1.h: New file, includes linux/ioctlent.h. * linux/tile/signalent1.h: New file, includes linux/signalent.h. * linux/tile/syscallent.h: Update with new asm-generic syscalls. The version previously committed was the from the first tile patch to LKML, which subsequently was changed to use <asm-generic/unistd.h>. * linux/tile/syscallent1.h: Copy from linux/tile/syscallent.h. * mem.c (addtileflags) [TILE]: use %ld properly for a "long" variable. * process.c [TILE]: Choose clone arguments correctly and properly suppress all "struct user" related offsets in user_struct_offsets. * signal.c [TILE]: Use tile_regs not upeek. * syscall.c (update_personality) [TILE]: Print mode. (PT_FLAGS_COMPAT) [TILE]: Provide if not in system headers. (tile_regs) [TILE]: Define 'struct pt_regs' variable to hold state. (get_regs) [TILE]: use PTRACE_GETREGS to set tile_regs rather than using upeek. (get_scno) [TILE]: Set personality. (get_syscall_args) [TILE]: Use tile_regs. (get_syscall_result) [TILE]: Update tile_regs. (get_error) [TILE]: Use tile_regs. (printcall) [TILE]: Print pc. (arg0_offset, arg1_offset, restore_arg0, restore_arg1) [TILE]: Properly handle tile call semantics and support tilegx. Signed-off-by: Chris Metcalf <cmetcalf@tilera.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* Optimize out PTRACE_PEEKUSER with -iDenys Vlasenko2013-02-05
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | strace -i was fetching PC with a separate PEEKUSER despite having GETREGS data: ptrace(PTRACE_GETREGS, 22331, 0, 0x8087f00) = 0 ptrace(PTRACE_PEEKUSER, 22331, 4*EIP, [0x80dd7b7]) = 0 write(3, "[080dd7b7] ioctl(0, SNDCTL_TMR_T"..., 82) = 82 ptrace(PTRACE_SYSCALL, 22331, 0, SIG_0) = 0 Now it does this: ptrace(PTRACE_GETREGS, 22549, 0, 0x8087ea0) = 0 write(3, "[080dd7b7] ioctl(0, SNDCTL_TMR_T"..., 82) = 82 ptrace(PTRACE_SYSCALL, 22549, 0, SIG_0) = 0 Analogous improvement in sys_sigreturn() is also implemented. * defs.h: Declare extern struct pt_regs regs for SPARC[64] and ARM. Declare clear_regs(), get_regs() and get_regs_error flag variable. * strace.c (trace): Call get_regs(pid) as soon as we know the tcb and that it is stopped. * syscall.c (get_regs): New function. Used to fetch registers early, just after tracee has stopped. (printcall): Move it here from util.c. Use global regs.REG data, if available on the arch, instead of re-fetching it. (get_scno): Use global regs.REG data. (get_syscall_result): Likewise. * signal.c (sys_sigreturn): Likewise. * util.c (printcall): Moved to syscall.c. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* Fix glibc version checksJohn Spencer2012-12-06
| | | | | * util.c: Check if __GLIBC__ is defined before using it. * signal.c: Likewise. Fix __GLIBC_MINOR__ checks.
* Add state argument to change_syscall and fix SPARCJames Hogan2012-11-29
| | | | | | | | | | | | | | | | | Add a state argument to change_syscall() so that SPARC can modify that instead of read-modify-writing the whole register set. This function is always called within an arg_setup/arg_finish_change sequence which on certain architectures like SPARC will also be doing a read-modify-write. This prevents the second write (from arg_finish_change) from undoing the effects of the change_syscall call. * util.c (change_syscall): Move below definition of arg_setup_state. Add state argument. [SPARC || SPARC64] Change to set state->u_regs[U_REG_G1] rather than read-modify-writing it with PTRACE_GETREGS and PTRACE_SETREGS. (setbpt, clearbpt): Pass state argument to change_syscall. Signed-off-by: James Hogan <james.hogan@imgtec.com>
* Use perror_msg instead of perrorDmitry V. Levin2012-09-28
| | | | | | | * signal.c (sys_sigreturn): Use perror_msg instead of perror. * strace.c (tprintf, tprints, detach, startup_attach): Likewise. * syscall.c (get_scno): Likewise. * util.c (umoven, umovestr): Likewise.
* process_vm_readv may return ESRCH if tracee was killed, don't complainDenys Vlasenko2012-09-27
| | | | | | | | | | Discovered by running test/sigkill_rain under strace. * util.c (umoven): Do not emit error message if process_vm_readv fails with ESRCH. (umovestr): LikeWise. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* On clearing "breakpopint", restore syscall number tooDenys Vlasenko2012-05-14
| | | | | | | | | This fixes Fedora bug 659382. Low risk: this code is not supposed to be used on any non-acient kernel. * util.c (clearbpt): Restore syscall number too. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* util: fix building when glibc has a stub process_vm_readvMike Frysinger2012-05-05
| | | | | | | | | | | | | | | | | | | | If you have a newer glibc which provides process_vm_readv, but it is built against older kernel headers which lack __NR_process_vm_readv, the library will contain a stub implementation that just returns ENOSYS. Autoconf checks for this case explicitly and will declare it as unavailable. So we end up in a case where the headers provide the prototype, but autoconf has not defined HAVE_PROCESS_VM_READV, so we hit the same build failure again: util.c:738:16: error: static declaration of 'process_vm_readv' follows non-static declaration /usr/include/bits/uio.h:58:16: note: previous declaration of 'process_vm_readv' was here So rename our local function to something unique, and add a define so the callers all hit the right place. * util.c (strace_process_vm_readv): Rename from process_vm_readv. (process_vm_readv): Define to strace_process_vm_readv. Signed-off-by: Mike Frysinger <vapier@gentoo.org>
* Fix printstr's len parameter widthDenys Vlasenko2012-04-28
| | | | | | | | | | | | We often pass syscall params and other long-sized values as printstr(len). Truncating them to int may be a bad thing. * defs.h: Change len parameter's type from int to long in string_quote and printstr function declarations. * util.c (string_quote): Special-case only len==-1, not all len<0. (printstr): Likewise. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* Decode /dev/loop ioctlsMike Frysinger2012-04-18
| | | | | | | | | | | | | | | Needed to debug some losetup failures, and it's easier when you can see what the kernel is getting vs what you think you're sending, so add some decoders for those ioctls. * loop.c: New file. * Makefile.am (strace_SOURCES): Add loop.c. * defs.h (loop_ioctl): New prototype. (string_quote): Likewise. * ioctl.c (ioctl_decode): Call loop_ioctl when code is 'L'. * util.c (string_quote): Remove static keyword. Signed-off-by: Mike Frysinger <vapier@gentoo.org>
* Add x32 support to straceH.J. Lu2012-04-16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | X32 support is added to Linux kernel 3.4. In a nutshell, x32 is x86-64 with 32bit pointers. At system call level, x32 is also identical to x86-64, as shown by many changes like "defined(X86_64) || defined(X32)". The main differerence bewteen x32 and x86-64 is off_t in x32 is long long instead of long. This patch adds x32 support to strace. Tested on Linux/x32. * configure.ac: Support X32. * defs.h: Set SUPPORTED_PERSONALITIES to 3 for X86_64, Set PERSONALITY2_WORDSIZE to 4 for X86_64. Add tcb::ext_arg for X32. * file.c (stat): New for X32. (sys_lseek): Use 64-bit version for X32. (printstat64): Check current_personality != 1 for X86_64. * ipc.c (indirect_ipccall): Check current_personality == 1 for X86_64. * mem.c (sys_mmap64): Also use tcp->u_arg for X32. Print NULL for zero address. Call printllval for offset for X32. * pathtrace.c (pathtrace_match): Don't check sys_old_mmap for X32. * process.c (ARG_FLAGS): Defined for X32. (ARG_STACK): Likewise. (ARG_PTID): Likewise. (change_syscall): Handle X32. (struct_user_offsets): Support X32. (sys_arch_prctl): Likewise. * signal.c: Include <asm/sigcontext.h> for X32. (SA_RESTORER): Also define for X32. * syscall.c (update_personality): Support X32 for X86_64. (is_restart_error): Likewise. (syscall_fixup_on_sysenter): Likewise. (get_syscall_args): Likewise. (get_syscall_result): Likewise. (get_error): Likewise. (__X32_SYSCALL_BIT): Define if not defined. (__X32_SYSCALL_MASK): Likewise. (get_scno): Check DS register value for X32. Use __X32_SYSCALL_MASK on X32 system calls. * util.c (printllval): Use ext_arg for X32. (printcall): Support X32. (change_syscall): Likewise. (arg0_offset): Likewise. (arg1_offset): Likewise. * Makefile.am (EXTRA_DIST): Add linux/x32/errnoent.h, linux/x32/ioctlent.h.in, linux/x32/signalent.h, linux/x32/syscallent.h, linux/x86_64/errnoent2.h, linux/x86_64/ioctlent2.h, linux/x86_64/signalent2.h and linux/x86_64/syscallent2.h. * linux/x32/errnoent.h: New. * linux/x32/ioctlent.h.in: Likewise. * linux/x32/signalent.h: Likewise. * linux/x32/syscallent.h: Likewise. * linux/x86_64/errnoent2.h: Likewise. * linux/x86_64/ioctlent2.h: Likewise. * linux/x86_64/signalent2.h: Likewise. * linux/x86_64/syscallent2.h: Likewise. Signed-off-by: H.J. Lu <hongjiu.lu@intel.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* printstr: check for potential integer overflowDmitry V. Levin2012-03-25
| | | | | * util.c (printstr): Check for potential integer overflow during outstr buffer size calculation.
* Robustify parsing of numbers from stringsDmitry V. Levin2012-03-25
| | | | | | | | | | | | * defs.h (string_to_uint): New prototype. * util.c (string_to_uint): New function. * strace.c (error_opt_arg): New function. (process_opt_p_list): Use string_to_uint instead of atoi. Terminate in case of invalid process id. (init): Use string_to_uint instead of atoi. Use error_opt_arg in case of invalid option argument. * syscall.c (qual_syscall, qual_signal, qual_desc): Use string_to_uint instead of atoi.
* Make ptrace_restart() static. No code changesDenys Vlasenko2012-03-20
| | | | | | | | * defs.h: Remove ptrace_restart() declaration. * strace.c (ptrace_restart): Move its definition here. * util.c (ptrace_restart): Remove its definition. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* Optimize code if we have only one personalityDenys Vlasenko2012-03-19
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | On i386: text data bss dec hex filename 238025 672 18980 257677 3ee8d strace.before 237389 704 18944 257037 3ec0d strace * defs.h: Define PERSONALITY0_WORDSIZE as sizeof(long) if not defined. Introduce new define, current_wordsize as (personality_wordsize[current_personality]). Make set_personality() no-op, current_personality constant zero, current_wordsize as PERSONALITY0_WORDSIZE if we have only one personality. * count.c (call_summary): Use current_wordsize instead of personality_wordsize[current_personality]. * desc.c (printflock): Likewise. * file.c (sys_utime): Likewise. * io.c (tprint_iov): Likewise. * process.c (printargv): Likewise. * resource.c (decode_rlimit): Likewise. * signal.c (sys_kill): Likewise. (sys_rt_sigaction): Likewise. * time.c (sprinttv): Likewise. (sprint_timespec): Likewise. (printitv_bitness): Likewise. (tprint_timex): Likewise. (printsigevent): Likewise. * util.c (dumpiov): Likewise. (umoven): Likewise. (umovestr): Likewise. * syscall.c: Initialize sysent to sysent0 etc. Make current_personality, personality_wordsize[], set_personality() conditional on SUPPORTED_PERSONALITIES > 1. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* Remove unused PTRACE_WRITE{TEXT,DATA} constants (they are from SunOS)Denys Vlasenko2012-03-17
| | | | | | * util.c: Remove unused PTRACE_WRITE{TEXT,DATA} constants. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* Remove unused constants. No code changesDenys Vlasenko2012-03-17
| | | | | | | * syscall.c: Remove unused ENOIOCTLCMD constant. Fix indentation. * util.c: Remove unused CLONE_STOPPED constant. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* Move change_syscall() to its only user and make it staticDenys Vlasenko2012-03-17
| | | | | | | | * defs.h: Remove declaration of change_syscall(). * process.c (change_syscall): Remove definition of this function. * util.c (change_syscall): Add definition of change_syscall(). Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* Indentation and whitespace fixes. No code changes.Denys Vlasenko2012-03-17
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* Tidy up includes and copyright notices, fix indentationDenys Vlasenko2012-03-16
| | | | | | | | | | | | | | | The files not mentioned in changelog below had only copyright notices fixes and indentation fixes. * defs.h: Include <stdint.h> and <inttypes.h>. * file.c: Do not include <inttypes.h>. Move struct kernel_dirent declaration below top include block. * block.c: Do not include <stdint.h> and <inttypes.h>. * quota.c: Likewise. * desc.c: Likewise. * signal.c: Likewise. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* Remove extra include directives. No code changes.Denys Vlasenko2012-03-15
| | | | | | | | | | | | | | | | * defs.h: Include <signal.h> unconditionally. Other files were doing it unconditionally, so no harm done. * bjm.c: Remove system includes which are already included by defs.h. * pathtrace.c: Likewise. * process.c: Likewise. * signal.c: Likewise. * strace.c: Likewise. * stream.c: Likewise. * syscall.c: Likewise. * system.c: Likewise. * util.c: Likewise. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* Pass addr=0 instead of 1 into restarting ptrace callsDenys Vlasenko2012-03-08
| | | | | | | | | | | | | | | | | | | | | While we are at it, fold do_ptrace into its lone caller. We no longer set tcp->ptrace_errno = ESRCH on ESRC error in upeek. Other code paths where ptrace fails wern't doing it, and the code which checks tcp->ptrace_errno even assumes it is never set to ESRCH. (It was me who added this code sometime ago, so it was my fault that it was a bit messy) I ran sigkill_rain test and verified that unfinished syscalls are still handled correctly. * util.c (ptrace_restart): Do not pass addr=1 to ptrace(), pass 0 instead. I have no idea why we were passing 1. Ptrace documentation says that addr parameter is ignored. (do_ptrace): Remove this function. (upeek): Use ptrace() instead of do_ptrace(). * defs.h: Remove do_ptrace() declaration. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* Trivial tweaks to error messagesDenys Vlasenko2012-03-08
| | | | | | | | | | | | | | * strace.c (test_ptrace_setoptions_followfork): Use kill_save_errno instead of kill. (trace): Use perror_msg instead of perror. * count.c (set_sortby): Use error_msg_and_die instead of fprintf. * syscall.c (qualify): Likewise. * util.c (ptrace_restart): Expand error message. (umoven): Likewise. (umovestr): Likewise. (upeek): Use perror_msg instead of sprintf + perror. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* Compress blank linesDmitry V. Levin2012-02-25
| | | | | | Suppress repeated empty lines left after automated code removal. This change was made by filtering every source code file through "cat -s".
* Remove a few more code parts which are unused on LinuxDenys Vlasenko2012-02-25
| | | | | | | | | | | | | | | | | This change is abapted from Dmitry's changes to remove support for non-Linux architectures. * Makefile.am: Remove if LINUX/endif pairs. * defs.h: Remove stream_ioctl() declaration. * ioctl.c (ioctl_decode): Remove 'ifdef HAVE_SYS_STREAM_H' block. * resource.c: Use 'defined(FOO)' instead of 'defined FOO' form. * util.c: Likewise. * signal.c: Remove conditional includes which are never used on Linux. * stream.c: Likewise. * file.c: Remove excessive empty lines. Signed-off-by: Dmitry V. Levin <ldv@altlinux.org> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* Reindent preprocessor directives in util.c; fix style.Denys Vlasenko2012-02-25
| | | | | | | | * util.c: Fix indentation of preprocessor directives broken by automatic removal of non-Linux code. Fix style to use consistent defined(FOO) instead of defined (FOO). Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* Cleanup after non-Linux code removal.Denys Vlasenko2012-02-25
| | | | | | | | | Conditions such as defined(LINUX) are always true now, defined(FREEBSD) etc are always false. When if directive has them as subexpressions, it can be simplified. Another trivial changes here are fixes for directive indentation. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* Automated removal of non-Linux codeDenys Vlasenko2012-02-25
| | | | | | | | | | This change is generated by running every source through the following command: unifdef -DLINUX -Dlinux -USUNOS4 -USVR4 -UUNIXWARE -UFREEBSD -USUNOS4_KERNEL_ARCH_KLUDGE -UHAVE_MP_PROCFS -UHAVE_POLLABLE_PROCFS -UHAVE_PR_SYSCALL -UUSE_PROCFS file.c Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* When accessing data blocks, truncate addr to wordsizeDenys Vlasenko2012-02-25
| | | | * util.c (umoven): Truncate addr to wordsize before use.
* Remove initialization of native_scno fieldDmitry V. Levin2012-02-20
| | | | | | | | | | * linux/i386/syscallent.h: Remove native_scno initialization for clone, fork and vfork. * linux/ia64/syscallent.h (sys_fork, sys_vfork): Remove redirections to printargs. * linux/syscall.h [IA64]: Do not define SYS_fork and SYS_vfork. * util.c (printcall) [IA64]: Likewise. (setbpt): Use sys_func to check for clone, fork and vfork syscalls.
* util: check for process_vm_readv in C libraryMike Frysinger2012-02-14
| | | | | | | | | | glibc-2.15 provides process_vm_readv, so trying to provide it ourselves with that version fails. * configure.ac (AC_CHECK_FUNCS): Add process_vm_readv. * util.c: Handle HAVE_PROCESS_VM_READV. Signed-off-by: Mike Frysinger <vapier@gentoo.org>
* Simple optimizationsDenys Vlasenko2012-01-29
| | | | | | | | | | | | | | | | 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>
* Add experimental code to use PTRACE_SEIZE, disabled by defaultDenys Vlasenko2012-01-29
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* process_vm_readv gets EINVAL if process is gone (SIGKILLed). Don't complain.Denys Vlasenko2012-01-28
| | | | | | | * util.c (umoven): Don't complain on EINVAL from process_vm_readv. (umovestr): Likewise. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* Use process_vm_readv instead of PTRACE_PEEKDATA to read data blocksDenys Vlasenko2012-01-28
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* Improve code readability (logic is unchanged)Denys Vlasenko2012-01-21
| | | | | | | | | * 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>
* Change umovestr API: return > 0 instead of 0 if NUL was seenDenys Vlasenko2012-01-20
| | | | | | | | | | | | * 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>
* Reduce bss usage and speed up string printingDenys Vlasenko2012-01-19
| | | | | | | | | | | | | | | | 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>
* Enhance decoding for personalities with small wordsizeDmitry V. Levin2011-12-26
| | | | | | * 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.
* Remove unreachable code in umoven() and umovestr().Dmitry V. Levin2011-10-11
| | | | | | * util.c (umoven, umovestr): Remove unreachable code. Reported-by: Weichuan Yan <wchyan@marvell.com>
* Trivial fixes on error pathsDenys Vlasenko2011-09-02
| | | | | | | | * 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>
* Roll back "die on malloc failure" behaviour a bitDenys Vlasenko2011-09-01
| | | | | | | | | | | | | | | | | | 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>
* Add stpcpy to autoconf machineryDenys Vlasenko2011-09-01
| | | | | | | | * 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>
* Use tprints with literal strings, it may be faster than tprintfDenys Vlasenko2011-09-01
| | | | | | | | | | | | | | | | | | | | | | | | | | | * 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>