Move to kernel style SPDX license identifiers
[babeltrace.git] / src / plugins / text / details / write.c
index 78ab04dcc5dc613854146947a7dbbf4afae552aa..51490a14d8b92b149966c5bdbdb9f57a475dd7ce 100644 (file)
@@ -1,26 +1,11 @@
 /*
- * Copyright 2019 Philippe Proulx <pproulx@efficios.com>
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
+ * SPDX-License-Identifier: MIT
  *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
+ * Copyright 2019 Philippe Proulx <pproulx@efficios.com>
  */
 
 #include <babeltrace2/babeltrace.h>
+#include <stdbool.h>
 #include <stdio.h>
 #include <string.h>
 
@@ -41,7 +26,7 @@ const char *plural(uint64_t value)
 static inline
 void incr_indent_by(struct details_write_ctx *ctx, unsigned int value)
 {
-       BT_ASSERT(ctx);
+       BT_ASSERT_DBG(ctx);
        ctx->indent_level += value;
 }
 
@@ -54,8 +39,8 @@ void incr_indent(struct details_write_ctx *ctx)
 static inline
 void decr_indent_by(struct details_write_ctx *ctx, unsigned int value)
 {
-       BT_ASSERT(ctx);
-       BT_ASSERT(ctx->indent_level >= value);
+       BT_ASSERT_DBG(ctx);
+       BT_ASSERT_DBG(ctx->indent_level >= value);
        ctx->indent_level -= value;
 }
 
@@ -101,7 +86,7 @@ void format_uint(char *buf, uint64_t value, unsigned int base)
 
                break;
        default:
-               abort();
+               bt_common_abort();
        }
 
        sprintf(buf_start, spec, value);
@@ -154,7 +139,7 @@ void format_int(char *buf, int64_t value, unsigned int base)
 
                break;
        default:
-               abort();
+               bt_common_abort();
        }
 
        sprintf(buf_start, spec, abs_value);
@@ -167,14 +152,14 @@ void format_int(char *buf, int64_t value, unsigned int base)
 static inline
 void write_nl(struct details_write_ctx *ctx)
 {
-       BT_ASSERT(ctx);
+       BT_ASSERT_DBG(ctx);
        g_string_append_c(ctx->str, '\n');
 }
 
 static inline
 void write_sp(struct details_write_ctx *ctx)
 {
-       BT_ASSERT(ctx);
+       BT_ASSERT_DBG(ctx);
        g_string_append_c(ctx->str, ' ');
 }
 
@@ -183,7 +168,7 @@ void write_indent(struct details_write_ctx *ctx)
 {
        uint64_t i;
 
-       BT_ASSERT(ctx);
+       BT_ASSERT_DBG(ctx);
 
        for (i = 0; i < ctx->indent_level; i++) {
                write_sp(ctx);
@@ -214,7 +199,8 @@ static inline
 void write_obj_type_name(struct details_write_ctx *ctx, const char *name)
 {
        g_string_append_printf(ctx->str, "%s%s%s%s",
-               color_fg_yellow(ctx), color_bold(ctx), name, color_reset(ctx));
+               color_bold(ctx), color_fg_bright_yellow(ctx), name,
+               color_reset(ctx));
 }
 
 static inline
@@ -243,7 +229,7 @@ static inline
 void write_none_prop_value(struct details_write_ctx *ctx, const char *value)
 {
        g_string_append_printf(ctx->str, "%s%s%s%s",
-               color_bold(ctx), color_fg_magenta(ctx),
+               color_bold(ctx), color_fg_bright_magenta(ctx),
                value, color_reset(ctx));
 }
 
@@ -282,7 +268,7 @@ static inline
 void write_str_prop_line(struct details_write_ctx *ctx, const char *prop_name,
                const char *prop_value)
 {
-       BT_ASSERT(prop_value);
+       BT_ASSERT_DBG(prop_value);
        write_indent(ctx);
        write_prop_name(ctx, prop_name);
        g_string_append(ctx->str, ": ");
@@ -326,10 +312,10 @@ void write_bool_prop_value(struct details_write_ctx *ctx, bt_bool prop_value)
        g_string_append(ctx->str, color_bold(ctx));
 
        if (prop_value) {
-               g_string_append(ctx->str, color_fg_green(ctx));
+               g_string_append(ctx->str, color_fg_bright_green(ctx));
                str = "Yes";
        } else {
-               g_string_append(ctx->str, color_fg_red(ctx));
+               g_string_append(ctx->str, color_fg_bright_red(ctx));
                str = "No";
        }
 
@@ -351,7 +337,7 @@ static inline
 void write_uuid_prop_line(struct details_write_ctx *ctx, const char *prop_name,
                bt_uuid uuid)
 {
-       BT_ASSERT(uuid);
+       BT_ASSERT_DBG(uuid);
        write_indent(ctx);
        write_prop_name(ctx, prop_name);
        g_string_append_printf(ctx->str,
@@ -368,14 +354,14 @@ gint compare_strings(const char **a, const char **b)
 }
 
 static
-bt_bool map_value_foreach_add_key_to_array(const char *key,
-               const bt_value *object, void *data)
+bt_value_map_foreach_entry_const_func_status map_value_foreach_add_key_to_array(
+               const char *key, const bt_value *object, void *data)
 {
        GPtrArray *keys = data;
 
-       BT_ASSERT(keys);
+       BT_ASSERT_DBG(keys);
        g_ptr_array_add(keys, (void *) key);
-       return BT_TRUE;
+       return BT_VALUE_MAP_FOREACH_ENTRY_CONST_FUNC_STATUS_OK;
 }
 
 static
@@ -387,7 +373,7 @@ void write_value(struct details_write_ctx *ctx, const bt_value *value,
        GPtrArray *keys = g_ptr_array_new();
        char buf[64];
 
-       BT_ASSERT(keys);
+       BT_ASSERT_DBG(keys);
 
        /* Write field's name */
        if (name) {
@@ -456,7 +442,7 @@ void write_value(struct details_write_ctx *ctx, const bt_value *value,
                        bt_value_map_foreach_entry_const(value,
                                map_value_foreach_add_key_to_array, keys);
 
-               BT_ASSERT(foreach_status ==
+               BT_ASSERT_DBG(foreach_status ==
                        BT_VALUE_MAP_FOREACH_ENTRY_CONST_STATUS_OK);
                g_ptr_array_sort(keys, (GCompareFunc) compare_strings);
 
@@ -482,7 +468,7 @@ void write_value(struct details_write_ctx *ctx, const bt_value *value,
                break;
        }
        default:
-               abort();
+               bt_common_abort();
        }
 
        g_ptr_array_free(keys, TRUE);
@@ -492,7 +478,7 @@ static
 void write_user_attributes(struct details_write_ctx *ctx,
                const bt_value *user_attrs, bool write_newline, bool *written)
 {
-       BT_ASSERT(user_attrs);
+       BT_ASSERT_DBG(user_attrs);
 
        if (!bt_value_map_is_empty(user_attrs)) {
                write_value(ctx, user_attrs, "User attributes");
@@ -530,7 +516,7 @@ void write_int_field_class_props(struct details_write_ctx *ctx,
                write_uint_prop_value(ctx, 16);
                break;
        default:
-               abort();
+               bt_common_abort();
        }
 
        if (close) {
@@ -708,7 +694,7 @@ void write_enum_field_class_mappings(struct details_write_ctx *ctx,
 
        mappings = g_ptr_array_new_with_free_func(
                (GDestroyNotify) destroy_enum_field_class_mapping);
-       BT_ASSERT(mappings);
+       BT_ASSERT_DBG(mappings);
 
        /*
         * Copy field class's mappings to our own arrays and structures
@@ -720,7 +706,7 @@ void write_enum_field_class_mappings(struct details_write_ctx *ctx,
                struct enum_field_class_mapping *mapping = g_new0(
                        struct enum_field_class_mapping, 1);
 
-               BT_ASSERT(mapping);
+               BT_ASSERT_DBG(mapping);
 
                if (is_signed) {
                        fc_mapping = bt_field_class_enumeration_signed_borrow_mapping_by_index_const(
@@ -739,7 +725,7 @@ void write_enum_field_class_mappings(struct details_write_ctx *ctx,
                                fc_mapping));
                mapping->ranges = range_set_to_int_ranges(fc_range_set,
                        is_signed);
-               BT_ASSERT(mapping->ranges);
+               BT_ASSERT_DBG(mapping->ranges);
                g_ptr_array_add(mappings, mapping);
        }
 
@@ -787,7 +773,7 @@ void write_field_path(struct details_write_ctx *ctx,
                write_str_prop_value(ctx, "Event payload");
                break;
        default:
-               abort();
+               bt_common_abort();
        }
 
        g_string_append(ctx->str, ": ");
@@ -809,7 +795,7 @@ void write_field_path(struct details_write_ctx *ctx,
                        write_str_prop_value(ctx, "<current>");
                        break;
                default:
-                       abort();
+                       bt_common_abort();
                }
        }
 
@@ -840,22 +826,22 @@ void write_variant_field_class_option(struct details_write_ctx *ctx,
        write_compound_member_name(ctx,
                bt_field_class_variant_option_get_name(option));
 
-       if (fc_type == BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_SELECTOR) {
-               const bt_field_class_variant_with_selector_unsigned_option *spec_opt =
-                       bt_field_class_variant_with_selector_unsigned_borrow_option_by_index_const(
+       if (fc_type == BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD) {
+               const bt_field_class_variant_with_selector_field_integer_unsigned_option *spec_opt =
+                       bt_field_class_variant_with_selector_field_integer_unsigned_borrow_option_by_index_const(
                                fc, index);
 
                orig_ranges =
-                       bt_field_class_variant_with_selector_unsigned_option_borrow_ranges_const(
+                       bt_field_class_variant_with_selector_field_integer_unsigned_option_borrow_ranges_const(
                                spec_opt);
                is_signed = false;
-       } else if (fc_type == BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_SELECTOR) {
-               const bt_field_class_variant_with_selector_signed_option *spec_opt =
-                       bt_field_class_variant_with_selector_signed_borrow_option_by_index_const(
+       } else if (fc_type == BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR_FIELD) {
+               const bt_field_class_variant_with_selector_field_integer_signed_option *spec_opt =
+                       bt_field_class_variant_with_selector_field_integer_signed_borrow_option_by_index_const(
                                fc, index);
 
                orig_ranges =
-                       bt_field_class_variant_with_selector_signed_option_borrow_ranges_const(
+                       bt_field_class_variant_with_selector_field_integer_signed_option_borrow_ranges_const(
                                spec_opt);
                is_signed = true;
        }
@@ -864,7 +850,7 @@ void write_variant_field_class_option(struct details_write_ctx *ctx,
                uint64_t i;
 
                int_ranges = range_set_to_int_ranges(orig_ranges, is_signed);
-               BT_ASSERT(int_ranges);
+               BT_ASSERT_DBG(int_ranges);
 
                for (i = 0; i < int_ranges->len; i++) {
                        struct int_range *range = int_range_at(int_ranges, i);
@@ -931,8 +917,11 @@ void write_field_class(struct details_write_ctx *ctx, const bt_field_class *fc)
        case BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION:
                type = "Signed enumeration";
                break;
-       case BT_FIELD_CLASS_TYPE_REAL:
-               type = "Real";
+       case BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL:
+               type = "Single-precision real";
+               break;
+       case BT_FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL:
+               type = "Double-precision real";
                break;
        case BT_FIELD_CLASS_TYPE_STRING:
                type = "String";
@@ -943,38 +932,42 @@ void write_field_class(struct details_write_ctx *ctx, const bt_field_class *fc)
        case BT_FIELD_CLASS_TYPE_STATIC_ARRAY:
                type = "Static array";
                break;
-       case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY:
-               type = "Dynamic array";
+       case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITHOUT_LENGTH_FIELD:
+               type = "Dynamic array (no length field)";
                break;
-       case BT_FIELD_CLASS_TYPE_OPTION:
-               type = "Option";
+       case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITH_LENGTH_FIELD:
+               type = "Dynamic array (with length field)";
                break;
-       case BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR:
+       case BT_FIELD_CLASS_TYPE_OPTION_WITHOUT_SELECTOR_FIELD:
+               type = "Option (no selector)";
+               break;
+       case BT_FIELD_CLASS_TYPE_OPTION_WITH_BOOL_SELECTOR_FIELD:
+               type = "Option (boolean selector)";
+               break;
+       case BT_FIELD_CLASS_TYPE_OPTION_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD:
+               type = "Option (unsigned integer selector)";
+               break;
+       case BT_FIELD_CLASS_TYPE_OPTION_WITH_SIGNED_INTEGER_SELECTOR_FIELD:
+               type = "Option (signed integer selector)";
+               break;
+       case BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR_FIELD:
                type = "Variant (no selector)";
                break;
-       case BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_SELECTOR:
-               type = "Variant (unsigned selector)";
+       case BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD:
+               type = "Variant (unsigned integer selector)";
                break;
-       case BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_SELECTOR:
-               type = "Variant (signed selector)";
+       case BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR_FIELD:
+               type = "Variant (signed integer selector)";
                break;
        default:
-               abort();
+               bt_common_abort();
        }
 
        g_string_append_printf(ctx->str, "%s%s%s",
                color_fg_blue(ctx), type, color_reset(ctx));
 
        /* Write field class's single-line properties */
-       switch (fc_type) {
-       case BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER:
-       case BT_FIELD_CLASS_TYPE_SIGNED_INTEGER:
-               write_sp(ctx);
-               write_int_field_class_props(ctx, fc, true);
-               break;
-       case BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION:
-       case BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION:
-       {
+       if (bt_field_class_type_is(fc_type, BT_FIELD_CLASS_TYPE_ENUMERATION)) {
                uint64_t mapping_count =
                        bt_field_class_enumeration_get_mapping_count(fc);
 
@@ -984,18 +977,11 @@ void write_field_class(struct details_write_ctx *ctx, const bt_field_class *fc)
                write_uint_prop_value(ctx, mapping_count);
                g_string_append_printf(ctx->str, " mapping%s)",
                        plural(mapping_count));
-               break;
-       }
-       case BT_FIELD_CLASS_TYPE_REAL:
-               if (bt_field_class_real_is_single_precision(fc)) {
-                       g_string_append(ctx->str, " (Single precision)");
-               } else {
-                       g_string_append(ctx->str, " (Double precision)");
-               }
-
-               break;
-       case BT_FIELD_CLASS_TYPE_STRUCTURE:
-       {
+       } else if (bt_field_class_type_is(fc_type,
+                       BT_FIELD_CLASS_TYPE_INTEGER)) {
+               write_sp(ctx);
+               write_int_field_class_props(ctx, fc, true);
+       } else if (fc_type == BT_FIELD_CLASS_TYPE_STRUCTURE) {
                uint64_t member_count =
                        bt_field_class_structure_get_member_count(fc);
 
@@ -1003,55 +989,40 @@ void write_field_class(struct details_write_ctx *ctx, const bt_field_class *fc)
                write_uint_prop_value(ctx, member_count);
                g_string_append_printf(ctx->str, " member%s)",
                        plural(member_count));
-               break;
-       }
-       case BT_FIELD_CLASS_TYPE_STATIC_ARRAY:
-       case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY:
-               if (fc_type == BT_FIELD_CLASS_TYPE_STATIC_ARRAY) {
-                       g_string_append(ctx->str, " (Length ");
-                       write_uint_prop_value(ctx,
-                               bt_field_class_array_static_get_length(fc));
-                       g_string_append_c(ctx->str, ')');
-               } else {
-                       const bt_field_path *length_field_path =
-                               bt_field_class_array_dynamic_borrow_length_field_path_const(
-                                       fc);
-
-                       if (length_field_path) {
-                               g_string_append(ctx->str, " (Length field path ");
-                               write_field_path(ctx, length_field_path);
-                               g_string_append_c(ctx->str, ')');
-                       }
-               }
+       } else if (fc_type == BT_FIELD_CLASS_TYPE_STATIC_ARRAY) {
+               g_string_append(ctx->str, " (Length ");
+               write_uint_prop_value(ctx,
+                       bt_field_class_array_static_get_length(fc));
+               g_string_append_c(ctx->str, ')');
+       } else if (fc_type == BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITH_LENGTH_FIELD) {
+               const bt_field_path *length_field_path =
+                       bt_field_class_array_dynamic_with_length_field_borrow_length_field_path_const(
+                               fc);
 
-               break;
-       case BT_FIELD_CLASS_TYPE_OPTION:
-       {
+               g_string_append(ctx->str, " (Length field path ");
+               write_field_path(ctx, length_field_path);
+               g_string_append_c(ctx->str, ')');
+       } else if (bt_field_class_type_is(fc_type,
+                       BT_FIELD_CLASS_TYPE_OPTION_WITH_SELECTOR_FIELD)) {
                const bt_field_path *selector_field_path =
-                       bt_field_class_option_borrow_selector_field_path_const(fc);
+                       bt_field_class_option_with_selector_field_borrow_selector_field_path_const(
+                               fc);
 
-               if (selector_field_path) {
-                       g_string_append(ctx->str, " (Selector field path ");
-                       write_field_path(ctx, selector_field_path);
-                       g_string_append_c(ctx->str, ')');
-               }
-
-               break;
-       }
-       case BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR:
-       case BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_SELECTOR:
-       case BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_SELECTOR:
-       {
+               g_string_append(ctx->str, " (Selector field path ");
+               write_field_path(ctx, selector_field_path);
+               g_string_append_c(ctx->str, ')');
+       } else if (bt_field_class_type_is(fc_type,
+                       BT_FIELD_CLASS_TYPE_VARIANT)) {
                uint64_t option_count =
                        bt_field_class_variant_get_option_count(fc);
                const bt_field_path *sel_field_path = NULL;
 
-               if (fc_type == BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_SELECTOR ||
-                               fc_type == BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_SELECTOR) {
+               if (bt_field_class_type_is(fc_type,
+                               BT_FIELD_CLASS_TYPE_VARIANT_WITH_SELECTOR_FIELD)) {
                        sel_field_path =
-                               bt_field_class_variant_with_selector_borrow_selector_field_path_const(
+                               bt_field_class_variant_with_selector_field_borrow_selector_field_path_const(
                                        fc);
-                       BT_ASSERT(sel_field_path);
+                       BT_ASSERT_DBG(sel_field_path);
                }
 
                g_string_append(ctx->str, " (");
@@ -1065,10 +1036,6 @@ void write_field_class(struct details_write_ctx *ctx, const bt_field_class *fc)
                }
 
                g_string_append_c(ctx->str, ')');
-               break;
-       }
-       default:
-               break;
        }
 
        incr_indent(ctx);
@@ -1080,10 +1047,7 @@ void write_field_class(struct details_write_ctx *ctx, const bt_field_class *fc)
        }
 
        /* Write field class's complex properties */
-       switch (fc_type) {
-       case BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION:
-       case BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION:
-       {
+       if (bt_field_class_type_is(fc_type, BT_FIELD_CLASS_TYPE_ENUMERATION)) {
                uint64_t mapping_count =
                        bt_field_class_enumeration_get_mapping_count(fc);
 
@@ -1105,11 +1069,7 @@ void write_field_class(struct details_write_ctx *ctx, const bt_field_class *fc)
                                decr_indent(ctx);
                        }
                }
-
-               break;
-       }
-       case BT_FIELD_CLASS_TYPE_STRUCTURE:
-       {
+       } else if (fc_type == BT_FIELD_CLASS_TYPE_STRUCTURE) {
                uint64_t member_count =
                        bt_field_class_structure_get_member_count(fc);
 
@@ -1129,17 +1089,17 @@ void write_field_class(struct details_write_ctx *ctx, const bt_field_class *fc)
                                const bt_field_class_structure_member *member =
                                        bt_field_class_structure_borrow_member_by_index_const(
                                                fc, i);
-                               const bt_value *user_attrs;
+                               const bt_value *member_user_attrs;
                                const bt_field_class *member_fc =
                                        bt_field_class_structure_member_borrow_field_class_const(member);
 
                                write_nl(ctx);
                                write_compound_member_name(ctx,
                                        bt_field_class_structure_member_get_name(member));
-                               user_attrs = bt_field_class_structure_member_borrow_user_attributes_const(
+                               member_user_attrs = bt_field_class_structure_member_borrow_user_attributes_const(
                                        member);
 
-                               if (bt_value_map_is_empty(user_attrs)) {
+                               if (bt_value_map_is_empty(member_user_attrs)) {
                                        write_sp(ctx);
                                        write_field_class(ctx, member_fc);
                                } else {
@@ -1153,7 +1113,7 @@ void write_field_class(struct details_write_ctx *ctx, const bt_field_class *fc)
                                        write_nl(ctx);
 
                                        /* User attributes */
-                                       write_user_attributes(ctx, user_attrs,
+                                       write_user_attributes(ctx, member_user_attrs,
                                                false, NULL);
 
                                        decr_indent(ctx);
@@ -1164,11 +1124,7 @@ void write_field_class(struct details_write_ctx *ctx, const bt_field_class *fc)
                                decr_indent(ctx);
                        }
                }
-
-               break;
-       }
-       case BT_FIELD_CLASS_TYPE_STATIC_ARRAY:
-       case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY:
+       } else if (bt_field_class_type_is(fc_type, BT_FIELD_CLASS_TYPE_ARRAY)) {
                if (wrote_user_attrs) {
                        write_nl(ctx);
                } else {
@@ -1179,23 +1135,52 @@ void write_field_class(struct details_write_ctx *ctx, const bt_field_class *fc)
                write_sp(ctx);
                write_field_class(ctx,
                        bt_field_class_array_borrow_element_field_class_const(fc));
-               break;
-       case BT_FIELD_CLASS_TYPE_OPTION:
+       } else if (bt_field_class_type_is(fc_type,
+                       BT_FIELD_CLASS_TYPE_OPTION)) {
+               const void *ranges = NULL;
+               bool selector_is_signed = false;
+
                if (wrote_user_attrs) {
                        write_nl(ctx);
                } else {
                        g_string_append(ctx->str, ":\n");
                }
 
+               if (fc_type == BT_FIELD_CLASS_TYPE_OPTION_WITH_BOOL_SELECTOR_FIELD) {
+                       write_bool_prop_line(ctx, "Selector is reversed",
+                               bt_field_class_option_with_selector_field_bool_selector_is_reversed(fc));
+               } else if (fc_type == BT_FIELD_CLASS_TYPE_OPTION_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD) {
+                       ranges = bt_field_class_option_with_selector_field_integer_unsigned_borrow_selector_ranges_const(fc);
+               } else if (fc_type == BT_FIELD_CLASS_TYPE_OPTION_WITH_SIGNED_INTEGER_SELECTOR_FIELD) {
+                       ranges = bt_field_class_option_with_selector_field_integer_signed_borrow_selector_ranges_const(fc);
+                       selector_is_signed = true;
+               }
+
+               if (ranges) {
+                       GArray *sorted_ranges = range_set_to_int_ranges(
+                               ranges, selector_is_signed);
+
+                       BT_ASSERT_DBG(sorted_ranges);
+                       BT_ASSERT_DBG(sorted_ranges->len > 0);
+                       write_prop_name_line(ctx, "Selector ranges");
+
+                       for (i = 0; i < sorted_ranges->len; i++) {
+                               write_sp(ctx);
+                               write_int_range(ctx,
+                                       int_range_at(sorted_ranges, i),
+                                       selector_is_signed);
+                       }
+
+                       write_nl(ctx);
+                       g_array_free(sorted_ranges, TRUE);
+               }
+
                write_prop_name_line(ctx, "Content");
                write_sp(ctx);
                write_field_class(ctx,
                        bt_field_class_option_borrow_field_class_const(fc));
-               break;
-       case BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR:
-       case BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_SELECTOR:
-       case BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_SELECTOR:
-       {
+       } else if (bt_field_class_type_is(fc_type,
+                       BT_FIELD_CLASS_TYPE_VARIANT)) {
                uint64_t option_count =
                        bt_field_class_variant_get_option_count(fc);
 
@@ -1219,11 +1204,6 @@ void write_field_class(struct details_write_ctx *ctx, const bt_field_class *fc)
                                decr_indent(ctx);
                        }
                }
-
-               break;
-       }
-       default:
-               break;
        }
 
        decr_indent(ctx);
@@ -1233,8 +1213,8 @@ static
 void write_root_field_class(struct details_write_ctx *ctx, const char *name,
                const bt_field_class *fc)
 {
-       BT_ASSERT(name);
-       BT_ASSERT(fc);
+       BT_ASSERT_DBG(name);
+       BT_ASSERT_DBG(fc);
        write_indent(ctx);
        write_prop_name(ctx, name);
        g_string_append(ctx->str, ": ");
@@ -1322,7 +1302,7 @@ void write_event_class(struct details_write_ctx *ctx, const bt_event_class *ec)
                        ll_str = "Debug";
                        break;
                default:
-                       abort();
+                       bt_common_abort();
                }
 
                write_str_prop_line(ctx, "Log level", ll_str);
@@ -1575,7 +1555,7 @@ int try_write_meta(struct details_write_ctx *ctx, const bt_trace_class *tc,
 {
        int ret = 0;
 
-       BT_ASSERT(tc);
+       BT_ASSERT_DBG(tc);
 
        if (details_need_to_write_trace_class(ctx, tc)) {
                uint64_t sc_i;
@@ -1596,7 +1576,6 @@ int try_write_meta(struct details_write_ctx *ctx, const bt_trace_class *tc,
                 * rewrite `sc`.
                 */
                write_trace_class(ctx, tc);
-               write_nl(ctx);
 
                /*
                 * Mark this trace class as written, as well as all
@@ -1631,7 +1610,7 @@ int try_write_meta(struct details_write_ctx *ctx, const bt_trace_class *tc,
        if (sc && details_need_to_write_meta_object(ctx, tc, sc)) {
                uint64_t ec_i;
 
-               BT_ASSERT(tc);
+               BT_ASSERT_DBG(tc);
 
                if (ctx->details_comp->cfg.compact &&
                                ctx->details_comp->printed_something) {
@@ -1648,7 +1627,6 @@ int try_write_meta(struct details_write_ctx *ctx, const bt_trace_class *tc,
                 * classes, so we don't need to rewrite `ec`.
                 */
                write_stream_class(ctx, sc);
-               write_nl(ctx);
 
                /*
                 * Mark this stream class as written, as well as all its
@@ -1668,7 +1646,7 @@ int try_write_meta(struct details_write_ctx *ctx, const bt_trace_class *tc,
        }
 
        if (ec && details_need_to_write_meta_object(ctx, tc, ec)) {
-               BT_ASSERT(sc);
+               BT_ASSERT_DBG(sc);
 
                if (ctx->details_comp->cfg.compact &&
                                ctx->details_comp->printed_something) {
@@ -1681,7 +1659,6 @@ int try_write_meta(struct details_write_ctx *ctx, const bt_trace_class *tc,
                }
 
                write_event_class(ctx, ec);
-               write_nl(ctx);
                details_did_write_meta_object(ctx, tc, ec);
                goto end;
        }
@@ -1698,7 +1675,8 @@ void write_time_str(struct details_write_ctx *ctx, const char *str)
        }
 
        g_string_append_printf(ctx->str, "[%s%s%s%s]",
-               color_bold(ctx), color_fg_blue(ctx), str, color_reset(ctx));
+               color_bold(ctx), color_fg_bright_blue(ctx), str,
+               color_reset(ctx));
 
        if (ctx->details_comp->cfg.compact) {
                write_sp(ctx);
@@ -1723,7 +1701,7 @@ void write_time(struct details_write_ctx *ctx, const bt_clock_snapshot *cs)
 
        format_uint(buf, bt_clock_snapshot_get_value(cs), 10);
        g_string_append_printf(ctx->str, "[%s%s%s%s%s",
-               color_bold(ctx), color_fg_blue(ctx), buf,
+               color_bold(ctx), color_fg_bright_blue(ctx), buf,
                color_reset(ctx),
                ctx->details_comp->cfg.compact ? "" : " cycles");
        cs_status = bt_clock_snapshot_get_ns_from_origin(cs, &ns_from_origin);
@@ -1731,7 +1709,7 @@ void write_time(struct details_write_ctx *ctx, const bt_clock_snapshot *cs)
                format_int(buf, ns_from_origin, 10);
                g_string_append_printf(ctx->str, "%s %s%s%s%s%s",
                        ctx->details_comp->cfg.compact ? "" : ",",
-                       color_bold(ctx), color_fg_blue(ctx), buf,
+                       color_bold(ctx), color_fg_bright_blue(ctx), buf,
                        color_reset(ctx),
                        ctx->details_comp->cfg.compact ? "" : " ns from origin");
        }
@@ -1764,22 +1742,25 @@ int write_message_follow_tag(struct details_write_ctx *ctx,
 
        if (ctx->details_comp->cfg.compact) {
                g_string_append_printf(ctx->str,
-                       "%s{%s%" PRIu64 " %" PRIu64 " %" PRIu64 "%s%s}%s ",
+                       "%s{%s%s%" PRIu64 " %" PRIu64 " %" PRIu64 "%s%s}%s ",
                        color_fg_cyan(ctx), color_bold(ctx),
+                       color_fg_bright_cyan(ctx),
                        unique_trace_id, bt_stream_class_get_id(sc),
                        bt_stream_get_id(stream),
                        color_reset(ctx), color_fg_cyan(ctx), color_reset(ctx));
        } else {
                g_string_append_printf(ctx->str,
-                       "%s{Trace %s%" PRIu64 "%s%s, Stream class ID %s%" PRIu64 "%s%s, Stream ID %s%" PRIu64 "%s%s}%s\n",
+                       "%s{Trace %s%s%" PRIu64 "%s%s, Stream class ID %s%s%" PRIu64 "%s%s, Stream ID %s%s%" PRIu64 "%s%s}%s\n",
+                       color_fg_cyan(ctx),
+                       color_bold(ctx), color_fg_bright_cyan(ctx),
+                       unique_trace_id, color_reset(ctx),
+                       color_fg_cyan(ctx),
+                       color_bold(ctx), color_fg_bright_cyan(ctx),
+                       bt_stream_class_get_id(sc), color_reset(ctx),
                        color_fg_cyan(ctx),
-                       color_bold(ctx), unique_trace_id,
-                       color_reset(ctx), color_fg_cyan(ctx),
-                       color_bold(ctx), bt_stream_class_get_id(sc),
-                       color_reset(ctx), color_fg_cyan(ctx),
-                       color_bold(ctx), bt_stream_get_id(stream),
-                       color_reset(ctx), color_fg_cyan(ctx),
-                       color_reset(ctx));
+                       color_bold(ctx), color_fg_bright_cyan(ctx),
+                       bt_stream_get_id(stream), color_reset(ctx),
+                       color_fg_cyan(ctx), color_reset(ctx));
        }
 
 end:
@@ -1801,22 +1782,16 @@ void write_field(struct details_write_ctx *ctx, const bt_field *field,
        }
 
        /* Write field's value */
-       switch (fc_type) {
-       case BT_FIELD_CLASS_TYPE_BOOL:
+       if (fc_type == BT_FIELD_CLASS_TYPE_BOOL) {
                write_sp(ctx);
                write_bool_prop_value(ctx, bt_field_bool_get_value(field));
-               break;
-       case BT_FIELD_CLASS_TYPE_BIT_ARRAY:
+       } else if (fc_type == BT_FIELD_CLASS_TYPE_BIT_ARRAY) {
                format_uint(buf, bt_field_bit_array_get_value_as_integer(field),
                        16);
                write_sp(ctx);
                write_uint_str_prop_value(ctx, buf);
-               break;
-       case BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER:
-       case BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION:
-       case BT_FIELD_CLASS_TYPE_SIGNED_INTEGER:
-       case BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION:
-       {
+       } else if (bt_field_class_type_is(fc_type,
+                       BT_FIELD_CLASS_TYPE_INTEGER)) {
                unsigned int fmt_base;
                bt_field_class_integer_preferred_display_base base;
 
@@ -1837,11 +1812,11 @@ void write_field(struct details_write_ctx *ctx, const bt_field *field,
                        fmt_base = 16;
                        break;
                default:
-                       abort();
+                       bt_common_abort();
                }
 
-               if (fc_type == BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER ||
-                               fc_type == BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION) {
+               if (bt_field_class_type_is(fc_type,
+                               BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER)) {
                        format_uint(buf,
                                bt_field_integer_unsigned_get_value(field),
                                fmt_base);
@@ -1854,19 +1829,16 @@ void write_field(struct details_write_ctx *ctx, const bt_field *field,
                        write_sp(ctx);
                        write_int_str_prop_value(ctx, buf);
                }
-
-               break;
-       }
-       case BT_FIELD_CLASS_TYPE_REAL:
+       } else if (fc_type == BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL) {
                write_sp(ctx);
-               write_float_prop_value(ctx, bt_field_real_get_value(field));
-               break;
-       case BT_FIELD_CLASS_TYPE_STRING:
+               write_float_prop_value(ctx, bt_field_real_single_precision_get_value(field));
+       } else if (fc_type == BT_FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL) {
+               write_sp(ctx);
+               write_float_prop_value(ctx, bt_field_real_double_precision_get_value(field));
+       } else if (fc_type == BT_FIELD_CLASS_TYPE_STRING) {
                write_sp(ctx);
                write_str_prop_value(ctx, bt_field_string_get_value(field));
-               break;
-       case BT_FIELD_CLASS_TYPE_STRUCTURE:
-       {
+       } else if (fc_type == BT_FIELD_CLASS_TYPE_STRUCTURE) {
                uint64_t member_count;
 
                fc = bt_field_borrow_class_const(field);
@@ -1893,12 +1865,7 @@ void write_field(struct details_write_ctx *ctx, const bt_field *field,
                        write_sp(ctx);
                        write_none_prop_value(ctx, "Empty");
                }
-
-               break;
-       }
-       case BT_FIELD_CLASS_TYPE_STATIC_ARRAY:
-       case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY:
-       {
+       } else if (bt_field_class_type_is(fc_type, BT_FIELD_CLASS_TYPE_ARRAY)) {
                uint64_t length = bt_field_array_get_length(field);
 
                if (length == 0) {
@@ -1923,10 +1890,8 @@ void write_field(struct details_write_ctx *ctx, const bt_field *field,
                }
 
                decr_indent(ctx);
-               break;
-       }
-       case BT_FIELD_CLASS_TYPE_OPTION:
-       {
+       } else if (bt_field_class_type_is(fc_type,
+                       BT_FIELD_CLASS_TYPE_OPTION)) {
                const bt_field *content_field =
                        bt_field_option_borrow_field_const(field);
 
@@ -1936,18 +1901,13 @@ void write_field(struct details_write_ctx *ctx, const bt_field *field,
                } else {
                        write_field(ctx, content_field, NULL);
                }
-
-               break;
-       }
-       case BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR:
-       case BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_SELECTOR:
-       case BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_SELECTOR:
+       } else if (bt_field_class_type_is(fc_type,
+                       BT_FIELD_CLASS_TYPE_VARIANT)) {
                write_field(ctx,
                        bt_field_variant_borrow_selected_option_field_const(
                                field), NULL);
-               break;
-       default:
-               abort();
+       } else {
+               bt_common_abort();
        }
 }
 
@@ -1955,8 +1915,8 @@ static
 void write_root_field(struct details_write_ctx *ctx, const char *name,
                const bt_field *field)
 {
-       BT_ASSERT(name);
-       BT_ASSERT(field);
+       BT_ASSERT_DBG(name);
+       BT_ASSERT_DBG(field);
        write_indent(ctx);
        write_prop_name(ctx, name);
        g_string_append(ctx->str, ":");
@@ -1982,6 +1942,18 @@ int write_event_message(struct details_write_ctx *ctx,
                goto end;
        }
 
+       if (!ctx->details_comp->cfg.with_data) {
+               goto end;
+       }
+
+       if (ctx->str->len > 0) {
+               /*
+                * Output buffer contains metadata: separate blocks with
+                * newline.
+                */
+               write_nl(ctx);
+       }
+
        /* Write time */
        if (bt_stream_class_borrow_default_clock_class_const(sc)) {
                write_time(ctx,
@@ -2038,7 +2010,6 @@ int write_event_message(struct details_write_ctx *ctx,
        decr_indent(ctx);
 
 end:
-
        return ret;
 }
 
@@ -2071,7 +2042,6 @@ gint compare_streams(const bt_stream **a, const bt_stream **b)
 static
 void write_trace(struct details_write_ctx *ctx, const bt_trace *trace)
 {
-       const char *name;
        GPtrArray *streams = g_ptr_array_new();
        uint64_t i;
        bool printed_prop = false;
@@ -2083,7 +2053,7 @@ void write_trace(struct details_write_ctx *ctx, const bt_trace *trace)
 
        /* Write name */
        if (ctx->details_comp->cfg.with_trace_name) {
-               name = bt_trace_get_name(trace);
+               const char *name = bt_trace_get_name(trace);
                if (name) {
                        g_string_append(ctx->str, " `");
                        write_str_prop_value(ctx, name);
@@ -2142,7 +2112,7 @@ void write_trace(struct details_write_ctx *ctx, const bt_trace *trace)
                                bt_trace_borrow_environment_entry_value_by_name_const(
                                        trace, name);
 
-                       BT_ASSERT(value);
+                       BT_ASSERT_DBG(value);
                        write_compound_member_name(ctx, name);
                        write_sp(ctx);
 
@@ -2155,7 +2125,7 @@ void write_trace(struct details_write_ctx *ctx, const bt_trace *trace)
                                write_str_prop_value(ctx,
                                        bt_value_string_get(value));
                        } else {
-                               abort();
+                               bt_common_abort();
                        }
 
                        write_nl(ctx);
@@ -2219,6 +2189,18 @@ int write_stream_beginning_message(struct details_write_ctx *ctx,
                goto end;
        }
 
+       if (!ctx->details_comp->cfg.with_data) {
+               goto end;
+       }
+
+       if (ctx->str->len > 0) {
+               /*
+                * Output buffer contains metadata: separate blocks with
+                * newline.
+                */
+               write_nl(ctx);
+       }
+
        /* Write time */
        if (cc) {
                const bt_clock_snapshot *cs;
@@ -2282,6 +2264,10 @@ int write_stream_end_message(struct details_write_ctx *ctx,
        const bt_clock_class *cc =
                bt_stream_class_borrow_default_clock_class_const(sc);
 
+       if (!ctx->details_comp->cfg.with_data) {
+               goto end;
+       }
+
        /* Write time */
        if (cc) {
                const bt_clock_snapshot *cs;
@@ -2319,6 +2305,10 @@ int write_packet_beginning_message(struct details_write_ctx *ctx,
        const bt_stream_class *sc = bt_stream_borrow_class_const(stream);
        const bt_field *field;
 
+       if (!ctx->details_comp->cfg.with_data) {
+               goto end;
+       }
+
        /* Write time */
        if (bt_stream_class_packets_have_beginning_default_clock_snapshot(sc)) {
                write_time(ctx,
@@ -2340,15 +2330,16 @@ int write_packet_beginning_message(struct details_write_ctx *ctx,
        }
 
        /* Write field */
-       g_string_append(ctx->str, ":\n");
-       incr_indent(ctx);
        field = bt_packet_borrow_context_field_const(packet);
        if (field) {
+               g_string_append(ctx->str, ":\n");
+               incr_indent(ctx);
                write_root_field(ctx, "Context", field);
+               decr_indent(ctx);
+       } else {
+               write_nl(ctx);
        }
 
-       decr_indent(ctx);
-
 end:
        return ret;
 }
@@ -2364,7 +2355,7 @@ int write_discarded_items_message(struct details_write_ctx *ctx,
        /* Write times */
        if (beginning_cs) {
                write_time(ctx, beginning_cs);
-               BT_ASSERT(end_cs);
+               BT_ASSERT_DBG(end_cs);
                write_time(ctx, end_cs);
        }
 
@@ -2395,6 +2386,7 @@ static
 int write_discarded_events_message(struct details_write_ctx *ctx,
                const bt_message *msg)
 {
+       int ret = 0;
        const bt_stream *stream = bt_message_discarded_events_borrow_stream_const(
                msg);
        const bt_stream_class *sc = bt_stream_borrow_class_const(stream);
@@ -2402,6 +2394,10 @@ int write_discarded_events_message(struct details_write_ctx *ctx,
        const bt_clock_snapshot *end_cs = NULL;
        uint64_t count;
 
+       if (!ctx->details_comp->cfg.with_data) {
+               goto end;
+       }
+
        if (bt_stream_class_discarded_events_have_default_clock_snapshots(sc)) {
                beginning_cs =
                        bt_message_discarded_events_borrow_beginning_default_clock_snapshot_const(
@@ -2416,14 +2412,18 @@ int write_discarded_events_message(struct details_write_ctx *ctx,
                count = UINT64_C(-1);
        }
 
-       return write_discarded_items_message(ctx, "events", stream,
+       ret = write_discarded_items_message(ctx, "events", stream,
                beginning_cs, end_cs, count);
+
+end:
+       return ret;
 }
 
 static
 int write_discarded_packets_message(struct details_write_ctx *ctx,
                const bt_message *msg)
 {
+       int ret = 0;
        const bt_stream *stream = bt_message_discarded_packets_borrow_stream_const(
                msg);
        const bt_stream_class *sc = bt_stream_borrow_class_const(stream);
@@ -2431,6 +2431,10 @@ int write_discarded_packets_message(struct details_write_ctx *ctx,
        const bt_clock_snapshot *end_cs = NULL;
        uint64_t count;
 
+       if (!ctx->details_comp->cfg.with_data) {
+               goto end;
+       }
+
        if (bt_stream_class_discarded_packets_have_default_clock_snapshots(sc)) {
                beginning_cs =
                        bt_message_discarded_packets_borrow_beginning_default_clock_snapshot_const(
@@ -2445,8 +2449,11 @@ int write_discarded_packets_message(struct details_write_ctx *ctx,
                count = UINT64_C(-1);
        }
 
-       return write_discarded_items_message(ctx, "packets", stream,
+       ret = write_discarded_items_message(ctx, "packets", stream,
                beginning_cs, end_cs, count);
+
+end:
+       return ret;
 }
 
 static
@@ -2459,6 +2466,10 @@ int write_packet_end_message(struct details_write_ctx *ctx,
        const bt_stream *stream = bt_packet_borrow_stream_const(packet);
        const bt_stream_class *sc = bt_stream_borrow_class_const(stream);
 
+       if (!ctx->details_comp->cfg.with_data) {
+               goto end;
+       }
+
        /* Write time */
        if (bt_stream_class_packets_have_end_default_clock_snapshot(sc)) {
                write_time(ctx,
@@ -2485,7 +2496,7 @@ int write_message_iterator_inactivity_message(struct details_write_ctx *ctx,
 {
        int ret = 0;
        const bt_clock_snapshot *cs =
-               bt_message_message_iterator_inactivity_borrow_default_clock_snapshot_const(
+               bt_message_message_iterator_inactivity_borrow_clock_snapshot_const(
                        msg);
 
        /* Write time */
@@ -2527,10 +2538,6 @@ int details_write_message(struct details_comp *details_comp,
        /* Reset output buffer */
        g_string_assign(details_comp->str, "");
 
-       if (details_comp->printed_something && !details_comp->cfg.compact) {
-               write_nl(&ctx);
-       }
-
        switch (bt_message_get_type(msg)) {
        case BT_MESSAGE_TYPE_EVENT:
                ret = write_event_message(&ctx, msg);
@@ -2557,7 +2564,19 @@ int details_write_message(struct details_comp *details_comp,
                ret = write_discarded_packets_message(&ctx, msg);
                break;
        default:
-               abort();
+               bt_common_abort();
+       }
+
+       /*
+        * If this component printed at least one character so far, and
+        * we're not in compact mode, and there's something in the
+        * output buffer for this message, then prepend a newline to the
+        * output buffer to visually separate message blocks.
+        */
+       if (details_comp->printed_something && !details_comp->cfg.compact &&
+                       details_comp->str->len > 0) {
+               /* TODO: Optimize this */
+               g_string_prepend_c(details_comp->str, '\n');
        }
 
        return ret;
This page took 0.03956 seconds and 4 git commands to generate.