Commit Graph

472 Commits

Author SHA1 Message Date
1d98b287a4 mmap_cache: do not activate unless requested
Do not call mmap_cache functions until mmap_cache_enable is invoked.
Change struct mmap_cache_t into a proxy structure, move all mmap_cache
data from struct tcb inside this new structure.

* Makefile.am (strace_SOURCES): Move mmap_cache.c and mmap_cache.h
to libstrace_a_SOURCES.
* defs.h (struct tcb): Remove mmap_cache_size and mmap_cache_generation
* fields.
* mmap_cache.h (struct mmap_cache_t): Rename
to struct mmap_cache_entry_t, create a new struct mmap_cache_t,
all users updated.
(mmap_cache_delete): Remove.
* mmap_cache.c (mmap_cache_delete): Rename to delete_mmap_cache,
add static qualifier.
(build_mmap_cache): Merge into mmap_cache_rebuild_if_invalid.
* strace.c (droptcb): Replace mmap_cache_delete invocation
with tcp->mmap_cache->free_fn.
2018-05-04 14:45:44 +00:00
Eugene Syromyatnikov
37935cca18 strace.c: check return code of never failing fcntl call
Because the kernel cannot be trusted.

* strace.c (set_cloexec_flag): Call perror_msg_and_die if fcntl(F_SETFD)
has failed.
2018-05-03 00:09:53 +00:00
Eugene Syromyatnikov
3cdaf39e3d Add user interface for configuring xlat output style
* strace.c (init): Handle -X option, set xlat_verbosity
according to -X argument.
* strace.1.in: Document -X option.
* NEWS: Mention it.

Closes: https://github.com/strace/strace/issues/27
Co-Authored-by: Dmitry V. Levin <ldv@altlinux.org>
2018-04-20 12:39:05 +00:00
2e5167cc4f unwind: move unwind_tcb_init invocation to after_successful_attach
There is no need to call unwind_tcb_init before the tracee is attached.

* strace.c (alloctcb) [ENABLE_STACKTRACE]: Move unwind_tcb_init
invocation ...
(after_successful_attach) [ENABLE_STACKTRACE]: ... here.
(init) [ENABLE_STACKTRACE]: Remove unwind_tcb_init invocation loop.
* unwind.c (unwind_tcb_fin): Skip if tcp->unwind_queue is NULL.
2018-04-19 18:03:58 +00:00
ca5ca349ee strace: move setting of post-attach flags inside after_successful_attach
* strace.c (after_successful_attach): Add "flags" argument.
Set TCB_ATTACHED, TCB_STARTUP, and "flags" in tcp->flags.
All users updated.
2018-04-19 18:03:58 +00:00
4069dcb912 strace: rename newoutf to after_successful_attach
This function is going to be used for other things that have to be done
right after a successful attach, hence the rename.

* strace.c (newoutf): Rename to after_successful_attach,
all users updated.
2018-04-19 18:03:58 +00:00
Masatake YAMATO
98d3356b04 unwind: initialize unwind context only if given tcb is initialized
With libdw based unwinder, following warnings are reported
when -p is passed before -k:

   $ ./strace -p 1 -k
   ...
   ./strace: dwfl_linux_proc_attach returned an error for process 0: No such file or directory
   ...

It seems that commit 54c7792b, "Fix libunwind segfault when -p is
passed before -k" doesn't fix the original issue.

* strace.c (init) [ENABLE_STACKTRACE]: Initialize unwind context only
if given tcb is initialized.

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
2018-04-19 18:03:58 +00:00
Eugene Syromyatnikov
b9fcbe6112 Introduce XLAT_STYLE_DEFAULT
This will be needed later, with the introduction of user-configurable
xlat style setting (stored in xlat_verbosity variable).

* defs.h (XLAT_STYLE_VERBOSITY_MASK): New macro constant.
(enum xlat_style) <XLAT_STYLE_DEFAULT>: New enumeration entity.
(xlat_verbosity): New external declaration.
(printxvals, printxval_searchn, printxval_search_ex, sprintxval,
sprintflags, printflags64): Use XLAT_STYLE_DEFAULT instead of
XLAT_STYLE_ABBREV.
* strace.c (xlat_verbosity): New variable.
* xlat.c (get_xlat_style): New function.
(printxvals_ex, sprintxval_ex, printxval_searchn_ex, sprintflags_ex,
printflags_ex): Use it.
2018-04-13 00:25:13 +02:00
ecf5284f7d Lift experimental status from stack tracing feature
* strace.1.in (.SH OPTIONS) <.B \-k>: Remove " (experimental)".
* strace.c (usage) [ENABLE_STACKTRACE]: Likewise.
2018-04-11 22:01:37 +00:00
2713444cb7 unwind: prepare configure subsystem for alternative unwinders
Introduce --enable-stacktrace configure option to control whether
-k option support is compiled in, --with-libunwind option remains
available to control whether libunwind can be used as an unwinder.

* m4/st_demangle.m4: New file.
* m4/st_libunwind.m4: Likewise.
* m4/st_stacktrace.m4: Likewise.
* configure.ac: Replace all libunwind and libiberty checks
with a single st_STACKTRACE invocation.
* Makefile.am: Conditionalize checks for USE_LIBUNWIND and USE_DEMANGLE
on ENABLE_STACKTRACE.
[ENABLE_STACKTRACE] (strace_SOURCES): Append unwind.c and unwind.h.
* strace.1.in: Replace libunwind with an unwinder-agnostic wording.
* defs.h: Replace USE_LIBUNWIND with ENABLE_STACKTRACE.
* strace.c: Likewise.
(print_version): Print stack-trace instead of stack-unwind.
* syscall.c: Replace USE_LIBUNWIND with ENABLE_STACKTRACE.
* tests/Makefile.am: Likewise.  Replace LIBUNWIND_TESTS
with STACKTRACE_TESTS.
* tests/strace-V.test: Update expected output.
2018-04-08 22:01:12 +00:00
Eugene Syromyatnikov
be55c1c61a strace.c: add support for opening output file in append mode
* strace.c (open_append): New variable.
(init): Handle -A option.
(strace_fopen): Open file in "a" mode if open_append is set to true.
* strace.1.in: Document this.
* NEWS: Mention this.

Suggested-by: Philipp Marek <philipp.marek@emerion.com>
Closes: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=528488
2018-04-04 20:32:42 +00:00
Eugene Syromyatnikov
698e9c30d4 strace.c: support simultaneous usage of -r and -t options
* strace.c (init): Do not set tflag when rflag is set.
(printleader): Handle rflag and tflag separately.
* strace.1.in (.SH OPTIONS): Add a note about differences between
the monotonic clock time  and the wall clock time.
* tests/options-syntax.test: Remove the check for
"-tt has no effect with -r" warning.
* NEWS: Mention this.

Suggested-by: Josh Triplett <josh@freedesktop.org>
Co-Authored-by: Dmitry V. Levin <ldv@altlinux.org>
Closes: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=466195
2018-04-04 20:32:42 +00:00
Eugene Syromyatnikov
a02a583b3f strace: handle possible NULL from localtime() call
* strace.c (printleader): Print raw tv_sec value if localtime() returned
NULL.
* tests/localtime.c: New file.
* tests/localtime.test: New test.
* tests/Makefile.am (check_PROGRAMS): Add localtime.
(MISC_TESTS): Add localtime.test.
(localtime_LDADD): New variable.
* tests/.gitignore: Add localtime.
* ci/install-dependencies.sh (common_packages): Add faketime.

Co-Authored-by: Dmitry V. Levin <ldv@altlinux.org>
Closes: https://github.com/strace/strace/issues/42
2018-04-04 20:32:42 +00:00
53b0d9c438 Add i18n support
Let's make a step towards the growing strace userbase all around
the world and translate something to the language of their choice.

This change enables translation of error messages corresponding
to errno codes, making it consistent with error diagnostics of other
i18n-aware tools, e.g.

$ LANG=es_ES strace -qq -a38 -P /missing unlink /missing
unlink("/missing")                    = -1 ENOENT (No existe el fichero o el directorio)
unlink: no se puede deshacer el enlace '/missing': No existe el fichero o el directorio

* strace.c: Include <locale.h>.
(main): Invoke setlocale.
* tests/init.sh: Export LC_ALL=C.
* NEWS: Mention this enhancement.
2018-04-01 13:14:15 +00:00
6905f5d2bf Move delay interface from defs.h to delay.h
* defs.h (alloc_delay_data, fill_delay_data, is_delay_timer_armed,
delay_timer_expired, arm_delay_timer, delay_tcb): Move...
* delay.h: ... to new file.
* Makefile.am (strace_SOURCES): Add it.
* filter_qualify.c: Include it.
* strace.c: Likewise.
* syscall.c: Likewise.
2018-03-28 04:29:22 +00:00
5c0896d9d8 strace: further optimize unblocking of the delay signal handler
Do not unblock the delay signal handler unless the delay timer is armed.

* defs.h (is_delay_timer_created): Remove.
(is_delay_timer_armed, delay_timer_expired): New prototypes.
* delay.c (delay_timer_is_armed): New static variable.
(is_delay_timer_created): Add static qualifier.
(is_delay_timer_armed, delay_timer_expired): New functions.
(arm_delay_timer): Set delay_timer_is_armed.
* strace.c (next_event): Use is_delay_timer_armed instead of
is_delay_timer_created to check whether the delay signal handler
has to be unblocked.
(timer_sighandler): Invoke delay_timer_expired.
2018-03-23 00:20:33 +00:00
f56a3feb32 strace: rewrite restart error handling without sigsetjmp/siglongjmp
Further simplify and optimize error handling of the delay signal handler
by replacing sigsetjmp/siglongjmp mechanism with an error flag.

* strace.c: Do not include <setjmp.h>.
(restart_failed): New volatile variable.
(timer_jmp_buf): Remove.
(next_event): Cache is_delay_timer_created() return value,
remove sigsetjmp invocation, check restart_failed instead.
(timer_sighandler): Replace siglongjmp with setting restart_failed.
2018-03-23 00:20:33 +00:00
4976ce2f31 strace: do not call sigsetjmp without a delay timer
As sigsetjmp costs a syscall, do not call it unless a delay timer
is already created and its signal handler is going to be unblocked.

* strace.c (next_event): Move sigsetjmp invocation under
is_delay_timer_created() condition.

Optimizes: v4.21-108-gba8e768 ("Implement delay injection")
2018-03-23 00:20:33 +00:00
Elvira Khabirova
ba8e768a80 Implement delay injection
Add -e inject=SET:delay_enter= and -e inject=SET:delay_exit= options.

* configure.ac (AC_SEARCH_LIBS): Check for timer_create -lrt.
* delay.c: New file.
* Makefile.am (strace_SOURCES): Add it.
(strace_LDADD): Add $(timer_LIBS).
* defs.h (INJECT_F_DELAY_ENTER, INJECT_F_DELAY_EXIT,
TCB_INJECT_DELAY_EXIT, TCB_DELAYED, inject_delay_exit, syscall_delayed):
New macros.
(alloc_delay_data, fill_delay_data, is_delay_timer_created,
arm_delay_timer, delay_tcb): New prototypes.
(struct inject_data): Replace reserved field with delay_idx.
(struct tcb): Add delay_expiration_time field.
* filter_qualify.c (parse_delay_token): New function.
(parse_inject_token): Use it.
(qualify_inject_common): Initialize struct inject_opts.data.delay_idx.
* strace.c: Include <setjmp.h>
(timer_jmp_buf, timer_set): New static variables.
(timer_sighandler, restart_delayed_tcb, restart_delayed_tcbs): New
functions.
(init): Block SIGALRM, set SIGALRM handler.
(dispatch_event): Do not restart delayed syscalls.
(next_event): Unblock SIGALRM during wait4 invocation.
* syscall.c (tamper_with_syscall_entering): Arm delay timer if
INJECT_F_DELAY_ENTER injection flag is set, set TCB_INJECT_DELAY_EXIT
flag if INJECT_F_DELAY_EXIT injection flag is set.
tamper_with_syscall_exiting): Arm delay timer if inject_delay_exit.
(syscall_exiting_trace): Call tamper_with_syscall_exiting in case of
inject_delay_exit.
(syscall_exiting_finish): Clear TCB_INJECT_DELAY_EXIT flag.
* strace.1.in: Document delay injection.
* NEWS: Mention this improvement.

Co-Authored-by: Dmitry V. Levin <ldv@altlinux.org>
2018-03-22 06:23:25 +00:00
c3393d4770 Do not block handled signals in interactive mode
Let these signals be handled asynchronously as they are acted on
only when waiting for process state changes.

* strace.c (start_set, blocked_set): Remove.
(set_sighandler): Do not update blocked_set.
(startup_attach, init, next_event): Remove all sigprocmask calls.
2018-03-22 06:23:25 +00:00
17935497e2 Replace struct timeval with struct timespec in time measurements
This is required to implement more precise time measurements.

* Makefile.am (strace_LDADD): Add $(clock_LIBS).
* defs.h (struct tcb): Change the type of stime, dtime, and etime fields
from struct timeval to struct timespec, all users updated.
(syscall_exiting_decode, syscall_exiting_trace, count_syscall): Change
the type of "struct timeval *" argument to "struct timespec *", all
users updated.
(tv_nz, tv_cmp, tv_float, tv_add, tv_sub, tv_div, tv_mul): Rename to
ts_nz, ts_cmp, ts_float, ts_add, ts_sub, ts_div, and ts_mul.  Change
the type of all "struct timeval *" arguments to "struct timespec *",
all users updated.
* util.c (tv_nz, tv_cmp, tv_float, tv_add, tv_sub, tv_div, tv_mul):
Rename to ts_nz, ts_cmp, ts_float, ts_add, ts_sub, ts_div, and ts_mul.
Change the type of all "struct timeval *" arguments to "struct timespec *".
* count.c (struct call_counts): Change the type of "time" field
from struct timeval to struct timespec, all users updated.
(overhead): Change type from struct timeval to struct timespec, all
users updated.
(count_syscall): Change the type of "struct timeval *" argument to
"struct timespec *".
* strace.c (printleader): Change the type of struct timeval variables
to struct timespec, call clock_gettime instead of gettimeofday.
(next_event, trace_syscall): Change the type of struct timeval variables
to struct timespec.
* syscall.c (syscall_entering_finish, syscall_exiting_decode): Call
clock_gettime instead of gettimeofday.
2018-03-20 02:30:24 +00:00
24c5884e0e printleader: cleanup tflag handling
* strace.c (printleader): Move declarations of variables closer
to their first use.
2018-03-16 00:55:58 +00:00
e8cb814cf2 Optimize pid2tcb
Introduce an internal cache of pid2tcb translations.
This can save more than 80% of CPU user time spent by strace.

Tested using the following setup:

	#include <unistd.h>
	#include <sys/stat.h>
	#include <sys/wait.h>
	int main()
	{
		int i;
		sleep(1);
		for (i = 1; i < 1000; ++i) {
			pid_t pid = fork();
			if (pid < 0)
				return 2;
			if (pid)
				return wait(&i) != pid || i;
		}
		sleep(1);
		for (i = 0; i < 10000000; ++i)
			umask(0777);
		return 0;
	}

	old$ ./set_ptracer_any ./pid2tcb >pid2tcb.wait & \
	  while [ ! -s pid2tcb.wait ]; do sleep 0.1; done; \
	  time -f '%Uuser %Ssystem %eelapsed %PCPU' \
	  ../strace -qq -enone -esignal=none -f -p $!
	5.51user 104.90system 122.45elapsed 90%CPU

	new$ ./set_ptracer_any ./pid2tcb >pid2tcb.wait & \
	  while [ ! -s pid2tcb.wait ]; do sleep 0.1; done; \
	  time -f '%Uuser %Ssystem %eelapsed %PCPU' \
	  ../strace -qq -enone -esignal=none -f -p $!
	1.29user 102.78system 114.97elapsed 90%CPU
2018-03-13 22:33:48 +00:00
55df9a9251 Enable USE_SEIZE code unconditionally
It is by no means an experimental code.

* defs.h (USE_SEIZE): Remove.
* strace.c [!USE_SEIZE]: Remove.
2018-03-13 20:54:25 +00:00
42bedfc093 Replace fopen_for_input and fopen_for_output with fopen_stream
* largefile_wrappers.h (fopen_for_input, fopen_for_output): Replace
with fopen_stream.
* mmap_cache.c (fopen_for_input) Likewise.
* strace.c (fopen_for_output): Likewise.
2018-02-27 13:14:38 +00:00
bbeee0be62 Introduce mmap_cache.h
Let's avoid bloating defs.h and introduce a separate header for
mmap_cache.

* defs.h (struct mmap_cache_t, enum mmap_cache_protection,
enum mmap_cache_rebuild_result, mmap_cache_enable, mmap_cache_is_enabled,
mmap_cache_invalidate, mmap_cache_delete, mmap_cache_rebuild_if_invalid,
mmap_cache_search): Move ...
* mmap_cache.h: ... to this new file.
* Makefile.am (strace_SOURCES): Add mmap_cache.h.
* mmap_cache.c: Include mmap_cache.h.
* strace.c: Likewise.
* syscall.c: Likewise.
* unwind.c: Likewise.
2018-02-26 23:22:24 +00:00
Masatake YAMATO
7f041ed0d9 mmap_cache, unwind: lift up mmap_cache_delete invocation from unwind.c
mmap_cache_delete function used to be called by destructor of unwind
related code.  Now that other parts can use mmap cache,
mmap_cache_delete is called separately from unwind_tcb_fin.

* unwind.c (unwind_tcb_fin): Move mmap_cache_delete invocation ...
* strace.c (droptcb): ... here.

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
2018-02-26 23:22:24 +00:00
daaf8ab7fe Update copyright headers
Headers updated automatically using maint/update_copyright_years.sh
script.
2018-02-13 22:00:00 +00:00
5a6dff3fe8 Include <sys/ptrace.h> early
Include "ptrace.h" before any header that can include <signal.h>
because on some architectures the latter may include <asm/sigcontext.h>
which in turn may include <asm/ptrace.h> with potentially devastating
effect on <sys/ptrace.h>.

* process.c: Include "ptrace.h" before "regs.h".
* rt_sigframe.c: Likewise.
* sigreturn.c: Include "ptrace.h" before "nsig.h".
* syscall.c: Likewise.
* wait.c: Include "ptrace.h" before <sys/wait.h>.
* strace.c: Include "ptrace.h" before <signal.h>.
* tests/ptrace.c: Likewise.
* tests/test_ucopy.c: Include <sys/ptrace.h> before <signal.h>.
2018-02-11 00:26:09 +00:00
f2bb704a92 Include <limits.h> instead of <sys/param.h>
Do not include <sys/param.h> unnecessarily as it includes <signal.h>.

* pathtrace.c: Include <limits.h> instead of <sys/param.h>.
* strace.c: Likewise.
* syscall.c: Likewise.
* util.c: Likewise.
* tests/getcwd.c: Likewise.
* tests/group_req.c: Likewise.
* tests/inode_of_sockfd.c: Likewise.
* tests/ip_mreq.c: Likewise.
* tests/printpath-umovestr.c: Likewise.
* tests/qual_fault.c: Likewise.
* tests/test_printpath.c: Likewise.
* tests/umovestr3.c: Likewise.
* tests/net-y-unix.c: Do not include <sys/param.h>.
* tests/net-yy-unix.c: Likewise.
2018-02-11 00:26:09 +00:00
Eugene Syromyatnikov
eae4643b0f Move large file-related wrappers to a separate header
* strace.c [_LARGEFILE64_SOURCE]: Move the definitions under it to a...
* largefile_wrappers.h: ... new file.
* Makefile.am (strace_SOURCES): Add it.
2018-02-06 02:56:14 +01:00
Eugene Syromyatnikov
1b849e23bf Workaround stray PTRACE_EVENT_EXEC
We (apparently) had a long-standing test failure inside strace-ff.test
with the symptom that it misses exit_group call.  As it turned out, it
was PTRACE_EVENT_EXEC followed by execve syscall exiting stop.  That
behaviour indeed screwed all the syscall state tracking for the tracee.
Let's try to patch it up by calling trace_syscall when we receive
PTRACE_EVENT_EXEC outside syscall.

* defs.h (TCB_RECOVERING): New tcb flag.
* strace.c (dispatch_event) <case TE_STOP_BEFORE_EXECVE>: Invoke
trace_syscall with TCB_RECOVERING flag being set for the current_tcp
if the tracee is not on exiting syscall.
* syscall.c (get_scno): Set QUAL_RAW if we are recovering.
(tamper_with_syscall_entering): Do not perform actual tampering during
recovery as it's already too late.
* NEWS: Mention it.

Co-Authored-by: Dmitry V. Levin <ldv@altlinux.org>
2018-01-25 01:55:08 +00:00
Eugene Syromyatnikov
5fcdae5359 strace.c: reset printing_tcp on print_event_exit
print_event_exit should have printing_tcp setup analogous to printleader and
syscall_exit_trace before printing its part, otherwise it spuriously resets
curcol in line_ended for the stale printing_tcp if followfork == 2.

* strace.c (print_event_exit): Set printing_tcp to tcp before printing
exiting event line and calling line_ended.
2018-01-24 01:56:15 +00:00
Eugene Syromyatnikov
0918b3145c strace.c: print correct out file name in error messages in case of -ff
* strace.c (outf_perror): New function.
(tvprintf, tprints, flush_tcp_output): Use it.
2018-01-16 22:54:38 +00:00
Eugene Syromyatnikov
396961b1b4 Update current_personality on tcb switch
* strace.c (set_current_tcp): New function.
(printleader, droptcb, print_event_exit, next_event, dispatch_event):
Call set_current_tcp instead of setting current_tcp manually.
2018-01-16 22:54:38 +00:00
Eugene Syromyatnikov
7dbc3780a6 Add indication of mpers support to strace -V output
* strace.c (print_version): Append information about m32 and mx32
decoding support.
* tests/strace-V.test: Update expected output.
2018-01-11 15:54:33 +00:00
Eugene Syromyatnikov
8cea0b917a Add indication of optional demangle feature strace -V output
* strace.c (print_version) [USE_DEMANGLE]: Append " stack-demangle"
to the features string.
* tests/strace-V.test: Update expected output.
2018-01-11 15:54:33 +00:00
Eugene Syromiatnikov
562abec971 Add tcp argument to clear_regs
* defs.h (clear_regs): Add argument struct tcb *tcp.
* syscall.c (clear_regs): Likewise.
* strace.c (next_event): Pass tcp to clear_regs() call.
2018-01-07 16:46:32 +00:00
Eugene Syromiatnikov
cc057e03ae Include paths.h if it is available
Use the OS definition of _PATH_BSHELL macro if it is available.

* configure.ac (AC_CHECK_HEADERS): Add paths.h.
* strace.c [HAVE_PATHS_H]: Include paths.h.
2018-01-07 16:46:32 +00:00
Eugene Syromiatnikov
6b3f423640 strace.c: avoid duplication of a format string in attach_tcb
* strace.c (attach_tcb): Add task_path variable with the output format.
Use it for the procdir declaration and xsprintf format string argument.
2018-01-07 16:46:32 +00:00
Elvira Khabirova
2e351de149 strace.c: rename set_sigaction to set_sighandler
Since set_sigaction() actually specifies sa_handler and not sa_sigaction,
rename set_sigaction() to set_sighandler() for future definition of
set_sigaction() function as specifying sa_sigaction.

* strace.c (set_sigaction): Rename to set_sighandler.
All callers updated.
2018-01-07 03:11:21 +00:00
026b76444e strace.c: use xsprintf instead of sprintf
* strace.c: Include "xstring.h".
(strerror, newoutf, attach_tcb, print_debug_info): Replace sprintf
with xsprintf.
2018-01-05 12:26:47 +00:00
9cbb505f9f Lift artificial limit on output file names in -ff mode
Starting with commit v4.5.19~88 strace imposed an artificial limit
on output file names in -ff mode, leading to the following absurd
behaviour:

$ strace -ff -o"$(perl -e 'print "/" x 510')/$PWD/log" /bin/true
strace: Can't fopen '////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////.12345': Permission denied

* strace.c (newoutf): Raise buffer size to PATH_MAX.
(init) <followfork >= 2>: Check output file name prefix length.
* tests/options-syntax.test: Check it.
2018-01-04 10:52:07 +00:00
Eugene Syromiatnikov
0b786d6641 Move enum trace_event into a separate header
As it will have users outside strace.c in the future.

* trace_event.h (enum trace_event): Move it from...
* strace.c (enum trace_event): ...here.
(#include "trace_event.h"): New header, for enum trace_event.
* Makefile.am (strace_SOURCES): Add trace_event.h.
2018-01-04 00:16:21 +01:00
Eugene Syromyatnikov
576e2db4d0 Call get_scno during startup_tcb only for forcibly attached processes
Otherwise it makes little sense on most arches to try to get syscall
number.

* defs.h (TCB_GRABBED): New tcb flag.
* strace.c (attach_tcb): Set TCB_GRABBED for the tcb.
(startup_tcb): Call get_scno() only if process is grabbed and its
registers may contain syscall number information.

Reported-by: Dmitry V. Levin <ldv@altlinux.org>
Closes: https://github.com/strace/strace/issues/22
2018-01-03 23:56:48 +01:00
Eugene Syromyatnikov
45fa947494 strace.c: sort getopt switch branches alphabetically
There's no reason to have them out of order. This also (almost) matches
their order in the getopt call argument, introduced in
v4.20-64-g61c03be.

* strace.c (init): Sort branches in the getopt switch routine.
2018-01-01 17:34:57 +01:00
Eugene Syromyatnikov
910364a5dc strace.c: check for (non)zero argc instead of argv[0]
Since we can never be sure that we have NULL behind the last entry of
the argv array.

* strace.c (init): Check for non-zero argc before/instead of argv[0].
2018-01-01 17:25:53 +01:00
Eugene Syromyatnikov
fcf4b6afdc strace.c: inform the user about -F option obsolescence
* strace.c (init): Print an error message if the option is used.

Co-authored-by: Dmitry V. Levin <ldv@altlinux.org>
2017-12-20 22:58:42 +00:00
Eugene Syromyatnikov
61c03be596 strace.c: sort option arguments alphabetically
Except for the ones that enabled by configure options.

While we are here, let's also change the indentation of while expression
continuation in order to separate it from the following switch clause.

* strace.c (init): Reorder options in getopt() call.
2017-12-20 22:58:42 +00:00
Eugene Syromiatnikov
67c4b41ed0 strace.c: use _exit() instead of exit() in child's die()
Let's keep child's death routine as minimalistic as possible for the
cases when vfork() is used instead of fork() on systems that lack MMU.

* strace.c (die) <!(strace_tracer_pid == getpid())>: Call _exit().
2017-12-20 22:58:42 +00:00