14 int machine__init(struct machine *machine, const char *root_dir, pid_t pid)
16 map_groups__init(&machine->kmaps);
17 RB_CLEAR_NODE(&machine->rb_node);
18 INIT_LIST_HEAD(&machine->user_dsos);
19 INIT_LIST_HEAD(&machine->kernel_dsos);
21 machine->threads = RB_ROOT;
22 INIT_LIST_HEAD(&machine->dead_threads);
23 machine->last_match = NULL;
25 machine->kmaps.machine = machine;
28 machine->root_dir = strdup(root_dir);
29 if (machine->root_dir == NULL)
32 if (pid != HOST_KERNEL_ID) {
33 struct thread *thread = machine__findnew_thread(machine, pid);
39 snprintf(comm, sizeof(comm), "[guest/%d]", pid);
40 thread__set_comm(thread, comm);
46 static void dsos__delete(struct list_head *dsos)
50 list_for_each_entry_safe(pos, n, dsos, node) {
56 void machine__delete_dead_threads(struct machine *machine)
60 list_for_each_entry_safe(t, n, &machine->dead_threads, node) {
66 void machine__delete_threads(struct machine *machine)
68 struct rb_node *nd = rb_first(&machine->threads);
71 struct thread *t = rb_entry(nd, struct thread, rb_node);
73 rb_erase(&t->rb_node, &machine->threads);
79 void machine__exit(struct machine *machine)
81 map_groups__exit(&machine->kmaps);
82 dsos__delete(&machine->user_dsos);
83 dsos__delete(&machine->kernel_dsos);
84 free(machine->root_dir);
85 machine->root_dir = NULL;
88 void machine__delete(struct machine *machine)
90 machine__exit(machine);
94 struct machine *machines__add(struct rb_root *machines, pid_t pid,
97 struct rb_node **p = &machines->rb_node;
98 struct rb_node *parent = NULL;
99 struct machine *pos, *machine = malloc(sizeof(*machine));
104 if (machine__init(machine, root_dir, pid) != 0) {
111 pos = rb_entry(parent, struct machine, rb_node);
118 rb_link_node(&machine->rb_node, parent, p);
119 rb_insert_color(&machine->rb_node, machines);
124 struct machine *machines__find(struct rb_root *machines, pid_t pid)
126 struct rb_node **p = &machines->rb_node;
127 struct rb_node *parent = NULL;
128 struct machine *machine;
129 struct machine *default_machine = NULL;
133 machine = rb_entry(parent, struct machine, rb_node);
134 if (pid < machine->pid)
136 else if (pid > machine->pid)
141 default_machine = machine;
144 return default_machine;
147 struct machine *machines__findnew(struct rb_root *machines, pid_t pid)
150 const char *root_dir = "";
151 struct machine *machine = machines__find(machines, pid);
153 if (machine && (machine->pid == pid))
156 if ((pid != HOST_KERNEL_ID) &&
157 (pid != DEFAULT_GUEST_KERNEL_ID) &&
158 (symbol_conf.guestmount)) {
159 sprintf(path, "%s/%d", symbol_conf.guestmount, pid);
160 if (access(path, R_OK)) {
161 static struct strlist *seen;
164 seen = strlist__new(true, NULL);
166 if (!strlist__has_entry(seen, path)) {
167 pr_err("Can't access file %s\n", path);
168 strlist__add(seen, path);
176 machine = machines__add(machines, pid, root_dir);
181 void machines__process(struct rb_root *machines,
182 machine__process_t process, void *data)
186 for (nd = rb_first(machines); nd; nd = rb_next(nd)) {
187 struct machine *pos = rb_entry(nd, struct machine, rb_node);
192 char *machine__mmap_name(struct machine *machine, char *bf, size_t size)
194 if (machine__is_host(machine))
195 snprintf(bf, size, "[%s]", "kernel.kallsyms");
196 else if (machine__is_default_guest(machine))
197 snprintf(bf, size, "[%s]", "guest.kernel.kallsyms");
199 snprintf(bf, size, "[%s.%d]", "guest.kernel.kallsyms",
206 void machines__set_id_hdr_size(struct rb_root *machines, u16 id_hdr_size)
208 struct rb_node *node;
209 struct machine *machine;
211 for (node = rb_first(machines); node; node = rb_next(node)) {
212 machine = rb_entry(node, struct machine, rb_node);
213 machine->id_hdr_size = id_hdr_size;
219 static struct thread *__machine__findnew_thread(struct machine *machine, pid_t pid,
222 struct rb_node **p = &machine->threads.rb_node;
223 struct rb_node *parent = NULL;
227 * Font-end cache - PID lookups come in blocks,
228 * so most of the time we dont have to look up
231 if (machine->last_match && machine->last_match->pid == pid)
232 return machine->last_match;
236 th = rb_entry(parent, struct thread, rb_node);
238 if (th->pid == pid) {
239 machine->last_match = th;
252 th = thread__new(pid);
254 rb_link_node(&th->rb_node, parent, p);
255 rb_insert_color(&th->rb_node, &machine->threads);
256 machine->last_match = th;
262 struct thread *machine__findnew_thread(struct machine *machine, pid_t pid)
264 return __machine__findnew_thread(machine, pid, true);
267 struct thread *machine__find_thread(struct machine *machine, pid_t pid)
269 return __machine__findnew_thread(machine, pid, false);
272 int machine__process_comm_event(struct machine *machine, union perf_event *event)
274 struct thread *thread = machine__findnew_thread(machine, event->comm.tid);
277 perf_event__fprintf_comm(event, stdout);
279 if (thread == NULL || thread__set_comm(thread, event->comm.comm)) {
280 dump_printf("problem processing PERF_RECORD_COMM, skipping event.\n");
287 int machine__process_lost_event(struct machine *machine __maybe_unused,
288 union perf_event *event)
290 dump_printf(": id:%" PRIu64 ": lost:%" PRIu64 "\n",
291 event->lost.id, event->lost.lost);
295 struct map *machine__new_module(struct machine *machine, u64 start,
296 const char *filename)
299 struct dso *dso = __dsos__findnew(&machine->kernel_dsos, filename);
304 map = map__new2(start, dso, MAP__FUNCTION);
308 if (machine__is_host(machine))
309 dso->symtab_type = DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE;
311 dso->symtab_type = DSO_BINARY_TYPE__GUEST_KMODULE;
312 map_groups__insert(&machine->kmaps, map);
316 size_t machines__fprintf_dsos(struct rb_root *machines, FILE *fp)
321 for (nd = rb_first(machines); nd; nd = rb_next(nd)) {
322 struct machine *pos = rb_entry(nd, struct machine, rb_node);
323 ret += __dsos__fprintf(&pos->kernel_dsos, fp);
324 ret += __dsos__fprintf(&pos->user_dsos, fp);
330 size_t machine__fprintf_dsos_buildid(struct machine *machine, FILE *fp,
331 bool (skip)(struct dso *dso, int parm), int parm)
333 return __dsos__fprintf_buildid(&machine->kernel_dsos, fp, skip, parm) +
334 __dsos__fprintf_buildid(&machine->user_dsos, fp, skip, parm);
337 size_t machines__fprintf_dsos_buildid(struct rb_root *machines, FILE *fp,
338 bool (skip)(struct dso *dso, int parm), int parm)
343 for (nd = rb_first(machines); nd; nd = rb_next(nd)) {
344 struct machine *pos = rb_entry(nd, struct machine, rb_node);
345 ret += machine__fprintf_dsos_buildid(pos, fp, skip, parm);
350 size_t machine__fprintf_vmlinux_path(struct machine *machine, FILE *fp)
354 struct dso *kdso = machine->vmlinux_maps[MAP__FUNCTION]->dso;
356 if (kdso->has_build_id) {
357 char filename[PATH_MAX];
358 if (dso__build_id_filename(kdso, filename, sizeof(filename)))
359 printed += fprintf(fp, "[0] %s\n", filename);
362 for (i = 0; i < vmlinux_path__nr_entries; ++i)
363 printed += fprintf(fp, "[%d] %s\n",
364 i + kdso->has_build_id, vmlinux_path[i]);
369 size_t machine__fprintf(struct machine *machine, FILE *fp)
374 for (nd = rb_first(&machine->threads); nd; nd = rb_next(nd)) {
375 struct thread *pos = rb_entry(nd, struct thread, rb_node);
377 ret += thread__fprintf(pos, fp);
383 static struct dso *machine__get_kernel(struct machine *machine)
385 const char *vmlinux_name = NULL;
388 if (machine__is_host(machine)) {
389 vmlinux_name = symbol_conf.vmlinux_name;
391 vmlinux_name = "[kernel.kallsyms]";
393 kernel = dso__kernel_findnew(machine, vmlinux_name,
399 if (machine__is_default_guest(machine))
400 vmlinux_name = symbol_conf.default_guest_vmlinux_name;
402 vmlinux_name = machine__mmap_name(machine, bf,
405 kernel = dso__kernel_findnew(machine, vmlinux_name,
407 DSO_TYPE_GUEST_KERNEL);
410 if (kernel != NULL && (!kernel->has_build_id))
411 dso__read_running_kernel_build_id(kernel, machine);
416 struct process_args {
420 static int symbol__in_kernel(void *arg, const char *name,
421 char type __maybe_unused, u64 start)
423 struct process_args *args = arg;
425 if (strchr(name, '['))
432 /* Figure out the start address of kernel map from /proc/kallsyms */
433 static u64 machine__get_kernel_start_addr(struct machine *machine)
435 const char *filename;
437 struct process_args args;
439 if (machine__is_host(machine)) {
440 filename = "/proc/kallsyms";
442 if (machine__is_default_guest(machine))
443 filename = (char *)symbol_conf.default_guest_kallsyms;
445 sprintf(path, "%s/proc/kallsyms", machine->root_dir);
450 if (symbol__restricted_filename(filename, "/proc/kallsyms"))
453 if (kallsyms__parse(filename, &args, symbol__in_kernel) <= 0)
459 int __machine__create_kernel_maps(struct machine *machine, struct dso *kernel)
462 u64 start = machine__get_kernel_start_addr(machine);
464 for (type = 0; type < MAP__NR_TYPES; ++type) {
467 machine->vmlinux_maps[type] = map__new2(start, kernel, type);
468 if (machine->vmlinux_maps[type] == NULL)
471 machine->vmlinux_maps[type]->map_ip =
472 machine->vmlinux_maps[type]->unmap_ip =
474 kmap = map__kmap(machine->vmlinux_maps[type]);
475 kmap->kmaps = &machine->kmaps;
476 map_groups__insert(&machine->kmaps,
477 machine->vmlinux_maps[type]);
483 void machine__destroy_kernel_maps(struct machine *machine)
487 for (type = 0; type < MAP__NR_TYPES; ++type) {
490 if (machine->vmlinux_maps[type] == NULL)
493 kmap = map__kmap(machine->vmlinux_maps[type]);
494 map_groups__remove(&machine->kmaps,
495 machine->vmlinux_maps[type]);
496 if (kmap->ref_reloc_sym) {
498 * ref_reloc_sym is shared among all maps, so free just
501 if (type == MAP__FUNCTION) {
502 free((char *)kmap->ref_reloc_sym->name);
503 kmap->ref_reloc_sym->name = NULL;
504 free(kmap->ref_reloc_sym);
506 kmap->ref_reloc_sym = NULL;
509 map__delete(machine->vmlinux_maps[type]);
510 machine->vmlinux_maps[type] = NULL;
514 int machines__create_guest_kernel_maps(struct rb_root *machines)
517 struct dirent **namelist = NULL;
523 if (symbol_conf.default_guest_vmlinux_name ||
524 symbol_conf.default_guest_modules ||
525 symbol_conf.default_guest_kallsyms) {
526 machines__create_kernel_maps(machines, DEFAULT_GUEST_KERNEL_ID);
529 if (symbol_conf.guestmount) {
530 items = scandir(symbol_conf.guestmount, &namelist, NULL, NULL);
533 for (i = 0; i < items; i++) {
534 if (!isdigit(namelist[i]->d_name[0])) {
535 /* Filter out . and .. */
538 pid = (pid_t)strtol(namelist[i]->d_name, &endp, 10);
539 if ((*endp != '\0') ||
540 (endp == namelist[i]->d_name) ||
542 pr_debug("invalid directory (%s). Skipping.\n",
543 namelist[i]->d_name);
546 sprintf(path, "%s/%s/proc/kallsyms",
547 symbol_conf.guestmount,
548 namelist[i]->d_name);
549 ret = access(path, R_OK);
551 pr_debug("Can't access file %s\n", path);
554 machines__create_kernel_maps(machines, pid);
563 void machines__destroy_guest_kernel_maps(struct rb_root *machines)
565 struct rb_node *next = rb_first(machines);
568 struct machine *pos = rb_entry(next, struct machine, rb_node);
570 next = rb_next(&pos->rb_node);
571 rb_erase(&pos->rb_node, machines);
572 machine__delete(pos);
576 int machines__create_kernel_maps(struct rb_root *machines, pid_t pid)
578 struct machine *machine = machines__findnew(machines, pid);
583 return machine__create_kernel_maps(machine);
586 int machine__load_kallsyms(struct machine *machine, const char *filename,
587 enum map_type type, symbol_filter_t filter)
589 struct map *map = machine->vmlinux_maps[type];
590 int ret = dso__load_kallsyms(map->dso, filename, map, filter);
593 dso__set_loaded(map->dso, type);
595 * Since /proc/kallsyms will have multiple sessions for the
596 * kernel, with modules between them, fixup the end of all
599 __map_groups__fixup_end(&machine->kmaps, type);
605 int machine__load_vmlinux_path(struct machine *machine, enum map_type type,
606 symbol_filter_t filter)
608 struct map *map = machine->vmlinux_maps[type];
609 int ret = dso__load_vmlinux_path(map->dso, map, filter);
612 dso__set_loaded(map->dso, type);
613 map__reloc_vmlinux(map);
619 static void map_groups__fixup_end(struct map_groups *mg)
622 for (i = 0; i < MAP__NR_TYPES; ++i)
623 __map_groups__fixup_end(mg, i);
626 static char *get_kernel_version(const char *root_dir)
628 char version[PATH_MAX];
631 const char *prefix = "Linux version ";
633 sprintf(version, "%s/proc/version", root_dir);
634 file = fopen(version, "r");
639 tmp = fgets(version, sizeof(version), file);
642 name = strstr(version, prefix);
645 name += strlen(prefix);
646 tmp = strchr(name, ' ');
653 static int map_groups__set_modules_path_dir(struct map_groups *mg,
654 const char *dir_name)
657 DIR *dir = opendir(dir_name);
661 pr_debug("%s: cannot open %s dir\n", __func__, dir_name);
665 while ((dent = readdir(dir)) != NULL) {
669 /*sshfs might return bad dent->d_type, so we have to stat*/
670 snprintf(path, sizeof(path), "%s/%s", dir_name, dent->d_name);
674 if (S_ISDIR(st.st_mode)) {
675 if (!strcmp(dent->d_name, ".") ||
676 !strcmp(dent->d_name, ".."))
679 ret = map_groups__set_modules_path_dir(mg, path);
683 char *dot = strrchr(dent->d_name, '.'),
688 if (dot == NULL || strcmp(dot, ".ko"))
690 snprintf(dso_name, sizeof(dso_name), "[%.*s]",
691 (int)(dot - dent->d_name), dent->d_name);
693 strxfrchar(dso_name, '-', '_');
694 map = map_groups__find_by_name(mg, MAP__FUNCTION,
699 long_name = strdup(path);
700 if (long_name == NULL) {
704 dso__set_long_name(map->dso, long_name);
705 map->dso->lname_alloc = 1;
706 dso__kernel_module_get_build_id(map->dso, "");
715 static int machine__set_modules_path(struct machine *machine)
718 char modules_path[PATH_MAX];
720 version = get_kernel_version(machine->root_dir);
724 snprintf(modules_path, sizeof(modules_path), "%s/lib/modules/%s/kernel",
725 machine->root_dir, version);
728 return map_groups__set_modules_path_dir(&machine->kmaps, modules_path);
731 static int machine__create_modules(struct machine *machine)
740 if (machine__is_default_guest(machine))
741 modules = symbol_conf.default_guest_modules;
743 sprintf(path, "%s/proc/modules", machine->root_dir);
747 if (symbol__restricted_filename(path, "/proc/modules"))
750 file = fopen(modules, "r");
754 while (!feof(file)) {
760 line_len = getline(&line, &n, file);
767 line[--line_len] = '\0'; /* \n */
769 sep = strrchr(line, 'x');
773 hex2u64(sep + 1, &start);
775 sep = strchr(line, ' ');
781 snprintf(name, sizeof(name), "[%s]", line);
782 map = machine__new_module(machine, start, name);
784 goto out_delete_line;
785 dso__kernel_module_get_build_id(map->dso, machine->root_dir);
791 return machine__set_modules_path(machine);
799 int machine__create_kernel_maps(struct machine *machine)
801 struct dso *kernel = machine__get_kernel(machine);
803 if (kernel == NULL ||
804 __machine__create_kernel_maps(machine, kernel) < 0)
807 if (symbol_conf.use_modules && machine__create_modules(machine) < 0) {
808 if (machine__is_host(machine))
809 pr_debug("Problems creating module maps, "
810 "continuing anyway...\n");
812 pr_debug("Problems creating module maps for guest %d, "
813 "continuing anyway...\n", machine->pid);
817 * Now that we have all the maps created, just set the ->end of them:
819 map_groups__fixup_end(&machine->kmaps);
823 static void machine__set_kernel_mmap_len(struct machine *machine,
824 union perf_event *event)
828 for (i = 0; i < MAP__NR_TYPES; i++) {
829 machine->vmlinux_maps[i]->start = event->mmap.start;
830 machine->vmlinux_maps[i]->end = (event->mmap.start +
833 * Be a bit paranoid here, some perf.data file came with
834 * a zero sized synthesized MMAP event for the kernel.
836 if (machine->vmlinux_maps[i]->end == 0)
837 machine->vmlinux_maps[i]->end = ~0ULL;
841 static int machine__process_kernel_mmap_event(struct machine *machine,
842 union perf_event *event)
845 char kmmap_prefix[PATH_MAX];
846 enum dso_kernel_type kernel_type;
849 machine__mmap_name(machine, kmmap_prefix, sizeof(kmmap_prefix));
850 if (machine__is_host(machine))
851 kernel_type = DSO_TYPE_KERNEL;
853 kernel_type = DSO_TYPE_GUEST_KERNEL;
855 is_kernel_mmap = memcmp(event->mmap.filename,
857 strlen(kmmap_prefix) - 1) == 0;
858 if (event->mmap.filename[0] == '/' ||
859 (!is_kernel_mmap && event->mmap.filename[0] == '[')) {
861 char short_module_name[1024];
864 if (event->mmap.filename[0] == '/') {
865 name = strrchr(event->mmap.filename, '/');
870 dot = strrchr(name, '.');
873 snprintf(short_module_name, sizeof(short_module_name),
874 "[%.*s]", (int)(dot - name), name);
875 strxfrchar(short_module_name, '-', '_');
877 strcpy(short_module_name, event->mmap.filename);
879 map = machine__new_module(machine, event->mmap.start,
880 event->mmap.filename);
884 name = strdup(short_module_name);
888 map->dso->short_name = name;
889 map->dso->sname_alloc = 1;
890 map->end = map->start + event->mmap.len;
891 } else if (is_kernel_mmap) {
892 const char *symbol_name = (event->mmap.filename +
893 strlen(kmmap_prefix));
895 * Should be there already, from the build-id table in
898 struct dso *kernel = __dsos__findnew(&machine->kernel_dsos,
903 kernel->kernel = kernel_type;
904 if (__machine__create_kernel_maps(machine, kernel) < 0)
907 machine__set_kernel_mmap_len(machine, event);
910 * Avoid using a zero address (kptr_restrict) for the ref reloc
911 * symbol. Effectively having zero here means that at record
912 * time /proc/sys/kernel/kptr_restrict was non zero.
914 if (event->mmap.pgoff != 0) {
915 maps__set_kallsyms_ref_reloc_sym(machine->vmlinux_maps,
920 if (machine__is_default_guest(machine)) {
922 * preload dso of guest kernel and modules
924 dso__load(kernel, machine->vmlinux_maps[MAP__FUNCTION],
933 int machine__process_mmap_event(struct machine *machine, union perf_event *event)
935 u8 cpumode = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK;
936 struct thread *thread;
941 perf_event__fprintf_mmap(event, stdout);
943 if (cpumode == PERF_RECORD_MISC_GUEST_KERNEL ||
944 cpumode == PERF_RECORD_MISC_KERNEL) {
945 ret = machine__process_kernel_mmap_event(machine, event);
951 thread = machine__findnew_thread(machine, event->mmap.pid);
954 map = map__new(&machine->user_dsos, event->mmap.start,
955 event->mmap.len, event->mmap.pgoff,
956 event->mmap.pid, event->mmap.filename,
961 thread__insert_map(thread, map);
965 dump_printf("problem processing PERF_RECORD_MMAP, skipping event.\n");
969 int machine__process_fork_event(struct machine *machine, union perf_event *event)
971 struct thread *thread = machine__findnew_thread(machine, event->fork.tid);
972 struct thread *parent = machine__findnew_thread(machine, event->fork.ptid);
975 perf_event__fprintf_task(event, stdout);
977 if (thread == NULL || parent == NULL ||
978 thread__fork(thread, parent) < 0) {
979 dump_printf("problem processing PERF_RECORD_FORK, skipping event.\n");
986 int machine__process_exit_event(struct machine *machine, union perf_event *event)
988 struct thread *thread = machine__find_thread(machine, event->fork.tid);
991 perf_event__fprintf_task(event, stdout);
994 machine__remove_thread(machine, thread);
999 int machine__process_event(struct machine *machine, union perf_event *event)
1003 switch (event->header.type) {
1004 case PERF_RECORD_COMM:
1005 ret = machine__process_comm_event(machine, event); break;
1006 case PERF_RECORD_MMAP:
1007 ret = machine__process_mmap_event(machine, event); break;
1008 case PERF_RECORD_FORK:
1009 ret = machine__process_fork_event(machine, event); break;
1010 case PERF_RECORD_EXIT:
1011 ret = machine__process_exit_event(machine, event); break;
1012 case PERF_RECORD_LOST:
1013 ret = machine__process_lost_event(machine, event); break;
1022 void machine__remove_thread(struct machine *machine, struct thread *th)
1024 machine->last_match = NULL;
1025 rb_erase(&th->rb_node, &machine->threads);
1027 * We may have references to this thread, for instance in some hist_entry
1028 * instances, so just move them to a separate list.
1030 list_add_tail(&th->node, &machine->dead_threads);
1033 static bool symbol__match_parent_regex(struct symbol *sym)
1035 if (sym->name && !regexec(&parent_regex, sym->name, 0, NULL, 0))
1041 static const u8 cpumodes[] = {
1042 PERF_RECORD_MISC_USER,
1043 PERF_RECORD_MISC_KERNEL,
1044 PERF_RECORD_MISC_GUEST_USER,
1045 PERF_RECORD_MISC_GUEST_KERNEL
1047 #define NCPUMODES (sizeof(cpumodes)/sizeof(u8))
1049 static void ip__resolve_ams(struct machine *machine, struct thread *thread,
1050 struct addr_map_symbol *ams,
1053 struct addr_location al;
1057 memset(&al, 0, sizeof(al));
1059 for (i = 0; i < NCPUMODES; i++) {
1062 * We cannot use the header.misc hint to determine whether a
1063 * branch stack address is user, kernel, guest, hypervisor.
1064 * Branches may straddle the kernel/user/hypervisor boundaries.
1065 * Thus, we have to try consecutively until we find a match
1066 * or else, the symbol is unknown
1068 thread__find_addr_location(thread, machine, m, MAP__FUNCTION,
1075 ams->al_addr = al.addr;
1080 struct branch_info *machine__resolve_bstack(struct machine *machine,
1082 struct branch_stack *bs)
1084 struct branch_info *bi;
1087 bi = calloc(bs->nr, sizeof(struct branch_info));
1091 for (i = 0; i < bs->nr; i++) {
1092 ip__resolve_ams(machine, thr, &bi[i].to, bs->entries[i].to);
1093 ip__resolve_ams(machine, thr, &bi[i].from, bs->entries[i].from);
1094 bi[i].flags = bs->entries[i].flags;
1099 static int machine__resolve_callchain_sample(struct machine *machine,
1100 struct thread *thread,
1101 struct ip_callchain *chain,
1102 struct symbol **parent)
1105 u8 cpumode = PERF_RECORD_MISC_USER;
1109 callchain_cursor_reset(&callchain_cursor);
1111 if (chain->nr > PERF_MAX_STACK_DEPTH) {
1112 pr_warning("corrupted callchain. skipping...\n");
1116 for (i = 0; i < chain->nr; i++) {
1118 struct addr_location al;
1120 if (callchain_param.order == ORDER_CALLEE)
1123 ip = chain->ips[chain->nr - i - 1];
1125 if (ip >= PERF_CONTEXT_MAX) {
1127 case PERF_CONTEXT_HV:
1128 cpumode = PERF_RECORD_MISC_HYPERVISOR;
1130 case PERF_CONTEXT_KERNEL:
1131 cpumode = PERF_RECORD_MISC_KERNEL;
1133 case PERF_CONTEXT_USER:
1134 cpumode = PERF_RECORD_MISC_USER;
1137 pr_debug("invalid callchain context: "
1138 "%"PRId64"\n", (s64) ip);
1140 * It seems the callchain is corrupted.
1143 callchain_cursor_reset(&callchain_cursor);
1149 al.filtered = false;
1150 thread__find_addr_location(thread, machine, cpumode,
1151 MAP__FUNCTION, ip, &al, NULL);
1152 if (al.sym != NULL) {
1153 if (sort__has_parent && !*parent &&
1154 symbol__match_parent_regex(al.sym))
1156 if (!symbol_conf.use_callchain)
1160 err = callchain_cursor_append(&callchain_cursor,
1161 ip, al.map, al.sym);
1169 static int unwind_entry(struct unwind_entry *entry, void *arg)
1171 struct callchain_cursor *cursor = arg;
1172 return callchain_cursor_append(cursor, entry->ip,
1173 entry->map, entry->sym);
1176 int machine__resolve_callchain(struct machine *machine,
1177 struct perf_evsel *evsel,
1178 struct thread *thread,
1179 struct perf_sample *sample,
1180 struct symbol **parent)
1185 callchain_cursor_reset(&callchain_cursor);
1187 ret = machine__resolve_callchain_sample(machine, thread,
1188 sample->callchain, parent);
1192 /* Can we do dwarf post unwind? */
1193 if (!((evsel->attr.sample_type & PERF_SAMPLE_REGS_USER) &&
1194 (evsel->attr.sample_type & PERF_SAMPLE_STACK_USER)))
1197 /* Bail out if nothing was captured. */
1198 if ((!sample->user_regs.regs) ||
1199 (!sample->user_stack.size))
1202 return unwind__get_entries(unwind_entry, &callchain_cursor, machine,
1203 thread, evsel->attr.sample_regs_user,