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)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Fri, 3 May 2019 22:19:33 +0000 (18:19 -0400)
commit3669ec10ad4c06f8148ccd24e9054f39b6eca6fe
treec78e69ea44f6456a688b50ee34f9ec6e546f9600
parent7d15e2ab9409379f75a9afaa003c6f654fdbc6d7
Fix: call bt_stream_class_map_clock_class() in bt_event_create()

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
This page took 0.025017 seconds and 4 git commands to generate.