From: caremoli Date: Tue, 26 Jun 2007 09:29:29 +0000 (+0000) Subject: CCAR: add possibility to automatically launch a debugger attached to the container X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=ed195d35fc53499ceb1c23ada69659c7a23bccdc;p=modules%2Fkernel.git 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 --- 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 ) ;