MySQL 8.0.32
Source Code Documentation
gcs_debug.h
Go to the documentation of this file.
1/* Copyright (c) 2016, 2022, Oracle and/or its affiliates.
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
26#include "xcom/xcom_common.h"
27
28#include "xcom/x_platform.h"
29
30#ifdef TASK_DBUG_ON
31#error "TASK_DBUG_ON already defined"
32#else
33#define TASK_DBUG_ON 0
34#endif
35
36#define TX_FMT "{" SY_FMT_DEF " %" PRIu32 "}"
37#define TX_MEM(x) SY_MEM((x).cfg), (x).pc
38
39#include <stdio.h>
40#include <stdlib.h>
41
42double task_now();
43
44#ifdef DBGOUT
45#error "DBGOUT defined"
46#endif
47
48#include "xcom/xcom_logger.h"
49
50#ifndef XCOM_STANDALONE
51#include "my_compiler.h"
52#endif
53
54/**
55 Callbacks used in the logging macros.
56*/
57
61
62/**
63 Define the set of debug and trace options that are enabled if there
64 is no debugger check injected.
65*/
66extern int64_t xcom_debug_options;
67
68/**
69 Concatenates two strings and returns pointer to last character of final
70 string, allowing further concatenations without having to cycle through the
71 entire string again.
72
73 @param dest pointer to last character of destination string
74 @param size pointer to the number of characters currently added to
75 xcom_log_buffer
76 @param src pointer to the string to append to dest
77 @return pointer to the last character of destination string after appending
78 dest, which corresponds to the position of the '\0' character
79*/
80
81char *mystrcat(char *dest, int *size, const char *src);
82
83/**
84 This function allocates a new string where the format string and optional
85 arguments are rendered to.
86 Finally, it invokes mystr_cat to concatenate the rendered string to the
87 string received in the first parameter.
88*/
89
90char *mystrcat_sprintf(char *dest, int *size, const char *format, ...)
91 MY_ATTRIBUTE((format(printf, 3, 4)));
92
93#define STR_SIZE 2047
94
95#define GET_GOUT \
96 char xcom_log_buffer[STR_SIZE + 1]; \
97 char *xcom_temp_buf = xcom_log_buffer; \
98 int xcom_log_buffer_size = 0; \
99 xcom_log_buffer[0] = 0
100#define GET_NEW_GOUT \
101 char *xcom_log_buffer = (char *)malloc((STR_SIZE + 1) * sizeof(char)); \
102 char *xcom_temp_buf = xcom_log_buffer; \
103 int xcom_log_buffer_size = 0; \
104 xcom_log_buffer[0] = 0
105#define FREE_GOUT xcom_log_buffer[0] = 0
106#define ADD_GOUT(s) \
107 xcom_temp_buf = mystrcat(xcom_temp_buf, &xcom_log_buffer_size, s)
108#define COPY_AND_FREE_GOUT(s) \
109 { \
110 char *__funny = s; \
111 ADD_GOUT(__funny); \
112 free(__funny); \
113 }
114#define ADD_F_GOUT(...) \
115 xcom_temp_buf = \
116 mystrcat_sprintf(xcom_temp_buf, &xcom_log_buffer_size, __VA_ARGS__)
117#define PRINT_LOUT(level) xcom_log(level, xcom_log_buffer)
118#define PRINT_GOUT xcom_debug("%s", xcom_log_buffer)
119#define RET_GOUT return xcom_log_buffer
120
121#define G_LOG_LEVEL(level, ...) \
122 { \
123 GET_GOUT; \
124 ADD_F_GOUT(__VA_ARGS__); \
125 PRINT_LOUT(level); \
126 FREE_GOUT; \
127 }
128
129#ifndef XCOM_STANDALONE
130#define G_DEBUG_LEVEL(level, ...) \
131 { \
132 if (IS_XCOM_DEBUG_WITH(level)) { \
133 xcom_debug(__VA_ARGS__); \
134 } \
135 }
136#else
137#define G_DEBUG_LEVEL(level, ...) \
138 { \
139 if (IS_XCOM_DEBUG_WITH(level)) { \
140 GET_GOUT; \
141 ADD_F_GOUT(__VA_ARGS__); \
142 PRINT_GOUT; \
143 FREE_GOUT; \
144 } \
145 }
146#endif /* XCOM_STANDALONE */
147
148#define g_critical(...) G_LOG_LEVEL(XCOM_LOG_FATAL, __VA_ARGS__)
149#define G_ERROR(...) G_LOG_LEVEL(XCOM_LOG_ERROR, __VA_ARGS__)
150#define G_WARNING(...) G_LOG_LEVEL(XCOM_LOG_WARN, __VA_ARGS__)
151#define G_MESSAGE(...) G_LOG_LEVEL(XCOM_LOG_INFO, __VA_ARGS__)
152#define G_INFO(...) G_LOG_LEVEL(XCOM_LOG_INFO, __VA_ARGS__)
153#define G_DEBUG(...) \
154 G_DEBUG_LEVEL(XCOM_DEBUG_BASIC | XCOM_DEBUG_TRACE, __VA_ARGS__)
155#define G_TRACE(...) G_DEBUG_LEVEL(XCOM_DEBUG_TRACE, __VA_ARGS__)
156#define IS_XCOM_DEBUG_WITH(level) xcom_debug_check(level)
157
158#ifdef IDENTIFY
159#error "IDENTIFY already defined!"
160#else
161#define IDENTIFY
162#endif
163
164#ifdef DBG_IDENTIFY
165#error "DBG_IDENTIFY already defined!"
166#else
167#define DBG_IDENTIFY
168#endif
169
170#define BIT(n) (1L << n)
171
176 D_FSM = BIT(2),
181 D_XDR = BIT(7),
188 D_CONS = BIT(14),
189 D_BUG = ~0L
192
193enum { DBG_STACK_SIZE = 256 };
194extern long xcom_debug_mask;
195extern long xcom_dbg_stack[DBG_STACK_SIZE];
196extern int xcom_dbg_stack_top;
197
198static inline int do_dbg(xcom_dbg_type x) { return (x & xcom_debug_mask) != 0; }
199static inline void set_dbg(xcom_dbg_type x) { xcom_debug_mask |= x; }
200static inline void unset_dbg(xcom_dbg_type x) { xcom_debug_mask &= ~x; }
201static inline long get_dbg() { return xcom_debug_mask; }
202
203static inline void push_dbg(long x) {
207 xcom_debug_mask = x;
208 }
209}
210
211static inline void pop_dbg() {
212 if (xcom_dbg_stack_top > 0) {
215 }
216}
217
218#ifdef INFO
219#error "INFO already defined!"
220#else
221#define INFO(x) \
222 do { \
223 GET_GOUT; \
224 ADD_F_GOUT("%f ", task_now()); \
225 x; \
226 PRINT_LOUT(XCOM_LOG_INFO); \
227 FREE_GOUT; \
228 } while (0)
229#endif
230
231#if TASK_DBUG_ON
232
233#define DBGOUT(x) \
234 do { \
235 if (IS_XCOM_DEBUG_WITH(XCOM_DEBUG_TRACE)) { \
236 GET_GOUT; \
237 ADD_F_GOUT("%f ", task_now()); \
238 x; \
239 PRINT_GOUT; \
240 FREE_GOUT; \
241 } \
242 } while (0)
243#define NEW_DBG(x) \
244 long dbg_save = get_dbg(); \
245 set_dbg(x)
246#define RESTORE_DBG set_dbg(dbg_save)
247
248#ifdef IFDBG
249#error "IFDBG already defined!"
250#else
251#define IFDBG(mask, body) \
252 { \
253 if (do_dbg(mask)) DBGOUT(body); \
254 }
255#endif
256
257#ifdef DBGOUT_ASSERT
258#error "DBGOUT_ASSERT already defined"
259#else
260#define DBGOUT_ASSERT(expr, dbginfo) \
261 if (!(expr)) { \
262 GET_GOUT; \
263 FN; \
264 dbginfo; \
265 PRINT_LOUT(XCOM_LOG_ERROR); \
266 FREE_GOUT; \
267 abort(); \
268 }
269#endif
270
271#else
272
273#define DBGOUT(x) \
274 do { \
275 } while (0)
276#define DBGOUT_ASSERT(expr, dbginfo)
277#define NEW_DBG(x)
278#define IFDBG(mask, body)
279#endif
280
281#include <sys/types.h>
282#ifndef _WIN32
283#include <unistd.h>
284#endif
285
286static inline int xpid() {
287 static int pid = 0;
288 if (!pid) pid = getpid();
289 return pid;
290}
291
292#ifdef _WIN32
293static inline char const *fixpath(char const *x) {
294 char const *s = strrchr(x, '\\');
295 return s ? s + 1 : x;
296}
297#else
298static inline char const *fixpath(char const *x) {
299 char const *s = strrchr(x, '/');
300 return s ? s + 1 : x;
301}
302#endif
303
304extern uint32_t get_my_xcom_id();
305
306#define XDBG #error
307#define FN \
308 ADD_GOUT(__func__); \
309 ADD_F_GOUT(" pid %d xcom_id %x %s:%d ", xpid(), get_my_xcom_id(), \
310 fixpath(__FILE__), __LINE__)
311#define PTREXP(x) ADD_F_GOUT(#x ": %p ", (void const*)(x))
312#define CONSTPTREXP(x) PTREXP(x)
313#define PPUT(x) ADD_F_GOUT("0x%p ", (void *)(x))
314#define STREXP(x) ADD_F_GOUT(#x ": %s ", x)
315#define STRLIT(x) ADD_GOUT(x)
316#define NPUT(x, f) ADD_F_GOUT("%" #f " ", x)
317#define NDBG(x, f) \
318 ADD_F_GOUT(#x " = "); \
319 NPUT(x, f)
320#define NDBG64(x) \
321 ADD_F_GOUT(#x " = "); \
322 NPUT64(x);
323#define NPUT64(x) ADD_F_GOUT("%" PRIu64 " ", x)
324#define NEXP(x, f) ADD_F_GOUT(#x ": %" #f " ", x)
325#define NUMEXP(x) NEXP(x, d)
326#define g_strerror strerror
327#define LOUT(pri, x) ADD_F_GOUT(x);
328#define SYCEXP(exp) \
329 ADD_F_GOUT(#exp "={%x %" PRIu64 " %u} ", (exp).group_id, ((exp).msgno), \
330 ((exp).node))
331#define TIDCEXP(exp) \
332 ADD_F_GOUT(#exp "={%x %" PRIu64 " %u %u} ", (exp).cfg.group_id, \
333 (exp).cfg.msgno, (exp).cfg.node, (exp).pc)
334#define TIMECEXP(exp) ADD_F_GOUT(#exp "=%f sec ", (exp))
335#define BALCEXP(exp) ADD_F_GOUT(#exp "={%d %d} ", (exp).cnt, (exp).node)
336
337#endif /* GCS_DEBUG_H */
#define L
Definition: ctype-tis620.cc:75
@ DBG_STACK_SIZE
Definition: gcs_debug.h:193
static int xpid()
Definition: gcs_debug.h:286
uint32_t get_my_xcom_id()
Definition: xcom_base.cc:441
static long get_dbg()
Definition: gcs_debug.h:201
xcom_debugger xcom_debug
Definition: xcom_interface.cc:101
#define BIT(n)
Definition: gcs_debug.h:170
static char const * fixpath(char const *x)
Definition: gcs_debug.h:298
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.cc:77
static void set_dbg(xcom_dbg_type x)
Definition: gcs_debug.h:199
xcom_debugger_check xcom_debug_check
Definition: xcom_interface.cc:102
xcom_dbg_type
Definition: gcs_debug.h:172
@ D_TRANSPORT
Definition: gcs_debug.h:177
@ D_PROPOSE
Definition: gcs_debug.h:178
@ D_ALLOC
Definition: gcs_debug.h:185
@ D_STORE
Definition: gcs_debug.h:182
@ D_FSM
Definition: gcs_debug.h:176
@ D_BUG
Definition: gcs_debug.h:189
@ D_DETECT
Definition: gcs_debug.h:184
@ D_DISPATCH
Definition: gcs_debug.h:179
@ D_XDR
Definition: gcs_debug.h:181
@ D_EXEC
Definition: gcs_debug.h:183
@ D_SEMA
Definition: gcs_debug.h:180
@ D_CONS
Definition: gcs_debug.h:188
@ D_BASE
Definition: gcs_debug.h:175
@ D_NONE
Definition: gcs_debug.h:173
@ D_FILEOP
Definition: gcs_debug.h:186
@ D_CACHE
Definition: gcs_debug.h:187
@ D_TASK
Definition: gcs_debug.h:174
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.cc:103
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.cc:37
long xcom_dbg_stack[DBG_STACK_SIZE]
Definition: xcom_base.cc:415
int xcom_dbg_stack_top
Definition: xcom_base.cc:416
static void unset_dbg(xcom_dbg_type x)
Definition: gcs_debug.h:200
long xcom_debug_mask
Definition: xcom_base.cc:413
static void pop_dbg()
Definition: gcs_debug.h:211
double task_now()
Definition: task.cc:317
static void push_dbg(long x)
Definition: gcs_debug.h:203
xcom_logger xcom_log
Callbacks used in the logging macros.
Definition: xcom_interface.cc:100
static int do_dbg(xcom_dbg_type x)
Definition: gcs_debug.h:198
Header for compiler-dependent features.
int(* xcom_debugger_check)(const int64_t debug_options)
Definition: xcom_logger.h:78
void(* xcom_debugger)(const char *format,...)
Definition: xcom_logger.h:76
void(* xcom_logger)(const int64_t level, const char *message)
Definition: xcom_logger.h:75