[PATCHv4] print stack trace after each syscall
Luca Clementi
luca.clementi at gmail.com
Wed Sep 18 06:47:03 UTC 2013
On Tue, Sep 17, 2013 at 5:12 AM, Masatake YAMATO <yamato at redhat.com> wrote:
>> In the patch `delete_mmap_cache' is used as a trigger for updating
>> proc/maps info cache. It is called as expected when mmap and friends
>> are traced. However, if the tracing is disabled with -e option, strae
>> misses the chance to updating the info cache.
>
> Could you review this patch for the bug I reported and merge if appreciated.
>
> `REQUIRED_BY_STACKTRACE' is introduced to trigger the `delete_mmap_cache'.
>
It works for me.
Acked-by: Luca Clementi <luca.clementi at gmail.com>
Thanks for the fix,
Luca
> Masatake YAMATO
>
>
>
> diff --git a/defs.h b/defs.h
> index 7f76008..46188c9 100644
> --- a/defs.h
> +++ b/defs.h
> @@ -557,6 +557,7 @@ extern const struct xlat whence_codes[];
> #define TRACE_DESC 040 /* Trace file descriptor-related syscalls. */
> #define TRACE_MEMORY 0100 /* Trace memory mapping-related syscalls. */
> #define SYSCALL_NEVER_FAILS 0200 /* Syscall is always successful. */
> +#define REQUIRED_BY_STACKTRACE 0400 /* Trigger proc/maps cache updating */
>
> typedef enum {
> CFLAG_NONE = 0,
> diff --git a/linux/x86_64/syscallent.h b/linux/x86_64/syscallent.h
> index 8e3a200..a710401 100644
> --- a/linux/x86_64/syscallent.h
> +++ b/linux/x86_64/syscallent.h
> @@ -7,9 +7,9 @@
> { 2, TF, sys_lstat, "lstat" }, /* 6 */
> { 3, TD, sys_poll, "poll" }, /* 7 */
> { 3, TD, sys_lseek, "lseek" }, /* 8 */
> - { 6, TD|TM, sys_mmap, "mmap" }, /* 9 */
> - { 3, TM, sys_mprotect, "mprotect" }, /* 10 */
> - { 2, TM, sys_munmap, "munmap" }, /* 11 */
> + { 6, TD|TM|RT,sys_mmap, "mmap" }, /* 9 */
> + { 3, TM|RT, sys_mprotect, "mprotect" }, /* 10 */
> + { 2, TM|RT, sys_munmap, "munmap" }, /* 11 */
> { 1, TM, sys_brk, "brk" }, /* 12 */
> { 4, TS, sys_rt_sigaction, "rt_sigaction" }, /* 13 */
> { 4, TS, sys_rt_sigprocmask, "rt_sigprocmask"}, /* 14 */
> @@ -23,7 +23,7 @@
> { 1, TD, sys_pipe, "pipe" }, /* 22 */
> { 5, TD, sys_select, "select" }, /* 23 */
> { 0, 0, sys_sched_yield, "sched_yield" }, /* 24 */
> - { 5, TM, sys_mremap, "mremap" }, /* 25 */
> + { 5, TM|RT, sys_mremap, "mremap" }, /* 25 */
> { 3, TM, sys_msync, "msync" }, /* 26 */
> { 3, TM, sys_mincore, "mincore" }, /* 27 */
> { 3, TM, sys_madvise, "madvise" }, /* 28 */
> @@ -57,7 +57,7 @@
> { 5, TP, sys_clone, "clone" }, /* 56 */
> { 0, TP, sys_fork, "fork" }, /* 57 */
> { 0, TP, sys_vfork, "vfork" }, /* 58 */
> - { 3, TF|TP, sys_execve, "execve" }, /* 59 */
> + { 3, TF|TP|RT,sys_execve, "execve" }, /* 59 */
> { 1, TP, sys_exit, "_exit" }, /* 60 */
> { 4, TP, sys_wait4, "wait4" }, /* 61 */
> { 2, TS, sys_kill, "kill" }, /* 62 */
> diff --git a/mem.c b/mem.c
> index ca6caa1..ef273c7 100644
> --- a/mem.c
> +++ b/mem.c
> @@ -175,11 +175,6 @@ static int
> print_mmap(struct tcb *tcp, long *u_arg, unsigned long long offset)
> {
> if (entering(tcp)) {
> -#ifdef USE_LIBUNWIND
> - if (stack_trace_enabled)
> - delete_mmap_cache(tcp);
> -#endif
> -
> /* addr */
> if (!u_arg[0])
> tprints("NULL, ");
> @@ -309,12 +304,6 @@ sys_munmap(struct tcb *tcp)
> tprintf("%#lx, %lu",
> tcp->u_arg[0], tcp->u_arg[1]);
> }
> -#ifdef USE_LIBUNWIND
> - else {
> - if (stack_trace_enabled)
> - delete_mmap_cache(tcp);
> - }
> -#endif
> return 0;
> }
>
> @@ -326,12 +315,6 @@ sys_mprotect(struct tcb *tcp)
> tcp->u_arg[0], tcp->u_arg[1]);
> printflags(mmap_prot, tcp->u_arg[2], "PROT_???");
> }
> -#ifdef USE_LIBUNWIND
> - else {
> - if (stack_trace_enabled)
> - delete_mmap_cache(tcp);
> - }
> -#endif
> return 0;
> }
>
> diff --git a/process.c b/process.c
> index 22bb5b6..aaea9c5 100644
> --- a/process.c
> +++ b/process.c
> @@ -992,12 +992,6 @@ sys_execve(struct tcb *tcp)
> tprints("]");
> }
> }
> -#ifdef USE_LIBUNWIND
> - else {
> - if (stack_trace_enabled)
> - delete_mmap_cache(tcp);
> - }
> -#endif
>
> return 0;
> }
> diff --git a/syscall.c b/syscall.c
> index b01c023..7ddde88 100644
> --- a/syscall.c
> +++ b/syscall.c
> @@ -97,6 +97,7 @@
> #define TM TRACE_MEMORY
> #define NF SYSCALL_NEVER_FAILS
> #define MA MAX_ARGS
> +#define RT REQUIRED_BY_STACKTRACE
>
> const struct_sysent sysent0[] = {
> #include "syscallent.h"
> @@ -2712,6 +2713,11 @@ trace_syscall_exiting(struct tcb *tcp)
> #endif
>
> ret:
> +#ifdef USE_LIBUNWIND
> + if (stack_trace_enabled)
> + if (tcp->s_ent->sys_flags & REQUIRED_BY_STACKTRACE)
> + delete_mmap_cache(tcp);
> +#endif
> tcp->flags &= ~TCB_INSYSCALL;
> return 0;
> }
More information about the Strace-devel
mailing list