483 Commits

Author SHA1 Message Date
Eugene Syromyatnikov
08c045c3ac Work around possible post-execve-SIGTRAP when PTRACE_ATTACH is used 2018-09-04 22:14:03 +02:00
Eugene Syromyatnikov
68d33a311a fixup! syscall: track syscall system time a bit more explicitly 2018-09-04 22:12:13 +02:00
Eugene Syromyatnikov
e369424a58 count: add ability to select columnt being shown
* count.c (set_count_summary_columns): New function.
* defs.h (set_count_summary_columns): New declaration.
* strace.c (init) <-U>: Pass option argument to
set_count_summary_columns.
* strace.1.in (.SH OPTIONS): Document it.
2018-09-04 20:28:38 +02:00
Eugene Syromyatnikov
05ae538c90 mmap_cache: simplify API
* mmap_cache.h (mmap_cache_rebuild_if_invalid_): rename from
mmap_cache_rebuild_if_invalid.
(mmap_cache_rebuild_if_invalid): New macro, a wrapper for
mmap_cache_rebuild_if_invalid_ that supplies __func__ to it.
(mmap_cache_free_): New declaration.
(mmap_cache_free): New macro, a wrapper for mmap_cache_free_ that
supplies __func__ to it.
* mmap_cache.c (mmap_cache_rebuild_if_invalid_): Rename from
mmap_cache_rebuild_if_invalid.
(mmap_cache_free_): New function.
* unwind-libunwind.c (tcb_walk): Remove __func__ argument from the
mmap_cache_rebuild_if_invalid call.
* kvm.c (vcpu_get_info): Likewise.
* strace.c (droptcb): Call mmap_cache_free.
2018-09-04 15:41:47 +02:00
Eugene Syromyatnikov
0685a353bf syscall: track syscall system time a bit more explicitly
Before, it relied on implicit assumptions that syscall-exit event is
right the next one after syscall-enter.  Also, there's some additional
debugging output that may be might help someone someday.

* count.c (count_syscall): Calculate system time as difference of tcp's
stime and ltime.
* defs.h (struct tcb): Add ltime, atime fields, remove dtime.
* strace.c (droptcb): Print total system time spent by a tcb.
(startup_tcb): Store initial system time in atime.
(next_event): Update stime directly.
* syscall.c (syscall_entering_finish): Store current system time in
tcb's ltime field.
(syscall_exiting_finish): Likewise.
2018-09-03 04:57:13 +02:00
Eugene Syromyatnikov
0a21612184 count: use parse_ts for parsing overhead value
* count.c (set_overhead): Change argument type to const char *, call
parse_ts to parse it and set to overhead.
* defs.h (set_overhead): Update declaration.
* strace.c: (init) <case 'O'>: do not parse argument, pass optarg to
set_overhead call.
* tests/count.test (GENERIC, WALLCLOCK, HALFCLOCK): New variables with
expected patterns.
Add checks for the new -O syntax.
2018-09-02 21:56:47 +02:00
Eugene Syromyatnikov
a010a633cd Print stack traces on signals
I don't know why it hasn't been done earlier.

* strace.c [ENABLE_STACKTRACE] (print_stopped): Call unwind_tcb_print
if stack trace printing is enabled.
2018-08-31 21:11:42 +02:00
14ae61f37b strace.c: introduce struct tcb_wait_data
Introduce a new structure to pass information between next_event(),
restart_delayed_tcb(), and dispatch_event().

This is going to be used by a subsequent change of next_event().

* strace.c (struct tcb_wait_data): New type.
(next_event): Remove parameters, return a pointer
to const struct tcb_wait_data.  Return NULL instead of TE_BREAK.
(dispatch_event): Replace all parameters with a pointer
to const struct tcb_wait_data, obtain the trace event, siginfo,
and status from its fields.
(restart_delayed_tcb): Add local struct tcb_wait_data variable
with te field set to TE_RESTART, pass it to dispatch_event().
(main): Remove status and si variables, update next_event()
and dispatch_event() invocations.

Co-Authored-by: Eugene Syromyatnikov <evgsyr@gmail.com>
2018-08-19 10:26:18 +00:00
048d1885fa Implement -e kvm= option on all architectures
Make -e kvm= interface available on all architectures by adding a stub
on those architectures that do not have <linux/kvm.h>.

* filter_qualify.c (qualify_kvm): Define unconditionally.
(qual_options): Define qualify_kvm entry unconditionally.
* strace.c (usage): Mention kvm argument of -e option unconditionally.
2018-07-11 00:00:57 +00:00
4a48f6b3e8 Mention -e inject option in "strace -h" output
* strace.c (usage): Mention inject argument of -e option.
2018-07-10 16:10:38 +00:00
Masatake YAMATO
b7416438b8 kvm: attach the exit reason of vcpu as auxstr to KVM_RUN output
In KVM, a virtual machine implementation like Qemu can access a vcpu
via ioctl.  KVM_RUN is an ioctl command to enter vcpu.  The command
returns control for various reasons: needs of device emulation or
consuming time slices are the typical ones.  The vmi takes a different
action for the reason.

We, strace users, want to know the reason to understand kvm.  This
change prints the reason as auxstr if "-e kvm=vcpu" option is given,
and if strace runs on Linux 4.16.0 or higher, which includes commit
e46b469278a59781f9b25ff608af84892963821b, "kvm: embed vcpu id to dentry
of vcpu anon inode."

The way to get the reason is a bit complicated because the ioctl does
not return it to the userspace directly.  Instead, the vmi and kvm
communicate via an area of the process virtual memory where the fd of
vcpu is mmap'ed.  strace must peek the area to know the reason.

The change does three things: (1) recording the area for the given vcpu
when the target calls VCPU_CREATE to vcpu_info_list per tcb data field,
(2) verifying the data recorded in vcpu_info_list before doing (3), and
(3) decoding the exit reason field of the area.

The change is complicated because there is a case that strace
does not have a chance to do (1) if -p option is used.
In this case, vcpu_info data created in the step (2).

The area has more fields than "exit reason",
dumping them may be implemented in the future.

* defs.h (struct tcb) [HAVE_LINUX_KVM_H]: Add vcpu_info_list field.
[HAVE_LINUX_KVM_H]: (kvm_run_structure_decoder_init,
kvm_vcpu_info_free): New declarations.
* strace.c (usage): Add "kvm" as a new expression for -e option.
(droptcb): Call kvm_vcpu_info_free.
* filter_qualify.c (qualify_kvm): New function calling
kvm_run_structure_decoder_init to enable for attaching the exit
reason to auxstr.
(qual_options): Add "kvm" as an entry.
* xlat/kvm_exit_reason.in: New file.
* kvm.c: Include xmalloc.h and mmap_cache.h.
(dump_kvm_run_structure): New static variable.
(kvm_run_structure_decoder_init): New function.
(vcpu_info): New struct definition representing the 3-tuple: vcpu file
descriptor, id of the vcpu, and mmap'ed entry.
(vcpu_find, vcpu_alloc, vcpu_register, vcpu_getinfo,
kvm_vcpu_info_free): New functions to access tcb's vcpu_info_list
field and vcpu_info data type.
(is_map_for_file, map_len): New helper functions.
(kvm_ioclt_run_attach_auxstr, kvm_ioctl_decode_run): New functions
decoding vcpu exit reason and attaching the decoded data to auxstr
field of tcb.
(kvm_ioctl_create_vcpu): Call vcpu_register to make an entry mapping
a file descriptor and the vcpu id associated with the fd.
(kvm_ioctl): Call kvm_ioctl_decode_run.

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
Co-Authored-by: Dmitry V. Levin <ldv@altlinux.org>
2018-07-07 10:29:02 +00:00
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