X-Git-Url: http://git.liburcu.org/?a=blobdiff_plain;f=liblttng-ust%2Flttng-bytecode-specialize.c;h=31bc3d05f6d043072854415cdeebe3736353664b;hb=4e48b5d;hp=ee65ff3be259b59bf1da7b1c7e3359700ec981ed;hpb=362a65de6aba2cbc27c61c9fc23e755cb617837f;p=lttng-ust.git diff --git a/liblttng-ust/lttng-bytecode-specialize.c b/liblttng-ust/lttng-bytecode-specialize.c index ee65ff3b..31bc3d05 100644 --- a/liblttng-ust/lttng-bytecode-specialize.c +++ b/liblttng-ust/lttng-bytecode-specialize.c @@ -7,14 +7,16 @@ */ #define _LGPL_SOURCE +#include #include #include -#include +#include #include "context-internal.h" #include "lttng-bytecode.h" #include "ust-events-internal.h" +#include "ust-helper.h" static int lttng_fls(int val) { @@ -252,24 +254,20 @@ static int specialize_get_index(struct bytecode_runtime *runtime, switch (stack_top->load.object_type) { case OBJECT_TYPE_ARRAY: { - const struct lttng_integer_type *integer_type; - const struct lttng_event_field *field; + const struct lttng_ust_type_integer *integer_type; + const struct lttng_ust_event_field *field; uint32_t elem_len, num_elems; int signedness; field = stack_top->load.field; - switch (field->type.atype) { - case atype_array: - integer_type = &field->type.u.legacy.array.elem_type.u.basic.integer; - num_elems = field->type.u.legacy.array.length; - break; - case atype_array_nestable: - if (field->type.u.array_nestable.elem_type->atype != atype_integer) { + switch (field->type->type) { + case lttng_ust_type_array: + if (lttng_ust_get_type_array(field->type)->elem_type->type != lttng_ust_type_integer) { ret = -EINVAL; goto end; } - integer_type = &field->type.u.array_nestable.elem_type->u.integer; - num_elems = field->type.u.array_nestable.length; + integer_type = lttng_ust_get_type_integer(lttng_ust_get_type_array(field->type)->elem_type); + num_elems = lttng_ust_get_type_array(field->type)->length; break; default: ret = -EINVAL; @@ -296,22 +294,19 @@ static int specialize_get_index(struct bytecode_runtime *runtime, } case OBJECT_TYPE_SEQUENCE: { - const struct lttng_integer_type *integer_type; - const struct lttng_event_field *field; + const struct lttng_ust_type_integer *integer_type; + const struct lttng_ust_event_field *field; uint32_t elem_len; int signedness; field = stack_top->load.field; - switch (field->type.atype) { - case atype_sequence: - integer_type = &field->type.u.legacy.sequence.elem_type.u.basic.integer; - break; - case atype_sequence_nestable: - if (field->type.u.sequence_nestable.elem_type->atype != atype_integer) { + switch (field->type->type) { + case lttng_ust_type_sequence: + if (lttng_ust_get_type_sequence(field->type)->elem_type->type != lttng_ust_type_integer) { ret = -EINVAL; goto end; } - integer_type = &field->type.u.sequence_nestable.elem_type->u.integer; + integer_type = lttng_ust_get_type_integer(lttng_ust_get_type_sequence(field->type)->elem_type); break; default: ret = -EINVAL; @@ -372,7 +367,7 @@ end: return ret; } -static int specialize_context_lookup_name(struct lttng_ctx *ctx, +static int specialize_context_lookup_name(struct lttng_ust_ctx *ctx, struct bytecode_runtime *bytecode, struct load_op *insn) { @@ -380,33 +375,28 @@ static int specialize_context_lookup_name(struct lttng_ctx *ctx, const char *name; offset = ((struct get_symbol *) insn->data)->offset; - name = bytecode->p.priv->bc->bc.data + bytecode->p.priv->bc->bc.reloc_offset + offset; + name = bytecode->p.bc->bc.data + bytecode->p.bc->bc.reloc_offset + offset; return lttng_get_context_index(ctx, name); } -static int specialize_load_object(const struct lttng_event_field *field, +static int specialize_load_object(const struct lttng_ust_event_field *field, struct vstack_load *load, bool is_context) { load->type = LOAD_OBJECT; - switch (field->type.atype) { - case atype_integer: - if (field->type.u.integer.signedness) + switch (field->type->type) { + case lttng_ust_type_integer: + if (lttng_ust_get_type_integer(field->type)->signedness) load->object_type = OBJECT_TYPE_S64; else load->object_type = OBJECT_TYPE_U64; load->rev_bo = false; break; - case atype_enum: - case atype_enum_nestable: + case lttng_ust_type_enum: { - const struct lttng_integer_type *itype; + const struct lttng_ust_type_integer *itype; - if (field->type.atype == atype_enum) { - itype = &field->type.u.legacy.basic.enumeration.container_type; - } else { - itype = &field->type.u.enum_nestable.container_type->u.integer; - } + itype = lttng_ust_get_type_integer(lttng_ust_get_type_enum(field->type)->container_type); if (itype->signedness) load->object_type = OBJECT_TYPE_SIGNED_ENUM; else @@ -414,15 +404,15 @@ static int specialize_load_object(const struct lttng_event_field *field, load->rev_bo = false; break; } - case atype_array: - if (field->type.u.legacy.array.elem_type.atype != atype_integer) { + case lttng_ust_type_array: + if (lttng_ust_get_type_array(field->type)->elem_type->type != lttng_ust_type_integer) { ERR("Array nesting only supports integer types."); return -EINVAL; } if (is_context) { load->object_type = OBJECT_TYPE_STRING; } else { - if (field->type.u.legacy.array.elem_type.u.basic.integer.encoding == lttng_encode_none) { + if (lttng_ust_get_type_array(field->type)->encoding == lttng_ust_string_encoding_none) { load->object_type = OBJECT_TYPE_ARRAY; load->field = field; } else { @@ -430,47 +420,15 @@ static int specialize_load_object(const struct lttng_event_field *field, } } break; - case atype_array_nestable: - if (field->type.u.array_nestable.elem_type->atype != atype_integer) { - ERR("Array nesting only supports integer types."); - return -EINVAL; - } - if (is_context) { - load->object_type = OBJECT_TYPE_STRING; - } else { - if (field->type.u.array_nestable.elem_type->u.integer.encoding == lttng_encode_none) { - load->object_type = OBJECT_TYPE_ARRAY; - load->field = field; - } else { - load->object_type = OBJECT_TYPE_STRING_SEQUENCE; - } - } - break; - case atype_sequence: - if (field->type.u.legacy.sequence.elem_type.atype != atype_integer) { + case lttng_ust_type_sequence: + if (lttng_ust_get_type_sequence(field->type)->elem_type->type != lttng_ust_type_integer) { ERR("Sequence nesting only supports integer types."); return -EINVAL; } if (is_context) { load->object_type = OBJECT_TYPE_STRING; } else { - if (field->type.u.legacy.sequence.elem_type.u.basic.integer.encoding == lttng_encode_none) { - load->object_type = OBJECT_TYPE_SEQUENCE; - load->field = field; - } else { - load->object_type = OBJECT_TYPE_STRING_SEQUENCE; - } - } - break; - case atype_sequence_nestable: - if (field->type.u.sequence_nestable.elem_type->atype != atype_integer) { - ERR("Sequence nesting only supports integer types."); - return -EINVAL; - } - if (is_context) { - load->object_type = OBJECT_TYPE_STRING; - } else { - if (field->type.u.sequence_nestable.elem_type->u.integer.encoding == lttng_encode_none) { + if (lttng_ust_get_type_sequence(field->type)->encoding == lttng_ust_string_encoding_none) { load->object_type = OBJECT_TYPE_SEQUENCE; load->field = field; } else { @@ -479,33 +437,30 @@ static int specialize_load_object(const struct lttng_event_field *field, } break; - case atype_string: + case lttng_ust_type_string: load->object_type = OBJECT_TYPE_STRING; break; - case atype_float: + case lttng_ust_type_float: load->object_type = OBJECT_TYPE_DOUBLE; break; - case atype_dynamic: + case lttng_ust_type_dynamic: load->object_type = OBJECT_TYPE_DYNAMIC; break; - case atype_struct: - ERR("Structure type cannot be loaded."); - return -EINVAL; default: - ERR("Unknown type: %d", (int) field->type.atype); + ERR("Unknown type: %d", (int) field->type->type); return -EINVAL; } return 0; } -static int specialize_context_lookup(struct lttng_ctx *ctx, +static int specialize_context_lookup(struct lttng_ust_ctx *ctx, struct bytecode_runtime *runtime, struct load_op *insn, struct vstack_load *load) { int idx, ret; - struct lttng_ctx_field *ctx_field; - struct lttng_event_field *field; + const struct lttng_ust_ctx_field *ctx_field; + const struct lttng_ust_event_field *field; struct bytecode_get_index_data gid; ssize_t data_offset; @@ -514,7 +469,7 @@ static int specialize_context_lookup(struct lttng_ctx *ctx, return -ENOENT; } ctx_field = &ctx->fields[idx]; - field = &ctx_field->event_field; + field = ctx_field->event_field; ret = specialize_load_object(field, load, true); if (ret) return ret; @@ -534,7 +489,7 @@ static int specialize_context_lookup(struct lttng_ctx *ctx, return 0; } -static int specialize_app_context_lookup(struct lttng_ctx **pctx, +static int specialize_app_context_lookup(struct lttng_ust_ctx **pctx, struct bytecode_runtime *runtime, struct load_op *insn, struct vstack_load *load) @@ -543,13 +498,13 @@ static int specialize_app_context_lookup(struct lttng_ctx **pctx, const char *orig_name; char *name = NULL; int idx, ret; - struct lttng_ctx_field *ctx_field; - struct lttng_event_field *field; + const struct lttng_ust_ctx_field *ctx_field; + const struct lttng_ust_event_field *field; struct bytecode_get_index_data gid; ssize_t data_offset; offset = ((struct get_symbol *) insn->data)->offset; - orig_name = runtime->p.priv->bc->bc.data + runtime->p.priv->bc->bc.reloc_offset + offset; + orig_name = runtime->p.bc->bc.data + runtime->p.bc->bc.reloc_offset + offset; name = zmalloc(strlen(orig_name) + strlen("$app.") + 1); if (!name) { ret = -ENOMEM; @@ -569,7 +524,7 @@ static int specialize_app_context_lookup(struct lttng_ctx **pctx, return -ENOENT; } ctx_field = &(*pctx)->fields[idx]; - field = &ctx_field->event_field; + field = ctx_field->event_field; ret = specialize_load_object(field, load, true); if (ret) goto end; @@ -593,7 +548,7 @@ end: return ret; } -static int specialize_payload_lookup(const struct lttng_event_desc *event_desc, +static int specialize_payload_lookup(const struct lttng_ust_event_desc *event_desc, struct bytecode_runtime *runtime, struct load_op *insn, struct vstack_load *load) @@ -603,17 +558,17 @@ static int specialize_payload_lookup(const struct lttng_event_desc *event_desc, unsigned int i, nr_fields; bool found = false; uint32_t field_offset = 0; - const struct lttng_event_field *field; + const struct lttng_ust_event_field *field; int ret; struct bytecode_get_index_data gid; ssize_t data_offset; nr_fields = event_desc->nr_fields; offset = ((struct get_symbol *) insn->data)->offset; - name = runtime->p.priv->bc->bc.data + runtime->p.priv->bc->bc.reloc_offset + offset; + name = runtime->p.bc->bc.data + runtime->p.bc->bc.reloc_offset + offset; for (i = 0; i < nr_fields; i++) { - field = &event_desc->fields[i]; - if (field->u.ext.nofilter) { + field = event_desc->fields[i]; + if (field->nofilter) { continue; } if (!strcmp(field->name, name)) { @@ -621,23 +576,20 @@ static int specialize_payload_lookup(const struct lttng_event_desc *event_desc, break; } /* compute field offset on stack */ - switch (field->type.atype) { - case atype_integer: - case atype_enum: - case atype_enum_nestable: + switch (field->type->type) { + case lttng_ust_type_integer: + case lttng_ust_type_enum: field_offset += sizeof(int64_t); break; - case atype_array: - case atype_array_nestable: - case atype_sequence: - case atype_sequence_nestable: + case lttng_ust_type_array: + case lttng_ust_type_sequence: field_offset += sizeof(unsigned long); field_offset += sizeof(void *); break; - case atype_string: + case lttng_ust_type_string: field_offset += sizeof(void *); break; - case atype_float: + case lttng_ust_type_float: field_offset += sizeof(double); break; default: @@ -673,14 +625,14 @@ end: return ret; } -int lttng_bytecode_specialize(const struct lttng_event_desc *event_desc, +int lttng_bytecode_specialize(const struct lttng_ust_event_desc *event_desc, struct bytecode_runtime *bytecode) { void *pc, *next_pc, *start_pc; int ret = -EINVAL; struct vstack _stack; struct vstack *stack = &_stack; - struct lttng_ctx **pctx = bytecode->p.priv->pctx; + struct lttng_ust_ctx **pctx = bytecode->p.pctx; vstack_init(stack);