IF YOU WOULD LIKE TO GET AN ACCOUNT, please write an
email to Administrator. User accounts are meant only to access repo
and report issues and/or generate pull requests.
This is a purpose-specific Git hosting for
BaseALT
projects. Thank you for your understanding!
Только зарегистрированные пользователи имеют доступ к сервису!
Для получения аккаунта, обратитесь к администратору.
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.
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.
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.
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>
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.
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.
* 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
* 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
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.
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.
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.
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")
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>
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.
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.
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
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>
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>.
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>
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.
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.
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.
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.
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.
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
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.
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].
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.
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().