condition: implement lttng_condition_event_rule_generate_capture_descriptor_bytecode
authorJonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Wed, 8 Apr 2020 21:51:52 +0000 (17:51 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Thu, 11 Mar 2021 20:31:53 +0000 (15:31 -0500)
Generate the bytecode related to the tracer notification capture
feature.

The bytecode is stored alongside the lttng_event_expr in an internal
lttng_capture_descriptor object.

Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: I4cfbdd9ab91328a5540ad19049e056fe3ce7f5ba
Depends-on: lttng-ust: I5a800fc92e588c2a6a0e26282b0ad5f31c044479

include/lttng/condition/event-rule-internal.h
include/lttng/lttng-error.h
src/common/conditions/event-rule.c
src/common/error.c

index 241ec571df77316b8827b6619e0c736ed2d00fec..1f039c3475f8c5eec77084eee754d70e700aa1f1 100644 (file)
@@ -39,7 +39,6 @@ struct lttng_evaluation_event_rule_comm {
        char payload[];
 } LTTNG_PACKED;
 
-
 LTTNG_HIDDEN
 ssize_t lttng_condition_event_rule_create_from_payload(
                struct lttng_payload_view *view,
@@ -60,4 +59,9 @@ ssize_t lttng_evaluation_event_rule_create_from_payload(
                struct lttng_payload_view *view,
                struct lttng_evaluation **_evaluation);
 
+LTTNG_HIDDEN
+enum lttng_error_code
+lttng_condition_event_rule_generate_capture_descriptor_bytecode(
+               struct lttng_condition *condition);
+
 #endif /* LTTNG_CONDITION_EVENT_RULE_INTERNAL_H */
index db0f5e0f7f0308da85ba62822324ae03a42be554..606d8b0b28a0c0a29b4bed5cf15c8ca899388f6f 100644 (file)
@@ -175,6 +175,7 @@ enum lttng_error_code {
        LTTNG_ERR_UNSUPPORTED_DOMAIN     = 162,  /* Unsupported domain used. */
        LTTNG_ERR_PROCESS_ATTR_TRACKER_INVALID_TRACKING_POLICY = 163, /* Operation does not apply to the process attribute tracker's tracking policy */
        LTTNG_ERR_EVENT_NOTIFIER_GROUP_NOTIFICATION_FD = 164, /* Error initializing event notifier group notification file descriptor */
+       LTTNG_ERR_INVALID_CAPTURE_EXPRESSION = 165, /* Invalid capture expression. */
 
        /* MUST be last element of the manually-assigned section of the enum */
        LTTNG_ERR_NR,
index 8d3f1cd536c01e427513ff528d764063ea849715..8959652ddda3da8ba23364b73cc3e8b1d0bbc338 100644 (file)
@@ -7,14 +7,16 @@
 
 #include <assert.h>
 #include <common/error.h>
+#include <common/event-expr-to-bytecode.h>
 #include <common/macros.h>
 #include <inttypes.h>
 #include <lttng/condition/condition-internal.h>
+#include <lttng/event-rule/event-rule-internal.h>
 #include <lttng/condition/event-rule-internal.h>
 #include <lttng/condition/event-rule.h>
 #include <lttng/event-expr-internal.h>
 #include <lttng/event-expr.h>
-#include <lttng/event-rule/event-rule-internal.h>
+#include <lttng/lttng-error.h>
 #include <stdbool.h>
 #include <stdint.h>
 #include <vendor/msgpack/msgpack.h>
@@ -922,3 +924,51 @@ enum lttng_evaluation_status lttng_evaluation_event_rule_get_trigger_name(
 end:
        return status;
 }
+
+LTTNG_HIDDEN
+enum lttng_error_code
+lttng_condition_event_rule_generate_capture_descriptor_bytecode(
+               struct lttng_condition *condition)
+{
+       enum lttng_error_code ret;
+       enum lttng_condition_status status;
+       unsigned int capture_count, i;
+
+       if (!condition || !IS_EVENT_RULE_CONDITION(condition)) {
+               ret = LTTNG_ERR_FATAL;
+               goto end;
+       }
+
+       status = lttng_condition_event_rule_get_capture_descriptor_count(
+                       condition, &capture_count);
+       if (status != LTTNG_CONDITION_STATUS_OK) {
+               ret = LTTNG_ERR_FATAL;
+               goto end;
+       }
+
+       for (i = 0; i < capture_count; i++) {
+               struct lttng_capture_descriptor *local_capture_desc =
+                               lttng_condition_event_rule_get_internal_capture_descriptor_at_index(
+                                               condition, i);
+
+               if (local_capture_desc == NULL) {
+                       ret = LTTNG_ERR_FATAL;
+                       goto end;
+               }
+
+               /* Generate the bytecode. */
+               status = lttng_event_expr_to_bytecode(
+                               local_capture_desc->event_expression,
+                               &local_capture_desc->bytecode);
+               if (status < 0 || local_capture_desc->bytecode == NULL) {
+                       ret = LTTNG_ERR_INVALID_CAPTURE_EXPRESSION;
+                       goto end;
+               }
+       }
+
+       /* Everything went better than expected */
+       ret = LTTNG_OK;
+
+end:
+       return ret;
+}
index b8dabdf6e1bc02aae4108e7ab3aad75753f05cf0..e03bee350d0e2c07bf0b7cb56f4463492ba0ec12 100644 (file)
@@ -240,6 +240,7 @@ static const char *error_string_array[] = {
        [ ERROR_INDEX(LTTNG_ERR_UNSUPPORTED_DOMAIN) ] = "Unsupported domain used",
        [ ERROR_INDEX(LTTNG_ERR_PROCESS_ATTR_TRACKER_INVALID_TRACKING_POLICY) ] = "Operation does not apply to the process attribute tracker's tracking policy",
        [ ERROR_INDEX(LTTNG_ERR_EVENT_NOTIFIER_GROUP_NOTIFICATION_FD) ] = "Failed to create an event notifier group notification file descriptor",
+       [ ERROR_INDEX(LTTNG_ERR_INVALID_CAPTURE_EXPRESSION) ] = "Invalid capture expression",
 
        /* Last element */
        [ ERROR_INDEX(LTTNG_ERR_NR) ] = "Unknown error code"
This page took 0.036401 seconds and 4 git commands to generate.