On Fri, Aug 11, 2017 at 05:43:53PM +0700, Nikolay Marchuk wrote:
> * 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 | 11 +++++++++++
>  strace.c        |  4 ++--
>  syscall.c       |  6 +++---
>  unwind.c        |  6 ++++++
>  5 files changed, 27 insertions(+), 6 deletions(-)
> 
> diff --git a/defs.h b/defs.h
> index 13893f64..8604651a 100644
> --- a/defs.h
> +++ b/defs.h
> @@ -271,6 +271,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)
>  
> @@ -281,6 +284,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)
>  
> @@ -383,7 +387,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 */
"stack tracing"

>  extern bool stack_trace_enabled;
>  #endif
>  extern unsigned ptrace_setoptions;
> diff --git a/filter_action.c b/filter_action.c
> index 776ffded..2cffe7a2 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 *);
> @@ -81,6 +84,9 @@ static const struct filter_action_type {
>       FILTER_ACTION_TYPE(raw,         2, QUAL_RAW,            null,   
> is_traced),
>       FILTER_ACTION_TYPE(abbrev,      2, QUAL_ABBREV,         null,   
> is_traced),
>       FILTER_ACTION_TYPE(verbose,     2, QUAL_VERBOSE,        null,   
> is_traced),
> +# ifdef USE_LIBUNWIND
> +     FILTER_ACTION_TYPE(stacktrace,  2, QUAL_STACKTRACE,     null,   
> is_traced),
> +# endif
>  };
>  #undef FILTER_ACTION_TYPE
>  
> @@ -163,6 +169,11 @@ add_action(const struct filter_action_type *type)
>       /* Update default_flags */
>       if (default_flags & type->qual_flg)
>               default_flags &= ~type->qual_flg;
> +     /* Enable stack tracing. */
> +#ifdef USE_LIBUNWIND
> +     if (type->qual_flg & QUAL_STACKTRACE)
> +             stack_trace_enabled = true;
> +#endif
>  
>       filter_actions = xreallocarray(filter_actions, ++nfilter_actions,
>                                      sizeof(struct filter_action));
> diff --git a/strace.c b/strace.c
> index 79c5397e..d2011d0c 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 */
"stack tracing"

>  bool stack_trace_enabled;
>  #endif
>  
> @@ -1693,7 +1693,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 b740dadb..ed463f92 100644
> --- a/syscall.c
> +++ b/syscall.c
> @@ -686,7 +686,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);
>       }
> @@ -732,7 +732,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);
>       }
> @@ -952,7 +952,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 919b63c3..caab4143 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.11.0

------------------------------------------------------------------------------
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@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/strace-devel

Reply via email to