From: Jonathan Rajotte Date: Tue, 3 Nov 2020 23:04:34 +0000 (-0500) Subject: Implement lttng_condition_event_rule_get_capture_bytecode_at_index X-Git-Tag: v2.13.0-rc1~248 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=51dbe9857c314b9b0dc53b4f9c367f7db659a6b4;p=lttng-tools.git Implement lttng_condition_event_rule_get_capture_bytecode_at_index Signed-off-by: Jonathan Rajotte Signed-off-by: Jérémie Galarneau Change-Id: I0478c3c1a5866f924fa8a5b49fdc61570a802989 --- 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; +}