MySQL  8.0.16
Source Code Documentation
my_dbug.h
Go to the documentation of this file.
1 /* Copyright (c) 2000, 2019, 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 MY_DBUG_INCLUDED
24 #define MY_DBUG_INCLUDED
25 
26 /**
27  @file include/my_dbug.h
28 */
29 
30 #ifdef MY_MSCRT_DEBUG
31 #include <crtdbg.h>
32 #endif
33 #include <stdlib.h>
34 
35 #include "my_compiler.h"
36 
37 #if !defined(DBUG_OFF)
38 #include <assert.h> // IWYU pragma: keep
39 #include <stdio.h>
40 #endif
41 
42 #if !defined(DBUG_OFF)
43 
45  const char *func; /* function name of the previous stack frame */
46  const char *file; /* filename of the function of previous frame */
47  unsigned int level; /* this nesting level, highest bit enables tracing */
48  struct _db_stack_frame_ *prev; /* pointer to the previous frame */
49 };
50 
51 struct CODE_STATE;
52 
53 extern int _db_keyword_(struct CODE_STATE *, const char *, int);
54 extern int _db_explain_(struct CODE_STATE *cs, char *buf, size_t len);
55 extern int _db_explain_init_(char *buf, size_t len);
56 extern int _db_is_pushed_(void);
57 extern void _db_process_(const char *name);
58 extern void _db_push_(const char *control);
59 extern void _db_pop_(void);
60 extern void _db_set_(const char *control);
61 extern void _db_set_init_(const char *control);
62 extern void _db_enter_(const char *_func_, const char *_file_,
63  unsigned int _line_,
64  struct _db_stack_frame_ *_stack_frame_);
65 extern void _db_return_(unsigned int _line_,
66  struct _db_stack_frame_ *_stack_frame_);
67 extern void _db_pargs_(unsigned int _line_, const char *keyword);
68 extern int _db_enabled_();
69 extern void _db_doprnt_(const char *format, ...)
70  MY_ATTRIBUTE((format(printf, 1, 2)));
71 extern void _db_dump_(unsigned int _line_, const char *keyword,
72  const unsigned char *memory, size_t length);
73 extern void _db_end_(void);
74 extern void _db_lock_file_(void);
75 extern void _db_unlock_file_(void);
76 extern FILE *_db_fp_(void);
77 extern void _db_flush_();
78 extern const char *_db_get_func_(void);
79 
80 #define DBUG_ENTER(a) \
81  struct _db_stack_frame_ _db_stack_frame_; \
82  _db_enter_(a, __FILE__, __LINE__, &_db_stack_frame_)
83 #define DBUG_LEAVE _db_return_(__LINE__, &_db_stack_frame_)
84 #define DBUG_RETURN(a1) \
85  do { \
86  DBUG_LEAVE; \
87  return (a1); \
88  } while (0)
89 #define DBUG_VOID_RETURN \
90  do { \
91  DBUG_LEAVE; \
92  return; \
93  } while (0)
94 #define DBUG_EXECUTE(keyword, a1) \
95  do { \
96  if (_db_keyword_(0, (keyword), 0)) { \
97  a1 \
98  } \
99  } while (0)
100 #define DBUG_EXECUTE_IF(keyword, a1) \
101  do { \
102  if (_db_keyword_(0, (keyword), 1)) { \
103  a1 \
104  } \
105  } while (0)
106 #define DBUG_EVALUATE(keyword, a1, a2) \
107  (_db_keyword_(0, (keyword), 0) ? (a1) : (a2))
108 #define DBUG_EVALUATE_IF(keyword, a1, a2) \
109  (_db_keyword_(0, (keyword), 1) ? (a1) : (a2))
110 #define DBUG_PRINT(keyword, arglist) \
111  do { \
112  _db_pargs_(__LINE__, keyword); \
113  if (_db_enabled_()) { \
114  _db_doprnt_ arglist; \
115  } \
116  } while (0)
117 
118 #define DBUG_PUSH(a1) _db_push_(a1)
119 #define DBUG_POP() _db_pop_()
120 #define DBUG_SET(a1) _db_set_(a1)
121 #define DBUG_SET_INITIAL(a1) _db_set_init_(a1)
122 #define DBUG_PROCESS(a1) _db_process_(a1)
123 #define DBUG_FILE _db_fp_()
124 #define DBUG_DUMP(keyword, a1, a2) _db_dump_(__LINE__, keyword, a1, a2)
125 #define DBUG_END() _db_end_()
126 #define DBUG_LOCK_FILE _db_lock_file_()
127 #define DBUG_UNLOCK_FILE _db_unlock_file_()
128 #define DBUG_ASSERT(A) assert(A)
129 #define DBUG_EXPLAIN(buf, len) _db_explain_(0, (buf), (len))
130 #define DBUG_EXPLAIN_INITIAL(buf, len) _db_explain_init_((buf), (len))
131 #ifndef _WIN32
132 #define DBUG_ABORT() (_db_flush_(), abort())
133 #define DBUG_EXIT() (_db_flush_(), exit(2))
134 #else
135 #include <crtdbg.h>
136 
137 #define DBUG_ABORT() \
138  (_db_flush_(), (void)_CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE), \
139  (void)_CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR), abort())
140 #define DBUG_EXIT() \
141  (_db_flush_(), (void)_CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE), \
142  (void)_CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR), _exit(2))
143 #endif
144 
145 /*
146  Make the program fail, without creating a core file.
147  abort() will send SIGABRT which (most likely) generates core.
148  Use SIGKILL instead, which cannot be caught.
149  We also pause the current thread, until the signal is actually delivered.
150  An alternative would be to use _exit(EXIT_FAILURE),
151  but then valgrind would report lots of memory leaks.
152  */
153 #ifdef _WIN32
154 #define DBUG_SUICIDE() DBUG_EXIT()
155 #else
156 extern void _db_suicide_() MY_ATTRIBUTE((noreturn));
157 extern void _db_flush_gcov_();
158 #define DBUG_SUICIDE() (_db_flush_(), _db_suicide_())
159 #endif
160 
161 #else /* No debugger */
162 
163 #define DBUG_ENTER(a1)
164 #define DBUG_LEAVE
165 #define DBUG_RETURN(a1) \
166  do { \
167  return (a1); \
168  } while (0)
169 #define DBUG_VOID_RETURN \
170  do { \
171  return; \
172  } while (0)
173 #define DBUG_EXECUTE(keyword, a1) \
174  do { \
175  } while (0)
176 #define DBUG_EXECUTE_IF(keyword, a1) \
177  do { \
178  } while (0)
179 #define DBUG_EVALUATE(keyword, a1, a2) (a2)
180 #define DBUG_EVALUATE_IF(keyword, a1, a2) (a2)
181 #define DBUG_PRINT(keyword, arglist) \
182  do { \
183  } while (0)
184 #define DBUG_PUSH(a1) \
185  do { \
186  } while (0)
187 #define DBUG_SET(a1) \
188  do { \
189  } while (0)
190 #define DBUG_SET_INITIAL(a1) \
191  do { \
192  } while (0)
193 #define DBUG_POP() \
194  do { \
195  } while (0)
196 #define DBUG_PROCESS(a1) \
197  do { \
198  } while (0)
199 #define DBUG_DUMP(keyword, a1, a2) \
200  do { \
201  } while (0)
202 #define DBUG_END() \
203  do { \
204  } while (0)
205 #define DBUG_ASSERT(A) \
206  do { \
207  } while (0)
208 #define DBUG_LOCK_FILE \
209  do { \
210  } while (0)
211 #define DBUG_FILE (stderr)
212 #define DBUG_UNLOCK_FILE \
213  do { \
214  } while (0)
215 #define DBUG_EXPLAIN(buf, len)
216 #define DBUG_EXPLAIN_INITIAL(buf, len)
217 #define DBUG_ABORT() \
218  do { \
219  } while (0)
220 #define DBUG_SUICIDE() \
221  do { \
222  } while (0)
223 
224 #endif
225 
226 #ifdef __cplusplus
227 #if !defined(DBUG_OFF)
228 #include <sstream>
229 #include <string>
230 
231 /*
232  A C++ interface to the DBUG_PRINT macro. The DBUG_LOG macro takes two
233  arguments. The first argument is the keyword, as that of the
234  DBUG_PRINT. The 2nd argument 'v' will be passed to a C++ output stream.
235  This enables the use of C++ style output stream operator. In the code, it
236  will be used as follows:
237 
238  DBUG_LOG("blob", "space: " << space_id);
239 
240  Note: DBUG_PRINT() has a limitation of 1024 bytes for a single
241  print out. So, this limitation is there for DBUG_LOG macro also.
242 */
243 
244 #define DBUG_LOG(keyword, v) \
245  do { \
246  std::ostringstream sout; \
247  sout << v; \
248  DBUG_PRINT(keyword, ("%s", sout.str().c_str())); \
249  } while (0)
250 
251 void log_prefix(std::ostream &out);
252 void trace(const std::string &note);
253 void dump_trace();
254 
255 #define DBUG_TRACE(x) \
256  do { \
257  std::ostringstream sout; \
258  log_prefix(sout); \
259  sout << x; \
260  trace(sout.str()); \
261  } while (false)
262 
263 #else /* DBUG_OFF */
264 #define DBUG_LOG(keyword, v) \
265  do { \
266  } while (0)
267 #define DBUG_TRACE(x) \
268  do { \
269  } while (0)
270 #endif /* DBUG_OFF */
271 #endif /* __cplusplus */
272 
273 #endif /* MY_DBUG_INCLUDED */
void _db_return_(unsigned int _line_, struct _db_stack_frame_ *_stack_frame_)
Definition: dbug.cc:1185
struct _db_stack_frame_ * prev
Definition: my_dbug.h:48
void trace(const std::string &note)
Definition: trace.cc:57
const string name("\ame\)
void _db_end_(void)
Definition: dbug.cc:1651
int _db_explain_init_(char *buf, size_t len)
Definition: dbug.cc:1077
void _db_set_init_(const char *control)
Definition: dbug.cc:878
printf("== done ==\)
void _db_suicide_()
Definition: dbug.cc:2135
Definition: my_dbug.h:44
const std::string FILE("FILE")
void _db_pop_(void)
Definition: dbug.cc:903
void _db_flush_()
Definition: dbug.cc:2114
void _db_doprnt_(const char *format,...)
Definition: dbug.cc:1301
void _db_set_(const char *control)
Definition: dbug.cc:799
int _db_explain_(struct CODE_STATE *cs, char *buf, size_t len)
Definition: dbug.cc:1017
const char * file
Definition: my_dbug.h:46
void _db_pargs_(unsigned int _line_, const char *keyword)
Definition: dbug.cc:1241
void dump_trace()
Definition: trace.cc:69
Header for compiler-dependent features.
void log_prefix(std::ostream &out)
Definition: trace.cc:43
unsigned int len
Definition: dbug_analyze.cc:216
const char * func
Definition: my_dbug.h:45
void _db_dump_(unsigned int _line_, const char *keyword, const unsigned char *memory, size_t length)
Definition: dbug.cc:1359
void _db_enter_(const char *_func_, const char *_file_, unsigned int _line_, struct _db_stack_frame_ *_stack_frame_)
Definition: dbug.cc:1118
FILE * _db_fp_(void)
Definition: dbug.cc:1723
unsigned int level
Definition: my_dbug.h:47
void _db_unlock_file_(void)
Definition: dbug.cc:2165
void _db_push_(const char *control)
Definition: dbug.cc:835
void _db_lock_file_(void)
Definition: dbug.cc:2158
const char * _db_get_func_(void)
Definition: dbug.cc:2172
int _db_keyword_(struct CODE_STATE *, const char *, int)
Definition: dbug.cc:1749
int _db_enabled_()
Definition: dbug.cc:1265
Definition: dbug.cc:215
int _db_is_pushed_(void)
Returns true if session-local settings have been set.
Definition: dbug.cc:857
void _db_flush_gcov_()
Definition: dbug.cc:2126
bool length(const dd::Spatial_reference_system *srs, const Geometry *g1, double *length, bool *null) noexcept
Computes the length of linestrings and multilinestrings.
Definition: length.cc:75
void _db_process_(const char *name)
Definition: dbug.cc:396