[DTrace-devel] [PATCH 1/4] parser: fix parser debugging yet again

Kris Van Hees kris.van.hees at oracle.com
Fri Oct 3 00:00:24 UTC 2025


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 at oracle.com>

Reviewed-by: Kris Van Hees <kris.van.hees at 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
> 



More information about the DTrace-devel mailing list