*/
#define _GNU_SOURCE
+#include <assert.h>
#include <popt.h>
#include <stdio.h>
#include <stdlib.h>
#include "../command.h"
#include <src/common/sessiond-comm/sessiond-comm.h>
+#if (LTTNG_SYMBOL_NAME_LEN == 256)
+#define LTTNG_SYMBOL_NAME_LEN_SCANF_IS_A_BROKEN_API "255"
+#endif
+
static char *opt_event_list;
static int opt_event_type;
static const char *opt_loglevel;
fprintf(ofp, " --syscall System call event\n");
fprintf(ofp, "\n");
fprintf(ofp, " --loglevel name\n");
- fprintf(ofp, " Tracepoint loglevel range from 0 to loglevel\n");
+ fprintf(ofp, " Tracepoint loglevel range from 0 to loglevel.\n");
+ fprintf(ofp, " For JUL domain, see the table below for the range values.\n");
fprintf(ofp, " --loglevel-only name\n");
fprintf(ofp, " Tracepoint loglevel (only this loglevel)\n");
fprintf(ofp, "\n");
fprintf(ofp, " TRACE_DEBUG_LINE = 13\n");
fprintf(ofp, " TRACE_DEBUG = 14\n");
fprintf(ofp, " (shortcuts such as \"system\" are allowed)\n");
+ fprintf(ofp, "\n");
+ fprintf(ofp, " Available JUL domain loglevels:\n");
+ fprintf(ofp, " JUL_OFF = INT32_MAX\n");
+ fprintf(ofp, " JUL_SEVERE = %d\n", LTTNG_LOGLEVEL_JUL_SEVERE);
+ fprintf(ofp, " JUL_WARNING = %d\n", LTTNG_LOGLEVEL_JUL_WARNING);
+ fprintf(ofp, " JUL_INFO = %d\n", LTTNG_LOGLEVEL_JUL_INFO);
+ fprintf(ofp, " JUL_CONFIG = %d\n", LTTNG_LOGLEVEL_JUL_CONFIG);
+ fprintf(ofp, " JUL_FINE = %d\n", LTTNG_LOGLEVEL_JUL_FINE);
+ fprintf(ofp, " JUL_FINER = %d\n", LTTNG_LOGLEVEL_JUL_FINER);
+ fprintf(ofp, " JUL_FINEST = %d\n", LTTNG_LOGLEVEL_JUL_FINEST);
+ fprintf(ofp, " JUL_ALL = INT32_MIN\n");
+ fprintf(ofp, " (shortcuts such as \"severe\" are allowed)\n");
+ fprintf(ofp, "\n");
fprintf(ofp, " -f, --filter \'expression\'\n");
fprintf(ofp, " Filter expression on event fields and context.\n");
fprintf(ofp, " Event recording depends on evaluation.\n");
{
int ret;
char s_hex[19];
+#define S_HEX_LEN_SCANF_IS_A_BROKEN_API "18" /* 18 is (19 - 1) (\0 is extra) */
char name[LTTNG_SYMBOL_NAME_LEN];
if (opt == NULL) {
}
/* Check for symbol+offset */
- ret = sscanf(opt, "%[^'+']+%s", name, s_hex);
+ ret = sscanf(opt, "%" LTTNG_SYMBOL_NAME_LEN_SCANF_IS_A_BROKEN_API
+ "[^'+']+%" S_HEX_LEN_SCANF_IS_A_BROKEN_API "s", name, s_hex);
if (ret == 2) {
strncpy(ev->attr.probe.symbol_name, name, LTTNG_SYMBOL_NAME_LEN);
ev->attr.probe.symbol_name[LTTNG_SYMBOL_NAME_LEN - 1] = '\0';
/* Check for symbol */
if (isalpha(name[0])) {
- ret = sscanf(opt, "%s", name);
+ ret = sscanf(opt, "%" LTTNG_SYMBOL_NAME_LEN_SCANF_IS_A_BROKEN_API "s",
+ name);
if (ret == 1) {
strncpy(ev->attr.probe.symbol_name, name, LTTNG_SYMBOL_NAME_LEN);
ev->attr.probe.symbol_name[LTTNG_SYMBOL_NAME_LEN - 1] = '\0';
}
/* Check for address */
- ret = sscanf(opt, "%s", s_hex);
+ ret = sscanf(opt, "%" S_HEX_LEN_SCANF_IS_A_BROKEN_API "s", s_hex);
if (ret > 0) {
if (*s_hex == '\0') {
ERR("Invalid probe address %s", s_hex);
return ret;
}
+/*
+ * Maps JUL loglevel from string to value
+ */
+static int loglevel_jul_str_to_value(const char *inputstr)
+{
+ int i = 0;
+ char str[LTTNG_SYMBOL_NAME_LEN];
+
+ /*
+ * Loop up to LTTNG_SYMBOL_NAME_LEN minus one because the NULL bytes is
+ * added at the end of the loop so a the upper bound we avoid the overflow.
+ */
+ while (i < (LTTNG_SYMBOL_NAME_LEN - 1) && inputstr[i] != '\0') {
+ str[i] = toupper(inputstr[i]);
+ i++;
+ }
+ str[i] = '\0';
+
+ if (!strcmp(str, "JUL_OFF") || !strcmp(str, "OFF")) {
+ return LTTNG_LOGLEVEL_JUL_OFF;
+ } else if (!strcmp(str, "JUL_SEVERE") || !strcmp(str, "SEVERE")) {
+ return LTTNG_LOGLEVEL_JUL_SEVERE;
+ } else if (!strcmp(str, "JUL_WARNING") || !strcmp(str, "WARNING")) {
+ return LTTNG_LOGLEVEL_JUL_WARNING;
+ } else if (!strcmp(str, "JUL_INFO") || !strcmp(str, "INFO")) {
+ return LTTNG_LOGLEVEL_JUL_INFO;
+ } else if (!strcmp(str, "JUL_CONFIG") || !strcmp(str, "CONFIG")) {
+ return LTTNG_LOGLEVEL_JUL_CONFIG;
+ } else if (!strcmp(str, "JUL_FINE") || !strcmp(str, "FINE")) {
+ return LTTNG_LOGLEVEL_JUL_FINE;
+ } else if (!strcmp(str, "JUL_FINER") || !strcmp(str, "FINER")) {
+ return LTTNG_LOGLEVEL_JUL_FINER;
+ } else if (!strcmp(str, "JUL_FINEST") || !strcmp(str, "FINEST")) {
+ return LTTNG_LOGLEVEL_JUL_FINEST;
+ } else if (!strcmp(str, "JUL_ALL") || !strcmp(str, "ALL")) {
+ return LTTNG_LOGLEVEL_JUL_ALL;
+ } else {
+ return -1;
+ }
+}
+
/*
* Maps loglevel from string to value
*/
return name ? : "<default>";
}
+/*
+ * Return allocated string for pretty-printing exclusion names.
+ */
+static
+char *print_exclusions(int count, char **names)
+{
+ int length = 0;
+ int i;
+ const char *preamble = " excluding ";
+ char *ret;
+
+ if (count == 0) {
+ return strdup("");
+ }
+
+ /* calculate total required length */
+ for (i = 0; i < count; i++) {
+ length += strlen(names[i]) + 1;
+ }
+
+ /* add length of preamble + one for NUL - one for last (missing) comma */
+ length += strlen(preamble);
+ ret = malloc(length);
+ strncpy(ret, preamble, length);
+ for (i = 0; i < count; i++) {
+ strcat(ret, names[i]);
+ if (i != count - 1) {
+ strcat(ret, ",");
+ }
+ }
+ return ret;
+}
+
/*
* Compare list of exclusions against an event name.
* Return a list of legal exclusion names.
goto error;
}
+ if (opt_kernel && opt_exclude) {
+ ERR("Event name exclusions are not yet implemented for kernel events");
+ ret = CMD_ERROR;
+ goto error;
+ }
+
channel_name = opt_channel_name;
handle = lttng_create_handle(session_name, &dom);
strcpy(ev.name, "*");
ev.loglevel_type = opt_loglevel_type;
if (opt_loglevel) {
- ev.loglevel = loglevel_str_to_value(opt_loglevel);
+ assert(opt_userspace || opt_jul);
+ if (opt_userspace) {
+ ev.loglevel = loglevel_str_to_value(opt_loglevel);
+ } else if (opt_jul) {
+ ev.loglevel = loglevel_jul_str_to_value(opt_loglevel);
+ }
if (ev.loglevel == -1) {
ERR("Unknown loglevel %s", opt_loglevel);
ret = -LTTNG_ERR_INVALID;
goto error;
}
} else {
- ev.loglevel = -1;
+ assert(opt_userspace || opt_jul);
+ if (opt_userspace) {
+ ev.loglevel = -1;
+ } else if (opt_jul) {
+ ev.loglevel = LTTNG_LOGLEVEL_JUL_ALL;
+ }
}
}
switch (opt_event_type) {
case LTTNG_EVENT_TRACEPOINT:
if (opt_loglevel && dom.type != LTTNG_DOMAIN_KERNEL) {
- MSG("All %s tracepoints are enabled in channel %s for loglevel %s",
+ char *exclusion_string = print_exclusions(exclusion_count, exclusion_list);
+ MSG("All %s tracepoints%s are enabled in channel %s for loglevel %s",
get_domain_str(dom.type),
+ exclusion_string,
print_channel_name(channel_name),
opt_loglevel);
+ free(exclusion_string);
} else {
- MSG("All %s tracepoints are enabled in channel %s",
+ char *exclusion_string = print_exclusions(exclusion_count, exclusion_list);
+ MSG("All %s tracepoints%s are enabled in channel %s",
get_domain_str(dom.type),
+ exclusion_string,
print_channel_name(channel_name));
+ free(exclusion_string);
}
break;
case LTTNG_EVENT_SYSCALL:
break;
case LTTNG_EVENT_ALL:
if (opt_loglevel && dom.type != LTTNG_DOMAIN_KERNEL) {
- MSG("All %s events are enabled in channel %s for loglevel %s",
+ char *exclusion_string = print_exclusions(exclusion_count, exclusion_list);
+ MSG("All %s events%s are enabled in channel %s for loglevel %s",
get_domain_str(dom.type),
+ exclusion_string,
print_channel_name(channel_name),
opt_loglevel);
+ free(exclusion_string);
} else {
- MSG("All %s events are enabled in channel %s",
+ char *exclusion_string = print_exclusions(exclusion_count, exclusion_list);
+ MSG("All %s events%s are enabled in channel %s",
get_domain_str(dom.type),
+ exclusion_string,
print_channel_name(channel_name));
+ free(exclusion_string);
}
break;
default:
}
if (opt_exclude) {
+ if (opt_event_type != LTTNG_EVENT_ALL && opt_event_type != LTTNG_EVENT_TRACEPOINT) {
+ ERR("Exclusion option can only be used with tracepoint events");
+ ret = CMD_ERROR;
+ goto error;
+ }
/* Free previously allocated items */
if (exclusion_list != NULL) {
while (exclusion_count--) {
ret = CMD_UNSUPPORTED;
goto error;
}
+
+ ev.loglevel_type = opt_loglevel_type;
+ if (opt_loglevel) {
+ ev.loglevel = loglevel_jul_str_to_value(opt_loglevel);
+ if (ev.loglevel == -1) {
+ ERR("Unknown loglevel %s", opt_loglevel);
+ ret = -LTTNG_ERR_INVALID;
+ goto error;
+ }
+ } else {
+ ev.loglevel = LTTNG_LOGLEVEL_JUL_ALL;
+ }
ev.type = LTTNG_EVENT_TRACEPOINT;
strncpy(ev.name, event_name, LTTNG_SYMBOL_NAME_LEN);
ev.name[LTTNG_SYMBOL_NAME_LEN - 1] = '\0';
}
if (!opt_filter) {
+ char *exclusion_string;
+
ret = lttng_enable_event_with_exclusions(handle,
&ev, channel_name,
NULL, exclusion_count, exclusion_list);
+ exclusion_string = print_exclusions(exclusion_count, exclusion_list);
if (ret < 0) {
/* Turn ret to positive value to handle the positive error code */
switch (-ret) {
case LTTNG_ERR_KERN_EVENT_EXIST:
- WARN("Kernel event %s already enabled (channel %s, session %s)",
+ WARN("Kernel event %s%s already enabled (channel %s, session %s)",
event_name,
+ exclusion_string,
print_channel_name(channel_name), session_name);
break;
default:
- ERR("Event %s: %s (channel %s, session %s)", event_name,
+ ERR("Event %s%s: %s (channel %s, session %s)", event_name,
+ exclusion_string,
lttng_strerror(ret),
ret == -LTTNG_ERR_NEED_CHANNEL_NAME
? print_raw_channel_name(channel_name)
}
warn = 1;
} else {
- MSG("%s event %s created in channel %s",
+ MSG("%s event %s%s created in channel %s",
get_domain_str(dom.type), event_name,
+ exclusion_string,
print_channel_name(channel_name));
}
+ free(exclusion_string);
}
if (opt_filter) {
+ char *exclusion_string;
+
ret = lttng_enable_event_with_exclusions(handle, &ev, channel_name,
opt_filter, exclusion_count, exclusion_list);
+ exclusion_string = print_exclusions(exclusion_count, exclusion_list);
+
if (ret < 0) {
switch (-ret) {
case LTTNG_ERR_FILTER_EXIST:
- WARN("Filter on event %s is already enabled"
+ WARN("Filter on event %s%s is already enabled"
" (channel %s, session %s)",
event_name,
+ exclusion_string,
print_channel_name(channel_name), session_name);
break;
default:
- ERR("Event %s: %s (channel %s, session %s, filter \'%s\')", ev.name,
+ ERR("Event %s%s: %s (channel %s, session %s, filter \'%s\')", ev.name,
+ exclusion_string,
lttng_strerror(ret),
ret == -LTTNG_ERR_NEED_CHANNEL_NAME
? print_raw_channel_name(channel_name)
session_name, opt_filter);
break;
}
+ free(exclusion_string);
goto error;
} else {
- MSG("Filter '%s' successfully set", opt_filter);
+ MSG("Event %s%s: Filter '%s' successfully set",
+ event_name, exclusion_string,
+ opt_filter);
}
+ free(exclusion_string);
}
/* Next event */