MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
my_dbug.h
1 /* Copyright (c) 2000, 2012, 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 as published by
5  the Free Software Foundation; version 2 of the License.
6 
7  This program is distributed in the hope that it will be useful,
8  but WITHOUT ANY WARRANTY; without even the implied warranty of
9  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  GNU General Public License for more details.
11 
12  You should have received a copy of the GNU General Public License
13  along with this program; if not, write to the Free Software
14  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
15 
16 #ifndef MY_DBUG_INCLUDED
17 #define MY_DBUG_INCLUDED
18 
19 #ifndef __WIN__
20 #ifdef HAVE_SYS_TYPES_H
21 #include <sys/types.h>
22 #endif
23 #ifdef HAVE_UNISTD_H
24 #include <unistd.h>
25 #endif
26 #include <signal.h>
27 #endif /* not __WIN__ */
28 
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32 #if !defined(DBUG_OFF) && !defined(_lint)
33 
35  const char *func; /* function name of the previous stack frame */
36  const char *file; /* filename of the function of previous frame */
37  uint level; /* this nesting level, highest bit enables tracing */
38  struct _db_stack_frame_ *prev; /* pointer to the previous frame */
39 };
40 
41 struct _db_code_state_;
42 extern MYSQL_PLUGIN_IMPORT my_bool _dbug_on_;
43 extern my_bool _db_keyword_(struct _db_code_state_ *, const char *, int);
44 extern int _db_explain_(struct _db_code_state_ *cs, char *buf, size_t len);
45 extern int _db_explain_init_(char *buf, size_t len);
46 extern int _db_is_pushed_(void);
47 extern void _db_setjmp_(void);
48 extern void _db_longjmp_(void);
49 extern void _db_process_(const char *name);
50 extern void _db_push_(const char *control);
51 extern void _db_pop_(void);
52 extern void _db_set_(const char *control);
53 extern void _db_set_init_(const char *control);
54 extern void _db_enter_(const char *_func_, const char *_file_, uint _line_,
55  struct _db_stack_frame_ *_stack_frame_);
56 extern void _db_return_(uint _line_, struct _db_stack_frame_ *_stack_frame_);
57 extern void _db_pargs_(uint _line_,const char *keyword);
58 extern int _db_enabled_();
59 extern void _db_doprnt_(const char *format,...)
60  ATTRIBUTE_FORMAT(printf, 1, 2);
61 extern void _db_dump_(uint _line_,const char *keyword,
62  const unsigned char *memory, size_t length);
63 extern void _db_end_(void);
64 extern void _db_lock_file_(void);
65 extern void _db_unlock_file_(void);
66 extern FILE *_db_fp_(void);
67 extern void _db_flush_();
68 extern const char* _db_get_func_(void);
69 
70 #define DBUG_ENTER(a) struct _db_stack_frame_ _db_stack_frame_; \
71  _db_enter_ (a,__FILE__,__LINE__,&_db_stack_frame_)
72 #define DBUG_LEAVE _db_return_ (__LINE__, &_db_stack_frame_)
73 #define DBUG_RETURN(a1) do {DBUG_LEAVE; return(a1);} while(0)
74 #define DBUG_VOID_RETURN do {DBUG_LEAVE; return;} while(0)
75 #define DBUG_EXECUTE(keyword,a1) \
76  do {if (_db_keyword_(0, (keyword), 0)) { a1 }} while(0)
77 #define DBUG_EXECUTE_IF(keyword,a1) \
78  do {if (_db_keyword_(0, (keyword), 1)) { a1 }} while(0)
79 #define DBUG_EVALUATE(keyword,a1,a2) \
80  (_db_keyword_(0,(keyword), 0) ? (a1) : (a2))
81 #define DBUG_EVALUATE_IF(keyword,a1,a2) \
82  (_db_keyword_(0,(keyword), 1) ? (a1) : (a2))
83 #define DBUG_PRINT(keyword,arglist) \
84  do \
85  { \
86  if (_dbug_on_) \
87  { \
88  _db_pargs_(__LINE__,keyword); \
89  if (_db_enabled_()) \
90  { \
91  _db_doprnt_ arglist; \
92  } \
93  } \
94  } while(0)
95 #define DBUG_PUSH(a1) _db_push_ (a1)
96 #define DBUG_POP() _db_pop_ ()
97 #define DBUG_SET(a1) _db_set_ (a1)
98 #define DBUG_SET_INITIAL(a1) _db_set_init_ (a1)
99 #define DBUG_PROCESS(a1) _db_process_(a1)
100 #define DBUG_FILE _db_fp_()
101 #define DBUG_SETJMP(a1) (_db_setjmp_ (), setjmp (a1))
102 #define DBUG_LONGJMP(a1,a2) (_db_longjmp_ (), longjmp (a1, a2))
103 #define DBUG_DUMP(keyword,a1,a2) _db_dump_(__LINE__,keyword,a1,a2)
104 #define DBUG_END() _db_end_ ()
105 #define DBUG_LOCK_FILE _db_lock_file_()
106 #define DBUG_UNLOCK_FILE _db_unlock_file_()
107 #define DBUG_ASSERT(A) assert(A)
108 #define DBUG_EXPLAIN(buf,len) _db_explain_(0, (buf),(len))
109 #define DBUG_EXPLAIN_INITIAL(buf,len) _db_explain_init_((buf),(len))
110 #define DEBUGGER_OFF do { _dbug_on_= 0; } while(0)
111 #define DEBUGGER_ON do { _dbug_on_= 1; } while(0)
112 #ifndef __WIN__
113 #define DBUG_ABORT() (_db_flush_(), abort())
114 #else
115 /*
116  Avoid popup with abort/retry/ignore buttons. When BUG#31745 is fixed we can
117  call abort() instead of _exit(3) (now it would cause a "test signal" popup).
118 */
119 #include <crtdbg.h>
120 #define DBUG_ABORT() (_db_flush_(),\
121  (void)_CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE),\
122  (void)_CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR),\
123  _exit(3))
124 #endif
125 #define DBUG_CHECK_CRASH(func, op) \
126  do { char _dbuf_[255]; strxnmov(_dbuf_, sizeof(_dbuf_)-1, (func), (op)); \
127  DBUG_EXECUTE_IF(_dbuf_, DBUG_ABORT()); } while(0)
128 #define DBUG_CRASH_ENTER(func) \
129  DBUG_ENTER(func); DBUG_CHECK_CRASH(func, "_crash_enter")
130 #define DBUG_CRASH_RETURN(val) \
131  DBUG_CHECK_CRASH(_db_get_func_(), "_crash_return")
132 #define DBUG_CRASH_VOID_RETURN \
133  DBUG_CHECK_CRASH (_db_get_func_(), "_crash_return")
134 
135 /*
136  Make the program fail, without creating a core file.
137  abort() will send SIGABRT which (most likely) generates core.
138  Use SIGKILL instead, which cannot be caught.
139  We also pause the current thread, until the signal is actually delivered.
140  An alternative would be to use _exit(EXIT_FAILURE),
141  but then valgrind would report lots of memory leaks.
142  */
143 #ifdef __WIN__
144 #define DBUG_SUICIDE() DBUG_ABORT()
145 #else
146 extern void _db_suicide_();
147 extern void _db_flush_gcov_();
148 #define DBUG_SUICIDE() (_db_flush_(), _db_suicide_())
149 #endif
150 
151 #else /* No debugger */
152 
153 #define DBUG_ENTER(a1)
154 #define DBUG_LEAVE
155 #define DBUG_RETURN(a1) do { return(a1); } while(0)
156 #define DBUG_VOID_RETURN do { return; } while(0)
157 #define DBUG_EXECUTE(keyword,a1) do { } while(0)
158 #define DBUG_EXECUTE_IF(keyword,a1) do { } while(0)
159 #define DBUG_EVALUATE(keyword,a1,a2) (a2)
160 #define DBUG_EVALUATE_IF(keyword,a1,a2) (a2)
161 #define DBUG_PRINT(keyword,arglist) do { } while(0)
162 #define DBUG_PUSH(a1) do { } while(0)
163 #define DBUG_SET(a1) do { } while(0)
164 #define DBUG_SET_INITIAL(a1) do { } while(0)
165 #define DBUG_POP() do { } while(0)
166 #define DBUG_PROCESS(a1) do { } while(0)
167 #define DBUG_SETJMP(a1) setjmp(a1)
168 #define DBUG_LONGJMP(a1) longjmp(a1)
169 #define DBUG_DUMP(keyword,a1,a2) do { } while(0)
170 #define DBUG_END() do { } while(0)
171 #define DBUG_ASSERT(A) do { } while(0)
172 #define DBUG_LOCK_FILE do { } while(0)
173 #define DBUG_FILE (stderr)
174 #define DBUG_UNLOCK_FILE do { } while(0)
175 #define DBUG_EXPLAIN(buf,len)
176 #define DBUG_EXPLAIN_INITIAL(buf,len)
177 #define DEBUGGER_OFF do { } while(0)
178 #define DEBUGGER_ON do { } while(0)
179 #define DBUG_ABORT() do { } while(0)
180 #define DBUG_CRASH_ENTER(func)
181 #define DBUG_CRASH_RETURN(val) do { return(val); } while(0)
182 #define DBUG_CRASH_VOID_RETURN do { return; } while(0)
183 #define DBUG_SUICIDE() do { } while(0)
184 
185 #endif
186 
187 #ifdef EXTRA_DEBUG
188 
195 #define DBUG_SYNC_POINT(lock_name,lock_timeout) \
196  debug_sync_point(lock_name,lock_timeout)
197 void debug_sync_point(const char* lock_name, uint lock_timeout);
198 #else
199 #define DBUG_SYNC_POINT(lock_name,lock_timeout)
200 #endif /* EXTRA_DEBUG */
201 
202 #ifdef __cplusplus
203 }
204 #endif
205 
206 #endif /* MY_DBUG_INCLUDED */