Force usage of assert() condition when NDEBUG is defined
[lttng-tools.git] / src / lib / lttng-ctl / event.c
CommitLineData
eb5c4f4e
JG
1/*
2 * event.c
3 *
4 * Linux Trace Toolkit Control Library
5 *
ab5be9fa 6 * Copyright (C) 2017 Jérémie Galarneau <jeremie.galarneau@efficios.com>
eb5c4f4e 7 *
ab5be9fa 8 * SPDX-License-Identifier: LGPL-2.1-only
eb5c4f4e 9 *
eb5c4f4e
JG
10 */
11
12#define _LGPL_SOURCE
eb5c4f4e 13#include <stddef.h>
ef0e06bc
JG
14
15#include <common/error.h>
eb5c4f4e 16#include <common/sessiond-comm/sessiond-comm.h>
ef0e06bc
JG
17#include <lttng/event-internal.h>
18#include <lttng/event.h>
19#include <lttng/lttng-error.h>
20#include <lttng/userspace-probe-internal.h>
21
22struct lttng_event *lttng_event_create(void)
23{
24 struct lttng_event *event;
25 struct lttng_event_extended *event_extended;
26
27 event = zmalloc(sizeof(*event));
28 if (!event) {
29 PERROR("Error allocating event structure");
30 goto end;
31 }
32
33 event_extended = zmalloc(sizeof(*event_extended));
34 if (!event_extended) {
35 PERROR("Error allocating event extended structure");
36 goto error;
37 }
38 event->extended.ptr = event_extended;
39end:
40 return event;
41error:
42 free(event);
37750a61 43 event = NULL;
ef0e06bc
JG
44 goto end;
45}
46
47void lttng_event_destroy(struct lttng_event *event)
48{
49 struct lttng_event_extended *event_extended;
50
51 if (!event) {
52 return;
53 }
54
55 event_extended = (struct lttng_event_extended *) event->extended.ptr;
56
57 if (event_extended) {
58 if (event_extended->probe_location) {
59 lttng_userspace_probe_location_destroy(
60 event_extended->probe_location);
61 }
62 free(event_extended);
63 }
64 free(event);
65}
eb5c4f4e
JG
66
67int lttng_event_get_filter_expression(struct lttng_event *event,
68 const char **filter_expression)
69{
70 int ret = 0;
de453daa 71 struct lttng_event_extended *event_extended;
eb5c4f4e
JG
72
73 if (!event || !filter_expression) {
74 ret = -LTTNG_ERR_INVALID;
75 goto end;
76 }
77
de453daa
JG
78 event_extended = (struct lttng_event_extended *) event->extended.ptr;
79 if (!event_extended) {
eb5c4f4e
JG
80 /*
81 * This can happen since the lttng_event structure is
82 * used for other tasks where this pointer is never set.
83 */
84 *filter_expression = NULL;
85 goto end;
86 }
87
de453daa 88 *filter_expression = event_extended->filter_expression;
eb5c4f4e
JG
89end:
90 return ret;
91}
92
93int lttng_event_get_exclusion_name_count(struct lttng_event *event)
94{
de453daa
JG
95 int ret = 0;
96 struct lttng_event_extended *event_extended;
eb5c4f4e
JG
97
98 if (!event) {
99 ret = -LTTNG_ERR_INVALID;
100 goto end;
101 }
102
de453daa
JG
103 event_extended = (struct lttng_event_extended *) event->extended.ptr;
104 if (!event_extended) {
eb5c4f4e
JG
105 /*
106 * This can happen since the lttng_event structure is
107 * used for other tasks where this pointer is never set.
108 */
eb5c4f4e
JG
109 goto end;
110 }
111
de453daa 112 if (event_extended->exclusions.count > INT_MAX) {
eb5c4f4e
JG
113 ret = -LTTNG_ERR_OVERFLOW;
114 goto end;
115 }
de453daa 116 ret = (int) event_extended->exclusions.count;
eb5c4f4e
JG
117end:
118 return ret;
119}
120
121int lttng_event_get_exclusion_name(struct lttng_event *event,
122 size_t index, const char **exclusion_name)
123{
124 int ret = 0;
de453daa 125 struct lttng_event_extended *event_extended;
eb5c4f4e
JG
126
127 if (!event || !exclusion_name) {
128 ret = -LTTNG_ERR_INVALID;
129 goto end;
130 }
131
de453daa
JG
132 if (index > UINT_MAX) {
133 ret = -LTTNG_ERR_OVERFLOW;
eb5c4f4e
JG
134 goto end;
135 }
136
de453daa
JG
137 event_extended = (struct lttng_event_extended *) event->extended.ptr;
138 if (!event_extended) {
139 /*
140 * This can happen since the lttng_event structure is
141 * used for other tasks where this pointer is never set.
142 */
eb5c4f4e
JG
143 ret = -LTTNG_ERR_INVALID;
144 goto end;
145 }
146
de453daa
JG
147 if (index >= event_extended->exclusions.count) {
148 ret = -LTTNG_ERR_INVALID;
149 goto end;
150 }
eb5c4f4e 151
de453daa
JG
152 *exclusion_name = event_extended->exclusions.strings +
153 (index * LTTNG_SYMBOL_NAME_LEN);
eb5c4f4e
JG
154end:
155 return ret;
156}
ef0e06bc 157
87597c2c
JG
158const struct lttng_userspace_probe_location *
159lttng_event_get_userspace_probe_location(const struct lttng_event *event)
ef0e06bc
JG
160{
161 struct lttng_userspace_probe_location *probe_location = NULL;
162 struct lttng_event_extended *event_extended;
163
164 if (!event) {
165 goto end;
166 }
167
168 event_extended = (struct lttng_event_extended *) event->extended.ptr;
169 if (!event_extended) {
170 goto end;
171 }
172 probe_location = event_extended->probe_location;
173end:
174 return probe_location;
175}
176
177int lttng_event_set_userspace_probe_location(struct lttng_event *event,
178 struct lttng_userspace_probe_location *probe_location)
179{
180 int ret = 0;
181 struct lttng_event_extended *event_extended;
182
183 if (!event || !probe_location) {
184 ret = -LTTNG_ERR_INVALID;
185 goto end;
186 }
187
188 event_extended = (struct lttng_event_extended *) event->extended.ptr;
a0377dfe 189 LTTNG_ASSERT(event_extended);
ef0e06bc
JG
190 if (event_extended->probe_location) {
191 lttng_userspace_probe_location_destroy(
192 event_extended->probe_location);
193 }
194 event_extended->probe_location = probe_location;
195end:
196 return ret;
197}
This page took 0.038808 seconds and 4 git commands to generate.