sink.text.details: handle BLOB field class type
authorSimon Marchi <simon.marchi@efficios.com>
Sat, 5 Mar 2022 03:28:14 +0000 (22:28 -0500)
committerSimon Marchi <simon.marchi@efficios.com>
Wed, 4 Sep 2024 19:05:14 +0000 (15:05 -0400)
Make the `sink.text.details` component class handle the BLOB field class
type, introduced in MIP 1.

When dumping the field class details, print the names of the new field
classes.  For the static BLOB field class, print the static length
value (similar to static arrays).

For BLOB fields:

 - if it is empty, print "Empty" (like a few other existing field kinds)
 - if it is not empty, print bytes as hex (without the 0x prefix), 16
   bytes per line.  This is similar to what `od -t x1` outputs, minus
   the address/offset column.

The output looks like this.  The field class part:

        static_blob: Static BLOB (Length 1)
        blob_without_len: Dynamic BLOB (no length field)
        blob_with_len: Dynamic BLOB (with length field)

The field part:

    static_blob: Length 1:
      fe
    blob_without_len: Length 2048:
      46 72 6f 6d 20 36 34 64 62 36 31 36 36 35 65 32
      38 62 62 63 39 63 62 64 32 62 64 32 62 34 39 31
      <snip>
    blob_with_len: Empty

Change-Id: Iae1f12e8b8d4d3a0612b935ddd45072dbc26df24
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7502
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
CI-Build: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12692

src/plugins/text/details/write.c

index ffc72bb4bb54f3410a51ba49f2d4056e070e654c..df3f28a9eb37978dcac5a5b932d94feb58257516 100644 (file)
@@ -1016,6 +1016,15 @@ void write_field_class(struct details_write_ctx *ctx, const bt_field_class *fc)
        case BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR_FIELD:
                type = "Variant (signed integer selector)";
                break;
+       case BT_FIELD_CLASS_TYPE_STATIC_BLOB:
+               type = "Static BLOB";
+               break;
+       case BT_FIELD_CLASS_TYPE_DYNAMIC_BLOB_WITHOUT_LENGTH_FIELD:
+               type = "Dynamic BLOB (no length field)";
+               break;
+       case BT_FIELD_CLASS_TYPE_DYNAMIC_BLOB_WITH_LENGTH_FIELD:
+               type = "Dynamic BLOB (with length field)";
+               break;
        default:
                bt_common_abort();
        }
@@ -1123,6 +1132,32 @@ void write_field_class(struct details_write_ctx *ctx, const bt_field_class *fc)
                }
 
                g_string_append_c(ctx->str, ')');
+       } else if (bt_field_class_type_is(fc_type, BT_FIELD_CLASS_TYPE_BLOB)) {
+               const char *media_type;
+
+               g_string_append(ctx->str, " (");
+
+               if (fc_type == BT_FIELD_CLASS_TYPE_STATIC_BLOB) {
+                       g_string_append(ctx->str, "Length ");
+                       write_uint_prop_value(ctx,
+                               bt_field_class_blob_static_get_length(fc));
+                       g_string_append(ctx->str, ", ");
+               } else if (fc_type == BT_FIELD_CLASS_TYPE_DYNAMIC_BLOB_WITH_LENGTH_FIELD) {
+                       const bt_field_location *length_field_location =
+                               bt_field_class_blob_dynamic_with_length_field_borrow_length_field_location_const(
+                                       fc);
+
+                       g_string_append(ctx->str, "Length field location ");
+                       write_field_location(ctx, length_field_location);
+                       g_string_append(ctx->str, ", ");
+               }
+
+               media_type = bt_field_class_blob_get_media_type(fc);
+               BT_ASSERT(media_type);
+
+               g_string_append(ctx->str, "Media type `");
+               write_str_prop_value(ctx, media_type);
+               g_string_append(ctx->str, "`)");
        }
 
        incr_indent(ctx);
@@ -1993,6 +2028,40 @@ void write_field(struct details_write_ctx *ctx, const bt_field *field,
                write_field(ctx,
                        bt_field_variant_borrow_selected_option_field_const(
                                field), NULL);
+       } else if (bt_field_class_type_is(fc_type, BT_FIELD_CLASS_TYPE_BLOB)) {
+               uint64_t length = bt_field_blob_get_length(field);
+               const uint8_t *blob_data = bt_field_blob_get_data_const(field);
+
+               if (length == 0) {
+                       write_sp(ctx);
+                       write_none_prop_value(ctx, "Empty");
+               } else {
+                       g_string_append(ctx->str, " Length ");
+                       write_uint_prop_value(ctx, length);
+                       g_string_append_c(ctx->str, ':');
+               }
+
+               incr_indent(ctx);
+
+               /* Print bytes on 16-byte long lines */
+               for (i = 0; i < length; i++) {
+                       uint8_t byte = blob_data[i];
+                       char byte_buf[3];
+
+                       if (i % 16 == 0) {
+                               /* Start of a line */
+                               write_nl(ctx);
+                               write_indent(ctx);
+                       } else {
+                               /* Not the start of a line */
+                               write_sp(ctx);
+                       }
+
+                       sprintf(byte_buf, "%02x", byte);
+                       write_uint_str_prop_value(ctx, byte_buf);
+               }
+
+               decr_indent(ctx);
        } else {
                bt_common_abort();
        }
This page took 0.026046 seconds and 4 git commands to generate.