MCPcopy Create free account
hub / github.com/Warzone2100/warzone2100 / posixExceptionHandler

Function posixExceptionHandler

lib/exceptionhandler/exceptionhandler.cpp:636–709  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

634static void posixExceptionHandler(int signum, siginfo_t *siginfo, void *sigcontext)
635#else
636static void posixExceptionHandler(int signum)
637#endif
638{
639 static sig_atomic_t allreadyRunning = 0;
640 // XXXXXX will be converted into random characters by mkstemp(3)
641 static const char gdmpFile[] = "warzone2100.gdmp-XXXXXX";
642 char gdmpPath[PATH_MAX] = {'\0'};
643 char dumpFilename[PATH_MAX];
644 int dumpFile;
645 const char *signal;
646# if defined(__GLIBC__)
647 void *btBuffer[MAX_BACKTRACE] = {nullptr};
648 uint32_t btSize = backtrace(btBuffer, MAX_BACKTRACE);
649# endif
650
651 if (allreadyRunning)
652 {
653 raise(signum);
654 }
655 allreadyRunning = 1;
656 // we use our write directory (which is the only directory that wz should have access to)
657 // and stuff it into our logs directory (same as on windows)
658 ssprintf(gdmpPath, "%slogs/%s", WritePath, gdmpFile);
659 sstrcpy(dumpFilename, gdmpPath);
660
661 dumpFile = mkstemp(dumpFilename);
662
663 if (dumpFile == -1)
664 {
665 printf("Failed to create dump file '%s'", dumpFilename);
666 return;
667 }
668
669 // Dump a generic info header
670 dbgDumpHeader(dumpFile);
671
672#ifdef SA_SIGINFO
673 writeAll(dumpFile, "Dump caused by signal: ");
674
675 signal = wz_strsignal(siginfo->si_signo, siginfo->si_code);
676 writeAll(dumpFile, signal);
677 writeAll(dumpFile, "\n\n");
678#endif
679
680 dbgDumpLog(dumpFile); // dump out the last several log calls
681
682# if defined(__GLIBC__)
683 // Dump raw backtrace in case GDB is not available or fails
684 writeAll(dumpFile, "GLIBC raw backtrace:\n");
685 backtrace_symbols_fd(btBuffer, btSize, dumpFile);
686 writeAll(dumpFile, "\n");
687# else
688 writeAll(dumpFile, "GLIBC not available, no raw backtrace dumped\n\n");
689# endif
690
691
692 // Make sure everything is written before letting GDB write to it
693 fsync(dumpFile);

Callers

nothing calls this directly

Calls 7

sstrcpyFunction · 0.85
dbgDumpHeaderFunction · 0.85
writeAllFunction · 0.85
wz_strsignalFunction · 0.85
dbgDumpLogFunction · 0.85
gdbExtendedBacktraceFunction · 0.85
sigactionClass · 0.70

Tested by

no test coverage detected