blob: 501e4e722e8e853258e3e06b8448cc5792005971 [file] [log] [blame]
John Kacur8b40f522009-09-24 18:02:18 +02001#ifndef __PERF_SYMBOL
2#define __PERF_SYMBOL 1
Arnaldo Carvalho de Meloa2928c42009-05-28 14:55:04 -03003
4#include <linux/types.h>
Arnaldo Carvalho de Meloe4204992009-10-20 14:25:40 -02005#include <stdbool.h>
Arnaldo Carvalho de Melo5aab6212010-03-25 19:59:00 -03006#include <stdint.h>
7#include "map.h"
Roberto Agostino Vitillob5387522012-02-09 23:21:01 +01008#include "../perf.h"
Arnaldo Carvalho de Melo5da50252009-07-01 14:46:08 -03009#include <linux/list.h>
Arnaldo Carvalho de Melo43cbcd82009-07-01 12:28:37 -030010#include <linux/rbtree.h>
Arnaldo Carvalho de Melo5aab6212010-03-25 19:59:00 -030011#include <stdio.h>
Jiri Olsa8db48412012-05-30 14:23:42 +020012#include <byteswap.h>
Irina Tirdeab771a832012-09-08 03:43:17 +030013#include <libgen.h>
Jiri Olsa4383db82012-10-27 23:18:29 +020014#include "build-id.h"
Arnaldo Carvalho de Meloa2928c42009-05-28 14:55:04 -030015
Ingo Molnar89fe8082013-09-30 12:07:11 +020016#ifdef HAVE_LIBELF_SUPPORT
Cody P Schaferb68e2f92012-08-10 15:22:57 -070017#include <libelf.h>
18#include <gelf.h>
Cody P Schaferb68e2f92012-08-10 15:22:57 -070019#endif
Namhyung Kimeec185a2012-12-28 16:16:49 +090020#include <elf.h>
Cody P Schaferb68e2f92012-08-10 15:22:57 -070021
Jiri Olsacdd059d2012-10-27 23:18:32 +020022#include "dso.h"
23
Ingo Molnar89fe8082013-09-30 12:07:11 +020024#ifdef HAVE_CPLUS_DEMANGLE_SUPPORT
Arnaldo Carvalho de Melo247648e2009-08-11 16:22:11 -030025extern char *cplus_demangle(const char *, int);
26
Irina Tirdea1d037ca2012-09-11 01:15:03 +030027static inline char *bfd_demangle(void __maybe_unused *v, const char *c, int i)
Arnaldo Carvalho de Melo247648e2009-08-11 16:22:11 -030028{
29 return cplus_demangle(c, i);
30}
31#else
32#ifdef NO_DEMANGLE
Irina Tirdea1d037ca2012-09-11 01:15:03 +030033static inline char *bfd_demangle(void __maybe_unused *v,
34 const char __maybe_unused *c,
35 int __maybe_unused i)
Arnaldo Carvalho de Melo247648e2009-08-11 16:22:11 -030036{
37 return NULL;
38}
39#else
Markus Trippelsdorf3ce711a2012-09-19 09:29:02 +020040#define PACKAGE 'perf'
Arnaldo Carvalho de Melo247648e2009-08-11 16:22:11 -030041#include <bfd.h>
42#endif
43#endif
44
Marti Raudsepp84087122009-10-24 19:10:36 +030045/*
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 */
Ingo Molnar89fe8082013-09-30 12:07:11 +020049#ifdef HAVE_LIBELF_MMAP_SUPPORT
Marti Raudsepp84087122009-10-24 19:10:36 +030050# define PERF_ELF_C_READ_MMAP ELF_C_READ_MMAP
Namhyung Kim29a0fc92012-09-28 18:31:59 +090051#else
52# define PERF_ELF_C_READ_MMAP ELF_C_READ
Marti Raudsepp84087122009-10-24 19:10:36 +030053#endif
54
Masami Hiramatsu99ca4232014-01-16 09:39:49 +000055#ifdef HAVE_LIBELF_SUPPORT
56extern Elf_Scn *elf_section_by_name(Elf *elf, GElf_Ehdr *ep,
57 GElf_Shdr *shp, const char *name, size_t *idx);
58#endif
59
Arnaldo Carvalho de Melo247648e2009-08-11 16:22:11 -030060#ifndef DMGL_PARAMS
61#define DMGL_PARAMS (1 << 0) /* Include function args */
62#define DMGL_ANSI (1 << 1) /* Include const, volatile, etc */
63#endif
64
Arnaldo Carvalho de Melo171b3be2011-03-11 13:36:01 -030065/** struct symbol - symtab entry
66 *
67 * @ignore - resolvable but tools ignore it (e.g. idle routines)
68 */
Arnaldo Carvalho de Meloa2928c42009-05-28 14:55:04 -030069struct symbol {
70 struct rb_node rb_node;
Paul Mackerras9cffa8d2009-06-19 22:21:42 +100071 u64 start;
72 u64 end;
Arnaldo Carvalho de Melofefb0b92010-05-10 13:57:51 -030073 u16 namelen;
Arnaldo Carvalho de Meloc408fed2010-08-05 12:59:47 -030074 u8 binding;
Arnaldo Carvalho de Melo171b3be2011-03-11 13:36:01 -030075 bool ignore;
Arnaldo Carvalho de Meloa2928c42009-05-28 14:55:04 -030076 char name[0];
77};
78
Arnaldo Carvalho de Meloaeafcba2011-03-31 10:56:28 -030079void symbol__delete(struct symbol *sym);
Jiri Olsacdd059d2012-10-27 23:18:32 +020080void symbols__delete(struct rb_root *symbols);
Arnaldo Carvalho de Melo628ada02010-02-25 12:57:40 -030081
Masami Hiramatsueb948e52014-02-06 05:32:25 +000082/* symbols__for_each_entry - iterate over symbols (rb_root)
83 *
84 * @symbols: the rb_root of symbols
85 * @pos: the 'struct symbol *' to use as a loop cursor
86 * @nd: the 'struct rb_node *' to use as a temporary storage
87 */
88#define symbols__for_each_entry(symbols, pos, nd) \
89 for (nd = rb_first(symbols); \
90 nd && (pos = rb_entry(nd, struct symbol, rb_node)); \
91 nd = rb_next(nd))
92
Arnaldo Carvalho de Melo1b2e2df2012-04-19 10:57:06 -030093static inline size_t symbol__size(const struct symbol *sym)
94{
95 return sym->end - sym->start + 1;
96}
97
Arnaldo Carvalho de Melo655000e2009-12-15 20:04:40 -020098struct strlist;
99
Arnaldo Carvalho de Melob32d1332009-11-24 12:05:15 -0200100struct symbol_conf {
101 unsigned short priv_size;
Arnaldo Carvalho de Melod04b35f2011-11-11 22:17:32 -0200102 unsigned short nr_events;
Arnaldo Carvalho de Melob32d1332009-11-24 12:05:15 -0200103 bool try_vmlinux_path,
Willy Tarreaufc2be692013-09-14 10:32:59 +0200104 ignore_vmlinux,
Akihiro Nagai0bc8d202012-01-30 13:43:20 +0900105 show_kernel_path,
Arnaldo Carvalho de Melo79406cd2009-12-11 18:50:22 -0200106 use_modules,
Arnaldo Carvalho de Melod599db32009-12-15 20:04:42 -0200107 sort_by_name,
108 show_nr_samples,
Arnaldo Carvalho de Melo3f2728b2011-10-05 16:10:06 -0300109 show_total_period,
Arnaldo Carvalho de Melod599db32009-12-15 20:04:42 -0200110 use_callchain,
Arnaldo Carvalho de Melof7d87442009-12-27 21:37:04 -0200111 exclude_other,
Jovi Zhang85e00b52010-09-09 13:30:59 -0300112 show_cpu_utilization,
Arnaldo Carvalho de Meloec80fde2011-05-26 09:53:51 -0300113 initialized,
Stephane Eranian3e6a2a72011-05-17 17:32:07 +0200114 kptr_restrict,
115 annotate_asm_raw,
Namhyung Kim6e1f6012013-01-22 18:09:32 +0900116 annotate_src,
Namhyung Kim328ccda2013-03-25 18:18:18 +0900117 event_group,
118 demangle;
Arnaldo Carvalho de Meloc410a332009-12-15 20:04:41 -0200119 const char *vmlinux_name,
David Ahernb226a5a72010-12-07 19:39:46 -0700120 *kallsyms_name,
Chase Douglas9ed7e1b2010-06-14 15:26:30 -0400121 *source_prefix,
Arnaldo Carvalho de Meloc410a332009-12-15 20:04:41 -0200122 *field_sep;
Zhang, Yanmina1645ce2010-04-19 13:32:50 +0800123 const char *default_guest_vmlinux_name,
124 *default_guest_kallsyms,
125 *default_guest_modules;
126 const char *guestmount;
Arnaldo Carvalho de Meloedb7c602010-05-17 16:22:41 -0300127 const char *dso_list_str,
Arnaldo Carvalho de Melo655000e2009-12-15 20:04:40 -0200128 *comm_list_str,
129 *sym_list_str,
130 *col_width_list_str;
131 struct strlist *dso_list,
132 *comm_list,
Stephane Eraniana68c2c52012-03-08 23:47:48 +0100133 *sym_list,
134 *dso_from_list,
135 *dso_to_list,
136 *sym_from_list,
137 *sym_to_list;
David Ahernec5761e2010-12-09 13:27:07 -0700138 const char *symfs;
Arnaldo Carvalho de Melob32d1332009-11-24 12:05:15 -0200139};
140
Arnaldo Carvalho de Melo75be6cf2009-12-15 20:04:39 -0200141extern struct symbol_conf symbol_conf;
Arnaldo Carvalho de Melo3f067dc2012-12-07 17:39:39 -0300142extern int vmlinux_path__nr_entries;
143extern char **vmlinux_path;
Arnaldo Carvalho de Melo00a192b2009-10-30 16:28:24 -0200144
Arnaldo Carvalho de Meloaeafcba2011-03-31 10:56:28 -0300145static inline void *symbol__priv(struct symbol *sym)
Arnaldo Carvalho de Melo00a192b2009-10-30 16:28:24 -0200146{
Arnaldo Carvalho de Meloaeafcba2011-03-31 10:56:28 -0300147 return ((void *)sym) - symbol_conf.priv_size;
Arnaldo Carvalho de Melo00a192b2009-10-30 16:28:24 -0200148}
149
Arnaldo Carvalho de Melo9de89fe2010-02-03 16:52:00 -0200150struct ref_reloc_sym {
151 const char *name;
152 u64 addr;
153 u64 unrelocated_addr;
154};
155
Arnaldo Carvalho de Melo59fd5302010-03-24 16:40:17 -0300156struct map_symbol {
157 struct map *map;
158 struct symbol *sym;
Arnaldo Carvalho de Melo0f0cbf72010-07-26 17:13:40 -0300159 bool unfolded;
160 bool has_children;
Arnaldo Carvalho de Melo59fd5302010-03-24 16:40:17 -0300161};
162
Roberto Agostino Vitillob5387522012-02-09 23:21:01 +0100163struct addr_map_symbol {
164 struct map *map;
165 struct symbol *sym;
166 u64 addr;
Stephane Eraniana68c2c52012-03-08 23:47:48 +0100167 u64 al_addr;
Roberto Agostino Vitillob5387522012-02-09 23:21:01 +0100168};
169
170struct branch_info {
171 struct addr_map_symbol from;
172 struct addr_map_symbol to;
173 struct branch_flags flags;
174};
175
Stephane Eranian98a3b322013-01-24 16:10:35 +0100176struct mem_info {
177 struct addr_map_symbol iaddr;
178 struct addr_map_symbol daddr;
179 union perf_mem_data_src data_src;
180};
181
Arnaldo Carvalho de Melo1ed091c2009-11-27 16:29:23 -0200182struct addr_location {
Arnaldo Carvalho de Melocc22e572013-12-19 17:20:06 -0300183 struct machine *machine;
Arnaldo Carvalho de Melo1ed091c2009-11-27 16:29:23 -0200184 struct thread *thread;
185 struct map *map;
186 struct symbol *sym;
187 u64 addr;
188 char level;
Namhyung Kimb3cef7f2014-03-17 16:59:21 -0300189 u8 filtered;
Arun Sharmaf60f3592010-06-04 11:27:10 -0300190 u8 cpumode;
191 s32 cpu;
Zhang, Yanmina1645ce2010-04-19 13:32:50 +0800192};
193
Cody P Schaferb68e2f92012-08-10 15:22:57 -0700194struct symsrc {
195 char *name;
196 int fd;
197 enum dso_binary_type type;
198
Ingo Molnar89fe8082013-09-30 12:07:11 +0200199#ifdef HAVE_LIBELF_SUPPORT
Cody P Schaferb68e2f92012-08-10 15:22:57 -0700200 Elf *elf;
201 GElf_Ehdr ehdr;
202
203 Elf_Scn *opdsec;
204 size_t opdidx;
205 GElf_Shdr opdshdr;
206
207 Elf_Scn *symtab;
208 GElf_Shdr symshdr;
209
210 Elf_Scn *dynsym;
211 size_t dynsym_idx;
212 GElf_Shdr dynshdr;
213
214 bool adjust_symbols;
215#endif
216};
217
218void symsrc__destroy(struct symsrc *ss);
219int symsrc__init(struct symsrc *ss, struct dso *dso, const char *name,
220 enum dso_binary_type type);
Cody P Schaferd26cd122012-08-10 15:23:00 -0700221bool symsrc__has_symtab(struct symsrc *ss);
Cody P Schafer3aafe5a2012-08-10 15:23:02 -0700222bool symsrc__possibly_runtime(struct symsrc *ss);
Cody P Schaferb68e2f92012-08-10 15:22:57 -0700223
Arnaldo Carvalho de Meloaeafcba2011-03-31 10:56:28 -0300224int dso__load(struct dso *dso, struct map *map, symbol_filter_t filter);
225int dso__load_vmlinux(struct dso *dso, struct map *map,
Arnaldo Carvalho de Melo5230fb72013-12-10 11:58:52 -0300226 const char *vmlinux, bool vmlinux_allocated,
227 symbol_filter_t filter);
Arnaldo Carvalho de Meloaeafcba2011-03-31 10:56:28 -0300228int dso__load_vmlinux_path(struct dso *dso, struct map *map,
Arnaldo Carvalho de Melo9de89fe2010-02-03 16:52:00 -0200229 symbol_filter_t filter);
Arnaldo Carvalho de Meloaeafcba2011-03-31 10:56:28 -0300230int dso__load_kallsyms(struct dso *dso, const char *filename, struct map *map,
Arnaldo Carvalho de Melo9de89fe2010-02-03 16:52:00 -0200231 symbol_filter_t filter);
Arnaldo Carvalho de Melob0a9ab62010-03-15 11:46:58 -0300232
Arnaldo Carvalho de Meloaeafcba2011-03-31 10:56:28 -0300233struct symbol *dso__find_symbol(struct dso *dso, enum map_type type,
234 u64 addr);
235struct symbol *dso__find_symbol_by_name(struct dso *dso, enum map_type type,
Arnaldo Carvalho de Melo79406cd2009-12-11 18:50:22 -0200236 const char *name);
Arnaldo Carvalho de Meloa2928c42009-05-28 14:55:04 -0300237
Arnaldo Carvalho de Melo2643ce12009-11-03 21:46:10 -0200238int filename__read_build_id(const char *filename, void *bf, size_t size);
Arnaldo Carvalho de Melof1617b42009-11-18 20:20:52 -0200239int sysfs__read_build_id(const char *filename, void *bf, size_t size);
Adrian Hunter316d70d2013-10-08 11:45:48 +0300240int modules__parse(const char *filename, void *arg,
241 int (*process_module)(void *arg, const char *name,
242 u64 start));
Namhyung Kime5a18452012-08-06 13:41:20 +0900243int filename__read_debuglink(const char *filename, char *debuglink,
244 size_t size);
Arnaldo Carvalho de Melo2643ce12009-11-03 21:46:10 -0200245
Arnaldo Carvalho de Melo75be6cf2009-12-15 20:04:39 -0200246int symbol__init(void);
Arnaldo Carvalho de Melod65a4582010-07-30 18:31:28 -0300247void symbol__exit(void);
Namhyung Kim166ccc92012-08-06 13:41:19 +0900248void symbol__elf_init(void);
Namhyung Kime5a18452012-08-06 13:41:20 +0900249struct symbol *symbol__new(u64 start, u64 len, u8 binding, const char *name);
Akihiro Nagaia978f2a2012-01-30 13:43:15 +0900250size_t symbol__fprintf_symname_offs(const struct symbol *sym,
251 const struct addr_location *al, FILE *fp);
Akihiro Nagai547a92e2012-01-30 13:42:57 +0900252size_t symbol__fprintf_symname(const struct symbol *sym, FILE *fp);
Jiri Olsacdd059d2012-10-27 23:18:32 +0200253size_t symbol__fprintf(struct symbol *sym, FILE *fp);
Arnaldo Carvalho de Melo36a3e642010-01-04 16:19:27 -0200254bool symbol_type__is_a(char symbol_type, enum map_type map_type);
Arnaldo Carvalho de Melo3f067dc2012-12-07 17:39:39 -0300255bool symbol__restricted_filename(const char *filename,
256 const char *restricted_filename);
David Ahern82d1deb2013-11-18 13:32:45 -0700257bool symbol__is_idle(struct symbol *sym);
Arnaldo Carvalho de Melo36a3e642010-01-04 16:19:27 -0200258
Cody P Schafer261360b2012-08-10 15:23:01 -0700259int dso__load_sym(struct dso *dso, struct map *map, struct symsrc *syms_ss,
260 struct symsrc *runtime_ss, symbol_filter_t filter,
261 int kmodule);
Cody P Schafera44f6052012-08-10 15:22:59 -0700262int dso__synthesize_plt_symbols(struct dso *dso, struct symsrc *ss,
263 struct map *map, symbol_filter_t filter);
Namhyung Kime5a18452012-08-06 13:41:20 +0900264
265void symbols__insert(struct rb_root *symbols, struct symbol *sym);
266void symbols__fixup_duplicate(struct rb_root *symbols);
267void symbols__fixup_end(struct rb_root *symbols);
268void __map_groups__fixup_end(struct map_groups *mg, enum map_type type);
269
Adrian Hunter8e0cf962013-08-07 14:38:51 +0300270typedef int (*mapfn_t)(u64 start, u64 len, u64 pgoff, void *data);
271int file__read_maps(int fd, bool exe, mapfn_t mapfn, void *data,
272 bool *is_64_bit);
273
Adrian Hunterafba19d2013-10-09 15:01:12 +0300274#define PERF_KCORE_EXTRACT "/tmp/perf-kcore-XXXXXX"
275
276struct kcore_extract {
277 char *kcore_filename;
278 u64 addr;
279 u64 offs;
280 u64 len;
281 char extract_filename[sizeof(PERF_KCORE_EXTRACT)];
282 int fd;
283};
284
285int kcore_extract__create(struct kcore_extract *kce);
286void kcore_extract__delete(struct kcore_extract *kce);
287
Adrian Hunterfc1b6912013-10-14 16:57:29 +0300288int kcore_copy(const char *from_dir, const char *to_dir);
289int compare_proc_modules(const char *from, const char *to);
290
David Ahern3bfe5f82013-11-18 13:32:48 -0700291int setup_list(struct strlist **list, const char *list_str,
292 const char *list_name);
293
John Kacur8b40f522009-09-24 18:02:18 +0200294#endif /* __PERF_SYMBOL */