diff --git a/Makefile.am b/Makefile.am index 483f126..fd65b12 100644 --- a/Makefile.am +++ b/Makefile.am @@ -24,13 +24,11 @@ AM_CXXFLAGS += -DNO_STRASSEN -DFORTRAN_ AM_CXXFLAGS += $(CBLASOPT) $(CLAPACKOPT) AM_CXXFLAGS += $(MKLOPT) -AM_CXXFLAGS += $(TRACEBACKOPT) #AM_LDFLAGS += .libs/libla.a AM_LDFLAGS += $(CBLASLIB) AM_LDFLAGS += $(BLASLIB) AM_LDFLAGS += $(ATLASLIB) AM_LDFLAGS += $(MKLLIB) AM_LDFLAGS += $(CUDALIBS) -AM_LDFLAGS += $(TRACEBACKLIB) include $(top_srcdir)/aminclude.am diff --git a/configure.ac b/configure.ac index 9905807..368ce00 100644 --- a/configure.ac +++ b/configure.ac @@ -105,12 +105,6 @@ AC_SUBST([NVCCFLAGS]) AC_SUBST([MATPTROPT]) -#the check for traceback needs bfd to be linked into -AC_CHECK_LIB([bfd], [bfd_fprintf_vma]) -AC_CHECK_LIB([traceback], [sigtraceback], [TRACEBACKLIB="-ltraceback -lbfd" TRACEBACKOPT="-DUSE_TRACEBACK -fno-omit-frame-pointer"]) -AC_SUBST([TRACEBACKOPT]) -AC_SUBST([TRACEBACKLIB]) - #process options FORINTOPT="" AC_ARG_ENABLE([fotran64int],[ --enable-fotran64int to link with 64-bit-integer-BLAS+LAPACK ], diff --git a/la.h b/la.h index 512f009..0201ed4 100644 --- a/la.h +++ b/la.h @@ -20,9 +20,6 @@ //this should be the single include file for the end user // -#ifdef USE_TRACEBACK -#include "traceback.h" -#endif #include "la_traits.h" #include "laerror.h" #include "auxstorage.h" diff --git a/laerror.cc b/laerror.cc index 5e015de..7a0a9d5 100644 --- a/laerror.cc +++ b/laerror.cc @@ -24,12 +24,17 @@ #include #include #include +#include +#include +#include +#include +#include +#include +#include + #include "cuda_la.h" -#ifdef USE_TRACEBACK -#include "traceback.h" -#endif namespace LA { @@ -42,8 +47,60 @@ bool _LA_count_check=true; extern "C" void _findme(void) {}; //for autoconf test we need a function with C linkage +//traceback routines +extern "C" { + + +//simple traceback by calling gdb on ourselves +int traceback(int flags) +{ + char pid_buf[256]; + sprintf(pid_buf, "%d", getpid()); + char name_buf[512]; + name_buf[readlink("/proc/self/exe", name_buf, 511)]=0; + prctl(PR_SET_PTRACER, PR_SET_PTRACER_ANY, 0, 0, 0); + int child_pid = fork(); + if (!child_pid) { + dup2(2,1); // redirect output to stderr - edit: unnecessary? + execl("/usr/bin/gdb", "gdb", "--batch", "-n", "-ex", "thread", "-ex", "bt", name_buf, pid_buf, NULL); + abort(); /* If gdb failed to start */ + } else { + waitpid(child_pid,NULL,0); + } +return 0; +} + +static int tracebackflags; +static int washere=0; + +void tracebackhandler(int i, siginfo_t *info, void *x) +{ +fflush(stdout); + +traceback(tracebackflags); + +if(!washere) {washere=1; raise(i);} /*generate core*/ +else _exit(1); /*prevent endless loop if something goes very wrong*/ +} + +void sigtraceback(int sig,int flags) +{ +struct sigaction action; +action.sa_sigaction=tracebackhandler; +action.sa_flags=SA_ONESHOT|SA_SIGINFO; +memset(&action.sa_mask,0,sizeof(sigset_t)); +tracebackflags=flags; +if(sigaction(sig,&action,NULL)) perror("cannot install signal handler"); +} + + + +}//extern C + void laerror2(const char *s1, const char *s2) { + std::cout.flush(); + std::cerr.flush(); std::cerr << "LA:ERROR - "; std::cout << "LA:ERROR - "; if(s1) diff --git a/laerror.h b/laerror.h index 6592802..632590e 100644 --- a/laerror.h +++ b/laerror.h @@ -19,8 +19,15 @@ #define _LAERROR_H_ #include +#include + namespace LA { +extern "C" { +extern int traceback(int flags); +extern void sigtraceback(int sig,int flags); +} + //exception class for laerror class LAerror { diff --git a/t.cc b/t.cc index f142500..95d5560 100644 --- a/t.cc +++ b/t.cc @@ -123,12 +123,10 @@ cout < x(1.,10); diff --git a/t2.cc b/t2.cc index e845056..8f88333 100644 --- a/t2.cc +++ b/t2.cc @@ -24,9 +24,6 @@ #include "fourindex.h" #include "bitvector.h" -#ifdef USE_TRACEBACK -#include "traceback.h" -#endif using namespace LA;