#include <stdarg.h>
#include <stdio.h>
#include <assert.h>
+#include <algorithm>
+#include <mutex>
#if SWR_ENABLE_ASSERTS || SWR_ENABLE_REL_ASSERTS
#endif
}
-bool SwrAssert(
- bool chkDebugger,
- bool& enabled,
- const char* pExpression,
+static std::mutex g_stderrMutex;
+
+void SwrTrace(
const char* pFileName,
uint32_t lineNum,
- const char* pFunction,
- const char* pFmtString /* = nullptr */,
+ const char* function,
+ const char* pFmtString,
...)
{
- SetTextColor(stderr, TEXT_CYAN, TEXT_NORMAL);
+ std::lock_guard<std::mutex> l(g_stderrMutex);
- fprintf(stderr, "%s(%d): ", pFileName, lineNum);
-
- SetTextColor(stderr, TEXT_RED, TEXT_INTENSITY);
-
- fprintf(stderr, "ASSERT: %s\n", pExpression);
+ SetTextColor(stderr, TEXT_CYAN, TEXT_NORMAL);
- SetTextColor(stderr, TEXT_CYAN, TEXT_INTENSITY);
- fprintf(stderr, "\t%s\n", pFunction);
+ fprintf(stderr, "%s(%d): TRACE in %s:\n", pFileName, lineNum, function);
if (pFmtString)
{
- SetTextColor(stderr, TEXT_YELLOW, TEXT_INTENSITY);
+ SetTextColor(stderr, TEXT_PURPLE, TEXT_INTENSITY);
fprintf(stderr, "\t");
va_list args;
va_start(args, pFmtString);
ResetTextColor(stderr);
fflush(stderr);
+#if defined(_WIN32)
+ static const int MAX_MESSAGE_LEN = 2048;
+ char msgBuf[MAX_MESSAGE_LEN];
+
+ sprintf_s(msgBuf, "%s(%d): TRACE in %s\n", pFileName, lineNum, function);
+ msgBuf[MAX_MESSAGE_LEN - 2] = '\n';
+ msgBuf[MAX_MESSAGE_LEN - 1] = 0;
+ OutputDebugStringA(msgBuf);
+
+ int offset = 0;
+
+ if (pFmtString)
+ {
+ va_list args;
+ va_start(args, pFmtString);
+ offset = _vsnprintf_s(
+ msgBuf,
+ sizeof(msgBuf),
+ sizeof(msgBuf),
+ pFmtString,
+ args);
+ va_end(args);
+
+ if (offset < 0) { return; }
+
+ OutputDebugStringA("\t");
+ OutputDebugStringA(msgBuf);
+ OutputDebugStringA("\n");
+ }
+#endif // _WIN32
+}
+
+bool SwrAssert(
+ bool chkDebugger,
+ bool& enabled,
+ const char* pExpression,
+ const char* pFileName,
+ uint32_t lineNum,
+ const char* pFunction,
+ const char* pFmtString /* = nullptr */,
+ ...)
+{
+ {
+ std::lock_guard<std::mutex> l(g_stderrMutex);
+
+ SetTextColor(stderr, TEXT_CYAN, TEXT_NORMAL);
+
+ fprintf(stderr, "%s(%d): ", pFileName, lineNum);
+
+ SetTextColor(stderr, TEXT_RED, TEXT_INTENSITY);
+
+ fprintf(stderr, "ASSERT: %s\n", pExpression);
+
+ SetTextColor(stderr, TEXT_CYAN, TEXT_INTENSITY);
+ fprintf(stderr, "\t%s\n", pFunction);
+
+ if (pFmtString)
+ {
+ SetTextColor(stderr, TEXT_YELLOW, TEXT_INTENSITY);
+ fprintf(stderr, "\t");
+ va_list args;
+ va_start(args, pFmtString);
+ vfprintf(stderr, pFmtString, args);
+ va_end(args);
+ fprintf(stderr, "\n");
+ }
+ ResetTextColor(stderr);
+ fflush(stderr);
+ }
+
#if defined(_WIN32)
static const int MAX_MESSAGE_LEN = 2048;
char msgBuf[MAX_MESSAGE_LEN];
const char* pFmtString = nullptr,
...);
+void SwrTrace(
+ const char* pFileName,
+ uint32_t lineNum,
+ const char* function,
+ const char* pFmtString,
+ ...);
+
#define _SWR_ASSERT(chkDebugger, e, ...) {\
bool expFailed = !(e);\
if (expFailed) {\
}\
}
+#define _SWR_TRACE(_fmtstr, ...) \
+ SwrTrace(__FILE__, __LINE__, __FUNCTION__, _fmtstr, ##__VA_ARGS__);
+
#if SWR_ENABLE_ASSERTS
#define SWR_ASSERT(e, ...) _SWR_ASSERT(true, e, ##__VA_ARGS__)
#define SWR_ASSUME_ASSERT(e, ...) SWR_ASSERT(e, ##__VA_ARGS__)
+#define SWR_TRACE(_fmtstr, ...) _SWR_TRACE(_fmtstr, ##__VA_ARGS__)
#if defined(assert)
#undef assert
#if SWR_ENABLE_REL_ASSERTS
#define SWR_REL_ASSERT(e, ...) _SWR_ASSERT(false, e, ##__VA_ARGS__)
#define SWR_REL_ASSUME_ASSERT(e, ...) SWR_REL_ASSERT(e, ##__VA_ARGS__)
+#define SWR_REL_TRACE(_fmtstr, ...) _SWR_TRACE(_fmtstr, ##__VA_ARGS__)
#endif
#endif // C++
#if !SWR_ENABLE_ASSERTS
#define SWR_ASSERT(e, ...) (void)(0)
#define SWR_ASSUME_ASSERT(e, ...) SWR_ASSUME(e, ##__VA_ARGS__)
+#define SWR_TRACE(_fmtstr, ...) (void)(0)
#endif
#if !SWR_ENABLE_REL_ASSERTS
#define SWR_REL_ASSERT(e, ...) (void)(0)
#define SWR_REL_ASSUME_ASSERT(e, ...) SWR_ASSUME(e, ##__VA_ARGS__)
+#define SWR_REL_TRACE(_fmtstr, ...) (void)(0)
#endif
#define SWR_NOT_IMPL SWR_ASSERT(0, "%s not implemented", __FUNCTION__)