Further Windows fixes.
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Deukhoofd 2020-08-18 19:15:00 +02:00
parent 16b083d927
commit 5eb95805f6
Signed by: Deukhoofd
GPG Key ID: F63E044490819F6F
4 changed files with 21 additions and 16 deletions

View File

@ -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); }

15
extern/backward.hpp vendored
View File

@ -310,14 +310,16 @@
#include <mutex>
#include <thread>
#include <BaseTsd.h>
#include <basetsd.h>
typedef SSIZE_T ssize_t;
#ifndef NOMINMAX
#define NOMINMAX
#include <Windows.h>
#endif
#include <windows.h>
#include <winnt.h>
#include <Psapi.h>
#include <psapi.h>
#include <signal.h>
#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);
}

View File

@ -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());

View File

@ -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<char*> _stack_content;
bool _loaded;
@ -153,7 +154,7 @@ namespace ArbUt {
class SignalHandling {
public:
SignalHandling(const std::vector<int>& = std::vector<int>())
SignalHandling(void(callback)(const char*) = nullptr, const std::vector<int>& = std::vector<int>())
: 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());