my_dbug.h 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. /* Copyright (c) 2000, 2010, Oracle and/or its affiliates.
  2. Copyright (C) 2000-2011 Monty Program Ab
  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. This program is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9. GNU General Public License for more details.
  10. You should have received a copy of the GNU General Public License
  11. along with this program; if not, write to the Free Software
  12. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
  13. #ifndef _my_dbug_h
  14. #define _my_dbug_h
  15. #ifndef __WIN__
  16. #include <signal.h>
  17. #endif /* not __WIN__ */
  18. #ifdef __cplusplus
  19. extern "C" {
  20. #endif
  21. #if !defined(DBUG_OFF) && !defined(_lint)
  22. struct _db_stack_frame_ {
  23. const char *func; /* function name of the previous stack frame */
  24. const char *file; /* filename of the function of previous frame */
  25. uint level; /* this nesting level, highest bit enables tracing */
  26. int line; /* line of DBUG_RETURN */
  27. struct _db_stack_frame_ *prev; /* pointer to the previous frame */
  28. };
  29. struct _db_code_state_;
  30. extern my_bool _dbug_on_;
  31. extern my_bool _db_keyword_(struct _db_code_state_ *, const char *, int);
  32. extern int _db_explain_(struct _db_code_state_ *cs, char *buf, size_t len);
  33. extern int _db_explain_init_(char *buf, size_t len);
  34. extern int _db_is_pushed_(void);
  35. extern void _db_setjmp_(void);
  36. extern void _db_longjmp_(void);
  37. extern void _db_process_(const char *name);
  38. extern void _db_push_(const char *control);
  39. extern void _db_pop_(void);
  40. extern void _db_set_(const char *control);
  41. extern void _db_set_init_(const char *control);
  42. extern void _db_enter_(const char *_func_, const char *_file_, uint _line_,
  43. struct _db_stack_frame_ *_stack_frame_);
  44. extern void _db_return_(struct _db_stack_frame_ *_stack_frame_);
  45. extern void _db_pargs_(uint _line_,const char *keyword);
  46. extern void _db_doprnt_(const char *format,...)
  47. ATTRIBUTE_FORMAT(printf, 1, 2);
  48. extern void _db_dump_(uint _line_,const char *keyword,
  49. const unsigned char *memory, size_t length);
  50. extern void _db_end_(void);
  51. extern void _db_lock_file_(void);
  52. extern void _db_unlock_file_(void);
  53. extern FILE *_db_fp_(void);
  54. extern void _db_flush_(void);
  55. extern void dbug_swap_code_state(void **code_state_store);
  56. extern void dbug_free_code_state(void **code_state_store);
  57. extern const char* _db_get_func_(void);
  58. #define DBUG_LEAVE do { \
  59. _db_stack_frame_.line= __LINE__; \
  60. _db_return_ (&_db_stack_frame_); \
  61. _db_stack_frame_.line= 0; \
  62. } while(0)
  63. #ifdef HAVE_ATTRIBUTE_CLEANUP
  64. #define DBUG_ENTER(a) struct _db_stack_frame_ _db_stack_frame_ __attribute__((cleanup(_db_return_))); \
  65. _db_enter_ (a,__FILE__,__LINE__,&_db_stack_frame_)
  66. #define DBUG_RETURN(a1) do { _db_stack_frame_.line=__LINE__; return(a1);} while(0)
  67. #define DBUG_VOID_RETURN do { _db_stack_frame_.line=__LINE__; return;} while(0)
  68. #else
  69. #define DBUG_ENTER(a) struct _db_stack_frame_ _db_stack_frame_; \
  70. _db_enter_ (a,__FILE__,__LINE__,&_db_stack_frame_)
  71. #define DBUG_RETURN(a1) do {DBUG_LEAVE; return(a1);} while(0)
  72. #define DBUG_VOID_RETURN do {DBUG_LEAVE; return;} while(0)
  73. #endif
  74. #define DBUG_EXECUTE(keyword,a1) \
  75. do {if (_db_keyword_(0, (keyword), 0)) { a1 }} while(0)
  76. #define DBUG_EXECUTE_IF(keyword,a1) \
  77. do {if (_db_keyword_(0, (keyword), 1)) { a1 }} while(0)
  78. #define DBUG_EVALUATE(keyword,a1,a2) \
  79. (_db_keyword_(0,(keyword), 0) ? (a1) : (a2))
  80. #define DBUG_EVALUATE_IF(keyword,a1,a2) \
  81. (_db_keyword_(0,(keyword), 1) ? (a1) : (a2))
  82. #define DBUG_PRINT(keyword,arglist) \
  83. do {_db_pargs_(__LINE__,keyword); _db_doprnt_ arglist;} while(0)
  84. #define DBUG_PUSH(a1) _db_push_ (a1)
  85. #define DBUG_POP() _db_pop_ ()
  86. #define DBUG_SET(a1) _db_set_ (a1)
  87. #define DBUG_SET_INITIAL(a1) _db_set_init_ (a1)
  88. #define DBUG_PROCESS(a1) _db_process_(a1)
  89. #define DBUG_FILE _db_fp_()
  90. #define DBUG_DUMP(keyword,a1,a2) _db_dump_(__LINE__,keyword,a1,a2)
  91. #define DBUG_END() _db_end_ ()
  92. #define DBUG_LOCK_FILE _db_lock_file_()
  93. #define DBUG_UNLOCK_FILE _db_unlock_file_()
  94. #define DBUG_ASSERT(A) assert(A)
  95. #define DBUG_EXPLAIN(buf,len) _db_explain_(0, (buf),(len))
  96. #define DBUG_EXPLAIN_INITIAL(buf,len) _db_explain_init_((buf),(len))
  97. #define DEBUGGER_OFF do { _dbug_on_= 0; } while(0)
  98. #define DEBUGGER_ON do { _dbug_on_= 1; } while(0)
  99. #define IF_DBUG(A,B) A
  100. #define DBUG_SWAP_CODE_STATE(arg) dbug_swap_code_state(arg)
  101. #define DBUG_FREE_CODE_STATE(arg) dbug_free_code_state(arg)
  102. #ifndef __WIN__
  103. #define DBUG_ABORT() (_db_flush_(), abort())
  104. #else
  105. /*
  106. Avoid popup with abort/retry/ignore buttons. When BUG#31745 is fixed we can
  107. call abort() instead of _exit(3) (now it would cause a "test signal" popup).
  108. */
  109. #include <crtdbg.h>
  110. #define DBUG_ABORT() (_db_flush_(),\
  111. (void)_CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE),\
  112. (void)_CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR),\
  113. _exit(3))
  114. #endif
  115. /*
  116. Make the program fail, without creating a core file.
  117. abort() will send SIGABRT which (most likely) generates core.
  118. Use SIGKILL instead, which cannot be caught.
  119. We also pause the current thread, until the signal is actually delivered.
  120. An alternative would be to use _exit(EXIT_FAILURE),
  121. but then valgrind would report lots of memory leaks.
  122. */
  123. #ifdef __WIN__
  124. #define DBUG_SUICIDE() DBUG_ABORT()
  125. #else
  126. extern void _db_suicide_(void);
  127. #define DBUG_SUICIDE() (_db_flush_(), _db_suicide_())
  128. #endif
  129. #else /* No debugger */
  130. #define DBUG_ENTER(a1)
  131. #define DBUG_VIOLATION_HELPER_LEAVE do { } while(0)
  132. #define DBUG_LEAVE
  133. #define DBUG_RETURN(a1) do { return(a1); } while(0)
  134. #define DBUG_VOID_RETURN do { return; } while(0)
  135. #define DBUG_EXECUTE(keyword,a1) do { } while(0)
  136. #define DBUG_EXECUTE_IF(keyword,a1) do { } while(0)
  137. #define DBUG_EVALUATE(keyword,a1,a2) (a2)
  138. #define DBUG_EVALUATE_IF(keyword,a1,a2) (a2)
  139. #define DBUG_PRINT(keyword,arglist) do { } while(0)
  140. #define DBUG_PUSH(a1) do { } while(0)
  141. #define DBUG_SET(a1) do { } while(0)
  142. #define DBUG_SET_INITIAL(a1) do { } while(0)
  143. #define DBUG_POP() do { } while(0)
  144. #define DBUG_PROCESS(a1) do { } while(0)
  145. #define DBUG_DUMP(keyword,a1,a2) do { } while(0)
  146. #define DBUG_END() do { } while(0)
  147. #define DBUG_ASSERT(A) do { } while(0)
  148. #define DBUG_LOCK_FILE do { } while(0)
  149. #define DBUG_FILE (stderr)
  150. #define DBUG_UNLOCK_FILE do { } while(0)
  151. #define DBUG_EXPLAIN(buf,len)
  152. #define DBUG_EXPLAIN_INITIAL(buf,len)
  153. #define DEBUGGER_OFF do { } while(0)
  154. #define DEBUGGER_ON do { } while(0)
  155. #define IF_DBUG(A,B) B
  156. #define DBUG_SWAP_CODE_STATE(arg) do { } while(0)
  157. #define DBUG_FREE_CODE_STATE(arg) do { } while(0)
  158. #define DBUG_ABORT() do { } while(0)
  159. #define DBUG_CRASH_ENTER(func)
  160. #define DBUG_CRASH_RETURN(val) do { return(val); } while(0)
  161. #define DBUG_CRASH_VOID_RETURN do { return; } while(0)
  162. #define DBUG_SUICIDE() do { } while(0)
  163. #endif
  164. #ifdef EXTRA_DEBUG
  165. /**
  166. Sync points allow us to force the server to reach a certain line of code
  167. and block there until the client tells the server it is ok to go on.
  168. The client tells the server to block with SELECT GET_LOCK()
  169. and unblocks it with SELECT RELEASE_LOCK(). Used for debugging difficult
  170. concurrency problems
  171. */
  172. #define DBUG_SYNC_POINT(lock_name,lock_timeout) \
  173. debug_sync_point(lock_name,lock_timeout)
  174. void debug_sync_point(const char* lock_name, uint lock_timeout);
  175. #else
  176. #define DBUG_SYNC_POINT(lock_name,lock_timeout)
  177. #endif /* EXTRA_DEBUG */
  178. #ifdef __cplusplus
  179. }
  180. #endif
  181. #endif /* _my_dbug_h */