Commit | Line | Data |
---|---|---|
f3ed775e DG |
1 | /* |
2 | * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca> | |
3 | * | |
d14d33bf AM |
4 | * This program is free software; you can redistribute it and/or modify |
5 | * it under the terms of the GNU General Public License, version 2 only, | |
6 | * as published by the Free Software Foundation. | |
f3ed775e DG |
7 | * |
8 | * This program is distributed in the hope that it will be useful, | |
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
11 | * GNU General Public License for more details. | |
12 | * | |
d14d33bf AM |
13 | * You should have received a copy of the GNU General Public License along |
14 | * with this program; if not, write to the Free Software Foundation, Inc., | |
15 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | |
f3ed775e DG |
16 | */ |
17 | ||
18 | #define _GNU_SOURCE | |
b2064f54 | 19 | #include <assert.h> |
f3ed775e DG |
20 | #include <popt.h> |
21 | #include <stdio.h> | |
22 | #include <stdlib.h> | |
23 | #include <string.h> | |
24 | #include <sys/stat.h> | |
25 | #include <sys/types.h> | |
26 | #include <unistd.h> | |
5a0de755 | 27 | #include <inttypes.h> |
8f0d098b | 28 | #include <ctype.h> |
f3ed775e | 29 | |
42224349 | 30 | #include <src/common/sessiond-comm/sessiond-comm.h> |
f3ed775e | 31 | |
89476427 JRJ |
32 | /* Mi dependancy */ |
33 | #include <common/mi-lttng.h> | |
34 | ||
35 | #include "../command.h" | |
36 | ||
8ab7c0d9 MD |
37 | #if (LTTNG_SYMBOL_NAME_LEN == 256) |
38 | #define LTTNG_SYMBOL_NAME_LEN_SCANF_IS_A_BROKEN_API "255" | |
39 | #endif | |
40 | ||
f3ed775e DG |
41 | static char *opt_event_list; |
42 | static int opt_event_type; | |
0cda4f28 MD |
43 | static const char *opt_loglevel; |
44 | static int opt_loglevel_type; | |
6181537c | 45 | static int opt_kernel; |
5440dc42 | 46 | static char *opt_session_name; |
f3ed775e | 47 | static int opt_userspace; |
b9dfb167 | 48 | static int opt_jul; |
5cdb6027 | 49 | static int opt_log4j; |
0e115563 | 50 | static int opt_python; |
f3ed775e | 51 | static int opt_enable_all; |
cf0e5467 | 52 | static char *opt_probe; |
8f0d098b MD |
53 | static char *opt_function; |
54 | static char *opt_function_entry_symbol; | |
f3ed775e | 55 | static char *opt_channel_name; |
53a80697 | 56 | static char *opt_filter; |
fac3366c | 57 | static char *opt_exclude; |
d78d6610 DG |
58 | #if 0 |
59 | /* Not implemented yet */ | |
60 | static char *opt_cmd_name; | |
61 | static pid_t opt_pid; | |
62 | #endif | |
f3ed775e DG |
63 | |
64 | enum { | |
65 | OPT_HELP = 1, | |
f3ed775e | 66 | OPT_TRACEPOINT, |
cf0e5467 | 67 | OPT_PROBE, |
f3ed775e | 68 | OPT_FUNCTION, |
8f0d098b | 69 | OPT_FUNCTION_ENTRY, |
a54bd42d | 70 | OPT_SYSCALL, |
eeac7d46 | 71 | OPT_USERSPACE, |
0cda4f28 MD |
72 | OPT_LOGLEVEL, |
73 | OPT_LOGLEVEL_ONLY, | |
679b4943 | 74 | OPT_LIST_OPTIONS, |
53a80697 | 75 | OPT_FILTER, |
fac3366c | 76 | OPT_EXCLUDE, |
f3ed775e DG |
77 | }; |
78 | ||
cd80958d | 79 | static struct lttng_handle *handle; |
89476427 | 80 | static struct mi_writer *writer; |
cd80958d | 81 | |
f3ed775e DG |
82 | static struct poptOption long_options[] = { |
83 | /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */ | |
84 | {"help", 'h', POPT_ARG_NONE, 0, OPT_HELP, 0, 0}, | |
5440dc42 | 85 | {"session", 's', POPT_ARG_STRING, &opt_session_name, 0, 0, 0}, |
e14f64a8 | 86 | {"all", 'a', POPT_ARG_VAL, &opt_enable_all, 1, 0, 0}, |
f3ed775e DG |
87 | {"channel", 'c', POPT_ARG_STRING, &opt_channel_name, 0, 0, 0}, |
88 | {"kernel", 'k', POPT_ARG_VAL, &opt_kernel, 1, 0, 0}, | |
d78d6610 | 89 | {"userspace", 'u', POPT_ARG_NONE, 0, OPT_USERSPACE, 0, 0}, |
b9dfb167 | 90 | {"jul", 'j', POPT_ARG_VAL, &opt_jul, 1, 0, 0}, |
5cdb6027 | 91 | {"log4j", 'l', POPT_ARG_VAL, &opt_log4j, 1, 0, 0}, |
0e115563 | 92 | {"python", 'p', POPT_ARG_VAL, &opt_python, 1, 0, 0}, |
f3ed775e | 93 | {"tracepoint", 0, POPT_ARG_NONE, 0, OPT_TRACEPOINT, 0, 0}, |
7ebae521 | 94 | {"probe", 0, POPT_ARG_STRING, &opt_probe, OPT_PROBE, 0, 0}, |
40e9d5d3 | 95 | {"function", 0, POPT_ARG_STRING, &opt_function, OPT_FUNCTION, 0, 0}, |
b213d387 MD |
96 | #if 0 |
97 | /* | |
98 | * Currently removed from lttng kernel tracer. Removed from | |
99 | * lttng UI to discourage its use. | |
100 | */ | |
40e9d5d3 | 101 | {"function:entry", 0, POPT_ARG_STRING, &opt_function_entry_symbol, OPT_FUNCTION_ENTRY, 0, 0}, |
b213d387 | 102 | #endif |
7ebae521 | 103 | {"syscall", 0, POPT_ARG_NONE, 0, OPT_SYSCALL, 0, 0}, |
0cda4f28 MD |
104 | {"loglevel", 0, POPT_ARG_STRING, 0, OPT_LOGLEVEL, 0, 0}, |
105 | {"loglevel-only", 0, POPT_ARG_STRING, 0, OPT_LOGLEVEL_ONLY, 0, 0}, | |
679b4943 | 106 | {"list-options", 0, POPT_ARG_NONE, NULL, OPT_LIST_OPTIONS, NULL, NULL}, |
53a80697 | 107 | {"filter", 'f', POPT_ARG_STRING, &opt_filter, OPT_FILTER, 0, 0}, |
fac3366c | 108 | {"exclude", 'x', POPT_ARG_STRING, &opt_exclude, OPT_EXCLUDE, 0, 0}, |
f3ed775e DG |
109 | {0, 0, 0, 0, 0, 0, 0} |
110 | }; | |
111 | ||
112 | /* | |
113 | * usage | |
114 | */ | |
115 | static void usage(FILE *ofp) | |
116 | { | |
32a6298d | 117 | fprintf(ofp, "usage: lttng enable-event NAME[,NAME2,...] [-k|-u] [OPTIONS] \n"); |
f3ed775e | 118 | fprintf(ofp, "\n"); |
32a6298d | 119 | fprintf(ofp, "Options:\n"); |
f3ed775e | 120 | fprintf(ofp, " -h, --help Show this help\n"); |
679b4943 | 121 | fprintf(ofp, " --list-options Simple listing of options\n"); |
32a6298d DG |
122 | fprintf(ofp, " -s, --session NAME Apply to session name\n"); |
123 | fprintf(ofp, " -c, --channel NAME Apply to this channel\n"); | |
e08bff8d | 124 | fprintf(ofp, " -a, --all Enable all tracepoints and syscalls\n"); |
f3ed775e | 125 | fprintf(ofp, " -k, --kernel Apply for the kernel tracer\n"); |
27221701 | 126 | fprintf(ofp, " -u, --userspace Apply to the user-space tracer\n"); |
b9dfb167 | 127 | fprintf(ofp, " -j, --jul Apply for Java application using JUL\n"); |
5cdb6027 | 128 | fprintf(ofp, " -l, --log4j Apply for Java application using LOG4j\n"); |
0e115563 | 129 | fprintf(ofp, " -p, --python Apply for Java application using LOG4j\n"); |
f3ed775e DG |
130 | fprintf(ofp, "\n"); |
131 | fprintf(ofp, "Event options:\n"); | |
132 | fprintf(ofp, " --tracepoint Tracepoint event (default)\n"); | |
be49af1e MD |
133 | fprintf(ofp, " - userspace tracer supports wildcards at end of string.\n"); |
134 | fprintf(ofp, " Don't forget to quote to deal with bash expansion.\n"); | |
135 | fprintf(ofp, " e.g.:\n"); | |
136 | fprintf(ofp, " \"*\"\n"); | |
137 | fprintf(ofp, " \"app_component:na*\"\n"); | |
6a240cd9 | 138 | fprintf(ofp, " --probe (addr | symbol | symbol+offset)\n"); |
cf0e5467 MD |
139 | fprintf(ofp, " Dynamic probe.\n"); |
140 | fprintf(ofp, " Addr and offset can be octal (0NNN...),\n"); | |
141 | fprintf(ofp, " decimal (NNN...) or hexadecimal (0xNNN...)\n"); | |
6a240cd9 | 142 | fprintf(ofp, " --function (addr | symbol | symbol+offset)\n"); |
8f0d098b MD |
143 | fprintf(ofp, " Dynamic function entry/return probe.\n"); |
144 | fprintf(ofp, " Addr and offset can be octal (0NNN...),\n"); | |
145 | fprintf(ofp, " decimal (NNN...) or hexadecimal (0xNNN...)\n"); | |
b213d387 | 146 | #if 0 |
8f0d098b MD |
147 | fprintf(ofp, " --function:entry symbol\n"); |
148 | fprintf(ofp, " Function tracer event\n"); | |
b213d387 | 149 | #endif |
a54bd42d | 150 | fprintf(ofp, " --syscall System call event\n"); |
f3ed775e | 151 | fprintf(ofp, "\n"); |
300b8fd5 | 152 | fprintf(ofp, " --loglevel name\n"); |
f9e8873b | 153 | fprintf(ofp, " Tracepoint loglevel range from 0 to loglevel.\n"); |
5cdb6027 | 154 | fprintf(ofp, " For JUL/LOG4j domain, see the table below for the range values.\n"); |
300b8fd5 MD |
155 | fprintf(ofp, " --loglevel-only name\n"); |
156 | fprintf(ofp, " Tracepoint loglevel (only this loglevel)\n"); | |
157 | fprintf(ofp, "\n"); | |
0c8477c8 MD |
158 | fprintf(ofp, " The loglevel or loglevel-only options should be\n"); |
159 | fprintf(ofp, " combined with a tracepoint name or tracepoint\n"); | |
160 | fprintf(ofp, " wildcard.\n"); | |
161 | fprintf(ofp, " Available loglevels:\n"); | |
162 | fprintf(ofp, " (higher value is more verbose)\n"); | |
46839cc2 MD |
163 | fprintf(ofp, " TRACE_EMERG = 0\n"); |
164 | fprintf(ofp, " TRACE_ALERT = 1\n"); | |
165 | fprintf(ofp, " TRACE_CRIT = 2\n"); | |
166 | fprintf(ofp, " TRACE_ERR = 3\n"); | |
167 | fprintf(ofp, " TRACE_WARNING = 4\n"); | |
168 | fprintf(ofp, " TRACE_NOTICE = 5\n"); | |
169 | fprintf(ofp, " TRACE_INFO = 6\n"); | |
170 | fprintf(ofp, " TRACE_DEBUG_SYSTEM = 7\n"); | |
171 | fprintf(ofp, " TRACE_DEBUG_PROGRAM = 8\n"); | |
172 | fprintf(ofp, " TRACE_DEBUG_PROCESS = 9\n"); | |
173 | fprintf(ofp, " TRACE_DEBUG_MODULE = 10\n"); | |
174 | fprintf(ofp, " TRACE_DEBUG_UNIT = 11\n"); | |
175 | fprintf(ofp, " TRACE_DEBUG_FUNCTION = 12\n"); | |
176 | fprintf(ofp, " TRACE_DEBUG_LINE = 13\n"); | |
177 | fprintf(ofp, " TRACE_DEBUG = 14\n"); | |
178 | fprintf(ofp, " (shortcuts such as \"system\" are allowed)\n"); | |
b2064f54 DG |
179 | fprintf(ofp, "\n"); |
180 | fprintf(ofp, " Available JUL domain loglevels:\n"); | |
181 | fprintf(ofp, " JUL_OFF = INT32_MAX\n"); | |
182 | fprintf(ofp, " JUL_SEVERE = %d\n", LTTNG_LOGLEVEL_JUL_SEVERE); | |
183 | fprintf(ofp, " JUL_WARNING = %d\n", LTTNG_LOGLEVEL_JUL_WARNING); | |
184 | fprintf(ofp, " JUL_INFO = %d\n", LTTNG_LOGLEVEL_JUL_INFO); | |
185 | fprintf(ofp, " JUL_CONFIG = %d\n", LTTNG_LOGLEVEL_JUL_CONFIG); | |
186 | fprintf(ofp, " JUL_FINE = %d\n", LTTNG_LOGLEVEL_JUL_FINE); | |
187 | fprintf(ofp, " JUL_FINER = %d\n", LTTNG_LOGLEVEL_JUL_FINER); | |
188 | fprintf(ofp, " JUL_FINEST = %d\n", LTTNG_LOGLEVEL_JUL_FINEST); | |
189 | fprintf(ofp, " JUL_ALL = INT32_MIN\n"); | |
190 | fprintf(ofp, " (shortcuts such as \"severe\" are allowed)\n"); | |
191 | fprintf(ofp, "\n"); | |
5cdb6027 DG |
192 | fprintf(ofp, " Available LOG4j domain loglevels:\n"); |
193 | fprintf(ofp, " LOG4J_OFF = INT32_MAX\n"); | |
194 | fprintf(ofp, " LOG4J_FATAL = %d\n", LTTNG_LOGLEVEL_LOG4J_FATAL); | |
195 | fprintf(ofp, " LOG4J_ERROR = %d\n", LTTNG_LOGLEVEL_LOG4J_ERROR); | |
196 | fprintf(ofp, " LOG4J_WARN = %d\n", LTTNG_LOGLEVEL_LOG4J_WARN); | |
197 | fprintf(ofp, " LOG4J_INFO = %d\n", LTTNG_LOGLEVEL_LOG4J_INFO); | |
198 | fprintf(ofp, " LOG4J_DEBUG = %d\n", LTTNG_LOGLEVEL_LOG4J_DEBUG); | |
199 | fprintf(ofp, " LOG4J_TRACE = %d\n", LTTNG_LOGLEVEL_LOG4J_TRACE); | |
200 | fprintf(ofp, " LOG4J_ALL = INT32_MIN\n"); | |
201 | fprintf(ofp, " (shortcuts such as \"severe\" are allowed)\n"); | |
202 | fprintf(ofp, "\n"); | |
0e115563 DG |
203 | fprintf(ofp, " Available Python domain loglevels:\n"); |
204 | fprintf(ofp, " PYTHON_CRITICAL = %d\n", LTTNG_LOGLEVEL_PYTHON_CRITICAL); | |
205 | fprintf(ofp, " PYTHON_ERROR = %d\n", LTTNG_LOGLEVEL_PYTHON_ERROR); | |
206 | fprintf(ofp, " PYTHON_WARNING = %d\n", LTTNG_LOGLEVEL_PYTHON_WARNING); | |
207 | fprintf(ofp, " PYTHON_INFO = %d\n", LTTNG_LOGLEVEL_PYTHON_INFO); | |
208 | fprintf(ofp, " PYTHON_DEBUG = %d\n", LTTNG_LOGLEVEL_PYTHON_DEBUG); | |
209 | fprintf(ofp, " PYTHON_NOTSET = %d\n", LTTNG_LOGLEVEL_PYTHON_NOTSET); | |
210 | fprintf(ofp, " (shortcuts such as \"critical\" are allowed)\n"); | |
211 | fprintf(ofp, "\n"); | |
f2611ab0 | 212 | fprintf(ofp, " -f, --filter \'expression\'\n"); |
ee8ccafa MD |
213 | fprintf(ofp, " Filter expression on event fields and context.\n"); |
214 | fprintf(ofp, " Event recording depends on evaluation.\n"); | |
919e300c MD |
215 | fprintf(ofp, " Only specify on first activation of\n"); |
216 | fprintf(ofp, " a given event within a session.\n"); | |
217 | fprintf(ofp, " Filter only allowed when enabling\n"); | |
218 | fprintf(ofp, " events within a session before tracing\n"); | |
9bd578f5 MD |
219 | fprintf(ofp, " is started. If the filter fails to link\n"); |
220 | fprintf(ofp, " with the event within the traced domain,\n"); | |
221 | fprintf(ofp, " the event will be discarded. Currently,\n"); | |
222 | fprintf(ofp, " filter is only implemented for the user-space\n"); | |
223 | fprintf(ofp, " tracer.\n"); | |
224 | fprintf(ofp, " Expression examples:.\n"); | |
225 | fprintf(ofp, " \n"); | |
226 | fprintf(ofp, " 'intfield > 500 && intfield < 503'\n"); | |
6a240cd9 | 227 | fprintf(ofp, " '(strfield == \"test\" || intfield != 10) && intfield > 33'\n"); |
9bd578f5 MD |
228 | fprintf(ofp, " 'doublefield > 1.1 && intfield < 5.3'\n"); |
229 | fprintf(ofp, " \n"); | |
230 | fprintf(ofp, " Wildcards are allowed at the end of strings:\n"); | |
231 | fprintf(ofp, " 'seqfield1 == \"te*\"'\n"); | |
232 | fprintf(ofp, " In string literals, the escape character is '\\'.\n"); | |
233 | fprintf(ofp, " Use '\\*' for the '*' character, and '\\\\' for\n"); | |
ee8ccafa MD |
234 | fprintf(ofp, " the '\\' character. Wildcard match any sequence of,\n"); |
235 | fprintf(ofp, " characters including an empty sub-string (match 0 or\n"); | |
236 | fprintf(ofp, " more characters).\n"); | |
237 | fprintf(ofp, "\n"); | |
238 | fprintf(ofp, " Context information can be used for filtering. The\n"); | |
239 | fprintf(ofp, " examples below show usage of context filtering on\n"); | |
240 | fprintf(ofp, " process name (with a wildcard), process ID range, and\n"); | |
241 | fprintf(ofp, " unique thread ID for filtering. The process and\n"); | |
242 | fprintf(ofp, " thread ID of running applications can be found under\n"); | |
243 | fprintf(ofp, " columns \"PID\" and \"LWP\" of the \"ps -eLf\" command.\n"); | |
244 | fprintf(ofp, "\n"); | |
245 | fprintf(ofp, " '$ctx.procname == \"demo*\"'\n"); | |
246 | fprintf(ofp, " '$ctx.vpid >= 4433 && $ctx.vpid < 4455'\n"); | |
247 | fprintf(ofp, " '$ctx.vtid == 1234'\n"); | |
c2063d0b JI |
248 | fprintf(ofp, " -x, --exclude LIST\n"); |
249 | fprintf(ofp, " Add exclusions to UST tracepoints:\n"); | |
250 | fprintf(ofp, " Events that match any of the items\n"); | |
251 | fprintf(ofp, " in the comma-separated LIST are not\n"); | |
252 | fprintf(ofp, " enabled, even if they match a wildcard\n"); | |
253 | fprintf(ofp, " definition of the event.\n"); | |
300b8fd5 | 254 | fprintf(ofp, "\n"); |
f3ed775e DG |
255 | } |
256 | ||
0d63dd19 | 257 | /* |
6181537c | 258 | * Parse probe options. |
0d63dd19 | 259 | */ |
cf0e5467 | 260 | static int parse_probe_opts(struct lttng_event *ev, char *opt) |
0d63dd19 | 261 | { |
49d4e302 JRJ |
262 | int ret = CMD_SUCCESS; |
263 | int match; | |
8ff0bbd0 | 264 | char s_hex[19]; |
8ab7c0d9 | 265 | #define S_HEX_LEN_SCANF_IS_A_BROKEN_API "18" /* 18 is (19 - 1) (\0 is extra) */ |
0d63dd19 DG |
266 | char name[LTTNG_SYMBOL_NAME_LEN]; |
267 | ||
268 | if (opt == NULL) { | |
49d4e302 | 269 | ret = CMD_ERROR; |
8f0d098b | 270 | goto end; |
0d63dd19 DG |
271 | } |
272 | ||
273 | /* Check for symbol+offset */ | |
49d4e302 | 274 | match = sscanf(opt, "%" LTTNG_SYMBOL_NAME_LEN_SCANF_IS_A_BROKEN_API |
8ab7c0d9 | 275 | "[^'+']+%" S_HEX_LEN_SCANF_IS_A_BROKEN_API "s", name, s_hex); |
49d4e302 | 276 | if (match == 2) { |
7d29a247 | 277 | strncpy(ev->attr.probe.symbol_name, name, LTTNG_SYMBOL_NAME_LEN); |
99497cd0 | 278 | ev->attr.probe.symbol_name[LTTNG_SYMBOL_NAME_LEN - 1] = '\0'; |
cf0e5467 | 279 | DBG("probe symbol %s", ev->attr.probe.symbol_name); |
9d035200 | 280 | if (*s_hex == '\0') { |
8ff0bbd0 | 281 | ERR("Invalid probe offset %s", s_hex); |
49d4e302 | 282 | ret = CMD_ERROR; |
8f0d098b | 283 | goto end; |
0d63dd19 | 284 | } |
8ff0bbd0 | 285 | ev->attr.probe.offset = strtoul(s_hex, NULL, 0); |
cf0e5467 | 286 | DBG("probe offset %" PRIu64, ev->attr.probe.offset); |
3000dc78 | 287 | ev->attr.probe.addr = 0; |
8f0d098b MD |
288 | goto end; |
289 | } | |
290 | ||
291 | /* Check for symbol */ | |
292 | if (isalpha(name[0])) { | |
49d4e302 | 293 | match = sscanf(opt, "%" LTTNG_SYMBOL_NAME_LEN_SCANF_IS_A_BROKEN_API "s", |
8ab7c0d9 | 294 | name); |
49d4e302 | 295 | if (match == 1) { |
8f0d098b | 296 | strncpy(ev->attr.probe.symbol_name, name, LTTNG_SYMBOL_NAME_LEN); |
99497cd0 | 297 | ev->attr.probe.symbol_name[LTTNG_SYMBOL_NAME_LEN - 1] = '\0'; |
8f0d098b MD |
298 | DBG("probe symbol %s", ev->attr.probe.symbol_name); |
299 | ev->attr.probe.offset = 0; | |
300 | DBG("probe offset %" PRIu64, ev->attr.probe.offset); | |
301 | ev->attr.probe.addr = 0; | |
302 | goto end; | |
303 | } | |
0d63dd19 DG |
304 | } |
305 | ||
306 | /* Check for address */ | |
49d4e302 JRJ |
307 | match = sscanf(opt, "%" S_HEX_LEN_SCANF_IS_A_BROKEN_API "s", s_hex); |
308 | if (match > 0) { | |
9d035200 | 309 | if (*s_hex == '\0') { |
8ff0bbd0 | 310 | ERR("Invalid probe address %s", s_hex); |
49d4e302 | 311 | ret = CMD_ERROR; |
8f0d098b | 312 | goto end; |
0d63dd19 | 313 | } |
8ff0bbd0 | 314 | ev->attr.probe.addr = strtoul(s_hex, NULL, 0); |
cf0e5467 | 315 | DBG("probe addr %" PRIu64, ev->attr.probe.addr); |
3000dc78 DG |
316 | ev->attr.probe.offset = 0; |
317 | memset(ev->attr.probe.symbol_name, 0, LTTNG_SYMBOL_NAME_LEN); | |
8f0d098b | 318 | goto end; |
0d63dd19 DG |
319 | } |
320 | ||
321 | /* No match */ | |
49d4e302 | 322 | ret = CMD_ERROR; |
0d63dd19 | 323 | |
8f0d098b | 324 | end: |
0d63dd19 DG |
325 | return ret; |
326 | } | |
327 | ||
5cdb6027 DG |
328 | /* |
329 | * Maps LOG4j loglevel from string to value | |
330 | */ | |
331 | static int loglevel_log4j_str_to_value(const char *inputstr) | |
332 | { | |
333 | int i = 0; | |
334 | char str[LTTNG_SYMBOL_NAME_LEN]; | |
335 | ||
336 | /* | |
337 | * Loop up to LTTNG_SYMBOL_NAME_LEN minus one because the NULL bytes is | |
338 | * added at the end of the loop so a the upper bound we avoid the overflow. | |
339 | */ | |
340 | while (i < (LTTNG_SYMBOL_NAME_LEN - 1) && inputstr[i] != '\0') { | |
341 | str[i] = toupper(inputstr[i]); | |
342 | i++; | |
343 | } | |
344 | str[i] = '\0'; | |
345 | ||
346 | if (!strcmp(str, "LOG4J_OFF") || !strcmp(str, "OFF")) { | |
347 | return LTTNG_LOGLEVEL_LOG4J_OFF; | |
348 | } else if (!strcmp(str, "LOG4J_FATAL") || !strcmp(str, "FATAL")) { | |
349 | return LTTNG_LOGLEVEL_LOG4J_FATAL; | |
350 | } else if (!strcmp(str, "LOG4J_ERROR") || !strcmp(str, "ERROR")) { | |
351 | return LTTNG_LOGLEVEL_LOG4J_ERROR; | |
352 | } else if (!strcmp(str, "LOG4J_WARN") || !strcmp(str, "WARN")) { | |
353 | return LTTNG_LOGLEVEL_LOG4J_WARN; | |
354 | } else if (!strcmp(str, "LOG4J_INFO") || !strcmp(str, "INFO")) { | |
355 | return LTTNG_LOGLEVEL_LOG4J_INFO; | |
356 | } else if (!strcmp(str, "LOG4J_DEBUG") || !strcmp(str, "DEBUG")) { | |
357 | return LTTNG_LOGLEVEL_LOG4J_DEBUG; | |
358 | } else if (!strcmp(str, "LOG4J_TRACE") || !strcmp(str, "TRACE")) { | |
359 | return LTTNG_LOGLEVEL_LOG4J_TRACE; | |
360 | } else if (!strcmp(str, "LOG4J_ALL") || !strcmp(str, "ALL")) { | |
361 | return LTTNG_LOGLEVEL_LOG4J_ALL; | |
362 | } else { | |
363 | return -1; | |
364 | } | |
365 | } | |
366 | ||
b2064f54 DG |
367 | /* |
368 | * Maps JUL loglevel from string to value | |
369 | */ | |
370 | static int loglevel_jul_str_to_value(const char *inputstr) | |
371 | { | |
372 | int i = 0; | |
373 | char str[LTTNG_SYMBOL_NAME_LEN]; | |
374 | ||
375 | /* | |
376 | * Loop up to LTTNG_SYMBOL_NAME_LEN minus one because the NULL bytes is | |
377 | * added at the end of the loop so a the upper bound we avoid the overflow. | |
378 | */ | |
379 | while (i < (LTTNG_SYMBOL_NAME_LEN - 1) && inputstr[i] != '\0') { | |
380 | str[i] = toupper(inputstr[i]); | |
381 | i++; | |
382 | } | |
383 | str[i] = '\0'; | |
384 | ||
385 | if (!strcmp(str, "JUL_OFF") || !strcmp(str, "OFF")) { | |
386 | return LTTNG_LOGLEVEL_JUL_OFF; | |
387 | } else if (!strcmp(str, "JUL_SEVERE") || !strcmp(str, "SEVERE")) { | |
388 | return LTTNG_LOGLEVEL_JUL_SEVERE; | |
389 | } else if (!strcmp(str, "JUL_WARNING") || !strcmp(str, "WARNING")) { | |
390 | return LTTNG_LOGLEVEL_JUL_WARNING; | |
391 | } else if (!strcmp(str, "JUL_INFO") || !strcmp(str, "INFO")) { | |
392 | return LTTNG_LOGLEVEL_JUL_INFO; | |
393 | } else if (!strcmp(str, "JUL_CONFIG") || !strcmp(str, "CONFIG")) { | |
394 | return LTTNG_LOGLEVEL_JUL_CONFIG; | |
395 | } else if (!strcmp(str, "JUL_FINE") || !strcmp(str, "FINE")) { | |
396 | return LTTNG_LOGLEVEL_JUL_FINE; | |
397 | } else if (!strcmp(str, "JUL_FINER") || !strcmp(str, "FINER")) { | |
398 | return LTTNG_LOGLEVEL_JUL_FINER; | |
399 | } else if (!strcmp(str, "JUL_FINEST") || !strcmp(str, "FINEST")) { | |
400 | return LTTNG_LOGLEVEL_JUL_FINEST; | |
401 | } else if (!strcmp(str, "JUL_ALL") || !strcmp(str, "ALL")) { | |
402 | return LTTNG_LOGLEVEL_JUL_ALL; | |
403 | } else { | |
404 | return -1; | |
405 | } | |
406 | } | |
407 | ||
0e115563 DG |
408 | /* |
409 | * Maps Python loglevel from string to value | |
410 | */ | |
411 | static int loglevel_python_str_to_value(const char *inputstr) | |
412 | { | |
413 | int i = 0; | |
414 | char str[LTTNG_SYMBOL_NAME_LEN]; | |
415 | ||
416 | /* | |
417 | * Loop up to LTTNG_SYMBOL_NAME_LEN minus one because the NULL bytes is | |
418 | * added at the end of the loop so a the upper bound we avoid the overflow. | |
419 | */ | |
420 | while (i < (LTTNG_SYMBOL_NAME_LEN - 1) && inputstr[i] != '\0') { | |
421 | str[i] = toupper(inputstr[i]); | |
422 | i++; | |
423 | } | |
424 | str[i] = '\0'; | |
425 | ||
426 | if (!strcmp(str, "PYTHON_CRITICAL") || !strcmp(str, "CRITICAL")) { | |
427 | return LTTNG_LOGLEVEL_PYTHON_CRITICAL; | |
428 | } else if (!strcmp(str, "PYTHON_ERROR") || !strcmp(str, "ERROR")) { | |
429 | return LTTNG_LOGLEVEL_PYTHON_ERROR; | |
430 | } else if (!strcmp(str, "PYTHON_WARNING") || !strcmp(str, "WARNING")) { | |
431 | return LTTNG_LOGLEVEL_PYTHON_WARNING; | |
432 | } else if (!strcmp(str, "PYTHON_INFO") || !strcmp(str, "INFO")) { | |
433 | return LTTNG_LOGLEVEL_PYTHON_INFO; | |
434 | } else if (!strcmp(str, "PYTNON_DEBUG") || !strcmp(str, "DEBUG")) { | |
435 | return LTTNG_LOGLEVEL_PYTHON_DEBUG; | |
436 | } else if (!strcmp(str, "PYTHON_NOTSET") || !strcmp(str, "NOTSET")) { | |
437 | return LTTNG_LOGLEVEL_PYTHON_NOTSET; | |
438 | } else { | |
439 | return -1; | |
440 | } | |
441 | } | |
442 | ||
8005f29a | 443 | /* |
0c8477c8 | 444 | * Maps loglevel from string to value |
8005f29a MD |
445 | */ |
446 | static | |
46839cc2 | 447 | int loglevel_str_to_value(const char *inputstr) |
8005f29a | 448 | { |
46839cc2 MD |
449 | int i = 0; |
450 | char str[LTTNG_SYMBOL_NAME_LEN]; | |
451 | ||
e051e07c DG |
452 | /* |
453 | * Loop up to LTTNG_SYMBOL_NAME_LEN minus one because the NULL bytes is | |
454 | * added at the end of the loop so a the upper bound we avoid the overflow. | |
455 | */ | |
456 | while (i < (LTTNG_SYMBOL_NAME_LEN - 1) && inputstr[i] != '\0') { | |
46839cc2 MD |
457 | str[i] = toupper(inputstr[i]); |
458 | i++; | |
459 | } | |
460 | str[i] = '\0'; | |
461 | if (!strcmp(str, "TRACE_EMERG") || !strcmp(str, "EMERG")) { | |
462 | return LTTNG_LOGLEVEL_EMERG; | |
463 | } else if (!strcmp(str, "TRACE_ALERT") || !strcmp(str, "ALERT")) { | |
464 | return LTTNG_LOGLEVEL_ALERT; | |
465 | } else if (!strcmp(str, "TRACE_CRIT") || !strcmp(str, "CRIT")) { | |
466 | return LTTNG_LOGLEVEL_CRIT; | |
467 | } else if (!strcmp(str, "TRACE_ERR") || !strcmp(str, "ERR")) { | |
468 | return LTTNG_LOGLEVEL_ERR; | |
469 | } else if (!strcmp(str, "TRACE_WARNING") || !strcmp(str, "WARNING")) { | |
470 | return LTTNG_LOGLEVEL_WARNING; | |
471 | } else if (!strcmp(str, "TRACE_NOTICE") || !strcmp(str, "NOTICE")) { | |
472 | return LTTNG_LOGLEVEL_NOTICE; | |
473 | } else if (!strcmp(str, "TRACE_INFO") || !strcmp(str, "INFO")) { | |
474 | return LTTNG_LOGLEVEL_INFO; | |
475 | } else if (!strcmp(str, "TRACE_DEBUG_SYSTEM") || !strcmp(str, "DEBUG_SYSTEM") || !strcmp(str, "SYSTEM")) { | |
476 | return LTTNG_LOGLEVEL_DEBUG_SYSTEM; | |
477 | } else if (!strcmp(str, "TRACE_DEBUG_PROGRAM") || !strcmp(str, "DEBUG_PROGRAM") || !strcmp(str, "PROGRAM")) { | |
478 | return LTTNG_LOGLEVEL_DEBUG_PROGRAM; | |
479 | } else if (!strcmp(str, "TRACE_DEBUG_PROCESS") || !strcmp(str, "DEBUG_PROCESS") || !strcmp(str, "PROCESS")) { | |
480 | return LTTNG_LOGLEVEL_DEBUG_PROCESS; | |
481 | } else if (!strcmp(str, "TRACE_DEBUG_MODULE") || !strcmp(str, "DEBUG_MODULE") || !strcmp(str, "MODULE")) { | |
482 | return LTTNG_LOGLEVEL_DEBUG_MODULE; | |
483 | } else if (!strcmp(str, "TRACE_DEBUG_UNIT") || !strcmp(str, "DEBUG_UNIT") || !strcmp(str, "UNIT")) { | |
484 | return LTTNG_LOGLEVEL_DEBUG_UNIT; | |
485 | } else if (!strcmp(str, "TRACE_DEBUG_FUNCTION") || !strcmp(str, "DEBUG_FUNCTION") || !strcmp(str, "FUNCTION")) { | |
486 | return LTTNG_LOGLEVEL_DEBUG_FUNCTION; | |
487 | } else if (!strcmp(str, "TRACE_DEBUG_LINE") || !strcmp(str, "DEBUG_LINE") || !strcmp(str, "LINE")) { | |
488 | return LTTNG_LOGLEVEL_DEBUG_LINE; | |
489 | } else if (!strcmp(str, "TRACE_DEBUG") || !strcmp(str, "DEBUG")) { | |
490 | return LTTNG_LOGLEVEL_DEBUG; | |
8005f29a MD |
491 | } else { |
492 | return -1; | |
493 | } | |
494 | } | |
495 | ||
85076754 MD |
496 | static |
497 | const char *print_channel_name(const char *name) | |
498 | { | |
499 | return name ? : DEFAULT_CHANNEL_NAME; | |
500 | } | |
501 | ||
502 | static | |
503 | const char *print_raw_channel_name(const char *name) | |
504 | { | |
505 | return name ? : "<default>"; | |
506 | } | |
507 | ||
89476427 JRJ |
508 | /* |
509 | * Mi print exlcusion list | |
510 | */ | |
511 | static | |
512 | int mi_print_exclusion(int count, char **names) | |
513 | { | |
514 | int i, ret; | |
515 | ||
516 | assert(writer); | |
517 | ||
518 | if (count == 0) { | |
519 | ret = 0; | |
520 | goto end; | |
521 | } | |
522 | ret = mi_lttng_writer_open_element(writer, config_element_exclusions); | |
523 | if (ret) { | |
524 | goto end; | |
525 | } | |
526 | ||
527 | for (i = 0; i < count; i++) { | |
528 | ret = mi_lttng_writer_write_element_string(writer, | |
529 | config_element_exclusion, names[i]); | |
530 | if (ret) { | |
531 | goto end; | |
532 | } | |
533 | } | |
534 | ||
535 | /* Close exclusions element */ | |
536 | ret = mi_lttng_writer_close_element(writer); | |
537 | ||
538 | end: | |
539 | return ret; | |
540 | } | |
541 | ||
9c48cab3 JI |
542 | /* |
543 | * Return allocated string for pretty-printing exclusion names. | |
544 | */ | |
545 | static | |
546 | char *print_exclusions(int count, char **names) | |
547 | { | |
548 | int length = 0; | |
549 | int i; | |
550 | const char *preamble = " excluding "; | |
551 | char *ret; | |
552 | ||
553 | if (count == 0) { | |
554 | return strdup(""); | |
555 | } | |
556 | ||
557 | /* calculate total required length */ | |
558 | for (i = 0; i < count; i++) { | |
559 | length += strlen(names[i]) + 1; | |
560 | } | |
561 | ||
562 | /* add length of preamble + one for NUL - one for last (missing) comma */ | |
563 | length += strlen(preamble); | |
564 | ret = malloc(length); | |
565 | strncpy(ret, preamble, length); | |
566 | for (i = 0; i < count; i++) { | |
567 | strcat(ret, names[i]); | |
568 | if (i != count - 1) { | |
569 | strcat(ret, ","); | |
570 | } | |
571 | } | |
89476427 | 572 | |
9c48cab3 JI |
573 | return ret; |
574 | } | |
575 | ||
748bde76 JI |
576 | /* |
577 | * Compare list of exclusions against an event name. | |
578 | * Return a list of legal exclusion names. | |
579 | * Produce an error or a warning about others (depending on the situation) | |
580 | */ | |
581 | static | |
582 | int check_exclusion_subsets(const char *event_name, | |
583 | const char *exclusions, | |
584 | int *exclusion_count_ptr, | |
585 | char ***exclusion_list_ptr) | |
586 | { | |
587 | const char *excluder_ptr; | |
588 | const char *event_ptr; | |
589 | const char *next_excluder; | |
590 | int excluder_length; | |
591 | int exclusion_count = 0; | |
592 | char **exclusion_list = NULL; | |
593 | int ret = CMD_SUCCESS; | |
594 | ||
595 | if (event_name[strlen(event_name) - 1] != '*') { | |
596 | ERR("Event %s: Excluders can only be used with wildcarded events", event_name); | |
597 | goto error; | |
598 | } | |
599 | ||
600 | next_excluder = exclusions; | |
601 | while (*next_excluder != 0) { | |
602 | event_ptr = event_name; | |
603 | excluder_ptr = next_excluder; | |
604 | excluder_length = strcspn(next_excluder, ","); | |
605 | ||
606 | /* Scan both the excluder and the event letter by letter */ | |
607 | while (1) { | |
608 | char e, x; | |
609 | ||
610 | e = *event_ptr; | |
611 | x = *excluder_ptr; | |
612 | ||
613 | if (x == '*') { | |
614 | /* Event is a subset of the excluder */ | |
615 | ERR("Event %s: %.*s excludes all events from %s", | |
616 | event_name, | |
617 | excluder_length, | |
618 | next_excluder, | |
619 | event_name); | |
620 | goto error; | |
621 | } | |
622 | if (e == '*') { | |
623 | /* Excluder is a proper subset of event */ | |
624 | exclusion_count++; | |
625 | exclusion_list = realloc(exclusion_list, sizeof(char **) * exclusion_count); | |
626 | exclusion_list[exclusion_count - 1] = strndup(next_excluder, excluder_length); | |
627 | ||
628 | break; | |
629 | } | |
630 | if (x != e) { | |
631 | /* Excluder and event sets have no common elements */ | |
632 | WARN("Event %s: %.*s does not exclude any events from %s", | |
633 | event_name, | |
634 | excluder_length, | |
635 | next_excluder, | |
636 | event_name); | |
637 | break; | |
638 | } | |
639 | excluder_ptr++; | |
640 | event_ptr++; | |
641 | } | |
642 | /* next excluder */ | |
643 | next_excluder += excluder_length; | |
644 | if (*next_excluder == ',') { | |
645 | next_excluder++; | |
646 | } | |
647 | } | |
648 | goto end; | |
649 | error: | |
650 | while (exclusion_count--) { | |
651 | free(exclusion_list[exclusion_count]); | |
652 | } | |
653 | if (exclusion_list != NULL) { | |
654 | free(exclusion_list); | |
655 | } | |
656 | exclusion_list = NULL; | |
657 | exclusion_count = 0; | |
658 | ret = CMD_ERROR; | |
659 | end: | |
660 | *exclusion_count_ptr = exclusion_count; | |
661 | *exclusion_list_ptr = exclusion_list; | |
662 | return ret; | |
663 | } | |
f3ed775e | 664 | /* |
6181537c | 665 | * Enabling event using the lttng API. |
89476427 | 666 | * Note: in case of error only the last error code will be return. |
f3ed775e | 667 | */ |
cd80958d | 668 | static int enable_events(char *session_name) |
f3ed775e | 669 | { |
89476427 JRJ |
670 | int ret = CMD_SUCCESS, command_ret = CMD_SUCCESS; |
671 | int error_holder = CMD_SUCCESS, warn = 0, error = 0, success = 1; | |
b73d0b29 | 672 | char *event_name, *channel_name = NULL; |
f3ed775e | 673 | struct lttng_event ev; |
7d29a247 | 674 | struct lttng_domain dom; |
7ed70bc9 JI |
675 | int exclusion_count = 0; |
676 | char **exclusion_list = NULL; | |
f3ed775e | 677 | |
441c16a7 MD |
678 | memset(&ev, 0, sizeof(ev)); |
679 | memset(&dom, 0, sizeof(dom)); | |
680 | ||
53a80697 MD |
681 | if (opt_kernel) { |
682 | if (opt_filter) { | |
683 | ERR("Filter not implement for kernel tracing yet"); | |
684 | ret = CMD_ERROR; | |
685 | goto error; | |
686 | } | |
67b58630 JG |
687 | if (opt_loglevel) { |
688 | WARN("Kernel loglevels are not supported."); | |
689 | } | |
53a80697 MD |
690 | } |
691 | ||
7d29a247 DG |
692 | /* Create lttng domain */ |
693 | if (opt_kernel) { | |
694 | dom.type = LTTNG_DOMAIN_KERNEL; | |
7972aab2 | 695 | dom.buf_type = LTTNG_BUFFER_GLOBAL; |
d78d6610 | 696 | } else if (opt_userspace) { |
2bdd86d4 | 697 | dom.type = LTTNG_DOMAIN_UST; |
7972aab2 | 698 | /* Default. */ |
8692d4e5 | 699 | dom.buf_type = LTTNG_BUFFER_PER_UID; |
b9dfb167 DG |
700 | } else if (opt_jul) { |
701 | dom.type = LTTNG_DOMAIN_JUL; | |
702 | /* Default. */ | |
703 | dom.buf_type = LTTNG_BUFFER_PER_UID; | |
5cdb6027 DG |
704 | } else if (opt_log4j) { |
705 | dom.type = LTTNG_DOMAIN_LOG4J; | |
706 | /* Default. */ | |
707 | dom.buf_type = LTTNG_BUFFER_PER_UID; | |
0e115563 DG |
708 | } else if (opt_python) { |
709 | dom.type = LTTNG_DOMAIN_PYTHON; | |
710 | /* Default. */ | |
711 | dom.buf_type = LTTNG_BUFFER_PER_UID; | |
6181537c | 712 | } else { |
b9dfb167 | 713 | print_missing_domain(); |
d16c1a4c | 714 | ret = CMD_ERROR; |
6181537c | 715 | goto error; |
2bdd86d4 | 716 | } |
7d29a247 | 717 | |
d5dd17fd JI |
718 | if (opt_kernel && opt_exclude) { |
719 | ERR("Event name exclusions are not yet implemented for kernel events"); | |
720 | ret = CMD_ERROR; | |
721 | goto error; | |
722 | } | |
723 | ||
85076754 | 724 | channel_name = opt_channel_name; |
ae856491 | 725 | |
cd80958d DG |
726 | handle = lttng_create_handle(session_name, &dom); |
727 | if (handle == NULL) { | |
728 | ret = -1; | |
729 | goto error; | |
730 | } | |
1aef21b6 | 731 | |
89476427 JRJ |
732 | /* Prepare Mi */ |
733 | if (lttng_opt_mi) { | |
734 | /* Open a events element */ | |
735 | ret = mi_lttng_writer_open_element(writer, config_element_events); | |
736 | if (ret) { | |
737 | ret = CMD_ERROR; | |
738 | goto error; | |
739 | } | |
740 | } | |
741 | ||
cd80958d | 742 | if (opt_enable_all) { |
8c9ae521 | 743 | /* Default setup for enable all */ |
75e8c5ab MD |
744 | if (opt_kernel) { |
745 | ev.type = opt_event_type; | |
746 | ev.name[0] = '\0'; | |
300b8fd5 MD |
747 | /* kernel loglevels not implemented */ |
748 | ev.loglevel_type = LTTNG_EVENT_LOGLEVEL_ALL; | |
75e8c5ab MD |
749 | } else { |
750 | ev.type = LTTNG_EVENT_TRACEPOINT; | |
751 | strcpy(ev.name, "*"); | |
300b8fd5 MD |
752 | ev.loglevel_type = opt_loglevel_type; |
753 | if (opt_loglevel) { | |
0e115563 | 754 | assert(opt_userspace || opt_jul || opt_log4j || opt_python); |
b2064f54 DG |
755 | if (opt_userspace) { |
756 | ev.loglevel = loglevel_str_to_value(opt_loglevel); | |
757 | } else if (opt_jul) { | |
758 | ev.loglevel = loglevel_jul_str_to_value(opt_loglevel); | |
5cdb6027 DG |
759 | } else if (opt_log4j) { |
760 | ev.loglevel = loglevel_log4j_str_to_value(opt_loglevel); | |
0e115563 DG |
761 | } else if (opt_python) { |
762 | ev.loglevel = loglevel_python_str_to_value(opt_loglevel); | |
b2064f54 | 763 | } |
300b8fd5 MD |
764 | if (ev.loglevel == -1) { |
765 | ERR("Unknown loglevel %s", opt_loglevel); | |
2f70b271 | 766 | ret = -LTTNG_ERR_INVALID; |
300b8fd5 MD |
767 | goto error; |
768 | } | |
22e25b71 | 769 | } else { |
0e115563 | 770 | assert(opt_userspace || opt_jul || opt_log4j || opt_python); |
b2064f54 DG |
771 | if (opt_userspace) { |
772 | ev.loglevel = -1; | |
5cdb6027 | 773 | } else if (opt_jul || opt_log4j) { |
b2064f54 | 774 | ev.loglevel = LTTNG_LOGLEVEL_JUL_ALL; |
0e115563 DG |
775 | } else if (opt_python) { |
776 | ev.loglevel = LTTNG_LOGLEVEL_PYTHON_DEBUG; | |
b2064f54 | 777 | } |
300b8fd5 | 778 | } |
75e8c5ab | 779 | } |
8c9ae521 | 780 | |
7ed70bc9 JI |
781 | if (opt_exclude) { |
782 | ret = check_exclusion_subsets("*", opt_exclude, | |
783 | &exclusion_count, &exclusion_list); | |
784 | if (ret == CMD_ERROR) { | |
785 | goto error; | |
786 | } | |
89476427 | 787 | ev.exclusion = 1; |
7ed70bc9 | 788 | } |
025faf73 | 789 | if (!opt_filter) { |
7ed70bc9 JI |
790 | ret = lttng_enable_event_with_exclusions(handle, |
791 | &ev, channel_name, | |
792 | NULL, | |
793 | exclusion_count, exclusion_list); | |
025faf73 DG |
794 | if (ret < 0) { |
795 | switch (-ret) { | |
796 | case LTTNG_ERR_KERN_EVENT_EXIST: | |
797 | WARN("Kernel events already enabled (channel %s, session %s)", | |
85076754 | 798 | print_channel_name(channel_name), session_name); |
89476427 | 799 | warn = 1; |
025faf73 DG |
800 | break; |
801 | default: | |
802 | ERR("Events: %s (channel %s, session %s)", | |
85076754 MD |
803 | lttng_strerror(ret), |
804 | ret == -LTTNG_ERR_NEED_CHANNEL_NAME | |
805 | ? print_raw_channel_name(channel_name) | |
806 | : print_channel_name(channel_name), | |
807 | session_name); | |
89476427 | 808 | error = 1; |
025faf73 DG |
809 | break; |
810 | } | |
811 | goto end; | |
42224349 | 812 | } |
8c9ae521 | 813 | |
025faf73 DG |
814 | switch (opt_event_type) { |
815 | case LTTNG_EVENT_TRACEPOINT: | |
67b58630 | 816 | if (opt_loglevel && dom.type != LTTNG_DOMAIN_KERNEL) { |
9c48cab3 JI |
817 | char *exclusion_string = print_exclusions(exclusion_count, exclusion_list); |
818 | MSG("All %s tracepoints%s are enabled in channel %s for loglevel %s", | |
b9dfb167 | 819 | get_domain_str(dom.type), |
9c48cab3 | 820 | exclusion_string, |
85076754 | 821 | print_channel_name(channel_name), |
025faf73 | 822 | opt_loglevel); |
9c48cab3 | 823 | free(exclusion_string); |
025faf73 | 824 | } else { |
9c48cab3 JI |
825 | char *exclusion_string = print_exclusions(exclusion_count, exclusion_list); |
826 | MSG("All %s tracepoints%s are enabled in channel %s", | |
b9dfb167 | 827 | get_domain_str(dom.type), |
9c48cab3 | 828 | exclusion_string, |
85076754 | 829 | print_channel_name(channel_name)); |
9c48cab3 | 830 | free(exclusion_string); |
025faf73 DG |
831 | } |
832 | break; | |
833 | case LTTNG_EVENT_SYSCALL: | |
834 | if (opt_kernel) { | |
6e911cad MD |
835 | MSG("All %s system calls are enabled in channel %s", |
836 | get_domain_str(dom.type), | |
85076754 | 837 | print_channel_name(channel_name)); |
025faf73 DG |
838 | } |
839 | break; | |
840 | case LTTNG_EVENT_ALL: | |
67b58630 | 841 | if (opt_loglevel && dom.type != LTTNG_DOMAIN_KERNEL) { |
9c48cab3 JI |
842 | char *exclusion_string = print_exclusions(exclusion_count, exclusion_list); |
843 | MSG("All %s events%s are enabled in channel %s for loglevel %s", | |
b9dfb167 | 844 | get_domain_str(dom.type), |
9c48cab3 | 845 | exclusion_string, |
85076754 | 846 | print_channel_name(channel_name), |
025faf73 | 847 | opt_loglevel); |
9c48cab3 | 848 | free(exclusion_string); |
025faf73 | 849 | } else { |
9c48cab3 JI |
850 | char *exclusion_string = print_exclusions(exclusion_count, exclusion_list); |
851 | MSG("All %s events%s are enabled in channel %s", | |
b9dfb167 | 852 | get_domain_str(dom.type), |
9c48cab3 | 853 | exclusion_string, |
85076754 | 854 | print_channel_name(channel_name)); |
9c48cab3 | 855 | free(exclusion_string); |
025faf73 DG |
856 | } |
857 | break; | |
858 | default: | |
859 | /* | |
860 | * We should not be here since lttng_enable_event should have | |
861 | * failed on the event type. | |
862 | */ | |
863 | goto error; | |
57064ada | 864 | } |
f3ed775e | 865 | } |
89476427 | 866 | |
025faf73 | 867 | if (opt_filter) { |
89476427 | 868 | command_ret = lttng_enable_event_with_exclusions(handle, &ev, channel_name, |
7ed70bc9 | 869 | opt_filter, exclusion_count, exclusion_list); |
89476427 JRJ |
870 | if (command_ret < 0) { |
871 | switch (-command_ret) { | |
16363652 | 872 | case LTTNG_ERR_FILTER_EXIST: |
85076754 | 873 | WARN("Filter on all events is already enabled" |
16363652 | 874 | " (channel %s, session %s)", |
85076754 | 875 | print_channel_name(channel_name), session_name); |
89476427 | 876 | warn = 1; |
16363652 DG |
877 | break; |
878 | default: | |
85076754 | 879 | ERR("All events: %s (channel %s, session %s, filter \'%s\')", |
da3d7d0e JRJ |
880 | lttng_strerror(command_ret), |
881 | command_ret == -LTTNG_ERR_NEED_CHANNEL_NAME | |
85076754 MD |
882 | ? print_raw_channel_name(channel_name) |
883 | : print_channel_name(channel_name), | |
884 | session_name, opt_filter); | |
89476427 | 885 | error = 1; |
16363652 DG |
886 | break; |
887 | } | |
89476427 | 888 | error_holder = command_ret; |
16363652 | 889 | } else { |
89476427 | 890 | ev.filter = 1; |
16363652 DG |
891 | MSG("Filter '%s' successfully set", opt_filter); |
892 | } | |
893 | } | |
89476427 JRJ |
894 | |
895 | if (lttng_opt_mi) { | |
896 | /* The wildcard * is used for kernel and ust domain to | |
897 | * represent ALL. We copy * in event name to force the wildcard use | |
898 | * for kernel domain | |
899 | * | |
900 | * Note: this is strictly for semantic and printing while in | |
901 | * machine interface mode. | |
902 | */ | |
903 | strcpy(ev.name, "*"); | |
904 | ||
905 | /* If we reach here the events are enabled */ | |
906 | if (!error && !warn) { | |
907 | ev.enabled = 1; | |
908 | } else { | |
909 | ev.enabled = 0; | |
910 | success = 0; | |
911 | } | |
970d848b | 912 | ret = mi_lttng_event(writer, &ev, 1, handle->domain.type); |
89476427 JRJ |
913 | if (ret) { |
914 | ret = CMD_ERROR; | |
915 | goto error; | |
916 | } | |
917 | ||
918 | /* print exclusion */ | |
919 | ret = mi_print_exclusion(exclusion_count, exclusion_list); | |
920 | if (ret) { | |
921 | ret = CMD_ERROR; | |
922 | goto error; | |
923 | } | |
924 | ||
925 | /* Success ? */ | |
926 | ret = mi_lttng_writer_write_element_bool(writer, | |
927 | mi_lttng_element_command_success, success); | |
928 | if (ret) { | |
929 | ret = CMD_ERROR; | |
930 | goto error; | |
931 | } | |
932 | ||
933 | /* Close event element */ | |
934 | ret = mi_lttng_writer_close_element(writer); | |
935 | if (ret) { | |
936 | ret = CMD_ERROR; | |
937 | goto error; | |
938 | } | |
939 | } | |
940 | ||
8c9ae521 | 941 | goto end; |
f3ed775e DG |
942 | } |
943 | ||
944 | /* Strip event list */ | |
945 | event_name = strtok(opt_event_list, ","); | |
946 | while (event_name != NULL) { | |
6181537c DG |
947 | /* Copy name and type of the event */ |
948 | strncpy(ev.name, event_name, LTTNG_SYMBOL_NAME_LEN); | |
949 | ev.name[LTTNG_SYMBOL_NAME_LEN - 1] = '\0'; | |
950 | ev.type = opt_event_type; | |
951 | ||
f3ed775e DG |
952 | /* Kernel tracer action */ |
953 | if (opt_kernel) { | |
954 | DBG("Enabling kernel event %s for channel %s", | |
85076754 MD |
955 | event_name, |
956 | print_channel_name(channel_name)); | |
f3ed775e DG |
957 | |
958 | switch (opt_event_type) { | |
7a3d1328 MD |
959 | case LTTNG_EVENT_ALL: /* Default behavior is tracepoint */ |
960 | ev.type = LTTNG_EVENT_TRACEPOINT; | |
961 | /* Fall-through */ | |
e6ddca71 | 962 | case LTTNG_EVENT_TRACEPOINT: |
f3ed775e | 963 | break; |
7d29a247 | 964 | case LTTNG_EVENT_PROBE: |
cf0e5467 | 965 | ret = parse_probe_opts(&ev, opt_probe); |
49d4e302 | 966 | if (ret) { |
cf0e5467 | 967 | ERR("Unable to parse probe options"); |
0d63dd19 DG |
968 | ret = 0; |
969 | goto error; | |
970 | } | |
f3ed775e DG |
971 | break; |
972 | case LTTNG_EVENT_FUNCTION: | |
8f0d098b | 973 | ret = parse_probe_opts(&ev, opt_function); |
49d4e302 | 974 | if (ret) { |
8f0d098b MD |
975 | ERR("Unable to parse function probe options"); |
976 | ret = 0; | |
977 | goto error; | |
978 | } | |
979 | break; | |
980 | case LTTNG_EVENT_FUNCTION_ENTRY: | |
6181537c DG |
981 | strncpy(ev.attr.ftrace.symbol_name, opt_function_entry_symbol, |
982 | LTTNG_SYMBOL_NAME_LEN); | |
99497cd0 | 983 | ev.attr.ftrace.symbol_name[LTTNG_SYMBOL_NAME_LEN - 1] = '\0'; |
f3ed775e | 984 | break; |
a54bd42d | 985 | case LTTNG_EVENT_SYSCALL: |
c6aa2d41 MD |
986 | ev.type = LTTNG_EVENT_SYSCALL; |
987 | break; | |
f3ed775e | 988 | default: |
1ab1ea0b | 989 | ret = CMD_UNDEFINED; |
f3ed775e DG |
990 | goto error; |
991 | } | |
0cda4f28 | 992 | |
0cda4f28 | 993 | /* kernel loglevels not implemented */ |
8005f29a | 994 | ev.loglevel_type = LTTNG_EVENT_LOGLEVEL_ALL; |
f3ed775e | 995 | } else if (opt_userspace) { /* User-space tracer action */ |
d78d6610 | 996 | #if 0 |
e14f64a8 DG |
997 | if (opt_cmd_name != NULL || opt_pid) { |
998 | MSG("Only supporting tracing all UST processes (-u) for now."); | |
1ab1ea0b | 999 | ret = CMD_UNDEFINED; |
2bdd86d4 MD |
1000 | goto error; |
1001 | } | |
d78d6610 | 1002 | #endif |
6181537c | 1003 | |
300b8fd5 | 1004 | DBG("Enabling UST event %s for channel %s, loglevel %s", event_name, |
85076754 | 1005 | print_channel_name(channel_name), opt_loglevel ? : "<all>"); |
2bdd86d4 MD |
1006 | |
1007 | switch (opt_event_type) { | |
1008 | case LTTNG_EVENT_ALL: /* Default behavior is tracepoint */ | |
2bdd86d4 MD |
1009 | /* Fall-through */ |
1010 | case LTTNG_EVENT_TRACEPOINT: | |
e4baff1e MD |
1011 | /* Copy name and type of the event */ |
1012 | ev.type = LTTNG_EVENT_TRACEPOINT; | |
1013 | strncpy(ev.name, event_name, LTTNG_SYMBOL_NAME_LEN); | |
1014 | ev.name[LTTNG_SYMBOL_NAME_LEN - 1] = '\0'; | |
2bdd86d4 MD |
1015 | break; |
1016 | case LTTNG_EVENT_PROBE: | |
1017 | case LTTNG_EVENT_FUNCTION: | |
1018 | case LTTNG_EVENT_FUNCTION_ENTRY: | |
1019 | case LTTNG_EVENT_SYSCALL: | |
1020 | default: | |
cc62c0c0 | 1021 | ERR("Event type not available for user-space tracing"); |
4ce78777 | 1022 | ret = CMD_UNSUPPORTED; |
2bdd86d4 MD |
1023 | goto error; |
1024 | } | |
0cda4f28 | 1025 | |
7ed70bc9 | 1026 | if (opt_exclude) { |
89476427 | 1027 | ev.exclusion = 1; |
d5dd17fd JI |
1028 | if (opt_event_type != LTTNG_EVENT_ALL && opt_event_type != LTTNG_EVENT_TRACEPOINT) { |
1029 | ERR("Exclusion option can only be used with tracepoint events"); | |
1030 | ret = CMD_ERROR; | |
1031 | goto error; | |
1032 | } | |
7ed70bc9 JI |
1033 | /* Free previously allocated items */ |
1034 | if (exclusion_list != NULL) { | |
1035 | while (exclusion_count--) { | |
1036 | free(exclusion_list[exclusion_count]); | |
1037 | } | |
1038 | free(exclusion_list); | |
1039 | exclusion_list = NULL; | |
1040 | } | |
1041 | /* Check for proper subsets */ | |
1042 | ret = check_exclusion_subsets(event_name, opt_exclude, | |
1043 | &exclusion_count, &exclusion_list); | |
1044 | if (ret == CMD_ERROR) { | |
1045 | goto error; | |
1046 | } | |
1047 | } | |
1048 | ||
0cda4f28 | 1049 | ev.loglevel_type = opt_loglevel_type; |
ed7f4083 | 1050 | if (opt_loglevel) { |
8005f29a MD |
1051 | ev.loglevel = loglevel_str_to_value(opt_loglevel); |
1052 | if (ev.loglevel == -1) { | |
1053 | ERR("Unknown loglevel %s", opt_loglevel); | |
2f70b271 | 1054 | ret = -LTTNG_ERR_INVALID; |
8005f29a MD |
1055 | goto error; |
1056 | } | |
22e25b71 MD |
1057 | } else { |
1058 | ev.loglevel = -1; | |
ed7f4083 | 1059 | } |
0e115563 | 1060 | } else if (opt_jul || opt_log4j || opt_python) { |
b9dfb167 DG |
1061 | if (opt_event_type != LTTNG_EVENT_ALL && |
1062 | opt_event_type != LTTNG_EVENT_TRACEPOINT) { | |
5cdb6027 | 1063 | ERR("Event type not supported for domain."); |
b9dfb167 DG |
1064 | ret = CMD_UNSUPPORTED; |
1065 | goto error; | |
1066 | } | |
b2064f54 DG |
1067 | |
1068 | ev.loglevel_type = opt_loglevel_type; | |
1069 | if (opt_loglevel) { | |
5cdb6027 DG |
1070 | if (opt_jul) { |
1071 | ev.loglevel = loglevel_jul_str_to_value(opt_loglevel); | |
1072 | } else if (opt_log4j) { | |
1073 | ev.loglevel = loglevel_log4j_str_to_value(opt_loglevel); | |
0e115563 DG |
1074 | } else if (opt_python) { |
1075 | ev.loglevel = loglevel_python_str_to_value(opt_loglevel); | |
5cdb6027 | 1076 | } |
b2064f54 DG |
1077 | if (ev.loglevel == -1) { |
1078 | ERR("Unknown loglevel %s", opt_loglevel); | |
1079 | ret = -LTTNG_ERR_INVALID; | |
1080 | goto error; | |
1081 | } | |
1082 | } else { | |
5cdb6027 DG |
1083 | if (opt_jul) { |
1084 | ev.loglevel = LTTNG_LOGLEVEL_JUL_ALL; | |
1085 | } else if (opt_log4j) { | |
1086 | ev.loglevel = LTTNG_LOGLEVEL_LOG4J_ALL; | |
0e115563 DG |
1087 | } else if (opt_python) { |
1088 | ev.loglevel = LTTNG_LOGLEVEL_PYTHON_DEBUG; | |
5cdb6027 | 1089 | } |
b2064f54 | 1090 | } |
b9dfb167 DG |
1091 | ev.type = LTTNG_EVENT_TRACEPOINT; |
1092 | strncpy(ev.name, event_name, LTTNG_SYMBOL_NAME_LEN); | |
1093 | ev.name[LTTNG_SYMBOL_NAME_LEN - 1] = '\0'; | |
f3ed775e | 1094 | } else { |
b9dfb167 | 1095 | print_missing_domain(); |
300b8fd5 | 1096 | ret = CMD_ERROR; |
f3ed775e DG |
1097 | goto error; |
1098 | } | |
1099 | ||
025faf73 | 1100 | if (!opt_filter) { |
9c48cab3 JI |
1101 | char *exclusion_string; |
1102 | ||
89476427 | 1103 | command_ret = lttng_enable_event_with_exclusions(handle, |
7ed70bc9 JI |
1104 | &ev, channel_name, |
1105 | NULL, exclusion_count, exclusion_list); | |
9c48cab3 | 1106 | exclusion_string = print_exclusions(exclusion_count, exclusion_list); |
89476427 | 1107 | if (command_ret < 0) { |
025faf73 | 1108 | /* Turn ret to positive value to handle the positive error code */ |
89476427 | 1109 | switch (-command_ret) { |
025faf73 | 1110 | case LTTNG_ERR_KERN_EVENT_EXIST: |
9c48cab3 | 1111 | WARN("Kernel event %s%s already enabled (channel %s, session %s)", |
85076754 | 1112 | event_name, |
9c48cab3 | 1113 | exclusion_string, |
85076754 | 1114 | print_channel_name(channel_name), session_name); |
89476427 | 1115 | warn = 1; |
025faf73 DG |
1116 | break; |
1117 | default: | |
9c48cab3 JI |
1118 | ERR("Event %s%s: %s (channel %s, session %s)", event_name, |
1119 | exclusion_string, | |
da3d7d0e JRJ |
1120 | lttng_strerror(command_ret), |
1121 | command_ret == -LTTNG_ERR_NEED_CHANNEL_NAME | |
85076754 MD |
1122 | ? print_raw_channel_name(channel_name) |
1123 | : print_channel_name(channel_name), | |
1124 | session_name); | |
89476427 | 1125 | error = 1; |
025faf73 DG |
1126 | break; |
1127 | } | |
89476427 | 1128 | error_holder = command_ret; |
025faf73 | 1129 | } else { |
5cdb6027 DG |
1130 | /* So we don't print the default channel name for agent domain. */ |
1131 | if (dom.type == LTTNG_DOMAIN_JUL || | |
1132 | dom.type == LTTNG_DOMAIN_LOG4J) { | |
49ceaa70 DG |
1133 | MSG("%s event %s%s enabled.", |
1134 | get_domain_str(dom.type), event_name, | |
1135 | exclusion_string); | |
1136 | } else { | |
1137 | MSG("%s event %s%s created in channel %s", | |
1138 | get_domain_str(dom.type), event_name, | |
1139 | exclusion_string, | |
1140 | print_channel_name(channel_name)); | |
1141 | } | |
42224349 | 1142 | } |
9c48cab3 | 1143 | free(exclusion_string); |
6181537c | 1144 | } |
025faf73 DG |
1145 | |
1146 | if (opt_filter) { | |
9c48cab3 JI |
1147 | char *exclusion_string; |
1148 | ||
89476427 JRJ |
1149 | /* Filter present */ |
1150 | ev.filter = 1; | |
1151 | ||
1152 | command_ret = lttng_enable_event_with_exclusions(handle, &ev, channel_name, | |
7ed70bc9 | 1153 | opt_filter, exclusion_count, exclusion_list); |
9c48cab3 JI |
1154 | exclusion_string = print_exclusions(exclusion_count, exclusion_list); |
1155 | ||
89476427 JRJ |
1156 | if (command_ret < 0) { |
1157 | switch (-command_ret) { | |
7671f53c | 1158 | case LTTNG_ERR_FILTER_EXIST: |
9c48cab3 | 1159 | WARN("Filter on event %s%s is already enabled" |
7671f53c | 1160 | " (channel %s, session %s)", |
85076754 | 1161 | event_name, |
9c48cab3 | 1162 | exclusion_string, |
85076754 | 1163 | print_channel_name(channel_name), session_name); |
89476427 | 1164 | warn = 1; |
7671f53c CB |
1165 | break; |
1166 | default: | |
9c48cab3 JI |
1167 | ERR("Event %s%s: %s (channel %s, session %s, filter \'%s\')", ev.name, |
1168 | exclusion_string, | |
da3d7d0e JRJ |
1169 | lttng_strerror(command_ret), |
1170 | command_ret == -LTTNG_ERR_NEED_CHANNEL_NAME | |
85076754 MD |
1171 | ? print_raw_channel_name(channel_name) |
1172 | : print_channel_name(channel_name), | |
1173 | session_name, opt_filter); | |
89476427 | 1174 | error = 1; |
7671f53c CB |
1175 | break; |
1176 | } | |
89476427 JRJ |
1177 | error_holder = command_ret; |
1178 | ||
16363652 | 1179 | } else { |
9c48cab3 JI |
1180 | MSG("Event %s%s: Filter '%s' successfully set", |
1181 | event_name, exclusion_string, | |
1182 | opt_filter); | |
53a80697 | 1183 | } |
9c48cab3 | 1184 | free(exclusion_string); |
53a80697 | 1185 | } |
6181537c | 1186 | |
89476427 JRJ |
1187 | if (lttng_opt_mi) { |
1188 | if (command_ret) { | |
1189 | success = 0; | |
1190 | ev.enabled = 0; | |
1191 | } else { | |
1192 | ev.enabled = 1; | |
1193 | } | |
1194 | ||
970d848b | 1195 | ret = mi_lttng_event(writer, &ev, 1, handle->domain.type); |
89476427 JRJ |
1196 | if (ret) { |
1197 | ret = CMD_ERROR; | |
1198 | goto error; | |
1199 | } | |
1200 | ||
1201 | /* print exclusion */ | |
1202 | ret = mi_print_exclusion(exclusion_count, exclusion_list); | |
1203 | if (ret) { | |
1204 | ret = CMD_ERROR; | |
1205 | goto error; | |
1206 | } | |
1207 | ||
1208 | /* Success ? */ | |
1209 | ret = mi_lttng_writer_write_element_bool(writer, | |
1210 | mi_lttng_element_command_success, success); | |
1211 | if (ret) { | |
1212 | ret = CMD_ERROR; | |
1213 | goto end; | |
1214 | } | |
1215 | ||
1216 | /* Close event element */ | |
1217 | ret = mi_lttng_writer_close_element(writer); | |
1218 | if (ret) { | |
1219 | ret = CMD_ERROR; | |
1220 | goto end; | |
1221 | } | |
1222 | } | |
1223 | ||
f3ed775e DG |
1224 | /* Next event */ |
1225 | event_name = strtok(NULL, ","); | |
89476427 JRJ |
1226 | /* Reset warn, error and success */ |
1227 | success = 1; | |
f3ed775e DG |
1228 | } |
1229 | ||
8c9ae521 | 1230 | end: |
89476427 JRJ |
1231 | /* Close Mi */ |
1232 | if (lttng_opt_mi) { | |
1233 | /* Close events element */ | |
1234 | ret = mi_lttng_writer_close_element(writer); | |
1235 | if (ret) { | |
1236 | ret = CMD_ERROR; | |
1237 | goto error; | |
1238 | } | |
1239 | } | |
f3ed775e | 1240 | error: |
ae856491 DG |
1241 | if (warn) { |
1242 | ret = CMD_WARNING; | |
1243 | } | |
89476427 JRJ |
1244 | if (error) { |
1245 | ret = CMD_ERROR; | |
1246 | } | |
cd80958d DG |
1247 | lttng_destroy_handle(handle); |
1248 | ||
7ed70bc9 JI |
1249 | if (exclusion_list != NULL) { |
1250 | while (exclusion_count--) { | |
1251 | free(exclusion_list[exclusion_count]); | |
1252 | } | |
1253 | free(exclusion_list); | |
1254 | } | |
1255 | ||
89476427 JRJ |
1256 | /* Overwrite ret with error_holder if there was an actual error with |
1257 | * enabling an event. | |
1258 | */ | |
1259 | ret = error_holder ? error_holder : ret; | |
1260 | ||
f3ed775e DG |
1261 | return ret; |
1262 | } | |
1263 | ||
1264 | /* | |
6181537c | 1265 | * Add event to trace session |
f3ed775e DG |
1266 | */ |
1267 | int cmd_enable_events(int argc, const char **argv) | |
1268 | { | |
89476427 | 1269 | int opt, ret = CMD_SUCCESS, command_ret = CMD_SUCCESS, success = 1; |
f3ed775e | 1270 | static poptContext pc; |
cd80958d | 1271 | char *session_name = NULL; |
de044b7a | 1272 | int event_type = -1; |
f3ed775e DG |
1273 | |
1274 | pc = poptGetContext(NULL, argc, argv, long_options, 0); | |
1275 | poptReadDefaultConfig(pc, 0); | |
1276 | ||
1277 | /* Default event type */ | |
7a3d1328 | 1278 | opt_event_type = LTTNG_EVENT_ALL; |
f3ed775e DG |
1279 | |
1280 | while ((opt = poptGetNextOpt(pc)) != -1) { | |
1281 | switch (opt) { | |
1282 | case OPT_HELP: | |
ca1c3607 | 1283 | usage(stdout); |
f3ed775e | 1284 | goto end; |
f3ed775e | 1285 | case OPT_TRACEPOINT: |
e6ddca71 | 1286 | opt_event_type = LTTNG_EVENT_TRACEPOINT; |
f3ed775e | 1287 | break; |
cf0e5467 | 1288 | case OPT_PROBE: |
7d29a247 | 1289 | opt_event_type = LTTNG_EVENT_PROBE; |
f3ed775e DG |
1290 | break; |
1291 | case OPT_FUNCTION: | |
1292 | opt_event_type = LTTNG_EVENT_FUNCTION; | |
8f0d098b MD |
1293 | break; |
1294 | case OPT_FUNCTION_ENTRY: | |
1295 | opt_event_type = LTTNG_EVENT_FUNCTION_ENTRY; | |
f3ed775e | 1296 | break; |
a54bd42d MD |
1297 | case OPT_SYSCALL: |
1298 | opt_event_type = LTTNG_EVENT_SYSCALL; | |
0133c199 | 1299 | break; |
eeac7d46 MD |
1300 | case OPT_USERSPACE: |
1301 | opt_userspace = 1; | |
eeac7d46 | 1302 | break; |
0cda4f28 | 1303 | case OPT_LOGLEVEL: |
8005f29a | 1304 | opt_loglevel_type = LTTNG_EVENT_LOGLEVEL_RANGE; |
0cda4f28 MD |
1305 | opt_loglevel = poptGetOptArg(pc); |
1306 | break; | |
1307 | case OPT_LOGLEVEL_ONLY: | |
8005f29a | 1308 | opt_loglevel_type = LTTNG_EVENT_LOGLEVEL_SINGLE; |
0cda4f28 | 1309 | opt_loglevel = poptGetOptArg(pc); |
13dce3b7 | 1310 | break; |
679b4943 SM |
1311 | case OPT_LIST_OPTIONS: |
1312 | list_cmd_options(stdout, long_options); | |
679b4943 | 1313 | goto end; |
53a80697 MD |
1314 | case OPT_FILTER: |
1315 | break; | |
fac3366c JI |
1316 | case OPT_EXCLUDE: |
1317 | break; | |
f3ed775e DG |
1318 | default: |
1319 | usage(stderr); | |
1320 | ret = CMD_UNDEFINED; | |
1321 | goto end; | |
1322 | } | |
de044b7a DG |
1323 | |
1324 | /* Validate event type. Multiple event type are not supported. */ | |
1325 | if (event_type == -1) { | |
1326 | event_type = opt_event_type; | |
1327 | } else { | |
1328 | if (event_type != opt_event_type) { | |
1329 | ERR("Multiple event type not supported."); | |
1330 | ret = CMD_ERROR; | |
1331 | goto end; | |
1332 | } | |
1333 | } | |
f3ed775e DG |
1334 | } |
1335 | ||
89476427 JRJ |
1336 | /* Mi check */ |
1337 | if (lttng_opt_mi) { | |
1338 | writer = mi_lttng_writer_create(fileno(stdout), lttng_opt_mi); | |
1339 | if (!writer) { | |
1340 | ret = -LTTNG_ERR_NOMEM; | |
1341 | goto end; | |
1342 | } | |
1343 | ||
1344 | /* Open command element */ | |
1345 | ret = mi_lttng_writer_command_open(writer, | |
1346 | mi_lttng_element_command_enable_event); | |
1347 | if (ret) { | |
1348 | ret = CMD_ERROR; | |
1349 | goto end; | |
1350 | } | |
1351 | ||
1352 | /* Open output element */ | |
1353 | ret = mi_lttng_writer_open_element(writer, | |
1354 | mi_lttng_element_command_output); | |
1355 | if (ret) { | |
1356 | ret = CMD_ERROR; | |
1357 | goto end; | |
1358 | } | |
1359 | } | |
1360 | ||
f3ed775e DG |
1361 | opt_event_list = (char*) poptGetArg(pc); |
1362 | if (opt_event_list == NULL && opt_enable_all == 0) { | |
1363 | ERR("Missing event name(s).\n"); | |
1364 | usage(stderr); | |
ca1c3607 | 1365 | ret = CMD_ERROR; |
f3ed775e DG |
1366 | goto end; |
1367 | } | |
1368 | ||
cd80958d DG |
1369 | if (!opt_session_name) { |
1370 | session_name = get_session_name(); | |
1371 | if (session_name == NULL) { | |
89476427 JRJ |
1372 | command_ret = CMD_ERROR; |
1373 | success = 0; | |
1374 | goto mi_closing; | |
cd80958d DG |
1375 | } |
1376 | } else { | |
1377 | session_name = opt_session_name; | |
1378 | } | |
1379 | ||
89476427 JRJ |
1380 | command_ret = enable_events(session_name); |
1381 | if (command_ret) { | |
1382 | success = 0; | |
1383 | goto mi_closing; | |
1384 | } | |
1385 | ||
1386 | mi_closing: | |
1387 | /* Mi closing */ | |
1388 | if (lttng_opt_mi) { | |
1389 | /* Close output element */ | |
1390 | ret = mi_lttng_writer_close_element(writer); | |
1391 | if (ret) { | |
1392 | ret = CMD_ERROR; | |
1393 | goto end; | |
1394 | } | |
1395 | ||
1396 | ret = mi_lttng_writer_write_element_bool(writer, | |
1397 | mi_lttng_element_command_success, success); | |
1398 | if (ret) { | |
1399 | ret = CMD_ERROR; | |
1400 | goto end; | |
1401 | } | |
1402 | ||
1403 | /* Command element close */ | |
1404 | ret = mi_lttng_writer_command_close(writer); | |
1405 | if (ret) { | |
1406 | ret = CMD_ERROR; | |
1407 | goto end; | |
1408 | } | |
1409 | } | |
f3ed775e DG |
1410 | |
1411 | end: | |
89476427 JRJ |
1412 | /* Mi clean-up */ |
1413 | if (writer && mi_lttng_writer_destroy(writer)) { | |
1414 | /* Preserve original error code */ | |
1415 | ret = ret ? ret : LTTNG_ERR_MI_IO_FAIL; | |
1416 | } | |
1417 | ||
cd80958d DG |
1418 | if (opt_session_name == NULL) { |
1419 | free(session_name); | |
1420 | } | |
1421 | ||
89476427 JRJ |
1422 | /* Overwrite ret if an error occurred in enable_events */ |
1423 | ret = command_ret ? command_ret : ret; | |
1424 | ||
ca1c3607 | 1425 | poptFreeContext(pc); |
f3ed775e DG |
1426 | return ret; |
1427 | } |