static int parse_events_resolve_symbol(int fd, char *event, int type) { char *colon, *end; vaddr_t symbol_address; int ret; struct probe_cb_base base = { .fd = fd, .event = event }; colon = strchr(event, ':'); if (!colon) return 0; base.ret_probe = !!strstr(event, "%return"); symbol_address = strtol(colon + 1 /* skip ":" */, NULL, 0); base.binary = strndup(event, colon - event); base.fetch_args = strchr(event, ' '); /* * We already have address, no need in resolving. */ if (symbol_address) { int ret; ret = write_uprobe_event(fd, base.ret_probe, base.binary, "NULL", symbol_address, base.fetch_args); free(base.binary); return ret; } end = strpbrk(event, "% "); if (end) base.symbol = strndup(colon + 1, end - 1 - colon); else base.symbol = strdup(colon + 1); ret = parse_dso_symbols(base.binary, type, uprobe_symbol_actor, (void *)&base); if (!ret) { fprintf(stderr, "error: cannot find symbol %s in binary %s\n", base.symbol, base.binary); ret = -1; } else if(ret > 0) { /* no error found when parse symbols */ ret = 0; } free(base.binary); free(base.symbol); return ret; }
static void parse_option(int argc, char **argv) { char pid[32] = {0}; char cpu_str[32] = {0}; char *next_arg; int i, j; for (i = 1; i < argc; i++) { if (argv[i][0] != '-') { script_file = argv[i]; if (!script_file) usage(""); script_args_start = i + 1; script_args_end = argc; for (j = i + 1; j < argc; j++) { if (argv[j][0] == '-' && argv[j][1] == '-') goto found_cmd; } return; } if (argv[i][0] == '-' && argv[i][1] == '-') { j = i; goto found_cmd; } next_arg = argv[i + 1]; switch (argv[i][1]) { case 'o': output_filename = malloc(strlen(next_arg) + 1); if (!output_filename) return; strncpy(output_filename, next_arg, strlen(next_arg)); i++; break; case 'e': strncpy(oneline_src, next_arg, strlen(next_arg)); i++; break; case 'p': strncpy(pid, next_arg, strlen(next_arg)); trace_pid = atoi(pid); i++; break; case 'C': strncpy(cpu_str, next_arg, strlen(next_arg)); trace_cpu = atoi(cpu_str); i++; break; case 'T': print_timestamp = 1; break; case 'v': verbose = 1; break; case 's': sprintf(oneline_src, SIMPLE_ONE_LINER_FMT, next_arg); i++; break; case 'b': dump_bytecode = 1; break; #ifndef NO_LIBELF case 'F': case 'M': { const char *binary = next_arg; int type = argv[i][1] == 'F' ? FIND_SYMBOL : FIND_STAPSDT_NOTE; struct binary_base base = { .type = type, .binary = binary, }; int ret; ret = parse_dso_symbols(binary, type, print_symbol, (void *)&base); if (ret <= 0) { fprintf(stderr, "error: no symbols in binary %s\n", binary); exit(EXIT_FAILURE); } exit(EXIT_SUCCESS); } #endif case 'V': case '?': case 'h': usage(""); break; default: usage("wrong argument\n"); break; } } return; found_cmd: script_args_end = j; forks = 1; workload_argv = &argv[j + 1]; }
static void parse_option(int argc, char **argv) { char pid[32] = {0}; char cpu_str[32] = {0}; char *next_arg; int i, j; for (i = 1; i < argc; i++) { if (argv[i][0] != '-') { script_file = argv[i]; if (!script_file) usage(""); script_args_start = i + 1; script_args_end = argc; for (j = i + 1; j < argc; j++) { if (argv[j][0] == '-' && argv[j][1] == '-') goto found_cmd; } return; } if (argv[i][0] == '-' && argv[i][1] == '-') { j = i; goto found_cmd; } next_arg = argv[i + 1]; /* These flags require arguments. */ if (!next_arg && (argv[i][1] == 'o' || argv[i][1] == 'e' || argv[i][1] == 'p' || argv[i][1] == 'C' || argv[i][1] == 'l')) usage("flag -%s requires an argument\n", argv[i][1]); switch (argv[i][1]) { case 'o': output_filename = malloc(strlen(next_arg) + 1); if (!output_filename) return; strncpy(output_filename, next_arg, strlen(next_arg)); i++; break; case 'e': strncpy(oneline_src, next_arg, strlen(next_arg)); i++; break; case 'p': strncpy(pid, next_arg, strlen(next_arg)); trace_pid = atoi(pid); i++; break; case 'C': strncpy(cpu_str, next_arg, strlen(next_arg)); trace_cpu = atoi(cpu_str); i++; break; case 'T': print_timestamp = 1; break; case 'v': verbose = 1; break; case 'q': quiet = 1; break; case 'd': dry_run = 1; break; case 's': sprintf(oneline_src, SIMPLE_ONE_LINER_FMT, next_arg); i++; break; case 'b': dump_bytecode = 1; break; case 'l': /* list available events */ switch (argv[i][2]) { case 'e': /* tracepoints */ list_available_events(next_arg); exit(EXIT_SUCCESS); #ifndef NO_LIBELF case 'f': /* functions in DSO */ case 'm': /* static marks in DSO */ { const char *binary = next_arg; int type = argv[i][2] == 'f' ? FIND_SYMBOL : FIND_STAPSDT_NOTE; struct binary_base base = { .type = type, .binary = binary, }; int ret; ret = parse_dso_symbols(binary, type, print_symbol, (void *)&base); if (ret <= 0) { fprintf(stderr, "error: no symbols in binary %s\n", binary); exit(EXIT_FAILURE); } exit(EXIT_SUCCESS); } #endif default: exit(EXIT_FAILURE); } break; case 'V': #ifdef CONFIG_KTAP_FFI usage("%s (with FFI)\n\n", KTAP_VERSION); #else usage("%s\n\n", KTAP_VERSION); #endif break; case '?': case 'h': usage(""); break; default: usage("wrong argument\n"); break; } } return; found_cmd: script_args_end = j; forks = 1; workload_argv = &argv[j + 1]; }