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 void lttng_event_destroy(struct lttng_event
*event
)
59 struct lttng_event_extended
*event_extended
;
65 event_extended
= (struct lttng_event_extended
*) event
->extended
.ptr
;
68 if (event_extended
->probe_location
) {
69 lttng_userspace_probe_location_destroy(
70 event_extended
->probe_location
);
77 int lttng_event_get_filter_expression(struct lttng_event
*event
,
78 const char **filter_expression
)
81 struct lttcomm_event_extended_header
*ext_header
;
83 if (!event
|| !filter_expression
) {
84 ret
= -LTTNG_ERR_INVALID
;
88 ext_header
= event
->extended
.ptr
;
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 if (ext_header
->filter_len
) {
100 *filter_expression
= ((const char *) (ext_header
)) +
103 *filter_expression
= NULL
;
110 int lttng_event_get_exclusion_name_count(struct lttng_event
*event
)
113 struct lttcomm_event_extended_header
*ext_header
;
116 ret
= -LTTNG_ERR_INVALID
;
120 ext_header
= event
->extended
.ptr
;
123 * This can happen since the lttng_event structure is
124 * used for other tasks where this pointer is never set.
130 if (ext_header
->nb_exclusions
> INT_MAX
) {
131 ret
= -LTTNG_ERR_OVERFLOW
;
134 ret
= (int) ext_header
->nb_exclusions
;
139 int lttng_event_get_exclusion_name(struct lttng_event
*event
,
140 size_t index
, const char **exclusion_name
)
143 struct lttcomm_event_extended_header
*ext_header
;
146 if (!event
|| !exclusion_name
) {
147 ret
= -LTTNG_ERR_INVALID
;
151 ext_header
= event
->extended
.ptr
;
153 ret
= -LTTNG_ERR_INVALID
;
157 if (index
>= ext_header
->nb_exclusions
) {
158 ret
= -LTTNG_ERR_INVALID
;
162 at
= (void *) ext_header
+ sizeof(*ext_header
);
163 at
+= ext_header
->filter_len
;
164 at
+= index
* LTTNG_SYMBOL_NAME_LEN
;
165 *exclusion_name
= at
;
171 struct lttng_userspace_probe_location
*
172 lttng_event_get_userspace_probe_location(struct lttng_event
*event
)
174 struct lttng_userspace_probe_location
*probe_location
= NULL
;
175 struct lttng_event_extended
*event_extended
;
181 event_extended
= (struct lttng_event_extended
*) event
->extended
.ptr
;
182 if (!event_extended
) {
185 probe_location
= event_extended
->probe_location
;
187 return probe_location
;
190 int lttng_event_set_userspace_probe_location(struct lttng_event
*event
,
191 struct lttng_userspace_probe_location
*probe_location
)
194 struct lttng_event_extended
*event_extended
;
196 if (!event
|| !probe_location
) {
197 ret
= -LTTNG_ERR_INVALID
;
201 event_extended
= (struct lttng_event_extended
*) event
->extended
.ptr
;
202 assert(event_extended
);
203 if (event_extended
->probe_location
) {
204 lttng_userspace_probe_location_destroy(
205 event_extended
->probe_location
);
207 event_extended
->probe_location
= probe_location
;