#include <common/make-unique.hpp>
#include <unordered_map>
+#include <utility>
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
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 }
{
}
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);
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);
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));
}
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));
}
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)));
}
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)));
}
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()));
}
}
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)));
}
/* 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;
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)));
}
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)));
}
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));
static_cast<const lst::integer_type&>(*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));
}
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)));
}
static_cast<const lst::integer_type&>(*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));
}
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)));
}
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));
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 =
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<lst::field>(std::move(length_field_name),
static_cast<const lst::integer_type&>(*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));
}
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)));
}
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);
static_cast<const lst::integer_type&>(*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));
}
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)));
}
}
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));
}
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
});
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));
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)));
}
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);
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)
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)));
}
}
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 (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<lst::field>(
lookup_field_in_vector(std::vector<lst::field::cuptr>& 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));
}
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;