[PATCH 1/2] unwind: split the build condition into front-end and back-end

Masatake YAMATO yamato at redhat.com
Sun Apr 8 18:06:15 UTC 2018


* configure.ac [CAN_UNWIND]: New Makefile.am condition. Enable this if
  libunwind is available.
* Makefile.am [CAN_UNWIND] (strace_SOURCES): Add unwind.c and unwind.h.
  [USE_LIBUNWIND] (strace_SOURCES): Add only unwind-libunwind.c.
* defs.h: Refer CAN_UNWIND as a condition instead of USE_LIBUNWIND.
* strace.c: Likewise.
* syscall.c: Likewise.

Signed-off-by: Masatake YAMATO <yamato at redhat.com>
---
 Makefile.am  | 14 +++++++++-----
 configure.ac | 11 +++++++++--
 defs.h       |  6 +++---
 strace.c     | 20 ++++++++++----------
 syscall.c    |  4 ++--
 5 files changed, 33 insertions(+), 22 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index 6985d282..b16c4afd 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -349,11 +349,8 @@ strace_SOURCES =	\
 
 strace_SOURCES_check = bpf_attr_check.c
 
-if USE_LIBUNWIND
-strace_SOURCES += unwind.c unwind.h unwind-libunwind.c
-strace_CPPFLAGS += $(libunwind_CPPFLAGS)
-strace_LDFLAGS += $(libunwind_LDFLAGS)
-strace_LDADD += $(libunwind_LIBS)
+if CAN_UNWIND
+strace_SOURCES += unwind.c unwind.h
 if USE_DEMANGLE
 strace_CPPFLAGS += $(libiberty_CPPFLAGS)
 strace_LDFLAGS += $(libiberty_LDFLAGS)
@@ -361,6 +358,13 @@ strace_LDADD += $(libiberty_LIBS)
 endif
 endif
 
+if USE_LIBUNWIND
+strace_SOURCES += unwind-libunwind.c
+strace_CPPFLAGS += $(libunwind_CPPFLAGS)
+strace_LDFLAGS += $(libunwind_LDFLAGS)
+strace_LDADD += $(libunwind_LIBS)
+endif
+
 @CODE_COVERAGE_RULES@
 CODE_COVERAGE_BRANCH_COVERAGE = 1
 CODE_COVERAGE_GENHTML_OPTIONS = $(CODE_COVERAGE_GENHTML_OPTIONS_DEFAULT) \
diff --git a/configure.ac b/configure.ac
index 6e53f982..fa1c2360 100644
--- a/configure.ac
+++ b/configure.ac
@@ -925,7 +925,7 @@ AS_IF([test "x$with_libunwind" != xno],
 dnl enable libunwind
 AC_MSG_CHECKING([whether to enable stack tracing support using libunwind])
 if test "x$use_libunwind" = xyes; then
-	AC_DEFINE([USE_LIBUNWIND], 1, [Compile stack tracing functionality])
+	AC_DEFINE([USE_LIBUNWIND], 1, [Compile stack tracing functionality with libunwind])
 	AC_SUBST(libunwind_LIBS)
 	AC_SUBST(libunwind_LDFLAGS)
 	AC_SUBST(libunwind_CPPFLAGS)
@@ -933,6 +933,13 @@ fi
 AM_CONDITIONAL([USE_LIBUNWIND], [test "x$use_libunwind" = xyes])
 AC_MSG_RESULT([$use_libunwind])
 
+can_unwind=no
+if test "x$use_libunwind" = xyes; then
+	can_unwind=yes
+	AC_DEFINE([CAN_UNWIND], 1, [Compile stack tracing functionality])
+fi
+AM_CONDITIONAL([CAN_UNWIND], [test "x$can_unwind" = xyes])
+
 dnl demangling symbols in the stack trace
 libiberty_CPPFLAGS=
 libiberty_LDFLAGS=
@@ -950,7 +957,7 @@ AC_ARG_WITH([libiberty],
 )
 
 use_libiberty=no
-AS_IF([test "x$use_libunwind" = xyes && test "x$with_libiberty" != xno],
+AS_IF([test "x$can_unwind" = xyes && test "x$with_libiberty" != xno],
       [saved_CPPFLAGS="$CPPFLAGS"
        CPPFLAGS="$CPPFLAGS $libiberty_CPPFLAGS"
        AC_CHECK_HEADERS([demangle.h libiberty/demangle.h],
diff --git a/defs.h b/defs.h
index 62aa11c9..21069741 100644
--- a/defs.h
+++ b/defs.h
@@ -222,7 +222,7 @@ struct tcb {
 	unsigned int mmap_cache_size;
 	unsigned int mmap_cache_generation;
 
-#ifdef USE_LIBUNWIND
+#ifdef CAN_UNWIND
 	void *unwind_ctx;
 	struct unwind_queue_t *unwind_queue;
 #endif
@@ -377,7 +377,7 @@ extern struct path_set {
 #define tracing_paths (global_path_set.num_selected != 0)
 extern unsigned xflag;
 extern unsigned followfork;
-#ifdef USE_LIBUNWIND
+#ifdef CAN_UNWIND
 /* if this is true do the stack trace for every system call */
 extern bool stack_trace_enabled;
 #endif
@@ -732,7 +732,7 @@ extern void ts_sub(struct timespec *, const struct timespec *, const struct time
 extern void ts_mul(struct timespec *, const struct timespec *, int);
 extern void ts_div(struct timespec *, const struct timespec *, int);
 
-#ifdef USE_LIBUNWIND
+#ifdef CAN_UNWIND
 extern void unwind_init(void);
 extern void unwind_tcb_init(struct tcb *);
 extern void unwind_tcb_fin(struct tcb *);
diff --git a/strace.c b/strace.c
index a76502af..4a691bab 100644
--- a/strace.c
+++ b/strace.c
@@ -65,7 +65,7 @@ extern char **environ;
 extern int optind;
 extern char *optarg;
 
-#ifdef USE_LIBUNWIND
+#ifdef CAN_UNWIND
 /* if this is true do the stack trace for every system call */
 bool stack_trace_enabled;
 #endif
@@ -203,9 +203,9 @@ static void
 print_version(void)
 {
 	static const char features[] =
-#ifdef USE_LIBUNWIND
+#ifdef CAN_UNWIND
 		" stack-unwind"
-#endif /* USE_LIBUNWIND */
+#endif /* CAN_UNWIND */
 #ifdef USE_DEMANGLE
 		" stack-demangle"
 #endif /* USE_DEMANGLE */
@@ -248,7 +248,7 @@ Output format:\n\
   -a column      alignment COLUMN for printing syscall results (default %d)\n\
   -i             print instruction pointer at time of syscall\n\
 "
-#ifdef USE_LIBUNWIND
+#ifdef CAN_UNWIND
 "\
   -k             obtain stack trace between each syscall (experimental)\n\
 "
@@ -753,7 +753,7 @@ alloctcb(int pid)
 			tcp->currpers = current_personality;
 #endif
 
-#ifdef USE_LIBUNWIND
+#ifdef CAN_UNWIND
 			if (stack_trace_enabled)
 				unwind_tcb_init(tcp);
 #endif
@@ -810,7 +810,7 @@ droptcb(struct tcb *tcp)
 
 	free_tcb_priv_data(tcp);
 
-#ifdef USE_LIBUNWIND
+#ifdef CAN_UNWIND
 	if (stack_trace_enabled) {
 		unwind_tcb_fin(tcp);
 	}
@@ -1592,7 +1592,7 @@ init(int argc, char *argv[])
 #endif
 	qualify("signal=all");
 	while ((c = getopt(argc, argv, "+"
-#ifdef USE_LIBUNWIND
+#ifdef CAN_UNWIND
 	    "k"
 #endif
 	    "a:Ab:cCdDe:E:fFhiI:o:O:p:P:qrs:S:tTu:vVwxyz")) != EOF) {
@@ -1653,7 +1653,7 @@ init(int argc, char *argv[])
 			if (opt_intr <= 0)
 				error_opt_arg(c, optarg);
 			break;
-#ifdef USE_LIBUNWIND
+#ifdef CAN_UNWIND
 		case 'k':
 			stack_trace_enabled = true;
 			break;
@@ -1754,7 +1754,7 @@ init(int argc, char *argv[])
 	if (cflag == CFLAG_ONLY_STATS) {
 		if (iflag)
 			error_msg("-%c has no effect with -c", 'i');
-#ifdef USE_LIBUNWIND
+#ifdef CAN_UNWIND
 		if (stack_trace_enabled)
 			error_msg("-%c has no effect with -c", 'k');
 #endif
@@ -1774,7 +1774,7 @@ init(int argc, char *argv[])
 
 	set_sighandler(SIGCHLD, SIG_DFL, &params_for_tracee.child_sa);
 
-#ifdef USE_LIBUNWIND
+#ifdef CAN_UNWIND
 	if (stack_trace_enabled) {
 		unsigned int tcbi;
 
diff --git a/syscall.c b/syscall.c
index 13d81532..53b5ffe6 100644
--- a/syscall.c
+++ b/syscall.c
@@ -705,7 +705,7 @@ syscall_entering_trace(struct tcb *tcp, unsigned int *sig)
 		return 0;
 	}
 
-#ifdef USE_LIBUNWIND
+#ifdef CAN_UNWIND
 	if (stack_trace_enabled) {
 		if (tcp->s_ent->sys_flags & STACKTRACE_CAPTURE_ON_ENTER)
 			unwind_tcb_capture(tcp);
@@ -959,7 +959,7 @@ syscall_exiting_trace(struct tcb *tcp, struct timespec *ts, int res)
 	dumpio(tcp);
 	line_ended();
 
-#ifdef USE_LIBUNWIND
+#ifdef CAN_UNWIND
 	if (stack_trace_enabled)
 		unwind_tcb_print(tcp);
 #endif
-- 
2.14.3



More information about the Strace-devel mailing list