1
/*****************************************************************************
3
Copyright (c) 1994, 2009, Innobase Oy. All Rights Reserved.
5
This program is free software; you can redistribute it and/or modify it under
6
the terms of the GNU General Public License as published by the Free Software
7
Foundation; version 2 of the License.
9
This program is distributed in the hope that it will be useful, but WITHOUT
10
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
13
You should have received a copy of the GNU General Public License along with
14
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
15
Place, Suite 330, Boston, MA 02111-1307 USA
17
*****************************************************************************/
19
/*****************************************************************//**
20
@file include/ut0dbg.h
21
Debug utilities for Innobase
23
Created 1/30/1994 Heikki Tuuri
24
**********************************************************************/
31
#include "os0thread.h"
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 */
37
# define UT_DBG_FAIL(EXPR) UNIV_UNLIKELY(!((ulint)(EXPR)))
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 */
44
# define UT_DBG_FAIL(EXPR) !((ulint)(EXPR) + ut_dbg_zero)
47
/*************************************************************//**
48
Report a failed assertion. */
51
ut_dbg_assertion_failed(
52
/*====================*/
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 */
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. */
61
extern ibool panic_shutdown;
62
/* Abort the execution. */
63
void ut_dbg_panic(void);
64
# define UT_DBG_PANIC ut_dbg_panic()
65
/* Stop threads in ut_a(). */
66
# define UT_DBG_STOP do {} while (0) /* We do not do this on NetWare */
67
#else /* __NETWARE__ */
68
# if defined(__WIN__) || defined(__INTEL_COMPILER)
69
# undef UT_DBG_USE_ABORT
70
# elif defined(__GNUC__) && (__GNUC__ > 2)
71
# define UT_DBG_USE_ABORT
74
# ifndef UT_DBG_USE_ABORT
75
/** A null pointer that will be dereferenced to trigger a memory trap */
76
extern ulint* ut_dbg_null_ptr;
79
# if defined(UNIV_SYNC_DEBUG) || !defined(UT_DBG_USE_ABORT)
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(). */
82
extern ibool ut_dbg_stop_threads;
84
/*************************************************************//**
85
Stop a thread after assertion failure. */
94
# ifdef UT_DBG_USE_ABORT
95
/** Abort the execution. */
96
# define UT_DBG_PANIC abort()
97
/** Stop threads (null operation) */
98
# define UT_DBG_STOP do {} while (0)
99
# else /* UT_DBG_USE_ABORT */
100
/** Abort the execution. */
101
# define UT_DBG_PANIC \
102
if (*(ut_dbg_null_ptr)) ut_dbg_null_ptr = NULL
103
/** Stop threads in ut_a(). */
104
# define UT_DBG_STOP do \
105
if (UNIV_UNLIKELY(ut_dbg_stop_threads)) { \
106
ut_dbg_stop_thread(__FILE__, (ulint) __LINE__); \
108
# endif /* UT_DBG_USE_ABORT */
109
#endif /* __NETWARE__ */
111
/** Abort execution if EXPR does not evaluate to nonzero.
112
@param EXPR assertion expression that should hold */
113
#define ut_a(EXPR) do { \
114
if (UT_DBG_FAIL(EXPR)) { \
115
ut_dbg_assertion_failed(#EXPR, \
116
__FILE__, (ulint) __LINE__); \
122
/** Abort execution. */
123
#define ut_error do { \
124
ut_dbg_assertion_failed(0, __FILE__, (ulint) __LINE__); \
129
/** Debug assertion. Does nothing unless UNIV_DEBUG is defined. */
130
#define ut_ad(EXPR) ut_a(EXPR)
131
/** Debug statement. Does nothing unless UNIV_DEBUG is defined. */
132
#define ut_d(EXPR) do {EXPR;} while (0)
134
/** Debug assertion. Does nothing unless UNIV_DEBUG is defined. */
136
/** Debug statement. Does nothing unless UNIV_DEBUG is defined. */
140
/** Silence warnings about an unused variable by doing a null assignment.
141
@param A the unused variable */
142
#define UT_NOT_USED(A) A = A
144
#ifdef UNIV_COMPILE_TEST_FUNCS
146
#include <sys/types.h>
147
#include <sys/time.h>
148
#include <sys/resource.h>
150
/** structure used for recording usage statistics */
151
typedef struct speedo_struct {
152
struct rusage ru; /*!< getrusage() result */
153
struct timeval tv; /*!< gettimeofday() result */
156
/*******************************************************************//**
157
Resets a speedo (records the current time in it). */
162
speedo_t* speedo); /*!< out: speedo */
164
/*******************************************************************//**
165
Shows the time elapsed and usage statistics since the last reset of a
171
const speedo_t* speedo); /*!< in: speedo */
173
#endif /* UNIV_COMPILE_TEST_FUNCS */