diff --git a/include/os/os.h b/include/os/os.h index 0688eeb9addf920b4a27a7fac0dcab0ec4735144..b27fa84406b843f15ba99d52f7d9fde8580a0899 100644 --- a/include/os/os.h +++ b/include/os/os.h @@ -27,6 +27,7 @@ extern "C" { #if !defined(WINDOWS) #include +#include #include #include #include diff --git a/include/os/osSystem.h b/include/os/osSystem.h index eca984c41a3a0502ba726dfbac228dcc82076298..dd1c5cd2047e994b730f2e868f55dfb7ba62050a 100644 --- a/include/os/osSystem.h +++ b/include/os/osSystem.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 diff --git a/include/util/tlog.h b/include/util/tlog.h index 12103d97f16db9e0240d4f7ed6783da094f20bae..2caeaf71a9f25788215b6924297d3d84983ed338 100644 --- a/include/util/tlog.h +++ b/include/util/tlog.h @@ -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__); }} diff --git a/source/dnode/mgmt/node_mgmt/src/dmMgmt.c b/source/dnode/mgmt/node_mgmt/src/dmMgmt.c index 02a268afda28698aba56148eacb8b205f12e0af2..c3f5313f7bf9b6b161ad4d8a9dcb57bfa4858c23 100644 --- a/source/dnode/mgmt/node_mgmt/src/dmMgmt.c +++ b/source/dnode/mgmt/node_mgmt/src/dmMgmt.c @@ -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(); diff --git a/source/util/src/tlog.c b/source/util/src/tlog.c index 5d887bb1ac16c8ce4bcb957ac56d6ae12e4c574d..7beddd5d4ffe14467b4e45cbd63cb9cb79ba0250 100644 --- a/source/util/src/tlog.c +++ b/source/util/src/tlog.c @@ -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 }