-
Notifications
You must be signed in to change notification settings - Fork 2
/
ma_debug.h
114 lines (91 loc) · 3.64 KB
/
ma_debug.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/************************************************************************************
Copyright (C) 2013, 2015 MariaDB Corporation AB
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library 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. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not see <http://www.gnu.org/licenses>
or write to the Free Software Foundation, Inc.,
51 Franklin St., Fifth Floor, Boston, MA 02110, USA
*************************************************************************************/
#ifndef _ma_debug_h_
#define _ma_debug_h_
#define MA_DEBUG_FLAG 4
#ifndef WIN32
#include <time.h>
#endif
void ma_debug_print(my_bool ident, char *format, ...);
void ma_debug_print_error(MADB_Error *err);
void ma_debug_print_bytes(char *name, char *ptr, int len);
/* Debug is on for connection */
#define MDBUG_C_IS_ON(C) ((C) && (((MADB_Dbc*)(C))->Options & MA_DEBUG_FLAG))
/* Use the definition below for debug build on Windows, as Options is not exposed in the Data Source UI */
// #define MDBUG_C_IS_ON(C) ((C))
#ifdef WIN32
#define MDBUG_C_ENTER(C,A)\
if (MDBUG_C_IS_ON(C))\
{\
SYSTEMTIME st;\
GetSystemTime(&st);\
ma_debug_print(0, ">>> %d-%02d-%02d %02d:%02d:%02d --- %s (thread: %lu) ---", st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond, A, ((MADB_Dbc*)(C))->mariadb ? mysql_thread_id(((MADB_Dbc*)(C))->mariadb) : 0);\
}
#else
#define MDBUG_C_ENTER(C,A)\
if ((C) && (((MADB_Dbc*)(C))->Options & MA_DEBUG_FLAG))\
{\
time_t t = time(NULL);\
struct tm st= *gmtime(&t);\
ma_debug_print(0, ">>> %d-%02d-%02d %02d:%02d:%02d --- %s (thread: %d) ---", st.tm_year + 1900, st.tm_mon + 1, st.tm_mday, st.tm_hour, st.tm_min, st.tm_sec, A, ((MADB_Dbc*)(C))->mariadb ? mysql_thread_id(((MADB_Dbc*)(C))->mariadb) : 0);\
}
#endif
#define MDBUG_C_RETURN(C,A,E)\
if (MDBUG_C_IS_ON(C))\
{\
SQLRETURN _ret= (A);\
if (_ret && (E)->ReturnValue)\
ma_debug_print_error(E); \
ma_debug_print(0, "<<< --- end of function, returning %d ---", _ret); \
return _ret;\
}\
return (A);
#define MDBUG_C_PRINT(C, format, ...)\
if (MDBUG_C_IS_ON(C))\
ma_debug_print(1, format, __VA_ARGS__);
#define MDBUG_C_VOID_RETURN(C)\
if (MDBUG_C_IS_ON(C))\
ma_debug_print(0, "<<< --- end of function ---");\
return;
#define MDBUG_C_DUMP(C,A,B)\
if (MDBUG_C_IS_ON(C))\
ma_debug_print(1, #A ":\t%" #B, A);
#define MDBUG_C_DUMP_HEX(C,A,L)\
if (MDBUG_C_IS_ON(C))\
ma_debug_print_bytes("Buffer bytes: ", A, L)
/* These macros will be used to force debug output
for functions without a DBC handle */
#ifndef MA_ODBC_DEBUG_ALL
#define MDBUG_ENTER(A) {}
#define MDBUG_RETURN(A) return (A)
#define MDBUG_PRINT(format, args) {}
#define MDBUG_VOID_RETURN() {}
#define MDBUG_DUMP(B,C) {}
#else
#define MDBUG_ENTER(A)\
ma_debug_print(0, ">>> --- %s ---", A);
#define MDBUG_RETURN(A)\
ma_debug_print(0, "<<< .. end of function ---");\
return (A);
#define MDBUG_PRINT(format, ...)\
ma_debug_print(1, format, __VA_ARGS__);
#define MDBUG_VOID_RETURN()\
ma_debug_print(0, "<<< --- end of function ---");\
return;
#define MDBUG_DUMP(A,B)\
ma_debug_print(1, #A ":\t%" #B, A);
#endif /* MA_ODBC_DEBUG_ALL */
#endif /* _ma_debug_h_ */