2 * probe-event.c : perf-probe definition to probe_events format converter
4 * Written by Masami Hiramatsu <mhiramat@redhat.com>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 #include <sys/utsname.h>
23 #include <sys/types.h>
43 #include <api/fs/debugfs.h>
44 #include "trace-event.h" /* For __maybe_unused */
45 #include "probe-event.h"
46 #include "probe-finder.h"
49 #define MAX_CMDLEN 256
50 #define PERFPROBE_GROUP "probe"
52 bool probe_event_dry_run; /* Dry run flag */
54 #define semantic_error(msg ...) pr_err("Semantic error :" msg)
56 /* If there is no space to write, returns -E2BIG. */
57 static int e_snprintf(char *str, size_t size, const char *format, ...)
58 __attribute__((format(printf, 3, 4)));
60 static int e_snprintf(char *str, size_t size, const char *format, ...)
65 ret = vsnprintf(str, size, format, ap);
72 static char *synthesize_perf_probe_point(struct perf_probe_point *pp);
73 static int convert_name_to_addr(struct perf_probe_event *pev,
75 static struct machine machine;
77 /* Initialize symbol maps and path of vmlinux/modules */
78 static int init_vmlinux(void)
82 symbol_conf.sort_by_name = true;
83 if (symbol_conf.vmlinux_name == NULL)
84 symbol_conf.try_vmlinux_path = true;
86 pr_debug("Use vmlinux: %s\n", symbol_conf.vmlinux_name);
89 pr_debug("Failed to init symbol map.\n");
93 ret = machine__init(&machine, "", HOST_KERNEL_ID);
97 if (machine__create_kernel_maps(&machine) < 0) {
98 pr_debug("machine__create_kernel_maps() failed.\n");
103 pr_warning("Failed to init vmlinux path.\n");
107 static struct symbol *__find_kernel_function_by_name(const char *name,
110 return machine__find_kernel_function_by_name(&machine, name, mapp,
114 static struct map *kernel_get_module_map(const char *module)
117 struct map_groups *grp = &machine.kmaps;
119 /* A file path -- this is an offline module */
120 if (module && strchr(module, '/'))
121 return machine__new_module(&machine, 0, module);
126 for (nd = rb_first(&grp->maps[MAP__FUNCTION]); nd; nd = rb_next(nd)) {
127 struct map *pos = rb_entry(nd, struct map, rb_node);
128 if (strncmp(pos->dso->short_name + 1, module,
129 pos->dso->short_name_len - 2) == 0) {
136 static struct dso *kernel_get_module_dso(const char *module)
140 const char *vmlinux_name;
143 list_for_each_entry(dso, &machine.kernel_dsos, node) {
144 if (strncmp(dso->short_name + 1, module,
145 dso->short_name_len - 2) == 0)
148 pr_debug("Failed to find module %s.\n", module);
152 map = machine.vmlinux_maps[MAP__FUNCTION];
155 vmlinux_name = symbol_conf.vmlinux_name;
157 if (dso__load_vmlinux(dso, map, vmlinux_name, false, NULL) <= 0)
160 if (dso__load_vmlinux_path(dso, map, NULL) <= 0) {
161 pr_debug("Failed to load kernel map.\n");
169 const char *kernel_get_module_path(const char *module)
171 struct dso *dso = kernel_get_module_dso(module);
172 return (dso) ? dso->long_name : NULL;
175 #ifdef HAVE_DWARF_SUPPORT
176 /* Copied from unwind.c */
177 static Elf_Scn *elf_section_by_name(Elf *elf, GElf_Ehdr *ep,
178 GElf_Shdr *shp, const char *name)
182 while ((sec = elf_nextscn(elf, sec)) != NULL) {
185 gelf_getshdr(sec, shp);
186 str = elf_strptr(elf, ep->e_shstrndx, shp->sh_name);
187 if (!strcmp(name, str))
194 static int get_text_start_address(const char *exec, unsigned long *address)
199 int fd, ret = -ENOENT;
201 fd = open(exec, O_RDONLY);
205 elf = elf_begin(fd, PERF_ELF_C_READ_MMAP, NULL);
209 if (gelf_getehdr(elf, &ehdr) == NULL)
212 if (!elf_section_by_name(elf, &ehdr, &shdr, ".text"))
215 *address = shdr.sh_addr - shdr.sh_offset;
223 static int init_user_exec(void)
227 symbol_conf.try_vmlinux_path = false;
228 symbol_conf.sort_by_name = true;
229 ret = symbol__init();
232 pr_debug("Failed to init symbol map.\n");
237 static int convert_exec_to_group(const char *exec, char **result)
239 char *ptr1, *ptr2, *exec_copy;
243 exec_copy = strdup(exec);
247 ptr1 = basename(exec_copy);
253 ptr2 = strpbrk(ptr1, "-._");
256 ret = e_snprintf(buf, 64, "%s_%s", PERFPROBE_GROUP, ptr1);
260 *result = strdup(buf);
261 ret = *result ? 0 : -ENOMEM;
268 static int convert_to_perf_probe_point(struct probe_trace_point *tp,
269 struct perf_probe_point *pp)
271 pp->function = strdup(tp->symbol);
273 if (pp->function == NULL)
276 pp->offset = tp->offset;
277 pp->retprobe = tp->retprobe;
282 #ifdef HAVE_DWARF_SUPPORT
283 /* Open new debuginfo of given module */
284 static struct debuginfo *open_debuginfo(const char *module)
288 /* A file path -- this is an offline module */
289 if (module && strchr(module, '/'))
292 path = kernel_get_module_path(module);
295 pr_err("Failed to find path of %s module.\n",
300 return debuginfo__new(path);
304 * Convert trace point to probe point with debuginfo
305 * Currently only handles kprobes.
307 static int kprobe_convert_to_perf_probe(struct probe_trace_point *tp,
308 struct perf_probe_point *pp)
314 struct debuginfo *dinfo;
316 sym = __find_kernel_function_by_name(tp->symbol, &map);
318 addr = map->unmap_ip(map, sym->start + tp->offset);
319 pr_debug("try to find %s+%ld@%" PRIx64 "\n", tp->symbol,
322 dinfo = debuginfo__new_online_kernel(addr);
324 ret = debuginfo__find_probe_point(dinfo,
325 (unsigned long)addr, pp);
326 debuginfo__delete(dinfo);
328 pr_debug("Failed to open debuginfo at 0x%" PRIx64 "\n",
334 pr_debug("Failed to find corresponding probes from "
335 "debuginfo. Use kprobe event information.\n");
336 return convert_to_perf_probe_point(tp, pp);
338 pp->retprobe = tp->retprobe;
343 static int add_exec_to_probe_trace_events(struct probe_trace_event *tevs,
344 int ntevs, const char *exec)
347 unsigned long offset, stext = 0;
353 ret = get_text_start_address(exec, &stext);
357 for (i = 0; i < ntevs && ret >= 0; i++) {
358 offset = tevs[i].point.address - stext;
359 offset += tevs[i].point.offset;
360 tevs[i].point.offset = 0;
361 zfree(&tevs[i].point.symbol);
362 ret = e_snprintf(buf, 32, "0x%lx", offset);
365 tevs[i].point.module = strdup(exec);
366 tevs[i].point.symbol = strdup(buf);
367 if (!tevs[i].point.symbol || !tevs[i].point.module) {
371 tevs[i].uprobes = true;
377 static int add_module_to_probe_trace_events(struct probe_trace_event *tevs,
378 int ntevs, const char *module)
386 tmp = strrchr(module, '/');
388 /* This is a module path -- get the module name */
389 module = strdup(tmp + 1);
392 tmp = strchr(module, '.');
395 tmp = (char *)module; /* For free() */
398 for (i = 0; i < ntevs; i++) {
399 tevs[i].point.module = strdup(module);
400 if (!tevs[i].point.module) {
410 /* Try to find perf_probe_event with debuginfo */
411 static int try_to_find_probe_trace_events(struct perf_probe_event *pev,
412 struct probe_trace_event **tevs,
413 int max_tevs, const char *target)
415 bool need_dwarf = perf_probe_event_need_dwarf(pev);
416 struct debuginfo *dinfo;
419 dinfo = open_debuginfo(target);
423 pr_warning("Failed to open debuginfo file.\n");
426 pr_debug("Could not open debuginfo. Try to use symbols.\n");
430 /* Searching trace events corresponding to a probe event */
431 ntevs = debuginfo__find_trace_events(dinfo, pev, tevs, max_tevs);
433 debuginfo__delete(dinfo);
435 if (ntevs > 0) { /* Succeeded to find trace events */
436 pr_debug("find %d probe_trace_events.\n", ntevs);
439 ret = add_exec_to_probe_trace_events(*tevs,
442 ret = add_module_to_probe_trace_events(*tevs,
445 return ret < 0 ? ret : ntevs;
448 if (ntevs == 0) { /* No error but failed to find probe point. */
449 pr_warning("Probe point '%s' not found.\n",
450 synthesize_perf_probe_point(&pev->point));
453 /* Error path : ntevs < 0 */
454 pr_debug("An error occurred in debuginfo analysis (%d).\n", ntevs);
455 if (ntevs == -EBADF) {
456 pr_warning("Warning: No dwarf info found in the vmlinux - "
457 "please rebuild kernel with CONFIG_DEBUG_INFO=y.\n");
459 pr_debug("Trying to use symbols.\n");
467 * Find a src file from a DWARF tag path. Prepend optional source path prefix
468 * and chop off leading directories that do not exist. Result is passed back as
469 * a newly allocated path on success.
470 * Return 0 if file was found and readable, -errno otherwise.
472 static int get_real_path(const char *raw_path, const char *comp_dir,
475 const char *prefix = symbol_conf.source_prefix;
478 if (raw_path[0] != '/' && comp_dir)
479 /* If not an absolute path, try to use comp_dir */
482 if (access(raw_path, R_OK) == 0) {
483 *new_path = strdup(raw_path);
490 *new_path = malloc((strlen(prefix) + strlen(raw_path) + 2));
495 sprintf(*new_path, "%s/%s", prefix, raw_path);
497 if (access(*new_path, R_OK) == 0)
500 if (!symbol_conf.source_prefix)
501 /* In case of searching comp_dir, don't retry */
509 raw_path = strchr(++raw_path, '/');
523 #define LINEBUF_SIZE 256
524 #define NR_ADDITIONAL_LINES 2
526 static int __show_one_line(FILE *fp, int l, bool skip, bool show_num)
528 char buf[LINEBUF_SIZE];
529 const char *color = show_num ? "" : PERF_COLOR_BLUE;
530 const char *prefix = NULL;
533 if (fgets(buf, LINEBUF_SIZE, fp) == NULL)
538 prefix = show_num ? "%7d " : " ";
539 color_fprintf(stdout, color, prefix, l);
541 color_fprintf(stdout, color, "%s", buf);
543 } while (strchr(buf, '\n') == NULL);
548 pr_warning("File read error: %s\n", strerror(errno));
554 static int _show_one_line(FILE *fp, int l, bool skip, bool show_num)
556 int rv = __show_one_line(fp, l, skip, show_num);
558 pr_warning("Source file is shorter than expected.\n");
564 #define show_one_line_with_num(f,l) _show_one_line(f,l,false,true)
565 #define show_one_line(f,l) _show_one_line(f,l,false,false)
566 #define skip_one_line(f,l) _show_one_line(f,l,true,false)
567 #define show_one_line_or_eof(f,l) __show_one_line(f,l,false,false)
570 * Show line-range always requires debuginfo to find source file and
573 int show_line_range(struct line_range *lr, const char *module)
576 struct line_node *ln;
577 struct debuginfo *dinfo;
582 /* Search a line range */
583 ret = init_vmlinux();
587 dinfo = open_debuginfo(module);
589 pr_warning("Failed to open debuginfo file.\n");
593 ret = debuginfo__find_line_range(dinfo, lr);
594 debuginfo__delete(dinfo);
596 pr_warning("Specified source line is not found.\n");
598 } else if (ret < 0) {
599 pr_warning("Debuginfo analysis failed. (%d)\n", ret);
603 /* Convert source file path */
605 ret = get_real_path(tmp, lr->comp_dir, &lr->path);
606 free(tmp); /* Free old path */
608 pr_warning("Failed to find source file. (%d)\n", ret);
615 fprintf(stdout, "<%s@%s:%d>\n", lr->function, lr->path,
616 lr->start - lr->offset);
618 fprintf(stdout, "<%s:%d>\n", lr->path, lr->start);
620 fp = fopen(lr->path, "r");
622 pr_warning("Failed to open %s: %s\n", lr->path,
626 /* Skip to starting line number */
627 while (l < lr->start) {
628 ret = skip_one_line(fp, l++);
633 list_for_each_entry(ln, &lr->line_list, list) {
634 for (; ln->line > l; l++) {
635 ret = show_one_line(fp, l - lr->offset);
639 ret = show_one_line_with_num(fp, l++ - lr->offset);
644 if (lr->end == INT_MAX)
645 lr->end = l + NR_ADDITIONAL_LINES;
646 while (l <= lr->end) {
647 ret = show_one_line_or_eof(fp, l++ - lr->offset);
656 static int show_available_vars_at(struct debuginfo *dinfo,
657 struct perf_probe_event *pev,
658 int max_vls, struct strfilter *_filter,
663 struct str_node *node;
664 struct variable_list *vls = NULL, *vl;
667 buf = synthesize_perf_probe_point(&pev->point);
670 pr_debug("Searching variables at %s\n", buf);
672 ret = debuginfo__find_available_vars_at(dinfo, pev, &vls,
675 pr_err("Failed to find variables at %s (%d)\n", buf, ret);
678 /* Some variables are found */
679 fprintf(stdout, "Available variables at %s\n", buf);
680 for (i = 0; i < ret; i++) {
683 * A probe point might be converted to
684 * several trace points.
686 fprintf(stdout, "\t@<%s+%lu>\n", vl->point.symbol,
688 zfree(&vl->point.symbol);
691 strlist__for_each(node, vl->vars) {
692 var = strchr(node->s, '\t') + 1;
693 if (strfilter__compare(_filter, var)) {
694 fprintf(stdout, "\t\t%s\n", node->s);
698 strlist__delete(vl->vars);
701 fprintf(stdout, "\t\t(No matched variables)\n");
709 /* Show available variables on given probe point */
710 int show_available_vars(struct perf_probe_event *pevs, int npevs,
711 int max_vls, const char *module,
712 struct strfilter *_filter, bool externs)
715 struct debuginfo *dinfo;
717 ret = init_vmlinux();
721 dinfo = open_debuginfo(module);
723 pr_warning("Failed to open debuginfo file.\n");
729 for (i = 0; i < npevs && ret >= 0; i++)
730 ret = show_available_vars_at(dinfo, &pevs[i], max_vls, _filter,
733 debuginfo__delete(dinfo);
737 #else /* !HAVE_DWARF_SUPPORT */
739 static int kprobe_convert_to_perf_probe(struct probe_trace_point *tp,
740 struct perf_probe_point *pp)
744 sym = __find_kernel_function_by_name(tp->symbol, NULL);
746 pr_err("Failed to find symbol %s in kernel.\n", tp->symbol);
750 return convert_to_perf_probe_point(tp, pp);
753 static int try_to_find_probe_trace_events(struct perf_probe_event *pev,
754 struct probe_trace_event **tevs __maybe_unused,
755 int max_tevs __maybe_unused,
756 const char *target __maybe_unused)
758 if (perf_probe_event_need_dwarf(pev)) {
759 pr_warning("Debuginfo-analysis is not supported.\n");
766 int show_line_range(struct line_range *lr __maybe_unused,
767 const char *module __maybe_unused)
769 pr_warning("Debuginfo-analysis is not supported.\n");
773 int show_available_vars(struct perf_probe_event *pevs __maybe_unused,
774 int npevs __maybe_unused, int max_vls __maybe_unused,
775 const char *module __maybe_unused,
776 struct strfilter *filter __maybe_unused,
777 bool externs __maybe_unused)
779 pr_warning("Debuginfo-analysis is not supported.\n");
784 static int parse_line_num(char **ptr, int *val, const char *what)
786 const char *start = *ptr;
789 *val = strtol(*ptr, ptr, 0);
790 if (errno || *ptr == start) {
791 semantic_error("'%s' is not a valid number.\n", what);
798 * Stuff 'lr' according to the line range described by 'arg'.
799 * The line range syntax is described by:
801 * SRC[:SLN[+NUM|-ELN]]
802 * FNC[@SRC][:SLN[+NUM|-ELN]]
804 int parse_line_range_desc(const char *arg, struct line_range *lr)
806 char *range, *file, *name = strdup(arg);
815 range = strchr(name, ':');
819 err = parse_line_num(&range, &lr->start, "start line");
823 if (*range == '+' || *range == '-') {
824 const char c = *range++;
826 err = parse_line_num(&range, &lr->end, "end line");
831 lr->end += lr->start;
833 * Adjust the number of lines here.
834 * If the number of lines == 1, the
835 * the end of line should be equal to
842 pr_debug("Line range is %d to %d\n", lr->start, lr->end);
845 if (lr->start > lr->end) {
846 semantic_error("Start line must be smaller"
847 " than end line.\n");
850 if (*range != '\0') {
851 semantic_error("Tailing with invalid str '%s'.\n", range);
856 file = strchr(name, '@');
859 lr->file = strdup(++file);
860 if (lr->file == NULL) {
865 } else if (strchr(name, '.'))
876 /* Check the name is good for event/group */
877 static bool check_event_name(const char *name)
879 if (!isalpha(*name) && *name != '_')
881 while (*++name != '\0') {
882 if (!isalpha(*name) && !isdigit(*name) && *name != '_')
888 /* Parse probepoint definition. */
889 static int parse_perf_probe_point(char *arg, struct perf_probe_event *pev)
891 struct perf_probe_point *pp = &pev->point;
896 * perf probe [EVENT=]SRC[:LN|;PTN]
897 * perf probe [EVENT=]FUNC[@SRC][+OFFS|%return|:LN|;PAT]
899 * TODO:Group name support
902 ptr = strpbrk(arg, ";=@+%");
903 if (ptr && *ptr == '=') { /* Event name */
906 if (strchr(arg, ':')) {
907 semantic_error("Group name is not supported yet.\n");
910 if (!check_event_name(arg)) {
911 semantic_error("%s is bad for event name -it must "
912 "follow C symbol-naming rule.\n", arg);
915 pev->event = strdup(arg);
916 if (pev->event == NULL)
922 ptr = strpbrk(arg, ";:+@%");
932 /* Check arg is function or file and copy it */
933 if (strchr(tmp, '.')) /* File */
938 /* Parse other options */
942 if (c == ';') { /* Lazy pattern must be the last part */
943 pp->lazy_line = strdup(arg);
944 if (pp->lazy_line == NULL)
948 ptr = strpbrk(arg, ";:+@%");
954 case ':': /* Line number */
955 pp->line = strtoul(arg, &tmp, 0);
957 semantic_error("There is non-digit char"
958 " in line number.\n");
962 case '+': /* Byte offset from a symbol */
963 pp->offset = strtoul(arg, &tmp, 0);
965 semantic_error("There is non-digit character"
970 case '@': /* File name */
972 semantic_error("SRC@SRC is not allowed.\n");
975 pp->file = strdup(arg);
976 if (pp->file == NULL)
979 case '%': /* Probe places */
980 if (strcmp(arg, "return") == 0) {
982 } else { /* Others not supported yet */
983 semantic_error("%%%s is not supported.\n", arg);
987 default: /* Buggy case */
988 pr_err("This program has a bug at %s:%d.\n",
995 /* Exclusion check */
996 if (pp->lazy_line && pp->line) {
997 semantic_error("Lazy pattern can't be used with"
1002 if (pp->lazy_line && pp->offset) {
1003 semantic_error("Lazy pattern can't be used with offset.\n");
1007 if (pp->line && pp->offset) {
1008 semantic_error("Offset can't be used with line number.\n");
1012 if (!pp->line && !pp->lazy_line && pp->file && !pp->function) {
1013 semantic_error("File always requires line number or "
1018 if (pp->offset && !pp->function) {
1019 semantic_error("Offset requires an entry function.\n");
1023 if (pp->retprobe && !pp->function) {
1024 semantic_error("Return probe requires an entry function.\n");
1028 if ((pp->offset || pp->line || pp->lazy_line) && pp->retprobe) {
1029 semantic_error("Offset/Line/Lazy pattern can't be used with "
1034 pr_debug("symbol:%s file:%s line:%d offset:%lu return:%d lazy:%s\n",
1035 pp->function, pp->file, pp->line, pp->offset, pp->retprobe,
1040 /* Parse perf-probe event argument */
1041 static int parse_perf_probe_arg(char *str, struct perf_probe_arg *arg)
1043 char *tmp, *goodname;
1044 struct perf_probe_arg_field **fieldp;
1046 pr_debug("parsing arg: %s into ", str);
1048 tmp = strchr(str, '=');
1050 arg->name = strndup(str, tmp - str);
1051 if (arg->name == NULL)
1053 pr_debug("name:%s ", arg->name);
1057 tmp = strchr(str, ':');
1058 if (tmp) { /* Type setting */
1060 arg->type = strdup(tmp + 1);
1061 if (arg->type == NULL)
1063 pr_debug("type:%s ", arg->type);
1066 tmp = strpbrk(str, "-.[");
1067 if (!is_c_varname(str) || !tmp) {
1068 /* A variable, register, symbol or special value */
1069 arg->var = strdup(str);
1070 if (arg->var == NULL)
1072 pr_debug("%s\n", arg->var);
1076 /* Structure fields or array element */
1077 arg->var = strndup(str, tmp - str);
1078 if (arg->var == NULL)
1080 goodname = arg->var;
1081 pr_debug("%s, ", arg->var);
1082 fieldp = &arg->field;
1085 *fieldp = zalloc(sizeof(struct perf_probe_arg_field));
1086 if (*fieldp == NULL)
1088 if (*tmp == '[') { /* Array */
1090 (*fieldp)->index = strtol(str + 1, &tmp, 0);
1091 (*fieldp)->ref = true;
1092 if (*tmp != ']' || tmp == str + 1) {
1093 semantic_error("Array index must be a"
1100 } else { /* Structure */
1103 (*fieldp)->ref = false;
1104 } else if (tmp[1] == '>') {
1106 (*fieldp)->ref = true;
1108 semantic_error("Argument parse error: %s\n",
1112 tmp = strpbrk(str, "-.[");
1115 (*fieldp)->name = strndup(str, tmp - str);
1116 if ((*fieldp)->name == NULL)
1119 goodname = (*fieldp)->name;
1120 pr_debug("%s(%d), ", (*fieldp)->name, (*fieldp)->ref);
1121 fieldp = &(*fieldp)->next;
1124 (*fieldp)->name = strdup(str);
1125 if ((*fieldp)->name == NULL)
1128 goodname = (*fieldp)->name;
1129 pr_debug("%s(%d)\n", (*fieldp)->name, (*fieldp)->ref);
1131 /* If no name is specified, set the last field name (not array index)*/
1133 arg->name = strdup(goodname);
1134 if (arg->name == NULL)
1140 /* Parse perf-probe event command */
1141 int parse_perf_probe_command(const char *cmd, struct perf_probe_event *pev)
1144 int argc, i, ret = 0;
1146 argv = argv_split(cmd, &argc);
1148 pr_debug("Failed to split arguments.\n");
1151 if (argc - 1 > MAX_PROBE_ARGS) {
1152 semantic_error("Too many probe arguments (%d).\n", argc - 1);
1156 /* Parse probe point */
1157 ret = parse_perf_probe_point(argv[0], pev);
1161 /* Copy arguments and ensure return probe has no C argument */
1162 pev->nargs = argc - 1;
1163 pev->args = zalloc(sizeof(struct perf_probe_arg) * pev->nargs);
1164 if (pev->args == NULL) {
1168 for (i = 0; i < pev->nargs && ret >= 0; i++) {
1169 ret = parse_perf_probe_arg(argv[i + 1], &pev->args[i]);
1171 is_c_varname(pev->args[i].var) && pev->point.retprobe) {
1172 semantic_error("You can't specify local variable for"
1183 /* Return true if this perf_probe_event requires debuginfo */
1184 bool perf_probe_event_need_dwarf(struct perf_probe_event *pev)
1188 if (pev->point.file || pev->point.line || pev->point.lazy_line)
1191 for (i = 0; i < pev->nargs; i++)
1192 if (is_c_varname(pev->args[i].var))
1198 /* Parse probe_events event into struct probe_point */
1199 static int parse_probe_trace_command(const char *cmd,
1200 struct probe_trace_event *tev)
1202 struct probe_trace_point *tp = &tev->point;
1205 char *argv0_str = NULL, *fmt, *fmt1_str, *fmt2_str, *fmt3_str;
1209 pr_debug("Parsing probe_events: %s\n", cmd);
1210 argv = argv_split(cmd, &argc);
1212 pr_debug("Failed to split arguments.\n");
1216 semantic_error("Too few probe arguments.\n");
1221 /* Scan event and group name. */
1222 argv0_str = strdup(argv[0]);
1223 if (argv0_str == NULL) {
1227 fmt1_str = strtok_r(argv0_str, ":", &fmt);
1228 fmt2_str = strtok_r(NULL, "/", &fmt);
1229 fmt3_str = strtok_r(NULL, " \t", &fmt);
1230 if (fmt1_str == NULL || strlen(fmt1_str) != 1 || fmt2_str == NULL
1231 || fmt3_str == NULL) {
1232 semantic_error("Failed to parse event name: %s\n", argv[0]);
1237 tev->group = strdup(fmt2_str);
1238 tev->event = strdup(fmt3_str);
1239 if (tev->group == NULL || tev->event == NULL) {
1243 pr_debug("Group:%s Event:%s probe:%c\n", tev->group, tev->event, pr);
1245 tp->retprobe = (pr == 'r');
1247 /* Scan module name(if there), function name and offset */
1248 p = strchr(argv[1], ':');
1250 tp->module = strndup(argv[1], p - argv[1]);
1254 fmt1_str = strtok_r(p, "+", &fmt);
1255 tp->symbol = strdup(fmt1_str);
1256 if (tp->symbol == NULL) {
1260 fmt2_str = strtok_r(NULL, "", &fmt);
1261 if (fmt2_str == NULL)
1264 tp->offset = strtoul(fmt2_str, NULL, 10);
1266 tev->nargs = argc - 2;
1267 tev->args = zalloc(sizeof(struct probe_trace_arg) * tev->nargs);
1268 if (tev->args == NULL) {
1272 for (i = 0; i < tev->nargs; i++) {
1273 p = strchr(argv[i + 2], '=');
1274 if (p) /* We don't need which register is assigned. */
1278 tev->args[i].name = strdup(argv[i + 2]);
1279 /* TODO: parse regs and offset */
1280 tev->args[i].value = strdup(p);
1281 if (tev->args[i].name == NULL || tev->args[i].value == NULL) {
1293 /* Compose only probe arg */
1294 int synthesize_perf_probe_arg(struct perf_probe_arg *pa, char *buf, size_t len)
1296 struct perf_probe_arg_field *field = pa->field;
1300 if (pa->name && pa->var)
1301 ret = e_snprintf(tmp, len, "%s=%s", pa->name, pa->var);
1303 ret = e_snprintf(tmp, len, "%s", pa->name ? pa->name : pa->var);
1310 if (field->name[0] == '[')
1311 ret = e_snprintf(tmp, len, "%s", field->name);
1313 ret = e_snprintf(tmp, len, "%s%s",
1314 field->ref ? "->" : ".", field->name);
1319 field = field->next;
1323 ret = e_snprintf(tmp, len, ":%s", pa->type);
1332 pr_debug("Failed to synthesize perf probe argument: %s\n",
1337 /* Compose only probe point (not argument) */
1338 static char *synthesize_perf_probe_point(struct perf_probe_point *pp)
1341 char offs[32] = "", line[32] = "", file[32] = "";
1344 buf = zalloc(MAX_CMDLEN);
1350 ret = e_snprintf(offs, 32, "+%lu", pp->offset);
1355 ret = e_snprintf(line, 32, ":%d", pp->line);
1363 tmp = strchr(pp->file + len - 30, '/');
1364 tmp = tmp ? tmp + 1 : pp->file + len - 30;
1366 ret = e_snprintf(file, 32, "@%s", tmp);
1372 ret = e_snprintf(buf, MAX_CMDLEN, "%s%s%s%s%s", pp->function,
1373 offs, pp->retprobe ? "%return" : "", line,
1376 ret = e_snprintf(buf, MAX_CMDLEN, "%s%s", file, line);
1382 pr_debug("Failed to synthesize perf probe point: %s\n",
1389 char *synthesize_perf_probe_command(struct perf_probe_event *pev)
1394 buf = synthesize_perf_probe_point(&pev->point);
1399 for (i = 0; i < pev->nargs; i++) {
1400 ret = e_snprintf(&buf[len], MAX_CMDLEN - len, " %s",
1413 static int __synthesize_probe_trace_arg_ref(struct probe_trace_arg_ref *ref,
1414 char **buf, size_t *buflen,
1419 depth = __synthesize_probe_trace_arg_ref(ref->next, buf,
1425 ret = e_snprintf(*buf, *buflen, "%+ld(", ref->offset);
1437 static int synthesize_probe_trace_arg(struct probe_trace_arg *arg,
1438 char *buf, size_t buflen)
1440 struct probe_trace_arg_ref *ref = arg->ref;
1444 /* Argument name or separator */
1446 ret = e_snprintf(buf, buflen, " %s=", arg->name);
1448 ret = e_snprintf(buf, buflen, " ");
1454 /* Special case: @XXX */
1455 if (arg->value[0] == '@' && arg->ref)
1458 /* Dereferencing arguments */
1460 depth = __synthesize_probe_trace_arg_ref(ref, &buf,
1466 /* Print argument value */
1467 if (arg->value[0] == '@' && arg->ref)
1468 ret = e_snprintf(buf, buflen, "%s%+ld", arg->value,
1471 ret = e_snprintf(buf, buflen, "%s", arg->value);
1479 ret = e_snprintf(buf, buflen, ")");
1485 /* Print argument type */
1487 ret = e_snprintf(buf, buflen, ":%s", arg->type);
1496 char *synthesize_probe_trace_command(struct probe_trace_event *tev)
1498 struct probe_trace_point *tp = &tev->point;
1502 buf = zalloc(MAX_CMDLEN);
1507 len = e_snprintf(buf, MAX_CMDLEN, "%c:%s/%s %s:%s",
1508 tp->retprobe ? 'r' : 'p',
1509 tev->group, tev->event,
1510 tp->module, tp->symbol);
1512 len = e_snprintf(buf, MAX_CMDLEN, "%c:%s/%s %s%s%s+%lu",
1513 tp->retprobe ? 'r' : 'p',
1514 tev->group, tev->event,
1515 tp->module ?: "", tp->module ? ":" : "",
1516 tp->symbol, tp->offset);
1521 for (i = 0; i < tev->nargs; i++) {
1522 ret = synthesize_probe_trace_arg(&tev->args[i], buf + len,
1535 static int convert_to_perf_probe_event(struct probe_trace_event *tev,
1536 struct perf_probe_event *pev, bool is_kprobe)
1541 /* Convert event/group name */
1542 pev->event = strdup(tev->event);
1543 pev->group = strdup(tev->group);
1544 if (pev->event == NULL || pev->group == NULL)
1547 /* Convert trace_point to probe_point */
1549 ret = kprobe_convert_to_perf_probe(&tev->point, &pev->point);
1551 ret = convert_to_perf_probe_point(&tev->point, &pev->point);
1556 /* Convert trace_arg to probe_arg */
1557 pev->nargs = tev->nargs;
1558 pev->args = zalloc(sizeof(struct perf_probe_arg) * pev->nargs);
1559 if (pev->args == NULL)
1561 for (i = 0; i < tev->nargs && ret >= 0; i++) {
1562 if (tev->args[i].name)
1563 pev->args[i].name = strdup(tev->args[i].name);
1565 ret = synthesize_probe_trace_arg(&tev->args[i],
1567 pev->args[i].name = strdup(buf);
1569 if (pev->args[i].name == NULL && ret >= 0)
1574 clear_perf_probe_event(pev);
1579 void clear_perf_probe_event(struct perf_probe_event *pev)
1581 struct perf_probe_point *pp = &pev->point;
1582 struct perf_probe_arg_field *field, *next;
1589 free(pp->lazy_line);
1591 for (i = 0; i < pev->nargs; i++) {
1592 free(pev->args[i].name);
1593 free(pev->args[i].var);
1594 free(pev->args[i].type);
1595 field = pev->args[i].field;
1598 zfree(&field->name);
1604 memset(pev, 0, sizeof(*pev));
1607 static void clear_probe_trace_event(struct probe_trace_event *tev)
1609 struct probe_trace_arg_ref *ref, *next;
1614 free(tev->point.symbol);
1615 free(tev->point.module);
1616 for (i = 0; i < tev->nargs; i++) {
1617 free(tev->args[i].name);
1618 free(tev->args[i].value);
1619 free(tev->args[i].type);
1620 ref = tev->args[i].ref;
1628 memset(tev, 0, sizeof(*tev));
1631 static void print_warn_msg(const char *file, bool is_kprobe)
1634 if (errno == ENOENT) {
1638 config = "CONFIG_UPROBE_EVENTS";
1640 config = "CONFIG_KPROBE_EVENTS";
1642 pr_warning("%s file does not exist - please rebuild kernel"
1643 " with %s.\n", file, config);
1645 pr_warning("Failed to open %s file: %s\n", file,
1649 static int open_probe_events(const char *trace_file, bool readwrite,
1653 const char *__debugfs;
1656 __debugfs = debugfs_find_mountpoint();
1657 if (__debugfs == NULL) {
1658 pr_warning("Debugfs is not mounted.\n");
1662 ret = e_snprintf(buf, PATH_MAX, "%s/%s", __debugfs, trace_file);
1664 pr_debug("Opening %s write=%d\n", buf, readwrite);
1665 if (readwrite && !probe_event_dry_run)
1666 ret = open(buf, O_RDWR, O_APPEND);
1668 ret = open(buf, O_RDONLY, 0);
1671 print_warn_msg(buf, is_kprobe);
1676 static int open_kprobe_events(bool readwrite)
1678 return open_probe_events("tracing/kprobe_events", readwrite, true);
1681 static int open_uprobe_events(bool readwrite)
1683 return open_probe_events("tracing/uprobe_events", readwrite, false);
1686 /* Get raw string list of current kprobe_events or uprobe_events */
1687 static struct strlist *get_probe_trace_command_rawlist(int fd)
1691 char buf[MAX_CMDLEN];
1695 sl = strlist__new(true, NULL);
1697 fp = fdopen(dup(fd), "r");
1699 p = fgets(buf, MAX_CMDLEN, fp);
1703 idx = strlen(p) - 1;
1706 ret = strlist__add(sl, buf);
1708 pr_debug("strlist__add failed: %s\n", strerror(-ret));
1709 strlist__delete(sl);
1719 static int show_perf_probe_event(struct perf_probe_event *pev)
1725 /* Synthesize only event probe point */
1726 place = synthesize_perf_probe_point(&pev->point);
1730 ret = e_snprintf(buf, 128, "%s:%s", pev->group, pev->event);
1734 printf(" %-20s (on %s", buf, place);
1736 if (pev->nargs > 0) {
1738 for (i = 0; i < pev->nargs; i++) {
1739 ret = synthesize_perf_probe_arg(&pev->args[i],
1751 static int __show_perf_probe_events(int fd, bool is_kprobe)
1754 struct probe_trace_event tev;
1755 struct perf_probe_event pev;
1756 struct strlist *rawlist;
1757 struct str_node *ent;
1759 memset(&tev, 0, sizeof(tev));
1760 memset(&pev, 0, sizeof(pev));
1762 rawlist = get_probe_trace_command_rawlist(fd);
1766 strlist__for_each(ent, rawlist) {
1767 ret = parse_probe_trace_command(ent->s, &tev);
1769 ret = convert_to_perf_probe_event(&tev, &pev,
1772 ret = show_perf_probe_event(&pev);
1774 clear_perf_probe_event(&pev);
1775 clear_probe_trace_event(&tev);
1779 strlist__delete(rawlist);
1784 /* List up current perf-probe events */
1785 int show_perf_probe_events(void)
1790 fd = open_kprobe_events(false);
1795 ret = init_vmlinux();
1799 ret = __show_perf_probe_events(fd, true);
1802 fd = open_uprobe_events(false);
1804 ret = __show_perf_probe_events(fd, false);
1811 /* Get current perf-probe event names */
1812 static struct strlist *get_probe_trace_event_names(int fd, bool include_group)
1815 struct strlist *sl, *rawlist;
1816 struct str_node *ent;
1817 struct probe_trace_event tev;
1820 memset(&tev, 0, sizeof(tev));
1821 rawlist = get_probe_trace_command_rawlist(fd);
1822 sl = strlist__new(true, NULL);
1823 strlist__for_each(ent, rawlist) {
1824 ret = parse_probe_trace_command(ent->s, &tev);
1827 if (include_group) {
1828 ret = e_snprintf(buf, 128, "%s:%s", tev.group,
1831 ret = strlist__add(sl, buf);
1833 ret = strlist__add(sl, tev.event);
1834 clear_probe_trace_event(&tev);
1838 strlist__delete(rawlist);
1841 strlist__delete(sl);
1847 static int write_probe_trace_event(int fd, struct probe_trace_event *tev)
1850 char *buf = synthesize_probe_trace_command(tev);
1853 pr_debug("Failed to synthesize probe trace event.\n");
1857 pr_debug("Writing event: %s\n", buf);
1858 if (!probe_event_dry_run) {
1859 ret = write(fd, buf, strlen(buf));
1861 pr_warning("Failed to write event: %s\n",
1868 static int get_new_event_name(char *buf, size_t len, const char *base,
1869 struct strlist *namelist, bool allow_suffix)
1874 ret = e_snprintf(buf, len, "%s", base);
1876 pr_debug("snprintf() failed: %s\n", strerror(-ret));
1879 if (!strlist__has_entry(namelist, buf))
1882 if (!allow_suffix) {
1883 pr_warning("Error: event \"%s\" already exists. "
1884 "(Use -f to force duplicates.)\n", base);
1888 /* Try to add suffix */
1889 for (i = 1; i < MAX_EVENT_INDEX; i++) {
1890 ret = e_snprintf(buf, len, "%s_%d", base, i);
1892 pr_debug("snprintf() failed: %s\n", strerror(-ret));
1895 if (!strlist__has_entry(namelist, buf))
1898 if (i == MAX_EVENT_INDEX) {
1899 pr_warning("Too many events are on the same function.\n");
1906 static int __add_probe_trace_events(struct perf_probe_event *pev,
1907 struct probe_trace_event *tevs,
1908 int ntevs, bool allow_suffix)
1911 struct probe_trace_event *tev = NULL;
1913 const char *event, *group;
1914 struct strlist *namelist;
1917 fd = open_uprobe_events(true);
1919 fd = open_kprobe_events(true);
1923 /* Get current event names */
1924 namelist = get_probe_trace_event_names(fd, false);
1926 pr_debug("Failed to get current event list.\n");
1931 printf("Added new event%s\n", (ntevs > 1) ? "s:" : ":");
1932 for (i = 0; i < ntevs; i++) {
1937 if (pev->point.function)
1938 event = pev->point.function;
1940 event = tev->point.symbol;
1944 group = PERFPROBE_GROUP;
1946 /* Get an unused new event name */
1947 ret = get_new_event_name(buf, 64, event,
1948 namelist, allow_suffix);
1953 tev->event = strdup(event);
1954 tev->group = strdup(group);
1955 if (tev->event == NULL || tev->group == NULL) {
1959 ret = write_probe_trace_event(fd, tev);
1962 /* Add added event name to namelist */
1963 strlist__add(namelist, event);
1965 /* Trick here - save current event/group */
1968 pev->event = tev->event;
1969 pev->group = tev->group;
1970 show_perf_probe_event(pev);
1971 /* Trick here - restore current event/group */
1972 pev->event = (char *)event;
1973 pev->group = (char *)group;
1976 * Probes after the first probe which comes from same
1977 * user input are always allowed to add suffix, because
1978 * there might be several addresses corresponding to
1981 allow_suffix = true;
1985 /* Show how to use the event. */
1986 printf("\nYou can now use it in all perf tools, such as:\n\n");
1987 printf("\tperf record -e %s:%s -aR sleep 1\n\n", tev->group,
1991 strlist__delete(namelist);
1996 static int convert_to_probe_trace_events(struct perf_probe_event *pev,
1997 struct probe_trace_event **tevs,
1998 int max_tevs, const char *target)
2002 struct probe_trace_event *tev;
2004 if (pev->uprobes && !pev->group) {
2005 /* Replace group name if not given */
2006 ret = convert_exec_to_group(target, &pev->group);
2008 pr_warning("Failed to make a group name.\n");
2013 /* Convert perf_probe_event with debuginfo */
2014 ret = try_to_find_probe_trace_events(pev, tevs, max_tevs, target);
2016 return ret; /* Found in debuginfo or got an error */
2019 ret = convert_name_to_addr(pev, target);
2024 /* Allocate trace event buffer */
2025 tev = *tevs = zalloc(sizeof(struct probe_trace_event));
2029 /* Copy parameters */
2030 tev->point.symbol = strdup(pev->point.function);
2031 if (tev->point.symbol == NULL) {
2037 tev->point.module = strdup(target);
2038 if (tev->point.module == NULL) {
2044 tev->point.offset = pev->point.offset;
2045 tev->point.retprobe = pev->point.retprobe;
2046 tev->nargs = pev->nargs;
2047 tev->uprobes = pev->uprobes;
2050 tev->args = zalloc(sizeof(struct probe_trace_arg)
2052 if (tev->args == NULL) {
2056 for (i = 0; i < tev->nargs; i++) {
2057 if (pev->args[i].name) {
2058 tev->args[i].name = strdup(pev->args[i].name);
2059 if (tev->args[i].name == NULL) {
2064 tev->args[i].value = strdup(pev->args[i].var);
2065 if (tev->args[i].value == NULL) {
2069 if (pev->args[i].type) {
2070 tev->args[i].type = strdup(pev->args[i].type);
2071 if (tev->args[i].type == NULL) {
2082 /* Currently just checking function name from symbol map */
2083 sym = __find_kernel_function_by_name(tev->point.symbol, NULL);
2085 pr_warning("Kernel symbol \'%s\' not found.\n",
2089 } else if (tev->point.offset > sym->end - sym->start) {
2090 pr_warning("Offset specified is greater than size of %s\n",
2099 clear_probe_trace_event(tev);
2105 struct __event_package {
2106 struct perf_probe_event *pev;
2107 struct probe_trace_event *tevs;
2111 int add_perf_probe_events(struct perf_probe_event *pevs, int npevs,
2112 int max_tevs, const char *target, bool force_add)
2115 struct __event_package *pkgs;
2118 pkgs = zalloc(sizeof(struct __event_package) * npevs);
2124 /* Init vmlinux path */
2125 ret = init_vmlinux();
2127 ret = init_user_exec();
2134 /* Loop 1: convert all events */
2135 for (i = 0; i < npevs; i++) {
2136 pkgs[i].pev = &pevs[i];
2137 /* Convert with or without debuginfo */
2138 ret = convert_to_probe_trace_events(pkgs[i].pev,
2144 pkgs[i].ntevs = ret;
2147 /* Loop 2: add all events */
2148 for (i = 0; i < npevs; i++) {
2149 ret = __add_probe_trace_events(pkgs[i].pev, pkgs[i].tevs,
2150 pkgs[i].ntevs, force_add);
2155 /* Loop 3: cleanup and free trace events */
2156 for (i = 0; i < npevs; i++) {
2157 for (j = 0; j < pkgs[i].ntevs; j++)
2158 clear_probe_trace_event(&pkgs[i].tevs[j]);
2159 zfree(&pkgs[i].tevs);
2166 static int __del_trace_probe_event(int fd, struct str_node *ent)
2172 /* Convert from perf-probe event to trace-probe event */
2173 ret = e_snprintf(buf, 128, "-:%s", ent->s);
2177 p = strchr(buf + 2, ':');
2179 pr_debug("Internal error: %s should have ':' but not.\n",
2186 pr_debug("Writing event: %s\n", buf);
2187 ret = write(fd, buf, strlen(buf));
2193 printf("Removed event: %s\n", ent->s);
2196 pr_warning("Failed to delete event: %s\n", strerror(-ret));
2200 static int del_trace_probe_event(int fd, const char *buf,
2201 struct strlist *namelist)
2203 struct str_node *ent, *n;
2206 if (strpbrk(buf, "*?")) { /* Glob-exp */
2207 strlist__for_each_safe(ent, n, namelist)
2208 if (strglobmatch(ent->s, buf)) {
2209 ret = __del_trace_probe_event(fd, ent);
2212 strlist__remove(namelist, ent);
2215 ent = strlist__find(namelist, buf);
2217 ret = __del_trace_probe_event(fd, ent);
2219 strlist__remove(namelist, ent);
2226 int del_perf_probe_events(struct strlist *dellist)
2228 int ret = -1, ufd = -1, kfd = -1;
2230 const char *group, *event;
2232 struct str_node *ent;
2233 struct strlist *namelist = NULL, *unamelist = NULL;
2235 /* Get current event names */
2236 kfd = open_kprobe_events(true);
2240 namelist = get_probe_trace_event_names(kfd, true);
2241 ufd = open_uprobe_events(true);
2244 unamelist = get_probe_trace_event_names(ufd, true);
2246 if (namelist == NULL && unamelist == NULL)
2249 strlist__for_each(ent, dellist) {
2250 str = strdup(ent->s);
2255 pr_debug("Parsing: %s\n", str);
2256 p = strchr(str, ':');
2266 ret = e_snprintf(buf, 128, "%s:%s", group, event);
2268 pr_err("Failed to copy event.");
2273 pr_debug("Group: %s, Event: %s\n", group, event);
2276 ret = del_trace_probe_event(kfd, buf, namelist);
2278 if (unamelist && ret != 0)
2279 ret = del_trace_probe_event(ufd, buf, unamelist);
2282 pr_info("Info: Event \"%s\" does not exist.\n", buf);
2289 strlist__delete(namelist);
2294 strlist__delete(unamelist);
2301 /* TODO: don't use a global variable for filter ... */
2302 static struct strfilter *available_func_filter;
2305 * If a symbol corresponds to a function with global binding and
2306 * matches filter return 0. For all others return 1.
2308 static int filter_available_functions(struct map *map __maybe_unused,
2311 if (sym->binding == STB_GLOBAL &&
2312 strfilter__compare(available_func_filter, sym->name))
2317 static int __show_available_funcs(struct map *map)
2319 if (map__load(map, filter_available_functions)) {
2320 pr_err("Failed to load map.\n");
2323 if (!dso__sorted_by_name(map->dso, map->type))
2324 dso__sort_by_name(map->dso, map->type);
2326 dso__fprintf_symbols_by_name(map->dso, map->type, stdout);
2330 static int available_kernel_funcs(const char *module)
2335 ret = init_vmlinux();
2339 map = kernel_get_module_map(module);
2341 pr_err("Failed to find %s map.\n", (module) ? : "kernel");
2344 return __show_available_funcs(map);
2347 static int available_user_funcs(const char *target)
2352 ret = init_user_exec();
2356 map = dso__new_map(target);
2357 ret = __show_available_funcs(map);
2358 dso__delete(map->dso);
2363 int show_available_funcs(const char *target, struct strfilter *_filter,
2367 available_func_filter = _filter;
2370 return available_kernel_funcs(target);
2372 return available_user_funcs(target);
2376 * uprobe_events only accepts address:
2377 * Convert function and any offset to address
2379 static int convert_name_to_addr(struct perf_probe_event *pev, const char *exec)
2381 struct perf_probe_point *pp = &pev->point;
2383 struct map *map = NULL;
2384 char *function = NULL;
2386 unsigned long long vaddr = 0;
2388 if (!pp->function) {
2389 pr_warning("No function specified for uprobes");
2393 function = strdup(pp->function);
2395 pr_warning("Failed to allocate memory by strdup.\n");
2400 map = dso__new_map(exec);
2402 pr_warning("Cannot find appropriate DSO for %s.\n", exec);
2405 available_func_filter = strfilter__new(function, NULL);
2406 if (map__load(map, filter_available_functions)) {
2407 pr_err("Failed to load map.\n");
2411 sym = map__find_symbol_by_name(map, function, NULL);
2413 pr_warning("Cannot find %s in DSO %s\n", function, exec);
2417 if (map->start > sym->start)
2419 vaddr += sym->start + pp->offset + map->pgoff;
2423 pev->event = function;
2427 char *ptr1, *ptr2, *exec_copy;
2429 pev->group = zalloc(sizeof(char *) * 64);
2430 exec_copy = strdup(exec);
2433 pr_warning("Failed to copy exec string.\n");
2437 ptr1 = strdup(basename(exec_copy));
2439 ptr2 = strpbrk(ptr1, "-._");
2442 e_snprintf(pev->group, 64, "%s_%s", PERFPROBE_GROUP,
2449 pp->function = zalloc(sizeof(char *) * MAX_PROBE_ARGS);
2450 if (!pp->function) {
2452 pr_warning("Failed to allocate memory by zalloc.\n");
2455 e_snprintf(pp->function, MAX_PROBE_ARGS, "0x%llx", vaddr);
2460 dso__delete(map->dso);