Commit 496a14e1 authored by Monty's avatar Monty Committed by Sergei Golubchik

Move debug_crash_here to it's own source files

parent ad02d53a
......@@ -78,7 +78,8 @@ SET(SQL_EMBEDDED_SOURCES emb_qcache.cc libmysqld.c lib_sql.cc
../sql/sql_binlog.cc ../sql/sql_manager.cc
../sql/sql_parse.cc ../sql/sql_bootstrap.cc
../sql/sql_partition.cc ../sql/sql_plugin.cc
../sql/debug_sync.cc ../sql/opt_table_elimination.cc
../sql/debug_sync.cc ../sql/debug.cc
../sql/opt_table_elimination.cc
../sql/sql_prepare.cc ../sql/sql_rename.cc ../sql/sql_repl.cc
../sql/sql_select.cc ../sql/sql_servers.cc
../sql/group_by_handler.cc ../sql/derived_handler.cc
......
......@@ -117,7 +117,7 @@ SET (SQL_SOURCE
sql_list.cc sql_load.cc sql_manager.cc
sql_parse.cc sql_bootstrap.cc
sql_partition.cc sql_plugin.cc sql_prepare.cc sql_rename.cc
debug_sync.cc
debug_sync.cc debug.cc
sql_repl.cc sql_select.cc sql_show.cc sql_state.c
group_by_handler.cc derived_handler.cc select_handler.cc
sql_statistics.cc sql_string.cc lex_string.h
......
/* Copyright (c) 2021, MariaDB Corporation.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software Foundation,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA */
#include "mariadb.h"
#include "sql_class.h"
#include "debug.h"
/**
Debug utility to do crash after a set number of executions
The user variable, either @debug_crash_counter or @debug_error_counter,
is decremented each time debug_crash() or debug_simulate_error is called
if the keyword is set with @@debug_push, like
@@debug_push="d+frm_data_type_info_emulate"
If the variable is not set or is not an integer it will be ignored.
*/
#ifndef DBUG_OFF
static const LEX_CSTRING debug_crash_counter=
{ STRING_WITH_LEN("debug_crash_counter") };
static const LEX_CSTRING debug_error_counter=
{ STRING_WITH_LEN("debug_error_counter") };
static bool debug_decrement_counter(const LEX_CSTRING *name)
{
THD *thd= current_thd;
user_var_entry *entry= (user_var_entry*)
my_hash_search(&thd->user_vars, (uchar*) name->str, name->length);
if (!entry || entry->type != INT_RESULT || ! entry->value)
return 0;
(*(ulonglong*) entry->value)= (*(ulonglong*) entry->value)-1;
return !*(ulonglong*) entry->value;
}
void debug_crash_here(const char *keyword)
{
DBUG_ENTER("debug_crash_here");
DBUG_PRINT("enter", ("keyword: %s", keyword));
DBUG_EXECUTE_IF(keyword,
if (debug_decrement_counter(&debug_crash_counter))
{
my_printf_error(ER_INTERNAL_ERROR,
"Crashing at %s",
MYF(ME_ERROR_LOG | ME_NOTE), keyword);
DBUG_SUICIDE();
});
DBUG_VOID_RETURN;
}
/*
This can be used as debug_counter to simulate an error at a specific
position.
Typical usage would be
if (debug_simualte_error("keyword"))
error= 1;
*/
bool debug_simulate_error(const char *keyword, uint error)
{
DBUG_ENTER("debug_crash_here");
DBUG_PRINT("enter", ("keyword: %s", keyword));
DBUG_EXECUTE_IF(keyword,
if (debug_decrement_counter(&debug_error_counter))
{
my_printf_error(error,
"Simulating error for '%s'",
MYF(ME_ERROR_LOG), keyword);
DBUG_RETURN(1);
});
DBUG_RETURN(0);
}
#endif /* DBUG_OFF */
#ifndef DEBUG_INCLUDED
#define DEBUG_INCLUDED
/* Copyright (c) 2021, MariaDB Corporation
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1335 USA */
/**
@file
Declarations for debug_crash_here and other future mariadb server debug
functionality.
*/
/* debug_crash_here() functionallity.
See mysql_test/suite/atomic/create_table.test for an example of how it
can be used
*/
#ifndef DBUG_OFF
void debug_crash_here(const char *keyword);
bool debug_simulate_error(const char *keyword, uint error);
#else
#define debug_crash_here(A) do { } while(0)
#define debug_simulate_error(A, B) 0
#endif
#endif /* DEBUG_INCLUDED */
......@@ -1628,74 +1628,3 @@ bool debug_sync_set_action(THD *thd, const char *action_str, size_t len)
/* prevent linker/lib warning about file without public symbols */
int debug_sync_dummy;
#endif /* defined(ENABLED_DEBUG_SYNC) */
/**
Debug utility to do crash after a set number of executions
The user variable, either @debug_crash_counter or @debug_error_counter,
is decremented each time debug_crash() or debug_simulate_error is called
if the keyword is set with @@debug_push, like
@@debug_push="d+frm_data_type_info_emulate"
If the variable is not set or is not an integer it will be ignored.
*/
#ifndef DBUG_OFF
static const LEX_CSTRING debug_crash_counter=
{ STRING_WITH_LEN("debug_crash_counter") };
static const LEX_CSTRING debug_error_counter=
{ STRING_WITH_LEN("debug_error_counter") };
static bool debug_decrement_counter(const LEX_CSTRING *name)
{
THD *thd= current_thd;
user_var_entry *entry= (user_var_entry*)
my_hash_search(&thd->user_vars, (uchar*) name->str, name->length);
if (!entry || entry->type != INT_RESULT || ! entry->value)
return 0;
(*(ulonglong*) entry->value)= (*(ulonglong*) entry->value)-1;
return !*(ulonglong*) entry->value;
}
void debug_crash_here(const char *keyword)
{
DBUG_ENTER("debug_crash_here");
DBUG_PRINT("enter", ("keyword: %s", keyword));
DBUG_EXECUTE_IF(keyword,
if (debug_decrement_counter(&debug_crash_counter))
{
my_printf_error(ER_INTERNAL_ERROR,
"Crashing at %s",
MYF(ME_ERROR_LOG | ME_NOTE), keyword);
DBUG_SUICIDE();
});
DBUG_VOID_RETURN;
}
/*
This can be used as debug_counter to simulate an error at a specific
position.
Typical usage would be
if (debug_simualte_error("keyword"))
error= 1;
*/
bool debug_simulate_error(const char *keyword, uint error)
{
DBUG_ENTER("debug_crash_here");
DBUG_PRINT("enter", ("keyword: %s", keyword));
DBUG_EXECUTE_IF(keyword,
if (debug_decrement_counter(&debug_error_counter))
{
my_printf_error(error,
"Simulating error for '%s'",
MYF(ME_ERROR_LOG), keyword);
DBUG_RETURN(1);
});
DBUG_RETURN(0);
}
#endif /* DBUG_OFF */
......@@ -52,13 +52,4 @@ static inline void debug_sync_reset_thread(THD *thd) {}
static inline bool debug_sync_set_action(THD *, const char *, size_t)
{ return false; }
#endif /* defined(ENABLED_DEBUG_SYNC) */
#ifndef DBUG_OFF
void debug_crash_here(const char *keyword);
bool debug_simulate_error(const char *keyword, uint error);
#else
#define debug_crash_here(A) do { } while(0)
#define debug_simulate_error(A, B) 0
#endif
#endif /* DEBUG_SYNC_INCLUDED */
......@@ -25,7 +25,7 @@
#include "parse_file.h"
#include "unireg.h" // CREATE_MODE
#include "sql_table.h" // build_table_filename
#include "debug_sync.h"
#include "debug.h"
#include <mysys_err.h> // EE_WRITE
#include <m_ctype.h>
#include <my_dir.h>
......
......@@ -47,7 +47,7 @@
#ifdef __WIN__
#include <direct.h>
#endif
#include "debug_sync.h"
#include "debug.h" // debug_crash_here
#define MAX_DROP_TABLE_Q_LEN 1024
......
......@@ -77,10 +77,10 @@
#include "sql_audit.h"
#include "sql_derived.h" // mysql_handle_derived
#include "sql_prepare.h"
#include "debug_sync.h" // DEBUG_SYNC
#include "debug.h" // debug_crash_here
#include <my_bit.h>
#include "debug_sync.h"
#ifdef WITH_WSREP
#include "wsrep_trans_observer.h" /* wsrep_start_transction() */
#endif /* WITH_WSREP */
......
......@@ -31,7 +31,7 @@
#include "sql_handler.h" // mysql_ha_rm_tables
#include "sql_statistics.h"
#include "ddl_log.h"
#include "debug_sync.h"
#include "debug.h"
/* used to hold table entries for as part of list of renamed temporary tables */
struct TABLE_PAIR
......
......@@ -56,7 +56,7 @@
#include "tztime.h"
#include "sql_insert.h" // binlog_drop_table
#include "ddl_log.h"
#include "debug_sync.h" // debug_crash_here()
#include "debug.h" // debug_crash_here()
#include <algorithm>
#ifdef __WIN__
......
......@@ -33,8 +33,9 @@
#include "sql_handler.h" // mysql_ha_rm_tables
#include "sp_cache.h" // sp_invalidate_cache
#include <mysys_err.h>
#include <ddl_log.h> // ddl_log_state
#include "debug_sync.h"
#include "ddl_log.h" // ddl_log_state
#include "debug_sync.h" // DEBUG_SYNC
#include "debug.h" // debug_crash_here
#include "mysql/psi/mysql_sp.h"
/*************************************************************************/
......
......@@ -37,8 +37,8 @@
#include "sql_cte.h" // check_dependencies_in_with_clauses()
#include "opt_trace.h"
#include "ddl_log.h"
#include "debug.h" // debug_crash_here
#include "wsrep_mysqld.h"
#include "debug_sync.h" // debug_crash_here
#define MD5_BUFF_LENGTH 33
......
......@@ -45,7 +45,7 @@ C_MODE_END
#include "key.h"
#include "log.h"
#include "sql_parse.h"
#include "debug_sync.h"
#include "debug.h"
/*
Note that in future versions, only *transactional* Maria tables can
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment