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