Commit Graph

2085 Commits

Author SHA1 Message Date
faa177e3d9 arm, i386: use PTRACE_GETREGSET if available
* syscall.c [ARM || I386 || X86_64] (get_regset): New function.
(get_regs) [ARM || I386 || X86_64]: Use it.
2013-03-18 12:00:57 +00:00
32c049a9d8 Include <sys/uio.h> and <elf.h> on all architectures
* syscall.c: Include <sys/uio.h> and <elf.h> on all architectures.
2013-03-18 11:59:37 +00:00
27e3ae973a x86-64: enhance PTRACE_GETREGSET test
* syscall.c (get_regs) [X86_64]: Check whether PTRACE_GETREGSET
works regardless of the kernel version.
2013-03-18 11:46:36 +00:00
ee348c6073 x32: use PTRACE_GETREGSET unconditionally
* syscall.c (get_regs) [X32]: Assume that PTRACE_GETREGSET always works
regardless of the kernel version.
2013-03-18 11:46:35 +00:00
0482c5a21d x86-64, x32: do not include linux/ptrace.h unnecessarily
* syscall.c [X86_64 || X32]: Stop including linux/ptrace.h.
2013-03-18 11:46:32 +00:00
7d5696f11d i386, tile, x32: do not redefine ptrace prototype
* defs.h [I386 || TILE || X32]: Use ptrace prototype from sys/ptrace.h.
2013-03-18 11:46:26 +00:00
c41808bcd6 ptrace: decode note segment descriptor types
* configure.ac (AC_CHECK_HEADERS): Add elf.h.
* process.c: Include elf.h.
(nt_descriptor_types): New xlat structure.
(sys_ptrace): Use it.
2013-03-18 11:46:02 +00:00
3ec134b07a Update MADV_* constants
* mem.c (madvise_cmds): Add more MADV_* constants from
asm-generic/mman-common.h

Reported-by: Robin Hack <hack.robin@gmail.com>
2013-03-14 18:55:26 +00:00
Denys Vlasenko
8050cdc43c Tweaks for -c: fixed setitimer/getitimer hack; optimized call_summary_pers()
count_syscall() was calling setitimer/getitimer once in order to find
smallest "tick" OS uses in time accounting, in order to use it
for syscalls which apparently spent less than that time in syscall.
The code assumed that this "tick" is not zero... but it is zero
on linux-3.6.11. Which means that this hack doesn't work...

At least this change prevents this measurement from being done
_repeatedly_, by initializing one_tick to -1, not 0.

While at it, added comments in count_syscall() explaining what we are doing.

Optimized call_summary_pers() a bit, by eliminating redundant tv -> float
conversions, and prevented 0.0/0.0 which was resulting in "% time"
being shown as "-nan" if total CPU time spent was 0.000000
(try "strace -c /bin/true").

The code seems to seriously underestimate CPU usage:
"strace -c ls -lR /usr/share >/dev/null" shows total time spent
in syscalls to be only ~10..20% of what "time ls -lR /usr/share >/dev/null"
shows.

It might be useful to have a mode where we show wall clock time
spent in syscalls, not CPU time. It might also be more accurate.

   text	   data	    bss	    dec	    hex	filename
 245019	    676	   5708	 251403	  3d60b	strace_old
 244923	    684	   5676	 251283	  3d593	strace

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2013-03-07 12:27:40 +01:00
Denys Vlasenko
5198ed4bb3 Open-code isprint(c) and isspace(c)
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>
2013-03-06 23:44:23 +01:00
Denys Vlasenko
76f61bec5e Makefile: add commented-out tweak to generate link map
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2013-03-06 18:59:09 +01:00
Denys Vlasenko
61ad0a401c Stop using a large static buffer in getfdpath
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>
2013-03-06 18:24:34 +01:00
Denys Vlasenko
7672946e74 Fix wrongly indented closing curly brace. No code changes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2013-03-05 17:46:19 +01:00
Denys Vlasenko
dafba9bb99 strace_vfprintf: if malloc fails, exit gracefully
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2013-03-05 17:29:18 +01:00
c76a363af8 Use sysconf(_SC_PAGESIZE) instead of hardcoded PAGE_SHIFT
PAGE_SHIFT couldn't be reliably obtained at compile time,
thanks to Chris Metcalf for the hint.

* mem.c: Do not include <sys/user.h>.
[SH64] Do not include <asm/page.h>.
(get_pagesize): New function.
(sys_mmap_pgoff, sys_old_mmap_pgoff): Use it.
2013-03-05 16:03:53 +00:00
Denys Vlasenko
aba6292797 Emit better message for ERESTARTNOHAND return
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2013-03-05 16:56:35 +01:00
Denys Vlasenko
cc90291f4b Disable STREAMS syscalls for non-SPARC
text	   data	    bss	    dec	    hex	filename
   3002	      0	   1024	   4026	    fba	stream.o.old
   1729	      0	   1024	   2753	    ac1	stream.o

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2013-03-05 16:50:12 +01:00
Denys Vlasenko
e7db46503d Fix printstrbufarg's address argument to be long, not int
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2013-03-05 16:17:46 +01:00
Denys Vlasenko
38cfe7c923 Remove variable tracing_paths and check in pathtrace_match
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2013-03-05 16:01:53 +01:00
Denys Vlasenko
7239dbcf2d Use dynamically-sized selected[] array for -P PATH
While at it, added a small optimization of not remembering
the path twice if it happens to be the same.

   text	   data	    bss	    dec	    hex	filename
 245111	    680	  10860	 256651	  3ea8b	strace_old
 245075	    680	   9804	 255559	  3e647	strace

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2013-03-05 15:46:34 +01:00
Denys Vlasenko
f877982aa2 metag,or1k: whitesace style fix. no code changes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2013-03-05 14:03:07 +01:00
Denys Vlasenko
99d3e01eef Assorted fixes to syscallent.h
or1k was missing TM on many memory-related syscalls
sys_lookup_dcookie is 3-arg on 64-bit arches, and isn't TF
sys_recvmsg is 3-arg on all arches
sys_nfsservctl is 3-arg on all arches
sys_timerfd_create is 2-arg on all arches
sys_[f]truncate64 is 4-arg or 3-arg, never 5-arg
truncate64 is TF
sys_[l]lseek is TD
fstat[64] is TD

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2013-03-05 13:59:45 +01:00
James Hogan
5f999a869b Add support for Imagination Technologies Meta
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>
2013-03-05 12:57:06 +01:00
Denys Vlasenko
1694092d7d umovestr: speed up check for NUL byte in the fetched word
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2013-03-01 18:52:59 +01:00
7b9e45e891 Fix trace=set regression introduced by commit v4.7-111-g9cbc15b
* syscall.c (qual_syscall, qualify): Pass personality down to
qualify_one.
* tests/qual_syscall: New test.
* tests/Makefile.am (TESTS): Add qual_syscall.
2013-03-01 16:22:02 +00:00
Chris Metcalf
879ddddeba tile: handle printllval like x86_64 or powerpc64
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>
2013-03-01 10:41:02 +01:00
Denys Vlasenko
22efaf0028 Make -b take SYSCALL param, document it in --help and in manpage.
To not waste an option letter for just one trick,
extend -b to take a parameter:
"on which syscalls do you want to detach?".
Currently supports only execve.

While at it, fixed (by removing non-Linux and stale info)
and extended manpage text about -f.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2013-02-27 12:15:19 +01:00
9700592e49 Cleanup umoven and umovestr
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.
2013-02-26 22:11:32 +00:00
1a880cf3bd pathtrace: fix umovestr return code check
* pathtrace.c (upathmatch): Only NUL-terminated strings can be
path-matched, so fix the umovestr return code check to filter out
unsuitable strings.
2013-02-26 22:11:29 +00:00
e6f55240a1 Fix compilation errors uncovered by -Werror=enum-compare
This fixes regression introduced by commit v4.7-111-g9cbc15b.

* syscall.c: Merge all nsyscalls* enums into single enum.
Likewise merge nerrnos*, nsignals*, and nioctlents* into single enums.
2013-02-26 22:07:55 +00:00
Denys Vlasenko
905e8e0e2f Mass replace error_msg("%s", "literal") -> error_msg("literal")
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>
2013-02-26 12:30:09 +01:00
Ben Noordhuis
1d58fe9b3b Make umoven report success as 0, not >=0, stop returning success on partial 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>
2013-02-26 12:24:25 +01:00
Denys Vlasenko
05f325199a Assorted NOMMU fixes
With -D, strdup'ing of pathname is necessary only on NOMMU.

Don't set skip_startup_execve to 1 if NOMMU and not in daemonized mode
(try "strace [-D] -b env echo HI" to see whether we detach on correct execve).

Fix test_ptrace_FOO shortcuts on NOMMU to always assume success
and _properly_ set all variables.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2013-02-26 12:00:34 +01:00
Denys Vlasenko
38e79bbb25 Shorten help text - no need to show deprecated option -F
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2013-02-26 11:33:54 +01:00
Denys Vlasenko
859ea8b8cc Merge adjacent tprint's
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2013-02-23 20:07:44 +01:00
Denys Vlasenko
b43dacd6d1 Correct i > MAX_NSYSCALLS commparison: should be i >= MAX_NSYSCALLS
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2013-02-23 18:19:28 +01:00
Denys Vlasenko
f90979b701 Fix wrong offset display in dumpstr
BTW, the new code from prev commit is 5 times faster
than old one :)

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2013-02-22 15:00:11 +01:00
Denys Vlasenko
763258071c Fix a bug in dumpstr (no null termination). Essentially rewrote dumpstr
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>
2013-02-22 14:47:39 +01:00
Denys Vlasenko
9cbc15b7e7 Eliminate MAX_QUALS, make qualifier array dynamic
MAX_QUALS was 2048, even though most arches used less than 500 entries
in it. MAX_QUALS had to be maintained by hand to be higher than syscall
count. It also limited the highest possible fd to track.

This change makes qual_flagsN[] arrays start sized to the required minimum
(number of syscalls) and grow dynamically if user requested
-e read=BIGNUM. As a precaution, BIGNUM should be < 2^15, but this limit
can be raised with no cost for normal strace invocations.

qual_flags is now a define to qual_vec[current_personality].

As a bonus, this patch aliases sysent, errnoent, signalent, ioctlent
names in one-personality arches to their corresponding <foo>0 arrays,
removing one indirection level.

  text   data    bss    dec    hex filename
244471    700  12928 258099  3f033 strace.t7/strace
244627    680  10860 256167  3e8a7 strace.t8/strace

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2013-02-22 13:37:36 +01:00
Denys Vlasenko
a9fe13c943 Create and use struct_sysent and struct_ioctlent typedefs.
This is a preparatory mass replace patch with no code changes.

The future change will need to typedef sysent to sysent0,
which results in compile failures when "struct sysent" string
gets mangled into "struct sysent0".

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2013-02-22 13:26:10 +01:00
Denys Vlasenko
40d63b9a92 Use tcp->qual_flg instead of qual_flags[] in verbose() and abbrev()
We have hundreds of uses of these macros.
Result is more efficient and 1.1 kbyte shorter code:

  text	   data	    bss	    dec	    hex	filename
245579	    700	  12928	 259207	  3f487	strace.t5/strace
244471	    700	  12928	 258099	  3f033	strace.t6/strace

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2013-02-22 13:23:38 +01:00
Denys Vlasenko
c1540fe19d Remove unused QUAL_FAULT code (was used by non-Linux code only).
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2013-02-21 16:17:08 +01:00
Denys Vlasenko
a585c9d641 Use uint8_t for qual_flags[] instead of ints.
Resulting bss reduction is ~6kbytes:

   text	   data	    bss	    dec	    hex	filename
 245703	    700	  19072	 265475	  40d03	strace.t4/strace
 245687	    700	  12928	 259315	  3f4f3	strace.t5/strace

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2013-02-21 16:15:43 +01:00
Denys Vlasenko
74ec14f968 Eliminate many SCNO_IS_VALID checks
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>
2013-02-21 16:13:47 +01:00
Denys Vlasenko
7270de551c ARM: make it one-personality arch
ARM in fact _is_ one personality.

We had two personalities for it because it has a handful of
syscalls with huge scnos (0x000f00xx).

Extending syscall table to have [0x000f0005] index is of course
not a good idea.

Someone decided to handle that by having a separate personality
just for these syscalls.

But multi-personality arch does a bit more work in other parts.

This patch is another alternative: "move" 0x000f00nn syscalls
down to the entries just above last ordinary syscall,
by manipulating scno if it falls into the 0x000f00xx range.

In order to not worsen genuine undefined scnos' printing,
the code remaps scno back to actual value before printing
"syscall_NNN" string.

* defs.h: Remove multi-reprsonality defines from ARM.
* syscall.c (shuffle_scno): New function.
(undefined_scno_name): New function.
(get_scno): [ARM] Replace personality setting with scno shuffling.
(trace_syscall_entering): Print unknown syscall name using
undefined_scno_name().
(trace_syscall_exiting): Likewise.
* linux/arm/syscallent.h: Add ARM specific syscalls at the end.
* linux/arm/errnoent1.h: Deleted.
* linux/arm/ioctlent1.h: Deleted.
* linux/arm/signalent1.h: Deleted.
* linux/arm/syscallent1.h: Deleted.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2013-02-21 15:46:34 +01:00
Denys Vlasenko
e7030e5a7e arm: shorten syscall table for EABI - no point in storing NULL entries
Also, reformatted ARM code in get_scno(), mostly improved comments,
without code changes.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2013-02-20 18:08:25 +01:00
Denys Vlasenko
4bfb198db1 Use the same style of includes in linux/*/* files
While at it, fix some comments which say
"we use i386 syscalls/ioctls/errnos" but in reality
common ones are used.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2013-02-20 12:38:14 +01:00
Denys Vlasenko
2544f988c9 Fix compiler warnings
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>
2013-02-19 17:39:56 +01:00
Denys Vlasenko
30c03230a8 Improve comment text. No code changes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2013-02-19 16:59:26 +01:00
Denys Vlasenko
f909c8d0d7 Fix NOMMU + daemonized tracer SEGV
pathname[] was getting destroyed, execve of garbage pathname
failing, and to top it off, the tracer's stack was also
smashed and trecer segfaulted.

* strace.c (exec_or_die): New function.
(startup_child): Don't use pathname[] contents after vfork,
make a malloced copy instead. Explain "NOMMU + -D bug"
and how we work around it.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2013-02-19 16:30:31 +01:00