4 * Linux Trace Toolkit Control Library
6 * Copyright (C) 2017 - Jérémie Galarneau <jeremie.galarneau@efficios.com>
8 * This library is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU Lesser General Public License, version 2.1 only,
10 * as published by the Free Software Foundation.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with this library; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
26 #include <common/error.h>
27 #include <common/sessiond-comm/sessiond-comm.h>
28 #include <lttng/event-internal.h>
29 #include <lttng/event.h>
30 #include <lttng/lttng-error.h>
31 #include <lttng/userspace-probe-internal.h>
33 struct lttng_event
*lttng_event_create(void)
35 struct lttng_event
*event
;
36 struct lttng_event_extended
*event_extended
;
38 event
= zmalloc(sizeof(*event
));
40 PERROR("Error allocating event structure");
44 event_extended
= zmalloc(sizeof(*event_extended
));
45 if (!event_extended
) {
46 PERROR("Error allocating event extended structure");
49 event
->extended
.ptr
= event_extended
;
58 void lttng_event_destroy(struct lttng_event
*event
)
60 struct lttng_event_extended
*event_extended
;
66 event_extended
= (struct lttng_event_extended
*) event
->extended
.ptr
;
69 if (event_extended
->probe_location
) {
70 lttng_userspace_probe_location_destroy(
71 event_extended
->probe_location
);
78 int lttng_event_get_filter_expression(struct lttng_event
*event
,
79 const char **filter_expression
)
82 struct lttng_event_extended
*event_extended
;
84 if (!event
|| !filter_expression
) {
85 ret
= -LTTNG_ERR_INVALID
;
89 event_extended
= (struct lttng_event_extended
*) event
->extended
.ptr
;
90 if (!event_extended
) {
92 * This can happen since the lttng_event structure is
93 * used for other tasks where this pointer is never set.
95 *filter_expression
= NULL
;
99 *filter_expression
= event_extended
->filter_expression
;
104 int lttng_event_get_exclusion_name_count(struct lttng_event
*event
)
107 struct lttng_event_extended
*event_extended
;
110 ret
= -LTTNG_ERR_INVALID
;
114 event_extended
= (struct lttng_event_extended
*) event
->extended
.ptr
;
115 if (!event_extended
) {
117 * This can happen since the lttng_event structure is
118 * used for other tasks where this pointer is never set.
123 if (event_extended
->exclusions
.count
> INT_MAX
) {
124 ret
= -LTTNG_ERR_OVERFLOW
;
127 ret
= (int) event_extended
->exclusions
.count
;
132 int lttng_event_get_exclusion_name(struct lttng_event
*event
,
133 size_t index
, const char **exclusion_name
)
136 struct lttng_event_extended
*event_extended
;
138 if (!event
|| !exclusion_name
) {
139 ret
= -LTTNG_ERR_INVALID
;
143 if (index
> UINT_MAX
) {
144 ret
= -LTTNG_ERR_OVERFLOW
;
148 event_extended
= (struct lttng_event_extended
*) event
->extended
.ptr
;
149 if (!event_extended
) {
151 * This can happen since the lttng_event structure is
152 * used for other tasks where this pointer is never set.
154 ret
= -LTTNG_ERR_INVALID
;
158 if (index
>= event_extended
->exclusions
.count
) {
159 ret
= -LTTNG_ERR_INVALID
;
163 *exclusion_name
= event_extended
->exclusions
.strings
+
164 (index
* LTTNG_SYMBOL_NAME_LEN
);
169 const struct lttng_userspace_probe_location
*
170 lttng_event_get_userspace_probe_location(const struct lttng_event
*event
)
172 struct lttng_userspace_probe_location
*probe_location
= NULL
;
173 struct lttng_event_extended
*event_extended
;
179 event_extended
= (struct lttng_event_extended
*) event
->extended
.ptr
;
180 if (!event_extended
) {
183 probe_location
= event_extended
->probe_location
;
185 return probe_location
;
188 int lttng_event_set_userspace_probe_location(struct lttng_event
*event
,
189 struct lttng_userspace_probe_location
*probe_location
)
192 struct lttng_event_extended
*event_extended
;
194 if (!event
|| !probe_location
) {
195 ret
= -LTTNG_ERR_INVALID
;
199 event_extended
= (struct lttng_event_extended
*) event
->extended
.ptr
;
200 assert(event_extended
);
201 if (event_extended
->probe_location
) {
202 lttng_userspace_probe_location_destroy(
203 event_extended
->probe_location
);
205 event_extended
->probe_location
= probe_location
;