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 | |
c399183f | 30 | #include "../command.h" |
42224349 | 31 | #include <src/common/sessiond-comm/sessiond-comm.h> |
f3ed775e | 32 | |
8ab7c0d9 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"); |
f9e8873b 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"); | |
b2064f54 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 DG |
230 | { |
231 | int ret; | |
8ff0bbd0 | 232 | char s_hex[19]; |
8ab7c0d9 | 233 | #define S_HEX_LEN_SCANF_IS_A_BROKEN_API "18" /* 18 is (19 - 1) (\0 is extra) */ |
0d63dd19 DG |
234 | char name[LTTNG_SYMBOL_NAME_LEN]; |
235 | ||
236 | if (opt == NULL) { | |
237 | ret = -1; | |
8f0d098b | 238 | goto end; |
0d63dd19 DG |
239 | } |
240 | ||
241 | /* Check for symbol+offset */ | |
8ab7c0d9 MD |
242 | ret = sscanf(opt, "%" LTTNG_SYMBOL_NAME_LEN_SCANF_IS_A_BROKEN_API |
243 | "[^'+']+%" S_HEX_LEN_SCANF_IS_A_BROKEN_API "s", name, s_hex); | |
0d63dd19 | 244 | if (ret == 2) { |
7d29a247 | 245 | strncpy(ev->attr.probe.symbol_name, name, LTTNG_SYMBOL_NAME_LEN); |
99497cd0 | 246 | ev->attr.probe.symbol_name[LTTNG_SYMBOL_NAME_LEN - 1] = '\0'; |
cf0e5467 | 247 | DBG("probe symbol %s", ev->attr.probe.symbol_name); |
9d035200 | 248 | if (*s_hex == '\0') { |
8ff0bbd0 | 249 | ERR("Invalid probe offset %s", s_hex); |
0d63dd19 | 250 | ret = -1; |
8f0d098b | 251 | goto end; |
0d63dd19 | 252 | } |
8ff0bbd0 | 253 | ev->attr.probe.offset = strtoul(s_hex, NULL, 0); |
cf0e5467 | 254 | DBG("probe offset %" PRIu64, ev->attr.probe.offset); |
3000dc78 | 255 | ev->attr.probe.addr = 0; |
8f0d098b MD |
256 | goto end; |
257 | } | |
258 | ||
259 | /* Check for symbol */ | |
260 | if (isalpha(name[0])) { | |
8ab7c0d9 MD |
261 | ret = sscanf(opt, "%" LTTNG_SYMBOL_NAME_LEN_SCANF_IS_A_BROKEN_API "s", |
262 | name); | |
8f0d098b MD |
263 | if (ret == 1) { |
264 | strncpy(ev->attr.probe.symbol_name, name, LTTNG_SYMBOL_NAME_LEN); | |
99497cd0 | 265 | ev->attr.probe.symbol_name[LTTNG_SYMBOL_NAME_LEN - 1] = '\0'; |
8f0d098b MD |
266 | DBG("probe symbol %s", ev->attr.probe.symbol_name); |
267 | ev->attr.probe.offset = 0; | |
268 | DBG("probe offset %" PRIu64, ev->attr.probe.offset); | |
269 | ev->attr.probe.addr = 0; | |
270 | goto end; | |
271 | } | |
0d63dd19 DG |
272 | } |
273 | ||
274 | /* Check for address */ | |
8ab7c0d9 | 275 | ret = sscanf(opt, "%" S_HEX_LEN_SCANF_IS_A_BROKEN_API "s", s_hex); |
0d63dd19 | 276 | if (ret > 0) { |
9d035200 | 277 | if (*s_hex == '\0') { |
8ff0bbd0 | 278 | ERR("Invalid probe address %s", s_hex); |
0d63dd19 | 279 | ret = -1; |
8f0d098b | 280 | goto end; |
0d63dd19 | 281 | } |
8ff0bbd0 | 282 | ev->attr.probe.addr = strtoul(s_hex, NULL, 0); |
cf0e5467 | 283 | DBG("probe addr %" PRIu64, ev->attr.probe.addr); |
3000dc78 DG |
284 | ev->attr.probe.offset = 0; |
285 | memset(ev->attr.probe.symbol_name, 0, LTTNG_SYMBOL_NAME_LEN); | |
8f0d098b | 286 | goto end; |
0d63dd19 DG |
287 | } |
288 | ||
289 | /* No match */ | |
290 | ret = -1; | |
291 | ||
8f0d098b | 292 | end: |
0d63dd19 DG |
293 | return ret; |
294 | } | |
295 | ||
b2064f54 DG |
296 | /* |
297 | * Maps JUL loglevel from string to value | |
298 | */ | |
299 | static int loglevel_jul_str_to_value(const char *inputstr) | |
300 | { | |
301 | int i = 0; | |
302 | char str[LTTNG_SYMBOL_NAME_LEN]; | |
303 | ||
304 | /* | |
305 | * Loop up to LTTNG_SYMBOL_NAME_LEN minus one because the NULL bytes is | |
306 | * added at the end of the loop so a the upper bound we avoid the overflow. | |
307 | */ | |
308 | while (i < (LTTNG_SYMBOL_NAME_LEN - 1) && inputstr[i] != '\0') { | |
309 | str[i] = toupper(inputstr[i]); | |
310 | i++; | |
311 | } | |
312 | str[i] = '\0'; | |
313 | ||
314 | if (!strcmp(str, "JUL_OFF") || !strcmp(str, "OFF")) { | |
315 | return LTTNG_LOGLEVEL_JUL_OFF; | |
316 | } else if (!strcmp(str, "JUL_SEVERE") || !strcmp(str, "SEVERE")) { | |
317 | return LTTNG_LOGLEVEL_JUL_SEVERE; | |
318 | } else if (!strcmp(str, "JUL_WARNING") || !strcmp(str, "WARNING")) { | |
319 | return LTTNG_LOGLEVEL_JUL_WARNING; | |
320 | } else if (!strcmp(str, "JUL_INFO") || !strcmp(str, "INFO")) { | |
321 | return LTTNG_LOGLEVEL_JUL_INFO; | |
322 | } else if (!strcmp(str, "JUL_CONFIG") || !strcmp(str, "CONFIG")) { | |
323 | return LTTNG_LOGLEVEL_JUL_CONFIG; | |
324 | } else if (!strcmp(str, "JUL_FINE") || !strcmp(str, "FINE")) { | |
325 | return LTTNG_LOGLEVEL_JUL_FINE; | |
326 | } else if (!strcmp(str, "JUL_FINER") || !strcmp(str, "FINER")) { | |
327 | return LTTNG_LOGLEVEL_JUL_FINER; | |
328 | } else if (!strcmp(str, "JUL_FINEST") || !strcmp(str, "FINEST")) { | |
329 | return LTTNG_LOGLEVEL_JUL_FINEST; | |
330 | } else if (!strcmp(str, "JUL_ALL") || !strcmp(str, "ALL")) { | |
331 | return LTTNG_LOGLEVEL_JUL_ALL; | |
332 | } else { | |
333 | return -1; | |
334 | } | |
335 | } | |
336 | ||
8005f29a | 337 | /* |
0c8477c8 | 338 | * Maps loglevel from string to value |
8005f29a MD |
339 | */ |
340 | static | |
46839cc2 | 341 | int loglevel_str_to_value(const char *inputstr) |
8005f29a | 342 | { |
46839cc2 MD |
343 | int i = 0; |
344 | char str[LTTNG_SYMBOL_NAME_LEN]; | |
345 | ||
e051e07c DG |
346 | /* |
347 | * Loop up to LTTNG_SYMBOL_NAME_LEN minus one because the NULL bytes is | |
348 | * added at the end of the loop so a the upper bound we avoid the overflow. | |
349 | */ | |
350 | while (i < (LTTNG_SYMBOL_NAME_LEN - 1) && inputstr[i] != '\0') { | |
46839cc2 MD |
351 | str[i] = toupper(inputstr[i]); |
352 | i++; | |
353 | } | |
354 | str[i] = '\0'; | |
355 | if (!strcmp(str, "TRACE_EMERG") || !strcmp(str, "EMERG")) { | |
356 | return LTTNG_LOGLEVEL_EMERG; | |
357 | } else if (!strcmp(str, "TRACE_ALERT") || !strcmp(str, "ALERT")) { | |
358 | return LTTNG_LOGLEVEL_ALERT; | |
359 | } else if (!strcmp(str, "TRACE_CRIT") || !strcmp(str, "CRIT")) { | |
360 | return LTTNG_LOGLEVEL_CRIT; | |
361 | } else if (!strcmp(str, "TRACE_ERR") || !strcmp(str, "ERR")) { | |
362 | return LTTNG_LOGLEVEL_ERR; | |
363 | } else if (!strcmp(str, "TRACE_WARNING") || !strcmp(str, "WARNING")) { | |
364 | return LTTNG_LOGLEVEL_WARNING; | |
365 | } else if (!strcmp(str, "TRACE_NOTICE") || !strcmp(str, "NOTICE")) { | |
366 | return LTTNG_LOGLEVEL_NOTICE; | |
367 | } else if (!strcmp(str, "TRACE_INFO") || !strcmp(str, "INFO")) { | |
368 | return LTTNG_LOGLEVEL_INFO; | |
369 | } else if (!strcmp(str, "TRACE_DEBUG_SYSTEM") || !strcmp(str, "DEBUG_SYSTEM") || !strcmp(str, "SYSTEM")) { | |
370 | return LTTNG_LOGLEVEL_DEBUG_SYSTEM; | |
371 | } else if (!strcmp(str, "TRACE_DEBUG_PROGRAM") || !strcmp(str, "DEBUG_PROGRAM") || !strcmp(str, "PROGRAM")) { | |
372 | return LTTNG_LOGLEVEL_DEBUG_PROGRAM; | |
373 | } else if (!strcmp(str, "TRACE_DEBUG_PROCESS") || !strcmp(str, "DEBUG_PROCESS") || !strcmp(str, "PROCESS")) { | |
374 | return LTTNG_LOGLEVEL_DEBUG_PROCESS; | |
375 | } else if (!strcmp(str, "TRACE_DEBUG_MODULE") || !strcmp(str, "DEBUG_MODULE") || !strcmp(str, "MODULE")) { | |
376 | return LTTNG_LOGLEVEL_DEBUG_MODULE; | |
377 | } else if (!strcmp(str, "TRACE_DEBUG_UNIT") || !strcmp(str, "DEBUG_UNIT") || !strcmp(str, "UNIT")) { | |
378 | return LTTNG_LOGLEVEL_DEBUG_UNIT; | |
379 | } else if (!strcmp(str, "TRACE_DEBUG_FUNCTION") || !strcmp(str, "DEBUG_FUNCTION") || !strcmp(str, "FUNCTION")) { | |
380 | return LTTNG_LOGLEVEL_DEBUG_FUNCTION; | |
381 | } else if (!strcmp(str, "TRACE_DEBUG_LINE") || !strcmp(str, "DEBUG_LINE") || !strcmp(str, "LINE")) { | |
382 | return LTTNG_LOGLEVEL_DEBUG_LINE; | |
383 | } else if (!strcmp(str, "TRACE_DEBUG") || !strcmp(str, "DEBUG")) { | |
384 | return LTTNG_LOGLEVEL_DEBUG; | |
8005f29a MD |
385 | } else { |
386 | return -1; | |
387 | } | |
388 | } | |
389 | ||
85076754 MD |
390 | static |
391 | const char *print_channel_name(const char *name) | |
392 | { | |
393 | return name ? : DEFAULT_CHANNEL_NAME; | |
394 | } | |
395 | ||
396 | static | |
397 | const char *print_raw_channel_name(const char *name) | |
398 | { | |
399 | return name ? : "<default>"; | |
400 | } | |
401 | ||
9c48cab3 JI |
402 | /* |
403 | * Return allocated string for pretty-printing exclusion names. | |
404 | */ | |
405 | static | |
406 | char *print_exclusions(int count, char **names) | |
407 | { | |
408 | int length = 0; | |
409 | int i; | |
410 | const char *preamble = " excluding "; | |
411 | char *ret; | |
412 | ||
413 | if (count == 0) { | |
414 | return strdup(""); | |
415 | } | |
416 | ||
417 | /* calculate total required length */ | |
418 | for (i = 0; i < count; i++) { | |
419 | length += strlen(names[i]) + 1; | |
420 | } | |
421 | ||
422 | /* add length of preamble + one for NUL - one for last (missing) comma */ | |
423 | length += strlen(preamble); | |
424 | ret = malloc(length); | |
425 | strncpy(ret, preamble, length); | |
426 | for (i = 0; i < count; i++) { | |
427 | strcat(ret, names[i]); | |
428 | if (i != count - 1) { | |
429 | strcat(ret, ","); | |
430 | } | |
431 | } | |
432 | return ret; | |
433 | } | |
434 | ||
748bde76 JI |
435 | /* |
436 | * Compare list of exclusions against an event name. | |
437 | * Return a list of legal exclusion names. | |
438 | * Produce an error or a warning about others (depending on the situation) | |
439 | */ | |
440 | static | |
441 | int check_exclusion_subsets(const char *event_name, | |
442 | const char *exclusions, | |
443 | int *exclusion_count_ptr, | |
444 | char ***exclusion_list_ptr) | |
445 | { | |
446 | const char *excluder_ptr; | |
447 | const char *event_ptr; | |
448 | const char *next_excluder; | |
449 | int excluder_length; | |
450 | int exclusion_count = 0; | |
451 | char **exclusion_list = NULL; | |
452 | int ret = CMD_SUCCESS; | |
453 | ||
454 | if (event_name[strlen(event_name) - 1] != '*') { | |
455 | ERR("Event %s: Excluders can only be used with wildcarded events", event_name); | |
456 | goto error; | |
457 | } | |
458 | ||
459 | next_excluder = exclusions; | |
460 | while (*next_excluder != 0) { | |
461 | event_ptr = event_name; | |
462 | excluder_ptr = next_excluder; | |
463 | excluder_length = strcspn(next_excluder, ","); | |
464 | ||
465 | /* Scan both the excluder and the event letter by letter */ | |
466 | while (1) { | |
467 | char e, x; | |
468 | ||
469 | e = *event_ptr; | |
470 | x = *excluder_ptr; | |
471 | ||
472 | if (x == '*') { | |
473 | /* Event is a subset of the excluder */ | |
474 | ERR("Event %s: %.*s excludes all events from %s", | |
475 | event_name, | |
476 | excluder_length, | |
477 | next_excluder, | |
478 | event_name); | |
479 | goto error; | |
480 | } | |
481 | if (e == '*') { | |
482 | /* Excluder is a proper subset of event */ | |
483 | exclusion_count++; | |
484 | exclusion_list = realloc(exclusion_list, sizeof(char **) * exclusion_count); | |
485 | exclusion_list[exclusion_count - 1] = strndup(next_excluder, excluder_length); | |
486 | ||
487 | break; | |
488 | } | |
489 | if (x != e) { | |
490 | /* Excluder and event sets have no common elements */ | |
491 | WARN("Event %s: %.*s does not exclude any events from %s", | |
492 | event_name, | |
493 | excluder_length, | |
494 | next_excluder, | |
495 | event_name); | |
496 | break; | |
497 | } | |
498 | excluder_ptr++; | |
499 | event_ptr++; | |
500 | } | |
501 | /* next excluder */ | |
502 | next_excluder += excluder_length; | |
503 | if (*next_excluder == ',') { | |
504 | next_excluder++; | |
505 | } | |
506 | } | |
507 | goto end; | |
508 | error: | |
509 | while (exclusion_count--) { | |
510 | free(exclusion_list[exclusion_count]); | |
511 | } | |
512 | if (exclusion_list != NULL) { | |
513 | free(exclusion_list); | |
514 | } | |
515 | exclusion_list = NULL; | |
516 | exclusion_count = 0; | |
517 | ret = CMD_ERROR; | |
518 | end: | |
519 | *exclusion_count_ptr = exclusion_count; | |
520 | *exclusion_list_ptr = exclusion_list; | |
521 | return ret; | |
522 | } | |
f3ed775e | 523 | /* |
6181537c | 524 | * Enabling event using the lttng API. |
f3ed775e | 525 | */ |
cd80958d | 526 | static int enable_events(char *session_name) |
f3ed775e | 527 | { |
85076754 | 528 | int ret = CMD_SUCCESS, warn = 0; |
b73d0b29 | 529 | char *event_name, *channel_name = NULL; |
f3ed775e | 530 | struct lttng_event ev; |
7d29a247 | 531 | struct lttng_domain dom; |
7ed70bc9 JI |
532 | int exclusion_count = 0; |
533 | char **exclusion_list = NULL; | |
f3ed775e | 534 | |
441c16a7 MD |
535 | memset(&ev, 0, sizeof(ev)); |
536 | memset(&dom, 0, sizeof(dom)); | |
537 | ||
53a80697 MD |
538 | if (opt_kernel) { |
539 | if (opt_filter) { | |
540 | ERR("Filter not implement for kernel tracing yet"); | |
541 | ret = CMD_ERROR; | |
542 | goto error; | |
543 | } | |
67b58630 JG |
544 | if (opt_loglevel) { |
545 | WARN("Kernel loglevels are not supported."); | |
546 | } | |
53a80697 MD |
547 | } |
548 | ||
7d29a247 DG |
549 | /* Create lttng domain */ |
550 | if (opt_kernel) { | |
551 | dom.type = LTTNG_DOMAIN_KERNEL; | |
7972aab2 | 552 | dom.buf_type = LTTNG_BUFFER_GLOBAL; |
d78d6610 | 553 | } else if (opt_userspace) { |
2bdd86d4 | 554 | dom.type = LTTNG_DOMAIN_UST; |
7972aab2 | 555 | /* Default. */ |
8692d4e5 | 556 | dom.buf_type = LTTNG_BUFFER_PER_UID; |
b9dfb167 DG |
557 | } else if (opt_jul) { |
558 | dom.type = LTTNG_DOMAIN_JUL; | |
559 | /* Default. */ | |
560 | dom.buf_type = LTTNG_BUFFER_PER_UID; | |
6181537c | 561 | } else { |
b9dfb167 | 562 | print_missing_domain(); |
d16c1a4c | 563 | ret = CMD_ERROR; |
6181537c | 564 | goto error; |
2bdd86d4 | 565 | } |
7d29a247 | 566 | |
d5dd17fd JI |
567 | if (opt_kernel && opt_exclude) { |
568 | ERR("Event name exclusions are not yet implemented for kernel events"); | |
569 | ret = CMD_ERROR; | |
570 | goto error; | |
571 | } | |
572 | ||
85076754 | 573 | channel_name = opt_channel_name; |
ae856491 | 574 | |
cd80958d DG |
575 | handle = lttng_create_handle(session_name, &dom); |
576 | if (handle == NULL) { | |
577 | ret = -1; | |
578 | goto error; | |
579 | } | |
1aef21b6 | 580 | |
cd80958d | 581 | if (opt_enable_all) { |
8c9ae521 | 582 | /* Default setup for enable all */ |
75e8c5ab MD |
583 | if (opt_kernel) { |
584 | ev.type = opt_event_type; | |
585 | ev.name[0] = '\0'; | |
300b8fd5 MD |
586 | /* kernel loglevels not implemented */ |
587 | ev.loglevel_type = LTTNG_EVENT_LOGLEVEL_ALL; | |
75e8c5ab MD |
588 | } else { |
589 | ev.type = LTTNG_EVENT_TRACEPOINT; | |
590 | strcpy(ev.name, "*"); | |
300b8fd5 MD |
591 | ev.loglevel_type = opt_loglevel_type; |
592 | if (opt_loglevel) { | |
b2064f54 DG |
593 | assert(opt_userspace || opt_jul); |
594 | if (opt_userspace) { | |
595 | ev.loglevel = loglevel_str_to_value(opt_loglevel); | |
596 | } else if (opt_jul) { | |
597 | ev.loglevel = loglevel_jul_str_to_value(opt_loglevel); | |
598 | } | |
300b8fd5 MD |
599 | if (ev.loglevel == -1) { |
600 | ERR("Unknown loglevel %s", opt_loglevel); | |
2f70b271 | 601 | ret = -LTTNG_ERR_INVALID; |
300b8fd5 MD |
602 | goto error; |
603 | } | |
22e25b71 | 604 | } else { |
b2064f54 DG |
605 | assert(opt_userspace || opt_jul); |
606 | if (opt_userspace) { | |
607 | ev.loglevel = -1; | |
608 | } else if (opt_jul) { | |
609 | ev.loglevel = LTTNG_LOGLEVEL_JUL_ALL; | |
610 | } | |
300b8fd5 | 611 | } |
75e8c5ab | 612 | } |
8c9ae521 | 613 | |
7ed70bc9 JI |
614 | if (opt_exclude) { |
615 | ret = check_exclusion_subsets("*", opt_exclude, | |
616 | &exclusion_count, &exclusion_list); | |
617 | if (ret == CMD_ERROR) { | |
618 | goto error; | |
619 | } | |
620 | } | |
025faf73 | 621 | if (!opt_filter) { |
7ed70bc9 JI |
622 | ret = lttng_enable_event_with_exclusions(handle, |
623 | &ev, channel_name, | |
624 | NULL, | |
625 | exclusion_count, exclusion_list); | |
025faf73 DG |
626 | if (ret < 0) { |
627 | switch (-ret) { | |
628 | case LTTNG_ERR_KERN_EVENT_EXIST: | |
629 | WARN("Kernel events already enabled (channel %s, session %s)", | |
85076754 | 630 | print_channel_name(channel_name), session_name); |
025faf73 DG |
631 | break; |
632 | default: | |
633 | ERR("Events: %s (channel %s, session %s)", | |
85076754 MD |
634 | lttng_strerror(ret), |
635 | ret == -LTTNG_ERR_NEED_CHANNEL_NAME | |
636 | ? print_raw_channel_name(channel_name) | |
637 | : print_channel_name(channel_name), | |
638 | session_name); | |
025faf73 DG |
639 | break; |
640 | } | |
641 | goto end; | |
42224349 | 642 | } |
8c9ae521 | 643 | |
025faf73 DG |
644 | switch (opt_event_type) { |
645 | case LTTNG_EVENT_TRACEPOINT: | |
67b58630 | 646 | if (opt_loglevel && dom.type != LTTNG_DOMAIN_KERNEL) { |
9c48cab3 JI |
647 | char *exclusion_string = print_exclusions(exclusion_count, exclusion_list); |
648 | MSG("All %s tracepoints%s are enabled in channel %s for loglevel %s", | |
b9dfb167 | 649 | get_domain_str(dom.type), |
9c48cab3 | 650 | exclusion_string, |
85076754 | 651 | print_channel_name(channel_name), |
025faf73 | 652 | opt_loglevel); |
9c48cab3 | 653 | free(exclusion_string); |
025faf73 | 654 | } else { |
9c48cab3 JI |
655 | char *exclusion_string = print_exclusions(exclusion_count, exclusion_list); |
656 | MSG("All %s tracepoints%s are enabled in channel %s", | |
b9dfb167 | 657 | get_domain_str(dom.type), |
9c48cab3 | 658 | exclusion_string, |
85076754 | 659 | print_channel_name(channel_name)); |
9c48cab3 | 660 | free(exclusion_string); |
025faf73 DG |
661 | } |
662 | break; | |
663 | case LTTNG_EVENT_SYSCALL: | |
664 | if (opt_kernel) { | |
665 | MSG("All kernel system calls are enabled in channel %s", | |
85076754 | 666 | print_channel_name(channel_name)); |
025faf73 DG |
667 | } |
668 | break; | |
669 | case LTTNG_EVENT_ALL: | |
67b58630 | 670 | if (opt_loglevel && dom.type != LTTNG_DOMAIN_KERNEL) { |
9c48cab3 JI |
671 | char *exclusion_string = print_exclusions(exclusion_count, exclusion_list); |
672 | MSG("All %s events%s are enabled in channel %s for loglevel %s", | |
b9dfb167 | 673 | get_domain_str(dom.type), |
9c48cab3 | 674 | exclusion_string, |
85076754 | 675 | print_channel_name(channel_name), |
025faf73 | 676 | opt_loglevel); |
9c48cab3 | 677 | free(exclusion_string); |
025faf73 | 678 | } else { |
9c48cab3 JI |
679 | char *exclusion_string = print_exclusions(exclusion_count, exclusion_list); |
680 | MSG("All %s events%s are enabled in channel %s", | |
b9dfb167 | 681 | get_domain_str(dom.type), |
9c48cab3 | 682 | exclusion_string, |
85076754 | 683 | print_channel_name(channel_name)); |
9c48cab3 | 684 | free(exclusion_string); |
025faf73 DG |
685 | } |
686 | break; | |
687 | default: | |
688 | /* | |
689 | * We should not be here since lttng_enable_event should have | |
690 | * failed on the event type. | |
691 | */ | |
692 | goto error; | |
57064ada | 693 | } |
f3ed775e | 694 | } |
025faf73 | 695 | if (opt_filter) { |
7ed70bc9 JI |
696 | ret = lttng_enable_event_with_exclusions(handle, &ev, channel_name, |
697 | opt_filter, exclusion_count, exclusion_list); | |
16363652 DG |
698 | if (ret < 0) { |
699 | switch (-ret) { | |
700 | case LTTNG_ERR_FILTER_EXIST: | |
85076754 | 701 | WARN("Filter on all events is already enabled" |
16363652 | 702 | " (channel %s, session %s)", |
85076754 | 703 | print_channel_name(channel_name), session_name); |
16363652 DG |
704 | break; |
705 | default: | |
85076754 MD |
706 | ERR("All events: %s (channel %s, session %s, filter \'%s\')", |
707 | lttng_strerror(ret), | |
708 | ret == -LTTNG_ERR_NEED_CHANNEL_NAME | |
709 | ? print_raw_channel_name(channel_name) | |
710 | : print_channel_name(channel_name), | |
711 | session_name, opt_filter); | |
16363652 DG |
712 | break; |
713 | } | |
714 | goto error; | |
715 | } else { | |
716 | MSG("Filter '%s' successfully set", opt_filter); | |
717 | } | |
718 | } | |
8c9ae521 | 719 | goto end; |
f3ed775e DG |
720 | } |
721 | ||
722 | /* Strip event list */ | |
723 | event_name = strtok(opt_event_list, ","); | |
724 | while (event_name != NULL) { | |
6181537c DG |
725 | /* Copy name and type of the event */ |
726 | strncpy(ev.name, event_name, LTTNG_SYMBOL_NAME_LEN); | |
727 | ev.name[LTTNG_SYMBOL_NAME_LEN - 1] = '\0'; | |
728 | ev.type = opt_event_type; | |
729 | ||
f3ed775e DG |
730 | /* Kernel tracer action */ |
731 | if (opt_kernel) { | |
732 | DBG("Enabling kernel event %s for channel %s", | |
85076754 MD |
733 | event_name, |
734 | print_channel_name(channel_name)); | |
f3ed775e DG |
735 | |
736 | switch (opt_event_type) { | |
7a3d1328 MD |
737 | case LTTNG_EVENT_ALL: /* Default behavior is tracepoint */ |
738 | ev.type = LTTNG_EVENT_TRACEPOINT; | |
739 | /* Fall-through */ | |
e6ddca71 | 740 | case LTTNG_EVENT_TRACEPOINT: |
f3ed775e | 741 | break; |
7d29a247 | 742 | case LTTNG_EVENT_PROBE: |
cf0e5467 | 743 | ret = parse_probe_opts(&ev, opt_probe); |
0d63dd19 | 744 | if (ret < 0) { |
cf0e5467 | 745 | ERR("Unable to parse probe options"); |
0d63dd19 DG |
746 | ret = 0; |
747 | goto error; | |
748 | } | |
f3ed775e DG |
749 | break; |
750 | case LTTNG_EVENT_FUNCTION: | |
8f0d098b MD |
751 | ret = parse_probe_opts(&ev, opt_function); |
752 | if (ret < 0) { | |
753 | ERR("Unable to parse function probe options"); | |
754 | ret = 0; | |
755 | goto error; | |
756 | } | |
757 | break; | |
758 | case LTTNG_EVENT_FUNCTION_ENTRY: | |
6181537c DG |
759 | strncpy(ev.attr.ftrace.symbol_name, opt_function_entry_symbol, |
760 | LTTNG_SYMBOL_NAME_LEN); | |
99497cd0 | 761 | ev.attr.ftrace.symbol_name[LTTNG_SYMBOL_NAME_LEN - 1] = '\0'; |
f3ed775e | 762 | break; |
a54bd42d | 763 | case LTTNG_EVENT_SYSCALL: |
6181537c DG |
764 | MSG("per-syscall selection not supported yet. Use \"-a\" " |
765 | "for all syscalls."); | |
f3ed775e | 766 | default: |
1ab1ea0b | 767 | ret = CMD_UNDEFINED; |
f3ed775e DG |
768 | goto error; |
769 | } | |
0cda4f28 | 770 | |
0cda4f28 | 771 | /* kernel loglevels not implemented */ |
8005f29a | 772 | ev.loglevel_type = LTTNG_EVENT_LOGLEVEL_ALL; |
f3ed775e | 773 | } else if (opt_userspace) { /* User-space tracer action */ |
d78d6610 | 774 | #if 0 |
e14f64a8 DG |
775 | if (opt_cmd_name != NULL || opt_pid) { |
776 | MSG("Only supporting tracing all UST processes (-u) for now."); | |
1ab1ea0b | 777 | ret = CMD_UNDEFINED; |
2bdd86d4 MD |
778 | goto error; |
779 | } | |
d78d6610 | 780 | #endif |
6181537c | 781 | |
300b8fd5 | 782 | DBG("Enabling UST event %s for channel %s, loglevel %s", event_name, |
85076754 | 783 | print_channel_name(channel_name), opt_loglevel ? : "<all>"); |
2bdd86d4 MD |
784 | |
785 | switch (opt_event_type) { | |
786 | case LTTNG_EVENT_ALL: /* Default behavior is tracepoint */ | |
2bdd86d4 MD |
787 | /* Fall-through */ |
788 | case LTTNG_EVENT_TRACEPOINT: | |
e4baff1e MD |
789 | /* Copy name and type of the event */ |
790 | ev.type = LTTNG_EVENT_TRACEPOINT; | |
791 | strncpy(ev.name, event_name, LTTNG_SYMBOL_NAME_LEN); | |
792 | ev.name[LTTNG_SYMBOL_NAME_LEN - 1] = '\0'; | |
2bdd86d4 MD |
793 | break; |
794 | case LTTNG_EVENT_PROBE: | |
795 | case LTTNG_EVENT_FUNCTION: | |
796 | case LTTNG_EVENT_FUNCTION_ENTRY: | |
797 | case LTTNG_EVENT_SYSCALL: | |
798 | default: | |
cc62c0c0 | 799 | ERR("Event type not available for user-space tracing"); |
4ce78777 | 800 | ret = CMD_UNSUPPORTED; |
2bdd86d4 MD |
801 | goto error; |
802 | } | |
0cda4f28 | 803 | |
7ed70bc9 | 804 | if (opt_exclude) { |
d5dd17fd JI |
805 | if (opt_event_type != LTTNG_EVENT_ALL && opt_event_type != LTTNG_EVENT_TRACEPOINT) { |
806 | ERR("Exclusion option can only be used with tracepoint events"); | |
807 | ret = CMD_ERROR; | |
808 | goto error; | |
809 | } | |
7ed70bc9 JI |
810 | /* Free previously allocated items */ |
811 | if (exclusion_list != NULL) { | |
812 | while (exclusion_count--) { | |
813 | free(exclusion_list[exclusion_count]); | |
814 | } | |
815 | free(exclusion_list); | |
816 | exclusion_list = NULL; | |
817 | } | |
818 | /* Check for proper subsets */ | |
819 | ret = check_exclusion_subsets(event_name, opt_exclude, | |
820 | &exclusion_count, &exclusion_list); | |
821 | if (ret == CMD_ERROR) { | |
822 | goto error; | |
823 | } | |
824 | } | |
825 | ||
0cda4f28 | 826 | ev.loglevel_type = opt_loglevel_type; |
ed7f4083 | 827 | if (opt_loglevel) { |
8005f29a MD |
828 | ev.loglevel = loglevel_str_to_value(opt_loglevel); |
829 | if (ev.loglevel == -1) { | |
830 | ERR("Unknown loglevel %s", opt_loglevel); | |
2f70b271 | 831 | ret = -LTTNG_ERR_INVALID; |
8005f29a MD |
832 | goto error; |
833 | } | |
22e25b71 MD |
834 | } else { |
835 | ev.loglevel = -1; | |
ed7f4083 | 836 | } |
b9dfb167 DG |
837 | } else if (opt_jul) { |
838 | if (opt_event_type != LTTNG_EVENT_ALL && | |
839 | opt_event_type != LTTNG_EVENT_TRACEPOINT) { | |
840 | ERR("Event type not supported for JUL domain."); | |
841 | ret = CMD_UNSUPPORTED; | |
842 | goto error; | |
843 | } | |
b2064f54 DG |
844 | |
845 | ev.loglevel_type = opt_loglevel_type; | |
846 | if (opt_loglevel) { | |
847 | ev.loglevel = loglevel_jul_str_to_value(opt_loglevel); | |
848 | if (ev.loglevel == -1) { | |
849 | ERR("Unknown loglevel %s", opt_loglevel); | |
850 | ret = -LTTNG_ERR_INVALID; | |
851 | goto error; | |
852 | } | |
853 | } else { | |
854 | ev.loglevel = LTTNG_LOGLEVEL_JUL_ALL; | |
855 | } | |
b9dfb167 DG |
856 | ev.type = LTTNG_EVENT_TRACEPOINT; |
857 | strncpy(ev.name, event_name, LTTNG_SYMBOL_NAME_LEN); | |
858 | ev.name[LTTNG_SYMBOL_NAME_LEN - 1] = '\0'; | |
f3ed775e | 859 | } else { |
b9dfb167 | 860 | print_missing_domain(); |
300b8fd5 | 861 | ret = CMD_ERROR; |
f3ed775e DG |
862 | goto error; |
863 | } | |
864 | ||
025faf73 | 865 | if (!opt_filter) { |
9c48cab3 JI |
866 | char *exclusion_string; |
867 | ||
7ed70bc9 JI |
868 | ret = lttng_enable_event_with_exclusions(handle, |
869 | &ev, channel_name, | |
870 | NULL, exclusion_count, exclusion_list); | |
9c48cab3 | 871 | exclusion_string = print_exclusions(exclusion_count, exclusion_list); |
025faf73 DG |
872 | if (ret < 0) { |
873 | /* Turn ret to positive value to handle the positive error code */ | |
874 | switch (-ret) { | |
875 | case LTTNG_ERR_KERN_EVENT_EXIST: | |
9c48cab3 | 876 | WARN("Kernel event %s%s already enabled (channel %s, session %s)", |
85076754 | 877 | event_name, |
9c48cab3 | 878 | exclusion_string, |
85076754 | 879 | print_channel_name(channel_name), session_name); |
025faf73 DG |
880 | break; |
881 | default: | |
9c48cab3 JI |
882 | ERR("Event %s%s: %s (channel %s, session %s)", event_name, |
883 | exclusion_string, | |
85076754 MD |
884 | lttng_strerror(ret), |
885 | ret == -LTTNG_ERR_NEED_CHANNEL_NAME | |
886 | ? print_raw_channel_name(channel_name) | |
887 | : print_channel_name(channel_name), | |
888 | session_name); | |
025faf73 DG |
889 | break; |
890 | } | |
891 | warn = 1; | |
892 | } else { | |
9c48cab3 | 893 | MSG("%s event %s%s created in channel %s", |
b9dfb167 | 894 | get_domain_str(dom.type), event_name, |
9c48cab3 | 895 | exclusion_string, |
85076754 | 896 | print_channel_name(channel_name)); |
42224349 | 897 | } |
9c48cab3 | 898 | free(exclusion_string); |
6181537c | 899 | } |
025faf73 DG |
900 | |
901 | if (opt_filter) { | |
9c48cab3 JI |
902 | char *exclusion_string; |
903 | ||
7ed70bc9 JI |
904 | ret = lttng_enable_event_with_exclusions(handle, &ev, channel_name, |
905 | opt_filter, exclusion_count, exclusion_list); | |
9c48cab3 JI |
906 | exclusion_string = print_exclusions(exclusion_count, exclusion_list); |
907 | ||
53a80697 | 908 | if (ret < 0) { |
7671f53c CB |
909 | switch (-ret) { |
910 | case LTTNG_ERR_FILTER_EXIST: | |
9c48cab3 | 911 | WARN("Filter on event %s%s is already enabled" |
7671f53c | 912 | " (channel %s, session %s)", |
85076754 | 913 | event_name, |
9c48cab3 | 914 | exclusion_string, |
85076754 | 915 | print_channel_name(channel_name), session_name); |
7671f53c CB |
916 | break; |
917 | default: | |
9c48cab3 JI |
918 | ERR("Event %s%s: %s (channel %s, session %s, filter \'%s\')", ev.name, |
919 | exclusion_string, | |
85076754 MD |
920 | lttng_strerror(ret), |
921 | ret == -LTTNG_ERR_NEED_CHANNEL_NAME | |
922 | ? print_raw_channel_name(channel_name) | |
923 | : print_channel_name(channel_name), | |
924 | session_name, opt_filter); | |
7671f53c CB |
925 | break; |
926 | } | |
b69793ae | 927 | free(exclusion_string); |
53a80697 | 928 | goto error; |
16363652 | 929 | } else { |
9c48cab3 JI |
930 | MSG("Event %s%s: Filter '%s' successfully set", |
931 | event_name, exclusion_string, | |
932 | opt_filter); | |
53a80697 | 933 | } |
9c48cab3 | 934 | free(exclusion_string); |
53a80697 | 935 | } |
6181537c | 936 | |
f3ed775e DG |
937 | /* Next event */ |
938 | event_name = strtok(NULL, ","); | |
939 | } | |
940 | ||
8c9ae521 | 941 | end: |
f3ed775e | 942 | error: |
ae856491 DG |
943 | if (warn) { |
944 | ret = CMD_WARNING; | |
945 | } | |
cd80958d DG |
946 | lttng_destroy_handle(handle); |
947 | ||
7ed70bc9 JI |
948 | if (exclusion_list != NULL) { |
949 | while (exclusion_count--) { | |
950 | free(exclusion_list[exclusion_count]); | |
951 | } | |
952 | free(exclusion_list); | |
953 | } | |
954 | ||
f3ed775e DG |
955 | return ret; |
956 | } | |
957 | ||
958 | /* | |
6181537c | 959 | * Add event to trace session |
f3ed775e DG |
960 | */ |
961 | int cmd_enable_events(int argc, const char **argv) | |
962 | { | |
ca1c3607 | 963 | int opt, ret = CMD_SUCCESS; |
f3ed775e | 964 | static poptContext pc; |
cd80958d | 965 | char *session_name = NULL; |
de044b7a | 966 | int event_type = -1; |
f3ed775e DG |
967 | |
968 | pc = poptGetContext(NULL, argc, argv, long_options, 0); | |
969 | poptReadDefaultConfig(pc, 0); | |
970 | ||
971 | /* Default event type */ | |
7a3d1328 | 972 | opt_event_type = LTTNG_EVENT_ALL; |
f3ed775e DG |
973 | |
974 | while ((opt = poptGetNextOpt(pc)) != -1) { | |
975 | switch (opt) { | |
976 | case OPT_HELP: | |
ca1c3607 | 977 | usage(stdout); |
f3ed775e | 978 | goto end; |
f3ed775e | 979 | case OPT_TRACEPOINT: |
e6ddca71 | 980 | opt_event_type = LTTNG_EVENT_TRACEPOINT; |
f3ed775e | 981 | break; |
cf0e5467 | 982 | case OPT_PROBE: |
7d29a247 | 983 | opt_event_type = LTTNG_EVENT_PROBE; |
f3ed775e DG |
984 | break; |
985 | case OPT_FUNCTION: | |
986 | opt_event_type = LTTNG_EVENT_FUNCTION; | |
8f0d098b MD |
987 | break; |
988 | case OPT_FUNCTION_ENTRY: | |
989 | opt_event_type = LTTNG_EVENT_FUNCTION_ENTRY; | |
f3ed775e | 990 | break; |
a54bd42d MD |
991 | case OPT_SYSCALL: |
992 | opt_event_type = LTTNG_EVENT_SYSCALL; | |
0133c199 | 993 | break; |
eeac7d46 MD |
994 | case OPT_USERSPACE: |
995 | opt_userspace = 1; | |
eeac7d46 | 996 | break; |
0cda4f28 | 997 | case OPT_LOGLEVEL: |
8005f29a | 998 | opt_loglevel_type = LTTNG_EVENT_LOGLEVEL_RANGE; |
0cda4f28 MD |
999 | opt_loglevel = poptGetOptArg(pc); |
1000 | break; | |
1001 | case OPT_LOGLEVEL_ONLY: | |
8005f29a | 1002 | opt_loglevel_type = LTTNG_EVENT_LOGLEVEL_SINGLE; |
0cda4f28 | 1003 | opt_loglevel = poptGetOptArg(pc); |
13dce3b7 | 1004 | break; |
679b4943 SM |
1005 | case OPT_LIST_OPTIONS: |
1006 | list_cmd_options(stdout, long_options); | |
679b4943 | 1007 | goto end; |
53a80697 MD |
1008 | case OPT_FILTER: |
1009 | break; | |
fac3366c JI |
1010 | case OPT_EXCLUDE: |
1011 | break; | |
f3ed775e DG |
1012 | default: |
1013 | usage(stderr); | |
1014 | ret = CMD_UNDEFINED; | |
1015 | goto end; | |
1016 | } | |
de044b7a DG |
1017 | |
1018 | /* Validate event type. Multiple event type are not supported. */ | |
1019 | if (event_type == -1) { | |
1020 | event_type = opt_event_type; | |
1021 | } else { | |
1022 | if (event_type != opt_event_type) { | |
1023 | ERR("Multiple event type not supported."); | |
1024 | ret = CMD_ERROR; | |
1025 | goto end; | |
1026 | } | |
1027 | } | |
f3ed775e DG |
1028 | } |
1029 | ||
1030 | opt_event_list = (char*) poptGetArg(pc); | |
1031 | if (opt_event_list == NULL && opt_enable_all == 0) { | |
1032 | ERR("Missing event name(s).\n"); | |
1033 | usage(stderr); | |
ca1c3607 | 1034 | ret = CMD_ERROR; |
f3ed775e DG |
1035 | goto end; |
1036 | } | |
1037 | ||
cd80958d DG |
1038 | if (!opt_session_name) { |
1039 | session_name = get_session_name(); | |
1040 | if (session_name == NULL) { | |
ca1c3607 | 1041 | ret = CMD_ERROR; |
cd80958d DG |
1042 | goto end; |
1043 | } | |
1044 | } else { | |
1045 | session_name = opt_session_name; | |
1046 | } | |
1047 | ||
1048 | ret = enable_events(session_name); | |
f3ed775e DG |
1049 | |
1050 | end: | |
cd80958d DG |
1051 | if (opt_session_name == NULL) { |
1052 | free(session_name); | |
1053 | } | |
1054 | ||
ca1c3607 | 1055 | poptFreeContext(pc); |
f3ed775e DG |
1056 | return ret; |
1057 | } |