sink.text.pretty: abort on unknown field class type
[babeltrace.git] / src / plugins / text / pretty / print.c
index 9645827e15bd6b7d912e5bcdb98d57cae52db3ae..4c7e18337b5e459787ad2233080f1b4c8d1eea6a 100644 (file)
@@ -1,26 +1,8 @@
 /*
+ * SPDX-License-Identifier: MIT
+ *
  * Copyright 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com>
  * Copyright 2016 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
- *
- * Author: Jérémie Galarneau <jeremie.galarneau@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.
- *
- * 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.
  */
 
 #include <babeltrace2/babeltrace.h>
 #include "common/assert.h"
 #include <inttypes.h>
 #include <ctype.h>
+#include <stdbool.h>
 #include <string.h>
 #include "pretty.h"
 
 #define NSEC_PER_SEC 1000000000LL
 
-#define COLOR_NAME             BT_COMMON_COLOR_BOLD
-#define COLOR_FIELD_NAME       BT_COMMON_COLOR_FG_CYAN
-#define COLOR_RST              BT_COMMON_COLOR_RESET
-#define COLOR_STRING_VALUE     BT_COMMON_COLOR_BOLD
-#define COLOR_NUMBER_VALUE     BT_COMMON_COLOR_BOLD
-#define COLOR_ENUM_MAPPING_NAME        BT_COMMON_COLOR_BOLD
-#define COLOR_UNKNOWN          BT_COMMON_COLOR_BOLD BT_COMMON_COLOR_FG_RED
-#define COLOR_EVENT_NAME       BT_COMMON_COLOR_BOLD BT_COMMON_COLOR_FG_MAGENTA
-#define COLOR_TIMESTAMP                BT_COMMON_COLOR_BOLD BT_COMMON_COLOR_FG_YELLOW
+static char color_name[32];
+static char color_field_name[32];
+static char color_rst[32];
+static char color_string_value[32];
+static char color_number_value[32];
+static char color_enum_mapping_name[32];
+static char color_unknown[32];
+static char color_event_name[32];
+static char color_timestamp[32];
 
 struct timestamp {
        int64_t real_timestamp; /* Relative to UNIX epoch. */
@@ -53,29 +36,32 @@ struct timestamp {
 
 static
 int print_field(struct pretty_component *pretty,
-               const bt_field *field, bool print_names,
-               GQuark *filters_fields, int filter_array_len);
+               const bt_field *field, bool print_names);
 
 static
 void print_name_equal(struct pretty_component *pretty, const char *name)
 {
        if (pretty->use_colors) {
-               g_string_append_printf(pretty->string, "%s%s%s = ", COLOR_NAME,
-                       name, COLOR_RST);
+               bt_common_g_string_append(pretty->string, color_name);
+               bt_common_g_string_append(pretty->string, name);
+               bt_common_g_string_append(pretty->string, color_rst);
        } else {
-               g_string_append_printf(pretty->string, "%s = ", name);
+               bt_common_g_string_append(pretty->string, name);
        }
+       bt_common_g_string_append(pretty->string, " = ");
 }
 
 static
 void print_field_name_equal(struct pretty_component *pretty, const char *name)
 {
        if (pretty->use_colors) {
-               g_string_append_printf(pretty->string, "%s%s%s = ",
-                       COLOR_FIELD_NAME, name, COLOR_RST);
+               bt_common_g_string_append(pretty->string, color_field_name);
+               bt_common_g_string_append(pretty->string, name);
+               bt_common_g_string_append(pretty->string, color_rst);
        } else {
-               g_string_append_printf(pretty->string, "%s = ", name);
+               bt_common_g_string_append(pretty->string, name);
        }
+       bt_common_g_string_append(pretty->string, " = ");
 }
 
 static
@@ -85,7 +71,7 @@ void print_timestamp_cycles(struct pretty_component *pretty,
        uint64_t cycles;
 
        cycles = bt_clock_snapshot_get_value(clock_snapshot);
-       g_string_append_printf(pretty->string, "%020" PRIu64, cycles);
+       bt_common_g_string_append_printf(pretty->string, "%020" PRIu64, cycles);
 
        if (update_last) {
                if (pretty->last_cycles_timestamp != -1ULL) {
@@ -107,14 +93,14 @@ void print_timestamp_wall(struct pretty_component *pretty,
        bool is_negative;
 
        if (!clock_snapshot) {
-               g_string_append(pretty->string, "??:??:??.?????????");
+               bt_common_g_string_append(pretty->string, "??:??:??.?????????");
                return;
        }
 
        ret = bt_clock_snapshot_get_ns_from_origin(clock_snapshot, &ts_nsec);
        if (ret) {
                // TODO: log, this is unexpected
-               g_string_append(pretty->string, "Error");
+               bt_common_g_string_append(pretty->string, "Error");
                return;
        }
 
@@ -198,17 +184,17 @@ void print_timestamp_wall(struct pretty_component *pretty,
                                goto seconds;
                        }
 
-                       g_string_append(pretty->string, timestr);
+                       bt_common_g_string_append(pretty->string, timestr);
                }
 
                /* Print time in HH:MM:SS.ns */
-               g_string_append_printf(pretty->string,
+               bt_common_g_string_append_printf(pretty->string,
                        "%02d:%02d:%02d.%09" PRIu64, tm.tm_hour, tm.tm_min,
                        tm.tm_sec, ts_nsec_abs);
                goto end;
        }
 seconds:
-       g_string_append_printf(pretty->string, "%s%" PRId64 ".%09" PRIu64,
+       bt_common_g_string_append_printf(pretty->string, "%s%" PRId64 ".%09" PRIu64,
                is_negative ? "-" : "", ts_sec_abs, ts_nsec_abs);
 end:
        return;
@@ -233,10 +219,10 @@ int print_event_timestamp(struct pretty_component *pretty,
        if (print_names) {
                print_name_equal(pretty, "timestamp");
        } else {
-               g_string_append(pretty->string, "[");
+               bt_common_g_string_append(pretty->string, "[");
        }
        if (pretty->use_colors) {
-               g_string_append(pretty->string, COLOR_TIMESTAMP);
+               bt_common_g_string_append(pretty->string, color_timestamp);
        }
        if (pretty->options.print_timestamp_cycles) {
                print_timestamp_cycles(pretty, clock_snapshot, true);
@@ -244,25 +230,25 @@ int print_event_timestamp(struct pretty_component *pretty,
                print_timestamp_wall(pretty, clock_snapshot, true);
        }
        if (pretty->use_colors) {
-               g_string_append(pretty->string, COLOR_RST);
+               bt_common_g_string_append(pretty->string, color_rst);
        }
 
        if (!print_names)
-               g_string_append(pretty->string, "] ");
+               bt_common_g_string_append(pretty->string, "] ");
 
        if (pretty->options.print_delta_field) {
                if (print_names) {
-                       g_string_append(pretty->string, ", ");
+                       bt_common_g_string_append(pretty->string, ", ");
                        print_name_equal(pretty, "delta");
                } else {
-                       g_string_append(pretty->string, "(");
+                       bt_common_g_string_append(pretty->string, "(");
                }
                if (pretty->options.print_timestamp_cycles) {
                        if (pretty->delta_cycles == -1ULL) {
-                               g_string_append(pretty->string,
+                               bt_common_g_string_append(pretty->string,
                                        "+??????????\?\?"); /* Not a trigraph. */
                        } else {
-                               g_string_append_printf(pretty->string,
+                               bt_common_g_string_append_printf(pretty->string,
                                        "+%012" PRIu64, pretty->delta_cycles);
                        }
                } else {
@@ -272,15 +258,15 @@ int print_event_timestamp(struct pretty_component *pretty,
                                delta = pretty->delta_real_timestamp;
                                delta_sec = delta / NSEC_PER_SEC;
                                delta_nsec = delta % NSEC_PER_SEC;
-                               g_string_append_printf(pretty->string,
+                               bt_common_g_string_append_printf(pretty->string,
                                        "+%" PRIu64 ".%09" PRIu64,
                                        delta_sec, delta_nsec);
                        } else {
-                               g_string_append(pretty->string, "+?.?????????");
+                               bt_common_g_string_append(pretty->string, "+?.?????????");
                        }
                }
                if (!print_names) {
-                       g_string_append(pretty->string, ") ");
+                       bt_common_g_string_append(pretty->string, ") ");
                }
        }
        *start_line = !print_names;
@@ -296,7 +282,6 @@ int print_event_header(struct pretty_component *pretty,
        bool print_names = pretty->options.print_header_field_names;
        int ret = 0;
        const bt_event_class *event_class = NULL;
-       const bt_packet *packet = NULL;
        const bt_stream *stream = NULL;
        const bt_trace *trace = NULL;
        const bt_event *event = bt_message_event_borrow_event_const(event_msg);
@@ -305,8 +290,7 @@ int print_event_header(struct pretty_component *pretty,
        bt_property_availability prop_avail;
 
        event_class = bt_event_borrow_class_const(event);
-       packet = bt_event_borrow_packet_const(event);
-       stream = bt_packet_borrow_stream_const(packet);
+       stream = bt_event_borrow_stream_const(event);
        trace = bt_stream_borrow_trace_const(stream);
        ret = print_event_timestamp(pretty, event_msg, &pretty->start_line);
        if (ret) {
@@ -318,16 +302,16 @@ int print_event_header(struct pretty_component *pretty,
                name = bt_trace_get_name(trace);
                if (name) {
                        if (!pretty->start_line) {
-                               g_string_append(pretty->string, ", ");
+                               bt_common_g_string_append(pretty->string, ", ");
                        }
                        if (print_names) {
                                print_name_equal(pretty, "trace");
                        }
 
-                       g_string_append(pretty->string, name);
+                       bt_common_g_string_append(pretty->string, name);
 
                        if (print_names) {
-                               g_string_append(pretty->string, ", ");
+                               bt_common_g_string_append(pretty->string, ", ");
                        }
                }
        }
@@ -340,13 +324,13 @@ int print_event_header(struct pretty_component *pretty,
                        const char *str;
 
                        if (!pretty->start_line) {
-                               g_string_append(pretty->string, ", ");
+                               bt_common_g_string_append(pretty->string, ", ");
                        }
                        if (print_names) {
                                print_name_equal(pretty, "trace:hostname");
                        }
                        str = bt_value_string_get(hostname_str);
-                       g_string_append(pretty->string, str);
+                       bt_common_g_string_append(pretty->string, str);
                        dom_print = 1;
                }
        }
@@ -359,15 +343,15 @@ int print_event_header(struct pretty_component *pretty,
                        const char *str;
 
                        if (!pretty->start_line) {
-                               g_string_append(pretty->string, ", ");
+                               bt_common_g_string_append(pretty->string, ", ");
                        }
                        if (print_names) {
                                print_name_equal(pretty, "trace:domain");
                        } else if (dom_print) {
-                               g_string_append(pretty->string, ":");
+                               bt_common_g_string_append(pretty->string, ":");
                        }
                        str = bt_value_string_get(domain_str);
-                       g_string_append(pretty->string, str);
+                       bt_common_g_string_append(pretty->string, str);
                        dom_print = 1;
                }
        }
@@ -380,15 +364,15 @@ int print_event_header(struct pretty_component *pretty,
                        const char *str;
 
                        if (!pretty->start_line) {
-                               g_string_append(pretty->string, ", ");
+                               bt_common_g_string_append(pretty->string, ", ");
                        }
                        if (print_names) {
                                print_name_equal(pretty, "trace:procname");
                        } else if (dom_print) {
-                               g_string_append(pretty->string, ":");
+                               bt_common_g_string_append(pretty->string, ":");
                        }
                        str = bt_value_string_get(procname_str);
-                       g_string_append(pretty->string, str);
+                       bt_common_g_string_append(pretty->string, str);
                        dom_print = 1;
                }
        }
@@ -401,15 +385,15 @@ int print_event_header(struct pretty_component *pretty,
                        int64_t value;
 
                        if (!pretty->start_line) {
-                               g_string_append(pretty->string, ", ");
+                               bt_common_g_string_append(pretty->string, ", ");
                        }
                        if (print_names) {
                                print_name_equal(pretty, "trace:vpid");
                        } else if (dom_print) {
-                               g_string_append(pretty->string, ":");
+                               bt_common_g_string_append(pretty->string, ":");
                        }
-                       value = bt_value_signed_integer_get(vpid_value);
-                       g_string_append_printf(pretty->string,
+                       value = bt_value_integer_signed_get(vpid_value);
+                       bt_common_g_string_append_printf(pretty->string,
                                "(%" PRId64 ")", value);
                        dom_print = 1;
                }
@@ -439,19 +423,19 @@ int print_event_header(struct pretty_component *pretty,
                        &log_level);
                if (prop_avail == BT_PROPERTY_AVAILABILITY_AVAILABLE) {
                        log_level_str = log_level_names[log_level];
-                       BT_ASSERT(log_level_str);
+                       BT_ASSERT_DBG(log_level_str);
 
                        if (!pretty->start_line) {
-                               g_string_append(pretty->string, ", ");
+                               bt_common_g_string_append(pretty->string, ", ");
                        }
                        if (print_names) {
                                print_name_equal(pretty, "loglevel");
                        } else if (dom_print) {
-                               g_string_append(pretty->string, ":");
+                               bt_common_g_string_append(pretty->string, ":");
                        }
 
-                       g_string_append(pretty->string, log_level_str);
-                       g_string_append_printf(
+                       bt_common_g_string_append(pretty->string, log_level_str);
+                       bt_common_g_string_append_printf(
                                pretty->string, " (%d)", (int) log_level);
                        dom_print = 1;
                }
@@ -462,23 +446,23 @@ int print_event_header(struct pretty_component *pretty,
                uri_str = bt_event_class_get_emf_uri(event_class);
                if (uri_str) {
                        if (!pretty->start_line) {
-                               g_string_append(pretty->string, ", ");
+                               bt_common_g_string_append(pretty->string, ", ");
                        }
                        if (print_names) {
                                print_name_equal(pretty, "model.emf.uri");
                        } else if (dom_print) {
-                               g_string_append(pretty->string, ":");
+                               bt_common_g_string_append(pretty->string, ":");
                        }
 
-                       g_string_append(pretty->string, uri_str);
+                       bt_common_g_string_append(pretty->string, uri_str);
                        dom_print = 1;
                }
        }
        if (dom_print && !print_names) {
-               g_string_append(pretty->string, " ");
+               bt_common_g_string_append(pretty->string, " ");
        }
        if (!pretty->start_line) {
-               g_string_append(pretty->string, ", ");
+               bt_common_g_string_append(pretty->string, ", ");
        }
        pretty->start_line = true;
        if (print_names) {
@@ -487,23 +471,25 @@ int print_event_header(struct pretty_component *pretty,
        ev_name = bt_event_class_get_name(event_class);
        if (pretty->use_colors) {
                if (ev_name) {
-                       g_string_append(pretty->string, COLOR_EVENT_NAME);
+                       bt_common_g_string_append(pretty->string,
+                               color_event_name);
                } else {
-                       g_string_append(pretty->string, COLOR_UNKNOWN);
+                       bt_common_g_string_append(pretty->string,
+                               color_unknown);
                }
        }
        if (ev_name) {
-               g_string_append(pretty->string, ev_name);
+               bt_common_g_string_append(pretty->string, ev_name);
        } else {
-               g_string_append(pretty->string, "<unknown>");
+               bt_common_g_string_append(pretty->string, "<unknown>");
        }
        if (pretty->use_colors) {
-               g_string_append(pretty->string, COLOR_RST);
+               bt_common_g_string_append(pretty->string, color_rst);
        }
        if (!print_names) {
-               g_string_append(pretty->string, ": ");
+               bt_common_g_string_append(pretty->string, ": ");
        } else {
-               g_string_append(pretty->string, ", ");
+               bt_common_g_string_append(pretty->string, ", ");
        }
 
 end:
@@ -525,17 +511,17 @@ int print_integer(struct pretty_component *pretty,
        bt_field_class_type ft_type;
 
        int_fc = bt_field_borrow_class_const(field);
-       BT_ASSERT(int_fc);
+       BT_ASSERT_DBG(int_fc);
        ft_type = bt_field_get_class_type(field);
-       if (ft_type == BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER ||
-                       ft_type == BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION) {
-               v.u = bt_field_unsigned_integer_get_value(field);
+       if (bt_field_class_type_is(ft_type,
+                       BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER)) {
+               v.u = bt_field_integer_unsigned_get_value(field);
        } else {
-               v.s = bt_field_signed_integer_get_value(field);
+               v.s = bt_field_integer_signed_get_value(field);
        }
 
        if (pretty->use_colors) {
-               g_string_append(pretty->string, COLOR_NUMBER_VALUE);
+               bt_common_g_string_append(pretty->string, color_number_value);
                rst_color = true;
        }
 
@@ -546,18 +532,19 @@ int print_integer(struct pretty_component *pretty,
                int bitnr, len;
 
                len = bt_field_class_integer_get_field_value_range(int_fc);
-               g_string_append(pretty->string, "0b");
+               bt_common_g_string_append(pretty->string, "0b");
                _bt_safe_lshift(v.u, 64 - len);
                for (bitnr = 0; bitnr < len; bitnr++) {
-                       g_string_append_printf(pretty->string, "%u", (v.u & (1ULL << 63)) ? 1 : 0);
+                       bt_common_g_string_append_c(pretty->string,
+                                               (v.u & (1ULL << 63)) ? '1' : '0');
                        _bt_safe_lshift(v.u, 1);
                }
                break;
        }
        case BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_OCTAL:
        {
-               if (ft_type == BT_FIELD_CLASS_TYPE_SIGNED_INTEGER ||
-                               ft_type == BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION) {
+               if (bt_field_class_type_is(ft_type,
+                               BT_FIELD_CLASS_TYPE_SIGNED_INTEGER)) {
                        int len;
 
                        len = bt_field_class_integer_get_field_value_range(
@@ -565,22 +552,22 @@ int print_integer(struct pretty_component *pretty,
                        if (len < 64) {
                                size_t rounded_len;
 
-                               BT_ASSERT(len != 0);
+                               BT_ASSERT_DBG(len != 0);
                                /* Round length to the nearest 3-bit */
                                rounded_len = (((len - 1) / 3) + 1) * 3;
                                v.u &= ((uint64_t) 1 << rounded_len) - 1;
                        }
                }
 
-               g_string_append_printf(pretty->string, "0%" PRIo64, v.u);
+               bt_common_g_string_append_printf(pretty->string, "0%" PRIo64, v.u);
                break;
        }
        case BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_DECIMAL:
-               if (ft_type == BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER ||
-                               ft_type == BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION) {
-                       g_string_append_printf(pretty->string, "%" PRIu64, v.u);
+               if (bt_field_class_type_is(ft_type,
+                               BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER)) {
+                       bt_common_g_string_append_printf(pretty->string, "%" PRIu64, v.u);
                } else {
-                       g_string_append_printf(pretty->string, "%" PRId64, v.s);
+                       bt_common_g_string_append_printf(pretty->string, "%" PRId64, v.s);
                }
                break;
        case BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_HEXADECIMAL:
@@ -595,7 +582,7 @@ int print_integer(struct pretty_component *pretty,
                        v.u &= ((uint64_t) 1 << rounded_len) - 1;
                }
 
-               g_string_append_printf(pretty->string, "0x%" PRIX64, v.u);
+               bt_common_g_string_append_printf(pretty->string, "0x%" PRIX64, v.u);
                break;
        }
        default:
@@ -604,7 +591,7 @@ int print_integer(struct pretty_component *pretty,
        }
 end:
        if (rst_color) {
-               g_string_append(pretty->string, COLOR_RST);
+               bt_common_g_string_append(pretty->string, color_rst);
        }
        return ret;
 }
@@ -614,164 +601,422 @@ void print_escape_string(struct pretty_component *pretty, const char *str)
 {
        int i;
 
-       g_string_append_c(pretty->string, '"');
+       bt_common_g_string_append_c(pretty->string, '"');
 
        for (i = 0; i < strlen(str); i++) {
                /* Escape sequences not recognized by iscntrl(). */
                switch (str[i]) {
                case '\\':
-                       g_string_append(pretty->string, "\\\\");
+                       bt_common_g_string_append(pretty->string, "\\\\");
                        continue;
                case '\'':
-                       g_string_append(pretty->string, "\\\'");
+                       bt_common_g_string_append(pretty->string, "\\\'");
                        continue;
                case '\"':
-                       g_string_append(pretty->string, "\\\"");
+                       bt_common_g_string_append(pretty->string, "\\\"");
                        continue;
                case '\?':
-                       g_string_append(pretty->string, "\\\?");
+                       bt_common_g_string_append(pretty->string, "\\\?");
                        continue;
                }
 
                /* Standard characters. */
-               if (!iscntrl(str[i])) {
-                       g_string_append_c(pretty->string, str[i]);
+               if (!iscntrl((unsigned char) str[i])) {
+                       bt_common_g_string_append_c(pretty->string, str[i]);
                        continue;
                }
 
                switch (str[i]) {
                case '\0':
-                       g_string_append(pretty->string, "\\0");
+                       bt_common_g_string_append(pretty->string, "\\0");
                        break;
                case '\a':
-                       g_string_append(pretty->string, "\\a");
+                       bt_common_g_string_append(pretty->string, "\\a");
                        break;
                case '\b':
-                       g_string_append(pretty->string, "\\b");
+                       bt_common_g_string_append(pretty->string, "\\b");
                        break;
                case '\e':
-                       g_string_append(pretty->string, "\\e");
+                       bt_common_g_string_append(pretty->string, "\\e");
                        break;
                case '\f':
-                       g_string_append(pretty->string, "\\f");
+                       bt_common_g_string_append(pretty->string, "\\f");
                        break;
                case '\n':
-                       g_string_append(pretty->string, "\\n");
+                       bt_common_g_string_append(pretty->string, "\\n");
                        break;
                case '\r':
-                       g_string_append(pretty->string, "\\r");
+                       bt_common_g_string_append(pretty->string, "\\r");
                        break;
                case '\t':
-                       g_string_append(pretty->string, "\\t");
+                       bt_common_g_string_append(pretty->string, "\\t");
                        break;
                case '\v':
-                       g_string_append(pretty->string, "\\v");
+                       bt_common_g_string_append(pretty->string, "\\v");
                        break;
                default:
                        /* Unhandled control-sequence, print as hex. */
-                       g_string_append_printf(pretty->string, "\\x%02x", str[i]);
+                       bt_common_g_string_append_printf(pretty->string, "\\x%02x", str[i]);
                        break;
                }
        }
 
-       g_string_append_c(pretty->string, '"');
+       bt_common_g_string_append_c(pretty->string, '"');
 }
 
+/*
+ * Print the unknown label.
+ */
 static
-int print_enum(struct pretty_component *pretty,
-               const bt_field *field)
+void print_enum_value_label_unknown(struct pretty_component *pretty)
 {
-       int ret = 0;
-       const bt_field_class *enumeration_field_class = NULL;
-       bt_field_class_enumeration_mapping_label_array label_array;
-       uint64_t label_count;
-       uint64_t i;
-
-       enumeration_field_class = bt_field_borrow_class_const(field);
-       if (!enumeration_field_class) {
-               ret = -1;
-               goto end;
+       if (pretty->use_colors) {
+               bt_common_g_string_append(pretty->string, color_unknown);
        }
 
-       switch (bt_field_get_class_type(field)) {
-       case BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION:
-               ret = bt_field_unsigned_enumeration_get_mapping_labels(field,
-                       &label_array, &label_count);
-               break;
-       case BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION:
-               ret = bt_field_signed_enumeration_get_mapping_labels(field,
-                       &label_array, &label_count);
-               break;
-       default:
-               abort();
-       }
+       bt_common_g_string_append(pretty->string, "<unknown>");
 
-       if (ret) {
-               ret = -1;
-               goto end;
+       if (pretty->use_colors) {
+               bt_common_g_string_append(pretty->string, color_rst);
        }
+}
 
-       g_string_append(pretty->string, "( ");
-       if (label_count == 0) {
-               if (pretty->use_colors) {
-                       g_string_append(pretty->string, COLOR_UNKNOWN);
-               }
-               g_string_append(pretty->string, "<unknown>");
-               if (pretty->use_colors) {
-                       g_string_append(pretty->string, COLOR_RST);
-               }
-               goto skip_loop;
+/*
+ * 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) {
-                       g_string_append(pretty->string, ", ");
+                       bt_common_g_string_append(pretty->string, ", ");
                }
                if (pretty->use_colors) {
-                       g_string_append(pretty->string, COLOR_ENUM_MAPPING_NAME);
+                       bt_common_g_string_append(pretty->string, color_enum_mapping_name);
                }
                print_escape_string(pretty, mapping_name);
                if (pretty->use_colors) {
-                       g_string_append(pretty->string, COLOR_RST);
+                       bt_common_g_string_append(pretty->string, color_rst);
                }
        }
-skip_loop:
-       g_string_append(pretty->string, " : container = ");
-       ret = print_integer(pretty, field);
-       if (ret != 0) {
+
+       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,
+               const bt_field *field)
+{
+       uint64_t i;
+       uint64_t value = bt_field_integer_unsigned_get_value(field);
+       const bt_field_class *fc = bt_field_borrow_class_const(field);
+
+       /* Value is 0, if there was a label for it, we would know by now. */
+       if (value == 0) {
+               print_enum_value_label_unknown(pretty);
                goto end;
        }
-       g_string_append(pretty->string, " )");
+
+       for (i = 0; i < ENUMERATION_MAX_BITFLAGS_COUNT; i++) {
+               uint64_t bit_value = UINT64_C(1) << i;
+
+               if ((value & bit_value) != 0) {
+                       print_enum_unsigned_get_mapping_labels_for_value(
+                               fc, bit_value, pretty->enum_bit_labels[i]);
+
+                       if (pretty->enum_bit_labels[i]->len == 0) {
+                               /*
+                                * This bit has no matching label, so this
+                                * field is not a bit flag field, print
+                                * unknown and return.
+                                */
+                               print_enum_value_label_unknown(pretty);
+                               goto end;
+                       }
+               }
+       }
+
+       print_enum_value_bit_flag_label_arrays(pretty);
+
 end:
-       return ret;
+       return;
 }
 
+/*
+ * Get the labels mapping to a signed 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
-int filter_field_name(struct pretty_component *pretty, const char *field_name,
-               GQuark *filter_fields, int filter_array_len)
+void print_enum_signed_get_mapping_labels_for_value(const bt_field_class *fc,
+               int64_t value, GPtrArray *labels)
 {
-       int i;
-       GQuark field_quark = g_quark_try_string(field_name);
+       uint64_t mapping_count = bt_field_class_enumeration_get_mapping_count(fc);
+       uint64_t i;
 
-       if (!field_quark || pretty->options.verbose) {
-               return 1;
+       for (i = 0; i < mapping_count; i++) {
+               uint64_t range_i;
+               const struct bt_field_class_enumeration_signed_mapping *mapping =
+                       bt_field_class_enumeration_signed_borrow_mapping_by_index_const(fc, i);
+               const bt_integer_range_set_signed *ranges =
+                       bt_field_class_enumeration_signed_mapping_borrow_ranges_const(mapping);
+               uint64_t range_count = bt_integer_range_set_get_range_count(
+                               bt_integer_range_set_signed_as_range_set_const(ranges));
+
+               for (range_i = 0; range_i < range_count; range_i++) {
+                       const bt_integer_range_signed *range =
+                               bt_integer_range_set_signed_borrow_range_by_index_const(ranges, range_i);
+                       uint64_t lower = bt_integer_range_signed_get_lower(range);
+                       uint64_t upper = bt_integer_range_signed_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_signed_mapping_as_mapping_const(mapping)));
+                               break;
+                       }
+               }
        }
+}
 
-       for (i = 0; i < filter_array_len; i++) {
-               if (field_quark == filter_fields[i]) {
-                       return 0;
+/*
+ * Splits a signed 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_signed_try_bit_flags(struct pretty_component *pretty,
+               const bt_field *field)
+{
+       uint64_t i;
+       int64_t value = bt_field_integer_signed_get_value(field);
+       const bt_field_class *fc = bt_field_borrow_class_const(field);
+
+       /*
+        * Negative value, not a bit flag enum
+        * For 0, if there was a value, we would know by now.
+        */
+       if (value <= 0) {
+               print_enum_value_label_unknown(pretty);
+               goto end;
+       }
+
+       for (i = 0; i < ENUMERATION_MAX_BITFLAGS_COUNT; i++) {
+               uint64_t bit_value = 1ULL << i;
+
+               if ((value & bit_value) != 0) {
+                       print_enum_signed_get_mapping_labels_for_value(
+                               fc, bit_value, pretty->enum_bit_labels[i]);
+
+                       if (pretty->enum_bit_labels[i]->len == 0) {
+                               /*
+                                * This bit has no matching label, so this
+                                * field is not a bit flag field, print
+                                * unknown and return.
+                                */
+                               print_enum_value_label_unknown(pretty);
+                               goto end;
+                       }
                }
        }
-       return 1;
+
+       print_enum_value_bit_flag_label_arrays(pretty);
+
+end:
+       return;
+}
+
+/*
+ * Main function to try to print the value of the enum field as a
+ * bit flag. It calls the appropriate function depending on the
+ * field type's signedness and prints the label for each bit set,
+ * if it's a bit flag field.
+ */
+static
+void print_enum_try_bit_flags(struct pretty_component *pretty,
+               const bt_field *field)
+{
+       const bt_field_class *fc = bt_field_borrow_class_const(field);
+       uint64_t int_range = bt_field_class_integer_get_field_value_range(fc);
+       int i;
+
+       BT_ASSERT(int_range <= ENUMERATION_MAX_BITFLAGS_COUNT);
+
+       /*
+        * Remove all labels from the previous enumeration field.
+        */
+       for (i = 0; i < ENUMERATION_MAX_BITFLAGS_COUNT; i++) {
+               g_ptr_array_set_size(pretty->enum_bit_labels[i], 0);
+       }
+
+       /* Get the mapping labels for the bit value. */
+       switch (bt_field_class_get_type(fc)) {
+       case BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION:
+               print_enum_unsigned_try_bit_flags(pretty, field);
+               break;
+       case BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION:
+               print_enum_signed_try_bit_flags(pretty, field);
+               break;
+       default:
+               bt_common_abort();
+       }
+}
+
+static
+int print_enum(struct pretty_component *pretty,
+               const bt_field *field)
+{
+       int ret = 0;
+       bt_field_class_enumeration_mapping_label_array label_array;
+       uint64_t label_count;
+
+       switch (bt_field_get_class_type(field)) {
+       case BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION:
+               ret = bt_field_enumeration_unsigned_get_mapping_labels(field,
+                       &label_array, &label_count);
+               break;
+       case BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION:
+               ret = bt_field_enumeration_signed_get_mapping_labels(field,
+                       &label_array, &label_count);
+               break;
+       default:
+               bt_common_abort();
+       }
+
+       if (ret) {
+               ret = -1;
+               goto end;
+       }
+
+       bt_common_g_string_append(pretty->string, "( ");
+       if (label_count != 0) {
+               /* The numerical value matches some labels, print them. */
+               print_enum_value_label_array(pretty, label_count, label_array);
+       } else if (pretty->options.print_enum_flags) {
+               /*
+                * The numerical value of the enumeration does not match any
+                * label but the `print-enum-flags` parameter is TRUE so try to
+                * decompose the value of the enum into bits and print it as a
+                * bit flag enum.
+                */
+               print_enum_try_bit_flags(pretty, field);
+       } else {
+               print_enum_value_label_unknown(pretty);
+       }
+
+       /* Print the actual value of the enum. */
+       bt_common_g_string_append(pretty->string, " : container = ");
+       ret = print_integer(pretty, field);
+       if (ret != 0) {
+               goto end;
+       }
+       bt_common_g_string_append(pretty->string, " )");
+end:
+       return ret;
 }
 
 static
 int print_struct_field(struct pretty_component *pretty,
                const bt_field *_struct,
                const bt_field_class *struct_class,
-               uint64_t i, bool print_names, uint64_t *nr_printed_fields,
-               GQuark *filter_fields, int filter_array_len)
+               uint64_t i, bool print_names, uint64_t *nr_printed_fields)
 {
        int ret = 0;
        const char *field_name;
@@ -788,21 +1033,15 @@ int print_struct_field(struct pretty_component *pretty,
                struct_class, i);
        field_name = bt_field_class_structure_member_get_name(member);
 
-       if (filter_fields && !filter_field_name(pretty, field_name,
-                               filter_fields, filter_array_len)) {
-               ret = 0;
-               goto end;
-       }
-
        if (*nr_printed_fields > 0) {
-               g_string_append(pretty->string, ", ");
+               bt_common_g_string_append(pretty->string, ", ");
        } else {
-               g_string_append(pretty->string, " ");
+               bt_common_g_string_append(pretty->string, " ");
        }
        if (print_names) {
                print_field_name_equal(pretty, field_name);
        }
-       ret = print_field(pretty, field, print_names, NULL, 0);
+       ret = print_field(pretty, field, print_names);
        *nr_printed_fields += 1;
 
 end:
@@ -811,34 +1050,27 @@ end:
 
 static
 int print_struct(struct pretty_component *pretty,
-               const bt_field *_struct, bool print_names,
-               GQuark *filter_fields, int filter_array_len)
+               const bt_field *_struct, bool print_names)
 {
        int ret = 0;
        const bt_field_class *struct_class = NULL;
        uint64_t nr_fields, i, nr_printed_fields;
 
        struct_class = bt_field_borrow_class_const(_struct);
-       if (!struct_class) {
-               ret = -1;
-               goto end;
-       }
-
        nr_fields = bt_field_class_structure_get_member_count(struct_class);
 
-       g_string_append(pretty->string, "{");
+       bt_common_g_string_append(pretty->string, "{");
        pretty->depth++;
        nr_printed_fields = 0;
        for (i = 0; i < nr_fields; i++) {
                ret = print_struct_field(pretty, _struct, struct_class, i,
-                               print_names, &nr_printed_fields, filter_fields,
-                               filter_array_len);
+                               print_names, &nr_printed_fields);
                if (ret != 0) {
                        goto end;
                }
        }
        pretty->depth--;
-       g_string_append(pretty->string, " }");
+       bt_common_g_string_append(pretty->string, " }");
 
 end:
        return ret;
@@ -851,17 +1083,17 @@ int print_array_field(struct pretty_component *pretty,
        const bt_field *field = NULL;
 
        if (i != 0) {
-               g_string_append(pretty->string, ", ");
+               bt_common_g_string_append(pretty->string, ", ");
        } else {
-               g_string_append(pretty->string, " ");
+               bt_common_g_string_append(pretty->string, " ");
        }
        if (print_names) {
-               g_string_append_printf(pretty->string, "[%" PRIu64 "] = ", i);
+               bt_common_g_string_append_printf(pretty->string, "[%" PRIu64 "] = ", i);
        }
 
        field = bt_field_array_borrow_element_field_by_index_const(array, i);
-       BT_ASSERT(field);
-       return print_field(pretty, field, print_names, NULL, 0);
+       BT_ASSERT_DBG(field);
+       return print_field(pretty, field, print_names);
 }
 
 static
@@ -869,17 +1101,11 @@ int print_array(struct pretty_component *pretty,
                const bt_field *array, bool print_names)
 {
        int ret = 0;
-       const bt_field_class *array_class = NULL;
        uint64_t len;
        uint64_t i;
 
-       array_class = bt_field_borrow_class_const(array);
-       if (!array_class) {
-               ret = -1;
-               goto end;
-       }
        len = bt_field_array_get_length(array);
-       g_string_append(pretty->string, "[");
+       bt_common_g_string_append(pretty->string, "[");
        pretty->depth++;
        for (i = 0; i < len; i++) {
                ret = print_array_field(pretty, array, i, print_names);
@@ -888,7 +1114,7 @@ int print_array(struct pretty_component *pretty,
                }
        }
        pretty->depth--;
-       g_string_append(pretty->string, " ]");
+       bt_common_g_string_append(pretty->string, " ]");
 
 end:
        return ret;
@@ -901,17 +1127,17 @@ int print_sequence_field(struct pretty_component *pretty,
        const bt_field *field = NULL;
 
        if (i != 0) {
-               g_string_append(pretty->string, ", ");
+               bt_common_g_string_append(pretty->string, ", ");
        } else {
-               g_string_append(pretty->string, " ");
+               bt_common_g_string_append(pretty->string, " ");
        }
        if (print_names) {
-               g_string_append_printf(pretty->string, "[%" PRIu64 "] = ", i);
+               bt_common_g_string_append_printf(pretty->string, "[%" PRIu64 "] = ", i);
        }
 
        field = bt_field_array_borrow_element_field_by_index_const(seq, i);
-       BT_ASSERT(field);
-       return print_field(pretty, field, print_names, NULL, 0);
+       BT_ASSERT_DBG(field);
+       return print_field(pretty, field, print_names);
 }
 
 static
@@ -923,7 +1149,7 @@ int print_sequence(struct pretty_component *pretty,
        uint64_t i;
 
        len = bt_field_array_get_length(seq);
-       g_string_append(pretty->string, "[");
+       bt_common_g_string_append(pretty->string, "[");
 
        pretty->depth++;
        for (i = 0; i < len; i++) {
@@ -933,7 +1159,36 @@ int print_sequence(struct pretty_component *pretty,
                }
        }
        pretty->depth--;
-       g_string_append(pretty->string, " ]");
+       bt_common_g_string_append(pretty->string, " ]");
+
+end:
+       return ret;
+}
+
+static
+int print_option(struct pretty_component *pretty,
+               const bt_field *option, bool print_names)
+{
+       int ret = 0;
+       const bt_field *field = NULL;
+
+       field = bt_field_option_borrow_field_const(option);
+       if (field) {
+               bt_common_g_string_append(pretty->string, "{ ");
+               pretty->depth++;
+               if (print_names) {
+                       // TODO: find tag's name using field path
+                       // print_field_name_equal(pretty, tag_choice);
+               }
+               ret = print_field(pretty, field, print_names);
+               if (ret != 0) {
+                       goto end;
+               }
+               pretty->depth--;
+               bt_common_g_string_append(pretty->string, " }");
+       } else {
+               bt_common_g_string_append(pretty->string, "<none>");
+       }
 
 end:
        return ret;
@@ -947,19 +1202,19 @@ int print_variant(struct pretty_component *pretty,
        const bt_field *field = NULL;
 
        field = bt_field_variant_borrow_selected_option_field_const(variant);
-       BT_ASSERT(field);
-       g_string_append(pretty->string, "{ ");
+       BT_ASSERT_DBG(field);
+       bt_common_g_string_append(pretty->string, "{ ");
        pretty->depth++;
        if (print_names) {
                // TODO: find tag's name using field path
                // print_field_name_equal(pretty, tag_choice);
        }
-       ret = print_field(pretty, field, print_names, NULL, 0);
+       ret = print_field(pretty, field, print_names);
        if (ret != 0) {
                goto end;
        }
        pretty->depth--;
-       g_string_append(pretty->string, " }");
+       bt_common_g_string_append(pretty->string, " }");
 
 end:
        return ret;
@@ -967,35 +1222,67 @@ end:
 
 static
 int print_field(struct pretty_component *pretty,
-               const bt_field *field, bool print_names,
-               GQuark *filter_fields, int filter_array_len)
+               const bt_field *field, bool print_names)
 {
        bt_field_class_type class_id;
 
        class_id = bt_field_get_class_type(field);
-       switch (class_id) {
-       case BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER:
-       case BT_FIELD_CLASS_TYPE_SIGNED_INTEGER:
+       if (class_id == BT_FIELD_CLASS_TYPE_BOOL) {
+               bt_bool v;
+               const char *text;
+
+               v = bt_field_bool_get_value(field);
+               if (pretty->use_colors) {
+                       bt_common_g_string_append(pretty->string, color_number_value);
+               }
+               if (v) {
+                       text = "true";
+               } else {
+                       text = "false";
+               }
+               bt_common_g_string_append(pretty->string, text);
+               if (pretty->use_colors) {
+                       bt_common_g_string_append(pretty->string, color_rst);
+               }
+               return 0;
+       } else if (class_id == BT_FIELD_CLASS_TYPE_BIT_ARRAY) {
+               uint64_t v = bt_field_bit_array_get_value_as_integer(field);
+
+               if (pretty->use_colors) {
+                       bt_common_g_string_append(pretty->string,
+                               color_number_value);
+               }
+               bt_common_g_string_append_printf(pretty->string, "0x%" PRIX64,
+                       v);
+               if (pretty->use_colors) {
+                       bt_common_g_string_append(pretty->string, color_rst);
+               }
+               return 0;
+       } else if (bt_field_class_type_is(class_id,
+                       BT_FIELD_CLASS_TYPE_ENUMERATION)) {
+               return print_enum(pretty, field);
+       } else if (bt_field_class_type_is(class_id,
+                       BT_FIELD_CLASS_TYPE_INTEGER)) {
                return print_integer(pretty, field);
-       case BT_FIELD_CLASS_TYPE_REAL:
-       {
+       } else if (bt_field_class_type_is(class_id,
+                       BT_FIELD_CLASS_TYPE_REAL)) {
                double v;
 
-               v = bt_field_real_get_value(field);
+               if (class_id == BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL) {
+                       v = bt_field_real_single_precision_get_value(field);
+               } else {
+                       v = bt_field_real_double_precision_get_value(field);
+               }
+
                if (pretty->use_colors) {
-                       g_string_append(pretty->string, COLOR_NUMBER_VALUE);
+                       bt_common_g_string_append(pretty->string, color_number_value);
                }
-               g_string_append_printf(pretty->string, "%g", v);
+               bt_common_g_string_append_printf(pretty->string, "%g", v);
                if (pretty->use_colors) {
-                       g_string_append(pretty->string, COLOR_RST);
+                       bt_common_g_string_append(pretty->string, color_rst);
                }
                return 0;
-       }
-       case BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION:
-       case BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION:
-               return print_enum(pretty, field);
-       case BT_FIELD_CLASS_TYPE_STRING:
-       {
+       } else if (class_id == BT_FIELD_CLASS_TYPE_STRING) {
                const char *str;
 
                str = bt_field_string_get_value(field);
@@ -1004,28 +1291,29 @@ int print_field(struct pretty_component *pretty,
                }
 
                if (pretty->use_colors) {
-                       g_string_append(pretty->string, COLOR_STRING_VALUE);
+                       bt_common_g_string_append(pretty->string, color_string_value);
                }
                print_escape_string(pretty, str);
                if (pretty->use_colors) {
-                       g_string_append(pretty->string, COLOR_RST);
+                       bt_common_g_string_append(pretty->string, color_rst);
                }
                return 0;
-       }
-       case BT_FIELD_CLASS_TYPE_STRUCTURE:
-               return print_struct(pretty, field, print_names, filter_fields,
-                               filter_array_len);
-       case BT_FIELD_CLASS_TYPE_VARIANT:
+       } else if (class_id == BT_FIELD_CLASS_TYPE_STRUCTURE) {
+               return print_struct(pretty, field, print_names);
+       } else if (bt_field_class_type_is(class_id,
+                       BT_FIELD_CLASS_TYPE_OPTION)) {
+               return print_option(pretty, field, print_names);
+       } else if (bt_field_class_type_is(class_id,
+                       BT_FIELD_CLASS_TYPE_VARIANT)) {
                return print_variant(pretty, field, print_names);
-       case BT_FIELD_CLASS_TYPE_STATIC_ARRAY:
+       } else if (class_id == BT_FIELD_CLASS_TYPE_STATIC_ARRAY) {
                return print_array(pretty, field, print_names);
-       case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY:
+       } else if (bt_field_class_type_is(class_id,
+                       BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY)) {
                return print_sequence(pretty, field, print_names);
-       default:
-               // TODO: log instead
-               fprintf(pretty->err, "[error] Unknown type id: %d\n", (int) class_id);
-               return -1;
        }
+
+       bt_common_abort();
 }
 
 static
@@ -1038,7 +1326,6 @@ int print_stream_packet_context(struct pretty_component *pretty,
 
        packet = bt_event_borrow_packet_const(event);
        if (!packet) {
-               ret = -1;
                goto end;
        }
        main_field = bt_packet_borrow_context_field_const(packet);
@@ -1046,16 +1333,14 @@ int print_stream_packet_context(struct pretty_component *pretty,
                goto end;
        }
        if (!pretty->start_line) {
-               g_string_append(pretty->string, ", ");
+               bt_common_g_string_append(pretty->string, ", ");
        }
        pretty->start_line = false;
        if (pretty->options.print_scope_field_names) {
                print_name_equal(pretty, "stream.packet.context");
        }
        ret = print_field(pretty, main_field,
-                       pretty->options.print_context_field_names,
-                       stream_packet_context_quarks,
-                       STREAM_PACKET_CONTEXT_QUARKS_LEN);
+                       pretty->options.print_context_field_names);
 
 end:
        return ret;
@@ -1073,14 +1358,14 @@ int print_stream_event_context(struct pretty_component *pretty,
                goto end;
        }
        if (!pretty->start_line) {
-               g_string_append(pretty->string, ", ");
+               bt_common_g_string_append(pretty->string, ", ");
        }
        pretty->start_line = false;
        if (pretty->options.print_scope_field_names) {
                print_name_equal(pretty, "stream.event.context");
        }
        ret = print_field(pretty, main_field,
-                       pretty->options.print_context_field_names, NULL, 0);
+                       pretty->options.print_context_field_names);
 
 end:
        return ret;
@@ -1098,14 +1383,14 @@ int print_event_context(struct pretty_component *pretty,
                goto end;
        }
        if (!pretty->start_line) {
-               g_string_append(pretty->string, ", ");
+               bt_common_g_string_append(pretty->string, ", ");
        }
        pretty->start_line = false;
        if (pretty->options.print_scope_field_names) {
                print_name_equal(pretty, "event.context");
        }
        ret = print_field(pretty, main_field,
-                       pretty->options.print_context_field_names, NULL, 0);
+                       pretty->options.print_context_field_names);
 
 end:
        return ret;
@@ -1123,14 +1408,14 @@ int print_event_payload(struct pretty_component *pretty,
                goto end;
        }
        if (!pretty->start_line) {
-               g_string_append(pretty->string, ", ");
+               bt_common_g_string_append(pretty->string, ", ");
        }
        pretty->start_line = false;
        if (pretty->options.print_scope_field_names) {
                print_name_equal(pretty, "event.fields");
        }
        ret = print_field(pretty, main_field,
-                       pretty->options.print_payload_field_names, NULL, 0);
+                       pretty->options.print_payload_field_names);
 
 end:
        return ret;
@@ -1153,7 +1438,6 @@ end:
        return ret;
 }
 
-BT_HIDDEN
 int pretty_print_event(struct pretty_component *pretty,
                const bt_message *event_msg)
 {
@@ -1161,7 +1445,7 @@ int pretty_print_event(struct pretty_component *pretty,
        const bt_event *event =
                bt_message_event_borrow_event_const(event_msg);
 
-       BT_ASSERT(event);
+       BT_ASSERT_DBG(event);
        pretty->start_line = true;
        g_string_assign(pretty->string, "");
        ret = print_event_header(pretty, event_msg);
@@ -1189,7 +1473,7 @@ int pretty_print_event(struct pretty_component *pretty,
                goto end;
        }
 
-       g_string_append_c(pretty->string, '\n');
+       bt_common_g_string_append_c(pretty->string, '\n');
        if (flush_buf(pretty->out, pretty)) {
                ret = -1;
                goto end;
@@ -1250,7 +1534,7 @@ int print_discarded_elements_msg(struct pretty_component *pretty,
                init_msg = "Tracer discarded";
        }
 
-       g_string_append_printf(pretty->string,
+       bt_common_g_string_append_printf(pretty->string,
                "%s%sWARNING%s%s: %s ",
                bt_common_color_fg_yellow(),
                bt_common_color_bold(),
@@ -1258,47 +1542,47 @@ int print_discarded_elements_msg(struct pretty_component *pretty,
                bt_common_color_fg_yellow(), init_msg);
 
        if (count == UINT64_C(-1)) {
-               g_string_append_printf(pretty->string, "%ss", elem_type);
+               bt_common_g_string_append_printf(pretty->string, "%ss", elem_type);
        } else {
-               g_string_append_printf(pretty->string,
+               bt_common_g_string_append_printf(pretty->string,
                        "%" PRIu64 " %s%s", count, elem_type,
                        count == 1 ? "" : "s");
        }
 
-       g_string_append_c(pretty->string, ' ');
+       bt_common_g_string_append_c(pretty->string, ' ');
 
        if (begin_clock_snapshot && end_clock_snapshot) {
-               g_string_append(pretty->string, "between [");
+               bt_common_g_string_append(pretty->string, "between [");
                print_timestamp_wall(pretty, begin_clock_snapshot, false);
-               g_string_append(pretty->string, "] and [");
+               bt_common_g_string_append(pretty->string, "] and [");
                print_timestamp_wall(pretty, end_clock_snapshot, false);
-               g_string_append(pretty->string, "]");
+               bt_common_g_string_append(pretty->string, "]");
        } else {
-               g_string_append(pretty->string, "(unknown time range)");
+               bt_common_g_string_append(pretty->string, "(unknown time range)");
        }
 
-       g_string_append_printf(pretty->string, " in trace \"%s\" ", trace_name);
+       bt_common_g_string_append_printf(pretty->string, " in trace \"%s\" ", trace_name);
 
        if (trace_uuid) {
-               g_string_append_printf(pretty->string,
+               bt_common_g_string_append_printf(pretty->string,
                        "(UUID: " BT_UUID_FMT ") ",
                        BT_UUID_FMT_VALUES(trace_uuid));
        } else {
-               g_string_append(pretty->string, "(no UUID) ");
+               bt_common_g_string_append(pretty->string, "(no UUID) ");
        }
 
-       g_string_append_printf(pretty->string,
+       bt_common_g_string_append_printf(pretty->string,
                "within stream \"%s\" (stream class ID: %" PRIu64 ", ",
                stream_name, stream_class_id);
 
        if (stream_id >= 0) {
-               g_string_append_printf(pretty->string,
+               bt_common_g_string_append_printf(pretty->string,
                        "stream ID: %" PRIu64, stream_id);
        } else {
-               g_string_append(pretty->string, "no stream ID");
+               bt_common_g_string_append(pretty->string, "no stream ID");
        }
 
-       g_string_append_printf(pretty->string, ").%s\n",
+       bt_common_g_string_append_printf(pretty->string, ").%s\n",
                bt_common_color_reset());
 
        /*
@@ -1312,7 +1596,6 @@ int print_discarded_elements_msg(struct pretty_component *pretty,
        return ret;
 }
 
-BT_HIDDEN
 int pretty_print_discarded_items(struct pretty_component *pretty,
                const bt_message *msg)
 {
@@ -1345,7 +1628,7 @@ int pretty_print_discarded_items(struct pretty_component *pretty,
                elem_type = "packet";
                break;
        default:
-               abort();
+               bt_common_abort();
        }
 
        BT_ASSERT(stream);
@@ -1373,10 +1656,26 @@ int pretty_print_discarded_items(struct pretty_component *pretty,
 
                break;
        default:
-               abort();
+               bt_common_abort();
        }
 
        print_discarded_elements_msg(pretty, stream, begin, end,
                count, elem_type);
        return 0;
 }
+
+void pretty_print_init(void)
+{
+       strcpy(color_name, bt_common_color_bold());
+       strcpy(color_field_name, bt_common_color_fg_cyan());
+       strcpy(color_rst, bt_common_color_reset());
+       strcpy(color_string_value, bt_common_color_bold());
+       strcpy(color_number_value, bt_common_color_bold());
+       strcpy(color_enum_mapping_name, bt_common_color_bold());
+       strcpy(color_unknown, bt_common_color_bold());
+       strcat(color_unknown, bt_common_color_fg_bright_red());
+       strcpy(color_event_name, bt_common_color_bold());
+       strcat(color_event_name, bt_common_color_fg_bright_magenta());
+       strcpy(color_timestamp, bt_common_color_bold());
+       strcat(color_timestamp, bt_common_color_fg_bright_yellow());
+}
This page took 0.047504 seconds and 4 git commands to generate.