diff mbox series

[10/10] libtraceevent: Have print_field_raw() handle old data layout

Message ID 20211216213956.13934-11-rostedt@goodmis.org (mailing list archive)
State Accepted
Commit 6064b38e6dca089fd8e2fda9354e551b6c831fac
Headers show
Series libtraceevent: Makefile updates fixes and unit tests | expand

Commit Message

Steven Rostedt Dec. 16, 2021, 9:39 p.m. UTC
From: "Steven Rostedt (VMware)" <rostedt@goodmis.org>

Old kernels would produce dynamic strings with only a two byte offset. The
length of the array was determined by the string length. When parsing, if
the field is dynamic with a size of 2, then it is the old dynamic string
layout. Set the field to both a string and an array.

Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
---
 src/event-parse.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
diff mbox series

Patch

diff --git a/src/event-parse.c b/src/event-parse.c
index 40af92f4295f..9bd605d74b1f 100644
--- a/src/event-parse.c
+++ b/src/event-parse.c
@@ -1828,6 +1828,16 @@  static int event_read_fields(struct tep_event *event, struct tep_format_field **
 		field->size = strtoul(token, NULL, 0);
 		free_token(token);
 
+		/*
+		 * The old data format before dynamic arrays had dynamic
+		 * strings defined with just a 2 byte offset (the length
+		 * is defined by the strlen() of the string. To process them
+		 * correctly, check if the field is dynamic and has a size of
+		 * 2 bytes. All current dynamic events have a size of 4.
+		 */
+		if ((field->flags & TEP_FIELD_IS_DYNAMIC) && field->size == 2)
+			field->flags |= TEP_FIELD_IS_STRING | TEP_FIELD_IS_ARRAY;
+
 		if (read_expected(TEP_EVENT_OP, ";") < 0)
 			goto fail_expect;