| 1 |
/***************************************************************************** |
| 2 |
|
| 3 |
Copyright (c) 1994, 2026, Oracle and/or its affiliates. |
| 4 |
|
| 5 |
This program is free software; you can redistribute it and/or modify it under |
| 6 |
the terms of the GNU General Public License, version 2.0, as published by the |
| 7 |
Free Software Foundation. |
| 8 |
|
| 9 |
This program is designed to work with certain software (including |
| 10 |
but not limited to OpenSSL) that is licensed under separate terms, |
| 11 |
as designated in a particular file or component or in included license |
| 12 |
documentation. The authors of MySQL hereby grant you an additional |
| 13 |
permission to link the program and your derivative works with the |
| 14 |
separately licensed software that they have either included with |
| 15 |
the program or referenced in the documentation. |
| 16 |
|
| 17 |
This program is distributed in the hope that it will be useful, but WITHOUT |
| 18 |
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 19 |
FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0, |
| 20 |
for more details. |
| 21 |
|
| 22 |
You should have received a copy of the GNU General Public License along with |
| 23 |
this program; if not, write to the Free Software Foundation, Inc., |
| 24 |
51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 25 |
|
| 26 |
*****************************************************************************/ |
| 27 |
|
| 28 |
/** @file ut/ut0dbg.cc |
| 29 |
Debug utilities for Innobase. |
| 30 |
|
| 31 |
Created 1/30/1994 Heikki Tuuri |
| 32 |
**********************************************************************/ |
| 33 |
|
| 34 |
#include <stdlib.h> |
| 35 |
|
| 36 |
#include "my_dbug.h" |
| 37 |
#include "univ.i" |
| 38 |
|
| 39 |
#ifndef UNIV_HOTBACKUP |
| 40 |
#include "ha_prototypes.h" |
| 41 |
#include "sql/log.h" |
| 42 |
#endif /* !UNIV_HOTBACKUP */ |
| 43 |
|
| 44 |
#include "ut0dbg.h" |
| 45 |
|
| 46 |
static std::function<void()> assert_callback; |
| 47 |
|
| 48 |
void ut_set_assert_callback(std::function<void()> &callback) { |
| 49 |
assert_callback = callback; |
| 50 |
} |
| 51 |
|
| 52 |
/** Report a failed assertion. |
| 53 |
@param[in] expr The failed assertion |
| 54 |
@param[in] file Source file containing the assertion |
| 55 |
@param[in] line Line number of the assertion */ |
| 56 |
[[noreturn]] void ut_dbg_assertion_failed(const char *expr, const char *file, |
| 57 |
uint64_t line) { |
| 58 |
#if !defined(UNIV_HOTBACKUP) && !defined(UNIV_NO_ERR_MSGS) |
| 59 |
ib::error(ER_IB_MSG_1273) |
| 60 |
<< "Assertion failure: " << innobase_basename(file) << ":" << line |
| 61 |
<< ((expr != nullptr) ? ":" : "") << ((expr != nullptr) ? expr : "") |
| 62 |
<< " thread " << to_string(std::this_thread::get_id()); |
| 63 |
|
| 64 |
flush_error_log_messages(); |
| 65 |
|
| 66 |
#else /* !UNIV_HOTBACKUP && !defined(UNIV_NO_ERR_MSGS) */ |
| 67 |
auto filename = base_name(file); |
| 68 |
|
| 69 |
if (filename == nullptr) { |
| 70 |
filename = "null"; |
| 71 |
} |
| 72 |
|
| 73 |
fprintf(stderr, |
| 74 |
"InnoDB: Assertion failure: %s:" UINT64PF |
| 75 |
"%s%s\n" |
| 76 |
"InnoDB: thread %s", |
| 77 |
filename, line, expr != nullptr ? ":" : "", |
| 78 |
expr != nullptr ? expr : "", |
| 79 |
to_string(std::this_thread::get_id()).c_str()); |
| 80 |
#endif /* !UNIV_HOTBACKUP */ |
| 81 |
|
| 82 |
fputs( |
| 83 |
"InnoDB: We intentionally generate a memory trap.\n" |
| 84 |
"InnoDB: Submit a detailed bug report" |
| 85 |
" to http://bugs.mysql.com.\n" |
| 86 |
"InnoDB: If you get repeated assertion failures or crashes, even\n" |
| 87 |
"InnoDB: immediately after the mysqld startup, there may be\n" |
| 88 |
"InnoDB: corruption in the InnoDB tablespace. Please refer to\n" |
| 89 |
"InnoDB: " REFMAN |
| 90 |
"forcing-innodb-recovery.html\n" |
| 91 |
"InnoDB: about forcing recovery.\n", |
| 92 |
stderr); |
| 93 |
|
| 94 |
fflush(stderr); |
| 95 |
fflush(stdout); |
| 96 |
/* Call any registered callback function. */ |
| 97 |
if (assert_callback) { |
| 98 |
assert_callback(); |
| 99 |
} |
| 100 |
my_abort(); |
| 101 |
} |