From: Francis Deslauriers Date: Thu, 7 May 2020 20:41:18 +0000 (-0400) Subject: bytecode: Add `OBJECT_TYPE_{UN,}SIGNED_ENUM` type X-Git-Tag: v2.13.0-rc1~435 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=70f9f7f95a5a36231e4a71191bcd88d582c3ca81;p=lttng-ust.git 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: I4b3ec8187a578ddc6c9d87f72d462441ba5e4a1e --- diff --git a/liblttng-ust/lttng-bytecode-interpreter.c b/liblttng-ust/lttng-bytecode-interpreter.c index 9d7258f7..9a2aaa45 100644 --- a/liblttng-ust/lttng-bytecode-interpreter.c +++ b/liblttng-ust/lttng-bytecode-interpreter.c @@ -267,11 +267,11 @@ static int context_get_index(struct lttng_ctx *ctx, } ctx_field->get_value(ctx_field, &v); if (itype->signedness) { - ptr->object_type = OBJECT_TYPE_S64; + ptr->object_type = OBJECT_TYPE_SIGNED_ENUM; ptr->u.s64 = v.u.s64; ptr->ptr = &ptr->u.s64; } else { - ptr->object_type = OBJECT_TYPE_U64; + ptr->object_type = OBJECT_TYPE_UNSIGNED_ENUM; ptr->u.u64 = v.u.s64; /* Cast. */ ptr->ptr = &ptr->u.u64; } @@ -523,6 +523,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_printf("op load field signed enumeration\n"); + tmp = *(int64_t *) stack_top->u.ptr.ptr; + if (stack_top->u.ptr.rev_bo) + tmp = bswap_64(tmp); + stack_top->u.v = tmp; + stack_top->type = REG_S64; + break; + } case OBJECT_TYPE_U8: dbg_printf("op load field u8\n"); stack_top->u.v = *(uint8_t *) stack_top->u.ptr.ptr; @@ -564,6 +576,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_printf("op load field unsigned enumeration\n"); + tmp = *(uint64_t *) stack_top->u.ptr.ptr; + if (stack_top->u.ptr.rev_bo) + tmp = bswap_64(tmp); + stack_top->u.v = tmp; + stack_top->type = REG_U64; + break; + } case OBJECT_TYPE_DOUBLE: memcpy(&stack_top->u.d, stack_top->u.ptr.ptr, @@ -683,6 +707,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/liblttng-ust/lttng-bytecode-specialize.c b/liblttng-ust/lttng-bytecode-specialize.c index 55b2ebf2..15a45b93 100644 --- a/liblttng-ust/lttng-bytecode-specialize.c +++ b/liblttng-ust/lttng-bytecode-specialize.c @@ -155,6 +155,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 +182,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; @@ -416,9 +424,9 @@ static int specialize_load_object(const struct lttng_event_field *field, 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; } diff --git a/liblttng-ust/lttng-bytecode.h b/liblttng-ust/lttng-bytecode.h index 5742f7f5..57093a55 100644 --- a/liblttng-ust/lttng-bytecode.h +++ b/liblttng-ust/lttng-bytecode.h @@ -112,6 +112,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,