diff --git a/dbug/dbug.c b/dbug/dbug.c index 9ec8044..c63db2e 100644 --- a/dbug/dbug.c +++ b/dbug/dbug.c @@ -272,6 +272,9 @@ static void PushState(CODE_STATE *cs); static void FreeState (CODE_STATE *cs, int free_state); /* Test for tracing enabled */ static int DoTrace(CODE_STATE *cs); + /* Check keyword */ +static BOOLEAN DBUGKeyword(CODE_STATE *cs, const char *keyword, int strict); + /* return values of DoTrace. Can also be used as bitmask: ret & DO_TRACE @@ -1267,7 +1270,7 @@ void _db_doprnt_(const char *format,...) if (!cs->locked) pthread_mutex_lock(&THR_LOCK_dbug); - if (_db_keyword_(cs, cs->u_keyword, 0)) + if (DBUGKeyword(cs, cs->u_keyword, 0)) { int save_errno=errno; DoPrefix(cs, cs->u_line); @@ -1326,7 +1329,7 @@ void _db_dump_(uint _line_, const char *keyword, if (!cs->locked) pthread_mutex_lock(&THR_LOCK_dbug); - if (_db_keyword_(cs, keyword, 0)) + if (DBUGKeyword(cs, keyword, 0)) { DoPrefix(cs, _line_); if (TRACING) @@ -1705,8 +1708,23 @@ FILE *_db_fp_(void) BOOLEAN _db_keyword_(CODE_STATE *cs, const char *keyword, int strict) { + BOOLEAN res; + get_code_state_or_return FALSE; + + if (!cs->locked) + pthread_mutex_lock(&THR_LOCK_dbug); + + res= DBUGKeyword(cs, keyword, strict); + + if (!cs->locked) + pthread_mutex_unlock(&THR_LOCK_dbug); + + return res; +} + +static BOOLEAN DBUGKeyword(CODE_STATE *cs, const char *keyword, int strict) +{ int match= strict ? INCLUDE : INCLUDE|MATCHED; - get_code_state_if_not_set_or_return FALSE; return (DEBUGGING && DoTrace(cs) & DO_TRACE && InList(cs->stack->keywords, keyword, strict) & match); diff --git a/mysql-test/r/debug.result b/mysql-test/r/debug.result new file mode 100644 index 0000000..a388675 --- /dev/null +++ b/mysql-test/r/debug.result @@ -0,0 +1,22 @@ +CREATE PROCEDURE p1 () +begin +set @a = 0; +while @a < 100 do +SET GLOBAL debug=''; +SET debug=''; +SET GLOBAL debug='+dkalle'; +SET debug=@tmp; +set @a = @a + 1; +end while; +end;| +CREATE PROCEDURE p2 () +begin +set @a = 0; +while @a < 100 do +select @@debug; +set @a = @a + 1; +end while; +end;| +drop procedure p1; +drop procedure p2; +Resetting global.debug to initial state diff --git a/mysql-test/t/debug.test b/mysql-test/t/debug.test new file mode 100644 index 0000000..4165a92 --- /dev/null +++ b/mysql-test/t/debug.test @@ -0,0 +1,160 @@ +# +# We need the debug +# +--source include/have_debug.inc + +# +# Skip embedded +# +--source include/not_embedded.inc + +# +# test that SET @@global.debug is thread-safe +# as in don't crash :-) +# +let $save_debug=`select @@debug`; + +--disable_query_log +--disable_result_log +--eval set @tmp='$save_debug'; +--enable_query_log +--enable_result_log + +delimiter |; +CREATE PROCEDURE p1 () +begin + set @a = 0; + while @a < 100 do + SET GLOBAL debug=''; + SET debug=''; + SET GLOBAL debug='+dkalle'; + SET debug=@tmp; + set @a = @a + 1; + end while; +end;| +CREATE PROCEDURE p2 () +begin + set @a = 0; + while @a < 100 do + select @@debug; + set @a = @a + 1; + end while; +end;| +delimiter ;| + +connect (con0,localhost,root,,); +connect (con1,localhost,root,,); +connect (con2,localhost,root,,); +connect (con3,localhost,root,,); +connect (con4,localhost,root,,); +connect (con5,localhost,root,,); +connect (con6,localhost,root,,); +connect (con7,localhost,root,,); +connect (con8,localhost,root,,); +connect (con9,localhost,root,,); +connect (con10,localhost,root,,); +connect (con11,localhost,root,,); +connect (con12,localhost,root,,); +connect (con13,localhost,root,,); +connect (con14,localhost,root,,); +connect (con15,localhost,root,,); +connect (con16,localhost,root,,); +connect (con17,localhost,root,,); +connect (con18,localhost,root,,); +connect (con19,localhost,root,,); + +--disable_query_log +--disable_result_log +--connection con0 +send call p1(); +--connection con1 +send call p2(); +--connection con2 +send call p1(); +--connection con3 +send call p2(); +--connection con4 +send call p1(); +--connection con5 +send call p2(); +--connection con6 +send call p1(); +--connection con7 +send call p2(); +--connection con8 +send call p1(); +--connection con9 +send call p2(); +--connection con10 +send call p1(); +--connection con11 +send call p2(); +--connection con12 +send call p1(); +--connection con13 +send call p2(); +--connection con14 +send call p1(); +--connection con15 +send call p2(); +--connection con16 +send call p1(); +--connection con17 +send call p2(); +--connection con18 +send call p1(); +--connection con19 +send call p2(); + +--connection con0 +reap; +--connection con1 +reap; +--connection con2 +reap; +--connection con3 +reap; +--connection con4 +reap; +--connection con5 +reap; +--connection con6 +reap; +--connection con7 +reap; +--connection con8 +reap; +--connection con9 +reap; +--connection con10 +reap; +--connection con11 +reap; +--connection con12 +reap; +--connection con13 +reap; +--connection con14 +reap; +--connection con15 +reap; +--connection con16 +reap; +--connection con17 +reap; +--connection con18 +reap; +--connection con19 +reap; +--enable_result_log +--enable_query_log + +drop procedure p1; +drop procedure p2; + +--echo Resetting global.debug to initial state +--disable_query_log +--disable_result_log +--eval SET GLOBAL debug='$save_debug'; +--enable_result_log +--enable_query_log