From ed195d35fc53499ceb1c23ada69659c7a23bccdc Mon Sep 17 00:00:00 2001 From: caremoli Date: Tue, 26 Jun 2007 09:29:29 +0000 Subject: [PATCH] CCAR: add possibility to automatically launch a debugger attached to the container on SIGSEGV and not trapped exceptions. Only if DEBUGGER env variable is set to a shell to execute --- src/Container/Makefile.am | 3 ++ src/Container/SALOME_Container.cxx | 56 ++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) diff --git a/src/Container/Makefile.am b/src/Container/Makefile.am index 4e7c0d619..d4b30879b 100644 --- a/src/Container/Makefile.am +++ b/src/Container/Makefile.am @@ -139,6 +139,9 @@ SALOME_Container_LDADD =\ $(COMMON_LIBS) \ ../Basics/libSALOMEBasics.la +SALOME_Container_LDFLAGS =\ +-Xlinker -export-dynamic + SALOME_ContainerManagerServer_SOURCES =\ SALOME_ContainerManagerServer.cxx diff --git a/src/Container/SALOME_Container.cxx b/src/Container/SALOME_Container.cxx index ab3e599a7..9a8cf992b 100644 --- a/src/Container/SALOME_Container.cxx +++ b/src/Container/SALOME_Container.cxx @@ -62,12 +62,68 @@ using namespace std; extern "C" void HandleServerSideSignals(CORBA::ORB_ptr theORB); +#include +#include +#include +#include + +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_Container " << 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[]) { #ifdef HAVE_MPI2 MPI_Init(&argc,&argv); #endif + if(getenv ("DEBUGGER")) + { + setsig(SIGSEGV,&Handler); + set_terminate(&terminateHandler); + set_unexpected(&unexpectedHandler); + } + // Initialise the ORB. //SRN: BugID: IPAL9541, it's necessary to set a size of one message to be at least 100Mb //CORBA::ORB_var orb = CORBA::ORB_init( argc , argv ) ; -- 2.39.2