Move debug_crash_here to it's own source files
This commit is contained in:
parent
ad02d53a71
commit
496a14e187
@ -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
|
||||
|
88
sql/debug.cc
Normal file
88
sql/debug.cc
Normal file
@ -0,0 +1,88 @@
|
||||
/* 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 */
|
39
sql/debug.h
Normal file
39
sql/debug.h
Normal file
@ -0,0 +1,39 @@
|
||||
#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
|
||||
|
@ -54,9 +54,9 @@
|
||||
#include "sql_audit.h"
|
||||
#include "sql_sequence.h"
|
||||
#include "tztime.h"
|
||||
#include "sql_insert.h" // binlog_drop_table
|
||||
#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"
|
||||
|
||||
/*************************************************************************/
|
||||
|
@ -16,29 +16,29 @@
|
||||
*/
|
||||
|
||||
#define MYSQL_LEX 1
|
||||
#include "mariadb.h" /* NO_EMBEDDED_ACCESS_CHECKS */
|
||||
#include "mariadb.h" /* NO_EMBEDDED_ACCESS_CHECKS */
|
||||
#include "sql_priv.h"
|
||||
#include "unireg.h"
|
||||
#include "sql_view.h"
|
||||
#include "sql_base.h" // find_table_in_global_list, lock_table_names
|
||||
#include "sql_parse.h" // sql_parse
|
||||
#include "sql_cache.h" // query_cache_*
|
||||
#include "lock.h" // MYSQL_OPEN_SKIP_TEMPORARY
|
||||
#include "sql_show.h" // append_identifier
|
||||
#include "sql_table.h" // build_table_filename
|
||||
#include "sql_base.h" // find_table_in_global_list, lock_table_names
|
||||
#include "sql_parse.h" // sql_parse
|
||||
#include "sql_cache.h" // query_cache_*
|
||||
#include "lock.h" // MYSQL_OPEN_SKIP_TEMPORARY
|
||||
#include "sql_show.h" // append_identifier
|
||||
#include "sql_table.h" // build_table_filename
|
||||
#include "sql_db.h" // mysql_opt_change_db, mysql_change_db
|
||||
#include "sql_select.h"
|
||||
#include "parse_file.h"
|
||||
#include "sp_head.h"
|
||||
#include "sp.h"
|
||||
#include "sp_cache.h"
|
||||
#include "datadict.h" // dd_frm_is_view()
|
||||
#include "datadict.h" // dd_frm_is_view()
|
||||
#include "sql_derived.h"
|
||||
#include "sql_cte.h" // check_dependencies_in_with_clauses()
|
||||
#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
|
||||
|
Loading…
x
Reference in New Issue
Block a user