[apparmor] [patch 11/26] A few fixes/improvements to the lexer debug output

Seth Arnold seth.arnold at canonical.com
Thu Apr 17 06:10:03 UTC 2014


On Tue, Apr 15, 2014 at 10:22:18AM -0700, john.johansen at canonical.com wrote:
> Signed-off-by: John Johansen <john.johansen at canonical.com>

Some of this doesn't look right.

> ---
>  parser/parser_lex.l |   19 +++++++++----------
>  1 file changed, 9 insertions(+), 10 deletions(-)
> 
> --- 2.9-test.orig/parser/parser_lex.l
> +++ 2.9-test/parser/parser_lex.l
> @@ -52,7 +52,7 @@
>  /* #define DEBUG */
>  #ifdef DEBUG
>  static int yy_top_state(void);
> -#define PDEBUG(fmt, args...) printf("Lexer (Line %d) (state %s): " fmt, current_lineno, state_names[YY_START].c_str(), ## args)
> +#define PDEBUG(fmt, args...) fprintf(stderr, "Lexer (Line %d) (state %s): " fmt, current_lineno, state_names[YY_START].c_str(), ## args)
>  #else
>  #define PDEBUG(fmt, args...)	/* Do nothing */
>  #endif
> @@ -70,7 +70,7 @@
>  
>  #define RETURN_TOKEN(X) \
>  do { \
> -	DUMP_AND_DEBUG("Matched: %s\n", yytext); \
> +	DUMP_AND_DEBUG("Matched: '%s'	Returning(%s)\n", yytext, #X); \
>  	return (X); \
>  } while (0)
>  
> @@ -276,12 +276,12 @@
>  		char *filename = strndup(yytext, yyleng - 1);
>  		include_filename(filename + 1, *filename == '<');
>  		free(filename);
> -		yy_pop_state();
> +		POP();
>  	}
>  
>  	[^\<\>\" \t\n]+ {	/* filename */
>  		include_filename(yytext, 0);
> -		yy_pop_state();
> +		POP();
>  	}
>  }

The two cases above look odd; I haven't tested but I have the feeling that
these will print the <filename> in an #include <filename> statement.

>  
> @@ -425,7 +425,7 @@
>  	\r?\n	{
>  		DUMP_PREPROCESS;
>  		current_lineno++;
> -		yy_pop_state();
> +		POP();
>  	}

This calls DUMP_PREPROCESS twice in extremely quick succession and is
probably incorrect.

>  }
>  
> @@ -469,8 +469,7 @@
>  	write		{ RETURN_TOKEN(TOK_WRITE); }
>  	eavesdrop	{ RETURN_TOKEN(TOK_EAVESDROP); }
>  	{OPEN_PAREN}	{
> -			yy_push_state(LIST_VAL_MODE);
> -			RETURN_TOKEN(TOK_OPENPAREN);
> +			PUSH_AND_RETURN(LIST_VAL_MODE, TOK_OPENPAREN);
>  			}
>  	(r|w|rw|wr)/([[:space:],])	{
>  			yylval.mode = strdup(yytext);
> @@ -488,8 +487,8 @@
>  }
>  
>  #include/.*\r?\n	{
> -	/* Don't use push here as we don't want #include echoed out. It needs
> -	 * to be handled specially
> +	/* Don't use PUSH() macro here as we don't want #include echoed out.
> +	 * It needs to be handled specially
>  	 */ 
>  	yy_push_state(INCLUDE);
>  }
> @@ -576,7 +575,7 @@
>  <INITIAL,NETWORK_MODE,RLIMIT_MODE,MOUNT_MODE,DBUS_MODE>{
>  	{END_OF_RULE}	{
>  		if (YY_START != INITIAL)
> -			yy_pop_state();
> +			POP();
>  		RETURN_TOKEN(TOK_END_OF_RULE);
>  	}
>  
> 


Thanks
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 473 bytes
Desc: Digital signature
URL: <https://lists.ubuntu.com/archives/apparmor/attachments/20140416/05ca6d6d/attachment.pgp>


More information about the AppArmor mailing list