* [PATCH 1/4] parser: fix parser debugging yet again
@ 2025-09-18 18:03 Nick Alcock
2025-09-18 18:03 ` [PATCH 2/4] lexer: the things inside an enum { ... } declaration are identifiers Nick Alcock
` (3 more replies)
0 siblings, 4 replies; 11+ messages in thread
From: Nick Alcock @ 2025-09-18 18:03 UTC (permalink / raw)
To: dtrace, dtrace-devel
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.
Signed-off-by: Nick Alcock <nick.alcock@oracle.com>
---
libdtrace/dt_impl.h | 2 ++
libdtrace/dt_lex.l | 4 +---
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/libdtrace/dt_impl.h b/libdtrace/dt_impl.h
index 7d8e4432a24ad..9c4651a46baa6 100644
--- a/libdtrace/dt_impl.h
+++ b/libdtrace/dt_impl.h
@@ -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 */
diff --git a/libdtrace/dt_lex.l b/libdtrace/dt_lex.l
index e8f3bc8c25bb0..9f12f5c7ca289 100644
--- a/libdtrace/dt_lex.l
+++ b/libdtrace/dt_lex.l
@@ -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)
--
2.48.1.283.g18c60a128c
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 2/4] lexer: the things inside an enum { ... } declaration are identifiers
2025-09-18 18:03 [PATCH 1/4] parser: fix parser debugging yet again Nick Alcock
@ 2025-09-18 18:03 ` Nick Alcock
2025-10-03 0:00 ` [DTrace-devel] " Kris Van Hees
2025-09-18 18:03 ` [PATCH 3/4] test: enum tests Nick Alcock
` (2 subsequent siblings)
3 siblings, 1 reply; 11+ messages in thread
From: Nick Alcock @ 2025-09-18 18:03 UTC (permalink / raw)
To: dtrace, 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).
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
Signed-off-by: Nick Alcock <nick.alcock@oracle.com>
---
libdtrace/dt_lex.l | 17 +++++++++++++++--
libdtrace/dt_pcb.h | 1 +
2 files changed, 16 insertions(+), 2 deletions(-)
diff --git a/libdtrace/dt_lex.l b/libdtrace/dt_lex.l
index 9f12f5c7ca289..fd70aa0aa5803 100644
--- a/libdtrace/dt_lex.l
+++ b/libdtrace/dt_lex.l
@@ -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.
diff --git a/libdtrace/dt_pcb.h b/libdtrace/dt_pcb.h
index 7c57f83220b28..b6a7620f4920c 100644
--- a/libdtrace/dt_pcb.h
+++ b/libdtrace/dt_pcb.h
@@ -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 */
--
2.48.1.283.g18c60a128c
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 3/4] test: enum tests
2025-09-18 18:03 [PATCH 1/4] parser: fix parser debugging yet again Nick Alcock
2025-09-18 18:03 ` [PATCH 2/4] lexer: the things inside an enum { ... } declaration are identifiers Nick Alcock
@ 2025-09-18 18:03 ` Nick Alcock
2025-10-03 0:00 ` Kris Van Hees
2025-09-18 18:03 ` [PATCH 4/4] test: fix test failure when no /usr/sbin/dtrace exists Nick Alcock
2025-10-03 0:00 ` [PATCH 1/4] parser: fix parser debugging yet again Kris Van Hees
3 siblings, 1 reply; 11+ messages in thread
From: Nick Alcock @ 2025-09-18 18:03 UTC (permalink / raw)
To: dtrace, dtrace-devel
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.)
Signed-off-by: Nick Alcock <nick.alcock@oracle.com>
---
...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
diff --git a/test/unittest/enum/err.D_UNKNOWN.RepeatIdentifiers.d b/test/unittest/enum/err.D_DECL_IDRED.RepeatIdentifiers.d
similarity index 100%
copy from test/unittest/enum/err.D_UNKNOWN.RepeatIdentifiers.d
copy to test/unittest/enum/err.D_DECL_IDRED.RepeatIdentifiers.d
diff --git a/test/unittest/enum/err.D_DECL_IDRED.RepeatIdentifiers.r b/test/unittest/enum/err.D_DECL_IDRED.RepeatIdentifiers.r
new file mode 100644
index 0000000000000..424d6b0775810
--- /dev/null
+++ b/test/unittest/enum/err.D_DECL_IDRED.RepeatIdentifiers.r
@@ -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
diff --git a/test/unittest/enum/err.D_UNKNOWN.RepeatIdentifiers.r.p b/test/unittest/enum/err.D_DECL_IDRED.RepeatIdentifiers.r.p
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
diff --git a/test/unittest/enum/err.D_UNKNOWN.RepeatIdentifiers.d b/test/unittest/enum/err.D_SYNTAX.RepeatTypeNames.d
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
--- a/test/unittest/enum/err.D_UNKNOWN.RepeatIdentifiers.d
+++ b/test/unittest/enum/err.D_SYNTAX.RepeatTypeNames.d
@@ -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
diff --git a/test/unittest/enum/err.D_UNKNOWN.RepeatIdentifiers.r b/test/unittest/enum/err.D_UNKNOWN.RepeatIdentifiers.r
deleted file mode 100644
index 0bf0acdb0702b..0000000000000
--- a/test/unittest/enum/err.D_UNKNOWN.RepeatIdentifiers.r
+++ /dev/null
@@ -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
diff --git a/test/unittest/enum/err.D_UNKNOWN.RepeatIdentifiers.d b/test/unittest/enum/tst.EnumKernelDup.d
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
--- a/test/unittest/enum/err.D_UNKNOWN.RepeatIdentifiers.d
+++ b/test/unittest/enum/tst.EnumKernelDup.d
@@ -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
diff --git a/test/unittest/enum/tst.EnumKernelDup.r b/test/unittest/enum/tst.EnumKernelDup.r
new file mode 100644
index 0000000000000..8b137891791fe
--- /dev/null
+++ b/test/unittest/enum/tst.EnumKernelDup.r
@@ -0,0 +1 @@
+
diff --git a/test/unittest/types/err.D_UNKNOWN.dupenum.d b/test/unittest/types/err.D_DECL_IDRED.dupenum.d
similarity index 100%
rename from test/unittest/types/err.D_UNKNOWN.dupenum.d
rename to test/unittest/types/err.D_DECL_IDRED.dupenum.d
diff --git a/test/unittest/types/err.D_DECL_IDRED.dupenum.r b/test/unittest/types/err.D_DECL_IDRED.dupenum.r
new file mode 100644
index 0000000000000..0b6369e523cb2
--- /dev/null
+++ b/test/unittest/types/err.D_DECL_IDRED.dupenum.r
@@ -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
diff --git a/test/unittest/types/err.D_UNKNOWN.dupenum.r.p b/test/unittest/types/err.D_DECL_IDRED.dupenum.r.p
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
diff --git a/test/unittest/types/err.D_UNKNOWN.dupenum.r b/test/unittest/types/err.D_UNKNOWN.dupenum.r
deleted file mode 100644
index 2d6aa3069b94d..0000000000000
--- a/test/unittest/types/err.D_UNKNOWN.dupenum.r
+++ /dev/null
@@ -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
--
2.48.1.283.g18c60a128c
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 4/4] test: fix test failure when no /usr/sbin/dtrace exists
2025-09-18 18:03 [PATCH 1/4] parser: fix parser debugging yet again Nick Alcock
2025-09-18 18:03 ` [PATCH 2/4] lexer: the things inside an enum { ... } declaration are identifiers Nick Alcock
2025-09-18 18:03 ` [PATCH 3/4] test: enum tests Nick Alcock
@ 2025-09-18 18:03 ` Nick Alcock
2025-09-18 19:18 ` Eugene Loh
2025-10-03 0:01 ` [DTrace-devel] [PATCH " Kris Van Hees
2025-10-03 0:00 ` [PATCH 1/4] parser: fix parser debugging yet again Kris Van Hees
3 siblings, 2 replies; 11+ messages in thread
From: Nick Alcock @ 2025-09-18 18:03 UTC (permalink / raw)
To: dtrace, dtrace-devel
A missing $ led to this test spuriously failing in this case.
Signed-off-by: Nick Alcock <nick.alcock@oracle.com>
---
test/unittest/usdt/tst.exec-dof-replacement.sh | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/test/unittest/usdt/tst.exec-dof-replacement.sh b/test/unittest/usdt/tst.exec-dof-replacement.sh
index b7ec5f2dc5e92..81833cc8b77f8 100755
--- a/test/unittest/usdt/tst.exec-dof-replacement.sh
+++ b/test/unittest/usdt/tst.exec-dof-replacement.sh
@@ -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
--
2.48.1.283.g18c60a128c
^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH 4/4] test: fix test failure when no /usr/sbin/dtrace exists
2025-09-18 18:03 ` [PATCH 4/4] test: fix test failure when no /usr/sbin/dtrace exists Nick Alcock
@ 2025-09-18 19:18 ` Eugene Loh
2025-09-23 15:15 ` Nick Alcock
2025-09-23 15:31 ` [PATCH v2 " Nick Alcock
2025-10-03 0:01 ` [DTrace-devel] [PATCH " Kris Van Hees
1 sibling, 2 replies; 11+ messages in thread
From: Eugene Loh @ 2025-09-18 19:18 UTC (permalink / raw)
To: Nick Alcock, dtrace, dtrace-devel
Okay, but should it even be $dtrace $dt_flags? If for no other reason
than symmetry with prov1.d?
On 9/18/25 14:03, Nick Alcock wrote:
> A missing $ led to this test spuriously failing in this case.
>
> Signed-off-by: Nick Alcock <nick.alcock@oracle.com>
> ---
> test/unittest/usdt/tst.exec-dof-replacement.sh | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/test/unittest/usdt/tst.exec-dof-replacement.sh b/test/unittest/usdt/tst.exec-dof-replacement.sh
> index b7ec5f2dc5e92..81833cc8b77f8 100755
> --- a/test/unittest/usdt/tst.exec-dof-replacement.sh
> +++ b/test/unittest/usdt/tst.exec-dof-replacement.sh
> @@ -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
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 4/4] test: fix test failure when no /usr/sbin/dtrace exists
2025-09-18 19:18 ` Eugene Loh
@ 2025-09-23 15:15 ` Nick Alcock
2025-09-23 15:31 ` [PATCH v2 " Nick Alcock
1 sibling, 0 replies; 11+ messages in thread
From: Nick Alcock @ 2025-09-23 15:15 UTC (permalink / raw)
To: Eugene Loh; +Cc: dtrace, dtrace-devel
On 18 Sep 2025, Eugene Loh uttered the following:
> 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.
--
NULL && (void)
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH v2 4/4] test: fix test failure when no /usr/sbin/dtrace exists
2025-09-18 19:18 ` Eugene Loh
2025-09-23 15:15 ` Nick Alcock
@ 2025-09-23 15:31 ` Nick Alcock
1 sibling, 0 replies; 11+ messages in thread
From: Nick Alcock @ 2025-09-23 15:31 UTC (permalink / raw)
To: dtrace, dtrace-devel
A missing $ led to this test spuriously failing in this case.
Signed-off-by: Nick Alcock <nick.alcock@oracle.com>
---
test/unittest/usdt/tst.exec-dof-replacement.sh | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/test/unittest/usdt/tst.exec-dof-replacement.sh b/test/unittest/usdt/tst.exec-dof-replacement.sh
index b7ec5f2dc5e92..fc04c61d231a0 100755
--- a/test/unittest/usdt/tst.exec-dof-replacement.sh
+++ b/test/unittest/usdt/tst.exec-dof-replacement.sh
@@ -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
--
2.51.0.284.g117bcb8de7
^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH 1/4] parser: fix parser debugging yet again
2025-09-18 18:03 [PATCH 1/4] parser: fix parser debugging yet again Nick Alcock
` (2 preceding siblings ...)
2025-09-18 18:03 ` [PATCH 4/4] test: fix test failure when no /usr/sbin/dtrace exists Nick Alcock
@ 2025-10-03 0:00 ` Kris Van Hees
3 siblings, 0 replies; 11+ messages in thread
From: Kris Van Hees @ 2025-10-03 0:00 UTC (permalink / raw)
To: Nick Alcock; +Cc: dtrace, dtrace-devel
On Thu, Sep 18, 2025 at 07:03:35PM +0100, Nick Alcock wrote:
> 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.
>
> Signed-off-by: Nick Alcock <nick.alcock@oracle.com>
Reviewed-by: Kris Van Hees <kris.van.hees@oracle.com>
> ---
> libdtrace/dt_impl.h | 2 ++
> libdtrace/dt_lex.l | 4 +---
> 2 files changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/libdtrace/dt_impl.h b/libdtrace/dt_impl.h
> index 7d8e4432a24ad..9c4651a46baa6 100644
> --- a/libdtrace/dt_impl.h
> +++ b/libdtrace/dt_impl.h
> @@ -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 */
> diff --git a/libdtrace/dt_lex.l b/libdtrace/dt_lex.l
> index e8f3bc8c25bb0..9f12f5c7ca289 100644
> --- a/libdtrace/dt_lex.l
> +++ b/libdtrace/dt_lex.l
> @@ -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)
> --
> 2.48.1.283.g18c60a128c
>
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [DTrace-devel] [PATCH 2/4] lexer: the things inside an enum { ... } declaration are identifiers
2025-09-18 18:03 ` [PATCH 2/4] lexer: the things inside an enum { ... } declaration are identifiers Nick Alcock
@ 2025-10-03 0:00 ` Kris Van Hees
0 siblings, 0 replies; 11+ messages in thread
From: Kris Van Hees @ 2025-10-03 0:00 UTC (permalink / raw)
To: Nick Alcock; +Cc: dtrace, dtrace-devel
On Thu, Sep 18, 2025 at 07:03:36PM +0100, Nick Alcock via DTrace-devel wrote:
> 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
>
> Signed-off-by: Nick Alcock <nick.alcock@oracle.com>
Reviewed-by: Kris Van Hees <kris.van.hees@oracle.com>
> ---
> libdtrace/dt_lex.l | 17 +++++++++++++++--
> libdtrace/dt_pcb.h | 1 +
> 2 files changed, 16 insertions(+), 2 deletions(-)
>
> diff --git a/libdtrace/dt_lex.l b/libdtrace/dt_lex.l
> index 9f12f5c7ca289..fd70aa0aa5803 100644
> --- a/libdtrace/dt_lex.l
> +++ b/libdtrace/dt_lex.l
> @@ -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.
> diff --git a/libdtrace/dt_pcb.h b/libdtrace/dt_pcb.h
> index 7c57f83220b28..b6a7620f4920c 100644
> --- a/libdtrace/dt_pcb.h
> +++ b/libdtrace/dt_pcb.h
> @@ -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 */
> --
> 2.48.1.283.g18c60a128c
>
>
> _______________________________________________
> DTrace-devel mailing list
> DTrace-devel@oss.oracle.com
> https://oss.oracle.com/mailman/listinfo/dtrace-devel
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 3/4] test: enum tests
2025-09-18 18:03 ` [PATCH 3/4] test: enum tests Nick Alcock
@ 2025-10-03 0:00 ` Kris Van Hees
0 siblings, 0 replies; 11+ messages in thread
From: Kris Van Hees @ 2025-10-03 0:00 UTC (permalink / raw)
To: Nick Alcock; +Cc: dtrace, dtrace-devel
On Thu, Sep 18, 2025 at 07:03:37PM +0100, Nick Alcock wrote:
> 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.)
>
> Signed-off-by: Nick Alcock <nick.alcock@oracle.com>
Reviewed-by: Kris Van Hees <kris.van.hees@oracle.com>
> ---
> ...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
>
> diff --git a/test/unittest/enum/err.D_UNKNOWN.RepeatIdentifiers.d b/test/unittest/enum/err.D_DECL_IDRED.RepeatIdentifiers.d
> similarity index 100%
> copy from test/unittest/enum/err.D_UNKNOWN.RepeatIdentifiers.d
> copy to test/unittest/enum/err.D_DECL_IDRED.RepeatIdentifiers.d
> diff --git a/test/unittest/enum/err.D_DECL_IDRED.RepeatIdentifiers.r b/test/unittest/enum/err.D_DECL_IDRED.RepeatIdentifiers.r
> new file mode 100644
> index 0000000000000..424d6b0775810
> --- /dev/null
> +++ b/test/unittest/enum/err.D_DECL_IDRED.RepeatIdentifiers.r
> @@ -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
> diff --git a/test/unittest/enum/err.D_UNKNOWN.RepeatIdentifiers.r.p b/test/unittest/enum/err.D_DECL_IDRED.RepeatIdentifiers.r.p
> 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
> diff --git a/test/unittest/enum/err.D_UNKNOWN.RepeatIdentifiers.d b/test/unittest/enum/err.D_SYNTAX.RepeatTypeNames.d
> 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
> --- a/test/unittest/enum/err.D_UNKNOWN.RepeatIdentifiers.d
> +++ b/test/unittest/enum/err.D_SYNTAX.RepeatTypeNames.d
> @@ -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
> diff --git a/test/unittest/enum/err.D_UNKNOWN.RepeatIdentifiers.r b/test/unittest/enum/err.D_UNKNOWN.RepeatIdentifiers.r
> deleted file mode 100644
> index 0bf0acdb0702b..0000000000000
> --- a/test/unittest/enum/err.D_UNKNOWN.RepeatIdentifiers.r
> +++ /dev/null
> @@ -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
> diff --git a/test/unittest/enum/err.D_UNKNOWN.RepeatIdentifiers.d b/test/unittest/enum/tst.EnumKernelDup.d
> 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
> --- a/test/unittest/enum/err.D_UNKNOWN.RepeatIdentifiers.d
> +++ b/test/unittest/enum/tst.EnumKernelDup.d
> @@ -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
> diff --git a/test/unittest/enum/tst.EnumKernelDup.r b/test/unittest/enum/tst.EnumKernelDup.r
> new file mode 100644
> index 0000000000000..8b137891791fe
> --- /dev/null
> +++ b/test/unittest/enum/tst.EnumKernelDup.r
> @@ -0,0 +1 @@
> +
> diff --git a/test/unittest/types/err.D_UNKNOWN.dupenum.d b/test/unittest/types/err.D_DECL_IDRED.dupenum.d
> similarity index 100%
> rename from test/unittest/types/err.D_UNKNOWN.dupenum.d
> rename to test/unittest/types/err.D_DECL_IDRED.dupenum.d
> diff --git a/test/unittest/types/err.D_DECL_IDRED.dupenum.r b/test/unittest/types/err.D_DECL_IDRED.dupenum.r
> new file mode 100644
> index 0000000000000..0b6369e523cb2
> --- /dev/null
> +++ b/test/unittest/types/err.D_DECL_IDRED.dupenum.r
> @@ -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
> diff --git a/test/unittest/types/err.D_UNKNOWN.dupenum.r.p b/test/unittest/types/err.D_DECL_IDRED.dupenum.r.p
> 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
> diff --git a/test/unittest/types/err.D_UNKNOWN.dupenum.r b/test/unittest/types/err.D_UNKNOWN.dupenum.r
> deleted file mode 100644
> index 2d6aa3069b94d..0000000000000
> --- a/test/unittest/types/err.D_UNKNOWN.dupenum.r
> +++ /dev/null
> @@ -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
> --
> 2.48.1.283.g18c60a128c
>
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [DTrace-devel] [PATCH 4/4] test: fix test failure when no /usr/sbin/dtrace exists
2025-09-18 18:03 ` [PATCH 4/4] test: fix test failure when no /usr/sbin/dtrace exists Nick Alcock
2025-09-18 19:18 ` Eugene Loh
@ 2025-10-03 0:01 ` Kris Van Hees
1 sibling, 0 replies; 11+ messages in thread
From: Kris Van Hees @ 2025-10-03 0:01 UTC (permalink / raw)
To: Nick Alcock; +Cc: dtrace, dtrace-devel
On Thu, Sep 18, 2025 at 07:03:38PM +0100, Nick Alcock via DTrace-devel wrote:
> A missing $ led to this test spuriously failing in this case.
>
> Signed-off-by: Nick Alcock <nick.alcock@oracle.com>
Reviewed-by: Kris Van Hees <kris.van.hees@oracle.com>
> ---
> test/unittest/usdt/tst.exec-dof-replacement.sh | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/test/unittest/usdt/tst.exec-dof-replacement.sh b/test/unittest/usdt/tst.exec-dof-replacement.sh
> index b7ec5f2dc5e92..81833cc8b77f8 100755
> --- a/test/unittest/usdt/tst.exec-dof-replacement.sh
> +++ b/test/unittest/usdt/tst.exec-dof-replacement.sh
> @@ -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
> --
> 2.48.1.283.g18c60a128c
>
>
> _______________________________________________
> DTrace-devel mailing list
> DTrace-devel@oss.oracle.com
> https://oss.oracle.com/mailman/listinfo/dtrace-devel
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2025-10-03 0:01 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-18 18:03 [PATCH 1/4] parser: fix parser debugging yet again Nick Alcock
2025-09-18 18:03 ` [PATCH 2/4] lexer: the things inside an enum { ... } declaration are identifiers Nick Alcock
2025-10-03 0:00 ` [DTrace-devel] " Kris Van Hees
2025-09-18 18:03 ` [PATCH 3/4] test: enum tests Nick Alcock
2025-10-03 0:00 ` Kris Van Hees
2025-09-18 18:03 ` [PATCH 4/4] test: fix test failure when no /usr/sbin/dtrace exists Nick Alcock
2025-09-18 19:18 ` Eugene Loh
2025-09-23 15:15 ` Nick Alcock
2025-09-23 15:31 ` [PATCH v2 " Nick Alcock
2025-10-03 0:01 ` [DTrace-devel] [PATCH " Kris Van Hees
2025-10-03 0:00 ` [PATCH 1/4] parser: fix parser debugging yet again Kris Van Hees
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox