diff options
Diffstat (limited to 'tools/perf/util/parse-events.l')
| -rw-r--r-- | tools/perf/util/parse-events.l | 25 | 
1 files changed, 21 insertions, 4 deletions
diff --git a/tools/perf/util/parse-events.l b/tools/perf/util/parse-events.l index c42edeac451f..6680e4fb7967 100644 --- a/tools/perf/util/parse-events.l +++ b/tools/perf/util/parse-events.l @@ -8,6 +8,9 @@  %{  #include <errno.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <unistd.h>  #include "../perf.h"  #include "parse-events.h"  #include "parse-events-bison.h" @@ -53,9 +56,8 @@ static int str(yyscan_t scanner, int token)  	return token;  } -static bool isbpf(yyscan_t scanner) +static bool isbpf_suffix(char *text)  { -	char *text = parse_events_get_text(scanner);  	int len = strlen(text);  	if (len < 2) @@ -68,6 +70,17 @@ static bool isbpf(yyscan_t scanner)  	return false;  } +static bool isbpf(yyscan_t scanner) +{ +	char *text = parse_events_get_text(scanner); +	struct stat st; + +	if (!isbpf_suffix(text)) +		return false; + +	return stat(text, &st) == 0; +} +  /*   * This function is called when the parser gets two kind of input:   * @@ -141,6 +154,10 @@ do {							\  	yycolumn += yyleng;				\  } while (0); +#define USER_REJECT		\ +	yycolumn -= yyleng;	\ +	REJECT +  %}  %x mem @@ -322,8 +339,8 @@ r{num_raw_hex}		{ return raw(yyscanner); }  {num_hex}		{ return value(yyscanner, 16); }  {modifier_event}	{ return str(yyscanner, PE_MODIFIER_EVENT); } -{bpf_object}		{ if (!isbpf(yyscanner)) REJECT; return str(yyscanner, PE_BPF_OBJECT); } -{bpf_source}		{ if (!isbpf(yyscanner)) REJECT; return str(yyscanner, PE_BPF_SOURCE); } +{bpf_object}		{ if (!isbpf(yyscanner)) USER_REJECT; return str(yyscanner, PE_BPF_OBJECT); } +{bpf_source}		{ if (!isbpf(yyscanner)) USER_REJECT; return str(yyscanner, PE_BPF_SOURCE); }  {name}			{ return pmu_str_check(yyscanner); }  "/"			{ BEGIN(config); return '/'; }  -			{ return '-'; }  |