blob: 9b9ea00173af5cfc084b8a8fcdfd4c6f7356e73b [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>
Arnaldo Carvalho de Meloa2928c42009-05-28 14:55:04 -030013
Arnaldo Carvalho de Melo247648e2009-08-11 16:22:11 -030014#ifdef HAVE_CPLUS_DEMANGLE
15extern char *cplus_demangle(const char *, int);
16
17static inline char *bfd_demangle(void __used *v, const char *c, int i)
18{
19 return cplus_demangle(c, i);
20}
21#else
22#ifdef NO_DEMANGLE
23static inline char *bfd_demangle(void __used *v, const char __used *c,
24 int __used i)
25{
26 return NULL;
27}
28#else
29#include <bfd.h>
30#endif
31#endif
32
Arnaldo Carvalho de Melo5aab6212010-03-25 19:59:00 -030033int hex2u64(const char *ptr, u64 *val);
34char *strxfrchar(char *s, char from, char to);
35
Marti Raudsepp84087122009-10-24 19:10:36 +030036/*
37 * libelf 0.8.x and earlier do not support ELF_C_READ_MMAP;
38 * for newer versions we can use mmap to reduce memory usage:
39 */
40#ifdef LIBELF_NO_MMAP
41# define PERF_ELF_C_READ_MMAP ELF_C_READ
42#else
43# define PERF_ELF_C_READ_MMAP ELF_C_READ_MMAP
44#endif
45
Arnaldo Carvalho de Melo247648e2009-08-11 16:22:11 -030046#ifndef DMGL_PARAMS
47#define DMGL_PARAMS (1 << 0) /* Include function args */
48#define DMGL_ANSI (1 << 1) /* Include const, volatile, etc */
49#endif
50
Arnaldo Carvalho de Melo5aab6212010-03-25 19:59:00 -030051#define BUILD_ID_SIZE 20
52
Arnaldo Carvalho de Melo171b3be2011-03-11 13:36:01 -030053/** struct symbol - symtab entry
54 *
55 * @ignore - resolvable but tools ignore it (e.g. idle routines)
56 */
Arnaldo Carvalho de Meloa2928c42009-05-28 14:55:04 -030057struct symbol {
58 struct rb_node rb_node;
Paul Mackerras9cffa8d2009-06-19 22:21:42 +100059 u64 start;
60 u64 end;
Arnaldo Carvalho de Melofefb0b92010-05-10 13:57:51 -030061 u16 namelen;
Arnaldo Carvalho de Meloc408fed2010-08-05 12:59:47 -030062 u8 binding;
Arnaldo Carvalho de Melo171b3be2011-03-11 13:36:01 -030063 bool ignore;
Arnaldo Carvalho de Meloa2928c42009-05-28 14:55:04 -030064 char name[0];
65};
66
Arnaldo Carvalho de Meloaeafcba2011-03-31 10:56:28 -030067void symbol__delete(struct symbol *sym);
Arnaldo Carvalho de Melo628ada02010-02-25 12:57:40 -030068
Arnaldo Carvalho de Melo1b2e2df2012-04-19 10:57:06 -030069static inline size_t symbol__size(const struct symbol *sym)
70{
71 return sym->end - sym->start + 1;
72}
73
Arnaldo Carvalho de Melo655000e2009-12-15 20:04:40 -020074struct strlist;
75
Arnaldo Carvalho de Melob32d1332009-11-24 12:05:15 -020076struct symbol_conf {
77 unsigned short priv_size;
Arnaldo Carvalho de Melod04b35f2011-11-11 22:17:32 -020078 unsigned short nr_events;
Arnaldo Carvalho de Melob32d1332009-11-24 12:05:15 -020079 bool try_vmlinux_path,
Akihiro Nagai0bc8d202012-01-30 13:43:20 +090080 show_kernel_path,
Arnaldo Carvalho de Melo79406cd2009-12-11 18:50:22 -020081 use_modules,
Arnaldo Carvalho de Melod599db32009-12-15 20:04:42 -020082 sort_by_name,
83 show_nr_samples,
Arnaldo Carvalho de Melo3f2728b2011-10-05 16:10:06 -030084 show_total_period,
Arnaldo Carvalho de Melod599db32009-12-15 20:04:42 -020085 use_callchain,
Arnaldo Carvalho de Melof7d87442009-12-27 21:37:04 -020086 exclude_other,
Jovi Zhang85e00b52010-09-09 13:30:59 -030087 show_cpu_utilization,
Arnaldo Carvalho de Meloec80fde2011-05-26 09:53:51 -030088 initialized,
Stephane Eranian3e6a2a72011-05-17 17:32:07 +020089 kptr_restrict,
90 annotate_asm_raw,
91 annotate_src;
Arnaldo Carvalho de Meloc410a332009-12-15 20:04:41 -020092 const char *vmlinux_name,
David Ahernb226a5a72010-12-07 19:39:46 -070093 *kallsyms_name,
Chase Douglas9ed7e1b2010-06-14 15:26:30 -040094 *source_prefix,
Arnaldo Carvalho de Meloc410a332009-12-15 20:04:41 -020095 *field_sep;
Zhang, Yanmina1645ce2010-04-19 13:32:50 +080096 const char *default_guest_vmlinux_name,
97 *default_guest_kallsyms,
98 *default_guest_modules;
99 const char *guestmount;
Arnaldo Carvalho de Meloedb7c602010-05-17 16:22:41 -0300100 const char *dso_list_str,
Arnaldo Carvalho de Melo655000e2009-12-15 20:04:40 -0200101 *comm_list_str,
102 *sym_list_str,
103 *col_width_list_str;
104 struct strlist *dso_list,
105 *comm_list,
Stephane Eraniana68c2c52012-03-08 23:47:48 +0100106 *sym_list,
107 *dso_from_list,
108 *dso_to_list,
109 *sym_from_list,
110 *sym_to_list;
David Ahernec5761e2010-12-09 13:27:07 -0700111 const char *symfs;
Arnaldo Carvalho de Melob32d1332009-11-24 12:05:15 -0200112};
113
Arnaldo Carvalho de Melo75be6cf2009-12-15 20:04:39 -0200114extern struct symbol_conf symbol_conf;
Arnaldo Carvalho de Melo00a192b2009-10-30 16:28:24 -0200115
Arnaldo Carvalho de Meloaeafcba2011-03-31 10:56:28 -0300116static inline void *symbol__priv(struct symbol *sym)
Arnaldo Carvalho de Melo00a192b2009-10-30 16:28:24 -0200117{
Arnaldo Carvalho de Meloaeafcba2011-03-31 10:56:28 -0300118 return ((void *)sym) - symbol_conf.priv_size;
Arnaldo Carvalho de Melo00a192b2009-10-30 16:28:24 -0200119}
120
Arnaldo Carvalho de Melo9de89fe2010-02-03 16:52:00 -0200121struct ref_reloc_sym {
122 const char *name;
123 u64 addr;
124 u64 unrelocated_addr;
125};
126
Arnaldo Carvalho de Melo59fd5302010-03-24 16:40:17 -0300127struct map_symbol {
128 struct map *map;
129 struct symbol *sym;
Arnaldo Carvalho de Melo0f0cbf72010-07-26 17:13:40 -0300130 bool unfolded;
131 bool has_children;
Arnaldo Carvalho de Melo59fd5302010-03-24 16:40:17 -0300132};
133
Roberto Agostino Vitillob5387522012-02-09 23:21:01 +0100134struct addr_map_symbol {
135 struct map *map;
136 struct symbol *sym;
137 u64 addr;
Stephane Eraniana68c2c52012-03-08 23:47:48 +0100138 u64 al_addr;
Roberto Agostino Vitillob5387522012-02-09 23:21:01 +0100139};
140
141struct branch_info {
142 struct addr_map_symbol from;
143 struct addr_map_symbol to;
144 struct branch_flags flags;
145};
146
Arnaldo Carvalho de Melo1ed091c2009-11-27 16:29:23 -0200147struct addr_location {
148 struct thread *thread;
149 struct map *map;
150 struct symbol *sym;
151 u64 addr;
152 char level;
Arnaldo Carvalho de Meloc410a332009-12-15 20:04:41 -0200153 bool filtered;
Arun Sharmaf60f3592010-06-04 11:27:10 -0300154 u8 cpumode;
155 s32 cpu;
Zhang, Yanmina1645ce2010-04-19 13:32:50 +0800156};
157
Jiri Olsa44f24cb2012-07-22 14:14:32 +0200158enum dso_binary_type {
159 DSO_BINARY_TYPE__KALLSYMS = 0,
160 DSO_BINARY_TYPE__GUEST_KALLSYMS,
161 DSO_BINARY_TYPE__JAVA_JIT,
162 DSO_BINARY_TYPE__DEBUGLINK,
163 DSO_BINARY_TYPE__BUILD_ID_CACHE,
164 DSO_BINARY_TYPE__FEDORA_DEBUGINFO,
165 DSO_BINARY_TYPE__UBUNTU_DEBUGINFO,
166 DSO_BINARY_TYPE__BUILDID_DEBUGINFO,
167 DSO_BINARY_TYPE__SYSTEM_PATH_DSO,
168 DSO_BINARY_TYPE__GUEST_KMODULE,
169 DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE,
170 DSO_BINARY_TYPE__NOT_FOUND,
171};
172
Zhang, Yanmina1645ce2010-04-19 13:32:50 +0800173enum dso_kernel_type {
174 DSO_TYPE_USER = 0,
175 DSO_TYPE_KERNEL,
176 DSO_TYPE_GUEST_KERNEL
Arnaldo Carvalho de Melo1ed091c2009-11-27 16:29:23 -0200177};
178
Jiri Olsa8db48412012-05-30 14:23:42 +0200179enum dso_swap_type {
180 DSO_SWAP__UNSET,
181 DSO_SWAP__NO,
182 DSO_SWAP__YES,
183};
184
Arnaldo Carvalho de Meloa2928c42009-05-28 14:55:04 -0300185struct dso {
186 struct list_head node;
Arnaldo Carvalho de Melo6a4694a2009-11-27 16:29:17 -0200187 struct rb_root symbols[MAP__NR_TYPES];
Arnaldo Carvalho de Melo79406cd2009-12-11 18:50:22 -0200188 struct rb_root symbol_names[MAP__NR_TYPES];
Arnaldo Carvalho de Melo6e406252010-07-29 15:11:30 -0300189 enum dso_kernel_type kernel;
Jiri Olsa8db48412012-05-30 14:23:42 +0200190 enum dso_swap_type needs_swap;
Jiri Olsa44f24cb2012-07-22 14:14:32 +0200191 enum dso_binary_type symtab_type;
Jiri Olsa949d1602012-07-22 14:14:33 +0200192 enum dso_binary_type data_type;
Arnaldo Carvalho de Melo8d063672009-11-04 18:50:43 -0200193 u8 adjust_symbols:1;
Arnaldo Carvalho de Melo8d063672009-11-04 18:50:43 -0200194 u8 has_build_id:1;
Arnaldo Carvalho de Melo88d3d9b72010-01-14 23:45:30 -0200195 u8 hit:1;
Arnaldo Carvalho de Melod06d92b2010-03-15 13:04:33 -0300196 u8 annotate_warned:1;
Arnaldo Carvalho de Melo6e406252010-07-29 15:11:30 -0300197 u8 sname_alloc:1;
198 u8 lname_alloc:1;
Arnaldo Carvalho de Melo79406cd2009-12-11 18:50:22 -0200199 u8 sorted_by_name;
Arnaldo Carvalho de Melo36105832009-11-27 16:29:16 -0200200 u8 loaded;
Arnaldo Carvalho de Melo8d063672009-11-04 18:50:43 -0200201 u8 build_id[BUILD_ID_SIZE];
Arnaldo Carvalho de Melo439d4732009-10-02 03:29:58 -0300202 const char *short_name;
203 char *long_name;
Arnaldo Carvalho de Melob63be8d2010-03-15 15:03:50 -0300204 u16 long_name_len;
205 u16 short_name_len;
Arnaldo Carvalho de Meloa2928c42009-05-28 14:55:04 -0300206 char name[0];
207};
208
Jiri Olsa8db48412012-05-30 14:23:42 +0200209#define DSO__SWAP(dso, type, val) \
210({ \
211 type ____r = val; \
212 BUG_ON(dso->needs_swap == DSO_SWAP__UNSET); \
213 if (dso->needs_swap == DSO_SWAP__YES) { \
214 switch (sizeof(____r)) { \
215 case 2: \
216 ____r = bswap_16(val); \
217 break; \
218 case 4: \
219 ____r = bswap_32(val); \
220 break; \
221 case 8: \
222 ____r = bswap_64(val); \
223 break; \
224 default: \
225 BUG_ON(1); \
226 } \
227 } \
228 ____r; \
229})
230
Arnaldo Carvalho de Melo00a192b2009-10-30 16:28:24 -0200231struct dso *dso__new(const char *name);
Arnaldo Carvalho de Meloaeafcba2011-03-31 10:56:28 -0300232void dso__delete(struct dso *dso);
Arnaldo Carvalho de Meloa2928c42009-05-28 14:55:04 -0300233
Arnaldo Carvalho de Meloaeafcba2011-03-31 10:56:28 -0300234int dso__name_len(const struct dso *dso);
Arnaldo Carvalho de Melo8a6c5b22010-07-20 14:42:52 -0300235
Arnaldo Carvalho de Meloaeafcba2011-03-31 10:56:28 -0300236bool dso__loaded(const struct dso *dso, enum map_type type);
237bool dso__sorted_by_name(const struct dso *dso, enum map_type type);
Arnaldo Carvalho de Melo79406cd2009-12-11 18:50:22 -0200238
Arnaldo Carvalho de Meloaeafcba2011-03-31 10:56:28 -0300239static inline void dso__set_loaded(struct dso *dso, enum map_type type)
Arnaldo Carvalho de Melo8d92c022010-02-03 16:52:02 -0200240{
Arnaldo Carvalho de Meloaeafcba2011-03-31 10:56:28 -0300241 dso->loaded |= (1 << type);
Arnaldo Carvalho de Melo8d92c022010-02-03 16:52:02 -0200242}
243
Arnaldo Carvalho de Meloaeafcba2011-03-31 10:56:28 -0300244void dso__sort_by_name(struct dso *dso, enum map_type type);
Arnaldo Carvalho de Melo36105832009-11-27 16:29:16 -0200245
Arnaldo Carvalho de Meloa89e5abe2010-01-07 19:59:39 -0200246struct dso *__dsos__findnew(struct list_head *head, const char *name);
247
Arnaldo Carvalho de Meloaeafcba2011-03-31 10:56:28 -0300248int dso__load(struct dso *dso, struct map *map, symbol_filter_t filter);
249int dso__load_vmlinux(struct dso *dso, struct map *map,
Franck Bui-Huufd930ff2010-12-10 14:06:03 +0100250 const char *vmlinux, symbol_filter_t filter);
Arnaldo Carvalho de Meloaeafcba2011-03-31 10:56:28 -0300251int dso__load_vmlinux_path(struct dso *dso, struct map *map,
Arnaldo Carvalho de Melo9de89fe2010-02-03 16:52:00 -0200252 symbol_filter_t filter);
Arnaldo Carvalho de Meloaeafcba2011-03-31 10:56:28 -0300253int dso__load_kallsyms(struct dso *dso, const char *filename, struct map *map,
Arnaldo Carvalho de Melo9de89fe2010-02-03 16:52:00 -0200254 symbol_filter_t filter);
Arnaldo Carvalho de Meloaeafcba2011-03-31 10:56:28 -0300255int machine__load_kallsyms(struct machine *machine, const char *filename,
Arnaldo Carvalho de Melo5c0541d2010-04-29 15:25:23 -0300256 enum map_type type, symbol_filter_t filter);
Arnaldo Carvalho de Meloaeafcba2011-03-31 10:56:28 -0300257int machine__load_vmlinux_path(struct machine *machine, enum map_type type,
Arnaldo Carvalho de Melo5c0541d2010-04-29 15:25:23 -0300258 symbol_filter_t filter);
259
Arnaldo Carvalho de Melo1f626bc2010-05-09 19:57:08 -0300260size_t __dsos__fprintf(struct list_head *head, FILE *fp);
261
Arnaldo Carvalho de Meloaeafcba2011-03-31 10:56:28 -0300262size_t machine__fprintf_dsos_buildid(struct machine *machine,
263 FILE *fp, bool with_hits);
264size_t machines__fprintf_dsos(struct rb_root *machines, FILE *fp);
265size_t machines__fprintf_dsos_buildid(struct rb_root *machines,
266 FILE *fp, bool with_hits);
267size_t dso__fprintf_buildid(struct dso *dso, FILE *fp);
268size_t dso__fprintf_symbols_by_name(struct dso *dso,
269 enum map_type type, FILE *fp);
270size_t dso__fprintf(struct dso *dso, enum map_type type, FILE *fp);
Arnaldo Carvalho de Melob0a9ab62010-03-15 11:46:58 -0300271
Arnaldo Carvalho de Meloaeafcba2011-03-31 10:56:28 -0300272char dso__symtab_origin(const struct dso *dso);
273void dso__set_long_name(struct dso *dso, char *name);
274void dso__set_build_id(struct dso *dso, void *build_id);
275void dso__read_running_kernel_build_id(struct dso *dso,
276 struct machine *machine);
Srikar Dronamraju225466f2012-04-16 17:39:09 +0530277struct map *dso__new_map(const char *name);
Arnaldo Carvalho de Meloaeafcba2011-03-31 10:56:28 -0300278struct symbol *dso__find_symbol(struct dso *dso, enum map_type type,
279 u64 addr);
280struct symbol *dso__find_symbol_by_name(struct dso *dso, enum map_type type,
Arnaldo Carvalho de Melo79406cd2009-12-11 18:50:22 -0200281 const char *name);
Arnaldo Carvalho de Meloa2928c42009-05-28 14:55:04 -0300282
Arnaldo Carvalho de Melo2643ce1142009-11-03 21:46:10 -0200283int filename__read_build_id(const char *filename, void *bf, size_t size);
Arnaldo Carvalho de Melof1617b42009-11-18 20:20:52 -0200284int sysfs__read_build_id(const char *filename, void *bf, size_t size);
Zhang, Yanmina1645ce2010-04-19 13:32:50 +0800285bool __dsos__read_build_ids(struct list_head *head, bool with_hits);
Arnaldo Carvalho de Meloaeafcba2011-03-31 10:56:28 -0300286int build_id__sprintf(const u8 *build_id, int len, char *bf);
Arnaldo Carvalho de Melo9e201442010-01-14 18:30:06 -0200287int kallsyms__parse(const char *filename, void *arg,
288 int (*process_symbol)(void *arg, const char *name,
Arnaldo Carvalho de Melo3b01a412010-12-22 01:08:36 -0200289 char type, u64 start, u64 end));
Arnaldo Carvalho de Melo2643ce1142009-11-03 21:46:10 -0200290
Arnaldo Carvalho de Meloaeafcba2011-03-31 10:56:28 -0300291void machine__destroy_kernel_maps(struct machine *machine);
292int __machine__create_kernel_maps(struct machine *machine, struct dso *kernel);
293int machine__create_kernel_maps(struct machine *machine);
Arnaldo Carvalho de Melo5c0541d2010-04-29 15:25:23 -0300294
Arnaldo Carvalho de Meloaeafcba2011-03-31 10:56:28 -0300295int machines__create_kernel_maps(struct rb_root *machines, pid_t pid);
296int machines__create_guest_kernel_maps(struct rb_root *machines);
297void machines__destroy_guest_kernel_maps(struct rb_root *machines);
Zhang, Yanmina1645ce2010-04-19 13:32:50 +0800298
Arnaldo Carvalho de Melo75be6cf2009-12-15 20:04:39 -0200299int symbol__init(void);
Arnaldo Carvalho de Melod65a4582010-07-30 18:31:28 -0300300void symbol__exit(void);
Akihiro Nagaia978f2a2012-01-30 13:43:15 +0900301size_t symbol__fprintf_symname_offs(const struct symbol *sym,
302 const struct addr_location *al, FILE *fp);
Akihiro Nagai547a92e2012-01-30 13:42:57 +0900303size_t symbol__fprintf_symname(const struct symbol *sym, FILE *fp);
Arnaldo Carvalho de Melo36a3e642010-01-04 16:19:27 -0200304bool symbol_type__is_a(char symbol_type, enum map_type map_type);
305
Arnaldo Carvalho de Meloaeafcba2011-03-31 10:56:28 -0300306size_t machine__fprintf_vmlinux_path(struct machine *machine, FILE *fp);
Arnaldo Carvalho de Melob0a9ab62010-03-15 11:46:58 -0300307
Jiri Olsa44f24cb2012-07-22 14:14:32 +0200308int dso__binary_type_file(struct dso *dso, enum dso_binary_type type,
309 char *root_dir, char *file, size_t size);
Jiri Olsa949d1602012-07-22 14:14:33 +0200310
311int dso__data_fd(struct dso *dso, struct machine *machine);
312ssize_t dso__data_read_offset(struct dso *dso, struct machine *machine,
313 u64 offset, u8 *data, ssize_t size);
314ssize_t dso__data_read_addr(struct dso *dso, struct map *map,
315 struct machine *machine, u64 addr,
316 u8 *data, ssize_t size);
John Kacur8b40f522009-09-24 18:02:18 +0200317#endif /* __PERF_SYMBOL */