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 | |
e3a639d0 | 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 | |
c399183f | 30 | #include "../command.h" |
42224349 | 31 | #include <src/common/sessiond-comm/sessiond-comm.h> |
f3ed775e | 32 | |
134cfa5c MD |
33 | #if (LTTNG_SYMBOL_NAME_LEN == 256) |
34 | #define LTTNG_SYMBOL_NAME_LEN_SCANF_IS_A_BROKEN_API "255" | |
35 | #endif | |
36 | ||
f3ed775e DG |
37 | static char *opt_event_list; |
38 | static int opt_event_type; | |
0cda4f28 MD |
39 | static const char *opt_loglevel; |
40 | static int opt_loglevel_type; | |
6181537c | 41 | static int opt_kernel; |
5440dc42 | 42 | static char *opt_session_name; |
f3ed775e | 43 | static int opt_userspace; |
b9dfb167 | 44 | static int opt_jul; |
f3ed775e | 45 | static int opt_enable_all; |
cf0e5467 | 46 | static char *opt_probe; |
8f0d098b MD |
47 | static char *opt_function; |
48 | static char *opt_function_entry_symbol; | |
f3ed775e | 49 | static char *opt_channel_name; |
53a80697 | 50 | static char *opt_filter; |
fac3366c | 51 | static char *opt_exclude; |
d78d6610 DG |
52 | #if 0 |
53 | /* Not implemented yet */ | |
54 | static char *opt_cmd_name; | |
55 | static pid_t opt_pid; | |
56 | #endif | |
f3ed775e DG |
57 | |
58 | enum { | |
59 | OPT_HELP = 1, | |
f3ed775e | 60 | OPT_TRACEPOINT, |
cf0e5467 | 61 | OPT_PROBE, |
f3ed775e | 62 | OPT_FUNCTION, |
8f0d098b | 63 | OPT_FUNCTION_ENTRY, |
a54bd42d | 64 | OPT_SYSCALL, |
eeac7d46 | 65 | OPT_USERSPACE, |
0cda4f28 MD |
66 | OPT_LOGLEVEL, |
67 | OPT_LOGLEVEL_ONLY, | |
679b4943 | 68 | OPT_LIST_OPTIONS, |
53a80697 | 69 | OPT_FILTER, |
fac3366c | 70 | OPT_EXCLUDE, |
f3ed775e DG |
71 | }; |
72 | ||
cd80958d DG |
73 | static struct lttng_handle *handle; |
74 | ||
f3ed775e DG |
75 | static struct poptOption long_options[] = { |
76 | /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */ | |
77 | {"help", 'h', POPT_ARG_NONE, 0, OPT_HELP, 0, 0}, | |
5440dc42 | 78 | {"session", 's', POPT_ARG_STRING, &opt_session_name, 0, 0, 0}, |
e14f64a8 | 79 | {"all", 'a', POPT_ARG_VAL, &opt_enable_all, 1, 0, 0}, |
f3ed775e DG |
80 | {"channel", 'c', POPT_ARG_STRING, &opt_channel_name, 0, 0, 0}, |
81 | {"kernel", 'k', POPT_ARG_VAL, &opt_kernel, 1, 0, 0}, | |
d78d6610 | 82 | {"userspace", 'u', POPT_ARG_NONE, 0, OPT_USERSPACE, 0, 0}, |
b9dfb167 | 83 | {"jul", 'j', POPT_ARG_VAL, &opt_jul, 1, 0, 0}, |
f3ed775e | 84 | {"tracepoint", 0, POPT_ARG_NONE, 0, OPT_TRACEPOINT, 0, 0}, |
7ebae521 | 85 | {"probe", 0, POPT_ARG_STRING, &opt_probe, OPT_PROBE, 0, 0}, |
40e9d5d3 | 86 | {"function", 0, POPT_ARG_STRING, &opt_function, OPT_FUNCTION, 0, 0}, |
b213d387 MD |
87 | #if 0 |
88 | /* | |
89 | * Currently removed from lttng kernel tracer. Removed from | |
90 | * lttng UI to discourage its use. | |
91 | */ | |
40e9d5d3 | 92 | {"function:entry", 0, POPT_ARG_STRING, &opt_function_entry_symbol, OPT_FUNCTION_ENTRY, 0, 0}, |
b213d387 | 93 | #endif |
7ebae521 | 94 | {"syscall", 0, POPT_ARG_NONE, 0, OPT_SYSCALL, 0, 0}, |
0cda4f28 MD |
95 | {"loglevel", 0, POPT_ARG_STRING, 0, OPT_LOGLEVEL, 0, 0}, |
96 | {"loglevel-only", 0, POPT_ARG_STRING, 0, OPT_LOGLEVEL_ONLY, 0, 0}, | |
679b4943 | 97 | {"list-options", 0, POPT_ARG_NONE, NULL, OPT_LIST_OPTIONS, NULL, NULL}, |
53a80697 | 98 | {"filter", 'f', POPT_ARG_STRING, &opt_filter, OPT_FILTER, 0, 0}, |
fac3366c | 99 | {"exclude", 'x', POPT_ARG_STRING, &opt_exclude, OPT_EXCLUDE, 0, 0}, |
f3ed775e DG |
100 | {0, 0, 0, 0, 0, 0, 0} |
101 | }; | |
102 | ||
103 | /* | |
104 | * usage | |
105 | */ | |
106 | static void usage(FILE *ofp) | |
107 | { | |
32a6298d | 108 | fprintf(ofp, "usage: lttng enable-event NAME[,NAME2,...] [-k|-u] [OPTIONS] \n"); |
f3ed775e | 109 | fprintf(ofp, "\n"); |
32a6298d | 110 | fprintf(ofp, "Options:\n"); |
f3ed775e | 111 | fprintf(ofp, " -h, --help Show this help\n"); |
679b4943 | 112 | fprintf(ofp, " --list-options Simple listing of options\n"); |
32a6298d DG |
113 | fprintf(ofp, " -s, --session NAME Apply to session name\n"); |
114 | fprintf(ofp, " -c, --channel NAME Apply to this channel\n"); | |
e08bff8d | 115 | fprintf(ofp, " -a, --all Enable all tracepoints and syscalls\n"); |
f3ed775e | 116 | fprintf(ofp, " -k, --kernel Apply for the kernel tracer\n"); |
27221701 | 117 | fprintf(ofp, " -u, --userspace Apply to the user-space tracer\n"); |
b9dfb167 | 118 | fprintf(ofp, " -j, --jul Apply for Java application using JUL\n"); |
f3ed775e DG |
119 | fprintf(ofp, "\n"); |
120 | fprintf(ofp, "Event options:\n"); | |
121 | fprintf(ofp, " --tracepoint Tracepoint event (default)\n"); | |
be49af1e MD |
122 | fprintf(ofp, " - userspace tracer supports wildcards at end of string.\n"); |
123 | fprintf(ofp, " Don't forget to quote to deal with bash expansion.\n"); | |
124 | fprintf(ofp, " e.g.:\n"); | |
125 | fprintf(ofp, " \"*\"\n"); | |
126 | fprintf(ofp, " \"app_component:na*\"\n"); | |
6a240cd9 | 127 | fprintf(ofp, " --probe (addr | symbol | symbol+offset)\n"); |
cf0e5467 MD |
128 | fprintf(ofp, " Dynamic probe.\n"); |
129 | fprintf(ofp, " Addr and offset can be octal (0NNN...),\n"); | |
130 | fprintf(ofp, " decimal (NNN...) or hexadecimal (0xNNN...)\n"); | |
6a240cd9 | 131 | fprintf(ofp, " --function (addr | symbol | symbol+offset)\n"); |
8f0d098b MD |
132 | fprintf(ofp, " Dynamic function entry/return probe.\n"); |
133 | fprintf(ofp, " Addr and offset can be octal (0NNN...),\n"); | |
134 | fprintf(ofp, " decimal (NNN...) or hexadecimal (0xNNN...)\n"); | |
b213d387 | 135 | #if 0 |
8f0d098b MD |
136 | fprintf(ofp, " --function:entry symbol\n"); |
137 | fprintf(ofp, " Function tracer event\n"); | |
b213d387 | 138 | #endif |
a54bd42d | 139 | fprintf(ofp, " --syscall System call event\n"); |
f3ed775e | 140 | fprintf(ofp, "\n"); |
300b8fd5 | 141 | fprintf(ofp, " --loglevel name\n"); |
bc358d3e DG |
142 | fprintf(ofp, " Tracepoint loglevel range from 0 to loglevel.\n"); |
143 | fprintf(ofp, " For JUL domain, see the table below for the range values.\n"); | |
300b8fd5 MD |
144 | fprintf(ofp, " --loglevel-only name\n"); |
145 | fprintf(ofp, " Tracepoint loglevel (only this loglevel)\n"); | |
146 | fprintf(ofp, "\n"); | |
0c8477c8 MD |
147 | fprintf(ofp, " The loglevel or loglevel-only options should be\n"); |
148 | fprintf(ofp, " combined with a tracepoint name or tracepoint\n"); | |
149 | fprintf(ofp, " wildcard.\n"); | |
150 | fprintf(ofp, " Available loglevels:\n"); | |
151 | fprintf(ofp, " (higher value is more verbose)\n"); | |
46839cc2 MD |
152 | fprintf(ofp, " TRACE_EMERG = 0\n"); |
153 | fprintf(ofp, " TRACE_ALERT = 1\n"); | |
154 | fprintf(ofp, " TRACE_CRIT = 2\n"); | |
155 | fprintf(ofp, " TRACE_ERR = 3\n"); | |
156 | fprintf(ofp, " TRACE_WARNING = 4\n"); | |
157 | fprintf(ofp, " TRACE_NOTICE = 5\n"); | |
158 | fprintf(ofp, " TRACE_INFO = 6\n"); | |
159 | fprintf(ofp, " TRACE_DEBUG_SYSTEM = 7\n"); | |
160 | fprintf(ofp, " TRACE_DEBUG_PROGRAM = 8\n"); | |
161 | fprintf(ofp, " TRACE_DEBUG_PROCESS = 9\n"); | |
162 | fprintf(ofp, " TRACE_DEBUG_MODULE = 10\n"); | |
163 | fprintf(ofp, " TRACE_DEBUG_UNIT = 11\n"); | |
164 | fprintf(ofp, " TRACE_DEBUG_FUNCTION = 12\n"); | |
165 | fprintf(ofp, " TRACE_DEBUG_LINE = 13\n"); | |
166 | fprintf(ofp, " TRACE_DEBUG = 14\n"); | |
167 | fprintf(ofp, " (shortcuts such as \"system\" are allowed)\n"); | |
e3a639d0 DG |
168 | fprintf(ofp, "\n"); |
169 | fprintf(ofp, " Available JUL domain loglevels:\n"); | |
170 | fprintf(ofp, " JUL_OFF = INT32_MAX\n"); | |
171 | fprintf(ofp, " JUL_SEVERE = %d\n", LTTNG_LOGLEVEL_JUL_SEVERE); | |
172 | fprintf(ofp, " JUL_WARNING = %d\n", LTTNG_LOGLEVEL_JUL_WARNING); | |
173 | fprintf(ofp, " JUL_INFO = %d\n", LTTNG_LOGLEVEL_JUL_INFO); | |
174 | fprintf(ofp, " JUL_CONFIG = %d\n", LTTNG_LOGLEVEL_JUL_CONFIG); | |
175 | fprintf(ofp, " JUL_FINE = %d\n", LTTNG_LOGLEVEL_JUL_FINE); | |
176 | fprintf(ofp, " JUL_FINER = %d\n", LTTNG_LOGLEVEL_JUL_FINER); | |
177 | fprintf(ofp, " JUL_FINEST = %d\n", LTTNG_LOGLEVEL_JUL_FINEST); | |
178 | fprintf(ofp, " JUL_ALL = INT32_MIN\n"); | |
179 | fprintf(ofp, " (shortcuts such as \"severe\" are allowed)\n"); | |
180 | fprintf(ofp, "\n"); | |
f2611ab0 | 181 | fprintf(ofp, " -f, --filter \'expression\'\n"); |
ee8ccafa MD |
182 | fprintf(ofp, " Filter expression on event fields and context.\n"); |
183 | fprintf(ofp, " Event recording depends on evaluation.\n"); | |
919e300c MD |
184 | fprintf(ofp, " Only specify on first activation of\n"); |
185 | fprintf(ofp, " a given event within a session.\n"); | |
186 | fprintf(ofp, " Filter only allowed when enabling\n"); | |
187 | fprintf(ofp, " events within a session before tracing\n"); | |
9bd578f5 MD |
188 | fprintf(ofp, " is started. If the filter fails to link\n"); |
189 | fprintf(ofp, " with the event within the traced domain,\n"); | |
190 | fprintf(ofp, " the event will be discarded. Currently,\n"); | |
191 | fprintf(ofp, " filter is only implemented for the user-space\n"); | |
192 | fprintf(ofp, " tracer.\n"); | |
193 | fprintf(ofp, " Expression examples:.\n"); | |
194 | fprintf(ofp, " \n"); | |
195 | fprintf(ofp, " 'intfield > 500 && intfield < 503'\n"); | |
6a240cd9 | 196 | fprintf(ofp, " '(strfield == \"test\" || intfield != 10) && intfield > 33'\n"); |
9bd578f5 MD |
197 | fprintf(ofp, " 'doublefield > 1.1 && intfield < 5.3'\n"); |
198 | fprintf(ofp, " \n"); | |
199 | fprintf(ofp, " Wildcards are allowed at the end of strings:\n"); | |
200 | fprintf(ofp, " 'seqfield1 == \"te*\"'\n"); | |
201 | fprintf(ofp, " In string literals, the escape character is '\\'.\n"); | |
202 | fprintf(ofp, " Use '\\*' for the '*' character, and '\\\\' for\n"); | |
ee8ccafa MD |
203 | fprintf(ofp, " the '\\' character. Wildcard match any sequence of,\n"); |
204 | fprintf(ofp, " characters including an empty sub-string (match 0 or\n"); | |
205 | fprintf(ofp, " more characters).\n"); | |
206 | fprintf(ofp, "\n"); | |
207 | fprintf(ofp, " Context information can be used for filtering. The\n"); | |
208 | fprintf(ofp, " examples below show usage of context filtering on\n"); | |
209 | fprintf(ofp, " process name (with a wildcard), process ID range, and\n"); | |
210 | fprintf(ofp, " unique thread ID for filtering. The process and\n"); | |
211 | fprintf(ofp, " thread ID of running applications can be found under\n"); | |
212 | fprintf(ofp, " columns \"PID\" and \"LWP\" of the \"ps -eLf\" command.\n"); | |
213 | fprintf(ofp, "\n"); | |
214 | fprintf(ofp, " '$ctx.procname == \"demo*\"'\n"); | |
215 | fprintf(ofp, " '$ctx.vpid >= 4433 && $ctx.vpid < 4455'\n"); | |
216 | fprintf(ofp, " '$ctx.vtid == 1234'\n"); | |
c2063d0b JI |
217 | fprintf(ofp, " -x, --exclude LIST\n"); |
218 | fprintf(ofp, " Add exclusions to UST tracepoints:\n"); | |
219 | fprintf(ofp, " Events that match any of the items\n"); | |
220 | fprintf(ofp, " in the comma-separated LIST are not\n"); | |
221 | fprintf(ofp, " enabled, even if they match a wildcard\n"); | |
222 | fprintf(ofp, " definition of the event.\n"); | |
300b8fd5 | 223 | fprintf(ofp, "\n"); |
f3ed775e DG |
224 | } |
225 | ||
0d63dd19 | 226 | /* |
6181537c | 227 | * Parse probe options. |
0d63dd19 | 228 | */ |
cf0e5467 | 229 | static int parse_probe_opts(struct lttng_event *ev, char *opt) |
0d63dd19 | 230 | { |
35ae3228 JRJ |
231 | int ret = CMD_SUCCESS; |
232 | int match; | |
8ff0bbd0 | 233 | char s_hex[19]; |
134cfa5c | 234 | #define S_HEX_LEN_SCANF_IS_A_BROKEN_API "18" /* 18 is (19 - 1) (\0 is extra) */ |
0d63dd19 DG |
235 | char name[LTTNG_SYMBOL_NAME_LEN]; |
236 | ||
237 | if (opt == NULL) { | |
35ae3228 | 238 | ret = CMD_ERROR; |
8f0d098b | 239 | goto end; |
0d63dd19 DG |
240 | } |
241 | ||
242 | /* Check for symbol+offset */ | |
35ae3228 | 243 | match = sscanf(opt, "%" LTTNG_SYMBOL_NAME_LEN_SCANF_IS_A_BROKEN_API |
134cfa5c | 244 | "[^'+']+%" S_HEX_LEN_SCANF_IS_A_BROKEN_API "s", name, s_hex); |
35ae3228 | 245 | if (match == 2) { |
7d29a247 | 246 | strncpy(ev->attr.probe.symbol_name, name, LTTNG_SYMBOL_NAME_LEN); |
99497cd0 | 247 | ev->attr.probe.symbol_name[LTTNG_SYMBOL_NAME_LEN - 1] = '\0'; |
cf0e5467 | 248 | DBG("probe symbol %s", ev->attr.probe.symbol_name); |
9d035200 | 249 | if (*s_hex == '\0') { |
8ff0bbd0 | 250 | ERR("Invalid probe offset %s", s_hex); |
35ae3228 | 251 | ret = CMD_ERROR; |
8f0d098b | 252 | goto end; |
0d63dd19 | 253 | } |
8ff0bbd0 | 254 | ev->attr.probe.offset = strtoul(s_hex, NULL, 0); |
cf0e5467 | 255 | DBG("probe offset %" PRIu64, ev->attr.probe.offset); |
3000dc78 | 256 | ev->attr.probe.addr = 0; |
8f0d098b MD |
257 | goto end; |
258 | } | |
259 | ||
260 | /* Check for symbol */ | |
261 | if (isalpha(name[0])) { | |
35ae3228 | 262 | match = sscanf(opt, "%" LTTNG_SYMBOL_NAME_LEN_SCANF_IS_A_BROKEN_API "s", |
134cfa5c | 263 | name); |
35ae3228 | 264 | if (match == 1) { |
8f0d098b | 265 | strncpy(ev->attr.probe.symbol_name, name, LTTNG_SYMBOL_NAME_LEN); |
99497cd0 | 266 | ev->attr.probe.symbol_name[LTTNG_SYMBOL_NAME_LEN - 1] = '\0'; |
8f0d098b MD |
267 | DBG("probe symbol %s", ev->attr.probe.symbol_name); |
268 | ev->attr.probe.offset = 0; | |
269 | DBG("probe offset %" PRIu64, ev->attr.probe.offset); | |
270 | ev->attr.probe.addr = 0; | |
271 | goto end; | |
272 | } | |
0d63dd19 DG |
273 | } |
274 | ||
275 | /* Check for address */ | |
35ae3228 JRJ |
276 | match = sscanf(opt, "%" S_HEX_LEN_SCANF_IS_A_BROKEN_API "s", s_hex); |
277 | if (match > 0) { | |
9d035200 | 278 | if (*s_hex == '\0') { |
8ff0bbd0 | 279 | ERR("Invalid probe address %s", s_hex); |
35ae3228 | 280 | ret = CMD_ERROR; |
8f0d098b | 281 | goto end; |
0d63dd19 | 282 | } |
8ff0bbd0 | 283 | ev->attr.probe.addr = strtoul(s_hex, NULL, 0); |
cf0e5467 | 284 | DBG("probe addr %" PRIu64, ev->attr.probe.addr); |
3000dc78 DG |
285 | ev->attr.probe.offset = 0; |
286 | memset(ev->attr.probe.symbol_name, 0, LTTNG_SYMBOL_NAME_LEN); | |
8f0d098b | 287 | goto end; |
0d63dd19 DG |
288 | } |
289 | ||
290 | /* No match */ | |
35ae3228 | 291 | ret = CMD_ERROR; |
0d63dd19 | 292 | |
8f0d098b | 293 | end: |
0d63dd19 DG |
294 | return ret; |
295 | } | |
296 | ||
e3a639d0 DG |
297 | /* |
298 | * Maps JUL loglevel from string to value | |
299 | */ | |
300 | static int loglevel_jul_str_to_value(const char *inputstr) | |
301 | { | |
302 | int i = 0; | |
303 | char str[LTTNG_SYMBOL_NAME_LEN]; | |
304 | ||
305 | /* | |
306 | * Loop up to LTTNG_SYMBOL_NAME_LEN minus one because the NULL bytes is | |
307 | * added at the end of the loop so a the upper bound we avoid the overflow. | |
308 | */ | |
309 | while (i < (LTTNG_SYMBOL_NAME_LEN - 1) && inputstr[i] != '\0') { | |
310 | str[i] = toupper(inputstr[i]); | |
311 | i++; | |
312 | } | |
313 | str[i] = '\0'; | |
314 | ||
315 | if (!strcmp(str, "JUL_OFF") || !strcmp(str, "OFF")) { | |
316 | return LTTNG_LOGLEVEL_JUL_OFF; | |
317 | } else if (!strcmp(str, "JUL_SEVERE") || !strcmp(str, "SEVERE")) { | |
318 | return LTTNG_LOGLEVEL_JUL_SEVERE; | |
319 | } else if (!strcmp(str, "JUL_WARNING") || !strcmp(str, "WARNING")) { | |
320 | return LTTNG_LOGLEVEL_JUL_WARNING; | |
321 | } else if (!strcmp(str, "JUL_INFO") || !strcmp(str, "INFO")) { | |
322 | return LTTNG_LOGLEVEL_JUL_INFO; | |
323 | } else if (!strcmp(str, "JUL_CONFIG") || !strcmp(str, "CONFIG")) { | |
324 | return LTTNG_LOGLEVEL_JUL_CONFIG; | |
325 | } else if (!strcmp(str, "JUL_FINE") || !strcmp(str, "FINE")) { | |
326 | return LTTNG_LOGLEVEL_JUL_FINE; | |
327 | } else if (!strcmp(str, "JUL_FINER") || !strcmp(str, "FINER")) { | |
328 | return LTTNG_LOGLEVEL_JUL_FINER; | |
329 | } else if (!strcmp(str, "JUL_FINEST") || !strcmp(str, "FINEST")) { | |
330 | return LTTNG_LOGLEVEL_JUL_FINEST; | |
331 | } else if (!strcmp(str, "JUL_ALL") || !strcmp(str, "ALL")) { | |
332 | return LTTNG_LOGLEVEL_JUL_ALL; | |
333 | } else { | |
334 | return -1; | |
335 | } | |
336 | } | |
337 | ||
8005f29a | 338 | /* |
0c8477c8 | 339 | * Maps loglevel from string to value |
8005f29a MD |
340 | */ |
341 | static | |
46839cc2 | 342 | int loglevel_str_to_value(const char *inputstr) |
8005f29a | 343 | { |
46839cc2 MD |
344 | int i = 0; |
345 | char str[LTTNG_SYMBOL_NAME_LEN]; | |
346 | ||
e051e07c DG |
347 | /* |
348 | * Loop up to LTTNG_SYMBOL_NAME_LEN minus one because the NULL bytes is | |
349 | * added at the end of the loop so a the upper bound we avoid the overflow. | |
350 | */ | |
351 | while (i < (LTTNG_SYMBOL_NAME_LEN - 1) && inputstr[i] != '\0') { | |
46839cc2 MD |
352 | str[i] = toupper(inputstr[i]); |
353 | i++; | |
354 | } | |
355 | str[i] = '\0'; | |
356 | if (!strcmp(str, "TRACE_EMERG") || !strcmp(str, "EMERG")) { | |
357 | return LTTNG_LOGLEVEL_EMERG; | |
358 | } else if (!strcmp(str, "TRACE_ALERT") || !strcmp(str, "ALERT")) { | |
359 | return LTTNG_LOGLEVEL_ALERT; | |
360 | } else if (!strcmp(str, "TRACE_CRIT") || !strcmp(str, "CRIT")) { | |
361 | return LTTNG_LOGLEVEL_CRIT; | |
362 | } else if (!strcmp(str, "TRACE_ERR") || !strcmp(str, "ERR")) { | |
363 | return LTTNG_LOGLEVEL_ERR; | |
364 | } else if (!strcmp(str, "TRACE_WARNING") || !strcmp(str, "WARNING")) { | |
365 | return LTTNG_LOGLEVEL_WARNING; | |
366 | } else if (!strcmp(str, "TRACE_NOTICE") || !strcmp(str, "NOTICE")) { | |
367 | return LTTNG_LOGLEVEL_NOTICE; | |
368 | } else if (!strcmp(str, "TRACE_INFO") || !strcmp(str, "INFO")) { | |
369 | return LTTNG_LOGLEVEL_INFO; | |
370 | } else if (!strcmp(str, "TRACE_DEBUG_SYSTEM") || !strcmp(str, "DEBUG_SYSTEM") || !strcmp(str, "SYSTEM")) { | |
371 | return LTTNG_LOGLEVEL_DEBUG_SYSTEM; | |
372 | } else if (!strcmp(str, "TRACE_DEBUG_PROGRAM") || !strcmp(str, "DEBUG_PROGRAM") || !strcmp(str, "PROGRAM")) { | |
373 | return LTTNG_LOGLEVEL_DEBUG_PROGRAM; | |
374 | } else if (!strcmp(str, "TRACE_DEBUG_PROCESS") || !strcmp(str, "DEBUG_PROCESS") || !strcmp(str, "PROCESS")) { | |
375 | return LTTNG_LOGLEVEL_DEBUG_PROCESS; | |
376 | } else if (!strcmp(str, "TRACE_DEBUG_MODULE") || !strcmp(str, "DEBUG_MODULE") || !strcmp(str, "MODULE")) { | |
377 | return LTTNG_LOGLEVEL_DEBUG_MODULE; | |
378 | } else if (!strcmp(str, "TRACE_DEBUG_UNIT") || !strcmp(str, "DEBUG_UNIT") || !strcmp(str, "UNIT")) { | |
379 | return LTTNG_LOGLEVEL_DEBUG_UNIT; | |
380 | } else if (!strcmp(str, "TRACE_DEBUG_FUNCTION") || !strcmp(str, "DEBUG_FUNCTION") || !strcmp(str, "FUNCTION")) { | |
381 | return LTTNG_LOGLEVEL_DEBUG_FUNCTION; | |
382 | } else if (!strcmp(str, "TRACE_DEBUG_LINE") || !strcmp(str, "DEBUG_LINE") || !strcmp(str, "LINE")) { | |
383 | return LTTNG_LOGLEVEL_DEBUG_LINE; | |
384 | } else if (!strcmp(str, "TRACE_DEBUG") || !strcmp(str, "DEBUG")) { | |
385 | return LTTNG_LOGLEVEL_DEBUG; | |
8005f29a MD |
386 | } else { |
387 | return -1; | |
388 | } | |
389 | } | |
390 | ||
85076754 MD |
391 | static |
392 | const char *print_channel_name(const char *name) | |
393 | { | |
394 | return name ? : DEFAULT_CHANNEL_NAME; | |
395 | } | |
396 | ||
397 | static | |
398 | const char *print_raw_channel_name(const char *name) | |
399 | { | |
400 | return name ? : "<default>"; | |
401 | } | |
402 | ||
9c48cab3 JI |
403 | /* |
404 | * Return allocated string for pretty-printing exclusion names. | |
405 | */ | |
406 | static | |
407 | char *print_exclusions(int count, char **names) | |
408 | { | |
409 | int length = 0; | |
410 | int i; | |
411 | const char *preamble = " excluding "; | |
412 | char *ret; | |
413 | ||
414 | if (count == 0) { | |
415 | return strdup(""); | |
416 | } | |
417 | ||
418 | /* calculate total required length */ | |
419 | for (i = 0; i < count; i++) { | |
420 | length += strlen(names[i]) + 1; | |
421 | } | |
422 | ||
423 | /* add length of preamble + one for NUL - one for last (missing) comma */ | |
424 | length += strlen(preamble); | |
425 | ret = malloc(length); | |
426 | strncpy(ret, preamble, length); | |
427 | for (i = 0; i < count; i++) { | |
428 | strcat(ret, names[i]); | |
429 | if (i != count - 1) { | |
430 | strcat(ret, ","); | |
431 | } | |
432 | } | |
433 | return ret; | |
434 | } | |
435 | ||
748bde76 JI |
436 | /* |
437 | * Compare list of exclusions against an event name. | |
438 | * Return a list of legal exclusion names. | |
439 | * Produce an error or a warning about others (depending on the situation) | |
440 | */ | |
441 | static | |
442 | int check_exclusion_subsets(const char *event_name, | |
443 | const char *exclusions, | |
444 | int *exclusion_count_ptr, | |
445 | char ***exclusion_list_ptr) | |
446 | { | |
447 | const char *excluder_ptr; | |
448 | const char *event_ptr; | |
449 | const char *next_excluder; | |
450 | int excluder_length; | |
451 | int exclusion_count = 0; | |
452 | char **exclusion_list = NULL; | |
453 | int ret = CMD_SUCCESS; | |
454 | ||
455 | if (event_name[strlen(event_name) - 1] != '*') { | |
456 | ERR("Event %s: Excluders can only be used with wildcarded events", event_name); | |
457 | goto error; | |
458 | } | |
459 | ||
460 | next_excluder = exclusions; | |
461 | while (*next_excluder != 0) { | |
462 | event_ptr = event_name; | |
463 | excluder_ptr = next_excluder; | |
464 | excluder_length = strcspn(next_excluder, ","); | |
465 | ||
466 | /* Scan both the excluder and the event letter by letter */ | |
467 | while (1) { | |
468 | char e, x; | |
469 | ||
470 | e = *event_ptr; | |
471 | x = *excluder_ptr; | |
472 | ||
473 | if (x == '*') { | |
474 | /* Event is a subset of the excluder */ | |
475 | ERR("Event %s: %.*s excludes all events from %s", | |
476 | event_name, | |
477 | excluder_length, | |
478 | next_excluder, | |
479 | event_name); | |
480 | goto error; | |
481 | } | |
482 | if (e == '*') { | |
483 | /* Excluder is a proper subset of event */ | |
484 | exclusion_count++; | |
485 | exclusion_list = realloc(exclusion_list, sizeof(char **) * exclusion_count); | |
486 | exclusion_list[exclusion_count - 1] = strndup(next_excluder, excluder_length); | |
487 | ||
488 | break; | |
489 | } | |
490 | if (x != e) { | |
491 | /* Excluder and event sets have no common elements */ | |
492 | WARN("Event %s: %.*s does not exclude any events from %s", | |
493 | event_name, | |
494 | excluder_length, | |
495 | next_excluder, | |
496 | event_name); | |
497 | break; | |
498 | } | |
499 | excluder_ptr++; | |
500 | event_ptr++; | |
501 | } | |
502 | /* next excluder */ | |
503 | next_excluder += excluder_length; | |
504 | if (*next_excluder == ',') { | |
505 | next_excluder++; | |
506 | } | |
507 | } | |
508 | goto end; | |
509 | error: | |
510 | while (exclusion_count--) { | |
511 | free(exclusion_list[exclusion_count]); | |
512 | } | |
513 | if (exclusion_list != NULL) { | |
514 | free(exclusion_list); | |
515 | } | |
516 | exclusion_list = NULL; | |
517 | exclusion_count = 0; | |
518 | ret = CMD_ERROR; | |
519 | end: | |
520 | *exclusion_count_ptr = exclusion_count; | |
521 | *exclusion_list_ptr = exclusion_list; | |
522 | return ret; | |
523 | } | |
f3ed775e | 524 | /* |
6181537c | 525 | * Enabling event using the lttng API. |
f3ed775e | 526 | */ |
cd80958d | 527 | static int enable_events(char *session_name) |
f3ed775e | 528 | { |
85076754 | 529 | int ret = CMD_SUCCESS, warn = 0; |
b73d0b29 | 530 | char *event_name, *channel_name = NULL; |
f3ed775e | 531 | struct lttng_event ev; |
7d29a247 | 532 | struct lttng_domain dom; |
7ed70bc9 JI |
533 | int exclusion_count = 0; |
534 | char **exclusion_list = NULL; | |
f3ed775e | 535 | |
441c16a7 MD |
536 | memset(&ev, 0, sizeof(ev)); |
537 | memset(&dom, 0, sizeof(dom)); | |
538 | ||
53a80697 MD |
539 | if (opt_kernel) { |
540 | if (opt_filter) { | |
541 | ERR("Filter not implement for kernel tracing yet"); | |
542 | ret = CMD_ERROR; | |
543 | goto error; | |
544 | } | |
67b58630 JG |
545 | if (opt_loglevel) { |
546 | WARN("Kernel loglevels are not supported."); | |
547 | } | |
53a80697 MD |
548 | } |
549 | ||
7d29a247 DG |
550 | /* Create lttng domain */ |
551 | if (opt_kernel) { | |
552 | dom.type = LTTNG_DOMAIN_KERNEL; | |
7972aab2 | 553 | dom.buf_type = LTTNG_BUFFER_GLOBAL; |
d78d6610 | 554 | } else if (opt_userspace) { |
2bdd86d4 | 555 | dom.type = LTTNG_DOMAIN_UST; |
7972aab2 | 556 | /* Default. */ |
8692d4e5 | 557 | dom.buf_type = LTTNG_BUFFER_PER_UID; |
b9dfb167 DG |
558 | } else if (opt_jul) { |
559 | dom.type = LTTNG_DOMAIN_JUL; | |
560 | /* Default. */ | |
561 | dom.buf_type = LTTNG_BUFFER_PER_UID; | |
6181537c | 562 | } else { |
b9dfb167 | 563 | print_missing_domain(); |
d16c1a4c | 564 | ret = CMD_ERROR; |
6181537c | 565 | goto error; |
2bdd86d4 | 566 | } |
7d29a247 | 567 | |
d5dd17fd JI |
568 | if (opt_kernel && opt_exclude) { |
569 | ERR("Event name exclusions are not yet implemented for kernel events"); | |
570 | ret = CMD_ERROR; | |
571 | goto error; | |
572 | } | |
573 | ||
85076754 | 574 | channel_name = opt_channel_name; |
ae856491 | 575 | |
cd80958d DG |
576 | handle = lttng_create_handle(session_name, &dom); |
577 | if (handle == NULL) { | |
578 | ret = -1; | |
579 | goto error; | |
580 | } | |
1aef21b6 | 581 | |
cd80958d | 582 | if (opt_enable_all) { |
8c9ae521 | 583 | /* Default setup for enable all */ |
75e8c5ab MD |
584 | if (opt_kernel) { |
585 | ev.type = opt_event_type; | |
586 | ev.name[0] = '\0'; | |
300b8fd5 MD |
587 | /* kernel loglevels not implemented */ |
588 | ev.loglevel_type = LTTNG_EVENT_LOGLEVEL_ALL; | |
75e8c5ab MD |
589 | } else { |
590 | ev.type = LTTNG_EVENT_TRACEPOINT; | |
591 | strcpy(ev.name, "*"); | |
300b8fd5 MD |
592 | ev.loglevel_type = opt_loglevel_type; |
593 | if (opt_loglevel) { | |
e3a639d0 DG |
594 | assert(opt_userspace || opt_jul); |
595 | if (opt_userspace) { | |
596 | ev.loglevel = loglevel_str_to_value(opt_loglevel); | |
597 | } else if (opt_jul) { | |
598 | ev.loglevel = loglevel_jul_str_to_value(opt_loglevel); | |
599 | } | |
300b8fd5 MD |
600 | if (ev.loglevel == -1) { |
601 | ERR("Unknown loglevel %s", opt_loglevel); | |
2f70b271 | 602 | ret = -LTTNG_ERR_INVALID; |
300b8fd5 MD |
603 | goto error; |
604 | } | |
22e25b71 | 605 | } else { |
e3a639d0 DG |
606 | assert(opt_userspace || opt_jul); |
607 | if (opt_userspace) { | |
608 | ev.loglevel = -1; | |
609 | } else if (opt_jul) { | |
610 | ev.loglevel = LTTNG_LOGLEVEL_JUL_ALL; | |
611 | } | |
300b8fd5 | 612 | } |
75e8c5ab | 613 | } |
8c9ae521 | 614 | |
7ed70bc9 JI |
615 | if (opt_exclude) { |
616 | ret = check_exclusion_subsets("*", opt_exclude, | |
617 | &exclusion_count, &exclusion_list); | |
618 | if (ret == CMD_ERROR) { | |
619 | goto error; | |
620 | } | |
621 | } | |
025faf73 | 622 | if (!opt_filter) { |
7ed70bc9 JI |
623 | ret = lttng_enable_event_with_exclusions(handle, |
624 | &ev, channel_name, | |
625 | NULL, | |
626 | exclusion_count, exclusion_list); | |
025faf73 DG |
627 | if (ret < 0) { |
628 | switch (-ret) { | |
629 | case LTTNG_ERR_KERN_EVENT_EXIST: | |
630 | WARN("Kernel events already enabled (channel %s, session %s)", | |
85076754 | 631 | print_channel_name(channel_name), session_name); |
025faf73 | 632 | break; |
c160a3a4 CB |
633 | case LTTNG_ERR_TRACE_ALREADY_STARTED: |
634 | { | |
635 | const char *msg = "The command tried to enable an event in a new domain for a session that has already been started once."; | |
636 | ERR("Events: %s (channel %s, session %s)", | |
637 | msg, | |
638 | print_channel_name(channel_name), | |
639 | session_name); | |
0a8f0213 | 640 | ret = CMD_ERROR; |
c160a3a4 CB |
641 | break; |
642 | } | |
025faf73 DG |
643 | default: |
644 | ERR("Events: %s (channel %s, session %s)", | |
85076754 MD |
645 | lttng_strerror(ret), |
646 | ret == -LTTNG_ERR_NEED_CHANNEL_NAME | |
647 | ? print_raw_channel_name(channel_name) | |
648 | : print_channel_name(channel_name), | |
649 | session_name); | |
025faf73 DG |
650 | break; |
651 | } | |
652 | goto end; | |
42224349 | 653 | } |
8c9ae521 | 654 | |
025faf73 DG |
655 | switch (opt_event_type) { |
656 | case LTTNG_EVENT_TRACEPOINT: | |
67b58630 | 657 | if (opt_loglevel && dom.type != LTTNG_DOMAIN_KERNEL) { |
9c48cab3 JI |
658 | char *exclusion_string = print_exclusions(exclusion_count, exclusion_list); |
659 | MSG("All %s tracepoints%s are enabled in channel %s for loglevel %s", | |
b9dfb167 | 660 | get_domain_str(dom.type), |
9c48cab3 | 661 | exclusion_string, |
85076754 | 662 | print_channel_name(channel_name), |
025faf73 | 663 | opt_loglevel); |
9c48cab3 | 664 | free(exclusion_string); |
025faf73 | 665 | } else { |
9c48cab3 JI |
666 | char *exclusion_string = print_exclusions(exclusion_count, exclusion_list); |
667 | MSG("All %s tracepoints%s are enabled in channel %s", | |
b9dfb167 | 668 | get_domain_str(dom.type), |
9c48cab3 | 669 | exclusion_string, |
85076754 | 670 | print_channel_name(channel_name)); |
9c48cab3 | 671 | free(exclusion_string); |
025faf73 DG |
672 | } |
673 | break; | |
674 | case LTTNG_EVENT_SYSCALL: | |
675 | if (opt_kernel) { | |
676 | MSG("All kernel system calls are enabled in channel %s", | |
85076754 | 677 | print_channel_name(channel_name)); |
025faf73 DG |
678 | } |
679 | break; | |
680 | case LTTNG_EVENT_ALL: | |
67b58630 | 681 | if (opt_loglevel && dom.type != LTTNG_DOMAIN_KERNEL) { |
9c48cab3 JI |
682 | char *exclusion_string = print_exclusions(exclusion_count, exclusion_list); |
683 | MSG("All %s events%s are enabled in channel %s for loglevel %s", | |
b9dfb167 | 684 | get_domain_str(dom.type), |
9c48cab3 | 685 | exclusion_string, |
85076754 | 686 | print_channel_name(channel_name), |
025faf73 | 687 | opt_loglevel); |
9c48cab3 | 688 | free(exclusion_string); |
025faf73 | 689 | } else { |
9c48cab3 JI |
690 | char *exclusion_string = print_exclusions(exclusion_count, exclusion_list); |
691 | MSG("All %s events%s are enabled in channel %s", | |
b9dfb167 | 692 | get_domain_str(dom.type), |
9c48cab3 | 693 | exclusion_string, |
85076754 | 694 | print_channel_name(channel_name)); |
9c48cab3 | 695 | free(exclusion_string); |
025faf73 DG |
696 | } |
697 | break; | |
698 | default: | |
699 | /* | |
700 | * We should not be here since lttng_enable_event should have | |
701 | * failed on the event type. | |
702 | */ | |
703 | goto error; | |
57064ada | 704 | } |
f3ed775e | 705 | } |
025faf73 | 706 | if (opt_filter) { |
7ed70bc9 JI |
707 | ret = lttng_enable_event_with_exclusions(handle, &ev, channel_name, |
708 | opt_filter, exclusion_count, exclusion_list); | |
16363652 DG |
709 | if (ret < 0) { |
710 | switch (-ret) { | |
711 | case LTTNG_ERR_FILTER_EXIST: | |
85076754 | 712 | WARN("Filter on all events is already enabled" |
16363652 | 713 | " (channel %s, session %s)", |
85076754 | 714 | print_channel_name(channel_name), session_name); |
16363652 | 715 | break; |
c160a3a4 CB |
716 | case LTTNG_ERR_TRACE_ALREADY_STARTED: |
717 | { | |
718 | const char *msg = "The command tried to enable an event in a new domain for a session that has already been started once."; | |
719 | ERR("All events: %s (channel %s, session %s, filter \'%s\')", | |
720 | msg, | |
721 | print_channel_name(channel_name), | |
722 | session_name, opt_filter); | |
0a8f0213 | 723 | ret = CMD_ERROR; |
c160a3a4 CB |
724 | break; |
725 | } | |
16363652 | 726 | default: |
85076754 MD |
727 | ERR("All events: %s (channel %s, session %s, filter \'%s\')", |
728 | lttng_strerror(ret), | |
729 | ret == -LTTNG_ERR_NEED_CHANNEL_NAME | |
730 | ? print_raw_channel_name(channel_name) | |
731 | : print_channel_name(channel_name), | |
732 | session_name, opt_filter); | |
16363652 DG |
733 | break; |
734 | } | |
735 | goto error; | |
736 | } else { | |
737 | MSG("Filter '%s' successfully set", opt_filter); | |
738 | } | |
739 | } | |
8c9ae521 | 740 | goto end; |
f3ed775e DG |
741 | } |
742 | ||
743 | /* Strip event list */ | |
744 | event_name = strtok(opt_event_list, ","); | |
745 | while (event_name != NULL) { | |
6181537c DG |
746 | /* Copy name and type of the event */ |
747 | strncpy(ev.name, event_name, LTTNG_SYMBOL_NAME_LEN); | |
748 | ev.name[LTTNG_SYMBOL_NAME_LEN - 1] = '\0'; | |
749 | ev.type = opt_event_type; | |
750 | ||
f3ed775e DG |
751 | /* Kernel tracer action */ |
752 | if (opt_kernel) { | |
753 | DBG("Enabling kernel event %s for channel %s", | |
85076754 MD |
754 | event_name, |
755 | print_channel_name(channel_name)); | |
f3ed775e DG |
756 | |
757 | switch (opt_event_type) { | |
7a3d1328 MD |
758 | case LTTNG_EVENT_ALL: /* Default behavior is tracepoint */ |
759 | ev.type = LTTNG_EVENT_TRACEPOINT; | |
760 | /* Fall-through */ | |
e6ddca71 | 761 | case LTTNG_EVENT_TRACEPOINT: |
f3ed775e | 762 | break; |
7d29a247 | 763 | case LTTNG_EVENT_PROBE: |
cf0e5467 | 764 | ret = parse_probe_opts(&ev, opt_probe); |
35ae3228 | 765 | if (ret) { |
cf0e5467 | 766 | ERR("Unable to parse probe options"); |
0d63dd19 DG |
767 | ret = 0; |
768 | goto error; | |
769 | } | |
f3ed775e DG |
770 | break; |
771 | case LTTNG_EVENT_FUNCTION: | |
8f0d098b | 772 | ret = parse_probe_opts(&ev, opt_function); |
35ae3228 | 773 | if (ret) { |
8f0d098b MD |
774 | ERR("Unable to parse function probe options"); |
775 | ret = 0; | |
776 | goto error; | |
777 | } | |
778 | break; | |
779 | case LTTNG_EVENT_FUNCTION_ENTRY: | |
6181537c DG |
780 | strncpy(ev.attr.ftrace.symbol_name, opt_function_entry_symbol, |
781 | LTTNG_SYMBOL_NAME_LEN); | |
99497cd0 | 782 | ev.attr.ftrace.symbol_name[LTTNG_SYMBOL_NAME_LEN - 1] = '\0'; |
f3ed775e | 783 | break; |
a54bd42d | 784 | case LTTNG_EVENT_SYSCALL: |
6181537c DG |
785 | MSG("per-syscall selection not supported yet. Use \"-a\" " |
786 | "for all syscalls."); | |
f3ed775e | 787 | default: |
1ab1ea0b | 788 | ret = CMD_UNDEFINED; |
f3ed775e DG |
789 | goto error; |
790 | } | |
0cda4f28 | 791 | |
0cda4f28 | 792 | /* kernel loglevels not implemented */ |
8005f29a | 793 | ev.loglevel_type = LTTNG_EVENT_LOGLEVEL_ALL; |
f3ed775e | 794 | } else if (opt_userspace) { /* User-space tracer action */ |
d78d6610 | 795 | #if 0 |
e14f64a8 DG |
796 | if (opt_cmd_name != NULL || opt_pid) { |
797 | MSG("Only supporting tracing all UST processes (-u) for now."); | |
1ab1ea0b | 798 | ret = CMD_UNDEFINED; |
2bdd86d4 MD |
799 | goto error; |
800 | } | |
d78d6610 | 801 | #endif |
6181537c | 802 | |
300b8fd5 | 803 | DBG("Enabling UST event %s for channel %s, loglevel %s", event_name, |
85076754 | 804 | print_channel_name(channel_name), opt_loglevel ? : "<all>"); |
2bdd86d4 MD |
805 | |
806 | switch (opt_event_type) { | |
807 | case LTTNG_EVENT_ALL: /* Default behavior is tracepoint */ | |
2bdd86d4 MD |
808 | /* Fall-through */ |
809 | case LTTNG_EVENT_TRACEPOINT: | |
e4baff1e MD |
810 | /* Copy name and type of the event */ |
811 | ev.type = LTTNG_EVENT_TRACEPOINT; | |
812 | strncpy(ev.name, event_name, LTTNG_SYMBOL_NAME_LEN); | |
813 | ev.name[LTTNG_SYMBOL_NAME_LEN - 1] = '\0'; | |
2bdd86d4 MD |
814 | break; |
815 | case LTTNG_EVENT_PROBE: | |
816 | case LTTNG_EVENT_FUNCTION: | |
817 | case LTTNG_EVENT_FUNCTION_ENTRY: | |
818 | case LTTNG_EVENT_SYSCALL: | |
819 | default: | |
cc62c0c0 | 820 | ERR("Event type not available for user-space tracing"); |
4ce78777 | 821 | ret = CMD_UNSUPPORTED; |
2bdd86d4 MD |
822 | goto error; |
823 | } | |
0cda4f28 | 824 | |
7ed70bc9 | 825 | if (opt_exclude) { |
d5dd17fd JI |
826 | if (opt_event_type != LTTNG_EVENT_ALL && opt_event_type != LTTNG_EVENT_TRACEPOINT) { |
827 | ERR("Exclusion option can only be used with tracepoint events"); | |
828 | ret = CMD_ERROR; | |
829 | goto error; | |
830 | } | |
7ed70bc9 JI |
831 | /* Free previously allocated items */ |
832 | if (exclusion_list != NULL) { | |
833 | while (exclusion_count--) { | |
834 | free(exclusion_list[exclusion_count]); | |
835 | } | |
836 | free(exclusion_list); | |
837 | exclusion_list = NULL; | |
838 | } | |
839 | /* Check for proper subsets */ | |
840 | ret = check_exclusion_subsets(event_name, opt_exclude, | |
841 | &exclusion_count, &exclusion_list); | |
842 | if (ret == CMD_ERROR) { | |
843 | goto error; | |
844 | } | |
845 | } | |
846 | ||
0cda4f28 | 847 | ev.loglevel_type = opt_loglevel_type; |
ed7f4083 | 848 | if (opt_loglevel) { |
8005f29a MD |
849 | ev.loglevel = loglevel_str_to_value(opt_loglevel); |
850 | if (ev.loglevel == -1) { | |
851 | ERR("Unknown loglevel %s", opt_loglevel); | |
2f70b271 | 852 | ret = -LTTNG_ERR_INVALID; |
8005f29a MD |
853 | goto error; |
854 | } | |
22e25b71 MD |
855 | } else { |
856 | ev.loglevel = -1; | |
ed7f4083 | 857 | } |
b9dfb167 DG |
858 | } else if (opt_jul) { |
859 | if (opt_event_type != LTTNG_EVENT_ALL && | |
860 | opt_event_type != LTTNG_EVENT_TRACEPOINT) { | |
861 | ERR("Event type not supported for JUL domain."); | |
862 | ret = CMD_UNSUPPORTED; | |
863 | goto error; | |
864 | } | |
e3a639d0 DG |
865 | |
866 | ev.loglevel_type = opt_loglevel_type; | |
867 | if (opt_loglevel) { | |
868 | ev.loglevel = loglevel_jul_str_to_value(opt_loglevel); | |
869 | if (ev.loglevel == -1) { | |
870 | ERR("Unknown loglevel %s", opt_loglevel); | |
871 | ret = -LTTNG_ERR_INVALID; | |
872 | goto error; | |
873 | } | |
874 | } else { | |
875 | ev.loglevel = LTTNG_LOGLEVEL_JUL_ALL; | |
876 | } | |
b9dfb167 DG |
877 | ev.type = LTTNG_EVENT_TRACEPOINT; |
878 | strncpy(ev.name, event_name, LTTNG_SYMBOL_NAME_LEN); | |
879 | ev.name[LTTNG_SYMBOL_NAME_LEN - 1] = '\0'; | |
f3ed775e | 880 | } else { |
b9dfb167 | 881 | print_missing_domain(); |
300b8fd5 | 882 | ret = CMD_ERROR; |
f3ed775e DG |
883 | goto error; |
884 | } | |
885 | ||
025faf73 | 886 | if (!opt_filter) { |
9c48cab3 JI |
887 | char *exclusion_string; |
888 | ||
7ed70bc9 JI |
889 | ret = lttng_enable_event_with_exclusions(handle, |
890 | &ev, channel_name, | |
891 | NULL, exclusion_count, exclusion_list); | |
9c48cab3 | 892 | exclusion_string = print_exclusions(exclusion_count, exclusion_list); |
025faf73 DG |
893 | if (ret < 0) { |
894 | /* Turn ret to positive value to handle the positive error code */ | |
895 | switch (-ret) { | |
896 | case LTTNG_ERR_KERN_EVENT_EXIST: | |
9c48cab3 | 897 | WARN("Kernel event %s%s already enabled (channel %s, session %s)", |
85076754 | 898 | event_name, |
9c48cab3 | 899 | exclusion_string, |
85076754 | 900 | print_channel_name(channel_name), session_name); |
0a8f0213 | 901 | warn = 1; |
025faf73 | 902 | break; |
c160a3a4 CB |
903 | case LTTNG_ERR_TRACE_ALREADY_STARTED: |
904 | { | |
905 | const char *msg = "The command tried to enable an event in a new domain for a session that has already been started once."; | |
906 | ERR("Event %s%s: %s (channel %s, session %s)", event_name, | |
907 | exclusion_string, | |
908 | msg, | |
909 | print_channel_name(channel_name), | |
910 | session_name); | |
0a8f0213 | 911 | ret = CMD_ERROR; |
c160a3a4 CB |
912 | break; |
913 | } | |
025faf73 | 914 | default: |
9c48cab3 JI |
915 | ERR("Event %s%s: %s (channel %s, session %s)", event_name, |
916 | exclusion_string, | |
85076754 MD |
917 | lttng_strerror(ret), |
918 | ret == -LTTNG_ERR_NEED_CHANNEL_NAME | |
919 | ? print_raw_channel_name(channel_name) | |
920 | : print_channel_name(channel_name), | |
921 | session_name); | |
0a8f0213 | 922 | warn = 1; |
025faf73 DG |
923 | break; |
924 | } | |
025faf73 | 925 | } else { |
9c48cab3 | 926 | MSG("%s event %s%s created in channel %s", |
b9dfb167 | 927 | get_domain_str(dom.type), event_name, |
9c48cab3 | 928 | exclusion_string, |
85076754 | 929 | print_channel_name(channel_name)); |
42224349 | 930 | } |
9c48cab3 | 931 | free(exclusion_string); |
6181537c | 932 | } |
025faf73 DG |
933 | |
934 | if (opt_filter) { | |
9c48cab3 JI |
935 | char *exclusion_string; |
936 | ||
7ed70bc9 JI |
937 | ret = lttng_enable_event_with_exclusions(handle, &ev, channel_name, |
938 | opt_filter, exclusion_count, exclusion_list); | |
9c48cab3 JI |
939 | exclusion_string = print_exclusions(exclusion_count, exclusion_list); |
940 | ||
53a80697 | 941 | if (ret < 0) { |
7671f53c CB |
942 | switch (-ret) { |
943 | case LTTNG_ERR_FILTER_EXIST: | |
9c48cab3 | 944 | WARN("Filter on event %s%s is already enabled" |
7671f53c | 945 | " (channel %s, session %s)", |
85076754 | 946 | event_name, |
9c48cab3 | 947 | exclusion_string, |
85076754 | 948 | print_channel_name(channel_name), session_name); |
7671f53c | 949 | break; |
c160a3a4 CB |
950 | case LTTNG_ERR_TRACE_ALREADY_STARTED: |
951 | { | |
952 | const char *msg = "The command tried to enable an event in a new domain for a session that has already been started once."; | |
953 | ERR("Event %s%s: %s (channel %s, session %s, filter \'%s\')", ev.name, | |
954 | exclusion_string, | |
955 | msg, | |
956 | print_channel_name(channel_name), | |
957 | session_name, opt_filter); | |
0a8f0213 | 958 | ret = CMD_ERROR; |
c160a3a4 CB |
959 | break; |
960 | } | |
7671f53c | 961 | default: |
9c48cab3 JI |
962 | ERR("Event %s%s: %s (channel %s, session %s, filter \'%s\')", ev.name, |
963 | exclusion_string, | |
85076754 MD |
964 | lttng_strerror(ret), |
965 | ret == -LTTNG_ERR_NEED_CHANNEL_NAME | |
966 | ? print_raw_channel_name(channel_name) | |
967 | : print_channel_name(channel_name), | |
968 | session_name, opt_filter); | |
7671f53c CB |
969 | break; |
970 | } | |
b69793ae | 971 | free(exclusion_string); |
53a80697 | 972 | goto error; |
16363652 | 973 | } else { |
9c48cab3 JI |
974 | MSG("Event %s%s: Filter '%s' successfully set", |
975 | event_name, exclusion_string, | |
976 | opt_filter); | |
53a80697 | 977 | } |
9c48cab3 | 978 | free(exclusion_string); |
53a80697 | 979 | } |
6181537c | 980 | |
f3ed775e DG |
981 | /* Next event */ |
982 | event_name = strtok(NULL, ","); | |
983 | } | |
984 | ||
8c9ae521 | 985 | end: |
f3ed775e | 986 | error: |
ae856491 DG |
987 | if (warn) { |
988 | ret = CMD_WARNING; | |
989 | } | |
cd80958d DG |
990 | lttng_destroy_handle(handle); |
991 | ||
7ed70bc9 JI |
992 | if (exclusion_list != NULL) { |
993 | while (exclusion_count--) { | |
994 | free(exclusion_list[exclusion_count]); | |
995 | } | |
996 | free(exclusion_list); | |
997 | } | |
998 | ||
f3ed775e DG |
999 | return ret; |
1000 | } | |
1001 | ||
1002 | /* | |
6181537c | 1003 | * Add event to trace session |
f3ed775e DG |
1004 | */ |
1005 | int cmd_enable_events(int argc, const char **argv) | |
1006 | { | |
ca1c3607 | 1007 | int opt, ret = CMD_SUCCESS; |
f3ed775e | 1008 | static poptContext pc; |
cd80958d | 1009 | char *session_name = NULL; |
de044b7a | 1010 | int event_type = -1; |
f3ed775e DG |
1011 | |
1012 | pc = poptGetContext(NULL, argc, argv, long_options, 0); | |
1013 | poptReadDefaultConfig(pc, 0); | |
1014 | ||
1015 | /* Default event type */ | |
7a3d1328 | 1016 | opt_event_type = LTTNG_EVENT_ALL; |
f3ed775e DG |
1017 | |
1018 | while ((opt = poptGetNextOpt(pc)) != -1) { | |
1019 | switch (opt) { | |
1020 | case OPT_HELP: | |
ca1c3607 | 1021 | usage(stdout); |
f3ed775e | 1022 | goto end; |
f3ed775e | 1023 | case OPT_TRACEPOINT: |
e6ddca71 | 1024 | opt_event_type = LTTNG_EVENT_TRACEPOINT; |
f3ed775e | 1025 | break; |
cf0e5467 | 1026 | case OPT_PROBE: |
7d29a247 | 1027 | opt_event_type = LTTNG_EVENT_PROBE; |
f3ed775e DG |
1028 | break; |
1029 | case OPT_FUNCTION: | |
1030 | opt_event_type = LTTNG_EVENT_FUNCTION; | |
8f0d098b MD |
1031 | break; |
1032 | case OPT_FUNCTION_ENTRY: | |
1033 | opt_event_type = LTTNG_EVENT_FUNCTION_ENTRY; | |
f3ed775e | 1034 | break; |
a54bd42d MD |
1035 | case OPT_SYSCALL: |
1036 | opt_event_type = LTTNG_EVENT_SYSCALL; | |
0133c199 | 1037 | break; |
eeac7d46 MD |
1038 | case OPT_USERSPACE: |
1039 | opt_userspace = 1; | |
eeac7d46 | 1040 | break; |
0cda4f28 | 1041 | case OPT_LOGLEVEL: |
8005f29a | 1042 | opt_loglevel_type = LTTNG_EVENT_LOGLEVEL_RANGE; |
0cda4f28 MD |
1043 | opt_loglevel = poptGetOptArg(pc); |
1044 | break; | |
1045 | case OPT_LOGLEVEL_ONLY: | |
8005f29a | 1046 | opt_loglevel_type = LTTNG_EVENT_LOGLEVEL_SINGLE; |
0cda4f28 | 1047 | opt_loglevel = poptGetOptArg(pc); |
13dce3b7 | 1048 | break; |
679b4943 SM |
1049 | case OPT_LIST_OPTIONS: |
1050 | list_cmd_options(stdout, long_options); | |
679b4943 | 1051 | goto end; |
53a80697 MD |
1052 | case OPT_FILTER: |
1053 | break; | |
fac3366c JI |
1054 | case OPT_EXCLUDE: |
1055 | break; | |
f3ed775e DG |
1056 | default: |
1057 | usage(stderr); | |
1058 | ret = CMD_UNDEFINED; | |
1059 | goto end; | |
1060 | } | |
de044b7a DG |
1061 | |
1062 | /* Validate event type. Multiple event type are not supported. */ | |
1063 | if (event_type == -1) { | |
1064 | event_type = opt_event_type; | |
1065 | } else { | |
1066 | if (event_type != opt_event_type) { | |
1067 | ERR("Multiple event type not supported."); | |
1068 | ret = CMD_ERROR; | |
1069 | goto end; | |
1070 | } | |
1071 | } | |
f3ed775e DG |
1072 | } |
1073 | ||
1074 | opt_event_list = (char*) poptGetArg(pc); | |
1075 | if (opt_event_list == NULL && opt_enable_all == 0) { | |
1076 | ERR("Missing event name(s).\n"); | |
1077 | usage(stderr); | |
ca1c3607 | 1078 | ret = CMD_ERROR; |
f3ed775e DG |
1079 | goto end; |
1080 | } | |
1081 | ||
cd80958d DG |
1082 | if (!opt_session_name) { |
1083 | session_name = get_session_name(); | |
1084 | if (session_name == NULL) { | |
ca1c3607 | 1085 | ret = CMD_ERROR; |
cd80958d DG |
1086 | goto end; |
1087 | } | |
1088 | } else { | |
1089 | session_name = opt_session_name; | |
1090 | } | |
1091 | ||
1092 | ret = enable_events(session_name); | |
f3ed775e DG |
1093 | |
1094 | end: | |
cd80958d DG |
1095 | if (opt_session_name == NULL) { |
1096 | free(session_name); | |
1097 | } | |
1098 | ||
ca1c3607 | 1099 | poptFreeContext(pc); |
f3ed775e DG |
1100 | return ret; |
1101 | } |