2 * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
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.
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.
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.
24 #include <sys/types.h>
29 #include <common/sessiond-comm/sessiond-comm.h>
30 #include <common/compat/string.h>
31 #include <common/compat/getenv.h>
32 #include <common/string-utils/string-utils.h>
33 #include <common/utils.h>
35 #include <lttng/constant.h>
37 #include <common/mi-lttng.h>
39 #include "../command.h"
41 #if (LTTNG_SYMBOL_NAME_LEN == 256)
42 #define LTTNG_SYMBOL_NAME_LEN_SCANF_IS_A_BROKEN_API "255"
45 static char *opt_event_list
;
46 static int opt_event_type
;
47 static const char *opt_loglevel
;
48 static int opt_loglevel_type
;
49 static int opt_kernel
;
50 static char *opt_session_name
;
51 static int opt_userspace
;
54 static int opt_python
;
55 static int opt_enable_all
;
56 static char *opt_probe
;
57 static char *opt_userspace_probe
;
58 static char *opt_function
;
59 static char *opt_channel_name
;
60 static char *opt_filter
;
61 static char *opt_exclude
;
63 #ifdef LTTNG_EMBED_HELP
64 static const char help_msg
[] =
65 #include <lttng-enable-event.1.h>
84 static struct lttng_handle
*handle
;
85 static struct mi_writer
*writer
;
87 static struct poptOption long_options
[] = {
88 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
89 {"help", 'h', POPT_ARG_NONE
, 0, OPT_HELP
, 0, 0},
90 {"session", 's', POPT_ARG_STRING
, &opt_session_name
, 0, 0, 0},
91 {"all", 'a', POPT_ARG_VAL
, &opt_enable_all
, 1, 0, 0},
92 {"channel", 'c', POPT_ARG_STRING
, &opt_channel_name
, 0, 0, 0},
93 {"kernel", 'k', POPT_ARG_VAL
, &opt_kernel
, 1, 0, 0},
94 {"userspace", 'u', POPT_ARG_NONE
, 0, OPT_USERSPACE
, 0, 0},
95 {"jul", 'j', POPT_ARG_VAL
, &opt_jul
, 1, 0, 0},
96 {"log4j", 'l', POPT_ARG_VAL
, &opt_log4j
, 1, 0, 0},
97 {"python", 'p', POPT_ARG_VAL
, &opt_python
, 1, 0, 0},
98 {"tracepoint", 0, POPT_ARG_NONE
, 0, OPT_TRACEPOINT
, 0, 0},
99 {"probe", 0, POPT_ARG_STRING
, &opt_probe
, OPT_PROBE
, 0, 0},
100 {"userspace-probe",0, POPT_ARG_STRING
, &opt_userspace_probe
, OPT_USERSPACE_PROBE
, 0, 0},
101 {"function", 0, POPT_ARG_STRING
, &opt_function
, OPT_FUNCTION
, 0, 0},
102 {"syscall", 0, POPT_ARG_NONE
, 0, OPT_SYSCALL
, 0, 0},
103 {"loglevel", 0, POPT_ARG_STRING
, 0, OPT_LOGLEVEL
, 0, 0},
104 {"loglevel-only", 0, POPT_ARG_STRING
, 0, OPT_LOGLEVEL_ONLY
, 0, 0},
105 {"list-options", 0, POPT_ARG_NONE
, NULL
, OPT_LIST_OPTIONS
, NULL
, NULL
},
106 {"filter", 'f', POPT_ARG_STRING
, &opt_filter
, OPT_FILTER
, 0, 0},
107 {"exclude", 'x', POPT_ARG_STRING
, &opt_exclude
, OPT_EXCLUDE
, 0, 0},
108 {0, 0, 0, 0, 0, 0, 0}
112 * Parse probe options.
114 static int parse_probe_opts(struct lttng_event
*ev
, char *opt
)
116 int ret
= CMD_SUCCESS
;
119 #define S_HEX_LEN_SCANF_IS_A_BROKEN_API "18" /* 18 is (19 - 1) (\0 is extra) */
120 char name
[LTTNG_SYMBOL_NAME_LEN
];
127 /* Check for symbol+offset */
128 match
= sscanf(opt
, "%" LTTNG_SYMBOL_NAME_LEN_SCANF_IS_A_BROKEN_API
129 "[^'+']+%" S_HEX_LEN_SCANF_IS_A_BROKEN_API
"s", name
, s_hex
);
131 strncpy(ev
->attr
.probe
.symbol_name
, name
, LTTNG_SYMBOL_NAME_LEN
);
132 ev
->attr
.probe
.symbol_name
[LTTNG_SYMBOL_NAME_LEN
- 1] = '\0';
133 DBG("probe symbol %s", ev
->attr
.probe
.symbol_name
);
134 if (*s_hex
== '\0') {
135 ERR("Invalid probe offset %s", s_hex
);
139 ev
->attr
.probe
.offset
= strtoul(s_hex
, NULL
, 0);
140 DBG("probe offset %" PRIu64
, ev
->attr
.probe
.offset
);
141 ev
->attr
.probe
.addr
= 0;
145 /* Check for symbol */
146 if (isalpha(name
[0])) {
147 match
= sscanf(opt
, "%" LTTNG_SYMBOL_NAME_LEN_SCANF_IS_A_BROKEN_API
"s",
150 strncpy(ev
->attr
.probe
.symbol_name
, name
, LTTNG_SYMBOL_NAME_LEN
);
151 ev
->attr
.probe
.symbol_name
[LTTNG_SYMBOL_NAME_LEN
- 1] = '\0';
152 DBG("probe symbol %s", ev
->attr
.probe
.symbol_name
);
153 ev
->attr
.probe
.offset
= 0;
154 DBG("probe offset %" PRIu64
, ev
->attr
.probe
.offset
);
155 ev
->attr
.probe
.addr
= 0;
160 /* Check for address */
161 match
= sscanf(opt
, "%" S_HEX_LEN_SCANF_IS_A_BROKEN_API
"s", s_hex
);
163 if (*s_hex
== '\0') {
164 ERR("Invalid probe address %s", s_hex
);
168 ev
->attr
.probe
.addr
= strtoul(s_hex
, NULL
, 0);
169 DBG("probe addr %" PRIu64
, ev
->attr
.probe
.addr
);
170 ev
->attr
.probe
.offset
= 0;
171 memset(ev
->attr
.probe
.symbol_name
, 0, LTTNG_SYMBOL_NAME_LEN
);
183 * Walk the directories in the PATH environment variable to find the target
184 * binary passed as parameter.
186 * On success, the full path of the binary is copied in binary_full_path out
187 * parameter. This buffer is allocated by the caller and must be at least
188 * LTTNG_PATH_MAX bytes long.
189 * On failure, returns -1;
191 static int walk_command_search_path(const char *binary
, char *binary_full_path
)
193 char *tentative_binary_path
= NULL
;
194 char *command_search_path
= NULL
;
195 char *curr_search_dir_end
= NULL
;
196 char *curr_search_dir
= NULL
;
197 struct stat stat_output
;
200 command_search_path
= lttng_secure_getenv("PATH");
201 if (!command_search_path
) {
207 * Duplicate the $PATH string as the char pointer returned by getenv() should
210 command_search_path
= strdup(command_search_path
);
211 if (!command_search_path
) {
217 * This char array is used to concatenate path to binary to look for
220 tentative_binary_path
= zmalloc(LTTNG_PATH_MAX
* sizeof(char));
221 if (!tentative_binary_path
) {
226 curr_search_dir
= command_search_path
;
229 * Split on ':'. The return value of this call points to the
230 * matching character.
232 curr_search_dir_end
= strchr(curr_search_dir
, ':');
233 if (curr_search_dir_end
!= NULL
) {
235 * Add a NULL byte to the end of the first token so it
236 * can be used as a string.
238 curr_search_dir_end
[0] = '\0';
241 /* Empty the tentative path */
242 memset(tentative_binary_path
, 0, LTTNG_PATH_MAX
* sizeof(char));
245 * Build the tentative path to the binary using the current
246 * search directory and the name of the binary.
248 ret
= snprintf(tentative_binary_path
, LTTNG_PATH_MAX
, "%s/%s",
249 curr_search_dir
, binary
);
251 goto free_binary_path
;
253 if (ret
< LTTNG_PATH_MAX
) {
255 * Use STAT(2) to see if the file exists.
257 ret
= stat(tentative_binary_path
, &stat_output
);
260 * Verify that it is a regular file or a
261 * symlink and not a special file (e.g.
264 if (S_ISREG(stat_output
.st_mode
)
265 || S_ISLNK(stat_output
.st_mode
)) {
267 * Found a match, set the out parameter
268 * and return success.
270 ret
= lttng_strncpy(binary_full_path
,
271 tentative_binary_path
,
274 ERR("Source path does not fit "
275 "in destination buffer.");
277 goto free_binary_path
;
281 /* Go to the next entry in the $PATH variable. */
282 curr_search_dir
= curr_search_dir_end
+ 1;
283 } while (curr_search_dir_end
!= NULL
);
286 free(tentative_binary_path
);
288 free(command_search_path
);
294 * Check if the symbol field passed by the user is in fact an address or an
295 * offset from a symbol. Those two instrumentation types are not supported yet.
296 * It's expected to be a common mistake because of the existing --probe option
297 * that does support these formats.
299 * Here are examples of these unsupported formats for the --userspace-probe
301 * elf:/path/to/binary:0x400430
302 * elf:/path/to/binary:4194364
303 * elf:/path/to/binary:my_symbol+0x323
304 * elf:/path/to/binary:my_symbol+43
306 static int warn_userspace_probe_syntax(const char *symbol
)
308 unsigned long addr
= 0;
312 /* Check if the symbol field is an hex address. */
313 ret
= sscanf(symbol
, "0x%lx", &addr
);
315 /* If there is a match, print a warning and return an error. */
316 ERR("Userspace probe on address not supported yet.");
317 ret
= CMD_UNSUPPORTED
;
321 /* Check if the symbol field is an decimal address. */
322 ret
= sscanf(symbol
, "%lu", &addr
);
324 /* If there is a match, print a warning and return an error. */
325 ERR("Userspace probe on address not supported yet.");
326 ret
= CMD_UNSUPPORTED
;
330 /* Check if the symbol field is symbol+hex_offset. */
331 ret
= sscanf(symbol
, "%*[^+]+0x%lx", &offset
);
333 /* If there is a match, print a warning and return an error. */
334 ERR("Userspace probe on symbol+offset not supported yet.");
335 ret
= CMD_UNSUPPORTED
;
339 /* Check if the symbol field is symbol+decimal_offset. */
340 ret
= sscanf(symbol
, "%*[^+]+%lu", &offset
);
342 /* If there is a match, print a warning and return an error. */
343 ERR("Userspace probe on symbol+offset not supported yet.");
344 ret
= CMD_UNSUPPORTED
;
355 * Parse userspace probe options
356 * Set the userspace probe fields in the lttng_event struct and set the
357 * target_path to the path to the binary.
359 static int parse_userspace_probe_opts(struct lttng_event
*ev
, char *opt
)
361 int ret
= CMD_SUCCESS
;
364 char *target_path
= NULL
;
365 char *unescaped_target_path
= NULL
;
366 char *real_target_path
= NULL
;
367 char *symbol_name
= NULL
, *probe_name
= NULL
, *provider_name
= NULL
;
368 struct lttng_userspace_probe_location
*probe_location
= NULL
;
369 struct lttng_userspace_probe_location_lookup_method
*lookup_method
=
378 case LTTNG_EVENT_USERSPACE_PROBE
:
385 * userspace probe fields are separated by ':'.
387 tokens
= strutils_split(opt
, ':', 1);
388 num_token
= strutils_array_of_strings_len(tokens
);
391 * Early sanity check that the number of parameter is between 2 and 4
394 * std:PATH:PROVIDER_NAME:PROBE_NAME
395 * PATH:SYMBOL (same behavior as ELF)
397 if (num_token
< 2 || num_token
> 4) {
403 * Looking up the first parameter will tell the technique to use to
404 * interpret the userspace probe/function description.
408 /* When the probe type is omitted we assume ELF for now. */
410 if (num_token
== 3 && strcmp(tokens
[0], "elf") == 0) {
411 target_path
= tokens
[1];
412 symbol_name
= tokens
[2];
413 } else if (num_token
== 2) {
414 target_path
= tokens
[0];
415 symbol_name
= tokens
[1];
421 lttng_userspace_probe_location_lookup_method_function_elf_create();
422 if (!lookup_method
) {
423 WARN("Failed to create ELF lookup method");
429 if (strcmp(tokens
[0], "sdt") == 0) {
430 target_path
= tokens
[1];
431 provider_name
= tokens
[2];
432 probe_name
= tokens
[3];
438 lttng_userspace_probe_location_lookup_method_tracepoint_sdt_create();
439 if (!lookup_method
) {
440 WARN("Failed to create ELF lookup method");
450 /* strutils_unescape_string allocates a new char *. */
451 unescaped_target_path
= strutils_unescape_string(target_path
, 0);
452 if (!unescaped_target_path
) {
454 goto end_destroy_lookup_method
;
458 * If there is not forward slash in the path. Walk the $PATH else
461 if (strchr(unescaped_target_path
, '/') == NULL
) {
462 /* Walk the $PATH variable to find the targeted binary. */
463 real_target_path
= zmalloc(LTTNG_PATH_MAX
* sizeof(char));
464 if (!real_target_path
) {
465 PERROR("Error allocating path buffer");
467 goto end_destroy_lookup_method
;
469 ret
= walk_command_search_path(unescaped_target_path
, real_target_path
);
471 ERR("Binary not found.");
473 goto end_destroy_lookup_method
;
477 * Expand references to `/./` and `/../`. This function does not check
478 * if the file exists. This call returns an allocated buffer on
481 real_target_path
= utils_expand_path_keep_symlink(unescaped_target_path
);
482 if (!real_target_path
) {
483 ERR("Error expanding the path to binary.");
485 goto end_destroy_lookup_method
;
489 * Check if the file exists using access(2). If it does not, walk the
492 ret
= access(real_target_path
, F_OK
);
494 ERR("Cannot find binary at path: %s.", real_target_path
);
496 goto end_destroy_lookup_method
;
500 switch (lttng_userspace_probe_location_lookup_method_get_type(lookup_method
)) {
501 case LTTNG_USERSPACE_PROBE_LOCATION_LOOKUP_METHOD_TYPE_FUNCTION_ELF
:
503 * Check for common mistakes in userspace probe description syntax.
505 ret
= warn_userspace_probe_syntax(symbol_name
);
507 goto end_destroy_lookup_method
;
510 probe_location
= lttng_userspace_probe_location_function_create(
511 real_target_path
, symbol_name
, lookup_method
);
512 if (!probe_location
) {
513 WARN("Failed to create function probe location");
515 goto end_destroy_lookup_method
;
518 /* Ownership transferred to probe_location. */
519 lookup_method
= NULL
;
521 ret
= lttng_event_set_userspace_probe_location(ev
, probe_location
);
523 WARN("Failed to set probe location on event");
525 goto end_destroy_location
;
528 case LTTNG_USERSPACE_PROBE_LOCATION_LOOKUP_METHOD_TYPE_TRACEPOINT_SDT
:
529 probe_location
= lttng_userspace_probe_location_tracepoint_create(
530 real_target_path
, provider_name
, probe_name
, lookup_method
);
531 if (!probe_location
) {
532 WARN("Failed to create function probe location");
534 goto end_destroy_lookup_method
;
537 /* Ownership transferred to probe_location. */
538 lookup_method
= NULL
;
540 ret
= lttng_event_set_userspace_probe_location(ev
, probe_location
);
542 WARN("Failed to set probe location on event");
544 goto end_destroy_location
;
549 goto end_destroy_lookup_method
;
552 /* Successful parsing, now clean up everything and return. */
555 end_destroy_location
:
556 lttng_userspace_probe_location_destroy(probe_location
);
557 end_destroy_lookup_method
:
558 lttng_userspace_probe_location_lookup_method_destroy(lookup_method
);
560 strutils_free_null_terminated_array_of_strings(tokens
);
562 * Freeing both char * here makes the error handling simplier. free()
563 * performs not action if the pointer is NULL.
565 free(real_target_path
);
566 free(unescaped_target_path
);
572 * Maps LOG4j loglevel from string to value
574 static int loglevel_log4j_str_to_value(const char *inputstr
)
577 char str
[LTTNG_SYMBOL_NAME_LEN
];
579 if (!inputstr
|| strlen(inputstr
) == 0) {
584 * Loop up to LTTNG_SYMBOL_NAME_LEN minus one because the NULL bytes is
585 * added at the end of the loop so a the upper bound we avoid the overflow.
587 while (i
< (LTTNG_SYMBOL_NAME_LEN
- 1) && inputstr
[i
] != '\0') {
588 str
[i
] = toupper(inputstr
[i
]);
593 if (!strcmp(str
, "LOG4J_OFF") || !strcmp(str
, "OFF")) {
594 return LTTNG_LOGLEVEL_LOG4J_OFF
;
595 } else if (!strcmp(str
, "LOG4J_FATAL") || !strcmp(str
, "FATAL")) {
596 return LTTNG_LOGLEVEL_LOG4J_FATAL
;
597 } else if (!strcmp(str
, "LOG4J_ERROR") || !strcmp(str
, "ERROR")) {
598 return LTTNG_LOGLEVEL_LOG4J_ERROR
;
599 } else if (!strcmp(str
, "LOG4J_WARN") || !strcmp(str
, "WARN")) {
600 return LTTNG_LOGLEVEL_LOG4J_WARN
;
601 } else if (!strcmp(str
, "LOG4J_INFO") || !strcmp(str
, "INFO")) {
602 return LTTNG_LOGLEVEL_LOG4J_INFO
;
603 } else if (!strcmp(str
, "LOG4J_DEBUG") || !strcmp(str
, "DEBUG")) {
604 return LTTNG_LOGLEVEL_LOG4J_DEBUG
;
605 } else if (!strcmp(str
, "LOG4J_TRACE") || !strcmp(str
, "TRACE")) {
606 return LTTNG_LOGLEVEL_LOG4J_TRACE
;
607 } else if (!strcmp(str
, "LOG4J_ALL") || !strcmp(str
, "ALL")) {
608 return LTTNG_LOGLEVEL_LOG4J_ALL
;
615 * Maps JUL loglevel from string to value
617 static int loglevel_jul_str_to_value(const char *inputstr
)
620 char str
[LTTNG_SYMBOL_NAME_LEN
];
622 if (!inputstr
|| strlen(inputstr
) == 0) {
627 * Loop up to LTTNG_SYMBOL_NAME_LEN minus one because the NULL bytes is
628 * added at the end of the loop so a the upper bound we avoid the overflow.
630 while (i
< (LTTNG_SYMBOL_NAME_LEN
- 1) && inputstr
[i
] != '\0') {
631 str
[i
] = toupper(inputstr
[i
]);
636 if (!strcmp(str
, "JUL_OFF") || !strcmp(str
, "OFF")) {
637 return LTTNG_LOGLEVEL_JUL_OFF
;
638 } else if (!strcmp(str
, "JUL_SEVERE") || !strcmp(str
, "SEVERE")) {
639 return LTTNG_LOGLEVEL_JUL_SEVERE
;
640 } else if (!strcmp(str
, "JUL_WARNING") || !strcmp(str
, "WARNING")) {
641 return LTTNG_LOGLEVEL_JUL_WARNING
;
642 } else if (!strcmp(str
, "JUL_INFO") || !strcmp(str
, "INFO")) {
643 return LTTNG_LOGLEVEL_JUL_INFO
;
644 } else if (!strcmp(str
, "JUL_CONFIG") || !strcmp(str
, "CONFIG")) {
645 return LTTNG_LOGLEVEL_JUL_CONFIG
;
646 } else if (!strcmp(str
, "JUL_FINE") || !strcmp(str
, "FINE")) {
647 return LTTNG_LOGLEVEL_JUL_FINE
;
648 } else if (!strcmp(str
, "JUL_FINER") || !strcmp(str
, "FINER")) {
649 return LTTNG_LOGLEVEL_JUL_FINER
;
650 } else if (!strcmp(str
, "JUL_FINEST") || !strcmp(str
, "FINEST")) {
651 return LTTNG_LOGLEVEL_JUL_FINEST
;
652 } else if (!strcmp(str
, "JUL_ALL") || !strcmp(str
, "ALL")) {
653 return LTTNG_LOGLEVEL_JUL_ALL
;
660 * Maps Python loglevel from string to value
662 static int loglevel_python_str_to_value(const char *inputstr
)
665 char str
[LTTNG_SYMBOL_NAME_LEN
];
667 if (!inputstr
|| strlen(inputstr
) == 0) {
672 * Loop up to LTTNG_SYMBOL_NAME_LEN minus one because the NULL bytes is
673 * added at the end of the loop so a the upper bound we avoid the overflow.
675 while (i
< (LTTNG_SYMBOL_NAME_LEN
- 1) && inputstr
[i
] != '\0') {
676 str
[i
] = toupper(inputstr
[i
]);
681 if (!strcmp(str
, "PYTHON_CRITICAL") || !strcmp(str
, "CRITICAL")) {
682 return LTTNG_LOGLEVEL_PYTHON_CRITICAL
;
683 } else if (!strcmp(str
, "PYTHON_ERROR") || !strcmp(str
, "ERROR")) {
684 return LTTNG_LOGLEVEL_PYTHON_ERROR
;
685 } else if (!strcmp(str
, "PYTHON_WARNING") || !strcmp(str
, "WARNING")) {
686 return LTTNG_LOGLEVEL_PYTHON_WARNING
;
687 } else if (!strcmp(str
, "PYTHON_INFO") || !strcmp(str
, "INFO")) {
688 return LTTNG_LOGLEVEL_PYTHON_INFO
;
689 } else if (!strcmp(str
, "PYTNON_DEBUG") || !strcmp(str
, "DEBUG")) {
690 return LTTNG_LOGLEVEL_PYTHON_DEBUG
;
691 } else if (!strcmp(str
, "PYTHON_NOTSET") || !strcmp(str
, "NOTSET")) {
692 return LTTNG_LOGLEVEL_PYTHON_NOTSET
;
699 * Maps loglevel from string to value
702 int loglevel_str_to_value(const char *inputstr
)
705 char str
[LTTNG_SYMBOL_NAME_LEN
];
707 if (!inputstr
|| strlen(inputstr
) == 0) {
712 * Loop up to LTTNG_SYMBOL_NAME_LEN minus one because the NULL bytes is
713 * added at the end of the loop so a the upper bound we avoid the overflow.
715 while (i
< (LTTNG_SYMBOL_NAME_LEN
- 1) && inputstr
[i
] != '\0') {
716 str
[i
] = toupper(inputstr
[i
]);
720 if (!strcmp(str
, "TRACE_EMERG") || !strcmp(str
, "EMERG")) {
721 return LTTNG_LOGLEVEL_EMERG
;
722 } else if (!strcmp(str
, "TRACE_ALERT") || !strcmp(str
, "ALERT")) {
723 return LTTNG_LOGLEVEL_ALERT
;
724 } else if (!strcmp(str
, "TRACE_CRIT") || !strcmp(str
, "CRIT")) {
725 return LTTNG_LOGLEVEL_CRIT
;
726 } else if (!strcmp(str
, "TRACE_ERR") || !strcmp(str
, "ERR")) {
727 return LTTNG_LOGLEVEL_ERR
;
728 } else if (!strcmp(str
, "TRACE_WARNING") || !strcmp(str
, "WARNING")) {
729 return LTTNG_LOGLEVEL_WARNING
;
730 } else if (!strcmp(str
, "TRACE_NOTICE") || !strcmp(str
, "NOTICE")) {
731 return LTTNG_LOGLEVEL_NOTICE
;
732 } else if (!strcmp(str
, "TRACE_INFO") || !strcmp(str
, "INFO")) {
733 return LTTNG_LOGLEVEL_INFO
;
734 } else if (!strcmp(str
, "TRACE_DEBUG_SYSTEM") || !strcmp(str
, "DEBUG_SYSTEM") || !strcmp(str
, "SYSTEM")) {
735 return LTTNG_LOGLEVEL_DEBUG_SYSTEM
;
736 } else if (!strcmp(str
, "TRACE_DEBUG_PROGRAM") || !strcmp(str
, "DEBUG_PROGRAM") || !strcmp(str
, "PROGRAM")) {
737 return LTTNG_LOGLEVEL_DEBUG_PROGRAM
;
738 } else if (!strcmp(str
, "TRACE_DEBUG_PROCESS") || !strcmp(str
, "DEBUG_PROCESS") || !strcmp(str
, "PROCESS")) {
739 return LTTNG_LOGLEVEL_DEBUG_PROCESS
;
740 } else if (!strcmp(str
, "TRACE_DEBUG_MODULE") || !strcmp(str
, "DEBUG_MODULE") || !strcmp(str
, "MODULE")) {
741 return LTTNG_LOGLEVEL_DEBUG_MODULE
;
742 } else if (!strcmp(str
, "TRACE_DEBUG_UNIT") || !strcmp(str
, "DEBUG_UNIT") || !strcmp(str
, "UNIT")) {
743 return LTTNG_LOGLEVEL_DEBUG_UNIT
;
744 } else if (!strcmp(str
, "TRACE_DEBUG_FUNCTION") || !strcmp(str
, "DEBUG_FUNCTION") || !strcmp(str
, "FUNCTION")) {
745 return LTTNG_LOGLEVEL_DEBUG_FUNCTION
;
746 } else if (!strcmp(str
, "TRACE_DEBUG_LINE") || !strcmp(str
, "DEBUG_LINE") || !strcmp(str
, "LINE")) {
747 return LTTNG_LOGLEVEL_DEBUG_LINE
;
748 } else if (!strcmp(str
, "TRACE_DEBUG") || !strcmp(str
, "DEBUG")) {
749 return LTTNG_LOGLEVEL_DEBUG
;
756 const char *print_channel_name(const char *name
)
758 return name
? : DEFAULT_CHANNEL_NAME
;
762 const char *print_raw_channel_name(const char *name
)
764 return name
? : "<default>";
768 * Mi print exlcusion list
771 int mi_print_exclusion(char **names
)
774 int count
= names
? strutils_array_of_strings_len(names
) : 0;
782 ret
= mi_lttng_writer_open_element(writer
, config_element_exclusions
);
787 for (i
= 0; i
< count
; i
++) {
788 ret
= mi_lttng_writer_write_element_string(writer
,
789 config_element_exclusion
, names
[i
]);
795 /* Close exclusions element */
796 ret
= mi_lttng_writer_close_element(writer
);
803 * Return allocated string for pretty-printing exclusion names.
806 char *print_exclusions(char **names
)
810 const char *preamble
= " excluding ";
812 int count
= names
? strutils_array_of_strings_len(names
) : 0;
818 /* calculate total required length */
819 for (i
= 0; i
< count
; i
++) {
820 length
+= strlen(names
[i
]) + 4;
823 /* add length of preamble + one for NUL - one for last (missing) comma */
824 length
+= strlen(preamble
);
825 ret
= zmalloc(length
+ 1);
829 strncpy(ret
, preamble
, length
);
830 for (i
= 0; i
< count
; i
++) {
832 strcat(ret
, names
[i
]);
834 if (i
!= count
- 1) {
843 int check_exclusion_subsets(const char *event_name
, const char *exclusion
)
847 const char *e
= event_name
;
848 const char *x
= exclusion
;
850 /* Scan both the excluder and the event letter by letter */
864 /* Event is a subset of the excluder */
865 ERR("Event %s: %s excludes all events from %s",
866 event_name
, exclusion
, event_name
);
872 * Reached the end of the event name before the
873 * end of the exclusion: this is valid.
895 WARN("Event %s: %s does not exclude any events from %s",
896 event_name
, exclusion
, event_name
);
903 int create_exclusion_list_and_validate(const char *event_name
,
904 const char *exclusions_arg
,
905 char ***exclusion_list
)
908 char **exclusions
= NULL
;
910 /* Event name must be a valid globbing pattern to allow exclusions. */
911 if (!strutils_is_star_glob_pattern(event_name
)) {
912 ERR("Event %s: Exclusions can only be used with a globbing pattern",
917 /* Split exclusions. */
918 exclusions
= strutils_split(exclusions_arg
, ',', true);
924 * If the event name is a star-at-end only globbing pattern,
925 * then we can validate the individual exclusions. Otherwise
926 * all exclusions are passed to the session daemon.
928 if (strutils_is_star_at_the_end_only_glob_pattern(event_name
)) {
929 char * const *exclusion
;
931 for (exclusion
= exclusions
; *exclusion
; exclusion
++) {
932 if (!strutils_is_star_glob_pattern(*exclusion
) ||
933 strutils_is_star_at_the_end_only_glob_pattern(*exclusion
)) {
934 ret
= check_exclusion_subsets(event_name
, *exclusion
);
942 *exclusion_list
= exclusions
;
948 strutils_free_null_terminated_array_of_strings(exclusions
);
954 static void warn_on_truncated_exclusion_names(char * const *exclusion_list
,
957 char * const *exclusion
;
959 for (exclusion
= exclusion_list
; *exclusion
; exclusion
++) {
960 if (strlen(*exclusion
) >= LTTNG_SYMBOL_NAME_LEN
) {
961 WARN("Event exclusion \"%s\" will be truncated",
969 * Enabling event using the lttng API.
970 * Note: in case of error only the last error code will be return.
972 static int enable_events(char *session_name
)
974 int ret
= CMD_SUCCESS
, command_ret
= CMD_SUCCESS
;
975 int error_holder
= CMD_SUCCESS
, warn
= 0, error
= 0, success
= 1;
976 char *event_name
, *channel_name
= NULL
;
977 struct lttng_event
*ev
;
978 struct lttng_domain dom
;
979 char **exclusion_list
= NULL
;
981 memset(&dom
, 0, sizeof(dom
));
983 ev
= lttng_event_create();
991 WARN("Kernel loglevels are not supported.");
995 /* Create lttng domain */
997 dom
.type
= LTTNG_DOMAIN_KERNEL
;
998 dom
.buf_type
= LTTNG_BUFFER_GLOBAL
;
999 } else if (opt_userspace
) {
1000 dom
.type
= LTTNG_DOMAIN_UST
;
1002 dom
.buf_type
= LTTNG_BUFFER_PER_UID
;
1003 } else if (opt_jul
) {
1004 dom
.type
= LTTNG_DOMAIN_JUL
;
1006 dom
.buf_type
= LTTNG_BUFFER_PER_UID
;
1007 } else if (opt_log4j
) {
1008 dom
.type
= LTTNG_DOMAIN_LOG4J
;
1010 dom
.buf_type
= LTTNG_BUFFER_PER_UID
;
1011 } else if (opt_python
) {
1012 dom
.type
= LTTNG_DOMAIN_PYTHON
;
1014 dom
.buf_type
= LTTNG_BUFFER_PER_UID
;
1016 /* Checked by the caller. */
1022 case LTTNG_DOMAIN_KERNEL
:
1023 case LTTNG_DOMAIN_JUL
:
1024 case LTTNG_DOMAIN_LOG4J
:
1025 case LTTNG_DOMAIN_PYTHON
:
1026 ERR("Event name exclusions are not yet implemented for %s events",
1027 get_domain_str(dom
.type
));
1030 case LTTNG_DOMAIN_UST
:
1031 /* Exclusions supported */
1039 * Adding a filter to a probe, function or userspace-probe would be
1040 * denied by the kernel tracer as it's not supported at the moment. We
1041 * do an early check here to warn the user.
1043 if (opt_filter
&& opt_kernel
) {
1044 switch (opt_event_type
) {
1045 case LTTNG_EVENT_ALL
:
1046 case LTTNG_EVENT_TRACEPOINT
:
1047 case LTTNG_EVENT_SYSCALL
:
1049 case LTTNG_EVENT_PROBE
:
1050 case LTTNG_EVENT_USERSPACE_PROBE
:
1051 case LTTNG_EVENT_FUNCTION
:
1052 ERR("Filter expressions are not supported for %s events",
1053 get_event_type_str(opt_event_type
));
1057 ret
= CMD_UNDEFINED
;
1062 channel_name
= opt_channel_name
;
1064 handle
= lttng_create_handle(session_name
, &dom
);
1065 if (handle
== NULL
) {
1072 /* Open a events element */
1073 ret
= mi_lttng_writer_open_element(writer
, config_element_events
);
1080 if (opt_enable_all
) {
1081 /* Default setup for enable all */
1083 ev
->type
= opt_event_type
;
1084 strcpy(ev
->name
, "*");
1085 /* kernel loglevels not implemented */
1086 ev
->loglevel_type
= LTTNG_EVENT_LOGLEVEL_ALL
;
1088 ev
->type
= LTTNG_EVENT_TRACEPOINT
;
1089 strcpy(ev
->name
, "*");
1090 ev
->loglevel_type
= opt_loglevel_type
;
1092 assert(opt_userspace
|| opt_jul
|| opt_log4j
|| opt_python
);
1093 if (opt_userspace
) {
1094 ev
->loglevel
= loglevel_str_to_value(opt_loglevel
);
1095 } else if (opt_jul
) {
1096 ev
->loglevel
= loglevel_jul_str_to_value(opt_loglevel
);
1097 } else if (opt_log4j
) {
1098 ev
->loglevel
= loglevel_log4j_str_to_value(opt_loglevel
);
1099 } else if (opt_python
) {
1100 ev
->loglevel
= loglevel_python_str_to_value(opt_loglevel
);
1102 if (ev
->loglevel
== -1) {
1103 ERR("Unknown loglevel %s", opt_loglevel
);
1104 ret
= -LTTNG_ERR_INVALID
;
1108 assert(opt_userspace
|| opt_jul
|| opt_log4j
|| opt_python
);
1109 if (opt_userspace
) {
1111 } else if (opt_jul
) {
1112 ev
->loglevel
= LTTNG_LOGLEVEL_JUL_ALL
;
1113 } else if (opt_log4j
) {
1114 ev
->loglevel
= LTTNG_LOGLEVEL_LOG4J_ALL
;
1115 } else if (opt_python
) {
1116 ev
->loglevel
= LTTNG_LOGLEVEL_PYTHON_DEBUG
;
1122 ret
= create_exclusion_list_and_validate("*",
1123 opt_exclude
, &exclusion_list
);
1130 warn_on_truncated_exclusion_names(exclusion_list
,
1134 ret
= lttng_enable_event_with_exclusions(handle
,
1137 exclusion_list
? strutils_array_of_strings_len(exclusion_list
) : 0,
1141 case LTTNG_ERR_KERN_EVENT_EXIST
:
1142 WARN("Kernel events already enabled (channel %s, session %s)",
1143 print_channel_name(channel_name
), session_name
);
1146 case LTTNG_ERR_TRACE_ALREADY_STARTED
:
1148 const char *msg
= "The command tried to enable an event in a new domain for a session that has already been started once.";
1149 ERR("Events: %s (channel %s, session %s)",
1151 print_channel_name(channel_name
),
1157 ERR("Events: %s (channel %s, session %s)",
1158 lttng_strerror(ret
),
1159 ret
== -LTTNG_ERR_NEED_CHANNEL_NAME
1160 ? print_raw_channel_name(channel_name
)
1161 : print_channel_name(channel_name
),
1169 switch (opt_event_type
) {
1170 case LTTNG_EVENT_TRACEPOINT
:
1171 if (opt_loglevel
&& dom
.type
!= LTTNG_DOMAIN_KERNEL
) {
1172 char *exclusion_string
= print_exclusions(exclusion_list
);
1174 if (!exclusion_string
) {
1175 PERROR("Cannot allocate exclusion_string");
1179 MSG("All %s tracepoints%s are enabled in channel %s for loglevel %s",
1180 get_domain_str(dom
.type
),
1182 print_channel_name(channel_name
),
1184 free(exclusion_string
);
1186 char *exclusion_string
= print_exclusions(exclusion_list
);
1188 if (!exclusion_string
) {
1189 PERROR("Cannot allocate exclusion_string");
1193 MSG("All %s tracepoints%s are enabled in channel %s",
1194 get_domain_str(dom
.type
),
1196 print_channel_name(channel_name
));
1197 free(exclusion_string
);
1200 case LTTNG_EVENT_SYSCALL
:
1202 MSG("All %s system calls are enabled in channel %s",
1203 get_domain_str(dom
.type
),
1204 print_channel_name(channel_name
));
1207 case LTTNG_EVENT_ALL
:
1208 if (opt_loglevel
&& dom
.type
!= LTTNG_DOMAIN_KERNEL
) {
1209 char *exclusion_string
= print_exclusions(exclusion_list
);
1211 if (!exclusion_string
) {
1212 PERROR("Cannot allocate exclusion_string");
1216 MSG("All %s events%s are enabled in channel %s for loglevel %s",
1217 get_domain_str(dom
.type
),
1219 print_channel_name(channel_name
),
1221 free(exclusion_string
);
1223 char *exclusion_string
= print_exclusions(exclusion_list
);
1225 if (!exclusion_string
) {
1226 PERROR("Cannot allocate exclusion_string");
1230 MSG("All %s events%s are enabled in channel %s",
1231 get_domain_str(dom
.type
),
1233 print_channel_name(channel_name
));
1234 free(exclusion_string
);
1239 * We should not be here since lttng_enable_event should have
1240 * failed on the event type.
1247 command_ret
= lttng_enable_event_with_exclusions(handle
, ev
, channel_name
,
1249 exclusion_list
? strutils_array_of_strings_len(exclusion_list
) : 0,
1251 if (command_ret
< 0) {
1252 switch (-command_ret
) {
1253 case LTTNG_ERR_FILTER_EXIST
:
1254 WARN("Filter on all events is already enabled"
1255 " (channel %s, session %s)",
1256 print_channel_name(channel_name
), session_name
);
1259 case LTTNG_ERR_TRACE_ALREADY_STARTED
:
1261 const char *msg
= "The command tried to enable an event in a new domain for a session that has already been started once.";
1262 ERR("All events: %s (channel %s, session %s, filter \'%s\')",
1264 print_channel_name(channel_name
),
1265 session_name
, opt_filter
);
1270 ERR("All events: %s (channel %s, session %s, filter \'%s\')",
1271 lttng_strerror(command_ret
),
1272 command_ret
== -LTTNG_ERR_NEED_CHANNEL_NAME
1273 ? print_raw_channel_name(channel_name
)
1274 : print_channel_name(channel_name
),
1275 session_name
, opt_filter
);
1279 error_holder
= command_ret
;
1282 MSG("Filter '%s' successfully set", opt_filter
);
1287 /* The wildcard * is used for kernel and ust domain to
1288 * represent ALL. We copy * in event name to force the wildcard use
1291 * Note: this is strictly for semantic and printing while in
1292 * machine interface mode.
1294 strcpy(ev
->name
, "*");
1296 /* If we reach here the events are enabled */
1297 if (!error
&& !warn
) {
1303 ret
= mi_lttng_event(writer
, ev
, 1, handle
->domain
.type
);
1309 /* print exclusion */
1310 ret
= mi_print_exclusion(exclusion_list
);
1317 ret
= mi_lttng_writer_write_element_bool(writer
,
1318 mi_lttng_element_command_success
, success
);
1324 /* Close event element */
1325 ret
= mi_lttng_writer_close_element(writer
);
1335 /* Strip event list */
1336 event_name
= strtok(opt_event_list
, ",");
1337 while (event_name
!= NULL
) {
1338 /* Copy name and type of the event */
1339 strncpy(ev
->name
, event_name
, LTTNG_SYMBOL_NAME_LEN
);
1340 ev
->name
[LTTNG_SYMBOL_NAME_LEN
- 1] = '\0';
1341 ev
->type
= opt_event_type
;
1343 /* Kernel tracer action */
1345 DBG("Enabling kernel event %s for channel %s",
1347 print_channel_name(channel_name
));
1349 switch (opt_event_type
) {
1350 case LTTNG_EVENT_ALL
: /* Enable tracepoints and syscalls */
1351 /* If event name differs from *, select tracepoint. */
1352 if (strcmp(ev
->name
, "*")) {
1353 ev
->type
= LTTNG_EVENT_TRACEPOINT
;
1356 case LTTNG_EVENT_TRACEPOINT
:
1358 case LTTNG_EVENT_PROBE
:
1359 ret
= parse_probe_opts(ev
, opt_probe
);
1361 ERR("Unable to parse probe options");
1366 case LTTNG_EVENT_USERSPACE_PROBE
:
1367 ret
= parse_userspace_probe_opts(ev
, opt_userspace_probe
);
1370 case CMD_UNSUPPORTED
:
1372 * Error message describing
1373 * what is not supported was
1374 * printed in the function.
1379 ERR("Unable to parse userspace probe options");
1385 case LTTNG_EVENT_FUNCTION
:
1386 ret
= parse_probe_opts(ev
, opt_function
);
1388 ERR("Unable to parse function probe options");
1393 case LTTNG_EVENT_SYSCALL
:
1394 ev
->type
= LTTNG_EVENT_SYSCALL
;
1397 ret
= CMD_UNDEFINED
;
1401 /* kernel loglevels not implemented */
1402 ev
->loglevel_type
= LTTNG_EVENT_LOGLEVEL_ALL
;
1403 } else if (opt_userspace
) { /* User-space tracer action */
1404 DBG("Enabling UST event %s for channel %s, loglevel %s", event_name
,
1405 print_channel_name(channel_name
), opt_loglevel
? : "<all>");
1407 switch (opt_event_type
) {
1408 case LTTNG_EVENT_ALL
: /* Default behavior is tracepoint */
1410 case LTTNG_EVENT_TRACEPOINT
:
1411 /* Copy name and type of the event */
1412 ev
->type
= LTTNG_EVENT_TRACEPOINT
;
1413 strncpy(ev
->name
, event_name
, LTTNG_SYMBOL_NAME_LEN
);
1414 ev
->name
[LTTNG_SYMBOL_NAME_LEN
- 1] = '\0';
1416 case LTTNG_EVENT_PROBE
:
1417 case LTTNG_EVENT_FUNCTION
:
1418 case LTTNG_EVENT_SYSCALL
:
1419 case LTTNG_EVENT_USERSPACE_PROBE
:
1421 ERR("Event type not available for user-space tracing");
1422 ret
= CMD_UNSUPPORTED
;
1428 if (opt_event_type
!= LTTNG_EVENT_ALL
&& opt_event_type
!= LTTNG_EVENT_TRACEPOINT
) {
1429 ERR("Exclusion option can only be used with tracepoint events");
1433 /* Free previously allocated items */
1434 strutils_free_null_terminated_array_of_strings(
1436 exclusion_list
= NULL
;
1437 ret
= create_exclusion_list_and_validate(
1438 event_name
, opt_exclude
,
1445 warn_on_truncated_exclusion_names(
1446 exclusion_list
, &warn
);
1449 ev
->loglevel_type
= opt_loglevel_type
;
1451 ev
->loglevel
= loglevel_str_to_value(opt_loglevel
);
1452 if (ev
->loglevel
== -1) {
1453 ERR("Unknown loglevel %s", opt_loglevel
);
1454 ret
= -LTTNG_ERR_INVALID
;
1460 } else if (opt_jul
|| opt_log4j
|| opt_python
) {
1461 if (opt_event_type
!= LTTNG_EVENT_ALL
&&
1462 opt_event_type
!= LTTNG_EVENT_TRACEPOINT
) {
1463 ERR("Event type not supported for domain.");
1464 ret
= CMD_UNSUPPORTED
;
1468 ev
->loglevel_type
= opt_loglevel_type
;
1471 ev
->loglevel
= loglevel_jul_str_to_value(opt_loglevel
);
1472 } else if (opt_log4j
) {
1473 ev
->loglevel
= loglevel_log4j_str_to_value(opt_loglevel
);
1474 } else if (opt_python
) {
1475 ev
->loglevel
= loglevel_python_str_to_value(opt_loglevel
);
1477 if (ev
->loglevel
== -1) {
1478 ERR("Unknown loglevel %s", opt_loglevel
);
1479 ret
= -LTTNG_ERR_INVALID
;
1484 ev
->loglevel
= LTTNG_LOGLEVEL_JUL_ALL
;
1485 } else if (opt_log4j
) {
1486 ev
->loglevel
= LTTNG_LOGLEVEL_LOG4J_ALL
;
1487 } else if (opt_python
) {
1488 ev
->loglevel
= LTTNG_LOGLEVEL_PYTHON_DEBUG
;
1491 ev
->type
= LTTNG_EVENT_TRACEPOINT
;
1492 strncpy(ev
->name
, event_name
, LTTNG_SYMBOL_NAME_LEN
);
1493 ev
->name
[LTTNG_SYMBOL_NAME_LEN
- 1] = '\0';
1499 char *exclusion_string
;
1501 command_ret
= lttng_enable_event_with_exclusions(handle
,
1504 exclusion_list
? strutils_array_of_strings_len(exclusion_list
) : 0,
1506 exclusion_string
= print_exclusions(exclusion_list
);
1507 if (!exclusion_string
) {
1508 PERROR("Cannot allocate exclusion_string");
1512 if (command_ret
< 0) {
1513 /* Turn ret to positive value to handle the positive error code */
1514 switch (-command_ret
) {
1515 case LTTNG_ERR_KERN_EVENT_EXIST
:
1516 WARN("Kernel event %s%s already enabled (channel %s, session %s)",
1519 print_channel_name(channel_name
), session_name
);
1522 case LTTNG_ERR_TRACE_ALREADY_STARTED
:
1524 const char *msg
= "The command tried to enable an event in a new domain for a session that has already been started once.";
1525 ERR("Event %s%s: %s (channel %s, session %s)", event_name
,
1528 print_channel_name(channel_name
),
1533 case LTTNG_ERR_SDT_PROBE_SEMAPHORE
:
1534 ERR("SDT probes %s guarded by semaphores are not supported (channel %s, session %s)",
1535 event_name
, print_channel_name(channel_name
),
1540 ERR("Event %s%s: %s (channel %s, session %s)", event_name
,
1542 lttng_strerror(command_ret
),
1543 command_ret
== -LTTNG_ERR_NEED_CHANNEL_NAME
1544 ? print_raw_channel_name(channel_name
)
1545 : print_channel_name(channel_name
),
1550 error_holder
= command_ret
;
1553 case LTTNG_DOMAIN_KERNEL
:
1554 case LTTNG_DOMAIN_UST
:
1555 MSG("%s event %s%s created in channel %s",
1556 get_domain_str(dom
.type
),
1559 print_channel_name(channel_name
));
1561 case LTTNG_DOMAIN_JUL
:
1562 case LTTNG_DOMAIN_LOG4J
:
1563 case LTTNG_DOMAIN_PYTHON
:
1565 * Don't print the default channel
1566 * name for agent domains.
1568 MSG("%s event %s%s enabled",
1569 get_domain_str(dom
.type
),
1577 free(exclusion_string
);
1581 char *exclusion_string
;
1583 /* Filter present */
1586 command_ret
= lttng_enable_event_with_exclusions(handle
, ev
, channel_name
,
1588 exclusion_list
? strutils_array_of_strings_len(exclusion_list
) : 0,
1590 exclusion_string
= print_exclusions(exclusion_list
);
1591 if (!exclusion_string
) {
1592 PERROR("Cannot allocate exclusion_string");
1596 if (command_ret
< 0) {
1597 switch (-command_ret
) {
1598 case LTTNG_ERR_FILTER_EXIST
:
1599 WARN("Filter on event %s%s is already enabled"
1600 " (channel %s, session %s)",
1603 print_channel_name(channel_name
), session_name
);
1606 case LTTNG_ERR_TRACE_ALREADY_STARTED
:
1608 const char *msg
= "The command tried to enable an event in a new domain for a session that has already been started once.";
1609 ERR("Event %s%s: %s (channel %s, session %s, filter \'%s\')", ev
->name
,
1612 print_channel_name(channel_name
),
1613 session_name
, opt_filter
);
1618 ERR("Event %s%s: %s (channel %s, session %s, filter \'%s\')", ev
->name
,
1620 lttng_strerror(command_ret
),
1621 command_ret
== -LTTNG_ERR_NEED_CHANNEL_NAME
1622 ? print_raw_channel_name(channel_name
)
1623 : print_channel_name(channel_name
),
1624 session_name
, opt_filter
);
1628 error_holder
= command_ret
;
1631 MSG("Event %s%s: Filter '%s' successfully set",
1632 event_name
, exclusion_string
,
1635 free(exclusion_string
);
1646 ret
= mi_lttng_event(writer
, ev
, 1, handle
->domain
.type
);
1652 /* print exclusion */
1653 ret
= mi_print_exclusion(exclusion_list
);
1660 ret
= mi_lttng_writer_write_element_bool(writer
,
1661 mi_lttng_element_command_success
, success
);
1667 /* Close event element */
1668 ret
= mi_lttng_writer_close_element(writer
);
1676 event_name
= strtok(NULL
, ",");
1677 /* Reset warn, error and success */
1684 /* Close events element */
1685 ret
= mi_lttng_writer_close_element(writer
);
1698 lttng_destroy_handle(handle
);
1699 strutils_free_null_terminated_array_of_strings(exclusion_list
);
1701 /* Overwrite ret with error_holder if there was an actual error with
1702 * enabling an event.
1704 ret
= error_holder
? error_holder
: ret
;
1706 lttng_event_destroy(ev
);
1711 * Add event to trace session
1713 int cmd_enable_events(int argc
, const char **argv
)
1715 int opt
, ret
= CMD_SUCCESS
, command_ret
= CMD_SUCCESS
, success
= 1;
1716 static poptContext pc
;
1717 char *session_name
= NULL
;
1718 const char *leftover
= NULL
;
1719 int event_type
= -1;
1721 pc
= poptGetContext(NULL
, argc
, argv
, long_options
, 0);
1722 poptReadDefaultConfig(pc
, 0);
1724 /* Default event type */
1725 opt_event_type
= LTTNG_EVENT_ALL
;
1727 while ((opt
= poptGetNextOpt(pc
)) != -1) {
1732 case OPT_TRACEPOINT
:
1733 opt_event_type
= LTTNG_EVENT_TRACEPOINT
;
1736 opt_event_type
= LTTNG_EVENT_PROBE
;
1738 case OPT_USERSPACE_PROBE
:
1739 opt_event_type
= LTTNG_EVENT_USERSPACE_PROBE
;
1742 opt_event_type
= LTTNG_EVENT_FUNCTION
;
1745 opt_event_type
= LTTNG_EVENT_SYSCALL
;
1751 opt_loglevel_type
= LTTNG_EVENT_LOGLEVEL_RANGE
;
1752 opt_loglevel
= poptGetOptArg(pc
);
1754 case OPT_LOGLEVEL_ONLY
:
1755 opt_loglevel_type
= LTTNG_EVENT_LOGLEVEL_SINGLE
;
1756 opt_loglevel
= poptGetOptArg(pc
);
1758 case OPT_LIST_OPTIONS
:
1759 list_cmd_options(stdout
, long_options
);
1766 ret
= CMD_UNDEFINED
;
1770 /* Validate event type. Multiple event type are not supported. */
1771 if (event_type
== -1) {
1772 event_type
= opt_event_type
;
1774 if (event_type
!= opt_event_type
) {
1775 ERR("Multiple event type not supported.");
1782 ret
= print_missing_or_multiple_domains(
1783 opt_kernel
+ opt_userspace
+ opt_jul
+ opt_log4j
+ opt_python
);
1791 writer
= mi_lttng_writer_create(fileno(stdout
), lttng_opt_mi
);
1793 ret
= -LTTNG_ERR_NOMEM
;
1797 /* Open command element */
1798 ret
= mi_lttng_writer_command_open(writer
,
1799 mi_lttng_element_command_enable_event
);
1805 /* Open output element */
1806 ret
= mi_lttng_writer_open_element(writer
,
1807 mi_lttng_element_command_output
);
1814 opt_event_list
= (char*) poptGetArg(pc
);
1815 if (opt_event_list
== NULL
&& opt_enable_all
== 0) {
1816 ERR("Missing event name(s).\n");
1821 leftover
= poptGetArg(pc
);
1823 ERR("Unknown argument: %s", leftover
);
1828 if (!opt_session_name
) {
1829 session_name
= get_session_name();
1830 if (session_name
== NULL
) {
1831 command_ret
= CMD_ERROR
;
1836 session_name
= opt_session_name
;
1839 command_ret
= enable_events(session_name
);
1848 /* Close output element */
1849 ret
= mi_lttng_writer_close_element(writer
);
1855 ret
= mi_lttng_writer_write_element_bool(writer
,
1856 mi_lttng_element_command_success
, success
);
1862 /* Command element close */
1863 ret
= mi_lttng_writer_command_close(writer
);
1872 if (writer
&& mi_lttng_writer_destroy(writer
)) {
1873 /* Preserve original error code */
1874 ret
= ret
? ret
: LTTNG_ERR_MI_IO_FAIL
;
1877 if (opt_session_name
== NULL
) {
1881 /* Overwrite ret if an error occurred in enable_events */
1882 ret
= command_ret
? command_ret
: ret
;
1884 poptFreeContext(pc
);