X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=blobdiff_plain;f=src%2Fbin%2Flttng-sessiond%2Fust-field-convert.cpp;h=91ab45c1a1396cb5c77b831371a4ed77499cc537;hp=74c41939e3c218a3ce291040d9f49ca253f51cf6;hb=da9dd5212ebacf388ebe26aa80fd0ddcf7ffe049;hpb=45110cdd99bd9ecc13a12d29afde3fffa48b4641 diff --git a/src/bin/lttng-sessiond/ust-field-convert.cpp b/src/bin/lttng-sessiond/ust-field-convert.cpp index 74c41939e..91ab45c1a 100644 --- a/src/bin/lttng-sessiond/ust-field-convert.cpp +++ b/src/bin/lttng-sessiond/ust-field-convert.cpp @@ -594,15 +594,15 @@ typename lst::variant_type::choices create_ty * field's name. */ const auto mapping_it = std::find_if( - typed_enumeration._mappings->begin(), - typed_enumeration._mappings->end(), + typed_enumeration.mappings_->begin(), + typed_enumeration.mappings_->end(), [&field](const typename std::remove_reference< decltype(typed_enumeration)>::type:: mapping& mapping) { return mapping.name == field->name; }); - if (mapping_it == typed_enumeration._mappings->end()) { + if (mapping_it == typed_enumeration.mappings_->end()) { LTTNG_THROW_PROTOCOL_ERROR(fmt::format( "Invalid variant choice: `{}` does not match any mapping in `{}` enumeration", field->name, selector_field.name)); @@ -768,6 +768,35 @@ void create_field_from_ust_ctl_fields(const lttng_ust_ctl_field *current, lookup_root, current_field_location_elements))); } +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( + "Unexpected field location received during field look-up: location = {}", + location)); + } + + /* + * In the context of fields received from LTTng-UST, field + * look-up is extremely naive as the protocol can only + * express empty structures. It is safe to assume that + * location has a depth of 1 and directly refers to a field + * in the 'fields' vector. + */ + const auto field_it = std::find_if(fields.begin(), fields.end(), + [location](lst::field::cuptr &field) { + return field->name == location.elements_[0]; + }); + + if (field_it == fields.end()) { + LTTNG_THROW_PROTOCOL_ERROR( + fmt::format("Failed to look-up field: location = {}", location)); + } + + return field_it; +} + /* * `lttng_ust_ctl_field`s can be nested, in which case creating a field will consume * more than one lttng_ust_ctl_field. create_field_from_ust_ctl_fields returns the @@ -812,34 +841,8 @@ std::vector create_fields_from_ust_ctl_fields( }, [&fields](const lst::field_location& location) -> lookup_field_fn::result_type { - if (location.elements_.size() != 1) { - LTTNG_THROW_ERROR(fmt::format( - "Unexpected field location received during field look-up: location = {}", - location)); - } - - /* - * In the context of fields received from LTTng-UST, field - * look-up is extremely naive as the protocol can only - * express empty structures. It is safe to assume that - * location has a depth of 1 and directly refers to a field - * in the 'fields' vector. - */ - const auto field_it = std::find_if(fields.begin(), - fields.end(), - [&location](decltype(fields)::value_type& - field) { - return field->name == - location.elements_[0]; - }); - - if (field_it == fields.end()) { - LTTNG_THROW_PROTOCOL_ERROR(fmt::format( - "Failed to look-up field: location = {}", - location)); - } - - return **field_it; + /* Resolve location to a previously-constructed field. */ + return **lookup_field_in_vector(fields, location); }, lookup_root, current_field_location_elements);