Arnaldo Carvalho de Melo | 5aab621 | 2010-03-25 19:59:00 -0300 | [diff] [blame] | 1 | #include <dirent.h> |
| 2 | #include <errno.h> |
Arnaldo Carvalho de Melo | 5aab621 | 2010-03-25 19:59:00 -0300 | [diff] [blame] | 3 | #include <stdlib.h> |
| 4 | #include <stdio.h> |
| 5 | #include <string.h> |
| 6 | #include <sys/types.h> |
| 7 | #include <sys/stat.h> |
| 8 | #include <sys/param.h> |
| 9 | #include <fcntl.h> |
| 10 | #include <unistd.h> |
Arnaldo Carvalho de Melo | 9486aa3 | 2011-01-22 20:37:02 -0200 | [diff] [blame] | 11 | #include <inttypes.h> |
Arnaldo Carvalho de Melo | b36f19d | 2010-05-20 12:15:33 -0300 | [diff] [blame] | 12 | #include "build-id.h" |
Namhyung Kim | e334c72 | 2012-02-10 10:10:17 +0900 | [diff] [blame] | 13 | #include "util.h" |
Arnaldo Carvalho de Melo | 8a6c5b2 | 2010-07-20 14:42:52 -0300 | [diff] [blame] | 14 | #include "debug.h" |
Arnaldo Carvalho de Melo | 69d2591 | 2012-11-09 11:32:52 -0300 | [diff] [blame] | 15 | #include "machine.h" |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 16 | #include "symbol.h" |
Arnaldo Carvalho de Melo | 5aab621 | 2010-03-25 19:59:00 -0300 | [diff] [blame] | 17 | #include "strlist.h" |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 18 | |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 19 | #include <elf.h> |
Arnaldo Carvalho de Melo | f1617b4 | 2009-11-18 20:20:52 -0200 | [diff] [blame] | 20 | #include <limits.h> |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 21 | #include <sys/utsname.h> |
Peter Zijlstra | 2cdbc46 | 2009-08-05 14:05:16 +0200 | [diff] [blame] | 22 | |
Arnaldo Carvalho de Melo | 3b01a41 | 2010-12-22 01:08:36 -0200 | [diff] [blame] | 23 | #ifndef KSYM_NAME_LEN |
Ricardo Ribalda Delgado | c752d04 | 2011-10-20 09:43:26 +0200 | [diff] [blame] | 24 | #define KSYM_NAME_LEN 256 |
Arnaldo Carvalho de Melo | 3b01a41 | 2010-12-22 01:08:36 -0200 | [diff] [blame] | 25 | #endif |
| 26 | |
Arnaldo Carvalho de Melo | aeafcba | 2011-03-31 10:56:28 -0300 | [diff] [blame] | 27 | static int dso__load_kernel_sym(struct dso *dso, struct map *map, |
Arnaldo Carvalho de Melo | 9de89fe | 2010-02-03 16:52:00 -0200 | [diff] [blame] | 28 | symbol_filter_t filter); |
Arnaldo Carvalho de Melo | aeafcba | 2011-03-31 10:56:28 -0300 | [diff] [blame] | 29 | static int dso__load_guest_kernel_sym(struct dso *dso, struct map *map, |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 30 | symbol_filter_t filter); |
Arnaldo Carvalho de Melo | 3f067dc | 2012-12-07 17:39:39 -0300 | [diff] [blame] | 31 | int vmlinux_path__nr_entries; |
| 32 | char **vmlinux_path; |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 33 | |
Arnaldo Carvalho de Melo | 75be6cf | 2009-12-15 20:04:39 -0200 | [diff] [blame] | 34 | struct symbol_conf symbol_conf = { |
Arnaldo Carvalho de Melo | b32d133 | 2009-11-24 12:05:15 -0200 | [diff] [blame] | 35 | .use_modules = true, |
| 36 | .try_vmlinux_path = true, |
Stephane Eranian | 3e6a2a7 | 2011-05-17 17:32:07 +0200 | [diff] [blame] | 37 | .annotate_src = true, |
Namhyung Kim | 328ccda | 2013-03-25 18:18:18 +0900 | [diff] [blame] | 38 | .demangle = true, |
David Ahern | ec5761e | 2010-12-09 13:27:07 -0700 | [diff] [blame] | 39 | .symfs = "", |
Arnaldo Carvalho de Melo | b32d133 | 2009-11-24 12:05:15 -0200 | [diff] [blame] | 40 | }; |
| 41 | |
Jiri Olsa | 44f24cb | 2012-07-22 14:14:32 +0200 | [diff] [blame] | 42 | static enum dso_binary_type binary_type_symtab[] = { |
| 43 | DSO_BINARY_TYPE__KALLSYMS, |
| 44 | DSO_BINARY_TYPE__GUEST_KALLSYMS, |
| 45 | DSO_BINARY_TYPE__JAVA_JIT, |
| 46 | DSO_BINARY_TYPE__DEBUGLINK, |
| 47 | DSO_BINARY_TYPE__BUILD_ID_CACHE, |
| 48 | DSO_BINARY_TYPE__FEDORA_DEBUGINFO, |
| 49 | DSO_BINARY_TYPE__UBUNTU_DEBUGINFO, |
| 50 | DSO_BINARY_TYPE__BUILDID_DEBUGINFO, |
| 51 | DSO_BINARY_TYPE__SYSTEM_PATH_DSO, |
| 52 | DSO_BINARY_TYPE__GUEST_KMODULE, |
| 53 | DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE, |
Ricardo Ribalda Delgado | 9cd0094 | 2013-09-18 15:56:14 +0200 | [diff] [blame] | 54 | DSO_BINARY_TYPE__OPENEMBEDDED_DEBUGINFO, |
Jiri Olsa | 44f24cb | 2012-07-22 14:14:32 +0200 | [diff] [blame] | 55 | DSO_BINARY_TYPE__NOT_FOUND, |
| 56 | }; |
| 57 | |
Jiri Olsa | 028df76 | 2012-08-01 14:47:57 +0200 | [diff] [blame] | 58 | #define DSO_BINARY_TYPE__SYMTAB_CNT ARRAY_SIZE(binary_type_symtab) |
Jiri Olsa | 44f24cb | 2012-07-22 14:14:32 +0200 | [diff] [blame] | 59 | |
Arnaldo Carvalho de Melo | 36a3e64 | 2010-01-04 16:19:27 -0200 | [diff] [blame] | 60 | bool symbol_type__is_a(char symbol_type, enum map_type map_type) |
Arnaldo Carvalho de Melo | 6893d4e | 2009-12-11 14:50:37 -0200 | [diff] [blame] | 61 | { |
Anton Blanchard | 3187790 | 2011-08-24 16:40:16 +1000 | [diff] [blame] | 62 | symbol_type = toupper(symbol_type); |
| 63 | |
Arnaldo Carvalho de Melo | 6893d4e | 2009-12-11 14:50:37 -0200 | [diff] [blame] | 64 | switch (map_type) { |
| 65 | case MAP__FUNCTION: |
| 66 | return symbol_type == 'T' || symbol_type == 'W'; |
Arnaldo Carvalho de Melo | f1dfa0b | 2009-12-11 14:50:39 -0200 | [diff] [blame] | 67 | case MAP__VARIABLE: |
Anton Blanchard | 3187790 | 2011-08-24 16:40:16 +1000 | [diff] [blame] | 68 | return symbol_type == 'D'; |
Arnaldo Carvalho de Melo | 6893d4e | 2009-12-11 14:50:37 -0200 | [diff] [blame] | 69 | default: |
| 70 | return false; |
| 71 | } |
| 72 | } |
| 73 | |
Anton Blanchard | 694bf40 | 2011-08-24 16:40:17 +1000 | [diff] [blame] | 74 | static int prefix_underscores_count(const char *str) |
| 75 | { |
| 76 | const char *tail = str; |
| 77 | |
| 78 | while (*tail == '_') |
| 79 | tail++; |
| 80 | |
| 81 | return tail - str; |
| 82 | } |
| 83 | |
| 84 | #define SYMBOL_A 0 |
| 85 | #define SYMBOL_B 1 |
| 86 | |
| 87 | static int choose_best_symbol(struct symbol *syma, struct symbol *symb) |
| 88 | { |
| 89 | s64 a; |
| 90 | s64 b; |
Adrian Hunter | 3445432 | 2013-08-07 14:38:49 +0300 | [diff] [blame] | 91 | size_t na, nb; |
Anton Blanchard | 694bf40 | 2011-08-24 16:40:17 +1000 | [diff] [blame] | 92 | |
| 93 | /* Prefer a symbol with non zero length */ |
| 94 | a = syma->end - syma->start; |
| 95 | b = symb->end - symb->start; |
| 96 | if ((b == 0) && (a > 0)) |
| 97 | return SYMBOL_A; |
| 98 | else if ((a == 0) && (b > 0)) |
| 99 | return SYMBOL_B; |
| 100 | |
| 101 | /* Prefer a non weak symbol over a weak one */ |
| 102 | a = syma->binding == STB_WEAK; |
| 103 | b = symb->binding == STB_WEAK; |
| 104 | if (b && !a) |
| 105 | return SYMBOL_A; |
| 106 | if (a && !b) |
| 107 | return SYMBOL_B; |
| 108 | |
| 109 | /* Prefer a global symbol over a non global one */ |
| 110 | a = syma->binding == STB_GLOBAL; |
| 111 | b = symb->binding == STB_GLOBAL; |
| 112 | if (a && !b) |
| 113 | return SYMBOL_A; |
| 114 | if (b && !a) |
| 115 | return SYMBOL_B; |
| 116 | |
| 117 | /* Prefer a symbol with less underscores */ |
| 118 | a = prefix_underscores_count(syma->name); |
| 119 | b = prefix_underscores_count(symb->name); |
| 120 | if (b > a) |
| 121 | return SYMBOL_A; |
| 122 | else if (a > b) |
| 123 | return SYMBOL_B; |
| 124 | |
Adrian Hunter | 3445432 | 2013-08-07 14:38:49 +0300 | [diff] [blame] | 125 | /* Choose the symbol with the longest name */ |
| 126 | na = strlen(syma->name); |
| 127 | nb = strlen(symb->name); |
| 128 | if (na > nb) |
Anton Blanchard | 694bf40 | 2011-08-24 16:40:17 +1000 | [diff] [blame] | 129 | return SYMBOL_A; |
Adrian Hunter | 3445432 | 2013-08-07 14:38:49 +0300 | [diff] [blame] | 130 | else if (na < nb) |
Anton Blanchard | 694bf40 | 2011-08-24 16:40:17 +1000 | [diff] [blame] | 131 | return SYMBOL_B; |
Adrian Hunter | 3445432 | 2013-08-07 14:38:49 +0300 | [diff] [blame] | 132 | |
| 133 | /* Avoid "SyS" kernel syscall aliases */ |
| 134 | if (na >= 3 && !strncmp(syma->name, "SyS", 3)) |
| 135 | return SYMBOL_B; |
| 136 | if (na >= 10 && !strncmp(syma->name, "compat_SyS", 10)) |
| 137 | return SYMBOL_B; |
| 138 | |
| 139 | return SYMBOL_A; |
Anton Blanchard | 694bf40 | 2011-08-24 16:40:17 +1000 | [diff] [blame] | 140 | } |
| 141 | |
Namhyung Kim | e5a1845 | 2012-08-06 13:41:20 +0900 | [diff] [blame] | 142 | void symbols__fixup_duplicate(struct rb_root *symbols) |
Anton Blanchard | 694bf40 | 2011-08-24 16:40:17 +1000 | [diff] [blame] | 143 | { |
| 144 | struct rb_node *nd; |
| 145 | struct symbol *curr, *next; |
| 146 | |
| 147 | nd = rb_first(symbols); |
| 148 | |
| 149 | while (nd) { |
| 150 | curr = rb_entry(nd, struct symbol, rb_node); |
| 151 | again: |
| 152 | nd = rb_next(&curr->rb_node); |
| 153 | next = rb_entry(nd, struct symbol, rb_node); |
| 154 | |
| 155 | if (!nd) |
| 156 | break; |
| 157 | |
| 158 | if (curr->start != next->start) |
| 159 | continue; |
| 160 | |
| 161 | if (choose_best_symbol(curr, next) == SYMBOL_A) { |
| 162 | rb_erase(&next->rb_node, symbols); |
| 163 | goto again; |
| 164 | } else { |
| 165 | nd = rb_next(&curr->rb_node); |
| 166 | rb_erase(&curr->rb_node, symbols); |
| 167 | } |
| 168 | } |
| 169 | } |
| 170 | |
Namhyung Kim | e5a1845 | 2012-08-06 13:41:20 +0900 | [diff] [blame] | 171 | void symbols__fixup_end(struct rb_root *symbols) |
Arnaldo Carvalho de Melo | af427bf | 2009-10-05 14:26:17 -0300 | [diff] [blame] | 172 | { |
Arnaldo Carvalho de Melo | aeafcba | 2011-03-31 10:56:28 -0300 | [diff] [blame] | 173 | struct rb_node *nd, *prevnd = rb_first(symbols); |
Arnaldo Carvalho de Melo | 2e538c4 | 2009-10-07 13:48:56 -0300 | [diff] [blame] | 174 | struct symbol *curr, *prev; |
Arnaldo Carvalho de Melo | af427bf | 2009-10-05 14:26:17 -0300 | [diff] [blame] | 175 | |
| 176 | if (prevnd == NULL) |
| 177 | return; |
| 178 | |
Arnaldo Carvalho de Melo | 2e538c4 | 2009-10-07 13:48:56 -0300 | [diff] [blame] | 179 | curr = rb_entry(prevnd, struct symbol, rb_node); |
| 180 | |
Arnaldo Carvalho de Melo | af427bf | 2009-10-05 14:26:17 -0300 | [diff] [blame] | 181 | for (nd = rb_next(prevnd); nd; nd = rb_next(nd)) { |
Arnaldo Carvalho de Melo | 2e538c4 | 2009-10-07 13:48:56 -0300 | [diff] [blame] | 182 | prev = curr; |
| 183 | curr = rb_entry(nd, struct symbol, rb_node); |
Arnaldo Carvalho de Melo | af427bf | 2009-10-05 14:26:17 -0300 | [diff] [blame] | 184 | |
Arnaldo Carvalho de Melo | 3b01a41 | 2010-12-22 01:08:36 -0200 | [diff] [blame] | 185 | if (prev->end == prev->start && prev->end != curr->start) |
Arnaldo Carvalho de Melo | af427bf | 2009-10-05 14:26:17 -0300 | [diff] [blame] | 186 | prev->end = curr->start - 1; |
Arnaldo Carvalho de Melo | af427bf | 2009-10-05 14:26:17 -0300 | [diff] [blame] | 187 | } |
Arnaldo Carvalho de Melo | 2e538c4 | 2009-10-07 13:48:56 -0300 | [diff] [blame] | 188 | |
| 189 | /* Last entry */ |
| 190 | if (curr->end == curr->start) |
| 191 | curr->end = roundup(curr->start, 4096); |
Arnaldo Carvalho de Melo | af427bf | 2009-10-05 14:26:17 -0300 | [diff] [blame] | 192 | } |
| 193 | |
Namhyung Kim | e5a1845 | 2012-08-06 13:41:20 +0900 | [diff] [blame] | 194 | void __map_groups__fixup_end(struct map_groups *mg, enum map_type type) |
Arnaldo Carvalho de Melo | af427bf | 2009-10-05 14:26:17 -0300 | [diff] [blame] | 195 | { |
| 196 | struct map *prev, *curr; |
Arnaldo Carvalho de Melo | aeafcba | 2011-03-31 10:56:28 -0300 | [diff] [blame] | 197 | struct rb_node *nd, *prevnd = rb_first(&mg->maps[type]); |
Arnaldo Carvalho de Melo | af427bf | 2009-10-05 14:26:17 -0300 | [diff] [blame] | 198 | |
| 199 | if (prevnd == NULL) |
| 200 | return; |
| 201 | |
| 202 | curr = rb_entry(prevnd, struct map, rb_node); |
Arnaldo Carvalho de Melo | af427bf | 2009-10-05 14:26:17 -0300 | [diff] [blame] | 203 | |
| 204 | for (nd = rb_next(prevnd); nd; nd = rb_next(nd)) { |
| 205 | prev = curr; |
| 206 | curr = rb_entry(nd, struct map, rb_node); |
| 207 | prev->end = curr->start - 1; |
Arnaldo Carvalho de Melo | 2e538c4 | 2009-10-07 13:48:56 -0300 | [diff] [blame] | 208 | } |
Arnaldo Carvalho de Melo | 90c8321 | 2009-11-21 14:31:24 -0200 | [diff] [blame] | 209 | |
| 210 | /* |
| 211 | * We still haven't the actual symbols, so guess the |
| 212 | * last map final address. |
| 213 | */ |
Ian Munsie | 9d1faba | 2010-11-25 15:12:53 +1100 | [diff] [blame] | 214 | curr->end = ~0ULL; |
Arnaldo Carvalho de Melo | af427bf | 2009-10-05 14:26:17 -0300 | [diff] [blame] | 215 | } |
| 216 | |
Namhyung Kim | e5a1845 | 2012-08-06 13:41:20 +0900 | [diff] [blame] | 217 | struct symbol *symbol__new(u64 start, u64 len, u8 binding, const char *name) |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 218 | { |
Arnaldo Carvalho de Melo | 0085c954 | 2009-05-28 14:55:13 -0300 | [diff] [blame] | 219 | size_t namelen = strlen(name) + 1; |
Arnaldo Carvalho de Melo | aeafcba | 2011-03-31 10:56:28 -0300 | [diff] [blame] | 220 | struct symbol *sym = calloc(1, (symbol_conf.priv_size + |
| 221 | sizeof(*sym) + namelen)); |
| 222 | if (sym == NULL) |
Ingo Molnar | 0b73da3 | 2009-06-06 15:48:52 +0200 | [diff] [blame] | 223 | return NULL; |
| 224 | |
Arnaldo Carvalho de Melo | 75be6cf | 2009-12-15 20:04:39 -0200 | [diff] [blame] | 225 | if (symbol_conf.priv_size) |
Arnaldo Carvalho de Melo | aeafcba | 2011-03-31 10:56:28 -0300 | [diff] [blame] | 226 | sym = ((void *)sym) + symbol_conf.priv_size; |
Arnaldo Carvalho de Melo | 3647948 | 2009-11-24 12:05:16 -0200 | [diff] [blame] | 227 | |
Arnaldo Carvalho de Melo | aeafcba | 2011-03-31 10:56:28 -0300 | [diff] [blame] | 228 | sym->start = start; |
| 229 | sym->end = len ? start + len - 1 : start; |
| 230 | sym->binding = binding; |
| 231 | sym->namelen = namelen - 1; |
Arnaldo Carvalho de Melo | e420499 | 2009-10-20 14:25:40 -0200 | [diff] [blame] | 232 | |
Arnaldo Carvalho de Melo | aeafcba | 2011-03-31 10:56:28 -0300 | [diff] [blame] | 233 | pr_debug4("%s: %s %#" PRIx64 "-%#" PRIx64 "\n", |
| 234 | __func__, name, start, sym->end); |
| 235 | memcpy(sym->name, name, namelen); |
Arnaldo Carvalho de Melo | e420499 | 2009-10-20 14:25:40 -0200 | [diff] [blame] | 236 | |
Arnaldo Carvalho de Melo | aeafcba | 2011-03-31 10:56:28 -0300 | [diff] [blame] | 237 | return sym; |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 238 | } |
| 239 | |
Arnaldo Carvalho de Melo | aeafcba | 2011-03-31 10:56:28 -0300 | [diff] [blame] | 240 | void symbol__delete(struct symbol *sym) |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 241 | { |
Arnaldo Carvalho de Melo | aeafcba | 2011-03-31 10:56:28 -0300 | [diff] [blame] | 242 | free(((void *)sym) - symbol_conf.priv_size); |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 243 | } |
| 244 | |
Jiri Olsa | cdd059d | 2012-10-27 23:18:32 +0200 | [diff] [blame] | 245 | size_t symbol__fprintf(struct symbol *sym, FILE *fp) |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 246 | { |
Arnaldo Carvalho de Melo | 9486aa3 | 2011-01-22 20:37:02 -0200 | [diff] [blame] | 247 | return fprintf(fp, " %" PRIx64 "-%" PRIx64 " %c %s\n", |
Arnaldo Carvalho de Melo | aeafcba | 2011-03-31 10:56:28 -0300 | [diff] [blame] | 248 | sym->start, sym->end, |
| 249 | sym->binding == STB_GLOBAL ? 'g' : |
| 250 | sym->binding == STB_LOCAL ? 'l' : 'w', |
| 251 | sym->name); |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 252 | } |
| 253 | |
Akihiro Nagai | a978f2a | 2012-01-30 13:43:15 +0900 | [diff] [blame] | 254 | size_t symbol__fprintf_symname_offs(const struct symbol *sym, |
| 255 | const struct addr_location *al, FILE *fp) |
| 256 | { |
| 257 | unsigned long offset; |
| 258 | size_t length; |
| 259 | |
| 260 | if (sym && sym->name) { |
| 261 | length = fprintf(fp, "%s", sym->name); |
| 262 | if (al) { |
David Ahern | 0b8c25d | 2013-07-28 09:48:32 -0600 | [diff] [blame] | 263 | if (al->addr < sym->end) |
| 264 | offset = al->addr - sym->start; |
| 265 | else |
| 266 | offset = al->addr - al->map->start - sym->start; |
Akihiro Nagai | a978f2a | 2012-01-30 13:43:15 +0900 | [diff] [blame] | 267 | length += fprintf(fp, "+0x%lx", offset); |
| 268 | } |
| 269 | return length; |
| 270 | } else |
| 271 | return fprintf(fp, "[unknown]"); |
| 272 | } |
| 273 | |
Akihiro Nagai | 547a92e | 2012-01-30 13:42:57 +0900 | [diff] [blame] | 274 | size_t symbol__fprintf_symname(const struct symbol *sym, FILE *fp) |
| 275 | { |
Akihiro Nagai | a978f2a | 2012-01-30 13:43:15 +0900 | [diff] [blame] | 276 | return symbol__fprintf_symname_offs(sym, NULL, fp); |
Akihiro Nagai | 547a92e | 2012-01-30 13:42:57 +0900 | [diff] [blame] | 277 | } |
| 278 | |
Jiri Olsa | cdd059d | 2012-10-27 23:18:32 +0200 | [diff] [blame] | 279 | void symbols__delete(struct rb_root *symbols) |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 280 | { |
| 281 | struct symbol *pos; |
Arnaldo Carvalho de Melo | aeafcba | 2011-03-31 10:56:28 -0300 | [diff] [blame] | 282 | struct rb_node *next = rb_first(symbols); |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 283 | |
| 284 | while (next) { |
| 285 | pos = rb_entry(next, struct symbol, rb_node); |
| 286 | next = rb_next(&pos->rb_node); |
Arnaldo Carvalho de Melo | aeafcba | 2011-03-31 10:56:28 -0300 | [diff] [blame] | 287 | rb_erase(&pos->rb_node, symbols); |
Arnaldo Carvalho de Melo | 00a192b | 2009-10-30 16:28:24 -0200 | [diff] [blame] | 288 | symbol__delete(pos); |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 289 | } |
| 290 | } |
| 291 | |
Namhyung Kim | e5a1845 | 2012-08-06 13:41:20 +0900 | [diff] [blame] | 292 | void symbols__insert(struct rb_root *symbols, struct symbol *sym) |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 293 | { |
Arnaldo Carvalho de Melo | aeafcba | 2011-03-31 10:56:28 -0300 | [diff] [blame] | 294 | struct rb_node **p = &symbols->rb_node; |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 295 | struct rb_node *parent = NULL; |
Paul Mackerras | 9cffa8d | 2009-06-19 22:21:42 +1000 | [diff] [blame] | 296 | const u64 ip = sym->start; |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 297 | struct symbol *s; |
| 298 | |
| 299 | while (*p != NULL) { |
| 300 | parent = *p; |
| 301 | s = rb_entry(parent, struct symbol, rb_node); |
| 302 | if (ip < s->start) |
| 303 | p = &(*p)->rb_left; |
| 304 | else |
| 305 | p = &(*p)->rb_right; |
| 306 | } |
| 307 | rb_link_node(&sym->rb_node, parent, p); |
Arnaldo Carvalho de Melo | aeafcba | 2011-03-31 10:56:28 -0300 | [diff] [blame] | 308 | rb_insert_color(&sym->rb_node, symbols); |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 309 | } |
| 310 | |
Arnaldo Carvalho de Melo | aeafcba | 2011-03-31 10:56:28 -0300 | [diff] [blame] | 311 | static struct symbol *symbols__find(struct rb_root *symbols, u64 ip) |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 312 | { |
| 313 | struct rb_node *n; |
| 314 | |
Arnaldo Carvalho de Melo | aeafcba | 2011-03-31 10:56:28 -0300 | [diff] [blame] | 315 | if (symbols == NULL) |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 316 | return NULL; |
| 317 | |
Arnaldo Carvalho de Melo | aeafcba | 2011-03-31 10:56:28 -0300 | [diff] [blame] | 318 | n = symbols->rb_node; |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 319 | |
| 320 | while (n) { |
| 321 | struct symbol *s = rb_entry(n, struct symbol, rb_node); |
| 322 | |
| 323 | if (ip < s->start) |
| 324 | n = n->rb_left; |
| 325 | else if (ip > s->end) |
| 326 | n = n->rb_right; |
| 327 | else |
| 328 | return s; |
| 329 | } |
| 330 | |
| 331 | return NULL; |
| 332 | } |
| 333 | |
Adrian Hunter | 8e0cf96 | 2013-08-07 14:38:51 +0300 | [diff] [blame] | 334 | static struct symbol *symbols__first(struct rb_root *symbols) |
| 335 | { |
| 336 | struct rb_node *n = rb_first(symbols); |
| 337 | |
| 338 | if (n) |
| 339 | return rb_entry(n, struct symbol, rb_node); |
| 340 | |
| 341 | return NULL; |
| 342 | } |
| 343 | |
Arnaldo Carvalho de Melo | 79406cd | 2009-12-11 18:50:22 -0200 | [diff] [blame] | 344 | struct symbol_name_rb_node { |
| 345 | struct rb_node rb_node; |
| 346 | struct symbol sym; |
| 347 | }; |
| 348 | |
Arnaldo Carvalho de Melo | aeafcba | 2011-03-31 10:56:28 -0300 | [diff] [blame] | 349 | static void symbols__insert_by_name(struct rb_root *symbols, struct symbol *sym) |
Arnaldo Carvalho de Melo | 79406cd | 2009-12-11 18:50:22 -0200 | [diff] [blame] | 350 | { |
Arnaldo Carvalho de Melo | aeafcba | 2011-03-31 10:56:28 -0300 | [diff] [blame] | 351 | struct rb_node **p = &symbols->rb_node; |
Arnaldo Carvalho de Melo | 79406cd | 2009-12-11 18:50:22 -0200 | [diff] [blame] | 352 | struct rb_node *parent = NULL; |
Rabin Vincent | 02a9d03 | 2010-11-23 22:08:18 +0530 | [diff] [blame] | 353 | struct symbol_name_rb_node *symn, *s; |
| 354 | |
| 355 | symn = container_of(sym, struct symbol_name_rb_node, sym); |
Arnaldo Carvalho de Melo | 79406cd | 2009-12-11 18:50:22 -0200 | [diff] [blame] | 356 | |
| 357 | while (*p != NULL) { |
| 358 | parent = *p; |
| 359 | s = rb_entry(parent, struct symbol_name_rb_node, rb_node); |
| 360 | if (strcmp(sym->name, s->sym.name) < 0) |
| 361 | p = &(*p)->rb_left; |
| 362 | else |
| 363 | p = &(*p)->rb_right; |
| 364 | } |
| 365 | rb_link_node(&symn->rb_node, parent, p); |
Arnaldo Carvalho de Melo | aeafcba | 2011-03-31 10:56:28 -0300 | [diff] [blame] | 366 | rb_insert_color(&symn->rb_node, symbols); |
Arnaldo Carvalho de Melo | 79406cd | 2009-12-11 18:50:22 -0200 | [diff] [blame] | 367 | } |
| 368 | |
Arnaldo Carvalho de Melo | aeafcba | 2011-03-31 10:56:28 -0300 | [diff] [blame] | 369 | static void symbols__sort_by_name(struct rb_root *symbols, |
| 370 | struct rb_root *source) |
Arnaldo Carvalho de Melo | 79406cd | 2009-12-11 18:50:22 -0200 | [diff] [blame] | 371 | { |
| 372 | struct rb_node *nd; |
| 373 | |
| 374 | for (nd = rb_first(source); nd; nd = rb_next(nd)) { |
| 375 | struct symbol *pos = rb_entry(nd, struct symbol, rb_node); |
Arnaldo Carvalho de Melo | aeafcba | 2011-03-31 10:56:28 -0300 | [diff] [blame] | 376 | symbols__insert_by_name(symbols, pos); |
Arnaldo Carvalho de Melo | 79406cd | 2009-12-11 18:50:22 -0200 | [diff] [blame] | 377 | } |
| 378 | } |
| 379 | |
Arnaldo Carvalho de Melo | aeafcba | 2011-03-31 10:56:28 -0300 | [diff] [blame] | 380 | static struct symbol *symbols__find_by_name(struct rb_root *symbols, |
| 381 | const char *name) |
Arnaldo Carvalho de Melo | 79406cd | 2009-12-11 18:50:22 -0200 | [diff] [blame] | 382 | { |
| 383 | struct rb_node *n; |
| 384 | |
Arnaldo Carvalho de Melo | aeafcba | 2011-03-31 10:56:28 -0300 | [diff] [blame] | 385 | if (symbols == NULL) |
Arnaldo Carvalho de Melo | 79406cd | 2009-12-11 18:50:22 -0200 | [diff] [blame] | 386 | return NULL; |
| 387 | |
Arnaldo Carvalho de Melo | aeafcba | 2011-03-31 10:56:28 -0300 | [diff] [blame] | 388 | n = symbols->rb_node; |
Arnaldo Carvalho de Melo | 79406cd | 2009-12-11 18:50:22 -0200 | [diff] [blame] | 389 | |
| 390 | while (n) { |
| 391 | struct symbol_name_rb_node *s; |
| 392 | int cmp; |
| 393 | |
| 394 | s = rb_entry(n, struct symbol_name_rb_node, rb_node); |
| 395 | cmp = strcmp(name, s->sym.name); |
| 396 | |
| 397 | if (cmp < 0) |
| 398 | n = n->rb_left; |
| 399 | else if (cmp > 0) |
| 400 | n = n->rb_right; |
| 401 | else |
| 402 | return &s->sym; |
| 403 | } |
| 404 | |
| 405 | return NULL; |
| 406 | } |
| 407 | |
Arnaldo Carvalho de Melo | aeafcba | 2011-03-31 10:56:28 -0300 | [diff] [blame] | 408 | struct symbol *dso__find_symbol(struct dso *dso, |
Arnaldo Carvalho de Melo | 79406cd | 2009-12-11 18:50:22 -0200 | [diff] [blame] | 409 | enum map_type type, u64 addr) |
Arnaldo Carvalho de Melo | fcf1203 | 2009-11-24 13:01:52 -0200 | [diff] [blame] | 410 | { |
Arnaldo Carvalho de Melo | aeafcba | 2011-03-31 10:56:28 -0300 | [diff] [blame] | 411 | return symbols__find(&dso->symbols[type], addr); |
Arnaldo Carvalho de Melo | fcf1203 | 2009-11-24 13:01:52 -0200 | [diff] [blame] | 412 | } |
| 413 | |
Adrian Hunter | 8e0cf96 | 2013-08-07 14:38:51 +0300 | [diff] [blame] | 414 | struct symbol *dso__first_symbol(struct dso *dso, enum map_type type) |
| 415 | { |
| 416 | return symbols__first(&dso->symbols[type]); |
| 417 | } |
| 418 | |
Arnaldo Carvalho de Melo | aeafcba | 2011-03-31 10:56:28 -0300 | [diff] [blame] | 419 | struct symbol *dso__find_symbol_by_name(struct dso *dso, enum map_type type, |
Arnaldo Carvalho de Melo | 79406cd | 2009-12-11 18:50:22 -0200 | [diff] [blame] | 420 | const char *name) |
| 421 | { |
Arnaldo Carvalho de Melo | aeafcba | 2011-03-31 10:56:28 -0300 | [diff] [blame] | 422 | return symbols__find_by_name(&dso->symbol_names[type], name); |
Arnaldo Carvalho de Melo | 79406cd | 2009-12-11 18:50:22 -0200 | [diff] [blame] | 423 | } |
| 424 | |
Arnaldo Carvalho de Melo | aeafcba | 2011-03-31 10:56:28 -0300 | [diff] [blame] | 425 | void dso__sort_by_name(struct dso *dso, enum map_type type) |
Arnaldo Carvalho de Melo | 79406cd | 2009-12-11 18:50:22 -0200 | [diff] [blame] | 426 | { |
Arnaldo Carvalho de Melo | aeafcba | 2011-03-31 10:56:28 -0300 | [diff] [blame] | 427 | dso__set_sorted_by_name(dso, type); |
| 428 | return symbols__sort_by_name(&dso->symbol_names[type], |
| 429 | &dso->symbols[type]); |
Arnaldo Carvalho de Melo | 79406cd | 2009-12-11 18:50:22 -0200 | [diff] [blame] | 430 | } |
| 431 | |
Arnaldo Carvalho de Melo | aeafcba | 2011-03-31 10:56:28 -0300 | [diff] [blame] | 432 | size_t dso__fprintf_symbols_by_name(struct dso *dso, |
| 433 | enum map_type type, FILE *fp) |
Srikar Dronamraju | 90f18e6 | 2010-08-25 19:13:29 +0530 | [diff] [blame] | 434 | { |
| 435 | size_t ret = 0; |
| 436 | struct rb_node *nd; |
| 437 | struct symbol_name_rb_node *pos; |
| 438 | |
Arnaldo Carvalho de Melo | aeafcba | 2011-03-31 10:56:28 -0300 | [diff] [blame] | 439 | for (nd = rb_first(&dso->symbol_names[type]); nd; nd = rb_next(nd)) { |
Srikar Dronamraju | 90f18e6 | 2010-08-25 19:13:29 +0530 | [diff] [blame] | 440 | pos = rb_entry(nd, struct symbol_name_rb_node, rb_node); |
| 441 | fprintf(fp, "%s\n", pos->sym.name); |
| 442 | } |
| 443 | |
| 444 | return ret; |
| 445 | } |
| 446 | |
Arnaldo Carvalho de Melo | 9e20144 | 2010-01-14 18:30:06 -0200 | [diff] [blame] | 447 | int kallsyms__parse(const char *filename, void *arg, |
| 448 | int (*process_symbol)(void *arg, const char *name, |
Cody P Schafer | 8215152 | 2012-08-10 15:22:48 -0700 | [diff] [blame] | 449 | char type, u64 start)) |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 450 | { |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 451 | char *line = NULL; |
| 452 | size_t n; |
Arnaldo Carvalho de Melo | 3b01a41 | 2010-12-22 01:08:36 -0200 | [diff] [blame] | 453 | int err = -1; |
Arnaldo Carvalho de Melo | 9e20144 | 2010-01-14 18:30:06 -0200 | [diff] [blame] | 454 | FILE *file = fopen(filename, "r"); |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 455 | |
| 456 | if (file == NULL) |
| 457 | goto out_failure; |
| 458 | |
Arnaldo Carvalho de Melo | 3b01a41 | 2010-12-22 01:08:36 -0200 | [diff] [blame] | 459 | err = 0; |
| 460 | |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 461 | while (!feof(file)) { |
Paul Mackerras | 9cffa8d | 2009-06-19 22:21:42 +1000 | [diff] [blame] | 462 | u64 start; |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 463 | int line_len, len; |
| 464 | char symbol_type; |
Arnaldo Carvalho de Melo | 2e538c4 | 2009-10-07 13:48:56 -0300 | [diff] [blame] | 465 | char *symbol_name; |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 466 | |
| 467 | line_len = getline(&line, &n, file); |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 468 | if (line_len < 0 || !line) |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 469 | break; |
| 470 | |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 471 | line[--line_len] = '\0'; /* \n */ |
| 472 | |
Arnaldo Carvalho de Melo | a0055ae | 2009-06-01 17:50:19 -0300 | [diff] [blame] | 473 | len = hex2u64(line, &start); |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 474 | |
| 475 | len++; |
| 476 | if (len + 2 >= line_len) |
| 477 | continue; |
| 478 | |
Anton Blanchard | 3187790 | 2011-08-24 16:40:16 +1000 | [diff] [blame] | 479 | symbol_type = line[len]; |
Arnaldo Carvalho de Melo | 3b01a41 | 2010-12-22 01:08:36 -0200 | [diff] [blame] | 480 | len += 2; |
| 481 | symbol_name = line + len; |
| 482 | len = line_len - len; |
Arnaldo Carvalho de Melo | af427bf | 2009-10-05 14:26:17 -0300 | [diff] [blame] | 483 | |
Arnaldo Carvalho de Melo | 3b01a41 | 2010-12-22 01:08:36 -0200 | [diff] [blame] | 484 | if (len >= KSYM_NAME_LEN) { |
| 485 | err = -1; |
Arnaldo Carvalho de Melo | 682b335 | 2010-01-04 16:19:26 -0200 | [diff] [blame] | 486 | break; |
Arnaldo Carvalho de Melo | 3b01a41 | 2010-12-22 01:08:36 -0200 | [diff] [blame] | 487 | } |
| 488 | |
Anton Blanchard | 3f5a427 | 2011-08-24 16:40:15 +1000 | [diff] [blame] | 489 | err = process_symbol(arg, symbol_name, |
Cody P Schafer | 8215152 | 2012-08-10 15:22:48 -0700 | [diff] [blame] | 490 | symbol_type, start); |
Anton Blanchard | 3f5a427 | 2011-08-24 16:40:15 +1000 | [diff] [blame] | 491 | if (err) |
| 492 | break; |
Arnaldo Carvalho de Melo | 2e538c4 | 2009-10-07 13:48:56 -0300 | [diff] [blame] | 493 | } |
| 494 | |
| 495 | free(line); |
| 496 | fclose(file); |
Arnaldo Carvalho de Melo | 682b335 | 2010-01-04 16:19:26 -0200 | [diff] [blame] | 497 | return err; |
Arnaldo Carvalho de Melo | 2e538c4 | 2009-10-07 13:48:56 -0300 | [diff] [blame] | 498 | |
Arnaldo Carvalho de Melo | 2e538c4 | 2009-10-07 13:48:56 -0300 | [diff] [blame] | 499 | out_failure: |
| 500 | return -1; |
| 501 | } |
| 502 | |
Arnaldo Carvalho de Melo | 682b335 | 2010-01-04 16:19:26 -0200 | [diff] [blame] | 503 | struct process_kallsyms_args { |
| 504 | struct map *map; |
| 505 | struct dso *dso; |
| 506 | }; |
| 507 | |
Arnaldo Carvalho de Melo | c408fed | 2010-08-05 12:59:47 -0300 | [diff] [blame] | 508 | static u8 kallsyms2elf_type(char type) |
| 509 | { |
| 510 | if (type == 'W') |
| 511 | return STB_WEAK; |
| 512 | |
| 513 | return isupper(type) ? STB_GLOBAL : STB_LOCAL; |
| 514 | } |
| 515 | |
Arnaldo Carvalho de Melo | 682b335 | 2010-01-04 16:19:26 -0200 | [diff] [blame] | 516 | static int map__process_kallsym_symbol(void *arg, const char *name, |
Cody P Schafer | 8215152 | 2012-08-10 15:22:48 -0700 | [diff] [blame] | 517 | char type, u64 start) |
Arnaldo Carvalho de Melo | 682b335 | 2010-01-04 16:19:26 -0200 | [diff] [blame] | 518 | { |
| 519 | struct symbol *sym; |
| 520 | struct process_kallsyms_args *a = arg; |
| 521 | struct rb_root *root = &a->dso->symbols[a->map->type]; |
| 522 | |
| 523 | if (!symbol_type__is_a(type, a->map->type)) |
| 524 | return 0; |
| 525 | |
Cody P Schafer | 8215152 | 2012-08-10 15:22:48 -0700 | [diff] [blame] | 526 | /* |
| 527 | * module symbols are not sorted so we add all |
| 528 | * symbols, setting length to 0, and rely on |
| 529 | * symbols__fixup_end() to fix it up. |
| 530 | */ |
| 531 | sym = symbol__new(start, 0, kallsyms2elf_type(type), name); |
Arnaldo Carvalho de Melo | 682b335 | 2010-01-04 16:19:26 -0200 | [diff] [blame] | 532 | if (sym == NULL) |
| 533 | return -ENOMEM; |
| 534 | /* |
| 535 | * We will pass the symbols to the filter later, in |
| 536 | * map__split_kallsyms, when we have split the maps per module |
| 537 | */ |
| 538 | symbols__insert(root, sym); |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 539 | |
Arnaldo Carvalho de Melo | 682b335 | 2010-01-04 16:19:26 -0200 | [diff] [blame] | 540 | return 0; |
| 541 | } |
| 542 | |
| 543 | /* |
| 544 | * Loads the function entries in /proc/kallsyms into kernel_map->dso, |
| 545 | * so that we can in the next step set the symbol ->end address and then |
| 546 | * call kernel_maps__split_kallsyms. |
| 547 | */ |
Arnaldo Carvalho de Melo | aeafcba | 2011-03-31 10:56:28 -0300 | [diff] [blame] | 548 | static int dso__load_all_kallsyms(struct dso *dso, const char *filename, |
Arnaldo Carvalho de Melo | 9e20144 | 2010-01-14 18:30:06 -0200 | [diff] [blame] | 549 | struct map *map) |
Arnaldo Carvalho de Melo | 682b335 | 2010-01-04 16:19:26 -0200 | [diff] [blame] | 550 | { |
Arnaldo Carvalho de Melo | aeafcba | 2011-03-31 10:56:28 -0300 | [diff] [blame] | 551 | struct process_kallsyms_args args = { .map = map, .dso = dso, }; |
Arnaldo Carvalho de Melo | 9e20144 | 2010-01-14 18:30:06 -0200 | [diff] [blame] | 552 | return kallsyms__parse(filename, &args, map__process_kallsym_symbol); |
Arnaldo Carvalho de Melo | 682b335 | 2010-01-04 16:19:26 -0200 | [diff] [blame] | 553 | } |
| 554 | |
Adrian Hunter | 8e0cf96 | 2013-08-07 14:38:51 +0300 | [diff] [blame] | 555 | static int dso__split_kallsyms_for_kcore(struct dso *dso, struct map *map, |
| 556 | symbol_filter_t filter) |
| 557 | { |
| 558 | struct map_groups *kmaps = map__kmap(map)->kmaps; |
| 559 | struct map *curr_map; |
| 560 | struct symbol *pos; |
| 561 | int count = 0, moved = 0; |
| 562 | struct rb_root *root = &dso->symbols[map->type]; |
| 563 | struct rb_node *next = rb_first(root); |
| 564 | |
| 565 | while (next) { |
| 566 | char *module; |
| 567 | |
| 568 | pos = rb_entry(next, struct symbol, rb_node); |
| 569 | next = rb_next(&pos->rb_node); |
| 570 | |
| 571 | module = strchr(pos->name, '\t'); |
| 572 | if (module) |
| 573 | *module = '\0'; |
| 574 | |
| 575 | curr_map = map_groups__find(kmaps, map->type, pos->start); |
| 576 | |
| 577 | if (!curr_map || (filter && filter(curr_map, pos))) { |
| 578 | rb_erase(&pos->rb_node, root); |
| 579 | symbol__delete(pos); |
| 580 | } else { |
| 581 | pos->start -= curr_map->start - curr_map->pgoff; |
| 582 | if (pos->end) |
| 583 | pos->end -= curr_map->start - curr_map->pgoff; |
| 584 | if (curr_map != map) { |
| 585 | rb_erase(&pos->rb_node, root); |
| 586 | symbols__insert( |
| 587 | &curr_map->dso->symbols[curr_map->type], |
| 588 | pos); |
| 589 | ++moved; |
| 590 | } else { |
| 591 | ++count; |
| 592 | } |
| 593 | } |
| 594 | } |
| 595 | |
| 596 | /* Symbols have been adjusted */ |
| 597 | dso->adjust_symbols = 1; |
| 598 | |
| 599 | return count + moved; |
| 600 | } |
| 601 | |
Arnaldo Carvalho de Melo | 2e538c4 | 2009-10-07 13:48:56 -0300 | [diff] [blame] | 602 | /* |
| 603 | * Split the symbols into maps, making sure there are no overlaps, i.e. the |
| 604 | * kernel range is broken in several maps, named [kernel].N, as we don't have |
| 605 | * the original ELF section names vmlinux have. |
| 606 | */ |
Arnaldo Carvalho de Melo | aeafcba | 2011-03-31 10:56:28 -0300 | [diff] [blame] | 607 | static int dso__split_kallsyms(struct dso *dso, struct map *map, |
Arnaldo Carvalho de Melo | 9de89fe | 2010-02-03 16:52:00 -0200 | [diff] [blame] | 608 | symbol_filter_t filter) |
Arnaldo Carvalho de Melo | 2e538c4 | 2009-10-07 13:48:56 -0300 | [diff] [blame] | 609 | { |
Arnaldo Carvalho de Melo | 9de89fe | 2010-02-03 16:52:00 -0200 | [diff] [blame] | 610 | struct map_groups *kmaps = map__kmap(map)->kmaps; |
Arnaldo Carvalho de Melo | 23346f2 | 2010-04-27 21:17:50 -0300 | [diff] [blame] | 611 | struct machine *machine = kmaps->machine; |
Arnaldo Carvalho de Melo | 4e06255 | 2009-11-27 16:29:18 -0200 | [diff] [blame] | 612 | struct map *curr_map = map; |
Arnaldo Carvalho de Melo | 2e538c4 | 2009-10-07 13:48:56 -0300 | [diff] [blame] | 613 | struct symbol *pos; |
Arnaldo Carvalho de Melo | 8a95331 | 2010-11-29 12:44:15 -0200 | [diff] [blame] | 614 | int count = 0, moved = 0; |
Arnaldo Carvalho de Melo | aeafcba | 2011-03-31 10:56:28 -0300 | [diff] [blame] | 615 | struct rb_root *root = &dso->symbols[map->type]; |
Arnaldo Carvalho de Melo | 4e06255 | 2009-11-27 16:29:18 -0200 | [diff] [blame] | 616 | struct rb_node *next = rb_first(root); |
Arnaldo Carvalho de Melo | 2e538c4 | 2009-10-07 13:48:56 -0300 | [diff] [blame] | 617 | int kernel_range = 0; |
| 618 | |
| 619 | while (next) { |
| 620 | char *module; |
| 621 | |
| 622 | pos = rb_entry(next, struct symbol, rb_node); |
| 623 | next = rb_next(&pos->rb_node); |
| 624 | |
| 625 | module = strchr(pos->name, '\t'); |
| 626 | if (module) { |
Arnaldo Carvalho de Melo | 75be6cf | 2009-12-15 20:04:39 -0200 | [diff] [blame] | 627 | if (!symbol_conf.use_modules) |
Arnaldo Carvalho de Melo | 1de8e24 | 2009-11-27 16:29:21 -0200 | [diff] [blame] | 628 | goto discard_symbol; |
| 629 | |
Arnaldo Carvalho de Melo | 2e538c4 | 2009-10-07 13:48:56 -0300 | [diff] [blame] | 630 | *module++ = '\0'; |
| 631 | |
Arnaldo Carvalho de Melo | b7cece76 | 2010-01-13 13:22:17 -0200 | [diff] [blame] | 632 | if (strcmp(curr_map->dso->short_name, module)) { |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 633 | if (curr_map != map && |
Arnaldo Carvalho de Melo | aeafcba | 2011-03-31 10:56:28 -0300 | [diff] [blame] | 634 | dso->kernel == DSO_TYPE_GUEST_KERNEL && |
Arnaldo Carvalho de Melo | 23346f2 | 2010-04-27 21:17:50 -0300 | [diff] [blame] | 635 | machine__is_default_guest(machine)) { |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 636 | /* |
| 637 | * We assume all symbols of a module are |
| 638 | * continuous in * kallsyms, so curr_map |
| 639 | * points to a module and all its |
| 640 | * symbols are in its kmap. Mark it as |
| 641 | * loaded. |
| 642 | */ |
| 643 | dso__set_loaded(curr_map->dso, |
| 644 | curr_map->type); |
Arnaldo Carvalho de Melo | af427bf | 2009-10-05 14:26:17 -0300 | [diff] [blame] | 645 | } |
Arnaldo Carvalho de Melo | b7cece76 | 2010-01-13 13:22:17 -0200 | [diff] [blame] | 646 | |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 647 | curr_map = map_groups__find_by_name(kmaps, |
| 648 | map->type, module); |
| 649 | if (curr_map == NULL) { |
Arnaldo Carvalho de Melo | 2f51903 | 2010-05-17 17:57:59 -0300 | [diff] [blame] | 650 | pr_debug("%s/proc/{kallsyms,modules} " |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 651 | "inconsistency while looking " |
| 652 | "for \"%s\" module!\n", |
Arnaldo Carvalho de Melo | 23346f2 | 2010-04-27 21:17:50 -0300 | [diff] [blame] | 653 | machine->root_dir, module); |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 654 | curr_map = map; |
| 655 | goto discard_symbol; |
| 656 | } |
| 657 | |
| 658 | if (curr_map->dso->loaded && |
Arnaldo Carvalho de Melo | 23346f2 | 2010-04-27 21:17:50 -0300 | [diff] [blame] | 659 | !machine__is_default_guest(machine)) |
Arnaldo Carvalho de Melo | b7cece76 | 2010-01-13 13:22:17 -0200 | [diff] [blame] | 660 | goto discard_symbol; |
Arnaldo Carvalho de Melo | af427bf | 2009-10-05 14:26:17 -0300 | [diff] [blame] | 661 | } |
Arnaldo Carvalho de Melo | 2e538c4 | 2009-10-07 13:48:56 -0300 | [diff] [blame] | 662 | /* |
| 663 | * So that we look just like we get from .ko files, |
| 664 | * i.e. not prelinked, relative to map->start. |
| 665 | */ |
Arnaldo Carvalho de Melo | 4e06255 | 2009-11-27 16:29:18 -0200 | [diff] [blame] | 666 | pos->start = curr_map->map_ip(curr_map, pos->start); |
| 667 | pos->end = curr_map->map_ip(curr_map, pos->end); |
| 668 | } else if (curr_map != map) { |
Arnaldo Carvalho de Melo | 2e538c4 | 2009-10-07 13:48:56 -0300 | [diff] [blame] | 669 | char dso_name[PATH_MAX]; |
Arnaldo Carvalho de Melo | aeafcba | 2011-03-31 10:56:28 -0300 | [diff] [blame] | 670 | struct dso *ndso; |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 671 | |
Arnaldo Carvalho de Melo | 8a95331 | 2010-11-29 12:44:15 -0200 | [diff] [blame] | 672 | if (count == 0) { |
| 673 | curr_map = map; |
| 674 | goto filter_symbol; |
| 675 | } |
| 676 | |
Arnaldo Carvalho de Melo | aeafcba | 2011-03-31 10:56:28 -0300 | [diff] [blame] | 677 | if (dso->kernel == DSO_TYPE_GUEST_KERNEL) |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 678 | snprintf(dso_name, sizeof(dso_name), |
| 679 | "[guest.kernel].%d", |
| 680 | kernel_range++); |
| 681 | else |
| 682 | snprintf(dso_name, sizeof(dso_name), |
| 683 | "[kernel].%d", |
| 684 | kernel_range++); |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 685 | |
Arnaldo Carvalho de Melo | aeafcba | 2011-03-31 10:56:28 -0300 | [diff] [blame] | 686 | ndso = dso__new(dso_name); |
| 687 | if (ndso == NULL) |
Arnaldo Carvalho de Melo | 2e538c4 | 2009-10-07 13:48:56 -0300 | [diff] [blame] | 688 | return -1; |
| 689 | |
Arnaldo Carvalho de Melo | aeafcba | 2011-03-31 10:56:28 -0300 | [diff] [blame] | 690 | ndso->kernel = dso->kernel; |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 691 | |
Arnaldo Carvalho de Melo | aeafcba | 2011-03-31 10:56:28 -0300 | [diff] [blame] | 692 | curr_map = map__new2(pos->start, ndso, map->type); |
Zhang, Yanmin | 37fe5fc | 2010-02-25 11:00:51 +0800 | [diff] [blame] | 693 | if (curr_map == NULL) { |
Arnaldo Carvalho de Melo | aeafcba | 2011-03-31 10:56:28 -0300 | [diff] [blame] | 694 | dso__delete(ndso); |
Arnaldo Carvalho de Melo | 2e538c4 | 2009-10-07 13:48:56 -0300 | [diff] [blame] | 695 | return -1; |
| 696 | } |
| 697 | |
Arnaldo Carvalho de Melo | 4e06255 | 2009-11-27 16:29:18 -0200 | [diff] [blame] | 698 | curr_map->map_ip = curr_map->unmap_ip = identity__map_ip; |
Arnaldo Carvalho de Melo | 9de89fe | 2010-02-03 16:52:00 -0200 | [diff] [blame] | 699 | map_groups__insert(kmaps, curr_map); |
Arnaldo Carvalho de Melo | 2e538c4 | 2009-10-07 13:48:56 -0300 | [diff] [blame] | 700 | ++kernel_range; |
| 701 | } |
Arnaldo Carvalho de Melo | 8a95331 | 2010-11-29 12:44:15 -0200 | [diff] [blame] | 702 | filter_symbol: |
Arnaldo Carvalho de Melo | 4e06255 | 2009-11-27 16:29:18 -0200 | [diff] [blame] | 703 | if (filter && filter(curr_map, pos)) { |
Arnaldo Carvalho de Melo | 1de8e24 | 2009-11-27 16:29:21 -0200 | [diff] [blame] | 704 | discard_symbol: rb_erase(&pos->rb_node, root); |
Arnaldo Carvalho de Melo | 00a192b | 2009-10-30 16:28:24 -0200 | [diff] [blame] | 705 | symbol__delete(pos); |
Arnaldo Carvalho de Melo | 2e538c4 | 2009-10-07 13:48:56 -0300 | [diff] [blame] | 706 | } else { |
Arnaldo Carvalho de Melo | 4e06255 | 2009-11-27 16:29:18 -0200 | [diff] [blame] | 707 | if (curr_map != map) { |
| 708 | rb_erase(&pos->rb_node, root); |
| 709 | symbols__insert(&curr_map->dso->symbols[curr_map->type], pos); |
Arnaldo Carvalho de Melo | 8a95331 | 2010-11-29 12:44:15 -0200 | [diff] [blame] | 710 | ++moved; |
| 711 | } else |
| 712 | ++count; |
Mike Galbraith | 9974f49 | 2009-07-02 08:05:58 +0200 | [diff] [blame] | 713 | } |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 714 | } |
| 715 | |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 716 | if (curr_map != map && |
Arnaldo Carvalho de Melo | aeafcba | 2011-03-31 10:56:28 -0300 | [diff] [blame] | 717 | dso->kernel == DSO_TYPE_GUEST_KERNEL && |
Arnaldo Carvalho de Melo | 23346f2 | 2010-04-27 21:17:50 -0300 | [diff] [blame] | 718 | machine__is_default_guest(kmaps->machine)) { |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 719 | dso__set_loaded(curr_map->dso, curr_map->type); |
| 720 | } |
| 721 | |
Arnaldo Carvalho de Melo | 8a95331 | 2010-11-29 12:44:15 -0200 | [diff] [blame] | 722 | return count + moved; |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 723 | } |
| 724 | |
Arnaldo Carvalho de Melo | 3f067dc | 2012-12-07 17:39:39 -0300 | [diff] [blame] | 725 | bool symbol__restricted_filename(const char *filename, |
| 726 | const char *restricted_filename) |
Arnaldo Carvalho de Melo | ec80fde | 2011-05-26 09:53:51 -0300 | [diff] [blame] | 727 | { |
| 728 | bool restricted = false; |
| 729 | |
| 730 | if (symbol_conf.kptr_restrict) { |
| 731 | char *r = realpath(filename, NULL); |
| 732 | |
| 733 | if (r != NULL) { |
| 734 | restricted = strcmp(r, restricted_filename) == 0; |
| 735 | free(r); |
| 736 | return restricted; |
| 737 | } |
| 738 | } |
| 739 | |
| 740 | return restricted; |
| 741 | } |
| 742 | |
Adrian Hunter | 8e0cf96 | 2013-08-07 14:38:51 +0300 | [diff] [blame] | 743 | struct kcore_mapfn_data { |
| 744 | struct dso *dso; |
| 745 | enum map_type type; |
| 746 | struct list_head maps; |
| 747 | }; |
| 748 | |
| 749 | static int kcore_mapfn(u64 start, u64 len, u64 pgoff, void *data) |
| 750 | { |
| 751 | struct kcore_mapfn_data *md = data; |
| 752 | struct map *map; |
| 753 | |
| 754 | map = map__new2(start, md->dso, md->type); |
| 755 | if (map == NULL) |
| 756 | return -ENOMEM; |
| 757 | |
| 758 | map->end = map->start + len; |
| 759 | map->pgoff = pgoff; |
| 760 | |
| 761 | list_add(&map->node, &md->maps); |
| 762 | |
| 763 | return 0; |
| 764 | } |
| 765 | |
| 766 | /* |
| 767 | * If kallsyms is referenced by name then we look for kcore in the same |
| 768 | * directory. |
| 769 | */ |
| 770 | static bool kcore_filename_from_kallsyms_filename(char *kcore_filename, |
| 771 | const char *kallsyms_filename) |
| 772 | { |
| 773 | char *name; |
| 774 | |
| 775 | strcpy(kcore_filename, kallsyms_filename); |
| 776 | name = strrchr(kcore_filename, '/'); |
| 777 | if (!name) |
| 778 | return false; |
| 779 | |
| 780 | if (!strcmp(name, "/kallsyms")) { |
| 781 | strcpy(name, "/kcore"); |
| 782 | return true; |
| 783 | } |
| 784 | |
| 785 | return false; |
| 786 | } |
| 787 | |
| 788 | static int dso__load_kcore(struct dso *dso, struct map *map, |
| 789 | const char *kallsyms_filename) |
| 790 | { |
| 791 | struct map_groups *kmaps = map__kmap(map)->kmaps; |
| 792 | struct machine *machine = kmaps->machine; |
| 793 | struct kcore_mapfn_data md; |
| 794 | struct map *old_map, *new_map, *replacement_map = NULL; |
| 795 | bool is_64_bit; |
| 796 | int err, fd; |
| 797 | char kcore_filename[PATH_MAX]; |
| 798 | struct symbol *sym; |
| 799 | |
| 800 | /* This function requires that the map is the kernel map */ |
| 801 | if (map != machine->vmlinux_maps[map->type]) |
| 802 | return -EINVAL; |
| 803 | |
| 804 | if (!kcore_filename_from_kallsyms_filename(kcore_filename, |
| 805 | kallsyms_filename)) |
| 806 | return -EINVAL; |
| 807 | |
| 808 | md.dso = dso; |
| 809 | md.type = map->type; |
| 810 | INIT_LIST_HEAD(&md.maps); |
| 811 | |
| 812 | fd = open(kcore_filename, O_RDONLY); |
| 813 | if (fd < 0) |
| 814 | return -EINVAL; |
| 815 | |
| 816 | /* Read new maps into temporary lists */ |
| 817 | err = file__read_maps(fd, md.type == MAP__FUNCTION, kcore_mapfn, &md, |
| 818 | &is_64_bit); |
| 819 | if (err) |
| 820 | goto out_err; |
| 821 | |
| 822 | if (list_empty(&md.maps)) { |
| 823 | err = -EINVAL; |
| 824 | goto out_err; |
| 825 | } |
| 826 | |
| 827 | /* Remove old maps */ |
| 828 | old_map = map_groups__first(kmaps, map->type); |
| 829 | while (old_map) { |
| 830 | struct map *next = map_groups__next(old_map); |
| 831 | |
| 832 | if (old_map != map) |
| 833 | map_groups__remove(kmaps, old_map); |
| 834 | old_map = next; |
| 835 | } |
| 836 | |
| 837 | /* Find the kernel map using the first symbol */ |
| 838 | sym = dso__first_symbol(dso, map->type); |
| 839 | list_for_each_entry(new_map, &md.maps, node) { |
| 840 | if (sym && sym->start >= new_map->start && |
| 841 | sym->start < new_map->end) { |
| 842 | replacement_map = new_map; |
| 843 | break; |
| 844 | } |
| 845 | } |
| 846 | |
| 847 | if (!replacement_map) |
| 848 | replacement_map = list_entry(md.maps.next, struct map, node); |
| 849 | |
| 850 | /* Add new maps */ |
| 851 | while (!list_empty(&md.maps)) { |
| 852 | new_map = list_entry(md.maps.next, struct map, node); |
| 853 | list_del(&new_map->node); |
| 854 | if (new_map == replacement_map) { |
| 855 | map->start = new_map->start; |
| 856 | map->end = new_map->end; |
| 857 | map->pgoff = new_map->pgoff; |
| 858 | map->map_ip = new_map->map_ip; |
| 859 | map->unmap_ip = new_map->unmap_ip; |
| 860 | map__delete(new_map); |
| 861 | /* Ensure maps are correctly ordered */ |
| 862 | map_groups__remove(kmaps, map); |
| 863 | map_groups__insert(kmaps, map); |
| 864 | } else { |
| 865 | map_groups__insert(kmaps, new_map); |
| 866 | } |
| 867 | } |
| 868 | |
| 869 | /* |
| 870 | * Set the data type and long name so that kcore can be read via |
| 871 | * dso__data_read_addr(). |
| 872 | */ |
| 873 | if (dso->kernel == DSO_TYPE_GUEST_KERNEL) |
| 874 | dso->data_type = DSO_BINARY_TYPE__GUEST_KCORE; |
| 875 | else |
| 876 | dso->data_type = DSO_BINARY_TYPE__KCORE; |
| 877 | dso__set_long_name(dso, strdup(kcore_filename)); |
| 878 | |
| 879 | close(fd); |
| 880 | |
| 881 | if (map->type == MAP__FUNCTION) |
| 882 | pr_debug("Using %s for kernel object code\n", kcore_filename); |
| 883 | else |
| 884 | pr_debug("Using %s for kernel data\n", kcore_filename); |
| 885 | |
| 886 | return 0; |
| 887 | |
| 888 | out_err: |
| 889 | while (!list_empty(&md.maps)) { |
| 890 | map = list_entry(md.maps.next, struct map, node); |
| 891 | list_del(&map->node); |
| 892 | map__delete(map); |
| 893 | } |
| 894 | close(fd); |
| 895 | return -EINVAL; |
| 896 | } |
| 897 | |
Arnaldo Carvalho de Melo | aeafcba | 2011-03-31 10:56:28 -0300 | [diff] [blame] | 898 | int dso__load_kallsyms(struct dso *dso, const char *filename, |
Arnaldo Carvalho de Melo | 9de89fe | 2010-02-03 16:52:00 -0200 | [diff] [blame] | 899 | struct map *map, symbol_filter_t filter) |
Arnaldo Carvalho de Melo | 2e538c4 | 2009-10-07 13:48:56 -0300 | [diff] [blame] | 900 | { |
Arnaldo Carvalho de Melo | ec80fde | 2011-05-26 09:53:51 -0300 | [diff] [blame] | 901 | if (symbol__restricted_filename(filename, "/proc/kallsyms")) |
| 902 | return -1; |
| 903 | |
Arnaldo Carvalho de Melo | aeafcba | 2011-03-31 10:56:28 -0300 | [diff] [blame] | 904 | if (dso__load_all_kallsyms(dso, filename, map) < 0) |
Arnaldo Carvalho de Melo | 2e538c4 | 2009-10-07 13:48:56 -0300 | [diff] [blame] | 905 | return -1; |
| 906 | |
Anton Blanchard | 694bf40 | 2011-08-24 16:40:17 +1000 | [diff] [blame] | 907 | symbols__fixup_duplicate(&dso->symbols[map->type]); |
Anton Blanchard | 3f5a427 | 2011-08-24 16:40:15 +1000 | [diff] [blame] | 908 | symbols__fixup_end(&dso->symbols[map->type]); |
| 909 | |
Arnaldo Carvalho de Melo | aeafcba | 2011-03-31 10:56:28 -0300 | [diff] [blame] | 910 | if (dso->kernel == DSO_TYPE_GUEST_KERNEL) |
Jiri Olsa | 44f24cb | 2012-07-22 14:14:32 +0200 | [diff] [blame] | 911 | dso->symtab_type = DSO_BINARY_TYPE__GUEST_KALLSYMS; |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 912 | else |
Jiri Olsa | 44f24cb | 2012-07-22 14:14:32 +0200 | [diff] [blame] | 913 | dso->symtab_type = DSO_BINARY_TYPE__KALLSYMS; |
Arnaldo Carvalho de Melo | 2e538c4 | 2009-10-07 13:48:56 -0300 | [diff] [blame] | 914 | |
Adrian Hunter | 8e0cf96 | 2013-08-07 14:38:51 +0300 | [diff] [blame] | 915 | if (!dso__load_kcore(dso, map, filename)) |
| 916 | return dso__split_kallsyms_for_kcore(dso, map, filter); |
| 917 | else |
| 918 | return dso__split_kallsyms(dso, map, filter); |
Arnaldo Carvalho de Melo | af427bf | 2009-10-05 14:26:17 -0300 | [diff] [blame] | 919 | } |
| 920 | |
Arnaldo Carvalho de Melo | aeafcba | 2011-03-31 10:56:28 -0300 | [diff] [blame] | 921 | static int dso__load_perf_map(struct dso *dso, struct map *map, |
Arnaldo Carvalho de Melo | 6beba7a | 2009-10-21 17:34:06 -0200 | [diff] [blame] | 922 | symbol_filter_t filter) |
Pekka Enberg | 80d496b | 2009-06-08 21:12:48 +0300 | [diff] [blame] | 923 | { |
| 924 | char *line = NULL; |
| 925 | size_t n; |
| 926 | FILE *file; |
| 927 | int nr_syms = 0; |
| 928 | |
Arnaldo Carvalho de Melo | aeafcba | 2011-03-31 10:56:28 -0300 | [diff] [blame] | 929 | file = fopen(dso->long_name, "r"); |
Pekka Enberg | 80d496b | 2009-06-08 21:12:48 +0300 | [diff] [blame] | 930 | if (file == NULL) |
| 931 | goto out_failure; |
| 932 | |
| 933 | while (!feof(file)) { |
Paul Mackerras | 9cffa8d | 2009-06-19 22:21:42 +1000 | [diff] [blame] | 934 | u64 start, size; |
Pekka Enberg | 80d496b | 2009-06-08 21:12:48 +0300 | [diff] [blame] | 935 | struct symbol *sym; |
| 936 | int line_len, len; |
| 937 | |
| 938 | line_len = getline(&line, &n, file); |
| 939 | if (line_len < 0) |
| 940 | break; |
| 941 | |
| 942 | if (!line) |
| 943 | goto out_failure; |
| 944 | |
| 945 | line[--line_len] = '\0'; /* \n */ |
| 946 | |
| 947 | len = hex2u64(line, &start); |
| 948 | |
| 949 | len++; |
| 950 | if (len + 2 >= line_len) |
| 951 | continue; |
| 952 | |
| 953 | len += hex2u64(line + len, &size); |
| 954 | |
| 955 | len++; |
| 956 | if (len + 2 >= line_len) |
| 957 | continue; |
| 958 | |
Arnaldo Carvalho de Melo | c408fed | 2010-08-05 12:59:47 -0300 | [diff] [blame] | 959 | sym = symbol__new(start, size, STB_GLOBAL, line + len); |
Pekka Enberg | 80d496b | 2009-06-08 21:12:48 +0300 | [diff] [blame] | 960 | |
| 961 | if (sym == NULL) |
| 962 | goto out_delete_line; |
| 963 | |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 964 | if (filter && filter(map, sym)) |
Arnaldo Carvalho de Melo | 00a192b | 2009-10-30 16:28:24 -0200 | [diff] [blame] | 965 | symbol__delete(sym); |
Pekka Enberg | 80d496b | 2009-06-08 21:12:48 +0300 | [diff] [blame] | 966 | else { |
Arnaldo Carvalho de Melo | aeafcba | 2011-03-31 10:56:28 -0300 | [diff] [blame] | 967 | symbols__insert(&dso->symbols[map->type], sym); |
Pekka Enberg | 80d496b | 2009-06-08 21:12:48 +0300 | [diff] [blame] | 968 | nr_syms++; |
| 969 | } |
| 970 | } |
| 971 | |
| 972 | free(line); |
| 973 | fclose(file); |
| 974 | |
| 975 | return nr_syms; |
| 976 | |
| 977 | out_delete_line: |
| 978 | free(line); |
| 979 | out_failure: |
| 980 | return -1; |
| 981 | } |
| 982 | |
Arnaldo Carvalho de Melo | aeafcba | 2011-03-31 10:56:28 -0300 | [diff] [blame] | 983 | int dso__load(struct dso *dso, struct map *map, symbol_filter_t filter) |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 984 | { |
Arnaldo Carvalho de Melo | c338aee | 2009-11-20 20:51:27 -0200 | [diff] [blame] | 985 | char *name; |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 986 | int ret = -1; |
Jiri Olsa | 44f24cb | 2012-07-22 14:14:32 +0200 | [diff] [blame] | 987 | u_int i; |
Arnaldo Carvalho de Melo | 23346f2 | 2010-04-27 21:17:50 -0300 | [diff] [blame] | 988 | struct machine *machine; |
Jiri Olsa | 44f24cb | 2012-07-22 14:14:32 +0200 | [diff] [blame] | 989 | char *root_dir = (char *) ""; |
Cody P Schafer | 3aafe5a | 2012-08-10 15:23:02 -0700 | [diff] [blame] | 990 | int ss_pos = 0; |
| 991 | struct symsrc ss_[2]; |
| 992 | struct symsrc *syms_ss = NULL, *runtime_ss = NULL; |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 993 | |
Arnaldo Carvalho de Melo | aeafcba | 2011-03-31 10:56:28 -0300 | [diff] [blame] | 994 | dso__set_loaded(dso, map->type); |
Arnaldo Carvalho de Melo | 66bd842 | 2009-10-28 21:51:21 -0200 | [diff] [blame] | 995 | |
Arnaldo Carvalho de Melo | aeafcba | 2011-03-31 10:56:28 -0300 | [diff] [blame] | 996 | if (dso->kernel == DSO_TYPE_KERNEL) |
| 997 | return dso__load_kernel_sym(dso, map, filter); |
| 998 | else if (dso->kernel == DSO_TYPE_GUEST_KERNEL) |
| 999 | return dso__load_guest_kernel_sym(dso, map, filter); |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 1000 | |
Arnaldo Carvalho de Melo | 23346f2 | 2010-04-27 21:17:50 -0300 | [diff] [blame] | 1001 | if (map->groups && map->groups->machine) |
| 1002 | machine = map->groups->machine; |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 1003 | else |
Arnaldo Carvalho de Melo | 23346f2 | 2010-04-27 21:17:50 -0300 | [diff] [blame] | 1004 | machine = NULL; |
Arnaldo Carvalho de Melo | c338aee | 2009-11-20 20:51:27 -0200 | [diff] [blame] | 1005 | |
Arnaldo Carvalho de Melo | aeafcba | 2011-03-31 10:56:28 -0300 | [diff] [blame] | 1006 | dso->adjust_symbols = 0; |
Arnaldo Carvalho de Melo | f5812a7 | 2009-06-30 11:43:17 -0300 | [diff] [blame] | 1007 | |
Arnaldo Carvalho de Melo | aeafcba | 2011-03-31 10:56:28 -0300 | [diff] [blame] | 1008 | if (strncmp(dso->name, "/tmp/perf-", 10) == 0) { |
Pekka Enberg | 981c125 | 2011-08-09 22:54:18 +0300 | [diff] [blame] | 1009 | struct stat st; |
| 1010 | |
Vasiliy Kulikov | e9b52ef | 2011-08-12 00:55:37 +0400 | [diff] [blame] | 1011 | if (lstat(dso->name, &st) < 0) |
Pekka Enberg | 981c125 | 2011-08-09 22:54:18 +0300 | [diff] [blame] | 1012 | return -1; |
| 1013 | |
| 1014 | if (st.st_uid && (st.st_uid != geteuid())) { |
| 1015 | pr_warning("File %s not owned by current user or root, " |
| 1016 | "ignoring it.\n", dso->name); |
| 1017 | return -1; |
| 1018 | } |
| 1019 | |
Arnaldo Carvalho de Melo | aeafcba | 2011-03-31 10:56:28 -0300 | [diff] [blame] | 1020 | ret = dso__load_perf_map(dso, map, filter); |
Jiri Olsa | 44f24cb | 2012-07-22 14:14:32 +0200 | [diff] [blame] | 1021 | dso->symtab_type = ret > 0 ? DSO_BINARY_TYPE__JAVA_JIT : |
| 1022 | DSO_BINARY_TYPE__NOT_FOUND; |
Arnaldo Carvalho de Melo | 94cb9e3 | 2009-08-06 14:43:17 -0300 | [diff] [blame] | 1023 | return ret; |
| 1024 | } |
| 1025 | |
Jiri Olsa | 44f24cb | 2012-07-22 14:14:32 +0200 | [diff] [blame] | 1026 | if (machine) |
| 1027 | root_dir = machine->root_dir; |
| 1028 | |
David Ahern | 164c800 | 2013-01-14 10:46:47 -0700 | [diff] [blame] | 1029 | name = malloc(PATH_MAX); |
| 1030 | if (!name) |
| 1031 | return -1; |
| 1032 | |
Dave Martin | 6da80ce | 2010-07-30 09:50:09 -0300 | [diff] [blame] | 1033 | /* Iterate over candidate debug images. |
Cody P Schafer | 3aafe5a | 2012-08-10 15:23:02 -0700 | [diff] [blame] | 1034 | * Keep track of "interesting" ones (those which have a symtab, dynsym, |
| 1035 | * and/or opd section) for processing. |
Dave Martin | 6da80ce | 2010-07-30 09:50:09 -0300 | [diff] [blame] | 1036 | */ |
Jiri Olsa | 44f24cb | 2012-07-22 14:14:32 +0200 | [diff] [blame] | 1037 | for (i = 0; i < DSO_BINARY_TYPE__SYMTAB_CNT; i++) { |
Cody P Schafer | 3aafe5a | 2012-08-10 15:23:02 -0700 | [diff] [blame] | 1038 | struct symsrc *ss = &ss_[ss_pos]; |
| 1039 | bool next_slot = false; |
Dave Martin | 6da80ce | 2010-07-30 09:50:09 -0300 | [diff] [blame] | 1040 | |
Cody P Schafer | 005f929 | 2012-08-10 15:22:58 -0700 | [diff] [blame] | 1041 | enum dso_binary_type symtab_type = binary_type_symtab[i]; |
Dave Martin | 6da80ce | 2010-07-30 09:50:09 -0300 | [diff] [blame] | 1042 | |
Cody P Schafer | 005f929 | 2012-08-10 15:22:58 -0700 | [diff] [blame] | 1043 | if (dso__binary_type_file(dso, symtab_type, |
Jiri Olsa | 44f24cb | 2012-07-22 14:14:32 +0200 | [diff] [blame] | 1044 | root_dir, name, PATH_MAX)) |
| 1045 | continue; |
Dave Martin | 6da80ce | 2010-07-30 09:50:09 -0300 | [diff] [blame] | 1046 | |
| 1047 | /* Name is now the name of the next image to try */ |
Cody P Schafer | 3aafe5a | 2012-08-10 15:23:02 -0700 | [diff] [blame] | 1048 | if (symsrc__init(ss, dso, name, symtab_type) < 0) |
Dave Martin | 6da80ce | 2010-07-30 09:50:09 -0300 | [diff] [blame] | 1049 | continue; |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 1050 | |
Cody P Schafer | 3aafe5a | 2012-08-10 15:23:02 -0700 | [diff] [blame] | 1051 | if (!syms_ss && symsrc__has_symtab(ss)) { |
| 1052 | syms_ss = ss; |
| 1053 | next_slot = true; |
Cody P Schafer | d26cd12 | 2012-08-10 15:23:00 -0700 | [diff] [blame] | 1054 | } |
| 1055 | |
Cody P Schafer | 3aafe5a | 2012-08-10 15:23:02 -0700 | [diff] [blame] | 1056 | if (!runtime_ss && symsrc__possibly_runtime(ss)) { |
| 1057 | runtime_ss = ss; |
| 1058 | next_slot = true; |
Cody P Schafer | a44f605 | 2012-08-10 15:22:59 -0700 | [diff] [blame] | 1059 | } |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 1060 | |
Cody P Schafer | 3aafe5a | 2012-08-10 15:23:02 -0700 | [diff] [blame] | 1061 | if (next_slot) { |
| 1062 | ss_pos++; |
Jiri Olsa | 33ff581 | 2012-04-18 15:46:58 +0200 | [diff] [blame] | 1063 | |
Cody P Schafer | 3aafe5a | 2012-08-10 15:23:02 -0700 | [diff] [blame] | 1064 | if (syms_ss && runtime_ss) |
| 1065 | break; |
Dave Martin | 6da80ce | 2010-07-30 09:50:09 -0300 | [diff] [blame] | 1066 | } |
Cody P Schafer | 3aafe5a | 2012-08-10 15:23:02 -0700 | [diff] [blame] | 1067 | |
Arnaldo Carvalho de Melo | a25e46c | 2009-07-11 12:18:36 -0300 | [diff] [blame] | 1068 | } |
Dave Martin | 6da80ce | 2010-07-30 09:50:09 -0300 | [diff] [blame] | 1069 | |
Cody P Schafer | 3aafe5a | 2012-08-10 15:23:02 -0700 | [diff] [blame] | 1070 | if (!runtime_ss && !syms_ss) |
| 1071 | goto out_free; |
| 1072 | |
| 1073 | if (runtime_ss && !syms_ss) { |
| 1074 | syms_ss = runtime_ss; |
Arnaldo Carvalho de Melo | 60e4b10 | 2011-03-22 15:42:14 -0300 | [diff] [blame] | 1075 | } |
| 1076 | |
Cody P Schafer | 3aafe5a | 2012-08-10 15:23:02 -0700 | [diff] [blame] | 1077 | /* We'll have to hope for the best */ |
| 1078 | if (!runtime_ss && syms_ss) |
| 1079 | runtime_ss = syms_ss; |
| 1080 | |
Adrian Hunter | 0131c4e | 2013-08-07 14:38:50 +0300 | [diff] [blame] | 1081 | if (syms_ss) { |
| 1082 | int km; |
| 1083 | |
| 1084 | km = dso->symtab_type == DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE || |
| 1085 | dso->symtab_type == DSO_BINARY_TYPE__GUEST_KMODULE; |
| 1086 | ret = dso__load_sym(dso, map, syms_ss, runtime_ss, filter, km); |
| 1087 | } else { |
Cody P Schafer | 3aafe5a | 2012-08-10 15:23:02 -0700 | [diff] [blame] | 1088 | ret = -1; |
Adrian Hunter | 0131c4e | 2013-08-07 14:38:50 +0300 | [diff] [blame] | 1089 | } |
Cody P Schafer | 3aafe5a | 2012-08-10 15:23:02 -0700 | [diff] [blame] | 1090 | |
David Ahern | f47b58b | 2012-08-19 09:47:14 -0600 | [diff] [blame] | 1091 | if (ret > 0) { |
Cody P Schafer | 3aafe5a | 2012-08-10 15:23:02 -0700 | [diff] [blame] | 1092 | int nr_plt; |
| 1093 | |
| 1094 | nr_plt = dso__synthesize_plt_symbols(dso, runtime_ss, map, filter); |
| 1095 | if (nr_plt > 0) |
| 1096 | ret += nr_plt; |
| 1097 | } |
| 1098 | |
| 1099 | for (; ss_pos > 0; ss_pos--) |
| 1100 | symsrc__destroy(&ss_[ss_pos - 1]); |
| 1101 | out_free: |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 1102 | free(name); |
Arnaldo Carvalho de Melo | aeafcba | 2011-03-31 10:56:28 -0300 | [diff] [blame] | 1103 | if (ret < 0 && strstr(dso->name, " (deleted)") != NULL) |
Arnaldo Carvalho de Melo | 1340e6b | 2009-08-11 17:04:36 -0300 | [diff] [blame] | 1104 | return 0; |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 1105 | return ret; |
| 1106 | } |
| 1107 | |
Arnaldo Carvalho de Melo | aeafcba | 2011-03-31 10:56:28 -0300 | [diff] [blame] | 1108 | struct map *map_groups__find_by_name(struct map_groups *mg, |
Arnaldo Carvalho de Melo | 79406cd | 2009-12-11 18:50:22 -0200 | [diff] [blame] | 1109 | enum map_type type, const char *name) |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 1110 | { |
| 1111 | struct rb_node *nd; |
| 1112 | |
Arnaldo Carvalho de Melo | aeafcba | 2011-03-31 10:56:28 -0300 | [diff] [blame] | 1113 | for (nd = rb_first(&mg->maps[type]); nd; nd = rb_next(nd)) { |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 1114 | struct map *map = rb_entry(nd, struct map, rb_node); |
| 1115 | |
Arnaldo Carvalho de Melo | b7cece76 | 2010-01-13 13:22:17 -0200 | [diff] [blame] | 1116 | if (map->dso && strcmp(map->dso->short_name, name) == 0) |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 1117 | return map; |
| 1118 | } |
| 1119 | |
| 1120 | return NULL; |
| 1121 | } |
| 1122 | |
Arnaldo Carvalho de Melo | aeafcba | 2011-03-31 10:56:28 -0300 | [diff] [blame] | 1123 | int dso__load_vmlinux(struct dso *dso, struct map *map, |
Franck Bui-Huu | fd930ff | 2010-12-10 14:06:03 +0100 | [diff] [blame] | 1124 | const char *vmlinux, symbol_filter_t filter) |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 1125 | { |
Cody P Schafer | b68e2f9 | 2012-08-10 15:22:57 -0700 | [diff] [blame] | 1126 | int err = -1; |
| 1127 | struct symsrc ss; |
David Ahern | ec5761e | 2010-12-09 13:27:07 -0700 | [diff] [blame] | 1128 | char symfs_vmlinux[PATH_MAX]; |
Cody P Schafer | 005f929 | 2012-08-10 15:22:58 -0700 | [diff] [blame] | 1129 | enum dso_binary_type symtab_type; |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 1130 | |
Namhyung Kim | 5698d2c | 2013-07-17 17:08:15 +0900 | [diff] [blame] | 1131 | if (vmlinux[0] == '/') |
| 1132 | snprintf(symfs_vmlinux, sizeof(symfs_vmlinux), "%s", vmlinux); |
| 1133 | else |
| 1134 | snprintf(symfs_vmlinux, sizeof(symfs_vmlinux), "%s%s", |
| 1135 | symbol_conf.symfs, vmlinux); |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 1136 | |
Cody P Schafer | 21ea453 | 2012-08-10 15:22:56 -0700 | [diff] [blame] | 1137 | if (dso->kernel == DSO_TYPE_GUEST_KERNEL) |
Cody P Schafer | 005f929 | 2012-08-10 15:22:58 -0700 | [diff] [blame] | 1138 | symtab_type = DSO_BINARY_TYPE__GUEST_VMLINUX; |
Cody P Schafer | 21ea453 | 2012-08-10 15:22:56 -0700 | [diff] [blame] | 1139 | else |
Cody P Schafer | 005f929 | 2012-08-10 15:22:58 -0700 | [diff] [blame] | 1140 | symtab_type = DSO_BINARY_TYPE__VMLINUX; |
Cody P Schafer | 21ea453 | 2012-08-10 15:22:56 -0700 | [diff] [blame] | 1141 | |
Cody P Schafer | 005f929 | 2012-08-10 15:22:58 -0700 | [diff] [blame] | 1142 | if (symsrc__init(&ss, dso, symfs_vmlinux, symtab_type)) |
Cody P Schafer | b68e2f9 | 2012-08-10 15:22:57 -0700 | [diff] [blame] | 1143 | return -1; |
| 1144 | |
Cody P Schafer | 261360b | 2012-08-10 15:23:01 -0700 | [diff] [blame] | 1145 | err = dso__load_sym(dso, map, &ss, &ss, filter, 0); |
Cody P Schafer | b68e2f9 | 2012-08-10 15:22:57 -0700 | [diff] [blame] | 1146 | symsrc__destroy(&ss); |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 1147 | |
Cody P Schafer | 515850e | 2012-08-10 15:22:54 -0700 | [diff] [blame] | 1148 | if (err > 0) { |
Adrian Hunter | 39b12f78 | 2013-08-07 14:38:47 +0300 | [diff] [blame] | 1149 | if (dso->kernel == DSO_TYPE_GUEST_KERNEL) |
| 1150 | dso->data_type = DSO_BINARY_TYPE__GUEST_VMLINUX; |
| 1151 | else |
| 1152 | dso->data_type = DSO_BINARY_TYPE__VMLINUX; |
Cody P Schafer | 515850e | 2012-08-10 15:22:54 -0700 | [diff] [blame] | 1153 | dso__set_long_name(dso, (char *)vmlinux); |
| 1154 | dso__set_loaded(dso, map->type); |
David Ahern | ec5761e | 2010-12-09 13:27:07 -0700 | [diff] [blame] | 1155 | pr_debug("Using %s for symbols\n", symfs_vmlinux); |
Cody P Schafer | 515850e | 2012-08-10 15:22:54 -0700 | [diff] [blame] | 1156 | } |
Arnaldo Carvalho de Melo | 3846df2 | 2010-02-22 16:15:39 -0300 | [diff] [blame] | 1157 | |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 1158 | return err; |
| 1159 | } |
| 1160 | |
Arnaldo Carvalho de Melo | aeafcba | 2011-03-31 10:56:28 -0300 | [diff] [blame] | 1161 | int dso__load_vmlinux_path(struct dso *dso, struct map *map, |
Arnaldo Carvalho de Melo | 9de89fe | 2010-02-03 16:52:00 -0200 | [diff] [blame] | 1162 | symbol_filter_t filter) |
Arnaldo Carvalho de Melo | a19afe4 | 2010-01-27 21:05:50 -0200 | [diff] [blame] | 1163 | { |
| 1164 | int i, err = 0; |
Arnaldo Carvalho de Melo | 5ad90e4 | 2010-05-26 13:26:02 -0300 | [diff] [blame] | 1165 | char *filename; |
Arnaldo Carvalho de Melo | a19afe4 | 2010-01-27 21:05:50 -0200 | [diff] [blame] | 1166 | |
| 1167 | pr_debug("Looking at the vmlinux_path (%d entries long)\n", |
Arnaldo Carvalho de Melo | 5ad90e4 | 2010-05-26 13:26:02 -0300 | [diff] [blame] | 1168 | vmlinux_path__nr_entries + 1); |
| 1169 | |
Arnaldo Carvalho de Melo | aeafcba | 2011-03-31 10:56:28 -0300 | [diff] [blame] | 1170 | filename = dso__build_id_filename(dso, NULL, 0); |
Arnaldo Carvalho de Melo | 5ad90e4 | 2010-05-26 13:26:02 -0300 | [diff] [blame] | 1171 | if (filename != NULL) { |
Arnaldo Carvalho de Melo | aeafcba | 2011-03-31 10:56:28 -0300 | [diff] [blame] | 1172 | err = dso__load_vmlinux(dso, map, filename, filter); |
David Ahern | b7c14a0 | 2013-01-14 10:47:30 -0700 | [diff] [blame] | 1173 | if (err > 0) { |
| 1174 | dso->lname_alloc = 1; |
Arnaldo Carvalho de Melo | 5ad90e4 | 2010-05-26 13:26:02 -0300 | [diff] [blame] | 1175 | goto out; |
David Ahern | b7c14a0 | 2013-01-14 10:47:30 -0700 | [diff] [blame] | 1176 | } |
Arnaldo Carvalho de Melo | 5ad90e4 | 2010-05-26 13:26:02 -0300 | [diff] [blame] | 1177 | free(filename); |
| 1178 | } |
Arnaldo Carvalho de Melo | a19afe4 | 2010-01-27 21:05:50 -0200 | [diff] [blame] | 1179 | |
| 1180 | for (i = 0; i < vmlinux_path__nr_entries; ++i) { |
Arnaldo Carvalho de Melo | aeafcba | 2011-03-31 10:56:28 -0300 | [diff] [blame] | 1181 | err = dso__load_vmlinux(dso, map, vmlinux_path[i], filter); |
Arnaldo Carvalho de Melo | a19afe4 | 2010-01-27 21:05:50 -0200 | [diff] [blame] | 1182 | if (err > 0) { |
Arnaldo Carvalho de Melo | aeafcba | 2011-03-31 10:56:28 -0300 | [diff] [blame] | 1183 | dso__set_long_name(dso, strdup(vmlinux_path[i])); |
David Ahern | b7c14a0 | 2013-01-14 10:47:30 -0700 | [diff] [blame] | 1184 | dso->lname_alloc = 1; |
Arnaldo Carvalho de Melo | a19afe4 | 2010-01-27 21:05:50 -0200 | [diff] [blame] | 1185 | break; |
| 1186 | } |
| 1187 | } |
Arnaldo Carvalho de Melo | 5ad90e4 | 2010-05-26 13:26:02 -0300 | [diff] [blame] | 1188 | out: |
Arnaldo Carvalho de Melo | a19afe4 | 2010-01-27 21:05:50 -0200 | [diff] [blame] | 1189 | return err; |
| 1190 | } |
| 1191 | |
Arnaldo Carvalho de Melo | aeafcba | 2011-03-31 10:56:28 -0300 | [diff] [blame] | 1192 | static int dso__load_kernel_sym(struct dso *dso, struct map *map, |
Arnaldo Carvalho de Melo | 9de89fe | 2010-02-03 16:52:00 -0200 | [diff] [blame] | 1193 | symbol_filter_t filter) |
Arnaldo Carvalho de Melo | a827c87 | 2009-05-28 14:55:19 -0300 | [diff] [blame] | 1194 | { |
Arnaldo Carvalho de Melo | cc612d8 | 2009-11-23 16:39:10 -0200 | [diff] [blame] | 1195 | int err; |
Arnaldo Carvalho de Melo | 9e20144 | 2010-01-14 18:30:06 -0200 | [diff] [blame] | 1196 | const char *kallsyms_filename = NULL; |
| 1197 | char *kallsyms_allocated_filename = NULL; |
Arnaldo Carvalho de Melo | dc8d6ab | 2010-01-19 10:36:14 -0200 | [diff] [blame] | 1198 | /* |
David Ahern | b226a5a7 | 2010-12-07 19:39:46 -0700 | [diff] [blame] | 1199 | * Step 1: if the user specified a kallsyms or vmlinux filename, use |
| 1200 | * it and only it, reporting errors to the user if it cannot be used. |
Arnaldo Carvalho de Melo | dc8d6ab | 2010-01-19 10:36:14 -0200 | [diff] [blame] | 1201 | * |
| 1202 | * For instance, try to analyse an ARM perf.data file _without_ a |
| 1203 | * build-id, or if the user specifies the wrong path to the right |
| 1204 | * vmlinux file, obviously we can't fallback to another vmlinux (a |
| 1205 | * x86_86 one, on the machine where analysis is being performed, say), |
| 1206 | * or worse, /proc/kallsyms. |
| 1207 | * |
| 1208 | * If the specified file _has_ a build-id and there is a build-id |
| 1209 | * section in the perf.data file, we will still do the expected |
| 1210 | * validation in dso__load_vmlinux and will bail out if they don't |
| 1211 | * match. |
| 1212 | */ |
David Ahern | b226a5a7 | 2010-12-07 19:39:46 -0700 | [diff] [blame] | 1213 | if (symbol_conf.kallsyms_name != NULL) { |
| 1214 | kallsyms_filename = symbol_conf.kallsyms_name; |
| 1215 | goto do_kallsyms; |
| 1216 | } |
| 1217 | |
Willy Tarreau | fc2be69 | 2013-09-14 10:32:59 +0200 | [diff] [blame] | 1218 | if (!symbol_conf.ignore_vmlinux && symbol_conf.vmlinux_name != NULL) { |
Arnaldo Carvalho de Melo | aeafcba | 2011-03-31 10:56:28 -0300 | [diff] [blame] | 1219 | err = dso__load_vmlinux(dso, map, |
Arnaldo Carvalho de Melo | dc8d6ab | 2010-01-19 10:36:14 -0200 | [diff] [blame] | 1220 | symbol_conf.vmlinux_name, filter); |
Arnaldo Carvalho de Melo | e7dadc0 | 2010-06-03 18:35:55 -0300 | [diff] [blame] | 1221 | if (err > 0) { |
Arnaldo Carvalho de Melo | aeafcba | 2011-03-31 10:56:28 -0300 | [diff] [blame] | 1222 | dso__set_long_name(dso, |
Arnaldo Carvalho de Melo | e7dadc0 | 2010-06-03 18:35:55 -0300 | [diff] [blame] | 1223 | strdup(symbol_conf.vmlinux_name)); |
David Ahern | b7c14a0 | 2013-01-14 10:47:30 -0700 | [diff] [blame] | 1224 | dso->lname_alloc = 1; |
Adrian Hunter | 39b12f78 | 2013-08-07 14:38:47 +0300 | [diff] [blame] | 1225 | return err; |
Arnaldo Carvalho de Melo | e7dadc0 | 2010-06-03 18:35:55 -0300 | [diff] [blame] | 1226 | } |
| 1227 | return err; |
Arnaldo Carvalho de Melo | dc8d6ab | 2010-01-19 10:36:14 -0200 | [diff] [blame] | 1228 | } |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 1229 | |
Willy Tarreau | fc2be69 | 2013-09-14 10:32:59 +0200 | [diff] [blame] | 1230 | if (!symbol_conf.ignore_vmlinux && vmlinux_path != NULL) { |
Arnaldo Carvalho de Melo | aeafcba | 2011-03-31 10:56:28 -0300 | [diff] [blame] | 1231 | err = dso__load_vmlinux_path(dso, map, filter); |
Arnaldo Carvalho de Melo | a19afe4 | 2010-01-27 21:05:50 -0200 | [diff] [blame] | 1232 | if (err > 0) |
Adrian Hunter | 39b12f78 | 2013-08-07 14:38:47 +0300 | [diff] [blame] | 1233 | return err; |
Arnaldo Carvalho de Melo | cc612d8 | 2009-11-23 16:39:10 -0200 | [diff] [blame] | 1234 | } |
| 1235 | |
David Ahern | ec5761e | 2010-12-09 13:27:07 -0700 | [diff] [blame] | 1236 | /* do not try local files if a symfs was given */ |
| 1237 | if (symbol_conf.symfs[0] != 0) |
| 1238 | return -1; |
| 1239 | |
Arnaldo Carvalho de Melo | b7cece76 | 2010-01-13 13:22:17 -0200 | [diff] [blame] | 1240 | /* |
| 1241 | * Say the kernel DSO was created when processing the build-id header table, |
| 1242 | * we have a build-id, so check if it is the same as the running kernel, |
| 1243 | * using it if it is. |
| 1244 | */ |
Arnaldo Carvalho de Melo | aeafcba | 2011-03-31 10:56:28 -0300 | [diff] [blame] | 1245 | if (dso->has_build_id) { |
Arnaldo Carvalho de Melo | b7cece76 | 2010-01-13 13:22:17 -0200 | [diff] [blame] | 1246 | u8 kallsyms_build_id[BUILD_ID_SIZE]; |
Arnaldo Carvalho de Melo | 9e20144 | 2010-01-14 18:30:06 -0200 | [diff] [blame] | 1247 | char sbuild_id[BUILD_ID_SIZE * 2 + 1]; |
Arnaldo Carvalho de Melo | b7cece76 | 2010-01-13 13:22:17 -0200 | [diff] [blame] | 1248 | |
| 1249 | if (sysfs__read_build_id("/sys/kernel/notes", kallsyms_build_id, |
Arnaldo Carvalho de Melo | 8d0591f6 | 2010-01-14 18:30:05 -0200 | [diff] [blame] | 1250 | sizeof(kallsyms_build_id)) == 0) { |
Arnaldo Carvalho de Melo | aeafcba | 2011-03-31 10:56:28 -0300 | [diff] [blame] | 1251 | if (dso__build_id_equal(dso, kallsyms_build_id)) { |
Arnaldo Carvalho de Melo | 9e20144 | 2010-01-14 18:30:06 -0200 | [diff] [blame] | 1252 | kallsyms_filename = "/proc/kallsyms"; |
Arnaldo Carvalho de Melo | 8d0591f6 | 2010-01-14 18:30:05 -0200 | [diff] [blame] | 1253 | goto do_kallsyms; |
Arnaldo Carvalho de Melo | 9e20144 | 2010-01-14 18:30:06 -0200 | [diff] [blame] | 1254 | } |
Arnaldo Carvalho de Melo | 8d0591f6 | 2010-01-14 18:30:05 -0200 | [diff] [blame] | 1255 | } |
Arnaldo Carvalho de Melo | dc8d6ab | 2010-01-19 10:36:14 -0200 | [diff] [blame] | 1256 | /* |
| 1257 | * Now look if we have it on the build-id cache in |
| 1258 | * $HOME/.debug/[kernel.kallsyms]. |
| 1259 | */ |
Arnaldo Carvalho de Melo | aeafcba | 2011-03-31 10:56:28 -0300 | [diff] [blame] | 1260 | build_id__sprintf(dso->build_id, sizeof(dso->build_id), |
Arnaldo Carvalho de Melo | 9e20144 | 2010-01-14 18:30:06 -0200 | [diff] [blame] | 1261 | sbuild_id); |
| 1262 | |
| 1263 | if (asprintf(&kallsyms_allocated_filename, |
| 1264 | "%s/.debug/[kernel.kallsyms]/%s", |
Arnaldo Carvalho de Melo | 3846df2 | 2010-02-22 16:15:39 -0300 | [diff] [blame] | 1265 | getenv("HOME"), sbuild_id) == -1) { |
| 1266 | pr_err("Not enough memory for kallsyms file lookup\n"); |
Arnaldo Carvalho de Melo | 8d0591f6 | 2010-01-14 18:30:05 -0200 | [diff] [blame] | 1267 | return -1; |
Arnaldo Carvalho de Melo | 3846df2 | 2010-02-22 16:15:39 -0300 | [diff] [blame] | 1268 | } |
Arnaldo Carvalho de Melo | 8d0591f6 | 2010-01-14 18:30:05 -0200 | [diff] [blame] | 1269 | |
Arnaldo Carvalho de Melo | 19fc2de | 2010-01-22 14:35:02 -0200 | [diff] [blame] | 1270 | kallsyms_filename = kallsyms_allocated_filename; |
| 1271 | |
Arnaldo Carvalho de Melo | dc8d6ab | 2010-01-19 10:36:14 -0200 | [diff] [blame] | 1272 | if (access(kallsyms_filename, F_OK)) { |
Arnaldo Carvalho de Melo | 3846df2 | 2010-02-22 16:15:39 -0300 | [diff] [blame] | 1273 | pr_err("No kallsyms or vmlinux with build-id %s " |
| 1274 | "was found\n", sbuild_id); |
Arnaldo Carvalho de Melo | dc8d6ab | 2010-01-19 10:36:14 -0200 | [diff] [blame] | 1275 | free(kallsyms_allocated_filename); |
| 1276 | return -1; |
| 1277 | } |
Arnaldo Carvalho de Melo | dc8d6ab | 2010-01-19 10:36:14 -0200 | [diff] [blame] | 1278 | } else { |
| 1279 | /* |
| 1280 | * Last resort, if we don't have a build-id and couldn't find |
| 1281 | * any vmlinux file, try the running kernel kallsyms table. |
| 1282 | */ |
| 1283 | kallsyms_filename = "/proc/kallsyms"; |
Arnaldo Carvalho de Melo | ef6ae72 | 2009-11-20 20:51:29 -0200 | [diff] [blame] | 1284 | } |
Arnaldo Carvalho de Melo | a827c87 | 2009-05-28 14:55:19 -0300 | [diff] [blame] | 1285 | |
Arnaldo Carvalho de Melo | dc8d6ab | 2010-01-19 10:36:14 -0200 | [diff] [blame] | 1286 | do_kallsyms: |
Arnaldo Carvalho de Melo | aeafcba | 2011-03-31 10:56:28 -0300 | [diff] [blame] | 1287 | err = dso__load_kallsyms(dso, kallsyms_filename, map, filter); |
Arnaldo Carvalho de Melo | 3846df2 | 2010-02-22 16:15:39 -0300 | [diff] [blame] | 1288 | if (err > 0) |
| 1289 | pr_debug("Using %s for symbols\n", kallsyms_filename); |
Arnaldo Carvalho de Melo | dc8d6ab | 2010-01-19 10:36:14 -0200 | [diff] [blame] | 1290 | free(kallsyms_allocated_filename); |
| 1291 | |
Adrian Hunter | 8e0cf96 | 2013-08-07 14:38:51 +0300 | [diff] [blame] | 1292 | if (err > 0 && !dso__is_kcore(dso)) { |
Cody P Schafer | 0a0317b | 2012-08-10 15:22:53 -0700 | [diff] [blame] | 1293 | dso__set_long_name(dso, strdup("[kernel.kallsyms]")); |
Arnaldo Carvalho de Melo | 6a4694a | 2009-11-27 16:29:17 -0200 | [diff] [blame] | 1294 | map__fixup_start(map); |
| 1295 | map__fixup_end(map); |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 1296 | } |
Arnaldo Carvalho de Melo | 94cb9e3 | 2009-08-06 14:43:17 -0300 | [diff] [blame] | 1297 | |
Arnaldo Carvalho de Melo | a827c87 | 2009-05-28 14:55:19 -0300 | [diff] [blame] | 1298 | return err; |
| 1299 | } |
| 1300 | |
Arnaldo Carvalho de Melo | aeafcba | 2011-03-31 10:56:28 -0300 | [diff] [blame] | 1301 | static int dso__load_guest_kernel_sym(struct dso *dso, struct map *map, |
| 1302 | symbol_filter_t filter) |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 1303 | { |
| 1304 | int err; |
| 1305 | const char *kallsyms_filename = NULL; |
Arnaldo Carvalho de Melo | 23346f2 | 2010-04-27 21:17:50 -0300 | [diff] [blame] | 1306 | struct machine *machine; |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 1307 | char path[PATH_MAX]; |
| 1308 | |
| 1309 | if (!map->groups) { |
| 1310 | pr_debug("Guest kernel map hasn't the point to groups\n"); |
| 1311 | return -1; |
| 1312 | } |
Arnaldo Carvalho de Melo | 23346f2 | 2010-04-27 21:17:50 -0300 | [diff] [blame] | 1313 | machine = map->groups->machine; |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 1314 | |
Arnaldo Carvalho de Melo | 23346f2 | 2010-04-27 21:17:50 -0300 | [diff] [blame] | 1315 | if (machine__is_default_guest(machine)) { |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 1316 | /* |
| 1317 | * if the user specified a vmlinux filename, use it and only |
| 1318 | * it, reporting errors to the user if it cannot be used. |
| 1319 | * Or use file guest_kallsyms inputted by user on commandline |
| 1320 | */ |
| 1321 | if (symbol_conf.default_guest_vmlinux_name != NULL) { |
Arnaldo Carvalho de Melo | aeafcba | 2011-03-31 10:56:28 -0300 | [diff] [blame] | 1322 | err = dso__load_vmlinux(dso, map, |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 1323 | symbol_conf.default_guest_vmlinux_name, filter); |
Adrian Hunter | 39b12f78 | 2013-08-07 14:38:47 +0300 | [diff] [blame] | 1324 | return err; |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 1325 | } |
| 1326 | |
| 1327 | kallsyms_filename = symbol_conf.default_guest_kallsyms; |
| 1328 | if (!kallsyms_filename) |
| 1329 | return -1; |
| 1330 | } else { |
Arnaldo Carvalho de Melo | 23346f2 | 2010-04-27 21:17:50 -0300 | [diff] [blame] | 1331 | sprintf(path, "%s/proc/kallsyms", machine->root_dir); |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 1332 | kallsyms_filename = path; |
| 1333 | } |
| 1334 | |
Arnaldo Carvalho de Melo | aeafcba | 2011-03-31 10:56:28 -0300 | [diff] [blame] | 1335 | err = dso__load_kallsyms(dso, kallsyms_filename, map, filter); |
Adrian Hunter | 8e0cf96 | 2013-08-07 14:38:51 +0300 | [diff] [blame] | 1336 | if (err > 0) |
Adrian Hunter | 39b12f78 | 2013-08-07 14:38:47 +0300 | [diff] [blame] | 1337 | pr_debug("Using %s for symbols\n", kallsyms_filename); |
Adrian Hunter | 8e0cf96 | 2013-08-07 14:38:51 +0300 | [diff] [blame] | 1338 | if (err > 0 && !dso__is_kcore(dso)) { |
Adrian Hunter | 39b12f78 | 2013-08-07 14:38:47 +0300 | [diff] [blame] | 1339 | machine__mmap_name(machine, path, sizeof(path)); |
| 1340 | dso__set_long_name(dso, strdup(path)); |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 1341 | map__fixup_start(map); |
| 1342 | map__fixup_end(map); |
| 1343 | } |
| 1344 | |
| 1345 | return err; |
| 1346 | } |
Frederic Weisbecker | cd84c2a | 2009-08-12 10:03:49 +0200 | [diff] [blame] | 1347 | |
Arnaldo Carvalho de Melo | cc612d8 | 2009-11-23 16:39:10 -0200 | [diff] [blame] | 1348 | static void vmlinux_path__exit(void) |
Arnaldo Carvalho de Melo | 2446042 | 2009-11-18 20:20:53 -0200 | [diff] [blame] | 1349 | { |
Arnaldo Carvalho de Melo | cc612d8 | 2009-11-23 16:39:10 -0200 | [diff] [blame] | 1350 | while (--vmlinux_path__nr_entries >= 0) { |
| 1351 | free(vmlinux_path[vmlinux_path__nr_entries]); |
| 1352 | vmlinux_path[vmlinux_path__nr_entries] = NULL; |
| 1353 | } |
| 1354 | |
| 1355 | free(vmlinux_path); |
| 1356 | vmlinux_path = NULL; |
| 1357 | } |
| 1358 | |
| 1359 | static int vmlinux_path__init(void) |
| 1360 | { |
| 1361 | struct utsname uts; |
| 1362 | char bf[PATH_MAX]; |
| 1363 | |
Arnaldo Carvalho de Melo | cc612d8 | 2009-11-23 16:39:10 -0200 | [diff] [blame] | 1364 | vmlinux_path = malloc(sizeof(char *) * 5); |
| 1365 | if (vmlinux_path == NULL) |
| 1366 | return -1; |
| 1367 | |
| 1368 | vmlinux_path[vmlinux_path__nr_entries] = strdup("vmlinux"); |
| 1369 | if (vmlinux_path[vmlinux_path__nr_entries] == NULL) |
| 1370 | goto out_fail; |
| 1371 | ++vmlinux_path__nr_entries; |
| 1372 | vmlinux_path[vmlinux_path__nr_entries] = strdup("/boot/vmlinux"); |
| 1373 | if (vmlinux_path[vmlinux_path__nr_entries] == NULL) |
| 1374 | goto out_fail; |
| 1375 | ++vmlinux_path__nr_entries; |
David Ahern | ec5761e | 2010-12-09 13:27:07 -0700 | [diff] [blame] | 1376 | |
| 1377 | /* only try running kernel version if no symfs was given */ |
| 1378 | if (symbol_conf.symfs[0] != 0) |
| 1379 | return 0; |
| 1380 | |
| 1381 | if (uname(&uts) < 0) |
| 1382 | return -1; |
| 1383 | |
Arnaldo Carvalho de Melo | cc612d8 | 2009-11-23 16:39:10 -0200 | [diff] [blame] | 1384 | snprintf(bf, sizeof(bf), "/boot/vmlinux-%s", uts.release); |
| 1385 | vmlinux_path[vmlinux_path__nr_entries] = strdup(bf); |
| 1386 | if (vmlinux_path[vmlinux_path__nr_entries] == NULL) |
| 1387 | goto out_fail; |
| 1388 | ++vmlinux_path__nr_entries; |
| 1389 | snprintf(bf, sizeof(bf), "/lib/modules/%s/build/vmlinux", uts.release); |
| 1390 | vmlinux_path[vmlinux_path__nr_entries] = strdup(bf); |
| 1391 | if (vmlinux_path[vmlinux_path__nr_entries] == NULL) |
| 1392 | goto out_fail; |
| 1393 | ++vmlinux_path__nr_entries; |
| 1394 | snprintf(bf, sizeof(bf), "/usr/lib/debug/lib/modules/%s/vmlinux", |
| 1395 | uts.release); |
| 1396 | vmlinux_path[vmlinux_path__nr_entries] = strdup(bf); |
| 1397 | if (vmlinux_path[vmlinux_path__nr_entries] == NULL) |
| 1398 | goto out_fail; |
| 1399 | ++vmlinux_path__nr_entries; |
| 1400 | |
| 1401 | return 0; |
| 1402 | |
| 1403 | out_fail: |
| 1404 | vmlinux_path__exit(); |
| 1405 | return -1; |
| 1406 | } |
| 1407 | |
Arnaldo Carvalho de Melo | 655000e | 2009-12-15 20:04:40 -0200 | [diff] [blame] | 1408 | static int setup_list(struct strlist **list, const char *list_str, |
| 1409 | const char *list_name) |
| 1410 | { |
| 1411 | if (list_str == NULL) |
| 1412 | return 0; |
| 1413 | |
| 1414 | *list = strlist__new(true, list_str); |
| 1415 | if (!*list) { |
| 1416 | pr_err("problems parsing %s list\n", list_name); |
| 1417 | return -1; |
| 1418 | } |
| 1419 | return 0; |
| 1420 | } |
| 1421 | |
Arnaldo Carvalho de Melo | ec80fde | 2011-05-26 09:53:51 -0300 | [diff] [blame] | 1422 | static bool symbol__read_kptr_restrict(void) |
| 1423 | { |
| 1424 | bool value = false; |
| 1425 | |
| 1426 | if (geteuid() != 0) { |
| 1427 | FILE *fp = fopen("/proc/sys/kernel/kptr_restrict", "r"); |
| 1428 | if (fp != NULL) { |
| 1429 | char line[8]; |
| 1430 | |
| 1431 | if (fgets(line, sizeof(line), fp) != NULL) |
| 1432 | value = atoi(line) != 0; |
| 1433 | |
| 1434 | fclose(fp); |
| 1435 | } |
| 1436 | } |
| 1437 | |
| 1438 | return value; |
| 1439 | } |
| 1440 | |
Arnaldo Carvalho de Melo | 75be6cf | 2009-12-15 20:04:39 -0200 | [diff] [blame] | 1441 | int symbol__init(void) |
Arnaldo Carvalho de Melo | cc612d8 | 2009-11-23 16:39:10 -0200 | [diff] [blame] | 1442 | { |
David Ahern | ec5761e | 2010-12-09 13:27:07 -0700 | [diff] [blame] | 1443 | const char *symfs; |
| 1444 | |
Jovi Zhang | 85e00b5 | 2010-09-09 13:30:59 -0300 | [diff] [blame] | 1445 | if (symbol_conf.initialized) |
| 1446 | return 0; |
| 1447 | |
Irina Tirdea | 9ac3e48 | 2012-09-11 01:15:01 +0300 | [diff] [blame] | 1448 | symbol_conf.priv_size = PERF_ALIGN(symbol_conf.priv_size, sizeof(u64)); |
David S. Miller | 4d43951 | 2011-03-29 14:18:39 -0300 | [diff] [blame] | 1449 | |
Namhyung Kim | 166ccc9 | 2012-08-06 13:41:19 +0900 | [diff] [blame] | 1450 | symbol__elf_init(); |
| 1451 | |
Arnaldo Carvalho de Melo | 75be6cf | 2009-12-15 20:04:39 -0200 | [diff] [blame] | 1452 | if (symbol_conf.sort_by_name) |
| 1453 | symbol_conf.priv_size += (sizeof(struct symbol_name_rb_node) - |
| 1454 | sizeof(struct symbol)); |
Arnaldo Carvalho de Melo | b32d133 | 2009-11-24 12:05:15 -0200 | [diff] [blame] | 1455 | |
Arnaldo Carvalho de Melo | 75be6cf | 2009-12-15 20:04:39 -0200 | [diff] [blame] | 1456 | if (symbol_conf.try_vmlinux_path && vmlinux_path__init() < 0) |
Arnaldo Carvalho de Melo | cc612d8 | 2009-11-23 16:39:10 -0200 | [diff] [blame] | 1457 | return -1; |
| 1458 | |
Arnaldo Carvalho de Melo | c410a33 | 2009-12-15 20:04:41 -0200 | [diff] [blame] | 1459 | if (symbol_conf.field_sep && *symbol_conf.field_sep == '.') { |
| 1460 | pr_err("'.' is the only non valid --field-separator argument\n"); |
| 1461 | return -1; |
| 1462 | } |
| 1463 | |
Arnaldo Carvalho de Melo | 655000e | 2009-12-15 20:04:40 -0200 | [diff] [blame] | 1464 | if (setup_list(&symbol_conf.dso_list, |
| 1465 | symbol_conf.dso_list_str, "dso") < 0) |
| 1466 | return -1; |
| 1467 | |
| 1468 | if (setup_list(&symbol_conf.comm_list, |
| 1469 | symbol_conf.comm_list_str, "comm") < 0) |
| 1470 | goto out_free_dso_list; |
| 1471 | |
| 1472 | if (setup_list(&symbol_conf.sym_list, |
| 1473 | symbol_conf.sym_list_str, "symbol") < 0) |
| 1474 | goto out_free_comm_list; |
| 1475 | |
David Ahern | ec5761e | 2010-12-09 13:27:07 -0700 | [diff] [blame] | 1476 | /* |
| 1477 | * A path to symbols of "/" is identical to "" |
| 1478 | * reset here for simplicity. |
| 1479 | */ |
| 1480 | symfs = realpath(symbol_conf.symfs, NULL); |
| 1481 | if (symfs == NULL) |
| 1482 | symfs = symbol_conf.symfs; |
| 1483 | if (strcmp(symfs, "/") == 0) |
| 1484 | symbol_conf.symfs = ""; |
| 1485 | if (symfs != symbol_conf.symfs) |
| 1486 | free((void *)symfs); |
| 1487 | |
Arnaldo Carvalho de Melo | ec80fde | 2011-05-26 09:53:51 -0300 | [diff] [blame] | 1488 | symbol_conf.kptr_restrict = symbol__read_kptr_restrict(); |
| 1489 | |
Jovi Zhang | 85e00b5 | 2010-09-09 13:30:59 -0300 | [diff] [blame] | 1490 | symbol_conf.initialized = true; |
Arnaldo Carvalho de Melo | 4aa6563 | 2009-12-13 19:50:29 -0200 | [diff] [blame] | 1491 | return 0; |
Arnaldo Carvalho de Melo | 655000e | 2009-12-15 20:04:40 -0200 | [diff] [blame] | 1492 | |
Arnaldo Carvalho de Melo | 655000e | 2009-12-15 20:04:40 -0200 | [diff] [blame] | 1493 | out_free_comm_list: |
| 1494 | strlist__delete(symbol_conf.comm_list); |
Namhyung Kim | d74c896 | 2011-12-13 00:16:52 +0900 | [diff] [blame] | 1495 | out_free_dso_list: |
| 1496 | strlist__delete(symbol_conf.dso_list); |
Arnaldo Carvalho de Melo | 655000e | 2009-12-15 20:04:40 -0200 | [diff] [blame] | 1497 | return -1; |
Arnaldo Carvalho de Melo | 4aa6563 | 2009-12-13 19:50:29 -0200 | [diff] [blame] | 1498 | } |
Arnaldo Carvalho de Melo | cc612d8 | 2009-11-23 16:39:10 -0200 | [diff] [blame] | 1499 | |
Arnaldo Carvalho de Melo | d65a458 | 2010-07-30 18:31:28 -0300 | [diff] [blame] | 1500 | void symbol__exit(void) |
| 1501 | { |
Jovi Zhang | 85e00b5 | 2010-09-09 13:30:59 -0300 | [diff] [blame] | 1502 | if (!symbol_conf.initialized) |
| 1503 | return; |
Arnaldo Carvalho de Melo | d65a458 | 2010-07-30 18:31:28 -0300 | [diff] [blame] | 1504 | strlist__delete(symbol_conf.sym_list); |
| 1505 | strlist__delete(symbol_conf.dso_list); |
| 1506 | strlist__delete(symbol_conf.comm_list); |
| 1507 | vmlinux_path__exit(); |
| 1508 | symbol_conf.sym_list = symbol_conf.dso_list = symbol_conf.comm_list = NULL; |
Jovi Zhang | 85e00b5 | 2010-09-09 13:30:59 -0300 | [diff] [blame] | 1509 | symbol_conf.initialized = false; |
Arnaldo Carvalho de Melo | d65a458 | 2010-07-30 18:31:28 -0300 | [diff] [blame] | 1510 | } |