]> granicus.if.org Git - strace/log
strace
5 years ago[wip] mmap_cache: rewrite using tracee_* calls esyr/gdbserver0
Eugene Syromyatnikov [Fri, 22 Feb 2019 12:20:51 +0000 (13:20 +0100)]
[wip] mmap_cache: rewrite using tracee_* calls

5 years ago[wip] gdbserver backend fixes
Eugene Syromyatnikov [Fri, 22 Feb 2019 12:19:55 +0000 (13:19 +0100)]
[wip] gdbserver backend fixes

5 years agostrace.c: indicate presence of gdb rtacing backen in version information output
Eugene Syromyatnikov [Fri, 22 Feb 2019 12:18:33 +0000 (13:18 +0100)]
strace.c: indicate presence of gdb rtacing backen in version information output

5 years agoconfigure: fix additional_tracing_backends setting (it should be a shell variable...
Eugene Syromyatnikov [Thu, 21 Feb 2019 11:45:00 +0000 (12:45 +0100)]
configure: fix additional_tracing_backends setting (it should be a shell variable and not m4)

5 years agogdbserver: readlink fixes
Eugene Syromyatnikov [Mon, 18 Feb 2019 01:33:30 +0000 (02:33 +0100)]
gdbserver: readlink fixes

5 years agogdbserver: remove gdb_dispatch_event
Eugene Syromyatnikov [Mon, 18 Feb 2019 01:30:24 +0000 (02:30 +0100)]
gdbserver: remove gdb_dispatch_event

5 years agoMerge branch 'master' into gdbserver0
Stan Cox [Mon, 7 Jan 2019 20:30:47 +0000 (15:30 -0500)]
Merge branch 'master' into gdbserver0

Conflicts:
Makefile.am
aux_children.c
aux_children.h
defs.h
list.h
ptrace_backend.c
ptrace_backend.h
strace.c
syscall.c
tracing_backend.c
tracing_backend.h
util.c

5 years agoUse call via structure only when multiple tracing backends are available esyr/gdbserver-prep
Eugene Syromiatnikov [Mon, 25 Dec 2017 23:48:42 +0000 (00:48 +0100)]
Use call via structure only when multiple tracing backends are available

Since dispatching function calls via the tracing backend structure
definitely imposes some overhead, let's try to minimise it for the
(pretty common) case of having only one tracing backend available.

* configure.ac (additional_tracing_backends): New m4 variable.
(ADDITIONAL_TRACING_BACKENDS): New AC_DEFINE, equal to
additional_tracing_backends.
* ptrace_backend.c: Put ptrace_backend definition under
"#if ADDITIONAL_TRACING_PACKENDS".
* ptrace_backend.h: Put ptrace_backend declaration under
"#if ADDITIONAL_TRACING_PACKENDS".
* tcb_wait_data.h [!ADDITIONAL_TRACING_PACKENDS]: Provide macros for
aliasing trace_wait_data_size, init_trace_wait_data,
copy_trace_wait_data, and free_trace_wait_data to ptrace-based tracing
backend definitions.
* tracing_backend.c: Put the contents, except local_open, under #if
ADDITIONAL_TRACING_PACKENDS.
* tracing_backend.h: Put the contents (except local_open) under #if
ADDITIONAL_TRACING_PACKENDS, provide macros for all the inline functions
that alias them to the respective functions in the ptrace-based tracing
backend in the opposite case.

5 years agoIntroduce tracing backend abstraction layer (TraBAL, for short)
Eugene Syromiatnikov [Mon, 25 Dec 2017 23:17:36 +0000 (00:17 +0100)]
Introduce tracing backend abstraction layer (TraBAL, for short)

So, all the ptrace-specific routines are now getting "ptrace_" prefix.
Wrappers for the old routines are provided, that call appropriate method
based on current tracing backend selection. Some auxiliary functions
are provided for getting backend name and selecting backend.

Based on "Implement gdbserver using backend dispatch table." and "Add
defaults for all backend methods." commits by Stanford Cox.

* Makefile.am (strace_SOURCES): Add ptrace_backend.c, ptrace_backend.h,
ptrace_wait_data.h, tcb_wait_data.h, tracing_backend.c, tracing_backend.h.
* defs.h: Add struct tcb_wait_data forward declaration; include
tracing_backend.h.
(generic_get_instruction_pointer): Rename from get_instruction_pointer,
the latter is now defined in tracing_backend.h.
(generic_get_stack_pointer): Rename from get_stack_pointer, the latter
is now defained in tracing_dackend.h.
(clear_regs, get_scno, umoven, umovestr, upeek, upoke): Remove
declarations, they are now defined in tracing_backend.h.
* pathtrace.c (getfdpath): Change readlink call to tracee_readlink.
(pathtrace_select_set): Change realpath call to tracee_realpath.
* ptrace_backend.c: New file.
* ptrace_backend.h: Likewise.
* ptrace_wait_data.h: Likewise.
* tcb_wait_data.h: Likewise.
* tracing_backend.c: Likewise.
* tracing_backend.h: Likewise.
* strace.c: Include "tcb_wait_data.h", "ptrace_wait_data.h".
(struct tcb_wait_data): Move to tcb_wait_data.h.
(struct ptrace_wait_data, to_ptrace_wait_data): Move to
ptrace_wait_data.h.
(detach, cleanup): Remove declarations (they are a part of
tracing_backend.h now).
(detach, attach_tcb, startup_child, init_trace_wait_data,
copy_trace_wait_data, free_trace_wait_data, next_event,
handle_group_stop, handle_exec, restart_process): Add "ptrace_" prefix.
Remove static qualifier.
(tracing_backend_init): Rename to ptrace_init.
(tracing_backend_name): Remove.
(trace_wait_data_size): Remove, it is now defined in
tracing_backend.h.
(init): Call tracing_backend_post_init() at the end of the routine.
* syscall.c (get_regs, get_syscall_args, get_syscall_result. get_error,
set_scno, set_error, set_success): Remove declarations (they are part
of tracing_backend.h now).
(clear_regs, get_regs, get_scno, set_scno, set_error, set_success,
get_syscall_args, get_syscall_result, get_syscall_regs, ): Add "ptrace_"
prefix, remove static qualifier.
(get_instruction_pointer): Split into ptrace_get_instruction_pointer
and generic_get_instruction_pointer.
(get_stack_pointer): Split into ptrace_get_stack_pointer
and generic_get_stack_pointer.
* ucopy.c (umoven, umovestr): Add "ptrace_" prefix.
* upeek.c (upeek): Likewise.
* upoke.c (upoke): Likewise.
* socketutils.c (send_query): Replace sendmsg call with tracee_sendmsg.
(receive_responses): Replace recvmsg call with tracee_recvmsg.
(get_sockaddr_by_inode_uncached, genl_families_xlat): Replace socket
call with tracee_socket.
* util.c (getfdproto): Replace getxattr call with tracee_getxattr.
(open_file): Move to is part of ptrace_backend.c.
(read_int_from_file): Replace open_file call with tracee_open. Replace
read call with tracee_pread. Replace close call with tracee_close.

Co-Authored-by: Stan Cox <scox@redhat.com>
5 years agotests: add additional tests for strace's -E behaviour
Eugene Syromyatnikov [Fri, 22 Feb 2019 18:01:12 +0000 (19:01 +0100)]
tests: add additional tests for strace's -E behaviour

* tests/Makefile.am (MISC_TESTS): Add strace-E-override.test,
strace-E-unset.test.
(EXTRA_DIST): Add strace-E-unset.expected.
* tests/strace-E-override.test: New test.
* tests/strace-E-unset.test: Likewise.
* tests/strace-E-unset.expected: New file.

5 years agostrace.c: construct and pass environment to startup_child
Eugene Syromyatnikov [Fri, 22 Feb 2019 17:51:30 +0000 (18:51 +0100)]
strace.c: construct and pass environment to startup_child

The current approach with putenv() during parsing has two problems:
 - it changes tracer's own environment which may affect its behaviour
   and may be undesirable;
 - it's specific to ptrace tracing backend.

As a solution, let's apply an approach similar to path tracing option
parsing: collect the provided optarg's in an array and then pass it to
tracing-backend-specific routines.

* strace.c (struct exec_params): Add env field.
(exec_or_die): Call execve() instead of execv(); pass params->env
as the third argument.
(startup_child): Add env parameter, set params_for_tracee.env to it.
(add_to_env, make_env): New functions.
(init): Add env_changes, env_change_size, env_change_count local
variables; store optarg in env_changes array on -E option occurrence;
construct new environment using make_env and pass it to startup_child
in the second argument.

5 years agotests: add support for negative match patterns to match_grep
Eugene Syromyatnikov [Fri, 22 Feb 2019 17:46:07 +0000 (18:46 +0100)]
tests: add support for negative match patterns to match_grep

For the cases when we want that some patterns do not appear in the
output.

* tests/init.sh (match_grep): Add res and negated local variables; set
negated to 1 if pattern starts with "!", otherwise to 0; fail if negated
pattern has been matched.

5 years agoUse xzalloc(sz) instead of xcalloc(1, sz)
Eugene Syromyatnikov [Fri, 22 Feb 2019 17:41:31 +0000 (18:41 +0100)]
Use xzalloc(sz) instead of xcalloc(1, sz)

* aux_children.c (register_aux_child_ex): Use xzalloc instead of xcalloc
of one-item-sized array.
* bpf.c (BEGIN_BPF_CMD_DECODER(BPF_OBJ_GET_INFO_BY_FD)): Likewise.
* kvm.c (vcpu_alloc): Likewise.
* perf.c (fetch_perf_event_attr): Likewise.
* syscall.c (ptrace_get_scno): Likewise.

5 years agoxmalloc: add zero-initialisation counterparts for xmalloc and xcalloc
Eugene Syromyatnikov [Fri, 22 Feb 2019 17:34:33 +0000 (18:34 +0100)]
xmalloc: add zero-initialisation counterparts for xmalloc and xcalloc

Specifically, array allocation without zero memory initialisation
and xmalloc with zero memory initialisation.

* xmalloc.c (xallocarray): New function.
* xmalloc.h (xcalloc): Document the function.
(xallocarray): New function declaration.
(xzalloc): New function, wrapper for xcalloc with xmalloc interface.

5 years agostrace.c: print resolved path name when startup child's stat has failed
Eugene Syromyatnikov [Fri, 22 Feb 2019 12:22:17 +0000 (13:22 +0100)]
strace.c: print resolved path name when startup child's stat has failed

* strace.c (ptrace_startup_child): Print resolved pathname in the stat
error message.

5 years agosyscall.c: wrap arch_set_scno in TraBAL-specific wrapper
Eugene Syromiatnikov [Mon, 25 Dec 2017 23:15:33 +0000 (00:15 +0100)]
syscall.c: wrap arch_set_scno in TraBAL-specific wrapper

* syscall.c (tamper_with_syscall_entering): Change arch_set_scno call to
set_scno.
(set_scno): New function.

5 years agoPass tcp argument to pathtrace_select_set
Eugene Syromiatnikov [Mon, 25 Dec 2017 23:11:27 +0000 (00:11 +0100)]
Pass tcp argument to pathtrace_select_set

As it will pass tcp to tracee-related syscalls.

* defs.h (pathtrace_select_set, pathtrace_select): Add tcp argument.
* pathtrace.c (pathtrace_select_set): Likewise.
* strace.c (init): Pass current_tcp to pathtrace_select call.

5 years agostrace.c: move ptrace-specific parts out of dispatch_event
Eugene Syromyatnikov [Sun, 10 Feb 2019 23:47:13 +0000 (00:47 +0100)]
strace.c: move ptrace-specific parts out of dispatch_event

dispatch_event is mostly neutral to a tracing backends, except for some
parts. Let's move them into separate functions and call them from it.
Also, while we are here, let's pass an opaque pointer to next_event and
these new functions, so a tracing backend is able to carry some tracing
loop state (like siginfo and restart_op, in case of ptrace) there.

* strace.c (struct tcb_wait_data): Remove msg and status fields (as
those are specific to tracing backend), ass sig, exit, and core_dumped
fields.
(struct ptrace_wait_data): New type.
(to_ptrace_wait_data): New macro.
(tcb_wait_tab): Change type to struct ptrace_wait_data *.
(maybe_switch_tcbs): Change the second argument to struct tcb_wait_data *wd,
use to_ptrace_wait_data(wd)->msg to obtain previously stored
PTRACE_GETEVENTMSG result, use tcp->pid instead of pid, avoid tcp =
execve_thread assignment.
(print_signalled): Change the third argument to struct tcb_wait_data *wd,
use wd->sig instead of WTERMSIG(status).
(print_exited): Rename second argument to exit, use it directly instead
of WEXITSTATUS(status).
(trace_wait_data_size): Return sizeof(struct ptrace_wait_data) instead
of sizeof(struct tcb_wait_data).
(init_trace_wait_data): Initialise struct ptrace_wait_data: set
ptrace_wd->restart_op to PTRACE_SYSCALL; return pointer to the wd field.
(copy_trace_wait_data): Copy containing struct ptrace_wait_data instead
of struct tcb_wait_data.
(free_trace_wait_data): Free containing struct ptrace_wait_data.
(next_event): Change type of wd to struct ptrace_wait_data; initialise
wd->wd.sig and wd->wd.core_dumped on WIFSIGNALED(status); initialise
wd->wd.exit on WIFEXITED(status); initialise wd->wd.sig on ptrace event
being 0 or PTRACE_EVENT_STOP with signal being one of SIGSTOP, SIGTSTP,
SIGTTIN, or SIGTTOU.
(classify_ptrace_stop, handle_exec, restart_process): New functions.
(dispatch_event): Remove restart_op, restart_sig, status; use wd->sig
instead of restart_sig; pass wd to print_signalled.
(dispatch_event) <case TE_GROUP_STOP>: Move ptrace-specific code to
classify_group_stop, call it from next_event instead.
(dispatch_event) <case TE_STOP_BEFORE_EXECVE>: Move ptrace-specific code
to handle_exec.
(dispatch_event): Replace ptrace_restart call with restart_process call.

5 years agostrace.c: move argc+daemonized check to tracing_backend_init
Eugene Syromiatnikov [Sun, 31 Dec 2017 17:14:05 +0000 (18:14 +0100)]
strace.c: move argc+daemonized check to tracing_backend_init

This check is also specific to the ptrace tracing backend.

* strace.c (init): Mave !argc && daemonized_tracer check...
(tracing_backend_init): ...here.

5 years agostrace.c: move argc/nprocs check to the tracing_backend_init routine
Eugene Syromiatnikov [Sun, 31 Dec 2017 17:13:39 +0000 (18:13 +0100)]
strace.c: move argc/nprocs check to the tracing_backend_init routine

It is deemed that for some tracing backends it is possible to run strace
without providing either program to run or PIDs to attach (attaching to
already running GDB server with existing inferiors is an example). Thus,
let's move this check to tracing_backend_init.

* strace.c (tracing_backend_init): Add (!nprocs && !argc) check.
(init): Remove (!nprocs && !argc) check, update error message for (argc
< 0) check.
* tests/options-syntax.test: Update expected output.

5 years agostrace.c: move ptrace backend initialisation into a separate routine
Eugene Syromiatnikov [Mon, 25 Dec 2017 22:59:36 +0000 (23:59 +0100)]
strace.c: move ptrace backend initialisation into a separate routine

In a preparation to TraBAL introduction.

* strace.c (tracing_backend_init): New function.
(tracing_backend_name): New macro.
(init): Move OS release detection, ptrace_setoptions initialisation,
and PTRACE_SEIZE/PTRACE_GET_SYSCALL_INFO tests to tracing_backend_init.

5 years agostrace.c: move pathtrace_select calls to a later initialisation stage
Eugene Syromiatnikov [Mon, 25 Dec 2017 22:57:36 +0000 (23:57 +0100)]
strace.c: move pathtrace_select calls to a later initialisation stage

Since pathtrace initialisation (more speicifically, path name
resolution) is specific to the tracing backend (especially in case
tracees are remote), let's first collect the list of paths to trace
in a temporary array and add it later during the initialisation.

* strace.c (init): Add pathtrace_paths temporary array, with its
element count stored in pathtrace_count and size in pathtrace_size.
(init) <case 'P'>: Store argument in pathtrace_paths, grow it if needed.
(init): Iterate over pathtrace_paths and call pathtrace_select for each
element. Free the array.

5 years agostrace.c: use aux_children interface for handling strace_popen'ed child
Eugene Syromiatnikov [Fri, 15 Dec 2017 16:42:12 +0000 (17:42 +0100)]
strace.c: use aux_children interface for handling strace_popen'ed child

Now, when we have generic auxiliary children handling interface, we can
implement it once and then add additional children with
register_aux_child call, without disturbing main strace code.

* strace.c: Include "aux_children.h"
(popen_pid): Remove.
(strace_popen): Provide resulting PID as an argument to
register_aux_child instead of storing it in popen_pid.
(next_event): Check for the presence of additional children with
have_aux_children. Handle stops of auxiliary children with
aux_children_signal.
(terminate): Use aux_children_exit_notify and aux_children_exit_wait
instead of manually waiting on popen_pid.

5 years agoIntroduce an API for handling spawned auxiliary children
Eugene Syromiatnikov [Wed, 13 Dec 2017 12:53:17 +0000 (13:53 +0100)]
Introduce an API for handling spawned auxiliary children

One of gdbserver backend features is to spawn a GDB server. The handling
of this child process is more or less similar to strace_popen'ed child,
so let's generalise it.

* aux_children.c: New file.
* aux_children.h: Likewise.
* Makefile.am (strace_SOURCES): Add them.

5 years agostrace.c: implement a routine for creating a child connected with a pipe
Eugene Syromiatnikov [Thu, 14 Dec 2017 12:48:10 +0000 (13:48 +0100)]
strace.c: implement a routine for creating a child connected with a pipe

This routine also utilises posix_spawn_* calls in an attempt to avoid
common pitfalls associated with vfork execution on no-MMU systems.

The implementation is based on a part of original gdbserver backend
support code by Josh Stone (commit "Add -G support for files and piped
commands").

* strace.c (ZERO_OR_DIE): New macro.
(strace_pipe_exec): New function.
(strace_popen): Rewrite as a wrapper for strace_pipe_exec.

Co-Authored-by: Josh Stone <jistone@redhat.com>
5 years agoIntroduce next_setqual_scno (needed for gdbserver backend)
Eugene Syromiatnikov [Tue, 1 Aug 2017 15:12:40 +0000 (17:12 +0200)]
Introduce next_setqual_scno (needed for gdbserver backend)

During initialisation, gdbserver backend enumerates all the syscall
numbers enabled for tracing and asks GDB server to stop only on the
specified syscall numbers. Since number_set interface is now opaque,
we provide an ability to enumerate all the syscall numbers that are
enabled.

* defs.h (next_set_qual_scno): New declaration.
* number_set.h (next_set_bit_in_set_array): Likewise.
* filter_qualify.c (next_set_qual_scno): Implement it.
* number_set.c (next_set_bit_in_set_array): Likewise.

5 years agostrace.c: pre-allocate tcb on PTRACE_EVENT_{FORK,VFORK,CLONE}
Eugene Syromyatnikov [Thu, 21 Feb 2019 18:41:58 +0000 (19:41 +0100)]
strace.c: pre-allocate tcb on PTRACE_EVENT_{FORK,VFORK,CLONE}

In an attempt to resolve a race between the first stop of a new child
and the death of the last process.

* defs.h (TCB_PREALLOCATED): New constant.
* strace.c (pid2tcb): Add skip_preallocated parameter.
(maybe_allocate_tcb): Add tcp parameter, use it instead of allocating a
new tcp if it is not NULL.
(maybe_switch_tcbs): Pass true as a second argument to pid2tcb.
(next_event): Pass tcp to maybe_switch_tcbs if it is pre-allocated,
pre-allocate a tcb on PTRACE_EVENT_{FORK,VFORK,CLONE} if followfork is
enabled and we successfully retrieved the new pid.

5 years agostrace.c: fix up formatting after commit v4.24~48
Eugene Syromyatnikov [Thu, 21 Feb 2019 15:55:51 +0000 (16:55 +0100)]
strace.c: fix up formatting after commit v4.24~48

The commit v4.24~48 "Implement -e kvm= option on all architectures",
while removing #ifdef, left formatting of the help message string a bit
inconsistent.

* strace.c (usage): Move "\n\" bit after "kvm", remove double quotes.

Complements: v4.24~48 "Implement -e kvm= option on all architectures"

5 years agotests: fix xgetrlimit output when syscall returns an error
Eugene Syromyatnikov [Thu, 21 Feb 2019 15:52:46 +0000 (16:52 +0100)]
tests: fix xgetrlimit output when syscall returns an error

* tests/xgetrlimit.c (main): Expect pointer to rlimit as a second
argument when syscall returns an error. Convert rc printing to sprintrc.

5 years agoRename the stat struct used internally by strace to strace_stat_t
Eugene Syromyatnikov [Thu, 21 Feb 2019 15:49:35 +0000 (16:49 +0100)]
Rename the stat struct used internally by strace to strace_stat_t

5 years agoMove open_file to largefile_wrappers.h
Eugene Syromyatnikov [Thu, 21 Feb 2019 15:48:44 +0000 (16:48 +0100)]
Move open_file to largefile_wrappers.h

* util.c (open_file): Move it...
* largefile_wrappers.h (open_file): ...here.

5 years agostrace.c: pass signal to cleanup() instead of reading it inside it
Eugene Syromyatnikov [Thu, 21 Feb 2019 11:56:29 +0000 (12:56 +0100)]
strace.c: pass signal to cleanup() instead of reading it inside it

* strace.c (die): Pass 0 as an argument to cleanup().
(cleanup): Add fatal_sig parameter, remove the local variable
of the same name, do not use interrupted.
(terminate): Initialise new sig local variable with interrupted,
pass it to cleanup and use it instead of the latter for exit_code
initialisation.

5 years agoImplement queueing of threads before dispatching them
Eugene Syromyatnikov [Wed, 8 Aug 2018 19:41:39 +0000 (21:41 +0200)]
Implement queueing of threads before dispatching them

It is possible that some tracees call a lot of cheap syscalls too fast,
and that can lead to starvation to the point some tracees are not served
for indefinite amount of time.  In order to solve that unfairness, try
to collect all the pending tracees first along with the relevant
information and only then dispatch the events.

* defs.h: Include "list.h".
(struct tcb): Add wait_data_idx, delayed_wait_data, and wait_list
fields.
* strace.c (struct tcb_wait_data): Add "msg" field.
(tcb_wait_tab, tcb_wait_tab_size): New static variable.
(droptcb): Remove tcp from wait_list.
(maybe_switch_tcbs): Get old pid from
tcb_wait_tab[tcp->wait_data_idx].msg instead of calling
ptrace(PTRACE_GETEVENTMSG).
(tcb_wait_tab_check_size): New function.
(trace_wait_data_size, init_trace_wait_data, copy_trace_wait_data,
free_trace_wait_data): New functions, in order to allow the code outside
next_event to operate with wait_data as with an opaque object (needed
for dispatch_event and restart_delayed_tcb).
(next_event): Add pending_tcps, extra_tcp, wait_nohang, elem, and
wait_tab_pos variables; check for elements in pending_tcps and skip
waiting if the list is not empty; check for extra_tcp and skip waiting
along with swapping wait_data_idx with wait_extra_data_idx;
after the initial wait4(), call wait4() in loop with WNOHANG flag set;
fetch siginfo on signal and eventmsg on PTRACE_EVENT_EXEC;
return the first tcp in pending_tcps list.
(dispatch_event): Store a pointer to a copy of tcb_wait_data in
tcp->delayed_wait_data if tcp's restart has to be delayed.
(restart_delayed_tcb): Use tcp->delayed_wait_data, create a stub
tcb_wait_data if it is NULL, free temporary trace_wait_data.
* tests/Makefile.am (XFAIL_TEST): Remove looping_threads.test.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=478419
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=526740
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=851457
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1609318
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1610774
Co-Authored-by: Dmitry V. Levin <ldv@altlinux.org>
Co-Authored-by: Denys Vlasenko <dvlasenk@redhat.com>
Co-Authored-by: Andreas Schwab <aschwab@redhat.com>
Co-Authored-by: Jeff Law <law@redhat.com>
Co-Authored-by: DJ Delorie <dj@redhat.com>
5 years agoxmalloc: add ability to specify desired minimum size for xgrowarray
Eugene Syromyatnikov [Wed, 27 Feb 2019 16:14:49 +0000 (17:14 +0100)]
xmalloc: add ability to specify desired minimum size for xgrowarray

* xmalloc.h (xgrowarray_ex): Rename from xgrowarray, add min_memb
parameter.
(xgrowarray): New static inline function, wrapper for xgrowarray_ex.
* xmalloc.c: Include "macros.h".
(xgrowarray_ex): Rename from xgrowarray, add min_memb, increase array
size to the maximum of min_memb and old size + grow_memb.

5 years agoAdd a generic list implementation
Eugene Syromyatnikov [Sun, 11 Sep 2016 09:11:45 +0000 (12:11 +0300)]
Add a generic list implementation

Similar to the one used in the Linux kernel.

* macros.h (cast_ptr, containerof): New macros.
* list.h: New file.
* Makefile.am (strace_SOURCES): Add it.

5 years agotests: check tracing of looping threads
Dmitry V. Levin [Wed, 4 Jul 2018 02:11:27 +0000 (02:11 +0000)]
tests: check tracing of looping threads

* test/many_looping_threads.c: Remove.
* test/.gitignore: Remove many_looping_threads.
* test/Makefile (PROGS): Likewise.
(many_looping_threads): Remove.
* tests/looping_threads.c: New file.
* tests/looping_threads.test: New test.
* tests/.gitignore: Add looping_threads.
* tests/Makefile.am (check_PROGRAMS): Likewise.
(looping_threads_LDADD): New variable.
(MISC_TESTS, XFAIL_TESTS): Add looping_threads.test.

5 years agoUpdate ioctl entries from linux v5.0
Gleb Fotengauer-Malinovskiy [Mon, 25 Feb 2019 14:47:20 +0000 (17:47 +0300)]
Update ioctl entries from linux v5.0

* linux/32/ioctls_inc_align16.h: Update from linux v5.0-rc8
using ioctls_gen.sh.
* linux/32/ioctls_inc_align32.h: Likewise.
* linux/32/ioctls_inc_align64.h: Likewise.
* linux/64/ioctls_inc.h: Likewise.
* linux/x32/ioctls_inc0.h: Likewise.
* linux/aarch64/ioctls_arch0.h: Likewise.
* linux/arm/ioctls_arch0.h: Likewise.
* linux/mips/ioctls_arch0.h: Likewise.
* linux/powerpc/ioctls_arch0.h: Likewise.
* linux/s390/ioctls_arch0.h: Likewise.
* linux/s390x/ioctls_arch0.h: Likewise.
* NEWS: Mention this.

5 years agomaint: update for linux 5.0-rc8
Gleb Fotengauer-Malinovskiy [Mon, 25 Feb 2019 14:36:16 +0000 (17:36 +0300)]
maint: update for linux 5.0-rc8

* maint/ioctls_sym.sh (x86_list): Add KVM_GET_SUPPORTED_HV_CPUID.

5 years agoxlat/gen.sh: disable file name globbing by default
Dmitry V. Levin [Sun, 24 Feb 2019 23:37:00 +0000 (23:37 +0000)]
xlat/gen.sh: disable file name globbing by default

As the script uses file name globbing only in one place,
disable it by default and enable it when necessary.

* xlat/gen.sh: Add -f to shebang.
(main): Enable file name globbing to generate the list of input files.

5 years agoxlat/gen.sh: speedup, part 5
Eugene Syromyatnikov [Tue, 5 Feb 2019 23:49:47 +0000 (00:49 +0100)]
xlat/gen.sh: speedup, part 5

* xlat/gen.sh (gen_header): Process xlat line with sed only when "/*"
substring is present in it.

Co-Authored-by: Dmitry V. Levin <ldv@altlinux.org>
5 years agoxlat/gen.sh: speedup, part 4
Eugene Syromyatnikov [Tue, 5 Feb 2019 23:49:47 +0000 (00:49 +0100)]
xlat/gen.sh: speedup, part 4

* xlat/gen.sh (cond_xlat): Use read instead of sed for xlat entry
parsing.

Co-Authored-by: Dmitry V. Levin <ldv@altlinux.org>
5 years agoxlat/gen.sh: speedup, part 3
Eugene Syromyatnikov [Tue, 5 Feb 2019 23:49:47 +0000 (00:49 +0100)]
xlat/gen.sh: speedup, part 3

* xlat/gen.sh (cond_def): Use parameter substitution instead of sed
for xlat line parsing.

Co-Authored-by: Dmitry V. Levin <ldv@altlinux.org>
5 years agoxlat/gen.sh: speedup, part 2
Eugene Syromyatnikov [Tue, 5 Feb 2019 23:49:47 +0000 (00:49 +0100)]
xlat/gen.sh: speedup, part 2

* xlat/gen.sh (gen_header): Use "grep -q" instead of "grep > /dev/null".

5 years agoxlat/gen.sh: speedup, part 1
Eugene Syromyatnikov [Tue, 5 Feb 2019 23:49:47 +0000 (00:49 +0100)]
xlat/gen.sh: speedup, part 1

* xlat/gen.sh (cond_def, cond_xlat): Use printf builtin instead of cat.

5 years agoxlat/gen.sh: cleanup
Eugene Syromyatnikov [Tue, 5 Feb 2019 23:49:47 +0000 (00:49 +0100)]
xlat/gen.sh: cleanup

* xlat/gen.sh: Export LC_ALL=C so it could be omitted from individual
invocations.
(cond_def): Remove LC_ALL=C from sed invocation.
(gen_header): Remove LC_COLLATE=C.

5 years agoMakefile.am: pass D variable to shell scripts' environment
Eugene Syromyatnikov [Mon, 18 Feb 2019 23:01:01 +0000 (00:01 +0100)]
Makefile.am: pass D variable to shell scripts' environment

And set -x if D is set to 1, so the commands called by various shell scripts
are easier to see during debugging.

* Makefile.am (bpf_attr_check.c, sen.h, mpers-m%.stamp, $(srcdir)/CREDITS): Pass
D variable in the environment to the shell script call.
* gen_bpf_attr_check.sh: Set -x if D is set to 1.
* generate_mpers_am.sh: Likewise.
* generate_sen.sh: Likewise.
* maint/gen-contributors-list.sh: Likewise.
* mpers.sh: Likewise.
* mpers_test.sh: Likewise.

5 years agotests: add checks for dumpstr output into read-write test
Eugene Syromyatnikov [Wed, 20 Feb 2019 13:52:59 +0000 (14:52 +0100)]
tests: add checks for dumpstr output into read-write test

util.c:dumpstr() now aligns offsets in accordance with the total length
of the dump and also may perform only partial dump, so let's add checks
for these cases.

* tests/fill_memory.c (fill_memory_ex): Change the type of the period
argument from unsigned char to unsigned int.
* tests/tests.h (fill_memory_ex): Likewise.
* tests/read-write.c (dump_str_ex): Rename from dump_str, add idx_w
argument, support len greater than 240 bytes.
(dump_str): New function, wrapper for dump_str_ex with the default index
width.
(print_hex): Add checks for dumpstr output, close fd 1 later.

5 years agoutil: update dumpstr
Eugene Syromyatnikov [Tue, 19 Feb 2019 02:10:11 +0000 (03:10 +0100)]
util: update dumpstr

Use a buffer of a limited size, use proper type for dump amount, avoid
hard-coding of byte counts, calculate output buffer size more accurately
and minimise its rewriting, pad offset with zeros in accordance
with expected output amount.

* defs.h (dumpstr): Change the type of len argument from int to
kernel_ulong_t.
* macros.h (ROUNDUP_DIV): New macro.
(ROUNDUP): Rewrite using ROUNDUP_DIV.
* util.c (ILOG2_ITER_): New macro.
(ilog2_64, ilog2_32): New functions.
(ilog2_klong): New macro, wrapper around ilog2_32/ilog2_64, so (potentially
more expensive) ilog2_64 is not used for ilog2 calculation
of a kernel_ulong_t-typed variable on architectures with 32-bit kernel long.
(dumpstr): Update.

Co-Authored-by: Dmitry V. Levin <ldv@altlinux.org>
5 years agoGeneralise UUID printing
Eugene Syromyatnikov [Tue, 19 Feb 2019 01:50:53 +0000 (02:50 +0100)]
Generalise UUID printing

It was open-coded (using yet another open-coded hexadecimal character
printing) in btrfs.c and can be used in other places (like dm.c or
rtnl_link.c).

* defs.h (print_uuid): New declaration.
* print_fields.h (PRINT_FIELD_UUID): New macro.
* util.c (print_uuid): New function.
* btrfs.c (prnibble, UUID_STRING_SIZE, btrfs_unparse_uuid): Remove.
(btrfs_ioctl): Use PRINT_FIELD_UUID for UUID printing.

5 years agoGeneralise some printing primitives
Eugene Syromyatnikov [Tue, 19 Feb 2019 01:46:58 +0000 (02:46 +0100)]
Generalise some printing primitives

Character class checks and hexadecimal number formatting are open-coded
all over the place, let's try to de-duplicate them a bit.

* print_utils.h: New file.
* Makefile.am (strace_SOURCES): Add it.
* util.c: Include "print_utils.h".
(string_quote, dumpstr): Use sprint_byte_hex and is_print.
* v4l2.c: Include "print_utils.h".
(print_pixelformat): Use is_print and BYTE_HEX_CHARS_PRINTF_QUOTED,
add a note that the routine is rather generic.

5 years agoMove call_summary() from cleanup() to terminate()
Eugene Syromyatnikov [Tue, 19 Feb 2019 02:57:34 +0000 (03:57 +0100)]
Move call_summary() from cleanup() to terminate()

cleanup() has exactly two call sites, die() and terminate(), and the
first one resets cflag in order to prevent call_summary() invocation.
Move the call to terminate() in order to avoid bogus cflag reset.

* strace.c (die): Remove cflag reset.
(cleanup): Move call_summary() call ...
(terminate): ... here.

5 years agodefs.h: define stack_trace_enabled to 0 is stack tracing is not enabled
Eugene Syromyatnikov [Tue, 19 Feb 2019 02:50:25 +0000 (03:50 +0100)]
defs.h: define stack_trace_enabled to 0 is stack tracing is not enabled

This allows avoiding ifdefs sometimes.

* defs.h [!ENABLE_STACKTRACE] (stack_trace_enabled): Define as 0.
* strace.c (init): Remove #ifdef ENABLE_STACKTRACE around -c/-k check.

5 years agobuild: fix --with-libiberty
Dmitry V. Levin [Tue, 19 Feb 2019 01:39:32 +0000 (01:39 +0000)]
build: fix --with-libiberty

* m4/st_demangle.m4 (st_DEMANGLE): Move the check for cplus_demangle
out of AC_CHECK_HEADERS because the latter checks for demangle.h in two
different places and an absence of demangle.h in one of these places
would cause a build error in --with-libiberty=yes mode.
* NEWS: Mention this fix.

Resolves: https://github.com/strace/strace/issues/92

5 years agoHonor xlat styles when decoding ioprio_get and ioprio_set
Shankara Pailoor [Sat, 12 Jan 2019 04:59:00 +0000 (20:59 -0800)]
Honor xlat styles when decoding ioprio_get and ioprio_set

* ioprio.c (SYS_FUNC(ioprio_get), SYS_FUNC(ioprio_set)): Add xlat_style
support.
* tests/ioprio-Xabbrev.c: New file.
* tests/ioprio-Xraw.c: Likewise.
* tests/ioprio-Xverbose.c: Likewise.
* tests/ioprio.c: Handle XLAT_RAW, XLAT_ABBREV, and XLAT_VERBOSE macros.
* tests/gen_tests.in (ioprio-Xabbrev, ioprio-Xraw, ioprio-Xverbose): New
tests.
* tests/pure_executables.list: Add ioprio-Xabbrev, ioprio-Xraw, and
ioprio-Xverbose.
* tests/.gitignore: Likewise.

Co-Authored-by: Dmitry V. Levin <ldv@altlinux.org>
5 years agomove_pages: honor xlat styles
Shankara Pailoor [Sun, 13 Jan 2019 19:37:49 +0000 (11:37 -0800)]
move_pages: honor xlat styles

* numa.c (print_status): Add xlat_style support for status argument.
* tests/move_pages-Xabbrev.c: New file.
* tests/move_pages-Xraw.c: Likewise.
* tests/move_pages-Xverbose.c: Likewise.
* tests/move_pages.c: Handle XLAT_RAW, XLAT_ABBREV, and XLAT_VERBOSE
macros.
* tests/gen_tests.in (move_pages-Xabbrev, move_pages-Xraw,
move_pages-Xverbose): New tests.
* tests/pure_executables.list: Add move_pages-Xabbrev, move_pages-Xraw,
and move_pages-Xverbose.
* tests/.gitignore: Likewise.

5 years agotests: robustify threads-execve test against the odds
Dmitry V. Levin [Mon, 18 Feb 2019 00:29:43 +0000 (00:29 +0000)]
tests: robustify threads-execve test against the odds

Give threads-execve.test more chances to succeed.

* tests/threads-execve.test: Retry the test until run out of time.

5 years agoHonor xlat styles when decoding resource limits
Shankara Pailoor [Sat, 12 Jan 2019 03:07:33 +0000 (19:07 -0800)]
Honor xlat styles when decoding resource limits

* resource.c (sprint_rlim64, sprint_rlim32): Remove.
(print_rlim64_t, print_rlim32_t): New functions.
(print_rlimit64, print_rlimit32): Use them.
* tests/setrlimit-Xabbrev.c: New file.
* tests/setrlimit-Xraw.c: Likewise.
* tests/setrlimit-Xverbose.c: Likewise.
* tests/setrlimit.c (main): Handle XLAT_ABBREV, XLAT_RAW,
and XLAT_VERBOSE macros.
* tests/xgetrlimit.c (sprint_rlim): Likewise.
* tests/gen_tests.in (setrlimit-Xabbrev, setrlimit-Xraw,
setrlimit-Xverbose): New tests.
* tests/pure_executables.list: Add setrlimit-Xabbrev, setrlimit-Xraw,
and setrlimit-Xverbose.
* tests/.gitignore: Likewise.

Co-Authored-by: Dmitry V. Levin <ldv@altlinux.org>
5 years agohppa: workaround kernel bug in syscall number tampering
Dmitry V. Levin [Sun, 17 Feb 2019 00:10:26 +0000 (00:10 +0000)]
hppa: workaround kernel bug in syscall number tampering

Linux kernel commit v4.6-rc2~20^2 introduced a regression:
when tracer changes syscall number to -1, the kernel fails
to initialize %r28 with -ENOSYS and subsequently fails
to return the error code of the failed syscall to userspace.
Workaround this by initializing %r28 ourselves.

* linux/arch_defs_.h (ARCH_NEEDS_SET_ERROR_FOR_SCNO_TAMPERING): Define
to 0.
* linux/hppa/arch_defs_.h (ARCH_NEEDS_SET_ERROR_FOR_SCNO_TAMPERING):
Define to 1.
* syscall.c (tamper_with_syscall_entering)
[ARCH_NEEDS_SET_ERROR_FOR_SCNO_TAMPERING]: When changing syscall number
to -1, set the return value as well.

5 years agohppa: define PT_* constants as offsets inside struct pt_regs
Dmitry V. Levin [Sat, 16 Feb 2019 00:33:38 +0000 (00:33 +0000)]
hppa: define PT_* constants as offsets inside struct pt_regs

Define constants passed to upeek and upoke using a method that works
with different wordsize values.

* linux/hppa/arch_regs.c (PT_GR26, PT_GR30, PT_IAOQ0, PT_IAOQ1): Remove.
(PT_GR20, PT_GR28, ARCH_PC_PEEK_ADDR, ARCH_SP_PEEK_ADDR): Redefine using
offsets inside struct pt_regs.
* linux/hppa/get_syscall_args.c (arch_get_syscall_args): Replace PT_GR26
with offsets inside struct pt_regs.

5 years agohppa: enhance decoding of PTRACE_PEEKUSER and PTRACE_POKEUSER
Dmitry V. Levin [Sat, 16 Feb 2019 00:33:38 +0000 (00:33 +0000)]
hppa: enhance decoding of PTRACE_PEEKUSER and PTRACE_POKEUSER

Print symbolic constants corresponding to numeric arguments
of PTRACE_PEEKUSER and PTRACE_POKEUSER requests.

* linux/hppa/userent.h: New file.
* Makefile.am (EXTRA_DIST): Add it.
* NEWS: Mention this.

5 years agomips o32: fix 7th syscall argument with PTRACE_GET_SYSCALL_INFO API
Dmitry V. Levin [Fri, 15 Feb 2019 21:22:30 +0000 (21:22 +0000)]
mips o32: fix 7th syscall argument with PTRACE_GET_SYSCALL_INFO API

As PTRACE_GET_SYSCALL_INFO API supports 6 syscall arguments,
all architectures that have syscalls with more than 6 arguments
(i.e. mips o32) have to fetch extra arguments manually when using
PTRACE_GET_SYSCALL_INFO API.

* linux/mips/get_syscall_args.c [LINUX_MIPSO32]
(arch_get_syscall_args_extra): New function.
* syscall.c (get_syscall_args) [MAX_ARGS > 6]: Use it.

Fixes: v4.26~49 "Introduce PTRACE_GET_SYSCALL_INFO support"
5 years agomips: update comment
Dmitry V. Levin [Fri, 15 Feb 2019 21:22:30 +0000 (21:22 +0000)]
mips: update comment

* linux/mips/get_syscall_args.c (decode_syscall_subcall): Update comment.

Complements: v4.26-27-g2c8b6de91 "mips o32: fix build"

5 years agotests: add kill_child test
Eugene Syromyatnikov [Fri, 1 Feb 2019 10:04:51 +0000 (11:04 +0100)]
tests: add kill_child test

This tests repeatedly creates and kills children, so some corner
cases in handling of not-quite-existing processes can be observed.

Previously, strace was crashing in the following situation:

    13994 ????( <unfinished ...>
    ...
    13994 <... ???? resumed>) = ?

as tcp->s_ent wasn't initialised on syscall entering and
strace.c:print_event_exit segfaulted when tried to access
tcp->s_ent->sys_name.

* tests/kill_child.c: New file.
* tests/kill_child.test: New test.
* tests/.gitignore: Add kill_child.
* tests/Makefile.am (check_PROGRAMS): Likewise.
(MISC_TESTS): Add kill_child.test.

Co-Authored-by: Dmitry V. Levin <ldv@altlinux.org>
5 years agoWire up kexec_file_load syscall on architectures that use generic unistd.h
Dmitry V. Levin [Mon, 11 Feb 2019 23:35:07 +0000 (23:35 +0000)]
Wire up kexec_file_load syscall on architectures that use generic unistd.h

* linux/32/syscallent.h [294]: Wire up kexec_file_load syscall
introduced by linux commit v5.0-rc1~35^2~41^2~15.
* linux/64/syscallent.h [294]: Likewise.
* NEWS: Mention this.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1676045

5 years agoWire up rseq syscall on architectures that use generic unistd.h
Dmitry V. Levin [Mon, 11 Feb 2019 23:35:07 +0000 (23:35 +0000)]
Wire up rseq syscall on architectures that use generic unistd.h

* linux/32/syscallent.h [293]: Wire up rseq syscall introduced by linux
commit v4.19-rc1~109^2~47.
* linux/64/syscallent.h [293]: Likewise.
* NEWS: Mention this.

5 years agotests: robustify preadv2-pwritev2 test against odd kernels
Dmitry V. Levin [Mon, 11 Feb 2019 21:00:05 +0000 (21:00 +0000)]
tests: robustify preadv2-pwritev2 test against odd kernels

The test used to assume that either both preadv2 and pwritev2 syscalls
are implemented or both are not implemented, but, apparently, there are
kernels in the wild that implement just preadv2 syscall without
pwritev2.

* tests/preadv2-pwritev2.c (main): Skip the dumpio part of the test
if either preadv2 or pwritev2 syscall is not implemented.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1668750

5 years agoptrace_restart: do not print diagnostics when ptrace returns ESRCH
Eugene Syromyatnikov [Sun, 10 Feb 2019 23:57:38 +0000 (00:57 +0100)]
ptrace_restart: do not print diagnostics when ptrace returns ESRCH

After some discussion, it was decided that the situation
when the tracee is gone does not worth reporting.

* strace.c (ptrace_restart): Return early if ptrace returned ESRCH.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1662936

5 years agoptrace_restart: use xlat-based approach for printing ptrace requests
Eugene Syromyatnikov [Sun, 10 Feb 2019 23:45:37 +0000 (00:45 +0100)]
ptrace_restart: use xlat-based approach for printing ptrace requests

* defs.h (ptrace_cmds): New prototype.
* strace.c (ptrace_op_str): New function.
(ptrace_restart): Use it.

5 years agoFix whitespace issues
Dmitry V. Levin [Sun, 10 Feb 2019 21:04:41 +0000 (21:04 +0000)]
Fix whitespace issues

* Makefile.am (strace_SOURCES, EXTRA_DIST): Replace SPACE symbol followed
by TAB symbol with TAB symbol.
* kvm.c (is_map_for_file): Likewise.
* tests/gen_tests.in (ioctl_ptp, printsignal-Xverbose): Likewise.
* xlat/skf_ad.in: Likewise.

5 years agoMake inline message on failed restart attempt more verbose
Eugene Syromyatnikov [Sun, 10 Feb 2019 18:49:46 +0000 (19:49 +0100)]
Make inline message on failed restart attempt more verbose

Hopefully, now it is less confusing.

* strace.c (ptrace_restart): Provide intent and pid in the inline error
message.

References: https://bugzilla.redhat.com/show_bug.cgi?id=1662936

5 years agosyscall.c: set MEMORY_MAPPING_CHANGE in stub sysent
Eugene Syromyatnikov [Tue, 29 Jan 2019 14:35:00 +0000 (15:35 +0100)]
syscall.c: set MEMORY_MAPPING_CHANGE in stub sysent

As unknown syscalls may incur unknown side effects.

* syscall.c (stub_sysent): Set sys_flags to MEMORY_MAPPING_CHANGE.

5 years agoUse accessors for tcp->s_ent, return a stub struct if it is NULL
Eugene Syromyatnikov [Tue, 29 Jan 2019 13:40:11 +0000 (14:40 +0100)]
Use accessors for tcp->s_ent, return a stub struct if it is NULL

Since code paths are non-trivial, it's an attempt to future-proof
and prevent improper access of tcp->s_ent fields.

* defs.h (struct tcb): Update the description of s_ent field.
(stub_sysent): New declaration.
(tcp_sysent, n_args): New macro functions.
(indirect_ipccall): Use tcp_sysent() instead of tcp->s_ent.
* ipc.c (SYS_FUNC(ipc)): Use n_args() instead of tcp->s_ent->nargs.
* linux/alpha/get_syscall_args.c (get_syscall_args): Likewise.
* linux/bfin/get_syscall_args.c (get_syscall_args): Likewise.
* linux/hppa/get_syscall_args.c (get_syscall_args): Likewise.
* linux/ia64/get_syscall_args.c (get_syscall_args): Likewise.
* linux/microblaze/get_syscall_args.c (get_syscall_args): Likewise.
* linux/mips/get_syscall_args.c (get_syscall_args): Likewise.
* linux/sh/get_syscall_args.c (get_syscall_args): Likewise.
* linux/sh64/get_syscall_args.c (get_syscall_args): Likewise.
* linux/x86_64/get_syscall_args.c (get_syscall_args): Likewise.
* linux/xtensa/get_syscall_args.c (get_syscall_args): Likewise.
* prctl.c (print_prctl_args): Likewise.
* signal.c (SYS_FUNC(sgetmask)): Likewise.
* util.c (printargs, printargs_u, printargs_d): Likewise.
* syscall.c (decode_ipc_subcall, decode_syscall_subcall: Likewise.
(dumpio, tamper_with_syscall_exiting, syscall_entering_decode,
syscall_entering_decode, syscall_entering_trace, syscall_entering_trace,
syscall_exiting_decode, print_syscall_resume, syscall_exiting_trace,
get_syscall_result): Use tcp_sysent() instead of tcp->s_ent.
(stub_sysent): New stub sysent.
(get_scno): Reset scno, s_ent, qual_flg; initialise s->ent from
stub_sysent.
* pathtrace.c (pathtrace_match_set): Use tcp_sysent() instead of
tcp->s_ent.

Co-Authored-by: Dmitry V. Levin <ldv@altlinux.org>
5 years agosyscall.c: remove arch check for SEN_execv usage
Eugene Syromyatnikov [Tue, 29 Jan 2019 13:07:46 +0000 (14:07 +0100)]
syscall.c: remove arch check for SEN_execv usage

SEN_* declarations are always present and can be used regardless
of architecture.

* syscall.c (syscall_entering_trace): Remove "#if defined SPARC ||
defined SPARC64" guard.

5 years agoMerge "<... resumed>" printing
Eugene Syromyatnikov [Tue, 29 Jan 2019 12:54:23 +0000 (13:54 +0100)]
Merge "<... resumed>" printing

Apparently, it was slightly different with no apparent reason.
Use a single routine to print this message now.

* defs.h (print_syscall_resume): New function declaration.
* strace.c (print_event_exit): Replace open-coding of "<... resumed>"
message printing with a print_syscall_resume() call.
* syscall.c (syscall_exiting_trace): Likewise.
(print_syscall_resume): New function.
* tests/threads-execve.c: Update expected output.

5 years agosockaddr: print sin6_flowinfo field before sin6_addr
Shankara Pailoor [Wed, 9 Jan 2019 17:09:04 +0000 (09:09 -0800)]
sockaddr: print sin6_flowinfo field before sin6_addr

The sin6_flowinfo field comes before sin6_addr in the sockaddr_in6
defintion, but for some reason we switch the order when decoding.
This patch fixes the order of decoding.

* sockaddr.c (print_sockaddr_data_in6): Print sin6_flowinfo field
before sin6_addr.
* NEWS: Mention this fix.
* tests/group_req.c (main): Update expected output.
* tests/net-sockaddr.c (check_in6_linklocal, check_in6): Likewise.
* tests/net-yy-inet6.c (INADDR_STR, SA_FIELDS): Likewise.
* tests/sockaddr_xlat.c (validate_in6): Likewise.

5 years agomips o32: fix build
Dmitry V. Levin [Tue, 8 Jan 2019 19:23:44 +0000 (19:23 +0000)]
mips o32: fix build

Commit 917c2ccf3a67 "Refactor stack pointers" moved mips_REG_* macros
from linux/mips/arch_regs.h to linux/mips/arch_regs.c because these
macros are no longer used outside syscall.c or files included by
syscall.c, but this caused a build regression on mips o32 because
decode_syscall_subcall() uses mips_REG_SP prior to its definition.

* syscall.c (decode_syscall_subcall): Move ...
* linux/mips/get_syscall_args.c: ... here.
* NEWS: Mention this fix.

Reported-by: Baruch Siach <baruch@tkos.co.il>
Fixes: v4.26~61 "Refactor stack pointers"
5 years agoFix build for no-MMU targets
Baruch Siach [Tue, 8 Jan 2019 16:36:20 +0000 (18:36 +0200)]
Fix build for no-MMU targets

Commit 7488ce9e23f1 "Check whether PTRACE_GET_SYSCALL_INFO is supported
by the kernel" added a fork() call in test_ptrace_get_syscall_info()
which is included in the main strace executable code.  Although the
test_ptrace_get_syscall_info() routine is not called on no-MMU targets,
the compiler can't optimize it out because it is a global symbol.
So build for no-MMU targets currently fails:

strace-ptrace_syscall_info.o: In function `test_ptrace_get_syscall_info':
ptrace_syscall_info.c:(.text+0x1c): undefined reference to `fork'

* ptrace_syscall_info.c (test_ptrace_get_syscall_info): Make
the definition depend on HAVE_FORK.
* strace.c (init): Call test_ptrace_get_syscall_info unconditionally.
* NEWS: Mention this fix.

Co-Authored-by: Dmitry V. Levin <ldv@altlinux.org>
Fixes: v4.26~50 "Check whether PTRACE_GET_SYSCALL_INFO is supported by the kernel"
5 years agolinux/mips/.gitignore: drop copyright header
Baruch Siach [Tue, 8 Jan 2019 17:15:35 +0000 (19:15 +0200)]
linux/mips/.gitignore: drop copyright header

The '/*' in the first line of the copyright header matches all files in
that directory.  No other .gitignore file has this header.  Drop it.

* linux/mips/.gitignore: Remove copyright header.

Fixes: v4.26~23 "Add copyright headers to some files that lack them"
5 years agoHonor xlat styles when decoding sockaddr_in, sockaddr_in6, and sockaddr_ll
Shankara Pailoor [Wed, 2 Jan 2019 21:15:28 +0000 (13:15 -0800)]
Honor xlat styles when decoding sockaddr_in, sockaddr_in6, and sockaddr_ll

* print_fields.h (PRINT_FIELD_NET_PORT): Handle xlat styles.
* sockaddr.c (print_sll_protocol): New function.
(print_sockaddr_data_ll, print_inet_addr, print_sockaddr_data_in6):
Handle xlat styles.
* NEWS: Mention this.
* tests/sockaddr_xlat.c: New file.
* tests/sockaddr_xlat-Xabbrev.c: Likewise.
* tests/sockaddr_xlat-Xraw.c: Likewise.
* tests/sockaddr_xlat-Xverbose.c: Likewise.
* tests/Makefile.am (EXTRA_DIST): Add sockaddr_xlat.c.
* tests/gen_tests.in (sockaddr_xlat-Xabbrev, sockaddr_xlat-Xraw,
sockaddr_xlat-Xverbose): New tests.
* tests/pure_executables.list: Add sockaddr_xlat-Xabbrev,
sockaddr_xlat-Xraw, and sockaddr_xlat-Xverbose.
* tests/.gitignore: Likewise.

5 years agoRemove PRINT_FIELD_INET4_ADDR
Dmitry V. Levin [Mon, 7 Jan 2019 23:30:52 +0000 (23:30 +0000)]
Remove PRINT_FIELD_INET4_ADDR

Reduce code duplication by removing PRINT_FIELD_INET4_ADDR
and using PRINT_FIELD_INET_ADDR instead.

* print_fields.h (PRINT_FIELD_INET4_ADDR): Remove.
* msghdr.c (print_cmsg_ip_pktinfo): Use PRINT_FIELD_INET_ADDR
instead of PRINT_FIELD_INET4_ADDR.
* net.c (print_mreq): Likewise.
* sockaddr.c (print_sockaddr_data_in): Likewise.

5 years agoxlat: update REL_* constants
Dmitry V. Levin [Sat, 5 Jan 2019 21:14:42 +0000 (21:14 +0000)]
xlat: update REL_* constants

* xlat/evdev_relative_axes.in (REL_HWHEEL_HI_RES): New constant
introduced by Linux kernel commit v5.0-rc1~18^2^7~7.
* NEWS: Mention this.

5 years agoxlat: update UDP_* constants
Dmitry V. Levin [Sat, 5 Jan 2019 21:14:42 +0000 (21:14 +0000)]
xlat: update UDP_* constants

* xlat/sock_udp_options.in (UDP_GRO): New constant introduced
by Linux kernel commit v5.0-rc1~129^2~379^2~8.
* NEWS: Mention this.

5 years agoxlat: update FAN_* constants
Dmitry V. Levin [Sat, 5 Jan 2019 21:14:42 +0000 (21:14 +0000)]
xlat: update FAN_* constants

* xlat/fan_event_flags.in (FAN_OPEN_EXEC, FAN_OPEN_EXEC_PERM): New
constants introduced by Linux kernel commits v5.0-rc1~124^2~5
and v5.0-rc1~124^2~3, respectively.
* NEWS: Mention this.
* tests/fanotify_mark.c (main): Update expected output.

5 years agoxlat: update SCTP_* constants
Dmitry V. Levin [Sat, 5 Jan 2019 21:14:42 +0000 (21:14 +0000)]
xlat: update SCTP_* constants

* xlat/sock_sctp_options.in (SCTP_EVENT): New constant introduced
by Linux kernel commit v5.0-rc1~129^2~255^2.
* NEWS: Mention this.

5 years agoxlat: update IFLA_* constants
Dmitry V. Levin [Sat, 5 Jan 2019 21:14:42 +0000 (21:14 +0000)]
xlat: update IFLA_* constants

* xlat/rtnl_ifla_info_data_bridge_attrs.in (IFLA_BR_MULTI_BOOLOPT): New
constant introduced by Linux kernel commit v5.0-rc1~129^2~207^2~2.
* NEWS: Mention this.
* tests/nlattr_ifla_linkinfo.c (main): Update.

5 years agoxlat: update NETNSA_* constants
Dmitry V. Levin [Sat, 5 Jan 2019 21:14:42 +0000 (21:14 +0000)]
xlat: update NETNSA_* constants

* xlat/rtnl_nsid_attrs.in (NETNSA_TARGET_NSID, NETNSA_CURRENT_NSID): New
constants introduced by Linux kernel commits v5.0-rc1~129^2~201^2~2
and v5.0-rc1~129^2~201^2, respectively.
* rtnl_nsid.c (rtgenmsg_nla_decoders): Add NETNSA_TARGET_NSID
and NETNSA_CURRENT_NSID.
* NEWS: Mention this.

5 years agoxlat: update SECCOMP_* constants
Dmitry V. Levin [Sat, 5 Jan 2019 21:14:42 +0000 (21:14 +0000)]
xlat: update SECCOMP_* constants

* xlat/seccomp_ops.in (SECCOMP_GET_NOTIF_SIZES): New constant introduced
by Linux kernel commit v5.0-rc1~66^2~1^2~1.
* xlat/seccomp_ret_action.in (SECCOMP_RET_USER_NOTIF): Likewise.
* xlat/seccomp_filter_flags.in (SECCOMP_FILTER_FLAG_NEW_LISTENER):
Likewise.
* NEWS: Mention this.
* tests/seccomp-filter.c (main): Update expected output.
* tests/seccomp-filter-v.c (main): Likewise.
* tests/seccomp_get_action_avail.c (main): Check SECCOMP_RET_USER_NOTIF.

5 years agoxlat: update NT_* constants
Dmitry V. Levin [Sat, 5 Jan 2019 21:14:42 +0000 (21:14 +0000)]
xlat: update NT_* constants

* xlat/nt_descriptor_types.in (NT_ARM_PAC_MASK, NT_MIPS_MSA): New
constants introduced by Linux kernel commits v5.0-rc1~35^2~21
and v5.0-rc1~30^2~58, respectively.
* NEWS: Mention this.

5 years agoxlat: update PR_* constants
Dmitry V. Levin [Sat, 5 Jan 2019 21:14:42 +0000 (21:14 +0000)]
xlat: update PR_* constants

* xlat/prctl_options.in (PR_PAC_RESET_KEYS): New constant introduced
by Linux kernel commit v5.0-rc1~35^2~19.
* NEWS: Mention this.

5 years agoxlat: update V4L2_* constants
Dmitry V. Levin [Sat, 5 Jan 2019 21:14:42 +0000 (21:14 +0000)]
xlat: update V4L2_* constants

* xlat/v4l2_buf_types.in (V4L2_BUF_TYPE_META_OUTPUT): New constant
introduced by Linux kernel commit v5.0-rc1~181^2~21.
* xlat/v4l2_device_capabilities_flags.in (V4L2_CAP_META_OUTPUT):
Likewise.
* xlat/v4l2_pix_fmts.in (V4L2_PIX_FMT_CNF4): New constant introduced
by Linux kernel commit v5.0-rc1~182^2~120.
* NEWS: Mention this.

5 years agoxlat: update KVM_CAP_* constants
Dmitry V. Levin [Sat, 5 Jan 2019 21:14:42 +0000 (21:14 +0000)]
xlat: update KVM_CAP_* constants

* xlat/kvm_cap.in (KVM_CAP_MANUAL_DIRTY_LOG_PROTECT,
KVM_CAP_HYPERV_CPUID): New constants introduced by Linux kernel commits
v5.0-rc1~156^2~115 and v5.0-rc1~156^2~74, respectively.
* NEWS: Mention this.

5 years agoxlat: update NDA_* constants
Dmitry V. Levin [Sat, 5 Jan 2019 21:14:42 +0000 (21:14 +0000)]
xlat: update NDA_* constants

* xlat/rtnl_neigh_attrs.in (NDA_PROTOCOL): New constant introduced
by Linux kernel commit v5.0-rc1~129^2~79.
* rtnl_neigh.c (ndmsg_nla_decoders): Add NDA_PROTOCOL.
* NEWS: Mention this.

5 years agoxlat: update BTRFS_FEATURE_INCOMPAT_* constants
Dmitry V. Levin [Sat, 5 Jan 2019 21:14:42 +0000 (21:14 +0000)]
xlat: update BTRFS_FEATURE_INCOMPAT_* constants

* xlat/btrfs_features_incompat.in
(BTRFS_FEATURE_INCOMPAT_METADATA_UUID): New constant introduced by Linux
kernel commit v5.0-rc1~126^2~64.
* NEWS: Mention this.

5 years agoxlat: update *_MAGIC constants
Dmitry V. Levin [Sat, 5 Jan 2019 21:14:42 +0000 (21:14 +0000)]
xlat: update *_MAGIC constants

* xlat/fsmagic.in (BINDERFS_SUPER_MAGIC): New constant introduced
by Linux kernel commit v5.0-rc1~95^2~15.
* NEWS: Mention this.

5 years agoxlat: update KERN_* constants
Dmitry V. Levin [Sat, 5 Jan 2019 21:14:42 +0000 (21:14 +0000)]
xlat: update KERN_* constants

* xlat/sysctl_kern.in (KERN_PANIC_ON_WARN, KERN_PANIC_PRINT): New
constants introduced by Linux kernel commits v3.19-rc1~135^2~91
and v5.0-rc1~38^2~16, respectively.
* configure.ac (AC_CHECK_DECLS): Add them.
* NEWS: Mention this.

5 years agoxlat: update BPF_F_* constants
Dmitry V. Levin [Thu, 3 Jan 2019 23:36:22 +0000 (23:36 +0000)]
xlat: update BPF_F_* constants

* xlat/bpf_map_flags.in (BPF_F_ZERO_SEED): New constant introduced
by Linux kernel commit v5.0-rc1~129^2~114^2~18^2~3.
* xlat/bpf_prog_flags.in (BPF_F_ANY_ALIGNMENT): New constant introduced
by Linux kernel commit v5.0-rc1~129^2~209^2~17^2~3.
* NEWS: Mention this.
* tests/bpf.c (BPF_MAP_CREATE_checks, BPF_PROG_LOAD_checks,
print_BPF_PROG_LOAD_attr3, print_BPF_PROG_LOAD_attr4): Update.

5 years agotests: fix prog_info initialization in bpf-obj_get_info_by_fd-prog*
Martin Lau [Thu, 3 Jan 2019 23:36:22 +0000 (23:36 +0000)]
tests: fix prog_info initialization in bpf-obj_get_info_by_fd-prog*

The sys_bpf(BPF_OBJ_GET_INFO_BY_FD, &bpf_prog_get_info_attr, ...) is
called in a loop.  The bpf_prog_get_info_attr.info object is in size 104
but bpf_prog_get_info_attr.info_len is in size 168.  Hence, if the prog
is jited, the second iteration onwards will have nr_jited_ksyms == 1
which is asking the kernel to fill the
bpf_prog_get_info_attr.info.jited_ksyms and it is NULL.

* tests/bpf-obj_get_info_by_fd.c (main): Clear memory beyond prog_info
at the start of every iteration.

Co-Authored-by: Dmitry V. Levin <ldv@altlinux.org>
5 years agotests: use tail_alloc instead of calloc in bpf-obj_get_info_by_fd-prog*
Dmitry V. Levin [Thu, 3 Jan 2019 23:36:22 +0000 (23:36 +0000)]
tests: use tail_alloc instead of calloc in bpf-obj_get_info_by_fd-prog*

This guarantees that map_info and prog_info objects are not accessed
out of bounds.

* tests/bpf-obj_get_info_by_fd.c: Include <string.h>.
(main): Use tail_alloc instead of calloc for map_info and prog_info.

5 years agoBring lists back to the sorted order
Dmitry V. Levin [Wed, 2 Jan 2019 00:29:09 +0000 (00:29 +0000)]
Bring lists back to the sorted order

* .gitignore: Make the list sorted again.
* Makefile.am (strace_SOURCES): Likewise.
* tests/.gitignore: Likewise.
* tests/gen_tests.in: Likewise.
* tests/Makefile.am (check_PROGRAMS, DECODER_TESTS, EXTRA_DIST):
Likewise.

5 years agotests: fix strace-k.test on alpha
Dmitry V. Levin [Tue, 1 Jan 2019 21:36:08 +0000 (21:36 +0000)]
tests: fix strace-k.test on alpha

Change strace-k.test to use chdir syscall instead of getpid syscall
because the latter is not universally available, e.g. there is no getpid
syscall on alpha.

* tests/stack-fcall-3.c (f3) <default>: Replace getpid with chdir.
* tests/strace-k.test: Likewise.
* tests/strace-k.expected: Likewise.
* tests/strace-k-demangle.expected: Likewise.
* NEWS: Mention this.