AuroraRuntime/Source/Debug/Panic.cpp

95 lines
2.1 KiB
C++
Raw Normal View History

2021-06-27 21:25:29 +00:00
/***
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: Panic.cpp
Date: 2021-6-12
Author: Reece
***/
2021-09-30 14:57:41 +00:00
#include <Source/RuntimeInternal.hpp>
2021-06-27 21:25:29 +00:00
#include "Debug.hpp"
#include "Panic.hpp"
//#include <intrin.h>
2022-01-28 00:45:37 +00:00
#include <Source/Console/Flusher.hpp>
2021-06-27 21:25:29 +00:00
namespace Aurora::Debug
{
void PlatformHandleFatal();
2021-09-06 10:58:08 +00:00
AUKN_SYM void DebugBreak()
{
#if defined(DEBUG) || defined(STAGING)
2021-09-06 10:58:08 +00:00
#if defined(AURORA_PLATFORM_WIN32)
#if defined(STAGING)
2021-09-06 10:58:08 +00:00
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
2021-09-06 10:58:08 +00:00
#endif
#endif
}
2021-06-27 21:25:29 +00:00
AUKN_SYM void Panic()
{
2022-01-28 00:45:37 +00:00
//
static bool handlingFatal = false;
if (AuExchange(handlingFatal, true))
{
goto failFast;
}
2021-09-06 10:58:08 +00:00
DebugBreak();
2021-06-27 21:25:29 +00:00
try
{
CheckErrors();
}
catch (...)
{
}
try
{
2022-01-28 00:45:37 +00:00
Console::ForceFlush();
2021-06-27 21:25:29 +00:00
}
catch (...)
{
}
static bool panicSingleshot = false;
2022-01-19 17:08:13 +00:00
if (AuExchange(panicSingleshot, true))
2021-06-27 21:25:29 +00:00
{
try
{
Telemetry::Mayday();
}
catch (...)
{
}
}
2022-01-28 00:45:37 +00:00
failFast:
2021-09-06 10:58:08 +00:00
#if defined(AURORA_IS_MODERNNT_DERIVED)
__fastfail('FCKD');
2021-06-27 21:25:29 +00:00
#else
2021-09-06 10:58:08 +00:00
#if defined(AURORA_COMPILER_GCC) || defined(AURORA_COMPILER_CLANG)
__builtin_trap();
#else
std::terminate();
2021-09-06 10:58:08 +00:00
#endif
2021-06-27 21:25:29 +00:00
#endif
}
}