2018-08-02 01:29:14 +02:00
|
|
|
#include <cpp-utils/assert/backtrace.h>
|
|
|
|
#include <csignal>
|
|
|
|
#include <stdexcept>
|
|
|
|
|
|
|
|
#if defined(_MSC_VER)
|
|
|
|
#include <Windows.h>
|
|
|
|
#endif
|
|
|
|
|
2019-06-08 22:06:17 +02:00
|
|
|
void handle_exit_signal(char **argv) {
|
2018-08-02 01:29:14 +02:00
|
|
|
const std::string kind = argv[1];
|
|
|
|
if (kind == "exception") {
|
|
|
|
throw std::logic_error(argv[2]);
|
|
|
|
} else if (kind == "nullptr") {
|
|
|
|
int* ptr = nullptr;
|
2018-10-14 22:26:30 +02:00
|
|
|
*ptr = 5; // NOLINT
|
2018-08-02 01:29:14 +02:00
|
|
|
} else if (kind == "signal") {
|
|
|
|
#if defined(_MSC_VER)
|
|
|
|
DWORD code = std::atoll(argv[2]);
|
|
|
|
::RaiseException(code, EXCEPTION_NONCONTINUABLE, 0, NULL);
|
|
|
|
#else
|
2019-06-08 22:06:17 +02:00
|
|
|
int code = static_cast<int>(std::strtol(argv[2], nullptr, 10));
|
2018-08-02 01:29:14 +02:00
|
|
|
::raise(code);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-10-14 22:26:30 +02:00
|
|
|
int main(int /*argc*/, char* argv[]) {
|
2018-08-02 01:29:14 +02:00
|
|
|
cpputils::showBacktraceOnCrash();
|
|
|
|
#if defined(_MSC_VER)
|
|
|
|
// don't show windows error box
|
|
|
|
_set_abort_behavior(0, _WRITE_ABORT_MSG);
|
|
|
|
#endif
|
|
|
|
handle_exit_signal(argv);
|
2018-08-02 02:13:42 +02:00
|
|
|
return 0;
|
2018-08-02 01:29:14 +02:00
|
|
|
}
|