static int parse_events_add_kprobe(char *event) { char *symbol, *end; struct probe_cb_base base; int fd, ret; fd = open(KPROBE_EVENTS_PATH, O_WRONLY); if (fd < 0) { fprintf(stderr, "Cannot open %s\n", KPROBE_EVENTS_PATH); return -1; } end = strpbrk(event, "% "); if (end) symbol = strndup(event, end - event); else symbol = strdup(event); base.fd = fd; base.ret_probe = !!strstr(event, "%return"); base.symbol = symbol; base.fetch_args = strchr(event, ' '); init_kprobe_prohibited_area(); ret = kallsyms_parse(&base, kprobe_symbol_actor); if (ret < 0) fprintf(stderr, "cannot parse symbol \"%s\"\n", symbol); free(symbol); close(fd); return ret; }
unsigned long find_kernel_symbol(const char *symbol) { int ret; struct ksym_addr_t arg = { .name = symbol, .addr = 0 }; ret = kallsyms_parse(&arg, symbol_cmp); if (ret < 0 || arg.addr == 0) { fprintf(stderr, "cannot read kernel symbol \"%s\" in %s\n", symbol, KALLSYMS_PATH); exit(EXIT_FAILURE); } return arg.addr; }
unsigned long find_kernel_symbol(const char *symbol) { int ret; struct ksym_addr_t arg = { .name = symbol, .addr = 0 }; ret = kallsyms_parse(&arg, symbol_cmp); if (ret < 0 || arg.addr == 0) { fprintf(stderr, "cannot read kernel symbol \"%s\" in %s\n", symbol, KALLSYMS_PATH); exit(EXIT_FAILURE); } return arg.addr; } #define AVAILABLE_EVENTS_PATH "/sys/kernel/debug/tracing/available_events" void list_available_events(const char *match) { FILE *file; char *line = NULL; file = fopen(AVAILABLE_EVENTS_PATH, "r"); if (file == NULL) handle_error("open " AVAILABLE_EVENTS_PATH " failed"); while (!feof(file)) { int line_len; size_t n; line_len = getline(&line, &n, file); if (line_len < 0 || !line) break; if (!match || strglobmatch(line, match)) printf("%s", line); } free(line); fclose(file); }