bytecode: Add `OBJECT_TYPE_{UN,}SIGNED_ENUM` type
authorFrancis Deslauriers <fdeslaur@gmail.com>
Thu, 7 May 2020 20:41:18 +0000 (16:41 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Thu, 26 Nov 2020 18:37:00 +0000 (13:37 -0500)
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 <fdeslaur@gmail.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Change-Id: I4b3ec8187a578ddc6c9d87f72d462441ba5e4a1e

liblttng-ust/lttng-bytecode-interpreter.c
liblttng-ust/lttng-bytecode-specialize.c
liblttng-ust/lttng-bytecode.h

index 9d7258f7dd81530c9e892912ac017a602e1625b1..9a2aaa45ec97b63748150c7700dadaac6f49ddc6 100644 (file)
@@ -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:
index 55b2ebf221687be36d8c4f306b8e85b8a2cbd70c..15a45b93947fb19f9ae057984f6307c98befb45c 100644 (file)
@@ -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;
        }
index 5742f7f5c34eae8cad45294494f73818add7f942..57093a5573604b2634aff4aacb10c05426e3ede9 100644 (file)
@@ -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,
This page took 0.028701 seconds and 4 git commands to generate.