Move event-expr-to-bytecode to event-expr
authorJonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Thu, 11 Feb 2021 15:40:39 +0000 (10:40 -0500)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Tue, 22 Jun 2021 17:46:28 +0000 (13:46 -0400)
Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: I74a4b823ae7bbcbb062dbb9a2a0f84785bca287a

include/lttng/event-expr-internal.h
src/common/Makefile.am
src/common/conditions/event-rule-matches.c
src/common/event-expr-to-bytecode.c [deleted file]
src/common/event-expr-to-bytecode.h [deleted file]
src/common/event-expr/event-expr.c
tests/unit/test_event_expr_to_bytecode.c

index 88fa695de9d154882e9a8d44ed5d9865594126df..048aaff18665b3a73de50ca38829a4f504442e7a 100644 (file)
@@ -9,8 +9,11 @@
 #define LTTNG_EVENT_EXPR_INTERNAL_H
 
 #include <assert.h>
+#include <common/macros.h>
 #include <lttng/event-expr.h>
 
+struct lttng_bytecode;
+
 struct lttng_event_expr {
        enum lttng_event_expr_type type;
 };
@@ -54,4 +57,8 @@ bool lttng_event_expr_is_lvalue(const struct lttng_event_expr *expr)
                        expr->type == LTTNG_EVENT_EXPR_TYPE_ARRAY_FIELD_ELEMENT;
 }
 
+LTTNG_HIDDEN
+int lttng_event_expr_to_bytecode(const struct lttng_event_expr *expr,
+               struct lttng_bytecode **bytecode_out);
+
 #endif /* LTTNG_EVENT_EXPR_INTERNAL_H */
index ca0973403b7a0c07fc37e6d2e49112993618abe2..9c66a7658cf170b9cc5690a04a419269ae2ffb11 100644 (file)
@@ -67,7 +67,6 @@ libcommon_la_SOURCES = \
        evaluation.c \
        event.c \
        event-expr/event-expr.c \
-       event-expr-to-bytecode.c event-expr-to-bytecode.h \
        event-field-value.c \
        event-rule/event-rule.c \
        event-rule/kernel-kprobe.c \
index 8877966421996f86661a375f6320e3bfe319cb00..259173a63b3a94432461d74d92f216ac6f9b0ec2 100644 (file)
@@ -7,7 +7,6 @@
 
 #include <assert.h>
 #include <common/error.h>
-#include <common/event-expr-to-bytecode.h>
 #include <common/macros.h>
 #include <inttypes.h>
 #include <limits.h>
diff --git a/src/common/event-expr-to-bytecode.c b/src/common/event-expr-to-bytecode.c
deleted file mode 100644 (file)
index 9fe3c03..0000000
+++ /dev/null
@@ -1,225 +0,0 @@
-/*
- * Copyright 2020 EfficiOS, Inc.
- *
- * SPDX-License-Identifier: LGPL-2.1-only
- *
- */
-
-#include "event-expr-to-bytecode.h"
-
-#include <stdio.h>
-#include <lttng/event-expr.h>
-#include <common/bytecode/bytecode.h>
-#include <common/error.h>
-
-static
-int event_expr_to_bytecode_recursive(const struct lttng_event_expr *expr,
-               struct lttng_bytecode_alloc **bytecode,
-               struct lttng_bytecode_alloc **bytecode_reloc)
-{
-       int status;
-       enum lttng_event_expr_status event_expr_status;
-
-       switch (lttng_event_expr_get_type(expr)) {
-       case LTTNG_EVENT_EXPR_TYPE_EVENT_PAYLOAD_FIELD:
-       {
-               const char *name;
-
-               status = bytecode_push_get_payload_root(bytecode);
-               if (status) {
-                       ERR("Failed to get payload root from bytecode");
-                       goto end;
-               }
-
-               name = lttng_event_expr_event_payload_field_get_name(expr);
-               if (!name) {
-                       ERR("Failed to get payload field name from event expression");
-                       status = -1;
-                       goto end;
-               }
-
-               status = bytecode_push_get_symbol(bytecode, bytecode_reloc, name);
-               if (status) {
-                       ERR("Failed to push 'get symbol %s' in bytecode", name);
-                       goto end;
-               }
-
-               break;
-       }
-       case LTTNG_EVENT_EXPR_TYPE_CHANNEL_CONTEXT_FIELD:
-       {
-               const char *name;
-
-               status = bytecode_push_get_context_root(bytecode);
-               if (status) {
-                       ERR("Failed to get context root from bytecode");
-                       goto end;
-               }
-
-               name = lttng_event_expr_channel_context_field_get_name(expr);
-               if (!name) {
-                       ERR("Failed to get channel context field name from event expression");
-                       status = -1;
-                       goto end;
-               }
-
-               status = bytecode_push_get_symbol(bytecode, bytecode_reloc, name);
-               if (status) {
-                       ERR("Failed to push 'get symbol %s' in bytecode", name);
-                       goto end;
-               }
-
-               break;
-       }
-       case LTTNG_EVENT_EXPR_TYPE_APP_SPECIFIC_CONTEXT_FIELD:
-       {
-               int ret;
-               char *name = NULL;
-               const char *provider_name, *type_name;
-
-               status = bytecode_push_get_app_context_root(bytecode);
-               if (status) {
-                       ERR("Failed to get application context root from bytecode");
-                       goto end;
-               }
-
-               provider_name = lttng_event_expr_app_specific_context_field_get_provider_name(
-                               expr);
-               if (!provider_name) {
-                       ERR("Failed to get application context provider name from event expression");
-                       status = -1;
-                       goto end;
-               }
-
-               type_name = lttng_event_expr_app_specific_context_field_get_type_name(
-                               expr);
-               if (!type_name) {
-                       ERR("Failed to get application context type name from event expression");
-                       status = -1;
-                       goto end;
-               }
-
-               /*
-                * Reconstitute the app context field name from its two parts.
-                */
-               ret = asprintf(&name, "%s:%s", provider_name, type_name);
-               if (ret < 0) {
-                       PERROR("Failed to format application specific context: provider_name = '%s', type_name = '%s'",
-                                       provider_name, type_name);
-                       status = -1;
-                       goto end;
-               }
-
-               status = bytecode_push_get_symbol(
-                               bytecode, bytecode_reloc, name);
-               free(name);
-               if (status) {
-                       ERR("Failed to push 'get symbol %s:%s' in bytecode",
-                                       provider_name, type_name);
-                       goto end;
-               }
-
-               break;
-       }
-       case LTTNG_EVENT_EXPR_TYPE_ARRAY_FIELD_ELEMENT:
-       {
-               unsigned int index;
-               const struct lttng_event_expr *parent;
-
-               parent = lttng_event_expr_array_field_element_get_parent_expr(
-                               expr);
-               if (!parent) {
-                       ERR("Failed to get parent expression from array event expression");
-                       status = -1;
-                       goto end;
-               }
-
-               status = event_expr_to_bytecode_recursive(
-                               parent, bytecode, bytecode_reloc);
-               if (status) {
-                       goto end;
-               }
-
-               event_expr_status = lttng_event_expr_array_field_element_get_index(
-                               expr, &index);
-               if (event_expr_status != LTTNG_EVENT_EXPR_STATUS_OK) {
-                       ERR("Failed to get array field element index from event expression");
-                       status = -1;
-                       goto end;
-               }
-
-               status = bytecode_push_get_index_u64(bytecode, index);
-               if (status) {
-                       ERR("Failed to push 'get index %u' in bytecode", index);
-                       goto end;
-               }
-
-               break;
-       }
-       default:
-               abort();
-       }
-
-       status = 0;
-end:
-       return status;
-}
-
-LTTNG_HIDDEN
-int lttng_event_expr_to_bytecode(const struct lttng_event_expr *expr,
-               struct lttng_bytecode **bytecode_out)
-{
-       int status;
-       struct return_op ret_insn;
-       struct lttng_bytecode_alloc *bytecode = NULL;
-       struct lttng_bytecode_alloc *bytecode_reloc = NULL;
-
-       status = bytecode_init(&bytecode);
-       if (status) {
-               ERR("Failed to initialize bytecode");
-               goto end;
-       }
-
-       status = bytecode_init(&bytecode_reloc);
-       if (status) {
-               ERR("Failed to initialize relocation bytecode");
-               goto end;
-       }
-
-       status = event_expr_to_bytecode_recursive(
-                       expr, &bytecode, &bytecode_reloc);
-       if (status) {
-               /* Errors already logged. */
-               goto end;
-       }
-
-       ret_insn.op = BYTECODE_OP_RETURN;
-       bytecode_push(&bytecode, &ret_insn, 1, sizeof(ret_insn));
-
-       /* Append symbol table to bytecode. */
-       bytecode->b.reloc_table_offset = bytecode_get_len(&bytecode->b);
-       status = bytecode_push(&bytecode, bytecode_reloc->b.data, 1,
-                       bytecode_get_len(&bytecode_reloc->b));
-       if (status) {
-               ERR("Failed to push symbol table to bytecode");
-               goto end;
-       }
-
-       /* Copy the `lttng_bytecode` out of the `lttng_bytecode_alloc`.  */
-       *bytecode_out = lttng_bytecode_copy(&bytecode->b);
-       if (!*bytecode_out) {
-               status = -1;
-               goto end;
-       }
-
-end:
-       if (bytecode) {
-               free(bytecode);
-       }
-
-       if (bytecode_reloc) {
-               free(bytecode_reloc);
-       }
-
-       return status;
-}
diff --git a/src/common/event-expr-to-bytecode.h b/src/common/event-expr-to-bytecode.h
deleted file mode 100644 (file)
index 9d7d57a..0000000
+++ /dev/null
@@ -1,20 +0,0 @@
-#ifndef SRC_COMMON_EVENT_EXPR_TO_BYTECODE_H
-#define SRC_COMMON_EVENT_EXPR_TO_BYTECODE_H
-
-/*
- * Copyright 2020 EfficiOS, Inc.
- *
- * SPDX-License-Identifier: LGPL-2.1-only
- *
- */
-
-#include <common/macros.h>
-
-struct lttng_bytecode;
-struct lttng_event_expr;
-
-LTTNG_HIDDEN
-int lttng_event_expr_to_bytecode (const struct lttng_event_expr *expr,
-               struct lttng_bytecode **bytecode_out);
-
-#endif /* SRC_COMMON_EVENT_EXPR_TO_BYTECODE_H */
index c0ec2571baa15c9ff2621e4bc3027b650168be57..1351a347f5de21ca054010aa8bcc088a73a94915 100644 (file)
 #include <assert.h>
 #include <stddef.h>
 
+#include <common/bytecode/bytecode.h>
 #include <common/error.h>
 #include <common/macros.h>
 #include <lttng/event-expr-internal.h>
+#include <lttng/event-expr.h>
+#include <stdio.h>
 
 enum lttng_event_expr_type lttng_event_expr_get_type(
                const struct lttng_event_expr *expr)
@@ -440,3 +443,217 @@ void lttng_event_expr_destroy(struct lttng_event_expr *expr)
 end:
        return;
 }
+
+static int event_expr_to_bytecode_recursive(const struct lttng_event_expr *expr,
+               struct lttng_bytecode_alloc **bytecode,
+               struct lttng_bytecode_alloc **bytecode_reloc)
+{
+       int status;
+       enum lttng_event_expr_status event_expr_status;
+
+       switch (lttng_event_expr_get_type(expr)) {
+       case LTTNG_EVENT_EXPR_TYPE_EVENT_PAYLOAD_FIELD:
+       {
+               const char *name;
+
+               status = bytecode_push_get_payload_root(bytecode);
+               if (status) {
+                       ERR("Failed to get payload root from bytecode");
+                       goto end;
+               }
+
+               name = lttng_event_expr_event_payload_field_get_name(expr);
+               if (!name) {
+                       ERR("Failed to get payload field name from event expression");
+                       status = -1;
+                       goto end;
+               }
+
+               status = bytecode_push_get_symbol(
+                               bytecode, bytecode_reloc, name);
+               if (status) {
+                       ERR("Failed to push 'get symbol %s' in bytecode", name);
+                       goto end;
+               }
+
+               break;
+       }
+       case LTTNG_EVENT_EXPR_TYPE_CHANNEL_CONTEXT_FIELD:
+       {
+               const char *name;
+
+               status = bytecode_push_get_context_root(bytecode);
+               if (status) {
+                       ERR("Failed to get context root from bytecode");
+                       goto end;
+               }
+
+               name = lttng_event_expr_channel_context_field_get_name(expr);
+               if (!name) {
+                       ERR("Failed to get channel context field name from event expression");
+                       status = -1;
+                       goto end;
+               }
+
+               status = bytecode_push_get_symbol(
+                               bytecode, bytecode_reloc, name);
+               if (status) {
+                       ERR("Failed to push 'get symbol %s' in bytecode", name);
+                       goto end;
+               }
+
+               break;
+       }
+       case LTTNG_EVENT_EXPR_TYPE_APP_SPECIFIC_CONTEXT_FIELD:
+       {
+               int ret;
+               char *name = NULL;
+               const char *provider_name, *type_name;
+
+               status = bytecode_push_get_app_context_root(bytecode);
+               if (status) {
+                       ERR("Failed to get application context root from bytecode");
+                       goto end;
+               }
+
+               provider_name = lttng_event_expr_app_specific_context_field_get_provider_name(
+                               expr);
+               if (!provider_name) {
+                       ERR("Failed to get application context provider name from event expression");
+                       status = -1;
+                       goto end;
+               }
+
+               type_name = lttng_event_expr_app_specific_context_field_get_type_name(
+                               expr);
+               if (!type_name) {
+                       ERR("Failed to get application context type name from event expression");
+                       status = -1;
+                       goto end;
+               }
+
+               /*
+                * Reconstitute the app context field name from its two parts.
+                */
+               ret = asprintf(&name, "%s:%s", provider_name, type_name);
+               if (ret < 0) {
+                       PERROR("Failed to format application specific context: provider_name = '%s', type_name = '%s'",
+                                       provider_name, type_name);
+                       status = -1;
+                       goto end;
+               }
+
+               status = bytecode_push_get_symbol(
+                               bytecode, bytecode_reloc, name);
+               free(name);
+               if (status) {
+                       ERR("Failed to push 'get symbol %s:%s' in bytecode",
+                                       provider_name, type_name);
+                       goto end;
+               }
+
+               break;
+       }
+       case LTTNG_EVENT_EXPR_TYPE_ARRAY_FIELD_ELEMENT:
+       {
+               unsigned int index;
+               const struct lttng_event_expr *parent;
+
+               parent = lttng_event_expr_array_field_element_get_parent_expr(
+                               expr);
+               if (!parent) {
+                       ERR("Failed to get parent expression from array event expression");
+                       status = -1;
+                       goto end;
+               }
+
+               status = event_expr_to_bytecode_recursive(
+                               parent, bytecode, bytecode_reloc);
+               if (status) {
+                       goto end;
+               }
+
+               event_expr_status =
+                               lttng_event_expr_array_field_element_get_index(
+                                               expr, &index);
+               if (event_expr_status != LTTNG_EVENT_EXPR_STATUS_OK) {
+                       ERR("Failed to get array field element index from event expression");
+                       status = -1;
+                       goto end;
+               }
+
+               status = bytecode_push_get_index_u64(bytecode, index);
+               if (status) {
+                       ERR("Failed to push 'get index %u' in bytecode", index);
+                       goto end;
+               }
+
+               break;
+       }
+       default:
+               abort();
+       }
+
+       status = 0;
+end:
+       return status;
+}
+
+LTTNG_HIDDEN
+int lttng_event_expr_to_bytecode(const struct lttng_event_expr *expr,
+               struct lttng_bytecode **bytecode_out)
+{
+       int status;
+       struct return_op ret_insn;
+       struct lttng_bytecode_alloc *bytecode = NULL;
+       struct lttng_bytecode_alloc *bytecode_reloc = NULL;
+
+       status = bytecode_init(&bytecode);
+       if (status) {
+               ERR("Failed to initialize bytecode");
+               goto end;
+       }
+
+       status = bytecode_init(&bytecode_reloc);
+       if (status) {
+               ERR("Failed to initialize relocation bytecode");
+               goto end;
+       }
+
+       status = event_expr_to_bytecode_recursive(
+                       expr, &bytecode, &bytecode_reloc);
+       if (status) {
+               /* Errors already logged. */
+               goto end;
+       }
+
+       ret_insn.op = BYTECODE_OP_RETURN;
+       bytecode_push(&bytecode, &ret_insn, 1, sizeof(ret_insn));
+
+       /* Append symbol table to bytecode. */
+       bytecode->b.reloc_table_offset = bytecode_get_len(&bytecode->b);
+       status = bytecode_push(&bytecode, bytecode_reloc->b.data, 1,
+                       bytecode_get_len(&bytecode_reloc->b));
+       if (status) {
+               ERR("Failed to push symbol table to bytecode");
+               goto end;
+       }
+
+       /* Copy the `lttng_bytecode` out of the `lttng_bytecode_alloc`.  */
+       *bytecode_out = lttng_bytecode_copy(&bytecode->b);
+       if (!*bytecode_out) {
+               status = -1;
+               goto end;
+       }
+
+end:
+       if (bytecode) {
+               free(bytecode);
+       }
+
+       if (bytecode_reloc) {
+               free(bytecode_reloc);
+       }
+
+       return status;
+}
index dd26e66e6fcdbfe9d338a2703519fcf6bdd9dee0..fae7eb26ebe214f567a37bdf12bcd0abbf49e73a 100644 (file)
@@ -5,9 +5,9 @@
  *
  */
 
-#include <lttng/event-expr.h>
-#include <common/event-expr-to-bytecode.h>
 #include <common/bytecode/bytecode.h>
+#include <lttng/event-expr-internal.h>
+#include <lttng/event-expr.h>
 #include <tap/tap.h>
 
 #define NR_TESTS 4
This page took 0.033276 seconds and 4 git commands to generate.