Fix: call bt_stream_class_map_clock_class() in bt_event_create()
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Mon, 19 Feb 2018 22:32:52 +0000 (17:32 -0500)
committerPhilippe Proulx <eeppeliteloop@gmail.com>
Thu, 2 May 2019 03:32:03 +0000 (23:32 -0400)
Issue
=====
It is possible, for backward compatibility, to create an event before it
is appended to a CTF writer stream. This means that, when
bt_ctf_writer_create_stream() is called, bt_event_create() is already
called. Because bt_ctf_writer_create_stream() calls
bt_trace_add_stream_class(), which calls
bt_stream_class_map_clock_class() to map selected fields to the stream
class's clock's class, this is skipped in this use case and selected
fields are never mapped.

The problematic sequence is:

1. Create a stream class.
2. Set this stream class's CTF writer clock.
3. Create an event with bt_event_create().
4. Create a CTF writer stream with bt_ctf_writer_create_stream().
5. Append the event (3.) to the CTF writer stream (4.) with
   bt_stream_append_event().

In 5., the event header's `timestamp` field is not automatically
populated from the current value of the stream class's clock because its
field type was not automatically mapped to a clock class.

Solution
========
After validating the field types in bt_event_create(), call
bt_stream_class_map_clock_class() on the validated packet context and
event header field types. bt_stream_class_map_clock_class() only
performs automatic mapping when the stream class has a registered CTF
writer clock, which eventually guarantees that this is a CTF writer
stream class because it is forbidden to call bt_trace_add_stream_class()
with such a stream class when the trace was not created by a CTF writer.

In other words, this additional bt_stream_class_map_clock_class() in
bt_event_create() does NOT affect non-CTF writer objects.

Known drawbacks
===============
None.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
lib/ctf-ir/event.c

index fd4563744e534157131df8d2a727a1dfe0fc2f2e..6438564459c1d80308307d49fc9a0e5a6eeb0f80 100644 (file)
@@ -185,6 +185,19 @@ struct bt_event *bt_event_create(struct bt_event_class *event_class)
                goto error;
        }
 
+       /*
+        * Safe to automatically map selected fields to the stream's
+        * clock's class here because the stream class is about to be
+        * frozen.
+        */
+       if (bt_stream_class_map_clock_class(stream_class,
+                       validation_output.packet_context_type,
+                       validation_output.event_header_type)) {
+               BT_LOGW_STR("Cannot automatically map selected stream class's "
+                       "field types to stream class's clock's class.");
+               goto error;
+       }
+
        /*
         * At this point we know the trace (if associated to the stream
         * class), the stream class, and the event class, with their
This page took 0.025033 seconds and 4 git commands to generate.