blob: 325ee36a9d29d63d82973d262816f91a064813f2 [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"
Arnaldo Carvalho de Melo5da50252009-07-01 14:46:08 -03008#include <linux/list.h>
Arnaldo Carvalho de Melo43cbcd82009-07-01 12:28:37 -03009#include <linux/rbtree.h>
Arnaldo Carvalho de Melo5aab6212010-03-25 19:59:00 -030010#include <stdio.h>
Arnaldo Carvalho de Meloa2928c42009-05-28 14:55:04 -030011
Arnaldo Carvalho de Melo247648e2009-08-11 16:22:11 -030012#ifdef HAVE_CPLUS_DEMANGLE
13extern char *cplus_demangle(const char *, int);
14
15static inline char *bfd_demangle(void __used *v, const char *c, int i)
16{
17 return cplus_demangle(c, i);
18}
19#else
20#ifdef NO_DEMANGLE
21static inline char *bfd_demangle(void __used *v, const char __used *c,
22 int __used i)
23{
24 return NULL;
25}
26#else
27#include <bfd.h>
28#endif
29#endif
30
Arnaldo Carvalho de Melo5aab6212010-03-25 19:59:00 -030031int hex2u64(const char *ptr, u64 *val);
32char *strxfrchar(char *s, char from, char to);
33
Marti Raudsepp84087122009-10-24 19:10:36 +030034/*
35 * libelf 0.8.x and earlier do not support ELF_C_READ_MMAP;
36 * for newer versions we can use mmap to reduce memory usage:
37 */
38#ifdef LIBELF_NO_MMAP
39# define PERF_ELF_C_READ_MMAP ELF_C_READ
40#else
41# define PERF_ELF_C_READ_MMAP ELF_C_READ_MMAP
42#endif
43
Arnaldo Carvalho de Melo247648e2009-08-11 16:22:11 -030044#ifndef DMGL_PARAMS
45#define DMGL_PARAMS (1 << 0) /* Include function args */
46#define DMGL_ANSI (1 << 1) /* Include const, volatile, etc */
47#endif
48
Arnaldo Carvalho de Melo5aab6212010-03-25 19:59:00 -030049#define BUILD_ID_SIZE 20
50
Arnaldo Carvalho de Melo171b3be2011-03-11 13:36:01 -030051/** struct symbol - symtab entry
52 *
53 * @ignore - resolvable but tools ignore it (e.g. idle routines)
54 */
Arnaldo Carvalho de Meloa2928c42009-05-28 14:55:04 -030055struct symbol {
56 struct rb_node rb_node;
Paul Mackerras9cffa8d2009-06-19 22:21:42 +100057 u64 start;
58 u64 end;
Arnaldo Carvalho de Melofefb0b92010-05-10 13:57:51 -030059 u16 namelen;
Arnaldo Carvalho de Meloc408fed2010-08-05 12:59:47 -030060 u8 binding;
Arnaldo Carvalho de Melo171b3be2011-03-11 13:36:01 -030061 bool ignore;
Arnaldo Carvalho de Meloa2928c42009-05-28 14:55:04 -030062 char name[0];
63};
64
Arnaldo Carvalho de Meloaeafcba2011-03-31 10:56:28 -030065void symbol__delete(struct symbol *sym);
Arnaldo Carvalho de Melo628ada02010-02-25 12:57:40 -030066
Arnaldo Carvalho de Melo655000e2009-12-15 20:04:40 -020067struct strlist;
68
Arnaldo Carvalho de Melob32d1332009-11-24 12:05:15 -020069struct symbol_conf {
70 unsigned short priv_size;
71 bool try_vmlinux_path,
Arnaldo Carvalho de Melo79406cd2009-12-11 18:50:22 -020072 use_modules,
Arnaldo Carvalho de Melod599db32009-12-15 20:04:42 -020073 sort_by_name,
74 show_nr_samples,
75 use_callchain,
Arnaldo Carvalho de Melof7d87442009-12-27 21:37:04 -020076 exclude_other,
Jovi Zhang85e00b52010-09-09 13:30:59 -030077 show_cpu_utilization,
Arnaldo Carvalho de Meloec80fde2011-05-26 09:53:51 -030078 initialized,
79 kptr_restrict;
Arnaldo Carvalho de Meloc410a332009-12-15 20:04:41 -020080 const char *vmlinux_name,
David Ahernb226a5a72010-12-07 19:39:46 -070081 *kallsyms_name,
Chase Douglas9ed7e1b2010-06-14 15:26:30 -040082 *source_prefix,
Arnaldo Carvalho de Meloc410a332009-12-15 20:04:41 -020083 *field_sep;
Zhang, Yanmina1645ce2010-04-19 13:32:50 +080084 const char *default_guest_vmlinux_name,
85 *default_guest_kallsyms,
86 *default_guest_modules;
87 const char *guestmount;
Arnaldo Carvalho de Meloedb7c602010-05-17 16:22:41 -030088 const char *dso_list_str,
Arnaldo Carvalho de Melo655000e2009-12-15 20:04:40 -020089 *comm_list_str,
90 *sym_list_str,
91 *col_width_list_str;
92 struct strlist *dso_list,
93 *comm_list,
94 *sym_list;
David Ahernec5761e2010-12-09 13:27:07 -070095 const char *symfs;
Arnaldo Carvalho de Melob32d1332009-11-24 12:05:15 -020096};
97
Arnaldo Carvalho de Melo75be6cf2009-12-15 20:04:39 -020098extern struct symbol_conf symbol_conf;
Arnaldo Carvalho de Melo00a192b2009-10-30 16:28:24 -020099
Arnaldo Carvalho de Meloaeafcba2011-03-31 10:56:28 -0300100static inline void *symbol__priv(struct symbol *sym)
Arnaldo Carvalho de Melo00a192b2009-10-30 16:28:24 -0200101{
Arnaldo Carvalho de Meloaeafcba2011-03-31 10:56:28 -0300102 return ((void *)sym) - symbol_conf.priv_size;
Arnaldo Carvalho de Melo00a192b2009-10-30 16:28:24 -0200103}
104
Arnaldo Carvalho de Melo9de89fe2010-02-03 16:52:00 -0200105struct ref_reloc_sym {
106 const char *name;
107 u64 addr;
108 u64 unrelocated_addr;
109};
110
Arnaldo Carvalho de Melo59fd5302010-03-24 16:40:17 -0300111struct map_symbol {
112 struct map *map;
113 struct symbol *sym;
Arnaldo Carvalho de Melo0f0cbf72010-07-26 17:13:40 -0300114 bool unfolded;
115 bool has_children;
Arnaldo Carvalho de Melo59fd5302010-03-24 16:40:17 -0300116};
117
Arnaldo Carvalho de Melo1ed091c2009-11-27 16:29:23 -0200118struct addr_location {
119 struct thread *thread;
120 struct map *map;
121 struct symbol *sym;
122 u64 addr;
123 char level;
Arnaldo Carvalho de Meloc410a332009-12-15 20:04:41 -0200124 bool filtered;
Arun Sharmaf60f3592010-06-04 11:27:10 -0300125 u8 cpumode;
126 s32 cpu;
Zhang, Yanmina1645ce2010-04-19 13:32:50 +0800127};
128
129enum dso_kernel_type {
130 DSO_TYPE_USER = 0,
131 DSO_TYPE_KERNEL,
132 DSO_TYPE_GUEST_KERNEL
Arnaldo Carvalho de Melo1ed091c2009-11-27 16:29:23 -0200133};
134
Arnaldo Carvalho de Meloa2928c42009-05-28 14:55:04 -0300135struct dso {
136 struct list_head node;
Arnaldo Carvalho de Melo6a4694a2009-11-27 16:29:17 -0200137 struct rb_root symbols[MAP__NR_TYPES];
Arnaldo Carvalho de Melo79406cd2009-12-11 18:50:22 -0200138 struct rb_root symbol_names[MAP__NR_TYPES];
Arnaldo Carvalho de Melo6e406252010-07-29 15:11:30 -0300139 enum dso_kernel_type kernel;
Arnaldo Carvalho de Melo8d063672009-11-04 18:50:43 -0200140 u8 adjust_symbols:1;
Arnaldo Carvalho de Melo8d063672009-11-04 18:50:43 -0200141 u8 has_build_id:1;
Arnaldo Carvalho de Melo88d3d9b72010-01-14 23:45:30 -0200142 u8 hit:1;
Arnaldo Carvalho de Melod06d92b2010-03-15 13:04:33 -0300143 u8 annotate_warned:1;
Arnaldo Carvalho de Melo6e406252010-07-29 15:11:30 -0300144 u8 sname_alloc:1;
145 u8 lname_alloc:1;
Arnaldo Carvalho de Melo878b4392011-03-11 13:13:36 -0300146 unsigned char symtab_type;
Arnaldo Carvalho de Melo79406cd2009-12-11 18:50:22 -0200147 u8 sorted_by_name;
Arnaldo Carvalho de Melo36105832009-11-27 16:29:16 -0200148 u8 loaded;
Arnaldo Carvalho de Melo8d063672009-11-04 18:50:43 -0200149 u8 build_id[BUILD_ID_SIZE];
Arnaldo Carvalho de Melo439d4732009-10-02 03:29:58 -0300150 const char *short_name;
151 char *long_name;
Arnaldo Carvalho de Melob63be8d2010-03-15 15:03:50 -0300152 u16 long_name_len;
153 u16 short_name_len;
Arnaldo Carvalho de Meloa2928c42009-05-28 14:55:04 -0300154 char name[0];
155};
156
Arnaldo Carvalho de Melo00a192b2009-10-30 16:28:24 -0200157struct dso *dso__new(const char *name);
Arnaldo Carvalho de Melofd1d9082010-01-27 21:05:51 -0200158struct dso *dso__new_kernel(const char *name);
Arnaldo Carvalho de Meloaeafcba2011-03-31 10:56:28 -0300159void dso__delete(struct dso *dso);
Arnaldo Carvalho de Meloa2928c42009-05-28 14:55:04 -0300160
Arnaldo Carvalho de Meloaeafcba2011-03-31 10:56:28 -0300161int dso__name_len(const struct dso *dso);
Arnaldo Carvalho de Melo8a6c5b22010-07-20 14:42:52 -0300162
Arnaldo Carvalho de Meloaeafcba2011-03-31 10:56:28 -0300163bool dso__loaded(const struct dso *dso, enum map_type type);
164bool dso__sorted_by_name(const struct dso *dso, enum map_type type);
Arnaldo Carvalho de Melo79406cd2009-12-11 18:50:22 -0200165
Arnaldo Carvalho de Meloaeafcba2011-03-31 10:56:28 -0300166static inline void dso__set_loaded(struct dso *dso, enum map_type type)
Arnaldo Carvalho de Melo8d92c022010-02-03 16:52:02 -0200167{
Arnaldo Carvalho de Meloaeafcba2011-03-31 10:56:28 -0300168 dso->loaded |= (1 << type);
Arnaldo Carvalho de Melo8d92c022010-02-03 16:52:02 -0200169}
170
Arnaldo Carvalho de Meloaeafcba2011-03-31 10:56:28 -0300171void dso__sort_by_name(struct dso *dso, enum map_type type);
Arnaldo Carvalho de Melo36105832009-11-27 16:29:16 -0200172
Arnaldo Carvalho de Meloa89e5abe2010-01-07 19:59:39 -0200173struct dso *__dsos__findnew(struct list_head *head, const char *name);
174
Arnaldo Carvalho de Meloaeafcba2011-03-31 10:56:28 -0300175int dso__load(struct dso *dso, struct map *map, symbol_filter_t filter);
176int dso__load_vmlinux(struct dso *dso, struct map *map,
Franck Bui-Huufd930ff2010-12-10 14:06:03 +0100177 const char *vmlinux, symbol_filter_t filter);
Arnaldo Carvalho de Meloaeafcba2011-03-31 10:56:28 -0300178int dso__load_vmlinux_path(struct dso *dso, struct map *map,
Arnaldo Carvalho de Melo9de89fe2010-02-03 16:52:00 -0200179 symbol_filter_t filter);
Arnaldo Carvalho de Meloaeafcba2011-03-31 10:56:28 -0300180int dso__load_kallsyms(struct dso *dso, const char *filename, struct map *map,
Arnaldo Carvalho de Melo9de89fe2010-02-03 16:52:00 -0200181 symbol_filter_t filter);
Arnaldo Carvalho de Meloaeafcba2011-03-31 10:56:28 -0300182int machine__load_kallsyms(struct machine *machine, const char *filename,
Arnaldo Carvalho de Melo5c0541d2010-04-29 15:25:23 -0300183 enum map_type type, symbol_filter_t filter);
Arnaldo Carvalho de Meloaeafcba2011-03-31 10:56:28 -0300184int machine__load_vmlinux_path(struct machine *machine, enum map_type type,
Arnaldo Carvalho de Melo5c0541d2010-04-29 15:25:23 -0300185 symbol_filter_t filter);
186
Arnaldo Carvalho de Melo1f626bc2010-05-09 19:57:08 -0300187size_t __dsos__fprintf(struct list_head *head, FILE *fp);
188
Arnaldo Carvalho de Meloaeafcba2011-03-31 10:56:28 -0300189size_t machine__fprintf_dsos_buildid(struct machine *machine,
190 FILE *fp, bool with_hits);
191size_t machines__fprintf_dsos(struct rb_root *machines, FILE *fp);
192size_t machines__fprintf_dsos_buildid(struct rb_root *machines,
193 FILE *fp, bool with_hits);
194size_t dso__fprintf_buildid(struct dso *dso, FILE *fp);
195size_t dso__fprintf_symbols_by_name(struct dso *dso,
196 enum map_type type, FILE *fp);
197size_t dso__fprintf(struct dso *dso, enum map_type type, FILE *fp);
Arnaldo Carvalho de Melob0a9ab62010-03-15 11:46:58 -0300198
Arnaldo Carvalho de Melo878b4392011-03-11 13:13:36 -0300199enum symtab_type {
200 SYMTAB__KALLSYMS = 0,
201 SYMTAB__GUEST_KALLSYMS,
202 SYMTAB__JAVA_JIT,
203 SYMTAB__BUILD_ID_CACHE,
204 SYMTAB__FEDORA_DEBUGINFO,
205 SYMTAB__UBUNTU_DEBUGINFO,
206 SYMTAB__BUILDID_DEBUGINFO,
207 SYMTAB__SYSTEM_PATH_DSO,
208 SYMTAB__GUEST_KMODULE,
209 SYMTAB__SYSTEM_PATH_KMODULE,
210 SYMTAB__NOT_FOUND,
Arnaldo Carvalho de Melob0a9ab62010-03-15 11:46:58 -0300211};
212
Arnaldo Carvalho de Meloaeafcba2011-03-31 10:56:28 -0300213char dso__symtab_origin(const struct dso *dso);
214void dso__set_long_name(struct dso *dso, char *name);
215void dso__set_build_id(struct dso *dso, void *build_id);
216void dso__read_running_kernel_build_id(struct dso *dso,
217 struct machine *machine);
218struct symbol *dso__find_symbol(struct dso *dso, enum map_type type,
219 u64 addr);
220struct symbol *dso__find_symbol_by_name(struct dso *dso, enum map_type type,
Arnaldo Carvalho de Melo79406cd2009-12-11 18:50:22 -0200221 const char *name);
Arnaldo Carvalho de Meloa2928c42009-05-28 14:55:04 -0300222
Arnaldo Carvalho de Melo2643ce12009-11-03 21:46:10 -0200223int filename__read_build_id(const char *filename, void *bf, size_t size);
Arnaldo Carvalho de Melof1617b42009-11-18 20:20:52 -0200224int sysfs__read_build_id(const char *filename, void *bf, size_t size);
Zhang, Yanmina1645ce2010-04-19 13:32:50 +0800225bool __dsos__read_build_ids(struct list_head *head, bool with_hits);
Arnaldo Carvalho de Meloaeafcba2011-03-31 10:56:28 -0300226int build_id__sprintf(const u8 *build_id, int len, char *bf);
Arnaldo Carvalho de Melo9e201442010-01-14 18:30:06 -0200227int kallsyms__parse(const char *filename, void *arg,
228 int (*process_symbol)(void *arg, const char *name,
Arnaldo Carvalho de Melo3b01a412010-12-22 01:08:36 -0200229 char type, u64 start, u64 end));
Arnaldo Carvalho de Melo2643ce12009-11-03 21:46:10 -0200230
Arnaldo Carvalho de Meloaeafcba2011-03-31 10:56:28 -0300231void machine__destroy_kernel_maps(struct machine *machine);
232int __machine__create_kernel_maps(struct machine *machine, struct dso *kernel);
233int machine__create_kernel_maps(struct machine *machine);
Arnaldo Carvalho de Melo5c0541d2010-04-29 15:25:23 -0300234
Arnaldo Carvalho de Meloaeafcba2011-03-31 10:56:28 -0300235int machines__create_kernel_maps(struct rb_root *machines, pid_t pid);
236int machines__create_guest_kernel_maps(struct rb_root *machines);
237void machines__destroy_guest_kernel_maps(struct rb_root *machines);
Zhang, Yanmina1645ce2010-04-19 13:32:50 +0800238
Arnaldo Carvalho de Melo75be6cf2009-12-15 20:04:39 -0200239int symbol__init(void);
Arnaldo Carvalho de Melod65a4582010-07-30 18:31:28 -0300240void symbol__exit(void);
Arnaldo Carvalho de Melo36a3e642010-01-04 16:19:27 -0200241bool symbol_type__is_a(char symbol_type, enum map_type map_type);
242
Arnaldo Carvalho de Meloaeafcba2011-03-31 10:56:28 -0300243size_t machine__fprintf_vmlinux_path(struct machine *machine, FILE *fp);
Arnaldo Carvalho de Melob0a9ab62010-03-15 11:46:58 -0300244
John Kacur8b40f522009-09-24 18:02:18 +0200245#endif /* __PERF_SYMBOL */