diff --git a/CInterface/Core.cpp b/CInterface/Core.cpp index 1d3e233..90fa41d 100644 --- a/CInterface/Core.cpp +++ b/CInterface/Core.cpp @@ -5,5 +5,5 @@ std::string ExceptionHandler::_ArbutilsLastException = ""; export const char* Arbutils_C_GetLastException() { return ExceptionHandler::GetLastException(); } static ArbUt::SignalHandling sh; -export void Arbutils_C_SetSignalCallback(void (*callback)(const char*)) { sh = ArbUt::SignalHandling(callback); } +export void Arbutils_C_SetSignalCallback(void (*callback)(const char*)) { sh.SetCallback(callback); } export void Arbutils_C_RaiseSignal() { raise(SIGSEGV); } diff --git a/extern/backward.hpp b/extern/backward.hpp index 3b7a3fd..c3c37f4 100644 --- a/extern/backward.hpp +++ b/extern/backward.hpp @@ -310,14 +310,16 @@ #include #include -#include +#include typedef SSIZE_T ssize_t; +#ifndef NOMINMAX #define NOMINMAX -#include +#endif +#include #include -#include +#include #include #ifndef __clang__ @@ -325,9 +327,6 @@ typedef SSIZE_T ssize_t; #define NOINLINE __declspec(noinline) #endif -#pragma comment(lib, "psapi.lib") -#pragma comment(lib, "dbghelp.lib") - // Comment / packing is from stackoverflow: // https://stackoverflow.com/questions/6205981/windows-c-stack-trace-from-a-running-app/28276227#28276227 // Some versions of imagehlp.dll lack the proper packing directives themselves @@ -4016,8 +4015,8 @@ public: signal(SIGABRT, signal_handler); _set_abort_behavior(0, _WRITE_ABORT_MSG | _CALL_REPORTFAULT); - set_terminate(&terminator); - set_unexpected(&terminator); + std::set_terminate(&terminator); + std::set_unexpected(&terminator); _set_purecall_handler(&terminator); _set_invalid_parameter_handler(&invalid_parameter_handler); } diff --git a/src/Collections/List.hpp b/src/Collections/List.hpp index 8a5a1b6..d20ee37 100644 --- a/src/Collections/List.hpp +++ b/src/Collections/List.hpp @@ -25,7 +25,7 @@ namespace ArbUt { inline reference At(size_t index) { #ifndef NO_ASSERT - if (index >= _vector.size() || index < 0) { + if (index >= _vector.size()) { std::stringstream ss; ss << "Index " << index << " is out of bounds."; throw ArbUt::Exception(ss.str()); diff --git a/src/SignalHandling.hpp b/src/SignalHandling.hpp index c0b7915..879d3d8 100644 --- a/src/SignalHandling.hpp +++ b/src/SignalHandling.hpp @@ -4,7 +4,6 @@ #define BACKWARD_HAS_DW 1 #endif #include "../extern/backward.hpp" - #include "Exception.hpp" // Sourced from https://github.com/bombela/backward-cpp/blob/master/backward.hpp#L3849 @@ -126,6 +125,8 @@ namespace ArbUt { #endif } + void SetCallback(void (*callback)(const char*)) { _callback = callback; } + private: backward::details::handle _stack_content; bool _loaded; @@ -153,7 +154,7 @@ namespace ArbUt { class SignalHandling { public: - SignalHandling(const std::vector& = std::vector()) + SignalHandling(void(callback)(const char*) = nullptr, const std::vector& = std::vector()) : reporter_thread_([]() { /* We handle crashes in a utility thread: backward structures and some Windows functions called here @@ -177,12 +178,13 @@ namespace ArbUt { cv().notify_one(); }) { SetUnhandledExceptionFilter(crash_handler); + _callback = callback; signal(SIGABRT, signal_handler); _set_abort_behavior(0, _WRITE_ABORT_MSG | _CALL_REPORTFAULT); - set_terminate(&terminator); - set_unexpected(&terminator); + std::set_terminate(&terminator); + std::set_unexpected(&terminator); _set_purecall_handler(&terminator); _set_invalid_parameter_handler(&invalid_parameter_handler); } @@ -199,7 +201,11 @@ namespace ArbUt { reporter_thread_.join(); } + void SetCallback(void (*callback)(const char*)) { _callback = callback; } + private: + static void (*_callback)(const char*); + static CONTEXT* ctx() { static CONTEXT data; return &data; @@ -302,9 +308,9 @@ namespace ArbUt { // macros. // StackTrace also requires that the PDBs are already loaded, which is done // in the constructor of TraceResolver - Printer printer; + backward::Printer printer; - StackTrace st; + backward::StackTrace st; st.set_machine_type(printer.resolver().machine_type()); st.set_context(ctx()); st.set_thread_handle(thread_handle());