From: Francis Deslauriers Date: Wed, 13 May 2020 15:42:09 +0000 (-0400) Subject: bytecode: Add `OBJECT_TYPE_{UN,}SIGNED_ENUM` type X-Git-Tag: v2.13.0-rc1~91 X-Git-Url: http://git.lttng.org/?p=lttng-modules.git;a=commitdiff_plain;h=29a574c31cacca0367653c8a197c9ef519f89203 bytecode: Add `OBJECT_TYPE_{UN,}SIGNED_ENUM` type Enumerations are currently converted to their integer counterparts as soon as they are encountered. In order to use them in captures, we need to differentiate the enumerations from integers for the entirety of the interpretation. This commit adds the `OBJECT_TYPE_SIGNED_ENUM` and `OBJECT_TYPE_UNSIGNED_ENUM` to keep track of these objects Signed-off-by: Francis Deslauriers Signed-off-by: Mathieu Desnoyers Change-Id: Ic0ab518588d7250190e42576d9baba2e8d8ce94a --- diff --git a/include/lttng/lttng-bytecode.h b/include/lttng/lttng-bytecode.h index 79a562bf..3a11e230 100644 --- a/include/lttng/lttng-bytecode.h +++ b/include/lttng/lttng-bytecode.h @@ -71,6 +71,9 @@ enum object_type { OBJECT_TYPE_U32, OBJECT_TYPE_U64, + OBJECT_TYPE_SIGNED_ENUM, + OBJECT_TYPE_UNSIGNED_ENUM, + OBJECT_TYPE_DOUBLE, OBJECT_TYPE_STRING, OBJECT_TYPE_STRING_SEQUENCE, diff --git a/src/lttng-bytecode-interpreter.c b/src/lttng-bytecode-interpreter.c index 950c0ba0..8252cdf1 100644 --- a/src/lttng-bytecode-interpreter.c +++ b/src/lttng-bytecode-interpreter.c @@ -298,11 +298,11 @@ static int context_get_index(struct lttng_probe_ctx *lttng_probe_ctx, ctx_field->get_value(ctx_field, lttng_probe_ctx, &v); if (itype->signedness) { - ptr->object_type = OBJECT_TYPE_S64; + ptr->object_type = OBJECT_TYPE_SIGNED_ENUM; ptr->u.s64 = v.s64; ptr->ptr = &ptr->u.s64; } else { - ptr->object_type = OBJECT_TYPE_U64; + ptr->object_type = OBJECT_TYPE_UNSIGNED_ENUM; ptr->u.u64 = v.s64; /* Cast. */ ptr->ptr = &ptr->u.u64; } @@ -496,6 +496,18 @@ static int dynamic_load_field(struct estack_entry *stack_top) stack_top->type = REG_S64; break; } + case OBJECT_TYPE_SIGNED_ENUM: + { + int64_t tmp; + + dbg_printk("op load field signed enumeration\n"); + tmp = *(int64_t *) stack_top->u.ptr.ptr; + if (stack_top->u.ptr.rev_bo) + __swab64s(&tmp); + stack_top->u.v = tmp; + stack_top->type = REG_S64; + break; + } case OBJECT_TYPE_U8: dbg_printk("op load field u8\n"); stack_top->u.v = *(uint8_t *) stack_top->u.ptr.ptr; @@ -537,6 +549,18 @@ static int dynamic_load_field(struct estack_entry *stack_top) stack_top->type = REG_U64; break; } + case OBJECT_TYPE_UNSIGNED_ENUM: + { + uint64_t tmp; + + dbg_printk("op load field unsigned enumeration\n"); + tmp = *(uint64_t *) stack_top->u.ptr.ptr; + if (stack_top->u.ptr.rev_bo) + __swab64s(&tmp); + stack_top->u.v = tmp; + stack_top->type = REG_U64; + break; + } case OBJECT_TYPE_STRING: { const char *str; @@ -649,6 +673,20 @@ again: output->u.sequence.nr_elem = ax->u.ptr.field->type.u.array_nestable.length; output->u.sequence.nested_type = ax->u.ptr.field->type.u.array_nestable.elem_type; break; + case OBJECT_TYPE_SIGNED_ENUM: + ret = dynamic_load_field(ax); + if (ret) + return ret; + output->type = LTTNG_INTERPRETER_TYPE_SIGNED_ENUM; + output->u.s = ax->u.v; + break; + case OBJECT_TYPE_UNSIGNED_ENUM: + ret = dynamic_load_field(ax); + if (ret) + return ret; + output->type = LTTNG_INTERPRETER_TYPE_UNSIGNED_ENUM; + output->u.u = ax->u.v; + break; case OBJECT_TYPE_STRUCT: case OBJECT_TYPE_VARIANT: default: diff --git a/src/lttng-bytecode-specialize.c b/src/lttng-bytecode-specialize.c index 83ba6f55..1ad577a3 100644 --- a/src/lttng-bytecode-specialize.c +++ b/src/lttng-bytecode-specialize.c @@ -95,6 +95,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_printk("op load field signed enumeration\n"); + stack_top->type = REG_PTR; + break; case OBJECT_TYPE_U8: dbg_printk("op load field u8\n"); stack_top->type = REG_S64; @@ -118,6 +122,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_printk("op load field unsigned enumeration\n"); + stack_top->type = REG_PTR; + break; case OBJECT_TYPE_DOUBLE: printk(KERN_WARNING "LTTng: bytecode: Double type unsupported\n\n"); ret = -EINVAL; @@ -328,9 +336,9 @@ static int specialize_load_object(const struct lttng_event_field *field, &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; }