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