]> granicus.if.org Git - strace/commitdiff
unwind: move unwind_tcb_init invocation to after_successful_attach
authorDmitry V. Levin <ldv@altlinux.org>
Thu, 19 Apr 2018 18:03:58 +0000 (18:03 +0000)
committerDmitry V. Levin <ldv@altlinux.org>
Thu, 19 Apr 2018 18:03:58 +0000 (18:03 +0000)
There is no need to call unwind_tcb_init before the tracee is attached.

* strace.c (alloctcb) [ENABLE_STACKTRACE]: Move unwind_tcb_init
invocation ...
(after_successful_attach) [ENABLE_STACKTRACE]: ... here.
(init) [ENABLE_STACKTRACE]: Remove unwind_tcb_init invocation loop.
* unwind.c (unwind_tcb_fin): Skip if tcp->unwind_queue is NULL.

strace.c
unwind.c

index 8143cadb21ddd25836b9dbded8a6c06dfa3541e9..7b79b0c5cb9191f0ac0e2fe3a3558dd5a2f87351 100644 (file)
--- a/strace.c
+++ b/strace.c
@@ -715,6 +715,11 @@ after_successful_attach(struct tcb *tcp, const unsigned int flags)
                xsprintf(name, "%s.%u", outfname, tcp->pid);
                tcp->outf = strace_fopen(name);
        }
+
+#ifdef ENABLE_STACKTRACE
+       if (stack_trace_enabled)
+               unwind_tcb_init(tcp);
+#endif
 }
 
 static void
@@ -756,12 +761,6 @@ alloctcb(int pid)
 #if SUPPORTED_PERSONALITIES > 1
                        tcp->currpers = current_personality;
 #endif
-
-#ifdef ENABLE_STACKTRACE
-                       if (stack_trace_enabled)
-                               unwind_tcb_init(tcp);
-#endif
-
                        nprocs++;
                        debug_msg("new tcb for pid %d, active tcbs:%d",
                                  tcp->pid, nprocs);
@@ -815,9 +814,8 @@ droptcb(struct tcb *tcp)
        free_tcb_priv_data(tcp);
 
 #ifdef ENABLE_STACKTRACE
-       if (stack_trace_enabled) {
+       if (stack_trace_enabled)
                unwind_tcb_fin(tcp);
-       }
 #endif
 
        mmap_cache_delete(tcp, __func__);
@@ -1777,16 +1775,8 @@ init(int argc, char *argv[])
        set_sighandler(SIGCHLD, SIG_DFL, &params_for_tracee.child_sa);
 
 #ifdef ENABLE_STACKTRACE
-       if (stack_trace_enabled) {
-               unsigned int tcbi;
-
+       if (stack_trace_enabled)
                unwind_init();
-               for (tcbi = 0; tcbi < tcbtabsize; ++tcbi) {
-                       if (!tcbtab[tcbi]->pid)
-                               continue;
-                       unwind_tcb_init(tcbtab[tcbi]);
-               }
-       }
 #endif
 
        /* See if they want to run as another user. */
index 41d0740d070f61b478b5975fa9f5d2af065ae7d0..586f74500b8bbae053a39d76bfcc7a9ee6c86a67 100644 (file)
--- a/unwind.c
+++ b/unwind.c
@@ -78,6 +78,9 @@ unwind_tcb_init(struct tcb *tcp)
 void
 unwind_tcb_fin(struct tcb *tcp)
 {
+       if (!tcp->unwind_queue)
+               return;
+
        queue_print(tcp->unwind_queue);
        free(tcp->unwind_queue);
        tcp->unwind_queue = NULL;