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 lttng_event_extended
*event_extended
;
83 if (!event
|| !filter_expression
) {
84 ret
= -LTTNG_ERR_INVALID
;
88 event_extended
= (struct lttng_event_extended
*) event
->extended
.ptr
;
89 if (!event_extended
) {
91 * This can happen since the lttng_event structure is
92 * used for other tasks where this pointer is never set.
94 *filter_expression
= NULL
;
98 *filter_expression
= event_extended
->filter_expression
;
103 int lttng_event_get_exclusion_name_count(struct lttng_event
*event
)
106 struct lttng_event_extended
*event_extended
;
109 ret
= -LTTNG_ERR_INVALID
;
113 event_extended
= (struct lttng_event_extended
*) event
->extended
.ptr
;
114 if (!event_extended
) {
116 * This can happen since the lttng_event structure is
117 * used for other tasks where this pointer is never set.
122 if (event_extended
->exclusions
.count
> INT_MAX
) {
123 ret
= -LTTNG_ERR_OVERFLOW
;
126 ret
= (int) event_extended
->exclusions
.count
;
131 int lttng_event_get_exclusion_name(struct lttng_event
*event
,
132 size_t index
, const char **exclusion_name
)
135 struct lttng_event_extended
*event_extended
;
137 if (!event
|| !exclusion_name
) {
138 ret
= -LTTNG_ERR_INVALID
;
142 if (index
> UINT_MAX
) {
143 ret
= -LTTNG_ERR_OVERFLOW
;
147 event_extended
= (struct lttng_event_extended
*) event
->extended
.ptr
;
148 if (!event_extended
) {
150 * This can happen since the lttng_event structure is
151 * used for other tasks where this pointer is never set.
153 ret
= -LTTNG_ERR_INVALID
;
157 if (index
>= event_extended
->exclusions
.count
) {
158 ret
= -LTTNG_ERR_INVALID
;
162 *exclusion_name
= event_extended
->exclusions
.strings
+
163 (index
* LTTNG_SYMBOL_NAME_LEN
);
168 const struct lttng_userspace_probe_location
*
169 lttng_event_get_userspace_probe_location(const struct lttng_event
*event
)
171 struct lttng_userspace_probe_location
*probe_location
= NULL
;
172 struct lttng_event_extended
*event_extended
;
178 event_extended
= (struct lttng_event_extended
*) event
->extended
.ptr
;
179 if (!event_extended
) {
182 probe_location
= event_extended
->probe_location
;
184 return probe_location
;
187 int lttng_event_set_userspace_probe_location(struct lttng_event
*event
,
188 struct lttng_userspace_probe_location
*probe_location
)
191 struct lttng_event_extended
*event_extended
;
193 if (!event
|| !probe_location
) {
194 ret
= -LTTNG_ERR_INVALID
;
198 event_extended
= (struct lttng_event_extended
*) event
->extended
.ptr
;
199 assert(event_extended
);
200 if (event_extended
->probe_location
) {
201 lttng_userspace_probe_location_destroy(
202 event_extended
->probe_location
);
204 event_extended
->probe_location
= probe_location
;