--source include/have_debug.inc

SET @old_debug = @@GLOBAL.debug;

#
# Bug#34678 @@debug variable's incremental mode
#

set debug_dbug= 'T';
select @@debug;
set debug_dbug= '+P';
select @@debug;
set debug_dbug= '-P';
select @@debug;

#
# Bug#38054: "SET SESSION debug" modifies @@global.debug variable
#

SELECT @@session.debug, @@global.debug;

SET SESSION debug_dbug= '';

SELECT @@session.debug, @@global.debug;

--echo #
--echo # Bug #52629: memory leak from sys_var_thd_dbug in 
--echo #  binlog.binlog_write_error
--echo #

SET GLOBAL debug_dbug='d,injecting_fault_writing';
SELECT @@global.debug;
SET GLOBAL debug_dbug='';
SELECT @@global.debug;

SET GLOBAL debug_dbug=@old_debug;

--echo #
--echo # Bug #56709: Memory leaks at running the 5.1 test suite
--echo # 

SET @old_local_debug = @@debug;

SET @@debug_dbug='d,foo';
SELECT @@debug;
SET @@debug_dbug='';
SELECT @@debug;

SET @@debug_dbug= @old_local_debug;

--echo End of 5.1 tests


--echo #
--echo # Bug#46165 server crash in dbug
--echo #

SET @old_globaldebug = @@global.debug;
SET @old_sessiondebug= @@session.debug;

--echo # Test 1 - Bug test case, single connection
--replace_result $MYSQL_TMP_DIR MYSQL_TMP_DIR
eval SET GLOBAL  debug_dbug= '+O,$MYSQL_TMP_DIR/bug46165.1.trace';
SET SESSION debug_dbug= '-d:-t:-i';

SET GLOBAL  debug_dbug= '';
SET SESSION debug_dbug= '';

--echo # Test 2 - Bug test case, two connections
--echo # Connection default
connection default;
--replace_result $MYSQL_TMP_DIR MYSQL_TMP_DIR
eval SET GLOBAL  debug_dbug= '+O,$MYSQL_TMP_DIR/bug46165.2.trace';
SET SESSION debug_dbug= '-d:-t:-i';

--echo # Connection con1
connect (con1, localhost, root);
SET GLOBAL  debug_dbug= '';

--echo # Connection default
connection default;
SET SESSION debug_dbug= '';
--echo # Connection con1
connection con1;
disconnect con1;
--source include/wait_until_disconnected.inc
--echo # Connection default
connection default;
SET GLOBAL  debug_dbug= '';

--echo # Test 3 - Active session trace file on disconnect
--echo # Connection con1
connect (con1, localhost, root);
--replace_result $MYSQL_TMP_DIR MYSQL_TMP_DIR
eval SET GLOBAL  debug_dbug= '+O,$MYSQL_TMP_DIR/bug46165.3.trace';
--replace_result $MYSQL_TMP_DIR MYSQL_TMP_DIR
SELECT @@global.debug_dbug, @@session.debug_dbug;
SET SESSION debug_dbug= '+T';
--replace_result $MYSQL_TMP_DIR MYSQL_TMP_DIR
SELECT @@global.debug_dbug, @@session.debug_dbug;
SET GLOBAL  debug_dbug= '';
--replace_result $MYSQL_TMP_DIR MYSQL_TMP_DIR
SELECT @@global.debug_dbug, @@session.debug_dbug;
disconnect con1;
--source include/wait_until_disconnected.inc

--echo # Test 4 - Active session trace file on two connections
--echo # Connection default
connection default;
--replace_result $MYSQL_TMP_DIR MYSQL_TMP_DIR
eval SET GLOBAL  debug_dbug= '+O,$MYSQL_TMP_DIR/bug46165.4.trace';
SET SESSION debug_dbug= '-d:-t:-i';

--echo # Connection con1
connect (con1, localhost, root);
SET SESSION debug_dbug= '-d:-t:-i';
SET GLOBAL  debug_dbug= '';
SET SESSION debug_dbug= '';

--echo # Connection default
connection default;
SET SESSION debug_dbug= '';
--echo # Connection con1
connection con1;
disconnect con1;
--source include/wait_until_disconnected.inc
--echo # Connection default
connection default;

--echo # Test 5 - Different trace files
--replace_result $MYSQL_TMP_DIR MYSQL_TMP_DIR
eval SET SESSION debug_dbug= '+O,$MYSQL_TMP_DIR/bug46165.5.trace';
--replace_result $MYSQL_TMP_DIR MYSQL_TMP_DIR
eval SET SESSION debug_dbug= '+O,$MYSQL_TMP_DIR/bug46165.6.trace';
SET SESSION debug_dbug= '-O';

SET GLOBAL  debug_dbug= @old_globaldebug;
SET SESSION debug_dbug= @old_sessiondebug;
