From 51dbe9857c314b9b0dc53b4f9c367f7db659a6b4 Mon Sep 17 00:00:00 2001 From: Jonathan Rajotte Date: Tue, 3 Nov 2020 18:04:34 -0500 Subject: [PATCH] Implement lttng_condition_event_rule_get_capture_bytecode_at_index MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jonathan Rajotte Signed-off-by: Jérémie Galarneau Change-Id: I0478c3c1a5866f924fa8a5b49fdc61570a802989 --- include/lttng/condition/event-rule-internal.h | 5 +++ src/common/conditions/event-rule.c | 39 +++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/include/lttng/condition/event-rule-internal.h b/include/lttng/condition/event-rule-internal.h index 1f039c347..0f2f3fbf6 100644 --- a/include/lttng/condition/event-rule-internal.h +++ b/include/lttng/condition/event-rule-internal.h @@ -64,4 +64,9 @@ enum lttng_error_code lttng_condition_event_rule_generate_capture_descriptor_bytecode( struct lttng_condition *condition); +LTTNG_HIDDEN +const struct lttng_bytecode * +lttng_condition_event_rule_get_capture_bytecode_at_index( + const struct lttng_condition *condition, unsigned int index); + #endif /* LTTNG_CONDITION_EVENT_RULE_INTERNAL_H */ diff --git a/src/common/conditions/event-rule.c b/src/common/conditions/event-rule.c index 8959652dd..dcc31ef86 100644 --- a/src/common/conditions/event-rule.c +++ b/src/common/conditions/event-rule.c @@ -972,3 +972,42 @@ lttng_condition_event_rule_generate_capture_descriptor_bytecode( end: return ret; } + +LTTNG_HIDDEN +const struct lttng_bytecode * +lttng_condition_event_rule_get_capture_bytecode_at_index( + const struct lttng_condition *condition, unsigned int index) +{ + const struct lttng_condition_event_rule *event_rule_cond = + container_of(condition, + const struct lttng_condition_event_rule, + parent); + struct lttng_capture_descriptor *desc = NULL; + struct lttng_bytecode *bytecode = NULL; + unsigned int count; + enum lttng_condition_status status; + + if (!condition || !IS_EVENT_RULE_CONDITION(condition)) { + goto end; + } + + status = lttng_condition_event_rule_get_capture_descriptor_count( + condition, &count); + if (status != LTTNG_CONDITION_STATUS_OK) { + goto end; + } + + if (index >= count) { + goto end; + } + + desc = lttng_dynamic_pointer_array_get_pointer( + &event_rule_cond->capture_descriptors, index); + if (desc == NULL) { + goto end; + } + + bytecode = desc->bytecode; +end: + return bytecode; +} -- 2.34.1