36#if TRINITY_COMPILER == TRINITY_COMPILER_MICROSOFT
37#define Unreachable() (__assume(false))
39#define Unreachable() (__builtin_unreachable())
42#if TRINITY_PLATFORM == TRINITY_PLATFORM_WINDOWS
45#define Crash(message) \
46 ULONG_PTR execeptionArgs[] = { reinterpret_cast<ULONG_PTR>(strdup(message)), reinterpret_cast<ULONG_PTR>(_ReturnAddress()) }; \
47 RaiseException(EXCEPTION_ASSERTION_FAILURE, 0, 2, execeptionArgs); \
51extern "C" {
TC_COMMON_API char const* TrinityAssertionFailedMessage =
nullptr; }
52#define Crash(message) \
53 TrinityAssertionFailedMessage = strdup(message); \
54 *((volatile int*)nullptr) = 0; \
60 void FormatAssertionMessageTo(std::string& formatted,
char const* format, va_list args)
noexcept
65 int32 length = vsnprintf(
nullptr, 0, format, len);
68 std::size_t offset = formatted.length();
69 formatted.resize(offset + length);
70 vsnprintf(&formatted[offset], length + 1, format, args);
76void Assert(
char const* file,
int line,
char const* function,
char const* message, std::string debugInfo)
noexcept
78 std::string formattedMessage =
StringFormat(
"\n{}:{} in {} ASSERTION FAILED:\n {}\n{}\n", file, line, function, message, debugInfo);
79 fprintf(stderr,
"%s", formattedMessage.c_str());
81 Crash(formattedMessage.c_str());
84void Assert(
char const* file,
int line,
char const* function,
char const* message, std::string debugInfo,
char const* format, ...) noexcept
87 va_start(args, format);
89 std::string formattedMessage =
StringFormat(
"\n{}:{} in {} ASSERTION FAILED:\n {}\n", file, line, function, message);
90 FormatAssertionMessageTo(formattedMessage, format, args);
93 formattedMessage.append(1,
'\n');
94 formattedMessage.append(debugInfo);
95 formattedMessage.append(1,
'\n');
97 fprintf(stderr,
"%s", formattedMessage.c_str());
100 Crash(formattedMessage.c_str());
103void Fatal(
char const* file,
int line,
char const* function,
char const* message, ...) noexcept
106 va_start(args, message);
108 std::string formattedMessage =
StringFormat(
"\n{}:{} in {} FATAL ERROR:\n", file, line, function);
109 FormatAssertionMessageTo(formattedMessage, message, args);
112 formattedMessage.append(1,
'\n');
114 fprintf(stderr,
"%s", formattedMessage.c_str());
117 std::this_thread::sleep_for(std::chrono::seconds(10));
118 Crash(formattedMessage.c_str());
121void Error(
char const* file,
int line,
char const* function,
char const* message)
noexcept
123 std::string formattedMessage =
StringFormat(
"\n{}:{} in {} ERROR:\n {}\n", file, line, function, message);
124 fprintf(stderr,
"%s", formattedMessage.c_str());
126 Crash(formattedMessage.c_str());
129void Warning(
char const* file,
int line,
char const* function,
char const* message)
noexcept
131 fprintf(stderr,
"\n%s:%i in %s WARNING:\n %s\n",
132 file, line, function, message);
135void Abort(
char const* file,
int line,
char const* function)
noexcept
137 std::string formattedMessage =
StringFormat(
"\n{}:{} in {} ABORTED.\n", file, line, function);
138 fprintf(stderr,
"%s", formattedMessage.c_str());
140 Crash(formattedMessage.c_str());
143void Abort(
char const* file,
int line,
char const* function,
char const* message, ...) noexcept
146 va_start(args, message);
148 std::string formattedMessage =
StringFormat(
"\n{}:{} in {} ABORTED:\n", file, line, function);
149 FormatAssertionMessageTo(formattedMessage, message, args);
152 formattedMessage.append(1,
'\n');
154 fprintf(stderr,
"%s", formattedMessage.c_str());
157 Crash(formattedMessage.c_str());
163 std::string formattedMessage =
StringFormat(
"Caught signal {}\n", sigval);
164 fprintf(stderr,
"%s", formattedMessage.c_str());
166 Crash(formattedMessage.c_str());
std::string GetDebugInfo()
void Assert(char const *file, int line, char const *function, char const *message, std::string debugInfo) noexcept
void Error(char const *file, int line, char const *function, char const *message) noexcept
std::string StringFormat(FormatString< Args... > fmt, Args &&... args) noexcept
Default TC string format function.
void Abort(char const *file, int line, char const *function) noexcept
void Fatal(char const *file, int line, char const *function, char const *message,...) noexcept
void AbortHandler(int sigval) noexcept