[mpich-commits] [mpich] MPICH primary repository branch, master, updated. v3.2-12-g4e19514
Service Account
noreply at mpich.org
Tue Dec 8 09:23:34 CST 2015
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "MPICH primary repository".
The branch, master has been updated
via 4e195146c8fd4d2130edba140798ebbc2fdf69c2 (commit)
from 244d3fcdd5aa28bac8f7b1a6b8bbd7cca9d3f619 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
http://git.mpich.org/mpich.git/commitdiff/4e195146c8fd4d2130edba140798ebbc2fdf69c2
commit 4e195146c8fd4d2130edba140798ebbc2fdf69c2
Author: Rob Latham <robl at mcs.anl.gov>
Date: Fri Sep 25 10:53:36 2015 -0500
a portable version of backtrace
There are several approaches available for backtracing. As a starting
point, provide an MPL backtrace routine that looks for and uses one of
several approaches. In this first stab, the order will be
- libbacktrace
- libunwind
- glibc-like backtrace (available in glibc, freebsd, and solaris)
- the "i can't do anything" handler
Signed-off-by: Sangmin Seo <sseo at anl.gov>
diff --git a/src/mpl/Makefile.am b/src/mpl/Makefile.am
index d4a8675..34a7221 100644
--- a/src/mpl/Makefile.am
+++ b/src/mpl/Makefile.am
@@ -13,7 +13,8 @@ lib at MPLLIBNAME@_la_SOURCES = \
src/mpltrmem.c \
src/mplenv.c \
src/mplmsg.c \
- src/mplsock.c
+ src/mplsock.c \
+ src/mplutil.c
lib at MPLLIBNAME@_la_LDFLAGS = ${lib at MPLLIBNAME@_so_versionflags}
MPL_TESTS = strsep
@@ -32,7 +33,8 @@ mpl_headers = \
include/mpltrmem.h \
include/mplmsg.h \
include/mpliov.h \
- include/mplsock.h
+ include/mplsock.h \
+ include/mplutil.h
if MPL_EMBEDDED_MODE
noinst_HEADERS = $(mpl_headers)
diff --git a/src/mpl/configure.ac b/src/mpl/configure.ac
index c4e798c..662e528 100644
--- a/src/mpl/configure.ac
+++ b/src/mpl/configure.ac
@@ -71,7 +71,7 @@ if test "$pac_cv_have___typeof" = "yes" ; then
fi
dnl Check if the necessary headers are available
-AC_CHECK_HEADERS(stdio.h stdlib.h string.h stdarg.h ctype.h search.h sys/types.h sys/uio.h)
+AC_CHECK_HEADERS(stdio.h stdlib.h string.h stdarg.h ctype.h search.h sys/types.h sys/uio.h execinfo.h backtrace.h libunwind.h)
# A C99 compliant compiler should have inttypes.h for fixed-size int types
AC_CHECK_HEADERS(inttypes.h stdint.h)
@@ -200,6 +200,10 @@ if test "$ac_cv_func_strerror" = "yes" ; then
PAC_FUNC_NEEDS_DECL([#include <string.h>],strerror)
fi
+AC_CHECK_FUNCS(backtrace_symbols)
+AC_CHECK_LIB(backtrace, backtrace_create_state)
+AC_CHECK_LIB(unwind, unw_backtrace)
+
dnl Check for ATTRIBUTE
PAC_C_GNU_ATTRIBUTE
diff --git a/src/mpl/include/mpl.h b/src/mpl/include/mpl.h
index 4885750..0ceb887 100644
--- a/src/mpl/include/mpl.h
+++ b/src/mpl/include/mpl.h
@@ -114,5 +114,6 @@
#include "mplsock.h"
#include "mplmsg.h"
#include "mpliov.h"
+#include "mplutil.h"
#endif /* MPL_H_INCLUDED */
diff --git a/src/mpl/include/mplutil.h b/src/mpl/include/mplutil.h
new file mode 100644
index 0000000..2937751
--- /dev/null
+++ b/src/mpl/include/mplutil.h
@@ -0,0 +1,25 @@
+/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
+/*
+ * (C) 2015 by Argonne National Laboratory.
+ * See COPYRIGHT in top-level directory.
+ */
+
+
+#ifndef MPLUTIL_H_INCLUDED
+#define MPLUTIL_H_INCLUDED
+
+#include "mplconfig.h"
+#if defined(__cplusplus)
+extern "C" {
+#endif
+
+#define MPL_BACKTRACE_BUFFER_LEN 1024
+#define MPL_MAX_TRACE_DEPTH 32
+void MPL_backtrace_show(FILE *output);
+
+#if defined(__cplusplus)
+
+}
+#endif
+
+#endif
diff --git a/src/mpl/src/mplutil.c b/src/mpl/src/mplutil.c
new file mode 100644
index 0000000..c55dd38
--- /dev/null
+++ b/src/mpl/src/mplutil.c
@@ -0,0 +1,132 @@
+/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
+/*
+ * (C) 2015 by Argonne National Laboratory.
+ * See COPYRIGHT in top-level directory.
+ */
+
+#include "mpl.h"
+#ifdef MPL_HAVE_EXECINFO_H
+#include <execinfo.h>
+#endif
+
+#ifdef MPL_HAVE_BACKTRACE_H
+#include <backtrace.h>
+#endif
+
+#ifdef MPL_HAVE_LIBUNWIND_H
+#define UNW_LOCAL_ONLY
+#include <libunwind.h>
+#endif
+
+
+/* freebsd and linux have slightly different backtrace routines.
+ * solaris uses something totally different: a 'walkcontext' routine
+ * which takes a function pointer. solaris 'walkcontext' is simliar to
+ * libbacktrace, shipped with gcc-4.8 and newer. both share features
+ * with libunwind.
+ *
+ * For the case of "display the call stack to this point" the various
+ * approaches share a common pattern:
+ * - initialize the library
+ * - get the stack
+ * - decode the stack
+ *
+ * but for now we'll simply dispatch to one of several appraoches
+ * depending on what configure found
+ *
+ */
+
+#ifdef MPL_HAVE_BACKTRACE_SYMBOLS
+static inline void backtrace_libc(FILE *output)
+{
+#ifndef MPL_MAX_TRACE_DEPTH
+#define MPL_MAX_TRACE_DEPTH 32
+#endif
+ void *trace[MPL_MAX_TRACE_DEPTH];
+ char **stack_strs;
+ char backtrace_buffer[MPL_BACKTRACE_BUFFER_LEN];
+ int frames, i, ret, chars = 0;
+
+ frames = backtrace(trace, MPL_MAX_TRACE_DEPTH);
+ stack_strs = backtrace_symbols(trace, frames);
+
+ for (i = 0; i < frames; i++) {
+ ret = MPL_snprintf(backtrace_buffer + chars,
+ MPL_BACKTRACE_BUFFER_LEN - chars,
+ "%s\n", stack_strs[i]);
+ if (ret + chars >= MPL_BACKTRACE_BUFFER_LEN) {
+ /* the extra new line will be more readable than a merely
+ * truncated string */
+ backtrace_buffer[MPL_BACKTRACE_BUFFER_LEN - 2] = '\n';
+ backtrace_buffer[MPL_BACKTRACE_BUFFER_LEN - 1] = '\0';
+ break;
+ }
+ chars += ret;
+ }
+ fprintf(output, "%s", backtrace_buffer);
+ free(stack_strs);
+}
+#endif
+
+#ifdef MPL_HAVE_LIBBACKTRACE
+static inline void backtrace_libback(FILE *output)
+{
+ struct backtrace_state *btstate;
+ btstate = backtrace_create_state(NULL, 1, NULL, NULL);
+ backtrace_print(btstate, 0, output);
+}
+#endif
+
+#ifdef MPL_HAVE_LIBUNWIND
+static inline void backtrace_libunwind(FILE *output)
+{
+ unw_cursor_t cursor;
+ unw_context_t uc;
+ unw_word_t ip, offset;
+ int ret, chars = 0;
+ char buffer[MPL_BACKTRACE_BUFFER_LEN];
+ char backtrace_buffer[MPL_BACKTRACE_BUFFER_LEN];
+
+ unw_getcontext(&uc);
+ unw_init_local(&cursor, &uc);
+ while (unw_step(&cursor) > 0) {
+ unw_get_reg(&cursor, UNW_REG_IP, &ip);
+ unw_get_proc_name(&cursor, buffer,
+ MPL_BACKTRACE_BUFFER_LEN, &offset);
+ ret = MPL_snprintf(backtrace_buffer + chars,
+ MPL_BACKTRACE_BUFFER_LEN - chars,
+ "0x%lx %s() + 0x%lx\n",
+ (long)ip, buffer, (long)offset);
+ if (ret + chars >= MPL_BACKTRACE_BUFFER_LEN) {
+ /* the extra new line will be more readable than a merely
+ * truncated string */
+ backtrace_buffer[MPL_BACKTRACE_BUFFER_LEN - 2] = '\n';
+ backtrace_buffer[MPL_BACKTRACE_BUFFER_LEN - 1] = '\0';
+ break;
+ }
+ chars += ret;
+ }
+ fprintf(output, "%s", backtrace_buffer);
+}
+#endif
+
+static inline void backtrace_unsupported(FILE *output)
+{
+ fprintf(output, "No backtrace info available\n");
+}
+
+/* Pick one of the many ways one could dump out a call stack*/
+void MPL_backtrace_show(FILE *output)
+{
+#ifdef MPL_HAVE_LIBBACKTRACE
+ backtrace_libback(output);
+#elif defined MPL_HAVE_LIBUNWIND
+ /* libunwind is not able to get line numbers without forking off to
+ * addr2line (?)*/
+ backtrace_libunwind(output);
+#elif defined MPL_HAVE_BACKTRACE_SYMBOLS
+ backtrace_libc(output);
+#else
+ backtrace_unsupported(output);
+#endif
+}
diff --git a/src/util/other/assert.c b/src/util/other/assert.c
index 5fae177..0439fed 100644
--- a/src/util/other/assert.c
+++ b/src/util/other/assert.c
@@ -27,6 +27,7 @@ int MPIR_Assert_fail(const char *cond, const char *file_name, int line_num)
(MPIU_DBG_FDEST,
"Assertion failed in file %s at line %d: %s",
file_name, line_num, cond));
+ MPL_backtrace_show(stderr);
MPID_Abort(NULL, MPI_SUCCESS, 1, NULL);
return MPI_ERR_INTERN; /* never get here, abort should kill us */
}
-----------------------------------------------------------------------
Summary of changes:
src/mpl/Makefile.am | 6 ++-
src/mpl/configure.ac | 6 ++-
src/mpl/include/mpl.h | 1 +
src/mpl/include/mplutil.h | 25 +++++++++
src/mpl/src/mplutil.c | 132 +++++++++++++++++++++++++++++++++++++++++++++
src/util/other/assert.c | 1 +
6 files changed, 168 insertions(+), 3 deletions(-)
create mode 100644 src/mpl/include/mplutil.h
create mode 100644 src/mpl/src/mplutil.c
hooks/post-receive
--
MPICH primary repository
More information about the commits
mailing list