Fix: uninitialized variable may be used warning
[babeltrace.git] / plugins / ctf / common / metadata / visitor-generate-ir.c
index b4a084df898a2ea0380fdee963e058a7fdc4272d..734ed996840b144b9f9844eebe1169ae8662bbe4 100644 (file)
 #include <errno.h>
 #include <babeltrace/compat/uuid-internal.h>
 #include <babeltrace/endian-internal.h>
-#include <babeltrace/ref.h>
-#include <babeltrace/ctf-ir/trace.h>
-#include <babeltrace/ctf-ir/stream-class.h>
-#include <babeltrace/ctf-ir/event.h>
-#include <babeltrace/ctf-ir/event-class.h>
-#include <babeltrace/ctf-ir/field-types.h>
+#include <babeltrace/babeltrace.h>
 #include <babeltrace/ctf-ir/field-types-internal.h>
-#include <babeltrace/ctf-ir/clock-class.h>
 
 #include "scanner.h"
 #include "parser.h"
 #include "ast.h"
+#include "decoder.h"
 
 /* Bit value (left shift) */
 #define _BV(_val)              (1 << (_val))
@@ -151,13 +146,21 @@ enum loglevel {
 #define _BT_LIST_FIRST_ENTRY(_ptr, _type, _member)     \
        bt_list_entry((_ptr)->next, _type, _member)
 
-#define _BT_CTF_FIELD_TYPE_INIT(_name) struct bt_ctf_field_type *_name = NULL;
+#define _BT_FIELD_TYPE_INIT(_name)     struct bt_field_type *_name = NULL;
 
-#define _BT_LOGE_DUP_ATTR(_attr, _entity)                              \
-       do {                                                            \
-               BT_LOGE("Duplicate attribute in %s: attr-name=\"%s\"",  \
-                       _entity, _attr);                                \
-       } while (0)
+#define _BT_LOGE_DUP_ATTR(_node, _attr, _entity)                       \
+       _BT_LOGE_LINENO((_node)->lineno,                                \
+               "Duplicate attribute in %s: attr-name=\"%s\"",          \
+               _entity, _attr)
+
+#define _BT_LOGE_NODE(_node, _msg, args...)                            \
+       _BT_LOGE_LINENO((_node)->lineno, _msg, ## args)
+
+#define _BT_LOGW_NODE(_node, _msg, args...)                            \
+       _BT_LOGW_LINENO((_node)->lineno, _msg, ## args)
+
+#define _BT_LOGV_NODE(_node, _msg, args...)                            \
+       _BT_LOGV_LINENO((_node)->lineno, _msg, ## args)
 
 /*
  * Declaration scope of a visitor context. This represents a TSDL
@@ -168,7 +171,7 @@ struct ctx_decl_scope {
        /*
         * Alias name to field type.
         *
-        * GQuark -> struct bt_ctf_field_type *
+        * GQuark -> struct bt_field_type *
         */
        GHashTable *decl_map;
 
@@ -181,7 +184,7 @@ struct ctx_decl_scope {
  */
 struct ctx {
        /* Trace being filled (owned by this) */
-       struct bt_ctf_trace *trace;
+       struct bt_trace *trace;
 
        /* Current declaration scope (top of the stack) */
        struct ctx_decl_scope *current_scope;
@@ -192,14 +195,11 @@ struct ctx {
        /* 1 if this is an LTTng trace */
        bool is_lttng;
 
-       /* Offset (ns) to apply to clock classes on creation */
-       int64_t clock_class_offset_ns;
-
        /* Eventual name suffix of the trace to set */
        char *trace_name_suffix;
 
        /* Trace attributes */
-       enum bt_ctf_byte_order trace_bo;
+       enum bt_byte_order trace_bo;
        uint64_t trace_major;
        uint64_t trace_minor;
        unsigned char trace_uuid[BABELTRACE_UUID_LEN];
@@ -207,9 +207,12 @@ struct ctx {
        /*
         * Stream IDs to stream classes.
         *
-        * int64_t -> struct bt_ctf_stream_class *
+        * int64_t -> struct bt_stream_class *
         */
        GHashTable *stream_classes;
+
+       /* Config passed by the user */
+       struct ctf_metadata_decoder_config decoder_config;
 };
 
 /*
@@ -217,37 +220,6 @@ struct ctx {
  */
 struct ctf_visitor_generate_ir { };
 
-static
-const char *loglevel_str [] = {
-       [ LOGLEVEL_EMERG ] = "TRACE_EMERG",
-       [ LOGLEVEL_ALERT ] = "TRACE_ALERT",
-       [ LOGLEVEL_CRIT ] = "TRACE_CRIT",
-       [ LOGLEVEL_ERR ] = "TRACE_ERR",
-       [ LOGLEVEL_WARNING ] = "TRACE_WARNING",
-       [ LOGLEVEL_NOTICE ] = "TRACE_NOTICE",
-       [ LOGLEVEL_INFO ] = "TRACE_INFO",
-       [ LOGLEVEL_DEBUG_SYSTEM ] = "TRACE_DEBUG_SYSTEM",
-       [ LOGLEVEL_DEBUG_PROGRAM ] = "TRACE_DEBUG_PROGRAM",
-       [ LOGLEVEL_DEBUG_PROCESS ] = "TRACE_DEBUG_PROCESS",
-       [ LOGLEVEL_DEBUG_MODULE ] = "TRACE_DEBUG_MODULE",
-       [ LOGLEVEL_DEBUG_UNIT ] = "TRACE_DEBUG_UNIT",
-       [ LOGLEVEL_DEBUG_FUNCTION ] = "TRACE_DEBUG_FUNCTION",
-       [ LOGLEVEL_DEBUG_LINE ] = "TRACE_DEBUG_LINE",
-       [ LOGLEVEL_DEBUG ] = "TRACE_DEBUG",
-};
-
-static
-const char *print_loglevel(int64_t value)
-{
-       if (value < 0) {
-               return NULL;
-       }
-       if (value >= _NR_LOGLEVELS) {
-               return "<<UNKNOWN>>";
-       }
-       return loglevel_str[value];
-}
-
 /**
  * Creates a new declaration scope.
  *
@@ -261,11 +233,12 @@ struct ctx_decl_scope *ctx_decl_scope_create(struct ctx_decl_scope *par_scope)
 
        scope = g_new(struct ctx_decl_scope, 1);
        if (!scope) {
+               BT_LOGE_STR("Failed to allocate one declaration scope.");
                goto end;
        }
 
        scope->decl_map = g_hash_table_new_full(g_direct_hash, g_direct_equal,
-               NULL, (GDestroyNotify) bt_ctf_field_type_put);
+               NULL, (GDestroyNotify) bt_put);
        scope->parent_scope = par_scope;
 
 end:
@@ -310,6 +283,7 @@ GQuark get_prefixed_named_quark(char prefix, const char *name)
        /* Prefix character + original string + '\0' */
        char *prname = g_new(char, strlen(name) + 2);
        if (!prname) {
+               BT_LOGE_STR("Failed to allocate a string.");
                goto end;
        }
 
@@ -331,13 +305,13 @@ end:
  * @returns            Declaration, or NULL if not found
  */
 static
-struct bt_ctf_field_type *ctx_decl_scope_lookup_prefix_alias(
+struct bt_field_type *ctx_decl_scope_lookup_prefix_alias(
        struct ctx_decl_scope *scope, char prefix,
        const char *name, int levels)
 {
        GQuark qname = 0;
        int cur_levels = 0;
-       _BT_CTF_FIELD_TYPE_INIT(decl);
+       _BT_FIELD_TYPE_INIT(decl);
        struct ctx_decl_scope *cur_scope = scope;
 
        assert(scope);
@@ -379,7 +353,7 @@ error:
  * @returns            Declaration, or NULL if not found
  */
 static
-struct bt_ctf_field_type *ctx_decl_scope_lookup_alias(
+struct bt_field_type *ctx_decl_scope_lookup_alias(
        struct ctx_decl_scope *scope, const char *name, int levels)
 {
        return ctx_decl_scope_lookup_prefix_alias(scope, _PREFIX_ALIAS,
@@ -395,7 +369,7 @@ struct bt_ctf_field_type *ctx_decl_scope_lookup_alias(
  * @returns            Declaration, or NULL if not found
  */
 static
-struct bt_ctf_field_type *ctx_decl_scope_lookup_enum(
+struct bt_field_type *ctx_decl_scope_lookup_enum(
        struct ctx_decl_scope *scope, const char *name, int levels)
 {
        return ctx_decl_scope_lookup_prefix_alias(scope, _PREFIX_ENUM,
@@ -411,7 +385,7 @@ struct bt_ctf_field_type *ctx_decl_scope_lookup_enum(
  * @returns            Declaration, or NULL if not found
  */
 static
-struct bt_ctf_field_type *ctx_decl_scope_lookup_struct(
+struct bt_field_type *ctx_decl_scope_lookup_struct(
        struct ctx_decl_scope *scope, const char *name, int levels)
 {
        return ctx_decl_scope_lookup_prefix_alias(scope, _PREFIX_STRUCT,
@@ -427,7 +401,7 @@ struct bt_ctf_field_type *ctx_decl_scope_lookup_struct(
  * @returns            Declaration, or NULL if not found
  */
 static
-struct bt_ctf_field_type *ctx_decl_scope_lookup_variant(
+struct bt_field_type *ctx_decl_scope_lookup_variant(
        struct ctx_decl_scope *scope, const char *name, int levels)
 {
        return ctx_decl_scope_lookup_prefix_alias(scope, _PREFIX_VARIANT,
@@ -445,11 +419,11 @@ struct bt_ctf_field_type *ctx_decl_scope_lookup_variant(
  */
 static
 int ctx_decl_scope_register_prefix_alias(struct ctx_decl_scope *scope,
-       char prefix, const char *name, struct bt_ctf_field_type *decl)
+       char prefix, const char *name, struct bt_field_type *decl)
 {
        int ret = 0;
        GQuark qname = 0;
-       _BT_CTF_FIELD_TYPE_INIT(edecl);
+       _BT_FIELD_TYPE_INIT(edecl);
 
        assert(scope);
        assert(name);
@@ -490,7 +464,7 @@ error:
  */
 static
 int ctx_decl_scope_register_alias(struct ctx_decl_scope *scope,
-       const char *name, struct bt_ctf_field_type *decl)
+       const char *name, struct bt_field_type *decl)
 {
        return ctx_decl_scope_register_prefix_alias(scope, _PREFIX_ALIAS,
                name, decl);
@@ -506,7 +480,7 @@ int ctx_decl_scope_register_alias(struct ctx_decl_scope *scope,
  */
 static
 int ctx_decl_scope_register_enum(struct ctx_decl_scope *scope,
-       const char *name, struct bt_ctf_field_type *decl)
+       const char *name, struct bt_field_type *decl)
 {
        return ctx_decl_scope_register_prefix_alias(scope, _PREFIX_ENUM,
                name, decl);
@@ -522,7 +496,7 @@ int ctx_decl_scope_register_enum(struct ctx_decl_scope *scope,
  */
 static
 int ctx_decl_scope_register_struct(struct ctx_decl_scope *scope,
-       const char *name, struct bt_ctf_field_type *decl)
+       const char *name, struct bt_field_type *decl)
 {
        return ctx_decl_scope_register_prefix_alias(scope, _PREFIX_STRUCT,
                name, decl);
@@ -538,7 +512,7 @@ int ctx_decl_scope_register_struct(struct ctx_decl_scope *scope,
  */
 static
 int ctx_decl_scope_register_variant(struct ctx_decl_scope *scope,
-       const char *name, struct bt_ctf_field_type *decl)
+       const char *name, struct bt_field_type *decl)
 {
        return ctx_decl_scope_register_prefix_alias(scope, _PREFIX_VARIANT,
                name, decl);
@@ -590,32 +564,39 @@ end:
  * @returns    New visitor context, or NULL on error
  */
 static
-struct ctx *ctx_create(struct bt_ctf_trace *trace,
-               int64_t clock_class_offset_ns, const char *trace_name_suffix)
+struct ctx *ctx_create(struct bt_trace *trace,
+               const struct ctf_metadata_decoder_config *decoder_config,
+               const char *trace_name_suffix)
 {
        struct ctx *ctx = NULL;
        struct ctx_decl_scope *scope = NULL;
 
+       assert(decoder_config);
+
        ctx = g_new0(struct ctx, 1);
        if (!ctx) {
+               BT_LOGE_STR("Failed to allocate one visitor context.");
                goto error;
        }
 
        /* Root declaration scope */
        scope = ctx_decl_scope_create(NULL);
        if (!scope) {
+               BT_LOGE_STR("Cannot create declaration scope.");
                goto error;
        }
 
-       ctx->stream_classes = g_hash_table_new_full(g_direct_hash,
-               g_direct_equal, NULL, (GDestroyNotify) bt_put);
+       ctx->stream_classes = g_hash_table_new_full(g_int64_hash,
+               g_int64_equal, g_free, (GDestroyNotify) bt_put);
        if (!ctx->stream_classes) {
+               BT_LOGE_STR("Failed to allocate a GHashTable.");
                goto error;
        }
 
        if (trace_name_suffix) {
                ctx->trace_name_suffix = strdup(trace_name_suffix);
                if (!ctx->trace_name_suffix) {
+                       BT_LOGE_STR("Failed to copy string.");
                        goto error;
                }
        }
@@ -623,8 +604,8 @@ struct ctx *ctx_create(struct bt_ctf_trace *trace,
        ctx->trace = trace;
        ctx->current_scope = scope;
        scope = NULL;
-       ctx->trace_bo = BT_CTF_BYTE_ORDER_NATIVE;
-       ctx->clock_class_offset_ns = clock_class_offset_ns;
+       ctx->trace_bo = BT_BYTE_ORDER_NATIVE;
+       ctx->decoder_config = *decoder_config;
        return ctx;
 
 error:
@@ -649,6 +630,7 @@ int ctx_push_scope(struct ctx *ctx)
        assert(ctx);
        new_scope = ctx_decl_scope_create(ctx->current_scope);
        if (!new_scope) {
+               BT_LOGE_STR("Cannot create declaration scope.");
                ret = -ENOMEM;
                goto end;
        }
@@ -680,7 +662,62 @@ end:
 
 static
 int visit_type_specifier_list(struct ctx *ctx, struct ctf_node *ts_list,
-       struct bt_ctf_field_type **decl);
+       struct bt_field_type **decl);
+
+static
+char *remove_underscores_from_field_ref(const char *field_ref)
+{
+       const char *in_ch;
+       char *out_ch;
+       char *ret;
+       enum {
+               UNDERSCORE_REMOVE_STATE_REMOVE_NEXT_UNDERSCORE,
+               UNDERSCORE_REMOVE_STATE_DO_NOT_REMOVE_NEXT_UNDERSCORE,
+       } state = UNDERSCORE_REMOVE_STATE_REMOVE_NEXT_UNDERSCORE;
+
+       assert(field_ref);
+       ret = calloc(strlen(field_ref) + 1, 1);
+       if (!ret) {
+               BT_LOGE("Failed to allocate a string: size=%zu",
+                       strlen(field_ref) + 1);
+               goto end;
+       }
+
+       in_ch = field_ref;
+       out_ch = ret;
+
+       while (*in_ch != '\0') {
+               switch (*in_ch) {
+               case ' ':
+               case '\t':
+                       /* Remove whitespace */
+                       in_ch++;
+                       continue;
+               case '_':
+                       if (state == UNDERSCORE_REMOVE_STATE_REMOVE_NEXT_UNDERSCORE) {
+                               in_ch++;
+                               state = UNDERSCORE_REMOVE_STATE_DO_NOT_REMOVE_NEXT_UNDERSCORE;
+                               continue;
+                       }
+
+                       goto copy;
+               case '.':
+                       state = UNDERSCORE_REMOVE_STATE_REMOVE_NEXT_UNDERSCORE;
+                       goto copy;
+               default:
+                       state = UNDERSCORE_REMOVE_STATE_DO_NOT_REMOVE_NEXT_UNDERSCORE;
+                       goto copy;
+               }
+
+copy:
+               *out_ch = *in_ch;
+               in_ch++;
+               out_ch++;
+       }
+
+end:
+       return ret;
+}
 
 static
 int is_unary_string(struct bt_list_head *head)
@@ -851,6 +888,7 @@ int get_unary_unsigned(struct bt_list_head *head, uint64_t *value)
                        uexpr_type != UNARY_UNSIGNED_CONSTANT ||
                        uexpr_link != UNARY_LINK_UNKNOWN || i != 0;
                if (cond) {
+                       _BT_LOGE_NODE(node, "Invalid constant unsigned integer.");
                        ret = -EINVAL;
                        goto end;
                }
@@ -893,7 +931,6 @@ int get_unary_signed(struct bt_list_head *head, int64_t *value)
                int uexpr_type = node->u.unary_expression.type;
                int uexpr_link = node->u.unary_expression.link;
                int cond = node->type != NODE_UNARY_EXPRESSION ||
-                       (uexpr_type != UNARY_UNSIGNED_CONSTANT) ||
                        (uexpr_type != UNARY_UNSIGNED_CONSTANT &&
                                uexpr_type != UNARY_SIGNED_CONSTANT) ||
                        uexpr_link != UNARY_LINK_UNKNOWN || i != 0;
@@ -902,7 +939,7 @@ int get_unary_signed(struct bt_list_head *head, int64_t *value)
                        goto end;
                }
 
-               switch (node->u.unary_expression.type) {
+               switch (uexpr_type) {
                case UNARY_UNSIGNED_CONSTANT:
                        *value = (int64_t)
                                node->u.unary_expression.u.unsigned_constant;
@@ -945,6 +982,8 @@ int get_unary_uuid(struct bt_list_head *head, unsigned char *uuid)
                src_string = node->u.unary_expression.u.string;
                ret = bt_uuid_parse(src_string, uuid);
                if (ret) {
+                       _BT_LOGE_NODE(node,
+                               "Cannot parse UUID: uuid=\"%s\"", src_string);
                        goto end;
                }
        }
@@ -959,7 +998,8 @@ int get_boolean(struct ctf_node *unary_expr)
        int ret = 0;
 
        if (unary_expr->type != NODE_UNARY_EXPRESSION) {
-               BT_LOGE("Expecting unary expression: node-type=%d",
+               _BT_LOGE_NODE(unary_expr,
+                       "Expecting unary expression: node-type=%d",
                        unary_expr->type);
                ret = -EINVAL;
                goto end;
@@ -981,14 +1021,16 @@ int get_boolean(struct ctf_node *unary_expr)
                } else if (!strcmp(str, "false") || !strcmp(str, "FALSE")) {
                        ret = FALSE;
                } else {
-                       BT_LOGE("Unexpected boolean value: value=\"%s\"", str);
+                       _BT_LOGE_NODE(unary_expr,
+                               "Unexpected boolean value: value=\"%s\"", str);
                        ret = -EINVAL;
                        goto end;
                }
                break;
        }
        default:
-               BT_LOGE("Unexpected unary expression type: node-type=%d",
+               _BT_LOGE_NODE(unary_expr,
+                       "Unexpected unary expression type: node-type=%d",
                        unary_expr->u.unary_expression.type);
                ret = -EINVAL;
                goto end;
@@ -999,26 +1041,28 @@ end:
 }
 
 static
-enum bt_ctf_byte_order byte_order_from_unary_expr(struct ctf_node *unary_expr)
+enum bt_byte_order byte_order_from_unary_expr(struct ctf_node *unary_expr)
 {
        const char *str;
-       enum bt_ctf_byte_order bo = BT_CTF_BYTE_ORDER_UNKNOWN;
+       enum bt_byte_order bo = BT_BYTE_ORDER_UNKNOWN;
 
        if (unary_expr->u.unary_expression.type != UNARY_STRING) {
-               BT_LOGE_STR("\"byte_order\" attribute: expecting `be`, `le`, `network`, or `native`.");
+               _BT_LOGE_NODE(unary_expr,
+                       "\"byte_order\" attribute: expecting `be`, `le`, `network`, or `native`.");
                goto end;
        }
 
        str = unary_expr->u.unary_expression.u.string;
 
        if (!strcmp(str, "be") || !strcmp(str, "network")) {
-               bo = BT_CTF_BYTE_ORDER_BIG_ENDIAN;
+               bo = BT_BYTE_ORDER_BIG_ENDIAN;
        } else if (!strcmp(str, "le")) {
-               bo = BT_CTF_BYTE_ORDER_LITTLE_ENDIAN;
+               bo = BT_BYTE_ORDER_LITTLE_ENDIAN;
        } else if (!strcmp(str, "native")) {
-               bo = BT_CTF_BYTE_ORDER_NATIVE;
+               bo = BT_BYTE_ORDER_NATIVE;
        } else {
-               BT_LOGE("Unexpected \"byte_order\" attribute value: "
+               _BT_LOGE_NODE(unary_expr,
+                       "Unexpected \"byte_order\" attribute value: "
                        "expecting `be`, `le`, `network`, or `native`: value=\"%s\"",
                        str);
                goto end;
@@ -1029,13 +1073,13 @@ end:
 }
 
 static
-enum bt_ctf_byte_order get_real_byte_order(struct ctx *ctx,
+enum bt_byte_order get_real_byte_order(struct ctx *ctx,
        struct ctf_node *uexpr)
 {
-       enum bt_ctf_byte_order bo = byte_order_from_unary_expr(uexpr);
+       enum bt_byte_order bo = byte_order_from_unary_expr(uexpr);
 
-       if (bo == BT_CTF_BYTE_ORDER_NATIVE) {
-               bo = bt_ctf_trace_get_native_byte_order(ctx->trace);
+       if (bo == BT_BYTE_ORDER_NATIVE) {
+               bo = bt_trace_get_native_byte_order(ctx->trace);
        }
 
        return bo;
@@ -1044,7 +1088,7 @@ enum bt_ctf_byte_order get_real_byte_order(struct ctx *ctx,
 static
 int is_align_valid(uint64_t align)
 {
-       return (align != 0) && !(align & (align - 1));
+       return (align != 0) && !(align & (align - 1ULL));
 }
 
 static
@@ -1054,6 +1098,9 @@ int get_type_specifier_name(struct ctx *ctx, struct ctf_node *type_specifier,
        int ret = 0;
 
        if (type_specifier->type != NODE_TYPE_SPECIFIER) {
+               _BT_LOGE_NODE(type_specifier,
+                       "Unexpected node type: node-type=%d",
+                       type_specifier->type);
                ret = -EINVAL;
                goto end;
        }
@@ -1109,7 +1156,7 @@ int get_type_specifier_name(struct ctx *ctx, struct ctf_node *type_specifier,
                struct ctf_node *node = type_specifier->u.type_specifier.node;
 
                if (!node->u._struct.name) {
-                       BT_LOGE_STR("Unexpected empty structure name.");
+                       _BT_LOGE_NODE(node, "Unexpected empty structure field type name.");
                        ret = -EINVAL;
                        goto end;
                }
@@ -1123,7 +1170,7 @@ int get_type_specifier_name(struct ctx *ctx, struct ctf_node *type_specifier,
                struct ctf_node *node = type_specifier->u.type_specifier.node;
 
                if (!node->u.variant.name) {
-                       BT_LOGE_STR("Unexpected empty variant name.");
+                       _BT_LOGE_NODE(node, "Unexpected empty variant field type name.");
                        ret = -EINVAL;
                        goto end;
                }
@@ -1137,7 +1184,8 @@ int get_type_specifier_name(struct ctx *ctx, struct ctf_node *type_specifier,
                struct ctf_node *node = type_specifier->u.type_specifier.node;
 
                if (!node->u._enum.enum_id) {
-                       BT_LOGE_STR("Unexpected empty enumeration field type (`enum`) name.");
+                       _BT_LOGE_NODE(node,
+                               "Unexpected empty enumeration field type (`enum`) name.");
                        ret = -EINVAL;
                        goto end;
                }
@@ -1150,7 +1198,8 @@ int get_type_specifier_name(struct ctx *ctx, struct ctf_node *type_specifier,
        case TYPESPEC_INTEGER:
        case TYPESPEC_STRING:
        default:
-               BT_LOGE("Unexpected type specifier type: %d",
+               _BT_LOGE_NODE(type_specifier->u.type_specifier.node,
+                       "Unexpected type specifier type: %d",
                        type_specifier->u.type_specifier.type);
                ret = -EINVAL;
                goto end;
@@ -1225,8 +1274,8 @@ end:
 static
 int visit_type_declarator(struct ctx *ctx, struct ctf_node *type_specifier_list,
        GQuark *field_name, struct ctf_node *node_type_declarator,
-       struct bt_ctf_field_type **field_decl,
-       struct bt_ctf_field_type *nested_decl)
+       struct bt_field_type **field_decl,
+       struct bt_field_type *nested_decl)
 {
        /*
         * During this whole function, nested_decl is always OURS,
@@ -1241,7 +1290,8 @@ int visit_type_declarator(struct ctx *ctx, struct ctf_node *type_specifier_list,
        if (node_type_declarator) {
                if (node_type_declarator->u.type_declarator.type ==
                                TYPEDEC_UNKNOWN) {
-                       BT_LOGE("Unexpected type declarator type: type=%d",
+                       _BT_LOGE_NODE(node_type_declarator,
+                               "Unexpected type declarator type: type=%d",
                                node_type_declarator->u.type_declarator.type);
                        ret = -EINVAL;
                        goto error;
@@ -1250,7 +1300,8 @@ int visit_type_declarator(struct ctx *ctx, struct ctf_node *type_specifier_list,
                /* TODO: GCC bitfields not supported yet */
                if (node_type_declarator->u.type_declarator.bitfield_len !=
                                NULL) {
-                       BT_LOGE_STR("GCC bitfields are not supported as of this version.");
+                       _BT_LOGE_NODE(node_type_declarator,
+                               "GCC bitfields are not supported as of this version.");
                        ret = -EPERM;
                        goto error;
                }
@@ -1263,7 +1314,7 @@ int visit_type_declarator(struct ctx *ctx, struct ctf_node *type_specifier_list,
 
                if (node_type_declarator && !bt_list_empty(pointers)) {
                        GQuark qalias;
-                       _BT_CTF_FIELD_TYPE_INIT(nested_decl_copy);
+                       _BT_FIELD_TYPE_INIT(nested_decl_copy);
 
                        /*
                         * If we have a pointer declarator, it HAS to
@@ -1275,17 +1326,19 @@ int visit_type_declarator(struct ctx *ctx, struct ctf_node *type_specifier_list,
                                ctx_decl_scope_lookup_alias(ctx->current_scope,
                                        g_quark_to_string(qalias), -1);
                        if (!nested_decl) {
-                               BT_LOGE("Cannot find type alias: name=\"%s\"",
+                               _BT_LOGE_NODE(node_type_declarator,
+                                       "Cannot find type alias: name=\"%s\"",
                                        g_quark_to_string(qalias));
                                ret = -EINVAL;
                                goto error;
                        }
 
                        /* Make a copy of it */
-                       nested_decl_copy = bt_ctf_field_type_copy(nested_decl);
+                       nested_decl_copy = bt_field_type_copy(nested_decl);
                        BT_PUT(nested_decl);
                        if (!nested_decl_copy) {
-                               BT_LOGE_STR("Cannot copy nested field type.");
+                               _BT_LOGE_NODE(node_type_declarator,
+                                       "Cannot copy nested field type.");
                                ret = -EINVAL;
                                goto error;
                        }
@@ -1293,9 +1346,11 @@ int visit_type_declarator(struct ctx *ctx, struct ctf_node *type_specifier_list,
                        BT_MOVE(nested_decl, nested_decl_copy);
 
                        /* Force integer's base to 16 since it's a pointer */
-                       if (bt_ctf_field_type_is_integer(nested_decl)) {
-                               bt_ctf_field_type_integer_set_base(nested_decl,
-                                       BT_CTF_INTEGER_BASE_HEXADECIMAL);
+                       if (bt_field_type_is_integer(nested_decl)) {
+                               ret = bt_field_type_integer_set_base(
+                                       nested_decl,
+                                       BT_INTEGER_BASE_HEXADECIMAL);
+                               assert(ret == 0);
                        }
                } else {
                        ret = visit_type_specifier_list(ctx,
@@ -1319,6 +1374,10 @@ int visit_type_declarator(struct ctx *ctx, struct ctf_node *type_specifier_list,
                        const char *id =
                                node_type_declarator->u.type_declarator.u.id;
 
+                       if (id[0] == '_') {
+                               id++;
+                       }
+
                        *field_name = g_quark_from_string(id);
                } else {
                        *field_name = 0;
@@ -1328,21 +1387,25 @@ int visit_type_declarator(struct ctx *ctx, struct ctf_node *type_specifier_list,
                goto end;
        } else {
                struct ctf_node *first;
-               _BT_CTF_FIELD_TYPE_INIT(decl);
-               _BT_CTF_FIELD_TYPE_INIT(outer_field_decl);
+               _BT_FIELD_TYPE_INIT(decl);
+               _BT_FIELD_TYPE_INIT(outer_field_decl);
                struct bt_list_head *length =
                        &node_type_declarator->
                                u.type_declarator.u.nested.length;
 
                /* Create array/sequence, pass nested_decl as child */
                if (bt_list_empty(length)) {
-                       BT_LOGE_STR("Expecting length field reference or value.");
+                       _BT_LOGE_NODE(node_type_declarator,
+                               "Expecting length field reference or value.");
                        ret = -EINVAL;
                        goto error;
                }
 
                first = _BT_LIST_FIRST_ENTRY(length, struct ctf_node, siblings);
                if (first->type != NODE_UNARY_EXPRESSION) {
+                       _BT_LOGE_NODE(first,
+                               "Unexpected node type: node-type=%d",
+                               first->type);
                        ret = -EINVAL;
                        goto error;
                }
@@ -1351,14 +1414,15 @@ int visit_type_declarator(struct ctx *ctx, struct ctf_node *type_specifier_list,
                case UNARY_UNSIGNED_CONSTANT:
                {
                        size_t len;
-                       _BT_CTF_FIELD_TYPE_INIT(array_decl);
+                       _BT_FIELD_TYPE_INIT(array_decl);
 
                        len = first->u.unary_expression.u.unsigned_constant;
-                       array_decl = bt_ctf_field_type_array_create(nested_decl,
+                       array_decl = bt_field_type_array_create(nested_decl,
                                len);
                        BT_PUT(nested_decl);
                        if (!array_decl) {
-                               BT_LOGE_STR("Cannot create array field type.");
+                               _BT_LOGE_NODE(first,
+                                       "Cannot create array field type.");
                                ret = -ENOMEM;
                                goto error;
                        }
@@ -1369,20 +1433,32 @@ int visit_type_declarator(struct ctx *ctx, struct ctf_node *type_specifier_list,
                case UNARY_STRING:
                {
                        /* Lookup unsigned integer definition, create seq. */
-                       _BT_CTF_FIELD_TYPE_INIT(seq_decl);
+                       _BT_FIELD_TYPE_INIT(seq_decl);
                        char *length_name = concatenate_unary_strings(length);
+                       char *length_name_no_underscore;
 
                        if (!length_name) {
+                               _BT_LOGE_NODE(node_type_declarator,
+                                       "Cannot concatenate unary strings.");
                                ret = -EINVAL;
                                goto error;
                        }
 
-                       seq_decl = bt_ctf_field_type_sequence_create(
-                               nested_decl, length_name);
+                       length_name_no_underscore =
+                               remove_underscores_from_field_ref(length_name);
+                       if (!length_name_no_underscore) {
+                               /* remove_underscores_from_field_ref() logs errors */
+                               ret = -EINVAL;
+                               goto error;
+                       }
+                       seq_decl = bt_field_type_sequence_create(
+                               nested_decl, length_name_no_underscore);
+                       free(length_name_no_underscore);
                        g_free(length_name);
                        BT_PUT(nested_decl);
                        if (!seq_decl) {
-                               BT_LOGE_STR("Cannot create sequence field type.");
+                               _BT_LOGE_NODE(node_type_declarator,
+                                       "Cannot create sequence field type.");
                                ret = -ENOMEM;
                                goto error;
                        }
@@ -1437,25 +1513,26 @@ error:
 
 static
 int visit_struct_decl_field(struct ctx *ctx,
-       struct bt_ctf_field_type *struct_decl,
+       struct bt_field_type *struct_decl,
        struct ctf_node *type_specifier_list,
        struct bt_list_head *type_declarators)
 {
        int ret = 0;
        struct ctf_node *iter;
-       _BT_CTF_FIELD_TYPE_INIT(field_decl);
+       _BT_FIELD_TYPE_INIT(field_decl);
 
        bt_list_for_each_entry(iter, type_declarators, siblings) {
                field_decl = NULL;
                GQuark qfield_name;
                const char *field_name;
-               _BT_CTF_FIELD_TYPE_INIT(efield_decl);
+               _BT_FIELD_TYPE_INIT(efield_decl);
 
                ret = visit_type_declarator(ctx, type_specifier_list,
                        &qfield_name, iter, &field_decl, NULL);
                if (ret) {
                        assert(!field_decl);
-                       BT_LOGE("Cannot visit type declarator: ret=%d", ret);
+                       _BT_LOGE_NODE(type_specifier_list,
+                               "Cannot visit type declarator: ret=%d", ret);
                        goto error;
                }
 
@@ -1464,22 +1541,24 @@ int visit_struct_decl_field(struct ctx *ctx,
 
                /* Check if field with same name already exists */
                efield_decl =
-                       bt_ctf_field_type_structure_get_field_type_by_name(
+                       bt_field_type_structure_get_field_type_by_name(
                                struct_decl, field_name);
                if (efield_decl) {
                        BT_PUT(efield_decl);
-                       BT_LOGE("Duplicate field in structure field type: "
+                       _BT_LOGE_NODE(type_specifier_list,
+                               "Duplicate field in structure field type: "
                                "field-name=\"%s\"", field_name);
                        ret = -EINVAL;
                        goto error;
                }
 
                /* Add field to structure */
-               ret = bt_ctf_field_type_structure_add_field(struct_decl,
+               ret = bt_field_type_structure_add_field(struct_decl,
                        field_decl, field_name);
                BT_PUT(field_decl);
                if (ret) {
-                       BT_LOGE("Cannot add field to structure field type: "
+                       _BT_LOGE_NODE(type_specifier_list,
+                               "Cannot add field to structure field type: "
                                "field-name=\"%s\", ret=%d",
                                g_quark_to_string(qfield_name), ret);
                        goto error;
@@ -1496,25 +1575,26 @@ error:
 
 static
 int visit_variant_decl_field(struct ctx *ctx,
-       struct bt_ctf_field_type *variant_decl,
+       struct bt_field_type *variant_decl,
        struct ctf_node *type_specifier_list,
        struct bt_list_head *type_declarators)
 {
        int ret = 0;
        struct ctf_node *iter;
-       _BT_CTF_FIELD_TYPE_INIT(field_decl);
+       _BT_FIELD_TYPE_INIT(field_decl);
 
        bt_list_for_each_entry(iter, type_declarators, siblings) {
                field_decl = NULL;
                GQuark qfield_name;
                const char *field_name;
-               _BT_CTF_FIELD_TYPE_INIT(efield_decl);
+               _BT_FIELD_TYPE_INIT(efield_decl);
 
                ret = visit_type_declarator(ctx, type_specifier_list,
                        &qfield_name, iter, &field_decl, NULL);
                if (ret) {
                        assert(!field_decl);
-                       BT_LOGE("Cannot visit type declarator: ret=%d", ret);
+                       _BT_LOGE_NODE(type_specifier_list,
+                               "Cannot visit type declarator: ret=%d", ret);
                        goto error;
                }
 
@@ -1523,22 +1603,24 @@ int visit_variant_decl_field(struct ctx *ctx,
 
                /* Check if field with same name already exists */
                efield_decl =
-                       bt_ctf_field_type_variant_get_field_type_by_name(
+                       bt_field_type_variant_get_field_type_by_name(
                                variant_decl, field_name);
                if (efield_decl) {
                        BT_PUT(efield_decl);
-                       BT_LOGE("Duplicate field in variant field type: "
+                       _BT_LOGE_NODE(type_specifier_list,
+                               "Duplicate field in variant field type: "
                                "field-name=\"%s\"", field_name);
                        ret = -EINVAL;
                        goto error;
                }
 
                /* Add field to structure */
-               ret = bt_ctf_field_type_variant_add_field(variant_decl,
+               ret = bt_field_type_variant_add_field(variant_decl,
                        field_decl, field_name);
                BT_PUT(field_decl);
                if (ret) {
-                       BT_LOGE("Cannot add field to variant field type: "
+                       _BT_LOGE_NODE(type_specifier_list,
+                               "Cannot add field to variant field type: "
                                "field-name=\"%s\", ret=%d",
                                g_quark_to_string(qfield_name), ret);
                        goto error;
@@ -1560,21 +1642,23 @@ int visit_typedef(struct ctx *ctx, struct ctf_node *type_specifier_list,
        int ret = 0;
        GQuark qidentifier;
        struct ctf_node *iter;
-       _BT_CTF_FIELD_TYPE_INIT(type_decl);
+       _BT_FIELD_TYPE_INIT(type_decl);
 
        bt_list_for_each_entry(iter, type_declarators, siblings) {
                ret = visit_type_declarator(ctx, type_specifier_list,
                        &qidentifier, iter, &type_decl, NULL);
                if (ret) {
-                       BT_LOGE("Cannot visit type declarator: ret=%d", ret);
+                       _BT_LOGE_NODE(iter,
+                               "Cannot visit type declarator: ret=%d", ret);
                        ret = -EINVAL;
                        goto end;
                }
 
                /* Do not allow typedef and typealias of untagged variants */
-               if (bt_ctf_field_type_is_variant(type_decl)) {
-                       if (bt_ctf_field_type_variant_get_tag_name(type_decl)) {
-                               BT_LOGE_STR("Type definition of untagged variant field type is not allowed.");
+               if (bt_field_type_is_variant(type_decl)) {
+                       if (bt_field_type_variant_get_tag_name(type_decl)) {
+                               _BT_LOGE_NODE(iter,
+                                       "Type definition of untagged variant field type is not allowed.");
                                ret = -EPERM;
                                goto end;
                        }
@@ -1583,7 +1667,8 @@ int visit_typedef(struct ctx *ctx, struct ctf_node *type_specifier_list,
                ret = ctx_decl_scope_register_alias(ctx->current_scope,
                        g_quark_to_string(qidentifier), type_decl);
                if (ret) {
-                       BT_LOGE("Cannot register type definition: name=\"%s\"",
+                       _BT_LOGE_NODE(iter,
+                               "Cannot register type definition: name=\"%s\"",
                                g_quark_to_string(qidentifier));
                        goto end;
                }
@@ -1603,7 +1688,7 @@ int visit_typealias(struct ctx *ctx, struct ctf_node *target,
        GQuark qalias;
        struct ctf_node *node;
        GQuark qdummy_field_name;
-       _BT_CTF_FIELD_TYPE_INIT(type_decl);
+       _BT_FIELD_TYPE_INIT(type_decl);
 
        /* Create target type declaration */
        if (bt_list_empty(&target->u.typealias_target.type_declarators)) {
@@ -1619,14 +1704,16 @@ int visit_typealias(struct ctx *ctx, struct ctf_node *target,
                &qdummy_field_name, node, &type_decl, NULL);
        if (ret) {
                assert(!type_decl);
-               BT_LOGE("Cannot visit type declarator: ret=%d", ret);
+               _BT_LOGE_NODE(node,
+                       "Cannot visit type declarator: ret=%d", ret);
                goto end;
        }
 
        /* Do not allow typedef and typealias of untagged variants */
-       if (bt_ctf_field_type_is_variant(type_decl)) {
-               if (bt_ctf_field_type_variant_get_tag_name(type_decl)) {
-                       BT_LOGE_STR("Type definition of untagged variant field type is not allowed.");
+       if (bt_field_type_is_variant(type_decl)) {
+               if (bt_field_type_variant_get_tag_name(type_decl)) {
+                       _BT_LOGE_NODE(target,
+                               "Type definition of untagged variant field type is not allowed.");
                        ret = -EPERM;
                        goto end;
                }
@@ -1637,7 +1724,8 @@ int visit_typealias(struct ctx *ctx, struct ctf_node *target,
         * abstract or not (if it has an identifier). Check it here.
         */
        if (qdummy_field_name != 0) {
-               BT_LOGE("Expecting empty identifier: id=\"%s\"",
+               _BT_LOGE_NODE(target,
+                       "Expecting empty identifier: id=\"%s\"",
                        g_quark_to_string(qdummy_field_name));
                ret = -EINVAL;
                goto end;
@@ -1651,7 +1739,8 @@ int visit_typealias(struct ctx *ctx, struct ctf_node *target,
        ret = ctx_decl_scope_register_alias(ctx->current_scope,
                g_quark_to_string(qalias), type_decl);
        if (ret) {
-               BT_LOGE("Cannot register type alias: name=\"%s\"",
+               _BT_LOGE_NODE(node,
+                       "Cannot register type alias: name=\"%s\"",
                        g_quark_to_string(qalias));
                goto end;
        }
@@ -1664,7 +1753,7 @@ end:
 
 static
 int visit_struct_decl_entry(struct ctx *ctx, struct ctf_node *entry_node,
-       struct bt_ctf_field_type *struct_decl)
+       struct bt_field_type *struct_decl)
 {
        int ret = 0;
 
@@ -1674,7 +1763,8 @@ int visit_struct_decl_entry(struct ctx *ctx, struct ctf_node *entry_node,
                        entry_node->u._typedef.type_specifier_list,
                        &entry_node->u._typedef.type_declarators);
                if (ret) {
-                       BT_LOGE("Cannot add type definition found in structure field type: ret=%d",
+                       _BT_LOGE_NODE(entry_node,
+                               "Cannot add type definition found in structure field type: ret=%d",
                                ret);
                        goto end;
                }
@@ -1683,7 +1773,8 @@ int visit_struct_decl_entry(struct ctx *ctx, struct ctf_node *entry_node,
                ret = visit_typealias(ctx, entry_node->u.typealias.target,
                        entry_node->u.typealias.alias);
                if (ret) {
-                       BT_LOGE("Cannot add type alias found in structure field type: ret=%d",
+                       _BT_LOGE_NODE(entry_node,
+                               "Cannot add type alias found in structure field type: ret=%d",
                                ret);
                        goto end;
                }
@@ -1700,7 +1791,8 @@ int visit_struct_decl_entry(struct ctx *ctx, struct ctf_node *entry_node,
                }
                break;
        default:
-               BT_LOGE("Unexpected node type: node-type=%d", entry_node->type);
+               _BT_LOGE_NODE(entry_node,
+                       "Unexpected node type: node-type=%d", entry_node->type);
                ret = -EINVAL;
                goto end;
        }
@@ -1711,7 +1803,7 @@ end:
 
 static
 int visit_variant_decl_entry(struct ctx *ctx, struct ctf_node *entry_node,
-       struct bt_ctf_field_type *variant_decl)
+       struct bt_field_type *variant_decl)
 {
        int ret = 0;
 
@@ -1721,7 +1813,8 @@ int visit_variant_decl_entry(struct ctx *ctx, struct ctf_node *entry_node,
                        entry_node->u._typedef.type_specifier_list,
                        &entry_node->u._typedef.type_declarators);
                if (ret) {
-                       BT_LOGE("Cannot add type definition found in variant field type: ret=%d",
+                       _BT_LOGE_NODE(entry_node,
+                               "Cannot add type definition found in variant field type: ret=%d",
                                ret);
                        goto end;
                }
@@ -1730,7 +1823,8 @@ int visit_variant_decl_entry(struct ctx *ctx, struct ctf_node *entry_node,
                ret = visit_typealias(ctx, entry_node->u.typealias.target,
                        entry_node->u.typealias.alias);
                if (ret) {
-                       BT_LOGE("Cannot add type alias found in variant field type: ret=%d",
+                       _BT_LOGE_NODE(entry_node,
+                               "Cannot add type alias found in variant field type: ret=%d",
                                ret);
                        goto end;
                }
@@ -1747,7 +1841,8 @@ int visit_variant_decl_entry(struct ctx *ctx, struct ctf_node *entry_node,
                }
                break;
        default:
-               BT_LOGE("Unexpected node type: node-type=%d",
+               _BT_LOGE_NODE(entry_node,
+                       "Unexpected node type: node-type=%d",
                        entry_node->type);
                ret = -EINVAL;
                goto end;
@@ -1761,7 +1856,7 @@ static
 int visit_struct_decl(struct ctx *ctx, const char *name,
        struct bt_list_head *decl_list, int has_body,
        struct bt_list_head *min_align,
-       struct bt_ctf_field_type **struct_decl)
+       struct bt_field_type **struct_decl)
 {
        int ret = 0;
 
@@ -1769,9 +1864,10 @@ int visit_struct_decl(struct ctx *ctx, const char *name,
 
        /* For named struct (without body), lookup in declaration scope */
        if (!has_body) {
-               _BT_CTF_FIELD_TYPE_INIT(struct_decl_copy);
+               _BT_FIELD_TYPE_INIT(struct_decl_copy);
 
                if (!name) {
+                       BT_LOGE_STR("Bodyless structure field type: missing name.");
                        ret = -EPERM;
                        goto error;
                }
@@ -1786,7 +1882,7 @@ int visit_struct_decl(struct ctx *ctx, const char *name,
                }
 
                /* Make a copy of it */
-               struct_decl_copy = bt_ctf_field_type_copy(*struct_decl);
+               struct_decl_copy = bt_field_type_copy(*struct_decl);
                if (!struct_decl_copy) {
                        BT_LOGE_STR("Cannot create copy of structure field type.");
                        ret = -EINVAL;
@@ -1799,7 +1895,7 @@ int visit_struct_decl(struct ctx *ctx, const char *name,
                uint64_t min_align_value = 0;
 
                if (name) {
-                       _BT_CTF_FIELD_TYPE_INIT(estruct_decl);
+                       _BT_FIELD_TYPE_INIT(estruct_decl);
 
                        estruct_decl = ctx_decl_scope_lookup_struct(
                                ctx->current_scope, name, 1);
@@ -1821,7 +1917,7 @@ int visit_struct_decl(struct ctx *ctx, const char *name,
                        }
                }
 
-               *struct_decl = bt_ctf_field_type_structure_create();
+               *struct_decl = bt_field_type_structure_create();
                if (!*struct_decl) {
                        BT_LOGE_STR("Cannot create empty structure field type.");
                        ret = -ENOMEM;
@@ -1829,7 +1925,7 @@ int visit_struct_decl(struct ctx *ctx, const char *name,
                }
 
                if (min_align_value != 0) {
-                       ret = bt_ctf_field_type_set_alignment(*struct_decl,
+                       ret = bt_field_type_set_alignment(*struct_decl,
                                        min_align_value);
                        if (ret) {
                                BT_LOGE("Cannot set structure field type's alignment: "
@@ -1848,6 +1944,9 @@ int visit_struct_decl(struct ctx *ctx, const char *name,
                        ret = visit_struct_decl_entry(ctx, entry_node,
                                *struct_decl);
                        if (ret) {
+                               _BT_LOGE_NODE(entry_node,
+                                       "Cannot visit structure field type entry: "
+                                       "ret=%d", ret);
                                ctx_pop_scope(ctx);
                                goto error;
                        }
@@ -1877,18 +1976,19 @@ error:
 static
 int visit_variant_decl(struct ctx *ctx, const char *name,
        const char *tag, struct bt_list_head *decl_list,
-       int has_body, struct bt_ctf_field_type **variant_decl)
+       int has_body, struct bt_field_type **variant_decl)
 {
        int ret = 0;
-       _BT_CTF_FIELD_TYPE_INIT(untagged_variant_decl);
+       _BT_FIELD_TYPE_INIT(untagged_variant_decl);
 
        *variant_decl = NULL;
 
        /* For named variant (without body), lookup in declaration scope */
        if (!has_body) {
-               _BT_CTF_FIELD_TYPE_INIT(variant_decl_copy);
+               _BT_FIELD_TYPE_INIT(variant_decl_copy);
 
                if (!name) {
+                       BT_LOGE_STR("Bodyless variant field type: missing name.");
                        ret = -EPERM;
                        goto error;
                }
@@ -1904,7 +2004,7 @@ int visit_variant_decl(struct ctx *ctx, const char *name,
                }
 
                /* Make a copy of it */
-               variant_decl_copy = bt_ctf_field_type_copy(
+               variant_decl_copy = bt_field_type_copy(
                        untagged_variant_decl);
                if (!variant_decl_copy) {
                        BT_LOGE_STR("Cannot create copy of variant field type.");
@@ -1917,7 +2017,7 @@ int visit_variant_decl(struct ctx *ctx, const char *name,
                struct ctf_node *entry_node;
 
                if (name) {
-                       struct bt_ctf_field_type *evariant_decl =
+                       struct bt_field_type *evariant_decl =
                                ctx_decl_scope_lookup_struct(ctx->current_scope,
                                        name, 1);
 
@@ -1930,7 +2030,7 @@ int visit_variant_decl(struct ctx *ctx, const char *name,
                        }
                }
 
-               untagged_variant_decl = bt_ctf_field_type_variant_create(NULL,
+               untagged_variant_decl = bt_field_type_variant_create(NULL,
                        NULL);
                if (!untagged_variant_decl) {
                        BT_LOGE_STR("Cannot create empty variant field type.");
@@ -1948,6 +2048,9 @@ int visit_variant_decl(struct ctx *ctx, const char *name,
                        ret = visit_variant_decl_entry(ctx, entry_node,
                                untagged_variant_decl);
                        if (ret) {
+                               _BT_LOGE_NODE(entry_node,
+                                       "Cannot visit variant field type entry: "
+                                       "ret=%d", ret);
                                ctx_pop_scope(ctx);
                                goto error;
                        }
@@ -1978,9 +2081,20 @@ int visit_variant_decl(struct ctx *ctx, const char *name,
                 * At this point, we have a fresh untagged variant; nobody
                 * else owns it. Set its tag now.
                 */
-               ret = bt_ctf_field_type_variant_set_tag_name(
-                       untagged_variant_decl, tag);
+               char *tag_no_underscore =
+                       remove_underscores_from_field_ref(tag);
+
+               if (!tag_no_underscore) {
+                       /* remove_underscores_from_field_ref() logs errors */
+                       goto error;
+               }
+
+               ret = bt_field_type_variant_set_tag_name(
+                       untagged_variant_decl, tag_no_underscore);
+               free(tag_no_underscore);
                if (ret) {
+                       BT_LOGE("Cannot set variant field type's tag name: "
+                               "tag-name=\"%s\"", tag);
                        goto error;
                }
 
@@ -2001,20 +2115,22 @@ error:
 
 static
 int visit_enum_decl_entry(struct ctx *ctx, struct ctf_node *enumerator,
-       struct bt_ctf_field_type *enum_decl, int64_t *last, int is_signed)
+       struct bt_field_type *enum_decl, int64_t *last, bt_bool is_signed)
 {
        int ret = 0;
        int nr_vals = 0;
        struct ctf_node *iter;
        int64_t start = 0, end = 0;
        const char *label = enumerator->u.enumerator.id;
+       const char *effective_label = label;
        struct bt_list_head *values = &enumerator->u.enumerator.values;
 
        bt_list_for_each_entry(iter, values, siblings) {
                int64_t *target;
 
                if (iter->type != NODE_UNARY_EXPRESSION) {
-                       BT_LOGE("Wrong expression for enumeration field type label: "
+                       _BT_LOGE_NODE(iter,
+                               "Wrong expression for enumeration field type label: "
                                "node-type=%d, label=\"%s\"", iter->type,
                                label);
                        ret = -EINVAL;
@@ -2036,7 +2152,8 @@ int visit_enum_decl_entry(struct ctx *ctx, struct ctf_node *enumerator,
                                iter->u.unary_expression.u.unsigned_constant;
                        break;
                default:
-                       BT_LOGE("Invalid enumeration field type entry: "
+                       _BT_LOGE_NODE(iter,
+                               "Invalid enumeration field type entry: "
                                "expecting constant signed or unsigned integer: "
                                "node-type=%d, label=\"%s\"",
                                iter->u.unary_expression.type, label);
@@ -2045,7 +2162,8 @@ int visit_enum_decl_entry(struct ctx *ctx, struct ctf_node *enumerator,
                }
 
                if (nr_vals > 1) {
-                       BT_LOGE("Invalid enumeration field type entry: label=\"%s\"",
+                       _BT_LOGE_NODE(iter,
+                               "Invalid enumeration field type entry: label=\"%s\"",
                                label);
                        ret = -EINVAL;
                        goto error;
@@ -2064,15 +2182,28 @@ int visit_enum_decl_entry(struct ctx *ctx, struct ctf_node *enumerator,
 
        *last = end + 1;
 
+       if (label[0] == '_') {
+               /*
+                * Strip the first underscore of any enumeration field
+                * type's label in case this enumeration FT is used as
+                * a variant FT tag later. The variant FT choice names
+                * could also start with `_`, in which case the prefix
+                * is removed, and it the resulting choice name needs to
+                * match tag labels.
+                */
+               effective_label = &label[1];
+       }
+
        if (is_signed) {
-               ret = bt_ctf_field_type_enumeration_add_mapping(enum_decl, label,
-                       start, end);
+               ret = bt_field_type_enumeration_add_mapping_signed(enum_decl,
+                       effective_label, start, end);
        } else {
-               ret = bt_ctf_field_type_enumeration_add_mapping_unsigned(enum_decl,
-                       label, (uint64_t) start, (uint64_t) end);
+               ret = bt_field_type_enumeration_add_mapping_unsigned(enum_decl,
+                       effective_label, (uint64_t) start, (uint64_t) end);
        }
        if (ret) {
-               BT_LOGE("Cannot add mapping to enumeration field type: "
+               _BT_LOGE_NODE(enumerator,
+                       "Cannot add mapping to enumeration field type: "
                        "label=\"%s\", ret=%d, "
                        "start-value-unsigned=%" PRIu64 ", "
                        "end-value-unsigned=%" PRIu64, label, ret,
@@ -2091,19 +2222,20 @@ int visit_enum_decl(struct ctx *ctx, const char *name,
        struct ctf_node *container_type,
        struct bt_list_head *enumerator_list,
        int has_body,
-       struct bt_ctf_field_type **enum_decl)
+       struct bt_field_type **enum_decl)
 {
        int ret = 0;
        GQuark qdummy_id;
-       _BT_CTF_FIELD_TYPE_INIT(integer_decl);
+       _BT_FIELD_TYPE_INIT(integer_decl);
 
        *enum_decl = NULL;
 
        /* For named enum (without body), lookup in declaration scope */
        if (!has_body) {
-               _BT_CTF_FIELD_TYPE_INIT(enum_decl_copy);
+               _BT_FIELD_TYPE_INIT(enum_decl_copy);
 
                if (!name) {
+                       BT_LOGE_STR("Bodyless enumeration field type: missing name.");
                        ret = -EPERM;
                        goto error;
                }
@@ -2118,7 +2250,7 @@ int visit_enum_decl(struct ctx *ctx, const char *name,
                }
 
                /* Make a copy of it */
-               enum_decl_copy = bt_ctf_field_type_copy(*enum_decl);
+               enum_decl_copy = bt_field_type_copy(*enum_decl);
                if (!enum_decl_copy) {
                        BT_LOGE_STR("Cannot create copy of enumeration field type.");
                        ret = -EINVAL;
@@ -2132,7 +2264,7 @@ int visit_enum_decl(struct ctx *ctx, const char *name,
                int64_t last_value = 0;
 
                if (name) {
-                       _BT_CTF_FIELD_TYPE_INIT(eenum_decl);
+                       _BT_FIELD_TYPE_INIT(eenum_decl);
 
                        eenum_decl = ctx_decl_scope_lookup_enum(
                                ctx->current_scope, name, 1);
@@ -2165,16 +2297,16 @@ int visit_enum_decl(struct ctx *ctx, const char *name,
 
                assert(integer_decl);
 
-               if (!bt_ctf_field_type_is_integer(integer_decl)) {
+               if (!bt_field_type_is_integer(integer_decl)) {
                        BT_LOGE("Container field type for enumeration field type is not an integer field type: "
                                "ft-id=%s",
-                               bt_ctf_field_type_id_string(
-                                       bt_ctf_field_type_get_type_id(integer_decl)));
+                               bt_field_type_id_string(
+                                       bt_field_type_get_type_id(integer_decl)));
                        ret = -EINVAL;
                        goto error;
                }
 
-               *enum_decl = bt_ctf_field_type_enumeration_create(integer_decl);
+               *enum_decl = bt_field_type_enumeration_create(integer_decl);
                if (!*enum_decl) {
                        BT_LOGE_STR("Cannot create enumeration field type.");
                        ret = -ENOMEM;
@@ -2184,8 +2316,11 @@ int visit_enum_decl(struct ctx *ctx, const char *name,
                bt_list_for_each_entry(iter, enumerator_list, siblings) {
                        ret = visit_enum_decl_entry(ctx, iter, *enum_decl,
                                &last_value,
-                               bt_ctf_field_type_integer_get_signed(integer_decl));
+                               bt_field_type_integer_is_signed(integer_decl));
                        if (ret) {
+                               _BT_LOGE_NODE(iter,
+                                       "Cannot visit enumeration field type entry: "
+                                       "ret=%d", ret);
                                goto error;
                        }
                }
@@ -2194,6 +2329,8 @@ int visit_enum_decl(struct ctx *ctx, const char *name,
                        ret = ctx_decl_scope_register_enum(ctx->current_scope,
                                name, *enum_decl);
                        if (ret) {
+                               BT_LOGE("Cannot register enumeration field type in declaration scope: "
+                                       "ret=%d", ret);
                                goto error;
                        }
                }
@@ -2213,30 +2350,34 @@ error:
 static
 int visit_type_specifier(struct ctx *ctx,
        struct ctf_node *type_specifier_list,
-       struct bt_ctf_field_type **decl)
+       struct bt_field_type **decl)
 {
        int ret = 0;
        GString *str = NULL;
-       _BT_CTF_FIELD_TYPE_INIT(decl_copy);
+       _BT_FIELD_TYPE_INIT(decl_copy);
 
        *decl = NULL;
        str = g_string_new("");
        ret = get_type_specifier_list_name(ctx, type_specifier_list, str);
        if (ret) {
+               _BT_LOGE_NODE(type_specifier_list,
+                       "Cannot get type specifier list's name: ret=%d", ret);
                goto error;
        }
 
        *decl = ctx_decl_scope_lookup_alias(ctx->current_scope, str->str, -1);
        if (!*decl) {
-               BT_LOGE("Cannot find type alias: name=\"%s\"", str->str);
+               _BT_LOGE_NODE(type_specifier_list,
+                       "Cannot find type alias: name=\"%s\"", str->str);
                ret = -EINVAL;
                goto error;
        }
 
        /* Make a copy of the type declaration */
-       decl_copy = bt_ctf_field_type_copy(*decl);
+       decl_copy = bt_field_type_copy(*decl);
        if (!decl_copy) {
-               BT_LOGE_STR("Cannot create field type copy.");
+               _BT_LOGE_NODE(type_specifier_list,
+                       "Cannot create field type copy.");
                ret = -EINVAL;
                goto error;
        }
@@ -2260,18 +2401,18 @@ error:
 static
 int visit_integer_decl(struct ctx *ctx,
        struct bt_list_head *expressions,
-       struct bt_ctf_field_type **integer_decl)
+       struct bt_field_type **integer_decl)
 {
        int set = 0;
        int ret = 0;
-       int signedness = 0;
+       bt_bool signedness = 0;
        struct ctf_node *expression;
        uint64_t alignment = 0, size = 0;
-       struct bt_ctf_clock_class *mapped_clock = NULL;
-       enum bt_ctf_string_encoding encoding = BT_CTF_STRING_ENCODING_NONE;
-       enum bt_ctf_integer_base base = BT_CTF_INTEGER_BASE_DECIMAL;
-       enum bt_ctf_byte_order byte_order =
-               bt_ctf_trace_get_native_byte_order(ctx->trace);
+       struct bt_clock_class *mapped_clock = NULL;
+       enum bt_string_encoding encoding = BT_STRING_ENCODING_NONE;
+       enum bt_integer_base base = BT_INTEGER_BASE_DECIMAL;
+       enum bt_byte_order byte_order =
+               bt_trace_get_native_byte_order(ctx->trace);
 
        *integer_decl = NULL;
 
@@ -2285,13 +2426,16 @@ int visit_integer_decl(struct ctx *ctx,
                        siblings);
 
                if (left->u.unary_expression.type != UNARY_STRING) {
+                       _BT_LOGE_NODE(left,
+                               "Unexpected unary expression type: type=%d",
+                               left->u.unary_expression.type);
                        ret = -EINVAL;
                        goto error;
                }
 
                if (!strcmp(left->u.unary_expression.u.string, "signed")) {
                        if (_IS_SET(&set, _INTEGER_SIGNED_SET)) {
-                               _BT_LOGE_DUP_ATTR("signed",
+                               _BT_LOGE_DUP_ATTR(left, "signed",
                                        "integer field type");
                                ret = -EPERM;
                                goto error;
@@ -2299,6 +2443,9 @@ int visit_integer_decl(struct ctx *ctx,
 
                        signedness = get_boolean(right);
                        if (signedness < 0) {
+                               _BT_LOGE_NODE(right,
+                                       "Invalid boolean value for integer field type's `signed` attribute: "
+                                       "ret=%d", ret);
                                ret = -EINVAL;
                                goto error;
                        }
@@ -2307,15 +2454,16 @@ int visit_integer_decl(struct ctx *ctx,
                } else if (!strcmp(left->u.unary_expression.u.string,
                                "byte_order")) {
                        if (_IS_SET(&set, _INTEGER_BYTE_ORDER_SET)) {
-                               _BT_LOGE_DUP_ATTR("byte_order",
+                               _BT_LOGE_DUP_ATTR(left, "byte_order",
                                        "integer field type");
                                ret = -EPERM;
                                goto error;
                        }
 
                        byte_order = get_real_byte_order(ctx, right);
-                       if (byte_order == BT_CTF_BYTE_ORDER_UNKNOWN) {
-                               BT_LOGE("Invalid `byte_order` attribute in integer field type: "
+                       if (byte_order == BT_BYTE_ORDER_UNKNOWN) {
+                               _BT_LOGE_NODE(right,
+                                       "Invalid `byte_order` attribute in integer field type: "
                                        "ret=%d", ret);
                                ret = -EINVAL;
                                goto error;
@@ -2324,7 +2472,7 @@ int visit_integer_decl(struct ctx *ctx,
                        _SET(&set, _INTEGER_BYTE_ORDER_SET);
                } else if (!strcmp(left->u.unary_expression.u.string, "size")) {
                        if (_IS_SET(&set, _INTEGER_SIZE_SET)) {
-                               _BT_LOGE_DUP_ATTR("size",
+                               _BT_LOGE_DUP_ATTR(left, "size",
                                        "integer field type");
                                ret = -EPERM;
                                goto error;
@@ -2332,7 +2480,8 @@ int visit_integer_decl(struct ctx *ctx,
 
                        if (right->u.unary_expression.type !=
                                        UNARY_UNSIGNED_CONSTANT) {
-                               BT_LOGE("Invalid `size` attribute in integer field type: "
+                               _BT_LOGE_NODE(right,
+                                       "Invalid `size` attribute in integer field type: "
                                        "expecting unsigned constant integer: "
                                        "node-type=%d",
                                        right->u.unary_expression.type);
@@ -2342,13 +2491,15 @@ int visit_integer_decl(struct ctx *ctx,
 
                        size = right->u.unary_expression.u.unsigned_constant;
                        if (size == 0) {
-                               BT_LOGE("Invalid `size` attribute in integer field type: "
+                               _BT_LOGE_NODE(right,
+                                       "Invalid `size` attribute in integer field type: "
                                        "expecting positive constant integer: "
                                        "size=%" PRIu64, size);
                                ret = -EINVAL;
                                goto error;
                        } else if (size > 64) {
-                               BT_LOGE("Invalid `size` attribute in integer field type: "
+                               _BT_LOGE_NODE(right,
+                                       "Invalid `size` attribute in integer field type: "
                                        "integer fields over 64 bits are not supported as of this version: "
                                        "size=%" PRIu64, size);
                                ret = -EINVAL;
@@ -2359,7 +2510,7 @@ int visit_integer_decl(struct ctx *ctx,
                } else if (!strcmp(left->u.unary_expression.u.string,
                                "align")) {
                        if (_IS_SET(&set, _INTEGER_ALIGN_SET)) {
-                               _BT_LOGE_DUP_ATTR("align",
+                               _BT_LOGE_DUP_ATTR(left, "align",
                                        "integer field type");
                                ret = -EPERM;
                                goto error;
@@ -2367,7 +2518,8 @@ int visit_integer_decl(struct ctx *ctx,
 
                        if (right->u.unary_expression.type !=
                                        UNARY_UNSIGNED_CONSTANT) {
-                               BT_LOGE("Invalid `align` attribute in integer field type: "
+                               _BT_LOGE_NODE(right,
+                                       "Invalid `align` attribute in integer field type: "
                                        "expecting unsigned constant integer: "
                                        "node-type=%d",
                                        right->u.unary_expression.type);
@@ -2378,7 +2530,8 @@ int visit_integer_decl(struct ctx *ctx,
                        alignment =
                                right->u.unary_expression.u.unsigned_constant;
                        if (!is_align_valid(alignment)) {
-                               BT_LOGE("Invalid `align` attribute in integer field type: "
+                               _BT_LOGE_NODE(right,
+                                       "Invalid `align` attribute in integer field type: "
                                        "expecting power of two: "
                                        "align=%" PRIu64, alignment);
                                ret = -EINVAL;
@@ -2388,7 +2541,8 @@ int visit_integer_decl(struct ctx *ctx,
                        _SET(&set, _INTEGER_ALIGN_SET);
                } else if (!strcmp(left->u.unary_expression.u.string, "base")) {
                        if (_IS_SET(&set, _INTEGER_BASE_SET)) {
-                               _BT_LOGE_DUP_ATTR("base", "integer field type");
+                               _BT_LOGE_DUP_ATTR(left, "base",
+                                       "integer field type");
                                ret = -EPERM;
                                goto error;
                        }
@@ -2401,19 +2555,20 @@ int visit_integer_decl(struct ctx *ctx,
 
                                switch (constant) {
                                case 2:
-                                       base = BT_CTF_INTEGER_BASE_BINARY;
+                                       base = BT_INTEGER_BASE_BINARY;
                                        break;
                                case 8:
-                                       base = BT_CTF_INTEGER_BASE_OCTAL;
+                                       base = BT_INTEGER_BASE_OCTAL;
                                        break;
                                case 10:
-                                       base = BT_CTF_INTEGER_BASE_DECIMAL;
+                                       base = BT_INTEGER_BASE_DECIMAL;
                                        break;
                                case 16:
-                                       base = BT_CTF_INTEGER_BASE_HEXADECIMAL;
+                                       base = BT_INTEGER_BASE_HEXADECIMAL;
                                        break;
                                default:
-                                       BT_LOGE("Invalid `base` attribute in integer field type: "
+                                       _BT_LOGE_NODE(right,
+                                               "Invalid `base` attribute in integer field type: "
                                                "base=%" PRIu64,
                                                right->u.unary_expression.u.unsigned_constant);
                                        ret = -EINVAL;
@@ -2426,7 +2581,8 @@ int visit_integer_decl(struct ctx *ctx,
                                char *s_right = concatenate_unary_strings(
                                        &expression->u.ctf_expression.right);
                                if (!s_right) {
-                                       BT_LOGE_STR("Unexpected unary expression for integer field type's `base` attribute.");
+                                       _BT_LOGE_NODE(right,
+                                               "Unexpected unary expression for integer field type's `base` attribute.");
                                        ret = -EINVAL;
                                        goto error;
                                }
@@ -2436,22 +2592,23 @@ int visit_integer_decl(struct ctx *ctx,
                                                !strcmp(s_right, "d") ||
                                                !strcmp(s_right, "i") ||
                                                !strcmp(s_right, "u")) {
-                                       base = BT_CTF_INTEGER_BASE_DECIMAL;
+                                       base = BT_INTEGER_BASE_DECIMAL;
                                } else if (!strcmp(s_right, "hexadecimal") ||
                                                !strcmp(s_right, "hex") ||
                                                !strcmp(s_right, "x") ||
                                                !strcmp(s_right, "X") ||
                                                !strcmp(s_right, "p")) {
-                                       base = BT_CTF_INTEGER_BASE_HEXADECIMAL;
+                                       base = BT_INTEGER_BASE_HEXADECIMAL;
                                } else if (!strcmp(s_right, "octal") ||
                                                !strcmp(s_right, "oct") ||
                                                !strcmp(s_right, "o")) {
-                                       base = BT_CTF_INTEGER_BASE_OCTAL;
+                                       base = BT_INTEGER_BASE_OCTAL;
                                } else if (!strcmp(s_right, "binary") ||
                                                !strcmp(s_right, "b")) {
-                                       base = BT_CTF_INTEGER_BASE_BINARY;
+                                       base = BT_INTEGER_BASE_BINARY;
                                } else {
-                                       BT_LOGE("Unexpected unary expression for integer field type's `base` attribute: "
+                                       _BT_LOGE_NODE(right,
+                                               "Unexpected unary expression for integer field type's `base` attribute: "
                                                "base=\"%s\"", s_right);
                                        g_free(s_right);
                                        ret = -EINVAL;
@@ -2462,7 +2619,8 @@ int visit_integer_decl(struct ctx *ctx,
                                break;
                        }
                        default:
-                               BT_LOGE_STR("Invalid `base` attribute in integer field type: "
+                               _BT_LOGE_NODE(right,
+                                       "Invalid `base` attribute in integer field type: "
                                        "expecting unsigned constant integer or unary string.");
                                ret = -EINVAL;
                                goto error;
@@ -2474,14 +2632,15 @@ int visit_integer_decl(struct ctx *ctx,
                        char *s_right;
 
                        if (_IS_SET(&set, _INTEGER_ENCODING_SET)) {
-                               _BT_LOGE_DUP_ATTR("encoding",
+                               _BT_LOGE_DUP_ATTR(left, "encoding",
                                        "integer field type");
                                ret = -EPERM;
                                goto error;
                        }
 
                        if (right->u.unary_expression.type != UNARY_STRING) {
-                               BT_LOGE_STR("Invalid `encoding` attribute in integer field type: "
+                               _BT_LOGE_NODE(right,
+                                       "Invalid `encoding` attribute in integer field type: "
                                        "expecting unary string.");
                                ret = -EINVAL;
                                goto error;
@@ -2490,7 +2649,8 @@ int visit_integer_decl(struct ctx *ctx,
                        s_right = concatenate_unary_strings(
                                &expression->u.ctf_expression.right);
                        if (!s_right) {
-                               BT_LOGE_STR("Unexpected unary expression for integer field type's `encoding` attribute.");
+                               _BT_LOGE_NODE(right,
+                                       "Unexpected unary expression for integer field type's `encoding` attribute.");
                                ret = -EINVAL;
                                goto error;
                        }
@@ -2499,14 +2659,15 @@ int visit_integer_decl(struct ctx *ctx,
                                        !strcmp(s_right, "utf8") ||
                                        !strcmp(s_right, "utf-8") ||
                                        !strcmp(s_right, "UTF-8")) {
-                               encoding = BT_CTF_STRING_ENCODING_UTF8;
+                               encoding = BT_STRING_ENCODING_UTF8;
                        } else if (!strcmp(s_right, "ASCII") ||
                                        !strcmp(s_right, "ascii")) {
-                               encoding = BT_CTF_STRING_ENCODING_ASCII;
+                               encoding = BT_STRING_ENCODING_ASCII;
                        } else if (!strcmp(s_right, "none")) {
-                               encoding = BT_CTF_STRING_ENCODING_NONE;
+                               encoding = BT_STRING_ENCODING_NONE;
                        } else {
-                               BT_LOGE("Invalid `encoding` attribute in integer field type: "
+                               _BT_LOGE_NODE(right,
+                                       "Invalid `encoding` attribute in integer field type: "
                                        "unknown encoding: encoding=\"%s\"",
                                        s_right);
                                g_free(s_right);
@@ -2520,13 +2681,15 @@ int visit_integer_decl(struct ctx *ctx,
                        const char *clock_name;
 
                        if (_IS_SET(&set, _INTEGER_MAP_SET)) {
-                               _BT_LOGE_DUP_ATTR("map", "integer field type");
+                               _BT_LOGE_DUP_ATTR(left, "map",
+                                       "integer field type");
                                ret = -EPERM;
                                goto error;
                        }
 
                        if (right->u.unary_expression.type != UNARY_STRING) {
-                               BT_LOGE_STR("Invalid `map` attribute in integer field type: "
+                               _BT_LOGE_NODE(right,
+                                       "Invalid `map` attribute in integer field type: "
                                        "expecting unary string.");
                                ret = -EINVAL;
                                goto error;
@@ -2540,12 +2703,14 @@ int visit_integer_decl(struct ctx *ctx,
                                        &expression->u.ctf_expression.right);
 
                                if (!s_right) {
-                                       BT_LOGE_STR("Unexpected unary expression for integer field type's `map` attribute.");
+                                       _BT_LOGE_NODE(right,
+                                               "Unexpected unary expression for integer field type's `map` attribute.");
                                        ret = -EINVAL;
                                        goto error;
                                }
 
-                               BT_LOGE("Invalid `map` attribute in integer field type: "
+                               _BT_LOGE_NODE(right,
+                                       "Invalid `map` attribute in integer field type: "
                                        "cannot find clock class at this point: name=\"%s\"",
                                        s_right);
                                _SET(&set, _INTEGER_MAP_SET);
@@ -2553,10 +2718,11 @@ int visit_integer_decl(struct ctx *ctx,
                                continue;
                        }
 
-                       mapped_clock = bt_ctf_trace_get_clock_class_by_name(
+                       mapped_clock = bt_trace_get_clock_class_by_name(
                                ctx->trace, clock_name);
                        if (!mapped_clock) {
-                               BT_LOGE("Invalid `map` attribute in integer field type: "
+                               _BT_LOGE_NODE(right,
+                                       "Invalid `map` attribute in integer field type: "
                                        "cannot find clock class at this point: name=\"%s\"",
                                        clock_name);
                                ret = -EINVAL;
@@ -2565,7 +2731,8 @@ int visit_integer_decl(struct ctx *ctx,
 
                        _SET(&set, _INTEGER_MAP_SET);
                } else {
-                       BT_LOGW("Unknown attribute in integer field type: "
+                       _BT_LOGW_NODE(left,
+                               "Unknown attribute in integer field type: "
                                "attr-name=\"%s\"",
                                left->u.unary_expression.u.string);
                }
@@ -2587,23 +2754,23 @@ int visit_integer_decl(struct ctx *ctx,
                }
        }
 
-       *integer_decl = bt_ctf_field_type_integer_create((unsigned int) size);
+       *integer_decl = bt_field_type_integer_create((unsigned int) size);
        if (!*integer_decl) {
                BT_LOGE_STR("Cannot create integer field type.");
                ret = -ENOMEM;
                goto error;
        }
 
-       ret = bt_ctf_field_type_integer_set_signed(*integer_decl, signedness);
-       ret |= bt_ctf_field_type_integer_set_base(*integer_decl, base);
-       ret |= bt_ctf_field_type_integer_set_encoding(*integer_decl, encoding);
-       ret |= bt_ctf_field_type_set_alignment(*integer_decl,
+       ret = bt_field_type_integer_set_is_signed(*integer_decl, signedness);
+       ret |= bt_field_type_integer_set_base(*integer_decl, base);
+       ret |= bt_field_type_integer_set_encoding(*integer_decl, encoding);
+       ret |= bt_field_type_set_alignment(*integer_decl,
                (unsigned int) alignment);
-       ret |= bt_ctf_field_type_set_byte_order(*integer_decl, byte_order);
+       ret |= bt_field_type_set_byte_order(*integer_decl, byte_order);
 
        if (mapped_clock) {
                /* Move clock */
-               ret |= bt_ctf_field_type_integer_set_mapped_clock_class(
+               ret |= bt_field_type_integer_set_mapped_clock_class(
                        *integer_decl, mapped_clock);
                bt_put(mapped_clock);
                mapped_clock = NULL;
@@ -2630,14 +2797,14 @@ error:
 static
 int visit_floating_point_number_decl(struct ctx *ctx,
        struct bt_list_head *expressions,
-       struct bt_ctf_field_type **float_decl)
+       struct bt_field_type **float_decl)
 {
        int set = 0;
        int ret = 0;
        struct ctf_node *expression;
        uint64_t alignment = 1, exp_dig = 0, mant_dig = 0;
-       enum bt_ctf_byte_order byte_order =
-               bt_ctf_trace_get_native_byte_order(ctx->trace);
+       enum bt_byte_order byte_order =
+               bt_trace_get_native_byte_order(ctx->trace);
 
        *float_decl = NULL;
 
@@ -2651,21 +2818,25 @@ int visit_floating_point_number_decl(struct ctx *ctx,
                        siblings);
 
                if (left->u.unary_expression.type != UNARY_STRING) {
+                       _BT_LOGE_NODE(left,
+                               "Unexpected unary expression type: type=%d",
+                               left->u.unary_expression.type);
                        ret = -EINVAL;
                        goto error;
                }
 
                if (!strcmp(left->u.unary_expression.u.string, "byte_order")) {
                        if (_IS_SET(&set, _FLOAT_BYTE_ORDER_SET)) {
-                               _BT_LOGE_DUP_ATTR("byte_order",
+                               _BT_LOGE_DUP_ATTR(left, "byte_order",
                                        "floating point number field type");
                                ret = -EPERM;
                                goto error;
                        }
 
                        byte_order = get_real_byte_order(ctx, right);
-                       if (byte_order == BT_CTF_BYTE_ORDER_UNKNOWN) {
-                               BT_LOGE("Invalid `byte_order` attribute in floating point number field type: "
+                       if (byte_order == BT_BYTE_ORDER_UNKNOWN) {
+                               _BT_LOGE_NODE(right,
+                                       "Invalid `byte_order` attribute in floating point number field type: "
                                        "ret=%d", ret);
                                ret = -EINVAL;
                                goto error;
@@ -2675,7 +2846,7 @@ int visit_floating_point_number_decl(struct ctx *ctx,
                } else if (!strcmp(left->u.unary_expression.u.string,
                                "exp_dig")) {
                        if (_IS_SET(&set, _FLOAT_EXP_DIG_SET)) {
-                               _BT_LOGE_DUP_ATTR("exp_dig",
+                               _BT_LOGE_DUP_ATTR(left, "exp_dig",
                                        "floating point number field type");
                                ret = -EPERM;
                                goto error;
@@ -2683,7 +2854,8 @@ int visit_floating_point_number_decl(struct ctx *ctx,
 
                        if (right->u.unary_expression.type !=
                                        UNARY_UNSIGNED_CONSTANT) {
-                               BT_LOGE("Invalid `exp_dig` attribute in floating point number field type: "
+                               _BT_LOGE_NODE(right,
+                                       "Invalid `exp_dig` attribute in floating point number field type: "
                                        "expecting unsigned constant integer: "
                                        "node-type=%d",
                                        right->u.unary_expression.type);
@@ -2696,7 +2868,7 @@ int visit_floating_point_number_decl(struct ctx *ctx,
                } else if (!strcmp(left->u.unary_expression.u.string,
                                "mant_dig")) {
                        if (_IS_SET(&set, _FLOAT_MANT_DIG_SET)) {
-                               _BT_LOGE_DUP_ATTR("mant_dig",
+                               _BT_LOGE_DUP_ATTR(left, "mant_dig",
                                        "floating point number field type");
                                ret = -EPERM;
                                goto error;
@@ -2704,7 +2876,8 @@ int visit_floating_point_number_decl(struct ctx *ctx,
 
                        if (right->u.unary_expression.type !=
                                        UNARY_UNSIGNED_CONSTANT) {
-                               BT_LOGE("Invalid `mant_dig` attribute in floating point number field type: "
+                               _BT_LOGE_NODE(right,
+                                       "Invalid `mant_dig` attribute in floating point number field type: "
                                        "expecting unsigned constant integer: "
                                        "node-type=%d",
                                        right->u.unary_expression.type);
@@ -2718,7 +2891,7 @@ int visit_floating_point_number_decl(struct ctx *ctx,
                } else if (!strcmp(left->u.unary_expression.u.string,
                                "align")) {
                        if (_IS_SET(&set, _FLOAT_ALIGN_SET)) {
-                               _BT_LOGE_DUP_ATTR("align",
+                               _BT_LOGE_DUP_ATTR(left, "align",
                                        "floating point number field type");
                                ret = -EPERM;
                                goto error;
@@ -2726,7 +2899,8 @@ int visit_floating_point_number_decl(struct ctx *ctx,
 
                        if (right->u.unary_expression.type !=
                                        UNARY_UNSIGNED_CONSTANT) {
-                               BT_LOGE("Invalid `align` attribute in floating point number field type: "
+                               _BT_LOGE_NODE(right,
+                                       "Invalid `align` attribute in floating point number field type: "
                                        "expecting unsigned constant integer: "
                                        "node-type=%d",
                                        right->u.unary_expression.type);
@@ -2738,7 +2912,8 @@ int visit_floating_point_number_decl(struct ctx *ctx,
                                unsigned_constant;
 
                        if (!is_align_valid(alignment)) {
-                               BT_LOGE("Invalid `align` attribute in floating point number field type: "
+                               _BT_LOGE_NODE(right,
+                                       "Invalid `align` attribute in floating point number field type: "
                                        "expecting power of two: "
                                        "align=%" PRIu64, alignment);
                                ret = -EINVAL;
@@ -2747,7 +2922,8 @@ int visit_floating_point_number_decl(struct ctx *ctx,
 
                        _SET(&set, _FLOAT_ALIGN_SET);
                } else {
-                       BT_LOGW("Unknown attribute in floating point number field type: "
+                       _BT_LOGW_NODE(left,
+                               "Unknown attribute in floating point number field type: "
                                "attr-name=\"%s\"",
                                left->u.unary_expression.u.string);
                }
@@ -2775,19 +2951,19 @@ int visit_floating_point_number_decl(struct ctx *ctx,
                }
        }
 
-       *float_decl = bt_ctf_field_type_floating_point_create();
+       *float_decl = bt_field_type_floating_point_create();
        if (!*float_decl) {
                BT_LOGE_STR("Cannot create floating point number field type.");
                ret = -ENOMEM;
                goto error;
        }
 
-       ret = bt_ctf_field_type_floating_point_set_exponent_digits(
+       ret = bt_field_type_floating_point_set_exponent_digits(
                *float_decl, exp_dig);
-       ret |= bt_ctf_field_type_floating_point_set_mantissa_digits(
+       ret |= bt_field_type_floating_point_set_mantissa_digits(
                *float_decl, mant_dig);
-       ret |= bt_ctf_field_type_set_byte_order(*float_decl, byte_order);
-       ret |= bt_ctf_field_type_set_alignment(*float_decl, alignment);
+       ret |= bt_field_type_set_byte_order(*float_decl, byte_order);
+       ret |= bt_field_type_set_alignment(*float_decl, alignment);
        if (ret) {
                BT_LOGE_STR("Cannot configure floating point number field type.");
                ret = -EINVAL;
@@ -2805,12 +2981,12 @@ error:
 static
 int visit_string_decl(struct ctx *ctx,
        struct bt_list_head *expressions,
-       struct bt_ctf_field_type **string_decl)
+       struct bt_field_type **string_decl)
 {
        int set = 0;
        int ret = 0;
        struct ctf_node *expression;
-       enum bt_ctf_string_encoding encoding = BT_CTF_STRING_ENCODING_UTF8;
+       enum bt_string_encoding encoding = BT_STRING_ENCODING_UTF8;
 
        *string_decl = NULL;
 
@@ -2824,6 +3000,9 @@ int visit_string_decl(struct ctx *ctx,
                        siblings);
 
                if (left->u.unary_expression.type != UNARY_STRING) {
+                       _BT_LOGE_NODE(left,
+                               "Unexpected unary expression type: type=%d",
+                               left->u.unary_expression.type);
                        ret = -EINVAL;
                        goto error;
                }
@@ -2832,14 +3011,15 @@ int visit_string_decl(struct ctx *ctx,
                        char *s_right;
 
                        if (_IS_SET(&set, _STRING_ENCODING_SET)) {
-                               _BT_LOGE_DUP_ATTR("encoding",
+                               _BT_LOGE_DUP_ATTR(left, "encoding",
                                        "string field type");
                                ret = -EPERM;
                                goto error;
                        }
 
                        if (right->u.unary_expression.type != UNARY_STRING) {
-                               BT_LOGE_STR("Invalid `encoding` attribute in string field type: "
+                               _BT_LOGE_NODE(right,
+                                       "Invalid `encoding` attribute in string field type: "
                                        "expecting unary string.");
                                ret = -EINVAL;
                                goto error;
@@ -2848,7 +3028,8 @@ int visit_string_decl(struct ctx *ctx,
                        s_right = concatenate_unary_strings(
                                &expression->u.ctf_expression.right);
                        if (!s_right) {
-                               BT_LOGE_STR("Unexpected unary expression for string field type's `encoding` attribute.");
+                               _BT_LOGE_NODE(right,
+                                       "Unexpected unary expression for string field type's `encoding` attribute.");
                                ret = -EINVAL;
                                goto error;
                        }
@@ -2857,14 +3038,15 @@ int visit_string_decl(struct ctx *ctx,
                                        !strcmp(s_right, "utf8") ||
                                        !strcmp(s_right, "utf-8") ||
                                        !strcmp(s_right, "UTF-8")) {
-                               encoding = BT_CTF_STRING_ENCODING_UTF8;
+                               encoding = BT_STRING_ENCODING_UTF8;
                        } else if (!strcmp(s_right, "ASCII") ||
                                        !strcmp(s_right, "ascii")) {
-                               encoding = BT_CTF_STRING_ENCODING_ASCII;
+                               encoding = BT_STRING_ENCODING_ASCII;
                        } else if (!strcmp(s_right, "none")) {
-                               encoding = BT_CTF_STRING_ENCODING_NONE;
+                               encoding = BT_STRING_ENCODING_NONE;
                        } else {
-                               BT_LOGE("Invalid `encoding` attribute in string field type: "
+                               _BT_LOGE_NODE(right,
+                                       "Invalid `encoding` attribute in string field type: "
                                        "unknown encoding: encoding=\"%s\"",
                                        s_right);
                                g_free(s_right);
@@ -2875,20 +3057,21 @@ int visit_string_decl(struct ctx *ctx,
                        g_free(s_right);
                        _SET(&set, _STRING_ENCODING_SET);
                } else {
-                       BT_LOGW("Unknown attribute in string field type: "
+                       _BT_LOGW_NODE(left,
+                               "Unknown attribute in string field type: "
                                "attr-name=\"%s\"",
                                left->u.unary_expression.u.string);
                }
        }
 
-       *string_decl = bt_ctf_field_type_string_create();
+       *string_decl = bt_field_type_string_create();
        if (!*string_decl) {
                BT_LOGE_STR("Cannot create string field type.");
                ret = -ENOMEM;
                goto error;
        }
 
-       ret = bt_ctf_field_type_string_set_encoding(*string_decl, encoding);
+       ret = bt_field_type_string_set_encoding(*string_decl, encoding);
        if (ret) {
                BT_LOGE_STR("Cannot configure string field type.");
                ret = -EINVAL;
@@ -2906,7 +3089,7 @@ error:
 static
 int visit_type_specifier_list(struct ctx *ctx,
        struct ctf_node *ts_list,
-       struct bt_ctf_field_type **decl)
+       struct bt_field_type **decl)
 {
        int ret = 0;
        struct ctf_node *first, *node;
@@ -2914,6 +3097,8 @@ int visit_type_specifier_list(struct ctx *ctx,
        *decl = NULL;
 
        if (ts_list->type != NODE_TYPE_SPECIFIER_LIST) {
+               _BT_LOGE_NODE(ts_list,
+                       "Unexpected node type: node-type=%d", ts_list->type);
                ret = -EINVAL;
                goto error;
        }
@@ -2921,6 +3106,8 @@ int visit_type_specifier_list(struct ctx *ctx,
        first = _BT_LIST_FIRST_ENTRY(&ts_list->u.type_specifier_list.head,
                struct ctf_node, siblings);
        if (first->type != NODE_TYPE_SPECIFIER) {
+               _BT_LOGE_NODE(first,
+                       "Unexpected node type: node-type=%d", first->type);
                ret = -EINVAL;
                goto error;
        }
@@ -2998,12 +3185,16 @@ int visit_type_specifier_list(struct ctx *ctx,
        case TYPESPEC_ID_TYPE:
                ret = visit_type_specifier(ctx, ts_list, decl);
                if (ret) {
+                       _BT_LOGE_NODE(first,
+                               "Cannot visit type specifier: ret=%d",
+                               ret);
                        assert(!*decl);
                        goto error;
                }
                break;
        default:
-               BT_LOGE("Unexpected node type: node-type=%d",
+               _BT_LOGE_NODE(first,
+                       "Unexpected type specifier type: node-type=%d",
                        first->u.type_specifier.type);
                ret = -EINVAL;
                goto error;
@@ -3021,19 +3212,20 @@ error:
 
 static
 int visit_event_decl_entry(struct ctx *ctx, struct ctf_node *node,
-       struct bt_ctf_event_class *event_class, int64_t *stream_id,
+       struct bt_event_class *event_class, int64_t *stream_id,
        int *set)
 {
        int ret = 0;
        char *left = NULL;
-       _BT_CTF_FIELD_TYPE_INIT(decl);
+       _BT_FIELD_TYPE_INIT(decl);
 
        switch (node->type) {
        case NODE_TYPEDEF:
                ret = visit_typedef(ctx, node->u._typedef.type_specifier_list,
                        &node->u._typedef.type_declarators);
                if (ret) {
-                       BT_LOGE_STR("Cannot add type definition found in event class.");
+                       _BT_LOGE_NODE(node,
+                               "Cannot add type definition found in event class.");
                        goto error;
                }
                break;
@@ -3041,7 +3233,8 @@ int visit_event_decl_entry(struct ctx *ctx, struct ctf_node *node,
                ret = visit_typealias(ctx, node->u.typealias.target,
                        node->u.typealias.alias);
                if (ret) {
-                       BT_LOGE_STR("Cannot add type alias found in event class.");
+                       _BT_LOGE_NODE(node,
+                               "Cannot add type alias found in event class.");
                        goto error;
                }
                break;
@@ -3049,6 +3242,7 @@ int visit_event_decl_entry(struct ctx *ctx, struct ctf_node *node,
        {
                left = concatenate_unary_strings(&node->u.ctf_expression.left);
                if (!left) {
+                       _BT_LOGE_NODE(node, "Cannot concatenate unary strings.");
                        ret = -EINVAL;
                        goto error;
                }
@@ -3056,17 +3250,19 @@ int visit_event_decl_entry(struct ctx *ctx, struct ctf_node *node,
                if (!strcmp(left, "name")) {
                        /* This is already known at this stage */
                        if (_IS_SET(set, _EVENT_NAME_SET)) {
-                               _BT_LOGE_DUP_ATTR("name", "event declaration");
+                               _BT_LOGE_DUP_ATTR(node, "name",
+                                       "event class");
                                ret = -EPERM;
                                goto error;
                        }
 
                        _SET(set, _EVENT_NAME_SET);
                } else if (!strcmp(left, "id")) {
-                       int64_t id;
+                       int64_t id = -1;
 
                        if (_IS_SET(set, _EVENT_ID_SET)) {
-                               _BT_LOGE_DUP_ATTR("id", "event declaration");
+                               _BT_LOGE_DUP_ATTR(node, "id",
+                                       "event class");
                                ret = -EPERM;
                                goto error;
                        }
@@ -3075,14 +3271,16 @@ int visit_event_decl_entry(struct ctx *ctx, struct ctf_node *node,
                                (uint64_t *) &id);
                        /* Only read "id" if get_unary_unsigned() succeeded. */
                        if (ret || (!ret && id < 0)) {
-                               BT_LOGE_STR("Unexpected unary expression for event class's `id` attribute.");
+                               _BT_LOGE_NODE(node,
+                                       "Unexpected unary expression for event class's `id` attribute.");
                                ret = -EINVAL;
                                goto error;
                        }
 
-                       ret = bt_ctf_event_class_set_id(event_class, id);
+                       ret = bt_event_class_set_id(event_class, id);
                        if (ret) {
-                               BT_LOGE("Cannot set event class's ID: "
+                               _BT_LOGE_NODE(node,
+                                       "Cannot set event class's ID: "
                                        "id=%" PRId64, id);
                                goto error;
                        }
@@ -3090,7 +3288,7 @@ int visit_event_decl_entry(struct ctx *ctx, struct ctf_node *node,
                        _SET(set, _EVENT_ID_SET);
                } else if (!strcmp(left, "stream_id")) {
                        if (_IS_SET(set, _EVENT_STREAM_ID_SET)) {
-                               _BT_LOGE_DUP_ATTR("stream_id",
+                               _BT_LOGE_DUP_ATTR(node, "stream_id",
                                        "event class");
                                ret = -EPERM;
                                goto error;
@@ -3103,7 +3301,8 @@ int visit_event_decl_entry(struct ctx *ctx, struct ctf_node *node,
                         * succeeded.
                         */
                        if (ret || (!ret && *stream_id < 0)) {
-                               BT_LOGE_STR("Unexpected unary expression for event class's `stream_id` attribute.");
+                               _BT_LOGE_NODE(node,
+                                       "Unexpected unary expression for event class's `stream_id` attribute.");
                                ret = -EINVAL;
                                goto error;
                        }
@@ -3111,7 +3310,8 @@ int visit_event_decl_entry(struct ctx *ctx, struct ctf_node *node,
                        _SET(set, _EVENT_STREAM_ID_SET);
                } else if (!strcmp(left, "context")) {
                        if (_IS_SET(set, _EVENT_CONTEXT_SET)) {
-                               BT_LOGE_STR("Duplicate `context` entry in event class.");
+                               _BT_LOGE_NODE(node,
+                                       "Duplicate `context` entry in event class.");
                                ret = -EPERM;
                                goto error;
                        }
@@ -3122,23 +3322,26 @@ int visit_event_decl_entry(struct ctx *ctx, struct ctf_node *node,
                                        struct ctf_node, siblings),
                                &decl);
                        if (ret) {
-                               BT_LOGE_STR("Cannot create event class's context field type.");
+                               _BT_LOGE_NODE(node,
+                                       "Cannot create event class's context field type.");
                                goto error;
                        }
 
                        assert(decl);
-                       ret = bt_ctf_event_class_set_context_type(
+                       ret = bt_event_class_set_context_type(
                                event_class, decl);
                        BT_PUT(decl);
                        if (ret) {
-                               BT_LOGE_STR("Cannot set event class's context field type.");
+                               _BT_LOGE_NODE(node,
+                                       "Cannot set event class's context field type.");
                                goto error;
                        }
 
                        _SET(set, _EVENT_CONTEXT_SET);
                } else if (!strcmp(left, "fields")) {
                        if (_IS_SET(set, _EVENT_FIELDS_SET)) {
-                               BT_LOGE_STR("Duplicate `fields` entry in event class.");
+                               _BT_LOGE_NODE(node,
+                                       "Duplicate `fields` entry in event class.");
                                ret = -EPERM;
                                goto error;
                        }
@@ -3149,27 +3352,29 @@ int visit_event_decl_entry(struct ctx *ctx, struct ctf_node *node,
                                        struct ctf_node, siblings),
                                &decl);
                        if (ret) {
-                               BT_LOGE_STR("Cannot create event class's payload field type.");
+                               _BT_LOGE_NODE(node,
+                                       "Cannot create event class's payload field type.");
                                goto error;
                        }
 
                        assert(decl);
-                       ret = bt_ctf_event_class_set_payload_type(
+                       ret = bt_event_class_set_payload_type(
                                event_class, decl);
                        BT_PUT(decl);
                        if (ret) {
-                               BT_LOGE_STR("Cannot set event class's payload field type.");
+                               _BT_LOGE_NODE(node,
+                                       "Cannot set event class's payload field type.");
                                goto error;
                        }
 
                        _SET(set, _EVENT_FIELDS_SET);
                } else if (!strcmp(left, "loglevel")) {
                        uint64_t loglevel_value;
-                       const char *loglevel_str;
-                       struct bt_value *value_obj, *str_obj;
+                       enum bt_event_class_log_level log_level =
+                               BT_EVENT_CLASS_LOG_LEVEL_UNSPECIFIED;
 
                        if (_IS_SET(set, _EVENT_LOGLEVEL_SET)) {
-                               _BT_LOGE_DUP_ATTR("loglevel",
+                               _BT_LOGE_DUP_ATTR(node, "loglevel",
                                        "event class");
                                ret = -EPERM;
                                goto error;
@@ -3178,43 +3383,80 @@ int visit_event_decl_entry(struct ctx *ctx, struct ctf_node *node,
                        ret = get_unary_unsigned(&node->u.ctf_expression.right,
                                &loglevel_value);
                        if (ret) {
-                               BT_LOGE_STR("Unexpected unary expression for event class's `loglevel` attribute.");
+                               _BT_LOGE_NODE(node,
+                                       "Unexpected unary expression for event class's `loglevel` attribute.");
                                ret = -EINVAL;
                                goto error;
                        }
-                       value_obj = bt_value_integer_create_init(loglevel_value);
-                       if (!value_obj) {
-                               BT_LOGE_STR("Cannot create integer value object.");
-                               ret = -ENOMEM;
-                               goto error;
-                       }
-                       if (bt_ctf_event_class_set_attribute(event_class,
-                                       "loglevel", value_obj) != BT_VALUE_STATUS_OK) {
-                               BT_LOGE_STR("Cannot set event class's `loglevel` attribute.");
-                               ret = -EINVAL;
-                               bt_put(value_obj);
-                               goto error;
+
+                       switch (loglevel_value) {
+                       case 0:
+                               log_level = BT_EVENT_CLASS_LOG_LEVEL_EMERGENCY;
+                               break;
+                       case 1:
+                               log_level = BT_EVENT_CLASS_LOG_LEVEL_ALERT;
+                               break;
+                       case 2:
+                               log_level = BT_EVENT_CLASS_LOG_LEVEL_CRITICAL;
+                               break;
+                       case 3:
+                               log_level = BT_EVENT_CLASS_LOG_LEVEL_ERROR;
+                               break;
+                       case 4:
+                               log_level = BT_EVENT_CLASS_LOG_LEVEL_WARNING;
+                               break;
+                       case 5:
+                               log_level = BT_EVENT_CLASS_LOG_LEVEL_NOTICE;
+                               break;
+                       case 6:
+                               log_level = BT_EVENT_CLASS_LOG_LEVEL_INFO;
+                               break;
+                       case 7:
+                               log_level = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_SYSTEM;
+                               break;
+                       case 8:
+                               log_level = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_PROGRAM;
+                               break;
+                       case 9:
+                               log_level = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_PROCESS;
+                               break;
+                       case 10:
+                               log_level = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_MODULE;
+                               break;
+                       case 11:
+                               log_level = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_UNIT;
+                               break;
+                       case 12:
+                               log_level = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_FUNCTION;
+                               break;
+                       case 13:
+                               log_level = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_LINE;
+                               break;
+                       case 14:
+                               log_level = BT_EVENT_CLASS_LOG_LEVEL_DEBUG;
+                               break;
+                       default:
+                               _BT_LOGW_NODE(node, "Not setting event class's log level because its value is unknown: "
+                                       "log-level=%" PRIu64, loglevel_value);
                        }
-                       loglevel_str = print_loglevel(loglevel_value);
-                       if (loglevel_str) {
-                               str_obj = bt_value_string_create_init(loglevel_str);
-                               if (bt_ctf_event_class_set_attribute(event_class,
-                                               "loglevel_string", str_obj) != BT_VALUE_STATUS_OK) {
-                                       BT_LOGE_STR("Cannot set event class's `loglevel_string` attribute.");
-                                       ret = -EINVAL;
-                                       bt_put(str_obj);
+
+                       if (log_level != BT_EVENT_CLASS_LOG_LEVEL_UNSPECIFIED) {
+                               ret = bt_event_class_set_log_level(
+                                       event_class, log_level);
+                               if (ret) {
+                                       _BT_LOGE_NODE(node,
+                                               "Cannot set event class's log level.");
                                        goto error;
                                }
-                               bt_put(str_obj);
                        }
-                       bt_put(value_obj);
+
                        _SET(set, _EVENT_LOGLEVEL_SET);
                } else if (!strcmp(left, "model.emf.uri")) {
                        char *right;
 
                        if (_IS_SET(set, _EVENT_MODEL_EMF_URI_SET)) {
-                               _BT_LOGE_DUP_ATTR("model.emf.uri",
-                                       "event declaration");
+                               _BT_LOGE_DUP_ATTR(node, "model.emf.uri",
+                                       "event class");
                                ret = -EPERM;
                                goto error;
                        }
@@ -3222,17 +3464,30 @@ int visit_event_decl_entry(struct ctx *ctx, struct ctf_node *node,
                        right = concatenate_unary_strings(
                                &node->u.ctf_expression.right);
                        if (!right) {
-                               BT_LOGE_STR("Unexpected unary expression for event class's `model.emf.uri` attribute.");
+                               _BT_LOGE_NODE(node,
+                                       "Unexpected unary expression for event class's `model.emf.uri` attribute.");
                                ret = -EINVAL;
                                goto error;
                        }
 
-                       // TODO: FIXME: set model EMF URI here
+                       if (strlen(right) == 0) {
+                               _BT_LOGW_NODE(node,
+                                       "Not setting event class's EMF URI because it's empty.");
+                       } else {
+                               ret = bt_event_class_set_emf_uri(
+                                       event_class, right);
+                               if (ret) {
+                                       _BT_LOGE_NODE(node,
+                                               "Cannot set event class's EMF URI.");
+                                       goto error;
+                               }
+                       }
 
                        g_free(right);
                        _SET(set, _EVENT_MODEL_EMF_URI_SET);
                } else {
-                       BT_LOGW("Unknown attribute in event class: "
+                       _BT_LOGW_NODE(node,
+                               "Unknown attribute in event class: "
                                "attr-name=\"%s\"", left);
                }
 
@@ -3272,6 +3527,8 @@ char *get_event_decl_name(struct ctx *ctx, struct ctf_node *node)
 
                left = concatenate_unary_strings(&iter->u.ctf_expression.left);
                if (!left) {
+                       _BT_LOGE_NODE(iter,
+                               "Cannot concatenate unary strings.");
                        goto error;
                }
 
@@ -3279,7 +3536,8 @@ char *get_event_decl_name(struct ctx *ctx, struct ctf_node *node)
                        name = concatenate_unary_strings(
                                &iter->u.ctf_expression.right);
                        if (!name) {
-                               BT_LOGE_STR("Unexpected unary expression for event class's `name` attribute.");
+                               _BT_LOGE_NODE(iter,
+                                       "Unexpected unary expression for event class's `name` attribute.");
                                goto error;
                        }
                }
@@ -3302,21 +3560,25 @@ error:
 
 static
 int reset_event_decl_types(struct ctx *ctx,
-       struct bt_ctf_event_class *event_class)
+       struct bt_event_class *event_class)
 {
        int ret = 0;
 
        /* Context type. */
-       ret = bt_ctf_event_class_set_context_type(event_class, NULL);
+       ret = bt_event_class_set_context_type(event_class, NULL);
        if (ret) {
-               BT_LOGE_STR("Cannot reset initial event class's context field type.");
+               BT_LOGE("Cannot reset initial event class's context field type: "
+                       "event-name=\"%s\"",
+                       bt_event_class_get_name(event_class));
                goto end;
        }
 
        /* Event payload. */
-       ret = bt_ctf_event_class_set_payload_type(event_class, NULL);
+       ret = bt_event_class_set_payload_type(event_class, NULL);
        if (ret) {
-               BT_LOGE_STR("Cannot reset initial event class's payload field type.");
+               BT_LOGE("Cannot reset initial event class's payload field type: "
+                       "event-name=\"%s\"",
+                       bt_event_class_get_name(event_class));
                goto end;
        }
 end:
@@ -3325,26 +3587,26 @@ end:
 
 static
 int reset_stream_decl_types(struct ctx *ctx,
-       struct bt_ctf_stream_class *stream_class)
+       struct bt_stream_class *stream_class)
 {
        int ret = 0;
 
        /* Packet context. */
-       ret = bt_ctf_stream_class_set_packet_context_type(stream_class, NULL);
+       ret = bt_stream_class_set_packet_context_type(stream_class, NULL);
        if (ret) {
                BT_LOGE_STR("Cannot reset initial stream class's packet context field type.");
                goto end;
        }
 
        /* Event header. */
-       ret = bt_ctf_stream_class_set_event_header_type(stream_class, NULL);
+       ret = bt_stream_class_set_event_header_type(stream_class, NULL);
        if (ret) {
                BT_LOGE_STR("Cannot reset initial stream class's event header field type.");
                goto end;
        }
 
        /* Event context. */
-       ret = bt_ctf_stream_class_set_event_context_type(stream_class, NULL);
+       ret = bt_stream_class_set_event_context_type(stream_class, NULL);
        if (ret) {
                BT_LOGE_STR("Cannot reset initial stream class's event context field type.");
                goto end;
@@ -3354,12 +3616,12 @@ end:
 }
 
 static
-struct bt_ctf_stream_class *create_reset_stream_class(struct ctx *ctx)
+struct bt_stream_class *create_reset_stream_class(struct ctx *ctx)
 {
        int ret;
-       struct bt_ctf_stream_class *stream_class;
+       struct bt_stream_class *stream_class;
 
-       stream_class = bt_ctf_stream_class_create_empty(NULL);
+       stream_class = bt_stream_class_create_empty(NULL);
        if (!stream_class) {
                BT_LOGE_STR("Cannot create empty stream class.");
                goto error;
@@ -3391,9 +3653,9 @@ int visit_event_decl(struct ctx *ctx, struct ctf_node *node)
        struct ctf_node *iter;
        int64_t stream_id = -1;
        char *event_name = NULL;
-       struct bt_ctf_event_class *event_class = NULL;
-       struct bt_ctf_event_class *eevent_class;
-       struct bt_ctf_stream_class *stream_class = NULL;
+       struct bt_event_class *event_class = NULL;
+       struct bt_event_class *eevent_class;
+       struct bt_stream_class *stream_class = NULL;
        struct bt_list_head *decl_list = &node->u.event.declaration_list;
        bool pop_scope = false;
 
@@ -3404,18 +3666,22 @@ int visit_event_decl(struct ctx *ctx, struct ctf_node *node)
        node->visited = TRUE;
        event_name = get_event_decl_name(ctx, node);
        if (!event_name) {
-               BT_LOGE_STR("Missing `name` attribute in event class.");
+               _BT_LOGE_NODE(node,
+                       "Missing `name` attribute in event class.");
                ret = -EPERM;
                goto error;
        }
 
-       event_class = bt_ctf_event_class_create(event_name);
+       event_class = bt_event_class_create(event_name);
 
        /*
         * Unset context and fields to override the default ones.
         */
        ret = reset_event_decl_types(ctx, event_class);
        if (ret) {
+               _BT_LOGE_NODE(node,
+                       "Cannot reset event class's field types: "
+                       "ret=%d", ret);
                goto error;
        }
 
@@ -3431,16 +3697,19 @@ int visit_event_decl(struct ctx *ctx, struct ctf_node *node)
                ret = visit_event_decl_entry(ctx, iter, event_class,
                        &stream_id, &set);
                if (ret) {
+                       _BT_LOGE_NODE(iter, "Cannot visit event class's entry: "
+                               "ret=%d", ret);
                        goto error;
                }
        }
 
        if (!_IS_SET(&set, _EVENT_STREAM_ID_SET)) {
                GList *keys = NULL;
-               struct bt_ctf_stream_class *new_stream_class;
+               int64_t *new_stream_id;
+               struct bt_stream_class *new_stream_class;
                size_t stream_class_count =
                        g_hash_table_size(ctx->stream_classes) +
-                       bt_ctf_trace_get_stream_class_count(ctx->trace);
+                       bt_trace_get_stream_class_count(ctx->trace);
 
                /*
                 * Allow missing stream_id if there is only a single
@@ -3449,47 +3718,61 @@ int visit_event_decl(struct ctx *ctx, struct ctf_node *node)
                switch (stream_class_count) {
                case 0:
                        /* Create implicit stream class if there's none */
+                       stream_id = 0;
                        new_stream_class = create_reset_stream_class(ctx);
                        if (!new_stream_class) {
+                               _BT_LOGE_NODE(node,
+                                       "Cannot create empty stream class.");
                                ret = -EINVAL;
                                goto error;
                        }
 
-                       ret = bt_ctf_stream_class_set_id(new_stream_class, 0);
+                       ret = bt_stream_class_set_id(new_stream_class,
+                               stream_id);
                        if (ret) {
-                               BT_LOGE("Cannot set stream class's ID: "
+                               _BT_LOGE_NODE(node,
+                                       "Cannot set stream class's ID: "
                                        "id=0, ret=%d", ret);
                                BT_PUT(new_stream_class);
                                goto error;
                        }
 
-                       stream_id = 0;
+                       new_stream_id = g_new0(int64_t, 1);
+                       if (!new_stream_id) {
+                               BT_LOGE_STR("Failed to allocate a int64_t.");
+                               ret = -ENOMEM;
+                               goto error;
+                       }
+
+                       *new_stream_id = stream_id;
 
                        /* Move reference to visitor's context */
                        g_hash_table_insert(ctx->stream_classes,
-                               (gpointer) stream_id, new_stream_class);
+                               new_stream_id, new_stream_class);
+                       new_stream_id = NULL;
                        new_stream_class = NULL;
                        break;
                case 1:
                        /* Single stream class: get its ID */
                        if (g_hash_table_size(ctx->stream_classes) == 1) {
                                keys = g_hash_table_get_keys(ctx->stream_classes);
-                               stream_id = (int64_t) keys->data;
+                               stream_id = *((int64_t *) keys->data);
                                g_list_free(keys);
                        } else {
-                               assert(bt_ctf_trace_get_stream_class_count(
+                               assert(bt_trace_get_stream_class_count(
                                        ctx->trace) == 1);
                                stream_class =
-                                       bt_ctf_trace_get_stream_class_by_index(
+                                       bt_trace_get_stream_class_by_index(
                                                ctx->trace, 0);
                                assert(stream_class);
-                               stream_id = bt_ctf_stream_class_get_id(
+                               stream_id = bt_stream_class_get_id(
                                        stream_class);
                                BT_PUT(stream_class);
                        }
                        break;
                default:
-                       BT_LOGE_STR("Missing `stream_id` attribute in event class.");
+                       _BT_LOGE_NODE(node,
+                               "Missing `stream_id` attribute in event class.");
                        ret = -EPERM;
                        goto error;
                }
@@ -3498,14 +3781,14 @@ int visit_event_decl(struct ctx *ctx, struct ctf_node *node)
        assert(stream_id >= 0);
 
        /* We have the stream ID now; get the stream class if found */
-       stream_class = g_hash_table_lookup(ctx->stream_classes,
-               (gpointer) stream_id);
+       stream_class = g_hash_table_lookup(ctx->stream_classes, &stream_id);
        bt_get(stream_class);
        if (!stream_class) {
-               stream_class = bt_ctf_trace_get_stream_class_by_id(ctx->trace,
+               stream_class = bt_trace_get_stream_class_by_id(ctx->trace,
                        stream_id);
                if (!stream_class) {
-                       BT_LOGE("Cannot find stream class at this point: "
+                       _BT_LOGE_NODE(node,
+                               "Cannot find stream class at this point: "
                                "id=%" PRId64, stream_id);
                        ret = -EINVAL;
                        goto error;
@@ -3516,43 +3799,47 @@ int visit_event_decl(struct ctx *ctx, struct ctf_node *node)
 
        if (!_IS_SET(&set, _EVENT_ID_SET)) {
                /* Allow only one event without ID per stream */
-               if (bt_ctf_stream_class_get_event_class_count(stream_class) !=
+               if (bt_stream_class_get_event_class_count(stream_class) !=
                                0) {
-                       BT_LOGE_STR("Missing `id` attribute in event class.");
+                       _BT_LOGE_NODE(node,
+                               "Missing `id` attribute in event class.");
                        ret = -EPERM;
                        goto error;
                }
 
                /* Automatic ID */
-               ret = bt_ctf_event_class_set_id(event_class, 0);
+               ret = bt_event_class_set_id(event_class, 0);
                if (ret) {
-                       BT_LOGE("Cannot set event class's ID: id=0, ret=%d",
+                       _BT_LOGE_NODE(node,
+                               "Cannot set event class's ID: id=0, ret=%d",
                                ret);
                        goto error;
                }
        }
 
-       event_id = bt_ctf_event_class_get_id(event_class);
+       event_id = bt_event_class_get_id(event_class);
        if (event_id < 0) {
-               BT_LOGE_STR("Cannot get event class's ID.");
+               _BT_LOGE_NODE(node, "Cannot get event class's ID.");
                ret = -EINVAL;
                goto error;
        }
 
-       eevent_class = bt_ctf_stream_class_get_event_class_by_id(stream_class,
+       eevent_class = bt_stream_class_get_event_class_by_id(stream_class,
                event_id);
        if (eevent_class) {
                BT_PUT(eevent_class);
-               BT_LOGE("Duplicate event class (same ID) in the same stream class: "
+               _BT_LOGE_NODE(node,
+                       "Duplicate event class (same ID) in the same stream class: "
                        "id=%" PRId64, event_id);
                ret = -EEXIST;
                goto error;
        }
 
-       ret = bt_ctf_stream_class_add_event_class(stream_class, event_class);
+       ret = bt_stream_class_add_event_class(stream_class, event_class);
        BT_PUT(event_class);
        if (ret) {
-               BT_LOGE("Cannot add event class to stream class: ret=%d", ret);
+               _BT_LOGE_NODE(node,
+                       "Cannot add event class to stream class: ret=%d", ret);
                goto error;
        }
 
@@ -3571,20 +3858,165 @@ end:
        return ret;
 }
 
+static
+int auto_map_field_to_trace_clock_class(struct ctx *ctx,
+               struct bt_field_type *ft)
+{
+       struct bt_clock_class *clock_class_to_map_to = NULL;
+       struct bt_clock_class *mapped_clock_class = NULL;
+       int ret = 0;
+       int64_t clock_class_count;
+
+       if (!ft || !bt_field_type_is_integer(ft)) {
+               goto end;
+       }
+
+       mapped_clock_class =
+               bt_field_type_integer_get_mapped_clock_class(ft);
+       if (mapped_clock_class) {
+               goto end;
+       }
+
+       clock_class_count = bt_trace_get_clock_class_count(ctx->trace);
+       assert(clock_class_count >= 0);
+
+       switch (clock_class_count) {
+       case 0:
+               /*
+                * No clock class exists in the trace at this
+                * point. Create an implicit one at 1 GHz,
+                * named `default`, and use this clock class.
+                */
+               clock_class_to_map_to = bt_clock_class_create("default",
+                       1000000000);
+               if (!clock_class_to_map_to) {
+                       BT_LOGE_STR("Cannot create a clock class.");
+                       ret = -1;
+                       goto end;
+               }
+
+               ret = bt_trace_add_clock_class(ctx->trace,
+                       clock_class_to_map_to);
+               if (ret) {
+                       BT_LOGE_STR("Cannot add clock class to trace.");
+                       goto end;
+               }
+               break;
+       case 1:
+               /*
+                * Only one clock class exists in the trace at
+                * this point: use this one.
+                */
+               clock_class_to_map_to =
+                       bt_trace_get_clock_class_by_index(ctx->trace, 0);
+               assert(clock_class_to_map_to);
+               break;
+       default:
+               /*
+                * Timestamp field not mapped to a clock class
+                * and there's more than one clock class in the
+                * trace: this is an error.
+                */
+               BT_LOGE_STR("Timestamp field found with no mapped clock class, "
+                       "but there's more than one clock class in the trace at this point.");
+               ret = -1;
+               goto end;
+       }
+
+       assert(clock_class_to_map_to);
+       ret = bt_field_type_integer_set_mapped_clock_class(ft,
+               clock_class_to_map_to);
+       if (ret) {
+               BT_LOGE("Cannot map field type's field to trace's clock class: "
+                       "clock-class-name=\"%s\", ret=%d",
+                       bt_clock_class_get_name(clock_class_to_map_to),
+                       ret);
+               goto end;
+       }
+
+end:
+       bt_put(clock_class_to_map_to);
+       bt_put(mapped_clock_class);
+       return ret;
+}
+
+static
+int auto_map_fields_to_trace_clock_class(struct ctx *ctx,
+               struct bt_field_type *root_ft, const char *field_name)
+{
+       int ret = 0;
+       int64_t i, count;
+
+       if (!root_ft) {
+               goto end;
+       }
+
+       if (!bt_field_type_is_structure(root_ft) &&
+                       !bt_field_type_is_variant(root_ft)) {
+               goto end;
+       }
+
+       if (bt_field_type_is_structure(root_ft)) {
+               count = bt_field_type_structure_get_field_count(root_ft);
+       } else {
+               count = bt_field_type_variant_get_field_count(root_ft);
+       }
+
+       assert(count >= 0);
+
+       for (i = 0; i < count; i++) {
+               _BT_FIELD_TYPE_INIT(ft);
+               const char *name;
+
+               if (bt_field_type_is_structure(root_ft)) {
+                       ret = bt_field_type_structure_get_field_by_index(
+                               root_ft, &name, &ft, i);
+               } else if (bt_field_type_is_variant(root_ft)) {
+                       ret = bt_field_type_variant_get_field_by_index(
+                               root_ft, &name, &ft, i);
+               }
+
+               assert(ret == 0);
+
+               if (strcmp(name, field_name) == 0) {
+                       ret = auto_map_field_to_trace_clock_class(ctx, ft);
+                       if (ret) {
+                               BT_LOGE("Cannot automatically map field to trace's clock class: "
+                                       "field-name=\"%s\"", field_name);
+                               bt_put(ft);
+                               goto end;
+                       }
+               }
+
+               ret = auto_map_fields_to_trace_clock_class(ctx, ft, field_name);
+               bt_put(ft);
+               if (ret) {
+                       BT_LOGE("Cannot automatically map structure or variant field type's fields to trace's clock class: "
+                               "field-name=\"%s\", root-field-name=\"%s\"",
+                               field_name, name);
+                       goto end;
+               }
+       }
+
+end:
+       return ret;
+}
+
 static
 int visit_stream_decl_entry(struct ctx *ctx, struct ctf_node *node,
-       struct bt_ctf_stream_class *stream_class, int *set)
+       struct bt_stream_class *stream_class, int *set)
 {
        int ret = 0;
        char *left = NULL;
-       _BT_CTF_FIELD_TYPE_INIT(decl);
+       _BT_FIELD_TYPE_INIT(decl);
 
        switch (node->type) {
        case NODE_TYPEDEF:
                ret = visit_typedef(ctx, node->u._typedef.type_specifier_list,
                        &node->u._typedef.type_declarators);
                if (ret) {
-                       BT_LOGE_STR("Cannot add type definition found in stream class.");
+                       _BT_LOGE_NODE(node,
+                               "Cannot add type definition found in stream class.");
                        goto error;
                }
                break;
@@ -3592,7 +4024,8 @@ int visit_stream_decl_entry(struct ctx *ctx, struct ctf_node *node,
                ret = visit_typealias(ctx, node->u.typealias.target,
                        node->u.typealias.alias);
                if (ret) {
-                       BT_LOGE_STR("Cannot add type alias found in stream class.");
+                       _BT_LOGE_NODE(node,
+                               "Cannot add type alias found in stream class.");
                        goto error;
                }
                break;
@@ -3600,6 +4033,7 @@ int visit_stream_decl_entry(struct ctx *ctx, struct ctf_node *node,
        {
                left = concatenate_unary_strings(&node->u.ctf_expression.left);
                if (!left) {
+                       _BT_LOGE_NODE(node, "Cannot concatenate unary strings.");
                        ret = -EINVAL;
                        goto error;
                }
@@ -3609,7 +4043,8 @@ int visit_stream_decl_entry(struct ctx *ctx, struct ctf_node *node,
                        gpointer ptr;
 
                        if (_IS_SET(set, _STREAM_ID_SET)) {
-                               _BT_LOGE_DUP_ATTR("id", "stream declaration");
+                               _BT_LOGE_DUP_ATTR(node, "id",
+                                       "stream declaration");
                                ret = -EPERM;
                                goto error;
                        }
@@ -3618,23 +4053,25 @@ int visit_stream_decl_entry(struct ctx *ctx, struct ctf_node *node,
                                (uint64_t *) &id);
                        /* Only read "id" if get_unary_unsigned() succeeded. */
                        if (ret || (!ret && id < 0)) {
-                               BT_LOGE_STR("Unexpected unary expression for stream class's `id` attribute.");
+                               _BT_LOGE_NODE(node,
+                                       "Unexpected unary expression for stream class's `id` attribute.");
                                ret = -EINVAL;
                                goto error;
                        }
 
-                       ptr = g_hash_table_lookup(ctx->stream_classes,
-                               (gpointer) id);
+                       ptr = g_hash_table_lookup(ctx->stream_classes, &id);
                        if (ptr) {
-                               BT_LOGE("Duplicate stream class (same ID): id=%" PRId64,
+                               _BT_LOGE_NODE(node,
+                                       "Duplicate stream class (same ID): id=%" PRId64,
                                        id);
                                ret = -EEXIST;
                                goto error;
                        }
 
-                       ret = bt_ctf_stream_class_set_id(stream_class, id);
+                       ret = bt_stream_class_set_id(stream_class, id);
                        if (ret) {
-                               BT_LOGE("Cannot set stream class's ID: "
+                               _BT_LOGE_NODE(node,
+                                       "Cannot set stream class's ID: "
                                        "id=%" PRId64 ", ret=%d", id, ret);
                                goto error;
                        }
@@ -3642,7 +4079,8 @@ int visit_stream_decl_entry(struct ctx *ctx, struct ctf_node *node,
                        _SET(set, _STREAM_ID_SET);
                } else if (!strcmp(left, "event.header")) {
                        if (_IS_SET(set, _STREAM_EVENT_HEADER_SET)) {
-                               BT_LOGE_STR("Duplicate `event.header` entry in stream class.");
+                               _BT_LOGE_NODE(node,
+                                       "Duplicate `event.header` entry in stream class.");
                                ret = -EPERM;
                                goto error;
                        }
@@ -3653,24 +4091,34 @@ int visit_stream_decl_entry(struct ctx *ctx, struct ctf_node *node,
                                        struct ctf_node, siblings),
                                &decl);
                        if (ret) {
-                               BT_LOGE_STR("Cannot create stream class's event header field type.");
+                               _BT_LOGE_NODE(node,
+                                       "Cannot create stream class's event header field type.");
                                goto error;
                        }
 
                        assert(decl);
+                       ret = auto_map_fields_to_trace_clock_class(ctx,
+                               decl, "timestamp");
+                       if (ret) {
+                               _BT_LOGE_NODE(node,
+                                       "Cannot automatically map specific event header field type fields named `timestamp` to trace's clock class.");
+                               goto error;
+                       }
 
-                       ret = bt_ctf_stream_class_set_event_header_type(
+                       ret = bt_stream_class_set_event_header_type(
                                stream_class, decl);
                        BT_PUT(decl);
                        if (ret) {
-                               BT_LOGE_STR("Cannot set stream class's event header field type.");
+                               _BT_LOGE_NODE(node,
+                                       "Cannot set stream class's event header field type.");
                                goto error;
                        }
 
                        _SET(set, _STREAM_EVENT_HEADER_SET);
                } else if (!strcmp(left, "event.context")) {
                        if (_IS_SET(set, _STREAM_EVENT_CONTEXT_SET)) {
-                               BT_LOGE_STR("Duplicate `event.context` entry in stream class.");
+                               _BT_LOGE_NODE(node,
+                                       "Duplicate `event.context` entry in stream class.");
                                ret = -EPERM;
                                goto error;
                        }
@@ -3681,24 +4129,27 @@ int visit_stream_decl_entry(struct ctx *ctx, struct ctf_node *node,
                                        struct ctf_node, siblings),
                                &decl);
                        if (ret) {
-                               BT_LOGE_STR("Cannot create stream class's event context field type.");
+                               _BT_LOGE_NODE(node,
+                                       "Cannot create stream class's event context field type.");
                                goto error;
                        }
 
                        assert(decl);
 
-                       ret = bt_ctf_stream_class_set_event_context_type(
+                       ret = bt_stream_class_set_event_context_type(
                                stream_class, decl);
                        BT_PUT(decl);
                        if (ret) {
-                               BT_LOGE_STR("Cannot set stream class's event context field type.");
+                               _BT_LOGE_NODE(node,
+                                       "Cannot set stream class's event context field type.");
                                goto error;
                        }
 
                        _SET(set, _STREAM_EVENT_CONTEXT_SET);
                } else if (!strcmp(left, "packet.context")) {
                        if (_IS_SET(set, _STREAM_PACKET_CONTEXT_SET)) {
-                               BT_LOGE_STR("Duplicate `packet.context` entry in stream class.");
+                               _BT_LOGE_NODE(node,
+                                       "Duplicate `packet.context` entry in stream class.");
                                ret = -EPERM;
                                goto error;
                        }
@@ -3709,23 +4160,41 @@ int visit_stream_decl_entry(struct ctx *ctx, struct ctf_node *node,
                                        struct ctf_node, siblings),
                                &decl);
                        if (ret) {
-                               BT_LOGE_STR("Cannot create stream class's packet context field type.");
+                               _BT_LOGE_NODE(node,
+                                       "Cannot create stream class's packet context field type.");
                                goto error;
                        }
 
                        assert(decl);
+                       ret = auto_map_fields_to_trace_clock_class(ctx,
+                               decl, "timestamp_begin");
+                       if (ret) {
+                               _BT_LOGE_NODE(node,
+                                       "Cannot automatically map specific packet context field type fields named `timestamp_begin` to trace's clock class.");
+                               goto error;
+                       }
+
+                       ret = auto_map_fields_to_trace_clock_class(ctx,
+                               decl, "timestamp_end");
+                       if (ret) {
+                               _BT_LOGE_NODE(node,
+                                       "Cannot automatically map specific packet context field type fields named `timestamp_end` to trace's clock class.");
+                               goto error;
+                       }
 
-                       ret = bt_ctf_stream_class_set_packet_context_type(
+                       ret = bt_stream_class_set_packet_context_type(
                                stream_class, decl);
                        BT_PUT(decl);
                        if (ret) {
-                               BT_LOGE_STR("Cannot set stream class's packet context field type.");
+                               _BT_LOGE_NODE(node,
+                                       "Cannot set stream class's packet context field type.");
                                goto error;
                        }
 
                        _SET(set, _STREAM_PACKET_CONTEXT_SET);
                } else {
-                       BT_LOGW("Unknown attribute in stream class: "
+                       _BT_LOGW_NODE(node,
+                               "Unknown attribute in stream class: "
                                "attr-name=\"%s\"", left);
                }
 
@@ -3752,11 +4221,12 @@ static
 int visit_stream_decl(struct ctx *ctx, struct ctf_node *node)
 {
        int64_t id;
+       int64_t *new_id;
        int set = 0;
        int ret = 0;
        struct ctf_node *iter;
-       struct bt_ctf_stream_class *stream_class = NULL;
-       struct bt_ctf_stream_class *existing_stream_class = NULL;
+       struct bt_stream_class *stream_class = NULL;
+       struct bt_stream_class *existing_stream_class = NULL;
        struct bt_list_head *decl_list = &node->u.stream.declaration_list;
 
        if (node->visited) {
@@ -3766,6 +4236,7 @@ int visit_stream_decl(struct ctx *ctx, struct ctf_node *node)
        node->visited = TRUE;
        stream_class = create_reset_stream_class(ctx);
        if (!stream_class) {
+               _BT_LOGE_NODE(node, "Cannot create empty stream class.");
                ret = -EINVAL;
                goto error;
        }
@@ -3779,6 +4250,9 @@ int visit_stream_decl(struct ctx *ctx, struct ctf_node *node)
        bt_list_for_each_entry(iter, decl_list, siblings) {
                ret = visit_stream_decl_entry(ctx, iter, stream_class, &set);
                if (ret) {
+                       _BT_LOGE_NODE(iter,
+                               "Cannot visit stream class's entry: "
+                               "ret=%d", ret);
                        ctx_pop_scope(ctx);
                        goto error;
                }
@@ -3788,30 +4262,33 @@ int visit_stream_decl(struct ctx *ctx, struct ctf_node *node)
 
        if (_IS_SET(&set, _STREAM_ID_SET)) {
                /* Check that packet header has stream_id field */
-               _BT_CTF_FIELD_TYPE_INIT(stream_id_decl);
-               _BT_CTF_FIELD_TYPE_INIT(packet_header_decl);
+               _BT_FIELD_TYPE_INIT(stream_id_decl);
+               _BT_FIELD_TYPE_INIT(packet_header_decl);
 
                packet_header_decl =
-                       bt_ctf_trace_get_packet_header_type(ctx->trace);
+                       bt_trace_get_packet_header_type(ctx->trace);
                if (!packet_header_decl) {
-                       BT_LOGE_STR("Stream class has a `id` attribute, "
+                       _BT_LOGE_NODE(node,
+                               "Stream class has a `id` attribute, "
                                "but trace has no packet header field type.");
                        goto error;
                }
 
                stream_id_decl =
-                       bt_ctf_field_type_structure_get_field_type_by_name(
+                       bt_field_type_structure_get_field_type_by_name(
                                packet_header_decl, "stream_id");
                BT_PUT(packet_header_decl);
                if (!stream_id_decl) {
-                       BT_LOGE_STR("Stream class has a `id` attribute, "
+                       _BT_LOGE_NODE(node,
+                               "Stream class has a `id` attribute, "
                                "but trace's packet header field type has no `stream_id` field.");
                        goto error;
                }
 
-               if (!bt_ctf_field_type_is_integer(stream_id_decl)) {
+               if (!bt_field_type_is_integer(stream_id_decl)) {
                        BT_PUT(stream_id_decl);
-                       BT_LOGE_STR("Stream class has a `id` attribute, "
+                       _BT_LOGE_NODE(node,
+                               "Stream class has a `id` attribute, "
                                "but trace's packet header field type's `stream_id` field is not an integer field type.");
                        goto error;
                }
@@ -3820,19 +4297,21 @@ int visit_stream_decl(struct ctx *ctx, struct ctf_node *node)
        } else {
                /* Allow only _one_ ID-less stream */
                if (g_hash_table_size(ctx->stream_classes) != 0) {
-                       BT_LOGE_STR("Missing `id` attribute in stream class as there's more than one stream class in the trace.");
+                       _BT_LOGE_NODE(node,
+                               "Missing `id` attribute in stream class as there's more than one stream class in the trace.");
                        ret = -EPERM;
                        goto error;
                }
 
                /* Automatic ID: 0 */
-               ret = bt_ctf_stream_class_set_id(stream_class, 0);
+               ret = bt_stream_class_set_id(stream_class, 0);
                assert(ret == 0);
        }
 
-       id = bt_ctf_stream_class_get_id(stream_class);
+       id = bt_stream_class_get_id(stream_class);
        if (id < 0) {
-               BT_LOGE_STR("Cannot get stream class's ID.");
+               _BT_LOGE_NODE(node,
+                       "Cannot get stream class's ID.");
                ret = -EINVAL;
                goto error;
        }
@@ -3841,18 +4320,27 @@ int visit_stream_decl(struct ctx *ctx, struct ctf_node *node)
         * Make sure that this stream class's ID is currently unique in
         * the trace.
         */
-       existing_stream_class = bt_ctf_trace_get_stream_class_by_id(ctx->trace,
+       existing_stream_class = bt_trace_get_stream_class_by_id(ctx->trace,
                id);
-       if (g_hash_table_lookup(ctx->stream_classes, (gpointer) id) ||
+       if (g_hash_table_lookup(ctx->stream_classes, &id) ||
                        existing_stream_class) {
-               BT_LOGE("Duplicate stream class (same ID): id=%" PRId64,
+               _BT_LOGE_NODE(node,
+                       "Duplicate stream class (same ID): id=%" PRId64,
                        id);
                ret = -EINVAL;
                goto error;
        }
 
+       new_id = g_new0(int64_t, 1);
+       if (!new_id) {
+               BT_LOGE_STR("Failed to allocate a int64_t.");
+               ret = -ENOMEM;
+               goto error;
+       }
+       *new_id = id;
+
        /* Move reference to visitor's context */
-       g_hash_table_insert(ctx->stream_classes, (gpointer) (int64_t) id,
+       g_hash_table_insert(ctx->stream_classes, new_id,
                stream_class);
        stream_class = NULL;
        goto end;
@@ -3870,14 +4358,15 @@ int visit_trace_decl_entry(struct ctx *ctx, struct ctf_node *node, int *set)
 {
        int ret = 0;
        char *left = NULL;
-       _BT_CTF_FIELD_TYPE_INIT(packet_header_decl);
+       _BT_FIELD_TYPE_INIT(packet_header_decl);
 
        switch (node->type) {
        case NODE_TYPEDEF:
                ret = visit_typedef(ctx, node->u._typedef.type_specifier_list,
                        &node->u._typedef.type_declarators);
                if (ret) {
-                       BT_LOGE_STR("Cannot add type definition found in trace (`trace` block).");
+                       _BT_LOGE_NODE(node,
+                               "Cannot add type definition found in trace (`trace` block).");
                        goto error;
                }
                break;
@@ -3885,7 +4374,8 @@ int visit_trace_decl_entry(struct ctx *ctx, struct ctf_node *node, int *set)
                ret = visit_typealias(ctx, node->u.typealias.target,
                        node->u.typealias.alias);
                if (ret) {
-                       BT_LOGE_STR("Cannot add type alias found in trace (`trace` block).");
+                       _BT_LOGE_NODE(node,
+                               "Cannot add type alias found in trace (`trace` block).");
                        goto error;
                }
                break;
@@ -3893,13 +4383,14 @@ int visit_trace_decl_entry(struct ctx *ctx, struct ctf_node *node, int *set)
        {
                left = concatenate_unary_strings(&node->u.ctf_expression.left);
                if (!left) {
+                       _BT_LOGE_NODE(node, "Cannot concatenate unary strings.");
                        ret = -EINVAL;
                        goto error;
                }
 
                if (!strcmp(left, "major")) {
                        if (_IS_SET(set, _TRACE_MAJOR_SET)) {
-                               _BT_LOGE_DUP_ATTR("major", "trace");
+                               _BT_LOGE_DUP_ATTR(node, "major", "trace");
                                ret = -EPERM;
                                goto error;
                        }
@@ -3907,7 +4398,8 @@ int visit_trace_decl_entry(struct ctx *ctx, struct ctf_node *node, int *set)
                        ret = get_unary_unsigned(&node->u.ctf_expression.right,
                                &ctx->trace_major);
                        if (ret) {
-                               BT_LOGE_STR("Unexpected unary expression for trace's `major` attribute.");
+                               _BT_LOGE_NODE(node,
+                                       "Unexpected unary expression for trace's `major` attribute.");
                                ret = -EINVAL;
                                goto error;
                        }
@@ -3915,7 +4407,7 @@ int visit_trace_decl_entry(struct ctx *ctx, struct ctf_node *node, int *set)
                        _SET(set, _TRACE_MAJOR_SET);
                } else if (!strcmp(left, "minor")) {
                        if (_IS_SET(set, _TRACE_MINOR_SET)) {
-                               _BT_LOGE_DUP_ATTR("minor", "trace");
+                               _BT_LOGE_DUP_ATTR(node, "minor", "trace");
                                ret = -EPERM;
                                goto error;
                        }
@@ -3923,7 +4415,8 @@ int visit_trace_decl_entry(struct ctx *ctx, struct ctf_node *node, int *set)
                        ret = get_unary_unsigned(&node->u.ctf_expression.right,
                                &ctx->trace_minor);
                        if (ret) {
-                               BT_LOGE_STR("Unexpected unary expression for trace's `minor` attribute.");
+                               _BT_LOGE_NODE(node,
+                                       "Unexpected unary expression for trace's `minor` attribute.");
                                ret = -EINVAL;
                                goto error;
                        }
@@ -3931,7 +4424,7 @@ int visit_trace_decl_entry(struct ctx *ctx, struct ctf_node *node, int *set)
                        _SET(set, _TRACE_MINOR_SET);
                } else if (!strcmp(left, "uuid")) {
                        if (_IS_SET(set, _TRACE_UUID_SET)) {
-                               _BT_LOGE_DUP_ATTR("uuid", "trace");
+                               _BT_LOGE_DUP_ATTR(node, "uuid", "trace");
                                ret = -EPERM;
                                goto error;
                        }
@@ -3939,13 +4432,14 @@ int visit_trace_decl_entry(struct ctx *ctx, struct ctf_node *node, int *set)
                        ret = get_unary_uuid(&node->u.ctf_expression.right,
                                ctx->trace_uuid);
                        if (ret) {
-                               BT_LOGE_STR("Invalid trace's `uuid` attribute.");
+                               _BT_LOGE_NODE(node,
+                                       "Invalid trace's `uuid` attribute.");
                                goto error;
                        }
 
-                       ret = bt_ctf_trace_set_uuid(ctx->trace, ctx->trace_uuid);
+                       ret = bt_trace_set_uuid(ctx->trace, ctx->trace_uuid);
                        if (ret) {
-                               BT_LOGE_STR("Cannot set trace's UUID.");
+                               _BT_LOGE_NODE(node, "Cannot set trace's UUID.");
                                goto error;
                        }
 
@@ -3953,7 +4447,7 @@ int visit_trace_decl_entry(struct ctx *ctx, struct ctf_node *node, int *set)
                } else if (!strcmp(left, "byte_order")) {
                        /* Native byte order is already known at this stage */
                        if (_IS_SET(set, _TRACE_BYTE_ORDER_SET)) {
-                               _BT_LOGE_DUP_ATTR("byte_order",
+                               _BT_LOGE_DUP_ATTR(node, "byte_order",
                                        "trace");
                                ret = -EPERM;
                                goto error;
@@ -3962,7 +4456,8 @@ int visit_trace_decl_entry(struct ctx *ctx, struct ctf_node *node, int *set)
                        _SET(set, _TRACE_BYTE_ORDER_SET);
                } else if (!strcmp(left, "packet.header")) {
                        if (_IS_SET(set, _TRACE_PACKET_HEADER_SET)) {
-                               BT_LOGE_STR("Duplicate `packet.header` entry in trace.");
+                               _BT_LOGE_NODE(node,
+                                       "Duplicate `packet.header` entry in trace.");
                                ret = -EPERM;
                                goto error;
                        }
@@ -3973,22 +4468,25 @@ int visit_trace_decl_entry(struct ctx *ctx, struct ctf_node *node, int *set)
                                        struct ctf_node, siblings),
                                &packet_header_decl);
                        if (ret) {
-                               BT_LOGE_STR("Cannot create trace's packet header field type.");
+                               _BT_LOGE_NODE(node,
+                                       "Cannot create trace's packet header field type.");
                                goto error;
                        }
 
                        assert(packet_header_decl);
-                       ret = bt_ctf_trace_set_packet_header_type(ctx->trace,
+                       ret = bt_trace_set_packet_header_type(ctx->trace,
                                packet_header_decl);
                        BT_PUT(packet_header_decl);
                        if (ret) {
-                               BT_LOGE_STR("Cannot set trace's packet header field type.");
+                               _BT_LOGE_NODE(node,
+                                       "Cannot set trace's packet header field type.");
                                goto error;
                        }
 
                        _SET(set, _TRACE_PACKET_HEADER_SET);
                } else {
-                       BT_LOGW("Unknown attribute in stream class: "
+                       _BT_LOGW_NODE(node,
+                               "Unknown attribute in stream class: "
                                "attr-name=\"%s\"", left);
                }
 
@@ -3997,7 +4495,7 @@ int visit_trace_decl_entry(struct ctx *ctx, struct ctf_node *node, int *set)
                break;
        }
        default:
-               BT_LOGE_STR("Unknown expression in trace.");
+               _BT_LOGE_NODE(node, "Unknown expression in trace.");
                ret = -EINVAL;
                goto error;
        }
@@ -4026,7 +4524,7 @@ int visit_trace_decl(struct ctx *ctx, struct ctf_node *node)
        node->visited = TRUE;
 
        if (ctx->is_trace_visited) {
-               BT_LOGE_STR("Duplicate trace (`trace` block).");
+               _BT_LOGE_NODE(node, "Duplicate trace (`trace` block).");
                ret = -EEXIST;
                goto error;
        }
@@ -4040,6 +4538,8 @@ int visit_trace_decl(struct ctx *ctx, struct ctf_node *node)
        bt_list_for_each_entry(iter, decl_list, siblings) {
                ret = visit_trace_decl_entry(ctx, iter, &set);
                if (ret) {
+                       _BT_LOGE_NODE(iter, "Cannot visit trace's entry (`trace` block): "
+                               "ret=%d", ret);
                        ctx_pop_scope(ctx);
                        goto error;
                }
@@ -4048,19 +4548,22 @@ int visit_trace_decl(struct ctx *ctx, struct ctf_node *node)
        ctx_pop_scope(ctx);
 
        if (!_IS_SET(&set, _TRACE_MAJOR_SET)) {
-               BT_LOGE_STR("Missing `major` attribute in trace (`trace` block).");
+               _BT_LOGE_NODE(node,
+                       "Missing `major` attribute in trace (`trace` block).");
                ret = -EPERM;
                goto error;
        }
 
        if (!_IS_SET(&set, _TRACE_MINOR_SET)) {
-               BT_LOGE_STR("Missing `minor` attribute in trace (`trace` block).");
+               _BT_LOGE_NODE(node,
+                       "Missing `minor` attribute in trace (`trace` block).");
                ret = -EPERM;
                goto error;
        }
 
        if (!_IS_SET(&set, _TRACE_BYTE_ORDER_SET)) {
-               BT_LOGE_STR("Missing `byte_order` attribute in trace (`trace` block).");
+               _BT_LOGE_NODE(node,
+                       "Missing `byte_order` attribute in trace (`trace` block).");
                ret = -EPERM;
                goto error;
        }
@@ -4093,7 +4596,8 @@ int visit_env(struct ctx *ctx, struct ctf_node *node)
                        &entry_node->u.ctf_expression.right;
 
                if (entry_node->type != NODE_CTF_EXPRESSION) {
-                       BT_LOGE("Wrong expression in environment entry: "
+                       _BT_LOGE_NODE(entry_node,
+                               "Wrong expression in environment entry: "
                                "node-type=%d", entry_node->type);
                        ret = -EPERM;
                        goto error;
@@ -4102,7 +4606,8 @@ int visit_env(struct ctx *ctx, struct ctf_node *node)
                left = concatenate_unary_strings(
                        &entry_node->u.ctf_expression.left);
                if (!left) {
-                       BT_LOGE_STR("Cannot get environment entry's name.");
+                       _BT_LOGE_NODE(entry_node,
+                               "Cannot get environment entry's name.");
                        ret = -EINVAL;
                        goto error;
                }
@@ -4111,7 +4616,8 @@ int visit_env(struct ctx *ctx, struct ctf_node *node)
                        char *right = concatenate_unary_strings(right_head);
 
                        if (!right) {
-                               BT_LOGE("Unexpected unary expression for environment entry's value: "
+                               _BT_LOGE_NODE(entry_node,
+                                       "Unexpected unary expression for environment entry's value: "
                                        "name=\"%s\"", left);
                                ret = -EINVAL;
                                goto error;
@@ -4119,16 +4625,20 @@ int visit_env(struct ctx *ctx, struct ctf_node *node)
 
                        if (strcmp(left, "tracer_name") == 0) {
                                if (strncmp(right, "lttng", 5) == 0) {
+                                       BT_LOGI("Detected LTTng trace from `%s` environment value: "
+                                               "tracer-name=\"%s\"",
+                                               left, right);
                                        ctx->is_lttng = 1;
                                }
                        }
 
-                       ret = bt_ctf_trace_set_environment_field_string(
+                       ret = bt_trace_set_environment_field_string(
                                ctx->trace, left, right);
                        g_free(right);
 
                        if (ret) {
-                               BT_LOGE("Cannot add string environment entry to trace: "
+                               _BT_LOGE_NODE(entry_node,
+                                       "Cannot add string environment entry to trace: "
                                        "name=\"%s\", ret=%d", left, ret);
                                goto error;
                        }
@@ -4143,21 +4653,24 @@ int visit_env(struct ctx *ctx, struct ctf_node *node)
                                ret = get_unary_signed(right_head, &v);
                        }
                        if (ret) {
-                               BT_LOGE("Unexpected unary expression for environment entry's value: "
+                               _BT_LOGE_NODE(entry_node,
+                                       "Unexpected unary expression for environment entry's value: "
                                        "name=\"%s\"", left);
                                ret = -EINVAL;
                                goto error;
                        }
 
-                       ret = bt_ctf_trace_set_environment_field_integer(
+                       ret = bt_trace_set_environment_field_integer(
                                ctx->trace, left, v);
                        if (ret) {
-                               BT_LOGE("Cannot add integer environment entry to trace: "
+                               _BT_LOGE_NODE(entry_node,
+                                       "Cannot add integer environment entry to trace: "
                                        "name=\"%s\", ret=%d", left, ret);
                                goto error;
                        }
                } else {
-                       BT_LOGW("Environment entry has unknown type: "
+                       _BT_LOGW_NODE(entry_node,
+                               "Environment entry has unknown type: "
                                "name=\"%s\"", left);
                }
 
@@ -4190,15 +4703,17 @@ int set_trace_byte_order(struct ctx *ctx, struct ctf_node *trace_node)
                        left = concatenate_unary_strings(
                                &node->u.ctf_expression.left);
                        if (!left) {
+                               _BT_LOGE_NODE(node,
+                                       "Cannot concatenate unary strings.");
                                ret = -EINVAL;
                                goto error;
                        }
 
                        if (!strcmp(left, "byte_order")) {
-                               enum bt_ctf_byte_order bo;
+                               enum bt_byte_order bo;
 
                                if (_IS_SET(&set, _TRACE_BYTE_ORDER_SET)) {
-                                       _BT_LOGE_DUP_ATTR("byte_order",
+                                       _BT_LOGE_DUP_ATTR(node, "byte_order",
                                                "trace");
                                        ret = -EPERM;
                                        goto error;
@@ -4209,21 +4724,26 @@ int set_trace_byte_order(struct ctx *ctx, struct ctf_node *trace_node)
                                        &node->u.ctf_expression.right,
                                        struct ctf_node, siblings);
                                bo = byte_order_from_unary_expr(right_node);
-                               if (bo == BT_CTF_BYTE_ORDER_UNKNOWN) {
+                               if (bo == BT_BYTE_ORDER_UNKNOWN) {
+                                       _BT_LOGE_NODE(node,
+                                               "Invalid `byte_order` attribute in trace (`trace` block): "
+                                               "expecting `le`, `be`, or `network`.");
                                        ret = -EINVAL;
                                        goto error;
-                               } else if (bo == BT_CTF_BYTE_ORDER_NATIVE) {
-                                       BT_LOGE_STR("Invalid `byte_order` attribute in trace (`trace` block): "
+                               } else if (bo == BT_BYTE_ORDER_NATIVE) {
+                                       _BT_LOGE_NODE(node,
+                                               "Invalid `byte_order` attribute in trace (`trace` block): "
                                                "cannot be set to `native` here.");
                                        ret = -EPERM;
                                        goto error;
                                }
 
                                ctx->trace_bo = bo;
-                               ret = bt_ctf_trace_set_native_byte_order(
+                               ret = bt_trace_set_native_byte_order(
                                        ctx->trace, bo);
                                if (ret) {
-                                       BT_LOGE("Cannot set trace's byte order: "
+                                       _BT_LOGE_NODE(node,
+                                               "Cannot set trace's byte order: "
                                                "ret=%d", ret);
                                        goto error;
                                }
@@ -4235,7 +4755,8 @@ int set_trace_byte_order(struct ctx *ctx, struct ctf_node *trace_node)
        }
 
        if (!_IS_SET(&set, _TRACE_BYTE_ORDER_SET)) {
-               BT_LOGE_STR("Missing `byte_order` attribute in trace (`trace` block).");
+               _BT_LOGE_NODE(trace_node,
+                       "Missing `byte_order` attribute in trace (`trace` block).");
                ret = -EINVAL;
                goto error;
        }
@@ -4250,18 +4771,22 @@ error:
 
 static
 int visit_clock_decl_entry(struct ctx *ctx, struct ctf_node *entry_node,
-       struct bt_ctf_clock_class *clock, int *set)
+       struct bt_clock_class *clock, int *set)
 {
        int ret = 0;
        char *left = NULL;
 
        if (entry_node->type != NODE_CTF_EXPRESSION) {
+               _BT_LOGE_NODE(entry_node,
+                       "Unexpected node type: node-type=%d",
+                       entry_node->type);
                ret = -EPERM;
                goto error;
        }
 
        left = concatenate_unary_strings(&entry_node->u.ctf_expression.left);
        if (!left) {
+               _BT_LOGE_NODE(entry_node, "Cannot concatenate unary strings.");
                ret = -EINVAL;
                goto error;
        }
@@ -4270,7 +4795,7 @@ int visit_clock_decl_entry(struct ctx *ctx, struct ctf_node *entry_node,
                char *right;
 
                if (_IS_SET(set, _CLOCK_NAME_SET)) {
-                       _BT_LOGE_DUP_ATTR("name", "clock class");
+                       _BT_LOGE_DUP_ATTR(entry_node, "name", "clock class");
                        ret = -EPERM;
                        goto error;
                }
@@ -4278,14 +4803,16 @@ int visit_clock_decl_entry(struct ctx *ctx, struct ctf_node *entry_node,
                right = concatenate_unary_strings(
                        &entry_node->u.ctf_expression.right);
                if (!right) {
-                       BT_LOGE_STR("Unexpected unary expression for clock class's `name` attribute.");
+                       _BT_LOGE_NODE(entry_node,
+                               "Unexpected unary expression for clock class's `name` attribute.");
                        ret = -EINVAL;
                        goto error;
                }
 
-               ret = bt_ctf_clock_class_set_name(clock, right);
+               ret = bt_clock_class_set_name(clock, right);
                if (ret) {
-                       BT_LOGE("cannot set clock class's name");
+                       _BT_LOGE_NODE(entry_node,
+                               "cannot set clock class's name");
                        g_free(right);
                        goto error;
                }
@@ -4296,20 +4823,22 @@ int visit_clock_decl_entry(struct ctx *ctx, struct ctf_node *entry_node,
                unsigned char uuid[BABELTRACE_UUID_LEN];
 
                if (_IS_SET(set, _CLOCK_UUID_SET)) {
-                       _BT_LOGE_DUP_ATTR("uuid", "clock class");
+                       _BT_LOGE_DUP_ATTR(entry_node, "uuid", "clock class");
                        ret = -EPERM;
                        goto error;
                }
 
                ret = get_unary_uuid(&entry_node->u.ctf_expression.right, uuid);
                if (ret) {
-                       BT_LOGE_STR("Invalid clock class's `uuid` attribute.");
+                       _BT_LOGE_NODE(entry_node,
+                               "Invalid clock class's `uuid` attribute.");
                        goto error;
                }
 
-               ret = bt_ctf_clock_class_set_uuid(clock, uuid);
+               ret = bt_clock_class_set_uuid(clock, uuid);
                if (ret) {
-                       BT_LOGE_STR("Cannot set clock class's UUID.");
+                       _BT_LOGE_NODE(entry_node,
+                               "Cannot set clock class's UUID.");
                        goto error;
                }
 
@@ -4318,7 +4847,8 @@ int visit_clock_decl_entry(struct ctx *ctx, struct ctf_node *entry_node,
                char *right;
 
                if (_IS_SET(set, _CLOCK_DESCRIPTION_SET)) {
-                       _BT_LOGE_DUP_ATTR("description", "clock class");
+                       _BT_LOGE_DUP_ATTR(entry_node, "description",
+                               "clock class");
                        ret = -EPERM;
                        goto error;
                }
@@ -4326,14 +4856,16 @@ int visit_clock_decl_entry(struct ctx *ctx, struct ctf_node *entry_node,
                right = concatenate_unary_strings(
                        &entry_node->u.ctf_expression.right);
                if (!right) {
-                       BT_LOGE_STR("Unexpected unary expression for clock class's `description` attribute.");
+                       _BT_LOGE_NODE(entry_node,
+                               "Unexpected unary expression for clock class's `description` attribute.");
                        ret = -EINVAL;
                        goto error;
                }
 
-               ret = bt_ctf_clock_class_set_description(clock, right);
+               ret = bt_clock_class_set_description(clock, right);
                if (ret) {
-                       BT_LOGE_STR("Cannot set clock class's description.");
+                       _BT_LOGE_NODE(entry_node,
+                               "Cannot set clock class's description.");
                        g_free(right);
                        goto error;
                }
@@ -4341,10 +4873,10 @@ int visit_clock_decl_entry(struct ctx *ctx, struct ctf_node *entry_node,
                g_free(right);
                _SET(set, _CLOCK_DESCRIPTION_SET);
        } else if (!strcmp(left, "freq")) {
-               uint64_t freq;
+               uint64_t freq = -1ULL;
 
                if (_IS_SET(set, _CLOCK_FREQ_SET)) {
-                       _BT_LOGE_DUP_ATTR("freq", "clock class");
+                       _BT_LOGE_DUP_ATTR(entry_node, "freq", "clock class");
                        ret = -EPERM;
                        goto error;
                }
@@ -4352,14 +4884,24 @@ int visit_clock_decl_entry(struct ctx *ctx, struct ctf_node *entry_node,
                ret = get_unary_unsigned(
                        &entry_node->u.ctf_expression.right, &freq);
                if (ret) {
-                       BT_LOGE_STR("Unexpected unary expression for clock class's `freq` attribute.");
+                       _BT_LOGE_NODE(entry_node,
+                               "Unexpected unary expression for clock class's `freq` attribute.");
+                       ret = -EINVAL;
+                       goto error;
+               }
+
+               if (freq == -1ULL || freq == 0) {
+                       _BT_LOGE_NODE(entry_node,
+                               "Invalid clock class frequency: freq=%" PRIu64,
+                               freq);
                        ret = -EINVAL;
                        goto error;
                }
 
-               ret = bt_ctf_clock_class_set_frequency(clock, freq);
+               ret = bt_clock_class_set_frequency(clock, freq);
                if (ret) {
-                       BT_LOGE_STR("Cannot set clock class's frequency.");
+                       _BT_LOGE_NODE(entry_node,
+                               "Cannot set clock class's frequency.");
                        goto error;
                }
 
@@ -4368,7 +4910,8 @@ int visit_clock_decl_entry(struct ctx *ctx, struct ctf_node *entry_node,
                uint64_t precision;
 
                if (_IS_SET(set, _CLOCK_PRECISION_SET)) {
-                       _BT_LOGE_DUP_ATTR("precision", "clock class");
+                       _BT_LOGE_DUP_ATTR(entry_node, "precision",
+                               "clock class");
                        ret = -EPERM;
                        goto error;
                }
@@ -4376,62 +4919,69 @@ int visit_clock_decl_entry(struct ctx *ctx, struct ctf_node *entry_node,
                ret = get_unary_unsigned(
                        &entry_node->u.ctf_expression.right, &precision);
                if (ret) {
-                       BT_LOGE_STR("Unexpected unary expression for clock class's `precision` attribute.");
+                       _BT_LOGE_NODE(entry_node,
+                               "Unexpected unary expression for clock class's `precision` attribute.");
                        ret = -EINVAL;
                        goto error;
                }
 
-               ret = bt_ctf_clock_class_set_precision(clock, precision);
+               ret = bt_clock_class_set_precision(clock, precision);
                if (ret) {
-                       BT_LOGE_STR("Cannot set clock class's precision.");
+                       _BT_LOGE_NODE(entry_node,
+                               "Cannot set clock class's precision.");
                        goto error;
                }
 
                _SET(set, _CLOCK_PRECISION_SET);
        } else if (!strcmp(left, "offset_s")) {
-               uint64_t offset_s;
+               int64_t offset_s;
 
                if (_IS_SET(set, _CLOCK_OFFSET_S_SET)) {
-                       _BT_LOGE_DUP_ATTR("offset_s", "clock class");
+                       _BT_LOGE_DUP_ATTR(entry_node, "offset_s",
+                               "clock class");
                        ret = -EPERM;
                        goto error;
                }
 
-               ret = get_unary_unsigned(
+               ret = get_unary_signed(
                        &entry_node->u.ctf_expression.right, &offset_s);
                if (ret) {
-                       BT_LOGE_STR("Unexpected unary expression for clock class's `offset_s` attribute.");
+                       _BT_LOGE_NODE(entry_node,
+                               "Unexpected unary expression for clock class's `offset_s` attribute.");
                        ret = -EINVAL;
                        goto error;
                }
 
-               ret = bt_ctf_clock_class_set_offset_s(clock, offset_s);
+               ret = bt_clock_class_set_offset_s(clock, offset_s);
                if (ret) {
-                       BT_LOGE_STR("Cannot set clock class's offset in seconds.");
+                       _BT_LOGE_NODE(entry_node,
+                               "Cannot set clock class's offset in seconds.");
                        goto error;
                }
 
                _SET(set, _CLOCK_OFFSET_S_SET);
        } else if (!strcmp(left, "offset")) {
-               uint64_t offset;
+               int64_t offset;
 
                if (_IS_SET(set, _CLOCK_OFFSET_SET)) {
-                       _BT_LOGE_DUP_ATTR("offset", "clock class");
+                       _BT_LOGE_DUP_ATTR(entry_node, "offset", "clock class");
                        ret = -EPERM;
                        goto error;
                }
 
-               ret = get_unary_unsigned(
+               ret = get_unary_signed(
                        &entry_node->u.ctf_expression.right, &offset);
                if (ret) {
-                       BT_LOGE_STR("Unexpected unary expression for clock class's `offset` attribute.");
+                       _BT_LOGE_NODE(entry_node,
+                               "Unexpected unary expression for clock class's `offset` attribute.");
                        ret = -EINVAL;
                        goto error;
                }
 
-               ret = bt_ctf_clock_class_set_offset_cycles(clock, offset);
+               ret = bt_clock_class_set_offset_cycles(clock, offset);
                if (ret) {
-                       BT_LOGE_STR("Cannot set clock class's offset in cycles.");
+                       _BT_LOGE_NODE(entry_node,
+                               "Cannot set clock class's offset in cycles.");
                        goto error;
                }
 
@@ -4440,7 +4990,8 @@ int visit_clock_decl_entry(struct ctx *ctx, struct ctf_node *entry_node,
                struct ctf_node *right;
 
                if (_IS_SET(set, _CLOCK_ABSOLUTE_SET)) {
-                       _BT_LOGE_DUP_ATTR("absolute", "clock class");
+                       _BT_LOGE_DUP_ATTR(entry_node, "absolute",
+                               "clock class");
                        ret = -EPERM;
                        goto error;
                }
@@ -4450,20 +5001,23 @@ int visit_clock_decl_entry(struct ctx *ctx, struct ctf_node *entry_node,
                        struct ctf_node, siblings);
                ret = get_boolean(right);
                if (ret < 0) {
-                       BT_LOGE_STR("Unexpected unary expression for clock class's `absolute` attribute.");
+                       _BT_LOGE_NODE(entry_node,
+                               "Unexpected unary expression for clock class's `absolute` attribute.");
                        ret = -EINVAL;
                        goto error;
                }
 
-               ret = bt_ctf_clock_class_set_is_absolute(clock, ret);
+               ret = bt_clock_class_set_is_absolute(clock, ret);
                if (ret) {
-                       BT_LOGE_STR("Cannot set clock class's absolute flag.");
+                       _BT_LOGE_NODE(entry_node,
+                               "Cannot set clock class's absolute flag.");
                        goto error;
                }
 
                _SET(set, _CLOCK_ABSOLUTE_SET);
        } else {
-               BT_LOGW("Unknown attribute in clock class: attr-name=\"%s\"",
+               _BT_LOGW_NODE(entry_node,
+                       "Unknown attribute in clock class: attr-name=\"%s\"",
                        left);
        }
 
@@ -4494,28 +5048,32 @@ int64_t cycles_from_ns(uint64_t frequency, int64_t ns)
 }
 
 static
-int apply_clock_class_offset(struct ctx *ctx, struct bt_ctf_clock_class *clock)
+int apply_clock_class_offset(struct ctx *ctx, struct bt_clock_class *clock)
 {
        int ret;
        uint64_t freq;
        int64_t offset_cycles;
+       int64_t offset_to_apply;
 
-       freq = bt_ctf_clock_class_get_frequency(clock);
+       freq = bt_clock_class_get_frequency(clock);
        if (freq == -1ULL) {
                BT_LOGE_STR("Cannot get clock class's frequency.");
                ret = -1;
                goto end;
        }
 
-       ret = bt_ctf_clock_class_get_offset_cycles(clock, &offset_cycles);
+       ret = bt_clock_class_get_offset_cycles(clock, &offset_cycles);
        if (ret) {
                BT_LOGE_STR("Cannot get clock class's offset in cycles.");
                ret = -1;
                goto end;
        }
 
-       offset_cycles += cycles_from_ns(freq, ctx->clock_class_offset_ns);
-       ret = bt_ctf_clock_class_set_offset_cycles(clock, offset_cycles);
+       offset_to_apply =
+               ctx->decoder_config.clock_class_offset_s * 1000000000LL +
+               ctx->decoder_config.clock_class_offset_ns;
+       offset_cycles += cycles_from_ns(freq, offset_to_apply);
+       ret = bt_clock_class_set_offset_cycles(clock, offset_cycles);
 
 end:
        return ret;
@@ -4526,7 +5084,7 @@ int visit_clock_decl(struct ctx *ctx, struct ctf_node *clock_node)
 {
        int ret = 0;
        int set = 0;
-       struct bt_ctf_clock_class *clock;
+       struct bt_clock_class *clock;
        struct ctf_node *entry_node;
        struct bt_list_head *decl_list = &clock_node->u.clock.declaration_list;
        const char *clock_class_name;
@@ -4536,9 +5094,12 @@ int visit_clock_decl(struct ctx *ctx, struct ctf_node *clock_node)
        }
 
        clock_node->visited = TRUE;
-       clock = bt_ctf_clock_class_create(NULL);
+
+       /* CTF 1.8's default frequency for a clock class is 1 GHz */
+       clock = bt_clock_class_create(NULL, 1000000000);
        if (!clock) {
-               BT_LOGE_STR("Cannot create default clock class.");
+               _BT_LOGE_NODE(clock_node,
+                       "Cannot create default clock class.");
                ret = -ENOMEM;
                goto error;
        }
@@ -4546,17 +5107,21 @@ int visit_clock_decl(struct ctx *ctx, struct ctf_node *clock_node)
        bt_list_for_each_entry(entry_node, decl_list, siblings) {
                ret = visit_clock_decl_entry(ctx, entry_node, clock, &set);
                if (ret) {
+                       _BT_LOGE_NODE(entry_node,
+                               "Cannot visit clock class's entry: ret=%d",
+                               ret);
                        goto error;
                }
        }
 
        if (!_IS_SET(&set, _CLOCK_NAME_SET)) {
-               BT_LOGE_STR("Missing `name` attribute in clock class.");
+               _BT_LOGE_NODE(clock_node,
+                       "Missing `name` attribute in clock class.");
                ret = -EPERM;
                goto error;
        }
 
-       clock_class_name = bt_ctf_clock_class_get_name(clock);
+       clock_class_name = bt_clock_class_get_name(clock);
        assert(clock_class_name);
        if (ctx->is_lttng && strcmp(clock_class_name, "monotonic") == 0) {
                /*
@@ -4565,22 +5130,25 @@ int visit_clock_decl(struct ctx *ctx, struct ctf_node *clock_node)
                 * it's a condition to be able to sort notifications
                 * from different sources.
                 */
-               ret = bt_ctf_clock_class_set_is_absolute(clock, 1);
+               ret = bt_clock_class_set_is_absolute(clock, 1);
                if (ret) {
-                       BT_LOGE_STR("Cannot set clock class's absolute flag.");
+                       _BT_LOGE_NODE(clock_node,
+                               "Cannot set clock class's absolute flag.");
                        goto error;
                }
        }
 
        ret = apply_clock_class_offset(ctx, clock);
        if (ret) {
-               BT_LOGE_STR("Cannot apply clock class's custom offset.");
+               _BT_LOGE_NODE(clock_node,
+                       "Cannot apply clock class's custom offset.");
                goto error;
        }
 
-       ret = bt_ctf_trace_add_clock_class(ctx->trace, clock);
+       ret = bt_trace_add_clock_class(ctx->trace, clock);
        if (ret) {
-               BT_LOGE_STR("Cannot add clock class to trace.");
+               _BT_LOGE_NODE(clock_node,
+                       "Cannot add clock class to trace.");
                goto error;
        }
 
@@ -4607,7 +5175,8 @@ int visit_root_decl(struct ctx *ctx, struct ctf_node *root_decl_node)
                        root_decl_node->u._typedef.type_specifier_list,
                        &root_decl_node->u._typedef.type_declarators);
                if (ret) {
-                       BT_LOGE_STR("Cannot add type definition found in root scope.");
+                       _BT_LOGE_NODE(root_decl_node,
+                               "Cannot add type definition found in root scope.");
                        goto end;
                }
                break;
@@ -4615,13 +5184,14 @@ int visit_root_decl(struct ctx *ctx, struct ctf_node *root_decl_node)
                ret = visit_typealias(ctx, root_decl_node->u.typealias.target,
                        root_decl_node->u.typealias.alias);
                if (ret) {
-                       BT_LOGE_STR("Cannot add type alias found in root scope.");
+                       _BT_LOGE_NODE(root_decl_node,
+                               "Cannot add type alias found in root scope.");
                        goto end;
                }
                break;
        case NODE_TYPE_SPECIFIER_LIST:
        {
-               _BT_CTF_FIELD_TYPE_INIT(decl);
+               _BT_FIELD_TYPE_INIT(decl);
 
                /*
                 * Just add the type specifier to the root
@@ -4629,6 +5199,9 @@ int visit_root_decl(struct ctx *ctx, struct ctf_node *root_decl_node)
                 */
                ret = visit_type_specifier_list(ctx, root_decl_node, &decl);
                if (ret) {
+                       _BT_LOGE_NODE(root_decl_node,
+                               "Cannot visit root scope's field type: "
+                               "ret=%d", ret);
                        assert(!decl);
                        goto end;
                }
@@ -4637,6 +5210,9 @@ int visit_root_decl(struct ctx *ctx, struct ctf_node *root_decl_node)
                break;
        }
        default:
+               _BT_LOGE_NODE(root_decl_node,
+                       "Unexpected node type: node-type=%d",
+                       root_decl_node->type);
                ret = -EPERM;
                goto end;
        }
@@ -4652,9 +5228,10 @@ int set_trace_name(struct ctx *ctx)
        int ret = 0;
        struct bt_value *value = NULL;
 
-       assert(bt_ctf_trace_get_stream_class_count(ctx->trace) == 0);
+       assert(bt_trace_get_stream_class_count(ctx->trace) == 0);
        name = g_string_new(NULL);
        if (!name) {
+               BT_LOGE_STR("Failed to allocate a GString.");
                ret = -1;
                goto end;
        }
@@ -4663,7 +5240,7 @@ int set_trace_name(struct ctx *ctx)
         * Check if we have a trace environment string value named `hostname`.
         * If so, use it as the trace name's prefix.
         */
-       value = bt_ctf_trace_get_environment_field_value_by_name(ctx->trace,
+       value = bt_trace_get_environment_field_value_by_name(ctx->trace,
                "hostname");
        if (bt_value_is_string(value)) {
                const char *hostname;
@@ -4681,8 +5258,9 @@ int set_trace_name(struct ctx *ctx)
                g_string_append(name, ctx->trace_name_suffix);
        }
 
-       ret = bt_ctf_trace_set_name(ctx->trace, name->str);
+       ret = bt_trace_set_name(ctx->trace, name->str);
        if (ret) {
+               BT_LOGE("Cannot set trace's name: name=\"%s\"", name->str);
                goto error;
        }
 
@@ -4709,7 +5287,7 @@ int move_ctx_stream_classes_to_trace(struct ctx *ctx)
        gpointer key, stream_class;
 
        if (g_hash_table_size(ctx->stream_classes) > 0 &&
-                       bt_ctf_trace_get_stream_class_count(ctx->trace) == 0) {
+                       bt_trace_get_stream_class_count(ctx->trace) == 0) {
                /*
                 * We're about to add the first stream class to the
                 * trace. This will freeze the trace, and after this
@@ -4718,6 +5296,7 @@ int move_ctx_stream_classes_to_trace(struct ctx *ctx)
                 */
                ret = set_trace_name(ctx);
                if (ret) {
+                       BT_LOGE_STR("Cannot set trace's name.");
                        goto end;
                }
        }
@@ -4725,10 +5304,10 @@ int move_ctx_stream_classes_to_trace(struct ctx *ctx)
        g_hash_table_iter_init(&iter, ctx->stream_classes);
 
        while (g_hash_table_iter_next(&iter, &key, &stream_class)) {
-               ret = bt_ctf_trace_add_stream_class(ctx->trace,
+               ret = bt_trace_add_stream_class(ctx->trace,
                        stream_class);
                if (ret) {
-                       int64_t id = bt_ctf_stream_class_get_id(stream_class);
+                       int64_t id = bt_stream_class_get_id(stream_class);
                        BT_LOGE("Cannot add stream class to trace: id=%" PRId64,
                                id);
                        goto end;
@@ -4743,27 +5322,28 @@ end:
 
 BT_HIDDEN
 struct ctf_visitor_generate_ir *ctf_visitor_generate_ir_create(
-               int64_t clock_class_offset_ns, const char *name)
+               const struct ctf_metadata_decoder_config *decoder_config,
+               const char *name)
 {
        int ret;
        struct ctx *ctx = NULL;
-       struct bt_ctf_trace *trace;
+       struct bt_trace *trace;
 
-       trace = bt_ctf_trace_create();
+       trace = bt_trace_create();
        if (!trace) {
                BT_LOGE_STR("Cannot create empty trace.");
                goto error;
        }
 
        /* Set packet header to NULL to override the default one */
-       ret = bt_ctf_trace_set_packet_header_type(trace, NULL);
+       ret = bt_trace_set_packet_header_type(trace, NULL);
        if (ret) {
                BT_LOGE_STR("Cannot reset initial trace's packet header field type.");
                goto error;
        }
 
        /* Create visitor's context */
-       ctx = ctx_create(trace, clock_class_offset_ns, name);
+       ctx = ctx_create(trace, decoder_config, name);
        if (!ctx) {
                BT_LOGE_STR("Cannot create visitor's context.");
                goto error;
@@ -4788,7 +5368,7 @@ void ctf_visitor_generate_ir_destroy(struct ctf_visitor_generate_ir *visitor)
 }
 
 BT_HIDDEN
-struct bt_ctf_trace *ctf_visitor_generate_ir_get_trace(
+struct bt_trace *ctf_visitor_generate_ir_get_trace(
                struct ctf_visitor_generate_ir *visitor)
 {
        struct ctx *ctx = (void *) visitor;
@@ -4812,7 +5392,6 @@ int ctf_visitor_generate_ir_visit_node(struct ctf_visitor_generate_ir *visitor,
        {
                struct ctf_node *iter;
                int got_trace_decl = FALSE;
-               int found_callsite = FALSE;
 
                /*
                 * The first thing we need is the native byte order of
@@ -4821,17 +5400,19 @@ int ctf_visitor_generate_ir_visit_node(struct ctf_visitor_generate_ir *visitor,
                 * have the native byte order yet, and we don't have any
                 * trace block yet, then fail with EINCOMPLETE.
                 */
-               if (ctx->trace_bo == BT_CTF_BYTE_ORDER_NATIVE) {
+               if (ctx->trace_bo == BT_BYTE_ORDER_NATIVE) {
                        bt_list_for_each_entry(iter, &node->u.root.trace, siblings) {
                                if (got_trace_decl) {
-                                       BT_LOGE_STR("Duplicate trace (`trace` block).");
+                                       _BT_LOGE_NODE(node,
+                                               "Duplicate trace (`trace` block).");
                                        ret = -1;
                                        goto end;
                                }
 
                                ret = set_trace_byte_order(ctx, iter);
                                if (ret) {
-                                       BT_LOGE("Cannot set trace's native byte order: "
+                                       _BT_LOGE_NODE(node,
+                                               "Cannot set trace's native byte order: "
                                                "ret=%d", ret);
                                        goto end;
                                }
@@ -4840,13 +5421,14 @@ int ctf_visitor_generate_ir_visit_node(struct ctf_visitor_generate_ir *visitor,
                        }
 
                        if (!got_trace_decl) {
+                               BT_LOGD_STR("Incomplete AST: need trace (`trace` block).");
                                ret = -EINCOMPLETE;
                                goto end;
                        }
                }
 
-               assert(ctx->trace_bo == BT_CTF_BYTE_ORDER_LITTLE_ENDIAN ||
-                       ctx->trace_bo == BT_CTF_BYTE_ORDER_BIG_ENDIAN);
+               assert(ctx->trace_bo == BT_BYTE_ORDER_LITTLE_ENDIAN ||
+                       ctx->trace_bo == BT_BYTE_ORDER_BIG_ENDIAN);
                assert(ctx->current_scope &&
                        ctx->current_scope->parent_scope == NULL);
 
@@ -4854,7 +5436,8 @@ int ctf_visitor_generate_ir_visit_node(struct ctf_visitor_generate_ir *visitor,
                bt_list_for_each_entry(iter, &node->u.root.env, siblings) {
                        ret = visit_env(ctx, iter);
                        if (ret) {
-                               BT_LOGE("Cannot visit trace's environment (`env` block): "
+                               _BT_LOGE_NODE(iter,
+                                       "Cannot visit trace's environment (`env` block) entry: "
                                        "ret=%d", ret);
                                goto end;
                        }
@@ -4869,7 +5452,8 @@ int ctf_visitor_generate_ir_visit_node(struct ctf_visitor_generate_ir *visitor,
                bt_list_for_each_entry(iter, &node->u.root.clock, siblings) {
                        ret = visit_clock_decl(ctx, iter);
                        if (ret) {
-                               BT_LOGE("Cannot visit clock class: ret=%d",
+                               _BT_LOGE_NODE(iter,
+                                       "Cannot visit clock class: ret=%d",
                                        ret);
                                goto end;
                        }
@@ -4886,7 +5470,8 @@ int ctf_visitor_generate_ir_visit_node(struct ctf_visitor_generate_ir *visitor,
                                siblings) {
                        ret = visit_root_decl(ctx, iter);
                        if (ret) {
-                               BT_LOGE("Cannot visit root entry: ret=%d",
+                               _BT_LOGE_NODE(iter,
+                                       "Cannot visit root entry: ret=%d",
                                        ret);
                                goto end;
                        }
@@ -4897,22 +5482,19 @@ int ctf_visitor_generate_ir_visit_node(struct ctf_visitor_generate_ir *visitor,
 
                /* Callsite blocks are not supported */
                bt_list_for_each_entry(iter, &node->u.root.callsite, siblings) {
-                       found_callsite = TRUE;
-                       break;
+                       _BT_LOGW_NODE(iter,
+                               "\"callsite\" blocks are not supported as of this version.");
                }
 
                assert(ctx->current_scope &&
                        ctx->current_scope->parent_scope == NULL);
 
-               if (found_callsite) {
-                       BT_LOGW("\"callsite\" blocks are not supported as of this version.");
-               }
-
                /* Trace */
                bt_list_for_each_entry(iter, &node->u.root.trace, siblings) {
                        ret = visit_trace_decl(ctx, iter);
                        if (ret) {
-                               BT_LOGE("Cannot visit trace (`trace` block): "
+                               _BT_LOGE_NODE(iter,
+                                       "Cannot visit trace (`trace` block): "
                                        "ret=%d", ret);
                                goto end;
                        }
@@ -4925,7 +5507,8 @@ int ctf_visitor_generate_ir_visit_node(struct ctf_visitor_generate_ir *visitor,
                bt_list_for_each_entry(iter, &node->u.root.stream, siblings) {
                        ret = visit_stream_decl(ctx, iter);
                        if (ret) {
-                               BT_LOGE("Cannot visit stream class: ret=%d",
+                               _BT_LOGE_NODE(iter,
+                                       "Cannot visit stream class: ret=%d",
                                        ret);
                                goto end;
                        }
@@ -4938,7 +5521,8 @@ int ctf_visitor_generate_ir_visit_node(struct ctf_visitor_generate_ir *visitor,
                bt_list_for_each_entry(iter, &node->u.root.event, siblings) {
                        ret = visit_event_decl(ctx, iter);
                        if (ret) {
-                               BT_LOGE("Cannot visit event class: ret=%d",
+                               _BT_LOGE_NODE(iter,
+                                       "Cannot visit event class: ret=%d",
                                        ret);
                                goto end;
                        }
@@ -4949,7 +5533,8 @@ int ctf_visitor_generate_ir_visit_node(struct ctf_visitor_generate_ir *visitor,
                break;
        }
        default:
-               BT_LOGE("Unexpected node type: node-type=%d",
+               _BT_LOGE_NODE(node,
+                       "Unexpected node type: node-type=%d",
                        node->type);
                ret = -EINVAL;
                goto end;
This page took 0.084448 seconds and 4 git commands to generate.