John Kacur | 8b40f52 | 2009-09-24 18:02:18 +0200 | [diff] [blame] | 1 | #ifndef __PERF_SYMBOL |
| 2 | #define __PERF_SYMBOL 1 |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 3 | |
| 4 | #include <linux/types.h> |
Arnaldo Carvalho de Melo | e420499 | 2009-10-20 14:25:40 -0200 | [diff] [blame] | 5 | #include <stdbool.h> |
Arnaldo Carvalho de Melo | 5aab621 | 2010-03-25 19:59:00 -0300 | [diff] [blame] | 6 | #include <stdint.h> |
| 7 | #include "map.h" |
Roberto Agostino Vitillo | b538752 | 2012-02-09 23:21:01 +0100 | [diff] [blame] | 8 | #include "../perf.h" |
Arnaldo Carvalho de Melo | 5da5025 | 2009-07-01 14:46:08 -0300 | [diff] [blame] | 9 | #include <linux/list.h> |
Arnaldo Carvalho de Melo | 43cbcd8 | 2009-07-01 12:28:37 -0300 | [diff] [blame] | 10 | #include <linux/rbtree.h> |
Arnaldo Carvalho de Melo | 5aab621 | 2010-03-25 19:59:00 -0300 | [diff] [blame] | 11 | #include <stdio.h> |
Jiri Olsa | 8db4841 | 2012-05-30 14:23:42 +0200 | [diff] [blame] | 12 | #include <byteswap.h> |
Irina Tirdea | b771a83 | 2012-09-08 03:43:17 +0300 | [diff] [blame] | 13 | #include <libgen.h> |
Jiri Olsa | 4383db8 | 2012-10-27 23:18:29 +0200 | [diff] [blame] | 14 | #include "build-id.h" |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 15 | |
Namhyung Kim | 29a0fc9 | 2012-09-28 18:31:59 +0900 | [diff] [blame] | 16 | #ifdef LIBELF_SUPPORT |
Cody P Schafer | b68e2f9 | 2012-08-10 15:22:57 -0700 | [diff] [blame] | 17 | #include <libelf.h> |
| 18 | #include <gelf.h> |
Cody P Schafer | b68e2f9 | 2012-08-10 15:22:57 -0700 | [diff] [blame] | 19 | #endif |
Namhyung Kim | eec185a | 2012-12-28 16:16:49 +0900 | [diff] [blame] | 20 | #include <elf.h> |
Cody P Schafer | b68e2f9 | 2012-08-10 15:22:57 -0700 | [diff] [blame] | 21 | |
Jiri Olsa | cdd059d | 2012-10-27 23:18:32 +0200 | [diff] [blame] | 22 | #include "dso.h" |
| 23 | |
Arnaldo Carvalho de Melo | 247648e | 2009-08-11 16:22:11 -0300 | [diff] [blame] | 24 | #ifdef HAVE_CPLUS_DEMANGLE |
| 25 | extern char *cplus_demangle(const char *, int); |
| 26 | |
Irina Tirdea | 1d037ca | 2012-09-11 01:15:03 +0300 | [diff] [blame] | 27 | static inline char *bfd_demangle(void __maybe_unused *v, const char *c, int i) |
Arnaldo Carvalho de Melo | 247648e | 2009-08-11 16:22:11 -0300 | [diff] [blame] | 28 | { |
| 29 | return cplus_demangle(c, i); |
| 30 | } |
| 31 | #else |
| 32 | #ifdef NO_DEMANGLE |
Irina Tirdea | 1d037ca | 2012-09-11 01:15:03 +0300 | [diff] [blame] | 33 | static inline char *bfd_demangle(void __maybe_unused *v, |
| 34 | const char __maybe_unused *c, |
| 35 | int __maybe_unused i) |
Arnaldo Carvalho de Melo | 247648e | 2009-08-11 16:22:11 -0300 | [diff] [blame] | 36 | { |
| 37 | return NULL; |
| 38 | } |
| 39 | #else |
Markus Trippelsdorf | 3ce711a | 2012-09-19 09:29:02 +0200 | [diff] [blame] | 40 | #define PACKAGE 'perf' |
Arnaldo Carvalho de Melo | 247648e | 2009-08-11 16:22:11 -0300 | [diff] [blame] | 41 | #include <bfd.h> |
| 42 | #endif |
| 43 | #endif |
| 44 | |
Marti Raudsepp | 8408712 | 2009-10-24 19:10:36 +0300 | [diff] [blame] | 45 | /* |
| 46 | * libelf 0.8.x and earlier do not support ELF_C_READ_MMAP; |
| 47 | * for newer versions we can use mmap to reduce memory usage: |
| 48 | */ |
Namhyung Kim | 29a0fc9 | 2012-09-28 18:31:59 +0900 | [diff] [blame] | 49 | #ifdef LIBELF_MMAP |
Marti Raudsepp | 8408712 | 2009-10-24 19:10:36 +0300 | [diff] [blame] | 50 | # define PERF_ELF_C_READ_MMAP ELF_C_READ_MMAP |
Namhyung Kim | 29a0fc9 | 2012-09-28 18:31:59 +0900 | [diff] [blame] | 51 | #else |
| 52 | # define PERF_ELF_C_READ_MMAP ELF_C_READ |
Marti Raudsepp | 8408712 | 2009-10-24 19:10:36 +0300 | [diff] [blame] | 53 | #endif |
| 54 | |
Arnaldo Carvalho de Melo | 247648e | 2009-08-11 16:22:11 -0300 | [diff] [blame] | 55 | #ifndef DMGL_PARAMS |
| 56 | #define DMGL_PARAMS (1 << 0) /* Include function args */ |
| 57 | #define DMGL_ANSI (1 << 1) /* Include const, volatile, etc */ |
| 58 | #endif |
| 59 | |
Arnaldo Carvalho de Melo | 171b3be | 2011-03-11 13:36:01 -0300 | [diff] [blame] | 60 | /** struct symbol - symtab entry |
| 61 | * |
| 62 | * @ignore - resolvable but tools ignore it (e.g. idle routines) |
| 63 | */ |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 64 | struct symbol { |
| 65 | struct rb_node rb_node; |
Paul Mackerras | 9cffa8d | 2009-06-19 22:21:42 +1000 | [diff] [blame] | 66 | u64 start; |
| 67 | u64 end; |
Arnaldo Carvalho de Melo | fefb0b9 | 2010-05-10 13:57:51 -0300 | [diff] [blame] | 68 | u16 namelen; |
Arnaldo Carvalho de Melo | c408fed | 2010-08-05 12:59:47 -0300 | [diff] [blame] | 69 | u8 binding; |
Arnaldo Carvalho de Melo | 171b3be | 2011-03-11 13:36:01 -0300 | [diff] [blame] | 70 | bool ignore; |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 71 | char name[0]; |
| 72 | }; |
| 73 | |
Arnaldo Carvalho de Melo | aeafcba | 2011-03-31 10:56:28 -0300 | [diff] [blame] | 74 | void symbol__delete(struct symbol *sym); |
Jiri Olsa | cdd059d | 2012-10-27 23:18:32 +0200 | [diff] [blame] | 75 | void symbols__delete(struct rb_root *symbols); |
Arnaldo Carvalho de Melo | 628ada0 | 2010-02-25 12:57:40 -0300 | [diff] [blame] | 76 | |
Arnaldo Carvalho de Melo | 1b2e2df | 2012-04-19 10:57:06 -0300 | [diff] [blame] | 77 | static inline size_t symbol__size(const struct symbol *sym) |
| 78 | { |
| 79 | return sym->end - sym->start + 1; |
| 80 | } |
| 81 | |
Arnaldo Carvalho de Melo | 655000e | 2009-12-15 20:04:40 -0200 | [diff] [blame] | 82 | struct strlist; |
| 83 | |
Arnaldo Carvalho de Melo | b32d133 | 2009-11-24 12:05:15 -0200 | [diff] [blame] | 84 | struct symbol_conf { |
| 85 | unsigned short priv_size; |
Arnaldo Carvalho de Melo | d04b35f | 2011-11-11 22:17:32 -0200 | [diff] [blame] | 86 | unsigned short nr_events; |
Arnaldo Carvalho de Melo | b32d133 | 2009-11-24 12:05:15 -0200 | [diff] [blame] | 87 | bool try_vmlinux_path, |
Akihiro Nagai | 0bc8d20 | 2012-01-30 13:43:20 +0900 | [diff] [blame] | 88 | show_kernel_path, |
Arnaldo Carvalho de Melo | 79406cd | 2009-12-11 18:50:22 -0200 | [diff] [blame] | 89 | use_modules, |
Arnaldo Carvalho de Melo | d599db3 | 2009-12-15 20:04:42 -0200 | [diff] [blame] | 90 | sort_by_name, |
| 91 | show_nr_samples, |
Arnaldo Carvalho de Melo | 3f2728b | 2011-10-05 16:10:06 -0300 | [diff] [blame] | 92 | show_total_period, |
Arnaldo Carvalho de Melo | d599db3 | 2009-12-15 20:04:42 -0200 | [diff] [blame] | 93 | use_callchain, |
Arnaldo Carvalho de Melo | f7d8744 | 2009-12-27 21:37:04 -0200 | [diff] [blame] | 94 | exclude_other, |
Jovi Zhang | 85e00b5 | 2010-09-09 13:30:59 -0300 | [diff] [blame] | 95 | show_cpu_utilization, |
Arnaldo Carvalho de Melo | ec80fde | 2011-05-26 09:53:51 -0300 | [diff] [blame] | 96 | initialized, |
Stephane Eranian | 3e6a2a7 | 2011-05-17 17:32:07 +0200 | [diff] [blame] | 97 | kptr_restrict, |
| 98 | annotate_asm_raw, |
Namhyung Kim | 6e1f601 | 2013-01-22 18:09:32 +0900 | [diff] [blame] | 99 | annotate_src, |
Namhyung Kim | 328ccda | 2013-03-25 18:18:18 +0900 | [diff] [blame] | 100 | event_group, |
| 101 | demangle; |
Arnaldo Carvalho de Melo | c410a33 | 2009-12-15 20:04:41 -0200 | [diff] [blame] | 102 | const char *vmlinux_name, |
David Ahern | b226a5a7 | 2010-12-07 19:39:46 -0700 | [diff] [blame] | 103 | *kallsyms_name, |
Chase Douglas | 9ed7e1b | 2010-06-14 15:26:30 -0400 | [diff] [blame] | 104 | *source_prefix, |
Arnaldo Carvalho de Melo | c410a33 | 2009-12-15 20:04:41 -0200 | [diff] [blame] | 105 | *field_sep; |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 106 | const char *default_guest_vmlinux_name, |
| 107 | *default_guest_kallsyms, |
| 108 | *default_guest_modules; |
| 109 | const char *guestmount; |
Arnaldo Carvalho de Melo | edb7c60 | 2010-05-17 16:22:41 -0300 | [diff] [blame] | 110 | const char *dso_list_str, |
Arnaldo Carvalho de Melo | 655000e | 2009-12-15 20:04:40 -0200 | [diff] [blame] | 111 | *comm_list_str, |
| 112 | *sym_list_str, |
| 113 | *col_width_list_str; |
| 114 | struct strlist *dso_list, |
| 115 | *comm_list, |
Stephane Eranian | a68c2c5 | 2012-03-08 23:47:48 +0100 | [diff] [blame] | 116 | *sym_list, |
| 117 | *dso_from_list, |
| 118 | *dso_to_list, |
| 119 | *sym_from_list, |
| 120 | *sym_to_list; |
David Ahern | ec5761e | 2010-12-09 13:27:07 -0700 | [diff] [blame] | 121 | const char *symfs; |
Arnaldo Carvalho de Melo | b32d133 | 2009-11-24 12:05:15 -0200 | [diff] [blame] | 122 | }; |
| 123 | |
Arnaldo Carvalho de Melo | 75be6cf | 2009-12-15 20:04:39 -0200 | [diff] [blame] | 124 | extern struct symbol_conf symbol_conf; |
Arnaldo Carvalho de Melo | 3f067dc | 2012-12-07 17:39:39 -0300 | [diff] [blame] | 125 | extern int vmlinux_path__nr_entries; |
| 126 | extern char **vmlinux_path; |
Arnaldo Carvalho de Melo | 00a192b | 2009-10-30 16:28:24 -0200 | [diff] [blame] | 127 | |
Arnaldo Carvalho de Melo | aeafcba | 2011-03-31 10:56:28 -0300 | [diff] [blame] | 128 | static inline void *symbol__priv(struct symbol *sym) |
Arnaldo Carvalho de Melo | 00a192b | 2009-10-30 16:28:24 -0200 | [diff] [blame] | 129 | { |
Arnaldo Carvalho de Melo | aeafcba | 2011-03-31 10:56:28 -0300 | [diff] [blame] | 130 | return ((void *)sym) - symbol_conf.priv_size; |
Arnaldo Carvalho de Melo | 00a192b | 2009-10-30 16:28:24 -0200 | [diff] [blame] | 131 | } |
| 132 | |
Arnaldo Carvalho de Melo | 9de89fe | 2010-02-03 16:52:00 -0200 | [diff] [blame] | 133 | struct ref_reloc_sym { |
| 134 | const char *name; |
| 135 | u64 addr; |
| 136 | u64 unrelocated_addr; |
| 137 | }; |
| 138 | |
Arnaldo Carvalho de Melo | 59fd530 | 2010-03-24 16:40:17 -0300 | [diff] [blame] | 139 | struct map_symbol { |
| 140 | struct map *map; |
| 141 | struct symbol *sym; |
Arnaldo Carvalho de Melo | 0f0cbf7 | 2010-07-26 17:13:40 -0300 | [diff] [blame] | 142 | bool unfolded; |
| 143 | bool has_children; |
Arnaldo Carvalho de Melo | 59fd530 | 2010-03-24 16:40:17 -0300 | [diff] [blame] | 144 | }; |
| 145 | |
Roberto Agostino Vitillo | b538752 | 2012-02-09 23:21:01 +0100 | [diff] [blame] | 146 | struct addr_map_symbol { |
| 147 | struct map *map; |
| 148 | struct symbol *sym; |
| 149 | u64 addr; |
Stephane Eranian | a68c2c5 | 2012-03-08 23:47:48 +0100 | [diff] [blame] | 150 | u64 al_addr; |
Roberto Agostino Vitillo | b538752 | 2012-02-09 23:21:01 +0100 | [diff] [blame] | 151 | }; |
| 152 | |
| 153 | struct branch_info { |
| 154 | struct addr_map_symbol from; |
| 155 | struct addr_map_symbol to; |
| 156 | struct branch_flags flags; |
| 157 | }; |
| 158 | |
Stephane Eranian | 98a3b32 | 2013-01-24 16:10:35 +0100 | [diff] [blame] | 159 | struct mem_info { |
| 160 | struct addr_map_symbol iaddr; |
| 161 | struct addr_map_symbol daddr; |
| 162 | union perf_mem_data_src data_src; |
| 163 | }; |
| 164 | |
Arnaldo Carvalho de Melo | 1ed091c | 2009-11-27 16:29:23 -0200 | [diff] [blame] | 165 | struct addr_location { |
| 166 | struct thread *thread; |
| 167 | struct map *map; |
| 168 | struct symbol *sym; |
| 169 | u64 addr; |
| 170 | char level; |
Arnaldo Carvalho de Melo | c410a33 | 2009-12-15 20:04:41 -0200 | [diff] [blame] | 171 | bool filtered; |
Arun Sharma | f60f359 | 2010-06-04 11:27:10 -0300 | [diff] [blame] | 172 | u8 cpumode; |
| 173 | s32 cpu; |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 174 | }; |
| 175 | |
Cody P Schafer | b68e2f9 | 2012-08-10 15:22:57 -0700 | [diff] [blame] | 176 | struct symsrc { |
| 177 | char *name; |
| 178 | int fd; |
| 179 | enum dso_binary_type type; |
| 180 | |
Namhyung Kim | 29a0fc9 | 2012-09-28 18:31:59 +0900 | [diff] [blame] | 181 | #ifdef LIBELF_SUPPORT |
Cody P Schafer | b68e2f9 | 2012-08-10 15:22:57 -0700 | [diff] [blame] | 182 | Elf *elf; |
| 183 | GElf_Ehdr ehdr; |
| 184 | |
| 185 | Elf_Scn *opdsec; |
| 186 | size_t opdidx; |
| 187 | GElf_Shdr opdshdr; |
| 188 | |
| 189 | Elf_Scn *symtab; |
| 190 | GElf_Shdr symshdr; |
| 191 | |
| 192 | Elf_Scn *dynsym; |
| 193 | size_t dynsym_idx; |
| 194 | GElf_Shdr dynshdr; |
| 195 | |
| 196 | bool adjust_symbols; |
| 197 | #endif |
| 198 | }; |
| 199 | |
| 200 | void symsrc__destroy(struct symsrc *ss); |
| 201 | int symsrc__init(struct symsrc *ss, struct dso *dso, const char *name, |
| 202 | enum dso_binary_type type); |
Cody P Schafer | d26cd12 | 2012-08-10 15:23:00 -0700 | [diff] [blame] | 203 | bool symsrc__has_symtab(struct symsrc *ss); |
Cody P Schafer | 3aafe5a | 2012-08-10 15:23:02 -0700 | [diff] [blame] | 204 | bool symsrc__possibly_runtime(struct symsrc *ss); |
Cody P Schafer | b68e2f9 | 2012-08-10 15:22:57 -0700 | [diff] [blame] | 205 | |
Arnaldo Carvalho de Melo | aeafcba | 2011-03-31 10:56:28 -0300 | [diff] [blame] | 206 | int dso__load(struct dso *dso, struct map *map, symbol_filter_t filter); |
| 207 | int dso__load_vmlinux(struct dso *dso, struct map *map, |
Franck Bui-Huu | fd930ff | 2010-12-10 14:06:03 +0100 | [diff] [blame] | 208 | const char *vmlinux, symbol_filter_t filter); |
Arnaldo Carvalho de Melo | aeafcba | 2011-03-31 10:56:28 -0300 | [diff] [blame] | 209 | 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] | 210 | symbol_filter_t filter); |
Arnaldo Carvalho de Melo | aeafcba | 2011-03-31 10:56:28 -0300 | [diff] [blame] | 211 | int dso__load_kallsyms(struct dso *dso, const char *filename, struct map *map, |
Arnaldo Carvalho de Melo | 9de89fe | 2010-02-03 16:52:00 -0200 | [diff] [blame] | 212 | symbol_filter_t filter); |
Arnaldo Carvalho de Melo | b0a9ab6 | 2010-03-15 11:46:58 -0300 | [diff] [blame] | 213 | |
Arnaldo Carvalho de Melo | aeafcba | 2011-03-31 10:56:28 -0300 | [diff] [blame] | 214 | struct symbol *dso__find_symbol(struct dso *dso, enum map_type type, |
| 215 | u64 addr); |
| 216 | 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] | 217 | const char *name); |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 218 | |
Arnaldo Carvalho de Melo | 2643ce1 | 2009-11-03 21:46:10 -0200 | [diff] [blame] | 219 | int filename__read_build_id(const char *filename, void *bf, size_t size); |
Arnaldo Carvalho de Melo | f1617b4 | 2009-11-18 20:20:52 -0200 | [diff] [blame] | 220 | int sysfs__read_build_id(const char *filename, void *bf, size_t size); |
Arnaldo Carvalho de Melo | 9e20144 | 2010-01-14 18:30:06 -0200 | [diff] [blame] | 221 | int kallsyms__parse(const char *filename, void *arg, |
| 222 | int (*process_symbol)(void *arg, const char *name, |
Cody P Schafer | 8215152 | 2012-08-10 15:22:48 -0700 | [diff] [blame] | 223 | char type, u64 start)); |
Namhyung Kim | e5a1845 | 2012-08-06 13:41:20 +0900 | [diff] [blame] | 224 | int filename__read_debuglink(const char *filename, char *debuglink, |
| 225 | size_t size); |
Arnaldo Carvalho de Melo | 2643ce1 | 2009-11-03 21:46:10 -0200 | [diff] [blame] | 226 | |
Arnaldo Carvalho de Melo | 75be6cf | 2009-12-15 20:04:39 -0200 | [diff] [blame] | 227 | int symbol__init(void); |
Arnaldo Carvalho de Melo | d65a458 | 2010-07-30 18:31:28 -0300 | [diff] [blame] | 228 | void symbol__exit(void); |
Namhyung Kim | 166ccc9 | 2012-08-06 13:41:19 +0900 | [diff] [blame] | 229 | void symbol__elf_init(void); |
Namhyung Kim | e5a1845 | 2012-08-06 13:41:20 +0900 | [diff] [blame] | 230 | struct symbol *symbol__new(u64 start, u64 len, u8 binding, const char *name); |
Akihiro Nagai | a978f2a | 2012-01-30 13:43:15 +0900 | [diff] [blame] | 231 | size_t symbol__fprintf_symname_offs(const struct symbol *sym, |
| 232 | const struct addr_location *al, FILE *fp); |
Akihiro Nagai | 547a92e | 2012-01-30 13:42:57 +0900 | [diff] [blame] | 233 | size_t symbol__fprintf_symname(const struct symbol *sym, FILE *fp); |
Jiri Olsa | cdd059d | 2012-10-27 23:18:32 +0200 | [diff] [blame] | 234 | size_t symbol__fprintf(struct symbol *sym, FILE *fp); |
Arnaldo Carvalho de Melo | 36a3e64 | 2010-01-04 16:19:27 -0200 | [diff] [blame] | 235 | bool symbol_type__is_a(char symbol_type, enum map_type map_type); |
Arnaldo Carvalho de Melo | 3f067dc | 2012-12-07 17:39:39 -0300 | [diff] [blame] | 236 | bool symbol__restricted_filename(const char *filename, |
| 237 | const char *restricted_filename); |
Arnaldo Carvalho de Melo | 36a3e64 | 2010-01-04 16:19:27 -0200 | [diff] [blame] | 238 | |
Cody P Schafer | 261360b | 2012-08-10 15:23:01 -0700 | [diff] [blame] | 239 | int dso__load_sym(struct dso *dso, struct map *map, struct symsrc *syms_ss, |
| 240 | struct symsrc *runtime_ss, symbol_filter_t filter, |
| 241 | int kmodule); |
Cody P Schafer | a44f605 | 2012-08-10 15:22:59 -0700 | [diff] [blame] | 242 | int dso__synthesize_plt_symbols(struct dso *dso, struct symsrc *ss, |
| 243 | struct map *map, symbol_filter_t filter); |
Namhyung Kim | e5a1845 | 2012-08-06 13:41:20 +0900 | [diff] [blame] | 244 | |
| 245 | void symbols__insert(struct rb_root *symbols, struct symbol *sym); |
| 246 | void symbols__fixup_duplicate(struct rb_root *symbols); |
| 247 | void symbols__fixup_end(struct rb_root *symbols); |
| 248 | void __map_groups__fixup_end(struct map_groups *mg, enum map_type type); |
| 249 | |
John Kacur | 8b40f52 | 2009-09-24 18:02:18 +0200 | [diff] [blame] | 250 | #endif /* __PERF_SYMBOL */ |