提交 e7ee48fd 编写于 作者: S Shengliang Guan

enh: add tassert funcs

上级 bed68741
......@@ -27,6 +27,7 @@ extern "C" {
#if !defined(WINDOWS)
#include <dirent.h>
#include <execinfo.h>
#include <libgen.h>
#include <sched.h>
#include <unistd.h>
......
......@@ -46,6 +46,26 @@ void taosSetTerminalMode();
int32_t taosGetOldTerminalMode();
void taosResetTerminalMode();
#if defined(LINUX)
#define taosPrintTrace(flags, level, dflag) \
{ \
void* array[100]; \
int32_t size = backtrace(array, 100); \
char** strings = backtrace_symbols(array, size); \
if (strings != NULL) { \
taosPrintLog(flags, level, dflag, "obtained %d stack frames", size); \
for (int32_t i = 0; i < size; i++) { \
taosPrintLog(flags, level, dflag, "frame:%d, %s", i, strings[i]); \
} \
} \
\
taosMemoryFree(strings); \
}
#else
#define taosPrintTrace(flags, level, dflag) \
{}
#endif
#ifdef __cplusplus
}
#endif
......
......@@ -84,8 +84,8 @@ void taosPrintLongString(const char *flags, ELogLevel level, int32_t dflag, cons
;
bool taosAssertLog(bool condition, const char *file, int32_t line, const char *format, ...);
#define tAssert(...) (void)taosAssertLog(condition, __FILE__, __LINE__, __VA_ARGS__);
#define tAssertR(...) taosAssertLog(condition, __FILE__, __LINE__, __VA_ARGS__)
#define tAssert(condition, ...) (void)taosAssertLog(condition, __FILE__, __LINE__, __VA_ARGS__);
#define tAssertR(condition, ...) taosAssertLog(condition, __FILE__, __LINE__, __VA_ARGS__)
// clang-format off
#define uFatal(...) { if (uDebugFlag & DEBUG_FATAL) { taosPrintLog("UTL FATAL", DEBUG_FATAL, tsLogEmbedded ? 255 : uDebugFlag, __VA_ARGS__); }}
......
......@@ -103,6 +103,8 @@ int32_t dmInitDnode(SDnode *pDnode) {
goto _OVER;
}
tAssert(0, "");
pDnode->wrappers[DNODE].func = dmGetMgmtFunc();
pDnode->wrappers[MNODE].func = mmGetMgmtFunc();
pDnode->wrappers[VNODE].func = vmGetMgmtFunc();
......
......@@ -781,28 +781,33 @@ cmp_end:
}
bool taosAssertLog(bool condition, const char *file, int32_t line, const char *format, ...) {
if (!condition) return false;
if (condition) return false;
char buffer[LOG_MAX_LINE_BUFFER_SIZE];
int32_t len = taosBuildLogHead(buffer, "UTL FATAL");
const char *flags = "UTL FATAL ";
ELogLevel level = DEBUG_FATAL;
int32_t dflag = 255; // tsLogEmbedded ? 255 : uDebugFlag
char buffer[LOG_MAX_LINE_BUFFER_SIZE];
int32_t len = taosBuildLogHead(buffer, flags);
va_list argpointer;
va_start(argpointer, format);
int32_t writeLen = len + vsnprintf(buffer + len, LOG_MAX_LINE_BUFFER_SIZE - len, format, argpointer);
len = len + vsnprintf(buffer + len, LOG_MAX_LINE_BUFFER_SIZE - len, format, argpointer);
va_end(argpointer);
buffer[len++] = '\n';
buffer[len] = 0;
taosPrintLogImp(1, 255, buffer, len);
char fullBuf[LOG_MAX_LINE_BUFFER_SIZE];
int32_t fullLen = snprintf(fullBuf, sizeof(fullBuf), "ASSERT at file:%s:%d, %s", file, line, buffer);
taosPrintLogImp(1, 255, fullBuf, fullLen);
taosPrintLog(flags, level, dflag, "ASSERT at file %s:%d exit:%d", file, line, tsAssert);
taosPrintTrace(flags, level, dflag);
if (tsAssert) {
taosCloseLog();
taosMsleep(300);
#if NDEBUG
#ifdef NDEBUG
abort();
#else
ASSERT(1);
ASSERT(0);
#endif
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册