From: Jonathan Rajotte Date: Wed, 8 Apr 2020 21:51:52 +0000 (-0400) Subject: condition: implement lttng_condition_event_rule_generate_capture_descriptor_bytecode X-Git-Tag: v2.13.0-rc1~249 X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=commitdiff_plain;h=834966afb566191f13f7c6870902a3e4b00a9d27 condition: implement lttng_condition_event_rule_generate_capture_descriptor_bytecode 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 Signed-off-by: Jérémie Galarneau Change-Id: I4cfbdd9ab91328a5540ad19049e056fe3ce7f5ba Depends-on: lttng-ust: I5a800fc92e588c2a6a0e26282b0ad5f31c044479 --- diff --git a/include/lttng/condition/event-rule-internal.h b/include/lttng/condition/event-rule-internal.h index 241ec571d..1f039c347 100644 --- a/include/lttng/condition/event-rule-internal.h +++ b/include/lttng/condition/event-rule-internal.h @@ -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 */ diff --git a/include/lttng/lttng-error.h b/include/lttng/lttng-error.h index db0f5e0f7..606d8b0b2 100644 --- a/include/lttng/lttng-error.h +++ b/include/lttng/lttng-error.h @@ -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, diff --git a/src/common/conditions/event-rule.c b/src/common/conditions/event-rule.c index 8d3f1cd53..8959652dd 100644 --- a/src/common/conditions/event-rule.c +++ b/src/common/conditions/event-rule.c @@ -7,14 +7,16 @@ #include #include +#include #include #include #include +#include #include #include #include #include -#include +#include #include #include #include @@ -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; +} diff --git a/src/common/error.c b/src/common/error.c index b8dabdf6e..e03bee350 100644 --- a/src/common/error.c +++ b/src/common/error.c @@ -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"