diff options
| author | louist103 <35883445+louist103@users.noreply.github.com> | 2022-11-12 17:59:16 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-11-12 17:59:16 -0500 |
| commit | af2d9aa359ab9eac1f8339e080f67b8990b21b44 (patch) | |
| tree | a107ba18417f14e15136f5b61cb10afd64547530 | |
| parent | dcd98d81cc80a5387f01837c542bb5d15f1e152c (diff) | |
| parent | d79e0fbfab492dc22fa0fa8fecaa2bdba77d6b4f (diff) | |
Merge pull request #267 from louist103/crashHandlerCleanup
Cleanup crash handler.
| -rw-r--r-- | ZAPD/CrashHandler.cpp | 40 | ||||
| -rw-r--r-- | ZAPD/CrashHandler.h | 28 | ||||
| -rw-r--r-- | ZAPD/Main.cpp | 28 |
3 files changed, 43 insertions, 53 deletions
diff --git a/ZAPD/CrashHandler.cpp b/ZAPD/CrashHandler.cpp index 3a45260..b1b4a47 100644 --- a/ZAPD/CrashHandler.cpp +++ b/ZAPD/CrashHandler.cpp @@ -1,6 +1,32 @@ #include "CrashHandler.h" #include "Utils/StringHelper.h" +#if __has_include(<unistd.h>) +#define HAS_POSIX 1 +#else +#define HAS_POSIX 0 +#endif + +#include <array> +#include <cstdio> +#include <cstdlib> +#include <ctime> + +#if HAS_POSIX == 1 +#include <csignal> +#include <cxxabi.h> // for __cxa_demangle +#include <dlfcn.h> // for dladdr +#include <execinfo.h> +#include <unistd.h> +#elif defined(_MSC_VER) +#include <Windows.h> +#include <DbgHelp.h> + +#include <inttypes.h> + +#pragma comment(lib, "Dbghelp.lib") +#endif + // Feel free to add more crash messages. static std::array<const char* const, 14> crashEasterEgg = { @@ -164,5 +190,19 @@ LONG seh_filter(_EXCEPTION_POINTERS* ex) printStack(ex->ContextRecord); return EXCEPTION_EXECUTE_HANDLER; } +#endif +void CrashHandler_Init() +{ +#if HAS_POSIX == 1 + signal(SIGSEGV, ErrorHandler); + signal(SIGABRT, ErrorHandler); +#elif defined(_MSC_VER) + SetUnhandledExceptionFilter(seh_filter); +#else + HANDLE_WARNING(WarningType::Always, + "tried to set error handler, but this ZAPD build lacks support for one", ""); #endif +} + + diff --git a/ZAPD/CrashHandler.h b/ZAPD/CrashHandler.h index 86e4930..102778b 100644 --- a/ZAPD/CrashHandler.h +++ b/ZAPD/CrashHandler.h @@ -1,32 +1,6 @@ #ifndef CRASH_HANDLER_H #define CRASH_HANDLER_H -#if __has_include(<unistd.h>) -#define HAS_POSIX 1 -#else -#define HAS_POSIX 0 -#endif - - -#include <array> -#include <cstdio> -#include <cstdlib> -#include <ctime> -#if HAS_POSIX == 1 -#include <csignal> -#include <cxxabi.h> // for __cxa_demangle -#include <dlfcn.h> // for dladdr -#include <execinfo.h> -#include <unistd.h> -void ErrorHandler(int sig); -#elif defined(_MSC_VER) -#include <Windows.h> -#include <DbgHelp.h> - -#include <inttypes.h> -LONG seh_filter(_EXCEPTION_POINTERS* ex); - -#pragma comment(lib, "Dbghelp.lib") -#endif +void CrashHandler_Init(); #endif diff --git a/ZAPD/Main.cpp b/ZAPD/Main.cpp index a7b9660..2563154 100644 --- a/ZAPD/Main.cpp +++ b/ZAPD/Main.cpp @@ -24,7 +24,7 @@ void BuildAssetBlob(const fs::path& blobFilePath, const fs::path& outPath); extern const char gBuildHash[]; -int Main(int argc, char* argv[]) +int main(int argc, char* argv[]) { // Syntax: ZAPD.out [mode (btex/bovl/e)] (Arbritrary Number of Arguments) @@ -116,14 +116,7 @@ int Main(int argc, char* argv[]) } else if (arg == "-eh") // Enable Error Handler { -#if HAS_POSIX == 1 - signal(SIGSEGV, ErrorHandler); - signal(SIGABRT, ErrorHandler); -#elif !defined(_MSC_VER) - HANDLE_WARNING(WarningType::Always, - "tried to set error handler, but this ZAPD build lacks support for one", - ""); -#endif + CrashHandler_Init(); } else if (arg == "-v") // Verbose { @@ -246,23 +239,6 @@ int Main(int argc, char* argv[]) return 0; } -// Windows doesn't make it easy to get a stack trace from just a signal. So we need to do this messy -// stuff for just windows. -int main(int argc, char* argv[]) -{ -#ifdef _MSC_VER - __try - { - return Main(argc, argv); - } - __except (seh_filter(GetExceptionInformation())) - { - } -#else - return Main(argc, argv); -#endif -} - bool Parse(const fs::path& xmlFilePath, const fs::path& basePath, const fs::path& outPath, ZFileMode fileMode) { |
