17
17
*****************************************************************************/
19
/*********************************************************************
19
/*****************************************************************//**
20
@file include/ut0dbg.h
20
21
Debug utilities for Innobase
22
23
Created 1/30/1994 Heikki Tuuri
30
31
#include "os0thread.h"
32
33
#if defined(__GNUC__) && (__GNUC__ > 2)
34
/** Test if an assertion fails.
35
@param EXPR assertion expression
36
@return nonzero if EXPR holds, zero if not */
33
37
# define UT_DBG_FAIL(EXPR) UNIV_UNLIKELY(!((ulint)(EXPR)))
35
extern ulint ut_dbg_zero; /* This is used to eliminate
39
/** This is used to eliminate compiler warnings */
40
extern ulint ut_dbg_zero;
41
/** Test if an assertion fails.
42
@param EXPR assertion expression
43
@return nonzero if EXPR holds, zero if not */
37
44
# define UT_DBG_FAIL(EXPR) !((ulint)(EXPR) + ut_dbg_zero)
40
/*****************************************************************
47
/*************************************************************//**
41
48
Report a failed assertion. */
44
51
ut_dbg_assertion_failed(
45
52
/*====================*/
46
const char* expr, /* in: the failed assertion */
47
const char* file, /* in: source file containing the assertion */
48
ulint line); /* in: line number of the assertion */
53
const char* expr, /*!< in: the failed assertion */
54
const char* file, /*!< in: source file containing the assertion */
55
ulint line); /*!< in: line number of the assertion */
51
/* Flag for ignoring further assertion failures.
52
On NetWare, have a graceful exit rather than a segfault to avoid abends. */
58
/** Flag for ignoring further assertion failures. This is set to TRUE
59
when on NetWare there happens an InnoDB assertion failure or other
60
fatal error condition that requires an immediate shutdown. */
53
61
extern ibool panic_shutdown;
54
62
/* Abort the execution. */
55
63
void ut_dbg_panic(void);
66
74
# ifndef UT_DBG_USE_ABORT
67
/* A null pointer that will be dereferenced to trigger a memory trap */
75
/** A null pointer that will be dereferenced to trigger a memory trap */
68
76
extern ulint* ut_dbg_null_ptr;
71
79
# if defined(UNIV_SYNC_DEBUG) || !defined(UT_DBG_USE_ABORT)
72
/* Flag for indicating that all threads should stop. This will be set
73
by ut_dbg_assertion_failed(). */
80
/** If this is set to TRUE by ut_dbg_assertion_failed(), all threads
81
will stop at the next ut_a() or ut_ad(). */
74
82
extern ibool ut_dbg_stop_threads;
76
/*****************************************************************
84
/*************************************************************//**
77
85
Stop a thread after assertion failure. */
86
94
# ifdef UT_DBG_USE_ABORT
87
/* Abort the execution. */
95
/** Abort the execution. */
88
96
# define UT_DBG_PANIC abort()
89
/* Stop threads (null operation) */
97
/** Stop threads (null operation) */
90
98
# define UT_DBG_STOP do {} while (0)
91
99
# else /* UT_DBG_USE_ABORT */
92
/* Abort the execution. */
100
/** Abort the execution. */
93
101
# define UT_DBG_PANIC \
94
102
if (*(ut_dbg_null_ptr)) ut_dbg_null_ptr = NULL
95
/* Stop threads in ut_a(). */
103
/** Stop threads in ut_a(). */
96
104
# define UT_DBG_STOP do \
97
105
if (UNIV_UNLIKELY(ut_dbg_stop_threads)) { \
98
106
ut_dbg_stop_thread(__FILE__, (ulint) __LINE__); \
100
108
# endif /* UT_DBG_USE_ABORT */
101
109
#endif /* __NETWARE__ */
103
/* Abort execution if EXPR does not evaluate to nonzero. */
111
/** Abort execution if EXPR does not evaluate to nonzero.
112
@param EXPR assertion expression that should hold */
104
113
#define ut_a(EXPR) do { \
105
114
if (UT_DBG_FAIL(EXPR)) { \
106
115
ut_dbg_assertion_failed(#EXPR, \
113
/* Abort execution. */
122
/** Abort execution. */
114
123
#define ut_error do { \
115
124
ut_dbg_assertion_failed(0, __FILE__, (ulint) __LINE__); \
119
128
#ifdef UNIV_DEBUG
129
/** Debug assertion. Does nothing unless UNIV_DEBUG is defined. */
120
130
#define ut_ad(EXPR) ut_a(EXPR)
131
/** Debug statement. Does nothing unless UNIV_DEBUG is defined. */
121
132
#define ut_d(EXPR) do {EXPR;} while (0)
134
/** Debug assertion. Does nothing unless UNIV_DEBUG is defined. */
123
135
#define ut_ad(EXPR)
136
/** Debug statement. Does nothing unless UNIV_DEBUG is defined. */
124
137
#define ut_d(EXPR)
140
/** Silence warnings about an unused variable by doing a null assignment.
141
@param A the unused variable */
127
142
#define UT_NOT_USED(A) A = A
129
144
#ifdef UNIV_COMPILE_TEST_FUNCS
132
147
#include <sys/time.h>
133
148
#include <sys/resource.h>
135
/* structure used for recording usage statistics */
150
/** structure used for recording usage statistics */
136
151
typedef struct speedo_struct {
152
struct rusage ru; /*!< getrusage() result */
153
struct timeval tv; /*!< gettimeofday() result */
141
/***********************************************************************
156
/*******************************************************************//**
142
157
Resets a speedo (records the current time in it). */
147
speedo_t* speedo); /* out: speedo */
162
speedo_t* speedo); /*!< out: speedo */
149
/***********************************************************************
164
/*******************************************************************//**
150
165
Shows the time elapsed and usage statistics since the last reset of a
156
const speedo_t* speedo); /* in: speedo */
171
const speedo_t* speedo); /*!< in: speedo */
158
173
#endif /* UNIV_COMPILE_TEST_FUNCS */