From c3b52551167f71eb2a8a826780b74a0b051865cc Mon Sep 17 00:00:00 2001 From: Nathanne Isip Date: Sat, 21 Dec 2024 10:11:35 +0800 Subject: [PATCH] Hidden segmentation fault catch mechanism implementation on Windows. --- src/N8.cpp | 2 ++ src/n8/core/Runtime.cpp | 9 +++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/N8.cpp b/src/N8.cpp index 377503b..5bcc6e2 100644 --- a/src/N8.cpp +++ b/src/N8.cpp @@ -68,7 +68,9 @@ auto printBanner(N8Util::ArgumentParser argParse) -> void { } auto main(int argc, char** argv) -> int { + #if defined(__linux__) || defined(__APPLE__) Runtime::catchSegfault(); + #endif N8Util::ArgumentParser argParse(argc, argv); argParse.defineParameter("h", "help", "Show this help banner."); diff --git a/src/n8/core/Runtime.cpp b/src/n8/core/Runtime.cpp index 2edf65d..b4463ef 100644 --- a/src/n8/core/Runtime.cpp +++ b/src/n8/core/Runtime.cpp @@ -380,6 +380,7 @@ void Runtime::catchSegfault() { sigaction(SIGSEGV, &sa, NULL); } +#if defined(__linux__) || defined(__APPLE__) void Runtime::segfaultHandler( int signal, siginfo_t *si, @@ -397,14 +398,18 @@ void Runtime::segfaultHandler( std::cout << "\u001b[1;31mSending process ID\u001b[0m:\t" << si->si_pid << "\n"; std::cout << "\u001b[1;31mReal user ID\u001b[0m:\t\t" << si->si_uid << "\n"; std::cout << "\u001b[1;31mExit value\u001b[0m:\t\t\t" << si->si_status << "\n"; + std::cout << "\u001b[1;31mBand event\u001b[0m:\t\t\t" << si->si_band << "\n"; + std::cout << "\u001b[1;31mFaulting address\u001b[0m:\t" << si->si_addr << "\n"; + + #ifndef __APPLE__ std::cout << "\u001b[1;31mTimer overrun\u001b[0m:\t\t" << si->si_overrun << "\n"; std::cout << "\u001b[1;31mTimer ID\u001b[0m:\t\t\t" << si->si_timerid << "\n"; - std::cout << "\u001b[1;31mBand event\u001b[0m:\t\t\t" << si->si_band << "\n"; std::cout << "\u001b[1;31mFile descriptor\u001b[0m:\t" << si->si_fd << "\n"; - std::cout << "\u001b[1;31mFaulting address\u001b[0m:\t" << si->si_addr << "\n"; + #endif std::exit(1); } +#endif #else