static int access_dso_mem(struct unwind_info *ui, Dwarf_Addr addr, Dwarf_Word *data) { struct addr_location al; ssize_t size; thread__find_addr_map(ui->thread, PERF_RECORD_MISC_USER, MAP__FUNCTION, addr, &al); if (!al.map) { /* * We've seen cases (softice) where DWARF unwinder went * through non executable mmaps, which we need to lookup * in MAP__VARIABLE tree. */ thread__find_addr_map(ui->thread, PERF_RECORD_MISC_USER, MAP__VARIABLE, addr, &al); } if (!al.map) { pr_debug("unwind: no map for %lx\n", (unsigned long)addr); return -1; } if (!al.map->dso) return -1; size = dso__data_read_addr(al.map->dso, al.map, ui->machine, addr, (u8 *) data, sizeof(*data)); return !(size == sizeof(*data)); }
static int mmap_events(synth_cb synth) { struct machines machines; struct machine *machine; int err, i; /* * The threads_create will not return before all threads * are spawned and all created memory map. * * They will loop until threads_destroy is called, so we * can safely run synthesizing function. */ TEST_ASSERT_VAL("failed to create threads", !threads_create()); machines__init(&machines); machine = &machines.host; dump_trace = verbose > 1 ? 1 : 0; err = synth(machine); dump_trace = 0; TEST_ASSERT_VAL("failed to destroy threads", !threads_destroy()); TEST_ASSERT_VAL("failed to synthesize maps", !err); /* * All data is synthesized, try to find map for each * thread object. */ for (i = 0; i < THREADS; i++) { struct thread_data *td = &threads[i]; struct addr_location al; struct thread *thread; thread = machine__findnew_thread(machine, getpid(), td->tid); pr_debug("looking for map %p\n", td->map); thread__find_addr_map(thread, PERF_RECORD_MISC_USER, MAP__FUNCTION, (unsigned long) (td->map + 1), &al); thread__put(thread); if (!al.map) { pr_debug("failed, couldn't find map\n"); err = -1; break; } pr_debug("map %p, addr %" PRIx64 "\n", al.map, al.map->start); } machine__delete_threads(machine); machines__exit(&machines); return err; }
void thread__find_addr_location(struct thread *self, struct perf_session *session, u8 cpumode, enum map_type type, u64 addr, struct addr_location *al, symbol_filter_t filter) { thread__find_addr_map(self, session, cpumode, type, addr, al); if (al->map != NULL) al->sym = map__find_symbol(al->map, al->addr, filter); else al->sym = NULL; }
static int build_id__mark_dso_hit(event_t *event, struct perf_session *session) { struct addr_location al; u8 cpumode = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK; struct thread *thread = perf_session__findnew(session, event->ip.pid); if (thread == NULL) { pr_err("problem processing %d event, skipping it.\n", event->header.type); return -1; } thread__find_addr_map(thread, session, cpumode, MAP__FUNCTION, event->ip.ip, &al); if (al.map != NULL) al.map->dso->hit = 1; return 0; }
static int access_dso_mem(struct unwind_info *ui, Dwarf_Addr addr, Dwarf_Word *data) { struct addr_location al; ssize_t size; thread__find_addr_map(ui->thread, ui->machine, PERF_RECORD_MISC_USER, MAP__FUNCTION, addr, &al); if (!al.map) { pr_debug("unwind: no map for %lx\n", (unsigned long)addr); return -1; } if (!al.map->dso) return -1; size = dso__data_read_addr(al.map->dso, al.map, ui->machine, addr, (u8 *) data, sizeof(*data)); return !(size == sizeof(*data)); }
static int read_object_code(u64 addr, size_t len, u8 cpumode, struct thread *thread, struct machine *machine, struct state *state) { struct addr_location al; unsigned char buf1[BUFSZ]; unsigned char buf2[BUFSZ]; size_t ret_len; u64 objdump_addr; int ret; pr_debug("Reading object code for memory address: %#"PRIx64"\n", addr); thread__find_addr_map(thread, machine, cpumode, MAP__FUNCTION, addr, &al); if (!al.map || !al.map->dso) { pr_debug("thread__find_addr_map failed\n"); return -1; } pr_debug("File is: %s\n", al.map->dso->long_name); if (al.map->dso->symtab_type == DSO_BINARY_TYPE__KALLSYMS && !dso__is_kcore(al.map->dso)) { pr_debug("Unexpected kernel address - skipping\n"); return 0; } pr_debug("On file address is: %#"PRIx64"\n", al.addr); if (len > BUFSZ) len = BUFSZ; /* Do not go off the map */ if (addr + len > al.map->end) len = al.map->end - addr; /* Read the object code using perf */ ret_len = dso__data_read_offset(al.map->dso, machine, al.addr, buf1, len); if (ret_len != len) { pr_debug("dso__data_read_offset failed\n"); return -1; } /* * Converting addresses for use by objdump requires more information. * map__load() does that. See map__rip_2objdump() for details. */ if (map__load(al.map, NULL)) return -1; /* objdump struggles with kcore - try each map only once */ if (dso__is_kcore(al.map->dso)) { size_t d; for (d = 0; d < state->done_cnt; d++) { if (state->done[d] == al.map->start) { pr_debug("kcore map tested already"); pr_debug(" - skipping\n"); return 0; } } if (state->done_cnt >= ARRAY_SIZE(state->done)) { pr_debug("Too many kcore maps - skipping\n"); return 0; } state->done[state->done_cnt++] = al.map->start; } /* Read the object code using objdump */ objdump_addr = map__rip_2objdump(al.map, al.addr); ret = read_via_objdump(al.map->dso->long_name, objdump_addr, buf2, len); if (ret > 0) { /* * The kernel maps are inaccurate - assume objdump is right in * that case. */ if (cpumode == PERF_RECORD_MISC_KERNEL || cpumode == PERF_RECORD_MISC_GUEST_KERNEL) { len -= ret; if (len) { pr_debug("Reducing len to %zu\n", len); } else if (dso__is_kcore(al.map->dso)) { /* * objdump cannot handle very large segments * that may be found in kcore. */ pr_debug("objdump failed for kcore"); pr_debug(" - skipping\n"); return 0; } else { return -1; } } } if (ret < 0) { pr_debug("read_via_objdump failed\n"); return -1; } /* The results should be identical */ if (memcmp(buf1, buf2, len)) { pr_debug("Bytes read differ from those read by objdump\n"); return -1; } pr_debug("Bytes read match those read by objdump\n"); return 0; }
int event__preprocess_sample(const event_t *self, struct perf_session *session, struct addr_location *al, symbol_filter_t filter) { u8 cpumode = self->header.misc & PERF_RECORD_MISC_CPUMODE_MASK; struct thread *thread = perf_session__findnew(session, self->ip.pid); if (thread == NULL) return -1; if (symbol_conf.comm_list && !strlist__has_entry(symbol_conf.comm_list, thread->comm)) goto out_filtered; dump_printf(" ... thread: %s:%d\n", thread->comm, thread->pid); /* * Have we already created the kernel maps for the host machine? * * This should have happened earlier, when we processed the kernel MMAP * events, but for older perf.data files there was no such thing, so do * it now. */ if (cpumode == PERF_RECORD_MISC_KERNEL && session->host_machine.vmlinux_maps[MAP__FUNCTION] == NULL) machine__create_kernel_maps(&session->host_machine); thread__find_addr_map(thread, session, cpumode, MAP__FUNCTION, self->ip.pid, self->ip.ip, al); dump_printf(" ...... dso: %s\n", al->map ? al->map->dso->long_name : al->level == 'H' ? "[hypervisor]" : "<not found>"); al->sym = NULL; if (al->map) { if (symbol_conf.dso_list && (!al->map || !al->map->dso || !(strlist__has_entry(symbol_conf.dso_list, al->map->dso->short_name) || (al->map->dso->short_name != al->map->dso->long_name && strlist__has_entry(symbol_conf.dso_list, al->map->dso->long_name))))) goto out_filtered; /* * We have to do this here as we may have a dso with no symbol * hit that has a name longer than the ones with symbols * sampled. */ if (!sort_dso.elide && !al->map->dso->slen_calculated) dso__calc_col_width(al->map->dso); al->sym = map__find_symbol(al->map, al->addr, filter); } else { const unsigned int unresolved_col_width = BITS_PER_LONG / 4; if (dsos__col_width < unresolved_col_width && !symbol_conf.col_width_list_str && !symbol_conf.field_sep && !symbol_conf.dso_list) dsos__col_width = unresolved_col_width; } if (symbol_conf.sym_list && al->sym && !strlist__has_entry(symbol_conf.sym_list, al->sym->name)) goto out_filtered; return 0; out_filtered: al->filtered = true; return 0; }