Add error message if event not found
[lttng-tools.git] / lttng / commands / enable_events.c
index f9b51b14d74704fc1fc5127d3748b1adf0faa820..ce8d6024155e6dea7c7a2b696ac60cf521e48fe0 100644 (file)
 #include <unistd.h>
 
 #include "cmd.h"
-#include "config.h"
+#include "conf.h"
 #include "utils.h"
 
 static char *opt_event_list;
 static int opt_event_type;
 static char *opt_kernel;
 static char *opt_cmd_name;
+static char *opt_session_name;
 static int opt_pid_all;
 static int opt_userspace;
 static int opt_enable_all;
 static pid_t opt_pid;
-static char *opt_kprobe_addr;
+static char *opt_kprobe;
 static char *opt_function_symbol;
 static char *opt_channel_name;
 
@@ -53,6 +54,7 @@ enum {
 static struct poptOption long_options[] = {
        /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
        {"help",           'h', POPT_ARG_NONE, 0, OPT_HELP, 0, 0},
+       {"session",        's', POPT_ARG_STRING, &opt_session_name, 0, 0, 0},
        {"all-events",     'a', POPT_ARG_VAL, &opt_enable_all, 1, 0, 0},
        {"channel",        'c', POPT_ARG_STRING, &opt_channel_name, 0, 0, 0},
        {"kernel",         'k', POPT_ARG_VAL, &opt_kernel, 1, 0, 0},
@@ -74,6 +76,7 @@ static void usage(FILE *ofp)
        fprintf(ofp, "usage: lttng enable-event NAME[,NAME2,...] [options] [event_options]\n");
        fprintf(ofp, "\n");
        fprintf(ofp, "  -h, --help               Show this help\n");
+       fprintf(ofp, "  -s, --session            Apply on session name\n");
        fprintf(ofp, "  -c, --channel            Apply on this channel\n");
        fprintf(ofp, "  -a, --all-events         Enable all tracepoints\n");
        fprintf(ofp, "  -k, --kernel             Apply for the kernel tracer\n");
@@ -83,12 +86,64 @@ static void usage(FILE *ofp)
        fprintf(ofp, "\n");
        fprintf(ofp, "Event options:\n");
        fprintf(ofp, "    --tracepoint           Tracepoint event (default)\n");
-       fprintf(ofp, "    --kprobe ADDR          Kernel Kprobe\n");
+       fprintf(ofp, "    --kprobe [addr | symbol+offset]\n");
+       fprintf(ofp, "                           Kernel Kprobe. (addr or offset can be base 8,10 and 16)\n");
        fprintf(ofp, "    --function SYMBOL      Function tracer event\n");
        fprintf(ofp, "    --marker               User-space marker (deprecated)\n");
        fprintf(ofp, "\n");
 }
 
+/*
+ *  parse_kprobe_addr
+ *
+ *  Parse kprobe options.
+ */
+static int parse_kprobe_opts(struct lttng_event *ev, char *opt)
+{
+       int ret;
+       uint64_t hex;
+       char name[LTTNG_SYMBOL_NAME_LEN];
+
+       if (opt == NULL) {
+               ret = -1;
+               goto error;
+       }
+
+       /* Check for symbol+offset */
+       ret = sscanf(opt, "%[^'+']+%li", name, &hex);
+       if (ret == 2) {
+               strncpy(ev->attr.kprobe.symbol_name, name, LTTNG_SYMBOL_NAME_LEN);
+               DBG("kprobe symbol %s", ev->attr.kprobe.symbol_name);
+               if (hex == 0) {
+                       ERR("Invalid kprobe offset %lu", hex);
+                       ret = -1;
+                       goto error;
+               }
+               ev->attr.kprobe.offset = hex;
+               DBG("kprobe offset %lu", ev->attr.kprobe.offset);
+               goto error;
+       }
+
+       /* Check for address */
+       ret = sscanf(opt, "%li", &hex);
+       if (ret > 0) {
+               if (hex == 0) {
+                       ERR("Invalid kprobe address %lu", hex);
+                       ret = -1;
+                       goto error;
+               }
+               ev->attr.kprobe.addr = hex;
+               DBG("kprobe addr %lu", ev->attr.kprobe.addr);
+               goto error;
+       }
+
+       /* No match */
+       ret = -1;
+
+error:
+       return ret;
+}
+
 /*
  *  enable_events
  *
@@ -97,10 +152,10 @@ static void usage(FILE *ofp)
 static int enable_events(void)
 {
        int err, ret = CMD_SUCCESS;
-       char *event_name, *channel_name;
+       char *event_name, *channel_name = NULL;
        struct lttng_event ev;
 
-       if (set_session_name() < 0) {
+       if (set_session_name(opt_session_name) < 0) {
                ret = CMD_ERROR;
                goto error;
        }
@@ -138,10 +193,18 @@ static int enable_events(void)
                        switch (opt_event_type) {
                        case LTTNG_EVENT_TRACEPOINTS:
                                ret = lttng_kernel_enable_event(&ev, channel_name);
+                               if (ret < 0) {
+                                       ERR("Unable to find event %s", ev.name);
+                               }
                                break;
                        case LTTNG_EVENT_KPROBES:
-                               /* FIXME: check addr format */
-                               ev.attr.kprobe.addr = atoll(opt_kprobe_addr);
+                               ret = parse_kprobe_opts(&ev, opt_kprobe);
+                               if (ret < 0) {
+                                       ERR("Unable to parse kprobe options");
+                                       ret = 0;
+                                       goto error;
+                               }
+
                                ret = lttng_kernel_enable_event(&ev, channel_name);
                                break;
                        case LTTNG_EVENT_FUNCTION:
@@ -175,6 +238,9 @@ static int enable_events(void)
        }
 
 error:
+       if (opt_channel_name == NULL) {
+               free(channel_name);
+       }
        return ret;
 }
 
@@ -212,7 +278,7 @@ int cmd_enable_events(int argc, const char **argv)
                        goto end;
                case OPT_KPROBE:
                        opt_event_type = LTTNG_EVENT_KPROBES;
-                       opt_kprobe_addr = poptGetOptArg(pc);
+                       opt_kprobe = poptGetOptArg(pc);
                        break;
                case OPT_FUNCTION:
                        opt_event_type = LTTNG_EVENT_FUNCTION;
This page took 0.025678 seconds and 4 git commands to generate.