For parsing ktap scripts, uprobes functions are used for stapstd probes too, the only differ between then is type argument, which is bypassed up to find_symbol() that's it. Signed-off-by: Azat Khuzhin <a3at.mail@xxxxxxxxx> --- userspace/eventdef.c | 14 ++++++-------- userspace/symbol.c | 13 ++++++++++--- userspace/symbol.h | 5 ++++- 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/userspace/eventdef.c b/userspace/eventdef.c index 48830cd..3f5339c 100644 --- a/userspace/eventdef.c +++ b/userspace/eventdef.c @@ -304,7 +304,7 @@ static int parse_events_add_kprobe(char *old_event) return 0; } -static char *parse_events_resolve_symbol(char *event) +static char *parse_events_resolve_symbol(char *event, int type) { char *colon = strchr(event, ':'); vaddr_t symbol_address = strtol(colon + 1 /* skip ":" */, NULL, 0); @@ -336,7 +336,7 @@ static char *parse_events_resolve_symbol(char *event) symbol = strdup(colon + 1 /* skip ":" */); } - symbol_address = find_symbol(binary, symbol); + symbol_address = find_symbol(binary, symbol, type); if (symbol_address) { verbose_printf("symbol %s resolved to 0x%lx\n", event, symbol_address); @@ -361,7 +361,7 @@ static char *parse_events_resolve_symbol(char *event) #define UPROBE_EVENTS_PATH "/sys/kernel/debug/tracing/uprobe_events" -static int parse_events_add_uprobe(char *old_event) +static int parse_events_add_uprobe(char *old_event, int type) { static int event_seq = 0; struct probe_list *pl; @@ -381,7 +381,7 @@ static int parse_events_add_uprobe(char *old_event) event = strdup(old_event); /* resolve symbol with libelf help */ - event = parse_events_resolve_symbol(event); + event = parse_events_resolve_symbol(event, type); r = strstr(event, "%return"); if (r) { @@ -435,14 +435,12 @@ static int parse_events_add_probe(char *old_event) if (!separator || (separator == old_event)) return parse_events_add_kprobe(old_event); else - return parse_events_add_uprobe(old_event); + return parse_events_add_uprobe(old_event, FIND_SYMBOL); } static int parse_events_add_stapsdt(char *old_event) { - printf("Currently ktap don't support stapsdt, please waiting\n"); - - return -1; + return parse_events_add_uprobe(old_event, FIND_STAPSTD_NOTE); } static void strim(char *s) diff --git a/userspace/symbol.c b/userspace/symbol.c index b7f677c..7aaa359 100644 --- a/userspace/symbol.c +++ b/userspace/symbol.c @@ -222,7 +222,7 @@ static vaddr_t search_stapsdt_note(Elf *elf, const char *note) return vaddr; } -vaddr_t find_symbol(const char *exec, const char *symbol) +vaddr_t find_symbol(const char *exec, const char *symbol, int type) { vaddr_t vaddr = 0; Elf *elf; @@ -237,11 +237,18 @@ vaddr_t find_symbol(const char *exec, const char *symbol) elf = elf_begin(fd, ELF_C_READ, NULL); if (elf) { - vaddr = search_symbol(elf, symbol); + switch (type) { + case FIND_SYMBOL: + vaddr = search_symbol(elf, symbol); + break; + case FIND_STAPSTD_NOTE: + vaddr = search_stapsdt_note(elf, symbol); + break; + } + elf_end(elf); } close(fd); return vaddr; } - diff --git a/userspace/symbol.h b/userspace/symbol.h index 89af91b..67f9ad8 100644 --- a/userspace/symbol.h +++ b/userspace/symbol.h @@ -21,6 +21,9 @@ #include <gelf.h> +#define FIND_SYMBOL 1 +#define FIND_STAPSTD_NOTE 2 + typedef GElf_Addr vaddr_t; /** @@ -28,4 +31,4 @@ typedef GElf_Addr vaddr_t; * * @return 0 on failure, otherwise address of symbol. */ -vaddr_t find_symbol(const char *exec, const char *symbol); +vaddr_t find_symbol(const char *exec, const char *symbol, int type); -- 1.8.4.rc3