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