AuroraRuntime/Source/Debug/Panic.cpp
2022-01-28 00:45:37 +00:00

95 lines
2.1 KiB
C++

/***
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: Panic.cpp
Date: 2021-6-12
Author: Reece
***/
#include <Source/RuntimeInternal.hpp>
#include "Debug.hpp"
#include "Panic.hpp"
//#include <intrin.h>
#include <Source/Console/Flusher.hpp>
namespace Aurora::Debug
{
void PlatformHandleFatal();
AUKN_SYM void DebugBreak()
{
#if defined(DEBUG) || defined(STAGING)
#if defined(AURORA_PLATFORM_WIN32)
#if defined(STAGING)
if (IsDebuggerPresent())
#endif
{
::DebugBreak();
}
#elif defined(DEBUG)
#if defined(AURORA_COMPILER_MSVC)
__debugbreak();
#elif (defined(__has_builtin) && __has_builtin(__builtin_debugtrap))
__builtin_debugtrap();
#elif defined(AURORA_COMPILER_GCC) || defined(AURORA_COMPILER_CLANG)
// GCC is a terrible compiler, msvc is annoying at best, and LLVM + cpp frontend seems great, whats new?
// I refuse to chuck inline assembly here, not here, not in this project, not for freetards.
#endif
#endif
#endif
}
AUKN_SYM void Panic()
{
//
static bool handlingFatal = false;
if (AuExchange(handlingFatal, true))
{
goto failFast;
}
DebugBreak();
try
{
CheckErrors();
}
catch (...)
{
}
try
{
Console::ForceFlush();
}
catch (...)
{
}
static bool panicSingleshot = false;
if (AuExchange(panicSingleshot, true))
{
try
{
Telemetry::Mayday();
}
catch (...)
{
}
}
failFast:
#if defined(AURORA_IS_MODERNNT_DERIVED)
__fastfail('FCKD');
#else
#if defined(AURORA_COMPILER_GCC) || defined(AURORA_COMPILER_CLANG)
__builtin_trap();
#else
std::terminate();
#endif
#endif
}
}