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
13 #include <common/error.hpp>
14 #include <common/sessiond-comm/sessiond-comm.hpp>
16 #include <lttng/event-internal.hpp>
17 #include <lttng/event.h>
18 #include <lttng/lttng-error.h>
19 #include <lttng/userspace-probe-internal.hpp>
23 struct lttng_event
*lttng_event_create(void)
25 struct lttng_event
*event
;
26 struct lttng_event_extended
*event_extended
;
28 event
= zmalloc
<lttng_event
>();
30 PERROR("Error allocating event structure");
34 event_extended
= zmalloc
<lttng_event_extended
>();
35 if (!event_extended
) {
36 PERROR("Error allocating event extended structure");
39 event
->extended
.ptr
= event_extended
;
48 void lttng_event_destroy(struct lttng_event
*event
)
50 struct lttng_event_extended
*event_extended
;
56 event_extended
= (struct lttng_event_extended
*) event
->extended
.ptr
;
59 if (event_extended
->probe_location
) {
60 lttng_userspace_probe_location_destroy(event_extended
->probe_location
);
67 int lttng_event_get_filter_expression(struct lttng_event
*event
, const char **filter_expression
)
70 struct lttng_event_extended
*event_extended
;
72 if (!event
|| !filter_expression
) {
73 ret
= -LTTNG_ERR_INVALID
;
77 event_extended
= (struct lttng_event_extended
*) event
->extended
.ptr
;
78 if (!event_extended
) {
80 * This can happen since the lttng_event structure is
81 * used for other tasks where this pointer is never set.
83 *filter_expression
= nullptr;
87 *filter_expression
= event_extended
->filter_expression
;
92 int lttng_event_get_exclusion_name_count(struct lttng_event
*event
)
95 struct lttng_event_extended
*event_extended
;
98 ret
= -LTTNG_ERR_INVALID
;
102 event_extended
= (struct lttng_event_extended
*) event
->extended
.ptr
;
103 if (!event_extended
) {
105 * This can happen since the lttng_event structure is
106 * used for other tasks where this pointer is never set.
111 if (event_extended
->exclusions
.count
> INT_MAX
) {
112 ret
= -LTTNG_ERR_OVERFLOW
;
115 ret
= (int) event_extended
->exclusions
.count
;
120 int lttng_event_get_exclusion_name(struct lttng_event
*event
,
122 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
+ (index
* LTTNG_SYMBOL_NAME_LEN
);
157 const struct lttng_userspace_probe_location
*
158 lttng_event_get_userspace_probe_location(const struct lttng_event
*event
)
160 struct lttng_userspace_probe_location
*probe_location
= nullptr;
161 struct lttng_event_extended
*event_extended
;
167 event_extended
= (struct lttng_event_extended
*) event
->extended
.ptr
;
168 if (!event_extended
) {
171 probe_location
= event_extended
->probe_location
;
173 return probe_location
;
176 int lttng_event_set_userspace_probe_location(struct lttng_event
*event
,
177 struct lttng_userspace_probe_location
*probe_location
)
180 struct lttng_event_extended
*event_extended
;
182 if (!event
|| !probe_location
) {
183 ret
= -LTTNG_ERR_INVALID
;
187 event_extended
= (struct lttng_event_extended
*) event
->extended
.ptr
;
188 LTTNG_ASSERT(event_extended
);
189 if (event_extended
->probe_location
) {
190 lttng_userspace_probe_location_destroy(event_extended
->probe_location
);
192 event_extended
->probe_location
= probe_location
;