Commit | Line | Data |
---|---|---|
eb5c4f4e JG |
1 | /* |
2 | * event.c | |
3 | * | |
4 | * Linux Trace Toolkit Control Library | |
5 | * | |
6 | * Copyright (C) 2017 - Jérémie Galarneau <jeremie.galarneau@efficios.com> | |
7 | * | |
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. | |
11 | * | |
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. | |
16 | * | |
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 | |
20 | */ | |
21 | ||
22 | #define _LGPL_SOURCE | |
ef0e06bc | 23 | #include <assert.h> |
eb5c4f4e | 24 | #include <stddef.h> |
ef0e06bc JG |
25 | |
26 | #include <common/error.h> | |
eb5c4f4e | 27 | #include <common/sessiond-comm/sessiond-comm.h> |
ef0e06bc JG |
28 | #include <lttng/event-internal.h> |
29 | #include <lttng/event.h> | |
30 | #include <lttng/lttng-error.h> | |
31 | #include <lttng/userspace-probe-internal.h> | |
32 | ||
33 | struct lttng_event *lttng_event_create(void) | |
34 | { | |
35 | struct lttng_event *event; | |
36 | struct lttng_event_extended *event_extended; | |
37 | ||
38 | event = zmalloc(sizeof(*event)); | |
39 | if (!event) { | |
40 | PERROR("Error allocating event structure"); | |
41 | goto end; | |
42 | } | |
43 | ||
44 | event_extended = zmalloc(sizeof(*event_extended)); | |
45 | if (!event_extended) { | |
46 | PERROR("Error allocating event extended structure"); | |
47 | goto error; | |
48 | } | |
49 | event->extended.ptr = event_extended; | |
50 | end: | |
51 | return event; | |
52 | error: | |
53 | free(event); | |
54 | goto end; | |
55 | } | |
56 | ||
abcc74fa FD |
57 | struct lttng_event *lttng_event_copy(const struct lttng_event *event) |
58 | { | |
59 | struct lttng_event *new_event; | |
60 | struct lttng_event_extended *new_event_extended; | |
61 | ||
62 | new_event = zmalloc(sizeof(*event)); | |
63 | if (!event) { | |
64 | PERROR("Error allocating event structure"); | |
65 | goto end; | |
66 | } | |
67 | ||
68 | /* Copy the content of the old event. */ | |
69 | memcpy(new_event, event, sizeof(*event)); | |
70 | ||
71 | /* | |
72 | * We need to create a new extended since the previous pointer is now | |
73 | * invalid. | |
74 | */ | |
75 | new_event_extended = zmalloc(sizeof(*new_event_extended)); | |
76 | if (!new_event_extended) { | |
77 | PERROR("Error allocating event extended structure"); | |
78 | goto error; | |
79 | } | |
80 | ||
81 | new_event->extended.ptr = new_event_extended; | |
82 | end: | |
83 | return new_event; | |
84 | error: | |
85 | free(event); | |
86 | goto end; | |
87 | } | |
88 | ||
ef0e06bc JG |
89 | void lttng_event_destroy(struct lttng_event *event) |
90 | { | |
91 | struct lttng_event_extended *event_extended; | |
92 | ||
93 | if (!event) { | |
94 | return; | |
95 | } | |
96 | ||
97 | event_extended = (struct lttng_event_extended *) event->extended.ptr; | |
98 | ||
99 | if (event_extended) { | |
100 | if (event_extended->probe_location) { | |
101 | lttng_userspace_probe_location_destroy( | |
102 | event_extended->probe_location); | |
103 | } | |
104 | free(event_extended); | |
105 | } | |
106 | free(event); | |
107 | } | |
eb5c4f4e JG |
108 | |
109 | int lttng_event_get_filter_expression(struct lttng_event *event, | |
110 | const char **filter_expression) | |
111 | { | |
112 | int ret = 0; | |
de453daa | 113 | struct lttng_event_extended *event_extended; |
eb5c4f4e JG |
114 | |
115 | if (!event || !filter_expression) { | |
116 | ret = -LTTNG_ERR_INVALID; | |
117 | goto end; | |
118 | } | |
119 | ||
de453daa JG |
120 | event_extended = (struct lttng_event_extended *) event->extended.ptr; |
121 | if (!event_extended) { | |
eb5c4f4e JG |
122 | /* |
123 | * This can happen since the lttng_event structure is | |
124 | * used for other tasks where this pointer is never set. | |
125 | */ | |
126 | *filter_expression = NULL; | |
127 | goto end; | |
128 | } | |
129 | ||
de453daa | 130 | *filter_expression = event_extended->filter_expression; |
eb5c4f4e JG |
131 | end: |
132 | return ret; | |
133 | } | |
134 | ||
135 | int lttng_event_get_exclusion_name_count(struct lttng_event *event) | |
136 | { | |
de453daa JG |
137 | int ret = 0; |
138 | struct lttng_event_extended *event_extended; | |
eb5c4f4e JG |
139 | |
140 | if (!event) { | |
141 | ret = -LTTNG_ERR_INVALID; | |
142 | goto end; | |
143 | } | |
144 | ||
de453daa JG |
145 | event_extended = (struct lttng_event_extended *) event->extended.ptr; |
146 | if (!event_extended) { | |
eb5c4f4e JG |
147 | /* |
148 | * This can happen since the lttng_event structure is | |
149 | * used for other tasks where this pointer is never set. | |
150 | */ | |
eb5c4f4e JG |
151 | goto end; |
152 | } | |
153 | ||
de453daa | 154 | if (event_extended->exclusions.count > INT_MAX) { |
eb5c4f4e JG |
155 | ret = -LTTNG_ERR_OVERFLOW; |
156 | goto end; | |
157 | } | |
de453daa | 158 | ret = (int) event_extended->exclusions.count; |
eb5c4f4e JG |
159 | end: |
160 | return ret; | |
161 | } | |
162 | ||
163 | int lttng_event_get_exclusion_name(struct lttng_event *event, | |
164 | size_t index, const char **exclusion_name) | |
165 | { | |
166 | int ret = 0; | |
de453daa | 167 | struct lttng_event_extended *event_extended; |
eb5c4f4e JG |
168 | |
169 | if (!event || !exclusion_name) { | |
170 | ret = -LTTNG_ERR_INVALID; | |
171 | goto end; | |
172 | } | |
173 | ||
de453daa JG |
174 | if (index > UINT_MAX) { |
175 | ret = -LTTNG_ERR_OVERFLOW; | |
eb5c4f4e JG |
176 | goto end; |
177 | } | |
178 | ||
de453daa JG |
179 | event_extended = (struct lttng_event_extended *) event->extended.ptr; |
180 | if (!event_extended) { | |
181 | /* | |
182 | * This can happen since the lttng_event structure is | |
183 | * used for other tasks where this pointer is never set. | |
184 | */ | |
eb5c4f4e JG |
185 | ret = -LTTNG_ERR_INVALID; |
186 | goto end; | |
187 | } | |
188 | ||
de453daa JG |
189 | if (index >= event_extended->exclusions.count) { |
190 | ret = -LTTNG_ERR_INVALID; | |
191 | goto end; | |
192 | } | |
eb5c4f4e | 193 | |
de453daa JG |
194 | *exclusion_name = event_extended->exclusions.strings + |
195 | (index * LTTNG_SYMBOL_NAME_LEN); | |
eb5c4f4e JG |
196 | end: |
197 | return ret; | |
198 | } | |
ef0e06bc JG |
199 | |
200 | struct lttng_userspace_probe_location * | |
201 | lttng_event_get_userspace_probe_location(struct lttng_event *event) | |
202 | { | |
203 | struct lttng_userspace_probe_location *probe_location = NULL; | |
204 | struct lttng_event_extended *event_extended; | |
205 | ||
206 | if (!event) { | |
207 | goto end; | |
208 | } | |
209 | ||
210 | event_extended = (struct lttng_event_extended *) event->extended.ptr; | |
211 | if (!event_extended) { | |
212 | goto end; | |
213 | } | |
214 | probe_location = event_extended->probe_location; | |
215 | end: | |
216 | return probe_location; | |
217 | } | |
218 | ||
219 | int lttng_event_set_userspace_probe_location(struct lttng_event *event, | |
220 | struct lttng_userspace_probe_location *probe_location) | |
221 | { | |
222 | int ret = 0; | |
223 | struct lttng_event_extended *event_extended; | |
224 | ||
225 | if (!event || !probe_location) { | |
226 | ret = -LTTNG_ERR_INVALID; | |
227 | goto end; | |
228 | } | |
229 | ||
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); | |
235 | } | |
236 | event_extended->probe_location = probe_location; | |
237 | end: | |
238 | return ret; | |
239 | } |