X-Git-Url: http://git.lttng.org./?a=blobdiff_plain;ds=sidebyside;f=liblttng-ust%2Flttng-bytecode-specialize.c;h=c546c8d6dc411688943e8804128721ef69325fc1;hb=daacdbfc04fe07ecff0a0d1878b4f48d38912c78;hp=55b2ebf221687be36d8c4f306b8e85b8a2cbd70c;hpb=04aa13f8c2944839f6514e3841b93057b443a783;p=lttng-ust.git diff --git a/liblttng-ust/lttng-bytecode-specialize.c b/liblttng-ust/lttng-bytecode-specialize.c index 55b2ebf2..c546c8d6 100644 --- a/liblttng-ust/lttng-bytecode-specialize.c +++ b/liblttng-ust/lttng-bytecode-specialize.c @@ -1,36 +1,21 @@ /* - * lttng-bytecode-specialize.c - * - * LTTng UST bytecode specializer. + * SPDX-License-Identifier: MIT * * Copyright (C) 2010-2016 Mathieu Desnoyers * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. + * LTTng UST bytecode specializer. */ #define _LGPL_SOURCE #include #include -#include "lttng-bytecode.h" #include + +#include "context-internal.h" +#include "lttng-bytecode.h" #include "ust-events-internal.h" +#include "ust-helper.h" static int lttng_fls(int val) { @@ -155,6 +140,10 @@ static int specialize_load_field(struct vstack_entry *stack_top, if (!stack_top->load.rev_bo) insn->op = BYTECODE_OP_LOAD_FIELD_S64; break; + case OBJECT_TYPE_SIGNED_ENUM: + dbg_printf("op load field signed enumeration\n"); + stack_top->type = REG_PTR; + break; case OBJECT_TYPE_U8: dbg_printf("op load field u8\n"); stack_top->type = REG_U64; @@ -178,6 +167,10 @@ static int specialize_load_field(struct vstack_entry *stack_top, if (!stack_top->load.rev_bo) insn->op = BYTECODE_OP_LOAD_FIELD_U64; break; + case OBJECT_TYPE_UNSIGNED_ENUM: + dbg_printf("op load field unsigned enumeration\n"); + stack_top->type = REG_PTR; + break; case OBJECT_TYPE_DOUBLE: stack_top->type = REG_DOUBLE; insn->op = BYTECODE_OP_LOAD_FIELD_DOUBLE; @@ -261,16 +254,12 @@ static int specialize_get_index(struct bytecode_runtime *runtime, case OBJECT_TYPE_ARRAY: { const struct lttng_integer_type *integer_type; - const struct lttng_event_field *field; + 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) { ret = -EINVAL; @@ -305,15 +294,12 @@ 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_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) { ret = -EINVAL; @@ -380,7 +366,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) { @@ -388,11 +374,11 @@ static int specialize_context_lookup_name(struct lttng_ctx *ctx, const char *name; offset = ((struct get_symbol *) insn->data)->offset; - name = bytecode->p.bc->bc.data + bytecode->p.bc->bc.reloc_offset + offset; + name = bytecode->p.priv->bc->bc.data + bytecode->p.priv->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; @@ -405,39 +391,18 @@ static int specialize_load_object(const struct lttng_event_field *field, load->object_type = OBJECT_TYPE_U64; load->rev_bo = false; break; - case atype_enum: case atype_enum_nestable: { const struct lttng_integer_type *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 = &field->type.u.enum_nestable.container_type->u.integer; if (itype->signedness) - load->object_type = OBJECT_TYPE_S64; + load->object_type = OBJECT_TYPE_SIGNED_ENUM; else - load->object_type = OBJECT_TYPE_U64; + load->object_type = OBJECT_TYPE_UNSIGNED_ENUM; load->rev_bo = false; break; } - case atype_array: - if (field->type.u.legacy.array.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.legacy.array.elem_type.u.basic.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_array_nestable: if (field->type.u.array_nestable.elem_type->atype != atype_integer) { ERR("Array nesting only supports integer types."); @@ -454,22 +419,6 @@ static int specialize_load_object(const struct lttng_event_field *field, } } break; - case atype_sequence: - if (field->type.u.legacy.sequence.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.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."); @@ -496,9 +445,6 @@ static int specialize_load_object(const struct lttng_event_field *field, case atype_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); return -EINVAL; @@ -506,14 +452,14 @@ static int specialize_load_object(const struct lttng_event_field *field, 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; + struct lttng_ust_ctx_field *ctx_field; + struct lttng_ust_event_field *field; struct bytecode_get_index_data gid; ssize_t data_offset; @@ -521,8 +467,8 @@ static int specialize_context_lookup(struct lttng_ctx *ctx, if (idx < 0) { return -ENOENT; } - ctx_field = &ctx->fields[idx]; - field = &ctx_field->event_field; + ctx_field = ctx->fields[idx]; + field = ctx_field->event_field; ret = specialize_load_object(field, load, true); if (ret) return ret; @@ -542,7 +488,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) @@ -551,13 +497,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; + struct lttng_ust_ctx_field *ctx_field; + 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.bc->bc.data + runtime->p.bc->bc.reloc_offset + offset; + orig_name = runtime->p.priv->bc->bc.data + runtime->p.priv->bc->bc.reloc_offset + offset; name = zmalloc(strlen(orig_name) + strlen("$app.") + 1); if (!name) { ret = -ENOMEM; @@ -576,8 +522,8 @@ static int specialize_app_context_lookup(struct lttng_ctx **pctx, if (idx < 0) return -ENOENT; } - ctx_field = &(*pctx)->fields[idx]; - field = &ctx_field->event_field; + ctx_field = (*pctx)->fields[idx]; + field = ctx_field->event_field; ret = specialize_load_object(field, load, true); if (ret) goto end; @@ -601,7 +547,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) @@ -611,17 +557,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.bc->bc.data + runtime->p.bc->bc.reloc_offset + offset; + name = runtime->p.priv->bc->bc.data + runtime->p.priv->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)) { @@ -631,13 +577,10 @@ static int specialize_payload_lookup(const struct lttng_event_desc *event_desc, /* compute field offset on stack */ switch (field->type.atype) { case atype_integer: - case atype_enum: case atype_enum_nestable: field_offset += sizeof(int64_t); break; - case atype_array: case atype_array_nestable: - case atype_sequence: case atype_sequence_nestable: field_offset += sizeof(unsigned long); field_offset += sizeof(void *); @@ -681,14 +624,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.pctx; + struct lttng_ust_ctx **pctx = bytecode->p.priv->pctx; vstack_init(stack);