You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

144 lines
3.7 KiB

20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
  1. /*********************************************************************
  2. Debug utilities for Innobase
  3. (c) 1994, 1995 Innobase Oy
  4. Created 1/30/1994 Heikki Tuuri
  5. **********************************************************************/
  6. #ifndef ut0dbg_h
  7. #define ut0dbg_h
  8. #include "univ.i"
  9. #include <stdlib.h>
  10. #include "os0thread.h"
  11. #if defined(__GNUC__) && (__GNUC__ > 2)
  12. # define UT_DBG_FAIL(EXPR) UNIV_UNLIKELY(!((ulint)(EXPR)))
  13. #else
  14. extern ulint ut_dbg_zero; /* This is used to eliminate
  15. compiler warnings */
  16. # define UT_DBG_FAIL(EXPR) !((ulint)(EXPR) + ut_dbg_zero)
  17. #endif
  18. /*****************************************************************
  19. Report a failed assertion. */
  20. UNIV_INTERN
  21. void
  22. ut_dbg_assertion_failed(
  23. /*====================*/
  24. const char* expr, /* in: the failed assertion */
  25. const char* file, /* in: source file containing the assertion */
  26. ulint line); /* in: line number of the assertion */
  27. #ifdef __NETWARE__
  28. /* Flag for ignoring further assertion failures.
  29. On NetWare, have a graceful exit rather than a segfault to avoid abends. */
  30. extern ibool panic_shutdown;
  31. /* Abort the execution. */
  32. void ut_dbg_panic(void);
  33. # define UT_DBG_PANIC ut_dbg_panic()
  34. /* Stop threads in ut_a(). */
  35. # define UT_DBG_STOP while (0) /* We do not do this on NetWare */
  36. #else /* __NETWARE__ */
  37. # if defined(__WIN__) || defined(__INTEL_COMPILER)
  38. # undef UT_DBG_USE_ABORT
  39. # elif defined(__GNUC__) && (__GNUC__ > 2)
  40. # define UT_DBG_USE_ABORT
  41. # endif
  42. # ifndef UT_DBG_USE_ABORT
  43. /* A null pointer that will be dereferenced to trigger a memory trap */
  44. extern ulint* ut_dbg_null_ptr;
  45. # endif
  46. # if defined(UNIV_SYNC_DEBUG) || !defined(UT_DBG_USE_ABORT)
  47. /* Flag for indicating that all threads should stop. This will be set
  48. by ut_dbg_assertion_failed(). */
  49. extern ibool ut_dbg_stop_threads;
  50. /*****************************************************************
  51. Stop a thread after assertion failure. */
  52. UNIV_INTERN
  53. void
  54. ut_dbg_stop_thread(
  55. /*===============*/
  56. const char* file,
  57. ulint line);
  58. # endif
  59. # ifdef UT_DBG_USE_ABORT
  60. /* Abort the execution. */
  61. # define UT_DBG_PANIC abort()
  62. /* Stop threads (null operation) */
  63. # define UT_DBG_STOP while (0)
  64. # else /* UT_DBG_USE_ABORT */
  65. /* Abort the execution. */
  66. # define UT_DBG_PANIC \
  67. if (*(ut_dbg_null_ptr)) ut_dbg_null_ptr = NULL
  68. /* Stop threads in ut_a(). */
  69. # define UT_DBG_STOP do \
  70. if (UNIV_UNLIKELY(ut_dbg_stop_threads)) { \
  71. ut_dbg_stop_thread(__FILE__, (ulint) __LINE__); \
  72. } while (0)
  73. # endif /* UT_DBG_USE_ABORT */
  74. #endif /* __NETWARE__ */
  75. /* Abort execution if EXPR does not evaluate to nonzero. */
  76. #define ut_a(EXPR) do { \
  77. if (UT_DBG_FAIL(EXPR)) { \
  78. ut_dbg_assertion_failed(#EXPR, \
  79. __FILE__, (ulint) __LINE__); \
  80. UT_DBG_PANIC; \
  81. } \
  82. UT_DBG_STOP; \
  83. } while (0)
  84. /* Abort execution. */
  85. #define ut_error do { \
  86. ut_dbg_assertion_failed(0, __FILE__, (ulint) __LINE__); \
  87. UT_DBG_PANIC; \
  88. } while (0)
  89. #ifdef UNIV_DEBUG
  90. #define ut_ad(EXPR) ut_a(EXPR)
  91. #define ut_d(EXPR) do {EXPR;} while (0)
  92. #else
  93. #define ut_ad(EXPR)
  94. #define ut_d(EXPR)
  95. #endif
  96. #define UT_NOT_USED(A) A = A
  97. #ifdef UNIV_COMPILE_TEST_FUNCS
  98. #include <sys/types.h>
  99. #include <sys/time.h>
  100. #include <sys/resource.h>
  101. /* structure used for recording usage statistics */
  102. typedef struct speedo_struct {
  103. struct rusage ru;
  104. struct timeval tv;
  105. } speedo_t;
  106. /***********************************************************************
  107. Resets a speedo (records the current time in it). */
  108. UNIV_INTERN
  109. void
  110. speedo_reset(
  111. /*=========*/
  112. speedo_t* speedo); /* out: speedo */
  113. /***********************************************************************
  114. Shows the time elapsed and usage statistics since the last reset of a
  115. speedo. */
  116. UNIV_INTERN
  117. void
  118. speedo_show(
  119. /*========*/
  120. const speedo_t* speedo); /* in: speedo */
  121. #endif /* UNIV_COMPILE_TEST_FUNCS */
  122. #endif