There is a segfault if strace is called as `strace -p 2260 -k`.
The -k flag sets a global bool stack_trace_enabled. But -p already consults
stack_trace_enabled during tcb initialization. So if -p is passed first,
the libunwind components of the tcb are uninitialized.
The attached patch fixes this issue by having -k ensure that the libunwind
components are initialized.
Best,
Sean Stangl
From 886185a13e5a800c17330f4a4444cf226426dc74 Mon Sep 17 00:00:00 2001
From: Sean Stangl <ssta...@mozilla.com>
Date: Thu, 8 Dec 2016 09:54:24 -1000
Subject: [PATCH] Fix libunwind segfault when -p is passed before -k.
---
strace.c | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/strace.c b/strace.c
index ffb6bae..17173b1 100644
--- a/strace.c
+++ b/strace.c
@@ -748,6 +748,21 @@ alloctcb(int pid)
error_msg_and_die("bug in alloctcb");
}
+#ifdef USE_LIBUNWIND
+static void
+late_unwind_tcb_init()
+{
+ unsigned int i;
+ struct tcb *tcp;
+
+ for (i = 0; i < tcbtabsize; i++) {
+ tcp = tcbtab[i];
+ if (tcp->pid)
+ unwind_tcb_init(tcp);
+ }
+}
+#endif /* USE_LIBUNWIND */
+
void *
get_tcb_priv_data(const struct tcb *tcp)
{
@@ -1702,6 +1717,8 @@ init(int argc, char *argv[])
#ifdef USE_LIBUNWIND
case 'k':
stack_trace_enabled = true;
+ /* Handles the case where -p is passed before -k. */
+ late_unwind_tcb_init();
break;
#endif
case 'E':
--
2.7.4
------------------------------------------------------------------------------
Developer Access Program for Intel Xeon Phi Processors
Access to Intel Xeon Phi processor-based developer platforms.
With one year of Intel Parallel Studio XE.
Training and support from Colfax.
Order your platform today.http://sdm.link/xeonphi
_______________________________________________
Strace-devel mailing list
Strace-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/strace-devel