MySQL 9.0.0
Source Code Documentation
ut0dbg.h File Reference

Debug utilities for Innobase. More...

#include "my_compiler.h"
#include <cstdio>
#include <functional>
#include <sstream>
#include <sys/resource.h>
#include <sys/time.h>
#include <sys/types.h>

Go to the source code of this file.

Classes

class  ut_chrono_t
 A "chronometer" used to clock snippets of code. More...
 

Macros

#define ut_a_op(LHS, OP, RHS)
 Assert that LHS OP RHS, where OP is an operator. More...
 
#define ut_a_lt(LHS, RHS)   ut_a_op(LHS, <, RHS)
 Assert that LHS < RHS. More...
 
#define ut_a_le(LHS, RHS)   ut_a_op(LHS, <=, RHS)
 Assert that LHS <= RHS. More...
 
#define ut_a_eq(LHS, RHS)   ut_a_op(LHS, ==, RHS)
 Assert that LHS == RHS. More...
 
#define ut_a_ne(LHS, RHS)   ut_a_op(LHS, !=, RHS)
 Assert that LHS != RHS. More...
 
#define ut_a(EXPR)
 Abort execution if EXPR does not evaluate to nonzero. More...
 
#define ut_error   ut_dbg_assertion_failed(nullptr, __FILE__, __LINE__)
 Abort execution. More...
 
#define ut_ad(EXPR)   ut_a(EXPR)
 Debug assertion. More...
 
#define ut_d(EXPR)   EXPR
 Debug statement. More...
 
#define ut_o(EXPR)
 Opposite of ut_d(). More...
 
#define ut_ad_lt(LHS, RHS)   ut_a_lt(LHS, RHS)
 Debug-only assertion that LHS < RHS. More...
 
#define ut_ad_le(LHS, RHS)   ut_a_le(LHS, RHS)
 Debug-only assertion that LHS <= RHS. More...
 
#define ut_ad_eq(LHS, RHS)   ut_a_eq(LHS, RHS)
 Debug-only assertion that LHS == RHS. More...
 
#define ut_ad_ne(LHS, RHS)   ut_a_op(LHS, !=, RHS)
 Assert that LHS != RHS. More...
 
#define DBUG_INJECT_CRASH(prefix, count)
 Debug crash point. More...
 
#define DBUG_INJECT_CRASH_WITH_LOG_FLUSH(prefix, count)
 
#define UT_NOT_USED(A)   std::ignore = A
 Silence warnings about an unused variable by doing a null assignment. More...
 
#define HAVE_UT_CHRONO_T
 
#define timersub(a, b, r)
 
#define CHRONO_PRINT(type, tvp)
 

Functions

void ut_set_assert_callback (std::function< void()> &callback)
 Set a callback function to be called before exiting. More...
 
void ut_dbg_assertion_failed (const char *expr, const char *file, uint64_t line)
 Report a failed assertion. More...
 
template<typename L , typename R >
void ut_dbg_comparison_failed (const char *lhs_expr, const L &lhs_value, const char *op, const char *rhs_expr, const R &rhs_value, const char *file, uint64_t line)
 

Detailed Description

Debug utilities for Innobase.

Created 1/30/1994 Heikki Tuuri

Macro Definition Documentation

◆ CHRONO_PRINT

#define CHRONO_PRINT (   type,
  tvp 
)
Value:
fprintf(stderr, "%s: %s% 5ld.%06ld sec\n", m_name, type, \
static_cast<long>((tvp)->tv_sec), static_cast<long>((tvp)->tv_usec))
required string type
Definition: replication_group_member_actions.proto:34

◆ DBUG_INJECT_CRASH

#define DBUG_INJECT_CRASH (   prefix,
  count 
)
Value:
do { \
char buf[64]; \
snprintf(buf, sizeof buf, prefix "_%u", count); \
DBUG_EXECUTE_IF(buf, DBUG_SUICIDE();); \
} while (0)
#define DBUG_SUICIDE()
Definition: my_dbug.h:228
static int count
Definition: myisam_ftdump.cc:45
Definition: buf0block_hint.cc:30

Debug crash point.

◆ DBUG_INJECT_CRASH_WITH_LOG_FLUSH

#define DBUG_INJECT_CRASH_WITH_LOG_FLUSH (   prefix,
  count 
)
Value:
do { \
char buf[64]; \
snprintf(buf, sizeof buf, prefix "_%u", count); \
DBUG_EXECUTE_IF(buf, log_buffer_flush_to_disk(); DBUG_SUICIDE();); \
} while (0)
void log_buffer_flush_to_disk(log_t &log, bool sync=true)
Write to the log file up to the last log entry.
Definition: log0buf.cc:1183

◆ HAVE_UT_CHRONO_T

#define HAVE_UT_CHRONO_T

◆ timersub

#define timersub (   a,
  b,
  r 
)
Value:
do { \
(r)->tv_sec = (a)->tv_sec - (b)->tv_sec; \
(r)->tv_usec = (a)->tv_usec - (b)->tv_usec; \
if ((r)->tv_usec < 0) { \
(r)->tv_sec--; \
(r)->tv_usec += 1000000; \
} \
} while (0)
const mysql_service_registry_t * r
Definition: pfs_example_plugin_employee.cc:86

◆ ut_a

#define ut_a (   EXPR)
Value:
do { \
if (unlikely(false == (bool)(EXPR))) { \
ut_dbg_assertion_failed(#EXPR, __FILE__, __LINE__); \
} \
} while (0)
constexpr bool unlikely(bool expr)
Definition: my_compiler.h:58

Abort execution if EXPR does not evaluate to nonzero.

Parameters
EXPRassertion expression that should hold

◆ ut_a_eq

#define ut_a_eq (   LHS,
  RHS 
)    ut_a_op(LHS, ==, RHS)

Assert that LHS == RHS.

Abort execution otherwise.

◆ ut_a_le

#define ut_a_le (   LHS,
  RHS 
)    ut_a_op(LHS, <=, RHS)

Assert that LHS <= RHS.

Abort execution otherwise.

◆ ut_a_lt

#define ut_a_lt (   LHS,
  RHS 
)    ut_a_op(LHS, <, RHS)

Assert that LHS < RHS.

Abort execution otherwise.

◆ ut_a_ne

#define ut_a_ne (   LHS,
  RHS 
)    ut_a_op(LHS, !=, RHS)

Assert that LHS != RHS.

Abort execution otherwise.

◆ ut_a_op

#define ut_a_op (   LHS,
  OP,
  RHS 
)
Value:
do { \
const auto lhs{LHS}; \
const auto rhs{RHS}; \
if (unlikely(!(lhs OP rhs))) { \
ut_dbg_comparison_failed(#LHS, lhs, #OP, #RHS, rhs, __FILE__, __LINE__); \
} \
} while (0)

Assert that LHS OP RHS, where OP is an operator.

Abort execution otherwise. Technical remarks: The LHS and RHS are evaluated exactly once (no short circuiting, even if OP is && or ||). Each value is stored in a local variable, so it's fine for LHS or RHS to return a temporary. In case of assertion failure references to const values of LHS and RHS will be passed to std::ostringstream::operator<<, so it must be implemented for them.

◆ ut_ad

#define ut_ad (   EXPR)    ut_a(EXPR)

Debug assertion.

Does nothing unless UNIV_DEBUG is defined.

◆ ut_ad_eq

#define ut_ad_eq (   LHS,
  RHS 
)    ut_a_eq(LHS, RHS)

Debug-only assertion that LHS == RHS.

◆ ut_ad_le

#define ut_ad_le (   LHS,
  RHS 
)    ut_a_le(LHS, RHS)

Debug-only assertion that LHS <= RHS.

◆ ut_ad_lt

#define ut_ad_lt (   LHS,
  RHS 
)    ut_a_lt(LHS, RHS)

Debug-only assertion that LHS < RHS.

◆ ut_ad_ne

#define ut_ad_ne (   LHS,
  RHS 
)    ut_a_op(LHS, !=, RHS)

Assert that LHS != RHS.

Abort execution otherwise.

◆ ut_d

#define ut_d (   EXPR)    EXPR

Debug statement.

Does nothing unless UNIV_DEBUG is defined.

◆ ut_error

#define ut_error   ut_dbg_assertion_failed(nullptr, __FILE__, __LINE__)

Abort execution.

◆ UT_NOT_USED

#define UT_NOT_USED (   A)    std::ignore = A

Silence warnings about an unused variable by doing a null assignment.

Parameters
Athe unused variable

◆ ut_o

#define ut_o (   EXPR)

Opposite of ut_d().

Does nothing if UNIV_DEBUG is defined.

Function Documentation

◆ ut_dbg_assertion_failed()

void ut_dbg_assertion_failed ( const char *  expr,
const char *  file,
uint64_t  line 
)

Report a failed assertion.

Parameters
[in]exprThe failed assertion
[in]fileSource file containing the assertion
[in]lineLine number of the assertion

◆ ut_dbg_comparison_failed()

template<typename L , typename R >
void ut_dbg_comparison_failed ( const char *  lhs_expr,
const L lhs_value,
const char *  op,
const char *  rhs_expr,
const R &  rhs_value,
const char *  file,
uint64_t  line 
)
inline

◆ ut_set_assert_callback()

void ut_set_assert_callback ( std::function< void()> &  callback)

Set a callback function to be called before exiting.

Parameters
[in]callbackuser callback function