Further Windows fixes.
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
16b083d927
commit
5eb95805f6
|
@ -5,5 +5,5 @@ std::string ExceptionHandler::_ArbutilsLastException = "";
|
||||||
export const char* Arbutils_C_GetLastException() { return ExceptionHandler::GetLastException(); }
|
export const char* Arbutils_C_GetLastException() { return ExceptionHandler::GetLastException(); }
|
||||||
|
|
||||||
static ArbUt::SignalHandling sh;
|
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); }
|
export void Arbutils_C_RaiseSignal() { raise(SIGSEGV); }
|
||||||
|
|
|
@ -310,14 +310,16 @@
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
|
||||||
#include <BaseTsd.h>
|
#include <basetsd.h>
|
||||||
typedef SSIZE_T ssize_t;
|
typedef SSIZE_T ssize_t;
|
||||||
|
|
||||||
|
#ifndef NOMINMAX
|
||||||
#define NOMINMAX
|
#define NOMINMAX
|
||||||
#include <Windows.h>
|
#endif
|
||||||
|
#include <windows.h>
|
||||||
#include <winnt.h>
|
#include <winnt.h>
|
||||||
|
|
||||||
#include <Psapi.h>
|
#include <psapi.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
|
||||||
#ifndef __clang__
|
#ifndef __clang__
|
||||||
|
@ -325,9 +327,6 @@ typedef SSIZE_T ssize_t;
|
||||||
#define NOINLINE __declspec(noinline)
|
#define NOINLINE __declspec(noinline)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#pragma comment(lib, "psapi.lib")
|
|
||||||
#pragma comment(lib, "dbghelp.lib")
|
|
||||||
|
|
||||||
// Comment / packing is from stackoverflow:
|
// Comment / packing is from stackoverflow:
|
||||||
// https://stackoverflow.com/questions/6205981/windows-c-stack-trace-from-a-running-app/28276227#28276227
|
// 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
|
// Some versions of imagehlp.dll lack the proper packing directives themselves
|
||||||
|
@ -4016,8 +4015,8 @@ public:
|
||||||
signal(SIGABRT, signal_handler);
|
signal(SIGABRT, signal_handler);
|
||||||
_set_abort_behavior(0, _WRITE_ABORT_MSG | _CALL_REPORTFAULT);
|
_set_abort_behavior(0, _WRITE_ABORT_MSG | _CALL_REPORTFAULT);
|
||||||
|
|
||||||
set_terminate(&terminator);
|
std::set_terminate(&terminator);
|
||||||
set_unexpected(&terminator);
|
std::set_unexpected(&terminator);
|
||||||
_set_purecall_handler(&terminator);
|
_set_purecall_handler(&terminator);
|
||||||
_set_invalid_parameter_handler(&invalid_parameter_handler);
|
_set_invalid_parameter_handler(&invalid_parameter_handler);
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,7 @@ namespace ArbUt {
|
||||||
|
|
||||||
inline reference At(size_t index) {
|
inline reference At(size_t index) {
|
||||||
#ifndef NO_ASSERT
|
#ifndef NO_ASSERT
|
||||||
if (index >= _vector.size() || index < 0) {
|
if (index >= _vector.size()) {
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
ss << "Index " << index << " is out of bounds.";
|
ss << "Index " << index << " is out of bounds.";
|
||||||
throw ArbUt::Exception(ss.str());
|
throw ArbUt::Exception(ss.str());
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
#define BACKWARD_HAS_DW 1
|
#define BACKWARD_HAS_DW 1
|
||||||
#endif
|
#endif
|
||||||
#include "../extern/backward.hpp"
|
#include "../extern/backward.hpp"
|
||||||
|
|
||||||
#include "Exception.hpp"
|
#include "Exception.hpp"
|
||||||
|
|
||||||
// Sourced from https://github.com/bombela/backward-cpp/blob/master/backward.hpp#L3849
|
// Sourced from https://github.com/bombela/backward-cpp/blob/master/backward.hpp#L3849
|
||||||
|
@ -126,6 +125,8 @@ namespace ArbUt {
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SetCallback(void (*callback)(const char*)) { _callback = callback; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
backward::details::handle<char*> _stack_content;
|
backward::details::handle<char*> _stack_content;
|
||||||
bool _loaded;
|
bool _loaded;
|
||||||
|
@ -153,7 +154,7 @@ namespace ArbUt {
|
||||||
|
|
||||||
class SignalHandling {
|
class SignalHandling {
|
||||||
public:
|
public:
|
||||||
SignalHandling(const std::vector<int>& = std::vector<int>())
|
SignalHandling(void(callback)(const char*) = nullptr, const std::vector<int>& = std::vector<int>())
|
||||||
: reporter_thread_([]() {
|
: reporter_thread_([]() {
|
||||||
/* We handle crashes in a utility thread:
|
/* We handle crashes in a utility thread:
|
||||||
backward structures and some Windows functions called here
|
backward structures and some Windows functions called here
|
||||||
|
@ -177,12 +178,13 @@ namespace ArbUt {
|
||||||
cv().notify_one();
|
cv().notify_one();
|
||||||
}) {
|
}) {
|
||||||
SetUnhandledExceptionFilter(crash_handler);
|
SetUnhandledExceptionFilter(crash_handler);
|
||||||
|
_callback = callback;
|
||||||
|
|
||||||
signal(SIGABRT, signal_handler);
|
signal(SIGABRT, signal_handler);
|
||||||
_set_abort_behavior(0, _WRITE_ABORT_MSG | _CALL_REPORTFAULT);
|
_set_abort_behavior(0, _WRITE_ABORT_MSG | _CALL_REPORTFAULT);
|
||||||
|
|
||||||
set_terminate(&terminator);
|
std::set_terminate(&terminator);
|
||||||
set_unexpected(&terminator);
|
std::set_unexpected(&terminator);
|
||||||
_set_purecall_handler(&terminator);
|
_set_purecall_handler(&terminator);
|
||||||
_set_invalid_parameter_handler(&invalid_parameter_handler);
|
_set_invalid_parameter_handler(&invalid_parameter_handler);
|
||||||
}
|
}
|
||||||
|
@ -199,7 +201,11 @@ namespace ArbUt {
|
||||||
reporter_thread_.join();
|
reporter_thread_.join();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SetCallback(void (*callback)(const char*)) { _callback = callback; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
static void (*_callback)(const char*);
|
||||||
|
|
||||||
static CONTEXT* ctx() {
|
static CONTEXT* ctx() {
|
||||||
static CONTEXT data;
|
static CONTEXT data;
|
||||||
return &data;
|
return &data;
|
||||||
|
@ -302,9 +308,9 @@ namespace ArbUt {
|
||||||
// macros.
|
// macros.
|
||||||
// StackTrace also requires that the PDBs are already loaded, which is done
|
// StackTrace also requires that the PDBs are already loaded, which is done
|
||||||
// in the constructor of TraceResolver
|
// 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_machine_type(printer.resolver().machine_type());
|
||||||
st.set_context(ctx());
|
st.set_context(ctx());
|
||||||
st.set_thread_handle(thread_handle());
|
st.set_thread_handle(thread_handle());
|
||||||
|
|
Loading…
Reference in New Issue