From 6bdefb8c6ebc337439f4bda397e21bd1479e4ba4 Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Fri, 4 Mar 2022 22:28:14 -0500 Subject: [PATCH] sink.text.details: handle BLOB field class type 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 blob_with_len: Empty Change-Id: Iae1f12e8b8d4d3a0612b935ddd45072dbc26df24 Signed-off-by: Simon Marchi Reviewed-on: https://review.lttng.org/c/babeltrace/+/7502 Reviewed-by: Philippe Proulx CI-Build: Philippe Proulx Tested-by: jenkins Reviewed-on: https://review.lttng.org/c/babeltrace/+/12692 --- src/plugins/text/details/write.c | 69 ++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/src/plugins/text/details/write.c b/src/plugins/text/details/write.c index ffc72bb4..df3f28a9 100644 --- a/src/plugins/text/details/write.c +++ b/src/plugins/text/details/write.c @@ -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(); } -- 2.34.1