X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=blobdiff_plain;f=lttng%2Fcommands%2Fenable_events.c;h=ce8d6024155e6dea7c7a2b696ac60cf521e48fe0;hp=b39a9f4616da1b0b3aa91c6602c4a8adfccc66da;hb=ec188088b77f0ac753ca592f9c1cf46f219ec7dd;hpb=5440dc4282b3186641a8886dc05f6cf5641b5191 diff --git a/lttng/commands/enable_events.c b/lttng/commands/enable_events.c index b39a9f461..ce8d60241 100644 --- a/lttng/commands/enable_events.c +++ b/lttng/commands/enable_events.c @@ -38,7 +38,7 @@ 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; @@ -86,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 * @@ -100,7 +152,7 @@ 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(opt_session_name) < 0) { @@ -141,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: @@ -178,6 +238,9 @@ static int enable_events(void) } error: + if (opt_channel_name == NULL) { + free(channel_name); + } return ret; } @@ -215,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;