+void print_enum_value_label_unknown(struct pretty_component *pretty)
+{
+ if (pretty->use_colors) {
+ bt_common_g_string_append(pretty->string, color_unknown);
+ }
+
+ bt_common_g_string_append(pretty->string, "<unknown>");
+
+ if (pretty->use_colors) {
+ bt_common_g_string_append(pretty->string, color_rst);
+ }
+}
+
+/*
+ * Print labels for a value. If there are more than one label for the
+ * value, they will be printed in "{ }".
+ */
+static
+void print_enum_value_label_array(struct pretty_component *pretty,
+ uint64_t label_count,
+ bt_field_class_enumeration_mapping_label_array label_array)
+{
+ uint64_t i;
+
+ if (label_count > 1) {
+ bt_common_g_string_append(pretty->string, "{ ");
+ }
+
+ for (i = 0; i < label_count; i++) {
+ const char *mapping_name = label_array[i];
+
+ if (i != 0) {
+ bt_common_g_string_append(pretty->string, ", ");
+ }
+ if (pretty->use_colors) {
+ bt_common_g_string_append(pretty->string, color_enum_mapping_name);
+ }
+ print_escape_string(pretty, mapping_name);
+ if (pretty->use_colors) {
+ bt_common_g_string_append(pretty->string, color_rst);
+ }
+ }
+
+ if (label_count > 1) {
+ bt_common_g_string_append(pretty->string, " }");
+ }
+}
+
+/*
+ * Print arrays of labels and counts are ORed bit flags.
+ */
+static
+void print_enum_value_bit_flag_label_arrays(struct pretty_component *pretty)
+{
+ uint64_t i;
+ bool first_label = true;
+
+ /* For each bit with a label count > 0, print the labels. */
+ for (i = 0; i < ENUMERATION_MAX_BITFLAGS_COUNT; i++) {
+ uint64_t label_count = pretty->enum_bit_labels[i]->len;
+
+ if (label_count > 0) {
+ if (!first_label) {
+ bt_common_g_string_append(pretty->string, " | ");
+ }
+ print_enum_value_label_array(pretty, label_count,
+ (void *) pretty->enum_bit_labels[i]->pdata);
+ first_label = false;
+ }
+ }
+}
+
+/*
+ * Get the labels mapping to an unsigned value.
+ *
+ * This function will set the count to the count of mapping labels that match
+ * the value. If count == 0, the caller has nothing to do, if count > 0,
+ * the label_array contains the labels to print and the caller is responsible
+ * to call g_free on it once the values have been used.
+ */
+static
+void print_enum_unsigned_get_mapping_labels_for_value(const bt_field_class *fc,
+ uint64_t value, GPtrArray *labels)
+{
+ uint64_t mapping_count = bt_field_class_enumeration_get_mapping_count(fc);
+ uint64_t i;
+
+ for (i = 0; i < mapping_count; i++) {
+ uint64_t range_i;
+ const struct bt_field_class_enumeration_unsigned_mapping *mapping =
+ bt_field_class_enumeration_unsigned_borrow_mapping_by_index_const(fc, i);
+ const bt_integer_range_set_unsigned *ranges =
+ bt_field_class_enumeration_unsigned_mapping_borrow_ranges_const(mapping);
+ uint64_t range_count = bt_integer_range_set_get_range_count(
+ bt_integer_range_set_unsigned_as_range_set_const(ranges));
+
+ for (range_i = 0; range_i < range_count; range_i++) {
+ const bt_integer_range_unsigned *range =
+ bt_integer_range_set_unsigned_borrow_range_by_index_const(ranges, range_i);
+ uint64_t lower = bt_integer_range_unsigned_get_lower(range);
+ uint64_t upper = bt_integer_range_unsigned_get_upper(range);
+
+ /*
+ * Flag is active if this range represents a single value
+ * (lower == upper) and the lower is the same as the bit
+ * value to test against.
+ */
+ if ((lower == upper) && (lower == value)) {
+ g_ptr_array_add(labels, (void *) bt_field_class_enumeration_mapping_get_label(
+ bt_field_class_enumeration_unsigned_mapping_as_mapping_const(mapping)));
+ break;
+ }
+ }
+ }
+}
+
+/*
+ * Splits an unsigned enum value into its bit and for each bit set,
+ * try to find a corresponding label.
+ *
+ * If any bit set does not have a corresponding label, then it prints
+ * an unknown value, otherwise, it prints the labels, separated by '|'
+ */
+static
+void print_enum_unsigned_try_bit_flags(struct pretty_component *pretty,