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., 51 Franklin
15
St, Fifth Floor, Boston, MA 02110-1301 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. */
54
ut_dbg_assertion_failed(
55
/*====================*/
56
const char* expr, /*!< in: the failed assertion */
57
const char* file, /*!< in: source file containing the assertion */
58
ulint line); /*!< in: line number of the assertion */
60
#if defined(__WIN__) || defined(__INTEL_COMPILER)
61
# undef UT_DBG_USE_ABORT
62
#elif defined(__GNUC__) && (__GNUC__ > 2)
63
# define UT_DBG_USE_ABORT
66
#ifndef UT_DBG_USE_ABORT
67
/** A null pointer that will be dereferenced to trigger a memory trap */
68
extern ulint* ut_dbg_null_ptr;
71
#if defined(UNIV_SYNC_DEBUG) || !defined(UT_DBG_USE_ABORT)
72
/** If this is set to TRUE by ut_dbg_assertion_failed(), all threads
73
will stop at the next ut_a() or ut_ad(). */
74
extern ibool ut_dbg_stop_threads;
76
/*************************************************************//**
77
Stop a thread after assertion failure. */
86
#ifdef UT_DBG_USE_ABORT
87
/** Abort the execution. */
88
# define UT_DBG_PANIC abort()
89
/** Stop threads (null operation) */
90
# define UT_DBG_STOP do {} while (0)
91
#else /* UT_DBG_USE_ABORT */
92
/** Abort the execution. */
93
# define UT_DBG_PANIC \
94
if (*(ut_dbg_null_ptr)) ut_dbg_null_ptr = NULL
95
/** Stop threads in ut_a(). */
96
# define UT_DBG_STOP do \
97
if (UNIV_UNLIKELY(ut_dbg_stop_threads)) { \
98
ut_dbg_stop_thread(__FILE__, (ulint) __LINE__); \
100
#endif /* UT_DBG_USE_ABORT */
102
/** Abort execution if EXPR does not evaluate to nonzero.
103
@param EXPR assertion expression that should hold */
104
#define ut_a(EXPR) do { \
105
if (UT_DBG_FAIL(EXPR)) { \
106
ut_dbg_assertion_failed(#EXPR, \
107
__FILE__, (ulint) __LINE__); \
113
/** Abort execution. */
114
#define ut_error do { \
115
ut_dbg_assertion_failed(0, __FILE__, (ulint) __LINE__); \
120
/** Debug assertion. Does nothing unless UNIV_DEBUG is defined. */
121
#define ut_ad(EXPR) ut_a(EXPR)
122
/** Debug statement. Does nothing unless UNIV_DEBUG is defined. */
123
#define ut_d(EXPR) do {EXPR;} while (0)
125
/** Debug assertion. Does nothing unless UNIV_DEBUG is defined. */
127
/** Debug statement. Does nothing unless UNIV_DEBUG is defined. */
131
/** Silence warnings about an unused variable by doing a null assignment.
132
@param A the unused variable */
133
#define UT_NOT_USED(A) A = A
135
#ifdef UNIV_COMPILE_TEST_FUNCS
137
#include <sys/types.h>
138
#include <sys/time.h>
139
#include <sys/resource.h>
141
/** structure used for recording usage statistics */
142
typedef struct speedo_struct {
143
struct rusage ru; /*!< getrusage() result */
144
struct timeval tv; /*!< gettimeofday() result */
147
/*******************************************************************//**
148
Resets a speedo (records the current time in it). */
153
speedo_t* speedo); /*!< out: speedo */
155
/*******************************************************************//**
156
Shows the time elapsed and usage statistics since the last reset of a
162
const speedo_t* speedo); /*!< in: speedo */
164
#endif /* UNIV_COMPILE_TEST_FUNCS */