Blame SOURCES/libtraceevent-Handle-parsing-of-REC-case.patch

cad6f9
From 62823da1bd46f24e2b498513a809011dfe16cd9b Mon Sep 17 00:00:00 2001
cad6f9
From: "Steven Rostedt (VMware)" <rostedt@goodmis.org>
cad6f9
Date: Tue, 8 Jun 2021 17:27:44 -0400
cad6f9
Subject: [PATCH] libtraceevent: Handle parsing of "(REC)->" case
cad6f9
cad6f9
If a trace event wraps the special __entry variable to dereference it with
cad6f9
parenthesis, it shows up in the trace event format file wrapping the
cad6f9
"(REC)" as well. For example, the "func_repeats" event passed the __entry
cad6f9
into a helper macro in the TP_printk() portion, and the macro correctly
cad6f9
wrapped its parameter in parenthesis. This caused the output to show:
cad6f9
cad6f9
 "(((u64)(REC)->top_delta_ts << 32) | (REC)->bottom_delta_ts)"
cad6f9
cad6f9
The parser then failed to parse the "(REC)->" portion, as it expected the
cad6f9
"->" to appear directly after the "REC". This is not a requirement, and
cad6f9
the parser should be able to handle such cases.
cad6f9
cad6f9
When this occurred, trace-cmd would error with the following message:
cad6f9
cad6f9
trace-cmd: No such file or directory
cad6f9
  Error: expected type 4 but read 5
cad6f9
cad6f9
Link: https://lore.kernel.org/linux-trace-devel/20210608172744.796e93b7@gandalf.local.home
cad6f9
cad6f9
Fixes: 6582b0a ("tools/events: Add files to create libtraceevent.a")
cad6f9
Reported-by: Julia Lawall <julia.lawall@inria.fr>
cad6f9
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
cad6f9
---
cad6f9
 src/event-parse.c | 27 ++++++++++++++++++++++++---
cad6f9
 1 file changed, 24 insertions(+), 3 deletions(-)
cad6f9
cad6f9
diff --git a/src/event-parse.c b/src/event-parse.c
cad6f9
index 97c1a97..1217491 100644
cad6f9
--- a/src/event-parse.c
cad6f9
+++ b/src/event-parse.c
cad6f9
@@ -2311,8 +2311,19 @@ process_entry(struct tep_event *event __maybe_unused, struct tep_print_arg *arg,
cad6f9
 	char *field;
cad6f9
 	char *token;
cad6f9
 
cad6f9
-	if (read_expected(TEP_EVENT_OP, "->") < 0)
cad6f9
-		goto out_err;
cad6f9
+	type = read_token_item(&token);
cad6f9
+	/*
cad6f9
+	 * Check if REC happens to be surrounded by parenthesis, and
cad6f9
+	 * return if that's the case, as "(REC)->" is valid.
cad6f9
+	 * but return TEP_EVENT_ITEM.
cad6f9
+	 */
cad6f9
+	if (type == TEP_EVENT_DELIM && strcmp(token, ")") == 0) {
cad6f9
+		*tok = token;
cad6f9
+		return TEP_EVENT_ITEM;
cad6f9
+	}
cad6f9
+
cad6f9
+	if (test_type_token(type, token,  TEP_EVENT_OP, "->"))
cad6f9
+		goto out_free;
cad6f9
 
cad6f9
 	if (read_expect_type(TEP_EVENT_ITEM, &token) < 0)
cad6f9
 		goto out_free;
cad6f9
@@ -2338,7 +2349,6 @@ process_entry(struct tep_event *event __maybe_unused, struct tep_print_arg *arg,
cad6f9
 
cad6f9
  out_free:
cad6f9
 	free_token(token);
cad6f9
- out_err:
cad6f9
 	*tok = NULL;
cad6f9
 	return TEP_EVENT_ERROR;
cad6f9
 }
cad6f9
@@ -3033,6 +3043,17 @@ process_paren(struct tep_event *event, struct tep_print_arg *arg, char **tok)
cad6f9
 	if (type == TEP_EVENT_ERROR)
cad6f9
 		goto out_free;
cad6f9
 
cad6f9
+	/*
cad6f9
+	 * If REC is surrounded by parenthesis, the process_arg()
cad6f9
+	 * will return TEP_EVENT_ITEM with token == ")". In
cad6f9
+	 * this case, we need to continue processing the item
cad6f9
+	 * and return.
cad6f9
+	 */
cad6f9
+	if (type == TEP_EVENT_ITEM && strcmp(token, ")") == 0) {
cad6f9
+		free_token(token);
cad6f9
+		return process_entry(event, arg, tok);
cad6f9
+	}
cad6f9
+
cad6f9
 	if (test_type_token(type, token, TEP_EVENT_DELIM, ")"))
cad6f9
 		goto out_free;
cad6f9
 
cad6f9
-- 
cad6f9
2.31.1
cad6f9