From: David Goulet Date: Thu, 7 Jul 2011 18:26:02 +0000 (-0400) Subject: Parse kprobe options with enable-event X-Git-Tag: v2.0-pre1~44 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=0d63dd195f9b665bc46a23ec918b20bee7a5d96b;p=lttng-tools.git Parse kprobe options with enable-event Address or offset can be specified in base 8 (beginning with 0), base 10 and base 16 (beginning with 0x). Signed-off-by: David Goulet --- diff --git a/lttng/commands/enable_events.c b/lttng/commands/enable_events.c index b39a9f461..d4af4b3d3 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 * @@ -143,8 +195,13 @@ static int enable_events(void) ret = lttng_kernel_enable_event(&ev, channel_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: @@ -215,7 +272,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; diff --git a/lttng/conf.c b/lttng/conf.c index adc887486..e6cc7746c 100644 --- a/lttng/conf.c +++ b/lttng/conf.c @@ -165,7 +165,7 @@ char *config_read_session_name(char *path) fp = open_config(path, "r"); if (fp == NULL) { - ERR("Can't find valid lttng config in %s", path); + ERR("Can't find valid lttng config %s/.lttngrc", path); goto error; }