OPT_LOGLEVEL_ONLY,
OPT_DOMAIN,
-
- OPT_FUNCTION,
- OPT_PROBE,
- OPT_USERSPACE_PROBE,
- OPT_SYSCALL,
- OPT_TRACEPOINT,
+ OPT_TYPE,
+ OPT_LOCATION,
OPT_MAX_SIZE,
OPT_DATA_URL,
{ OPT_EVENT_NAME, 'E', "event-name", true },
{ OPT_DOMAIN, 'd', "domain", true },
-
- /* Event rule types */
- { OPT_FUNCTION, '\0', "function", true },
- { OPT_PROBE, '\0', "probe", true },
- { OPT_USERSPACE_PROBE, '\0', "userspace-probe", true },
- { OPT_SYSCALL, '\0', "syscall" },
- { OPT_TRACEPOINT, '\0', "tracepoint" },
+ { OPT_TYPE, 't', "type", true },
+ { OPT_LOCATION, 'L', "location", true },
/* Capture descriptor */
{ OPT_CAPTURE, '\0', "capture", true },
}
static
-bool assign_event_rule_type(enum lttng_event_rule_type *dest,
- enum lttng_event_rule_type src)
+bool assign_event_rule_type(enum lttng_event_rule_type *dest, const char *arg)
{
bool ret;
- if (*dest == LTTNG_EVENT_RULE_TYPE_UNKNOWN || *dest == src) {
- *dest = src;
- ret = true;
+ if (*dest != LTTNG_EVENT_RULE_TYPE_UNKNOWN) {
+ ERR("More than one `--type` was specified.");
+ goto error;
+ }
+
+ if (strcmp(arg, "tracepoint") == 0 || strcmp(arg, "logging") == 0) {
+ *dest = LTTNG_EVENT_RULE_TYPE_TRACEPOINT;
+ } else if (strcmp (arg, "kprobe") == 0 || strcmp(arg, "kernel-probe") == 0) {
+ *dest = LTTNG_EVENT_RULE_TYPE_KERNEL_PROBE;
+ } else if (strcmp (arg, "uprobe") == 0 || strcmp(arg, "userspace-probe") == 0) {
+ *dest = LTTNG_EVENT_RULE_TYPE_USERSPACE_PROBE;
+ } else if (strcmp (arg, "function") == 0) {
+ *dest = LTTNG_EVENT_RULE_TYPE_KERNEL_FUNCTION;
+ } else if (strcmp (arg, "syscall") == 0) {
+ *dest = LTTNG_EVENT_RULE_TYPE_SYSCALL;
} else {
- ERR("Multiple event types specified.");
- ret = false;
+ ERR("Invalid `--type` value: %s", arg);
+ goto error;
}
+ ret = true;
+ goto end;
+
+error:
+ ret = false;
+
+end:
return ret;
}
char *exclude_names = NULL;
char **exclusion_list = NULL;
- /* Holds the argument of --probe / --userspace-probe. */
- char *probe_source = NULL;
- char *probe_event_name = NULL;
+ /* For userspace / kernel probe and function. */
+ char *location = NULL;
+ char *event_name = NULL;
/* Filter. */
char *filter = NULL;
switch (item_opt->descr->id) {
/* Domains. */
case OPT_DOMAIN:
- if (!assign_domain_type(&domain_type, item_opt->arg)) {
+ if (!assign_domain_type(&domain_type,
+ item_opt->arg)) {
goto error;
}
break;
-
- /* Event rule types */
- case OPT_FUNCTION:
+ case OPT_TYPE:
if (!assign_event_rule_type(&event_rule_type,
- LTTNG_EVENT_RULE_TYPE_KERNEL_FUNCTION)) {
+ item_opt->arg)) {
goto error;
}
break;
- case OPT_PROBE:
- if (!assign_event_rule_type(&event_rule_type,
- LTTNG_EVENT_RULE_TYPE_KERNEL_PROBE)) {
- goto error;
- }
-
- if (!assign_string(&probe_source, item_opt->arg,
- "--probe")) {
- goto error;
- }
-
- break;
- case OPT_USERSPACE_PROBE:
- if (!assign_event_rule_type(&event_rule_type,
- LTTNG_EVENT_RULE_TYPE_USERSPACE_PROBE)) {
- goto error;
- }
-
- if (!assign_string(&probe_source, item_opt->arg,
- "--userspace-probe")) {
+ case OPT_LOCATION:
+ if (!assign_string(&location,
+ item_opt->arg,
+ "--location/-L")) {
goto error;
}
break;
case OPT_EVENT_NAME:
- if (!assign_string(&probe_event_name,
+ if (!assign_string(&event_name,
item_opt->arg,
"--event-name/-E")) {
goto error;
}
- break;
- case OPT_SYSCALL:
- if (!assign_event_rule_type(&event_rule_type,
- LTTNG_EVENT_RULE_TYPE_SYSCALL)) {
- goto error;
- }
-
- break;
- case OPT_TRACEPOINT:
- if (!assign_event_rule_type(&event_rule_type,
- LTTNG_EVENT_RULE_TYPE_TRACEPOINT)) {
- goto error;
- }
-
break;
case OPT_FILTER:
if (!assign_string(&filter, item_opt->arg,
}
/*
+ * Option --location is only applicable to (and mandatory for) event
+ * rules of type {k,u}probe and function.
+ *
* Option --event-name is only applicable to event rules of type probe.
- * If omitted, it defaults to the probe location.
+ * If omitted, it defaults to the location.
*/
switch (event_rule_type) {
case LTTNG_EVENT_RULE_TYPE_KERNEL_PROBE:
case LTTNG_EVENT_RULE_TYPE_USERSPACE_PROBE:
- if (!probe_event_name) {
- probe_event_name = strdup(probe_source);
+ case LTTNG_EVENT_RULE_TYPE_KERNEL_FUNCTION:
+ if (!location) {
+ ERR("Event rule of type %s requires a --location.",
+ lttng_event_rule_type_str(event_rule_type));
+ goto error;
+ }
+
+ if (!event_name) {
+ event_name = strdup(location);
}
break;
default:
- if (probe_event_name) {
+ if (location) {
+ ERR("Can't use --location with %s event rules.",
+ lttng_event_rule_type_str(event_rule_type));
+ goto error;
+ }
+
+ if (event_name) {
ERR("Can't use --event-name with %s event rules.",
lttng_event_rule_type_str(
event_rule_type));
enum lttng_event_rule_status event_rule_status;
ret = parse_kernel_probe_opts(
- probe_source, &kernel_probe_location);
+ location, &kernel_probe_location);
if (ret) {
ERR("Failed to parse kernel probe location.");
goto error;
event_rule_status =
lttng_event_rule_kernel_probe_set_event_name(
- res.er, probe_event_name);
+ res.er, event_name);
if (event_rule_status != LTTNG_EVENT_RULE_STATUS_OK) {
ERR("Failed to set kprobe event rule's name to '%s'.",
- probe_event_name);
+ event_name);
goto error;
}
enum lttng_event_rule_status event_rule_status;
ret = parse_userspace_probe_opts(
- probe_source, &userspace_probe_location);
+ location, &userspace_probe_location);
if (ret) {
ERR("Failed to parse user space probe location.");
goto error;
event_rule_status =
lttng_event_rule_userspace_probe_set_event_name(
- res.er, probe_event_name);
+ res.er, event_name);
if (event_rule_status != LTTNG_EVENT_RULE_STATUS_OK) {
ERR("Failed to set user space probe event rule's name to '%s'.",
- probe_event_name);
+ event_name);
goto error;
}
free(name);
free(exclude_names);
free(loglevel_str);
- free(probe_source);
- free(probe_event_name);
+ free(location);
+ free(event_name);
strutils_free_null_terminated_array_of_strings(exclusion_list);
lttng_kernel_probe_location_destroy(kernel_probe_location);
# shellcheck source=../../../utils/utils.sh
source "$TESTDIR/utils/utils.sh"
-plan_tests 228
+plan_tests 252
FULL_LTTNG_BIN="${TESTDIR}/../src/bin/lttng/${LTTNG_BIN}"
--action rotate-session my_session \
--rate-policy=once-after:55
-skip $ist_root "non-root user: skipping kprobe tests" 9 || {
- test_success "--condition event-rule-matches probe by symbol" \
- --condition event-rule-matches --domain=kernel --probe=lttng_channel_enable --event-name=my_channel_enable \
- --action notify
-
- channel_enable_addr=$(grep ' t lttng_channel_enable\s\[lttng_tracer\]$' /proc/kallsyms | cut -f 1 -d ' ')
- channel_disable_addr=$(grep ' t lttng_channel_disable\s\[lttng_tracer\]$' /proc/kallsyms | cut -f 1 -d ' ')
-
- # We need to find a valid offset.
- base_symbol=""
- offset=0
- if [[ 0x$channel_enable_addr -lt 0x$channel_disable_addr ]]; then
- base_symbol="lttng_channel_enable"
- offset=$(( 0x$channel_disable_addr - 0x$channel_enable_addr ))
- else
- base_symbol="lttng_channel_disable"
- offset=$(( 0x$channel_enable_addr - 0x$channel_disable_addr ))
- fi
-
- offset_hex="0x$(printf '%x' $offset)"
-
- test_success "--condition event-rule-matches probe by symbol with offset" \
- --condition event-rule-matches --domain=kernel --probe="${base_symbol}+${offset_hex}" --event-name=my_$base_symbol \
- --action notify
-
- test_success "--condition event-rule-matches probe by address" \
- --condition event-rule-matches --domain=kernel "--probe=0x${channel_enable_addr}" --event-name=my_channel_enable \
- --action notify
+skip $ist_root "non-root user: skipping kprobe tests" 18 || {
+ for type in kprobe kernel-probe; do
+ test_success "--condition event-rule-matches probe by symbol" \
+ --condition event-rule-matches --domain=kernel --type=$type --location=lttng_channel_enable --event-name=my_channel_enable \
+ --action notify
+
+ channel_enable_addr=$(grep ' t lttng_channel_enable\s\[lttng_tracer\]$' /proc/kallsyms | cut -f 1 -d ' ')
+ channel_disable_addr=$(grep ' t lttng_channel_disable\s\[lttng_tracer\]$' /proc/kallsyms | cut -f 1 -d ' ')
+
+ # We need to find a valid offset.
+ base_symbol=""
+ offset=0
+ if [[ 0x$channel_enable_addr -lt 0x$channel_disable_addr ]]; then
+ base_symbol="lttng_channel_enable"
+ offset=$(( 0x$channel_disable_addr - 0x$channel_enable_addr ))
+ else
+ base_symbol="lttng_channel_disable"
+ offset=$(( 0x$channel_enable_addr - 0x$channel_disable_addr ))
+ fi
+
+ offset_hex="0x$(printf '%x' $offset)"
+
+ test_success "--condition event-rule-matches probe by symbol with offset" \
+ --condition event-rule-matches --domain=kernel --type=$type --location="${base_symbol}+${offset_hex}" --event-name=my_$base_symbol \
+ --action notify
+
+ test_success "--condition event-rule-matches probe by address" \
+ --condition event-rule-matches --domain=kernel --type=$type --location="0x${channel_enable_addr}" --event-name=my_channel_enable \
+ --action notify
+ done
}
-skip $ist_root "non-root user: skipping uprobe tests" 6 || {
- test_success "--condition event-rule-matches uprobe" \
- --condition event-rule-matches --domain=kernel --userspace-probe=${uprobe_elf_binary}:test_function --event-name=ma-probe \
- --action notify
+skip $ist_root "non-root user: skipping uprobe tests" 12 || {
+ for type in uprobe userspace-probe; do
+ test_success "--condition event-rule-matches uprobe" \
+ --condition event-rule-matches --domain=kernel --type=$type --location=${uprobe_elf_binary}:test_function --event-name=ma-probe \
+ --action notify
- test_success "--condition event-rule-matches uprobe with elf prefix" \
- --condition event-rule-matches --domain=kernel --userspace-probe=elf:${uprobe_elf_binary}:test_function --event-name=ma-probe-2 \
- --action notify
+ test_success "--condition event-rule-matches uprobe with elf prefix" \
+ --condition event-rule-matches --domain=kernel --type=$type --location=elf:${uprobe_elf_binary}:test_function --event-name=ma-probe-2 \
+ --action notify
+ done
}
skip $ist_root "non-root user: skipping syscall tests" 9 || {
test_success "--condition event-rule-matches one syscall" \
- --condition event-rule-matches --domain=kernel --syscall --name=open \
+ --condition event-rule-matches --domain=kernel --type=syscall --name=open \
--action notify
test_success "--condition event-rule-matches all syscalls" \
- --condition event-rule-matches --domain=kernel --syscall \
+ --condition event-rule-matches --domain=kernel --type=syscall \
--action notify
test_success "--condition event-rule-matches one syscall with filter" \
- --condition event-rule-matches --domain=kernel --syscall --filter 'a > 2' --name=open \
+ --condition event-rule-matches --domain=kernel --type=syscall --filter 'a > 2' --name=open \
--action notify
}
"Error: More than one \`--domain\` was specified." \
--condition event-rule-matches --domain=user --domain=kernel
-test_failure "--condition event-rule-matches: --name with --probe" \
- "Error: Can't use --name with probe event rules." \
- --condition event-rule-matches --probe=do_sys_open --name='hello'
+for type in kprobe kernel-probe; do
+ test_failure "--condition event-rule-matches: --name with --type=$type" \
+ "Error: Can't use --name with probe event rules." \
+ --condition event-rule-matches --type=$type --location=do_sys_open --name='hello'
+done
+
+test_failure "--condition event-rule-matches: --location with tracepoint event rule" \
+ "Error: Can't use --location with tracepoint event rules." \
+ --condition event-rule-matches --domain=user --location='hello'
-test_failure "--condition event-rule-matches: --event-name with tracepoint" \
+test_failure "--condition event-rule-matches: --event-name with tracepoint event rule" \
"Error: Can't use --event-name with tracepoint event rules." \
--condition event-rule-matches --domain=user --event-name='hello'
-test_failure "--condition event-rule-matches: extra argument with --userspace-probe" \
- "Error: Unexpected argument 'hello'" \
- --condition event-rule-matches --domain=kernel --userspace-probe=${uprobe_elf_binary}:test_failure hello
+for type in uprobe userspace-probe; do
+ test_failure "--condition event-rule-matches: extra argument with --type=$type" \
+ "Error: Unexpected argument 'hello'" \
+ --condition event-rule-matches --domain=kernel --type=$type --location=${uprobe_elf_binary}:test_failure hello
+done
-test_failure "--condition event-rule-matches: extra argument with --syscall" \
+test_failure "--condition event-rule-matches: extra argument with --type=syscall" \
"Error: Unexpected argument 'open'" \
- --condition event-rule-matches --domain=kernel --syscall open
+ --condition event-rule-matches --domain=kernel --type=syscall open
test_failure "--condition event-rule-matches --capture: missing argument (end of arg list)" \
'Error: While parsing argument #2 (`--capture`): Missing required argument for option `--capture`' \