36#if TRINITY_PLATFORM == TRINITY_PLATFORM_WINDOWS
39#define Crash(message) \
40 ULONG_PTR execeptionArgs[] = { reinterpret_cast<ULONG_PTR>(strdup(message)), reinterpret_cast<ULONG_PTR>(_ReturnAddress()) }; \
41 RaiseException(EXCEPTION_ASSERTION_FAILURE, 0, 2, execeptionArgs);
45extern "C" {
TC_COMMON_API char const* TrinityAssertionFailedMessage =
nullptr; }
46#define Crash(message) \
47 TrinityAssertionFailedMessage = strdup(message); \
48 *((volatile int*)nullptr) = 0; \
54 std::string FormatAssertionMessage(
char const* format, va_list args)
56 std::string formatted;
60 int32 length = vsnprintf(
nullptr, 0, format, len);
63 formatted.resize(length);
64 vsnprintf(&formatted[0], length + 1, format, args);
73void Assert(
char const* file,
int line,
char const* function, std::string debugInfo,
char const* message)
75 std::string formattedMessage =
StringFormat(
"\n{}:{} in {} ASSERTION FAILED:\n {}\n", file, line, function, message) + debugInfo +
'\n';
76 fprintf(stderr,
"%s", formattedMessage.c_str());
78 Crash(formattedMessage.c_str());
81void Assert(
char const* file,
int line,
char const* function, std::string debugInfo,
char const* message,
char const* format, ...)
84 va_start(args, format);
86 std::string formattedMessage =
StringFormat(
"\n{}:{} in {} ASSERTION FAILED:\n {}\n", file, line, function, message) + FormatAssertionMessage(format, args) +
'\n' + debugInfo +
'\n';
89 fprintf(stderr,
"%s", formattedMessage.c_str());
92 Crash(formattedMessage.c_str());
95void Fatal(
char const* file,
int line,
char const* function,
char const* message, ...)
98 va_start(args, message);
100 std::string formattedMessage =
StringFormat(
"\n{}:{} in {} FATAL ERROR:\n", file, line, function) + FormatAssertionMessage(message, args) +
'\n';
103 fprintf(stderr,
"%s", formattedMessage.c_str());
106 std::this_thread::sleep_for(std::chrono::seconds(10));
107 Crash(formattedMessage.c_str());
110void Error(
char const* file,
int line,
char const* function,
char const* message)
112 std::string formattedMessage =
StringFormat(
"\n{}:{} in {} ERROR:\n {}\n", file, line, function, message);
113 fprintf(stderr,
"%s", formattedMessage.c_str());
115 Crash(formattedMessage.c_str());
118void Warning(
char const* file,
int line,
char const* function,
char const* message)
120 fprintf(stderr,
"\n%s:%i in %s WARNING:\n %s\n",
121 file, line, function, message);
124void Abort(
char const* file,
int line,
char const* function)
126 std::string formattedMessage =
StringFormat(
"\n{}:{} in {} ABORTED.\n", file, line, function);
127 fprintf(stderr,
"%s", formattedMessage.c_str());
129 Crash(formattedMessage.c_str());
132void Abort(
char const* file,
int line,
char const* function,
char const* message, ...)
135 va_start(args, message);
137 std::string formattedMessage =
StringFormat(
"\n{}:{} in {} ABORTED:\n", file, line, function) + FormatAssertionMessage(message, args) +
'\n';
140 fprintf(stderr,
"%s", formattedMessage.c_str());
143 Crash(formattedMessage.c_str());
149 std::string formattedMessage =
StringFormat(
"Caught signal {}\n", sigval);
150 fprintf(stderr,
"%s", formattedMessage.c_str());
152 Crash(formattedMessage.c_str());
std::string GetDebugInfo()
void Assert(char const *file, int line, char const *function, std::string debugInfo, char const *message)
void AbortHandler(int sigval)
void Warning(char const *file, int line, char const *function, char const *message)
void Abort(char const *file, int line, char const *function)
void Fatal(char const *file, int line, char const *function, char const *message,...)
std::string StringFormat(FormatString< Args... > fmt, Args &&... args)
Default TC string format function.
void Error(char const *file, int line, char const *function, char const *message)