Open MPI logo

Open MPI Development Mailing List Archives

  |   Home   |   Support   |   FAQ   |   all Development mailing list

From: Brooks Davis (brooks_at_[hidden])
Date: 2005-10-12 15:20:57


On Wed, Oct 12, 2005 at 11:07:51AM -0700, Brooks Davis wrote:
> On Wed, Oct 12, 2005 at 08:58:30AM -0400, Jeff Squyres wrote:
> > On Oct 12, 2005, at 12:54 AM, Brooks Davis wrote:
> >
> > >> Can you elaborate on why you needed that? If there's a problem with
> > >> the stacktrace stuff on BSD, I'd like to make it either disable by
> > >> default or fix whatever is required to work properly on BSD.
> > >
> > > There were a bunch of undefined symbols that I didn't track down.
> > > Hopefully there's just a missing header file. I need to dig into it
> > > more. I just disabled it because I was hoping that would be the only
> > > issue. It wasn't but, I had stop working before I could try again
> > > with stack traces enabled.
> >
> > Ok. Right now, that section is only protected with #ifdef __GLIBC__,
> > so let us know what you find. The sooner, the better. :-)
>
> After some investigation I've discovered there are two parts to this.
>
> First, the failure to compile is due to FreeBSD not defining a large
> portion of the si_code values in the decoding table. Overall the state
> of documentation of the FreeBSD si_code values is rather crappy so I've
> added #ifdef's around the ones that fail, but not attempted to add more
> values except SI_UNDEFINED. I've attached this bit (with this the
> system compiles with ./configure).
>
> Second, is actually supporting backtraces. It turns out there's a
> library to provide the glibc backtrace* API on BSD systems. I don't
> know which ones it works on or how good it is, but it's probably worth a
> short. The big change will be switching from __GLIBC__ to probing for
> libexecinfo, and the necessicary symbols. I'm taking a look at this
> now.

No testing yet, but I've modified configure.am and
opal/util/stacktrace.c to work by probing for backtrace() and
libexecinfo. The configure code is cribbed from the sched_yeild and -lrt
code for Solaris. The diff below includes that, some changes to
detect libutil.h and it include as needed and the added ifdef from my
last message in stacktrace.c.

Now to see if it runs. :)

-- Brooks

Index: opal/util/stacktrace.c
===================================================================
--- opal/util/stacktrace.c (revision 7735)
+++ opal/util/stacktrace.c (working copy)
@@ -46,6 +46,8 @@
  * to a user-specified signal (e.g. SIGFPE or SIGSEGV).
  * For Linux/Glibc, it then uses backtrace and backtrace_symbols
  * to figure the current stack and then prints that out to stdout.
+ * Where available, the BSD libexecinfo is used to provide Linux/Glibc
+ * compatable backtrace and backtrace_symbols functions.
  * Yes, printf and malloc are not signal-safe per se, but should be
  * on Linux?
  *
@@ -58,7 +60,7 @@
 #if OMPI_WANT_PRETTY_PRINT_STACKTRACE && ! defined(WIN32)
 static void opal_show_stackframe (int signo, siginfo_t * info, void * p)
 {
-#ifdef __GLIBC__
+#if HAVE_BACKTRACE
     int i;
     int trace_size;
     void * trace[32];
@@ -87,15 +89,21 @@
       case SIGILL:
         switch (info->si_code)
           {
+#ifdef ILL_ILLOPC
             case ILL_ILLOPC: str = "ILL_ILLOPC"; break;
+#endif
 #ifdef ILL_ILLOPN
             case ILL_ILLOPN: str = "ILL_ILLOPN"; break;
 #endif
 #ifdef ILL_ILLADR
             case ILL_ILLADR: str = "ILL_ILLADR"; break;
 #endif
+#ifdef ILL_ILLTRP
             case ILL_ILLTRP: str = "ILL_ILLTRP"; break;
+#endif
+#ifdef ILL_PRVOPC
             case ILL_PRVOPC: str = "ILL_PRVOPC"; break;
+#endif
 #ifdef ILL_PRVREG
             case ILL_PRVREG: str = "ILL_PRVREG"; break;
 #endif
@@ -129,14 +137,20 @@
       case SIGSEGV:
         switch (info->si_code)
           {
+#ifdef SEGV_MAPERR
             case SEGV_MAPERR: str = "SEGV_MAPERR"; break;
+#endif
+#ifdef SEGV_ACCERR
             case SEGV_ACCERR: str = "SEGV_ACCERR"; break;
+#endif
           }
         break;
       case SIGBUS:
         switch (info->si_code)
           {
+#ifdef BUS_ADRALN
             case BUS_ADRALN: str = "BUS_ADRALN"; break;
+#endif
 #ifdef BUSADRERR
             case BUS_ADRERR: str = "BUS_ADRERR"; break;
 #endif
@@ -159,12 +173,24 @@
       case SIGCHLD:
         switch (info->si_code)
           {
+#ifdef CLD_EXITED
             case CLD_EXITED: str = "CLD_EXITED"; break;
+#endif
+#ifdef CLD_KILLED
             case CLD_KILLED: str = "CLD_KILLED"; break;
+#endif
+#ifdef CLD_DUMPED
             case CLD_DUMPED: str = "CLD_DUMPED"; break;
+#endif
+#ifdef CLD_WTRAPPED
             case CLD_TRAPPED: str = "CLD_TRAPPED"; break;
+#endif
+#ifdef CLD_STOPPED
             case CLD_STOPPED: str = "CLD_STOPPED"; break;
+#endif
+#ifdef CLD_CONTINUED
             case CLD_CONTINUED: str = "CLD_CONTINUED"; break;
+#endif
           }
         break;
 #ifdef SIGPOLL
@@ -197,6 +223,9 @@
 #ifdef SI_KERNEL
             case SI_KERNEL: str = "SI_KERNEL"; break;
 #endif
+#ifdef SI_UNDEFINED
+ case SI_UNDEFINED: str = "SI_UNDEFINED"; break;
+#endif
           }
     }
 
@@ -245,7 +274,7 @@
     write(1, print_buffer, size);
     fflush(stderr);
 
-#ifdef __GLIBC__
+#ifdef HAVE_BACKTRACE
     trace_size = backtrace (trace, 32);
     messages = backtrace_symbols (trace, trace_size);
 
Index: configure.ac
===================================================================
--- configure.ac (revision 7735)
+++ configure.ac (working copy)
@@ -1043,7 +1043,7 @@
 ompi_show_title "Header file tests"
 
 AC_CHECK_HEADERS([alloca.h aio.h arpa/inet.h dirent.h \
- dlfcn.h execinfo.h err.h fcntl.h inttypes.h libgen.h \
+ dlfcn.h execinfo.h err.h fcntl.h inttypes.h libgen.h libutil.h \
     net/if.h netdb.h netinet/in.h netinet/tcp.h \
     poll.h pthread.h pty.h pwd.h sched.h stdint.h \
     string.h strings.h stropts.h sys/fcntl.h sys/ipc.h \
@@ -1202,6 +1202,35 @@
 AC_CHECK_FUNCS([sched_yield])
 
 #
+# FreeBSD has backtrace in -lexecinfo. Can't use a simple AC_CHECK_LIB,
+# though, because Linux has backtrace in glic (so linking in libexecinfo
+# will "find" backtrace, even though it would have been found anyway
+# -- so -lexecinfo would be useless [and potentially harmful?] in this
+# case).
+#
+
+AC_MSG_CHECKING([if we need -lexecinfo for backtrace])
+AC_LINK_IFELSE(AC_LANG_PROGRAM([[extern char *backtrace;]],
+[[char *bar = backtrace;]]),
+[MSG=no],[MSG=not_found])
+if test "$MSG" = "not_found"; then
+ LIBS_save="$LIBS"
+ LIBS="$LIBS -lexecinfo"
+ AC_LINK_IFELSE(AC_LANG_PROGRAM([[extern char *backtrace;]],
+[[char *bar = backtrace;]]),
+[MSG=yes],[MSG=not_found])
+ if test "$MSG" = "not_found"; then
+ LIBS="$LIBS_save"
+ fi
+fi
+AC_MSG_RESULT([$MSG])
+
+# see if we actually have backtrace. Use AC_CHECK_FUNCS so that it
+# does the glibs "not implemented" check. Will use the current LIBS,
+# so will check in -lexecinfo if we decided we needed it above
+AC_CHECK_FUNCS([backtrace])
+
+#
 # See if we need the math library explicitly linked in
 #
 
Index: orte/mca/iof/base/iof_base_setup.c
===================================================================
--- orte/mca/iof/base/iof_base_setup.c (revision 7735)
+++ orte/mca/iof/base/iof_base_setup.c (working copy)
@@ -47,6 +47,9 @@
 # include <termio.h>
 # endif
 #endif
+#ifdef HAVE_LIBUTIL_H
+#include <libutil.h>
+#endif
 
 #include "mca/iof/base/iof_base_setup.h"
 

-- 
Any statement of the form "X is the one, true Y" is FALSE.
PGP fingerprint 655D 519C 26A7 82E7 2529  9BF0 5D8E 8BE9 F238 1AD4


  • application/pgp-signature attachment: stored