Fix: missing dynamic array string handling
authorJonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Fri, 12 Aug 2022 14:39:25 +0000 (10:39 -0400)
committerJonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Mon, 15 Aug 2022 18:31:14 +0000 (14:31 -0400)
A dynamic array of integer can be a string based on the type encoding.

It was handled for static but not for dynamic array.

Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Change-Id: I0497c16880db8a423bb84f4aea63fe56c2ca7c2b

src/ctf2.c

index 7117f2aa0ba946327862893a2024c4c09f2c943d..bf0bbdabe1d096efadf220a79cc4fe7075723008 100644 (file)
@@ -1258,6 +1258,9 @@ static int ctf2_metadata_write_dynamic_length_array_field_class(
        const struct lttng_kernel_type_common *elem_type;
        struct field_path *field_path;
        int ret;
+       bool is_string = type->elem_type->type == lttng_kernel_type_integer &&
+               (type->encoding == lttng_kernel_string_encoding_ASCII ||
+                type->encoding == lttng_kernel_string_encoding_UTF8);
 
        field_path = field_path_resolve(field_location_ctx, type->length_name);
        if (!field_path) {
@@ -1265,45 +1268,55 @@ static int ctf2_metadata_write_dynamic_length_array_field_class(
                goto end;
        }
 
-       /*
-        * Nested compound types: Only array of integers, structures, and
-        * variants are currently supported.
-        */
-       ret = lttng_metadata_printf(session,
-                                   "{\n"
-                                   "  \"type\": \"dynamic-length-array\",\n"
-                                   "  \"length-field-location\": ");
-       if (ret)
-               goto end;
-
-       ret = print_field_location(session, field_path);
-       if (ret)
-               goto end;
+       if (is_string) {
+               ret = lttng_metadata_printf(
+                               session,
+                               "{"
+                               "  \"type\": \"dynamic-length-string\","
+                               "  \"length-field-location\": ");
+               ret = print_field_location(session, field_path);
+               if (ret)
+                       goto end;
 
-       if (type->alignment != 0 && type->alignment != 1) {
+       } else {
                ret = lttng_metadata_printf(session,
-                                           ",\n\"minimum-alignment\": %u",
-                                           type->alignment * CHAR_BIT);
+                               "{\n"
+                               "  \"type\": \"dynamic-length-array\",\n"
+                               "  \"length-field-location\": ");
+
+               ret = print_field_location(session, field_path);
                if (ret)
                        goto end;
-       }
 
-       ret = lttng_metadata_printf(session, ",\n\"element-field-class\":");
-       if (ret)
-               goto end;
+               if (type->alignment != 0 && type->alignment != 1) {
+                       ret = lttng_metadata_printf(session,
+                                       ",\n\"minimum-alignment\": %u",
+                                       type->alignment * CHAR_BIT);
+                       if (ret)
+                               goto end;
+               }
 
-       elem_type = type->elem_type;
-       switch (elem_type->type) {
-       case lttng_kernel_type_integer:
-       case lttng_kernel_type_struct:
-       case lttng_kernel_type_variant:
-               ret = ctf2_metadata_write_field_class(session, elem_type, NULL);
+               ret = lttng_metadata_printf(session, ",\n\"element-field-class\":");
                if (ret)
                        goto end;
-               break;
 
-       default:
-               return -EINVAL;
+               /*
+                * Nested compound types: Only array of integers, structures, and
+                * variants are currently supported.
+                */
+               elem_type = type->elem_type;
+               switch (elem_type->type) {
+               case lttng_kernel_type_integer:
+               case lttng_kernel_type_struct:
+               case lttng_kernel_type_variant:
+                       ret = ctf2_metadata_write_field_class(session, elem_type, NULL);
+                       if (ret)
+                               goto end;
+                       break;
+
+               default:
+                       return -EINVAL;
+               }
        }
 
        ret = lttng_metadata_printf(session, "}\n");
This page took 0.027995 seconds and 5 git commands to generate.