Core/Common: Allow to show a message when aborting

Add a new ABORT_MSG macro that allows to show a formatted message before stopping the executable

(cherry picked from commit 0ddee8a4a0)
This commit is contained in:
jackpoz
2020-03-09 20:06:13 +01:00
committed by Shauren
parent 2b656aa967
commit 1fa4403b8c
2 changed files with 17 additions and 0 deletions

View File

@@ -127,6 +127,20 @@ void Abort(char const* file, int line, char const* function)
Crash(formattedMessage.c_str());
}
void Abort(char const* file, int line, char const* function, char const* message, ...)
{
va_list args;
va_start(args, message);
std::string formattedMessage = StringFormat("\n%s:%i in %s ABORTED:\n", file, line, function) + FormatAssertionMessage(message, args) + '\n';
va_end(args);
fprintf(stderr, "%s", formattedMessage.c_str());
fflush(stderr);
Crash(formattedMessage.c_str());
}
void AbortHandler(int sigval)
{
// nothing useful to log here, no way to pass args

View File

@@ -31,6 +31,7 @@ namespace Trinity
DECLSPEC_NORETURN TC_COMMON_API void Error(char const* file, int line, char const* function, char const* message) ATTR_NORETURN;
DECLSPEC_NORETURN TC_COMMON_API void Abort(char const* file, int line, char const* function) ATTR_NORETURN;
DECLSPEC_NORETURN TC_COMMON_API void Abort(char const* file, int line, char const* function, char const* message, ...) ATTR_NORETURN;
TC_COMMON_API void Warning(char const* file, int line, char const* function, char const* message);
@@ -58,6 +59,7 @@ TC_COMMON_API std::string GetDebugInfo();
#define WPError(cond, msg) ASSERT_BEGIN do { if (!(cond)) Trinity::Error(__FILE__, __LINE__, __FUNCTION__, (msg)); } while(0) ASSERT_END
#define WPWarning(cond, msg) ASSERT_BEGIN do { if (!(cond)) Trinity::Warning(__FILE__, __LINE__, __FUNCTION__, (msg)); } while(0) ASSERT_END
#define WPAbort() ASSERT_BEGIN do { Trinity::Abort(__FILE__, __LINE__, __FUNCTION__); } while(0) ASSERT_END
#define WPAbort_MSG(msg, ...) ASSERT_BEGIN do { Trinity::Abort(__FILE__, __LINE__, __FUNCTION__, (msg), ##__VA_ARGS__); } while(0) ASSERT_END
#ifdef PERFORMANCE_PROFILING
#define ASSERT(cond, ...) ((void)0)
@@ -68,6 +70,7 @@ TC_COMMON_API std::string GetDebugInfo();
#endif
#define ABORT WPAbort
#define ABORT_MSG WPAbort_MSG
template <typename T>
inline T* ASSERT_NOTNULL_IMPL(T* pointer, char const* expr)