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