Fix: sessiond: work-around mismatching variant type tag field and selector names
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Fri, 25 Nov 2022 21:18:42 +0000 (16:18 -0500)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Thu, 8 Dec 2022 14:10:10 +0000 (09:10 -0500)
commit63c3462c3dbd028a08f7a9b504c45e178371248d
tree7e6892bde859c3de1d05ef3fcc9b55e0727798a6
parentdef9854df69838c3625360c725739ba865297187
Fix: sessiond: work-around mismatching variant type tag field and selector names

Observed issue
--------------

Applications fail to register to the session daemon when an application
context is used. The following error is printed by the session daemon:

Error: Failed to handle application context: Invalid variant choice: `none` does not match any mapping in `$app.mayo:ketchup_tag` enumeration [operator()() ust-field-convert.cpp:606]

Cause
-----

Application contexts are expressed as variants. LTTng-UST announces
those by registering an enumeration named `..._tag`. It then registers a
variant as part of the event context that contains the various possible
types.

Unfortunately, the names used in the enumeration and variant don't
match: the enumeration names are all prefixed with an underscore while
the variant type tag fields aren't.

In preparation for adding the support for the CTF 2 format, the session
daemon's handling of user space field class declarations was decoupled
from the generation of TSDL. Trace layouts are now expressed in an
internal intermediate representation that is used to generate TSDL or
CTF 2 independently.

As part of the conversion from liblttng-ust-ctl's communication
structures to the internal IR (see ust-field-convert.cpp), a certain
number of validations steps are taken. One of them ensures that variant
fields match a mapping within its '_tag' enumeration. This step fails
and produces the error message above.

While the CTF 1.8.3 specification mentions that
underscores *should* (not *must*) be removed by CTF readers. Babeltrace
1.x (and possibly others) expect a perfect match between the names used
by tags and variants.

The previous implementation of the TSDL producer always prepended '_' to
identifiers in order to side-step the problem of escaping TSDL keywords
and ensuring identifiers started with an alphabetic character.

This is not the case for enumeration mappings. Hence, I presume that the
underscores were added on the LTTng-UST side to coherce the session
daemon into producing a trace that Babeltrace 1.x would accept.

For reference, using LTTng 2.13 to trace the `$app:hey:you` application
context results in the following declaration in the TSDL metadata:

stream {
id = 0;
event.header := struct event_header_large;
packet.context := struct packet_context;
event.context := struct {
enum : integer { size = 8; align = 8; signed = 1; encoding = none; base = 10; } {
"_none" = 0,
"_int8" = 1,
"_int16" = 2,
"_int32" = 3,
"_int64" = 4,
"_uint8" = 5,
"_uint16" = 6,
"_uint32" = 7,
"_uint64" = 8,
"_float" = 9,
"_double" = 10,
"_string" = 11,
} __app_hey_you_tag;
variant <__app_hey_you_tag> {
struct {} _none;
integer { size = 8; align = 8; signed = 1; encoding = none; base = 10; } _int8;
integer { size = 16; align = 8; signed = 1; encoding = none; base = 10; } _int16;
integer { size = 32; align = 8; signed = 1; encoding = none; base = 10; } _int32;
integer { size = 64; align = 8; signed = 1; encoding = none; base = 10; } _int64;
integer { size = 8; align = 8; signed = 0; encoding = none; base = 10; } _uint8;
integer { size = 16; align = 8; signed = 0; encoding = none; base = 10; } _uint16;
integer { size = 32; align = 8; signed = 0; encoding = none; base = 10; } _uint32;
integer { size = 64; align = 8; signed = 0; encoding = none; base = 10; } _uint64;
floating_point { exp_dig = 8; mant_dig = 24; align = 8; } _float;
floating_point { exp_dig = 11; mant_dig = 53; align = 8; } _double;
string _string;
} __app_hey_you;
};
};

Solution
--------

During the creation of variant field types, the check for matching
variant/tag names is made more permissive if the registering tracer has
an affected ABI major version, which is always true for the moment.

In that mode, the variant fields are renamed to match the mappings in
the tag field when they differ by a leading underscore. For a reader,
this results in the same apparent trace where mappings and variant
fields are prefixed with an underscore.

A change to LTTng-UST removing the underscores from the enumeration
mapping names has been submitted. That fix bumps the
LTTNG_UST_ABI_MAJOR_VERSION to 10. Once/if that fix is accepted, the
check will return to its original strict-ness.

This change ensures that CTF 2 traces don't carry the leading underscore
baggage when tracing applications built against LTTng-UST 2.14+.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: I0e3ad6668baefaea011a878746e041bd17f6373c
src/bin/lttng-sessiond/ust-app.cpp
src/bin/lttng-sessiond/ust-field-convert.cpp
src/bin/lttng-sessiond/ust-field-convert.hpp
This page took 0.025657 seconds and 4 git commands to generate.