#include "proxysql.h" #include "proxysql_atomic.h" #include #ifdef DEBUG #ifdef DEBUG_EXTERN #undef DEBUG_EXTERN #endif /* DEBUG_EXTERN */ #endif /* DEBUG */ #define PROXYSQL_DEBUG_PTHREAD_MUTEX #ifndef CLOCK_MONOTONIC #define CLOCK_MONOTONIC SYSTEM_CLOCK #endif // CLOCK_MONOTONIC #ifdef DEBUG static unsigned long long pretime=0; #ifdef PROXYSQL_DEBUG_PTHREAD_MUTEX static pthread_mutex_t debug_mutex; #else static spinlock debug_spinlock; #endif #endif /* DEBUG */ static inline unsigned long long debug_monotonic_time() { struct timespec ts; clock_gettime(CLOCK_MONOTONIC, &ts); return (((unsigned long long) ts.tv_sec) * 1000000) + (ts.tv_nsec / 1000); } #define DEBUG_MSG_MAXSIZE 1024 #ifdef DEBUG void proxy_debug_func(enum debug_module module, int verbosity, int thr, const char *__file, int __line, const char *__func, const char *fmt, ...) { assert(module=10) { void *arr[20]; char **strings; int s; s = backtrace(arr, 20); //backtrace_symbols_fd(arr, s, STDERR_FILENO); strings=backtrace_symbols(arr,s); if (strings == NULL) { perror("backtrace_symbols"); exit(EXIT_FAILURE); } for (int i=0; i 0) { ssize_t ret = write(fd, buf, len); if ((ret == -1) && (errno != EINTR)) break; buf += (size_t) ret; len -= (size_t) ret; } } void print_backtrace(void) { static const char start[] = "BACKTRACE ------------\n"; static const char end[] = "----------------------\n"; void *bt[1024]; int bt_size; char **bt_syms; int i; bt_size = backtrace(bt, 1024); bt_syms = backtrace_symbols(bt, bt_size); full_write(STDERR_FILENO, start, strlen(start)); for (i = 1; i < bt_size; i++) { size_t len = strlen(bt_syms[i]); full_write(STDERR_FILENO, bt_syms[i], len); full_write(STDERR_FILENO, "\n", 1); } full_write(STDERR_FILENO, end, strlen(end)); free(bt_syms); } #ifdef DEBUG void init_debug_struct() { int i; #ifdef PROXYSQL_DEBUG_PTHREAD_MUTEX pthread_mutex_init(&debug_mutex,NULL); #else spinlock_init(&debug_spinlock); #endif pretime=debug_monotonic_time(); GloVars.global.gdbg_lvl= (debug_level *) malloc(PROXY_DEBUG_UNKNOWN*sizeof(debug_level)); for (i=0;i