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

Reply via email to