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
1
/*********************************************************************
21
2
Debug utilities for Innobase
4
(c) 1994, 1995 Innobase Oy
23
6
Created 1/30/1994 Heikki Tuuri
24
7
**********************************************************************/
31
14
#include "os0thread.h"
33
16
#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
17
# 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 */
19
extern ulint ut_dbg_zero; /* This is used to eliminate
44
21
# define UT_DBG_FAIL(EXPR) !((ulint)(EXPR) + ut_dbg_zero)
47
/*************************************************************//**
24
/*****************************************************************
48
25
Report a failed assertion. */
51
28
ut_dbg_assertion_failed(
52
29
/*====================*/
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 */
57
#if defined(__WIN__) || defined(__INTEL_COMPILER)
58
# undef UT_DBG_USE_ABORT
59
#elif defined(__GNUC__) && (__GNUC__ > 2)
60
# define UT_DBG_USE_ABORT
63
#ifndef UT_DBG_USE_ABORT
64
/** A null pointer that will be dereferenced to trigger a memory trap */
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 */
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
50
# ifndef UT_DBG_USE_ABORT
51
/* A null pointer that will be dereferenced to trigger a memory trap */
65
52
extern ulint* ut_dbg_null_ptr;
68
#if defined(UNIV_SYNC_DEBUG) || !defined(UT_DBG_USE_ABORT)
69
/** If this is set to TRUE by ut_dbg_assertion_failed(), all threads
70
will stop at the next ut_a() or ut_ad(). */
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(). */
71
58
extern ibool ut_dbg_stop_threads;
73
/*************************************************************//**
60
/*****************************************************************
74
61
Stop a thread after assertion failure. */
78
65
/*===============*/
83
#ifdef UT_DBG_USE_ABORT
84
/** Abort the execution. */
85
# define UT_DBG_PANIC abort()
86
/** Stop threads (null operation) */
87
# define UT_DBG_STOP do {} while (0)
88
#else /* UT_DBG_USE_ABORT */
89
/** Abort the execution. */
90
# define UT_DBG_PANIC \
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 \
91
78
if (*(ut_dbg_null_ptr)) ut_dbg_null_ptr = NULL
92
/** Stop threads in ut_a(). */
93
# define UT_DBG_STOP do \
79
/* Stop threads in ut_a(). */
80
# define UT_DBG_STOP do \
94
81
if (UNIV_UNLIKELY(ut_dbg_stop_threads)) { \
95
82
ut_dbg_stop_thread(__FILE__, (ulint) __LINE__); \
97
#endif /* UT_DBG_USE_ABORT */
84
# endif /* UT_DBG_USE_ABORT */
85
#endif /* __NETWARE__ */
99
/** Abort execution if EXPR does not evaluate to nonzero.
100
@param EXPR assertion expression that should hold */
87
/* Abort execution if EXPR does not evaluate to nonzero. */
101
88
#define ut_a(EXPR) do { \
102
89
if (UT_DBG_FAIL(EXPR)) { \
103
90
ut_dbg_assertion_failed(#EXPR, \
110
/** Abort execution. */
97
/* Abort execution. */
111
98
#define ut_error do { \
112
99
ut_dbg_assertion_failed(0, __FILE__, (ulint) __LINE__); \
116
103
#ifdef UNIV_DEBUG
117
/** Debug assertion. Does nothing unless UNIV_DEBUG is defined. */
118
104
#define ut_ad(EXPR) ut_a(EXPR)
119
/** Debug statement. Does nothing unless UNIV_DEBUG is defined. */
120
105
#define ut_d(EXPR) do {EXPR;} while (0)
122
/** Debug assertion. Does nothing unless UNIV_DEBUG is defined. */
123
107
#define ut_ad(EXPR)
124
/** Debug statement. Does nothing unless UNIV_DEBUG is defined. */
125
108
#define ut_d(EXPR)
128
/** Silence warnings about an unused variable by doing a null assignment.
129
@param A the unused variable */
130
111
#define UT_NOT_USED(A) A = A
132
113
#ifdef UNIV_COMPILE_TEST_FUNCS
135
116
#include <sys/time.h>
136
117
#include <sys/resource.h>
138
/** structure used for recording usage statistics */
119
/* structure used for recording usage statistics */
139
120
typedef struct speedo_struct {
140
struct rusage ru; /*!< getrusage() result */
141
struct timeval tv; /*!< gettimeofday() result */
144
/*******************************************************************//**
125
/***********************************************************************
145
126
Resets a speedo (records the current time in it). */
150
speedo_t* speedo); /*!< out: speedo */
131
speedo_t* speedo); /* out: speedo */
152
/*******************************************************************//**
133
/***********************************************************************
153
134
Shows the time elapsed and usage statistics since the last reset of a
159
const speedo_t* speedo); /*!< in: speedo */
140
const speedo_t* speedo); /* in: speedo */
161
142
#endif /* UNIV_COMPILE_TEST_FUNCS */