lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20241128133553.823722-6-yangjihong@bytedance.com>
Date: Thu, 28 Nov 2024 21:35:46 +0800
From: Yang Jihong <yangjihong@...edance.com>
To: peterz@...radead.org,
	mingo@...hat.com,
	acme@...nel.org,
	namhyung@...nel.org,
	mark.rutland@....com,
	alexander.shishkin@...ux.intel.com,
	jolsa@...nel.org,
	irogers@...gle.com,
	adrian.hunter@...el.com,
	kan.liang@...ux.intel.com,
	james.clark@....com,
	linux-perf-users@...r.kernel.org,
	linux-kernel@...r.kernel.org
Cc: yangjihong@...edance.com
Subject: [RFC 05/12] perf event action: Add parsing call expr support

Add support for parsing function call expression, the format is similar to
C language function call, with parameters specified after function name,
inside the parentheses and separated with a comma.

Signed-off-by: Yang Jihong <yangjihong@...edance.com>
---
 tools/perf/util/parse-action.c | 25 +++++++++++++++
 tools/perf/util/parse-action.h |  5 +++
 tools/perf/util/parse-action.l |  3 ++
 tools/perf/util/parse-action.y | 56 +++++++++++++++++++++++++++++++---
 4 files changed, 85 insertions(+), 4 deletions(-)

diff --git a/tools/perf/util/parse-action.c b/tools/perf/util/parse-action.c
index 7e5ca889d5b9..40e7c8aad7be 100644
--- a/tools/perf/util/parse-action.c
+++ b/tools/perf/util/parse-action.c
@@ -9,6 +9,7 @@
  *   - constant:
  *     - integer
  *     - string
+ *   - call:
  */
 
 #include "util/debug.h"
@@ -232,8 +233,32 @@ static struct evtact_expr_class expr_const = {
 	.set_ops = expr_const_set_ops,
 };
 
+static struct evtact_expr_ops *expr_call_ops_list[EVTACT_EXPR_CALL_TYPE_MAX] = {
+};
+
+static int expr_call_set_ops(struct evtact_expr *expr, u32 opcode)
+{
+	if (opcode >= EVTACT_EXPR_CALL_TYPE_MAX) {
+		pr_err("expr_call opcode invalid: %u\n", opcode);
+		return -EINVAL;
+	}
+
+	if (expr_call_ops_list[opcode] == NULL) {
+		pr_err("expr_call opcode not supported: %u\n", opcode);
+		return -ENOTSUP;
+	}
+
+	expr->ops = expr_call_ops_list[opcode];
+	return 0;
+}
+
+static struct evtact_expr_class expr_call = {
+	.set_ops = expr_call_set_ops,
+};
+
 static struct evtact_expr_class *expr_class_list[EVTACT_EXPR_TYPE_MAX] = {
 	[EVTACT_EXPR_TYPE_CONST]   = &expr_const,
+	[EVTACT_EXPR_TYPE_CALL]    = &expr_call,
 };
 
 int parse_action_expr__set_class(enum evtact_expr_type type,
diff --git a/tools/perf/util/parse-action.h b/tools/perf/util/parse-action.h
index ec422f8a05a7..30c2fd6e81d0 100644
--- a/tools/perf/util/parse-action.h
+++ b/tools/perf/util/parse-action.h
@@ -10,6 +10,7 @@
 
 enum evtact_expr_type {
 	EVTACT_EXPR_TYPE_CONST,
+	EVTACT_EXPR_TYPE_CALL,
 	EVTACT_EXPR_TYPE_MAX,
 };
 
@@ -19,6 +20,10 @@ enum evtact_expr_const_type {
 	EVTACT_EXPR_CONST_TYPE_MAX,
 };
 
+enum evtact_expr_call_type {
+	EVTACT_EXPR_CALL_TYPE_MAX,
+};
+
 struct evtact_expr;
 struct evtact_expr_ops {
 	int (*new)(struct evtact_expr *expr, void *data, int size);
diff --git a/tools/perf/util/parse-action.l b/tools/perf/util/parse-action.l
index f76240276b61..189f73dfc3b1 100644
--- a/tools/perf/util/parse-action.l
+++ b/tools/perf/util/parse-action.l
@@ -92,6 +92,9 @@ ident		[_a-zA-Z][_a-zA-Z0-9]*
 {space}		{ }
 
 ";"		{ return SEMI; }
+"("		{ return LP;   }
+")"		{ return RP;   }
+","		{ return COM;  }
 
 \"		{
 			int ret;
diff --git a/tools/perf/util/parse-action.y b/tools/perf/util/parse-action.y
index 4922b2d94aee..1b162c694218 100644
--- a/tools/perf/util/parse-action.y
+++ b/tools/perf/util/parse-action.y
@@ -35,15 +35,18 @@ static void parse_action_error(struct list_head *expr __maybe_unused,
 	struct evtact_expr *expr;
 	struct list_head *list;
 	unsigned long long num;
+	u32 opcode;
 }
 
-%token IDENT ERROR NUMBER STRING
-%token SEMI
-%type <expr> action_term expr_term
+%token IDENT ERROR NUMBER STRING CALL
+%token SEMI LP RP COM
+%type <expr> action_term expr_term expr_call_term
 %destructor { parse_action_expr__free($$); } <expr>
 %type <str> IDENT
 %type <num> NUMBER
 %type <str> STRING
+%type <opcode> CALL
+%type <list> opnds
 
 %%
 
@@ -64,11 +67,56 @@ action_term
 }
 
 action_term:
-expr_term
+expr_call_term
 {
 	$$ = $1;
 }
 
+expr_call_term:
+CALL LP RP
+{
+	$$ = parse_action_expr__new(evtact_expr_id_encode(EVTACT_EXPR_TYPE_CALL, $1), NULL, NULL, 0);
+	if ($$ == NULL)
+		YYERROR;
+}
+|
+CALL LP opnds RP
+{
+	$$ = parse_action_expr__new(evtact_expr_id_encode(EVTACT_EXPR_TYPE_CALL, $1), $3, NULL, 0);
+	if ($$ == NULL)
+		YYERROR;
+}
+|
+IDENT LP RP
+{
+	$$ = NULL;
+	pr_err("unknown function '%s()'\n", $1);
+	free($1);
+	YYERROR;
+}
+|
+IDENT LP opnds RP
+{
+	$$ = NULL;
+	pr_err("unknown function '%s()'\n", $1);
+	parse_action_expr__free_opnds($3);
+	free($1);
+	YYERROR;
+}
+
+opnds:
+opnds COM expr_term
+{
+	list_add_tail(&$3->list, $1);
+	$$ = $1;
+}
+|
+expr_term
+{
+	INIT_LIST_HEAD(&$1->list);
+	$$ = &$1->list;
+}
+
 expr_term:
 NUMBER
 {
-- 
2.25.1


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ