From 2680869e537193ad02bffc8553a921a5e1b5d37f Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Fri, 11 Mar 2022 15:56:09 -0500 Subject: [PATCH] src.text.pretty: handle BLOB fields Make the `src.text.pretty` components handle BLOB fields, by naively printing all bytes in hex (without a 0x prefix). Example output: da-ec-name: { blob_without_len = { 23 69 6e 63 6c 75 64 65 20 3c } } It would be nice to limit the number of bytes dumped (and provide an option to control it), because at some point it's useless for the user to dump thousands of bytes on one line. But this is enough to say that the `src.text.pretty` component class supports BLOB field classes (and MIP 1). Change-Id: Ia83e6429336d71082c35aa11153c9646e98e9bce Signed-off-by: Simon Marchi Reviewed-on: https://review.lttng.org/c/babeltrace/+/7581 Tested-by: jenkins Reviewed-by: Philippe Proulx Reviewed-on: https://review.lttng.org/c/babeltrace/+/7574 --- src/plugins/text/pretty/print.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/plugins/text/pretty/print.c b/src/plugins/text/pretty/print.c index 4c7e1833..e3e52182 100644 --- a/src/plugins/text/pretty/print.c +++ b/src/plugins/text/pretty/print.c @@ -1220,6 +1220,25 @@ end: return ret; } +static +int print_blob(struct pretty_component *pretty, const bt_field *blob) +{ + const uint8_t *data = bt_field_blob_get_data_const(blob); + uint64_t len = bt_field_blob_get_length(blob); + size_t i; + + bt_common_g_string_append(pretty->string, "{ "); + + for (i = 0; i < len; ++i) { + uint8_t b = data[i]; + + bt_common_g_string_append_printf(pretty->string, "%02x ", b); + } + + bt_common_g_string_append(pretty->string, "}"); + return 0; +} + static int print_field(struct pretty_component *pretty, const bt_field *field, bool print_names) @@ -1311,6 +1330,8 @@ int print_field(struct pretty_component *pretty, } else if (bt_field_class_type_is(class_id, BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY)) { return print_sequence(pretty, field, print_names); + } else if (bt_field_class_type_is(class_id, BT_FIELD_CLASS_TYPE_BLOB)) { + return print_blob(pretty, field); } bt_common_abort(); -- 2.34.1