Enumeration mapping iterator's initial position is inconsistent
[babeltrace.git] / plugins / text / pretty / print.c
index cc2d47d512cdcca7a97ec53477a6a4e37fc64be7..7234b8a485bbe4d94e4bbc3e37e6c5b3dd1a5535 100644 (file)
  * SOFTWARE.
  */
 
-#include <babeltrace/ctf-ir/event.h>
-#include <babeltrace/ctf-ir/event-class.h>
-#include <babeltrace/ctf-ir/packet.h>
-#include <babeltrace/ctf-ir/stream.h>
-#include <babeltrace/ctf-ir/stream-class.h>
-#include <babeltrace/ctf-ir/clock-class.h>
-#include <babeltrace/ctf-ir/field-types.h>
-#include <babeltrace/ctf-ir/fields.h>
-#include <babeltrace/ctf-ir/trace.h>
-#include <babeltrace/graph/notification-event.h>
-#include <babeltrace/graph/notification-discarded-events.h>
-#include <babeltrace/graph/notification-discarded-packets.h>
-#include <babeltrace/graph/clock-class-priority-map.h>
+#include <babeltrace/babeltrace.h>
 #include <babeltrace/bitfield-internal.h>
 #include <babeltrace/common-internal.h>
 #include <babeltrace/compat/time-internal.h>
@@ -191,9 +179,10 @@ void print_timestamp_wall(struct pretty_component *pretty,
                struct tm tm;
                time_t time_s = (time_t) ts_sec_abs;
 
-               if (is_negative) {
+               if (is_negative && !pretty->negative_timestamp_warning_done) {
                        // TODO: log instead
                        fprintf(stderr, "[warning] Fallback to [sec.ns] to print negative time value. Use --clock-seconds.\n");
+                       pretty->negative_timestamp_warning_done = true;
                        goto seconds;
                }
 
@@ -848,11 +837,18 @@ enum bt_component_status print_enum(struct pretty_component *pretty,
                iter = bt_ctf_field_type_enumeration_find_mappings_by_unsigned_value(
                                enumeration_field_type, value);
        }
-       if (!iter) {
-               ret = BT_COMPONENT_STATUS_ERROR;
-               goto end;
-       }
        g_string_append(pretty->string, "( ");
+       ret = bt_ctf_field_type_enumeration_mapping_iterator_next(iter);
+       if (ret) {
+               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;
+       }
        for (;;) {
                const char *mapping_name;
 
@@ -874,15 +870,7 @@ enum bt_component_status print_enum(struct pretty_component *pretty,
                        break;
                }
        }
-       if (!nr_mappings) {
-               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);
-               }
-       }
+skip_loop:
        g_string_append(pretty->string, " : container = ");
        ret = print_integer(pretty, container_field);
        if (ret != BT_COMPONENT_STATUS_OK) {
@@ -1256,7 +1244,9 @@ enum bt_component_status print_variant(struct pretty_component *pretty,
                }
 
                iter = bt_ctf_field_enumeration_get_mappings(tag_field);
-               if (!iter) {
+               iter_ret = bt_ctf_field_type_enumeration_mapping_iterator_next(
+                       iter);
+               if (!iter || ret) {
                        bt_put(tag_field);
                        ret = BT_COMPONENT_STATUS_ERROR;
                        goto end;
@@ -1316,14 +1306,23 @@ enum bt_component_status print_field(struct pretty_component *pretty,
        case CTF_TYPE_ENUM:
                return print_enum(pretty, field);
        case CTF_TYPE_STRING:
+       {
+               const char *str;
+
+               str = bt_ctf_field_string_get_value(field);
+               if (!str) {
+                       return BT_COMPONENT_STATUS_ERROR;
+               }
+
                if (pretty->use_colors) {
                        g_string_append(pretty->string, COLOR_STRING_VALUE);
                }
-               print_escape_string(pretty, bt_ctf_field_string_get_value(field));
+               print_escape_string(pretty, str);
                if (pretty->use_colors) {
                        g_string_append(pretty->string, COLOR_RST);
                }
                return BT_COMPONENT_STATUS_OK;
+       }
        case CTF_TYPE_STRUCT:
                return print_struct(pretty, field, print_names, filter_fields,
                                filter_array_len);
@@ -1565,6 +1564,7 @@ enum bt_component_status pretty_print_discarded_elements(
        int64_t stream_id;
        bool is_discarded_events;
        int64_t count;
+       struct bt_ctf_clock_value *clock_value = NULL;
 
        /* Stream name */
        switch (bt_notification_get_type(notif)) {
@@ -1617,16 +1617,18 @@ enum bt_component_status pretty_print_discarded_elements(
                count, is_discarded_events ? "event" : "packet",
                count == 1 ? "" : "s");
        g_string_assign(pretty->string, "");
-       print_timestamp_wall(pretty,
-               is_discarded_events ?
+       clock_value = is_discarded_events ?
                bt_notification_discarded_events_get_begin_clock_value(notif) :
-               bt_notification_discarded_packets_get_begin_clock_value(notif));
+               bt_notification_discarded_packets_get_begin_clock_value(notif);
+       print_timestamp_wall(pretty, clock_value);
+       BT_PUT(clock_value);
        fprintf(stderr, "%s] and [", pretty->string->str);
        g_string_assign(pretty->string, "");
-       print_timestamp_wall(pretty,
-               is_discarded_events ?
+       clock_value = is_discarded_events ?
                bt_notification_discarded_events_get_end_clock_value(notif) :
-               bt_notification_discarded_packets_get_end_clock_value(notif));
+               bt_notification_discarded_packets_get_end_clock_value(notif);
+       print_timestamp_wall(pretty, clock_value);
+       BT_PUT(clock_value);
        fprintf(stderr, "%s] in trace \"%s\" ",
                pretty->string->str, trace_name);
 
@@ -1666,5 +1668,6 @@ enum bt_component_status pretty_print_discarded_elements(
        bt_put(stream);
        bt_put(stream_class);
        bt_put(trace);
+       bt_put(clock_value);
        return ret;
 }
This page took 0.026957 seconds and 4 git commands to generate.