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
15 #include <common/error.h>
16 #include <common/sessiond-comm/sessiond-comm.h>
17 #include <lttng/event-internal.h>
18 #include <lttng/event.h>
19 #include <lttng/lttng-error.h>
20 #include <lttng/userspace-probe-internal.h>
22 struct lttng_event
*lttng_event_create(void)
24 struct lttng_event
*event
;
25 struct lttng_event_extended
*event_extended
;
27 event
= (lttng_event
*) zmalloc(sizeof(*event
));
29 PERROR("Error allocating event structure");
33 event_extended
= (lttng_event_extended
*) zmalloc(sizeof(*event_extended
));
34 if (!event_extended
) {
35 PERROR("Error allocating event extended structure");
38 event
->extended
.ptr
= event_extended
;
47 void lttng_event_destroy(struct lttng_event
*event
)
49 struct lttng_event_extended
*event_extended
;
55 event_extended
= (struct lttng_event_extended
*) event
->extended
.ptr
;
58 if (event_extended
->probe_location
) {
59 lttng_userspace_probe_location_destroy(
60 event_extended
->probe_location
);
67 int lttng_event_get_filter_expression(struct lttng_event
*event
,
68 const char **filter_expression
)
71 struct lttng_event_extended
*event_extended
;
73 if (!event
|| !filter_expression
) {
74 ret
= -LTTNG_ERR_INVALID
;
78 event_extended
= (struct lttng_event_extended
*) event
->extended
.ptr
;
79 if (!event_extended
) {
81 * This can happen since the lttng_event structure is
82 * used for other tasks where this pointer is never set.
84 *filter_expression
= NULL
;
88 *filter_expression
= event_extended
->filter_expression
;
93 int lttng_event_get_exclusion_name_count(struct lttng_event
*event
)
96 struct lttng_event_extended
*event_extended
;
99 ret
= -LTTNG_ERR_INVALID
;
103 event_extended
= (struct lttng_event_extended
*) event
->extended
.ptr
;
104 if (!event_extended
) {
106 * This can happen since the lttng_event structure is
107 * used for other tasks where this pointer is never set.
112 if (event_extended
->exclusions
.count
> INT_MAX
) {
113 ret
= -LTTNG_ERR_OVERFLOW
;
116 ret
= (int) event_extended
->exclusions
.count
;
121 int lttng_event_get_exclusion_name(struct lttng_event
*event
,
122 size_t index
, const char **exclusion_name
)
125 struct lttng_event_extended
*event_extended
;
127 if (!event
|| !exclusion_name
) {
128 ret
= -LTTNG_ERR_INVALID
;
132 if (index
> UINT_MAX
) {
133 ret
= -LTTNG_ERR_OVERFLOW
;
137 event_extended
= (struct lttng_event_extended
*) event
->extended
.ptr
;
138 if (!event_extended
) {
140 * This can happen since the lttng_event structure is
141 * used for other tasks where this pointer is never set.
143 ret
= -LTTNG_ERR_INVALID
;
147 if (index
>= event_extended
->exclusions
.count
) {
148 ret
= -LTTNG_ERR_INVALID
;
152 *exclusion_name
= event_extended
->exclusions
.strings
+
153 (index
* LTTNG_SYMBOL_NAME_LEN
);
158 const struct lttng_userspace_probe_location
*
159 lttng_event_get_userspace_probe_location(const struct lttng_event
*event
)
161 struct lttng_userspace_probe_location
*probe_location
= NULL
;
162 struct lttng_event_extended
*event_extended
;
168 event_extended
= (struct lttng_event_extended
*) event
->extended
.ptr
;
169 if (!event_extended
) {
172 probe_location
= event_extended
->probe_location
;
174 return probe_location
;
177 int lttng_event_set_userspace_probe_location(struct lttng_event
*event
,
178 struct lttng_userspace_probe_location
*probe_location
)
181 struct lttng_event_extended
*event_extended
;
183 if (!event
|| !probe_location
) {
184 ret
= -LTTNG_ERR_INVALID
;
188 event_extended
= (struct lttng_event_extended
*) event
->extended
.ptr
;
189 LTTNG_ASSERT(event_extended
);
190 if (event_extended
->probe_location
) {
191 lttng_userspace_probe_location_destroy(
192 event_extended
->probe_location
);
194 event_extended
->probe_location
= probe_location
;