9
3

my_dbug.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /* Copyright (C) 2000 MySQL AB
  2. This program is free software; you can redistribute it and/or modify
  3. it under the terms of the GNU General Public License as published by
  4. the Free Software Foundation; version 2 of the License.
  5. This program is distributed in the hope that it will be useful,
  6. but WITHOUT ANY WARRANTY; without even the implied warranty of
  7. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  8. GNU General Public License for more details.
  9. You should have received a copy of the GNU General Public License
  10. along with this program; if not, write to the Free Software
  11. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
  12. #ifndef _dbug_h
  13. #define _dbug_h
  14. #if defined(__cplusplus) && !defined(DBUG_OFF)
  15. class Dbug_violation_helper
  16. {
  17. public:
  18. inline Dbug_violation_helper() :
  19. _entered(TRUE)
  20. { }
  21. inline ~Dbug_violation_helper()
  22. {
  23. assert(!_entered);
  24. }
  25. inline void leave()
  26. {
  27. _entered= FALSE;
  28. }
  29. private:
  30. bool _entered;
  31. };
  32. #endif /* C++ */
  33. #ifdef __cplusplus
  34. extern "C" {
  35. #endif
  36. #if !defined(DBUG_OFF) && !defined(_lint)
  37. struct _db_code_state_;
  38. extern int _db_keyword_(struct _db_code_state_ *cs, const char *keyword);
  39. extern int _db_strict_keyword_(const char *keyword);
  40. extern int _db_explain_(struct _db_code_state_ *cs, char *buf, size_t len);
  41. extern int _db_explain_init_(char *buf, size_t len);
  42. extern void _db_setjmp_(void);
  43. extern void _db_longjmp_(void);
  44. extern void _db_process_(const char *name);
  45. extern void _db_push_(const char *control);
  46. extern void _db_pop_(void);
  47. extern void _db_set_(struct _db_code_state_ *cs, const char *control);
  48. extern void _db_set_init_(const char *control);
  49. extern void _db_enter_(const char *_func_,const char *_file_,uint _line_,
  50. const char **_sfunc_,const char **_sfile_,
  51. uint *_slevel_, char ***);
  52. extern void _db_return_(uint _line_,const char **_sfunc_,const char **_sfile_,
  53. uint *_slevel_);
  54. extern void _db_pargs_(uint _line_,const char *keyword);
  55. extern void _db_doprnt_ _VARARGS((const char *format,...))
  56. ATTRIBUTE_FORMAT(printf, 1, 2);
  57. extern void _db_dump_(uint _line_,const char *keyword,
  58. const unsigned char *memory, size_t length);
  59. extern void _db_end_(void);
  60. extern void _db_lock_file_(void);
  61. extern void _db_unlock_file_(void);
  62. extern FILE *_db_fp_(void);
  63. #ifdef __cplusplus
  64. #define DBUG_ENTER(a) \
  65. const char *_db_func_, *_db_file_; \
  66. uint _db_level_; \
  67. char **_db_framep_; \
  68. Dbug_violation_helper dbug_violation_helper; \
  69. _db_enter_ (a, __FILE__, __LINE__, &_db_func_, &_db_file_, \
  70. &_db_level_, &_db_framep_)
  71. #define DBUG_VIOLATION_HELPER_LEAVE dbug_violation_helper.leave()
  72. #else /* C */
  73. #define DBUG_ENTER(a) \
  74. const char *_db_func_, *_db_file_; \
  75. uint _db_level_; \
  76. char **_db_framep_; \
  77. _db_enter_ (a, __FILE__, __LINE__, &_db_func_, &_db_file_, \
  78. &_db_level_, &_db_framep_)
  79. #define DBUG_VIOLATION_HELPER_LEAVE do { } while(0)
  80. #endif /* C++ */
  81. #define DBUG_LEAVE \
  82. DBUG_VIOLATION_HELPER_LEAVE; \
  83. _db_return_ (__LINE__, &_db_func_, &_db_file_, &_db_level_)
  84. #define DBUG_RETURN(a1) do {DBUG_LEAVE; return(a1);} while(0)
  85. #define DBUG_VOID_RETURN do {DBUG_LEAVE; return;} while(0)
  86. #define DBUG_EXECUTE(keyword,a1) \
  87. do {if (_db_keyword_(0, (keyword))) { a1 }} while(0)
  88. #define DBUG_EXECUTE_IF(keyword,a1) \
  89. do {if (_db_strict_keyword_ (keyword)) { a1 } } while(0)
  90. #define DBUG_EVALUATE(keyword,a1,a2) \
  91. (_db_keyword_(0,(keyword)) ? (a1) : (a2))
  92. #define DBUG_EVALUATE_IF(keyword,a1,a2) \
  93. (_db_strict_keyword_((keyword)) ? (a1) : (a2))
  94. #define DBUG_PRINT(keyword,arglist) \
  95. do {_db_pargs_(__LINE__,keyword); _db_doprnt_ arglist;} while(0)
  96. #define DBUG_PUSH(a1) _db_push_ (a1)
  97. #define DBUG_POP() _db_pop_ ()
  98. #define DBUG_SET(a1) _db_set_ (0, (a1))
  99. #define DBUG_SET_INITIAL(a1) _db_set_init_ (a1)
  100. #define DBUG_PROCESS(a1) _db_process_(a1)
  101. #define DBUG_FILE _db_fp_()
  102. #define DBUG_SETJMP(a1) (_db_setjmp_ (), setjmp (a1))
  103. #define DBUG_LONGJMP(a1,a2) (_db_longjmp_ (), longjmp (a1, a2))
  104. #define DBUG_DUMP(keyword,a1,a2) _db_dump_(__LINE__,keyword,a1,a2)
  105. #define DBUG_END() _db_end_ ()
  106. #define DBUG_LOCK_FILE _db_lock_file_()
  107. #define DBUG_UNLOCK_FILE _db_unlock_file_()
  108. #define DBUG_ASSERT(A) assert(A)
  109. #define DBUG_EXPLAIN(buf,len) _db_explain_(0, (buf),(len))
  110. #define DBUG_EXPLAIN_INITIAL(buf,len) _db_explain_init_((buf),(len))
  111. #define IF_DBUG(A) A
  112. #else /* No debugger */
  113. #define DBUG_ENTER(a1)
  114. #define DBUG_LEAVE
  115. #define DBUG_VIOLATION_HELPER_LEAVE
  116. #define DBUG_RETURN(a1) do { return(a1); } while(0)
  117. #define DBUG_VOID_RETURN do { return; } while(0)
  118. #define DBUG_EXECUTE(keyword,a1) do { } while(0)
  119. #define DBUG_EXECUTE_IF(keyword,a1) do { } while(0)
  120. #define DBUG_EVALUATE(keyword,a1,a2) (a2)
  121. #define DBUG_EVALUATE_IF(keyword,a1,a2) (a2)
  122. #define DBUG_PRINT(keyword,arglist) do { } while(0)
  123. #define DBUG_PUSH(a1)
  124. #define DBUG_SET(a1) do { } while(0)
  125. #define DBUG_SET_INITIAL(a1) do { } while(0)
  126. #define DBUG_POP()
  127. #define DBUG_PROCESS(a1)
  128. #define DBUG_SETJMP(a1) setjmp(a1)
  129. #define DBUG_LONGJMP(a1) longjmp(a1)
  130. #define DBUG_DUMP(keyword,a1,a2) do { } while(0)
  131. #define DBUG_END()
  132. #define DBUG_ASSERT(A) do { } while(0)
  133. #define DBUG_LOCK_FILE
  134. #define DBUG_FILE (stderr)
  135. #define DBUG_UNLOCK_FILE
  136. #define DBUG_EXPLAIN(buf,len)
  137. #define DBUG_EXPLAIN_INITIAL(buf,len)
  138. #define IF_DBUG(A)
  139. #endif
  140. #ifdef __cplusplus
  141. }
  142. #endif
  143. #endif