mirror of
https://github.com/liyunfan1223/azerothcore-wotlk.git
synced 2026-08-08 15:58:04 +00:00
feat(Core/Debugging): Allow to show a message when aborting (#5228)
This commit is contained in:
@@ -56,7 +56,6 @@ namespace
|
|||||||
|
|
||||||
namespace acore
|
namespace acore
|
||||||
{
|
{
|
||||||
|
|
||||||
void Assert(char const* file, int line, char const* function, std::string const& debugInfo, char const* message)
|
void Assert(char const* file, int line, char const* function, std::string const& debugInfo, char const* message)
|
||||||
{
|
{
|
||||||
std::string formattedMessage = acore::StringFormat("\n%s:%i in %s ASSERTION FAILED:\n %s\n", file, line, function, message) + debugInfo + '\n';
|
std::string formattedMessage = acore::StringFormat("\n%s:%i in %s ASSERTION FAILED:\n %s\n", file, line, function, message) + debugInfo + '\n';
|
||||||
@@ -116,6 +115,20 @@ namespace acore
|
|||||||
Crash(formattedMessage.c_str());
|
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)
|
void AbortHandler(int sigval)
|
||||||
{
|
{
|
||||||
// nothing useful to log here, no way to pass args
|
// nothing useful to log here, no way to pass args
|
||||||
|
|||||||
@@ -21,6 +21,8 @@ namespace acore
|
|||||||
|
|
||||||
DECLSPEC_NORETURN void Abort(char const* file, int line, char const* function) ATTR_NORETURN;
|
DECLSPEC_NORETURN void Abort(char const* file, int line, char const* function) ATTR_NORETURN;
|
||||||
|
|
||||||
|
DECLSPEC_NORETURN void Abort(char const* file, int line, char const* function, char const* message, ...) ATTR_NORETURN;
|
||||||
|
|
||||||
void Warning(char const* file, int line, char const* function, char const* message);
|
void Warning(char const* file, int line, char const* function, char const* message);
|
||||||
|
|
||||||
DECLSPEC_NORETURN void AbortHandler(int sigval) ATTR_NORETURN;
|
DECLSPEC_NORETURN void AbortHandler(int sigval) ATTR_NORETURN;
|
||||||
@@ -47,6 +49,7 @@ std::string GetDebugInfo();
|
|||||||
#define WPError(cond, msg) ASSERT_BEGIN do { if (!(cond)) acore::Error(__FILE__, __LINE__, __FUNCTION__, (msg)); } while(0) ASSERT_END
|
#define WPError(cond, msg) ASSERT_BEGIN do { if (!(cond)) acore::Error(__FILE__, __LINE__, __FUNCTION__, (msg)); } while(0) ASSERT_END
|
||||||
#define WPWarning(cond, msg) ASSERT_BEGIN do { if (!(cond)) acore::Warning(__FILE__, __LINE__, __FUNCTION__, (msg)); } while(0) ASSERT_END
|
#define WPWarning(cond, msg) ASSERT_BEGIN do { if (!(cond)) acore::Warning(__FILE__, __LINE__, __FUNCTION__, (msg)); } while(0) ASSERT_END
|
||||||
#define WPAbort() ASSERT_BEGIN do { acore::Abort(__FILE__, __LINE__, __FUNCTION__); } while(0) ASSERT_END
|
#define WPAbort() ASSERT_BEGIN do { acore::Abort(__FILE__, __LINE__, __FUNCTION__); } while(0) ASSERT_END
|
||||||
|
#define WPAbort_MSG(msg, ...) ASSERT_BEGIN do { acore::Abort(__FILE__, __LINE__, __FUNCTION__, (msg), ##__VA_ARGS__); } while(0) ASSERT_END
|
||||||
|
|
||||||
#ifdef PERFORMANCE_PROFILING
|
#ifdef PERFORMANCE_PROFILING
|
||||||
#define ASSERT(cond, ...) ((void)0)
|
#define ASSERT(cond, ...) ((void)0)
|
||||||
@@ -57,6 +60,7 @@ std::string GetDebugInfo();
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define ABORT WPAbort
|
#define ABORT WPAbort
|
||||||
|
#define ABORT_MSG WPAbort_MSG
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
inline T* ASSERT_NOTNULL_IMPL(T* pointer, char const* expr)
|
inline T* ASSERT_NOTNULL_IMPL(T* pointer, char const* expr)
|
||||||
|
|||||||
Reference in New Issue
Block a user