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 void map__init(struct map *self, enum map_type type,
24 u64 start, u64 end, u64 pgoff, struct dso *dso)
31 self->map_ip = map__map_ip;
32 self->unmap_ip = map__unmap_ip;
33 RB_CLEAR_NODE(&self->rb_node);
36 struct map *map__new(struct mmap_event *event, enum map_type type,
37 char *cwd, int cwdlen)
39 struct map *self = malloc(sizeof(*self));
42 const char *filename = event->filename;
43 char newfilename[PATH_MAX];
48 int n = strcommon(filename, cwd, cwdlen);
51 snprintf(newfilename, sizeof(newfilename),
53 filename = newfilename;
57 anon = is_anon_memory(filename);
60 snprintf(newfilename, sizeof(newfilename), "/tmp/perf-%d.map", event->pid);
61 filename = newfilename;
64 dso = dsos__findnew(filename);
68 map__init(self, type, event->start, event->start + event->len,
73 self->map_ip = self->unmap_ip = identity__map_ip;
74 } else if (strcmp(filename, "[vdso]") == 0) {
75 dso__set_loaded(dso, self->type);
85 void map__delete(struct map *self)
90 void map__fixup_start(struct map *self)
92 struct rb_root *symbols = &self->dso->symbols[self->type];
93 struct rb_node *nd = rb_first(symbols);
95 struct symbol *sym = rb_entry(nd, struct symbol, rb_node);
96 self->start = sym->start;
100 void map__fixup_end(struct map *self)
102 struct rb_root *symbols = &self->dso->symbols[self->type];
103 struct rb_node *nd = rb_last(symbols);
105 struct symbol *sym = rb_entry(nd, struct symbol, rb_node);
106 self->end = sym->end;
110 #define DSO__DELETED "(deleted)"
112 int map__load(struct map *self, symbol_filter_t filter)
114 const char *name = self->dso->long_name;
117 if (dso__loaded(self->dso, self->type))
120 nr = dso__load(self->dso, self, filter);
122 if (self->dso->has_build_id) {
123 char sbuild_id[BUILD_ID_SIZE * 2 + 1];
125 build_id__sprintf(self->dso->build_id,
126 sizeof(self->dso->build_id),
128 pr_warning("%s with build id %s not found",
131 pr_warning("Failed to open %s", name);
133 pr_warning(", continuing without symbols\n");
135 } else if (nr == 0) {
136 const size_t len = strlen(name);
137 const size_t real_len = len - sizeof(DSO__DELETED);
139 if (len > sizeof(DSO__DELETED) &&
140 strcmp(name + real_len + 1, DSO__DELETED) == 0) {
141 pr_warning("%.*s was updated, restart the long "
142 "running apps that use it!\n",
143 (int)real_len, name);
145 pr_warning("no symbols found in %s, maybe install "
146 "a debug package?\n", name);
152 * Only applies to the kernel, as its symtabs aren't relative like the
155 if (self->dso->kernel)
156 map__reloc_vmlinux(self);
161 struct symbol *map__find_symbol(struct map *self, u64 addr,
162 symbol_filter_t filter)
164 if (map__load(self, filter) < 0)
167 return dso__find_symbol(self->dso, self->type, addr);
170 struct symbol *map__find_symbol_by_name(struct map *self, const char *name,
171 symbol_filter_t filter)
173 if (map__load(self, filter) < 0)
176 if (!dso__sorted_by_name(self->dso, self->type))
177 dso__sort_by_name(self->dso, self->type);
179 return dso__find_symbol_by_name(self->dso, self->type, name);
182 struct map *map__clone(struct map *self)
184 struct map *map = malloc(sizeof(*self));
189 memcpy(map, self, sizeof(*self));
194 int map__overlap(struct map *l, struct map *r)
196 if (l->start > r->start) {
202 if (l->end > r->start)
208 size_t map__fprintf(struct map *self, FILE *fp)
210 return fprintf(fp, " %Lx-%Lx %Lx %s\n",
211 self->start, self->end, self->pgoff, self->dso->name);
215 * objdump wants/reports absolute IPs for ET_EXEC, and RIPs for ET_DYN.
216 * map->dso->adjust_symbols==1 for ET_EXEC-like cases.
218 u64 map__rip_2objdump(struct map *map, u64 rip)
220 u64 addr = map->dso->adjust_symbols ?
221 map->unmap_ip(map, rip) : /* RIP -> IP */