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