[PATCH 3/9] unwind: introduce an ifdef condition, CAN_UNWIND as the super-set of USE_LIBUNWIND
Masatake YAMATO
yamato at redhat.com
Tue Mar 13 17:28:08 UTC 2018
Using libdw as an alternative unwinder is planed. strace will can
print stack trace without libunwind. In such plan, USE_LIBUNWIND is not
suitable to represent whether unwinder related code is compiled or
not.
CAN_UNWIND is common definition in either case: linking with libunwind
or linking with libdw.
Temporary, USE_LIBUNWIND is not used anywhere in the build system.
It will reintroduce when libdw is utilized in strace.
* configure: Introduce can_unwind local variable.
yes is set to the variable when any unwinder implementation
is available. Currently, only libuwind is usable implementation.
(CAN_UNWIND): New definition and automake condition. Currently
configure defines it is libunwind is available.
(USE_LIBUNWIND): update its comment.
* Makefile.am: Use CAN_UNWIND condition.
* defs.h: Use CAN_UNWIND definition.
* strace.c: Ditto.
* syscall.c: Ditto.
Signed-off-by: Masatake YAMATO <yamato at redhat.com>
---
Makefile.am | 2 +-
configure.ac | 12 +++++++++++-
defs.h | 6 +++---
strace.c | 20 ++++++++++----------
syscall.c | 4 ++--
5 files changed, 27 insertions(+), 17 deletions(-)
diff --git a/Makefile.am b/Makefile.am
index 181a0f8e..00c7b4bc 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -338,7 +338,7 @@ strace_SOURCES = \
xstring.h \
# end of strace_SOURCES
-if USE_LIBUNWIND
+if CAN_UNWIND
strace_SOURCES += unwind.c
strace_CPPFLAGS += $(libunwind_CPPFLAGS)
strace_LDFLAGS += $(libunwind_LDFLAGS)
diff --git a/configure.ac b/configure.ac
index b4c1990f..a1f15444 100644
--- a/configure.ac
+++ b/configure.ac
@@ -813,6 +813,9 @@ AC_PATH_PROG([PERL], [perl])
AC_CHECK_TOOL([READELF], [readelf])
+dnl stack trace
+can_unwind=no
+
dnl stack trace with libunwind
libunwind_CPPFLAGS=
libunwind_LDFLAGS=
@@ -894,14 +897,21 @@ 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, [Use libunwind for stack tracing])
AC_SUBST(libunwind_LIBS)
AC_SUBST(libunwind_LDFLAGS)
AC_SUBST(libunwind_CPPFLAGS)
+ can_unwind=yes
fi
AM_CONDITIONAL([USE_LIBUNWIND], [test "x$use_libunwind" = xyes])
AC_MSG_RESULT([$use_libunwind])
+dnl enable stack trace
+if test "x$can_unwind" = xyes; then
+ 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=
diff --git a/defs.h b/defs.h
index f8867157..b456791e 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
@@ -731,7 +731,7 @@ extern void tv_sub(struct timeval *, const struct timeval *, const struct timeva
extern void tv_mul(struct timeval *, const struct timeval *, int);
extern void tv_div(struct timeval *, const struct timeval *, 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 eac5ab8f..34e2ede7 100644
--- a/strace.c
+++ b/strace.c
@@ -63,7 +63,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\
"
@@ -741,7 +741,7 @@ alloctcb(int pid)
tcp->currpers = current_personality;
#endif
-#ifdef USE_LIBUNWIND
+#ifdef CAN_UNWIND
if (stack_trace_enabled)
unwind_tcb_init(tcp);
#endif
@@ -798,7 +798,7 @@ droptcb(struct tcb *tcp)
free_tcb_priv_data(tcp);
-#ifdef USE_LIBUNWIND
+#ifdef CAN_UNWIND
if (stack_trace_enabled) {
unwind_tcb_fin(tcp);
}
@@ -1605,7 +1605,7 @@ init(int argc, char *argv[])
#endif
qualify("signal=all");
while ((c = getopt(argc, argv, "+"
-#ifdef USE_LIBUNWIND
+#ifdef CAN_UNWIND
"k"
#endif
"a:b:cCdDe:E:fFhiI:o:O:p:P:qrs:S:tTu:vVwxyz")) != EOF) {
@@ -1663,7 +1663,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;
@@ -1764,7 +1764,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
@@ -1793,7 +1793,7 @@ init(int argc, char *argv[])
set_sighandler(SIGCHLD, SIG_DFL, ¶ms_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 24263b69..c72beda9 100644
--- a/syscall.c
+++ b/syscall.c
@@ -690,7 +690,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_capture_stacktrace(tcp);
@@ -950,7 +950,7 @@ syscall_exiting_trace(struct tcb *tcp, struct timeval tv, int res)
dumpio(tcp);
line_ended();
-#ifdef USE_LIBUNWIND
+#ifdef CAN_UNWIND
if (stack_trace_enabled)
unwind_print_stacktrace(tcp);
#endif
--
2.14.3
More information about the Strace-devel
mailing list