diff options
Diffstat (limited to 'tools/perf/util/map.c')
-rw-r--r-- | tools/perf/util/map.c | 162 |
1 files changed, 151 insertions, 11 deletions
diff --git a/tools/perf/util/map.c b/tools/perf/util/map.c index 804e02382739..e509cd59c67d 100644 --- a/tools/perf/util/map.c +++ b/tools/perf/util/map.c | |||
@@ -3,6 +3,12 @@ | |||
3 | #include <stdlib.h> | 3 | #include <stdlib.h> |
4 | #include <string.h> | 4 | #include <string.h> |
5 | #include <stdio.h> | 5 | #include <stdio.h> |
6 | #include "debug.h" | ||
7 | |||
8 | const char *map_type__name[MAP__NR_TYPES] = { | ||
9 | [MAP__FUNCTION] = "Functions", | ||
10 | [MAP__VARIABLE] = "Variables", | ||
11 | }; | ||
6 | 12 | ||
7 | static inline int is_anon_memory(const char *filename) | 13 | static inline int is_anon_memory(const char *filename) |
8 | { | 14 | { |
@@ -19,13 +25,28 @@ static int strcommon(const char *pathname, char *cwd, int cwdlen) | |||
19 | return n; | 25 | return n; |
20 | } | 26 | } |
21 | 27 | ||
22 | struct map *map__new(struct mmap_event *event, char *cwd, int cwdlen) | 28 | void map__init(struct map *self, enum map_type type, |
29 | u64 start, u64 end, u64 pgoff, struct dso *dso) | ||
30 | { | ||
31 | self->type = type; | ||
32 | self->start = start; | ||
33 | self->end = end; | ||
34 | self->pgoff = pgoff; | ||
35 | self->dso = dso; | ||
36 | self->map_ip = map__map_ip; | ||
37 | self->unmap_ip = map__unmap_ip; | ||
38 | RB_CLEAR_NODE(&self->rb_node); | ||
39 | } | ||
40 | |||
41 | struct map *map__new(struct mmap_event *event, enum map_type type, | ||
42 | char *cwd, int cwdlen) | ||
23 | { | 43 | { |
24 | struct map *self = malloc(sizeof(*self)); | 44 | struct map *self = malloc(sizeof(*self)); |
25 | 45 | ||
26 | if (self != NULL) { | 46 | if (self != NULL) { |
27 | const char *filename = event->filename; | 47 | const char *filename = event->filename; |
28 | char newfilename[PATH_MAX]; | 48 | char newfilename[PATH_MAX]; |
49 | struct dso *dso; | ||
29 | int anon; | 50 | int anon; |
30 | 51 | ||
31 | if (cwd) { | 52 | if (cwd) { |
@@ -45,18 +66,20 @@ static int strcommon(const char *pathname, char *cwd, int cwdlen) | |||
45 | filename = newfilename; | 66 | filename = newfilename; |
46 | } | 67 | } |
47 | 68 | ||
48 | self->start = event->start; | 69 | dso = dsos__findnew(filename); |
49 | self->end = event->start + event->len; | 70 | if (dso == NULL) |
50 | self->pgoff = event->pgoff; | ||
51 | |||
52 | self->dso = dsos__findnew(filename); | ||
53 | if (self->dso == NULL) | ||
54 | goto out_delete; | 71 | goto out_delete; |
55 | 72 | ||
56 | if (self->dso == vdso || anon) | 73 | map__init(self, type, event->start, event->start + event->len, |
57 | self->map_ip = vdso__map_ip; | 74 | event->pgoff, dso); |
58 | else | 75 | |
59 | self->map_ip = map__map_ip; | 76 | if (anon) { |
77 | set_identity: | ||
78 | self->map_ip = self->unmap_ip = identity__map_ip; | ||
79 | } else if (strcmp(filename, "[vdso]") == 0) { | ||
80 | dso__set_loaded(dso, self->type); | ||
81 | goto set_identity; | ||
82 | } | ||
60 | } | 83 | } |
61 | return self; | 84 | return self; |
62 | out_delete: | 85 | out_delete: |
@@ -64,6 +87,103 @@ out_delete: | |||
64 | return NULL; | 87 | return NULL; |
65 | } | 88 | } |
66 | 89 | ||
90 | void map__delete(struct map *self) | ||
91 | { | ||
92 | free(self); | ||
93 | } | ||
94 | |||
95 | void map__fixup_start(struct map *self) | ||
96 | { | ||
97 | struct rb_root *symbols = &self->dso->symbols[self->type]; | ||
98 | struct rb_node *nd = rb_first(symbols); | ||
99 | if (nd != NULL) { | ||
100 | struct symbol *sym = rb_entry(nd, struct symbol, rb_node); | ||
101 | self->start = sym->start; | ||
102 | } | ||
103 | } | ||
104 | |||
105 | void map__fixup_end(struct map *self) | ||
106 | { | ||
107 | struct rb_root *symbols = &self->dso->symbols[self->type]; | ||
108 | struct rb_node *nd = rb_last(symbols); | ||
109 | if (nd != NULL) { | ||
110 | struct symbol *sym = rb_entry(nd, struct symbol, rb_node); | ||
111 | self->end = sym->end; | ||
112 | } | ||
113 | } | ||
114 | |||
115 | #define DSO__DELETED "(deleted)" | ||
116 | |||
117 | int map__load(struct map *self, symbol_filter_t filter) | ||
118 | { | ||
119 | const char *name = self->dso->long_name; | ||
120 | int nr; | ||
121 | |||
122 | if (dso__loaded(self->dso, self->type)) | ||
123 | return 0; | ||
124 | |||
125 | nr = dso__load(self->dso, self, filter); | ||
126 | if (nr < 0) { | ||
127 | if (self->dso->has_build_id) { | ||
128 | char sbuild_id[BUILD_ID_SIZE * 2 + 1]; | ||
129 | |||
130 | build_id__sprintf(self->dso->build_id, | ||
131 | sizeof(self->dso->build_id), | ||
132 | sbuild_id); | ||
133 | pr_warning("%s with build id %s not found", | ||
134 | name, sbuild_id); | ||
135 | } else | ||
136 | pr_warning("Failed to open %s", name); | ||
137 | |||
138 | pr_warning(", continuing without symbols\n"); | ||
139 | return -1; | ||
140 | } else if (nr == 0) { | ||
141 | const size_t len = strlen(name); | ||
142 | const size_t real_len = len - sizeof(DSO__DELETED); | ||
143 | |||
144 | if (len > sizeof(DSO__DELETED) && | ||
145 | strcmp(name + real_len + 1, DSO__DELETED) == 0) { | ||
146 | pr_warning("%.*s was updated, restart the long " | ||
147 | "running apps that use it!\n", | ||
148 | (int)real_len, name); | ||
149 | } else { | ||
150 | pr_warning("no symbols found in %s, maybe install " | ||
151 | "a debug package?\n", name); | ||
152 | } | ||
153 | |||
154 | return -1; | ||
155 | } | ||
156 | /* | ||
157 | * Only applies to the kernel, as its symtabs aren't relative like the | ||
158 | * module ones. | ||
159 | */ | ||
160 | if (self->dso->kernel) | ||
161 | map__reloc_vmlinux(self); | ||
162 | |||
163 | return 0; | ||
164 | } | ||
165 | |||
166 | struct symbol *map__find_symbol(struct map *self, u64 addr, | ||
167 | symbol_filter_t filter) | ||
168 | { | ||
169 | if (map__load(self, filter) < 0) | ||
170 | return NULL; | ||
171 | |||
172 | return dso__find_symbol(self->dso, self->type, addr); | ||
173 | } | ||
174 | |||
175 | struct symbol *map__find_symbol_by_name(struct map *self, const char *name, | ||
176 | symbol_filter_t filter) | ||
177 | { | ||
178 | if (map__load(self, filter) < 0) | ||
179 | return NULL; | ||
180 | |||
181 | if (!dso__sorted_by_name(self->dso, self->type)) | ||
182 | dso__sort_by_name(self->dso, self->type); | ||
183 | |||
184 | return dso__find_symbol_by_name(self->dso, self->type, name); | ||
185 | } | ||
186 | |||
67 | struct map *map__clone(struct map *self) | 187 | struct map *map__clone(struct map *self) |
68 | { | 188 | { |
69 | struct map *map = malloc(sizeof(*self)); | 189 | struct map *map = malloc(sizeof(*self)); |
@@ -95,3 +215,23 @@ size_t map__fprintf(struct map *self, FILE *fp) | |||
95 | return fprintf(fp, " %Lx-%Lx %Lx %s\n", | 215 | return fprintf(fp, " %Lx-%Lx %Lx %s\n", |
96 | self->start, self->end, self->pgoff, self->dso->name); | 216 | self->start, self->end, self->pgoff, self->dso->name); |
97 | } | 217 | } |
218 | |||
219 | /* | ||
220 | * objdump wants/reports absolute IPs for ET_EXEC, and RIPs for ET_DYN. | ||
221 | * map->dso->adjust_symbols==1 for ET_EXEC-like cases. | ||
222 | */ | ||
223 | u64 map__rip_2objdump(struct map *map, u64 rip) | ||
224 | { | ||
225 | u64 addr = map->dso->adjust_symbols ? | ||
226 | map->unmap_ip(map, rip) : /* RIP -> IP */ | ||
227 | rip; | ||
228 | return addr; | ||
229 | } | ||
230 | |||
231 | u64 map__objdump_2ip(struct map *map, u64 addr) | ||
232 | { | ||
233 | u64 ip = map->dso->adjust_symbols ? | ||
234 | addr : | ||
235 | map->unmap_ip(map, addr); /* RIP -> IP */ | ||
236 | return ip; | ||
237 | } | ||