diff mbox series

[v3,2/2] libtraceevent: Keep the pointer to the field in args

Message ID 20210805133419.50802-2-y.karadz@gmail.com (mailing list archive)
State Superseded
Headers show
Series [v3,1/2] libtraceevent: Add dynamic_offset() | expand

Commit Message

Yordan Karadzhov Aug. 5, 2021, 1:34 p.m. UTC
From: Steven Rostedt <rostedt@goodmis.org>

In order to have tep_print_field() print the field closer to the way it
is printed via the "pretty_print" method, all field args, must keep a
pointer to the field it represents.

Suggested-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
Signed-off-by: Yordan Karadzhov (VMware) <y.karadz@gmail.com>
---
 src/event-parse.c | 60 +++++++++++++++++++++++++++--------------------
 1 file changed, 34 insertions(+), 26 deletions(-)
diff mbox series

Patch

diff --git a/src/event-parse.c b/src/event-parse.c
index fd6d916..331eb9f 100644
--- a/src/event-parse.c
+++ b/src/event-parse.c
@@ -2334,12 +2334,12 @@  process_entry(struct tep_event *event __maybe_unused, struct tep_print_arg *arg,
 	arg->type = TEP_PRINT_FIELD;
 	arg->field.name = field;
 
+	arg->field.field = tep_find_any_field(event, arg->field.name);
+
 	if (is_flag_field) {
-		arg->field.field = tep_find_any_field(event, arg->field.name);
 		arg->field.field->flags |= TEP_FIELD_IS_FLAG;
 		is_flag_field = 0;
 	} else if (is_symbolic_field) {
-		arg->field.field = tep_find_any_field(event, arg->field.name);
 		arg->field.field->flags |= TEP_FIELD_IS_SYMBOLIC;
 		is_symbolic_field = 0;
 	}
@@ -3103,7 +3103,7 @@  process_paren(struct tep_event *event, struct tep_print_arg *arg, char **tok)
 
 static enum tep_event_type
 process_str(struct tep_event *event __maybe_unused, struct tep_print_arg *arg,
-	    char **tok)
+	    char **field, char **tok)
 {
 	enum tep_event_type type;
 	char *token;
@@ -3111,6 +3111,7 @@  process_str(struct tep_event *event __maybe_unused, struct tep_print_arg *arg,
 	if (read_expect_type(TEP_EVENT_ITEM, &token) < 0)
 		goto out_free;
 
+	*field = token;
 	arg->type = TEP_PRINT_STRING;
 	arg->string.string = token;
 	arg->string.offset = -1;
@@ -3285,59 +3286,66 @@  process_function(struct tep_event *event, struct tep_print_arg *arg,
 		 char *token, char **tok)
 {
 	struct tep_function_handler *func;
+	int ret = TEP_EVENT_ERROR;
+	char *field = NULL;
 
 	if (strcmp(token, "__print_flags") == 0) {
-		free_token(token);
 		is_flag_field = 1;
-		return process_flags(event, arg, tok);
+		ret = process_flags(event, arg, tok);
+		goto done;
 	}
 	if (strcmp(token, "__print_symbolic") == 0) {
-		free_token(token);
 		is_symbolic_field = 1;
-		return process_symbols(event, arg, tok);
+		ret = process_symbols(event, arg, tok);
+		goto done;
 	}
 	if (strcmp(token, "__print_hex") == 0) {
-		free_token(token);
-		return process_hex(event, arg, tok);
+		ret = process_hex(event, arg, tok);
+		goto done;
 	}
 	if (strcmp(token, "__print_hex_str") == 0) {
-		free_token(token);
-		return process_hex_str(event, arg, tok);
+		ret = process_hex_str(event, arg, tok);
+		goto done;
 	}
 	if (strcmp(token, "__print_array") == 0) {
-		free_token(token);
-		return process_int_array(event, arg, tok);
+		ret = process_int_array(event, arg, tok);
+		goto done;
 	}
 	if (strcmp(token, "__get_str") == 0) {
-		free_token(token);
-		return process_str(event, arg, tok);
+		ret = process_str(event, arg, &field, tok);
+		goto done;
 	}
 	if (strcmp(token, "__get_bitmask") == 0) {
-		free_token(token);
-		return process_bitmask(event, arg, tok);
+		ret = process_bitmask(event, arg, tok);
+		goto done;
 	}
 	if (strcmp(token, "__get_dynamic_array") == 0) {
-		free_token(token);
-		return process_dynamic_array(event, arg, tok);
+		ret = process_dynamic_array(event, arg, tok);
+		goto done;
 	}
 	if (strcmp(token, "__get_dynamic_array_len") == 0) {
-		free_token(token);
-		return process_dynamic_array_len(event, arg, tok);
+		ret = process_dynamic_array_len(event, arg, tok);
+		goto done;
 	}
 	if (strcmp(token, "__builtin_expect") == 0) {
-		free_token(token);
-		return process_builtin_expect(event, arg, tok);
+		ret = process_builtin_expect(event, arg, tok);
+		goto done;
 	}
 
 	func = find_func_handler(event->tep, token);
 	if (func) {
-		free_token(token);
-		return process_func_handler(event, func, arg, tok);
+		ret = process_func_handler(event, func, arg, tok);
+		goto done;
 	}
 
 	do_warning_event(event, "function %s not defined", token);
+
+ done:
+	if (field)
+		arg->field.field = tep_find_any_field(event, field);
+
 	free_token(token);
-	return TEP_EVENT_ERROR;
+	return ret;
 }
 
 static enum tep_event_type