mirror of
https://github.com/taosdata/TDengine
synced 2026-05-24 10:09:01 +00:00
* enh: rename libtaos.so to libtaosinternal.so * enh: let python system-test work * enh: shell for libinternal.so * enh: refact script * enh: wrapper for libtaosinternal * enh: rename some files * enh: let shell support internal driver * enh: minor changes * enh: minor changes * add intenal.h * enh: remove unused codes * enh: minor changs * feat: mac os issues * enh: let python test use internal connection * enh: let nettest work * enh: let taosc -C work * enh: test shell in mac os * enh: minor changes * enh: let libtaosinternal.so work in linux * enh: update install script * enh: for ci * enh: for windows compile * enh: minor changes * enh: compile in windows * enh: minor changes * enh: taosinternal work in windows * enh: add taos_internal_static * enh: rollback os_for_wrapper * fix: conflicts * fix: conflicts * fix: compile errors * fix: conflicts * enh: rename taosinternal to taosnative * enh: rename taosinternal to taosnative * fix: compile error * enh: remove taosnative.h * fix: compile errors * enh: set default shell options * fix: compile errors * fix: compile errors * debug: switch taosws branch to feat/new-libtaos-with-ws * enh: taosBenchmark remove WEBSOCKET finished * fix: CMakeLists.txt remove WEBSOCKET * fix: compile errors * fix: taosBenchmark delete restful code * .gitignore remove taos-tools folder * fix: remove taosdump WEBSOCKET MACRO * fix: build error for taosdump * fix: build project passed * fix: support -Z for connect mode * fix: build error * fix: build error fixed * fix: add -Z options * fix: native and websocket with string * fix: -Z option core * fix: build unit test * fix: build error * fix: add colon for array * fix: unit test can not include fun * fix: CTest pointer null is nullptr * fix: include pub.h * fix: taosdump add -Z --driver options * fix: taosdump support -Z with pub.h pub.c * fix: toolsGetTimeDay move to pub.c * fix: restore pub.c only simple fun * fix: add error tips * fix: tmfree remove from taosdump * fix: remove double declare taos variant * fix: taos support -Z option * enh: configDir set with main fun * fix: add g_arguments.configDir * fix: show tips add cfgdir * fix: g_argument is pointer * fix: configDir is global var * fix: declare g_configDir in benchMain.c * fix: taos version not show on websocket * stmt2 websocket prepare with supertable * stmt2 websocket prepare build * fix: stmt and stmt2 prepare add db name * fix: remove -R --restful test case * fix: taosBenchmark adjust priority cmd > json > evn * fix: add connect mode test case connMode.py * fix: clear evn and add host port check * fix: army/test.py modify start taosAdapter is default * change: system-test/test.py default start taosAdapter * fix: add taosAdapter variant to system-test/test.py * fix: -y must put behind other options * fix: remove rest sml and add -N normal case * fix: add -c work cfg test case * del: queryMain.py remove rest query * fix: remove groups have a blank append bug * fix: caseBase.py add db in sql query * fix: query_json.py remove rest test * fix: taosBenchmark uniform dsn describe * fix: add pub.h pub.c to tools public * fix: case remove restful interface * fix: build error * fix: taosDriverCleanup no arg call * fix: taosdump add test conn mode case taosdumpCommandline.py * fix: modify insertFullType.json db name * fix: taosdump connMode test case taosDumpCommandline.py passed * enh: priority cmd > env > json * fix: taosCli remove is_native variant * fix: password is not pointer * fix: comment -o test case * fix: solve fun return code check * fix: windows unresolved strcasecmp * fix: remove coverHostToServAddr * fix: forbid check ODR violation * ci: trigger pr run * fix: build error not del >>>>>3.0 * fix: support json dbinfo->vgroups have blank space * fix: solve conflict with merge * fix: with TrimCaseCmp fun to compare vgroups * fix: del vgroups support blank code * feat: wrapper add taos_fetch_fields_e * fix: move jni from libtaosnative.so to libtaos.so * fix: move clientTmqConnector.c for jni * fix: fix assert check with del comment code * fix: taosBenchmark add prepare stmt debug log * fix: stmt2 already have debug log on preapare * fix: (double)LLONG_MAX force covert * fix: stmt insert normal table with websocket * fix: normal table with stmt too many ? * fix: taosdump stmt_prepare with child tbname * fix: build error add int code * feat: stmtPrepare with child table to do * taos -a options move to native test case * fix:unit test benchmarkTest passed * fix: query_json-with-sqlfile.py case no check results * fix: queryMain.py case lost, put in tasks again --------- Co-authored-by: Shengliang Guan <slguan@taosdata.com>
240 lines
19 KiB
C
240 lines
19 KiB
C
/*
|
|
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
|
*
|
|
* This program is free software: you can use, redistribute, and/or modify
|
|
* it under the terms of the GNU Affero General Public License, version 3
|
|
* or later ("AGPL"), as published by the Free Software Foundation.
|
|
*
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
* FITNESS FOR A PARTICULAR PURPOSE.
|
|
*
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#ifndef _TD_OS_SYSTEM_H_
|
|
#define _TD_OS_SYSTEM_H_
|
|
|
|
#ifdef _ALPINE
|
|
#define UNW_LOCAL_ONLY
|
|
#include <libunwind.h>
|
|
#endif
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
// If the error is in a third-party library, place this header file under the third-party library header file.
|
|
// When you want to use this feature, you should find or add the same function in the following section.
|
|
#ifndef ALLOW_FORBID_FUNC
|
|
#define popen POPEN_FUNC_TAOS_FORBID
|
|
#define pclose PCLOSE_FUNC_TAOS_FORBID
|
|
#define tcsetattr TCSETATTR_FUNC_TAOS_FORBID
|
|
#define tcgetattr TCGETATTR_FUNC_TAOS_FORBID
|
|
#endif
|
|
|
|
typedef struct TdCmd *TdCmdPtr;
|
|
|
|
TdCmdPtr taosOpenCmd(const char *cmd);
|
|
|
|
int64_t taosGetsCmd(TdCmdPtr pCmd, int32_t maxSize, char *__restrict buf);
|
|
|
|
int64_t taosGetLineCmd(TdCmdPtr pCmd, char **__restrict ptrBuf);
|
|
|
|
int32_t taosEOFCmd(TdCmdPtr pCmd);
|
|
|
|
void taosCloseCmd(TdCmdPtr *ppCmd);
|
|
|
|
void *taosLoadDll(const char *fileName);
|
|
|
|
void taosCloseDll(void *handle);
|
|
|
|
void *taosLoadDllFunc(void *handle, const char *funcName);
|
|
|
|
int32_t taosSetConsoleEcho(bool on);
|
|
|
|
int32_t taosSetTerminalMode();
|
|
|
|
int32_t taosGetOldTerminalMode();
|
|
|
|
int32_t taosResetTerminalMode();
|
|
|
|
#define STACKSIZE 100
|
|
|
|
#if defined(_ALPINE)
|
|
#define taosLogTraceToBuf(buf, bufSize, ignoreNum) \
|
|
{ \
|
|
unw_cursor_t cursor; \
|
|
unw_context_t context; \
|
|
\
|
|
unw_getcontext(&context); \
|
|
unw_init_local(&cursor, &context); \
|
|
\
|
|
char *array[STACKSIZE]; \
|
|
int32_t size = 0; \
|
|
int32_t ignores = ignoreNum; \
|
|
int32_t offset = 0; \
|
|
while (unw_step(&cursor) > 0 && size < STACKSIZE) { \
|
|
unw_word_t offset, pc; \
|
|
char fname[64]; \
|
|
unw_get_reg(&cursor, UNW_REG_IP, &pc); \
|
|
fname[0] = '\0'; \
|
|
(void)unw_get_proc_name(&cursor, fname, sizeof(fname), &offset); \
|
|
array[size] = (char *)taosMemoryMalloc(sizeof(char) * STACKSIZE + 1); \
|
|
if(NULL == array[size]) { \
|
|
break; \
|
|
} \
|
|
size += 1; \
|
|
snprintf(array[size], STACKSIZE, "0x%lx : (%s+0x%lx) [0x%lx]\n", (long)pc, fname, (long)offset, (long)pc); \
|
|
} \
|
|
if (ignoreNum < size && size > 0) { \
|
|
offset = tsnprintf(buf, bufSize - 1, "obtained %d stack frames\n", (ignoreNum > 0) ? size - ignoreNum : size); \
|
|
for (int32_t i = (ignoreNum > 0) ? ignoreNum : 0; i < size; i++) { \
|
|
offset += tsnprintf(buf + offset, bufSize - 1 - offset, "frame:%d, %s\n", (ignoreNum > 0) ? i - ignoreNum : i, \
|
|
array[i]); \
|
|
} \
|
|
} \
|
|
for (int i = 0; i < size; i++) { \
|
|
taosMemoryFree(array[i]); \
|
|
} \
|
|
}
|
|
|
|
#define taosPrintTrace(flags, level, dflag, ignoreNum) \
|
|
{ \
|
|
unw_cursor_t cursor; \
|
|
unw_context_t context; \
|
|
\
|
|
unw_getcontext(&context); \
|
|
unw_init_local(&cursor, &context); \
|
|
\
|
|
char *array[STACKSIZE]; \
|
|
int32_t size = 0; \
|
|
while (unw_step(&cursor) > 0 && size < STACKSIZE) { \
|
|
unw_word_t offset, pc; \
|
|
char fname[64]; \
|
|
unw_get_reg(&cursor, UNW_REG_IP, &pc); \
|
|
fname[0] = '\0'; \
|
|
(void)unw_get_proc_name(&cursor, fname, sizeof(fname), &offset); \
|
|
size += 1; \
|
|
array[size] = (char *)taosMemoryMalloc(sizeof(char) * STACKSIZE + 1); \
|
|
snprintf(array[size], STACKSIZE, "frame:%d, 0x%lx : (%s+0x%lx) [0x%lx]\n", size, (long)pc, fname, (long)offset, \
|
|
(long)pc); \
|
|
} \
|
|
if (ignoreNum < size && size > 0) { \
|
|
taosPrintLog(flags, level, dflag, "obtained %d stack frames", (ignoreNum > 0) ? size - ignoreNum : size); \
|
|
for (int32_t i = (ignoreNum > 0) ? ignoreNum : 0; i < size; i++) { \
|
|
taosPrintLog(flags, level, dflag, "frame:%d, %s", (ignoreNum > 0) ? i - ignoreNum : i, array[i]); \
|
|
} \
|
|
} \
|
|
for (int i = 0; i < size; i++) { \
|
|
taosMemoryFree(array[i]); \
|
|
} \
|
|
}
|
|
|
|
#elif !defined(WINDOWS)
|
|
#define taosLogTraceToBuf(buf, bufSize, ignoreNum) \
|
|
{ \
|
|
void *array[STACKSIZE]; \
|
|
int32_t size = backtrace(array, STACKSIZE); \
|
|
char **strings = backtrace_symbols(array, size); \
|
|
int32_t offset = 0; \
|
|
if (strings != NULL) { \
|
|
offset = tsnprintf(buf, bufSize - 1, "obtained %d stack frames\n", (ignoreNum > 0) ? size - ignoreNum : size); \
|
|
for (int32_t i = (ignoreNum > 0) ? ignoreNum : 0; i < size; i++) { \
|
|
offset += tsnprintf(buf + offset, bufSize - 1 - offset, "frame:%d, %s\n", (ignoreNum > 0) ? i - ignoreNum : i, \
|
|
strings[i]); \
|
|
} \
|
|
} \
|
|
\
|
|
taosMemoryFree(strings); \
|
|
}
|
|
|
|
#define taosPrintTrace(flags, level, dflag, ignoreNum) \
|
|
{ \
|
|
void *array[STACKSIZE]; \
|
|
int32_t size = backtrace(array, STACKSIZE); \
|
|
char **strings = backtrace_symbols(array, size); \
|
|
if (strings != NULL) { \
|
|
taosPrintLog(flags, level, dflag, "obtained %d stack frames", (ignoreNum > 0) ? size - ignoreNum : size); \
|
|
for (int32_t i = (ignoreNum > 0) ? ignoreNum : 0; i < size; i++) { \
|
|
taosPrintLog(flags, level, dflag, "frame:%d, %s", (ignoreNum > 0) ? i - ignoreNum : i, strings[i]); \
|
|
} \
|
|
} \
|
|
\
|
|
taosMemoryFree(strings); \
|
|
}
|
|
#else
|
|
|
|
#include <dbghelp.h>
|
|
#include <windows.h>
|
|
|
|
#define taosLogTraceToBuf(buf, bufSize, ignoreNum) \
|
|
{ \
|
|
unsigned int i; \
|
|
void *stack[STACKSIZE]; \
|
|
unsigned short frames; \
|
|
SYMBOL_INFO *symbol; \
|
|
HANDLE process; \
|
|
int32_t offset = 0; \
|
|
\
|
|
process = GetCurrentProcess(); \
|
|
\
|
|
SymInitialize(process, NULL, TRUE); \
|
|
\
|
|
frames = CaptureStackBackTrace(0, STACKSIZE, stack, NULL); \
|
|
symbol = (SYMBOL_INFO *)calloc(sizeof(SYMBOL_INFO) + 256 * sizeof(char), 1); \
|
|
if (symbol != NULL) { \
|
|
symbol->MaxNameLen = 255; \
|
|
symbol->SizeOfStruct = sizeof(SYMBOL_INFO); \
|
|
\
|
|
if (frames > 0) { \
|
|
offset = \
|
|
snprintf(buf, bufSize - 1, "obtained %d stack frames\n", (ignoreNum > 0) ? frames - ignoreNum : frames); \
|
|
for (i = (ignoreNum > 0) ? ignoreNum : 0; i < frames; i++) { \
|
|
SymFromAddr(process, (DWORD64)(stack[i]), 0, symbol); \
|
|
offset += tsnprintf(buf + offset, bufSize - 1 - offset, "frame:%i, %s - 0x%0X\n", \
|
|
(ignoreNum > 0) ? i - ignoreNum : i, symbol->Name, symbol->Address); \
|
|
} \
|
|
} \
|
|
free(symbol); \
|
|
} \
|
|
}
|
|
|
|
#define taosPrintTrace(flags, level, dflag, ignoreNum) \
|
|
{ \
|
|
unsigned int i; \
|
|
void *stack[STACKSIZE]; \
|
|
unsigned short frames; \
|
|
SYMBOL_INFO *symbol; \
|
|
HANDLE process; \
|
|
\
|
|
process = GetCurrentProcess(); \
|
|
\
|
|
SymInitialize(process, NULL, TRUE); \
|
|
\
|
|
frames = CaptureStackBackTrace(0, STACKSIZE, stack, NULL); \
|
|
symbol = (SYMBOL_INFO *)calloc(sizeof(SYMBOL_INFO) + 256 * sizeof(char), 1); \
|
|
if (symbol != NULL) { \
|
|
symbol->MaxNameLen = 255; \
|
|
symbol->SizeOfStruct = sizeof(SYMBOL_INFO); \
|
|
\
|
|
if (frames > 0) { \
|
|
taosPrintLog(flags, level, dflag, "obtained %d stack frames\n", \
|
|
(ignoreNum > 0) ? frames - ignoreNum : frames); \
|
|
for (i = (ignoreNum > 0) ? ignoreNum : 0; i < frames; i++) { \
|
|
SymFromAddr(process, (DWORD64)(stack[i]), 0, symbol); \
|
|
taosPrintLog(flags, level, dflag, "frame:%i, %s - 0x%0X\n", (ignoreNum > 0) ? i - ignoreNum : i, \
|
|
symbol->Name, symbol->Address); \
|
|
} \
|
|
} \
|
|
free(symbol); \
|
|
} \
|
|
}
|
|
#endif
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif /*_TD_OS_SYSTEM_H_*/
|