All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 1/2] libtraceevent: Add dynamic_offset()
@ 2021-08-04 12:55 Yordan Karadzhov (VMware)
  2021-08-04 12:55 ` [PATCH v2 2/2] libtraceevent: Keep the pointer to the field in args (WiP) Yordan Karadzhov (VMware)
  2021-08-04 15:58 ` [PATCH v2 1/2] libtraceevent: Add dynamic_offset() Steven Rostedt
  0 siblings, 2 replies; 4+ messages in thread
From: Yordan Karadzhov (VMware) @ 2021-08-04 12:55 UTC (permalink / raw)
  To: rostedt; +Cc: linux-trace-devel, Yordan Karadzhov (VMware)

The total allocated length of the dynamic array is stored in the top half
of the corresponding 32 bit field and the offset is in the bottom half of
the same field. Since the decoding of the length and offset is performed
in multiple locations is the code, we define a static helper function to
replace/cleanup the existing open coded conversions.

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

diff --git a/src/event-parse.c b/src/event-parse.c
index f42ae38..b0790d7 100644
--- a/src/event-parse.c
+++ b/src/event-parse.c
@@ -3858,6 +3858,36 @@ static unsigned long long test_for_symbol(struct tep_handle *tep,
 	return val;
 }
 
+#define TEP_OFFSET_LEN_MASK		0xffff
+#define TEP_LEN_SHIFT			16
+
+static void dynamic_offset(struct tep_handle *tep, int size, void *data,
+			   unsigned int *offset, unsigned int *len)
+{
+	unsigned long long val;
+
+	/*
+	 * The total allocated length of the dynamic array is
+	 * stored in the top half of the field and the offset
+	 * is in the bottom half of the 32 bit field.
+	 */
+	val = tep_read_number(tep, data, size);
+
+	if (*offset)
+		*offset = (unsigned int)(val & TEP_OFFSET_LEN_MASK);
+	if (*len)
+		*len = (unsigned int)((val >> TEP_LEN_SHIFT) & TEP_OFFSET_LEN_MASK);
+}
+
+static inline void dynamic_offset_field(struct tep_handle *tep,
+					struct tep_format_field *field,
+					void *data,
+					unsigned int *offset,
+					unsigned int *len)
+{
+	dynamic_offset(tep, field->size, data + field->offset, offset, len);
+}
+
 static unsigned long long
 eval_num_arg(void *data, int size, struct tep_event *event, struct tep_print_arg *arg)
 {
@@ -3866,7 +3896,7 @@ eval_num_arg(void *data, int size, struct tep_event *event, struct tep_print_arg
 	unsigned long long left, right;
 	struct tep_print_arg *typearg = NULL;
 	struct tep_print_arg *larg;
-	unsigned long offset;
+	unsigned int offset;
 	unsigned int field_size;
 
 	switch (arg->type) {
@@ -3930,18 +3960,11 @@ eval_num_arg(void *data, int size, struct tep_event *event, struct tep_print_arg
 
 			switch (larg->type) {
 			case TEP_PRINT_DYNAMIC_ARRAY:
-				offset = tep_read_number(tep,
-						   data + larg->dynarray.field->offset,
-						   larg->dynarray.field->size);
+				dynamic_offset_field(tep, larg->dynarray.field, data,
+						     &offset, NULL);
+				offset += right;
 				if (larg->dynarray.field->elementsize)
 					field_size = larg->dynarray.field->elementsize;
-				/*
-				 * The actual length of the dynamic array is stored
-				 * in the top half of the field, and the offset
-				 * is in the bottom half of the 32 bit field.
-				 */
-				offset &= 0xffff;
-				offset += right;
 				break;
 			case TEP_PRINT_FIELD:
 				if (!larg->field.field) {
@@ -4060,27 +4083,14 @@ eval_num_arg(void *data, int size, struct tep_event *event, struct tep_print_arg
 		}
 		break;
 	case TEP_PRINT_DYNAMIC_ARRAY_LEN:
-		offset = tep_read_number(tep,
-					 data + arg->dynarray.field->offset,
-					 arg->dynarray.field->size);
-		/*
-		 * The total allocated length of the dynamic array is
-		 * stored in the top half of the field, and the offset
-		 * is in the bottom half of the 32 bit field.
-		 */
-		val = (unsigned long long)(offset >> 16);
+		dynamic_offset_field(tep, arg->dynarray.field, data,
+				     NULL, &field_size);
+		val = (unsigned long long) field_size;
 		break;
 	case TEP_PRINT_DYNAMIC_ARRAY:
 		/* Without [], we pass the address to the dynamic data */
-		offset = tep_read_number(tep,
-					 data + arg->dynarray.field->offset,
-					 arg->dynarray.field->size);
-		/*
-		 * The total allocated length of the dynamic array is
-		 * stored in the top half of the field, and the offset
-		 * is in the bottom half of the 32 bit field.
-		 */
-		offset &= 0xffff;
+		dynamic_offset_field(tep, arg->dynarray.field, data,
+				     &offset, NULL);
 		val = (unsigned long long)((unsigned long)data + offset);
 		break;
 	default: /* not sure what to do there */
@@ -4209,12 +4219,13 @@ static void print_str_arg(struct trace_seq *s, void *data, int size,
 	struct tep_print_flag_sym *flag;
 	struct tep_format_field *field;
 	struct printk_map *printk;
+	unsigned int offset, len;
 	long long val, fval;
 	unsigned long long addr;
 	char *str;
 	unsigned char *hex;
 	int print;
-	int i, len;
+	int i;
 
 	switch (arg->type) {
 	case TEP_PRINT_NULL:
@@ -4318,11 +4329,9 @@ static void print_str_arg(struct trace_seq *s, void *data, int size,
 	case TEP_PRINT_HEX:
 	case TEP_PRINT_HEX_STR:
 		if (arg->hex.field->type == TEP_PRINT_DYNAMIC_ARRAY) {
-			unsigned long offset;
-			offset = tep_read_number(tep,
-				data + arg->hex.field->dynarray.field->offset,
-				arg->hex.field->dynarray.field->size);
-			hex = data + (offset & 0xffff);
+			dynamic_offset_field(tep, arg->hex.field->dynarray.field, data,
+				             &offset, NULL);
+			hex = data + offset;
 		} else {
 			field = arg->hex.field->field.field;
 			if (!field) {
@@ -4347,13 +4356,9 @@ static void print_str_arg(struct trace_seq *s, void *data, int size,
 		int el_size;
 
 		if (arg->int_array.field->type == TEP_PRINT_DYNAMIC_ARRAY) {
-			unsigned long offset;
-			struct tep_format_field *field =
-				arg->int_array.field->dynarray.field;
-			offset = tep_read_number(tep,
-						 data + field->offset,
-						 field->size);
-			num = data + (offset & 0xffff);
+			dynamic_offset_field(tep, arg->int_array.field->dynarray.field, data,
+					     &offset, NULL);
+			num = data + offset;
 		} else {
 			field = arg->int_array.field->field.field;
 			if (!field) {
@@ -4393,42 +4398,33 @@ static void print_str_arg(struct trace_seq *s, void *data, int size,
 	case TEP_PRINT_TYPE:
 		break;
 	case TEP_PRINT_STRING: {
-		int str_offset;
-		int len;
-
 		if (arg->string.offset == -1) {
 			struct tep_format_field *f;
 
 			f = tep_find_any_field(event, arg->string.string);
 			arg->string.offset = f->offset;
 		}
-		str_offset = data2host4(tep, *(unsigned int *)(data + arg->string.offset));
-		len = (str_offset >> 16) & 0xffff;
+		dynamic_offset(tep, 4, data + arg->string.offset, &offset, &len);
 		/* Do not attempt to save zero length dynamic strings */
 		if (!len)
 			break;
-		str_offset &= 0xffff;
-		print_str_to_seq(s, format, len_arg, ((char *)data) + str_offset);
+		offset &= TEP_OFFSET_LEN_MASK;
+		print_str_to_seq(s, format, len_arg, ((char *)data) + offset);
 		break;
 	}
 	case TEP_PRINT_BSTRING:
 		print_str_to_seq(s, format, len_arg, arg->string.string);
 		break;
 	case TEP_PRINT_BITMASK: {
-		int bitmask_offset;
-		int bitmask_size;
-
 		if (arg->bitmask.offset == -1) {
 			struct tep_format_field *f;
 
 			f = tep_find_any_field(event, arg->bitmask.bitmask);
 			arg->bitmask.offset = f->offset;
 		}
-		bitmask_offset = data2host4(tep, *(unsigned int *)(data + arg->bitmask.offset));
-		bitmask_size = bitmask_offset >> 16;
-		bitmask_offset &= 0xffff;
+		dynamic_offset(tep, 4, data + arg->bitmask.offset, &offset, &len);
 		print_bitmask_to_seq(tep, s, format, len_arg,
-				     data + bitmask_offset, bitmask_size);
+				     data + offset, len);
 		break;
 	}
 	case TEP_PRINT_OP:
@@ -5271,13 +5267,12 @@ static int print_raw_buff_arg(struct trace_seq *s, const char *ptr,
 			      void *data, int size, struct tep_event *event,
 			      struct tep_print_arg *arg, int print_len)
 {
+	unsigned int offset, arr_len;
 	int plen = print_len;
 	char *delim = " ";
 	int ret = 0;
 	char *buf;
 	int i;
-	unsigned long offset;
-	int arr_len;
 
 	switch (*(ptr + 1)) {
 	case 'C':
@@ -5304,11 +5299,9 @@ static int print_raw_buff_arg(struct trace_seq *s, const char *ptr,
 		return ret;
 	}
 
-	offset = tep_read_number(event->tep,
-				 data + arg->dynarray.field->offset,
-				 arg->dynarray.field->size);
-	arr_len = (unsigned long long)(offset >> 16);
-	buf = data + (offset & 0xffff);
+	dynamic_offset_field(event->tep, arg->dynarray.field, data,
+			     &offset, &arr_len);
+	buf = data + offset;
 
 	if (arr_len < plen)
 		plen = arr_len;
@@ -5336,19 +5329,18 @@ static int is_printable_array(char *p, unsigned int len)
 void tep_print_field(struct trace_seq *s, void *data,
 		     struct tep_format_field *field)
 {
-	unsigned long long val;
-	unsigned int offset, len, i;
 	struct tep_handle *tep = field->event->tep;
+	unsigned int offset, len, i;
+	unsigned long long val;
 
 	if (field->flags & TEP_FIELD_IS_ARRAY) {
-		offset = field->offset;
-		len = field->size;
 		if (field->flags & TEP_FIELD_IS_DYNAMIC) {
-			val = tep_read_number(tep, data + offset, len);
-			offset = val;
-			len = offset >> 16;
-			offset &= 0xffff;
+			dynamic_offset_field(tep, field, data, &offset, &len);
+		} else {
+			offset = field->offset;
+			len = field->size;
 		}
+
 		if (field->flags & TEP_FIELD_IS_STRING &&
 		    is_printable_array(data + offset, len)) {
 			trace_seq_printf(s, "%s", (char *)data + offset);
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH v2 2/2] libtraceevent: Keep the pointer to the field in args (WiP)
  2021-08-04 12:55 [PATCH v2 1/2] libtraceevent: Add dynamic_offset() Yordan Karadzhov (VMware)
@ 2021-08-04 12:55 ` Yordan Karadzhov (VMware)
  2021-08-04 16:04   ` Steven Rostedt
  2021-08-04 15:58 ` [PATCH v2 1/2] libtraceevent: Add dynamic_offset() Steven Rostedt
  1 sibling, 1 reply; 4+ messages in thread
From: Yordan Karadzhov (VMware) @ 2021-08-04 12:55 UTC (permalink / raw)
  To: rostedt; +Cc: linux-trace-devel, Yordan Karadzhov (VMware)

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.

Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
Signed-off-by: Yordan Karadzhov (VMware) <y.karadz@gmail.com>
---

Hi Steven,

This version is still WORK IN PROGRESS! 

Changes in c2:

 A kprobe that is defined as:
 "p:open do_sys_openat2 file=+0($arg2):string flags=+0($arg3):x64 mode=+8($arg3):x64"

 will have the following printing format:
 "print fmt: "(%lx) file=\"%s\" flags=0x%Lx mode=0x%Lx", REC->__probe_ip, __get_str(file), REC->flags, REC->mode"

 In v2 I am trying to add propper handling of the "file" fieled
 (via "__get_str") of this particular probe. A solution for the general
 case still needs to be developed.

 Any ideas?
 
Thanks!
Yordan


 src/event-parse.c | 60 +++++++++++++++++++++++++++--------------------
 1 file changed, 34 insertions(+), 26 deletions(-)

diff --git a/src/event-parse.c b/src/event-parse.c
index b0790d7..64ebed3 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
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v2 1/2] libtraceevent: Add dynamic_offset()
  2021-08-04 12:55 [PATCH v2 1/2] libtraceevent: Add dynamic_offset() Yordan Karadzhov (VMware)
  2021-08-04 12:55 ` [PATCH v2 2/2] libtraceevent: Keep the pointer to the field in args (WiP) Yordan Karadzhov (VMware)
@ 2021-08-04 15:58 ` Steven Rostedt
  1 sibling, 0 replies; 4+ messages in thread
From: Steven Rostedt @ 2021-08-04 15:58 UTC (permalink / raw)
  To: Yordan Karadzhov (VMware); +Cc: linux-trace-devel

On Wed,  4 Aug 2021 15:55:25 +0300
"Yordan Karadzhov (VMware)" <y.karadz@gmail.com> wrote:

> +	if (*offset)
> +		*offset = (unsigned int)(val & TEP_OFFSET_LEN_MASK);
> +	if (*len)
> +		*len = (unsigned int)((val >> TEP_LEN_SHIFT) & TEP_OFFSET_LEN_MASK);
> +}

Oops, the above is wrong. It should be:

	if (offset)
		*offset = (unsigned int)(val & TEP_OFFSET_LEN_MASK);
	if (len)
		*len = (unsigned int)((val >> TEP_LEN_SHIFT) & TEP_OFFSET_LEN_MASK);

And yes, this would crash if NULL is passed in.

-- Steve

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2 2/2] libtraceevent: Keep the pointer to the field in args (WiP)
  2021-08-04 12:55 ` [PATCH v2 2/2] libtraceevent: Keep the pointer to the field in args (WiP) Yordan Karadzhov (VMware)
@ 2021-08-04 16:04   ` Steven Rostedt
  0 siblings, 0 replies; 4+ messages in thread
From: Steven Rostedt @ 2021-08-04 16:04 UTC (permalink / raw)
  To: Yordan Karadzhov (VMware); +Cc: linux-trace-devel

On Wed,  4 Aug 2021 15:55:26 +0300
"Yordan Karadzhov (VMware)" <y.karadz@gmail.com> wrote:


>  In v2 I am trying to add propper handling of the "file" fieled
>  (via "__get_str") of this particular probe. A solution for the general
>  case still needs to be developed.

That's not what I meant. No need to touch anything to do with strings.

> 
>  Any ideas?
>  
> Thanks!
> Yordan
> 
> 
>  src/event-parse.c | 60 +++++++++++++++++++++++++++--------------------
>  1 file changed, 34 insertions(+), 26 deletions(-)
> 
> diff --git a/src/event-parse.c b/src/event-parse.c
> index b0790d7..64ebed3 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;
>  	}

The above is all that was needed. The below should not be touched.

> @@ -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

Fixing the offset and len dereferences in the first patch and then
applying this patch should give you exactly what you are looking for.
As we only care about conversions of numbers. Strings and arrays will
just be whatever they are.

-- Steve

Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>

diff --git a/src/event-parse.c b/src/event-parse.c
index b0790d7..24c69f2 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;
 	}
@@ -5326,8 +5326,8 @@ static int is_printable_array(char *p, unsigned int len)
 	return 1;
 }
 
-void tep_print_field(struct trace_seq *s, void *data,
-		     struct tep_format_field *field)
+static void _tep_print_field(struct trace_seq *s, void *data,
+			     struct tep_format_field *field)
 {
 	struct tep_handle *tep = field->event->tep;
 	unsigned int offset, len, i;
@@ -5390,6 +5390,39 @@ void tep_print_field(struct trace_seq *s, void *data,
 	}
 }
 
+static void print_parse_data(struct tep_print_parse *parse,
+			     struct trace_seq *s, void *data, int size,
+			     struct tep_event *event);
+
+void tep_print_field(struct trace_seq *s, void *data,
+		     struct tep_format_field *field)
+{
+	struct tep_event *event = field->event;
+	struct tep_print_parse *parse = event->print_fmt.print_cache;
+
+	if (event->flags & TEP_EVENT_FL_FAILED)
+		goto out;
+
+	if (field->flags & (TEP_FIELD_IS_ARRAY | TEP_FIELD_IS_STRING))
+		goto out;
+
+	for (;parse; parse = parse->next) {
+		if (parse->type == PRINT_FMT_STRING)
+			continue;
+		if (parse->arg->type != TEP_PRINT_FIELD)
+			continue;
+		if (parse->arg->field.field != field)
+			continue;
+
+		print_parse_data(parse, s, data, field->size, event);
+		return;
+	}
+	/* Not found */
+
+ out:
+	_tep_print_field(s, data, field);
+}
+
 void tep_print_fields(struct trace_seq *s, void *data,
 		      int size __maybe_unused, struct tep_event *event)
 {
@@ -5909,35 +5942,42 @@ parse_args(struct tep_event *event, const char *format, struct tep_print_arg *ar
 	return parse_ret;
 }
 
-static void print_event_cache(struct tep_print_parse *parse, struct trace_seq *s,
-			      void *data, int size, struct tep_event *event)
+static void print_parse_data(struct tep_print_parse *parse,
+			     struct trace_seq *s, void *data, int size,
+			     struct tep_event *event)
 {
 	int len_arg;
 
+	if (parse->len_as_arg)
+		len_arg = eval_num_arg(data, size, event, parse->len_as_arg);
+	switch (parse->type) {
+	case PRINT_FMT_ARG_DIGIT:
+		print_arg_number(s, parse->format,
+				 parse->len_as_arg ? len_arg : -1, data,
+				 size, parse->ls, event, parse->arg);
+		break;
+	case PRINT_FMT_ARG_POINTER:
+		print_arg_pointer(s, parse->format,
+				  parse->len_as_arg ? len_arg : 1,
+				  data, size, event, parse->arg);
+		break;
+	case PRINT_FMT_ARG_STRING:
+		print_arg_string(s, parse->format,
+				 parse->len_as_arg ? len_arg : -1,
+				 data, size, event, parse->arg);
+		break;
+	case PRINT_FMT_STRING:
+	default:
+		trace_seq_printf(s, "%s", parse->format);
+		break;
+	}
+}
+
+static void print_event_cache(struct tep_print_parse *parse, struct trace_seq *s,
+			      void *data, int size, struct tep_event *event)
+{
 	while (parse) {
-		if (parse->len_as_arg)
-			len_arg = eval_num_arg(data, size, event, parse->len_as_arg);
-		switch (parse->type) {
-		case PRINT_FMT_ARG_DIGIT:
-			print_arg_number(s, parse->format,
-					parse->len_as_arg ? len_arg : -1, data,
-					 size, parse->ls, event, parse->arg);
-			break;
-		case PRINT_FMT_ARG_POINTER:
-			print_arg_pointer(s, parse->format,
-					  parse->len_as_arg ? len_arg : 1,
-					  data, size, event, parse->arg);
-			break;
-		case PRINT_FMT_ARG_STRING:
-			print_arg_string(s, parse->format,
-					 parse->len_as_arg ? len_arg : -1,
-					 data, size, event, parse->arg);
-			break;
-		case PRINT_FMT_STRING:
-		default:
-			trace_seq_printf(s, "%s", parse->format);
-			break;
-		}
+		print_parse_data(parse, s, data, size, event);
 		parse = parse->next;
 	}
 }

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-08-04 16:04 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-04 12:55 [PATCH v2 1/2] libtraceevent: Add dynamic_offset() Yordan Karadzhov (VMware)
2021-08-04 12:55 ` [PATCH v2 2/2] libtraceevent: Keep the pointer to the field in args (WiP) Yordan Karadzhov (VMware)
2021-08-04 16:04   ` Steven Rostedt
2021-08-04 15:58 ` [PATCH v2 1/2] libtraceevent: Add dynamic_offset() Steven Rostedt

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.