diff options
| author | Russell King <rmk+kernel@arm.linux.org.uk> | 2009-12-06 12:00:33 -0500 | 
|---|---|---|
| committer | Russell King <rmk+kernel@arm.linux.org.uk> | 2009-12-06 12:00:33 -0500 | 
| commit | 3d14b5beba35250c548d3851a2b84fce742d8311 (patch) | |
| tree | 065e3d93c3fcbc5ee4c44fa78662393cddbdf6de /tools/perf/util/map.c | |
| parent | 0719dc341389882cc834ed18fc9b7fc6006b2b85 (diff) | |
| parent | 1bf8e6219552d5dd27012d567ec8c4bb9c2d86b4 (diff) | |
Merge branch 'sa1100' into devel
Diffstat (limited to 'tools/perf/util/map.c')
| -rw-r--r-- | tools/perf/util/map.c | 99 | 
1 files changed, 89 insertions, 10 deletions
| diff --git a/tools/perf/util/map.c b/tools/perf/util/map.c index 804e02382739..69f94fe9db20 100644 --- a/tools/perf/util/map.c +++ b/tools/perf/util/map.c | |||
| @@ -3,6 +3,7 @@ | |||
| 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" | ||
| 6 | 7 | ||
| 7 | static inline int is_anon_memory(const char *filename) | 8 | static inline int is_anon_memory(const char *filename) | 
| 8 | { | 9 | { | 
| @@ -19,13 +20,28 @@ static int strcommon(const char *pathname, char *cwd, int cwdlen) | |||
| 19 | return n; | 20 | return n; | 
| 20 | } | 21 | } | 
| 21 | 22 | ||
| 22 | struct map *map__new(struct mmap_event *event, char *cwd, int cwdlen) | 23 | void map__init(struct map *self, enum map_type type, | 
| 24 | u64 start, u64 end, u64 pgoff, struct dso *dso) | ||
| 25 | { | ||
| 26 | self->type = type; | ||
| 27 | self->start = start; | ||
| 28 | self->end = end; | ||
| 29 | self->pgoff = pgoff; | ||
| 30 | self->dso = dso; | ||
| 31 | self->map_ip = map__map_ip; | ||
| 32 | self->unmap_ip = map__unmap_ip; | ||
| 33 | RB_CLEAR_NODE(&self->rb_node); | ||
| 34 | } | ||
| 35 | |||
| 36 | struct map *map__new(struct mmap_event *event, enum map_type type, | ||
| 37 | char *cwd, int cwdlen) | ||
| 23 | { | 38 | { | 
| 24 | struct map *self = malloc(sizeof(*self)); | 39 | struct map *self = malloc(sizeof(*self)); | 
| 25 | 40 | ||
| 26 | if (self != NULL) { | 41 | if (self != NULL) { | 
| 27 | const char *filename = event->filename; | 42 | const char *filename = event->filename; | 
| 28 | char newfilename[PATH_MAX]; | 43 | char newfilename[PATH_MAX]; | 
| 44 | struct dso *dso; | ||
| 29 | int anon; | 45 | int anon; | 
| 30 | 46 | ||
| 31 | if (cwd) { | 47 | if (cwd) { | 
| @@ -45,18 +61,15 @@ static int strcommon(const char *pathname, char *cwd, int cwdlen) | |||
| 45 | filename = newfilename; | 61 | filename = newfilename; | 
| 46 | } | 62 | } | 
| 47 | 63 | ||
| 48 | self->start = event->start; | 64 | dso = dsos__findnew(filename); | 
| 49 | self->end = event->start + event->len; | 65 | if (dso == NULL) | 
| 50 | self->pgoff = event->pgoff; | ||
| 51 | |||
| 52 | self->dso = dsos__findnew(filename); | ||
| 53 | if (self->dso == NULL) | ||
| 54 | goto out_delete; | 66 | goto out_delete; | 
| 55 | 67 | ||
| 68 | map__init(self, type, event->start, event->start + event->len, | ||
| 69 | event->pgoff, dso); | ||
| 70 | |||
| 56 | if (self->dso == vdso || anon) | 71 | if (self->dso == vdso || anon) | 
| 57 | self->map_ip = vdso__map_ip; | 72 | self->map_ip = self->unmap_ip = identity__map_ip; | 
| 58 | else | ||
| 59 | self->map_ip = map__map_ip; | ||
| 60 | } | 73 | } | 
| 61 | return self; | 74 | return self; | 
| 62 | out_delete: | 75 | out_delete: | 
| @@ -64,6 +77,72 @@ out_delete: | |||
| 64 | return NULL; | 77 | return NULL; | 
| 65 | } | 78 | } | 
| 66 | 79 | ||
| 80 | void map__delete(struct map *self) | ||
| 81 | { | ||
| 82 | free(self); | ||
| 83 | } | ||
| 84 | |||
| 85 | void map__fixup_start(struct map *self) | ||
| 86 | { | ||
| 87 | struct rb_root *symbols = &self->dso->symbols[self->type]; | ||
| 88 | struct rb_node *nd = rb_first(symbols); | ||
| 89 | if (nd != NULL) { | ||
| 90 | struct symbol *sym = rb_entry(nd, struct symbol, rb_node); | ||
| 91 | self->start = sym->start; | ||
| 92 | } | ||
| 93 | } | ||
| 94 | |||
| 95 | void map__fixup_end(struct map *self) | ||
| 96 | { | ||
| 97 | struct rb_root *symbols = &self->dso->symbols[self->type]; | ||
| 98 | struct rb_node *nd = rb_last(symbols); | ||
| 99 | if (nd != NULL) { | ||
| 100 | struct symbol *sym = rb_entry(nd, struct symbol, rb_node); | ||
| 101 | self->end = sym->end; | ||
| 102 | } | ||
| 103 | } | ||
| 104 | |||
| 105 | #define DSO__DELETED "(deleted)" | ||
| 106 | |||
| 107 | struct symbol *map__find_symbol(struct map *self, u64 addr, | ||
| 108 | symbol_filter_t filter) | ||
| 109 | { | ||
| 110 | if (!dso__loaded(self->dso, self->type)) { | ||
| 111 | int nr = dso__load(self->dso, self, filter); | ||
| 112 | |||
| 113 | if (nr < 0) { | ||
| 114 | if (self->dso->has_build_id) { | ||
| 115 | char sbuild_id[BUILD_ID_SIZE * 2 + 1]; | ||
| 116 | |||
| 117 | build_id__sprintf(self->dso->build_id, | ||
| 118 | sizeof(self->dso->build_id), | ||
| 119 | sbuild_id); | ||
| 120 | pr_warning("%s with build id %s not found", | ||
| 121 | self->dso->long_name, sbuild_id); | ||
| 122 | } else | ||
| 123 | pr_warning("Failed to open %s", | ||
| 124 | self->dso->long_name); | ||
| 125 | pr_warning(", continuing without symbols\n"); | ||
| 126 | return NULL; | ||
| 127 | } else if (nr == 0) { | ||
| 128 | const char *name = self->dso->long_name; | ||
| 129 | const size_t len = strlen(name); | ||
| 130 | const size_t real_len = len - sizeof(DSO__DELETED); | ||
| 131 | |||
| 132 | if (len > sizeof(DSO__DELETED) && | ||
| 133 | strcmp(name + real_len + 1, DSO__DELETED) == 0) { | ||
| 134 | pr_warning("%.*s was updated, restart the long running apps that use it!\n", | ||
| 135 | (int)real_len, name); | ||
| 136 | } else { | ||
| 137 | pr_warning("no symbols found in %s, maybe install a debug package?\n", name); | ||
| 138 | } | ||
| 139 | return NULL; | ||
| 140 | } | ||
| 141 | } | ||
| 142 | |||
| 143 | return self->dso->find_symbol(self->dso, self->type, addr); | ||
| 144 | } | ||
| 145 | |||
| 67 | struct map *map__clone(struct map *self) | 146 | struct map *map__clone(struct map *self) | 
| 68 | { | 147 | { | 
| 69 | struct map *map = malloc(sizeof(*self)); | 148 | struct map *map = malloc(sizeof(*self)); | 
