summaryrefslogtreecommitdiff
path: root/util.c
Commit message (Collapse)AuthorAge
* Alias sys_vfork to sys_forkDmitry V. Levin2014-05-12
| | | | | | | | | * 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.
* Fix preadv/pwritev offset decodingDmitry V. Levin2014-04-17
| | | | | | | | | | | | | | | | | | | | * 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>
* Delete old PTRACE_{PEEK,POKE}USR logicMike Frysinger2013-12-31
| | | | | | | | | | | 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. * process.c: Delete PTRACE_PEEKUSR/PTRACE_POKEUSR defines. * signal.c: Likewise. * syscall.c: Delete PTRACE_PEEKUSR define. * util.c: Likewise.
* Fix select decoding on e.g. 32-bit ppc process by 64-bit strace.Denys Vlasenko2013-11-09
| | | | | | | | | | 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>
* Work around conflict between <sys/ptrace.h> and <linux/ptrace.h>Ali Polatel2013-09-26
| | | | | | | | | | | | | | | 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>
* Add support for ARC Cores from SynopsysVineet Gupta2013-09-11
| | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* Rename ia32 to ia64_ia32mode, and make it bool, not longDenys Vlasenko2013-07-01
| | | | | | Grepping for just ia32 was turning up many false positives. Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
* Change upeek() to take pid, not full tcp.Denys Vlasenko2013-06-28
| | | | | | This will be used by next change. Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
* ARM OABI: fix 64-bit arguments decodingDmitry V. Levin2013-05-06
| | | | | | | | ARM OABI and ARM EABI have different function parameters passing rules, see commit v4.6-11-g7a5b08f for details. * util.c (printllval): Do not align argument number in case of ARM OABI. * file.c (sys_fadvise64_64): Likewise.
* printllval: fix 64bit unpacking on mips/o32 and xtensaMike Frysinger2013-05-06
| | | | | | | | | | | | The mips/o32 ABI and xtensa arch also do 64bit aligning, so add it to the printllval list for this. Normally for sys_fadvise64_64 we'd handle the same list of arches, but mips/o32 ABI is funky and doesn't shift -- it has 7 args. So just add xtensa to it. * file.c (sys_fadvise64_64): Add XTENSA to the shifted list. * util.c (printllval): Add LINUX_MIPSO32 and XTENSA to the shifted list.
* printxval: support more architecturesDmitry V. Levin2013-05-04
| | | | | | * configure.ac: Define SIZEOF_LONG_LONG. * util.c (printllval): Handle all architectures with sizeof(long) > 4 and sizeof(long) == sizeof(long long).
* Fix building for sparc64 targetsMike Frysinger2013-05-04
| | | | * util.c (printllval): Handle SPARC64 define.
* Fix building for mips n64 targetsMike Frysinger2013-05-04
| | | | * util.c (printllval): Handle LINUX_MIPSN64 define.
* arm, aarch64, ppc: fix printllval-based decodersDmitry V. Levin2013-05-03
| | | | | | | | * util.c (printllval) [ARM || POWERPC]: Align argument number. [AARCH64]: Align argument number in 32bit mode. * file.c (sys_fadvise64_64) [ARM || POWERPC]: Remove no longer needed printllval workaround. [AARCH64]: Fix printing POSIX_FADV_* constants in 32bit mode.
* Decode mtd/ubi ioctlsMike Frysinger2013-05-02
| | | | | | | | | | | | | | | | | Been playing with UBI of late and it'd help if I could see what it was doing. Not entirely sure about the decoding of UBI_IOCVOLUP -- it takes a pointer to a 64bit value, not a strict. * util.c (MAX, MIN): Move to ... * defs.h (MAX, MIN): ... here. (CLAMP): Define. (ubi_ioctl): New prototype. * ioctl.c (ioctl_decode): Call ubi_ioctl when code is 'o' or 'O'. * mtd.c: Include ubi user API header. (ubi_volume_types): New enum decode. (ubi_volume_props): Likewise. (ubi_ioctl): Define. * linux/ubi-user.h: Import from linux 3.8.
* x32: fix printllval-based decoders of i386 syscallsDmitry V. Levin2013-05-02
| | | | * util.c (printllval) [X32]: Handle i386 personality.
* printllval: handle s390xMike Frysinger2013-05-01
| | | | | | | | | | | | | | This is a 64bit arch w/no personalities, so fix printing. It can now trace a simple call like readahead: $ cat test.c main(){readahead(-1, (unsigned long long)1 << 50, 0);} $ gcc test.c $ ./strace -ereadahead ./a.out readahead(-1, 1125899906842624, 0) = -1 EBADF (Bad file descriptor) * util.c (printllval): Handle S390X define. Signed-off-by: Mike Frysinger <vapier@gentoo.org>
* AArch64: Fix printing of long long valueAndreas Schwab2013-03-31
| | | | | | | * util.c (printllval): Fix printing of long long values on AArch64. Signed-off-by: Andreas Schwab <schwab@suse.de>
* Add support for the XTENSA architectureChris Zankel2013-03-25
| | | | | | | | | | | | | | * configure.ac: Add XTENSA to the list of supported architectures. * defs.h: Add XTENSA support. * linux/xtensa/syscallent.h: New file. * linux/xtensa/ioctlent.h.in: Likewise. * process.c (struct_user_offsets): Add XTENSA support. * signal.c (sys_sigreturn): Likewise. * syscall.c (printcall, get_scno, get_syscall_args, get_syscall_result, get_error): Likewise. * util.c (change_syscall): Likewise. Signed-off-by: Chris Zankel <chris@zankel.net>
* Open-code isprint(c) and isspace(c)Denys Vlasenko2013-03-06
| | | | | | | | | | | | | | | | | | | | We don't call setlocale, thus we always use C locale. But libc supports various other locales, and therefore its ctype interface is general and at times inefficient. For example, in glibc these macros result in function call, whereas for e.g. isprint(c) just c >= ' ' && c <= 0x7e suffices. By open-coding ctype checks (we have only 4 of them) we avoid function calls, we get smaller code: text data bss dec hex filename 245127 680 5708 251515 3d67b strace_old 245019 676 5708 251403 3d60b strace and we don't link in ctype tables (beneficial for static builds). Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* Stop using a large static buffer in getfdpathDenys Vlasenko2013-03-06
| | | | | | | | text data bss dec hex filename 245075 680 9836 255591 3e667 strace_old 245143 680 5708 251531 3d68b strace Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* Add support for Imagination Technologies MetaJames Hogan2013-03-05
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Add support for Imagination Technologies Meta architecture (the architecture/ABI is usually referred to as metag in code). The Meta Linux kernel port is in the process of being upstreamed for v3.9 so it uses generic system call numbers. sys_lookup_dcookie writes a filename to buffer argument, so I've set TF flag. nfsservctl appears to be set to sys_ni_syscall in asm-generic/unistd.h so I've left it blank. truncate64/ftruncate64/pread64/pwrite64/readahead have unaligned 64bit args which are packed tightly on metag, so less arguments on metag. fchdir/llseek takes a file descriptor so s/TF/TD/ sync_file_range has 2 64bit args so uses 6 args, so s/4/6/ timerfd_create/msgget/msgctl/msgrcv/semget/segtimedop/semop/shmget/ shmctl/shmat/shmdt/recvmsg/migrate_pages have different number of args. oldgetrlimit is just getrlimit for metag. add TM flag to various memory syscalls. metag doesn't directly use sys_mmap_pgoff for mmap2. prlimit64/process_vm_readv/process_vm_writev take a pid so add TP flag. fanotify_init doesn't appear to take a file descriptor so remove TD. Add kcmp syscall. Signed-off-by: James Hogan <james.hogan@imgtec.com> Cc: Christian Svensson <blue@cmd.nu> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* umovestr: speed up check for NUL byte in the fetched wordDenys Vlasenko2013-03-01
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* tile: handle printllval like x86_64 or powerpc64Chris Metcalf2013-03-01
| | | | | | | | | | Without this fix the tilegx build fails when it hits the new #error about SIZEOF_LONG > 4. * util.c (printllval): Fix printing of long long values on TILE. Signed-off-by: Chris Metcalf <cmetcalf@tilera.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* Cleanup umoven and umovestrDmitry V. Levin2013-02-26
| | | | | | | | | | | | | | | Cleanup sloppy error handling. First, EFAULT kind of errors from process_vm_readv by itself is not something unusual, so a warning message will not be issued unless a short read is detected. Second, clients of umoven and umovestr are not prepared to detect and handle short reads that can happen in these functions. The most safe way to handle them is to return an error code. * util.c (umoven, umovestr): Cleanup handling of errors coming from process_vm_readv and PTRACE_PEEKDATA.
* Mass replace error_msg("%s", "literal") -> error_msg("literal")Denys Vlasenko2013-02-26
| | | | | | | There is no need to print literal strings through "%s". Only untrusted strings such as filenames need that. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* Make umoven report success as 0, not >=0, stop returning success on partial ↵Ben Noordhuis2013-02-26
| | | | | | | | | | | | | | | | | | | | | | reads umoven() uses process_vm_readv() when available but it returns the return value of that syscall, which is the number of bytes copied, while its callers expect it to simply return zero on success. It was causing syscalls that take a user-space argument to print the abbreviated version, e.g.: epoll_ctl(5, EPOLL_CTL_ADD, 10, {...}) Instead of: epoll_ctl(5, EPOLL_CTL_ADD, 10, {EPOLLIN, {u32=10, u64=10}}) * util.c (umoven): Make umove[n] report success as 0, not >=0, stop returning "success" on partial reads. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* Fix wrong offset display in dumpstrDenys Vlasenko2013-02-22
| | | | | | | BTW, the new code from prev commit is 5 times faster than old one :) Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* Fix a bug in dumpstr (no null termination). Essentially rewrote dumpstrDenys Vlasenko2013-02-22
| | | | | | | | | | | | | | | | | | | This is a 14 year old bug (!). It wasn't biting us merely because outstr[80] was static, thus ended up in bss and whatever was after it "accidentally" provided the NUL byte. When dumpstr was changed to use on-stack buffer, the bug reared its ugly head. This is a rewrite which is smaller and should be significantly faster for _long_ strings. text data bss dec hex filename 244627 680 10860 256167 3e8a7 strace.t9/strace 244563 680 10860 256103 3e867 strace.ta/strace * util.c (dumpstr): Rewrite to be faster and smaller. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* Eliminate many SCNO_IS_VALID checksDenys Vlasenko2013-02-21
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | By adding tcp->s_ent pointer tot syscall table entry, we can replace sysent[tcp->scno] references by tcp->s_ent. More importantly, we may ensure that tcp->s_ent is always valid, regardless of tcp->scno value. This allows us to drop SCNO_IS_VALID(tcp->scno) checks before we access syscall table entry. We can optimize (qual_flags[tcp->scno] & QUAL_foo) checks with a similar technique. Resulting code shrink: text data bss dec hex filename 245975 700 19072 265747 40e13 strace.t3/strace 245703 700 19072 265475 40d03 strace.t4/strace * count.c (count_syscall): Use cheaper SCNO_IN_RANGE() check. * defs.h: Add "int qual_flg" and "const struct sysent *s_ent" to struct tcb. Remove "int u_nargs" from it. Add UNDEFINED_SCNO constant which will mark undefined scnos in tcp->qual_flg. * pathtrace.c (pathtrace_match): Drop SCNO_IS_VALID check. Use tcp->s_ent instead of sysent[tcp->scno]. * process.c (sys_prctl): Use tcp->s_ent->nargs instead of tcp->u_nargs. (sys_waitid): Likewise. * strace.c (init): Add compile-time check that DEFAULT_QUAL_FLAGS constant is consistent with init code. * syscall.c (decode_socket_subcall): Use tcp->s_ent->nargs instead of tcp->u_nargs. Set tcp->qual_flg and tcp->s_ent. (decode_ipc_subcall): Likewise. (printargs): Use tcp->s_ent->nargs instead of tcp->u_nargs. (printargs_lu): Likewise. (printargs_ld): Likewise. (get_scno): [MIPS,ALPHA] Use cheaper SCNO_IN_RANGE() check. If !SCNO_IS_VALID, set tcp->s_ent and tcp->qual_flg to default values. (internal_fork): Use tcp->s_ent instead of sysent[tcp->scno]. (syscall_fixup_for_fork_exec): Remove SCNO_IS_VALID check. Use tcp->s_ent instead of sysent[tcp->scno]. (get_syscall_args): Likewise. (get_error): Drop SCNO_IS_VALID check where it is redundant. (dumpio): Drop SCNO_IS_VALID check where it is redundant. Use tcp->s_ent instead of sysent[tcp->scno]. (trace_syscall_entering): Use (tcp->qual_flg & UNDEFINED_SCNO) instead of SCNO_IS_VALID check. Use tcp->s_ent instead of sysent[tcp->scno]. Drop SCNO_IS_VALID check where it is redundant. Print undefined syscall name with undefined_scno_name(tcp). (trace_syscall_exiting): Likewise. * util.c (setbpt): Use tcp->s_ent instead of sysent[tcp->scno]. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* Fix compiler warningsDenys Vlasenko2013-02-19
| | | | | | | | | With constant current_wordsize == 4 and 32-bit longs, gcc was spooked by "1ul << (8 * current_wordsize)" = "1ul << 32". Make such places conditional on SIZEOF_LONG > 4. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* Remove broken HAVE_LONG_LONG conditionalsDenys Vlasenko2013-02-17
| | | | | | | | | | | | | | | | We use printllval without HAVE_LONG_LONG guards in many places, but define it only if HAVE_LONG_LONG. This means that on !HAVE_LONG_LONG systems we won't build for some time now. * defs.h: Remove HAVE_LONG_LONG guard around LONG_LONG() macro and printllval() function declaration. * util.c: Remove HAVE_LONG_LONG guard around printllval() function definition. (printllval): Add compile-time error check for using wrong if branch. Explain places where we deliberately use mismatched types for printf formats. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* 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.