Fix: sessiond: tsdl: don't prepend underscore for stream_id
[lttng-tools.git] / src / bin / lttng-sessiond / tsdl-trace-class-visitor.cpp
index 733c05a457701b51cc96834c2475d4f10e324e53..b7777d203d2a5f2c0f3d654c4eaa871c4df7af7f 100644 (file)
@@ -14,8 +14,9 @@
 #include <common/uuid.hpp>
 
 #include <array>
-#include <queue>
 #include <locale>
+#include <queue>
+#include <set>
 
 namespace lst = lttng::sessiond::trace;
 namespace tsdl = lttng::sessiond::tsdl;
@@ -24,6 +25,12 @@ namespace {
 const auto ctf_spec_major = 1;
 const auto ctf_spec_minor = 8;
 
+/*
+ * Although the CTF v1.8 specification recommends ignoring any leading underscore, Some readers,
+ * such as Babeltrace 1.x, expect special identifiers without a prepended underscore.
+ */
+const std::set<std::string> safe_tsdl_identifiers = {"stream_id"};
+
 /*
  * A previous implementation always prepended '_' to the identifiers in order to
  * side-step the problem of escaping TSDL keywords and ensuring identifiers
@@ -38,6 +45,10 @@ std::string escape_tsdl_identifier(const std::string& original_identifier)
                LTTNG_THROW_ERROR("Invalid 0-length identifier used in trace description");
        }
 
+       if (safe_tsdl_identifiers.find(original_identifier) != safe_tsdl_identifiers.end()) {
+               return original_identifier;
+       }
+
        std::string new_identifier;
        /* Optimisticly assume most identifiers are valid and allocate the same length. */
        new_identifier.reserve(original_identifier.size());
@@ -134,15 +145,15 @@ private:
                                fmt::arg("alignment", type.alignment));
 
                /* Defaults to unsigned. */
-               if (type.signedness == lst::integer_type::signedness::SIGNED) {
+               if (type.signedness_ == lst::integer_type::signedness::SIGNED) {
                        _description += " signed = true;";
                }
 
                /* Defaults to 10. */
-               if (type.base != lst::integer_type::base::DECIMAL) {
+               if (type.base_ != lst::integer_type::base::DECIMAL) {
                        unsigned int base;
 
-                       switch (type.base) {
+                       switch (type.base_) {
                        case lst::integer_type::base::BINARY:
                                base = 2;
                                break;
@@ -155,7 +166,7 @@ private:
                        default:
                                LTTNG_THROW_ERROR(fmt::format(
                                                "Unexpected base encountered while serializing integer type to TSDL: base = {}",
-                                               (int) type.base));
+                                               (int) type.base_));
                        }
 
                        _description += fmt::format(" base = {};", base);
@@ -300,10 +311,34 @@ private:
                                "[{}]", escape_tsdl_identifier(type.length_field_name)));
        }
 
+       virtual void visit(const lst::static_length_blob_type& type) override final
+       {
+               /* This type doesn't exist in CTF 1.x, express it as a static length array of uint8_t. */
+               std::unique_ptr<const lst::type> uint8_element = lttng::make_unique<lst::integer_type>(8,
+                               _trace_abi.byte_order, 8, lst::integer_type::signedness::UNSIGNED,
+                               lst::integer_type::base::HEXADECIMAL);
+               const auto array = lttng::make_unique<lst::static_length_array_type>(
+                               type.alignment, std::move(uint8_element), type.length_bytes);
+
+               visit(*array);
+       }
+
+       virtual void visit(const lst::dynamic_length_blob_type& type) override final
+       {
+               /* This type doesn't exist in CTF 1.x, express it as a dynamic length array of uint8_t. */
+               std::unique_ptr<const lst::type> uint8_element = lttng::make_unique<lst::integer_type>(0,
+                               _trace_abi.byte_order, 8, lst::integer_type::signedness::UNSIGNED,
+                               lst::integer_type::base::HEXADECIMAL);
+               const auto array = lttng::make_unique<lst::dynamic_length_array_type>(
+                               type.alignment, std::move(uint8_element), type.length_field_name);
+
+               visit(*array);
+       }
+
        virtual void visit(const lst::null_terminated_string_type& type) override final
        {
                /* Defaults to UTF-8.  */
-               if (type.encoding == lst::null_terminated_string_type::encoding::ASCII) {
+               if (type.encoding_ == lst::null_terminated_string_type::encoding::ASCII) {
                        _description += "string { encoding = ASCII }";
                } else {
                        _description += "string";
@@ -376,7 +411,7 @@ private:
                 * an encoding specified.
                 */
                const auto char_array = lttng::make_unique<lst::static_length_array_type>(
-                               type.alignment, create_character_type(type.encoding), type.length);
+                               type.alignment, create_character_type(type.encoding_), type.length);
 
                visit(*char_array);
        }
@@ -388,7 +423,7 @@ private:
                 * an encoding specified.
                 */
                const auto char_sequence = lttng::make_unique<lst::dynamic_length_array_type>(
-                               type.alignment, create_character_type(type.encoding),
+                               type.alignment, create_character_type(type.encoding_),
                                type.length_field_name);
 
                visit(*char_sequence);
@@ -556,7 +591,7 @@ void tsdl::trace_class_visitor::visit(const lttng::sessiond::trace::stream_class
                                            "   event.header := {header_type};\n"
                                            "   packet.context := struct packet_context;\n",
                        fmt::arg("id", stream_class.id),
-                       fmt::arg("header_type", stream_class.header_type == lst::stream_class::header_type::COMPACT ?
+                       fmt::arg("header_type", stream_class.header_type_ == lst::stream_class::header_type::COMPACT ?
                                                        "struct event_header_compact" :
                                                              "struct event_header_large"));
 
This page took 0.025395 seconds and 4 git commands to generate.