Skip to contentSkip to conversation

parser: fix parser debugging yet again

PATCH In review Nick Alcock 3 participants 11 messages Sep 18, 2025 – Oct 3, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/4 parser: fix parser debugging yet again

The interaction between YYDEBUG and the yydebug extern variable has changed repeatedly in the various iterations of flex and bison. The one thing that is consistent is that yydebug is not used if YYDEBUG is unset or set to 0; if it's set to 1, the parser skeleton defines it for you.

So (now that -fno-common is on by default) dl_lex.l should not be defining yydebug itself, and dt_impl.h should only be declaring it extern if YYDEBUG is 1.

With this in place, we link and run with the parser debugger set to the expected state when compiling with YYDEBUG 1, YYDEBUG 0, and YYDEBUG unset.

---
 libdtrace/dt_impl.h | 2 ++
 libdtrace/dt_lex.l  | 4 +---
 2 files changed, 3 insertions(+), 3 deletions(-)
libdtrace/dt_impl.h +2 -0
index 7d8e4432a24ad..9c4651a46baa6 100644
@@ -808,7 +808,9 @@ extern char yyintsuffix[4];	/* int token suffix ([uUlL]*) */
 extern int yyintdecimal;	/* int token is decimal (1) or octal/hex (0) */
 extern char *yytext;		/* lex input buffer */
 extern int yylineno;		/* lex line number */
+#if defined(YYDEBUG) && YYDEBUG == 1
 extern int yydebug;		/* lex debugging */
+#endif
 extern dt_node_t *yypragma;	/* lex token list for control lines */
 
 extern const dtrace_attribute_t _dtrace_maxattr; /* maximum attributes */
libdtrace/dt_lex.l +1 -3
index e8f3bc8c25bb0..9f12f5c7ca289 100644
@@ -21,8 +21,6 @@
 static int id_or_type(const char *);
 static size_t dt_input(char *buf, size_t max_size);
 
-int yydebug;
-
 #define YY_INPUT(buf,result,max_size)                                   \
         result = dt_input(buf,max_size);
 
@@ -663,7 +661,7 @@ if (yypcb->pcb_token != 0) {
 void
 yybegin(yystate_t state)
 {
-#ifdef	YYDEBUG
+#if defined(YYDEBUG) && YYDEBUG == 1
 	yydebug = _dtrace_debug;
 #endif
 	if (yypcb->pcb_yystate == state)
Signature · 1 line
2.48.1.283.g18c60a128c
#1 lore raw

PATCH 2/4 lexer: the things inside an enum { ... } declaration are identifiers

The code in dt_lex.c:id_or_type() tries to figure out if something is an identifier or not: if it cannot prove it is an identifier, it concludes it must be a type name, which later triggers a search for said type (or identifier) which eventually reaches (expensively) across the entire kernel CTF. Usually this is what we want, since we use type names that actually reside in the kernel extensively and do not expect to have to decorate all of them with `. But if this misfires bad things can happen.

In the case of enums, existing code in dt_decl.c checks for duplicate identifiers, and carefully avoids considering code outside the C and D dicts to be duplicates: but if id_or_type() concludes this enumerator is probably a type name, we'll import the thing we find even if it's an identifier, and then conflict. Enumerators cannot be type names, so this must always be wrong (if we actually do put a type name in there, dt_parser.c will correctly reject it no matter what the lexer says).

So add yet another piece of parser context identifying when we are inside the { } in an enum (we set it to 1 when the enum is seen, then bump it when the braces are seen, so if it's 2 we are in the relevant context; it is reset to 0 on every ;), then use that to forcibly declare everything seen inside enums an identifier without trying to chase it down

---
 libdtrace/dt_lex.l | 17 +++++++++++++++--
 libdtrace/dt_pcb.h |  1 +
 2 files changed, 16 insertions(+), 2 deletions(-)
libdtrace/dt_lex.l +15 -2
index 9f12f5c7ca289..fd70aa0aa5803 100644
@@ -88,7 +88,7 @@ if (yypcb->pcb_token != 0) {
 <S0>do		return DT_KEY_DO;
 <S0>double	return DT_KEY_DOUBLE;
 <S0>else	return DT_KEY_ELSE;
-<S0>enum	{ yypcb->pcb_sou_type = 1; return DT_KEY_ENUM; }
+<S0>enum	{ yypcb->pcb_sou_type = 1; yypcb->pcb_enum_decl = 1; return DT_KEY_ENUM; }
 <S0>extern	return DT_KEY_EXTERN;
 <S0>float	return DT_KEY_FLOAT;
 <S0>for		return DT_KEY_FOR;
@@ -128,6 +128,7 @@ if (yypcb->pcb_token != 0) {
 <S2>counter	{ yybegin(YYS_DEFINE);	return DT_KEY_COUNTER; }
 <S2>double	{ yybegin(YYS_EXPR);	return DT_KEY_DOUBLE; }
 <S2>enum	{ yybegin(YYS_EXPR);	yypcb->pcb_sou_type = 1;
+					yypcb->pcb_enum_decl = 1;
 					return DT_KEY_ENUM; }
 <S2>extern	{ yybegin(YYS_EXPR);	return DT_KEY_EXTERN; }
 <S2>float	{ yybegin(YYS_EXPR);	return DT_KEY_FLOAT; }
@@ -463,6 +464,7 @@ if (yypcb->pcb_token != 0) {
 <S0>"("		{
 			yypcb->pcb_parens++;
 			yypcb->pcb_sou_type = 0;
+			yypcb->pcb_enum_decl = 0;
 			return DT_TOK_LPAR;
 		}
 
@@ -488,10 +490,13 @@ if (yypcb->pcb_token != 0) {
 <S2>"{"		{
 			yypcb->pcb_braces++;
 			yypcb->pcb_sou_type = 0;
+			if (yypcb->pcb_enum_decl)
+				yypcb->pcb_enum_decl++;
 			return '{';
 		}
 
 <S0>"}"		{
+			yypcb->pcb_enum_decl = 0;
 			if (--yypcb->pcb_braces < 0)
 				yyerror("extra } in input stream\n");
 			return '}';
@@ -536,7 +541,7 @@ if (yypcb->pcb_token != 0) {
 <S0>"--"	return DT_TOK_SUBSUB;
 <S0>"..."	return DT_TOK_ELLIPSIS;
 <S0>","		return DT_TOK_COMMA;
-<S0>";"		return ';';
+<S0>";"		yypcb->pcb_enum_decl = 0; return ';';
 <S0>{RGX_WS}	; /* discard */
 <S0>"\\"\n	; /* discard */
 <S0>.		{
@@ -769,6 +774,14 @@ id_or_type(const char *s)
 		return DT_TOK_IDENT;
 	}
 
+	/*
+	 * Inside an enumeration declaration's { }'s region: must be an ident.
+	 * Checking for conflicts is handled by dt_decl_enumerator().  No
+	 * need to look anything up here.
+	 */
+	if (yypcb->pcb_enum_decl == 2)
+	    return DT_TOK_IDENT;
+
 	/*
 	 * If the lexeme is a global variable or likely identifier, then it is
 	 * an identifier token.
libdtrace/dt_pcb.h +1 -0
index 7c57f83220b28..b6a7620f4920c 100644
@@ -71,6 +71,7 @@ typedef struct dt_pcb {
 	int pcb_parens;		/* number of open parentheses in lexer */
 	int pcb_sou_type;	/* lexer in struct/union type name */
 	int pcb_sou_deref;	/* lexer in struct/union dereference */
+	int pcb_enum_decl;	/* lexer in enum declaration: 2 for inside { }. */
 	int pcb_xlator_input;	/* in translator input type */
 	int pcb_array_dimens;	/* in array dimensions */
 	int pcb_alloca_taints;	/* number of alloca taint changes */
Signature · 1 line
2.48.1.283.g18c60a128c
Reviewed-by on v1 2/4
#2 lore raw

Re: [DTrace-devel] [PATCH 2/4] lexer: the things inside an enum { ... } declaration are identifiers

Quoted 16 lines · Nick Alcock via DTrace-devel

The code in dt_lex.c:id_or_type() tries to figure out if something is an identifier or not: if it cannot prove it is an identifier, it concludes it must be a type name, which later triggers a search for said type (or identifier) which eventually reaches (expensively) across the entire kernel CTF. Usually this is what we want, since we use type names that actually reside in the kernel extensively and do not expect to have to decorate all of them with `. But if this misfires bad things can happen.

In the case of enums, existing code in dt_decl.c checks for duplicate identifiers, and carefully avoids considering code outside the C and D dicts to be duplicates: but if id_or_type() concludes this enumerator is probably a type name, we'll import the thing we find even if it's an identifier, and then conflict. Enumerators cannot be type names, so this must always be wrong (if we actually do put a type name in there, dt_parser.c will correctly reject it no matter what the lexer says).

Quoted 8 lines

So add yet another piece of parser context identifying when we are inside the { } in an enum (we set it to 1 when the enum is seen, then bump it when the braces are seen, so if it's 2 we are in the relevant context; it is reset to 0 on every ;), then use that to forcibly declare everything seen inside enums an identifier without trying to chase it down

Quoted 92 lines
---
 libdtrace/dt_lex.l | 17 +++++++++++++++--
 libdtrace/dt_pcb.h |  1 +
 2 files changed, 16 insertions(+), 2 deletions(-)
libdtrace/dt_lex.l +15 -2
index 9f12f5c7ca289..fd70aa0aa5803 100644
@@ -88,7 +88,7 @@ if (yypcb->pcb_token != 0) {
 <S0>do		return DT_KEY_DO;
 <S0>double	return DT_KEY_DOUBLE;
 <S0>else	return DT_KEY_ELSE;
-<S0>enum	{ yypcb->pcb_sou_type = 1; return DT_KEY_ENUM; }
+<S0>enum	{ yypcb->pcb_sou_type = 1; yypcb->pcb_enum_decl = 1; return DT_KEY_ENUM; }
 <S0>extern	return DT_KEY_EXTERN;
 <S0>float	return DT_KEY_FLOAT;
 <S0>for		return DT_KEY_FOR;
@@ -128,6 +128,7 @@ if (yypcb->pcb_token != 0) {
 <S2>counter	{ yybegin(YYS_DEFINE);	return DT_KEY_COUNTER; }
 <S2>double	{ yybegin(YYS_EXPR);	return DT_KEY_DOUBLE; }
 <S2>enum	{ yybegin(YYS_EXPR);	yypcb->pcb_sou_type = 1;
+					yypcb->pcb_enum_decl = 1;
 					return DT_KEY_ENUM; }
 <S2>extern	{ yybegin(YYS_EXPR);	return DT_KEY_EXTERN; }
 <S2>float	{ yybegin(YYS_EXPR);	return DT_KEY_FLOAT; }
@@ -463,6 +464,7 @@ if (yypcb->pcb_token != 0) {
 <S0>"("		{
 			yypcb->pcb_parens++;
 			yypcb->pcb_sou_type = 0;
+			yypcb->pcb_enum_decl = 0;
 			return DT_TOK_LPAR;
 		}
 
@@ -488,10 +490,13 @@ if (yypcb->pcb_token != 0) {
 <S2>"{"		{
 			yypcb->pcb_braces++;
 			yypcb->pcb_sou_type = 0;
+			if (yypcb->pcb_enum_decl)
+				yypcb->pcb_enum_decl++;
 			return '{';
 		}
 
 <S0>"}"		{
+			yypcb->pcb_enum_decl = 0;
 			if (--yypcb->pcb_braces < 0)
 				yyerror("extra } in input stream\n");
 			return '}';
@@ -536,7 +541,7 @@ if (yypcb->pcb_token != 0) {
 <S0>"--"	return DT_TOK_SUBSUB;
 <S0>"..."	return DT_TOK_ELLIPSIS;
 <S0>","		return DT_TOK_COMMA;
-<S0>";"		return ';';
+<S0>";"		yypcb->pcb_enum_decl = 0; return ';';
 <S0>{RGX_WS}	; /* discard */
 <S0>"\\"\n	; /* discard */
 <S0>.		{
@@ -769,6 +774,14 @@ id_or_type(const char *s)
 		return DT_TOK_IDENT;
 	}
 
+	/*
+	 * Inside an enumeration declaration's { }'s region: must be an ident.
+	 * Checking for conflicts is handled by dt_decl_enumerator().  No
+	 * need to look anything up here.
+	 */
+	if (yypcb->pcb_enum_decl == 2)
+	    return DT_TOK_IDENT;
+
 	/*
 	 * If the lexeme is a global variable or likely identifier, then it is
 	 * an identifier token.
libdtrace/dt_pcb.h +1 -0
index 7c57f83220b28..b6a7620f4920c 100644
@@ -71,6 +71,7 @@ typedef struct dt_pcb {
 	int pcb_parens;		/* number of open parentheses in lexer */
 	int pcb_sou_type;	/* lexer in struct/union type name */
 	int pcb_sou_deref;	/* lexer in struct/union dereference */
+	int pcb_enum_decl;	/* lexer in enum declaration: 2 for inside { }. */
 	int pcb_xlator_input;	/* in translator input type */
 	int pcb_array_dimens;	/* in array dimensions */
 	int pcb_alloca_taints;	/* number of alloca taint changes */
Signature · 7 lines
2.48.1.283.g18c60a128c


_______________________________________________
DTrace-devel mailing list
[email protected]
https://oss.oracle.com/mailman/listinfo/dtrace-devel
#3 lore raw

PATCH 3/4 test: enum tests

In reply to Nick Alcock

A couple of new tests verifying that type names appearing in enums are forbidden, as well as that kernel-visible identifiers are permitted; and a renaming of the D_UNKNOWN tests now that libctf can be assumed to be everywhere and it's probably more common to have a libctf that emits a good description of this failure than the converse.

(The previous commit changes the error messages in this case back to what they used to be in the old days, too.)

---
 ...iers.d => err.D_DECL_IDRED.RepeatIdentifiers.d} |  0
 .../enum/err.D_DECL_IDRED.RepeatIdentifiers.r      |  2 ++
 ....r.p => err.D_DECL_IDRED.RepeatIdentifiers.r.p} |  0
 ...dentifiers.d => err.D_SYNTAX.RepeatTypeNames.d} | 12 +++---------
 .../enum/err.D_UNKNOWN.RepeatIdentifiers.r         |  2 --
 ...OWN.RepeatIdentifiers.d => tst.EnumKernelDup.d} | 14 ++++++--------
 test/unittest/enum/tst.EnumKernelDup.r             |  1 +
 ...NKNOWN.dupenum.d => err.D_DECL_IDRED.dupenum.d} |  0
 test/unittest/types/err.D_DECL_IDRED.dupenum.r     |  2 ++
 ...WN.dupenum.r.p => err.D_DECL_IDRED.dupenum.r.p} |  0
 test/unittest/types/err.D_UNKNOWN.dupenum.r        |  2 --
 11 files changed, 14 insertions(+), 21 deletions(-)
 copy test/unittest/enum/{err.D_UNKNOWN.RepeatIdentifiers.d => err.D_DECL_IDRED.RepeatIdentifiers.d} (100%)
 create mode 100644 test/unittest/enum/err.D_DECL_IDRED.RepeatIdentifiers.r
 rename test/unittest/enum/{err.D_UNKNOWN.RepeatIdentifiers.r.p => err.D_DECL_IDRED.RepeatIdentifiers.r.p} (100%)
 copy test/unittest/enum/{err.D_UNKNOWN.RepeatIdentifiers.d => err.D_SYNTAX.RepeatTypeNames.d} (72%)
 delete mode 100644 test/unittest/enum/err.D_UNKNOWN.RepeatIdentifiers.r
 rename test/unittest/enum/{err.D_UNKNOWN.RepeatIdentifiers.d => tst.EnumKernelDup.d} (57%)
 create mode 100644 test/unittest/enum/tst.EnumKernelDup.r
 rename test/unittest/types/{err.D_UNKNOWN.dupenum.d => err.D_DECL_IDRED.dupenum.d} (100%)
 create mode 100644 test/unittest/types/err.D_DECL_IDRED.dupenum.r
 rename test/unittest/types/{err.D_UNKNOWN.dupenum.r.p => err.D_DECL_IDRED.dupenum.r.p} (100%)
 delete mode 100644 test/unittest/types/err.D_UNKNOWN.dupenum.r
test/unittest/enum/err.D_DECL_IDRED.RepeatIdentifiers.d renamed from test/unittest/enum/err.D_UNKNOWN.RepeatIdentifiers.d +0 -0
similarity index 100%
copy from test/unittest/enum/err.D_UNKNOWN.RepeatIdentifiers.d
copy to test/unittest/enum/err.D_DECL_IDRED.RepeatIdentifiers.d
test/unittest/enum/err.D_DECL_IDRED.RepeatIdentifiers.r new file +2 -0
new file mode 100644
index 0000000000000..424d6b0775810
@@ -0,0 +1,2 @@
+-- @@stderr --
+dtrace: failed to compile script test/unittest/enum/err.D_DECL_IDRED.RepeatIdentifiers.d: [D_DECL_IDRED] line 24: identifier redeclared: GREEN
test/unittest/enum/err.D_DECL_IDRED.RepeatIdentifiers.r.p renamed from test/unittest/enum/err.D_UNKNOWN.RepeatIdentifiers.r.p +0 -0
similarity index 100%
rename from test/unittest/enum/err.D_UNKNOWN.RepeatIdentifiers.r.p
rename to test/unittest/enum/err.D_DECL_IDRED.RepeatIdentifiers.r.p
test/unittest/enum/err.D_SYNTAX.RepeatTypeNames.d renamed from test/unittest/enum/err.D_UNKNOWN.RepeatIdentifiers.d +3 -9
similarity index 72%
copy from test/unittest/enum/err.D_UNKNOWN.RepeatIdentifiers.d
copy to test/unittest/enum/err.D_SYNTAX.RepeatTypeNames.d
index 43837c78af9f2..74afdebf98082 100644
@@ -7,22 +7,16 @@
 
 /*
  * ASSERTION:
- * Repeating the same identifier in the same enumeration will throw a compiler
- * error.
+ * Enumerations cannot have the same names as already-existing types.
  *
  * SECTION: Type and Constant Definitions/Enumerations
- *
- * NOTES:
- *
  */
 
 #pragma D option quiet
 
 enum colors {
-	RED,
-	GREEN,
-	GREEN = 2,
-	BLUE
+	int,
+	not_int
 };
 
 BEGIN
test/unittest/enum/err.D_UNKNOWN.RepeatIdentifiers.r deleted +0 -2
deleted file mode 100644
index 0bf0acdb0702b..0000000000000
@@ -1,2 +0,0 @@
--- @@stderr --
-dtrace: failed to compile script test/unittest/enum/err.D_UNKNOWN.RepeatIdentifiers.d: [D_UNKNOWN] line 24: failed to define enumerator 'GREEN': Duplicate member or variable name
test/unittest/enum/tst.EnumKernelDup.d renamed from test/unittest/enum/err.D_UNKNOWN.RepeatIdentifiers.d +6 -8
similarity index 57%
rename from test/unittest/enum/err.D_UNKNOWN.RepeatIdentifiers.d
rename to test/unittest/enum/tst.EnumKernelDup.d
index 43837c78af9f2..429e2d0a01f66 100644
@@ -1,14 +1,14 @@
 /*
  * Oracle Linux DTrace.
- * Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2006, 2020, Oracle and/or its affiliates. All rights reserved.
  * Licensed under the Universal Permissive License v 1.0 as shown at
  * http://oss.oracle.com/licenses/upl.
  */
 
 /*
  * ASSERTION:
- * Repeating the same identifier in the same enumeration will throw a compiler
- * error.
+ * Enumerations using names also used for enumerators in the kernel should not
+ * raise errors.
  *
  * SECTION: Type and Constant Definitions/Enumerations
  *
@@ -18,11 +18,9 @@
 
 #pragma D option quiet
 
-enum colors {
-	RED,
-	GREEN,
-	GREEN = 2,
-	BLUE
+enum dirs {
+	UP,
+	DOWN
 };
 
 BEGIN
test/unittest/enum/tst.EnumKernelDup.r new file +1 -0
new file mode 100644
index 0000000000000..8b137891791fe
@@ -0,0 +1 @@
+
test/unittest/types/err.D_DECL_IDRED.dupenum.d renamed from test/unittest/types/err.D_UNKNOWN.dupenum.d +0 -0
similarity index 100%
rename from test/unittest/types/err.D_UNKNOWN.dupenum.d
rename to test/unittest/types/err.D_DECL_IDRED.dupenum.d
test/unittest/types/err.D_DECL_IDRED.dupenum.r new file +2 -0
new file mode 100644
index 0000000000000..0b6369e523cb2
@@ -0,0 +1,2 @@
+-- @@stderr --
+dtrace: failed to compile script test/unittest/types/err.D_DECL_IDRED.dupenum.d: [D_DECL_IDRED] line 18: identifier redeclared: x
test/unittest/types/err.D_DECL_IDRED.dupenum.r.p renamed from test/unittest/types/err.D_UNKNOWN.dupenum.r.p +0 -0
similarity index 100%
rename from test/unittest/types/err.D_UNKNOWN.dupenum.r.p
rename to test/unittest/types/err.D_DECL_IDRED.dupenum.r.p
test/unittest/types/err.D_UNKNOWN.dupenum.r deleted +0 -2
deleted file mode 100644
index 2d6aa3069b94d..0000000000000
@@ -1,2 +0,0 @@
--- @@stderr --
-dtrace: failed to compile script test/unittest/types/err.D_UNKNOWN.dupenum.d: [D_UNKNOWN] line 18: failed to define enumerator 'x': Duplicate member or variable name
Signature · 1 line
2.48.1.283.g18c60a128c
Reviewed-by on v1 3/4
#4 lore raw

Re: [PATCH 3/4] test: enum tests

Quoted 10 lines · Nick Alcock

A couple of new tests verifying that type names appearing in enums are forbidden, as well as that kernel-visible identifiers are permitted; and a renaming of the D_UNKNOWN tests now that libctf can be assumed to be everywhere and it's probably more common to have a libctf that emits a good description of this failure than the converse.

(The previous commit changes the error messages in this case back to what they used to be in the old days, too.)

Quoted 156 lines
---
 ...iers.d => err.D_DECL_IDRED.RepeatIdentifiers.d} |  0
 .../enum/err.D_DECL_IDRED.RepeatIdentifiers.r      |  2 ++
 ....r.p => err.D_DECL_IDRED.RepeatIdentifiers.r.p} |  0
 ...dentifiers.d => err.D_SYNTAX.RepeatTypeNames.d} | 12 +++---------
 .../enum/err.D_UNKNOWN.RepeatIdentifiers.r         |  2 --
 ...OWN.RepeatIdentifiers.d => tst.EnumKernelDup.d} | 14 ++++++--------
 test/unittest/enum/tst.EnumKernelDup.r             |  1 +
 ...NKNOWN.dupenum.d => err.D_DECL_IDRED.dupenum.d} |  0
 test/unittest/types/err.D_DECL_IDRED.dupenum.r     |  2 ++
 ...WN.dupenum.r.p => err.D_DECL_IDRED.dupenum.r.p} |  0
 test/unittest/types/err.D_UNKNOWN.dupenum.r        |  2 --
 11 files changed, 14 insertions(+), 21 deletions(-)
 copy test/unittest/enum/{err.D_UNKNOWN.RepeatIdentifiers.d => err.D_DECL_IDRED.RepeatIdentifiers.d} (100%)
 create mode 100644 test/unittest/enum/err.D_DECL_IDRED.RepeatIdentifiers.r
 rename test/unittest/enum/{err.D_UNKNOWN.RepeatIdentifiers.r.p => err.D_DECL_IDRED.RepeatIdentifiers.r.p} (100%)
 copy test/unittest/enum/{err.D_UNKNOWN.RepeatIdentifiers.d => err.D_SYNTAX.RepeatTypeNames.d} (72%)
 delete mode 100644 test/unittest/enum/err.D_UNKNOWN.RepeatIdentifiers.r
 rename test/unittest/enum/{err.D_UNKNOWN.RepeatIdentifiers.d => tst.EnumKernelDup.d} (57%)
 create mode 100644 test/unittest/enum/tst.EnumKernelDup.r
 rename test/unittest/types/{err.D_UNKNOWN.dupenum.d => err.D_DECL_IDRED.dupenum.d} (100%)
 create mode 100644 test/unittest/types/err.D_DECL_IDRED.dupenum.r
 rename test/unittest/types/{err.D_UNKNOWN.dupenum.r.p => err.D_DECL_IDRED.dupenum.r.p} (100%)
 delete mode 100644 test/unittest/types/err.D_UNKNOWN.dupenum.r
test/unittest/enum/err.D_DECL_IDRED.RepeatIdentifiers.d renamed from test/unittest/enum/err.D_UNKNOWN.RepeatIdentifiers.d +0 -0
similarity index 100%
copy from test/unittest/enum/err.D_UNKNOWN.RepeatIdentifiers.d
copy to test/unittest/enum/err.D_DECL_IDRED.RepeatIdentifiers.d
test/unittest/enum/err.D_DECL_IDRED.RepeatIdentifiers.r new file +2 -0
new file mode 100644
index 0000000000000..424d6b0775810
@@ -0,0 +1,2 @@
+-- @@stderr --
+dtrace: failed to compile script test/unittest/enum/err.D_DECL_IDRED.RepeatIdentifiers.d: [D_DECL_IDRED] line 24: identifier redeclared: GREEN
test/unittest/enum/err.D_DECL_IDRED.RepeatIdentifiers.r.p renamed from test/unittest/enum/err.D_UNKNOWN.RepeatIdentifiers.r.p +0 -0
similarity index 100%
rename from test/unittest/enum/err.D_UNKNOWN.RepeatIdentifiers.r.p
rename to test/unittest/enum/err.D_DECL_IDRED.RepeatIdentifiers.r.p
test/unittest/enum/err.D_SYNTAX.RepeatTypeNames.d renamed from test/unittest/enum/err.D_UNKNOWN.RepeatIdentifiers.d +3 -9
similarity index 72%
copy from test/unittest/enum/err.D_UNKNOWN.RepeatIdentifiers.d
copy to test/unittest/enum/err.D_SYNTAX.RepeatTypeNames.d
index 43837c78af9f2..74afdebf98082 100644
@@ -7,22 +7,16 @@
 
 /*
  * ASSERTION:
- * Repeating the same identifier in the same enumeration will throw a compiler
- * error.
+ * Enumerations cannot have the same names as already-existing types.
  *
  * SECTION: Type and Constant Definitions/Enumerations
- *
- * NOTES:
- *
  */
 
 #pragma D option quiet
 
 enum colors {
-	RED,
-	GREEN,
-	GREEN = 2,
-	BLUE
+	int,
+	not_int
 };
 
 BEGIN
test/unittest/enum/err.D_UNKNOWN.RepeatIdentifiers.r deleted +0 -2
deleted file mode 100644
index 0bf0acdb0702b..0000000000000
@@ -1,2 +0,0 @@
--- @@stderr --
-dtrace: failed to compile script test/unittest/enum/err.D_UNKNOWN.RepeatIdentifiers.d: [D_UNKNOWN] line 24: failed to define enumerator 'GREEN': Duplicate member or variable name
test/unittest/enum/tst.EnumKernelDup.d renamed from test/unittest/enum/err.D_UNKNOWN.RepeatIdentifiers.d +6 -8
similarity index 57%
rename from test/unittest/enum/err.D_UNKNOWN.RepeatIdentifiers.d
rename to test/unittest/enum/tst.EnumKernelDup.d
index 43837c78af9f2..429e2d0a01f66 100644
@@ -1,14 +1,14 @@
 /*
  * Oracle Linux DTrace.
- * Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2006, 2020, Oracle and/or its affiliates. All rights reserved.
  * Licensed under the Universal Permissive License v 1.0 as shown at
  * http://oss.oracle.com/licenses/upl.
  */
 
 /*
  * ASSERTION:
- * Repeating the same identifier in the same enumeration will throw a compiler
- * error.
+ * Enumerations using names also used for enumerators in the kernel should not
+ * raise errors.
  *
  * SECTION: Type and Constant Definitions/Enumerations
  *
@@ -18,11 +18,9 @@
 
 #pragma D option quiet
 
-enum colors {
-	RED,
-	GREEN,
-	GREEN = 2,
-	BLUE
+enum dirs {
+	UP,
+	DOWN
 };
 
 BEGIN
test/unittest/enum/tst.EnumKernelDup.r new file +1 -0
new file mode 100644
index 0000000000000..8b137891791fe
@@ -0,0 +1 @@
+
test/unittest/types/err.D_DECL_IDRED.dupenum.d renamed from test/unittest/types/err.D_UNKNOWN.dupenum.d +0 -0
similarity index 100%
rename from test/unittest/types/err.D_UNKNOWN.dupenum.d
rename to test/unittest/types/err.D_DECL_IDRED.dupenum.d
test/unittest/types/err.D_DECL_IDRED.dupenum.r new file +2 -0
new file mode 100644
index 0000000000000..0b6369e523cb2
@@ -0,0 +1,2 @@
+-- @@stderr --
+dtrace: failed to compile script test/unittest/types/err.D_DECL_IDRED.dupenum.d: [D_DECL_IDRED] line 18: identifier redeclared: x
test/unittest/types/err.D_DECL_IDRED.dupenum.r.p renamed from test/unittest/types/err.D_UNKNOWN.dupenum.r.p +0 -0
similarity index 100%
rename from test/unittest/types/err.D_UNKNOWN.dupenum.r.p
rename to test/unittest/types/err.D_DECL_IDRED.dupenum.r.p
test/unittest/types/err.D_UNKNOWN.dupenum.r deleted +0 -2
deleted file mode 100644
index 2d6aa3069b94d..0000000000000
@@ -1,2 +0,0 @@
--- @@stderr --
-dtrace: failed to compile script test/unittest/types/err.D_UNKNOWN.dupenum.d: [D_UNKNOWN] line 18: failed to define enumerator 'x': Duplicate member or variable name
Signature · 1 line
2.48.1.283.g18c60a128c
#5 lore raw

PATCH 4/4 test: fix test failure when no /usr/sbin/dtrace exists

In reply to Nick Alcock

A missing $ led to this test spuriously failing in this case.

---
 test/unittest/usdt/tst.exec-dof-replacement.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
test/unittest/usdt/tst.exec-dof-replacement.sh +1 -1
index b7ec5f2dc5e92..81833cc8b77f8 100755
@@ -33,7 +33,7 @@ provider test_prov {
 };
 EOF
 
-if ! { $dtrace $dt_flags -h -s prov1.d && dtrace -h -s prov2.d; } then
+if ! { $dtrace $dt_flags -h -s prov1.d && $dtrace -h -s prov2.d; } then
 	echo "failed to generate header files" >&2
 	exit 1
 fi
Signature · 1 line
2.48.1.283.g18c60a128c
#6 lore raw

Re: [PATCH 4/4] test: fix test failure when no /usr/sbin/dtrace exists

Okay, but should it even be $dtrace $dt_flags?  If for no other reason than symmetry with prov1.d?

Quoted 20 lines · Nick Alcock

A missing $ led to this test spuriously failing in this case.

---
  test/unittest/usdt/tst.exec-dof-replacement.sh | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
test/unittest/usdt/tst.exec-dof-replacement.sh +1 -1
index b7ec5f2dc5e92..81833cc8b77f8 100755
@@ -33,7 +33,7 @@ provider test_prov {
  };
  EOF
 
-if ! { $dtrace $dt_flags -h -s prov1.d && dtrace -h -s prov2.d; } then
+if ! { $dtrace $dt_flags -h -s prov1.d && $dtrace -h -s prov2.d; } then
  	echo "failed to generate header files" >&2
  	exit 1
  fi
#7 lore raw

Re: [PATCH 4/4] test: fix test failure when no /usr/sbin/dtrace exists

On 18 Sep 2025, Eugene Loh uttered the following:

Quoted 1 line

Okay, but should it even be $dtrace $dt_flags?  If for no other reason than symmetry with prov1.d?

... I guess so. Missed that. Can fix if you like.

Signature · 1 line
NULL && (void)
#8 lore raw

PATCH v2 4/4 test: fix test failure when no /usr/sbin/dtrace exists

In reply to Eugene Loh

A missing $ led to this test spuriously failing in this case.

---
 test/unittest/usdt/tst.exec-dof-replacement.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
test/unittest/usdt/tst.exec-dof-replacement.sh +1 -1
index b7ec5f2dc5e92..fc04c61d231a0 100755
@@ -33,7 +33,7 @@ provider test_prov {
 };
 EOF
 
-if ! { $dtrace $dt_flags -h -s prov1.d && dtrace -h -s prov2.d; } then
+if ! { $dtrace $dt_flags -h -s prov1.d && $dtrace $dt_flags -h -s prov2.d; } then
 	echo "failed to generate header files" >&2
 	exit 1
 fi
Signature · 1 line
2.51.0.284.g117bcb8de7
Reviewed-by on v1 4/4
#9 lore raw

Re: [DTrace-devel] [PATCH 4/4] test: fix test failure when no /usr/sbin/dtrace exists

In reply to Nick Alcock
Quoted 3 lines · Nick Alcock via DTrace-devel

A missing $ led to this test spuriously failing in this case.

Quoted 25 lines
---
 test/unittest/usdt/tst.exec-dof-replacement.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
test/unittest/usdt/tst.exec-dof-replacement.sh +1 -1
index b7ec5f2dc5e92..81833cc8b77f8 100755
@@ -33,7 +33,7 @@ provider test_prov {
 };
 EOF
 
-if ! { $dtrace $dt_flags -h -s prov1.d && dtrace -h -s prov2.d; } then
+if ! { $dtrace $dt_flags -h -s prov1.d && $dtrace -h -s prov2.d; } then
 	echo "failed to generate header files" >&2
 	exit 1
 fi
Signature · 7 lines
2.48.1.283.g18c60a128c


_______________________________________________
DTrace-devel mailing list
[email protected]
https://oss.oracle.com/mailman/listinfo/dtrace-devel
Reviewed-by on v1 1/4
#10 lore raw
In reply to Nick Alcock
Quoted 9 lines · Nick Alcock

The interaction between YYDEBUG and the yydebug extern variable has changed repeatedly in the various iterations of flex and bison. The one thing that is consistent is that yydebug is not used if YYDEBUG is unset or set to 0; if it's set to 1, the parser skeleton defines it for you.

So (now that -fno-common is on by default) dl_lex.l should not be defining yydebug itself, and dt_impl.h should only be declaring it extern if YYDEBUG is 1.

Quoted 5 lines

With this in place, we link and run with the parser debugger set to the expected state when compiling with YYDEBUG 1, YYDEBUG 0, and YYDEBUG unset.

Quoted 44 lines
---
 libdtrace/dt_impl.h | 2 ++
 libdtrace/dt_lex.l  | 4 +---
 2 files changed, 3 insertions(+), 3 deletions(-)
libdtrace/dt_impl.h +2 -0
index 7d8e4432a24ad..9c4651a46baa6 100644
@@ -808,7 +808,9 @@ extern char yyintsuffix[4];	/* int token suffix ([uUlL]*) */
 extern int yyintdecimal;	/* int token is decimal (1) or octal/hex (0) */
 extern char *yytext;		/* lex input buffer */
 extern int yylineno;		/* lex line number */
+#if defined(YYDEBUG) && YYDEBUG == 1
 extern int yydebug;		/* lex debugging */
+#endif
 extern dt_node_t *yypragma;	/* lex token list for control lines */
 
 extern const dtrace_attribute_t _dtrace_maxattr; /* maximum attributes */
libdtrace/dt_lex.l +1 -3
index e8f3bc8c25bb0..9f12f5c7ca289 100644
@@ -21,8 +21,6 @@
 static int id_or_type(const char *);
 static size_t dt_input(char *buf, size_t max_size);
 
-int yydebug;
-
 #define YY_INPUT(buf,result,max_size)                                   \
         result = dt_input(buf,max_size);
 
@@ -663,7 +661,7 @@ if (yypcb->pcb_token != 0) {
 void
 yybegin(yystate_t state)
 {
-#ifdef	YYDEBUG
+#if defined(YYDEBUG) && YYDEBUG == 1
 	yydebug = _dtrace_debug;
 #endif
 	if (yypcb->pcb_yystate == state)
Signature · 1 line
2.48.1.283.g18c60a128c