MySQL  8.0.19
Source Code Documentation
gcs_debug.h
Go to the documentation of this file.
1 /* Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
2 
3  This program is free software; you can redistribute it and/or modify
4  it under the terms of the GNU General Public License, version 2.0,
5  as published by the Free Software Foundation.
6 
7  This program is also distributed with certain software (including
8  but not limited to OpenSSL) that is licensed under separate terms,
9  as designated in a particular file or component or in included license
10  documentation. The authors of MySQL hereby grant you an additional
11  permission to link the program and your derivative works with the
12  separately licensed software that they have included with MySQL.
13 
14  This program is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU General Public License, version 2.0, for more details.
18 
19  You should have received a copy of the GNU General Public License
20  along with this program; if not, write to the Free Software
21  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
22 
23 #ifndef GCS_DEBUG_H
24 #define GCS_DEBUG_H
25 
27 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 
33 
34 #ifdef TASK_DBUG_ON
35 #error "TASK_DBUG_ON already defined"
36 #else
37 #define TASK_DBUG_ON 0
38 #endif
39 
40 #define TX_FMT "{" SY_FMT_DEF " %lu}"
41 #define TX_MEM(x) SY_MEM((x).cfg), (x).pc
42 
43 #include <stdio.h>
44 #include <stdlib.h>
45 
46 double task_now();
47 
48 #ifdef DBGOUT
49 #error "DBGOUT defined"
50 #endif
51 
53 
54 #ifndef XCOM_STANDALONE
55 #include "my_compiler.h"
56 #endif
57 
58 /**
59  Callbacks used in the logging macros.
60 */
61 
62 extern xcom_logger xcom_log;
65 
66 /**
67  Prints the logging messages to the console. It is invoked when no logger
68  callback was set by an upper layer.
69 */
70 void xcom_default_log(const int64_t l, const char *msg);
71 
72 /**
73  Prints the logging messages to the console. It is invoked when no debugger
74  callback was set by an upper layer.
75 */
76 void xcom_default_debug(const char *format, ...)
77  MY_ATTRIBUTE((format(printf, 1, 2)));
78 
79 /**
80  Check whether a set of debug and trace options are enabled. It is invoked
81  when no debugger callback was set by an upper layer.
82 */
83 int xcom_default_debug_check(const int64_t options);
84 
85 /**
86  Define the set of debug and trace options that are enabled if there
87  is no debugger check injected.
88 */
89 extern int64_t xcom_debug_options;
90 
91 /**
92  Concatenates two strings and returns pointer to last character of final
93  string, allowing further concatenations without having to cycle through the
94  entire string again.
95 
96  @param dest pointer to last character of destination string
97  @param size pointer to the number of characters currently added to
98  xcom_log_buffer
99  @param src pointer to the string to append to dest
100  @return pointer to the last character of destination string after appending
101  dest, which corresponds to the position of the '\0' character
102 */
103 
104 char *mystrcat(char *dest, int *size, const char *src);
105 
106 /**
107  This function allocates a new string where the format string and optional
108  arguments are rendered to.
109  Finally, it invokes mystr_cat to concatenate the rendered string to the
110  string received in the first parameter.
111 */
112 
113 char *mystrcat_sprintf(char *dest, int *size, const char *format, ...)
114  MY_ATTRIBUTE((format(printf, 3, 4)));
115 
116 #define STR_SIZE 2047
117 
118 #define GET_GOUT \
119  char xcom_log_buffer[STR_SIZE + 1]; \
120  char *xcom_temp_buf = xcom_log_buffer; \
121  int xcom_log_buffer_size = 0; \
122  xcom_log_buffer[0] = 0
123 #define GET_NEW_GOUT \
124  char *xcom_log_buffer = (char *)malloc((STR_SIZE + 1) * sizeof(char)); \
125  char *xcom_temp_buf = xcom_log_buffer; \
126  int xcom_log_buffer_size = 0; \
127  xcom_log_buffer[0] = 0
128 #define FREE_GOUT xcom_log_buffer[0] = 0
129 #define ADD_GOUT(s) \
130  xcom_temp_buf = mystrcat(xcom_temp_buf, &xcom_log_buffer_size, s)
131 #define COPY_AND_FREE_GOUT(s) \
132  { \
133  char *__funny = s; \
134  ADD_GOUT(__funny); \
135  free(__funny); \
136  }
137 #define ADD_F_GOUT(...) \
138  xcom_temp_buf = \
139  mystrcat_sprintf(xcom_temp_buf, &xcom_log_buffer_size, __VA_ARGS__)
140 #define PRINT_LOUT(level) xcom_log(level, xcom_log_buffer)
141 #define PRINT_GOUT xcom_debug("%s", xcom_log_buffer)
142 #define RET_GOUT return xcom_log_buffer
143 
144 #define G_LOG_LEVEL(level, ...) \
145  { \
146  GET_GOUT; \
147  ADD_F_GOUT(__VA_ARGS__); \
148  PRINT_LOUT(level); \
149  FREE_GOUT; \
150  }
151 
152 #ifndef XCOM_STANDALONE
153 #define G_DEBUG_LEVEL(level, ...) \
154  { \
155  if (IS_XCOM_DEBUG_WITH(level)) { \
156  xcom_debug(__VA_ARGS__); \
157  } \
158  }
159 #else
160 #define G_DEBUG_LEVEL(level, ...) \
161  { \
162  if (IS_XCOM_DEBUG_WITH(level)) { \
163  GET_GOUT; \
164  ADD_F_GOUT(__VA_ARGS__); \
165  PRINT_GOUT; \
166  FREE_GOUT; \
167  } \
168  }
169 #endif /* XCOM_STANDALONE */
170 
171 #define g_critical(...) G_LOG_LEVEL(XCOM_LOG_FATAL, __VA_ARGS__)
172 #define G_ERROR(...) G_LOG_LEVEL(XCOM_LOG_ERROR, __VA_ARGS__)
173 #define G_WARNING(...) G_LOG_LEVEL(XCOM_LOG_WARN, __VA_ARGS__)
174 #define G_MESSAGE(...) G_LOG_LEVEL(XCOM_LOG_INFO, __VA_ARGS__)
175 #define G_INFO(...) G_LOG_LEVEL(XCOM_LOG_INFO, __VA_ARGS__)
176 #define G_DEBUG(...) \
177  G_DEBUG_LEVEL(XCOM_DEBUG_BASIC | XCOM_DEBUG_TRACE, __VA_ARGS__)
178 #define G_TRACE(...) G_DEBUG_LEVEL(XCOM_DEBUG_TRACE, __VA_ARGS__)
179 #define IS_XCOM_DEBUG_WITH(level) xcom_debug_check(level)
180 
181 #if TASK_DBUG_ON
182 #define DBGOHK(x) \
183  do { \
184  if (IS_XCOM_DEBUG_WITH(XCOM_DEBUG_TRACE)) { \
185  GET_GOUT; \
186  ADD_F_GOUT("%f ", task_now()); \
187  NEXP(get_nodeno(get_site_def()), u); \
188  x; \
189  PRINT_GOUT; \
190  FREE_GOUT; \
191  } \
192  } while (0)
193 #define DBGOUT(x) \
194  do { \
195  if (IS_XCOM_DEBUG_WITH(XCOM_DEBUG_TRACE)) { \
196  GET_GOUT; \
197  ADD_F_GOUT("%f ", task_now()); \
198  x; \
199  PRINT_GOUT; \
200  FREE_GOUT; \
201  } \
202  } while (0)
203 #define MAY_DBG(x) DBGOUT(x)
204 #else
205 #define DBGOHK(x) \
206  do { \
207  } while (0)
208 #define DBGOUT(x) \
209  do { \
210  } while (0)
211 #define MAY_DBG(x) \
212  do { \
213  } while (0)
214 #endif
215 
216 #define XDBG #error
217 #define FN \
218  ADD_GOUT(__func__); \
219  ADD_F_GOUT(" " __FILE__ ":%d ", __LINE__)
220 #define PTREXP(x) ADD_F_GOUT(#x ": %p ", (void *)(x))
221 #define PPUT(x) ADD_F_GOUT("0x%p ", (void *)(x))
222 #define STREXP(x) ADD_F_GOUT(#x ": %s ", x)
223 #define STRLIT(x) ADD_GOUT(x)
224 #define NPUT(x, f) ADD_F_GOUT("%" #f " ", x)
225 #define NDBG(x, f) \
226  ADD_F_GOUT(#x " = "); \
227  NPUT(x, f)
228 #define NDBG64(x) \
229  ADD_F_GOUT(#x " = "); \
230  NPUT64(x);
231 #define NPUT64(x) ADD_F_GOUT("%" PRIu64 " ", x)
232 #define NEXP(x, f) ADD_F_GOUT(#x ": %" #f " ", x)
233 #define NUMEXP(x) NEXP(x, d)
234 #define g_strerror strerror
235 #define LOUT(pri, x) ADD_F_GOUT(x);
236 #define SYCEXP(exp) \
237  ADD_F_GOUT(#exp "={%x %" PRIu64 " %u} ", (exp).group_id, ((exp).msgno), \
238  ((exp).node))
239 #define TIDCEXP(exp) \
240  ADD_F_GOUT(#exp "={%x %" PRIu64 " %u %u} ", (exp).cfg.group_id, \
241  (exp).cfg.msgno, (exp).cfg.node, (exp).pc)
242 #define TIMECEXP(exp) ADD_F_GOUT(#exp "=%f sec ", (exp))
243 #define BALCEXP(exp) ADD_F_GOUT(#exp "={%d %d} ", (exp).cnt, (exp).node)
244 
245 #ifdef __cplusplus
246 }
247 #endif /* __cplusplus */
248 #endif /* GCS_DEBUG_H */
xcom_default_log
void xcom_default_log(const int64_t l, const char *msg)
Prints the logging messages to the console.
Definition: task_debug.c:89
msg
char msg[1024]
Definition: test_sql_9_sessions.cc:281
xcom_debugger_check
int(* xcom_debugger_check)(const int64_t debug_options)
Definition: xcom_logger.h:81
xcom_logger.h
my_compiler.h
xcom_log
xcom_logger xcom_log
Callbacks used in the logging macros.
Definition: xcom_interface.c:53
xcom_logger
void(* xcom_logger)(const int64_t level, const char *message)
Definition: xcom_logger.h:78
xcom_debug
xcom_debugger xcom_debug
Definition: xcom_interface.c:54
xcom_debug_check
xcom_debugger_check xcom_debug_check
Definition: xcom_interface.c:55
task_now
double task_now()
Definition: task.c:306
xcom_default_debug_check
int xcom_default_debug_check(const int64_t options)
Check whether a set of debug and trace options are enabled.
Definition: task_debug.c:128
dd::info_schema::options
static const Query_options options
Definition: show_query_builder.cc:48
mystrcat_sprintf
char * mystrcat_sprintf(char *dest, int *size, const char *format,...)
This function allocates a new string where the format string and optional arguments are rendered to.
Definition: task_debug.c:75
x_platform.h
mystrcat
char * mystrcat(char *dest, int *size, const char *src)
Concatenates two strings and returns pointer to last character of final string, allowing further conc...
Definition: task_debug.c:33
xcom_debugger
void(* xcom_debugger)(const char *format,...)
Definition: xcom_logger.h:79
xcom_common.h
xcom_default_debug
void xcom_default_debug(const char *format,...)
Prints the logging messages to the console.
Definition: task_debug.c:110
xcom_debug_options
int64_t xcom_debug_options
Define the set of debug and trace options that are enabled if there is no debugger check injected.
Definition: xcom_interface.c:56