using namespace std;
-#ifdef DEBUG_PARALLEL
+#ifdef _DEBUG_
#include <signal.h>
+void test(int sigval) {
+ cerr << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << endl;
+ cerr << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << endl;
+ cerr << "SIGSEGV in :" << getpid() << endl;
+ cerr << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << endl;
+ cerr << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << endl;
+ while (1) {}
+}
+
void handler(int t) {
cerr << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << endl;
cerr << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << endl;
}
#endif
+typedef void (*sighandler_t)(int);
+sighandler_t setsig(int sig, sighandler_t handler)
+{
+ struct sigaction context, ocontext;
+ context.sa_handler = handler;
+ sigemptyset(&context.sa_mask);
+ context.sa_flags = 0;
+ if (sigaction(sig, &context, &ocontext) == -1)
+ return SIG_ERR;
+ return ocontext.sa_handler;
+}
+
+void AttachDebugger()
+{
+ if(getenv ("DEBUGGER"))
+ {
+ std::stringstream exec;
+ exec << "$DEBUGGER SALOME_ParallelContainerNodeMpi " << getpid() << "&";
+ std::cerr << exec.str() << std::endl;
+ system(exec.str().c_str());
+ while(1);
+ }
+}
+
+void Handler(int theSigId)
+{
+ std::cerr << "SIGSEGV: " << std::endl;
+ AttachDebugger();
+ //to exit or not to exit
+ exit(1);
+}
+
+void terminateHandler(void)
+{
+ std::cerr << "Terminate: not managed exception !" << std::endl;
+ AttachDebugger();
+}
+
+void unexpectedHandler(void)
+{
+ std::cerr << "Unexpected: unexpected exception !" << std::endl;
+ AttachDebugger();
+}
+
int main(int argc, char* argv[])
{
INFOS("Launching a parallel Mpi container node");
-#ifdef DEBUG_PARALLEL
- signal(SIGSEGV, handler);
+#ifdef _DEBUG_
+// struct sigaction action;
+// action.sa_handler = &test;
+// sigaction(SIGSEGV, &action, NULL);
#endif
// MPI Init
int provided;
MPI_Init_thread(&argc, &argv, MPI_THREAD_MULTIPLE ,&provided);
-#ifdef DEBUG_PARALLEL
+ if(getenv ("DEBUGGER"))
+ {
+ std::cerr << "Unexpected: unexpected exception !" << std::endl;
+ setsig(SIGSEGV,&Handler);
+ set_terminate(&terminateHandler);
+ set_unexpected(&unexpectedHandler);
+ }
+#ifdef _DEBUG_
cerr << "Level MPI_THREAD_SINGLE : " << MPI_THREAD_SINGLE << endl;
cerr << "Level MPI_THREAD_SERIALIZED : " << MPI_THREAD_SERIALIZED << endl;
cerr << "Level MPI_THREAD_FUNNELED : " << MPI_THREAD_FUNNELED << endl;