src.text.pretty: handle BLOB fields
authorSimon Marchi <simon.marchi@efficios.com>
Fri, 11 Mar 2022 20:56:09 +0000 (15:56 -0500)
committerSimon Marchi <simon.marchi@efficios.com>
Wed, 4 Sep 2024 19:05:14 +0000 (15:05 -0400)
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 <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7581
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7574

src/plugins/text/pretty/print.c

index 4c7e18337b5e459787ad2233080f1b4c8d1eea6a..e3e52182484f960cbf5c1b57eaa7ad022a6f6a04 100644 (file)
@@ -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();
This page took 0.024737 seconds and 4 git commands to generate.