Skip to content

Commit 0b9400d

Browse files
BUG#11765644: DEBUG 'D' LIST SHOULD STAY EMPTY AFTER SET
DEBUG="+D,<SYMBOL>" PROBLEM AND FIX: When the debug 'd' flag has been set to empty, then all DBUG_ macros are enabled. But if one then sets debug=" +d,foo" then only foo, all others are turned off. The expected/intended behaviour should be to add debug for 'symbol' in addition to whatever was enabled before. The fix adds keyword to the stack of active keyword list if debug was not enabled for all symbols. Also turn debug off if the last keyword is removed from the stack of keywords. NOTE: This shall require a change in the docs to reflect the changed behaviour in this bug
1 parent f5a2ba3 commit 0b9400d

File tree

2 files changed

+79
-4
lines changed

2 files changed

+79
-4
lines changed

dbug/dbug.c

+22-4
Original file line numberDiff line numberDiff line change
@@ -598,19 +598,37 @@ int DbugParse(CODE_STATE *cs, const char *control)
598598
if (!is_shared(stack, keywords))
599599
FreeList(stack->keywords);
600600
stack->keywords=NULL;
601-
stack->flags &= ~DEBUG_ON;
601+
stack->flags&= ~DEBUG_ON;
602602
break;
603603
}
604604
if (rel && is_shared(stack, keywords))
605605
stack->keywords= ListCopy(stack->keywords);
606606
if (sign < 0)
607607
{
608608
if (DEBUGGING)
609+
{
609610
stack->keywords= ListDel(stack->keywords, control, end);
610-
break;
611+
/* Turn off DEBUG_ON if it is last keyword to be removed. */
612+
if (stack->keywords == NULL)
613+
stack->flags&= ~DEBUG_ON;
614+
}
615+
break;
611616
}
612-
stack->keywords= ListAdd(stack->keywords, control, end);
613-
stack->flags |= DEBUG_ON;
617+
618+
/* Do not add keyword if debugging all is enabled. */
619+
if (!(DEBUGGING && stack->keywords == NULL))
620+
{
621+
stack->keywords= ListAdd(stack->keywords, control, end);
622+
stack->flags|= DEBUG_ON;
623+
}
624+
625+
/* If debug all is enabled, make the keyword list empty. */
626+
if (sign == 1 && control == end)
627+
{
628+
FreeList(stack->keywords);
629+
stack->keywords= NULL;
630+
}
631+
614632
break;
615633
case 'D':
616634
stack->delay= atoi(control);

unittest/gunit/dbug-t.cc

+57
Original file line numberDiff line numberDiff line change
@@ -98,5 +98,62 @@ TEST(DebugPrintDeathTest, PrintEval)
9898
EXPECT_DEATH_IF_SUPPORTED(DBUG_PRINT("never",("%d",1/y)), "");
9999
DBUG_SET("");
100100
}
101+
102+
103+
TEST(DebugSetTest, DebugKeywordsTest)
104+
{
105+
char buf[1024];
106+
107+
/*
108+
Enable d flag, then enable debug on a keyword. The debug should
109+
remain set to d and empty list of keywords indicating debug is
110+
enabled for all.
111+
*/
112+
DBUG_SET("d");
113+
DBUG_SET("+d,keyword");
114+
DBUG_EXPLAIN(buf, sizeof(buf));
115+
EXPECT_STREQ("d", buf);
116+
DBUG_SET("");
117+
118+
/*
119+
Set debug on a specific keyword. Debug should be enabled
120+
for the keyword.
121+
*/
122+
DBUG_SET("+d,keyword");
123+
DBUG_EXPLAIN(buf, sizeof(buf));
124+
EXPECT_STREQ("d,keyword", buf);
125+
126+
/*
127+
Remove the keyword from debug list. Debug should be
128+
disabled.
129+
*/
130+
DBUG_SET("-d,keyword");
131+
DBUG_EXPLAIN(buf, sizeof(buf));
132+
EXPECT_STREQ("",buf);
133+
DBUG_SET("");
134+
135+
/*
136+
Enable debug for a keyword. Then enable debug for all
137+
keywords. Debug should now be enabled for all keywords.
138+
*/
139+
DBUG_SET("+d,keyword");
140+
DBUG_SET("+d");
141+
DBUG_EXPLAIN(buf,sizeof(buf));
142+
EXPECT_STREQ("d",buf);
143+
DBUG_SET("");
144+
145+
// Add multiple debug keywords.
146+
DBUG_SET("+d,keyword1");
147+
DBUG_SET("+d,keyword2");
148+
DBUG_EXPLAIN(buf,sizeof(buf));
149+
EXPECT_STREQ("d,keyword1,keyword2",buf);
150+
DBUG_SET("-d,keyword1");
151+
DBUG_EXPLAIN(buf,sizeof(buf));
152+
EXPECT_STREQ("d,keyword2",buf);
153+
DBUG_SET("-d,keyword2");
154+
DBUG_EXPLAIN(buf,sizeof(buf));
155+
EXPECT_STREQ("",buf);
156+
DBUG_SET("");
157+
}
101158
#endif /* DBUG_OFF */
102159
}

0 commit comments

Comments
 (0)