diff options
Diffstat (limited to 'tools/perf/util/map.c')
-rw-r--r-- | tools/perf/util/map.c | 168 |
1 files changed, 168 insertions, 0 deletions
diff --git a/tools/perf/util/map.c b/tools/perf/util/map.c index 9f2963f9ee9a..e21f98001734 100644 --- a/tools/perf/util/map.c +++ b/tools/perf/util/map.c | |||
@@ -1,4 +1,5 @@ | |||
1 | #include "symbol.h" | 1 | #include "symbol.h" |
2 | #include <errno.h> | ||
2 | #include <limits.h> | 3 | #include <limits.h> |
3 | #include <stdlib.h> | 4 | #include <stdlib.h> |
4 | #include <string.h> | 5 | #include <string.h> |
@@ -234,6 +235,37 @@ u64 map__objdump_2ip(struct map *map, u64 addr) | |||
234 | return ip; | 235 | return ip; |
235 | } | 236 | } |
236 | 237 | ||
238 | void map_groups__init(struct map_groups *self) | ||
239 | { | ||
240 | int i; | ||
241 | for (i = 0; i < MAP__NR_TYPES; ++i) { | ||
242 | self->maps[i] = RB_ROOT; | ||
243 | INIT_LIST_HEAD(&self->removed_maps[i]); | ||
244 | } | ||
245 | } | ||
246 | |||
247 | void map_groups__flush(struct map_groups *self) | ||
248 | { | ||
249 | int type; | ||
250 | |||
251 | for (type = 0; type < MAP__NR_TYPES; type++) { | ||
252 | struct rb_root *root = &self->maps[type]; | ||
253 | struct rb_node *next = rb_first(root); | ||
254 | |||
255 | while (next) { | ||
256 | struct map *pos = rb_entry(next, struct map, rb_node); | ||
257 | next = rb_next(&pos->rb_node); | ||
258 | rb_erase(&pos->rb_node, root); | ||
259 | /* | ||
260 | * We may have references to this map, for | ||
261 | * instance in some hist_entry instances, so | ||
262 | * just move them to a separate list. | ||
263 | */ | ||
264 | list_add_tail(&pos->node, &self->removed_maps[pos->type]); | ||
265 | } | ||
266 | } | ||
267 | } | ||
268 | |||
237 | struct symbol *map_groups__find_symbol(struct map_groups *self, | 269 | struct symbol *map_groups__find_symbol(struct map_groups *self, |
238 | enum map_type type, u64 addr, | 270 | enum map_type type, u64 addr, |
239 | symbol_filter_t filter) | 271 | symbol_filter_t filter) |
@@ -246,6 +278,142 @@ struct symbol *map_groups__find_symbol(struct map_groups *self, | |||
246 | return NULL; | 278 | return NULL; |
247 | } | 279 | } |
248 | 280 | ||
281 | size_t __map_groups__fprintf_maps(struct map_groups *self, | ||
282 | enum map_type type, int verbose, FILE *fp) | ||
283 | { | ||
284 | size_t printed = fprintf(fp, "%s:\n", map_type__name[type]); | ||
285 | struct rb_node *nd; | ||
286 | |||
287 | for (nd = rb_first(&self->maps[type]); nd; nd = rb_next(nd)) { | ||
288 | struct map *pos = rb_entry(nd, struct map, rb_node); | ||
289 | printed += fprintf(fp, "Map:"); | ||
290 | printed += map__fprintf(pos, fp); | ||
291 | if (verbose > 2) { | ||
292 | printed += dso__fprintf(pos->dso, type, fp); | ||
293 | printed += fprintf(fp, "--\n"); | ||
294 | } | ||
295 | } | ||
296 | |||
297 | return printed; | ||
298 | } | ||
299 | |||
300 | size_t map_groups__fprintf_maps(struct map_groups *self, int verbose, FILE *fp) | ||
301 | { | ||
302 | size_t printed = 0, i; | ||
303 | for (i = 0; i < MAP__NR_TYPES; ++i) | ||
304 | printed += __map_groups__fprintf_maps(self, i, verbose, fp); | ||
305 | return printed; | ||
306 | } | ||
307 | |||
308 | static size_t __map_groups__fprintf_removed_maps(struct map_groups *self, | ||
309 | enum map_type type, | ||
310 | int verbose, FILE *fp) | ||
311 | { | ||
312 | struct map *pos; | ||
313 | size_t printed = 0; | ||
314 | |||
315 | list_for_each_entry(pos, &self->removed_maps[type], node) { | ||
316 | printed += fprintf(fp, "Map:"); | ||
317 | printed += map__fprintf(pos, fp); | ||
318 | if (verbose > 1) { | ||
319 | printed += dso__fprintf(pos->dso, type, fp); | ||
320 | printed += fprintf(fp, "--\n"); | ||
321 | } | ||
322 | } | ||
323 | return printed; | ||
324 | } | ||
325 | |||
326 | static size_t map_groups__fprintf_removed_maps(struct map_groups *self, | ||
327 | int verbose, FILE *fp) | ||
328 | { | ||
329 | size_t printed = 0, i; | ||
330 | for (i = 0; i < MAP__NR_TYPES; ++i) | ||
331 | printed += __map_groups__fprintf_removed_maps(self, i, verbose, fp); | ||
332 | return printed; | ||
333 | } | ||
334 | |||
335 | size_t map_groups__fprintf(struct map_groups *self, int verbose, FILE *fp) | ||
336 | { | ||
337 | size_t printed = map_groups__fprintf_maps(self, verbose, fp); | ||
338 | printed += fprintf(fp, "Removed maps:\n"); | ||
339 | return printed + map_groups__fprintf_removed_maps(self, verbose, fp); | ||
340 | } | ||
341 | |||
342 | int map_groups__fixup_overlappings(struct map_groups *self, struct map *map, | ||
343 | int verbose, FILE *fp) | ||
344 | { | ||
345 | struct rb_root *root = &self->maps[map->type]; | ||
346 | struct rb_node *next = rb_first(root); | ||
347 | |||
348 | while (next) { | ||
349 | struct map *pos = rb_entry(next, struct map, rb_node); | ||
350 | next = rb_next(&pos->rb_node); | ||
351 | |||
352 | if (!map__overlap(pos, map)) | ||
353 | continue; | ||
354 | |||
355 | if (verbose >= 2) { | ||
356 | fputs("overlapping maps:\n", fp); | ||
357 | map__fprintf(map, fp); | ||
358 | map__fprintf(pos, fp); | ||
359 | } | ||
360 | |||
361 | rb_erase(&pos->rb_node, root); | ||
362 | /* | ||
363 | * We may have references to this map, for instance in some | ||
364 | * hist_entry instances, so just move them to a separate | ||
365 | * list. | ||
366 | */ | ||
367 | list_add_tail(&pos->node, &self->removed_maps[map->type]); | ||
368 | /* | ||
369 | * Now check if we need to create new maps for areas not | ||
370 | * overlapped by the new map: | ||
371 | */ | ||
372 | if (map->start > pos->start) { | ||
373 | struct map *before = map__clone(pos); | ||
374 | |||
375 | if (before == NULL) | ||
376 | return -ENOMEM; | ||
377 | |||
378 | before->end = map->start - 1; | ||
379 | map_groups__insert(self, before); | ||
380 | if (verbose >= 2) | ||
381 | map__fprintf(before, fp); | ||
382 | } | ||
383 | |||
384 | if (map->end < pos->end) { | ||
385 | struct map *after = map__clone(pos); | ||
386 | |||
387 | if (after == NULL) | ||
388 | return -ENOMEM; | ||
389 | |||
390 | after->start = map->end + 1; | ||
391 | map_groups__insert(self, after); | ||
392 | if (verbose >= 2) | ||
393 | map__fprintf(after, fp); | ||
394 | } | ||
395 | } | ||
396 | |||
397 | return 0; | ||
398 | } | ||
399 | |||
400 | /* | ||
401 | * XXX This should not really _copy_ te maps, but refcount them. | ||
402 | */ | ||
403 | int map_groups__clone(struct map_groups *self, | ||
404 | struct map_groups *parent, enum map_type type) | ||
405 | { | ||
406 | struct rb_node *nd; | ||
407 | for (nd = rb_first(&parent->maps[type]); nd; nd = rb_next(nd)) { | ||
408 | struct map *map = rb_entry(nd, struct map, rb_node); | ||
409 | struct map *new = map__clone(map); | ||
410 | if (new == NULL) | ||
411 | return -ENOMEM; | ||
412 | map_groups__insert(self, new); | ||
413 | } | ||
414 | return 0; | ||
415 | } | ||
416 | |||
249 | static u64 map__reloc_map_ip(struct map *map, u64 ip) | 417 | static u64 map__reloc_map_ip(struct map *map, u64 ip) |
250 | { | 418 | { |
251 | return ip + (s64)map->pgoff; | 419 | return ip + (s64)map->pgoff; |