ParserException(const Exception& ex, int aScriptLine, int aScriptPos, const char* aFile, int aLine) : Exception(aFile, aLine), scriptLine(aScriptLine), scriptPos(aScriptPos) { description = ex.toString(); }
extern "C" void segfaulth(int sig,siginfo_t *siginfo, void *secret) { ///c++ abi: nothing to play with /* ucontext_t *uc=(ucontext_t*)secret; #ifdef __powerpc__ signal.setFaultPosition((void *)uc->uc_mcontext.regs->nip); #else # ifdef __mips__ signal.setFaultPosition((void *)( (int) ( uc->uc_mcontext.pc & (0xffffffff) ) )); # else signal.setFaultPosition((void *)uc->uc_mcontext.gregs[REG_EIP]); # endif #endif */ //cerr << signal.getStackTrace(); //cerr << signal.what(); const char* detail_=fault_detail(sig,siginfo); char detail[1024]; void *faultAddr=NULL; SegfaultBuffer emergencyBuffer; SegfaultBuffer *oldBuffer=NULL; bool stuckCandidate=false; if ( siginfo ) faultAddr=siginfo->si_addr; snprintf(detail,1024,"Signal (%d) : %s [%p]",sig,detail_,faultAddr); fprintf(stderr,"IN RAII SEGFAULT HANDLER, %s\n",detail);fflush(stderr); if(1){ //code à activer si demangle et throw merdouillent après segfault Exception e; std::cerr << e.toString() << "\n"; std::cerr << e.getMessage() << "\n"; e.poorManPrintStackTrace(false); } if ( !segfaultBuffer || sig == SIGUSR2 ) { fprintf(stderr, sig == SIGUSR2 ? "dumping stack\n" : "segfaultBuffer is NULL (not in raii request)!\n");fflush(stderr); oldBuffer=segfaultBuffer; segfaultBuffer=&emergencyBuffer; stuckCandidate=true; } { // segfaultBuffer is not null, in raii request switch (sig) { case SIGILL: segfaultBuffer->exception=new IllegalInstruction(detail); break; case SIGFPE: segfaultBuffer->exception=new FloatingPointException(detail); break; case SIGSEGV: segfaultBuffer->exception=new SegmentationFault(detail); break; case SIGBUS: segfaultBuffer->exception=new BusError(detail); break; case SIGABRT: segfaultBuffer->exception=new Abort(detail); break; case SIGUSR2: segfaultBuffer->exception=new DumpStack(detail); default: segfaultBuffer->exception=new Signal(detail); } if ( !segfaultBuffer->exception ) fprintf(stderr,"UNABLE TO INSTANCIATE EXCEPTION\n"); else { fprintf(stderr,"EXCEPTION INSTANCIATED, STACKTRACE SIZE IS %d\n",segfaultBuffer->exception->depth); fflush(stderr); segfaultBuffer->exception->depth=backtrace(segfaultBuffer->exception->stackTrace,1024); segfaultBuffer->exception->start=2; //int i; /* //0 -> segfaulth //1 -> __restore_rt for ( i=2 ; i < depth ; i++ ) { segfaultBuffer->exception->stackTrace_.push_back(p[i]); } */ } fflush(stderr); segfaultBuffer->signal=sig; if ( stuckCandidate ) { segfaultBuffer=oldBuffer; //last state { static Mutex serialize_output; Lock l(serialize_output); Logger log("raii"); log ("trying to dump stack"); if ( emergencyBuffer.exception ) { log.error(emergencyBuffer.exception->toString()); std::cerr << emergencyBuffer.exception->getMessage() << "\n"; if ( sig == SIGUSR2 ) emergencyBuffer.exception->printStackTrace(); else emergencyBuffer.exception->poorManPrintStackTrace(); } else { log("exception is null"); } } delete emergencyBuffer.exception; if ( sig == SIGUSR2 ) { dumpStackFlag=false; return; } //double fault héhé //apache redémarre pour le coup... //j'ai pas mieux à proposer. Sinon y'a toujours moyen de //passer le thread en stuck avec une contruction du type //do { sleep(5); fprintf(stderr,"bip\n"); } while(true); //disabling handler for current sig signal(sig,SIG_DFL); fprintf(stderr,"Commiting suicide with that weapon %s\n", fault_detail(sig,siginfo));fflush(stderr); raise(sig); } else { fprintf(stderr,"LONGJUMPING\n");fflush(stderr); longjmp(segfaultBuffer->env,sig); } } }