36#if TRINITY_PLATFORM == TRINITY_PLATFORM_WINDOWS
38#define Crash(message) \
39 ULONG_PTR execeptionArgs[] = { reinterpret_cast<ULONG_PTR>(strdup(message)), reinterpret_cast<ULONG_PTR>(_ReturnAddress()) }; \
40 RaiseException(EXCEPTION_ASSERTION_FAILURE, 0, 2, execeptionArgs);
43extern "C" {
TC_COMMON_API char const* TrinityAssertionFailedMessage =
nullptr; }
44#define Crash(message) \
45 TrinityAssertionFailedMessage = strdup(message); \
46 *((volatile int*)nullptr) = 0; \
52 std::string FormatAssertionMessage(
char const* format, va_list args)
54 std::string formatted;
58 int32 length = vsnprintf(
nullptr, 0, format, len);
61 formatted.resize(length);
62 vsnprintf(&formatted[0], length + 1, format, args);
71void Assert(
char const* file,
int line,
char const* function, std::string debugInfo,
char const* message)
73 std::string formattedMessage =
StringFormat(
"\n{}:{} in {} ASSERTION FAILED:\n {}\n", file, line, function, message) + debugInfo +
'\n';
74 fprintf(stderr,
"%s", formattedMessage.c_str());
76 Crash(formattedMessage.c_str());
79void Assert(
char const* file,
int line,
char const* function, std::string debugInfo,
char const* message,
char const* format, ...)
82 va_start(args, format);
84 std::string formattedMessage =
StringFormat(
"\n{}:{} in {} ASSERTION FAILED:\n {}\n", file, line, function, message) + FormatAssertionMessage(format, args) +
'\n' + debugInfo +
'\n';
87 fprintf(stderr,
"%s", formattedMessage.c_str());
90 Crash(formattedMessage.c_str());
93void Fatal(
char const* file,
int line,
char const* function,
char const* message, ...)
96 va_start(args, message);
98 std::string formattedMessage =
StringFormat(
"\n{}:{} in {} FATAL ERROR:\n", file, line, function) + FormatAssertionMessage(message, args) +
'\n';
101 fprintf(stderr,
"%s", formattedMessage.c_str());
104 std::this_thread::sleep_for(std::chrono::seconds(10));
105 Crash(formattedMessage.c_str());
108void Error(
char const* file,
int line,
char const* function,
char const* message)
110 std::string formattedMessage =
StringFormat(
"\n{}:{} in {} ERROR:\n {}\n", file, line, function, message);
111 fprintf(stderr,
"%s", formattedMessage.c_str());
113 Crash(formattedMessage.c_str());
116void Warning(
char const* file,
int line,
char const* function,
char const* message)
118 fprintf(stderr,
"\n%s:%i in %s WARNING:\n %s\n",
119 file, line, function, message);
122void Abort(
char const* file,
int line,
char const* function)
124 std::string formattedMessage =
StringFormat(
"\n{}:{} in {} ABORTED.\n", file, line, function);
125 fprintf(stderr,
"%s", formattedMessage.c_str());
127 Crash(formattedMessage.c_str());
130void Abort(
char const* file,
int line,
char const* function,
char const* message, ...)
133 va_start(args, message);
135 std::string formattedMessage =
StringFormat(
"\n{}:{} in {} ABORTED:\n", file, line, function) + FormatAssertionMessage(message, args) +
'\n';
138 fprintf(stderr,
"%s", formattedMessage.c_str());
141 Crash(formattedMessage.c_str());
147 std::string formattedMessage =
StringFormat(
"Caught signal {}\n", sigval);
148 fprintf(stderr,
"%s", formattedMessage.c_str());
150 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)