8 static inline int is_anon_memory(const char *filename)
10 return strcmp(filename, "//anon") == 0;
13 static int strcommon(const char *pathname, char *cwd, int cwdlen)
17 while (n < cwdlen && pathname[n] == cwd[n])
23 struct map *map__new(struct mmap_event *event, char *cwd, int cwdlen,
24 unsigned int sym_priv_size)
26 struct map *self = malloc(sizeof(*self));
29 const char *filename = event->filename;
30 char newfilename[PATH_MAX];
34 int n = strcommon(filename, cwd, cwdlen);
37 snprintf(newfilename, sizeof(newfilename),
39 filename = newfilename;
43 anon = is_anon_memory(filename);
46 snprintf(newfilename, sizeof(newfilename), "/tmp/perf-%d.map", event->pid);
47 filename = newfilename;
50 self->start = event->start;
51 self->end = event->start + event->len;
52 self->pgoff = event->pgoff;
54 self->dso = dsos__findnew(filename, sym_priv_size);
55 if (self->dso == NULL)
58 if (self->dso == vdso || anon)
59 self->map_ip = self->unmap_ip = identity__map_ip;
61 self->map_ip = map__map_ip;
62 self->unmap_ip = map__unmap_ip;
72 map__find_symbol(struct map *self, u64 ip, symbol_filter_t filter)
74 if (!self->dso->loaded) {
75 int nr = dso__load(self->dso, self, filter);
78 pr_warning("Failed to open %s, continuing without symbols\n",
79 self->dso->long_name);
82 pr_warning("No symbols found in %s, maybe install a debug package?\n",
83 self->dso->long_name);
88 return self->dso->find_symbol(self->dso, ip);
91 struct map *map__clone(struct map *self)
93 struct map *map = malloc(sizeof(*self));
98 memcpy(map, self, sizeof(*self));
103 int map__overlap(struct map *l, struct map *r)
105 if (l->start > r->start) {
111 if (l->end > r->start)
117 size_t map__fprintf(struct map *self, FILE *fp)
119 return fprintf(fp, " %Lx-%Lx %Lx %s\n",
120 self->start, self->end, self->pgoff, self->dso->name);