/*
* Create a newly allocated kernel probe event rule.
*
- * Returns a new event rule on success, NULL on failure. The returned event rule
- * must be destroyed using lttng_event_rule_destroy().
- */
-extern struct lttng_event_rule *lttng_event_rule_kernel_probe_create(void);
-
-/*
- * Set the kernel probe location of a kernel probe event rule.
- *
* The location is copied internally.
*
- * Returns LTTNG_EVENT_RULE_STATUS_OK on success, LTTNG_EVENT_RULE_STATUS_INVALID
- * if invalid parameters are passed.
+ * Returns a new event rule on success, NULL on failure. The returned event rule
+ * must be destroyed using lttng_event_rule_destroy().
*/
-extern enum lttng_event_rule_status lttng_event_rule_kernel_probe_set_location(
- struct lttng_event_rule *rule,
+extern struct lttng_event_rule *lttng_event_rule_kernel_probe_create(
const struct lttng_kernel_probe_location *location);
/*
int ret;
enum lttng_event_rule_status event_rule_status;
- res.er = lttng_event_rule_kernel_probe_create();
- if (!res.er) {
- ERR("Failed to create kprobe event rule.");
- goto error;
- }
ret = parse_kernel_probe_opts(source, &kernel_probe_location);
if (ret) {
goto error;
}
- event_rule_status = lttng_event_rule_kernel_probe_set_event_name(res.er, tracepoint_name);
- if (event_rule_status != LTTNG_EVENT_RULE_STATUS_OK) {
- ERR("Failed to set kprobe event rule's name to '%s'.", tracepoint_name);
+ assert(kernel_probe_location);
+ res.er = lttng_event_rule_kernel_probe_create(kernel_probe_location);
+ if (!res.er) {
+ ERR("Failed to create kprobe event rule.");
goto error;
}
- assert(kernel_probe_location);
- event_rule_status = lttng_event_rule_kernel_probe_set_location(res.er, kernel_probe_location);
+ event_rule_status = lttng_event_rule_kernel_probe_set_event_name(res.er, tracepoint_name);
if (event_rule_status != LTTNG_EVENT_RULE_STATUS_OK) {
- ERR("Failed to set kprobe event rule's location.");
+ ERR("Failed to set kprobe event rule's name to '%s'.", tracepoint_name);
goto error;
}
#include <common/hashtable/utils.h>
#include <ctype.h>
#include <lttng/constant.h>
+#include <lttng/event-rule/event-rule.h>
#include <lttng/event-rule/event-rule-internal.h>
#include <lttng/event-rule/kernel-probe-internal.h>
#include <lttng/kernel-probe.h>
return hash;
}
-struct lttng_event_rule *lttng_event_rule_kernel_probe_create(void)
+static
+int kernel_probe_set_location(
+ struct lttng_event_rule_kernel_probe *kprobe,
+ const struct lttng_kernel_probe_location *location)
+{
+ int ret;
+ struct lttng_kernel_probe_location *location_copy = NULL;
+
+ if (!kprobe || !location || kprobe->location) {
+ ret = -1;
+ goto end;
+ }
+
+ location_copy = lttng_kernel_probe_location_copy(location);
+ if (!location_copy) {
+ ret = -1;
+ goto end;
+ }
+
+ kprobe->location = location_copy;
+ location_copy = NULL;
+ ret = 0;
+end:
+ lttng_kernel_probe_location_destroy(location_copy);
+ return ret;
+}
+
+struct lttng_event_rule *lttng_event_rule_kernel_probe_create(
+ const struct lttng_kernel_probe_location *location)
{
struct lttng_event_rule *rule = NULL;
struct lttng_event_rule_kernel_probe *krule;
krule->parent.generate_exclusions =
lttng_event_rule_kernel_probe_generate_exclusions;
krule->parent.hash = lttng_event_rule_kernel_probe_hash;
+
+ if (kernel_probe_set_location(krule, location)) {
+ lttng_event_rule_destroy(rule);
+ rule = NULL;
+ }
+
end:
return rule;
}
const char *name;
struct lttng_buffer_view current_buffer_view;
struct lttng_event_rule *rule = NULL;
- struct lttng_event_rule_kernel_probe *kprobe = NULL;
- struct lttng_kernel_probe_location *location;
+ struct lttng_kernel_probe_location *location = NULL;
if (!_event_rule) {
ret = -1;
kprobe_comm = (typeof(kprobe_comm)) current_buffer_view.data;
- rule = lttng_event_rule_kernel_probe_create();
- if (!rule) {
- ERR("Failed to create event rule kprobe.");
- ret = -1;
- goto end;
- }
-
- kprobe = container_of(rule, struct lttng_event_rule_kernel_probe, parent);
-
/* Skip to payload */
offset += current_buffer_view.size;
goto end;
}
- kprobe->location = location;
-
/* Skip after the location */
offset += kprobe_comm->location_len;
+ rule = lttng_event_rule_kernel_probe_create(location);
+ if (!rule) {
+ ERR("Failed to create event rule kprobe.");
+ ret = -1;
+ goto end;
+ }
+
status = lttng_event_rule_kernel_probe_set_event_name(rule, name);
if (status != LTTNG_EVENT_RULE_STATUS_OK) {
ERR("Failed to set event rule kprobe name.");
rule = NULL;
ret = offset;
end:
+ lttng_kernel_probe_location_destroy(location);
lttng_event_rule_destroy(rule);
return ret;
}
-enum lttng_event_rule_status lttng_event_rule_kernel_probe_set_location(
- struct lttng_event_rule *rule,
- const struct lttng_kernel_probe_location *location)
-{
- struct lttng_kernel_probe_location *location_copy = NULL;
- struct lttng_event_rule_kernel_probe *kprobe;
- enum lttng_event_rule_status status = LTTNG_EVENT_RULE_STATUS_OK;
-
- if (!rule || !IS_KPROBE_EVENT_RULE(rule) || !location) {
- status = LTTNG_EVENT_RULE_STATUS_INVALID;
- goto end;
- }
-
- kprobe = container_of(rule, struct lttng_event_rule_kernel_probe, parent);
- location_copy = lttng_kernel_probe_location_copy(location);
- if (!location_copy) {
- status = LTTNG_EVENT_RULE_STATUS_ERROR;
- goto end;
- }
-
- if (kprobe->location) {
- lttng_kernel_probe_location_destroy(kprobe->location);
- }
-
- kprobe->location = location_copy;
- location_copy = NULL;
-end:
- lttng_kernel_probe_location_destroy(location_copy);
- return status;
-}
-
enum lttng_event_rule_status lttng_event_rule_kernel_probe_get_location(
const struct lttng_event_rule *rule,
const struct lttng_kernel_probe_location **location)
lttng_session_daemon_notification_endpoint);
ok(notification_channel, "Notification channel object creation");
- event_rule = lttng_event_rule_kernel_probe_create();
+ event_rule = lttng_event_rule_kernel_probe_create(location);
ok(event_rule, "kprobe event rule object creation");
- event_rule_status = lttng_event_rule_kernel_probe_set_location(
- event_rule, location);
- ok(event_rule_status == LTTNG_EVENT_RULE_STATUS_OK,
- "Setting kprobe event rule location: '%s'", symbol_name);
-
event_rule_status = lttng_event_rule_kernel_probe_set_event_name(
event_rule, trigger_name);
ok(event_rule_status == LTTNG_EVENT_RULE_STATUS_OK,
}
case 4:
{
- plan_tests(13);
+ plan_tests(12);
/* Test cases that need the kernel tracer. */
assert(domain_type == LTTNG_DOMAIN_KERNEL);
int lttng_opt_verbose;
int lttng_opt_mi;
-#define NUM_TESTS 187
+#define NUM_TESTS 185
struct tracepoint_test {
enum lttng_domain_type type;
lttng_payload_init(&payload);
- kprobe = lttng_event_rule_kernel_probe_create();
+ kprobe = lttng_event_rule_kernel_probe_create(location);
ok(kprobe, "kprobe event rule object creation.");
- status = lttng_event_rule_kernel_probe_set_location(kprobe, location);
- ok(status == LTTNG_EVENT_RULE_STATUS_OK,
- "Setting kprobe event rule location.");
status = lttng_event_rule_kernel_probe_get_location(kprobe, &_location);
ok(status == LTTNG_EVENT_RULE_STATUS_OK,
"Getting kprobe event rule location.");