[PATCH v6 9/9] Add stacktrace filter action

Masatake YAMATO yamato at redhat.com
Wed Aug 2 11:42:54 UTC 2017


Works fine. Really nice! This is what I have wanted.
Why don't you update strace.1 ? 

    $ ./strace -e 'stacktrace(syscall lseek)' u-ctags strace.c
    ...
    write(3, "ed_log\tstrace.c\t/^static FILE *s"..., 4096) = 4096
    write(3, "me:void\nfputs_unlocked\tstrace.c\t"..., 4096) = 4096
    munmap(0x7fe720590000, 167936)          = 0
    write(3, " const siginfo_t *si, const unsi"..., 1525) = 1525
    lseek(3, 0, SEEK_CUR)                   = 13813
     > /usr/lib64/libc-2.24.so(llseek+0x7) [0x107e37]
     > /usr/lib64/libc-2.24.so(_IO_file_seekoff+0x519) [0x7a659]
     > /usr/lib64/libc-2.24.so(ftell+0x74) [0x6f864]
     > /home/yamato/var/ctags-github/ctags(closeTagFile+0x60) [0x5290]
     > /home/yamato/var/ctags-github/ctags(batchMakeTags+0x3d9) [0xc479]
     > /home/yamato/var/ctags-github/ctags(main+0x9f) [0x342f]
     > /usr/lib64/libc-2.24.so(__libc_start_main+0xf1) [0x20401]
     > /home/yamato/var/ctags-github/ctags(_start+0x2a) [0x34aa]
    fstat(3, {st_mode=S_IFREG|0644, st_size=13813, ...}) = 0
    lseek(3, 13813, SEEK_SET)               = 13813
     > /usr/lib64/libc-2.24.so(llseek+0x7) [0x107e37]
     > /usr/lib64/libc-2.24.so(_IO_file_seekoff+0xde) [0x7a21e]
     > /usr/lib64/libc-2.24.so(fseek+0x79) [0x77959]
     > /home/yamato/var/ctags-github/ctags(closeTagFile+0x76) [0x52a6]
     > /home/yamato/var/ctags-github/ctags(batchMakeTags+0x3d9) [0xc479]
     > /home/yamato/var/ctags-github/ctags(main+0x9f) [0x342f]
     > /usr/lib64/libc-2.24.so(__libc_start_main+0xf1) [0x20401]
     > /home/yamato/var/ctags-github/ctags(_start+0x2a) [0x34aa]
    close(3)                                = 0
    rt_sigaction(SIGINT, {sa_handler=SIG_IGN, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7fe71f385950}, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=0}, 8) = 0
    rt_sigaction(SIGQUIT, {sa_handler=SIG_IGN, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7fe71f385950}, {sa_handler=SIG_DFL, sa_mask=[]
    ...

Masatake YAMATO


> * defs.h (QUAL_STACKTRACE): Add new qual flag.
> (stacktrace): Add macro for checking QUAL_STACKTRACE.
> (stack_trace_enabled): Change description.
> * filter_action.c (action_types): Declare and add new filter action type.
> (update_default_flags): Update stack_trace_enabled.
> * strace.c (stack_trace_enabled): Change description.
> (init): Use filtering_parse for -k option.
> * syscall.c (syscall_entering_trace, syscall_exiting_decode,
>  syscall_exiting_trace): Use stacktrace macro instead of stack_trace_enabled.
> * unwind.c (apply_stacktrace): Add filter action function.
> ---
>  defs.h          |  6 +++++-
>  filter_action.c | 10 ++++++++++
>  strace.c        |  4 ++--
>  syscall.c       |  6 +++---
>  unwind.c        |  6 ++++++
>  5 files changed, 26 insertions(+), 6 deletions(-)
> 
> diff --git a/defs.h b/defs.h
> index a2a1c9f..14316c0 100644
> --- a/defs.h
> +++ b/defs.h
> @@ -269,6 +269,9 @@ struct tcb {
>  #define QUAL_SIGNAL	0x100	/* report events with this signal */
>  #define QUAL_READ	0x200	/* dump data read in this syscall */
>  #define QUAL_WRITE	0x400	/* dump data written in this syscall */
> +#ifdef USE_LIBUNWIND
> +# define QUAL_STACKTRACE	0x800	/* do the stack trace */
> +#endif
>  
>  #define DEFAULT_QUAL_FLAGS (QUAL_TRACE | QUAL_ABBREV | QUAL_VERBOSE)
>  
> @@ -279,6 +282,7 @@ struct tcb {
>  #define abbrev(tcp)	((tcp)->qual_flg & QUAL_ABBREV)
>  #define dump_read(tcp)	((tcp)->qual_flg & QUAL_READ)
>  #define dump_write(tcp)	((tcp)->qual_flg & QUAL_WRITE)
> +#define stacktrace(tcp)	((tcp)->qual_flg & QUAL_STACKTRACE) 
>  #define filtered(tcp)	((tcp)->flags & TCB_FILTERED)
>  #define hide_log(tcp)	((tcp)->flags & TCB_HIDE_LOG)
>  
> @@ -378,7 +382,7 @@ extern struct path_set {
>  extern unsigned xflag;
>  extern unsigned followfork;
>  #ifdef USE_LIBUNWIND
> -/* if this is true do the stack trace for every system call */
> +/* if this is true do the initialization of stack trace mechanism */
>  extern bool stack_trace_enabled;
>  #endif
>  extern unsigned ptrace_setoptions;
> diff --git a/filter_action.c b/filter_action.c
> index 5143bf3..5140197 100644
> --- a/filter_action.c
> +++ b/filter_action.c
> @@ -41,6 +41,9 @@ DECL_FILTER_ACTION(write);
>  DECL_FILTER_ACTION(raw);
>  DECL_FILTER_ACTION(abbrev);
>  DECL_FILTER_ACTION(verbose);
> +# ifdef USE_LIBUNWIND
> +DECL_FILTER_ACTION(stacktrace);
> +# endif
>  #undef DECL_FILTER_ACTION
>  
>  extern bool is_traced(struct tcb *);
> @@ -77,6 +80,9 @@ static const struct filter_action_type {
>  	FILTER_ACTION_TYPE(raw,		1,	null,	is_traced),
>  	FILTER_ACTION_TYPE(abbrev,	1,	null,	is_traced),
>  	FILTER_ACTION_TYPE(verbose,	1,	null,	is_traced),
> +# ifdef USE_LIBUNWIND
> +	FILTER_ACTION_TYPE(stacktrace,	1,	null,	is_traced),
> +# endif
>  };
>  #undef FILTER_ACTION_TYPE
>  
> @@ -148,6 +154,10 @@ update_default_flags(const char *name)
>  	} else if ((default_flags & QUAL_VERBOSE) && !strcmp(name, "verbose")) {
>  		default_flags &= ~QUAL_VERBOSE;
>  		return;
> +	} else if (!strcmp(name, "stacktrace")) {
> +#ifdef USE_LIBUNWIND
> +		stack_trace_enabled = true;
> +#endif
>  	}
>  
>  }
> diff --git a/strace.c b/strace.c
> index 560beea..14d73af 100644
> --- a/strace.c
> +++ b/strace.c
> @@ -56,7 +56,7 @@ extern int optind;
>  extern char *optarg;
>  
>  #ifdef USE_LIBUNWIND
> -/* if this is true do the stack trace for every system call */
> +/* if this is true do the initialization of stack trace mechanism */
>  bool stack_trace_enabled;
>  #endif
>  
> @@ -1761,7 +1761,7 @@ init(int argc, char *argv[])
>  			break;
>  #ifdef USE_LIBUNWIND
>  		case 'k':
> -			stack_trace_enabled = true;
> +			filtering_parse("stacktrace(syscall all)");
>  			break;
>  #endif
>  		case 'E':
> diff --git a/syscall.c b/syscall.c
> index 48ee62f..b0bb33b 100644
> --- a/syscall.c
> +++ b/syscall.c
> @@ -723,7 +723,7 @@ syscall_entering_trace(struct tcb *tcp, unsigned int *sig)
>  	}
>  
>  #ifdef USE_LIBUNWIND
> -	if (stack_trace_enabled) {
> +	if (stacktrace(tcp)) {
>  		if (tcp->s_ent->sys_flags & STACKTRACE_CAPTURE_ON_ENTER)
>  			unwind_capture_stacktrace(tcp);
>  	}
> @@ -769,7 +769,7 @@ syscall_exiting_decode(struct tcb *tcp, struct timeval *ptv)
>  		gettimeofday(ptv, NULL);
>  
>  #ifdef USE_LIBUNWIND
> -	if (stack_trace_enabled) {
> +	if (stacktrace(tcp)) {
>  		if (tcp->s_ent->sys_flags & STACKTRACE_INVALIDATE_CACHE)
>  			unwind_cache_invalidate(tcp);
>  	}
> @@ -989,7 +989,7 @@ syscall_exiting_trace(struct tcb *tcp, struct timeval tv, int res)
>  	line_ended();
>  
>  #ifdef USE_LIBUNWIND
> -	if (stack_trace_enabled)
> +	if (stacktrace(tcp))
>  		unwind_print_stacktrace(tcp);
>  #endif
>  	return 0;
> diff --git a/unwind.c b/unwind.c
> index 919b63c..caab414 100644
> --- a/unwind.c
> +++ b/unwind.c
> @@ -589,3 +589,9 @@ unwind_capture_stacktrace(struct tcb *tcp)
>  		DPRINTF("tcp=%p, queue=%p", "captured", tcp, tcp->queue->head);
>  	}
>  }
> +
> +void
> +apply_stacktrace(struct tcb *tcp, void *_priv_data)
> +{
> +	tcp->qual_flg |= QUAL_STACKTRACE;
> +}
> -- 
> 2.1.4
> 
> 
> ------------------------------------------------------------------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> _______________________________________________
> Strace-devel mailing list
> Strace-devel at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/strace-devel




More information about the Strace-devel mailing list