tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

dtrace vs. lex

dtrace's use of lex sometimes gets confused about EOF.
the flex-generated code does some fancy stuff with EOF that
I haven't looked at enough to completely understand yet,
and can result in the last of several calls to yyparse()
that is made to set up the dtrace library state thinking that
the string it's trying to parse is empty, which leads dtrace
to give a bogus error.

I think what needs to be done is call yyrestart() before
each subsequent call to yyparse(), and the attached patch
does allow dtrace to work on a script that previously failed.
is this the right way to deal with this?

Index: src/external/cddl/osnet/dist/lib/libdtrace/common/dt_cc.c
RCS file: 
retrieving revision 1.2
diff -u -p -r1.2 dt_cc.c
--- src/external/cddl/osnet/dist/lib/libdtrace/common/dt_cc.c   21 Feb 2010 
00:49:54 -0000      1.2
+++ src/external/cddl/osnet/dist/lib/libdtrace/common/dt_cc.c   11 Jun 2012 
15:44:46 -0000
@@ -2216,6 +2216,7 @@ dt_compile(dtrace_hdl_t *dtp, int contex
         * will longjmp back to pcb_jmpbuf to abort.  If parsing succeeds,
         * we optionally display the parse tree if debugging is enabled.
+       yyrestart(pcb.pcb_fileptr);
        if (yyparse() != 0 || yypcb->pcb_root == NULL)
                xyerror(D_EMPTY, "empty D program translation unit\n");
Index: src/external/cddl/osnet/dist/lib/libdtrace/common/dt_impl.h
RCS file: 
retrieving revision 1.5
diff -u -p -r1.5 dt_impl.h
--- src/external/cddl/osnet/dist/lib/libdtrace/common/dt_impl.h 15 May 2011 
18:33:33 -0000      1.5
+++ src/external/cddl/osnet/dist/lib/libdtrace/common/dt_impl.h 11 Jun 2012 
15:45:10 -0000
@@ -664,6 +664,7 @@ extern int yyintdecimal;    /* int token is
 extern char yytext[];          /* lex input buffer */
 extern int yylineno;           /* lex line number */
 extern int yydebug;            /* lex debugging */
+extern void yyrestart(FILE *);
 extern dt_node_t *yypragma;    /* lex token list for control lines */
 extern const dtrace_attribute_t _dtrace_maxattr; /* maximum attributes */

Home | Main Index | Thread Index | Old Index