AuroraRuntime/Include/Aurora/Debug/Debug.hpp
Reece Wilson 89d341b4fc [+] AuDebug::ErrorStack / AuErrorStack
[+] Begin stubbing out memory crunch apis
[*] Fixed MT consoletty missed flushes
2022-11-30 11:11:18 +00:00

110 lines
3.1 KiB
C++

/***
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: Debug.hpp
Date: 2021-6-9
Author: Reece
***/
#pragma once
#include <Aurora/Console/Console.hpp>
#include "StackTrace.hpp"
#include "EFailureCategory.hpp"
namespace Aurora::Debug
{
using OSError_t = AuPair<AuUInt64, AuString>;
/**
Retrieves a print-friendly callstack of the last trap (either innocent exception or fatal mem access) <br>
On Win32, this information is always available
*/
AUKN_SYM AuString GetLastErrorStack();
AUKN_SYM StackTrace GetLastStackTrace();
/**
Retrieve information about the last exception.
On Win32, this information is always available
*/
AUKN_SYM AuString GetLastException();
/**
Retrieve the last system error (Example -> Win32, GetLastError())
*/
AUKN_SYM OSError_t GetLastSystemMessage();
/**
Prints the current error state of the thread including: <br>
Current System Error, <br>
Current Runtime Error, <br>
Last Exception Call Stack, <br>
Last major ring notification
*/
AUKN_SYM void PrintError();
AUKN_SYM void CheckErrors();
/**
* @brief Specifies an EFailureCategory value for the current thread
* @param category
* @return
*/
AUKN_SYM void ErrorCategorySet(EFailureCategory category);
/**
* @brief Guarantees a refresh of ErrorCategoryGet's current value
* @return
*/
AUKN_SYM void ErrorCategoryClear();
/**
* @brief Returns the last EFailureCategory as specified by ErrorCategorySet or SysPushErrors
* @return
*/
AUKN_SYM EFailureCategory ErrorCategoryGet();
AUKN_SYM StackTrace GetStackTrace();
/**
Immediately terminates the process.
May attempt some hardened telemetry debug ops
*/
AUKN_SYM AU_NORETURN void Panic();
/**
Localize platform dependent abi mangled name
*/
AUKN_SYM AuResult<AuString> DemangleName(const AuString &pName);
AUKN_SYM void DebugBreak();
AUKN_SYM void AddMemoryCrunch();
AUKN_SYM void DecMemoryCrunch();
}
#include "SysPanic.hpp"
#include "SysAssertions.hpp"
#include "SysErrors.hpp"
#include "ErrorStack.hpp"
struct AuDbgStringSharedException : AuStringException
{
inline AuDbgStringSharedException(AuSPtr<AuString> pStr) noexcept :
AuStringException(pStr->c_str()),
pStr(pStr)
{
}
AuSPtr<AuString> pStr;
};
#if defined(AU_THROW_STRING)
#undef AU_THROW_STRING
#endif
#define AU_THROW_STRING(var) do { Aurora::Debug::AddMemoryCrunch(); auto pStr = AuMakeSharedPanic<AuString>(var); Aurora::Debug::DecMemoryCrunch(); throw AuDbgStringSharedException(pStr); } while (0)
#define AU_THROW_FORMATTED(var, ...) do { Aurora::Debug::AddMemoryCrunch(); auto pStr = AuMakeSharedPanic<AuString>(fmt::format(var, ##__VA_ARGS__)); Aurora::Debug::DecMemoryCrunch(); throw AuDbgStringSharedException(pStr); } while (0)