4 * Linux Trace Toolkit Control Library
6 * Copyright (C) 2017 Jérémie Galarneau <jeremie.galarneau@efficios.com>
8 * SPDX-License-Identifier: LGPL-2.1-only
16 #include <common/error.h>
17 #include <common/sessiond-comm/sessiond-comm.h>
18 #include <lttng/event-internal.h>
19 #include <lttng/event.h>
20 #include <lttng/lttng-error.h>
21 #include <lttng/userspace-probe-internal.h>
23 struct lttng_event
*lttng_event_create(void)
25 struct lttng_event
*event
;
26 struct lttng_event_extended
*event_extended
;
28 event
= zmalloc(sizeof(*event
));
30 PERROR("Error allocating event structure");
34 event_extended
= zmalloc(sizeof(*event_extended
));
35 if (!event_extended
) {
36 PERROR("Error allocating event extended structure");
39 event
->extended
.ptr
= event_extended
;
48 void lttng_event_destroy(struct lttng_event
*event
)
50 struct lttng_event_extended
*event_extended
;
56 event_extended
= (struct lttng_event_extended
*) event
->extended
.ptr
;
59 if (event_extended
->probe_location
) {
60 lttng_userspace_probe_location_destroy(
61 event_extended
->probe_location
);
68 int lttng_event_get_filter_expression(struct lttng_event
*event
,
69 const char **filter_expression
)
72 struct lttng_event_extended
*event_extended
;
74 if (!event
|| !filter_expression
) {
75 ret
= -LTTNG_ERR_INVALID
;
79 event_extended
= (struct lttng_event_extended
*) event
->extended
.ptr
;
80 if (!event_extended
) {
82 * This can happen since the lttng_event structure is
83 * used for other tasks where this pointer is never set.
85 *filter_expression
= NULL
;
89 *filter_expression
= event_extended
->filter_expression
;
94 int lttng_event_get_exclusion_name_count(struct lttng_event
*event
)
97 struct lttng_event_extended
*event_extended
;
100 ret
= -LTTNG_ERR_INVALID
;
104 event_extended
= (struct lttng_event_extended
*) event
->extended
.ptr
;
105 if (!event_extended
) {
107 * This can happen since the lttng_event structure is
108 * used for other tasks where this pointer is never set.
113 if (event_extended
->exclusions
.count
> INT_MAX
) {
114 ret
= -LTTNG_ERR_OVERFLOW
;
117 ret
= (int) event_extended
->exclusions
.count
;
122 int lttng_event_get_exclusion_name(struct lttng_event
*event
,
123 size_t index
, const char **exclusion_name
)
126 struct lttng_event_extended
*event_extended
;
128 if (!event
|| !exclusion_name
) {
129 ret
= -LTTNG_ERR_INVALID
;
133 if (index
> UINT_MAX
) {
134 ret
= -LTTNG_ERR_OVERFLOW
;
138 event_extended
= (struct lttng_event_extended
*) event
->extended
.ptr
;
139 if (!event_extended
) {
141 * This can happen since the lttng_event structure is
142 * used for other tasks where this pointer is never set.
144 ret
= -LTTNG_ERR_INVALID
;
148 if (index
>= event_extended
->exclusions
.count
) {
149 ret
= -LTTNG_ERR_INVALID
;
153 *exclusion_name
= event_extended
->exclusions
.strings
+
154 (index
* LTTNG_SYMBOL_NAME_LEN
);
159 const struct lttng_userspace_probe_location
*
160 lttng_event_get_userspace_probe_location(const struct lttng_event
*event
)
162 struct lttng_userspace_probe_location
*probe_location
= NULL
;
163 struct lttng_event_extended
*event_extended
;
169 event_extended
= (struct lttng_event_extended
*) event
->extended
.ptr
;
170 if (!event_extended
) {
173 probe_location
= event_extended
->probe_location
;
175 return probe_location
;
178 int lttng_event_set_userspace_probe_location(struct lttng_event
*event
,
179 struct lttng_userspace_probe_location
*probe_location
)
182 struct lttng_event_extended
*event_extended
;
184 if (!event
|| !probe_location
) {
185 ret
= -LTTNG_ERR_INVALID
;
189 event_extended
= (struct lttng_event_extended
*) event
->extended
.ptr
;
190 assert(event_extended
);
191 if (event_extended
->probe_location
) {
192 lttng_userspace_probe_location_destroy(
193 event_extended
->probe_location
);
195 event_extended
->probe_location
= probe_location
;