X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=src%2Fbin%2Flttng-sessiond%2Fust-field-convert.cpp;h=b51ba7bfc2c7e55ea4749b0e2d41807a7a33deed;hb=d512607fc0612c87ba071ccd3d59b98c9d488d6f;hp=0c713c21ba56c85a51c00d17f44ad40cec651bea;hpb=28ab034a2c3582d07d3423d2d746731f87d3969f;p=lttng-tools.git diff --git a/src/bin/lttng-sessiond/ust-field-convert.cpp b/src/bin/lttng-sessiond/ust-field-convert.cpp index 0c713c21b..b51ba7bfc 100644 --- a/src/bin/lttng-sessiond/ust-field-convert.cpp +++ b/src/bin/lttng-sessiond/ust-field-convert.cpp @@ -11,11 +11,21 @@ #include #include +#include namespace lst = lttng::sessiond::trace; namespace lsu = lttng::sessiond::ust; -namespace { +/* + * fmtlib helper that must be under the same namespace as lttng_ust_ctl_abstract_types + * (global). + */ +static int format_as(lttng_ust_ctl_abstract_types type) +{ + return fmt::underlying(type); +} + +namespace { /* * Type enclosing the session information that may be required during the decoding * of the lttng_ust_ctl_field array provided by applications on registration of @@ -29,7 +39,7 @@ public: session_attributes(registry_enum_getter_fn reg_enum_getter, lst::byte_order native_trace_byte_order) : - get_registry_enum{ reg_enum_getter }, + get_registry_enum{ std::move(reg_enum_getter) }, _native_trace_byte_order{ native_trace_byte_order } { } @@ -49,8 +59,8 @@ create_type_from_ust_ctl_fields(const lttng_ust_ctl_field *current, const lttng_ust_ctl_field *end, const session_attributes& session_attributes, const lttng_ust_ctl_field **next_ust_ctl_field, - publish_field_fn publish_field, - lookup_field_fn lookup_field, + const publish_field_fn& publish_field, + const lookup_field_fn& lookup_field, lst::field_location::root lookup_root, lst::field_location::elements& current_field_location_elements, lsu::ctl_field_quirks quirks); @@ -59,8 +69,8 @@ void create_field_from_ust_ctl_fields(const lttng_ust_ctl_field *current, const lttng_ust_ctl_field *end, const session_attributes& session_attributes, const lttng_ust_ctl_field **next_ust_ctl_field, - publish_field_fn publish_field, - lookup_field_fn lookup_field, + const publish_field_fn& publish_field, + const lookup_field_fn& lookup_field, lst::field_location::root lookup_root, lst::field_location::elements& current_field_location_elements, lsu::ctl_field_quirks quirks); @@ -80,7 +90,7 @@ ust_ctl_encoding_to_string_field_encoding(UstCtlEncodingType encoding) const auto encoding_it = encoding_conversion_map.find(encoding); if (encoding_it == encoding_conversion_map.end()) { - LTTNG_THROW_PROTOCOL_ERROR(fmt::format( + LTTNG_THROW_PROTOCOL_ERROR(lttng::format( "Unknown lttng_ust_ctl_string_encodings value `{}` encountered when decoding integer field", encoding)); } @@ -99,7 +109,7 @@ enum lst::integer_type::base ust_ctl_base_to_integer_field_base(UstCtlBaseType b const auto base_it = base_conversion_map.find(base); if (base_it == base_conversion_map.end()) { - LTTNG_THROW_PROTOCOL_ERROR(fmt::format( + LTTNG_THROW_PROTOCOL_ERROR(lttng::format( "Unknown integer base value `{}` encountered when decoding integer field", base)); } @@ -115,7 +125,7 @@ create_integer_type_from_ust_ctl_fields(const lttng_ust_ctl_field *current, lsu::ctl_field_quirks quirks __attribute__((unused))) { if (current >= end) { - LTTNG_THROW_PROTOCOL_ERROR(fmt::format( + LTTNG_THROW_PROTOCOL_ERROR(lttng::format( "End of {} array reached unexpectedly during decoding", typeid(*current))); } @@ -144,7 +154,7 @@ create_floating_point_type_from_ust_ctl_fields(const lttng_ust_ctl_field *curren lsu::ctl_field_quirks quirks __attribute__((unused))) { if (current >= end) { - LTTNG_THROW_PROTOCOL_ERROR(fmt::format( + LTTNG_THROW_PROTOCOL_ERROR(lttng::format( "End of {} array reached unexpectedly during decoding", typeid(*current))); } @@ -161,7 +171,7 @@ create_floating_point_type_from_ust_ctl_fields(const lttng_ust_ctl_field *curren current->type.u._float.exp_dig, current->type.u._float.mant_dig); } catch (lttng::invalid_argument_error& ex) { - LTTNG_THROW_PROTOCOL_ERROR(fmt::format( + LTTNG_THROW_PROTOCOL_ERROR(lttng::format( "Invalid floating point attribute in {}: {}", typeid(*current), ex.what())); } } @@ -174,7 +184,7 @@ create_enumeration_type_from_ust_ctl_fields(const lttng_ust_ctl_field *current, lsu::ctl_field_quirks quirks __attribute__((unused))) { if (current >= end) { - LTTNG_THROW_PROTOCOL_ERROR(fmt::format( + LTTNG_THROW_PROTOCOL_ERROR(lttng::format( "End of {} array reached unexpectedly during decoding", typeid(*current))); } @@ -188,15 +198,15 @@ create_enumeration_type_from_ust_ctl_fields(const lttng_ust_ctl_field *current, /* Nestable enumeration fields are followed by their container type. */ ++current; if (current >= end) { - LTTNG_THROW_PROTOCOL_ERROR(fmt::format( + LTTNG_THROW_PROTOCOL_ERROR(lttng::format( "Array of {} is too short to contain nestable enumeration's container", typeid(*current))); } if (current->type.atype != lttng_ust_ctl_atype_integer) { - LTTNG_THROW_PROTOCOL_ERROR( - fmt::format("Invalid type of nestable enum container: type id = {}", - current->type.atype)); + LTTNG_THROW_PROTOCOL_ERROR(lttng::format( + "Invalid type of nestable enum container: type id = {}", + current->type.atype)); } enum_container_uctl_type = ¤t->type.u.integer; @@ -249,7 +259,7 @@ create_string_type_from_ust_ctl_fields(const lttng_ust_ctl_field *current, lsu::ctl_field_quirks quirks __attribute__((unused))) { if (current >= end) { - LTTNG_THROW_PROTOCOL_ERROR(fmt::format( + LTTNG_THROW_PROTOCOL_ERROR(lttng::format( "End of {} array reached unexpectedly during decoding", typeid(*current))); } @@ -291,7 +301,7 @@ create_array_type_from_ust_ctl_fields(const lttng_ust_ctl_field *current, lsu::ctl_field_quirks quirks __attribute__((unused))) { if (current >= end) { - LTTNG_THROW_PROTOCOL_ERROR(fmt::format( + LTTNG_THROW_PROTOCOL_ERROR(lttng::format( "End of {} array reached unexpectedly during decoding", typeid(*current))); } @@ -305,7 +315,7 @@ create_array_type_from_ust_ctl_fields(const lttng_ust_ctl_field *current, const auto& element_uctl_type = array_uctl_field.type.u.legacy.array.elem_type; if (element_uctl_type.atype != lttng_ust_ctl_atype_integer) { - LTTNG_THROW_PROTOCOL_ERROR(fmt::format( + LTTNG_THROW_PROTOCOL_ERROR(lttng::format( "Unexpected legacy array element type: atype = {}, expected atype = lttng_ust_ctl_atype_integer ({})", element_uctl_type.atype, lttng_ust_ctl_atype_integer)); @@ -327,7 +337,7 @@ create_array_type_from_ust_ctl_fields(const lttng_ust_ctl_field *current, static_cast(*element_type).size; if (integer_element_size != 8) { - LTTNG_THROW_PROTOCOL_ERROR(fmt::format( + LTTNG_THROW_PROTOCOL_ERROR(lttng::format( "Unexpected legacy array element type: integer has encoding but size is not 8: size = {}", integer_element_size)); } @@ -346,14 +356,14 @@ lst::type::cuptr create_array_nestable_type_from_ust_ctl_fields( const lttng_ust_ctl_field *end, const session_attributes& session_attributes, const lttng_ust_ctl_field **next_ust_ctl_field, - publish_field_fn publish_field, - lookup_field_fn lookup_field, + const publish_field_fn& publish_field, + const lookup_field_fn& lookup_field, lst::field_location::root lookup_root, lst::field_location::elements& current_field_location_elements, lsu::ctl_field_quirks quirks) { if (current >= end) { - LTTNG_THROW_PROTOCOL_ERROR(fmt::format( + LTTNG_THROW_PROTOCOL_ERROR(lttng::format( "End of {} array reached unexpectedly during decoding", typeid(*current))); } @@ -390,7 +400,7 @@ lst::type::cuptr create_array_nestable_type_from_ust_ctl_fields( static_cast(*element_type).size; if (integer_element_size != 8) { - LTTNG_THROW_PROTOCOL_ERROR(fmt::format( + LTTNG_THROW_PROTOCOL_ERROR(lttng::format( "Unexpected array element type: integer has encoding but size is not 8: size = {}", integer_element_size)); } @@ -413,13 +423,13 @@ lst::type::cuptr create_sequence_type_from_ust_ctl_fields( const lttng_ust_ctl_field *end, const session_attributes& session_attributes, const lttng_ust_ctl_field **next_ust_ctl_field, - publish_field_fn publish_field, + const publish_field_fn& publish_field, lst::field_location::root lookup_root, lst::field_location::elements& current_field_location_elements, lsu::ctl_field_quirks quirks __attribute__((unused))) { if (current >= end) { - LTTNG_THROW_PROTOCOL_ERROR(fmt::format( + LTTNG_THROW_PROTOCOL_ERROR(lttng::format( "End of {} array reached unexpectedly during decoding", typeid(*current))); } @@ -429,14 +439,14 @@ lst::type::cuptr create_sequence_type_from_ust_ctl_fields( const auto sequence_alignment = 0U; if (element_uctl_type.atype != lttng_ust_ctl_atype_integer) { - LTTNG_THROW_PROTOCOL_ERROR(fmt::format( + LTTNG_THROW_PROTOCOL_ERROR(lttng::format( "Unexpected legacy sequence element type: atype = {}, expected atype = lttng_ust_ctl_atype_integer ({})", element_uctl_type.atype, lttng_ust_ctl_atype_integer)); } if (length_uctl_type.atype != lttng_ust_ctl_atype_integer) { - LTTNG_THROW_PROTOCOL_ERROR(fmt::format( + LTTNG_THROW_PROTOCOL_ERROR(lttng::format( "Unexpected legacy sequence length field type: atype = {}, expected atype = lttng_ust_ctl_atype_integer ({})", length_uctl_type.atype, lttng_ust_ctl_atype_integer)); @@ -450,7 +460,7 @@ lst::type::cuptr create_sequence_type_from_ust_ctl_fields( element_uctl_type.u.basic.integer.encoding); } - const auto length_field_name = fmt::format("_{}_length", sequence_uctl_field.name); + auto length_field_name = lttng::format("_{}_length", sequence_uctl_field.name); auto element_type = create_integer_type_from_ust_ctl_basic_type(element_uctl_type, session_attributes); auto length_type = @@ -460,9 +470,8 @@ lst::type::cuptr create_sequence_type_from_ust_ctl_fields( current_field_location_elements; length_field_location_elements.emplace_back(length_field_name); - const lst::field_location length_field_location{ - lookup_root, std::move(length_field_location_elements) - }; + lst::field_location length_field_location{ lookup_root, + std::move(length_field_location_elements) }; /* Publish an implicit length field _before_ the sequence field. */ publish_field(lttng::make_unique(std::move(length_field_name), @@ -475,7 +484,7 @@ lst::type::cuptr create_sequence_type_from_ust_ctl_fields( static_cast(*element_type).size; if (integer_element_size != 8) { - LTTNG_THROW_PROTOCOL_ERROR(fmt::format( + LTTNG_THROW_PROTOCOL_ERROR(lttng::format( "Unexpected legacy array element type: integer has encoding but size is not 8: size = {}", integer_element_size)); } @@ -494,14 +503,14 @@ lst::type::cuptr create_sequence_nestable_type_from_ust_ctl_fields( const lttng_ust_ctl_field *end, const session_attributes& session_attributes, const lttng_ust_ctl_field **next_ust_ctl_field, - publish_field_fn publish_field, - lookup_field_fn lookup_field, + const publish_field_fn& publish_field, + const lookup_field_fn& lookup_field, lst::field_location::root lookup_root, lst::field_location::elements& current_field_location_elements, lsu::ctl_field_quirks quirks) { if (current >= end) { - LTTNG_THROW_PROTOCOL_ERROR(fmt::format( + LTTNG_THROW_PROTOCOL_ERROR(lttng::format( "End of {} array reached unexpectedly during decoding", typeid(*current))); } @@ -539,11 +548,10 @@ lst::type::cuptr create_sequence_nestable_type_from_ust_ctl_fields( lst::field_location::elements length_field_location_elements = current_field_location_elements; - length_field_location_elements.emplace_back(std::move(length_field_name)); + length_field_location_elements.emplace_back(length_field_name); - const lst::field_location length_field_location{ - lookup_root, std::move(length_field_location_elements) - }; + lst::field_location length_field_location{ lookup_root, + std::move(length_field_location_elements) }; /* Validate existence of length field (throws if not found). */ const auto& length_field = lookup_field(length_field_location); @@ -559,7 +567,7 @@ lst::type::cuptr create_sequence_nestable_type_from_ust_ctl_fields( static_cast(*element_type).size; if (integer_element_size != 8) { - LTTNG_THROW_PROTOCOL_ERROR(fmt::format( + LTTNG_THROW_PROTOCOL_ERROR(lttng::format( "Unexpected array element type: integer has encoding but size is not 8: size = {}", integer_element_size)); } @@ -582,7 +590,7 @@ create_structure_field_from_ust_ctl_fields(const lttng_ust_ctl_field *current, lsu::ctl_field_quirks quirks __attribute__((unused))) { if (current >= end) { - LTTNG_THROW_PROTOCOL_ERROR(fmt::format( + LTTNG_THROW_PROTOCOL_ERROR(lttng::format( "End of {} array reached unexpectedly during decoding", typeid(*current))); } @@ -599,7 +607,7 @@ create_structure_field_from_ust_ctl_fields(const lttng_ust_ctl_field *current, } if (field_count != 0) { - LTTNG_THROW_PROTOCOL_ERROR(fmt::format( + LTTNG_THROW_PROTOCOL_ERROR(lttng::format( "Only empty structures are supported by LTTng-UST: nr_fields = {}", field_count)); } @@ -632,7 +640,7 @@ create_typed_variant_choices(const lttng_ust_ctl_field *current, end, session_attributes, next_ust_ctl_field, - [&choices, typed_enumeration, &selector_field, quirks]( + [&choices, &typed_enumeration, &selector_field, quirks]( lst::field::uptr field) { /* * Find the enumeration mapping that matches the @@ -665,7 +673,7 @@ create_typed_variant_choices(const lttng_ust_ctl_field *current, }); if (mapping_it == typed_enumeration.mappings_->end()) { - LTTNG_THROW_PROTOCOL_ERROR(fmt::format( + LTTNG_THROW_PROTOCOL_ERROR(lttng::format( "Invalid variant choice: `{}` does not match any mapping in `{}` enumeration", field->name, selector_field.name)); @@ -689,13 +697,13 @@ lst::type::cuptr create_variant_field_from_ust_ctl_fields( const lttng_ust_ctl_field *end, const session_attributes& session_attributes, const lttng_ust_ctl_field **next_ust_ctl_field, - lookup_field_fn lookup_field, + const lookup_field_fn& lookup_field, lst::field_location::root lookup_root, lst::field_location::elements& current_field_location_elements, lsu::ctl_field_quirks quirks) { if (current >= end) { - LTTNG_THROW_PROTOCOL_ERROR(fmt::format( + LTTNG_THROW_PROTOCOL_ERROR(lttng::format( "End of {} array reached unexpectedly during decoding", typeid(*current))); } @@ -720,9 +728,8 @@ lst::type::cuptr create_variant_field_from_ust_ctl_fields( current_field_location_elements; selector_field_location_elements.emplace_back(tag_name); - const lst::field_location selector_field_location{ - lookup_root, std::move(selector_field_location_elements) - }; + lst::field_location selector_field_location{ lookup_root, + std::move(selector_field_location_elements) }; /* Validate existence of selector field (throws if not found). */ const auto& selector_field = lookup_field(selector_field_location); @@ -778,8 +785,8 @@ create_type_from_ust_ctl_fields(const lttng_ust_ctl_field *current, const lttng_ust_ctl_field *end, const session_attributes& session_attributes, const lttng_ust_ctl_field **next_ust_ctl_field, - publish_field_fn publish_field, - lookup_field_fn lookup_field, + const publish_field_fn& publish_field, + const lookup_field_fn& lookup_field, lst::field_location::root lookup_root, lst::field_location::elements& current_field_location_elements, lsu::ctl_field_quirks quirks) @@ -848,11 +855,11 @@ create_type_from_ust_ctl_fields(const lttng_ust_ctl_field *current, quirks); default: LTTNG_THROW_PROTOCOL_ERROR( - fmt::format("Unknown {} value `{}` encountered while converting {} to {}", - typeid(current->type.atype), - current->type.atype, - typeid(*current), - typeid(lst::type::cuptr::element_type))); + lttng::format("Unknown {} value `{}` encountered while converting {} to {}", + typeid(current->type.atype), + current->type.atype, + typeid(*current), + typeid(lst::type::cuptr::element_type))); } } @@ -860,8 +867,8 @@ void create_field_from_ust_ctl_fields(const lttng_ust_ctl_field *current, const lttng_ust_ctl_field *end, const session_attributes& session_attributes, const lttng_ust_ctl_field **next_ust_ctl_field, - publish_field_fn publish_field, - lookup_field_fn lookup_field, + const publish_field_fn& publish_field, + const lookup_field_fn& lookup_field, lst::field_location::root lookup_root, lst::field_location::elements& current_field_location_elements, lsu::ctl_field_quirks quirks) @@ -870,7 +877,7 @@ void create_field_from_ust_ctl_fields(const lttng_ust_ctl_field *current, if (lttng_strnlen(current->name, sizeof(current->name)) == sizeof(current->name)) { LTTNG_THROW_PROTOCOL_ERROR( - fmt::format("Name of {} is not null-terminated", typeid(*current))); + lttng::format("Name of {} is not null-terminated", typeid(*current))); } publish_field(lttng::make_unique( @@ -890,7 +897,7 @@ std::vector::iterator lookup_field_in_vector(std::vector& fields, const lst::field_location& location) { if (location.elements_.size() != 1) { - LTTNG_THROW_ERROR(fmt::format( + LTTNG_THROW_ERROR(lttng::format( "Unexpected field location received during field look-up: location = {}", location)); } @@ -909,7 +916,7 @@ lookup_field_in_vector(std::vector& fields, const lst::field_ if (field_it == fields.end()) { LTTNG_THROW_PROTOCOL_ERROR( - fmt::format("Failed to look-up field: location = {}", location)); + lttng::format("Failed to look-up field: location = {}", location)); } return field_it;