Commit Graph

238 Commits

Author SHA1 Message Date
b172a94d02 Add a new helper function umove_ulong_array_or_printaddr
* defs.h (umove_ulong_array_or_printaddr): New prototype.
* util.c (umove_ulong_array_or_printaddr): New function.
* desc.c (sys_pselect6): Use it instead of open-coding
a proxy struct parser for different personalities.
* io.c (tprint_iov_upto): Use it instead of open-coding
a struct iovec parser for different personalities.
* kexec.c (print_kexec_segments): Use it instead of open-coding
a struct kexec_segment parser for different personalities.
(print_seg): Pass arguments using an array.
2015-09-15 11:23:27 +00:00
09a1a5a2ca Rename umove_long_or_printaddr to umove_ulong_or_printaddr
Rename the recently added function to reflect what kind of data type
it actually deals with: unsigned long int, without sign extension.

* defs.h (umove_long_or_printaddr): Rename to umove_ulong_or_printaddr,
chage 3rd argument to unsigned long *.
* util.c (umove_long_or_printaddr): Likewise.
* aio.c (sys_io_submit): Update callers.
2015-09-14 23:02:29 +00:00
13c2173393 Fix multiple personalities support in parser of io_submit syscall
Introduce a new helper function to fetch tracee's long integers
and use it to fix multiple personalities support in io_submit parser.

* defs.h (umove_long_or_printaddr): New prototype.
* util.c (umove_long_or_printaddr): New function.
* aio.c (sys_io_submit): Use it to fetch tracee's pointers.
* tests/aio.c: New file.
* tests/aio.test: New test.
* tests/Makefile.am (check_PROGRAMS): Add aio.
(TESTS): Add aio.test.
* tests/.gitignore: Add aio.
2015-08-26 21:05:17 +00:00
Mike Frysinger
54646b8e05 decode extend getsockopt/setsockopt options
Currently the code assumes the set of valid options between getsockopt
and setsockopt are exactly the same and thus maintains one list.  The
kernel unfortunately does not do this -- it allows for different opts
between the get and set functions.  See the {g,s}et_opt{min,max} fields
in the various netfilter subcores.

To support this, extend the printxval function to take multiple sets of
xlats as varargs.  Then we add the new get/set lists, and pass them down
in the net code when decoding things.

A simple example is iptables; before:
	getsockopt(4, SOL_IP, 0x40 /* IP_??? */, ...) = 0
	getsockopt(4, SOL_IP, 0x41 /* IP_??? */, ...) = 0
after:
	getsockopt(4, SOL_IP, IPT_SO_GET_INFO, ...) = 0
	getsockopt(4, SOL_IP, IPT_SO_GET_ENTRIES, ...) = 0

If these were setsockopt calls, then 0x40 & 0x41 would be
IPT_SO_SET_REPLACE & IPT_SO_SET_ADD_COUNTERS.

* configure.ac: Check for netfilter headers.
* defs.h (printxvals): New prototype.
(printxval): Change to a define.
* net.c: Include netfilter headers and new sockopts headers.
(print_sockopt_fd_level_name): Add a is_getsockopt argument.  Change SOL_IP
and SOL_IPV6 decoding to use printxvals, and use is_getsockopt to pass more
xlats down.
(getsockopt): Call print_sockopt_fd_level_name with is_getsockopt as true.
(setsockopt): Call print_sockopt_fd_level_name with is_getsockopt as false.
* util.c (printxval): Rename to ...
(printxvals): ... this.  Rewrite to be varargs based.
* xlat/getsockipoptions.in: New xlat list.
* xlat/getsockipv6options.in, xlat/setsockipoptions.in,
xlat/setsockipv6options.in: Likewise.
2015-08-26 12:09:25 +00:00
d77f6693e4 Make printnum_* functions return boolean status
With this change, printnum_* functions return true iff they
successfully fetched necessary data from tracee's memory.

* defs.h (printnum_short, printnum_int, printnum_int64,
printnum_long_int, printpair_int, printpair_int64): Return bool.
* util.c (DEF_PRINTNUM, DEF_PRINTPAIR, printnum_long_int): Likewise.
2015-08-19 13:36:44 +00:00
2479ef0bce Fix printing tracee's long integers
Replace ambiguous printnum_long that used to fetch native long integers
from tracee's memory with printnum_ptr, printnum_slong, and printnum_ulong
that fetch tracee's pointer, signed long, and unsigned long integers.

* defs.h (printnum_long, printpair_long): Remove prototypes.
(printnum_int64, printpair_int64): Remove macros, declare functions
unconditionally.
[SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4] (printnum_long_int):
New prototype.
(printnum_ptr, printnum_slong, printnum_ulong): New macros.
* aio.c (sys_io_setup): Use printnum_ulong.
* block.c (block_ioctl): Use printnum_slong and printnum_ulong.
* get_robust_list.c (sys_get_robust_list): Use printnum_ptr
and printnum_ulong.
* io.c (print_off_t): Remove.
(sys_sendfile): Use printnum_ulong.
* ipc.c (sys_semctl): Use printnum_ptr.
* prctl.c (sys_prctl): Likewise.
* process.c (sys_ptrace): Likewise.
* rtc.c (rtc_ioctl): Use printnum_ulong.
* util.c (printnum_long, printpair_long): Remove.
(printnum_int64, printpair_int64): Define unconditionally.
[SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4] (printnum_long_int):
New function.

Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
Signed-off-by: Elvira Khabirova <lineprinter0@gmail.com>
2015-08-18 16:15:33 +00:00
61b7989a01 umoven_or_printaddr: do not fetch data if not in verbose mode
After this change, umoven_or_printaddr and its callers, including
printnum_* and printpair_*, will not fetch data in !verbose mode.

* util.c (umoven_or_printaddr): Do not call umoven if !verbose.
2015-07-14 22:07:35 +00:00
850ba4b1e9 Change printnum_* printers to honor syserror
With this change, printnum_* printers will not attempt to fetch data
in case of exiting(tcp) && syserror(tcp).
All "at exiting" decoders that call these printers have been made
ready for this change in previous commits.

* util.c (DEF_PRINTNUM, DEF_PRINTPAIR): Use umove_or_printaddr.
* prctl.c (prctl_exit): Use printnum_int and printnum_long.
(sys_arch_prctl): Do not check for syserror.
2015-07-14 21:59:26 +00:00
69127a3a8d Add several generic integer pairs printing functions
Add functions to fetch and print pairs of integer types.
Note that these printers do not attempt to fetch data
in case of exiting(tcp) && syserror(tcp).

printnum_* printers will follow as soon as all callers are made ready
for this change.

* defs.h (printpair_int, printpair_long, printpair_int64): New
prototypes.
* util.c (DEF_PRINTPAIR): New macro.
(printpair_int, printpair_long, printpair_int64): New functions.
2015-07-09 01:41:51 +00:00
c88163e5bd Add two generic integer printing functions
Add printnum_short and printnum_int64 in addition to already existing
printnum_int and printnum_long.

* defs.h (printnum_short, printnum_int64): New prototypes.
* util.c (DEF_PRINTNUM): New macro.
(printnum_int, printnum_long): Use DEF_PRINTNUM.
(printnum_short, printnum_int64): New functions.
2015-07-09 01:35:41 +00:00
332a32619c Add address printing functions
printaddr is a simple function implementing "print NULL or address"
idiom.
umoven_or_printaddr is a wrapper around umoven that has the same return
value semantics as umoven but also prints the address when the data
is not going to be fetched (in case of exiting(tcp) && syserror(tcp))
or cannot be fetched (umoven fails).
umove_or_printaddr is a macro wrapper around umoven_or_printaddr that
mirrors umove wrapper around umoven.

* defs.h (printaddr, umoven_or_printaddr): New prototypes.
(umove_or_printaddr): New macro.
* util.c (printaddr, umoven_or_printaddr): New functions.
2015-07-09 01:21:56 +00:00
d93c4e80b3 Consistenly use #ifdef to check for AC_DEFINE'd macros
* aio.c (print_common_flags): Use #ifdef in the check for
HAVE_STRUCT_IOCB_U_C_FLAGS.
* defs.h: Use #ifdef in the check for HAVE_LITTLE_ENDIAN_LONG_LONG.
* net.c: Use #ifdef in the check for HAVE_SENDMSG.
* syscall.c (dumpio): Likewise.
* printstat.h (DO_PRINTSTAT): Use #ifdef in checks for
HAVE_STRUCT_STAT_ST_* macros.
* util.c: Use #ifdef in checks for HAVE_SYS_XATTR_H.
2015-06-17 20:09:13 +00:00
df3899149e Consistently print OOM diagnostic messages
* bjm.c (sys_query_module): Use error_msg to print OOM diagnostics.
* util.c (dumpiov, dumpstr): Likewise.
2015-05-25 22:25:22 +00:00
3e9d71feaa Introduce memory allocation wrappers
Introduce wrappers to the following functions that do memory allocation:
malloc, calloc, realloc, strdup.

This commit is a follow-up to the related discussions in strace-devel ML:
http://sourceforge.net/p/strace/mailman/message/33618180/
http://sourceforge.net/p/strace/mailman/message/33733470/

* defs.h (xmalloc, xcalloc, xreallocarray, xstrdup): New prototypes.
* xmalloc.c: New file.
* Makefile.am (strace_SOURCES): Add it.
* count.c (count_syscall, call_summary_pers): Use xcalloc.
* desc.c (decode_select): Use xmalloc.
* dirent.c (sys_getdents, sys_getdents64): Likewise.
* net.c (sys_recvmmsg): Use xstrdup.
* pathtrace.c (storepath): Use xreallocarray.
(pathtrace_match): Use xmalloc.
* strace.c (die_out_of_memory): Move to xmalloc.c.
(expand_tcbtab): Use xcalloc and xreallocarray.
(startup_child): Use xstrdup.
(init): Use xmalloc, xcalloc, and xstrdup.
* syscall.c (reallocate_qual): Use xreallocarray.
(qualify): Use xstrdup.
* unwind.c (unwind_tcb_init): Use xmalloc.
(build_mmap_cache): Use xcalloc, xreallocarray, and xstrdup.
(get_symbol_name): Use xreallocarray.
(stacktrace_walk, queue_put): Use xmalloc.
* util.c (printstr): Use xmalloc.
* vsprintf.c (strace_vfprintf): Likewise.
2015-05-25 22:25:22 +00:00
ea1fea6982 umovestr: read chunks of memory up to pagesize at a time
* defs.h (get_pagesize): New prototype.
* mem.c (get_pagesize) Make global.
* util.c (PAGMASK): Remove.
(vm_read_mem): New process_vm_readv proxy function.
(umoven, umovestr): Use it.
(umovestr): Read chunks up to pagesize at a time.
2015-03-31 20:56:38 +00:00
48321344d7 umovestr: fix short read bug
* util.c (umovestr): Check the right address.
* tests/umovestr.c: New file.
* tests/umovestr2.c: Likewise.
* tests/umovestr.expected: Likewise.
* tests/umovestr.test: New test.
* tests/umovestr2.test: Likewise.
* tests/Makefile.am (check_PROGRAMS): Add umovestr and umovestr2.
(TESTS): Add umovestr.test and umovestr2.test.
(EXTRA_DIST): Add umovestr.expected.
* tests/.gitignore: Add umovestr and umovestr2.

Reported-by: Josef T. Burger <bolo@cs.wisc.edu>
2015-03-31 20:52:41 +00:00
b2893c9e9e When process_vm_readv fails with EPERM, try PTRACE_PEEKDATA
process_vm_readv() and ptrace(PTRACE_PEEKDATA) have inconsistent access
control rules wrt traced processes: process_vm_readv() is more likely to
fail with EPERM than ptrace(PTRACE_PEEKDATA) when tracing a process that
has execve'd a privileged executable.

* util.c (umoven, umovestr): If process_vm_readv returned EPERM,
fall back to ptrace(PTRACE_PEEKDATA).

Reported-by: Andrew Guertin <lists@dolphinling.net>
2015-03-31 15:06:01 +00:00
Denys Vlasenko
7e69ed98cd Change last parameter of umoven() from char* to void*
Saves tons of casts.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
2015-03-21 19:50:53 +01:00
7211dbcb2f build: include ptrace.h after regs.h
Restore the order of including <sys/reg.h> and <linux/ptrace.h>
headers that was inadvertently changed by commit v4.9-280-g5503dd2.

This should fix build on platforms like m68k where some constants
are defined simultaneously as enums by <sys/reg.h> and as macros
by <asm/ptrace.h>.

* process.c: Include "ptrace.h" after "regs.h".
* signal.c: Likewise.
* syscall.c: Likewise.
* util.c: Likewise.
2015-02-28 12:20:21 +00:00
23ce9e48b5 Remove support for systems without PTRACE_SETOPTIONS
Assume that the kernel is v2.5.46 or newer, i.e. PTRACE_SETOPTIONS
and PTRACE_O_TRACESYSGOOD|PTRACE_O_TRACEEXEC|PTRACE_O_TRACECLONE
are universally available.

This change removes all code that implemented post-execve SIGTRAP
handling and fork/vfork/clone->CLONE_PTRACE substitution.

* defs.h (TCB_BPTSET, TCB_WAITEXECVE): Remove macros.
(need_fork_exec_workarounds, setbpt, clearbpt): Remove declarations.
* strace.c (need_fork_exec_workarounds,
test_ptrace_setoptions_followfork, test_ptrace_setoptions_for_all):
Remove.
(syscall_trap_sig): Set to (SIGTRAP | 0x80).
(ptrace_setoptions): Set to (PTRACE_O_TRACESYSGOOD | PTRACE_O_TRACEEXEC).
(detach): Do not test for TCB_BPTSET.
(init): Do not call test_ptrace_setoptions_followfork and
test_ptrace_setoptions_for_all.  Do not test for TCB_BPTSET.
* syscall.c (syscall_fixup_on_sysenter, internal_fork, internal_exec,
syscall_fixup_for_fork_exec, syscall_fixup_on_sysexit): Remove.
(trace_syscall_entering): Do not test for TCB_WAITEXECVE.  Do not call
syscall_fixup_on_sysenter and syscall_fixup_for_fork_exec.
(trace_syscall_exiting): Do not call syscall_fixup_on_sysexit and
syscall_fixup_for_fork_exec.
[IA64] (ia64_ia32mode): Make static.
* linux/ia64/arch_regs.h (ia64_ia32mode): Remove declaration.
* util.c: Do not include "syscall.h".
(arg_setup, get_arg0, get_arg1, set_arg0, set_arg1, restore_arg0,
restore_arg1, arg_finish_change, change_syscall, setbpt, clearbpt):
Remove.
* tests/ptrace_setoptions.test: Remove.
* tests/Makefile.am (TESTS): Remove it.
2015-02-24 03:36:38 +00:00
1c603a9e07 Rename printnum to printnum_long to avoid confusion
* defs.h (printnum): Rename to printnum_long.
* util.c (printnum): Likewise.
* process.c (sys_ptrace): Likewise.
* time.c (sys_time): Likewise.
2015-02-17 22:03:17 +00:00
5503dd28c6 Move regs-related macros and declarations from defs.h to regs.h
* regs.h: New file.
* Makefile.am (strace_SOURCES): Add it.
* linux/arch_regs.h: New file.
* linux/alpha/arch_regs.h: Likewise.
* linux/arm/arch_regs.h: Likewise.
* linux/hppa/arch_regs.h: Likewise.
* linux/i386/arch_regs.h: Likewise.
* linux/ia64/arch_regs.h: Likewise.
* linux/mips/arch_regs.h: Likewise.
* linux/powerpc/arch_regs.h: Likewise.
* linux/sh64/arch_regs.h: Likewise.
* linux/sparc/arch_regs.h: Likewise.
* linux/sparc64/arch_regs.h: Likewise.
* linux/tile/arch_regs.h: Likewise.
* linux/x86_64/arch_regs.h: Likewise.
* Makefile.am (EXTRA_DIST): Add them.
* defs.h: Remove definitions of PTRACE_*, REG_*, PT_*, U_REG_*,
and ARM_* macros.
Remove declarations of struct pt_regs variables.
[SPARC]: Do not include <asm/psr.h>.
[SPARC64]: Do not include <asm/psrcompat.h>.
* bjm.c: Do not include <sys/user.h>.
* process.c: Include "regs.h".
Do not include <sys/user.h> and <sys/reg.h>.
[IA64]: Do not include <asm/ptrace_offsets.h> and <asm/rse.h>.
* util.c: Likewise.
* syscall.c: Likewise.
[AARCH64]: Define struct arm_pt_regs and ARM_* macros.
[SPARC]: Include <asm/psr.h>.
[SPARC64]: Include <asm/psrcompat.h>.
* signal.c: Include "regs.h".
Do not include <sys/user.h> and <sys/reg.h>.
[IA64]: Do not include <asm/ptrace_offsets.h>.
* strace.c [IA64]: Do not include <asm/ptrace_offsets.h>.
2015-02-13 18:28:08 +00:00
fadf379b8e Move all ptrace-related macros and declarations from defs.h to ptrace.h
* ptrace.h: New file.
* Makefile.am (strace_SOURCES): Add it.
* configure.ac (AC_CHECK_HEADERS): Remove linux/ptrace.h and sys/ptrace.h.
* defs.h: Do not include <sys/ptrace.h> and <asm/ptrace.h>.
Remove definitions of PTRACE_* macros.
* process.c: Remove <linux/ptrace.h> workarounds, include "ptrace.h".
* signal.c: Likewise.
* syscall.c: Likewise.
* util.c: Likewise.
* strace.c: Include "ptrace.h".
* wait.c: Likewise.
2015-02-13 18:27:58 +00:00
c7235992dc printfd: quote pathnames
Change printfd() behaviour in show_fd_path mode to quote pathnames
the same way printpathn() does.

* util.c (printfd): Print non-socket paths using print_quoted_string.
* tests/scm_rights-fd.test: Test it.
* tests/scm_rights.c: Update.
2015-01-26 19:05:40 +00:00
513e96eb94 Rework string_quote API
string_quote() has proven to be too hard to use, replace it with
print_quoted_string() that does memory allocation and prints the result.

* defs.h (string_quote): Remove.
(QUOTE_0_TERMINATED, QUOTE_OMIT_LEADING_TRAILING_QUOTES): New macros.
(print_quoted_string): New prototype.
* util.c (string_quote): Make static; take "style" flags instead
of "len", treat QUOTE_0_TERMINATED style flag as former (len == -1);
add QUOTE_OMIT_LEADING_TRAILING_QUOTES style flag support.
(ALLOCA_CUTOFF, use_alloca): New macros.
(print_quoted_string): New function.
(printpathn, printstr): Update to new API.
* loop.c (loop_ioctl): Likewise.
* mtd.c (ubi_ioctl): Likewise.
* net.c (print_scm_security): Likewise.
* socketutils.c (unix_parse_response): Likewise.
2015-01-26 15:58:18 +00:00
97e5996105 Change length type of umoven and umovestr to unsigned
* defs.h (umoven, umovestr): Change type of 3rd argument from "int"
to "unsigned int".
* util.c (umoven, umovestr): Likewise.  Adjust the code appropriately.
2015-01-14 13:18:05 +00:00
1ea64735fc Fix fanotify_mark decoding on 32-bit architectures
The fanotify_mark syscall takes a 64-bit mask, and on 32-bit
architectures it is split up into two syscall arguments.

* configure.ac (AC_CHECK_FUNCS): Add fanotify_mark.
(AC_CHECK_HEADERS): Add sys/fanotify.h.
* defs.h (getllval): New prototype.
* util.c (getllval): New function based on printllval.
(printllval): Use getllval.
* fanotify.c (sys_fanotify_mark): Use getllval to properly decode
64-bit mask and two syscall arguments followed by it.
* tests/fanotify_mark.c: New file.
* tests/fanotify_mark.test: New test.
* tests/Makefile.am (check_PROGRAMS): Add fanotify_mark.
(TESTS): Add fanotify_mark.test.
* tests/.gitignore: Add fanotify_mark.
2015-01-10 00:40:10 +00:00
d4a9d83235 Fix printing of time_t values set in the distant future
* util.c (sprinttime): Increase buffer size.
* tests/stat64-v.test: Try to set modification time of the sample file
to a value set in the distant future.
2015-01-08 15:34:43 +00:00
Masatake YAMATO
f605e92365 Use the protocol name of a socket as a hint for peer address resolution
To resolve the peer address of socket, all combinations of families
(AF_INET, AF_INET6) and protocols(IPPROTO_TCP, IPPROTO_UDP) were tried.
This change utilizes the protocol name obtained via getxattr to specify
the right combination.

* socketutils.c (inet_print): New helper function.
(print_sockaddr_by_inode): Use it.  Utilize the protocol name
associated with the given inode for resolving the peer socket
address.  If the protocol name is NULL, resolve the address
by trying combinations of families and protocols as before.
* defs.h (print_sockaddr_by_inode): Update prototype.
* util.c (printfd): Pass the protocol name associated with
the given path to print_sockaddr_by_inode as the 2nd argument.

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
2014-12-16 04:08:20 +00:00
25ebe46ce2 util.c: move printuid to uid.c
This will make further uid/gid fixes simpler.

* util.c (printuid): Move
* uid.c: ... here.
2014-12-15 23:54:37 +00:00
1da7c95b62 printuid: fix uid_t decoding on 64-bit architectures
It was not a good idea to treat uid_t as a long int type because
the latter is twice larger than uid_t on 64-bit architectures.

* defs.h (printuid): Change uid argument type from "unsigned long"
to "unsigned int".
* util.c (printuid): Likewise.  When uid equals to -1, print "-1".
* tests/uid.awk: New file.
* tests/uid.c: New file.
* tests/uid32.c: Likewise.
* tests/uid.test: New test.
* tests/uid32.test: Likewise.
* tests/Makefile.am (CHECK_PROGRAMS): Add uid and uid32.
(TESTS): Add uid.test and uid32.test.
(EXTRA_DIST): Add uid.awk.
* tests/.gitignore: Add uid and uid32.
2014-12-14 03:54:04 +00:00
b1a01b8d42 Export sprinttime
* defs.h (sprinttime): New prototype.
* file.c (sprinttime): Make global and move to util.c.
2014-12-11 21:39:16 +00:00
Masatake YAMATO
f548067417 Print protocol name of socket descriptors with -yy option
For those socket descriptors that have no associated ip:port pairs
(or when this information is not available), -yy option prints
the same <socket:[INODE]> information as -y option, e.g.

$ strace -e sendto -yy ip l > /dev/null
sendto(3<socket:[23456789]>, ...

This change makes -yy output more informative: instead of just
printing "socket", the name of protocol behind the socket descriptor
will be printed, e.g.

sendto(3<NETLINK:[23456789]>, ...

* configure.ac (AC_CHECK_HEADERS): Add sys/xattr.h.
* tests/net-yy-accept.awk: Update to support protocol names.
* tests/net-yy-connect.awk: Likewise.
* util.c [HAVE_SYS_XATTR_H]: Include <sys/xattr.h>.
(getfdproto): New function.
(printfd): Use it.

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
2014-11-27 23:48:02 +00:00
025b3581ae Replace MAXPATHLEN with PATH_MAX
MAXPATHLEN is defined to PATH_MAX, so replace the former with the latter.

* strace.c (startup_child): Replace MAXPATHLEN with PATH_MAX.
* util.c (printpathn, printpath): Likewise.
2014-11-21 22:28:34 +00:00
b2fa2beedc Include <sys/uio.h> unconditionally
Since <sys/uio.h> is standardized by POSIX and is present in all
available versions of glibc, it's safe to assume that any usable
libc implementation provides this header file.

* configure.ac (AC_CHECK_HEADERS): Remove sys/uio.h.
* io.c: Include <sys/uio.h> unconditionally.
(tprint_iov_upto, tprint_iov, sys_readv, sys_writev,
print_llu_from_low_high_val, sys_preadv, sys_pwritev): Define
unconditionally.
* net.c: Include <sys/uio.h> unconditionally.
* util.c: Include <sys/uio.h> unconditionally.
(dumpiov): Define unconditionally.
2014-11-21 20:46:16 +00:00
Maarten ter Huurne
40c174b38b Include <linux/ptrace.h> regardless of <sys/reg.h> existence
This fixes compilation with musl libc.
This approach was already used in process.c, so I assume it is safe.

* signal.c: Move [HAVE_LINUX_PTRACE_H] code out of [HAVE_SYS_REG_H] check.
* syscall.c: Likewise.
* util.c: Likewise.

Signed-off-by: Maarten ter Huurne <maarten@treewalker.org>
2014-10-31 23:04:59 +00:00
4176d533e0 fsmagic: sort array by value and use bsearch for faster lookup
* defs.h (xlat_search): New prototype.
* util.c (xlat_bsearch_compare, xlat_search): New functions.
* file.c (sprintfstype): Use xlat_search for fsmagic lookup.
* xlat/fsmagic.in: Sort by value and mark as not NULL-terminated.
* tests/statfs.c: New file.
* tests/statfs.test: New test.
* tests/Makefile.am (check_PROGRAMS): Add statfs.
(statfs_CFLAGS): Define.
(TESTS): Add statfs.test.
* tests/.gitignore: Add statfs.
2014-09-22 00:31:06 +00:00
2f6510c8a6 Add -yy option: print ip and port associated with socket descriptors
When two ore more -y options are given, print local and remote ip:port
pairs associated with socket descriptors.  This implementation uses
NETLINK_INET_DIAG for sockaddr lookup; it's based on the patch
prepared by Zubin Mithra as a part of his GSoC 2014 strace project.

* Makefile.am (strace_SOURCES): Add socketutils.c
(EXTRA_DIST): Add linux/inet_diag.h and linux/sock_diag.h.
* defs.h (print_sockaddr_by_inode): New prototype.
* linux/inet_diag.h: New file.
* linux/sock_diag.h: Likewise.
* socketutils.c: Likewise.
* strace.1: Document -yy option.
* strace.c (usage): Likewise.
* util.c (printfd): Use print_sockaddr_by_inode.
2014-09-17 20:03:38 +00:00
3ed5d02183 Fix compilation warnings reported by gcc -Wsign-compare
* configure.ac (gl_WARN_ADD): Add -Wsign-compare.
* defs.h (struct tcb): Change 'currpers' type to unsigned.
(struct xlat): Change 'val' type to unsigned
(signame): Add 'const' qualifier to its argument.
(xlookup, printxval): Add 'const' qualifier to the 2nd argument and
change its type to unsigned.
(printpathn): Change the 3rd argument type to unsigned.
(ioctl_lookup): Change 1st argument type to unsigned.
* count.c (call_summary_pers, call_summary): Change 'i' type to unsigned.
* file.c (print_xattr_list): Fix comparisons between signed and unsigned
long values.
* ioctl.c (compare): Fix cast.
(ioctl_lookup): Change 1st argument type to to unsigned.
(ioctl_next_match): Change 'code' type to unsigned.
* mem.c (sys_move_pages): Change 'i' type to unsigned.
* mtd.c (mtd_ioctl): Change 'i' and 'j' types to unsigned.
Print 'i' using %u format string.
* process.c (sys_prctl): Change 'i' type to unsigned.
(printargv): Change 'n' type to unsigned.
(sys_ptrace): Change 'addr' type to unsigned.
* scsi.c (print_sg_io_buffer): Add 'const' qualifier to 'len' argument
and change its type to unsigned.  Change 'i' and 'allocated' types
to unsigned.
* signal.c (signame): Add 'const' qualifier to its argument.
Fix comparisons between signed and unsigned values.
(sprintsigmask_n, printsiginfo): Fix comparisons between signed and
unsigned values.
* sock.c (sock_ioctl): Change 'i' and 'nifra' types to unsigned.
* strace.c (expand_tcbtab, alloctcb): Change 'i' type to unsigned.
(detach): Change 'sig' type to unsigned.
(startup_attach): Change 'tcbi' type to unsigned.
(startup_child): Change 'm', 'n', and 'len' types to unsigned.
(init): Use new variable to iterate 'tcbtab'.
(pid2tcb): Change 'i' type to unsigned.
(cleanup): Change 'i' and 'sig' types to unsigned.
* syscall.c (update_personality): Change 'personality' argument type
to unsigned.
(struct qual_options): Change 'bitflag' type to unsigned.
(reallocate_qual): Add 'const' qualifier to its argument and change its
type to unsigned.
(qualify_one): Change 'n' and 'bitflag' arguments types to unsigned.
Add 'const' qualifier to 'n', 'not', and 'pers' arguments.
Change 'p' type to signed int.
(qual_syscall): Change 'bitflag' argument type to unsigned.
Add 'const' qualifier to 'bitflag' and 'not' arguments.
Change 'p' type to signed int.
(qual_signal): Change 'bitflag' argument type to unsigned.
Add 'const' qualifier to 'bitflag' and 'not' arguments.
Change 'i' type to unsigned.
(qual_desc): Change 'bitflag' argument type to unsigned.
Add 'const' qualifier to 'bitflag' and 'not' arguments.
(qualify): Change 'i' type to unsigned.
(get_scno): Change 'currpers' type to unsigned.
Fix a comparison between signed and unsigned values.
* system.c (sys_sysctl): Change 'cnt' and 'max_cnt' types to unsigned.
Fix comparisons between signed and unsigned values.
* util.c (xlookup, printxval): Add 'const' qualifier to 'val' argument
and change its type to unsigned.
(printuid): Fix a comparison between signed and unsigned values.
(printpathn): Change 'n' argument type to unsigned.
(printstr): Change 'size' type to unsigned.
Fix a comparison between signed and unsigned values.
(setbpt): Change 'i' type to unsigned.
* net.c (printsock): Silence a compilation warning.
* reboot.c (sys_reboot): Likewise.
2014-09-17 19:18:18 +00:00
3c49b02e98 Fix preadv/pwritev offset decoding on bigendian architectures
This partially reverts commit 7845a42b39.

* util.c (printllval): Remove align argument.
* defs.h (printllval): Update prototype.
(printllval_aligned, printllval_unaligned): Remove.
* 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_aligned call with printllval.
* io.c (sys_pread, sys_pwrite): Likewise.
(print_llu_from_low_high_val): New function.
(sys_preadv, sys_pwritev): Use it instead of printllval_unaligned.
2014-08-07 00:30:26 +00:00
447db45365 Constify tv_* functions
* 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.
2014-05-29 17:59:01 +00:00
6556315493 Alias sys_vfork to sys_fork
* 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.
2014-05-12 20:26:24 +00:00
7845a42b39 Fix preadv/pwritev offset decoding
* 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>
2014-04-17 13:39:49 +00:00
Mike Frysinger
94e246ac57 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.

* process.c: Delete PTRACE_PEEKUSR/PTRACE_POKEUSR defines.
* signal.c: Likewise.
* syscall.c: Delete PTRACE_PEEKUSR define.
* util.c: Likewise.
2013-12-31 07:50:09 +00:00
Denys Vlasenko
b338f2d65e Fix select decoding on e.g. 32-bit ppc process by 64-bit strace.
Added next_set_bit() function which finds the next set bit,
properly taking into account word size of the traced process.
Use it in decode_select() instead of fd_isset().
Also, properly round fdsize up to word size of traced process,
not to strace's word size.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
2013-11-09 20:40:31 +01:00
Ali Polatel
0b4060f61f Work around conflict between <sys/ptrace.h> and <linux/ptrace.h>
Since glibc-2.18~39 <sys/ptrace.h> defines ptrace_peeksiginfo_args
which collides with <linux/ptrace.h>.

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

Signed-off-by: Ali Polatel <alip@exherbo.org>
2013-09-26 13:08:43 +00:00
Vineet Gupta
7daacbbbe7 Add support for ARC Cores from Synopsys
Take #2 on mainlining strace support for ARC (last one was 4.6 based back
in March 2011), see
http://sourceforge.net/p/strace/mailman/message/27210168/

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

test/* all seem to work well.

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

Signed-off-by: Vineet Gupta <vgupta@synopsys.com>
Acked-by: Mike Frysinger <vapier@gentoo.org>
2013-09-11 14:44:54 +00:00
Denys Vlasenko
c09646aa9e Rename ia32 to ia64_ia32mode, and make it bool, not long
Grepping for just ia32 was turning up many false positives.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
2013-07-01 12:28:17 +02:00
Denys Vlasenko
752e5a02e6 Change upeek() to take pid, not full tcp.
This will be used by next change.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
2013-06-28 14:35:47 +02:00
8e096c4ec5 ARM OABI: fix 64-bit arguments decoding
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.
2013-05-06 18:23:01 +00:00