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
;
57 struct lttng_event
*lttng_event_copy(const struct lttng_event
*event
)
59 struct lttng_event
*new_event
;
60 struct lttng_event_extended
*new_event_extended
;
62 new_event
= zmalloc(sizeof(*event
));
64 PERROR("Error allocating event structure");
68 /* Copy the content of the old event. */
69 memcpy(new_event
, event
, sizeof(*event
));
72 * We need to create a new extended since the previous pointer is now
75 new_event_extended
= zmalloc(sizeof(*new_event_extended
));
76 if (!new_event_extended
) {
77 PERROR("Error allocating event extended structure");
81 new_event
->extended
.ptr
= new_event_extended
;
89 void lttng_event_destroy(struct lttng_event
*event
)
91 struct lttng_event_extended
*event_extended
;
97 event_extended
= (struct lttng_event_extended
*) event
->extended
.ptr
;
100 if (event_extended
->probe_location
) {
101 lttng_userspace_probe_location_destroy(
102 event_extended
->probe_location
);
104 free(event_extended
);
109 int lttng_event_get_filter_expression(struct lttng_event
*event
,
110 const char **filter_expression
)
113 struct lttng_event_extended
*event_extended
;
115 if (!event
|| !filter_expression
) {
116 ret
= -LTTNG_ERR_INVALID
;
120 event_extended
= (struct lttng_event_extended
*) event
->extended
.ptr
;
121 if (!event_extended
) {
123 * This can happen since the lttng_event structure is
124 * used for other tasks where this pointer is never set.
126 *filter_expression
= NULL
;
130 *filter_expression
= event_extended
->filter_expression
;
135 int lttng_event_get_exclusion_name_count(struct lttng_event
*event
)
138 struct lttng_event_extended
*event_extended
;
141 ret
= -LTTNG_ERR_INVALID
;
145 event_extended
= (struct lttng_event_extended
*) event
->extended
.ptr
;
146 if (!event_extended
) {
148 * This can happen since the lttng_event structure is
149 * used for other tasks where this pointer is never set.
154 if (event_extended
->exclusions
.count
> INT_MAX
) {
155 ret
= -LTTNG_ERR_OVERFLOW
;
158 ret
= (int) event_extended
->exclusions
.count
;
163 int lttng_event_get_exclusion_name(struct lttng_event
*event
,
164 size_t index
, const char **exclusion_name
)
167 struct lttng_event_extended
*event_extended
;
169 if (!event
|| !exclusion_name
) {
170 ret
= -LTTNG_ERR_INVALID
;
174 if (index
> UINT_MAX
) {
175 ret
= -LTTNG_ERR_OVERFLOW
;
179 event_extended
= (struct lttng_event_extended
*) event
->extended
.ptr
;
180 if (!event_extended
) {
182 * This can happen since the lttng_event structure is
183 * used for other tasks where this pointer is never set.
185 ret
= -LTTNG_ERR_INVALID
;
189 if (index
>= event_extended
->exclusions
.count
) {
190 ret
= -LTTNG_ERR_INVALID
;
194 *exclusion_name
= event_extended
->exclusions
.strings
+
195 (index
* LTTNG_SYMBOL_NAME_LEN
);
200 struct lttng_userspace_probe_location
*
201 lttng_event_get_userspace_probe_location(struct lttng_event
*event
)
203 struct lttng_userspace_probe_location
*probe_location
= NULL
;
204 struct lttng_event_extended
*event_extended
;
210 event_extended
= (struct lttng_event_extended
*) event
->extended
.ptr
;
211 if (!event_extended
) {
214 probe_location
= event_extended
->probe_location
;
216 return probe_location
;
219 int lttng_event_set_userspace_probe_location(struct lttng_event
*event
,
220 struct lttng_userspace_probe_location
*probe_location
)
223 struct lttng_event_extended
*event_extended
;
225 if (!event
|| !probe_location
) {
226 ret
= -LTTNG_ERR_INVALID
;
230 event_extended
= (struct lttng_event_extended
*) event
->extended
.ptr
;
231 assert(event_extended
);
232 if (event_extended
->probe_location
) {
233 lttng_userspace_probe_location_destroy(
234 event_extended
->probe_location
);
236 event_extended
->probe_location
= probe_location
;